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