raw/dpaa2_cmdif: introduce DPAA2 command interface driver
authorNipun Gupta <nipun.gupta@nxp.com>
Fri, 4 May 2018 10:11:26 +0000 (15:41 +0530)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 8 May 2018 12:20:39 +0000 (14:20 +0200)
Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
MAINTAINERS
config/common_base
config/common_linuxapp
drivers/raw/Makefile
drivers/raw/dpaa2_cmdif/Makefile [new file with mode: 0644]
drivers/raw/dpaa2_cmdif/dpaa2_cmdif.c [new file with mode: 0644]
drivers/raw/dpaa2_cmdif/dpaa2_cmdif_logs.h [new file with mode: 0644]
drivers/raw/dpaa2_cmdif/meson.build [new file with mode: 0644]
drivers/raw/dpaa2_cmdif/rte_pmd_dpaa2_cmdif_version.map [new file with mode: 0644]
drivers/raw/meson.build
mk/rte.app.mk

index 229bda2..bfad7d5 100644 (file)
@@ -851,6 +851,10 @@ M: Nipun Gupta <nipun.gupta@nxp.com>
 F: drivers/raw/dpaa2_qdma/
 F: doc/guides/rawdevs/dpaa2_qdma.rst
 
+DPAA2 CMDIF
+M: Nipun Gupta <nipun.gupta@nxp.com>
+F: drivers/raw/dpaa2_cmdif/
+
 
 Packet processing
 -----------------
index 9b48bcb..0d181ac 100644 (file)
@@ -617,6 +617,11 @@ CONFIG_RTE_LIBRTE_RAWDEV=y
 CONFIG_RTE_RAWDEV_MAX_DEVS=10
 CONFIG_RTE_LIBRTE_PMD_SKELETON_RAWDEV=y
 
+#
+# Compile PMD for NXP DPAA2 CMDIF raw device
+#
+CONFIG_RTE_LIBRTE_PMD_DPAA2_CMDIF_RAWDEV=n
+
 #
 # Compile PMD for NXP DPAA2 QDMA raw device
 #
index 21b3fe3..5c68cc0 100644 (file)
@@ -38,4 +38,5 @@ CONFIG_RTE_LIBRTE_DPAA2_MEMPOOL=y
 CONFIG_RTE_LIBRTE_DPAA2_PMD=y
 CONFIG_RTE_LIBRTE_PMD_DPAA2_EVENTDEV=y
 CONFIG_RTE_LIBRTE_PMD_DPAA2_SEC=y
+CONFIG_RTE_LIBRTE_PMD_DPAA2_CMDIF_RAWDEV=y
 CONFIG_RTE_LIBRTE_PMD_DPAA2_QDMA_RAWDEV=y
index 0f2b076..2eb2787 100644 (file)
@@ -6,6 +6,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 # DIRS-$(<configuration>) += <directory>
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_SKELETON_RAWDEV) += skeleton_rawdev
 ifeq ($(CONFIG_RTE_EAL_VFIO)$(CONFIG_RTE_LIBRTE_FSLMC_BUS),yy)
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_DPAA2_CMDIF_RAWDEV) += dpaa2_cmdif
 DIRS-$(CONFIG_RTE_LIBRTE_PMD_DPAA2_QDMA_RAWDEV) += dpaa2_qdma
 endif
 
