xref: /linux/drivers/net/ethernet/intel/idpf/idpf.h (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (C) 2023 Intel Corporation */
3 
4 #ifndef _IDPF_H_
5 #define _IDPF_H_
6 
7 /* Forward declaration */
8 struct idpf_adapter;
9 struct idpf_vport;
10 struct idpf_vport_max_q;
11 struct idpf_q_vec_rsrc;
12 struct idpf_rss_data;
13 
14 #include <net/pkt_sched.h>
15 #include <linux/aer.h>
16 #include <linux/etherdevice.h>
17 #include <linux/ioport.h>
18 #include <linux/pci.h>
19 #include <linux/bitfield.h>
20 #include <linux/sctp.h>
21 #include <linux/ethtool_netlink.h>
22 #include <net/gro.h>
23 
24 #include <linux/net/intel/iidc_rdma.h>
25 #include <linux/net/intel/iidc_rdma_idpf.h>
26 #include <linux/net/intel/libie/controlq.h>
27 #include <linux/net/intel/virtchnl2.h>
28 
29 #include "idpf_txrx.h"
30 
31 #define GETMAXVAL(num_bits)		GENMASK((num_bits) - 1, 0)
32 
33 #define IDPF_NO_FREE_SLOT		0xffff
34 
35 /* Default Mailbox settings */
36 #define IDPF_NUM_FILTERS_PER_MSG	20
37 #define IDPF_NUM_DFLT_MBX_Q		2	/* includes both TX and RX */
38 #define IDPF_DFLT_MBX_Q_LEN		64
39 /* maximum number of times to try before resetting mailbox */
40 #define IDPF_MB_MAX_ERR			20
41 #define IDPF_NUM_CHUNKS_PER_MSG(struct_sz, chunk_sz)	\
42 	((LIBIE_CTLQ_MAX_BUF_LEN - (struct_sz)) / (chunk_sz))
43 
44 #define IDPF_WAIT_FOR_MARKER_TIMEO	500
45 #define IDPF_MAX_WAIT			500
46 
47 /* available message levels */
48 #define IDPF_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
49 
50 #define IDPF_DIM_PROFILE_SLOTS  5
51 
52 #define IDPF_VIRTCHNL_VERSION_MAJOR VIRTCHNL2_VERSION_MAJOR_2
53 #define IDPF_VIRTCHNL_VERSION_MINOR VIRTCHNL2_VERSION_MINOR_0
54 
55 /**
56  * struct idpf_mac_filter
57  * @list: list member field
58  * @macaddr: MAC address
59  * @remove: filter should be removed (virtchnl)
60  * @add: filter should be added (virtchnl)
61  */
62 struct idpf_mac_filter {
63 	struct list_head list;
64 	u8 macaddr[ETH_ALEN];
65 	bool remove;
66 	bool add;
67 };
68 
69 /**
70  * enum idpf_state - State machine to handle bring up
71  * @__IDPF_VER_CHECK: Negotiate virtchnl version
72  * @__IDPF_GET_CAPS: Negotiate capabilities
73  * @__IDPF_INIT_SW: Init based on given capabilities
74  * @__IDPF_STATE_LAST: Must be last, used to determine size
75  */
76 enum idpf_state {
77 	__IDPF_VER_CHECK,
78 	__IDPF_GET_CAPS,
79 	__IDPF_INIT_SW,
80 	__IDPF_STATE_LAST,
81 };
82 
83 /**
84  * enum idpf_flags - Hard reset causes.
85  * @IDPF_HR_FUNC_RESET: Hard reset when TxRx timeout
86  * @IDPF_HR_DRV_LOAD: Set on driver load for a clean HW
87  * @IDPF_HR_RESET_IN_PROG: Reset in progress
88  * @IDPF_REMOVE_IN_PROG: Driver remove in progress
89  * @IDPF_MB_INTR_MODE: Mailbox in interrupt mode
90  * @IDPF_VC_CORE_INIT: virtchnl core has been init
91  * @IDPF_FLAGS_NBITS: Must be last
92  */
93 enum idpf_flags {
94 	IDPF_HR_FUNC_RESET,
95 	IDPF_HR_DRV_LOAD,
96 	IDPF_HR_RESET_IN_PROG,
97 	IDPF_REMOVE_IN_PROG,
98 	IDPF_MB_INTR_MODE,
99 	IDPF_VC_CORE_INIT,
100 	IDPF_FLAGS_NBITS,
101 };
102 
103 /**
104  * enum idpf_cap_field - Offsets into capabilities struct for specific caps
105  * @IDPF_BASE_CAPS: generic base capabilities
106  * @IDPF_CSUM_CAPS: checksum offload capabilities
107  * @IDPF_SEG_CAPS: segmentation offload capabilities
108  * @IDPF_RSS_CAPS: RSS offload capabilities
109  * @IDPF_HSPLIT_CAPS: Header split capabilities
110  * @IDPF_RSC_CAPS: RSC offload capabilities
111  * @IDPF_OTHER_CAPS: miscellaneous offloads
112  *
113  * Used when checking for a specific capability flag since different capability
114  * sets are not mutually exclusive numerically, the caller must specify which
115  * type of capability they are checking for.
116  */
117 enum idpf_cap_field {
118 	IDPF_BASE_CAPS		= -1,
119 	IDPF_CSUM_CAPS		= offsetof(struct virtchnl2_get_capabilities,
120 					   csum_caps),
121 	IDPF_SEG_CAPS		= offsetof(struct virtchnl2_get_capabilities,
122 					   seg_caps),
123 	IDPF_RSS_CAPS		= offsetof(struct virtchnl2_get_capabilities,
124 					   rss_caps),
125 	IDPF_HSPLIT_CAPS	= offsetof(struct virtchnl2_get_capabilities,
126 					   hsplit_caps),
127 	IDPF_RSC_CAPS		= offsetof(struct virtchnl2_get_capabilities,
128 					   rsc_caps),
129 	IDPF_OTHER_CAPS		= offsetof(struct virtchnl2_get_capabilities,
130 					   other_caps),
131 };
132 
133 /**
134  * enum idpf_vport_state - Current vport state
135  * @IDPF_VPORT_UP: Vport is up
136  * @IDPF_VPORT_STATE_NBITS: Must be last, number of states
137  */
138 enum idpf_vport_state {
139 	IDPF_VPORT_UP,
140 	IDPF_VPORT_STATE_NBITS
141 };
142 
143 /**
144  * struct idpf_netdev_priv - Struct to store vport back pointer
145  * @adapter: Adapter back pointer
146  * @vport: Vport back pointer
147  * @vport_id: Vport identifier
148  * @link_speed_mbps: Link speed in mbps
149  * @vport_idx: Relative vport index
150  * @max_tx_hdr_size: Max header length hardware can support
151  * @tx_max_bufs: Max buffers that can be transmitted with scatter-gather
152  * @state: See enum idpf_vport_state
153  * @netstats: Packet and byte stats
154  * @stats_lock: Lock to protect stats update
155  */
156 struct idpf_netdev_priv {
157 	struct idpf_adapter *adapter;
158 	struct idpf_vport *vport;
159 	u32 vport_id;
160 	u32 link_speed_mbps;
161 	u16 vport_idx;
162 	u16 max_tx_hdr_size;
163 	u16 tx_max_bufs;
164 	DECLARE_BITMAP(state, IDPF_VPORT_STATE_NBITS);
165 	struct rtnl_link_stats64 netstats;
166 	spinlock_t stats_lock;
167 };
168 
169 /**
170  * struct idpf_reset_reg - Reset register offsets/masks
171  * @rstat: Reset status register
172  * @rstat_m: Reset status mask
173  */
174 struct idpf_reset_reg {
175 	void __iomem *rstat;
176 	u32 rstat_m;
177 };
178 
179 /**
180  * struct idpf_vport_max_q - Queue limits
181  * @max_rxq: Maximum number of RX queues supported
182  * @max_txq: Maixmum number of TX queues supported
183  * @max_bufq: In splitq, maximum number of buffer queues supported
184  * @max_complq: In splitq, maximum number of completion queues supported
185  */
186 struct idpf_vport_max_q {
187 	u16 max_rxq;
188 	u16 max_txq;
189 	u16 max_bufq;
190 	u16 max_complq;
191 };
192 
193 /**
194  * struct idpf_reg_ops - Device specific register operation function pointers
195  * @ctlq_reg_init: Mailbox control queue register initialization
196  * @intr_reg_init: Traffic interrupt register initialization
197  * @mb_intr_reg_init: Mailbox interrupt register initialization
198  * @reset_reg_init: Reset register initialization
199  * @trigger_reset: Trigger a reset to occur
200  * @ptp_reg_init: PTP register initialization
201  */
202 struct idpf_reg_ops {
203 	void (*ctlq_reg_init)(struct libie_mmio_info *mmio,
204 			      struct libie_ctlq_create_info *cctlq_info);
205 	int (*intr_reg_init)(struct idpf_vport *vport,
206 			     struct idpf_q_vec_rsrc *rsrc);
207 	void (*mb_intr_reg_init)(struct idpf_adapter *adapter);
208 	void (*reset_reg_init)(struct idpf_adapter *adapter);
209 	void (*trigger_reset)(struct idpf_adapter *adapter,
210 			      enum idpf_flags trig_cause);
211 	void (*ptp_reg_init)(const struct idpf_adapter *adapter);
212 };
213 
214 #define IDPF_MMIO_REG_NUM_STATIC	2
215 #define IDPF_PF_MBX_REGION_SZ		4096
216 #define IDPF_PF_RSTAT_REGION_SZ		2048
217 #define IDPF_VF_MBX_REGION_SZ		10240
218 #define IDPF_VF_RSTAT_REGION_SZ		2048
219 
220 /**
221  * struct idpf_dev_ops - Device specific operations
222  * @reg_ops: Register operations
223  * @idc_init: IDC initialization
224  * @static_reg_info: array of mailbox and rstat register info
225  */
226 struct idpf_dev_ops {
227 	struct idpf_reg_ops reg_ops;
228 
229 	int (*idc_init)(struct idpf_adapter *adapter);
230 
231 	/* static_reg_info[0] is mailbox region, static_reg_info[1] is rstat */
232 	struct resource static_reg_info[IDPF_MMIO_REG_NUM_STATIC];
233 };
234 
235 /**
236  * enum idpf_vport_reset_cause - Vport soft reset causes
237  * @IDPF_SR_Q_CHANGE: Soft reset queue change
238  * @IDPF_SR_Q_DESC_CHANGE: Soft reset descriptor change
239  * @IDPF_SR_MTU_CHANGE: Soft reset MTU change
240  * @IDPF_SR_RSC_CHANGE: Soft reset RSC change
241  */
242 enum idpf_vport_reset_cause {
243 	IDPF_SR_Q_CHANGE,
244 	IDPF_SR_Q_DESC_CHANGE,
245 	IDPF_SR_MTU_CHANGE,
246 	IDPF_SR_RSC_CHANGE,
247 };
248 
249 /**
250  * enum idpf_vport_flags - Vport flags
251  * @IDPF_VPORT_DEL_QUEUES: To send delete queues message
252  * @IDPF_VPORT_FLAGS_NBITS: Must be last
253  */
254 enum idpf_vport_flags {
255 	IDPF_VPORT_DEL_QUEUES,
256 	IDPF_VPORT_FLAGS_NBITS,
257 };
258 
259 /**
260  * struct idpf_tstamp_stats - Tx timestamp statistics
261  * @stats_sync: See struct u64_stats_sync
262  * @packets: Number of packets successfully timestamped by the hardware
263  * @discarded: Number of Tx skbs discarded due to cached PHC
264  *	       being too old to correctly extend timestamp
265  * @flushed: Number of Tx skbs flushed due to interface closed
266  */
267 struct idpf_tstamp_stats {
268 	struct u64_stats_sync stats_sync;
269 	u64_stats_t packets;
270 	u64_stats_t discarded;
271 	u64_stats_t flushed;
272 };
273 
274 struct idpf_port_stats {
275 	struct u64_stats_sync stats_sync;
276 	u64_stats_t rx_hw_csum_err;
277 	u64_stats_t rx_hsplit;
278 	u64_stats_t rx_hsplit_hbo;
279 	u64_stats_t rx_bad_descs;
280 	u64_stats_t tx_linearize;
281 	u64_stats_t tx_busy;
282 	u64_stats_t tx_drops;
283 	u64_stats_t tx_dma_map_errs;
284 	struct virtchnl2_vport_stats vport_stats;
285 };
286 
287 struct idpf_fsteer_fltr {
288 	struct list_head list;
289 	struct ethtool_rx_flow_spec fs;
290 };
291 
292 /**
293  * struct idpf_q_vec_rsrc - handle for queue and vector resources
294  * @dev: device pointer for DMA mapping
295  * @q_vectors: array of queue vectors
296  * @q_vector_idxs: starting index of queue vectors
297  * @num_q_vectors: number of IRQ vectors allocated
298  * @noirq_v_idx: ID of the NOIRQ vector
299  * @noirq_dyn_ctl_ena: value to write to the above to enable it
300  * @noirq_dyn_ctl: register to enable/disable the vector for NOIRQ queues
301  * @txq_grps: array of TX queue groups
302  * @txq_desc_count: TX queue descriptor count
303  * @complq_desc_count: completion queue descriptor count
304  * @txq_model: split queue or single queue queuing model
305  * @num_txq: number of allocated TX queues
306  * @num_complq: number of allocated completion queues
307  * @num_txq_grp: number of TX queue groups
308  * @xdp_txq_offset: index of the first XDPSQ (== number of regular SQs)
309  * @num_rxq_grp: number of RX queues in a group
310  * @rxq_model: splitq queue or single queue queuing model
311  * @rxq_grps: total number of RX groups. Number of groups * number of RX per
312  *	      group will yield total number of RX queues.
313  * @num_rxq: number of allocated RX queues
314  * @num_bufq: number of allocated buffer queues
315  * @rxq_desc_count: RX queue descriptor count. *MUST* have enough descriptors
316  *		    to complete all buffer descriptors for all buffer queues in
317  *		    the worst case.
318  * @bufq_desc_count: buffer queue descriptor count
319  * @num_bufqs_per_qgrp: buffer queues per RX queue in a given grouping
320  * @base_rxd: true if the driver should use base descriptors instead of flex
321  */
322 struct idpf_q_vec_rsrc {
323 	struct device		*dev;
324 	struct idpf_q_vector	*q_vectors;
325 	u16			*q_vector_idxs;
326 	u16			num_q_vectors;
327 	u16			noirq_v_idx;
328 	u32			noirq_dyn_ctl_ena;
329 	void __iomem		*noirq_dyn_ctl;
330 
331 	struct idpf_txq_group	*txq_grps;
332 	u32			txq_desc_count;
333 	u32			complq_desc_count;
334 	u32			txq_model;
335 	u16			num_txq;
336 	u16			num_complq;
337 	u16			num_txq_grp;
338 	u16			xdp_txq_offset;
339 
340 	u16			num_rxq_grp;
341 	u32			rxq_model;
342 	struct idpf_rxq_group	*rxq_grps;
343 	u16			num_rxq;
344 	u16			num_bufq;
345 	u32			rxq_desc_count;
346 	u32			bufq_desc_count[IDPF_MAX_BUFQS_PER_RXQ_GRP];
347 	u8			num_bufqs_per_qgrp;
348 	bool			base_rxd;
349 };
350 
351 /**
352  * struct idpf_vport - Handle for netdevices and queue resources
353  * @dflt_qv_rsrc: contains default queue and vector resources
354  * @txqs: Used only in hotpath to get to the right queue very fast
355  * @num_txq: Number of allocated TX queues
356  * @num_xdp_txq: number of XDPSQs
357  * @xdpsq_share: whether XDPSQ sharing is enabled
358  * @xdp_prog: installed XDP program
359  * @vdev_info: IDC vport device info pointer
360  * @adapter: back pointer to associated adapter
361  * @netdev: Associated net_device. Each vport should have one and only one
362  *	    associated netdev.
363  * @flags: See enum idpf_vport_flags
364  * @compln_clean_budget: Work budget for completion clean
365  * @vport_id: Device given vport identifier
366  * @vport_type: Default SRIOV, SIOV, etc.
367  * @idx: Software index in adapter vports struct
368  * @max_mtu: device given max possible MTU
369  * @default_mac_addr: device will give a default MAC to use
370  * @rx_itr_profile: RX profiles for Dynamic Interrupt Moderation
371  * @tx_itr_profile: TX profiles for Dynamic Interrupt Moderation
372  * @port_stats: per port csum, header split, and other offload stats
373  * @default_vport: Use this vport if one isn't specified
374  * @crc_enable: Enable CRC insertion offload
375  * @link_up: True if link is up
376  * @tx_tstamp_caps: Capabilities negotiated for Tx timestamping
377  * @tstamp_config: The Tx tstamp config
378  * @tstamp_task: Tx timestamping task
379  * @tstamp_stats: Tx timestamping statistics
380  */
381 struct idpf_vport {
382 	struct idpf_q_vec_rsrc dflt_qv_rsrc;
383 	struct idpf_tx_queue **txqs;
384 	u16 num_txq;
385 	u16 num_xdp_txq;
386 	bool xdpsq_share;
387 	struct bpf_prog *xdp_prog;
388 
389 	struct iidc_rdma_vport_dev_info *vdev_info;
390 
391 	struct idpf_adapter *adapter;
392 	struct net_device *netdev;
393 	DECLARE_BITMAP(flags, IDPF_VPORT_FLAGS_NBITS);
394 	u32 compln_clean_budget;
395 	u32 vport_id;
396 	u16 vport_type;
397 	u16 idx;
398 
399 	u16 max_mtu;
400 	u8 default_mac_addr[ETH_ALEN];
401 	u16 rx_itr_profile[IDPF_DIM_PROFILE_SLOTS];
402 	u16 tx_itr_profile[IDPF_DIM_PROFILE_SLOTS];
403 
404 	struct idpf_port_stats port_stats;
405 	bool default_vport;
406 	bool crc_enable;
407 	bool link_up;
408 
409 	struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps;
410 	struct kernel_hwtstamp_config tstamp_config;
411 	struct work_struct tstamp_task;
412 	struct idpf_tstamp_stats tstamp_stats;
413 };
414 
415 /**
416  * enum idpf_user_flags
417  * @__IDPF_USER_FLAG_HSPLIT: header split state
418  * @__IDPF_PROMISC_UC: Unicast promiscuous mode
419  * @__IDPF_PROMISC_MC: Multicast promiscuous mode
420  * @__IDPF_USER_FLAGS_NBITS: Must be last
421  */
422 enum idpf_user_flags {
423 	__IDPF_USER_FLAG_HSPLIT = 0U,
424 	__IDPF_PROMISC_UC = 32,
425 	__IDPF_PROMISC_MC,
426 
427 	__IDPF_USER_FLAGS_NBITS,
428 };
429 
430 /**
431  * struct idpf_rss_data - Associated RSS data
432  * @rss_key_size: Size of RSS hash key
433  * @rss_key: RSS hash key
434  * @rss_lut_size: Size of RSS lookup table
435  * @rss_lut: RSS lookup table
436  */
437 struct idpf_rss_data {
438 	u16 rss_key_size;
439 	u8 *rss_key;
440 	u16 rss_lut_size;
441 	u32 *rss_lut;
442 };
443 
444 /**
445  * struct idpf_q_coalesce - User defined coalescing configuration values for
446  *			   a single queue.
447  * @tx_intr_mode: Dynamic TX ITR or not
448  * @rx_intr_mode: Dynamic RX ITR or not
449  * @tx_coalesce_usecs: TX interrupt throttling rate
450  * @rx_coalesce_usecs: RX interrupt throttling rate
451  *
452  * Used to restore user coalescing configuration after a reset.
453  */
454 struct idpf_q_coalesce {
455 	u32 tx_intr_mode;
456 	u32 rx_intr_mode;
457 	u32 tx_coalesce_usecs;
458 	u32 rx_coalesce_usecs;
459 };
460 
461 /**
462  * struct idpf_vport_user_config_data - User defined configuration values for
463  *					each vport.
464  * @rss_data: See struct idpf_rss_data
465  * @q_coalesce: Array of per queue coalescing data
466  * @num_req_tx_qs: Number of user requested TX queues through ethtool
467  * @num_req_rx_qs: Number of user requested RX queues through ethtool
468  * @num_req_txq_desc: Number of user requested TX queue descriptors through
469  *		      ethtool
470  * @num_req_rxq_desc: Number of user requested RX queue descriptors through
471  *		      ethtool
472  * @xdp_prog: requested XDP program to install
473  * @user_flags: User toggled config flags
474  * @mac_filter_list: List of MAC filters
475  * @num_fsteer_fltrs: number of flow steering filters
476  * @flow_steer_list: list of flow steering filters
477  *
478  * Used to restore configuration after a reset as the vport will get wiped.
479  */
480 struct idpf_vport_user_config_data {
481 	struct idpf_rss_data rss_data;
482 	struct idpf_q_coalesce *q_coalesce;
483 	u16 num_req_tx_qs;
484 	u16 num_req_rx_qs;
485 	u32 num_req_txq_desc;
486 	u32 num_req_rxq_desc;
487 	struct bpf_prog *xdp_prog;
488 	DECLARE_BITMAP(user_flags, __IDPF_USER_FLAGS_NBITS);
489 	struct list_head mac_filter_list;
490 	u32 num_fsteer_fltrs;
491 	struct list_head flow_steer_list;
492 };
493 
494 /**
495  * enum idpf_vport_config_flags - Vport config flags
496  * @IDPF_VPORT_REG_NETDEV: Register netdev
497  * @IDPF_VPORT_UP_REQUESTED: Set if interface up is requested on core reset
498  * @IDPF_VPORT_CONFIG_FLAGS_NBITS: Must be last
499  */
500 enum idpf_vport_config_flags {
501 	IDPF_VPORT_REG_NETDEV,
502 	IDPF_VPORT_UP_REQUESTED,
503 	IDPF_VPORT_CONFIG_FLAGS_NBITS,
504 };
505 
506 /**
507  * struct idpf_avail_queue_info
508  * @avail_rxq: Available RX queues
509  * @avail_txq: Available TX queues
510  * @avail_bufq: Available buffer queues
511  * @avail_complq: Available completion queues
512  *
513  * Maintain total queues available after allocating max queues to each vport.
514  */
515 struct idpf_avail_queue_info {
516 	u16 avail_rxq;
517 	u16 avail_txq;
518 	u16 avail_bufq;
519 	u16 avail_complq;
520 };
521 
522 /**
523  * struct idpf_vector_info - Utility structure to pass function arguments as a
524  *			     structure
525  * @num_req_vecs: Vectors required based on the number of queues updated by the
526  *		  user via ethtool
527  * @num_curr_vecs: Current number of vectors, must be >= @num_req_vecs
528  * @index: Relative starting index for vectors
529  * @default_vport: Vectors are for default vport
530  */
531 struct idpf_vector_info {
532 	u16 num_req_vecs;
533 	u16 num_curr_vecs;
534 	u16 index;
535 	bool default_vport;
536 };
537 
538 /**
539  * struct idpf_vector_lifo - Stack to maintain vector indexes used for vector
540  *			     distribution algorithm
541  * @top: Points to stack top i.e. next available vector index
542  * @base: Always points to start of the free pool
543  * @size: Total size of the vector stack
544  * @vec_idx: Array to store all the vector indexes
545  *
546  * Vector stack maintains all the relative vector indexes at the *adapter*
547  * level. This stack is divided into 2 parts, first one is called as 'default
548  * pool' and other one is called 'free pool'.  Vector distribution algorithm
549  * gives priority to default vports in a way that at least IDPF_MIN_Q_VEC
550  * vectors are allocated per default vport and the relative vector indexes for
551  * those are maintained in default pool. Free pool contains all the unallocated
552  * vector indexes which can be allocated on-demand basis. Mailbox vector index
553  * is maintained in the default pool of the stack.
554  */
555 struct idpf_vector_lifo {
556 	u16 top;
557 	u16 base;
558 	u16 size;
559 	u16 *vec_idx;
560 };
561 
562 /**
563  * struct idpf_queue_id_reg_chunk - individual queue ID and register chunk
564  * @qtail_reg_start: queue tail register offset
565  * @qtail_reg_spacing: queue tail register spacing
566  * @type: queue type of the queues in the chunk
567  * @start_queue_id: starting queue ID in the chunk
568  * @num_queues: number of queues in the chunk
569  */
570 struct idpf_queue_id_reg_chunk {
571 	u64 qtail_reg_start;
572 	u32 qtail_reg_spacing;
573 	u32 type;
574 	u32 start_queue_id;
575 	u32 num_queues;
576 };
577 
578 /**
579  * struct idpf_queue_id_reg_info - queue ID and register chunk info received
580  *				   over the mailbox
581  * @num_chunks: number of chunks
582  * @queue_chunks: array of chunks
583  */
584 struct idpf_queue_id_reg_info {
585 	u16 num_chunks;
586 	struct idpf_queue_id_reg_chunk *queue_chunks;
587 };
588 
589 /**
590  * struct idpf_vport_config - Vport configuration data
591  * @user_config: see struct idpf_vport_user_config_data
592  * @max_q: Maximum possible queues
593  * @qid_reg_info: Struct to store the queue ID and register info
594  * @mac_filter_list_lock: Lock to protect mac filters
595  * @flow_steer_list_lock: Lock to protect fsteer filters
596  * @flags: See enum idpf_vport_config_flags
597  */
598 struct idpf_vport_config {
599 	struct idpf_vport_user_config_data user_config;
600 	struct idpf_vport_max_q max_q;
601 	struct idpf_queue_id_reg_info qid_reg_info;
602 	spinlock_t mac_filter_list_lock;
603 	spinlock_t flow_steer_list_lock;
604 	DECLARE_BITMAP(flags, IDPF_VPORT_CONFIG_FLAGS_NBITS);
605 };
606 
607 #define idpf_for_each_vport(adapter, iter) \
608 	for (struct idpf_vport **__##iter = &(adapter)->vports[0], \
609 	     *iter = (adapter)->max_vports ? *__##iter : NULL; \
610 	     iter; \
611 	     iter = (++__##iter) < &(adapter)->vports[(adapter)->max_vports] ? \
612 	     *__##iter : NULL)
613 
614 /**
615  * struct idpf_adapter - Device data struct generated on probe
616  * @pdev: PCI device struct given on probe
617  * @virt_ver_maj: Virtchnl version major
618  * @virt_ver_min: Virtchnl version minor
619  * @msg_enable: Debug message level enabled
620  * @mb_wait_count: Number of times mailbox was attempted initialization
621  * @state: Init state machine
622  * @flags: See enum idpf_flags
623  * @reset_reg: See struct idpf_reset_reg
624  * @ctlq_ctx: controlq context
625  * @asq: Send control queue info
626  * @arq: Receive control queue info
627  * @xnm: Xn transaction manager
628  * @num_avail_msix: Available number of MSIX vectors
629  * @num_msix_entries: Number of entries in MSIX table
630  * @msix_entries: MSIX table
631  * @num_rdma_msix_entries: Available number of MSIX vectors for RDMA
632  * @rdma_msix_entries: RDMA MSIX table
633  * @req_vec_chunks: Requested vector chunk data
634  * @mb_vector: Mailbox vector data
635  * @vector_stack: Stack to store the msix vector indexes
636  * @irq_mb_handler: Handler for hard interrupt for mailbox
637  * @tx_timeout_count: Number of TX timeouts that have occurred
638  * @avail_queues: Device given queue limits
639  * @vports: Array to store vports created by the driver
640  * @netdevs: Associated Vport netdevs
641  * @vport_params_recvd: Vport params received
642  * @vport_ids: Array of device given vport identifiers
643  * @singleq_pt_lkup: Lookup table for singleq RX ptypes
644  * @splitq_pt_lkup: Lookup table for splitq RX ptypes
645  * @vport_config: Vport config parameters
646  * @max_vports: Maximum vports that can be allocated
647  * @num_alloc_vports: Current number of vports allocated
648  * @next_vport: Next free slot in pf->vport[] - 0-based!
649  * @init_task: Initialization task
650  * @init_wq: Workqueue for initialization task
651  * @serv_task: Periodically recurring maintenance task
652  * @serv_wq: Workqueue for service task
653  * @mbx_task: Task to handle mailbox interrupts
654  * @mbx_wq: Workqueue for mailbox responses
655  * @vc_event_task: Task to handle out of band virtchnl event notifications
656  * @vc_event_wq: Workqueue for virtchnl events
657  * @stats_task: Periodic statistics retrieval task
658  * @stats_wq: Workqueue for statistics task
659  * @caps: Negotiated capabilities with device
660  * @dev_ops: See idpf_dev_ops
661  * @cdev_info: IDC core device info pointer
662  * @num_vfs: Number of allocated VFs through sysfs. PF does not directly talk
663  *	     to VFs but is used to initialize them
664  * @crc_enable: Enable CRC insertion offload
665  * @req_tx_splitq: TX split or single queue model to request
666  * @req_rx_splitq: RX split or single queue model to request
667  * @vport_ctrl_lock: Lock to protect the vport control flow
668  * @vector_lock: Lock to protect vector distribution
669  * @queue_lock: Lock to protect queue distribution
670  * @vc_buf_lock: Lock to protect virtchnl buffer
671  * @ptp: Storage for PTP-related data
672  */
673 struct idpf_adapter {
674 	struct pci_dev *pdev;
675 	u32 virt_ver_maj;
676 	u32 virt_ver_min;
677 
678 	u32 msg_enable;
679 	u32 mb_wait_count;
680 	enum idpf_state state;
681 	DECLARE_BITMAP(flags, IDPF_FLAGS_NBITS);
682 	struct idpf_reset_reg reset_reg;
683 	struct libie_ctlq_ctx ctlq_ctx;
684 	struct libie_ctlq_info *asq;
685 	struct libie_ctlq_info *arq;
686 	struct libie_ctlq_xn_manager *xnm;
687 	u16 num_avail_msix;
688 	u16 num_msix_entries;
689 	struct msix_entry *msix_entries;
690 	u16 num_rdma_msix_entries;
691 	struct msix_entry *rdma_msix_entries;
692 	struct virtchnl2_alloc_vectors *req_vec_chunks;
693 	struct idpf_q_vector mb_vector;
694 	struct idpf_vector_lifo vector_stack;
695 	irqreturn_t (*irq_mb_handler)(int irq, void *data);
696 
697 	u32 tx_timeout_count;
698 	struct idpf_avail_queue_info avail_queues;
699 	struct idpf_vport **vports;
700 	struct net_device **netdevs;
701 	struct virtchnl2_create_vport **vport_params_recvd;
702 	u32 *vport_ids;
703 
704 	struct libeth_rx_pt *singleq_pt_lkup;
705 	struct libeth_rx_pt *splitq_pt_lkup;
706 
707 	struct idpf_vport_config **vport_config;
708 	u16 max_vports;
709 	u16 num_alloc_vports;
710 	u16 next_vport;
711 
712 	struct delayed_work init_task;
713 	struct workqueue_struct *init_wq;
714 	struct delayed_work serv_task;
715 	struct workqueue_struct *serv_wq;
716 	struct delayed_work mbx_task;
717 	struct workqueue_struct *mbx_wq;
718 	struct delayed_work vc_event_task;
719 	struct workqueue_struct *vc_event_wq;
720 	struct delayed_work stats_task;
721 	struct workqueue_struct *stats_wq;
722 	struct virtchnl2_get_capabilities caps;
723 
724 	struct idpf_dev_ops dev_ops;
725 	struct iidc_rdma_core_dev_info *cdev_info;
726 	int num_vfs;
727 	bool crc_enable;
728 	bool req_tx_splitq;
729 	bool req_rx_splitq;
730 
731 	struct mutex vport_ctrl_lock;
732 	struct mutex vector_lock;
733 	struct mutex queue_lock;
734 	struct mutex vc_buf_lock;
735 
736 	struct idpf_ptp *ptp;
737 };
738 
739 /**
740  * idpf_is_queue_model_split - check if queue model is split
741  * @q_model: queue model single or split
742  *
743  * Returns true if queue model is split else false
744  */
idpf_is_queue_model_split(u16 q_model)745 static inline int idpf_is_queue_model_split(u16 q_model)
746 {
747 	return !IS_ENABLED(CONFIG_IDPF_SINGLEQ) ||
748 	       q_model == VIRTCHNL2_QUEUE_MODEL_SPLIT;
749 }
750 
idpf_xdp_enabled(const struct idpf_vport * vport)751 static inline bool idpf_xdp_enabled(const struct idpf_vport *vport)
752 {
753 	return vport->adapter && vport->xdp_prog;
754 }
755 
756 #define idpf_is_cap_ena(adapter, field, flag) \
757 	idpf_is_capability_ena(adapter, false, field, flag)
758 #define idpf_is_cap_ena_all(adapter, field, flag) \
759 	idpf_is_capability_ena(adapter, true, field, flag)
760 
761 bool idpf_is_capability_ena(struct idpf_adapter *adapter, bool all,
762 			    enum idpf_cap_field field, u64 flag);
763 
764 /**
765  * idpf_is_rdma_cap_ena - Determine if RDMA is supported
766  * @adapter: private data struct
767  *
768  * Return: true if RDMA capability is enabled, false otherwise
769  */
idpf_is_rdma_cap_ena(struct idpf_adapter * adapter)770 static inline bool idpf_is_rdma_cap_ena(struct idpf_adapter *adapter)
771 {
772 	return idpf_is_cap_ena(adapter, IDPF_OTHER_CAPS, VIRTCHNL2_CAP_RDMA);
773 }
774 
775 #define IDPF_CAP_RSS (\
776 	VIRTCHNL2_FLOW_IPV4_TCP		|\
777 	VIRTCHNL2_FLOW_IPV4_UDP		|\
778 	VIRTCHNL2_FLOW_IPV4_SCTP	|\
779 	VIRTCHNL2_FLOW_IPV4_OTHER	|\
780 	VIRTCHNL2_FLOW_IPV6_TCP		|\
781 	VIRTCHNL2_FLOW_IPV6_UDP		|\
782 	VIRTCHNL2_FLOW_IPV6_SCTP	|\
783 	VIRTCHNL2_FLOW_IPV6_OTHER)
784 
785 #define IDPF_CAP_RSC (\
786 	VIRTCHNL2_CAP_RSC_IPV4_TCP	|\
787 	VIRTCHNL2_CAP_RSC_IPV6_TCP)
788 
789 #define IDPF_CAP_HSPLIT	(\
790 	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4	|\
791 	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6)
792 
793 #define IDPF_CAP_TX_CSUM_L4V4 (\
794 	VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_TCP	|\
795 	VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_UDP)
796 
797 #define IDPF_CAP_TX_CSUM_L4V6 (\
798 	VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_TCP	|\
799 	VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_UDP)
800 
801 #define IDPF_CAP_RX_CSUM (\
802 	VIRTCHNL2_CAP_RX_CSUM_L3_IPV4		|\
803 	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP	|\
804 	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP	|\
805 	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP	|\
806 	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP)
807 
808 #define IDPF_CAP_TX_SCTP_CSUM (\
809 	VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP	|\
810 	VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP)
811 
812 #define IDPF_CAP_TUNNEL_TX_CSUM (\
813 	VIRTCHNL2_CAP_TX_CSUM_L3_SINGLE_TUNNEL	|\
814 	VIRTCHNL2_CAP_TX_CSUM_L4_SINGLE_TUNNEL)
815 
816 /**
817  * idpf_get_reserved_vecs - Get reserved vectors
818  * @adapter: private data struct
819  */
idpf_get_reserved_vecs(struct idpf_adapter * adapter)820 static inline u16 idpf_get_reserved_vecs(struct idpf_adapter *adapter)
821 {
822 	return le16_to_cpu(adapter->caps.num_allocated_vectors);
823 }
824 
825 /**
826  * idpf_get_reserved_rdma_vecs - Get reserved RDMA vectors
827  * @adapter: private data struct
828  *
829  * Return: number of vectors reserved for RDMA
830  */
idpf_get_reserved_rdma_vecs(struct idpf_adapter * adapter)831 static inline u16 idpf_get_reserved_rdma_vecs(struct idpf_adapter *adapter)
832 {
833 	return le16_to_cpu(adapter->caps.num_rdma_allocated_vectors);
834 }
835 
836 /**
837  * idpf_get_default_vports - Get default number of vports
838  * @adapter: private data struct
839  */
idpf_get_default_vports(struct idpf_adapter * adapter)840 static inline u16 idpf_get_default_vports(struct idpf_adapter *adapter)
841 {
842 	return le16_to_cpu(adapter->caps.default_num_vports);
843 }
844 
845 /**
846  * idpf_get_max_vports - Get max number of vports
847  * @adapter: private data struct
848  */
idpf_get_max_vports(struct idpf_adapter * adapter)849 static inline u16 idpf_get_max_vports(struct idpf_adapter *adapter)
850 {
851 	return le16_to_cpu(adapter->caps.max_vports);
852 }
853 
854 /**
855  * idpf_get_max_tx_bufs - Get max scatter-gather buffers supported by the device
856  * @adapter: private data struct
857  */
idpf_get_max_tx_bufs(struct idpf_adapter * adapter)858 static inline unsigned int idpf_get_max_tx_bufs(struct idpf_adapter *adapter)
859 {
860 	return adapter->caps.max_sg_bufs_per_tx_pkt;
861 }
862 
863 /**
864  * idpf_get_min_tx_pkt_len - Get min packet length supported by the device
865  * @adapter: private data struct
866  */
idpf_get_min_tx_pkt_len(struct idpf_adapter * adapter)867 static inline u8 idpf_get_min_tx_pkt_len(struct idpf_adapter *adapter)
868 {
869 	u8 pkt_len = adapter->caps.min_sso_packet_len;
870 
871 	return pkt_len ? pkt_len : IDPF_TX_MIN_PKT_LEN;
872 }
873 
874 /**
875  * idpf_is_reset_detected - check if we were reset at some point
876  * @adapter: driver specific private structure
877  *
878  * Returns true if we are either in reset currently or were previously reset.
879  */
idpf_is_reset_detected(struct idpf_adapter * adapter)880 static inline bool idpf_is_reset_detected(struct idpf_adapter *adapter)
881 {
882 	struct libie_ctlq_info *arq = adapter->arq;
883 
884 	if (!arq)
885 		return true;
886 
887 	return !(readl(arq->reg.len) & arq->reg.len_mask);
888 }
889 
890 /**
891  * idpf_is_reset_in_prog - check if reset is in progress
892  * @adapter: driver specific private structure
893  *
894  * Returns true if hard reset is in progress, false otherwise
895  */
idpf_is_reset_in_prog(struct idpf_adapter * adapter)896 static inline bool idpf_is_reset_in_prog(struct idpf_adapter *adapter)
897 {
898 	return (test_bit(IDPF_HR_RESET_IN_PROG, adapter->flags) ||
899 		test_bit(IDPF_HR_FUNC_RESET, adapter->flags) ||
900 		test_bit(IDPF_HR_DRV_LOAD, adapter->flags));
901 }
902 
903 /**
904  * idpf_netdev_to_vport - get a vport handle from a netdev
905  * @netdev: network interface device structure
906  */
idpf_netdev_to_vport(struct net_device * netdev)907 static inline struct idpf_vport *idpf_netdev_to_vport(struct net_device *netdev)
908 {
909 	struct idpf_netdev_priv *np = netdev_priv(netdev);
910 
911 	return np->vport;
912 }
913 
914 /**
915  * idpf_netdev_to_adapter - Get adapter handle from a netdev
916  * @netdev: Network interface device structure
917  */
idpf_netdev_to_adapter(struct net_device * netdev)918 static inline struct idpf_adapter *idpf_netdev_to_adapter(struct net_device *netdev)
919 {
920 	struct idpf_netdev_priv *np = netdev_priv(netdev);
921 
922 	return np->adapter;
923 }
924 
925 /**
926  * idpf_is_feature_ena - Determine if a particular feature is enabled
927  * @vport: Vport to check
928  * @feature: Netdev flag to check
929  *
930  * Returns true or false if a particular feature is enabled.
931  */
idpf_is_feature_ena(const struct idpf_vport * vport,netdev_features_t feature)932 static inline bool idpf_is_feature_ena(const struct idpf_vport *vport,
933 				       netdev_features_t feature)
934 {
935 	return vport->netdev->features & feature;
936 }
937 
938 /**
939  * idpf_get_max_tx_hdr_size -- get the size of tx header
940  * @adapter: Driver specific private structure
941  */
idpf_get_max_tx_hdr_size(struct idpf_adapter * adapter)942 static inline u16 idpf_get_max_tx_hdr_size(struct idpf_adapter *adapter)
943 {
944 	return le16_to_cpu(adapter->caps.max_tx_hdr_size);
945 }
946 
947 /**
948  * idpf_vport_ctrl_lock - Acquire the vport control lock
949  * @netdev: Network interface device structure
950  *
951  * This lock should be used by non-datapath code to protect against vport
952  * destruction.
953  */
idpf_vport_ctrl_lock(struct net_device * netdev)954 static inline void idpf_vport_ctrl_lock(struct net_device *netdev)
955 {
956 	struct idpf_netdev_priv *np = netdev_priv(netdev);
957 
958 	mutex_lock(&np->adapter->vport_ctrl_lock);
959 }
960 
961 /**
962  * idpf_vport_ctrl_unlock - Release the vport control lock
963  * @netdev: Network interface device structure
964  */
idpf_vport_ctrl_unlock(struct net_device * netdev)965 static inline void idpf_vport_ctrl_unlock(struct net_device *netdev)
966 {
967 	struct idpf_netdev_priv *np = netdev_priv(netdev);
968 
969 	mutex_unlock(&np->adapter->vport_ctrl_lock);
970 }
971 
idpf_vport_ctrl_is_locked(struct net_device * netdev)972 static inline bool idpf_vport_ctrl_is_locked(struct net_device *netdev)
973 {
974 	struct idpf_netdev_priv *np = netdev_priv(netdev);
975 
976 	return mutex_is_locked(&np->adapter->vport_ctrl_lock);
977 }
978 
979 void idpf_statistics_task(struct work_struct *work);
980 void idpf_init_task(struct work_struct *work);
981 void idpf_service_task(struct work_struct *work);
982 void idpf_mbx_task(struct work_struct *work);
983 void idpf_vc_event_task(struct work_struct *work);
984 void idpf_dev_ops_init(struct idpf_adapter *adapter);
985 void idpf_vf_dev_ops_init(struct idpf_adapter *adapter);
986 int idpf_intr_req(struct idpf_adapter *adapter);
987 void idpf_mb_intr_rel_irq(struct idpf_adapter *adapter);
988 void idpf_intr_rel(struct idpf_adapter *adapter);
989 u16 idpf_get_max_tx_hdr_size(struct idpf_adapter *adapter);
990 int idpf_initiate_soft_reset(struct idpf_vport *vport,
991 			     enum idpf_vport_reset_cause reset_cause);
992 void idpf_deinit_task(struct idpf_adapter *adapter);
993 int idpf_req_rel_vector_indexes(struct idpf_adapter *adapter,
994 				u16 *q_vector_idxs,
995 				struct idpf_vector_info *vec_info);
996 void idpf_set_ethtool_ops(struct net_device *netdev);
997 void idpf_vport_intr_write_itr(struct idpf_q_vector *q_vector,
998 			       u16 itr, bool tx);
999 int idpf_sriov_configure(struct pci_dev *pdev, int num_vfs);
1000 
1001 u8 idpf_vport_get_hsplit(const struct idpf_vport *vport);
1002 bool idpf_vport_set_hsplit(const struct idpf_vport *vport, u8 val);
1003 int idpf_idc_init(struct idpf_adapter *adapter);
1004 int idpf_idc_init_aux_core_dev(struct idpf_adapter *adapter,
1005 			       enum iidc_function_type ftype);
1006 void idpf_idc_deinit_core_aux_device(struct idpf_adapter *adapter);
1007 void idpf_idc_deinit_vport_aux_device(struct iidc_rdma_vport_dev_info *vdev_info);
1008 void idpf_idc_issue_reset_event(struct iidc_rdma_core_dev_info *cdev_info);
1009 void idpf_idc_vdev_mtu_event(struct iidc_rdma_vport_dev_info *vdev_info,
1010 			     enum iidc_rdma_event_type event_type);
1011 
1012 int idpf_add_del_fsteer_filters(struct idpf_adapter *adapter,
1013 				struct virtchnl2_flow_rule_add_del *rule,
1014 				enum virtchnl2_op opcode);
1015 #endif /* !_IDPF_H_ */
1016