From: Jiawen Wu Date: Mon, 19 Oct 2020 08:53:19 +0000 (+0800) Subject: net/txgbe: support probe and remove X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=7dc117068a7c7da6d0704064b4380f064b9c1020;p=dpdk.git net/txgbe: support probe and remove Add basic PCIe ethdev probe and remove. Signed-off-by: Jiawen Wu Reviewed-by: Ferruh Yigit --- diff --git a/doc/guides/nics/txgbe.rst b/doc/guides/nics/txgbe.rst index 730e1a298d..01f878ee9f 100644 --- a/doc/guides/nics/txgbe.rst +++ b/doc/guides/nics/txgbe.rst @@ -15,6 +15,47 @@ Prerequisites - Follow the DPDK :ref:`Getting Started Guide for Linux ` to setup the basic DPDK environment. +Pre-Installation Configuration +------------------------------ + +Build Options +~~~~~~~~~~~~~ + +The following build-time options may be enabled on build time using. + +``-Dc_args=`` meson argument (e.g. ``-Dc_args=-DRTE_LIBRTE_TXGBE_DEBUG_RX``). + +Please note that enabling debugging options may affect system performance. + +- ``RTE_LIBRTE_TXGBE_DEBUG_RX`` (undefined by default) + + Toggle display of receive fast path run-time messages. + +- ``RTE_LIBRTE_TXGBE_DEBUG_TX`` (undefined by default) + + Toggle display of transmit fast path run-time messages. + +- ``RTE_LIBRTE_TXGBE_DEBUG_TX_FREE`` (undefined by default) + + Toggle display of transmit descriptor clean messages. + +Dynamic Logging Parameters +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +One may leverage EAL option "--log-level" to change default levels +for the log types supported by the driver. The option is used with +an argument typically consisting of two parts separated by a colon. + +TXGBE PMD provides the following log types available for control: + +- ``pmd.net.txgbe.driver`` (default level is **notice**) + + Affects driver-wide messages unrelated to any particular devices. + +- ``pmd.net.txgbe.init`` (default level is **notice**) + + Extra logging of the messages during PMD initialization. + Driver compilation and testing ------------------------------ diff --git a/drivers/net/txgbe/base/meson.build b/drivers/net/txgbe/base/meson.build new file mode 100644 index 0000000000..a0f65b8195 --- /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 0000000000..9aee9738af --- /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 0000000000..744f2f3b5e --- /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 0000000000..8ed324a1b9 --- /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 d5b19af316..295f39296b 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 cb758762d2..e2fd10cc20 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 cb758762d2..8581da4574 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 0000000000..f44ca06ee2 --- /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_ */