From patchwork Sun Jun 2 17:42:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Richardson X-Patchwork-Id: 54124 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4D3EA1B9A7; Sun, 2 Jun 2019 19:43:23 +0200 (CEST) Received: from mail-yw1-f52.google.com (mail-yw1-f52.google.com [209.85.161.52]) by dpdk.org (Postfix) with ESMTP id 4512A1B950 for ; Sun, 2 Jun 2019 19:43:11 +0200 (CEST) Received: by mail-yw1-f52.google.com with SMTP id k70so6464084ywe.7 for ; Sun, 02 Jun 2019 10:43:11 -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:in-reply-to:references; bh=AUTIa+EuRQI2aqLyu+0+jHF6stzfA53EPNharv6eaC8=; b=K8PaPJJph5NeYS/Wx68ZKxn2mWEqkz5kZ2sCgVy+reLy7OaA2F34pXsVCHiWYyO5Ue I+q2eXJUZkvgtfxzGBg+PgO9IBDr6SbMW0FRMVbWdinAoDelnupoQUpqUd5Z9E7aPUoF LAtI3pEp9e7EV/74JaGHHYH8EZ+2ODFmkMkVE= 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:in-reply-to :references; bh=AUTIa+EuRQI2aqLyu+0+jHF6stzfA53EPNharv6eaC8=; b=SMEVmfX35gwzwXdD3T59qIx/tBTlPXSI0eXxBV0VIHzY4q7+fTBJT7shiau5fDzHxp Cucuz6x6bZx0askVBIzinjX253u6Cugf5YR27T7PGwDsA/wQFZRUh1xHVNgFety4VUxF EqNHZ4yLb/XrCMmobgkGo8niF2ItUMC+wvruhTrPomRU9UUzXxeFTp3HZcP+LSI+MPIK rVAC6TIz/yxEg69v09LGQOieJkDFxT4sh4mo1JstPsP46nJFx+UC1V5kAP1mnFZ1V/U1 YUo3sBlKLEkaQv355lE9ZI1SoL8FOtLzW3ZpnwtlJDHIBCiYaqiSkWe/OLfhT4rOY9xm I5pQ== X-Gm-Message-State: APjAAAWrGof/uMdW255jYiuCCnLdPnxigN6yIOHsgzooHF73jiT43SmC v7wnMDnnBV0QzFFzx0zJWLhJ5/REoOpqgSjczArny4wdc6ojiwIGcLvTYsv2zEJ5uwwnZP+pR7F nlHf5ppa3+mR+O+EEJtPi6HY/CUdP7sacLHUVWQegX9RMlT7eKKgtUxGTcGA4hbyJ X-Google-Smtp-Source: APXvYqymm9yEH8ZQ2J9pZZQoH9yqWr6SDgxWtkbh6/7I0W6+TE0hKClHXaRUBM/4r5+vb1Y70BkNSQ== X-Received: by 2002:a81:3d07:: with SMTP id k7mr11610271ywa.376.1559497390452; Sun, 02 Jun 2019 10:43:10 -0700 (PDT) Received: from lrichardson-VirtualBox.attlocal.net (69-218-223-106.lightspeed.rlghnc.sbcglobal.net. [69.218.223.106]) by smtp.gmail.com with ESMTPSA id n78sm1000819ywd.2.2019.06.02.10.43.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Jun 2019 10:43:10 -0700 (PDT) From: Lance Richardson To: dev@dpdk.org Cc: ajit.khaparde@broadcom.com, ferruh.yigit@intel.com, Lance Richardson Date: Sun, 2 Jun 2019 13:42:43 -0400 Message-Id: <20190602174247.32368-9-lance.richardson@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190602174247.32368-1-lance.richardson@broadcom.com> References: <20190602174247.32368-1-lance.richardson@broadcom.com> Subject: [dpdk-dev] [PATCH 08/11] net/bnxt: refactor ring allocation code 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" Reduce code duplication and prepare for supporting hardware with different ring allocation requirements by refactoring ring allocation code. Signed-off-by: Lance Richardson Reviewed-by: Ajit Kumar Khaparde --- drivers/net/bnxt/bnxt_ring.c | 167 ++++++++++++++++++----------------- 1 file changed, 85 insertions(+), 82 deletions(-) diff --git a/drivers/net/bnxt/bnxt_ring.c b/drivers/net/bnxt/bnxt_ring.c index 15d418977..8473e4abe 100644 --- a/drivers/net/bnxt/bnxt_ring.c +++ b/drivers/net/bnxt/bnxt_ring.c @@ -295,29 +295,94 @@ static void bnxt_set_db(struct bnxt *bp, } } -int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index) +static int bnxt_alloc_cmpl_ring(struct bnxt *bp, int queue_index, + struct bnxt_cp_ring_info *cpr) +{ + struct bnxt_ring *cp_ring = cpr->cp_ring_struct; + uint8_t ring_type; + int rc = 0; + + ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL; + + rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, queue_index, + HWRM_NA_SIGNATURE, HWRM_NA_SIGNATURE); + if (rc) + return rc; + + cpr->cp_cons = 0; + bnxt_set_db(bp, &cpr->cp_db, ring_type, queue_index); + bnxt_db_cq(cpr); + + return 0; +} + +static int bnxt_alloc_rx_ring(struct bnxt *bp, int queue_index) { struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index]; struct bnxt_cp_ring_info *cpr = rxq->cp_ring; struct bnxt_ring *cp_ring = cpr->cp_ring_struct; struct bnxt_rx_ring_info *rxr = rxq->rx_ring; struct bnxt_ring *ring = rxr->rx_ring_struct; + uint8_t ring_type; + int rc = 0; + + ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX; + + rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, + queue_index, cpr->hw_stats_ctx_id, + cp_ring->fw_ring_id); + if (rc) + return rc; + + rxr->rx_prod = 0; + bp->grp_info[queue_index].rx_fw_ring_id = ring->fw_ring_id; + bnxt_set_db(bp, &rxr->rx_db, ring_type, queue_index); + bnxt_db_write(&rxr->rx_db, rxr->rx_prod); + + return 0; +} + +static int bnxt_alloc_rx_agg_ring(struct bnxt *bp, int queue_index) +{ unsigned int map_idx = queue_index + bp->rx_cp_nr_rings; + struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index]; + struct bnxt_cp_ring_info *cpr = rxq->cp_ring; + struct bnxt_ring *cp_ring = cpr->cp_ring_struct; + struct bnxt_rx_ring_info *rxr = rxq->rx_ring; + struct bnxt_ring *ring = rxr->ag_ring_struct; + uint32_t hw_stats_ctx_id = HWRM_NA_SIGNATURE; uint8_t ring_type; int rc = 0; - bp->grp_info[queue_index].fw_stats_ctx = cpr->hw_stats_ctx_id; + ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX; + + rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, map_idx, + hw_stats_ctx_id, cp_ring->fw_ring_id); - /* Rx cmpl */ - ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL; - rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, queue_index, - HWRM_NA_SIGNATURE, HWRM_NA_SIGNATURE); if (rc) + return rc; + + rxr->ag_prod = 0; + bp->grp_info[queue_index].ag_fw_ring_id = ring->fw_ring_id; + bnxt_set_db(bp, &rxr->ag_db, ring_type, map_idx); + bnxt_db_write(&rxr->ag_db, rxr->ag_prod); + + return 0; +} + +int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index) +{ + struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index]; + struct bnxt_cp_ring_info *cpr = rxq->cp_ring; + struct bnxt_ring *cp_ring = cpr->cp_ring_struct; + struct bnxt_rx_ring_info *rxr = rxq->rx_ring; + int rc = 0; + + if (bnxt_alloc_cmpl_ring(bp, queue_index, cpr)) goto err_out; + bp->grp_info[queue_index].fw_stats_ctx = cpr->hw_stats_ctx_id; bp->grp_info[queue_index].cp_fw_ring_id = cp_ring->fw_ring_id; - bnxt_set_db(bp, &cpr->cp_db, ring_type, queue_index); - bnxt_db_cq(cpr); if (!queue_index) { /* @@ -330,34 +395,12 @@ int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index) if (rc) goto err_out; } - /* Rx ring */ - ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX; - rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, queue_index, - cpr->hw_stats_ctx_id, cp_ring->fw_ring_id); - if (rc) - goto err_out; - - rxr->rx_prod = 0; - bp->grp_info[queue_index].rx_fw_ring_id = ring->fw_ring_id; - bnxt_set_db(bp, &rxr->rx_db, ring_type, queue_index); - bnxt_db_write(&rxr->rx_db, rxr->rx_prod); - - /* Agg ring */ - ring = rxr->ag_ring_struct; - if (!ring) - PMD_DRV_LOG(ERR, "Alloc AGG Ring is NULL!\n"); - ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX; - rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, map_idx, - HWRM_NA_SIGNATURE, cp_ring->fw_ring_id); - if (rc) + if (bnxt_alloc_rx_ring(bp, queue_index)) goto err_out; - PMD_DRV_LOG(DEBUG, "Alloc AGG Done!\n"); - rxr->ag_prod = 0; - bp->grp_info[queue_index].ag_fw_ring_id = ring->fw_ring_id; - bnxt_set_db(bp, &rxr->ag_db, ring_type, map_idx); - bnxt_db_write(&rxr->ag_db, rxr->ag_prod); + if (bnxt_alloc_rx_agg_ring(bp, queue_index)) + goto err_out; rxq->rx_buf_use_size = BNXT_MAX_MTU + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + (2 * VLAN_TAG_SIZE); @@ -403,21 +446,14 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp) struct bnxt_cp_ring_info *cpr = rxq->cp_ring; struct bnxt_ring *cp_ring = cpr->cp_ring_struct; struct bnxt_rx_ring_info *rxr = rxq->rx_ring; - struct bnxt_ring *ring = rxr->rx_ring_struct; - unsigned int map_idx = i + bp->rx_cp_nr_rings; bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id; - /* Rx cmpl */ - ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL; - rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, i, - HWRM_NA_SIGNATURE, - HWRM_NA_SIGNATURE); - if (rc) + if (bnxt_alloc_cmpl_ring(bp, i, cpr)) goto err_out; + + bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id; bp->grp_info[i].cp_fw_ring_id = cp_ring->fw_ring_id; - bnxt_set_db(bp, &cpr->cp_db, ring_type, i); - bnxt_db_cq(cpr); bnxt_hwrm_set_ring_coal(bp, &coal, cp_ring->fw_ring_id); @@ -434,38 +470,12 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp) goto err_out; } - /* Rx ring */ - ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX; - rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, i, - cpr->hw_stats_ctx_id, - cp_ring->fw_ring_id); - if (rc) - goto err_out; - rxr->rx_prod = 0; - bp->grp_info[i].rx_fw_ring_id = ring->fw_ring_id; - bnxt_set_db(bp, &rxr->rx_db, ring_type, i); - bnxt_db_write(&rxr->rx_db, rxr->rx_prod); - - /* Agg ring */ - ring = rxr->ag_ring_struct; - - if (ring == NULL) { - PMD_DRV_LOG(ERR, "Alloc AGG Ring is NULL!\n"); + if (bnxt_alloc_rx_ring(bp, i)) goto err_out; - } - ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX; - rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, map_idx, - HWRM_NA_SIGNATURE, - cp_ring->fw_ring_id); - if (rc) + if (bnxt_alloc_rx_agg_ring(bp, i)) goto err_out; - rxr->ag_prod = 0; - bp->grp_info[i].ag_fw_ring_id = ring->fw_ring_id; - bnxt_set_db(bp, &rxr->ag_db, ring_type, map_idx); - bnxt_db_write(&rxr->ag_db, rxr->ag_prod); - rxq->rx_buf_use_size = BNXT_MAX_MTU + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + (2 * VLAN_TAG_SIZE); if (bnxt_init_one_rx_ring(rxq)) { @@ -486,21 +496,14 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp) struct bnxt_ring *ring = txr->tx_ring_struct; unsigned int idx = i + bp->rx_cp_nr_rings; - /* Tx cmpl */ - ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL; - rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, idx, - HWRM_NA_SIGNATURE, - HWRM_NA_SIGNATURE); - if (rc) + if (bnxt_alloc_cmpl_ring(bp, idx, cpr)) goto err_out; - bnxt_set_db(bp, &cpr->cp_db, ring_type, idx); - bnxt_db_cq(cpr); - /* Tx ring */ ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_TX; - rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, idx, - cpr->hw_stats_ctx_id, + rc = bnxt_hwrm_ring_alloc(bp, ring, + ring_type, + idx, cpr->hw_stats_ctx_id, cp_ring->fw_ring_id); if (rc) goto err_out;