From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 69947A0547 for ; Mon, 19 Jul 2021 19:50:15 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6B8704068B; Mon, 19 Jul 2021 19:50:14 +0200 (CEST) Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by mails.dpdk.org (Postfix) with ESMTP id D275F4068B for ; Mon, 19 Jul 2021 19:50:12 +0200 (CEST) Received: by mail-pg1-f178.google.com with SMTP id t9so19773013pgn.4 for ; Mon, 19 Jul 2021 10:50:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:mime-version; bh=zy7h3zrF9ss0z89x51mWKKW/HENXFphpnR8xr/hOWJE=; b=V7g43JD6ZEN9ERRFmXEnXErIHBHf37V5vgzj7n5mJVrTp/VjiM6HHRCTKoyh1R63en GQCkYrNKnNIz0kw7uDaSV34SdWN5oHVVqs0/D6PFJyY1wcL3WKutKaqQiLHMqcQSzRqI psnAxV6OFeUb5kzlQPhhTSK4zb3Zx2FKyWIp0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version; bh=zy7h3zrF9ss0z89x51mWKKW/HENXFphpnR8xr/hOWJE=; b=hu45SRZlsxGOjGI+Tw77gqkry1+H0ozAsAcbRyllUtqgu0z5uImhOMxF6KO9/SoDR4 nr0+9bGU4J79NyY0Q+uPpHb2g+RdYl35fyeEZDtaIqRd8hzC4APU/m0UIV0xhQRZp1Br YvIlA1DrrG9rFx60VuFKPri6SdKQ2rtkpSphXL6H43njxQBFJ5oP7Gdi9uziM3+WhqyZ j8FL6as8bfgM70daIXIbGncIOkay5HwXMJSC1kLixJZVK5hXwrOpzf1KVCwT9rplqcPv UNDAsBy5s1ky1I5uzll47DHjKXJ47J4lelUKNZCO0kFfDmVmuwGOZj1ZNyDVdZ0IpYVG 9K7g== X-Gm-Message-State: AOAM532jLtZqKXtQeO32vLhH1aZVodQ+E3Mjuer2hVj0ofyRhJV+pODh XSc0UgASgTAuaDxozpoMD+oaiwxPNbVSEIo0lbxuJCEai6nBUZIkQw4SvBSxtUGNufavhYh+Xpy jFroKeLIK3gubBWMza34gV+k/kIL78wisj0jYBaPr1uQCXSXLrbb0b6kv1SFh6eeyWw0= X-Google-Smtp-Source: ABdhPJwoaVtA3Xd7AO9BXDVJx8G5TEGsPTWllATqqQcsu4/IQYXiWTk7T29MvMUtVmlS7IMBPia8wQ== X-Received: by 2002:a63:405:: with SMTP id 5mr26750277pge.132.1626717011528; Mon, 19 Jul 2021 10:50:11 -0700 (PDT) Received: from C02VPB22HTD6.wifi.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id x7sm21537426pfc.96.2021.07.19.10.50.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jul 2021 10:50:10 -0700 (PDT) From: Ajit Khaparde To: stable@dpdk.org Cc: Somnath Kotur Date: Mon, 19 Jul 2021 10:50:06 -0700 Message-Id: <20210719175006.43319-1-ajit.khaparde@broadcom.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="000000000000a6fb9305c77d9153" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [dpdk-stable] [PATCH 20.11] net/bnxt: fix ring allocation and free X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" --000000000000a6fb9305c77d9153 Content-Transfer-Encoding: 8bit [ upstream commit b3fa83945a367125f6e1b66cd330b8b683d0b4a3 ] Fix handling of ring alloc and free logic to fix check for invalid ring and context IDs. This also avoids code duplication. Fixes: 6133f207970c ("net/bnxt: add Rx queue create/destroy") Fixes: 51c87ebafc7d ("net/bnxt: add Tx queue create/destroy") Cc: stable@dpdk.org Signed-off-by: Ajit Khaparde Reviewed-by: Somnath Kotur --- drivers/net/bnxt/bnxt_hwrm.c | 122 +++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 55 deletions(-) diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c index ef402815cc..4d24c9c561 100644 --- a/drivers/net/bnxt/bnxt_hwrm.c +++ b/drivers/net/bnxt/bnxt_hwrm.c @@ -1676,12 +1676,16 @@ int bnxt_hwrm_ring_free(struct bnxt *bp, struct hwrm_ring_free_input req = {.req_type = 0 }; struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr; + if (ring->fw_ring_id == INVALID_HW_RING_ID) + return -EINVAL; + HWRM_PREP(&req, HWRM_RING_FREE, BNXT_USE_CHIMP_MB); req.ring_type = ring_type; req.ring_id = rte_cpu_to_le_16(ring->fw_ring_id); rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB); + ring->fw_ring_id = INVALID_HW_RING_ID; if (rc || resp->error_code) { if (rc == 0 && resp->error_code) @@ -1767,7 +1771,7 @@ int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr) struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 }; struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr; - if (cpr->hw_stats_ctx_id == (uint32_t)HWRM_NA_SIGNATURE) + if (cpr->hw_stats_ctx_id == HWRM_NA_SIGNATURE) return rc; HWRM_PREP(&req, HWRM_STAT_CTX_CLR_STATS, BNXT_USE_CHIMP_MB); @@ -1788,6 +1792,9 @@ static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *c struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 }; struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr; + if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) + return 0; + HWRM_PREP(&req, HWRM_STAT_CTX_ALLOC, BNXT_USE_CHIMP_MB); req.update_period_ms = rte_cpu_to_le_32(0); @@ -1811,6 +1818,9 @@ static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cp struct hwrm_stat_ctx_free_input req = {.req_type = 0 }; struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr; + if (cpr->hw_stats_ctx_id == HWRM_NA_SIGNATURE) + return 0; + HWRM_PREP(&req, HWRM_STAT_CTX_FREE, BNXT_USE_CHIMP_MB); req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id); @@ -1820,6 +1830,8 @@ static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cp HWRM_CHECK_RESULT(); HWRM_UNLOCK(); + cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE; + return rc; } @@ -2460,48 +2472,54 @@ bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp) unsigned int i; struct bnxt_cp_ring_info *cpr; - for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) { + for (i = 0; i < bp->rx_cp_nr_rings; i++) { - if (i >= bp->rx_cp_nr_rings) { - cpr = bp->tx_queues[i - bp->rx_cp_nr_rings]->cp_ring; - } else { - cpr = bp->rx_queues[i]->cp_ring; - if (BNXT_HAS_RING_GRPS(bp)) - bp->grp_info[i].fw_stats_ctx = -1; - } - if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE) { - rc = bnxt_hwrm_stat_ctx_free(bp, cpr); - cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE; - if (rc) - return rc; - } + cpr = bp->rx_queues[i]->cp_ring; + if (BNXT_HAS_RING_GRPS(bp)) + bp->grp_info[i].fw_stats_ctx = -1; + rc = bnxt_hwrm_stat_ctx_free(bp, cpr); + if (rc) + return rc; + } + + for (i = 0; i < bp->tx_cp_nr_rings; i++) { + cpr = bp->tx_queues[i]->cp_ring; + rc = bnxt_hwrm_stat_ctx_free(bp, cpr); + if (rc) + return rc; } + return 0; } int bnxt_alloc_all_hwrm_stat_ctxs(struct bnxt *bp) { + struct bnxt_cp_ring_info *cpr; unsigned int i; int rc = 0; - for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) { - struct bnxt_tx_queue *txq; - struct bnxt_rx_queue *rxq; - struct bnxt_cp_ring_info *cpr; + for (i = 0; i < bp->rx_cp_nr_rings; i++) { + struct bnxt_rx_queue *rxq = bp->rx_queues[i]; - if (i >= bp->rx_cp_nr_rings) { - txq = bp->tx_queues[i - bp->rx_cp_nr_rings]; - cpr = txq->cp_ring; - } else { - rxq = bp->rx_queues[i]; - cpr = rxq->cp_ring; + cpr = rxq->cp_ring; + if (cpr->hw_stats_ctx_id == HWRM_NA_SIGNATURE) { + rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr); + if (rc) + return rc; } + } - rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr); + for (i = 0; i < bp->tx_cp_nr_rings; i++) { + struct bnxt_tx_queue *txq = bp->tx_queues[i]; - if (rc) - return rc; + cpr = txq->cp_ring; + if (cpr->hw_stats_ctx_id == HWRM_NA_SIGNATURE) { + rc = bnxt_hwrm_stat_ctx_alloc(bp, cpr); + if (rc) + return rc; + } } + return rc; } @@ -2534,10 +2552,9 @@ void bnxt_free_nq_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr) bnxt_hwrm_ring_free(bp, cp_ring, HWRM_RING_FREE_INPUT_RING_TYPE_NQ); cp_ring->fw_ring_id = INVALID_HW_RING_ID; - memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size * - sizeof(*cpr->cp_desc_ring)); + memset(cpr->cp_desc_ring, 0, + cpr->cp_ring_struct->ring_size * sizeof(*cpr->cp_desc_ring)); cpr->cp_raw_cons = 0; - cpr->valid = 0; } void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr) @@ -2545,12 +2562,11 @@ void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr) struct bnxt_ring *cp_ring = cpr->cp_ring_struct; bnxt_hwrm_ring_free(bp, cp_ring, - HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL); + HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL); cp_ring->fw_ring_id = INVALID_HW_RING_ID; - memset(cpr->cp_desc_ring, 0, cpr->cp_ring_struct->ring_size * - sizeof(*cpr->cp_desc_ring)); + memset(cpr->cp_desc_ring, 0, + cpr->cp_ring_struct->ring_size * sizeof(*cpr->cp_desc_ring)); cpr->cp_raw_cons = 0; - cpr->valid = 0; } void bnxt_free_hwrm_rx_ring(struct bnxt *bp, int queue_index) @@ -2560,26 +2576,22 @@ void bnxt_free_hwrm_rx_ring(struct bnxt *bp, int queue_index) struct bnxt_ring *ring = rxr->rx_ring_struct; struct bnxt_cp_ring_info *cpr = rxq->cp_ring; - if (ring->fw_ring_id != INVALID_HW_RING_ID) { - bnxt_hwrm_ring_free(bp, ring, - HWRM_RING_FREE_INPUT_RING_TYPE_RX); - ring->fw_ring_id = INVALID_HW_RING_ID; - if (BNXT_HAS_RING_GRPS(bp)) - bp->grp_info[queue_index].rx_fw_ring_id = - INVALID_HW_RING_ID; - } + bnxt_hwrm_ring_free(bp, ring, + HWRM_RING_FREE_INPUT_RING_TYPE_RX); + if (BNXT_HAS_RING_GRPS(bp)) + bp->grp_info[queue_index].rx_fw_ring_id = + INVALID_HW_RING_ID; + ring = rxr->ag_ring_struct; - if (ring->fw_ring_id != INVALID_HW_RING_ID) { - bnxt_hwrm_ring_free(bp, ring, - BNXT_CHIP_THOR(bp) ? - HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG : - HWRM_RING_FREE_INPUT_RING_TYPE_RX); - if (BNXT_HAS_RING_GRPS(bp)) - bp->grp_info[queue_index].ag_fw_ring_id = - INVALID_HW_RING_ID; - } - if (cpr->cp_ring_struct->fw_ring_id != INVALID_HW_RING_ID) - bnxt_free_cp_ring(bp, cpr); + bnxt_hwrm_ring_free(bp, ring, + BNXT_CHIP_THOR(bp) ? + HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG : + HWRM_RING_FREE_INPUT_RING_TYPE_RX); + if (BNXT_HAS_RING_GRPS(bp)) + bp->grp_info[queue_index].ag_fw_ring_id = + INVALID_HW_RING_ID; + + bnxt_free_cp_ring(bp, cpr); if (BNXT_HAS_RING_GRPS(bp)) bp->grp_info[queue_index].cp_fw_ring_id = INVALID_HW_RING_ID; @@ -5938,4 +5950,4 @@ int bnxt_hwrm_poll_ver_get(struct bnxt *bp) HWRM_UNLOCK(); return rc; -} \ No newline at end of file +} -- 2.21.1 (Apple Git-122.3) --000000000000a6fb9305c77d9153--