net/txgbe: support VF probe and remove
[dpdk.git] / drivers / net / txgbe / txgbe_ethdev_vf.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020
3  */
4
5 #include <sys/queue.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <rte_log.h>
11 #include <ethdev_pci.h>
12
13 #include "base/txgbe.h"
14 #include "txgbe_ethdev.h"
15 #include "txgbe_rxtx.h"
16
17 static int txgbevf_dev_close(struct rte_eth_dev *dev);
18
19 /*
20  * The set of PCI devices this driver supports (for VF)
21  */
22 static const struct rte_pci_id pci_id_txgbevf_map[] = {
23         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_RAPTOR_VF) },
24         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_RAPTOR_VF_HV) },
25         { .vendor_id = 0, /* sentinel */ },
26 };
27
28 static const struct eth_dev_ops txgbevf_eth_dev_ops;
29
30 /*
31  * Virtual Function device init
32  */
33 static int
34 eth_txgbevf_dev_init(struct rte_eth_dev *eth_dev)
35 {
36         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
37         struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
38         PMD_INIT_FUNC_TRACE();
39
40         eth_dev->dev_ops = &txgbevf_eth_dev_ops;
41
42         /* for secondary processes, we don't initialise any further as primary
43          * has already done this work. Only check we don't need a different
44          * RX function
45          */
46         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
47                 struct txgbe_tx_queue *txq;
48                 uint16_t nb_tx_queues = eth_dev->data->nb_tx_queues;
49                 /* TX queue function in primary, set by last queue initialized
50                  * Tx queue may not initialized by primary process
51                  */
52                 if (eth_dev->data->tx_queues) {
53                         txq = eth_dev->data->tx_queues[nb_tx_queues - 1];
54                         txgbe_set_tx_function(eth_dev, txq);
55                 } else {
56                         /* Use default TX function if we get here */
57                         PMD_INIT_LOG(NOTICE,
58                                      "No TX queues configured yet. Using default TX function.");
59                 }
60
61                 txgbe_set_rx_function(eth_dev);
62
63                 return 0;
64         }
65
66         rte_eth_copy_pci_info(eth_dev, pci_dev);
67
68         hw->device_id = pci_dev->id.device_id;
69         hw->vendor_id = pci_dev->id.vendor_id;
70         hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
71         hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
72         hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
73
74         return 0;
75 }
76
77 /* Virtual Function device uninit */
78 static int
79 eth_txgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
80 {
81         PMD_INIT_FUNC_TRACE();
82
83         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
84                 return 0;
85
86         txgbevf_dev_close(eth_dev);
87
88         return 0;
89 }
90
91 static int eth_txgbevf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
92         struct rte_pci_device *pci_dev)
93 {
94         return rte_eth_dev_pci_generic_probe(pci_dev,
95                 sizeof(struct txgbe_adapter), eth_txgbevf_dev_init);
96 }
97
98 static int eth_txgbevf_pci_remove(struct rte_pci_device *pci_dev)
99 {
100         return rte_eth_dev_pci_generic_remove(pci_dev, eth_txgbevf_dev_uninit);
101 }
102
103 /*
104  * virtual function driver struct
105  */
106 static struct rte_pci_driver rte_txgbevf_pmd = {
107         .id_table = pci_id_txgbevf_map,
108         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
109         .probe = eth_txgbevf_pci_probe,
110         .remove = eth_txgbevf_pci_remove,
111 };
112
113 static int
114 txgbevf_dev_close(struct rte_eth_dev *dev)
115 {
116         PMD_INIT_FUNC_TRACE();
117         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
118                 return 0;
119
120         return 0;
121 }
122
123 /*
124  * dev_ops for virtual function, bare necessities for basic vf
125  * operation have been implemented
126  */
127 static const struct eth_dev_ops txgbevf_eth_dev_ops = {
128 };
129
130 RTE_PMD_REGISTER_PCI(net_txgbe_vf, rte_txgbevf_pmd);
131 RTE_PMD_REGISTER_PCI_TABLE(net_txgbe_vf, pci_id_txgbevf_map);
132 RTE_PMD_REGISTER_KMOD_DEP(net_txgbe_vf, "* igb_uio | vfio-pci");