1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
7 #include <rte_common.h>
11 #include <rte_ethdev.h>
12 #include <rte_event_eth_rx_adapter.h>
13 #include <rte_lcore.h>
15 #include <rte_malloc.h>
16 #include <rte_memory.h>
17 #include <rte_bus_vdev.h>
19 #include "ssovf_evdev.h"
21 /* SSOPF Mailbox messages */
23 struct ssovf_mbox_dev_info {
24 uint64_t min_deq_timeout_ns;
25 uint64_t max_deq_timeout_ns;
26 uint32_t max_num_events;
30 ssovf_mbox_dev_info(struct ssovf_mbox_dev_info *info)
32 struct octeontx_mbox_hdr hdr = {0};
33 uint16_t len = sizeof(struct ssovf_mbox_dev_info);
35 hdr.coproc = SSO_COPROC;
36 hdr.msg = SSO_GET_DEV_INFO;
40 return octeontx_ssovf_mbox_send(&hdr, NULL, 0, info, len);
43 struct ssovf_mbox_getwork_wait {
48 ssovf_mbox_getwork_tmo_set(uint32_t timeout_ns)
50 struct octeontx_mbox_hdr hdr = {0};
51 struct ssovf_mbox_getwork_wait tmo_set;
52 uint16_t len = sizeof(struct ssovf_mbox_getwork_wait);
55 hdr.coproc = SSO_COPROC;
56 hdr.msg = SSO_SET_GETWORK_WAIT;
59 tmo_set.wait_ns = timeout_ns;
60 ret = octeontx_ssovf_mbox_send(&hdr, &tmo_set, len, NULL, 0);
62 ssovf_log_err("Failed to set getwork timeout(%d)", ret);
67 struct ssovf_mbox_grp_pri {
68 uint8_t wgt_left; /* Read only */
75 ssovf_mbox_priority_set(uint8_t queue, uint8_t prio)
77 struct octeontx_mbox_hdr hdr = {0};
78 struct ssovf_mbox_grp_pri grp;
79 uint16_t len = sizeof(struct ssovf_mbox_grp_pri);
82 hdr.coproc = SSO_COPROC;
83 hdr.msg = SSO_GRP_SET_PRIORITY;
88 grp.priority = prio / 32; /* Normalize to 0 to 7 */
90 ret = octeontx_ssovf_mbox_send(&hdr, &grp, len, NULL, 0);
92 ssovf_log_err("Failed to set grp=%d prio=%d", queue, prio);
97 struct ssovf_mbox_convert_ns_getworks_iter {
99 uint32_t getwork_iter;/* Get_work iterations for the given wait_ns */
103 ssovf_mbox_timeout_ticks(uint64_t ns, uint64_t *tmo_ticks)
105 struct octeontx_mbox_hdr hdr = {0};
106 struct ssovf_mbox_convert_ns_getworks_iter ns2iter;
107 uint16_t len = sizeof(ns2iter);
110 hdr.coproc = SSO_COPROC;
111 hdr.msg = SSO_CONVERT_NS_GETWORK_ITER;
114 memset(&ns2iter, 0, len);
115 ns2iter.wait_ns = ns;
116 ret = octeontx_ssovf_mbox_send(&hdr, &ns2iter, len, &ns2iter, len);
117 if (ret < 0 || (ret != len)) {
118 ssovf_log_err("Failed to get tmo ticks ns=%"PRId64"", ns);
122 *tmo_ticks = ns2iter.getwork_iter;
127 ssovf_fastpath_fns_set(struct rte_eventdev *dev)
129 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
131 dev->enqueue = ssows_enq;
132 dev->enqueue_burst = ssows_enq_burst;
133 dev->enqueue_new_burst = ssows_enq_new_burst;
134 dev->enqueue_forward_burst = ssows_enq_fwd_burst;
135 dev->dequeue = ssows_deq;
136 dev->dequeue_burst = ssows_deq_burst;
138 if (edev->is_timeout_deq) {
139 dev->dequeue = ssows_deq_timeout;
140 dev->dequeue_burst = ssows_deq_timeout_burst;
145 ssovf_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *dev_info)
147 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
149 dev_info->driver_name = RTE_STR(EVENTDEV_NAME_OCTEONTX_PMD);
150 dev_info->min_dequeue_timeout_ns = edev->min_deq_timeout_ns;
151 dev_info->max_dequeue_timeout_ns = edev->max_deq_timeout_ns;
152 dev_info->max_event_queues = edev->max_event_queues;
153 dev_info->max_event_queue_flows = (1ULL << 20);
154 dev_info->max_event_queue_priority_levels = 8;
155 dev_info->max_event_priority_levels = 1;
156 dev_info->max_event_ports = edev->max_event_ports;
157 dev_info->max_event_port_dequeue_depth = 1;
158 dev_info->max_event_port_enqueue_depth = 1;
159 dev_info->max_num_events = edev->max_num_events;
160 dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_QUEUE_QOS |
161 RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
162 RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES;
166 ssovf_configure(const struct rte_eventdev *dev)
168 struct rte_event_dev_config *conf = &dev->data->dev_conf;
169 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
173 deq_tmo_ns = conf->dequeue_timeout_ns;
175 deq_tmo_ns = edev->min_deq_timeout_ns;
177 if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT) {
178 edev->is_timeout_deq = 1;
179 deq_tmo_ns = edev->min_deq_timeout_ns;
181 edev->nb_event_queues = conf->nb_event_queues;
182 edev->nb_event_ports = conf->nb_event_ports;
184 return ssovf_mbox_getwork_tmo_set(deq_tmo_ns);
188 ssovf_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
189 struct rte_event_queue_conf *queue_conf)
192 RTE_SET_USED(queue_id);
194 queue_conf->nb_atomic_flows = (1ULL << 20);
195 queue_conf->nb_atomic_order_sequences = (1ULL << 20);
196 queue_conf->event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
197 queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
201 ssovf_queue_release(struct rte_eventdev *dev, uint8_t queue_id)
204 RTE_SET_USED(queue_id);
208 ssovf_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
209 const struct rte_event_queue_conf *queue_conf)
212 ssovf_func_trace("queue=%d prio=%d", queue_id, queue_conf->priority);
214 return ssovf_mbox_priority_set(queue_id, queue_conf->priority);
218 ssovf_port_def_conf(struct rte_eventdev *dev, uint8_t port_id,
219 struct rte_event_port_conf *port_conf)
221 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
223 RTE_SET_USED(port_id);
224 port_conf->new_event_threshold = edev->max_num_events;
225 port_conf->dequeue_depth = 1;
226 port_conf->enqueue_depth = 1;
230 ssovf_port_release(void *port)
236 ssovf_port_setup(struct rte_eventdev *dev, uint8_t port_id,
237 const struct rte_event_port_conf *port_conf)
242 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
244 ssovf_func_trace("port=%d", port_id);
245 RTE_SET_USED(port_conf);
247 /* Free memory prior to re-allocation if needed */
248 if (dev->data->ports[port_id] != NULL) {
249 ssovf_port_release(dev->data->ports[port_id]);
250 dev->data->ports[port_id] = NULL;
253 /* Allocate event port memory */
254 ws = rte_zmalloc_socket("eventdev ssows",
255 sizeof(struct ssows), RTE_CACHE_LINE_SIZE,
256 dev->data->socket_id);
258 ssovf_log_err("Failed to alloc memory for port=%d", port_id);
262 ws->base = octeontx_ssovf_bar(OCTEONTX_SSO_HWS, port_id, 0);
263 if (ws->base == NULL) {
265 ssovf_log_err("Failed to get hws base addr port=%d", port_id);
269 reg_off = SSOW_VHWS_OP_GET_WORK0;
270 reg_off |= 1 << 4; /* Index_ggrp_mask (Use maskset zero) */
271 reg_off |= 1 << 16; /* Wait */
272 ws->getwork = ws->base + reg_off;
275 for (q = 0; q < edev->nb_event_queues; q++) {
276 ws->grps[q] = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, q, 2);
277 if (ws->grps[q] == NULL) {
279 ssovf_log_err("Failed to get grp%d base addr", q);
284 dev->data->ports[port_id] = ws;
285 ssovf_log_dbg("port=%d ws=%p", port_id, ws);
290 ssovf_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
291 const uint8_t priorities[], uint16_t nb_links)
295 struct ssows *ws = port;
297 ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_links);
299 RTE_SET_USED(priorities);
301 for (link = 0; link < nb_links; link++) {
303 val |= (1ULL << 24); /* Set membership */
304 ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
306 return (int)nb_links;
310 ssovf_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
315 struct ssows *ws = port;
317 ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_unlinks);
320 for (unlink = 0; unlink < nb_unlinks; unlink++) {
321 val = queues[unlink];
322 val &= ~(1ULL << 24); /* Clear membership */
323 ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
325 return (int)nb_unlinks;
329 ssovf_timeout_ticks(struct rte_eventdev *dev, uint64_t ns, uint64_t *tmo_ticks)
333 return ssovf_mbox_timeout_ticks(ns, tmo_ticks);
337 ssows_dump(struct ssows *ws, FILE *f)
339 uint8_t *base = ws->base;
342 fprintf(f, "\t---------------port%d---------------\n", ws->port);
343 val = ssovf_read64(base + SSOW_VHWS_TAG);
344 fprintf(f, "\ttag=0x%x tt=%d head=%d tail=%d grp=%d index=%d tail=%d\n",
345 (uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
346 (int)(val >> 34) & 0x1, (int)(val >> 35) & 0x1,
347 (int)(val >> 36) & 0x3ff, (int)(val >> 48) & 0x3ff,
348 (int)(val >> 63) & 0x1);
350 val = ssovf_read64(base + SSOW_VHWS_WQP);
351 fprintf(f, "\twqp=0x%"PRIx64"\n", val);
353 val = ssovf_read64(base + SSOW_VHWS_LINKS);
354 fprintf(f, "\tindex=%d valid=%d revlink=%d tail=%d head=%d grp=%d\n",
355 (int)(val & 0x3ff), (int)(val >> 10) & 0x1,
356 (int)(val >> 11) & 0x3ff, (int)(val >> 26) & 0x1,
357 (int)(val >> 27) & 0x1, (int)(val >> 28) & 0x3ff);
359 val = ssovf_read64(base + SSOW_VHWS_PENDTAG);
360 fprintf(f, "\tptag=0x%x ptt=%d pgwi=%d pdesc=%d pgw=%d pgww=%d ps=%d\n",
361 (uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
362 (int)(val >> 56) & 0x1, (int)(val >> 58) & 0x1,
363 (int)(val >> 61) & 0x1, (int)(val >> 62) & 0x1,
364 (int)(val >> 63) & 0x1);
366 val = ssovf_read64(base + SSOW_VHWS_PENDWQP);
367 fprintf(f, "\tpwqp=0x%"PRIx64"\n", val);
371 ssovf_eth_rx_adapter_caps_get(const struct rte_eventdev *dev,
372 const struct rte_eth_dev *eth_dev, uint32_t *caps)
377 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
379 *caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
381 *caps = RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT;
387 ssovf_eth_rx_adapter_queue_add(const struct rte_eventdev *dev,
388 const struct rte_eth_dev *eth_dev, int32_t rx_queue_id,
389 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
392 const struct octeontx_nic *nic = eth_dev->data->dev_private;
393 pki_mod_qos_t pki_qos;
396 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
400 if (rx_queue_id >= 0)
403 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
406 memset(&pki_qos, 0, sizeof(pki_mod_qos_t));
408 pki_qos.port_type = 0;
410 pki_qos.mmask.f_tag_type = 1;
411 pki_qos.mmask.f_port_add = 1;
412 pki_qos.mmask.f_grp_ok = 1;
413 pki_qos.mmask.f_grp_bad = 1;
414 pki_qos.mmask.f_grptag_ok = 1;
415 pki_qos.mmask.f_grptag_bad = 1;
417 pki_qos.tag_type = queue_conf->ev.sched_type;
418 pki_qos.qos_entry.port_add = 0;
419 pki_qos.qos_entry.ggrp_ok = queue_conf->ev.queue_id;
420 pki_qos.qos_entry.ggrp_bad = queue_conf->ev.queue_id;
421 pki_qos.qos_entry.grptag_bad = 0;
422 pki_qos.qos_entry.grptag_ok = 0;
424 ret = octeontx_pki_port_modify_qos(nic->port_id, &pki_qos);
426 ssovf_log_err("failed to modify QOS, port=%d, q=%d",
427 nic->port_id, queue_conf->ev.queue_id);
433 ssovf_eth_rx_adapter_queue_del(const struct rte_eventdev *dev,
434 const struct rte_eth_dev *eth_dev, int32_t rx_queue_id)
437 const struct octeontx_nic *nic = eth_dev->data->dev_private;
438 pki_del_qos_t pki_qos;
440 RTE_SET_USED(rx_queue_id);
442 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
446 pki_qos.port_type = 0;
448 memset(&pki_qos, 0, sizeof(pki_del_qos_t));
449 ret = octeontx_pki_port_delete_qos(nic->port_id, &pki_qos);
451 ssovf_log_err("Failed to delete QOS port=%d, q=%d",
452 nic->port_id, queue_conf->ev.queue_id);
457 ssovf_eth_rx_adapter_start(const struct rte_eventdev *dev,
458 const struct rte_eth_dev *eth_dev)
461 const struct octeontx_nic *nic = eth_dev->data->dev_private;
464 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
467 octeontx_pki_port_start(nic->port_id);
473 ssovf_eth_rx_adapter_stop(const struct rte_eventdev *dev,
474 const struct rte_eth_dev *eth_dev)
477 const struct octeontx_nic *nic = eth_dev->data->dev_private;
480 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
483 octeontx_pki_port_stop(nic->port_id);
488 ssovf_dump(struct rte_eventdev *dev, FILE *f)
490 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
493 /* Dump SSOWVF debug registers */
494 for (port = 0; port < edev->nb_event_ports; port++)
495 ssows_dump(dev->data->ports[port], f);
499 ssovf_start(struct rte_eventdev *dev)
501 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
507 for (i = 0; i < edev->nb_event_ports; i++) {
508 ws = dev->data->ports[i];
513 for (i = 0; i < edev->nb_event_queues; i++) {
514 /* Consume all the events through HWS0 */
515 ssows_flush_events(dev->data->ports[0], i);
517 base = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
518 base += SSO_VHGRP_QCTL;
519 ssovf_write64(1, base); /* Enable SSO group */
522 ssovf_fastpath_fns_set(dev);
527 ssovf_stop(struct rte_eventdev *dev)
529 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
535 for (i = 0; i < edev->nb_event_ports; i++) {
536 ws = dev->data->ports[i];
541 for (i = 0; i < edev->nb_event_queues; i++) {
542 /* Consume all the events through HWS0 */
543 ssows_flush_events(dev->data->ports[0], i);
545 base = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
546 base += SSO_VHGRP_QCTL;
547 ssovf_write64(0, base); /* Disable SSO group */
552 ssovf_close(struct rte_eventdev *dev)
554 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
555 uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
558 for (i = 0; i < edev->nb_event_queues; i++)
561 for (i = 0; i < edev->nb_event_ports; i++)
562 ssovf_port_unlink(dev, dev->data->ports[i], all_queues,
563 edev->nb_event_queues);
567 /* Initialize and register event driver with DPDK Application */
568 static const struct rte_eventdev_ops ssovf_ops = {
569 .dev_infos_get = ssovf_info_get,
570 .dev_configure = ssovf_configure,
571 .queue_def_conf = ssovf_queue_def_conf,
572 .queue_setup = ssovf_queue_setup,
573 .queue_release = ssovf_queue_release,
574 .port_def_conf = ssovf_port_def_conf,
575 .port_setup = ssovf_port_setup,
576 .port_release = ssovf_port_release,
577 .port_link = ssovf_port_link,
578 .port_unlink = ssovf_port_unlink,
579 .timeout_ticks = ssovf_timeout_ticks,
581 .eth_rx_adapter_caps_get = ssovf_eth_rx_adapter_caps_get,
582 .eth_rx_adapter_queue_add = ssovf_eth_rx_adapter_queue_add,
583 .eth_rx_adapter_queue_del = ssovf_eth_rx_adapter_queue_del,
584 .eth_rx_adapter_start = ssovf_eth_rx_adapter_start,
585 .eth_rx_adapter_stop = ssovf_eth_rx_adapter_stop,
588 .dev_start = ssovf_start,
589 .dev_stop = ssovf_stop,
590 .dev_close = ssovf_close
594 ssovf_vdev_probe(struct rte_vdev_device *vdev)
596 struct octeontx_ssovf_info oinfo;
597 struct ssovf_mbox_dev_info info;
598 struct ssovf_evdev *edev;
599 struct rte_eventdev *eventdev;
600 static int ssovf_init_once;
604 name = rte_vdev_device_name(vdev);
605 /* More than one instance is not supported */
606 if (ssovf_init_once) {
607 ssovf_log_err("Request to create >1 %s instance", name);
611 eventdev = rte_event_pmd_vdev_init(name, sizeof(struct ssovf_evdev),
613 if (eventdev == NULL) {
614 ssovf_log_err("Failed to create eventdev vdev %s", name);
617 eventdev->dev_ops = &ssovf_ops;
619 /* For secondary processes, the primary has done all the work */
620 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
621 ssovf_fastpath_fns_set(eventdev);
625 ret = octeontx_ssovf_info(&oinfo);
627 ssovf_log_err("Failed to probe and validate ssovfs %d", ret);
631 edev = ssovf_pmd_priv(eventdev);
632 edev->max_event_ports = oinfo.total_ssowvfs;
633 edev->max_event_queues = oinfo.total_ssovfs;
634 edev->is_timeout_deq = 0;
636 ret = ssovf_mbox_dev_info(&info);
637 if (ret < 0 || ret != sizeof(struct ssovf_mbox_dev_info)) {
638 ssovf_log_err("Failed to get mbox devinfo %d", ret);
642 edev->min_deq_timeout_ns = info.min_deq_timeout_ns;
643 edev->max_deq_timeout_ns = info.max_deq_timeout_ns;
644 edev->max_num_events = info.max_num_events;
645 ssovf_log_dbg("min_deq_tmo=%"PRId64" max_deq_tmo=%"PRId64" max_evts=%d",
646 info.min_deq_timeout_ns, info.max_deq_timeout_ns,
647 info.max_num_events);
649 if (!edev->max_event_ports || !edev->max_event_queues) {
650 ssovf_log_err("Not enough eventdev resource queues=%d ports=%d",
651 edev->max_event_queues, edev->max_event_ports);
656 ssovf_log_info("Initializing %s domain=%d max_queues=%d max_ports=%d",
657 name, oinfo.domain, edev->max_event_queues,
658 edev->max_event_ports);
664 rte_event_pmd_vdev_uninit(name);
669 ssovf_vdev_remove(struct rte_vdev_device *vdev)
673 name = rte_vdev_device_name(vdev);
674 ssovf_log_info("Closing %s", name);
675 return rte_event_pmd_vdev_uninit(name);
678 static struct rte_vdev_driver vdev_ssovf_pmd = {
679 .probe = ssovf_vdev_probe,
680 .remove = ssovf_vdev_remove
683 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_OCTEONTX_PMD, vdev_ssovf_pmd);