126b3f3ccSNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
226b3f3ccSNishad Kamdar /* Marvell OcteonTx2 CGX driver
38e22f040SSunil Goutham  *
4*c7cd6c5aSSunil Goutham  * Copyright (C) 2018 Marvell.
58e22f040SSunil Goutham  *
68e22f040SSunil Goutham  */
78e22f040SSunil Goutham 
88e22f040SSunil Goutham #ifndef CGX_H
98e22f040SSunil Goutham #define CGX_H
108e22f040SSunil Goutham 
1161071a87SLinu Cherian #include "mbox.h"
121463f382SLinu Cherian #include "cgx_fw_if.h"
1391c6945eSHariprasad Kelam #include "rpm.h"
141463f382SLinu Cherian 
158e22f040SSunil Goutham  /* PCI device IDs */
168e22f040SSunil Goutham #define	PCI_DEVID_OCTEONTX2_CGX		0xA059
178e22f040SSunil Goutham 
188e22f040SSunil Goutham /* PCI BAR nos */
198e22f040SSunil Goutham #define PCI_CFG_REG_BAR_NUM		0
208e22f040SSunil Goutham 
2112e4c9abSLinu Cherian #define CGX_ID_MASK			0x7
223a4fa841SLinu Cherian #define MAX_LMAC_PER_CGX		4
236f14078eSSunil Kumar Kori #define MAX_DMAC_ENTRIES_PER_CGX	32
249b7dd87aSSunil Goutham #define CGX_FIFO_LEN			65536 /* 64K for both Rx & Tx */
253a4fa841SLinu Cherian #define CGX_OFFSET(x)			((x) * MAX_LMAC_PER_CGX)
263a4fa841SLinu Cherian 
273a4fa841SLinu Cherian /* Registers */
281435f66aSSunil Goutham #define CGXX_CMRX_CFG			0x00
29c5a73b63SSubbaraya Sundeep #define CMR_P2X_SEL_MASK		GENMASK_ULL(61, 59)
30c5a73b63SSubbaraya Sundeep #define CMR_P2X_SEL_SHIFT		59ULL
31c5a73b63SSubbaraya Sundeep #define CMR_P2X_SEL_NIX0		1ULL
32c5a73b63SSubbaraya Sundeep #define CMR_P2X_SEL_NIX1		2ULL
331435f66aSSunil Goutham #define CMR_EN				BIT_ULL(55)
341435f66aSSunil Goutham #define DATA_PKT_TX_EN			BIT_ULL(53)
351435f66aSSunil Goutham #define DATA_PKT_RX_EN			BIT_ULL(54)
3661071a87SLinu Cherian #define CGX_LMAC_TYPE_SHIFT		40
3761071a87SLinu Cherian #define CGX_LMAC_TYPE_MASK		0xF
381463f382SLinu Cherian #define CGXX_CMRX_INT			0x040
391463f382SLinu Cherian #define FW_CGX_INT			BIT_ULL(1)
401463f382SLinu Cherian #define CGXX_CMRX_INT_ENA_W1S		0x058
413a4fa841SLinu Cherian #define CGXX_CMRX_RX_ID_MAP		0x060
42ce7a6c31SHariprasad Kelam #define CGXX_CMRX_RX_STAT0		0x070
433a4fa841SLinu Cherian #define CGXX_CMRX_RX_LMACS		0x128
4491c6945eSHariprasad Kelam #define CGXX_CMRX_RX_DMAC_CTL0		(0x1F8 + mac_ops->csr_offset)
4596be2e0dSVidhya Raman #define CGX_DMAC_CTL0_CAM_ENABLE	BIT_ULL(3)
4696be2e0dSVidhya Raman #define CGX_DMAC_CAM_ACCEPT		BIT_ULL(3)
476f14078eSSunil Kumar Kori #define CGX_DMAC_MCAST_MODE_CAM		BIT_ULL(2)
4896be2e0dSVidhya Raman #define CGX_DMAC_MCAST_MODE		BIT_ULL(1)
4996be2e0dSVidhya Raman #define CGX_DMAC_BCAST_MODE		BIT_ULL(0)
5091c6945eSHariprasad Kelam #define CGXX_CMRX_RX_DMAC_CAM0		(0x200 + mac_ops->csr_offset)
5196be2e0dSVidhya Raman #define CGX_DMAC_CAM_ADDR_ENABLE	BIT_ULL(48)
52dbc52debSHariprasad Kelam #define CGX_DMAC_CAM_ENTRY_LMACID	GENMASK_ULL(50, 49)
5396be2e0dSVidhya Raman #define CGXX_CMRX_RX_DMAC_CAM1		0x400
5496be2e0dSVidhya Raman #define CGX_RX_DMAC_ADR_MASK		GENMASK_ULL(47, 0)
55ce7a6c31SHariprasad Kelam #define CGXX_CMRX_TX_STAT0		0x700
561463f382SLinu Cherian #define CGXX_SCRATCH0_REG		0x1050
571463f382SLinu Cherian #define CGXX_SCRATCH1_REG		0x1058
581463f382SLinu Cherian #define CGX_CONST			0x2000
596e54e1c5SHariprasad Kelam #define CGX_CONST_RXFIFO_SIZE	        GENMASK_ULL(23, 0)
6023999b30SGeetha sowjanya #define CGXX_SPUX_CONTROL1		0x10000
6184c4f9caSChristina Jacob #define CGXX_SPUX_LNX_FEC_CORR_BLOCKS	0x10700
6284c4f9caSChristina Jacob #define CGXX_SPUX_LNX_FEC_UNCORR_BLOCKS	0x10800
6384c4f9caSChristina Jacob #define CGXX_SPUX_RSFEC_CORR		0x10088
6484c4f9caSChristina Jacob #define CGXX_SPUX_RSFEC_UNCORR		0x10090
6584c4f9caSChristina Jacob 
6623999b30SGeetha sowjanya #define CGXX_SPUX_CONTROL1_LBK		BIT_ULL(14)
6723999b30SGeetha sowjanya #define CGXX_GMP_PCS_MRX_CTL		0x30000
6823999b30SGeetha sowjanya #define CGXX_GMP_PCS_MRX_CTL_LBK	BIT_ULL(14)
691463f382SLinu Cherian 
705d9b976dSSunil Goutham #define CGXX_SMUX_RX_FRM_CTL		0x20020
715d9b976dSSunil Goutham #define CGX_SMUX_RX_FRM_CTL_CTL_BCK	BIT_ULL(3)
7242157217SZyta Szpak #define CGX_SMUX_RX_FRM_CTL_PTP_MODE	BIT_ULL(12)
735d9b976dSSunil Goutham #define CGXX_GMP_GMI_RXX_FRM_CTL	0x38028
745d9b976dSSunil Goutham #define CGX_GMP_GMI_RXX_FRM_CTL_CTL_BCK	BIT_ULL(3)
7542157217SZyta Szpak #define CGX_GMP_GMI_RXX_FRM_CTL_PTP_MODE BIT_ULL(12)
76f7e086e7SGeetha sowjanya #define CGXX_SMUX_TX_CTL		0x20178
77f7e086e7SGeetha sowjanya #define CGXX_SMUX_TX_PAUSE_PKT_TIME	0x20110
78f7e086e7SGeetha sowjanya #define CGXX_SMUX_TX_PAUSE_PKT_INTERVAL	0x20120
79f7e086e7SGeetha sowjanya #define CGXX_GMP_GMI_TX_PAUSE_PKT_TIME	0x38230
80f7e086e7SGeetha sowjanya #define CGXX_GMP_GMI_TX_PAUSE_PKT_INTERVAL	0x38248
81f7e086e7SGeetha sowjanya #define CGX_SMUX_TX_CTL_L2P_BP_CONV	BIT_ULL(7)
82f7e086e7SGeetha sowjanya #define CGXX_CMR_RX_OVR_BP		0x130
83f7e086e7SGeetha sowjanya #define CGX_CMR_RX_OVR_BP_EN(X)		BIT_ULL(((X) + 8))
84f7e086e7SGeetha sowjanya #define CGX_CMR_RX_OVR_BP_BP(X)		BIT_ULL(((X) + 4))
855d9b976dSSunil Goutham 
861463f382SLinu Cherian #define CGX_COMMAND_REG			CGXX_SCRATCH1_REG
871463f382SLinu Cherian #define CGX_EVENT_REG			CGXX_SCRATCH0_REG
881463f382SLinu Cherian #define CGX_CMD_TIMEOUT			2200 /* msecs */
89f7e086e7SGeetha sowjanya #define DEFAULT_PAUSE_TIME		0x7FF
901463f382SLinu Cherian 
911463f382SLinu Cherian #define CGX_LMAC_FWI			0
921463f382SLinu Cherian 
93f967488dSLinu Cherian enum  cgx_nix_stat_type {
94f967488dSLinu Cherian 	NIX_STATS_RX,
95f967488dSLinu Cherian 	NIX_STATS_TX,
96f967488dSLinu Cherian };
97f967488dSLinu Cherian 
9861071a87SLinu Cherian enum LMAC_TYPE {
9961071a87SLinu Cherian 	LMAC_MODE_SGMII		= 0,
10061071a87SLinu Cherian 	LMAC_MODE_XAUI		= 1,
10161071a87SLinu Cherian 	LMAC_MODE_RXAUI		= 2,
10261071a87SLinu Cherian 	LMAC_MODE_10G_R		= 3,
10361071a87SLinu Cherian 	LMAC_MODE_40G_R		= 4,
10461071a87SLinu Cherian 	LMAC_MODE_QSGMII	= 6,
10561071a87SLinu Cherian 	LMAC_MODE_25G_R		= 7,
10661071a87SLinu Cherian 	LMAC_MODE_50G_R		= 8,
10761071a87SLinu Cherian 	LMAC_MODE_100G_R	= 9,
10861071a87SLinu Cherian 	LMAC_MODE_USXGMII	= 10,
10961071a87SLinu Cherian 	LMAC_MODE_MAX,
11061071a87SLinu Cherian };
11161071a87SLinu Cherian 
1121463f382SLinu Cherian struct cgx_link_event {
11361071a87SLinu Cherian 	struct cgx_link_user_info link_uinfo;
1141463f382SLinu Cherian 	u8 cgx_id;
1151463f382SLinu Cherian 	u8 lmac_id;
1161463f382SLinu Cherian };
1171463f382SLinu Cherian 
1181463f382SLinu Cherian /**
1191463f382SLinu Cherian  * struct cgx_event_cb
1201463f382SLinu Cherian  * @notify_link_chg:	callback for link change notification
1211463f382SLinu Cherian  * @data:	data passed to callback function
1221463f382SLinu Cherian  */
1231463f382SLinu Cherian struct cgx_event_cb {
1241463f382SLinu Cherian 	int (*notify_link_chg)(struct cgx_link_event *event, void *data);
1251463f382SLinu Cherian 	void *data;
1261463f382SLinu Cherian };
1273a4fa841SLinu Cherian 
1288e22f040SSunil Goutham extern struct pci_driver cgx_driver;
1298e22f040SSunil Goutham 
13012e4c9abSLinu Cherian int cgx_get_cgxcnt_max(void);
131f967488dSLinu Cherian int cgx_get_cgxid(void *cgxd);
1323a4fa841SLinu Cherian int cgx_get_lmac_cnt(void *cgxd);
1333a4fa841SLinu Cherian void *cgx_get_pdata(int cgx_id);
13494d942c5SGeetha sowjanya int cgx_set_pkind(void *cgxd, u8 lmac_id, int pkind);
1351463f382SLinu Cherian int cgx_lmac_evh_register(struct cgx_event_cb *cb, void *cgxd, int lmac_id);
136c9293236SLinu Cherian int cgx_lmac_evh_unregister(void *cgxd, int lmac_id);
13766208910SChristina Jacob int cgx_get_tx_stats(void *cgxd, int lmac_id, int idx, u64 *tx_stat);
13866208910SChristina Jacob int cgx_get_rx_stats(void *cgxd, int lmac_id, int idx, u64 *rx_stat);
1391435f66aSSunil Goutham int cgx_lmac_rx_tx_enable(void *cgxd, int lmac_id, bool enable);
1405d9b976dSSunil Goutham int cgx_lmac_tx_enable(void *cgxd, int lmac_id, bool enable);
14196be2e0dSVidhya Raman int cgx_lmac_addr_set(u8 cgx_id, u8 lmac_id, u8 *mac_addr);
1426f14078eSSunil Kumar Kori int cgx_lmac_addr_reset(u8 cgx_id, u8 lmac_id);
14396be2e0dSVidhya Raman u64 cgx_lmac_addr_get(u8 cgx_id, u8 lmac_id);
1446f14078eSSunil Kumar Kori int cgx_lmac_addr_add(u8 cgx_id, u8 lmac_id, u8 *mac_addr);
1456f14078eSSunil Kumar Kori int cgx_lmac_addr_del(u8 cgx_id, u8 lmac_id, u8 index);
1466f14078eSSunil Kumar Kori int cgx_lmac_addr_max_entries_get(u8 cgx_id, u8 lmac_id);
14796be2e0dSVidhya Raman void cgx_lmac_promisc_config(int cgx_id, int lmac_id, bool enable);
1485d9b976dSSunil Goutham void cgx_lmac_enadis_rx_pause_fwding(void *cgxd, int lmac_id, bool enable);
14923999b30SGeetha sowjanya int cgx_lmac_internal_loopback(void *cgxd, int lmac_id, bool enable);
15061071a87SLinu Cherian int cgx_get_link_info(void *cgxd, int lmac_id,
15161071a87SLinu Cherian 		      struct cgx_link_user_info *linfo);
152d3b2b9abSLinu Cherian int cgx_lmac_linkup_start(void *cgxd);
1534f4eebf2SLinu Cherian int cgx_get_fwdata_base(u64 *base);
154f7e086e7SGeetha sowjanya int cgx_lmac_get_pause_frm(void *cgxd, int lmac_id,
155f7e086e7SGeetha sowjanya 			   u8 *tx_pause, u8 *rx_pause);
156f7e086e7SGeetha sowjanya int cgx_lmac_set_pause_frm(void *cgxd, int lmac_id,
157f7e086e7SGeetha sowjanya 			   u8 tx_pause, u8 rx_pause);
15842157217SZyta Szpak void cgx_lmac_ptp_config(void *cgxd, int lmac_id, bool enable);
159c5a73b63SSubbaraya Sundeep u8 cgx_lmac_get_p2x(int cgx_id, int lmac_id);
16084c4f9caSChristina Jacob int cgx_set_fec(u64 fec, int cgx_id, int lmac_id);
16184c4f9caSChristina Jacob int cgx_get_fec_stats(void *cgxd, int lmac_id, struct cgx_fec_stats_rsp *rsp);
162bd74d4eaSFelix Manlunas int cgx_get_phy_fec_stats(void *cgxd, int lmac_id);
16356b6d539SChristina Jacob int cgx_set_link_mode(void *cgxd, struct cgx_set_link_mode_args args,
16456b6d539SChristina Jacob 		      int cgx_id, int lmac_id);
16591c6945eSHariprasad Kelam u64 cgx_features_get(void *cgxd);
16691c6945eSHariprasad Kelam struct mac_ops *get_mac_ops(void *cgxd);
16791c6945eSHariprasad Kelam int cgx_get_nr_lmacs(void *cgxd);
16891c6945eSHariprasad Kelam u8 cgx_get_lmacid(void *cgxd, u8 lmac_index);
16991c6945eSHariprasad Kelam unsigned long cgx_get_lmac_bmap(void *cgxd);
170242da439SSubbaraya Sundeep void cgx_lmac_write(int cgx_id, int lmac_id, u64 offset, u64 val);
171242da439SSubbaraya Sundeep u64 cgx_lmac_read(int cgx_id, int lmac_id, u64 offset);
1726f14078eSSunil Kumar Kori int cgx_lmac_addr_update(u8 cgx_id, u8 lmac_id, u8 *mac_addr, u8 index);
173dbc52debSHariprasad Kelam u64 cgx_read_dmac_ctrl(void *cgxd, int lmac_id);
174dbc52debSHariprasad Kelam u64 cgx_read_dmac_entry(void *cgxd, int index);
1758e22f040SSunil Goutham #endif /* CGX_H */
176