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 int otx_logtype_ssovf;
23 RTE_INIT(otx_ssovf_init_log);
25 otx_ssovf_init_log(void)
27 otx_logtype_ssovf = rte_log_register("pmd.otx.eventdev");
28 if (otx_logtype_ssovf >= 0)
29 rte_log_set_level(otx_logtype_ssovf, RTE_LOG_NOTICE);
32 /* SSOPF Mailbox messages */
34 struct ssovf_mbox_dev_info {
35 uint64_t min_deq_timeout_ns;
36 uint64_t max_deq_timeout_ns;
37 uint32_t max_num_events;
41 ssovf_mbox_dev_info(struct ssovf_mbox_dev_info *info)
43 struct octeontx_mbox_hdr hdr = {0};
44 uint16_t len = sizeof(struct ssovf_mbox_dev_info);
46 hdr.coproc = SSO_COPROC;
47 hdr.msg = SSO_GET_DEV_INFO;
51 return octeontx_ssovf_mbox_send(&hdr, NULL, 0, info, len);
54 struct ssovf_mbox_getwork_wait {
59 ssovf_mbox_getwork_tmo_set(uint32_t timeout_ns)
61 struct octeontx_mbox_hdr hdr = {0};
62 struct ssovf_mbox_getwork_wait tmo_set;
63 uint16_t len = sizeof(struct ssovf_mbox_getwork_wait);
66 hdr.coproc = SSO_COPROC;
67 hdr.msg = SSO_SET_GETWORK_WAIT;
70 tmo_set.wait_ns = timeout_ns;
71 ret = octeontx_ssovf_mbox_send(&hdr, &tmo_set, len, NULL, 0);
73 ssovf_log_err("Failed to set getwork timeout(%d)", ret);
78 struct ssovf_mbox_grp_pri {
79 uint8_t wgt_left; /* Read only */
86 ssovf_mbox_priority_set(uint8_t queue, uint8_t prio)
88 struct octeontx_mbox_hdr hdr = {0};
89 struct ssovf_mbox_grp_pri grp;
90 uint16_t len = sizeof(struct ssovf_mbox_grp_pri);
93 hdr.coproc = SSO_COPROC;
94 hdr.msg = SSO_GRP_SET_PRIORITY;
99 grp.priority = prio / 32; /* Normalize to 0 to 7 */
101 ret = octeontx_ssovf_mbox_send(&hdr, &grp, len, NULL, 0);
103 ssovf_log_err("Failed to set grp=%d prio=%d", queue, prio);
108 struct ssovf_mbox_convert_ns_getworks_iter {
110 uint32_t getwork_iter;/* Get_work iterations for the given wait_ns */
114 ssovf_mbox_timeout_ticks(uint64_t ns, uint64_t *tmo_ticks)
116 struct octeontx_mbox_hdr hdr = {0};
117 struct ssovf_mbox_convert_ns_getworks_iter ns2iter;
118 uint16_t len = sizeof(ns2iter);
121 hdr.coproc = SSO_COPROC;
122 hdr.msg = SSO_CONVERT_NS_GETWORK_ITER;
125 memset(&ns2iter, 0, len);
126 ns2iter.wait_ns = ns;
127 ret = octeontx_ssovf_mbox_send(&hdr, &ns2iter, len, &ns2iter, len);
128 if (ret < 0 || (ret != len)) {
129 ssovf_log_err("Failed to get tmo ticks ns=%"PRId64"", ns);
133 *tmo_ticks = ns2iter.getwork_iter;
138 ssovf_fastpath_fns_set(struct rte_eventdev *dev)
140 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
142 dev->enqueue = ssows_enq;
143 dev->enqueue_burst = ssows_enq_burst;
144 dev->enqueue_new_burst = ssows_enq_new_burst;
145 dev->enqueue_forward_burst = ssows_enq_fwd_burst;
146 dev->dequeue = ssows_deq;
147 dev->dequeue_burst = ssows_deq_burst;
149 if (edev->is_timeout_deq) {
150 dev->dequeue = ssows_deq_timeout;
151 dev->dequeue_burst = ssows_deq_timeout_burst;
156 ssovf_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *dev_info)
158 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
160 dev_info->driver_name = RTE_STR(EVENTDEV_NAME_OCTEONTX_PMD);
161 dev_info->min_dequeue_timeout_ns = edev->min_deq_timeout_ns;
162 dev_info->max_dequeue_timeout_ns = edev->max_deq_timeout_ns;
163 dev_info->max_event_queues = edev->max_event_queues;
164 dev_info->max_event_queue_flows = (1ULL << 20);
165 dev_info->max_event_queue_priority_levels = 8;
166 dev_info->max_event_priority_levels = 1;
167 dev_info->max_event_ports = edev->max_event_ports;
168 dev_info->max_event_port_dequeue_depth = 1;
169 dev_info->max_event_port_enqueue_depth = 1;
170 dev_info->max_num_events = edev->max_num_events;
171 dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_QUEUE_QOS |
172 RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
173 RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES|
174 RTE_EVENT_DEV_CAP_RUNTIME_PORT_LINK |
175 RTE_EVENT_DEV_CAP_MULTIPLE_QUEUE_PORT |
176 RTE_EVENT_DEV_CAP_NONSEQ_MODE;
181 ssovf_configure(const struct rte_eventdev *dev)
183 struct rte_event_dev_config *conf = &dev->data->dev_conf;
184 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
188 deq_tmo_ns = conf->dequeue_timeout_ns;
190 deq_tmo_ns = edev->min_deq_timeout_ns;
192 if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT) {
193 edev->is_timeout_deq = 1;
194 deq_tmo_ns = edev->min_deq_timeout_ns;
196 edev->nb_event_queues = conf->nb_event_queues;
197 edev->nb_event_ports = conf->nb_event_ports;
199 return ssovf_mbox_getwork_tmo_set(deq_tmo_ns);
203 ssovf_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
204 struct rte_event_queue_conf *queue_conf)
207 RTE_SET_USED(queue_id);
209 queue_conf->nb_atomic_flows = (1ULL << 20);
210 queue_conf->nb_atomic_order_sequences = (1ULL << 20);
211 queue_conf->event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
212 queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
216 ssovf_queue_release(struct rte_eventdev *dev, uint8_t queue_id)
219 RTE_SET_USED(queue_id);
223 ssovf_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
224 const struct rte_event_queue_conf *queue_conf)
227 ssovf_func_trace("queue=%d prio=%d", queue_id, queue_conf->priority);
229 return ssovf_mbox_priority_set(queue_id, queue_conf->priority);
233 ssovf_port_def_conf(struct rte_eventdev *dev, uint8_t port_id,
234 struct rte_event_port_conf *port_conf)
236 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
238 RTE_SET_USED(port_id);
239 port_conf->new_event_threshold = edev->max_num_events;
240 port_conf->dequeue_depth = 1;
241 port_conf->enqueue_depth = 1;
242 port_conf->disable_implicit_release = 0;
246 ssovf_port_release(void *port)
252 ssovf_port_setup(struct rte_eventdev *dev, uint8_t port_id,
253 const struct rte_event_port_conf *port_conf)
258 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
260 ssovf_func_trace("port=%d", port_id);
261 RTE_SET_USED(port_conf);
263 /* Free memory prior to re-allocation if needed */
264 if (dev->data->ports[port_id] != NULL) {
265 ssovf_port_release(dev->data->ports[port_id]);
266 dev->data->ports[port_id] = NULL;
269 /* Allocate event port memory */
270 ws = rte_zmalloc_socket("eventdev ssows",
271 sizeof(struct ssows), RTE_CACHE_LINE_SIZE,
272 dev->data->socket_id);
274 ssovf_log_err("Failed to alloc memory for port=%d", port_id);
278 ws->base = octeontx_ssovf_bar(OCTEONTX_SSO_HWS, port_id, 0);
279 if (ws->base == NULL) {
281 ssovf_log_err("Failed to get hws base addr port=%d", port_id);
285 reg_off = SSOW_VHWS_OP_GET_WORK0;
286 reg_off |= 1 << 4; /* Index_ggrp_mask (Use maskset zero) */
287 reg_off |= 1 << 16; /* Wait */
288 ws->getwork = ws->base + reg_off;
291 for (q = 0; q < edev->nb_event_queues; q++) {
292 ws->grps[q] = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, q, 2);
293 if (ws->grps[q] == NULL) {
295 ssovf_log_err("Failed to get grp%d base addr", q);
300 dev->data->ports[port_id] = ws;
301 ssovf_log_dbg("port=%d ws=%p", port_id, ws);
306 ssovf_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
307 const uint8_t priorities[], uint16_t nb_links)
311 struct ssows *ws = port;
313 ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_links);
315 RTE_SET_USED(priorities);
317 for (link = 0; link < nb_links; link++) {
319 val |= (1ULL << 24); /* Set membership */
320 ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
322 return (int)nb_links;
326 ssovf_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
331 struct ssows *ws = port;
333 ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_unlinks);
336 for (unlink = 0; unlink < nb_unlinks; unlink++) {
337 val = queues[unlink];
338 val &= ~(1ULL << 24); /* Clear membership */
339 ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
341 return (int)nb_unlinks;
345 ssovf_timeout_ticks(struct rte_eventdev *dev, uint64_t ns, uint64_t *tmo_ticks)
349 return ssovf_mbox_timeout_ticks(ns, tmo_ticks);
353 ssows_dump(struct ssows *ws, FILE *f)
355 uint8_t *base = ws->base;
358 fprintf(f, "\t---------------port%d---------------\n", ws->port);
359 val = ssovf_read64(base + SSOW_VHWS_TAG);
360 fprintf(f, "\ttag=0x%x tt=%d head=%d tail=%d grp=%d index=%d tail=%d\n",
361 (uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
362 (int)(val >> 34) & 0x1, (int)(val >> 35) & 0x1,
363 (int)(val >> 36) & 0x3ff, (int)(val >> 48) & 0x3ff,
364 (int)(val >> 63) & 0x1);
366 val = ssovf_read64(base + SSOW_VHWS_WQP);
367 fprintf(f, "\twqp=0x%"PRIx64"\n", val);
369 val = ssovf_read64(base + SSOW_VHWS_LINKS);
370 fprintf(f, "\tindex=%d valid=%d revlink=%d tail=%d head=%d grp=%d\n",
371 (int)(val & 0x3ff), (int)(val >> 10) & 0x1,
372 (int)(val >> 11) & 0x3ff, (int)(val >> 26) & 0x1,
373 (int)(val >> 27) & 0x1, (int)(val >> 28) & 0x3ff);
375 val = ssovf_read64(base + SSOW_VHWS_PENDTAG);
376 fprintf(f, "\tptag=0x%x ptt=%d pgwi=%d pdesc=%d pgw=%d pgww=%d ps=%d\n",
377 (uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
378 (int)(val >> 56) & 0x1, (int)(val >> 58) & 0x1,
379 (int)(val >> 61) & 0x1, (int)(val >> 62) & 0x1,
380 (int)(val >> 63) & 0x1);
382 val = ssovf_read64(base + SSOW_VHWS_PENDWQP);
383 fprintf(f, "\tpwqp=0x%"PRIx64"\n", val);
387 ssovf_eth_rx_adapter_caps_get(const struct rte_eventdev *dev,
388 const struct rte_eth_dev *eth_dev, uint32_t *caps)
393 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
395 *caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
397 *caps = RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT;
403 ssovf_eth_rx_adapter_queue_add(const struct rte_eventdev *dev,
404 const struct rte_eth_dev *eth_dev, int32_t rx_queue_id,
405 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
408 const struct octeontx_nic *nic = eth_dev->data->dev_private;
409 pki_mod_qos_t pki_qos;
412 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
416 if (rx_queue_id >= 0)
419 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
422 memset(&pki_qos, 0, sizeof(pki_mod_qos_t));
424 pki_qos.port_type = 0;
426 pki_qos.mmask.f_tag_type = 1;
427 pki_qos.mmask.f_port_add = 1;
428 pki_qos.mmask.f_grp_ok = 1;
429 pki_qos.mmask.f_grp_bad = 1;
430 pki_qos.mmask.f_grptag_ok = 1;
431 pki_qos.mmask.f_grptag_bad = 1;
433 pki_qos.tag_type = queue_conf->ev.sched_type;
434 pki_qos.qos_entry.port_add = 0;
435 pki_qos.qos_entry.ggrp_ok = queue_conf->ev.queue_id;
436 pki_qos.qos_entry.ggrp_bad = queue_conf->ev.queue_id;
437 pki_qos.qos_entry.grptag_bad = 0;
438 pki_qos.qos_entry.grptag_ok = 0;
440 ret = octeontx_pki_port_modify_qos(nic->port_id, &pki_qos);
442 ssovf_log_err("failed to modify QOS, port=%d, q=%d",
443 nic->port_id, queue_conf->ev.queue_id);
449 ssovf_eth_rx_adapter_queue_del(const struct rte_eventdev *dev,
450 const struct rte_eth_dev *eth_dev, int32_t rx_queue_id)
453 const struct octeontx_nic *nic = eth_dev->data->dev_private;
454 pki_del_qos_t pki_qos;
456 RTE_SET_USED(rx_queue_id);
458 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
462 pki_qos.port_type = 0;
464 memset(&pki_qos, 0, sizeof(pki_del_qos_t));
465 ret = octeontx_pki_port_delete_qos(nic->port_id, &pki_qos);
467 ssovf_log_err("Failed to delete QOS port=%d, q=%d",
468 nic->port_id, queue_conf->ev.queue_id);
473 ssovf_eth_rx_adapter_start(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_start(nic->port_id);
489 ssovf_eth_rx_adapter_stop(const struct rte_eventdev *dev,
490 const struct rte_eth_dev *eth_dev)
493 const struct octeontx_nic *nic = eth_dev->data->dev_private;
496 ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
499 octeontx_pki_port_stop(nic->port_id);
504 ssovf_dump(struct rte_eventdev *dev, FILE *f)
506 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
509 /* Dump SSOWVF debug registers */
510 for (port = 0; port < edev->nb_event_ports; port++)
511 ssows_dump(dev->data->ports[port], f);
515 ssovf_start(struct rte_eventdev *dev)
517 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
523 for (i = 0; i < edev->nb_event_ports; i++) {
524 ws = dev->data->ports[i];
529 for (i = 0; i < edev->nb_event_queues; i++) {
530 /* Consume all the events through HWS0 */
531 ssows_flush_events(dev->data->ports[0], i);
533 base = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
534 base += SSO_VHGRP_QCTL;
535 ssovf_write64(1, base); /* Enable SSO group */
538 ssovf_fastpath_fns_set(dev);
543 ssovf_stop(struct rte_eventdev *dev)
545 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
551 for (i = 0; i < edev->nb_event_ports; i++) {
552 ws = dev->data->ports[i];
557 for (i = 0; i < edev->nb_event_queues; i++) {
558 /* Consume all the events through HWS0 */
559 ssows_flush_events(dev->data->ports[0], i);
561 base = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
562 base += SSO_VHGRP_QCTL;
563 ssovf_write64(0, base); /* Disable SSO group */
568 ssovf_close(struct rte_eventdev *dev)
570 struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
571 uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
574 for (i = 0; i < edev->nb_event_queues; i++)
577 for (i = 0; i < edev->nb_event_ports; i++)
578 ssovf_port_unlink(dev, dev->data->ports[i], all_queues,
579 edev->nb_event_queues);
583 /* Initialize and register event driver with DPDK Application */
584 static const struct rte_eventdev_ops ssovf_ops = {
585 .dev_infos_get = ssovf_info_get,
586 .dev_configure = ssovf_configure,
587 .queue_def_conf = ssovf_queue_def_conf,
588 .queue_setup = ssovf_queue_setup,
589 .queue_release = ssovf_queue_release,
590 .port_def_conf = ssovf_port_def_conf,
591 .port_setup = ssovf_port_setup,
592 .port_release = ssovf_port_release,
593 .port_link = ssovf_port_link,
594 .port_unlink = ssovf_port_unlink,
595 .timeout_ticks = ssovf_timeout_ticks,
597 .eth_rx_adapter_caps_get = ssovf_eth_rx_adapter_caps_get,
598 .eth_rx_adapter_queue_add = ssovf_eth_rx_adapter_queue_add,
599 .eth_rx_adapter_queue_del = ssovf_eth_rx_adapter_queue_del,
600 .eth_rx_adapter_start = ssovf_eth_rx_adapter_start,
601 .eth_rx_adapter_stop = ssovf_eth_rx_adapter_stop,
603 .dev_selftest = test_eventdev_octeontx,
606 .dev_start = ssovf_start,
607 .dev_stop = ssovf_stop,
608 .dev_close = ssovf_close
612 ssovf_vdev_probe(struct rte_vdev_device *vdev)
614 struct octeontx_ssovf_info oinfo;
615 struct ssovf_mbox_dev_info info;
616 struct ssovf_evdev *edev;
617 struct rte_eventdev *eventdev;
618 static int ssovf_init_once;
622 name = rte_vdev_device_name(vdev);
623 /* More than one instance is not supported */
624 if (ssovf_init_once) {
625 ssovf_log_err("Request to create >1 %s instance", name);
629 eventdev = rte_event_pmd_vdev_init(name, sizeof(struct ssovf_evdev),
631 if (eventdev == NULL) {
632 ssovf_log_err("Failed to create eventdev vdev %s", name);
635 eventdev->dev_ops = &ssovf_ops;
637 /* For secondary processes, the primary has done all the work */
638 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
639 ssovf_fastpath_fns_set(eventdev);
643 ret = octeontx_ssovf_info(&oinfo);
645 ssovf_log_err("Failed to probe and validate ssovfs %d", ret);
649 edev = ssovf_pmd_priv(eventdev);
650 edev->max_event_ports = oinfo.total_ssowvfs;
651 edev->max_event_queues = oinfo.total_ssovfs;
652 edev->is_timeout_deq = 0;
654 ret = ssovf_mbox_dev_info(&info);
655 if (ret < 0 || ret != sizeof(struct ssovf_mbox_dev_info)) {
656 ssovf_log_err("Failed to get mbox devinfo %d", ret);
660 edev->min_deq_timeout_ns = info.min_deq_timeout_ns;
661 edev->max_deq_timeout_ns = info.max_deq_timeout_ns;
662 edev->max_num_events = info.max_num_events;
663 ssovf_log_dbg("min_deq_tmo=%"PRId64" max_deq_tmo=%"PRId64" max_evts=%d",
664 info.min_deq_timeout_ns, info.max_deq_timeout_ns,
665 info.max_num_events);
667 if (!edev->max_event_ports || !edev->max_event_queues) {
668 ssovf_log_err("Not enough eventdev resource queues=%d ports=%d",
669 edev->max_event_queues, edev->max_event_ports);
674 ssovf_log_info("Initializing %s domain=%d max_queues=%d max_ports=%d",
675 name, oinfo.domain, edev->max_event_queues,
676 edev->max_event_ports);
682 rte_event_pmd_vdev_uninit(name);
687 ssovf_vdev_remove(struct rte_vdev_device *vdev)
691 name = rte_vdev_device_name(vdev);
692 ssovf_log_info("Closing %s", name);
693 return rte_event_pmd_vdev_uninit(name);
696 static struct rte_vdev_driver vdev_ssovf_pmd = {
697 .probe = ssovf_vdev_probe,
698 .remove = ssovf_vdev_remove
701 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_OCTEONTX_PMD, vdev_ssovf_pmd);