DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Min Hu (Connor)" <humin29@huawei.com>
To: <dev@dpdk.org>
Cc: <ferruh.yigit@intel.com>, <thomas@monjalon.net>
Subject: [PATCH 11/15] net/hns3: extract a common interface to obtain revision ID
Date: Fri, 7 Jan 2022 18:15:54 +0800	[thread overview]
Message-ID: <20220107101558.39219-12-humin29@huawei.com> (raw)
In-Reply-To: <20220107101558.39219-1-humin29@huawei.com>

From: Huisong Li <lihuisong@huawei.com>

The code logic of obtaining the revision ID of PCI device is the same for
PF and VF driver. This patch extracts a common interface to do it.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/net/hns3/hns3_common.c    | 22 ++++++++++++++++++++++
 drivers/net/hns3/hns3_common.h    |  2 ++
 drivers/net/hns3/hns3_ethdev.c    | 16 ++++------------
 drivers/net/hns3/hns3_ethdev_vf.c | 21 ++++-----------------
 4 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c
index cb581bb25a..1878bedf6c 100644
--- a/drivers/net/hns3/hns3_common.c
+++ b/drivers/net/hns3/hns3_common.c
@@ -815,3 +815,25 @@ hns3_restore_rx_interrupt(struct hns3_hw *hw)
 
 	return 0;
 }
+
+int
+hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id)
+{
+	struct rte_pci_device *pci_dev;
+	struct rte_eth_dev *eth_dev;
+	uint8_t revision;
+	int ret;
+
+	eth_dev = &rte_eth_devices[hw->data->port_id];
+	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+	ret = rte_pci_read_config(pci_dev, &revision, HNS3_PCI_REVISION_ID_LEN,
+				  HNS3_PCI_REVISION_ID);
+	if (ret != HNS3_PCI_REVISION_ID_LEN) {
+		hns3_err(hw, "failed to read pci revision id, ret = %d", ret);
+		return -EIO;
+	}
+
+	*revision_id = revision;
+
+	return 0;
+}
diff --git a/drivers/net/hns3/hns3_common.h b/drivers/net/hns3/hns3_common.h
index a9e8a9cccf..2994e4a269 100644
--- a/drivers/net/hns3/hns3_common.h
+++ b/drivers/net/hns3/hns3_common.h
@@ -59,4 +59,6 @@ int hns3_map_rx_interrupt(struct rte_eth_dev *dev);
 void hns3_unmap_rx_interrupt(struct rte_eth_dev *dev);
 int hns3_restore_rx_interrupt(struct hns3_hw *hw);
 
+int hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id);
+
 #endif /* _HNS3_COMMON_H_ */
diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 1deba2a055..a4ed08b52b 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -5,7 +5,6 @@
 #include <rte_alarm.h>
 #include <rte_bus_pci.h>
 #include <ethdev_pci.h>
-#include <rte_pci.h>
 
 #include "hns3_ethdev.h"
 #include "hns3_common.h"
@@ -2738,7 +2737,6 @@ hns3_get_capability(struct hns3_hw *hw)
 	struct hns3_pf *pf = &hns->pf;
 	struct rte_eth_dev *eth_dev;
 	uint16_t device_id;
-	uint8_t revision;
 	int ret;
 
 	eth_dev = &rte_eth_devices[hw->data->port_id];
@@ -2751,17 +2749,11 @@ hns3_get_capability(struct hns3_hw *hw)
 	    device_id == HNS3_DEV_ID_200G_RDMA)
 		hns3_set_bit(hw->capability, HNS3_DEV_SUPPORT_DCB_B, 1);
 
-	/* Get PCI revision id */
-	ret = rte_pci_read_config(pci_dev, &revision, HNS3_PCI_REVISION_ID_LEN,
-				  HNS3_PCI_REVISION_ID);
-	if (ret != HNS3_PCI_REVISION_ID_LEN) {
-		PMD_INIT_LOG(ERR, "failed to read pci revision id, ret = %d",
-			     ret);
-		return -EIO;
-	}
-	hw->revision = revision;
+	ret = hns3_get_pci_revision_id(hw, &hw->revision);
+	if (ret)
+		return ret;
 
