event/octeontx2: add device start function
[dpdk.git] / drivers / event / octeontx2 / otx2_evdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #include <inttypes.h>
6
7 #include <rte_bus_pci.h>
8 #include <rte_common.h>
9 #include <rte_eal.h>
10 #include <rte_eventdev_pmd_pci.h>
11 #include <rte_kvargs.h>
12 #include <rte_mbuf_pool_ops.h>
13 #include <rte_pci.h>
14
15 #include "otx2_evdev_stats.h"
16 #include "otx2_evdev.h"
17 #include "otx2_irq.h"
18
19 static inline int
20 sso_get_msix_offsets(const struct rte_eventdev *event_dev)
21 {
22         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
23         uint8_t nb_ports = dev->nb_event_ports * (dev->dual_ws ? 2 : 1);
24         struct otx2_mbox *mbox = dev->mbox;
25         struct msix_offset_rsp *msix_rsp;
26         int i, rc;
27
28         /* Get SSO and SSOW MSIX vector offsets */
29         otx2_mbox_alloc_msg_msix_offset(mbox);
30         rc = otx2_mbox_process_msg(mbox, (void *)&msix_rsp);
31
32         for (i = 0; i < nb_ports; i++)
33                 dev->ssow_msixoff[i] = msix_rsp->ssow_msixoff[i];
34
35         for (i = 0; i < dev->nb_event_queues; i++)
36                 dev->sso_msixoff[i] = msix_rsp->sso_msixoff[i];
37
38         return rc;
39 }
40
41 void
42 sso_fastpath_fns_set(struct rte_eventdev *event_dev)
43 {
44         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
45
46         event_dev->enqueue                      = otx2_ssogws_enq;
47         event_dev->enqueue_burst                = otx2_ssogws_enq_burst;
48         event_dev->enqueue_new_burst            = otx2_ssogws_enq_new_burst;
49         event_dev->enqueue_forward_burst        = otx2_ssogws_enq_fwd_burst;
50
51         event_dev->dequeue                      = otx2_ssogws_deq;
52         event_dev->dequeue_burst                = otx2_ssogws_deq_burst;
53         if (dev->is_timeout_deq) {
54                 event_dev->dequeue              = otx2_ssogws_deq_timeout;
55                 event_dev->dequeue_burst        = otx2_ssogws_deq_timeout_burst;
56         }
57
58         if (dev->dual_ws) {
59                 event_dev->enqueue              = otx2_ssogws_dual_enq;
60                 event_dev->enqueue_burst        = otx2_ssogws_dual_enq_burst;
61                 event_dev->enqueue_new_burst    =
62                                         otx2_ssogws_dual_enq_new_burst;
63                 event_dev->enqueue_forward_burst =
64                                         otx2_ssogws_dual_enq_fwd_burst;
65                 event_dev->dequeue              = otx2_ssogws_dual_deq;
66                 event_dev->dequeue_burst        = otx2_ssogws_dual_deq_burst;
67                 if (dev->is_timeout_deq) {
68                         event_dev->dequeue      = otx2_ssogws_dual_deq_timeout;
69                         event_dev->dequeue_burst =
70                                         otx2_ssogws_dual_deq_timeout_burst;
71                 }
72         }
73         rte_mb();
74 }
75
76 static void
77 otx2_sso_info_get(struct rte_eventdev *event_dev,
78                   struct rte_event_dev_info *dev_info)
79 {
80         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
81
82         dev_info->driver_name = RTE_STR(EVENTDEV_NAME_OCTEONTX2_PMD);
83         dev_info->min_dequeue_timeout_ns = dev->min_dequeue_timeout_ns;
84         dev_info->max_dequeue_timeout_ns = dev->max_dequeue_timeout_ns;
85         dev_info->max_event_queues = dev->max_event_queues;
86         dev_info->max_event_queue_flows = (1ULL << 20);
87         dev_info->max_event_queue_priority_levels = 8;
88         dev_info->max_event_priority_levels = 1;
89         dev_info->max_event_ports = dev->max_event_ports;
90         dev_info->max_event_port_dequeue_depth = 1;
91         dev_info->max_event_port_enqueue_depth = 1;
92         dev_info->max_num_events =  dev->max_num_events;
93         dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_QUEUE_QOS |
94                                         RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
95                                         RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES |
96                                         RTE_EVENT_DEV_CAP_RUNTIME_PORT_LINK |
97                                         RTE_EVENT_DEV_CAP_MULTIPLE_QUEUE_PORT |
98                                         RTE_EVENT_DEV_CAP_NONSEQ_MODE;
99 }
100
101 static void
102 sso_port_link_modify(struct otx2_ssogws *ws, uint8_t queue, uint8_t enable)
103 {
104         uintptr_t base = OTX2_SSOW_GET_BASE_ADDR(ws->getwrk_op);
105         uint64_t val;
106
107         val = queue;
108         val |= 0ULL << 12; /* SET 0 */
109         val |= 0x8000800080000000; /* Dont modify rest of the masks */
110         val |= (uint64_t)enable << 14;   /* Enable/Disable Membership. */
111
112         otx2_write64(val, base + SSOW_LF_GWS_GRPMSK_CHG);
113 }
114
115 static int
116 otx2_sso_port_link(struct rte_eventdev *event_dev, void *port,
117                    const uint8_t queues[], const uint8_t priorities[],
118                    uint16_t nb_links)
119 {
120         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
121         uint8_t port_id = 0;
122         uint16_t link;
123
124         RTE_SET_USED(priorities);
125         for (link = 0; link < nb_links; link++) {
126                 if (dev->dual_ws) {
127                         struct otx2_ssogws_dual *ws = port;
128
129                         port_id = ws->port;
130                         sso_port_link_modify((struct otx2_ssogws *)
131                                         &ws->ws_state[0], queues[link], true);
132                         sso_port_link_modify((struct otx2_ssogws *)
133                                         &ws->ws_state[1], queues[link], true);
134                 } else {
135                         struct otx2_ssogws *ws = port;
136
137                         port_id = ws->port;
138                         sso_port_link_modify(ws, queues[link], true);
139                 }
140         }
141         sso_func_trace("Port=%d nb_links=%d", port_id, nb_links);
142
143         return (int)nb_links;
144 }
145
146 static int
147 otx2_sso_port_unlink(struct rte_eventdev *event_dev, void *port,
148                      uint8_t queues[], uint16_t nb_unlinks)
149 {
150         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
151         uint8_t port_id = 0;
152         uint16_t unlink;
153
154         for (unlink = 0; unlink < nb_unlinks; unlink++) {
155                 if (dev->dual_ws) {
156                         struct otx2_ssogws_dual *ws = port;
157
158                         port_id = ws->port;
159                         sso_port_link_modify((struct otx2_ssogws *)
160                                         &ws->ws_state[0], queues[unlink],
161                                         false);
162                         sso_port_link_modify((struct otx2_ssogws *)
163                                         &ws->ws_state[1], queues[unlink],
164                                         false);
165                 } else {
166                         struct otx2_ssogws *ws = port;
167
168                         port_id = ws->port;
169                         sso_port_link_modify(ws, queues[unlink], false);
170                 }
171         }
172         sso_func_trace("Port=%d nb_unlinks=%d", port_id, nb_unlinks);
173
174         return (int)nb_unlinks;
175 }
176
177 static int
178 sso_hw_lf_cfg(struct otx2_mbox *mbox, enum otx2_sso_lf_type type,
179               uint16_t nb_lf, uint8_t attach)
180 {
181         if (attach) {
182                 struct rsrc_attach_req *req;
183
184                 req = otx2_mbox_alloc_msg_attach_resources(mbox);
185                 switch (type) {
186                 case SSO_LF_GGRP:
187                         req->sso = nb_lf;
188                         break;
189                 case SSO_LF_GWS:
190                         req->ssow = nb_lf;
191                         break;
192                 default:
193                         return -EINVAL;
194                 }
195                 req->modify = true;
196                 if (otx2_mbox_process(mbox) < 0)
197                         return -EIO;
198         } else {
199                 struct rsrc_detach_req *req;
200
201                 req = otx2_mbox_alloc_msg_detach_resources(mbox);
202                 switch (type) {
203                 case SSO_LF_GGRP:
204                         req->sso = true;
205                         break;
206                 case SSO_LF_GWS:
207                         req->ssow = true;
208                         break;
209                 default:
210                         return -EINVAL;
211                 }
212                 req->partial = true;
213                 if (otx2_mbox_process(mbox) < 0)
214                         return -EIO;
215         }
216
217         return 0;
218 }
219
220 static int
221 sso_lf_cfg(struct otx2_sso_evdev *dev, struct otx2_mbox *mbox,
222            enum otx2_sso_lf_type type, uint16_t nb_lf, uint8_t alloc)
223 {
224         void *rsp;
225         int rc;
226
227         if (alloc) {
228                 switch (type) {
229                 case SSO_LF_GGRP:
230                         {
231                         struct sso_lf_alloc_req *req_ggrp;
232                         req_ggrp = otx2_mbox_alloc_msg_sso_lf_alloc(mbox);
233                         req_ggrp->hwgrps = nb_lf;
234                         }
235                         break;
236                 case SSO_LF_GWS:
237                         {
238                         struct ssow_lf_alloc_req *req_hws;
239                         req_hws = otx2_mbox_alloc_msg_ssow_lf_alloc(mbox);
240                         req_hws->hws = nb_lf;
241                         }
242                         break;
243                 default:
244                         return -EINVAL;
245                 }
246         } else {
247                 switch (type) {
248                 case SSO_LF_GGRP:
249                         {
250                         struct sso_lf_free_req *req_ggrp;
251                         req_ggrp = otx2_mbox_alloc_msg_sso_lf_free(mbox);
252                         req_ggrp->hwgrps = nb_lf;
253                         }
254                         break;
255                 case SSO_LF_GWS:
256                         {
257                         struct ssow_lf_free_req *req_hws;
258                         req_hws = otx2_mbox_alloc_msg_ssow_lf_free(mbox);
259                         req_hws->hws = nb_lf;
260                         }
261                         break;
262                 default:
263                         return -EINVAL;
264                 }
265         }
266
267         rc = otx2_mbox_process_msg_tmo(mbox, (void **)&rsp, ~0);
268         if (rc < 0)
269                 return rc;
270
271         if (alloc && type == SSO_LF_GGRP) {
272                 struct sso_lf_alloc_rsp *rsp_ggrp = rsp;
273
274                 dev->xaq_buf_size = rsp_ggrp->xaq_buf_size;
275                 dev->xae_waes = rsp_ggrp->xaq_wq_entries;
276                 dev->iue = rsp_ggrp->in_unit_entries;
277         }
278
279         return 0;
280 }
281
282 static void
283 otx2_sso_port_release(void *port)
284 {
285         rte_free(port);
286 }
287
288 static void
289 otx2_sso_queue_release(struct rte_eventdev *event_dev, uint8_t queue_id)
290 {
291         RTE_SET_USED(event_dev);
292         RTE_SET_USED(queue_id);
293 }
294
295 static void
296 sso_clr_links(const struct rte_eventdev *event_dev)
297 {
298         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
299         int i, j;
300
301         for (i = 0; i < dev->nb_event_ports; i++) {
302                 if (dev->dual_ws) {
303                         struct otx2_ssogws_dual *ws;
304
305                         ws = event_dev->data->ports[i];
306                         for (j = 0; j < dev->nb_event_queues; j++) {
307                                 sso_port_link_modify((struct otx2_ssogws *)
308                                                 &ws->ws_state[0], j, false);
309                                 sso_port_link_modify((struct otx2_ssogws *)
310                                                 &ws->ws_state[1], j, false);
311                         }
312                 } else {
313                         struct otx2_ssogws *ws;
314
315                         ws = event_dev->data->ports[i];
316                         for (j = 0; j < dev->nb_event_queues; j++)
317                                 sso_port_link_modify(ws, j, false);
318                 }
319         }
320 }
321
322 static void
323 sso_set_port_ops(struct otx2_ssogws *ws, uintptr_t base)
324 {
325         ws->tag_op              = base + SSOW_LF_GWS_TAG;
326         ws->wqp_op              = base + SSOW_LF_GWS_WQP;
327         ws->getwrk_op           = base + SSOW_LF_GWS_OP_GET_WORK;
328         ws->swtp_op             = base + SSOW_LF_GWS_SWTP;
329         ws->swtag_norm_op       = base + SSOW_LF_GWS_OP_SWTAG_NORM;
330         ws->swtag_desched_op    = base + SSOW_LF_GWS_OP_SWTAG_DESCHED;
331 }
332
333 static int
334 sso_configure_dual_ports(const struct rte_eventdev *event_dev)
335 {
336         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
337         struct otx2_mbox *mbox = dev->mbox;
338         uint8_t vws = 0;
339         uint8_t nb_lf;
340         int i, rc;
341
342         otx2_sso_dbg("Configuring event ports %d", dev->nb_event_ports);
343
344         nb_lf = dev->nb_event_ports * 2;
345         /* Ask AF to attach required LFs. */
346         rc = sso_hw_lf_cfg(mbox, SSO_LF_GWS, nb_lf, true);
347         if (rc < 0) {
348                 otx2_err("Failed to attach SSO GWS LF");
349                 return -ENODEV;
350         }
351
352         if (sso_lf_cfg(dev, mbox, SSO_LF_GWS, nb_lf, true) < 0) {
353                 sso_hw_lf_cfg(mbox, SSO_LF_GWS, nb_lf, false);
354                 otx2_err("Failed to init SSO GWS LF");
355                 return -ENODEV;
356         }
357
358         for (i = 0; i < dev->nb_event_ports; i++) {
359                 struct otx2_ssogws_dual *ws;
360                 uintptr_t base;
361
362                 /* Free memory prior to re-allocation if needed */
363                 if (event_dev->data->ports[i] != NULL) {
364                         ws = event_dev->data->ports[i];
365                         rte_free(ws);
366                         ws = NULL;
367                 }
368
369                 /* Allocate event port memory */
370                 ws = rte_zmalloc_socket("otx2_sso_ws",
371                                         sizeof(struct otx2_ssogws_dual),
372                                         RTE_CACHE_LINE_SIZE,
373                                         event_dev->data->socket_id);
374                 if (ws == NULL) {
375                         otx2_err("Failed to alloc memory for port=%d", i);
376                         rc = -ENOMEM;
377                         break;
378                 }
379
380                 ws->port = i;
381                 base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | vws << 12);
382                 sso_set_port_ops((struct otx2_ssogws *)&ws->ws_state[0], base);
383                 vws++;
384
385                 base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | vws << 12);
386                 sso_set_port_ops((struct otx2_ssogws *)&ws->ws_state[1], base);
387                 vws++;
388
389                 event_dev->data->ports[i] = ws;
390         }
391
392         if (rc < 0) {
393                 sso_lf_cfg(dev, mbox, SSO_LF_GWS, nb_lf, false);
394                 sso_hw_lf_cfg(mbox, SSO_LF_GWS, nb_lf, false);
395         }
396
397         return rc;
398 }
399
400 static int
401 sso_configure_ports(const struct rte_eventdev *event_dev)
402 {
403         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
404         struct otx2_mbox *mbox = dev->mbox;
405         uint8_t nb_lf;
406         int i, rc;
407
408         otx2_sso_dbg("Configuring event ports %d", dev->nb_event_ports);
409
410         nb_lf = dev->nb_event_ports;
411         /* Ask AF to attach required LFs. */
412         rc = sso_hw_lf_cfg(mbox, SSO_LF_GWS, nb_lf, true);
413         if (rc < 0) {
414                 otx2_err("Failed to attach SSO GWS LF");
415                 return -ENODEV;
416         }
417
418         if (sso_lf_cfg(dev, mbox, SSO_LF_GWS, nb_lf, true) < 0) {
419                 sso_hw_lf_cfg(mbox, SSO_LF_GWS, nb_lf, false);
420                 otx2_err("Failed to init SSO GWS LF");
421                 return -ENODEV;
422         }
423
424         for (i = 0; i < nb_lf; i++) {
425                 struct otx2_ssogws *ws;
426                 uintptr_t base;
427
428                 /* Free memory prior to re-allocation if needed */
429                 if (event_dev->data->ports[i] != NULL) {
430                         ws = event_dev->data->ports[i];
431                         rte_free(ws);
432                         ws = NULL;
433                 }
434
435                 /* Allocate event port memory */
436                 ws = rte_zmalloc_socket("otx2_sso_ws",
437                                         sizeof(struct otx2_ssogws),
438                                         RTE_CACHE_LINE_SIZE,
439                                         event_dev->data->socket_id);
440                 if (ws == NULL) {
441                         otx2_err("Failed to alloc memory for port=%d", i);
442                         rc = -ENOMEM;
443                         break;
444                 }
445
446                 ws->port = i;
447                 base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | i << 12);
448                 sso_set_port_ops(ws, base);
449
450                 event_dev->data->ports[i] = ws;
451         }
452
453         if (rc < 0) {
454                 sso_lf_cfg(dev, mbox, SSO_LF_GWS, nb_lf, false);
455                 sso_hw_lf_cfg(mbox, SSO_LF_GWS, nb_lf, false);
456         }
457
458         return rc;
459 }
460
461 static int
462 sso_configure_queues(const struct rte_eventdev *event_dev)
463 {
464         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
465         struct otx2_mbox *mbox = dev->mbox;
466         uint8_t nb_lf;
467         int rc;
468
469         otx2_sso_dbg("Configuring event queues %d", dev->nb_event_queues);
470
471         nb_lf = dev->nb_event_queues;
472         /* Ask AF to attach required LFs. */
473         rc = sso_hw_lf_cfg(mbox, SSO_LF_GGRP, nb_lf, true);
474         if (rc < 0) {
475                 otx2_err("Failed to attach SSO GGRP LF");
476                 return -ENODEV;
477         }
478
479         if (sso_lf_cfg(dev, mbox, SSO_LF_GGRP, nb_lf, true) < 0) {
480                 sso_hw_lf_cfg(mbox, SSO_LF_GGRP, nb_lf, false);
481                 otx2_err("Failed to init SSO GGRP LF");
482                 return -ENODEV;
483         }
484
485         return rc;
486 }
487
488 static int
489 sso_xaq_allocate(struct otx2_sso_evdev *dev)
490 {
491         const struct rte_memzone *mz;
492         struct npa_aura_s *aura;
493         static int reconfig_cnt;
494         char pool_name[RTE_MEMZONE_NAMESIZE];
495         uint32_t xaq_cnt;
496         int rc;
497
498         if (dev->xaq_pool)
499                 rte_mempool_free(dev->xaq_pool);
500
501         /*
502          * Allocate memory for Add work backpressure.
503          */
504         mz = rte_memzone_lookup(OTX2_SSO_FC_NAME);
505         if (mz == NULL)
506                 mz = rte_memzone_reserve_aligned(OTX2_SSO_FC_NAME,
507                                                  OTX2_ALIGN +
508                                                  sizeof(struct npa_aura_s),
509                                                  rte_socket_id(),
510                                                  RTE_MEMZONE_IOVA_CONTIG,
511                                                  OTX2_ALIGN);
512         if (mz == NULL) {
513                 otx2_err("Failed to allocate mem for fcmem");
514                 return -ENOMEM;
515         }
516
517         dev->fc_iova = mz->iova;
518         dev->fc_mem = mz->addr;
519
520         aura = (struct npa_aura_s *)((uintptr_t)dev->fc_mem + OTX2_ALIGN);
521         memset(aura, 0, sizeof(struct npa_aura_s));
522
523         aura->fc_ena = 1;
524         aura->fc_addr = dev->fc_iova;
525         aura->fc_hyst_bits = 0; /* Store count on all updates */
526
527         /* Taken from HRM 14.3.3(4) */
528         xaq_cnt = dev->nb_event_queues * OTX2_SSO_XAQ_CACHE_CNT;
529         if (dev->xae_cnt)
530                 xaq_cnt += dev->xae_cnt / dev->xae_waes;
531         else
532                 xaq_cnt += (dev->iue / dev->xae_waes) +
533                         (OTX2_SSO_XAQ_SLACK * dev->nb_event_queues);
534
535         otx2_sso_dbg("Configuring %d xaq buffers", xaq_cnt);
536         /* Setup XAQ based on number of nb queues. */
537         snprintf(pool_name, 30, "otx2_xaq_buf_pool_%d", reconfig_cnt);
538         dev->xaq_pool = (void *)rte_mempool_create_empty(pool_name,
539                         xaq_cnt, dev->xaq_buf_size, 0, 0,
540                         rte_socket_id(), 0);
541
542         if (dev->xaq_pool == NULL) {
543                 otx2_err("Unable to create empty mempool.");
544                 rte_memzone_free(mz);
545                 return -ENOMEM;
546         }
547
548         rc = rte_mempool_set_ops_byname(dev->xaq_pool,
549                                         rte_mbuf_platform_mempool_ops(), aura);
550         if (rc != 0) {
551                 otx2_err("Unable to set xaqpool ops.");
552                 goto alloc_fail;
553         }
554
555         rc = rte_mempool_populate_default(dev->xaq_pool);
556         if (rc < 0) {
557                 otx2_err("Unable to set populate xaqpool.");
558                 goto alloc_fail;
559         }
560         reconfig_cnt++;
561         /* When SW does addwork (enqueue) check if there is space in XAQ by
562          * comparing fc_addr above against the xaq_lmt calculated below.
563          * There should be a minimum headroom (OTX2_SSO_XAQ_SLACK / 2) for SSO
564          * to request XAQ to cache them even before enqueue is called.
565          */
566         dev->xaq_lmt = xaq_cnt - (OTX2_SSO_XAQ_SLACK / 2 *
567                                   dev->nb_event_queues);
568         dev->nb_xaq_cfg = xaq_cnt;
569
570         return 0;
571 alloc_fail:
572         rte_mempool_free(dev->xaq_pool);
573         rte_memzone_free(mz);
574         return rc;
575 }
576
577 static int
578 sso_ggrp_alloc_xaq(struct otx2_sso_evdev *dev)
579 {
580         struct otx2_mbox *mbox = dev->mbox;
581         struct sso_hw_setconfig *req;
582
583         otx2_sso_dbg("Configuring XAQ for GGRPs");
584         req = otx2_mbox_alloc_msg_sso_hw_setconfig(mbox);
585         req->npa_pf_func = otx2_npa_pf_func_get();
586         req->npa_aura_id = npa_lf_aura_handle_to_aura(dev->xaq_pool->pool_id);
587         req->hwgrps = dev->nb_event_queues;
588
589         return otx2_mbox_process(mbox);
590 }
591
592 static void
593 sso_lf_teardown(struct otx2_sso_evdev *dev,
594                 enum otx2_sso_lf_type lf_type)
595 {
596         uint8_t nb_lf;
597
598         switch (lf_type) {
599         case SSO_LF_GGRP:
600                 nb_lf = dev->nb_event_queues;
601                 break;
602         case SSO_LF_GWS:
603                 nb_lf = dev->nb_event_ports;
604                 nb_lf *= dev->dual_ws ? 2 : 1;
605                 break;
606         default:
607                 return;
608         }
609
610         sso_lf_cfg(dev, dev->mbox, lf_type, nb_lf, false);
611         sso_hw_lf_cfg(dev->mbox, lf_type, nb_lf, false);
612 }
613
614 static int
615 otx2_sso_configure(const struct rte_eventdev *event_dev)
616 {
617         struct rte_event_dev_config *conf = &event_dev->data->dev_conf;
618         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
619         uint32_t deq_tmo_ns;
620         int rc;
621
622         sso_func_trace();
623         deq_tmo_ns = conf->dequeue_timeout_ns;
624
625         if (deq_tmo_ns == 0)
626                 deq_tmo_ns = dev->min_dequeue_timeout_ns;
627
628         if (deq_tmo_ns < dev->min_dequeue_timeout_ns ||
629             deq_tmo_ns > dev->max_dequeue_timeout_ns) {
630                 otx2_err("Unsupported dequeue timeout requested");
631                 return -EINVAL;
632         }
633
634         if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT)
635                 dev->is_timeout_deq = 1;
636
637         dev->deq_tmo_ns = deq_tmo_ns;
638
639         if (conf->nb_event_ports > dev->max_event_ports ||
640             conf->nb_event_queues > dev->max_event_queues) {
641                 otx2_err("Unsupported event queues/ports requested");
642                 return -EINVAL;
643         }
644
645         if (conf->nb_event_port_dequeue_depth > 1) {
646                 otx2_err("Unsupported event port deq depth requested");
647                 return -EINVAL;
648         }
649
650         if (conf->nb_event_port_enqueue_depth > 1) {
651                 otx2_err("Unsupported event port enq depth requested");
652                 return -EINVAL;
653         }
654
655         if (dev->configured)
656                 sso_unregister_irqs(event_dev);
657
658         if (dev->nb_event_queues) {
659                 /* Finit any previous queues. */
660                 sso_lf_teardown(dev, SSO_LF_GGRP);
661         }
662         if (dev->nb_event_ports) {
663                 /* Finit any previous ports. */
664                 sso_lf_teardown(dev, SSO_LF_GWS);
665         }
666
667         dev->nb_event_queues = conf->nb_event_queues;
668         dev->nb_event_ports = conf->nb_event_ports;
669
670         if (dev->dual_ws)
671                 rc = sso_configure_dual_ports(event_dev);
672         else
673                 rc = sso_configure_ports(event_dev);
674
675         if (rc < 0) {
676                 otx2_err("Failed to configure event ports");
677                 return -ENODEV;
678         }
679
680         if (sso_configure_queues(event_dev) < 0) {
681                 otx2_err("Failed to configure event queues");
682                 rc = -ENODEV;
683                 goto teardown_hws;
684         }
685
686         if (sso_xaq_allocate(dev) < 0) {
687                 rc = -ENOMEM;
688                 goto teardown_hwggrp;
689         }
690
691         /* Clear any prior port-queue mapping. */
692         sso_clr_links(event_dev);
693         rc = sso_ggrp_alloc_xaq(dev);
694         if (rc < 0) {
695                 otx2_err("Failed to alloc xaq to ggrp %d", rc);
696                 goto teardown_hwggrp;
697         }
698
699         rc = sso_get_msix_offsets(event_dev);
700         if (rc < 0) {
701                 otx2_err("Failed to get msix offsets %d", rc);
702                 goto teardown_hwggrp;
703         }
704
705         rc = sso_register_irqs(event_dev);
706         if (rc < 0) {
707                 otx2_err("Failed to register irq %d", rc);
708                 goto teardown_hwggrp;
709         }
710
711         dev->configured = 1;
712         rte_mb();
713
714         return 0;
715 teardown_hwggrp:
716         sso_lf_teardown(dev, SSO_LF_GGRP);
717 teardown_hws:
718         sso_lf_teardown(dev, SSO_LF_GWS);
719         dev->nb_event_queues = 0;
720         dev->nb_event_ports = 0;
721         dev->configured = 0;
722         return rc;
723 }
724
725 static void
726 otx2_sso_queue_def_conf(struct rte_eventdev *event_dev, uint8_t queue_id,
727                         struct rte_event_queue_conf *queue_conf)
728 {
729         RTE_SET_USED(event_dev);
730         RTE_SET_USED(queue_id);
731
732         queue_conf->nb_atomic_flows = (1ULL << 20);
733         queue_conf->nb_atomic_order_sequences = (1ULL << 20);
734         queue_conf->event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
735         queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
736 }
737
738 static int
739 otx2_sso_queue_setup(struct rte_eventdev *event_dev, uint8_t queue_id,
740                      const struct rte_event_queue_conf *queue_conf)
741 {
742         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
743         struct otx2_mbox *mbox = dev->mbox;
744         struct sso_grp_priority *req;
745         int rc;
746
747         sso_func_trace("Queue=%d prio=%d", queue_id, queue_conf->priority);
748
749         req = otx2_mbox_alloc_msg_sso_grp_set_priority(dev->mbox);
750         req->grp = queue_id;
751         req->weight = 0xFF;
752         req->affinity = 0xFF;
753         /* Normalize <0-255> to <0-7> */
754         req->priority = queue_conf->priority / 32;
755
756         rc = otx2_mbox_process(mbox);
757         if (rc < 0) {
758                 otx2_err("Failed to set priority queue=%d", queue_id);
759                 return rc;
760         }
761
762         return 0;
763 }
764
765 static void
766 otx2_sso_port_def_conf(struct rte_eventdev *event_dev, uint8_t port_id,
767                        struct rte_event_port_conf *port_conf)
768 {
769         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
770
771         RTE_SET_USED(port_id);
772         port_conf->new_event_threshold = dev->max_num_events;
773         port_conf->dequeue_depth = 1;
774         port_conf->enqueue_depth = 1;
775 }
776
777 static int
778 otx2_sso_port_setup(struct rte_eventdev *event_dev, uint8_t port_id,
779                     const struct rte_event_port_conf *port_conf)
780 {
781         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
782         uintptr_t grps_base[OTX2_SSO_MAX_VHGRP] = {0};
783         uint64_t val;
784         uint16_t q;
785
786         sso_func_trace("Port=%d", port_id);
787         RTE_SET_USED(port_conf);
788
789         if (event_dev->data->ports[port_id] == NULL) {
790                 otx2_err("Invalid port Id %d", port_id);
791                 return -EINVAL;
792         }
793
794         for (q = 0; q < dev->nb_event_queues; q++) {
795                 grps_base[q] = dev->bar2 + (RVU_BLOCK_ADDR_SSO << 20 | q << 12);
796                 if (grps_base[q] == 0) {
797                         otx2_err("Failed to get grp[%d] base addr", q);
798                         return -EINVAL;
799                 }
800         }
801
802         /* Set get_work timeout for HWS */
803         val = NSEC2USEC(dev->deq_tmo_ns) - 1;
804
805         if (dev->dual_ws) {
806                 struct otx2_ssogws_dual *ws = event_dev->data->ports[port_id];
807
808                 rte_memcpy(ws->grps_base, grps_base,
809                            sizeof(uintptr_t) * OTX2_SSO_MAX_VHGRP);
810                 ws->fc_mem = dev->fc_mem;
811                 ws->xaq_lmt = dev->xaq_lmt;
812                 otx2_write64(val, OTX2_SSOW_GET_BASE_ADDR(
813                              ws->ws_state[0].getwrk_op) + SSOW_LF_GWS_NW_TIM);
814                 otx2_write64(val, OTX2_SSOW_GET_BASE_ADDR(
815                              ws->ws_state[1].getwrk_op) + SSOW_LF_GWS_NW_TIM);
816         } else {
817                 struct otx2_ssogws *ws = event_dev->data->ports[port_id];
818                 uintptr_t base = OTX2_SSOW_GET_BASE_ADDR(ws->getwrk_op);
819
820                 rte_memcpy(ws->grps_base, grps_base,
821                            sizeof(uintptr_t) * OTX2_SSO_MAX_VHGRP);
822                 ws->fc_mem = dev->fc_mem;
823                 ws->xaq_lmt = dev->xaq_lmt;
824                 otx2_write64(val, base + SSOW_LF_GWS_NW_TIM);
825         }
826
827         otx2_sso_dbg("Port=%d ws=%p", port_id, event_dev->data->ports[port_id]);
828
829         return 0;
830 }
831
832 static int
833 otx2_sso_timeout_ticks(struct rte_eventdev *event_dev, uint64_t ns,
834                        uint64_t *tmo_ticks)
835 {
836         RTE_SET_USED(event_dev);
837         *tmo_ticks = NSEC2TICK(ns, rte_get_timer_hz());
838
839         return 0;
840 }
841
842 static void
843 ssogws_dump(struct otx2_ssogws *ws, FILE *f)
844 {
845         uintptr_t base = OTX2_SSOW_GET_BASE_ADDR(ws->getwrk_op);
846
847         fprintf(f, "SSOW_LF_GWS Base addr   0x%" PRIx64 "\n", (uint64_t)base);
848         fprintf(f, "SSOW_LF_GWS_LINKS       0x%" PRIx64 "\n",
849                 otx2_read64(base + SSOW_LF_GWS_LINKS));
850         fprintf(f, "SSOW_LF_GWS_PENDWQP     0x%" PRIx64 "\n",
851                 otx2_read64(base + SSOW_LF_GWS_PENDWQP));
852         fprintf(f, "SSOW_LF_GWS_PENDSTATE   0x%" PRIx64 "\n",
853                 otx2_read64(base + SSOW_LF_GWS_PENDSTATE));
854         fprintf(f, "SSOW_LF_GWS_NW_TIM      0x%" PRIx64 "\n",
855                 otx2_read64(base + SSOW_LF_GWS_NW_TIM));
856         fprintf(f, "SSOW_LF_GWS_TAG         0x%" PRIx64 "\n",
857                 otx2_read64(base + SSOW_LF_GWS_TAG));
858         fprintf(f, "SSOW_LF_GWS_WQP         0x%" PRIx64 "\n",
859                 otx2_read64(base + SSOW_LF_GWS_TAG));
860         fprintf(f, "SSOW_LF_GWS_SWTP        0x%" PRIx64 "\n",
861                 otx2_read64(base + SSOW_LF_GWS_SWTP));
862         fprintf(f, "SSOW_LF_GWS_PENDTAG     0x%" PRIx64 "\n",
863                 otx2_read64(base + SSOW_LF_GWS_PENDTAG));
864 }
865
866 static void
867 ssoggrp_dump(uintptr_t base, FILE *f)
868 {
869         fprintf(f, "SSO_LF_GGRP Base addr   0x%" PRIx64 "\n", (uint64_t)base);
870         fprintf(f, "SSO_LF_GGRP_QCTL        0x%" PRIx64 "\n",
871                 otx2_read64(base + SSO_LF_GGRP_QCTL));
872         fprintf(f, "SSO_LF_GGRP_XAQ_CNT     0x%" PRIx64 "\n",
873                 otx2_read64(base + SSO_LF_GGRP_XAQ_CNT));
874         fprintf(f, "SSO_LF_GGRP_INT_THR     0x%" PRIx64 "\n",
875                 otx2_read64(base + SSO_LF_GGRP_INT_THR));
876         fprintf(f, "SSO_LF_GGRP_INT_CNT     0x%" PRIX64 "\n",
877                 otx2_read64(base + SSO_LF_GGRP_INT_CNT));
878         fprintf(f, "SSO_LF_GGRP_AQ_CNT      0x%" PRIX64 "\n",
879                 otx2_read64(base + SSO_LF_GGRP_AQ_CNT));
880         fprintf(f, "SSO_LF_GGRP_AQ_THR      0x%" PRIX64 "\n",
881                 otx2_read64(base + SSO_LF_GGRP_AQ_THR));
882         fprintf(f, "SSO_LF_GGRP_MISC_CNT    0x%" PRIx64 "\n",
883                 otx2_read64(base + SSO_LF_GGRP_MISC_CNT));
884 }
885
886 static void
887 otx2_sso_dump(struct rte_eventdev *event_dev, FILE *f)
888 {
889         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
890         uint8_t queue;
891         uint8_t port;
892
893         fprintf(f, "[%s] SSO running in [%s] mode\n", __func__, dev->dual_ws ?
894                 "dual_ws" : "single_ws");
895         /* Dump SSOW registers */
896         for (port = 0; port < dev->nb_event_ports; port++) {
897                 if (dev->dual_ws) {
898                         struct otx2_ssogws_dual *ws =
899                                 event_dev->data->ports[port];
900
901                         fprintf(f, "[%s] SSO dual workslot[%d] vws[%d] dump\n",
902                                 __func__, port, 0);
903                         ssogws_dump((struct otx2_ssogws *)&ws->ws_state[0], f);
904                         fprintf(f, "[%s]SSO dual workslot[%d] vws[%d] dump\n",
905                                 __func__, port, 1);
906                         ssogws_dump((struct otx2_ssogws *)&ws->ws_state[1], f);
907                 } else {
908                         fprintf(f, "[%s]SSO single workslot[%d] dump\n",
909                                 __func__, port);
910                         ssogws_dump(event_dev->data->ports[port], f);
911                 }
912         }
913
914         /* Dump SSO registers */
915         for (queue = 0; queue < dev->nb_event_queues; queue++) {
916                 fprintf(f, "[%s]SSO group[%d] dump\n", __func__, queue);
917                 if (dev->dual_ws) {
918                         struct otx2_ssogws_dual *ws = event_dev->data->ports[0];
919                         ssoggrp_dump(ws->grps_base[queue], f);
920                 } else {
921                         struct otx2_ssogws *ws = event_dev->data->ports[0];
922                         ssoggrp_dump(ws->grps_base[queue], f);
923                 }
924         }
925 }
926
927 static void
928 otx2_handle_event(void *arg, struct rte_event event)
929 {
930         struct rte_eventdev *event_dev = arg;
931
932         if (event_dev->dev_ops->dev_stop_flush != NULL)
933                 event_dev->dev_ops->dev_stop_flush(event_dev->data->dev_id,
934                                 event, event_dev->data->dev_stop_flush_arg);
935 }
936
937 static void
938 sso_cleanup(struct rte_eventdev *event_dev, uint8_t enable)
939 {
940         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
941         uint16_t i;
942
943         for (i = 0; i < dev->nb_event_ports; i++) {
944                 if (dev->dual_ws) {
945                         struct otx2_ssogws_dual *ws;
946
947                         ws = event_dev->data->ports[i];
948                         ssogws_reset((struct otx2_ssogws *)&ws->ws_state[0]);
949                         ssogws_reset((struct otx2_ssogws *)&ws->ws_state[1]);
950                         ws->swtag_req = 0;
951                         ws->vws = 0;
952                         ws->ws_state[0].cur_grp = 0;
953                         ws->ws_state[0].cur_tt = SSO_SYNC_EMPTY;
954                         ws->ws_state[1].cur_grp = 0;
955                         ws->ws_state[1].cur_tt = SSO_SYNC_EMPTY;
956                 } else {
957                         struct otx2_ssogws *ws;
958
959                         ws = event_dev->data->ports[i];
960                         ssogws_reset(ws);
961                         ws->swtag_req = 0;
962                         ws->cur_grp = 0;
963                         ws->cur_tt = SSO_SYNC_EMPTY;
964                 }
965         }
966
967         rte_mb();
968         if (dev->dual_ws) {
969                 struct otx2_ssogws_dual *ws = event_dev->data->ports[0];
970                 struct otx2_ssogws temp_ws;
971
972                 memcpy(&temp_ws, &ws->ws_state[0],
973                        sizeof(struct otx2_ssogws_state));
974                 for (i = 0; i < dev->nb_event_queues; i++) {
975                         /* Consume all the events through HWS0 */
976                         ssogws_flush_events(&temp_ws, i, ws->grps_base[i],
977                                             otx2_handle_event, event_dev);
978                         /* Enable/Disable SSO GGRP */
979                         otx2_write64(enable, ws->grps_base[i] +
980                                      SSO_LF_GGRP_QCTL);
981                 }
982                 ws->ws_state[0].cur_grp = 0;
983                 ws->ws_state[0].cur_tt = SSO_SYNC_EMPTY;
984         } else {
985                 struct otx2_ssogws *ws = event_dev->data->ports[0];
986
987                 for (i = 0; i < dev->nb_event_queues; i++) {
988                         /* Consume all the events through HWS0 */
989                         ssogws_flush_events(ws, i, ws->grps_base[i],
990                                             otx2_handle_event, event_dev);
991                         /* Enable/Disable SSO GGRP */
992                         otx2_write64(enable, ws->grps_base[i] +
993                                      SSO_LF_GGRP_QCTL);
994                 }
995                 ws->cur_grp = 0;
996                 ws->cur_tt = SSO_SYNC_EMPTY;
997         }
998
999         /* reset SSO GWS cache */
1000         otx2_mbox_alloc_msg_sso_ws_cache_inv(dev->mbox);
1001         otx2_mbox_process(dev->mbox);
1002 }
1003
1004 static int
1005 otx2_sso_start(struct rte_eventdev *event_dev)
1006 {
1007         sso_func_trace();
1008         sso_cleanup(event_dev, 1);
1009         sso_fastpath_fns_set(event_dev);
1010
1011         return 0;
1012 }
1013
1014 /* Initialize and register event driver with DPDK Application */
1015 static struct rte_eventdev_ops otx2_sso_ops = {
1016         .dev_infos_get    = otx2_sso_info_get,
1017         .dev_configure    = otx2_sso_configure,
1018         .queue_def_conf   = otx2_sso_queue_def_conf,
1019         .queue_setup      = otx2_sso_queue_setup,
1020         .queue_release    = otx2_sso_queue_release,
1021         .port_def_conf    = otx2_sso_port_def_conf,
1022         .port_setup       = otx2_sso_port_setup,
1023         .port_release     = otx2_sso_port_release,
1024         .port_link        = otx2_sso_port_link,
1025         .port_unlink      = otx2_sso_port_unlink,
1026         .timeout_ticks    = otx2_sso_timeout_ticks,
1027
1028         .xstats_get       = otx2_sso_xstats_get,
1029         .xstats_reset     = otx2_sso_xstats_reset,
1030         .xstats_get_names = otx2_sso_xstats_get_names,
1031
1032         .dump             = otx2_sso_dump,
1033         .dev_start        = otx2_sso_start,
1034 };
1035
1036 #define OTX2_SSO_XAE_CNT        "xae_cnt"
1037 #define OTX2_SSO_SINGLE_WS      "single_ws"
1038
1039 static void
1040 sso_parse_devargs(struct otx2_sso_evdev *dev, struct rte_devargs *devargs)
1041 {
1042         struct rte_kvargs *kvlist;
1043         uint8_t single_ws = 0;
1044
1045         if (devargs == NULL)
1046                 return;
1047         kvlist = rte_kvargs_parse(devargs->args, NULL);
1048         if (kvlist == NULL)
1049                 return;
1050
1051         rte_kvargs_process(kvlist, OTX2_SSO_XAE_CNT, &parse_kvargs_value,
1052                            &dev->xae_cnt);
1053         rte_kvargs_process(kvlist, OTX2_SSO_SINGLE_WS, &parse_kvargs_flag,
1054                            &single_ws);
1055
1056         dev->dual_ws = !single_ws;
1057         rte_kvargs_free(kvlist);
1058 }
1059
1060 static int
1061 otx2_sso_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
1062 {
1063         return rte_event_pmd_pci_probe(pci_drv, pci_dev,
1064                                        sizeof(struct otx2_sso_evdev),
1065                                        otx2_sso_init);
1066 }
1067
1068 static int
1069 otx2_sso_remove(struct rte_pci_device *pci_dev)
1070 {
1071         return rte_event_pmd_pci_remove(pci_dev, otx2_sso_fini);
1072 }
1073
1074 static const struct rte_pci_id pci_sso_map[] = {
1075         {
1076                 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
1077                                PCI_DEVID_OCTEONTX2_RVU_SSO_TIM_PF)
1078         },
1079         {
1080                 .vendor_id = 0,
1081         },
1082 };
1083
1084 static struct rte_pci_driver pci_sso = {
1085         .id_table = pci_sso_map,
1086         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_IOVA_AS_VA,
1087         .probe = otx2_sso_probe,
1088         .remove = otx2_sso_remove,
1089 };
1090
1091 int
1092 otx2_sso_init(struct rte_eventdev *event_dev)
1093 {
1094         struct free_rsrcs_rsp *rsrc_cnt;
1095         struct rte_pci_device *pci_dev;
1096         struct otx2_sso_evdev *dev;
1097         int rc;
1098
1099         event_dev->dev_ops = &otx2_sso_ops;
1100         /* For secondary processes, the primary has done all the work */
1101         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1102                 sso_fastpath_fns_set(event_dev);
1103                 return 0;
1104         }
1105
1106         dev = sso_pmd_priv(event_dev);
1107
1108         pci_dev = container_of(event_dev->dev, struct rte_pci_device, device);
1109
1110         /* Initialize the base otx2_dev object */
1111         rc = otx2_dev_init(pci_dev, dev);
1112         if (rc < 0) {
1113                 otx2_err("Failed to initialize otx2_dev rc=%d", rc);
1114                 goto error;
1115         }
1116
1117         /* Get SSO and SSOW MSIX rsrc cnt */
1118         otx2_mbox_alloc_msg_free_rsrc_cnt(dev->mbox);
1119         rc = otx2_mbox_process_msg(dev->mbox, (void *)&rsrc_cnt);
1120         if (rc < 0) {
1121                 otx2_err("Unable to get free rsrc count");
1122                 goto otx2_dev_uninit;
1123         }
1124         otx2_sso_dbg("SSO %d SSOW %d NPA %d provisioned", rsrc_cnt->sso,
1125                      rsrc_cnt->ssow, rsrc_cnt->npa);
1126
1127         dev->max_event_ports = RTE_MIN(rsrc_cnt->ssow, OTX2_SSO_MAX_VHWS);
1128         dev->max_event_queues = RTE_MIN(rsrc_cnt->sso, OTX2_SSO_MAX_VHGRP);
1129         /* Grab the NPA LF if required */
1130         rc = otx2_npa_lf_init(pci_dev, dev);
1131         if (rc < 0) {
1132                 otx2_err("Unable to init NPA lf. It might not be provisioned");
1133                 goto otx2_dev_uninit;
1134         }
1135
1136         dev->drv_inited = true;
1137         dev->is_timeout_deq = 0;
1138         dev->min_dequeue_timeout_ns = USEC2NSEC(1);
1139         dev->max_dequeue_timeout_ns = USEC2NSEC(0x3FF);
1140         dev->max_num_events = -1;
1141         dev->nb_event_queues = 0;
1142         dev->nb_event_ports = 0;
1143
1144         if (!dev->max_event_ports || !dev->max_event_queues) {
1145                 otx2_err("Not enough eventdev resource queues=%d ports=%d",
1146                          dev->max_event_queues, dev->max_event_ports);
1147                 rc = -ENODEV;
1148                 goto otx2_npa_lf_uninit;
1149         }
1150
1151         dev->dual_ws = 1;
1152         sso_parse_devargs(dev, pci_dev->device.devargs);
1153         if (dev->dual_ws) {
1154                 otx2_sso_dbg("Using dual workslot mode");
1155                 dev->max_event_ports = dev->max_event_ports / 2;
1156         } else {
1157                 otx2_sso_dbg("Using single workslot mode");
1158         }
1159
1160         otx2_sso_pf_func_set(dev->pf_func);
1161         otx2_sso_dbg("Initializing %s max_queues=%d max_ports=%d",
1162                      event_dev->data->name, dev->max_event_queues,
1163                      dev->max_event_ports);
1164
1165
1166         return 0;
1167
1168 otx2_npa_lf_uninit:
1169         otx2_npa_lf_fini();
1170 otx2_dev_uninit:
1171         otx2_dev_fini(pci_dev, dev);
1172 error:
1173         return rc;
1174 }
1175
1176 int
1177 otx2_sso_fini(struct rte_eventdev *event_dev)
1178 {
1179         struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
1180         struct rte_pci_device *pci_dev;
1181
1182         /* For secondary processes, nothing to be done */
1183         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1184                 return 0;
1185
1186         pci_dev = container_of(event_dev->dev, struct rte_pci_device, device);
1187
1188         if (!dev->drv_inited)
1189                 goto dev_fini;
1190
1191         dev->drv_inited = false;
1192         otx2_npa_lf_fini();
1193
1194 dev_fini:
1195         if (otx2_npa_lf_active(dev)) {
1196                 otx2_info("Common resource in use by other devices");
1197                 return -EAGAIN;
1198         }
1199
1200         otx2_dev_fini(pci_dev, dev);
1201
1202         return 0;
1203 }
1204
1205 RTE_PMD_REGISTER_PCI(event_octeontx2, pci_sso);
1206 RTE_PMD_REGISTER_PCI_TABLE(event_octeontx2, pci_sso_map);
1207 RTE_PMD_REGISTER_KMOD_DEP(event_octeontx2, "vfio-pci");
1208 RTE_PMD_REGISTER_PARAM_STRING(event_octeontx2, OTX2_SSO_XAE_CNT "=<int>"
1209                               OTX2_SSO_SINGLE_WS "=1");