diff --git a/drivers/raw/dpaa2_cmdif/Makefile b/drivers/raw/dpaa2_cmdif/Makefile
new file mode 100644 (file)
index 0000000..5f9b8bf
--- /dev/null
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2018 NXP
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_pmd_dpaa2_cmdif.a
+
+CFLAGS += -DALLOW_EXPERIMENTAL_API
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc
+CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/qbman/include
+
+LDLIBS += -lrte_bus_fslmc
+LDLIBS += -lrte_bus_vdev
+LDLIBS += -lrte_eal
+LDLIBS += -lrte_kvargs
+LDLIBS += -lrte_mempool_dpaa2
+LDLIBS += -lrte_rawdev
+
+EXPORT_MAP := rte_pmd_dpaa2_cmdif_version.map
+
+LIBABIVER := 1
+
+#
+# all source are stored in SRCS-y
+#
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_DPAA2_CMDIF_RAWDEV) += dpaa2_cmdif.c
+
+include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/drivers/raw/dpaa2_cmdif/dpaa2_cmdif.c b/drivers/raw/dpaa2_cmdif/dpaa2_cmdif.c
new file mode 100644 (file)
index 0000000..470eb53
--- /dev/null
@@ -0,0 +1,137 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2018 NXP
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdint.h>
+
+#include <rte_bus_vdev.h>
+#include <rte_atomic.h>
+#include <rte_interrupts.h>
+#include <rte_branch_prediction.h>
+#include <rte_lcore.h>
+
+#include <rte_rawdev.h>
+#include <rte_rawdev_pmd.h>
+
+#include <portal/dpaa2_hw_pvt.h>
+#include <portal/dpaa2_hw_dpio.h>
+#include "dpaa2_cmdif_logs.h"
+
+/* Dynamic log type identifier */
+int dpaa2_cmdif_logtype;
+
+/* CMDIF driver name */
+#define DPAA2_CMDIF_PMD_NAME dpaa2_dpci
+
+/* CMDIF driver object */
+static struct rte_vdev_driver dpaa2_cmdif_drv;
+
+static const struct rte_rawdev_ops dpaa2_cmdif_ops;
+
+static int
+dpaa2_cmdif_create(const char *name,
+                  struct rte_vdev_device *vdev,
+                  int socket_id)
+{
+       struct rte_rawdev *rawdev;
+       struct dpaa2_dpci_dev *cidev;
+
+       /* Allocate device structure */
+       rawdev = rte_rawdev_pmd_allocate(name, sizeof(struct dpaa2_dpci_dev),
+                                        socket_id);
+       if (!rawdev) {
+               DPAA2_CMDIF_ERR("Unable to allocate rawdevice");
+               return -EINVAL;
+       }
+
+       rawdev->dev_ops = &dpaa2_cmdif_ops;
+       rawdev->device = &vdev->device;
+       rawdev->driver_name = vdev->device.driver->name;
+
+       /* For secondary processes, the primary has done all the work */
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return 0;
+
+       cidev = rte_dpaa2_alloc_dpci_dev();
+       if (!cidev) {
+               DPAA2_CMDIF_ERR("Unable to allocate CI device");
+               rte_rawdev_pmd_release(rawdev);
+               return -ENODEV;
+       }
+
+       rawdev->dev_private = cidev;
+
+       return 0;
+}
+
+static int
+dpaa2_cmdif_destroy(const char *name)
+{
+       int ret;
+       struct rte_rawdev *rdev;
+
+       rdev = rte_rawdev_pmd_get_named_dev(name);
+       if (!rdev) {
+               DPAA2_CMDIF_ERR("Invalid device name (%s)", name);
+               return -EINVAL;
+       }
+
+       /* The primary process will only free the DPCI device */
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+               rte_dpaa2_free_dpci_dev(rdev->dev_private);
+
+       ret = rte_rawdev_pmd_release(rdev);
+       if (ret)
+               DPAA2_CMDIF_DEBUG("Device cleanup failed");
+
+       return 0;
+}
+
+static int
+dpaa2_cmdif_probe(struct rte_vdev_device *vdev)
+{
+       const char *name;
+       int ret = 0;
+
+       name = rte_vdev_device_name(vdev);
+
+       DPAA2_CMDIF_INFO("Init %s on NUMA node %d", name, rte_socket_id());
+
+       ret = dpaa2_cmdif_create(name, vdev, rte_socket_id());
+
+       return ret;
+}
+
+static int
+dpaa2_cmdif_remove(struct rte_vdev_device *vdev)
+{
+       const char *name;
+       int ret;
+
+       name = rte_vdev_device_name(vdev);
+
+       DPAA2_CMDIF_INFO("Closing %s on NUMA node %d", name, rte_socket_id());
+
+       ret = dpaa2_cmdif_destroy(name);
+
+       return ret;
+}
+
+static struct rte_vdev_driver dpaa2_cmdif_drv = {
+       .probe = dpaa2_cmdif_probe,
+       .remove = dpaa2_cmdif_remove
+};
+
+RTE_PMD_REGISTER_VDEV(DPAA2_CMDIF_PMD_NAME, dpaa2_cmdif_drv);
+
+RTE_INIT(dpaa2_cmdif_init_log);
+
+static void
+dpaa2_cmdif_init_log(void)
+{
+       dpaa2_cmdif_logtype = rte_log_register("pmd.raw.dpaa2.cmdif");
+       if (dpaa2_cmdif_logtype >= 0)
+               rte_log_set_level(dpaa2_cmdif_logtype, RTE_LOG_INFO);
+}
diff --git a/drivers/raw/dpaa2_cmdif/dpaa2_cmdif_logs.h b/drivers/raw/dpaa2_cmdif/dpaa2_cmdif_logs.h
new file mode 100644 (file)
index 0000000..5eb0885
--- /dev/null
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2018 NXP
+ */
+
+#ifndef __DPAA2_CMDIF_LOGS_H__
+#define __DPAA2_CMDIF_LOGS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rte_rawdev.h>
+
+extern int dpaa2_cmdif_logtype;
+
+#define DPAA2_CMDIF_LOG(level, fmt, args...) \
+       rte_log(RTE_LOG_ ## level, dpaa2_cmdif_logtype, "%s(): " fmt "\n", \
+               __func__, ##args)
+
+#define DPAA2_CMDIF_FUNC_TRACE() DPAA2_CMDIF_LOG(DEBUG, ">>")
+
+#define DPAA2_CMDIF_DEBUG(fmt, args...) \
+       DPAA2_CMDIF_LOG(DEBUG, fmt, ## args)
+#define DPAA2_CMDIF_INFO(fmt, args...) \
+       DPAA2_CMDIF_LOG(INFO, fmt, ## args)
+#define DPAA2_CMDIF_ERR(fmt, args...) \
+       DPAA2_CMDIF_LOG(ERR, fmt, ## args)
+#define DPAA2_CMDIF_WARN(fmt, args...) \
+       DPAA2_CMDIF_LOG(WARNING, fmt, ## args)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DPAA2_CMDIF_LOGS_H__ */
diff --git a/drivers/raw/dpaa2_cmdif/meson.build b/drivers/raw/dpaa2_cmdif/meson.build
new file mode 100644 (file)
index 0000000..91a77ce
--- /dev/null
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2018 NXP
+
+deps += ['rawdev', 'mempool_dpaa2', 'bus_vdev']
+sources = files('dpaa2_cmdif.c')
+
+allow_experimental_apis = true
diff --git a/drivers/raw/dpaa2_cmdif/rte_pmd_dpaa2_cmdif_version.map b/drivers/raw/dpaa2_cmdif/rte_pmd_dpaa2_cmdif_version.map
new file mode 100644 (file)
index 0000000..9b9ab1a
--- /dev/null
@@ -0,0 +1,4 @@
+DPDK_18.05 {
+
+       local: *;
+};
index 1b298f8..34dfac4 100644 (file)
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright 2018 NXP
 
-drivers = ['skeleton_rawdev', 'dpaa2_qdma']
+drivers = ['skeleton_rawdev', 'dpaa2_cmdif', 'dpaa2_qdma']
 std_deps = ['rawdev']
 config_flag_fmt = 'RTE_LIBRTE_PMD_@0@_RAWDEV'
 driver_name_fmt = 'rte_pmd_@0@'
index 26a6b0c..26f3563 100644 (file)
@@ -252,6 +252,7 @@ endif # CONFIG_RTE_LIBRTE_EVENTDEV
 ifeq ($(CONFIG_RTE_LIBRTE_RAWDEV),y)
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_SKELETON_RAWDEV) += -lrte_pmd_skeleton_rawdev
 ifeq ($(CONFIG_RTE_EAL_VFIO)$(CONFIG_RTE_LIBRTE_FSLMC_BUS),yy)
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_DPAA2_CMDIF_RAWDEV) += -lrte_pmd_dpaa2_cmdif
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_DPAA2_QDMA_RAWDEV) += -lrte_pmd_dpaa2_qdma
 endif # CONFIG_RTE_LIBRTE_FSLMC_BUS
 endif # CONFIG_RTE_LIBRTE_RAWDEV