net/bnxt: check initialization before accessing stats
authorAjit Khaparde <ajit.khaparde@broadcom.com>
Mon, 8 Jan 2018 20:24:31 +0000 (12:24 -0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 16 Jan 2018 17:47:49 +0000 (18:47 +0100)
Maintain state of PMD initialization and check it before checking stats.
In certain cases, we might end up accessing stats before the required
HWRM commands are processed by FW.

Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
drivers/net/bnxt/bnxt.h
drivers/net/bnxt/bnxt_ethdev.c
drivers/net/bnxt/bnxt_stats.c

index 345750b..7e3d7ae 100644 (file)
@@ -245,6 +245,7 @@ struct bnxt {
 #define BNXT_FLAG_UPDATE_HASH  (1 << 5)
 #define BNXT_FLAG_PTP_SUPPORTED        (1 << 6)
 #define BNXT_FLAG_MULTI_HOST    (1 << 7)
+#define BNXT_FLAG_INIT_DONE    (1 << 31)
 #define BNXT_PF(bp)            (!((bp)->flags & BNXT_FLAG_VF))
 #define BNXT_VF(bp)            ((bp)->flags & BNXT_FLAG_VF)
 #define BNXT_NPAR(bp)          ((bp)->port_partition_type)
index 475faac..c2d158d 100644 (file)
@@ -590,6 +590,7 @@ static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
        if (rc)
                goto error;
 
+       bp->flags |= BNXT_FLAG_INIT_DONE;
        return 0;
 
 error:
@@ -635,6 +636,7 @@ static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
        }
        bnxt_set_hwrm_link_config(bp, false);
        bnxt_hwrm_port_clr_stats(bp);
+       bp->flags &= ~BNXT_FLAG_INIT_DONE;
        bnxt_shutdown_nic(bp);
        bp->dev_stopped = 1;
 }
index 2606e93..470c643 100644 (file)
@@ -236,6 +236,10 @@ int bnxt_stats_get_op(struct rte_eth_dev *eth_dev,
        struct bnxt *bp = eth_dev->data->dev_private;
 
        memset(bnxt_stats, 0, sizeof(*bnxt_stats));
+       if (!(bp->flags & BNXT_FLAG_INIT_DONE)) {
+               RTE_LOG(ERR, PMD, "Device Initialization not complete!\n");
+               return 0;
+       }
 
        for (i = 0; i < bp->rx_cp_nr_rings; i++) {
                struct bnxt_rx_queue *rxq = bp->rx_queues[i];
@@ -267,6 +271,11 @@ void bnxt_stats_reset_op(struct rte_eth_dev *eth_dev)
 {
        struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
 
+       if (!(bp->flags & BNXT_FLAG_INIT_DONE)) {
+               RTE_LOG(ERR, PMD, "Device Initialization not complete!\n");
+               return;
+       }
+
        bnxt_clear_all_hwrm_stat_ctxs(bp);
        rte_atomic64_clear(&bp->rx_mbuf_alloc_fail);
 }