From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 23866A00E6 for ; Wed, 15 May 2019 20:09:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 06D875F2E; Wed, 15 May 2019 20:08:32 +0200 (CEST) Received: from rnd-relay.smtp.broadcom.com (rnd-relay.smtp.broadcom.com [192.19.229.170]) by dpdk.org (Postfix) with ESMTP id AE0CB5B2E for ; Wed, 15 May 2019 20:08:24 +0200 (CEST) Received: from nis-sj1-27.broadcom.com (nis-sj1-27.lvn.broadcom.net [10.75.144.136]) by rnd-relay.smtp.broadcom.com (Postfix) with ESMTP id 64EB330C0AB; Wed, 15 May 2019 11:08:22 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 rnd-relay.smtp.broadcom.com 64EB330C0AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1557943702; bh=Og7h7DMCpjW+uuGgPsLArnjmlC5jJjlgSDvN4wn1i2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ea3yKSP+jGI4AW/eYBf6HjSdS4XLFvZ5OWS0ca9eor120gkATxKW9A24pr+9IWcNb uFXNbu8NdyT3kMp6gCUa7jjry4Ceg1Tl7T8SXg8IyANLd15Eh6T/34cxe0V4b5xGWo MicQPdXxkD7UD9A06xZxQOgj+p6/FG96B4ERayXQ= Received: from C02VPB22HTD6.wifi.broadcom.net (c02vpb22htd6.wifi.broadcom.net [10.69.74.102]) by nis-sj1-27.broadcom.com (Postfix) with ESMTP id 41D52AC0798; Wed, 15 May 2019 11:08:23 -0700 (PDT) From: Ajit Khaparde To: dev@dpdk.org Cc: ferruh.yigit@intel.com, Somnath Kotur , Sriharsha Basavapatna Date: Wed, 15 May 2019 11:08:14 -0700 Message-Id: <20190515180817.71523-4-ajit.khaparde@broadcom.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190515180817.71523-1-ajit.khaparde@broadcom.com> References: <20190515180817.71523-1-ajit.khaparde@broadcom.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 3/6] net/bnxt: check for some error conditions in Tx path X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190515180814._hEzH70pYP6xm6JjkqXp7FrLsEIp-Loc4EBfNGwwKN0@z> The HW can have limits on the minimum packet size it can support, or the maximum number of segments it can support. Check for such possibilities. Also check if we are going to have a 0 length buffer. Fixes: 6eb3cc2294fd ("net/bnxt: add initial Tx code") Signed-off-by: Ajit Khaparde Reviewed-by: Somnath Kotur Signed-off-by: Sriharsha Basavapatna --- drivers/net/bnxt/bnxt_txr.c | 31 ++++++++++++++++++++++++++++++- drivers/net/bnxt/bnxt_txr.h | 2 ++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/net/bnxt/bnxt_txr.c b/drivers/net/bnxt/bnxt_txr.c index 3a0d73af2..9684fb177 100644 --- a/drivers/net/bnxt/bnxt_txr.c +++ b/drivers/net/bnxt/bnxt_txr.c @@ -143,6 +143,33 @@ static uint16_t bnxt_start_xmit(struct rte_mbuf *tx_pkt, tx_buf->mbuf = tx_pkt; tx_buf->nr_bds = long_bd + tx_pkt->nb_segs; + /* Check if number of Tx descriptors is above HW limit */ + if (unlikely(tx_buf->nr_bds > BNXT_MAX_TSO_SEGS)) { + PMD_DRV_LOG(ERR, + "Num descriptors %d exceeds HW limit\n", + tx_buf->nr_bds); + return -ENOSPC; + } + + /* If packet length is less than minimum packet size, pad it */ + if (unlikely(rte_pktmbuf_pkt_len(tx_pkt) < BNXT_MIN_PKT_SIZE)) { + uint8_t pad = BNXT_MIN_PKT_SIZE - rte_pktmbuf_pkt_len(tx_pkt); + char *seg = rte_pktmbuf_append(tx_pkt, pad); + + if (!seg) { + PMD_DRV_LOG(ERR, + "Failed to pad mbuf by %d bytes\n", + pad); + return -ENOMEM; + } + + /* Note: data_len, pkt len are updated in rte_pktmbuf_append */ + memset(seg, 0, pad); + } + + /* Check non zero data_len */ + RTE_VERIFY(tx_pkt->data_len); + if (unlikely(bnxt_tx_avail(txr) < tx_buf->nr_bds)) return -ENOMEM; @@ -203,6 +230,7 @@ static uint16_t bnxt_start_xmit(struct rte_mbuf *tx_pkt, */ txbd1->hdr_size = hdr_size >> 1; txbd1->mss = tx_pkt->tso_segsz; + RTE_VERIFY(txbd1->mss); } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_TCP_UDP_CKSUM) == PKT_TX_OIP_IIP_TCP_UDP_CKSUM) { @@ -285,8 +313,9 @@ static uint16_t bnxt_start_xmit(struct rte_mbuf *tx_pkt, } m_seg = tx_pkt->next; - /* i is set at the end of the if(long_bd) block */ while (m_seg) { + /* Check non zero data_len */ + RTE_VERIFY(m_seg->data_len); txr->tx_prod = RING_NEXT(txr->tx_ring_struct, txr->tx_prod); tx_buf = &txr->tx_buf_ring[txr->tx_prod]; diff --git a/drivers/net/bnxt/bnxt_txr.h b/drivers/net/bnxt/bnxt_txr.h index 7f3c7cdb0..f802d5080 100644 --- a/drivers/net/bnxt/bnxt_txr.h +++ b/drivers/net/bnxt/bnxt_txr.h @@ -10,6 +10,8 @@ #define MAX_TX_RINGS 16 #define BNXT_TX_PUSH_THRESH 92 +#define BNXT_MAX_TSO_SEGS 32 +#define BNXT_MIN_PKT_SIZE 52 #define B_TX_DB(db, prod) rte_write32((DB_KEY_TX | (prod)), db) -- 2.20.1 (Apple Git-117)