1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
13 #include <sys/queue.h>
15 #include <rte_string_fns.h>
16 #include <rte_memzone.h>
18 #include <rte_malloc.h>
19 #include <rte_ether.h>
20 #include <ethdev_driver.h>
28 #include "i40e_logs.h"
29 #include "base/i40e_prototype.h"
30 #include "base/i40e_type.h"
31 #include "i40e_ethdev.h"
32 #include "i40e_rxtx.h"
34 #define DEFAULT_TX_RS_THRESH 32
35 #define DEFAULT_TX_FREE_THRESH 32
37 #define I40E_TX_MAX_BURST 32
39 #define I40E_DMA_MEM_ALIGN 4096
41 /* Base address of the HW descriptor ring should be 128B aligned. */
42 #define I40E_RING_BASE_ALIGN 128
44 #define I40E_TXD_CMD (I40E_TX_DESC_CMD_EOP | I40E_TX_DESC_CMD_RS)
46 #ifdef RTE_LIBRTE_IEEE1588
47 #define I40E_TX_IEEE1588_TMST PKT_TX_IEEE1588_TMST
49 #define I40E_TX_IEEE1588_TMST 0
52 #define I40E_TX_CKSUM_OFFLOAD_MASK ( \
56 PKT_TX_OUTER_IP_CKSUM)
58 #define I40E_TX_OFFLOAD_MASK ( \
65 PKT_TX_OUTER_IP_CKSUM | \
69 PKT_TX_TUNNEL_MASK | \
70 I40E_TX_IEEE1588_TMST)
72 #define I40E_TX_OFFLOAD_NOTSUP_MASK \
73 (PKT_TX_OFFLOAD_MASK ^ I40E_TX_OFFLOAD_MASK)
75 #define I40E_TX_OFFLOAD_SIMPLE_SUP_MASK ( \
81 #define I40E_TX_OFFLOAD_SIMPLE_NOTSUP_MASK \
82 (PKT_TX_OFFLOAD_MASK ^ I40E_TX_OFFLOAD_SIMPLE_SUP_MASK)
85 i40e_monitor_callback(const uint64_t value,
86 const uint64_t arg[RTE_POWER_MONITOR_OPAQUE_SZ] __rte_unused)
88 const uint64_t m = rte_cpu_to_le_64(1 << I40E_RX_DESC_STATUS_DD_SHIFT);
90 * we expect the DD bit to be set to 1 if this descriptor was already
93 return (value & m) == m ? -1 : 0;
97 i40e_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc)
99 struct i40e_rx_queue *rxq = rx_queue;
100 volatile union i40e_rx_desc *rxdp;
104 rxdp = &rxq->rx_ring[desc];
105 /* watch for changes in status bit */
106 pmc->addr = &rxdp->wb.qword1.status_error_len;
108 /* comparison callback */
109 pmc->fn = i40e_monitor_callback;
111 /* registers are 64-bit */
112 pmc->size = sizeof(uint64_t);
118 i40e_rxd_to_vlan_tci(struct rte_mbuf *mb, volatile union i40e_rx_desc *rxdp)
120 if (rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
121 (1 << I40E_RX_DESC_STATUS_L2TAG1P_SHIFT)) {
122 mb->ol_flags |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
124 rte_le_to_cpu_16(rxdp->wb.qword0.lo_dword.l2tag1);
125 PMD_RX_LOG(DEBUG, "Descriptor l2tag1: %u",
126 rte_le_to_cpu_16(rxdp->wb.qword0.lo_dword.l2tag1));
130 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
131 if (rte_le_to_cpu_16(rxdp->wb.qword2.ext_status) &
132 (1 << I40E_RX_DESC_EXT_STATUS_L2TAG2P_SHIFT)) {
133 mb->ol_flags |= PKT_RX_QINQ_STRIPPED | PKT_RX_QINQ |
134 PKT_RX_VLAN_STRIPPED | PKT_RX_VLAN;
135 mb->vlan_tci_outer = mb->vlan_tci;
136 mb->vlan_tci = rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_2);
137 PMD_RX_LOG(DEBUG, "Descriptor l2tag2_1: %u, l2tag2_2: %u",
138 rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_1),
139 rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_2));
141 mb->vlan_tci_outer = 0;
144 PMD_RX_LOG(DEBUG, "Mbuf vlan_tci: %u, vlan_tci_outer: %u",
145 mb->vlan_tci, mb->vlan_tci_outer);
148 /* Translate the rx descriptor status to pkt flags */
149 static inline uint64_t
150 i40e_rxd_status_to_pkt_flags(uint64_t qword)
154 /* Check if RSS_HASH */
155 flags = (((qword >> I40E_RX_DESC_STATUS_FLTSTAT_SHIFT) &
156 I40E_RX_DESC_FLTSTAT_RSS_HASH) ==
157 I40E_RX_DESC_FLTSTAT_RSS_HASH) ? PKT_RX_RSS_HASH : 0;
159 /* Check if FDIR Match */
160 flags |= (qword & (1 << I40E_RX_DESC_STATUS_FLM_SHIFT) ?
166 static inline uint64_t
167 i40e_rxd_error_to_pkt_flags(uint64_t qword)
170 uint64_t error_bits = (qword >> I40E_RXD_QW1_ERROR_SHIFT);
172 #define I40E_RX_ERR_BITS 0x3f
173 if (likely((error_bits & I40E_RX_ERR_BITS) == 0)) {
174 flags |= (PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD);
178 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_IPE_SHIFT)))
179 flags |= PKT_RX_IP_CKSUM_BAD;
181 flags |= PKT_RX_IP_CKSUM_GOOD;
183 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_L4E_SHIFT)))
184 flags |= PKT_RX_L4_CKSUM_BAD;
186 flags |= PKT_RX_L4_CKSUM_GOOD;
188 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_EIPE_SHIFT)))
189 flags |= PKT_RX_OUTER_IP_CKSUM_BAD;
194 /* Function to check and set the ieee1588 timesync index and get the
197 #ifdef RTE_LIBRTE_IEEE1588
198 static inline uint64_t
199 i40e_get_iee15888_flags(struct rte_mbuf *mb, uint64_t qword)
201 uint64_t pkt_flags = 0;
202 uint16_t tsyn = (qword & (I40E_RXD_QW1_STATUS_TSYNVALID_MASK
203 | I40E_RXD_QW1_STATUS_TSYNINDX_MASK))
204 >> I40E_RX_DESC_STATUS_TSYNINDX_SHIFT;
206 if ((mb->packet_type & RTE_PTYPE_L2_MASK)
207 == RTE_PTYPE_L2_ETHER_TIMESYNC)
208 pkt_flags = PKT_RX_IEEE1588_PTP;
210 pkt_flags |= PKT_RX_IEEE1588_TMST;
211 mb->timesync = tsyn & 0x03;
218 static inline uint64_t
219 i40e_rxd_build_fdir(volatile union i40e_rx_desc *rxdp, struct rte_mbuf *mb)
222 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
223 uint16_t flexbh, flexbl;
225 flexbh = (rte_le_to_cpu_32(rxdp->wb.qword2.ext_status) >>
226 I40E_RX_DESC_EXT_STATUS_FLEXBH_SHIFT) &
227 I40E_RX_DESC_EXT_STATUS_FLEXBH_MASK;
228 flexbl = (rte_le_to_cpu_32(rxdp->wb.qword2.ext_status) >>
229 I40E_RX_DESC_EXT_STATUS_FLEXBL_SHIFT) &
230 I40E_RX_DESC_EXT_STATUS_FLEXBL_MASK;
233 if (flexbh == I40E_RX_DESC_EXT_STATUS_FLEXBH_FD_ID) {
235 rte_le_to_cpu_32(rxdp->wb.qword3.hi_dword.fd_id);
236 flags |= PKT_RX_FDIR_ID;
237 } else if (flexbh == I40E_RX_DESC_EXT_STATUS_FLEXBH_FLEX) {
239 rte_le_to_cpu_32(rxdp->wb.qword3.hi_dword.flex_bytes_hi);
240 flags |= PKT_RX_FDIR_FLX;
242 if (flexbl == I40E_RX_DESC_EXT_STATUS_FLEXBL_FLEX) {
244 rte_le_to_cpu_32(rxdp->wb.qword3.lo_dword.flex_bytes_lo);
245 flags |= PKT_RX_FDIR_FLX;
249 rte_le_to_cpu_32(rxdp->wb.qword0.hi_dword.fd_id);
250 flags |= PKT_RX_FDIR_ID;
256 i40e_parse_tunneling_params(uint64_t ol_flags,
257 union i40e_tx_offload tx_offload,
258 uint32_t *cd_tunneling)
260 /* EIPT: External (outer) IP header type */
261 if (ol_flags & PKT_TX_OUTER_IP_CKSUM)
262 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV4;
263 else if (ol_flags & PKT_TX_OUTER_IPV4)
264 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV4_NO_CSUM;
265 else if (ol_flags & PKT_TX_OUTER_IPV6)
266 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV6;
268 /* EIPLEN: External (outer) IP header length, in DWords */
269 *cd_tunneling |= (tx_offload.outer_l3_len >> 2) <<
270 I40E_TXD_CTX_QW0_EXT_IPLEN_SHIFT;
272 /* L4TUNT: L4 Tunneling Type */
273 switch (ol_flags & PKT_TX_TUNNEL_MASK) {
274 case PKT_TX_TUNNEL_IPIP:
275 /* for non UDP / GRE tunneling, set to 00b */
277 case PKT_TX_TUNNEL_VXLAN:
278 case PKT_TX_TUNNEL_GENEVE:
279 *cd_tunneling |= I40E_TXD_CTX_UDP_TUNNELING;
281 case PKT_TX_TUNNEL_GRE:
282 *cd_tunneling |= I40E_TXD_CTX_GRE_TUNNELING;
285 PMD_TX_LOG(ERR, "Tunnel type not supported");
289 /* L4TUNLEN: L4 Tunneling Length, in Words
291 * We depend on app to set rte_mbuf.l2_len correctly.
292 * For IP in GRE it should be set to the length of the GRE
294 * for MAC in GRE or MAC in UDP it should be set to the length
295 * of the GRE or UDP headers plus the inner MAC up to including
296 * its last Ethertype.
298 *cd_tunneling |= (tx_offload.l2_len >> 1) <<
299 I40E_TXD_CTX_QW0_NATLEN_SHIFT;
303 i40e_txd_enable_checksum(uint64_t ol_flags,
306 union i40e_tx_offload tx_offload)
309 if (ol_flags & PKT_TX_TUNNEL_MASK)
310 *td_offset |= (tx_offload.outer_l2_len >> 1)
311 << I40E_TX_DESC_LENGTH_MACLEN_SHIFT;
313 *td_offset |= (tx_offload.l2_len >> 1)
314 << I40E_TX_DESC_LENGTH_MACLEN_SHIFT;
316 /* Enable L3 checksum offloads */
317 if (ol_flags & PKT_TX_IP_CKSUM) {
318 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV4_CSUM;
319 *td_offset |= (tx_offload.l3_len >> 2)
320 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
321 } else if (ol_flags & PKT_TX_IPV4) {
322 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV4;
323 *td_offset |= (tx_offload.l3_len >> 2)
324 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
325 } else if (ol_flags & PKT_TX_IPV6) {
326 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV6;
327 *td_offset |= (tx_offload.l3_len >> 2)
328 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
331 if (ol_flags & PKT_TX_TCP_SEG) {
332 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_TCP;
333 *td_offset |= (tx_offload.l4_len >> 2)
334 << I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
338 /* Enable L4 checksum offloads */
339 switch (ol_flags & PKT_TX_L4_MASK) {
340 case PKT_TX_TCP_CKSUM:
341 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_TCP;
342 *td_offset |= (sizeof(struct rte_tcp_hdr) >> 2) <<
343 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
345 case PKT_TX_SCTP_CKSUM:
346 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_SCTP;
347 *td_offset |= (sizeof(struct rte_sctp_hdr) >> 2) <<
348 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
350 case PKT_TX_UDP_CKSUM:
351 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_UDP;
352 *td_offset |= (sizeof(struct rte_udp_hdr) >> 2) <<
353 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
360 /* Construct the tx flags */
361 static inline uint64_t
362 i40e_build_ctob(uint32_t td_cmd,
367 return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA |
368 ((uint64_t)td_cmd << I40E_TXD_QW1_CMD_SHIFT) |
369 ((uint64_t)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) |
370 ((uint64_t)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) |
371 ((uint64_t)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT));
375 i40e_xmit_cleanup(struct i40e_tx_queue *txq)
377 struct i40e_tx_entry *sw_ring = txq->sw_ring;
378 volatile struct i40e_tx_desc *txd = txq->tx_ring;
379 uint16_t last_desc_cleaned = txq->last_desc_cleaned;
380 uint16_t nb_tx_desc = txq->nb_tx_desc;
381 uint16_t desc_to_clean_to;
382 uint16_t nb_tx_to_clean;
384 desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_rs_thresh);
385 if (desc_to_clean_to >= nb_tx_desc)
386 desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
388 desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
389 if ((txd[desc_to_clean_to].cmd_type_offset_bsz &
390 rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
391 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE)) {
392 PMD_TX_LOG(DEBUG, "TX descriptor %4u is not done "
393 "(port=%d queue=%d)", desc_to_clean_to,
394 txq->port_id, txq->queue_id);
398 if (last_desc_cleaned > desc_to_clean_to)
399 nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
402 nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
405 txd[desc_to_clean_to].cmd_type_offset_bsz = 0;
407 txq->last_desc_cleaned = desc_to_clean_to;
408 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
414 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
415 check_rx_burst_bulk_alloc_preconditions(struct i40e_rx_queue *rxq)
417 check_rx_burst_bulk_alloc_preconditions(__rte_unused struct i40e_rx_queue *rxq)
422 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
423 if (!(rxq->rx_free_thresh >= RTE_PMD_I40E_RX_MAX_BURST)) {
424 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
425 "rxq->rx_free_thresh=%d, "
426 "RTE_PMD_I40E_RX_MAX_BURST=%d",
427 rxq->rx_free_thresh, RTE_PMD_I40E_RX_MAX_BURST);
429 } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
430 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
431 "rxq->rx_free_thresh=%d, "
432 "rxq->nb_rx_desc=%d",
433 rxq->rx_free_thresh, rxq->nb_rx_desc);
435 } else if (rxq->nb_rx_desc % rxq->rx_free_thresh != 0) {
436 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
437 "rxq->nb_rx_desc=%d, "
438 "rxq->rx_free_thresh=%d",
439 rxq->nb_rx_desc, rxq->rx_free_thresh);
449 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
450 #define I40E_LOOK_AHEAD 8
451 #if (I40E_LOOK_AHEAD != 8)
452 #error "PMD I40E: I40E_LOOK_AHEAD must be 8\n"
455 i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
457 volatile union i40e_rx_desc *rxdp;
458 struct i40e_rx_entry *rxep;
463 int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
464 int32_t i, j, nb_rx = 0;
466 uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
468 rxdp = &rxq->rx_ring[rxq->rx_tail];
469 rxep = &rxq->sw_ring[rxq->rx_tail];
471 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
472 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
473 I40E_RXD_QW1_STATUS_SHIFT;
475 /* Make sure there is at least 1 packet to receive */
476 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
480 * Scan LOOK_AHEAD descriptors at a time to determine which
481 * descriptors reference packets that are ready to be received.
483 for (i = 0; i < RTE_PMD_I40E_RX_MAX_BURST; i+=I40E_LOOK_AHEAD,
484 rxdp += I40E_LOOK_AHEAD, rxep += I40E_LOOK_AHEAD) {
485 /* Read desc statuses backwards to avoid race condition */
486 for (j = I40E_LOOK_AHEAD - 1; j >= 0; j--) {
487 qword1 = rte_le_to_cpu_64(\
488 rxdp[j].wb.qword1.status_error_len);
489 s[j] = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
490 I40E_RXD_QW1_STATUS_SHIFT;
495 /* Compute how many status bits were set */
496 for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
497 var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
499 /* For Arm platforms, only compute continuous status bits */
511 /* Translate descriptor info to mbuf parameters */
512 for (j = 0; j < nb_dd; j++) {
514 qword1 = rte_le_to_cpu_64(\
515 rxdp[j].wb.qword1.status_error_len);
516 pkt_len = ((qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
517 I40E_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
518 mb->data_len = pkt_len;
519 mb->pkt_len = pkt_len;
521 i40e_rxd_to_vlan_tci(mb, &rxdp[j]);
522 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
523 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
525 ptype_tbl[(uint8_t)((qword1 &
526 I40E_RXD_QW1_PTYPE_MASK) >>
527 I40E_RXD_QW1_PTYPE_SHIFT)];
528 if (pkt_flags & PKT_RX_RSS_HASH)
529 mb->hash.rss = rte_le_to_cpu_32(\
530 rxdp[j].wb.qword0.hi_dword.rss);
531 if (pkt_flags & PKT_RX_FDIR)
532 pkt_flags |= i40e_rxd_build_fdir(&rxdp[j], mb);
534 #ifdef RTE_LIBRTE_IEEE1588
535 pkt_flags |= i40e_get_iee15888_flags(mb, qword1);
537 mb->ol_flags |= pkt_flags;
541 for (j = 0; j < I40E_LOOK_AHEAD; j++)
542 rxq->rx_stage[i + j] = rxep[j].mbuf;
544 if (nb_dd != I40E_LOOK_AHEAD)
548 /* Clear software ring entries */
549 for (i = 0; i < nb_rx; i++)
550 rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
555 static inline uint16_t
556 i40e_rx_fill_from_stage(struct i40e_rx_queue *rxq,
557 struct rte_mbuf **rx_pkts,
561 struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
563 nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
565 for (i = 0; i < nb_pkts; i++)
566 rx_pkts[i] = stage[i];
568 rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
569 rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
575 i40e_rx_alloc_bufs(struct i40e_rx_queue *rxq)
577 volatile union i40e_rx_desc *rxdp;
578 struct i40e_rx_entry *rxep;
580 uint16_t alloc_idx, i;
584 /* Allocate buffers in bulk */
585 alloc_idx = (uint16_t)(rxq->rx_free_trigger -
586 (rxq->rx_free_thresh - 1));
587 rxep = &(rxq->sw_ring[alloc_idx]);
588 diag = rte_mempool_get_bulk(rxq->mp, (void *)rxep,
589 rxq->rx_free_thresh);
590 if (unlikely(diag != 0)) {
591 PMD_DRV_LOG(ERR, "Failed to get mbufs in bulk");
595 rxdp = &rxq->rx_ring[alloc_idx];
596 for (i = 0; i < rxq->rx_free_thresh; i++) {
597 if (likely(i < (rxq->rx_free_thresh - 1)))
598 /* Prefetch next mbuf */
599 rte_prefetch0(rxep[i + 1].mbuf);
602 rte_mbuf_refcnt_set(mb, 1);
604 mb->data_off = RTE_PKTMBUF_HEADROOM;
606 mb->port = rxq->port_id;
607 dma_addr = rte_cpu_to_le_64(\
608 rte_mbuf_data_iova_default(mb));
609 rxdp[i].read.hdr_addr = 0;
610 rxdp[i].read.pkt_addr = dma_addr;
613 /* Update rx tail regsiter */
614 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->rx_free_trigger);
616 rxq->rx_free_trigger =
617 (uint16_t)(rxq->rx_free_trigger + rxq->rx_free_thresh);
618 if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
619 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
624 static inline uint16_t
625 rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
627 struct i40e_rx_queue *rxq = (struct i40e_rx_queue *)rx_queue;
628 struct rte_eth_dev *dev;
634 if (rxq->rx_nb_avail)
635 return i40e_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
637 nb_rx = (uint16_t)i40e_rx_scan_hw_ring(rxq);
638 rxq->rx_next_avail = 0;
639 rxq->rx_nb_avail = nb_rx;
640 rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
642 if (rxq->rx_tail > rxq->rx_free_trigger) {
643 if (i40e_rx_alloc_bufs(rxq) != 0) {
646 dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
647 dev->data->rx_mbuf_alloc_failed +=
650 rxq->rx_nb_avail = 0;
651 rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
652 for (i = 0, j = rxq->rx_tail; i < nb_rx; i++, j++)
653 rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
659 if (rxq->rx_tail >= rxq->nb_rx_desc)
662 if (rxq->rx_nb_avail)
663 return i40e_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
669 i40e_recv_pkts_bulk_alloc(void *rx_queue,
670 struct rte_mbuf **rx_pkts,
673 uint16_t nb_rx = 0, n, count;
675 if (unlikely(nb_pkts == 0))
678 if (likely(nb_pkts <= RTE_PMD_I40E_RX_MAX_BURST))
679 return rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
682 n = RTE_MIN(nb_pkts, RTE_PMD_I40E_RX_MAX_BURST);
683 count = rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
684 nb_rx = (uint16_t)(nb_rx + count);
685 nb_pkts = (uint16_t)(nb_pkts - count);
694 i40e_recv_pkts_bulk_alloc(void __rte_unused *rx_queue,
695 struct rte_mbuf __rte_unused **rx_pkts,
696 uint16_t __rte_unused nb_pkts)
700 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
703 i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
705 struct i40e_rx_queue *rxq;
706 volatile union i40e_rx_desc *rx_ring;
707 volatile union i40e_rx_desc *rxdp;
708 union i40e_rx_desc rxd;
709 struct i40e_rx_entry *sw_ring;
710 struct i40e_rx_entry *rxe;
711 struct rte_eth_dev *dev;
712 struct rte_mbuf *rxm;
713 struct rte_mbuf *nmb;
717 uint16_t rx_packet_len;
718 uint16_t rx_id, nb_hold;
726 rx_id = rxq->rx_tail;
727 rx_ring = rxq->rx_ring;
728 sw_ring = rxq->sw_ring;
729 ptype_tbl = rxq->vsi->adapter->ptype_tbl;
731 while (nb_rx < nb_pkts) {
732 rxdp = &rx_ring[rx_id];
733 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
734 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK)
735 >> I40E_RXD_QW1_STATUS_SHIFT;
737 /* Check the DD bit first */
738 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
741 nmb = rte_mbuf_raw_alloc(rxq->mp);
742 if (unlikely(!nmb)) {
743 dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
744 dev->data->rx_mbuf_alloc_failed++;
750 rxe = &sw_ring[rx_id];
752 if (unlikely(rx_id == rxq->nb_rx_desc))
755 /* Prefetch next mbuf */
756 rte_prefetch0(sw_ring[rx_id].mbuf);
759 * When next RX descriptor is on a cache line boundary,
760 * prefetch the next 4 RX descriptors and next 8 pointers
763 if ((rx_id & 0x3) == 0) {
764 rte_prefetch0(&rx_ring[rx_id]);
765 rte_prefetch0(&sw_ring[rx_id]);
770 rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
771 rxdp->read.hdr_addr = 0;
772 rxdp->read.pkt_addr = dma_addr;
774 rx_packet_len = ((qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
775 I40E_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
777 rxm->data_off = RTE_PKTMBUF_HEADROOM;
778 rte_prefetch0(RTE_PTR_ADD(rxm->buf_addr, RTE_PKTMBUF_HEADROOM));
781 rxm->pkt_len = rx_packet_len;
782 rxm->data_len = rx_packet_len;
783 rxm->port = rxq->port_id;
785 i40e_rxd_to_vlan_tci(rxm, &rxd);
786 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
787 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
789 ptype_tbl[(uint8_t)((qword1 &
790 I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
791 if (pkt_flags & PKT_RX_RSS_HASH)
793 rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
794 if (pkt_flags & PKT_RX_FDIR)
795 pkt_flags |= i40e_rxd_build_fdir(&rxd, rxm);
797 #ifdef RTE_LIBRTE_IEEE1588
798 pkt_flags |= i40e_get_iee15888_flags(rxm, qword1);
800 rxm->ol_flags |= pkt_flags;
802 rx_pkts[nb_rx++] = rxm;
804 rxq->rx_tail = rx_id;
807 * If the number of free RX descriptors is greater than the RX free
808 * threshold of the queue, advance the receive tail register of queue.
809 * Update that register with the value of the last processed RX
810 * descriptor minus 1.
812 nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
813 if (nb_hold > rxq->rx_free_thresh) {
814 rx_id = (uint16_t) ((rx_id == 0) ?
815 (rxq->nb_rx_desc - 1) : (rx_id - 1));
816 I40E_PCI_REG_WC_WRITE(rxq->qrx_tail, rx_id);
819 rxq->nb_rx_hold = nb_hold;
825 i40e_recv_scattered_pkts(void *rx_queue,
826 struct rte_mbuf **rx_pkts,
829 struct i40e_rx_queue *rxq = rx_queue;
830 volatile union i40e_rx_desc *rx_ring = rxq->rx_ring;
831 volatile union i40e_rx_desc *rxdp;
832 union i40e_rx_desc rxd;
833 struct i40e_rx_entry *sw_ring = rxq->sw_ring;
834 struct i40e_rx_entry *rxe;
835 struct rte_mbuf *first_seg = rxq->pkt_first_seg;
836 struct rte_mbuf *last_seg = rxq->pkt_last_seg;
837 struct rte_mbuf *nmb, *rxm;
838 uint16_t rx_id = rxq->rx_tail;
839 uint16_t nb_rx = 0, nb_hold = 0, rx_packet_len;
840 struct rte_eth_dev *dev;
845 uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
847 while (nb_rx < nb_pkts) {
848 rxdp = &rx_ring[rx_id];
849 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
850 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
851 I40E_RXD_QW1_STATUS_SHIFT;
853 /* Check the DD bit */
854 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
857 nmb = rte_mbuf_raw_alloc(rxq->mp);
858 if (unlikely(!nmb)) {
859 dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
860 dev->data->rx_mbuf_alloc_failed++;
866 rxe = &sw_ring[rx_id];
868 if (rx_id == rxq->nb_rx_desc)
871 /* Prefetch next mbuf */
872 rte_prefetch0(sw_ring[rx_id].mbuf);
875 * When next RX descriptor is on a cache line boundary,
876 * prefetch the next 4 RX descriptors and next 8 pointers
879 if ((rx_id & 0x3) == 0) {
880 rte_prefetch0(&rx_ring[rx_id]);
881 rte_prefetch0(&sw_ring[rx_id]);
887 rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
889 /* Set data buffer address and data length of the mbuf */
890 rxdp->read.hdr_addr = 0;
891 rxdp->read.pkt_addr = dma_addr;
892 rx_packet_len = (qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
893 I40E_RXD_QW1_LENGTH_PBUF_SHIFT;
894 rxm->data_len = rx_packet_len;
895 rxm->data_off = RTE_PKTMBUF_HEADROOM;
898 * If this is the first buffer of the received packet, set the
899 * pointer to the first mbuf of the packet and initialize its
900 * context. Otherwise, update the total length and the number
901 * of segments of the current scattered packet, and update the
902 * pointer to the last mbuf of the current packet.
906 first_seg->nb_segs = 1;
907 first_seg->pkt_len = rx_packet_len;
910 (uint16_t)(first_seg->pkt_len +
912 first_seg->nb_segs++;
913 last_seg->next = rxm;
917 * If this is not the last buffer of the received packet,
918 * update the pointer to the last mbuf of the current scattered
919 * packet and continue to parse the RX ring.
921 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_EOF_SHIFT))) {
927 * This is the last buffer of the received packet. If the CRC
928 * is not stripped by the hardware:
929 * - Subtract the CRC length from the total packet length.
930 * - If the last buffer only contains the whole CRC or a part
931 * of it, free the mbuf associated to the last buffer. If part
932 * of the CRC is also contained in the previous mbuf, subtract
933 * the length of that CRC part from the data length of the
937 if (unlikely(rxq->crc_len > 0)) {
938 first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
939 if (rx_packet_len <= RTE_ETHER_CRC_LEN) {
940 rte_pktmbuf_free_seg(rxm);
941 first_seg->nb_segs--;
943 (uint16_t)(last_seg->data_len -
944 (RTE_ETHER_CRC_LEN - rx_packet_len));
945 last_seg->next = NULL;
947 rxm->data_len = (uint16_t)(rx_packet_len -
951 first_seg->port = rxq->port_id;
952 first_seg->ol_flags = 0;
953 i40e_rxd_to_vlan_tci(first_seg, &rxd);
954 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
955 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
956 first_seg->packet_type =
957 ptype_tbl[(uint8_t)((qword1 &
958 I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
959 if (pkt_flags & PKT_RX_RSS_HASH)
960 first_seg->hash.rss =
961 rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
962 if (pkt_flags & PKT_RX_FDIR)
963 pkt_flags |= i40e_rxd_build_fdir(&rxd, first_seg);
965 #ifdef RTE_LIBRTE_IEEE1588
966 pkt_flags |= i40e_get_iee15888_flags(first_seg, qword1);
968 first_seg->ol_flags |= pkt_flags;
970 /* Prefetch data of first segment, if configured to do so. */
971 rte_prefetch0(RTE_PTR_ADD(first_seg->buf_addr,
972 first_seg->data_off));
973 rx_pkts[nb_rx++] = first_seg;
977 /* Record index of the next RX descriptor to probe. */
978 rxq->rx_tail = rx_id;
979 rxq->pkt_first_seg = first_seg;
980 rxq->pkt_last_seg = last_seg;
983 * If the number of free RX descriptors is greater than the RX free
984 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
985 * register. Update the RDT with the value of the last processed RX
986 * descriptor minus 1, to guarantee that the RDT register is never
987 * equal to the RDH register, which creates a "full" ring situtation
988 * from the hardware point of view.
990 nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
991 if (nb_hold > rxq->rx_free_thresh) {
992 rx_id = (uint16_t)(rx_id == 0 ?
993 (rxq->nb_rx_desc - 1) : (rx_id - 1));
994 I40E_PCI_REG_WC_WRITE(rxq->qrx_tail, rx_id);
997 rxq->nb_rx_hold = nb_hold;
1002 /* Check if the context descriptor is needed for TX offloading */
1003 static inline uint16_t
1004 i40e_calc_context_desc(uint64_t flags)
1006 static uint64_t mask = PKT_TX_OUTER_IP_CKSUM |
1011 #ifdef RTE_LIBRTE_IEEE1588
1012 mask |= PKT_TX_IEEE1588_TMST;
1015 return (flags & mask) ? 1 : 0;
1018 /* set i40e TSO context descriptor */
1019 static inline uint64_t
1020 i40e_set_tso_ctx(struct rte_mbuf *mbuf, union i40e_tx_offload tx_offload)
1022 uint64_t ctx_desc = 0;
1023 uint32_t cd_cmd, hdr_len, cd_tso_len;
1025 if (!tx_offload.l4_len) {
1026 PMD_DRV_LOG(DEBUG, "L4 length set to 0");
1030 hdr_len = tx_offload.l2_len + tx_offload.l3_len + tx_offload.l4_len;
1031 hdr_len += (mbuf->ol_flags & PKT_TX_TUNNEL_MASK) ?
1032 tx_offload.outer_l2_len + tx_offload.outer_l3_len : 0;
1034 cd_cmd = I40E_TX_CTX_DESC_TSO;
1035 cd_tso_len = mbuf->pkt_len - hdr_len;
1036 ctx_desc |= ((uint64_t)cd_cmd << I40E_TXD_CTX_QW1_CMD_SHIFT) |
1037 ((uint64_t)cd_tso_len <<
1038 I40E_TXD_CTX_QW1_TSO_LEN_SHIFT) |
1039 ((uint64_t)mbuf->tso_segsz <<
1040 I40E_TXD_CTX_QW1_MSS_SHIFT);
1045 /* HW requires that Tx buffer size ranges from 1B up to (16K-1)B. */
1046 #define I40E_MAX_DATA_PER_TXD \
1047 (I40E_TXD_QW1_TX_BUF_SZ_MASK >> I40E_TXD_QW1_TX_BUF_SZ_SHIFT)
1048 /* Calculate the number of TX descriptors needed for each pkt */
1049 static inline uint16_t
1050 i40e_calc_pkt_desc(struct rte_mbuf *tx_pkt)
1052 struct rte_mbuf *txd = tx_pkt;
1055 while (txd != NULL) {
1056 count += DIV_ROUND_UP(txd->data_len, I40E_MAX_DATA_PER_TXD);
1064 i40e_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1066 struct i40e_tx_queue *txq;
1067 struct i40e_tx_entry *sw_ring;
1068 struct i40e_tx_entry *txe, *txn;
1069 volatile struct i40e_tx_desc *txd;
1070 volatile struct i40e_tx_desc *txr;
1071 struct rte_mbuf *tx_pkt;
1072 struct rte_mbuf *m_seg;
1073 uint32_t cd_tunneling_params;
1084 uint64_t buf_dma_addr;
1085 union i40e_tx_offload tx_offload = {0};
1088 sw_ring = txq->sw_ring;
1090 tx_id = txq->tx_tail;
1091 txe = &sw_ring[tx_id];
1093 /* Check if the descriptor ring needs to be cleaned. */
1094 if (txq->nb_tx_free < txq->tx_free_thresh)
1095 (void)i40e_xmit_cleanup(txq);
1097 for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
1102 tx_pkt = *tx_pkts++;
1103 RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
1105 ol_flags = tx_pkt->ol_flags;
1106 tx_offload.l2_len = tx_pkt->l2_len;
1107 tx_offload.l3_len = tx_pkt->l3_len;
1108 tx_offload.outer_l2_len = tx_pkt->outer_l2_len;
1109 tx_offload.outer_l3_len = tx_pkt->outer_l3_len;
1110 tx_offload.l4_len = tx_pkt->l4_len;
1111 tx_offload.tso_segsz = tx_pkt->tso_segsz;
1113 /* Calculate the number of context descriptors needed. */
1114 nb_ctx = i40e_calc_context_desc(ol_flags);
1117 * The number of descriptors that must be allocated for
1118 * a packet equals to the number of the segments of that
1119 * packet plus 1 context descriptor if needed.
1120 * Recalculate the needed tx descs when TSO enabled in case
1121 * the mbuf data size exceeds max data size that hw allows
1124 if (ol_flags & PKT_TX_TCP_SEG)
1125 nb_used = (uint16_t)(i40e_calc_pkt_desc(tx_pkt) +
1128 nb_used = (uint16_t)(tx_pkt->nb_segs + nb_ctx);
1129 tx_last = (uint16_t)(tx_id + nb_used - 1);
1132 if (tx_last >= txq->nb_tx_desc)
1133 tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
1135 if (nb_used > txq->nb_tx_free) {
1136 if (i40e_xmit_cleanup(txq) != 0) {
1141 if (unlikely(nb_used > txq->tx_rs_thresh)) {
1142 while (nb_used > txq->nb_tx_free) {
1143 if (i40e_xmit_cleanup(txq) != 0) {
1152 /* Descriptor based VLAN insertion */
1153 if (ol_flags & (PKT_TX_VLAN_PKT | PKT_TX_QINQ_PKT)) {
1154 td_cmd |= I40E_TX_DESC_CMD_IL2TAG1;
1155 td_tag = tx_pkt->vlan_tci;
1158 /* Always enable CRC offload insertion */
1159 td_cmd |= I40E_TX_DESC_CMD_ICRC;
1161 /* Fill in tunneling parameters if necessary */
1162 cd_tunneling_params = 0;
1163 if (ol_flags & PKT_TX_TUNNEL_MASK)
1164 i40e_parse_tunneling_params(ol_flags, tx_offload,
1165 &cd_tunneling_params);
1166 /* Enable checksum offloading */
1167 if (ol_flags & I40E_TX_CKSUM_OFFLOAD_MASK)
1168 i40e_txd_enable_checksum(ol_flags, &td_cmd,
1169 &td_offset, tx_offload);
1172 /* Setup TX context descriptor if required */
1173 volatile struct i40e_tx_context_desc *ctx_txd =
1174 (volatile struct i40e_tx_context_desc *)\
1176 uint16_t cd_l2tag2 = 0;
1177 uint64_t cd_type_cmd_tso_mss =
1178 I40E_TX_DESC_DTYPE_CONTEXT;
1180 txn = &sw_ring[txe->next_id];
1181 RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1182 if (txe->mbuf != NULL) {
1183 rte_pktmbuf_free_seg(txe->mbuf);
1187 /* TSO enabled means no timestamp */
1188 if (ol_flags & PKT_TX_TCP_SEG)
1189 cd_type_cmd_tso_mss |=
1190 i40e_set_tso_ctx(tx_pkt, tx_offload);
1192 #ifdef RTE_LIBRTE_IEEE1588
1193 if (ol_flags & PKT_TX_IEEE1588_TMST)
1194 cd_type_cmd_tso_mss |=
1195 ((uint64_t)I40E_TX_CTX_DESC_TSYN <<
1196 I40E_TXD_CTX_QW1_CMD_SHIFT);
1200 ctx_txd->tunneling_params =
1201 rte_cpu_to_le_32(cd_tunneling_params);
1202 if (ol_flags & PKT_TX_QINQ_PKT) {
1203 cd_l2tag2 = tx_pkt->vlan_tci_outer;
1204 cd_type_cmd_tso_mss |=
1205 ((uint64_t)I40E_TX_CTX_DESC_IL2TAG2 <<
1206 I40E_TXD_CTX_QW1_CMD_SHIFT);
1208 ctx_txd->l2tag2 = rte_cpu_to_le_16(cd_l2tag2);
1209 ctx_txd->type_cmd_tso_mss =
1210 rte_cpu_to_le_64(cd_type_cmd_tso_mss);
1212 PMD_TX_LOG(DEBUG, "mbuf: %p, TCD[%u]:\n"
1213 "tunneling_params: %#x;\n"
1216 "type_cmd_tso_mss: %#"PRIx64";\n",
1218 ctx_txd->tunneling_params,
1221 ctx_txd->type_cmd_tso_mss);
1223 txe->last_id = tx_last;
1224 tx_id = txe->next_id;
1231 txn = &sw_ring[txe->next_id];
1234 rte_pktmbuf_free_seg(txe->mbuf);
1237 /* Setup TX Descriptor */
1238 slen = m_seg->data_len;
1239 buf_dma_addr = rte_mbuf_data_iova(m_seg);
1241 while ((ol_flags & PKT_TX_TCP_SEG) &&
1242 unlikely(slen > I40E_MAX_DATA_PER_TXD)) {
1244 rte_cpu_to_le_64(buf_dma_addr);
1245 txd->cmd_type_offset_bsz =
1246 i40e_build_ctob(td_cmd,
1247 td_offset, I40E_MAX_DATA_PER_TXD,
1250 buf_dma_addr += I40E_MAX_DATA_PER_TXD;
1251 slen -= I40E_MAX_DATA_PER_TXD;
1253 txe->last_id = tx_last;
1254 tx_id = txe->next_id;
1257 txn = &sw_ring[txe->next_id];
1259 PMD_TX_LOG(DEBUG, "mbuf: %p, TDD[%u]:\n"
1260 "buf_dma_addr: %#"PRIx64";\n"
1265 tx_pkt, tx_id, buf_dma_addr,
1266 td_cmd, td_offset, slen, td_tag);
1268 txd->buffer_addr = rte_cpu_to_le_64(buf_dma_addr);
1269 txd->cmd_type_offset_bsz = i40e_build_ctob(td_cmd,
1270 td_offset, slen, td_tag);
1271 txe->last_id = tx_last;
1272 tx_id = txe->next_id;
1274 m_seg = m_seg->next;
1275 } while (m_seg != NULL);
1277 /* The last packet data descriptor needs End Of Packet (EOP) */
1278 td_cmd |= I40E_TX_DESC_CMD_EOP;
1279 txq->nb_tx_used = (uint16_t)(txq->nb_tx_used + nb_used);
1280 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
1282 if (txq->nb_tx_used >= txq->tx_rs_thresh) {
1284 "Setting RS bit on TXD id="
1285 "%4u (port=%d queue=%d)",
1286 tx_last, txq->port_id, txq->queue_id);
1288 td_cmd |= I40E_TX_DESC_CMD_RS;
1290 /* Update txq RS bit counters */
1291 txq->nb_tx_used = 0;
1294 txd->cmd_type_offset_bsz |=
1295 rte_cpu_to_le_64(((uint64_t)td_cmd) <<
1296 I40E_TXD_QW1_CMD_SHIFT);
1300 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
1301 (unsigned) txq->port_id, (unsigned) txq->queue_id,
1302 (unsigned) tx_id, (unsigned) nb_tx);
1305 I40E_PCI_REG_WC_WRITE_RELAXED(txq->qtx_tail, tx_id);
1306 txq->tx_tail = tx_id;
1311 static __rte_always_inline int
1312 i40e_tx_free_bufs(struct i40e_tx_queue *txq)
1314 struct i40e_tx_entry *txep;
1315 uint16_t tx_rs_thresh = txq->tx_rs_thresh;
1316 uint16_t i = 0, j = 0;
1317 struct rte_mbuf *free[RTE_I40E_TX_MAX_FREE_BUF_SZ];
1318 const uint16_t k = RTE_ALIGN_FLOOR(tx_rs_thresh, RTE_I40E_TX_MAX_FREE_BUF_SZ);
1319 const uint16_t m = tx_rs_thresh % RTE_I40E_TX_MAX_FREE_BUF_SZ;
1321 if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz &
1322 rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
1323 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1326 txep = &txq->sw_ring[txq->tx_next_dd - (tx_rs_thresh - 1)];
1328 for (i = 0; i < tx_rs_thresh; i++)
1329 rte_prefetch0((txep + i)->mbuf);
1331 if (txq->offloads & DEV_TX_OFFLOAD_MBUF_FAST_FREE) {
1333 for (j = 0; j != k; j += RTE_I40E_TX_MAX_FREE_BUF_SZ) {
1334 for (i = 0; i < RTE_I40E_TX_MAX_FREE_BUF_SZ; ++i, ++txep) {
1335 free[i] = txep->mbuf;
1338 rte_mempool_put_bulk(free[0]->pool, (void **)free,
1339 RTE_I40E_TX_MAX_FREE_BUF_SZ);
1344 for (i = 0; i < m; ++i, ++txep) {
1345 free[i] = txep->mbuf;
1348 rte_mempool_put_bulk(free[0]->pool, (void **)free, m);
1351 for (i = 0; i < txq->tx_rs_thresh; ++i, ++txep) {
1352 rte_pktmbuf_free_seg(txep->mbuf);
1357 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_rs_thresh);
1358 txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_rs_thresh);
1359 if (txq->tx_next_dd >= txq->nb_tx_desc)
1360 txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
1362 return txq->tx_rs_thresh;
1365 /* Populate 4 descriptors with data from 4 mbufs */
1367 tx4(volatile struct i40e_tx_desc *txdp, struct rte_mbuf **pkts)
1372 for (i = 0; i < 4; i++, txdp++, pkts++) {
1373 dma_addr = rte_mbuf_data_iova(*pkts);
1374 txdp->buffer_addr = rte_cpu_to_le_64(dma_addr);
1375 txdp->cmd_type_offset_bsz =
1376 i40e_build_ctob((uint32_t)I40E_TD_CMD, 0,
1377 (*pkts)->data_len, 0);
1381 /* Populate 1 descriptor with data from 1 mbuf */
1383 tx1(volatile struct i40e_tx_desc *txdp, struct rte_mbuf **pkts)
1387 dma_addr = rte_mbuf_data_iova(*pkts);
1388 txdp->buffer_addr = rte_cpu_to_le_64(dma_addr);
1389 txdp->cmd_type_offset_bsz =
1390 i40e_build_ctob((uint32_t)I40E_TD_CMD, 0,
1391 (*pkts)->data_len, 0);
1394 /* Fill hardware descriptor ring with mbuf data */
1396 i40e_tx_fill_hw_ring(struct i40e_tx_queue *txq,
1397 struct rte_mbuf **pkts,
1400 volatile struct i40e_tx_desc *txdp = &(txq->tx_ring[txq->tx_tail]);
1401 struct i40e_tx_entry *txep = &(txq->sw_ring[txq->tx_tail]);
1402 const int N_PER_LOOP = 4;
1403 const int N_PER_LOOP_MASK = N_PER_LOOP - 1;
1404 int mainpart, leftover;
1407 mainpart = (nb_pkts & ((uint32_t) ~N_PER_LOOP_MASK));
1408 leftover = (nb_pkts & ((uint32_t) N_PER_LOOP_MASK));
1409 for (i = 0; i < mainpart; i += N_PER_LOOP) {
1410 for (j = 0; j < N_PER_LOOP; ++j) {
1411 (txep + i + j)->mbuf = *(pkts + i + j);
1413 tx4(txdp + i, pkts + i);
1415 if (unlikely(leftover > 0)) {
1416 for (i = 0; i < leftover; ++i) {
1417 (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
1418 tx1(txdp + mainpart + i, pkts + mainpart + i);
1423 static inline uint16_t
1424 tx_xmit_pkts(struct i40e_tx_queue *txq,
1425 struct rte_mbuf **tx_pkts,
1428 volatile struct i40e_tx_desc *txr = txq->tx_ring;
1432 * Begin scanning the H/W ring for done descriptors when the number
1433 * of available descriptors drops below tx_free_thresh. For each done
1434 * descriptor, free the associated buffer.
1436 if (txq->nb_tx_free < txq->tx_free_thresh)
1437 i40e_tx_free_bufs(txq);
1439 /* Use available descriptor only */
1440 nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
1441 if (unlikely(!nb_pkts))
1444 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
1445 if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
1446 n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
1447 i40e_tx_fill_hw_ring(txq, tx_pkts, n);
1448 txr[txq->tx_next_rs].cmd_type_offset_bsz |=
1449 rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
1450 I40E_TXD_QW1_CMD_SHIFT);
1451 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
1455 /* Fill hardware descriptor ring with mbuf data */
1456 i40e_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
1457 txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
1459 /* Determin if RS bit needs to be set */
1460 if (txq->tx_tail > txq->tx_next_rs) {
1461 txr[txq->tx_next_rs].cmd_type_offset_bsz |=
1462 rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
1463 I40E_TXD_QW1_CMD_SHIFT);
1465 (uint16_t)(txq->tx_next_rs + txq->tx_rs_thresh);
1466 if (txq->tx_next_rs >= txq->nb_tx_desc)
1467 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
1470 if (txq->tx_tail >= txq->nb_tx_desc)
1473 /* Update the tx tail register */
1474 I40E_PCI_REG_WC_WRITE(txq->qtx_tail, txq->tx_tail);
1480 i40e_xmit_pkts_simple(void *tx_queue,
1481 struct rte_mbuf **tx_pkts,
1486 if (likely(nb_pkts <= I40E_TX_MAX_BURST))
1487 return tx_xmit_pkts((struct i40e_tx_queue *)tx_queue,
1491 uint16_t ret, num = (uint16_t)RTE_MIN(nb_pkts,
1494 ret = tx_xmit_pkts((struct i40e_tx_queue *)tx_queue,
1495 &tx_pkts[nb_tx], num);
1496 nb_tx = (uint16_t)(nb_tx + ret);
1497 nb_pkts = (uint16_t)(nb_pkts - ret);
1506 i40e_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
1510 struct i40e_tx_queue *txq = (struct i40e_tx_queue *)tx_queue;
1515 num = (uint16_t)RTE_MIN(nb_pkts, txq->tx_rs_thresh);
1516 ret = i40e_xmit_fixed_burst_vec(tx_queue, &tx_pkts[nb_tx],
1527 /*********************************************************************
1529 * TX simple prep functions
1531 **********************************************************************/
1533 i40e_simple_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
1540 for (i = 0; i < nb_pkts; i++) {
1542 ol_flags = m->ol_flags;
1544 if (m->nb_segs != 1) {
1549 if (ol_flags & I40E_TX_OFFLOAD_SIMPLE_NOTSUP_MASK) {
1550 rte_errno = ENOTSUP;
1554 /* check the size of packet */
1555 if (m->pkt_len < I40E_TX_MIN_PKT_LEN ||
1556 m->pkt_len > I40E_FRAME_SIZE_MAX) {
1564 /*********************************************************************
1568 **********************************************************************/
1570 i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
1577 for (i = 0; i < nb_pkts; i++) {
1579 ol_flags = m->ol_flags;
1581 /* Check for m->nb_segs to not exceed the limits. */
1582 if (!(ol_flags & PKT_TX_TCP_SEG)) {
1583 if (m->nb_segs > I40E_TX_MAX_MTU_SEG ||
1584 m->pkt_len > I40E_FRAME_SIZE_MAX) {
1588 } else if (m->nb_segs > I40E_TX_MAX_SEG ||
1589 m->tso_segsz < I40E_MIN_TSO_MSS ||
1590 m->tso_segsz > I40E_MAX_TSO_MSS ||
1591 m->pkt_len > I40E_TSO_FRAME_SIZE_MAX) {
1592 /* MSS outside the range (256B - 9674B) are considered
1599 if (ol_flags & I40E_TX_OFFLOAD_NOTSUP_MASK) {
1600 rte_errno = ENOTSUP;
1604 /* check the size of packet */
1605 if (m->pkt_len < I40E_TX_MIN_PKT_LEN) {
1610 #ifdef RTE_ETHDEV_DEBUG_TX
1611 ret = rte_validate_tx_offload(m);
1617 ret = rte_net_intel_cksum_prepare(m);
1627 * Find the VSI the queue belongs to. 'queue_idx' is the queue index
1628 * application used, which assume having sequential ones. But from driver's
1629 * perspective, it's different. For example, q0 belongs to FDIR VSI, q1-q64
1630 * to MAIN VSI, , q65-96 to SRIOV VSIs, q97-128 to VMDQ VSIs. For application
1631 * running on host, q1-64 and q97-128 can be used, total 96 queues. They can
1632 * use queue_idx from 0 to 95 to access queues, while real queue would be
1633 * different. This function will do a queue mapping to find VSI the queue
1636 static struct i40e_vsi*
1637 i40e_pf_get_vsi_by_qindex(struct i40e_pf *pf, uint16_t queue_idx)
1639 /* the queue in MAIN VSI range */
1640 if (queue_idx < pf->main_vsi->nb_qps)
1641 return pf->main_vsi;
1643 queue_idx -= pf->main_vsi->nb_qps;
1645 /* queue_idx is greater than VMDQ VSIs range */
1646 if (queue_idx > pf->nb_cfg_vmdq_vsi * pf->vmdq_nb_qps - 1) {
1647 PMD_INIT_LOG(ERR, "queue_idx out of range. VMDQ configured?");
1651 return pf->vmdq[queue_idx / pf->vmdq_nb_qps].vsi;
1655 i40e_get_queue_offset_by_qindex(struct i40e_pf *pf, uint16_t queue_idx)
1657 /* the queue in MAIN VSI range */
1658 if (queue_idx < pf->main_vsi->nb_qps)
1661 /* It's VMDQ queues */
1662 queue_idx -= pf->main_vsi->nb_qps;
1664 if (pf->nb_cfg_vmdq_vsi)
1665 return queue_idx % pf->vmdq_nb_qps;
1667 PMD_INIT_LOG(ERR, "Fail to get queue offset");
1668 return (uint16_t)(-1);
1673 i40e_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1675 struct i40e_rx_queue *rxq;
1677 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1679 PMD_INIT_FUNC_TRACE();
1681 rxq = dev->data->rx_queues[rx_queue_id];
1682 if (!rxq || !rxq->q_set) {
1683 PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
1688 if (rxq->rx_deferred_start)
1689 PMD_DRV_LOG(WARNING, "RX queue %u is deferrd start",
1692 err = i40e_alloc_rx_queue_mbufs(rxq);
1694 PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
1698 /* Init the RX tail regieter. */
1699 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
1701 err = i40e_switch_rx_queue(hw, rxq->reg_idx, TRUE);
1703 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
1706 i40e_rx_queue_release_mbufs(rxq);
1707 i40e_reset_rx_queue(rxq);
1710 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1716 i40e_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1718 struct i40e_rx_queue *rxq;
1720 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1722 rxq = dev->data->rx_queues[rx_queue_id];
1723 if (!rxq || !rxq->q_set) {
1724 PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
1730 * rx_queue_id is queue id application refers to, while
1731 * rxq->reg_idx is the real queue index.
1733 err = i40e_switch_rx_queue(hw, rxq->reg_idx, FALSE);
1735 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
1739 i40e_rx_queue_release_mbufs(rxq);
1740 i40e_reset_rx_queue(rxq);
1741 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1747 i40e_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1750 struct i40e_tx_queue *txq;
1751 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1753 PMD_INIT_FUNC_TRACE();
1755 txq = dev->data->tx_queues[tx_queue_id];
1756 if (!txq || !txq->q_set) {
1757 PMD_DRV_LOG(ERR, "TX queue %u is not available or setup",
1762 if (txq->tx_deferred_start)
1763 PMD_DRV_LOG(WARNING, "TX queue %u is deferrd start",
1767 * tx_queue_id is queue id application refers to, while
1768 * rxq->reg_idx is the real queue index.
1770 err = i40e_switch_tx_queue(hw, txq->reg_idx, TRUE);
1772 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
1776 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1782 i40e_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1784 struct i40e_tx_queue *txq;
1786 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1788 txq = dev->data->tx_queues[tx_queue_id];
1789 if (!txq || !txq->q_set) {
1790 PMD_DRV_LOG(ERR, "TX queue %u is not available or setup",
1796 * tx_queue_id is queue id application refers to, while
1797 * txq->reg_idx is the real queue index.
1799 err = i40e_switch_tx_queue(hw, txq->reg_idx, FALSE);
1801 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u of",
1806 i40e_tx_queue_release_mbufs(txq);
1807 i40e_reset_tx_queue(txq);
1808 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1814 i40e_dev_supported_ptypes_get(struct rte_eth_dev *dev)
1816 static const uint32_t ptypes[] = {
1817 /* refers to i40e_rxd_pkt_type_mapping() */
1819 RTE_PTYPE_L2_ETHER_TIMESYNC,
1820 RTE_PTYPE_L2_ETHER_LLDP,
1821 RTE_PTYPE_L2_ETHER_ARP,
1822 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1823 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
1826 RTE_PTYPE_L4_NONFRAG,
1830 RTE_PTYPE_TUNNEL_GRENAT,
1831 RTE_PTYPE_TUNNEL_IP,
1832 RTE_PTYPE_INNER_L2_ETHER,
1833 RTE_PTYPE_INNER_L2_ETHER_VLAN,
1834 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
1835 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
1836 RTE_PTYPE_INNER_L4_FRAG,
1837 RTE_PTYPE_INNER_L4_ICMP,
1838 RTE_PTYPE_INNER_L4_NONFRAG,
1839 RTE_PTYPE_INNER_L4_SCTP,
1840 RTE_PTYPE_INNER_L4_TCP,
1841 RTE_PTYPE_INNER_L4_UDP,
1845 if (dev->rx_pkt_burst == i40e_recv_pkts ||
1846 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1847 dev->rx_pkt_burst == i40e_recv_pkts_bulk_alloc ||
1849 dev->rx_pkt_burst == i40e_recv_scattered_pkts ||
1850 dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec ||
1851 dev->rx_pkt_burst == i40e_recv_pkts_vec ||
1852 #ifdef CC_AVX512_SUPPORT
1853 dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx512 ||
1854 dev->rx_pkt_burst == i40e_recv_pkts_vec_avx512 ||
1856 dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx2 ||
1857 dev->rx_pkt_burst == i40e_recv_pkts_vec_avx2)
1863 i40e_dev_first_queue(uint16_t idx, void **queues, int num)
1867 for (i = 0; i < num; i++) {
1868 if (i != idx && queues[i])
1876 i40e_dev_rx_queue_setup_runtime(struct rte_eth_dev *dev,
1877 struct i40e_rx_queue *rxq)
1879 struct i40e_adapter *ad =
1880 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1881 int use_def_burst_func =
1882 check_rx_burst_bulk_alloc_preconditions(rxq);
1884 (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
1885 RTE_PKTMBUF_HEADROOM);
1886 int use_scattered_rx =
1887 (rxq->max_pkt_len > buf_size);
1889 if (i40e_rx_queue_init(rxq) != I40E_SUCCESS) {
1891 "Failed to do RX queue initialization");
1895 if (i40e_dev_first_queue(rxq->queue_id,
1896 dev->data->rx_queues,
1897 dev->data->nb_rx_queues)) {
1899 * If it is the first queue to setup,
1900 * set all flags to default and call
1901 * i40e_set_rx_function.
1903 ad->rx_bulk_alloc_allowed = true;
1904 ad->rx_vec_allowed = true;
1905 dev->data->scattered_rx = use_scattered_rx;
1906 if (use_def_burst_func)
1907 ad->rx_bulk_alloc_allowed = false;
1908 i40e_set_rx_function(dev);
1910 } else if (ad->rx_vec_allowed && !rte_is_power_of_2(rxq->nb_rx_desc)) {
1911 PMD_DRV_LOG(ERR, "Vector mode is allowed, but descriptor"
1912 " number %d of queue %d isn't power of 2",
1913 rxq->nb_rx_desc, rxq->queue_id);
1917 /* check bulk alloc conflict */
1918 if (ad->rx_bulk_alloc_allowed && use_def_burst_func) {
1919 PMD_DRV_LOG(ERR, "Can't use default burst.");
1922 /* check scatterred conflict */
1923 if (!dev->data->scattered_rx && use_scattered_rx) {
1924 PMD_DRV_LOG(ERR, "Scattered rx is required.");
1927 /* check vector conflict */
1928 if (ad->rx_vec_allowed && i40e_rxq_vec_setup(rxq)) {
1929 PMD_DRV_LOG(ERR, "Failed vector rx setup.");
1937 i40e_dev_rx_queue_setup(struct rte_eth_dev *dev,
1940 unsigned int socket_id,
1941 const struct rte_eth_rxconf *rx_conf,
1942 struct rte_mempool *mp)
1944 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1945 struct i40e_adapter *ad =
1946 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1947 struct i40e_vsi *vsi;
1948 struct i40e_pf *pf = NULL;
1949 struct i40e_vf *vf = NULL;
1950 struct i40e_rx_queue *rxq;
1951 const struct rte_memzone *rz;
1954 uint16_t reg_idx, base, bsf, tc_mapping;
1955 int q_offset, use_def_burst_func = 1;
1958 offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
1960 if (hw->mac.type == I40E_MAC_VF || hw->mac.type == I40E_MAC_X722_VF) {
1961 vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1965 reg_idx = queue_idx;
1967 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1968 vsi = i40e_pf_get_vsi_by_qindex(pf, queue_idx);
1971 q_offset = i40e_get_queue_offset_by_qindex(pf, queue_idx);
1974 reg_idx = vsi->base_queue + q_offset;
1977 if (nb_desc % I40E_ALIGN_RING_DESC != 0 ||
1978 (nb_desc > I40E_MAX_RING_DESC) ||
1979 (nb_desc < I40E_MIN_RING_DESC)) {
1980 PMD_DRV_LOG(ERR, "Number (%u) of receive descriptors is "
1981 "invalid", nb_desc);
1985 /* Free memory if needed */
1986 if (dev->data->rx_queues[queue_idx]) {
1987 i40e_dev_rx_queue_release(dev->data->rx_queues[queue_idx]);
1988 dev->data->rx_queues[queue_idx] = NULL;
1991 /* Allocate the rx queue data structure */
1992 rxq = rte_zmalloc_socket("i40e rx queue",
1993 sizeof(struct i40e_rx_queue),
1994 RTE_CACHE_LINE_SIZE,
1997 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
1998 "rx queue data structure");
2002 rxq->nb_rx_desc = nb_desc;
2003 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
2004 rxq->queue_id = queue_idx;
2005 rxq->reg_idx = reg_idx;
2006 rxq->port_id = dev->data->port_id;
2007 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC)
2008 rxq->crc_len = RTE_ETHER_CRC_LEN;
2011 rxq->drop_en = rx_conf->rx_drop_en;
2013 rxq->rx_deferred_start = rx_conf->rx_deferred_start;
2014 rxq->offloads = offloads;
2016 /* Allocate the maximun number of RX ring hardware descriptor. */
2017 len = I40E_MAX_RING_DESC;
2020 * Allocating a little more memory because vectorized/bulk_alloc Rx
2021 * functions doesn't check boundaries each time.
2023 len += RTE_PMD_I40E_RX_MAX_BURST;
2025 ring_size = RTE_ALIGN(len * sizeof(union i40e_rx_desc),
2026 I40E_DMA_MEM_ALIGN);
2028 rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
2029 ring_size, I40E_RING_BASE_ALIGN, socket_id);
2031 i40e_dev_rx_queue_release(rxq);
2032 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX");
2036 /* Zero all the descriptors in the ring. */
2037 memset(rz->addr, 0, ring_size);
2039 rxq->rx_ring_phys_addr = rz->iova;
2040 rxq->rx_ring = (union i40e_rx_desc *)rz->addr;
2042 len = (uint16_t)(nb_desc + RTE_PMD_I40E_RX_MAX_BURST);
2044 /* Allocate the software ring. */
2046 rte_zmalloc_socket("i40e rx sw ring",
2047 sizeof(struct i40e_rx_entry) * len,
2048 RTE_CACHE_LINE_SIZE,
2050 if (!rxq->sw_ring) {
2051 i40e_dev_rx_queue_release(rxq);
2052 PMD_DRV_LOG(ERR, "Failed to allocate memory for SW ring");
2056 i40e_reset_rx_queue(rxq);
2059 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
2060 if (!(vsi->enabled_tc & (1 << i)))
2062 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
2063 base = (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
2064 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
2065 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
2066 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
2068 if (queue_idx >= base && queue_idx < (base + BIT(bsf)))
2072 if (dev->data->dev_started) {
2073 if (i40e_dev_rx_queue_setup_runtime(dev, rxq)) {
2074 i40e_dev_rx_queue_release(rxq);
2078 use_def_burst_func =
2079 check_rx_burst_bulk_alloc_preconditions(rxq);
2080 if (!use_def_burst_func) {
2081 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2083 "Rx Burst Bulk Alloc Preconditions are "
2084 "satisfied. Rx Burst Bulk Alloc function will be "
2085 "used on port=%d, queue=%d.",
2086 rxq->port_id, rxq->queue_id);
2087 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2090 "Rx Burst Bulk Alloc Preconditions are "
2091 "not satisfied, Scattered Rx is requested, "
2092 "or RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC is "
2093 "not enabled on port=%d, queue=%d.",
2094 rxq->port_id, rxq->queue_id);
2095 ad->rx_bulk_alloc_allowed = false;
2099 dev->data->rx_queues[queue_idx] = rxq;
2104 i40e_dev_rx_queue_release(void *rxq)
2106 struct i40e_rx_queue *q = (struct i40e_rx_queue *)rxq;
2109 PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
2113 i40e_rx_queue_release_mbufs(q);
2114 rte_free(q->sw_ring);
2119 i40e_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
2121 #define I40E_RXQ_SCAN_INTERVAL 4
2122 volatile union i40e_rx_desc *rxdp;
2123 struct i40e_rx_queue *rxq;
2126 rxq = dev->data->rx_queues[rx_queue_id];
2127 rxdp = &(rxq->rx_ring[rxq->rx_tail]);
2128 while ((desc < rxq->nb_rx_desc) &&
2129 ((rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
2130 I40E_RXD_QW1_STATUS_MASK) >> I40E_RXD_QW1_STATUS_SHIFT) &
2131 (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
2133 * Check the DD bit of a rx descriptor of each 4 in a group,
2134 * to avoid checking too frequently and downgrading performance
2137 desc += I40E_RXQ_SCAN_INTERVAL;
2138 rxdp += I40E_RXQ_SCAN_INTERVAL;
2139 if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
2140 rxdp = &(rxq->rx_ring[rxq->rx_tail +
2141 desc - rxq->nb_rx_desc]);
2148 i40e_dev_rx_descriptor_done(void *rx_queue, uint16_t offset)
2150 volatile union i40e_rx_desc *rxdp;
2151 struct i40e_rx_queue *rxq = rx_queue;
2155 if (unlikely(offset >= rxq->nb_rx_desc)) {
2156 PMD_DRV_LOG(ERR, "Invalid RX descriptor id %u", offset);
2160 desc = rxq->rx_tail + offset;
2161 if (desc >= rxq->nb_rx_desc)
2162 desc -= rxq->nb_rx_desc;
2164 rxdp = &(rxq->rx_ring[desc]);
2166 ret = !!(((rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
2167 I40E_RXD_QW1_STATUS_MASK) >> I40E_RXD_QW1_STATUS_SHIFT) &
2168 (1 << I40E_RX_DESC_STATUS_DD_SHIFT));
2174 i40e_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
2176 struct i40e_rx_queue *rxq = rx_queue;
2177 volatile uint64_t *status;
2181 if (unlikely(offset >= rxq->nb_rx_desc))
2184 if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
2185 return RTE_ETH_RX_DESC_UNAVAIL;
2187 desc = rxq->rx_tail + offset;
2188 if (desc >= rxq->nb_rx_desc)
2189 desc -= rxq->nb_rx_desc;
2191 status = &rxq->rx_ring[desc].wb.qword1.status_error_len;
2192 mask = rte_le_to_cpu_64((1ULL << I40E_RX_DESC_STATUS_DD_SHIFT)
2193 << I40E_RXD_QW1_STATUS_SHIFT);
2195 return RTE_ETH_RX_DESC_DONE;
2197 return RTE_ETH_RX_DESC_AVAIL;
2201 i40e_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
2203 struct i40e_tx_queue *txq = tx_queue;
2204 volatile uint64_t *status;
2205 uint64_t mask, expect;
2208 if (unlikely(offset >= txq->nb_tx_desc))
2211 desc = txq->tx_tail + offset;
2212 /* go to next desc that has the RS bit */
2213 desc = ((desc + txq->tx_rs_thresh - 1) / txq->tx_rs_thresh) *
2215 if (desc >= txq->nb_tx_desc) {
2216 desc -= txq->nb_tx_desc;
2217 if (desc >= txq->nb_tx_desc)
2218 desc -= txq->nb_tx_desc;
2221 status = &txq->tx_ring[desc].cmd_type_offset_bsz;
2222 mask = rte_le_to_cpu_64(I40E_TXD_QW1_DTYPE_MASK);
2223 expect = rte_cpu_to_le_64(
2224 I40E_TX_DESC_DTYPE_DESC_DONE << I40E_TXD_QW1_DTYPE_SHIFT);
2225 if ((*status & mask) == expect)
2226 return RTE_ETH_TX_DESC_DONE;
2228 return RTE_ETH_TX_DESC_FULL;
2232 i40e_dev_tx_queue_setup_runtime(struct rte_eth_dev *dev,
2233 struct i40e_tx_queue *txq)
2235 struct i40e_adapter *ad =
2236 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2238 if (i40e_tx_queue_init(txq) != I40E_SUCCESS) {
2240 "Failed to do TX queue initialization");
2244 if (i40e_dev_first_queue(txq->queue_id,
2245 dev->data->tx_queues,
2246 dev->data->nb_tx_queues)) {
2248 * If it is the first queue to setup,
2249 * set all flags and call
2250 * i40e_set_tx_function.
2252 i40e_set_tx_function_flag(dev, txq);
2253 i40e_set_tx_function(dev);
2257 /* check vector conflict */
2258 if (ad->tx_vec_allowed) {
2259 if (txq->tx_rs_thresh > RTE_I40E_TX_MAX_FREE_BUF_SZ ||
2260 i40e_txq_vec_setup(txq)) {
2261 PMD_DRV_LOG(ERR, "Failed vector tx setup.");
2265 /* check simple tx conflict */
2266 if (ad->tx_simple_allowed) {
2267 if ((txq->offloads & ~DEV_TX_OFFLOAD_MBUF_FAST_FREE) != 0 ||
2268 txq->tx_rs_thresh < RTE_PMD_I40E_TX_MAX_BURST) {
2269 PMD_DRV_LOG(ERR, "No-simple tx is required.");
2278 i40e_dev_tx_queue_setup(struct rte_eth_dev *dev,
2281 unsigned int socket_id,
2282 const struct rte_eth_txconf *tx_conf)
2284 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2285 struct i40e_vsi *vsi;
2286 struct i40e_pf *pf = NULL;
2287 struct i40e_vf *vf = NULL;
2288 struct i40e_tx_queue *txq;
2289 const struct rte_memzone *tz;
2291 uint16_t tx_rs_thresh, tx_free_thresh;
2292 uint16_t reg_idx, i, base, bsf, tc_mapping;
2296 offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
2298 if (hw->mac.type == I40E_MAC_VF || hw->mac.type == I40E_MAC_X722_VF) {
2299 vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2301 reg_idx = queue_idx;
2303 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2304 vsi = i40e_pf_get_vsi_by_qindex(pf, queue_idx);
2307 q_offset = i40e_get_queue_offset_by_qindex(pf, queue_idx);
2310 reg_idx = vsi->base_queue + q_offset;
2313 if (nb_desc % I40E_ALIGN_RING_DESC != 0 ||
2314 (nb_desc > I40E_MAX_RING_DESC) ||
2315 (nb_desc < I40E_MIN_RING_DESC)) {
2316 PMD_DRV_LOG(ERR, "Number (%u) of transmit descriptors is "
2317 "invalid", nb_desc);
2322 * The following two parameters control the setting of the RS bit on
2323 * transmit descriptors. TX descriptors will have their RS bit set
2324 * after txq->tx_rs_thresh descriptors have been used. The TX
2325 * descriptor ring will be cleaned after txq->tx_free_thresh
2326 * descriptors are used or if the number of descriptors required to
2327 * transmit a packet is greater than the number of free TX descriptors.
2329 * The following constraints must be satisfied:
2330 * - tx_rs_thresh must be greater than 0.
2331 * - tx_rs_thresh must be less than the size of the ring minus 2.
2332 * - tx_rs_thresh must be less than or equal to tx_free_thresh.
2333 * - tx_rs_thresh must be a divisor of the ring size.
2334 * - tx_free_thresh must be greater than 0.
2335 * - tx_free_thresh must be less than the size of the ring minus 3.
2336 * - tx_free_thresh + tx_rs_thresh must not exceed nb_desc.
2338 * One descriptor in the TX ring is used as a sentinel to avoid a H/W
2339 * race condition, hence the maximum threshold constraints. When set
2340 * to zero use default values.
2342 tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
2343 tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
2344 /* force tx_rs_thresh to adapt an aggresive tx_free_thresh */
2345 tx_rs_thresh = (DEFAULT_TX_RS_THRESH + tx_free_thresh > nb_desc) ?
2346 nb_desc - tx_free_thresh : DEFAULT_TX_RS_THRESH;
2347 if (tx_conf->tx_rs_thresh > 0)
2348 tx_rs_thresh = tx_conf->tx_rs_thresh;
2349 if (tx_rs_thresh + tx_free_thresh > nb_desc) {
2350 PMD_INIT_LOG(ERR, "tx_rs_thresh + tx_free_thresh must not "
2351 "exceed nb_desc. (tx_rs_thresh=%u "
2352 "tx_free_thresh=%u nb_desc=%u port=%d queue=%d)",
2353 (unsigned int)tx_rs_thresh,
2354 (unsigned int)tx_free_thresh,
2355 (unsigned int)nb_desc,
2356 (int)dev->data->port_id,
2358 return I40E_ERR_PARAM;
2360 if (tx_rs_thresh >= (nb_desc - 2)) {
2361 PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than the "
2362 "number of TX descriptors minus 2. "
2363 "(tx_rs_thresh=%u port=%d queue=%d)",
2364 (unsigned int)tx_rs_thresh,
2365 (int)dev->data->port_id,
2367 return I40E_ERR_PARAM;
2369 if (tx_free_thresh >= (nb_desc - 3)) {
2370 PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the "
2371 "number of TX descriptors minus 3. "
2372 "(tx_free_thresh=%u port=%d queue=%d)",
2373 (unsigned int)tx_free_thresh,
2374 (int)dev->data->port_id,
2376 return I40E_ERR_PARAM;
2378 if (tx_rs_thresh > tx_free_thresh) {
2379 PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than or "
2380 "equal to tx_free_thresh. (tx_free_thresh=%u"
2381 " tx_rs_thresh=%u port=%d queue=%d)",
2382 (unsigned int)tx_free_thresh,
2383 (unsigned int)tx_rs_thresh,
2384 (int)dev->data->port_id,
2386 return I40E_ERR_PARAM;
2388 if ((nb_desc % tx_rs_thresh) != 0) {
2389 PMD_INIT_LOG(ERR, "tx_rs_thresh must be a divisor of the "
2390 "number of TX descriptors. (tx_rs_thresh=%u"
2391 " port=%d queue=%d)",
2392 (unsigned int)tx_rs_thresh,
2393 (int)dev->data->port_id,
2395 return I40E_ERR_PARAM;
2397 if ((tx_rs_thresh > 1) && (tx_conf->tx_thresh.wthresh != 0)) {
2398 PMD_INIT_LOG(ERR, "TX WTHRESH must be set to 0 if "
2399 "tx_rs_thresh is greater than 1. "
2400 "(tx_rs_thresh=%u port=%d queue=%d)",
2401 (unsigned int)tx_rs_thresh,
2402 (int)dev->data->port_id,
2404 return I40E_ERR_PARAM;
2407 /* Free memory if needed. */
2408 if (dev->data->tx_queues[queue_idx]) {
2409 i40e_dev_tx_queue_release(dev->data->tx_queues[queue_idx]);
2410 dev->data->tx_queues[queue_idx] = NULL;
2413 /* Allocate the TX queue data structure. */
2414 txq = rte_zmalloc_socket("i40e tx queue",
2415 sizeof(struct i40e_tx_queue),
2416 RTE_CACHE_LINE_SIZE,
2419 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
2420 "tx queue structure");
2424 /* Allocate TX hardware ring descriptors. */
2425 ring_size = sizeof(struct i40e_tx_desc) * I40E_MAX_RING_DESC;
2426 ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
2427 tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
2428 ring_size, I40E_RING_BASE_ALIGN, socket_id);
2430 i40e_dev_tx_queue_release(txq);
2431 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX");
2435 txq->nb_tx_desc = nb_desc;
2436 txq->tx_rs_thresh = tx_rs_thresh;
2437 txq->tx_free_thresh = tx_free_thresh;
2438 txq->pthresh = tx_conf->tx_thresh.pthresh;
2439 txq->hthresh = tx_conf->tx_thresh.hthresh;
2440 txq->wthresh = tx_conf->tx_thresh.wthresh;
2441 txq->queue_id = queue_idx;
2442 txq->reg_idx = reg_idx;
2443 txq->port_id = dev->data->port_id;
2444 txq->offloads = offloads;
2446 txq->tx_deferred_start = tx_conf->tx_deferred_start;
2448 txq->tx_ring_phys_addr = tz->iova;
2449 txq->tx_ring = (struct i40e_tx_desc *)tz->addr;
2451 /* Allocate software ring */
2453 rte_zmalloc_socket("i40e tx sw ring",
2454 sizeof(struct i40e_tx_entry) * nb_desc,
2455 RTE_CACHE_LINE_SIZE,
2457 if (!txq->sw_ring) {
2458 i40e_dev_tx_queue_release(txq);
2459 PMD_DRV_LOG(ERR, "Failed to allocate memory for SW TX ring");
2463 i40e_reset_tx_queue(txq);
2466 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
2467 if (!(vsi->enabled_tc & (1 << i)))
2469 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
2470 base = (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
2471 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
2472 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
2473 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
2475 if (queue_idx >= base && queue_idx < (base + BIT(bsf)))
2479 if (dev->data->dev_started) {
2480 if (i40e_dev_tx_queue_setup_runtime(dev, txq)) {
2481 i40e_dev_tx_queue_release(txq);
2486 * Use a simple TX queue without offloads or
2487 * multi segs if possible
2489 i40e_set_tx_function_flag(dev, txq);
2491 dev->data->tx_queues[queue_idx] = txq;
2497 i40e_dev_tx_queue_release(void *txq)
2499 struct i40e_tx_queue *q = (struct i40e_tx_queue *)txq;
2502 PMD_DRV_LOG(DEBUG, "Pointer to TX queue is NULL");
2506 i40e_tx_queue_release_mbufs(q);
2507 rte_free(q->sw_ring);
2511 const struct rte_memzone *
2512 i40e_memzone_reserve(const char *name, uint32_t len, int socket_id)
2514 const struct rte_memzone *mz;
2516 mz = rte_memzone_lookup(name);
2520 mz = rte_memzone_reserve_aligned(name, len, socket_id,
2521 RTE_MEMZONE_IOVA_CONTIG, I40E_RING_BASE_ALIGN);
2526 i40e_rx_queue_release_mbufs(struct i40e_rx_queue *rxq)
2530 /* SSE Vector driver has a different way of releasing mbufs. */
2531 if (rxq->rx_using_sse) {
2532 i40e_rx_queue_release_mbufs_vec(rxq);
2536 if (!rxq->sw_ring) {
2537 PMD_DRV_LOG(DEBUG, "Pointer to sw_ring is NULL");
2541 for (i = 0; i < rxq->nb_rx_desc; i++) {
2542 if (rxq->sw_ring[i].mbuf) {
2543 rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
2544 rxq->sw_ring[i].mbuf = NULL;
2547 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2548 if (rxq->rx_nb_avail == 0)
2550 for (i = 0; i < rxq->rx_nb_avail; i++) {
2551 struct rte_mbuf *mbuf;
2553 mbuf = rxq->rx_stage[rxq->rx_next_avail + i];
2554 rte_pktmbuf_free_seg(mbuf);
2556 rxq->rx_nb_avail = 0;
2557 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2561 i40e_reset_rx_queue(struct i40e_rx_queue *rxq)
2567 PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
2571 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2572 if (check_rx_burst_bulk_alloc_preconditions(rxq) == 0)
2573 len = (uint16_t)(rxq->nb_rx_desc + RTE_PMD_I40E_RX_MAX_BURST);
2575 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2576 len = rxq->nb_rx_desc;
2578 for (i = 0; i < len * sizeof(union i40e_rx_desc); i++)
2579 ((volatile char *)rxq->rx_ring)[i] = 0;
2581 memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
2582 for (i = 0; i < RTE_PMD_I40E_RX_MAX_BURST; ++i)
2583 rxq->sw_ring[rxq->nb_rx_desc + i].mbuf = &rxq->fake_mbuf;
2585 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2586 rxq->rx_nb_avail = 0;
2587 rxq->rx_next_avail = 0;
2588 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2589 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2591 rxq->nb_rx_hold = 0;
2592 rxq->pkt_first_seg = NULL;
2593 rxq->pkt_last_seg = NULL;
2595 rxq->rxrearm_start = 0;
2596 rxq->rxrearm_nb = 0;
2600 i40e_tx_queue_release_mbufs(struct i40e_tx_queue *txq)
2602 struct rte_eth_dev *dev;
2605 if (!txq || !txq->sw_ring) {
2606 PMD_DRV_LOG(DEBUG, "Pointer to txq or sw_ring is NULL");
2610 dev = &rte_eth_devices[txq->port_id];
2613 * vPMD tx will not set sw_ring's mbuf to NULL after free,
2614 * so need to free remains more carefully.
2616 #ifdef CC_AVX512_SUPPORT
2617 if (dev->tx_pkt_burst == i40e_xmit_pkts_vec_avx512) {
2618 struct i40e_vec_tx_entry *swr = (void *)txq->sw_ring;
2620 i = txq->tx_next_dd - txq->tx_rs_thresh + 1;
2621 if (txq->tx_tail < i) {
2622 for (; i < txq->nb_tx_desc; i++) {
2623 rte_pktmbuf_free_seg(swr[i].mbuf);
2628 for (; i < txq->tx_tail; i++) {
2629 rte_pktmbuf_free_seg(swr[i].mbuf);
2635 if (dev->tx_pkt_burst == i40e_xmit_pkts_vec_avx2 ||
2636 dev->tx_pkt_burst == i40e_xmit_pkts_vec) {
2637 i = txq->tx_next_dd - txq->tx_rs_thresh + 1;
2638 if (txq->tx_tail < i) {
2639 for (; i < txq->nb_tx_desc; i++) {
2640 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2641 txq->sw_ring[i].mbuf = NULL;
2645 for (; i < txq->tx_tail; i++) {
2646 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2647 txq->sw_ring[i].mbuf = NULL;
2650 for (i = 0; i < txq->nb_tx_desc; i++) {
2651 if (txq->sw_ring[i].mbuf) {
2652 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2653 txq->sw_ring[i].mbuf = NULL;
2660 i40e_tx_done_cleanup_full(struct i40e_tx_queue *txq,
2663 struct i40e_tx_entry *swr_ring = txq->sw_ring;
2664 uint16_t i, tx_last, tx_id;
2665 uint16_t nb_tx_free_last;
2666 uint16_t nb_tx_to_clean;
2669 /* Start free mbuf from the next of tx_tail */
2670 tx_last = txq->tx_tail;
2671 tx_id = swr_ring[tx_last].next_id;
2673 if (txq->nb_tx_free == 0 && i40e_xmit_cleanup(txq))
2676 nb_tx_to_clean = txq->nb_tx_free;
2677 nb_tx_free_last = txq->nb_tx_free;
2679 free_cnt = txq->nb_tx_desc;
2681 /* Loop through swr_ring to count the amount of
2682 * freeable mubfs and packets.
2684 for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
2685 for (i = 0; i < nb_tx_to_clean &&
2686 pkt_cnt < free_cnt &&
2687 tx_id != tx_last; i++) {
2688 if (swr_ring[tx_id].mbuf != NULL) {
2689 rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
2690 swr_ring[tx_id].mbuf = NULL;
2693 * last segment in the packet,
2694 * increment packet count
2696 pkt_cnt += (swr_ring[tx_id].last_id == tx_id);
2699 tx_id = swr_ring[tx_id].next_id;
2702 if (txq->tx_rs_thresh > txq->nb_tx_desc -
2703 txq->nb_tx_free || tx_id == tx_last)
2706 if (pkt_cnt < free_cnt) {
2707 if (i40e_xmit_cleanup(txq))
2710 nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
2711 nb_tx_free_last = txq->nb_tx_free;
2715 return (int)pkt_cnt;
2719 i40e_tx_done_cleanup_simple(struct i40e_tx_queue *txq,
2724 if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
2725 free_cnt = txq->nb_tx_desc;
2727 cnt = free_cnt - free_cnt % txq->tx_rs_thresh;
2729 for (i = 0; i < cnt; i += n) {
2730 if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_rs_thresh)
2733 n = i40e_tx_free_bufs(txq);
2743 i40e_tx_done_cleanup_vec(struct i40e_tx_queue *txq __rte_unused,
2744 uint32_t free_cnt __rte_unused)
2749 i40e_tx_done_cleanup(void *txq, uint32_t free_cnt)
2751 struct i40e_tx_queue *q = (struct i40e_tx_queue *)txq;
2752 struct rte_eth_dev *dev = &rte_eth_devices[q->port_id];
2753 struct i40e_adapter *ad =
2754 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2756 if (ad->tx_simple_allowed) {
2757 if (ad->tx_vec_allowed)
2758 return i40e_tx_done_cleanup_vec(q, free_cnt);
2760 return i40e_tx_done_cleanup_simple(q, free_cnt);
2762 return i40e_tx_done_cleanup_full(q, free_cnt);
2767 i40e_reset_tx_queue(struct i40e_tx_queue *txq)
2769 struct i40e_tx_entry *txe;
2770 uint16_t i, prev, size;
2773 PMD_DRV_LOG(DEBUG, "Pointer to txq is NULL");
2778 size = sizeof(struct i40e_tx_desc) * txq->nb_tx_desc;
2779 for (i = 0; i < size; i++)
2780 ((volatile char *)txq->tx_ring)[i] = 0;
2782 prev = (uint16_t)(txq->nb_tx_desc - 1);
2783 for (i = 0; i < txq->nb_tx_desc; i++) {
2784 volatile struct i40e_tx_desc *txd = &txq->tx_ring[i];
2786 txd->cmd_type_offset_bsz =
2787 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE);
2790 txe[prev].next_id = i;
2794 txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
2795 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
2798 txq->nb_tx_used = 0;
2800 txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
2801 txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
2804 /* Init the TX queue in hardware */
2806 i40e_tx_queue_init(struct i40e_tx_queue *txq)
2808 enum i40e_status_code err = I40E_SUCCESS;
2809 struct i40e_vsi *vsi = txq->vsi;
2810 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2811 uint16_t pf_q = txq->reg_idx;
2812 struct i40e_hmc_obj_txq tx_ctx;
2815 /* clear the context structure first */
2816 memset(&tx_ctx, 0, sizeof(tx_ctx));
2817 tx_ctx.new_context = 1;
2818 tx_ctx.base = txq->tx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
2819 tx_ctx.qlen = txq->nb_tx_desc;
2821 #ifdef RTE_LIBRTE_IEEE1588
2822 tx_ctx.timesync_ena = 1;
2824 tx_ctx.rdylist = rte_le_to_cpu_16(vsi->info.qs_handle[txq->dcb_tc]);
2825 if (vsi->type == I40E_VSI_FDIR)
2826 tx_ctx.fd_ena = TRUE;
2828 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2829 if (err != I40E_SUCCESS) {
2830 PMD_DRV_LOG(ERR, "Failure of clean lan tx queue context");
2834 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2835 if (err != I40E_SUCCESS) {
2836 PMD_DRV_LOG(ERR, "Failure of set lan tx queue context");
2840 /* Now associate this queue with this PCI function */
2841 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
2842 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2843 I40E_QTX_CTL_PF_INDX_MASK);
2844 I40E_WRITE_REG(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2845 I40E_WRITE_FLUSH(hw);
2847 txq->qtx_tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2853 i40e_alloc_rx_queue_mbufs(struct i40e_rx_queue *rxq)
2855 struct i40e_rx_entry *rxe = rxq->sw_ring;
2859 for (i = 0; i < rxq->nb_rx_desc; i++) {
2860 volatile union i40e_rx_desc *rxd;
2861 struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mp);
2863 if (unlikely(!mbuf)) {
2864 PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX");
2868 rte_mbuf_refcnt_set(mbuf, 1);
2870 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
2872 mbuf->port = rxq->port_id;
2875 rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
2877 rxd = &rxq->rx_ring[i];
2878 rxd->read.pkt_addr = dma_addr;
2879 rxd->read.hdr_addr = 0;
2880 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2881 rxd->read.rsvd1 = 0;
2882 rxd->read.rsvd2 = 0;
2883 #endif /* RTE_LIBRTE_I40E_16BYTE_RX_DESC */
2892 * Calculate the buffer length, and check the jumbo frame
2893 * and maximum packet length.
2896 i40e_rx_queue_config(struct i40e_rx_queue *rxq)
2898 struct i40e_pf *pf = I40E_VSI_TO_PF(rxq->vsi);
2899 struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
2900 struct rte_eth_dev_data *data = pf->dev_data;
2903 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
2904 RTE_PKTMBUF_HEADROOM);
2906 switch (pf->flags & (I40E_FLAG_HEADER_SPLIT_DISABLED |
2907 I40E_FLAG_HEADER_SPLIT_ENABLED)) {
2908 case I40E_FLAG_HEADER_SPLIT_ENABLED: /* Not supported */
2909 rxq->rx_hdr_len = RTE_ALIGN(I40E_RXBUF_SZ_1024,
2910 (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
2911 rxq->rx_buf_len = RTE_ALIGN(I40E_RXBUF_SZ_2048,
2912 (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
2913 rxq->hs_mode = i40e_header_split_enabled;
2915 case I40E_FLAG_HEADER_SPLIT_DISABLED:
2917 rxq->rx_hdr_len = 0;
2918 rxq->rx_buf_len = RTE_ALIGN_FLOOR(buf_size,
2919 (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
2920 rxq->hs_mode = i40e_header_split_none;
2925 RTE_MIN((uint32_t)(hw->func_caps.rx_buf_chain_len *
2926 rxq->rx_buf_len), data->dev_conf.rxmode.max_rx_pkt_len);
2927 if (data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
2928 if (rxq->max_pkt_len <= I40E_ETH_MAX_LEN ||
2929 rxq->max_pkt_len > I40E_FRAME_SIZE_MAX) {
2930 PMD_DRV_LOG(ERR, "maximum packet length must "
2931 "be larger than %u and smaller than %u,"
2932 "as jumbo frame is enabled",
2933 (uint32_t)I40E_ETH_MAX_LEN,
2934 (uint32_t)I40E_FRAME_SIZE_MAX);
2935 return I40E_ERR_CONFIG;
2938 if (rxq->max_pkt_len < RTE_ETHER_MIN_LEN ||
2939 rxq->max_pkt_len > I40E_ETH_MAX_LEN) {
2940 PMD_DRV_LOG(ERR, "maximum packet length must be "
2941 "larger than %u and smaller than %u, "
2942 "as jumbo frame is disabled",
2943 (uint32_t)RTE_ETHER_MIN_LEN,
2944 (uint32_t)I40E_ETH_MAX_LEN);
2945 return I40E_ERR_CONFIG;
2952 /* Init the RX queue in hardware */
2954 i40e_rx_queue_init(struct i40e_rx_queue *rxq)
2956 int err = I40E_SUCCESS;
2957 struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
2958 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(rxq->vsi);
2959 uint16_t pf_q = rxq->reg_idx;
2961 struct i40e_hmc_obj_rxq rx_ctx;
2963 err = i40e_rx_queue_config(rxq);
2965 PMD_DRV_LOG(ERR, "Failed to config RX queue");
2969 /* Clear the context structure first */
2970 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
2971 rx_ctx.dbuff = rxq->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
2972 rx_ctx.hbuff = rxq->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
2974 rx_ctx.base = rxq->rx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
2975 rx_ctx.qlen = rxq->nb_rx_desc;
2976 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2979 rx_ctx.dtype = rxq->hs_mode;
2981 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_ALL;
2983 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
2984 rx_ctx.rxmax = rxq->max_pkt_len;
2985 rx_ctx.tphrdesc_ena = 1;
2986 rx_ctx.tphwdesc_ena = 1;
2987 rx_ctx.tphdata_ena = 1;
2988 rx_ctx.tphhead_ena = 1;
2989 rx_ctx.lrxqthresh = 2;
2990 rx_ctx.crcstrip = (rxq->crc_len == 0) ? 1 : 0;
2992 /* showiv indicates if inner VLAN is stripped inside of tunnel
2993 * packet. When set it to 1, vlan information is stripped from
2994 * the inner header, but the hardware does not put it in the
2995 * descriptor. So set it zero by default.
3000 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
3001 if (err != I40E_SUCCESS) {
3002 PMD_DRV_LOG(ERR, "Failed to clear LAN RX queue context");
3005 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
3006 if (err != I40E_SUCCESS) {
3007 PMD_DRV_LOG(ERR, "Failed to set LAN RX queue context");
3011 rxq->qrx_tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
3013 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
3014 RTE_PKTMBUF_HEADROOM);
3016 /* Check if scattered RX needs to be used. */
3017 if (rxq->max_pkt_len > buf_size)
3018 dev_data->scattered_rx = 1;
3020 /* Init the RX tail regieter. */
3021 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
3027 i40e_dev_clear_queues(struct rte_eth_dev *dev)
3031 PMD_INIT_FUNC_TRACE();
3033 for (i = 0; i < dev->data->nb_tx_queues; i++) {
3034 if (!dev->data->tx_queues[i])
3036 i40e_tx_queue_release_mbufs(dev->data->tx_queues[i]);
3037 i40e_reset_tx_queue(dev->data->tx_queues[i]);
3040 for (i = 0; i < dev->data->nb_rx_queues; i++) {
3041 if (!dev->data->rx_queues[i])
3043 i40e_rx_queue_release_mbufs(dev->data->rx_queues[i]);
3044 i40e_reset_rx_queue(dev->data->rx_queues[i]);
3049 i40e_dev_free_queues(struct rte_eth_dev *dev)
3053 PMD_INIT_FUNC_TRACE();
3055 for (i = 0; i < dev->data->nb_rx_queues; i++) {
3056 if (!dev->data->rx_queues[i])
3058 i40e_dev_rx_queue_release(dev->data->rx_queues[i]);
3059 dev->data->rx_queues[i] = NULL;
3060 rte_eth_dma_zone_free(dev, "rx_ring", i);
3063 for (i = 0; i < dev->data->nb_tx_queues; i++) {
3064 if (!dev->data->tx_queues[i])
3066 i40e_dev_tx_queue_release(dev->data->tx_queues[i]);
3067 dev->data->tx_queues[i] = NULL;
3068 rte_eth_dma_zone_free(dev, "tx_ring", i);
3072 enum i40e_status_code
3073 i40e_fdir_setup_tx_resources(struct i40e_pf *pf)
3075 struct i40e_tx_queue *txq;
3076 const struct rte_memzone *tz = NULL;
3077 struct rte_eth_dev *dev;
3081 PMD_DRV_LOG(ERR, "PF is not available");
3082 return I40E_ERR_BAD_PTR;
3085 dev = &rte_eth_devices[pf->dev_data->port_id];
3087 /* Allocate the TX queue data structure. */
3088 txq = rte_zmalloc_socket("i40e fdir tx queue",
3089 sizeof(struct i40e_tx_queue),
3090 RTE_CACHE_LINE_SIZE,
3093 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
3094 "tx queue structure.");
3095 return I40E_ERR_NO_MEMORY;
3098 /* Allocate TX hardware ring descriptors. */
3099 ring_size = sizeof(struct i40e_tx_desc) * I40E_FDIR_NUM_TX_DESC;
3100 ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
3102 tz = rte_eth_dma_zone_reserve(dev, "fdir_tx_ring",
3103 I40E_FDIR_QUEUE_ID, ring_size,
3104 I40E_RING_BASE_ALIGN, SOCKET_ID_ANY);
3106 i40e_dev_tx_queue_release(txq);
3107 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX.");
3108 return I40E_ERR_NO_MEMORY;
3111 txq->nb_tx_desc = I40E_FDIR_NUM_TX_DESC;
3112 txq->queue_id = I40E_FDIR_QUEUE_ID;
3113 txq->reg_idx = pf->fdir.fdir_vsi->base_queue;
3114 txq->vsi = pf->fdir.fdir_vsi;
3116 txq->tx_ring_phys_addr = tz->iova;
3117 txq->tx_ring = (struct i40e_tx_desc *)tz->addr;
3120 * don't need to allocate software ring and reset for the fdir
3121 * program queue just set the queue has been configured.
3125 pf->fdir.txq_available_buf_count = I40E_FDIR_PRG_PKT_CNT;
3127 return I40E_SUCCESS;
3130 enum i40e_status_code
3131 i40e_fdir_setup_rx_resources(struct i40e_pf *pf)
3133 struct i40e_rx_queue *rxq;
3134 const struct rte_memzone *rz = NULL;
3136 struct rte_eth_dev *dev;
3139 PMD_DRV_LOG(ERR, "PF is not available");
3140 return I40E_ERR_BAD_PTR;
3143 dev = &rte_eth_devices[pf->dev_data->port_id];
3145 /* Allocate the RX queue data structure. */
3146 rxq = rte_zmalloc_socket("i40e fdir rx queue",
3147 sizeof(struct i40e_rx_queue),
3148 RTE_CACHE_LINE_SIZE,
3151 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
3152 "rx queue structure.");
3153 return I40E_ERR_NO_MEMORY;
3156 /* Allocate RX hardware ring descriptors. */
3157 ring_size = sizeof(union i40e_rx_desc) * I40E_FDIR_NUM_RX_DESC;
3158 ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
3160 rz = rte_eth_dma_zone_reserve(dev, "fdir_rx_ring",
3161 I40E_FDIR_QUEUE_ID, ring_size,
3162 I40E_RING_BASE_ALIGN, SOCKET_ID_ANY);
3164 i40e_dev_rx_queue_release(rxq);
3165 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX.");
3166 return I40E_ERR_NO_MEMORY;
3169 rxq->nb_rx_desc = I40E_FDIR_NUM_RX_DESC;
3170 rxq->queue_id = I40E_FDIR_QUEUE_ID;
3171 rxq->reg_idx = pf->fdir.fdir_vsi->base_queue;
3172 rxq->vsi = pf->fdir.fdir_vsi;
3174 rxq->rx_ring_phys_addr = rz->iova;
3175 memset(rz->addr, 0, I40E_FDIR_NUM_RX_DESC * sizeof(union i40e_rx_desc));
3176 rxq->rx_ring = (union i40e_rx_desc *)rz->addr;
3179 * Don't need to allocate software ring and reset for the fdir
3180 * rx queue, just set the queue has been configured.
3185 return I40E_SUCCESS;
3189 i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
3190 struct rte_eth_rxq_info *qinfo)
3192 struct i40e_rx_queue *rxq;
3194 rxq = dev->data->rx_queues[queue_id];
3196 qinfo->mp = rxq->mp;
3197 qinfo->scattered_rx = dev->data->scattered_rx;
3198 qinfo->nb_desc = rxq->nb_rx_desc;
3200 qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
3201 qinfo->conf.rx_drop_en = rxq->drop_en;
3202 qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
3203 qinfo->conf.offloads = rxq->offloads;
3207 i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
3208 struct rte_eth_txq_info *qinfo)
3210 struct i40e_tx_queue *txq;
3212 txq = dev->data->tx_queues[queue_id];
3214 qinfo->nb_desc = txq->nb_tx_desc;
3216 qinfo->conf.tx_thresh.pthresh = txq->pthresh;
3217 qinfo->conf.tx_thresh.hthresh = txq->hthresh;
3218 qinfo->conf.tx_thresh.wthresh = txq->wthresh;
3220 qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
3221 qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
3222 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
3223 qinfo->conf.offloads = txq->offloads;
3227 get_avx_supported(bool request_avx512)
3230 if (request_avx512) {
3231 if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512 &&
3232 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1 &&
3233 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512BW) == 1)
3234 #ifdef CC_AVX512_SUPPORT
3238 "AVX512 is not supported in build env");
3242 if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256 &&
3243 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1 &&
3244 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1)
3245 #ifdef CC_AVX2_SUPPORT
3249 "AVX2 is not supported in build env");
3254 RTE_SET_USED(request_avx512);
3255 #endif /* RTE_ARCH_X86 */
3262 i40e_set_rx_function(struct rte_eth_dev *dev)
3264 struct i40e_adapter *ad =
3265 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3266 uint16_t rx_using_sse, i;
3267 /* In order to allow Vector Rx there are a few configuration
3268 * conditions to be met and Rx Bulk Allocation should be allowed.
3270 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3272 ad->rx_use_avx512 = false;
3273 ad->rx_use_avx2 = false;
3275 if (i40e_rx_vec_dev_conf_condition_check(dev) ||
3276 !ad->rx_bulk_alloc_allowed) {
3277 PMD_INIT_LOG(DEBUG, "Port[%d] doesn't meet"
3278 " Vector Rx preconditions",
3279 dev->data->port_id);
3281 ad->rx_vec_allowed = false;
3283 if (ad->rx_vec_allowed) {
3284 for (i = 0; i < dev->data->nb_rx_queues; i++) {
3285 struct i40e_rx_queue *rxq =
3286 dev->data->rx_queues[i];
3288 if (rxq && i40e_rxq_vec_setup(rxq)) {
3289 ad->rx_vec_allowed = false;
3294 ad->rx_use_avx512 = get_avx_supported(1);
3296 if (!ad->rx_use_avx512)
3297 ad->rx_use_avx2 = get_avx_supported(0);
3302 if (ad->rx_vec_allowed &&
3303 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
3305 if (dev->data->scattered_rx) {
3306 if (ad->rx_use_avx512) {
3307 #ifdef CC_AVX512_SUPPORT
3309 "Using AVX512 Vector Scattered Rx (port %d).",
3310 dev->data->port_id);
3312 i40e_recv_scattered_pkts_vec_avx512;
3316 "Using %sVector Scattered Rx (port %d).",
3317 ad->rx_use_avx2 ? "avx2 " : "",
3318 dev->data->port_id);
3319 dev->rx_pkt_burst = ad->rx_use_avx2 ?
3320 i40e_recv_scattered_pkts_vec_avx2 :
3321 i40e_recv_scattered_pkts_vec;
3324 if (ad->rx_use_avx512) {
3325 #ifdef CC_AVX512_SUPPORT
3327 "Using AVX512 Vector Rx (port %d).",
3328 dev->data->port_id);
3330 i40e_recv_pkts_vec_avx512;
3334 "Using %sVector Rx (port %d).",
3335 ad->rx_use_avx2 ? "avx2 " : "",
3336 dev->data->port_id);
3337 dev->rx_pkt_burst = ad->rx_use_avx2 ?
3338 i40e_recv_pkts_vec_avx2 :
3342 #else /* RTE_ARCH_X86 */
3343 if (dev->data->scattered_rx) {
3345 "Using Vector Scattered Rx (port %d).",
3346 dev->data->port_id);
3347 dev->rx_pkt_burst = i40e_recv_scattered_pkts_vec;
3349 PMD_INIT_LOG(DEBUG, "Using Vector Rx (port %d).",
3350 dev->data->port_id);
3351 dev->rx_pkt_burst = i40e_recv_pkts_vec;
3353 #endif /* RTE_ARCH_X86 */
3354 } else if (!dev->data->scattered_rx && ad->rx_bulk_alloc_allowed) {
3355 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
3356 "satisfied. Rx Burst Bulk Alloc function "
3357 "will be used on port=%d.",
3358 dev->data->port_id);
3360 dev->rx_pkt_burst = i40e_recv_pkts_bulk_alloc;
3362 /* Simple Rx Path. */
3363 PMD_INIT_LOG(DEBUG, "Simple Rx path will be used on port=%d.",
3364 dev->data->port_id);
3365 dev->rx_pkt_burst = dev->data->scattered_rx ?
3366 i40e_recv_scattered_pkts :
3370 /* Propagate information about RX function choice through all queues. */
3371 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3373 (dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec ||
3374 dev->rx_pkt_burst == i40e_recv_pkts_vec ||
3375 #ifdef CC_AVX512_SUPPORT
3376 dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx512 ||
3377 dev->rx_pkt_burst == i40e_recv_pkts_vec_avx512 ||
3379 dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx2 ||
3380 dev->rx_pkt_burst == i40e_recv_pkts_vec_avx2);
3382 for (i = 0; i < dev->data->nb_rx_queues; i++) {
3383 struct i40e_rx_queue *rxq = dev->data->rx_queues[i];
3386 rxq->rx_using_sse = rx_using_sse;
3391 static const struct {
3392 eth_rx_burst_t pkt_burst;
3394 } i40e_rx_burst_infos[] = {
3395 { i40e_recv_scattered_pkts, "Scalar Scattered" },
3396 { i40e_recv_pkts_bulk_alloc, "Scalar Bulk Alloc" },
3397 { i40e_recv_pkts, "Scalar" },
3399 #ifdef CC_AVX512_SUPPORT
3400 { i40e_recv_scattered_pkts_vec_avx512, "Vector AVX512 Scattered" },
3401 { i40e_recv_pkts_vec_avx512, "Vector AVX512" },
3403 { i40e_recv_scattered_pkts_vec_avx2, "Vector AVX2 Scattered" },
3404 { i40e_recv_pkts_vec_avx2, "Vector AVX2" },
3405 { i40e_recv_scattered_pkts_vec, "Vector SSE Scattered" },
3406 { i40e_recv_pkts_vec, "Vector SSE" },
3407 #elif defined(RTE_ARCH_ARM64)
3408 { i40e_recv_scattered_pkts_vec, "Vector Neon Scattered" },
3409 { i40e_recv_pkts_vec, "Vector Neon" },
3410 #elif defined(RTE_ARCH_PPC_64)
3411 { i40e_recv_scattered_pkts_vec, "Vector AltiVec Scattered" },
3412 { i40e_recv_pkts_vec, "Vector AltiVec" },
3417 i40e_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
3418 struct rte_eth_burst_mode *mode)
3420 eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
3424 for (i = 0; i < RTE_DIM(i40e_rx_burst_infos); ++i) {
3425 if (pkt_burst == i40e_rx_burst_infos[i].pkt_burst) {
3426 snprintf(mode->info, sizeof(mode->info), "%s",
3427 i40e_rx_burst_infos[i].info);
3437 i40e_set_tx_function_flag(struct rte_eth_dev *dev, struct i40e_tx_queue *txq)
3439 struct i40e_adapter *ad =
3440 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3442 /* Use a simple Tx queue if possible (only fast free is allowed) */
3443 ad->tx_simple_allowed =
3445 (txq->offloads & DEV_TX_OFFLOAD_MBUF_FAST_FREE) &&
3446 txq->tx_rs_thresh >= RTE_PMD_I40E_TX_MAX_BURST);
3447 ad->tx_vec_allowed = (ad->tx_simple_allowed &&
3448 txq->tx_rs_thresh <= RTE_I40E_TX_MAX_FREE_BUF_SZ);
3450 if (ad->tx_vec_allowed)
3451 PMD_INIT_LOG(DEBUG, "Vector Tx can be enabled on Tx queue %u.",
3453 else if (ad->tx_simple_allowed)
3454 PMD_INIT_LOG(DEBUG, "Simple Tx can be enabled on Tx queue %u.",
3458 "Neither simple nor vector Tx enabled on Tx queue %u\n",
3463 i40e_set_tx_function(struct rte_eth_dev *dev)
3465 struct i40e_adapter *ad =
3466 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3469 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3471 ad->tx_use_avx2 = false;
3472 ad->tx_use_avx512 = false;
3474 if (ad->tx_vec_allowed) {
3475 for (i = 0; i < dev->data->nb_tx_queues; i++) {
3476 struct i40e_tx_queue *txq =
3477 dev->data->tx_queues[i];
3479 if (txq && i40e_txq_vec_setup(txq)) {
3480 ad->tx_vec_allowed = false;
3485 ad->tx_use_avx512 = get_avx_supported(1);
3487 if (!ad->tx_use_avx512)
3488 ad->tx_use_avx2 = get_avx_supported(0);
3493 if (ad->tx_simple_allowed) {
3494 if (ad->tx_vec_allowed &&
3495 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
3497 if (ad->tx_use_avx512) {
3498 #ifdef CC_AVX512_SUPPORT
3499 PMD_DRV_LOG(NOTICE, "Using AVX512 Vector Tx (port %d).",
3500 dev->data->port_id);
3501 dev->tx_pkt_burst = i40e_xmit_pkts_vec_avx512;
3504 PMD_INIT_LOG(DEBUG, "Using %sVector Tx (port %d).",
3505 ad->tx_use_avx2 ? "avx2 " : "",
3506 dev->data->port_id);
3507 dev->tx_pkt_burst = ad->tx_use_avx2 ?
3508 i40e_xmit_pkts_vec_avx2 :
3511 #else /* RTE_ARCH_X86 */
3512 PMD_INIT_LOG(DEBUG, "Using Vector Tx (port %d).",
3513 dev->data->port_id);
3514 dev->tx_pkt_burst = i40e_xmit_pkts_vec;
3515 #endif /* RTE_ARCH_X86 */
3517 PMD_INIT_LOG(DEBUG, "Simple tx finally be used.");
3518 dev->tx_pkt_burst = i40e_xmit_pkts_simple;
3520 dev->tx_pkt_prepare = i40e_simple_prep_pkts;
3522 PMD_INIT_LOG(DEBUG, "Xmit tx finally be used.");
3523 dev->tx_pkt_burst = i40e_xmit_pkts;
3524 dev->tx_pkt_prepare = i40e_prep_pkts;
3528 static const struct {
3529 eth_tx_burst_t pkt_burst;
3531 } i40e_tx_burst_infos[] = {
3532 { i40e_xmit_pkts_simple, "Scalar Simple" },
3533 { i40e_xmit_pkts, "Scalar" },
3535 #ifdef CC_AVX512_SUPPORT
3536 { i40e_xmit_pkts_vec_avx512, "Vector AVX512" },
3538 { i40e_xmit_pkts_vec_avx2, "Vector AVX2" },
3539 { i40e_xmit_pkts_vec, "Vector SSE" },
3540 #elif defined(RTE_ARCH_ARM64)
3541 { i40e_xmit_pkts_vec, "Vector Neon" },
3542 #elif defined(RTE_ARCH_PPC_64)
3543 { i40e_xmit_pkts_vec, "Vector AltiVec" },
3548 i40e_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
3549 struct rte_eth_burst_mode *mode)
3551 eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
3555 for (i = 0; i < RTE_DIM(i40e_tx_burst_infos); ++i) {
3556 if (pkt_burst == i40e_tx_burst_infos[i].pkt_burst) {
3557 snprintf(mode->info, sizeof(mode->info), "%s",
3558 i40e_tx_burst_infos[i].info);
3568 i40e_set_default_ptype_table(struct rte_eth_dev *dev)
3570 struct i40e_adapter *ad =
3571 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3574 for (i = 0; i < I40E_MAX_PKT_TYPE; i++)
3575 ad->ptype_tbl[i] = i40e_get_default_pkt_type(i);
3579 i40e_set_default_pctype_table(struct rte_eth_dev *dev)
3581 struct i40e_adapter *ad =
3582 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3583 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3586 for (i = 0; i < I40E_FLOW_TYPE_MAX; i++)
3587 ad->pctypes_tbl[i] = 0ULL;
3588 ad->flow_types_mask = 0ULL;
3589 ad->pctypes_mask = 0ULL;
3591 ad->pctypes_tbl[RTE_ETH_FLOW_FRAG_IPV4] =
3592 (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4);
3593 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] =
3594 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP);
3595 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_TCP] =
3596 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
3597 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_SCTP] =
3598 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP);
3599 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_OTHER] =
3600 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
3601 ad->pctypes_tbl[RTE_ETH_FLOW_FRAG_IPV6] =
3602 (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6);
3603 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] =
3604 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP);
3605 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_TCP] =
3606 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
3607 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_SCTP] =
3608 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP);
3609 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_OTHER] =
3610 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
3611 ad->pctypes_tbl[RTE_ETH_FLOW_L2_PAYLOAD] =
3612 (1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD);
3614 if (hw->mac.type == I40E_MAC_X722 ||
3615 hw->mac.type == I40E_MAC_X722_VF) {
3616 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] |=
3617 (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP);
3618 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] |=
3619 (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
3620 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_TCP] |=
3621 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
3622 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] |=
3623 (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP);
3624 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] |=
3625 (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
3626 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_TCP] |=
3627 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
3630 for (i = 0; i < I40E_FLOW_TYPE_MAX; i++) {
3631 if (ad->pctypes_tbl[i])
3632 ad->flow_types_mask |= (1ULL << i);
3633 ad->pctypes_mask |= ad->pctypes_tbl[i];
3637 #ifndef CC_AVX2_SUPPORT
3639 i40e_recv_pkts_vec_avx2(void __rte_unused *rx_queue,
3640 struct rte_mbuf __rte_unused **rx_pkts,
3641 uint16_t __rte_unused nb_pkts)
3647 i40e_recv_scattered_pkts_vec_avx2(void __rte_unused *rx_queue,
3648 struct rte_mbuf __rte_unused **rx_pkts,
3649 uint16_t __rte_unused nb_pkts)
3655 i40e_xmit_pkts_vec_avx2(void __rte_unused * tx_queue,
3656 struct rte_mbuf __rte_unused **tx_pkts,
3657 uint16_t __rte_unused nb_pkts)
3661 #endif /* ifndef CC_AVX2_SUPPORT */