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