1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
13 #include <sys/queue.h>
15 #include <rte_string_fns.h>
16 #include <rte_memzone.h>
18 #include <rte_malloc.h>
19 #include <rte_ether.h>
20 #include <ethdev_driver.h>
29 #include "iavf_rxtx.h"
30 #include "iavf_ipsec_crypto.h"
31 #include "rte_pmd_iavf.h"
33 /* Offset of mbuf dynamic field for protocol extraction's metadata */
34 int rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = -1;
36 /* Mask of mbuf dynamic flags for protocol extraction's type */
37 uint64_t rte_pmd_ifd_dynflag_proto_xtr_vlan_mask;
38 uint64_t rte_pmd_ifd_dynflag_proto_xtr_ipv4_mask;
39 uint64_t rte_pmd_ifd_dynflag_proto_xtr_ipv6_mask;
40 uint64_t rte_pmd_ifd_dynflag_proto_xtr_ipv6_flow_mask;
41 uint64_t rte_pmd_ifd_dynflag_proto_xtr_tcp_mask;
42 uint64_t rte_pmd_ifd_dynflag_proto_xtr_ip_offset_mask;
43 uint64_t rte_pmd_ifd_dynflag_proto_xtr_ipsec_crypto_said_mask;
46 iavf_proto_xtr_type_to_rxdid(uint8_t flex_type)
48 static uint8_t rxdid_map[] = {
49 [IAVF_PROTO_XTR_NONE] = IAVF_RXDID_COMMS_OVS_1,
50 [IAVF_PROTO_XTR_VLAN] = IAVF_RXDID_COMMS_AUX_VLAN,
51 [IAVF_PROTO_XTR_IPV4] = IAVF_RXDID_COMMS_AUX_IPV4,
52 [IAVF_PROTO_XTR_IPV6] = IAVF_RXDID_COMMS_AUX_IPV6,
53 [IAVF_PROTO_XTR_IPV6_FLOW] = IAVF_RXDID_COMMS_AUX_IPV6_FLOW,
54 [IAVF_PROTO_XTR_TCP] = IAVF_RXDID_COMMS_AUX_TCP,
55 [IAVF_PROTO_XTR_IP_OFFSET] = IAVF_RXDID_COMMS_AUX_IP_OFFSET,
56 [IAVF_PROTO_XTR_IPSEC_CRYPTO_SAID] =
57 IAVF_RXDID_COMMS_IPSEC_CRYPTO,
60 return flex_type < RTE_DIM(rxdid_map) ?
61 rxdid_map[flex_type] : IAVF_RXDID_COMMS_OVS_1;
65 iavf_monitor_callback(const uint64_t value,
66 const uint64_t arg[RTE_POWER_MONITOR_OPAQUE_SZ] __rte_unused)
68 const uint64_t m = rte_cpu_to_le_64(1 << IAVF_RX_DESC_STATUS_DD_SHIFT);
70 * we expect the DD bit to be set to 1 if this descriptor was already
73 return (value & m) == m ? -1 : 0;
77 iavf_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc)
79 struct iavf_rx_queue *rxq = rx_queue;
80 volatile union iavf_rx_desc *rxdp;
84 rxdp = &rxq->rx_ring[desc];
85 /* watch for changes in status bit */
86 pmc->addr = &rxdp->wb.qword1.status_error_len;
88 /* comparison callback */
89 pmc->fn = iavf_monitor_callback;
91 /* registers are 64-bit */
92 pmc->size = sizeof(uint64_t);
98 check_rx_thresh(uint16_t nb_desc, uint16_t thresh)
100 /* The following constraints must be satisfied:
101 * thresh < rxq->nb_rx_desc
103 if (thresh >= nb_desc) {
104 PMD_INIT_LOG(ERR, "rx_free_thresh (%u) must be less than %u",
112 check_tx_thresh(uint16_t nb_desc, uint16_t tx_rs_thresh,
113 uint16_t tx_free_thresh)
115 /* TX descriptors will have their RS bit set after tx_rs_thresh
116 * descriptors have been used. The TX descriptor ring will be cleaned
117 * after tx_free_thresh descriptors are used or if the number of
118 * descriptors required to transmit a packet is greater than the
119 * number of free TX descriptors.
121 * The following constraints must be satisfied:
122 * - tx_rs_thresh must be less than the size of the ring minus 2.
123 * - tx_free_thresh must be less than the size of the ring minus 3.
124 * - tx_rs_thresh must be less than or equal to tx_free_thresh.
125 * - tx_rs_thresh must be a divisor of the ring size.
127 * One descriptor in the TX ring is used as a sentinel to avoid a H/W
128 * race condition, hence the maximum threshold constraints. When set
129 * to zero use default values.
131 if (tx_rs_thresh >= (nb_desc - 2)) {
132 PMD_INIT_LOG(ERR, "tx_rs_thresh (%u) must be less than the "
133 "number of TX descriptors (%u) minus 2",
134 tx_rs_thresh, nb_desc);
137 if (tx_free_thresh >= (nb_desc - 3)) {
138 PMD_INIT_LOG(ERR, "tx_free_thresh (%u) must be less than the "
139 "number of TX descriptors (%u) minus 3.",
140 tx_free_thresh, nb_desc);
143 if (tx_rs_thresh > tx_free_thresh) {
144 PMD_INIT_LOG(ERR, "tx_rs_thresh (%u) must be less than or "
145 "equal to tx_free_thresh (%u).",
146 tx_rs_thresh, tx_free_thresh);
149 if ((nb_desc % tx_rs_thresh) != 0) {
150 PMD_INIT_LOG(ERR, "tx_rs_thresh (%u) must be a divisor of the "
151 "number of TX descriptors (%u).",
152 tx_rs_thresh, nb_desc);
160 check_rx_vec_allow(struct iavf_rx_queue *rxq)
162 if (rxq->rx_free_thresh >= IAVF_VPMD_RX_MAX_BURST &&
163 rxq->nb_rx_desc % rxq->rx_free_thresh == 0) {
164 PMD_INIT_LOG(DEBUG, "Vector Rx can be enabled on this rxq.");
168 PMD_INIT_LOG(DEBUG, "Vector Rx cannot be enabled on this rxq.");
173 check_tx_vec_allow(struct iavf_tx_queue *txq)
175 if (!(txq->offloads & IAVF_TX_NO_VECTOR_FLAGS) &&
176 txq->rs_thresh >= IAVF_VPMD_TX_MAX_BURST &&
177 txq->rs_thresh <= IAVF_VPMD_TX_MAX_FREE_BUF) {
178 PMD_INIT_LOG(DEBUG, "Vector tx can be enabled on this txq.");
181 PMD_INIT_LOG(DEBUG, "Vector Tx cannot be enabled on this txq.");
186 check_rx_bulk_allow(struct iavf_rx_queue *rxq)
190 if (!(rxq->rx_free_thresh >= IAVF_RX_MAX_BURST)) {
191 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
192 "rxq->rx_free_thresh=%d, "
193 "IAVF_RX_MAX_BURST=%d",
194 rxq->rx_free_thresh, IAVF_RX_MAX_BURST);
196 } else if (rxq->nb_rx_desc % rxq->rx_free_thresh != 0) {
197 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
198 "rxq->nb_rx_desc=%d, "
199 "rxq->rx_free_thresh=%d",
200 rxq->nb_rx_desc, rxq->rx_free_thresh);
207 reset_rx_queue(struct iavf_rx_queue *rxq)
215 len = rxq->nb_rx_desc + IAVF_RX_MAX_BURST;
217 for (i = 0; i < len * sizeof(union iavf_rx_desc); i++)
218 ((volatile char *)rxq->rx_ring)[i] = 0;
220 memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
222 for (i = 0; i < IAVF_RX_MAX_BURST; i++)
223 rxq->sw_ring[rxq->nb_rx_desc + i] = &rxq->fake_mbuf;
226 rxq->rx_nb_avail = 0;
227 rxq->rx_next_avail = 0;
228 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
233 rte_pktmbuf_free(rxq->pkt_first_seg);
235 rxq->pkt_first_seg = NULL;
236 rxq->pkt_last_seg = NULL;
238 rxq->rxrearm_start = 0;
242 reset_tx_queue(struct iavf_tx_queue *txq)
244 struct iavf_tx_entry *txe;
249 PMD_DRV_LOG(DEBUG, "Pointer to txq is NULL");
254 size = sizeof(struct iavf_tx_desc) * txq->nb_tx_desc;
255 for (i = 0; i < size; i++)
256 ((volatile char *)txq->tx_ring)[i] = 0;
258 prev = (uint16_t)(txq->nb_tx_desc - 1);
259 for (i = 0; i < txq->nb_tx_desc; i++) {
260 txq->tx_ring[i].cmd_type_offset_bsz =
261 rte_cpu_to_le_64(IAVF_TX_DESC_DTYPE_DESC_DONE);
264 txe[prev].next_id = i;
271 txq->last_desc_cleaned = txq->nb_tx_desc - 1;
272 txq->nb_free = txq->nb_tx_desc - 1;
274 txq->next_dd = txq->rs_thresh - 1;
275 txq->next_rs = txq->rs_thresh - 1;
279 alloc_rxq_mbufs(struct iavf_rx_queue *rxq)
281 volatile union iavf_rx_desc *rxd;
282 struct rte_mbuf *mbuf = NULL;
286 for (i = 0; i < rxq->nb_rx_desc; i++) {
287 mbuf = rte_mbuf_raw_alloc(rxq->mp);
288 if (unlikely(!mbuf)) {
289 for (j = 0; j < i; j++) {
290 rte_pktmbuf_free_seg(rxq->sw_ring[j]);
291 rxq->sw_ring[j] = NULL;
293 PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX");
297 rte_mbuf_refcnt_set(mbuf, 1);
299 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
301 mbuf->port = rxq->port_id;
304 rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
306 rxd = &rxq->rx_ring[i];
307 rxd->read.pkt_addr = dma_addr;
308 rxd->read.hdr_addr = 0;
309 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
314 rxq->sw_ring[i] = mbuf;
321 release_rxq_mbufs(struct iavf_rx_queue *rxq)
328 for (i = 0; i < rxq->nb_rx_desc; i++) {
329 if (rxq->sw_ring[i]) {
330 rte_pktmbuf_free_seg(rxq->sw_ring[i]);
331 rxq->sw_ring[i] = NULL;
336 if (rxq->rx_nb_avail == 0)
338 for (i = 0; i < rxq->rx_nb_avail; i++) {
339 struct rte_mbuf *mbuf;
341 mbuf = rxq->rx_stage[rxq->rx_next_avail + i];
342 rte_pktmbuf_free_seg(mbuf);
344 rxq->rx_nb_avail = 0;
348 release_txq_mbufs(struct iavf_tx_queue *txq)
352 if (!txq || !txq->sw_ring) {
353 PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL");
357 for (i = 0; i < txq->nb_tx_desc; i++) {
358 if (txq->sw_ring[i].mbuf) {
359 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
360 txq->sw_ring[i].mbuf = NULL;
365 static const struct iavf_rxq_ops def_rxq_ops = {
366 .release_mbufs = release_rxq_mbufs,
369 static const struct iavf_txq_ops def_txq_ops = {
370 .release_mbufs = release_txq_mbufs,
374 iavf_rxd_to_pkt_fields_by_comms_ovs(__rte_unused struct iavf_rx_queue *rxq,
376 volatile union iavf_rx_flex_desc *rxdp)
378 volatile struct iavf_32b_rx_flex_desc_comms_ovs *desc =
379 (volatile struct iavf_32b_rx_flex_desc_comms_ovs *)rxdp;
380 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
384 if (desc->flow_id != 0xFFFFFFFF) {
385 mb->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
386 mb->hash.fdir.hi = rte_le_to_cpu_32(desc->flow_id);
389 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
390 stat_err = rte_le_to_cpu_16(desc->status_error0);
391 if (likely(stat_err & (1 << IAVF_RX_FLEX_DESC_STATUS0_RSS_VALID_S))) {
392 mb->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
393 mb->hash.rss = rte_le_to_cpu_32(desc->rss_hash);
399 iavf_rxd_to_pkt_fields_by_comms_aux_v1(struct iavf_rx_queue *rxq,
401 volatile union iavf_rx_flex_desc *rxdp)
403 volatile struct iavf_32b_rx_flex_desc_comms *desc =
404 (volatile struct iavf_32b_rx_flex_desc_comms *)rxdp;
407 stat_err = rte_le_to_cpu_16(desc->status_error0);
408 if (likely(stat_err & (1 << IAVF_RX_FLEX_DESC_STATUS0_RSS_VALID_S))) {
409 mb->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
410 mb->hash.rss = rte_le_to_cpu_32(desc->rss_hash);
413 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
414 if (desc->flow_id != 0xFFFFFFFF) {
415 mb->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
416 mb->hash.fdir.hi = rte_le_to_cpu_32(desc->flow_id);
419 if (rxq->xtr_ol_flag) {
420 uint32_t metadata = 0;
422 stat_err = rte_le_to_cpu_16(desc->status_error1);
424 if (stat_err & (1 << IAVF_RX_FLEX_DESC_STATUS1_XTRMD4_VALID_S))
425 metadata = rte_le_to_cpu_16(desc->flex_ts.flex.aux0);
427 if (stat_err & (1 << IAVF_RX_FLEX_DESC_STATUS1_XTRMD5_VALID_S))
429 rte_le_to_cpu_16(desc->flex_ts.flex.aux1) << 16;
432 mb->ol_flags |= rxq->xtr_ol_flag;
434 *RTE_PMD_IFD_DYNF_PROTO_XTR_METADATA(mb) = metadata;
441 iavf_rxd_to_pkt_fields_by_comms_aux_v2(struct iavf_rx_queue *rxq,
443 volatile union iavf_rx_flex_desc *rxdp)
445 volatile struct iavf_32b_rx_flex_desc_comms *desc =
446 (volatile struct iavf_32b_rx_flex_desc_comms *)rxdp;
449 stat_err = rte_le_to_cpu_16(desc->status_error0);
450 if (likely(stat_err & (1 << IAVF_RX_FLEX_DESC_STATUS0_RSS_VALID_S))) {
451 mb->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
452 mb->hash.rss = rte_le_to_cpu_32(desc->rss_hash);
455 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
456 if (desc->flow_id != 0xFFFFFFFF) {
457 mb->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
458 mb->hash.fdir.hi = rte_le_to_cpu_32(desc->flow_id);
461 if (rxq->xtr_ol_flag) {
462 uint32_t metadata = 0;
464 if (desc->flex_ts.flex.aux0 != 0xFFFF)
465 metadata = rte_le_to_cpu_16(desc->flex_ts.flex.aux0);
466 else if (desc->flex_ts.flex.aux1 != 0xFFFF)
467 metadata = rte_le_to_cpu_16(desc->flex_ts.flex.aux1);
470 mb->ol_flags |= rxq->xtr_ol_flag;
472 *RTE_PMD_IFD_DYNF_PROTO_XTR_METADATA(mb) = metadata;
479 iavf_rxd_to_pkt_fields_t rxd_to_pkt_fields_ops[IAVF_RXDID_LAST + 1] = {
480 [IAVF_RXDID_COMMS_AUX_VLAN] = iavf_rxd_to_pkt_fields_by_comms_aux_v1,
481 [IAVF_RXDID_COMMS_AUX_IPV4] = iavf_rxd_to_pkt_fields_by_comms_aux_v1,
482 [IAVF_RXDID_COMMS_AUX_IPV6] = iavf_rxd_to_pkt_fields_by_comms_aux_v1,
483 [IAVF_RXDID_COMMS_AUX_IPV6_FLOW] =
484 iavf_rxd_to_pkt_fields_by_comms_aux_v1,
485 [IAVF_RXDID_COMMS_AUX_TCP] = iavf_rxd_to_pkt_fields_by_comms_aux_v1,
486 [IAVF_RXDID_COMMS_AUX_IP_OFFSET] =
487 iavf_rxd_to_pkt_fields_by_comms_aux_v2,
488 [IAVF_RXDID_COMMS_IPSEC_CRYPTO] =
489 iavf_rxd_to_pkt_fields_by_comms_aux_v2,
490 [IAVF_RXDID_COMMS_OVS_1] = iavf_rxd_to_pkt_fields_by_comms_ovs,
494 iavf_select_rxd_to_pkt_fields_handler(struct iavf_rx_queue *rxq, uint32_t rxdid)
499 case IAVF_RXDID_COMMS_AUX_VLAN:
500 rxq->xtr_ol_flag = rte_pmd_ifd_dynflag_proto_xtr_vlan_mask;
502 case IAVF_RXDID_COMMS_AUX_IPV4:
503 rxq->xtr_ol_flag = rte_pmd_ifd_dynflag_proto_xtr_ipv4_mask;
505 case IAVF_RXDID_COMMS_AUX_IPV6:
506 rxq->xtr_ol_flag = rte_pmd_ifd_dynflag_proto_xtr_ipv6_mask;
508 case IAVF_RXDID_COMMS_AUX_IPV6_FLOW:
510 rte_pmd_ifd_dynflag_proto_xtr_ipv6_flow_mask;
512 case IAVF_RXDID_COMMS_AUX_TCP:
513 rxq->xtr_ol_flag = rte_pmd_ifd_dynflag_proto_xtr_tcp_mask;
515 case IAVF_RXDID_COMMS_AUX_IP_OFFSET:
517 rte_pmd_ifd_dynflag_proto_xtr_ip_offset_mask;
519 case IAVF_RXDID_COMMS_IPSEC_CRYPTO:
521 rte_pmd_ifd_dynflag_proto_xtr_ipsec_crypto_said_mask;
523 case IAVF_RXDID_COMMS_OVS_1:
526 /* update this according to the RXDID for FLEX_DESC_NONE */
527 rxq->rxdid = IAVF_RXDID_COMMS_OVS_1;
531 if (!rte_pmd_ifd_dynf_proto_xtr_metadata_avail())
532 rxq->xtr_ol_flag = 0;
536 iavf_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
537 uint16_t nb_desc, unsigned int socket_id,
538 const struct rte_eth_rxconf *rx_conf,
539 struct rte_mempool *mp)
541 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
542 struct iavf_adapter *ad =
543 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
544 struct iavf_info *vf =
545 IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
546 struct iavf_vsi *vsi = &vf->vsi;
547 struct iavf_rx_queue *rxq;
548 const struct rte_memzone *mz;
552 uint16_t rx_free_thresh;
555 PMD_INIT_FUNC_TRACE();
557 offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
559 if (nb_desc % IAVF_ALIGN_RING_DESC != 0 ||
560 nb_desc > IAVF_MAX_RING_DESC ||
561 nb_desc < IAVF_MIN_RING_DESC) {
562 PMD_INIT_LOG(ERR, "Number (%u) of receive descriptors is "
567 /* Check free threshold */
568 rx_free_thresh = (rx_conf->rx_free_thresh == 0) ?
569 IAVF_DEFAULT_RX_FREE_THRESH :
570 rx_conf->rx_free_thresh;
571 if (check_rx_thresh(nb_desc, rx_free_thresh) != 0)
574 /* Free memory if needed */
575 if (dev->data->rx_queues[queue_idx]) {
576 iavf_dev_rx_queue_release(dev, queue_idx);
577 dev->data->rx_queues[queue_idx] = NULL;
580 /* Allocate the rx queue data structure */
581 rxq = rte_zmalloc_socket("iavf rxq",
582 sizeof(struct iavf_rx_queue),
586 PMD_INIT_LOG(ERR, "Failed to allocate memory for "
587 "rx queue data structure");
591 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
592 proto_xtr = vf->proto_xtr ? vf->proto_xtr[queue_idx] :
594 rxq->rxdid = iavf_proto_xtr_type_to_rxdid(proto_xtr);
595 rxq->proto_xtr = proto_xtr;
597 rxq->rxdid = IAVF_RXDID_LEGACY_1;
598 rxq->proto_xtr = IAVF_PROTO_XTR_NONE;
601 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
602 struct virtchnl_vlan_supported_caps *stripping_support =
603 &vf->vlan_v2_caps.offloads.stripping_support;
604 uint32_t stripping_cap;
606 if (stripping_support->outer)
607 stripping_cap = stripping_support->outer;
609 stripping_cap = stripping_support->inner;
611 if (stripping_cap & VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1)
612 rxq->rx_flags = IAVF_RX_FLAGS_VLAN_TAG_LOC_L2TAG1;
613 else if (stripping_cap & VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2)
614 rxq->rx_flags = IAVF_RX_FLAGS_VLAN_TAG_LOC_L2TAG2_2;
616 rxq->rx_flags = IAVF_RX_FLAGS_VLAN_TAG_LOC_L2TAG1;
619 iavf_select_rxd_to_pkt_fields_handler(rxq, rxq->rxdid);
622 rxq->nb_rx_desc = nb_desc;
623 rxq->rx_free_thresh = rx_free_thresh;
624 rxq->queue_id = queue_idx;
625 rxq->port_id = dev->data->port_id;
626 rxq->rx_deferred_start = rx_conf->rx_deferred_start;
629 rxq->offloads = offloads;
631 if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
632 rxq->crc_len = RTE_ETHER_CRC_LEN;
636 len = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
637 rxq->rx_buf_len = RTE_ALIGN_FLOOR(len, (1 << IAVF_RXQ_CTX_DBUFF_SHIFT));
639 /* Allocate the software ring. */
640 len = nb_desc + IAVF_RX_MAX_BURST;
642 rte_zmalloc_socket("iavf rx sw ring",
643 sizeof(struct rte_mbuf *) * len,
647 PMD_INIT_LOG(ERR, "Failed to allocate memory for SW ring");
652 /* Allocate the maximum number of RX ring hardware descriptor with
653 * a little more to support bulk allocate.
655 len = IAVF_MAX_RING_DESC + IAVF_RX_MAX_BURST;
656 ring_size = RTE_ALIGN(len * sizeof(union iavf_rx_desc),
658 mz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
659 ring_size, IAVF_RING_BASE_ALIGN,
662 PMD_INIT_LOG(ERR, "Failed to reserve DMA memory for RX");
663 rte_free(rxq->sw_ring);
667 /* Zero all the descriptors in the ring. */
668 memset(mz->addr, 0, ring_size);
669 rxq->rx_ring_phys_addr = mz->iova;
670 rxq->rx_ring = (union iavf_rx_desc *)mz->addr;
675 dev->data->rx_queues[queue_idx] = rxq;
676 rxq->qrx_tail = hw->hw_addr + IAVF_QRX_TAIL1(rxq->queue_id);
677 rxq->ops = &def_rxq_ops;
679 if (check_rx_bulk_allow(rxq) == true) {
680 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
681 "satisfied. Rx Burst Bulk Alloc function will be "
682 "used on port=%d, queue=%d.",
683 rxq->port_id, rxq->queue_id);
685 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
686 "not satisfied, Scattered Rx is requested "
687 "on port=%d, queue=%d.",
688 rxq->port_id, rxq->queue_id);
689 ad->rx_bulk_alloc_allowed = false;
692 if (check_rx_vec_allow(rxq) == false)
693 ad->rx_vec_allowed = false;
699 iavf_dev_tx_queue_setup(struct rte_eth_dev *dev,
702 unsigned int socket_id,
703 const struct rte_eth_txconf *tx_conf)
705 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
706 struct iavf_adapter *adapter =
707 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
708 struct iavf_info *vf =
709 IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
710 struct iavf_tx_queue *txq;
711 const struct rte_memzone *mz;
713 uint16_t tx_rs_thresh, tx_free_thresh;
716 PMD_INIT_FUNC_TRACE();
718 offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
720 if (nb_desc % IAVF_ALIGN_RING_DESC != 0 ||
721 nb_desc > IAVF_MAX_RING_DESC ||
722 nb_desc < IAVF_MIN_RING_DESC) {
723 PMD_INIT_LOG(ERR, "Number (%u) of transmit descriptors is "
728 tx_rs_thresh = (uint16_t)((tx_conf->tx_rs_thresh) ?
729 tx_conf->tx_rs_thresh : DEFAULT_TX_RS_THRESH);
730 tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
731 tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
732 if (check_tx_thresh(nb_desc, tx_rs_thresh, tx_free_thresh) != 0)
735 /* Free memory if needed. */
736 if (dev->data->tx_queues[queue_idx]) {
737 iavf_dev_tx_queue_release(dev, queue_idx);
738 dev->data->tx_queues[queue_idx] = NULL;
741 /* Allocate the TX queue data structure. */
742 txq = rte_zmalloc_socket("iavf txq",
743 sizeof(struct iavf_tx_queue),
747 PMD_INIT_LOG(ERR, "Failed to allocate memory for "
748 "tx queue structure");
752 if (adapter->vf.vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
753 struct virtchnl_vlan_supported_caps *insertion_support =
754 &adapter->vf.vlan_v2_caps.offloads.insertion_support;
755 uint32_t insertion_cap;
757 if (insertion_support->outer)
758 insertion_cap = insertion_support->outer;
760 insertion_cap = insertion_support->inner;
762 if (insertion_cap & VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1)
763 txq->vlan_flag = IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG1;
764 else if (insertion_cap & VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2)
765 txq->vlan_flag = IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG2;
767 txq->vlan_flag = IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG1;
770 txq->nb_tx_desc = nb_desc;
771 txq->rs_thresh = tx_rs_thresh;
772 txq->free_thresh = tx_free_thresh;
773 txq->queue_id = queue_idx;
774 txq->port_id = dev->data->port_id;
775 txq->offloads = offloads;
776 txq->tx_deferred_start = tx_conf->tx_deferred_start;
778 if (iavf_ipsec_crypto_supported(adapter))
779 txq->ipsec_crypto_pkt_md_offset =
780 iavf_security_get_pkt_md_offset(adapter);
782 /* Allocate software ring */
784 rte_zmalloc_socket("iavf tx sw ring",
785 sizeof(struct iavf_tx_entry) * nb_desc,
789 PMD_INIT_LOG(ERR, "Failed to allocate memory for SW TX ring");
794 /* Allocate TX hardware ring descriptors. */
795 ring_size = sizeof(struct iavf_tx_desc) * IAVF_MAX_RING_DESC;
796 ring_size = RTE_ALIGN(ring_size, IAVF_DMA_MEM_ALIGN);
797 mz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
798 ring_size, IAVF_RING_BASE_ALIGN,
801 PMD_INIT_LOG(ERR, "Failed to reserve DMA memory for TX");
802 rte_free(txq->sw_ring);
806 txq->tx_ring_phys_addr = mz->iova;
807 txq->tx_ring = (struct iavf_tx_desc *)mz->addr;
812 dev->data->tx_queues[queue_idx] = txq;
813 txq->qtx_tail = hw->hw_addr + IAVF_QTX_TAIL1(queue_idx);
814 txq->ops = &def_txq_ops;
816 if (check_tx_vec_allow(txq) == false) {
817 struct iavf_adapter *ad =
818 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
819 ad->tx_vec_allowed = false;
822 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS &&
823 vf->tm_conf.committed) {
825 for (tc = 0; tc < vf->qos_cap->num_elem; tc++) {
826 if (txq->queue_id >= vf->qtc_map[tc].start_queue_id &&
827 txq->queue_id < (vf->qtc_map[tc].start_queue_id +
828 vf->qtc_map[tc].queue_count))
831 if (tc >= vf->qos_cap->num_elem) {
832 PMD_INIT_LOG(ERR, "Queue TC mapping is not correct");
842 iavf_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
844 struct iavf_adapter *adapter =
845 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
846 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
847 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
848 struct iavf_rx_queue *rxq;
851 PMD_DRV_FUNC_TRACE();
853 if (rx_queue_id >= dev->data->nb_rx_queues)
856 rxq = dev->data->rx_queues[rx_queue_id];
858 err = alloc_rxq_mbufs(rxq);
860 PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
866 /* Init the RX tail register. */
867 IAVF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
868 IAVF_WRITE_FLUSH(hw);
870 /* Ready to switch the queue on */
872 err = iavf_switch_queue(adapter, rx_queue_id, true, true);
874 err = iavf_switch_queue_lv(adapter, rx_queue_id, true, true);
877 release_rxq_mbufs(rxq);
878 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
881 dev->data->rx_queue_state[rx_queue_id] =
882 RTE_ETH_QUEUE_STATE_STARTED;
889 iavf_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
891 struct iavf_adapter *adapter =
892 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
893 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
894 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
895 struct iavf_tx_queue *txq;
898 PMD_DRV_FUNC_TRACE();
900 if (tx_queue_id >= dev->data->nb_tx_queues)
903 txq = dev->data->tx_queues[tx_queue_id];
905 /* Init the RX tail register. */
906 IAVF_PCI_REG_WRITE(txq->qtx_tail, 0);
907 IAVF_WRITE_FLUSH(hw);
909 /* Ready to switch the queue on */
911 err = iavf_switch_queue(adapter, tx_queue_id, false, true);
913 err = iavf_switch_queue_lv(adapter, tx_queue_id, false, true);
916 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
919 dev->data->tx_queue_state[tx_queue_id] =
920 RTE_ETH_QUEUE_STATE_STARTED;
926 iavf_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
928 struct iavf_adapter *adapter =
929 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
930 struct iavf_rx_queue *rxq;
933 PMD_DRV_FUNC_TRACE();
935 if (rx_queue_id >= dev->data->nb_rx_queues)
938 err = iavf_switch_queue(adapter, rx_queue_id, true, false);
940 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
945 rxq = dev->data->rx_queues[rx_queue_id];
946 rxq->ops->release_mbufs(rxq);
948 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
954 iavf_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
956 struct iavf_adapter *adapter =
957 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
958 struct iavf_tx_queue *txq;
961 PMD_DRV_FUNC_TRACE();
963 if (tx_queue_id >= dev->data->nb_tx_queues)
966 err = iavf_switch_queue(adapter, tx_queue_id, false, false);
968 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u off",
973 txq = dev->data->tx_queues[tx_queue_id];
974 txq->ops->release_mbufs(txq);
976 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
982 iavf_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
984 struct iavf_rx_queue *q = dev->data->rx_queues[qid];
989 q->ops->release_mbufs(q);
990 rte_free(q->sw_ring);
991 rte_memzone_free(q->mz);
996 iavf_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
998 struct iavf_tx_queue *q = dev->data->tx_queues[qid];
1003 q->ops->release_mbufs(q);
1004 rte_free(q->sw_ring);
1005 rte_memzone_free(q->mz);
1010 iavf_stop_queues(struct rte_eth_dev *dev)
1012 struct iavf_adapter *adapter =
1013 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1014 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1015 struct iavf_rx_queue *rxq;
1016 struct iavf_tx_queue *txq;
1019 /* Stop All queues */
1020 if (!vf->lv_enabled) {
1021 ret = iavf_disable_queues(adapter);
1023 PMD_DRV_LOG(WARNING, "Fail to stop queues");
1025 ret = iavf_disable_queues_lv(adapter);
1027 PMD_DRV_LOG(WARNING, "Fail to stop queues for large VF");
1031 PMD_DRV_LOG(WARNING, "Fail to stop queues");
1033 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1034 txq = dev->data->tx_queues[i];
1037 txq->ops->release_mbufs(txq);
1038 reset_tx_queue(txq);
1039 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1041 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1042 rxq = dev->data->rx_queues[i];
1045 rxq->ops->release_mbufs(rxq);
1046 reset_rx_queue(rxq);
1047 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1051 #define IAVF_RX_FLEX_ERR0_BITS \
1052 ((1 << IAVF_RX_FLEX_DESC_STATUS0_HBO_S) | \
1053 (1 << IAVF_RX_FLEX_DESC_STATUS0_XSUM_IPE_S) | \
1054 (1 << IAVF_RX_FLEX_DESC_STATUS0_XSUM_L4E_S) | \
1055 (1 << IAVF_RX_FLEX_DESC_STATUS0_XSUM_EIPE_S) | \
1056 (1 << IAVF_RX_FLEX_DESC_STATUS0_XSUM_EUDPE_S) | \
1057 (1 << IAVF_RX_FLEX_DESC_STATUS0_RXE_S))
1060 iavf_rxd_to_vlan_tci(struct rte_mbuf *mb, volatile union iavf_rx_desc *rxdp)
1062 if (rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
1063 (1 << IAVF_RX_DESC_STATUS_L2TAG1P_SHIFT)) {
1064 mb->ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
1066 rte_le_to_cpu_16(rxdp->wb.qword0.lo_dword.l2tag1);
1073 iavf_flex_rxd_to_vlan_tci(struct rte_mbuf *mb,
1074 volatile union iavf_rx_flex_desc *rxdp)
1076 if (rte_le_to_cpu_64(rxdp->wb.status_error0) &
1077 (1 << IAVF_RX_FLEX_DESC_STATUS0_L2TAG1P_S)) {
1078 mb->ol_flags |= RTE_MBUF_F_RX_VLAN |
1079 RTE_MBUF_F_RX_VLAN_STRIPPED;
1081 rte_le_to_cpu_16(rxdp->wb.l2tag1);
1086 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
1087 if (rte_le_to_cpu_16(rxdp->wb.status_error1) &
1088 (1 << IAVF_RX_FLEX_DESC_STATUS1_L2TAG2P_S)) {
1089 mb->ol_flags |= RTE_MBUF_F_RX_QINQ_STRIPPED |
1090 RTE_MBUF_F_RX_QINQ |
1091 RTE_MBUF_F_RX_VLAN_STRIPPED |
1093 mb->vlan_tci_outer = mb->vlan_tci;
1094 mb->vlan_tci = rte_le_to_cpu_16(rxdp->wb.l2tag2_2nd);
1095 PMD_RX_LOG(DEBUG, "Descriptor l2tag2_1: %u, l2tag2_2: %u",
1096 rte_le_to_cpu_16(rxdp->wb.l2tag2_1st),
1097 rte_le_to_cpu_16(rxdp->wb.l2tag2_2nd));
1099 mb->vlan_tci_outer = 0;
1105 iavf_flex_rxd_to_ipsec_crypto_said_get(struct rte_mbuf *mb,
1106 volatile union iavf_rx_flex_desc *rxdp)
1108 volatile struct iavf_32b_rx_flex_desc_comms_ipsec *desc =
1109 (volatile struct iavf_32b_rx_flex_desc_comms_ipsec *)rxdp;
1111 mb->dynfield1[0] = desc->ipsec_said &
1112 IAVF_RX_FLEX_DESC_IPSEC_CRYPTO_SAID_MASK;
1116 iavf_flex_rxd_to_ipsec_crypto_status(struct rte_mbuf *mb,
1117 volatile union iavf_rx_flex_desc *rxdp,
1118 struct iavf_ipsec_crypto_stats *stats)
1120 uint16_t status1 = rte_le_to_cpu_64(rxdp->wb.status_error1);
1122 if (status1 & BIT(IAVF_RX_FLEX_DESC_STATUS1_IPSEC_CRYPTO_PROCESSED)) {
1123 uint16_t ipsec_status;
1125 mb->ol_flags |= RTE_MBUF_F_RX_SEC_OFFLOAD;
1127 ipsec_status = status1 &
1128 IAVF_RX_FLEX_DESC_IPSEC_CRYPTO_STATUS_MASK;
1131 if (unlikely(ipsec_status !=
1132 IAVF_IPSEC_CRYPTO_STATUS_SUCCESS)) {
1133 mb->ol_flags |= RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED;
1135 switch (ipsec_status) {
1136 case IAVF_IPSEC_CRYPTO_STATUS_SAD_MISS:
1137 stats->ierrors.sad_miss++;
1139 case IAVF_IPSEC_CRYPTO_STATUS_NOT_PROCESSED:
1140 stats->ierrors.not_processed++;
1142 case IAVF_IPSEC_CRYPTO_STATUS_ICV_CHECK_FAIL:
1143 stats->ierrors.icv_check++;
1145 case IAVF_IPSEC_CRYPTO_STATUS_LENGTH_ERR:
1146 stats->ierrors.ipsec_length++;
1148 case IAVF_IPSEC_CRYPTO_STATUS_MISC_ERR:
1149 stats->ierrors.misc++;
1153 stats->ierrors.count++;
1158 stats->ibytes += rxdp->wb.pkt_len & 0x3FFF;
1160 if (rxdp->wb.rxdid == IAVF_RXDID_COMMS_IPSEC_CRYPTO &&
1162 IAVF_IPSEC_CRYPTO_STATUS_SAD_MISS)
1163 iavf_flex_rxd_to_ipsec_crypto_said_get(mb, rxdp);
1168 /* Translate the rx descriptor status and error fields to pkt flags */
1169 static inline uint64_t
1170 iavf_rxd_to_pkt_flags(uint64_t qword)
1173 uint64_t error_bits = (qword >> IAVF_RXD_QW1_ERROR_SHIFT);
1175 #define IAVF_RX_ERR_BITS 0x3f
1177 /* Check if RSS_HASH */
1178 flags = (((qword >> IAVF_RX_DESC_STATUS_FLTSTAT_SHIFT) &
1179 IAVF_RX_DESC_FLTSTAT_RSS_HASH) ==
1180 IAVF_RX_DESC_FLTSTAT_RSS_HASH) ? RTE_MBUF_F_RX_RSS_HASH : 0;
1182 /* Check if FDIR Match */
1183 flags |= (qword & (1 << IAVF_RX_DESC_STATUS_FLM_SHIFT) ?
1184 RTE_MBUF_F_RX_FDIR : 0);
1186 if (likely((error_bits & IAVF_RX_ERR_BITS) == 0)) {
1187 flags |= (RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_GOOD);
1191 if (unlikely(error_bits & (1 << IAVF_RX_DESC_ERROR_IPE_SHIFT)))
1192 flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
1194 flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
1196 if (unlikely(error_bits & (1 << IAVF_RX_DESC_ERROR_L4E_SHIFT)))
1197 flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
1199 flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
1201 /* TODO: Oversize error bit is not processed here */
1206 static inline uint64_t
1207 iavf_rxd_build_fdir(volatile union iavf_rx_desc *rxdp, struct rte_mbuf *mb)
1210 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
1213 flexbh = (rte_le_to_cpu_32(rxdp->wb.qword2.ext_status) >>
1214 IAVF_RX_DESC_EXT_STATUS_FLEXBH_SHIFT) &
1215 IAVF_RX_DESC_EXT_STATUS_FLEXBH_MASK;
1217 if (flexbh == IAVF_RX_DESC_EXT_STATUS_FLEXBH_FD_ID) {
1219 rte_le_to_cpu_32(rxdp->wb.qword3.hi_dword.fd_id);
1220 flags |= RTE_MBUF_F_RX_FDIR_ID;
1224 rte_le_to_cpu_32(rxdp->wb.qword0.hi_dword.fd_id);
1225 flags |= RTE_MBUF_F_RX_FDIR_ID;
1230 #define IAVF_RX_FLEX_ERR0_BITS \
1231 ((1 << IAVF_RX_FLEX_DESC_STATUS0_HBO_S) | \
1232 (1 << IAVF_RX_FLEX_DESC_STATUS0_XSUM_IPE_S) | \
1233 (1 << IAVF_RX_FLEX_DESC_STATUS0_XSUM_L4E_S) | \
1234 (1 << IAVF_RX_FLEX_DESC_STATUS0_XSUM_EIPE_S) | \
1235 (1 << IAVF_RX_FLEX_DESC_STATUS0_XSUM_EUDPE_S) | \
1236 (1 << IAVF_RX_FLEX_DESC_STATUS0_RXE_S))
1238 /* Rx L3/L4 checksum */
1239 static inline uint64_t
1240 iavf_flex_rxd_error_to_pkt_flags(uint16_t stat_err0)
1244 /* check if HW has decoded the packet and checksum */
1245 if (unlikely(!(stat_err0 & (1 << IAVF_RX_FLEX_DESC_STATUS0_L3L4P_S))))
1248 if (likely(!(stat_err0 & IAVF_RX_FLEX_ERR0_BITS))) {
1249 flags |= (RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_GOOD);
1253 if (unlikely(stat_err0 & (1 << IAVF_RX_FLEX_DESC_STATUS0_XSUM_IPE_S)))
1254 flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
1256 flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
1258 if (unlikely(stat_err0 & (1 << IAVF_RX_FLEX_DESC_STATUS0_XSUM_L4E_S)))
1259 flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
1261 flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
1263 if (unlikely(stat_err0 & (1 << IAVF_RX_FLEX_DESC_STATUS0_XSUM_EIPE_S)))
1264 flags |= RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD;
1269 /* If the number of free RX descriptors is greater than the RX free
1270 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1271 * register. Update the RDT with the value of the last processed RX
1272 * descriptor minus 1, to guarantee that the RDT register is never
1273 * equal to the RDH register, which creates a "full" ring situation
1274 * from the hardware point of view.
1277 iavf_update_rx_tail(struct iavf_rx_queue *rxq, uint16_t nb_hold, uint16_t rx_id)
1279 nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
1281 if (nb_hold > rxq->rx_free_thresh) {
1283 "port_id=%u queue_id=%u rx_tail=%u nb_hold=%u",
1284 rxq->port_id, rxq->queue_id, rx_id, nb_hold);
1285 rx_id = (uint16_t)((rx_id == 0) ?
1286 (rxq->nb_rx_desc - 1) : (rx_id - 1));
1287 IAVF_PCI_REG_WC_WRITE(rxq->qrx_tail, rx_id);
1290 rxq->nb_rx_hold = nb_hold;
1293 /* implement recv_pkts */
1295 iavf_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
1297 volatile union iavf_rx_desc *rx_ring;
1298 volatile union iavf_rx_desc *rxdp;
1299 struct iavf_rx_queue *rxq;
1300 union iavf_rx_desc rxd;
1301 struct rte_mbuf *rxe;
1302 struct rte_eth_dev *dev;
1303 struct rte_mbuf *rxm;
1304 struct rte_mbuf *nmb;
1308 uint16_t rx_packet_len;
1309 uint16_t rx_id, nb_hold;
1312 const uint32_t *ptype_tbl;
1317 rx_id = rxq->rx_tail;
1318 rx_ring = rxq->rx_ring;
1319 ptype_tbl = rxq->vsi->adapter->ptype_tbl;
1321 while (nb_rx < nb_pkts) {
1322 rxdp = &rx_ring[rx_id];
1323 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
1324 rx_status = (qword1 & IAVF_RXD_QW1_STATUS_MASK) >>
1325 IAVF_RXD_QW1_STATUS_SHIFT;
1327 /* Check the DD bit first */
1328 if (!(rx_status & (1 << IAVF_RX_DESC_STATUS_DD_SHIFT)))
1330 IAVF_DUMP_RX_DESC(rxq, rxdp, rx_id);
1332 nmb = rte_mbuf_raw_alloc(rxq->mp);
1333 if (unlikely(!nmb)) {
1334 dev = &rte_eth_devices[rxq->port_id];
1335 dev->data->rx_mbuf_alloc_failed++;
1336 PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1337 "queue_id=%u", rxq->port_id, rxq->queue_id);
1343 rxe = rxq->sw_ring[rx_id];
1344 rxq->sw_ring[rx_id] = nmb;
1346 if (unlikely(rx_id == rxq->nb_rx_desc))
1349 /* Prefetch next mbuf */
1350 rte_prefetch0(rxq->sw_ring[rx_id]);
1352 /* When next RX descriptor is on a cache line boundary,
1353 * prefetch the next 4 RX descriptors and next 8 pointers
1356 if ((rx_id & 0x3) == 0) {
1357 rte_prefetch0(&rx_ring[rx_id]);
1358 rte_prefetch0(rxq->sw_ring[rx_id]);
1362 rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1363 rxdp->read.hdr_addr = 0;
1364 rxdp->read.pkt_addr = dma_addr;
1366 rx_packet_len = ((qword1 & IAVF_RXD_QW1_LENGTH_PBUF_MASK) >>
1367 IAVF_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
1369 rxm->data_off = RTE_PKTMBUF_HEADROOM;
1370 rte_prefetch0(RTE_PTR_ADD(rxm->buf_addr, RTE_PKTMBUF_HEADROOM));
1373 rxm->pkt_len = rx_packet_len;
1374 rxm->data_len = rx_packet_len;
1375 rxm->port = rxq->port_id;
1377 iavf_rxd_to_vlan_tci(rxm, &rxd);
1378 pkt_flags = iavf_rxd_to_pkt_flags(qword1);
1380 ptype_tbl[(uint8_t)((qword1 &
1381 IAVF_RXD_QW1_PTYPE_MASK) >> IAVF_RXD_QW1_PTYPE_SHIFT)];
1383 if (pkt_flags & RTE_MBUF_F_RX_RSS_HASH)
1385 rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
1387 if (pkt_flags & RTE_MBUF_F_RX_FDIR)
1388 pkt_flags |= iavf_rxd_build_fdir(&rxd, rxm);
1390 rxm->ol_flags |= pkt_flags;
1392 rx_pkts[nb_rx++] = rxm;
1394 rxq->rx_tail = rx_id;
1396 iavf_update_rx_tail(rxq, nb_hold, rx_id);
1401 /* implement recv_pkts for flexible Rx descriptor */
1403 iavf_recv_pkts_flex_rxd(void *rx_queue,
1404 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
1406 volatile union iavf_rx_desc *rx_ring;
1407 volatile union iavf_rx_flex_desc *rxdp;
1408 struct iavf_rx_queue *rxq;
1409 union iavf_rx_flex_desc rxd;
1410 struct rte_mbuf *rxe;
1411 struct rte_eth_dev *dev;
1412 struct rte_mbuf *rxm;
1413 struct rte_mbuf *nmb;
1415 uint16_t rx_stat_err0;
1416 uint16_t rx_packet_len;
1417 uint16_t rx_id, nb_hold;
1420 const uint32_t *ptype_tbl;
1425 rx_id = rxq->rx_tail;
1426 rx_ring = rxq->rx_ring;
1427 ptype_tbl = rxq->vsi->adapter->ptype_tbl;
1429 while (nb_rx < nb_pkts) {
1430 rxdp = (volatile union iavf_rx_flex_desc *)&rx_ring[rx_id];
1431 rx_stat_err0 = rte_le_to_cpu_16(rxdp->wb.status_error0);
1433 /* Check the DD bit first */
1434 if (!(rx_stat_err0 & (1 << IAVF_RX_FLEX_DESC_STATUS0_DD_S)))
1436 IAVF_DUMP_RX_DESC(rxq, rxdp, rx_id);
1438 nmb = rte_mbuf_raw_alloc(rxq->mp);
1439 if (unlikely(!nmb)) {
1440 dev = &rte_eth_devices[rxq->port_id];
1441 dev->data->rx_mbuf_alloc_failed++;
1442 PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1443 "queue_id=%u", rxq->port_id, rxq->queue_id);
1449 rxe = rxq->sw_ring[rx_id];
1450 rxq->sw_ring[rx_id] = nmb;
1452 if (unlikely(rx_id == rxq->nb_rx_desc))
1455 /* Prefetch next mbuf */
1456 rte_prefetch0(rxq->sw_ring[rx_id]);
1458 /* When next RX descriptor is on a cache line boundary,
1459 * prefetch the next 4 RX descriptors and next 8 pointers
1462 if ((rx_id & 0x3) == 0) {
1463 rte_prefetch0(&rx_ring[rx_id]);
1464 rte_prefetch0(rxq->sw_ring[rx_id]);
1468 rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1469 rxdp->read.hdr_addr = 0;
1470 rxdp->read.pkt_addr = dma_addr;
1472 rx_packet_len = (rte_le_to_cpu_16(rxd.wb.pkt_len) &
1473 IAVF_RX_FLX_DESC_PKT_LEN_M) - rxq->crc_len;
1475 rxm->data_off = RTE_PKTMBUF_HEADROOM;
1476 rte_prefetch0(RTE_PTR_ADD(rxm->buf_addr, RTE_PKTMBUF_HEADROOM));
1479 rxm->pkt_len = rx_packet_len;
1480 rxm->data_len = rx_packet_len;
1481 rxm->port = rxq->port_id;
1483 rxm->packet_type = ptype_tbl[IAVF_RX_FLEX_DESC_PTYPE_M &
1484 rte_le_to_cpu_16(rxd.wb.ptype_flex_flags0)];
1485 iavf_flex_rxd_to_vlan_tci(rxm, &rxd);
1486 iavf_flex_rxd_to_ipsec_crypto_status(rxm, &rxd,
1487 &rxq->stats.ipsec_crypto);
1488 rxd_to_pkt_fields_ops[rxq->rxdid](rxq, rxm, &rxd);
1489 pkt_flags = iavf_flex_rxd_error_to_pkt_flags(rx_stat_err0);
1490 rxm->ol_flags |= pkt_flags;
1492 rx_pkts[nb_rx++] = rxm;
1494 rxq->rx_tail = rx_id;
1496 iavf_update_rx_tail(rxq, nb_hold, rx_id);
1501 /* implement recv_scattered_pkts for flexible Rx descriptor */
1503 iavf_recv_scattered_pkts_flex_rxd(void *rx_queue, struct rte_mbuf **rx_pkts,
1506 struct iavf_rx_queue *rxq = rx_queue;
1507 union iavf_rx_flex_desc rxd;
1508 struct rte_mbuf *rxe;
1509 struct rte_mbuf *first_seg = rxq->pkt_first_seg;
1510 struct rte_mbuf *last_seg = rxq->pkt_last_seg;
1511 struct rte_mbuf *nmb, *rxm;
1512 uint16_t rx_id = rxq->rx_tail;
1513 uint16_t nb_rx = 0, nb_hold = 0, rx_packet_len;
1514 struct rte_eth_dev *dev;
1515 uint16_t rx_stat_err0;
1519 volatile union iavf_rx_desc *rx_ring = rxq->rx_ring;
1520 volatile union iavf_rx_flex_desc *rxdp;
1521 const uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
1523 while (nb_rx < nb_pkts) {
1524 rxdp = (volatile union iavf_rx_flex_desc *)&rx_ring[rx_id];
1525 rx_stat_err0 = rte_le_to_cpu_16(rxdp->wb.status_error0);
1527 /* Check the DD bit */
1528 if (!(rx_stat_err0 & (1 << IAVF_RX_FLEX_DESC_STATUS0_DD_S)))
1530 IAVF_DUMP_RX_DESC(rxq, rxdp, rx_id);
1532 nmb = rte_mbuf_raw_alloc(rxq->mp);
1533 if (unlikely(!nmb)) {
1534 PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1535 "queue_id=%u", rxq->port_id, rxq->queue_id);
1536 dev = &rte_eth_devices[rxq->port_id];
1537 dev->data->rx_mbuf_alloc_failed++;
1543 rxe = rxq->sw_ring[rx_id];
1544 rxq->sw_ring[rx_id] = nmb;
1546 if (rx_id == rxq->nb_rx_desc)
1549 /* Prefetch next mbuf */
1550 rte_prefetch0(rxq->sw_ring[rx_id]);
1552 /* When next RX descriptor is on a cache line boundary,
1553 * prefetch the next 4 RX descriptors and next 8 pointers
1556 if ((rx_id & 0x3) == 0) {
1557 rte_prefetch0(&rx_ring[rx_id]);
1558 rte_prefetch0(rxq->sw_ring[rx_id]);
1563 rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1565 /* Set data buffer address and data length of the mbuf */
1566 rxdp->read.hdr_addr = 0;
1567 rxdp->read.pkt_addr = dma_addr;
1568 rx_packet_len = rte_le_to_cpu_16(rxd.wb.pkt_len) &
1569 IAVF_RX_FLX_DESC_PKT_LEN_M;
1570 rxm->data_len = rx_packet_len;
1571 rxm->data_off = RTE_PKTMBUF_HEADROOM;
1573 /* If this is the first buffer of the received packet, set the
1574 * pointer to the first mbuf of the packet and initialize its
1575 * context. Otherwise, update the total length and the number
1576 * of segments of the current scattered packet, and update the
1577 * pointer to the last mbuf of the current packet.
1581 first_seg->nb_segs = 1;
1582 first_seg->pkt_len = rx_packet_len;
1584 first_seg->pkt_len =
1585 (uint16_t)(first_seg->pkt_len +
1587 first_seg->nb_segs++;
1588 last_seg->next = rxm;
1591 /* If this is not the last buffer of the received packet,
1592 * update the pointer to the last mbuf of the current scattered
1593 * packet and continue to parse the RX ring.
1595 if (!(rx_stat_err0 & (1 << IAVF_RX_FLEX_DESC_STATUS0_EOF_S))) {
1600 /* This is the last buffer of the received packet. If the CRC
1601 * is not stripped by the hardware:
1602 * - Subtract the CRC length from the total packet length.
1603 * - If the last buffer only contains the whole CRC or a part
1604 * of it, free the mbuf associated to the last buffer. If part
1605 * of the CRC is also contained in the previous mbuf, subtract
1606 * the length of that CRC part from the data length of the
1610 if (unlikely(rxq->crc_len > 0)) {
1611 first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
1612 if (rx_packet_len <= RTE_ETHER_CRC_LEN) {
1613 rte_pktmbuf_free_seg(rxm);
1614 first_seg->nb_segs--;
1615 last_seg->data_len =
1616 (uint16_t)(last_seg->data_len -
1617 (RTE_ETHER_CRC_LEN - rx_packet_len));
1618 last_seg->next = NULL;
1620 rxm->data_len = (uint16_t)(rx_packet_len -
1625 first_seg->port = rxq->port_id;
1626 first_seg->ol_flags = 0;
1627 first_seg->packet_type = ptype_tbl[IAVF_RX_FLEX_DESC_PTYPE_M &
1628 rte_le_to_cpu_16(rxd.wb.ptype_flex_flags0)];
1629 iavf_flex_rxd_to_vlan_tci(first_seg, &rxd);
1630 iavf_flex_rxd_to_ipsec_crypto_status(first_seg, &rxd,
1631 &rxq->stats.ipsec_crypto);
1632 rxd_to_pkt_fields_ops[rxq->rxdid](rxq, first_seg, &rxd);
1633 pkt_flags = iavf_flex_rxd_error_to_pkt_flags(rx_stat_err0);
1635 first_seg->ol_flags |= pkt_flags;
1637 /* Prefetch data of first segment, if configured to do so. */
1638 rte_prefetch0(RTE_PTR_ADD(first_seg->buf_addr,
1639 first_seg->data_off));
1640 rx_pkts[nb_rx++] = first_seg;
1644 /* Record index of the next RX descriptor to probe. */
1645 rxq->rx_tail = rx_id;
1646 rxq->pkt_first_seg = first_seg;
1647 rxq->pkt_last_seg = last_seg;
1649 iavf_update_rx_tail(rxq, nb_hold, rx_id);
1654 /* implement recv_scattered_pkts */
1656 iavf_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
1659 struct iavf_rx_queue *rxq = rx_queue;
1660 union iavf_rx_desc rxd;
1661 struct rte_mbuf *rxe;
1662 struct rte_mbuf *first_seg = rxq->pkt_first_seg;
1663 struct rte_mbuf *last_seg = rxq->pkt_last_seg;
1664 struct rte_mbuf *nmb, *rxm;
1665 uint16_t rx_id = rxq->rx_tail;
1666 uint16_t nb_rx = 0, nb_hold = 0, rx_packet_len;
1667 struct rte_eth_dev *dev;
1673 volatile union iavf_rx_desc *rx_ring = rxq->rx_ring;
1674 volatile union iavf_rx_desc *rxdp;
1675 const uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
1677 while (nb_rx < nb_pkts) {
1678 rxdp = &rx_ring[rx_id];
1679 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
1680 rx_status = (qword1 & IAVF_RXD_QW1_STATUS_MASK) >>
1681 IAVF_RXD_QW1_STATUS_SHIFT;
1683 /* Check the DD bit */
1684 if (!(rx_status & (1 << IAVF_RX_DESC_STATUS_DD_SHIFT)))
1686 IAVF_DUMP_RX_DESC(rxq, rxdp, rx_id);
1688 nmb = rte_mbuf_raw_alloc(rxq->mp);
1689 if (unlikely(!nmb)) {
1690 PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
1691 "queue_id=%u", rxq->port_id, rxq->queue_id);
1692 dev = &rte_eth_devices[rxq->port_id];
1693 dev->data->rx_mbuf_alloc_failed++;
1699 rxe = rxq->sw_ring[rx_id];
1700 rxq->sw_ring[rx_id] = nmb;
1702 if (rx_id == rxq->nb_rx_desc)
1705 /* Prefetch next mbuf */
1706 rte_prefetch0(rxq->sw_ring[rx_id]);
1708 /* When next RX descriptor is on a cache line boundary,
1709 * prefetch the next 4 RX descriptors and next 8 pointers
1712 if ((rx_id & 0x3) == 0) {
1713 rte_prefetch0(&rx_ring[rx_id]);
1714 rte_prefetch0(rxq->sw_ring[rx_id]);
1719 rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
1721 /* Set data buffer address and data length of the mbuf */
1722 rxdp->read.hdr_addr = 0;
1723 rxdp->read.pkt_addr = dma_addr;
1724 rx_packet_len = (qword1 & IAVF_RXD_QW1_LENGTH_PBUF_MASK) >>
1725 IAVF_RXD_QW1_LENGTH_PBUF_SHIFT;
1726 rxm->data_len = rx_packet_len;
1727 rxm->data_off = RTE_PKTMBUF_HEADROOM;
1729 /* If this is the first buffer of the received packet, set the
1730 * pointer to the first mbuf of the packet and initialize its
1731 * context. Otherwise, update the total length and the number
1732 * of segments of the current scattered packet, and update the
1733 * pointer to the last mbuf of the current packet.
1737 first_seg->nb_segs = 1;
1738 first_seg->pkt_len = rx_packet_len;
1740 first_seg->pkt_len =
1741 (uint16_t)(first_seg->pkt_len +
1743 first_seg->nb_segs++;
1744 last_seg->next = rxm;
1747 /* If this is not the last buffer of the received packet,
1748 * update the pointer to the last mbuf of the current scattered
1749 * packet and continue to parse the RX ring.
1751 if (!(rx_status & (1 << IAVF_RX_DESC_STATUS_EOF_SHIFT))) {
1756 /* This is the last buffer of the received packet. If the CRC
1757 * is not stripped by the hardware:
1758 * - Subtract the CRC length from the total packet length.
1759 * - If the last buffer only contains the whole CRC or a part
1760 * of it, free the mbuf associated to the last buffer. If part
1761 * of the CRC is also contained in the previous mbuf, subtract
1762 * the length of that CRC part from the data length of the
1766 if (unlikely(rxq->crc_len > 0)) {
1767 first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
1768 if (rx_packet_len <= RTE_ETHER_CRC_LEN) {
1769 rte_pktmbuf_free_seg(rxm);
1770 first_seg->nb_segs--;
1771 last_seg->data_len =
1772 (uint16_t)(last_seg->data_len -
1773 (RTE_ETHER_CRC_LEN - rx_packet_len));
1774 last_seg->next = NULL;
1776 rxm->data_len = (uint16_t)(rx_packet_len -
1780 first_seg->port = rxq->port_id;
1781 first_seg->ol_flags = 0;
1782 iavf_rxd_to_vlan_tci(first_seg, &rxd);
1783 pkt_flags = iavf_rxd_to_pkt_flags(qword1);
1784 first_seg->packet_type =
1785 ptype_tbl[(uint8_t)((qword1 &
1786 IAVF_RXD_QW1_PTYPE_MASK) >> IAVF_RXD_QW1_PTYPE_SHIFT)];
1788 if (pkt_flags & RTE_MBUF_F_RX_RSS_HASH)
1789 first_seg->hash.rss =
1790 rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
1792 if (pkt_flags & RTE_MBUF_F_RX_FDIR)
1793 pkt_flags |= iavf_rxd_build_fdir(&rxd, first_seg);
1795 first_seg->ol_flags |= pkt_flags;
1797 /* Prefetch data of first segment, if configured to do so. */
1798 rte_prefetch0(RTE_PTR_ADD(first_seg->buf_addr,
1799 first_seg->data_off));
1800 rx_pkts[nb_rx++] = first_seg;
1804 /* Record index of the next RX descriptor to probe. */
1805 rxq->rx_tail = rx_id;
1806 rxq->pkt_first_seg = first_seg;
1807 rxq->pkt_last_seg = last_seg;
1809 iavf_update_rx_tail(rxq, nb_hold, rx_id);
1814 #define IAVF_LOOK_AHEAD 8
1816 iavf_rx_scan_hw_ring_flex_rxd(struct iavf_rx_queue *rxq)
1818 volatile union iavf_rx_flex_desc *rxdp;
1819 struct rte_mbuf **rxep;
1820 struct rte_mbuf *mb;
1823 int32_t s[IAVF_LOOK_AHEAD], var, nb_dd;
1824 int32_t i, j, nb_rx = 0;
1826 const uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
1828 rxdp = (volatile union iavf_rx_flex_desc *)&rxq->rx_ring[rxq->rx_tail];
1829 rxep = &rxq->sw_ring[rxq->rx_tail];
1831 stat_err0 = rte_le_to_cpu_16(rxdp->wb.status_error0);
1833 /* Make sure there is at least 1 packet to receive */
1834 if (!(stat_err0 & (1 << IAVF_RX_FLEX_DESC_STATUS0_DD_S)))
1837 /* Scan LOOK_AHEAD descriptors at a time to determine which
1838 * descriptors reference packets that are ready to be received.
1840 for (i = 0; i < IAVF_RX_MAX_BURST; i += IAVF_LOOK_AHEAD,
1841 rxdp += IAVF_LOOK_AHEAD, rxep += IAVF_LOOK_AHEAD) {
1842 /* Read desc statuses backwards to avoid race condition */
1843 for (j = IAVF_LOOK_AHEAD - 1; j >= 0; j--)
1844 s[j] = rte_le_to_cpu_16(rxdp[j].wb.status_error0);
1848 /* Compute how many contiguous DD bits were set */
1849 for (j = 0, nb_dd = 0; j < IAVF_LOOK_AHEAD; j++) {
1850 var = s[j] & (1 << IAVF_RX_FLEX_DESC_STATUS0_DD_S);
1852 /* For Arm platforms, count only contiguous descriptors
1853 * whose DD bit is set to 1. On Arm platforms, reads of
1854 * descriptors can be reordered. Since the CPU may
1855 * be reading the descriptors as the NIC updates them
1856 * in memory, it is possbile that the DD bit for a
1857 * descriptor earlier in the queue is read as not set
1858 * while the DD bit for a descriptor later in the queue
1872 /* Translate descriptor info to mbuf parameters */
1873 for (j = 0; j < nb_dd; j++) {
1874 IAVF_DUMP_RX_DESC(rxq, &rxdp[j],
1876 i * IAVF_LOOK_AHEAD + j);
1879 pkt_len = (rte_le_to_cpu_16(rxdp[j].wb.pkt_len) &
1880 IAVF_RX_FLX_DESC_PKT_LEN_M) - rxq->crc_len;
1881 mb->data_len = pkt_len;
1882 mb->pkt_len = pkt_len;
1885 mb->packet_type = ptype_tbl[IAVF_RX_FLEX_DESC_PTYPE_M &
1886 rte_le_to_cpu_16(rxdp[j].wb.ptype_flex_flags0)];
1887 iavf_flex_rxd_to_vlan_tci(mb, &rxdp[j]);
1888 iavf_flex_rxd_to_ipsec_crypto_status(mb, &rxdp[j],
1889 &rxq->stats.ipsec_crypto);
1890 rxd_to_pkt_fields_ops[rxq->rxdid](rxq, mb, &rxdp[j]);
1891 stat_err0 = rte_le_to_cpu_16(rxdp[j].wb.status_error0);
1892 pkt_flags = iavf_flex_rxd_error_to_pkt_flags(stat_err0);
1894 mb->ol_flags |= pkt_flags;
1897 for (j = 0; j < IAVF_LOOK_AHEAD; j++)
1898 rxq->rx_stage[i + j] = rxep[j];
1900 if (nb_dd != IAVF_LOOK_AHEAD)
1904 /* Clear software ring entries */
1905 for (i = 0; i < nb_rx; i++)
1906 rxq->sw_ring[rxq->rx_tail + i] = NULL;
1912 iavf_rx_scan_hw_ring(struct iavf_rx_queue *rxq)
1914 volatile union iavf_rx_desc *rxdp;
1915 struct rte_mbuf **rxep;
1916 struct rte_mbuf *mb;
1920 int32_t s[IAVF_LOOK_AHEAD], var, nb_dd;
1921 int32_t i, j, nb_rx = 0;
1923 const uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
1925 rxdp = &rxq->rx_ring[rxq->rx_tail];
1926 rxep = &rxq->sw_ring[rxq->rx_tail];
1928 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
1929 rx_status = (qword1 & IAVF_RXD_QW1_STATUS_MASK) >>
1930 IAVF_RXD_QW1_STATUS_SHIFT;
1932 /* Make sure there is at least 1 packet to receive */
1933 if (!(rx_status & (1 << IAVF_RX_DESC_STATUS_DD_SHIFT)))
1936 /* Scan LOOK_AHEAD descriptors at a time to determine which
1937 * descriptors reference packets that are ready to be received.
1939 for (i = 0; i < IAVF_RX_MAX_BURST; i += IAVF_LOOK_AHEAD,
1940 rxdp += IAVF_LOOK_AHEAD, rxep += IAVF_LOOK_AHEAD) {
1941 /* Read desc statuses backwards to avoid race condition */
1942 for (j = IAVF_LOOK_AHEAD - 1; j >= 0; j--) {
1943 qword1 = rte_le_to_cpu_64(
1944 rxdp[j].wb.qword1.status_error_len);
1945 s[j] = (qword1 & IAVF_RXD_QW1_STATUS_MASK) >>
1946 IAVF_RXD_QW1_STATUS_SHIFT;
1951 /* Compute how many contiguous DD bits were set */
1952 for (j = 0, nb_dd = 0; j < IAVF_LOOK_AHEAD; j++) {
1953 var = s[j] & (1 << IAVF_RX_DESC_STATUS_DD_SHIFT);
1955 /* For Arm platforms, count only contiguous descriptors
1956 * whose DD bit is set to 1. On Arm platforms, reads of
1957 * descriptors can be reordered. Since the CPU may
1958 * be reading the descriptors as the NIC updates them
1959 * in memory, it is possbile that the DD bit for a
1960 * descriptor earlier in the queue is read as not set
1961 * while the DD bit for a descriptor later in the queue
1975 /* Translate descriptor info to mbuf parameters */
1976 for (j = 0; j < nb_dd; j++) {
1977 IAVF_DUMP_RX_DESC(rxq, &rxdp[j],
1978 rxq->rx_tail + i * IAVF_LOOK_AHEAD + j);
1981 qword1 = rte_le_to_cpu_64
1982 (rxdp[j].wb.qword1.status_error_len);
1983 pkt_len = ((qword1 & IAVF_RXD_QW1_LENGTH_PBUF_MASK) >>
1984 IAVF_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
1985 mb->data_len = pkt_len;
1986 mb->pkt_len = pkt_len;
1988 iavf_rxd_to_vlan_tci(mb, &rxdp[j]);
1989 pkt_flags = iavf_rxd_to_pkt_flags(qword1);
1991 ptype_tbl[(uint8_t)((qword1 &
1992 IAVF_RXD_QW1_PTYPE_MASK) >>
1993 IAVF_RXD_QW1_PTYPE_SHIFT)];
1995 if (pkt_flags & RTE_MBUF_F_RX_RSS_HASH)
1996 mb->hash.rss = rte_le_to_cpu_32(
1997 rxdp[j].wb.qword0.hi_dword.rss);
1999 if (pkt_flags & RTE_MBUF_F_RX_FDIR)
2000 pkt_flags |= iavf_rxd_build_fdir(&rxdp[j], mb);
2002 mb->ol_flags |= pkt_flags;
2005 for (j = 0; j < IAVF_LOOK_AHEAD; j++)
2006 rxq->rx_stage[i + j] = rxep[j];
2008 if (nb_dd != IAVF_LOOK_AHEAD)
2012 /* Clear software ring entries */
2013 for (i = 0; i < nb_rx; i++)
2014 rxq->sw_ring[rxq->rx_tail + i] = NULL;
2019 static inline uint16_t
2020 iavf_rx_fill_from_stage(struct iavf_rx_queue *rxq,
2021 struct rte_mbuf **rx_pkts,
2025 struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
2027 nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
2029 for (i = 0; i < nb_pkts; i++)
2030 rx_pkts[i] = stage[i];
2032 rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
2033 rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
2039 iavf_rx_alloc_bufs(struct iavf_rx_queue *rxq)
2041 volatile union iavf_rx_desc *rxdp;
2042 struct rte_mbuf **rxep;
2043 struct rte_mbuf *mb;
2044 uint16_t alloc_idx, i;
2048 /* Allocate buffers in bulk */
2049 alloc_idx = (uint16_t)(rxq->rx_free_trigger -
2050 (rxq->rx_free_thresh - 1));
2051 rxep = &rxq->sw_ring[alloc_idx];
2052 diag = rte_mempool_get_bulk(rxq->mp, (void *)rxep,
2053 rxq->rx_free_thresh);
2054 if (unlikely(diag != 0)) {
2055 PMD_RX_LOG(ERR, "Failed to get mbufs in bulk");
2059 rxdp = &rxq->rx_ring[alloc_idx];
2060 for (i = 0; i < rxq->rx_free_thresh; i++) {
2061 if (likely(i < (rxq->rx_free_thresh - 1)))
2062 /* Prefetch next mbuf */
2063 rte_prefetch0(rxep[i + 1]);
2066 rte_mbuf_refcnt_set(mb, 1);
2068 mb->data_off = RTE_PKTMBUF_HEADROOM;
2070 mb->port = rxq->port_id;
2071 dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mb));
2072 rxdp[i].read.hdr_addr = 0;
2073 rxdp[i].read.pkt_addr = dma_addr;
2076 /* Update rx tail register */
2078 IAVF_PCI_REG_WC_WRITE_RELAXED(rxq->qrx_tail, rxq->rx_free_trigger);
2080 rxq->rx_free_trigger =
2081 (uint16_t)(rxq->rx_free_trigger + rxq->rx_free_thresh);
2082 if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
2083 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
2088 static inline uint16_t
2089 rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2091 struct iavf_rx_queue *rxq = (struct iavf_rx_queue *)rx_queue;
2097 if (rxq->rx_nb_avail)
2098 return iavf_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
2100 if (rxq->rxdid >= IAVF_RXDID_FLEX_NIC && rxq->rxdid <= IAVF_RXDID_LAST)
2101 nb_rx = (uint16_t)iavf_rx_scan_hw_ring_flex_rxd(rxq);
2103 nb_rx = (uint16_t)iavf_rx_scan_hw_ring(rxq);
2104 rxq->rx_next_avail = 0;
2105 rxq->rx_nb_avail = nb_rx;
2106 rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
2108 if (rxq->rx_tail > rxq->rx_free_trigger) {
2109 if (iavf_rx_alloc_bufs(rxq) != 0) {
2112 /* TODO: count rx_mbuf_alloc_failed here */
2114 rxq->rx_nb_avail = 0;
2115 rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
2116 for (i = 0, j = rxq->rx_tail; i < nb_rx; i++, j++)
2117 rxq->sw_ring[j] = rxq->rx_stage[i];
2123 if (rxq->rx_tail >= rxq->nb_rx_desc)
2126 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u, nb_rx=%u",
2127 rxq->port_id, rxq->queue_id,
2128 rxq->rx_tail, nb_rx);
2130 if (rxq->rx_nb_avail)
2131 return iavf_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
2137 iavf_recv_pkts_bulk_alloc(void *rx_queue,
2138 struct rte_mbuf **rx_pkts,
2141 uint16_t nb_rx = 0, n, count;
2143 if (unlikely(nb_pkts == 0))
2146 if (likely(nb_pkts <= IAVF_RX_MAX_BURST))
2147 return rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
2150 n = RTE_MIN(nb_pkts, IAVF_RX_MAX_BURST);
2151 count = rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
2152 nb_rx = (uint16_t)(nb_rx + count);
2153 nb_pkts = (uint16_t)(nb_pkts - count);
2162 iavf_xmit_cleanup(struct iavf_tx_queue *txq)
2164 struct iavf_tx_entry *sw_ring = txq->sw_ring;
2165 uint16_t last_desc_cleaned = txq->last_desc_cleaned;
2166 uint16_t nb_tx_desc = txq->nb_tx_desc;
2167 uint16_t desc_to_clean_to;
2168 uint16_t nb_tx_to_clean;
2170 volatile struct iavf_tx_desc *txd = txq->tx_ring;
2172 desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->rs_thresh);
2173 if (desc_to_clean_to >= nb_tx_desc)
2174 desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
2176 desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
2177 if ((txd[desc_to_clean_to].cmd_type_offset_bsz &
2178 rte_cpu_to_le_64(IAVF_TXD_QW1_DTYPE_MASK)) !=
2179 rte_cpu_to_le_64(IAVF_TX_DESC_DTYPE_DESC_DONE)) {
2180 PMD_TX_LOG(DEBUG, "TX descriptor %4u is not done "
2181 "(port=%d queue=%d)", desc_to_clean_to,
2182 txq->port_id, txq->queue_id);
2186 if (last_desc_cleaned > desc_to_clean_to)
2187 nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
2190 nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
2193 txd[desc_to_clean_to].cmd_type_offset_bsz = 0;
2195 txq->last_desc_cleaned = desc_to_clean_to;
2196 txq->nb_free = (uint16_t)(txq->nb_free + nb_tx_to_clean);
2201 /* Check if the context descriptor is needed for TX offloading */
2202 static inline uint16_t
2203 iavf_calc_context_desc(uint64_t flags, uint8_t vlan_flag)
2205 if (flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG |
2206 RTE_MBUF_F_TX_TUNNEL_MASK))
2208 if (flags & RTE_MBUF_F_TX_VLAN &&
2209 vlan_flag & IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG2)
2215 iavf_fill_ctx_desc_cmd_field(volatile uint64_t *field, struct rte_mbuf *m,
2221 if (m->ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG))
2222 cmd = IAVF_TX_CTX_DESC_TSO << IAVF_TXD_CTX_QW1_CMD_SHIFT;
2224 if (m->ol_flags & RTE_MBUF_F_TX_VLAN &&
2225 vlan_flag & IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG2) {
2226 cmd |= IAVF_TX_CTX_DESC_IL2TAG2
2227 << IAVF_TXD_CTX_QW1_CMD_SHIFT;
2234 iavf_fill_ctx_desc_ipsec_field(volatile uint64_t *field,
2235 struct iavf_ipsec_crypto_pkt_metadata *ipsec_md)
2237 uint64_t ipsec_field =
2238 (uint64_t)ipsec_md->ctx_desc_ipsec_params <<
2239 IAVF_TXD_CTX_QW1_IPSEC_PARAMS_CIPHERBLK_SHIFT;
2241 *field |= ipsec_field;
2246 iavf_fill_ctx_desc_tunnelling_field(volatile uint64_t *qw0,
2247 const struct rte_mbuf *m)
2249 uint64_t eip_typ = IAVF_TX_CTX_DESC_EIPT_NONE;
2250 uint64_t eip_len = 0;
2251 uint64_t eip_noinc = 0;
2252 /* Default - IP_ID is increment in each segment of LSO */
2254 switch (m->ol_flags & (RTE_MBUF_F_TX_OUTER_IPV4 |
2255 RTE_MBUF_F_TX_OUTER_IPV6 |
2256 RTE_MBUF_F_TX_OUTER_IP_CKSUM)) {
2257 case RTE_MBUF_F_TX_OUTER_IPV4:
2258 eip_typ = IAVF_TX_CTX_DESC_EIPT_IPV4_NO_CHECKSUM_OFFLOAD;
2259 eip_len = m->outer_l3_len >> 2;
2261 case RTE_MBUF_F_TX_OUTER_IPV4 | RTE_MBUF_F_TX_OUTER_IP_CKSUM:
2262 eip_typ = IAVF_TX_CTX_DESC_EIPT_IPV4_CHECKSUM_OFFLOAD;
2263 eip_len = m->outer_l3_len >> 2;
2265 case RTE_MBUF_F_TX_OUTER_IPV6:
2266 eip_typ = IAVF_TX_CTX_DESC_EIPT_IPV6;
2267 eip_len = m->outer_l3_len >> 2;
2271 *qw0 = eip_typ << IAVF_TXD_CTX_QW0_TUN_PARAMS_EIPT_SHIFT |
2272 eip_len << IAVF_TXD_CTX_QW0_TUN_PARAMS_EIPLEN_SHIFT |
2273 eip_noinc << IAVF_TXD_CTX_QW0_TUN_PARAMS_EIP_NOINC_SHIFT;
2276 static inline uint16_t
2277 iavf_fill_ctx_desc_segmentation_field(volatile uint64_t *field,
2278 struct rte_mbuf *m, struct iavf_ipsec_crypto_pkt_metadata *ipsec_md)
2280 uint64_t segmentation_field = 0;
2281 uint64_t total_length = 0;
2283 if (m->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD) {
2284 total_length = ipsec_md->l4_payload_len;
2286 total_length = m->pkt_len - (m->l2_len + m->l3_len + m->l4_len);
2288 if (m->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK)
2289 total_length -= m->outer_l3_len;
2292 #ifdef RTE_LIBRTE_IAVF_DEBUG_TX
2293 if (!m->l4_len || !m->tso_segsz)
2294 PMD_TX_LOG(DEBUG, "L4 length %d, LSO Segment size %d",
2295 m->l4_len, m->tso_segsz);
2296 if (m->tso_segsz < 88)
2297 PMD_TX_LOG(DEBUG, "LSO Segment size %d is less than minimum %d",
2300 segmentation_field =
2301 (((uint64_t)total_length << IAVF_TXD_CTX_QW1_TSO_LEN_SHIFT) &
2302 IAVF_TXD_CTX_QW1_TSO_LEN_MASK) |
2303 (((uint64_t)m->tso_segsz << IAVF_TXD_CTX_QW1_MSS_SHIFT) &
2304 IAVF_TXD_CTX_QW1_MSS_MASK);
2306 *field |= segmentation_field;
2308 return total_length;
2312 struct iavf_tx_context_desc_qws {
2318 iavf_fill_context_desc(volatile struct iavf_tx_context_desc *desc,
2319 struct rte_mbuf *m, struct iavf_ipsec_crypto_pkt_metadata *ipsec_md,
2320 uint16_t *tlen, uint8_t vlan_flag)
2322 volatile struct iavf_tx_context_desc_qws *desc_qws =
2323 (volatile struct iavf_tx_context_desc_qws *)desc;
2324 /* fill descriptor type field */
2325 desc_qws->qw1 = IAVF_TX_DESC_DTYPE_CONTEXT;
2327 /* fill command field */
2328 iavf_fill_ctx_desc_cmd_field(&desc_qws->qw1, m, vlan_flag);
2330 /* fill segmentation field */
2331 if (m->ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) {
2332 /* fill IPsec field */
2333 if (m->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD)
2334 iavf_fill_ctx_desc_ipsec_field(&desc_qws->qw1,
2337 *tlen = iavf_fill_ctx_desc_segmentation_field(&desc_qws->qw1,
2341 /* fill tunnelling field */
2342 if (m->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK)
2343 iavf_fill_ctx_desc_tunnelling_field(&desc_qws->qw0, m);
2347 desc_qws->qw0 = rte_cpu_to_le_64(desc_qws->qw0);
2348 desc_qws->qw1 = rte_cpu_to_le_64(desc_qws->qw1);
2350 if (vlan_flag & IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG2)
2351 desc->l2tag2 = m->vlan_tci;
2356 iavf_fill_ipsec_desc(volatile struct iavf_tx_ipsec_desc *desc,
2357 const struct iavf_ipsec_crypto_pkt_metadata *md, uint16_t *ipsec_len)
2359 desc->qw0 = rte_cpu_to_le_64(((uint64_t)md->l4_payload_len <<
2360 IAVF_IPSEC_TX_DESC_QW0_L4PAYLEN_SHIFT) |
2361 ((uint64_t)md->esn << IAVF_IPSEC_TX_DESC_QW0_IPSECESN_SHIFT) |
2362 ((uint64_t)md->esp_trailer_len <<
2363 IAVF_IPSEC_TX_DESC_QW0_TRAILERLEN_SHIFT));
2365 desc->qw1 = rte_cpu_to_le_64(((uint64_t)md->sa_idx <<
2366 IAVF_IPSEC_TX_DESC_QW1_IPSECSA_SHIFT) |
2367 ((uint64_t)md->next_proto <<
2368 IAVF_IPSEC_TX_DESC_QW1_IPSECNH_SHIFT) |
2369 ((uint64_t)(md->len_iv & 0x3) <<
2370 IAVF_IPSEC_TX_DESC_QW1_IVLEN_SHIFT) |
2371 ((uint64_t)(md->ol_flags & IAVF_IPSEC_CRYPTO_OL_FLAGS_NATT ?
2373 IAVF_IPSEC_TX_DESC_QW1_UDP_SHIFT) |
2374 (uint64_t)IAVF_TX_DESC_DTYPE_IPSEC);
2377 * TODO: Pre-calculate this in the Session initialization
2379 * Calculate IPsec length required in data descriptor func when TSO
2380 * offload is enabled
2382 *ipsec_len = sizeof(struct rte_esp_hdr) + (md->len_iv >> 2) +
2383 (md->ol_flags & IAVF_IPSEC_CRYPTO_OL_FLAGS_NATT ?
2384 sizeof(struct rte_udp_hdr) : 0);
2388 iavf_build_data_desc_cmd_offset_fields(volatile uint64_t *qw1,
2389 struct rte_mbuf *m, uint8_t vlan_flag)
2391 uint64_t command = 0;
2392 uint64_t offset = 0;
2393 uint64_t l2tag1 = 0;
2395 *qw1 = IAVF_TX_DESC_DTYPE_DATA;
2397 command = (uint64_t)IAVF_TX_DESC_CMD_ICRC;
2399 /* Descriptor based VLAN insertion */
2400 if ((vlan_flag & IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG1) &&
2401 m->ol_flags & RTE_MBUF_F_TX_VLAN) {
2402 command |= (uint64_t)IAVF_TX_DESC_CMD_IL2TAG1;
2403 l2tag1 |= m->vlan_tci;
2407 offset |= (m->l2_len >> 1) << IAVF_TX_DESC_LENGTH_MACLEN_SHIFT;
2409 /* Enable L3 checksum offloading inner */
2410 if (m->ol_flags & (RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_IPV4)) {
2411 command |= IAVF_TX_DESC_CMD_IIPT_IPV4_CSUM;
2412 offset |= (m->l3_len >> 2) << IAVF_TX_DESC_LENGTH_IPLEN_SHIFT;
2413 } else if (m->ol_flags & RTE_MBUF_F_TX_IPV4) {
2414 command |= IAVF_TX_DESC_CMD_IIPT_IPV4;
2415 offset |= (m->l3_len >> 2) << IAVF_TX_DESC_LENGTH_IPLEN_SHIFT;
2416 } else if (m->ol_flags & RTE_MBUF_F_TX_IPV6) {
2417 command |= IAVF_TX_DESC_CMD_IIPT_IPV6;
2418 offset |= (m->l3_len >> 2) << IAVF_TX_DESC_LENGTH_IPLEN_SHIFT;
2421 if (m->ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
2422 command |= IAVF_TX_DESC_CMD_L4T_EOFT_TCP;
2423 offset |= (m->l4_len >> 2) <<
2424 IAVF_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
2427 /* Enable L4 checksum offloads */
2428 switch (m->ol_flags & RTE_MBUF_F_TX_L4_MASK) {
2429 case RTE_MBUF_F_TX_TCP_CKSUM:
2430 command |= IAVF_TX_DESC_CMD_L4T_EOFT_TCP;
2431 offset |= (sizeof(struct rte_tcp_hdr) >> 2) <<
2432 IAVF_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
2434 case RTE_MBUF_F_TX_SCTP_CKSUM:
2435 command |= IAVF_TX_DESC_CMD_L4T_EOFT_SCTP;
2436 offset |= (sizeof(struct rte_sctp_hdr) >> 2) <<
2437 IAVF_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
2439 case RTE_MBUF_F_TX_UDP_CKSUM:
2440 command |= IAVF_TX_DESC_CMD_L4T_EOFT_UDP;
2441 offset |= (sizeof(struct rte_udp_hdr) >> 2) <<
2442 IAVF_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
2446 *qw1 = rte_cpu_to_le_64((((uint64_t)command <<
2447 IAVF_TXD_DATA_QW1_CMD_SHIFT) & IAVF_TXD_DATA_QW1_CMD_MASK) |
2448 (((uint64_t)offset << IAVF_TXD_DATA_QW1_OFFSET_SHIFT) &
2449 IAVF_TXD_DATA_QW1_OFFSET_MASK) |
2450 ((uint64_t)l2tag1 << IAVF_TXD_DATA_QW1_L2TAG1_SHIFT));
2454 iavf_fill_data_desc(volatile struct iavf_tx_desc *desc,
2455 struct rte_mbuf *m, uint64_t desc_template,
2456 uint16_t tlen, uint16_t ipseclen)
2458 uint32_t hdrlen = m->l2_len;
2461 /* fill data descriptor qw1 from template */
2462 desc->cmd_type_offset_bsz = desc_template;
2464 /* set data buffer address */
2465 desc->buffer_addr = rte_mbuf_data_iova(m);
2467 /* calculate data buffer size less set header lengths */
2468 if ((m->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) &&
2469 (m->ol_flags & (RTE_MBUF_F_TX_TCP_SEG |
2470 RTE_MBUF_F_TX_UDP_SEG))) {
2471 hdrlen += m->outer_l3_len;
2472 if (m->ol_flags & RTE_MBUF_F_TX_L4_MASK)
2473 hdrlen += m->l3_len + m->l4_len;
2475 hdrlen += m->l3_len;
2476 if (m->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD)
2478 bufsz = hdrlen + tlen;
2479 } else if ((m->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD) &&
2480 (m->ol_flags & (RTE_MBUF_F_TX_TCP_SEG |
2481 RTE_MBUF_F_TX_UDP_SEG))) {
2482 hdrlen += m->outer_l3_len + m->l3_len + ipseclen;
2483 if (m->ol_flags & RTE_MBUF_F_TX_L4_MASK)
2484 hdrlen += m->l4_len;
2485 bufsz = hdrlen + tlen;
2488 bufsz = m->data_len;
2491 /* set data buffer size */
2492 desc->cmd_type_offset_bsz |=
2493 (((uint64_t)bufsz << IAVF_TXD_DATA_QW1_TX_BUF_SZ_SHIFT) &
2494 IAVF_TXD_DATA_QW1_TX_BUF_SZ_MASK);
2496 desc->buffer_addr = rte_cpu_to_le_64(desc->buffer_addr);
2497 desc->cmd_type_offset_bsz = rte_cpu_to_le_64(desc->cmd_type_offset_bsz);
2501 static struct iavf_ipsec_crypto_pkt_metadata *
2502 iavf_ipsec_crypto_get_pkt_metadata(const struct iavf_tx_queue *txq,
2505 if (m->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD)
2506 return RTE_MBUF_DYNFIELD(m, txq->ipsec_crypto_pkt_md_offset,
2507 struct iavf_ipsec_crypto_pkt_metadata *);
2514 iavf_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2516 struct iavf_tx_queue *txq = tx_queue;
2517 volatile struct iavf_tx_desc *txr = txq->tx_ring;
2518 struct iavf_tx_entry *txe_ring = txq->sw_ring;
2519 struct iavf_tx_entry *txe, *txn;
2520 struct rte_mbuf *mb, *mb_seg;
2521 uint16_t desc_idx, desc_idx_last;
2525 /* Check if the descriptor ring needs to be cleaned. */
2526 if (txq->nb_free < txq->free_thresh)
2527 iavf_xmit_cleanup(txq);
2529 desc_idx = txq->tx_tail;
2530 txe = &txe_ring[desc_idx];
2532 #ifdef RTE_LIBRTE_IAVF_DEBUG_TX_DESC_RING
2533 iavf_dump_tx_entry_ring(txq);
2534 iavf_dump_tx_desc_ring(txq);
2538 for (idx = 0; idx < nb_pkts; idx++) {
2539 volatile struct iavf_tx_desc *ddesc;
2540 struct iavf_ipsec_crypto_pkt_metadata *ipsec_md;
2542 uint16_t nb_desc_ctx, nb_desc_ipsec;
2543 uint16_t nb_desc_data, nb_desc_required;
2544 uint16_t tlen = 0, ipseclen = 0;
2545 uint64_t ddesc_template = 0;
2546 uint64_t ddesc_cmd = 0;
2550 RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
2553 * Get metadata for ipsec crypto from mbuf dynamic fields if
2554 * security offload is specified.
2556 ipsec_md = iavf_ipsec_crypto_get_pkt_metadata(txq, mb);
2558 nb_desc_data = mb->nb_segs;
2560 iavf_calc_context_desc(mb->ol_flags, txq->vlan_flag);
2561 nb_desc_ipsec = !!(mb->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD);
2564 * The number of descriptors that must be allocated for
2565 * a packet equals to the number of the segments of that
2566 * packet plus the context and ipsec descriptors if needed.
2568 nb_desc_required = nb_desc_data + nb_desc_ctx + nb_desc_ipsec;
2570 desc_idx_last = (uint16_t)(desc_idx + nb_desc_required - 1);
2572 /* wrap descriptor ring */
2573 if (desc_idx_last >= txq->nb_tx_desc)
2575 (uint16_t)(desc_idx_last - txq->nb_tx_desc);
2578 "port_id=%u queue_id=%u tx_first=%u tx_last=%u",
2579 txq->port_id, txq->queue_id, desc_idx, desc_idx_last);
2581 if (nb_desc_required > txq->nb_free) {
2582 if (iavf_xmit_cleanup(txq)) {
2587 if (unlikely(nb_desc_required > txq->rs_thresh)) {
2588 while (nb_desc_required > txq->nb_free) {
2589 if (iavf_xmit_cleanup(txq)) {
2598 iavf_build_data_desc_cmd_offset_fields(&ddesc_template, mb,
2601 /* Setup TX context descriptor if required */
2603 volatile struct iavf_tx_context_desc *ctx_desc =
2604 (volatile struct iavf_tx_context_desc *)
2607 /* clear QW0 or the previous writeback value
2608 * may impact next write
2610 *(volatile uint64_t *)ctx_desc = 0;
2612 txn = &txe_ring[txe->next_id];
2613 RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
2616 rte_pktmbuf_free_seg(txe->mbuf);
2620 iavf_fill_context_desc(ctx_desc, mb, ipsec_md, &tlen,
2622 IAVF_DUMP_TX_DESC(txq, ctx_desc, desc_idx);
2624 txe->last_id = desc_idx_last;
2625 desc_idx = txe->next_id;
2629 if (nb_desc_ipsec) {
2630 volatile struct iavf_tx_ipsec_desc *ipsec_desc =
2631 (volatile struct iavf_tx_ipsec_desc *)
2634 txn = &txe_ring[txe->next_id];
2635 RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
2638 rte_pktmbuf_free_seg(txe->mbuf);
2642 iavf_fill_ipsec_desc(ipsec_desc, ipsec_md, &ipseclen);
2644 IAVF_DUMP_TX_DESC(txq, ipsec_desc, desc_idx);
2646 txe->last_id = desc_idx_last;
2647 desc_idx = txe->next_id;
2654 ddesc = (volatile struct iavf_tx_desc *)
2657 txn = &txe_ring[txe->next_id];
2658 RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
2661 rte_pktmbuf_free_seg(txe->mbuf);
2664 iavf_fill_data_desc(ddesc, mb_seg,
2665 ddesc_template, tlen, ipseclen);
2667 IAVF_DUMP_TX_DESC(txq, ddesc, desc_idx);
2669 txe->last_id = desc_idx_last;
2670 desc_idx = txe->next_id;
2672 mb_seg = mb_seg->next;
2675 /* The last packet data descriptor needs End Of Packet (EOP) */
2676 ddesc_cmd = IAVF_TX_DESC_CMD_EOP;
2678 txq->nb_used = (uint16_t)(txq->nb_used + nb_desc_required);
2679 txq->nb_free = (uint16_t)(txq->nb_free - nb_desc_required);
2681 if (txq->nb_used >= txq->rs_thresh) {
2682 PMD_TX_LOG(DEBUG, "Setting RS bit on TXD id="
2683 "%4u (port=%d queue=%d)",
2684 desc_idx_last, txq->port_id, txq->queue_id);
2686 ddesc_cmd |= IAVF_TX_DESC_CMD_RS;
2688 /* Update txq RS bit counters */
2692 ddesc->cmd_type_offset_bsz |= rte_cpu_to_le_64(ddesc_cmd <<
2693 IAVF_TXD_DATA_QW1_CMD_SHIFT);
2695 IAVF_DUMP_TX_DESC(txq, ddesc, desc_idx - 1);
2701 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
2702 txq->port_id, txq->queue_id, desc_idx, idx);
2704 IAVF_PCI_REG_WRITE_RELAXED(txq->qtx_tail, desc_idx);
2705 txq->tx_tail = desc_idx;
2710 /* Check if the packet with vlan user priority is transmitted in the
2714 iavf_check_vlan_up2tc(struct iavf_tx_queue *txq, struct rte_mbuf *m)
2716 struct rte_eth_dev *dev = &rte_eth_devices[txq->port_id];
2717 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2720 up = m->vlan_tci >> IAVF_VLAN_TAG_PCP_OFFSET;
2722 if (!(vf->qos_cap->cap[txq->tc].tc_prio & BIT(up))) {
2723 PMD_TX_LOG(ERR, "packet with vlan pcp %u cannot transmit in queue %u\n",
2731 /* TX prep functions */
2733 iavf_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
2739 struct iavf_tx_queue *txq = tx_queue;
2740 struct rte_eth_dev *dev = &rte_eth_devices[txq->port_id];
2741 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2743 for (i = 0; i < nb_pkts; i++) {
2745 ol_flags = m->ol_flags;
2747 /* Check condition for nb_segs > IAVF_TX_MAX_MTU_SEG. */
2748 if (!(ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
2749 if (m->nb_segs > IAVF_TX_MAX_MTU_SEG) {
2753 } else if ((m->tso_segsz < IAVF_MIN_TSO_MSS) ||
2754 (m->tso_segsz > IAVF_MAX_TSO_MSS)) {
2755 /* MSS outside the range are considered malicious */
2760 if (ol_flags & IAVF_TX_OFFLOAD_NOTSUP_MASK) {
2761 rte_errno = ENOTSUP;
2765 #ifdef RTE_ETHDEV_DEBUG_TX
2766 ret = rte_validate_tx_offload(m);
2772 ret = rte_net_intel_cksum_prepare(m);
2778 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS &&
2779 ol_flags & (RTE_MBUF_F_RX_VLAN_STRIPPED | RTE_MBUF_F_RX_VLAN)) {
2780 ret = iavf_check_vlan_up2tc(txq, m);
2791 /* choose rx function*/
2793 iavf_set_rx_function(struct rte_eth_dev *dev)
2795 struct iavf_adapter *adapter =
2796 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2797 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2800 struct iavf_rx_queue *rxq;
2803 bool use_avx2 = false;
2804 bool use_avx512 = false;
2805 bool use_flex = false;
2807 check_ret = iavf_rx_vec_dev_check(dev);
2808 if (check_ret >= 0 &&
2809 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
2810 if ((rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1 ||
2811 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1) &&
2812 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256)
2815 #ifdef CC_AVX512_SUPPORT
2816 if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1 &&
2817 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512BW) == 1 &&
2818 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512)
2822 if (vf->vf_res->vf_cap_flags &
2823 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)
2826 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2827 rxq = dev->data->rx_queues[i];
2828 (void)iavf_rxq_vec_setup(rxq);
2831 if (dev->data->scattered_rx) {
2834 "Using %sVector Scattered Rx (port %d).",
2835 use_avx2 ? "avx2 " : "",
2836 dev->data->port_id);
2838 if (check_ret == IAVF_VECTOR_PATH)
2840 "Using AVX512 Vector Scattered Rx (port %d).",
2841 dev->data->port_id);
2844 "Using AVX512 OFFLOAD Vector Scattered Rx (port %d).",
2845 dev->data->port_id);
2848 dev->rx_pkt_burst = use_avx2 ?
2849 iavf_recv_scattered_pkts_vec_avx2_flex_rxd :
2850 iavf_recv_scattered_pkts_vec_flex_rxd;
2851 #ifdef CC_AVX512_SUPPORT
2853 if (check_ret == IAVF_VECTOR_PATH)
2855 iavf_recv_scattered_pkts_vec_avx512_flex_rxd;
2858 iavf_recv_scattered_pkts_vec_avx512_flex_rxd_offload;
2862 dev->rx_pkt_burst = use_avx2 ?
2863 iavf_recv_scattered_pkts_vec_avx2 :
2864 iavf_recv_scattered_pkts_vec;
2865 #ifdef CC_AVX512_SUPPORT
2867 if (check_ret == IAVF_VECTOR_PATH)
2869 iavf_recv_scattered_pkts_vec_avx512;
2872 iavf_recv_scattered_pkts_vec_avx512_offload;
2878 PMD_DRV_LOG(DEBUG, "Using %sVector Rx (port %d).",
2879 use_avx2 ? "avx2 " : "",
2880 dev->data->port_id);
2882 if (check_ret == IAVF_VECTOR_PATH)
2884 "Using AVX512 Vector Rx (port %d).",
2885 dev->data->port_id);
2888 "Using AVX512 OFFLOAD Vector Rx (port %d).",
2889 dev->data->port_id);
2892 dev->rx_pkt_burst = use_avx2 ?
2893 iavf_recv_pkts_vec_avx2_flex_rxd :
2894 iavf_recv_pkts_vec_flex_rxd;
2895 #ifdef CC_AVX512_SUPPORT
2897 if (check_ret == IAVF_VECTOR_PATH)
2899 iavf_recv_pkts_vec_avx512_flex_rxd;
2902 iavf_recv_pkts_vec_avx512_flex_rxd_offload;
2906 dev->rx_pkt_burst = use_avx2 ?
2907 iavf_recv_pkts_vec_avx2 :
2909 #ifdef CC_AVX512_SUPPORT
2911 if (check_ret == IAVF_VECTOR_PATH)
2913 iavf_recv_pkts_vec_avx512;
2916 iavf_recv_pkts_vec_avx512_offload;
2926 if (dev->data->scattered_rx) {
2927 PMD_DRV_LOG(DEBUG, "Using a Scattered Rx callback (port=%d).",
2928 dev->data->port_id);
2929 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)
2930 dev->rx_pkt_burst = iavf_recv_scattered_pkts_flex_rxd;
2932 dev->rx_pkt_burst = iavf_recv_scattered_pkts;
2933 } else if (adapter->rx_bulk_alloc_allowed) {
2934 PMD_DRV_LOG(DEBUG, "Using bulk Rx callback (port=%d).",
2935 dev->data->port_id);
2936 dev->rx_pkt_burst = iavf_recv_pkts_bulk_alloc;
2938 PMD_DRV_LOG(DEBUG, "Using Basic Rx callback (port=%d).",
2939 dev->data->port_id);
2940 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)
2941 dev->rx_pkt_burst = iavf_recv_pkts_flex_rxd;
2943 dev->rx_pkt_burst = iavf_recv_pkts;
2947 /* choose tx function*/
2949 iavf_set_tx_function(struct rte_eth_dev *dev)
2952 struct iavf_tx_queue *txq;
2955 bool use_sse = false;
2956 bool use_avx2 = false;
2957 bool use_avx512 = false;
2959 check_ret = iavf_tx_vec_dev_check(dev);
2961 if (check_ret >= 0 &&
2962 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
2963 /* SSE and AVX2 not support offload path yet. */
2964 if (check_ret == IAVF_VECTOR_PATH) {
2966 if ((rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1 ||
2967 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1) &&
2968 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256)
2971 #ifdef CC_AVX512_SUPPORT
2972 if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1 &&
2973 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512BW) == 1 &&
2974 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512)
2978 if (!use_sse && !use_avx2 && !use_avx512)
2982 PMD_DRV_LOG(DEBUG, "Using %sVector Tx (port %d).",
2983 use_avx2 ? "avx2 " : "",
2984 dev->data->port_id);
2985 dev->tx_pkt_burst = use_avx2 ?
2986 iavf_xmit_pkts_vec_avx2 :
2989 dev->tx_pkt_prepare = NULL;
2990 #ifdef CC_AVX512_SUPPORT
2992 if (check_ret == IAVF_VECTOR_PATH) {
2993 dev->tx_pkt_burst = iavf_xmit_pkts_vec_avx512;
2994 PMD_DRV_LOG(DEBUG, "Using AVX512 Vector Tx (port %d).",
2995 dev->data->port_id);
2997 dev->tx_pkt_burst = iavf_xmit_pkts_vec_avx512_offload;
2998 dev->tx_pkt_prepare = iavf_prep_pkts;
2999 PMD_DRV_LOG(DEBUG, "Using AVX512 OFFLOAD Vector Tx (port %d).",
3000 dev->data->port_id);
3005 for (i = 0; i < dev->data->nb_tx_queues; i++) {
3006 txq = dev->data->tx_queues[i];
3009 #ifdef CC_AVX512_SUPPORT
3011 iavf_txq_vec_setup_avx512(txq);
3013 iavf_txq_vec_setup(txq);
3015 iavf_txq_vec_setup(txq);
3024 PMD_DRV_LOG(DEBUG, "Using Basic Tx callback (port=%d).",
3025 dev->data->port_id);
3026 dev->tx_pkt_burst = iavf_xmit_pkts;
3027 dev->tx_pkt_prepare = iavf_prep_pkts;
3031 iavf_tx_done_cleanup_full(struct iavf_tx_queue *txq,
3034 struct iavf_tx_entry *swr_ring = txq->sw_ring;
3035 uint16_t i, tx_last, tx_id;
3036 uint16_t nb_tx_free_last;
3037 uint16_t nb_tx_to_clean;
3040 /* Start free mbuf from the next of tx_tail */
3041 tx_last = txq->tx_tail;
3042 tx_id = swr_ring[tx_last].next_id;
3044 if (txq->nb_free == 0 && iavf_xmit_cleanup(txq))
3047 nb_tx_to_clean = txq->nb_free;
3048 nb_tx_free_last = txq->nb_free;
3050 free_cnt = txq->nb_tx_desc;
3052 /* Loop through swr_ring to count the amount of
3053 * freeable mubfs and packets.
3055 for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
3056 for (i = 0; i < nb_tx_to_clean &&
3057 pkt_cnt < free_cnt &&
3058 tx_id != tx_last; i++) {
3059 if (swr_ring[tx_id].mbuf != NULL) {
3060 rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
3061 swr_ring[tx_id].mbuf = NULL;
3064 * last segment in the packet,
3065 * increment packet count
3067 pkt_cnt += (swr_ring[tx_id].last_id == tx_id);
3070 tx_id = swr_ring[tx_id].next_id;
3073 if (txq->rs_thresh > txq->nb_tx_desc -
3074 txq->nb_free || tx_id == tx_last)
3077 if (pkt_cnt < free_cnt) {
3078 if (iavf_xmit_cleanup(txq))
3081 nb_tx_to_clean = txq->nb_free - nb_tx_free_last;
3082 nb_tx_free_last = txq->nb_free;
3086 return (int)pkt_cnt;
3090 iavf_dev_tx_done_cleanup(void *txq, uint32_t free_cnt)
3092 struct iavf_tx_queue *q = (struct iavf_tx_queue *)txq;
3094 return iavf_tx_done_cleanup_full(q, free_cnt);
3098 iavf_dev_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
3099 struct rte_eth_rxq_info *qinfo)
3101 struct iavf_rx_queue *rxq;
3103 rxq = dev->data->rx_queues[queue_id];
3105 qinfo->mp = rxq->mp;
3106 qinfo->scattered_rx = dev->data->scattered_rx;
3107 qinfo->nb_desc = rxq->nb_rx_desc;
3109 qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
3110 qinfo->conf.rx_drop_en = true;
3111 qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
3115 iavf_dev_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
3116 struct rte_eth_txq_info *qinfo)
3118 struct iavf_tx_queue *txq;
3120 txq = dev->data->tx_queues[queue_id];
3122 qinfo->nb_desc = txq->nb_tx_desc;
3124 qinfo->conf.tx_free_thresh = txq->free_thresh;
3125 qinfo->conf.tx_rs_thresh = txq->rs_thresh;
3126 qinfo->conf.offloads = txq->offloads;
3127 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
3130 /* Get the number of used descriptors of a rx queue */
3132 iavf_dev_rxq_count(void *rx_queue)
3134 #define IAVF_RXQ_SCAN_INTERVAL 4
3135 volatile union iavf_rx_desc *rxdp;
3136 struct iavf_rx_queue *rxq;
3140 rxdp = &rxq->rx_ring[rxq->rx_tail];
3142 while ((desc < rxq->nb_rx_desc) &&
3143 ((rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
3144 IAVF_RXD_QW1_STATUS_MASK) >> IAVF_RXD_QW1_STATUS_SHIFT) &
3145 (1 << IAVF_RX_DESC_STATUS_DD_SHIFT)) {
3146 /* Check the DD bit of a rx descriptor of each 4 in a group,
3147 * to avoid checking too frequently and downgrading performance
3150 desc += IAVF_RXQ_SCAN_INTERVAL;
3151 rxdp += IAVF_RXQ_SCAN_INTERVAL;
3152 if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
3153 rxdp = &(rxq->rx_ring[rxq->rx_tail +
3154 desc - rxq->nb_rx_desc]);
3161 iavf_dev_rx_desc_status(void *rx_queue, uint16_t offset)
3163 struct iavf_rx_queue *rxq = rx_queue;
3164 volatile uint64_t *status;
3168 if (unlikely(offset >= rxq->nb_rx_desc))
3171 if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
3172 return RTE_ETH_RX_DESC_UNAVAIL;
3174 desc = rxq->rx_tail + offset;
3175 if (desc >= rxq->nb_rx_desc)
3176 desc -= rxq->nb_rx_desc;
3178 status = &rxq->rx_ring[desc].wb.qword1.status_error_len;
3179 mask = rte_le_to_cpu_64((1ULL << IAVF_RX_DESC_STATUS_DD_SHIFT)
3180 << IAVF_RXD_QW1_STATUS_SHIFT);
3182 return RTE_ETH_RX_DESC_DONE;
3184 return RTE_ETH_RX_DESC_AVAIL;
3188 iavf_dev_tx_desc_status(void *tx_queue, uint16_t offset)
3190 struct iavf_tx_queue *txq = tx_queue;
3191 volatile uint64_t *status;
3192 uint64_t mask, expect;
3195 if (unlikely(offset >= txq->nb_tx_desc))
3198 desc = txq->tx_tail + offset;
3199 /* go to next desc that has the RS bit */
3200 desc = ((desc + txq->rs_thresh - 1) / txq->rs_thresh) *
3202 if (desc >= txq->nb_tx_desc) {
3203 desc -= txq->nb_tx_desc;
3204 if (desc >= txq->nb_tx_desc)
3205 desc -= txq->nb_tx_desc;
3208 status = &txq->tx_ring[desc].cmd_type_offset_bsz;
3209 mask = rte_le_to_cpu_64(IAVF_TXD_QW1_DTYPE_MASK);
3210 expect = rte_cpu_to_le_64(
3211 IAVF_TX_DESC_DTYPE_DESC_DONE << IAVF_TXD_QW1_DTYPE_SHIFT);
3212 if ((*status & mask) == expect)
3213 return RTE_ETH_TX_DESC_DONE;
3215 return RTE_ETH_TX_DESC_FULL;
3218 static inline uint32_t
3219 iavf_get_default_ptype(uint16_t ptype)
3221 static const uint32_t ptype_tbl[IAVF_MAX_PKT_TYPE]
3222 __rte_cache_aligned = {
3225 [1] = RTE_PTYPE_L2_ETHER,
3226 [2] = RTE_PTYPE_L2_ETHER_TIMESYNC,
3227 /* [3] - [5] reserved */
3228 [6] = RTE_PTYPE_L2_ETHER_LLDP,
3229 /* [7] - [10] reserved */
3230 [11] = RTE_PTYPE_L2_ETHER_ARP,
3231 /* [12] - [21] reserved */
3233 /* Non tunneled IPv4 */
3234 [22] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3236 [23] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3237 RTE_PTYPE_L4_NONFRAG,
3238 [24] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3241 [26] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3243 [27] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3245 [28] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3249 [29] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3250 RTE_PTYPE_TUNNEL_IP |
3251 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3252 RTE_PTYPE_INNER_L4_FRAG,
3253 [30] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3254 RTE_PTYPE_TUNNEL_IP |
3255 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3256 RTE_PTYPE_INNER_L4_NONFRAG,
3257 [31] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3258 RTE_PTYPE_TUNNEL_IP |
3259 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3260 RTE_PTYPE_INNER_L4_UDP,
3262 [33] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3263 RTE_PTYPE_TUNNEL_IP |
3264 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3265 RTE_PTYPE_INNER_L4_TCP,
3266 [34] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3267 RTE_PTYPE_TUNNEL_IP |
3268 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3269 RTE_PTYPE_INNER_L4_SCTP,
3270 [35] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3271 RTE_PTYPE_TUNNEL_IP |
3272 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3273 RTE_PTYPE_INNER_L4_ICMP,
3276 [36] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3277 RTE_PTYPE_TUNNEL_IP |
3278 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3279 RTE_PTYPE_INNER_L4_FRAG,
3280 [37] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3281 RTE_PTYPE_TUNNEL_IP |
3282 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3283 RTE_PTYPE_INNER_L4_NONFRAG,
3284 [38] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3285 RTE_PTYPE_TUNNEL_IP |
3286 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3287 RTE_PTYPE_INNER_L4_UDP,
3289 [40] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3290 RTE_PTYPE_TUNNEL_IP |
3291 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3292 RTE_PTYPE_INNER_L4_TCP,
3293 [41] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3294 RTE_PTYPE_TUNNEL_IP |
3295 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3296 RTE_PTYPE_INNER_L4_SCTP,
3297 [42] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3298 RTE_PTYPE_TUNNEL_IP |
3299 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3300 RTE_PTYPE_INNER_L4_ICMP,
3302 /* IPv4 --> GRE/Teredo/VXLAN */
3303 [43] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3304 RTE_PTYPE_TUNNEL_GRENAT,
3306 /* IPv4 --> GRE/Teredo/VXLAN --> IPv4 */
3307 [44] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3308 RTE_PTYPE_TUNNEL_GRENAT |
3309 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3310 RTE_PTYPE_INNER_L4_FRAG,
3311 [45] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3312 RTE_PTYPE_TUNNEL_GRENAT |
3313 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3314 RTE_PTYPE_INNER_L4_NONFRAG,
3315 [46] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3316 RTE_PTYPE_TUNNEL_GRENAT |
3317 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3318 RTE_PTYPE_INNER_L4_UDP,
3320 [48] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3321 RTE_PTYPE_TUNNEL_GRENAT |
3322 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3323 RTE_PTYPE_INNER_L4_TCP,
3324 [49] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3325 RTE_PTYPE_TUNNEL_GRENAT |
3326 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3327 RTE_PTYPE_INNER_L4_SCTP,
3328 [50] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3329 RTE_PTYPE_TUNNEL_GRENAT |
3330 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3331 RTE_PTYPE_INNER_L4_ICMP,
3333 /* IPv4 --> GRE/Teredo/VXLAN --> IPv6 */
3334 [51] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3335 RTE_PTYPE_TUNNEL_GRENAT |
3336 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3337 RTE_PTYPE_INNER_L4_FRAG,
3338 [52] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3339 RTE_PTYPE_TUNNEL_GRENAT |
3340 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3341 RTE_PTYPE_INNER_L4_NONFRAG,
3342 [53] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3343 RTE_PTYPE_TUNNEL_GRENAT |
3344 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3345 RTE_PTYPE_INNER_L4_UDP,
3347 [55] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3348 RTE_PTYPE_TUNNEL_GRENAT |
3349 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3350 RTE_PTYPE_INNER_L4_TCP,
3351 [56] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3352 RTE_PTYPE_TUNNEL_GRENAT |
3353 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3354 RTE_PTYPE_INNER_L4_SCTP,
3355 [57] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3356 RTE_PTYPE_TUNNEL_GRENAT |
3357 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3358 RTE_PTYPE_INNER_L4_ICMP,
3360 /* IPv4 --> GRE/Teredo/VXLAN --> MAC */
3361 [58] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3362 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER,
3364 /* IPv4 --> GRE/Teredo/VXLAN --> MAC --> IPv4 */
3365 [59] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3366 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3367 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3368 RTE_PTYPE_INNER_L4_FRAG,
3369 [60] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3370 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3371 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3372 RTE_PTYPE_INNER_L4_NONFRAG,
3373 [61] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3374 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3375 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3376 RTE_PTYPE_INNER_L4_UDP,
3378 [63] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3379 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3380 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3381 RTE_PTYPE_INNER_L4_TCP,
3382 [64] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3383 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3384 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3385 RTE_PTYPE_INNER_L4_SCTP,
3386 [65] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3387 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3388 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3389 RTE_PTYPE_INNER_L4_ICMP,
3391 /* IPv4 --> GRE/Teredo/VXLAN --> MAC --> IPv6 */
3392 [66] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3393 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3394 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3395 RTE_PTYPE_INNER_L4_FRAG,
3396 [67] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3397 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3398 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3399 RTE_PTYPE_INNER_L4_NONFRAG,
3400 [68] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3401 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3402 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3403 RTE_PTYPE_INNER_L4_UDP,
3405 [70] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3406 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3407 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3408 RTE_PTYPE_INNER_L4_TCP,
3409 [71] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3410 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3411 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3412 RTE_PTYPE_INNER_L4_SCTP,
3413 [72] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3414 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3415 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3416 RTE_PTYPE_INNER_L4_ICMP,
3417 /* [73] - [87] reserved */
3419 /* Non tunneled IPv6 */
3420 [88] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3422 [89] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3423 RTE_PTYPE_L4_NONFRAG,
3424 [90] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3427 [92] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3429 [93] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3431 [94] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3435 [95] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3436 RTE_PTYPE_TUNNEL_IP |
3437 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3438 RTE_PTYPE_INNER_L4_FRAG,
3439 [96] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3440 RTE_PTYPE_TUNNEL_IP |
3441 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3442 RTE_PTYPE_INNER_L4_NONFRAG,
3443 [97] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3444 RTE_PTYPE_TUNNEL_IP |
3445 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3446 RTE_PTYPE_INNER_L4_UDP,
3448 [99] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3449 RTE_PTYPE_TUNNEL_IP |
3450 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3451 RTE_PTYPE_INNER_L4_TCP,
3452 [100] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3453 RTE_PTYPE_TUNNEL_IP |
3454 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3455 RTE_PTYPE_INNER_L4_SCTP,
3456 [101] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3457 RTE_PTYPE_TUNNEL_IP |
3458 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3459 RTE_PTYPE_INNER_L4_ICMP,
3462 [102] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3463 RTE_PTYPE_TUNNEL_IP |
3464 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3465 RTE_PTYPE_INNER_L4_FRAG,
3466 [103] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3467 RTE_PTYPE_TUNNEL_IP |
3468 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3469 RTE_PTYPE_INNER_L4_NONFRAG,
3470 [104] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3471 RTE_PTYPE_TUNNEL_IP |
3472 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3473 RTE_PTYPE_INNER_L4_UDP,
3474 /* [105] reserved */
3475 [106] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3476 RTE_PTYPE_TUNNEL_IP |
3477 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3478 RTE_PTYPE_INNER_L4_TCP,
3479 [107] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3480 RTE_PTYPE_TUNNEL_IP |
3481 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3482 RTE_PTYPE_INNER_L4_SCTP,
3483 [108] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3484 RTE_PTYPE_TUNNEL_IP |
3485 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3486 RTE_PTYPE_INNER_L4_ICMP,
3488 /* IPv6 --> GRE/Teredo/VXLAN */
3489 [109] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3490 RTE_PTYPE_TUNNEL_GRENAT,
3492 /* IPv6 --> GRE/Teredo/VXLAN --> IPv4 */
3493 [110] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3494 RTE_PTYPE_TUNNEL_GRENAT |
3495 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3496 RTE_PTYPE_INNER_L4_FRAG,
3497 [111] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3498 RTE_PTYPE_TUNNEL_GRENAT |
3499 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3500 RTE_PTYPE_INNER_L4_NONFRAG,
3501 [112] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3502 RTE_PTYPE_TUNNEL_GRENAT |
3503 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3504 RTE_PTYPE_INNER_L4_UDP,
3505 /* [113] reserved */
3506 [114] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3507 RTE_PTYPE_TUNNEL_GRENAT |
3508 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3509 RTE_PTYPE_INNER_L4_TCP,
3510 [115] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3511 RTE_PTYPE_TUNNEL_GRENAT |
3512 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3513 RTE_PTYPE_INNER_L4_SCTP,
3514 [116] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3515 RTE_PTYPE_TUNNEL_GRENAT |
3516 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3517 RTE_PTYPE_INNER_L4_ICMP,
3519 /* IPv6 --> GRE/Teredo/VXLAN --> IPv6 */
3520 [117] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3521 RTE_PTYPE_TUNNEL_GRENAT |
3522 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3523 RTE_PTYPE_INNER_L4_FRAG,
3524 [118] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3525 RTE_PTYPE_TUNNEL_GRENAT |
3526 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3527 RTE_PTYPE_INNER_L4_NONFRAG,
3528 [119] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3529 RTE_PTYPE_TUNNEL_GRENAT |
3530 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3531 RTE_PTYPE_INNER_L4_UDP,
3532 /* [120] reserved */
3533 [121] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3534 RTE_PTYPE_TUNNEL_GRENAT |
3535 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3536 RTE_PTYPE_INNER_L4_TCP,
3537 [122] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3538 RTE_PTYPE_TUNNEL_GRENAT |
3539 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3540 RTE_PTYPE_INNER_L4_SCTP,
3541 [123] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3542 RTE_PTYPE_TUNNEL_GRENAT |
3543 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3544 RTE_PTYPE_INNER_L4_ICMP,
3546 /* IPv6 --> GRE/Teredo/VXLAN --> MAC */
3547 [124] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3548 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER,
3550 /* IPv6 --> GRE/Teredo/VXLAN --> MAC --> IPv4 */
3551 [125] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3552 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3553 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3554 RTE_PTYPE_INNER_L4_FRAG,
3555 [126] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3556 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3557 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3558 RTE_PTYPE_INNER_L4_NONFRAG,
3559 [127] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3560 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3561 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3562 RTE_PTYPE_INNER_L4_UDP,
3563 /* [128] reserved */
3564 [129] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3565 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3566 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3567 RTE_PTYPE_INNER_L4_TCP,
3568 [130] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3569 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3570 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3571 RTE_PTYPE_INNER_L4_SCTP,
3572 [131] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3573 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3574 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3575 RTE_PTYPE_INNER_L4_ICMP,
3577 /* IPv6 --> GRE/Teredo/VXLAN --> MAC --> IPv6 */
3578 [132] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3579 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3580 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3581 RTE_PTYPE_INNER_L4_FRAG,
3582 [133] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3583 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3584 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3585 RTE_PTYPE_INNER_L4_NONFRAG,
3586 [134] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3587 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3588 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3589 RTE_PTYPE_INNER_L4_UDP,
3590 /* [135] reserved */
3591 [136] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3592 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3593 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3594 RTE_PTYPE_INNER_L4_TCP,
3595 [137] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3596 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3597 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3598 RTE_PTYPE_INNER_L4_SCTP,
3599 [138] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3600 RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
3601 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3602 RTE_PTYPE_INNER_L4_ICMP,
3603 /* [139] - [299] reserved */
3606 [300] = RTE_PTYPE_L2_ETHER_PPPOE,
3607 [301] = RTE_PTYPE_L2_ETHER_PPPOE,
3609 /* PPPoE --> IPv4 */
3610 [302] = RTE_PTYPE_L2_ETHER_PPPOE |
3611 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3613 [303] = RTE_PTYPE_L2_ETHER_PPPOE |
3614 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3615 RTE_PTYPE_L4_NONFRAG,
3616 [304] = RTE_PTYPE_L2_ETHER_PPPOE |
3617 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3619 [305] = RTE_PTYPE_L2_ETHER_PPPOE |
3620 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3622 [306] = RTE_PTYPE_L2_ETHER_PPPOE |
3623 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3625 [307] = RTE_PTYPE_L2_ETHER_PPPOE |
3626 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3629 /* PPPoE --> IPv6 */
3630 [308] = RTE_PTYPE_L2_ETHER_PPPOE |
3631 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3633 [309] = RTE_PTYPE_L2_ETHER_PPPOE |
3634 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3635 RTE_PTYPE_L4_NONFRAG,
3636 [310] = RTE_PTYPE_L2_ETHER_PPPOE |
3637 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3639 [311] = RTE_PTYPE_L2_ETHER_PPPOE |
3640 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3642 [312] = RTE_PTYPE_L2_ETHER_PPPOE |
3643 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3645 [313] = RTE_PTYPE_L2_ETHER_PPPOE |
3646 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3648 /* [314] - [324] reserved */
3650 /* IPv4/IPv6 --> GTPC/GTPU */
3651 [325] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3652 RTE_PTYPE_TUNNEL_GTPC,
3653 [326] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3654 RTE_PTYPE_TUNNEL_GTPC,
3655 [327] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3656 RTE_PTYPE_TUNNEL_GTPC,
3657 [328] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3658 RTE_PTYPE_TUNNEL_GTPC,
3659 [329] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3660 RTE_PTYPE_TUNNEL_GTPU,
3661 [330] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3662 RTE_PTYPE_TUNNEL_GTPU,
3664 /* IPv4 --> GTPU --> IPv4 */
3665 [331] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3666 RTE_PTYPE_TUNNEL_GTPU |
3667 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3668 RTE_PTYPE_INNER_L4_FRAG,
3669 [332] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3670 RTE_PTYPE_TUNNEL_GTPU |
3671 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3672 RTE_PTYPE_INNER_L4_NONFRAG,
3673 [333] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3674 RTE_PTYPE_TUNNEL_GTPU |
3675 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3676 RTE_PTYPE_INNER_L4_UDP,
3677 [334] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3678 RTE_PTYPE_TUNNEL_GTPU |
3679 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3680 RTE_PTYPE_INNER_L4_TCP,
3681 [335] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3682 RTE_PTYPE_TUNNEL_GTPU |
3683 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3684 RTE_PTYPE_INNER_L4_ICMP,
3686 /* IPv6 --> GTPU --> IPv4 */
3687 [336] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3688 RTE_PTYPE_TUNNEL_GTPU |
3689 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3690 RTE_PTYPE_INNER_L4_FRAG,
3691 [337] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3692 RTE_PTYPE_TUNNEL_GTPU |
3693 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3694 RTE_PTYPE_INNER_L4_NONFRAG,
3695 [338] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3696 RTE_PTYPE_TUNNEL_GTPU |
3697 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3698 RTE_PTYPE_INNER_L4_UDP,
3699 [339] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3700 RTE_PTYPE_TUNNEL_GTPU |
3701 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3702 RTE_PTYPE_INNER_L4_TCP,
3703 [340] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3704 RTE_PTYPE_TUNNEL_GTPU |
3705 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
3706 RTE_PTYPE_INNER_L4_ICMP,
3708 /* IPv4 --> GTPU --> IPv6 */
3709 [341] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3710 RTE_PTYPE_TUNNEL_GTPU |
3711 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3712 RTE_PTYPE_INNER_L4_FRAG,
3713 [342] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3714 RTE_PTYPE_TUNNEL_GTPU |
3715 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3716 RTE_PTYPE_INNER_L4_NONFRAG,
3717 [343] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3718 RTE_PTYPE_TUNNEL_GTPU |
3719 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3720 RTE_PTYPE_INNER_L4_UDP,
3721 [344] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3722 RTE_PTYPE_TUNNEL_GTPU |
3723 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3724 RTE_PTYPE_INNER_L4_TCP,
3725 [345] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3726 RTE_PTYPE_TUNNEL_GTPU |
3727 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3728 RTE_PTYPE_INNER_L4_ICMP,
3730 /* IPv6 --> GTPU --> IPv6 */
3731 [346] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3732 RTE_PTYPE_TUNNEL_GTPU |
3733 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3734 RTE_PTYPE_INNER_L4_FRAG,
3735 [347] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3736 RTE_PTYPE_TUNNEL_GTPU |
3737 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3738 RTE_PTYPE_INNER_L4_NONFRAG,
3739 [348] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3740 RTE_PTYPE_TUNNEL_GTPU |
3741 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3742 RTE_PTYPE_INNER_L4_UDP,
3743 [349] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3744 RTE_PTYPE_TUNNEL_GTPU |
3745 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3746 RTE_PTYPE_INNER_L4_TCP,
3747 [350] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3748 RTE_PTYPE_TUNNEL_GTPU |
3749 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
3750 RTE_PTYPE_INNER_L4_ICMP,
3752 /* IPv4 --> UDP ECPRI */
3753 [372] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3755 [373] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3757 [374] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3759 [375] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3761 [376] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3763 [377] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3765 [378] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3767 [379] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3769 [380] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3771 [381] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
3774 /* IPV6 --> UDP ECPRI */
3775 [382] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3777 [383] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3779 [384] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3781 [385] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3783 [386] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3785 [387] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3787 [388] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3789 [389] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3791 [390] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3793 [391] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
3795 /* All others reserved */
3798 return ptype_tbl[ptype];
3802 iavf_set_default_ptype_table(struct rte_eth_dev *dev)
3804 struct iavf_adapter *ad =
3805 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3808 for (i = 0; i < IAVF_MAX_PKT_TYPE; i++)
3809 ad->ptype_tbl[i] = iavf_get_default_ptype(i);