patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Somnath Kotur <somnath.kotur@broadcom.com>
To: stable@dpdk.org
Cc: ktraynor@redhat.com
Subject: [dpdk-stable] [PATCH 18.11 06/19] net/bnxt: fix extended port counter statistics
Date: Wed, 18 Dec 2019 11:53:58 +0530	[thread overview]
Message-ID: <20191218062411.13079-7-somnath.kotur@broadcom.com> (raw)
In-Reply-To: <20191218062411.13079-1-somnath.kotur@broadcom.com>

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

1. refactor stats allocation code to new routine
2. check for extended statistics support depends on "hwrm_spec_code"
   which is set in bnxt_hwrm_ver_get called later. Hence we were never
   querying extended port stats as flags field was not updated. Fixed
   this by moving the stats allocation after the call to
   bnxt_hwrm_ver_get.
3. we were incorrectly passing the host address used for port
   statistics to PORT_QSTATS_EXT command. Fixed this by passing the
   correct extended stats address.

Fixes: f55e12f33416 ("net/bnxt: support extended port counters")

Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt_ethdev.c | 227 ++++++++++++++++++++++-------------------
 drivers/net/bnxt/bnxt_hwrm.c   |   4 +-
 2 files changed, 122 insertions(+), 109 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index c87ccb6..d0d9196 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -3193,15 +3193,126 @@ static int bnxt_init_board(struct rte_eth_dev *eth_dev)
 		bp->pf.vf_req_fwd[((arg) >> 5)] &= \
 		~rte_cpu_to_le_32(1 << ((arg) & 0x1f)); \
 	}
