1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #include <ethdev_pci.h>
7 #include "otx2_common.h"
8 #include "otx_ep_common.h"
11 #define OTX_EP_DEV(_eth_dev) ((_eth_dev)->data->dev_private)
13 otx_ep_chip_specific_setup(struct otx_ep_device *otx_epvf)
15 struct rte_pci_device *pdev = otx_epvf->pdev;
16 uint32_t dev_id = pdev->id.device_id;
20 case PCI_DEVID_OCTEONTX_EP_VF:
21 otx_epvf->chip_id = dev_id;
23 case PCI_DEVID_OCTEONTX2_EP_NET_VF:
24 case PCI_DEVID_CN98XX_EP_NET_VF:
25 otx_epvf->chip_id = dev_id;
28 otx_ep_err("Unsupported device\n");
33 otx_ep_info("OTX_EP dev_id[%d]\n", dev_id);
38 /* OTX_EP VF device initialization */
40 otx_epdev_init(struct otx_ep_device *otx_epvf)
44 ret = otx_ep_chip_specific_setup(otx_epvf);
46 otx_ep_err("Chip specific setup failed\n");
55 otx_ep_eth_dev_uninit(__rte_unused struct rte_eth_dev *eth_dev)
61 otx_ep_eth_dev_init(struct rte_eth_dev *eth_dev)
63 struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(eth_dev);
64 struct otx_ep_device *otx_epvf = OTX_EP_DEV(eth_dev);
65 struct rte_ether_addr vf_mac_addr;
67 /* Single process support */
68 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
71 otx_epvf->eth_dev = eth_dev;
72 otx_epvf->port_id = eth_dev->data->port_id;
73 eth_dev->data->mac_addrs = rte_zmalloc("otx_ep", RTE_ETHER_ADDR_LEN, 0);
74 if (eth_dev->data->mac_addrs == NULL) {
75 otx_ep_err("MAC addresses memory allocation failed\n");
78 rte_eth_random_addr(vf_mac_addr.addr_bytes);
79 rte_ether_addr_copy(&vf_mac_addr, eth_dev->data->mac_addrs);
80 otx_epvf->hw_addr = pdev->mem_resource[0].addr;
81 otx_epvf->pdev = pdev;
83 otx_epdev_init(otx_epvf);
89 otx_ep_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
90 struct rte_pci_device *pci_dev)
92 return rte_eth_dev_pci_generic_probe(pci_dev,
93 sizeof(struct otx_ep_device),
98 otx_ep_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
100 return rte_eth_dev_pci_generic_remove(pci_dev,
101 otx_ep_eth_dev_uninit);
104 /* Set of PCI devices this driver supports */
105 static const struct rte_pci_id pci_id_otx_ep_map[] = {
106 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX_EP_VF) },
107 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX2_EP_NET_VF) },
108 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_CN98XX_EP_NET_VF) },
109 { .vendor_id = 0, /* sentinel */ }
112 static struct rte_pci_driver rte_otx_ep_pmd = {
113 .id_table = pci_id_otx_ep_map,
114 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
115 .probe = otx_ep_eth_dev_pci_probe,
116 .remove = otx_ep_eth_dev_pci_remove,
119 RTE_PMD_REGISTER_PCI(net_otx_ep, rte_otx_ep_pmd);
120 RTE_PMD_REGISTER_PCI_TABLE(net_otx_ep, pci_id_otx_ep_map);
121 RTE_PMD_REGISTER_KMOD_DEP(net_otx_ep, "* igb_uio | vfio-pci");
122 RTE_LOG_REGISTER(otx_net_ep_logtype, pmd.net.octeontx_ep, NOTICE);