1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
8 #include <rte_bus_pci.h>
10 #include <rte_lcore.h>
11 #include <rte_mempool.h>
14 #include <rte_common.h>
15 #include <rte_rawdev.h>
16 #include <rte_rawdev_pmd.h>
18 #include "otx2_common.h"
19 #include "otx2_ep_rawdev.h"
21 static const struct rte_pci_id pci_sdp_vf_map[] = {
23 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
24 PCI_DEVID_OCTEONTX2_EP_VF)
32 otx2_sdp_rawdev_probe(struct rte_pci_driver *pci_drv __rte_unused,
33 struct rte_pci_device *pci_dev)
35 char name[RTE_RAWDEV_NAME_MAX_LEN];
36 struct sdp_device *sdpvf = NULL;
37 struct rte_rawdev *sdp_rawdev;
40 /* Single process support */
41 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
44 if (pci_dev->mem_resource[0].addr)
45 otx2_info("SDP_EP BAR0 is mapped:");
47 otx2_err("SDP_EP: Failed to map device BARs");
48 otx2_err("BAR0 %p\n BAR2 %p",
49 pci_dev->mem_resource[0].addr,
50 pci_dev->mem_resource[2].addr);
54 memset(name, 0, sizeof(name));
55 snprintf(name, RTE_RAWDEV_NAME_MAX_LEN, "SDPEP:%x:%02x.%x",
56 pci_dev->addr.bus, pci_dev->addr.devid,
57 pci_dev->addr.function);
59 /* Allocate rawdev pmd */
60 sdp_rawdev = rte_rawdev_pmd_allocate(name,
61 sizeof(struct sdp_device),
64 if (sdp_rawdev == NULL) {
65 otx2_err("SDP_EP VF rawdev allocation failed");
69 sdp_rawdev->device = &pci_dev->device;
70 sdp_rawdev->driver_name = pci_dev->driver->driver.name;
72 sdpvf = (struct sdp_device *)sdp_rawdev->dev_private;
73 sdpvf->hw_addr = pci_dev->mem_resource[0].addr;
74 sdpvf->pci_dev = pci_dev;
76 /* Discover the VF number being probed */
77 vf_id = ((pci_dev->addr.devid & 0x1F) << 3) |
78 (pci_dev->addr.function & 0x7);
81 sdpvf->vf_num = vf_id;
83 otx2_info("SDP_EP VF[%d] probe done", vf_id);
89 otx2_sdp_rawdev_remove(struct rte_pci_device *pci_dev)
91 char name[RTE_RAWDEV_NAME_MAX_LEN];
92 struct rte_rawdev *rawdev;
93 struct sdp_device *sdpvf;
95 /* Single process support */
96 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
99 if (pci_dev == NULL) {
100 otx2_err("SDP_EP:invalid pci_dev!");
105 memset(name, 0, sizeof(name));
106 snprintf(name, RTE_RAWDEV_NAME_MAX_LEN, "SDPEP:%x:%02x.%x",
107 pci_dev->addr.bus, pci_dev->addr.devid,
108 pci_dev->addr.function);
110 rawdev = rte_rawdev_pmd_get_named_dev(name);
111 if (rawdev == NULL) {
112 otx2_err("SDP_EP: invalid device name (%s)", name);
116 sdpvf = (struct sdp_device *)rawdev->dev_private;
117 otx2_info("Removing SDP_EP VF[%d] ", sdpvf->vf_num);
119 /* rte_rawdev_close is called by pmd_release */
120 return rte_rawdev_pmd_release(rawdev);
123 static struct rte_pci_driver rte_sdp_rawdev_pmd = {
124 .id_table = pci_sdp_vf_map,
125 .drv_flags = (RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA),
126 .probe = otx2_sdp_rawdev_probe,
127 .remove = otx2_sdp_rawdev_remove,
130 RTE_PMD_REGISTER_PCI(sdp_rawdev_pci_driver, rte_sdp_rawdev_pmd);
131 RTE_PMD_REGISTER_PCI_TABLE(sdp_rawdev_pci_driver, pci_sdp_vf_map);
132 RTE_PMD_REGISTER_KMOD_DEP(sdp_rawdev_pci_driver, "vfio-pci");