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 ( \
80 PKT_TX_OUTER_IP_CKSUM)
82 static uint16_t i40e_xmit_pkts_simple(void *tx_queue
,
83 struct rte_mbuf
**tx_pkts
,
87 i40e_rxd_to_vlan_tci(struct rte_mbuf
*mb
, volatile union i40e_rx_desc
*rxdp
)
89 if (rte_le_to_cpu_64(rxdp
->wb
.qword1
.status_error_len
) &
90 (1 << I40E_RX_DESC_STATUS_L2TAG1P_SHIFT
)) {
91 mb
->ol_flags
|= PKT_RX_VLAN_PKT
| PKT_RX_VLAN_STRIPPED
;
93 rte_le_to_cpu_16(rxdp
->wb
.qword0
.lo_dword
.l2tag1
);
94 PMD_RX_LOG(DEBUG
, "Descriptor l2tag1: %u",
95 rte_le_to_cpu_16(rxdp
->wb
.qword0
.lo_dword
.l2tag1
));
99 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
100 if (rte_le_to_cpu_16(rxdp
->wb
.qword2
.ext_status
) &
101 (1 << I40E_RX_DESC_EXT_STATUS_L2TAG2P_SHIFT
)) {
102 mb
->ol_flags
|= PKT_RX_QINQ_STRIPPED
;
103 mb
->vlan_tci_outer
= mb
->vlan_tci
;
104 mb
->vlan_tci
= rte_le_to_cpu_16(rxdp
->wb
.qword2
.l2tag2_2
);
105 PMD_RX_LOG(DEBUG
, "Descriptor l2tag2_1: %u, l2tag2_2: %u",
106 rte_le_to_cpu_16(rxdp
->wb
.qword2
.l2tag2_1
),
107 rte_le_to_cpu_16(rxdp
->wb
.qword2
.l2tag2_2
));
109 mb
->vlan_tci_outer
= 0;
112 PMD_RX_LOG(DEBUG
, "Mbuf vlan_tci: %u, vlan_tci_outer: %u",
113 mb
->vlan_tci
, mb
->vlan_tci_outer
);
116 /* Translate the rx descriptor status to pkt flags */
117 static inline uint64_t
118 i40e_rxd_status_to_pkt_flags(uint64_t qword
)
122 /* Check if RSS_HASH */
123 flags
= (((qword
>> I40E_RX_DESC_STATUS_FLTSTAT_SHIFT
) &
124 I40E_RX_DESC_FLTSTAT_RSS_HASH
) ==
125 I40E_RX_DESC_FLTSTAT_RSS_HASH
) ? PKT_RX_RSS_HASH
: 0;
127 /* Check if FDIR Match */
128 flags
|= (qword
& (1 << I40E_RX_DESC_STATUS_FLM_SHIFT
) ?
134 static inline uint64_t
135 i40e_rxd_error_to_pkt_flags(uint64_t qword
)
138 uint64_t error_bits
= (qword
>> I40E_RXD_QW1_ERROR_SHIFT
);
140 #define I40E_RX_ERR_BITS 0x3f
141 if (likely((error_bits
& I40E_RX_ERR_BITS
) == 0))
143 if (unlikely(error_bits
& (1 << I40E_RX_DESC_ERROR_IPE_SHIFT
)))
144 flags
|= PKT_RX_IP_CKSUM_BAD
;
146 flags
|= PKT_RX_IP_CKSUM_GOOD
;
148 if (unlikely(error_bits
& (1 << I40E_RX_DESC_ERROR_L4E_SHIFT
)))
149 flags
|= PKT_RX_L4_CKSUM_BAD
;
151 flags
|= PKT_RX_L4_CKSUM_GOOD
;
153 if (unlikely(error_bits
& (1 << I40E_RX_DESC_ERROR_EIPE_SHIFT
)))
154 flags
|= PKT_RX_EIP_CKSUM_BAD
;
159 /* Function to check and set the ieee1588 timesync index and get the
162 #ifdef RTE_LIBRTE_IEEE1588
163 static inline uint64_t
164 i40e_get_iee15888_flags(struct rte_mbuf
*mb
, uint64_t qword
)
166 uint64_t pkt_flags
= 0;
167 uint16_t tsyn
= (qword
& (I40E_RXD_QW1_STATUS_TSYNVALID_MASK
168 | I40E_RXD_QW1_STATUS_TSYNINDX_MASK
))
169 >> I40E_RX_DESC_STATUS_TSYNINDX_SHIFT
;
171 if ((mb
->packet_type
& RTE_PTYPE_L2_MASK
)
172 == RTE_PTYPE_L2_ETHER_TIMESYNC
)
173 pkt_flags
= PKT_RX_IEEE1588_PTP
;
175 pkt_flags
|= PKT_RX_IEEE1588_TMST
;
176 mb
->timesync
= tsyn
& 0x03;
183 #define I40E_RX_DESC_EXT_STATUS_FLEXBH_MASK 0x03
184 #define I40E_RX_DESC_EXT_STATUS_FLEXBH_FD_ID 0x01
185 #define I40E_RX_DESC_EXT_STATUS_FLEXBH_FLEX 0x02
186 #define I40E_RX_DESC_EXT_STATUS_FLEXBL_MASK 0x03
187 #define I40E_RX_DESC_EXT_STATUS_FLEXBL_FLEX 0x01
189 static inline uint64_t
190 i40e_rxd_build_fdir(volatile union i40e_rx_desc
*rxdp
, struct rte_mbuf
*mb
)
193 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
194 uint16_t flexbh
, flexbl
;
196 flexbh
= (rte_le_to_cpu_32(rxdp
->wb
.qword2
.ext_status
) >>
197 I40E_RX_DESC_EXT_STATUS_FLEXBH_SHIFT
) &
198 I40E_RX_DESC_EXT_STATUS_FLEXBH_MASK
;
199 flexbl
= (rte_le_to_cpu_32(rxdp
->wb
.qword2
.ext_status
) >>
200 I40E_RX_DESC_EXT_STATUS_FLEXBL_SHIFT
) &
201 I40E_RX_DESC_EXT_STATUS_FLEXBL_MASK
;
204 if (flexbh
== I40E_RX_DESC_EXT_STATUS_FLEXBH_FD_ID
) {
206 rte_le_to_cpu_32(rxdp
->wb
.qword3
.hi_dword
.fd_id
);
207 flags
|= PKT_RX_FDIR_ID
;
208 } else if (flexbh
== I40E_RX_DESC_EXT_STATUS_FLEXBH_FLEX
) {
210 rte_le_to_cpu_32(rxdp
->wb
.qword3
.hi_dword
.flex_bytes_hi
);
211 flags
|= PKT_RX_FDIR_FLX
;
213 if (flexbl
== I40E_RX_DESC_EXT_STATUS_FLEXBL_FLEX
) {
215 rte_le_to_cpu_32(rxdp
->wb
.qword3
.lo_dword
.flex_bytes_lo
);
216 flags
|= PKT_RX_FDIR_FLX
;
220 rte_le_to_cpu_32(rxdp
->wb
.qword0
.hi_dword
.fd_id
);
221 flags
|= PKT_RX_FDIR_ID
;
227 i40e_parse_tunneling_params(uint64_t ol_flags
,
228 union i40e_tx_offload tx_offload
,
229 uint32_t *cd_tunneling
)
231 /* EIPT: External (outer) IP header type */
232 if (ol_flags
& PKT_TX_OUTER_IP_CKSUM
)
233 *cd_tunneling
|= I40E_TX_CTX_EXT_IP_IPV4
;
234 else if (ol_flags
& PKT_TX_OUTER_IPV4
)
235 *cd_tunneling
|= I40E_TX_CTX_EXT_IP_IPV4_NO_CSUM
;
236 else if (ol_flags
& PKT_TX_OUTER_IPV6
)
237 *cd_tunneling
|= I40E_TX_CTX_EXT_IP_IPV6
;
239 /* EIPLEN: External (outer) IP header length, in DWords */
240 *cd_tunneling
|= (tx_offload
.outer_l3_len
>> 2) <<
241 I40E_TXD_CTX_QW0_EXT_IPLEN_SHIFT
;
243 /* L4TUNT: L4 Tunneling Type */
244 switch (ol_flags
& PKT_TX_TUNNEL_MASK
) {
245 case PKT_TX_TUNNEL_IPIP
:
246 /* for non UDP / GRE tunneling, set to 00b */
248 case PKT_TX_TUNNEL_VXLAN
:
249 case PKT_TX_TUNNEL_GENEVE
:
250 *cd_tunneling
|= I40E_TXD_CTX_UDP_TUNNELING
;
252 case PKT_TX_TUNNEL_GRE
:
253 *cd_tunneling
|= I40E_TXD_CTX_GRE_TUNNELING
;
256 PMD_TX_LOG(ERR
, "Tunnel type not supported\n");
260 /* L4TUNLEN: L4 Tunneling Length, in Words
262 * We depend on app to set rte_mbuf.l2_len correctly.
263 * For IP in GRE it should be set to the length of the GRE
265 * for MAC in GRE or MAC in UDP it should be set to the length
266 * of the GRE or UDP headers plus the inner MAC up to including
267 * its last Ethertype.
269 *cd_tunneling
|= (tx_offload
.l2_len
>> 1) <<
270 I40E_TXD_CTX_QW0_NATLEN_SHIFT
;
274 i40e_txd_enable_checksum(uint64_t ol_flags
,
277 union i40e_tx_offload tx_offload
)
280 if (ol_flags
& PKT_TX_TUNNEL_MASK
)
281 *td_offset
|= (tx_offload
.outer_l2_len
>> 1)
282 << I40E_TX_DESC_LENGTH_MACLEN_SHIFT
;
284 *td_offset
|= (tx_offload
.l2_len
>> 1)
285 << I40E_TX_DESC_LENGTH_MACLEN_SHIFT
;
287 /* Enable L3 checksum offloads */
288 if (ol_flags
& PKT_TX_IP_CKSUM
) {
289 *td_cmd
|= I40E_TX_DESC_CMD_IIPT_IPV4_CSUM
;
290 *td_offset
|= (tx_offload
.l3_len
>> 2)
291 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT
;
292 } else if (ol_flags
& PKT_TX_IPV4
) {
293 *td_cmd
|= I40E_TX_DESC_CMD_IIPT_IPV4
;
294 *td_offset
|= (tx_offload
.l3_len
>> 2)
295 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT
;
296 } else if (ol_flags
& PKT_TX_IPV6
) {
297 *td_cmd
|= I40E_TX_DESC_CMD_IIPT_IPV6
;
298 *td_offset
|= (tx_offload
.l3_len
>> 2)
299 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT
;
302 if (ol_flags
& PKT_TX_TCP_SEG
) {
303 *td_cmd
|= I40E_TX_DESC_CMD_L4T_EOFT_TCP
;
304 *td_offset
|= (tx_offload
.l4_len
>> 2)
305 << I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT
;
309 /* Enable L4 checksum offloads */
310 switch (ol_flags
& PKT_TX_L4_MASK
) {
311 case PKT_TX_TCP_CKSUM
:
312 *td_cmd
|= I40E_TX_DESC_CMD_L4T_EOFT_TCP
;
313 *td_offset
|= (sizeof(struct tcp_hdr
) >> 2) <<
314 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT
;
316 case PKT_TX_SCTP_CKSUM
:
317 *td_cmd
|= I40E_TX_DESC_CMD_L4T_EOFT_SCTP
;
318 *td_offset
|= (sizeof(struct sctp_hdr
) >> 2) <<
319 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT
;
321 case PKT_TX_UDP_CKSUM
:
322 *td_cmd
|= I40E_TX_DESC_CMD_L4T_EOFT_UDP
;
323 *td_offset
|= (sizeof(struct udp_hdr
) >> 2) <<
324 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT
;
331 /* Construct the tx flags */
332 static inline uint64_t
333 i40e_build_ctob(uint32_t td_cmd
,
338 return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA
|
339 ((uint64_t)td_cmd
<< I40E_TXD_QW1_CMD_SHIFT
) |
340 ((uint64_t)td_offset
<< I40E_TXD_QW1_OFFSET_SHIFT
) |
341 ((uint64_t)size
<< I40E_TXD_QW1_TX_BUF_SZ_SHIFT
) |
342 ((uint64_t)td_tag
<< I40E_TXD_QW1_L2TAG1_SHIFT
));
346 i40e_xmit_cleanup(struct i40e_tx_queue
*txq
)
348 struct i40e_tx_entry
*sw_ring
= txq
->sw_ring
;
349 volatile struct i40e_tx_desc
*txd
= txq
->tx_ring
;
350 uint16_t last_desc_cleaned
= txq
->last_desc_cleaned
;
351 uint16_t nb_tx_desc
= txq
->nb_tx_desc
;
352 uint16_t desc_to_clean_to
;
353 uint16_t nb_tx_to_clean
;
355 desc_to_clean_to
= (uint16_t)(last_desc_cleaned
+ txq
->tx_rs_thresh
);
356 if (desc_to_clean_to
>= nb_tx_desc
)
357 desc_to_clean_to
= (uint16_t)(desc_to_clean_to
- nb_tx_desc
);
359 desc_to_clean_to
= sw_ring
[desc_to_clean_to
].last_id
;
360 if ((txd
[desc_to_clean_to
].cmd_type_offset_bsz
&
361 rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK
)) !=
362 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE
)) {
363 PMD_TX_FREE_LOG(DEBUG
, "TX descriptor %4u is not done "
364 "(port=%d queue=%d)", desc_to_clean_to
,
365 txq
->port_id
, txq
->queue_id
);
369 if (last_desc_cleaned
> desc_to_clean_to
)
370 nb_tx_to_clean
= (uint16_t)((nb_tx_desc
- last_desc_cleaned
) +
373 nb_tx_to_clean
= (uint16_t)(desc_to_clean_to
-
376 txd
[desc_to_clean_to
].cmd_type_offset_bsz
= 0;
378 txq
->last_desc_cleaned
= desc_to_clean_to
;
379 txq
->nb_tx_free
= (uint16_t)(txq
->nb_tx_free
+ nb_tx_to_clean
);
385 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
386 check_rx_burst_bulk_alloc_preconditions(struct i40e_rx_queue
*rxq
)
388 check_rx_burst_bulk_alloc_preconditions(__rte_unused
struct i40e_rx_queue
*rxq
)
393 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
394 if (!(rxq
->rx_free_thresh
>= RTE_PMD_I40E_RX_MAX_BURST
)) {
395 PMD_INIT_LOG(DEBUG
, "Rx Burst Bulk Alloc Preconditions: "
396 "rxq->rx_free_thresh=%d, "
397 "RTE_PMD_I40E_RX_MAX_BURST=%d",
398 rxq
->rx_free_thresh
, RTE_PMD_I40E_RX_MAX_BURST
);
400 } else if (!(rxq
->rx_free_thresh
< rxq
->nb_rx_desc
)) {
401 PMD_INIT_LOG(DEBUG
, "Rx Burst Bulk Alloc Preconditions: "
402 "rxq->rx_free_thresh=%d, "
403 "rxq->nb_rx_desc=%d",
404 rxq
->rx_free_thresh
, rxq
->nb_rx_desc
);
406 } else if (rxq
->nb_rx_desc
% rxq
->rx_free_thresh
!= 0) {
407 PMD_INIT_LOG(DEBUG
, "Rx Burst Bulk Alloc Preconditions: "
408 "rxq->nb_rx_desc=%d, "
409 "rxq->rx_free_thresh=%d",
410 rxq
->nb_rx_desc
, rxq
->rx_free_thresh
);
412 } else if (!(rxq
->nb_rx_desc
< (I40E_MAX_RING_DESC
-
413 RTE_PMD_I40E_RX_MAX_BURST
))) {
414 PMD_INIT_LOG(DEBUG
, "Rx Burst Bulk Alloc Preconditions: "
415 "rxq->nb_rx_desc=%d, "
416 "I40E_MAX_RING_DESC=%d, "
417 "RTE_PMD_I40E_RX_MAX_BURST=%d",
418 rxq
->nb_rx_desc
, I40E_MAX_RING_DESC
,
419 RTE_PMD_I40E_RX_MAX_BURST
);
429 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
430 #define I40E_LOOK_AHEAD 8
431 #if (I40E_LOOK_AHEAD != 8)
432 #error "PMD I40E: I40E_LOOK_AHEAD must be 8\n"
435 i40e_rx_scan_hw_ring(struct i40e_rx_queue
*rxq
)
437 volatile union i40e_rx_desc
*rxdp
;
438 struct i40e_rx_entry
*rxep
;
443 int32_t s
[I40E_LOOK_AHEAD
], nb_dd
;
444 int32_t i
, j
, nb_rx
= 0;
447 rxdp
= &rxq
->rx_ring
[rxq
->rx_tail
];
448 rxep
= &rxq
->sw_ring
[rxq
->rx_tail
];
450 qword1
= rte_le_to_cpu_64(rxdp
->wb
.qword1
.status_error_len
);
451 rx_status
= (qword1
& I40E_RXD_QW1_STATUS_MASK
) >>
452 I40E_RXD_QW1_STATUS_SHIFT
;
454 /* Make sure there is at least 1 packet to receive */
455 if (!(rx_status
& (1 << I40E_RX_DESC_STATUS_DD_SHIFT
)))
459 * Scan LOOK_AHEAD descriptors at a time to determine which
460 * descriptors reference packets that are ready to be received.
462 for (i
= 0; i
< RTE_PMD_I40E_RX_MAX_BURST
; i
+=I40E_LOOK_AHEAD
,
463 rxdp
+= I40E_LOOK_AHEAD
, rxep
+= I40E_LOOK_AHEAD
) {
464 /* Read desc statuses backwards to avoid race condition */
465 for (j
= I40E_LOOK_AHEAD
- 1; j
>= 0; j
--) {
466 qword1
= rte_le_to_cpu_64(\
467 rxdp
[j
].wb
.qword1
.status_error_len
);
468 s
[j
] = (qword1
& I40E_RXD_QW1_STATUS_MASK
) >>
469 I40E_RXD_QW1_STATUS_SHIFT
;
474 /* Compute how many status bits were set */
475 for (j
= 0, nb_dd
= 0; j
< I40E_LOOK_AHEAD
; j
++)
476 nb_dd
+= s
[j
] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT
);
480 /* Translate descriptor info to mbuf parameters */
481 for (j
= 0; j
< nb_dd
; j
++) {
483 qword1
= rte_le_to_cpu_64(\
484 rxdp
[j
].wb
.qword1
.status_error_len
);
485 pkt_len
= ((qword1
& I40E_RXD_QW1_LENGTH_PBUF_MASK
) >>
486 I40E_RXD_QW1_LENGTH_PBUF_SHIFT
) - rxq
->crc_len
;
487 mb
->data_len
= pkt_len
;
488 mb
->pkt_len
= pkt_len
;
490 i40e_rxd_to_vlan_tci(mb
, &rxdp
[j
]);
491 pkt_flags
= i40e_rxd_status_to_pkt_flags(qword1
);
492 pkt_flags
|= i40e_rxd_error_to_pkt_flags(qword1
);
494 i40e_rxd_pkt_type_mapping((uint8_t)((qword1
&
495 I40E_RXD_QW1_PTYPE_MASK
) >>
496 I40E_RXD_QW1_PTYPE_SHIFT
));
497 if (pkt_flags
& PKT_RX_RSS_HASH
)
498 mb
->hash
.rss
= rte_le_to_cpu_32(\
499 rxdp
[j
].wb
.qword0
.hi_dword
.rss
);
500 if (pkt_flags
& PKT_RX_FDIR
)
501 pkt_flags
|= i40e_rxd_build_fdir(&rxdp
[j
], mb
);
503 #ifdef RTE_LIBRTE_IEEE1588
504 pkt_flags
|= i40e_get_iee15888_flags(mb
, qword1
);
506 mb
->ol_flags
|= pkt_flags
;
510 for (j
= 0; j
< I40E_LOOK_AHEAD
; j
++)
511 rxq
->rx_stage
[i
+ j
] = rxep
[j
].mbuf
;
513 if (nb_dd
!= I40E_LOOK_AHEAD
)
517 /* Clear software ring entries */
518 for (i
= 0; i
< nb_rx
; i
++)
519 rxq
->sw_ring
[rxq
->rx_tail
+ i
].mbuf
= NULL
;
524 static inline uint16_t
525 i40e_rx_fill_from_stage(struct i40e_rx_queue
*rxq
,
526 struct rte_mbuf
**rx_pkts
,
530 struct rte_mbuf
**stage
= &rxq
->rx_stage
[rxq
->rx_next_avail
];
532 nb_pkts
= (uint16_t)RTE_MIN(nb_pkts
, rxq
->rx_nb_avail
);
534 for (i
= 0; i
< nb_pkts
; i
++)
535 rx_pkts
[i
] = stage
[i
];
537 rxq
->rx_nb_avail
= (uint16_t)(rxq
->rx_nb_avail
- nb_pkts
);
538 rxq
->rx_next_avail
= (uint16_t)(rxq
->rx_next_avail
+ nb_pkts
);
544 i40e_rx_alloc_bufs(struct i40e_rx_queue
*rxq
)
546 volatile union i40e_rx_desc
*rxdp
;
547 struct i40e_rx_entry
*rxep
;
549 uint16_t alloc_idx
, i
;
553 /* Allocate buffers in bulk */
554 alloc_idx
= (uint16_t)(rxq
->rx_free_trigger
-
555 (rxq
->rx_free_thresh
- 1));
556 rxep
= &(rxq
->sw_ring
[alloc_idx
]);
557 diag
= rte_mempool_get_bulk(rxq
->mp
, (void *)rxep
,
558 rxq
->rx_free_thresh
);
559 if (unlikely(diag
!= 0)) {
560 PMD_DRV_LOG(ERR
, "Failed to get mbufs in bulk");
564 rxdp
= &rxq
->rx_ring
[alloc_idx
];
565 for (i
= 0; i
< rxq
->rx_free_thresh
; i
++) {
566 if (likely(i
< (rxq
->rx_free_thresh
- 1)))
567 /* Prefetch next mbuf */
568 rte_prefetch0(rxep
[i
+ 1].mbuf
);
571 rte_mbuf_refcnt_set(mb
, 1);
573 mb
->data_off
= RTE_PKTMBUF_HEADROOM
;
575 mb
->port
= rxq
->port_id
;
576 dma_addr
= rte_cpu_to_le_64(\
577 rte_mbuf_data_dma_addr_default(mb
));
578 rxdp
[i
].read
.hdr_addr
= 0;
579 rxdp
[i
].read
.pkt_addr
= dma_addr
;
582 /* Update rx tail regsiter */
584 I40E_PCI_REG_WRITE(rxq
->qrx_tail
, rxq
->rx_free_trigger
);
586 rxq
->rx_free_trigger
=
587 (uint16_t)(rxq
->rx_free_trigger
+ rxq
->rx_free_thresh
);
588 if (rxq
->rx_free_trigger
>= rxq
->nb_rx_desc
)
589 rxq
->rx_free_trigger
= (uint16_t)(rxq
->rx_free_thresh
- 1);
594 static inline uint16_t
595 rx_recv_pkts(void *rx_queue
, struct rte_mbuf
**rx_pkts
, uint16_t nb_pkts
)
597 struct i40e_rx_queue
*rxq
= (struct i40e_rx_queue
*)rx_queue
;
603 if (rxq
->rx_nb_avail
)
604 return i40e_rx_fill_from_stage(rxq
, rx_pkts
, nb_pkts
);
606 nb_rx
= (uint16_t)i40e_rx_scan_hw_ring(rxq
);
607 rxq
->rx_next_avail
= 0;
608 rxq
->rx_nb_avail
= nb_rx
;
609 rxq
->rx_tail
= (uint16_t)(rxq
->rx_tail
+ nb_rx
);
611 if (rxq
->rx_tail
> rxq
->rx_free_trigger
) {
612 if (i40e_rx_alloc_bufs(rxq
) != 0) {
615 PMD_RX_LOG(DEBUG
, "Rx mbuf alloc failed for "
616 "port_id=%u, queue_id=%u",
617 rxq
->port_id
, rxq
->queue_id
);
618 rxq
->rx_nb_avail
= 0;
619 rxq
->rx_tail
= (uint16_t)(rxq
->rx_tail
- nb_rx
);
620 for (i
= 0, j
= rxq
->rx_tail
; i
< nb_rx
; i
++, j
++)
621 rxq
->sw_ring
[j
].mbuf
= rxq
->rx_stage
[i
];
627 if (rxq
->rx_tail
>= rxq
->nb_rx_desc
)
630 if (rxq
->rx_nb_avail
)
631 return i40e_rx_fill_from_stage(rxq
, rx_pkts
, nb_pkts
);
637 i40e_recv_pkts_bulk_alloc(void *rx_queue
,
638 struct rte_mbuf
**rx_pkts
,
641 uint16_t nb_rx
= 0, n
, count
;
643 if (unlikely(nb_pkts
== 0))
646 if (likely(nb_pkts
<= RTE_PMD_I40E_RX_MAX_BURST
))
647 return rx_recv_pkts(rx_queue
, rx_pkts
, nb_pkts
);
650 n
= RTE_MIN(nb_pkts
, RTE_PMD_I40E_RX_MAX_BURST
);
651 count
= rx_recv_pkts(rx_queue
, &rx_pkts
[nb_rx
], n
);
652 nb_rx
= (uint16_t)(nb_rx
+ count
);
653 nb_pkts
= (uint16_t)(nb_pkts
- count
);
662 i40e_recv_pkts_bulk_alloc(void __rte_unused
*rx_queue
,
663 struct rte_mbuf __rte_unused
**rx_pkts
,
664 uint16_t __rte_unused nb_pkts
)
668 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
671 i40e_recv_pkts(void *rx_queue
, struct rte_mbuf
**rx_pkts
, uint16_t nb_pkts
)
673 struct i40e_rx_queue
*rxq
;
674 volatile union i40e_rx_desc
*rx_ring
;
675 volatile union i40e_rx_desc
*rxdp
;
676 union i40e_rx_desc rxd
;
677 struct i40e_rx_entry
*sw_ring
;
678 struct i40e_rx_entry
*rxe
;
679 struct rte_mbuf
*rxm
;
680 struct rte_mbuf
*nmb
;
684 uint16_t rx_packet_len
;
685 uint16_t rx_id
, nb_hold
;
692 rx_id
= rxq
->rx_tail
;
693 rx_ring
= rxq
->rx_ring
;
694 sw_ring
= rxq
->sw_ring
;
696 while (nb_rx
< nb_pkts
) {
697 rxdp
= &rx_ring
[rx_id
];
698 qword1
= rte_le_to_cpu_64(rxdp
->wb
.qword1
.status_error_len
);
699 rx_status
= (qword1
& I40E_RXD_QW1_STATUS_MASK
)
700 >> I40E_RXD_QW1_STATUS_SHIFT
;
702 /* Check the DD bit first */
703 if (!(rx_status
& (1 << I40E_RX_DESC_STATUS_DD_SHIFT
)))
706 nmb
= rte_mbuf_raw_alloc(rxq
->mp
);
712 rxe
= &sw_ring
[rx_id
];
714 if (unlikely(rx_id
== rxq
->nb_rx_desc
))
717 /* Prefetch next mbuf */
718 rte_prefetch0(sw_ring
[rx_id
].mbuf
);
721 * When next RX descriptor is on a cache line boundary,
722 * prefetch the next 4 RX descriptors and next 8 pointers
725 if ((rx_id
& 0x3) == 0) {
726 rte_prefetch0(&rx_ring
[rx_id
]);
727 rte_prefetch0(&sw_ring
[rx_id
]);
732 rte_cpu_to_le_64(rte_mbuf_data_dma_addr_default(nmb
));
733 rxdp
->read
.hdr_addr
= 0;
734 rxdp
->read
.pkt_addr
= dma_addr
;
736 rx_packet_len
= ((qword1
& I40E_RXD_QW1_LENGTH_PBUF_MASK
) >>
737 I40E_RXD_QW1_LENGTH_PBUF_SHIFT
) - rxq
->crc_len
;
739 rxm
->data_off
= RTE_PKTMBUF_HEADROOM
;
740 rte_prefetch0(RTE_PTR_ADD(rxm
->buf_addr
, RTE_PKTMBUF_HEADROOM
));
743 rxm
->pkt_len
= rx_packet_len
;
744 rxm
->data_len
= rx_packet_len
;
745 rxm
->port
= rxq
->port_id
;
747 i40e_rxd_to_vlan_tci(rxm
, &rxd
);
748 pkt_flags
= i40e_rxd_status_to_pkt_flags(qword1
);
749 pkt_flags
|= i40e_rxd_error_to_pkt_flags(qword1
);
751 i40e_rxd_pkt_type_mapping((uint8_t)((qword1
&
752 I40E_RXD_QW1_PTYPE_MASK
) >> I40E_RXD_QW1_PTYPE_SHIFT
));
753 if (pkt_flags
& PKT_RX_RSS_HASH
)
755 rte_le_to_cpu_32(rxd
.wb
.qword0
.hi_dword
.rss
);
756 if (pkt_flags
& PKT_RX_FDIR
)
757 pkt_flags
|= i40e_rxd_build_fdir(&rxd
, rxm
);
759 #ifdef RTE_LIBRTE_IEEE1588
760 pkt_flags
|= i40e_get_iee15888_flags(rxm
, qword1
);
762 rxm
->ol_flags
|= pkt_flags
;
764 rx_pkts
[nb_rx
++] = rxm
;
766 rxq
->rx_tail
= rx_id
;
769 * If the number of free RX descriptors is greater than the RX free
770 * threshold of the queue, advance the receive tail register of queue.
771 * Update that register with the value of the last processed RX
772 * descriptor minus 1.
774 nb_hold
= (uint16_t)(nb_hold
+ rxq
->nb_rx_hold
);
775 if (nb_hold
> rxq
->rx_free_thresh
) {
776 rx_id
= (uint16_t) ((rx_id
== 0) ?
777 (rxq
->nb_rx_desc
- 1) : (rx_id
- 1));
778 I40E_PCI_REG_WRITE(rxq
->qrx_tail
, rx_id
);
781 rxq
->nb_rx_hold
= nb_hold
;
787 i40e_recv_scattered_pkts(void *rx_queue
,
788 struct rte_mbuf
**rx_pkts
,
791 struct i40e_rx_queue
*rxq
= rx_queue
;
792 volatile union i40e_rx_desc
*rx_ring
= rxq
->rx_ring
;
793 volatile union i40e_rx_desc
*rxdp
;
794 union i40e_rx_desc rxd
;
795 struct i40e_rx_entry
*sw_ring
= rxq
->sw_ring
;
796 struct i40e_rx_entry
*rxe
;
797 struct rte_mbuf
*first_seg
= rxq
->pkt_first_seg
;
798 struct rte_mbuf
*last_seg
= rxq
->pkt_last_seg
;
799 struct rte_mbuf
*nmb
, *rxm
;
800 uint16_t rx_id
= rxq
->rx_tail
;
801 uint16_t nb_rx
= 0, nb_hold
= 0, rx_packet_len
;
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
;
813 /* Check the DD bit */
814 if (!(rx_status
& (1 << I40E_RX_DESC_STATUS_DD_SHIFT
)))
817 nmb
= rte_mbuf_raw_alloc(rxq
->mp
);
822 rxe
= &sw_ring
[rx_id
];
824 if (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
]);
843 rte_cpu_to_le_64(rte_mbuf_data_dma_addr_default(nmb
));
845 /* Set data buffer address and data length of the mbuf */
846 rxdp
->read
.hdr_addr
= 0;
847 rxdp
->read
.pkt_addr
= dma_addr
;
848 rx_packet_len
= (qword1
& I40E_RXD_QW1_LENGTH_PBUF_MASK
) >>
849 I40E_RXD_QW1_LENGTH_PBUF_SHIFT
;
850 rxm
->data_len
= rx_packet_len
;
851 rxm
->data_off
= RTE_PKTMBUF_HEADROOM
;
854 * If this is the first buffer of the received packet, set the
855 * pointer to the first mbuf of the packet and initialize its
856 * context. Otherwise, update the total length and the number
857 * of segments of the current scattered packet, and update the
858 * pointer to the last mbuf of the current packet.
862 first_seg
->nb_segs
= 1;
863 first_seg
->pkt_len
= rx_packet_len
;
866 (uint16_t)(first_seg
->pkt_len
+
868 first_seg
->nb_segs
++;
869 last_seg
->next
= rxm
;
873 * If this is not the last buffer of the received packet,
874 * update the pointer to the last mbuf of the current scattered
875 * packet and continue to parse the RX ring.
877 if (!(rx_status
& (1 << I40E_RX_DESC_STATUS_EOF_SHIFT
))) {
883 * This is the last buffer of the received packet. If the CRC
884 * is not stripped by the hardware:
885 * - Subtract the CRC length from the total packet length.
886 * - If the last buffer only contains the whole CRC or a part
887 * of it, free the mbuf associated to the last buffer. If part
888 * of the CRC is also contained in the previous mbuf, subtract
889 * the length of that CRC part from the data length of the
893 if (unlikely(rxq
->crc_len
> 0)) {
894 first_seg
->pkt_len
-= ETHER_CRC_LEN
;
895 if (rx_packet_len
<= ETHER_CRC_LEN
) {
896 rte_pktmbuf_free_seg(rxm
);
897 first_seg
->nb_segs
--;
899 (uint16_t)(last_seg
->data_len
-
900 (ETHER_CRC_LEN
- rx_packet_len
));
901 last_seg
->next
= NULL
;
903 rxm
->data_len
= (uint16_t)(rx_packet_len
-
907 first_seg
->port
= rxq
->port_id
;
908 first_seg
->ol_flags
= 0;
909 i40e_rxd_to_vlan_tci(first_seg
, &rxd
);
910 pkt_flags
= i40e_rxd_status_to_pkt_flags(qword1
);
911 pkt_flags
|= i40e_rxd_error_to_pkt_flags(qword1
);
912 first_seg
->packet_type
=
913 i40e_rxd_pkt_type_mapping((uint8_t)((qword1
&
914 I40E_RXD_QW1_PTYPE_MASK
) >> I40E_RXD_QW1_PTYPE_SHIFT
));
915 if (pkt_flags
& PKT_RX_RSS_HASH
)
916 first_seg
->hash
.rss
=
917 rte_le_to_cpu_32(rxd
.wb
.qword0
.hi_dword
.rss
);
918 if (pkt_flags
& PKT_RX_FDIR
)
919 pkt_flags
|= i40e_rxd_build_fdir(&rxd
, first_seg
);
921 #ifdef RTE_LIBRTE_IEEE1588
922 pkt_flags
|= i40e_get_iee15888_flags(first_seg
, qword1
);
924 first_seg
->ol_flags
|= pkt_flags
;
926 /* Prefetch data of first segment, if configured to do so. */
927 rte_prefetch0(RTE_PTR_ADD(first_seg
->buf_addr
,
928 first_seg
->data_off
));
929 rx_pkts
[nb_rx
++] = first_seg
;
933 /* Record index of the next RX descriptor to probe. */
934 rxq
->rx_tail
= rx_id
;
935 rxq
->pkt_first_seg
= first_seg
;
936 rxq
->pkt_last_seg
= last_seg
;
939 * If the number of free RX descriptors is greater than the RX free
940 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
941 * register. Update the RDT with the value of the last processed RX
942 * descriptor minus 1, to guarantee that the RDT register is never
943 * equal to the RDH register, which creates a "full" ring situtation
944 * from the hardware point of view.
946 nb_hold
= (uint16_t)(nb_hold
+ rxq
->nb_rx_hold
);
947 if (nb_hold
> rxq
->rx_free_thresh
) {
948 rx_id
= (uint16_t)(rx_id
== 0 ?
949 (rxq
->nb_rx_desc
- 1) : (rx_id
- 1));
950 I40E_PCI_REG_WRITE(rxq
->qrx_tail
, rx_id
);
953 rxq
->nb_rx_hold
= nb_hold
;
958 /* Check if the context descriptor is needed for TX offloading */
959 static inline uint16_t
960 i40e_calc_context_desc(uint64_t flags
)
962 static uint64_t mask
= PKT_TX_OUTER_IP_CKSUM
|
967 #ifdef RTE_LIBRTE_IEEE1588
968 mask
|= PKT_TX_IEEE1588_TMST
;
971 return (flags
& mask
) ? 1 : 0;
974 /* set i40e TSO context descriptor */
975 static inline uint64_t
976 i40e_set_tso_ctx(struct rte_mbuf
*mbuf
, union i40e_tx_offload tx_offload
)
978 uint64_t ctx_desc
= 0;
979 uint32_t cd_cmd
, hdr_len
, cd_tso_len
;
981 if (!tx_offload
.l4_len
) {
982 PMD_DRV_LOG(DEBUG
, "L4 length set to 0");
987 * in case of non tunneling packet, the outer_l2_len and
988 * outer_l3_len must be 0.
990 hdr_len
= tx_offload
.outer_l2_len
+
991 tx_offload
.outer_l3_len
+
996 cd_cmd
= I40E_TX_CTX_DESC_TSO
;
997 cd_tso_len
= mbuf
->pkt_len
- hdr_len
;
998 ctx_desc
|= ((uint64_t)cd_cmd
<< I40E_TXD_CTX_QW1_CMD_SHIFT
) |
999 ((uint64_t)cd_tso_len
<<
1000 I40E_TXD_CTX_QW1_TSO_LEN_SHIFT
) |
1001 ((uint64_t)mbuf
->tso_segsz
<<
1002 I40E_TXD_CTX_QW1_MSS_SHIFT
);
1008 i40e_xmit_pkts(void *tx_queue
, struct rte_mbuf
**tx_pkts
, uint16_t nb_pkts
)
1010 struct i40e_tx_queue
*txq
;
1011 struct i40e_tx_entry
*sw_ring
;
1012 struct i40e_tx_entry
*txe
, *txn
;
1013 volatile struct i40e_tx_desc
*txd
;
1014 volatile struct i40e_tx_desc
*txr
;
1015 struct rte_mbuf
*tx_pkt
;
1016 struct rte_mbuf
*m_seg
;
1017 uint32_t cd_tunneling_params
;
1029 uint64_t buf_dma_addr
;
1030 union i40e_tx_offload tx_offload
= {0};
1033 sw_ring
= txq
->sw_ring
;
1035 tx_id
= txq
->tx_tail
;
1036 txe
= &sw_ring
[tx_id
];
1038 /* Check if the descriptor ring needs to be cleaned. */
1039 if (txq
->nb_tx_free
< txq
->tx_free_thresh
)
1040 i40e_xmit_cleanup(txq
);
1042 for (nb_tx
= 0; nb_tx
< nb_pkts
; nb_tx
++) {
1048 tx_pkt
= *tx_pkts
++;
1049 RTE_MBUF_PREFETCH_TO_FREE(txe
->mbuf
);
1051 ol_flags
= tx_pkt
->ol_flags
;
1052 tx_offload
.l2_len
= tx_pkt
->l2_len
;
1053 tx_offload
.l3_len
= tx_pkt
->l3_len
;
1054 tx_offload
.outer_l2_len
= tx_pkt
->outer_l2_len
;
1055 tx_offload
.outer_l3_len
= tx_pkt
->outer_l3_len
;
1056 tx_offload
.l4_len
= tx_pkt
->l4_len
;
1057 tx_offload
.tso_segsz
= tx_pkt
->tso_segsz
;
1059 /* Calculate the number of context descriptors needed. */
1060 nb_ctx
= i40e_calc_context_desc(ol_flags
);
1063 * The number of descriptors that must be allocated for
1064 * a packet equals to the number of the segments of that
1065 * packet plus 1 context descriptor if needed.
1067 nb_used
= (uint16_t)(tx_pkt
->nb_segs
+ nb_ctx
);
1068 tx_last
= (uint16_t)(tx_id
+ nb_used
- 1);
1071 if (tx_last
>= txq
->nb_tx_desc
)
1072 tx_last
= (uint16_t)(tx_last
- txq
->nb_tx_desc
);
1074 if (nb_used
> txq
->nb_tx_free
) {
1075 if (i40e_xmit_cleanup(txq
) != 0) {
1080 if (unlikely(nb_used
> txq
->tx_rs_thresh
)) {
1081 while (nb_used
> txq
->nb_tx_free
) {
1082 if (i40e_xmit_cleanup(txq
) != 0) {
1091 /* Descriptor based VLAN insertion */
1092 if (ol_flags
& (PKT_TX_VLAN_PKT
| PKT_TX_QINQ_PKT
)) {
1093 tx_flags
|= tx_pkt
->vlan_tci
<<
1094 I40E_TX_FLAG_L2TAG1_SHIFT
;
1095 tx_flags
|= I40E_TX_FLAG_INSERT_VLAN
;
1096 td_cmd
|= I40E_TX_DESC_CMD_IL2TAG1
;
1097 td_tag
= (tx_flags
& I40E_TX_FLAG_L2TAG1_MASK
) >>
1098 I40E_TX_FLAG_L2TAG1_SHIFT
;
1101 /* Always enable CRC offload insertion */
1102 td_cmd
|= I40E_TX_DESC_CMD_ICRC
;
1104 /* Fill in tunneling parameters if necessary */
1105 cd_tunneling_params
= 0;
1106 if (ol_flags
& PKT_TX_TUNNEL_MASK
)
1107 i40e_parse_tunneling_params(ol_flags
, tx_offload
,
1108 &cd_tunneling_params
);
1109 /* Enable checksum offloading */
1110 if (ol_flags
& I40E_TX_CKSUM_OFFLOAD_MASK
)
1111 i40e_txd_enable_checksum(ol_flags
, &td_cmd
,
1112 &td_offset
, tx_offload
);
1115 /* Setup TX context descriptor if required */
1116 volatile struct i40e_tx_context_desc
*ctx_txd
=
1117 (volatile struct i40e_tx_context_desc
*)\
1119 uint16_t cd_l2tag2
= 0;
1120 uint64_t cd_type_cmd_tso_mss
=
1121 I40E_TX_DESC_DTYPE_CONTEXT
;
1123 txn
= &sw_ring
[txe
->next_id
];
1124 RTE_MBUF_PREFETCH_TO_FREE(txn
->mbuf
);
1125 if (txe
->mbuf
!= NULL
) {
1126 rte_pktmbuf_free_seg(txe
->mbuf
);
1130 /* TSO enabled means no timestamp */
1131 if (ol_flags
& PKT_TX_TCP_SEG
)
1132 cd_type_cmd_tso_mss
|=
1133 i40e_set_tso_ctx(tx_pkt
, tx_offload
);
1135 #ifdef RTE_LIBRTE_IEEE1588
1136 if (ol_flags
& PKT_TX_IEEE1588_TMST
)
1137 cd_type_cmd_tso_mss
|=
1138 ((uint64_t)I40E_TX_CTX_DESC_TSYN
<<
1139 I40E_TXD_CTX_QW1_CMD_SHIFT
);
1143 ctx_txd
->tunneling_params
=
1144 rte_cpu_to_le_32(cd_tunneling_params
);
1145 if (ol_flags
& PKT_TX_QINQ_PKT
) {
1146 cd_l2tag2
= tx_pkt
->vlan_tci_outer
;
1147 cd_type_cmd_tso_mss
|=
1148 ((uint64_t)I40E_TX_CTX_DESC_IL2TAG2
<<
1149 I40E_TXD_CTX_QW1_CMD_SHIFT
);
1151 ctx_txd
->l2tag2
= rte_cpu_to_le_16(cd_l2tag2
);
1152 ctx_txd
->type_cmd_tso_mss
=
1153 rte_cpu_to_le_64(cd_type_cmd_tso_mss
);
1155 PMD_TX_LOG(DEBUG
, "mbuf: %p, TCD[%u]:\n"
1156 "tunneling_params: %#x;\n"
1159 "type_cmd_tso_mss: %#"PRIx64
";\n",
1161 ctx_txd
->tunneling_params
,
1164 ctx_txd
->type_cmd_tso_mss
);
1166 txe
->last_id
= tx_last
;
1167 tx_id
= txe
->next_id
;
1174 txn
= &sw_ring
[txe
->next_id
];
1177 rte_pktmbuf_free_seg(txe
->mbuf
);
1180 /* Setup TX Descriptor */
1181 slen
= m_seg
->data_len
;
1182 buf_dma_addr
= rte_mbuf_data_dma_addr(m_seg
);
1184 PMD_TX_LOG(DEBUG
, "mbuf: %p, TDD[%u]:\n"
1185 "buf_dma_addr: %#"PRIx64
";\n"
1190 tx_pkt
, tx_id
, buf_dma_addr
,
1191 td_cmd
, td_offset
, slen
, td_tag
);
1193 txd
->buffer_addr
= rte_cpu_to_le_64(buf_dma_addr
);
1194 txd
->cmd_type_offset_bsz
= i40e_build_ctob(td_cmd
,
1195 td_offset
, slen
, td_tag
);
1196 txe
->last_id
= tx_last
;
1197 tx_id
= txe
->next_id
;
1199 m_seg
= m_seg
->next
;
1200 } while (m_seg
!= NULL
);
1202 /* The last packet data descriptor needs End Of Packet (EOP) */
1203 td_cmd
|= I40E_TX_DESC_CMD_EOP
;
1204 txq
->nb_tx_used
= (uint16_t)(txq
->nb_tx_used
+ nb_used
);
1205 txq
->nb_tx_free
= (uint16_t)(txq
->nb_tx_free
- nb_used
);
1207 if (txq
->nb_tx_used
>= txq
->tx_rs_thresh
) {
1208 PMD_TX_FREE_LOG(DEBUG
,
1209 "Setting RS bit on TXD id="
1210 "%4u (port=%d queue=%d)",
1211 tx_last
, txq
->port_id
, txq
->queue_id
);
1213 td_cmd
|= I40E_TX_DESC_CMD_RS
;
1215 /* Update txq RS bit counters */
1216 txq
->nb_tx_used
= 0;
1219 txd
->cmd_type_offset_bsz
|=
1220 rte_cpu_to_le_64(((uint64_t)td_cmd
) <<
1221 I40E_TXD_QW1_CMD_SHIFT
);
1227 PMD_TX_LOG(DEBUG
, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
1228 (unsigned) txq
->port_id
, (unsigned) txq
->queue_id
,
1229 (unsigned) tx_id
, (unsigned) nb_tx
);
1231 I40E_PCI_REG_WRITE(txq
->qtx_tail
, tx_id
);
1232 txq
->tx_tail
= tx_id
;
1237 static inline int __attribute__((always_inline
))
1238 i40e_tx_free_bufs(struct i40e_tx_queue
*txq
)
1240 struct i40e_tx_entry
*txep
;
1243 if ((txq
->tx_ring
[txq
->tx_next_dd
].cmd_type_offset_bsz
&
1244 rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK
)) !=
1245 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE
))
1248 txep
= &(txq
->sw_ring
[txq
->tx_next_dd
- (txq
->tx_rs_thresh
- 1)]);
1250 for (i
= 0; i
< txq
->tx_rs_thresh
; i
++)
1251 rte_prefetch0((txep
+ i
)->mbuf
);
1253 if (txq
->txq_flags
& (uint32_t)ETH_TXQ_FLAGS_NOREFCOUNT
) {
1254 for (i
= 0; i
< txq
->tx_rs_thresh
; ++i
, ++txep
) {
1255 rte_mempool_put(txep
->mbuf
->pool
, txep
->mbuf
);
1259 for (i
= 0; i
< txq
->tx_rs_thresh
; ++i
, ++txep
) {
1260 rte_pktmbuf_free_seg(txep
->mbuf
);
1265 txq
->nb_tx_free
= (uint16_t)(txq
->nb_tx_free
+ txq
->tx_rs_thresh
);
1266 txq
->tx_next_dd
= (uint16_t)(txq
->tx_next_dd
+ txq
->tx_rs_thresh
);
1267 if (txq
->tx_next_dd
>= txq
->nb_tx_desc
)
1268 txq
->tx_next_dd
= (uint16_t)(txq
->tx_rs_thresh
- 1);
1270 return txq
->tx_rs_thresh
;
1273 /* Populate 4 descriptors with data from 4 mbufs */
1275 tx4(volatile struct i40e_tx_desc
*txdp
, struct rte_mbuf
**pkts
)
1280 for (i
= 0; i
< 4; i
++, txdp
++, pkts
++) {
1281 dma_addr
= rte_mbuf_data_dma_addr(*pkts
);
1282 txdp
->buffer_addr
= rte_cpu_to_le_64(dma_addr
);
1283 txdp
->cmd_type_offset_bsz
=
1284 i40e_build_ctob((uint32_t)I40E_TD_CMD
, 0,
1285 (*pkts
)->data_len
, 0);
1289 /* Populate 1 descriptor with data from 1 mbuf */
1291 tx1(volatile struct i40e_tx_desc
*txdp
, struct rte_mbuf
**pkts
)
1295 dma_addr
= rte_mbuf_data_dma_addr(*pkts
);
1296 txdp
->buffer_addr
= rte_cpu_to_le_64(dma_addr
);
1297 txdp
->cmd_type_offset_bsz
=
1298 i40e_build_ctob((uint32_t)I40E_TD_CMD
, 0,
1299 (*pkts
)->data_len
, 0);
1302 /* Fill hardware descriptor ring with mbuf data */
1304 i40e_tx_fill_hw_ring(struct i40e_tx_queue
*txq
,
1305 struct rte_mbuf
**pkts
,
1308 volatile struct i40e_tx_desc
*txdp
= &(txq
->tx_ring
[txq
->tx_tail
]);
1309 struct i40e_tx_entry
*txep
= &(txq
->sw_ring
[txq
->tx_tail
]);
1310 const int N_PER_LOOP
= 4;
1311 const int N_PER_LOOP_MASK
= N_PER_LOOP
- 1;
1312 int mainpart
, leftover
;
1315 mainpart
= (nb_pkts
& ((uint32_t) ~N_PER_LOOP_MASK
));
1316 leftover
= (nb_pkts
& ((uint32_t) N_PER_LOOP_MASK
));
1317 for (i
= 0; i
< mainpart
; i
+= N_PER_LOOP
) {
1318 for (j
= 0; j
< N_PER_LOOP
; ++j
) {
1319 (txep
+ i
+ j
)->mbuf
= *(pkts
+ i
+ j
);
1321 tx4(txdp
+ i
, pkts
+ i
);
1323 if (unlikely(leftover
> 0)) {
1324 for (i
= 0; i
< leftover
; ++i
) {
1325 (txep
+ mainpart
+ i
)->mbuf
= *(pkts
+ mainpart
+ i
);
1326 tx1(txdp
+ mainpart
+ i
, pkts
+ mainpart
+ i
);
1331 static inline uint16_t
1332 tx_xmit_pkts(struct i40e_tx_queue
*txq
,
1333 struct rte_mbuf
**tx_pkts
,
1336 volatile struct i40e_tx_desc
*txr
= txq
->tx_ring
;
1340 * Begin scanning the H/W ring for done descriptors when the number
1341 * of available descriptors drops below tx_free_thresh. For each done
1342 * descriptor, free the associated buffer.
1344 if (txq
->nb_tx_free
< txq
->tx_free_thresh
)
1345 i40e_tx_free_bufs(txq
);
1347 /* Use available descriptor only */
1348 nb_pkts
= (uint16_t)RTE_MIN(txq
->nb_tx_free
, nb_pkts
);
1349 if (unlikely(!nb_pkts
))
1352 txq
->nb_tx_free
= (uint16_t)(txq
->nb_tx_free
- nb_pkts
);
1353 if ((txq
->tx_tail
+ nb_pkts
) > txq
->nb_tx_desc
) {
1354 n
= (uint16_t)(txq
->nb_tx_desc
- txq
->tx_tail
);
1355 i40e_tx_fill_hw_ring(txq
, tx_pkts
, n
);
1356 txr
[txq
->tx_next_rs
].cmd_type_offset_bsz
|=
1357 rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS
) <<
1358 I40E_TXD_QW1_CMD_SHIFT
);
1359 txq
->tx_next_rs
= (uint16_t)(txq
->tx_rs_thresh
- 1);
1363 /* Fill hardware descriptor ring with mbuf data */
1364 i40e_tx_fill_hw_ring(txq
, tx_pkts
+ n
, (uint16_t)(nb_pkts
- n
));
1365 txq
->tx_tail
= (uint16_t)(txq
->tx_tail
+ (nb_pkts
- n
));
1367 /* Determin if RS bit needs to be set */
1368 if (txq
->tx_tail
> txq
->tx_next_rs
) {
1369 txr
[txq
->tx_next_rs
].cmd_type_offset_bsz
|=
1370 rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS
) <<
1371 I40E_TXD_QW1_CMD_SHIFT
);
1373 (uint16_t)(txq
->tx_next_rs
+ txq
->tx_rs_thresh
);
1374 if (txq
->tx_next_rs
>= txq
->nb_tx_desc
)
1375 txq
->tx_next_rs
= (uint16_t)(txq
->tx_rs_thresh
- 1);
1378 if (txq
->tx_tail
>= txq
->nb_tx_desc
)
1381 /* Update the tx tail register */
1383 I40E_PCI_REG_WRITE(txq
->qtx_tail
, txq
->tx_tail
);
1389 i40e_xmit_pkts_simple(void *tx_queue
,
1390 struct rte_mbuf
**tx_pkts
,
1395 if (likely(nb_pkts
<= I40E_TX_MAX_BURST
))
1396 return tx_xmit_pkts((struct i40e_tx_queue
*)tx_queue
,
1400 uint16_t ret
, num
= (uint16_t)RTE_MIN(nb_pkts
,
1403 ret
= tx_xmit_pkts((struct i40e_tx_queue
*)tx_queue
,
1404 &tx_pkts
[nb_tx
], num
);
1405 nb_tx
= (uint16_t)(nb_tx
+ ret
);
1406 nb_pkts
= (uint16_t)(nb_pkts
- ret
);
1415 * Find the VSI the queue belongs to. 'queue_idx' is the queue index
1416 * application used, which assume having sequential ones. But from driver's
1417 * perspective, it's different. For example, q0 belongs to FDIR VSI, q1-q64
1418 * to MAIN VSI, , q65-96 to SRIOV VSIs, q97-128 to VMDQ VSIs. For application
1419 * running on host, q1-64 and q97-128 can be used, total 96 queues. They can
1420 * use queue_idx from 0 to 95 to access queues, while real queue would be
1421 * different. This function will do a queue mapping to find VSI the queue
1424 static struct i40e_vsi
*
1425 i40e_pf_get_vsi_by_qindex(struct i40e_pf
*pf
, uint16_t queue_idx
)
1427 /* the queue in MAIN VSI range */
1428 if (queue_idx
< pf
->main_vsi
->nb_qps
)
1429 return pf
->main_vsi
;
1431 queue_idx
-= pf
->main_vsi
->nb_qps
;
1433 /* queue_idx is greater than VMDQ VSIs range */
1434 if (queue_idx
> pf
->nb_cfg_vmdq_vsi
* pf
->vmdq_nb_qps
- 1) {
1435 PMD_INIT_LOG(ERR
, "queue_idx out of range. VMDQ configured?");
1439 return pf
->vmdq
[queue_idx
/ pf
->vmdq_nb_qps
].vsi
;
1443 i40e_get_queue_offset_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
)
1449 /* It's VMDQ queues */
1450 queue_idx
-= pf
->main_vsi
->nb_qps
;
1452 if (pf
->nb_cfg_vmdq_vsi
)
1453 return queue_idx
% pf
->vmdq_nb_qps
;
1455 PMD_INIT_LOG(ERR
, "Fail to get queue offset");
1456 return (uint16_t)(-1);
1461 i40e_dev_rx_queue_start(struct rte_eth_dev
*dev
, uint16_t rx_queue_id
)
1463 struct i40e_rx_queue
*rxq
;
1465 struct i40e_hw
*hw
= I40E_DEV_PRIVATE_TO_HW(dev
->data
->dev_private
);
1467 PMD_INIT_FUNC_TRACE();
1469 if (rx_queue_id
< dev
->data
->nb_rx_queues
) {
1470 rxq
= dev
->data
->rx_queues
[rx_queue_id
];
1472 err
= i40e_alloc_rx_queue_mbufs(rxq
);
1474 PMD_DRV_LOG(ERR
, "Failed to allocate RX queue mbuf");
1480 /* Init the RX tail regieter. */
1481 I40E_PCI_REG_WRITE(rxq
->qrx_tail
, rxq
->nb_rx_desc
- 1);
1483 err
= i40e_switch_rx_queue(hw
, rxq
->reg_idx
, TRUE
);
1486 PMD_DRV_LOG(ERR
, "Failed to switch RX queue %u on",
1489 i40e_rx_queue_release_mbufs(rxq
);
1490 i40e_reset_rx_queue(rxq
);
1492 dev
->data
->rx_queue_state
[rx_queue_id
] = RTE_ETH_QUEUE_STATE_STARTED
;
1499 i40e_dev_rx_queue_stop(struct rte_eth_dev
*dev
, uint16_t rx_queue_id
)
1501 struct i40e_rx_queue
*rxq
;
1503 struct i40e_hw
*hw
= I40E_DEV_PRIVATE_TO_HW(dev
->data
->dev_private
);
1505 if (rx_queue_id
< dev
->data
->nb_rx_queues
) {
1506 rxq
= dev
->data
->rx_queues
[rx_queue_id
];
1509 * rx_queue_id is queue id aplication refers to, while
1510 * rxq->reg_idx is the real queue index.
1512 err
= i40e_switch_rx_queue(hw
, rxq
->reg_idx
, FALSE
);
1515 PMD_DRV_LOG(ERR
, "Failed to switch RX queue %u off",
1519 i40e_rx_queue_release_mbufs(rxq
);
1520 i40e_reset_rx_queue(rxq
);
1521 dev
->data
->rx_queue_state
[rx_queue_id
] = RTE_ETH_QUEUE_STATE_STOPPED
;
1528 i40e_dev_tx_queue_start(struct rte_eth_dev
*dev
, uint16_t tx_queue_id
)
1531 struct i40e_tx_queue
*txq
;
1532 struct i40e_hw
*hw
= I40E_DEV_PRIVATE_TO_HW(dev
->data
->dev_private
);
1534 PMD_INIT_FUNC_TRACE();
1536 if (tx_queue_id
< dev
->data
->nb_tx_queues
) {
1537 txq
= dev
->data
->tx_queues
[tx_queue_id
];
1540 * tx_queue_id is queue id aplication refers to, while
1541 * rxq->reg_idx is the real queue index.
1543 err
= i40e_switch_tx_queue(hw
, txq
->reg_idx
, TRUE
);
1545 PMD_DRV_LOG(ERR
, "Failed to switch TX queue %u on",
1548 dev
->data
->tx_queue_state
[tx_queue_id
] = RTE_ETH_QUEUE_STATE_STARTED
;
1555 i40e_dev_tx_queue_stop(struct rte_eth_dev
*dev
, uint16_t tx_queue_id
)
1557 struct i40e_tx_queue
*txq
;
1559 struct i40e_hw
*hw
= I40E_DEV_PRIVATE_TO_HW(dev
->data
->dev_private
);
1561 if (tx_queue_id
< dev
->data
->nb_tx_queues
) {
1562 txq
= dev
->data
->tx_queues
[tx_queue_id
];
1565 * tx_queue_id is queue id aplication refers to, while
1566 * txq->reg_idx is the real queue index.
1568 err
= i40e_switch_tx_queue(hw
, txq
->reg_idx
, FALSE
);
1571 PMD_DRV_LOG(ERR
, "Failed to switch TX queue %u of",
1576 i40e_tx_queue_release_mbufs(txq
);
1577 i40e_reset_tx_queue(txq
);
1578 dev
->data
->tx_queue_state
[tx_queue_id
] = RTE_ETH_QUEUE_STATE_STOPPED
;
1585 i40e_dev_supported_ptypes_get(struct rte_eth_dev
*dev
)
1587 static const uint32_t ptypes
[] = {
1588 /* refers to i40e_rxd_pkt_type_mapping() */
1590 RTE_PTYPE_L2_ETHER_TIMESYNC
,
1591 RTE_PTYPE_L2_ETHER_LLDP
,
1592 RTE_PTYPE_L2_ETHER_ARP
,
1593 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN
,
1594 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN
,
1597 RTE_PTYPE_L4_NONFRAG
,
1601 RTE_PTYPE_TUNNEL_GRENAT
,
1602 RTE_PTYPE_TUNNEL_IP
,
1603 RTE_PTYPE_INNER_L2_ETHER
,
1604 RTE_PTYPE_INNER_L2_ETHER_VLAN
,
1605 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN
,
1606 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN
,
1607 RTE_PTYPE_INNER_L4_FRAG
,
1608 RTE_PTYPE_INNER_L4_ICMP
,
1609 RTE_PTYPE_INNER_L4_NONFRAG
,
1610 RTE_PTYPE_INNER_L4_SCTP
,
1611 RTE_PTYPE_INNER_L4_TCP
,
1612 RTE_PTYPE_INNER_L4_UDP
,
1616 if (dev
->rx_pkt_burst
== i40e_recv_pkts
||
1617 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1618 dev
->rx_pkt_burst
== i40e_recv_pkts_bulk_alloc
||
1620 dev
->rx_pkt_burst
== i40e_recv_scattered_pkts
||
1621 dev
->rx_pkt_burst
== i40e_recv_scattered_pkts_vec
||
1622 dev
->rx_pkt_burst
== i40e_recv_pkts_vec
)
1628 i40e_dev_rx_queue_setup(struct rte_eth_dev
*dev
,
1631 unsigned int socket_id
,
1632 const struct rte_eth_rxconf
*rx_conf
,
1633 struct rte_mempool
*mp
)
1635 struct i40e_vsi
*vsi
;
1636 struct i40e_hw
*hw
= I40E_DEV_PRIVATE_TO_HW(dev
->data
->dev_private
);
1637 struct i40e_pf
*pf
= I40E_DEV_PRIVATE_TO_PF(dev
->data
->dev_private
);
1638 struct i40e_adapter
*ad
=
1639 I40E_DEV_PRIVATE_TO_ADAPTER(dev
->data
->dev_private
);
1640 struct i40e_rx_queue
*rxq
;
1641 const struct rte_memzone
*rz
;
1644 uint16_t base
, bsf
, tc_mapping
;
1645 int use_def_burst_func
= 1;
1647 if (hw
->mac
.type
== I40E_MAC_VF
|| hw
->mac
.type
== I40E_MAC_X722_VF
) {
1648 struct i40e_vf
*vf
=
1649 I40EVF_DEV_PRIVATE_TO_VF(dev
->data
->dev_private
);
1652 vsi
= i40e_pf_get_vsi_by_qindex(pf
, queue_idx
);
1655 PMD_DRV_LOG(ERR
, "VSI not available or queue "
1656 "index exceeds the maximum");
1657 return I40E_ERR_PARAM
;
1659 if (nb_desc
% I40E_ALIGN_RING_DESC
!= 0 ||
1660 (nb_desc
> I40E_MAX_RING_DESC
) ||
1661 (nb_desc
< I40E_MIN_RING_DESC
)) {
1662 PMD_DRV_LOG(ERR
, "Number (%u) of receive descriptors is "
1663 "invalid", nb_desc
);
1664 return I40E_ERR_PARAM
;
1667 /* Free memory if needed */
1668 if (dev
->data
->rx_queues
[queue_idx
]) {
1669 i40e_dev_rx_queue_release(dev
->data
->rx_queues
[queue_idx
]);
1670 dev
->data
->rx_queues
[queue_idx
] = NULL
;
1673 /* Allocate the rx queue data structure */
1674 rxq
= rte_zmalloc_socket("i40e rx queue",
1675 sizeof(struct i40e_rx_queue
),
1676 RTE_CACHE_LINE_SIZE
,
1679 PMD_DRV_LOG(ERR
, "Failed to allocate memory for "
1680 "rx queue data structure");
1684 rxq
->nb_rx_desc
= nb_desc
;
1685 rxq
->rx_free_thresh
= rx_conf
->rx_free_thresh
;
1686 rxq
->queue_id
= queue_idx
;
1687 if (hw
->mac
.type
== I40E_MAC_VF
|| hw
->mac
.type
== I40E_MAC_X722_VF
)
1688 rxq
->reg_idx
= queue_idx
;
1689 else /* PF device */
1690 rxq
->reg_idx
= vsi
->base_queue
+
1691 i40e_get_queue_offset_by_qindex(pf
, queue_idx
);
1693 rxq
->port_id
= dev
->data
->port_id
;
1694 rxq
->crc_len
= (uint8_t) ((dev
->data
->dev_conf
.rxmode
.hw_strip_crc
) ?
1696 rxq
->drop_en
= rx_conf
->rx_drop_en
;
1698 rxq
->rx_deferred_start
= rx_conf
->rx_deferred_start
;
1700 /* Allocate the maximun number of RX ring hardware descriptor. */
1701 ring_size
= sizeof(union i40e_rx_desc
) * I40E_MAX_RING_DESC
;
1702 ring_size
= RTE_ALIGN(ring_size
, I40E_DMA_MEM_ALIGN
);
1703 rz
= rte_eth_dma_zone_reserve(dev
, "rx_ring", queue_idx
,
1704 ring_size
, I40E_RING_BASE_ALIGN
, socket_id
);
1706 i40e_dev_rx_queue_release(rxq
);
1707 PMD_DRV_LOG(ERR
, "Failed to reserve DMA memory for RX");
1711 /* Zero all the descriptors in the ring. */
1712 memset(rz
->addr
, 0, ring_size
);
1714 rxq
->rx_ring_phys_addr
= rte_mem_phy2mch(rz
->memseg_id
, rz
->phys_addr
);
1715 rxq
->rx_ring
= (union i40e_rx_desc
*)rz
->addr
;
1717 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1718 len
= (uint16_t)(nb_desc
+ RTE_PMD_I40E_RX_MAX_BURST
);
1723 /* Allocate the software ring. */
1725 rte_zmalloc_socket("i40e rx sw ring",
1726 sizeof(struct i40e_rx_entry
) * len
,
1727 RTE_CACHE_LINE_SIZE
,
1729 if (!rxq
->sw_ring
) {
1730 i40e_dev_rx_queue_release(rxq
);
1731 PMD_DRV_LOG(ERR
, "Failed to allocate memory for SW ring");
1735 i40e_reset_rx_queue(rxq
);
1737 dev
->data
->rx_queues
[queue_idx
] = rxq
;
1739 use_def_burst_func
= check_rx_burst_bulk_alloc_preconditions(rxq
);
1741 if (!use_def_burst_func
) {
1742 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
1743 PMD_INIT_LOG(DEBUG
, "Rx Burst Bulk Alloc Preconditions are "
1744 "satisfied. Rx Burst Bulk Alloc function will be "
1745 "used on port=%d, queue=%d.",
1746 rxq
->port_id
, rxq
->queue_id
);
1747 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
1749 PMD_INIT_LOG(DEBUG
, "Rx Burst Bulk Alloc Preconditions are "
1750 "not satisfied, Scattered Rx is requested, "
1751 "or RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC is "
1752 "not enabled on port=%d, queue=%d.",
1753 rxq
->port_id
, rxq
->queue_id
);
1754 ad
->rx_bulk_alloc_allowed
= false;
1757 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1758 if (!(vsi
->enabled_tc
& (1 << i
)))
1760 tc_mapping
= rte_le_to_cpu_16(vsi
->info
.tc_mapping
[i
]);
1761 base
= (tc_mapping
& I40E_AQ_VSI_TC_QUE_OFFSET_MASK
) >>
1762 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
;
1763 bsf
= (tc_mapping
& I40E_AQ_VSI_TC_QUE_NUMBER_MASK
) >>
1764 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
;
1766 if (queue_idx
>= base
&& queue_idx
< (base
+ BIT(bsf
)))
1774 i40e_dev_rx_queue_release(void *rxq
)
1776 struct i40e_rx_queue
*q
= (struct i40e_rx_queue
*)rxq
;
1779 PMD_DRV_LOG(DEBUG
, "Pointer to rxq is NULL");
1783 i40e_rx_queue_release_mbufs(q
);
1784 rte_free(q
->sw_ring
);
1789 i40e_dev_rx_queue_count(struct rte_eth_dev
*dev
, uint16_t rx_queue_id
)
1791 #define I40E_RXQ_SCAN_INTERVAL 4
1792 volatile union i40e_rx_desc
*rxdp
;
1793 struct i40e_rx_queue
*rxq
;
1796 if (unlikely(rx_queue_id
>= dev
->data
->nb_rx_queues
)) {
1797 PMD_DRV_LOG(ERR
, "Invalid RX queue id %u", rx_queue_id
);
1801 rxq
= dev
->data
->rx_queues
[rx_queue_id
];
1802 rxdp
= &(rxq
->rx_ring
[rxq
->rx_tail
]);
1803 while ((desc
< rxq
->nb_rx_desc
) &&
1804 ((rte_le_to_cpu_64(rxdp
->wb
.qword1
.status_error_len
) &
1805 I40E_RXD_QW1_STATUS_MASK
) >> I40E_RXD_QW1_STATUS_SHIFT
) &
1806 (1 << I40E_RX_DESC_STATUS_DD_SHIFT
)) {
1808 * Check the DD bit of a rx descriptor of each 4 in a group,
1809 * to avoid checking too frequently and downgrading performance
1812 desc
+= I40E_RXQ_SCAN_INTERVAL
;
1813 rxdp
+= I40E_RXQ_SCAN_INTERVAL
;
1814 if (rxq
->rx_tail
+ desc
>= rxq
->nb_rx_desc
)
1815 rxdp
= &(rxq
->rx_ring
[rxq
->rx_tail
+
1816 desc
- rxq
->nb_rx_desc
]);
1823 i40e_dev_rx_descriptor_done(void *rx_queue
, uint16_t offset
)
1825 volatile union i40e_rx_desc
*rxdp
;
1826 struct i40e_rx_queue
*rxq
= rx_queue
;
1830 if (unlikely(offset
>= rxq
->nb_rx_desc
)) {
1831 PMD_DRV_LOG(ERR
, "Invalid RX queue id %u", offset
);
1835 desc
= rxq
->rx_tail
+ offset
;
1836 if (desc
>= rxq
->nb_rx_desc
)
1837 desc
-= rxq
->nb_rx_desc
;
1839 rxdp
= &(rxq
->rx_ring
[desc
]);
1841 ret
= !!(((rte_le_to_cpu_64(rxdp
->wb
.qword1
.status_error_len
) &
1842 I40E_RXD_QW1_STATUS_MASK
) >> I40E_RXD_QW1_STATUS_SHIFT
) &
1843 (1 << I40E_RX_DESC_STATUS_DD_SHIFT
));
1849 i40e_dev_tx_queue_setup(struct rte_eth_dev
*dev
,
1852 unsigned int socket_id
,
1853 const struct rte_eth_txconf
*tx_conf
)
1855 struct i40e_vsi
*vsi
;
1856 struct i40e_hw
*hw
= I40E_DEV_PRIVATE_TO_HW(dev
->data
->dev_private
);
1857 struct i40e_pf
*pf
= I40E_DEV_PRIVATE_TO_PF(dev
->data
->dev_private
);
1858 struct i40e_tx_queue
*txq
;
1859 const struct rte_memzone
*tz
;
1861 uint16_t tx_rs_thresh
, tx_free_thresh
;
1862 uint16_t i
, base
, bsf
, tc_mapping
;
1864 if (hw
->mac
.type
== I40E_MAC_VF
|| hw
->mac
.type
== I40E_MAC_X722_VF
) {
1865 struct i40e_vf
*vf
=
1866 I40EVF_DEV_PRIVATE_TO_VF(dev
->data
->dev_private
);
1869 vsi
= i40e_pf_get_vsi_by_qindex(pf
, queue_idx
);
1872 PMD_DRV_LOG(ERR
, "VSI is NULL, or queue index (%u) "
1873 "exceeds the maximum", queue_idx
);
1874 return I40E_ERR_PARAM
;
1877 if (nb_desc
% I40E_ALIGN_RING_DESC
!= 0 ||
1878 (nb_desc
> I40E_MAX_RING_DESC
) ||
1879 (nb_desc
< I40E_MIN_RING_DESC
)) {
1880 PMD_DRV_LOG(ERR
, "Number (%u) of transmit descriptors is "
1881 "invalid", nb_desc
);
1882 return I40E_ERR_PARAM
;
1886 * The following two parameters control the setting of the RS bit on
1887 * transmit descriptors. TX descriptors will have their RS bit set
1888 * after txq->tx_rs_thresh descriptors have been used. The TX
1889 * descriptor ring will be cleaned after txq->tx_free_thresh
1890 * descriptors are used or if the number of descriptors required to
1891 * transmit a packet is greater than the number of free TX descriptors.
1893 * The following constraints must be satisfied:
1894 * - tx_rs_thresh must be greater than 0.
1895 * - tx_rs_thresh must be less than the size of the ring minus 2.
1896 * - tx_rs_thresh must be less than or equal to tx_free_thresh.
1897 * - tx_rs_thresh must be a divisor of the ring size.
1898 * - tx_free_thresh must be greater than 0.
1899 * - tx_free_thresh must be less than the size of the ring minus 3.
1901 * One descriptor in the TX ring is used as a sentinel to avoid a H/W
1902 * race condition, hence the maximum threshold constraints. When set
1903 * to zero use default values.
1905 tx_rs_thresh
= (uint16_t)((tx_conf
->tx_rs_thresh
) ?
1906 tx_conf
->tx_rs_thresh
: DEFAULT_TX_RS_THRESH
);
1907 tx_free_thresh
= (uint16_t)((tx_conf
->tx_free_thresh
) ?
1908 tx_conf
->tx_free_thresh
: DEFAULT_TX_FREE_THRESH
);
1909 if (tx_rs_thresh
>= (nb_desc
- 2)) {
1910 PMD_INIT_LOG(ERR
, "tx_rs_thresh must be less than the "
1911 "number of TX descriptors minus 2. "
1912 "(tx_rs_thresh=%u port=%d queue=%d)",
1913 (unsigned int)tx_rs_thresh
,
1914 (int)dev
->data
->port_id
,
1916 return I40E_ERR_PARAM
;
1918 if (tx_free_thresh
>= (nb_desc
- 3)) {
1919 PMD_INIT_LOG(ERR
, "tx_rs_thresh must be less than the "
1920 "tx_free_thresh must be less than the "
1921 "number of TX descriptors minus 3. "
1922 "(tx_free_thresh=%u port=%d queue=%d)",
1923 (unsigned int)tx_free_thresh
,
1924 (int)dev
->data
->port_id
,
1926 return I40E_ERR_PARAM
;
1928 if (tx_rs_thresh
> tx_free_thresh
) {
1929 PMD_INIT_LOG(ERR
, "tx_rs_thresh must be less than or "
1930 "equal to tx_free_thresh. (tx_free_thresh=%u"
1931 " tx_rs_thresh=%u port=%d queue=%d)",
1932 (unsigned int)tx_free_thresh
,
1933 (unsigned int)tx_rs_thresh
,
1934 (int)dev
->data
->port_id
,
1936 return I40E_ERR_PARAM
;
1938 if ((nb_desc
% tx_rs_thresh
) != 0) {
1939 PMD_INIT_LOG(ERR
, "tx_rs_thresh must be a divisor of the "
1940 "number of TX descriptors. (tx_rs_thresh=%u"
1941 " port=%d queue=%d)",
1942 (unsigned int)tx_rs_thresh
,
1943 (int)dev
->data
->port_id
,
1945 return I40E_ERR_PARAM
;
1947 if ((tx_rs_thresh
> 1) && (tx_conf
->tx_thresh
.wthresh
!= 0)) {
1948 PMD_INIT_LOG(ERR
, "TX WTHRESH must be set to 0 if "
1949 "tx_rs_thresh is greater than 1. "
1950 "(tx_rs_thresh=%u port=%d queue=%d)",
1951 (unsigned int)tx_rs_thresh
,
1952 (int)dev
->data
->port_id
,
1954 return I40E_ERR_PARAM
;
1957 /* Free memory if needed. */
1958 if (dev
->data
->tx_queues
[queue_idx
]) {
1959 i40e_dev_tx_queue_release(dev
->data
->tx_queues
[queue_idx
]);
1960 dev
->data
->tx_queues
[queue_idx
] = NULL
;
1963 /* Allocate the TX queue data structure. */
1964 txq
= rte_zmalloc_socket("i40e tx queue",
1965 sizeof(struct i40e_tx_queue
),
1966 RTE_CACHE_LINE_SIZE
,
1969 PMD_DRV_LOG(ERR
, "Failed to allocate memory for "
1970 "tx queue structure");
1974 /* Allocate TX hardware ring descriptors. */
1975 ring_size
= sizeof(struct i40e_tx_desc
) * I40E_MAX_RING_DESC
;
1976 ring_size
= RTE_ALIGN(ring_size
, I40E_DMA_MEM_ALIGN
);
1977 tz
= rte_eth_dma_zone_reserve(dev
, "tx_ring", queue_idx
,
1978 ring_size
, I40E_RING_BASE_ALIGN
, socket_id
);
1980 i40e_dev_tx_queue_release(txq
);
1981 PMD_DRV_LOG(ERR
, "Failed to reserve DMA memory for TX");
1985 txq
->nb_tx_desc
= nb_desc
;
1986 txq
->tx_rs_thresh
= tx_rs_thresh
;
1987 txq
->tx_free_thresh
= tx_free_thresh
;
1988 txq
->pthresh
= tx_conf
->tx_thresh
.pthresh
;
1989 txq
->hthresh
= tx_conf
->tx_thresh
.hthresh
;
1990 txq
->wthresh
= tx_conf
->tx_thresh
.wthresh
;
1991 txq
->queue_id
= queue_idx
;
1992 if (hw
->mac
.type
== I40E_MAC_VF
|| hw
->mac
.type
== I40E_MAC_X722_VF
)
1993 txq
->reg_idx
= queue_idx
;
1994 else /* PF device */
1995 txq
->reg_idx
= vsi
->base_queue
+
1996 i40e_get_queue_offset_by_qindex(pf
, queue_idx
);
1998 txq
->port_id
= dev
->data
->port_id
;
1999 txq
->txq_flags
= tx_conf
->txq_flags
;
2001 txq
->tx_deferred_start
= tx_conf
->tx_deferred_start
;
2003 txq
->tx_ring_phys_addr
= rte_mem_phy2mch(tz
->memseg_id
, tz
->phys_addr
);
2004 txq
->tx_ring
= (struct i40e_tx_desc
*)tz
->addr
;
2006 /* Allocate software ring */
2008 rte_zmalloc_socket("i40e tx sw ring",
2009 sizeof(struct i40e_tx_entry
) * nb_desc
,
2010 RTE_CACHE_LINE_SIZE
,
2012 if (!txq
->sw_ring
) {
2013 i40e_dev_tx_queue_release(txq
);
2014 PMD_DRV_LOG(ERR
, "Failed to allocate memory for SW TX ring");
2018 i40e_reset_tx_queue(txq
);
2020 dev
->data
->tx_queues
[queue_idx
] = txq
;
2022 /* Use a simple TX queue without offloads or multi segs if possible */
2023 i40e_set_tx_function_flag(dev
, txq
);
2025 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
2026 if (!(vsi
->enabled_tc
& (1 << i
)))
2028 tc_mapping
= rte_le_to_cpu_16(vsi
->info
.tc_mapping
[i
]);
2029 base
= (tc_mapping
& I40E_AQ_VSI_TC_QUE_OFFSET_MASK
) >>
2030 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
;
2031 bsf
= (tc_mapping
& I40E_AQ_VSI_TC_QUE_NUMBER_MASK
) >>
2032 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
;
2034 if (queue_idx
>= base
&& queue_idx
< (base
+ BIT(bsf
)))
2042 i40e_dev_tx_queue_release(void *txq
)
2044 struct i40e_tx_queue
*q
= (struct i40e_tx_queue
*)txq
;
2047 PMD_DRV_LOG(DEBUG
, "Pointer to TX queue is NULL");
2051 i40e_tx_queue_release_mbufs(q
);
2052 rte_free(q
->sw_ring
);
2056 const struct rte_memzone
*
2057 i40e_memzone_reserve(const char *name
, uint32_t len
, int socket_id
)
2059 const struct rte_memzone
*mz
;
2061 mz
= rte_memzone_lookup(name
);
2065 if (rte_xen_dom0_supported())
2066 mz
= rte_memzone_reserve_bounded(name
, len
,
2067 socket_id
, 0, I40E_RING_BASE_ALIGN
, RTE_PGSIZE_2M
);
2069 mz
= rte_memzone_reserve_aligned(name
, len
,
2070 socket_id
, 0, I40E_RING_BASE_ALIGN
);
2075 i40e_rx_queue_release_mbufs(struct i40e_rx_queue
*rxq
)
2079 /* SSE Vector driver has a different way of releasing mbufs. */
2080 if (rxq
->rx_using_sse
) {
2081 i40e_rx_queue_release_mbufs_vec(rxq
);
2085 if (!rxq
->sw_ring
) {
2086 PMD_DRV_LOG(DEBUG
, "Pointer to sw_ring is NULL");
2090 for (i
= 0; i
< rxq
->nb_rx_desc
; i
++) {
2091 if (rxq
->sw_ring
[i
].mbuf
) {
2092 rte_pktmbuf_free_seg(rxq
->sw_ring
[i
].mbuf
);
2093 rxq
->sw_ring
[i
].mbuf
= NULL
;
2096 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2097 if (rxq
->rx_nb_avail
== 0)
2099 for (i
= 0; i
< rxq
->rx_nb_avail
; i
++) {
2100 struct rte_mbuf
*mbuf
;
2102 mbuf
= rxq
->rx_stage
[rxq
->rx_next_avail
+ i
];
2103 rte_pktmbuf_free_seg(mbuf
);
2105 rxq
->rx_nb_avail
= 0;
2106 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2110 i40e_reset_rx_queue(struct i40e_rx_queue
*rxq
)
2116 PMD_DRV_LOG(DEBUG
, "Pointer to rxq is NULL");
2120 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2121 if (check_rx_burst_bulk_alloc_preconditions(rxq
) == 0)
2122 len
= (uint16_t)(rxq
->nb_rx_desc
+ RTE_PMD_I40E_RX_MAX_BURST
);
2124 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2125 len
= rxq
->nb_rx_desc
;
2127 for (i
= 0; i
< len
* sizeof(union i40e_rx_desc
); i
++)
2128 ((volatile char *)rxq
->rx_ring
)[i
] = 0;
2130 #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
2131 memset(&rxq
->fake_mbuf
, 0x0, sizeof(rxq
->fake_mbuf
));
2132 for (i
= 0; i
< RTE_PMD_I40E_RX_MAX_BURST
; ++i
)
2133 rxq
->sw_ring
[rxq
->nb_rx_desc
+ i
].mbuf
= &rxq
->fake_mbuf
;
2135 rxq
->rx_nb_avail
= 0;
2136 rxq
->rx_next_avail
= 0;
2137 rxq
->rx_free_trigger
= (uint16_t)(rxq
->rx_free_thresh
- 1);
2138 #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
2140 rxq
->nb_rx_hold
= 0;
2141 rxq
->pkt_first_seg
= NULL
;
2142 rxq
->pkt_last_seg
= NULL
;
2144 rxq
->rxrearm_start
= 0;
2145 rxq
->rxrearm_nb
= 0;
2149 i40e_tx_queue_release_mbufs(struct i40e_tx_queue
*txq
)
2153 if (!txq
|| !txq
->sw_ring
) {
2154 PMD_DRV_LOG(DEBUG
, "Pointer to rxq or sw_ring is NULL");
2158 for (i
= 0; i
< txq
->nb_tx_desc
; i
++) {
2159 if (txq
->sw_ring
[i
].mbuf
) {
2160 rte_pktmbuf_free_seg(txq
->sw_ring
[i
].mbuf
);
2161 txq
->sw_ring
[i
].mbuf
= NULL
;
2167 i40e_reset_tx_queue(struct i40e_tx_queue
*txq
)
2169 struct i40e_tx_entry
*txe
;
2170 uint16_t i
, prev
, size
;
2173 PMD_DRV_LOG(DEBUG
, "Pointer to txq is NULL");
2178 size
= sizeof(struct i40e_tx_desc
) * txq
->nb_tx_desc
;
2179 for (i
= 0; i
< size
; i
++)
2180 ((volatile char *)txq
->tx_ring
)[i
] = 0;
2182 prev
= (uint16_t)(txq
->nb_tx_desc
- 1);
2183 for (i
= 0; i
< txq
->nb_tx_desc
; i
++) {
2184 volatile struct i40e_tx_desc
*txd
= &txq
->tx_ring
[i
];
2186 txd
->cmd_type_offset_bsz
=
2187 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE
);
2190 txe
[prev
].next_id
= i
;
2194 txq
->tx_next_dd
= (uint16_t)(txq
->tx_rs_thresh
- 1);
2195 txq
->tx_next_rs
= (uint16_t)(txq
->tx_rs_thresh
- 1);
2198 txq
->nb_tx_used
= 0;
2200 txq
->last_desc_cleaned
= (uint16_t)(txq
->nb_tx_desc
- 1);
2201 txq
->nb_tx_free
= (uint16_t)(txq
->nb_tx_desc
- 1);
2204 /* Init the TX queue in hardware */
2206 i40e_tx_queue_init(struct i40e_tx_queue
*txq
)
2208 enum i40e_status_code err
= I40E_SUCCESS
;
2209 struct i40e_vsi
*vsi
= txq
->vsi
;
2210 struct i40e_hw
*hw
= I40E_VSI_TO_HW(vsi
);
2211 uint16_t pf_q
= txq
->reg_idx
;
2212 struct i40e_hmc_obj_txq tx_ctx
;
2215 /* clear the context structure first */
2216 memset(&tx_ctx
, 0, sizeof(tx_ctx
));
2217 tx_ctx
.new_context
= 1;
2218 tx_ctx
.base
= txq
->tx_ring_phys_addr
/ I40E_QUEUE_BASE_ADDR_UNIT
;
2219 tx_ctx
.qlen
= txq
->nb_tx_desc
;
2221 #ifdef RTE_LIBRTE_IEEE1588
2222 tx_ctx
.timesync_ena
= 1;
2224 tx_ctx
.rdylist
= rte_le_to_cpu_16(vsi
->info
.qs_handle
[txq
->dcb_tc
]);
2225 if (vsi
->type
== I40E_VSI_FDIR
)
2226 tx_ctx
.fd_ena
= TRUE
;
2228 err
= i40e_clear_lan_tx_queue_context(hw
, pf_q
);
2229 if (err
!= I40E_SUCCESS
) {
2230 PMD_DRV_LOG(ERR
, "Failure of clean lan tx queue context");
2234 err
= i40e_set_lan_tx_queue_context(hw
, pf_q
, &tx_ctx
);
2235 if (err
!= I40E_SUCCESS
) {
2236 PMD_DRV_LOG(ERR
, "Failure of set lan tx queue context");
2240 /* Now associate this queue with this PCI function */
2241 qtx_ctl
= I40E_QTX_CTL_PF_QUEUE
;
2242 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
) &
2243 I40E_QTX_CTL_PF_INDX_MASK
);
2244 I40E_WRITE_REG(hw
, I40E_QTX_CTL(pf_q
), qtx_ctl
);
2245 I40E_WRITE_FLUSH(hw
);
2247 txq
->qtx_tail
= hw
->hw_addr
+ I40E_QTX_TAIL(pf_q
);
2253 i40e_alloc_rx_queue_mbufs(struct i40e_rx_queue
*rxq
)
2255 struct i40e_rx_entry
*rxe
= rxq
->sw_ring
;
2259 for (i
= 0; i
< rxq
->nb_rx_desc
; i
++) {
2260 volatile union i40e_rx_desc
*rxd
;
2261 struct rte_mbuf
*mbuf
= rte_mbuf_raw_alloc(rxq
->mp
);
2263 if (unlikely(!mbuf
)) {
2264 PMD_DRV_LOG(ERR
, "Failed to allocate mbuf for RX");
2268 rte_mbuf_refcnt_set(mbuf
, 1);
2270 mbuf
->data_off
= RTE_PKTMBUF_HEADROOM
;
2272 mbuf
->port
= rxq
->port_id
;
2275 rte_cpu_to_le_64(rte_mbuf_data_dma_addr_default(mbuf
));
2277 rxd
= &rxq
->rx_ring
[i
];
2278 rxd
->read
.pkt_addr
= dma_addr
;
2279 rxd
->read
.hdr_addr
= 0;
2280 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2281 rxd
->read
.rsvd1
= 0;
2282 rxd
->read
.rsvd2
= 0;
2283 #endif /* RTE_LIBRTE_I40E_16BYTE_RX_DESC */
2292 * Calculate the buffer length, and check the jumbo frame
2293 * and maximum packet length.
2296 i40e_rx_queue_config(struct i40e_rx_queue
*rxq
)
2298 struct i40e_pf
*pf
= I40E_VSI_TO_PF(rxq
->vsi
);
2299 struct i40e_hw
*hw
= I40E_VSI_TO_HW(rxq
->vsi
);
2300 struct rte_eth_dev_data
*data
= pf
->dev_data
;
2301 uint16_t buf_size
, len
;
2303 buf_size
= (uint16_t)(rte_pktmbuf_data_room_size(rxq
->mp
) -
2304 RTE_PKTMBUF_HEADROOM
);
2306 switch (pf
->flags
& (I40E_FLAG_HEADER_SPLIT_DISABLED
|
2307 I40E_FLAG_HEADER_SPLIT_ENABLED
)) {
2308 case I40E_FLAG_HEADER_SPLIT_ENABLED
: /* Not supported */
2309 rxq
->rx_hdr_len
= RTE_ALIGN(I40E_RXBUF_SZ_1024
,
2310 (1 << I40E_RXQ_CTX_HBUFF_SHIFT
));
2311 rxq
->rx_buf_len
= RTE_ALIGN(I40E_RXBUF_SZ_2048
,
2312 (1 << I40E_RXQ_CTX_DBUFF_SHIFT
));
2313 rxq
->hs_mode
= i40e_header_split_enabled
;
2315 case I40E_FLAG_HEADER_SPLIT_DISABLED
:
2317 rxq
->rx_hdr_len
= 0;
2318 rxq
->rx_buf_len
= RTE_ALIGN(buf_size
,
2319 (1 << I40E_RXQ_CTX_DBUFF_SHIFT
));
2320 rxq
->hs_mode
= i40e_header_split_none
;
2324 len
= hw
->func_caps
.rx_buf_chain_len
* rxq
->rx_buf_len
;
2325 rxq
->max_pkt_len
= RTE_MIN(len
, data
->dev_conf
.rxmode
.max_rx_pkt_len
);
2326 if (data
->dev_conf
.rxmode
.jumbo_frame
== 1) {
2327 if (rxq
->max_pkt_len
<= ETHER_MAX_LEN
||
2328 rxq
->max_pkt_len
> I40E_FRAME_SIZE_MAX
) {
2329 PMD_DRV_LOG(ERR
, "maximum packet length must "
2330 "be larger than %u and smaller than %u,"
2331 "as jumbo frame is enabled",
2332 (uint32_t)ETHER_MAX_LEN
,
2333 (uint32_t)I40E_FRAME_SIZE_MAX
);
2334 return I40E_ERR_CONFIG
;
2337 if (rxq
->max_pkt_len
< ETHER_MIN_LEN
||
2338 rxq
->max_pkt_len
> ETHER_MAX_LEN
) {
2339 PMD_DRV_LOG(ERR
, "maximum packet length must be "
2340 "larger than %u and smaller than %u, "
2341 "as jumbo frame is disabled",
2342 (uint32_t)ETHER_MIN_LEN
,
2343 (uint32_t)ETHER_MAX_LEN
);
2344 return I40E_ERR_CONFIG
;
2351 /* Init the RX queue in hardware */
2353 i40e_rx_queue_init(struct i40e_rx_queue
*rxq
)
2355 int err
= I40E_SUCCESS
;
2356 struct i40e_hw
*hw
= I40E_VSI_TO_HW(rxq
->vsi
);
2357 struct rte_eth_dev_data
*dev_data
= I40E_VSI_TO_DEV_DATA(rxq
->vsi
);
2358 uint16_t pf_q
= rxq
->reg_idx
;
2360 struct i40e_hmc_obj_rxq rx_ctx
;
2362 err
= i40e_rx_queue_config(rxq
);
2364 PMD_DRV_LOG(ERR
, "Failed to config RX queue");
2368 /* Clear the context structure first */
2369 memset(&rx_ctx
, 0, sizeof(struct i40e_hmc_obj_rxq
));
2370 rx_ctx
.dbuff
= rxq
->rx_buf_len
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
2371 rx_ctx
.hbuff
= rxq
->rx_hdr_len
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
2373 rx_ctx
.base
= rxq
->rx_ring_phys_addr
/ I40E_QUEUE_BASE_ADDR_UNIT
;
2374 rx_ctx
.qlen
= rxq
->nb_rx_desc
;
2375 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2378 rx_ctx
.dtype
= rxq
->hs_mode
;
2380 rx_ctx
.hsplit_0
= I40E_HEADER_SPLIT_ALL
;
2382 rx_ctx
.hsplit_0
= I40E_HEADER_SPLIT_NONE
;
2383 rx_ctx
.rxmax
= rxq
->max_pkt_len
;
2384 rx_ctx
.tphrdesc_ena
= 1;
2385 rx_ctx
.tphwdesc_ena
= 1;
2386 rx_ctx
.tphdata_ena
= 1;
2387 rx_ctx
.tphhead_ena
= 1;
2388 rx_ctx
.lrxqthresh
= 2;
2389 rx_ctx
.crcstrip
= (rxq
->crc_len
== 0) ? 1 : 0;
2391 /* showiv indicates if inner VLAN is stripped inside of tunnel
2392 * packet. When set it to 1, vlan information is stripped from
2393 * the inner header, but the hardware does not put it in the
2394 * descriptor. So set it zero by default.
2399 err
= i40e_clear_lan_rx_queue_context(hw
, pf_q
);
2400 if (err
!= I40E_SUCCESS
) {
2401 PMD_DRV_LOG(ERR
, "Failed to clear LAN RX queue context");
2404 err
= i40e_set_lan_rx_queue_context(hw
, pf_q
, &rx_ctx
);
2405 if (err
!= I40E_SUCCESS
) {
2406 PMD_DRV_LOG(ERR
, "Failed to set LAN RX queue context");
2410 rxq
->qrx_tail
= hw
->hw_addr
+ I40E_QRX_TAIL(pf_q
);
2412 buf_size
= (uint16_t)(rte_pktmbuf_data_room_size(rxq
->mp
) -
2413 RTE_PKTMBUF_HEADROOM
);
2415 /* Check if scattered RX needs to be used. */
2416 if ((rxq
->max_pkt_len
+ 2 * I40E_VLAN_TAG_SIZE
) > buf_size
) {
2417 dev_data
->scattered_rx
= 1;
2420 /* Init the RX tail regieter. */
2421 I40E_PCI_REG_WRITE(rxq
->qrx_tail
, rxq
->nb_rx_desc
- 1);
2427 i40e_dev_clear_queues(struct rte_eth_dev
*dev
)
2431 PMD_INIT_FUNC_TRACE();
2433 for (i
= 0; i
< dev
->data
->nb_tx_queues
; i
++) {
2434 if (!dev
->data
->tx_queues
[i
])
2436 i40e_tx_queue_release_mbufs(dev
->data
->tx_queues
[i
]);
2437 i40e_reset_tx_queue(dev
->data
->tx_queues
[i
]);
2440 for (i
= 0; i
< dev
->data
->nb_rx_queues
; i
++) {
2441 if (!dev
->data
->rx_queues
[i
])
2443 i40e_rx_queue_release_mbufs(dev
->data
->rx_queues
[i
]);
2444 i40e_reset_rx_queue(dev
->data
->rx_queues
[i
]);
2449 i40e_dev_free_queues(struct rte_eth_dev
*dev
)
2453 PMD_INIT_FUNC_TRACE();
2455 for (i
= 0; i
< dev
->data
->nb_rx_queues
; i
++) {
2456 if (!dev
->data
->rx_queues
[i
])
2458 i40e_dev_rx_queue_release(dev
->data
->rx_queues
[i
]);
2459 dev
->data
->rx_queues
[i
] = NULL
;
2461 dev
->data
->nb_rx_queues
= 0;
2463 for (i
= 0; i
< dev
->data
->nb_tx_queues
; i
++) {
2464 if (!dev
->data
->tx_queues
[i
])
2466 i40e_dev_tx_queue_release(dev
->data
->tx_queues
[i
]);
2467 dev
->data
->tx_queues
[i
] = NULL
;
2469 dev
->data
->nb_tx_queues
= 0;
2472 #define I40E_FDIR_NUM_TX_DESC I40E_MIN_RING_DESC
2473 #define I40E_FDIR_NUM_RX_DESC I40E_MIN_RING_DESC
2475 enum i40e_status_code
2476 i40e_fdir_setup_tx_resources(struct i40e_pf
*pf
)
2478 struct i40e_tx_queue
*txq
;
2479 const struct rte_memzone
*tz
= NULL
;
2481 struct rte_eth_dev
*dev
;
2484 PMD_DRV_LOG(ERR
, "PF is not available");
2485 return I40E_ERR_BAD_PTR
;
2488 dev
= pf
->adapter
->eth_dev
;
2490 /* Allocate the TX queue data structure. */
2491 txq
= rte_zmalloc_socket("i40e fdir tx queue",
2492 sizeof(struct i40e_tx_queue
),
2493 RTE_CACHE_LINE_SIZE
,
2496 PMD_DRV_LOG(ERR
, "Failed to allocate memory for "
2497 "tx queue structure.");
2498 return I40E_ERR_NO_MEMORY
;
2501 /* Allocate TX hardware ring descriptors. */
2502 ring_size
= sizeof(struct i40e_tx_desc
) * I40E_FDIR_NUM_TX_DESC
;
2503 ring_size
= RTE_ALIGN(ring_size
, I40E_DMA_MEM_ALIGN
);
2505 tz
= rte_eth_dma_zone_reserve(dev
, "fdir_tx_ring",
2506 I40E_FDIR_QUEUE_ID
, ring_size
,
2507 I40E_RING_BASE_ALIGN
, SOCKET_ID_ANY
);
2509 i40e_dev_tx_queue_release(txq
);
2510 PMD_DRV_LOG(ERR
, "Failed to reserve DMA memory for TX.");
2511 return I40E_ERR_NO_MEMORY
;
2514 txq
->nb_tx_desc
= I40E_FDIR_NUM_TX_DESC
;
2515 txq
->queue_id
= I40E_FDIR_QUEUE_ID
;
2516 txq
->reg_idx
= pf
->fdir
.fdir_vsi
->base_queue
;
2517 txq
->vsi
= pf
->fdir
.fdir_vsi
;
2519 txq
->tx_ring_phys_addr
= rte_mem_phy2mch(tz
->memseg_id
, tz
->phys_addr
);
2520 txq
->tx_ring
= (struct i40e_tx_desc
*)tz
->addr
;
2522 * don't need to allocate software ring and reset for the fdir
2523 * program queue just set the queue has been configured.
2528 return I40E_SUCCESS
;
2531 enum i40e_status_code
2532 i40e_fdir_setup_rx_resources(struct i40e_pf
*pf
)
2534 struct i40e_rx_queue
*rxq
;
2535 const struct rte_memzone
*rz
= NULL
;
2537 struct rte_eth_dev
*dev
;
2540 PMD_DRV_LOG(ERR
, "PF is not available");
2541 return I40E_ERR_BAD_PTR
;
2544 dev
= pf
->adapter
->eth_dev
;
2546 /* Allocate the RX queue data structure. */
2547 rxq
= rte_zmalloc_socket("i40e fdir rx queue",
2548 sizeof(struct i40e_rx_queue
),
2549 RTE_CACHE_LINE_SIZE
,
2552 PMD_DRV_LOG(ERR
, "Failed to allocate memory for "
2553 "rx queue structure.");
2554 return I40E_ERR_NO_MEMORY
;
2557 /* Allocate RX hardware ring descriptors. */
2558 ring_size
= sizeof(union i40e_rx_desc
) * I40E_FDIR_NUM_RX_DESC
;
2559 ring_size
= RTE_ALIGN(ring_size
, I40E_DMA_MEM_ALIGN
);
2561 rz
= rte_eth_dma_zone_reserve(dev
, "fdir_rx_ring",
2562 I40E_FDIR_QUEUE_ID
, ring_size
,
2563 I40E_RING_BASE_ALIGN
, SOCKET_ID_ANY
);
2565 i40e_dev_rx_queue_release(rxq
);
2566 PMD_DRV_LOG(ERR
, "Failed to reserve DMA memory for RX.");
2567 return I40E_ERR_NO_MEMORY
;
2570 rxq
->nb_rx_desc
= I40E_FDIR_NUM_RX_DESC
;
2571 rxq
->queue_id
= I40E_FDIR_QUEUE_ID
;
2572 rxq
->reg_idx
= pf
->fdir
.fdir_vsi
->base_queue
;
2573 rxq
->vsi
= pf
->fdir
.fdir_vsi
;
2575 rxq
->rx_ring_phys_addr
= rte_mem_phy2mch(rz
->memseg_id
, rz
->phys_addr
);
2576 rxq
->rx_ring
= (union i40e_rx_desc
*)rz
->addr
;
2579 * Don't need to allocate software ring and reset for the fdir
2580 * rx queue, just set the queue has been configured.
2585 return I40E_SUCCESS
;
2589 i40e_rxq_info_get(struct rte_eth_dev
*dev
, uint16_t queue_id
,
2590 struct rte_eth_rxq_info
*qinfo
)
2592 struct i40e_rx_queue
*rxq
;
2594 rxq
= dev
->data
->rx_queues
[queue_id
];
2596 qinfo
->mp
= rxq
->mp
;
2597 qinfo
->scattered_rx
= dev
->data
->scattered_rx
;
2598 qinfo
->nb_desc
= rxq
->nb_rx_desc
;
2600 qinfo
->conf
.rx_free_thresh
= rxq
->rx_free_thresh
;
2601 qinfo
->conf
.rx_drop_en
= rxq
->drop_en
;
2602 qinfo
->conf
.rx_deferred_start
= rxq
->rx_deferred_start
;
2606 i40e_txq_info_get(struct rte_eth_dev
*dev
, uint16_t queue_id
,
2607 struct rte_eth_txq_info
*qinfo
)
2609 struct i40e_tx_queue
*txq
;
2611 txq
= dev
->data
->tx_queues
[queue_id
];
2613 qinfo
->nb_desc
= txq
->nb_tx_desc
;
2615 qinfo
->conf
.tx_thresh
.pthresh
= txq
->pthresh
;
2616 qinfo
->conf
.tx_thresh
.hthresh
= txq
->hthresh
;
2617 qinfo
->conf
.tx_thresh
.wthresh
= txq
->wthresh
;
2619 qinfo
->conf
.tx_free_thresh
= txq
->tx_free_thresh
;
2620 qinfo
->conf
.tx_rs_thresh
= txq
->tx_rs_thresh
;
2621 qinfo
->conf
.txq_flags
= txq
->txq_flags
;
2622 qinfo
->conf
.tx_deferred_start
= txq
->tx_deferred_start
;
2625 void __attribute__((cold
))
2626 i40e_set_rx_function(struct rte_eth_dev
*dev
)
2628 struct i40e_adapter
*ad
=
2629 I40E_DEV_PRIVATE_TO_ADAPTER(dev
->data
->dev_private
);
2630 uint16_t rx_using_sse
, i
;
2631 /* In order to allow Vector Rx there are a few configuration
2632 * conditions to be met and Rx Bulk Allocation should be allowed.
2634 if (rte_eal_process_type() == RTE_PROC_PRIMARY
) {
2635 if (i40e_rx_vec_dev_conf_condition_check(dev
) ||
2636 !ad
->rx_bulk_alloc_allowed
) {
2637 PMD_INIT_LOG(DEBUG
, "Port[%d] doesn't meet"
2638 " Vector Rx preconditions",
2639 dev
->data
->port_id
);
2641 ad
->rx_vec_allowed
= false;
2643 if (ad
->rx_vec_allowed
) {
2644 for (i
= 0; i
< dev
->data
->nb_rx_queues
; i
++) {
2645 struct i40e_rx_queue
*rxq
=
2646 dev
->data
->rx_queues
[i
];
2648 if (rxq
&& i40e_rxq_vec_setup(rxq
)) {
2649 ad
->rx_vec_allowed
= false;
2656 if (dev
->data
->scattered_rx
) {
2657 /* Set the non-LRO scattered callback: there are Vector and
2658 * single allocation versions.
2660 if (ad
->rx_vec_allowed
) {
2661 PMD_INIT_LOG(DEBUG
, "Using Vector Scattered Rx "
2662 "callback (port=%d).",
2663 dev
->data
->port_id
);
2665 dev
->rx_pkt_burst
= i40e_recv_scattered_pkts_vec
;
2667 PMD_INIT_LOG(DEBUG
, "Using a Scattered with bulk "
2668 "allocation callback (port=%d).",
2669 dev
->data
->port_id
);
2670 dev
->rx_pkt_burst
= i40e_recv_scattered_pkts
;
2672 /* If parameters allow we are going to choose between the following
2676 * - Single buffer allocation (the simplest one)
2678 } else if (ad
->rx_vec_allowed
) {
2679 PMD_INIT_LOG(DEBUG
, "Vector rx enabled, please make sure RX "
2680 "burst size no less than %d (port=%d).",
2681 RTE_I40E_DESCS_PER_LOOP
,
2682 dev
->data
->port_id
);
2684 dev
->rx_pkt_burst
= i40e_recv_pkts_vec
;
2685 } else if (ad
->rx_bulk_alloc_allowed
) {
2686 PMD_INIT_LOG(DEBUG
, "Rx Burst Bulk Alloc Preconditions are "
2687 "satisfied. Rx Burst Bulk Alloc function "
2688 "will be used on port=%d.",
2689 dev
->data
->port_id
);
2691 dev
->rx_pkt_burst
= i40e_recv_pkts_bulk_alloc
;
2693 PMD_INIT_LOG(DEBUG
, "Rx Burst Bulk Alloc Preconditions are not "
2694 "satisfied, or Scattered Rx is requested "
2696 dev
->data
->port_id
);
2698 dev
->rx_pkt_burst
= i40e_recv_pkts
;
2701 /* Propagate information about RX function choice through all queues. */
2702 if (rte_eal_process_type() == RTE_PROC_PRIMARY
) {
2704 (dev
->rx_pkt_burst
== i40e_recv_scattered_pkts_vec
||
2705 dev
->rx_pkt_burst
== i40e_recv_pkts_vec
);
2707 for (i
= 0; i
< dev
->data
->nb_rx_queues
; i
++) {
2708 struct i40e_rx_queue
*rxq
= dev
->data
->rx_queues
[i
];
2711 rxq
->rx_using_sse
= rx_using_sse
;
2716 void __attribute__((cold
))
2717 i40e_set_tx_function_flag(struct rte_eth_dev
*dev
, struct i40e_tx_queue
*txq
)
2719 struct i40e_adapter
*ad
=
2720 I40E_DEV_PRIVATE_TO_ADAPTER(dev
->data
->dev_private
);
2722 /* Use a simple Tx queue (no offloads, no multi segs) if possible */
2723 if (((txq
->txq_flags
& I40E_SIMPLE_FLAGS
) == I40E_SIMPLE_FLAGS
)
2724 && (txq
->tx_rs_thresh
>= RTE_PMD_I40E_TX_MAX_BURST
)) {
2725 if (txq
->tx_rs_thresh
<= RTE_I40E_TX_MAX_FREE_BUF_SZ
) {
2726 PMD_INIT_LOG(DEBUG
, "Vector tx"
2727 " can be enabled on this txq.");
2730 ad
->tx_vec_allowed
= false;
2733 ad
->tx_simple_allowed
= false;
2737 void __attribute__((cold
))
2738 i40e_set_tx_function(struct rte_eth_dev
*dev
)
2740 struct i40e_adapter
*ad
=
2741 I40E_DEV_PRIVATE_TO_ADAPTER(dev
->data
->dev_private
);
2744 if (rte_eal_process_type() == RTE_PROC_PRIMARY
) {
2745 if (ad
->tx_vec_allowed
) {
2746 for (i
= 0; i
< dev
->data
->nb_tx_queues
; i
++) {
2747 struct i40e_tx_queue
*txq
=
2748 dev
->data
->tx_queues
[i
];
2750 if (txq
&& i40e_txq_vec_setup(txq
)) {
2751 ad
->tx_vec_allowed
= false;
2758 if (ad
->tx_simple_allowed
) {
2759 if (ad
->tx_vec_allowed
) {
2760 PMD_INIT_LOG(DEBUG
, "Vector tx finally be used.");
2761 dev
->tx_pkt_burst
= i40e_xmit_pkts_vec
;
2763 PMD_INIT_LOG(DEBUG
, "Simple tx finally be used.");
2764 dev
->tx_pkt_burst
= i40e_xmit_pkts_simple
;
2767 PMD_INIT_LOG(DEBUG
, "Xmit tx finally be used.");
2768 dev
->tx_pkt_burst
= i40e_xmit_pkts
;
2772 /* Stubs needed for linkage when CONFIG_RTE_I40E_INC_VECTOR is set to 'n' */
2773 int __attribute__((weak
))
2774 i40e_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused
*dev
)
2779 uint16_t __attribute__((weak
))
2781 void __rte_unused
*rx_queue
,
2782 struct rte_mbuf __rte_unused
**rx_pkts
,
2783 uint16_t __rte_unused nb_pkts
)
2788 uint16_t __attribute__((weak
))
2789 i40e_recv_scattered_pkts_vec(
2790 void __rte_unused
*rx_queue
,
2791 struct rte_mbuf __rte_unused
**rx_pkts
,
2792 uint16_t __rte_unused nb_pkts
)
2797 int __attribute__((weak
))
2798 i40e_rxq_vec_setup(struct i40e_rx_queue __rte_unused
*rxq
)
2803 int __attribute__((weak
))
2804 i40e_txq_vec_setup(struct i40e_tx_queue __rte_unused
*txq
)
2809 void __attribute__((weak
))
2810 i40e_rx_queue_release_mbufs_vec(struct i40e_rx_queue __rte_unused
*rxq
)
2815 uint16_t __attribute__((weak
))
2816 i40e_xmit_pkts_vec(void __rte_unused
*tx_queue
,
2817 struct rte_mbuf __rte_unused
**tx_pkts
,
2818 uint16_t __rte_unused nb_pkts
)