Branch data Line data Source code
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 : : uint32_t soft_exp_consumer_cnt;
9 : : roc_nix_inl_meta_pool_cb_t meta_pool_cb;
10 : : roc_nix_inl_custom_meta_pool_cb_t custom_meta_pool_cb;
11 : :
12 : : PLT_STATIC_ASSERT(ROC_NIX_INL_ON_IPSEC_INB_SA_SZ ==
13 : : 1UL << ROC_NIX_INL_ON_IPSEC_INB_SA_SZ_LOG2);
14 : : PLT_STATIC_ASSERT(ROC_NIX_INL_ON_IPSEC_INB_SA_SZ == 1024);
15 : : PLT_STATIC_ASSERT(ROC_NIX_INL_ON_IPSEC_OUTB_SA_SZ ==
16 : : 1UL << ROC_NIX_INL_ON_IPSEC_OUTB_SA_SZ_LOG2);
17 : : PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_INB_SA_SZ ==
18 : : 1UL << ROC_NIX_INL_OT_IPSEC_INB_SA_SZ_LOG2);
19 : : PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_INB_SA_SZ == 1024);
20 : : PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_OUTB_SA_SZ ==
21 : : 1UL << ROC_NIX_INL_OT_IPSEC_OUTB_SA_SZ_LOG2);
22 : :
23 : : static int
24 : 0 : nix_inl_meta_aura_destroy(struct roc_nix *roc_nix)
25 : : {
26 : 0 : struct idev_cfg *idev = idev_get_cfg();
27 : : struct idev_nix_inl_cfg *inl_cfg;
28 : 0 : char mempool_name[24] = {'\0'};
29 : : char *mp_name = NULL;
30 : : uint64_t *meta_aura;
31 : : int rc;
32 : :
33 [ # # ]: 0 : if (!idev)
34 : : return -EINVAL;
35 : :
36 : : inl_cfg = &idev->inl_cfg;
37 : :
38 [ # # # # ]: 0 : if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena) {
39 : 0 : meta_aura = &inl_cfg->meta_aura;
40 : : } else {
41 : 0 : meta_aura = &roc_nix->meta_aura_handle;
42 : 0 : snprintf(mempool_name, sizeof(mempool_name), "NIX_INL_META_POOL_%d",
43 : 0 : roc_nix->port_id + 1);
44 : : mp_name = mempool_name;
45 : : }
46 : :
47 : : /* Destroy existing Meta aura */
48 [ # # ]: 0 : if (*meta_aura) {
49 : : uint64_t avail, limit;
50 : :
51 : : /* Check if all buffers are back to pool */
52 : : avail = roc_npa_aura_op_available(*meta_aura);
53 : : limit = roc_npa_aura_op_limit_get(*meta_aura);
54 : : if (avail != limit)
55 : : plt_warn("Not all buffers are back to meta pool,"
56 : : " %" PRIu64 " != %" PRIu64, avail, limit);
57 : :
58 : 0 : rc = meta_pool_cb(meta_aura, &roc_nix->meta_mempool, 0, 0, true, mp_name);
59 [ # # ]: 0 : if (rc) {
60 : 0 : plt_err("Failed to destroy meta aura, rc=%d", rc);
61 : 0 : return rc;
62 : : }
63 : :
64 [ # # ]: 0 : if (!roc_nix->local_meta_aura_ena) {
65 : 0 : inl_cfg->meta_aura = 0;
66 : 0 : inl_cfg->buf_sz = 0;
67 : 0 : inl_cfg->nb_bufs = 0;
68 : : } else
69 : 0 : roc_nix->buf_sz = 0;
70 : : }
71 : :
72 : : return 0;
73 : : }
74 : :
75 : : static int
76 : 0 : nix_inl_meta_aura_create(struct idev_cfg *idev, struct roc_nix *roc_nix, uint16_t first_skip,
77 : : uint64_t *meta_aura, bool is_local_metaaura)
78 : : {
79 : : uint64_t mask = BIT_ULL(ROC_NPA_BUF_TYPE_PACKET_IPSEC);
80 : : struct idev_nix_inl_cfg *inl_cfg;
81 : : struct nix_inl_dev *nix_inl_dev;
82 : 0 : int port_id = roc_nix->port_id;
83 : 0 : char mempool_name[24] = {'\0'};
84 : : struct roc_nix_rq *inl_rq;
85 : : uint32_t nb_bufs, buf_sz;
86 : : char *mp_name = NULL;
87 : : uint16_t inl_rq_id;
88 : : uintptr_t mp;
89 : : int rc;
90 : :
91 : : inl_cfg = &idev->inl_cfg;
92 : 0 : nix_inl_dev = idev->nix_inl_dev;
93 : :
94 [ # # ]: 0 : if (is_local_metaaura) {
95 : : /* Per LF Meta Aura */
96 : : inl_rq_id = nix_inl_dev->nb_rqs > 1 ? port_id : 0;
97 : : inl_rq = &nix_inl_dev->rqs[inl_rq_id];
98 : :
99 : : nb_bufs = roc_npa_aura_op_limit_get(inl_rq->aura_handle);
100 : : if (inl_rq->spb_ena)
101 : : nb_bufs += roc_npa_aura_op_limit_get(inl_rq->spb_aura_handle);
102 : :
103 : : /* Override meta buf size from NIX devargs if present */
104 [ # # ]: 0 : if (roc_nix->meta_buf_sz)
105 : : buf_sz = roc_nix->meta_buf_sz;
106 : : else
107 : 0 : buf_sz = first_skip + NIX_INL_META_SIZE;
108 : :
109 : : /* Create Metapool name */
110 : 0 : snprintf(mempool_name, sizeof(mempool_name), "NIX_INL_META_POOL_%d",
111 : : roc_nix->port_id + 1);
112 : : mp_name = mempool_name;
113 : : } else {
114 : : /* Global Meta Aura (Aura 0) */
115 : : /* Override meta buf count from devargs if present */
116 [ # # # # ]: 0 : if (nix_inl_dev && nix_inl_dev->nb_meta_bufs)
117 : : nb_bufs = nix_inl_dev->nb_meta_bufs;
118 : : else
119 : 0 : nb_bufs = roc_npa_buf_type_limit_get(mask);
120 : :
121 : : /* Override meta buf size from devargs if present */
122 [ # # # # ]: 0 : if (nix_inl_dev && nix_inl_dev->meta_buf_sz)
123 : : buf_sz = nix_inl_dev->meta_buf_sz;
124 : : else
125 : 0 : buf_sz = first_skip + NIX_INL_META_SIZE;
126 : : }
127 : :
128 : : /* Allocate meta aura */
129 : 0 : rc = meta_pool_cb(meta_aura, &mp, buf_sz, nb_bufs, false, mp_name);
130 [ # # ]: 0 : if (rc) {
131 : 0 : plt_err("Failed to allocate meta aura, rc=%d", rc);
132 : 0 : return rc;
133 : : }
134 : 0 : roc_nix->meta_mempool = mp;
135 : :
136 : 0 : plt_nix_dbg("Created meta aura %p(%s)for port %d", (void *)*meta_aura, mp_name,
137 : : roc_nix->port_id);
138 : :
139 [ # # ]: 0 : if (!is_local_metaaura) {
140 : 0 : inl_cfg->buf_sz = buf_sz;
141 : 0 : inl_cfg->nb_bufs = nb_bufs;
142 : 0 : inl_cfg->meta_mempool = mp;
143 : : } else
144 : 0 : roc_nix->buf_sz = buf_sz;
145 : :
146 : : return 0;
147 : : }
148 : :
149 : : static int
150 : 0 : nix_inl_custom_meta_aura_destroy(struct roc_nix *roc_nix)
151 : : {
152 : 0 : struct idev_cfg *idev = idev_get_cfg();
153 : : struct idev_nix_inl_cfg *inl_cfg;
154 : 0 : char mempool_name[24] = {'\0'};
155 : : char *mp_name = NULL;
156 : : uint64_t *meta_aura;
157 : : int rc;
158 : :
159 [ # # ]: 0 : if (!idev)
160 : : return -EINVAL;
161 : :
162 : : inl_cfg = &idev->inl_cfg;
163 : 0 : meta_aura = &roc_nix->meta_aura_handle;
164 : 0 : snprintf(mempool_name, sizeof(mempool_name), "NIX_INL_META_POOL_%d",
165 [ # # ]: 0 : roc_nix->port_id + 1);
166 : : mp_name = mempool_name;
167 : :
168 : : /* Destroy existing Meta aura */
169 [ # # ]: 0 : if (*meta_aura) {
170 : : uint64_t avail, limit;
171 : :
172 : : /* Check if all buffers are back to pool */
173 : : avail = roc_npa_aura_op_available(*meta_aura);
174 : : limit = roc_npa_aura_op_limit_get(*meta_aura);
175 : : if (avail != limit)
176 : : plt_warn("Not all buffers are back to meta pool,"
177 : : " %" PRIu64 " != %" PRIu64, avail, limit);
178 : :
179 : 0 : rc = custom_meta_pool_cb(inl_cfg->meta_mempool, &roc_nix->meta_mempool, mp_name,
180 : : meta_aura, 0, 0, true);
181 [ # # ]: 0 : if (rc) {
182 : 0 : plt_err("Failed to destroy meta aura, rc=%d", rc);
183 : 0 : return rc;
184 : : }
185 : :
186 : 0 : roc_nix->buf_sz = 0;
187 : : }
188 : :
189 : : return 0;
190 : : }
191 : :
192 : : static int
193 : 0 : nix_inl_custom_meta_aura_create(struct idev_cfg *idev, struct roc_nix *roc_nix, uint16_t first_skip,
194 : : uint64_t *meta_aura)
195 : : {
196 : : uint64_t mask = BIT_ULL(ROC_NPA_BUF_TYPE_PACKET_IPSEC);
197 : : struct idev_nix_inl_cfg *inl_cfg;
198 : : struct nix_inl_dev *nix_inl_dev;
199 : 0 : char mempool_name[24] = {'\0'};
200 : : uint32_t nb_bufs, buf_sz;
201 : : char *mp_name = NULL;
202 : : uintptr_t mp;
203 : : int rc;
204 : :
205 : : inl_cfg = &idev->inl_cfg;
206 : 0 : nix_inl_dev = idev->nix_inl_dev;
207 : :
208 : : /* Override meta buf count from devargs if present */
209 [ # # # # ]: 0 : if (nix_inl_dev && nix_inl_dev->nb_meta_bufs)
210 : : nb_bufs = nix_inl_dev->nb_meta_bufs;
211 : : else
212 : 0 : nb_bufs = roc_npa_buf_type_limit_get(mask);
213 : :
214 : : /* Override meta buf size from devargs if present */
215 [ # # # # ]: 0 : if (nix_inl_dev && nix_inl_dev->meta_buf_sz)
216 : : buf_sz = nix_inl_dev->meta_buf_sz;
217 : : else
218 : 0 : buf_sz = first_skip + NIX_INL_META_SIZE;
219 : :
220 : : /* Create Metapool name */
221 : 0 : snprintf(mempool_name, sizeof(mempool_name), "NIX_INL_META_POOL_%d",
222 : 0 : roc_nix->port_id + 1);
223 : : mp_name = mempool_name;
224 : :
225 : : /* Allocate meta aura */
226 : 0 : rc = custom_meta_pool_cb(inl_cfg->meta_mempool, &mp, mp_name, meta_aura,
227 : : buf_sz, nb_bufs, false);
228 [ # # ]: 0 : if (rc) {
229 : 0 : plt_err("Failed to allocate meta aura, rc=%d", rc);
230 : 0 : return rc;
231 : : }
232 : :
233 : : /* Overwrite */
234 : 0 : roc_nix->meta_mempool = mp;
235 : 0 : roc_nix->buf_sz = buf_sz;
236 : :
237 : 0 : return 0;
238 : : }
239 : :
240 : : static int
241 : 0 : nix_inl_global_meta_buffer_validate(struct idev_cfg *idev, struct roc_nix_rq *rq)
242 : : {
243 : : struct idev_nix_inl_cfg *inl_cfg;
244 : : uint32_t actual, expected;
245 : : uint64_t mask, type_mask;
246 : :
247 : : inl_cfg = &idev->inl_cfg;
248 : : /* Validate if we have enough meta buffers */
249 : : mask = BIT_ULL(ROC_NPA_BUF_TYPE_PACKET_IPSEC);
250 : 0 : expected = roc_npa_buf_type_limit_get(mask);
251 : 0 : actual = inl_cfg->nb_bufs;
252 : :
253 [ # # ]: 0 : if (actual < expected) {
254 : 0 : plt_err("Insufficient buffers in meta aura %u < %u (expected)",
255 : : actual, expected);
256 : 0 : return -EIO;
257 : : }
258 : :
259 : : /* Validate if we have enough space for meta buffer */
260 [ # # ]: 0 : if (rq->first_skip + NIX_INL_META_SIZE > inl_cfg->buf_sz) {
261 : 0 : plt_err("Meta buffer size %u not sufficient to meet RQ first skip %u",
262 : : inl_cfg->buf_sz, rq->first_skip);
263 : 0 : return -EIO;
264 : : }
265 : :
266 : : /* Validate if we have enough VWQE buffers */
267 [ # # ]: 0 : if (rq->vwqe_ena) {
268 : 0 : actual = roc_npa_aura_op_limit_get(rq->vwqe_aura_handle);
269 : :
270 : 0 : type_mask = roc_npa_buf_type_mask(rq->vwqe_aura_handle);
271 [ # # ]: 0 : if (type_mask & BIT_ULL(ROC_NPA_BUF_TYPE_VWQE_IPSEC) &&
272 : : type_mask & BIT_ULL(ROC_NPA_BUF_TYPE_VWQE)) {
273 : : /* VWQE aura shared b/w Inline enabled and non Inline
274 : : * enabled ports needs enough buffers to store all the
275 : : * packet buffers, one per vwqe.
276 : : */
277 : : mask = (BIT_ULL(ROC_NPA_BUF_TYPE_PACKET_IPSEC) |
278 : : BIT_ULL(ROC_NPA_BUF_TYPE_PACKET));
279 : 0 : expected = roc_npa_buf_type_limit_get(mask);
280 : :
281 [ # # ]: 0 : if (actual < expected) {
282 : 0 : plt_err("VWQE aura shared b/w Inline inbound and non-Inline "
283 : : "ports needs vwqe bufs(%u) minimum of all pkt bufs (%u)",
284 : : actual, expected);
285 : 0 : return -EIO;
286 : : }
287 : : } else {
288 : : /* VWQE aura not shared b/w Inline and non Inline ports have relaxed
289 : : * requirement of match all the meta buffers.
290 : : */
291 : 0 : expected = inl_cfg->nb_bufs;
292 : :
293 [ # # ]: 0 : if (actual < expected) {
294 : 0 : plt_err("VWQE aura not shared b/w Inline inbound and non-Inline "
295 : : "ports needs vwqe bufs(%u) minimum of all meta bufs (%u)",
296 : : actual, expected);
297 : 0 : return -EIO;
298 : : }
299 : : }
300 : : }
301 : : return 0;
302 : : }
303 : :
304 : : static int
305 : 0 : nix_inl_local_meta_buffer_validate(struct roc_nix *roc_nix, struct roc_nix_rq *rq)
306 : : {
307 : : /* Validate if we have enough space for meta buffer */
308 [ # # # # ]: 0 : if (roc_nix->buf_sz && (rq->first_skip + NIX_INL_META_SIZE > roc_nix->buf_sz)) {
309 : 0 : plt_err("Meta buffer size %u not sufficient to meet RQ first skip %u",
310 : : roc_nix->buf_sz, rq->first_skip);
311 : 0 : return -EIO;
312 : : }
313 : :
314 : : /* TODO: Validate VWQE buffers */
315 : :
316 : : return 0;
317 : : }
318 : :
319 : : int
320 : 0 : roc_nix_inl_meta_aura_check(struct roc_nix *roc_nix, struct roc_nix_rq *rq)
321 : : {
322 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
323 : 0 : struct idev_cfg *idev = idev_get_cfg();
324 : : struct idev_nix_inl_cfg *inl_cfg;
325 : : bool is_local_metaaura;
326 : : bool aura_setup = false;
327 : : uint64_t *meta_aura;
328 : : int rc;
329 : :
330 [ # # # # ]: 0 : if (!idev || !meta_pool_cb)
331 : : return -EFAULT;
332 : :
333 : : inl_cfg = &idev->inl_cfg;
334 : :
335 : : /* Create meta aura if not present */
336 [ # # # # ]: 0 : if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena) {
337 : 0 : meta_aura = &inl_cfg->meta_aura;
338 : 0 : is_local_metaaura = false;
339 : : } else {
340 : 0 : meta_aura = &roc_nix->meta_aura_handle;
341 : : is_local_metaaura = true;
342 : : }
343 : :
344 [ # # ]: 0 : if (!(*meta_aura)) {
345 : 0 : rc = nix_inl_meta_aura_create(idev, roc_nix, rq->first_skip, meta_aura,
346 : : is_local_metaaura);
347 [ # # ]: 0 : if (rc)
348 : : return rc;
349 : :
350 : : aura_setup = true;
351 : : }
352 : :
353 [ # # ]: 0 : if (roc_nix->custom_meta_aura_ena) {
354 : : /* Create metaura for 1:N pool:aura */
355 [ # # ]: 0 : if (!custom_meta_pool_cb)
356 : : return -EFAULT;
357 : :
358 : 0 : meta_aura = &roc_nix->meta_aura_handle;
359 [ # # ]: 0 : if (!(*meta_aura)) {
360 : 0 : rc = nix_inl_custom_meta_aura_create(idev, roc_nix, rq->first_skip,
361 : : meta_aura);
362 [ # # ]: 0 : if (rc)
363 : : return rc;
364 : :
365 : : aura_setup = true;
366 : : }
367 : : }
368 : :
369 : : /* Update rq meta aura handle */
370 : 0 : rq->meta_aura_handle = *meta_aura;
371 : :
372 [ # # ]: 0 : if (roc_nix->local_meta_aura_ena) {
373 : 0 : rc = nix_inl_local_meta_buffer_validate(roc_nix, rq);
374 [ # # ]: 0 : if (rc)
375 : : return rc;
376 : :
377 : : /* Check for TC config on RQ 0 when local meta aura is used as
378 : : * inline meta aura creation is delayed.
379 : : */
380 [ # # # # : 0 : if (aura_setup && nix->rqs[0] && nix->rqs[0]->tc != ROC_NIX_PFC_CLASS_INVALID)
# # ]
381 : 0 : roc_nix_fc_npa_bp_cfg(roc_nix, roc_nix->meta_aura_handle,
382 : : true, false, nix->rqs[0]->tc, ROC_NIX_AURA_THRESH);
383 : : } else {
384 : 0 : rc = nix_inl_global_meta_buffer_validate(idev, rq);
385 [ # # ]: 0 : if (rc)
386 : 0 : return rc;
387 : : }
388 : :
389 : : return 0;
390 : : }
391 : :
392 : : static int
393 : 0 : nix_inl_inb_sa_tbl_setup(struct roc_nix *roc_nix)
394 : : {
395 : 0 : uint32_t ipsec_in_min_spi = roc_nix->ipsec_in_min_spi;
396 : 0 : uint32_t ipsec_in_max_spi = roc_nix->ipsec_in_max_spi;
397 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
398 : : struct roc_nix_ipsec_cfg cfg;
399 : : uint64_t max_sa, i;
400 : : size_t inb_sa_sz;
401 : : void *sa;
402 : : int rc;
403 : :
404 : 0 : max_sa = plt_align32pow2(ipsec_in_max_spi - ipsec_in_min_spi + 1);
405 : :
406 : : /* CN9K SA size is different */
407 : : if (roc_model_is_cn9k())
408 : : inb_sa_sz = ROC_NIX_INL_ON_IPSEC_INB_SA_SZ;
409 : : else
410 : : inb_sa_sz = ROC_NIX_INL_OT_IPSEC_INB_SA_SZ;
411 : :
412 : : /* Alloc contiguous memory for Inbound SA's */
413 : 0 : nix->inb_sa_sz = inb_sa_sz;
414 : 0 : nix->inb_spi_mask = max_sa - 1;
415 : 0 : nix->inb_sa_base = plt_zmalloc(inb_sa_sz * max_sa,
416 : : ROC_NIX_INL_SA_BASE_ALIGN);
417 [ # # ]: 0 : if (!nix->inb_sa_base) {
418 : 0 : plt_err("Failed to allocate memory for Inbound SA");
419 : 0 : return -ENOMEM;
420 : : }
421 [ # # ]: 0 : if (roc_model_is_cn10k()) {
422 [ # # ]: 0 : for (i = 0; i < max_sa; i++) {
423 : 0 : sa = ((uint8_t *)nix->inb_sa_base) + (i * inb_sa_sz);
424 : 0 : roc_ot_ipsec_inb_sa_init(sa, true);
425 : : }
426 : : }
427 : :
428 : : memset(&cfg, 0, sizeof(cfg));
429 : 0 : cfg.sa_size = inb_sa_sz;
430 : 0 : cfg.iova = (uintptr_t)nix->inb_sa_base;
431 : 0 : cfg.max_sa = max_sa;
432 : : cfg.tt = SSO_TT_ORDERED;
433 : :
434 : : /* Setup device specific inb SA table */
435 : 0 : rc = roc_nix_lf_inl_ipsec_cfg(roc_nix, &cfg, true);
436 [ # # ]: 0 : if (rc) {
437 : 0 : plt_err("Failed to setup NIX Inbound SA conf, rc=%d", rc);
438 : 0 : goto free_mem;
439 : : }
440 : :
441 : : return 0;
442 : : free_mem:
443 : 0 : plt_free(nix->inb_sa_base);
444 : 0 : nix->inb_sa_base = NULL;
445 : 0 : return rc;
446 : : }
447 : :
448 : : static int
449 : 0 : nix_inl_sa_tbl_release(struct roc_nix *roc_nix)
450 : : {
451 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
452 : : int rc;
453 : :
454 : 0 : rc = roc_nix_lf_inl_ipsec_cfg(roc_nix, NULL, false);
455 [ # # ]: 0 : if (rc) {
456 : 0 : plt_err("Failed to disable Inbound inline ipsec, rc=%d", rc);
457 : 0 : return rc;
458 : : }
459 : :
460 : 0 : plt_free(nix->inb_sa_base);
461 : 0 : nix->inb_sa_base = NULL;
462 : 0 : return 0;
463 : : }
464 : :
465 : : struct roc_cpt_lf *
466 : 0 : roc_nix_inl_outb_lf_base_get(struct roc_nix *roc_nix)
467 : : {
468 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
469 : :
470 : : /* NIX Inline config needs to be done */
471 [ # # # # ]: 0 : if (!nix->inl_outb_ena || !nix->cpt_lf_base)
472 : 0 : return NULL;
473 : :
474 : : return (struct roc_cpt_lf *)nix->cpt_lf_base;
475 : : }
476 : :
477 : : uintptr_t
478 : 0 : roc_nix_inl_outb_sa_base_get(struct roc_nix *roc_nix)
479 : : {
480 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
481 : :
482 : 0 : return (uintptr_t)nix->outb_sa_base;
483 : : }
484 : :
485 : : uintptr_t
486 : 0 : roc_nix_inl_inb_sa_base_get(struct roc_nix *roc_nix, bool inb_inl_dev)
487 : : {
488 : 0 : struct idev_cfg *idev = idev_get_cfg();
489 : : struct nix_inl_dev *inl_dev;
490 : : struct nix *nix = NULL;
491 : :
492 [ # # ]: 0 : if (idev == NULL)
493 : : return 0;
494 : :
495 [ # # ]: 0 : if (!inb_inl_dev && roc_nix == NULL)
496 : : return -EINVAL;
497 : :
498 [ # # ]: 0 : if (roc_nix) {
499 : : nix = roc_nix_to_nix_priv(roc_nix);
500 [ # # ]: 0 : if (!nix->inl_inb_ena)
501 : : return 0;
502 : : }
503 : :
504 [ # # ]: 0 : if (inb_inl_dev) {
505 : 0 : inl_dev = idev->nix_inl_dev;
506 : : /* Return inline dev sa base */
507 [ # # ]: 0 : if (inl_dev)
508 : 0 : return (uintptr_t)inl_dev->inb_sa_base;
509 : : return 0;
510 : : }
511 : :
512 : 0 : return (uintptr_t)nix->inb_sa_base;
513 : : }
514 : :
515 : : uint32_t
516 : 0 : roc_nix_inl_inb_spi_range(struct roc_nix *roc_nix, bool inb_inl_dev,
517 : : uint32_t *min_spi, uint32_t *max_spi)
518 : : {
519 : 0 : struct idev_cfg *idev = idev_get_cfg();
520 : : uint32_t min = 0, max = 0, mask = 0;
521 : : struct nix_inl_dev *inl_dev;
522 : : struct nix *nix = NULL;
523 : :
524 [ # # ]: 0 : if (idev == NULL)
525 : : return 0;
526 : :
527 [ # # ]: 0 : if (!inb_inl_dev && roc_nix == NULL)
528 : : return -EINVAL;
529 : :
530 : 0 : inl_dev = idev->nix_inl_dev;
531 [ # # ]: 0 : if (inb_inl_dev) {
532 [ # # ]: 0 : if (inl_dev == NULL)
533 : 0 : goto exit;
534 : 0 : min = inl_dev->ipsec_in_min_spi;
535 : 0 : max = inl_dev->ipsec_in_max_spi;
536 : 0 : mask = inl_dev->inb_spi_mask;
537 : : } else {
538 : : nix = roc_nix_to_nix_priv(roc_nix);
539 [ # # ]: 0 : if (!nix->inl_inb_ena)
540 : 0 : goto exit;
541 : 0 : min = roc_nix->ipsec_in_min_spi;
542 : 0 : max = roc_nix->ipsec_in_max_spi;
543 : 0 : mask = nix->inb_spi_mask;
544 : : }
545 : 0 : exit:
546 [ # # ]: 0 : if (min_spi)
547 : 0 : *min_spi = min;
548 [ # # ]: 0 : if (max_spi)
549 : 0 : *max_spi = max;
550 : : return mask;
551 : : }
552 : :
553 : : uint32_t
554 : 0 : roc_nix_inl_inb_sa_sz(struct roc_nix *roc_nix, bool inl_dev_sa)
555 : : {
556 : 0 : struct idev_cfg *idev = idev_get_cfg();
557 : : struct nix_inl_dev *inl_dev;
558 : : struct nix *nix;
559 : :
560 [ # # ]: 0 : if (idev == NULL)
561 : : return 0;
562 : :
563 [ # # ]: 0 : if (!inl_dev_sa && roc_nix == NULL)
564 : : return -EINVAL;
565 : :
566 [ # # ]: 0 : if (roc_nix) {
567 : : nix = roc_nix_to_nix_priv(roc_nix);
568 [ # # ]: 0 : if (!inl_dev_sa)
569 : 0 : return nix->inb_sa_sz;
570 : : }
571 : :
572 [ # # ]: 0 : if (inl_dev_sa) {
573 : 0 : inl_dev = idev->nix_inl_dev;
574 [ # # ]: 0 : if (inl_dev)
575 : 0 : return inl_dev->inb_sa_sz;
576 : : }
577 : :
578 : : return 0;
579 : : }
580 : :
581 : : uintptr_t
582 : 0 : roc_nix_inl_inb_sa_get(struct roc_nix *roc_nix, bool inb_inl_dev, uint32_t spi)
583 : : {
584 : 0 : uint32_t max_spi = 0, min_spi = 0, mask;
585 : : uintptr_t sa_base;
586 : : uint64_t sz;
587 : :
588 : 0 : sa_base = roc_nix_inl_inb_sa_base_get(roc_nix, inb_inl_dev);
589 : : /* Check if SA base exists */
590 [ # # ]: 0 : if (!sa_base)
591 : : return 0;
592 : :
593 : : /* Get SA size */
594 : 0 : sz = roc_nix_inl_inb_sa_sz(roc_nix, inb_inl_dev);
595 [ # # ]: 0 : if (!sz)
596 : : return 0;
597 : :
598 [ # # # # ]: 0 : if (roc_nix && roc_nix->custom_sa_action)
599 : 0 : return (sa_base + (spi * sz));
600 : :
601 : : /* Check if SPI is in range */
602 : 0 : mask = roc_nix_inl_inb_spi_range(roc_nix, inb_inl_dev, &min_spi,
603 : : &max_spi);
604 [ # # # # ]: 0 : if (spi > max_spi || spi < min_spi)
605 : 0 : plt_nix_dbg("Inbound SA SPI %u not in range (%u..%u)", spi,
606 : : min_spi, max_spi);
607 : :
608 : : /* Basic logic of SPI->SA for now */
609 : 0 : return (sa_base + ((spi & mask) * sz));
610 : : }
611 : :
612 : : int
613 : 0 : roc_nix_reassembly_configure(uint32_t max_wait_time, uint16_t max_frags)
614 : : {
615 : 0 : struct idev_cfg *idev = idev_get_cfg();
616 : : struct roc_cpt *roc_cpt;
617 : : struct roc_cpt_rxc_time_cfg cfg;
618 : :
619 [ # # ]: 0 : if (!idev)
620 : : return -EFAULT;
621 : :
622 : : PLT_SET_USED(max_frags);
623 : : if (idev == NULL)
624 : : return -ENOTSUP;
625 : 0 : roc_cpt = idev->cpt;
626 [ # # ]: 0 : if (!roc_cpt) {
627 : 0 : plt_err("Cannot support inline inbound, cryptodev not probed");
628 : 0 : return -ENOTSUP;
629 : : }
630 : :
631 : 0 : cfg.step = (max_wait_time * 1000 / ROC_NIX_INL_REAS_ACTIVE_LIMIT);
632 : 0 : cfg.zombie_limit = ROC_NIX_INL_REAS_ZOMBIE_LIMIT;
633 : 0 : cfg.zombie_thres = ROC_NIX_INL_REAS_ZOMBIE_THRESHOLD;
634 : 0 : cfg.active_limit = ROC_NIX_INL_REAS_ACTIVE_LIMIT;
635 : 0 : cfg.active_thres = ROC_NIX_INL_REAS_ACTIVE_THRESHOLD;
636 : :
637 : 0 : return roc_cpt_rxc_time_cfg(roc_cpt, &cfg);
638 : : }
639 : :
640 : : static int
641 : 0 : nix_inl_rq_mask_cfg(struct roc_nix *roc_nix, bool enable)
642 : : {
643 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
644 : : struct nix_rq_cpt_field_mask_cfg_req *msk_req;
645 : 0 : struct idev_cfg *idev = idev_get_cfg();
646 : 0 : struct mbox *mbox = mbox_get((&nix->dev)->mbox);
647 : : struct idev_nix_inl_cfg *inl_cfg;
648 : : uint64_t aura_handle;
649 : : int rc = -ENOSPC;
650 : : uint32_t buf_sz;
651 : : int i;
652 : :
653 [ # # ]: 0 : if (!idev)
654 : 0 : goto exit;
655 : :
656 : : inl_cfg = &idev->inl_cfg;
657 : 0 : msk_req = mbox_alloc_msg_nix_lf_inline_rq_cfg(mbox);
658 [ # # ]: 0 : if (msk_req == NULL)
659 : 0 : goto exit;
660 : :
661 [ # # ]: 0 : for (i = 0; i < RQ_CTX_MASK_MAX; i++)
662 : 0 : msk_req->rq_ctx_word_mask[i] = 0xFFFFFFFFFFFFFFFF;
663 : :
664 : 0 : msk_req->rq_set.len_ol3_dis = 1;
665 : 0 : msk_req->rq_set.len_ol4_dis = 1;
666 : 0 : msk_req->rq_set.len_il3_dis = 1;
667 : :
668 : 0 : msk_req->rq_set.len_il4_dis = 1;
669 : 0 : msk_req->rq_set.csum_ol4_dis = 1;
670 : 0 : msk_req->rq_set.csum_il4_dis = 1;
671 : :
672 : 0 : msk_req->rq_set.lenerr_dis = 1;
673 : 0 : msk_req->rq_set.port_ol4_dis = 1;
674 : 0 : msk_req->rq_set.port_il4_dis = 1;
675 : :
676 : 0 : msk_req->rq_set.lpb_drop_ena = 0;
677 : 0 : msk_req->rq_set.spb_drop_ena = 0;
678 : 0 : msk_req->rq_set.xqe_drop_ena = 0;
679 : 0 : msk_req->rq_set.spb_ena = 1;
680 : :
681 : 0 : msk_req->rq_mask.len_ol3_dis = 0;
682 : 0 : msk_req->rq_mask.len_ol4_dis = 0;
683 : 0 : msk_req->rq_mask.len_il3_dis = 0;
684 : :
685 : 0 : msk_req->rq_mask.len_il4_dis = 0;
686 : 0 : msk_req->rq_mask.csum_ol4_dis = 0;
687 : 0 : msk_req->rq_mask.csum_il4_dis = 0;
688 : :
689 : 0 : msk_req->rq_mask.lenerr_dis = 0;
690 : 0 : msk_req->rq_mask.port_ol4_dis = 0;
691 : 0 : msk_req->rq_mask.port_il4_dis = 0;
692 : :
693 : 0 : msk_req->rq_mask.lpb_drop_ena = 0;
694 : 0 : msk_req->rq_mask.spb_drop_ena = 0;
695 : 0 : msk_req->rq_mask.xqe_drop_ena = 0;
696 : 0 : msk_req->rq_mask.spb_ena = 0;
697 : :
698 [ # # ]: 0 : if (roc_nix->local_meta_aura_ena) {
699 : 0 : aura_handle = roc_nix->meta_aura_handle;
700 : 0 : buf_sz = roc_nix->buf_sz;
701 [ # # ]: 0 : if (!aura_handle && enable) {
702 : 0 : plt_err("NULL meta aura handle");
703 : 0 : goto exit;
704 : : }
705 : : } else {
706 : 0 : aura_handle = roc_npa_zero_aura_handle();
707 : 0 : buf_sz = inl_cfg->buf_sz;
708 : : }
709 : :
710 : 0 : msk_req->ipsec_cfg1.spb_cpt_aura = roc_npa_aura_handle_to_aura(aura_handle);
711 : 0 : msk_req->ipsec_cfg1.rq_mask_enable = enable;
712 : 0 : msk_req->ipsec_cfg1.spb_cpt_sizem1 = (buf_sz >> 7) - 1;
713 : 0 : msk_req->ipsec_cfg1.spb_cpt_enable = enable;
714 : :
715 : 0 : rc = mbox_process(mbox);
716 : 0 : exit:
717 : : mbox_put(mbox);
718 : 0 : return rc;
719 : : }
720 : :
721 : : static void
722 : 0 : nix_inl_eng_caps_get(struct nix *nix)
723 : : {
724 : 0 : struct roc_cpt_lf *lf = nix->cpt_lf_base;
725 : 0 : uintptr_t lmt_base = lf->lmt_base;
726 : : union cpt_res_s res, *hw_res;
727 : : struct cpt_inst_s inst;
728 : : uint64_t *rptr;
729 : :
730 : 0 : hw_res = plt_zmalloc(sizeof(*hw_res), ROC_CPT_RES_ALIGN);
731 [ # # ]: 0 : if (hw_res == NULL) {
732 : 0 : plt_err("Couldn't allocate memory for result address");
733 : 0 : return;
734 : : }
735 : :
736 : 0 : rptr = plt_zmalloc(ROC_ALIGN, 0);
737 [ # # ]: 0 : if (rptr == NULL) {
738 : 0 : plt_err("Couldn't allocate memory for rptr");
739 : 0 : plt_free(hw_res);
740 : 0 : return;
741 : : }
742 : :
743 : : /* Fill CPT_INST_S for LOAD_FVC/HW_CRYPTO_SUPPORT microcode op */
744 : : memset(&inst, 0, sizeof(struct cpt_inst_s));
745 : 0 : inst.res_addr = (uint64_t)hw_res;
746 : 0 : inst.rptr = (uint64_t)rptr;
747 : 0 : inst.w4.s.opcode_major = ROC_LOADFVC_MAJOR_OP;
748 : 0 : inst.w4.s.opcode_minor = ROC_LOADFVC_MINOR_OP;
749 : : inst.w7.s.egrp = ROC_CPT_DFLT_ENG_GRP_SE;
750 : :
751 : : /* Use 1 min timeout for the poll */
752 [ # # ]: 0 : const uint64_t timeout = plt_tsc_cycles() + 60 * plt_tsc_hz();
753 : :
754 [ # # ]: 0 : if (roc_model_is_cn9k()) {
755 : : uint64_t lmt_status;
756 : :
757 : 0 : hw_res->cn9k.compcode = CPT_COMP_NOT_DONE;
758 : 0 : plt_io_wmb();
759 : :
760 : : do {
761 : : roc_lmt_mov_seg((void *)lmt_base, &inst, 4);
762 : : lmt_status = roc_lmt_submit_ldeor(lf->io_addr);
763 : : } while (lmt_status != 0);
764 : :
765 : : /* Wait until CPT instruction completes */
766 : : do {
767 : 0 : res.u64[0] = __atomic_load_n(&hw_res->u64[0], __ATOMIC_RELAXED);
768 [ # # ]: 0 : if (unlikely(plt_tsc_cycles() > timeout))
769 : : break;
770 [ # # ]: 0 : } while (res.cn9k.compcode == CPT_COMP_NOT_DONE);
771 : :
772 [ # # ]: 0 : if (res.cn9k.compcode != CPT_COMP_GOOD) {
773 : 0 : plt_err("LOAD FVC operation timed out");
774 : 0 : return;
775 : : }
776 : : } else {
777 : : uint64_t lmt_arg, io_addr;
778 : : uint16_t lmt_id;
779 : :
780 : 0 : hw_res->cn10k.compcode = CPT_COMP_NOT_DONE;
781 : :
782 : : /* Use this reserved LMT line as no one else is using it */
783 : 0 : lmt_id = roc_plt_control_lmt_id_get();
784 : 0 : lmt_base += ((uint64_t)lmt_id << ROC_LMT_LINE_SIZE_LOG2);
785 : :
786 : 0 : memcpy((void *)lmt_base, &inst, sizeof(inst));
787 : :
788 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (uint64_t)lmt_id;
789 : : io_addr = lf->io_addr | ROC_CN10K_CPT_INST_DW_M1 << 4;
790 : :
791 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
792 : 0 : plt_io_wmb();
793 : :
794 : : /* Wait until CPT instruction completes */
795 : : do {
796 : 0 : res.u64[0] = __atomic_load_n(&hw_res->u64[0], __ATOMIC_RELAXED);
797 [ # # ]: 0 : if (unlikely(plt_tsc_cycles() > timeout))
798 : : break;
799 [ # # ]: 0 : } while (res.cn10k.compcode == CPT_COMP_NOT_DONE);
800 : :
801 [ # # ]: 0 : if (res.cn10k.compcode != CPT_COMP_GOOD || res.cn10k.uc_compcode) {
802 : 0 : plt_err("LOAD FVC operation timed out");
803 : 0 : goto exit;
804 : : }
805 : : }
806 : :
807 [ # # ]: 0 : nix->cpt_eng_caps = plt_be_to_cpu_64(*rptr);
808 : 0 : exit:
809 : 0 : plt_free(rptr);
810 : 0 : plt_free(hw_res);
811 : : }
812 : :
813 : : int
814 : 0 : roc_nix_inl_inb_init(struct roc_nix *roc_nix)
815 : : {
816 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
817 : : struct roc_cpt_inline_ipsec_inb_cfg cfg;
818 : 0 : struct idev_cfg *idev = idev_get_cfg();
819 : : struct nix_inl_dev *inl_dev;
820 : : uint16_t bpids[ROC_NIX_MAX_BPID_CNT];
821 : : struct roc_cpt *roc_cpt;
822 : : int rc;
823 : :
824 [ # # ]: 0 : if (idev == NULL)
825 : : return -ENOTSUP;
826 : :
827 : : /* Unless we have another mechanism to trigger
828 : : * onetime Inline config in CPTPF, we cannot
829 : : * support without CPT being probed.
830 : : */
831 : 0 : roc_cpt = idev->cpt;
832 [ # # ]: 0 : if (!roc_cpt) {
833 : 0 : plt_err("Cannot support inline inbound, cryptodev not probed");
834 : 0 : return -ENOTSUP;
835 : : }
836 : :
837 [ # # ]: 0 : if (roc_model_is_cn9k()) {
838 : 0 : cfg.param1 = (ROC_ONF_IPSEC_INB_MAX_L2_SZ >> 3) & 0xf;
839 : 0 : cfg.param2 = ROC_IE_ON_INB_IKEV2_SINGLE_SA_SUPPORT;
840 : 0 : cfg.opcode =
841 : : ((ROC_IE_ON_INB_MAX_CTX_LEN << 8) |
842 : : (ROC_IE_ON_MAJOR_OP_PROCESS_INBOUND_IPSEC | (1 << 6)));
843 : : } else {
844 : : union roc_ot_ipsec_inb_param1 u;
845 : :
846 : : u.u16 = 0;
847 : : u.s.esp_trailer_disable = 1;
848 : 0 : cfg.param1 = u.u16;
849 : 0 : cfg.param2 = 0;
850 : 0 : cfg.opcode = (ROC_IE_OT_MAJOR_OP_PROCESS_INBOUND_IPSEC | (1 << 6));
851 : 0 : rc = roc_nix_bpids_alloc(roc_nix, ROC_NIX_INTF_TYPE_CPT_NIX, 1, bpids);
852 [ # # ]: 0 : if (rc > 0) {
853 : 0 : nix->cpt_nixbpid = bpids[0];
854 : 0 : cfg.bpid = nix->cpt_nixbpid;
855 : : }
856 : :
857 [ # # ]: 0 : if (roc_errata_cpt_has_ctx_fetch_issue()) {
858 : 0 : cfg.ctx_ilen_valid = true;
859 : 0 : cfg.ctx_ilen = (ROC_NIX_INL_OT_IPSEC_INB_HW_SZ / 128) - 1;
860 : : }
861 : : }
862 : :
863 : : /* Do onetime Inbound Inline config in CPTPF */
864 : 0 : rc = roc_cpt_inline_ipsec_inb_cfg(roc_cpt, &cfg);
865 [ # # ]: 0 : if (rc && rc != -EEXIST) {
866 : 0 : plt_err("Failed to setup inbound lf, rc=%d", rc);
867 : 0 : return rc;
868 : : }
869 : 0 : nix->cpt_eng_caps = roc_cpt->hw_caps[CPT_ENG_TYPE_SE].u;
870 : :
871 : : /* Setup Inbound SA table */
872 : 0 : rc = nix_inl_inb_sa_tbl_setup(roc_nix);
873 [ # # ]: 0 : if (rc)
874 : : return rc;
875 : :
876 : 0 : inl_dev = idev->nix_inl_dev;
877 : :
878 [ # # # # ]: 0 : roc_nix->custom_meta_aura_ena = (roc_nix->local_meta_aura_ena &&
879 [ # # # # ]: 0 : (inl_dev->is_multi_channel || roc_nix->custom_sa_action));
880 [ # # # # ]: 0 : if (!roc_model_is_cn9k() && !roc_errata_nix_no_meta_aura()) {
881 : 0 : nix->need_meta_aura = true;
882 [ # # # # ]: 0 : if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
883 : 0 : idev->inl_cfg.refs++;
884 : : }
885 : :
886 : 0 : nix->inl_inb_ena = true;
887 : 0 : return 0;
888 : : }
889 : :
890 : : int
891 : 0 : roc_nix_inl_inb_fini(struct roc_nix *roc_nix)
892 : : {
893 : 0 : struct idev_cfg *idev = idev_get_cfg();
894 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
895 : : int rc;
896 : :
897 [ # # ]: 0 : if (!nix->inl_inb_ena)
898 : : return 0;
899 : :
900 [ # # ]: 0 : if (!idev)
901 : : return -EFAULT;
902 : :
903 : 0 : nix->inl_inb_ena = false;
904 : :
905 [ # # ]: 0 : if (nix->need_meta_aura) {
906 : 0 : nix->need_meta_aura = false;
907 [ # # # # ]: 0 : if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
908 : 0 : idev->inl_cfg.refs--;
909 : :
910 [ # # ]: 0 : if (roc_nix->custom_meta_aura_ena)
911 : 0 : nix_inl_custom_meta_aura_destroy(roc_nix);
912 : :
913 [ # # ]: 0 : if (!idev->inl_cfg.refs)
914 : 0 : nix_inl_meta_aura_destroy(roc_nix);
915 : : }
916 : :
917 [ # # ]: 0 : if (roc_feature_nix_has_inl_rq_mask()) {
918 : 0 : rc = nix_inl_rq_mask_cfg(roc_nix, false);
919 [ # # ]: 0 : if (rc) {
920 : 0 : plt_err("Failed to get rq mask rc=%d", rc);
921 : 0 : return rc;
922 : : }
923 : : }
924 : :
925 : : /* Flush Inbound CTX cache entries */
926 : 0 : roc_nix_cpt_ctx_cache_sync(roc_nix);
927 : :
928 : : /* Disable Inbound SA */
929 : 0 : return nix_inl_sa_tbl_release(roc_nix);
930 : : }
931 : :
932 : : int
933 : 0 : roc_nix_inl_outb_init(struct roc_nix *roc_nix)
934 : : {
935 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
936 : 0 : struct idev_cfg *idev = idev_get_cfg();
937 : : struct roc_cpt_lf *lf_base, *lf;
938 : 0 : struct dev *dev = &nix->dev;
939 : : struct msix_offset_rsp *rsp;
940 : : struct nix_inl_dev *inl_dev;
941 : : bool ctx_ilen_valid = false;
942 : : size_t sa_sz, ring_sz;
943 : : uint8_t ctx_ilen = 0;
944 : : uint16_t sso_pffunc;
945 : : uint8_t eng_grpmask;
946 : : uint64_t blkaddr, i;
947 : : uint64_t *ring_base;
948 : : uint16_t nb_lf;
949 : : void *sa_base;
950 : : int j, rc;
951 : : void *sa;
952 : :
953 [ # # ]: 0 : if (idev == NULL)
954 : : return -ENOTSUP;
955 : :
956 : 0 : nb_lf = roc_nix->outb_nb_crypto_qs;
957 [ # # ]: 0 : blkaddr = nix->is_nix1 ? RVU_BLOCK_ADDR_CPT1 : RVU_BLOCK_ADDR_CPT0;
958 : :
959 : : /* Retrieve inline device if present */
960 : 0 : inl_dev = idev->nix_inl_dev;
961 [ # # ]: 0 : sso_pffunc = inl_dev ? inl_dev->dev.pf_func : idev_sso_pffunc_get();
962 : : /* Use sso_pffunc if explicitly requested */
963 [ # # ]: 0 : if (roc_nix->ipsec_out_sso_pffunc)
964 : 0 : sso_pffunc = idev_sso_pffunc_get();
965 : :
966 [ # # ]: 0 : if (!sso_pffunc) {
967 : 0 : plt_err("Failed to setup inline outb, need either "
968 : : "inline device or sso device");
969 : 0 : return -ENOTSUP;
970 : : }
971 : :
972 : : /* Attach CPT LF for outbound */
973 : 0 : rc = cpt_lfs_attach(dev, blkaddr, true, nb_lf);
974 [ # # ]: 0 : if (rc) {
975 : 0 : plt_err("Failed to attach CPT LF for inline outb, rc=%d", rc);
976 : 0 : return rc;
977 : : }
978 : :
979 [ # # # # ]: 0 : if (!roc_model_is_cn9k() && roc_errata_cpt_has_ctx_fetch_issue()) {
980 : : ctx_ilen = (ROC_NIX_INL_OT_IPSEC_OUTB_HW_SZ / 128) - 1;
981 : : ctx_ilen_valid = true;
982 : : }
983 : :
984 : : /* Alloc CPT LF */
985 : : eng_grpmask = (1ULL << ROC_CPT_DFLT_ENG_GRP_SE |
986 : : 1ULL << ROC_CPT_DFLT_ENG_GRP_SE_IE |
987 : : 1ULL << ROC_CPT_DFLT_ENG_GRP_AE);
988 : 0 : rc = cpt_lfs_alloc(dev, eng_grpmask, blkaddr,
989 : 0 : !roc_nix->ipsec_out_sso_pffunc, ctx_ilen_valid, ctx_ilen);
990 [ # # ]: 0 : if (rc) {
991 : 0 : plt_err("Failed to alloc CPT LF resources, rc=%d", rc);
992 : 0 : goto lf_detach;
993 : : }
994 : :
995 : : /* Get msix offsets */
996 : 0 : rc = cpt_get_msix_offset(dev, &rsp);
997 [ # # ]: 0 : if (rc) {
998 : 0 : plt_err("Failed to get CPT LF msix offset, rc=%d", rc);
999 : 0 : goto lf_free;
1000 : : }
1001 : :
1002 : 0 : mbox_memcpy(nix->cpt_msixoff,
1003 [ # # ]: 0 : nix->is_nix1 ? rsp->cpt1_lf_msixoff : rsp->cptlf_msixoff,
1004 : : sizeof(nix->cpt_msixoff));
1005 : :
1006 : : /* Alloc required num of cpt lfs */
1007 : 0 : lf_base = plt_zmalloc(nb_lf * sizeof(struct roc_cpt_lf), 0);
1008 [ # # ]: 0 : if (!lf_base) {
1009 : 0 : plt_err("Failed to alloc cpt lf memory");
1010 : : rc = -ENOMEM;
1011 : 0 : goto lf_free;
1012 : : }
1013 : :
1014 : : /* Initialize CPT LF's */
1015 [ # # ]: 0 : for (i = 0; i < nb_lf; i++) {
1016 : 0 : lf = &lf_base[i];
1017 : :
1018 : 0 : lf->lf_id = i;
1019 : 0 : lf->nb_desc = roc_nix->outb_nb_desc;
1020 : 0 : lf->dev = &nix->dev;
1021 : 0 : lf->msixoff = nix->cpt_msixoff[i];
1022 : 0 : lf->pci_dev = nix->pci_dev;
1023 : :
1024 : : /* Setup CPT LF instruction queue */
1025 : 0 : rc = cpt_lf_init(lf);
1026 [ # # ]: 0 : if (rc) {
1027 : 0 : plt_err("Failed to initialize CPT LF, rc=%d", rc);
1028 : 0 : goto lf_fini;
1029 : : }
1030 : :
1031 : : /* Associate this CPT LF with NIX PFFUNC */
1032 : 0 : rc = cpt_lf_outb_cfg(dev, sso_pffunc, nix->dev.pf_func, i,
1033 : : true);
1034 [ # # ]: 0 : if (rc) {
1035 : 0 : plt_err("Failed to setup CPT LF->(NIX,SSO) link, rc=%d",
1036 : : rc);
1037 : 0 : goto lf_fini;
1038 : : }
1039 : :
1040 : : /* Enable IQ */
1041 : 0 : roc_cpt_iq_enable(lf);
1042 : : }
1043 : :
1044 [ # # ]: 0 : if (!roc_nix->ipsec_out_max_sa)
1045 : 0 : goto skip_sa_alloc;
1046 : :
1047 : : /* CN9K SA size is different */
1048 : : if (roc_model_is_cn9k())
1049 : : sa_sz = ROC_NIX_INL_ON_IPSEC_OUTB_SA_SZ;
1050 : : else
1051 : : sa_sz = ROC_NIX_INL_OT_IPSEC_OUTB_SA_SZ;
1052 : : /* Alloc contiguous memory of outbound SA */
1053 : 0 : sa_base = plt_zmalloc(sa_sz * roc_nix->ipsec_out_max_sa,
1054 : : ROC_NIX_INL_SA_BASE_ALIGN);
1055 [ # # ]: 0 : if (!sa_base) {
1056 : 0 : plt_err("Outbound SA base alloc failed");
1057 : 0 : goto lf_fini;
1058 : : }
1059 [ # # ]: 0 : if (roc_model_is_cn10k()) {
1060 [ # # ]: 0 : for (i = 0; i < roc_nix->ipsec_out_max_sa; i++) {
1061 : 0 : sa = ((uint8_t *)sa_base) + (i * sa_sz);
1062 : 0 : roc_ot_ipsec_outb_sa_init(sa);
1063 : : }
1064 : : }
1065 : 0 : nix->outb_sa_base = sa_base;
1066 : 0 : nix->outb_sa_sz = sa_sz;
1067 : :
1068 : 0 : skip_sa_alloc:
1069 : :
1070 : 0 : nix->cpt_lf_base = lf_base;
1071 : 0 : nix->nb_cpt_lf = nb_lf;
1072 : 0 : nix->outb_err_sso_pffunc = sso_pffunc;
1073 : 0 : nix->inl_outb_ena = true;
1074 : 0 : nix->outb_se_ring_cnt =
1075 : 0 : roc_nix->ipsec_out_max_sa / ROC_IPSEC_ERR_RING_MAX_ENTRY + 1;
1076 : 0 : nix->outb_se_ring_base =
1077 : 0 : roc_nix->port_id * ROC_NIX_SOFT_EXP_PER_PORT_MAX_RINGS;
1078 : :
1079 [ # # # # ]: 0 : if (inl_dev == NULL || !inl_dev->set_soft_exp_poll) {
1080 : 0 : nix->outb_se_ring_cnt = 0;
1081 : 0 : return 0;
1082 : : }
1083 : :
1084 : : /* Allocate memory to be used as a ring buffer to poll for
1085 : : * soft expiry event from ucode
1086 : : */
1087 : : ring_sz = (ROC_IPSEC_ERR_RING_MAX_ENTRY + 1) * sizeof(uint64_t);
1088 : 0 : ring_base = inl_dev->sa_soft_exp_ring;
1089 [ # # ]: 0 : for (i = 0; i < nix->outb_se_ring_cnt; i++) {
1090 : 0 : ring_base[nix->outb_se_ring_base + i] =
1091 : 0 : PLT_U64_CAST(plt_zmalloc(ring_sz, 0));
1092 [ # # ]: 0 : if (!ring_base[nix->outb_se_ring_base + i]) {
1093 : 0 : plt_err("Couldn't allocate memory for soft exp ring");
1094 [ # # ]: 0 : while (i--)
1095 : 0 : plt_free(PLT_PTR_CAST(
1096 : : ring_base[nix->outb_se_ring_base + i]));
1097 : : rc = -ENOMEM;
1098 : 0 : goto lf_fini;
1099 : : }
1100 : : }
1101 : :
1102 : : /* Fetch engine capabilities */
1103 : 0 : nix_inl_eng_caps_get(nix);
1104 : 0 : return 0;
1105 : :
1106 : 0 : lf_fini:
1107 [ # # ]: 0 : for (j = i - 1; j >= 0; j--)
1108 : 0 : cpt_lf_fini(&lf_base[j]);
1109 : 0 : plt_free(lf_base);
1110 : 0 : lf_free:
1111 : 0 : rc |= cpt_lfs_free(dev);
1112 : 0 : lf_detach:
1113 : 0 : rc |= cpt_lfs_detach(dev);
1114 : 0 : return rc;
1115 : : }
1116 : :
1117 : : int
1118 : 0 : roc_nix_inl_outb_fini(struct roc_nix *roc_nix)
1119 : : {
1120 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1121 : 0 : struct roc_cpt_lf *lf_base = nix->cpt_lf_base;
1122 : 0 : struct idev_cfg *idev = idev_get_cfg();
1123 : 0 : struct dev *dev = &nix->dev;
1124 : : struct nix_inl_dev *inl_dev;
1125 : : uint64_t *ring_base;
1126 : : int i, rc, ret = 0;
1127 : :
1128 [ # # ]: 0 : if (!nix->inl_outb_ena)
1129 : : return 0;
1130 : :
1131 : 0 : nix->inl_outb_ena = false;
1132 : :
1133 : : /* Cleanup CPT LF instruction queue */
1134 [ # # ]: 0 : for (i = 0; i < nix->nb_cpt_lf; i++)
1135 : 0 : cpt_lf_fini(&lf_base[i]);
1136 : :
1137 : : /* Free LF resources */
1138 : 0 : rc = cpt_lfs_free(dev);
1139 [ # # ]: 0 : if (rc)
1140 : 0 : plt_err("Failed to free CPT LF resources, rc=%d", rc);
1141 : : ret |= rc;
1142 : :
1143 : : /* Detach LF */
1144 : 0 : rc = cpt_lfs_detach(dev);
1145 [ # # ]: 0 : if (rc)
1146 : 0 : plt_err("Failed to detach CPT LF, rc=%d", rc);
1147 : :
1148 : : /* Free LF memory */
1149 : 0 : plt_free(lf_base);
1150 : 0 : nix->cpt_lf_base = NULL;
1151 : 0 : nix->nb_cpt_lf = 0;
1152 : :
1153 : : /* Free outbound SA base */
1154 : 0 : plt_free(nix->outb_sa_base);
1155 : 0 : nix->outb_sa_base = NULL;
1156 : :
1157 [ # # # # : 0 : if (idev && idev->nix_inl_dev && nix->outb_se_ring_cnt) {
# # ]
1158 : : inl_dev = idev->nix_inl_dev;
1159 : 0 : ring_base = inl_dev->sa_soft_exp_ring;
1160 : 0 : ring_base += nix->outb_se_ring_base;
1161 : :
1162 [ # # ]: 0 : for (i = 0; i < nix->outb_se_ring_cnt; i++) {
1163 [ # # ]: 0 : if (ring_base[i])
1164 : 0 : plt_free(PLT_PTR_CAST(ring_base[i]));
1165 : : }
1166 : : }
1167 : :
1168 : 0 : ret |= rc;
1169 : 0 : return ret;
1170 : : }
1171 : :
1172 : : bool
1173 : 0 : roc_nix_inl_dev_is_probed(void)
1174 : : {
1175 : 0 : struct idev_cfg *idev = idev_get_cfg();
1176 : :
1177 [ # # ]: 0 : if (idev == NULL)
1178 : : return 0;
1179 : :
1180 : 0 : return !!idev->nix_inl_dev;
1181 : : }
1182 : :
1183 : : bool
1184 : 0 : roc_nix_inl_inb_is_enabled(struct roc_nix *roc_nix)
1185 : : {
1186 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1187 : :
1188 : 0 : return nix->inl_inb_ena;
1189 : : }
1190 : :
1191 : : bool
1192 : 0 : roc_nix_inl_outb_is_enabled(struct roc_nix *roc_nix)
1193 : : {
1194 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1195 : :
1196 : 0 : return nix->inl_outb_ena;
1197 : : }
1198 : :
1199 : : int
1200 : 0 : roc_nix_inl_dev_rq_get(struct roc_nix_rq *rq, bool enable)
1201 : : {
1202 : 0 : struct nix *nix = roc_nix_to_nix_priv(rq->roc_nix);
1203 : 0 : struct idev_cfg *idev = idev_get_cfg();
1204 : 0 : int port_id = rq->roc_nix->port_id;
1205 : : struct nix_inl_dev *inl_dev;
1206 : : struct roc_nix_rq *inl_rq;
1207 : : uint16_t inl_rq_id;
1208 : : struct mbox *mbox;
1209 : : struct dev *dev;
1210 : : int rc;
1211 : :
1212 [ # # ]: 0 : if (idev == NULL)
1213 : : return 0;
1214 : :
1215 : : /* Update meta aura handle in RQ */
1216 [ # # ]: 0 : if (nix->need_meta_aura)
1217 : 0 : rq->meta_aura_handle = roc_npa_zero_aura_handle();
1218 : :
1219 : 0 : inl_dev = idev->nix_inl_dev;
1220 : : /* Nothing to do if no inline device */
1221 [ # # ]: 0 : if (!inl_dev)
1222 : : return 0;
1223 : :
1224 : : /* Check if this RQ is already holding reference */
1225 [ # # ]: 0 : if (rq->inl_dev_refs)
1226 : : return 0;
1227 : :
1228 [ # # ]: 0 : inl_rq_id = inl_dev->nb_rqs > 1 ? port_id : 0;
1229 : 0 : dev = &inl_dev->dev;
1230 : 0 : inl_rq = &inl_dev->rqs[inl_rq_id];
1231 : :
1232 : : /* Just take reference if already inited */
1233 [ # # ]: 0 : if (inl_rq->inl_dev_refs) {
1234 : 0 : inl_rq->inl_dev_refs++;
1235 : 0 : rq->inl_dev_refs = 1;
1236 : 0 : return 0;
1237 : : }
1238 : : memset(inl_rq, 0, sizeof(struct roc_nix_rq));
1239 : :
1240 : : /* Take RQ pool attributes from the first ethdev RQ */
1241 : 0 : inl_rq->qid = inl_rq_id;
1242 : 0 : inl_rq->aura_handle = rq->aura_handle;
1243 : 0 : inl_rq->first_skip = rq->first_skip;
1244 : 0 : inl_rq->later_skip = rq->later_skip;
1245 : 0 : inl_rq->lpb_size = rq->lpb_size;
1246 : 0 : inl_rq->spb_ena = rq->spb_ena;
1247 : 0 : inl_rq->spb_aura_handle = rq->spb_aura_handle;
1248 [ # # ]: 0 : inl_rq->spb_size = rq->spb_size;
1249 : :
1250 [ # # ]: 0 : if (roc_errata_nix_no_meta_aura()) {
1251 : : uint64_t aura_limit =
1252 : : roc_npa_aura_op_limit_get(inl_rq->aura_handle);
1253 : : uint64_t aura_shift = plt_log2_u32(aura_limit);
1254 : : uint64_t aura_drop, drop_pc;
1255 : :
1256 : 0 : inl_rq->lpb_drop_ena = true;
1257 : :
1258 : : if (aura_shift < 8)
1259 : : aura_shift = 0;
1260 : : else
1261 : : aura_shift = aura_shift - 8;
1262 : :
1263 : : /* Set first pass RQ to drop after part of buffers are in
1264 : : * use to avoid metabuf alloc failure. This is needed as long
1265 : : * as we cannot use different aura.
1266 : : */
1267 : : drop_pc = inl_dev->lpb_drop_pc;
1268 : : aura_drop = ((aura_limit * drop_pc) / 100) >> aura_shift;
1269 : 0 : roc_npa_aura_drop_set(inl_rq->aura_handle, aura_drop, true);
1270 : : }
1271 : :
1272 [ # # # # ]: 0 : if (roc_errata_nix_no_meta_aura() && inl_rq->spb_ena) {
1273 : : uint64_t aura_limit =
1274 : 0 : roc_npa_aura_op_limit_get(inl_rq->spb_aura_handle);
1275 : : uint64_t aura_shift = plt_log2_u32(aura_limit);
1276 : : uint64_t aura_drop, drop_pc;
1277 : :
1278 : 0 : inl_rq->spb_drop_ena = true;
1279 : :
1280 : : if (aura_shift < 8)
1281 : : aura_shift = 0;
1282 : : else
1283 : : aura_shift = aura_shift - 8;
1284 : :
1285 : : /* Set first pass RQ to drop after part of buffers are in
1286 : : * use to avoid metabuf alloc failure. This is needed as long
1287 : : * as we cannot use different aura.
1288 : : */
1289 : : drop_pc = inl_dev->spb_drop_pc;
1290 : : aura_drop = ((aura_limit * drop_pc) / 100) >> aura_shift;
1291 : 0 : roc_npa_aura_drop_set(inl_rq->spb_aura_handle, aura_drop, true);
1292 : : }
1293 : :
1294 : : /* Enable IPSec */
1295 : 0 : inl_rq->ipsech_ena = true;
1296 : :
1297 : 0 : inl_rq->flow_tag_width = 20;
1298 : : /* Special tag mask */
1299 : 0 : inl_rq->tag_mask = rq->tag_mask;
1300 : 0 : inl_rq->tt = SSO_TT_ORDERED;
1301 : 0 : inl_rq->hwgrp = 0;
1302 : 0 : inl_rq->wqe_skip = inl_dev->wqe_skip;
1303 : 0 : inl_rq->sso_ena = true;
1304 : :
1305 : : /* Prepare and send RQ init mbox */
1306 : 0 : mbox = mbox_get(dev->mbox);
1307 [ # # ]: 0 : if (roc_model_is_cn9k())
1308 : 0 : rc = nix_rq_cn9k_cfg(dev, inl_rq, inl_dev->qints, false, enable);
1309 : : else
1310 : 0 : rc = nix_rq_cfg(dev, inl_rq, inl_dev->qints, false, enable);
1311 [ # # ]: 0 : if (rc) {
1312 : 0 : plt_err("Failed to prepare aq_enq msg, rc=%d", rc);
1313 : : mbox_put(mbox);
1314 : 0 : return rc;
1315 : : }
1316 : :
1317 : 0 : rc = mbox_process(dev->mbox);
1318 [ # # ]: 0 : if (rc) {
1319 : 0 : plt_err("Failed to send aq_enq msg, rc=%d", rc);
1320 : : mbox_put(mbox);
1321 : 0 : return rc;
1322 : : }
1323 : : mbox_put(mbox);
1324 : :
1325 : : /* Check meta aura */
1326 [ # # # # ]: 0 : if (enable && nix->need_meta_aura) {
1327 : 0 : rc = roc_nix_inl_meta_aura_check(rq->roc_nix, rq);
1328 [ # # ]: 0 : if (rc)
1329 : : return rc;
1330 : : }
1331 : :
1332 : 0 : inl_rq->inl_dev_refs++;
1333 : 0 : rq->inl_dev_refs = 1;
1334 : 0 : return 0;
1335 : : }
1336 : :
1337 : : int
1338 : 0 : roc_nix_inl_dev_rq_put(struct roc_nix_rq *rq)
1339 : : {
1340 : 0 : struct idev_cfg *idev = idev_get_cfg();
1341 : 0 : int port_id = rq->roc_nix->port_id;
1342 : : struct nix_inl_dev *inl_dev;
1343 : : struct roc_nix_rq *inl_rq;
1344 : : uint16_t inl_rq_id;
1345 : : struct dev *dev;
1346 : : int rc;
1347 : :
1348 [ # # ]: 0 : if (idev == NULL)
1349 : : return 0;
1350 : :
1351 : 0 : rq->meta_aura_handle = 0;
1352 [ # # ]: 0 : if (!rq->inl_dev_refs)
1353 : : return 0;
1354 : :
1355 : 0 : inl_dev = idev->nix_inl_dev;
1356 : : /* Inline device should be there if we have ref */
1357 [ # # ]: 0 : if (!inl_dev) {
1358 : 0 : plt_err("Failed to find inline device with refs");
1359 : 0 : return -EFAULT;
1360 : : }
1361 : :
1362 : 0 : dev = &inl_dev->dev;
1363 [ # # ]: 0 : inl_rq_id = inl_dev->nb_rqs > 1 ? port_id : 0;
1364 : 0 : inl_rq = &inl_dev->rqs[inl_rq_id];
1365 : :
1366 : 0 : rq->inl_dev_refs = 0;
1367 : 0 : inl_rq->inl_dev_refs--;
1368 [ # # ]: 0 : if (inl_rq->inl_dev_refs)
1369 : : return 0;
1370 : :
1371 : : /* There are no more references, disable RQ */
1372 : 0 : rc = nix_rq_ena_dis(dev, inl_rq, false);
1373 [ # # ]: 0 : if (rc)
1374 : 0 : plt_err("Failed to disable inline device rq, rc=%d", rc);
1375 : :
1376 : 0 : roc_npa_aura_drop_set(inl_rq->aura_handle, 0, false);
1377 [ # # ]: 0 : if (inl_rq->spb_ena)
1378 : 0 : roc_npa_aura_drop_set(inl_rq->spb_aura_handle, 0, false);
1379 : :
1380 : : /* Flush NIX LF for CN10K */
1381 : 0 : nix_rq_vwqe_flush(rq, inl_dev->vwqe_interval);
1382 : :
1383 : 0 : return rc;
1384 : : }
1385 : :
1386 : : int
1387 : 0 : roc_nix_inl_rq_ena_dis(struct roc_nix *roc_nix, bool enable)
1388 : : {
1389 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1390 : 0 : struct roc_nix_rq *inl_rq = roc_nix_inl_dev_rq(roc_nix);
1391 : 0 : struct idev_cfg *idev = idev_get_cfg();
1392 : : struct nix_inl_dev *inl_dev;
1393 : : int rc;
1394 : :
1395 [ # # ]: 0 : if (!idev)
1396 : : return -EFAULT;
1397 : :
1398 [ # # ]: 0 : if (roc_feature_nix_has_inl_rq_mask()) {
1399 : 0 : rc = nix_inl_rq_mask_cfg(roc_nix, enable);
1400 [ # # ]: 0 : if (rc) {
1401 : 0 : plt_err("Failed to get rq mask rc=%d", rc);
1402 : 0 : return rc;
1403 : : }
1404 : : }
1405 : :
1406 [ # # ]: 0 : if (nix->inb_inl_dev) {
1407 [ # # # # ]: 0 : if (!inl_rq || !idev->nix_inl_dev)
1408 : : return -EFAULT;
1409 : :
1410 : : inl_dev = idev->nix_inl_dev;
1411 : :
1412 : 0 : rc = nix_rq_ena_dis(&inl_dev->dev, inl_rq, enable);
1413 [ # # ]: 0 : if (rc)
1414 : : return rc;
1415 : :
1416 [ # # # # ]: 0 : if (enable && nix->need_meta_aura)
1417 : 0 : return roc_nix_inl_meta_aura_check(roc_nix, inl_rq);
1418 : : }
1419 : : return 0;
1420 : : }
1421 : :
1422 : : void
1423 : 0 : roc_nix_inb_mode_set(struct roc_nix *roc_nix, bool use_inl_dev)
1424 : : {
1425 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1426 : :
1427 : : /* Info used by NPC flow rule add */
1428 : 0 : nix->inb_inl_dev = use_inl_dev;
1429 : 0 : }
1430 : :
1431 : : void
1432 : 0 : roc_nix_inl_inb_set(struct roc_nix *roc_nix, bool ena)
1433 : : {
1434 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1435 : 0 : struct idev_cfg *idev = idev_get_cfg();
1436 : :
1437 [ # # ]: 0 : if (!idev)
1438 : : return;
1439 : : /* Need to set here for cases when inbound SA table is
1440 : : * managed outside RoC.
1441 : : */
1442 [ # # ]: 0 : nix->inl_inb_ena = ena;
1443 : :
1444 [ # # # # ]: 0 : if (roc_model_is_cn9k() || roc_errata_nix_no_meta_aura())
1445 : : return;
1446 : :
1447 [ # # ]: 0 : if (ena) {
1448 : 0 : nix->need_meta_aura = true;
1449 [ # # # # ]: 0 : if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
1450 : 0 : idev->inl_cfg.refs++;
1451 [ # # ]: 0 : } else if (nix->need_meta_aura) {
1452 : 0 : nix->need_meta_aura = false;
1453 [ # # # # ]: 0 : if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
1454 : 0 : idev->inl_cfg.refs--;
1455 : :
1456 [ # # ]: 0 : if (roc_nix->custom_meta_aura_ena)
1457 : 0 : nix_inl_custom_meta_aura_destroy(roc_nix);
1458 : :
1459 [ # # ]: 0 : if (!idev->inl_cfg.refs)
1460 : 0 : nix_inl_meta_aura_destroy(roc_nix);
1461 : : }
1462 : : }
1463 : :
1464 : : int
1465 : 0 : roc_nix_inl_outb_soft_exp_poll_switch(struct roc_nix *roc_nix, bool poll)
1466 : : {
1467 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1468 : 0 : struct idev_cfg *idev = idev_get_cfg();
1469 : : struct nix_inl_dev *inl_dev;
1470 : : uint16_t ring_idx, i;
1471 : :
1472 [ # # # # ]: 0 : if (!idev || !idev->nix_inl_dev)
1473 : : return 0;
1474 : :
1475 : : inl_dev = idev->nix_inl_dev;
1476 : :
1477 [ # # ]: 0 : for (i = 0; i < nix->outb_se_ring_cnt; i++) {
1478 : 0 : ring_idx = nix->outb_se_ring_base + i;
1479 : :
1480 [ # # ]: 0 : if (poll)
1481 : 0 : plt_bitmap_set(inl_dev->soft_exp_ring_bmap, ring_idx);
1482 : : else
1483 : 0 : plt_bitmap_clear(inl_dev->soft_exp_ring_bmap, ring_idx);
1484 : : }
1485 : :
1486 [ # # ]: 0 : if (poll)
1487 : 0 : soft_exp_consumer_cnt++;
1488 : : else
1489 : 0 : soft_exp_consumer_cnt--;
1490 : :
1491 : : return 0;
1492 : : }
1493 : :
1494 : : bool
1495 : 0 : roc_nix_inb_is_with_inl_dev(struct roc_nix *roc_nix)
1496 : : {
1497 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1498 : :
1499 : 0 : return nix->inb_inl_dev;
1500 : : }
1501 : :
1502 : : struct roc_nix_rq *
1503 : 0 : roc_nix_inl_dev_rq(struct roc_nix *roc_nix)
1504 : : {
1505 : 0 : struct idev_cfg *idev = idev_get_cfg();
1506 : 0 : int port_id = roc_nix->port_id;
1507 : : struct nix_inl_dev *inl_dev;
1508 : : struct roc_nix_rq *inl_rq;
1509 : : uint16_t inl_rq_id;
1510 : :
1511 [ # # ]: 0 : if (idev != NULL) {
1512 : 0 : inl_dev = idev->nix_inl_dev;
1513 [ # # ]: 0 : if (inl_dev != NULL) {
1514 [ # # ]: 0 : inl_rq_id = inl_dev->nb_rqs > 1 ? port_id : 0;
1515 : 0 : inl_rq = &inl_dev->rqs[inl_rq_id];
1516 [ # # ]: 0 : if (inl_rq->inl_dev_refs)
1517 : 0 : return inl_rq;
1518 : : }
1519 : : }
1520 : :
1521 : : return NULL;
1522 : : }
1523 : :
1524 : : uint16_t __roc_api
1525 : 0 : roc_nix_inl_outb_sso_pffunc_get(struct roc_nix *roc_nix)
1526 : : {
1527 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1528 : :
1529 : 0 : return nix->outb_err_sso_pffunc;
1530 : : }
1531 : :
1532 : : int
1533 : 0 : roc_nix_inl_cb_register(roc_nix_inl_sso_work_cb_t cb, void *args)
1534 : : {
1535 : 0 : struct idev_cfg *idev = idev_get_cfg();
1536 : : struct nix_inl_dev *inl_dev;
1537 : :
1538 [ # # ]: 0 : if (idev == NULL)
1539 : : return -EIO;
1540 : :
1541 : 0 : inl_dev = idev->nix_inl_dev;
1542 [ # # ]: 0 : if (!inl_dev)
1543 : : return -EIO;
1544 : :
1545 : : /* Be silent if registration called with same cb and args */
1546 [ # # # # ]: 0 : if (inl_dev->work_cb == cb && inl_dev->cb_args == args)
1547 : : return 0;
1548 : :
1549 : : /* Don't allow registration again if registered with different cb */
1550 [ # # ]: 0 : if (inl_dev->work_cb)
1551 : : return -EBUSY;
1552 : :
1553 : 0 : inl_dev->work_cb = cb;
1554 : 0 : inl_dev->cb_args = args;
1555 : 0 : return 0;
1556 : : }
1557 : :
1558 : : int
1559 : 0 : roc_nix_inl_cb_unregister(roc_nix_inl_sso_work_cb_t cb, void *args)
1560 : : {
1561 : 0 : struct idev_cfg *idev = idev_get_cfg();
1562 : : struct nix_inl_dev *inl_dev;
1563 : :
1564 [ # # ]: 0 : if (idev == NULL)
1565 : : return -ENOENT;
1566 : :
1567 : 0 : inl_dev = idev->nix_inl_dev;
1568 [ # # ]: 0 : if (!inl_dev)
1569 : : return -ENOENT;
1570 : :
1571 [ # # # # ]: 0 : if (inl_dev->work_cb != cb || inl_dev->cb_args != args)
1572 : : return -EINVAL;
1573 : :
1574 : 0 : inl_dev->work_cb = NULL;
1575 : 0 : inl_dev->cb_args = NULL;
1576 : 0 : return 0;
1577 : : }
1578 : :
1579 : : int
1580 : 0 : roc_nix_inl_inb_tag_update(struct roc_nix *roc_nix, uint32_t tag_const,
1581 : : uint8_t tt)
1582 : : {
1583 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1584 : : struct roc_nix_ipsec_cfg cfg;
1585 : :
1586 : : /* Be silent if inline inbound not enabled */
1587 [ # # ]: 0 : if (!nix->inl_inb_ena)
1588 : : return 0;
1589 : :
1590 : : memset(&cfg, 0, sizeof(cfg));
1591 : 0 : cfg.sa_size = nix->inb_sa_sz;
1592 : 0 : cfg.iova = (uintptr_t)nix->inb_sa_base;
1593 : 0 : cfg.max_sa = nix->inb_spi_mask + 1;
1594 : 0 : cfg.tt = tt;
1595 : 0 : cfg.tag_const = tag_const;
1596 : :
1597 : 0 : return roc_nix_lf_inl_ipsec_cfg(roc_nix, &cfg, true);
1598 : : }
1599 : :
1600 : : int
1601 : 0 : roc_nix_inl_sa_sync(struct roc_nix *roc_nix, void *sa, bool inb,
1602 : : enum roc_nix_inl_sa_sync_op op)
1603 : : {
1604 : 0 : struct idev_cfg *idev = idev_get_cfg();
1605 : : struct nix_inl_dev *inl_dev = NULL;
1606 : : struct roc_cpt_lf *outb_lf = NULL;
1607 : : union cpt_lf_ctx_reload reload;
1608 : : union cpt_lf_ctx_flush flush;
1609 : : bool get_inl_lf = true;
1610 : : uintptr_t rbase;
1611 : : struct nix *nix;
1612 : :
1613 : : /* Nothing much to do on cn9k */
1614 [ # # ]: 0 : if (roc_model_is_cn9k()) {
1615 : : plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
1616 : 0 : return 0;
1617 : : }
1618 : :
1619 [ # # ]: 0 : if (idev)
1620 : 0 : inl_dev = idev->nix_inl_dev;
1621 : :
1622 [ # # ]: 0 : if (!inl_dev && roc_nix == NULL)
1623 : : return -EINVAL;
1624 : :
1625 [ # # ]: 0 : if (roc_nix) {
1626 : : nix = roc_nix_to_nix_priv(roc_nix);
1627 : 0 : outb_lf = nix->cpt_lf_base;
1628 [ # # # # ]: 0 : if (inb && !nix->inb_inl_dev)
1629 : : get_inl_lf = false;
1630 : : }
1631 : :
1632 [ # # ]: 0 : if (inb && get_inl_lf) {
1633 : : outb_lf = NULL;
1634 [ # # # # ]: 0 : if (inl_dev && inl_dev->attach_cptlf)
1635 : 0 : outb_lf = &inl_dev->cpt_lf;
1636 : : }
1637 : :
1638 [ # # ]: 0 : if (outb_lf) {
1639 : 0 : rbase = outb_lf->rbase;
1640 : :
1641 : 0 : flush.u = 0;
1642 : 0 : reload.u = 0;
1643 [ # # # # ]: 0 : switch (op) {
1644 : 0 : case ROC_NIX_INL_SA_OP_FLUSH_INVAL:
1645 : 0 : flush.s.inval = 1;
1646 : : /* fall through */
1647 : 0 : case ROC_NIX_INL_SA_OP_FLUSH:
1648 : 0 : flush.s.cptr = ((uintptr_t)sa) >> 7;
1649 : 0 : plt_write64(flush.u, rbase + CPT_LF_CTX_FLUSH);
1650 : : break;
1651 : 0 : case ROC_NIX_INL_SA_OP_RELOAD:
1652 : 0 : reload.s.cptr = ((uintptr_t)sa) >> 7;
1653 : 0 : plt_write64(reload.u, rbase + CPT_LF_CTX_RELOAD);
1654 : : break;
1655 : : default:
1656 : : return -EINVAL;
1657 : : }
1658 : 0 : return 0;
1659 : : }
1660 : 0 : plt_err("Could not get CPT LF for SA sync");
1661 : 0 : return -ENOTSUP;
1662 : : }
1663 : :
1664 : : int
1665 : 0 : roc_nix_inl_ctx_write(struct roc_nix *roc_nix, void *sa_dptr, void *sa_cptr,
1666 : : bool inb, uint16_t sa_len)
1667 : : {
1668 : 0 : struct idev_cfg *idev = idev_get_cfg();
1669 : : struct nix_inl_dev *inl_dev = NULL;
1670 : : struct roc_cpt_lf *outb_lf = NULL;
1671 : : union cpt_lf_ctx_flush flush;
1672 : : bool get_inl_lf = true;
1673 : : uintptr_t rbase;
1674 : : struct nix *nix;
1675 : : int rc;
1676 : :
1677 : : /* Nothing much to do on cn9k */
1678 [ # # ]: 0 : if (roc_model_is_cn9k()) {
1679 : : return 0;
1680 : : }
1681 : :
1682 [ # # ]: 0 : if (idev)
1683 : 0 : inl_dev = idev->nix_inl_dev;
1684 : :
1685 [ # # ]: 0 : if (!inl_dev && roc_nix == NULL)
1686 : : return -EINVAL;
1687 : :
1688 [ # # ]: 0 : if (roc_nix) {
1689 : : nix = roc_nix_to_nix_priv(roc_nix);
1690 : 0 : outb_lf = nix->cpt_lf_base;
1691 : :
1692 [ # # # # ]: 0 : if (inb && !nix->inb_inl_dev)
1693 : : get_inl_lf = false;
1694 : : }
1695 : :
1696 [ # # ]: 0 : if (inb && get_inl_lf) {
1697 : : outb_lf = NULL;
1698 [ # # # # ]: 0 : if (inl_dev && inl_dev->attach_cptlf)
1699 : 0 : outb_lf = &inl_dev->cpt_lf;
1700 : : }
1701 : :
1702 [ # # ]: 0 : if (outb_lf) {
1703 : 0 : rbase = outb_lf->rbase;
1704 : 0 : flush.u = 0;
1705 : :
1706 : 0 : rc = roc_cpt_ctx_write(outb_lf, sa_dptr, sa_cptr, sa_len);
1707 [ # # ]: 0 : if (rc)
1708 : : return rc;
1709 : : /* Trigger CTX flush to write dirty data back to DRAM */
1710 : 0 : flush.s.cptr = ((uintptr_t)sa_cptr) >> 7;
1711 : 0 : plt_write64(flush.u, rbase + CPT_LF_CTX_FLUSH);
1712 : :
1713 : 0 : return 0;
1714 : : }
1715 : 0 : plt_nix_dbg("Could not get CPT LF for CTX write");
1716 : 0 : return -ENOTSUP;
1717 : : }
1718 : :
1719 : : int
1720 : 0 : roc_nix_inl_ts_pkind_set(struct roc_nix *roc_nix, bool ts_ena, bool inb_inl_dev)
1721 : : {
1722 : 0 : struct idev_cfg *idev = idev_get_cfg();
1723 : : struct nix_inl_dev *inl_dev = NULL;
1724 : : void *sa, *sa_base = NULL;
1725 : : struct nix *nix = NULL;
1726 : : uint16_t max_spi = 0;
1727 : : uint32_t rq_refs = 0;
1728 : : uint8_t pkind = 0;
1729 : : int i;
1730 : :
1731 [ # # ]: 0 : if (roc_model_is_cn9k())
1732 : : return 0;
1733 : :
1734 [ # # ]: 0 : if (!inb_inl_dev && (roc_nix == NULL))
1735 : : return -EINVAL;
1736 : :
1737 [ # # ]: 0 : if (inb_inl_dev) {
1738 [ # # # # ]: 0 : if ((idev == NULL) || (idev->nix_inl_dev == NULL))
1739 : : return 0;
1740 : : inl_dev = idev->nix_inl_dev;
1741 : : } else {
1742 : : nix = roc_nix_to_nix_priv(roc_nix);
1743 [ # # ]: 0 : if (!nix->inl_inb_ena)
1744 : : return 0;
1745 : 0 : sa_base = nix->inb_sa_base;
1746 : 0 : max_spi = roc_nix->ipsec_in_max_spi;
1747 : : }
1748 : :
1749 [ # # ]: 0 : if (inl_dev) {
1750 [ # # ]: 0 : for (i = 0; i < inl_dev->nb_rqs; i++)
1751 : 0 : rq_refs += inl_dev->rqs[i].inl_dev_refs;
1752 : :
1753 [ # # ]: 0 : if (rq_refs == 0) {
1754 : 0 : inl_dev->ts_ena = ts_ena;
1755 : 0 : max_spi = inl_dev->ipsec_in_max_spi;
1756 : 0 : sa_base = inl_dev->inb_sa_base;
1757 [ # # ]: 0 : } else if (inl_dev->ts_ena != ts_ena) {
1758 [ # # ]: 0 : if (inl_dev->ts_ena)
1759 : 0 : plt_err("Inline device is already configured with TS enable");
1760 : : else
1761 : 0 : plt_err("Inline device is already configured with TS disable");
1762 : 0 : return -ENOTSUP;
1763 : : } else {
1764 : : return 0;
1765 : : }
1766 : : }
1767 : :
1768 [ # # ]: 0 : pkind = ts_ena ? ROC_IE_OT_CPT_TS_PKIND : ROC_IE_OT_CPT_PKIND;
1769 : :
1770 : : sa = (uint8_t *)sa_base;
1771 [ # # ]: 0 : if (pkind == ((struct roc_ot_ipsec_inb_sa *)sa)->w0.s.pkind)
1772 : : return 0;
1773 : :
1774 [ # # ]: 0 : for (i = 0; i < max_spi; i++) {
1775 : 0 : sa = ((uint8_t *)sa_base) +
1776 : 0 : (i * ROC_NIX_INL_OT_IPSEC_INB_SA_SZ);
1777 : 0 : ((struct roc_ot_ipsec_inb_sa *)sa)->w0.s.pkind = pkind;
1778 : : }
1779 : : return 0;
1780 : : }
1781 : :
1782 : : void
1783 : 0 : roc_nix_inl_dev_lock(void)
1784 : : {
1785 : 0 : struct idev_cfg *idev = idev_get_cfg();
1786 : :
1787 [ # # ]: 0 : if (idev != NULL)
1788 : 0 : plt_spinlock_lock(&idev->nix_inl_dev_lock);
1789 : 0 : }
1790 : :
1791 : : void
1792 : 0 : roc_nix_inl_dev_unlock(void)
1793 : : {
1794 : 0 : struct idev_cfg *idev = idev_get_cfg();
1795 : :
1796 [ # # ]: 0 : if (idev != NULL)
1797 : 0 : plt_spinlock_unlock(&idev->nix_inl_dev_lock);
1798 : 0 : }
1799 : :
1800 : : void
1801 : 0 : roc_nix_inl_meta_pool_cb_register(roc_nix_inl_meta_pool_cb_t cb)
1802 : : {
1803 : 0 : meta_pool_cb = cb;
1804 : 0 : }
1805 : :
1806 : : uint64_t
1807 : 0 : roc_nix_inl_eng_caps_get(struct roc_nix *roc_nix)
1808 : : {
1809 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1810 : :
1811 : 0 : return nix->cpt_eng_caps;
1812 : : }
1813 : :
1814 : : void
1815 : 0 : roc_nix_inl_custom_meta_pool_cb_register(roc_nix_inl_custom_meta_pool_cb_t cb)
1816 : : {
1817 : 0 : custom_meta_pool_cb = cb;
1818 : 0 : }
|