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