xref: /openbmc/linux/drivers/net/ethernet/intel/ice/ice.h (revision 0fee35774d8f2277cfb101dd1d9d0d5e39015b93)
1837f08fdSAnirudh Venkataramanan /* SPDX-License-Identifier: GPL-2.0 */
2837f08fdSAnirudh Venkataramanan /* Copyright (c) 2018, Intel Corporation. */
3837f08fdSAnirudh Venkataramanan 
4837f08fdSAnirudh Venkataramanan #ifndef _ICE_H_
5837f08fdSAnirudh Venkataramanan #define _ICE_H_
6837f08fdSAnirudh Venkataramanan 
7837f08fdSAnirudh Venkataramanan #include <linux/types.h>
8837f08fdSAnirudh Venkataramanan #include <linux/errno.h>
9837f08fdSAnirudh Venkataramanan #include <linux/kernel.h>
10837f08fdSAnirudh Venkataramanan #include <linux/module.h>
11462acf6aSTony Nguyen #include <linux/firmware.h>
12837f08fdSAnirudh Venkataramanan #include <linux/netdevice.h>
13837f08fdSAnirudh Venkataramanan #include <linux/compiler.h>
14dc49c772SAnirudh Venkataramanan #include <linux/etherdevice.h>
15cdedef59SAnirudh Venkataramanan #include <linux/skbuff.h>
163a858ba3SAnirudh Venkataramanan #include <linux/cpumask.h>
17fcea6f3dSAnirudh Venkataramanan #include <linux/rtnetlink.h>
183a858ba3SAnirudh Venkataramanan #include <linux/if_vlan.h>
19cdedef59SAnirudh Venkataramanan #include <linux/dma-mapping.h>
20837f08fdSAnirudh Venkataramanan #include <linux/pci.h>
21940b61afSAnirudh Venkataramanan #include <linux/workqueue.h>
22837f08fdSAnirudh Venkataramanan #include <linux/aer.h>
23940b61afSAnirudh Venkataramanan #include <linux/interrupt.h>
24fcea6f3dSAnirudh Venkataramanan #include <linux/ethtool.h>
25940b61afSAnirudh Venkataramanan #include <linux/timer.h>
267ec59eeaSAnirudh Venkataramanan #include <linux/delay.h>
27837f08fdSAnirudh Venkataramanan #include <linux/bitmap.h>
283a858ba3SAnirudh Venkataramanan #include <linux/log2.h>
29d76a60baSAnirudh Venkataramanan #include <linux/ip.h>
30cf909e19SAnirudh Venkataramanan #include <linux/sctp.h>
31d76a60baSAnirudh Venkataramanan #include <linux/ipv6.h>
32efc2214bSMaciej Fijalkowski #include <linux/pkt_sched.h>
33940b61afSAnirudh Venkataramanan #include <linux/if_bridge.h>
34e3710a01SPaul M Stillwell Jr #include <linux/ctype.h>
35efc2214bSMaciej Fijalkowski #include <linux/bpf.h>
36ddf30f7fSAnirudh Venkataramanan #include <linux/avf/virtchnl.h>
371adf7eadSJacob Keller #include <net/devlink.h>
38d76a60baSAnirudh Venkataramanan #include <net/ipv6.h>
392d4238f5SKrzysztof Kazimierczak #include <net/xdp_sock.h>
40a4e82a81STony Nguyen #include <net/geneve.h>
41a4e82a81STony Nguyen #include <net/gre.h>
42a4e82a81STony Nguyen #include <net/udp_tunnel.h>
43a4e82a81STony Nguyen #include <net/vxlan.h>
44837f08fdSAnirudh Venkataramanan #include "ice_devids.h"
45837f08fdSAnirudh Venkataramanan #include "ice_type.h"
46940b61afSAnirudh Venkataramanan #include "ice_txrx.h"
4737b6f646SAnirudh Venkataramanan #include "ice_dcb.h"
489c20346bSAnirudh Venkataramanan #include "ice_switch.h"
49f31e4b6fSAnirudh Venkataramanan #include "ice_common.h"
509c20346bSAnirudh Venkataramanan #include "ice_sched.h"
51ddf30f7fSAnirudh Venkataramanan #include "ice_virtchnl_pf.h"
52007676b4SAnirudh Venkataramanan #include "ice_sriov.h"
532d4238f5SKrzysztof Kazimierczak #include "ice_xsk.h"
54837f08fdSAnirudh Venkataramanan 
55fcea6f3dSAnirudh Venkataramanan extern const char ice_drv_ver[];
56837f08fdSAnirudh Venkataramanan #define ICE_BAR0		0
573a858ba3SAnirudh Venkataramanan #define ICE_REQ_DESC_MULTIPLE	32
588be92a76SPreethi Banala #define ICE_MIN_NUM_DESC	64
593b6bf296SBruce Allan #define ICE_MAX_NUM_DESC	8160
601aec6e1bSBrett Creeley #define ICE_DFLT_MIN_RX_DESC	512
61dd47e1fdSJesse Brandeburg #define ICE_DFLT_NUM_TX_DESC	256
62dd47e1fdSJesse Brandeburg #define ICE_DFLT_NUM_RX_DESC	2048
63ad71b256SBrett Creeley 
645513b920SAnirudh Venkataramanan #define ICE_DFLT_TRAFFIC_CLASS	BIT(0)
65940b61afSAnirudh Venkataramanan #define ICE_INT_NAME_STR_LEN	(IFNAMSIZ + 16)
66f31e4b6fSAnirudh Venkataramanan #define ICE_AQ_LEN		64
6711836214SBrett Creeley #define ICE_MBXSQ_LEN		64
68940b61afSAnirudh Venkataramanan #define ICE_MIN_MSIX		2
693a858ba3SAnirudh Venkataramanan #define ICE_NO_VSI		0xffff
703a858ba3SAnirudh Venkataramanan #define ICE_VSI_MAP_CONTIG	0
713a858ba3SAnirudh Venkataramanan #define ICE_VSI_MAP_SCATTER	1
723a858ba3SAnirudh Venkataramanan #define ICE_MAX_SCATTER_TXQS	16
733a858ba3SAnirudh Venkataramanan #define ICE_MAX_SCATTER_RXQS	16
74cdedef59SAnirudh Venkataramanan #define ICE_Q_WAIT_RETRY_LIMIT	10
75cdedef59SAnirudh Venkataramanan #define ICE_Q_WAIT_MAX_RETRY	(5 * ICE_Q_WAIT_RETRY_LIMIT)
76d76a60baSAnirudh Venkataramanan #define ICE_MAX_LG_RSS_QS	256
77940b61afSAnirudh Venkataramanan #define ICE_RES_VALID_BIT	0x8000
78940b61afSAnirudh Venkataramanan #define ICE_RES_MISC_VEC_ID	(ICE_RES_VALID_BIT - 1)
793a858ba3SAnirudh Venkataramanan #define ICE_INVAL_Q_INDEX	0xffff
800f9d5027SAnirudh Venkataramanan #define ICE_INVAL_VFID		256
81837f08fdSAnirudh Venkataramanan 
82afd9d4abSAnirudh Venkataramanan #define ICE_MAX_RESET_WAIT		20
83afd9d4abSAnirudh Venkataramanan 
84fcea6f3dSAnirudh Venkataramanan #define ICE_VSIQF_HKEY_ARRAY_SIZE	((VSIQF_HKEY_MAX_INDEX + 1) *	4)
85fcea6f3dSAnirudh Venkataramanan 
86837f08fdSAnirudh Venkataramanan #define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
87837f08fdSAnirudh Venkataramanan 
88efc2214bSMaciej Fijalkowski #define ICE_MAX_MTU	(ICE_AQ_SET_MAC_FRAME_SIZE_MAX - ICE_ETH_PKT_HDR_PAD)
893a858ba3SAnirudh Venkataramanan 
903a858ba3SAnirudh Venkataramanan #define ICE_UP_TABLE_TRANSLATE(val, i) \
913a858ba3SAnirudh Venkataramanan 		(((val) << ICE_AQ_VSI_UP_TABLE_UP##i##_S) & \
923a858ba3SAnirudh Venkataramanan 		  ICE_AQ_VSI_UP_TABLE_UP##i##_M)
933a858ba3SAnirudh Venkataramanan 
942b245cb2SAnirudh Venkataramanan #define ICE_TX_DESC(R, i) (&(((struct ice_tx_desc *)((R)->desc))[i]))
95cdedef59SAnirudh Venkataramanan #define ICE_RX_DESC(R, i) (&(((union ice_32b_rx_flex_desc *)((R)->desc))[i]))
96d76a60baSAnirudh Venkataramanan #define ICE_TX_CTX_DESC(R, i) (&(((struct ice_tx_ctx_desc *)((R)->desc))[i]))
97cdedef59SAnirudh Venkataramanan 
980b28b702SAnirudh Venkataramanan /* Macro for each VSI in a PF */
990b28b702SAnirudh Venkataramanan #define ice_for_each_vsi(pf, i) \
1000b28b702SAnirudh Venkataramanan 	for ((i) = 0; (i) < (pf)->num_alloc_vsi; (i)++)
1010b28b702SAnirudh Venkataramanan 
102d337f2afSAnirudh Venkataramanan /* Macros for each Tx/Rx ring in a VSI */
103cdedef59SAnirudh Venkataramanan #define ice_for_each_txq(vsi, i) \
104cdedef59SAnirudh Venkataramanan 	for ((i) = 0; (i) < (vsi)->num_txq; (i)++)
105cdedef59SAnirudh Venkataramanan 
106cdedef59SAnirudh Venkataramanan #define ice_for_each_rxq(vsi, i) \
107cdedef59SAnirudh Venkataramanan 	for ((i) = 0; (i) < (vsi)->num_rxq; (i)++)
108cdedef59SAnirudh Venkataramanan 
109d337f2afSAnirudh Venkataramanan /* Macros for each allocated Tx/Rx ring whether used or not in a VSI */
110f8ba7db8SJacob Keller #define ice_for_each_alloc_txq(vsi, i) \
111f8ba7db8SJacob Keller 	for ((i) = 0; (i) < (vsi)->alloc_txq; (i)++)
112f8ba7db8SJacob Keller 
113f8ba7db8SJacob Keller #define ice_for_each_alloc_rxq(vsi, i) \
114f8ba7db8SJacob Keller 	for ((i) = 0; (i) < (vsi)->alloc_rxq; (i)++)
115f8ba7db8SJacob Keller 
11667fe64d7SBrett Creeley #define ice_for_each_q_vector(vsi, i) \
11767fe64d7SBrett Creeley 	for ((i) = 0; (i) < (vsi)->num_q_vectors; (i)++)
11867fe64d7SBrett Creeley 
1195eda8afdSAkeem G Abodunrin #define ICE_UCAST_PROMISC_BITS (ICE_PROMISC_UCAST_TX | ICE_PROMISC_MCAST_TX | \
1205eda8afdSAkeem G Abodunrin 				ICE_PROMISC_UCAST_RX | ICE_PROMISC_MCAST_RX)
1215eda8afdSAkeem G Abodunrin 
1225eda8afdSAkeem G Abodunrin #define ICE_UCAST_VLAN_PROMISC_BITS (ICE_PROMISC_UCAST_TX | \
1235eda8afdSAkeem G Abodunrin 				     ICE_PROMISC_MCAST_TX | \
1245eda8afdSAkeem G Abodunrin 				     ICE_PROMISC_UCAST_RX | \
1255eda8afdSAkeem G Abodunrin 				     ICE_PROMISC_MCAST_RX | \
1265eda8afdSAkeem G Abodunrin 				     ICE_PROMISC_VLAN_TX  | \
1275eda8afdSAkeem G Abodunrin 				     ICE_PROMISC_VLAN_RX)
1285eda8afdSAkeem G Abodunrin 
1295eda8afdSAkeem G Abodunrin #define ICE_MCAST_PROMISC_BITS (ICE_PROMISC_MCAST_TX | ICE_PROMISC_MCAST_RX)
1305eda8afdSAkeem G Abodunrin 
1315eda8afdSAkeem G Abodunrin #define ICE_MCAST_VLAN_PROMISC_BITS (ICE_PROMISC_MCAST_TX | \
1325eda8afdSAkeem G Abodunrin 				     ICE_PROMISC_MCAST_RX | \
1335eda8afdSAkeem G Abodunrin 				     ICE_PROMISC_VLAN_TX  | \
1345eda8afdSAkeem G Abodunrin 				     ICE_PROMISC_VLAN_RX)
1355eda8afdSAkeem G Abodunrin 
1364015d11eSBrett Creeley #define ice_pf_to_dev(pf) (&((pf)->pdev->dev))
1374015d11eSBrett Creeley 
138eff380aaSAnirudh Venkataramanan struct ice_txq_meta {
139eff380aaSAnirudh Venkataramanan 	u32 q_teid;	/* Tx-scheduler element identifier */
140eff380aaSAnirudh Venkataramanan 	u16 q_id;	/* Entry in VSI's txq_map bitmap */
141eff380aaSAnirudh Venkataramanan 	u16 q_handle;	/* Relative index of Tx queue within TC */
142eff380aaSAnirudh Venkataramanan 	u16 vsi_idx;	/* VSI index that Tx queue belongs to */
143eff380aaSAnirudh Venkataramanan 	u8 tc;		/* TC number that Tx queue belongs to */
144eff380aaSAnirudh Venkataramanan };
145eff380aaSAnirudh Venkataramanan 
1463a858ba3SAnirudh Venkataramanan struct ice_tc_info {
1473a858ba3SAnirudh Venkataramanan 	u16 qoffset;
148c5a2a4a3SUsha Ketineni 	u16 qcount_tx;
149c5a2a4a3SUsha Ketineni 	u16 qcount_rx;
150c5a2a4a3SUsha Ketineni 	u8 netdev_tc;
1513a858ba3SAnirudh Venkataramanan };
1523a858ba3SAnirudh Venkataramanan 
1533a858ba3SAnirudh Venkataramanan struct ice_tc_cfg {
1543a858ba3SAnirudh Venkataramanan 	u8 numtc; /* Total number of enabled TCs */
155f9867df6SAnirudh Venkataramanan 	u8 ena_tc; /* Tx map */
1563a858ba3SAnirudh Venkataramanan 	struct ice_tc_info tc_info[ICE_MAX_TRAFFIC_CLASS];
1573a858ba3SAnirudh Venkataramanan };
1583a858ba3SAnirudh Venkataramanan 
159940b61afSAnirudh Venkataramanan struct ice_res_tracker {
160940b61afSAnirudh Venkataramanan 	u16 num_entries;
161cbe66bfeSBrett Creeley 	u16 end;
162940b61afSAnirudh Venkataramanan 	u16 list[1];
163940b61afSAnirudh Venkataramanan };
164940b61afSAnirudh Venkataramanan 
16503f7a986SAnirudh Venkataramanan struct ice_qs_cfg {
16694c4441bSAnirudh Venkataramanan 	struct mutex *qs_mutex;  /* will be assigned to &pf->avail_q_mutex */
16703f7a986SAnirudh Venkataramanan 	unsigned long *pf_map;
16803f7a986SAnirudh Venkataramanan 	unsigned long pf_map_size;
16903f7a986SAnirudh Venkataramanan 	unsigned int q_count;
17003f7a986SAnirudh Venkataramanan 	unsigned int scatter_count;
17103f7a986SAnirudh Venkataramanan 	u16 *vsi_map;
17203f7a986SAnirudh Venkataramanan 	u16 vsi_map_offset;
17303f7a986SAnirudh Venkataramanan 	u8 mapping_mode;
17403f7a986SAnirudh Venkataramanan };
17503f7a986SAnirudh Venkataramanan 
176940b61afSAnirudh Venkataramanan struct ice_sw {
177940b61afSAnirudh Venkataramanan 	struct ice_pf *pf;
178940b61afSAnirudh Venkataramanan 	u16 sw_id;		/* switch ID for this switch */
179940b61afSAnirudh Venkataramanan 	u16 bridge_mode;	/* VEB/VEPA/Port Virtualizer */
180fc0f39bcSBrett Creeley 	struct ice_vsi *dflt_vsi;	/* default VSI for this switch */
181fc0f39bcSBrett Creeley 	u8 dflt_vsi_ena:1;	/* true if above dflt_vsi is enabled */
182940b61afSAnirudh Venkataramanan };
183940b61afSAnirudh Venkataramanan 
184837f08fdSAnirudh Venkataramanan enum ice_state {
1850e674aebSAnirudh Venkataramanan 	__ICE_TESTING,
186837f08fdSAnirudh Venkataramanan 	__ICE_DOWN,
1870b28b702SAnirudh Venkataramanan 	__ICE_NEEDS_RESTART,
1880f9d5027SAnirudh Venkataramanan 	__ICE_PREPARED_FOR_RESET,	/* set by driver when prepared */
1895df7e45dSDave Ertman 	__ICE_RESET_OICR_RECV,		/* set by driver after rcv reset OICR */
190b94b013eSDave Ertman 	__ICE_DCBNL_DEVRESET,		/* set by dcbnl devreset */
191940b61afSAnirudh Venkataramanan 	__ICE_PFR_REQ,			/* set by driver and peers */
1920b28b702SAnirudh Venkataramanan 	__ICE_CORER_REQ,		/* set by driver and peers */
1930b28b702SAnirudh Venkataramanan 	__ICE_GLOBR_REQ,		/* set by driver and peers */
1940b28b702SAnirudh Venkataramanan 	__ICE_CORER_RECV,		/* set by OICR handler */
1950b28b702SAnirudh Venkataramanan 	__ICE_GLOBR_RECV,		/* set by OICR handler */
1960b28b702SAnirudh Venkataramanan 	__ICE_EMPR_RECV,		/* set by OICR handler */
1970b28b702SAnirudh Venkataramanan 	__ICE_SUSPENDED,		/* set on module remove path */
1980b28b702SAnirudh Venkataramanan 	__ICE_RESET_FAILED,		/* set by reset/rebuild */
199ddf30f7fSAnirudh Venkataramanan 	/* When checking for the PF to be in a nominal operating state, the
200ddf30f7fSAnirudh Venkataramanan 	 * bits that are grouped at the beginning of the list need to be
201ddf30f7fSAnirudh Venkataramanan 	 * checked. Bits occurring before __ICE_STATE_NOMINAL_CHECK_BITS will
202ddf30f7fSAnirudh Venkataramanan 	 * be checked. If you need to add a bit into consideration for nominal
203ddf30f7fSAnirudh Venkataramanan 	 * operating state, it must be added before
204ddf30f7fSAnirudh Venkataramanan 	 * __ICE_STATE_NOMINAL_CHECK_BITS. Do not move this entry's position
205ddf30f7fSAnirudh Venkataramanan 	 * without appropriate consideration.
206ddf30f7fSAnirudh Venkataramanan 	 */
207ddf30f7fSAnirudh Venkataramanan 	__ICE_STATE_NOMINAL_CHECK_BITS,
208940b61afSAnirudh Venkataramanan 	__ICE_ADMINQ_EVENT_PENDING,
20975d2b253SAnirudh Venkataramanan 	__ICE_MAILBOXQ_EVENT_PENDING,
210b3969fd7SSudheer Mogilappagari 	__ICE_MDD_EVENT_PENDING,
211007676b4SAnirudh Venkataramanan 	__ICE_VFLR_EVENT_PENDING,
212e94d4478SAnirudh Venkataramanan 	__ICE_FLTR_OVERFLOW_PROMISC,
213ddf30f7fSAnirudh Venkataramanan 	__ICE_VF_DIS,
214fcea6f3dSAnirudh Venkataramanan 	__ICE_CFG_BUSY,
215940b61afSAnirudh Venkataramanan 	__ICE_SERVICE_SCHED,
2168d81fa55SAkeem G Abodunrin 	__ICE_SERVICE_DIS,
217d82dd83dSAkeem G Abodunrin 	__ICE_OICR_INTR_DIS,		/* Global OICR interrupt disabled */
2189d5c5a52SPaul Greenwalt 	__ICE_MDD_VF_PRINT_PENDING,	/* set when MDD event handle */
219f844d521SBrett Creeley 	__ICE_VF_RESETS_DISABLED,	/* disable resets during ice_remove */
220837f08fdSAnirudh Venkataramanan 	__ICE_STATE_NBITS		/* must be last */
221837f08fdSAnirudh Venkataramanan };
222837f08fdSAnirudh Venkataramanan 
223e94d4478SAnirudh Venkataramanan enum ice_vsi_flags {
224e94d4478SAnirudh Venkataramanan 	ICE_VSI_FLAG_UMAC_FLTR_CHANGED,
225e94d4478SAnirudh Venkataramanan 	ICE_VSI_FLAG_MMAC_FLTR_CHANGED,
226e94d4478SAnirudh Venkataramanan 	ICE_VSI_FLAG_VLAN_FLTR_CHANGED,
227e94d4478SAnirudh Venkataramanan 	ICE_VSI_FLAG_PROMISC_CHANGED,
228e94d4478SAnirudh Venkataramanan 	ICE_VSI_FLAG_NBITS		/* must be last */
229e94d4478SAnirudh Venkataramanan };
230e94d4478SAnirudh Venkataramanan 
231940b61afSAnirudh Venkataramanan /* struct that defines a VSI, associated with a dev */
232940b61afSAnirudh Venkataramanan struct ice_vsi {
233940b61afSAnirudh Venkataramanan 	struct net_device *netdev;
2343a858ba3SAnirudh Venkataramanan 	struct ice_sw *vsw;		 /* switch this VSI is on */
2353a858ba3SAnirudh Venkataramanan 	struct ice_pf *back;		 /* back pointer to PF */
236940b61afSAnirudh Venkataramanan 	struct ice_port_info *port_info; /* back pointer to port_info */
237d337f2afSAnirudh Venkataramanan 	struct ice_ring **rx_rings;	 /* Rx ring array */
238d337f2afSAnirudh Venkataramanan 	struct ice_ring **tx_rings;	 /* Tx ring array */
2393a858ba3SAnirudh Venkataramanan 	struct ice_q_vector **q_vectors; /* q_vector array */
240cdedef59SAnirudh Venkataramanan 
241cdedef59SAnirudh Venkataramanan 	irqreturn_t (*irq_handler)(int irq, void *data);
242cdedef59SAnirudh Venkataramanan 
243fcea6f3dSAnirudh Venkataramanan 	u64 tx_linearize;
2443a858ba3SAnirudh Venkataramanan 	DECLARE_BITMAP(state, __ICE_STATE_NBITS);
245e94d4478SAnirudh Venkataramanan 	DECLARE_BITMAP(flags, ICE_VSI_FLAG_NBITS);
246e94d4478SAnirudh Venkataramanan 	unsigned int current_netdev_flags;
247fcea6f3dSAnirudh Venkataramanan 	u32 tx_restart;
248fcea6f3dSAnirudh Venkataramanan 	u32 tx_busy;
249fcea6f3dSAnirudh Venkataramanan 	u32 rx_buf_failed;
250fcea6f3dSAnirudh Venkataramanan 	u32 rx_page_failed;
2513a858ba3SAnirudh Venkataramanan 	int num_q_vectors;
252cbe66bfeSBrett Creeley 	int base_vector;		/* IRQ base for OS reserved vectors */
2533a858ba3SAnirudh Venkataramanan 	enum ice_vsi_type type;
254940b61afSAnirudh Venkataramanan 	u16 vsi_num;			/* HW (absolute) index of this VSI */
2553a858ba3SAnirudh Venkataramanan 	u16 idx;			/* software index in pf->vsi[] */
2563a858ba3SAnirudh Venkataramanan 
2578ede0178SAnirudh Venkataramanan 	s16 vf_id;			/* VF ID for SR-IOV VSIs */
2588ede0178SAnirudh Venkataramanan 
259d95276ceSAkeem G Abodunrin 	u16 ethtype;			/* Ethernet protocol for pause frame */
260d95276ceSAkeem G Abodunrin 
261d76a60baSAnirudh Venkataramanan 	/* RSS config */
262d76a60baSAnirudh Venkataramanan 	u16 rss_table_size;	/* HW RSS table size */
263d76a60baSAnirudh Venkataramanan 	u16 rss_size;		/* Allocated RSS queues */
264d76a60baSAnirudh Venkataramanan 	u8 *rss_hkey_user;	/* User configured hash keys */
265d76a60baSAnirudh Venkataramanan 	u8 *rss_lut_user;	/* User configured lookup table entries */
266d76a60baSAnirudh Venkataramanan 	u8 rss_lut_type;	/* used to configure Get/Set RSS LUT AQ call */
267d76a60baSAnirudh Venkataramanan 
268cdedef59SAnirudh Venkataramanan 	u16 max_frame;
269cdedef59SAnirudh Venkataramanan 	u16 rx_buf_len;
270cdedef59SAnirudh Venkataramanan 
2713a858ba3SAnirudh Venkataramanan 	struct ice_aqc_vsi_props info;	 /* VSI properties */
2723a858ba3SAnirudh Venkataramanan 
273fcea6f3dSAnirudh Venkataramanan 	/* VSI stats */
274fcea6f3dSAnirudh Venkataramanan 	struct rtnl_link_stats64 net_stats;
275fcea6f3dSAnirudh Venkataramanan 	struct ice_eth_stats eth_stats;
276fcea6f3dSAnirudh Venkataramanan 	struct ice_eth_stats eth_stats_prev;
277fcea6f3dSAnirudh Venkataramanan 
278e94d4478SAnirudh Venkataramanan 	struct list_head tmp_sync_list;		/* MAC filters to be synced */
279e94d4478SAnirudh Venkataramanan 	struct list_head tmp_unsync_list;	/* MAC filters to be unsynced */
280e94d4478SAnirudh Venkataramanan 
2810ab54c5fSJesse Brandeburg 	u8 irqs_ready:1;
2820ab54c5fSJesse Brandeburg 	u8 current_isup:1;		 /* Sync 'link up' logging */
2830ab54c5fSJesse Brandeburg 	u8 stat_offsets_loaded:1;
2840ab54c5fSJesse Brandeburg 	u8 vlan_ena:1;
285cd6d6b83SBrett Creeley 	u16 num_vlan;
286cdedef59SAnirudh Venkataramanan 
2873a858ba3SAnirudh Venkataramanan 	/* queue information */
2883a858ba3SAnirudh Venkataramanan 	u8 tx_mapping_mode;		 /* ICE_MAP_MODE_[CONTIG|SCATTER] */
2893a858ba3SAnirudh Venkataramanan 	u8 rx_mapping_mode;		 /* ICE_MAP_MODE_[CONTIG|SCATTER] */
29078b5713aSAnirudh Venkataramanan 	u16 *txq_map;			 /* index in pf->avail_txqs */
29178b5713aSAnirudh Venkataramanan 	u16 *rxq_map;			 /* index in pf->avail_rxqs */
2923a858ba3SAnirudh Venkataramanan 	u16 alloc_txq;			 /* Allocated Tx queues */
2933a858ba3SAnirudh Venkataramanan 	u16 num_txq;			 /* Used Tx queues */
2943a858ba3SAnirudh Venkataramanan 	u16 alloc_rxq;			 /* Allocated Rx queues */
2953a858ba3SAnirudh Venkataramanan 	u16 num_rxq;			 /* Used Rx queues */
29687324e74SHenry Tieman 	u16 req_txq;			 /* User requested Tx queues */
29787324e74SHenry Tieman 	u16 req_rxq;			 /* User requested Rx queues */
298ad71b256SBrett Creeley 	u16 num_rx_desc;
299ad71b256SBrett Creeley 	u16 num_tx_desc;
3003a858ba3SAnirudh Venkataramanan 	struct ice_tc_cfg tc_cfg;
301efc2214bSMaciej Fijalkowski 	struct bpf_prog *xdp_prog;
302efc2214bSMaciej Fijalkowski 	struct ice_ring **xdp_rings;	 /* XDP ring array */
303efc2214bSMaciej Fijalkowski 	u16 num_xdp_txq;		 /* Used XDP queues */
304efc2214bSMaciej Fijalkowski 	u8 xdp_mapping_mode;		 /* ICE_MAP_MODE_[CONTIG|SCATTER] */
3052d4238f5SKrzysztof Kazimierczak 	struct xdp_umem **xsk_umems;
3062d4238f5SKrzysztof Kazimierczak 	u16 num_xsk_umems_used;
3072d4238f5SKrzysztof Kazimierczak 	u16 num_xsk_umems;
3083a858ba3SAnirudh Venkataramanan } ____cacheline_internodealigned_in_smp;
3093a858ba3SAnirudh Venkataramanan 
3103a858ba3SAnirudh Venkataramanan /* struct that defines an interrupt vector */
3113a858ba3SAnirudh Venkataramanan struct ice_q_vector {
3123a858ba3SAnirudh Venkataramanan 	struct ice_vsi *vsi;
3138244dd2dSBrett Creeley 
3143a858ba3SAnirudh Venkataramanan 	u16 v_idx;			/* index in the vsi->q_vector array. */
315b07833a0SBrett Creeley 	u16 reg_idx;
316d337f2afSAnirudh Venkataramanan 	u8 num_ring_rx;			/* total number of Rx rings in vector */
3178244dd2dSBrett Creeley 	u8 num_ring_tx;			/* total number of Tx rings in vector */
3188244dd2dSBrett Creeley 	u8 itr_countdown;		/* when 0 should adjust adaptive ITR */
3199e4ab4c2SBrett Creeley 	/* in usecs, need to use ice_intrl_to_usecs_reg() before writing this
3209e4ab4c2SBrett Creeley 	 * value to the device
3219e4ab4c2SBrett Creeley 	 */
3229e4ab4c2SBrett Creeley 	u8 intrl;
3238244dd2dSBrett Creeley 
3248244dd2dSBrett Creeley 	struct napi_struct napi;
3258244dd2dSBrett Creeley 
3268244dd2dSBrett Creeley 	struct ice_ring_container rx;
3278244dd2dSBrett Creeley 	struct ice_ring_container tx;
3288244dd2dSBrett Creeley 
3298244dd2dSBrett Creeley 	cpumask_t affinity_mask;
3308244dd2dSBrett Creeley 	struct irq_affinity_notify affinity_notify;
3318244dd2dSBrett Creeley 
3328244dd2dSBrett Creeley 	char name[ICE_INT_NAME_STR_LEN];
333940b61afSAnirudh Venkataramanan } ____cacheline_internodealigned_in_smp;
334940b61afSAnirudh Venkataramanan 
335940b61afSAnirudh Venkataramanan enum ice_pf_flags {
336940b61afSAnirudh Venkataramanan 	ICE_FLAG_FLTR_SYNC,
337940b61afSAnirudh Venkataramanan 	ICE_FLAG_RSS_ENA,
338ddf30f7fSAnirudh Venkataramanan 	ICE_FLAG_SRIOV_ENA,
33975d2b253SAnirudh Venkataramanan 	ICE_FLAG_SRIOV_CAPABLE,
34037b6f646SAnirudh Venkataramanan 	ICE_FLAG_DCB_CAPABLE,
34137b6f646SAnirudh Venkataramanan 	ICE_FLAG_DCB_ENA,
342462acf6aSTony Nguyen 	ICE_FLAG_ADV_FEATURES,
343ab4ab73fSBruce Allan 	ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA,
3446d599946STony Nguyen 	ICE_FLAG_NO_MEDIA,
34584a118abSDave Ertman 	ICE_FLAG_FW_LLDP_AGENT,
3463a257a14SAnirudh Venkataramanan 	ICE_FLAG_ETHTOOL_CTXT,		/* set when ethtool holds RTNL lock */
3477237f5b0SMaciej Fijalkowski 	ICE_FLAG_LEGACY_RX,
34801b5e89aSBrett Creeley 	ICE_FLAG_VF_TRUE_PROMISC_ENA,
3499d5c5a52SPaul Greenwalt 	ICE_FLAG_MDD_AUTO_RESET_VF,
350940b61afSAnirudh Venkataramanan 	ICE_PF_FLAGS_NBITS		/* must be last */
351940b61afSAnirudh Venkataramanan };
352940b61afSAnirudh Venkataramanan 
353837f08fdSAnirudh Venkataramanan struct ice_pf {
354837f08fdSAnirudh Venkataramanan 	struct pci_dev *pdev;
355eb0208ecSPreethi Banala 
3561adf7eadSJacob Keller 	/* devlink port data */
3571adf7eadSJacob Keller 	struct devlink_port devlink_port;
3581adf7eadSJacob Keller 
359dce730f1SJacob Keller 	struct devlink_region *nvm_region;
360dce730f1SJacob Keller 
361eb0208ecSPreethi Banala 	/* OS reserved IRQ details */
362940b61afSAnirudh Venkataramanan 	struct msix_entry *msix_entries;
363cbe66bfeSBrett Creeley 	struct ice_res_tracker *irq_tracker;
364cbe66bfeSBrett Creeley 	/* First MSIX vector used by SR-IOV VFs. Calculated by subtracting the
365cbe66bfeSBrett Creeley 	 * number of MSIX vectors needed for all SR-IOV VFs from the number of
366cbe66bfeSBrett Creeley 	 * MSIX vectors allowed on this PF.
367cbe66bfeSBrett Creeley 	 */
368cbe66bfeSBrett Creeley 	u16 sriov_base_vector;
369eb0208ecSPreethi Banala 
370940b61afSAnirudh Venkataramanan 	struct ice_vsi **vsi;		/* VSIs created by the driver */
371940b61afSAnirudh Venkataramanan 	struct ice_sw *first_sw;	/* first switch created by firmware */
372ddf30f7fSAnirudh Venkataramanan 	/* Virtchnl/SR-IOV config info */
373ddf30f7fSAnirudh Venkataramanan 	struct ice_vf *vf;
374ddf30f7fSAnirudh Venkataramanan 	int num_alloc_vfs;		/* actual number of VFs allocated */
37575d2b253SAnirudh Venkataramanan 	u16 num_vfs_supported;		/* num VFs supported for this PF */
37646c276ceSBrett Creeley 	u16 num_qps_per_vf;
37746c276ceSBrett Creeley 	u16 num_msix_per_vf;
3789d5c5a52SPaul Greenwalt 	/* used to ratelimit the MDD event logging */
3799d5c5a52SPaul Greenwalt 	unsigned long last_printed_mdd_jiffies;
380837f08fdSAnirudh Venkataramanan 	DECLARE_BITMAP(state, __ICE_STATE_NBITS);
381940b61afSAnirudh Venkataramanan 	DECLARE_BITMAP(flags, ICE_PF_FLAGS_NBITS);
38278b5713aSAnirudh Venkataramanan 	unsigned long *avail_txqs;	/* bitmap to track PF Tx queue usage */
38378b5713aSAnirudh Venkataramanan 	unsigned long *avail_rxqs;	/* bitmap to track PF Rx queue usage */
384940b61afSAnirudh Venkataramanan 	unsigned long serv_tmr_period;
385940b61afSAnirudh Venkataramanan 	unsigned long serv_tmr_prev;
386940b61afSAnirudh Venkataramanan 	struct timer_list serv_tmr;
387940b61afSAnirudh Venkataramanan 	struct work_struct serv_task;
388940b61afSAnirudh Venkataramanan 	struct mutex avail_q_mutex;	/* protects access to avail_[rx|tx]qs */
389940b61afSAnirudh Venkataramanan 	struct mutex sw_mutex;		/* lock for protecting VSI alloc flow */
390b94b013eSDave Ertman 	struct mutex tc_mutex;		/* lock to protect TC changes */
391837f08fdSAnirudh Venkataramanan 	u32 msg_enable;
392d76a60baSAnirudh Venkataramanan 	u32 hw_csum_rx_error;
393cbe66bfeSBrett Creeley 	u32 oicr_idx;		/* Other interrupt cause MSIX vector index */
394eb0208ecSPreethi Banala 	u32 num_avail_sw_msix;	/* remaining MSIX SW vectors left unclaimed */
39578b5713aSAnirudh Venkataramanan 	u16 max_pf_txqs;	/* Total Tx queues PF wide */
39678b5713aSAnirudh Venkataramanan 	u16 max_pf_rxqs;	/* Total Rx queues PF wide */
397940b61afSAnirudh Venkataramanan 	u32 num_lan_msix;	/* Total MSIX vectors for base driver */
398f9867df6SAnirudh Venkataramanan 	u16 num_lan_tx;		/* num LAN Tx queues setup */
399f9867df6SAnirudh Venkataramanan 	u16 num_lan_rx;		/* num LAN Rx queues setup */
400940b61afSAnirudh Venkataramanan 	u16 next_vsi;		/* Next free slot in pf->vsi[] - 0-based! */
401940b61afSAnirudh Venkataramanan 	u16 num_alloc_vsi;
4020b28b702SAnirudh Venkataramanan 	u16 corer_count;	/* Core reset count */
4030b28b702SAnirudh Venkataramanan 	u16 globr_count;	/* Global reset count */
4040b28b702SAnirudh Venkataramanan 	u16 empr_count;		/* EMP reset count */
4050b28b702SAnirudh Venkataramanan 	u16 pfr_count;		/* PF reset count */
4060b28b702SAnirudh Venkataramanan 
407fcea6f3dSAnirudh Venkataramanan 	struct ice_hw_port_stats stats;
408fcea6f3dSAnirudh Venkataramanan 	struct ice_hw_port_stats stats_prev;
409837f08fdSAnirudh Venkataramanan 	struct ice_hw hw;
4100ab54c5fSJesse Brandeburg 	u8 stat_prev_loaded:1; /* has previous stats been loaded */
4117b9ffc76SAnirudh Venkataramanan #ifdef CONFIG_DCB
4127b9ffc76SAnirudh Venkataramanan 	u16 dcbx_cap;
4137b9ffc76SAnirudh Venkataramanan #endif /* CONFIG_DCB */
414b3969fd7SSudheer Mogilappagari 	u32 tx_timeout_count;
415b3969fd7SSudheer Mogilappagari 	unsigned long tx_timeout_last_recovery;
416b3969fd7SSudheer Mogilappagari 	u32 tx_timeout_recovery_level;
417940b61afSAnirudh Venkataramanan 	char int_name[ICE_INT_NAME_STR_LEN];
4180e674aebSAnirudh Venkataramanan 	u32 sw_int_count;
419837f08fdSAnirudh Venkataramanan };
420940b61afSAnirudh Venkataramanan 
4213a858ba3SAnirudh Venkataramanan struct ice_netdev_priv {
4223a858ba3SAnirudh Venkataramanan 	struct ice_vsi *vsi;
4233a858ba3SAnirudh Venkataramanan };
4243a858ba3SAnirudh Venkataramanan 
425940b61afSAnirudh Venkataramanan /**
426940b61afSAnirudh Venkataramanan  * ice_irq_dynamic_ena - Enable default interrupt generation settings
427f9867df6SAnirudh Venkataramanan  * @hw: pointer to HW struct
428f9867df6SAnirudh Venkataramanan  * @vsi: pointer to VSI struct, can be NULL
429cdedef59SAnirudh Venkataramanan  * @q_vector: pointer to q_vector, can be NULL
430940b61afSAnirudh Venkataramanan  */
431c8b7abddSBruce Allan static inline void
432c8b7abddSBruce Allan ice_irq_dynamic_ena(struct ice_hw *hw, struct ice_vsi *vsi,
433cdedef59SAnirudh Venkataramanan 		    struct ice_q_vector *q_vector)
434940b61afSAnirudh Venkataramanan {
435b07833a0SBrett Creeley 	u32 vector = (vsi && q_vector) ? q_vector->reg_idx :
436cbe66bfeSBrett Creeley 				((struct ice_pf *)hw->back)->oicr_idx;
437940b61afSAnirudh Venkataramanan 	int itr = ICE_ITR_NONE;
438940b61afSAnirudh Venkataramanan 	u32 val;
439940b61afSAnirudh Venkataramanan 
440940b61afSAnirudh Venkataramanan 	/* clear the PBA here, as this function is meant to clean out all
441940b61afSAnirudh Venkataramanan 	 * previous interrupts and enable the interrupt
442940b61afSAnirudh Venkataramanan 	 */
443940b61afSAnirudh Venkataramanan 	val = GLINT_DYN_CTL_INTENA_M | GLINT_DYN_CTL_CLEARPBA_M |
444940b61afSAnirudh Venkataramanan 	      (itr << GLINT_DYN_CTL_ITR_INDX_S);
445cdedef59SAnirudh Venkataramanan 	if (vsi)
446cdedef59SAnirudh Venkataramanan 		if (test_bit(__ICE_DOWN, vsi->state))
447cdedef59SAnirudh Venkataramanan 			return;
448940b61afSAnirudh Venkataramanan 	wr32(hw, GLINT_DYN_CTL(vector), val);
449940b61afSAnirudh Venkataramanan }
450cdedef59SAnirudh Venkataramanan 
451c2a23e00SBrett Creeley /**
452462acf6aSTony Nguyen  * ice_netdev_to_pf - Retrieve the PF struct associated with a netdev
453462acf6aSTony Nguyen  * @netdev: pointer to the netdev struct
454462acf6aSTony Nguyen  */
455462acf6aSTony Nguyen static inline struct ice_pf *ice_netdev_to_pf(struct net_device *netdev)
456462acf6aSTony Nguyen {
457462acf6aSTony Nguyen 	struct ice_netdev_priv *np = netdev_priv(netdev);
458462acf6aSTony Nguyen 
459462acf6aSTony Nguyen 	return np->vsi->back;
460462acf6aSTony Nguyen }
461462acf6aSTony Nguyen 
462efc2214bSMaciej Fijalkowski static inline bool ice_is_xdp_ena_vsi(struct ice_vsi *vsi)
463efc2214bSMaciej Fijalkowski {
464efc2214bSMaciej Fijalkowski 	return !!vsi->xdp_prog;
465efc2214bSMaciej Fijalkowski }
466efc2214bSMaciej Fijalkowski 
467efc2214bSMaciej Fijalkowski static inline void ice_set_ring_xdp(struct ice_ring *ring)
468efc2214bSMaciej Fijalkowski {
469efc2214bSMaciej Fijalkowski 	ring->flags |= ICE_TX_FLAGS_RING_XDP;
470efc2214bSMaciej Fijalkowski }
471efc2214bSMaciej Fijalkowski 
472462acf6aSTony Nguyen /**
4732d4238f5SKrzysztof Kazimierczak  * ice_xsk_umem - get XDP UMEM bound to a ring
4742d4238f5SKrzysztof Kazimierczak  * @ring - ring to use
4752d4238f5SKrzysztof Kazimierczak  *
4762d4238f5SKrzysztof Kazimierczak  * Returns a pointer to xdp_umem structure if there is an UMEM present,
4772d4238f5SKrzysztof Kazimierczak  * NULL otherwise.
4782d4238f5SKrzysztof Kazimierczak  */
4792d4238f5SKrzysztof Kazimierczak static inline struct xdp_umem *ice_xsk_umem(struct ice_ring *ring)
4802d4238f5SKrzysztof Kazimierczak {
4812d4238f5SKrzysztof Kazimierczak 	struct xdp_umem **umems = ring->vsi->xsk_umems;
48265bb559bSKrzysztof Kazimierczak 	u16 qid = ring->q_index;
4832d4238f5SKrzysztof Kazimierczak 
4842d4238f5SKrzysztof Kazimierczak 	if (ice_ring_is_xdp(ring))
4852d4238f5SKrzysztof Kazimierczak 		qid -= ring->vsi->num_xdp_txq;
4862d4238f5SKrzysztof Kazimierczak 
48765bb559bSKrzysztof Kazimierczak 	if (qid >= ring->vsi->num_xsk_umems || !umems || !umems[qid] ||
48865bb559bSKrzysztof Kazimierczak 	    !ice_is_xdp_ena_vsi(ring->vsi))
4892d4238f5SKrzysztof Kazimierczak 		return NULL;
4902d4238f5SKrzysztof Kazimierczak 
4912d4238f5SKrzysztof Kazimierczak 	return umems[qid];
4922d4238f5SKrzysztof Kazimierczak }
4932d4238f5SKrzysztof Kazimierczak 
4942d4238f5SKrzysztof Kazimierczak /**
495208ff751SAnirudh Venkataramanan  * ice_get_main_vsi - Get the PF VSI
496208ff751SAnirudh Venkataramanan  * @pf: PF instance
497208ff751SAnirudh Venkataramanan  *
498208ff751SAnirudh Venkataramanan  * returns pf->vsi[0], which by definition is the PF VSI
499c2a23e00SBrett Creeley  */
500208ff751SAnirudh Venkataramanan static inline struct ice_vsi *ice_get_main_vsi(struct ice_pf *pf)
501c2a23e00SBrett Creeley {
502208ff751SAnirudh Venkataramanan 	if (pf->vsi)
503208ff751SAnirudh Venkataramanan 		return pf->vsi[0];
504c2a23e00SBrett Creeley 
505c2a23e00SBrett Creeley 	return NULL;
506c2a23e00SBrett Creeley }
507c2a23e00SBrett Creeley 
5080e674aebSAnirudh Venkataramanan int ice_vsi_setup_tx_rings(struct ice_vsi *vsi);
5090e674aebSAnirudh Venkataramanan int ice_vsi_setup_rx_rings(struct ice_vsi *vsi);
510fcea6f3dSAnirudh Venkataramanan void ice_set_ethtool_ops(struct net_device *netdev);
511462acf6aSTony Nguyen void ice_set_ethtool_safe_mode_ops(struct net_device *netdev);
5128c243700SAnirudh Venkataramanan u16 ice_get_avail_txq_count(struct ice_pf *pf);
5138c243700SAnirudh Venkataramanan u16 ice_get_avail_rxq_count(struct ice_pf *pf);
51487324e74SHenry Tieman int ice_vsi_recfg_qs(struct ice_vsi *vsi, int new_rx, int new_tx);
5155a4a8673SBruce Allan void ice_update_vsi_stats(struct ice_vsi *vsi);
5165a4a8673SBruce Allan void ice_update_pf_stats(struct ice_pf *pf);
517fcea6f3dSAnirudh Venkataramanan int ice_up(struct ice_vsi *vsi);
518fcea6f3dSAnirudh Venkataramanan int ice_down(struct ice_vsi *vsi);
5190e674aebSAnirudh Venkataramanan int ice_vsi_cfg(struct ice_vsi *vsi);
5200e674aebSAnirudh Venkataramanan struct ice_vsi *ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi);
521efc2214bSMaciej Fijalkowski int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog);
522efc2214bSMaciej Fijalkowski int ice_destroy_xdp_rings(struct ice_vsi *vsi);
523efc2214bSMaciej Fijalkowski int
524efc2214bSMaciej Fijalkowski ice_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames,
525efc2214bSMaciej Fijalkowski 	     u32 flags);
526d76a60baSAnirudh Venkataramanan int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
527d76a60baSAnirudh Venkataramanan int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
528d76a60baSAnirudh Venkataramanan void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size);
52987324e74SHenry Tieman int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset);
530fcea6f3dSAnirudh Venkataramanan void ice_print_link_msg(struct ice_vsi *vsi, bool isup);
531*0fee3577SLihong Yang const char *ice_stat_str(enum ice_status stat_err);
532*0fee3577SLihong Yang const char *ice_aq_str(enum ice_aq_err aq_err);
5330e674aebSAnirudh Venkataramanan int ice_open(struct net_device *netdev);
5340e674aebSAnirudh Venkataramanan int ice_stop(struct net_device *netdev);
535d76a60baSAnirudh Venkataramanan 
536837f08fdSAnirudh Venkataramanan #endif /* _ICE_H_ */
537