From: Dengdui Huang <huangdeng...@huawei.com>

In the HNS3 driver, pkt_len in mbuf do not contain the CRC length.
This patch fix it.

Fixes: 8973d7c4ca12 ("net/hns3: support keeping CRC")
Cc: sta...@dpdk.org

Signed-off-by: Dengdui Huang <huangdeng...@huawei.com>
Acked-by: Huisong Li <lihuis...@huawei.com>
Acked-by: Jie Hai <haij...@huawei.com>
---
 drivers/net/hns3/hns3_rxtx.c          | 53 +++------------------------
 drivers/net/hns3/hns3_rxtx_vec_neon.h | 19 ----------
 drivers/net/hns3/hns3_rxtx_vec_sve.c  |  3 +-
 3 files changed, 7 insertions(+), 68 deletions(-)

diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c
index 5941b966e094..39ba9080ea15 100644
--- a/drivers/net/hns3/hns3_rxtx.c
+++ b/drivers/net/hns3/hns3_rxtx.c
@@ -1951,7 +1951,6 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t 
idx, uint16_t nb_desc,
        memset(&rxq->err_stats, 0, sizeof(struct hns3_rx_bd_errors_stats));
        memset(&rxq->dfx_stats, 0, sizeof(struct hns3_rx_dfx_stats));
 
-       /* CRC len set here is used for amending packet length */
        if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
                rxq->crc_len = RTE_ETHER_CRC_LEN;
        else
@@ -2383,23 +2382,6 @@ hns3_rxd_to_vlan_tci(struct hns3_rx_queue *rxq, struct 
rte_mbuf *mb,
        }
 }
 
