From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A4B90433A3 for ; Thu, 23 Nov 2023 09:05:32 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 099B942F06; Thu, 23 Nov 2023 09:05:32 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 78D7C427E8 for ; Thu, 23 Nov 2023 09:05:30 +0100 (CET) Received: from kwepemm000004.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SbVv80FsczrVP6; Thu, 23 Nov 2023 16:01:56 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by kwepemm000004.china.huawei.com (7.193.23.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 Nov 2023 16:05:24 +0800 From: Huisong Li To: , CC: , Subject: [PATCH 21.11 1/4] net/hns3: extract common function to obtain revision ID Date: Thu, 23 Nov 2023 16:05:26 +0800 Message-ID: <20231123080529.15216-2-lihuisong@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231123080529.15216-1-lihuisong@huawei.com> References: <20231123080529.15216-1-lihuisong@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm000004.china.huawei.com (7.193.23.18) X-CFilter-Loop: Reflected X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org [ upstream commit f5ed7d99cf45d550a69c1430b7c4a5623a9c774a ] 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 Acked-by: Min Hu (Connor) --- drivers/net/hns3/hns3_common.c | 22 ++++++++++++++++++++++ drivers/net/hns3/hns3_common.h | 1 + drivers/net/hns3/hns3_ethdev.c | 16 ++++------------ drivers/net/hns3/hns3_ethdev_vf.c | 21 ++++----------------- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c index 6dae69347c..8641b90f67 100644 --- a/drivers/net/hns3/hns3_common.c +++ b/drivers/net/hns3/hns3_common.c @@ -789,6 +789,28 @@ 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; +} + void hns3_set_default_dev_specifications(struct hns3_hw *hw) { diff --git a/drivers/net/hns3/hns3_common.h b/drivers/net/hns3/hns3_common.h index 1d2ca24194..47d6e34269 100644 --- a/drivers/net/hns3/hns3_common.h +++ b/drivers/net/hns3/hns3_common.h @@ -58,6 +58,7 @@ 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); void hns3_set_default_dev_specifications(struct hns3_hw *hw); int hns3_query_dev_specifications(struct hns3_hw *hw); diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c index ed85caa7bd..6ae62879b3 100644 --- a/drivers/net/hns3/hns3_ethdev.c +++ b/drivers/net/hns3/hns3_ethdev.c @@ -5,7 +5,6 @@ #include #include #include -#include #include "hns3_ethdev.h" #include "hns3_common.h" @@ -2694,7 +2693,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]; @@ -2707,21 +2705,15 @@ 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; ret = hns3_query_mac_stats_reg_num(hw); 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 a125cfbeb9..cea885d7d8 100644 --- a/drivers/net/hns3/hns3_ethdev_vf.c +++ b/drivers/net/hns3/hns3_ethdev_vf.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "hns3_ethdev.h" @@ -760,25 +759,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) { 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; -- 2.33.0