-static int
-bnxt_dev_init(struct rte_eth_dev *eth_dev)
+
+static int bnxt_alloc_stats_mem(struct bnxt *bp)
 {
-	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+	struct rte_pci_device *pci_dev = bp->pdev;
 	char mz_name[RTE_MEMZONE_NAMESIZE];
 	const struct rte_memzone *mz = NULL;
-	static int version_printed;
 	uint32_t total_alloc_len;
 	rte_iova_t mz_phys_addr;
+
+	if (pci_dev->id.device_id == BROADCOM_DEV_ID_NS2)
+		return 0;
+
+	snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
+		 "bnxt_%04x:%02x:%02x:%02x-%s", pci_dev->addr.domain,
+		 pci_dev->addr.bus, pci_dev->addr.devid,
+		 pci_dev->addr.function, "rx_port_stats");
+	mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
+	total_alloc_len =
+		RTE_CACHE_LINE_ROUNDUP(sizeof(struct rx_port_stats) +
+				       sizeof(struct rx_port_stats_ext) +
+				       512);
+	mz = rte_memzone_lookup(mz_name);
+	if (!mz) {
+		mz = rte_memzone_reserve(mz_name, total_alloc_len,
+					 SOCKET_ID_ANY,
+					 RTE_MEMZONE_2MB |
+					 RTE_MEMZONE_SIZE_HINT_ONLY |
+					 RTE_MEMZONE_IOVA_CONTIG);
+		if (mz == NULL)
+			return -ENOMEM;
+	}
+	memset(mz->addr, 0, mz->len);
+	mz_phys_addr = mz->iova;
+	if ((unsigned long)mz->addr == mz_phys_addr) {
+		PMD_DRV_LOG(DEBUG,
+			    "Memzone physical address same as virtual.\n");
+		PMD_DRV_LOG(DEBUG,
+			    "Using rte_mem_virt2iova()\n");
+		mz_phys_addr = rte_mem_virt2iova(mz->addr);
+		if (mz_phys_addr == RTE_BAD_IOVA) {
+			PMD_DRV_LOG(ERR,
+				    "Can't map address to physical memory\n");
+			return -ENOMEM;
+		}
+	}
+
+	bp->rx_mem_zone = (const void *)mz;
+	bp->hw_rx_port_stats = mz->addr;
+	bp->hw_rx_port_stats_map = mz_phys_addr;
+
+	snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
+		 "bnxt_%04x:%02x:%02x:%02x-%s", pci_dev->addr.domain,
+		 pci_dev->addr.bus, pci_dev->addr.devid,
+		 pci_dev->addr.function, "tx_port_stats");
+	mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
+	total_alloc_len =
+		RTE_CACHE_LINE_ROUNDUP(sizeof(struct tx_port_stats) +
+				       sizeof(struct tx_port_stats_ext) +
+				       512);
+	mz = rte_memzone_lookup(mz_name);
+	if (!mz) {
+		mz = rte_memzone_reserve(mz_name,
+					 total_alloc_len,
+					 SOCKET_ID_ANY,
+					 RTE_MEMZONE_2MB |
+					 RTE_MEMZONE_SIZE_HINT_ONLY |
+					 RTE_MEMZONE_IOVA_CONTIG);
+		if (mz == NULL)
+			return -ENOMEM;
+	}
+	memset(mz->addr, 0, mz->len);
+	mz_phys_addr = mz->iova;
+	if ((unsigned long)mz->addr == mz_phys_addr) {
+		PMD_DRV_LOG(DEBUG,
+			    "Memzone physical address same as virtual.\n");
+		PMD_DRV_LOG(DEBUG,
+			    "Using rte_mem_virt2iova()\n");
+		mz_phys_addr = rte_mem_virt2iova(mz->addr);
+		if (mz_phys_addr == RTE_BAD_IOVA) {
+			PMD_DRV_LOG(ERR,
+				    "Can't map address to physical memory\n");
+			return -ENOMEM;
+		}
+	}
+
+	bp->tx_mem_zone = (const void *)mz;
+	bp->hw_tx_port_stats = mz->addr;
+	bp->hw_tx_port_stats_map = mz_phys_addr;
+	bp->flags |= BNXT_FLAG_PORT_STATS;
+
+	/* Display extended statistics if FW supports it */
+	if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_8_4 ||
+	    bp->hwrm_spec_code == HWRM_SPEC_CODE_1_9_0)
+		return 0;
+
+	bp->hw_rx_port_stats_ext = (void *)
+		((uint8_t *)bp->hw_rx_port_stats +
+		 sizeof(struct rx_port_stats));
+	bp->hw_rx_port_stats_ext_map = bp->hw_rx_port_stats_map +
+		sizeof(struct rx_port_stats);
+	bp->flags |= BNXT_FLAG_EXT_RX_PORT_STATS;
+
+	if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_9_2) {
+		bp->hw_tx_port_stats_ext = (void *)
+				((uint8_t *)bp->hw_tx_port_stats +
+				 sizeof(struct tx_port_stats));
+		bp->hw_tx_port_stats_ext_map =
+				bp->hw_tx_port_stats_map +
+				sizeof(struct tx_port_stats);
+		bp->flags |= BNXT_FLAG_EXT_TX_PORT_STATS;
+	}
+
+	return 0;
+}
+
+static int
+bnxt_dev_init(struct rte_eth_dev *eth_dev)
+{
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+	static int version_printed;
 	struct bnxt *bp;
 	int rc;
 
@@ -3235,109 +3346,6 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
 		goto error;
 	}
 
