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