1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
3 * Copyright(c) 2010-2017 Intel Corporation
7 #include <rte_common.h>
8 #include <ethdev_pci.h>
10 #include "ngbe_logs.h"
12 #include "ngbe_ethdev.h"
14 static int ngbe_dev_close(struct rte_eth_dev *dev);
17 * The set of PCI devices this driver supports
19 static const struct rte_pci_id pci_id_ngbe_map[] = {
20 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A2) },
21 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A2S) },
22 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A4) },
23 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A4S) },
24 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL2) },
25 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL2S) },
26 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL4) },
27 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL4S) },
28 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860NCSI) },
29 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A1) },
30 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A1L) },
31 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL_W) },
32 { .vendor_id = 0, /* sentinel */ },
36 eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
38 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
39 struct ngbe_hw *hw = ngbe_dev_hw(eth_dev);
42 PMD_INIT_FUNC_TRACE();
44 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
47 rte_eth_copy_pci_info(eth_dev, pci_dev);
49 /* Vendor and Device ID need to be set before init of shared code */
50 hw->device_id = pci_dev->id.device_id;
51 hw->vendor_id = pci_dev->id.vendor_id;
52 hw->sub_system_id = pci_dev->id.subsystem_device_id;
53 ngbe_map_device_id(hw);
54 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
56 /* Initialize the shared code (base driver) */
57 err = ngbe_init_shared_code(hw);
59 PMD_INIT_LOG(ERR, "Shared code init failed: %d", err);
67 eth_ngbe_dev_uninit(struct rte_eth_dev *eth_dev)
69 PMD_INIT_FUNC_TRACE();
71 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
74 ngbe_dev_close(eth_dev);
80 eth_ngbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
81 struct rte_pci_device *pci_dev)
83 return rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
84 sizeof(struct ngbe_adapter),
85 eth_dev_pci_specific_init, pci_dev,
86 eth_ngbe_dev_init, NULL);
89 static int eth_ngbe_pci_remove(struct rte_pci_device *pci_dev)
91 struct rte_eth_dev *ethdev;
93 ethdev = rte_eth_dev_allocated(pci_dev->device.name);
97 return rte_eth_dev_destroy(ethdev, eth_ngbe_dev_uninit);
100 static struct rte_pci_driver rte_ngbe_pmd = {
101 .id_table = pci_id_ngbe_map,
102 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
103 .probe = eth_ngbe_pci_probe,
104 .remove = eth_ngbe_pci_remove,
108 * Reset and stop device.
111 ngbe_dev_close(struct rte_eth_dev *dev)
113 PMD_INIT_FUNC_TRACE();
120 RTE_PMD_REGISTER_PCI(net_ngbe, rte_ngbe_pmd);
121 RTE_PMD_REGISTER_PCI_TABLE(net_ngbe, pci_id_ngbe_map);
122 RTE_PMD_REGISTER_KMOD_DEP(net_ngbe, "* igb_uio | uio_pci_generic | vfio-pci");
124 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_init, init, NOTICE);
125 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_driver, driver, NOTICE);
127 #ifdef RTE_ETHDEV_DEBUG_RX
128 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_rx, rx, DEBUG);
130 #ifdef RTE_ETHDEV_DEBUG_TX
131 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_tx, tx, DEBUG);