net/hns3: fix checking enough Tx BDs
[dpdk.git] / drivers / net / hns3 / hns3_rxtx.c
index fdac55a..8166447 100644 (file)
@@ -661,7 +661,6 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
        rxq->l4_csum_erros = 0;
        rxq->ol3_csum_erros = 0;
        rxq->ol4_csum_erros = 0;
-       rxq->errors = 0;
 
        rte_spinlock_lock(&hw->lock);
        dev->data->rx_queues[idx] = rxq;
@@ -817,14 +816,12 @@ hns3_handle_bdinfo(struct hns3_rx_queue *rxq, struct rte_mbuf *rxm,
 
        if (unlikely(l234_info & BIT(HNS3_RXD_L2E_B))) {
                rxq->l2_errors++;
-               rxq->errors++;
                return -EINVAL;
        }
 
        if (unlikely(rxm->pkt_len == 0 ||
                (l234_info & BIT(HNS3_RXD_TRUNCAT_B)))) {
                rxq->pkt_len_errors++;
-               rxq->errors++;
                return -EINVAL;
        }
 
@@ -980,6 +977,7 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                first_seg->pkt_len = pkt_len;
                first_seg->port = rxq->port_id;
                first_seg->hash.rss = rte_le_to_cpu_32(rxdp->rx.rss_hash);
+               first_seg->ol_flags |= PKT_RX_RSS_HASH;
                if (unlikely(hns3_get_bit(bd_base_info, HNS3_RXD_LUM_B))) {
                        first_seg->hash.fdir.hi =
                                rte_le_to_cpu_32(rxdp->rx.fd_id);
@@ -1098,7 +1096,6 @@ hns3_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
        txq->next_to_clean = 0;
        txq->tx_bd_ready   = txq->nb_tx_desc;
        txq->port_id = dev->data->port_id;
-       txq->pkt_len_errors = 0;
        txq->configured = true;
        txq->io_base = (void *)((char *)hw->io_base + HNS3_TQP_REG_OFFSET +
                                idx * HNS3_TQP_REG_SIZE);
@@ -1601,13 +1598,27 @@ 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)) {
-                       txq->pkt_len_errors++;
-                       continue;
+               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;
@@ -1638,6 +1649,7 @@ hns3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
                } while (m_seg != NULL);
 
                nb_hold += i;
+               txq->next_to_use = tx_next_use;
        }
 
 end_of_tx:
@@ -1645,7 +1657,6 @@ end_of_tx:
        if (likely(nb_tx)) {
                hns3_queue_xmit(txq, nb_hold);
                txq->next_to_clean = tx_next_clean;
-               txq->next_to_use   = tx_next_use;
                txq->tx_bd_ready   = tx_bd_ready - nb_hold;
        }