net/ngbe: support probe and remove
[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_devids.h"
11
12 /*
13  * The set of PCI devices this driver supports
14  */
15 static const struct rte_pci_id pci_id_ngbe_map[] = {
16         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A2) },
17         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A2S) },
18         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A4) },
19         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A4S) },
20         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL2) },
21         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL2S) },
22         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL4) },
23         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL4S) },
24         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860NCSI) },
25         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A1) },
26         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A1L) },
27         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL_W) },
28         { .vendor_id = 0, /* sentinel */ },
29 };
30
31 static int
32 eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
33 {
34         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
35
36         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
37                 return 0;
38
39         rte_eth_copy_pci_info(eth_dev, pci_dev);
40
41         return -EINVAL;
42 }
43
44 static int
45 eth_ngbe_dev_uninit(struct rte_eth_dev *eth_dev)
46 {
47         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
48                 return 0;
49
50         RTE_SET_USED(eth_dev);
51
52         return -EINVAL;
53 }
54
55 static int
56 eth_ngbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
57                 struct rte_pci_device *pci_dev)
58 {
59         return rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
60                         0, eth_dev_pci_specific_init, pci_dev,
61                         eth_ngbe_dev_init, NULL);
62 }
63
64 static int eth_ngbe_pci_remove(struct rte_pci_device *pci_dev)
65 {
66         struct rte_eth_dev *ethdev;
67
68         ethdev = rte_eth_dev_allocated(pci_dev->device.name);
69         if (ethdev == NULL)
70                 return 0;
71
72         return rte_eth_dev_destroy(ethdev, eth_ngbe_dev_uninit);
73 }
74
75 static struct rte_pci_driver rte_ngbe_pmd = {
76         .id_table = pci_id_ngbe_map,
77         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
78         .probe = eth_ngbe_pci_probe,
79         .remove = eth_ngbe_pci_remove,
80 };
81
82 RTE_PMD_REGISTER_PCI(net_ngbe, rte_ngbe_pmd);
83 RTE_PMD_REGISTER_PCI_TABLE(net_ngbe, pci_id_ngbe_map);
84 RTE_PMD_REGISTER_KMOD_DEP(net_ngbe, "* igb_uio | uio_pci_generic | vfio-pci");