54512217ded0c9acdc34d736e1b9196580632456
[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.h>
12 #include <rte_event_eth_rx_adapter.h>
13 #include <rte_lcore.h>
14 #include <rte_log.h>
15 #include <rte_malloc.h>
16 #include <rte_memory.h>
17 #include <rte_bus_vdev.h>
18
19 #include "ssovf_evdev.h"
20
21 int otx_logtype_ssovf;
22
23 RTE_INIT(otx_ssovf_init_log);
24 static void
25 otx_ssovf_init_log(void)
26 {
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);
30 }
31
32 /* SSOPF Mailbox messages */
33
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;
38 };
39
40 static int
41 ssovf_mbox_dev_info(struct ssovf_mbox_dev_info *info)
42 {
43         struct octeontx_mbox_hdr hdr = {0};
44         uint16_t len = sizeof(struct ssovf_mbox_dev_info);
45
46         hdr.coproc = SSO_COPROC;
47         hdr.msg = SSO_GET_DEV_INFO;
48         hdr.vfid = 0;
49
50         memset(info, 0, len);
51         return octeontx_ssovf_mbox_send(&hdr, NULL, 0, info, len);
52 }
53
54 struct ssovf_mbox_getwork_wait {
55         uint64_t wait_ns;
56 };
57
58 static int
59 ssovf_mbox_getwork_tmo_set(uint32_t timeout_ns)
60 {
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);
64         int ret;
65
66         hdr.coproc = SSO_COPROC;
67         hdr.msg = SSO_SET_GETWORK_WAIT;
68         hdr.vfid = 0;
69
70         tmo_set.wait_ns = timeout_ns;
71         ret = octeontx_ssovf_mbox_send(&hdr, &tmo_set, len, NULL, 0);
72         if (ret)
73                 ssovf_log_err("Failed to set getwork timeout(%d)", ret);
74
75         return ret;
76 }
77
78 struct ssovf_mbox_grp_pri {
79         uint8_t wgt_left; /* Read only */
80         uint8_t weight;
81         uint8_t affinity;
82         uint8_t priority;
83 };
84
85 static int
86 ssovf_mbox_priority_set(uint8_t queue, uint8_t prio)
87 {
88         struct octeontx_mbox_hdr hdr = {0};
89         struct ssovf_mbox_grp_pri grp;
90         uint16_t len = sizeof(struct ssovf_mbox_grp_pri);
91         int ret;
92
93         hdr.coproc = SSO_COPROC;
94         hdr.msg = SSO_GRP_SET_PRIORITY;
95         hdr.vfid = queue;
96
97         grp.weight = 0xff;
98         grp.affinity = 0xff;
99         grp.priority = prio / 32; /* Normalize to 0 to 7 */
100
101         ret = octeontx_ssovf_mbox_send(&hdr, &grp, len, NULL, 0);
102         if (ret)
103                 ssovf_log_err("Failed to set grp=%d prio=%d", queue, prio);
104
105         return ret;
106 }
107
108 struct ssovf_mbox_convert_ns_getworks_iter {
109         uint64_t wait_ns;
110         uint32_t getwork_iter;/* Get_work iterations for the given wait_ns */
111 };
112
113 static int
114 ssovf_mbox_timeout_ticks(uint64_t ns, uint64_t *tmo_ticks)
115 {
116         struct octeontx_mbox_hdr hdr = {0};
117         struct ssovf_mbox_convert_ns_getworks_iter ns2iter;
118         uint16_t len = sizeof(ns2iter);
119         int ret;
120
121         hdr.coproc = SSO_COPROC;
122         hdr.msg = SSO_CONVERT_NS_GETWORK_ITER;
123         hdr.vfid = 0;
124
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);
130                 return -EIO;
131         }
132
133         *tmo_ticks = ns2iter.getwork_iter;
134         return 0;
135 }
136
137 static void
138 ssovf_fastpath_fns_set(struct rte_eventdev *dev)
139 {
140         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
141
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;
148
149         if (edev->is_timeout_deq) {
150                 dev->dequeue       = ssows_deq_timeout;
151                 dev->dequeue_burst = ssows_deq_timeout_burst;
152         }
153 }
154
155 static void
156 ssovf_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *dev_info)
157 {
158         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
159
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 }
175
176 static int
177 ssovf_configure(const struct rte_eventdev *dev)
178 {
179         struct rte_event_dev_config *conf = &dev->data->dev_conf;
180         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
181         uint64_t deq_tmo_ns;
182
183         ssovf_func_trace();
184         deq_tmo_ns = conf->dequeue_timeout_ns;
185         if (deq_tmo_ns == 0)
186                 deq_tmo_ns = edev->min_deq_timeout_ns;
187
188         if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT) {
189                 edev->is_timeout_deq = 1;
190                 deq_tmo_ns = edev->min_deq_timeout_ns;
191         }
192         edev->nb_event_queues = conf->nb_event_queues;
193         edev->nb_event_ports = conf->nb_event_ports;
194
195         return ssovf_mbox_getwork_tmo_set(deq_tmo_ns);
196 }
197
198 static void
199 ssovf_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
200                                  struct rte_event_queue_conf *queue_conf)
201 {
202         RTE_SET_USED(dev);
203         RTE_SET_USED(queue_id);
204
205         queue_conf->nb_atomic_flows = (1ULL << 20);
206         queue_conf->nb_atomic_order_sequences = (1ULL << 20);
207         queue_conf->event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
208         queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
209 }
210
211 static void
212 ssovf_queue_release(struct rte_eventdev *dev, uint8_t queue_id)
213 {
214         RTE_SET_USED(dev);
215         RTE_SET_USED(queue_id);
216 }
217
218 static int
219 ssovf_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
220                               const struct rte_event_queue_conf *queue_conf)
221 {
222         RTE_SET_USED(dev);
223         ssovf_func_trace("queue=%d prio=%d", queue_id, queue_conf->priority);
224
225         return ssovf_mbox_priority_set(queue_id, queue_conf->priority);
226 }
227
228 static void
229 ssovf_port_def_conf(struct rte_eventdev *dev, uint8_t port_id,
230                                  struct rte_event_port_conf *port_conf)
231 {
232         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
233
234         RTE_SET_USED(port_id);
235         port_conf->new_event_threshold = edev->max_num_events;
236         port_conf->dequeue_depth = 1;
237         port_conf->enqueue_depth = 1;
238         port_conf->disable_implicit_release = 0;
239 }
240
241 static void
242 ssovf_port_release(void *port)
243 {
244         rte_free(port);
245 }
246
247 static int
248 ssovf_port_setup(struct rte_eventdev *dev, uint8_t port_id,
249                                 const struct rte_event_port_conf *port_conf)
250 {
251         struct ssows *ws;
252         uint32_t reg_off;
253         uint8_t q;
254         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
255
256         ssovf_func_trace("port=%d", port_id);
257         RTE_SET_USED(port_conf);
258
259         /* Free memory prior to re-allocation if needed */
260         if (dev->data->ports[port_id] != NULL) {
261                 ssovf_port_release(dev->data->ports[port_id]);
262                 dev->data->ports[port_id] = NULL;
263         }
264
265         /* Allocate event port memory */
266         ws = rte_zmalloc_socket("eventdev ssows",
267                         sizeof(struct ssows), RTE_CACHE_LINE_SIZE,
268                         dev->data->socket_id);
269         if (ws == NULL) {
270                 ssovf_log_err("Failed to alloc memory for port=%d", port_id);
271                 return -ENOMEM;
272         }
273
274         ws->base = octeontx_ssovf_bar(OCTEONTX_SSO_HWS, port_id, 0);
275         if (ws->base == NULL) {
276                 rte_free(ws);
277                 ssovf_log_err("Failed to get hws base addr port=%d", port_id);
278                 return -EINVAL;
279         }
280
281         reg_off = SSOW_VHWS_OP_GET_WORK0;
282         reg_off |= 1 << 4; /* Index_ggrp_mask (Use maskset zero) */
283         reg_off |= 1 << 16; /* Wait */
284         ws->getwork = ws->base + reg_off;
285         ws->port = port_id;
286
287         for (q = 0; q < edev->nb_event_queues; q++) {
288                 ws->grps[q] = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, q, 2);
289                 if (ws->grps[q] == NULL) {
290                         rte_free(ws);
291                         ssovf_log_err("Failed to get grp%d base addr", q);
292                         return -EINVAL;
293                 }
294         }
295
296         dev->data->ports[port_id] = ws;
297         ssovf_log_dbg("port=%d ws=%p", port_id, ws);
298         return 0;
299 }
300
301 static int
302 ssovf_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
303                 const uint8_t priorities[], uint16_t nb_links)
304 {
305         uint16_t link;
306         uint64_t val;
307         struct ssows *ws = port;
308
309         ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_links);
310         RTE_SET_USED(dev);
311         RTE_SET_USED(priorities);
312
313         for (link = 0; link < nb_links; link++) {
314                 val = queues[link];
315                 val |= (1ULL << 24); /* Set membership */
316                 ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
317         }
318         return (int)nb_links;
319 }
320
321 static int
322 ssovf_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
323                         uint16_t nb_unlinks)
324 {
325         uint16_t unlink;
326         uint64_t val;
327         struct ssows *ws = port;
328
329         ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_unlinks);
330         RTE_SET_USED(dev);
331
332         for (unlink = 0; unlink < nb_unlinks; unlink++) {
333                 val = queues[unlink];
334                 val &= ~(1ULL << 24); /* Clear membership */
335                 ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
336         }
337         return (int)nb_unlinks;
338 }
339
340 static int
341 ssovf_timeout_ticks(struct rte_eventdev *dev, uint64_t ns, uint64_t *tmo_ticks)
342 {
343         RTE_SET_USED(dev);
344
345         return ssovf_mbox_timeout_ticks(ns, tmo_ticks);
346 }
347
348 static void
349 ssows_dump(struct ssows *ws, FILE *f)
350 {
351         uint8_t *base = ws->base;
352         uint64_t val;
353
354         fprintf(f, "\t---------------port%d---------------\n", ws->port);
355         val = ssovf_read64(base + SSOW_VHWS_TAG);
356         fprintf(f, "\ttag=0x%x tt=%d head=%d tail=%d grp=%d index=%d tail=%d\n",
357                 (uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
358                 (int)(val >> 34) & 0x1, (int)(val >> 35) & 0x1,
359                 (int)(val >> 36) & 0x3ff, (int)(val >> 48) & 0x3ff,
360                 (int)(val >> 63) & 0x1);
361
362         val = ssovf_read64(base + SSOW_VHWS_WQP);
363         fprintf(f, "\twqp=0x%"PRIx64"\n", val);
364
365         val = ssovf_read64(base + SSOW_VHWS_LINKS);
366         fprintf(f, "\tindex=%d valid=%d revlink=%d tail=%d head=%d grp=%d\n",
367                 (int)(val & 0x3ff), (int)(val >> 10) & 0x1,
368                 (int)(val >> 11) & 0x3ff, (int)(val >> 26) & 0x1,
369                 (int)(val >> 27) & 0x1, (int)(val >> 28) & 0x3ff);
370
371         val = ssovf_read64(base + SSOW_VHWS_PENDTAG);
372         fprintf(f, "\tptag=0x%x ptt=%d pgwi=%d pdesc=%d pgw=%d pgww=%d ps=%d\n",
373                 (uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
374                 (int)(val >> 56) & 0x1, (int)(val >> 58) & 0x1,
375                 (int)(val >> 61) & 0x1, (int)(val >> 62) & 0x1,
376                 (int)(val >> 63) & 0x1);
377
378         val = ssovf_read64(base + SSOW_VHWS_PENDWQP);
379         fprintf(f, "\tpwqp=0x%"PRIx64"\n", val);
380 }
381
382 static int
383 ssovf_eth_rx_adapter_caps_get(const struct rte_eventdev *dev,
384                 const struct rte_eth_dev *eth_dev, uint32_t *caps)
385 {
386         int ret;
387         RTE_SET_USED(dev);
388
389         ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
390         if (ret)
391                 *caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
392         else
393                 *caps = RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT;
394
395         return 0;
396 }
397
398 static int
399 ssovf_eth_rx_adapter_queue_add(const struct rte_eventdev *dev,
400                 const struct rte_eth_dev *eth_dev, int32_t rx_queue_id,
401                 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
402 {
403         int ret = 0;
404         const struct octeontx_nic *nic = eth_dev->data->dev_private;
405         pki_mod_qos_t pki_qos;
406         RTE_SET_USED(dev);
407
408         ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
409         if (ret)
410                 return -EINVAL;
411
412         if (rx_queue_id >= 0)
413                 return -EINVAL;
414
415         if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
416                 return -ENOTSUP;
417
418         memset(&pki_qos, 0, sizeof(pki_mod_qos_t));
419
420         pki_qos.port_type = 0;
421         pki_qos.index = 0;
422         pki_qos.mmask.f_tag_type = 1;
423         pki_qos.mmask.f_port_add = 1;
424         pki_qos.mmask.f_grp_ok = 1;
425         pki_qos.mmask.f_grp_bad = 1;
426         pki_qos.mmask.f_grptag_ok = 1;
427         pki_qos.mmask.f_grptag_bad = 1;
428
429         pki_qos.tag_type = queue_conf->ev.sched_type;
430         pki_qos.qos_entry.port_add = 0;
431         pki_qos.qos_entry.ggrp_ok = queue_conf->ev.queue_id;
432         pki_qos.qos_entry.ggrp_bad = queue_conf->ev.queue_id;
433         pki_qos.qos_entry.grptag_bad = 0;
434         pki_qos.qos_entry.grptag_ok = 0;
435
436         ret = octeontx_pki_port_modify_qos(nic->port_id, &pki_qos);
437         if (ret < 0)
438                 ssovf_log_err("failed to modify QOS, port=%d, q=%d",
439                                 nic->port_id, queue_conf->ev.queue_id);
440
441         return ret;
442 }
443
444 static int
445 ssovf_eth_rx_adapter_queue_del(const struct rte_eventdev *dev,
446                 const struct rte_eth_dev *eth_dev, int32_t rx_queue_id)
447 {
448         int ret = 0;
449         const struct octeontx_nic *nic = eth_dev->data->dev_private;
450         pki_del_qos_t pki_qos;
451         RTE_SET_USED(dev);
452         RTE_SET_USED(rx_queue_id);
453
454         ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
455         if (ret)
456                 return -EINVAL;
457
458         pki_qos.port_type = 0;
459         pki_qos.index = 0;
460         memset(&pki_qos, 0, sizeof(pki_del_qos_t));
461         ret = octeontx_pki_port_delete_qos(nic->port_id, &pki_qos);
462         if (ret < 0)
463                 ssovf_log_err("Failed to delete QOS port=%d, q=%d",
464                                 nic->port_id, queue_conf->ev.queue_id);
465         return ret;
466 }
467
468 static int
469 ssovf_eth_rx_adapter_start(const struct rte_eventdev *dev,
470                                         const struct rte_eth_dev *eth_dev)
471 {
472         int ret;
473         const struct octeontx_nic *nic = eth_dev->data->dev_private;
474         RTE_SET_USED(dev);
475
476         ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
477         if (ret)
478                 return 0;
479         octeontx_pki_port_start(nic->port_id);
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         int ret;
489         const struct octeontx_nic *nic = eth_dev->data->dev_private;
490         RTE_SET_USED(dev);
491
492         ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
493         if (ret)
494                 return 0;
495         octeontx_pki_port_stop(nic->port_id);
496         return 0;
497 }
498
499 static void
500 ssovf_dump(struct rte_eventdev *dev, FILE *f)
501 {
502         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
503         uint8_t port;
504
505         /* Dump SSOWVF debug registers */
506         for (port = 0; port < edev->nb_event_ports; port++)
507                 ssows_dump(dev->data->ports[port], f);
508 }
509
510 static int
511 ssovf_start(struct rte_eventdev *dev)
512 {
513         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
514         struct ssows *ws;
515         uint8_t *base;
516         uint8_t i;
517
518         ssovf_func_trace();
519         for (i = 0; i < edev->nb_event_ports; i++) {
520                 ws = dev->data->ports[i];
521                 ssows_reset(ws);
522                 ws->swtag_req = 0;
523         }
524
525         for (i = 0; i < edev->nb_event_queues; i++) {
526                 /* Consume all the events through HWS0 */
527                 ssows_flush_events(dev->data->ports[0], i);
528
529                 base = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
530                 base += SSO_VHGRP_QCTL;
531                 ssovf_write64(1, base); /* Enable SSO group */
532         }
533
534         ssovf_fastpath_fns_set(dev);
535         return 0;
536 }
537
538 static void
539 ssovf_stop(struct rte_eventdev *dev)
540 {
541         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
542         struct ssows *ws;
543         uint8_t *base;
544         uint8_t i;
545
546         ssovf_func_trace();
547         for (i = 0; i < edev->nb_event_ports; i++) {
548                 ws = dev->data->ports[i];
549                 ssows_reset(ws);
550                 ws->swtag_req = 0;
551         }
552
553         for (i = 0; i < edev->nb_event_queues; i++) {
554                 /* Consume all the events through HWS0 */
555                 ssows_flush_events(dev->data->ports[0], i);
556
557                 base = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
558                 base += SSO_VHGRP_QCTL;
559                 ssovf_write64(0, base); /* Disable SSO group */
560         }
561 }
562
563 static int
564 ssovf_close(struct rte_eventdev *dev)
565 {
566         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
567         uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
568         uint8_t i;
569
570         for (i = 0; i < edev->nb_event_queues; i++)
571                 all_queues[i] = i;
572
573         for (i = 0; i < edev->nb_event_ports; i++)
574                 ssovf_port_unlink(dev, dev->data->ports[i], all_queues,
575                         edev->nb_event_queues);
576         return 0;
577 }
578
579 /* Initialize and register event driver with DPDK Application */
580 static const struct rte_eventdev_ops ssovf_ops = {
581         .dev_infos_get    = ssovf_info_get,
582         .dev_configure    = ssovf_configure,
583         .queue_def_conf   = ssovf_queue_def_conf,
584         .queue_setup      = ssovf_queue_setup,
585         .queue_release    = ssovf_queue_release,
586         .port_def_conf    = ssovf_port_def_conf,
587         .port_setup       = ssovf_port_setup,
588         .port_release     = ssovf_port_release,
589         .port_link        = ssovf_port_link,
590         .port_unlink      = ssovf_port_unlink,
591         .timeout_ticks    = ssovf_timeout_ticks,
592
593         .eth_rx_adapter_caps_get  = ssovf_eth_rx_adapter_caps_get,
594         .eth_rx_adapter_queue_add = ssovf_eth_rx_adapter_queue_add,
595         .eth_rx_adapter_queue_del = ssovf_eth_rx_adapter_queue_del,
596         .eth_rx_adapter_start = ssovf_eth_rx_adapter_start,
597         .eth_rx_adapter_stop = ssovf_eth_rx_adapter_stop,
598
599         .dump             = ssovf_dump,
600         .dev_start        = ssovf_start,
601         .dev_stop         = ssovf_stop,
602         .dev_close        = ssovf_close
603 };
604
605 static int
606 ssovf_vdev_probe(struct rte_vdev_device *vdev)
607 {
608         struct octeontx_ssovf_info oinfo;
609         struct ssovf_mbox_dev_info info;
610         struct ssovf_evdev *edev;
611         struct rte_eventdev *eventdev;
612         static int ssovf_init_once;
613         const char *name;
614         int ret;
615
616         name = rte_vdev_device_name(vdev);
617         /* More than one instance is not supported */
618         if (ssovf_init_once) {
619                 ssovf_log_err("Request to create >1 %s instance", name);
620                 return -EINVAL;
621         }
622
623         eventdev = rte_event_pmd_vdev_init(name, sizeof(struct ssovf_evdev),
624                                 rte_socket_id());
625         if (eventdev == NULL) {
626                 ssovf_log_err("Failed to create eventdev vdev %s", name);
627                 return -ENOMEM;
628         }
629         eventdev->dev_ops = &ssovf_ops;
630
631         /* For secondary processes, the primary has done all the work */
632         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
633                 ssovf_fastpath_fns_set(eventdev);
634                 return 0;
635         }
636
637         ret = octeontx_ssovf_info(&oinfo);
638         if (ret) {
639                 ssovf_log_err("Failed to probe and validate ssovfs %d", ret);
640                 goto error;
641         }
642
643         edev = ssovf_pmd_priv(eventdev);
644         edev->max_event_ports = oinfo.total_ssowvfs;
645         edev->max_event_queues = oinfo.total_ssovfs;
646         edev->is_timeout_deq = 0;
647
648         ret = ssovf_mbox_dev_info(&info);
649         if (ret < 0 || ret != sizeof(struct ssovf_mbox_dev_info)) {
650                 ssovf_log_err("Failed to get mbox devinfo %d", ret);
651                 goto error;
652         }
653
654         edev->min_deq_timeout_ns = info.min_deq_timeout_ns;
655         edev->max_deq_timeout_ns = info.max_deq_timeout_ns;
656         edev->max_num_events =  info.max_num_events;
657         ssovf_log_dbg("min_deq_tmo=%"PRId64" max_deq_tmo=%"PRId64" max_evts=%d",
658                         info.min_deq_timeout_ns, info.max_deq_timeout_ns,
659                         info.max_num_events);
660
661         if (!edev->max_event_ports || !edev->max_event_queues) {
662                 ssovf_log_err("Not enough eventdev resource queues=%d ports=%d",
663                         edev->max_event_queues, edev->max_event_ports);
664                 ret = -ENODEV;
665                 goto error;
666         }
667
668         ssovf_log_info("Initializing %s domain=%d max_queues=%d max_ports=%d",
669                         name, oinfo.domain, edev->max_event_queues,
670                         edev->max_event_ports);
671
672         ssovf_init_once = 1;
673         return 0;
674
675 error:
676         rte_event_pmd_vdev_uninit(name);
677         return ret;
678 }
679
680 static int
681 ssovf_vdev_remove(struct rte_vdev_device *vdev)
682 {
683         const char *name;
684
685         name = rte_vdev_device_name(vdev);
686         ssovf_log_info("Closing %s", name);
687         return rte_event_pmd_vdev_uninit(name);
688 }
689
690 static struct rte_vdev_driver vdev_ssovf_pmd = {
691         .probe = ssovf_vdev_probe,
692         .remove = ssovf_vdev_remove
693 };
694
695 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_OCTEONTX_PMD, vdev_ssovf_pmd);