4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <sys/queue.h>
44 #include <rte_string_fns.h>
45 #include <rte_memzone.h>
47 #include <rte_malloc.h>
48 #include <rte_ether.h>
49 #include <rte_ethdev.h>
54 #include "i40e_logs.h"
55 #include "base/i40e_prototype.h"
56 #include "base/i40e_type.h"
57 #include "i40e_ethdev.h"
58 #include "i40e_rxtx.h"
60 #define DEFAULT_TX_RS_THRESH 32
61 #define DEFAULT_TX_FREE_THRESH 32
62 #define I40E_MAX_PKT_TYPE 256
64 #define I40E_TX_MAX_BURST 32
66 #define I40E_DMA_MEM_ALIGN 4096
68 /* Base address of the HW descriptor ring should be 128B aligned. */
69 #define I40E_RING_BASE_ALIGN 128
71 #define I40E_SIMPLE_FLAGS ((uint32_t)ETH_TXQ_FLAGS_NOMULTSEGS | \
72 ETH_TXQ_FLAGS_NOOFFLOADS)
74 #define I40E_TXD_CMD (I40E_TX_DESC_CMD_EOP | I40E_TX_DESC_CMD_RS)
76 #define I40E_TX_CKSUM_OFFLOAD_MASK ( \
84 PKT_TX_OUTER_IP_CKSUM)
86 static uint16_t i40e_xmit_pkts_simple(void *tx_queue,
87 struct rte_mbuf **tx_pkts,
91 i40e_rxd_to_vlan_tci(struct rte_mbuf *mb, volatile union i40e_rx_desc *rxdp)
93 if (rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
94 (1 << I40E_RX_DESC_STATUS_L2TAG1P_SHIFT)) {
95 mb->ol_flags |= PKT_RX_VLAN_PKT | PKT_RX_VLAN_STRIPPED;
97 rte_le_to_cpu_16(rxdp->wb.qword0.lo_dword.l2tag1);
98 PMD_RX_LOG(DEBUG, "Descriptor l2tag1: %u",
99 rte_le_to_cpu_16(rxdp->wb.qword0.lo_dword.l2tag1));
103 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
104 if (rte_le_to_cpu_16(rxdp->wb.qword2.ext_status) &
105 (1 << I40E_RX_DESC_EXT_STATUS_L2TAG2P_SHIFT)) {
106 mb->ol_flags |= PKT_RX_QINQ_STRIPPED;
107 mb->vlan_tci_outer = mb->vlan_tci;
108 mb->vlan_tci = rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_2);
109 PMD_RX_LOG(DEBUG, "Descriptor l2tag2_1: %u, l2tag2_2: %u",
110 rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_1),
111 rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_2));
113 mb->vlan_tci_outer = 0;
116 PMD_RX_LOG(DEBUG, "Mbuf vlan_tci: %u, vlan_tci_outer: %u",
117 mb->vlan_tci, mb->vlan_tci_outer);
120 /* Translate the rx descriptor status to pkt flags */
121 static inline uint64_t
122 i40e_rxd_status_to_pkt_flags(uint64_t qword)
126 /* Check if RSS_HASH */
127 flags = (((qword >> I40E_RX_DESC_STATUS_FLTSTAT_SHIFT) &
128 I40E_RX_DESC_FLTSTAT_RSS_HASH) ==
129 I40E_RX_DESC_FLTSTAT_RSS_HASH) ? PKT_RX_RSS_HASH : 0;
131 /* Check if FDIR Match */
132 flags |= (qword & (1 << I40E_RX_DESC_STATUS_FLM_SHIFT) ?
138 static inline uint64_t
139 i40e_rxd_error_to_pkt_flags(uint64_t qword)
142 uint64_t error_bits = (qword >> I40E_RXD_QW1_ERROR_SHIFT);
144 #define I40E_RX_ERR_BITS 0x3f
145 if (likely((error_bits & I40E_RX_ERR_BITS) == 0)) {
146 flags |= (PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD);
150 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_IPE_SHIFT)))
151 flags |= PKT_RX_IP_CKSUM_BAD;
153 flags |= PKT_RX_IP_CKSUM_GOOD;
155 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_L4E_SHIFT)))
156 flags |= PKT_RX_L4_CKSUM_BAD;
158 flags |= PKT_RX_L4_CKSUM_GOOD;
160 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_EIPE_SHIFT)))
161 flags |= PKT_RX_EIP_CKSUM_BAD;
166 /* Function to check and set the ieee1588 timesync index and get the
169 #ifdef RTE_LIBRTE_IEEE1588
170 static inline uint64_t
171 i40e_get_iee15888_flags(struct rte_mbuf *mb, uint64_t qword)
173 uint64_t pkt_flags = 0;
174 uint16_t tsyn = (qword & (I40E_RXD_QW1_STATUS_TSYNVALID_MASK
175 | I40E_RXD_QW1_STATUS_TSYNINDX_MASK))
176 >> I40E_RX_DESC_STATUS_TSYNINDX_SHIFT;
178 if ((mb->packet_type & RTE_PTYPE_L2_MASK)
179 == RTE_PTYPE_L2_ETHER_TIMESYNC)
180 pkt_flags = PKT_RX_IEEE1588_PTP;
182 pkt_flags |= PKT_RX_IEEE1588_TMST;
183 mb->timesync = tsyn & 0x03;
190 #define I40E_RX_DESC_EXT_STATUS_FLEXBH_MASK 0x03
191 #define I40E_RX_DESC_EXT_STATUS_FLEXBH_FD_ID 0x01
192 #define I40E_RX_DESC_EXT_STATUS_FLEXBH_FLEX 0x02
193 #define I40E_RX_DESC_EXT_STATUS_FLEXBL_MASK 0x03
194 #define I40E_RX_DESC_EXT_STATUS_FLEXBL_FLEX 0x01
196 static inline uint64_t
197 i40e_rxd_build_fdir(volatile union i40e_rx_desc *rxdp, struct rte_mbuf *mb)
200 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
201 uint16_t flexbh, flexbl;
203 flexbh = (rte_le_to_cpu_32(rxdp->wb.qword2.ext_status) >>
204 I40E_RX_DESC_EXT_STATUS_FLEXBH_SHIFT) &
205 I40E_RX_DESC_EXT_STATUS_FLEXBH_MASK;
206 flexbl = (rte_le_to_cpu_32(rxdp->wb.qword2.ext_status) >>
207 I40E_RX_DESC_EXT_STATUS_FLEXBL_SHIFT) &
208 I40E_RX_DESC_EXT_STATUS_FLEXBL_MASK;
211 if (flexbh == I40E_RX_DESC_EXT_STATUS_FLEXBH_FD_ID) {
213 rte_le_to_cpu_32(rxdp->wb.qword3.hi_dword.fd_id);
214 flags |= PKT_RX_FDIR_ID;
215 } else if (flexbh == I40E_RX_DESC_EXT_STATUS_FLEXBH_FLEX) {
217 rte_le_to_cpu_32(rxdp->wb.qword3.hi_dword.flex_bytes_hi);
218 flags |= PKT_RX_FDIR_FLX;
220 if (flexbl == I40E_RX_DESC_EXT_STATUS_FLEXBL_FLEX) {
222 rte_le_to_cpu_32(rxdp->wb.qword3.lo_dword.flex_bytes_lo);
223 flags |= PKT_RX_FDIR_FLX;
227 rte_le_to_cpu_32(rxdp->wb.qword0.hi_dword.fd_id);
228 flags |= PKT_RX_FDIR_ID;
234 i40e_parse_tunneling_params(uint64_t ol_flags,
235 union i40e_tx_offload tx_offload,
236 uint32_t *cd_tunneling)
238 /* EIPT: External (outer) IP header type */
239 if (ol_flags & PKT_TX_OUTER_IP_CKSUM)
240 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV4;
241 else if (ol_flags & PKT_TX_OUTER_IPV4)
242 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV4_NO_CSUM;
243 else if (ol_flags & PKT_TX_OUTER_IPV6)
244 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV6;
246 /* EIPLEN: External (outer) IP header length, in DWords */
247 *cd_tunneling |= (tx_offload.outer_l3_len >> 2) <<
248 I40E_TXD_CTX_QW0_EXT_IPLEN_SHIFT;
250 /* L4TUNT: L4 Tunneling Type */
251 switch (ol_flags & PKT_TX_TUNNEL_MASK) {
252 case PKT_TX_TUNNEL_IPIP:
253 /* for non UDP / GRE tunneling, set to 00b */
255 case PKT_TX_TUNNEL_VXLAN:
256 case PKT_TX_TUNNEL_GENEVE:
257 *cd_tunneling |= I40E_TXD_CTX_UDP_TUNNELING;
259 case PKT_TX_TUNNEL_GRE:
260 *cd_tunneling |= I40E_TXD_CTX_GRE_TUNNELING;
263 PMD_TX_LOG(ERR, "Tunnel type not supported\n");
267 /* L4TUNLEN: L4 Tunneling Length, in Words
269 * We depend on app to set rte_mbuf.l2_len correctly.
270 * For IP in GRE it should be set to the length of the GRE
272 * for MAC in GRE or MAC in UDP it should be set to the length
273 * of the GRE or UDP headers plus the inner MAC up to including
274 * its last Ethertype.
276 *cd_tunneling |= (tx_offload.l2_len >> 1) <<
277 I40E_TXD_CTX_QW0_NATLEN_SHIFT;
281 i40e_txd_enable_checksum(uint64_t ol_flags,
284 union i40e_tx_offload tx_offload)
287 if (ol_flags & PKT_TX_TUNNEL_MASK)
288 *td_offset |= (tx_offload.outer_l2_len >> 1)
289 << I40E_TX_DESC_LENGTH_MACLEN_SHIFT;
291 *td_offset |= (tx_offload.l2_len >> 1)
292 << I40E_TX_DESC_LENGTH_MACLEN_SHIFT;
294 /* Enable L3 checksum offloads */
295 if (ol_flags & PKT_TX_IP_CKSUM) {
296 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV4_CSUM;
297 *td_offset |= (tx_offload.l3_len >> 2)
298 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
299 } else if (ol_flags & PKT_TX_IPV4) {
300 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV4;
301 *td_offset |= (tx_offload.l3_len >> 2)
302 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
303 } else if (ol_flags & PKT_TX_IPV6) {
304 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV6;
305 *td_offset |= (tx_offload.l3_len >> 2)
306 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
309 if (ol_flags & PKT_TX_TCP_SEG) {
310 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_TCP;
311 *td_offset |= (tx_offload.l4_len >> 2)
312 << I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
316 /* Enable L4 checksum offloads */
317 switch (ol_flags & PKT_TX_L4_MASK) {
318 case PKT_TX_TCP_CKSUM:
319 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_TCP;
320 *td_offset |= (sizeof(struct tcp_hdr) >> 2) <<
321 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
323 case PKT_TX_SCTP_CKSUM:
324 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_SCTP;
325 *td_offset |= (sizeof(struct sctp_hdr) >> 2) <<
326 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
328 case PKT_TX_UDP_CKSUM:
329 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_UDP;
330 *td_offset |= (sizeof(struct udp_hdr) >> 2) <<
331 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
338 /* Construct the tx flags */
339 static inline uint64_t
340 i40e_build_ctob(uint32_t td_cmd,
345 return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA |
346 ((uint64_t)td_cmd << I40E_TXD_QW1_CMD_SHIFT) |
347 ((uint64_t)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) |
348 ((uint64_t)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) |
349 ((uint64_t)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT));
353 i40e_xmit_cleanup(struct i40e_tx_queue *txq)
355 struct i40e_tx_entry *sw_ring = txq->sw_ring;
356 volatile struct i40e_tx_desc *txd = txq->tx_ring;
357 uint16_t last_desc_cleaned = txq->last_desc_cleaned;
358 uint16_t nb_tx_desc = txq->nb_tx_desc;
359 uint16_t desc_to_clean_to;
360 uint16_t nb_tx_to_clean;
362 desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_rs_thresh);
363 if (desc_to_clean_to >= nb_tx_desc)
364 desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
366 desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
367 if ((txd[desc_to_clean_to].cmd_type_offset_bsz &
368 rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
369 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE)) {
370 PMD_TX_FREE_LOG(DEBUG, "TX descriptor %4u is not done "
371 "(port=%d queue=%d)", desc_to_clean_to,
372 txq->port_id, txq->queue_id);
376 if (last_desc_cleaned > desc_to_clean_to)
377 nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
380 nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
383 txd[desc_to_clean_to].cmd_type_offset_bsz = 0;
385 txq->last_desc_cleaned = desc_to_clean_to;
386 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
392 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
393 check_rx_burst_bulk_alloc_preconditions(struct i40e_rx_queue *rxq)
395 check_rx_burst_bulk_alloc_preconditions(__rte_unused struct i40e_rx_queue *rxq)
400 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
401 if (!(rxq->rx_free_thresh >= RTE_PMD_I40E_RX_MAX_BURST)) {
402 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
403 "rxq->rx_free_thresh=%d, "
404 "RTE_PMD_I40E_RX_MAX_BURST=%d",
405 rxq->rx_free_thresh, RTE_PMD_I40E_RX_MAX_BURST);
407 } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
408 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
409 "rxq->rx_free_thresh=%d, "
410 "rxq->nb_rx_desc=%d",
411 rxq->rx_free_thresh, rxq->nb_rx_desc);
413 } else if (rxq->nb_rx_desc % rxq->rx_free_thresh != 0) {
414 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
415 "rxq->nb_rx_desc=%d, "
416 "rxq->rx_free_thresh=%d",
417 rxq->nb_rx_desc, rxq->rx_free_thresh);
419 } else if (!(rxq->nb_rx_desc < (I40E_MAX_RING_DESC -
420 RTE_PMD_I40E_RX_MAX_BURST))) {
421 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
422 "rxq->nb_rx_desc=%d, "
423 "I40E_MAX_RING_DESC=%d, "
424 "RTE_PMD_I40E_RX_MAX_BURST=%d",
425 rxq->nb_rx_desc, I40E_MAX_RING_DESC,
426 RTE_PMD_I40E_RX_MAX_BURST);
436 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
437 #define I40E_LOOK_AHEAD 8
438 #if (I40E_LOOK_AHEAD != 8)
439 #error "PMD I40E: I40E_LOOK_AHEAD must be 8\n"
442 i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
444 volatile union i40e_rx_desc *rxdp;
445 struct i40e_rx_entry *rxep;
450 int32_t s[I40E_LOOK_AHEAD], nb_dd;
451 int32_t i, j, nb_rx = 0;
454 rxdp = &rxq->rx_ring[rxq->rx_tail];
455 rxep = &rxq->sw_ring[rxq->rx_tail];
457 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
458 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
459 I40E_RXD_QW1_STATUS_SHIFT;
461 /* Make sure there is at least 1 packet to receive */
462 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
466 * Scan LOOK_AHEAD descriptors at a time to determine which
467 * descriptors reference packets that are ready to be received.
469 for (i = 0; i < RTE_PMD_I40E_RX_MAX_BURST; i+=I40E_LOOK_AHEAD,
470 rxdp += I40E_LOOK_AHEAD, rxep += I40E_LOOK_AHEAD) {
471 /* Read desc statuses backwards to avoid race condition */
472 for (j = I40E_LOOK_AHEAD - 1; j >= 0; j--) {
473 qword1 = rte_le_to_cpu_64(\
474 rxdp[j].wb.qword1.status_error_len);
475 s[j] = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
476 I40E_RXD_QW1_STATUS_SHIFT;
481 /* Compute how many status bits were set */
482 for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
483 nb_dd += s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
487 /* Translate descriptor info to mbuf parameters */
488 for (j = 0; j < nb_dd; j++) {
490 qword1 = rte_le_to_cpu_64(\
491 rxdp[j].wb.qword1.status_error_len);
492 pkt_len = ((qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
493 I40E_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
494 mb->data_len = pkt_len;
495 mb->pkt_len = pkt_len;
497 i40e_rxd_to_vlan_tci(mb, &rxdp[j]);
498 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
499 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
501 i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
502 I40E_RXD_QW1_PTYPE_MASK) >>
503 I40E_RXD_QW1_PTYPE_SHIFT));
504 if (pkt_flags & PKT_RX_RSS_HASH)
505 mb->hash.rss = rte_le_to_cpu_32(\
506 rxdp[j].wb.qword0.hi_dword.rss);
507 if (pkt_flags & PKT_RX_FDIR)
508 pkt_flags |= i40e_rxd_build_fdir(&rxdp[j], mb);
510 #ifdef RTE_LIBRTE_IEEE1588
511 pkt_flags |= i40e_get_iee15888_flags(mb, qword1);
513 mb->ol_flags |= pkt_flags;
517 for (j = 0; j < I40E_LOOK_AHEAD; j++)
518 rxq->rx_stage[i + j] = rxep[j].mbuf;
520 if (nb_dd != I40E_LOOK_AHEAD)
524 /* Clear software ring entries */
525 for (i = 0; i < nb_rx; i++)
526 rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
531 static inline uint16_t
532 i40e_rx_fill_from_stage(struct i40e_rx_queue *rxq,
533 struct rte_mbuf **rx_pkts,
537 struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
539 nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
541 for (i = 0; i < nb_pkts; i++)
542 rx_pkts[i] = stage[i];
544 rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
545 rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
551 i40e_rx_alloc_bufs(struct i40e_rx_queue *rxq)
553 volatile union i40e_rx_desc *rxdp;
554 struct i40e_rx_entry *rxep;
556 uint16_t alloc_idx, i;
560 /* Allocate buffers in bulk */
561 alloc_idx = (uint16_t)(rxq->rx_free_trigger -
562 (rxq->rx_free_thresh - 1));
563 rxep = &(rxq->sw_ring[alloc_idx]);
564 diag = rte_mempool_get_bulk(rxq->mp, (void *)rxep,
565 rxq->rx_free_thresh);
566 if (unlikely(diag != 0)) {
567 PMD_DRV_LOG(ERR, "Failed to get mbufs in bulk");
571 rxdp = &rxq->rx_ring[alloc_idx];
572 for (i = 0; i < rxq->rx_free_thresh; i++) {
573 if (likely(i < (rxq->rx_free_thresh - 1)))
574 /* Prefetch next mbuf */
575 rte_prefetch0(rxep[i + 1].mbuf);
578 rte_mbuf_refcnt_set(mb, 1);
580 mb->data_off = RTE_PKTMBUF_HEADROOM;
582 mb->port = rxq->port_id;
583 dma_addr = rte_cpu_to_le_64(\
584 rte_mbuf_data_dma_addr_default(mb));
585 rxdp[i].read.hdr_addr = 0;
586 rxdp[i].read.pkt_addr = dma_addr;
589 /* Update rx tail regsiter */
591 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->rx_free_trigger);
593 rxq->rx_free_trigger =
594 (uint16_t)(rxq->rx_free_trigger + rxq->rx_free_thresh);
595 if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
596 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
601 static inline uint16_t
602 rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
604 struct i40e_rx_queue *rxq = (struct i40e_rx_queue *)rx_queue;
605 struct rte_eth_dev *dev;
611 if (rxq->rx_nb_avail)
612 return i40e_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
614 nb_rx = (uint16_t)i40e_rx_scan_hw_ring(rxq);
615 rxq->rx_next_avail = 0;
616 rxq->rx_nb_avail = nb_rx;
617 rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
619 if (rxq->rx_tail > rxq->rx_free_trigger) {
620 if (i40e_rx_alloc_bufs(rxq) != 0) {
623 dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
624 dev->data->rx_mbuf_alloc_failed +=
627 rxq->rx_nb_avail = 0;
628 rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
629 for (i = 0, j = rxq->rx_tail; i < nb_rx; i++, j++)
630 rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
636 if (rxq->rx_tail >= rxq->nb_rx_desc)
639 if (rxq->rx_nb_avail)
640 return i40e_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
646 i40e_recv_pkts_bulk_alloc(void *rx_queue,
647 struct rte_mbuf **rx_pkts,
650 uint16_t nb_rx = 0, n, count;
652 if (unlikely(nb_pkts == 0))
655 if (likely(nb_pkts <= RTE_PMD_I40E_RX_MAX_BURST))
656 return rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
659 n = RTE_MIN(nb_pkts, RTE_PMD_I40E_RX_MAX_BURST);
660 count = rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
661 nb_rx = (uint16_t)(nb_rx + count);
662 nb_pkts = (uint16_t)(nb_pkts - count);
671 i40e_recv_pkts_bulk_alloc(void __rte_unused *rx_queue,
672 struct rte_mbuf __rte_unused **rx_pkts,
673 uint16_t __rte_unused nb_pkts)
677 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
680 i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
682 struct i40e_rx_queue *rxq;
683 volatile union i40e_rx_desc *rx_ring;
684 volatile union i40e_rx_desc *rxdp;
685 union i40e_rx_desc rxd;
686 struct i40e_rx_entry *sw_ring;
687 struct i40e_rx_entry *rxe;
688 struct rte_eth_dev *dev;
689 struct rte_mbuf *rxm;
690 struct rte_mbuf *nmb;
694 uint16_t rx_packet_len;
695 uint16_t rx_id, nb_hold;
702 rx_id = rxq->rx_tail;
703 rx_ring = rxq->rx_ring;
704 sw_ring = rxq->sw_ring;
706 while (nb_rx < nb_pkts) {
707 rxdp = &rx_ring[rx_id];
708 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
709 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK)
710 >> I40E_RXD_QW1_STATUS_SHIFT;
712 /* Check the DD bit first */
713 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
716 nmb = rte_mbuf_raw_alloc(rxq->mp);
717 if (unlikely(!nmb)) {
718 dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
719 dev->data->rx_mbuf_alloc_failed++;
725 rxe = &sw_ring[rx_id];
727 if (unlikely(rx_id == rxq->nb_rx_desc))
730 /* Prefetch next mbuf */
731 rte_prefetch0(sw_ring[rx_id].mbuf);
734 * When next RX descriptor is on a cache line boundary,
735 * prefetch the next 4 RX descriptors and next 8 pointers
738 if ((rx_id & 0x3) == 0) {
739 rte_prefetch0(&rx_ring[rx_id]);
740 rte_prefetch0(&sw_ring[rx_id]);
745 rte_cpu_to_le_64(rte_mbuf_data_dma_addr_default(nmb));
746 rxdp->read.hdr_addr = 0;
747 rxdp->read.pkt_addr = dma_addr;
749 rx_packet_len = ((qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
750 I40E_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
752 rxm->data_off = RTE_PKTMBUF_HEADROOM;
753 rte_prefetch0(RTE_PTR_ADD(rxm->buf_addr, RTE_PKTMBUF_HEADROOM));
756 rxm->pkt_len = rx_packet_len;
757 rxm->data_len = rx_packet_len;
758 rxm->port = rxq->port_id;
760 i40e_rxd_to_vlan_tci(rxm, &rxd);
761 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
762 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
764 i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
765 I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT));
766 if (pkt_flags & PKT_RX_RSS_HASH)
768 rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
769 if (pkt_flags & PKT_RX_FDIR)
770 pkt_flags |= i40e_rxd_build_fdir(&rxd, rxm);
772 #ifdef RTE_LIBRTE_IEEE1588
773 pkt_flags |= i40e_get_iee15888_flags(rxm, qword1);
775 rxm->ol_flags |= pkt_flags;
777 rx_pkts[nb_rx++] = rxm;
779 rxq->rx_tail = rx_id;
782 * If the number of free RX descriptors is greater than the RX free
783 * threshold of the queue, advance the receive tail register of queue.
784 * Update that register with the value of the last processed RX
785 * descriptor minus 1.
787 nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
788 if (nb_hold > rxq->rx_free_thresh) {
789 rx_id = (uint16_t) ((rx_id == 0) ?
790 (rxq->nb_rx_desc - 1) : (rx_id - 1));
791 I40E_PCI_REG_WRITE(rxq->qrx_tail, rx_id);
794 rxq->nb_rx_hold = nb_hold;
800 i40e_recv_scattered_pkts(void *rx_queue,
801 struct rte_mbuf **rx_pkts,
804 struct i40e_rx_queue *rxq = rx_queue;
805 volatile union i40e_rx_desc *rx_ring = rxq->rx_ring;
806 volatile union i40e_rx_desc *rxdp;
807 union i40e_rx_desc rxd;
808 struct i40e_rx_entry *sw_ring = rxq->sw_ring;
809 struct i40e_rx_entry *rxe;
810 struct rte_mbuf *first_seg = rxq->pkt_first_seg;
811 struct rte_mbuf *last_seg = rxq->pkt_last_seg;
812 struct rte_mbuf *nmb, *rxm;
813 uint16_t rx_id = rxq->rx_tail;
814 uint16_t nb_rx = 0, nb_hold = 0, rx_packet_len;
815 struct rte_eth_dev *dev;
821 while (nb_rx < nb_pkts) {
822 rxdp = &rx_ring[rx_id];
823 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
824 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
825 I40E_RXD_QW1_STATUS_SHIFT;
827 /* Check the DD bit */
828 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
831 nmb = rte_mbuf_raw_alloc(rxq->mp);
832 if (unlikely(!nmb)) {
833 dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
834 dev->data->rx_mbuf_alloc_failed++;
840 rxe = &sw_ring[rx_id];
842 if (rx_id == rxq->nb_rx_desc)
845 /* Prefetch next mbuf */
846 rte_prefetch0(sw_ring[rx_id].mbuf);
849 * When next RX descriptor is on a cache line boundary,
850 * prefetch the next 4 RX descriptors and next 8 pointers
853 if ((rx_id & 0x3) == 0) {
854 rte_prefetch0(&rx_ring[rx_id]);
855 rte_prefetch0(&sw_ring[rx_id]);
861 rte_cpu_to_le_64(rte_mbuf_data_dma_addr_default(nmb));
863 /* Set data buffer address and data length of the mbuf */
864 rxdp->read.hdr_addr = 0;
865 rxdp->read.pkt_addr = dma_addr;
866 rx_packet_len = (qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
867 I40E_RXD_QW1_LENGTH_PBUF_SHIFT;
868 rxm->data_len = rx_packet_len;
869 rxm->data_off = RTE_PKTMBUF_HEADROOM;
872 * If this is the first buffer of the received packet, set the
873 * pointer to the first mbuf of the packet and initialize its
874 * context. Otherwise, update the total length and the number
875 * of segments of the current scattered packet, and update the
876 * pointer to the last mbuf of the current packet.
880 first_seg->nb_segs = 1;
881 first_seg->pkt_len = rx_packet_len;
884 (uint16_t)(first_seg->pkt_len +
886 first_seg->nb_segs++;
887 last_seg->next = rxm;
891 * If this is not the last buffer of the received packet,
892 * update the pointer to the last mbuf of the current scattered
893 * packet and continue to parse the RX ring.
895 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_EOF_SHIFT))) {
901 * This is the last buffer of the received packet. If the CRC
902 * is not stripped by the hardware:
903 * - Subtract the CRC length from the total packet length.
904 * - If the last buffer only contains the whole CRC or a part
905 * of it, free the mbuf associated to the last buffer. If part
906 * of the CRC is also contained in the previous mbuf, subtract
907 * the length of that CRC part from the data length of the
911 if (unlikely(rxq->crc_len > 0)) {
912 first_seg->pkt_len -= ETHER_CRC_LEN;
913 if (rx_packet_len <= ETHER_CRC_LEN) {
914 rte_pktmbuf_free_seg(rxm);
915 first_seg->nb_segs--;
917 (uint16_t)(last_seg->data_len -
918 (ETHER_CRC_LEN - rx_packet_len));
919 last_seg->next = NULL;
921 rxm->data_len = (uint16_t)(rx_packet_len -
925 first_seg->port = rxq->port_id;
926 first_seg->ol_flags = 0;
927 i40e_rxd_to_vlan_tci(first_seg, &rxd);
928 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
929 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
930 first_seg->packet_type =
931 i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
932 I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT));
933 if (pkt_flags & PKT_RX_RSS_HASH)
934 first_seg->hash.rss =
935 rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
936 if (pkt_flags & PKT_RX_FDIR)
937 pkt_flags |= i40e_rxd_build_fdir(&rxd, first_seg);
939 #ifdef RTE_LIBRTE_IEEE1588
940 pkt_flags |= i40e_get_iee15888_flags(first_seg, qword1);
942 first_seg->ol_flags |= pkt_flags;
944 /* Prefetch data of first segment, if configured to do so. */
945 rte_prefetch0(RTE_PTR_ADD(first_seg->buf_addr,
946 first_seg->data_off));
947 rx_pkts[nb_rx++] = first_seg;
951 /* Record index of the next RX descriptor to probe. */
952 rxq->rx_tail = rx_id;
953 rxq->pkt_first_seg = first_seg;
954 rxq->pkt_last_seg = last_seg;
957 * If the number of free RX descriptors is greater than the RX free
958 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
959 * register. Update the RDT with the value of the last processed RX
960 * descriptor minus 1, to guarantee that the RDT register is never
961 * equal to the RDH register, which creates a "full" ring situtation
962 * from the hardware point of view.
964 nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
965 if (nb_hold > rxq->rx_free_thresh) {
966 rx_id = (uint16_t)(rx_id == 0 ?
967 (rxq->nb_rx_desc - 1) : (rx_id - 1));
968 I40E_PCI_REG_WRITE(rxq->qrx_tail, rx_id);
971 rxq->nb_rx_hold = nb_hold;
976 /* Check if the context descriptor is needed for TX offloading */
977 static inline uint16_t
978 i40e_calc_context_desc(uint64_t flags)
980 static uint64_t mask = PKT_TX_OUTER_IP_CKSUM |
985 #ifdef RTE_LIBRTE_IEEE1588
986 mask |= PKT_TX_IEEE1588_TMST;
989 return (flags & mask) ? 1 : 0;
992 /* set i40e TSO context descriptor */
993 static inline uint64_t
994 i40e_set_tso_ctx(struct rte_mbuf *mbuf, union i40e_tx_offload tx_offload)
996 uint64_t ctx_desc = 0;
997 uint32_t cd_cmd, hdr_len, cd_tso_len;
999 if (!tx_offload.l4_len) {
1000 PMD_DRV_LOG(DEBUG, "L4 length set to 0");
1005 * in case of non tunneling packet, the outer_l2_len and
1006 * outer_l3_len must be 0.
1008 hdr_len = tx_offload.outer_l2_len +
1009 tx_offload.outer_l3_len +
1014 cd_cmd = I40E_TX_CTX_DESC_TSO;
1015 cd_tso_len = mbuf->pkt_len - hdr_len;
1016 ctx_desc |= ((uint64_t)cd_cmd << I40E_TXD_CTX_QW1_CMD_SHIFT) |
1017 ((uint64_t)cd_tso_len <<
1018 I40E_TXD_CTX_QW1_TSO_LEN_SHIFT) |
1019 ((uint64_t)mbuf->tso_segsz <<
1020 I40E_TXD_CTX_QW1_MSS_SHIFT);
1026 i40e_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1028 struct i40e_tx_queue *txq;
1029 struct i40e_tx_entry *sw_ring;
1030 struct i40e_tx_entry *txe, *txn;
1031 volatile struct i40e_tx_desc *txd;
1032 volatile struct i40e_tx_desc *txr;
1033 struct rte_mbuf *tx_pkt;
1034 struct rte_mbuf *m_seg;
1035 uint32_t cd_tunneling_params;
1047 uint64_t buf_dma_addr;
1048 union i40e_tx_offload tx_offload = {0};
1051 sw_ring = txq->sw_ring;
1053 tx_id = txq->tx_tail;
1054 txe = &sw_ring[tx_id];
1056 /* Check if the descriptor ring needs to be cleaned. */
1057 if (txq->nb_tx_free < txq->tx_free_thresh)
1058 i40e_xmit_cleanup(txq);
1060 for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
1066 tx_pkt = *tx_pkts++;
1067 RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
1069 ol_flags = tx_pkt->ol_flags;
1070 tx_offload.l2_len = tx_pkt->l2_len;
1071 tx_offload.l3_len = tx_pkt->l3_len;
1072 tx_offload.outer_l2_len = tx_pkt->outer_l2_len;
1073 tx_offload.outer_l3_len = tx_pkt->outer_l3_len;
1074 tx_offload.l4_len = tx_pkt->l4_len;
1075 tx_offload.tso_segsz = tx_pkt->tso_segsz;
1077 /* Calculate the number of context descriptors needed. */
1078 nb_ctx = i40e_calc_context_desc(ol_flags);
1081 * The number of descriptors that must be allocated for
1082 * a packet equals to the number of the segments of that
1083 * packet plus 1 context descriptor if needed.
1085 nb_used = (uint16_t)(tx_pkt->nb_segs + nb_ctx);
1086 tx_last = (uint16_t)(tx_id + nb_used - 1);
1089 if (tx_last >= txq->nb_tx_desc)
1090 tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
1092 if (nb_used > txq->nb_tx_free) {
1093 if (i40e_xmit_cleanup(txq) != 0) {
1098 if (unlikely(nb_used > txq->tx_rs_thresh)) {
1099 while (nb_used > txq->nb_tx_free) {
1100 if (i40e_xmit_cleanup(txq) != 0) {
1109 /* Descriptor based VLAN insertion */
1110 if (ol_flags & (PKT_TX_VLAN_PKT | PKT_TX_QINQ_PKT)) {
1111 tx_flags |= tx_pkt->vlan_tci <<
1112 I40E_TX_FLAG_L2TAG1_SHIFT;
1113 tx_flags |= I40E_TX_FLAG_INSERT_VLAN;
1114 td_cmd |= I40E_TX_DESC_CMD_IL2TAG1;
1115 td_tag = (tx_flags & I40E_TX_FLAG_L2TAG1_MASK) >>
1116 I40E_TX_FLAG_L2TAG1_SHIFT;
1119 /* Always enable CRC offload insertion */
1120 td_cmd |= I40E_TX_DESC_CMD_ICRC;
1122 /* Fill in tunneling parameters if necessary */
1123 cd_tunneling_params = 0;
1124 if (ol_flags & PKT_TX_TUNNEL_MASK)
1125 i40e_parse_tunneling_params(ol_flags, tx_offload,
1126 &cd_tunneling_params);
1127 /* Enable checksum offloading */
1128 if (ol_flags & I40E_TX_CKSUM_OFFLOAD_MASK)
1129 i40e_txd_enable_checksum(ol_flags, &td_cmd,
1130 &td_offset, tx_offload);
1133 /* Setup TX context descriptor if required */
1134 volatile struct i40e_tx_context_desc *ctx_txd =
1135 (volatile struct i40e_tx_context_desc *)\
1137 uint16_t cd_l2tag2 = 0;
1138 uint64_t cd_type_cmd_tso_mss =
1139 I40E_TX_DESC_DTYPE_CONTEXT;
1141 txn = &sw_ring[txe->next_id];
1142 RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1143 if (txe->mbuf != NULL) {
1144 rte_pktmbuf_free_seg(txe->mbuf);
1148 /* TSO enabled means no timestamp */
1149 if (ol_flags & PKT_TX_TCP_SEG)
1150 cd_type_cmd_tso_mss |=
1151 i40e_set_tso_ctx(tx_pkt, tx_offload);
1153 #ifdef RTE_LIBRTE_IEEE1588
1154 if (ol_flags & PKT_TX_IEEE1588_TMST)
1155 cd_type_cmd_tso_mss |=
1156 ((uint64_t)I40E_TX_CTX_DESC_TSYN <<
1157 I40E_TXD_CTX_QW1_CMD_SHIFT);
1161 ctx_txd->tunneling_params =
1162 rte_cpu_to_le_32(cd_tunneling_params);
1163 if (ol_flags & PKT_TX_QINQ_PKT) {
1164 cd_l2tag2 = tx_pkt->vlan_tci_outer;
1165 cd_type_cmd_tso_mss |=
1166 ((uint64_t)I40E_TX_CTX_DESC_IL2TAG2 <<
1167 I40E_TXD_CTX_QW1_CMD_SHIFT);
1169 ctx_txd->l2tag2 = rte_cpu_to_le_16(cd_l2tag2);
1170 ctx_txd->type_cmd_tso_mss =
1171 rte_cpu_to_le_64(cd_type_cmd_tso_mss);
1173 PMD_TX_LOG(DEBUG, "mbuf: %p, TCD[%u]:\n"
1174 "tunneling_params: %#x;\n"
1177 "type_cmd_tso_mss: %#"PRIx64";\n",
1179 ctx_txd->tunneling_params,
1182 ctx_txd->type_cmd_tso_mss);
1184 txe->last_id = tx_last;
1185 tx_id = txe->next_id;
1192 txn = &sw_ring[txe->next_id];
1195 rte_pktmbuf_free_seg(txe->mbuf);
1198 /* Setup TX Descriptor */
1199 slen = m_seg->data_len;
1200 buf_dma_addr = rte_mbuf_data_dma_addr(m_seg);
1202 PMD_TX_LOG(DEBUG, "mbuf: %p, TDD[%u]:\n"
1203 "buf_dma_addr: %#"PRIx64";\n"
1208 tx_pkt, tx_id, buf_dma_addr,
1209 td_cmd, td_offset, slen, td_tag);
1211 txd->buffer_addr = rte_cpu_to_le_64(buf_dma_addr);
1212 txd->cmd_type_offset_bsz = i40e_build_ctob(td_cmd,
1213 td_offset, slen, td_tag);
1214 txe->last_id = tx_last;
1215 tx_id = txe->next_id;
1217 m_seg = m_seg->next;
1218 } while (m_seg != NULL);
1220 /* The last packet data descriptor needs End Of Packet (EOP) */
1221 td_cmd |= I40E_TX_DESC_CMD_EOP;
1222 txq->nb_tx_used = (uint16_t)(txq->nb_tx_used + nb_used);
1223 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
1225 if (txq->nb_tx_used >= txq->tx_rs_thresh) {
1226 PMD_TX_FREE_LOG(DEBUG,
1227 "Setting RS bit on TXD id="
1228 "%4u (port=%d queue=%d)",
1229 tx_last, txq->port_id, txq->queue_id);
1231 td_cmd |= I40E_TX_DESC_CMD_RS;
1233 /* Update txq RS bit counters */
1234 txq->nb_tx_used = 0;
1237 txd->cmd_type_offset_bsz |=
1238 rte_cpu_to_le_64(((uint64_t)td_cmd) <<
1239 I40E_TXD_QW1_CMD_SHIFT);
1245 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
1246 (unsigned) txq->port_id, (unsigned) txq->queue_id,
1247 (unsigned) tx_id, (unsigned) nb_tx);
1249 I40E_PCI_REG_WRITE(txq->qtx_tail, tx_id);
1250 txq->tx_tail = tx_id;
1255 static inline int __attribute__((always_inline))
1256 i40e_tx_free_bufs(struct i40e_tx_queue *txq)
1258 struct i40e_tx_entry *txep;
1261 if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz &
1262 rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
1263 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1266 txep = &(txq->sw_ring[txq->tx_next_dd - (txq->tx_rs_thresh - 1)]);
1268 for (i = 0; i < txq->tx_rs_thresh; i++)
1269 rte_prefetch0((txep + i)->mbuf);
1271 if (txq->txq_flags & (uint32_t)ETH_TXQ_FLAGS_NOREFCOUNT) {
1272 for (i = 0; i < txq->tx_rs_thresh; ++i, ++txep) {
1273 rte_mempool_put(txep->mbuf->pool, txep->mbuf);
1277 for (i = 0; i < txq->tx_rs_thresh; ++i, ++txep) {
1278 rte_pktmbuf_free_seg(txep->mbuf);
1283 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_rs_thresh);
1284 txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_rs_thresh);
1285 if (txq->tx_next_dd >= txq->nb_tx_desc)
1286 txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
1288 return txq->tx_rs_thresh;
1291 /* Populate 4 descriptors with data from 4 mbufs */
1293 tx4(volatile struct i40e_tx_desc *txdp, struct rte_mbuf **pkts)
1298 for (i = 0; i < 4; i++, txdp++, pkts++) {
1299 dma_addr = rte_mbuf_data_dma_addr(*pkts);
1300 txdp->buffer_addr = rte_cpu_to_le_64(dma_addr);
1301 txdp->cmd_type_offset_bsz =
1302 i40e_build_ctob((uint32_t)I40E_TD_CMD, 0,
1303 (*pkts)->data_len, 0);
1307 /* Populate 1 descriptor with data from 1 mbuf */
1309 tx1(volatile struct i40e_tx_desc *txdp, struct rte_mbuf **pkts)
1313 dma_addr = rte_mbuf_data_dma_addr(*pkts);
1314 txdp->buffer_addr = rte_cpu_to_le_64(dma_addr);
1315 txdp->cmd_type_offset_bsz =
1316 i40e_build_ctob((uint32_t)I40E_TD_CMD, 0,
1317 (*pkts)->data_len, 0);
1320 /* Fill hardware descriptor ring with mbuf data */
1322 i40e_tx_fill_hw_ring(struct i40e_tx_queue *txq,
1323 struct rte_mbuf **pkts,
1326 volatile struct i40e_tx_desc *txdp = &(txq->tx_ring[txq->tx_tail]);
1327 struct i40e_tx_entry *txep = &(txq->sw_ring[txq->tx_tail]);
1328 const int N_PER_LOOP = 4;
1329 const int N_PER_LOOP_MASK = N_PER_LOOP - 1;
1330 int mainpart, leftover;
1333 mainpart = (nb_pkts & ((uint32_t) ~N_PER_LOOP_MASK));
1334 leftover = (nb_pkts & ((uint32_t) N_PER_LOOP_MASK));
1335 for (i = 0; i < mainpart; i += N_PER_LOOP) {
1336 for (j = 0; j < N_PER_LOOP; ++j) {
1337 (txep + i + j)->mbuf = *(pkts + i + j);
1339 tx4(txdp + i, pkts + i);
1341 if (unlikely(leftover > 0)) {
1342 for (i = 0; i < leftover; ++i) {
1343 (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
1344 tx1(txdp + mainpart + i, pkts + mainpart + i);
1349 static inline uint16_t
1350 tx_xmit_pkts(struct i40e_tx_queue *txq,
1351 struct rte_mbuf **tx_pkts,
1354 volatile struct i40e_tx_desc *txr = txq->tx_ring;
1358 * Begin scanning the H/W ring for done descriptors when the number
1359 * of available descriptors drops below tx_free_thresh. For each done
1360 * descriptor, free the associated buffer.
1362 if (txq->nb_tx_free < txq->tx_free_thresh)
1363 i40e_tx_free_bufs(txq);
1365 /* Use available descriptor only */
1366 nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
1367 if (unlikely(!nb_pkts))
1370 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
1371 if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
1372 n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
1373 i40e_tx_fill_hw_ring(txq, tx_pkts, n);
1374 txr[txq->tx_next_rs].cmd_type_offset_bsz |=
1375 rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
1376 I40E_TXD_QW1_CMD_SHIFT);
1377 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
1381 /* Fill hardware descriptor ring with mbuf data */
1382 i40e_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
1383 txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
1385 /* Determin if RS bit needs to be set */
1386 if (txq->tx_tail > txq->tx_next_rs) {
1387 txr[txq->tx_next_rs].cmd_type_offset_bsz |=
1388 rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
1389 I40E_TXD_QW1_CMD_SHIFT);
1391 (uint16_t)(txq->tx_next_rs + txq->tx_rs_thresh);
1392 if (txq->tx_next_rs >= txq->nb_tx_desc)
1393 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
1396 if (txq->tx_tail >= txq->nb_tx_desc)
1399 /* Update the tx tail register */
1401 I40E_PCI_REG_WRITE(txq->qtx_tail, txq->tx_tail);
1407 i40e_xmit_pkts_simple(void *tx_queue,
1408 struct rte_mbuf **tx_pkts,
1413 if (likely(nb_pkts <= I40E_TX_MAX_BURST))
1414 return tx_xmit_pkts((struct i40e_tx_queue *)tx_queue,
1418 uint16_t ret, num = (uint16_t)RTE_MIN(nb_pkts,
1421 ret = tx_xmit_pkts((struct i40e_tx_queue *)tx_queue,
1422 &tx_pkts[nb_tx], num);
1423 nb_tx = (uint16_t)(nb_tx + ret);
1424 nb_pkts = (uint16_t)(nb_pkts - ret);
1433 * Find the VSI the queue belongs to. 'queue_idx' is the queue index
1434 * application used, which assume having sequential ones. But from driver's
1435 * perspective, it's different. For example, q0 belongs to FDIR VSI, q1-q64
1436 * to MAIN VSI, , q65-96 to SRIOV VSIs, q97-128 to VMDQ VSIs. For application
1437 * running on host, q1-64 and q97-128 can be used, total 96 queues. They can
1438 * use queue_idx from 0 to 95 to access queues, while real queue would be
1439 * different. This function will do a queue mapping to find VSI the queue
1442 static struct i40e_vsi*
1443 i40e_pf_get_vsi_by_qindex(struct i40e_pf *pf, uint16_t queue_idx)
1445 /* the queue in MAIN VSI range */
1446 if (queue_idx < pf->main_vsi->nb_qps)
1447 return pf->main_vsi;
1449 queue_idx -= pf->main_vsi->nb_qps;
1451 /* queue_idx is greater than VMDQ VSIs range */
1452 if (queue_idx > pf->nb_cfg_vmdq_vsi * pf->vmdq_nb_qps - 1) {
1453 PMD_INIT_LOG(ERR, "queue_idx out of range. VMDQ configured?");
1457 return pf->vmdq[queue_idx / pf->vmdq_nb_qps].vsi;
1461 i40e_get_queue_offset_by_qindex(struct i40e_pf *pf, uint16_t queue_idx)
1463 /* the queue in MAIN VSI range */
1464 if (queue_idx < pf->main_vsi->nb_qps)
1467 /* It's VMDQ queues */
1468 queue_idx -= pf->main_vsi->nb_qps;
1470 if (pf->nb_cfg_vmdq_vsi)
1471 return queue_idx % pf->vmdq_nb_qps;
1473 PMD_INIT_LOG(ERR, "Fail to get queue offset");
1474 return (uint16_t)(-1);
1479 i40e_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1481 struct i40e_rx_queue *rxq;
1483 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1485 PMD_INIT_FUNC_TRACE();
1487 if (rx_queue_id < dev->data->nb_rx_queues) {
1488 rxq = dev->data->rx_queues[rx_queue_id];
1490 err = i40e_alloc_rx_queue_mbufs(rxq);
1492 PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
1498 /* Init the RX tail regieter. */
1499 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
1501 err = i40e_switch_rx_queue(hw, rxq->reg_idx, TRUE);
1504 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
1507 i40e_rx_queue_release_mbufs(rxq);
1508 i40e_reset_rx_queue(rxq);
1510 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1517 i40e_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1519 struct i40e_rx_queue *rxq;
1521 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1523 if (rx_queue_id < dev->data->nb_rx_queues) {
1524 rxq = dev->data->rx_queues[rx_queue_id];
1527 * rx_queue_id is queue id aplication refers to, while
1528 * rxq->reg_idx is the real queue index.
1530 err = i40e_switch_rx_queue(hw, rxq->reg_idx, FALSE);
1533 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
1537 i40e_rx_queue_release_mbufs(rxq);
1538 i40e_reset_rx_queue(rxq);
1539 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1546 i40e_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1549 struct i40e_tx_queue *txq;
1550 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1552 PMD_INIT_FUNC_TRACE();
1554 if (tx_queue_id < dev->data->nb_tx_queues) {
1555 txq = dev->data->tx_queues[tx_queue_id];
1558 * tx_queue_id is queue id aplication refers to, while
1559 * rxq->reg_idx is the real queue index.
1561 err = i40e_switch_tx_queue(hw, txq->reg_idx, TRUE);
1563 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
1566 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1573 i40e_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1575 struct i40e_tx_queue *txq;
1577 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1579 if (tx_queue_id < dev->data->nb_tx_queues) {
1580 txq = dev->data->tx_queues[tx_queue_id];
1583 * tx_queue_id is queue id aplication refers to, while
1584 * txq->reg_idx is the real queue index.
1586 err = i40e_switch_tx_queue(hw, txq->reg_idx, FALSE);
1589 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u of",
1594 i40e_tx_queue_release_mbufs(txq);
1595 i40e_reset_tx_queue(txq);
1596 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1603 i40e_dev_supported_ptypes_get(struct rte_eth_dev *dev)
1605 static const uint32_t ptypes[] = {
1606 /* refers to i40e_rxd_pkt_type_mapping() */
1608 RTE_PTYPE_L2_ETHER_TIMESYNC,
1609 RTE_PTYPE_L2_ETHER_LLDP,
1610 RTE_PTYPE_L2_ETHER_ARP,
1611 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1612 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
1615 RTE_PTYPE_L4_NONFRAG,
1619 RTE_PTYPE_TUNNEL_GRENAT,
1620 RTE_PTYPE_TUNNEL_IP,
1621 RTE_PTYPE_INNER_L2_ETHER,
1622 RTE_PTYPE_INNER_L2_ETHER_VLAN,
1623 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
1624 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
1625 RTE_PTYPE_INNER_L4_FRAG,
1626 RTE_PTYPE_INNER_L4_ICMP,
1627 RTE_PTYPE_INNER_L4_NONFRAG,
1628 RTE_PTYPE_INNER_L4_SCTP,
1629 RTE_PTYPE_INNER_L4_TCP,
1630 RTE_PTYPE_INNER_L4_UDP,
1634 if (dev->rx_pkt_burst == i40e_recv_pkts ||
1635 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1636 dev->rx_pkt_burst == i40e_recv_pkts_bulk_alloc ||
1638 dev->rx_pkt_burst == i40e_recv_scattered_pkts ||
1639 dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec ||
1640 dev->rx_pkt_burst == i40e_recv_pkts_vec)
1646 i40e_dev_rx_queue_setup(struct rte_eth_dev *dev,
1649 unsigned int socket_id,
1650 const struct rte_eth_rxconf *rx_conf,
1651 struct rte_mempool *mp)
1653 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1654 struct i40e_adapter *ad =
1655 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1656 struct i40e_vsi *vsi;
1657 struct i40e_pf *pf = NULL;
1658 struct i40e_vf *vf = NULL;
1659 struct i40e_rx_queue *rxq;
1660 const struct rte_memzone *rz;
1663 uint16_t reg_idx, base, bsf, tc_mapping;
1664 int q_offset, use_def_burst_func = 1;
1666 if (hw->mac.type == I40E_MAC_VF || hw->mac.type == I40E_MAC_X722_VF) {
1667 vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1671 reg_idx = queue_idx;
1673 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1674 vsi = i40e_pf_get_vsi_by_qindex(pf, queue_idx);
1677 q_offset = i40e_get_queue_offset_by_qindex(pf, queue_idx);
1680 reg_idx = vsi->base_queue + q_offset;
1683 if (nb_desc % I40E_ALIGN_RING_DESC != 0 ||
1684 (nb_desc > I40E_MAX_RING_DESC) ||
1685 (nb_desc < I40E_MIN_RING_DESC)) {
1686 PMD_DRV_LOG(ERR, "Number (%u) of receive descriptors is "
1687 "invalid", nb_desc);
1691 /* Free memory if needed */
1692 if (dev->data->rx_queues[queue_idx]) {
1693 i40e_dev_rx_queue_release(dev->data->rx_queues[queue_idx]);
1694 dev->data->rx_queues[queue_idx] = NULL;
1697 /* Allocate the rx queue data structure */
1698 rxq = rte_zmalloc_socket("i40e rx queue",
1699 sizeof(struct i40e_rx_queue),
1700 RTE_CACHE_LINE_SIZE,
1703 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
1704 "rx queue data structure");
1708 rxq->nb_rx_desc = nb_desc;
1709 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1710 rxq->queue_id = queue_idx;
1711 rxq->reg_idx = reg_idx;
1712 rxq->port_id = dev->data->port_id;
1713 rxq->crc_len = (uint8_t) ((dev->data->dev_conf.rxmode.hw_strip_crc) ?
1715 rxq->drop_en = rx_conf->rx_drop_en;
1717 rxq->rx_deferred_start = rx_conf->rx_deferred_start;
1719 /* Allocate the maximun number of RX ring hardware descriptor. */
1720 ring_size = sizeof(union i40e_rx_desc) * I40E_MAX_RING_DESC;
1721 ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
1722 rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
1723 ring_size, I40E_RING_BASE_ALIGN, socket_id);
1725 i40e_dev_rx_queue_release(rxq);
1726 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX");
1730 /* Zero all the descriptors in the ring. */
1731 memset(rz->addr, 0, ring_size);
1733 rxq->rx_ring_phys_addr = rte_mem_phy2mch(rz->memseg_id, rz->phys_addr);
1734 rxq->rx_ring = (union i40e_rx_desc *)rz->addr;
1736 len = (uint16_t)(nb_desc + RTE_PMD_I40E_RX_MAX_BURST);
1738 /* Allocate the software ring. */
1740 rte_zmalloc_socket("i40e rx sw ring",
1741 sizeof(struct i40e_rx_entry) * len,
1742 RTE_CACHE_LINE_SIZE,
1744 if (!rxq->sw_ring) {
1745 i40e_dev_rx_queue_release(rxq);
1746 PMD_DRV_LOG(ERR, "Failed to allocate memory for SW ring");
1750 i40e_reset_rx_queue(rxq);
1752 dev->data->rx_queues[queue_idx] = rxq;
1754 use_def_burst_func = check_rx_burst_bulk_alloc_preconditions(rxq);
1756 if (!use_def_burst_func) {
1757 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1758 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
1759 "satisfied. Rx Burst Bulk Alloc function will be "
1760 "used on port=%d, queue=%d.",
1761 rxq->port_id, rxq->queue_id);
1762 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
1764 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
1765 "not satisfied, Scattered Rx is requested, "
1766 "or RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC is "
1767 "not enabled on port=%d, queue=%d.",
1768 rxq->port_id, rxq->queue_id);
1769 ad->rx_bulk_alloc_allowed = false;
1772 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1773 if (!(vsi->enabled_tc & (1 << i)))
1775 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
1776 base = (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
1777 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
1778 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
1779 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
1781 if (queue_idx >= base && queue_idx < (base + BIT(bsf)))
1789 i40e_dev_rx_queue_release(void *rxq)
1791 struct i40e_rx_queue *q = (struct i40e_rx_queue *)rxq;
1794 PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
1798 i40e_rx_queue_release_mbufs(q);
1799 rte_free(q->sw_ring);
1804 i40e_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1806 #define I40E_RXQ_SCAN_INTERVAL 4
1807 volatile union i40e_rx_desc *rxdp;
1808 struct i40e_rx_queue *rxq;
1811 if (unlikely(rx_queue_id >= dev->data->nb_rx_queues)) {
1812 PMD_DRV_LOG(ERR, "Invalid RX queue id %u", rx_queue_id);
1816 rxq = dev->data->rx_queues[rx_queue_id];
1817 rxdp = &(rxq->rx_ring[rxq->rx_tail]);
1818 while ((desc < rxq->nb_rx_desc) &&
1819 ((rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
1820 I40E_RXD_QW1_STATUS_MASK) >> I40E_RXD_QW1_STATUS_SHIFT) &
1821 (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
1823 * Check the DD bit of a rx descriptor of each 4 in a group,
1824 * to avoid checking too frequently and downgrading performance
1827 desc += I40E_RXQ_SCAN_INTERVAL;
1828 rxdp += I40E_RXQ_SCAN_INTERVAL;
1829 if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
1830 rxdp = &(rxq->rx_ring[rxq->rx_tail +
1831 desc - rxq->nb_rx_desc]);
1838 i40e_dev_rx_descriptor_done(void *rx_queue, uint16_t offset)
1840 volatile union i40e_rx_desc *rxdp;
1841 struct i40e_rx_queue *rxq = rx_queue;
1845 if (unlikely(offset >= rxq->nb_rx_desc)) {
1846 PMD_DRV_LOG(ERR, "Invalid RX queue id %u", offset);
1850 desc = rxq->rx_tail + offset;
1851 if (desc >= rxq->nb_rx_desc)
1852 desc -= rxq->nb_rx_desc;
1854 rxdp = &(rxq->rx_ring[desc]);
1856 ret = !!(((rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
1857 I40E_RXD_QW1_STATUS_MASK) >> I40E_RXD_QW1_STATUS_SHIFT) &
1858 (1 << I40E_RX_DESC_STATUS_DD_SHIFT));
1864 i40e_dev_tx_queue_setup(struct rte_eth_dev *dev,
1867 unsigned int socket_id,
1868 const struct rte_eth_txconf *tx_conf)
1870 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1871 struct i40e_vsi *vsi;
1872 struct i40e_pf *pf = NULL;
1873 struct i40e_vf *vf = NULL;
1874 struct i40e_tx_queue *txq;
1875 const struct rte_memzone *tz;
1877 uint16_t tx_rs_thresh, tx_free_thresh;
1878 uint16_t reg_idx, i, base, bsf, tc_mapping;
1881 if (hw->mac.type == I40E_MAC_VF || hw->mac.type == I40E_MAC_X722_VF) {
1882 vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1886 reg_idx = queue_idx;
1888 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1889 vsi = i40e_pf_get_vsi_by_qindex(pf, queue_idx);
1892 q_offset = i40e_get_queue_offset_by_qindex(pf, queue_idx);
1895 reg_idx = vsi->base_queue + q_offset;
1898 if (nb_desc % I40E_ALIGN_RING_DESC != 0 ||
1899 (nb_desc > I40E_MAX_RING_DESC) ||
1900 (nb_desc < I40E_MIN_RING_DESC)) {
1901 PMD_DRV_LOG(ERR, "Number (%u) of transmit descriptors is "
1902 "invalid", nb_desc);
1907 * The following two parameters control the setting of the RS bit on
1908 * transmit descriptors. TX descriptors will have their RS bit set
1909 * after txq->tx_rs_thresh descriptors have been used. The TX
1910 * descriptor ring will be cleaned after txq->tx_free_thresh
1911 * descriptors are used or if the number of descriptors required to
1912 * transmit a packet is greater than the number of free TX descriptors.
1914 * The following constraints must be satisfied:
1915 * - tx_rs_thresh must be greater than 0.
1916 * - tx_rs_thresh must be less than the size of the ring minus 2.
1917 * - tx_rs_thresh must be less than or equal to tx_free_thresh.
1918 * - tx_rs_thresh must be a divisor of the ring size.
1919 * - tx_free_thresh must be greater than 0.
1920 * - tx_free_thresh must be less than the size of the ring minus 3.
1922 * One descriptor in the TX ring is used as a sentinel to avoid a H/W
1923 * race condition, hence the maximum threshold constraints. When set
1924 * to zero use default values.
1926 tx_rs_thresh = (uint16_t)((tx_conf->tx_rs_thresh) ?
1927 tx_conf->tx_rs_thresh : DEFAULT_TX_RS_THRESH);
1928 tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
1929 tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
1930 if (tx_rs_thresh >= (nb_desc - 2)) {
1931 PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than the "
1932 "number of TX descriptors minus 2. "
1933 "(tx_rs_thresh=%u port=%d queue=%d)",
1934 (unsigned int)tx_rs_thresh,
1935 (int)dev->data->port_id,
1937 return I40E_ERR_PARAM;
1939 if (tx_free_thresh >= (nb_desc - 3)) {
1940 PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the "
1941 "number of TX descriptors minus 3. "
1942 "(tx_free_thresh=%u port=%d queue=%d)",
1943 (unsigned int)tx_free_thresh,
1944 (int)dev->data->port_id,
1946 return I40E_ERR_PARAM;
1948 if (tx_rs_thresh > tx_free_thresh) {
1949 PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than or "
1950 "equal to tx_free_thresh. (tx_free_thresh=%u"
1951 " tx_rs_thresh=%u port=%d queue=%d)",
1952 (unsigned int)tx_free_thresh,
1953 (unsigned int)tx_rs_thresh,
1954 (int)dev->data->port_id,
1956 return I40E_ERR_PARAM;
1958 if ((nb_desc % tx_rs_thresh) != 0) {
1959 PMD_INIT_LOG(ERR, "tx_rs_thresh must be a divisor of the "
1960 "number of TX descriptors. (tx_rs_thresh=%u"
1961 " port=%d queue=%d)",
1962 (unsigned int)tx_rs_thresh,
1963 (int)dev->data->port_id,
1965 return I40E_ERR_PARAM;
1967 if ((tx_rs_thresh > 1) && (tx_conf->tx_thresh.wthresh != 0)) {
1968 PMD_INIT_LOG(ERR, "TX WTHRESH must be set to 0 if "
1969 "tx_rs_thresh is greater than 1. "
1970 "(tx_rs_thresh=%u port=%d queue=%d)",
1971 (unsigned int)tx_rs_thresh,
1972 (int)dev->data->port_id,
1974 return I40E_ERR_PARAM;
1977 /* Free memory if needed. */
1978 if (dev->data->tx_queues[queue_idx]) {
1979 i40e_dev_tx_queue_release(dev->data->tx_queues[queue_idx]);
1980 dev->data->tx_queues[queue_idx] = NULL;
1983 /* Allocate the TX queue data structure. */
1984 txq = rte_zmalloc_socket("i40e tx queue",
1985 sizeof(struct i40e_tx_queue),
1986 RTE_CACHE_LINE_SIZE,
1989 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
1990 "tx queue structure");
1994 /* Allocate TX hardware ring descriptors. */
1995 ring_size = sizeof(struct i40e_tx_desc) * I40E_MAX_RING_DESC;
1996 ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
1997 tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
1998 ring_size, I40E_RING_BASE_ALIGN, socket_id);
2000 i40e_dev_tx_queue_release(txq);
2001 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX");
2005 txq->nb_tx_desc = nb_desc;
2006 txq->tx_rs_thresh = tx_rs_thresh;
2007 txq->tx_free_thresh = tx_free_thresh;
2008 txq->pthresh = tx_conf->tx_thresh.pthresh;
2009 txq->hthresh = tx_conf->tx_thresh.hthresh;
2010 txq->wthresh = tx_conf->tx_thresh.wthresh;
2011 txq->queue_id = queue_idx;
2012 txq->reg_idx = reg_idx;
2013 txq->port_id = dev->data->port_id;
2014 txq->txq_flags = tx_conf->txq_flags;
2016 txq->tx_deferred_start = tx_conf->tx_deferred_start;
2018 txq->tx_ring_phys_addr = rte_mem_phy2mch(tz->memseg_id, tz->phys_addr);
2019 txq->tx_ring = (struct i40e_tx_desc *)tz->addr;
2021 /* Allocate software ring */
2023 rte_zmalloc_socket("i40e tx sw ring",
2024 sizeof(struct i40e_tx_entry) * nb_desc,
2025 RTE_CACHE_LINE_SIZE,
2027 if (!txq->sw_ring) {
2028 i40e_dev_tx_queue_release(txq);
2029 PMD_DRV_LOG(ERR, "Failed to allocate memory for SW TX ring");
2033 i40e_reset_tx_queue(txq);
2035 dev->data->tx_queues[queue_idx] = txq;
2037 /* Use a simple TX queue without offloads or multi segs if possible */
2038 i40e_set_tx_function_flag(dev, txq);
2040 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
2041 if (!(vsi->enabled_tc & (1 << i)))
2043 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
2044 base = (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
2045 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
2046 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
2047 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
2049 if (queue_idx >= base && queue_idx < (base + BIT(bsf)))
2057 i40e_dev_tx_queue_release(void *txq)
2059 struct i40e_tx_queue *q = (struct i40e_tx_queue *)txq;
2062 PMD_DRV_LOG(DEBUG, "Pointer to TX queue is NULL");
2066 i40e_tx_queue_release_mbufs(q);
2067 rte_free(q->sw_ring);
2071 const struct rte_memzone *
2072 i40e_memzone_reserve(const char *name, uint32_t len, int socket_id)
2074 const struct rte_memzone *mz;
2076 mz = rte_memzone_lookup(name);
2080 if (rte_xen_dom0_supported())
2081 mz = rte_memzone_reserve_bounded(name, len,
2082 socket_id, 0, I40E_RING_BASE_ALIGN, RTE_PGSIZE_2M);
2084 mz = rte_memzone_reserve_aligned(name, len,
2085 socket_id, 0, I40E_RING_BASE_ALIGN);
2090 i40e_rx_queue_release_mbufs(struct i40e_rx_queue *rxq)
2094 /* SSE Vector driver has a different way of releasing mbufs. */
2095 if (rxq->rx_using_sse) {
2096 i40e_rx_queue_release_mbufs_vec(rxq);
2100 if (!rxq->sw_ring) {
2101 PMD_DRV_LOG(DEBUG, "Pointer to sw_ring is NULL");
2105 for (i = 0; i < rxq->nb_rx_desc; i++) {
2106 if (rxq->sw_ring[i].mbuf) {
2107 rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
2108 rxq->sw_ring[i].mbuf = NULL;
2111 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2112 if (rxq->rx_nb_avail == 0)
2114 for (i = 0; i < rxq->rx_nb_avail; i++) {
2115 struct rte_mbuf *mbuf;
2117 mbuf = rxq->rx_stage[rxq->rx_next_avail + i];
2118 rte_pktmbuf_free_seg(mbuf);
2120 rxq->rx_nb_avail = 0;
2121 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2125 i40e_reset_rx_queue(struct i40e_rx_queue *rxq)
2131 PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
2135 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2136 if (check_rx_burst_bulk_alloc_preconditions(rxq) == 0)
2137 len = (uint16_t)(rxq->nb_rx_desc + RTE_PMD_I40E_RX_MAX_BURST);
2139 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2140 len = rxq->nb_rx_desc;
2142 for (i = 0; i < len * sizeof(union i40e_rx_desc); i++)
2143 ((volatile char *)rxq->rx_ring)[i] = 0;
2145 memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
2146 for (i = 0; i < RTE_PMD_I40E_RX_MAX_BURST; ++i)
2147 rxq->sw_ring[rxq->nb_rx_desc + i].mbuf = &rxq->fake_mbuf;
2149 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2150 rxq->rx_nb_avail = 0;
2151 rxq->rx_next_avail = 0;
2152 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2153 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2155 rxq->nb_rx_hold = 0;
2156 rxq->pkt_first_seg = NULL;
2157 rxq->pkt_last_seg = NULL;
2159 rxq->rxrearm_start = 0;
2160 rxq->rxrearm_nb = 0;
2164 i40e_tx_queue_release_mbufs(struct i40e_tx_queue *txq)
2166 struct rte_eth_dev *dev;
2169 dev = &rte_eth_devices[txq->port_id];
2171 if (!txq || !txq->sw_ring) {
2172 PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL");
2177 * vPMD tx will not set sw_ring's mbuf to NULL after free,
2178 * so need to free remains more carefully.
2180 if (dev->tx_pkt_burst == i40e_xmit_pkts_vec) {
2181 i = txq->tx_next_dd - txq->tx_rs_thresh + 1;
2182 if (txq->tx_tail < i) {
2183 for (; i < txq->nb_tx_desc; i++) {
2184 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2185 txq->sw_ring[i].mbuf = NULL;
2189 for (; i < txq->tx_tail; i++) {
2190 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2191 txq->sw_ring[i].mbuf = NULL;
2194 for (i = 0; i < txq->nb_tx_desc; i++) {
2195 if (txq->sw_ring[i].mbuf) {
2196 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
2197 txq->sw_ring[i].mbuf = NULL;
2204 i40e_reset_tx_queue(struct i40e_tx_queue *txq)
2206 struct i40e_tx_entry *txe;
2207 uint16_t i, prev, size;
2210 PMD_DRV_LOG(DEBUG, "Pointer to txq is NULL");
2215 size = sizeof(struct i40e_tx_desc) * txq->nb_tx_desc;
2216 for (i = 0; i < size; i++)
2217 ((volatile char *)txq->tx_ring)[i] = 0;
2219 prev = (uint16_t)(txq->nb_tx_desc - 1);
2220 for (i = 0; i < txq->nb_tx_desc; i++) {
2221 volatile struct i40e_tx_desc *txd = &txq->tx_ring[i];
2223 txd->cmd_type_offset_bsz =
2224 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE);
2227 txe[prev].next_id = i;
2231 txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
2232 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
2235 txq->nb_tx_used = 0;
2237 txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
2238 txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
2241 /* Init the TX queue in hardware */
2243 i40e_tx_queue_init(struct i40e_tx_queue *txq)
2245 enum i40e_status_code err = I40E_SUCCESS;
2246 struct i40e_vsi *vsi = txq->vsi;
2247 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2248 uint16_t pf_q = txq->reg_idx;
2249 struct i40e_hmc_obj_txq tx_ctx;
2252 /* clear the context structure first */
2253 memset(&tx_ctx, 0, sizeof(tx_ctx));
2254 tx_ctx.new_context = 1;
2255 tx_ctx.base = txq->tx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
2256 tx_ctx.qlen = txq->nb_tx_desc;
2258 #ifdef RTE_LIBRTE_IEEE1588
2259 tx_ctx.timesync_ena = 1;
2261 tx_ctx.rdylist = rte_le_to_cpu_16(vsi->info.qs_handle[txq->dcb_tc]);
2262 if (vsi->type == I40E_VSI_FDIR)
2263 tx_ctx.fd_ena = TRUE;
2265 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2266 if (err != I40E_SUCCESS) {
2267 PMD_DRV_LOG(ERR, "Failure of clean lan tx queue context");
2271 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2272 if (err != I40E_SUCCESS) {
2273 PMD_DRV_LOG(ERR, "Failure of set lan tx queue context");
2277 /* Now associate this queue with this PCI function */
2278 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
2279 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2280 I40E_QTX_CTL_PF_INDX_MASK);
2281 I40E_WRITE_REG(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2282 I40E_WRITE_FLUSH(hw);
2284 txq->qtx_tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2290 i40e_alloc_rx_queue_mbufs(struct i40e_rx_queue *rxq)
2292 struct i40e_rx_entry *rxe = rxq->sw_ring;
2296 for (i = 0; i < rxq->nb_rx_desc; i++) {
2297 volatile union i40e_rx_desc *rxd;
2298 struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mp);
2300 if (unlikely(!mbuf)) {
2301 PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX");
2305 rte_mbuf_refcnt_set(mbuf, 1);
2307 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
2309 mbuf->port = rxq->port_id;
2312 rte_cpu_to_le_64(rte_mbuf_data_dma_addr_default(mbuf));
2314 rxd = &rxq->rx_ring[i];
2315 rxd->read.pkt_addr = dma_addr;
2316 rxd->read.hdr_addr = 0;
2317 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2318 rxd->read.rsvd1 = 0;
2319 rxd->read.rsvd2 = 0;
2320 #endif /* RTE_LIBRTE_I40E_16BYTE_RX_DESC */
2329 * Calculate the buffer length, and check the jumbo frame
2330 * and maximum packet length.
2333 i40e_rx_queue_config(struct i40e_rx_queue *rxq)
2335 struct i40e_pf *pf = I40E_VSI_TO_PF(rxq->vsi);
2336 struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
2337 struct rte_eth_dev_data *data = pf->dev_data;
2338 uint16_t buf_size, len;
2340 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
2341 RTE_PKTMBUF_HEADROOM);
2343 switch (pf->flags & (I40E_FLAG_HEADER_SPLIT_DISABLED |
2344 I40E_FLAG_HEADER_SPLIT_ENABLED)) {
2345 case I40E_FLAG_HEADER_SPLIT_ENABLED: /* Not supported */
2346 rxq->rx_hdr_len = RTE_ALIGN(I40E_RXBUF_SZ_1024,
2347 (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
2348 rxq->rx_buf_len = RTE_ALIGN(I40E_RXBUF_SZ_2048,
2349 (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
2350 rxq->hs_mode = i40e_header_split_enabled;
2352 case I40E_FLAG_HEADER_SPLIT_DISABLED:
2354 rxq->rx_hdr_len = 0;
2355 rxq->rx_buf_len = RTE_ALIGN_FLOOR(buf_size,
2356 (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
2357 rxq->hs_mode = i40e_header_split_none;
2361 len = hw->func_caps.rx_buf_chain_len * rxq->rx_buf_len;
2362 rxq->max_pkt_len = RTE_MIN(len, data->dev_conf.rxmode.max_rx_pkt_len);
2363 if (data->dev_conf.rxmode.jumbo_frame == 1) {
2364 if (rxq->max_pkt_len <= ETHER_MAX_LEN ||
2365 rxq->max_pkt_len > I40E_FRAME_SIZE_MAX) {
2366 PMD_DRV_LOG(ERR, "maximum packet length must "
2367 "be larger than %u and smaller than %u,"
2368 "as jumbo frame is enabled",
2369 (uint32_t)ETHER_MAX_LEN,
2370 (uint32_t)I40E_FRAME_SIZE_MAX);
2371 return I40E_ERR_CONFIG;
2374 if (rxq->max_pkt_len < ETHER_MIN_LEN ||
2375 rxq->max_pkt_len > ETHER_MAX_LEN) {
2376 PMD_DRV_LOG(ERR, "maximum packet length must be "
2377 "larger than %u and smaller than %u, "
2378 "as jumbo frame is disabled",
2379 (uint32_t)ETHER_MIN_LEN,
2380 (uint32_t)ETHER_MAX_LEN);
2381 return I40E_ERR_CONFIG;
2388 /* Init the RX queue in hardware */
2390 i40e_rx_queue_init(struct i40e_rx_queue *rxq)
2392 int err = I40E_SUCCESS;
2393 struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
2394 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(rxq->vsi);
2395 uint16_t pf_q = rxq->reg_idx;
2397 struct i40e_hmc_obj_rxq rx_ctx;
2399 err = i40e_rx_queue_config(rxq);
2401 PMD_DRV_LOG(ERR, "Failed to config RX queue");
2405 /* Clear the context structure first */
2406 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
2407 rx_ctx.dbuff = rxq->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
2408 rx_ctx.hbuff = rxq->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
2410 rx_ctx.base = rxq->rx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
2411 rx_ctx.qlen = rxq->nb_rx_desc;
2412 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2415 rx_ctx.dtype = rxq->hs_mode;
2417 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_ALL;
2419 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
2420 rx_ctx.rxmax = rxq->max_pkt_len;
2421 rx_ctx.tphrdesc_ena = 1;
2422 rx_ctx.tphwdesc_ena = 1;
2423 rx_ctx.tphdata_ena = 1;
2424 rx_ctx.tphhead_ena = 1;
2425 rx_ctx.lrxqthresh = 2;
2426 rx_ctx.crcstrip = (rxq->crc_len == 0) ? 1 : 0;
2428 /* showiv indicates if inner VLAN is stripped inside of tunnel
2429 * packet. When set it to 1, vlan information is stripped from
2430 * the inner header, but the hardware does not put it in the
2431 * descriptor. So set it zero by default.
2436 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
2437 if (err != I40E_SUCCESS) {
2438 PMD_DRV_LOG(ERR, "Failed to clear LAN RX queue context");
2441 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
2442 if (err != I40E_SUCCESS) {
2443 PMD_DRV_LOG(ERR, "Failed to set LAN RX queue context");
2447 rxq->qrx_tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
2449 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
2450 RTE_PKTMBUF_HEADROOM);
2452 /* Check if scattered RX needs to be used. */
2453 if ((rxq->max_pkt_len + 2 * I40E_VLAN_TAG_SIZE) > buf_size) {
2454 dev_data->scattered_rx = 1;
2457 /* Init the RX tail regieter. */
2458 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
2464 i40e_dev_clear_queues(struct rte_eth_dev *dev)
2468 PMD_INIT_FUNC_TRACE();
2470 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2471 if (!dev->data->tx_queues[i])
2473 i40e_tx_queue_release_mbufs(dev->data->tx_queues[i]);
2474 i40e_reset_tx_queue(dev->data->tx_queues[i]);
2477 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2478 if (!dev->data->rx_queues[i])
2480 i40e_rx_queue_release_mbufs(dev->data->rx_queues[i]);
2481 i40e_reset_rx_queue(dev->data->rx_queues[i]);
2486 i40e_dev_free_queues(struct rte_eth_dev *dev)
2490 PMD_INIT_FUNC_TRACE();
2492 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2493 if (!dev->data->rx_queues[i])
2495 i40e_dev_rx_queue_release(dev->data->rx_queues[i]);
2496 dev->data->rx_queues[i] = NULL;
2498 dev->data->nb_rx_queues = 0;
2500 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2501 if (!dev->data->tx_queues[i])
2503 i40e_dev_tx_queue_release(dev->data->tx_queues[i]);
2504 dev->data->tx_queues[i] = NULL;
2506 dev->data->nb_tx_queues = 0;
2509 #define I40E_FDIR_NUM_TX_DESC I40E_MIN_RING_DESC
2510 #define I40E_FDIR_NUM_RX_DESC I40E_MIN_RING_DESC
2512 enum i40e_status_code
2513 i40e_fdir_setup_tx_resources(struct i40e_pf *pf)
2515 struct i40e_tx_queue *txq;
2516 const struct rte_memzone *tz = NULL;
2518 struct rte_eth_dev *dev;
2521 PMD_DRV_LOG(ERR, "PF is not available");
2522 return I40E_ERR_BAD_PTR;
2525 dev = pf->adapter->eth_dev;
2527 /* Allocate the TX queue data structure. */
2528 txq = rte_zmalloc_socket("i40e fdir tx queue",
2529 sizeof(struct i40e_tx_queue),
2530 RTE_CACHE_LINE_SIZE,
2533 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
2534 "tx queue structure.");
2535 return I40E_ERR_NO_MEMORY;
2538 /* Allocate TX hardware ring descriptors. */
2539 ring_size = sizeof(struct i40e_tx_desc) * I40E_FDIR_NUM_TX_DESC;
2540 ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
2542 tz = rte_eth_dma_zone_reserve(dev, "fdir_tx_ring",
2543 I40E_FDIR_QUEUE_ID, ring_size,
2544 I40E_RING_BASE_ALIGN, SOCKET_ID_ANY);
2546 i40e_dev_tx_queue_release(txq);
2547 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX.");
2548 return I40E_ERR_NO_MEMORY;
2551 txq->nb_tx_desc = I40E_FDIR_NUM_TX_DESC;
2552 txq->queue_id = I40E_FDIR_QUEUE_ID;
2553 txq->reg_idx = pf->fdir.fdir_vsi->base_queue;
2554 txq->vsi = pf->fdir.fdir_vsi;
2556 txq->tx_ring_phys_addr = rte_mem_phy2mch(tz->memseg_id, tz->phys_addr);
2557 txq->tx_ring = (struct i40e_tx_desc *)tz->addr;
2559 * don't need to allocate software ring and reset for the fdir
2560 * program queue just set the queue has been configured.
2565 return I40E_SUCCESS;
2568 enum i40e_status_code
2569 i40e_fdir_setup_rx_resources(struct i40e_pf *pf)
2571 struct i40e_rx_queue *rxq;
2572 const struct rte_memzone *rz = NULL;
2574 struct rte_eth_dev *dev;
2577 PMD_DRV_LOG(ERR, "PF is not available");
2578 return I40E_ERR_BAD_PTR;
2581 dev = pf->adapter->eth_dev;
2583 /* Allocate the RX queue data structure. */
2584 rxq = rte_zmalloc_socket("i40e fdir rx queue",
2585 sizeof(struct i40e_rx_queue),
2586 RTE_CACHE_LINE_SIZE,
2589 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
2590 "rx queue structure.");
2591 return I40E_ERR_NO_MEMORY;
2594 /* Allocate RX hardware ring descriptors. */
2595 ring_size = sizeof(union i40e_rx_desc) * I40E_FDIR_NUM_RX_DESC;
2596 ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
2598 rz = rte_eth_dma_zone_reserve(dev, "fdir_rx_ring",
2599 I40E_FDIR_QUEUE_ID, ring_size,
2600 I40E_RING_BASE_ALIGN, SOCKET_ID_ANY);
2602 i40e_dev_rx_queue_release(rxq);
2603 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX.");
2604 return I40E_ERR_NO_MEMORY;
2607 rxq->nb_rx_desc = I40E_FDIR_NUM_RX_DESC;
2608 rxq->queue_id = I40E_FDIR_QUEUE_ID;
2609 rxq->reg_idx = pf->fdir.fdir_vsi->base_queue;
2610 rxq->vsi = pf->fdir.fdir_vsi;
2612 rxq->rx_ring_phys_addr = rte_mem_phy2mch(rz->memseg_id, rz->phys_addr);
2613 memset(rz->addr, 0, I40E_FDIR_NUM_RX_DESC * sizeof(union i40e_rx_desc));
2614 rxq->rx_ring = (union i40e_rx_desc *)rz->addr;
2617 * Don't need to allocate software ring and reset for the fdir
2618 * rx queue, just set the queue has been configured.
2623 return I40E_SUCCESS;
2627 i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2628 struct rte_eth_rxq_info *qinfo)
2630 struct i40e_rx_queue *rxq;
2632 rxq = dev->data->rx_queues[queue_id];
2634 qinfo->mp = rxq->mp;
2635 qinfo->scattered_rx = dev->data->scattered_rx;
2636 qinfo->nb_desc = rxq->nb_rx_desc;
2638 qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
2639 qinfo->conf.rx_drop_en = rxq->drop_en;
2640 qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
2644 i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2645 struct rte_eth_txq_info *qinfo)
2647 struct i40e_tx_queue *txq;
2649 txq = dev->data->tx_queues[queue_id];
2651 qinfo->nb_desc = txq->nb_tx_desc;
2653 qinfo->conf.tx_thresh.pthresh = txq->pthresh;
2654 qinfo->conf.tx_thresh.hthresh = txq->hthresh;
2655 qinfo->conf.tx_thresh.wthresh = txq->wthresh;
2657 qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
2658 qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
2659 qinfo->conf.txq_flags = txq->txq_flags;
2660 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
2663 void __attribute__((cold))
2664 i40e_set_rx_function(struct rte_eth_dev *dev)
2666 struct i40e_adapter *ad =
2667 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2668 uint16_t rx_using_sse, i;
2669 /* In order to allow Vector Rx there are a few configuration
2670 * conditions to be met and Rx Bulk Allocation should be allowed.
2672 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2673 if (i40e_rx_vec_dev_conf_condition_check(dev) ||
2674 !ad->rx_bulk_alloc_allowed) {
2675 PMD_INIT_LOG(DEBUG, "Port[%d] doesn't meet"
2676 " Vector Rx preconditions",
2677 dev->data->port_id);
2679 ad->rx_vec_allowed = false;
2681 if (ad->rx_vec_allowed) {
2682 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2683 struct i40e_rx_queue *rxq =
2684 dev->data->rx_queues[i];
2686 if (rxq && i40e_rxq_vec_setup(rxq)) {
2687 ad->rx_vec_allowed = false;
2694 if (dev->data->scattered_rx) {
2695 /* Set the non-LRO scattered callback: there are Vector and
2696 * single allocation versions.
2698 if (ad->rx_vec_allowed) {
2699 PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx "
2700 "callback (port=%d).",
2701 dev->data->port_id);
2703 dev->rx_pkt_burst = i40e_recv_scattered_pkts_vec;
2705 PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
2706 "allocation callback (port=%d).",
2707 dev->data->port_id);
2708 dev->rx_pkt_burst = i40e_recv_scattered_pkts;
2710 /* If parameters allow we are going to choose between the following
2714 * - Single buffer allocation (the simplest one)
2716 } else if (ad->rx_vec_allowed) {
2717 PMD_INIT_LOG(DEBUG, "Vector rx enabled, please make sure RX "
2718 "burst size no less than %d (port=%d).",
2719 RTE_I40E_DESCS_PER_LOOP,
2720 dev->data->port_id);
2722 dev->rx_pkt_burst = i40e_recv_pkts_vec;
2723 } else if (ad->rx_bulk_alloc_allowed) {
2724 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
2725 "satisfied. Rx Burst Bulk Alloc function "
2726 "will be used on port=%d.",
2727 dev->data->port_id);
2729 dev->rx_pkt_burst = i40e_recv_pkts_bulk_alloc;
2731 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are not "
2732 "satisfied, or Scattered Rx is requested "
2734 dev->data->port_id);
2736 dev->rx_pkt_burst = i40e_recv_pkts;
2739 /* Propagate information about RX function choice through all queues. */
2740 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2742 (dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec ||
2743 dev->rx_pkt_burst == i40e_recv_pkts_vec);
2745 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2746 struct i40e_rx_queue *rxq = dev->data->rx_queues[i];
2749 rxq->rx_using_sse = rx_using_sse;
2754 void __attribute__((cold))
2755 i40e_set_tx_function_flag(struct rte_eth_dev *dev, struct i40e_tx_queue *txq)
2757 struct i40e_adapter *ad =
2758 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2760 /* Use a simple Tx queue (no offloads, no multi segs) if possible */
2761 if (((txq->txq_flags & I40E_SIMPLE_FLAGS) == I40E_SIMPLE_FLAGS)
2762 && (txq->tx_rs_thresh >= RTE_PMD_I40E_TX_MAX_BURST)) {
2763 if (txq->tx_rs_thresh <= RTE_I40E_TX_MAX_FREE_BUF_SZ) {
2764 PMD_INIT_LOG(DEBUG, "Vector tx"
2765 " can be enabled on this txq.");
2768 ad->tx_vec_allowed = false;
2771 ad->tx_simple_allowed = false;
2775 void __attribute__((cold))
2776 i40e_set_tx_function(struct rte_eth_dev *dev)
2778 struct i40e_adapter *ad =
2779 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2782 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2783 if (ad->tx_vec_allowed) {
2784 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2785 struct i40e_tx_queue *txq =
2786 dev->data->tx_queues[i];
2788 if (txq && i40e_txq_vec_setup(txq)) {
2789 ad->tx_vec_allowed = false;
2796 if (ad->tx_simple_allowed) {
2797 if (ad->tx_vec_allowed) {
2798 PMD_INIT_LOG(DEBUG, "Vector tx finally be used.");
2799 dev->tx_pkt_burst = i40e_xmit_pkts_vec;
2801 PMD_INIT_LOG(DEBUG, "Simple tx finally be used.");
2802 dev->tx_pkt_burst = i40e_xmit_pkts_simple;
2805 PMD_INIT_LOG(DEBUG, "Xmit tx finally be used.");
2806 dev->tx_pkt_burst = i40e_xmit_pkts;
2810 /* Stubs needed for linkage when CONFIG_RTE_I40E_INC_VECTOR is set to 'n' */
2811 int __attribute__((weak))
2812 i40e_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused *dev)
2817 uint16_t __attribute__((weak))
2819 void __rte_unused *rx_queue,
2820 struct rte_mbuf __rte_unused **rx_pkts,
2821 uint16_t __rte_unused nb_pkts)
2826 uint16_t __attribute__((weak))
2827 i40e_recv_scattered_pkts_vec(
2828 void __rte_unused *rx_queue,
2829 struct rte_mbuf __rte_unused **rx_pkts,
2830 uint16_t __rte_unused nb_pkts)
2835 int __attribute__((weak))
2836 i40e_rxq_vec_setup(struct i40e_rx_queue __rte_unused *rxq)
2841 int __attribute__((weak))
2842 i40e_txq_vec_setup(struct i40e_tx_queue __rte_unused *txq)
2847 void __attribute__((weak))
2848 i40e_rx_queue_release_mbufs_vec(struct i40e_rx_queue __rte_unused*rxq)
2853 uint16_t __attribute__((weak))
2854 i40e_xmit_pkts_vec(void __rte_unused *tx_queue,
2855 struct rte_mbuf __rte_unused **tx_pkts,
2856 uint16_t __rte_unused nb_pkts)