xref: /openbmc/linux/drivers/net/ethernet/cavium/thunder/nicvf_queues.h (revision cbecf716ca618fd44feda6bd9a64a8179d031fc5)
125763b3cSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
24863dea3SSunil Goutham /*
34863dea3SSunil Goutham  * Copyright (C) 2015 Cavium, Inc.
44863dea3SSunil Goutham  */
54863dea3SSunil Goutham 
64863dea3SSunil Goutham #ifndef NICVF_QUEUES_H
74863dea3SSunil Goutham #define NICVF_QUEUES_H
84863dea3SSunil Goutham 
94863dea3SSunil Goutham #include <linux/netdevice.h>
1005c773f5SSunil Goutham #include <linux/iommu.h>
1127e95e36SJesper Dangaard Brouer #include <net/xdp.h>
124863dea3SSunil Goutham #include "q_struct.h"
134863dea3SSunil Goutham 
144863dea3SSunil Goutham #define MAX_QUEUE_SET			128
154863dea3SSunil Goutham #define MAX_RCV_QUEUES_PER_QS		8
164863dea3SSunil Goutham #define MAX_RCV_BUF_DESC_RINGS_PER_QS	2
174863dea3SSunil Goutham #define MAX_SND_QUEUES_PER_QS		8
184863dea3SSunil Goutham #define MAX_CMP_QUEUES_PER_QS		8
194863dea3SSunil Goutham 
204863dea3SSunil Goutham /* VF's queue interrupt ranges */
214863dea3SSunil Goutham #define	NICVF_INTR_ID_CQ		0
224863dea3SSunil Goutham #define	NICVF_INTR_ID_SQ		8
234863dea3SSunil Goutham #define	NICVF_INTR_ID_RBDR		16
244863dea3SSunil Goutham #define	NICVF_INTR_ID_MISC		18
254863dea3SSunil Goutham #define	NICVF_INTR_ID_QS_ERR		19
264863dea3SSunil Goutham 
274863dea3SSunil Goutham #define	for_each_cq_irq(irq)	\
284863dea3SSunil Goutham 	for (irq = NICVF_INTR_ID_CQ; irq < NICVF_INTR_ID_SQ; irq++)
294863dea3SSunil Goutham #define	for_each_sq_irq(irq)	\
304863dea3SSunil Goutham 	for (irq = NICVF_INTR_ID_SQ; irq < NICVF_INTR_ID_RBDR; irq++)
314863dea3SSunil Goutham #define	for_each_rbdr_irq(irq)	\
324863dea3SSunil Goutham 	for (irq = NICVF_INTR_ID_RBDR; irq < NICVF_INTR_ID_MISC; irq++)
334863dea3SSunil Goutham 
344863dea3SSunil Goutham #define RBDR_SIZE0		0ULL /* 8K entries */
354863dea3SSunil Goutham #define RBDR_SIZE1		1ULL /* 16K entries */
364863dea3SSunil Goutham #define RBDR_SIZE2		2ULL /* 32K entries */
374863dea3SSunil Goutham #define RBDR_SIZE3		3ULL /* 64K entries */
384863dea3SSunil Goutham #define RBDR_SIZE4		4ULL /* 126K entries */
394863dea3SSunil Goutham #define RBDR_SIZE5		5ULL /* 256K entries */
404863dea3SSunil Goutham #define RBDR_SIZE6		6ULL /* 512K entries */
414863dea3SSunil Goutham 
424863dea3SSunil Goutham #define SND_QUEUE_SIZE0		0ULL /* 1K entries */
434863dea3SSunil Goutham #define SND_QUEUE_SIZE1		1ULL /* 2K entries */
444863dea3SSunil Goutham #define SND_QUEUE_SIZE2		2ULL /* 4K entries */
454863dea3SSunil Goutham #define SND_QUEUE_SIZE3		3ULL /* 8K entries */
464863dea3SSunil Goutham #define SND_QUEUE_SIZE4		4ULL /* 16K entries */
474863dea3SSunil Goutham #define SND_QUEUE_SIZE5		5ULL /* 32K entries */
484863dea3SSunil Goutham #define SND_QUEUE_SIZE6		6ULL /* 64K entries */
494863dea3SSunil Goutham 
504863dea3SSunil Goutham #define CMP_QUEUE_SIZE0		0ULL /* 1K entries */
514863dea3SSunil Goutham #define CMP_QUEUE_SIZE1		1ULL /* 2K entries */
524863dea3SSunil Goutham #define CMP_QUEUE_SIZE2		2ULL /* 4K entries */
534863dea3SSunil Goutham #define CMP_QUEUE_SIZE3		3ULL /* 8K entries */
544863dea3SSunil Goutham #define CMP_QUEUE_SIZE4		4ULL /* 16K entries */
554863dea3SSunil Goutham #define CMP_QUEUE_SIZE5		5ULL /* 32K entries */
564863dea3SSunil Goutham #define CMP_QUEUE_SIZE6		6ULL /* 64K entries */
574863dea3SSunil Goutham 
584863dea3SSunil Goutham /* Default queue count per QS, its lengths and threshold values */
593a397ebeSSunil Goutham #define DEFAULT_RBDR_CNT	1
604863dea3SSunil Goutham 
61fff4ffddSSunil Goutham #define SND_QSIZE		SND_QUEUE_SIZE0
624863dea3SSunil Goutham #define SND_QUEUE_LEN		(1ULL << (SND_QSIZE + 10))
63fff4ffddSSunil Goutham #define MIN_SND_QUEUE_LEN	(1ULL << (SND_QUEUE_SIZE0 + 10))
644863dea3SSunil Goutham #define MAX_SND_QUEUE_LEN	(1ULL << (SND_QUEUE_SIZE6 + 10))
654863dea3SSunil Goutham #define SND_QUEUE_THRESH	2ULL
664863dea3SSunil Goutham #define MIN_SQ_DESC_PER_PKT_XMIT	2
674863dea3SSunil Goutham /* Since timestamp not enabled, otherwise 2 */
684863dea3SSunil Goutham #define MAX_CQE_PER_PKT_XMIT		1
694863dea3SSunil Goutham 
7032c1b965SSunil Goutham /* Keep CQ and SQ sizes same, if timestamping
7132c1b965SSunil Goutham  * is enabled this equation will change.
7232c1b965SSunil Goutham  */
73fff4ffddSSunil Goutham #define CMP_QSIZE		CMP_QUEUE_SIZE0
744863dea3SSunil Goutham #define CMP_QUEUE_LEN		(1ULL << (CMP_QSIZE + 10))
75fff4ffddSSunil Goutham #define MIN_CMP_QUEUE_LEN	(1ULL << (CMP_QUEUE_SIZE0 + 10))
76fff4ffddSSunil Goutham #define MAX_CMP_QUEUE_LEN	(1ULL << (CMP_QUEUE_SIZE6 + 10))
77b9687b48SSunil Goutham #define CMP_QUEUE_CQE_THRESH	(NAPI_POLL_WEIGHT / 2)
78006394a7SSunil Goutham #define CMP_QUEUE_TIMER_THRESH	80 /* ~2usec */
794863dea3SSunil Goutham 
80fff4ffddSSunil Goutham /* No of CQEs that might anyway gets used by HW due to pipelining
81fff4ffddSSunil Goutham  * effects irrespective of PASS/DROP/LEVELS being configured
82fff4ffddSSunil Goutham  */
83fff4ffddSSunil Goutham #define CMP_QUEUE_PIPELINE_RSVD 544
84fff4ffddSSunil Goutham 
854863dea3SSunil Goutham #define RBDR_SIZE		RBDR_SIZE0
864863dea3SSunil Goutham #define RCV_BUF_COUNT		(1ULL << (RBDR_SIZE + 13))
874863dea3SSunil Goutham #define MAX_RCV_BUF_COUNT	(1ULL << (RBDR_SIZE6 + 13))
884863dea3SSunil Goutham #define RBDR_THRESH		(RCV_BUF_COUNT / 2)
8983abb7d7SSunil Goutham #define DMA_BUFFER_LEN		1536 /* In multiples of 128bytes */
904863dea3SSunil Goutham #define RCV_FRAG_LEN	 (SKB_DATA_ALIGN(DMA_BUFFER_LEN + NET_SKB_PAD) + \
91668dda06SSunil Goutham 			 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
924863dea3SSunil Goutham 
934863dea3SSunil Goutham #define MAX_CQES_FOR_TX		((SND_QUEUE_LEN / MIN_SQ_DESC_PER_PKT_XMIT) * \
944863dea3SSunil Goutham 				 MAX_CQE_PER_PKT_XMIT)
95d5b2d7a7SSunil Goutham 
96d5b2d7a7SSunil Goutham /* RED and Backpressure levels of CQ for pkt reception
97d5b2d7a7SSunil Goutham  * For CQ, level is a measure of emptiness i.e 0x0 means full
98bd3ad7d3SSunil Goutham  * eg: For CQ of size 4K, and for pass/drop levels of 160/144
99bd3ad7d3SSunil Goutham  * HW accepts pkt if unused CQE >= 2560
100bd3ad7d3SSunil Goutham  * RED accepts pkt if unused CQE < 2304 & >= 2560
101bd3ad7d3SSunil Goutham  * DROPs pkts if unused CQE < 2304
10232c1b965SSunil Goutham  */
103c0d2507aSSunil Goutham #define RQ_PASS_CQ_LVL         224ULL
104c0d2507aSSunil Goutham #define RQ_DROP_CQ_LVL         216ULL
105d5b2d7a7SSunil Goutham 
106d5b2d7a7SSunil Goutham /* RED and Backpressure levels of RBDR for pkt reception
107d5b2d7a7SSunil Goutham  * For RBDR, level is a measure of fullness i.e 0x0 means empty
108d5b2d7a7SSunil Goutham  * eg: For RBDR of size 8K, and for pass/drop levels of 4/0
109d5b2d7a7SSunil Goutham  * HW accepts pkt if unused RBs >= 256
110d5b2d7a7SSunil Goutham  * RED accepts pkt if unused RBs < 256 & >= 0
111d5b2d7a7SSunil Goutham  * DROPs pkts if unused RBs < 0
112d5b2d7a7SSunil Goutham  */
113d5b2d7a7SSunil Goutham #define RQ_PASS_RBDR_LVL	8ULL
114d5b2d7a7SSunil Goutham #define RQ_DROP_RBDR_LVL	0ULL
1154863dea3SSunil Goutham 
1164863dea3SSunil Goutham /* Descriptor size in bytes */
1174863dea3SSunil Goutham #define SND_QUEUE_DESC_SIZE	16
1184863dea3SSunil Goutham #define CMP_QUEUE_DESC_SIZE	512
1194863dea3SSunil Goutham 
1204863dea3SSunil Goutham /* Buffer / descriptor alignments */
1214863dea3SSunil Goutham #define NICVF_RCV_BUF_ALIGN		7
1224863dea3SSunil Goutham #define NICVF_RCV_BUF_ALIGN_BYTES	(1ULL << NICVF_RCV_BUF_ALIGN)
1234863dea3SSunil Goutham #define NICVF_CQ_BASE_ALIGN_BYTES	512  /* 9 bits */
1244863dea3SSunil Goutham #define NICVF_SQ_BASE_ALIGN_BYTES	128  /* 7 bits */
1254863dea3SSunil Goutham 
1264863dea3SSunil Goutham #define NICVF_ALIGNED_ADDR(ADDR, ALIGN_BYTES)	ALIGN(ADDR, ALIGN_BYTES)
1274863dea3SSunil Goutham 
1284863dea3SSunil Goutham /* Queue enable/disable */
1294863dea3SSunil Goutham #define NICVF_SQ_EN		BIT_ULL(19)
1304863dea3SSunil Goutham 
1314863dea3SSunil Goutham /* Queue reset */
1324863dea3SSunil Goutham #define NICVF_CQ_RESET		BIT_ULL(41)
1334863dea3SSunil Goutham #define NICVF_SQ_RESET		BIT_ULL(17)
1344863dea3SSunil Goutham #define NICVF_RBDR_RESET	BIT_ULL(43)
1354863dea3SSunil Goutham 
1364863dea3SSunil Goutham enum CQ_RX_ERRLVL_E {
1374863dea3SSunil Goutham 	CQ_ERRLVL_MAC,
1384863dea3SSunil Goutham 	CQ_ERRLVL_L2,
1394863dea3SSunil Goutham 	CQ_ERRLVL_L3,
1404863dea3SSunil Goutham 	CQ_ERRLVL_L4,
1414863dea3SSunil Goutham };
1424863dea3SSunil Goutham 
1434863dea3SSunil Goutham enum CQ_RX_ERROP_E {
1444863dea3SSunil Goutham 	CQ_RX_ERROP_RE_NONE = 0x0,
1454863dea3SSunil Goutham 	CQ_RX_ERROP_RE_PARTIAL = 0x1,
1464863dea3SSunil Goutham 	CQ_RX_ERROP_RE_JABBER = 0x2,
1474863dea3SSunil Goutham 	CQ_RX_ERROP_RE_FCS = 0x7,
1484863dea3SSunil Goutham 	CQ_RX_ERROP_RE_TERMINATE = 0x9,
1494863dea3SSunil Goutham 	CQ_RX_ERROP_RE_RX_CTL = 0xb,
1504863dea3SSunil Goutham 	CQ_RX_ERROP_PREL2_ERR = 0x1f,
1514863dea3SSunil Goutham 	CQ_RX_ERROP_L2_FRAGMENT = 0x20,
1524863dea3SSunil Goutham 	CQ_RX_ERROP_L2_OVERRUN = 0x21,
1534863dea3SSunil Goutham 	CQ_RX_ERROP_L2_PFCS = 0x22,
1544863dea3SSunil Goutham 	CQ_RX_ERROP_L2_PUNY = 0x23,
1554863dea3SSunil Goutham 	CQ_RX_ERROP_L2_MAL = 0x24,
1564863dea3SSunil Goutham 	CQ_RX_ERROP_L2_OVERSIZE = 0x25,
1574863dea3SSunil Goutham 	CQ_RX_ERROP_L2_UNDERSIZE = 0x26,
1584863dea3SSunil Goutham 	CQ_RX_ERROP_L2_LENMISM = 0x27,
1594863dea3SSunil Goutham 	CQ_RX_ERROP_L2_PCLP = 0x28,
1604863dea3SSunil Goutham 	CQ_RX_ERROP_IP_NOT = 0x41,
1614863dea3SSunil Goutham 	CQ_RX_ERROP_IP_CSUM_ERR = 0x42,
1624863dea3SSunil Goutham 	CQ_RX_ERROP_IP_MAL = 0x43,
1634863dea3SSunil Goutham 	CQ_RX_ERROP_IP_MALD = 0x44,
1644863dea3SSunil Goutham 	CQ_RX_ERROP_IP_HOP = 0x45,
1654863dea3SSunil Goutham 	CQ_RX_ERROP_L3_ICRC = 0x46,
1664863dea3SSunil Goutham 	CQ_RX_ERROP_L3_PCLP = 0x47,
1674863dea3SSunil Goutham 	CQ_RX_ERROP_L4_MAL = 0x61,
1684863dea3SSunil Goutham 	CQ_RX_ERROP_L4_CHK = 0x62,
1694863dea3SSunil Goutham 	CQ_RX_ERROP_UDP_LEN = 0x63,
1704863dea3SSunil Goutham 	CQ_RX_ERROP_L4_PORT = 0x64,
1714863dea3SSunil Goutham 	CQ_RX_ERROP_TCP_FLAG = 0x65,
1724863dea3SSunil Goutham 	CQ_RX_ERROP_TCP_OFFSET = 0x66,
1734863dea3SSunil Goutham 	CQ_RX_ERROP_L4_PCLP = 0x67,
1744863dea3SSunil Goutham 	CQ_RX_ERROP_RBDR_TRUNC = 0x70,
1754863dea3SSunil Goutham };
1764863dea3SSunil Goutham 
1774863dea3SSunil Goutham enum CQ_TX_ERROP_E {
1784863dea3SSunil Goutham 	CQ_TX_ERROP_GOOD = 0x0,
1794863dea3SSunil Goutham 	CQ_TX_ERROP_DESC_FAULT = 0x10,
1804863dea3SSunil Goutham 	CQ_TX_ERROP_HDR_CONS_ERR = 0x11,
1814863dea3SSunil Goutham 	CQ_TX_ERROP_SUBDC_ERR = 0x12,
182712c3185SSunil Goutham 	CQ_TX_ERROP_MAX_SIZE_VIOL = 0x13,
1834863dea3SSunil Goutham 	CQ_TX_ERROP_IMM_SIZE_OFLOW = 0x80,
1844863dea3SSunil Goutham 	CQ_TX_ERROP_DATA_SEQUENCE_ERR = 0x81,
1854863dea3SSunil Goutham 	CQ_TX_ERROP_MEM_SEQUENCE_ERR = 0x82,
1864863dea3SSunil Goutham 	CQ_TX_ERROP_LOCK_VIOL = 0x83,
1874863dea3SSunil Goutham 	CQ_TX_ERROP_DATA_FAULT = 0x84,
1884863dea3SSunil Goutham 	CQ_TX_ERROP_TSTMP_CONFLICT = 0x85,
1894863dea3SSunil Goutham 	CQ_TX_ERROP_TSTMP_TIMEOUT = 0x86,
1904863dea3SSunil Goutham 	CQ_TX_ERROP_MEM_FAULT = 0x87,
1914863dea3SSunil Goutham 	CQ_TX_ERROP_CK_OVERLAP = 0x88,
1924863dea3SSunil Goutham 	CQ_TX_ERROP_CK_OFLOW = 0x89,
1934863dea3SSunil Goutham 	CQ_TX_ERROP_ENUM_LAST = 0x8a,
1944863dea3SSunil Goutham };
1954863dea3SSunil Goutham 
1964863dea3SSunil Goutham enum RQ_SQ_STATS {
1974863dea3SSunil Goutham 	RQ_SQ_STATS_OCTS,
1984863dea3SSunil Goutham 	RQ_SQ_STATS_PKTS,
1994863dea3SSunil Goutham };
2004863dea3SSunil Goutham 
2014863dea3SSunil Goutham struct rx_tx_queue_stats {
2024863dea3SSunil Goutham 	u64	bytes;
2034863dea3SSunil Goutham 	u64	pkts;
2044863dea3SSunil Goutham } ____cacheline_aligned_in_smp;
2054863dea3SSunil Goutham 
2064863dea3SSunil Goutham struct q_desc_mem {
2074863dea3SSunil Goutham 	dma_addr_t	dma;
2084863dea3SSunil Goutham 	u64		size;
20988c991a9SDean Nelson 	u32		q_len;
2104863dea3SSunil Goutham 	dma_addr_t	phys_base;
2114863dea3SSunil Goutham 	void		*base;
2124863dea3SSunil Goutham 	void		*unalign_base;
2134863dea3SSunil Goutham };
2144863dea3SSunil Goutham 
2155836b442SSunil Goutham struct pgcache {
2165836b442SSunil Goutham 	struct page	*page;
21777322538SSunil Goutham 	int		ref_count;
2185836b442SSunil Goutham 	u64		dma_addr;
2195836b442SSunil Goutham };
2205836b442SSunil Goutham 
2214863dea3SSunil Goutham struct rbdr {
2224863dea3SSunil Goutham 	bool		enable;
2234863dea3SSunil Goutham 	u32		dma_size;
2244863dea3SSunil Goutham 	u32		frag_len;
2254863dea3SSunil Goutham 	u32		thresh;		/* Threshold level for interrupt */
2264863dea3SSunil Goutham 	void		*desc;
2274863dea3SSunil Goutham 	u32		head;
2284863dea3SSunil Goutham 	u32		tail;
2294863dea3SSunil Goutham 	struct q_desc_mem   dmem;
230c56d91ceSSunil Goutham 	bool		is_xdp;
2315836b442SSunil Goutham 
2325836b442SSunil Goutham 	/* For page recycling */
2335836b442SSunil Goutham 	int		pgidx;
2345836b442SSunil Goutham 	int		pgcnt;
2355836b442SSunil Goutham 	int		pgalloc;
2365836b442SSunil Goutham 	struct pgcache	*pgcache;
2374863dea3SSunil Goutham } ____cacheline_aligned_in_smp;
2384863dea3SSunil Goutham 
2394863dea3SSunil Goutham struct rcv_queue {
2404863dea3SSunil Goutham 	bool		enable;
2414863dea3SSunil Goutham 	struct	rbdr	*rbdr_start;
2424863dea3SSunil Goutham 	struct	rbdr	*rbdr_cont;
2434863dea3SSunil Goutham 	bool		en_tcp_reassembly;
2444863dea3SSunil Goutham 	u8		cq_qs;  /* CQ's QS to which this RQ is assigned */
2454863dea3SSunil Goutham 	u8		cq_idx; /* CQ index (0 to 7) in the QS */
2464863dea3SSunil Goutham 	u8		cont_rbdr_qs;      /* Continue buffer ptrs - QS num */
2474863dea3SSunil Goutham 	u8		cont_qs_rbdr_idx;  /* RBDR idx in the cont QS */
2484863dea3SSunil Goutham 	u8		start_rbdr_qs;     /* First buffer ptrs - QS num */
2494863dea3SSunil Goutham 	u8		start_qs_rbdr_idx; /* RBDR idx in the above QS */
2504863dea3SSunil Goutham 	u8		caching;
2514863dea3SSunil Goutham 	struct		rx_tx_queue_stats stats;
25227e95e36SJesper Dangaard Brouer 	struct xdp_rxq_info xdp_rxq;
2534863dea3SSunil Goutham } ____cacheline_aligned_in_smp;
2544863dea3SSunil Goutham 
2554863dea3SSunil Goutham struct cmp_queue {
2564863dea3SSunil Goutham 	bool		enable;
2574863dea3SSunil Goutham 	u16		thresh;
2584863dea3SSunil Goutham 	spinlock_t	lock;  /* lock to serialize processing CQEs */
2594863dea3SSunil Goutham 	void		*desc;
2604863dea3SSunil Goutham 	struct q_desc_mem   dmem;
26139ad6eeaSSunil Goutham 	int		irq;
2624863dea3SSunil Goutham } ____cacheline_aligned_in_smp;
2634863dea3SSunil Goutham 
2644863dea3SSunil Goutham struct snd_queue {
2654863dea3SSunil Goutham 	bool		enable;
2664863dea3SSunil Goutham 	u8		cq_qs;  /* CQ's QS to which this SQ is pointing */
2674863dea3SSunil Goutham 	u8		cq_idx; /* CQ index (0 to 7) in the above QS */
2684863dea3SSunil Goutham 	u16		thresh;
2694863dea3SSunil Goutham 	atomic_t	free_cnt;
2704863dea3SSunil Goutham 	u32		head;
2714863dea3SSunil Goutham 	u32		tail;
2724863dea3SSunil Goutham 	u64		*skbuff;
2734863dea3SSunil Goutham 	void		*desc;
27416f2bccdSSunil Goutham 	u64		*xdp_page;
27516f2bccdSSunil Goutham 	u16		xdp_desc_cnt;
27616f2bccdSSunil Goutham 	u16		xdp_free_cnt;
27716f2bccdSSunil Goutham 	bool		is_xdp;
2784863dea3SSunil Goutham 
2794863dea3SSunil Goutham 	/* For TSO segment's header */
2804863dea3SSunil Goutham 	char		*tso_hdrs;
2814863dea3SSunil Goutham 	dma_addr_t	tso_hdrs_phys;
2824863dea3SSunil Goutham 
2834863dea3SSunil Goutham 	cpumask_t	affinity_mask;
2844863dea3SSunil Goutham 	struct q_desc_mem   dmem;
2854863dea3SSunil Goutham 	struct rx_tx_queue_stats stats;
2864863dea3SSunil Goutham } ____cacheline_aligned_in_smp;
2874863dea3SSunil Goutham 
2884863dea3SSunil Goutham struct queue_set {
2894863dea3SSunil Goutham 	bool		enable;
2904863dea3SSunil Goutham 	bool		be_en;
2914863dea3SSunil Goutham 	u8		vnic_id;
2924863dea3SSunil Goutham 	u8		rq_cnt;
2934863dea3SSunil Goutham 	u8		cq_cnt;
2944863dea3SSunil Goutham 	u64		cq_len;
2954863dea3SSunil Goutham 	u8		sq_cnt;
2964863dea3SSunil Goutham 	u64		sq_len;
2974863dea3SSunil Goutham 	u8		rbdr_cnt;
2984863dea3SSunil Goutham 	u64		rbdr_len;
2994863dea3SSunil Goutham 	struct	rcv_queue	rq[MAX_RCV_QUEUES_PER_QS];
3004863dea3SSunil Goutham 	struct	cmp_queue	cq[MAX_CMP_QUEUES_PER_QS];
3014863dea3SSunil Goutham 	struct	snd_queue	sq[MAX_SND_QUEUES_PER_QS];
3024863dea3SSunil Goutham 	struct	rbdr		rbdr[MAX_RCV_BUF_DESC_RINGS_PER_QS];
3034863dea3SSunil Goutham } ____cacheline_aligned_in_smp;
3044863dea3SSunil Goutham 
3054863dea3SSunil Goutham #define GET_RBDR_DESC(RING, idx)\
3064863dea3SSunil Goutham 		(&(((struct rbdr_entry_t *)((RING)->desc))[idx]))
3074863dea3SSunil Goutham #define GET_SQ_DESC(RING, idx)\
3084863dea3SSunil Goutham 		(&(((struct sq_hdr_subdesc *)((RING)->desc))[idx]))
3094863dea3SSunil Goutham #define GET_CQ_DESC(RING, idx)\
3104863dea3SSunil Goutham 		(&(((union cq_desc_t *)((RING)->desc))[idx]))
3114863dea3SSunil Goutham 
3124863dea3SSunil Goutham /* CQ status bits */
3134863dea3SSunil Goutham #define	CQ_WR_FULL	BIT(26)
3144863dea3SSunil Goutham #define	CQ_WR_DISABLE	BIT(25)
3154863dea3SSunil Goutham #define	CQ_WR_FAULT	BIT(24)
3164863dea3SSunil Goutham #define	CQ_CQE_COUNT	(0xFFFF << 0)
3174863dea3SSunil Goutham 
3184863dea3SSunil Goutham #define	CQ_ERR_MASK	(CQ_WR_FULL | CQ_WR_DISABLE | CQ_WR_FAULT)
3194863dea3SSunil Goutham 
nicvf_iova_to_phys(struct nicvf * nic,dma_addr_t dma_addr)32005c773f5SSunil Goutham static inline u64 nicvf_iova_to_phys(struct nicvf *nic, dma_addr_t dma_addr)
32105c773f5SSunil Goutham {
32205c773f5SSunil Goutham 	/* Translation is installed only when IOMMU is present */
32305c773f5SSunil Goutham 	if (nic->iommu_domain)
32405c773f5SSunil Goutham 		return iommu_iova_to_phys(nic->iommu_domain, dma_addr);
32505c773f5SSunil Goutham 	return dma_addr;
32605c773f5SSunil Goutham }
32705c773f5SSunil Goutham 
32883abb7d7SSunil Goutham void nicvf_unmap_sndq_buffers(struct nicvf *nic, struct snd_queue *sq,
32983abb7d7SSunil Goutham 			      int hdr_sqe, u8 subdesc_cnt);
330aa2e259bSSunil Goutham void nicvf_config_vlan_stripping(struct nicvf *nic,
331aa2e259bSSunil Goutham 				 netdev_features_t features);
3324863dea3SSunil Goutham int nicvf_set_qset_resources(struct nicvf *nic);
3334863dea3SSunil Goutham int nicvf_config_data_transfer(struct nicvf *nic, bool enable);
3344863dea3SSunil Goutham void nicvf_qset_config(struct nicvf *nic, bool enable);
3354863dea3SSunil Goutham void nicvf_cmp_queue_config(struct nicvf *nic, struct queue_set *qs,
3364863dea3SSunil Goutham 			    int qidx, bool enable);
3374863dea3SSunil Goutham 
3384863dea3SSunil Goutham void nicvf_sq_enable(struct nicvf *nic, struct snd_queue *sq, int qidx);
3394863dea3SSunil Goutham void nicvf_sq_disable(struct nicvf *nic, int qidx);
3404863dea3SSunil Goutham void nicvf_put_sq_desc(struct snd_queue *sq, int desc_cnt);
3414863dea3SSunil Goutham void nicvf_sq_free_used_descs(struct net_device *netdev,
3424863dea3SSunil Goutham 			      struct snd_queue *sq, int qidx);
343bd3ad7d3SSunil Goutham int nicvf_sq_append_skb(struct nicvf *nic, struct snd_queue *sq,
344bd3ad7d3SSunil Goutham 			struct sk_buff *skb, u8 sq_num);
34516f2bccdSSunil Goutham int nicvf_xdp_sq_append_pkt(struct nicvf *nic, struct snd_queue *sq,
34616f2bccdSSunil Goutham 			    u64 bufaddr, u64 dma_addr, u16 len);
34716f2bccdSSunil Goutham void nicvf_xdp_sq_doorbell(struct nicvf *nic, struct snd_queue *sq, int sq_num);
3484863dea3SSunil Goutham 
349c56d91ceSSunil Goutham struct sk_buff *nicvf_get_rcv_skb(struct nicvf *nic,
350c56d91ceSSunil Goutham 				  struct cqe_rx_t *cqe_rx, bool xdp);
351*dfe4e612SAllen Pais void nicvf_rbdr_task(struct tasklet_struct *t);
3524863dea3SSunil Goutham void nicvf_rbdr_work(struct work_struct *work);
3534863dea3SSunil Goutham 
3544863dea3SSunil Goutham void nicvf_enable_intr(struct nicvf *nic, int int_type, int q_idx);
3554863dea3SSunil Goutham void nicvf_disable_intr(struct nicvf *nic, int int_type, int q_idx);
3564863dea3SSunil Goutham void nicvf_clear_intr(struct nicvf *nic, int int_type, int q_idx);
3574863dea3SSunil Goutham int nicvf_is_intr_enabled(struct nicvf *nic, int int_type, int q_idx);
3584863dea3SSunil Goutham 
3594863dea3SSunil Goutham /* Register access APIs */
3604863dea3SSunil Goutham void nicvf_reg_write(struct nicvf *nic, u64 offset, u64 val);
3614863dea3SSunil Goutham u64  nicvf_reg_read(struct nicvf *nic, u64 offset);
3624863dea3SSunil Goutham void nicvf_qset_reg_write(struct nicvf *nic, u64 offset, u64 val);
3634863dea3SSunil Goutham u64 nicvf_qset_reg_read(struct nicvf *nic, u64 offset);
3644863dea3SSunil Goutham void nicvf_queue_reg_write(struct nicvf *nic, u64 offset,
3654863dea3SSunil Goutham 			   u64 qidx, u64 val);
3664863dea3SSunil Goutham u64  nicvf_queue_reg_read(struct nicvf *nic,
3674863dea3SSunil Goutham 			  u64 offset, u64 qidx);
3684863dea3SSunil Goutham 
3694863dea3SSunil Goutham /* Stats */
3704863dea3SSunil Goutham void nicvf_update_rq_stats(struct nicvf *nic, int rq_idx);
3714863dea3SSunil Goutham void nicvf_update_sq_stats(struct nicvf *nic, int sq_idx);
372ad2ecebdSSunil Goutham int nicvf_check_cqe_rx_errs(struct nicvf *nic, struct cqe_rx_t *cqe_rx);
373964cb69bSSunil Goutham int nicvf_check_cqe_tx_errs(struct nicvf *nic, struct cqe_send_t *cqe_tx);
3744863dea3SSunil Goutham #endif /* NICVF_QUEUES_H */
375