-	if (pci_dev->id.device_id != BROADCOM_DEV_ID_NS2) {
-		snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
-			 "bnxt_%04x:%02x:%02x:%02x-%s", pci_dev->addr.domain,
-			 pci_dev->addr.bus, pci_dev->addr.devid,
-			 pci_dev->addr.function, "rx_port_stats");
-		mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
-		mz = rte_memzone_lookup(mz_name);
-		total_alloc_len = RTE_CACHE_LINE_ROUNDUP(
-					sizeof(struct rx_port_stats) +
-					sizeof(struct rx_port_stats_ext) +
-					512);
-		if (!mz) {
-			mz = rte_memzone_reserve(mz_name, total_alloc_len,
-					SOCKET_ID_ANY,
-					RTE_MEMZONE_2MB |
-					RTE_MEMZONE_SIZE_HINT_ONLY |
-					RTE_MEMZONE_IOVA_CONTIG);
-			if (mz == NULL)
-				return -ENOMEM;
-		}
-		memset(mz->addr, 0, mz->len);
-		mz_phys_addr = mz->iova;
-		if ((unsigned long)mz->addr == mz_phys_addr) {
-			PMD_DRV_LOG(INFO,
-				"Memzone physical address same as virtual using rte_mem_virt2iova()\n");
-			mz_phys_addr = rte_mem_virt2iova(mz->addr);
-			if (mz_phys_addr == RTE_BAD_IOVA) {
-				PMD_DRV_LOG(ERR,
-				"unable to map address to physical memory\n");
-				return -ENOMEM;
-			}
-		}
-
-		bp->rx_mem_zone = (const void *)mz;
-		bp->hw_rx_port_stats = mz->addr;
-		bp->hw_rx_port_stats_map = mz_phys_addr;
-
-		snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
-			 "bnxt_%04x:%02x:%02x:%02x-%s", pci_dev->addr.domain,
-			 pci_dev->addr.bus, pci_dev->addr.devid,
-			 pci_dev->addr.function, "tx_port_stats");
-		mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
-		mz = rte_memzone_lookup(mz_name);
-		total_alloc_len = RTE_CACHE_LINE_ROUNDUP(
-					sizeof(struct tx_port_stats) +
-					sizeof(struct tx_port_stats_ext) +
-					512);
-		if (!mz) {
-			mz = rte_memzone_reserve(mz_name,
-					total_alloc_len,
-					SOCKET_ID_ANY,
-					RTE_MEMZONE_2MB |
-					RTE_MEMZONE_SIZE_HINT_ONLY |
-					RTE_MEMZONE_IOVA_CONTIG);
-			if (mz == NULL)
-				return -ENOMEM;
-		}
-		memset(mz->addr, 0, mz->len);
-		mz_phys_addr = mz->iova;
-		if ((unsigned long)mz->addr == mz_phys_addr) {
-			PMD_DRV_LOG(WARNING,
-				"Memzone physical address same as virtual.\n");
-			PMD_DRV_LOG(WARNING,
-				"Using rte_mem_virt2iova()\n");
-			mz_phys_addr = rte_mem_virt2iova(mz->addr);
-			if (mz_phys_addr == RTE_BAD_IOVA) {
-				PMD_DRV_LOG(ERR,
-				"unable to map address to physical memory\n");
-				return -ENOMEM;
-			}
-		}
-
-		bp->tx_mem_zone = (const void *)mz;
-		bp->hw_tx_port_stats = mz->addr;
-		bp->hw_tx_port_stats_map = mz_phys_addr;
-
-		bp->flags |= BNXT_FLAG_PORT_STATS;
-
-		/* Display extended statistics if FW supports it */
-		if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_8_4 ||
-		    bp->hwrm_spec_code == HWRM_SPEC_CODE_1_9_0)
-			goto skip_ext_stats;
-
-		bp->hw_rx_port_stats_ext = (void *)
-			((uint8_t *)bp->hw_rx_port_stats +
-			 sizeof(struct rx_port_stats));
-		bp->hw_rx_port_stats_ext_map = bp->hw_rx_port_stats_map +
-			sizeof(struct rx_port_stats);
-		bp->flags |= BNXT_FLAG_EXT_RX_PORT_STATS;
-
-
-		if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_9_2) {
-			bp->hw_tx_port_stats_ext = (void *)
-				((uint8_t *)bp->hw_tx_port_stats +
-				 sizeof(struct tx_port_stats));
-			bp->hw_tx_port_stats_ext_map =
-				bp->hw_tx_port_stats_map +
-				sizeof(struct tx_port_stats);
-			bp->flags |= BNXT_FLAG_EXT_TX_PORT_STATS;
-		}
-	}
-
-skip_ext_stats:
 	rc = bnxt_alloc_hwrm_resources(bp);
 	if (rc) {
 		PMD_DRV_LOG(ERR,
@@ -3365,6 +3373,11 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
 		PMD_DRV_LOG(ERR, "hwrm query capability failure rc: %x\n", rc);
 		goto error_free;
 	}
+
+	rc = bnxt_alloc_stats_mem(bp);
+	if (rc)
+		goto error_free;
+
 	if (bp->max_tx_rings == 0) {
 		PMD_DRV_LOG(ERR, "No TX rings available!\n");
 		rc = -EBUSY;
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 791bf4b..a69e3e3 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -3968,13 +3968,13 @@ int bnxt_hwrm_ext_port_qstats(struct bnxt *bp)
 	req.port_id = rte_cpu_to_le_16(pf->port_id);
 	if (bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS) {
 		req.tx_stat_host_addr =
-			rte_cpu_to_le_64(bp->hw_tx_port_stats_map);
+			rte_cpu_to_le_64(bp->hw_tx_port_stats_ext_map);
 		req.tx_stat_size =
 			rte_cpu_to_le_16(sizeof(struct tx_port_stats_ext));
 	}
 	if (bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS) {
 		req.rx_stat_host_addr =
-			rte_cpu_to_le_64(bp->hw_rx_port_stats_map);
+			rte_cpu_to_le_64(bp->hw_rx_port_stats_ext_map);
 		req.rx_stat_size =
 			rte_cpu_to_le_16(sizeof(struct rx_port_stats_ext));
 	}
-- 
2.10.1


  parent reply	other threads:[~2019-12-18  6:24 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-18  6:23 [dpdk-stable] [PATCH 18.11 00/19] bnxt patchset for 18.11 Somnath Kotur
2019-12-18  6:23 ` [dpdk-stable] [PATCH 18.11 01/19] net/bnxt: fix setting default MAC address Somnath Kotur
2019-12-18  6:23 ` [dpdk-stable] [PATCH 18.11 02/19] net/bnxt: fix error checking of FW commands Somnath Kotur
2019-12-18  6:23 ` [dpdk-stable] [PATCH 18.11 03/19] net/bnxt: fix check of address mapping Somnath Kotur
2019-12-18  6:23 ` [dpdk-stable] [PATCH 18.11 04/19] net/bnxt: fix stats errors handling Somnath Kotur
2019-12-18  6:23 ` [dpdk-stable] [PATCH 18.11 05/19] net/bnxt: move macro definitions to header file Somnath Kotur
2019-12-18  6:23 ` Somnath Kotur [this message]
2019-12-18  6:23 ` [dpdk-stable] [PATCH 18.11 07/19] net/bnxt: fix VF probe when MAC address is zero Somnath Kotur
2019-12-18  6:24 ` [dpdk-stable] [PATCH 18.11 08/19] net/bnxt: fix coding style Somnath Kotur
2019-12-18  6:24 ` [dpdk-stable] [PATCH 18.11 09/19] net/bnxt: fix async link handling and update Somnath Kotur
2019-12-18  6:24 ` [dpdk-stable] [PATCH 18.11 10/19] net/bnxt: fix flow flush handling Somnath Kotur
2019-12-18  6:24 ` [dpdk-stable] [PATCH 18.11 11/19] net/bnxt: update trusted VF status only when it changes Somnath Kotur
2019-12-18  6:24 ` [dpdk-stable] [PATCH 18.11 12/19] net/bnxt: fix doorbell register offset for Tx ring Somnath Kotur
2019-12-18  6:24 ` [dpdk-stable] [PATCH 18.11 13/19] net/bnxt: get default HWRM command timeout from FW Somnath Kotur
2019-12-18  6:24 ` [dpdk-stable] [PATCH 18.11 14/19] net/bnxt: fix MAC/VLAN filter allocation Somnath Kotur
2019-12-18  6:24 ` [dpdk-stable] [PATCH 18.11 15/19] net/bnxt: fix forwarding with higher mbuf size Somnath Kotur
2019-12-18  6:24 ` [dpdk-stable] [PATCH 18.11 16/19] net/bnxt: fix crash after removing and adding slaves Somnath Kotur
2019-12-18  6:24 ` [dpdk-stable] [PATCH 18.11 17/19] net/bnxt: fix Rx queue count Somnath Kotur
2019-12-18  6:24 ` [dpdk-stable] [PATCH 18.11 18/19] net/bnxt: fix deferred start of Tx queues Somnath Kotur
2019-12-18 10:21   ` Kevin Traynor
2019-12-18  6:24 ` [dpdk-stable] [PATCH 18.11 19/19] net/bnxt: fix rx queue start/stop Somnath Kotur
2019-12-18 11:22 ` [dpdk-stable] [PATCH 18.11 00/19] bnxt patchset for 18.11 Kevin Traynor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191218062411.13079-7-somnath.kotur@broadcom.com \
    --to=somnath.kotur@broadcom.com \
    --cc=ktraynor@redhat.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).