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