1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Copyright (C) 2023 Intel Corporation */ 3 4 #ifndef _IDPF_TXRX_H_ 5 #define _IDPF_TXRX_H_ 6 7 #include <linux/dim.h> 8 9 #include <net/libeth/cache.h> 10 #include <net/tcp.h> 11 #include <net/netdev_queues.h> 12 13 #include "idpf_lan_txrx.h" 14 #include "virtchnl2_lan_desc.h" 15 16 #define IDPF_LARGE_MAX_Q 256 17 #define IDPF_MAX_Q 16 18 #define IDPF_MIN_Q 2 19 /* Mailbox Queue */ 20 #define IDPF_MAX_MBXQ 1 21 22 #define IDPF_MIN_TXQ_DESC 64 23 #define IDPF_MIN_RXQ_DESC 64 24 #define IDPF_MIN_TXQ_COMPLQ_DESC 256 25 #define IDPF_MAX_QIDS 256 26 27 /* Number of descriptors in a queue should be a multiple of 32. RX queue 28 * descriptors alone should be a multiple of IDPF_REQ_RXQ_DESC_MULTIPLE 29 * to achieve BufQ descriptors aligned to 32 30 */ 31 #define IDPF_REQ_DESC_MULTIPLE 32 32 #define IDPF_REQ_RXQ_DESC_MULTIPLE (IDPF_MAX_BUFQS_PER_RXQ_GRP * 32) 33 #define IDPF_MIN_TX_DESC_NEEDED (MAX_SKB_FRAGS + 6) 34 #define IDPF_TX_WAKE_THRESH ((u16)IDPF_MIN_TX_DESC_NEEDED * 2) 35 36 #define IDPF_MAX_DESCS 8160 37 #define IDPF_MAX_TXQ_DESC ALIGN_DOWN(IDPF_MAX_DESCS, IDPF_REQ_DESC_MULTIPLE) 38 #define IDPF_MAX_RXQ_DESC ALIGN_DOWN(IDPF_MAX_DESCS, IDPF_REQ_RXQ_DESC_MULTIPLE) 39 #define MIN_SUPPORT_TXDID (\ 40 VIRTCHNL2_TXDID_FLEX_FLOW_SCHED |\ 41 VIRTCHNL2_TXDID_FLEX_TSO_CTX) 42 43 #define IDPF_DFLT_SINGLEQ_TX_Q_GROUPS 1 44 #define IDPF_DFLT_SINGLEQ_RX_Q_GROUPS 1 45 #define IDPF_DFLT_SINGLEQ_TXQ_PER_GROUP 4 46 #define IDPF_DFLT_SINGLEQ_RXQ_PER_GROUP 4 47 48 #define IDPF_COMPLQ_PER_GROUP 1 49 #define IDPF_SINGLE_BUFQ_PER_RXQ_GRP 1 50 #define IDPF_MAX_BUFQS_PER_RXQ_GRP 2 51 #define IDPF_BUFQ2_ENA 1 52 #define IDPF_NUMQ_PER_CHUNK 1 53 54 #define IDPF_DFLT_SPLITQ_TXQ_PER_GROUP 1 55 #define IDPF_DFLT_SPLITQ_RXQ_PER_GROUP 1 56 57 /* Default vector sharing */ 58 #define IDPF_MBX_Q_VEC 1 59 #define IDPF_MIN_Q_VEC 1 60 61 #define IDPF_DFLT_TX_Q_DESC_COUNT 512 62 #define IDPF_DFLT_TX_COMPLQ_DESC_COUNT 512 63 #define IDPF_DFLT_RX_Q_DESC_COUNT 512 64 65 /* IMPORTANT: We absolutely _cannot_ have more buffers in the system than a 66 * given RX completion queue has descriptors. This includes _ALL_ buffer 67 * queues. E.g.: If you have two buffer queues of 512 descriptors and buffers, 68 * you have a total of 1024 buffers so your RX queue _must_ have at least that 69 * many descriptors. This macro divides a given number of RX descriptors by 70 * number of buffer queues to calculate how many descriptors each buffer queue 71 * can have without overrunning the RX queue. 72 * 73 * If you give hardware more buffers than completion descriptors what will 74 * happen is that if hardware gets a chance to post more than ring wrap of 75 * descriptors before SW gets an interrupt and overwrites SW head, the gen bit 76 * in the descriptor will be wrong. Any overwritten descriptors' buffers will 77 * be gone forever and SW has no reasonable way to tell that this has happened. 78 * From SW perspective, when we finally get an interrupt, it looks like we're 79 * still waiting for descriptor to be done, stalling forever. 80 */ 81 #define IDPF_RX_BUFQ_DESC_COUNT(RXD, NUM_BUFQ) ((RXD) / (NUM_BUFQ)) 82 83 #define IDPF_RX_BUFQ_WORKING_SET(rxq) ((rxq)->desc_count - 1) 84 85 #define IDPF_RX_BUMP_NTC(rxq, ntc) \ 86 do { \ 87 if (unlikely(++(ntc) == (rxq)->desc_count)) { \ 88 ntc = 0; \ 89 idpf_queue_change(GEN_CHK, rxq); \ 90 } \ 91 } while (0) 92 93 #define IDPF_SINGLEQ_BUMP_RING_IDX(q, idx) \ 94 do { \ 95 if (unlikely(++(idx) == (q)->desc_count)) \ 96 idx = 0; \ 97 } while (0) 98 99 #define IDPF_RX_BUF_STRIDE 32 100 #define IDPF_RX_BUF_POST_STRIDE 16 101 #define IDPF_LOW_WATERMARK 64 102 103 #define IDPF_TX_TSO_MIN_MSS 88 104 105 /* Minimum number of descriptors between 2 descriptors with the RE bit set; 106 * only relevant in flow scheduling mode 107 */ 108 #define IDPF_TX_SPLITQ_RE_MIN_GAP 64 109 110 #define IDPF_RX_BI_GEN_M BIT(16) 111 #define IDPF_RX_BI_BUFID_M GENMASK(15, 0) 112 113 #define IDPF_RXD_EOF_SPLITQ VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_EOF_M 114 #define IDPF_RXD_EOF_SINGLEQ VIRTCHNL2_RX_BASE_DESC_STATUS_EOF_M 115 116 #define IDPF_DESC_UNUSED(txq) \ 117 ((((txq)->next_to_clean > (txq)->next_to_use) ? 0 : (txq)->desc_count) + \ 118 (txq)->next_to_clean - (txq)->next_to_use - 1) 119 120 #define IDPF_TX_BUF_RSV_UNUSED(txq) ((txq)->stash->buf_stack.top) 121 #define IDPF_TX_BUF_RSV_LOW(txq) (IDPF_TX_BUF_RSV_UNUSED(txq) < \ 122 (txq)->desc_count >> 2) 123 124 #define IDPF_TX_COMPLQ_OVERFLOW_THRESH(txcq) ((txcq)->desc_count >> 1) 125 /* Determine the absolute number of completions pending, i.e. the number of 126 * completions that are expected to arrive on the TX completion queue. 127 */ 128 #define IDPF_TX_COMPLQ_PENDING(txq) \ 129 (((txq)->num_completions_pending >= (txq)->complq->num_completions ? \ 130 0 : U64_MAX) + \ 131 (txq)->num_completions_pending - (txq)->complq->num_completions) 132 133 #define IDPF_TX_SPLITQ_COMPL_TAG_WIDTH 16 134 #define IDPF_SPLITQ_TX_INVAL_COMPL_TAG -1 135 /* Adjust the generation for the completion tag and wrap if necessary */ 136 #define IDPF_TX_ADJ_COMPL_TAG_GEN(txq) \ 137 ((++(txq)->compl_tag_cur_gen) >= (txq)->compl_tag_gen_max ? \ 138 0 : (txq)->compl_tag_cur_gen) 139 140 #define IDPF_TXD_LAST_DESC_CMD (IDPF_TX_DESC_CMD_EOP | IDPF_TX_DESC_CMD_RS) 141 142 #define IDPF_TX_FLAGS_TSO BIT(0) 143 #define IDPF_TX_FLAGS_IPV4 BIT(1) 144 #define IDPF_TX_FLAGS_IPV6 BIT(2) 145 #define IDPF_TX_FLAGS_TUNNEL BIT(3) 146 147 union idpf_tx_flex_desc { 148 struct idpf_flex_tx_desc q; /* queue based scheduling */ 149 struct idpf_flex_tx_sched_desc flow; /* flow based scheduling */ 150 }; 151 152 /** 153 * struct idpf_tx_buf 154 * @next_to_watch: Next descriptor to clean 155 * @skb: Pointer to the skb 156 * @dma: DMA address 157 * @len: DMA length 158 * @bytecount: Number of bytes 159 * @gso_segs: Number of GSO segments 160 * @compl_tag: Splitq only, unique identifier for a buffer. Used to compare 161 * with completion tag returned in buffer completion event. 162 * Because the completion tag is expected to be the same in all 163 * data descriptors for a given packet, and a single packet can 164 * span multiple buffers, we need this field to track all 165 * buffers associated with this completion tag independently of 166 * the buf_id. The tag consists of a N bit buf_id and M upper 167 * order "generation bits". See compl_tag_bufid_m and 168 * compl_tag_gen_s in struct idpf_queue. We'll use a value of -1 169 * to indicate the tag is not valid. 170 * @ctx_entry: Singleq only. Used to indicate the corresponding entry 171 * in the descriptor ring was used for a context descriptor and 172 * this buffer entry should be skipped. 173 */ 174 struct idpf_tx_buf { 175 void *next_to_watch; 176 struct sk_buff *skb; 177 DEFINE_DMA_UNMAP_ADDR(dma); 178 DEFINE_DMA_UNMAP_LEN(len); 179 unsigned int bytecount; 180 unsigned short gso_segs; 181 182 union { 183 int compl_tag; 184 185 bool ctx_entry; 186 }; 187 }; 188 189 struct idpf_tx_stash { 190 struct hlist_node hlist; 191 struct idpf_tx_buf buf; 192 }; 193 194 /** 195 * struct idpf_buf_lifo - LIFO for managing OOO completions 196 * @top: Used to know how many buffers are left 197 * @size: Total size of LIFO 198 * @bufs: Backing array 199 */ 200 struct idpf_buf_lifo { 201 u16 top; 202 u16 size; 203 struct idpf_tx_stash **bufs; 204 }; 205 206 /** 207 * struct idpf_tx_offload_params - Offload parameters for a given packet 208 * @tx_flags: Feature flags enabled for this packet 209 * @hdr_offsets: Offset parameter for single queue model 210 * @cd_tunneling: Type of tunneling enabled for single queue model 211 * @tso_len: Total length of payload to segment 212 * @mss: Segment size 213 * @tso_segs: Number of segments to be sent 214 * @tso_hdr_len: Length of headers to be duplicated 215 * @td_cmd: Command field to be inserted into descriptor 216 */ 217 struct idpf_tx_offload_params { 218 u32 tx_flags; 219 220 u32 hdr_offsets; 221 u32 cd_tunneling; 222 223 u32 tso_len; 224 u16 mss; 225 u16 tso_segs; 226 u16 tso_hdr_len; 227 228 u16 td_cmd; 229 }; 230 231 /** 232 * struct idpf_tx_splitq_params 233 * @dtype: General descriptor info 234 * @eop_cmd: Type of EOP 235 * @compl_tag: Associated tag for completion 236 * @td_tag: Descriptor tunneling tag 237 * @offload: Offload parameters 238 */ 239 struct idpf_tx_splitq_params { 240 enum idpf_tx_desc_dtype_value dtype; 241 u16 eop_cmd; 242 union { 243 u16 compl_tag; 244 u16 td_tag; 245 }; 246 247 struct idpf_tx_offload_params offload; 248 }; 249 250 enum idpf_tx_ctx_desc_eipt_offload { 251 IDPF_TX_CTX_EXT_IP_NONE = 0x0, 252 IDPF_TX_CTX_EXT_IP_IPV6 = 0x1, 253 IDPF_TX_CTX_EXT_IP_IPV4_NO_CSUM = 0x2, 254 IDPF_TX_CTX_EXT_IP_IPV4 = 0x3 255 }; 256 257 /* Checksum offload bits decoded from the receive descriptor. */ 258 struct idpf_rx_csum_decoded { 259 u32 l3l4p : 1; 260 u32 ipe : 1; 261 u32 eipe : 1; 262 u32 eudpe : 1; 263 u32 ipv6exadd : 1; 264 u32 l4e : 1; 265 u32 pprs : 1; 266 u32 nat : 1; 267 u32 raw_csum_inv : 1; 268 u32 raw_csum : 16; 269 }; 270 271 struct idpf_rx_extracted { 272 unsigned int size; 273 u16 rx_ptype; 274 }; 275 276 #define IDPF_TX_COMPLQ_CLEAN_BUDGET 256 277 #define IDPF_TX_MIN_PKT_LEN 17 278 #define IDPF_TX_DESCS_FOR_SKB_DATA_PTR 1 279 #define IDPF_TX_DESCS_PER_CACHE_LINE (L1_CACHE_BYTES / \ 280 sizeof(struct idpf_flex_tx_desc)) 281 #define IDPF_TX_DESCS_FOR_CTX 1 282 /* TX descriptors needed, worst case */ 283 #define IDPF_TX_DESC_NEEDED (MAX_SKB_FRAGS + IDPF_TX_DESCS_FOR_CTX + \ 284 IDPF_TX_DESCS_PER_CACHE_LINE + \ 285 IDPF_TX_DESCS_FOR_SKB_DATA_PTR) 286 287 /* The size limit for a transmit buffer in a descriptor is (16K - 1). 288 * In order to align with the read requests we will align the value to 289 * the nearest 4K which represents our maximum read request size. 290 */ 291 #define IDPF_TX_MAX_READ_REQ_SIZE SZ_4K 292 #define IDPF_TX_MAX_DESC_DATA (SZ_16K - 1) 293 #define IDPF_TX_MAX_DESC_DATA_ALIGNED \ 294 ALIGN_DOWN(IDPF_TX_MAX_DESC_DATA, IDPF_TX_MAX_READ_REQ_SIZE) 295 296 #define idpf_rx_buf libeth_fqe 297 298 #define IDPF_RX_MAX_PTYPE_PROTO_IDS 32 299 #define IDPF_RX_MAX_PTYPE_SZ (sizeof(struct virtchnl2_ptype) + \ 300 (sizeof(u16) * IDPF_RX_MAX_PTYPE_PROTO_IDS)) 301 #define IDPF_RX_PTYPE_HDR_SZ sizeof(struct virtchnl2_get_ptype_info) 302 #define IDPF_RX_MAX_PTYPES_PER_BUF \ 303 DIV_ROUND_DOWN_ULL((IDPF_CTLQ_MAX_BUF_LEN - IDPF_RX_PTYPE_HDR_SZ), \ 304 IDPF_RX_MAX_PTYPE_SZ) 305 306 #define IDPF_GET_PTYPE_SIZE(p) struct_size((p), proto_id, (p)->proto_id_count) 307 308 #define IDPF_TUN_IP_GRE (\ 309 IDPF_PTYPE_TUNNEL_IP |\ 310 IDPF_PTYPE_TUNNEL_IP_GRENAT) 311 312 #define IDPF_TUN_IP_GRE_MAC (\ 313 IDPF_TUN_IP_GRE |\ 314 IDPF_PTYPE_TUNNEL_IP_GRENAT_MAC) 315 316 #define IDPF_RX_MAX_PTYPE 1024 317 #define IDPF_RX_MAX_BASE_PTYPE 256 318 #define IDPF_INVALID_PTYPE_ID 0xFFFF 319 320 enum idpf_tunnel_state { 321 IDPF_PTYPE_TUNNEL_IP = BIT(0), 322 IDPF_PTYPE_TUNNEL_IP_GRENAT = BIT(1), 323 IDPF_PTYPE_TUNNEL_IP_GRENAT_MAC = BIT(2), 324 }; 325 326 struct idpf_ptype_state { 327 bool outer_ip:1; 328 bool outer_frag:1; 329 u8 tunnel_state:6; 330 }; 331 332 /** 333 * enum idpf_queue_flags_t 334 * @__IDPF_Q_GEN_CHK: Queues operating in splitq mode use a generation bit to 335 * identify new descriptor writebacks on the ring. HW sets 336 * the gen bit to 1 on the first writeback of any given 337 * descriptor. After the ring wraps, HW sets the gen bit of 338 * those descriptors to 0, and continues flipping 339 * 0->1 or 1->0 on each ring wrap. SW maintains its own 340 * gen bit to know what value will indicate writebacks on 341 * the next pass around the ring. E.g. it is initialized 342 * to 1 and knows that reading a gen bit of 1 in any 343 * descriptor on the initial pass of the ring indicates a 344 * writeback. It also flips on every ring wrap. 345 * @__IDPF_Q_RFL_GEN_CHK: Refill queues are SW only, so Q_GEN acts as the HW 346 * bit and Q_RFL_GEN is the SW bit. 347 * @__IDPF_Q_FLOW_SCH_EN: Enable flow scheduling 348 * @__IDPF_Q_SW_MARKER: Used to indicate TX queue marker completions 349 * @__IDPF_Q_POLL_MODE: Enable poll mode 350 * @__IDPF_Q_CRC_EN: enable CRC offload in singleq mode 351 * @__IDPF_Q_HSPLIT_EN: enable header split on Rx (splitq) 352 * @__IDPF_Q_FLAGS_NBITS: Must be last 353 */ 354 enum idpf_queue_flags_t { 355 __IDPF_Q_GEN_CHK, 356 __IDPF_Q_RFL_GEN_CHK, 357 __IDPF_Q_FLOW_SCH_EN, 358 __IDPF_Q_SW_MARKER, 359 __IDPF_Q_POLL_MODE, 360 __IDPF_Q_CRC_EN, 361 __IDPF_Q_HSPLIT_EN, 362 363 __IDPF_Q_FLAGS_NBITS, 364 }; 365 366 #define idpf_queue_set(f, q) __set_bit(__IDPF_Q_##f, (q)->flags) 367 #define idpf_queue_clear(f, q) __clear_bit(__IDPF_Q_##f, (q)->flags) 368 #define idpf_queue_change(f, q) __change_bit(__IDPF_Q_##f, (q)->flags) 369 #define idpf_queue_has(f, q) test_bit(__IDPF_Q_##f, (q)->flags) 370 371 #define idpf_queue_has_clear(f, q) \ 372 __test_and_clear_bit(__IDPF_Q_##f, (q)->flags) 373 #define idpf_queue_assign(f, q, v) \ 374 __assign_bit(__IDPF_Q_##f, (q)->flags, v) 375 376 /** 377 * struct idpf_vec_regs 378 * @dyn_ctl_reg: Dynamic control interrupt register offset 379 * @itrn_reg: Interrupt Throttling Rate register offset 380 * @itrn_index_spacing: Register spacing between ITR registers of the same 381 * vector 382 */ 383 struct idpf_vec_regs { 384 u32 dyn_ctl_reg; 385 u32 itrn_reg; 386 u32 itrn_index_spacing; 387 }; 388 389 /** 390 * struct idpf_intr_reg 391 * @dyn_ctl: Dynamic control interrupt register 392 * @dyn_ctl_intena_m: Mask for dyn_ctl interrupt enable 393 * @dyn_ctl_itridx_s: Register bit offset for ITR index 394 * @dyn_ctl_itridx_m: Mask for ITR index 395 * @dyn_ctl_intrvl_s: Register bit offset for ITR interval 396 * @rx_itr: RX ITR register 397 * @tx_itr: TX ITR register 398 * @icr_ena: Interrupt cause register offset 399 * @icr_ena_ctlq_m: Mask for ICR 400 */ 401 struct idpf_intr_reg { 402 void __iomem *dyn_ctl; 403 u32 dyn_ctl_intena_m; 404 u32 dyn_ctl_itridx_s; 405 u32 dyn_ctl_itridx_m; 406 u32 dyn_ctl_intrvl_s; 407 void __iomem *rx_itr; 408 void __iomem *tx_itr; 409 void __iomem *icr_ena; 410 u32 icr_ena_ctlq_m; 411 }; 412 413 /** 414 * struct idpf_q_vector 415 * @vport: Vport back pointer 416 * @num_rxq: Number of RX queues 417 * @num_txq: Number of TX queues 418 * @num_bufq: Number of buffer queues 419 * @num_complq: number of completion queues 420 * @rx: Array of RX queues to service 421 * @tx: Array of TX queues to service 422 * @bufq: Array of buffer queues to service 423 * @complq: array of completion queues 424 * @intr_reg: See struct idpf_intr_reg 425 * @napi: napi handler 426 * @total_events: Number of interrupts processed 427 * @tx_dim: Data for TX net_dim algorithm 428 * @tx_itr_value: TX interrupt throttling rate 429 * @tx_intr_mode: Dynamic ITR or not 430 * @tx_itr_idx: TX ITR index 431 * @rx_dim: Data for RX net_dim algorithm 432 * @rx_itr_value: RX interrupt throttling rate 433 * @rx_intr_mode: Dynamic ITR or not 434 * @rx_itr_idx: RX ITR index 435 * @v_idx: Vector index 436 * @affinity_mask: CPU affinity mask 437 */ 438 struct idpf_q_vector { 439 __cacheline_group_begin_aligned(read_mostly); 440 struct idpf_vport *vport; 441 442 u16 num_rxq; 443 u16 num_txq; 444 u16 num_bufq; 445 u16 num_complq; 446 struct idpf_rx_queue **rx; 447 struct idpf_tx_queue **tx; 448 struct idpf_buf_queue **bufq; 449 struct idpf_compl_queue **complq; 450 451 struct idpf_intr_reg intr_reg; 452 __cacheline_group_end_aligned(read_mostly); 453 454 __cacheline_group_begin_aligned(read_write); 455 struct napi_struct napi; 456 u16 total_events; 457 458 struct dim tx_dim; 459 u16 tx_itr_value; 460 bool tx_intr_mode; 461 u32 tx_itr_idx; 462 463 struct dim rx_dim; 464 u16 rx_itr_value; 465 bool rx_intr_mode; 466 u32 rx_itr_idx; 467 __cacheline_group_end_aligned(read_write); 468 469 __cacheline_group_begin_aligned(cold); 470 u16 v_idx; 471 472 cpumask_var_t affinity_mask; 473 __cacheline_group_end_aligned(cold); 474 }; 475 libeth_cacheline_set_assert(struct idpf_q_vector, 104, 476 424 + 2 * sizeof(struct dim), 477 8 + sizeof(cpumask_var_t)); 478 479 struct idpf_rx_queue_stats { 480 u64_stats_t packets; 481 u64_stats_t bytes; 482 u64_stats_t rsc_pkts; 483 u64_stats_t hw_csum_err; 484 u64_stats_t hsplit_pkts; 485 u64_stats_t hsplit_buf_ovf; 486 u64_stats_t bad_descs; 487 }; 488 489 struct idpf_tx_queue_stats { 490 u64_stats_t packets; 491 u64_stats_t bytes; 492 u64_stats_t lso_pkts; 493 u64_stats_t linearize; 494 u64_stats_t q_busy; 495 u64_stats_t skb_drops; 496 u64_stats_t dma_map_errs; 497 }; 498 499 struct idpf_cleaned_stats { 500 u32 packets; 501 u32 bytes; 502 }; 503 504 #define IDPF_ITR_DYNAMIC 1 505 #define IDPF_ITR_MAX 0x1FE0 506 #define IDPF_ITR_20K 0x0032 507 #define IDPF_ITR_GRAN_S 1 /* Assume ITR granularity is 2us */ 508 #define IDPF_ITR_MASK 0x1FFE /* ITR register value alignment mask */ 509 #define ITR_REG_ALIGN(setting) ((setting) & IDPF_ITR_MASK) 510 #define IDPF_ITR_IS_DYNAMIC(itr_mode) (itr_mode) 511 #define IDPF_ITR_TX_DEF IDPF_ITR_20K 512 #define IDPF_ITR_RX_DEF IDPF_ITR_20K 513 /* Index used for 'No ITR' update in DYN_CTL register */ 514 #define IDPF_NO_ITR_UPDATE_IDX 3 515 #define IDPF_ITR_IDX_SPACING(spacing, dflt) (spacing ? spacing : dflt) 516 #define IDPF_DIM_DEFAULT_PROFILE_IX 1 517 518 /** 519 * struct idpf_txq_stash - Tx buffer stash for Flow-based scheduling mode 520 * @buf_stack: Stack of empty buffers to store buffer info for out of order 521 * buffer completions. See struct idpf_buf_lifo 522 * @sched_buf_hash: Hash table to store buffers 523 */ 524 struct idpf_txq_stash { 525 struct idpf_buf_lifo buf_stack; 526 DECLARE_HASHTABLE(sched_buf_hash, 12); 527 } ____cacheline_aligned; 528 529 /** 530 * struct idpf_rx_queue - software structure representing a receive queue 531 * @rx: universal receive descriptor array 532 * @single_buf: buffer descriptor array in singleq 533 * @desc_ring: virtual descriptor ring address 534 * @bufq_sets: Pointer to the array of buffer queues in splitq mode 535 * @napi: NAPI instance corresponding to this queue (splitq) 536 * @rx_buf: See struct &libeth_fqe 537 * @pp: Page pool pointer in singleq mode 538 * @netdev: &net_device corresponding to this queue 539 * @tail: Tail offset. Used for both queue models single and split. 540 * @flags: See enum idpf_queue_flags_t 541 * @idx: For RX queue, it is used to index to total RX queue across groups and 542 * used for skb reporting. 543 * @desc_count: Number of descriptors 544 * @rxdids: Supported RX descriptor ids 545 * @rx_ptype_lkup: LUT of Rx ptypes 546 * @next_to_use: Next descriptor to use 547 * @next_to_clean: Next descriptor to clean 548 * @next_to_alloc: RX buffer to allocate at 549 * @skb: Pointer to the skb 550 * @truesize: data buffer truesize in singleq 551 * @stats_sync: See struct u64_stats_sync 552 * @q_stats: See union idpf_rx_queue_stats 553 * @q_id: Queue id 554 * @size: Length of descriptor ring in bytes 555 * @dma: Physical address of ring 556 * @q_vector: Backreference to associated vector 557 * @rx_buffer_low_watermark: RX buffer low watermark 558 * @rx_hbuf_size: Header buffer size 559 * @rx_buf_size: Buffer size 560 * @rx_max_pkt_size: RX max packet size 561 */ 562 struct idpf_rx_queue { 563 __cacheline_group_begin_aligned(read_mostly); 564 union { 565 union virtchnl2_rx_desc *rx; 566 struct virtchnl2_singleq_rx_buf_desc *single_buf; 567 568 void *desc_ring; 569 }; 570 union { 571 struct { 572 struct idpf_bufq_set *bufq_sets; 573 struct napi_struct *napi; 574 }; 575 struct { 576 struct libeth_fqe *rx_buf; 577 struct page_pool *pp; 578 }; 579 }; 580 struct net_device *netdev; 581 void __iomem *tail; 582 583 DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS); 584 u16 idx; 585 u16 desc_count; 586 587 u32 rxdids; 588 const struct libeth_rx_pt *rx_ptype_lkup; 589 __cacheline_group_end_aligned(read_mostly); 590 591 __cacheline_group_begin_aligned(read_write); 592 u16 next_to_use; 593 u16 next_to_clean; 594 u16 next_to_alloc; 595 596 struct sk_buff *skb; 597 u32 truesize; 598 599 struct u64_stats_sync stats_sync; 600 struct idpf_rx_queue_stats q_stats; 601 __cacheline_group_end_aligned(read_write); 602 603 __cacheline_group_begin_aligned(cold); 604 u32 q_id; 605 u32 size; 606 dma_addr_t dma; 607 608 struct idpf_q_vector *q_vector; 609 610 u16 rx_buffer_low_watermark; 611 u16 rx_hbuf_size; 612 u16 rx_buf_size; 613 u16 rx_max_pkt_size; 614 __cacheline_group_end_aligned(cold); 615 }; 616 libeth_cacheline_set_assert(struct idpf_rx_queue, 64, 617 80 + sizeof(struct u64_stats_sync), 618 32); 619 620 /** 621 * struct idpf_tx_queue - software structure representing a transmit queue 622 * @base_tx: base Tx descriptor array 623 * @base_ctx: base Tx context descriptor array 624 * @flex_tx: flex Tx descriptor array 625 * @flex_ctx: flex Tx context descriptor array 626 * @desc_ring: virtual descriptor ring address 627 * @tx_buf: See struct idpf_tx_buf 628 * @txq_grp: See struct idpf_txq_group 629 * @dev: Device back pointer for DMA mapping 630 * @tail: Tail offset. Used for both queue models single and split 631 * @flags: See enum idpf_queue_flags_t 632 * @idx: For TX queue, it is used as index to map between TX queue group and 633 * hot path TX pointers stored in vport. Used in both singleq/splitq. 634 * @desc_count: Number of descriptors 635 * @tx_min_pkt_len: Min supported packet length 636 * @compl_tag_gen_s: Completion tag generation bit 637 * The format of the completion tag will change based on the TXQ 638 * descriptor ring size so that we can maintain roughly the same level 639 * of "uniqueness" across all descriptor sizes. For example, if the 640 * TXQ descriptor ring size is 64 (the minimum size supported), the 641 * completion tag will be formatted as below: 642 * 15 6 5 0 643 * -------------------------------- 644 * | GEN=0-1023 |IDX = 0-63| 645 * -------------------------------- 646 * 647 * This gives us 64*1024 = 65536 possible unique values. Similarly, if 648 * the TXQ descriptor ring size is 8160 (the maximum size supported), 649 * the completion tag will be formatted as below: 650 * 15 13 12 0 651 * -------------------------------- 652 * |GEN | IDX = 0-8159 | 653 * -------------------------------- 654 * 655 * This gives us 8*8160 = 65280 possible unique values. 656 * @netdev: &net_device corresponding to this queue 657 * @next_to_use: Next descriptor to use 658 * @next_to_clean: Next descriptor to clean 659 * @cleaned_bytes: Splitq only, TXQ only: When a TX completion is received on 660 * the TX completion queue, it can be for any TXQ associated 661 * with that completion queue. This means we can clean up to 662 * N TXQs during a single call to clean the completion queue. 663 * cleaned_bytes|pkts tracks the clean stats per TXQ during 664 * that single call to clean the completion queue. By doing so, 665 * we can update BQL with aggregate cleaned stats for each TXQ 666 * only once at the end of the cleaning routine. 667 * @clean_budget: singleq only, queue cleaning budget 668 * @cleaned_pkts: Number of packets cleaned for the above said case 669 * @tx_max_bufs: Max buffers that can be transmitted with scatter-gather 670 * @stash: Tx buffer stash for Flow-based scheduling mode 671 * @compl_tag_bufid_m: Completion tag buffer id mask 672 * @compl_tag_cur_gen: Used to keep track of current completion tag generation 673 * @compl_tag_gen_max: To determine when compl_tag_cur_gen should be reset 674 * @stats_sync: See struct u64_stats_sync 675 * @q_stats: See union idpf_tx_queue_stats 676 * @q_id: Queue id 677 * @size: Length of descriptor ring in bytes 678 * @dma: Physical address of ring 679 * @q_vector: Backreference to associated vector 680 */ 681 struct idpf_tx_queue { 682 __cacheline_group_begin_aligned(read_mostly); 683 union { 684 struct idpf_base_tx_desc *base_tx; 685 struct idpf_base_tx_ctx_desc *base_ctx; 686 union idpf_tx_flex_desc *flex_tx; 687 struct idpf_flex_tx_ctx_desc *flex_ctx; 688 689 void *desc_ring; 690 }; 691 struct idpf_tx_buf *tx_buf; 692 struct idpf_txq_group *txq_grp; 693 struct device *dev; 694 void __iomem *tail; 695 696 DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS); 697 u16 idx; 698 u16 desc_count; 699 700 u16 tx_min_pkt_len; 701 u16 compl_tag_gen_s; 702 703 struct net_device *netdev; 704 __cacheline_group_end_aligned(read_mostly); 705 706 __cacheline_group_begin_aligned(read_write); 707 u16 next_to_use; 708 u16 next_to_clean; 709 710 union { 711 u32 cleaned_bytes; 712 u32 clean_budget; 713 }; 714 u16 cleaned_pkts; 715 716 u16 tx_max_bufs; 717 struct idpf_txq_stash *stash; 718 719 u16 compl_tag_bufid_m; 720 u16 compl_tag_cur_gen; 721 u16 compl_tag_gen_max; 722 723 struct u64_stats_sync stats_sync; 724 struct idpf_tx_queue_stats q_stats; 725 __cacheline_group_end_aligned(read_write); 726 727 __cacheline_group_begin_aligned(cold); 728 u32 q_id; 729 u32 size; 730 dma_addr_t dma; 731 732 struct idpf_q_vector *q_vector; 733 __cacheline_group_end_aligned(cold); 734 }; 735 libeth_cacheline_set_assert(struct idpf_tx_queue, 64, 736 88 + sizeof(struct u64_stats_sync), 737 24); 738 739 /** 740 * struct idpf_buf_queue - software structure representing a buffer queue 741 * @split_buf: buffer descriptor array 742 * @hdr_buf: &libeth_fqe for header buffers 743 * @hdr_pp: &page_pool for header buffers 744 * @buf: &libeth_fqe for data buffers 745 * @pp: &page_pool for data buffers 746 * @tail: Tail offset 747 * @flags: See enum idpf_queue_flags_t 748 * @desc_count: Number of descriptors 749 * @next_to_use: Next descriptor to use 750 * @next_to_clean: Next descriptor to clean 751 * @next_to_alloc: RX buffer to allocate at 752 * @hdr_truesize: truesize for buffer headers 753 * @truesize: truesize for data buffers 754 * @q_id: Queue id 755 * @size: Length of descriptor ring in bytes 756 * @dma: Physical address of ring 757 * @q_vector: Backreference to associated vector 758 * @rx_buffer_low_watermark: RX buffer low watermark 759 * @rx_hbuf_size: Header buffer size 760 * @rx_buf_size: Buffer size 761 */ 762 struct idpf_buf_queue { 763 __cacheline_group_begin_aligned(read_mostly); 764 struct virtchnl2_splitq_rx_buf_desc *split_buf; 765 struct libeth_fqe *hdr_buf; 766 struct page_pool *hdr_pp; 767 struct libeth_fqe *buf; 768 struct page_pool *pp; 769 void __iomem *tail; 770 771 DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS); 772 u32 desc_count; 773 __cacheline_group_end_aligned(read_mostly); 774 775 __cacheline_group_begin_aligned(read_write); 776 u32 next_to_use; 777 u32 next_to_clean; 778 u32 next_to_alloc; 779 780 u32 hdr_truesize; 781 u32 truesize; 782 __cacheline_group_end_aligned(read_write); 783 784 __cacheline_group_begin_aligned(cold); 785 u32 q_id; 786 u32 size; 787 dma_addr_t dma; 788 789 struct idpf_q_vector *q_vector; 790 791 u16 rx_buffer_low_watermark; 792 u16 rx_hbuf_size; 793 u16 rx_buf_size; 794 __cacheline_group_end_aligned(cold); 795 }; 796 libeth_cacheline_set_assert(struct idpf_buf_queue, 64, 24, 32); 797 798 /** 799 * struct idpf_compl_queue - software structure representing a completion queue 800 * @comp: completion descriptor array 801 * @txq_grp: See struct idpf_txq_group 802 * @flags: See enum idpf_queue_flags_t 803 * @desc_count: Number of descriptors 804 * @clean_budget: queue cleaning budget 805 * @netdev: &net_device corresponding to this queue 806 * @next_to_use: Next descriptor to use. Relevant in both split & single txq 807 * and bufq. 808 * @next_to_clean: Next descriptor to clean 809 * @num_completions: Only relevant for TX completion queue. It tracks the 810 * number of completions received to compare against the 811 * number of completions pending, as accumulated by the 812 * TX queues. 813 * @q_id: Queue id 814 * @size: Length of descriptor ring in bytes 815 * @dma: Physical address of ring 816 * @q_vector: Backreference to associated vector 817 */ 818 struct idpf_compl_queue { 819 __cacheline_group_begin_aligned(read_mostly); 820 struct idpf_splitq_tx_compl_desc *comp; 821 struct idpf_txq_group *txq_grp; 822 823 DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS); 824 u32 desc_count; 825 826 u32 clean_budget; 827 struct net_device *netdev; 828 __cacheline_group_end_aligned(read_mostly); 829 830 __cacheline_group_begin_aligned(read_write); 831 u32 next_to_use; 832 u32 next_to_clean; 833 834 u32 num_completions; 835 __cacheline_group_end_aligned(read_write); 836 837 __cacheline_group_begin_aligned(cold); 838 u32 q_id; 839 u32 size; 840 dma_addr_t dma; 841 842 struct idpf_q_vector *q_vector; 843 __cacheline_group_end_aligned(cold); 844 }; 845 libeth_cacheline_set_assert(struct idpf_compl_queue, 40, 16, 24); 846 847 /** 848 * struct idpf_sw_queue 849 * @ring: Pointer to the ring 850 * @flags: See enum idpf_queue_flags_t 851 * @desc_count: Descriptor count 852 * @next_to_use: Buffer to allocate at 853 * @next_to_clean: Next descriptor to clean 854 * 855 * Software queues are used in splitq mode to manage buffers between rxq 856 * producer and the bufq consumer. These are required in order to maintain a 857 * lockless buffer management system and are strictly software only constructs. 858 */ 859 struct idpf_sw_queue { 860 __cacheline_group_begin_aligned(read_mostly); 861 u32 *ring; 862 863 DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS); 864 u32 desc_count; 865 __cacheline_group_end_aligned(read_mostly); 866 867 __cacheline_group_begin_aligned(read_write); 868 u32 next_to_use; 869 u32 next_to_clean; 870 __cacheline_group_end_aligned(read_write); 871 }; 872 libeth_cacheline_group_assert(struct idpf_sw_queue, read_mostly, 24); 873 libeth_cacheline_group_assert(struct idpf_sw_queue, read_write, 8); 874 libeth_cacheline_struct_assert(struct idpf_sw_queue, 24, 8); 875 876 /** 877 * struct idpf_rxq_set 878 * @rxq: RX queue 879 * @refillq: pointers to refill queues 880 * 881 * Splitq only. idpf_rxq_set associates an rxq with at an array of refillqs. 882 * Each rxq needs a refillq to return used buffers back to the respective bufq. 883 * Bufqs then clean these refillqs for buffers to give to hardware. 884 */ 885 struct idpf_rxq_set { 886 struct idpf_rx_queue rxq; 887 struct idpf_sw_queue *refillq[IDPF_MAX_BUFQS_PER_RXQ_GRP]; 888 }; 889 890 /** 891 * struct idpf_bufq_set 892 * @bufq: Buffer queue 893 * @num_refillqs: Number of refill queues. This is always equal to num_rxq_sets 894 * in idpf_rxq_group. 895 * @refillqs: Pointer to refill queues array. 896 * 897 * Splitq only. idpf_bufq_set associates a bufq to an array of refillqs. 898 * In this bufq_set, there will be one refillq for each rxq in this rxq_group. 899 * Used buffers received by rxqs will be put on refillqs which bufqs will 900 * clean to return new buffers back to hardware. 901 * 902 * Buffers needed by some number of rxqs associated in this rxq_group are 903 * managed by at most two bufqs (depending on performance configuration). 904 */ 905 struct idpf_bufq_set { 906 struct idpf_buf_queue bufq; 907 int num_refillqs; 908 struct idpf_sw_queue *refillqs; 909 }; 910 911 /** 912 * struct idpf_rxq_group 913 * @vport: Vport back pointer 914 * @singleq: Struct with single queue related members 915 * @singleq.num_rxq: Number of RX queues associated 916 * @singleq.rxqs: Array of RX queue pointers 917 * @splitq: Struct with split queue related members 918 * @splitq.num_rxq_sets: Number of RX queue sets 919 * @splitq.rxq_sets: Array of RX queue sets 920 * @splitq.bufq_sets: Buffer queue set pointer 921 * 922 * In singleq mode, an rxq_group is simply an array of rxqs. In splitq, a 923 * rxq_group contains all the rxqs, bufqs and refillqs needed to 924 * manage buffers in splitq mode. 925 */ 926 struct idpf_rxq_group { 927 struct idpf_vport *vport; 928 929 union { 930 struct { 931 u16 num_rxq; 932 struct idpf_rx_queue *rxqs[IDPF_LARGE_MAX_Q]; 933 } singleq; 934 struct { 935 u16 num_rxq_sets; 936 struct idpf_rxq_set *rxq_sets[IDPF_LARGE_MAX_Q]; 937 struct idpf_bufq_set *bufq_sets; 938 } splitq; 939 }; 940 }; 941 942 /** 943 * struct idpf_txq_group 944 * @vport: Vport back pointer 945 * @num_txq: Number of TX queues associated 946 * @txqs: Array of TX queue pointers 947 * @stashes: array of OOO stashes for the queues 948 * @complq: Associated completion queue pointer, split queue only 949 * @num_completions_pending: Total number of completions pending for the 950 * completion queue, acculumated for all TX queues 951 * associated with that completion queue. 952 * 953 * Between singleq and splitq, a txq_group is largely the same except for the 954 * complq. In splitq a single complq is responsible for handling completions 955 * for some number of txqs associated in this txq_group. 956 */ 957 struct idpf_txq_group { 958 struct idpf_vport *vport; 959 960 u16 num_txq; 961 struct idpf_tx_queue *txqs[IDPF_LARGE_MAX_Q]; 962 struct idpf_txq_stash *stashes; 963 964 struct idpf_compl_queue *complq; 965 966 u32 num_completions_pending; 967 }; 968 969 static inline int idpf_q_vector_to_mem(const struct idpf_q_vector *q_vector) 970 { 971 u32 cpu; 972 973 if (!q_vector) 974 return NUMA_NO_NODE; 975 976 cpu = cpumask_first(q_vector->affinity_mask); 977 978 return cpu < nr_cpu_ids ? cpu_to_mem(cpu) : NUMA_NO_NODE; 979 } 980 981 /** 982 * idpf_size_to_txd_count - Get number of descriptors needed for large Tx frag 983 * @size: transmit request size in bytes 984 * 985 * In the case where a large frag (>= 16K) needs to be split across multiple 986 * descriptors, we need to assume that we can have no more than 12K of data 987 * per descriptor due to hardware alignment restrictions (4K alignment). 988 */ 989 static inline u32 idpf_size_to_txd_count(unsigned int size) 990 { 991 return DIV_ROUND_UP(size, IDPF_TX_MAX_DESC_DATA_ALIGNED); 992 } 993 994 /** 995 * idpf_tx_singleq_build_ctob - populate command tag offset and size 996 * @td_cmd: Command to be filled in desc 997 * @td_offset: Offset to be filled in desc 998 * @size: Size of the buffer 999 * @td_tag: td tag to be filled 1000 * 1001 * Returns the 64 bit value populated with the input parameters 1002 */ 1003 static inline __le64 idpf_tx_singleq_build_ctob(u64 td_cmd, u64 td_offset, 1004 unsigned int size, u64 td_tag) 1005 { 1006 return cpu_to_le64(IDPF_TX_DESC_DTYPE_DATA | 1007 (td_cmd << IDPF_TXD_QW1_CMD_S) | 1008 (td_offset << IDPF_TXD_QW1_OFFSET_S) | 1009 ((u64)size << IDPF_TXD_QW1_TX_BUF_SZ_S) | 1010 (td_tag << IDPF_TXD_QW1_L2TAG1_S)); 1011 } 1012 1013 void idpf_tx_splitq_build_ctb(union idpf_tx_flex_desc *desc, 1014 struct idpf_tx_splitq_params *params, 1015 u16 td_cmd, u16 size); 1016 void idpf_tx_splitq_build_flow_desc(union idpf_tx_flex_desc *desc, 1017 struct idpf_tx_splitq_params *params, 1018 u16 td_cmd, u16 size); 1019 /** 1020 * idpf_tx_splitq_build_desc - determine which type of data descriptor to build 1021 * @desc: descriptor to populate 1022 * @params: pointer to tx params struct 1023 * @td_cmd: command to be filled in desc 1024 * @size: size of buffer 1025 */ 1026 static inline void idpf_tx_splitq_build_desc(union idpf_tx_flex_desc *desc, 1027 struct idpf_tx_splitq_params *params, 1028 u16 td_cmd, u16 size) 1029 { 1030 if (params->dtype == IDPF_TX_DESC_DTYPE_FLEX_L2TAG1_L2TAG2) 1031 idpf_tx_splitq_build_ctb(desc, params, td_cmd, size); 1032 else 1033 idpf_tx_splitq_build_flow_desc(desc, params, td_cmd, size); 1034 } 1035 1036 int idpf_vport_singleq_napi_poll(struct napi_struct *napi, int budget); 1037 void idpf_vport_init_num_qs(struct idpf_vport *vport, 1038 struct virtchnl2_create_vport *vport_msg); 1039 void idpf_vport_calc_num_q_desc(struct idpf_vport *vport); 1040 int idpf_vport_calc_total_qs(struct idpf_adapter *adapter, u16 vport_index, 1041 struct virtchnl2_create_vport *vport_msg, 1042 struct idpf_vport_max_q *max_q); 1043 void idpf_vport_calc_num_q_groups(struct idpf_vport *vport); 1044 int idpf_vport_queues_alloc(struct idpf_vport *vport); 1045 void idpf_vport_queues_rel(struct idpf_vport *vport); 1046 void idpf_vport_intr_rel(struct idpf_vport *vport); 1047 int idpf_vport_intr_alloc(struct idpf_vport *vport); 1048 void idpf_vport_intr_update_itr_ena_irq(struct idpf_q_vector *q_vector); 1049 void idpf_vport_intr_deinit(struct idpf_vport *vport); 1050 int idpf_vport_intr_init(struct idpf_vport *vport); 1051 void idpf_vport_intr_ena(struct idpf_vport *vport); 1052 int idpf_config_rss(struct idpf_vport *vport); 1053 int idpf_init_rss(struct idpf_vport *vport); 1054 void idpf_deinit_rss(struct idpf_vport *vport); 1055 int idpf_rx_bufs_init_all(struct idpf_vport *vport); 1056 void idpf_rx_add_frag(struct idpf_rx_buf *rx_buf, struct sk_buff *skb, 1057 unsigned int size); 1058 struct sk_buff *idpf_rx_build_skb(const struct libeth_fqe *buf, u32 size); 1059 void idpf_tx_buf_hw_update(struct idpf_tx_queue *tx_q, u32 val, 1060 bool xmit_more); 1061 unsigned int idpf_size_to_txd_count(unsigned int size); 1062 netdev_tx_t idpf_tx_drop_skb(struct idpf_tx_queue *tx_q, struct sk_buff *skb); 1063 void idpf_tx_dma_map_error(struct idpf_tx_queue *txq, struct sk_buff *skb, 1064 struct idpf_tx_buf *first, u16 ring_idx); 1065 unsigned int idpf_tx_desc_count_required(struct idpf_tx_queue *txq, 1066 struct sk_buff *skb); 1067 int idpf_tx_maybe_stop_common(struct idpf_tx_queue *tx_q, unsigned int size); 1068 void idpf_tx_timeout(struct net_device *netdev, unsigned int txqueue); 1069 netdev_tx_t idpf_tx_singleq_frame(struct sk_buff *skb, 1070 struct idpf_tx_queue *tx_q); 1071 netdev_tx_t idpf_tx_start(struct sk_buff *skb, struct net_device *netdev); 1072 bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_rx_queue *rxq, 1073 u16 cleaned_count); 1074 int idpf_tso(struct sk_buff *skb, struct idpf_tx_offload_params *off); 1075 1076 #endif /* !_IDPF_TXRX_H_ */ 1077