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.h> 19 #include <net/gro.h> 20 #include <linux/dim.h> 21 22 #include "virtchnl2.h" 23 #include "idpf_lan_txrx.h" 24 #include "idpf_txrx.h" 25 #include "idpf_controlq.h" 26 27 #define GETMAXVAL(num_bits) GENMASK((num_bits) - 1, 0) 28 29 #define IDPF_NO_FREE_SLOT 0xffff 30 31 /* Default Mailbox settings */ 32 #define IDPF_NUM_FILTERS_PER_MSG 20 33 #define IDPF_NUM_DFLT_MBX_Q 2 /* includes both TX and RX */ 34 #define IDPF_DFLT_MBX_Q_LEN 64 35 #define IDPF_DFLT_MBX_ID -1 36 /* maximum number of times to try before resetting mailbox */ 37 #define IDPF_MB_MAX_ERR 20 38 #define IDPF_NUM_CHUNKS_PER_MSG(struct_sz, chunk_sz) \ 39 ((IDPF_CTLQ_MAX_BUF_LEN - (struct_sz)) / (chunk_sz)) 40 #define IDPF_WAIT_FOR_EVENT_TIMEO_MIN 2000 41 #define IDPF_WAIT_FOR_EVENT_TIMEO 60000 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_STARTUP: Start the state machine 70 * @__IDPF_VER_CHECK: Negotiate virtchnl version 71 * @__IDPF_GET_CAPS: Negotiate capabilities 72 * @__IDPF_INIT_SW: Init based on given capabilities 73 * @__IDPF_STATE_LAST: Must be last, used to determine size 74 */ 75 enum idpf_state { 76 __IDPF_STARTUP, 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_FLAGS_NBITS: Must be last 91 */ 92 enum idpf_flags { 93 IDPF_HR_FUNC_RESET, 94 IDPF_HR_DRV_LOAD, 95 IDPF_HR_RESET_IN_PROG, 96 IDPF_REMOVE_IN_PROG, 97 IDPF_MB_INTR_MODE, 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 * @vport_idx: Relative vport index 149 * @state: See enum idpf_vport_state 150 * @netstats: Packet and byte stats 151 * @stats_lock: Lock to protect stats update 152 */ 153 struct idpf_netdev_priv { 154 struct idpf_adapter *adapter; 155 struct idpf_vport *vport; 156 u32 vport_id; 157 u16 vport_idx; 158 enum idpf_vport_state state; 159 struct rtnl_link_stats64 netstats; 160 spinlock_t stats_lock; 161 }; 162 163 /** 164 * struct idpf_reset_reg - Reset register offsets/masks 165 * @rstat: Reset status register 166 * @rstat_m: Reset status mask 167 */ 168 struct idpf_reset_reg { 169 void __iomem *rstat; 170 u32 rstat_m; 171 }; 172 173 /** 174 * struct idpf_vport_max_q - Queue limits 175 * @max_rxq: Maximum number of RX queues supported 176 * @max_txq: Maixmum number of TX queues supported 177 * @max_bufq: In splitq, maximum number of buffer queues supported 178 * @max_complq: In splitq, maximum number of completion queues supported 179 */ 180 struct idpf_vport_max_q { 181 u16 max_rxq; 182 u16 max_txq; 183 u16 max_bufq; 184 u16 max_complq; 185 }; 186 187 /** 188 * struct idpf_reg_ops - Device specific register operation function pointers 189 * @ctlq_reg_init: Mailbox control queue register initialization 190 * @intr_reg_init: Traffic interrupt register initialization 191 * @mb_intr_reg_init: Mailbox interrupt register initialization 192 * @reset_reg_init: Reset register initialization 193 * @trigger_reset: Trigger a reset to occur 194 */ 195 struct idpf_reg_ops { 196 void (*ctlq_reg_init)(struct idpf_ctlq_create_info *cq); 197 int (*intr_reg_init)(struct idpf_vport *vport); 198 void (*mb_intr_reg_init)(struct idpf_adapter *adapter); 199 void (*reset_reg_init)(struct idpf_adapter *adapter); 200 void (*trigger_reset)(struct idpf_adapter *adapter, 201 enum idpf_flags trig_cause); 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 /* These macros allow us to generate an enum and a matching char * array of 213 * stringified enums that are always in sync. Checkpatch issues a bogus warning 214 * about this being a complex macro; but it's wrong, these are never used as a 215 * statement and instead only used to define the enum and array. 216 */ 217 #define IDPF_FOREACH_VPORT_VC_STATE(STATE) \ 218 STATE(IDPF_VC_CREATE_VPORT) \ 219 STATE(IDPF_VC_CREATE_VPORT_ERR) \ 220 STATE(IDPF_VC_ENA_VPORT) \ 221 STATE(IDPF_VC_ENA_VPORT_ERR) \ 222 STATE(IDPF_VC_DIS_VPORT) \ 223 STATE(IDPF_VC_DIS_VPORT_ERR) \ 224 STATE(IDPF_VC_DESTROY_VPORT) \ 225 STATE(IDPF_VC_DESTROY_VPORT_ERR) \ 226 STATE(IDPF_VC_CONFIG_TXQ) \ 227 STATE(IDPF_VC_CONFIG_TXQ_ERR) \ 228 STATE(IDPF_VC_CONFIG_RXQ) \ 229 STATE(IDPF_VC_CONFIG_RXQ_ERR) \ 230 STATE(IDPF_VC_ENA_QUEUES) \ 231 STATE(IDPF_VC_ENA_QUEUES_ERR) \ 232 STATE(IDPF_VC_DIS_QUEUES) \ 233 STATE(IDPF_VC_DIS_QUEUES_ERR) \ 234 STATE(IDPF_VC_MAP_IRQ) \ 235 STATE(IDPF_VC_MAP_IRQ_ERR) \ 236 STATE(IDPF_VC_UNMAP_IRQ) \ 237 STATE(IDPF_VC_UNMAP_IRQ_ERR) \ 238 STATE(IDPF_VC_ADD_QUEUES) \ 239 STATE(IDPF_VC_ADD_QUEUES_ERR) \ 240 STATE(IDPF_VC_DEL_QUEUES) \ 241 STATE(IDPF_VC_DEL_QUEUES_ERR) \ 242 STATE(IDPF_VC_ALLOC_VECTORS) \ 243 STATE(IDPF_VC_ALLOC_VECTORS_ERR) \ 244 STATE(IDPF_VC_DEALLOC_VECTORS) \ 245 STATE(IDPF_VC_DEALLOC_VECTORS_ERR) \ 246 STATE(IDPF_VC_SET_SRIOV_VFS) \ 247 STATE(IDPF_VC_SET_SRIOV_VFS_ERR) \ 248 STATE(IDPF_VC_GET_RSS_LUT) \ 249 STATE(IDPF_VC_GET_RSS_LUT_ERR) \ 250 STATE(IDPF_VC_SET_RSS_LUT) \ 251 STATE(IDPF_VC_SET_RSS_LUT_ERR) \ 252 STATE(IDPF_VC_GET_RSS_KEY) \ 253 STATE(IDPF_VC_GET_RSS_KEY_ERR) \ 254 STATE(IDPF_VC_SET_RSS_KEY) \ 255 STATE(IDPF_VC_SET_RSS_KEY_ERR) \ 256 STATE(IDPF_VC_GET_STATS) \ 257 STATE(IDPF_VC_GET_STATS_ERR) \ 258 STATE(IDPF_VC_ADD_MAC_ADDR) \ 259 STATE(IDPF_VC_ADD_MAC_ADDR_ERR) \ 260 STATE(IDPF_VC_DEL_MAC_ADDR) \ 261 STATE(IDPF_VC_DEL_MAC_ADDR_ERR) \ 262 STATE(IDPF_VC_GET_PTYPE_INFO) \ 263 STATE(IDPF_VC_GET_PTYPE_INFO_ERR) \ 264 STATE(IDPF_VC_LOOPBACK_STATE) \ 265 STATE(IDPF_VC_LOOPBACK_STATE_ERR) \ 266 STATE(IDPF_VC_NBITS) 267 268 #define IDPF_GEN_ENUM(ENUM) ENUM, 269 #define IDPF_GEN_STRING(STRING) #STRING, 270 271 enum idpf_vport_vc_state { 272 IDPF_FOREACH_VPORT_VC_STATE(IDPF_GEN_ENUM) 273 }; 274 275 extern const char * const idpf_vport_vc_state_str[]; 276 277 /** 278 * enum idpf_vport_reset_cause - Vport soft reset causes 279 * @IDPF_SR_Q_CHANGE: Soft reset queue change 280 * @IDPF_SR_Q_DESC_CHANGE: Soft reset descriptor change 281 * @IDPF_SR_MTU_CHANGE: Soft reset MTU change 282 * @IDPF_SR_RSC_CHANGE: Soft reset RSC change 283 */ 284 enum idpf_vport_reset_cause { 285 IDPF_SR_Q_CHANGE, 286 IDPF_SR_Q_DESC_CHANGE, 287 IDPF_SR_MTU_CHANGE, 288 IDPF_SR_RSC_CHANGE, 289 }; 290 291 /** 292 * enum idpf_vport_flags - Vport flags 293 * @IDPF_VPORT_DEL_QUEUES: To send delete queues message 294 * @IDPF_VPORT_SW_MARKER: Indicate TX pipe drain software marker packets 295 * processing is done 296 * @IDPF_VPORT_FLAGS_NBITS: Must be last 297 */ 298 enum idpf_vport_flags { 299 IDPF_VPORT_DEL_QUEUES, 300 IDPF_VPORT_SW_MARKER, 301 IDPF_VPORT_FLAGS_NBITS, 302 }; 303 304 struct idpf_port_stats { 305 struct u64_stats_sync stats_sync; 306 u64_stats_t rx_hw_csum_err; 307 u64_stats_t rx_hsplit; 308 u64_stats_t rx_hsplit_hbo; 309 u64_stats_t rx_bad_descs; 310 u64_stats_t tx_linearize; 311 u64_stats_t tx_busy; 312 u64_stats_t tx_drops; 313 u64_stats_t tx_dma_map_errs; 314 struct virtchnl2_vport_stats vport_stats; 315 }; 316 317 /** 318 * struct idpf_vport - Handle for netdevices and queue resources 319 * @num_txq: Number of allocated TX queues 320 * @num_complq: Number of allocated completion queues 321 * @txq_desc_count: TX queue descriptor count 322 * @complq_desc_count: Completion queue descriptor count 323 * @compln_clean_budget: Work budget for completion clean 324 * @num_txq_grp: Number of TX queue groups 325 * @txq_grps: Array of TX queue groups 326 * @txq_model: Split queue or single queue queuing model 327 * @txqs: Used only in hotpath to get to the right queue very fast 328 * @crc_enable: Enable CRC insertion offload 329 * @num_rxq: Number of allocated RX queues 330 * @num_bufq: Number of allocated buffer queues 331 * @rxq_desc_count: RX queue descriptor count. *MUST* have enough descriptors 332 * to complete all buffer descriptors for all buffer queues in 333 * the worst case. 334 * @num_bufqs_per_qgrp: Buffer queues per RX queue in a given grouping 335 * @bufq_desc_count: Buffer queue descriptor count 336 * @bufq_size: Size of buffers in ring (e.g. 2K, 4K, etc) 337 * @num_rxq_grp: Number of RX queues in a group 338 * @rxq_grps: Total number of RX groups. Number of groups * number of RX per 339 * group will yield total number of RX queues. 340 * @rxq_model: Splitq queue or single queue queuing model 341 * @rx_ptype_lkup: Lookup table for ptypes on RX 342 * @adapter: back pointer to associated adapter 343 * @netdev: Associated net_device. Each vport should have one and only one 344 * associated netdev. 345 * @flags: See enum idpf_vport_flags 346 * @vport_type: Default SRIOV, SIOV, etc. 347 * @vport_id: Device given vport identifier 348 * @idx: Software index in adapter vports struct 349 * @default_vport: Use this vport if one isn't specified 350 * @base_rxd: True if the driver should use base descriptors instead of flex 351 * @num_q_vectors: Number of IRQ vectors allocated 352 * @q_vectors: Array of queue vectors 353 * @q_vector_idxs: Starting index of queue vectors 354 * @max_mtu: device given max possible MTU 355 * @default_mac_addr: device will give a default MAC to use 356 * @rx_itr_profile: RX profiles for Dynamic Interrupt Moderation 357 * @tx_itr_profile: TX profiles for Dynamic Interrupt Moderation 358 * @port_stats: per port csum, header split, and other offload stats 359 * @link_up: True if link is up 360 * @link_speed_mbps: Link speed in mbps 361 * @vc_msg: Virtchnl message buffer 362 * @vc_state: Virtchnl message state 363 * @vchnl_wq: Wait queue for virtchnl messages 364 * @sw_marker_wq: workqueue for marker packets 365 * @vc_buf_lock: Lock to protect virtchnl buffer 366 */ 367 struct idpf_vport { 368 u16 num_txq; 369 u16 num_complq; 370 u32 txq_desc_count; 371 u32 complq_desc_count; 372 u32 compln_clean_budget; 373 u16 num_txq_grp; 374 struct idpf_txq_group *txq_grps; 375 u32 txq_model; 376 struct idpf_queue **txqs; 377 bool crc_enable; 378 379 u16 num_rxq; 380 u16 num_bufq; 381 u32 rxq_desc_count; 382 u8 num_bufqs_per_qgrp; 383 u32 bufq_desc_count[IDPF_MAX_BUFQS_PER_RXQ_GRP]; 384 u32 bufq_size[IDPF_MAX_BUFQS_PER_RXQ_GRP]; 385 u16 num_rxq_grp; 386 struct idpf_rxq_group *rxq_grps; 387 u32 rxq_model; 388 struct idpf_rx_ptype_decoded rx_ptype_lkup[IDPF_RX_MAX_PTYPE]; 389 390 struct idpf_adapter *adapter; 391 struct net_device *netdev; 392 DECLARE_BITMAP(flags, IDPF_VPORT_FLAGS_NBITS); 393 u16 vport_type; 394 u32 vport_id; 395 u16 idx; 396 bool default_vport; 397 bool base_rxd; 398 399 u16 num_q_vectors; 400 struct idpf_q_vector *q_vectors; 401 u16 *q_vector_idxs; 402 u16 max_mtu; 403 u8 default_mac_addr[ETH_ALEN]; 404 u16 rx_itr_profile[IDPF_DIM_PROFILE_SLOTS]; 405 u16 tx_itr_profile[IDPF_DIM_PROFILE_SLOTS]; 406 struct idpf_port_stats port_stats; 407 408 bool link_up; 409 u32 link_speed_mbps; 410 411 char vc_msg[IDPF_CTLQ_MAX_BUF_LEN]; 412 DECLARE_BITMAP(vc_state, IDPF_VC_NBITS); 413 414 wait_queue_head_t vchnl_wq; 415 wait_queue_head_t sw_marker_wq; 416 struct mutex vc_buf_lock; 417 }; 418 419 /** 420 * enum idpf_user_flags 421 * @__IDPF_PROMISC_UC: Unicast promiscuous mode 422 * @__IDPF_PROMISC_MC: Multicast promiscuous mode 423 * @__IDPF_USER_FLAGS_NBITS: Must be last 424 */ 425 enum idpf_user_flags { 426 __IDPF_PROMISC_UC = 32, 427 __IDPF_PROMISC_MC, 428 429 __IDPF_USER_FLAGS_NBITS, 430 }; 431 432 /** 433 * struct idpf_rss_data - Associated RSS data 434 * @rss_key_size: Size of RSS hash key 435 * @rss_key: RSS hash key 436 * @rss_lut_size: Size of RSS lookup table 437 * @rss_lut: RSS lookup table 438 * @cached_lut: Used to restore previously init RSS lut 439 */ 440 struct idpf_rss_data { 441 u16 rss_key_size; 442 u8 *rss_key; 443 u16 rss_lut_size; 444 u32 *rss_lut; 445 u32 *cached_lut; 446 }; 447 448 /** 449 * struct idpf_vport_user_config_data - User defined configuration values for 450 * each vport. 451 * @rss_data: See struct idpf_rss_data 452 * @num_req_tx_qs: Number of user requested TX queues through ethtool 453 * @num_req_rx_qs: Number of user requested RX queues through ethtool 454 * @num_req_txq_desc: Number of user requested TX queue descriptors through 455 * ethtool 456 * @num_req_rxq_desc: Number of user requested RX queue descriptors through 457 * ethtool 458 * @user_flags: User toggled config flags 459 * @mac_filter_list: List of MAC filters 460 * 461 * Used to restore configuration after a reset as the vport will get wiped. 462 */ 463 struct idpf_vport_user_config_data { 464 struct idpf_rss_data rss_data; 465 u16 num_req_tx_qs; 466 u16 num_req_rx_qs; 467 u32 num_req_txq_desc; 468 u32 num_req_rxq_desc; 469 DECLARE_BITMAP(user_flags, __IDPF_USER_FLAGS_NBITS); 470 struct list_head mac_filter_list; 471 }; 472 473 /** 474 * enum idpf_vport_config_flags - Vport config flags 475 * @IDPF_VPORT_REG_NETDEV: Register netdev 476 * @IDPF_VPORT_UP_REQUESTED: Set if interface up is requested on core reset 477 * @IDPF_VPORT_ADD_MAC_REQ: Asynchronous add ether address in flight 478 * @IDPF_VPORT_DEL_MAC_REQ: Asynchronous delete ether address in flight 479 * @IDPF_VPORT_CONFIG_FLAGS_NBITS: Must be last 480 */ 481 enum idpf_vport_config_flags { 482 IDPF_VPORT_REG_NETDEV, 483 IDPF_VPORT_UP_REQUESTED, 484 IDPF_VPORT_ADD_MAC_REQ, 485 IDPF_VPORT_DEL_MAC_REQ, 486 IDPF_VPORT_CONFIG_FLAGS_NBITS, 487 }; 488 489 /** 490 * struct idpf_avail_queue_info 491 * @avail_rxq: Available RX queues 492 * @avail_txq: Available TX queues 493 * @avail_bufq: Available buffer queues 494 * @avail_complq: Available completion queues 495 * 496 * Maintain total queues available after allocating max queues to each vport. 497 */ 498 struct idpf_avail_queue_info { 499 u16 avail_rxq; 500 u16 avail_txq; 501 u16 avail_bufq; 502 u16 avail_complq; 503 }; 504 505 /** 506 * struct idpf_vector_info - Utility structure to pass function arguments as a 507 * structure 508 * @num_req_vecs: Vectors required based on the number of queues updated by the 509 * user via ethtool 510 * @num_curr_vecs: Current number of vectors, must be >= @num_req_vecs 511 * @index: Relative starting index for vectors 512 * @default_vport: Vectors are for default vport 513 */ 514 struct idpf_vector_info { 515 u16 num_req_vecs; 516 u16 num_curr_vecs; 517 u16 index; 518 bool default_vport; 519 }; 520 521 /** 522 * struct idpf_vector_lifo - Stack to maintain vector indexes used for vector 523 * distribution algorithm 524 * @top: Points to stack top i.e. next available vector index 525 * @base: Always points to start of the free pool 526 * @size: Total size of the vector stack 527 * @vec_idx: Array to store all the vector indexes 528 * 529 * Vector stack maintains all the relative vector indexes at the *adapter* 530 * level. This stack is divided into 2 parts, first one is called as 'default 531 * pool' and other one is called 'free pool'. Vector distribution algorithm 532 * gives priority to default vports in a way that at least IDPF_MIN_Q_VEC 533 * vectors are allocated per default vport and the relative vector indexes for 534 * those are maintained in default pool. Free pool contains all the unallocated 535 * vector indexes which can be allocated on-demand basis. Mailbox vector index 536 * is maintained in the default pool of the stack. 537 */ 538 struct idpf_vector_lifo { 539 u16 top; 540 u16 base; 541 u16 size; 542 u16 *vec_idx; 543 }; 544 545 /** 546 * struct idpf_vport_config - Vport configuration data 547 * @user_config: see struct idpf_vport_user_config_data 548 * @max_q: Maximum possible queues 549 * @req_qs_chunks: Queue chunk data for requested queues 550 * @mac_filter_list_lock: Lock to protect mac filters 551 * @flags: See enum idpf_vport_config_flags 552 */ 553 struct idpf_vport_config { 554 struct idpf_vport_user_config_data user_config; 555 struct idpf_vport_max_q max_q; 556 void *req_qs_chunks; 557 spinlock_t mac_filter_list_lock; 558 DECLARE_BITMAP(flags, IDPF_VPORT_CONFIG_FLAGS_NBITS); 559 }; 560 561 /** 562 * struct idpf_adapter - Device data struct generated on probe 563 * @pdev: PCI device struct given on probe 564 * @virt_ver_maj: Virtchnl version major 565 * @virt_ver_min: Virtchnl version minor 566 * @msg_enable: Debug message level enabled 567 * @mb_wait_count: Number of times mailbox was attempted initialization 568 * @state: Init state machine 569 * @flags: See enum idpf_flags 570 * @reset_reg: See struct idpf_reset_reg 571 * @hw: Device access data 572 * @num_req_msix: Requested number of MSIX vectors 573 * @num_avail_msix: Available number of MSIX vectors 574 * @num_msix_entries: Number of entries in MSIX table 575 * @msix_entries: MSIX table 576 * @req_vec_chunks: Requested vector chunk data 577 * @mb_vector: Mailbox vector data 578 * @vector_stack: Stack to store the msix vector indexes 579 * @irq_mb_handler: Handler for hard interrupt for mailbox 580 * @tx_timeout_count: Number of TX timeouts that have occurred 581 * @avail_queues: Device given queue limits 582 * @vports: Array to store vports created by the driver 583 * @netdevs: Associated Vport netdevs 584 * @vport_params_reqd: Vport params requested 585 * @vport_params_recvd: Vport params received 586 * @vport_ids: Array of device given vport identifiers 587 * @vport_config: Vport config parameters 588 * @max_vports: Maximum vports that can be allocated 589 * @num_alloc_vports: Current number of vports allocated 590 * @next_vport: Next free slot in pf->vport[] - 0-based! 591 * @init_task: Initialization task 592 * @init_wq: Workqueue for initialization task 593 * @serv_task: Periodically recurring maintenance task 594 * @serv_wq: Workqueue for service task 595 * @mbx_task: Task to handle mailbox interrupts 596 * @mbx_wq: Workqueue for mailbox responses 597 * @vc_event_task: Task to handle out of band virtchnl event notifications 598 * @vc_event_wq: Workqueue for virtchnl events 599 * @stats_task: Periodic statistics retrieval task 600 * @stats_wq: Workqueue for statistics task 601 * @caps: Negotiated capabilities with device 602 * @vchnl_wq: Wait queue for virtchnl messages 603 * @vc_state: Virtchnl message state 604 * @vc_msg: Virtchnl message buffer 605 * @dev_ops: See idpf_dev_ops 606 * @num_vfs: Number of allocated VFs through sysfs. PF does not directly talk 607 * to VFs but is used to initialize them 608 * @crc_enable: Enable CRC insertion offload 609 * @req_tx_splitq: TX split or single queue model to request 610 * @req_rx_splitq: RX split or single queue model to request 611 * @vport_ctrl_lock: Lock to protect the vport control flow 612 * @vector_lock: Lock to protect vector distribution 613 * @queue_lock: Lock to protect queue distribution 614 * @vc_buf_lock: Lock to protect virtchnl buffer 615 */ 616 struct idpf_adapter { 617 struct pci_dev *pdev; 618 u32 virt_ver_maj; 619 u32 virt_ver_min; 620 621 u32 msg_enable; 622 u32 mb_wait_count; 623 enum idpf_state state; 624 DECLARE_BITMAP(flags, IDPF_FLAGS_NBITS); 625 struct idpf_reset_reg reset_reg; 626 struct idpf_hw hw; 627 u16 num_req_msix; 628 u16 num_avail_msix; 629 u16 num_msix_entries; 630 struct msix_entry *msix_entries; 631 struct virtchnl2_alloc_vectors *req_vec_chunks; 632 struct idpf_q_vector mb_vector; 633 struct idpf_vector_lifo vector_stack; 634 irqreturn_t (*irq_mb_handler)(int irq, void *data); 635 636 u32 tx_timeout_count; 637 struct idpf_avail_queue_info avail_queues; 638 struct idpf_vport **vports; 639 struct net_device **netdevs; 640 struct virtchnl2_create_vport **vport_params_reqd; 641 struct virtchnl2_create_vport **vport_params_recvd; 642 u32 *vport_ids; 643 644 struct idpf_vport_config **vport_config; 645 u16 max_vports; 646 u16 num_alloc_vports; 647 u16 next_vport; 648 649 struct delayed_work init_task; 650 struct workqueue_struct *init_wq; 651 struct delayed_work serv_task; 652 struct workqueue_struct *serv_wq; 653 struct delayed_work mbx_task; 654 struct workqueue_struct *mbx_wq; 655 struct delayed_work vc_event_task; 656 struct workqueue_struct *vc_event_wq; 657 struct delayed_work stats_task; 658 struct workqueue_struct *stats_wq; 659 struct virtchnl2_get_capabilities caps; 660 661 wait_queue_head_t vchnl_wq; 662 DECLARE_BITMAP(vc_state, IDPF_VC_NBITS); 663 char vc_msg[IDPF_CTLQ_MAX_BUF_LEN]; 664 struct idpf_dev_ops dev_ops; 665 int num_vfs; 666 bool crc_enable; 667 bool req_tx_splitq; 668 bool req_rx_splitq; 669 670 struct mutex vport_ctrl_lock; 671 struct mutex vector_lock; 672 struct mutex queue_lock; 673 struct mutex vc_buf_lock; 674 }; 675 676 /** 677 * idpf_is_queue_model_split - check if queue model is split 678 * @q_model: queue model single or split 679 * 680 * Returns true if queue model is split else false 681 */ 682 static inline int idpf_is_queue_model_split(u16 q_model) 683 { 684 return q_model == VIRTCHNL2_QUEUE_MODEL_SPLIT; 685 } 686 687 #define idpf_is_cap_ena(adapter, field, flag) \ 688 idpf_is_capability_ena(adapter, false, field, flag) 689 #define idpf_is_cap_ena_all(adapter, field, flag) \ 690 idpf_is_capability_ena(adapter, true, field, flag) 691 692 bool idpf_is_capability_ena(struct idpf_adapter *adapter, bool all, 693 enum idpf_cap_field field, u64 flag); 694 695 #define IDPF_CAP_RSS (\ 696 VIRTCHNL2_CAP_RSS_IPV4_TCP |\ 697 VIRTCHNL2_CAP_RSS_IPV4_TCP |\ 698 VIRTCHNL2_CAP_RSS_IPV4_UDP |\ 699 VIRTCHNL2_CAP_RSS_IPV4_SCTP |\ 700 VIRTCHNL2_CAP_RSS_IPV4_OTHER |\ 701 VIRTCHNL2_CAP_RSS_IPV6_TCP |\ 702 VIRTCHNL2_CAP_RSS_IPV6_TCP |\ 703 VIRTCHNL2_CAP_RSS_IPV6_UDP |\ 704 VIRTCHNL2_CAP_RSS_IPV6_SCTP |\ 705 VIRTCHNL2_CAP_RSS_IPV6_OTHER) 706 707 #define IDPF_CAP_RSC (\ 708 VIRTCHNL2_CAP_RSC_IPV4_TCP |\ 709 VIRTCHNL2_CAP_RSC_IPV6_TCP) 710 711 #define IDPF_CAP_HSPLIT (\ 712 VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 |\ 713 VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6) 714 715 #define IDPF_CAP_RX_CSUM_L4V4 (\ 716 VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP |\ 717 VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP) 718 719 #define IDPF_CAP_RX_CSUM_L4V6 (\ 720 VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP |\ 721 VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP) 722 723 #define IDPF_CAP_RX_CSUM (\ 724 VIRTCHNL2_CAP_RX_CSUM_L3_IPV4 |\ 725 VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP |\ 726 VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP |\ 727 VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP |\ 728 VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP) 729 730 #define IDPF_CAP_SCTP_CSUM (\ 731 VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP |\ 732 VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP |\ 733 VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP |\ 734 VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP) 735 736 #define IDPF_CAP_TUNNEL_TX_CSUM (\ 737 VIRTCHNL2_CAP_TX_CSUM_L3_SINGLE_TUNNEL |\ 738 VIRTCHNL2_CAP_TX_CSUM_L4_SINGLE_TUNNEL) 739 740 /** 741 * idpf_get_reserved_vecs - Get reserved vectors 742 * @adapter: private data struct 743 */ 744 static inline u16 idpf_get_reserved_vecs(struct idpf_adapter *adapter) 745 { 746 return le16_to_cpu(adapter->caps.num_allocated_vectors); 747 } 748 749 /** 750 * idpf_get_default_vports - Get default number of vports 751 * @adapter: private data struct 752 */ 753 static inline u16 idpf_get_default_vports(struct idpf_adapter *adapter) 754 { 755 return le16_to_cpu(adapter->caps.default_num_vports); 756 } 757 758 /** 759 * idpf_get_max_vports - Get max number of vports 760 * @adapter: private data struct 761 */ 762 static inline u16 idpf_get_max_vports(struct idpf_adapter *adapter) 763 { 764 return le16_to_cpu(adapter->caps.max_vports); 765 } 766 767 /** 768 * idpf_get_max_tx_bufs - Get max scatter-gather buffers supported by the device 769 * @adapter: private data struct 770 */ 771 static inline unsigned int idpf_get_max_tx_bufs(struct idpf_adapter *adapter) 772 { 773 return adapter->caps.max_sg_bufs_per_tx_pkt; 774 } 775 776 /** 777 * idpf_get_min_tx_pkt_len - Get min packet length supported by the device 778 * @adapter: private data struct 779 */ 780 static inline u8 idpf_get_min_tx_pkt_len(struct idpf_adapter *adapter) 781 { 782 u8 pkt_len = adapter->caps.min_sso_packet_len; 783 784 return pkt_len ? pkt_len : IDPF_TX_MIN_PKT_LEN; 785 } 786 787 /** 788 * idpf_get_reg_addr - Get BAR0 register address 789 * @adapter: private data struct 790 * @reg_offset: register offset value 791 * 792 * Based on the register offset, return the actual BAR0 register address 793 */ 794 static inline void __iomem *idpf_get_reg_addr(struct idpf_adapter *adapter, 795 resource_size_t reg_offset) 796 { 797 return (void __iomem *)(adapter->hw.hw_addr + reg_offset); 798 } 799 800 /** 801 * idpf_is_reset_detected - check if we were reset at some point 802 * @adapter: driver specific private structure 803 * 804 * Returns true if we are either in reset currently or were previously reset. 805 */ 806 static inline bool idpf_is_reset_detected(struct idpf_adapter *adapter) 807 { 808 if (!adapter->hw.arq) 809 return true; 810 811 return !(readl(idpf_get_reg_addr(adapter, adapter->hw.arq->reg.len)) & 812 adapter->hw.arq->reg.len_mask); 813 } 814 815 /** 816 * idpf_is_reset_in_prog - check if reset is in progress 817 * @adapter: driver specific private structure 818 * 819 * Returns true if hard reset is in progress, false otherwise 820 */ 821 static inline bool idpf_is_reset_in_prog(struct idpf_adapter *adapter) 822 { 823 return (test_bit(IDPF_HR_RESET_IN_PROG, adapter->flags) || 824 test_bit(IDPF_HR_FUNC_RESET, adapter->flags) || 825 test_bit(IDPF_HR_DRV_LOAD, adapter->flags)); 826 } 827 828 /** 829 * idpf_netdev_to_vport - get a vport handle from a netdev 830 * @netdev: network interface device structure 831 */ 832 static inline struct idpf_vport *idpf_netdev_to_vport(struct net_device *netdev) 833 { 834 struct idpf_netdev_priv *np = netdev_priv(netdev); 835 836 return np->vport; 837 } 838 839 /** 840 * idpf_netdev_to_adapter - Get adapter handle from a netdev 841 * @netdev: Network interface device structure 842 */ 843 static inline struct idpf_adapter *idpf_netdev_to_adapter(struct net_device *netdev) 844 { 845 struct idpf_netdev_priv *np = netdev_priv(netdev); 846 847 return np->adapter; 848 } 849 850 /** 851 * idpf_is_feature_ena - Determine if a particular feature is enabled 852 * @vport: Vport to check 853 * @feature: Netdev flag to check 854 * 855 * Returns true or false if a particular feature is enabled. 856 */ 857 static inline bool idpf_is_feature_ena(const struct idpf_vport *vport, 858 netdev_features_t feature) 859 { 860 return vport->netdev->features & feature; 861 } 862 863 /** 864 * idpf_get_max_tx_hdr_size -- get the size of tx header 865 * @adapter: Driver specific private structure 866 */ 867 static inline u16 idpf_get_max_tx_hdr_size(struct idpf_adapter *adapter) 868 { 869 return le16_to_cpu(adapter->caps.max_tx_hdr_size); 870 } 871 872 /** 873 * idpf_vport_ctrl_lock - Acquire the vport control lock 874 * @netdev: Network interface device structure 875 * 876 * This lock should be used by non-datapath code to protect against vport 877 * destruction. 878 */ 879 static inline void idpf_vport_ctrl_lock(struct net_device *netdev) 880 { 881 struct idpf_netdev_priv *np = netdev_priv(netdev); 882 883 mutex_lock(&np->adapter->vport_ctrl_lock); 884 } 885 886 /** 887 * idpf_vport_ctrl_unlock - Release the vport control lock 888 * @netdev: Network interface device structure 889 */ 890 static inline void idpf_vport_ctrl_unlock(struct net_device *netdev) 891 { 892 struct idpf_netdev_priv *np = netdev_priv(netdev); 893 894 mutex_unlock(&np->adapter->vport_ctrl_lock); 895 } 896 897 void idpf_statistics_task(struct work_struct *work); 898 void idpf_init_task(struct work_struct *work); 899 void idpf_service_task(struct work_struct *work); 900 void idpf_mbx_task(struct work_struct *work); 901 void idpf_vc_event_task(struct work_struct *work); 902 void idpf_dev_ops_init(struct idpf_adapter *adapter); 903 void idpf_vf_dev_ops_init(struct idpf_adapter *adapter); 904 int idpf_vport_adjust_qs(struct idpf_vport *vport); 905 int idpf_init_dflt_mbx(struct idpf_adapter *adapter); 906 void idpf_deinit_dflt_mbx(struct idpf_adapter *adapter); 907 int idpf_vc_core_init(struct idpf_adapter *adapter); 908 void idpf_vc_core_deinit(struct idpf_adapter *adapter); 909 int idpf_intr_req(struct idpf_adapter *adapter); 910 void idpf_intr_rel(struct idpf_adapter *adapter); 911 int idpf_get_reg_intr_vecs(struct idpf_vport *vport, 912 struct idpf_vec_regs *reg_vals); 913 u16 idpf_get_max_tx_hdr_size(struct idpf_adapter *adapter); 914 int idpf_send_delete_queues_msg(struct idpf_vport *vport); 915 int idpf_send_add_queues_msg(const struct idpf_vport *vport, u16 num_tx_q, 916 u16 num_complq, u16 num_rx_q, u16 num_rx_bufq); 917 int idpf_initiate_soft_reset(struct idpf_vport *vport, 918 enum idpf_vport_reset_cause reset_cause); 919 int idpf_send_enable_vport_msg(struct idpf_vport *vport); 920 int idpf_send_disable_vport_msg(struct idpf_vport *vport); 921 int idpf_send_destroy_vport_msg(struct idpf_vport *vport); 922 int idpf_send_get_rx_ptype_msg(struct idpf_vport *vport); 923 int idpf_send_ena_dis_loopback_msg(struct idpf_vport *vport); 924 int idpf_send_get_set_rss_key_msg(struct idpf_vport *vport, bool get); 925 int idpf_send_get_set_rss_lut_msg(struct idpf_vport *vport, bool get); 926 int idpf_send_dealloc_vectors_msg(struct idpf_adapter *adapter); 927 int idpf_send_alloc_vectors_msg(struct idpf_adapter *adapter, u16 num_vectors); 928 void idpf_deinit_task(struct idpf_adapter *adapter); 929 int idpf_req_rel_vector_indexes(struct idpf_adapter *adapter, 930 u16 *q_vector_idxs, 931 struct idpf_vector_info *vec_info); 932 int idpf_vport_alloc_vec_indexes(struct idpf_vport *vport); 933 int idpf_send_get_stats_msg(struct idpf_vport *vport); 934 int idpf_get_vec_ids(struct idpf_adapter *adapter, 935 u16 *vecids, int num_vecids, 936 struct virtchnl2_vector_chunks *chunks); 937 int idpf_recv_mb_msg(struct idpf_adapter *adapter, u32 op, 938 void *msg, int msg_size); 939 int idpf_send_mb_msg(struct idpf_adapter *adapter, u32 op, 940 u16 msg_size, u8 *msg); 941 void idpf_set_ethtool_ops(struct net_device *netdev); 942 int idpf_vport_alloc_max_qs(struct idpf_adapter *adapter, 943 struct idpf_vport_max_q *max_q); 944 void idpf_vport_dealloc_max_qs(struct idpf_adapter *adapter, 945 struct idpf_vport_max_q *max_q); 946 int idpf_add_del_mac_filters(struct idpf_vport *vport, 947 struct idpf_netdev_priv *np, 948 bool add, bool async); 949 int idpf_set_promiscuous(struct idpf_adapter *adapter, 950 struct idpf_vport_user_config_data *config_data, 951 u32 vport_id); 952 int idpf_send_disable_queues_msg(struct idpf_vport *vport); 953 void idpf_vport_init(struct idpf_vport *vport, struct idpf_vport_max_q *max_q); 954 u32 idpf_get_vport_id(struct idpf_vport *vport); 955 int idpf_vport_queue_ids_init(struct idpf_vport *vport); 956 int idpf_queue_reg_init(struct idpf_vport *vport); 957 int idpf_send_config_queues_msg(struct idpf_vport *vport); 958 int idpf_send_enable_queues_msg(struct idpf_vport *vport); 959 int idpf_send_create_vport_msg(struct idpf_adapter *adapter, 960 struct idpf_vport_max_q *max_q); 961 int idpf_check_supported_desc_ids(struct idpf_vport *vport); 962 void idpf_vport_intr_write_itr(struct idpf_q_vector *q_vector, 963 u16 itr, bool tx); 964 int idpf_send_map_unmap_queue_vector_msg(struct idpf_vport *vport, bool map); 965 int idpf_send_set_sriov_vfs_msg(struct idpf_adapter *adapter, u16 num_vfs); 966 int idpf_sriov_configure(struct pci_dev *pdev, int num_vfs); 967 968 #endif /* !_IDPF_H_ */ 969