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