net/hns3: fix sending packets less than 60 bytes
authorWei Hu (Xavier) <xavier.huwei@huawei.com>
Fri, 22 Nov 2019 12:06:21 +0000 (20:06 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 26 Nov 2019 17:05:15 +0000 (18:05 +0100)
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 <lihuisong@huawei.com>
Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
drivers/net/hns3/hns3_ethdev.h
drivers/net/hns3/hns3_rxtx.c

index 9710e45..e9a3fe4 100644 (file)
@@ -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
index 1de238b..34cb7fa 100644 (file)
@@ -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))