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