]> git.droids-corp.org - dpdk.git/commitdiff
net/hns3: extract common function to obtain revision ID
authorHuisong Li <lihuisong@huawei.com>
Sat, 22 Jan 2022 01:51:37 +0000 (09:51 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Thu, 27 Jan 2022 13:39:13 +0000 (14:39 +0100)
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>
Acked-by: Min Hu (Connor) <humin29@huawei.com>
drivers/net/hns3/hns3_common.c
drivers/net/hns3/hns3_common.h
drivers/net/hns3/hns3_ethdev.c
drivers/net/hns3/hns3_ethdev_vf.c

index 0f39d51a878ecb05bbb61409b64b966c5f776f28..dcdc609654adbfc4cd61941d8d97119602c48cdd 100644 (file)
@@ -821,3 +821,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;
+}
index a9e8a9cccfd26efd62f0b6a2abe102d1e39912c6..2994e4a269692992d04b9148b65231dc92fc9573 100644 (file)
@@ -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_ */
index aa9301c561ed5fd2f301f2fd539fc4c466589cf1..b417d55e1086b60a87d158a83c471f82cd359be2 100644 (file)
@@ -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"
@@ -2732,7 +2731,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];
@@ -2745,17 +2743,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;
index 36d860d08ac82b45981bb3affb7b009dbe447acc..a9e129288b9f3a7d50c64b2efbf68a5e9f5c743d 100644 (file)
@@ -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;