4 * Copyright (C) Cavium networks Ltd. 2017.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium networks nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <rte_common.h>
34 #include <rte_debug.h>
37 #include <rte_lcore.h>
39 #include <rte_malloc.h>
40 #include <rte_memory.h>
41 #include <rte_memzone.h>
44 #include "ssovf_evdev.h"
46 /* SSOPF Mailbox messages */
48 struct ssovf_mbox_dev_info {
49 uint64_t min_deq_timeout_ns;
50 uint64_t max_deq_timeout_ns;
51 uint32_t max_num_events;
55 ssovf_mbox_dev_info(struct ssovf_mbox_dev_info *info)
57 struct octeontx_mbox_hdr hdr = {0};
58 uint16_t len = sizeof(struct ssovf_mbox_dev_info);
60 hdr.coproc = SSO_COPROC;
61 hdr.msg = SSO_GET_DEV_INFO;
65 return octeontx_ssovf_mbox_send(&hdr, NULL, 0, info, len);
68 struct ssovf_mbox_getwork_wait {
73 ssovf_mbox_getwork_tmo_set(uint32_t timeout_ns)
75 struct octeontx_mbox_hdr hdr = {0};
76 struct ssovf_mbox_getwork_wait tmo_set;
77 uint16_t len = sizeof(struct ssovf_mbox_getwork_wait);
80 hdr.coproc = SSO_COPROC;
81 hdr.msg = SSO_SET_GETWORK_WAIT;
84 tmo_set.wait_ns = timeout_ns;
85 ret = octeontx_ssovf_mbox_send(&hdr, &tmo_set, len, NULL, 0);
87 ssovf_log_err("Failed to set getwork timeout(%d)", ret);
92 struct ssovf_mbox_grp_pri {
93 uint8_t wgt_left; /* Read only */
100 ssovf_mbox_priority_set(uint8_t queue, uint8_t prio)
102 struct octeontx_mbox_hdr hdr = {0};
103 struct ssovf_mbox_grp_pri grp;
104 uint16_t len = sizeof(struct ssovf_mbox_grp_pri);
107 hdr.coproc = SSO_COPROC;
108 hdr.msg = SSO_GRP_SET_PRIORITY;
113 grp.priority = prio / 32; /* Normalize to 0 to 7 */
115 ret = octeontx_ssovf_mbox_send(&hdr, &grp, len, NULL, 0);
117 ssovf_log_err("Failed to set grp=%d prio=%d", queue, prio);
123 ssovf_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *dev_info)
125 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
127 dev_info->min_dequeue_timeout_ns = edev->min_deq_timeout_ns;
128 dev_info->max_dequeue_timeout_ns = edev->max_deq_timeout_ns;
129 dev_info->max_event_queues = edev->max_event_queues;
130 dev_info->max_event_queue_flows = (1ULL << 20);
131 dev_info->max_event_queue_priority_levels = 8;
132 dev_info->max_event_priority_levels = 1;
133 dev_info->max_event_ports = edev->max_event_ports;
134 dev_info->max_event_port_dequeue_depth = 1;
135 dev_info->max_event_port_enqueue_depth = 1;
136 dev_info->max_num_events = edev->max_num_events;
137 dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_QUEUE_QOS |
138 RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
139 RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES;
143 ssovf_configure(const struct rte_eventdev *dev)
145 struct rte_event_dev_config *conf = &dev->data->dev_conf;
146 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
150 deq_tmo_ns = conf->dequeue_timeout_ns;
152 if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT) {
153 edev->is_timeout_deq = 1;
154 deq_tmo_ns = edev->min_deq_timeout_ns;
156 edev->nb_event_queues = conf->nb_event_queues;
157 edev->nb_event_ports = conf->nb_event_ports;
159 return ssovf_mbox_getwork_tmo_set(deq_tmo_ns);
163 ssovf_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
164 struct rte_event_queue_conf *queue_conf)
167 RTE_SET_USED(queue_id);
169 queue_conf->nb_atomic_flows = (1ULL << 20);
170 queue_conf->nb_atomic_order_sequences = (1ULL << 20);
171 queue_conf->event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
172 queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
176 ssovf_queue_release(struct rte_eventdev *dev, uint8_t queue_id)
179 RTE_SET_USED(queue_id);
183 ssovf_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
184 const struct rte_event_queue_conf *queue_conf)
187 ssovf_func_trace("queue=%d prio=%d", queue_id, queue_conf->priority);
189 return ssovf_mbox_priority_set(queue_id, queue_conf->priority);
192 /* Initialize and register event driver with DPDK Application */
193 static const struct rte_eventdev_ops ssovf_ops = {
194 .dev_infos_get = ssovf_info_get,
195 .dev_configure = ssovf_configure,
196 .queue_def_conf = ssovf_queue_def_conf,
197 .queue_setup = ssovf_queue_setup,
198 .queue_release = ssovf_queue_release,
202 ssovf_vdev_probe(const char *name, const char *params)
204 struct octeontx_ssovf_info oinfo;
205 struct ssovf_mbox_dev_info info;
206 struct ssovf_evdev *edev;
207 struct rte_eventdev *eventdev;
208 static int ssovf_init_once;
211 RTE_SET_USED(params);
213 /* More than one instance is not supported */
214 if (ssovf_init_once) {
215 ssovf_log_err("Request to create >1 %s instance", name);
219 eventdev = rte_event_pmd_vdev_init(name, sizeof(struct ssovf_evdev),
221 if (eventdev == NULL) {
222 ssovf_log_err("Failed to create eventdev vdev %s", name);
225 eventdev->dev_ops = &ssovf_ops;
227 /* For secondary processes, the primary has done all the work */
228 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
231 ret = octeontx_ssovf_info(&oinfo);
233 ssovf_log_err("Failed to probe and validate ssovfs %d", ret);
237 edev = ssovf_pmd_priv(eventdev);
238 edev->max_event_ports = oinfo.total_ssowvfs;
239 edev->max_event_queues = oinfo.total_ssovfs;
240 edev->is_timeout_deq = 0;
242 ret = ssovf_mbox_dev_info(&info);
243 if (ret < 0 || ret != sizeof(struct ssovf_mbox_dev_info)) {
244 ssovf_log_err("Failed to get mbox devinfo %d", ret);
248 edev->min_deq_timeout_ns = info.min_deq_timeout_ns;
249 edev->max_deq_timeout_ns = info.max_deq_timeout_ns;
250 edev->max_num_events = info.max_num_events;
251 ssovf_log_dbg("min_deq_tmo=%"PRId64" max_deq_tmo=%"PRId64" max_evts=%d",
252 info.min_deq_timeout_ns, info.max_deq_timeout_ns,
253 info.max_num_events);
255 if (!edev->max_event_ports || !edev->max_event_queues) {
256 ssovf_log_err("Not enough eventdev resource queues=%d ports=%d",
257 edev->max_event_queues, edev->max_event_ports);
262 ssovf_log_info("Initializing %s domain=%d max_queues=%d max_ports=%d",
263 name, oinfo.domain, edev->max_event_queues,
264 edev->max_event_ports);
270 rte_event_pmd_vdev_uninit(name);
275 ssovf_vdev_remove(const char *name)
277 ssovf_log_info("Closing %s", name);
278 return rte_event_pmd_vdev_uninit(name);
281 static struct rte_vdev_driver vdev_ssovf_pmd = {
282 .probe = ssovf_vdev_probe,
283 .remove = ssovf_vdev_remove
286 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_OCTEONTX_PMD, vdev_ssovf_pmd);