1 /* SPDX-License-Identifier: BSD-3-Clause
9 #include <rte_bus_vdev.h>
10 #include <rte_atomic.h>
11 #include <rte_interrupts.h>
12 #include <rte_branch_prediction.h>
13 #include <rte_lcore.h>
15 #include <rte_rawdev.h>
16 #include <rte_rawdev_pmd.h>
18 #include <portal/dpaa2_hw_pvt.h>
19 #include <portal/dpaa2_hw_dpio.h>
20 #include "dpaa2_cmdif_logs.h"
22 /* Dynamic log type identifier */
23 int dpaa2_cmdif_logtype;
25 /* CMDIF driver name */
26 #define DPAA2_CMDIF_PMD_NAME dpaa2_dpci
28 /* CMDIF driver object */
29 static struct rte_vdev_driver dpaa2_cmdif_drv;
32 * This API provides the DPCI device ID in 'attr_value'.
33 * The device ID shall be passed by GPP to the AIOP using CMDIF commands.
36 dpaa2_cmdif_get_attr(struct rte_rawdev *dev,
37 const char *attr_name,
40 struct dpaa2_dpci_dev *cidev = dev->dev_private;
42 DPAA2_CMDIF_FUNC_TRACE();
44 RTE_SET_USED(attr_name);
47 DPAA2_CMDIF_ERR("Invalid arguments for getting attributes");
50 *attr_value = cidev->dpci_id;
55 static const struct rte_rawdev_ops dpaa2_cmdif_ops = {
56 .attr_get = dpaa2_cmdif_get_attr,
60 dpaa2_cmdif_create(const char *name,
61 struct rte_vdev_device *vdev,
64 struct rte_rawdev *rawdev;
65 struct dpaa2_dpci_dev *cidev;
67 /* Allocate device structure */
68 rawdev = rte_rawdev_pmd_allocate(name, sizeof(struct dpaa2_dpci_dev),
71 DPAA2_CMDIF_ERR("Unable to allocate rawdevice");
75 rawdev->dev_ops = &dpaa2_cmdif_ops;
76 rawdev->device = &vdev->device;
77 rawdev->driver_name = vdev->device.driver->name;
79 /* For secondary processes, the primary has done all the work */
80 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
83 cidev = rte_dpaa2_alloc_dpci_dev();
85 DPAA2_CMDIF_ERR("Unable to allocate CI device");
86 rte_rawdev_pmd_release(rawdev);
90 rawdev->dev_private = cidev;
96 dpaa2_cmdif_destroy(const char *name)
99 struct rte_rawdev *rdev;
101 rdev = rte_rawdev_pmd_get_named_dev(name);
103 DPAA2_CMDIF_ERR("Invalid device name (%s)", name);
107 /* The primary process will only free the DPCI device */
108 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
109 rte_dpaa2_free_dpci_dev(rdev->dev_private);
111 ret = rte_rawdev_pmd_release(rdev);
113 DPAA2_CMDIF_DEBUG("Device cleanup failed");
119 dpaa2_cmdif_probe(struct rte_vdev_device *vdev)
124 name = rte_vdev_device_name(vdev);
126 DPAA2_CMDIF_INFO("Init %s on NUMA node %d", name, rte_socket_id());
128 ret = dpaa2_cmdif_create(name, vdev, rte_socket_id());
134 dpaa2_cmdif_remove(struct rte_vdev_device *vdev)
139 name = rte_vdev_device_name(vdev);
141 DPAA2_CMDIF_INFO("Closing %s on NUMA node %d", name, rte_socket_id());
143 ret = dpaa2_cmdif_destroy(name);
148 static struct rte_vdev_driver dpaa2_cmdif_drv = {
149 .probe = dpaa2_cmdif_probe,
150 .remove = dpaa2_cmdif_remove
153 RTE_PMD_REGISTER_VDEV(DPAA2_CMDIF_PMD_NAME, dpaa2_cmdif_drv);
155 RTE_INIT(dpaa2_cmdif_init_log);
158 dpaa2_cmdif_init_log(void)
160 dpaa2_cmdif_logtype = rte_log_register("pmd.raw.dpaa2.cmdif");
161 if (dpaa2_cmdif_logtype >= 0)
162 rte_log_set_level(dpaa2_cmdif_logtype, RTE_LOG_INFO);