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 54E1FA04DC; Mon, 19 Oct 2020 10:52:57 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2B099C7EA; Mon, 19 Oct 2020 10:52:39 +0200 (CEST) Received: from smtpproxy21.qq.com (smtpbg704.qq.com [203.205.195.105]) by dpdk.org (Postfix) with ESMTP id C4B35BE4D for ; Mon, 19 Oct 2020 10:52:34 +0200 (CEST) X-QQ-mid: bizesmtp6t1603097549tv0h132wy Received: from localhost.localdomain.com (unknown [183.129.236.74]) by esmtp6.qq.com (ESMTP) with id ; Mon, 19 Oct 2020 16:52:29 +0800 (CST) X-QQ-SSF: 01400000002000C0C000B00A0000000 X-QQ-FEAT: Me8y4DzRu2TZuxV/lVPfrXK6H7bePoZdHjluvtYEoXq8ST9fvUfO+8EtlsKt1 USlhZLkoDOcNYO67SYfRti84l/kYodgSZRijccN8jbhA/N7kQS1Lhyuq+F8Piu+KG6y1kvs 8xFNJaNdyGZ+BmhGOUA2d52d0C9SxMIPQI4EYsKhj1FMT6qteVSZJIdie92TGvubFuXeDYs mY3wjiI/lSzEX0j65vwAIU0WABSul26auL3MnkajuDRdGzdEocqbHcjd0L9ZkpeMJPquJij sBjZx0IfhgzWLW5yFF4n8S8rk7CuNdlYHcymxQYmt2dxuuCuKX6LcES6Ns6KDcxqLY6wLG9 hU+i8OBx9gBgeH7sPbhWF4Ss53hHg== X-QQ-GoodBg: 2 From: Jiawen Wu To: dev@dpdk.org Cc: jiawenwu Date: Mon, 19 Oct 2020 16:53:19 +0800 Message-Id: <20201019085415.82207-3-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201019085415.82207-1-jiawenwu@trustnetic.com> References: <20201019085415.82207-1-jiawenwu@trustnetic.com> X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybgforeign:qybgforeign7 X-QQ-Bgrelay: 1 Subject: [dpdk-dev] [PATCH v4 02/58] net/txgbe: add ethdev probe and remove 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" From: jiawenwu Add basic PCIe ethdev probe and remove. Signed-off-by: Jiawen Wu --- drivers/net/txgbe/base/meson.build | 18 +++++ drivers/net/txgbe/base/txgbe.h | 10 +++ drivers/net/txgbe/base/txgbe_devids.h | 40 ++++++++++ drivers/net/txgbe/base/txgbe_type.h | 14 ++++ drivers/net/txgbe/meson.build | 4 + drivers/net/txgbe/txgbe_ethdev.c | 101 ++++++++++++++++++++++++++ drivers/net/txgbe/txgbe_ethdev.h | 13 ++++ drivers/net/txgbe/txgbe_logs.h | 54 ++++++++++++++ 8 files changed, 254 insertions(+) create mode 100644 drivers/net/txgbe/base/meson.build create mode 100644 drivers/net/txgbe/base/txgbe.h create mode 100644 drivers/net/txgbe/base/txgbe_devids.h create mode 100644 drivers/net/txgbe/base/txgbe_type.h create mode 100644 drivers/net/txgbe/txgbe_logs.h diff --git a/drivers/net/txgbe/base/meson.build b/drivers/net/txgbe/base/meson.build new file mode 100644 index 000000000..a0f65b819 --- /dev/null +++ b/drivers/net/txgbe/base/meson.build @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2015-2020 + +sources = [] + +error_cflags = [] + +c_args = cflags +foreach flag: error_cflags + if cc.has_argument(flag) + c_args += flag + endif +endforeach + +base_lib = static_library('txgbe_base', sources, + dependencies: static_rte_eal, + c_args: c_args) +base_objs = base_lib.extract_all_objects() diff --git a/drivers/net/txgbe/base/txgbe.h b/drivers/net/txgbe/base/txgbe.h new file mode 100644 index 000000000..9aee9738a --- /dev/null +++ b/drivers/net/txgbe/base/txgbe.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2015-2020 + */ + +#ifndef _TXGBE_H_ +#define _TXGBE_H_ + +#include "txgbe_type.h" + +#endif /* _TXGBE_H_ */ diff --git a/drivers/net/txgbe/base/txgbe_devids.h b/drivers/net/txgbe/base/txgbe_devids.h new file mode 100644 index 000000000..744f2f3b5 --- /dev/null +++ b/drivers/net/txgbe/base/txgbe_devids.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2015-2020 + */ + +#ifndef _TXGBE_DEVIDS_H_ +#define _TXGBE_DEVIDS_H_ + +/* + * Vendor ID + */ +#ifndef PCI_VENDOR_ID_WANGXUN +#define PCI_VENDOR_ID_WANGXUN 0x8088 +#endif + +/* + * Device IDs + */ +#define TXGBE_DEV_ID_RAPTOR_VF 0x1000 +#define TXGBE_DEV_ID_RAPTOR_SFP 0x1001 /* fiber */ +#define TXGBE_DEV_ID_RAPTOR_KR_KX_KX4 0x1002 /* backplane */ +#define TXGBE_DEV_ID_RAPTOR_XAUI 0x1003 /* copper */ +#define TXGBE_DEV_ID_RAPTOR_SGMII 0x1004 /* copper */ +#define TXGBE_DEV_ID_RAPTOR_QSFP 0x1011 /* fiber */ +#define TXGBE_DEV_ID_RAPTOR_VF_HV 0x2000 +#define TXGBE_DEV_ID_RAPTOR_T3_LOM 0x2001 + +#define TXGBE_DEV_ID_WX1820_SFP 0x2001 + +/* + * Subdevice IDs + */ +#define TXGBE_SUBDEV_ID_RAPTOR 0x0000 +#define TXGBE_SUBDEV_ID_MPW 0x0001 + +#define TXGBE_ETHERTYPE_FLOW_CTRL 0x8808 +#define TXGBE_ETHERTYPE_IEEE_VLAN 0x8100 /* 802.1q protocol */ + +#define TXGBE_VXLAN_PORT 4789 + +#endif /* _TXGBE_DEVIDS_H_ */ diff --git a/drivers/net/txgbe/base/txgbe_type.h b/drivers/net/txgbe/base/txgbe_type.h new file mode 100644 index 000000000..8ed324a1b --- /dev/null +++ b/drivers/net/txgbe/base/txgbe_type.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2015-2020 + */ + +#ifndef _TXGBE_TYPE_H_ +#define _TXGBE_TYPE_H_ + +#include "txgbe_devids.h" + +struct txgbe_hw { + void *back; +}; + +#endif /* _TXGBE_TYPE_H_ */ diff --git a/drivers/net/txgbe/meson.build b/drivers/net/txgbe/meson.build index d5b19af31..295f39296 100644 --- a/drivers/net/txgbe/meson.build +++ b/drivers/net/txgbe/meson.build @@ -1,7 +1,11 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2015-2020 +subdir('base') +objs = [base_objs] + sources = files( 'txgbe_ethdev.c', ) +includes += include_directories('base') diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c index cb758762d..e2fd10cc2 100644 --- a/drivers/net/txgbe/txgbe_ethdev.c +++ b/drivers/net/txgbe/txgbe_ethdev.c @@ -2,3 +2,104 @@ * Copyright(c) 2015-2020 */ +#include +#include +#include + +#include "txgbe_logs.h" +#include "base/txgbe.h" +#include "txgbe_ethdev.h" + +/* + * The set of PCI devices this driver supports + */ +static const struct rte_pci_id pci_id_txgbe_map[] = { + { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_RAPTOR_SFP) }, + { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_WX1820_SFP) }, + { .vendor_id = 0, /* sentinel */ }, +}; + +static int +eth_txgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused) +{ + RTE_SET_USED(eth_dev); + + return 0; +} + +static int +eth_txgbe_dev_uninit(struct rte_eth_dev *eth_dev) +{ + RTE_SET_USED(eth_dev); + + return 0; +} + +static int +eth_txgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev) +{ + struct rte_eth_dev *pf_ethdev; + struct rte_eth_devargs eth_da; + int retval; + + if (pci_dev->device.devargs) { + retval = rte_eth_devargs_parse(pci_dev->device.devargs->args, + ð_da); + if (retval) + return retval; + } else { + memset(ð_da, 0, sizeof(eth_da)); + } + + retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name, + sizeof(struct txgbe_adapter), + eth_dev_pci_specific_init, pci_dev, + eth_txgbe_dev_init, NULL); + + if (retval || eth_da.nb_representor_ports < 1) + return retval; + + pf_ethdev = rte_eth_dev_allocated(pci_dev->device.name); + if (pf_ethdev == NULL) + return -ENODEV; + + return 0; +} + +static int eth_txgbe_pci_remove(struct rte_pci_device *pci_dev) +{ + struct rte_eth_dev *ethdev; + + ethdev = rte_eth_dev_allocated(pci_dev->device.name); + if (!ethdev) + return -ENODEV; + + return rte_eth_dev_destroy(ethdev, eth_txgbe_dev_uninit); +} + +static struct rte_pci_driver rte_txgbe_pmd = { + .id_table = pci_id_txgbe_map, + .drv_flags = RTE_PCI_DRV_NEED_MAPPING | + RTE_PCI_DRV_INTR_LSC, + .probe = eth_txgbe_pci_probe, + .remove = eth_txgbe_pci_remove, +}; + +RTE_PMD_REGISTER_PCI(net_txgbe, rte_txgbe_pmd); +RTE_PMD_REGISTER_PCI_TABLE(net_txgbe, pci_id_txgbe_map); +RTE_PMD_REGISTER_KMOD_DEP(net_txgbe, "* igb_uio | uio_pci_generic | vfio-pci"); + +RTE_LOG_REGISTER(txgbe_logtype_init, pmd.net.txgbe.init, NOTICE); +RTE_LOG_REGISTER(txgbe_logtype_driver, pmd.net.txgbe.driver, NOTICE); + +#ifdef RTE_LIBRTE_TXGBE_DEBUG_RX + RTE_LOG_REGISTER(txgbe_logtype_rx, pmd.net.txgbe.rx, DEBUG); +#endif +#ifdef RTE_LIBRTE_TXGBE_DEBUG_TX + RTE_LOG_REGISTER(txgbe_logtype_tx, pmd.net.txgbe.tx, DEBUG); +#endif + +#ifdef RTE_LIBRTE_TXGBE_DEBUG_TX_FREE + RTE_LOG_REGISTER(txgbe_logtype_tx_free, pmd.net.txgbe.tx_free, DEBUG); +#endif diff --git a/drivers/net/txgbe/txgbe_ethdev.h b/drivers/net/txgbe/txgbe_ethdev.h index cb758762d..8581da457 100644 --- a/drivers/net/txgbe/txgbe_ethdev.h +++ b/drivers/net/txgbe/txgbe_ethdev.h @@ -2,3 +2,16 @@ * Copyright(c) 2015-2020 */ +#ifndef _TXGBE_ETHDEV_H_ +#define _TXGBE_ETHDEV_H_ + +#include "base/txgbe.h" + +/* + * Structure to store private data for each driver instance (for each port). + */ +struct txgbe_adapter { + struct txgbe_hw hw; +}; + +#endif /* _TXGBE_ETHDEV_H_ */ diff --git a/drivers/net/txgbe/txgbe_logs.h b/drivers/net/txgbe/txgbe_logs.h new file mode 100644 index 000000000..f44ca06ee --- /dev/null +++ b/drivers/net/txgbe/txgbe_logs.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2015-2020 + */ + +#ifndef _TXGBE_LOGS_H_ +#define _TXGBE_LOGS_H_ + +/* + * PMD_USER_LOG: for user + */ +extern int txgbe_logtype_init; +#define PMD_INIT_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, txgbe_logtype_init, \ + "%s(): " fmt "\n", __func__, ##args) + +extern int txgbe_logtype_driver; +#define PMD_DRV_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, txgbe_logtype_driver, \ + "%s(): " fmt "\n", __func__, ##args) + +#ifdef RTE_LIBRTE_TXGBE_DEBUG_RX +extern int txgbe_logtype_rx; +#define PMD_RX_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, txgbe_logtype_rx, \ + "%s(): " fmt "\n", __func__, ##args) +#else +#define PMD_RX_LOG(level, fmt, args...) do { } while (0) +#endif + +#ifdef RTE_LIBRTE_TXGBE_DEBUG_TX +extern int txgbe_logtype_tx; +#define PMD_TX_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, txgbe_logtype_tx, \ + "%s(): " fmt "\n", __func__, ##args) +#else +#define PMD_TX_LOG(level, fmt, args...) do { } while (0) +#endif + +#ifdef RTE_LIBRTE_TXGBE_DEBUG_TX_FREE +extern int txgbe_logtype_tx_free; +#define PMD_TX_FREE_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, txgbe_logtype_tx_free, \ + "%s(): " fmt "\n", __func__, ##args) +#else +#define PMD_TX_FREE_LOG(level, fmt, args...) do { } while (0) +#endif + +#define TLOG_DEBUG(fmt, args...) PMD_DRV_LOG(DEBUG, fmt, ##args) + +#define DEBUGOUT(fmt, args...) TLOG_DEBUG(fmt, ##args) +#define PMD_INIT_FUNC_TRACE() TLOG_DEBUG(" >>") +#define DEBUGFUNC(fmt) TLOG_DEBUG(fmt) + +#endif /* _TXGBE_LOGS_H_ */ -- 2.18.4