net/bnxt: fix stats errors handling
authorKalesh AP <kalesh-anakkur.purayil@broadcom.com>
Thu, 10 Oct 2019 01:41:42 +0000 (18:41 -0700)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 23 Oct 2019 14:43:08 +0000 (16:43 +0200)
This patch fixes few checks and few return values while getting
and clearing device statistics.

1. Fixed to return standard error code.
2. Clubbed few error checks
3. Removed an unnecessary return check

Fixes: bfb9c2260be2 ("net/bnxt: support xstats get/reset")
Fixes: 88920136688c ("net/bnxt: support xstats get by id")
Cc: stable@dpdk.org
Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
drivers/net/bnxt/bnxt_stats.c

index 21012e1..f486a56 100644 (file)
@@ -360,7 +360,7 @@ int bnxt_stats_get_op(struct rte_eth_dev *eth_dev,
        memset(bnxt_stats, 0, sizeof(*bnxt_stats));
        if (!(bp->flags & BNXT_FLAG_INIT_DONE)) {
                PMD_DRV_LOG(ERR, "Device Initialization not complete!\n");
-               return -1;
+               return -EIO;
        }
 
        num_q_stats = RTE_MIN(bp->rx_cp_nr_rings,
@@ -390,9 +390,8 @@ int bnxt_stats_get_op(struct rte_eth_dev *eth_dev,
                if (unlikely(rc))
                        return rc;
        }
+
        rc = bnxt_hwrm_func_qstats(bp, 0xffff, bnxt_stats);
-       if (unlikely(rc))
-               return rc;
        return rc;
 }
 
@@ -573,30 +572,17 @@ int bnxt_dev_xstats_reset_op(struct rte_eth_dev *eth_dev)
        if (ret)
                return ret;
 
-       if (bp->flags & BNXT_FLAG_PORT_STATS && BNXT_SINGLE_PF(bp)) {
-               ret = bnxt_hwrm_port_clr_stats(bp);
-               if (ret != 0) {
-                       PMD_DRV_LOG(ERR, "Operation failed: %s\n",
-                                   strerror(-ret));
-                       return ret;
-               }
-       }
-
-       ret = 0;
-
-       if (BNXT_VF(bp)) {
-               PMD_DRV_LOG(ERR, "Operation not supported on a VF device\n");
-               ret = -ENOTSUP;
-       }
-       if (!BNXT_SINGLE_PF(bp)) {
-               PMD_DRV_LOG(ERR, "Operation not supported on a MF device\n");
-               ret = -ENOTSUP;
-       }
-       if (!(bp->flags & BNXT_FLAG_PORT_STATS)) {
+       if (BNXT_VF(bp) || !BNXT_SINGLE_PF(bp) ||
+           !(bp->flags & BNXT_FLAG_PORT_STATS)) {
                PMD_DRV_LOG(ERR, "Operation not supported\n");
                ret = -ENOTSUP;
        }
 
+       ret = bnxt_hwrm_port_clr_stats(bp);
+       if (ret != 0)
+               PMD_DRV_LOG(ERR, "Failed to reset xstats: %s\n",
+                           strerror(-ret));
+
        return ret;
 }
 
@@ -625,7 +611,7 @@ int bnxt_dev_xstats_get_by_id_op(struct rte_eth_dev *dev, const uint64_t *ids,
        for (i = 0; i < limit; i++) {
                if (ids[i] >= stat_cnt) {
                        PMD_DRV_LOG(ERR, "id value isn't valid");
-                       return -1;
+                       return -EINVAL;
                }
                values[i] = values_copy[ids[i]];
        }
@@ -659,7 +645,7 @@ int bnxt_dev_xstats_get_names_by_id_op(struct rte_eth_dev *dev,
        for (i = 0; i < limit; i++) {
                if (ids[i] >= stat_cnt) {
                        PMD_DRV_LOG(ERR, "id value isn't valid");
-                       return -1;
+                       return -EINVAL;
                }
                strcpy(xstats_names[i].name,
                                xstats_names_copy[ids[i]].name);