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