common/cnxk: support CPT CTX write through microcode op
[dpdk.git] / drivers / common / cnxk / roc_nix_inl_dev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #include "roc_api.h"
6 #include "roc_priv.h"
7
8 #define XAQ_CACHE_CNT 0x7
9
10 /* Default Rx Config for Inline NIX LF */
11 #define NIX_INL_LF_RX_CFG                                                      \
12         (ROC_NIX_LF_RX_CFG_DROP_RE | ROC_NIX_LF_RX_CFG_L2_LEN_ERR |            \
13          ROC_NIX_LF_RX_CFG_IP6_UDP_OPT | ROC_NIX_LF_RX_CFG_DIS_APAD |          \
14          ROC_NIX_LF_RX_CFG_CSUM_IL4 | ROC_NIX_LF_RX_CFG_CSUM_OL4 |             \
15          ROC_NIX_LF_RX_CFG_LEN_IL4 | ROC_NIX_LF_RX_CFG_LEN_IL3 |               \
16          ROC_NIX_LF_RX_CFG_LEN_OL4 | ROC_NIX_LF_RX_CFG_LEN_OL3)
17
18 uint16_t
19 nix_inl_dev_pffunc_get(void)
20 {
21         struct idev_cfg *idev = idev_get_cfg();
22         struct nix_inl_dev *inl_dev;
23
24         if (idev != NULL) {
25                 inl_dev = idev->nix_inl_dev;
26                 if (inl_dev)
27                         return inl_dev->dev.pf_func;
28         }
29         return 0;
30 }
31
32 static void
33 nix_inl_selftest_work_cb(uint64_t *gw, void *args)
34 {
35         uintptr_t work = gw[1];
36
37         *((uintptr_t *)args + (gw[0] & 0x1)) = work;
38
39         plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
40 }
41
42 static int
43 nix_inl_selftest(void)
44 {
45         struct idev_cfg *idev = idev_get_cfg();
46         roc_nix_inl_sso_work_cb_t save_cb;
47         static uintptr_t work_arr[2];
48         struct nix_inl_dev *inl_dev;
49         void *save_cb_args;
50         uint64_t add_work0;
51         int rc = 0;
52
53         if (idev == NULL)
54                 return -ENOTSUP;
55
56         inl_dev = idev->nix_inl_dev;
57         if (inl_dev == NULL)
58                 return -ENOTSUP;
59
60         plt_info("Performing nix inl self test");
61
62         /* Save and update cb to test cb */
63         save_cb = inl_dev->work_cb;
64         save_cb_args = inl_dev->cb_args;
65         inl_dev->work_cb = nix_inl_selftest_work_cb;
66         inl_dev->cb_args = work_arr;
67
68         plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
69
70 #define WORK_MAGIC1 0x335577ff0
71 #define WORK_MAGIC2 0xdeadbeef0
72
73         /* Add work */
74         add_work0 = ((uint64_t)(SSO_TT_ORDERED) << 32) | 0x0;
75         roc_store_pair(add_work0, WORK_MAGIC1, inl_dev->sso_base);
76         add_work0 = ((uint64_t)(SSO_TT_ORDERED) << 32) | 0x1;
77         roc_store_pair(add_work0, WORK_MAGIC2, inl_dev->sso_base);
78
79         plt_delay_ms(10000);
80
81         /* Check if we got expected work */
82         if (work_arr[0] != WORK_MAGIC1 || work_arr[1] != WORK_MAGIC2) {
83                 plt_err("Failed to get expected work, [0]=%p [1]=%p",
84                         (void *)work_arr[0], (void *)work_arr[1]);
85                 rc = -EFAULT;
86                 goto exit;
87         }
88
89         plt_info("Work, [0]=%p [1]=%p", (void *)work_arr[0],
90                  (void *)work_arr[1]);
91
92 exit:
93         /* Restore state */
94         inl_dev->work_cb = save_cb;
95         inl_dev->cb_args = save_cb_args;
96         return rc;
97 }
98
99 static int
100 nix_inl_nix_ipsec_cfg(struct nix_inl_dev *inl_dev, bool ena)
101 {
102         struct nix_inline_ipsec_lf_cfg *lf_cfg;
103         struct mbox *mbox = (&inl_dev->dev)->mbox;
104         uint32_t sa_w;
105
106         lf_cfg = mbox_alloc_msg_nix_inline_ipsec_lf_cfg(mbox);
107         if (lf_cfg == NULL)
108                 return -ENOSPC;
109
110         if (ena) {
111                 sa_w = plt_align32pow2(inl_dev->ipsec_in_max_spi + 1);
112                 sa_w = plt_log2_u32(sa_w);
113
114                 lf_cfg->enable = 1;
115                 lf_cfg->sa_base_addr = (uintptr_t)inl_dev->inb_sa_base;
116                 lf_cfg->ipsec_cfg1.sa_idx_w = sa_w;
117                 /* CN9K SA size is different */
118                 if (roc_model_is_cn9k())
119                         lf_cfg->ipsec_cfg0.lenm1_max = NIX_CN9K_MAX_HW_FRS - 1;
120                 else
121                         lf_cfg->ipsec_cfg0.lenm1_max = NIX_RPM_MAX_HW_FRS - 1;
122                 lf_cfg->ipsec_cfg1.sa_idx_max = inl_dev->ipsec_in_max_spi;
123                 lf_cfg->ipsec_cfg0.sa_pow2_size =
124                         plt_log2_u32(inl_dev->inb_sa_sz);
125
126                 lf_cfg->ipsec_cfg0.tag_const = 0;
127                 lf_cfg->ipsec_cfg0.tt = SSO_TT_ORDERED;
128         } else {
129                 lf_cfg->enable = 0;
130         }
131
132         return mbox_process(mbox);
133 }
134
135 static int
136 nix_inl_cpt_setup(struct nix_inl_dev *inl_dev)
137 {
138         struct roc_cpt_lf *lf = &inl_dev->cpt_lf;
139         struct dev *dev = &inl_dev->dev;
140         uint8_t eng_grpmask;
141         int rc;
142
143         if (!inl_dev->attach_cptlf)
144                 return 0;
145
146         /* Alloc CPT LF */
147         eng_grpmask = (1ULL << ROC_CPT_DFLT_ENG_GRP_SE |
148                        1ULL << ROC_CPT_DFLT_ENG_GRP_SE_IE |
149                        1ULL << ROC_CPT_DFLT_ENG_GRP_AE);
150         rc = cpt_lfs_alloc(dev, eng_grpmask, RVU_BLOCK_ADDR_CPT0, false);
151         if (rc) {
152                 plt_err("Failed to alloc CPT LF resources, rc=%d", rc);
153                 return rc;
154         }
155
156         /* Setup CPT LF for submitting control opcode */
157         lf = &inl_dev->cpt_lf;
158         lf->lf_id = 0;
159         lf->nb_desc = 0; /* Set to default */
160         lf->dev = &inl_dev->dev;
161         lf->msixoff = inl_dev->cpt_msixoff;
162         lf->pci_dev = inl_dev->pci_dev;
163
164         rc = cpt_lf_init(lf);
165         if (rc) {
166                 plt_err("Failed to initialize CPT LF, rc=%d", rc);
167                 goto lf_free;
168         }
169
170         roc_cpt_iq_enable(lf);
171         return 0;
172 lf_free:
173         rc |= cpt_lfs_free(dev);
174         return rc;
175 }
176
177 static int
178 nix_inl_cpt_release(struct nix_inl_dev *inl_dev)
179 {
180         struct roc_cpt_lf *lf = &inl_dev->cpt_lf;
181         struct dev *dev = &inl_dev->dev;
182         int rc, ret = 0;
183
184         if (!inl_dev->attach_cptlf)
185                 return 0;
186
187         /* Cleanup CPT LF queue */
188         cpt_lf_fini(lf);
189
190         /* Free LF resources */
191         rc = cpt_lfs_free(dev);
192         if (rc)
193                 plt_err("Failed to free CPT LF resources, rc=%d", rc);
194         ret |= rc;
195
196         /* Detach LF */
197         rc = cpt_lfs_detach(dev);
198         if (rc)
199                 plt_err("Failed to detach CPT LF, rc=%d", rc);
200         ret |= rc;
201
202         return ret;
203 }
204
205 static int
206 nix_inl_sso_setup(struct nix_inl_dev *inl_dev)
207 {
208         struct sso_lf_alloc_rsp *sso_rsp;
209         struct dev *dev = &inl_dev->dev;
210         uint32_t xaq_cnt, count, aura;
211         uint16_t hwgrp[1] = {0};
212         struct npa_pool_s pool;
213         uintptr_t iova;
214         int rc;
215
216         /* Alloc SSOW LF */
217         rc = sso_lf_alloc(dev, SSO_LF_TYPE_HWS, 1, NULL);
218         if (rc) {
219                 plt_err("Failed to alloc SSO HWS, rc=%d", rc);
220                 return rc;
221         }
222
223         /* Alloc HWGRP LF */
224         rc = sso_lf_alloc(dev, SSO_LF_TYPE_HWGRP, 1, (void **)&sso_rsp);
225         if (rc) {
226                 plt_err("Failed to alloc SSO HWGRP, rc=%d", rc);
227                 goto free_ssow;
228         }
229
230         inl_dev->xaq_buf_size = sso_rsp->xaq_buf_size;
231         inl_dev->xae_waes = sso_rsp->xaq_wq_entries;
232         inl_dev->iue = sso_rsp->in_unit_entries;
233
234         /* Create XAQ pool */
235         xaq_cnt = XAQ_CACHE_CNT;
236         xaq_cnt += inl_dev->iue / inl_dev->xae_waes;
237         plt_sso_dbg("Configuring %d xaq buffers", xaq_cnt);
238
239         inl_dev->xaq_mem = plt_zmalloc(inl_dev->xaq_buf_size * xaq_cnt,
240                                        inl_dev->xaq_buf_size);
241         if (!inl_dev->xaq_mem) {
242                 rc = NIX_ERR_NO_MEM;
243                 plt_err("Failed to alloc xaq buf mem");
244                 goto free_sso;
245         }
246
247         memset(&pool, 0, sizeof(struct npa_pool_s));
248         pool.nat_align = 1;
249         rc = roc_npa_pool_create(&inl_dev->xaq_aura, inl_dev->xaq_buf_size,
250                                  xaq_cnt, NULL, &pool);
251         if (rc) {
252                 plt_err("Failed to alloc aura for XAQ, rc=%d", rc);
253                 goto free_mem;
254         }
255
256         /* Fill the XAQ buffers */
257         iova = (uint64_t)inl_dev->xaq_mem;
258         for (count = 0; count < xaq_cnt; count++) {
259                 roc_npa_aura_op_free(inl_dev->xaq_aura, 0, iova);
260                 iova += inl_dev->xaq_buf_size;
261         }
262         roc_npa_aura_op_range_set(inl_dev->xaq_aura, (uint64_t)inl_dev->xaq_mem,
263                                   iova);
264
265         aura = roc_npa_aura_handle_to_aura(inl_dev->xaq_aura);
266
267         /* Setup xaq for hwgrps */
268         rc = sso_hwgrp_alloc_xaq(dev, aura, 1);
269         if (rc) {
270                 plt_err("Failed to setup hwgrp xaq aura, rc=%d", rc);
271                 goto destroy_pool;
272         }
273
274         /* Register SSO, SSOW error and work irq's */
275         rc = nix_inl_sso_register_irqs(inl_dev);
276         if (rc) {
277                 plt_err("Failed to register sso irq's, rc=%d", rc);
278                 goto release_xaq;
279         }
280
281         /* Setup hwgrp->hws link */
282         sso_hws_link_modify(0, inl_dev->ssow_base, NULL, hwgrp, 1, true);
283
284         /* Enable HWGRP */
285         plt_write64(0x1, inl_dev->sso_base + SSO_LF_GGRP_QCTL);
286
287         return 0;
288
289 release_xaq:
290         sso_hwgrp_release_xaq(&inl_dev->dev, 1);
291 destroy_pool:
292         roc_npa_pool_destroy(inl_dev->xaq_aura);
293         inl_dev->xaq_aura = 0;
294 free_mem:
295         plt_free(inl_dev->xaq_mem);
296         inl_dev->xaq_mem = NULL;
297 free_sso:
298         sso_lf_free(dev, SSO_LF_TYPE_HWGRP, 1);
299 free_ssow:
300         sso_lf_free(dev, SSO_LF_TYPE_HWS, 1);
301         return rc;
302 }
303
304 static int
305 nix_inl_sso_release(struct nix_inl_dev *inl_dev)
306 {
307         uint16_t hwgrp[1] = {0};
308
309         /* Disable HWGRP */
310         plt_write64(0, inl_dev->sso_base + SSO_LF_GGRP_QCTL);
311
312         /* Unregister SSO/SSOW IRQ's */
313         nix_inl_sso_unregister_irqs(inl_dev);
314
315         /* Unlink hws */
316         sso_hws_link_modify(0, inl_dev->ssow_base, NULL, hwgrp, 1, false);
317
318         /* Release XAQ aura */
319         sso_hwgrp_release_xaq(&inl_dev->dev, 1);
320
321         /* Free SSO, SSOW LF's */
322         sso_lf_free(&inl_dev->dev, SSO_LF_TYPE_HWS, 1);
323         sso_lf_free(&inl_dev->dev, SSO_LF_TYPE_HWGRP, 1);
324
325         return 0;
326 }
327
328 static int
329 nix_inl_nix_setup(struct nix_inl_dev *inl_dev)
330 {
331         uint16_t ipsec_in_max_spi = inl_dev->ipsec_in_max_spi;
332         struct dev *dev = &inl_dev->dev;
333         struct mbox *mbox = dev->mbox;
334         struct nix_lf_alloc_rsp *rsp;
335         struct nix_lf_alloc_req *req;
336         size_t inb_sa_sz;
337         int i, rc = -ENOSPC;
338         void *sa;
339
340         /* Alloc NIX LF needed for single RQ */
341         req = mbox_alloc_msg_nix_lf_alloc(mbox);
342         if (req == NULL)
343                 return rc;
344         req->rq_cnt = 1;
345         req->sq_cnt = 1;
346         req->cq_cnt = 1;
347         /* XQESZ is W16 */
348         req->xqe_sz = NIX_XQESZ_W16;
349         /* RSS size does not matter as this RQ is only for UCAST_IPSEC action */
350         req->rss_sz = ROC_NIX_RSS_RETA_SZ_64;
351         req->rss_grps = ROC_NIX_RSS_GRPS;
352         req->npa_func = idev_npa_pffunc_get();
353         req->sso_func = dev->pf_func;
354         req->rx_cfg = NIX_INL_LF_RX_CFG;
355         req->flags = NIX_LF_RSS_TAG_LSB_AS_ADDER;
356
357         if (roc_model_is_cn10ka_a0() || roc_model_is_cnf10ka_a0() ||
358             roc_model_is_cnf10kb_a0())
359                 req->rx_cfg &= ~ROC_NIX_LF_RX_CFG_DROP_RE;
360
361         rc = mbox_process_msg(mbox, (void *)&rsp);
362         if (rc) {
363                 plt_err("Failed to alloc lf, rc=%d", rc);
364                 return rc;
365         }
366
367         inl_dev->lf_tx_stats = rsp->lf_tx_stats;
368         inl_dev->lf_rx_stats = rsp->lf_rx_stats;
369         inl_dev->qints = rsp->qints;
370         inl_dev->cints = rsp->cints;
371
372         /* Register nix interrupts */
373         rc = nix_inl_nix_register_irqs(inl_dev);
374         if (rc) {
375                 plt_err("Failed to register nix irq's, rc=%d", rc);
376                 goto lf_free;
377         }
378
379         /* CN9K SA is different */
380         if (roc_model_is_cn9k())
381                 inb_sa_sz = ROC_NIX_INL_ONF_IPSEC_INB_SA_SZ;
382         else
383                 inb_sa_sz = ROC_NIX_INL_OT_IPSEC_INB_SA_SZ;
384
385         /* Alloc contiguous memory for Inbound SA's */
386         inl_dev->inb_sa_sz = inb_sa_sz;
387         inl_dev->inb_sa_base = plt_zmalloc(inb_sa_sz * ipsec_in_max_spi,
388                                            ROC_NIX_INL_SA_BASE_ALIGN);
389         if (!inl_dev->inb_sa_base) {
390                 plt_err("Failed to allocate memory for Inbound SA");
391                 rc = -ENOMEM;
392                 goto unregister_irqs;
393         }
394
395         if (roc_model_is_cn10k()) {
396                 for (i = 0; i < ipsec_in_max_spi; i++) {
397                         sa = ((uint8_t *)inl_dev->inb_sa_base) +
398                              (i * inb_sa_sz);
399                         roc_nix_inl_inb_sa_init(sa);
400                 }
401         }
402         /* Setup device specific inb SA table */
403         rc = nix_inl_nix_ipsec_cfg(inl_dev, true);
404         if (rc) {
405                 plt_err("Failed to setup NIX Inbound SA conf, rc=%d", rc);
406                 goto free_mem;
407         }
408
409         return 0;
410 free_mem:
411         plt_free(inl_dev->inb_sa_base);
412         inl_dev->inb_sa_base = NULL;
413 unregister_irqs:
414         nix_inl_nix_unregister_irqs(inl_dev);
415 lf_free:
416         mbox_alloc_msg_nix_lf_free(mbox);
417         rc |= mbox_process(mbox);
418         return rc;
419 }
420
421 static int
422 nix_inl_nix_release(struct nix_inl_dev *inl_dev)
423 {
424         struct dev *dev = &inl_dev->dev;
425         struct mbox *mbox = dev->mbox;
426         struct nix_lf_free_req *req;
427         struct ndc_sync_op *ndc_req;
428         int rc = -ENOSPC;
429
430         /* Disable Inbound processing */
431         rc = nix_inl_nix_ipsec_cfg(inl_dev, false);
432         if (rc)
433                 plt_err("Failed to disable Inbound IPSec, rc=%d", rc);
434
435         /* Sync NDC-NIX for LF */
436         ndc_req = mbox_alloc_msg_ndc_sync_op(mbox);
437         if (ndc_req == NULL)
438                 return rc;
439         ndc_req->nix_lf_rx_sync = 1;
440         rc = mbox_process(mbox);
441         if (rc)
442                 plt_err("Error on NDC-NIX-RX LF sync, rc %d", rc);
443
444         /* Unregister IRQs */
445         nix_inl_nix_unregister_irqs(inl_dev);
446
447         /* By default all associated mcam rules are deleted */
448         req = mbox_alloc_msg_nix_lf_free(mbox);
449         if (req == NULL)
450                 return -ENOSPC;
451
452         return mbox_process(mbox);
453 }
454
455 static int
456 nix_inl_lf_attach(struct nix_inl_dev *inl_dev)
457 {
458         struct msix_offset_rsp *msix_rsp;
459         struct dev *dev = &inl_dev->dev;
460         struct mbox *mbox = dev->mbox;
461         struct rsrc_attach_req *req;
462         uint64_t nix_blkaddr;
463         int rc = -ENOSPC;
464
465         req = mbox_alloc_msg_attach_resources(mbox);
466         if (req == NULL)
467                 return rc;
468         req->modify = true;
469         /* Attach 1 NIXLF, SSO HWS and SSO HWGRP */
470         req->nixlf = true;
471         req->ssow = 1;
472         req->sso = 1;
473         if (inl_dev->attach_cptlf) {
474                 req->cptlfs = 1;
475                 req->cpt_blkaddr = RVU_BLOCK_ADDR_CPT0;
476         }
477
478         rc = mbox_process(dev->mbox);
479         if (rc)
480                 return rc;
481
482         /* Get MSIX vector offsets */
483         mbox_alloc_msg_msix_offset(mbox);
484         rc = mbox_process_msg(dev->mbox, (void **)&msix_rsp);
485         if (rc)
486                 return rc;
487
488         inl_dev->nix_msixoff = msix_rsp->nix_msixoff;
489         inl_dev->ssow_msixoff = msix_rsp->ssow_msixoff[0];
490         inl_dev->sso_msixoff = msix_rsp->sso_msixoff[0];
491         inl_dev->cpt_msixoff = msix_rsp->cptlf_msixoff[0];
492
493         nix_blkaddr = nix_get_blkaddr(dev);
494         inl_dev->is_nix1 = (nix_blkaddr == RVU_BLOCK_ADDR_NIX1);
495
496         /* Update base addresses for LF's */
497         inl_dev->nix_base = dev->bar2 + (nix_blkaddr << 20);
498         inl_dev->ssow_base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20);
499         inl_dev->sso_base = dev->bar2 + (RVU_BLOCK_ADDR_SSO << 20);
500         inl_dev->cpt_base = dev->bar2 + (RVU_BLOCK_ADDR_CPT0 << 20);
501
502         return 0;
503 }
504
505 static int
506 nix_inl_lf_detach(struct nix_inl_dev *inl_dev)
507 {
508         struct dev *dev = &inl_dev->dev;
509         struct mbox *mbox = dev->mbox;
510         struct rsrc_detach_req *req;
511         int rc = -ENOSPC;
512
513         req = mbox_alloc_msg_detach_resources(mbox);
514         if (req == NULL)
515                 return rc;
516         req->partial = true;
517         req->nixlf = true;
518         req->ssow = true;
519         req->sso = true;
520         req->cptlfs = !!inl_dev->attach_cptlf;
521
522         return mbox_process(dev->mbox);
523 }
524
525 int
526 roc_nix_inl_dev_init(struct roc_nix_inl_dev *roc_inl_dev)
527 {
528         struct plt_pci_device *pci_dev;
529         struct nix_inl_dev *inl_dev;
530         struct idev_cfg *idev;
531         int rc;
532
533         pci_dev = roc_inl_dev->pci_dev;
534
535         /* Skip probe if already done */
536         idev = idev_get_cfg();
537         if (idev == NULL)
538                 return -ENOTSUP;
539
540         if (idev->nix_inl_dev) {
541                 plt_info("Skipping device %s, inline device already probed",
542                          pci_dev->name);
543                 return -EEXIST;
544         }
545
546         PLT_STATIC_ASSERT(sizeof(struct nix_inl_dev) <= ROC_NIX_INL_MEM_SZ);
547
548         inl_dev = (struct nix_inl_dev *)roc_inl_dev->reserved;
549         memset(inl_dev, 0, sizeof(*inl_dev));
550
551         inl_dev->pci_dev = pci_dev;
552         inl_dev->ipsec_in_max_spi = roc_inl_dev->ipsec_in_max_spi;
553         inl_dev->selftest = roc_inl_dev->selftest;
554         inl_dev->is_multi_channel = roc_inl_dev->is_multi_channel;
555         inl_dev->channel = roc_inl_dev->channel;
556         inl_dev->chan_mask = roc_inl_dev->chan_mask;
557         inl_dev->attach_cptlf = roc_inl_dev->attach_cptlf;
558
559         /* Initialize base device */
560         rc = dev_init(&inl_dev->dev, pci_dev);
561         if (rc) {
562                 plt_err("Failed to init roc device");
563                 goto error;
564         }
565
566         /* Attach LF resources */
567         rc = nix_inl_lf_attach(inl_dev);
568         if (rc) {
569                 plt_err("Failed to attach LF resources, rc=%d", rc);
570                 goto dev_cleanup;
571         }
572
573         /* Setup NIX LF */
574         rc = nix_inl_nix_setup(inl_dev);
575         if (rc)
576                 goto lf_detach;
577
578         /* Setup SSO LF */
579         rc = nix_inl_sso_setup(inl_dev);
580         if (rc)
581                 goto nix_release;
582
583         /* Setup CPT LF */
584         rc = nix_inl_cpt_setup(inl_dev);
585         if (rc)
586                 goto sso_release;
587
588         /* Perform selftest if asked for */
589         if (inl_dev->selftest) {
590                 rc = nix_inl_selftest();
591                 if (rc)
592                         goto cpt_release;
593         }
594
595         idev->nix_inl_dev = inl_dev;
596
597         return 0;
598 cpt_release:
599         rc |= nix_inl_cpt_release(inl_dev);
600 sso_release:
601         rc |= nix_inl_sso_release(inl_dev);
602 nix_release:
603         rc |= nix_inl_nix_release(inl_dev);
604 lf_detach:
605         rc |= nix_inl_lf_detach(inl_dev);
606 dev_cleanup:
607         rc |= dev_fini(&inl_dev->dev, pci_dev);
608 error:
609         return rc;
610 }
611
612 int
613 roc_nix_inl_dev_fini(struct roc_nix_inl_dev *roc_inl_dev)
614 {
615         struct plt_pci_device *pci_dev;
616         struct nix_inl_dev *inl_dev;
617         struct idev_cfg *idev;
618         int rc;
619
620         idev = idev_get_cfg();
621         if (idev == NULL)
622                 return 0;
623
624         if (!idev->nix_inl_dev ||
625             PLT_PTR_DIFF(roc_inl_dev->reserved, idev->nix_inl_dev))
626                 return 0;
627
628         inl_dev = idev->nix_inl_dev;
629         pci_dev = inl_dev->pci_dev;
630
631         /* Release SSO */
632         rc = nix_inl_sso_release(inl_dev);
633
634         /* Release NIX */
635         rc |= nix_inl_nix_release(inl_dev);
636
637         /* Detach LF's */
638         rc |= nix_inl_lf_detach(inl_dev);
639
640         /* Cleanup mbox */
641         rc |= dev_fini(&inl_dev->dev, pci_dev);
642         if (rc)
643                 return rc;
644
645         idev->nix_inl_dev = NULL;
646         return 0;
647 }