From de620754a10974f810b878f637b1ed9f77ebd7d8 Mon Sep 17 00:00:00 2001 From: "Wei Hu (Xavier)" Date: Fri, 22 Nov 2019 20:06:21 +0800 Subject: [PATCH] net/hns3: fix sending packets less than 60 bytes Ethernet minimum packet length is 64 bytes. If upper application sends packets with less than 60 bytes in length(no CRC), driver adds padding processing to avoid failure. Fixes: bba636698316 ("net/hns3: support Rx/Tx and related operations") Cc: stable@dpdk.org Signed-off-by: Huisong Li Signed-off-by: Wei Hu (Xavier) --- drivers/net/hns3/hns3_ethdev.h | 1 + drivers/net/hns3/hns3_rxtx.c | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h index 9710e45fb7..e9a3fe4107 100644 --- a/drivers/net/hns3/hns3_ethdev.h +++ b/drivers/net/hns3/hns3_ethdev.h @@ -43,6 +43,7 @@ #define HNS3_MAX_MTU (HNS3_MAX_FRAME_LEN - HNS3_ETH_OVERHEAD) #define HNS3_DEFAULT_MTU 1500UL #define HNS3_DEFAULT_FRAME_LEN (HNS3_DEFAULT_MTU + HNS3_ETH_OVERHEAD) +#define HNS3_MIN_PKT_SIZE 60 #define HNS3_4_TCS 4 #define HNS3_8_TCS 8 diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c index 1de238b4c1..34cb7faf9e 100644 --- a/drivers/net/hns3/hns3_rxtx.c +++ b/drivers/net/hns3/hns3_rxtx.c @@ -1598,13 +1598,29 @@ hns3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) } /* - * If the length of the packet is too long or zero, the packet - * will be ignored. + * If packet length is greater than HNS3_MAX_FRAME_LEN + * driver support, the packet will be ignored. */ - if (unlikely(tx_pkt->pkt_len > HNS3_MAX_FRAME_LEN || - tx_pkt->pkt_len == 0)) + if (unlikely(rte_pktmbuf_pkt_len(tx_pkt) > HNS3_MAX_FRAME_LEN)) break; + /* + * If packet length is less than minimum packet size, driver + * need to pad it. + */ + if (unlikely(rte_pktmbuf_pkt_len(tx_pkt) < HNS3_MIN_PKT_SIZE)) { + uint16_t add_len; + char *appended; + + add_len = HNS3_MIN_PKT_SIZE - + rte_pktmbuf_pkt_len(tx_pkt); + appended = rte_pktmbuf_append(tx_pkt, add_len); + if (appended == NULL) + break; + + memset(appended, 0, add_len); + } + m_seg = tx_pkt; if (unlikely(nb_buf > HNS3_MAX_TX_BD_PER_PKT)) { if (hns3_reassemble_tx_pkts(txq, tx_pkt, &new_pkt)) -- 2.20.1