net/mlx5: remove redundant flag in device config
[dpdk.git] / drivers / common / cnxk / roc_nix_inl.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 PLT_STATIC_ASSERT(ROC_NIX_INL_ONF_IPSEC_INB_SA_SZ ==
9                   1UL << ROC_NIX_INL_ONF_IPSEC_INB_SA_SZ_LOG2);
10 PLT_STATIC_ASSERT(ROC_NIX_INL_ONF_IPSEC_INB_SA_SZ == 512);
11 PLT_STATIC_ASSERT(ROC_NIX_INL_ONF_IPSEC_OUTB_SA_SZ ==
12                   1UL << ROC_NIX_INL_ONF_IPSEC_OUTB_SA_SZ_LOG2);
13 PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_INB_SA_SZ ==
14                   1UL << ROC_NIX_INL_OT_IPSEC_INB_SA_SZ_LOG2);
15 PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_INB_SA_SZ == 1024);
16 PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_OUTB_SA_SZ ==
17                   1UL << ROC_NIX_INL_OT_IPSEC_OUTB_SA_SZ_LOG2);
18
19 static int
20 nix_inl_inb_sa_tbl_setup(struct roc_nix *roc_nix)
21 {
22         uint16_t ipsec_in_max_spi = roc_nix->ipsec_in_max_spi;
23         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
24         struct roc_nix_ipsec_cfg cfg;
25         size_t inb_sa_sz;
26         int rc;
27
28         /* CN9K SA size is different */
29         if (roc_model_is_cn9k())
30                 inb_sa_sz = ROC_NIX_INL_ONF_IPSEC_INB_SA_SZ;
31         else
32                 inb_sa_sz = ROC_NIX_INL_OT_IPSEC_INB_SA_SZ;
33
34         /* Alloc contiguous memory for Inbound SA's */
35         nix->inb_sa_sz = inb_sa_sz;
36         nix->inb_sa_base = plt_zmalloc(inb_sa_sz * ipsec_in_max_spi,
37                                        ROC_NIX_INL_SA_BASE_ALIGN);
38         if (!nix->inb_sa_base) {
39                 plt_err("Failed to allocate memory for Inbound SA");
40                 return -ENOMEM;
41         }
42
43         memset(&cfg, 0, sizeof(cfg));
44         cfg.sa_size = inb_sa_sz;
45         cfg.iova = (uintptr_t)nix->inb_sa_base;
46         cfg.max_sa = ipsec_in_max_spi + 1;
47         cfg.tt = SSO_TT_ORDERED;
48
49         /* Setup device specific inb SA table */
50         rc = roc_nix_lf_inl_ipsec_cfg(roc_nix, &cfg, true);
51         if (rc) {
52                 plt_err("Failed to setup NIX Inbound SA conf, rc=%d", rc);
53                 goto free_mem;
54         }
55
56         return 0;
57 free_mem:
58         plt_free(nix->inb_sa_base);
59         nix->inb_sa_base = NULL;
60         return rc;
61 }
62
63 static int
64 nix_inl_sa_tbl_release(struct roc_nix *roc_nix)
65 {
66         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
67         int rc;
68
69         rc = roc_nix_lf_inl_ipsec_cfg(roc_nix, NULL, false);
70         if (rc) {
71                 plt_err("Failed to disable Inbound inline ipsec, rc=%d", rc);
72                 return rc;
73         }
74
75         plt_free(nix->inb_sa_base);
76         nix->inb_sa_base = NULL;
77         return 0;
78 }
79
80 struct roc_cpt_lf *
81 roc_nix_inl_outb_lf_base_get(struct roc_nix *roc_nix)
82 {
83         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
84
85         /* NIX Inline config needs to be done */
86         if (!nix->inl_outb_ena || !nix->cpt_lf_base)
87                 return NULL;
88
89         return (struct roc_cpt_lf *)nix->cpt_lf_base;
90 }
91
92 uintptr_t
93 roc_nix_inl_outb_sa_base_get(struct roc_nix *roc_nix)
94 {
95         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
96
97         return (uintptr_t)nix->outb_sa_base;
98 }
99
100 uintptr_t
101 roc_nix_inl_inb_sa_base_get(struct roc_nix *roc_nix, bool inb_inl_dev)
102 {
103         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
104         struct idev_cfg *idev = idev_get_cfg();
105         struct nix_inl_dev *inl_dev;
106
107         if (idev == NULL)
108                 return 0;
109
110         if (!nix->inl_inb_ena)
111                 return 0;
112
113         inl_dev = idev->nix_inl_dev;
114         if (inb_inl_dev) {
115                 /* Return inline dev sa base */
116                 if (inl_dev)
117                         return (uintptr_t)inl_dev->inb_sa_base;
118                 return 0;
119         }
120
121         return (uintptr_t)nix->inb_sa_base;
122 }
123
124 uint32_t
125 roc_nix_inl_inb_sa_max_spi(struct roc_nix *roc_nix, bool inb_inl_dev)
126 {
127         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
128         struct idev_cfg *idev = idev_get_cfg();
129         struct nix_inl_dev *inl_dev;
130
131         if (idev == NULL)
132                 return 0;
133
134         if (!nix->inl_inb_ena)
135                 return 0;
136
137         inl_dev = idev->nix_inl_dev;
138         if (inb_inl_dev) {
139                 if (inl_dev)
140                         return inl_dev->ipsec_in_max_spi;
141                 return 0;
142         }
143
144         return roc_nix->ipsec_in_max_spi;
145 }
146
147 uint32_t
148 roc_nix_inl_inb_sa_sz(struct roc_nix *roc_nix, bool inl_dev_sa)
149 {
150         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
151         struct idev_cfg *idev = idev_get_cfg();
152         struct nix_inl_dev *inl_dev;
153
154         if (idev == NULL)
155                 return 0;
156
157         if (!inl_dev_sa)
158                 return nix->inb_sa_sz;
159
160         inl_dev = idev->nix_inl_dev;
161         if (inl_dev_sa && inl_dev)
162                 return inl_dev->inb_sa_sz;
163
164         /* On error */
165         return 0;
166 }
167
168 uintptr_t
169 roc_nix_inl_inb_sa_get(struct roc_nix *roc_nix, bool inb_inl_dev, uint32_t spi)
170 {
171         uintptr_t sa_base;
172         uint32_t max_spi;
173         uint64_t sz;
174
175         sa_base = roc_nix_inl_inb_sa_base_get(roc_nix, inb_inl_dev);
176         /* Check if SA base exists */
177         if (!sa_base)
178                 return 0;
179
180         /* Check if SPI is in range */
181         max_spi = roc_nix_inl_inb_sa_max_spi(roc_nix, inb_inl_dev);
182         if (spi > max_spi) {
183                 plt_err("Inbound SA SPI %u exceeds max %u", spi, max_spi);
184                 return 0;
185         }
186
187         /* Get SA size */
188         sz = roc_nix_inl_inb_sa_sz(roc_nix, inb_inl_dev);
189         if (!sz)
190                 return 0;
191
192         /* Basic logic of SPI->SA for now */
193         return (sa_base + (spi * sz));
194 }
195
196 int
197 roc_nix_inl_inb_init(struct roc_nix *roc_nix)
198 {
199         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
200         struct idev_cfg *idev = idev_get_cfg();
201         struct roc_cpt *roc_cpt;
202         uint16_t param1;
203         int rc;
204
205         if (idev == NULL)
206                 return -ENOTSUP;
207
208         /* Unless we have another mechanism to trigger
209          * onetime Inline config in CPTPF, we cannot
210          * support without CPT being probed.
211          */
212         roc_cpt = idev->cpt;
213         if (!roc_cpt) {
214                 plt_err("Cannot support inline inbound, cryptodev not probed");
215                 return -ENOTSUP;
216         }
217
218         if (roc_model_is_cn9k()) {
219                 param1 = ROC_ONF_IPSEC_INB_MAX_L2_SZ;
220         } else {
221                 union roc_ot_ipsec_inb_param1 u;
222
223                 u.u16 = 0;
224                 u.s.esp_trailer_disable = 1;
225                 param1 = u.u16;
226         }
227
228         /* Do onetime Inbound Inline config in CPTPF */
229         rc = roc_cpt_inline_ipsec_inb_cfg(roc_cpt, param1, 0);
230         if (rc && rc != -EEXIST) {
231                 plt_err("Failed to setup inbound lf, rc=%d", rc);
232                 return rc;
233         }
234
235         /* Setup Inbound SA table */
236         rc = nix_inl_inb_sa_tbl_setup(roc_nix);
237         if (rc)
238                 return rc;
239
240         nix->inl_inb_ena = true;
241         return 0;
242 }
243
244 int
245 roc_nix_inl_inb_fini(struct roc_nix *roc_nix)
246 {
247         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
248
249         if (!nix->inl_inb_ena)
250                 return 0;
251
252         nix->inl_inb_ena = false;
253
254         /* Disable Inbound SA */
255         return nix_inl_sa_tbl_release(roc_nix);
256 }
257
258 int
259 roc_nix_inl_outb_init(struct roc_nix *roc_nix)
260 {
261         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
262         struct idev_cfg *idev = idev_get_cfg();
263         struct roc_cpt_lf *lf_base, *lf;
264         struct dev *dev = &nix->dev;
265         struct msix_offset_rsp *rsp;
266         struct nix_inl_dev *inl_dev;
267         uint16_t sso_pffunc;
268         uint8_t eng_grpmask;
269         uint64_t blkaddr;
270         uint16_t nb_lf;
271         void *sa_base;
272         size_t sa_sz;
273         int i, j, rc;
274
275         if (idev == NULL)
276                 return -ENOTSUP;
277
278         nb_lf = roc_nix->outb_nb_crypto_qs;
279         blkaddr = nix->is_nix1 ? RVU_BLOCK_ADDR_CPT1 : RVU_BLOCK_ADDR_CPT0;
280
281         /* Retrieve inline device if present */
282         inl_dev = idev->nix_inl_dev;
283         sso_pffunc = inl_dev ? inl_dev->dev.pf_func : idev_sso_pffunc_get();
284         if (!sso_pffunc) {
285                 plt_err("Failed to setup inline outb, need either "
286                         "inline device or sso device");
287                 return -ENOTSUP;
288         }
289
290         /* Attach CPT LF for outbound */
291         rc = cpt_lfs_attach(dev, blkaddr, true, nb_lf);
292         if (rc) {
293                 plt_err("Failed to attach CPT LF for inline outb, rc=%d", rc);
294                 return rc;
295         }
296
297         /* Alloc CPT LF */
298         eng_grpmask = (1ULL << ROC_CPT_DFLT_ENG_GRP_SE |
299                        1ULL << ROC_CPT_DFLT_ENG_GRP_SE_IE |
300                        1ULL << ROC_CPT_DFLT_ENG_GRP_AE);
301         rc = cpt_lfs_alloc(dev, eng_grpmask, blkaddr, true);
302         if (rc) {
303                 plt_err("Failed to alloc CPT LF resources, rc=%d", rc);
304                 goto lf_detach;
305         }
306
307         /* Get msix offsets */
308         rc = cpt_get_msix_offset(dev, &rsp);
309         if (rc) {
310                 plt_err("Failed to get CPT LF msix offset, rc=%d", rc);
311                 goto lf_free;
312         }
313
314         mbox_memcpy(nix->cpt_msixoff,
315                     nix->is_nix1 ? rsp->cpt1_lf_msixoff : rsp->cptlf_msixoff,
316                     sizeof(nix->cpt_msixoff));
317
318         /* Alloc required num of cpt lfs */
319         lf_base = plt_zmalloc(nb_lf * sizeof(struct roc_cpt_lf), 0);
320         if (!lf_base) {
321                 plt_err("Failed to alloc cpt lf memory");
322                 rc = -ENOMEM;
323                 goto lf_free;
324         }
325
326         /* Initialize CPT LF's */
327         for (i = 0; i < nb_lf; i++) {
328                 lf = &lf_base[i];
329
330                 lf->lf_id = i;
331                 lf->nb_desc = roc_nix->outb_nb_desc;
332                 lf->dev = &nix->dev;
333                 lf->msixoff = nix->cpt_msixoff[i];
334                 lf->pci_dev = nix->pci_dev;
335
336                 /* Setup CPT LF instruction queue */
337                 rc = cpt_lf_init(lf);
338                 if (rc) {
339                         plt_err("Failed to initialize CPT LF, rc=%d", rc);
340                         goto lf_fini;
341                 }
342
343                 /* Associate this CPT LF with NIX PFFUNC */
344                 rc = cpt_lf_outb_cfg(dev, sso_pffunc, nix->dev.pf_func, i,
345                                      true);
346                 if (rc) {
347                         plt_err("Failed to setup CPT LF->(NIX,SSO) link, rc=%d",
348                                 rc);
349                         goto lf_fini;
350                 }
351
352                 /* Enable IQ */
353                 roc_cpt_iq_enable(lf);
354         }
355
356         if (!roc_nix->ipsec_out_max_sa)
357                 goto skip_sa_alloc;
358
359         /* CN9K SA size is different */
360         if (roc_model_is_cn9k())
361                 sa_sz = ROC_NIX_INL_ONF_IPSEC_OUTB_SA_SZ;
362         else
363                 sa_sz = ROC_NIX_INL_OT_IPSEC_OUTB_SA_SZ;
364         /* Alloc contiguous memory of outbound SA */
365         sa_base = plt_zmalloc(sa_sz * roc_nix->ipsec_out_max_sa,
366                               ROC_NIX_INL_SA_BASE_ALIGN);
367         if (!sa_base) {
368                 plt_err("Outbound SA base alloc failed");
369                 goto lf_fini;
370         }
371         nix->outb_sa_base = sa_base;
372         nix->outb_sa_sz = sa_sz;
373
374 skip_sa_alloc:
375
376         nix->cpt_lf_base = lf_base;
377         nix->nb_cpt_lf = nb_lf;
378         nix->outb_err_sso_pffunc = sso_pffunc;
379         nix->inl_outb_ena = true;
380         return 0;
381
382 lf_fini:
383         for (j = i - 1; j >= 0; j--)
384                 cpt_lf_fini(&lf_base[j]);
385         plt_free(lf_base);
386 lf_free:
387         rc |= cpt_lfs_free(dev);
388 lf_detach:
389         rc |= cpt_lfs_detach(dev);
390         return rc;
391 }
392
393 int
394 roc_nix_inl_outb_fini(struct roc_nix *roc_nix)
395 {
396         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
397         struct roc_cpt_lf *lf_base = nix->cpt_lf_base;
398         struct dev *dev = &nix->dev;
399         int i, rc, ret = 0;
400
401         if (!nix->inl_outb_ena)
402                 return 0;
403
404         nix->inl_outb_ena = false;
405
406         /* Cleanup CPT LF instruction queue */
407         for (i = 0; i < nix->nb_cpt_lf; i++)
408                 cpt_lf_fini(&lf_base[i]);
409
410         /* Free LF resources */
411         rc = cpt_lfs_free(dev);
412         if (rc)
413                 plt_err("Failed to free CPT LF resources, rc=%d", rc);
414         ret |= rc;
415
416         /* Detach LF */
417         rc = cpt_lfs_detach(dev);
418         if (rc)
419                 plt_err("Failed to detach CPT LF, rc=%d", rc);
420
421         /* Free LF memory */
422         plt_free(lf_base);
423         nix->cpt_lf_base = NULL;
424         nix->nb_cpt_lf = 0;
425
426         /* Free outbound SA base */
427         plt_free(nix->outb_sa_base);
428         nix->outb_sa_base = NULL;
429
430         ret |= rc;
431         return ret;
432 }
433
434 bool
435 roc_nix_inl_dev_is_probed(void)
436 {
437         struct idev_cfg *idev = idev_get_cfg();
438
439         if (idev == NULL)
440                 return 0;
441
442         return !!idev->nix_inl_dev;
443 }
444
445 bool
446 roc_nix_inl_inb_is_enabled(struct roc_nix *roc_nix)
447 {
448         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
449
450         return nix->inl_inb_ena;
451 }
452
453 bool
454 roc_nix_inl_outb_is_enabled(struct roc_nix *roc_nix)
455 {
456         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
457
458         return nix->inl_outb_ena;
459 }
460
461 int
462 roc_nix_inl_dev_rq_get(struct roc_nix_rq *rq)
463 {
464         struct idev_cfg *idev = idev_get_cfg();
465         struct nix_inl_dev *inl_dev;
466         struct roc_nix_rq *inl_rq;
467         struct dev *dev;
468         int rc;
469
470         if (idev == NULL)
471                 return 0;
472
473         inl_dev = idev->nix_inl_dev;
474         /* Nothing to do if no inline device */
475         if (!inl_dev)
476                 return 0;
477
478         /* Just take reference if already inited */
479         if (inl_dev->rq_refs) {
480                 inl_dev->rq_refs++;
481                 rq->inl_dev_ref = true;
482                 return 0;
483         }
484
485         dev = &inl_dev->dev;
486         inl_rq = &inl_dev->rq;
487         memset(inl_rq, 0, sizeof(struct roc_nix_rq));
488
489         /* Take RQ pool attributes from the first ethdev RQ */
490         inl_rq->qid = 0;
491         inl_rq->aura_handle = rq->aura_handle;
492         inl_rq->first_skip = rq->first_skip;
493         inl_rq->later_skip = rq->later_skip;
494         inl_rq->lpb_size = rq->lpb_size;
495
496         if (!roc_model_is_cn9k()) {
497                 uint64_t aura_limit =
498                         roc_npa_aura_op_limit_get(inl_rq->aura_handle);
499                 uint64_t aura_shift = plt_log2_u32(aura_limit);
500
501                 if (aura_shift < 8)
502                         aura_shift = 0;
503                 else
504                         aura_shift = aura_shift - 8;
505
506                 /* Set first pass RQ to drop when half of the buffers are in
507                  * use to avoid metabuf alloc failure. This is needed as long
508                  * as we cannot use different
509                  */
510                 inl_rq->red_pass = (aura_limit / 2) >> aura_shift;
511                 inl_rq->red_drop = ((aura_limit / 2) - 1) >> aura_shift;
512         }
513
514         /* Enable IPSec */
515         inl_rq->ipsech_ena = true;
516
517         inl_rq->flow_tag_width = 20;
518         /* Special tag mask */
519         inl_rq->tag_mask = 0xFFF00000;
520         inl_rq->tt = SSO_TT_ORDERED;
521         inl_rq->hwgrp = 0;
522         inl_rq->wqe_skip = 1;
523         inl_rq->sso_ena = true;
524
525         /* Prepare and send RQ init mbox */
526         if (roc_model_is_cn9k())
527                 rc = nix_rq_cn9k_cfg(dev, inl_rq, inl_dev->qints, false, true);
528         else
529                 rc = nix_rq_cfg(dev, inl_rq, inl_dev->qints, false, true);
530         if (rc) {
531                 plt_err("Failed to prepare aq_enq msg, rc=%d", rc);
532                 return rc;
533         }
534
535         rc = mbox_process(dev->mbox);
536         if (rc) {
537                 plt_err("Failed to send aq_enq msg, rc=%d", rc);
538                 return rc;
539         }
540
541         inl_dev->rq_refs++;
542         rq->inl_dev_ref = true;
543         return 0;
544 }
545
546 int
547 roc_nix_inl_dev_rq_put(struct roc_nix_rq *rq)
548 {
549         struct idev_cfg *idev = idev_get_cfg();
550         struct nix_inl_dev *inl_dev;
551         struct roc_nix_rq *inl_rq;
552         struct dev *dev;
553         int rc;
554
555         if (idev == NULL)
556                 return 0;
557
558         if (!rq->inl_dev_ref)
559                 return 0;
560
561         inl_dev = idev->nix_inl_dev;
562         /* Inline device should be there if we have ref */
563         if (!inl_dev) {
564                 plt_err("Failed to find inline device with refs");
565                 return -EFAULT;
566         }
567
568         rq->inl_dev_ref = false;
569         inl_dev->rq_refs--;
570         if (inl_dev->rq_refs)
571                 return 0;
572
573         dev = &inl_dev->dev;
574         inl_rq = &inl_dev->rq;
575         /* There are no more references, disable RQ */
576         rc = nix_rq_ena_dis(dev, inl_rq, false);
577         if (rc)
578                 plt_err("Failed to disable inline device rq, rc=%d", rc);
579
580         /* Flush NIX LF for CN10K */
581         if (roc_model_is_cn10k())
582                 plt_write64(0, inl_dev->nix_base + NIX_LF_OP_VWQE_FLUSH);
583
584         return rc;
585 }
586
587 uint64_t
588 roc_nix_inl_dev_rq_limit_get(void)
589 {
590         struct idev_cfg *idev = idev_get_cfg();
591         struct nix_inl_dev *inl_dev;
592         struct roc_nix_rq *inl_rq;
593
594         if (!idev || !idev->nix_inl_dev)
595                 return 0;
596
597         inl_dev = idev->nix_inl_dev;
598         if (!inl_dev->rq_refs)
599                 return 0;
600
601         inl_rq = &inl_dev->rq;
602
603         return roc_npa_aura_op_limit_get(inl_rq->aura_handle);
604 }
605
606 void
607 roc_nix_inb_mode_set(struct roc_nix *roc_nix, bool use_inl_dev)
608 {
609         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
610
611         /* Info used by NPC flow rule add */
612         nix->inb_inl_dev = use_inl_dev;
613 }
614
615 bool
616 roc_nix_inb_is_with_inl_dev(struct roc_nix *roc_nix)
617 {
618         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
619
620         return nix->inb_inl_dev;
621 }
622
623 struct roc_nix_rq *
624 roc_nix_inl_dev_rq(void)
625 {
626         struct idev_cfg *idev = idev_get_cfg();
627         struct nix_inl_dev *inl_dev;
628
629         if (idev != NULL) {
630                 inl_dev = idev->nix_inl_dev;
631                 if (inl_dev != NULL && inl_dev->rq_refs)
632                         return &inl_dev->rq;
633         }
634
635         return NULL;
636 }
637
638 uint16_t __roc_api
639 roc_nix_inl_outb_sso_pffunc_get(struct roc_nix *roc_nix)
640 {
641         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
642
643         return nix->outb_err_sso_pffunc;
644 }
645
646 int
647 roc_nix_inl_cb_register(roc_nix_inl_sso_work_cb_t cb, void *args)
648 {
649         struct idev_cfg *idev = idev_get_cfg();
650         struct nix_inl_dev *inl_dev;
651
652         if (idev == NULL)
653                 return -EIO;
654
655         inl_dev = idev->nix_inl_dev;
656         if (!inl_dev)
657                 return -EIO;
658
659         /* Be silent if registration called with same cb and args */
660         if (inl_dev->work_cb == cb && inl_dev->cb_args == args)
661                 return 0;
662
663         /* Don't allow registration again if registered with different cb */
664         if (inl_dev->work_cb)
665                 return -EBUSY;
666
667         inl_dev->work_cb = cb;
668         inl_dev->cb_args = args;
669         return 0;
670 }
671
672 int
673 roc_nix_inl_cb_unregister(roc_nix_inl_sso_work_cb_t cb, void *args)
674 {
675         struct idev_cfg *idev = idev_get_cfg();
676         struct nix_inl_dev *inl_dev;
677
678         if (idev == NULL)
679                 return -ENOENT;
680
681         inl_dev = idev->nix_inl_dev;
682         if (!inl_dev)
683                 return -ENOENT;
684
685         if (inl_dev->work_cb != cb || inl_dev->cb_args != args)
686                 return -EINVAL;
687
688         inl_dev->work_cb = NULL;
689         inl_dev->cb_args = NULL;
690         return 0;
691 }
692
693 int
694 roc_nix_inl_inb_tag_update(struct roc_nix *roc_nix, uint32_t tag_const,
695                            uint8_t tt)
696 {
697         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
698         struct roc_nix_ipsec_cfg cfg;
699
700         /* Be silent if inline inbound not enabled */
701         if (!nix->inl_inb_ena)
702                 return 0;
703
704         memset(&cfg, 0, sizeof(cfg));
705         cfg.sa_size = nix->inb_sa_sz;
706         cfg.iova = (uintptr_t)nix->inb_sa_base;
707         cfg.max_sa = roc_nix->ipsec_in_max_spi + 1;
708         cfg.tt = tt;
709         cfg.tag_const = tag_const;
710
711         return roc_nix_lf_inl_ipsec_cfg(roc_nix, &cfg, true);
712 }
713
714 int
715 roc_nix_inl_sa_sync(struct roc_nix *roc_nix, void *sa, bool inb,
716                     enum roc_nix_inl_sa_sync_op op)
717 {
718         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
719         struct roc_cpt_lf *outb_lf = nix->cpt_lf_base;
720         union cpt_lf_ctx_reload reload;
721         union cpt_lf_ctx_flush flush;
722         uintptr_t rbase;
723
724         /* Nothing much to do on cn9k */
725         if (roc_model_is_cn9k()) {
726                 plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
727                 return 0;
728         }
729
730         if (!inb && !outb_lf)
731                 return -EINVAL;
732
733         /* Performing op via outbound lf is enough
734          * when inline dev is not in use.
735          */
736         if (outb_lf && !nix->inb_inl_dev) {
737                 rbase = outb_lf->rbase;
738
739                 flush.u = 0;
740                 reload.u = 0;
741                 switch (op) {
742                 case ROC_NIX_INL_SA_OP_FLUSH_INVAL:
743                         flush.s.inval = 1;
744                         /* fall through */
745                 case ROC_NIX_INL_SA_OP_FLUSH:
746                         flush.s.cptr = ((uintptr_t)sa) >> 7;
747                         plt_write64(flush.u, rbase + CPT_LF_CTX_FLUSH);
748                         break;
749                 case ROC_NIX_INL_SA_OP_RELOAD:
750                         reload.s.cptr = ((uintptr_t)sa) >> 7;
751                         plt_write64(reload.u, rbase + CPT_LF_CTX_RELOAD);
752                         break;
753                 default:
754                         return -EINVAL;
755                 }
756                 return 0;
757         }
758
759         return -ENOTSUP;
760 }
761
762 void
763 roc_nix_inl_dev_lock(void)
764 {
765         struct idev_cfg *idev = idev_get_cfg();
766
767         if (idev != NULL)
768                 plt_spinlock_lock(&idev->nix_inl_dev_lock);
769 }
770
771 void
772 roc_nix_inl_dev_unlock(void)
773 {
774         struct idev_cfg *idev = idev_get_cfg();
775
776         if (idev != NULL)
777                 plt_spinlock_unlock(&idev->nix_inl_dev_lock);
778 }