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_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc)
87 struct i40e_rx_queue *rxq = rx_queue;
88 volatile union i40e_rx_desc *rxdp;
92 rxdp = &rxq->rx_ring[desc];
93 /* watch for changes in status bit */
94 pmc->addr = &rxdp->wb.qword1.status_error_len;
97 * we expect the DD bit to be set to 1 if this descriptor was already
100 pmc->val = rte_cpu_to_le_64(1 << I40E_RX_DESC_STATUS_DD_SHIFT);
101 pmc->mask = rte_cpu_to_le_64(1 << I40E_RX_DESC_STATUS_DD_SHIFT);
103 /* registers are 64-bit */
104 pmc->size = sizeof(uint64_t);
110 i40e_rxd_to_vlan_tci(struct rte_mbuf *mb, volatile union i40e_rx_desc *rxdp)
112 if (rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
113 (1 << I40E_RX_DESC_STATUS_L2TAG1P_SHIFT)) {
114 mb->ol_flags |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
116 rte_le_to_cpu_16(rxdp->wb.qword0.lo_dword.l2tag1);
117 PMD_RX_LOG(DEBUG, "Descriptor l2tag1: %u",
118 rte_le_to_cpu_16(rxdp->wb.qword0.lo_dword.l2tag1));
122 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
123 if (rte_le_to_cpu_16(rxdp->wb.qword2.ext_status) &
124 (1 << I40E_RX_DESC_EXT_STATUS_L2TAG2P_SHIFT)) {
125 mb->ol_flags |= PKT_RX_QINQ_STRIPPED | PKT_RX_QINQ |
126 PKT_RX_VLAN_STRIPPED | PKT_RX_VLAN;
127 mb->vlan_tci_outer = mb->vlan_tci;
128 mb->vlan_tci = rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_2);
129 PMD_RX_LOG(DEBUG, "Descriptor l2tag2_1: %u, l2tag2_2: %u",
130 rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_1),
131 rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_2));
133 mb->vlan_tci_outer = 0;
136 PMD_RX_LOG(DEBUG, "Mbuf vlan_tci: %u, vlan_tci_outer: %u",
137 mb->vlan_tci, mb->vlan_tci_outer);
140 /* Translate the rx descriptor status to pkt flags */
141 static inline uint64_t
142 i40e_rxd_status_to_pkt_flags(uint64_t qword)
146 /* Check if RSS_HASH */
147 flags = (((qword >> I40E_RX_DESC_STATUS_FLTSTAT_SHIFT) &
148 I40E_RX_DESC_FLTSTAT_RSS_HASH) ==
149 I40E_RX_DESC_FLTSTAT_RSS_HASH) ? PKT_RX_RSS_HASH : 0;
151 /* Check if FDIR Match */
152 flags |= (qword & (1 << I40E_RX_DESC_STATUS_FLM_SHIFT) ?
158 static inline uint64_t
159 i40e_rxd_error_to_pkt_flags(uint64_t qword)
162 uint64_t error_bits = (qword >> I40E_RXD_QW1_ERROR_SHIFT);
164 #define I40E_RX_ERR_BITS 0x3f
165 if (likely((error_bits & I40E_RX_ERR_BITS) == 0)) {
166 flags |= (PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD);
170 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_IPE_SHIFT)))
171 flags |= PKT_RX_IP_CKSUM_BAD;
173 flags |= PKT_RX_IP_CKSUM_GOOD;
175 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_L4E_SHIFT)))
176 flags |= PKT_RX_L4_CKSUM_BAD;
178 flags |= PKT_RX_L4_CKSUM_GOOD;
180 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_EIPE_SHIFT)))
181 flags |= PKT_RX_OUTER_IP_CKSUM_BAD;
186 /* Function to check and set the ieee1588 timesync index and get the
189 #ifdef RTE_LIBRTE_IEEE1588
190 static inline uint64_t
191 i40e_get_iee15888_flags(struct rte_mbuf *mb, uint64_t qword)
193 uint64_t pkt_flags = 0;
194 uint16_t tsyn = (qword & (I40E_RXD_QW1_STATUS_TSYNVALID_MASK
195 | I40E_RXD_QW1_STATUS_TSYNINDX_MASK))
196 >> I40E_RX_DESC_STATUS_TSYNINDX_SHIFT;
198 if ((mb->packet_type & RTE_PTYPE_L2_MASK)
199 == RTE_PTYPE_L2_ETHER_TIMESYNC)
200 pkt_flags = PKT_RX_IEEE1588_PTP;
202 pkt_flags |= PKT_RX_IEEE1588_TMST;
203 mb->timesync = tsyn & 0x03;
210 static inline uint64_t
211 i40e_rxd_build_fdir(volatile union i40e_rx_desc *rxdp, struct rte_mbuf *mb)
214 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
215 uint16_t flexbh, flexbl;
217 flexbh = (rte_le_to_cpu_32(rxdp->wb.qword2.ext_status) >>
218 I40E_RX_DESC_EXT_STATUS_FLEXBH_SHIFT) &
219 I40E_RX_DESC_EXT_STATUS_FLEXBH_MASK;
220 flexbl = (rte_le_to_cpu_32(rxdp->wb.qword2.ext_status) >>
221 I40E_RX_DESC_EXT_STATUS_FLEXBL_SHIFT) &
222 I40E_RX_DESC_EXT_STATUS_FLEXBL_MASK;
225 if (flexbh == I40E_RX_DESC_EXT_STATUS_FLEXBH_FD_ID) {
227 rte_le_to_cpu_32(rxdp->wb.qword3.hi_dword.fd_id);
228 flags |= PKT_RX_FDIR_ID;
229 } else if (flexbh == I40E_RX_DESC_EXT_STATUS_FLEXBH_FLEX) {
231 rte_le_to_cpu_32(rxdp->wb.qword3.hi_dword.flex_bytes_hi);
232 flags |= PKT_RX_FDIR_FLX;
234 if (flexbl == I40E_RX_DESC_EXT_STATUS_FLEXBL_FLEX) {
236 rte_le_to_cpu_32(rxdp->wb.qword3.lo_dword.flex_bytes_lo);
237 flags |= PKT_RX_FDIR_FLX;
241 rte_le_to_cpu_32(rxdp->wb.qword0.hi_dword.fd_id);
242 flags |= PKT_RX_FDIR_ID;
248 i40e_parse_tunneling_params(uint64_t ol_flags,
249 union i40e_tx_offload tx_offload,
250 uint32_t *cd_tunneling)
252 /* EIPT: External (outer) IP header type */
253 if (ol_flags & PKT_TX_OUTER_IP_CKSUM)
254 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV4;
255 else if (ol_flags & PKT_TX_OUTER_IPV4)
256 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV4_NO_CSUM;
257 else if (ol_flags & PKT_TX_OUTER_IPV6)
258 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV6;
260 /* EIPLEN: External (outer) IP header length, in DWords */
261 *cd_tunneling |= (tx_offload.outer_l3_len >> 2) <<
262 I40E_TXD_CTX_QW0_EXT_IPLEN_SHIFT;
264 /* L4TUNT: L4 Tunneling Type */
265 switch (ol_flags & PKT_TX_TUNNEL_MASK) {
266 case PKT_TX_TUNNEL_IPIP:
267 /* for non UDP / GRE tunneling, set to 00b */
269 case PKT_TX_TUNNEL_VXLAN:
270 case PKT_TX_TUNNEL_GENEVE:
271 *cd_tunneling |= I40E_TXD_CTX_UDP_TUNNELING;
273 case PKT_TX_TUNNEL_GRE:
274 *cd_tunneling |= I40E_TXD_CTX_GRE_TUNNELING;
277 PMD_TX_LOG(ERR, "Tunnel type not supported");
281 /* L4TUNLEN: L4 Tunneling Length, in Words
283 * We depend on app to set rte_mbuf.l2_len correctly.
284 * For IP in GRE it should be set to the length of the GRE
286 * for MAC in GRE or MAC in UDP it should be set to the length
287 * of the GRE or UDP headers plus the inner MAC up to including
288 * its last Ethertype.
290 *cd_tunneling |= (tx_offload.l2_len >> 1) <<
291 I40E_TXD_CTX_QW0_NATLEN_SHIFT;
295 i40e_txd_enable_checksum(uint64_t ol_flags,
298 union i40e_tx_offload tx_offload)
301 if (ol_flags & PKT_TX_TUNNEL_MASK)
302 *td_offset |= (tx_offload.outer_l2_len >> 1)
303 << I40E_TX_DESC_LENGTH_MACLEN_SHIFT;
305 *td_offset |= (tx_offload.l2_len >> 1)
306 << I40E_TX_DESC_LENGTH_MACLEN_SHIFT;
308 /* Enable L3 checksum offloads */
309 if (ol_flags & PKT_TX_IP_CKSUM) {
310 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV4_CSUM;
311 *td_offset |= (tx_offload.l3_len >> 2)
312 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
313 } else if (ol_flags & PKT_TX_IPV4) {
314 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV4;
315 *td_offset |= (tx_offload.l3_len >> 2)
316 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
317 } else if (ol_flags & PKT_TX_IPV6) {
318 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV6;
319 *td_offset |= (tx_offload.l3_len >> 2)
320 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
323 if (ol_flags & PKT_TX_TCP_SEG) {
324 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_TCP;
325 *td_offset |= (tx_offload.l4_len >> 2)
326 << I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
330 /* Enable L4 checksum offloads */
331 switch (ol_flags & PKT_TX_L4_MASK) {
332 case PKT_TX_TCP_CKSUM:
333 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_TCP;
334 *td_offset |= (sizeof(struct rte_tcp_hdr) >> 2) <<
335 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
337 case PKT_TX_SCTP_CKSUM:
338 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_SCTP;
339 *td_offset |= (sizeof(struct rte_sctp_hdr) >> 2) <<
340 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
342 case PKT_TX_UDP_CKSUM:
343 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_UDP;
344 *td_offset |= (sizeof(struct rte_udp_hdr) >> 2) <<
345 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
352 /* Construct the tx flags */
353 static inline uint64_t
354 i40e_build_ctob(uint32_t td_cmd,
359 return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA |
360 ((uint64_t)td_cmd << I40E_TXD_QW1_CMD_SHIFT) |
361 ((uint64_t)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) |
362 ((uint64_t)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) |
363 ((uint64_t)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT));
367 i40e_xmit_cleanup(struct i40e_tx_queue *txq)
369 struct i40e_tx_entry *sw_ring = txq->sw_ring;
370 volatile struct i40e_tx_desc *txd = txq->tx_ring;
371 uint16_t last_desc_cleaned = txq->last_desc_cleaned;
372 uint16_t nb_tx_desc = txq->nb_tx_desc;
373 uint16_t desc_to_clean_to;
374 uint16_t nb_tx_to_clean;
376 desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_rs_thresh);
377 if (desc_to_clean_to >= nb_tx_desc)
378 desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
380 desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
381 if ((txd[desc_to_clean_to].cmd_type_offset_bsz &
382 rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
383 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE)) {
384 PMD_TX_LOG(DEBUG, "TX descriptor %4u is not done "
385 "(port=%d queue=%d)", desc_to_clean_to,
386 txq->port_id, txq->queue_id);
390 if (last_desc_cleaned > desc_to_clean_to)
391 nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
394 nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
397 txd[desc_to_clean_to].cmd_type_offset_bsz = 0;
399 txq->last_desc_cleaned = desc_to_clean_to;
400 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
406 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
407 check_rx_burst_bulk_alloc_preconditions(struct i40e_rx_queue *rxq)
409 check_rx_burst_bulk_alloc_preconditions(__rte_unused struct i40e_rx_queue *rxq)
414 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
415 if (!(rxq->rx_free_thresh >= RTE_PMD_I40E_RX_MAX_BURST)) {
416 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
417 "rxq->rx_free_thresh=%d, "
418 "RTE_PMD_I40E_RX_MAX_BURST=%d",
419 rxq->rx_free_thresh, RTE_PMD_I40E_RX_MAX_BURST);
421 } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
422 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
423 "rxq->rx_free_thresh=%d, "
424 "rxq->nb_rx_desc=%d",
425 rxq->rx_free_thresh, rxq->nb_rx_desc);
427 } else if (rxq->nb_rx_desc % rxq->rx_free_thresh != 0) {
428 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
429 "rxq->nb_rx_desc=%d, "
430 "rxq->rx_free_thresh=%d",
431 rxq->nb_rx_desc, rxq->rx_free_thresh);
441 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
442 #define I40E_LOOK_AHEAD 8
443 #if (I40E_LOOK_AHEAD != 8)
444 #error "PMD I40E: I40E_LOOK_AHEAD must be 8\n"
447 i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
449 volatile union i40e_rx_desc *rxdp;
450 struct i40e_rx_entry *rxep;
455 int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
456 int32_t i, j, nb_rx = 0;
458 uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
460 rxdp = &rxq->rx_ring[rxq->rx_tail];
461 rxep = &rxq->sw_ring[rxq->rx_tail];
463 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
464 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
465 I40E_RXD_QW1_STATUS_SHIFT;
467 /* Make sure there is at least 1 packet to receive */
468 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
472 * Scan LOOK_AHEAD descriptors at a time to determine which
473 * descriptors reference packets that are ready to be received.
475 for (i = 0; i < RTE_PMD_I40E_RX_MAX_BURST; i+=I40E_LOOK_AHEAD,
476 rxdp += I40E_LOOK_AHEAD, rxep += I40E_LOOK_AHEAD) {
477 /* Read desc statuses backwards to avoid race condition */
478 for (j = I40E_LOOK_AHEAD - 1; j >= 0; j--) {
479 qword1 = rte_le_to_cpu_64(\
480 rxdp[j].wb.qword1.status_error_len);
481 s[j] = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
482 I40E_RXD_QW1_STATUS_SHIFT;
487 /* Compute how many status bits were set */
488 for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
489 var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
491 /* For Arm platforms, only compute continuous status bits */
503 /* Translate descriptor info to mbuf parameters */
504 for (j = 0; j < nb_dd; j++) {
506 qword1 = rte_le_to_cpu_64(\
507 rxdp[j].wb.qword1.status_error_len);
508 pkt_len = ((qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
509 I40E_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
510 mb->data_len = pkt_len;
511 mb->pkt_len = pkt_len;
513 i40e_rxd_to_vlan_tci(mb, &rxdp[j]);
514 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
515 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
517 ptype_tbl[(uint8_t)((qword1 &
518 I40E_RXD_QW1_PTYPE_MASK) >>
519 I40E_RXD_QW1_PTYPE_SHIFT)];
520 if (pkt_flags & PKT_RX_RSS_HASH)
521 mb->hash.rss = rte_le_to_cpu_32(\
522 rxdp[j].wb.qword0.hi_dword.rss);
523 if (pkt_flags & PKT_RX_FDIR)
524 pkt_flags |= i40e_rxd_build_fdir(&rxdp[j], mb);
526 #ifdef RTE_LIBRTE_IEEE1588
527 pkt_flags |= i40e_get_iee15888_flags(mb, qword1);
529 mb->ol_flags |= pkt_flags;
533 for (j = 0; j < I40E_LOOK_AHEAD; j++)
534 rxq->rx_stage[i + j] = rxep[j].mbuf;
536 if (nb_dd != I40E_LOOK_AHEAD)
540 /* Clear software ring entries */
541 for (i = 0; i < nb_rx; i++)
542 rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
547 static inline uint16_t
548 i40e_rx_fill_from_stage(struct i40e_rx_queue *rxq,
549 struct rte_mbuf **rx_pkts,
553 struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
555 nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
557 for (i = 0; i < nb_pkts; i++)
558 rx_pkts[i] = stage[i];
560 rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
561 rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
567 i40e_rx_alloc_bufs(struct i40e_rx_queue *rxq)
569 volatile union i40e_rx_desc *rxdp;
570 struct i40e_rx_entry *rxep;
572 uint16_t alloc_idx, i;
576 /* Allocate buffers in bulk */
577 alloc_idx = (uint16_t)(rxq->rx_free_trigger -
578 (rxq->rx_free_thresh - 1));
579 rxep = &(rxq->sw_ring[alloc_idx]);
580 diag = rte_mempool_get_bulk(rxq->mp, (void *)rxep,
581 rxq->rx_free_thresh);
582 if (unlikely(diag != 0)) {
583 PMD_DRV_LOG(ERR, "Failed to get mbufs in bulk");
587 rxdp = &rxq->rx_ring[alloc_idx];
588 for (i = 0; i < rxq->rx_free_thresh; i++) {
589 if (likely(i < (rxq->rx_free_thresh - 1)))
590 /* Prefetch next mbuf */
591 rte_prefetch0(rxep[i + 1].mbuf);
594 rte_mbuf_refcnt_set(mb, 1);
596 mb->data_off = RTE_PKTMBUF_HEADROOM;
598 mb->port = rxq->port_id;
599 dma_addr = rte_cpu_to_le_64(\
600 rte_mbuf_data_iova_default(mb));
601 rxdp[i].read.hdr_addr = 0;
602 rxdp[i].read.pkt_addr = dma_addr;
605 /* Update rx tail regsiter */
606 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->rx_free_trigger);
608 rxq->rx_free_trigger =
609 (uint16_t)(rxq->rx_free_trigger + rxq->rx_free_thresh);
610 if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
611 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
616 static inline uint16_t
617 rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
619 struct i40e_rx_queue *rxq = (struct i40e_rx_queue *)rx_queue;
620 struct rte_eth_dev *dev;
626 if (rxq->rx_nb_avail)
627 return i40e_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
629 nb_rx = (uint16_t)i40e_rx_scan_hw_ring(rxq);
630 rxq->rx_next_avail = 0;
631 rxq->rx_nb_avail = nb_rx;
632 rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
634 if (rxq->rx_tail > rxq->rx_free_trigger) {
635 if (i40e_rx_alloc_bufs(rxq) != 0) {
638 dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
639 dev->data->rx_mbuf_alloc_failed +=
642 rxq->rx_nb_avail = 0;
643 rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
644 for (i = 0, j = rxq->rx_tail; i < nb_rx; i++, j++)
645 rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
651 if (rxq->rx_tail >= rxq->nb_rx_desc)
654 if (rxq->rx_nb_avail)
655 return i40e_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
661 i40e_recv_pkts_bulk_alloc(void *rx_queue,
662 struct rte_mbuf **rx_pkts,
665 uint16_t nb_rx = 0, n, count;
667 if (unlikely(nb_pkts == 0))
670 if (likely(nb_pkts <= RTE_PMD_I40E_RX_MAX_BURST))
671 return rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
674 n = RTE_MIN(nb_pkts, RTE_PMD_I40E_RX_MAX_BURST);
675 count = rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
676 nb_rx = (uint16_t)(nb_rx + count);
677 nb_pkts = (uint16_t)(nb_pkts - count);
686 i40e_recv_pkts_bulk_alloc(void __rte_unused *rx_queue,
687 struct rte_mbuf __rte_unused **rx_pkts,
688 uint16_t __rte_unused nb_pkts)
692 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
695 i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
697 struct i40e_rx_queue *rxq;
698 volatile union i40e_rx_desc *rx_ring;
699 volatile union i40e_rx_desc *rxdp;
700 union i40e_rx_desc rxd;
701 struct i40e_rx_entry *sw_ring;
702 struct i40e_rx_entry *rxe;
703 struct rte_eth_dev *dev;
704 struct rte_mbuf *rxm;
705 struct rte_mbuf *nmb;
709 uint16_t rx_packet_len;
710 uint16_t rx_id, nb_hold;
718 rx_id = rxq->rx_tail;
719 rx_ring = rxq->rx_ring;
720 sw_ring = rxq->sw_ring;
721 ptype_tbl = rxq->vsi->adapter->ptype_tbl;
723 while (nb_rx < nb_pkts) {
724 rxdp = &rx_ring[rx_id];
725 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
726 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK)
727 >> I40E_RXD_QW1_STATUS_SHIFT;
729 /* Check the DD bit first */
730 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
733 nmb = rte_mbuf_raw_alloc(rxq->mp);
734 if (unlikely(!nmb)) {
735 dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
736 dev->data->rx_mbuf_alloc_failed++;
742 rxe = &sw_ring[rx_id];
744 if (unlikely(rx_id == rxq->nb_rx_desc))
747 /* Prefetch next mbuf */
748 rte_prefetch0(sw_ring[rx_id].mbuf);
751 * When next RX descriptor is on a cache line boundary,
752 * prefetch the next 4 RX descriptors and next 8 pointers
755 if ((rx_id & 0x3) == 0) {
756 rte_prefetch0(&rx_ring[rx_id]);
757 rte_prefetch0(&sw_ring[rx_id]);
762 rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
763 rxdp->read.hdr_addr = 0;
764 rxdp->read.pkt_addr = dma_addr;
766 rx_packet_len = ((qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
767 I40E_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
769 rxm->data_off = RTE_PKTMBUF_HEADROOM;
770 rte_prefetch0(RTE_PTR_ADD(rxm->buf_addr, RTE_PKTMBUF_HEADROOM));
773 rxm->pkt_len = rx_packet_len;
774 rxm->data_len = rx_packet_len;
775 rxm->port = rxq->port_id;
777 i40e_rxd_to_vlan_tci(rxm, &rxd);
778 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
779 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
781 ptype_tbl[(uint8_t)((qword1 &
782 I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
783 if (pkt_flags & PKT_RX_RSS_HASH)
785 rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
786 if (pkt_flags & PKT_RX_FDIR)
787 pkt_flags |= i40e_rxd_build_fdir(&rxd, rxm);
789 #ifdef RTE_LIBRTE_IEEE1588
790 pkt_flags |= i40e_get_iee15888_flags(rxm, qword1);
792 rxm->ol_flags |= pkt_flags;
794 rx_pkts[nb_rx++] = rxm;
796 rxq->rx_tail = rx_id;
799 * If the number of free RX descriptors is greater than the RX free
800 * threshold of the queue, advance the receive tail register of queue.
801 * Update that register with the value of the last processed RX
802 * descriptor minus 1.
804 nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
805 if (nb_hold > rxq->rx_free_thresh) {
806 rx_id = (uint16_t) ((rx_id == 0) ?
807 (rxq->nb_rx_desc - 1) : (rx_id - 1));
808 I40E_PCI_REG_WC_WRITE(rxq->qrx_tail, rx_id);
811 rxq->nb_rx_hold = nb_hold;
817 i40e_recv_scattered_pkts(void *rx_queue,
818 struct rte_mbuf **rx_pkts,
821 struct i40e_rx_queue *rxq = rx_queue;
822 volatile union i40e_rx_desc *rx_ring = rxq->rx_ring;
823 volatile union i40e_rx_desc *rxdp;
824 union i40e_rx_desc rxd;
825 struct i40e_rx_entry *sw_ring = rxq->sw_ring;
826 struct i40e_rx_entry *rxe;
827 struct rte_mbuf *first_seg = rxq->pkt_first_seg;
828 struct rte_mbuf *last_seg = rxq->pkt_last_seg;
829 struct rte_mbuf *nmb, *rxm;
830 uint16_t rx_id = rxq->rx_tail;
831 uint16_t nb_rx = 0, nb_hold = 0, rx_packet_len;
832 struct rte_eth_dev *dev;
837 uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
839 while (nb_rx < nb_pkts) {
840 rxdp = &rx_ring[rx_id];
841 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
842 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
843 I40E_RXD_QW1_STATUS_SHIFT;
845 /* Check the DD bit */
846 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
849 nmb = rte_mbuf_raw_alloc(rxq->mp);
850 if (unlikely(!nmb)) {
851 dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
852 dev->data->rx_mbuf_alloc_failed++;
858 rxe = &sw_ring[rx_id];
860 if (rx_id == rxq->nb_rx_desc)
863 /* Prefetch next mbuf */
864 rte_prefetch0(sw_ring[rx_id].mbuf);
867 * When next RX descriptor is on a cache line boundary,
868 * prefetch the next 4 RX descriptors and next 8 pointers
871 if ((rx_id & 0x3) == 0) {
872 rte_prefetch0(&rx_ring[rx_id]);
873 rte_prefetch0(&sw_ring[rx_id]);
879 rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
881 /* Set data buffer address and data length of the mbuf */
882 rxdp->read.hdr_addr = 0;
883 rxdp->read.pkt_addr = dma_addr;
884 rx_packet_len = (qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
885 I40E_RXD_QW1_LENGTH_PBUF_SHIFT;
886 rxm->data_len = rx_packet_len;
887 rxm->data_off = RTE_PKTMBUF_HEADROOM;
890 * If this is the first buffer of the received packet, set the
891 * pointer to the first mbuf of the packet and initialize its
892 * context. Otherwise, update the total length and the number
893 * of segments of the current scattered packet, and update the
894 * pointer to the last mbuf of the current packet.
898 first_seg->nb_segs = 1;
899 first_seg->pkt_len = rx_packet_len;
902 (uint16_t)(first_seg->pkt_len +
904 first_seg->nb_segs++;
905 last_seg->next = rxm;
909 * If this is not the last buffer of the received packet,
910 * update the pointer to the last mbuf of the current scattered
911 * packet and continue to parse the RX ring.
913 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_EOF_SHIFT))) {
919 * This is the last buffer of the received packet. If the CRC
920 * is not stripped by the hardware:
921 * - Subtract the CRC length from the total packet length.
922 * - If the last buffer only contains the whole CRC or a part
923 * of it, free the mbuf associated to the last buffer. If part
924 * of the CRC is also contained in the previous mbuf, subtract
925 * the length of that CRC part from the data length of the
929 if (unlikely(rxq->crc_len > 0)) {
930 first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
931 if (rx_packet_len <= RTE_ETHER_CRC_LEN) {
932 rte_pktmbuf_free_seg(rxm);
933 first_seg->nb_segs--;
935 (uint16_t)(last_seg->data_len -
936 (RTE_ETHER_CRC_LEN - rx_packet_len));
937 last_seg->next = NULL;
939 rxm->data_len = (uint16_t)(rx_packet_len -
943 first_seg->port = rxq->port_id;
944 first_seg->ol_flags = 0;
945 i40e_rxd_to_vlan_tci(first_seg, &rxd);
946 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
947 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
948 first_seg->packet_type =
949 ptype_tbl[(uint8_t)((qword1 &
950 I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
951 if (pkt_flags & PKT_RX_RSS_HASH)
952 first_seg->hash.rss =
953 rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
954 if (pkt_flags & PKT_RX_FDIR)
955 pkt_flags |= i40e_rxd_build_fdir(&rxd, first_seg);
957 #ifdef RTE_LIBRTE_IEEE1588
958 pkt_flags |= i40e_get_iee15888_flags(first_seg, qword1);
960 first_seg->ol_flags |= pkt_flags;
962 /* Prefetch data of first segment, if configured to do so. */
963 rte_prefetch0(RTE_PTR_ADD(first_seg->buf_addr,
964 first_seg->data_off));
965 rx_pkts[nb_rx++] = first_seg;
969 /* Record index of the next RX descriptor to probe. */
970 rxq->rx_tail = rx_id;
971 rxq->pkt_first_seg = first_seg;
972 rxq->pkt_last_seg = last_seg;
975 * If the number of free RX descriptors is greater than the RX free
976 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
977 * register. Update the RDT with the value of the last processed RX
978 * descriptor minus 1, to guarantee that the RDT register is never
979 * equal to the RDH register, which creates a "full" ring situtation
980 * from the hardware point of view.
982 nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
983 if (nb_hold > rxq->rx_free_thresh) {
984 rx_id = (uint16_t)(rx_id == 0 ?
985 (rxq->nb_rx_desc - 1) : (rx_id - 1));
986 I40E_PCI_REG_WC_WRITE(rxq->qrx_tail, rx_id);
989 rxq->nb_rx_hold = nb_hold;
994 /* Check if the context descriptor is needed for TX offloading */
995 static inline uint16_t
996 i40e_calc_context_desc(uint64_t flags)
998 static uint64_t mask = PKT_TX_OUTER_IP_CKSUM |
1003 #ifdef RTE_LIBRTE_IEEE1588
1004 mask |= PKT_TX_IEEE1588_TMST;
1007 return (flags & mask) ? 1 : 0;
1010 /* set i40e TSO context descriptor */
1011 static inline uint64_t
1012 i40e_set_tso_ctx(struct rte_mbuf *mbuf, union i40e_tx_offload tx_offload)
1014 uint64_t ctx_desc = 0;
1015 uint32_t cd_cmd, hdr_len, cd_tso_len;
1017 if (!tx_offload.l4_len) {
1018 PMD_DRV_LOG(DEBUG, "L4 length set to 0");
1022 hdr_len = tx_offload.l2_len + tx_offload.l3_len + tx_offload.l4_len;
1023 hdr_len += (mbuf->ol_flags & PKT_TX_TUNNEL_MASK) ?
1024 tx_offload.outer_l2_len + tx_offload.outer_l3_len : 0;
1026 cd_cmd = I40E_TX_CTX_DESC_TSO;
1027 cd_tso_len = mbuf->pkt_len - hdr_len;
1028 ctx_desc |= ((uint64_t)cd_cmd << I40E_TXD_CTX_QW1_CMD_SHIFT) |
1029 ((uint64_t)cd_tso_len <<
1030 I40E_TXD_CTX_QW1_TSO_LEN_SHIFT) |
1031 ((uint64_t)mbuf->tso_segsz <<
1032 I40E_TXD_CTX_QW1_MSS_SHIFT);
1037 /* HW requires that Tx buffer size ranges from 1B up to (16K-1)B. */
1038 #define I40E_MAX_DATA_PER_TXD \
1039 (I40E_TXD_QW1_TX_BUF_SZ_MASK >> I40E_TXD_QW1_TX_BUF_SZ_SHIFT)
1040 /* Calculate the number of TX descriptors needed for each pkt */
1041 static inline uint16_t
1042 i40e_calc_pkt_desc(struct rte_mbuf *tx_pkt)
1044 struct rte_mbuf *txd = tx_pkt;
1047 while (txd != NULL) {
1048 count += DIV_ROUND_UP(txd->data_len, I40E_MAX_DATA_PER_TXD);
1056 i40e_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1058 struct i40e_tx_queue *txq;
1059 struct i40e_tx_entry *sw_ring;
1060 struct i40e_tx_entry *txe, *txn;
1061 volatile struct i40e_tx_desc *txd;
1062 volatile struct i40e_tx_desc *txr;
1063 struct rte_mbuf *tx_pkt;
1064 struct rte_mbuf *m_seg;
1065 uint32_t cd_tunneling_params;
1076 uint64_t buf_dma_addr;
1077 union i40e_tx_offload tx_offload = {0};
1080 sw_ring = txq->sw_ring;
1082 tx_id = txq->tx_tail;
1083 txe = &sw_ring[tx_id];
1085 /* Check if the descriptor ring needs to be cleaned. */
1086 if (txq->nb_tx_free < txq->tx_free_thresh)
1087 (void)i40e_xmit_cleanup(txq);
1089 for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
1094 tx_pkt = *tx_pkts++;
1095 RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
1097 ol_flags = tx_pkt->ol_flags;
1098 tx_offload.l2_len = tx_pkt->l2_len;
1099 tx_offload.l3_len = tx_pkt->l3_len;
1100 tx_offload.outer_l2_len = tx_pkt->outer_l2_len;
1101 tx_offload.outer_l3_len = tx_pkt->outer_l3_len;
1102 tx_offload.l4_len = tx_pkt->l4_len;
1103 tx_offload.tso_segsz = tx_pkt->tso_segsz;
1105 /* Calculate the number of context descriptors needed. */
1106 nb_ctx = i40e_calc_context_desc(ol_flags);
1109 * The number of descriptors that must be allocated for
1110 * a packet equals to the number of the segments of that
1111 * packet plus 1 context descriptor if needed.
1112 * Recalculate the needed tx descs when TSO enabled in case
1113 * the mbuf data size exceeds max data size that hw allows
1116 if (ol_flags & PKT_TX_TCP_SEG)
1117 nb_used = (uint16_t)(i40e_calc_pkt_desc(tx_pkt) +
1120 nb_used = (uint16_t)(tx_pkt->nb_segs + nb_ctx);
1121 tx_last = (uint16_t)(tx_id + nb_used - 1);
1124 if (tx_last >= txq->nb_tx_desc)
1125 tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
1127 if (nb_used > txq->nb_tx_free) {
1128 if (i40e_xmit_cleanup(txq) != 0) {
1133 if (unlikely(nb_used > txq->tx_rs_thresh)) {
1134 while (nb_used > txq->nb_tx_free) {
1135 if (i40e_xmit_cleanup(txq) != 0) {
1144 /* Descriptor based VLAN insertion */
1145 if (ol_flags & (PKT_TX_VLAN_PKT | PKT_TX_QINQ_PKT)) {
1146 td_cmd |= I40E_TX_DESC_CMD_IL2TAG1;
1147 td_tag = tx_pkt->vlan_tci;
1150 /* Always enable CRC offload insertion */
1151 td_cmd |= I40E_TX_DESC_CMD_ICRC;
1153 /* Fill in tunneling parameters if necessary */
1154 cd_tunneling_params = 0;
1155 if (ol_flags & PKT_TX_TUNNEL_MASK)
1156 i40e_parse_tunneling_params(ol_flags, tx_offload,
1157 &cd_tunneling_params);
1158 /* Enable checksum offloading */
1159 if (ol_flags & I40E_TX_CKSUM_OFFLOAD_MASK)
1160 i40e_txd_enable_checksum(ol_flags, &td_cmd,
1161 &td_offset, tx_offload);
1164 /* Setup TX context descriptor if required */
1165 volatile struct i40e_tx_context_desc *ctx_txd =
1166 (volatile struct i40e_tx_context_desc *)\
1168 uint16_t cd_l2tag2 = 0;
1169 uint64_t cd_type_cmd_tso_mss =
1170 I40E_TX_DESC_DTYPE_CONTEXT;
1172 txn = &sw_ring[txe->next_id];
1173 RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1174 if (txe->mbuf != NULL) {
1175 rte_pktmbuf_free_seg(txe->mbuf);
1179 /* TSO enabled means no timestamp */
1180 if (ol_flags & PKT_TX_TCP_SEG)
1181 cd_type_cmd_tso_mss |=
1182 i40e_set_tso_ctx(tx_pkt, tx_offload);
1184 #ifdef RTE_LIBRTE_IEEE1588
1185 if (ol_flags & PKT_TX_IEEE1588_TMST)
1186 cd_type_cmd_tso_mss |=
1187 ((uint64_t)I40E_TX_CTX_DESC_TSYN <<
1188 I40E_TXD_CTX_QW1_CMD_SHIFT);
1192 ctx_txd->tunneling_params =
1193 rte_cpu_to_le_32(cd_tunneling_params);
1194 if (ol_flags & PKT_TX_QINQ_PKT) {
1195 cd_l2tag2 = tx_pkt->vlan_tci_outer;
1196 cd_type_cmd_tso_mss |=
1197 ((uint64_t)I40E_TX_CTX_DESC_IL2TAG2 <<
1198 I40E_TXD_CTX_QW1_CMD_SHIFT);
1200 ctx_txd->l2tag2 = rte_cpu_to_le_16(cd_l2tag2);
1201 ctx_txd->type_cmd_tso_mss =
1202 rte_cpu_to_le_64(cd_type_cmd_tso_mss);
1204 PMD_TX_LOG(DEBUG, "mbuf: %p, TCD[%u]:\n"
1205 "tunneling_params: %#x;\n"
1208 "type_cmd_tso_mss: %#"PRIx64";\n",
1210 ctx_txd->tunneling_params,
1213 ctx_txd->type_cmd_tso_mss);
1215 txe->last_id = tx_last;
1216 tx_id = txe->next_id;
1223 txn = &sw_ring[txe->next_id];
1226 rte_pktmbuf_free_seg(txe->mbuf);
1229 /* Setup TX Descriptor */
1230 slen = m_seg->data_len;
1231 buf_dma_addr = rte_mbuf_data_iova(m_seg);
1233 while ((ol_flags & PKT_TX_TCP_SEG) &&
1234 unlikely(slen > I40E_MAX_DATA_PER_TXD)) {
1236 rte_cpu_to_le_64(buf_dma_addr);
1237 txd->cmd_type_offset_bsz =
1238 i40e_build_ctob(td_cmd,
1239 td_offset, I40E_MAX_DATA_PER_TXD,
1242 buf_dma_addr += I40E_MAX_DATA_PER_TXD;
1243 slen -= I40E_MAX_DATA_PER_TXD;
1245 txe->last_id = tx_last;
1246 tx_id = txe->next_id;
1249 txn = &sw_ring[txe->next_id];
1251 PMD_TX_LOG(DEBUG, "mbuf: %p, TDD[%u]:\n"
1252 "buf_dma_addr: %#"PRIx64";\n"
1257 tx_pkt, tx_id, buf_dma_addr,
1258 td_cmd, td_offset, slen, td_tag);
1260 txd->buffer_addr = rte_cpu_to_le_64(buf_dma_addr);
1261 txd->cmd_type_offset_bsz = i40e_build_ctob(td_cmd,
1262 td_offset, slen, td_tag);
1263 txe->last_id = tx_last;
1264 tx_id = txe->next_id;
1266 m_seg = m_seg->next;
1267 } while (m_seg != NULL);
1269 /* The last packet data descriptor needs End Of Packet (EOP) */
1270 td_cmd |= I40E_TX_DESC_CMD_EOP;
1271 txq->nb_tx_used = (uint16_t)(txq->nb_tx_used + nb_used);
1272 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
1274 if (txq->nb_tx_used >= txq->tx_rs_thresh) {
1276 "Setting RS bit on TXD id="
1277 "%4u (port=%d queue=%d)",
1278 tx_last, txq->port_id, txq->queue_id);
1280 td_cmd |= I40E_TX_DESC_CMD_RS;
1282 /* Update txq RS bit counters */
1283 txq->nb_tx_used = 0;
1286 txd->cmd_type_offset_bsz |=
1287 rte_cpu_to_le_64(((uint64_t)td_cmd) <<
1288 I40E_TXD_QW1_CMD_SHIFT);
1292 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
1293 (unsigned) txq->port_id, (unsigned) txq->queue_id,
1294 (unsigned) tx_id, (unsigned) nb_tx);
1297 I40E_PCI_REG_WC_WRITE_RELAXED(txq->qtx_tail, tx_id);
1298 txq->tx_tail = tx_id;
1303 static __rte_always_inline int
1304 i40e_tx_free_bufs(struct i40e_tx_queue *txq)
1306 struct i40e_tx_entry *txep;
1307 uint16_t tx_rs_thresh = txq->tx_rs_thresh;
1308 uint16_t i = 0, j = 0;
1309 struct rte_mbuf *free[RTE_I40E_TX_MAX_FREE_BUF_SZ];
1310 const uint16_t k = RTE_ALIGN_FLOOR(tx_rs_thresh, RTE_I40E_TX_MAX_FREE_BUF_SZ);
1311 const uint16_t m = tx_rs_thresh % RTE_I40E_TX_MAX_FREE_BUF_SZ;
1313 if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz &
1314 rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
1315 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1318 txep = &txq->sw_ring[txq->tx_next_dd - (tx_rs_thresh - 1)];
1320 for (i = 0; i < tx_rs_thresh; i++)
1321 rte_prefetch0((txep + i)->mbuf);
1323 if (txq->offloads & DEV_TX_OFFLOAD_MBUF_FAST_FREE) {
1325 for (j = 0; j != k; j += RTE_I40E_TX_MAX_FREE_BUF_SZ) {
1326 for (i = 0; i < RTE_I40E_TX_MAX_FREE_BUF_SZ; ++i, ++txep) {
1327 free[i] = txep->mbuf;
1330 rte_mempool_put_bulk(free[0]->pool, (void **)free,
1331 RTE_I40E_TX_MAX_FREE_BUF_SZ);
1336 for (i = 0; i < m; ++i, ++txep) {
1337 free[i] = txep->mbuf;
1340 rte_mempool_put_bulk(free[0]->pool, (void **)free, m);
1343 for (i = 0; i < txq->tx_rs_thresh; ++i, ++txep) {
1344 rte_pktmbuf_free_seg(txep->mbuf);
1349 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_rs_thresh);
1350 txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_rs_thresh);
1351 if (txq->tx_next_dd >= txq->nb_tx_desc)
1352 txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
1354 return txq->tx_rs_thresh;
1357 /* Populate 4 descriptors with data from 4 mbufs */
1359 tx4(volatile struct i40e_tx_desc *txdp, struct rte_mbuf **pkts)
1364 for (i = 0; i < 4; i++, txdp++, pkts++) {
1365 dma_addr = rte_mbuf_data_iova(*pkts);
1366 txdp->buffer_addr = rte_cpu_to_le_64(dma_addr);
1367 txdp->cmd_type_offset_bsz =
1368 i40e_build_ctob((uint32_t)I40E_TD_CMD, 0,
1369 (*pkts)->data_len, 0);
1373 /* Populate 1 descriptor with data from 1 mbuf */
1375 tx1(volatile struct i40e_tx_desc *txdp, struct rte_mbuf **pkts)
1379 dma_addr = rte_mbuf_data_iova(*pkts);
1380 txdp->buffer_addr = rte_cpu_to_le_64(dma_addr);
1381 txdp->cmd_type_offset_bsz =
1382 i40e_build_ctob((uint32_t)I40E_TD_CMD, 0,
1383 (*pkts)->data_len, 0);
1386 /* Fill hardware descriptor ring with mbuf data */
1388 i40e_tx_fill_hw_ring(struct i40e_tx_queue *txq,
1389 struct rte_mbuf **pkts,
1392 volatile struct i40e_tx_desc *txdp = &(txq->tx_ring[txq->tx_tail]);
1393 struct i40e_tx_entry *txep = &(txq->sw_ring[txq->tx_tail]);
1394 const int N_PER_LOOP = 4;
1395 const int N_PER_LOOP_MASK = N_PER_LOOP - 1;
1396 int mainpart, leftover;
1399 mainpart = (nb_pkts & ((uint32_t) ~N_PER_LOOP_MASK));
1400 leftover = (nb_pkts & ((uint32_t) N_PER_LOOP_MASK));
1401 for (i = 0; i < mainpart; i += N_PER_LOOP) {
1402 for (j = 0; j < N_PER_LOOP; ++j) {
1403 (txep + i + j)->mbuf = *(pkts + i + j);
1405 tx4(txdp + i, pkts + i);
1407 if (unlikely(leftover > 0)) {
1408 for (i = 0; i < leftover; ++i) {
1409 (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
1410 tx1(txdp + mainpart + i, pkts + mainpart + i);
1415 static inline uint16_t
1416 tx_xmit_pkts(struct i40e_tx_queue *txq,
1417 struct rte_mbuf **tx_pkts,
1420 volatile struct i40e_tx_desc *txr = txq->tx_ring;
1424 * Begin scanning the H/W ring for done descriptors when the number
1425 * of available descriptors drops below tx_free_thresh. For each done
1426 * descriptor, free the associated buffer.
1428 if (txq->nb_tx_free < txq->tx_free_thresh)
1429 i40e_tx_free_bufs(txq);
1431 /* Use available descriptor only */
1432 nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
1433 if (unlikely(!nb_pkts))
1436 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
1437 if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
1438 n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
1439 i40e_tx_fill_hw_ring(txq, tx_pkts, n);
1440 txr[txq->tx_next_rs].cmd_type_offset_bsz |=
1441 rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
1442 I40E_TXD_QW1_CMD_SHIFT);
1443 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
1447 /* Fill hardware descriptor ring with mbuf data */
1448 i40e_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
1449 txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
1451 /* Determin if RS bit needs to be set */
1452 if (txq->tx_tail > txq->tx_next_rs) {
1453 txr[txq->tx_next_rs].cmd_type_offset_bsz |=
1454 rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
1455 I40E_TXD_QW1_CMD_SHIFT);
1457 (uint16_t)(txq->tx_next_rs + txq->tx_rs_thresh);
1458 if (txq->tx_next_rs >= txq->nb_tx_desc)
1459 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
1462 if (txq->tx_tail >= txq->nb_tx_desc)
1465 /* Update the tx tail register */
1466 I40E_PCI_REG_WC_WRITE(txq->qtx_tail, txq->tx_tail);
1472 i40e_xmit_pkts_simple(void *tx_queue,
1473 struct rte_mbuf **tx_pkts,
1478 if (likely(nb_pkts <= I40E_TX_MAX_BURST))
1479 return tx_xmit_pkts((struct i40e_tx_queue *)tx_queue,
1483 uint16_t ret, num = (uint16_t)RTE_MIN(nb_pkts,
1486 ret = tx_xmit_pkts((struct i40e_tx_queue *)tx_queue,
1487 &tx_pkts[nb_tx], num);
1488 nb_tx = (uint16_t)(nb_tx + ret);
1489 nb_pkts = (uint16_t)(nb_pkts - ret);
1498 i40e_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
1502 struct i40e_tx_queue *txq = (struct i40e_tx_queue *)tx_queue;
1507 num = (uint16_t)RTE_MIN(nb_pkts, txq->tx_rs_thresh);
1508 ret = i40e_xmit_fixed_burst_vec(tx_queue, &tx_pkts[nb_tx],
1519 /*********************************************************************
1521 * TX simple prep functions
1523 **********************************************************************/
1525 i40e_simple_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
1532 for (i = 0; i < nb_pkts; i++) {
1534 ol_flags = m->ol_flags;
1536 if (m->nb_segs != 1) {
1541 if (ol_flags & I40E_TX_OFFLOAD_SIMPLE_NOTSUP_MASK) {
1542 rte_errno = ENOTSUP;
1546 /* check the size of packet */
1547 if (m->pkt_len < I40E_TX_MIN_PKT_LEN ||
1548 m->pkt_len > I40E_FRAME_SIZE_MAX) {
1556 /*********************************************************************
1560 **********************************************************************/
1562 i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
1569 for (i = 0; i < nb_pkts; i++) {
1571 ol_flags = m->ol_flags;
1573 /* Check for m->nb_segs to not exceed the limits. */
1574 if (!(ol_flags & PKT_TX_TCP_SEG)) {
1575 if (m->nb_segs > I40E_TX_MAX_MTU_SEG ||
1576 m->pkt_len > I40E_FRAME_SIZE_MAX) {
1580 } else if (m->nb_segs > I40E_TX_MAX_SEG ||
1581 m->tso_segsz < I40E_MIN_TSO_MSS ||
1582 m->tso_segsz > I40E_MAX_TSO_MSS ||
1583 m->pkt_len > I40E_TSO_FRAME_SIZE_MAX) {
1584 /* MSS outside the range (256B - 9674B) are considered
1591 if (ol_flags & I40E_TX_OFFLOAD_NOTSUP_MASK) {
1592 rte_errno = ENOTSUP;
1596 /* check the size of packet */
1597 if (m->pkt_len < I40E_TX_MIN_PKT_LEN) {
1602 #ifdef RTE_ETHDEV_DEBUG_TX
1603 ret = rte_validate_tx_offload(m);
1609 ret = rte_net_intel_cksum_prepare(m);
1619 * Find the VSI the queue belongs to. 'queue_idx' is the queue index
1620 * application used, which assume having sequential ones. But from driver's
1621 * perspective, it's different. For example, q0 belongs to FDIR VSI, q1-q64
1622 * to MAIN VSI, , q65-96 to SRIOV VSIs, q97-128 to VMDQ VSIs. For application
1623 * running on host, q1-64 and q97-128 can be used, total 96 queues. They can
1624 * use queue_idx from 0 to 95 to access queues, while real queue would be
1625 * different. This function will do a queue mapping to find VSI the queue
1628 static struct i40e_vsi*
1629 i40e_pf_get_vsi_by_qindex(struct i40e_pf *pf, uint16_t queue_idx)
1631 /* the queue in MAIN VSI range */
1632 if (queue_idx < pf->main_vsi->nb_qps)
1633 return pf->main_vsi;
1635 queue_idx -= pf->main_vsi->nb_qps;
1637 /* queue_idx is greater than VMDQ VSIs range */
1638 if (queue_idx > pf->nb_cfg_vmdq_vsi * pf->vmdq_nb_qps - 1) {
1639 PMD_INIT_LOG(ERR, "queue_idx out of range. VMDQ configured?");
1643 return pf->vmdq[queue_idx / pf->vmdq_nb_qps].vsi;
1647 i40e_get_queue_offset_by_qindex(struct i40e_pf *pf, uint16_t queue_idx)
1649 /* the queue in MAIN VSI range */
1650 if (queue_idx < pf->main_vsi->nb_qps)
1653 /* It's VMDQ queues */
1654 queue_idx -= pf->main_vsi->nb_qps;
1656 if (pf->nb_cfg_vmdq_vsi)
1657 return queue_idx % pf->vmdq_nb_qps;
1659 PMD_INIT_LOG(ERR, "Fail to get queue offset");
1660 return (uint16_t)(-1);
1665 i40e_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1667 struct i40e_rx_queue *rxq;
1669 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1671 PMD_INIT_FUNC_TRACE();
1673 rxq = dev->data->rx_queues[rx_queue_id];
1674 if (!rxq || !rxq->q_set) {
1675 PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
1680 if (rxq->rx_deferred_start)
1681 PMD_DRV_LOG(WARNING, "RX queue %u is deferrd start",
1684 err = i40e_alloc_rx_queue_mbufs(rxq);
1686 PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
1690 /* Init the RX tail regieter. */
1691 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
1693 err = i40e_switch_rx_queue(hw, rxq->reg_idx, TRUE);
1695 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
1698 i40e_rx_queue_release_mbufs(rxq);
1699 i40e_reset_rx_queue(rxq);
1702 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1708 i40e_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1710 struct i40e_rx_queue *rxq;
1712 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1714 rxq = dev->data->rx_queues[rx_queue_id];
1715 if (!rxq || !rxq->q_set) {
1716 PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
1722 * rx_queue_id is queue id application refers to, while
1723 * rxq->reg_idx is the real queue index.
1725 err = i40e_switch_rx_queue(hw, rxq->reg_idx, FALSE);
1727 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
1731 i40e_rx_queue_release_mbufs(rxq);
1732 i40e_reset_rx_queue(rxq);
1733 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1739 i40e_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1742 struct i40e_tx_queue *txq;
1743 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1745 PMD_INIT_FUNC_TRACE();
1747 txq = dev->data->tx_queues[tx_queue_id];
1748 if (!txq || !txq->q_set) {
1749 PMD_DRV_LOG(ERR, "TX queue %u is not available or setup",
1754 if (txq->tx_deferred_start)
1755 PMD_DRV_LOG(WARNING, "TX queue %u is deferrd start",
1759 * tx_queue_id is queue id application refers to, while
1760 * rxq->reg_idx is the real queue index.
1762 err = i40e_switch_tx_queue(hw, txq->reg_idx, TRUE);
1764 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
1768 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1774 i40e_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1776 struct i40e_tx_queue *txq;
1778 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1780 txq = dev->data->tx_queues[tx_queue_id];
1781 if (!txq || !txq->q_set) {
1782 PMD_DRV_LOG(ERR, "TX queue %u is not available or setup",
1788 * tx_queue_id is queue id application refers to, while
1789 * txq->reg_idx is the real queue index.
1791 err = i40e_switch_tx_queue(hw, txq->reg_idx, FALSE);
1793 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u of",
1798 i40e_tx_queue_release_mbufs(txq);
1799 i40e_reset_tx_queue(txq);
1800 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1806 i40e_dev_supported_ptypes_get(struct rte_eth_dev *dev)
1808 static const uint32_t ptypes[] = {
1809 /* refers to i40e_rxd_pkt_type_mapping() */
1811 RTE_PTYPE_L2_ETHER_TIMESYNC,
1812 RTE_PTYPE_L2_ETHER_LLDP,
1813 RTE_PTYPE_L2_ETHER_ARP,
1814 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1815 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
1818 RTE_PTYPE_L4_NONFRAG,
1822 RTE_PTYPE_TUNNEL_GRENAT,
1823 RTE_PTYPE_TUNNEL_IP,
1824 RTE_PTYPE_INNER_L2_ETHER,
1825 RTE_PTYPE_INNER_L2_ETHER_VLAN,
1826 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
1827 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
1828 RTE_PTYPE_INNER_L4_FRAG,
1829 RTE_PTYPE_INNER_L4_ICMP,
1830 RTE_PTYPE_INNER_L4_NONFRAG,
1831 RTE_PTYPE_INNER_L4_SCTP,
1832 RTE_PTYPE_INNER_L4_TCP,
1833 RTE_PTYPE_INNER_L4_UDP,
1837 if (dev->rx_pkt_burst == i40e_recv_pkts ||
1838 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1839 dev->rx_pkt_burst == i40e_recv_pkts_bulk_alloc ||
1841 dev->rx_pkt_burst == i40e_recv_scattered_pkts ||
1842 dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec ||
1843 dev->rx_pkt_burst == i40e_recv_pkts_vec ||
1844 #ifdef CC_AVX512_SUPPORT
1845 dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx512 ||
1846 dev->rx_pkt_burst == i40e_recv_pkts_vec_avx512 ||
1848 dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx2 ||
1849 dev->rx_pkt_burst == i40e_recv_pkts_vec_avx2)
1855 i40e_dev_first_queue(uint16_t idx, void **queues, int num)
1859 for (i = 0; i < num; i++) {
1860 if (i != idx && queues[i])
1868 i40e_dev_rx_queue_setup_runtime(struct rte_eth_dev *dev,
1869 struct i40e_rx_queue *rxq)
1871 struct i40e_adapter *ad =
1872 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1873 int use_def_burst_func =
1874 check_rx_burst_bulk_alloc_preconditions(rxq);
1876 (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
1877 RTE_PKTMBUF_HEADROOM);
1878 int use_scattered_rx =
1879 (rxq->max_pkt_len > buf_size);
1881 if (i40e_rx_queue_init(rxq) != I40E_SUCCESS) {
1883 "Failed to do RX queue initialization");
1887 if (i40e_dev_first_queue(rxq->queue_id,
1888 dev->data->rx_queues,
1889 dev->data->nb_rx_queues)) {
1891 * If it is the first queue to setup,
1892 * set all flags to default and call
1893 * i40e_set_rx_function.
1895 ad->rx_bulk_alloc_allowed = true;
1896 ad->rx_vec_allowed = true;
1897 dev->data->scattered_rx = use_scattered_rx;
1898 if (use_def_burst_func)
1899 ad->rx_bulk_alloc_allowed = false;
1900 i40e_set_rx_function(dev);
1902 } else if (ad->rx_vec_allowed && !rte_is_power_of_2(rxq->nb_rx_desc)) {
1903 PMD_DRV_LOG(ERR, "Vector mode is allowed, but descriptor"
1904 " number %d of queue %d isn't power of 2",
1905 rxq->nb_rx_desc, rxq->queue_id);
1909 /* check bulk alloc conflict */
1910 if (ad->rx_bulk_alloc_allowed && use_def_burst_func) {
1911 PMD_DRV_LOG(ERR, "Can't use default burst.");
1914 /* check scatterred conflict */
1915 if (!dev->data->scattered_rx && use_scattered_rx) {
1916 PMD_DRV_LOG(ERR, "Scattered rx is required.");
1919 /* check vector conflict */
1920 if (ad->rx_vec_allowed && i40e_rxq_vec_setup(rxq)) {
1921 PMD_DRV_LOG(ERR, "Failed vector rx setup.");
1929 i40e_dev_rx_queue_setup(struct rte_eth_dev *dev,
1932 unsigned int socket_id,
1933 const struct rte_eth_rxconf *rx_conf,
1934 struct rte_mempool *mp)
1936 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1937 struct i40e_adapter *ad =
1938 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1939 struct i40e_vsi *vsi;
1940 struct i40e_pf *pf = NULL;
1941 struct i40e_vf *vf = NULL;
1942 struct i40e_rx_queue *rxq;
1943 const struct rte_memzone *rz;
1946 uint16_t reg_idx, base, bsf, tc_mapping;
1947 int q_offset, use_def_burst_func = 1;
1950 offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
1952 if (hw->mac.type == I40E_MAC_VF || hw->mac.type == I40E_MAC_X722_VF) {
1953 vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1957 reg_idx = queue_idx;
1959 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1960 vsi = i40e_pf_get_vsi_by_qindex(pf, queue_idx);
1963 q_offset = i40e_get_queue_offset_by_qindex(pf, queue_idx);
1966 reg_idx = vsi->base_queue + q_offset;
1969 if (nb_desc % I40E_ALIGN_RING_DESC != 0 ||
1970 (nb_desc > I40E_MAX_RING_DESC) ||
1971 (nb_desc < I40E_MIN_RING_DESC)) {
1972 PMD_DRV_LOG(ERR, "Number (%u) of receive descriptors is "
1973 "invalid", nb_desc);
1977 /* Free memory if needed */
1978 if (dev->data->rx_queues[queue_idx]) {
1979 i40e_dev_rx_queue_release(dev->data->rx_queues[queue_idx]);
1980 dev->data->rx_queues[queue_idx] = NULL;
1983 /* Allocate the rx queue data structure */
1984 rxq = rte_zmalloc_socket("i40e rx queue",
1985 sizeof(struct i40e_rx_queue),
1986 RTE_CACHE_LINE_SIZE,
1989 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
1990 "rx queue data structure");
1994 rxq->nb_rx_desc = nb_desc;
1995 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1996 rxq->queue_id = queue_idx;
1997 rxq->reg_idx = reg_idx;
1998 rxq->port_id = dev->data->port_id;
1999 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC)
2000 rxq->crc_len = RTE_ETHER_CRC_LEN;
2003 rxq->drop_en = rx_conf->rx_drop_en;
2005 rxq->rx_deferred_start = rx_conf->rx_deferred_start;
2006 rxq->offloads = offloads;
2008 /* Allocate the maximun number of RX ring hardware descriptor. */
2009 len = I40E_MAX_RING_DESC;
2012 * Allocating a little more memory because vectorized/bulk_alloc Rx
2013 * functions doesn't check boundaries each time.
2015 len += RTE_PMD_I40E_RX_MAX_BURST;
2017 ring_size = RTE_ALIGN(len * sizeof(union i40e_rx_desc),
2018 I40E_DMA_MEM_ALIGN);
2020 rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
2021 ring_size, I40E_RING_BASE_ALIGN, socket_id);
2023 i40e_dev_rx_queue_release(rxq);
2024 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX");
2028 /* Zero all the descriptors in the ring. */
2029 memset(rz->addr, 0, ring_size);
2031 rxq->rx_ring_phys_addr = rz->iova;
2032 rxq->rx_ring = (union i40e_rx_desc *)rz->addr;
2034 len = (uint16_t)(nb_desc + RTE_PMD_I40E_RX_MAX_BURST);
2036 /* Allocate the software ring. */
2038 rte_zmalloc_socket("i40e rx sw ring",
2039 sizeof(struct i40e_rx_entry) * len,
2040 RTE_CACHE_LINE_SIZE,
2042 if (!rxq->sw_ring) {
2043 i40e_dev_rx_queue_release(rxq);
2044 PMD_DRV_LOG(ERR, "Failed to allocate memory for SW ring");
2048 i40e_reset_rx_queue(rxq);
2051 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
2052 if (!(vsi->enabled_tc & (1 << i)))
2054 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
2055 base = (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
2056 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
2057 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
2058 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
2060 if (queue_idx >= base && queue_idx < (base + BIT(bsf)))
2064 if (dev->data->dev_started) {
2065 if (i40e_dev_rx_queue_setup_runtime(dev, rxq)) {
2066 i40e_dev_rx_queue_release(rxq);
2070 use_def_burst_func =
2071 check_rx_burst_bulk_alloc_preconditions(rxq);
2072 if (!use_def_burst_func) {
2073 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2075 "Rx Burst Bulk Alloc Preconditions are "
2076 "satisfied. Rx Burst Bulk Alloc function will be "
2077 "used on port=%d, queue=%d.",
2078 rxq->port_id, rxq->queue_id);
2079 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2082 "Rx Burst Bulk Alloc Preconditions are "
2083 "not satisfied, Scattered Rx is requested, "
2084 "or RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC is "
2085 "not enabled on port=%d, queue=%d.",
2086 rxq->port_id, rxq->queue_id);
2087 ad->rx_bulk_alloc_allowed = false;
2091 dev->data->rx_queues[queue_idx] = rxq;
2096 i40e_dev_rx_queue_release(void *rxq)
2098 struct i40e_rx_queue *q = (struct i40e_rx_queue *)rxq;
2101 PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
2105 i40e_rx_queue_release_mbufs(q);
2106 rte_free(q->sw_ring);
2111 i40e_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
2113 #define I40E_RXQ_SCAN_INTERVAL 4
2114 volatile union i40e_rx_desc *rxdp;
2115 struct i40e_rx_queue *rxq;
2118 rxq = dev->data->rx_queues[rx_queue_id];
2119 rxdp = &(rxq->rx_ring[rxq->rx_tail]);
2120 while ((desc < rxq->nb_rx_desc) &&
2121 ((rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
2122 I40E_RXD_QW1_STATUS_MASK) >> I40E_RXD_QW1_STATUS_SHIFT) &
2123 (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
2125 * Check the DD bit of a rx descriptor of each 4 in a group,
2126 * to avoid checking too frequently and downgrading performance
2129 desc += I40E_RXQ_SCAN_INTERVAL;
2130 rxdp += I40E_RXQ_SCAN_INTERVAL;
2131 if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
2132 rxdp = &(rxq->rx_ring[rxq->rx_tail +
2133 desc - rxq->nb_rx_desc]);
2140 i40e_dev_rx_descriptor_done(void *rx_queue, uint16_t offset)
2142 volatile union i40e_rx_desc *rxdp;
2143 struct i40e_rx_queue *rxq = rx_queue;
2147 if (unlikely(offset >= rxq->nb_rx_desc)) {
2148 PMD_DRV_LOG(ERR, "Invalid RX descriptor id %u", offset);
2152 desc = rxq->rx_tail + offset;
2153 if (desc >= rxq->nb_rx_desc)
2154 desc -= rxq->nb_rx_desc;
2156 rxdp = &(rxq->rx_ring[desc]);
2158 ret = !!(((rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
2159 I40E_RXD_QW1_STATUS_MASK) >> I40E_RXD_QW1_STATUS_SHIFT) &
2160 (1 << I40E_RX_DESC_STATUS_DD_SHIFT));
2166 i40e_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
2168 struct i40e_rx_queue *rxq = rx_queue;
2169 volatile uint64_t *status;
2173 if (unlikely(offset >= rxq->nb_rx_desc))
2176 if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
2177 return RTE_ETH_RX_DESC_UNAVAIL;
2179 desc = rxq->rx_tail + offset;
2180 if (desc >= rxq->nb_rx_desc)
2181 desc -= rxq->nb_rx_desc;
2183 status = &rxq->rx_ring[desc].wb.qword1.status_error_len;
2184 mask = rte_le_to_cpu_64((1ULL << I40E_RX_DESC_STATUS_DD_SHIFT)
2185 << I40E_RXD_QW1_STATUS_SHIFT);
2187 return RTE_ETH_RX_DESC_DONE;
2189 return RTE_ETH_RX_DESC_AVAIL;
2193 i40e_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
2195 struct i40e_tx_queue *txq = tx_queue;
2196 volatile uint64_t *status;
2197 uint64_t mask, expect;
2200 if (unlikely(offset >= txq->nb_tx_desc))
2203 desc = txq->tx_tail + offset;
2204 /* go to next desc that has the RS bit */
2205 desc = ((desc + txq->tx_rs_thresh - 1) / txq->tx_rs_thresh) *
2207 if (desc >= txq->nb_tx_desc) {
2208 desc -= txq->nb_tx_desc;
2209 if (desc >= txq->nb_tx_desc)
2210 desc -= txq->nb_tx_desc;
2213 status = &txq->tx_ring[desc].cmd_type_offset_bsz;
2214 mask = rte_le_to_cpu_64(I40E_TXD_QW1_DTYPE_MASK);
2215 expect = rte_cpu_to_le_64(
2216 I40E_TX_DESC_DTYPE_DESC_DONE << I40E_TXD_QW1_DTYPE_SHIFT);
2217 if ((*status & mask) == expect)
2218 return RTE_ETH_TX_DESC_DONE;
2220 return RTE_ETH_TX_DESC_FULL;
2224 i40e_dev_tx_queue_setup_runtime(struct rte_eth_dev *dev,
2225 struct i40e_tx_queue *txq)
2227 struct i40e_adapter *ad =
2228 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2230 if (i40e_tx_queue_init(txq) != I40E_SUCCESS) {
2232 "Failed to do TX queue initialization");
2236 if (i40e_dev_first_queue(txq->queue_id,
2237 dev->data->tx_queues,
2238 dev->data->nb_tx_queues)) {
2240 * If it is the first queue to setup,
2241 * set all flags and call
2242 * i40e_set_tx_function.
2244 i40e_set_tx_function_flag(dev, txq);
2245 i40e_set_tx_function(dev);
2249 /* check vector conflict */
2250 if (ad->tx_vec_allowed) {
2251 if (txq->tx_rs_thresh > RTE_I40E_TX_MAX_FREE_BUF_SZ ||
2252 i40e_txq_vec_setup(txq)) {
2253 PMD_DRV_LOG(ERR, "Failed vector tx setup.");
2257 /* check simple tx conflict */
2258 if (ad->tx_simple_allowed) {
2259 if ((txq->offloads & ~DEV_TX_OFFLOAD_MBUF_FAST_FREE) != 0 ||
2260 txq->tx_rs_thresh < RTE_PMD_I40E_TX_MAX_BURST) {
2261 PMD_DRV_LOG(ERR, "No-simple tx is required.");
2270 i40e_dev_tx_queue_setup(struct rte_eth_dev *dev,
2273 unsigned int socket_id,
2274 const struct rte_eth_txconf *tx_conf)
2276 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2277 struct i40e_vsi *vsi;
2278 struct i40e_pf *pf = NULL;
2279 struct i40e_vf *vf = NULL;
2280 struct i40e_tx_queue *txq;
2281 const struct rte_memzone *tz;
2283 uint16_t tx_rs_thresh, tx_free_thresh;
2284 uint16_t reg_idx, i, base, bsf, tc_mapping;
2288 offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
2290 if (hw->mac.type == I40E_MAC_VF || hw->mac.type == I40E_MAC_X722_VF) {
2291 vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2293 reg_idx = queue_idx;
2295 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2296 vsi = i40e_pf_get_vsi_by_qindex(pf, queue_idx);
2299 q_offset = i40e_get_queue_offset_by_qindex(pf, queue_idx);
2302 reg_idx = vsi->base_queue + q_offset;
2305 if (nb_desc % I40E_ALIGN_RING_DESC != 0 ||
2306 (nb_desc > I40E_MAX_RING_DESC) ||
2307 (nb_desc < I40E_MIN_RING_DESC)) {
2308 PMD_DRV_LOG(ERR, "Number (%u) of transmit descriptors is "
2309 "invalid", nb_desc);
2314 * The following two parameters control the setting of the RS bit on
2315 * transmit descriptors. TX descriptors will have their RS bit set
2316 * after txq->tx_rs_thresh descriptors have been used. The TX
2317 * descriptor ring will be cleaned after txq->tx_free_thresh
2318 * descriptors are used or if the number of descriptors required to
2319 * transmit a packet is greater than the number of free TX descriptors.
2321 * The following constraints must be satisfied:
2322 * - tx_rs_thresh must be greater than 0.
2323 * - tx_rs_thresh must be less than the size of the ring minus 2.
2324 * - tx_rs_thresh must be less than or equal to tx_free_thresh.
2325 * - tx_rs_thresh must be a divisor of the ring size.
2326 * - tx_free_thresh must be greater than 0.
2327 * - tx_free_thresh must be less than the size of the ring minus 3.
2328 * - tx_free_thresh + tx_rs_thresh must not exceed nb_desc.
2330 * One descriptor in the TX ring is used as a sentinel to avoid a H/W
2331 * race condition, hence the maximum threshold constraints. When set
2332 * to zero use default values.
2334 tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
2335 tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
2336 /* force tx_rs_thresh to adapt an aggresive tx_free_thresh */
2337 tx_rs_thresh = (DEFAULT_TX_RS_THRESH + tx_free_thresh > nb_desc) ?
2338 nb_desc - tx_free_thresh : DEFAULT_TX_RS_THRESH;
2339 if (tx_conf->tx_rs_thresh > 0)
2340 tx_rs_thresh = tx_conf->tx_rs_thresh;
2341 if (tx_rs_thresh + tx_free_thresh > nb_desc) {
2342 PMD_INIT_LOG(ERR, "tx_rs_thresh + tx_free_thresh must not "
2343 "exceed nb_desc. (tx_rs_thresh=%u "
2344 "tx_free_thresh=%u nb_desc=%u port=%d queue=%d)",
2345 (unsigned int)tx_rs_thresh,
2346 (unsigned int)tx_free_thresh,
2347 (unsigned int)nb_desc,
2348 (int)dev->data->port_id,
2350 return I40E_ERR_PARAM;
2352 if (tx_rs_thresh >= (nb_desc - 2)) {
2353 PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than the "
2354 "number of TX descriptors minus 2. "
2355 "(tx_rs_thresh=%u port=%d queue=%d)",
2356 (unsigned int)tx_rs_thresh,
2357 (int)dev->data->port_id,
2359 return I40E_ERR_PARAM;
2361 if (tx_free_thresh >= (nb_desc - 3)) {
2362 PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the "
2363 "number of TX descriptors minus 3. "
2364 "(tx_free_thresh=%u port=%d queue=%d)",
2365 (unsigned int)tx_free_thresh,
2366 (int)dev->data->port_id,
2368 return I40E_ERR_PARAM;
2370 if (tx_rs_thresh > tx_free_thresh) {
2371 PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than or "
2372 "equal to tx_free_thresh. (tx_free_thresh=%u"
2373 " tx_rs_thresh=%u port=%d queue=%d)",
2374 (unsigned int)tx_free_thresh,
2375 (unsigned int)tx_rs_thresh,
2376 (int)dev->data->port_id,
2378 return I40E_ERR_PARAM;
2380 if ((nb_desc % tx_rs_thresh) != 0) {
2381 PMD_INIT_LOG(ERR, "tx_rs_thresh must be a divisor of the "
2382 "number of TX descriptors. (tx_rs_thresh=%u"
2383 " port=%d queue=%d)",
2384 (unsigned int)tx_rs_thresh,
2385 (int)dev->data->port_id,
2387 return I40E_ERR_PARAM;
2389 if ((tx_rs_thresh > 1) && (tx_conf->tx_thresh.wthresh != 0)) {
2390 PMD_INIT_LOG(ERR, "TX WTHRESH must be set to 0 if "
2391 "tx_rs_thresh is greater than 1. "
2392 "(tx_rs_thresh=%u port=%d queue=%d)",
2393 (unsigned int)tx_rs_thresh,
2394 (int)dev->data->port_id,
2396 return I40E_ERR_PARAM;
2399 /* Free memory if needed. */
2400 if (dev->data->tx_queues[queue_idx]) {
2401 i40e_dev_tx_queue_release(dev->data->tx_queues[queue_idx]);
2402 dev->data->tx_queues[queue_idx] = NULL;
2405 /* Allocate the TX queue data structure. */
2406 txq = rte_zmalloc_socket("i40e tx queue",
2407 sizeof(struct i40e_tx_queue),
2408 RTE_CACHE_LINE_SIZE,
2411 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
2412 "tx queue structure");
2416 /* Allocate TX hardware ring descriptors. */
2417 ring_size = sizeof(struct i40e_tx_desc) * I40E_MAX_RING_DESC;
2418 ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
2419 tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
2420 ring_size, I40E_RING_BASE_ALIGN, socket_id);
2422 i40e_dev_tx_queue_release(txq);
2423 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX");
2427 txq->nb_tx_desc = nb_desc;
2428 txq->tx_rs_thresh = tx_rs_thresh;
2429 txq->tx_free_thresh = tx_free_thresh;
2430 txq->pthresh = tx_conf->tx_thresh.pthresh;
2431 txq->hthresh = tx_conf->tx_thresh.hthresh;
2432 txq->wthresh = tx_conf->tx_thresh.wthresh;
2433 txq->queue_id = queue_idx;
2434 txq->reg_idx = reg_idx;
2435 txq->port_id = dev->data->port_id;
2436 txq->offloads = offloads;
2438 txq->tx_deferred_start = tx_conf->tx_deferred_start;
2440 txq->tx_ring_phys_addr = tz->iova;
2441 txq->tx_ring = (struct i40e_tx_desc *)tz->addr;
2443 /* Allocate software ring */
2445 rte_zmalloc_socket("i40e tx sw ring",
2446 sizeof(struct i40e_tx_entry) * nb_desc,
2447 RTE_CACHE_LINE_SIZE,
2449 if (!txq->sw_ring) {
2450 i40e_dev_tx_queue_release(txq);
2451 PMD_DRV_LOG(ERR, "Failed to allocate memory for SW TX ring");
2455 i40e_reset_tx_queue(txq);
2458 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
2459 if (!(vsi->enabled_tc & (1 << i)))
2461 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
2462 base = (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
2463 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
2464 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
2465 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
2467 if (queue_idx >= base && queue_idx < (base + BIT(bsf)))
2471 if (dev->data->dev_started) {
2472 if (i40e_dev_tx_queue_setup_runtime(dev, txq)) {
2473 i40e_dev_tx_queue_release(txq);
2478 * Use a simple TX queue without offloads or
2479 * multi segs if possible
2481 i40e_set_tx_function_flag(dev, txq);
2483 dev->data->tx_queues[queue_idx] = txq;
2489 i40e_dev_tx_queue_release(void *txq)
2491 struct i40e_tx_queue *q = (struct i40e_tx_queue *)txq;
2494 PMD_DRV_LOG(DEBUG, "Pointer to TX queue is NULL");
2498 i40e_tx_queue_release_mbufs(q);
2499 rte_free(q->sw_ring);
2503 const struct rte_memzone *
2504 i40e_memzone_reserve(const char *name, uint32_t len, int socket_id)
2506 const struct rte_memzone *mz;
2508 mz = rte_memzone_lookup(name);
2512 mz = rte_memzone_reserve_aligned(name, len, socket_id,
2513 RTE_MEMZONE_IOVA_CONTIG, I40E_RING_BASE_ALIGN);
2518 i40e_rx_queue_release_mbufs(struct i40e_rx_queue *rxq)
2522 /* SSE Vector driver has a different way of releasing mbufs. */
2523 if (rxq->rx_using_sse) {
2524 i40e_rx_queue_release_mbufs_vec(rxq);
2528 if (!rxq->sw_ring) {
2529 PMD_DRV_LOG(DEBUG, "Pointer to sw_ring is NULL");
2533 for (i = 0; i < rxq->nb_rx_desc; i++) {
2534 if (rxq->sw_ring[i].mbuf) {
2535 rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
2536 rxq->sw_ring[i].mbuf = NULL;
2539 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2540 if (rxq->rx_nb_avail == 0)
2542 for (i = 0; i < rxq->rx_nb_avail; i++) {
2543 struct rte_mbuf *mbuf;
2545 mbuf = rxq->rx_stage[rxq->rx_next_avail + i];
2546 rte_pktmbuf_free_seg(mbuf);
2548 rxq->rx_nb_avail = 0;
2549 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2553 i40e_reset_rx_queue(struct i40e_rx_queue *rxq)
2559 PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
2563 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2564 if (check_rx_burst_bulk_alloc_preconditions(rxq) == 0)
2565 len = (uint16_t)(rxq->nb_rx_desc + RTE_PMD_I40E_RX_MAX_BURST);
2567 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2568 len = rxq->nb_rx_desc;
2570 for (i = 0; i < len * sizeof(union i40e_rx_desc); i++)
2571 ((volatile char *)rxq->rx_ring)[i] = 0;
2573 memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
2574 for (i = 0; i < RTE_PMD_I40E_RX_MAX_BURST; ++i)
2575 rxq->sw_ring[rxq->nb_rx_desc + i].mbuf = &rxq->fake_mbuf;
2577 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2578 rxq->rx_nb_avail = 0;
2579 rxq->rx_next_avail = 0;
2580 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2581 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2583 rxq->nb_rx_hold = 0;
2584 rxq->pkt_first_seg = NULL;
2585 rxq->pkt_last_seg = NULL;
2587 rxq->rxrearm_start = 0;
2588 rxq->rxrearm_nb = 0;
2592 i40e_tx_queue_release_mbufs(struct i40e_tx_queue *txq)
2594 struct rte_eth_dev *dev;
2597 if (!txq || !txq->sw_ring) {
2598 PMD_DRV_LOG(DEBUG, "Pointer to txq or sw_ring is NULL");
2602 dev = &rte_eth_devices[txq->port_id];
2605 * vPMD tx will not set sw_ring's mbuf to NULL after free,
2606 * so need to free remains more carefully.
2608 #ifdef CC_AVX512_SUPPORT
2609 if (dev->tx_pkt_burst == i40e_xmit_pkts_vec_avx512) {
2610 struct i40e_vec_tx_entry *swr = (void *)txq->sw_ring;
2612 i = txq->tx_next_dd - txq->tx_rs_thresh + 1;
2613 if (txq->tx_tail < i) {
2614 for (; i < txq->nb_tx_desc; i++) {
2615 rte_pktmbuf_free_seg(swr[i].mbuf);
2620 for (; i < txq->tx_tail; i++) {
2621 rte_pktmbuf_free_seg(swr[i].mbuf);
2627 if (dev->tx_pkt_burst == i40e_xmit_pkts_vec_avx2 ||
2628 dev->tx_pkt_burst == i40e_xmit_pkts_vec) {
2629 i = txq->tx_next_dd - txq->tx_rs_thresh + 1;
2630 if (txq->tx_tail < i) {
2631 for (; i < txq->nb_tx_desc; i++) {
2632 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2633 txq->sw_ring[i].mbuf = NULL;
2637 for (; i < txq->tx_tail; i++) {
2638 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2639 txq->sw_ring[i].mbuf = NULL;
2642 for (i = 0; i < txq->nb_tx_desc; i++) {
2643 if (txq->sw_ring[i].mbuf) {
2644 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2645 txq->sw_ring[i].mbuf = NULL;
2652 i40e_tx_done_cleanup_full(struct i40e_tx_queue *txq,
2655 struct i40e_tx_entry *swr_ring = txq->sw_ring;
2656 uint16_t i, tx_last, tx_id;
2657 uint16_t nb_tx_free_last;
2658 uint16_t nb_tx_to_clean;
2661 /* Start free mbuf from the next of tx_tail */
2662 tx_last = txq->tx_tail;
2663 tx_id = swr_ring[tx_last].next_id;
2665 if (txq->nb_tx_free == 0 && i40e_xmit_cleanup(txq))
2668 nb_tx_to_clean = txq->nb_tx_free;
2669 nb_tx_free_last = txq->nb_tx_free;
2671 free_cnt = txq->nb_tx_desc;
2673 /* Loop through swr_ring to count the amount of
2674 * freeable mubfs and packets.
2676 for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
2677 for (i = 0; i < nb_tx_to_clean &&
2678 pkt_cnt < free_cnt &&
2679 tx_id != tx_last; i++) {
2680 if (swr_ring[tx_id].mbuf != NULL) {
2681 rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
2682 swr_ring[tx_id].mbuf = NULL;
2685 * last segment in the packet,
2686 * increment packet count
2688 pkt_cnt += (swr_ring[tx_id].last_id == tx_id);
2691 tx_id = swr_ring[tx_id].next_id;
2694 if (txq->tx_rs_thresh > txq->nb_tx_desc -
2695 txq->nb_tx_free || tx_id == tx_last)
2698 if (pkt_cnt < free_cnt) {
2699 if (i40e_xmit_cleanup(txq))
2702 nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
2703 nb_tx_free_last = txq->nb_tx_free;
2707 return (int)pkt_cnt;
2711 i40e_tx_done_cleanup_simple(struct i40e_tx_queue *txq,
2716 if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
2717 free_cnt = txq->nb_tx_desc;
2719 cnt = free_cnt - free_cnt % txq->tx_rs_thresh;
2721 for (i = 0; i < cnt; i += n) {
2722 if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_rs_thresh)
2725 n = i40e_tx_free_bufs(txq);
2735 i40e_tx_done_cleanup_vec(struct i40e_tx_queue *txq __rte_unused,
2736 uint32_t free_cnt __rte_unused)
2741 i40e_tx_done_cleanup(void *txq, uint32_t free_cnt)
2743 struct i40e_tx_queue *q = (struct i40e_tx_queue *)txq;
2744 struct rte_eth_dev *dev = &rte_eth_devices[q->port_id];
2745 struct i40e_adapter *ad =
2746 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2748 if (ad->tx_simple_allowed) {
2749 if (ad->tx_vec_allowed)
2750 return i40e_tx_done_cleanup_vec(q, free_cnt);
2752 return i40e_tx_done_cleanup_simple(q, free_cnt);
2754 return i40e_tx_done_cleanup_full(q, free_cnt);
2759 i40e_reset_tx_queue(struct i40e_tx_queue *txq)
2761 struct i40e_tx_entry *txe;
2762 uint16_t i, prev, size;
2765 PMD_DRV_LOG(DEBUG, "Pointer to txq is NULL");
2770 size = sizeof(struct i40e_tx_desc) * txq->nb_tx_desc;
2771 for (i = 0; i < size; i++)
2772 ((volatile char *)txq->tx_ring)[i] = 0;
2774 prev = (uint16_t)(txq->nb_tx_desc - 1);
2775 for (i = 0; i < txq->nb_tx_desc; i++) {
2776 volatile struct i40e_tx_desc *txd = &txq->tx_ring[i];
2778 txd->cmd_type_offset_bsz =
2779 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE);
2782 txe[prev].next_id = i;
2786 txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
2787 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
2790 txq->nb_tx_used = 0;
2792 txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
2793 txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
2796 /* Init the TX queue in hardware */
2798 i40e_tx_queue_init(struct i40e_tx_queue *txq)
2800 enum i40e_status_code err = I40E_SUCCESS;
2801 struct i40e_vsi *vsi = txq->vsi;
2802 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2803 uint16_t pf_q = txq->reg_idx;
2804 struct i40e_hmc_obj_txq tx_ctx;
2807 /* clear the context structure first */
2808 memset(&tx_ctx, 0, sizeof(tx_ctx));
2809 tx_ctx.new_context = 1;
2810 tx_ctx.base = txq->tx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
2811 tx_ctx.qlen = txq->nb_tx_desc;
2813 #ifdef RTE_LIBRTE_IEEE1588
2814 tx_ctx.timesync_ena = 1;
2816 tx_ctx.rdylist = rte_le_to_cpu_16(vsi->info.qs_handle[txq->dcb_tc]);
2817 if (vsi->type == I40E_VSI_FDIR)
2818 tx_ctx.fd_ena = TRUE;
2820 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2821 if (err != I40E_SUCCESS) {
2822 PMD_DRV_LOG(ERR, "Failure of clean lan tx queue context");
2826 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2827 if (err != I40E_SUCCESS) {
2828 PMD_DRV_LOG(ERR, "Failure of set lan tx queue context");
2832 /* Now associate this queue with this PCI function */
2833 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
2834 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2835 I40E_QTX_CTL_PF_INDX_MASK);
2836 I40E_WRITE_REG(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2837 I40E_WRITE_FLUSH(hw);
2839 txq->qtx_tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2845 i40e_alloc_rx_queue_mbufs(struct i40e_rx_queue *rxq)
2847 struct i40e_rx_entry *rxe = rxq->sw_ring;
2851 for (i = 0; i < rxq->nb_rx_desc; i++) {
2852 volatile union i40e_rx_desc *rxd;
2853 struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mp);
2855 if (unlikely(!mbuf)) {
2856 PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX");
2860 rte_mbuf_refcnt_set(mbuf, 1);
2862 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
2864 mbuf->port = rxq->port_id;
2867 rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
2869 rxd = &rxq->rx_ring[i];
2870 rxd->read.pkt_addr = dma_addr;
2871 rxd->read.hdr_addr = 0;
2872 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2873 rxd->read.rsvd1 = 0;
2874 rxd->read.rsvd2 = 0;
2875 #endif /* RTE_LIBRTE_I40E_16BYTE_RX_DESC */
2884 * Calculate the buffer length, and check the jumbo frame
2885 * and maximum packet length.
2888 i40e_rx_queue_config(struct i40e_rx_queue *rxq)
2890 struct i40e_pf *pf = I40E_VSI_TO_PF(rxq->vsi);
2891 struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
2892 struct rte_eth_dev_data *data = pf->dev_data;
2895 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
2896 RTE_PKTMBUF_HEADROOM);
2898 switch (pf->flags & (I40E_FLAG_HEADER_SPLIT_DISABLED |
2899 I40E_FLAG_HEADER_SPLIT_ENABLED)) {
2900 case I40E_FLAG_HEADER_SPLIT_ENABLED: /* Not supported */
2901 rxq->rx_hdr_len = RTE_ALIGN(I40E_RXBUF_SZ_1024,
2902 (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
2903 rxq->rx_buf_len = RTE_ALIGN(I40E_RXBUF_SZ_2048,
2904 (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
2905 rxq->hs_mode = i40e_header_split_enabled;
2907 case I40E_FLAG_HEADER_SPLIT_DISABLED:
2909 rxq->rx_hdr_len = 0;
2910 rxq->rx_buf_len = RTE_ALIGN_FLOOR(buf_size,
2911 (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
2912 rxq->hs_mode = i40e_header_split_none;
2917 RTE_MIN((uint32_t)(hw->func_caps.rx_buf_chain_len *
2918 rxq->rx_buf_len), data->dev_conf.rxmode.max_rx_pkt_len);
2919 if (data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
2920 if (rxq->max_pkt_len <= I40E_ETH_MAX_LEN ||
2921 rxq->max_pkt_len > I40E_FRAME_SIZE_MAX) {
2922 PMD_DRV_LOG(ERR, "maximum packet length must "
2923 "be larger than %u and smaller than %u,"
2924 "as jumbo frame is enabled",
2925 (uint32_t)I40E_ETH_MAX_LEN,
2926 (uint32_t)I40E_FRAME_SIZE_MAX);
2927 return I40E_ERR_CONFIG;
2930 if (rxq->max_pkt_len < RTE_ETHER_MIN_LEN ||
2931 rxq->max_pkt_len > I40E_ETH_MAX_LEN) {
2932 PMD_DRV_LOG(ERR, "maximum packet length must be "
2933 "larger than %u and smaller than %u, "
2934 "as jumbo frame is disabled",
2935 (uint32_t)RTE_ETHER_MIN_LEN,
2936 (uint32_t)I40E_ETH_MAX_LEN);
2937 return I40E_ERR_CONFIG;
2944 /* Init the RX queue in hardware */
2946 i40e_rx_queue_init(struct i40e_rx_queue *rxq)
2948 int err = I40E_SUCCESS;
2949 struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
2950 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(rxq->vsi);
2951 uint16_t pf_q = rxq->reg_idx;
2953 struct i40e_hmc_obj_rxq rx_ctx;
2955 err = i40e_rx_queue_config(rxq);
2957 PMD_DRV_LOG(ERR, "Failed to config RX queue");
2961 /* Clear the context structure first */
2962 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
2963 rx_ctx.dbuff = rxq->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
2964 rx_ctx.hbuff = rxq->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
2966 rx_ctx.base = rxq->rx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
2967 rx_ctx.qlen = rxq->nb_rx_desc;
2968 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2971 rx_ctx.dtype = rxq->hs_mode;
2973 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_ALL;
2975 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
2976 rx_ctx.rxmax = rxq->max_pkt_len;
2977 rx_ctx.tphrdesc_ena = 1;
2978 rx_ctx.tphwdesc_ena = 1;
2979 rx_ctx.tphdata_ena = 1;
2980 rx_ctx.tphhead_ena = 1;
2981 rx_ctx.lrxqthresh = 2;
2982 rx_ctx.crcstrip = (rxq->crc_len == 0) ? 1 : 0;
2984 /* showiv indicates if inner VLAN is stripped inside of tunnel
2985 * packet. When set it to 1, vlan information is stripped from
2986 * the inner header, but the hardware does not put it in the
2987 * descriptor. So set it zero by default.
2992 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
2993 if (err != I40E_SUCCESS) {
2994 PMD_DRV_LOG(ERR, "Failed to clear LAN RX queue context");
2997 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
2998 if (err != I40E_SUCCESS) {
2999 PMD_DRV_LOG(ERR, "Failed to set LAN RX queue context");
3003 rxq->qrx_tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
3005 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
3006 RTE_PKTMBUF_HEADROOM);
3008 /* Check if scattered RX needs to be used. */
3009 if (rxq->max_pkt_len > buf_size)
3010 dev_data->scattered_rx = 1;
3012 /* Init the RX tail regieter. */
3013 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
3019 i40e_dev_clear_queues(struct rte_eth_dev *dev)
3023 PMD_INIT_FUNC_TRACE();
3025 for (i = 0; i < dev->data->nb_tx_queues; i++) {
3026 if (!dev->data->tx_queues[i])
3028 i40e_tx_queue_release_mbufs(dev->data->tx_queues[i]);
3029 i40e_reset_tx_queue(dev->data->tx_queues[i]);
3032 for (i = 0; i < dev->data->nb_rx_queues; i++) {
3033 if (!dev->data->rx_queues[i])
3035 i40e_rx_queue_release_mbufs(dev->data->rx_queues[i]);
3036 i40e_reset_rx_queue(dev->data->rx_queues[i]);
3041 i40e_dev_free_queues(struct rte_eth_dev *dev)
3045 PMD_INIT_FUNC_TRACE();
3047 for (i = 0; i < dev->data->nb_rx_queues; i++) {
3048 if (!dev->data->rx_queues[i])
3050 i40e_dev_rx_queue_release(dev->data->rx_queues[i]);
3051 dev->data->rx_queues[i] = NULL;
3052 rte_eth_dma_zone_free(dev, "rx_ring", i);
3055 for (i = 0; i < dev->data->nb_tx_queues; i++) {
3056 if (!dev->data->tx_queues[i])
3058 i40e_dev_tx_queue_release(dev->data->tx_queues[i]);
3059 dev->data->tx_queues[i] = NULL;
3060 rte_eth_dma_zone_free(dev, "tx_ring", i);
3064 enum i40e_status_code
3065 i40e_fdir_setup_tx_resources(struct i40e_pf *pf)
3067 struct i40e_tx_queue *txq;
3068 const struct rte_memzone *tz = NULL;
3069 struct rte_eth_dev *dev;
3073 PMD_DRV_LOG(ERR, "PF is not available");
3074 return I40E_ERR_BAD_PTR;
3077 dev = &rte_eth_devices[pf->dev_data->port_id];
3079 /* Allocate the TX queue data structure. */
3080 txq = rte_zmalloc_socket("i40e fdir tx queue",
3081 sizeof(struct i40e_tx_queue),
3082 RTE_CACHE_LINE_SIZE,
3085 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
3086 "tx queue structure.");
3087 return I40E_ERR_NO_MEMORY;
3090 /* Allocate TX hardware ring descriptors. */
3091 ring_size = sizeof(struct i40e_tx_desc) * I40E_FDIR_NUM_TX_DESC;
3092 ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
3094 tz = rte_eth_dma_zone_reserve(dev, "fdir_tx_ring",
3095 I40E_FDIR_QUEUE_ID, ring_size,
3096 I40E_RING_BASE_ALIGN, SOCKET_ID_ANY);
3098 i40e_dev_tx_queue_release(txq);
3099 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX.");
3100 return I40E_ERR_NO_MEMORY;
3103 txq->nb_tx_desc = I40E_FDIR_NUM_TX_DESC;
3104 txq->queue_id = I40E_FDIR_QUEUE_ID;
3105 txq->reg_idx = pf->fdir.fdir_vsi->base_queue;
3106 txq->vsi = pf->fdir.fdir_vsi;
3108 txq->tx_ring_phys_addr = tz->iova;
3109 txq->tx_ring = (struct i40e_tx_desc *)tz->addr;
3112 * don't need to allocate software ring and reset for the fdir
3113 * program queue just set the queue has been configured.
3117 pf->fdir.txq_available_buf_count = I40E_FDIR_PRG_PKT_CNT;
3119 return I40E_SUCCESS;
3122 enum i40e_status_code
3123 i40e_fdir_setup_rx_resources(struct i40e_pf *pf)
3125 struct i40e_rx_queue *rxq;
3126 const struct rte_memzone *rz = NULL;
3128 struct rte_eth_dev *dev;
3131 PMD_DRV_LOG(ERR, "PF is not available");
3132 return I40E_ERR_BAD_PTR;
3135 dev = &rte_eth_devices[pf->dev_data->port_id];
3137 /* Allocate the RX queue data structure. */
3138 rxq = rte_zmalloc_socket("i40e fdir rx queue",
3139 sizeof(struct i40e_rx_queue),
3140 RTE_CACHE_LINE_SIZE,
3143 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
3144 "rx queue structure.");
3145 return I40E_ERR_NO_MEMORY;
3148 /* Allocate RX hardware ring descriptors. */
3149 ring_size = sizeof(union i40e_rx_desc) * I40E_FDIR_NUM_RX_DESC;
3150 ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
3152 rz = rte_eth_dma_zone_reserve(dev, "fdir_rx_ring",
3153 I40E_FDIR_QUEUE_ID, ring_size,
3154 I40E_RING_BASE_ALIGN, SOCKET_ID_ANY);
3156 i40e_dev_rx_queue_release(rxq);
3157 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX.");
3158 return I40E_ERR_NO_MEMORY;
3161 rxq->nb_rx_desc = I40E_FDIR_NUM_RX_DESC;
3162 rxq->queue_id = I40E_FDIR_QUEUE_ID;
3163 rxq->reg_idx = pf->fdir.fdir_vsi->base_queue;
3164 rxq->vsi = pf->fdir.fdir_vsi;
3166 rxq->rx_ring_phys_addr = rz->iova;
3167 memset(rz->addr, 0, I40E_FDIR_NUM_RX_DESC * sizeof(union i40e_rx_desc));
3168 rxq->rx_ring = (union i40e_rx_desc *)rz->addr;
3171 * Don't need to allocate software ring and reset for the fdir
3172 * rx queue, just set the queue has been configured.
3177 return I40E_SUCCESS;
3181 i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
3182 struct rte_eth_rxq_info *qinfo)
3184 struct i40e_rx_queue *rxq;
3186 rxq = dev->data->rx_queues[queue_id];
3188 qinfo->mp = rxq->mp;
3189 qinfo->scattered_rx = dev->data->scattered_rx;
3190 qinfo->nb_desc = rxq->nb_rx_desc;
3192 qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
3193 qinfo->conf.rx_drop_en = rxq->drop_en;
3194 qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
3195 qinfo->conf.offloads = rxq->offloads;
3199 i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
3200 struct rte_eth_txq_info *qinfo)
3202 struct i40e_tx_queue *txq;
3204 txq = dev->data->tx_queues[queue_id];
3206 qinfo->nb_desc = txq->nb_tx_desc;
3208 qinfo->conf.tx_thresh.pthresh = txq->pthresh;
3209 qinfo->conf.tx_thresh.hthresh = txq->hthresh;
3210 qinfo->conf.tx_thresh.wthresh = txq->wthresh;
3212 qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
3213 qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
3214 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
3215 qinfo->conf.offloads = txq->offloads;
3219 get_avx_supported(bool request_avx512)
3222 if (request_avx512) {
3223 if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512 &&
3224 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1 &&
3225 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512BW) == 1)
3226 #ifdef CC_AVX512_SUPPORT
3230 "AVX512 is not supported in build env");
3234 if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256 &&
3235 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1 &&
3236 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1)
3237 #ifdef CC_AVX2_SUPPORT
3241 "AVX2 is not supported in build env");
3246 RTE_SET_USED(request_avx512);
3247 #endif /* RTE_ARCH_X86 */
3254 i40e_set_rx_function(struct rte_eth_dev *dev)
3256 struct i40e_adapter *ad =
3257 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3258 uint16_t rx_using_sse, i;
3259 /* In order to allow Vector Rx there are a few configuration
3260 * conditions to be met and Rx Bulk Allocation should be allowed.
3262 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3264 ad->rx_use_avx512 = false;
3265 ad->rx_use_avx2 = false;
3267 if (i40e_rx_vec_dev_conf_condition_check(dev) ||
3268 !ad->rx_bulk_alloc_allowed) {
3269 PMD_INIT_LOG(DEBUG, "Port[%d] doesn't meet"
3270 " Vector Rx preconditions",
3271 dev->data->port_id);
3273 ad->rx_vec_allowed = false;
3275 if (ad->rx_vec_allowed) {
3276 for (i = 0; i < dev->data->nb_rx_queues; i++) {
3277 struct i40e_rx_queue *rxq =
3278 dev->data->rx_queues[i];
3280 if (rxq && i40e_rxq_vec_setup(rxq)) {
3281 ad->rx_vec_allowed = false;
3286 ad->rx_use_avx512 = get_avx_supported(1);
3288 if (!ad->rx_use_avx512)
3289 ad->rx_use_avx2 = get_avx_supported(0);
3294 if (ad->rx_vec_allowed &&
3295 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
3297 if (dev->data->scattered_rx) {
3298 if (ad->rx_use_avx512) {
3299 #ifdef CC_AVX512_SUPPORT
3301 "Using AVX512 Vector Scattered Rx (port %d).",
3302 dev->data->port_id);
3304 i40e_recv_scattered_pkts_vec_avx512;
3308 "Using %sVector Scattered Rx (port %d).",
3309 ad->rx_use_avx2 ? "avx2 " : "",
3310 dev->data->port_id);
3311 dev->rx_pkt_burst = ad->rx_use_avx2 ?
3312 i40e_recv_scattered_pkts_vec_avx2 :
3313 i40e_recv_scattered_pkts_vec;
3316 if (ad->rx_use_avx512) {
3317 #ifdef CC_AVX512_SUPPORT
3319 "Using AVX512 Vector Rx (port %d).",
3320 dev->data->port_id);
3322 i40e_recv_pkts_vec_avx512;
3326 "Using %sVector Rx (port %d).",
3327 ad->rx_use_avx2 ? "avx2 " : "",
3328 dev->data->port_id);
3329 dev->rx_pkt_burst = ad->rx_use_avx2 ?
3330 i40e_recv_pkts_vec_avx2 :
3334 #else /* RTE_ARCH_X86 */
3335 if (dev->data->scattered_rx) {
3337 "Using Vector Scattered Rx (port %d).",
3338 dev->data->port_id);
3339 dev->rx_pkt_burst = i40e_recv_scattered_pkts_vec;
3341 PMD_INIT_LOG(DEBUG, "Using Vector Rx (port %d).",
3342 dev->data->port_id);
3343 dev->rx_pkt_burst = i40e_recv_pkts_vec;
3345 #endif /* RTE_ARCH_X86 */
3346 } else if (!dev->data->scattered_rx && ad->rx_bulk_alloc_allowed) {
3347 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
3348 "satisfied. Rx Burst Bulk Alloc function "
3349 "will be used on port=%d.",
3350 dev->data->port_id);
3352 dev->rx_pkt_burst = i40e_recv_pkts_bulk_alloc;
3354 /* Simple Rx Path. */
3355 PMD_INIT_LOG(DEBUG, "Simple Rx path will be used on port=%d.",
3356 dev->data->port_id);
3357 dev->rx_pkt_burst = dev->data->scattered_rx ?
3358 i40e_recv_scattered_pkts :
3362 /* Propagate information about RX function choice through all queues. */
3363 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3365 (dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec ||
3366 dev->rx_pkt_burst == i40e_recv_pkts_vec ||
3367 #ifdef CC_AVX512_SUPPORT
3368 dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx512 ||
3369 dev->rx_pkt_burst == i40e_recv_pkts_vec_avx512 ||
3371 dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx2 ||
3372 dev->rx_pkt_burst == i40e_recv_pkts_vec_avx2);
3374 for (i = 0; i < dev->data->nb_rx_queues; i++) {
3375 struct i40e_rx_queue *rxq = dev->data->rx_queues[i];
3378 rxq->rx_using_sse = rx_using_sse;
3383 static const struct {
3384 eth_rx_burst_t pkt_burst;
3386 } i40e_rx_burst_infos[] = {
3387 { i40e_recv_scattered_pkts, "Scalar Scattered" },
3388 { i40e_recv_pkts_bulk_alloc, "Scalar Bulk Alloc" },
3389 { i40e_recv_pkts, "Scalar" },
3391 #ifdef CC_AVX512_SUPPORT
3392 { i40e_recv_scattered_pkts_vec_avx512, "Vector AVX512 Scattered" },
3393 { i40e_recv_pkts_vec_avx512, "Vector AVX512" },
3395 { i40e_recv_scattered_pkts_vec_avx2, "Vector AVX2 Scattered" },
3396 { i40e_recv_pkts_vec_avx2, "Vector AVX2" },
3397 { i40e_recv_scattered_pkts_vec, "Vector SSE Scattered" },
3398 { i40e_recv_pkts_vec, "Vector SSE" },
3399 #elif defined(RTE_ARCH_ARM64)
3400 { i40e_recv_scattered_pkts_vec, "Vector Neon Scattered" },
3401 { i40e_recv_pkts_vec, "Vector Neon" },
3402 #elif defined(RTE_ARCH_PPC_64)
3403 { i40e_recv_scattered_pkts_vec, "Vector AltiVec Scattered" },
3404 { i40e_recv_pkts_vec, "Vector AltiVec" },
3409 i40e_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
3410 struct rte_eth_burst_mode *mode)
3412 eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
3416 for (i = 0; i < RTE_DIM(i40e_rx_burst_infos); ++i) {
3417 if (pkt_burst == i40e_rx_burst_infos[i].pkt_burst) {
3418 snprintf(mode->info, sizeof(mode->info), "%s",
3419 i40e_rx_burst_infos[i].info);
3429 i40e_set_tx_function_flag(struct rte_eth_dev *dev, struct i40e_tx_queue *txq)
3431 struct i40e_adapter *ad =
3432 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3434 /* Use a simple Tx queue if possible (only fast free is allowed) */
3435 ad->tx_simple_allowed =
3437 (txq->offloads & DEV_TX_OFFLOAD_MBUF_FAST_FREE) &&
3438 txq->tx_rs_thresh >= RTE_PMD_I40E_TX_MAX_BURST);
3439 ad->tx_vec_allowed = (ad->tx_simple_allowed &&
3440 txq->tx_rs_thresh <= RTE_I40E_TX_MAX_FREE_BUF_SZ);
3442 if (ad->tx_vec_allowed)
3443 PMD_INIT_LOG(DEBUG, "Vector Tx can be enabled on Tx queue %u.",
3445 else if (ad->tx_simple_allowed)
3446 PMD_INIT_LOG(DEBUG, "Simple Tx can be enabled on Tx queue %u.",
3450 "Neither simple nor vector Tx enabled on Tx queue %u\n",
3455 i40e_set_tx_function(struct rte_eth_dev *dev)
3457 struct i40e_adapter *ad =
3458 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3461 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3463 ad->tx_use_avx2 = false;
3464 ad->tx_use_avx512 = false;
3466 if (ad->tx_vec_allowed) {
3467 for (i = 0; i < dev->data->nb_tx_queues; i++) {
3468 struct i40e_tx_queue *txq =
3469 dev->data->tx_queues[i];
3471 if (txq && i40e_txq_vec_setup(txq)) {
3472 ad->tx_vec_allowed = false;
3477 ad->tx_use_avx512 = get_avx_supported(1);
3479 if (!ad->tx_use_avx512)
3480 ad->tx_use_avx2 = get_avx_supported(0);
3485 if (ad->tx_simple_allowed) {
3486 if (ad->tx_vec_allowed &&
3487 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
3489 if (ad->tx_use_avx512) {
3490 #ifdef CC_AVX512_SUPPORT
3491 PMD_DRV_LOG(NOTICE, "Using AVX512 Vector Tx (port %d).",
3492 dev->data->port_id);
3493 dev->tx_pkt_burst = i40e_xmit_pkts_vec_avx512;
3496 PMD_INIT_LOG(DEBUG, "Using %sVector Tx (port %d).",
3497 ad->tx_use_avx2 ? "avx2 " : "",
3498 dev->data->port_id);
3499 dev->tx_pkt_burst = ad->tx_use_avx2 ?
3500 i40e_xmit_pkts_vec_avx2 :
3503 #else /* RTE_ARCH_X86 */
3504 PMD_INIT_LOG(DEBUG, "Using Vector Tx (port %d).",
3505 dev->data->port_id);
3506 dev->tx_pkt_burst = i40e_xmit_pkts_vec;
3507 #endif /* RTE_ARCH_X86 */
3509 PMD_INIT_LOG(DEBUG, "Simple tx finally be used.");
3510 dev->tx_pkt_burst = i40e_xmit_pkts_simple;
3512 dev->tx_pkt_prepare = i40e_simple_prep_pkts;
3514 PMD_INIT_LOG(DEBUG, "Xmit tx finally be used.");
3515 dev->tx_pkt_burst = i40e_xmit_pkts;
3516 dev->tx_pkt_prepare = i40e_prep_pkts;
3520 static const struct {
3521 eth_tx_burst_t pkt_burst;
3523 } i40e_tx_burst_infos[] = {
3524 { i40e_xmit_pkts_simple, "Scalar Simple" },
3525 { i40e_xmit_pkts, "Scalar" },
3527 #ifdef CC_AVX512_SUPPORT
3528 { i40e_xmit_pkts_vec_avx512, "Vector AVX512" },
3530 { i40e_xmit_pkts_vec_avx2, "Vector AVX2" },
3531 { i40e_xmit_pkts_vec, "Vector SSE" },
3532 #elif defined(RTE_ARCH_ARM64)
3533 { i40e_xmit_pkts_vec, "Vector Neon" },
3534 #elif defined(RTE_ARCH_PPC_64)
3535 { i40e_xmit_pkts_vec, "Vector AltiVec" },
3540 i40e_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
3541 struct rte_eth_burst_mode *mode)
3543 eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
3547 for (i = 0; i < RTE_DIM(i40e_tx_burst_infos); ++i) {
3548 if (pkt_burst == i40e_tx_burst_infos[i].pkt_burst) {
3549 snprintf(mode->info, sizeof(mode->info), "%s",
3550 i40e_tx_burst_infos[i].info);
3560 i40e_set_default_ptype_table(struct rte_eth_dev *dev)
3562 struct i40e_adapter *ad =
3563 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3566 for (i = 0; i < I40E_MAX_PKT_TYPE; i++)
3567 ad->ptype_tbl[i] = i40e_get_default_pkt_type(i);
3571 i40e_set_default_pctype_table(struct rte_eth_dev *dev)
3573 struct i40e_adapter *ad =
3574 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3575 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3578 for (i = 0; i < I40E_FLOW_TYPE_MAX; i++)
3579 ad->pctypes_tbl[i] = 0ULL;
3580 ad->flow_types_mask = 0ULL;
3581 ad->pctypes_mask = 0ULL;
3583 ad->pctypes_tbl[RTE_ETH_FLOW_FRAG_IPV4] =
3584 (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4);
3585 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] =
3586 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP);
3587 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_TCP] =
3588 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
3589 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_SCTP] =
3590 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP);
3591 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_OTHER] =
3592 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
3593 ad->pctypes_tbl[RTE_ETH_FLOW_FRAG_IPV6] =
3594 (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6);
3595 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] =
3596 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP);
3597 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_TCP] =
3598 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
3599 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_SCTP] =
3600 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP);
3601 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_OTHER] =
3602 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
3603 ad->pctypes_tbl[RTE_ETH_FLOW_L2_PAYLOAD] =
3604 (1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD);
3606 if (hw->mac.type == I40E_MAC_X722 ||
3607 hw->mac.type == I40E_MAC_X722_VF) {
3608 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] |=
3609 (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP);
3610 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] |=
3611 (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
3612 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_TCP] |=
3613 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
3614 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] |=
3615 (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP);
3616 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] |=
3617 (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
3618 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_TCP] |=
3619 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
3622 for (i = 0; i < I40E_FLOW_TYPE_MAX; i++) {
3623 if (ad->pctypes_tbl[i])
3624 ad->flow_types_mask |= (1ULL << i);
3625 ad->pctypes_mask |= ad->pctypes_tbl[i];
3629 #ifndef CC_AVX2_SUPPORT
3631 i40e_recv_pkts_vec_avx2(void __rte_unused *rx_queue,
3632 struct rte_mbuf __rte_unused **rx_pkts,
3633 uint16_t __rte_unused nb_pkts)
3639 i40e_recv_scattered_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_xmit_pkts_vec_avx2(void __rte_unused * tx_queue,
3648 struct rte_mbuf __rte_unused **tx_pkts,
3649 uint16_t __rte_unused nb_pkts)
3653 #endif /* ifndef CC_AVX2_SUPPORT */