net/bnxt: return error in stats if init is not complete
[dpdk.git] / drivers / net / bnxt / bnxt_ring.c
index 0e8a6a2..aa9f3f4 100644 (file)
@@ -1,34 +1,6 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) Broadcom Limited.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Broadcom Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2014-2018 Broadcom
+ * All rights reserved.
  */
 
 #include <rte_bitmap.h>
 
 void bnxt_free_ring(struct bnxt_ring *ring)
 {
+       if (!ring)
+               return;
+
        if (ring->vmem_size && *ring->vmem) {
                memset((char *)*ring->vmem, 0, ring->vmem_size);
                *ring->vmem = NULL;
        }
-       rte_memzone_free((const struct rte_memzone *)ring->mem_zone);
+       ring->mem_zone = NULL;
 }
 
 /*
@@ -89,15 +64,18 @@ int bnxt_init_ring_grps(struct bnxt *bp)
  * rx bd ring - Only non-zero length if rx_ring_info is not NULL
  */
 int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx,
-                           struct bnxt_tx_ring_info *tx_ring_info,
-                           struct bnxt_rx_ring_info *rx_ring_info,
+                           struct bnxt_tx_queue *txq,
+                           struct bnxt_rx_queue *rxq,
                            struct bnxt_cp_ring_info *cp_ring_info,
                            const char *suffix)
 {
        struct bnxt_ring *cp_ring = cp_ring_info->cp_ring_struct;
+       struct bnxt_rx_ring_info *rx_ring_info = rxq ? rxq->rx_ring : NULL;
+       struct bnxt_tx_ring_info *tx_ring_info = txq ? txq->tx_ring : NULL;
        struct bnxt_ring *tx_ring;
        struct bnxt_ring *rx_ring;
        struct rte_pci_device *pdev = bp->pdev;
+       uint64_t rx_offloads = bp->eth_dev->data->dev_conf.rxmode.offloads;
        const struct rte_memzone *mz = NULL;
        char mz_name[RTE_MEMZONE_NAMESIZE];
        rte_iova_t mz_phys_addr;
@@ -155,7 +133,7 @@ int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx,
                                       sizeof(struct bnxt_tpa_info)) : 0;
 
        int total_alloc_len = tpa_info_start;
-       if (bp->eth_dev->data->dev_conf.rxmode.enable_lro)
+       if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
                total_alloc_len += tpa_info_len;
 
        snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
@@ -192,6 +170,7 @@ int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx,
        }
 
        if (tx_ring_info) {
+               txq->mz = mz;
                tx_ring = tx_ring_info->tx_ring_struct;
 
                tx_ring->bd = ((char *)mz->addr + tx_ring_start);
@@ -211,6 +190,7 @@ int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx,
        }
 
        if (rx_ring_info) {
+               rxq->mz = mz;
                rx_ring = rx_ring_info->rx_ring_struct;
 
                rx_ring->bd = ((char *)mz->addr + rx_ring_start);
@@ -253,7 +233,7 @@ int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx,
                                    ag_bitmap_start, ag_bitmap_len);
 
                /* TPA info */
-               if (bp->eth_dev->data->dev_conf.rxmode.enable_lro)
+               if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
                        rx_ring_info->tpa_info =
                                ((struct bnxt_tpa_info *)((char *)mz->addr +
                                                          tpa_info_start));
@@ -284,7 +264,6 @@ int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx,
  */
 int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 {
-       struct rte_pci_device *pci_dev = bp->pdev;
        unsigned int i;
        int rc = 0;
 
@@ -306,8 +285,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
                                        HWRM_NA_SIGNATURE);
                if (rc)
                        goto err_out;
-               cpr->cp_doorbell = (char *)pci_dev->mem_resource[2].addr +
-                   idx * 0x80;
+               cpr->cp_doorbell = (char *)bp->doorbell_base + idx * 0x80;
                bp->grp_info[i].cp_fw_ring_id = cp_ring->fw_ring_id;
                B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
 
@@ -319,8 +297,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
                if (rc)
                        goto err_out;
                rxr->rx_prod = 0;
-               rxr->rx_doorbell = (char *)pci_dev->mem_resource[2].addr +
-                   idx * 0x80;
+               rxr->rx_doorbell = (char *)bp->doorbell_base + idx * 0x80;
                bp->grp_info[i].rx_fw_ring_id = ring->fw_ring_id;
                B_RX_DB(rxr->rx_doorbell, rxr->rx_prod);
 
@@ -339,9 +316,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
                        goto err_out;
                PMD_DRV_LOG(DEBUG, "Alloc AGG Done!\n");
                rxr->ag_prod = 0;
-               rxr->ag_doorbell =
-                   (char *)pci_dev->mem_resource[2].addr +
-                   map_idx * 0x80;
+               rxr->ag_doorbell = (char *)bp->doorbell_base + map_idx * 0x80;
                bp->grp_info[i].ag_fw_ring_id = ring->fw_ring_id;
                B_RX_DB(rxr->ag_doorbell, rxr->ag_prod);
 
@@ -373,8 +348,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
                if (rc)
                        goto err_out;
 
-               cpr->cp_doorbell = (char *)pci_dev->mem_resource[2].addr +
-                   idx * 0x80;
+               cpr->cp_doorbell = (char *)bp->doorbell_base + idx * 0x80;
                B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
 
                /* Tx ring */
@@ -385,8 +359,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
                if (rc)
                        goto err_out;
 
-               txr->tx_doorbell = (char *)pci_dev->mem_resource[2].addr +
-                   idx * 0x80;
+               txr->tx_doorbell = (char *)bp->doorbell_base + idx * 0x80;
                txq->index = idx;
        }