• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
12 #include <net/pkt_sched.h>
13 #include <linux/aer.h>
14 #include <linux/etherdevice.h>
15 #include <linux/pci.h>
16 #include <linux/bitfield.h>
17 #include <linux/sctp.h>
18 #include <linux/ethtool_netlink.h>
19 #include <net/gro.h>
20 
21 #include "virtchnl2.h"
22 #include "idpf_txrx.h"
23 #include "idpf_controlq.h"
24 
25 #define GETMAXVAL(num_bits)		GENMASK((num_bits) - 1, 0)
26 
27 #define IDPF_NO_FREE_SLOT		0xffff
28 
29 /* Default Mailbox settings */
30 #define IDPF_NUM_FILTERS_PER_MSG	20
31 #define IDPF_NUM_DFLT_MBX_Q		2	/* includes both TX and RX */
32 #define IDPF_DFLT_MBX_Q_LEN		64
33 #define IDPF_DFLT_MBX_ID		-1
34 /* maximum number of times to try before resetting mailbox */
35 #define IDPF_MB_MAX_ERR			20
36 #define IDPF_NUM_CHUNKS_PER_MSG(struct_sz, chunk_sz)	\
37 	((IDPF_CTLQ_MAX_BUF_LEN - (struct_sz)) / (chunk_sz))
38 
39 #define IDPF_MAX_WAIT			500
40 
41 /* available message levels */
42 #define IDPF_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
43 
44 #define IDPF_DIM_PROFILE_SLOTS  5
45 
46 #define IDPF_VIRTCHNL_VERSION_MAJOR VIRTCHNL2_VERSION_MAJOR_2
47 #define IDPF_VIRTCHNL_VERSION_MINOR VIRTCHNL2_VERSION_MINOR_0
48 
49 /**
50  * struct idpf_mac_filter
51  * @list: list member field
52  * @macaddr: MAC address
53  * @remove: filter should be removed (virtchnl)
54  * @add: filter should be added (virtchnl)
55  */
56 struct idpf_mac_filter {
57 	struct list_head list;
58 	u8 macaddr[ETH_ALEN];
59 	bool remove;
60 	bool add;
61 };
62 
63 /**
64  * enum idpf_state - State machine to handle bring up
65  * @__IDPF_VER_CHECK: Negotiate virtchnl version
66  * @__IDPF_GET_CAPS: Negotiate capabilities
67  * @__IDPF_INIT_SW: Init based on given capabilities
68  * @__IDPF_STATE_LAST: Must be last, used to determine size
69  */
70 enum idpf_state {
71 	__IDPF_VER_CHECK,
72 	__IDPF_GET_CAPS,
73 	__IDPF_INIT_SW,
74 	__IDPF_STATE_LAST,
75 };
76 
77 /**
78  * enum idpf_flags - Hard reset causes.
79  * @IDPF_HR_FUNC_RESET: Hard reset when TxRx timeout
80  * @IDPF_HR_DRV_LOAD: Set on driver load for a clean HW
81  * @IDPF_HR_RESET_IN_PROG: Reset in progress
82  * @IDPF_REMOVE_IN_PROG: Driver remove in progress
83  * @IDPF_MB_INTR_MODE: Mailbox in interrupt mode
84  * @IDPF_VC_CORE_INIT: virtchnl core has been init
85  * @IDPF_FLAGS_NBITS: Must be last
86  */
87 enum idpf_flags {
88 	IDPF_HR_FUNC_RESET,
89 	IDPF_HR_DRV_LOAD,
90 	IDPF_HR_RESET_IN_PROG,
91 	IDPF_REMOVE_IN_PROG,
92 	IDPF_MB_INTR_MODE,
93 	IDPF_VC_CORE_INIT,
94 	IDPF_FLAGS_NBITS,
95 };
96 
97 /**
98  * enum idpf_cap_field - Offsets into capabilities struct for specific caps
99  * @IDPF_BASE_CAPS: generic base capabilities
100  * @IDPF_CSUM_CAPS: checksum offload capabilities
101  * @IDPF_SEG_CAPS: segmentation offload capabilities
102  * @IDPF_RSS_CAPS: RSS offload capabilities
103  * @IDPF_HSPLIT_CAPS: Header split capabilities
104  * @IDPF_RSC_CAPS: RSC offload capabilities
105  * @IDPF_OTHER_CAPS: miscellaneous offloads
106  *
107  * Used when checking for a specific capability flag since different capability
108  * sets are not mutually exclusive numerically, the caller must specify which
109  * type of capability they are checking for.
110  */
111 enum idpf_cap_field {
112 	IDPF_BASE_CAPS		= -1,
113 	IDPF_CSUM_CAPS		= offsetof(struct virtchnl2_get_capabilities,
114 					   csum_caps),
115 	IDPF_SEG_CAPS		= offsetof(struct virtchnl2_get_capabilities,
116 					   seg_caps),
117 	IDPF_RSS_CAPS		= offsetof(struct virtchnl2_get_capabilities,
118 					   rss_caps),
119 	IDPF_HSPLIT_CAPS	= offsetof(struct virtchnl2_get_capabilities,
120 					   hsplit_caps),
121 	IDPF_RSC_CAPS		= offsetof(struct virtchnl2_get_capabilities,
122 					   rsc_caps),
123 	IDPF_OTHER_CAPS		= offsetof(struct virtchnl2_get_capabilities,
124 					   other_caps),
125 };
126 
127 /**
128  * enum idpf_vport_state - Current vport state
129  * @__IDPF_VPORT_DOWN: Vport is down
130  * @__IDPF_VPORT_UP: Vport is up
131  * @__IDPF_VPORT_STATE_LAST: Must be last, number of states
132  */
133 enum idpf_vport_state {
134 	__IDPF_VPORT_DOWN,
135 	__IDPF_VPORT_UP,
136 	__IDPF_VPORT_STATE_LAST,
137 };
138 
139 /**
140  * struct idpf_netdev_priv - Struct to store vport back pointer
141  * @adapter: Adapter back pointer
142  * @vport: Vport back pointer
143  * @vport_id: Vport identifier
144  * @link_speed_mbps: Link speed in mbps
145  * @vport_idx: Relative vport index
146  * @max_tx_hdr_size: Max header length hardware can support
147  * @state: See enum idpf_vport_state
148  * @netstats: Packet and byte stats
149  * @stats_lock: Lock to protect stats update
150  */
151 struct idpf_netdev_priv {
152 	struct idpf_adapter *adapter;
153 	struct idpf_vport *vport;
154 	u32 vport_id;
155 	u32 link_speed_mbps;
156 	u16 vport_idx;
157 	u16 max_tx_hdr_size;
158 	enum idpf_vport_state state;
159 	struct rtnl_link_stats64 netstats;
160 	spinlock_t stats_lock;
161 };
162 
163 /**
164  * struct idpf_reset_reg - Reset register offsets/masks
165  * @rstat: Reset status register
166  * @rstat_m: Reset status mask
167  */
168 struct idpf_reset_reg {
169 	void __iomem *rstat;
170 	u32 rstat_m;
171 };
172 
173 /**
174  * struct idpf_vport_max_q - Queue limits
175  * @max_rxq: Maximum number of RX queues supported
176  * @max_txq: Maixmum number of TX queues supported
177  * @max_bufq: In splitq, maximum number of buffer queues supported
178  * @max_complq: In splitq, maximum number of completion queues supported
179  */
180 struct idpf_vport_max_q {
181 	u16 max_rxq;
182 	u16 max_txq;
183 	u16 max_bufq;
184 	u16 max_complq;
185 };
186 
187 /**
188  * struct idpf_reg_ops - Device specific register operation function pointers
189  * @ctlq_reg_init: Mailbox control queue register initialization
190  * @intr_reg_init: Traffic interrupt register initialization
191  * @mb_intr_reg_init: Mailbox interrupt register initialization
192  * @reset_reg_init: Reset register initialization
193  * @trigger_reset: Trigger a reset to occur
194  */
195 struct idpf_reg_ops {
196 	void (*ctlq_reg_init)(struct idpf_ctlq_create_info *cq);
197 	int (*intr_reg_init)(struct idpf_vport *vport);
198 	void (*mb_intr_reg_init)(struct idpf_adapter *adapter);
199 	void (*reset_reg_init)(struct idpf_adapter *adapter);
200 	void (*trigger_reset)(struct idpf_adapter *adapter,
201 			      enum idpf_flags trig_cause);
202 };
203 
204 /**
205  * struct idpf_dev_ops - Device specific operations
206  * @reg_ops: Register operations
207  */
208 struct idpf_dev_ops {
209 	struct idpf_reg_ops reg_ops;
210 };
211 
212 /**
213  * enum idpf_vport_reset_cause - Vport soft reset causes
214  * @IDPF_SR_Q_CHANGE: Soft reset queue change
215  * @IDPF_SR_Q_DESC_CHANGE: Soft reset descriptor change
216  * @IDPF_SR_MTU_CHANGE: Soft reset MTU change
217  * @IDPF_SR_RSC_CHANGE: Soft reset RSC change
218  */
219 enum idpf_vport_reset_cause {
220 	IDPF_SR_Q_CHANGE,
221 	IDPF_SR_Q_DESC_CHANGE,
222 	IDPF_SR_MTU_CHANGE,
223 	IDPF_SR_RSC_CHANGE,
224 };
225 
226 /**
227  * enum idpf_vport_flags - Vport flags
228  * @IDPF_VPORT_DEL_QUEUES: To send delete queues message
229  * @IDPF_VPORT_SW_MARKER: Indicate TX pipe drain software marker packets
230  *			  processing is done
231  * @IDPF_VPORT_FLAGS_NBITS: Must be last
232  */
233 enum idpf_vport_flags {
234 	IDPF_VPORT_DEL_QUEUES,
235 	IDPF_VPORT_SW_MARKER,
236 	IDPF_VPORT_FLAGS_NBITS,
237 };
238 
239 struct idpf_port_stats {
240 	struct u64_stats_sync stats_sync;
241 	u64_stats_t rx_hw_csum_err;
242 	u64_stats_t rx_hsplit;
243 	u64_stats_t rx_hsplit_hbo;
244 	u64_stats_t rx_bad_descs;
245 	u64_stats_t tx_linearize;
246 	u64_stats_t tx_busy;
247 	u64_stats_t tx_drops;
248 	u64_stats_t tx_dma_map_errs;
249 	struct virtchnl2_vport_stats vport_stats;
250 };
251 
252 /**
253  * struct idpf_vport - Handle for netdevices and queue resources
254  * @num_txq: Number of allocated TX queues
255  * @num_complq: Number of allocated completion queues
256  * @txq_desc_count: TX queue descriptor count
257  * @complq_desc_count: Completion queue descriptor count
258  * @compln_clean_budget: Work budget for completion clean
259  * @num_txq_grp: Number of TX queue groups
260  * @txq_grps: Array of TX queue groups
261  * @txq_model: Split queue or single queue queuing model
262  * @txqs: Used only in hotpath to get to the right queue very fast
263  * @crc_enable: Enable CRC insertion offload
264  * @num_rxq: Number of allocated RX queues
265  * @num_bufq: Number of allocated buffer queues
266  * @rxq_desc_count: RX queue descriptor count. *MUST* have enough descriptors
267  *		    to complete all buffer descriptors for all buffer queues in
268  *		    the worst case.
269  * @num_bufqs_per_qgrp: Buffer queues per RX queue in a given grouping
270  * @bufq_desc_count: Buffer queue descriptor count
271  * @num_rxq_grp: Number of RX queues in a group
272  * @rxq_grps: Total number of RX groups. Number of groups * number of RX per
273  *	      group will yield total number of RX queues.
274  * @rxq_model: Splitq queue or single queue queuing model
275  * @rx_ptype_lkup: Lookup table for ptypes on RX
276  * @adapter: back pointer to associated adapter
277  * @netdev: Associated net_device. Each vport should have one and only one
278  *	    associated netdev.
279  * @flags: See enum idpf_vport_flags
280  * @vport_type: Default SRIOV, SIOV, etc.
281  * @vport_id: Device given vport identifier
282  * @idx: Software index in adapter vports struct
283  * @default_vport: Use this vport if one isn't specified
284  * @base_rxd: True if the driver should use base descriptors instead of flex
285  * @num_q_vectors: Number of IRQ vectors allocated
286  * @q_vectors: Array of queue vectors
287  * @q_vector_idxs: Starting index of queue vectors
288  * @max_mtu: device given max possible MTU
289  * @default_mac_addr: device will give a default MAC to use
290  * @rx_itr_profile: RX profiles for Dynamic Interrupt Moderation
291  * @tx_itr_profile: TX profiles for Dynamic Interrupt Moderation
292  * @port_stats: per port csum, header split, and other offload stats
293  * @link_up: True if link is up
294  * @sw_marker_wq: workqueue for marker packets
295  */
296 struct idpf_vport {
297 	u16 num_txq;
298 	u16 num_complq;
299 	u32 txq_desc_count;
300 	u32 complq_desc_count;
301 	u32 compln_clean_budget;
302 	u16 num_txq_grp;
303 	struct idpf_txq_group *txq_grps;
304 	u32 txq_model;
305 	struct idpf_tx_queue **txqs;
306 	bool crc_enable;
307 
308 	u16 num_rxq;
309 	u16 num_bufq;
310 	u32 rxq_desc_count;
311 	u8 num_bufqs_per_qgrp;
312 	u32 bufq_desc_count[IDPF_MAX_BUFQS_PER_RXQ_GRP];
313 	u16 num_rxq_grp;
314 	struct idpf_rxq_group *rxq_grps;
315 	u32 rxq_model;
316 	struct libeth_rx_pt *rx_ptype_lkup;
317 
318 	struct idpf_adapter *adapter;
319 	struct net_device *netdev;
320 	DECLARE_BITMAP(flags, IDPF_VPORT_FLAGS_NBITS);
321 	u16 vport_type;
322 	u32 vport_id;
323 	u16 idx;
324 	bool default_vport;
325 	bool base_rxd;
326 
327 	u16 num_q_vectors;
328 	struct idpf_q_vector *q_vectors;
329 	u16 *q_vector_idxs;
330 	u16 max_mtu;
331 	u8 default_mac_addr[ETH_ALEN];
332 	u16 rx_itr_profile[IDPF_DIM_PROFILE_SLOTS];
333 	u16 tx_itr_profile[IDPF_DIM_PROFILE_SLOTS];
334 	struct idpf_port_stats port_stats;
335 
336 	bool link_up;
337 
338 	wait_queue_head_t sw_marker_wq;
339 };
340 
341 /**
342  * enum idpf_user_flags
343  * @__IDPF_USER_FLAG_HSPLIT: header split state
344  * @__IDPF_PROMISC_UC: Unicast promiscuous mode
345  * @__IDPF_PROMISC_MC: Multicast promiscuous mode
346  * @__IDPF_USER_FLAGS_NBITS: Must be last
347  */
348 enum idpf_user_flags {
349 	__IDPF_USER_FLAG_HSPLIT = 0U,
350 	__IDPF_PROMISC_UC = 32,
351 	__IDPF_PROMISC_MC,
352 
353 	__IDPF_USER_FLAGS_NBITS,
354 };
355 
356 /**
357  * struct idpf_rss_data - Associated RSS data
358  * @rss_key_size: Size of RSS hash key
359  * @rss_key: RSS hash key
360  * @rss_lut_size: Size of RSS lookup table
361  * @rss_lut: RSS lookup table
362  * @cached_lut: Used to restore previously init RSS lut
363  */
364 struct idpf_rss_data {
365 	u16 rss_key_size;
366 	u8 *rss_key;
367 	u16 rss_lut_size;
368 	u32 *rss_lut;
369 	u32 *cached_lut;
370 };
371 
372 /**
373  * struct idpf_q_coalesce - User defined coalescing configuration values for
374  *			   a single queue.
375  * @tx_intr_mode: Dynamic TX ITR or not
376  * @rx_intr_mode: Dynamic RX ITR or not
377  * @tx_coalesce_usecs: TX interrupt throttling rate
378  * @rx_coalesce_usecs: RX interrupt throttling rate
379  *
380  * Used to restore user coalescing configuration after a reset.
381  */
382 struct idpf_q_coalesce {
383 	u32 tx_intr_mode;
384 	u32 rx_intr_mode;
385 	u32 tx_coalesce_usecs;
386 	u32 rx_coalesce_usecs;
387 };
388 
389 /**
390  * struct idpf_vport_user_config_data - User defined configuration values for
391  *					each vport.
392  * @rss_data: See struct idpf_rss_data
393  * @q_coalesce: Array of per queue coalescing data
394  * @num_req_tx_qs: Number of user requested TX queues through ethtool
395  * @num_req_rx_qs: Number of user requested RX queues through ethtool
396  * @num_req_txq_desc: Number of user requested TX queue descriptors through
397  *		      ethtool
398  * @num_req_rxq_desc: Number of user requested RX queue descriptors through
399  *		      ethtool
400  * @user_flags: User toggled config flags
401  * @mac_filter_list: List of MAC filters
402  *
403  * Used to restore configuration after a reset as the vport will get wiped.
404  */
405 struct idpf_vport_user_config_data {
406 	struct idpf_rss_data rss_data;
407 	struct idpf_q_coalesce *q_coalesce;
408 	u16 num_req_tx_qs;
409 	u16 num_req_rx_qs;
410 	u32 num_req_txq_desc;
411 	u32 num_req_rxq_desc;
412 	DECLARE_BITMAP(user_flags, __IDPF_USER_FLAGS_NBITS);
413 	struct list_head mac_filter_list;
414 };
415 
416 /**
417  * enum idpf_vport_config_flags - Vport config flags
418  * @IDPF_VPORT_REG_NETDEV: Register netdev
419  * @IDPF_VPORT_UP_REQUESTED: Set if interface up is requested on core reset
420  * @IDPF_VPORT_CONFIG_FLAGS_NBITS: Must be last
421  */
422 enum idpf_vport_config_flags {
423 	IDPF_VPORT_REG_NETDEV,
424 	IDPF_VPORT_UP_REQUESTED,
425 	IDPF_VPORT_CONFIG_FLAGS_NBITS,
426 };
427 
428 /**
429  * struct idpf_avail_queue_info
430  * @avail_rxq: Available RX queues
431  * @avail_txq: Available TX queues
432  * @avail_bufq: Available buffer queues
433  * @avail_complq: Available completion queues
434  *
435  * Maintain total queues available after allocating max queues to each vport.
436  */
437 struct idpf_avail_queue_info {
438 	u16 avail_rxq;
439 	u16 avail_txq;
440 	u16 avail_bufq;
441 	u16 avail_complq;
442 };
443 
444 /**
445  * struct idpf_vector_info - Utility structure to pass function arguments as a
446  *			     structure
447  * @num_req_vecs: Vectors required based on the number of queues updated by the
448  *		  user via ethtool
449  * @num_curr_vecs: Current number of vectors, must be >= @num_req_vecs
450  * @index: Relative starting index for vectors
451  * @default_vport: Vectors are for default vport
452  */
453 struct idpf_vector_info {
454 	u16 num_req_vecs;
455 	u16 num_curr_vecs;
456 	u16 index;
457 	bool default_vport;
458 };
459 
460 /**
461  * struct idpf_vector_lifo - Stack to maintain vector indexes used for vector
462  *			     distribution algorithm
463  * @top: Points to stack top i.e. next available vector index
464  * @base: Always points to start of the free pool
465  * @size: Total size of the vector stack
466  * @vec_idx: Array to store all the vector indexes
467  *
468  * Vector stack maintains all the relative vector indexes at the *adapter*
469  * level. This stack is divided into 2 parts, first one is called as 'default
470  * pool' and other one is called 'free pool'.  Vector distribution algorithm
471  * gives priority to default vports in a way that at least IDPF_MIN_Q_VEC
472  * vectors are allocated per default vport and the relative vector indexes for
473  * those are maintained in default pool. Free pool contains all the unallocated
474  * vector indexes which can be allocated on-demand basis. Mailbox vector index
475  * is maintained in the default pool of the stack.
476  */
477 struct idpf_vector_lifo {
478 	u16 top;
479 	u16 base;
480 	u16 size;
481 	u16 *vec_idx;
482 };
483 
484 /**
485  * struct idpf_vport_config - Vport configuration data
486  * @user_config: see struct idpf_vport_user_config_data
487  * @max_q: Maximum possible queues
488  * @req_qs_chunks: Queue chunk data for requested queues
489  * @mac_filter_list_lock: Lock to protect mac filters
490  * @flags: See enum idpf_vport_config_flags
491  */
492 struct idpf_vport_config {
493 	struct idpf_vport_user_config_data user_config;
494 	struct idpf_vport_max_q max_q;
495 	struct virtchnl2_add_queues *req_qs_chunks;
496 	spinlock_t mac_filter_list_lock;
497 	DECLARE_BITMAP(flags, IDPF_VPORT_CONFIG_FLAGS_NBITS);
498 };
499 
500 struct idpf_vc_xn_manager;
501 
502 /**
503  * struct idpf_adapter - Device data struct generated on probe
504  * @pdev: PCI device struct given on probe
505  * @virt_ver_maj: Virtchnl version major
506  * @virt_ver_min: Virtchnl version minor
507  * @msg_enable: Debug message level enabled
508  * @mb_wait_count: Number of times mailbox was attempted initialization
509  * @state: Init state machine
510  * @flags: See enum idpf_flags
511  * @reset_reg: See struct idpf_reset_reg
512  * @hw: Device access data
513  * @num_req_msix: Requested number of MSIX vectors
514  * @num_avail_msix: Available number of MSIX vectors
515  * @num_msix_entries: Number of entries in MSIX table
516  * @msix_entries: MSIX table
517  * @req_vec_chunks: Requested vector chunk data
518  * @mb_vector: Mailbox vector data
519  * @vector_stack: Stack to store the msix vector indexes
520  * @irq_mb_handler: Handler for hard interrupt for mailbox
521  * @tx_timeout_count: Number of TX timeouts that have occurred
522  * @avail_queues: Device given queue limits
523  * @vports: Array to store vports created by the driver
524  * @netdevs: Associated Vport netdevs
525  * @vport_params_reqd: Vport params requested
526  * @vport_params_recvd: Vport params received
527  * @vport_ids: Array of device given vport identifiers
528  * @vport_config: Vport config parameters
529  * @max_vports: Maximum vports that can be allocated
530  * @num_alloc_vports: Current number of vports allocated
531  * @next_vport: Next free slot in pf->vport[] - 0-based!
532  * @init_task: Initialization task
533  * @init_wq: Workqueue for initialization task
534  * @serv_task: Periodically recurring maintenance task
535  * @serv_wq: Workqueue for service task
536  * @mbx_task: Task to handle mailbox interrupts
537  * @mbx_wq: Workqueue for mailbox responses
538  * @vc_event_task: Task to handle out of band virtchnl event notifications
539  * @vc_event_wq: Workqueue for virtchnl events
540  * @stats_task: Periodic statistics retrieval task
541  * @stats_wq: Workqueue for statistics task
542  * @caps: Negotiated capabilities with device
543  * @vcxn_mngr: Virtchnl transaction manager
544  * @dev_ops: See idpf_dev_ops
545  * @num_vfs: Number of allocated VFs through sysfs. PF does not directly talk
546  *	     to VFs but is used to initialize them
547  * @crc_enable: Enable CRC insertion offload
548  * @req_tx_splitq: TX split or single queue model to request
549  * @req_rx_splitq: RX split or single queue model to request
550  * @vport_ctrl_lock: Lock to protect the vport control flow
551  * @vector_lock: Lock to protect vector distribution
552  * @queue_lock: Lock to protect queue distribution
553  * @vc_buf_lock: Lock to protect virtchnl buffer
554  */
555 struct idpf_adapter {
556 	struct pci_dev *pdev;
557 	u32 virt_ver_maj;
558 	u32 virt_ver_min;
559 
560 	u32 msg_enable;
561 	u32 mb_wait_count;
562 	enum idpf_state state;
563 	DECLARE_BITMAP(flags, IDPF_FLAGS_NBITS);
564 	struct idpf_reset_reg reset_reg;
565 	struct idpf_hw hw;
566 	u16 num_req_msix;
567 	u16 num_avail_msix;
568 	u16 num_msix_entries;
569 	struct msix_entry *msix_entries;
570 	struct virtchnl2_alloc_vectors *req_vec_chunks;
571 	struct idpf_q_vector mb_vector;
572 	struct idpf_vector_lifo vector_stack;
573 	irqreturn_t (*irq_mb_handler)(int irq, void *data);
574 
575 	u32 tx_timeout_count;
576 	struct idpf_avail_queue_info avail_queues;
577 	struct idpf_vport **vports;
578 	struct net_device **netdevs;
579 	struct virtchnl2_create_vport **vport_params_reqd;
580 	struct virtchnl2_create_vport **vport_params_recvd;
581 	u32 *vport_ids;
582 
583 	struct idpf_vport_config **vport_config;
584 	u16 max_vports;
585 	u16 num_alloc_vports;
586 	u16 next_vport;
587 
588 	struct delayed_work init_task;
589 	struct workqueue_struct *init_wq;
590 	struct delayed_work serv_task;
591 	struct workqueue_struct *serv_wq;
592 	struct delayed_work mbx_task;
593 	struct workqueue_struct *mbx_wq;
594 	struct delayed_work vc_event_task;
595 	struct workqueue_struct *vc_event_wq;
596 	struct delayed_work stats_task;
597 	struct workqueue_struct *stats_wq;
598 	struct virtchnl2_get_capabilities caps;
599 	struct idpf_vc_xn_manager *vcxn_mngr;
600 
601 	struct idpf_dev_ops dev_ops;
602 	int num_vfs;
603 	bool crc_enable;
604 	bool req_tx_splitq;
605 	bool req_rx_splitq;
606 
607 	struct mutex vport_ctrl_lock;
608 	struct mutex vector_lock;
609 	struct mutex queue_lock;
610 	struct mutex vc_buf_lock;
611 };
612 
613 /**
614  * idpf_is_queue_model_split - check if queue model is split
615  * @q_model: queue model single or split
616  *
617  * Returns true if queue model is split else false
618  */
idpf_is_queue_model_split(u16 q_model)619 static inline int idpf_is_queue_model_split(u16 q_model)
620 {
621 	return !IS_ENABLED(CONFIG_IDPF_SINGLEQ) ||
622 	       q_model == VIRTCHNL2_QUEUE_MODEL_SPLIT;
623 }
624 
625 #define idpf_is_cap_ena(adapter, field, flag) \
626 	idpf_is_capability_ena(adapter, false, field, flag)
627 #define idpf_is_cap_ena_all(adapter, field, flag) \
628 	idpf_is_capability_ena(adapter, true, field, flag)
629 
630 bool idpf_is_capability_ena(struct idpf_adapter *adapter, bool all,
631 			    enum idpf_cap_field field, u64 flag);
632 
633 #define IDPF_CAP_RSS (\
634 	VIRTCHNL2_CAP_RSS_IPV4_TCP	|\
635 	VIRTCHNL2_CAP_RSS_IPV4_TCP	|\
636 	VIRTCHNL2_CAP_RSS_IPV4_UDP	|\
637 	VIRTCHNL2_CAP_RSS_IPV4_SCTP	|\
638 	VIRTCHNL2_CAP_RSS_IPV4_OTHER	|\
639 	VIRTCHNL2_CAP_RSS_IPV6_TCP	|\
640 	VIRTCHNL2_CAP_RSS_IPV6_TCP	|\
641 	VIRTCHNL2_CAP_RSS_IPV6_UDP	|\
642 	VIRTCHNL2_CAP_RSS_IPV6_SCTP	|\
643 	VIRTCHNL2_CAP_RSS_IPV6_OTHER)
644 
645 #define IDPF_CAP_RSC (\
646 	VIRTCHNL2_CAP_RSC_IPV4_TCP	|\
647 	VIRTCHNL2_CAP_RSC_IPV6_TCP)
648 
649 #define IDPF_CAP_HSPLIT	(\
650 	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4	|\
651 	VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6)
652 
653 #define IDPF_CAP_TX_CSUM_L4V4 (\
654 	VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_TCP	|\
655 	VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_UDP)
656 
657 #define IDPF_CAP_TX_CSUM_L4V6 (\
658 	VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_TCP	|\
659 	VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_UDP)
660 
661 #define IDPF_CAP_RX_CSUM (\
662 	VIRTCHNL2_CAP_RX_CSUM_L3_IPV4		|\
663 	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP	|\
664 	VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP	|\
665 	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP	|\
666 	VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP)
667 
668 #define IDPF_CAP_TX_SCTP_CSUM (\
669 	VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP	|\
670 	VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP)
671 
672 #define IDPF_CAP_TUNNEL_TX_CSUM (\
673 	VIRTCHNL2_CAP_TX_CSUM_L3_SINGLE_TUNNEL	|\
674 	VIRTCHNL2_CAP_TX_CSUM_L4_SINGLE_TUNNEL)
675 
676 /**
677  * idpf_get_reserved_vecs - Get reserved vectors
678  * @adapter: private data struct
679  */
idpf_get_reserved_vecs(struct idpf_adapter * adapter)680 static inline u16 idpf_get_reserved_vecs(struct idpf_adapter *adapter)
681 {
682 	return le16_to_cpu(adapter->caps.num_allocated_vectors);
683 }
684 
685 /**
686  * idpf_get_default_vports - Get default number of vports
687  * @adapter: private data struct
688  */
idpf_get_default_vports(struct idpf_adapter * adapter)689 static inline u16 idpf_get_default_vports(struct idpf_adapter *adapter)
690 {
691 	return le16_to_cpu(adapter->caps.default_num_vports);
692 }
693 
694 /**
695  * idpf_get_max_vports - Get max number of vports
696  * @adapter: private data struct
697  */
idpf_get_max_vports(struct idpf_adapter * adapter)698 static inline u16 idpf_get_max_vports(struct idpf_adapter *adapter)
699 {
700 	return le16_to_cpu(adapter->caps.max_vports);
701 }
702 
703 /**
704  * idpf_get_max_tx_bufs - Get max scatter-gather buffers supported by the device
705  * @adapter: private data struct
706  */
idpf_get_max_tx_bufs(struct idpf_adapter * adapter)707 static inline unsigned int idpf_get_max_tx_bufs(struct idpf_adapter *adapter)
708 {
709 	return adapter->caps.max_sg_bufs_per_tx_pkt;
710 }
711 
712 /**
713  * idpf_get_min_tx_pkt_len - Get min packet length supported by the device
714  * @adapter: private data struct
715  */
idpf_get_min_tx_pkt_len(struct idpf_adapter * adapter)716 static inline u8 idpf_get_min_tx_pkt_len(struct idpf_adapter *adapter)
717 {
718 	u8 pkt_len = adapter->caps.min_sso_packet_len;
719 
720 	return pkt_len ? pkt_len : IDPF_TX_MIN_PKT_LEN;
721 }
722 
723 /**
724  * idpf_get_reg_addr - Get BAR0 register address
725  * @adapter: private data struct
726  * @reg_offset: register offset value
727  *
728  * Based on the register offset, return the actual BAR0 register address
729  */
idpf_get_reg_addr(struct idpf_adapter * adapter,resource_size_t reg_offset)730 static inline void __iomem *idpf_get_reg_addr(struct idpf_adapter *adapter,
731 					      resource_size_t reg_offset)
732 {
733 	return (void __iomem *)(adapter->hw.hw_addr + reg_offset);
734 }
735 
736 /**
737  * idpf_is_reset_detected - check if we were reset at some point
738  * @adapter: driver specific private structure
739  *
740  * Returns true if we are either in reset currently or were previously reset.
741  */
idpf_is_reset_detected(struct idpf_adapter * adapter)742 static inline bool idpf_is_reset_detected(struct idpf_adapter *adapter)
743 {
744 	if (!adapter->hw.arq)
745 		return true;
746 
747 	return !(readl(idpf_get_reg_addr(adapter, adapter->hw.arq->reg.len)) &
748 		 adapter->hw.arq->reg.len_mask);
749 }
750 
751 /**
752  * idpf_is_reset_in_prog - check if reset is in progress
753  * @adapter: driver specific private structure
754  *
755  * Returns true if hard reset is in progress, false otherwise
756  */
idpf_is_reset_in_prog(struct idpf_adapter * adapter)757 static inline bool idpf_is_reset_in_prog(struct idpf_adapter *adapter)
758 {
759 	return (test_bit(IDPF_HR_RESET_IN_PROG, adapter->flags) ||
760 		test_bit(IDPF_HR_FUNC_RESET, adapter->flags) ||
761 		test_bit(IDPF_HR_DRV_LOAD, adapter->flags));
762 }
763 
764 /**
765  * idpf_netdev_to_vport - get a vport handle from a netdev
766  * @netdev: network interface device structure
767  */
idpf_netdev_to_vport(struct net_device * netdev)768 static inline struct idpf_vport *idpf_netdev_to_vport(struct net_device *netdev)
769 {
770 	struct idpf_netdev_priv *np = netdev_priv(netdev);
771 
772 	return np->vport;
773 }
774 
775 /**
776  * idpf_netdev_to_adapter - Get adapter handle from a netdev
777  * @netdev: Network interface device structure
778  */
idpf_netdev_to_adapter(struct net_device * netdev)779 static inline struct idpf_adapter *idpf_netdev_to_adapter(struct net_device *netdev)
780 {
781 	struct idpf_netdev_priv *np = netdev_priv(netdev);
782 
783 	return np->adapter;
784 }
785 
786 /**
787  * idpf_is_feature_ena - Determine if a particular feature is enabled
788  * @vport: Vport to check
789  * @feature: Netdev flag to check
790  *
791  * Returns true or false if a particular feature is enabled.
792  */
idpf_is_feature_ena(const struct idpf_vport * vport,netdev_features_t feature)793 static inline bool idpf_is_feature_ena(const struct idpf_vport *vport,
794 				       netdev_features_t feature)
795 {
796 	return vport->netdev->features & feature;
797 }
798 
799 /**
800  * idpf_get_max_tx_hdr_size -- get the size of tx header
801  * @adapter: Driver specific private structure
802  */
idpf_get_max_tx_hdr_size(struct idpf_adapter * adapter)803 static inline u16 idpf_get_max_tx_hdr_size(struct idpf_adapter *adapter)
804 {
805 	return le16_to_cpu(adapter->caps.max_tx_hdr_size);
806 }
807 
808 /**
809  * idpf_vport_ctrl_lock - Acquire the vport control lock
810  * @netdev: Network interface device structure
811  *
812  * This lock should be used by non-datapath code to protect against vport
813  * destruction.
814  */
idpf_vport_ctrl_lock(struct net_device * netdev)815 static inline void idpf_vport_ctrl_lock(struct net_device *netdev)
816 {
817 	struct idpf_netdev_priv *np = netdev_priv(netdev);
818 
819 	mutex_lock(&np->adapter->vport_ctrl_lock);
820 }
821 
822 /**
823  * idpf_vport_ctrl_unlock - Release the vport control lock
824  * @netdev: Network interface device structure
825  */
idpf_vport_ctrl_unlock(struct net_device * netdev)826 static inline void idpf_vport_ctrl_unlock(struct net_device *netdev)
827 {
828 	struct idpf_netdev_priv *np = netdev_priv(netdev);
829 
830 	mutex_unlock(&np->adapter->vport_ctrl_lock);
831 }
832 
833 void idpf_statistics_task(struct work_struct *work);
834 void idpf_init_task(struct work_struct *work);
835 void idpf_service_task(struct work_struct *work);
836 void idpf_mbx_task(struct work_struct *work);
837 void idpf_vc_event_task(struct work_struct *work);
838 void idpf_dev_ops_init(struct idpf_adapter *adapter);
839 void idpf_vf_dev_ops_init(struct idpf_adapter *adapter);
840 int idpf_intr_req(struct idpf_adapter *adapter);
841 void idpf_intr_rel(struct idpf_adapter *adapter);
842 u16 idpf_get_max_tx_hdr_size(struct idpf_adapter *adapter);
843 int idpf_initiate_soft_reset(struct idpf_vport *vport,
844 			     enum idpf_vport_reset_cause reset_cause);
845 void idpf_deinit_task(struct idpf_adapter *adapter);
846 int idpf_req_rel_vector_indexes(struct idpf_adapter *adapter,
847 				u16 *q_vector_idxs,
848 				struct idpf_vector_info *vec_info);
849 void idpf_set_ethtool_ops(struct net_device *netdev);
850 void idpf_vport_intr_write_itr(struct idpf_q_vector *q_vector,
851 			       u16 itr, bool tx);
852 int idpf_sriov_configure(struct pci_dev *pdev, int num_vfs);
853 
854 u8 idpf_vport_get_hsplit(const struct idpf_vport *vport);
855 bool idpf_vport_set_hsplit(const struct idpf_vport *vport, u8 val);
856 
857 #endif /* !_IDPF_H_ */
858