-static inline void
-recalculate_data_len(struct rte_mbuf *first_seg, struct rte_mbuf *last_seg,
-                   struct rte_mbuf *rxm, struct hns3_rx_queue *rxq,
-                   uint16_t data_len)
-{
-       uint8_t crc_len = rxq->crc_len;
-
-       if (data_len <= crc_len) {
-               rte_pktmbuf_free_seg(rxm);
-               first_seg->nb_segs--;
-               last_seg->data_len = (uint16_t)(last_seg->data_len -
-                       (crc_len - data_len));
-               last_seg->next = NULL;
-       } else
-               rxm->data_len = (uint16_t)(data_len - crc_len);
-}
-
 static inline struct rte_mbuf *
 hns3_rx_alloc_buffer(struct hns3_rx_queue *rxq)
 {
@@ -2503,8 +2485,7 @@ hns3_recv_pkts_simple(void *rx_queue,
                rxdp->rx.bd_base_info = 0;
 
                rxm->data_off = RTE_PKTMBUF_HEADROOM;
-               rxm->pkt_len = (uint16_t)(rte_le_to_cpu_16(rxd.rx.pkt_len)) -
-                               rxq->crc_len;
+               rxm->pkt_len = (uint16_t)(rte_le_to_cpu_16(rxd.rx.pkt_len));
                rxm->data_len = rxm->pkt_len;
                rxm->port = rxq->port_id;
                rxm->hash.rss = rte_le_to_cpu_32(rxd.rx.rss_hash);
@@ -2531,8 +2512,8 @@ hns3_recv_pkts_simple(void *rx_queue,
 
                hns3_rxd_to_vlan_tci(rxq, rxm, l234_info, &rxd);
 
-               /* Increment bytes counter  */
-               rxq->basic_stats.bytes += rxm->pkt_len;
+               /* All byte-related statistics do not include Ethernet FCS */
+               rxq->basic_stats.bytes += rxm->pkt_len - rxq->crc_len;
 
                rx_pkts[nb_rx++] = rxm;
                continue;
@@ -2695,10 +2676,10 @@ hns3_recv_scattered_pkts(void *rx_queue,
 
                rxm->data_off = RTE_PKTMBUF_HEADROOM;
                rxm->data_len = rte_le_to_cpu_16(rxd.rx.size);
+               rxm->next = NULL;
 
                if (!(bd_base_info & BIT(HNS3_RXD_FE_B))) {
                        last_seg = rxm;
-                       rxm->next = NULL;
                        continue;
                }
 
@@ -2706,30 +2687,8 @@ hns3_recv_scattered_pkts(void *rx_queue,
                if (unlikely(bd_base_info & BIT(HNS3_RXD_TS_VLD_B)))
                        hns3_rx_ptp_timestamp_handle(rxq, first_seg, timestamp);
 
-               /*
-                * The last buffer of the received packet. packet len from
-                * buffer description may contains CRC len, packet len should
-                * subtract it, same as data len.
-                */
                first_seg->pkt_len = rte_le_to_cpu_16(rxd.rx.pkt_len);
 
-               /*
-                * This is the last buffer of the received packet. If the CRC
-                * is not stripped by the hardware:
-                *  - Subtract the CRC length from the total packet length.
-                *  - If the last buffer only contains the whole CRC or a part
-                *  of it, free the mbuf associated to the last buffer. If part
-                *  of the CRC is also contained in the previous mbuf, subtract
-                *  the length of that CRC part from the data length of the
-                *  previous mbuf.
-                */
-               rxm->next = NULL;
-               if (unlikely(rxq->crc_len > 0)) {
-                       first_seg->pkt_len -= rxq->crc_len;
-                       recalculate_data_len(first_seg, last_seg, rxm, rxq,
-                               rxm->data_len);
-               }
-
                first_seg->port = rxq->port_id;
                first_seg->hash.rss = rte_le_to_cpu_32(rxd.rx.rss_hash);
                first_seg->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
@@ -2761,8 +2720,8 @@ hns3_recv_scattered_pkts(void *rx_queue,
 
                hns3_rxd_to_vlan_tci(rxq, first_seg, l234_info, &rxd);
 
-               /* Increment bytes counter */
-               rxq->basic_stats.bytes += first_seg->pkt_len;
+               /* All byte-related statistics do not include Ethernet FCS */
+               rxq->basic_stats.bytes += first_seg->pkt_len - rxq->crc_len;
 
                rx_pkts[nb_rx++] = first_seg;
                first_seg = NULL;
diff --git a/drivers/net/hns3/hns3_rxtx_vec_neon.h 
b/drivers/net/hns3/hns3_rxtx_vec_neon.h
index 0dc6b9f0a22d..60ec501a2ab6 100644
--- a/drivers/net/hns3/hns3_rxtx_vec_neon.h
+++ b/drivers/net/hns3/hns3_rxtx_vec_neon.h
@@ -148,14 +148,6 @@ hns3_recv_burst_vec(struct hns3_rx_queue *__restrict rxq,
                8, 9, 10, 11,            /* rx.rss_hash to rte_mbuf.hash.rss */
        };
 
-       uint16x8_t crc_adjust = {
-               0, 0,         /* ignore pkt_type field */
-               rxq->crc_len, /* sub crc on pkt_len */
-               0,            /* ignore high-16bits of pkt_len */
-               rxq->crc_len, /* sub crc on data_len */
-               0, 0, 0,      /* ignore non-length fields */
-       };
-
        /* compile-time verifies the shuffle mask */
        RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=
                         offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
@@ -171,7 +163,6 @@ hns3_recv_burst_vec(struct hns3_rx_queue *__restrict rxq,
                uint8x16_t pkt_mb1, pkt_mb2, pkt_mb3, pkt_mb4;
                uint64x2_t mbp1, mbp2;
                uint16x4_t bd_vld = {0};
-               uint16x8_t tmp;
                uint64_t stat;
 
                /* calc how many bd valid */
@@ -225,16 +216,6 @@ hns3_recv_burst_vec(struct hns3_rx_queue *__restrict rxq,
                pkt_mb3 = vqtbl2q_u8(pkt_mbuf3, shuf_desc_fields_msk);
                pkt_mb4 = vqtbl2q_u8(pkt_mbuf4, shuf_desc_fields_msk);
 
-               /* 4 packets remove crc */
-               tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb1), crc_adjust);
-               pkt_mb1 = vreinterpretq_u8_u16(tmp);
-               tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb2), crc_adjust);
-               pkt_mb2 = vreinterpretq_u8_u16(tmp);
-               tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb3), crc_adjust);
-               pkt_mb3 = vreinterpretq_u8_u16(tmp);
-               tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb4), crc_adjust);
-               pkt_mb4 = vreinterpretq_u8_u16(tmp);
-
                /* save packet info to rx_pkts mbuf */
                vst1q_u8((void *)&sw_ring[pos + 0].mbuf->rx_descriptor_fields1,
                         pkt_mb1);
diff --git a/drivers/net/hns3/hns3_rxtx_vec_sve.c 
b/drivers/net/hns3/hns3_rxtx_vec_sve.c
index 8aa4448558cf..67c87f570e8a 100644
--- a/drivers/net/hns3/hns3_rxtx_vec_sve.c
+++ b/drivers/net/hns3/hns3_rxtx_vec_sve.c
@@ -36,8 +36,7 @@ hns3_desc_parse_field_sve(struct hns3_rx_queue *rxq,
                /* init rte_mbuf.rearm_data last 64-bit */
                rx_pkts[i]->ol_flags = RTE_MBUF_F_RX_RSS_HASH;
                rx_pkts[i]->hash.rss = rxdp[i].rx.rss_hash;
-               rx_pkts[i]->pkt_len = rte_le_to_cpu_16(rxdp[i].rx.pkt_len) -
-                                       rxq->crc_len;
+               rx_pkts[i]->pkt_len = rte_le_to_cpu_16(rxdp[i].rx.pkt_len);
                rx_pkts[i]->data_len = rx_pkts[i]->pkt_len;
 
                l234_info = rxdp[i].rx.l234_info;
-- 
2.33.0

Reply via email to