event/dlb: add eventdev probe
[dpdk.git] / drivers / event / dlb / pf / dlb_pf.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2020 Intel Corporation
3  */
4
5 #include <stdint.h>
6 #include <stdbool.h>
7 #include <stdio.h>
8 #include <sys/mman.h>
9 #include <sys/fcntl.h>
10 #include <sys/time.h>
11 #include <errno.h>
12 #include <assert.h>
13 #include <unistd.h>
14 #include <string.h>
15 #include <rte_debug.h>
16 #include <rte_log.h>
17 #include <rte_dev.h>
18 #include <rte_devargs.h>
19 #include <rte_mbuf.h>
20 #include <rte_ring.h>
21 #include <rte_errno.h>
22 #include <rte_kvargs.h>
23 #include <rte_malloc.h>
24 #include <rte_cycles.h>
25 #include <rte_io.h>
26 #include <rte_memory.h>
27 #include <rte_string_fns.h>
28
29 #include "../dlb_priv.h"
30 #include "../dlb_inline_fns.h"
31 #include "dlb_main.h"
32 #include "base/dlb_hw_types.h"
33 #include "base/dlb_osdep.h"
34 #include "base/dlb_resource.h"
35
36 static void
37 dlb_pf_iface_fn_ptrs_init(void)
38 {
39
40 }
41
42 /* PCI DEV HOOKS */
43 static int
44 dlb_eventdev_pci_init(struct rte_eventdev *eventdev)
45 {
46         int ret = 0;
47         struct rte_pci_device *pci_dev;
48         struct dlb_devargs dlb_args = {
49                 .socket_id = rte_socket_id(),
50                 .max_num_events = DLB_MAX_NUM_LDB_CREDITS,
51                 .num_dir_credits_override = -1,
52                 .defer_sched = 0,
53                 .num_atm_inflights = DLB_NUM_ATOMIC_INFLIGHTS_PER_QUEUE,
54         };
55         struct dlb_eventdev *dlb;
56
57         DLB_LOG_DBG("Enter with dev_id=%d socket_id=%d",
58                     eventdev->data->dev_id, eventdev->data->socket_id);
59
60         dlb_entry_points_init(eventdev);
61
62         dlb_pf_iface_fn_ptrs_init();
63
64         pci_dev = RTE_DEV_TO_PCI(eventdev->dev);
65
66         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
67                 dlb = dlb_pmd_priv(eventdev); /* rte_zmalloc_socket mem */
68
69                 /* Probe the DLB PF layer */
70                 dlb->qm_instance.pf_dev = dlb_probe(pci_dev);
71
72                 if (dlb->qm_instance.pf_dev == NULL) {
73                         DLB_LOG_ERR("DLB PF Probe failed with error %d\n",
74                                     rte_errno);
75                         ret = -rte_errno;
76                         goto dlb_probe_failed;
77                 }
78
79                 /* Were we invoked with runtime parameters? */
80                 if (pci_dev->device.devargs) {
81                         ret = dlb_parse_params(pci_dev->device.devargs->args,
82                                                pci_dev->device.devargs->name,
83                                                &dlb_args);
84                         if (ret) {
85                                 DLB_LOG_ERR("PFPMD failed to parse args ret=%d, errno=%d\n",
86                                             ret, rte_errno);
87                                 goto dlb_probe_failed;
88                         }
89                 }
90
91                 ret = dlb_primary_eventdev_probe(eventdev,
92                                                  EVDEV_DLB_NAME_PMD_STR,
93                                                  &dlb_args);
94         } else {
95                 ret = dlb_secondary_eventdev_probe(eventdev,
96                                                    EVDEV_DLB_NAME_PMD_STR);
97         }
98         if (ret)
99                 goto dlb_probe_failed;
100
101         DLB_LOG_INFO("DLB PF Probe success\n");
102
103         return 0;
104
105 dlb_probe_failed:
106
107         DLB_LOG_INFO("DLB PF Probe failed, ret=%d\n", ret);
108
109         return ret;
110 }
111
112 #define EVENTDEV_INTEL_VENDOR_ID 0x8086
113
114 static const struct rte_pci_id pci_id_dlb_map[] = {
115         {
116                 RTE_PCI_DEVICE(EVENTDEV_INTEL_VENDOR_ID,
117                                DLB_PF_DEV_ID)
118         },
119         {
120                 .vendor_id = 0,
121         },
122 };
123
124 static int
125 event_dlb_pci_probe(struct rte_pci_driver *pci_drv,
126                     struct rte_pci_device *pci_dev)
127 {
128         return rte_event_pmd_pci_probe_named(pci_drv, pci_dev,
129                 sizeof(struct dlb_eventdev), dlb_eventdev_pci_init,
130                 EVDEV_DLB_NAME_PMD_STR);
131 }
132
133 static int
134 event_dlb_pci_remove(struct rte_pci_device *pci_dev)
135 {
136         return rte_event_pmd_pci_remove(pci_dev, NULL);
137 }
138
139 static struct rte_pci_driver pci_eventdev_dlb_pmd = {
140         .id_table = pci_id_dlb_map,
141         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
142         .probe = event_dlb_pci_probe,
143         .remove = event_dlb_pci_remove,
144 };
145
146 RTE_PMD_REGISTER_PCI(event_dlb_pf, pci_eventdev_dlb_pmd);
147 RTE_PMD_REGISTER_PCI_TABLE(event_dlb_pf, pci_id_dlb_map);