1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020
11 #include <ethdev_pci.h>
13 #include "base/txgbe.h"
14 #include "txgbe_ethdev.h"
15 #include "txgbe_rxtx.h"
17 static int txgbevf_dev_close(struct rte_eth_dev *dev);
20 * The set of PCI devices this driver supports (for VF)
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 */ },
28 static const struct eth_dev_ops txgbevf_eth_dev_ops;
31 * Virtual Function device init
34 eth_txgbevf_dev_init(struct rte_eth_dev *eth_dev)
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();
40 eth_dev->dev_ops = &txgbevf_eth_dev_ops;
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
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
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);
56 /* Use default TX function if we get here */
58 "No TX queues configured yet. Using default TX function.");
61 txgbe_set_rx_function(eth_dev);
66 rte_eth_copy_pci_info(eth_dev, pci_dev);
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;
77 /* Virtual Function device uninit */
79 eth_txgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
81 PMD_INIT_FUNC_TRACE();
83 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
86 txgbevf_dev_close(eth_dev);
91 static int eth_txgbevf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
92 struct rte_pci_device *pci_dev)
94 return rte_eth_dev_pci_generic_probe(pci_dev,
95 sizeof(struct txgbe_adapter), eth_txgbevf_dev_init);
98 static int eth_txgbevf_pci_remove(struct rte_pci_device *pci_dev)
100 return rte_eth_dev_pci_generic_remove(pci_dev, eth_txgbevf_dev_uninit);
104 * virtual function driver struct
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,
114 txgbevf_dev_close(struct rte_eth_dev *dev)
116 PMD_INIT_FUNC_TRACE();
117 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
124 * dev_ops for virtual function, bare necessities for basic vf
125 * operation have been implemented
127 static const struct eth_dev_ops txgbevf_eth_dev_ops = {
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");