f94c5d9306912f94e41ca0e9f33766b2b2fc5da2
[dpdk.git] / drivers / net / ngbe / ngbe_ethdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
3  * Copyright(c) 2010-2017 Intel Corporation
4  */
5
6 #include <errno.h>
7 #include <rte_common.h>
8 #include <ethdev_pci.h>
9
10 #include "ngbe_logs.h"
11 #include "ngbe.h"
12 #include "ngbe_ethdev.h"
13
14 static int ngbe_dev_close(struct rte_eth_dev *dev);
15
16 /*
17  * The set of PCI devices this driver supports
18  */
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 */ },
33 };
34
35 static int
36 eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
37 {
38         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
39         struct ngbe_hw *hw = ngbe_dev_hw(eth_dev);
40         int err;
41
42         PMD_INIT_FUNC_TRACE();
43
44         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
45                 return 0;
46
47         rte_eth_copy_pci_info(eth_dev, pci_dev);
48
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;
55
56         /* Initialize the shared code (base driver) */
57         err = ngbe_init_shared_code(hw);
58         if (err != 0) {
59                 PMD_INIT_LOG(ERR, "Shared code init failed: %d", err);
60                 return -EIO;
61         }
62
63         return 0;
64 }
65
66 static int
67 eth_ngbe_dev_uninit(struct rte_eth_dev *eth_dev)
68 {
69         PMD_INIT_FUNC_TRACE();
70
71         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
72                 return 0;
73
74         ngbe_dev_close(eth_dev);
75
76         return -EINVAL;
77 }
78
79 static int
80 eth_ngbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
81                 struct rte_pci_device *pci_dev)
82 {
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);
87 }
88
89 static int eth_ngbe_pci_remove(struct rte_pci_device *pci_dev)
90 {
91         struct rte_eth_dev *ethdev;
92
93         ethdev = rte_eth_dev_allocated(pci_dev->device.name);
94         if (ethdev == NULL)
95                 return 0;
96
97         return rte_eth_dev_destroy(ethdev, eth_ngbe_dev_uninit);
98 }
99
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,
105 };
106
107 /*
108  * Reset and stop device.
109  */
110 static int
111 ngbe_dev_close(struct rte_eth_dev *dev)
112 {
113         PMD_INIT_FUNC_TRACE();
114
115         RTE_SET_USED(dev);
116
117         return -EINVAL;
118 }
119
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");
123
124 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_init, init, NOTICE);
125 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_driver, driver, NOTICE);
126
127 #ifdef RTE_ETHDEV_DEBUG_RX
128         RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_rx, rx, DEBUG);
129 #endif
130 #ifdef RTE_ETHDEV_DEBUG_TX
131         RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_tx, tx, DEBUG);
132 #endif