patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11
@ 2021-08-16 14:50 Kalesh A P
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 1/6] net/bnxt: fix auto-negotiation on Whitney+ Kalesh A P
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Kalesh A P @ 2021-08-16 14:50 UTC (permalink / raw)
  To: stable

From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>

Please apply.

Kalesh AP (4):
  net/bnxt: fix auto-negotiation on Whitney+
  net/bnxt: remove unnecessary comment
  net/bnxt: invoke device removal event on recovery failure
  net/bnxt: clear cached statistics

Somnath Kotur (2):
  net/bnxt: detect bad opaque in Rx completion
  net/bnxt: workaround spurious zero stats in Thor

 drivers/net/bnxt/bnxt.h                |  47 ++++++++++
 drivers/net/bnxt/bnxt_ethdev.c         |  51 +++++++++-
 drivers/net/bnxt/bnxt_hwrm.c           | 167 ++++++++++++++++++++++++++++-----
 drivers/net/bnxt/bnxt_hwrm.h           |   7 +-
 drivers/net/bnxt/bnxt_rxq.h            |   1 +
 drivers/net/bnxt/bnxt_rxr.c            | 102 +++++++++++++++++++-
 drivers/net/bnxt/bnxt_rxr.h            |   1 +
 drivers/net/bnxt/bnxt_stats.c          |  77 +++++++++++++--
 drivers/net/bnxt/hsi_struct_def_dpdk.h |  11 ++-
 9 files changed, 422 insertions(+), 42 deletions(-)

-- 
2.10.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [dpdk-stable] [PATCH 19.11 1/6] net/bnxt: fix auto-negotiation on Whitney+
  2021-08-16 14:50 [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11 Kalesh A P
@ 2021-08-16 14:50 ` Kalesh A P
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 2/6] net/bnxt: remove unnecessary comment Kalesh A P
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Kalesh A P @ 2021-08-16 14:50 UTC (permalink / raw)
  To: stable

From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>

[ upstream commit 70c7d4184cb9a32ab6c65ce67ce5fbe3a5be5294 ]

Driver should enable autoneg on a port if FW supports it.
Because of a wrong check, driver is not enabling autoneg
on a port after setting forced speed on Whitney+.

There was some dependency on other changes which are not there
in the 19.11 stable. Merged the minimal needed changes for this.

Fixes: 7bc8e9a227cc ("net/bnxt: support async link notification")

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.h        |  1 +
 drivers/net/bnxt/bnxt_ethdev.c |  2 ++
 drivers/net/bnxt/bnxt_hwrm.c   | 43 +++++++++++++++++++++++++++++++++---------
 drivers/net/bnxt/bnxt_hwrm.h   |  1 +
 4 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h
index 335c88d..60173e4 100644
--- a/drivers/net/bnxt/bnxt.h
+++ b/drivers/net/bnxt/bnxt.h
@@ -251,6 +251,7 @@ struct bnxt_link_info {
 	uint8_t			phy_ver[PHY_VER_LEN];
 	uint16_t		link_speed;
 	uint16_t		support_speeds;
+	uint16_t                support_auto_speeds;
 	uint16_t		auto_link_speed;
 	uint16_t		force_link_speed;
 	uint16_t		auto_link_speed_mask;
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 5ca0317..64df248 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -4993,6 +4993,8 @@ static int bnxt_init_fw(struct bnxt *bp)
 
 	bnxt_hwrm_port_led_qcaps(bp);
 
+	bnxt_hwrm_port_phy_qcaps(bp);
+
 	return 0;
 }
 
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index d1f6d23..e354df1 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -1239,6 +1239,7 @@ static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
 
 	link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
 	link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
+	link_info->auto_link_speed_mask = rte_le_to_cpu_16(resp->auto_link_speed_mask);
 	link_info->preemphasis = rte_le_to_cpu_32(resp->preemphasis);
 	link_info->force_link_speed = rte_le_to_cpu_16(resp->force_link_speed);
 	link_info->phy_ver[0] = resp->phy_maj;
@@ -2885,15 +2886,8 @@ int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
 
 	speed = bnxt_parse_eth_link_speed(dev_conf->link_speeds);
 	link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
-	/* Autoneg can be done only when the FW allows.
-	 * When user configures fixed speed of 40G and later changes to
-	 * any other speed, auto_link_speed/force_link_speed is still set
-	 * to 40G until link comes up at new speed.
-	 */
-	if (autoneg == 1 &&
-	    !(!BNXT_CHIP_THOR(bp) &&
-	      (bp->link_info.auto_link_speed ||
-	       bp->link_info.force_link_speed))) {
+	/* Autoneg can be done only when the FW allows. */
+	if (autoneg == 1 && bp->link_info.support_auto_speeds) {
 		link_req.phy_flags |=
 				HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
 		link_req.auto_link_speed_mask =
@@ -5122,3 +5116,34 @@ int bnxt_hwrm_poll_ver_get(struct bnxt *bp)
 
 	return rc;
 }
+
+int bnxt_hwrm_port_phy_qcaps(struct bnxt *bp)
+{
+	int rc = 0;
+	struct hwrm_port_phy_qcaps_input req = {0};
+	struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
+	struct bnxt_link_info *link_info = &bp->link_info;
+
+	if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
+		return 0;
+
+	HWRM_PREP(req, PORT_PHY_QCAPS, BNXT_USE_CHIMP_MB);
+
+	rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
+
+	HWRM_CHECK_RESULT();
+
+	if (resp->supported_speeds_auto_mode)
+		link_info->support_auto_speeds =
+			rte_le_to_cpu_16(resp->supported_speeds_auto_mode);
+
+	/* Older firmware does not have supported_auto_speeds, so assume
+	 * that all supported speeds can be autonegotiated.
+	 */
+	if (link_info->auto_link_speed_mask && !link_info->support_auto_speeds)
+		link_info->support_auto_speeds = link_info->support_speeds;
+
+	HWRM_UNLOCK();
+
+	return 0;
+}
diff --git a/drivers/net/bnxt/bnxt_hwrm.h b/drivers/net/bnxt/bnxt_hwrm.h
index 7b2432f..b8fb37d 100644
--- a/drivers/net/bnxt/bnxt_hwrm.h
+++ b/drivers/net/bnxt/bnxt_hwrm.h
@@ -228,4 +228,5 @@ int bnxt_hwrm_port_ts_query(struct bnxt *bp, uint8_t path,
 int bnxt_clear_one_vnic_filter(struct bnxt *bp,
 			       struct bnxt_filter_info *filter);
 int bnxt_hwrm_poll_ver_get(struct bnxt *bp);
+int bnxt_hwrm_port_phy_qcaps(struct bnxt *bp);
 #endif
-- 
2.10.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [dpdk-stable] [PATCH 19.11 2/6] net/bnxt: remove unnecessary comment
  2021-08-16 14:50 [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11 Kalesh A P
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 1/6] net/bnxt: fix auto-negotiation on Whitney+ Kalesh A P
@ 2021-08-16 14:50 ` Kalesh A P
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 3/6] net/bnxt: invoke device removal event on recovery failure Kalesh A P
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Kalesh A P @ 2021-08-16 14:50 UTC (permalink / raw)
  To: stable

