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_vport_user_config_data - User defined configuration values for
374 * each vport.
375 * @rss_data: See struct idpf_rss_data
376 * @num_req_tx_qs: Number of user requested TX queues through ethtool
377 * @num_req_rx_qs: Number of user requested RX queues through ethtool
378 * @num_req_txq_desc: Number of user requested TX queue descriptors through
379 * ethtool
380 * @num_req_rxq_desc: Number of user requested RX queue descriptors through
381 * ethtool
382 * @user_flags: User toggled config flags
383 * @mac_filter_list: List of MAC filters
384 *
385 * Used to restore configuration after a reset as the vport will get wiped.
386 */
387 struct idpf_vport_user_config_data {
388 struct idpf_rss_data rss_data;
389 u16 num_req_tx_qs;
390 u16 num_req_rx_qs;
391 u32 num_req_txq_desc;
392 u32 num_req_rxq_desc;
393 DECLARE_BITMAP(user_flags, __IDPF_USER_FLAGS_NBITS);
394 struct list_head mac_filter_list;
395 };
396
397 /**
398 * enum idpf_vport_config_flags - Vport config flags
399 * @IDPF_VPORT_REG_NETDEV: Register netdev
400 * @IDPF_VPORT_UP_REQUESTED: Set if interface up is requested on core reset
401 * @IDPF_VPORT_CONFIG_FLAGS_NBITS: Must be last
402 */
403 enum idpf_vport_config_flags {
404 IDPF_VPORT_REG_NETDEV,
405 IDPF_VPORT_UP_REQUESTED,
406 IDPF_VPORT_CONFIG_FLAGS_NBITS,
407 };
408
409 /**
410 * struct idpf_avail_queue_info
411 * @avail_rxq: Available RX queues
412 * @avail_txq: Available TX queues
413 * @avail_bufq: Available buffer queues
414 * @avail_complq: Available completion queues
415 *
416 * Maintain total queues available after allocating max queues to each vport.
417 */
418 struct idpf_avail_queue_info {
419 u16 avail_rxq;
420 u16 avail_txq;
421 u16 avail_bufq;
422 u16 avail_complq;
423 };
424
425 /**
426 * struct idpf_vector_info - Utility structure to pass function arguments as a
427 * structure
428 * @num_req_vecs: Vectors required based on the number of queues updated by the
429 * user via ethtool
430 * @num_curr_vecs: Current number of vectors, must be >= @num_req_vecs
431 * @index: Relative starting index for vectors
432 * @default_vport: Vectors are for default vport
433 */
434 struct idpf_vector_info {
435 u16 num_req_vecs;
436 u16 num_curr_vecs;
437 u16 index;
438 bool default_vport;
439 };
440
441 /**
442 * struct idpf_vector_lifo - Stack to maintain vector indexes used for vector
443 * distribution algorithm
444 * @top: Points to stack top i.e. next available vector index
445 * @base: Always points to start of the free pool
446 * @size: Total size of the vector stack
447 * @vec_idx: Array to store all the vector indexes
448 *
449 * Vector stack maintains all the relative vector indexes at the *adapter*
450 * level. This stack is divided into 2 parts, first one is called as 'default
451 * pool' and other one is called 'free pool'. Vector distribution algorithm
452 * gives priority to default vports in a way that at least IDPF_MIN_Q_VEC
453 * vectors are allocated per default vport and the relative vector indexes for
454 * those are maintained in default pool. Free pool contains all the unallocated
455 * vector indexes which can be allocated on-demand basis. Mailbox vector index
456 * is maintained in the default pool of the stack.
457 */
458 struct idpf_vector_lifo {
459 u16 top;
460 u16 base;
461 u16 size;
462 u16 *vec_idx;
463 };
464
465 /**
466 * struct idpf_vport_config - Vport configuration data
467 * @user_config: see struct idpf_vport_user_config_data
468 * @max_q: Maximum possible queues
469 * @req_qs_chunks: Queue chunk data for requested queues
470 * @mac_filter_list_lock: Lock to protect mac filters
471 * @flags: See enum idpf_vport_config_flags
472 */
473 struct idpf_vport_config {
474 struct idpf_vport_user_config_data user_config;
475 struct idpf_vport_max_q max_q;
476 struct virtchnl2_add_queues *req_qs_chunks;
477 spinlock_t mac_filter_list_lock;
478 DECLARE_BITMAP(flags, IDPF_VPORT_CONFIG_FLAGS_NBITS);
479 };
480
481 struct idpf_vc_xn_manager;
482
483 /**
484 * struct idpf_adapter - Device data struct generated on probe
485 * @pdev: PCI device struct given on probe
486 * @virt_ver_maj: Virtchnl version major
487 * @virt_ver_min: Virtchnl version minor
488 * @msg_enable: Debug message level enabled
489 * @mb_wait_count: Number of times mailbox was attempted initialization
490 * @state: Init state machine
491 * @flags: See enum idpf_flags
492 * @reset_reg: See struct idpf_reset_reg
493 * @hw: Device access data
494 * @num_req_msix: Requested number of MSIX vectors
495 * @num_avail_msix: Available number of MSIX vectors
496 * @num_msix_entries: Number of entries in MSIX table
497 * @msix_entries: MSIX table
498 * @req_vec_chunks: Requested vector chunk data
499 * @mb_vector: Mailbox vector data
500 * @vector_stack: Stack to store the msix vector indexes
501 * @irq_mb_handler: Handler for hard interrupt for mailbox
502 * @tx_timeout_count: Number of TX timeouts that have occurred
503 * @avail_queues: Device given queue limits
504 * @vports: Array to store vports created by the driver
505 * @netdevs: Associated Vport netdevs
506 * @vport_params_reqd: Vport params requested
507 * @vport_params_recvd: Vport params received
508 * @vport_ids: Array of device given vport identifiers
509 * @vport_config: Vport config parameters
510 * @max_vports: Maximum vports that can be allocated
511 * @num_alloc_vports: Current number of vports allocated
512 * @next_vport: Next free slot in pf->vport[] - 0-based!
513 * @init_task: Initialization task
514 * @init_wq: Workqueue for initialization task
515 * @serv_task: Periodically recurring maintenance task
516 * @serv_wq: Workqueue for service task
517 * @mbx_task: Task to handle mailbox interrupts
518 * @mbx_wq: Workqueue for mailbox responses
519 * @vc_event_task: Task to handle out of band virtchnl event notifications
520 * @vc_event_wq: Workqueue for virtchnl events
521 * @stats_task: Periodic statistics retrieval task
522 * @stats_wq: Workqueue for statistics task
523 * @caps: Negotiated capabilities with device
524 * @vcxn_mngr: Virtchnl transaction manager
525 * @dev_ops: See idpf_dev_ops
526 * @num_vfs: Number of allocated VFs through sysfs. PF does not directly talk
527 * to VFs but is used to initialize them
528 * @crc_enable: Enable CRC insertion offload
529 * @req_tx_splitq: TX split or single queue model to request
530 * @req_rx_splitq: RX split or single queue model to request
531 * @vport_ctrl_lock: Lock to protect the vport control flow
532 * @vector_lock: Lock to protect vector distribution
533 * @queue_lock: Lock to protect queue distribution
534 * @vc_buf_lock: Lock to protect virtchnl buffer
535 */
536 struct idpf_adapter {
537 struct pci_dev *pdev;
538 u32 virt_ver_maj;
539 u32 virt_ver_min;
540
541 u32 msg_enable;
542 u32 mb_wait_count;
543 enum idpf_state state;
544 DECLARE_BITMAP(flags, IDPF_FLAGS_NBITS);
545 struct idpf_reset_reg reset_reg;
546 struct idpf_hw hw;
547 u16 num_req_msix;
548 u16 num_avail_msix;
549 u16 num_msix_entries;
550 struct msix_entry *msix_entries;
551 struct virtchnl2_alloc_vectors *req_vec_chunks;
552 struct idpf_q_vector mb_vector;
553 struct idpf_vector_lifo vector_stack;
554 irqreturn_t (*irq_mb_handler)(int irq, void *data);
555
556 u32 tx_timeout_count;
557 struct idpf_avail_queue_info avail_queues;
558 struct idpf_vport **vports;
559 struct net_device **netdevs;
560 struct virtchnl2_create_vport **vport_params_reqd;
561 struct virtchnl2_create_vport **vport_params_recvd;
562 u32 *vport_ids;
563
564 struct idpf_vport_config **vport_config;
565 u16 max_vports;
566 u16 num_alloc_vports;
567 u16 next_vport;
568
569 struct delayed_work init_task;
570 struct workqueue_struct *init_wq;
571 struct delayed_work serv_task;
572 struct workqueue_struct *serv_wq;
573 struct delayed_work mbx_task;
574 struct workqueue_struct *mbx_wq;
575 struct delayed_work vc_event_task;
576 struct workqueue_struct *vc_event_wq;
577 struct delayed_work stats_task;
578 struct workqueue_struct *stats_wq;
579 struct virtchnl2_get_capabilities caps;
580 struct idpf_vc_xn_manager *vcxn_mngr;
581
582 struct idpf_dev_ops dev_ops;
583 int num_vfs;
584 bool crc_enable;
585 bool req_tx_splitq;
586 bool req_rx_splitq;
587
588 struct mutex vport_ctrl_lock;
589 struct mutex vector_lock;
590 struct mutex queue_lock;
591 struct mutex vc_buf_lock;
592 };
593
594 /**
595 * idpf_is_queue_model_split - check if queue model is split
596 * @q_model: queue model single or split
597 *
598 * Returns true if queue model is split else false
599 */
idpf_is_queue_model_split(u16 q_model)600 static inline int idpf_is_queue_model_split(u16 q_model)
601 {
602 return !IS_ENABLED(CONFIG_IDPF_SINGLEQ) ||
603 q_model == VIRTCHNL2_QUEUE_MODEL_SPLIT;
604 }
605
606 #define idpf_is_cap_ena(adapter, field, flag) \
607 idpf_is_capability_ena(adapter, false, field, flag)
608 #define idpf_is_cap_ena_all(adapter, field, flag) \
609 idpf_is_capability_ena(adapter, true, field, flag)
610
611 bool idpf_is_capability_ena(struct idpf_adapter *adapter, bool all,
612 enum idpf_cap_field field, u64 flag);
613
614 #define IDPF_CAP_RSS (\
615 VIRTCHNL2_CAP_RSS_IPV4_TCP |\
616 VIRTCHNL2_CAP_RSS_IPV4_TCP |\
617 VIRTCHNL2_CAP_RSS_IPV4_UDP |\
618 VIRTCHNL2_CAP_RSS_IPV4_SCTP |\
619 VIRTCHNL2_CAP_RSS_IPV4_OTHER |\
620 VIRTCHNL2_CAP_RSS_IPV6_TCP |\
621 VIRTCHNL2_CAP_RSS_IPV6_TCP |\
622 VIRTCHNL2_CAP_RSS_IPV6_UDP |\
623 VIRTCHNL2_CAP_RSS_IPV6_SCTP |\
624 VIRTCHNL2_CAP_RSS_IPV6_OTHER)
625
626 #define IDPF_CAP_RSC (\
627 VIRTCHNL2_CAP_RSC_IPV4_TCP |\
628 VIRTCHNL2_CAP_RSC_IPV6_TCP)
629
630 #define IDPF_CAP_HSPLIT (\
631 VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 |\
632 VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6)
633
634 #define IDPF_CAP_TX_CSUM_L4V4 (\
635 VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_TCP |\
636 VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_UDP)
637
638 #define IDPF_CAP_TX_CSUM_L4V6 (\
639 VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_TCP |\
640 VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_UDP)
641
642 #define IDPF_CAP_RX_CSUM (\
643 VIRTCHNL2_CAP_RX_CSUM_L3_IPV4 |\
644 VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP |\
645 VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP |\
646 VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP |\
647 VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP)
648
649 #define IDPF_CAP_TX_SCTP_CSUM (\
650 VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP |\
651 VIRTCHNL2_CAP_TX_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