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