From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>

[ upstream commit 46c451d905e8e27787a0471ecc1d31a4cde25a9e ]

Remove unnecessary comment in the code.

Fixes: 0a6d2a720078 ("net/bnxt: get device infos")

Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt_ethdev.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 64df248..35f33b8 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -547,7 +547,6 @@ static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
 	dev_info->tx_offload_capa = BNXT_DEV_TX_OFFLOAD_SUPPORT;
 	dev_info->flow_type_rss_offloads = BNXT_ETH_RSS_SUPPORT;
 
-	/* *INDENT-OFF* */
 	dev_info->default_rxconf = (struct rte_eth_rxconf) {
 		.rx_thresh = {
 			.pthresh = 8,
@@ -575,8 +574,6 @@ static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
 	dev_info->tx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
 	dev_info->tx_desc_lim.nb_max = BNXT_MAX_TX_RING_DESC;
 
-	/* *INDENT-ON* */
-
 	/*
 	 * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
 	 *       need further investigation.
-- 
2.10.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [dpdk-stable] [PATCH 19.11 3/6] net/bnxt: invoke device removal event on recovery failure
  2021-08-16 14:50 [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11 Kalesh A P
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 1/6] net/bnxt: fix auto-negotiation on Whitney+ Kalesh A P
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 2/6] net/bnxt: remove unnecessary comment Kalesh A P
@ 2021-08-16 14:50 ` Kalesh A P
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 4/6] net/bnxt: detect bad opaque in Rx completion Kalesh A P
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Kalesh A P @ 2021-08-16 14:50 UTC (permalink / raw)
  To: stable

From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>

[ upstream commit 8ac3cbba621ad1887b069b271115faf76bf04b75 ]

When the driver receives RESET_NOTIFY async event from FW or detects
a FW fatal error condition, it tries to recover from the error.
When the driver fails to recover from the error condition, fixed to
send device removal event to the application.

Fixes: df6cd7c1f73a ("net/bnxt: handle reset notify async event from FW")

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_ethdev.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 35f33b8..4d428b6 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -4288,6 +4288,10 @@ static void bnxt_dev_recover(void *arg)
 err:
 	bp->flags |= BNXT_FLAG_FATAL_ERROR;
 	bnxt_uninit_resources(bp, false);
+	if (bp->eth_dev->data->dev_conf.intr_conf.rmv)
+		_rte_eth_dev_callback_process(bp->eth_dev,
+					      RTE_ETH_EVENT_INTR_RMV,
+					      NULL);
 	PMD_DRV_LOG(ERR, "Failed to recover from FW reset\n");
 }
 
@@ -5236,7 +5240,8 @@ static int bnxt_pci_remove(struct rte_pci_device *pci_dev)
 
 static struct rte_pci_driver bnxt_rte_pmd = {
 	.id_table = bnxt_pci_id_map,
-	.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+	.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
+			RTE_PCI_DRV_INTR_RMV,
 	.probe = bnxt_pci_probe,
 	.remove = bnxt_pci_remove,
 };
-- 
2.10.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [dpdk-stable] [PATCH 19.11 4/6] net/bnxt: detect bad opaque in Rx completion
  2021-08-16 14:50 [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11 Kalesh A P
                   ` (2 preceding siblings ...)
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 3/6] net/bnxt: invoke device removal event on recovery failure Kalesh A P
@ 2021-08-16 14:50 ` Kalesh A P
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 5/6] net/bnxt: workaround spurious zero stats in Thor Kalesh A P
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Kalesh A P @ 2021-08-16 14:50 UTC (permalink / raw)
  To: stable

From: Somnath Kotur <somnath.kotur@broadcom.com>

[ upstream commit 03c8f2fe111c2b4c4fddc960dc82253ac7e6c5c5 ]

There is a rare hardware bug that can cause a bad opaque value in the RX
or TPA start completion. When this happens, the hardware may have used the
same buffer twice for 2 Rx packets.  In addition, the driver might also
crash later using the bad opaque as an index into the ring.

The Rx opaque value is predictable and is always monotonically increasing.
The workaround is to keep track of the expected next opaque value and
compare it with the one returned by hardware during RX and TPA start
completions. If they miscompare, log it, discard the completion,
schedule a ring reset and move on to the next one.

Fixes: 0958d8b6435d ("net/bnxt: support LRO")

Signed-off-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt_hwrm.c           |  19 ++++++
 drivers/net/bnxt/bnxt_hwrm.h           |   1 +
 drivers/net/bnxt/bnxt_rxq.h            |   1 +
 drivers/net/bnxt/bnxt_rxr.c            | 102 ++++++++++++++++++++++++++++++++-
 drivers/net/bnxt/bnxt_rxr.h            |   1 +
 drivers/net/bnxt/hsi_struct_def_dpdk.h |  11 +++-
 6 files changed, 131 insertions(+), 4 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index e354df1..724fa25 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -2530,6 +2530,25 @@ int bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 	return rc;
 }
 
+int bnxt_hwrm_rx_ring_reset(struct bnxt *bp, int queue_index)
+{
+	int rc;
+	struct hwrm_ring_reset_input req = {.req_type = 0 };
+	struct hwrm_ring_reset_output *resp = bp->hwrm_cmd_resp_addr;
+
+	HWRM_PREP(req, RING_RESET, BNXT_USE_CHIMP_MB);
+
+	req.ring_type = HWRM_RING_RESET_INPUT_RING_TYPE_RX_RING_GRP;
+	req.ring_id = rte_cpu_to_le_16(bp->grp_info[queue_index].fw_grp_id);
+	rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
+
+	HWRM_CHECK_RESULT();
+
+	HWRM_UNLOCK();
+
+	return rc;
+}
+
 static int
 bnxt_clear_hwrm_vnic_flows(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 {
diff --git a/drivers/net/bnxt/bnxt_hwrm.h b/drivers/net/bnxt/bnxt_hwrm.h
index b8fb37d..8ee9a7b 100644
--- a/drivers/net/bnxt/bnxt_hwrm.h
+++ b/drivers/net/bnxt/bnxt_hwrm.h
@@ -229,4 +229,5 @@ int bnxt_clear_one_vnic_filter(struct bnxt *bp,
 			       struct bnxt_filter_info *filter);
 int bnxt_hwrm_poll_ver_get(struct bnxt *bp);
 int bnxt_hwrm_port_phy_qcaps(struct bnxt *bp);
+int bnxt_hwrm_rx_ring_reset(struct bnxt *bp, int queue_index);
 #endif
diff --git a/drivers/net/bnxt/bnxt_rxq.h b/drivers/net/bnxt/bnxt_rxq.h
index ae3badb..6942af9 100644
--- a/drivers/net/bnxt/bnxt_rxq.h
+++ b/drivers/net/bnxt/bnxt_rxq.h
@@ -32,6 +32,7 @@ struct bnxt_rx_queue {
 	uint8_t			rx_deferred_start; /* not in global dev start */
 	uint8_t			rx_started; /* RX queue is started */
 	uint8_t			drop_en; /* Drop when rx desc not available. */
+	uint8_t			in_reset; /* Rx ring is scheduled for reset */
 
 	struct bnxt		*bp;
 	int			index;
diff --git a/drivers/net/bnxt/bnxt_rxr.c b/drivers/net/bnxt/bnxt_rxr.c
index 8abd391..faa13bc 100644
--- a/drivers/net/bnxt/bnxt_rxr.c
+++ b/drivers/net/bnxt/bnxt_rxr.c
@@ -10,15 +10,14 @@
 #include <rte_byteorder.h>
 #include <rte_malloc.h>
 #include <rte_memory.h>
+#include <rte_alarm.h>
 
 #include "bnxt.h"
 #include "bnxt_ring.h"
 #include "bnxt_rxr.h"
 #include "bnxt_rxq.h"
 #include "hsi_struct_def_dpdk.h"
-#ifdef RTE_LIBRTE_IEEE1588
 #include "bnxt_hwrm.h"
-#endif
 
 /*
  * RX Ring handling
@@ -122,6 +121,50 @@ struct rte_mbuf *bnxt_consume_rx_buf(struct bnxt_rx_ring_info *rxr,
 	return mbuf;
 }
 
+static void bnxt_rx_ring_reset(void *arg)
+{
+	struct bnxt *bp = arg;
+	int i, rc = 0;
+	struct bnxt_rx_queue *rxq;
+
+
+	for (i = 0; i < (int)bp->rx_nr_rings; i++) {
+		struct bnxt_rx_ring_info *rxr;
+
+		rxq = bp->rx_queues[i];
+		if (!rxq || !rxq->in_reset)
+			continue;
+
+		rxr = rxq->rx_ring;
+		/* Disable and flush TPA before resetting the RX ring */
+		if (rxr->tpa_info)
+			bnxt_hwrm_vnic_tpa_cfg(bp, rxq->vnic, false);
+		rc = bnxt_hwrm_rx_ring_reset(bp, i);
+		if (rc) {
+			PMD_DRV_LOG(ERR, "Rx ring%d reset failed\n", i);
+			continue;
+		}
+
+		bnxt_rx_queue_release_mbufs(rxq);
+		rxr->rx_prod = 0;
+		rxr->ag_prod = 0;
+		rxr->rx_next_cons = 0;
+		bnxt_init_one_rx_ring(rxq);
+		bnxt_db_write(&rxr->rx_db, rxr->rx_prod);
+		bnxt_db_write(&rxr->ag_db, rxr->ag_prod);
+		if (rxr->tpa_info)
+			bnxt_hwrm_vnic_tpa_cfg(bp, rxq->vnic, true);
+
+		rxq->in_reset = 0;
+	}
+}
+
+static void bnxt_sched_ring_reset(struct bnxt_rx_queue *rxq)
+{
+	rxq->in_reset = 1;
+	rte_eal_alarm_set(1, bnxt_rx_ring_reset, (void *)rxq->bp);
+}
+
 static void bnxt_tpa_start(struct bnxt_rx_queue *rxq,
 			   struct rx_tpa_start_cmpl *tpa_start,
 			   struct rx_tpa_start_cmpl_hi *tpa_start1)
