xref: /openbmc/linux/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h (revision ecc23d0a422a3118fcf6e4f0a46e17a6c2047b02)
116547577SSunil Goutham /* SPDX-License-Identifier: GPL-2.0 */
2cb0e3ec4SSunil Goutham /* Marvell RVU Ethernet driver
316547577SSunil Goutham  *
4cb0e3ec4SSunil Goutham  * Copyright (C) 2020 Marvell.
516547577SSunil Goutham  *
616547577SSunil Goutham  */
716547577SSunil Goutham 
816547577SSunil Goutham #ifndef OTX2_COMMON_H
916547577SSunil Goutham #define OTX2_COMMON_H
1016547577SSunil Goutham 
11cc69837fSJakub Kicinski #include <linux/ethtool.h>
1216547577SSunil Goutham #include <linux/pci.h>
13caa2da34SSunil Goutham #include <linux/iommu.h>
14c9c12d33SAleksey Makarov #include <linux/net_tstamp.h>
15c9c12d33SAleksey Makarov #include <linux/ptp_clock_kernel.h>
16c9c12d33SAleksey Makarov #include <linux/timecounter.h>
17956fb852SSrujana Challa #include <linux/soc/marvell/octeontx2/asm.h>
1848c0db05SSubbaraya Sundeep #include <net/macsec.h>
191d4d9e42SNaveen Mamindlapalli #include <net/pkt_cls.h>
202da48943SSunil Goutham #include <net/devlink.h>
2174c1b233SNaveen Mamindlapalli #include <linux/time64.h>
226e144b47SSuman Ghosh #include <linux/dim.h>
23c54ffc73SSubbaraya Sundeep #include <uapi/linux/if_macsec.h>
2416547577SSunil Goutham 
255a6d7c9dSSunil Goutham #include <mbox.h>
26f0a1913fSSubbaraya Sundeep #include <npc.h>
2716547577SSunil Goutham #include "otx2_reg.h"
28caa2da34SSunil Goutham #include "otx2_txrx.h"
292da48943SSunil Goutham #include "otx2_devlink.h"
3031a97460SSubbaraya Sundeep #include <rvu_trace.h>
31ab6dddd2SSubbaraya Sundeep #include "qos.h"
3216547577SSunil Goutham 
33c672e372SSuman Ghosh /* IPv4 flag more fragment bit */
34c672e372SSuman Ghosh #define IPV4_FLAG_MORE				0x20
35c672e372SSuman Ghosh 
3616547577SSunil Goutham /* PCI device IDs */
3716547577SSunil Goutham #define PCI_DEVID_OCTEONTX2_RVU_PF              0xA063
383184fb5bSTomasz Duszynski #define PCI_DEVID_OCTEONTX2_RVU_VF		0xA064
393184fb5bSTomasz Duszynski #define PCI_DEVID_OCTEONTX2_RVU_AFVF		0xA0F8
4016547577SSunil Goutham 
4104a21ef3SSunil Goutham #define PCI_SUBSYS_DEVID_96XX_RVU_PFVF		0xB200
42c54ffc73SSubbaraya Sundeep #define PCI_SUBSYS_DEVID_CN10K_B_RVU_PFVF	0xBD00
4304a21ef3SSunil Goutham 
4416547577SSunil Goutham /* PCI BAR nos */
4516547577SSunil Goutham #define PCI_CFG_REG_BAR_NUM                     2
465a6d7c9dSSunil Goutham #define PCI_MBOX_BAR_NUM                        4
475a6d7c9dSSunil Goutham 
485a6d7c9dSSunil Goutham #define NAME_SIZE                               32
495a6d7c9dSSunil Goutham 
5099c969a8SSuman Ghosh #ifdef CONFIG_DCB
5199c969a8SSuman Ghosh /* Max priority supported for PFC */
5299c969a8SSuman Ghosh #define NIX_PF_PFC_PRIO_MAX			8
5399c969a8SSuman Ghosh #endif
5499c969a8SSuman Ghosh 
55caa2da34SSunil Goutham enum arua_mapped_qtypes {
56caa2da34SSunil Goutham 	AURA_NIX_RQ,
57caa2da34SSunil Goutham 	AURA_NIX_SQ,
5805fcc9e0SSunil Goutham };
5905fcc9e0SSunil Goutham 
6004a21ef3SSunil Goutham /* NIX LF interrupts range*/
6104a21ef3SSunil Goutham #define NIX_LF_QINT_VEC_START			0x00
6204a21ef3SSunil Goutham #define NIX_LF_CINT_VEC_START			0x40
6304a21ef3SSunil Goutham #define NIX_LF_GINT_VEC				0x80
6404a21ef3SSunil Goutham #define NIX_LF_ERR_VEC				0x81
6504a21ef3SSunil Goutham #define NIX_LF_POISON_VEC			0x82
6604a21ef3SSunil Goutham 
674c236d5dSGeetha sowjanya /* Send skid of 2000 packets required for CQ size of 4K CQEs. */
684c236d5dSGeetha sowjanya #define SEND_CQ_SKID	2000
694c236d5dSGeetha sowjanya 
706e144b47SSuman Ghosh #define OTX2_GET_RX_STATS(reg) \
716e144b47SSuman Ghosh 	otx2_read64(pfvf, NIX_LF_RX_STATX(reg))
726e144b47SSuman Ghosh #define OTX2_GET_TX_STATS(reg) \
736e144b47SSuman Ghosh 	otx2_read64(pfvf, NIX_LF_TX_STATX(reg))
746e144b47SSuman Ghosh 
75ef6c8da7SGeetha sowjanya struct otx2_lmt_info {
76ef6c8da7SGeetha sowjanya 	u64 lmt_addr;
77ef6c8da7SGeetha sowjanya 	u16 lmt_id;
78ef6c8da7SGeetha sowjanya };
7985069e95SSunil Goutham /* RSS configuration */
8081a43620SGeetha sowjanya struct otx2_rss_ctx {
8181a43620SGeetha sowjanya 	u8  ind_tbl[MAX_RSS_INDIR_TBL_SIZE];
8281a43620SGeetha sowjanya };
8381a43620SGeetha sowjanya 
8485069e95SSunil Goutham struct otx2_rss_info {
8585069e95SSunil Goutham 	u8 enable;
8685069e95SSunil Goutham 	u32 flowkey_cfg;
8785069e95SSunil Goutham 	u16 rss_size;
8885069e95SSunil Goutham #define RSS_HASH_KEY_SIZE	44   /* 352 bit key */
8985069e95SSunil Goutham 	u8  key[RSS_HASH_KEY_SIZE];
9081a43620SGeetha sowjanya 	struct otx2_rss_ctx	*rss_ctx[MAX_RSS_GROUPS];
9185069e95SSunil Goutham };
9285069e95SSunil Goutham 
93abe02543SSunil Goutham /* NIX (or NPC) RX errors */
94abe02543SSunil Goutham enum otx2_errlvl {
95abe02543SSunil Goutham 	NPC_ERRLVL_RE,
96abe02543SSunil Goutham 	NPC_ERRLVL_LID_LA,
97abe02543SSunil Goutham 	NPC_ERRLVL_LID_LB,
98abe02543SSunil Goutham 	NPC_ERRLVL_LID_LC,
99abe02543SSunil Goutham 	NPC_ERRLVL_LID_LD,
100abe02543SSunil Goutham 	NPC_ERRLVL_LID_LE,
101abe02543SSunil Goutham 	NPC_ERRLVL_LID_LF,
102abe02543SSunil Goutham 	NPC_ERRLVL_LID_LG,
103abe02543SSunil Goutham 	NPC_ERRLVL_LID_LH,
104abe02543SSunil Goutham 	NPC_ERRLVL_NIX = 0x0F,
105abe02543SSunil Goutham };
106abe02543SSunil Goutham 
107abe02543SSunil Goutham enum otx2_errcodes_re {
108abe02543SSunil Goutham 	/* NPC_ERRLVL_RE errcodes */
109abe02543SSunil Goutham 	ERRCODE_FCS = 0x7,
110abe02543SSunil Goutham 	ERRCODE_FCS_RCV = 0x8,
111abe02543SSunil Goutham 	ERRCODE_UNDERSIZE = 0x10,
112abe02543SSunil Goutham 	ERRCODE_OVERSIZE = 0x11,
113abe02543SSunil Goutham 	ERRCODE_OL2_LEN_MISMATCH = 0x12,
114abe02543SSunil Goutham 	/* NPC_ERRLVL_NIX errcodes */
115abe02543SSunil Goutham 	ERRCODE_OL3_LEN = 0x10,
116abe02543SSunil Goutham 	ERRCODE_OL4_LEN = 0x11,
117abe02543SSunil Goutham 	ERRCODE_OL4_CSUM = 0x12,
118abe02543SSunil Goutham 	ERRCODE_IL3_LEN = 0x20,
119abe02543SSunil Goutham 	ERRCODE_IL4_LEN = 0x21,
120abe02543SSunil Goutham 	ERRCODE_IL4_CSUM = 0x22,
121abe02543SSunil Goutham };
122abe02543SSunil Goutham 
123e239d0c7SGeetha sowjanya /* NIX TX stats */
124e239d0c7SGeetha sowjanya enum nix_stat_lf_tx {
125e239d0c7SGeetha sowjanya 	TX_UCAST	= 0x0,
126e239d0c7SGeetha sowjanya 	TX_BCAST	= 0x1,
127e239d0c7SGeetha sowjanya 	TX_MCAST	= 0x2,
128e239d0c7SGeetha sowjanya 	TX_DROP		= 0x3,
129e239d0c7SGeetha sowjanya 	TX_OCTS		= 0x4,
130e239d0c7SGeetha sowjanya 	TX_STATS_ENUM_LAST,
131e239d0c7SGeetha sowjanya };
132e239d0c7SGeetha sowjanya 
133e239d0c7SGeetha sowjanya /* NIX RX stats */
134e239d0c7SGeetha sowjanya enum nix_stat_lf_rx {
135e239d0c7SGeetha sowjanya 	RX_OCTS		= 0x0,
136e239d0c7SGeetha sowjanya 	RX_UCAST	= 0x1,
137e239d0c7SGeetha sowjanya 	RX_BCAST	= 0x2,
138e239d0c7SGeetha sowjanya 	RX_MCAST	= 0x3,
139e239d0c7SGeetha sowjanya 	RX_DROP		= 0x4,
140e239d0c7SGeetha sowjanya 	RX_DROP_OCTS	= 0x5,
141e239d0c7SGeetha sowjanya 	RX_FCS		= 0x6,
142e239d0c7SGeetha sowjanya 	RX_ERR		= 0x7,
143e239d0c7SGeetha sowjanya 	RX_DRP_BCAST	= 0x8,
144e239d0c7SGeetha sowjanya 	RX_DRP_MCAST	= 0x9,
145e239d0c7SGeetha sowjanya 	RX_DRP_L3BCAST	= 0xa,
146e239d0c7SGeetha sowjanya 	RX_DRP_L3MCAST	= 0xb,
147e239d0c7SGeetha sowjanya 	RX_STATS_ENUM_LAST,
148e239d0c7SGeetha sowjanya };
149e239d0c7SGeetha sowjanya 
150e239d0c7SGeetha sowjanya struct otx2_dev_stats {
151e239d0c7SGeetha sowjanya 	u64 rx_bytes;
152e239d0c7SGeetha sowjanya 	u64 rx_frames;
153e239d0c7SGeetha sowjanya 	u64 rx_ucast_frames;
154e239d0c7SGeetha sowjanya 	u64 rx_bcast_frames;
155e239d0c7SGeetha sowjanya 	u64 rx_mcast_frames;
156e239d0c7SGeetha sowjanya 	u64 rx_drops;
157e239d0c7SGeetha sowjanya 
158e239d0c7SGeetha sowjanya 	u64 tx_bytes;
159e239d0c7SGeetha sowjanya 	u64 tx_frames;
160e239d0c7SGeetha sowjanya 	u64 tx_ucast_frames;
161e239d0c7SGeetha sowjanya 	u64 tx_bcast_frames;
162e239d0c7SGeetha sowjanya 	u64 tx_mcast_frames;
163e239d0c7SGeetha sowjanya 	u64 tx_drops;
164e239d0c7SGeetha sowjanya };
165e239d0c7SGeetha sowjanya 
166abe02543SSunil Goutham /* Driver counted stats */
167abe02543SSunil Goutham struct otx2_drv_stats {
168abe02543SSunil Goutham 	atomic_t rx_fcs_errs;
169abe02543SSunil Goutham 	atomic_t rx_oversize_errs;
170abe02543SSunil Goutham 	atomic_t rx_undersize_errs;
171abe02543SSunil Goutham 	atomic_t rx_csum_errs;
172abe02543SSunil Goutham 	atomic_t rx_len_errs;
173abe02543SSunil Goutham 	atomic_t rx_other_errs;
174abe02543SSunil Goutham };
175abe02543SSunil Goutham 
1765a6d7c9dSSunil Goutham struct mbox {
1775a6d7c9dSSunil Goutham 	struct otx2_mbox	mbox;
1785a6d7c9dSSunil Goutham 	struct work_struct	mbox_wrk;
1795a6d7c9dSSunil Goutham 	struct otx2_mbox	mbox_up;
1805a6d7c9dSSunil Goutham 	struct work_struct	mbox_up_wrk;
1815a6d7c9dSSunil Goutham 	struct otx2_nic		*pfvf;
1825a6d7c9dSSunil Goutham 	void			*bbuf_base; /* Bounce buffer for mbox memory */
1835a6d7c9dSSunil Goutham 	struct mutex		lock;	/* serialize mailbox access */
1845a6d7c9dSSunil Goutham 	int			num_msgs; /* mbox number of messages */
1855a6d7c9dSSunil Goutham 	int			up_num_msgs; /* mbox_up number of messages */
1865a6d7c9dSSunil Goutham };
18716547577SSunil Goutham 
188cb748a7eSHariprasad Kelam /* Egress rate limiting definitions */
189cb748a7eSHariprasad Kelam #define MAX_BURST_EXPONENT		0x0FULL
190cb748a7eSHariprasad Kelam #define MAX_BURST_MANTISSA		0xFFULL
191cb748a7eSHariprasad Kelam #define MAX_BURST_SIZE			130816ULL
192cb748a7eSHariprasad Kelam #define MAX_RATE_DIVIDER_EXPONENT	12ULL
193cb748a7eSHariprasad Kelam #define MAX_RATE_EXPONENT		0x0FULL
194cb748a7eSHariprasad Kelam #define MAX_RATE_MANTISSA		0xFFULL
195cb748a7eSHariprasad Kelam 
196cb748a7eSHariprasad Kelam /* Bitfields in NIX_TLX_PIR register */
197cb748a7eSHariprasad Kelam #define TLX_RATE_MANTISSA		GENMASK_ULL(8, 1)
198cb748a7eSHariprasad Kelam #define TLX_RATE_EXPONENT		GENMASK_ULL(12, 9)
199cb748a7eSHariprasad Kelam #define TLX_RATE_DIVIDER_EXPONENT	GENMASK_ULL(16, 13)
200cb748a7eSHariprasad Kelam #define TLX_BURST_MANTISSA		GENMASK_ULL(36, 29)
201cb748a7eSHariprasad Kelam #define TLX_BURST_EXPONENT		GENMASK_ULL(40, 37)
202cb748a7eSHariprasad Kelam 
20316547577SSunil Goutham struct otx2_hw {
20416547577SSunil Goutham 	struct pci_dev		*pdev;
20585069e95SSunil Goutham 	struct otx2_rss_info	rss_info;
20616547577SSunil Goutham 	u16                     rx_queues;
20716547577SSunil Goutham 	u16                     tx_queues;
20806059a1aSGeetha sowjanya 	u16                     xdp_queues;
209ab6dddd2SSubbaraya Sundeep 	u16			tc_tx_queues;
210508c58f7SHariprasad Kelam 	u16                     non_qos_queues; /* tx queues plus xdp queues */
21116547577SSunil Goutham 	u16			max_queues;
21205fcc9e0SSunil Goutham 	u16			pool_cnt;
213caa2da34SSunil Goutham 	u16			rqpool_cnt;
214caa2da34SSunil Goutham 	u16			sqpool_cnt;
21505fcc9e0SSunil Goutham 
216a989eb66SSubbaraya Sundeep #define OTX2_DEFAULT_RBUF_LEN	2048
217a989eb66SSubbaraya Sundeep 	u16			rbuf_len;
21868258596SSubbaraya Sundeep 	u32			xqe_size;
219a989eb66SSubbaraya Sundeep 
22005fcc9e0SSunil Goutham 	/* NPA */
22105fcc9e0SSunil Goutham 	u32			stack_pg_ptrs;  /* No of ptrs per stack page */
22205fcc9e0SSunil Goutham 	u32			stack_pg_bytes; /* Size of stack page */
22305fcc9e0SSunil Goutham 	u16			sqb_size;
22405fcc9e0SSunil Goutham 
225caa2da34SSunil Goutham 	/* NIX */
22613c9f4dcSNaveen Mamindlapalli 	u8			txschq_link_cfg_lvl;
22747a9656fSNaveen Mamindlapalli 	u8			txschq_aggr_lvl_rr_prio;
228caa2da34SSunil Goutham 	u16			txschq_list[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
2292ca89a2cSSunil Goutham 	u16			matchall_ipolicer;
230c39830a4SSunil Goutham 	u32			dwrr_mtu;
231bbba125eSSunil Goutham 	u8			smq_link_type;
232caa2da34SSunil Goutham 
233caa2da34SSunil Goutham 	/* HW settings, coalescing etc */
23405fcc9e0SSunil Goutham 	u16			rx_chan_base;
23505fcc9e0SSunil Goutham 	u16			tx_chan_base;
23604a21ef3SSunil Goutham 	u16			cq_qcount_wait;
23704a21ef3SSunil Goutham 	u16			cq_ecount_wait;
238caa2da34SSunil Goutham 	u16			rq_skid;
23904a21ef3SSunil Goutham 	u8			cq_time_wait;
2405a6d7c9dSSunil Goutham 
241dc1a9bf2SSunil Goutham 	/* Segmentation */
24286d74760SSunil Goutham 	u8			lso_tsov4_idx;
24386d74760SSunil Goutham 	u8			lso_tsov6_idx;
244dc1a9bf2SSunil Goutham 	u8			lso_udpv4_idx;
245dc1a9bf2SSunil Goutham 	u8			lso_udpv6_idx;
24686d74760SSunil Goutham 
247e7938365SSunil Goutham 	/* RSS */
248e7938365SSunil Goutham 	u8			flowkey_alg_idx;
249e7938365SSunil Goutham 
2505a6d7c9dSSunil Goutham 	/* MSI-X */
25104a21ef3SSunil Goutham 	u8			cint_cnt; /* CQ interrupt count */
25205fcc9e0SSunil Goutham 	u16			npa_msixoff; /* Offset of NPA vectors */
25305fcc9e0SSunil Goutham 	u16			nix_msixoff; /* Offset of NIX vectors */
2545a6d7c9dSSunil Goutham 	char			*irq_name;
2555a6d7c9dSSunil Goutham 	cpumask_var_t           *affinity_mask;
256abe02543SSunil Goutham 
257abe02543SSunil Goutham 	/* Stats */
258e239d0c7SGeetha sowjanya 	struct otx2_dev_stats	dev_stats;
259abe02543SSunil Goutham 	struct otx2_drv_stats	drv_stats;
260d45d8979SChristina Jacob 	u64			cgx_rx_stats[CGX_RX_STATS_COUNT];
261d45d8979SChristina Jacob 	u64			cgx_tx_stats[CGX_TX_STATS_COUNT];
262d0cf9503SChristina Jacob 	u64			cgx_fec_corr_blks;
263d0cf9503SChristina Jacob 	u64			cgx_fec_uncorr_blks;
2648bcf5cedSSubbaraya Sundeep 	u8			cgx_links;  /* No. of CGX links present in HW */
2658bcf5cedSSubbaraya Sundeep 	u8			lbk_links;  /* No. of LBK links present in HW */
266039190bbSSubbaraya Sundeep 	u8			tx_link;    /* Transmit channel link number */
267c7766260SDan Carpenter #define HW_TSO			0
268c7766260SDan Carpenter #define CN10K_MBOX		1
269c7766260SDan Carpenter #define CN10K_LMTST		2
27063f85c40SHariprasad Kelam #define CN10K_RPM		3
2712958d17aSHariprasad Kelam #define CN10K_PTP_ONESTEP	4
272c54ffc73SSubbaraya Sundeep #define CN10K_HW_MACSEC		5
273cb748a7eSHariprasad Kelam #define QOS_CIR_PIR_SUPPORT	6
274facede82SSubbaraya Sundeep 	unsigned long		cap_flag;
2756e8ad438SGeetha sowjanya 
2766e8ad438SGeetha sowjanya #define LMT_LINE_SIZE		128
2775c051207SGeetha sowjanya #define LMT_BURST_SIZE		32 /* 32 LMTST lines for burst SQE flush */
2785c051207SGeetha sowjanya 	u64			*lmt_base;
279ef6c8da7SGeetha sowjanya 	struct otx2_lmt_info	__percpu *lmt_info;
28016547577SSunil Goutham };
28116547577SSunil Goutham 
282b1dc2040SHariprasad Kelam enum vfperm {
283b1dc2040SHariprasad Kelam 	OTX2_RESET_VF_PERM,
284b1dc2040SHariprasad Kelam 	OTX2_TRUSTED_VF,
285b1dc2040SHariprasad Kelam };
286b1dc2040SHariprasad Kelam 
287ad513ed9STomasz Duszynski struct otx2_vf_config {
288ad513ed9STomasz Duszynski 	struct otx2_nic *pf;
289ad513ed9STomasz Duszynski 	struct delayed_work link_event_work;
290ad513ed9STomasz Duszynski 	bool intf_down; /* interface was either configured or not */
291f0c2982aSNaveen Mamindlapalli 	u8 mac[ETH_ALEN];
292f0c2982aSNaveen Mamindlapalli 	u16 vlan;
293f0c2982aSNaveen Mamindlapalli 	int tx_vtag_idx;
294b1dc2040SHariprasad Kelam 	bool trusted;
295ad513ed9STomasz Duszynski };
296ad513ed9STomasz Duszynski 
297547d20f1SGeetha sowjanya struct flr_work {
298547d20f1SGeetha sowjanya 	struct work_struct work;
299547d20f1SGeetha sowjanya 	struct otx2_nic *pf;
300547d20f1SGeetha sowjanya };
301547d20f1SGeetha sowjanya 
3024ff7d148SGeetha sowjanya struct refill_work {
3034ff7d148SGeetha sowjanya 	struct delayed_work pool_refill_work;
3044ff7d148SGeetha sowjanya 	struct otx2_nic *pf;
30588e69af0SRatheesh Kannoth 	struct napi_struct *napi;
3064ff7d148SGeetha sowjanya };
3074ff7d148SGeetha sowjanya 
3082958d17aSHariprasad Kelam /* PTPv2 originTimestamp structure */
3092958d17aSHariprasad Kelam struct ptpv2_tstamp {
3102958d17aSHariprasad Kelam 	__be16 seconds_msb; /* 16 bits + */
3112958d17aSHariprasad Kelam 	__be32 seconds_lsb; /* 32 bits = 48 bits*/
3122958d17aSHariprasad Kelam 	__be32 nanoseconds;
3132958d17aSHariprasad Kelam } __packed;
3142958d17aSHariprasad Kelam 
315c9c12d33SAleksey Makarov struct otx2_ptp {
316c9c12d33SAleksey Makarov 	struct ptp_clock_info ptp_info;
317c9c12d33SAleksey Makarov 	struct ptp_clock *ptp_clock;
318c9c12d33SAleksey Makarov 	struct otx2_nic *nic;
319c9c12d33SAleksey Makarov 
320c9c12d33SAleksey Makarov 	struct cyclecounter cycle_counter;
321c9c12d33SAleksey Makarov 	struct timecounter time_counter;
32299bbc4aeSYi Guo 
32399bbc4aeSYi Guo 	struct delayed_work extts_work;
32499bbc4aeSYi Guo 	u64 last_extts;
32599bbc4aeSYi Guo 	u64 thresh;
32699bbc4aeSYi Guo 
32799bbc4aeSYi Guo 	struct ptp_pin_desc extts_config;
32874c1b233SNaveen Mamindlapalli 	u64 (*convert_rx_ptp_tstmp)(u64 timestamp);
32974c1b233SNaveen Mamindlapalli 	u64 (*convert_tx_ptp_tstmp)(u64 timestamp);
330bdf79b12SSai Krishna 	u64 (*ptp_tstamp2nsec)(const struct timecounter *time_counter, u64 timestamp);
3312958d17aSHariprasad Kelam 	struct delayed_work synctstamp_work;
3322958d17aSHariprasad Kelam 	u64 tstamp;
3332958d17aSHariprasad Kelam 	u32 base_ns;
334c9c12d33SAleksey Makarov };
335c9c12d33SAleksey Makarov 
336c9c12d33SAleksey Makarov #define OTX2_HW_TIMESTAMP_LEN	8
337c9c12d33SAleksey Makarov 
33863ee5157SHariprasad Kelam struct otx2_mac_table {
33963ee5157SHariprasad Kelam 	u8 addr[ETH_ALEN];
34063ee5157SHariprasad Kelam 	u16 mcam_entry;
34163ee5157SHariprasad Kelam 	bool inuse;
34263ee5157SHariprasad Kelam };
34363ee5157SHariprasad Kelam 
344f0a1913fSSubbaraya Sundeep struct otx2_flow_config {
3459917060fSSunil Goutham 	u16			*flow_ent;
3469917060fSSunil Goutham 	u16			*def_ent;
3479917060fSSunil Goutham 	u16			nr_flows;
3489917060fSSunil Goutham #define OTX2_DEFAULT_FLOWCOUNT		16
34963ee5157SHariprasad Kelam #define OTX2_MAX_UNICAST_FLOWS		8
350fd9d7859SHariprasad Kelam #define OTX2_MAX_VLAN_FLOWS		1
3519917060fSSunil Goutham #define OTX2_MAX_TC_FLOWS	OTX2_DEFAULT_FLOWCOUNT
3529917060fSSunil Goutham #define OTX2_MCAM_COUNT		(OTX2_DEFAULT_FLOWCOUNT + \
353fd9d7859SHariprasad Kelam 				 OTX2_MAX_UNICAST_FLOWS + \
354fd9d7859SHariprasad Kelam 				 OTX2_MAX_VLAN_FLOWS)
3559917060fSSunil Goutham 	u16			unicast_offset;
3569917060fSSunil Goutham 	u16			rx_vlan_offset;
3579917060fSSunil Goutham 	u16			vf_vlan_offset;
3589917060fSSunil Goutham #define OTX2_PER_VF_VLAN_FLOWS	2 /* Rx + Tx per VF */
359f0c2982aSNaveen Mamindlapalli #define OTX2_VF_VLAN_RX_INDEX	0
360f0c2982aSNaveen Mamindlapalli #define OTX2_VF_VLAN_TX_INDEX	1
361fa5e0ccbSRatheesh Kannoth 	u32			*bmap_to_dmacindex;
362fa5e0ccbSRatheesh Kannoth 	unsigned long		*dmacflt_bmap;
363f0a1913fSSubbaraya Sundeep 	struct list_head	flow_list;
3642a6eecc5SRatheesh Kannoth 	u32			dmacflt_max_flows;
3652a6eecc5SRatheesh Kannoth 	u16                     max_flows;
366ec87f054SSuman Ghosh 	struct list_head	flow_list_tc;
367ec87f054SSuman Ghosh 	bool			ntuple;
3681d4d9e42SNaveen Mamindlapalli };
3691d4d9e42SNaveen Mamindlapalli 
3704c236d5dSGeetha sowjanya struct dev_hw_ops {
3714c236d5dSGeetha sowjanya 	int	(*sq_aq_init)(void *dev, u16 qidx, u16 sqb_aura);
3724c236d5dSGeetha sowjanya 	void	(*sqe_flush)(void *dev, struct otx2_snd_queue *sq,
3734c236d5dSGeetha sowjanya 			     int size, int qidx);
37488e69af0SRatheesh Kannoth 	int	(*refill_pool_ptrs)(void *dev, struct otx2_cq_queue *cq);
3754c236d5dSGeetha sowjanya 	void	(*aura_freeptr)(void *dev, int aura, u64 buf);
3764c236d5dSGeetha sowjanya };
3774c236d5dSGeetha sowjanya 
378c54ffc73SSubbaraya Sundeep #define CN10K_MCS_SA_PER_SC	4
379c54ffc73SSubbaraya Sundeep 
380c54ffc73SSubbaraya Sundeep /* Stats which need to be accumulated in software because
381c54ffc73SSubbaraya Sundeep  * of shared counters in hardware.
382c54ffc73SSubbaraya Sundeep  */
383c54ffc73SSubbaraya Sundeep struct cn10k_txsc_stats {
384c54ffc73SSubbaraya Sundeep 	u64 InPktsUntagged;
385c54ffc73SSubbaraya Sundeep 	u64 InPktsNoTag;
386c54ffc73SSubbaraya Sundeep 	u64 InPktsBadTag;
387c54ffc73SSubbaraya Sundeep 	u64 InPktsUnknownSCI;
388c54ffc73SSubbaraya Sundeep 	u64 InPktsNoSCI;
389c54ffc73SSubbaraya Sundeep 	u64 InPktsOverrun;
390c54ffc73SSubbaraya Sundeep };
391c54ffc73SSubbaraya Sundeep 
392c54ffc73SSubbaraya Sundeep struct cn10k_rxsc_stats {
393c54ffc73SSubbaraya Sundeep 	u64 InOctetsValidated;
394c54ffc73SSubbaraya Sundeep 	u64 InOctetsDecrypted;
395c54ffc73SSubbaraya Sundeep 	u64 InPktsUnchecked;
396c54ffc73SSubbaraya Sundeep 	u64 InPktsDelayed;
397c54ffc73SSubbaraya Sundeep 	u64 InPktsOK;
398c54ffc73SSubbaraya Sundeep 	u64 InPktsInvalid;
399c54ffc73SSubbaraya Sundeep 	u64 InPktsLate;
400c54ffc73SSubbaraya Sundeep 	u64 InPktsNotValid;
401c54ffc73SSubbaraya Sundeep 	u64 InPktsNotUsingSA;
402c54ffc73SSubbaraya Sundeep 	u64 InPktsUnusedSA;
403c54ffc73SSubbaraya Sundeep };
404c54ffc73SSubbaraya Sundeep 
405c54ffc73SSubbaraya Sundeep struct cn10k_mcs_txsc {
406c54ffc73SSubbaraya Sundeep 	struct macsec_secy *sw_secy;
407c54ffc73SSubbaraya Sundeep 	struct cn10k_txsc_stats stats;
408c54ffc73SSubbaraya Sundeep 	struct list_head entry;
409c54ffc73SSubbaraya Sundeep 	enum macsec_validation_type last_validate_frames;
4109bdfe610SSubbaraya Sundeep 	bool last_replay_protect;
411c54ffc73SSubbaraya Sundeep 	u16 hw_secy_id_tx;
412c54ffc73SSubbaraya Sundeep 	u16 hw_secy_id_rx;
413c54ffc73SSubbaraya Sundeep 	u16 hw_flow_id;
414c54ffc73SSubbaraya Sundeep 	u16 hw_sc_id;
415c54ffc73SSubbaraya Sundeep 	u16 hw_sa_id[CN10K_MCS_SA_PER_SC];
416c54ffc73SSubbaraya Sundeep 	u8 sa_bmap;
417c54ffc73SSubbaraya Sundeep 	u8 sa_key[CN10K_MCS_SA_PER_SC][MACSEC_MAX_KEY_LEN];
418c54ffc73SSubbaraya Sundeep 	u8 encoding_sa;
41948c0db05SSubbaraya Sundeep 	u8 salt[CN10K_MCS_SA_PER_SC][MACSEC_SALT_LEN];
42048c0db05SSubbaraya Sundeep 	ssci_t ssci[CN10K_MCS_SA_PER_SC];
421030d71fdSSubbaraya Sundeep 	bool vlan_dev; /* macsec running on VLAN ? */
422c54ffc73SSubbaraya Sundeep };
423c54ffc73SSubbaraya Sundeep 
424c54ffc73SSubbaraya Sundeep struct cn10k_mcs_rxsc {
425c54ffc73SSubbaraya Sundeep 	struct macsec_secy *sw_secy;
426c54ffc73SSubbaraya Sundeep 	struct macsec_rx_sc *sw_rxsc;
427c54ffc73SSubbaraya Sundeep 	struct cn10k_rxsc_stats stats;
428c54ffc73SSubbaraya Sundeep 	struct list_head entry;
429c54ffc73SSubbaraya Sundeep 	u16 hw_flow_id;
430c54ffc73SSubbaraya Sundeep 	u16 hw_sc_id;
431c54ffc73SSubbaraya Sundeep 	u16 hw_sa_id[CN10K_MCS_SA_PER_SC];
432c54ffc73SSubbaraya Sundeep 	u8 sa_bmap;
433c54ffc73SSubbaraya Sundeep 	u8 sa_key[CN10K_MCS_SA_PER_SC][MACSEC_MAX_KEY_LEN];
43448c0db05SSubbaraya Sundeep 	u8 salt[CN10K_MCS_SA_PER_SC][MACSEC_SALT_LEN];
43548c0db05SSubbaraya Sundeep 	ssci_t ssci[CN10K_MCS_SA_PER_SC];
436c54ffc73SSubbaraya Sundeep };
437c54ffc73SSubbaraya Sundeep 
438c54ffc73SSubbaraya Sundeep struct cn10k_mcs_cfg {
439c54ffc73SSubbaraya Sundeep 	struct list_head txsc_list;
440c54ffc73SSubbaraya Sundeep 	struct list_head rxsc_list;
441c54ffc73SSubbaraya Sundeep };
442c54ffc73SSubbaraya Sundeep 
44316547577SSunil Goutham struct otx2_nic {
44416547577SSunil Goutham 	void __iomem		*reg_base;
44516547577SSunil Goutham 	struct net_device	*netdev;
4464c236d5dSGeetha sowjanya 	struct dev_hw_ops	*hw_ops;
447caa2da34SSunil Goutham 	void			*iommu_domain;
4480182d078SSubbaraya Sundeep 	u16			tx_max_pktlen;
449caa2da34SSunil Goutham 	u16			rbsize; /* Receive buffer size */
45016547577SSunil Goutham 
451c9c12d33SAleksey Makarov #define OTX2_FLAG_RX_TSTAMP_ENABLED		BIT_ULL(0)
452c9c12d33SAleksey Makarov #define OTX2_FLAG_TX_TSTAMP_ENABLED		BIT_ULL(1)
45350fe6c02SLinu Cherian #define OTX2_FLAG_INTF_DOWN			BIT_ULL(2)
454f0a1913fSSubbaraya Sundeep #define OTX2_FLAG_MCAM_ENTRIES_ALLOC		BIT_ULL(3)
455f0a1913fSSubbaraya Sundeep #define OTX2_FLAG_NTUPLE_SUPPORT		BIT_ULL(4)
45663ee5157SHariprasad Kelam #define OTX2_FLAG_UCAST_FLTR_SUPPORT		BIT_ULL(5)
457fd9d7859SHariprasad Kelam #define OTX2_FLAG_RX_VLAN_SUPPORT		BIT_ULL(6)
458f0c2982aSNaveen Mamindlapalli #define OTX2_FLAG_VF_VLAN_SUPPORT		BIT_ULL(7)
459f0c2982aSNaveen Mamindlapalli #define OTX2_FLAG_PF_SHUTDOWN			BIT_ULL(8)
46075f36270SGeetha sowjanya #define OTX2_FLAG_RX_PAUSE_ENABLED		BIT_ULL(9)
46175f36270SGeetha sowjanya #define OTX2_FLAG_TX_PAUSE_ENABLED		BIT_ULL(10)
4621d4d9e42SNaveen Mamindlapalli #define OTX2_FLAG_TC_FLOWER_SUPPORT		BIT_ULL(11)
463e638a83fSSunil Goutham #define OTX2_FLAG_TC_MATCHALL_EGRESS_ENABLED	BIT_ULL(12)
4642ca89a2cSSunil Goutham #define OTX2_FLAG_TC_MATCHALL_INGRESS_ENABLED	BIT_ULL(13)
46579d2be38SHariprasad Kelam #define OTX2_FLAG_DMACFLTR_SUPPORT		BIT_ULL(14)
4662958d17aSHariprasad Kelam #define OTX2_FLAG_PTP_ONESTEP_SYNC		BIT_ULL(15)
4676e144b47SSuman Ghosh #define OTX2_FLAG_ADPTV_INT_COAL_ENABLED BIT_ULL(16)
46850fe6c02SLinu Cherian 	u64			flags;
469af3826dbSGeetha sowjanya 	u64			*cq_op_addr;
47050fe6c02SLinu Cherian 
47106059a1aSGeetha sowjanya 	struct bpf_prog		*xdp_prog;
47205fcc9e0SSunil Goutham 	struct otx2_qset	qset;
47316547577SSunil Goutham 	struct otx2_hw		hw;
47416547577SSunil Goutham 	struct pci_dev		*pdev;
47516547577SSunil Goutham 	struct device		*dev;
4765a6d7c9dSSunil Goutham 
4775a6d7c9dSSunil Goutham 	/* Mbox */
4785a6d7c9dSSunil Goutham 	struct mbox		mbox;
479d424b6c0SSunil Goutham 	struct mbox		*mbox_pfvf;
4805a6d7c9dSSunil Goutham 	struct workqueue_struct *mbox_wq;
481d424b6c0SSunil Goutham 	struct workqueue_struct *mbox_pfvf_wq;
4825a6d7c9dSSunil Goutham 
483d424b6c0SSunil Goutham 	u8			total_vfs;
4845a6d7c9dSSunil Goutham 	u16			pcifunc; /* RVU PF_FUNC */
48575f36270SGeetha sowjanya 	u16			bpid[NIX_MAX_BPID_CHAN];
486ad513ed9STomasz Duszynski 	struct otx2_vf_config	*vf_configs;
48750fe6c02SLinu Cherian 	struct cgx_link_user_info linfo;
488caa2da34SSunil Goutham 
4892e2a8126SSunil Goutham 	/* NPC MCAM */
4902e2a8126SSunil Goutham 	struct otx2_flow_config	*flow_cfg;
4912e2a8126SSunil Goutham 	struct otx2_mac_table	*mac_table;
4922e2a8126SSunil Goutham 
4934ff7d148SGeetha sowjanya 	u64			reset_count;
4944ff7d148SGeetha sowjanya 	struct work_struct	reset_task;
495547d20f1SGeetha sowjanya 	struct workqueue_struct	*flr_wq;
496547d20f1SGeetha sowjanya 	struct flr_work		*flr_wrk;
4974ff7d148SGeetha sowjanya 	struct refill_work	*refill_wrk;
498e99b7c84SSunil Goutham 	struct workqueue_struct	*otx2_wq;
499e99b7c84SSunil Goutham 	struct work_struct	rx_mode_work;
5004ff7d148SGeetha sowjanya 
5016e92d71bSSunil Goutham 	/* Ethtool stuff */
5026e92d71bSSunil Goutham 	u32			msg_enable;
5036e92d71bSSunil Goutham 
504caa2da34SSunil Goutham 	/* Block address of NIX either BLKADDR_NIX0 or BLKADDR_NIX1 */
505caa2da34SSunil Goutham 	int			nix_blkaddr;
5066e8ad438SGeetha sowjanya 	/* LMTST Lines info */
5075c051207SGeetha sowjanya 	struct qmem		*dync_lmt;
5086e8ad438SGeetha sowjanya 	u16			tot_lmt_lines;
5095c051207SGeetha sowjanya 	u16			npa_lmt_lines;
5106e8ad438SGeetha sowjanya 	u32			nix_lmt_size;
511c9c12d33SAleksey Makarov 
512c9c12d33SAleksey Makarov 	struct otx2_ptp		*ptp;
513c9c12d33SAleksey Makarov 	struct hwtstamp_config	tstamp;
514f0a1913fSSubbaraya Sundeep 
51568fbff68SSubbaraya Sundeep 	unsigned long		rq_bmap;
5162da48943SSunil Goutham 
5172da48943SSunil Goutham 	/* Devlink */
5182da48943SSunil Goutham 	struct otx2_devlink	*dl;
5198e675581SHariprasad Kelam #ifdef CONFIG_DCB
5208e675581SHariprasad Kelam 	/* PFC */
5218e675581SHariprasad Kelam 	u8			pfc_en;
5228e675581SHariprasad Kelam 	u8			*queue_to_pfc_map;
52399c969a8SSuman Ghosh 	u16			pfc_schq_list[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
52499c969a8SSuman Ghosh 	bool			pfc_alloc_status[NIX_PF_PFC_PRIO_MAX];
5258e675581SHariprasad Kelam #endif
526ab6dddd2SSubbaraya Sundeep 	/* qos */
527ab6dddd2SSubbaraya Sundeep 	struct otx2_qos		qos;
5286e144b47SSuman Ghosh 
5296e144b47SSuman Ghosh 	/* napi event count. It is needed for adaptive irq coalescing. */
5306e144b47SSuman Ghosh 	u32 napi_events;
531c54ffc73SSubbaraya Sundeep 
532c54ffc73SSubbaraya Sundeep #if IS_ENABLED(CONFIG_MACSEC)
533c54ffc73SSubbaraya Sundeep 	struct cn10k_mcs_cfg	*macsec_cfg;
534c54ffc73SSubbaraya Sundeep #endif
53516547577SSunil Goutham };
53616547577SSunil Goutham 
is_otx2_lbkvf(struct pci_dev * pdev)5373184fb5bSTomasz Duszynski static inline bool is_otx2_lbkvf(struct pci_dev *pdev)
5383184fb5bSTomasz Duszynski {
5393184fb5bSTomasz Duszynski 	return pdev->device == PCI_DEVID_OCTEONTX2_RVU_AFVF;
5403184fb5bSTomasz Duszynski }
5413184fb5bSTomasz Duszynski 
is_96xx_A0(struct pci_dev * pdev)54204a21ef3SSunil Goutham static inline bool is_96xx_A0(struct pci_dev *pdev)
54304a21ef3SSunil Goutham {
54404a21ef3SSunil Goutham 	return (pdev->revision == 0x00) &&
54504a21ef3SSunil Goutham 		(pdev->subsystem_device == PCI_SUBSYS_DEVID_96XX_RVU_PFVF);
54604a21ef3SSunil Goutham }
54704a21ef3SSunil Goutham 
is_96xx_B0(struct pci_dev * pdev)54804a21ef3SSunil Goutham static inline bool is_96xx_B0(struct pci_dev *pdev)
54904a21ef3SSunil Goutham {
55004a21ef3SSunil Goutham 	return (pdev->revision == 0x01) &&
55104a21ef3SSunil Goutham 		(pdev->subsystem_device == PCI_SUBSYS_DEVID_96XX_RVU_PFVF);
55204a21ef3SSunil Goutham }
55304a21ef3SSunil Goutham 
554facede82SSubbaraya Sundeep /* REVID for PCIe devices.
555facede82SSubbaraya Sundeep  * Bits 0..1: minor pass, bit 3..2: major pass
556facede82SSubbaraya Sundeep  * bits 7..4: midr id
557facede82SSubbaraya Sundeep  */
558facede82SSubbaraya Sundeep #define PCI_REVISION_ID_96XX		0x00
559facede82SSubbaraya Sundeep #define PCI_REVISION_ID_95XX		0x10
560ef6c8da7SGeetha sowjanya #define PCI_REVISION_ID_95XXN		0x20
561facede82SSubbaraya Sundeep #define PCI_REVISION_ID_98XX		0x30
562facede82SSubbaraya Sundeep #define PCI_REVISION_ID_95XXMM		0x40
563ef6c8da7SGeetha sowjanya #define PCI_REVISION_ID_95XXO		0xE0
564facede82SSubbaraya Sundeep 
is_dev_otx2(struct pci_dev * pdev)565facede82SSubbaraya Sundeep static inline bool is_dev_otx2(struct pci_dev *pdev)
566facede82SSubbaraya Sundeep {
567facede82SSubbaraya Sundeep 	u8 midr = pdev->revision & 0xF0;
568facede82SSubbaraya Sundeep 
569facede82SSubbaraya Sundeep 	return (midr == PCI_REVISION_ID_96XX || midr == PCI_REVISION_ID_95XX ||
570ef6c8da7SGeetha sowjanya 		midr == PCI_REVISION_ID_95XXN || midr == PCI_REVISION_ID_98XX ||
571ef6c8da7SGeetha sowjanya 		midr == PCI_REVISION_ID_95XXMM || midr == PCI_REVISION_ID_95XXO);
572facede82SSubbaraya Sundeep }
573facede82SSubbaraya Sundeep 
is_dev_cn10kb(struct pci_dev * pdev)574c54ffc73SSubbaraya Sundeep static inline bool is_dev_cn10kb(struct pci_dev *pdev)
575c54ffc73SSubbaraya Sundeep {
576c54ffc73SSubbaraya Sundeep 	return pdev->subsystem_device == PCI_SUBSYS_DEVID_CN10K_B_RVU_PFVF;
577c54ffc73SSubbaraya Sundeep }
578c54ffc73SSubbaraya Sundeep 
otx2_setup_dev_hw_settings(struct otx2_nic * pfvf)57904a21ef3SSunil Goutham static inline void otx2_setup_dev_hw_settings(struct otx2_nic *pfvf)
58004a21ef3SSunil Goutham {
58186d74760SSunil Goutham 	struct otx2_hw *hw = &pfvf->hw;
58286d74760SSunil Goutham 
58304a21ef3SSunil Goutham 	pfvf->hw.cq_time_wait = CQ_TIMER_THRESH_DEFAULT;
58404a21ef3SSunil Goutham 	pfvf->hw.cq_ecount_wait = CQ_CQE_THRESH_DEFAULT;
58504a21ef3SSunil Goutham 	pfvf->hw.cq_qcount_wait = CQ_QCOUNT_DEFAULT;
58604a21ef3SSunil Goutham 
587facede82SSubbaraya Sundeep 	__set_bit(HW_TSO, &hw->cap_flag);
58886d74760SSunil Goutham 
58904a21ef3SSunil Goutham 	if (is_96xx_A0(pfvf->pdev)) {
590facede82SSubbaraya Sundeep 		__clear_bit(HW_TSO, &hw->cap_flag);
59186d74760SSunil Goutham 
59204a21ef3SSunil Goutham 		/* Time based irq coalescing is not supported */
59304a21ef3SSunil Goutham 		pfvf->hw.cq_qcount_wait = 0x0;
59404a21ef3SSunil Goutham 
59504a21ef3SSunil Goutham 		/* Due to HW issue previous silicons required minimum
59604a21ef3SSunil Goutham 		 * 600 unused CQE to avoid CQ overflow.
59704a21ef3SSunil Goutham 		 */
59804a21ef3SSunil Goutham 		pfvf->hw.rq_skid = 600;
59904a21ef3SSunil Goutham 		pfvf->qset.rqe_cnt = Q_COUNT(Q_SIZE_1K);
60004a21ef3SSunil Goutham 	}
601786621d2SGeetha sowjanya 	if (is_96xx_B0(pfvf->pdev))
602786621d2SGeetha sowjanya 		__clear_bit(HW_TSO, &hw->cap_flag);
603786621d2SGeetha sowjanya 
6046e8ad438SGeetha sowjanya 	if (!is_dev_otx2(pfvf->pdev)) {
605facede82SSubbaraya Sundeep 		__set_bit(CN10K_MBOX, &hw->cap_flag);
6066e8ad438SGeetha sowjanya 		__set_bit(CN10K_LMTST, &hw->cap_flag);
60763f85c40SHariprasad Kelam 		__set_bit(CN10K_RPM, &hw->cap_flag);
6082958d17aSHariprasad Kelam 		__set_bit(CN10K_PTP_ONESTEP, &hw->cap_flag);
609cb748a7eSHariprasad Kelam 		__set_bit(QOS_CIR_PIR_SUPPORT, &hw->cap_flag);
6106e8ad438SGeetha sowjanya 	}
611c54ffc73SSubbaraya Sundeep 
612c54ffc73SSubbaraya Sundeep 	if (is_dev_cn10kb(pfvf->pdev))
613c54ffc73SSubbaraya Sundeep 		__set_bit(CN10K_HW_MACSEC, &hw->cap_flag);
61404a21ef3SSunil Goutham }
61504a21ef3SSunil Goutham 
61616547577SSunil Goutham /* Register read/write APIs */
otx2_get_regaddr(struct otx2_nic * nic,u64 offset)61716547577SSunil Goutham static inline void __iomem *otx2_get_regaddr(struct otx2_nic *nic, u64 offset)
61816547577SSunil Goutham {
61916547577SSunil Goutham 	u64 blkaddr;
62016547577SSunil Goutham 
62116547577SSunil Goutham 	switch ((offset >> RVU_FUNC_BLKADDR_SHIFT) & RVU_FUNC_BLKADDR_MASK) {
62216547577SSunil Goutham 	case BLKTYPE_NIX:
623caa2da34SSunil Goutham 		blkaddr = nic->nix_blkaddr;
62416547577SSunil Goutham 		break;
62516547577SSunil Goutham 	case BLKTYPE_NPA:
62616547577SSunil Goutham 		blkaddr = BLKADDR_NPA;
62716547577SSunil Goutham 		break;
62816547577SSunil Goutham 	default:
62916547577SSunil Goutham 		blkaddr = BLKADDR_RVUM;
63016547577SSunil Goutham 		break;
631ae23aae2SZheng Bin 	}
63216547577SSunil Goutham 
63316547577SSunil Goutham 	offset &= ~(RVU_FUNC_BLKADDR_MASK << RVU_FUNC_BLKADDR_SHIFT);
63416547577SSunil Goutham 	offset |= (blkaddr << RVU_FUNC_BLKADDR_SHIFT);
63516547577SSunil Goutham 
63616547577SSunil Goutham 	return nic->reg_base + offset;
63716547577SSunil Goutham }
63816547577SSunil Goutham 
otx2_write64(struct otx2_nic * nic,u64 offset,u64 val)63916547577SSunil Goutham static inline void otx2_write64(struct otx2_nic *nic, u64 offset, u64 val)
64016547577SSunil Goutham {
64116547577SSunil Goutham 	void __iomem *addr = otx2_get_regaddr(nic, offset);
64216547577SSunil Goutham 
64316547577SSunil Goutham 	writeq(val, addr);
64416547577SSunil Goutham }
64516547577SSunil Goutham 
otx2_read64(struct otx2_nic * nic,u64 offset)64616547577SSunil Goutham static inline u64 otx2_read64(struct otx2_nic *nic, u64 offset)
64716547577SSunil Goutham {
64816547577SSunil Goutham 	void __iomem *addr = otx2_get_regaddr(nic, offset);
64916547577SSunil Goutham 
65016547577SSunil Goutham 	return readq(addr);
65116547577SSunil Goutham }
65216547577SSunil Goutham 
6535a6d7c9dSSunil Goutham /* Mbox bounce buffer APIs */
otx2_mbox_bbuf_init(struct mbox * mbox,struct pci_dev * pdev)6545a6d7c9dSSunil Goutham static inline int otx2_mbox_bbuf_init(struct mbox *mbox, struct pci_dev *pdev)
6555a6d7c9dSSunil Goutham {
6565a6d7c9dSSunil Goutham 	struct otx2_mbox *otx2_mbox;
6575a6d7c9dSSunil Goutham 	struct otx2_mbox_dev *mdev;
6585a6d7c9dSSunil Goutham 
6595a6d7c9dSSunil Goutham 	mbox->bbuf_base = devm_kmalloc(&pdev->dev, MBOX_SIZE, GFP_KERNEL);
6605a6d7c9dSSunil Goutham 	if (!mbox->bbuf_base)
6615a6d7c9dSSunil Goutham 		return -ENOMEM;
6625a6d7c9dSSunil Goutham 
6635a6d7c9dSSunil Goutham 	/* Overwrite mbox mbase to point to bounce buffer, so that PF/VF
6645a6d7c9dSSunil Goutham 	 * prepare all mbox messages in bounce buffer instead of directly
6655a6d7c9dSSunil Goutham 	 * in hw mbox memory.
6665a6d7c9dSSunil Goutham 	 */
6675a6d7c9dSSunil Goutham 	otx2_mbox = &mbox->mbox;
6685a6d7c9dSSunil Goutham 	mdev = &otx2_mbox->dev[0];
6695a6d7c9dSSunil Goutham 	mdev->mbase = mbox->bbuf_base;
6705a6d7c9dSSunil Goutham 
6715a6d7c9dSSunil Goutham 	otx2_mbox = &mbox->mbox_up;
6725a6d7c9dSSunil Goutham 	mdev = &otx2_mbox->dev[0];
6735a6d7c9dSSunil Goutham 	mdev->mbase = mbox->bbuf_base;
6745a6d7c9dSSunil Goutham 	return 0;
6755a6d7c9dSSunil Goutham }
6765a6d7c9dSSunil Goutham 
otx2_sync_mbox_bbuf(struct otx2_mbox * mbox,int devid)6775a6d7c9dSSunil Goutham static inline void otx2_sync_mbox_bbuf(struct otx2_mbox *mbox, int devid)
6785a6d7c9dSSunil Goutham {
6795a6d7c9dSSunil Goutham 	u16 msgs_offset = ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
6805a6d7c9dSSunil Goutham 	void *hw_mbase = mbox->hwbase + (devid * MBOX_SIZE);
6815a6d7c9dSSunil Goutham 	struct otx2_mbox_dev *mdev = &mbox->dev[devid];
6825a6d7c9dSSunil Goutham 	struct mbox_hdr *hdr;
6835a6d7c9dSSunil Goutham 	u64 msg_size;
6845a6d7c9dSSunil Goutham 
6855a6d7c9dSSunil Goutham 	if (mdev->mbase == hw_mbase)
6865a6d7c9dSSunil Goutham 		return;
6875a6d7c9dSSunil Goutham 
6885a6d7c9dSSunil Goutham 	hdr = hw_mbase + mbox->rx_start;
6895a6d7c9dSSunil Goutham 	msg_size = hdr->msg_size;
6905a6d7c9dSSunil Goutham 
6915a6d7c9dSSunil Goutham 	if (msg_size > mbox->rx_size - msgs_offset)
6925a6d7c9dSSunil Goutham 		msg_size = mbox->rx_size - msgs_offset;
6935a6d7c9dSSunil Goutham 
6945a6d7c9dSSunil Goutham 	/* Copy mbox messages from mbox memory to bounce buffer */
6955a6d7c9dSSunil Goutham 	memcpy(mdev->mbase + mbox->rx_start,
6965a6d7c9dSSunil Goutham 	       hw_mbase + mbox->rx_start, msg_size + msgs_offset);
6975a6d7c9dSSunil Goutham }
6985a6d7c9dSSunil Goutham 
699caa2da34SSunil Goutham /* With the absence of API for 128-bit IO memory access for arm64,
700caa2da34SSunil Goutham  * implement required operations at place.
701caa2da34SSunil Goutham  */
702caa2da34SSunil Goutham #if defined(CONFIG_ARM64)
otx2_write128(u64 lo,u64 hi,void __iomem * addr)703caa2da34SSunil Goutham static inline void otx2_write128(u64 lo, u64 hi, void __iomem *addr)
704caa2da34SSunil Goutham {
705caa2da34SSunil Goutham 	__asm__ volatile("stp %x[x0], %x[x1], [%x[p1],#0]!"
706caa2da34SSunil Goutham 			 ::[x0]"r"(lo), [x1]"r"(hi), [p1]"r"(addr));
707caa2da34SSunil Goutham }
708caa2da34SSunil Goutham 
otx2_atomic64_add(u64 incr,u64 * ptr)709caa2da34SSunil Goutham static inline u64 otx2_atomic64_add(u64 incr, u64 *ptr)
710caa2da34SSunil Goutham {
711caa2da34SSunil Goutham 	u64 result;
712caa2da34SSunil Goutham 
713caa2da34SSunil Goutham 	__asm__ volatile(".cpu   generic+lse\n"
714caa2da34SSunil Goutham 			 "ldadd %x[i], %x[r], [%[b]]"
715caa2da34SSunil Goutham 			 : [r]"=r"(result), "+m"(*ptr)
716caa2da34SSunil Goutham 			 : [i]"r"(incr), [b]"r"(ptr)
717caa2da34SSunil Goutham 			 : "memory");
718caa2da34SSunil Goutham 	return result;
719caa2da34SSunil Goutham }
720caa2da34SSunil Goutham 
721caa2da34SSunil Goutham #else
7224c236d5dSGeetha sowjanya #define otx2_write128(lo, hi, addr)		writeq((hi) | (lo), addr)
723caa2da34SSunil Goutham #define otx2_atomic64_add(incr, ptr)		({ *ptr += incr; })
724caa2da34SSunil Goutham #endif
725caa2da34SSunil Goutham 
__cn10k_aura_freeptr(struct otx2_nic * pfvf,u64 aura,u64 * ptrs,u64 num_ptrs)7264c236d5dSGeetha sowjanya static inline void __cn10k_aura_freeptr(struct otx2_nic *pfvf, u64 aura,
727ef6c8da7SGeetha sowjanya 					u64 *ptrs, u64 num_ptrs)
7284c236d5dSGeetha sowjanya {
729ef6c8da7SGeetha sowjanya 	struct otx2_lmt_info *lmt_info;
7304c236d5dSGeetha sowjanya 	u64 size = 0, count_eot = 0;
7314c236d5dSGeetha sowjanya 	u64 tar_addr, val = 0;
7324c236d5dSGeetha sowjanya 
733ef6c8da7SGeetha sowjanya 	lmt_info = per_cpu_ptr(pfvf->hw.lmt_info, smp_processor_id());
7344c236d5dSGeetha sowjanya 	tar_addr = (__force u64)otx2_get_regaddr(pfvf, NPA_LF_AURA_BATCH_FREE0);
7354c236d5dSGeetha sowjanya 	/* LMTID is same as AURA Id */
736ef6c8da7SGeetha sowjanya 	val = (lmt_info->lmt_id & 0x7FF) | BIT_ULL(63);
7374c236d5dSGeetha sowjanya 	/* Set if [127:64] of last 128bit word has a valid pointer */
7384c236d5dSGeetha sowjanya 	count_eot = (num_ptrs % 2) ? 0ULL : 1ULL;
7394c236d5dSGeetha sowjanya 	/* Set AURA ID to free pointer */
7404c236d5dSGeetha sowjanya 	ptrs[0] = (count_eot << 32) | (aura & 0xFFFFF);
7414c236d5dSGeetha sowjanya 	/* Target address for LMTST flush tells HW how many 128bit
7424c236d5dSGeetha sowjanya 	 * words are valid from NPA_LF_AURA_BATCH_FREE0.
7434c236d5dSGeetha sowjanya 	 *
7444c236d5dSGeetha sowjanya 	 * tar_addr[6:4] is LMTST size-1 in units of 128b.
7454c236d5dSGeetha sowjanya 	 */
7464c236d5dSGeetha sowjanya 	if (num_ptrs > 2) {
7474c236d5dSGeetha sowjanya 		size = (sizeof(u64) * num_ptrs) / 16;
7484c236d5dSGeetha sowjanya 		if (!count_eot)
7494c236d5dSGeetha sowjanya 			size++;
7504c236d5dSGeetha sowjanya 		tar_addr |=  ((size - 1) & 0x7) << 4;
7514c236d5dSGeetha sowjanya 	}
752c5d731c5SGeetha sowjanya 	dma_wmb();
753ef6c8da7SGeetha sowjanya 	memcpy((u64 *)lmt_info->lmt_addr, ptrs, sizeof(u64) * num_ptrs);
7544c236d5dSGeetha sowjanya 	/* Perform LMTST flush */
7554c236d5dSGeetha sowjanya 	cn10k_lmt_flush(val, tar_addr);
7564c236d5dSGeetha sowjanya }
7574c236d5dSGeetha sowjanya 
cn10k_aura_freeptr(void * dev,int aura,u64 buf)7584c236d5dSGeetha sowjanya static inline void cn10k_aura_freeptr(void *dev, int aura, u64 buf)
7594c236d5dSGeetha sowjanya {
7604c236d5dSGeetha sowjanya 	struct otx2_nic *pfvf = dev;
7614c236d5dSGeetha sowjanya 	u64 ptrs[2];
7624c236d5dSGeetha sowjanya 
7634c236d5dSGeetha sowjanya 	ptrs[1] = buf;
76455ba18dcSKevin Hao 	get_cpu();
765ef6c8da7SGeetha sowjanya 	/* Free only one buffer at time during init and teardown */
766ef6c8da7SGeetha sowjanya 	__cn10k_aura_freeptr(pfvf, aura, ptrs, 2);
76755ba18dcSKevin Hao 	put_cpu();
7684c236d5dSGeetha sowjanya }
7694c236d5dSGeetha sowjanya 
770caa2da34SSunil Goutham /* Alloc pointer from pool/aura */
otx2_aura_allocptr(struct otx2_nic * pfvf,int aura)771caa2da34SSunil Goutham static inline u64 otx2_aura_allocptr(struct otx2_nic *pfvf, int aura)
772caa2da34SSunil Goutham {
773ab6dddd2SSubbaraya Sundeep 	u64 *ptr = (__force u64 *)otx2_get_regaddr(pfvf, NPA_LF_AURA_OP_ALLOCX(0));
774caa2da34SSunil Goutham 	u64 incr = (u64)aura | BIT_ULL(63);
775caa2da34SSunil Goutham 
776caa2da34SSunil Goutham 	return otx2_atomic64_add(incr, ptr);
777caa2da34SSunil Goutham }
778caa2da34SSunil Goutham 
779caa2da34SSunil Goutham /* Free pointer to a pool/aura */
otx2_aura_freeptr(void * dev,int aura,u64 buf)7804c236d5dSGeetha sowjanya static inline void otx2_aura_freeptr(void *dev, int aura, u64 buf)
781caa2da34SSunil Goutham {
7824c236d5dSGeetha sowjanya 	struct otx2_nic *pfvf = dev;
7834c236d5dSGeetha sowjanya 	void __iomem *addr = otx2_get_regaddr(pfvf, NPA_LF_AURA_OP_FREE0);
7844c236d5dSGeetha sowjanya 
7854c236d5dSGeetha sowjanya 	otx2_write128(buf, (u64)aura | BIT_ULL(63), addr);
786caa2da34SSunil Goutham }
787caa2da34SSunil Goutham 
otx2_get_pool_idx(struct otx2_nic * pfvf,int type,int idx)788caa2da34SSunil Goutham static inline int otx2_get_pool_idx(struct otx2_nic *pfvf, int type, int idx)
789caa2da34SSunil Goutham {
790caa2da34SSunil Goutham 	if (type == AURA_NIX_SQ)
791caa2da34SSunil Goutham 		return pfvf->hw.rqpool_cnt + idx;
792caa2da34SSunil Goutham 
793caa2da34SSunil Goutham 	 /* AURA_NIX_RQ */
794caa2da34SSunil Goutham 	return idx;
795caa2da34SSunil Goutham }
796caa2da34SSunil Goutham 
7975a6d7c9dSSunil Goutham /* Mbox APIs */
otx2_sync_mbox_msg(struct mbox * mbox)7985a6d7c9dSSunil Goutham static inline int otx2_sync_mbox_msg(struct mbox *mbox)
7995a6d7c9dSSunil Goutham {
8005a6d7c9dSSunil Goutham 	int err;
8015a6d7c9dSSunil Goutham 
8025a6d7c9dSSunil Goutham 	if (!otx2_mbox_nonempty(&mbox->mbox, 0))
8035a6d7c9dSSunil Goutham 		return 0;
8045a6d7c9dSSunil Goutham 	otx2_mbox_msg_send(&mbox->mbox, 0);
8055a6d7c9dSSunil Goutham 	err = otx2_mbox_wait_for_rsp(&mbox->mbox, 0);
8065a6d7c9dSSunil Goutham 	if (err)
8075a6d7c9dSSunil Goutham 		return err;
8085a6d7c9dSSunil Goutham 
8095a6d7c9dSSunil Goutham 	return otx2_mbox_check_rsp_msgs(&mbox->mbox, 0);
8105a6d7c9dSSunil Goutham }
8115a6d7c9dSSunil Goutham 
otx2_sync_mbox_up_msg(struct mbox * mbox,int devid)8125a6d7c9dSSunil Goutham static inline int otx2_sync_mbox_up_msg(struct mbox *mbox, int devid)
8135a6d7c9dSSunil Goutham {
8145a6d7c9dSSunil Goutham 	int err;
8155a6d7c9dSSunil Goutham 
8165a6d7c9dSSunil Goutham 	if (!otx2_mbox_nonempty(&mbox->mbox_up, devid))
8175a6d7c9dSSunil Goutham 		return 0;
818c6354b85SSubbaraya Sundeep 	otx2_mbox_msg_send_up(&mbox->mbox_up, devid);
8195a6d7c9dSSunil Goutham 	err = otx2_mbox_wait_for_rsp(&mbox->mbox_up, devid);
8205a6d7c9dSSunil Goutham 	if (err)
8215a6d7c9dSSunil Goutham 		return err;
8225a6d7c9dSSunil Goutham 
8235a6d7c9dSSunil Goutham 	return otx2_mbox_check_rsp_msgs(&mbox->mbox_up, devid);
8245a6d7c9dSSunil Goutham }
8255a6d7c9dSSunil Goutham 
8265a6d7c9dSSunil Goutham /* Use this API to send mbox msgs in atomic context
8275a6d7c9dSSunil Goutham  * where sleeping is not allowed
8285a6d7c9dSSunil Goutham  */
otx2_sync_mbox_msg_busy_poll(struct mbox * mbox)8295a6d7c9dSSunil Goutham static inline int otx2_sync_mbox_msg_busy_poll(struct mbox *mbox)
8305a6d7c9dSSunil Goutham {
8315a6d7c9dSSunil Goutham 	int err;
8325a6d7c9dSSunil Goutham 
8335a6d7c9dSSunil Goutham 	if (!otx2_mbox_nonempty(&mbox->mbox, 0))
8345a6d7c9dSSunil Goutham 		return 0;
8355a6d7c9dSSunil Goutham 	otx2_mbox_msg_send(&mbox->mbox, 0);
8365a6d7c9dSSunil Goutham 	err = otx2_mbox_busy_poll_for_rsp(&mbox->mbox, 0);
8375a6d7c9dSSunil Goutham 	if (err)
8385a6d7c9dSSunil Goutham 		return err;
8395a6d7c9dSSunil Goutham 
8405a6d7c9dSSunil Goutham 	return otx2_mbox_check_rsp_msgs(&mbox->mbox, 0);
8415a6d7c9dSSunil Goutham }
8425a6d7c9dSSunil Goutham 
8435a6d7c9dSSunil Goutham #define M(_name, _id, _fn_name, _req_type, _rsp_type)                   \
8445a6d7c9dSSunil Goutham static struct _req_type __maybe_unused					\
8455a6d7c9dSSunil Goutham *otx2_mbox_alloc_msg_ ## _fn_name(struct mbox *mbox)                    \
8465a6d7c9dSSunil Goutham {									\
8475a6d7c9dSSunil Goutham 	struct _req_type *req;						\
8485a6d7c9dSSunil Goutham 									\
8495a6d7c9dSSunil Goutham 	req = (struct _req_type *)otx2_mbox_alloc_msg_rsp(		\
8505a6d7c9dSSunil Goutham 		&mbox->mbox, 0, sizeof(struct _req_type),		\
8515a6d7c9dSSunil Goutham 		sizeof(struct _rsp_type));				\
8525a6d7c9dSSunil Goutham 	if (!req)							\
8535a6d7c9dSSunil Goutham 		return NULL;						\
8545a6d7c9dSSunil Goutham 	req->hdr.sig = OTX2_MBOX_REQ_SIG;				\
8555a6d7c9dSSunil Goutham 	req->hdr.id = _id;						\
85631a97460SSubbaraya Sundeep 	trace_otx2_msg_alloc(mbox->mbox.pdev, _id, sizeof(*req));	\
8575a6d7c9dSSunil Goutham 	return req;							\
8585a6d7c9dSSunil Goutham }
8595a6d7c9dSSunil Goutham 
8605a6d7c9dSSunil Goutham MBOX_MESSAGES
8615a6d7c9dSSunil Goutham #undef M
8625a6d7c9dSSunil Goutham 
8635a6d7c9dSSunil Goutham #define M(_name, _id, _fn_name, _req_type, _rsp_type)			\
8645a6d7c9dSSunil Goutham int									\
8655a6d7c9dSSunil Goutham otx2_mbox_up_handler_ ## _fn_name(struct otx2_nic *pfvf,		\
8665a6d7c9dSSunil Goutham 				struct _req_type *req,			\
8675a6d7c9dSSunil Goutham 				struct _rsp_type *rsp);			\
8685a6d7c9dSSunil Goutham 
8695a6d7c9dSSunil Goutham MBOX_UP_CGX_MESSAGES
870c54ffc73SSubbaraya Sundeep MBOX_UP_MCS_MESSAGES
8715a6d7c9dSSunil Goutham #undef M
8725a6d7c9dSSunil Goutham 
8734ff7d148SGeetha sowjanya /* Time to wait before watchdog kicks off */
8744ff7d148SGeetha sowjanya #define OTX2_TX_TIMEOUT		(100 * HZ)
8754ff7d148SGeetha sowjanya 
8765a6d7c9dSSunil Goutham #define	RVU_PFVF_PF_SHIFT	10
8775a6d7c9dSSunil Goutham #define	RVU_PFVF_PF_MASK	0x3F
8785a6d7c9dSSunil Goutham #define	RVU_PFVF_FUNC_SHIFT	0
8795a6d7c9dSSunil Goutham #define	RVU_PFVF_FUNC_MASK	0x3FF
8805a6d7c9dSSunil Goutham 
is_otx2_vf(u16 pcifunc)8813cffaed2SRakesh Babu static inline bool is_otx2_vf(u16 pcifunc)
8823cffaed2SRakesh Babu {
8833cffaed2SRakesh Babu 	return !!(pcifunc & RVU_PFVF_FUNC_MASK);
8843cffaed2SRakesh Babu }
8853cffaed2SRakesh Babu 
rvu_get_pf(u16 pcifunc)88604a21ef3SSunil Goutham static inline int rvu_get_pf(u16 pcifunc)
88704a21ef3SSunil Goutham {
88804a21ef3SSunil Goutham 	return (pcifunc >> RVU_PFVF_PF_SHIFT) & RVU_PFVF_PF_MASK;
88904a21ef3SSunil Goutham }
89004a21ef3SSunil Goutham 
otx2_dma_map_page(struct otx2_nic * pfvf,struct page * page,size_t offset,size_t size,enum dma_data_direction dir)891caa2da34SSunil Goutham static inline dma_addr_t otx2_dma_map_page(struct otx2_nic *pfvf,
892caa2da34SSunil Goutham 					   struct page *page,
893caa2da34SSunil Goutham 					   size_t offset, size_t size,
894caa2da34SSunil Goutham 					   enum dma_data_direction dir)
895caa2da34SSunil Goutham {
896caa2da34SSunil Goutham 	dma_addr_t iova;
897caa2da34SSunil Goutham 
898caa2da34SSunil Goutham 	iova = dma_map_page_attrs(pfvf->dev, page,
899caa2da34SSunil Goutham 				  offset, size, dir, DMA_ATTR_SKIP_CPU_SYNC);
900caa2da34SSunil Goutham 	if (unlikely(dma_mapping_error(pfvf->dev, iova)))
901caa2da34SSunil Goutham 		return (dma_addr_t)NULL;
902caa2da34SSunil Goutham 	return iova;
903caa2da34SSunil Goutham }
904caa2da34SSunil Goutham 
otx2_dma_unmap_page(struct otx2_nic * pfvf,dma_addr_t addr,size_t size,enum dma_data_direction dir)905caa2da34SSunil Goutham static inline void otx2_dma_unmap_page(struct otx2_nic *pfvf,
906caa2da34SSunil Goutham 				       dma_addr_t addr, size_t size,
907caa2da34SSunil Goutham 				       enum dma_data_direction dir)
908caa2da34SSunil Goutham {
909caa2da34SSunil Goutham 	dma_unmap_page_attrs(pfvf->dev, addr, size,
910caa2da34SSunil Goutham 			     dir, DMA_ATTR_SKIP_CPU_SYNC);
911caa2da34SSunil Goutham }
912caa2da34SSunil Goutham 
otx2_get_smq_idx(struct otx2_nic * pfvf,u16 qidx)91399c969a8SSuman Ghosh static inline u16 otx2_get_smq_idx(struct otx2_nic *pfvf, u16 qidx)
91499c969a8SSuman Ghosh {
915ab6dddd2SSubbaraya Sundeep 	u16 smq;
91699c969a8SSuman Ghosh #ifdef CONFIG_DCB
91732b931c8SSuman Ghosh 	if (qidx < NIX_PF_PFC_PRIO_MAX && pfvf->pfc_alloc_status[qidx])
91899c969a8SSuman Ghosh 		return pfvf->pfc_schq_list[NIX_TXSCH_LVL_SMQ][qidx];
91999c969a8SSuman Ghosh #endif
920ab6dddd2SSubbaraya Sundeep 	/* check if qidx falls under QOS queues */
921ab6dddd2SSubbaraya Sundeep 	if (qidx >= pfvf->hw.non_qos_queues)
922ab6dddd2SSubbaraya Sundeep 		smq = pfvf->qos.qid_to_sqmap[qidx - pfvf->hw.non_qos_queues];
923ab6dddd2SSubbaraya Sundeep 	else
924ab6dddd2SSubbaraya Sundeep 		smq = pfvf->hw.txschq_list[NIX_TXSCH_LVL_SMQ][0];
92599c969a8SSuman Ghosh 
926ab6dddd2SSubbaraya Sundeep 	return smq;
927ab6dddd2SSubbaraya Sundeep }
928ab6dddd2SSubbaraya Sundeep 
otx2_get_total_tx_queues(struct otx2_nic * pfvf)929ab6dddd2SSubbaraya Sundeep static inline u16 otx2_get_total_tx_queues(struct otx2_nic *pfvf)
930ab6dddd2SSubbaraya Sundeep {
931ab6dddd2SSubbaraya Sundeep 	return pfvf->hw.non_qos_queues + pfvf->hw.tc_tx_queues;
93299c969a8SSuman Ghosh }
93399c969a8SSuman Ghosh 
otx2_convert_rate(u64 rate)934cb748a7eSHariprasad Kelam static inline u64 otx2_convert_rate(u64 rate)
935cb748a7eSHariprasad Kelam {
936cb748a7eSHariprasad Kelam 	u64 converted_rate;
937cb748a7eSHariprasad Kelam 
938cb748a7eSHariprasad Kelam 	/* Convert bytes per second to Mbps */
939cb748a7eSHariprasad Kelam 	converted_rate = rate * 8;
940cb748a7eSHariprasad Kelam 	converted_rate = max_t(u64, converted_rate / 1000000, 1);
941cb748a7eSHariprasad Kelam 
942cb748a7eSHariprasad Kelam 	return converted_rate;
943cb748a7eSHariprasad Kelam }
944cb748a7eSHariprasad Kelam 
otx2_tc_flower_rule_cnt(struct otx2_nic * pfvf)94561f98da4SHariprasad Kelam static inline int otx2_tc_flower_rule_cnt(struct otx2_nic *pfvf)
94661f98da4SHariprasad Kelam {
94761f98da4SHariprasad Kelam 	/* return here if MCAM entries not allocated */
94861f98da4SHariprasad Kelam 	if (!pfvf->flow_cfg)
94961f98da4SHariprasad Kelam 		return 0;
95061f98da4SHariprasad Kelam 
95161f98da4SHariprasad Kelam 	return pfvf->flow_cfg->nr_flows;
95261f98da4SHariprasad Kelam }
95361f98da4SHariprasad Kelam 
95404a21ef3SSunil Goutham /* MSI-X APIs */
95504a21ef3SSunil Goutham void otx2_free_cints(struct otx2_nic *pfvf, int n);
95604a21ef3SSunil Goutham void otx2_set_cints_affinity(struct otx2_nic *pfvf);
95734bfe0ebSSunil Goutham int otx2_set_mac_address(struct net_device *netdev, void *p);
95834bfe0ebSSunil Goutham int otx2_hw_set_mtu(struct otx2_nic *pfvf, int mtu);
9594ff7d148SGeetha sowjanya void otx2_tx_timeout(struct net_device *netdev, unsigned int txq);
96034bfe0ebSSunil Goutham void otx2_get_mac_from_af(struct net_device *netdev);
96104a21ef3SSunil Goutham void otx2_config_irq_coalescing(struct otx2_nic *pfvf, int qidx);
96275f36270SGeetha sowjanya int otx2_config_pause_frm(struct otx2_nic *pfvf);
963dc1a9bf2SSunil Goutham void otx2_setup_segmentation(struct otx2_nic *pfvf);
964*92ada6dfSSai Krishna int otx2_reset_mac_stats(struct otx2_nic *pfvf);
96504a21ef3SSunil Goutham 
96605fcc9e0SSunil Goutham /* RVU block related APIs */
96705fcc9e0SSunil Goutham int otx2_attach_npa_nix(struct otx2_nic *pfvf);
96805fcc9e0SSunil Goutham int otx2_detach_resources(struct mbox *mbox);
96905fcc9e0SSunil Goutham int otx2_config_npa(struct otx2_nic *pfvf);
970caa2da34SSunil Goutham int otx2_sq_aura_pool_init(struct otx2_nic *pfvf);
971caa2da34SSunil Goutham int otx2_rq_aura_pool_init(struct otx2_nic *pfvf);
972caa2da34SSunil Goutham void otx2_aura_pool_free(struct otx2_nic *pfvf);
973caa2da34SSunil Goutham void otx2_free_aura_ptr(struct otx2_nic *pfvf, int type);
974caa2da34SSunil Goutham void otx2_sq_free_sqbs(struct otx2_nic *pfvf);
97505fcc9e0SSunil Goutham int otx2_config_nix(struct otx2_nic *pfvf);
976caa2da34SSunil Goutham int otx2_config_nix_queues(struct otx2_nic *pfvf);
97799c969a8SSuman Ghosh int otx2_txschq_config(struct otx2_nic *pfvf, int lvl, int prio, bool pfc_en);
978caa2da34SSunil Goutham int otx2_txsch_alloc(struct otx2_nic *pfvf);
9796b4b2dedSHariprasad Kelam void otx2_txschq_stop(struct otx2_nic *pfvf);
9806b4b2dedSHariprasad Kelam void otx2_txschq_free_one(struct otx2_nic *pfvf, u16 lvl, u16 schq);
98192662d9fSGeetha sowjanya void otx2_free_pending_sqe(struct otx2_nic *pfvf);
982caa2da34SSunil Goutham void otx2_sqb_flush(struct otx2_nic *pfvf);
983ab6dddd2SSubbaraya Sundeep int otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool,
9841fb3ca76SKevin Hao 		    dma_addr_t *dma);
98550fe6c02SLinu Cherian int otx2_rxtx_enable(struct otx2_nic *pfvf, bool enable);
986caa2da34SSunil Goutham void otx2_ctx_disable(struct mbox *mbox, int type, bool npa);
98775f36270SGeetha sowjanya int otx2_nix_config_bp(struct otx2_nic *pfvf, bool enable);
988b2e3406aSRatheesh Kannoth void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq, int qidx);
9893ca6c4c8SSunil Goutham void otx2_cleanup_tx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
990ab6dddd2SSubbaraya Sundeep int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16 sqb_aura);
9914c236d5dSGeetha sowjanya int otx2_sq_aq_init(void *dev, u16 qidx, u16 sqb_aura);
9924c236d5dSGeetha sowjanya int cn10k_sq_aq_init(void *dev, u16 qidx, u16 sqb_aura);
9934c236d5dSGeetha sowjanya int otx2_alloc_buffer(struct otx2_nic *pfvf, struct otx2_cq_queue *cq,
9944c236d5dSGeetha sowjanya 		      dma_addr_t *dma);
995ab6dddd2SSubbaraya Sundeep int otx2_pool_init(struct otx2_nic *pfvf, u16 pool_id,
996b2e3406aSRatheesh Kannoth 		   int stack_pages, int numptrs, int buf_size, int type);
997ab6dddd2SSubbaraya Sundeep int otx2_aura_init(struct otx2_nic *pfvf, int aura_id,
998ab6dddd2SSubbaraya Sundeep 		   int pool_id, int numptrs);
99905fcc9e0SSunil Goutham 
100085069e95SSunil Goutham /* RSS configuration APIs*/
100185069e95SSunil Goutham int otx2_rss_init(struct otx2_nic *pfvf);
10026e92d71bSSunil Goutham int otx2_set_flowkey_cfg(struct otx2_nic *pfvf);
10036e92d71bSSunil Goutham void otx2_set_rss_key(struct otx2_nic *pfvf);
100481a43620SGeetha sowjanya int otx2_set_rss_table(struct otx2_nic *pfvf, int ctx_id);
100585069e95SSunil Goutham 
100605fcc9e0SSunil Goutham /* Mbox handlers */
100705fcc9e0SSunil Goutham void mbox_handler_msix_offset(struct otx2_nic *pfvf,
100805fcc9e0SSunil Goutham 			      struct msix_offset_rsp *rsp);
100905fcc9e0SSunil Goutham void mbox_handler_npa_lf_alloc(struct otx2_nic *pfvf,
101005fcc9e0SSunil Goutham 			       struct npa_lf_alloc_rsp *rsp);
101105fcc9e0SSunil Goutham void mbox_handler_nix_lf_alloc(struct otx2_nic *pfvf,
101205fcc9e0SSunil Goutham 			       struct nix_lf_alloc_rsp *rsp);
1013caa2da34SSunil Goutham void mbox_handler_nix_txsch_alloc(struct otx2_nic *pf,
1014caa2da34SSunil Goutham 				  struct nix_txsch_alloc_rsp *rsp);
1015d45d8979SChristina Jacob void mbox_handler_cgx_stats(struct otx2_nic *pfvf,
1016d45d8979SChristina Jacob 			    struct cgx_stats_rsp *rsp);
1017d0cf9503SChristina Jacob void mbox_handler_cgx_fec_stats(struct otx2_nic *pfvf,
1018d0cf9503SChristina Jacob 				struct cgx_fec_stats_rsp *rsp);
1019d0cf9503SChristina Jacob void otx2_set_fec_stats_count(struct otx2_nic *pfvf);
102075f36270SGeetha sowjanya void mbox_handler_nix_bp_enable(struct otx2_nic *pfvf,
102175f36270SGeetha sowjanya 				struct nix_bp_cfg_rsp *rsp);
102234bfe0ebSSunil Goutham 
1023e239d0c7SGeetha sowjanya /* Device stats APIs */
1024e239d0c7SGeetha sowjanya void otx2_get_dev_stats(struct otx2_nic *pfvf);
1025e239d0c7SGeetha sowjanya void otx2_get_stats64(struct net_device *netdev,
1026e239d0c7SGeetha sowjanya 		      struct rtnl_link_stats64 *stats);
1027d45d8979SChristina Jacob void otx2_update_lmac_stats(struct otx2_nic *pfvf);
1028d0cf9503SChristina Jacob void otx2_update_lmac_fec_stats(struct otx2_nic *pfvf);
1029d45d8979SChristina Jacob int otx2_update_rq_stats(struct otx2_nic *pfvf, int qidx);
1030d45d8979SChristina Jacob int otx2_update_sq_stats(struct otx2_nic *pfvf, int qidx);
1031d45d8979SChristina Jacob void otx2_set_ethtool_ops(struct net_device *netdev);
103205c22b54STomasz Duszynski void otx2vf_set_ethtool_ops(struct net_device *netdev);
1033e239d0c7SGeetha sowjanya 
103434bfe0ebSSunil Goutham int otx2_open(struct net_device *netdev);
103534bfe0ebSSunil Goutham int otx2_stop(struct net_device *netdev);
1036d45d8979SChristina Jacob int otx2_set_real_num_queues(struct net_device *netdev,
1037d45d8979SChristina Jacob 			     int tx_queues, int rx_queues);
103843510ef4SNaveen Mamindlapalli int otx2_ioctl(struct net_device *netdev, struct ifreq *req, int cmd);
103943510ef4SNaveen Mamindlapalli int otx2_config_hwtstamp(struct net_device *netdev, struct ifreq *ifr);
104043510ef4SNaveen Mamindlapalli 
1041f0a1913fSSubbaraya Sundeep /* MCAM filter related APIs */
1042f0a1913fSSubbaraya Sundeep int otx2_mcam_flow_init(struct otx2_nic *pf);
10433cffaed2SRakesh Babu int otx2vf_mcam_flow_init(struct otx2_nic *pfvf);
10442da48943SSunil Goutham int otx2_alloc_mcam_entries(struct otx2_nic *pfvf, u16 count);
1045f0a1913fSSubbaraya Sundeep void otx2_mcam_flow_del(struct otx2_nic *pf);
1046f0a1913fSSubbaraya Sundeep int otx2_destroy_ntuple_flows(struct otx2_nic *pf);
1047f0a1913fSSubbaraya Sundeep int otx2_destroy_mcam_flows(struct otx2_nic *pfvf);
1048f0a1913fSSubbaraya Sundeep int otx2_get_flow(struct otx2_nic *pfvf,
1049f0a1913fSSubbaraya Sundeep 		  struct ethtool_rxnfc *nfc, u32 location);
1050f0a1913fSSubbaraya Sundeep int otx2_get_all_flows(struct otx2_nic *pfvf,
1051f0a1913fSSubbaraya Sundeep 		       struct ethtool_rxnfc *nfc, u32 *rule_locs);
1052f0a1913fSSubbaraya Sundeep int otx2_add_flow(struct otx2_nic *pfvf,
105381a43620SGeetha sowjanya 		  struct ethtool_rxnfc *nfc);
1054f0a1913fSSubbaraya Sundeep int otx2_remove_flow(struct otx2_nic *pfvf, u32 location);
10553cffaed2SRakesh Babu int otx2_get_maxflows(struct otx2_flow_config *flow_cfg);
105681a43620SGeetha sowjanya void otx2_rss_ctx_flow_del(struct otx2_nic *pfvf, int ctx_id);
105763ee5157SHariprasad Kelam int otx2_del_macfilter(struct net_device *netdev, const u8 *mac);
105863ee5157SHariprasad Kelam int otx2_add_macfilter(struct net_device *netdev, const u8 *mac);
1059fd9d7859SHariprasad Kelam int otx2_enable_rxvlan(struct otx2_nic *pf, bool enable);
1060fd9d7859SHariprasad Kelam int otx2_install_rxvlan_offload_flow(struct otx2_nic *pfvf);
106106059a1aSGeetha sowjanya bool otx2_xdp_sq_append_pkt(struct otx2_nic *pfvf, u64 iova, int len, u16 qidx);
1062ab58a416SHariprasad Kelam u16 otx2_get_max_mtu(struct otx2_nic *pfvf);
10634b0385bcSSubbaraya Sundeep int otx2_handle_ntuple_tc_features(struct net_device *netdev,
10644b0385bcSSubbaraya Sundeep 				   netdev_features_t features);
106599c969a8SSuman Ghosh int otx2_smq_flush(struct otx2_nic *pfvf, int smq);
1066b2e3406aSRatheesh Kannoth void otx2_free_bufs(struct otx2_nic *pfvf, struct otx2_pool *pool,
1067b2e3406aSRatheesh Kannoth 		    u64 iova, int size);
106899c969a8SSuman Ghosh 
10691d4d9e42SNaveen Mamindlapalli /* tc support */
10701d4d9e42SNaveen Mamindlapalli int otx2_init_tc(struct otx2_nic *nic);
10711d4d9e42SNaveen Mamindlapalli void otx2_shutdown_tc(struct otx2_nic *nic);
10721d4d9e42SNaveen Mamindlapalli int otx2_setup_tc(struct net_device *netdev, enum tc_setup_type type,
10731d4d9e42SNaveen Mamindlapalli 		  void *type_data);
1074d3290f7eSSubbaraya Sundeep void otx2_tc_apply_ingress_police_rules(struct otx2_nic *nic);
1075d3290f7eSSubbaraya Sundeep 
107679d2be38SHariprasad Kelam /* CGX/RPM DMAC filters support */
107779d2be38SHariprasad Kelam int otx2_dmacflt_get_max_cnt(struct otx2_nic *pf);
1078fa5e0ccbSRatheesh Kannoth int otx2_dmacflt_add(struct otx2_nic *pf, const u8 *mac, u32 bit_pos);
1079fa5e0ccbSRatheesh Kannoth int otx2_dmacflt_remove(struct otx2_nic *pf, const u8 *mac, u32 bit_pos);
1080fa5e0ccbSRatheesh Kannoth int otx2_dmacflt_update(struct otx2_nic *pf, u8 *mac, u32 bit_pos);
108179d2be38SHariprasad Kelam void otx2_dmacflt_reinstall_flows(struct otx2_nic *pf);
108279d2be38SHariprasad Kelam void otx2_dmacflt_update_pfmac_flow(struct otx2_nic *pfvf);
10838e675581SHariprasad Kelam 
10848e675581SHariprasad Kelam #ifdef CONFIG_DCB
10858e675581SHariprasad Kelam /* DCB support*/
10868e675581SHariprasad Kelam void otx2_update_bpid_in_rqctx(struct otx2_nic *pfvf, int vlan_prio, int qidx, bool pfc_enable);
10878e675581SHariprasad Kelam int otx2_config_priority_flow_ctrl(struct otx2_nic *pfvf);
10888e675581SHariprasad Kelam int otx2_dcbnl_set_ops(struct net_device *dev);
108999c969a8SSuman Ghosh /* PFC support */
109099c969a8SSuman Ghosh int otx2_pfc_txschq_config(struct otx2_nic *pfvf);
109199c969a8SSuman Ghosh int otx2_pfc_txschq_alloc(struct otx2_nic *pfvf);
109299c969a8SSuman Ghosh int otx2_pfc_txschq_update(struct otx2_nic *pfvf);
109399c969a8SSuman Ghosh int otx2_pfc_txschq_stop(struct otx2_nic *pfvf);
10948e675581SHariprasad Kelam #endif
1095c54ffc73SSubbaraya Sundeep 
1096c54ffc73SSubbaraya Sundeep #if IS_ENABLED(CONFIG_MACSEC)
1097c54ffc73SSubbaraya Sundeep /* MACSEC offload support */
1098c54ffc73SSubbaraya Sundeep int cn10k_mcs_init(struct otx2_nic *pfvf);
1099c54ffc73SSubbaraya Sundeep void cn10k_mcs_free(struct otx2_nic *pfvf);
1100c54ffc73SSubbaraya Sundeep void cn10k_handle_mcs_event(struct otx2_nic *pfvf, struct mcs_intr_info *event);
1101c54ffc73SSubbaraya Sundeep #else
cn10k_mcs_init(struct otx2_nic * pfvf)1102c54ffc73SSubbaraya Sundeep static inline int cn10k_mcs_init(struct otx2_nic *pfvf) { return 0; }
cn10k_mcs_free(struct otx2_nic * pfvf)1103c54ffc73SSubbaraya Sundeep static inline void cn10k_mcs_free(struct otx2_nic *pfvf) {}
cn10k_handle_mcs_event(struct otx2_nic * pfvf,struct mcs_intr_info * event)1104c54ffc73SSubbaraya Sundeep static inline void cn10k_handle_mcs_event(struct otx2_nic *pfvf,
1105c54ffc73SSubbaraya Sundeep 					  struct mcs_intr_info *event)
1106c54ffc73SSubbaraya Sundeep {}
1107c54ffc73SSubbaraya Sundeep #endif /* CONFIG_MACSEC */
1108c54ffc73SSubbaraya Sundeep 
1109ab6dddd2SSubbaraya Sundeep /* qos support */
otx2_qos_init(struct otx2_nic * pfvf,int qos_txqs)1110ab6dddd2SSubbaraya Sundeep static inline void otx2_qos_init(struct otx2_nic *pfvf, int qos_txqs)
1111ab6dddd2SSubbaraya Sundeep {
1112ab6dddd2SSubbaraya Sundeep 	struct otx2_hw *hw = &pfvf->hw;
1113ab6dddd2SSubbaraya Sundeep 
1114ab6dddd2SSubbaraya Sundeep 	hw->tc_tx_queues = qos_txqs;
11155e6808b4SNaveen Mamindlapalli 	INIT_LIST_HEAD(&pfvf->qos.qos_tree);
11165e6808b4SNaveen Mamindlapalli 	mutex_init(&pfvf->qos.qos_lock);
11175e6808b4SNaveen Mamindlapalli }
11185e6808b4SNaveen Mamindlapalli 
otx2_shutdown_qos(struct otx2_nic * pfvf)11195e6808b4SNaveen Mamindlapalli static inline void otx2_shutdown_qos(struct otx2_nic *pfvf)
11205e6808b4SNaveen Mamindlapalli {
11215e6808b4SNaveen Mamindlapalli 	mutex_destroy(&pfvf->qos.qos_lock);
1122ab6dddd2SSubbaraya Sundeep }
1123ab6dddd2SSubbaraya Sundeep 
1124ab6dddd2SSubbaraya Sundeep u16 otx2_select_queue(struct net_device *netdev, struct sk_buff *skb,
1125ab6dddd2SSubbaraya Sundeep 		      struct net_device *sb_dev);
11265e6808b4SNaveen Mamindlapalli int otx2_get_txq_by_classid(struct otx2_nic *pfvf, u16 classid);
11275e6808b4SNaveen Mamindlapalli void otx2_qos_config_txschq(struct otx2_nic *pfvf);
11285e6808b4SNaveen Mamindlapalli void otx2_clean_qos_queues(struct otx2_nic *pfvf);
112916547577SSunil Goutham #endif /* OTX2_COMMON_H */
1130