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 DF30AA0613 for ; Thu, 26 Sep 2019 16:07:37 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 738B91BF03; Thu, 26 Sep 2019 16:05:43 +0200 (CEST) Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) by dpdk.org (Postfix) with ESMTP id 42D861BE9C for ; Thu, 26 Sep 2019 16:04:58 +0200 (CEST) Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id B2E75D60BE7CB4791B96; Thu, 26 Sep 2019 22:04:53 +0800 (CST) Received: from localhost.localdomain (10.67.212.132) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Thu, 26 Sep 2019 22:04:43 +0800 From: "Wei Hu (Xavier)" To: CC: , , , Date: Thu, 26 Sep 2019 22:01:50 +0800 Message-ID: <1569506528-60464-5-git-send-email-xavier.huwei@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569506528-60464-1-git-send-email-xavier.huwei@huawei.com> References: <1569506528-60464-1-git-send-email-xavier.huwei@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.212.132] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v3 04/22] net/hns3: register hns3 PMD driver and add the log interface definition X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch registers hns3 PMD driver and adds the definition for log interfaces. Signed-off-by: Wei Hu (Xavier) Signed-off-by: Chunsong Feng Signed-off-by: Min Hu (Connor) Signed-off-by: Hao Chen Signed-off-by: Huisong Li --- v1 -> v2: Address Ferruh Yigit's comments as follows: https://inbox.dpdk.org/dev/763b0d93-3e5a-d12d-663a-65ba94189f0e@intel.com --- drivers/net/hns3/Makefile | 4 ++ drivers/net/hns3/hns3_ethdev.c | 130 +++++++++++++++++++++++++++++++++++++++++ drivers/net/hns3/hns3_logs.h | 34 +++++++++++ 3 files changed, 168 insertions(+) create mode 100644 drivers/net/hns3/hns3_logs.h diff --git a/drivers/net/hns3/Makefile b/drivers/net/hns3/Makefile index ddf3bfb..1ef0e20 100644 --- a/drivers/net/hns3/Makefile +++ b/drivers/net/hns3/Makefile @@ -11,6 +11,10 @@ LIB = librte_pmd_hns3.a CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +LDLIBS += -lrte_eal +LDLIBS += -lrte_ethdev -lrte_net +LDLIBS += -lrte_bus_pci + EXPORT_MAP := rte_pmd_hns3_version.map LIBABIVER := 1 diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c index 3f74e54..ffd2184 100644 --- a/drivers/net/hns3/hns3_ethdev.c +++ b/drivers/net/hns3/hns3_ethdev.c @@ -1,3 +1,133 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2018-2019 Hisilicon Limited. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hns3_ethdev.h" +#include "hns3_logs.h" +#include "hns3_regs.h" + +int hns3_logtype_init; +int hns3_logtype_driver; + +static void +hns3_dev_close(struct rte_eth_dev *eth_dev) +{ + struct hns3_adapter *hns = eth_dev->data->dev_private; + struct hns3_hw *hw = &hns->hw; + + hw->adapter_state = HNS3_NIC_CLOSED; +} + +static const struct eth_dev_ops hns3_eth_dev_ops = { + .dev_close = hns3_dev_close, +}; + +static int +hns3_dev_init(struct rte_eth_dev *eth_dev) +{ + struct hns3_adapter *hns = eth_dev->data->dev_private; + struct hns3_hw *hw = &hns->hw; + + PMD_INIT_FUNC_TRACE(); + + eth_dev->dev_ops = &hns3_eth_dev_ops; + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return 0; + + hns->is_vf = false; + hw->data = eth_dev->data; + hw->adapter_state = HNS3_NIC_INITIALIZED; + /* + * Pass the information to the rte_eth_dev_close() that it should also + * release the private port resources. + */ + eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE; + + return 0; +} + +static int +hns3_dev_uninit(struct rte_eth_dev *eth_dev) +{ + struct hns3_adapter *hns = eth_dev->data->dev_private; + struct hns3_hw *hw = &hns->hw; + + PMD_INIT_FUNC_TRACE(); + + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -EPERM; + + eth_dev->dev_ops = NULL; + eth_dev->rx_pkt_burst = NULL; + eth_dev->tx_pkt_burst = NULL; + eth_dev->tx_pkt_prepare = NULL; + if (hw->adapter_state < HNS3_NIC_CLOSING) + hns3_dev_close(eth_dev); + + hw->adapter_state = HNS3_NIC_REMOVED; + return 0; +} + +static int +eth_hns3_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev) +{ + return rte_eth_dev_pci_generic_probe(pci_dev, + sizeof(struct hns3_adapter), + hns3_dev_init); +} + +static int +eth_hns3_pci_remove(struct rte_pci_device *pci_dev) +{ + return rte_eth_dev_pci_generic_remove(pci_dev, hns3_dev_uninit); +} + +static const struct rte_pci_id pci_id_hns3_map[] = { + { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_GE) }, + { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_25GE) }, + { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_25GE_RDMA) }, + { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_50GE_RDMA) }, + { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_100G_RDMA_MACSEC) }, + { .vendor_id = 0, /* sentinel */ }, +}; + +static struct rte_pci_driver rte_hns3_pmd = { + .id_table = pci_id_hns3_map, + .drv_flags = RTE_PCI_DRV_NEED_MAPPING, + .probe = eth_hns3_pci_probe, + .remove = eth_hns3_pci_remove, +}; + +RTE_PMD_REGISTER_PCI(net_hns3, rte_hns3_pmd); +RTE_PMD_REGISTER_PCI_TABLE(net_hns3, pci_id_hns3_map); +RTE_PMD_REGISTER_KMOD_DEP(net_hns3, "* igb_uio | vfio-pci"); + +RTE_INIT(hns3_init_log) +{ + hns3_logtype_init = rte_log_register("pmd.net.hns3.init"); + if (hns3_logtype_init >= 0) + rte_log_set_level(hns3_logtype_init, RTE_LOG_NOTICE); + hns3_logtype_driver = rte_log_register("pmd.net.hns3.driver"); + if (hns3_logtype_driver >= 0) + rte_log_set_level(hns3_logtype_driver, RTE_LOG_NOTICE); +} diff --git a/drivers/net/hns3/hns3_logs.h b/drivers/net/hns3/hns3_logs.h new file mode 100644 index 0000000..f3fc7b5 --- /dev/null +++ b/drivers/net/hns3/hns3_logs.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018-2019 Hisilicon Limited. + */ + +#ifndef _HNS3_LOGS_H_ +#define _HNS3_LOGS_H_ + +extern int hns3_logtype_init; +#define PMD_INIT_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, hns3_logtype_init, "%s(): " fmt "\n", \ + __func__, ##args) +#define PMD_INIT_FUNC_TRACE() PMD_INIT_LOG(DEBUG, " >>") + +extern int hns3_logtype_driver; +#define PMD_DRV_LOG_RAW(hw, level, fmt, args...) \ + rte_log(level, hns3_logtype_driver, "%s %s(): " fmt, \ + (hw)->data->name, __func__, ## args) + +#define hns3_err(hw, fmt, args...) \ + PMD_DRV_LOG_RAW(hw, RTE_LOG_ERR, fmt "\n", ## args) + +#define hns3_warn(hw, fmt, args...) \ + PMD_DRV_LOG_RAW(hw, RTE_LOG_WARNING, fmt "\n", ## args) + +#define hns3_notice(hw, fmt, args...) \ + PMD_DRV_LOG_RAW(hw, RTE_LOG_NOTICE, fmt "\n", ## args) + +#define hns3_info(hw, fmt, args...) \ + PMD_DRV_LOG_RAW(hw, RTE_LOG_INFO, fmt "\n", ## args) + +#define hns3_dbg(hw, fmt, args...) \ + PMD_DRV_LOG_RAW(hw, RTE_LOG_DEBUG, fmt "\n", ## args) + +#endif /* _HNS3_LOGS_H_ */ -- 2.7.4