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);
122 struct ssovf_mbox_convert_ns_getworks_iter {
124 uint32_t getwork_iter;/* Get_work iterations for the given wait_ns */
128 ssovf_mbox_timeout_ticks(uint64_t ns, uint64_t *tmo_ticks)
130 struct octeontx_mbox_hdr hdr = {0};
131 struct ssovf_mbox_convert_ns_getworks_iter ns2iter;
132 uint16_t len = sizeof(ns2iter);
135 hdr.coproc = SSO_COPROC;
136 hdr.msg = SSO_CONVERT_NS_GETWORK_ITER;
139 memset(&ns2iter, 0, len);
140 ns2iter.wait_ns = ns;
141 ret = octeontx_ssovf_mbox_send(&hdr, &ns2iter, len, &ns2iter, len);
142 if (ret < 0 || (ret != len)) {
143 ssovf_log_err("Failed to get tmo ticks ns=%"PRId64"", ns);
147 *tmo_ticks = ns2iter.getwork_iter;
152 ssovf_fastpath_fns_set(struct rte_eventdev *dev)
154 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
156 dev->schedule = NULL;
157 dev->enqueue = ssows_enq;
158 dev->enqueue_burst = ssows_enq_burst;
159 dev->dequeue = ssows_deq;
160 dev->dequeue_burst = ssows_deq_burst;
162 if (edev->is_timeout_deq) {
163 dev->dequeue = ssows_deq_timeout;
164 dev->dequeue_burst = ssows_deq_timeout_burst;
169 ssovf_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *dev_info)
171 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
173 dev_info->min_dequeue_timeout_ns = edev->min_deq_timeout_ns;
174 dev_info->max_dequeue_timeout_ns = edev->max_deq_timeout_ns;
175 dev_info->max_event_queues = edev->max_event_queues;
176 dev_info->max_event_queue_flows = (1ULL << 20);
177 dev_info->max_event_queue_priority_levels = 8;
178 dev_info->max_event_priority_levels = 1;
179 dev_info->max_event_ports = edev->max_event_ports;
180 dev_info->max_event_port_dequeue_depth = 1;
181 dev_info->max_event_port_enqueue_depth = 1;
182 dev_info->max_num_events = edev->max_num_events;
183 dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_QUEUE_QOS |
184 RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
185 RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES;
189 ssovf_configure(const struct rte_eventdev *dev)
191 struct rte_event_dev_config *conf = &dev->data->dev_conf;
192 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
196 deq_tmo_ns = conf->dequeue_timeout_ns;
198 if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT) {
199 edev->is_timeout_deq = 1;
200 deq_tmo_ns = edev->min_deq_timeout_ns;
202 edev->nb_event_queues = conf->nb_event_queues;
203 edev->nb_event_ports = conf->nb_event_ports;
205 return ssovf_mbox_getwork_tmo_set(deq_tmo_ns);
209 ssovf_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
210 struct rte_event_queue_conf *queue_conf)
213 RTE_SET_USED(queue_id);
215 queue_conf->nb_atomic_flows = (1ULL << 20);
216 queue_conf->nb_atomic_order_sequences = (1ULL << 20);
217 queue_conf->event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
218 queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
222 ssovf_queue_release(struct rte_eventdev *dev, uint8_t queue_id)
225 RTE_SET_USED(queue_id);
229 ssovf_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
230 const struct rte_event_queue_conf *queue_conf)
233 ssovf_func_trace("queue=%d prio=%d", queue_id, queue_conf->priority);
235 return ssovf_mbox_priority_set(queue_id, queue_conf->priority);
239 ssovf_port_def_conf(struct rte_eventdev *dev, uint8_t port_id,
240 struct rte_event_port_conf *port_conf)
242 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
244 RTE_SET_USED(port_id);
245 port_conf->new_event_threshold = edev->max_num_events;
246 port_conf->dequeue_depth = 1;
247 port_conf->enqueue_depth = 1;
251 ssovf_port_release(void *port)
257 ssovf_port_setup(struct rte_eventdev *dev, uint8_t port_id,
258 const struct rte_event_port_conf *port_conf)
263 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
265 ssovf_func_trace("port=%d", port_id);
266 RTE_SET_USED(port_conf);
268 /* Free memory prior to re-allocation if needed */
269 if (dev->data->ports[port_id] != NULL) {
270 ssovf_port_release(dev->data->ports[port_id]);
271 dev->data->ports[port_id] = NULL;
274 /* Allocate event port memory */
275 ws = rte_zmalloc_socket("eventdev ssows",
276 sizeof(struct ssows), RTE_CACHE_LINE_SIZE,
277 dev->data->socket_id);
279 ssovf_log_err("Failed to alloc memory for port=%d", port_id);
283 ws->base = octeontx_ssovf_bar(OCTEONTX_SSO_HWS, port_id, 0);
284 if (ws->base == NULL) {
286 ssovf_log_err("Failed to get hws base addr port=%d", port_id);
290 reg_off = SSOW_VHWS_OP_GET_WORK0;
291 reg_off |= 1 << 4; /* Index_ggrp_mask (Use maskset zero) */
292 reg_off |= 1 << 16; /* Wait */
293 ws->getwork = ws->base + reg_off;
296 for (q = 0; q < edev->nb_event_queues; q++) {
297 ws->grps[q] = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, q, 2);
298 if (ws->grps[q] == NULL) {
300 ssovf_log_err("Failed to get grp%d base addr", q);
305 dev->data->ports[port_id] = ws;
306 ssovf_log_dbg("port=%d ws=%p", port_id, ws);
311 ssovf_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
312 const uint8_t priorities[], uint16_t nb_links)
316 struct ssows *ws = port;
318 ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_links);
320 RTE_SET_USED(priorities);
322 for (link = 0; link < nb_links; link++) {
324 val |= (1ULL << 24); /* Set membership */
325 ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
327 return (int)nb_links;
331 ssovf_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
336 struct ssows *ws = port;
338 ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_unlinks);
341 for (unlink = 0; unlink < nb_unlinks; unlink++) {
342 val = queues[unlink];
343 val &= ~(1ULL << 24); /* Clear membership */
344 ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
346 return (int)nb_unlinks;
350 ssovf_timeout_ticks(struct rte_eventdev *dev, uint64_t ns, uint64_t *tmo_ticks)
354 return ssovf_mbox_timeout_ticks(ns, tmo_ticks);
358 ssows_dump(struct ssows *ws, FILE *f)
360 uint8_t *base = ws->base;
363 fprintf(f, "\t---------------port%d---------------\n", ws->port);
364 val = ssovf_read64(base + SSOW_VHWS_TAG);
365 fprintf(f, "\ttag=0x%x tt=%d head=%d tail=%d grp=%d index=%d tail=%d\n",
366 (uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
367 (int)(val >> 34) & 0x1, (int)(val >> 35) & 0x1,
368 (int)(val >> 36) & 0x3ff, (int)(val >> 48) & 0x3ff,
369 (int)(val >> 63) & 0x1);
371 val = ssovf_read64(base + SSOW_VHWS_WQP);
372 fprintf(f, "\twqp=0x%"PRIx64"\n", val);
374 val = ssovf_read64(base + SSOW_VHWS_LINKS);
375 fprintf(f, "\tindex=%d valid=%d revlink=%d tail=%d head=%d grp=%d\n",
376 (int)(val & 0x3ff), (int)(val >> 10) & 0x1,
377 (int)(val >> 11) & 0x3ff, (int)(val >> 26) & 0x1,
378 (int)(val >> 27) & 0x1, (int)(val >> 28) & 0x3ff);
380 val = ssovf_read64(base + SSOW_VHWS_PENDTAG);
381 fprintf(f, "\tptag=0x%x ptt=%d pgwi=%d pdesc=%d pgw=%d pgww=%d ps=%d\n",
382 (uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
383 (int)(val >> 56) & 0x1, (int)(val >> 58) & 0x1,
384 (int)(val >> 61) & 0x1, (int)(val >> 62) & 0x1,
385 (int)(val >> 63) & 0x1);
387 val = ssovf_read64(base + SSOW_VHWS_PENDWQP);
388 fprintf(f, "\tpwqp=0x%"PRIx64"\n", val);
392 ssovf_dump(struct rte_eventdev *dev, FILE *f)
394 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
397 /* Dump SSOWVF debug registers */
398 for (port = 0; port < edev->nb_event_ports; port++)
399 ssows_dump(dev->data->ports[port], f);
403 ssovf_start(struct rte_eventdev *dev)
405 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
411 for (i = 0; i < edev->nb_event_ports; i++) {
412 ws = dev->data->ports[i];
417 for (i = 0; i < edev->nb_event_queues; i++) {
418 /* Consume all the events through HWS0 */
419 ssows_flush_events(dev->data->ports[0], i);
421 base = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
422 base += SSO_VHGRP_QCTL;
423 ssovf_write64(1, base); /* Enable SSO group */
426 ssovf_fastpath_fns_set(dev);
431 ssovf_stop(struct rte_eventdev *dev)
433 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
439 for (i = 0; i < edev->nb_event_ports; i++) {
440 ws = dev->data->ports[i];
445 for (i = 0; i < edev->nb_event_queues; i++) {
446 /* Consume all the events through HWS0 */
447 ssows_flush_events(dev->data->ports[0], i);
449 base = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
450 base += SSO_VHGRP_QCTL;
451 ssovf_write64(0, base); /* Disable SSO group */
456 ssovf_close(struct rte_eventdev *dev)
458 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
459 uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
462 for (i = 0; i < edev->nb_event_queues; i++)
465 for (i = 0; i < edev->nb_event_ports; i++)
466 ssovf_port_unlink(dev, dev->data->ports[i], all_queues,
467 edev->nb_event_queues);
471 /* Initialize and register event driver with DPDK Application */
472 static const struct rte_eventdev_ops ssovf_ops = {
473 .dev_infos_get = ssovf_info_get,
474 .dev_configure = ssovf_configure,
475 .queue_def_conf = ssovf_queue_def_conf,
476 .queue_setup = ssovf_queue_setup,
477 .queue_release = ssovf_queue_release,
478 .port_def_conf = ssovf_port_def_conf,
479 .port_setup = ssovf_port_setup,
480 .port_release = ssovf_port_release,
481 .port_link = ssovf_port_link,
482 .port_unlink = ssovf_port_unlink,
483 .timeout_ticks = ssovf_timeout_ticks,
485 .dev_start = ssovf_start,
486 .dev_stop = ssovf_stop,
487 .dev_close = ssovf_close
491 ssovf_vdev_probe(const char *name, const char *params)
493 struct octeontx_ssovf_info oinfo;
494 struct ssovf_mbox_dev_info info;
495 struct ssovf_evdev *edev;
496 struct rte_eventdev *eventdev;
497 static int ssovf_init_once;
500 RTE_SET_USED(params);
502 /* More than one instance is not supported */
503 if (ssovf_init_once) {
504 ssovf_log_err("Request to create >1 %s instance", name);
508 eventdev = rte_event_pmd_vdev_init(name, sizeof(struct ssovf_evdev),
510 if (eventdev == NULL) {
511 ssovf_log_err("Failed to create eventdev vdev %s", name);
514 eventdev->dev_ops = &ssovf_ops;
516 /* For secondary processes, the primary has done all the work */
517 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
518 ssovf_fastpath_fns_set(eventdev);
522 ret = octeontx_ssovf_info(&oinfo);
524 ssovf_log_err("Failed to probe and validate ssovfs %d", ret);
528 edev = ssovf_pmd_priv(eventdev);
529 edev->max_event_ports = oinfo.total_ssowvfs;
530 edev->max_event_queues = oinfo.total_ssovfs;
531 edev->is_timeout_deq = 0;
533 ret = ssovf_mbox_dev_info(&info);
534 if (ret < 0 || ret != sizeof(struct ssovf_mbox_dev_info)) {
535 ssovf_log_err("Failed to get mbox devinfo %d", ret);
539 edev->min_deq_timeout_ns = info.min_deq_timeout_ns;
540 edev->max_deq_timeout_ns = info.max_deq_timeout_ns;
541 edev->max_num_events = info.max_num_events;
542 ssovf_log_dbg("min_deq_tmo=%"PRId64" max_deq_tmo=%"PRId64" max_evts=%d",
543 info.min_deq_timeout_ns, info.max_deq_timeout_ns,
544 info.max_num_events);
546 if (!edev->max_event_ports || !edev->max_event_queues) {
547 ssovf_log_err("Not enough eventdev resource queues=%d ports=%d",
548 edev->max_event_queues, edev->max_event_ports);
553 ssovf_log_info("Initializing %s domain=%d max_queues=%d max_ports=%d",
554 name, oinfo.domain, edev->max_event_queues,
555 edev->max_event_ports);
561 rte_event_pmd_vdev_uninit(name);
566 ssovf_vdev_remove(const char *name)
568 ssovf_log_info("Closing %s", name);
569 return rte_event_pmd_vdev_uninit(name);
572 static struct rte_vdev_driver vdev_ssovf_pmd = {
573 .probe = ssovf_vdev_probe,
574 .remove = ssovf_vdev_remove
577 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_OCTEONTX_PMD, vdev_ssovf_pmd);