Message ID | 20220527063157.486686-1-jiawenwu@trustnetic.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net-next,v3] net: txgbe: Add build support for txgbe | expand |
Hi Jiawen, I love your patch! Perhaps something to improve: [auto build test WARNING on net-next/master] url: https://github.com/intel-lab-lkp/linux/commits/Jiawen-Wu/net-txgbe-Add-build-support-for-txgbe/20220527-143401 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 7e062cda7d90543ac8c7700fc7c5527d0c0f22ad config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20220527/202205271506.b3ILwQFq-lkp@intel.com/config) compiler: arceb-elf-gcc (GCC) 11.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/b2d691a438052d44a1ec82c4b9e23ecf5514a579 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Jiawen-Wu/net-txgbe-Add-build-support-for-txgbe/20220527-143401 git checkout b2d691a438052d44a1ec82c4b9e23ecf5514a579 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash drivers/net/ethernet/wangxun/txgbe/ If you fix the issue, kindly add following tag where applicable Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): drivers/net/ethernet/wangxun/txgbe/txgbe_main.c: In function 'txgbe_probe': >> drivers/net/ethernet/wangxun/txgbe/txgbe_main.c:93:26: warning: variable 'hw' set but not used [-Wunused-but-set-variable] 93 | struct txgbe_hw *hw = NULL; | ^~ vim +/hw +93 drivers/net/ethernet/wangxun/txgbe/txgbe_main.c 77 78 /** 79 * txgbe_probe - Device Initialization Routine 80 * @pdev: PCI device information struct 81 * @ent: entry in txgbe_pci_tbl 82 * 83 * Returns 0 on success, negative on failure 84 * 85 * txgbe_probe initializes an adapter identified by a pci_dev structure. 86 * The OS initialization, configuring of the adapter private structure, 87 * and a hardware reset occur. 88 **/ 89 static int txgbe_probe(struct pci_dev *pdev, 90 const struct pci_device_id __always_unused *ent) 91 { 92 struct txgbe_adapter *adapter = NULL; > 93 struct txgbe_hw *hw = NULL; 94 struct net_device *netdev; 95 int err, pci_using_dac; 96 97 err = pci_enable_device_mem(pdev); 98 if (err) 99 return err; 100 101 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && 102 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { 103 pci_using_dac = 1; 104 } else { 105 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); 106 if (err) { 107 err = dma_set_coherent_mask(&pdev->dev, 108 DMA_BIT_MASK(32)); 109 if (err) { 110 dev_err(&pdev->dev, 111 "No usable DMA configuration, aborting\n"); 112 goto err_dma; 113 } 114 } 115 pci_using_dac = 0; 116 } 117 118 err = pci_request_selected_regions(pdev, 119 pci_select_bars(pdev, IORESOURCE_MEM), 120 txgbe_driver_name); 121 if (err) { 122 dev_err(&pdev->dev, 123 "pci_request_selected_regions failed 0x%x\n", err); 124 goto err_pci_reg; 125 } 126 127 pci_enable_pcie_error_reporting(pdev); 128 pci_set_master(pdev); 129 /* errata 16 */ 130 pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL, 131 PCI_EXP_DEVCTL_READRQ, 132 0x1000); 133 134 netdev = devm_alloc_etherdev_mqs(&pdev->dev, 135 sizeof(struct txgbe_adapter), 136 TXGBE_MAX_TX_QUEUES, 137 TXGBE_MAX_RX_QUEUES); 138 if (!netdev) { 139 err = -ENOMEM; 140 goto err_alloc_etherdev; 141 } 142 143 SET_NETDEV_DEV(netdev, &pdev->dev); 144 145 adapter = netdev_priv(netdev); 146 adapter->netdev = netdev; 147 adapter->pdev = pdev; 148 hw = &adapter->hw; 149 150 adapter->io_addr = devm_ioremap(&pdev->dev, 151 pci_resource_start(pdev, 0), 152 pci_resource_len(pdev, 0)); 153 if (!adapter->io_addr) { 154 err = -EIO; 155 goto err_ioremap; 156 } 157 158 /* setup the private structure */ 159 err = txgbe_sw_init(adapter); 160 if (err) 161 goto err_sw_init; 162 163 if (pci_using_dac) 164 netdev->features |= NETIF_F_HIGHDMA; 165 166 pci_set_drvdata(pdev, adapter); 167 168 return 0; 169 170 err_sw_init: 171 devm_iounmap(&pdev->dev, adapter->io_addr); 172 err_ioremap: 173 err_alloc_etherdev: 174 pci_release_selected_regions(pdev, 175 pci_select_bars(pdev, IORESOURCE_MEM)); 176 err_pci_reg: 177 err_dma: 178 pci_disable_device(pdev); 179 return err; 180 } 181
On Fri, May 27, 2022 at 02:31:57PM +0800, Jiawen Wu wrote: > Add doc build infrastructure for txgbe driver. > Initialize PCI memory space for WangXun 10 Gigabit Ethernet devices. > > Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com> > --- > .../device_drivers/ethernet/index.rst | 1 + > .../device_drivers/ethernet/wangxun/txgbe.rst | 20 ++ > MAINTAINERS | 7 + > drivers/net/ethernet/Kconfig | 1 + > drivers/net/ethernet/Makefile | 1 + > drivers/net/ethernet/wangxun/Kconfig | 32 +++ > drivers/net/ethernet/wangxun/Makefile | 6 + > drivers/net/ethernet/wangxun/txgbe/Makefile | 9 + > drivers/net/ethernet/wangxun/txgbe/txgbe.h | 27 ++ > .../net/ethernet/wangxun/txgbe/txgbe_main.c | 241 ++++++++++++++++++ > .../net/ethernet/wangxun/txgbe/txgbe_type.h | 65 +++++ > 11 files changed, 410 insertions(+) > create mode 100644 Documentation/networking/device_drivers/ethernet/wangxun/txgbe.rst > create mode 100644 drivers/net/ethernet/wangxun/Kconfig > create mode 100644 drivers/net/ethernet/wangxun/Makefile > create mode 100644 drivers/net/ethernet/wangxun/txgbe/Makefile > create mode 100644 drivers/net/ethernet/wangxun/txgbe/txgbe.h > create mode 100644 drivers/net/ethernet/wangxun/txgbe/txgbe_main.c > create mode 100644 drivers/net/ethernet/wangxun/txgbe/txgbe_type.h <...> > +/** > + * txgbe_sw_init - Initialize general software structures (struct txgbe_adapter) > + * @adapter: board private structure to initialize > + * > + * txgbe_sw_init initializes the Adapter private data structure. > + * Fields are initialized based on PCI device information and > + * OS network device settings (MTU size). > + **/ > +static int txgbe_sw_init(struct txgbe_adapter *adapter) > +{ > + struct txgbe_hw *hw = &adapter->hw; > + struct pci_dev *pdev = adapter->pdev; > + > + /* PCI config space info */ > + hw->vendor_id = pdev->vendor; > + hw->device_id = pdev->device; > + hw->revision_id = pdev->revision; > + hw->subsystem_vendor_id = pdev->subsystem_vendor; > + hw->subsystem_device_id = pdev->subsystem_device; > + > + return 0; > +} You are setting this data, but not using it. I'm not sure that to cache this data is even correct thing to do in a first place. > + <...> > + pci_set_master(pdev); > + /* errata 16 */ > + pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL, > + PCI_EXP_DEVCTL_READRQ, > + 0x1000); Why do you need this in probe function and not as PCI quirk? Thanks
> + > +err_sw_init: > + devm_iounmap(&pdev->dev, adapter->io_addr); You should not need this. That is the point of the devm_ API, it gets released automatically either when probe fails, or after the release method is called. > +static struct pci_driver txgbe_driver = { > + .name = txgbe_driver_name, > + .id_table = txgbe_pci_tbl, > + .probe = txgbe_probe, > + .remove = txgbe_remove, > + .shutdown = txgbe_shutdown, > +}; > + > +/** > + * txgbe_init_module - Driver Registration Routine > + * > + * txgbe_init_module is the first routine called when the driver is > + * loaded. All it does is register with the PCI subsystem. > + **/ > +static int __init txgbe_init_module(void) > +{ > + int ret; > + > + ret = pci_register_driver(&txgbe_driver); > + return ret; > +} > + > +module_init(txgbe_init_module); > + > +/** > + * txgbe_exit_module - Driver Exit Cleanup Routine > + * > + * txgbe_exit_module is called just before the driver is removed > + * from memory. > + **/ > +static void __exit txgbe_exit_module(void) > +{ > + pci_unregister_driver(&txgbe_driver); > +} It looks like you should be able to use module_pci_driver(). Andrew
On Mon, May 30, 2022 at 02:17:08PM +0800, Jiawen Wu wrote: > On Saturday, May 28, 2022 12:45 AM, Leon Romanovsky wrote: > > On Fri, May 27, 2022 at 02:31:57PM +0800, Jiawen Wu wrote: > > > Add doc build infrastructure for txgbe driver. > > > Initialize PCI memory space for WangXun 10 Gigabit Ethernet devices. > > > > > > Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com> > > > --- > > > .../device_drivers/ethernet/index.rst | 1 + > > > .../device_drivers/ethernet/wangxun/txgbe.rst | 20 ++ > > > MAINTAINERS | 7 + > > > drivers/net/ethernet/Kconfig | 1 + > > > drivers/net/ethernet/Makefile | 1 + > > > drivers/net/ethernet/wangxun/Kconfig | 32 +++ > > > drivers/net/ethernet/wangxun/Makefile | 6 + > > > drivers/net/ethernet/wangxun/txgbe/Makefile | 9 + > > > drivers/net/ethernet/wangxun/txgbe/txgbe.h | 27 ++ > > > .../net/ethernet/wangxun/txgbe/txgbe_main.c | 241 > > ++++++++++++++++++ > > > .../net/ethernet/wangxun/txgbe/txgbe_type.h | 65 +++++ > > > 11 files changed, 410 insertions(+) > > > create mode 100644 > > > Documentation/networking/device_drivers/ethernet/wangxun/txgbe.rst > > > create mode 100644 drivers/net/ethernet/wangxun/Kconfig > > > create mode 100644 drivers/net/ethernet/wangxun/Makefile > > > create mode 100644 drivers/net/ethernet/wangxun/txgbe/Makefile > > > create mode 100644 drivers/net/ethernet/wangxun/txgbe/txgbe.h > > > create mode 100644 drivers/net/ethernet/wangxun/txgbe/txgbe_main.c > > > create mode 100644 drivers/net/ethernet/wangxun/txgbe/txgbe_type.h > > > > <...> > > > > > + pci_set_master(pdev); > > > + /* errata 16 */ > > > + pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL, > > > + PCI_EXP_DEVCTL_READRQ, > > > + 0x1000); > > > > Why do you need this in probe function and not as PCI quirk? > > > > It is necessary to set read request size 256 bytes for us. > Otherwise, some PCI exception issues may occur. It is not what I asked. I would expect such code in PCI quirk and not in probe function. Thanks > > > >
diff --git a/Documentation/networking/device_drivers/ethernet/index.rst b/Documentation/networking/device_drivers/ethernet/index.rst index 6b5dc203da2b..4766ac9d260e 100644 --- a/Documentation/networking/device_drivers/ethernet/index.rst +++ b/Documentation/networking/device_drivers/ethernet/index.rst @@ -52,6 +52,7 @@ Contents: ti/am65_nuss_cpsw_switchdev ti/tlan toshiba/spider_net + wangxun/txgbe .. only:: subproject and html diff --git a/Documentation/networking/device_drivers/ethernet/wangxun/txgbe.rst b/Documentation/networking/device_drivers/ethernet/wangxun/txgbe.rst new file mode 100644 index 000000000000..eaa87dbe8848 --- /dev/null +++ b/Documentation/networking/device_drivers/ethernet/wangxun/txgbe.rst @@ -0,0 +1,20 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================================================================ +Linux Base Driver for WangXun(R) 10 Gigabit PCI Express Adapters +================================================================ + +WangXun 10 Gigabit Linux driver. +Copyright (c) 2015 - 2022 Beijing WangXun Technology Co., Ltd. + + +Contents +======== + +- Support + + +Support +======= +If you got any problem, contact Wangxun support team via support@trustnetic.com +and Cc: netdev. diff --git a/MAINTAINERS b/MAINTAINERS index f468864fd268..a18a7ea9e671 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21208,6 +21208,13 @@ L: linux-input@vger.kernel.org S: Maintained F: drivers/input/tablet/wacom_serial4.c +WANGXUN ETHERNET DRIVER +M: Jiawen Wu <jiawenwu@trustnetic.com> +L: netdev@vger.kernel.org +S: Maintained +F: Documentation/networking/device_drivers/ethernet/wangxun/txgbe.rst +F: drivers/net/ethernet/wangxun/ + WATCHDOG DEVICE DRIVERS M: Wim Van Sebroeck <wim@linux-watchdog.org> M: Guenter Roeck <linux@roeck-us.net> diff --git a/drivers/net/ethernet/Kconfig b/drivers/net/ethernet/Kconfig index 827993022386..e505cb1c171b 100644 --- a/drivers/net/ethernet/Kconfig +++ b/drivers/net/ethernet/Kconfig @@ -84,6 +84,7 @@ source "drivers/net/ethernet/huawei/Kconfig" source "drivers/net/ethernet/i825xx/Kconfig" source "drivers/net/ethernet/ibm/Kconfig" source "drivers/net/ethernet/intel/Kconfig" +source "drivers/net/ethernet/wangxun/Kconfig" source "drivers/net/ethernet/xscale/Kconfig" config JME diff --git a/drivers/net/ethernet/Makefile b/drivers/net/ethernet/Makefile index 8ef43e0c33c0..82db3b15e421 100644 --- a/drivers/net/ethernet/Makefile +++ b/drivers/net/ethernet/Makefile @@ -96,6 +96,7 @@ obj-$(CONFIG_NET_VENDOR_TOSHIBA) += toshiba/ obj-$(CONFIG_NET_VENDOR_TUNDRA) += tundra/ obj-$(CONFIG_NET_VENDOR_VERTEXCOM) += vertexcom/ obj-$(CONFIG_NET_VENDOR_VIA) += via/ +obj-$(CONFIG_NET_VENDOR_WANGXUN) += wangxun/ obj-$(CONFIG_NET_VENDOR_WIZNET) += wiznet/ obj-$(CONFIG_NET_VENDOR_XILINX) += xilinx/ obj-$(CONFIG_NET_VENDOR_XIRCOM) += xircom/ diff --git a/drivers/net/ethernet/wangxun/Kconfig b/drivers/net/ethernet/wangxun/Kconfig new file mode 100644 index 000000000000..baa1f0a5cc37 --- /dev/null +++ b/drivers/net/ethernet/wangxun/Kconfig @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Wangxun network device configuration +# + +config NET_VENDOR_WANGXUN + bool "Wangxun devices" + default y + help + If you have a network (Ethernet) card belonging to this class, say Y. + + Note that the answer to this question doesn't directly affect the + kernel: saying N will just cause the configurator to skip all + the questions about Intel cards. If you say Y, you will be asked for + your specific card in the following questions. + +if NET_VENDOR_WANGXUN + +config TXGBE + tristate "Wangxun(R) 10GbE PCI Express adapters support" + depends on PCI + help + This driver supports Wangxun(R) 10GbE PCI Express family of + adapters. + + More specific information on configuring the driver is in + <file:Documentation/networking/device_drivers/ethernet/wangxun/txgbe.rst>. + + To compile this driver as a module, choose M here. The module + will be called txgbe. + +endif # NET_VENDOR_WANGXUN diff --git a/drivers/net/ethernet/wangxun/Makefile b/drivers/net/ethernet/wangxun/Makefile new file mode 100644 index 000000000000..c34db1bead25 --- /dev/null +++ b/drivers/net/ethernet/wangxun/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the Wangxun network device drivers. +# + +obj-$(CONFIG_TXGBE) += txgbe/ diff --git a/drivers/net/ethernet/wangxun/txgbe/Makefile b/drivers/net/ethernet/wangxun/txgbe/Makefile new file mode 100644 index 000000000000..431303ca75b4 --- /dev/null +++ b/drivers/net/ethernet/wangxun/txgbe/Makefile @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2015 - 2022 Beijing WangXun Technology Co., Ltd. +# +# Makefile for the Wangxun(R) 10GbE PCI Express ethernet driver +# + +obj-$(CONFIG_TXGBE) += txgbe.o + +txgbe-objs := txgbe_main.o diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe.h b/drivers/net/ethernet/wangxun/txgbe/txgbe.h new file mode 100644 index 000000000000..333c5a063080 --- /dev/null +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2015 - 2022 Beijing WangXun Technology Co., Ltd. */ + +#ifndef _TXGBE_H_ +#define _TXGBE_H_ + +#include "txgbe_type.h" + +#define TXGBE_MAX_FDIR_INDICES 63 + +#define TXGBE_MAX_RX_QUEUES (TXGBE_MAX_FDIR_INDICES + 1) +#define TXGBE_MAX_TX_QUEUES (TXGBE_MAX_FDIR_INDICES + 1) + +/* board specific private data structure */ +struct txgbe_adapter { + u8 __iomem *io_addr; /* Mainly for iounmap use */ + /* OS defined structs */ + struct net_device *netdev; + struct pci_dev *pdev; + + /* structs defined in txgbe_hw.h */ + struct txgbe_hw hw; +}; + +#define TXGBE_NAME "txgbe" + +#endif /* _TXGBE_H_ */ diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c new file mode 100644 index 000000000000..5f9ca9f9d591 --- /dev/null +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c @@ -0,0 +1,241 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2015 - 2022 Beijing WangXun Technology Co., Ltd. */ + +#include <linux/types.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/netdevice.h> +#include <linux/string.h> +#include <linux/aer.h> +#include <linux/etherdevice.h> + +#include "txgbe.h" + +char txgbe_driver_name[32] = TXGBE_NAME; + +/* txgbe_pci_tbl - PCI Device ID Table + * + * Wildcard entries (PCI_ANY_ID) should come last + * Last entry must be all 0s + * + * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, + * Class, Class Mask, private data (not used) } + */ +static const struct pci_device_id txgbe_pci_tbl[] = { + { PCI_VDEVICE(TRUSTNETIC, TXGBE_DEV_ID_SP1000), 0}, + { PCI_VDEVICE(TRUSTNETIC, TXGBE_DEV_ID_WX1820), 0}, + /* required last entry */ + { .device = 0 } +}; + +#define DEFAULT_DEBUG_LEVEL_SHIFT 3 + +/** + * txgbe_sw_init - Initialize general software structures (struct txgbe_adapter) + * @adapter: board private structure to initialize + * + * txgbe_sw_init initializes the Adapter private data structure. + * Fields are initialized based on PCI device information and + * OS network device settings (MTU size). + **/ +static int txgbe_sw_init(struct txgbe_adapter *adapter) +{ + struct txgbe_hw *hw = &adapter->hw; + struct pci_dev *pdev = adapter->pdev; + + /* PCI config space info */ + hw->vendor_id = pdev->vendor; + hw->device_id = pdev->device; + hw->revision_id = pdev->revision; + hw->subsystem_vendor_id = pdev->subsystem_vendor; + hw->subsystem_device_id = pdev->subsystem_device; + + return 0; +} + +static void txgbe_dev_shutdown(struct pci_dev *pdev, bool *enable_wake) +{ + struct txgbe_adapter *adapter = pci_get_drvdata(pdev); + struct net_device *netdev = adapter->netdev; + + netif_device_detach(netdev); + + pci_disable_device(pdev); +} + +static void txgbe_shutdown(struct pci_dev *pdev) +{ + bool wake; + + txgbe_dev_shutdown(pdev, &wake); + + if (system_state == SYSTEM_POWER_OFF) { + pci_wake_from_d3(pdev, wake); + pci_set_power_state(pdev, PCI_D3hot); + } +} + +/** + * txgbe_probe - Device Initialization Routine + * @pdev: PCI device information struct + * @ent: entry in txgbe_pci_tbl + * + * Returns 0 on success, negative on failure + * + * txgbe_probe initializes an adapter identified by a pci_dev structure. + * The OS initialization, configuring of the adapter private structure, + * and a hardware reset occur. + **/ +static int txgbe_probe(struct pci_dev *pdev, + const struct pci_device_id __always_unused *ent) +{ + struct txgbe_adapter *adapter = NULL; + struct txgbe_hw *hw = NULL; + struct net_device *netdev; + int err, pci_using_dac; + + err = pci_enable_device_mem(pdev); + if (err) + return err; + + if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && + !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { + pci_using_dac = 1; + } else { + err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); + if (err) { + err = dma_set_coherent_mask(&pdev->dev, + DMA_BIT_MASK(32)); + if (err) { + dev_err(&pdev->dev, + "No usable DMA configuration, aborting\n"); + goto err_dma; + } + } + pci_using_dac = 0; + } + + err = pci_request_selected_regions(pdev, + pci_select_bars(pdev, IORESOURCE_MEM), + txgbe_driver_name); + if (err) { + dev_err(&pdev->dev, + "pci_request_selected_regions failed 0x%x\n", err); + goto err_pci_reg; + } + + pci_enable_pcie_error_reporting(pdev); + pci_set_master(pdev); + /* errata 16 */ + pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL, + PCI_EXP_DEVCTL_READRQ, + 0x1000); + + netdev = devm_alloc_etherdev_mqs(&pdev->dev, + sizeof(struct txgbe_adapter), + TXGBE_MAX_TX_QUEUES, + TXGBE_MAX_RX_QUEUES); + if (!netdev) { + err = -ENOMEM; + goto err_alloc_etherdev; + } + + SET_NETDEV_DEV(netdev, &pdev->dev); + + adapter = netdev_priv(netdev); + adapter->netdev = netdev; + adapter->pdev = pdev; + hw = &adapter->hw; + + adapter->io_addr = devm_ioremap(&pdev->dev, + pci_resource_start(pdev, 0), + pci_resource_len(pdev, 0)); + if (!adapter->io_addr) { + err = -EIO; + goto err_ioremap; + } + + /* setup the private structure */ + err = txgbe_sw_init(adapter); + if (err) + goto err_sw_init; + + if (pci_using_dac) + netdev->features |= NETIF_F_HIGHDMA; + + pci_set_drvdata(pdev, adapter); + + return 0; + +err_sw_init: + devm_iounmap(&pdev->dev, adapter->io_addr); +err_ioremap: +err_alloc_etherdev: + pci_release_selected_regions(pdev, + pci_select_bars(pdev, IORESOURCE_MEM)); +err_pci_reg: +err_dma: + pci_disable_device(pdev); + return err; +} + +/** + * txgbe_remove - Device Removal Routine + * @pdev: PCI device information struct + * + * txgbe_remove is called by the PCI subsystem to alert the driver + * that it should release a PCI device. The could be caused by a + * Hot-Plug event, or because the driver is going to be removed from + * memory. + **/ +static void txgbe_remove(struct pci_dev *pdev) +{ + pci_release_selected_regions(pdev, + pci_select_bars(pdev, IORESOURCE_MEM)); + + pci_disable_pcie_error_reporting(pdev); + + pci_disable_device(pdev); +} + +static struct pci_driver txgbe_driver = { + .name = txgbe_driver_name, + .id_table = txgbe_pci_tbl, + .probe = txgbe_probe, + .remove = txgbe_remove, + .shutdown = txgbe_shutdown, +}; + +/** + * txgbe_init_module - Driver Registration Routine + * + * txgbe_init_module is the first routine called when the driver is + * loaded. All it does is register with the PCI subsystem. + **/ +static int __init txgbe_init_module(void) +{ + int ret; + + ret = pci_register_driver(&txgbe_driver); + return ret; +} + +module_init(txgbe_init_module); + +/** + * txgbe_exit_module - Driver Exit Cleanup Routine + * + * txgbe_exit_module is called just before the driver is removed + * from memory. + **/ +static void __exit txgbe_exit_module(void) +{ + pci_unregister_driver(&txgbe_driver); +} + +module_exit(txgbe_exit_module); + +MODULE_DEVICE_TABLE(pci, txgbe_pci_tbl); +MODULE_AUTHOR("Beijing WangXun Technology Co., Ltd, <software@trustnetic.com>"); +MODULE_DESCRIPTION("WangXun(R) 10 Gigabit PCI Express Network Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h new file mode 100644 index 000000000000..58f5b6867b0d --- /dev/null +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2015 - 2022 Beijing WangXun Technology Co., Ltd. */ + +#ifndef _TXGBE_TYPE_H_ +#define _TXGBE_TYPE_H_ + +#include <linux/types.h> +#include <linux/netdevice.h> + +/************ txgbe_register.h ************/ +/* Vendor ID */ +#ifndef PCI_VENDOR_ID_TRUSTNETIC +#define PCI_VENDOR_ID_TRUSTNETIC 0x8088 +#endif + +/* Device IDs */ +#define TXGBE_DEV_ID_SP1000 0x1001 +#define TXGBE_DEV_ID_WX1820 0x2001 + +/* Subsystem IDs */ +/* SFP */ +#define TXGBE_ID_SP1000_SFP 0x0000 +#define TXGBE_ID_WX1820_SFP 0x2000 +#define TXGBE_ID_SFP 0x00 + +/* copper */ +#define TXGBE_ID_SP1000_XAUI 0x1010 +#define TXGBE_ID_WX1820_XAUI 0x2010 +#define TXGBE_ID_XAUI 0x10 +#define TXGBE_ID_SP1000_SGMII 0x1020 +#define TXGBE_ID_WX1820_SGMII 0x2020 +#define TXGBE_ID_SGMII 0x20 +/* backplane */ +#define TXGBE_ID_SP1000_KR_KX_KX4 0x1030 +#define TXGBE_ID_WX1820_KR_KX_KX4 0x2030 +#define TXGBE_ID_KR_KX_KX4 0x30 +/* MAC Interface */ +#define TXGBE_ID_SP1000_MAC_XAUI 0x1040 +#define TXGBE_ID_WX1820_MAC_XAUI 0x2040 +#define TXGBE_ID_MAC_XAUI 0x40 +#define TXGBE_ID_SP1000_MAC_SGMII 0x1060 +#define TXGBE_ID_WX1820_MAC_SGMII 0x2060 +#define TXGBE_ID_MAC_SGMII 0x60 + +#define TXGBE_NCSI_SUP 0x8000 +#define TXGBE_NCSI_MASK 0x8000 +#define TXGBE_WOL_SUP 0x4000 +#define TXGBE_WOL_MASK 0x4000 +#define TXGBE_DEV_MASK 0xf0 + +/* Combined interface*/ +#define TXGBE_ID_SFI_XAUI 0x50 + +/* Revision ID */ +#define TXGBE_SP_MPW 1 + +struct txgbe_hw { + u16 device_id; + u16 vendor_id; + u16 subsystem_device_id; + u16 subsystem_vendor_id; + u8 revision_id; +}; + +#endif /* _TXGBE_TYPE_H_ */
Add doc build infrastructure for txgbe driver. Initialize PCI memory space for WangXun 10 Gigabit Ethernet devices. Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com> --- .../device_drivers/ethernet/index.rst | 1 + .../device_drivers/ethernet/wangxun/txgbe.rst | 20 ++ MAINTAINERS | 7 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/wangxun/Kconfig | 32 +++ drivers/net/ethernet/wangxun/Makefile | 6 + drivers/net/ethernet/wangxun/txgbe/Makefile | 9 + drivers/net/ethernet/wangxun/txgbe/txgbe.h | 27 ++ .../net/ethernet/wangxun/txgbe/txgbe_main.c | 241 ++++++++++++++++++ .../net/ethernet/wangxun/txgbe/txgbe_type.h | 65 +++++ 11 files changed, 410 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/wangxun/txgbe.rst create mode 100644 drivers/net/ethernet/wangxun/Kconfig create mode 100644 drivers/net/ethernet/wangxun/Makefile create mode 100644 drivers/net/ethernet/wangxun/txgbe/Makefile create mode 100644 drivers/net/ethernet/wangxun/txgbe/txgbe.h create mode 100644 drivers/net/ethernet/wangxun/txgbe/txgbe_main.c create mode 100644 drivers/net/ethernet/wangxun/txgbe/txgbe_type.h