@@ -136,6 +179,12 @@ static void bnxt_tpa_start(struct bnxt_rx_queue *rxq,
 
 	data_cons = tpa_start->opaque;
 	tpa_info = &rxr->tpa_info[agg_id];
+	if (unlikely(data_cons != rxr->rx_next_cons)) {
+		PMD_DRV_LOG(ERR, "TPA cons %x, expected cons %x\n",
+			    data_cons, rxr->rx_next_cons);
+		bnxt_sched_ring_reset(rxq);
+		return;
+	}
 
 	mbuf = bnxt_consume_rx_buf(rxr, data_cons);
 
@@ -172,6 +221,8 @@ static void bnxt_tpa_start(struct bnxt_rx_queue *rxq,
 	/* recycle next mbuf */
 	data_cons = RING_NEXT(rxr->rx_ring_struct, data_cons);
 	bnxt_reuse_rx_mbuf(rxr, bnxt_consume_rx_buf(rxr, data_cons));
+
+	rxr->rx_next_cons = RING_NEXT(rxr->rx_ring_struct, data_cons);
 }
 
 static int bnxt_agg_bufs_valid(struct bnxt_cp_ring_info *cpr,
@@ -267,6 +318,34 @@ static int bnxt_rx_pages(struct bnxt_rx_queue *rxq,
 	return 0;
 }
 
+static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
+			   uint32_t *raw_cons, void *cmp)
+{
+	struct rx_pkt_cmpl *rxcmp = cmp;
+	uint32_t tmp_raw_cons = *raw_cons;
+	uint8_t cmp_type, agg_bufs = 0;
+
+	cmp_type = CMP_TYPE(rxcmp);
+
+	if (cmp_type == CMPL_BASE_TYPE_RX_L2) {
+		agg_bufs = BNXT_RX_L2_AGG_BUFS(rxcmp);
+	} else if (cmp_type == RX_TPA_END_CMPL_TYPE_RX_TPA_END) {
+		struct rx_tpa_end_cmpl *tpa_end = cmp;
+
+		if (BNXT_CHIP_THOR(bp))
+			return 0;
+
+		agg_bufs = BNXT_TPA_END_AGG_BUFS(tpa_end);
+	}
+
+	if (agg_bufs) {
+		if (!bnxt_agg_bufs_valid(cpr, agg_bufs, tmp_raw_cons))
+			return -EBUSY;
+	}
+	*raw_cons = tmp_raw_cons;
+	return 0;
+}
+
 static inline struct rte_mbuf *bnxt_tpa_end(
 		struct bnxt_rx_queue *rxq,
 		uint32_t *raw_cp_cons,
@@ -281,6 +360,13 @@ static inline struct rte_mbuf *bnxt_tpa_end(
 	uint8_t payload_offset;
 	struct bnxt_tpa_info *tpa_info;
 
+	if (unlikely(rxq->in_reset)) {
+		PMD_DRV_LOG(ERR, "rxq->in_reset: raw_cp_cons:%d\n",
+			    *raw_cp_cons);
+		bnxt_discard_rx(rxq->bp, cpr, raw_cp_cons, tpa_end);
+		return NULL;
+	}
+
 	if (BNXT_CHIP_THOR(rxq->bp)) {
 		struct rx_tpa_v2_end_cmpl *th_tpa_end;
 		struct rx_tpa_v2_end_cmpl_hi *th_tpa_end1;
@@ -475,6 +561,14 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt,
 	prod = rxr->rx_prod;
 
 	cons = rxcmp->opaque;
+	if (unlikely(cons != rxr->rx_next_cons)) {
+		bnxt_discard_rx(rxq->bp, cpr, &tmp_raw_cons, rxcmp);
+		PMD_DRV_LOG(ERR, "RX cons %x != expected cons %x\n",
+			    cons, rxr->rx_next_cons);
+		bnxt_sched_ring_reset(rxq);
+		rc = -EBUSY;
+		goto next_rx;
+	}
 	mbuf = bnxt_consume_rx_buf(rxr, cons);
 	if (mbuf == NULL)
 		return -EBUSY;
@@ -588,6 +682,7 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt,
 		goto rx;
 	}
 	rxr->rx_prod = prod;
+	rxr->rx_next_cons = RING_NEXT(rxr->rx_ring_struct, cons);
 	/*
 	 * All MBUFs are allocated with the same size under DPDK,
 	 * no optimization for rx_copy_thresh
@@ -907,5 +1002,8 @@ int bnxt_init_one_rx_ring(struct bnxt_rx_queue *rxq)
 	}
 	PMD_DRV_LOG(DEBUG, "TPA alloc Done!\n");
 
+	/* Explicitly reset this driver internal tracker on a ring init */
+	rxr->rx_next_cons = 0;
+
 	return 0;
 }
diff --git a/drivers/net/bnxt/bnxt_rxr.h b/drivers/net/bnxt/bnxt_rxr.h
index 387ab0b..f53bdde 100644
--- a/drivers/net/bnxt/bnxt_rxr.h
+++ b/drivers/net/bnxt/bnxt_rxr.h
@@ -190,6 +190,7 @@ struct bnxt_sw_rx_bd {
 struct bnxt_rx_ring_info {
 	uint16_t		rx_prod;
 	uint16_t		ag_prod;
+	uint16_t                rx_next_cons;
 	struct bnxt_db_info     rx_db;
 	struct bnxt_db_info     ag_db;
 
diff --git a/drivers/net/bnxt/hsi_struct_def_dpdk.h b/drivers/net/bnxt/hsi_struct_def_dpdk.h
index c2bae0f..ced1e04 100644
--- a/drivers/net/bnxt/hsi_struct_def_dpdk.h
+++ b/drivers/net/bnxt/hsi_struct_def_dpdk.h
@@ -24388,8 +24388,15 @@ struct hwrm_ring_reset_input {
 	#define HWRM_RING_RESET_INPUT_RING_TYPE_RX        UINT32_C(0x2)
 	/* RoCE Notification Completion Ring (ROCE_CR) */
 	#define HWRM_RING_RESET_INPUT_RING_TYPE_ROCE_CMPL UINT32_C(0x3)
-	#define HWRM_RING_RESET_INPUT_RING_TYPE_LAST \
-		HWRM_RING_RESET_INPUT_RING_TYPE_ROCE_CMPL
+	/*
+	 * Rx Ring Group.  This is to reset rx and aggregation in an atomic
+	 * operation. Completion ring associated with this ring group is
+	 * not reset.
+	 */
+        #define HWRM_RING_RESET_INPUT_RING_TYPE_RX_RING_GRP UINT32_C(0x6)
+        #define HWRM_RING_RESET_INPUT_RING_TYPE_LAST \
+                HWRM_RING_RESET_INPUT_RING_TYPE_RX_RING_GRP
+
 	uint8_t	unused_0;
 	/* Physical number of the ring. */
 	uint16_t	ring_id;
-- 
2.10.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [dpdk-stable] [PATCH 19.11 5/6] net/bnxt: workaround spurious zero stats in Thor
  2021-08-16 14:50 [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11 Kalesh A P
                   ` (3 preceding siblings ...)
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 4/6] net/bnxt: detect bad opaque in Rx completion Kalesh A P
@ 2021-08-16 14:50 ` Kalesh A P
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 6/6] net/bnxt: clear cached statistics Kalesh A P
  2021-08-17  9:40 ` [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11 Christian Ehrhardt
  6 siblings, 0 replies; 8+ messages in thread
From: Kalesh A P @ 2021-08-16 14:50 UTC (permalink / raw)
  To: stable

From: Somnath Kotur <somnath.kotur@broadcom.com>

[ upstream commit 219842b9990c2a3a426c14c7911a44d2cb9b6fdf ]

There is a HW bug that can result in certain stats being reported as
zero.
Workaround this by ignoring stats with a value of zero based on the
previously stored snapshot of the same stat.
This bug mainly manifests in the output of func_qstats as FW aggregrates
each ring's stat value to give the per function stat and if one of
them is zero, the per function stat value ends up being lower than the
previous snapshot which shows up as a zero PPS value in testpmd.
Eliminate invocation of func_qstats and aggregate the per-ring stat
values in the driver itself to derive the func_qstats output post
accounting for the spurious zero stat value.

Bugzilla ID: 641
Fixes: f8168ca0e690 ("net/bnxt: support thor controller")

Signed-off-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Lance Richardson <lance.richardson@broadcom.com>
Reviewed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt.h        |  46 ++++++++++++++++++
 drivers/net/bnxt/bnxt_ethdev.c |  39 +++++++++++++++
 drivers/net/bnxt/bnxt_hwrm.c   | 105 ++++++++++++++++++++++++++++++++++-------
 drivers/net/bnxt/bnxt_hwrm.h   |   5 +-
 drivers/net/bnxt/bnxt_stats.c  |  63 ++++++++++++++++++++++---
 5 files changed, 233 insertions(+), 25 deletions(-)

diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h
index 60173e4..ceff0a7 100644
--- a/drivers/net/bnxt/bnxt.h
+++ b/drivers/net/bnxt/bnxt.h
@@ -492,6 +492,50 @@ struct bnxt_error_recovery_info {
 #define BNXT_FW_STATUS_SHUTDOWN		0x100000
 
 #define BNXT_HWRM_SHORT_REQ_LEN		sizeof(struct hwrm_short_input)
+
+struct bnxt_ring_stats {
+	/* Number of transmitted unicast packets */
+	uint64_t	tx_ucast_pkts;
+	/* Number of transmitted multicast packets */
+	uint64_t	tx_mcast_pkts;
+	/* Number of transmitted broadcast packets */
+	uint64_t	tx_bcast_pkts;
+	/* Number of packets discarded in transmit path */
+	uint64_t	tx_discard_pkts;
+	/* Number of packets in transmit path with error */
+	uint64_t	tx_error_pkts;
+	/* Number of transmitted bytes for unicast traffic */
+	uint64_t	tx_ucast_bytes;
+	/* Number of transmitted bytes for multicast traffic */
+	uint64_t	tx_mcast_bytes;
+	/* Number of transmitted bytes for broadcast traffic */
+	uint64_t	tx_bcast_bytes;
+	/* Number of received unicast packets */
+	uint64_t	rx_ucast_pkts;
+	/* Number of received multicast packets */
+	uint64_t	rx_mcast_pkts;
+	/* Number of received broadcast packets */
+	uint64_t	rx_bcast_pkts;
+	/* Number of packets discarded in receive path */
+	uint64_t	rx_discard_pkts;
+	/* Number of packets in receive path with errors */
+	uint64_t	rx_error_pkts;
+	/* Number of received bytes for unicast traffic */
+	uint64_t	rx_ucast_bytes;
+	/* Number of received bytes for multicast traffic */
+	uint64_t	rx_mcast_bytes;
+	/* Number of received bytes for broadcast traffic */
+	uint64_t	rx_bcast_bytes;
+	/* Number of aggregated unicast packets */
+	uint64_t	rx_agg_pkts;
+	/* Number of aggregated unicast bytes */
+	uint64_t	rx_agg_bytes;
+	/* Number of aggregation events */
+	uint64_t	rx_agg_events;
+	/* Number of aborted aggregations */
+	uint64_t	rx_agg_aborts;
+};
+
 struct bnxt {
 	void				*bar0;
 
@@ -661,6 +705,8 @@ struct bnxt {
 
 	/* Struct to hold adapter error recovery related info */
 	struct bnxt_error_recovery_info *recovery_info;
+	struct bnxt_ring_stats	*prev_rx_ring_stats;
+	struct bnxt_ring_stats	*prev_tx_ring_stats;
 };
 
 static
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 4d428b6..06b043d 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -334,6 +334,39 @@ static int bnxt_setup_one_vnic(struct bnxt *bp, uint16_t vnic_id)
 	return rc;
 }
 
+static void bnxt_free_prev_ring_stats(struct bnxt *bp)
+{
+	rte_free(bp->prev_rx_ring_stats);
+	rte_free(bp->prev_tx_ring_stats);
+
+	bp->prev_rx_ring_stats = NULL;
+	bp->prev_tx_ring_stats = NULL;
+}
+
+static int bnxt_alloc_prev_ring_stats(struct bnxt *bp)
+{
+	bp->prev_rx_ring_stats =  rte_zmalloc("bnxt_prev_rx_ring_stats",
+					      sizeof(struct bnxt_ring_stats) *
+					      bp->rx_cp_nr_rings,
+					      0);
+	if (bp->prev_rx_ring_stats == NULL)
+		return -ENOMEM;
+
+	bp->prev_tx_ring_stats = rte_zmalloc("bnxt_prev_tx_ring_stats",
+					     sizeof(struct bnxt_ring_stats) *
+					     bp->tx_cp_nr_rings,
+					     0);
+	if (bp->prev_tx_ring_stats == NULL)
+		goto error;
+
+	return 0;
+
+error:
+	bnxt_free_prev_ring_stats(bp);
+	return -ENOMEM;
+}
+
+
 static int bnxt_init_chip(struct bnxt *bp)
 {
 	struct rte_eth_link new;
@@ -880,6 +913,10 @@ static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
 	if (rc)
 		goto error;
 
+	rc = bnxt_alloc_prev_ring_stats(bp);
+	if (rc)
+		goto error;
+
 	eth_dev->data->scattered_rx = bnxt_scattered_rx(eth_dev);
 	eth_dev->data->dev_started = 1;
 
@@ -905,6 +942,7 @@ static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
 	bnxt_free_tx_mbufs(bp);
 	bnxt_free_rx_mbufs(bp);
 	bnxt_hwrm_if_change(bp, false);
+	bnxt_free_prev_ring_stats(bp);
 	eth_dev->data->dev_started = 0;
 	return rc;
 }
@@ -1055,6 +1093,7 @@ static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
 	bnxt_int_handler(eth_dev);
 	bnxt_shutdown_nic(bp);
 	bnxt_hwrm_if_change(bp, false);
+	bnxt_free_prev_ring_stats(bp);
 	bp->rx_cosq_cnt = 0;
 }
 
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 724fa25..22e92a9 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -3690,8 +3690,20 @@ int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
 	return rc;
 }
 
-int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
-			 struct rte_eth_stats *stats, uint8_t rx)
+static void bnxt_update_prev_stat(uint64_t *cntr, uint64_t *prev_cntr)
+{
+	/* One of the HW stat values that make up this counter was zero as
+	 * returned by HW in this iteration, so use the previous
+	 * iteration's counter value
+	 */
+	if (*prev_cntr && *cntr == 0)
+		*cntr = *prev_cntr;
+	else
+		*prev_cntr = *cntr;
+}
+
+int bnxt_hwrm_ring_stats(struct bnxt *bp, uint32_t cid, int idx,
+			 struct bnxt_ring_stats *ring_stats, bool rx)
 {
 	int rc = 0;
 	struct hwrm_stat_ctx_query_input req = {.req_type = 0};
@@ -3706,21 +3718,82 @@ int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
 	HWRM_CHECK_RESULT();
 
 	if (rx) {
-		stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
-		stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
-		stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
-		stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
-		stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
-		stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
-		stats->q_errors[idx] = rte_le_to_cpu_64(resp->rx_err_pkts);
-		stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
+		struct bnxt_ring_stats *prev_stats = &bp->prev_rx_ring_stats[idx];
+
+		ring_stats->rx_ucast_pkts = rte_le_to_cpu_64(resp->rx_ucast_pkts);
+		bnxt_update_prev_stat(&ring_stats->rx_ucast_pkts,
+				      &prev_stats->rx_ucast_pkts);
+
+		ring_stats->rx_mcast_pkts = rte_le_to_cpu_64(resp->rx_mcast_pkts);
+		bnxt_update_prev_stat(&ring_stats->rx_mcast_pkts,
+				      &prev_stats->rx_mcast_pkts);
+
+		ring_stats->rx_bcast_pkts = rte_le_to_cpu_64(resp->rx_bcast_pkts);
+		bnxt_update_prev_stat(&ring_stats->rx_bcast_pkts,
+				      &prev_stats->rx_bcast_pkts);
+
+		ring_stats->rx_ucast_bytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
+		bnxt_update_prev_stat(&ring_stats->rx_ucast_bytes,
+				      &prev_stats->rx_ucast_bytes);
+
+		ring_stats->rx_mcast_bytes = rte_le_to_cpu_64(resp->rx_mcast_bytes);
+		bnxt_update_prev_stat(&ring_stats->rx_mcast_bytes,
+				      &prev_stats->rx_mcast_bytes);
+
+		ring_stats->rx_bcast_bytes = rte_le_to_cpu_64(resp->rx_bcast_bytes);
+		bnxt_update_prev_stat(&ring_stats->rx_bcast_bytes,
+				      &prev_stats->rx_bcast_bytes);
+
+		ring_stats->rx_error_pkts = rte_le_to_cpu_64(resp->rx_err_pkts);
+		bnxt_update_prev_stat(&ring_stats->rx_error_pkts,
+				      &prev_stats->rx_error_pkts);
+
+		ring_stats->rx_discard_pkts = rte_le_to_cpu_64(resp->rx_drop_pkts);
+		bnxt_update_prev_stat(&ring_stats->rx_discard_pkts,
+				      &prev_stats->rx_discard_pkts);
+
+		ring_stats->rx_agg_pkts = rte_le_to_cpu_64(resp->rx_agg_pkts);
+		bnxt_update_prev_stat(&ring_stats->rx_agg_pkts,
+				      &prev_stats->rx_agg_pkts);
+
+		ring_stats->rx_agg_bytes = rte_le_to_cpu_64(resp->rx_agg_bytes);
+		bnxt_update_prev_stat(&ring_stats->rx_agg_bytes,
+				      &prev_stats->rx_agg_bytes);
+
+		ring_stats->rx_agg_events = rte_le_to_cpu_64(resp->rx_agg_events);
+		bnxt_update_prev_stat(&ring_stats->rx_agg_events,
+				      &prev_stats->rx_agg_events);
+
+		ring_stats->rx_agg_aborts = rte_le_to_cpu_64(resp->rx_agg_aborts);
+		bnxt_update_prev_stat(&ring_stats->rx_agg_aborts,
+				      &prev_stats->rx_agg_aborts);
 	} else {
-		stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
-		stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
-		stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
-		stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
-		stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
-		stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
+		struct bnxt_ring_stats *prev_stats = &bp->prev_tx_ring_stats[idx];
+
+		ring_stats->tx_ucast_pkts = rte_le_to_cpu_64(resp->tx_ucast_pkts);
+		bnxt_update_prev_stat(&ring_stats->tx_ucast_pkts,
+				      &prev_stats->tx_ucast_pkts);
+
+		ring_stats->tx_mcast_pkts = rte_le_to_cpu_64(resp->tx_mcast_pkts);
+		bnxt_update_prev_stat(&ring_stats->tx_mcast_pkts,
+				      &prev_stats->tx_mcast_pkts);
+
+		ring_stats->tx_bcast_pkts = rte_le_to_cpu_64(resp->tx_bcast_pkts);
+		bnxt_update_prev_stat(&ring_stats->tx_bcast_pkts,
+				      &prev_stats->tx_bcast_pkts);
+
+		ring_stats->tx_ucast_bytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
+		bnxt_update_prev_stat(&ring_stats->tx_ucast_bytes,
+				      &prev_stats->tx_ucast_bytes);
+
+		ring_stats->tx_mcast_bytes = rte_le_to_cpu_64(resp->tx_mcast_bytes);
+		bnxt_update_prev_stat(&ring_stats->tx_mcast_bytes,
+				      &prev_stats->tx_mcast_bytes);
+
+		ring_stats->tx_bcast_bytes = rte_le_to_cpu_64(resp->tx_bcast_bytes);
+		bnxt_update_prev_stat(&ring_stats->tx_bcast_bytes,
+				      &prev_stats->tx_bcast_bytes);
+
 	}
 
 	HWRM_UNLOCK();
diff --git a/drivers/net/bnxt/bnxt_hwrm.h b/drivers/net/bnxt/bnxt_hwrm.h
index 8ee9a7b..2fb0d97 100644
--- a/drivers/net/bnxt/bnxt_hwrm.h
+++ b/drivers/net/bnxt/bnxt_hwrm.h
@@ -113,9 +113,6 @@ int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx);
 int bnxt_hwrm_ring_grp_free(struct bnxt *bp, unsigned int idx);
 
 int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr);
-int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
-			 struct rte_eth_stats *stats, uint8_t rx);
-
 int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout);
 
 int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic);
@@ -230,4 +227,6 @@ int bnxt_clear_one_vnic_filter(struct bnxt *bp,
 int bnxt_hwrm_poll_ver_get(struct bnxt *bp);
 int bnxt_hwrm_port_phy_qcaps(struct bnxt *bp);
 int bnxt_hwrm_rx_ring_reset(struct bnxt *bp, int queue_index);
+int bnxt_hwrm_ring_stats(struct bnxt *bp, uint32_t cid, int idx,
+			 struct bnxt_ring_stats *stats, bool rx);
 #endif
diff --git a/drivers/net/bnxt/bnxt_stats.c b/drivers/net/bnxt/bnxt_stats.c
index 692b096..2b8b927 100644
--- a/drivers/net/bnxt/bnxt_stats.c
+++ b/drivers/net/bnxt/bnxt_stats.c
@@ -377,8 +377,48 @@ void bnxt_free_stats(struct bnxt *bp)
 	}
 }
 
+static void bnxt_fill_rte_eth_stats(struct rte_eth_stats *stats,
+				    struct bnxt_ring_stats *ring_stats,
+				    unsigned int i, bool rx)
+{
+	if (rx) {
+		stats->q_ipackets[i] = ring_stats->rx_ucast_pkts;
+		stats->q_ipackets[i] += ring_stats->rx_mcast_pkts;
+		stats->q_ipackets[i] += ring_stats->rx_bcast_pkts;
+
+		stats->ipackets += stats->q_ipackets[i];
+
+		stats->q_ibytes[i] = ring_stats->rx_ucast_bytes;
+		stats->q_ibytes[i] += ring_stats->rx_mcast_bytes;
+		stats->q_ibytes[i] += ring_stats->rx_bcast_bytes;
+
+		stats->ibytes += stats->q_ibytes[i];
+
+		stats->q_errors[i] = ring_stats->rx_discard_pkts;
+		stats->q_errors[i] += ring_stats->rx_error_pkts;
+
+		stats->imissed += ring_stats->rx_discard_pkts;
+		stats->ierrors += ring_stats->rx_error_pkts;
+		stats->ierrors += ring_stats->rx_discard_pkts;
+	} else {
+		stats->q_opackets[i] = ring_stats->tx_ucast_pkts;
+		stats->q_opackets[i] += ring_stats->tx_mcast_pkts;
+		stats->q_opackets[i] += ring_stats->tx_bcast_pkts;
+
+		stats->opackets += stats->q_opackets[i];
+
+		stats->q_obytes[i] = ring_stats->tx_ucast_bytes;
+		stats->q_obytes[i] += ring_stats->tx_mcast_bytes;
+		stats->q_obytes[i] += ring_stats->tx_bcast_bytes;
+
+		stats->obytes += stats->q_obytes[i];
+
+		stats->oerrors += ring_stats->tx_discard_pkts;
+	}
+}
+
 int bnxt_stats_get_op(struct rte_eth_dev *eth_dev,
-			   struct rte_eth_stats *bnxt_stats)
+		      struct rte_eth_stats *bnxt_stats)
 {
 	int rc = 0;
 	unsigned int i;
@@ -398,11 +438,17 @@ int bnxt_stats_get_op(struct rte_eth_dev *eth_dev,
 	for (i = 0; i < num_q_stats; i++) {
 		struct bnxt_rx_queue *rxq = bp->rx_queues[i];
 		struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
+		struct bnxt_ring_stats ring_stats = {0};
 
-		rc = bnxt_hwrm_ctx_qstats(bp, cpr->hw_stats_ctx_id, i,
-				     bnxt_stats, 1);
+		if (!rxq->rx_started)
+			continue;
+
+		rc = bnxt_hwrm_ring_stats(bp, cpr->hw_stats_ctx_id, i,
+					  &ring_stats, true);
 		if (unlikely(rc))
 			return rc;
+
+		bnxt_fill_rte_eth_stats(bnxt_stats, &ring_stats, i, true);
 		bnxt_stats->rx_nombuf +=
 				rte_atomic64_read(&rxq->rx_mbuf_alloc_fail);
 	}
@@ -413,14 +459,19 @@ int bnxt_stats_get_op(struct rte_eth_dev *eth_dev,
 	for (i = 0; i < num_q_stats; i++) {
 		struct bnxt_tx_queue *txq = bp->tx_queues[i];
 		struct bnxt_cp_ring_info *cpr = txq->cp_ring;
+		struct bnxt_ring_stats ring_stats = {0};
 
-		rc = bnxt_hwrm_ctx_qstats(bp, cpr->hw_stats_ctx_id, i,
-				     bnxt_stats, 0);
+		if (!txq->tx_started)
+			continue;
+
+		rc = bnxt_hwrm_ring_stats(bp, cpr->hw_stats_ctx_id, i,
+					  &ring_stats, false);
 		if (unlikely(rc))
 			return rc;
+
+		bnxt_fill_rte_eth_stats(bnxt_stats, &ring_stats, i, false);
 	}
 
-	rc = bnxt_hwrm_func_qstats(bp, 0xffff, bnxt_stats);
 	return rc;
 }
 
-- 
2.10.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [dpdk-stable] [PATCH 19.11 6/6] net/bnxt: clear cached statistics
  2021-08-16 14:50 [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11 Kalesh A P
                   ` (4 preceding siblings ...)
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 5/6] net/bnxt: workaround spurious zero stats in Thor Kalesh A P
@ 2021-08-16 14:50 ` Kalesh A P
  2021-08-17  9:40 ` [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11 Christian Ehrhardt
  6 siblings, 0 replies; 8+ messages in thread
From: Kalesh A P @ 2021-08-16 14:50 UTC (permalink / raw)
  To: stable

From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>

[ upstream commit 84fd852caac19795d0a05af8dabce8f011fe61a4 ]

As part of the workaround put in the commit "219842b9990c",
driver caches the last read stats values from the hardware.
But this is not cleared during the clear stats operation. This
results in showing up stale stats values while reading the stats
after the clear operation.

Fixes: 219842b9990c ("net/bnxt: workaround spurious zero stats in Thor")

Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Reviewed-by: Lance Richardson <lance.richardson@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
---
 drivers/net/bnxt/bnxt_stats.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/net/bnxt/bnxt_stats.c b/drivers/net/bnxt/bnxt_stats.c
index 2b8b927..b9538bb 100644
--- a/drivers/net/bnxt/bnxt_stats.c
+++ b/drivers/net/bnxt/bnxt_stats.c
@@ -475,6 +475,16 @@ int bnxt_stats_get_op(struct rte_eth_dev *eth_dev,
 	return rc;
 }
 
+static void bnxt_clear_prev_stat(struct bnxt *bp)
+{
+	/*
+	 * Clear the cached values of stats returned by HW in the previous
+	 * get operation.
+	 */
+	memset(bp->prev_rx_ring_stats, 0, sizeof(struct bnxt_ring_stats) * bp->rx_cp_nr_rings);
+	memset(bp->prev_tx_ring_stats, 0, sizeof(struct bnxt_ring_stats) * bp->tx_cp_nr_rings);
+}
+
 int bnxt_stats_reset_op(struct rte_eth_dev *eth_dev)
 {
 	struct bnxt *bp = eth_dev->data->dev_private;
@@ -497,6 +507,8 @@ int bnxt_stats_reset_op(struct rte_eth_dev *eth_dev)
 		rte_atomic64_clear(&rxq->rx_mbuf_alloc_fail);
 	}
 
+	bnxt_clear_prev_stat(bp);
+
 	return ret;
 }
 
@@ -662,5 +674,7 @@ int bnxt_dev_xstats_reset_op(struct rte_eth_dev *eth_dev)
 		PMD_DRV_LOG(ERR, "Failed to reset xstats: %s\n",
 			    strerror(-ret));
 
+	bnxt_clear_prev_stat(bp);
+
 	return ret;
 }
-- 
2.10.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11
  2021-08-16 14:50 [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11 Kalesh A P
                   ` (5 preceding siblings ...)
  2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 6/6] net/bnxt: clear cached statistics Kalesh A P
@ 2021-08-17  9:40 ` Christian Ehrhardt
  6 siblings, 0 replies; 8+ messages in thread
From: Christian Ehrhardt @ 2021-08-17  9:40 UTC (permalink / raw)
  To: Kalesh A P; +Cc: dpdk stable

On Mon, Aug 16, 2021 at 4:30 PM Kalesh A P
<kalesh-anakkur.purayil@broadcom.com> wrote:
>
> From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
>
> Please apply.

Thank you, applied to 19.11 WIP stable branch

> Kalesh AP (4):
>   net/bnxt: fix auto-negotiation on Whitney+
>   net/bnxt: remove unnecessary comment
>   net/bnxt: invoke device removal event on recovery failure
>   net/bnxt: clear cached statistics
>
> Somnath Kotur (2):
>   net/bnxt: detect bad opaque in Rx completion
>   net/bnxt: workaround spurious zero stats in Thor
>
>  drivers/net/bnxt/bnxt.h                |  47 ++++++++++
>  drivers/net/bnxt/bnxt_ethdev.c         |  51 +++++++++-
>  drivers/net/bnxt/bnxt_hwrm.c           | 167 ++++++++++++++++++++++++++++-----
>  drivers/net/bnxt/bnxt_hwrm.h           |   7 +-
>  drivers/net/bnxt/bnxt_rxq.h            |   1 +
>  drivers/net/bnxt/bnxt_rxr.c            | 102 +++++++++++++++++++-
>  drivers/net/bnxt/bnxt_rxr.h            |   1 +
>  drivers/net/bnxt/bnxt_stats.c          |  77 +++++++++++++--
>  drivers/net/bnxt/hsi_struct_def_dpdk.h |  11 ++-
>  9 files changed, 422 insertions(+), 42 deletions(-)
>
> --
> 2.10.1
>


-- 
Christian Ehrhardt
Staff Engineer, Ubuntu Server
Canonical Ltd

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-08-17  9:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16 14:50 [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11 Kalesh A P
2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 1/6] net/bnxt: fix auto-negotiation on Whitney+ Kalesh A P
2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 2/6] net/bnxt: remove unnecessary comment Kalesh A P
2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 3/6] net/bnxt: invoke device removal event on recovery failure Kalesh A P
2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 4/6] net/bnxt: detect bad opaque in Rx completion Kalesh A P
2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 5/6] net/bnxt: workaround spurious zero stats in Thor Kalesh A P
2021-08-16 14:50 ` [dpdk-stable] [PATCH 19.11 6/6] net/bnxt: clear cached statistics Kalesh A P
2021-08-17  9:40 ` [dpdk-stable] [PATCH 19.11 0/6] backport bnxt fixes to 19.11 Christian Ehrhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).