4 * Copyright(c) 2010-2014 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 "i40e/i40e_prototype.h"
56 #include "i40e/i40e_type.h"
57 #include "i40e_ethdev.h"
58 #include "i40e_rxtx.h"
60 #define I40E_MIN_RING_DESC 64
61 #define I40E_MAX_RING_DESC 4096
62 #define I40E_ALIGN 128
63 #define DEFAULT_TX_RS_THRESH 32
64 #define DEFAULT_TX_FREE_THRESH 32
65 #define I40E_MAX_PKT_TYPE 256
67 #define I40E_VLAN_TAG_SIZE 4
68 #define I40E_TX_MAX_BURST 32
70 #define I40E_DMA_MEM_ALIGN 4096
72 #define I40E_SIMPLE_FLAGS ((uint32_t)ETH_TXQ_FLAGS_NOMULTSEGS | \
73 ETH_TXQ_FLAGS_NOOFFLOADS)
75 #define I40E_TXD_CMD (I40E_TX_DESC_CMD_EOP | I40E_TX_DESC_CMD_RS)
77 #define RTE_MBUF_DATA_DMA_ADDR_DEFAULT(mb) \
78 (uint64_t) ((mb)->buf_physaddr + RTE_PKTMBUF_HEADROOM)
80 #define RTE_MBUF_DATA_DMA_ADDR(mb) \
81 ((uint64_t)((mb)->buf_physaddr + \
82 (uint64_t)((char *)((mb)->pkt.data) - \
83 (char *)(mb)->buf_addr)))
85 static const struct rte_memzone *
86 i40e_ring_dma_zone_reserve(struct rte_eth_dev *dev,
87 const char *ring_name,
91 static void i40e_reset_rx_queue(struct i40e_rx_queue *rxq);
92 static void i40e_reset_tx_queue(struct i40e_tx_queue *txq);
93 static void i40e_tx_queue_release_mbufs(struct i40e_tx_queue *txq);
94 static uint16_t i40e_xmit_pkts_simple(void *tx_queue,
95 struct rte_mbuf **tx_pkts,
98 /* Translate the rx descriptor status to pkt flags */
99 static inline uint16_t
100 i40e_rxd_status_to_pkt_flags(uint64_t qword)
104 /* Check if VLAN packet */
105 flags = (uint16_t)(qword & (1 << I40E_RX_DESC_STATUS_L2TAG1P_SHIFT) ?
106 PKT_RX_VLAN_PKT : 0);
108 /* Check if RSS_HASH */
109 flags |= (uint16_t)((((qword >> I40E_RX_DESC_STATUS_FLTSTAT_SHIFT) &
110 I40E_RX_DESC_FLTSTAT_RSS_HASH) ==
111 I40E_RX_DESC_FLTSTAT_RSS_HASH) ? PKT_RX_RSS_HASH : 0);
116 static inline uint16_t
117 i40e_rxd_error_to_pkt_flags(uint64_t qword)
120 uint64_t error_bits = (qword >> I40E_RXD_QW1_ERROR_SHIFT);
122 #define I40E_RX_ERR_BITS 0x3f
123 if (likely((error_bits & I40E_RX_ERR_BITS) == 0))
125 /* If RXE bit set, all other status bits are meaningless */
126 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_RXE_SHIFT))) {
127 flags |= PKT_RX_MAC_ERR;
131 /* If RECIPE bit set, all other status indications should be ignored */
132 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_RECIPE_SHIFT))) {
133 flags |= PKT_RX_RECIP_ERR;
136 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_HBO_SHIFT)))
137 flags |= PKT_RX_HBUF_OVERFLOW;
138 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_IPE_SHIFT)))
139 flags |= PKT_RX_IP_CKSUM_BAD;
140 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_L4E_SHIFT)))
141 flags |= PKT_RX_L4_CKSUM_BAD;
142 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_EIPE_SHIFT)))
143 flags |= PKT_RX_EIP_CKSUM_BAD;
144 if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_OVERSIZE_SHIFT)))
145 flags |= PKT_RX_OVERSIZE;
150 /* Translate pkt types to pkt flags */
151 static inline uint16_t
152 i40e_rxd_ptype_to_pkt_flags(uint64_t qword)
154 uint8_t ptype = (uint8_t)((qword & I40E_RXD_QW1_PTYPE_MASK) >>
155 I40E_RXD_QW1_PTYPE_SHIFT);
156 static const uint16_t ip_ptype_map[I40E_MAX_PKT_TYPE] = {
179 PKT_RX_IPV4_HDR, /* PTYPE 22 */
180 PKT_RX_IPV4_HDR, /* PTYPE 23 */
181 PKT_RX_IPV4_HDR, /* PTYPE 24 */
183 PKT_RX_IPV4_HDR, /* PTYPE 26 */
184 PKT_RX_IPV4_HDR, /* PTYPE 27 */
185 PKT_RX_IPV4_HDR, /* PTYPE 28 */
186 PKT_RX_IPV4_HDR_EXT, /* PTYPE 29 */
187 PKT_RX_IPV4_HDR_EXT, /* PTYPE 30 */
188 PKT_RX_IPV4_HDR_EXT, /* PTYPE 31 */
190 PKT_RX_IPV4_HDR_EXT, /* PTYPE 33 */
191 PKT_RX_IPV4_HDR_EXT, /* PTYPE 34 */
192 PKT_RX_IPV4_HDR_EXT, /* PTYPE 35 */
193 PKT_RX_IPV4_HDR_EXT, /* PTYPE 36 */
194 PKT_RX_IPV4_HDR_EXT, /* PTYPE 37 */
195 PKT_RX_IPV4_HDR_EXT, /* PTYPE 38 */
197 PKT_RX_IPV4_HDR_EXT, /* PTYPE 40 */
198 PKT_RX_IPV4_HDR_EXT, /* PTYPE 41 */
199 PKT_RX_IPV4_HDR_EXT, /* PTYPE 42 */
200 PKT_RX_IPV4_HDR_EXT, /* PTYPE 43 */
201 PKT_RX_IPV4_HDR_EXT, /* PTYPE 44 */
202 PKT_RX_IPV4_HDR_EXT, /* PTYPE 45 */
203 PKT_RX_IPV4_HDR_EXT, /* PTYPE 46 */
205 PKT_RX_IPV4_HDR_EXT, /* PTYPE 48 */
206 PKT_RX_IPV4_HDR_EXT, /* PTYPE 49 */
207 PKT_RX_IPV4_HDR_EXT, /* PTYPE 50 */
208 PKT_RX_IPV4_HDR_EXT, /* PTYPE 51 */
209 PKT_RX_IPV4_HDR_EXT, /* PTYPE 52 */
210 PKT_RX_IPV4_HDR_EXT, /* PTYPE 53 */
212 PKT_RX_IPV4_HDR_EXT, /* PTYPE 55 */
213 PKT_RX_IPV4_HDR_EXT, /* PTYPE 56 */
214 PKT_RX_IPV4_HDR_EXT, /* PTYPE 57 */
215 PKT_RX_IPV4_HDR_EXT, /* PTYPE 58 */
216 PKT_RX_IPV4_HDR_EXT, /* PTYPE 59 */
217 PKT_RX_IPV4_HDR_EXT, /* PTYPE 60 */
218 PKT_RX_IPV4_HDR_EXT, /* PTYPE 61 */
220 PKT_RX_IPV4_HDR_EXT, /* PTYPE 63 */
221 PKT_RX_IPV4_HDR_EXT, /* PTYPE 64 */
222 PKT_RX_IPV4_HDR_EXT, /* PTYPE 65 */
223 PKT_RX_IPV4_HDR_EXT, /* PTYPE 66 */
224 PKT_RX_IPV4_HDR_EXT, /* PTYPE 67 */
225 PKT_RX_IPV4_HDR_EXT, /* PTYPE 68 */
227 PKT_RX_IPV4_HDR_EXT, /* PTYPE 70 */
228 PKT_RX_IPV4_HDR_EXT, /* PTYPE 71 */
229 PKT_RX_IPV4_HDR_EXT, /* PTYPE 72 */
230 PKT_RX_IPV4_HDR_EXT, /* PTYPE 73 */
231 PKT_RX_IPV4_HDR_EXT, /* PTYPE 74 */
232 PKT_RX_IPV4_HDR_EXT, /* PTYPE 75 */
233 PKT_RX_IPV4_HDR_EXT, /* PTYPE 76 */
235 PKT_RX_IPV4_HDR_EXT, /* PTYPE 78 */
236 PKT_RX_IPV4_HDR_EXT, /* PTYPE 79 */
237 PKT_RX_IPV4_HDR_EXT, /* PTYPE 80 */
238 PKT_RX_IPV4_HDR_EXT, /* PTYPE 81 */
239 PKT_RX_IPV4_HDR_EXT, /* PTYPE 82 */
240 PKT_RX_IPV4_HDR_EXT, /* PTYPE 83 */
242 PKT_RX_IPV4_HDR_EXT, /* PTYPE 85 */
243 PKT_RX_IPV4_HDR_EXT, /* PTYPE 86 */
244 PKT_RX_IPV4_HDR_EXT, /* PTYPE 87 */
245 PKT_RX_IPV6_HDR, /* PTYPE 88 */
246 PKT_RX_IPV6_HDR, /* PTYPE 89 */
247 PKT_RX_IPV6_HDR, /* PTYPE 90 */
249 PKT_RX_IPV6_HDR, /* PTYPE 92 */
250 PKT_RX_IPV6_HDR, /* PTYPE 93 */
251 PKT_RX_IPV6_HDR, /* PTYPE 94 */
252 PKT_RX_IPV6_HDR_EXT, /* PTYPE 95 */
253 PKT_RX_IPV6_HDR_EXT, /* PTYPE 96 */
254 PKT_RX_IPV6_HDR_EXT, /* PTYPE 97 */
256 PKT_RX_IPV6_HDR_EXT, /* PTYPE 99 */
257 PKT_RX_IPV6_HDR_EXT, /* PTYPE 100 */
258 PKT_RX_IPV6_HDR_EXT, /* PTYPE 101 */
259 PKT_RX_IPV6_HDR_EXT, /* PTYPE 102 */
260 PKT_RX_IPV6_HDR_EXT, /* PTYPE 103 */
261 PKT_RX_IPV6_HDR_EXT, /* PTYPE 104 */
263 PKT_RX_IPV6_HDR_EXT, /* PTYPE 106 */
264 PKT_RX_IPV6_HDR_EXT, /* PTYPE 107 */
265 PKT_RX_IPV6_HDR_EXT, /* PTYPE 108 */
266 PKT_RX_IPV6_HDR_EXT, /* PTYPE 109 */
267 PKT_RX_IPV6_HDR_EXT, /* PTYPE 110 */
268 PKT_RX_IPV6_HDR_EXT, /* PTYPE 111 */
269 PKT_RX_IPV6_HDR_EXT, /* PTYPE 112 */
271 PKT_RX_IPV6_HDR_EXT, /* PTYPE 114 */
272 PKT_RX_IPV6_HDR_EXT, /* PTYPE 115 */
273 PKT_RX_IPV6_HDR_EXT, /* PTYPE 116 */
274 PKT_RX_IPV6_HDR_EXT, /* PTYPE 117 */
275 PKT_RX_IPV6_HDR_EXT, /* PTYPE 118 */
276 PKT_RX_IPV6_HDR_EXT, /* PTYPE 119 */
278 PKT_RX_IPV6_HDR_EXT, /* PTYPE 121 */
279 PKT_RX_IPV6_HDR_EXT, /* PTYPE 122 */
280 PKT_RX_IPV6_HDR_EXT, /* PTYPE 123 */
281 PKT_RX_IPV6_HDR_EXT, /* PTYPE 124 */
282 PKT_RX_IPV6_HDR_EXT, /* PTYPE 125 */
283 PKT_RX_IPV6_HDR_EXT, /* PTYPE 126 */
284 PKT_RX_IPV6_HDR_EXT, /* PTYPE 127 */
286 PKT_RX_IPV6_HDR_EXT, /* PTYPE 129 */
287 PKT_RX_IPV6_HDR_EXT, /* PTYPE 130 */
288 PKT_RX_IPV6_HDR_EXT, /* PTYPE 131 */
289 PKT_RX_IPV6_HDR_EXT, /* PTYPE 132 */
290 PKT_RX_IPV6_HDR_EXT, /* PTYPE 133 */
291 PKT_RX_IPV6_HDR_EXT, /* PTYPE 134 */
293 PKT_RX_IPV6_HDR_EXT, /* PTYPE 136 */
294 PKT_RX_IPV6_HDR_EXT, /* PTYPE 137 */
295 PKT_RX_IPV6_HDR_EXT, /* PTYPE 138 */
296 PKT_RX_IPV6_HDR_EXT, /* PTYPE 139 */
297 PKT_RX_IPV6_HDR_EXT, /* PTYPE 140 */
298 PKT_RX_IPV6_HDR_EXT, /* PTYPE 141 */
299 PKT_RX_IPV6_HDR_EXT, /* PTYPE 142 */
301 PKT_RX_IPV6_HDR_EXT, /* PTYPE 144 */
302 PKT_RX_IPV6_HDR_EXT, /* PTYPE 145 */
303 PKT_RX_IPV6_HDR_EXT, /* PTYPE 146 */
304 PKT_RX_IPV6_HDR_EXT, /* PTYPE 147 */
305 PKT_RX_IPV6_HDR_EXT, /* PTYPE 148 */
306 PKT_RX_IPV6_HDR_EXT, /* PTYPE 149 */
308 PKT_RX_IPV6_HDR_EXT, /* PTYPE 151 */
309 PKT_RX_IPV6_HDR_EXT, /* PTYPE 152 */
310 PKT_RX_IPV6_HDR_EXT, /* PTYPE 153 */
415 return ip_ptype_map[ptype];
419 i40e_txd_enable_checksum(uint32_t ol_flags,
426 PMD_DRV_LOG(DEBUG, "L2 length set to 0\n");
429 *td_offset |= (l2_len >> 1) << I40E_TX_DESC_LENGTH_MACLEN_SHIFT;
432 PMD_DRV_LOG(DEBUG, "L3 length set to 0\n");
436 /* Enable L3 checksum offloads */
437 if (ol_flags & PKT_TX_IPV4_CSUM) {
438 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV4_CSUM;
439 *td_offset |= (l3_len >> 2) << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
440 } else if (ol_flags & PKT_TX_IPV4) {
441 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV4;
442 *td_offset |= (l3_len >> 2) << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
443 } else if (ol_flags & PKT_TX_IPV6) {
444 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV6;
445 *td_offset |= (l3_len >> 2) << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
448 /* Enable L4 checksum offloads */
449 switch (ol_flags & PKT_TX_L4_MASK) {
450 case PKT_TX_TCP_CKSUM:
451 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_TCP;
452 *td_offset |= (sizeof(struct tcp_hdr) >> 2) <<
453 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
455 case PKT_TX_SCTP_CKSUM:
456 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_SCTP;
457 *td_offset |= (sizeof(struct sctp_hdr) >> 2) <<
458 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
460 case PKT_TX_UDP_CKSUM:
461 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_UDP;
462 *td_offset |= (sizeof(struct udp_hdr) >> 2) <<
463 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
470 static inline struct rte_mbuf *
471 rte_rxmbuf_alloc(struct rte_mempool *mp)
475 m = __rte_mbuf_raw_alloc(mp);
476 __rte_mbuf_sanity_check_raw(m, RTE_MBUF_PKT, 0);
481 /* Construct the tx flags */
482 static inline uint64_t
483 i40e_build_ctob(uint32_t td_cmd,
488 return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA |
489 ((uint64_t)td_cmd << I40E_TXD_QW1_CMD_SHIFT) |
490 ((uint64_t)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) |
491 ((uint64_t)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) |
492 ((uint64_t)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT));
496 i40e_xmit_cleanup(struct i40e_tx_queue *txq)
498 struct i40e_tx_entry *sw_ring = txq->sw_ring;
499 volatile struct i40e_tx_desc *txd = txq->tx_ring;
500 uint16_t last_desc_cleaned = txq->last_desc_cleaned;
501 uint16_t nb_tx_desc = txq->nb_tx_desc;
502 uint16_t desc_to_clean_to;
503 uint16_t nb_tx_to_clean;
505 desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_rs_thresh);
506 if (desc_to_clean_to >= nb_tx_desc)
507 desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
509 desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
510 if (!(txd[desc_to_clean_to].cmd_type_offset_bsz &
511 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))) {
512 PMD_TX_FREE_LOG(DEBUG, "TX descriptor %4u is not done "
513 "(port=%d queue=%d)", desc_to_clean_to,
514 txq->port_id, txq->queue_id);
518 if (last_desc_cleaned > desc_to_clean_to)
519 nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
522 nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
525 txd[desc_to_clean_to].cmd_type_offset_bsz = 0;
527 txq->last_desc_cleaned = desc_to_clean_to;
528 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
534 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
535 check_rx_burst_bulk_alloc_preconditions(struct i40e_rx_queue *rxq)
537 check_rx_burst_bulk_alloc_preconditions(__rte_unused struct i40e_rx_queue *rxq)
542 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
543 if (!(rxq->rx_free_thresh >= RTE_PMD_I40E_RX_MAX_BURST))
545 else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc))
547 else if (!(rxq->nb_rx_desc % rxq->rx_free_thresh) == 0)
549 else if (!(rxq->nb_rx_desc < (I40E_MAX_RING_DESC -
550 RTE_PMD_I40E_RX_MAX_BURST)))
559 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
560 #define I40E_LOOK_AHEAD 8
561 #if (I40E_LOOK_AHEAD != 8)
562 #error "PMD I40E: I40E_LOOK_AHEAD must be 8\n"
565 i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
567 volatile union i40e_rx_desc *rxdp;
568 struct i40e_rx_entry *rxep;
573 int32_t s[I40E_LOOK_AHEAD], nb_dd;
574 int32_t i, j, nb_rx = 0;
577 rxdp = &rxq->rx_ring[rxq->rx_tail];
578 rxep = &rxq->sw_ring[rxq->rx_tail];
580 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
581 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
582 I40E_RXD_QW1_STATUS_SHIFT;
584 /* Make sure there is at least 1 packet to receive */
585 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
589 * Scan LOOK_AHEAD descriptors at a time to determine which
590 * descriptors reference packets that are ready to be received.
592 for (i = 0; i < RTE_PMD_I40E_RX_MAX_BURST; i+=I40E_LOOK_AHEAD,
593 rxdp += I40E_LOOK_AHEAD, rxep += I40E_LOOK_AHEAD) {
594 /* Read desc statuses backwards to avoid race condition */
595 for (j = I40E_LOOK_AHEAD - 1; j >= 0; j--) {
596 qword1 = rte_le_to_cpu_64(\
597 rxdp[j].wb.qword1.status_error_len);
598 s[j] = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
599 I40E_RXD_QW1_STATUS_SHIFT;
602 /* Compute how many status bits were set */
603 for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++)
604 nb_dd += s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
608 /* Translate descriptor info to mbuf parameters */
609 for (j = 0; j < nb_dd; j++) {
611 qword1 = rte_le_to_cpu_64(\
612 rxdp[j].wb.qword1.status_error_len);
613 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
614 I40E_RXD_QW1_STATUS_SHIFT;
615 pkt_len = ((qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
616 I40E_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
617 mb->pkt.data_len = pkt_len;
618 mb->pkt.pkt_len = pkt_len;
619 mb->pkt.vlan_macip.f.vlan_tci = rx_status &
620 (1 << I40E_RX_DESC_STATUS_L2TAG1P_SHIFT) ?
622 rxdp[j].wb.qword0.lo_dword.l2tag1) : 0;
623 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
624 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
625 pkt_flags |= i40e_rxd_ptype_to_pkt_flags(qword1);
626 mb->ol_flags = pkt_flags;
627 if (pkt_flags & PKT_RX_RSS_HASH)
628 mb->pkt.hash.rss = rte_le_to_cpu_32(\
629 rxdp->wb.qword0.hi_dword.rss);
632 for (j = 0; j < I40E_LOOK_AHEAD; j++)
633 rxq->rx_stage[i + j] = rxep[j].mbuf;
635 if (nb_dd != I40E_LOOK_AHEAD)
639 /* Clear software ring entries */
640 for (i = 0; i < nb_rx; i++)
641 rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
646 static inline uint16_t
647 i40e_rx_fill_from_stage(struct i40e_rx_queue *rxq,
648 struct rte_mbuf **rx_pkts,
652 struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
654 nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
656 for (i = 0; i < nb_pkts; i++)
657 rx_pkts[i] = stage[i];
659 rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
660 rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
666 i40e_rx_alloc_bufs(struct i40e_rx_queue *rxq)
668 volatile union i40e_rx_desc *rxdp;
669 struct i40e_rx_entry *rxep;
671 uint16_t alloc_idx, i;
675 /* Allocate buffers in bulk */
676 alloc_idx = (uint16_t)(rxq->rx_free_trigger -
677 (rxq->rx_free_thresh - 1));
678 rxep = &(rxq->sw_ring[alloc_idx]);
679 diag = rte_mempool_get_bulk(rxq->mp, (void *)rxep,
680 rxq->rx_free_thresh);
681 if (unlikely(diag != 0)) {
682 PMD_DRV_LOG(ERR, "Failed to get mbufs in bulk\n");
686 rxdp = &rxq->rx_ring[alloc_idx];
687 for (i = 0; i < rxq->rx_free_thresh; i++) {
689 rte_mbuf_refcnt_set(mb, 1);
690 mb->type = RTE_MBUF_PKT;
692 mb->pkt.data = (char *)mb->buf_addr + RTE_PKTMBUF_HEADROOM;
694 mb->pkt.in_port = rxq->port_id;
695 dma_addr = rte_cpu_to_le_64(\
696 RTE_MBUF_DATA_DMA_ADDR_DEFAULT(mb));
697 rxdp[i].read.hdr_addr = dma_addr;
698 rxdp[i].read.pkt_addr = dma_addr;
701 /* Update rx tail regsiter */
703 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->rx_free_trigger);
705 rxq->rx_free_trigger =
706 (uint16_t)(rxq->rx_free_trigger + rxq->rx_free_thresh);
707 if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
708 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
713 static inline uint16_t
714 rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
716 struct i40e_rx_queue *rxq = (struct i40e_rx_queue *)rx_queue;
722 if (rxq->rx_nb_avail)
723 return i40e_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
725 nb_rx = (uint16_t)i40e_rx_scan_hw_ring(rxq);
726 rxq->rx_next_avail = 0;
727 rxq->rx_nb_avail = nb_rx;
728 rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
730 if (rxq->rx_tail > rxq->rx_free_trigger) {
731 if (i40e_rx_alloc_bufs(rxq) != 0) {
734 PMD_RX_LOG(DEBUG, "Rx mbuf alloc failed for "
735 "port_id=%u, queue_id=%u\n",
736 rxq->port_id, rxq->queue_id);
737 rxq->rx_nb_avail = 0;
738 rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
739 for (i = 0, j = rxq->rx_tail; i < nb_rx; i++, j++)
740 rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
746 if (rxq->rx_tail >= rxq->nb_rx_desc)
749 if (rxq->rx_nb_avail)
750 return i40e_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
756 i40e_recv_pkts_bulk_alloc(void *rx_queue,
757 struct rte_mbuf **rx_pkts,
760 uint16_t nb_rx = 0, n, count;
762 if (unlikely(nb_pkts == 0))
765 if (likely(nb_pkts <= RTE_PMD_I40E_RX_MAX_BURST))
766 return rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
769 n = RTE_MIN(nb_pkts, RTE_PMD_I40E_RX_MAX_BURST);
770 count = rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
771 nb_rx = (uint16_t)(nb_rx + count);
772 nb_pkts = (uint16_t)(nb_pkts - count);
779 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
782 i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
784 struct i40e_rx_queue *rxq;
785 volatile union i40e_rx_desc *rx_ring;
786 volatile union i40e_rx_desc *rxdp;
787 union i40e_rx_desc rxd;
788 struct i40e_rx_entry *sw_ring;
789 struct i40e_rx_entry *rxe;
790 struct rte_mbuf *rxm;
791 struct rte_mbuf *nmb;
795 uint16_t rx_packet_len;
796 uint16_t rx_id, nb_hold;
803 rx_id = rxq->rx_tail;
804 rx_ring = rxq->rx_ring;
805 sw_ring = rxq->sw_ring;
807 while (nb_rx < nb_pkts) {
808 rxdp = &rx_ring[rx_id];
809 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
810 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK)
811 >> I40E_RXD_QW1_STATUS_SHIFT;
812 /* Check the DD bit first */
813 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
816 nmb = rte_rxmbuf_alloc(rxq->mp);
822 rxe = &sw_ring[rx_id];
824 if (unlikely(rx_id == rxq->nb_rx_desc))
827 /* Prefetch next mbuf */
828 rte_prefetch0(sw_ring[rx_id].mbuf);
831 * When next RX descriptor is on a cache line boundary,
832 * prefetch the next 4 RX descriptors and next 8 pointers
835 if ((rx_id & 0x3) == 0) {
836 rte_prefetch0(&rx_ring[rx_id]);
837 rte_prefetch0(&sw_ring[rx_id]);
842 rte_cpu_to_le_64(RTE_MBUF_DATA_DMA_ADDR_DEFAULT(nmb));
843 rxdp->read.hdr_addr = dma_addr;
844 rxdp->read.pkt_addr = dma_addr;
846 rx_packet_len = ((qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
847 I40E_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
849 rxm->pkt.data = (char *)rxm->buf_addr + RTE_PKTMBUF_HEADROOM;
850 rte_prefetch0(rxm->pkt.data);
851 rxm->pkt.nb_segs = 1;
852 rxm->pkt.next = NULL;
853 rxm->pkt.pkt_len = rx_packet_len;
854 rxm->pkt.data_len = rx_packet_len;
855 rxm->pkt.in_port = rxq->port_id;
857 rxm->pkt.vlan_macip.f.vlan_tci = rx_status &
858 (1 << I40E_RX_DESC_STATUS_L2TAG1P_SHIFT) ?
859 rte_le_to_cpu_16(rxd.wb.qword0.lo_dword.l2tag1) : 0;
860 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
861 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
862 pkt_flags |= i40e_rxd_ptype_to_pkt_flags(qword1);
863 rxm->ol_flags = pkt_flags;
864 if (pkt_flags & PKT_RX_RSS_HASH)
866 rte_le_to_cpu_32(rxdp->wb.qword0.hi_dword.rss);
868 rx_pkts[nb_rx++] = rxm;
870 rxq->rx_tail = rx_id;
873 * If the number of free RX descriptors is greater than the RX free
874 * threshold of the queue, advance the receive tail register of queue.
875 * Update that register with the value of the last processed RX
876 * descriptor minus 1.
878 nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
879 if (nb_hold > rxq->rx_free_thresh) {
880 rx_id = (uint16_t) ((rx_id == 0) ?
881 (rxq->nb_rx_desc - 1) : (rx_id - 1));
882 I40E_PCI_REG_WRITE(rxq->qrx_tail, rx_id);
885 rxq->nb_rx_hold = nb_hold;
891 i40e_recv_scattered_pkts(void *rx_queue,
892 struct rte_mbuf **rx_pkts,
895 struct i40e_rx_queue *rxq = rx_queue;
896 volatile union i40e_rx_desc *rx_ring = rxq->rx_ring;
897 volatile union i40e_rx_desc *rxdp;
898 union i40e_rx_desc rxd;
899 struct i40e_rx_entry *sw_ring = rxq->sw_ring;
900 struct i40e_rx_entry *rxe;
901 struct rte_mbuf *first_seg = rxq->pkt_first_seg;
902 struct rte_mbuf *last_seg = rxq->pkt_last_seg;
903 struct rte_mbuf *nmb, *rxm;
904 uint16_t rx_id = rxq->rx_tail;
905 uint16_t nb_rx = 0, nb_hold = 0, rx_packet_len, pkt_flags;
910 while (nb_rx < nb_pkts) {
911 rxdp = &rx_ring[rx_id];
912 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
913 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
914 I40E_RXD_QW1_STATUS_SHIFT;
915 /* Check the DD bit */
916 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
919 nmb = rte_rxmbuf_alloc(rxq->mp);
924 rxe = &sw_ring[rx_id];
926 if (rx_id == rxq->nb_rx_desc)
929 /* Prefetch next mbuf */
930 rte_prefetch0(sw_ring[rx_id].mbuf);
933 * When next RX descriptor is on a cache line boundary,
934 * prefetch the next 4 RX descriptors and next 8 pointers
937 if ((rx_id & 0x3) == 0) {
938 rte_prefetch0(&rx_ring[rx_id]);
939 rte_prefetch0(&sw_ring[rx_id]);
945 rte_cpu_to_le_64(RTE_MBUF_DATA_DMA_ADDR_DEFAULT(nmb));
947 /* Set data buffer address and data length of the mbuf */
948 rxdp->read.hdr_addr = dma_addr;
949 rxdp->read.pkt_addr = dma_addr;
950 rx_packet_len = (qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
951 I40E_RXD_QW1_LENGTH_PBUF_SHIFT;
952 rxm->pkt.data_len = rx_packet_len;
953 rxm->pkt.data = (char *)rxm->buf_addr + RTE_PKTMBUF_HEADROOM;
956 * If this is the first buffer of the received packet, set the
957 * pointer to the first mbuf of the packet and initialize its
958 * context. Otherwise, update the total length and the number
959 * of segments of the current scattered packet, and update the
960 * pointer to the last mbuf of the current packet.
964 first_seg->pkt.nb_segs = 1;
965 first_seg->pkt.pkt_len = rx_packet_len;
967 first_seg->pkt.pkt_len =
968 (uint16_t)(first_seg->pkt.pkt_len +
970 first_seg->pkt.nb_segs++;
971 last_seg->pkt.next = rxm;
975 * If this is not the last buffer of the received packet,
976 * update the pointer to the last mbuf of the current scattered
977 * packet and continue to parse the RX ring.
979 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_EOF_SHIFT))) {
985 * This is the last buffer of the received packet. If the CRC
986 * is not stripped by the hardware:
987 * - Subtract the CRC length from the total packet length.
988 * - If the last buffer only contains the whole CRC or a part
989 * of it, free the mbuf associated to the last buffer. If part
990 * of the CRC is also contained in the previous mbuf, subtract
991 * the length of that CRC part from the data length of the
994 rxm->pkt.next = NULL;
995 if (unlikely(rxq->crc_len > 0)) {
996 first_seg->pkt.pkt_len -= ETHER_CRC_LEN;
997 if (rx_packet_len <= ETHER_CRC_LEN) {
998 rte_pktmbuf_free_seg(rxm);
999 first_seg->pkt.nb_segs--;
1000 last_seg->pkt.data_len =
1001 (uint16_t)(last_seg->pkt.data_len -
1002 (ETHER_CRC_LEN - rx_packet_len));
1003 last_seg->pkt.next = NULL;
1005 rxm->pkt.data_len = (uint16_t)(rx_packet_len -
1009 first_seg->pkt.in_port = rxq->port_id;
1010 first_seg->pkt.vlan_macip.f.vlan_tci = (rx_status &
1011 (1 << I40E_RX_DESC_STATUS_L2TAG1P_SHIFT)) ?
1012 rte_le_to_cpu_16(rxd.wb.qword0.lo_dword.l2tag1) : 0;
1013 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
1014 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
1015 pkt_flags |= i40e_rxd_ptype_to_pkt_flags(qword1);
1016 first_seg->ol_flags = pkt_flags;
1017 if (pkt_flags & PKT_RX_RSS_HASH)
1019 rte_le_to_cpu_32(rxdp->wb.qword0.hi_dword.rss);
1021 /* Prefetch data of first segment, if configured to do so. */
1022 rte_prefetch0(first_seg->pkt.data);
1023 rx_pkts[nb_rx++] = first_seg;
1027 /* Record index of the next RX descriptor to probe. */
1028 rxq->rx_tail = rx_id;
1029 rxq->pkt_first_seg = first_seg;
1030 rxq->pkt_last_seg = last_seg;
1033 * If the number of free RX descriptors is greater than the RX free
1034 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1035 * register. Update the RDT with the value of the last processed RX
1036 * descriptor minus 1, to guarantee that the RDT register is never
1037 * equal to the RDH register, which creates a "full" ring situtation
1038 * from the hardware point of view.
1040 nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
1041 if (nb_hold > rxq->rx_free_thresh) {
1042 rx_id = (uint16_t)(rx_id == 0 ?
1043 (rxq->nb_rx_desc - 1) : (rx_id - 1));
1044 I40E_PCI_REG_WRITE(rxq->qrx_tail, rx_id);
1047 rxq->nb_rx_hold = nb_hold;
1052 /* Check if the context descriptor is needed for TX offloading */
1053 static inline uint16_t
1054 i40e_calc_context_desc(uint16_t flags)
1058 #ifdef RTE_LIBRTE_IEEE1588
1059 mask |= PKT_TX_IEEE1588_TMST;
1068 i40e_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1070 struct i40e_tx_queue *txq;
1071 struct i40e_tx_entry *sw_ring;
1072 struct i40e_tx_entry *txe, *txn;
1073 volatile struct i40e_tx_desc *txd;
1074 volatile struct i40e_tx_desc *txr;
1075 struct rte_mbuf *tx_pkt;
1076 struct rte_mbuf *m_seg;
1090 uint64_t buf_dma_addr;
1093 sw_ring = txq->sw_ring;
1095 tx_id = txq->tx_tail;
1096 txe = &sw_ring[tx_id];
1098 /* Check if the descriptor ring needs to be cleaned. */
1099 if ((txq->nb_tx_desc - txq->nb_tx_free) > txq->tx_free_thresh)
1100 i40e_xmit_cleanup(txq);
1102 for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
1108 tx_pkt = *tx_pkts++;
1109 RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
1111 ol_flags = tx_pkt->ol_flags;
1112 l2_len = tx_pkt->pkt.vlan_macip.f.l2_len;
1113 l3_len = tx_pkt->pkt.vlan_macip.f.l3_len;
1115 /* Calculate the number of context descriptors needed. */
1116 nb_ctx = i40e_calc_context_desc(ol_flags);
1119 * The number of descriptors that must be allocated for
1120 * a packet equals to the number of the segments of that
1121 * packet plus 1 context descriptor if needed.
1123 nb_used = (uint16_t)(tx_pkt->pkt.nb_segs + nb_ctx);
1124 tx_last = (uint16_t)(tx_id + nb_used - 1);
1127 if (tx_last >= txq->nb_tx_desc)
1128 tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
1130 if (nb_used > txq->nb_tx_free) {
1131 if (i40e_xmit_cleanup(txq) != 0) {
1136 if (unlikely(nb_used > txq->tx_rs_thresh)) {
1137 while (nb_used > txq->nb_tx_free) {
1138 if (i40e_xmit_cleanup(txq) != 0) {
1147 /* Descriptor based VLAN insertion */
1148 if (ol_flags & PKT_TX_VLAN_PKT) {
1149 tx_flags |= tx_pkt->pkt.vlan_macip.f.vlan_tci <<
1150 I40E_TX_FLAG_L2TAG1_SHIFT;
1151 tx_flags |= I40E_TX_FLAG_INSERT_VLAN;
1152 td_cmd |= I40E_TX_DESC_CMD_IL2TAG1;
1153 td_tag = (tx_flags & I40E_TX_FLAG_L2TAG1_MASK) >>
1154 I40E_TX_FLAG_L2TAG1_SHIFT;
1157 /* Always enable CRC offload insertion */
1158 td_cmd |= I40E_TX_DESC_CMD_ICRC;
1160 /* Enable checksum offloading */
1161 i40e_txd_enable_checksum(ol_flags, &td_cmd, &td_offset,
1164 if (unlikely(nb_ctx)) {
1165 /* Setup TX context descriptor if required */
1166 volatile struct i40e_tx_context_desc *ctx_txd =
1167 (volatile struct i40e_tx_context_desc *)\
1169 uint32_t cd_tunneling_params = 0;
1170 uint16_t cd_l2tag2 = 0;
1171 uint64_t cd_type_cmd_tso_mss =
1172 I40E_TX_DESC_DTYPE_CONTEXT;
1174 txn = &sw_ring[txe->next_id];
1175 RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
1176 if (txe->mbuf != NULL) {
1177 rte_pktmbuf_free_seg(txe->mbuf);
1180 #ifdef RTE_LIBRTE_IEEE1588
1181 if (ol_flags & PKT_TX_IEEE1588_TMST)
1182 cd_type_cmd_tso_mss |=
1183 ((uint64_t)I40E_TX_CTX_DESC_TSYN <<
1184 I40E_TXD_CTX_QW1_CMD_SHIFT);
1186 ctx_txd->tunneling_params =
1187 rte_cpu_to_le_32(cd_tunneling_params);
1188 ctx_txd->l2tag2 = rte_cpu_to_le_16(cd_l2tag2);
1189 ctx_txd->type_cmd_tso_mss =
1190 rte_cpu_to_le_64(cd_type_cmd_tso_mss);
1191 txe->last_id = tx_last;
1192 tx_id = txe->next_id;
1199 txn = &sw_ring[txe->next_id];
1202 rte_pktmbuf_free_seg(txe->mbuf);
1205 /* Setup TX Descriptor */
1206 slen = m_seg->pkt.data_len;
1207 buf_dma_addr = RTE_MBUF_DATA_DMA_ADDR(m_seg);
1208 txd->buffer_addr = rte_cpu_to_le_64(buf_dma_addr);
1209 txd->cmd_type_offset_bsz = i40e_build_ctob(td_cmd,
1210 td_offset, slen, td_tag);
1211 txe->last_id = tx_last;
1212 tx_id = txe->next_id;
1214 m_seg = m_seg->pkt.next;
1215 } while (m_seg != NULL);
1217 /* The last packet data descriptor needs End Of Packet (EOP) */
1218 td_cmd |= I40E_TX_DESC_CMD_EOP;
1219 txq->nb_tx_used = (uint16_t)(txq->nb_tx_used + nb_used);
1220 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
1222 if (txq->nb_tx_used >= txq->tx_rs_thresh) {
1223 PMD_TX_FREE_LOG(DEBUG,
1224 "Setting RS bit on TXD id="
1225 "%4u (port=%d queue=%d)",
1226 tx_last, txq->port_id, txq->queue_id);
1228 td_cmd |= I40E_TX_DESC_CMD_RS;
1230 /* Update txq RS bit counters */
1231 txq->nb_tx_used = 0;
1234 txd->cmd_type_offset_bsz |=
1235 rte_cpu_to_le_64(((uint64_t)td_cmd) <<
1236 I40E_TXD_QW1_CMD_SHIFT);
1242 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
1243 (unsigned) txq->port_id, (unsigned) txq->queue_id,
1244 (unsigned) tx_id, (unsigned) nb_tx);
1246 I40E_PCI_REG_WRITE(txq->qtx_tail, tx_id);
1247 txq->tx_tail = tx_id;
1252 static inline int __attribute__((always_inline))
1253 i40e_tx_free_bufs(struct i40e_tx_queue *txq)
1255 struct i40e_tx_entry *txep;
1258 if (!(txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz &
1259 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE)))
1262 txep = &(txq->sw_ring[txq->tx_next_dd - (txq->tx_rs_thresh - 1)]);
1264 for (i = 0; i < txq->tx_rs_thresh; i++)
1265 rte_prefetch0((txep + i)->mbuf);
1267 if (!(txq->txq_flags & (uint32_t)ETH_TXQ_FLAGS_NOREFCOUNT)) {
1268 for (i = 0; i < txq->tx_rs_thresh; ++i, ++txep) {
1269 rte_mempool_put(txep->mbuf->pool, txep->mbuf);
1273 for (i = 0; i < txq->tx_rs_thresh; ++i, ++txep) {
1274 rte_pktmbuf_free_seg(txep->mbuf);
1279 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_rs_thresh);
1280 txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_rs_thresh);
1281 if (txq->tx_next_dd >= txq->nb_tx_desc)
1282 txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
1284 return txq->tx_rs_thresh;
1287 #define I40E_TD_CMD (I40E_TX_DESC_CMD_ICRC |\
1288 I40E_TX_DESC_CMD_EOP)
1290 /* Populate 4 descriptors with data from 4 mbufs */
1292 tx4(volatile struct i40e_tx_desc *txdp, struct rte_mbuf **pkts)
1297 for (i = 0; i < 4; i++, txdp++, pkts++) {
1298 dma_addr = RTE_MBUF_DATA_DMA_ADDR(*pkts);
1299 txdp->buffer_addr = rte_cpu_to_le_64(dma_addr);
1300 txdp->cmd_type_offset_bsz =
1301 i40e_build_ctob((uint32_t)I40E_TD_CMD, 0,
1302 (*pkts)->pkt.data_len, 0);
1306 /* Populate 1 descriptor with data from 1 mbuf */
1308 tx1(volatile struct i40e_tx_desc *txdp, struct rte_mbuf **pkts)
1312 dma_addr = RTE_MBUF_DATA_DMA_ADDR(*pkts);
1313 txdp->buffer_addr = rte_cpu_to_le_64(dma_addr);
1314 txdp->cmd_type_offset_bsz =
1315 i40e_build_ctob((uint32_t)I40E_TD_CMD, 0,
1316 (*pkts)->pkt.data_len, 0);
1319 /* Fill hardware descriptor ring with mbuf data */
1321 i40e_tx_fill_hw_ring(struct i40e_tx_queue *txq,
1322 struct rte_mbuf **pkts,
1325 volatile struct i40e_tx_desc *txdp = &(txq->tx_ring[txq->tx_tail]);
1326 struct i40e_tx_entry *txep = &(txq->sw_ring[txq->tx_tail]);
1327 const int N_PER_LOOP = 4;
1328 const int N_PER_LOOP_MASK = N_PER_LOOP - 1;
1329 int mainpart, leftover;
1332 mainpart = (nb_pkts & ((uint32_t) ~N_PER_LOOP_MASK));
1333 leftover = (nb_pkts & ((uint32_t) N_PER_LOOP_MASK));
1334 for (i = 0; i < mainpart; i += N_PER_LOOP) {
1335 for (j = 0; j < N_PER_LOOP; ++j) {
1336 (txep + i + j)->mbuf = *(pkts + i + j);
1338 tx4(txdp + i, pkts + i);
1340 if (unlikely(leftover > 0)) {
1341 for (i = 0; i < leftover; ++i) {
1342 (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
1343 tx1(txdp + mainpart + i, pkts + mainpart + i);
1348 static inline uint16_t
1349 tx_xmit_pkts(struct i40e_tx_queue *txq,
1350 struct rte_mbuf **tx_pkts,
1353 volatile struct i40e_tx_desc *txr = txq->tx_ring;
1357 * Begin scanning the H/W ring for done descriptors when the number
1358 * of available descriptors drops below tx_free_thresh. For each done
1359 * descriptor, free the associated buffer.
1361 if (txq->nb_tx_free < txq->tx_free_thresh)
1362 i40e_tx_free_bufs(txq);
1364 /* Use available descriptor only */
1365 nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
1366 if (unlikely(!nb_pkts))
1369 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
1370 if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
1371 n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
1372 i40e_tx_fill_hw_ring(txq, tx_pkts, n);
1373 txr[txq->tx_next_rs].cmd_type_offset_bsz |=
1374 rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
1375 I40E_TXD_QW1_CMD_SHIFT);
1376 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
1380 /* Fill hardware descriptor ring with mbuf data */
1381 i40e_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
1382 txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
1384 /* Determin if RS bit needs to be set */
1385 if (txq->tx_tail > txq->tx_next_rs) {
1386 txr[txq->tx_next_rs].cmd_type_offset_bsz |=
1387 rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
1388 I40E_TXD_QW1_CMD_SHIFT);
1390 (uint16_t)(txq->tx_next_rs + txq->tx_rs_thresh);
1391 if (txq->tx_next_rs >= txq->nb_tx_desc)
1392 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
1395 if (txq->tx_tail >= txq->nb_tx_desc)
1398 /* Update the tx tail register */
1400 I40E_PCI_REG_WRITE(txq->qtx_tail, txq->tx_tail);
1406 i40e_xmit_pkts_simple(void *tx_queue,
1407 struct rte_mbuf **tx_pkts,
1412 if (likely(nb_pkts <= I40E_TX_MAX_BURST))
1413 return tx_xmit_pkts((struct i40e_tx_queue *)tx_queue,
1417 uint16_t ret, num = (uint16_t)RTE_MIN(nb_pkts,
1420 ret = tx_xmit_pkts((struct i40e_tx_queue *)tx_queue,
1421 &tx_pkts[nb_tx], num);
1422 nb_tx = (uint16_t)(nb_tx + ret);
1423 nb_pkts = (uint16_t)(nb_pkts - ret);
1432 i40e_dev_rx_queue_setup(struct rte_eth_dev *dev,
1435 unsigned int socket_id,
1436 const struct rte_eth_rxconf *rx_conf,
1437 struct rte_mempool *mp)
1439 struct i40e_vsi *vsi = I40E_DEV_PRIVATE_TO_VSI(dev->data->dev_private);
1440 struct i40e_rx_queue *rxq;
1441 const struct rte_memzone *rz;
1444 int use_def_burst_func = 1;
1446 if (!vsi || queue_idx >= vsi->nb_qps) {
1447 PMD_DRV_LOG(ERR, "VSI not available or queue "
1448 "index exceeds the maximum\n");
1449 return I40E_ERR_PARAM;
1451 if (((nb_desc * sizeof(union i40e_rx_desc)) % I40E_ALIGN) != 0 ||
1452 (nb_desc > I40E_MAX_RING_DESC) ||
1453 (nb_desc < I40E_MIN_RING_DESC)) {
1454 PMD_DRV_LOG(ERR, "Number (%u) of receive descriptors is "
1455 "invalid\n", nb_desc);
1456 return I40E_ERR_PARAM;
1459 /* Free memory if needed */
1460 if (dev->data->rx_queues[queue_idx]) {
1461 i40e_dev_rx_queue_release(dev->data->rx_queues[queue_idx]);
1462 dev->data->rx_queues[queue_idx] = NULL;
1465 /* Allocate the rx queue data structure */
1466 rxq = rte_zmalloc_socket("i40e rx queue",
1467 sizeof(struct i40e_rx_queue),
1471 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
1472 "rx queue data structure\n");
1476 rxq->nb_rx_desc = nb_desc;
1477 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1478 rxq->queue_id = queue_idx;
1479 rxq->reg_idx = vsi->base_queue + queue_idx;
1480 rxq->port_id = dev->data->port_id;
1481 rxq->crc_len = (uint8_t) ((dev->data->dev_conf.rxmode.hw_strip_crc) ?
1483 rxq->drop_en = rx_conf->rx_drop_en;
1486 /* Allocate the maximun number of RX ring hardware descriptor. */
1487 ring_size = sizeof(union i40e_rx_desc) * I40E_MAX_RING_DESC;
1488 ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
1489 rz = i40e_ring_dma_zone_reserve(dev,
1495 i40e_dev_rx_queue_release(rxq);
1496 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX\n");
1500 /* Zero all the descriptors in the ring. */
1501 memset(rz->addr, 0, ring_size);
1503 #ifdef RTE_LIBRTE_XEN_DOM0
1504 rxq->rx_ring_phys_addr = rte_mem_phy2mch(rz->memseg_id, rz->phys_addr);
1506 rxq->rx_ring_phys_addr = (uint64_t)rz->phys_addr;
1509 rxq->rx_ring = (union i40e_rx_desc *)rz->addr;
1511 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1512 len = (uint16_t)(nb_desc + RTE_PMD_I40E_RX_MAX_BURST);
1517 /* Allocate the software ring. */
1519 rte_zmalloc_socket("i40e rx sw ring",
1520 sizeof(struct i40e_rx_entry) * len,
1523 if (!rxq->sw_ring) {
1524 i40e_dev_rx_queue_release(rxq);
1525 PMD_DRV_LOG(ERR, "Failed to allocate memory for SW ring\n");
1529 i40e_reset_rx_queue(rxq);
1531 dev->data->rx_queues[queue_idx] = rxq;
1533 use_def_burst_func = check_rx_burst_bulk_alloc_preconditions(rxq);
1535 if (!use_def_burst_func && !dev->data->scattered_rx) {
1536 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1537 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
1538 "satisfied. Rx Burst Bulk Alloc function will be "
1539 "used on port=%d, queue=%d.\n",
1540 rxq->port_id, rxq->queue_id);
1541 dev->rx_pkt_burst = i40e_recv_pkts_bulk_alloc;
1542 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
1544 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
1545 "not satisfied, Scattered Rx is requested, "
1546 "or RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC is "
1547 "not enabled on port=%d, queue=%d.\n",
1548 rxq->port_id, rxq->queue_id);
1555 i40e_dev_rx_queue_release(void *rxq)
1557 struct i40e_rx_queue *q = (struct i40e_rx_queue *)rxq;
1560 PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL\n");
1564 i40e_rx_queue_release_mbufs(q);
1565 rte_free(q->sw_ring);
1570 i40e_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1572 #define I40E_RXQ_SCAN_INTERVAL 4
1573 volatile union i40e_rx_desc *rxdp;
1574 struct i40e_rx_queue *rxq;
1577 if (unlikely(rx_queue_id >= dev->data->nb_rx_queues)) {
1578 PMD_DRV_LOG(ERR, "Invalid RX queue id %u\n", rx_queue_id);
1582 rxq = dev->data->rx_queues[rx_queue_id];
1583 rxdp = &(rxq->rx_ring[rxq->rx_tail]);
1584 while ((desc < rxq->nb_rx_desc) &&
1585 ((rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
1586 I40E_RXD_QW1_STATUS_MASK) >> I40E_RXD_QW1_STATUS_SHIFT) &
1587 (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
1589 * Check the DD bit of a rx descriptor of each 4 in a group,
1590 * to avoid checking too frequently and downgrading performance
1593 desc += I40E_RXQ_SCAN_INTERVAL;
1594 rxdp += I40E_RXQ_SCAN_INTERVAL;
1595 if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
1596 rxdp = &(rxq->rx_ring[rxq->rx_tail +
1597 desc - rxq->nb_rx_desc]);
1604 i40e_dev_rx_descriptor_done(void *rx_queue, uint16_t offset)
1606 volatile union i40e_rx_desc *rxdp;
1607 struct i40e_rx_queue *rxq = rx_queue;
1611 if (unlikely(offset >= rxq->nb_rx_desc)) {
1612 PMD_DRV_LOG(ERR, "Invalid RX queue id %u\n", offset);
1616 desc = rxq->rx_tail + offset;
1617 if (desc >= rxq->nb_rx_desc)
1618 desc -= rxq->nb_rx_desc;
1620 rxdp = &(rxq->rx_ring[desc]);
1622 ret = !!(((rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
1623 I40E_RXD_QW1_STATUS_MASK) >> I40E_RXD_QW1_STATUS_SHIFT) &
1624 (1 << I40E_RX_DESC_STATUS_DD_SHIFT));
1630 i40e_dev_tx_queue_setup(struct rte_eth_dev *dev,
1633 unsigned int socket_id,
1634 const struct rte_eth_txconf *tx_conf)
1636 struct i40e_vsi *vsi = I40E_DEV_PRIVATE_TO_VSI(dev->data->dev_private);
1637 struct i40e_tx_queue *txq;
1638 const struct rte_memzone *tz;
1640 uint16_t tx_rs_thresh, tx_free_thresh;
1642 if (!vsi || queue_idx >= vsi->nb_qps) {
1643 PMD_DRV_LOG(ERR, "VSI is NULL, or queue index (%u) "
1644 "exceeds the maximum\n", queue_idx);
1645 return I40E_ERR_PARAM;
1648 if (((nb_desc * sizeof(struct i40e_tx_desc)) % I40E_ALIGN) != 0 ||
1649 (nb_desc > I40E_MAX_RING_DESC) ||
1650 (nb_desc < I40E_MIN_RING_DESC)) {
1651 PMD_DRV_LOG(ERR, "Number (%u) of transmit descriptors is "
1652 "invalid\n", nb_desc);
1653 return I40E_ERR_PARAM;
1657 * The following two parameters control the setting of the RS bit on
1658 * transmit descriptors. TX descriptors will have their RS bit set
1659 * after txq->tx_rs_thresh descriptors have been used. The TX
1660 * descriptor ring will be cleaned after txq->tx_free_thresh
1661 * descriptors are used or if the number of descriptors required to
1662 * transmit a packet is greater than the number of free TX descriptors.
1664 * The following constraints must be satisfied:
1665 * - tx_rs_thresh must be greater than 0.
1666 * - tx_rs_thresh must be less than the size of the ring minus 2.
1667 * - tx_rs_thresh must be less than or equal to tx_free_thresh.
1668 * - tx_rs_thresh must be a divisor of the ring size.
1669 * - tx_free_thresh must be greater than 0.
1670 * - tx_free_thresh must be less than the size of the ring minus 3.
1672 * One descriptor in the TX ring is used as a sentinel to avoid a H/W
1673 * race condition, hence the maximum threshold constraints. When set
1674 * to zero use default values.
1676 tx_rs_thresh = (uint16_t)((tx_conf->tx_rs_thresh) ?
1677 tx_conf->tx_rs_thresh : DEFAULT_TX_RS_THRESH);
1678 tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
1679 tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
1680 if (tx_rs_thresh >= (nb_desc - 2)) {
1681 RTE_LOG(ERR, PMD, "tx_rs_thresh must be less than the "
1682 "number of TX descriptors minus 2. "
1683 "(tx_rs_thresh=%u port=%d queue=%d)\n",
1684 (unsigned int)tx_rs_thresh,
1685 (int)dev->data->port_id,
1687 return I40E_ERR_PARAM;
1689 if (tx_free_thresh >= (nb_desc - 3)) {
1690 RTE_LOG(ERR, PMD, "tx_rs_thresh must be less than the "
1691 "tx_free_thresh must be less than the "
1692 "number of TX descriptors minus 3. "
1693 "(tx_free_thresh=%u port=%d queue=%d)\n",
1694 (unsigned int)tx_free_thresh,
1695 (int)dev->data->port_id,
1697 return I40E_ERR_PARAM;
1699 if (tx_rs_thresh > tx_free_thresh) {
1700 RTE_LOG(ERR, PMD, "tx_rs_thresh must be less than or "
1701 "equal to tx_free_thresh. (tx_free_thresh=%u"
1702 " tx_rs_thresh=%u port=%d queue=%d)\n",
1703 (unsigned int)tx_free_thresh,
1704 (unsigned int)tx_rs_thresh,
1705 (int)dev->data->port_id,
1707 return I40E_ERR_PARAM;
1709 if ((nb_desc % tx_rs_thresh) != 0) {
1710 RTE_LOG(ERR, PMD, "tx_rs_thresh must be a divisor of the "
1711 "number of TX descriptors. (tx_rs_thresh=%u"
1712 " port=%d queue=%d)\n",
1713 (unsigned int)tx_rs_thresh,
1714 (int)dev->data->port_id,
1716 return I40E_ERR_PARAM;
1718 if ((tx_rs_thresh > 1) && (tx_conf->tx_thresh.wthresh != 0)) {
1719 RTE_LOG(ERR, PMD, "TX WTHRESH must be set to 0 if "
1720 "tx_rs_thresh is greater than 1. "
1721 "(tx_rs_thresh=%u port=%d queue=%d)\n",
1722 (unsigned int)tx_rs_thresh,
1723 (int)dev->data->port_id,
1725 return I40E_ERR_PARAM;
1728 /* Free memory if needed. */
1729 if (dev->data->tx_queues[queue_idx]) {
1730 i40e_dev_tx_queue_release(dev->data->tx_queues[queue_idx]);
1731 dev->data->tx_queues[queue_idx] = NULL;
1734 /* Allocate the TX queue data structure. */
1735 txq = rte_zmalloc_socket("i40e tx queue",
1736 sizeof(struct i40e_tx_queue),
1740 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
1741 "tx queue structure\n");
1745 /* Allocate TX hardware ring descriptors. */
1746 ring_size = sizeof(struct i40e_tx_desc) * I40E_MAX_RING_DESC;
1747 ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
1748 tz = i40e_ring_dma_zone_reserve(dev,
1754 i40e_dev_tx_queue_release(txq);
1755 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX\n");
1759 txq->nb_tx_desc = nb_desc;
1760 txq->tx_rs_thresh = tx_rs_thresh;
1761 txq->tx_free_thresh = tx_free_thresh;
1762 txq->pthresh = tx_conf->tx_thresh.pthresh;
1763 txq->hthresh = tx_conf->tx_thresh.hthresh;
1764 txq->wthresh = tx_conf->tx_thresh.wthresh;
1765 txq->queue_id = queue_idx;
1766 txq->reg_idx = vsi->base_queue + queue_idx;
1767 txq->port_id = dev->data->port_id;
1768 txq->txq_flags = tx_conf->txq_flags;
1771 #ifdef RTE_LIBRTE_XEN_DOM0
1772 txq->tx_ring_phys_addr = rte_mem_phy2mch(tz->memseg_id, tz->phys_addr);
1774 txq->tx_ring_phys_addr = (uint64_t)tz->phys_addr;
1776 txq->tx_ring = (struct i40e_tx_desc *)tz->addr;
1778 /* Allocate software ring */
1780 rte_zmalloc_socket("i40e tx sw ring",
1781 sizeof(struct i40e_tx_entry) * nb_desc,
1784 if (!txq->sw_ring) {
1785 i40e_dev_tx_queue_release(txq);
1786 PMD_DRV_LOG(ERR, "Failed to allocate memory for SW TX ring\n");
1790 i40e_reset_tx_queue(txq);
1792 dev->data->tx_queues[queue_idx] = txq;
1794 /* Use a simple TX queue without offloads or multi segs if possible */
1795 if (((txq->txq_flags & I40E_SIMPLE_FLAGS) == I40E_SIMPLE_FLAGS) &&
1796 (txq->tx_rs_thresh >= I40E_TX_MAX_BURST)) {
1797 PMD_INIT_LOG(INFO, "Using simple tx path\n");
1798 dev->tx_pkt_burst = i40e_xmit_pkts_simple;
1800 PMD_INIT_LOG(INFO, "Using full-featured tx path\n");
1801 dev->tx_pkt_burst = i40e_xmit_pkts;
1808 i40e_dev_tx_queue_release(void *txq)
1810 struct i40e_tx_queue *q = (struct i40e_tx_queue *)txq;
1813 PMD_DRV_LOG(DEBUG, "Pointer to TX queue is NULL\n");
1817 i40e_tx_queue_release_mbufs(q);
1818 rte_free(q->sw_ring);
1822 static const struct rte_memzone *
1823 i40e_ring_dma_zone_reserve(struct rte_eth_dev *dev,
1824 const char *ring_name,
1829 char z_name[RTE_MEMZONE_NAMESIZE];
1830 const struct rte_memzone *mz;
1832 rte_snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
1833 dev->driver->pci_drv.name, ring_name,
1834 dev->data->port_id, queue_id);
1835 mz = rte_memzone_lookup(z_name);
1839 #ifdef RTE_LIBRTE_XEN_DOM0
1840 return rte_memzone_reserve_bounded(z_name, ring_size,
1841 socket_id, 0, I40E_ALIGN, RTE_PGSIZE_2M);
1843 return rte_memzone_reserve_aligned(z_name, ring_size,
1844 socket_id, 0, I40E_ALIGN);
1849 i40e_rx_queue_release_mbufs(struct i40e_rx_queue *rxq)
1853 if (!rxq || !rxq->sw_ring) {
1854 PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL\n");
1858 for (i = 0; i < rxq->nb_rx_desc; i++) {
1859 if (rxq->sw_ring[i].mbuf) {
1860 rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
1861 rxq->sw_ring[i].mbuf = NULL;
1864 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1865 if (rxq->rx_nb_avail == 0)
1867 for (i = 0; i < rxq->rx_nb_avail; i++) {
1868 struct rte_mbuf *mbuf;
1870 mbuf = rxq->rx_stage[rxq->rx_next_avail + i];
1871 rte_pktmbuf_free_seg(mbuf);
1873 rxq->rx_nb_avail = 0;
1874 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
1878 i40e_reset_rx_queue(struct i40e_rx_queue *rxq)
1883 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1884 if (check_rx_burst_bulk_alloc_preconditions(rxq) == 0)
1885 len = (uint16_t)(rxq->nb_rx_desc + RTE_PMD_I40E_RX_MAX_BURST);
1887 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
1888 len = rxq->nb_rx_desc;
1890 for (i = 0; i < len * sizeof(union i40e_rx_desc); i++)
1891 ((volatile char *)rxq->rx_ring)[i] = 0;
1893 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1894 memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
1895 for (i = 0; i < RTE_PMD_I40E_RX_MAX_BURST; ++i)
1896 rxq->sw_ring[rxq->nb_rx_desc + i].mbuf = &rxq->fake_mbuf;
1898 rxq->rx_nb_avail = 0;
1899 rxq->rx_next_avail = 0;
1900 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
1901 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
1903 rxq->nb_rx_hold = 0;
1904 rxq->pkt_first_seg = NULL;
1905 rxq->pkt_last_seg = NULL;
1909 i40e_tx_queue_release_mbufs(struct i40e_tx_queue *txq)
1913 if (!txq || !txq->sw_ring) {
1914 PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL\n");
1918 for (i = 0; i < txq->nb_tx_desc; i++) {
1919 if (txq->sw_ring[i].mbuf) {
1920 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
1921 txq->sw_ring[i].mbuf = NULL;
1927 i40e_reset_tx_queue(struct i40e_tx_queue *txq)
1929 struct i40e_tx_entry *txe;
1930 uint16_t i, prev, size;
1933 PMD_DRV_LOG(DEBUG, "Pointer to txq is NULL\n");
1938 size = sizeof(struct i40e_tx_desc) * txq->nb_tx_desc;
1939 for (i = 0; i < size; i++)
1940 ((volatile char *)txq->tx_ring)[i] = 0;
1942 prev = (uint16_t)(txq->nb_tx_desc - 1);
1943 for (i = 0; i < txq->nb_tx_desc; i++) {
1944 volatile struct i40e_tx_desc *txd = &txq->tx_ring[i];
1946 txd[i].cmd_type_offset_bsz =
1947 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE);
1950 txe[prev].next_id = i;
1954 txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
1955 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
1958 txq->nb_tx_used = 0;
1960 txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
1961 txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
1964 /* Init the TX queue in hardware */
1966 i40e_tx_queue_init(struct i40e_tx_queue *txq)
1968 enum i40e_status_code err = I40E_SUCCESS;
1969 struct i40e_vsi *vsi = txq->vsi;
1970 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1971 uint16_t pf_q = txq->reg_idx;
1972 struct i40e_hmc_obj_txq tx_ctx;
1975 /* clear the context structure first */
1976 memset(&tx_ctx, 0, sizeof(tx_ctx));
1977 tx_ctx.new_context = 1;
1978 tx_ctx.base = txq->tx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
1979 tx_ctx.qlen = txq->nb_tx_desc;
1980 tx_ctx.rdylist = rte_le_to_cpu_16(vsi->info.qs_handle[0]);
1982 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
1983 if (err != I40E_SUCCESS) {
1984 PMD_DRV_LOG(ERR, "Failure of clean lan tx queue context\n");
1988 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
1989 if (err != I40E_SUCCESS) {
1990 PMD_DRV_LOG(ERR, "Failure of set lan tx queue context\n");
1994 /* Now associate this queue with this PCI function */
1995 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
1996 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
1997 I40E_QTX_CTL_PF_INDX_MASK);
1998 I40E_WRITE_REG(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
1999 I40E_WRITE_FLUSH(hw);
2001 txq->qtx_tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2007 i40e_alloc_rx_queue_mbufs(struct i40e_rx_queue *rxq)
2009 struct i40e_rx_entry *rxe = rxq->sw_ring;
2013 for (i = 0; i < rxq->nb_rx_desc; i++) {
2014 volatile union i40e_rx_desc *rxd;
2015 struct rte_mbuf *mbuf = rte_rxmbuf_alloc(rxq->mp);
2017 if (unlikely(!mbuf)) {
2018 PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX\n");
2022 rte_mbuf_refcnt_set(mbuf, 1);
2023 mbuf->type = RTE_MBUF_PKT;
2024 mbuf->pkt.next = NULL;
2025 mbuf->pkt.data = (char *)mbuf->buf_addr + RTE_PKTMBUF_HEADROOM;
2026 mbuf->pkt.nb_segs = 1;
2027 mbuf->pkt.in_port = rxq->port_id;
2030 rte_cpu_to_le_64(RTE_MBUF_DATA_DMA_ADDR_DEFAULT(mbuf));
2032 rxd = &rxq->rx_ring[i];
2033 rxd->read.pkt_addr = dma_addr;
2034 rxd->read.hdr_addr = dma_addr;
2035 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2036 rxd->read.rsvd1 = 0;
2037 rxd->read.rsvd2 = 0;
2038 #endif /* RTE_LIBRTE_I40E_16BYTE_RX_DESC */
2047 * Calculate the buffer length, and check the jumbo frame
2048 * and maximum packet length.
2051 i40e_rx_queue_config(struct i40e_rx_queue *rxq)
2053 struct i40e_pf *pf = I40E_VSI_TO_PF(rxq->vsi);
2054 struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
2055 struct rte_eth_dev_data *data = pf->dev_data;
2056 struct rte_pktmbuf_pool_private *mbp_priv =
2057 rte_mempool_get_priv(rxq->mp);
2058 uint16_t buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
2059 RTE_PKTMBUF_HEADROOM);
2062 switch (pf->flags & (I40E_FLAG_HEADER_SPLIT_DISABLED |
2063 I40E_FLAG_HEADER_SPLIT_ENABLED)) {
2064 case I40E_FLAG_HEADER_SPLIT_ENABLED: /* Not supported */
2065 rxq->rx_hdr_len = RTE_ALIGN(I40E_RXBUF_SZ_1024,
2066 (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
2067 rxq->rx_buf_len = RTE_ALIGN(I40E_RXBUF_SZ_2048,
2068 (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
2069 rxq->hs_mode = i40e_header_split_enabled;
2071 case I40E_FLAG_HEADER_SPLIT_DISABLED:
2073 rxq->rx_hdr_len = 0;
2074 rxq->rx_buf_len = RTE_ALIGN(buf_size,
2075 (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
2076 rxq->hs_mode = i40e_header_split_none;
2080 len = hw->func_caps.rx_buf_chain_len * rxq->rx_buf_len;
2081 rxq->max_pkt_len = RTE_MIN(len, data->dev_conf.rxmode.max_rx_pkt_len);
2082 if (data->dev_conf.rxmode.jumbo_frame == 1) {
2083 if (rxq->max_pkt_len <= ETHER_MAX_LEN ||
2084 rxq->max_pkt_len > I40E_FRAME_SIZE_MAX) {
2085 PMD_DRV_LOG(ERR, "maximum packet length must "
2086 "be larger than %u and smaller than %u,"
2087 "as jumbo frame is enabled\n",
2088 (uint32_t)ETHER_MAX_LEN,
2089 (uint32_t)I40E_FRAME_SIZE_MAX);
2090 return I40E_ERR_CONFIG;
2093 if (rxq->max_pkt_len < ETHER_MIN_LEN ||
2094 rxq->max_pkt_len > ETHER_MAX_LEN) {
2095 PMD_DRV_LOG(ERR, "maximum packet length must be "
2096 "larger than %u and smaller than %u, "
2097 "as jumbo frame is disabled\n",
2098 (uint32_t)ETHER_MIN_LEN,
2099 (uint32_t)ETHER_MAX_LEN);
2100 return I40E_ERR_CONFIG;
2107 /* Init the RX queue in hardware */
2109 i40e_rx_queue_init(struct i40e_rx_queue *rxq)
2111 int err = I40E_SUCCESS;
2112 struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
2113 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(rxq->vsi);
2114 struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
2115 uint16_t pf_q = rxq->reg_idx;
2117 struct i40e_hmc_obj_rxq rx_ctx;
2118 struct rte_pktmbuf_pool_private *mbp_priv;
2120 err = i40e_rx_queue_config(rxq);
2122 PMD_DRV_LOG(ERR, "Failed to config RX queue\n");
2126 /* Clear the context structure first */
2127 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
2128 rx_ctx.dbuff = rxq->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
2129 rx_ctx.hbuff = rxq->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
2131 rx_ctx.base = rxq->rx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
2132 rx_ctx.qlen = rxq->nb_rx_desc;
2133 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2136 rx_ctx.dtype = rxq->hs_mode;
2138 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_ALL;
2140 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
2141 rx_ctx.rxmax = rxq->max_pkt_len;
2142 rx_ctx.tphrdesc_ena = 1;
2143 rx_ctx.tphwdesc_ena = 1;
2144 rx_ctx.tphdata_ena = 1;
2145 rx_ctx.tphhead_ena = 1;
2146 rx_ctx.lrxqthresh = 2;
2147 rx_ctx.crcstrip = (rxq->crc_len == 0) ? 1 : 0;
2152 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
2153 if (err != I40E_SUCCESS) {
2154 PMD_DRV_LOG(ERR, "Failed to clear LAN RX queue context\n");
2157 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
2158 if (err != I40E_SUCCESS) {
2159 PMD_DRV_LOG(ERR, "Failed to set LAN RX queue context\n");
2163 rxq->qrx_tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
2164 err = i40e_alloc_rx_queue_mbufs(rxq);
2165 mbp_priv = rte_mempool_get_priv(rxq->mp);
2166 buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
2167 RTE_PKTMBUF_HEADROOM);
2169 /* Check if scattered RX needs to be used. */
2170 if ((rxq->max_pkt_len + 2 * I40E_VLAN_TAG_SIZE) > buf_size) {
2171 dev_data->scattered_rx = 1;
2172 dev->rx_pkt_burst = i40e_recv_scattered_pkts;
2177 /* Init the RX tail regieter. */
2178 I40E_PCI_REG_WRITE(rxq->qrx_tail, 0);
2179 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
2182 PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf\n");
2188 i40e_dev_clear_queues(struct rte_eth_dev *dev)
2192 PMD_INIT_FUNC_TRACE();
2194 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2195 i40e_tx_queue_release_mbufs(dev->data->tx_queues[i]);
2196 i40e_reset_tx_queue(dev->data->tx_queues[i]);
2199 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2200 i40e_rx_queue_release_mbufs(dev->data->rx_queues[i]);
2201 i40e_reset_rx_queue(dev->data->rx_queues[i]);