event/octeontx: add framework for Rx/Tx offloads
[dpdk.git] / drivers / event / octeontx / ssovf_evdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Cavium, Inc
3  */
4
5 #include <inttypes.h>
6
7 #include <rte_common.h>
8 #include <rte_debug.h>
9 #include <rte_dev.h>
10 #include <rte_eal.h>
11 #include <rte_ethdev_driver.h>
12 #include <rte_event_eth_rx_adapter.h>
13 #include <rte_kvargs.h>
14 #include <rte_lcore.h>
15 #include <rte_log.h>
16 #include <rte_malloc.h>
17 #include <rte_memory.h>
18 #include <rte_bus_vdev.h>
19
20 #include "ssovf_evdev.h"
21 #include "timvf_evdev.h"
22
23 int otx_logtype_ssovf;
24 static uint8_t timvf_enable_stats;
25
26 RTE_INIT(otx_ssovf_init_log)
27 {
28         otx_logtype_ssovf = rte_log_register("pmd.event.octeontx");
29         if (otx_logtype_ssovf >= 0)
30                 rte_log_set_level(otx_logtype_ssovf, RTE_LOG_NOTICE);
31 }
32
33 /* SSOPF Mailbox messages */
34
35 struct ssovf_mbox_dev_info {
36         uint64_t min_deq_timeout_ns;
37         uint64_t max_deq_timeout_ns;
38         uint32_t max_num_events;
39 };
40
41 static int
42 ssovf_mbox_dev_info(struct ssovf_mbox_dev_info *info)
43 {
44         struct octeontx_mbox_hdr hdr = {0};
45         uint16_t len = sizeof(struct ssovf_mbox_dev_info);
46
47         hdr.coproc = SSO_COPROC;
48         hdr.msg = SSO_GET_DEV_INFO;
49         hdr.vfid = 0;
50
51         memset(info, 0, len);
52         return octeontx_mbox_send(&hdr, NULL, 0, info, len);
53 }
54
55 struct ssovf_mbox_getwork_wait {
56         uint64_t wait_ns;
57 };
58
59 static int
60 ssovf_mbox_getwork_tmo_set(uint32_t timeout_ns)
61 {
62         struct octeontx_mbox_hdr hdr = {0};
63         struct ssovf_mbox_getwork_wait tmo_set;
64         uint16_t len = sizeof(struct ssovf_mbox_getwork_wait);
65         int ret;
66
67         hdr.coproc = SSO_COPROC;
68         hdr.msg = SSO_SET_GETWORK_WAIT;
69         hdr.vfid = 0;
70
71         tmo_set.wait_ns = timeout_ns;
72         ret = octeontx_mbox_send(&hdr, &tmo_set, len, NULL, 0);
73         if (ret)
74                 ssovf_log_err("Failed to set getwork timeout(%d)", ret);
75
76         return ret;
77 }
78
79 struct ssovf_mbox_grp_pri {
80         uint8_t vhgrp_id;
81         uint8_t wgt_left; /* Read only */
82         uint8_t weight;
83         uint8_t affinity;
84         uint8_t priority;
85 };
86
87 static int
88 ssovf_mbox_priority_set(uint8_t queue, uint8_t prio)
89 {
90         struct octeontx_mbox_hdr hdr = {0};
91         struct ssovf_mbox_grp_pri grp;
92         uint16_t len = sizeof(struct ssovf_mbox_grp_pri);
93         int ret;
94
95         hdr.coproc = SSO_COPROC;
96         hdr.msg = SSO_GRP_SET_PRIORITY;
97         hdr.vfid = queue;
98
99         grp.vhgrp_id = queue;
100         grp.weight = 0xff;
101         grp.affinity = 0xff;
102         grp.priority = prio / 32; /* Normalize to 0 to 7 */
103
104         ret = octeontx_mbox_send(&hdr, &grp, len, NULL, 0);
105         if (ret)
106                 ssovf_log_err("Failed to set grp=%d prio=%d", queue, prio);
107
108         return ret;
109 }
110
111 struct ssovf_mbox_convert_ns_getworks_iter {
112         uint64_t wait_ns;
113         uint32_t getwork_iter;/* Get_work iterations for the given wait_ns */
114 };
115
116 static int
117 ssovf_mbox_timeout_ticks(uint64_t ns, uint64_t *tmo_ticks)
118 {
119         struct octeontx_mbox_hdr hdr = {0};
120         struct ssovf_mbox_convert_ns_getworks_iter ns2iter;
121         uint16_t len = sizeof(ns2iter);
122         int ret;
123
124         hdr.coproc = SSO_COPROC;
125         hdr.msg = SSO_CONVERT_NS_GETWORK_ITER;
126         hdr.vfid = 0;
127
128         memset(&ns2iter, 0, len);
129         ns2iter.wait_ns = ns;
130         ret = octeontx_mbox_send(&hdr, &ns2iter, len, &ns2iter, len);
131         if (ret < 0 || (ret != len)) {
132                 ssovf_log_err("Failed to get tmo ticks ns=%"PRId64"", ns);
133                 return -EIO;
134         }
135
136         *tmo_ticks = ns2iter.getwork_iter;
137         return 0;
138 }
139
140 static void
141 ssovf_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *dev_info)
142 {
143         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
144
145         dev_info->driver_name = RTE_STR(EVENTDEV_NAME_OCTEONTX_PMD);
146         dev_info->min_dequeue_timeout_ns = edev->min_deq_timeout_ns;
147         dev_info->max_dequeue_timeout_ns = edev->max_deq_timeout_ns;
148         dev_info->max_event_queues = edev->max_event_queues;
149         dev_info->max_event_queue_flows = (1ULL << 20);
150         dev_info->max_event_queue_priority_levels = 8;
151         dev_info->max_event_priority_levels = 1;
152         dev_info->max_event_ports = edev->max_event_ports;
153         dev_info->max_event_port_dequeue_depth = 1;
154         dev_info->max_event_port_enqueue_depth = 1;
155         dev_info->max_num_events =  edev->max_num_events;
156         dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_QUEUE_QOS |
157                                         RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
158                                         RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES|
159                                         RTE_EVENT_DEV_CAP_RUNTIME_PORT_LINK |
160                                         RTE_EVENT_DEV_CAP_MULTIPLE_QUEUE_PORT |
161                                         RTE_EVENT_DEV_CAP_NONSEQ_MODE;
162
163 }
164
165 static int
166 ssovf_configure(const struct rte_eventdev *dev)
167 {
168         struct rte_event_dev_config *conf = &dev->data->dev_conf;
169         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
170         uint64_t deq_tmo_ns;
171
172         ssovf_func_trace();
173         deq_tmo_ns = conf->dequeue_timeout_ns;
174         if (deq_tmo_ns == 0)
175                 deq_tmo_ns = edev->min_deq_timeout_ns;
176
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;
180         }
181         edev->nb_event_queues = conf->nb_event_queues;
182         edev->nb_event_ports = conf->nb_event_ports;
183
184         return ssovf_mbox_getwork_tmo_set(deq_tmo_ns);
185 }
186
187 static void
188 ssovf_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
189                                  struct rte_event_queue_conf *queue_conf)
190 {
191         RTE_SET_USED(dev);
192         RTE_SET_USED(queue_id);
193
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;
198 }
199
200 static void
201 ssovf_queue_release(struct rte_eventdev *dev, uint8_t queue_id)
202 {
203         RTE_SET_USED(dev);
204         RTE_SET_USED(queue_id);
205 }
206
207 static int
208 ssovf_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
209                               const struct rte_event_queue_conf *queue_conf)
210 {
211         RTE_SET_USED(dev);
212         ssovf_func_trace("queue=%d prio=%d", queue_id, queue_conf->priority);
213
214         return ssovf_mbox_priority_set(queue_id, queue_conf->priority);
215 }
216
217 static void
218 ssovf_port_def_conf(struct rte_eventdev *dev, uint8_t port_id,
219                                  struct rte_event_port_conf *port_conf)
220 {
221         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
222
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;
227         port_conf->disable_implicit_release = 0;
228 }
229
230 static void
231 ssovf_port_release(void *port)
232 {
233         rte_free(port);
234 }
235
236 static int
237 ssovf_port_setup(struct rte_eventdev *dev, uint8_t port_id,
238                                 const struct rte_event_port_conf *port_conf)
239 {
240         struct ssows *ws;
241         uint32_t reg_off;
242         uint8_t q;
243         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
244
245         ssovf_func_trace("port=%d", port_id);
246         RTE_SET_USED(port_conf);
247
248         /* Free memory prior to re-allocation if needed */
249         if (dev->data->ports[port_id] != NULL) {
250                 ssovf_port_release(dev->data->ports[port_id]);
251                 dev->data->ports[port_id] = NULL;
252         }
253
254         /* Allocate event port memory */
255         ws = rte_zmalloc_socket("eventdev ssows",
256                         sizeof(struct ssows), RTE_CACHE_LINE_SIZE,
257                         dev->data->socket_id);
258         if (ws == NULL) {
259                 ssovf_log_err("Failed to alloc memory for port=%d", port_id);
260                 return -ENOMEM;
261         }
262
263         ws->base = ssovf_bar(OCTEONTX_SSO_HWS, port_id, 0);
264         if (ws->base == NULL) {
265                 rte_free(ws);
266                 ssovf_log_err("Failed to get hws base addr port=%d", port_id);
267                 return -EINVAL;
268         }
269
270         reg_off = SSOW_VHWS_OP_GET_WORK0;
271         reg_off |= 1 << 4; /* Index_ggrp_mask (Use maskset zero) */
272         reg_off |= 1 << 16; /* Wait */
273         ws->getwork = ws->base + reg_off;
274         ws->port = port_id;
275
276         for (q = 0; q < edev->nb_event_queues; q++) {
277                 ws->grps[q] = ssovf_bar(OCTEONTX_SSO_GROUP, q, 2);
278                 if (ws->grps[q] == NULL) {
279                         rte_free(ws);
280                         ssovf_log_err("Failed to get grp%d base addr", q);
281                         return -EINVAL;
282                 }
283         }
284
285         dev->data->ports[port_id] = ws;
286         ssovf_log_dbg("port=%d ws=%p", port_id, ws);
287         return 0;
288 }
289
290 static int
291 ssovf_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
292                 const uint8_t priorities[], uint16_t nb_links)
293 {
294         uint16_t link;
295         uint64_t val;
296         struct ssows *ws = port;
297
298         ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_links);
299         RTE_SET_USED(dev);
300         RTE_SET_USED(priorities);
301
302         for (link = 0; link < nb_links; link++) {
303                 val = queues[link];
304                 val |= (1ULL << 24); /* Set membership */
305                 ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
306         }
307         return (int)nb_links;
308 }
309
310 static int
311 ssovf_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
312                         uint16_t nb_unlinks)
313 {
314         uint16_t unlink;
315         uint64_t val;
316         struct ssows *ws = port;
317
318         ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_unlinks);
319         RTE_SET_USED(dev);
320
321         for (unlink = 0; unlink < nb_unlinks; unlink++) {
322                 val = queues[unlink];
323                 val &= ~(1ULL << 24); /* Clear membership */
324                 ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
325         }
326         return (int)nb_unlinks;
327 }
328
329 static int
330 ssovf_timeout_ticks(struct rte_eventdev *dev, uint64_t ns, uint64_t *tmo_ticks)
331 {
332         RTE_SET_USED(dev);
333
334         return ssovf_mbox_timeout_ticks(ns, tmo_ticks);
335 }
336
337 static void
338 ssows_dump(struct ssows *ws, FILE *f)
339 {
340         uint8_t *base = ws->base;
341         uint64_t val;
342
343         fprintf(f, "\t---------------port%d---------------\n", ws->port);
344         val = ssovf_read64(base + SSOW_VHWS_TAG);
345         fprintf(f, "\ttag=0x%x tt=%d head=%d tail=%d grp=%d index=%d tail=%d\n",
346                 (uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
347                 (int)(val >> 34) & 0x1, (int)(val >> 35) & 0x1,
348                 (int)(val >> 36) & 0x3ff, (int)(val >> 48) & 0x3ff,
349                 (int)(val >> 63) & 0x1);
350
351         val = ssovf_read64(base + SSOW_VHWS_WQP);
352         fprintf(f, "\twqp=0x%"PRIx64"\n", val);
353
354         val = ssovf_read64(base + SSOW_VHWS_LINKS);
355         fprintf(f, "\tindex=%d valid=%d revlink=%d tail=%d head=%d grp=%d\n",
356                 (int)(val & 0x3ff), (int)(val >> 10) & 0x1,
357                 (int)(val >> 11) & 0x3ff, (int)(val >> 26) & 0x1,
358                 (int)(val >> 27) & 0x1, (int)(val >> 28) & 0x3ff);
359
360         val = ssovf_read64(base + SSOW_VHWS_PENDTAG);
361         fprintf(f, "\tptag=0x%x ptt=%d pgwi=%d pdesc=%d pgw=%d pgww=%d ps=%d\n",
362                 (uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
363                 (int)(val >> 56) & 0x1, (int)(val >> 58) & 0x1,
364                 (int)(val >> 61) & 0x1, (int)(val >> 62) & 0x1,
365                 (int)(val >> 63) & 0x1);
366
367         val = ssovf_read64(base + SSOW_VHWS_PENDWQP);
368         fprintf(f, "\tpwqp=0x%"PRIx64"\n", val);
369 }
370
371 static int
372 ssovf_eth_rx_adapter_caps_get(const struct rte_eventdev *dev,
373                 const struct rte_eth_dev *eth_dev, uint32_t *caps)
374 {
375         int ret;
376         RTE_SET_USED(dev);
377
378         ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
379         if (ret)
380                 *caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
381         else
382                 *caps = RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT;
383
384         return 0;
385 }
386
387 static int
388 ssovf_eth_rx_adapter_queue_add(const struct rte_eventdev *dev,
389                 const struct rte_eth_dev *eth_dev, int32_t rx_queue_id,
390                 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
391 {
392         int ret = 0;
393         const struct octeontx_nic *nic = eth_dev->data->dev_private;
394         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
395         pki_mod_qos_t pki_qos;
396         RTE_SET_USED(dev);
397
398         ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
399         if (ret)
400                 return -EINVAL;
401
402         if (rx_queue_id >= 0)
403                 return -EINVAL;
404
405         if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
406                 return -ENOTSUP;
407
408         memset(&pki_qos, 0, sizeof(pki_mod_qos_t));
409
410         pki_qos.port_type = 0;
411         pki_qos.index = 0;
412         pki_qos.mmask.f_tag_type = 1;
413         pki_qos.mmask.f_port_add = 1;
414         pki_qos.mmask.f_grp_ok = 1;
415         pki_qos.mmask.f_grp_bad = 1;
416         pki_qos.mmask.f_grptag_ok = 1;
417         pki_qos.mmask.f_grptag_bad = 1;
418
419         pki_qos.qos_entry.tag_type = queue_conf->ev.sched_type;
420         pki_qos.qos_entry.port_add = 0;
421         pki_qos.qos_entry.ggrp_ok = queue_conf->ev.queue_id;
422         pki_qos.qos_entry.ggrp_bad = queue_conf->ev.queue_id;
423         pki_qos.qos_entry.grptag_bad = 0;
424         pki_qos.qos_entry.grptag_ok = 0;
425
426         ret = octeontx_pki_port_modify_qos(nic->port_id, &pki_qos);
427         if (ret < 0)
428                 ssovf_log_err("failed to modify QOS, port=%d, q=%d",
429                                 nic->port_id, queue_conf->ev.queue_id);
430
431         edev->rx_offload_flags = nic->rx_offload_flags;
432         edev->tx_offload_flags = nic->tx_offload_flags;
433         return ret;
434 }
435
436 static int
437 ssovf_eth_rx_adapter_queue_del(const struct rte_eventdev *dev,
438                 const struct rte_eth_dev *eth_dev, int32_t rx_queue_id)
439 {
440         int ret = 0;
441         const struct octeontx_nic *nic = eth_dev->data->dev_private;
442         pki_del_qos_t pki_qos;
443         RTE_SET_USED(dev);
444
445         ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
446         if (ret)
447                 return -EINVAL;
448
449         pki_qos.port_type = 0;
450         pki_qos.index = 0;
451         memset(&pki_qos, 0, sizeof(pki_del_qos_t));
452         ret = octeontx_pki_port_delete_qos(nic->port_id, &pki_qos);
453         if (ret < 0)
454                 ssovf_log_err("Failed to delete QOS port=%d, q=%d",
455                                 nic->port_id, rx_queue_id);
456         return ret;
457 }
458
459 static int
460 ssovf_eth_rx_adapter_start(const struct rte_eventdev *dev,
461                                         const struct rte_eth_dev *eth_dev)
462 {
463         RTE_SET_USED(dev);
464         RTE_SET_USED(eth_dev);
465
466         return 0;
467 }
468
469
470 static int
471 ssovf_eth_rx_adapter_stop(const struct rte_eventdev *dev,
472                 const struct rte_eth_dev *eth_dev)
473 {
474         RTE_SET_USED(dev);
475         RTE_SET_USED(eth_dev);
476
477         return 0;
478 }
479
480 static int
481 ssovf_eth_tx_adapter_caps_get(const struct rte_eventdev *dev,
482                 const struct rte_eth_dev *eth_dev, uint32_t *caps)
483 {
484         int ret;
485         RTE_SET_USED(dev);
486
487         ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
488         if (ret)
489                 *caps = 0;
490         else
491                 *caps = RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT;
492
493         return 0;
494 }
495
496 static int
497 ssovf_eth_tx_adapter_create(uint8_t id, const struct rte_eventdev *dev)
498 {
499         RTE_SET_USED(id);
500         RTE_SET_USED(dev);
501         return 0;
502 }
503
504 static int
505 ssovf_eth_tx_adapter_free(uint8_t id, const struct rte_eventdev *dev)
506 {
507         RTE_SET_USED(id);
508         RTE_SET_USED(dev);
509         return 0;
510 }
511
512 static int
513 ssovf_eth_tx_adapter_queue_add(uint8_t id, const struct rte_eventdev *dev,
514                 const struct rte_eth_dev *eth_dev, int32_t tx_queue_id)
515 {
516         RTE_SET_USED(id);
517         RTE_SET_USED(dev);
518         RTE_SET_USED(eth_dev);
519         RTE_SET_USED(tx_queue_id);
520         return 0;
521 }
522
523 static int
524 ssovf_eth_tx_adapter_queue_del(uint8_t id, const struct rte_eventdev *dev,
525                 const struct rte_eth_dev *eth_dev, int32_t tx_queue_id)
526 {
527         RTE_SET_USED(id);
528         RTE_SET_USED(dev);
529         RTE_SET_USED(eth_dev);
530         RTE_SET_USED(tx_queue_id);
531         return 0;
532 }
533
534 static int
535 ssovf_eth_tx_adapter_start(uint8_t id, const struct rte_eventdev *dev)
536 {
537         RTE_SET_USED(id);
538         RTE_SET_USED(dev);
539         return 0;
540 }
541
542 static int
543 ssovf_eth_tx_adapter_stop(uint8_t id, const struct rte_eventdev *dev)
544 {
545         RTE_SET_USED(id);
546         RTE_SET_USED(dev);
547         return 0;
548 }
549
550
551 static void
552 ssovf_dump(struct rte_eventdev *dev, FILE *f)
553 {
554         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
555         uint8_t port;
556
557         /* Dump SSOWVF debug registers */
558         for (port = 0; port < edev->nb_event_ports; port++)
559                 ssows_dump(dev->data->ports[port], f);
560 }
561
562 static int
563 ssovf_start(struct rte_eventdev *dev)
564 {
565         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
566         struct ssows *ws;
567         uint8_t *base;
568         uint8_t i;
569
570         ssovf_func_trace();
571         for (i = 0; i < edev->nb_event_ports; i++) {
572                 ws = dev->data->ports[i];
573                 ssows_reset(ws);
574                 ws->swtag_req = 0;
575         }
576
577         for (i = 0; i < edev->nb_event_queues; i++) {
578                 /* Consume all the events through HWS0 */
579                 ssows_flush_events(dev->data->ports[0], i, NULL, NULL);
580
581                 base = ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
582                 base += SSO_VHGRP_QCTL;
583                 ssovf_write64(1, base); /* Enable SSO group */
584         }
585
586         ssovf_fastpath_fns_set(dev);
587         return 0;
588 }
589
590 static void
591 ssows_handle_event(void *arg, struct rte_event event)
592 {
593         struct rte_eventdev *dev = arg;
594
595         if (dev->dev_ops->dev_stop_flush != NULL)
596                 dev->dev_ops->dev_stop_flush(dev->data->dev_id, event,
597                                         dev->data->dev_stop_flush_arg);
598 }
599
600 static void
601 ssovf_stop(struct rte_eventdev *dev)
602 {
603         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
604         struct ssows *ws;
605         uint8_t *base;
606         uint8_t i;
607
608         ssovf_func_trace();
609         for (i = 0; i < edev->nb_event_ports; i++) {
610                 ws = dev->data->ports[i];
611                 ssows_reset(ws);
612                 ws->swtag_req = 0;
613         }
614
615         for (i = 0; i < edev->nb_event_queues; i++) {
616                 /* Consume all the events through HWS0 */
617                 ssows_flush_events(dev->data->ports[0], i,
618                                 ssows_handle_event, dev);
619
620                 base = ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
621                 base += SSO_VHGRP_QCTL;
622                 ssovf_write64(0, base); /* Disable SSO group */
623         }
624 }
625
626 static int
627 ssovf_close(struct rte_eventdev *dev)
628 {
629         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
630         uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
631         uint8_t i;
632
633         for (i = 0; i < edev->nb_event_queues; i++)
634                 all_queues[i] = i;
635
636         for (i = 0; i < edev->nb_event_ports; i++)
637                 ssovf_port_unlink(dev, dev->data->ports[i], all_queues,
638                         edev->nb_event_queues);
639         return 0;
640 }
641
642 static int
643 ssovf_selftest(const char *key __rte_unused, const char *value,
644                 void *opaque)
645 {
646         int *flag = opaque;
647         *flag = !!atoi(value);
648         return 0;
649 }
650
651 static int
652 ssovf_timvf_caps_get(const struct rte_eventdev *dev, uint64_t flags,
653                 uint32_t *caps, const struct rte_event_timer_adapter_ops **ops)
654 {
655         return timvf_timer_adapter_caps_get(dev, flags, caps, ops,
656                         timvf_enable_stats);
657 }
658
659 /* Initialize and register event driver with DPDK Application */
660 static struct rte_eventdev_ops ssovf_ops = {
661         .dev_infos_get    = ssovf_info_get,
662         .dev_configure    = ssovf_configure,
663         .queue_def_conf   = ssovf_queue_def_conf,
664         .queue_setup      = ssovf_queue_setup,
665         .queue_release    = ssovf_queue_release,
666         .port_def_conf    = ssovf_port_def_conf,
667         .port_setup       = ssovf_port_setup,
668         .port_release     = ssovf_port_release,
669         .port_link        = ssovf_port_link,
670         .port_unlink      = ssovf_port_unlink,
671         .timeout_ticks    = ssovf_timeout_ticks,
672
673         .eth_rx_adapter_caps_get  = ssovf_eth_rx_adapter_caps_get,
674         .eth_rx_adapter_queue_add = ssovf_eth_rx_adapter_queue_add,
675         .eth_rx_adapter_queue_del = ssovf_eth_rx_adapter_queue_del,
676         .eth_rx_adapter_start = ssovf_eth_rx_adapter_start,
677         .eth_rx_adapter_stop = ssovf_eth_rx_adapter_stop,
678
679         .eth_tx_adapter_caps_get = ssovf_eth_tx_adapter_caps_get,
680         .eth_tx_adapter_create = ssovf_eth_tx_adapter_create,
681         .eth_tx_adapter_free = ssovf_eth_tx_adapter_free,
682         .eth_tx_adapter_queue_add = ssovf_eth_tx_adapter_queue_add,
683         .eth_tx_adapter_queue_del = ssovf_eth_tx_adapter_queue_del,
684         .eth_tx_adapter_start = ssovf_eth_tx_adapter_start,
685         .eth_tx_adapter_stop = ssovf_eth_tx_adapter_stop,
686
687         .timer_adapter_caps_get = ssovf_timvf_caps_get,
688
689         .dev_selftest = test_eventdev_octeontx,
690
691         .dump             = ssovf_dump,
692         .dev_start        = ssovf_start,
693         .dev_stop         = ssovf_stop,
694         .dev_close        = ssovf_close
695 };
696
697 static int
698 ssovf_vdev_probe(struct rte_vdev_device *vdev)
699 {
700         struct ssovf_info oinfo;
701         struct ssovf_mbox_dev_info info;
702         struct ssovf_evdev *edev;
703         struct rte_eventdev *eventdev;
704         static int ssovf_init_once;
705         const char *name;
706         const char *params;
707         int ret;
708         int selftest = 0;
709
710         static const char *const args[] = {
711                 SSOVF_SELFTEST_ARG,
712                 TIMVF_ENABLE_STATS_ARG,
713                 NULL
714         };
715
716         name = rte_vdev_device_name(vdev);
717         /* More than one instance is not supported */
718         if (ssovf_init_once) {
719                 ssovf_log_err("Request to create >1 %s instance", name);
720                 return -EINVAL;
721         }
722
723         params = rte_vdev_device_args(vdev);
724         if (params != NULL && params[0] != '\0') {
725                 struct rte_kvargs *kvlist = rte_kvargs_parse(params, args);
726
727                 if (!kvlist) {
728                         ssovf_log_info(
729                                 "Ignoring unsupported params supplied '%s'",
730                                 name);
731                 } else {
732                         int ret = rte_kvargs_process(kvlist,
733                                         SSOVF_SELFTEST_ARG,
734                                         ssovf_selftest, &selftest);
735                         if (ret != 0) {
736                                 ssovf_log_err("%s: Error in selftest", name);
737                                 rte_kvargs_free(kvlist);
738                                 return ret;
739                         }
740
741                         ret = rte_kvargs_process(kvlist,
742                                         TIMVF_ENABLE_STATS_ARG,
743                                         ssovf_selftest, &timvf_enable_stats);
744                         if (ret != 0) {
745                                 ssovf_log_err("%s: Error in timvf stats", name);
746                                 rte_kvargs_free(kvlist);
747                                 return ret;
748                         }
749                 }
750
751                 rte_kvargs_free(kvlist);
752         }
753
754         eventdev = rte_event_pmd_vdev_init(name, sizeof(struct ssovf_evdev),
755                                 rte_socket_id());
756         if (eventdev == NULL) {
757                 ssovf_log_err("Failed to create eventdev vdev %s", name);
758                 return -ENOMEM;
759         }
760         eventdev->dev_ops = &ssovf_ops;
761
762         /* For secondary processes, the primary has done all the work */
763         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
764                 ssovf_fastpath_fns_set(eventdev);
765                 return 0;
766         }
767
768         octeontx_mbox_init();
769         ret = ssovf_info(&oinfo);
770         if (ret) {
771                 ssovf_log_err("Failed to probe and validate ssovfs %d", ret);
772                 goto error;
773         }
774
775         edev = ssovf_pmd_priv(eventdev);
776         edev->max_event_ports = oinfo.total_ssowvfs;
777         edev->max_event_queues = oinfo.total_ssovfs;
778         edev->is_timeout_deq = 0;
779
780         ret = ssovf_mbox_dev_info(&info);
781         if (ret < 0 || ret != sizeof(struct ssovf_mbox_dev_info)) {
782                 ssovf_log_err("Failed to get mbox devinfo %d", ret);
783                 goto error;
784         }
785
786         edev->min_deq_timeout_ns = info.min_deq_timeout_ns;
787         edev->max_deq_timeout_ns = info.max_deq_timeout_ns;
788         edev->max_num_events =  info.max_num_events;
789         ssovf_log_dbg("min_deq_tmo=%"PRId64" max_deq_tmo=%"PRId64" max_evts=%d",
790                         info.min_deq_timeout_ns, info.max_deq_timeout_ns,
791                         info.max_num_events);
792
793         if (!edev->max_event_ports || !edev->max_event_queues) {
794                 ssovf_log_err("Not enough eventdev resource queues=%d ports=%d",
795                         edev->max_event_queues, edev->max_event_ports);
796                 ret = -ENODEV;
797                 goto error;
798         }
799
800         ssovf_log_info("Initializing %s domain=%d max_queues=%d max_ports=%d",
801                         name, oinfo.domain, edev->max_event_queues,
802                         edev->max_event_ports);
803
804         ssovf_init_once = 1;
805         if (selftest)
806                 test_eventdev_octeontx();
807         return 0;
808
809 error:
810         rte_event_pmd_vdev_uninit(name);
811         return ret;
812 }
813
814 static int
815 ssovf_vdev_remove(struct rte_vdev_device *vdev)
816 {
817         const char *name;
818
819         name = rte_vdev_device_name(vdev);
820         ssovf_log_info("Closing %s", name);
821         return rte_event_pmd_vdev_uninit(name);
822 }
823
824 static struct rte_vdev_driver vdev_ssovf_pmd = {
825         .probe = ssovf_vdev_probe,
826         .remove = ssovf_vdev_remove
827 };
828
829 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_OCTEONTX_PMD, vdev_ssovf_pmd);