-	if (revision < PCI_REVISION_ID_HIP09_A) {
+	if (hw->revision < PCI_REVISION_ID_HIP09_A) {
 		hns3_set_default_dev_specifications(hw);
 		hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE;
 		hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_2US;
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index 0921534205..18abf9b109 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -6,7 +6,6 @@
 #include <rte_alarm.h>
 #include <ethdev_pci.h>
 #include <rte_io.h>
-#include <rte_pci.h>
 #include <rte_vfio.h>
 
 #include "hns3_ethdev.h"
@@ -810,25 +809,13 @@ hns3vf_get_push_lsc_cap(struct hns3_hw *hw)
 static int
 hns3vf_get_capability(struct hns3_hw *hw)
 {
-	struct rte_pci_device *pci_dev;
-	struct rte_eth_dev *eth_dev;
-	uint8_t revision;
 	int ret;
 
-	eth_dev = &rte_eth_devices[hw->data->port_id];
-	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-
-	/* Get PCI revision id */
-	ret = rte_pci_read_config(pci_dev, &revision, HNS3_PCI_REVISION_ID_LEN,
-				  HNS3_PCI_REVISION_ID);
-	if (ret != HNS3_PCI_REVISION_ID_LEN) {
-		PMD_INIT_LOG(ERR, "failed to read pci revision id, ret = %d",
-			     ret);
-		return -EIO;
-	}
-	hw->revision = revision;
+	ret = hns3_get_pci_revision_id(hw, &hw->revision);
+	if (ret)
+		return ret;
 
-	if (revision < PCI_REVISION_ID_HIP09_A) {
+	if (hw->revision < PCI_REVISION_ID_HIP09_A) {
 		hns3vf_set_default_dev_specifications(hw);
 		hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE;
 		hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_2US;
-- 
2.33.0


  parent reply	other threads:[~2022-01-07 10:16 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-07 10:15 [PATCH 00/15] fix and feature for hns3 PMD Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 01/15] net/hns3: remove unnecessary assignment Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 02/15] net/hns3: fix a misjudgment expression Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 03/15] net/hns3: extract a common API to initialize MAC addrs Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 04/15] net/hns3: remove unnecessary 'inline' Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 05/15] net/hns3: remove unnecessary black lines Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 06/15] net/hns3: extract a function to handle reset fail Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 07/15] net/hns3: extract functions to create RSS and FDIR flow rule Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 08/15] net/hns3: remove unused variables Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 09/15] net/hns3: remove the number of queue descriptors Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 10/15] net/hns3: remove the printing of memory addresses Min Hu (Connor)
2022-01-07 10:15 ` Min Hu (Connor) [this message]
2022-01-07 10:15 ` [PATCH 12/15] net/hns3: remove invalid encapsulation function Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 13/15] net/hns3: delete strerror invoke Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 14/15] net/hns3: rename function Min Hu (Connor)
2022-01-07 10:15 ` [PATCH 15/15] net/hns3: support indirect counter action Min Hu (Connor)
2022-01-21 17:29 ` [PATCH 00/15] fix and feature for hns3 PMD Ferruh Yigit
2022-01-22  1:52   ` Min Hu (Connor)
2022-01-22  1:51 ` [PATCH v2 " Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 01/15] net/hns3: remove unnecessary assignment Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 02/15] net/hns3: fix a misjudgment expression Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 03/15] net/hns3: extract a common API to initialize MAC addrs Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 04/15] net/hns3: remove unnecessary 'inline' Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 05/15] net/hns3: remove unnecessary black lines Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 06/15] net/hns3: extract a function to handle reset fail Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 07/15] net/hns3: remove unused variables Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 08/15] net/hns3: remove the number of queue descriptors Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 09/15] net/hns3: remove the printing of memory addresses Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 10/15] net/hns3: extract a common interface to obtain revision ID Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 11/15] net/hns3: remove invalid encapsulation function Min Hu (Connor)
2022-01-27 13:04     ` Ferruh Yigit
2022-01-22  1:51   ` [PATCH v2 12/15] net/hns3: delete strerror invoke Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 13/15] net/hns3: rename function Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 14/15] net/hns3: extract functions to create RSS and FDIR flow rule Min Hu (Connor)
2022-01-22  1:51   ` [PATCH v2 15/15] net/hns3: support indirect counter action Min Hu (Connor)
2022-01-27 12:49   ` [PATCH v2 00/15] fix and feature for hns3 PMD Ferruh Yigit
2022-01-27 13:50     ` Ferruh Yigit
2022-01-28  0:40       ` Min Hu (Connor)

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=20220107101558.39219-12-humin29@huawei.com \
    --to=humin29@huawei.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=thomas@monjalon.net \
    /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).