18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Marvell OcteonTx2 CGX driver 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2018 Marvell International Ltd. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 78c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License version 2 as 88c2ecf20Sopenharmony_ci * published by the Free Software Foundation. 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifndef CGX_H 128c2ecf20Sopenharmony_ci#define CGX_H 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include "mbox.h" 158c2ecf20Sopenharmony_ci#include "cgx_fw_if.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci /* PCI device IDs */ 188c2ecf20Sopenharmony_ci#define PCI_DEVID_OCTEONTX2_CGX 0xA059 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* PCI BAR nos */ 218c2ecf20Sopenharmony_ci#define PCI_CFG_REG_BAR_NUM 0 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define CGX_ID_MASK 0x7 248c2ecf20Sopenharmony_ci#define MAX_LMAC_PER_CGX 4 258c2ecf20Sopenharmony_ci#define CGX_FIFO_LEN 65536 /* 64K for both Rx & Tx */ 268c2ecf20Sopenharmony_ci#define CGX_OFFSET(x) ((x) * MAX_LMAC_PER_CGX) 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* Registers */ 298c2ecf20Sopenharmony_ci#define CGXX_CMRX_CFG 0x00 308c2ecf20Sopenharmony_ci#define CMR_P2X_SEL_MASK GENMASK_ULL(61, 59) 318c2ecf20Sopenharmony_ci#define CMR_P2X_SEL_SHIFT 59ULL 328c2ecf20Sopenharmony_ci#define CMR_P2X_SEL_NIX0 1ULL 338c2ecf20Sopenharmony_ci#define CMR_P2X_SEL_NIX1 2ULL 348c2ecf20Sopenharmony_ci#define DATA_PKT_TX_EN BIT_ULL(53) 358c2ecf20Sopenharmony_ci#define DATA_PKT_RX_EN BIT_ULL(54) 368c2ecf20Sopenharmony_ci#define CGX_LMAC_TYPE_SHIFT 40 378c2ecf20Sopenharmony_ci#define CGX_LMAC_TYPE_MASK 0xF 388c2ecf20Sopenharmony_ci#define CGXX_CMRX_INT 0x040 398c2ecf20Sopenharmony_ci#define FW_CGX_INT BIT_ULL(1) 408c2ecf20Sopenharmony_ci#define CGXX_CMRX_INT_ENA_W1S 0x058 418c2ecf20Sopenharmony_ci#define CGXX_CMRX_RX_ID_MAP 0x060 428c2ecf20Sopenharmony_ci#define CGXX_CMRX_RX_STAT0 0x070 438c2ecf20Sopenharmony_ci#define CGXX_CMRX_RX_LMACS 0x128 448c2ecf20Sopenharmony_ci#define CGXX_CMRX_RX_DMAC_CTL0 0x1F8 458c2ecf20Sopenharmony_ci#define CGX_DMAC_CTL0_CAM_ENABLE BIT_ULL(3) 468c2ecf20Sopenharmony_ci#define CGX_DMAC_CAM_ACCEPT BIT_ULL(3) 478c2ecf20Sopenharmony_ci#define CGX_DMAC_MCAST_MODE BIT_ULL(1) 488c2ecf20Sopenharmony_ci#define CGX_DMAC_BCAST_MODE BIT_ULL(0) 498c2ecf20Sopenharmony_ci#define CGXX_CMRX_RX_DMAC_CAM0 0x200 508c2ecf20Sopenharmony_ci#define CGX_DMAC_CAM_ADDR_ENABLE BIT_ULL(48) 518c2ecf20Sopenharmony_ci#define CGXX_CMRX_RX_DMAC_CAM1 0x400 528c2ecf20Sopenharmony_ci#define CGX_RX_DMAC_ADR_MASK GENMASK_ULL(47, 0) 538c2ecf20Sopenharmony_ci#define CGXX_CMRX_TX_STAT0 0x700 548c2ecf20Sopenharmony_ci#define CGXX_SCRATCH0_REG 0x1050 558c2ecf20Sopenharmony_ci#define CGXX_SCRATCH1_REG 0x1058 568c2ecf20Sopenharmony_ci#define CGX_CONST 0x2000 578c2ecf20Sopenharmony_ci#define CGXX_SPUX_CONTROL1 0x10000 588c2ecf20Sopenharmony_ci#define CGXX_SPUX_CONTROL1_LBK BIT_ULL(14) 598c2ecf20Sopenharmony_ci#define CGXX_GMP_PCS_MRX_CTL 0x30000 608c2ecf20Sopenharmony_ci#define CGXX_GMP_PCS_MRX_CTL_LBK BIT_ULL(14) 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#define CGXX_SMUX_RX_FRM_CTL 0x20020 638c2ecf20Sopenharmony_ci#define CGX_SMUX_RX_FRM_CTL_CTL_BCK BIT_ULL(3) 648c2ecf20Sopenharmony_ci#define CGX_SMUX_RX_FRM_CTL_PTP_MODE BIT_ULL(12) 658c2ecf20Sopenharmony_ci#define CGXX_GMP_GMI_RXX_FRM_CTL 0x38028 668c2ecf20Sopenharmony_ci#define CGX_GMP_GMI_RXX_FRM_CTL_CTL_BCK BIT_ULL(3) 678c2ecf20Sopenharmony_ci#define CGX_GMP_GMI_RXX_FRM_CTL_PTP_MODE BIT_ULL(12) 688c2ecf20Sopenharmony_ci#define CGXX_SMUX_TX_CTL 0x20178 698c2ecf20Sopenharmony_ci#define CGXX_SMUX_TX_PAUSE_PKT_TIME 0x20110 708c2ecf20Sopenharmony_ci#define CGXX_SMUX_TX_PAUSE_PKT_INTERVAL 0x20120 718c2ecf20Sopenharmony_ci#define CGXX_GMP_GMI_TX_PAUSE_PKT_TIME 0x38230 728c2ecf20Sopenharmony_ci#define CGXX_GMP_GMI_TX_PAUSE_PKT_INTERVAL 0x38248 738c2ecf20Sopenharmony_ci#define CGX_SMUX_TX_CTL_L2P_BP_CONV BIT_ULL(7) 748c2ecf20Sopenharmony_ci#define CGXX_CMR_RX_OVR_BP 0x130 758c2ecf20Sopenharmony_ci#define CGX_CMR_RX_OVR_BP_EN(X) BIT_ULL(((X) + 8)) 768c2ecf20Sopenharmony_ci#define CGX_CMR_RX_OVR_BP_BP(X) BIT_ULL(((X) + 4)) 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#define CGX_COMMAND_REG CGXX_SCRATCH1_REG 798c2ecf20Sopenharmony_ci#define CGX_EVENT_REG CGXX_SCRATCH0_REG 808c2ecf20Sopenharmony_ci#define CGX_CMD_TIMEOUT 2200 /* msecs */ 818c2ecf20Sopenharmony_ci#define DEFAULT_PAUSE_TIME 0x7FF 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#define CGX_NVEC 37 848c2ecf20Sopenharmony_ci#define CGX_LMAC_FWI 0 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cienum cgx_nix_stat_type { 878c2ecf20Sopenharmony_ci NIX_STATS_RX, 888c2ecf20Sopenharmony_ci NIX_STATS_TX, 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cienum LMAC_TYPE { 928c2ecf20Sopenharmony_ci LMAC_MODE_SGMII = 0, 938c2ecf20Sopenharmony_ci LMAC_MODE_XAUI = 1, 948c2ecf20Sopenharmony_ci LMAC_MODE_RXAUI = 2, 958c2ecf20Sopenharmony_ci LMAC_MODE_10G_R = 3, 968c2ecf20Sopenharmony_ci LMAC_MODE_40G_R = 4, 978c2ecf20Sopenharmony_ci LMAC_MODE_QSGMII = 6, 988c2ecf20Sopenharmony_ci LMAC_MODE_25G_R = 7, 998c2ecf20Sopenharmony_ci LMAC_MODE_50G_R = 8, 1008c2ecf20Sopenharmony_ci LMAC_MODE_100G_R = 9, 1018c2ecf20Sopenharmony_ci LMAC_MODE_USXGMII = 10, 1028c2ecf20Sopenharmony_ci LMAC_MODE_MAX, 1038c2ecf20Sopenharmony_ci}; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_cistruct cgx_link_event { 1068c2ecf20Sopenharmony_ci struct cgx_link_user_info link_uinfo; 1078c2ecf20Sopenharmony_ci u8 cgx_id; 1088c2ecf20Sopenharmony_ci u8 lmac_id; 1098c2ecf20Sopenharmony_ci}; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci/** 1128c2ecf20Sopenharmony_ci * struct cgx_event_cb 1138c2ecf20Sopenharmony_ci * @notify_link_chg: callback for link change notification 1148c2ecf20Sopenharmony_ci * @data: data passed to callback function 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_cistruct cgx_event_cb { 1178c2ecf20Sopenharmony_ci int (*notify_link_chg)(struct cgx_link_event *event, void *data); 1188c2ecf20Sopenharmony_ci void *data; 1198c2ecf20Sopenharmony_ci}; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ciextern struct pci_driver cgx_driver; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ciint cgx_get_cgxcnt_max(void); 1248c2ecf20Sopenharmony_ciint cgx_get_cgxid(void *cgxd); 1258c2ecf20Sopenharmony_ciint cgx_get_lmac_cnt(void *cgxd); 1268c2ecf20Sopenharmony_civoid *cgx_get_pdata(int cgx_id); 1278c2ecf20Sopenharmony_ciint cgx_set_pkind(void *cgxd, u8 lmac_id, int pkind); 1288c2ecf20Sopenharmony_ciint cgx_lmac_evh_register(struct cgx_event_cb *cb, void *cgxd, int lmac_id); 1298c2ecf20Sopenharmony_ciint cgx_lmac_evh_unregister(void *cgxd, int lmac_id); 1308c2ecf20Sopenharmony_ciint cgx_get_tx_stats(void *cgxd, int lmac_id, int idx, u64 *tx_stat); 1318c2ecf20Sopenharmony_ciint cgx_get_rx_stats(void *cgxd, int lmac_id, int idx, u64 *rx_stat); 1328c2ecf20Sopenharmony_ciint cgx_lmac_rx_tx_enable(void *cgxd, int lmac_id, bool enable); 1338c2ecf20Sopenharmony_ciint cgx_lmac_tx_enable(void *cgxd, int lmac_id, bool enable); 1348c2ecf20Sopenharmony_ciint cgx_lmac_addr_set(u8 cgx_id, u8 lmac_id, u8 *mac_addr); 1358c2ecf20Sopenharmony_ciu64 cgx_lmac_addr_get(u8 cgx_id, u8 lmac_id); 1368c2ecf20Sopenharmony_civoid cgx_lmac_promisc_config(int cgx_id, int lmac_id, bool enable); 1378c2ecf20Sopenharmony_civoid cgx_lmac_enadis_rx_pause_fwding(void *cgxd, int lmac_id, bool enable); 1388c2ecf20Sopenharmony_ciint cgx_lmac_internal_loopback(void *cgxd, int lmac_id, bool enable); 1398c2ecf20Sopenharmony_ciint cgx_get_link_info(void *cgxd, int lmac_id, 1408c2ecf20Sopenharmony_ci struct cgx_link_user_info *linfo); 1418c2ecf20Sopenharmony_ciint cgx_lmac_linkup_start(void *cgxd); 1428c2ecf20Sopenharmony_ciint cgx_get_fwdata_base(u64 *base); 1438c2ecf20Sopenharmony_ciint cgx_lmac_get_pause_frm(void *cgxd, int lmac_id, 1448c2ecf20Sopenharmony_ci u8 *tx_pause, u8 *rx_pause); 1458c2ecf20Sopenharmony_ciint cgx_lmac_set_pause_frm(void *cgxd, int lmac_id, 1468c2ecf20Sopenharmony_ci u8 tx_pause, u8 rx_pause); 1478c2ecf20Sopenharmony_civoid cgx_lmac_ptp_config(void *cgxd, int lmac_id, bool enable); 1488c2ecf20Sopenharmony_ciu8 cgx_lmac_get_p2x(int cgx_id, int lmac_id); 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci#endif /* CGX_H */ 151