summaryrefslogtreecommitdiff
path: root/drivers/raw/octeontx2_dma/otx2_dpi_rawdev.c
diff options
context:
space:
mode:
authorJerin Jacob <jerinj@marvell.com>2019-07-05 14:07:58 +0530
committerThomas Monjalon <thomas@monjalon.net>2019-07-05 12:43:30 +0200
commit185656e7c9c8e26d6b93903b35518ef7b6c0c17e (patch)
tree703e05d74a3fbebee1c514faa799651dcf023a5f /drivers/raw/octeontx2_dma/otx2_dpi_rawdev.c
parent29893042c29d83bcaf9f812f72aad2257d153508 (diff)
downloaddpdk-185656e7c9c8e26d6b93903b35518ef7b6c0c17e.zip
dpdk-185656e7c9c8e26d6b93903b35518ef7b6c0c17e.tar.gz
dpdk-185656e7c9c8e26d6b93903b35518ef7b6c0c17e.tar.xz
raw/octeontx2_dma: add build infra and device probe
Add the make and meson based build infrastructure along with the DMA device probe with documentation infrastructure. Signed-off-by: Jerin Jacob <jerinj@marvell.com> Signed-off-by: Satha Rao <skoteshwar@marvell.com> Signed-off-by: Vamsi Attunuru <vattunuru@marvell.com>
Diffstat (limited to 'drivers/raw/octeontx2_dma/otx2_dpi_rawdev.c')
-rw-r--r--drivers/raw/octeontx2_dma/otx2_dpi_rawdev.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/drivers/raw/octeontx2_dma/otx2_dpi_rawdev.c b/drivers/raw/octeontx2_dma/otx2_dpi_rawdev.c
new file mode 100644
index 0000000..c363bf4
--- /dev/null
+++ b/drivers/raw/octeontx2_dma/otx2_dpi_rawdev.c
@@ -0,0 +1,99 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2019 Marvell International Ltd.
+ */
+
+#include <string.h>
+#include <unistd.h>
+
+#include <rte_bus.h>
+#include <rte_bus_pci.h>
+#include <rte_common.h>
+#include <rte_eal.h>
+#include <rte_lcore.h>
+#include <rte_pci.h>
+#include <rte_rawdev.h>
+#include <rte_rawdev_pmd.h>
+
+#include <otx2_common.h>
+
+static const struct rte_pci_id pci_dma_map[] = {
+ {
+ RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
+ PCI_DEVID_OCTEONTX2_DPI_VF)
+ },
+ {
+ .vendor_id = 0,
+ },
+};
+
+static int
+otx2_dpi_rawdev_probe(struct rte_pci_driver *pci_drv __rte_unused,
+ struct rte_pci_device *pci_dev)
+{
+ char name[RTE_RAWDEV_NAME_MAX_LEN];
+ struct rte_rawdev *rawdev;
+
+ /* For secondary processes, the primary has done all the work */
+ if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+ return 0;
+
+ if (pci_dev->mem_resource[0].addr == NULL) {
+ otx2_dpi_dbg("Empty bars %p %p", pci_dev->mem_resource[0].addr,
+ pci_dev->mem_resource[2].addr);
+ return -ENODEV;
+ }
+
+ memset(name, 0, sizeof(name));
+ snprintf(name, RTE_RAWDEV_NAME_MAX_LEN, "DPI:%x:%02x.%x",
+ pci_dev->addr.bus, pci_dev->addr.devid,
+ pci_dev->addr.function);
+
+ /* Allocate device structure */
+ rawdev = rte_rawdev_pmd_allocate(name, 0, rte_socket_id());
+ if (rawdev == NULL) {
+ otx2_err("Rawdev allocation failed");
+ return -EINVAL;
+ }
+
+ rawdev->device = &pci_dev->device;
+ rawdev->driver_name = pci_dev->driver->driver.name;
+
+ return 0;
+}
+
+static int
+otx2_dpi_rawdev_remove(struct rte_pci_device *pci_dev)
+{
+ char name[RTE_RAWDEV_NAME_MAX_LEN];
+ struct rte_rawdev *rawdev;
+
+ if (pci_dev == NULL) {
+ otx2_dpi_dbg("Invalid pci_dev of the device!");
+ return -EINVAL;
+ }
+
+ memset(name, 0, sizeof(name));
+ snprintf(name, RTE_RAWDEV_NAME_MAX_LEN, "DPI:%x:%02x.%x",
+ pci_dev->addr.bus, pci_dev->addr.devid,
+ pci_dev->addr.function);
+
+ rawdev = rte_rawdev_pmd_get_named_dev(name);
+ if (rawdev == NULL) {
+ otx2_dpi_dbg("Invalid device name (%s)", name);
+ return -EINVAL;
+ }
+
+ /* rte_rawdev_close is called by pmd_release */
+ return rte_rawdev_pmd_release(rawdev);
+}
+
+static struct rte_pci_driver rte_dpi_rawdev_pmd = {
+ .id_table = pci_dma_map,
+ .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_IOVA_AS_VA,
+ .probe = otx2_dpi_rawdev_probe,
+ .remove = otx2_dpi_rawdev_remove,
+};
+
+RTE_PMD_REGISTER_PCI(dpi_rawdev_pci_driver, rte_dpi_rawdev_pmd);
+RTE_PMD_REGISTER_PCI_TABLE(dpi_rawdev_pci_driver, pci_dma_map);
+RTE_PMD_REGISTER_KMOD_DEP(dpi_rawdev_pci_driver, "vfio-pci");