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