From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6966AA034C for ; Tue, 18 Aug 2020 08:50:28 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 644681C022; Tue, 18 Aug 2020 08:50:28 +0200 (CEST) Received: from mail.chinasoftinc.com (unknown [114.113.233.8]) by dpdk.org (Postfix) with ESMTP id F0B511C032 for ; Tue, 18 Aug 2020 08:50:26 +0200 (CEST) Received: from localhost.localdomain (120.133.139.157) by INCCAS001.ito.icss (10.168.0.60) with Microsoft SMTP Server id 14.3.487.0; Tue, 18 Aug 2020 14:49:57 +0800 From: "Wei Hu (Xavier)" To: , CC: Date: Tue, 18 Aug 2020 14:49:27 +0800 Message-ID: <20200818064931.46414-7-huwei013@chinasoftinc.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200818064931.46414-1-huwei013@chinasoftinc.com> References: <20200817092532.59530-1-huwei013@chinasoftinc.com> <20200818064931.46414-1-huwei013@chinasoftinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [120.133.139.157] Subject: [dpdk-stable] [PATCH v2 06/10] net/hns3: get device capability in primary process X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 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 Sender: "stable" From: "Wei Hu (Xavier)" [ upstream commit ab2e2e34416371817a21a41fc3def231675d4487 ] This patch optimizes the code to get device capability in primary process, and moves the code of getting PCI revision id in order to avoid evaluating the private hw->revision of shared PMD-specific private data in slave process. Signed-off-by: Wei Hu (Xavier) Signed-off-by: Huisong Li Signed-off-by: Chengwen Feng Signed-off-by: Chengchang Tang --- drivers/net/hns3/hns3_ethdev.c | 46 +++++++++++++++++++++++++------ drivers/net/hns3/hns3_ethdev.h | 4 +-- drivers/net/hns3/hns3_ethdev_vf.c | 30 ++++++++++++++++++++ 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c index 217aea4c0..ece02d440 100644 --- a/drivers/net/hns3/hns3_ethdev.c +++ b/drivers/net/hns3/hns3_ethdev.c @@ -2783,6 +2783,36 @@ hns3_parse_speed(int speed_cmd, uint32_t *speed) return 0; } +static int +hns3_get_capability(struct hns3_hw *hw) +{ + struct rte_pci_device *pci_dev; + struct rte_eth_dev *eth_dev; + uint16_t device_id; + uint8_t revision; + int ret; + + eth_dev = &rte_eth_devices[hw->data->port_id]; + pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); + device_id = pci_dev->id.device_id; + + if (device_id == HNS3_DEV_ID_25GE_RDMA || + device_id == HNS3_DEV_ID_50GE_RDMA || + device_id == HNS3_DEV_ID_100G_RDMA_MACSEC) + 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: %d", ret); + return -EIO; + } + hw->revision = revision; + + return 0; +} + static int hns3_get_board_configuration(struct hns3_hw *hw) { @@ -2857,6 +2887,13 @@ hns3_get_configuration(struct hns3_hw *hw) return ret; } + /* Get device capability */ + ret = hns3_get_capability(hw); + if (ret) { + PMD_INIT_LOG(ERR, "failed to get device capability: %d.", ret); + return ret; + } + /* Get pf resource */ ret = hns3_query_pf_resource(hw); if (ret) { @@ -5383,11 +5420,8 @@ static const struct hns3_reset_ops hns3_reset_ops = { static int hns3_dev_init(struct rte_eth_dev *eth_dev) { - struct rte_device *dev = eth_dev->device; - struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev); struct hns3_adapter *hns = eth_dev->data->dev_private; struct hns3_hw *hw = &hns->hw; - uint16_t device_id = pci_dev->id.device_id; int ret; PMD_INIT_FUNC_TRACE(); @@ -5425,12 +5459,6 @@ hns3_dev_init(struct rte_eth_dev *eth_dev) } hw->adapter_state = HNS3_NIC_UNINITIALIZED; - - if (device_id == HNS3_DEV_ID_25GE_RDMA || - device_id == HNS3_DEV_ID_50GE_RDMA || - device_id == HNS3_DEV_ID_100G_RDMA_MACSEC) - hns3_set_bit(hw->flag, HNS3_DEV_SUPPORT_DCB_B, 1); - hns->is_vf = false; hw->data = eth_dev->data; diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h index 35e64aa5a..6b2cebe22 100644 --- a/drivers/net/hns3/hns3_ethdev.h +++ b/drivers/net/hns3/hns3_ethdev.h @@ -389,7 +389,7 @@ struct hns3_hw { uint16_t alloc_rss_size; /* RX queue number per TC */ uint16_t tx_qnum_per_tc; /* TX queue number per TC */ - uint32_t flag; + uint32_t capability; struct hns3_port_base_vlan_config port_base_vlan_cfg; /* @@ -520,7 +520,7 @@ struct hns3_adapter { #define HNS3_DEV_SUPPORT_DCB_B 0x0 #define hns3_dev_dcb_supported(hw) \ - hns3_get_bit((hw)->flag, HNS3_DEV_SUPPORT_DCB_B) + hns3_get_bit((hw)->capability, HNS3_DEV_SUPPORT_DCB_B) #define HNS3_DEV_PRIVATE_TO_HW(adapter) \ (&((struct hns3_adapter *)adapter)->hw) diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c index b929fbcc8..847e4c61c 100644 --- a/drivers/net/hns3/hns3_ethdev_vf.c +++ b/drivers/net/hns3/hns3_ethdev_vf.c @@ -940,6 +940,29 @@ hns3vf_interrupt_handler(void *param) hns3vf_enable_irq0(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: %d", ret); + return -EIO; + } + hw->revision = revision; + + return 0; +} + static int hns3vf_check_tqp_info(struct hns3_hw *hw) { @@ -1026,6 +1049,13 @@ hns3vf_get_configuration(struct hns3_hw *hw) hw->mac.media_type = HNS3_MEDIA_TYPE_NONE; hw->rss_dis_flag = false; + /* Get device capability */ + ret = hns3vf_get_capability(hw); + if (ret) { + PMD_INIT_LOG(ERR, "failed to get device capability: %d.", ret); + return ret; + } + /* Get queue configuration from PF */ ret = hns3vf_get_queue_info(hw); if (ret) -- 2.27.0