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_ipsec_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 : 0 : struct idev_cfg *idev = idev_get_cfg();
399 : : struct nix_inl_dev *inl_dev = NULL;
400 : : uint64_t max_sa, i, sa_pow2_sz;
401 : : uint64_t sa_idx_w, lenm1_max;
402 : : uint8_t profile_id = 0;
403 : : struct mbox *mbox;
404 : : size_t inb_sa_sz;
405 : : void *sa;
406 : : int rc;
407 : :
408 : : /* Setup default IPsec profile */
409 [ # # ]: 0 : if (roc_feature_nix_has_inl_profile()) {
410 : 0 : rc = nix_inl_setup_dflt_ipsec_profile(&nix->dev, &nix->ipsec_prof_id);
411 [ # # ]: 0 : if (rc)
412 : : return rc;
413 : 0 : profile_id = nix->ipsec_prof_id;
414 : : }
415 : :
416 : 0 : mbox = mbox_get(nix->dev.mbox);
417 : :
418 [ # # ]: 0 : max_sa = plt_align32pow2(ipsec_in_max_spi - ipsec_in_min_spi + 1);
419 : :
420 : : /* CN9K SA size is different */
421 [ # # ]: 0 : if (roc_nix->custom_inb_sa)
422 : : inb_sa_sz = ROC_NIX_INL_INB_CUSTOM_SA_SZ;
423 : : else if (roc_model_is_cn9k())
424 : : inb_sa_sz = ROC_NIX_INL_ON_IPSEC_INB_SA_SZ;
425 : : else if (roc_model_is_cn10k())
426 : : inb_sa_sz = ROC_NIX_INL_OT_IPSEC_INB_SA_SZ;
427 : : else
428 : : inb_sa_sz = ROC_NIX_INL_OW_IPSEC_INB_SA_SZ;
429 : :
430 : : /* Alloc contiguous memory for Inbound SA's */
431 : 0 : nix->inb_sa_sz[profile_id] = inb_sa_sz;
432 : 0 : nix->inb_sa_max[profile_id] = max_sa;
433 : 0 : nix->inb_spi_mask = max_sa - 1;
434 : 0 : nix->inb_sa_base[profile_id] = plt_zmalloc(inb_sa_sz * max_sa, ROC_NIX_INL_SA_BASE_ALIGN);
435 [ # # ]: 0 : if (!nix->inb_sa_base[profile_id]) {
436 : : rc = -ENOMEM;
437 : 0 : plt_err("Failed to allocate memory for Inbound SA");
438 : 0 : goto exit;
439 : : }
440 : :
441 [ # # ]: 0 : sa_pow2_sz = plt_log2_u32(inb_sa_sz);
442 : 0 : sa_idx_w = plt_log2_u32(max_sa);
443 [ # # ]: 0 : lenm1_max = roc_nix_max_pkt_len(roc_nix) - 1;
444 : :
445 [ # # ]: 0 : if (!roc_model_is_cn9k()) {
446 [ # # ]: 0 : for (i = 0; i < max_sa; i++) {
447 [ # # ]: 0 : sa = ((uint8_t *)nix->inb_sa_base[profile_id]) + (i * inb_sa_sz);
448 [ # # ]: 0 : if (roc_model_is_cn10k())
449 : 0 : roc_ot_ipsec_inb_sa_init(sa);
450 : : else
451 : 0 : roc_ow_ipsec_inb_sa_init(sa);
452 : : }
453 : : }
454 : :
455 [ # # # # ]: 0 : if (roc_model_is_cn9k() || roc_model_is_cn10k()) {
456 : : struct nix_inline_ipsec_lf_cfg *lf_cfg;
457 : :
458 : : /* Setup device specific inb SA table */
459 : 0 : lf_cfg = mbox_alloc_msg_nix_inline_ipsec_lf_cfg(mbox);
460 [ # # ]: 0 : if (lf_cfg == NULL) {
461 : : rc = -ENOSPC;
462 : 0 : plt_err("Failed to alloc nix inline ipsec lf cfg mbox msg");
463 : 0 : goto free_mem;
464 : : }
465 : :
466 : 0 : lf_cfg->enable = 1;
467 : 0 : lf_cfg->sa_base_addr = (uintptr_t)nix->inb_sa_base[profile_id];
468 : 0 : lf_cfg->ipsec_cfg1.sa_idx_w = sa_idx_w;
469 : 0 : lf_cfg->ipsec_cfg0.lenm1_max = lenm1_max;
470 : 0 : lf_cfg->ipsec_cfg1.sa_idx_max = max_sa - 1;
471 : 0 : lf_cfg->ipsec_cfg0.sa_pow2_size = sa_pow2_sz;
472 : 0 : lf_cfg->ipsec_cfg0.tag_const = 0;
473 : 0 : lf_cfg->ipsec_cfg0.tt = SSO_TT_ORDERED;
474 : : } else {
475 : : struct nix_rx_inl_lf_cfg_req *lf_cfg;
476 : : uint64_t def_cptq = 0;
477 : :
478 : : /* Setup device specific inb SA table */
479 : 0 : lf_cfg = mbox_alloc_msg_nix_rx_inl_lf_cfg(mbox);
480 [ # # ]: 0 : if (lf_cfg == NULL) {
481 : : rc = -ENOSPC;
482 : 0 : plt_err("Failed to alloc nix inline ipsec lf cfg mbox msg");
483 : 0 : goto free_mem;
484 : : }
485 : :
486 : : /*TODO default cptq */
487 [ # # # # ]: 0 : if (idev && idev->nix_inl_dev) {
488 : : inl_dev = idev->nix_inl_dev;
489 [ # # ]: 0 : if (!inl_dev->nb_inb_cptlfs)
490 : : def_cptq = 0;
491 : : else
492 : 0 : def_cptq = inl_dev->nix_inb_qids[0];
493 : : }
494 : :
495 : 0 : lf_cfg->enable = 1;
496 : 0 : lf_cfg->profile_id = profile_id; /* IPsec profile is 0th one */
497 : 0 : lf_cfg->rx_inline_sa_base = (uintptr_t)nix->inb_sa_base[profile_id];
498 : 0 : lf_cfg->rx_inline_cfg0 = ((def_cptq << 57) | ((uint64_t)SSO_TT_ORDERED << 44) |
499 : 0 : (sa_pow2_sz << 16) | lenm1_max);
500 : 0 : lf_cfg->rx_inline_cfg1 = (max_sa - 1) | (sa_idx_w << 32);
501 : : }
502 : :
503 : 0 : rc = mbox_process(mbox);
504 [ # # ]: 0 : if (rc) {
505 : 0 : plt_err("Failed to setup NIX Inbound SA conf, rc=%d", rc);
506 : 0 : goto free_mem;
507 : : }
508 : :
509 : : mbox_put(mbox);
510 : 0 : return 0;
511 : 0 : free_mem:
512 : 0 : plt_free(nix->inb_sa_base[profile_id]);
513 : 0 : nix->inb_sa_base[profile_id] = NULL;
514 : 0 : exit:
515 : : mbox_put(mbox);
516 : 0 : return rc;
517 : : }
518 : :
519 : : static int
520 : 0 : nix_inl_ipsec_sa_tbl_release(struct roc_nix *roc_nix)
521 : : {
522 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
523 : 0 : struct mbox *mbox = mbox_get((&nix->dev)->mbox);
524 : : uint8_t profile_id = 0;
525 : : int rc;
526 : :
527 [ # # # # ]: 0 : if (roc_model_is_cn9k() || roc_model_is_cn10k()) {
528 : : struct nix_inline_ipsec_lf_cfg *lf_cfg;
529 : :
530 : 0 : lf_cfg = mbox_alloc_msg_nix_inline_ipsec_lf_cfg(mbox);
531 [ # # ]: 0 : if (lf_cfg == NULL) {
532 : : rc = -ENOSPC;
533 : 0 : goto exit;
534 : : }
535 : :
536 : 0 : lf_cfg->enable = 0;
537 : : } else {
538 : : struct nix_rx_inl_lf_cfg_req *lf_cfg;
539 : :
540 : 0 : profile_id = nix->ipsec_prof_id;
541 : 0 : lf_cfg = mbox_alloc_msg_nix_rx_inl_lf_cfg(mbox);
542 [ # # ]: 0 : if (!lf_cfg) {
543 : : rc = -ENOSPC;
544 : 0 : goto exit;
545 : : }
546 : :
547 : 0 : lf_cfg->enable = 0;
548 : 0 : lf_cfg->profile_id = profile_id; /* IPsec profile is 0th one */
549 : : }
550 : :
551 : 0 : rc = mbox_process(mbox);
552 [ # # ]: 0 : if (rc) {
553 : 0 : plt_err("Failed to cleanup NIX Inbound SA conf, rc=%d", rc);
554 : 0 : goto exit;
555 : : }
556 : :
557 : 0 : plt_free(nix->inb_sa_base[profile_id]);
558 : 0 : nix->inb_sa_base[profile_id] = NULL;
559 : 0 : exit:
560 : : mbox_put(mbox);
561 : 0 : return rc;
562 : : }
563 : :
564 : : static int
565 : 0 : nix_inl_reass_inb_sa_tbl_setup(struct roc_nix *roc_nix)
566 : : {
567 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
568 : : struct nix_rx_inl_lf_cfg_req *lf_cfg;
569 : : uint64_t max_sa = 1, sa_pow2_sz;
570 : : uint64_t sa_idx_w, lenm1_max;
571 : : size_t inb_sa_sz = 1;
572 : : uint8_t profile_id;
573 : : struct mbox *mbox;
574 : : void *sa;
575 : : int rc;
576 : :
577 [ # # ]: 0 : if (!roc_nix->reass_ena)
578 : : return 0;
579 : :
580 : 0 : rc = nix_inl_setup_reass_profile(&nix->dev, &nix->reass_prof_id);
581 [ # # ]: 0 : if (rc)
582 : : return rc;
583 : :
584 : 0 : profile_id = nix->reass_prof_id;
585 : 0 : nix->inb_sa_sz[profile_id] = inb_sa_sz;
586 : 0 : nix->inb_sa_max[profile_id] = max_sa;
587 : 0 : nix->inb_spi_mask = 1;
588 : 0 : nix->inb_sa_base[profile_id] = plt_zmalloc(inb_sa_sz * max_sa, ROC_NIX_INL_SA_BASE_ALIGN);
589 [ # # ]: 0 : if (!nix->inb_sa_base[profile_id]) {
590 : 0 : plt_err("Failed to allocate memory for reassembly Inbound SA");
591 : 0 : return -ENOMEM;
592 : : }
593 : :
594 : : sa = ((uint8_t *)nix->inb_sa_base[profile_id]);
595 : 0 : roc_ow_reass_inb_sa_init(sa);
596 : :
597 : 0 : mbox = mbox_get(nix->dev.mbox);
598 : : /* Setup device specific inb SA table */
599 : 0 : lf_cfg = mbox_alloc_msg_nix_rx_inl_lf_cfg(mbox);
600 [ # # ]: 0 : if (lf_cfg == NULL) {
601 : : rc = -ENOSPC;
602 : 0 : plt_err("Failed to alloc nix inline reassembly lf cfg mbox msg");
603 : 0 : goto free_mem;
604 : : }
605 : :
606 : : sa_pow2_sz = plt_log2_u32(inb_sa_sz);
607 : : sa_idx_w = plt_log2_u32(max_sa);
608 : 0 : lenm1_max = roc_nix_max_pkt_len(roc_nix) - 1;
609 : :
610 : 0 : lf_cfg->enable = 1;
611 : 0 : lf_cfg->profile_id = profile_id;
612 : 0 : lf_cfg->rx_inline_sa_base = (uintptr_t)nix->inb_sa_base[profile_id];
613 : 0 : lf_cfg->rx_inline_cfg0 =
614 : : (((uint64_t)SSO_TT_ORDERED << 44) | (sa_pow2_sz << 16) | lenm1_max);
615 : 0 : lf_cfg->rx_inline_cfg1 = (max_sa - 1) | (sa_idx_w << 32);
616 : :
617 : 0 : rc = mbox_process(mbox);
618 [ # # ]: 0 : if (rc) {
619 : 0 : plt_err("Failed to setup NIX Inbound reassembly SA conf, rc=%d", rc);
620 : 0 : goto free_mem;
621 : : }
622 : :
623 : : mbox_put(mbox);
624 : 0 : return 0;
625 : :
626 : 0 : free_mem:
627 : 0 : plt_free(nix->inb_sa_base[profile_id]);
628 : 0 : nix->inb_sa_base[profile_id] = NULL;
629 : : mbox_put(mbox);
630 : 0 : return rc;
631 : : }
632 : :
633 : : static int
634 : 0 : nix_inl_reass_sa_tbl_release(struct roc_nix *roc_nix)
635 : : {
636 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
637 : 0 : struct mbox *mbox = mbox_get((&nix->dev)->mbox);
638 : : struct nix_rx_inl_lf_cfg_req *lf_cfg;
639 : : uint8_t profile_id;
640 : : int rc;
641 : :
642 [ # # ]: 0 : if (!roc_nix->reass_ena)
643 : : return 0;
644 : :
645 : 0 : lf_cfg = mbox_alloc_msg_nix_rx_inl_lf_cfg(mbox);
646 [ # # ]: 0 : if (!lf_cfg) {
647 : : rc = -ENOSPC;
648 : 0 : goto exit;
649 : : }
650 : :
651 : 0 : profile_id = nix->reass_prof_id;
652 : :
653 : 0 : lf_cfg->enable = 0;
654 : 0 : lf_cfg->profile_id = profile_id;
655 : 0 : rc = mbox_process(mbox);
656 [ # # ]: 0 : if (rc) {
657 : 0 : plt_err("Failed to cleanup NIX Inbound Reassembly SA conf, rc=%d", rc);
658 : 0 : goto exit;
659 : : }
660 : :
661 : 0 : plt_free(nix->inb_sa_base[profile_id]);
662 : 0 : nix->inb_sa_base[profile_id] = NULL;
663 : 0 : exit:
664 : : mbox_put(mbox);
665 : 0 : return rc;
666 : : }
667 : :
668 : : struct roc_cpt_lf *
669 : 0 : roc_nix_inl_outb_lf_base_get(struct roc_nix *roc_nix)
670 : : {
671 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
672 : :
673 : : /* NIX Inline config needs to be done */
674 [ # # # # ]: 0 : if (!nix->inl_outb_ena || !nix->cpt_lf_base)
675 : 0 : return NULL;
676 : :
677 : : return (struct roc_cpt_lf *)nix->cpt_lf_base;
678 : : }
679 : :
680 : : struct roc_cpt_lf *
681 : 0 : roc_nix_inl_inb_inj_lf_get(struct roc_nix *roc_nix)
682 : : {
683 : : struct nix *nix;
684 : 0 : struct idev_cfg *idev = idev_get_cfg();
685 : : struct nix_inl_dev *inl_dev = NULL;
686 : : struct roc_cpt_lf *lf = NULL;
687 : :
688 [ # # ]: 0 : if (!idev)
689 : : return NULL;
690 : :
691 : 0 : inl_dev = idev->nix_inl_dev;
692 : :
693 [ # # ]: 0 : if (!inl_dev && roc_nix == NULL)
694 : : return NULL;
695 : :
696 : : nix = roc_nix_to_nix_priv(roc_nix);
697 : :
698 [ # # # # : 0 : if (nix->inb_inl_dev && inl_dev && inl_dev->attach_cptlf &&
# # ]
699 [ # # ]: 0 : inl_dev->rx_inj_ena)
700 : 0 : return &inl_dev->cpt_lf[inl_dev->nb_cptlf - 1];
701 : :
702 : 0 : lf = roc_nix_inl_outb_lf_base_get(roc_nix);
703 [ # # ]: 0 : if (lf)
704 : 0 : lf += roc_nix->outb_nb_crypto_qs;
705 : : return lf;
706 : : }
707 : :
708 : : uintptr_t
709 : 0 : roc_nix_inl_outb_sa_base_get(struct roc_nix *roc_nix)
710 : : {
711 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
712 : :
713 : 0 : return (uintptr_t)nix->outb_sa_base;
714 : : }
715 : :
716 : : uintptr_t
717 : 0 : roc_nix_inl_inb_sa_base_get(struct roc_nix *roc_nix, bool inb_inl_dev)
718 : : {
719 : 0 : struct idev_cfg *idev = idev_get_cfg();
720 : : struct nix_inl_dev *inl_dev;
721 : : struct nix *nix = NULL;
722 : :
723 [ # # ]: 0 : if (idev == NULL)
724 : : return 0;
725 : :
726 [ # # ]: 0 : if (!inb_inl_dev && roc_nix == NULL)
727 : : return -EINVAL;
728 : :
729 [ # # ]: 0 : if (roc_nix) {
730 : : nix = roc_nix_to_nix_priv(roc_nix);
731 [ # # ]: 0 : if (!nix->inl_inb_ena)
732 : : return 0;
733 : : }
734 : :
735 [ # # ]: 0 : if (inb_inl_dev) {
736 : 0 : inl_dev = idev->nix_inl_dev;
737 : : /* Return inline dev sa base */
738 [ # # ]: 0 : if (inl_dev)
739 : 0 : return (uintptr_t)inl_dev->inb_sa_base[inl_dev->ipsec_prof_id];
740 : : return 0;
741 : : }
742 : :
743 : 0 : return (uintptr_t)nix->inb_sa_base[nix->ipsec_prof_id];
744 : : }
745 : :
746 : : uint16_t
747 : 0 : roc_nix_inl_inb_ipsec_profile_id_get(struct roc_nix *roc_nix, bool inb_inl_dev)
748 : : {
749 : 0 : struct idev_cfg *idev = idev_get_cfg();
750 : : struct nix_inl_dev *inl_dev;
751 : : struct nix *nix = NULL;
752 : :
753 [ # # ]: 0 : if (idev == NULL)
754 : : return 0;
755 : :
756 [ # # ]: 0 : if (!inb_inl_dev && roc_nix == NULL)
757 : : return -EINVAL;
758 : :
759 [ # # ]: 0 : if (roc_nix) {
760 : : nix = roc_nix_to_nix_priv(roc_nix);
761 [ # # ]: 0 : if (!nix->inl_inb_ena)
762 : : return 0;
763 : : }
764 : :
765 [ # # ]: 0 : if (inb_inl_dev) {
766 : 0 : inl_dev = idev->nix_inl_dev;
767 : : /* Return inline Ipsec profile ID */
768 [ # # ]: 0 : if (inl_dev)
769 : 0 : return inl_dev->ipsec_prof_id;
770 : : return 0;
771 : : }
772 : :
773 : 0 : return nix->ipsec_prof_id;
774 : : }
775 : :
776 : : uint16_t
777 : 0 : roc_nix_inl_inb_reass_profile_id_get(struct roc_nix *roc_nix, bool inb_inl_dev)
778 : : {
779 : 0 : struct idev_cfg *idev = idev_get_cfg();
780 : : struct nix_inl_dev *inl_dev;
781 : : struct nix *nix = NULL;
782 : :
783 [ # # ]: 0 : if (idev == NULL)
784 : : return 0;
785 : :
786 [ # # ]: 0 : if (!inb_inl_dev && roc_nix == NULL)
787 : : return -EINVAL;
788 : :
789 [ # # ]: 0 : if (roc_nix) {
790 : : nix = roc_nix_to_nix_priv(roc_nix);
791 [ # # ]: 0 : if (!nix->inl_inb_ena)
792 : : return 0;
793 : : }
794 : :
795 [ # # ]: 0 : if (inb_inl_dev) {
796 : 0 : inl_dev = idev->nix_inl_dev;
797 : : /* Return inline reassembly profile ID */
798 [ # # ]: 0 : if (inl_dev)
799 : 0 : return inl_dev->reass_prof_id;
800 : : return 0;
801 : : }
802 : :
803 : 0 : return nix->reass_prof_id;
804 : : }
805 : :
806 : : bool
807 : 0 : roc_nix_inl_inb_rx_inject_enable(struct roc_nix *roc_nix, bool inb_inl_dev)
808 : : {
809 : 0 : struct idev_cfg *idev = idev_get_cfg();
810 : : struct nix_inl_dev *inl_dev;
811 : : struct nix *nix = NULL;
812 : :
813 [ # # ]: 0 : if (idev == NULL)
814 : : return 0;
815 : :
816 [ # # ]: 0 : if (!inb_inl_dev && roc_nix == NULL)
817 : : return 0;
818 : :
819 [ # # ]: 0 : if (roc_nix) {
820 : : nix = roc_nix_to_nix_priv(roc_nix);
821 [ # # ]: 0 : if (!nix->inl_inb_ena)
822 : : return 0;
823 : : }
824 : :
825 [ # # ]: 0 : if (inb_inl_dev) {
826 : 0 : inl_dev = idev->nix_inl_dev;
827 [ # # # # : 0 : if (inl_dev && inl_dev->attach_cptlf && inl_dev->rx_inj_ena &&
# # ]
828 [ # # ]: 0 : roc_nix->rx_inj_ena)
829 : : return true;
830 : : }
831 : :
832 : 0 : return roc_nix->rx_inj_ena;
833 : : }
834 : :
835 : : uint32_t
836 : 0 : roc_nix_inl_inb_spi_range(struct roc_nix *roc_nix, bool inb_inl_dev,
837 : : uint32_t *min_spi, uint32_t *max_spi)
838 : : {
839 : 0 : struct idev_cfg *idev = idev_get_cfg();
840 : : uint32_t min = 0, max = 0, mask = 0;
841 : : struct nix_inl_dev *inl_dev;
842 : : struct nix *nix = NULL;
843 : :
844 [ # # ]: 0 : if (idev == NULL)
845 : : return 0;
846 : :
847 [ # # ]: 0 : if (!inb_inl_dev && roc_nix == NULL)
848 : : return -EINVAL;
849 : :
850 : 0 : inl_dev = idev->nix_inl_dev;
851 [ # # ]: 0 : if (inb_inl_dev) {
852 [ # # ]: 0 : if (inl_dev == NULL)
853 : 0 : goto exit;
854 : 0 : min = inl_dev->ipsec_in_min_spi;
855 : 0 : max = inl_dev->ipsec_in_max_spi;
856 : 0 : mask = inl_dev->inb_spi_mask;
857 : : } else {
858 : : nix = roc_nix_to_nix_priv(roc_nix);
859 [ # # ]: 0 : if (!nix->inl_inb_ena)
860 : 0 : goto exit;
861 : 0 : min = roc_nix->ipsec_in_min_spi;
862 : 0 : max = roc_nix->ipsec_in_max_spi;
863 : 0 : mask = nix->inb_spi_mask;
864 : : }
865 : 0 : exit:
866 [ # # ]: 0 : if (min_spi)
867 : 0 : *min_spi = min;
868 [ # # ]: 0 : if (max_spi)
869 : 0 : *max_spi = max;
870 : : return mask;
871 : : }
872 : :
873 : : uint32_t
874 : 0 : roc_nix_inl_inb_sa_sz(struct roc_nix *roc_nix, bool inl_dev_sa)
875 : : {
876 : 0 : struct idev_cfg *idev = idev_get_cfg();
877 : : struct nix_inl_dev *inl_dev;
878 : : struct nix *nix;
879 : :
880 [ # # ]: 0 : if (idev == NULL)
881 : : return 0;
882 : :
883 [ # # ]: 0 : if (!inl_dev_sa && roc_nix == NULL)
884 : : return -EINVAL;
885 : :
886 [ # # ]: 0 : if (roc_nix) {
887 : : nix = roc_nix_to_nix_priv(roc_nix);
888 [ # # ]: 0 : if (!inl_dev_sa)
889 : 0 : return nix->inb_sa_sz[nix->ipsec_prof_id];
890 : : }
891 : :
892 [ # # ]: 0 : if (inl_dev_sa) {
893 : 0 : inl_dev = idev->nix_inl_dev;
894 [ # # ]: 0 : if (inl_dev)
895 : 0 : return inl_dev->inb_sa_sz[inl_dev->ipsec_prof_id];
896 : : }
897 : :
898 : : return 0;
899 : : }
900 : :
901 : : uintptr_t
902 : 0 : roc_nix_inl_inb_sa_get(struct roc_nix *roc_nix, bool inb_inl_dev, uint32_t spi)
903 : : {
904 : 0 : uint32_t max_spi = 0, min_spi = 0, mask;
905 : : uintptr_t sa_base;
906 : : uint64_t sz;
907 : :
908 : 0 : sa_base = roc_nix_inl_inb_sa_base_get(roc_nix, inb_inl_dev);
909 : : /* Check if SA base exists */
910 [ # # ]: 0 : if (!sa_base)
911 : : return 0;
912 : :
913 : : /* Get SA size */
914 : 0 : sz = roc_nix_inl_inb_sa_sz(roc_nix, inb_inl_dev);
915 [ # # ]: 0 : if (!sz)
916 : : return 0;
917 : :
918 [ # # # # ]: 0 : if (roc_nix && roc_nix->custom_sa_action)
919 : 0 : return (sa_base + (spi * sz));
920 : :
921 : : /* Check if SPI is in range */
922 : 0 : mask = roc_nix_inl_inb_spi_range(roc_nix, inb_inl_dev, &min_spi,
923 : : &max_spi);
924 [ # # # # ]: 0 : if (spi > max_spi || spi < min_spi)
925 : 0 : plt_nix_dbg("Inbound SA SPI %u not in range (%u..%u)", spi,
926 : : min_spi, max_spi);
927 : :
928 : : /* Basic logic of SPI->SA for now */
929 : 0 : return (sa_base + ((spi & mask) * sz));
930 : : }
931 : :
932 : : int
933 : 0 : roc_nix_reassembly_configure(struct roc_cpt_rxc_time_cfg *req_cfg, uint32_t max_wait_time)
934 : : {
935 : 0 : struct idev_cfg *idev = idev_get_cfg();
936 : : struct nix_inl_dev *inl_dev = NULL;
937 : : struct cpt_rxc_time_cfg_req *req;
938 : : struct roc_cpt_rxc_time_cfg cfg;
939 : : struct roc_cpt *roc_cpt;
940 : : struct mbox *mbox;
941 : : int rc;
942 : :
943 [ # # ]: 0 : if (!idev)
944 : : return -EFAULT;
945 : :
946 : 0 : roc_cpt = idev->cpt;
947 [ # # ]: 0 : if (!roc_cpt) {
948 : 0 : plt_err("Cannot support inline inbound, cryptodev not probed");
949 : 0 : return -ENOTSUP;
950 : : }
951 : :
952 [ # # ]: 0 : cfg.step = req_cfg->step ? req_cfg->step :
953 : 0 : (max_wait_time * 1000 / ROC_NIX_INL_REAS_ACTIVE_LIMIT);
954 : 0 : cfg.zombie_limit =
955 [ # # ]: 0 : req_cfg->zombie_limit ? req_cfg->zombie_limit : ROC_NIX_INL_REAS_ZOMBIE_LIMIT;
956 : 0 : cfg.zombie_thres =
957 [ # # ]: 0 : req_cfg->zombie_thres ? req_cfg->zombie_thres : ROC_NIX_INL_REAS_ZOMBIE_THRESHOLD;
958 : 0 : cfg.active_limit =
959 [ # # ]: 0 : req_cfg->active_limit ? req_cfg->active_limit : ROC_NIX_INL_REAS_ACTIVE_LIMIT;
960 [ # # ]: 0 : cfg.active_thres =
961 [ # # ]: 0 : req_cfg->active_thres ? req_cfg->active_thres : ROC_NIX_INL_REAS_ACTIVE_THRESHOLD;
962 : :
963 [ # # ]: 0 : if (roc_model_is_cn10k())
964 : 0 : return roc_cpt_rxc_time_cfg(roc_cpt, &cfg);
965 : :
966 : 0 : inl_dev = idev->nix_inl_dev;
967 [ # # ]: 0 : if (!inl_dev) {
968 : 0 : plt_err("Cannot support RXC config, inlinedev is not probed");
969 : 0 : return -ENOTSUP;
970 : : }
971 : :
972 : 0 : mbox = mbox_get((&inl_dev->dev)->mbox);
973 : :
974 : 0 : req = mbox_alloc_msg_cpt_rxc_time_cfg(mbox);
975 [ # # ]: 0 : if (req == NULL) {
976 : : rc = -ENOSPC;
977 : 0 : goto exit;
978 : : }
979 : :
980 : 0 : req->blkaddr = 0;
981 : 0 : req->queue_id = inl_dev->nix_inb_qids[inl_dev->inb_cpt_lf_id];
982 : 0 : req->step = cfg.step;
983 : 0 : req->zombie_limit = cfg.zombie_limit;
984 : 0 : req->zombie_thres = cfg.zombie_thres;
985 : 0 : req->active_limit = cfg.active_limit;
986 : 0 : req->active_thres = cfg.active_thres;
987 : :
988 : 0 : rc = mbox_process(mbox);
989 : 0 : exit:
990 : : mbox_put(mbox);
991 : 0 : return rc;
992 : : }
993 : :
994 : : static void
995 : 0 : nix_inl_rq_mask_init(struct nix_rq_cpt_field_mask_cfg_req *msk_req)
996 : : {
997 : : int i;
998 : :
999 [ # # ]: 0 : for (i = 0; i < RQ_CTX_MASK_MAX; i++)
1000 : 0 : msk_req->rq_ctx_word_mask[i] = 0xFFFFFFFFFFFFFFFF;
1001 : :
1002 : 0 : msk_req->rq_set.len_ol3_dis = 1;
1003 : 0 : msk_req->rq_set.len_ol4_dis = 1;
1004 : 0 : msk_req->rq_set.len_il3_dis = 1;
1005 : :
1006 : 0 : msk_req->rq_set.len_il4_dis = 1;
1007 : 0 : msk_req->rq_set.csum_ol4_dis = 1;
1008 : 0 : msk_req->rq_set.csum_il4_dis = 1;
1009 : :
1010 : 0 : msk_req->rq_set.lenerr_dis = 1;
1011 : 0 : msk_req->rq_set.port_ol4_dis = 1;
1012 : 0 : msk_req->rq_set.port_il4_dis = 1;
1013 : :
1014 : 0 : msk_req->rq_set.lpb_drop_ena = 0;
1015 : 0 : msk_req->rq_set.spb_drop_ena = 0;
1016 : 0 : msk_req->rq_set.xqe_drop_ena = 0;
1017 [ # # ]: 0 : msk_req->rq_set.spb_ena = 1;
1018 : :
1019 [ # # ]: 0 : if (!roc_feature_nix_has_second_pass_drop()) {
1020 : 0 : msk_req->rq_set.ena = 1;
1021 : 0 : msk_req->rq_set.rq_int_ena = 1;
1022 : 0 : msk_req->rq_mask.ena = 0;
1023 : 0 : msk_req->rq_mask.rq_int_ena = 0;
1024 : : }
1025 : :
1026 : 0 : msk_req->rq_mask.len_ol3_dis = 0;
1027 : 0 : msk_req->rq_mask.len_ol4_dis = 0;
1028 : 0 : msk_req->rq_mask.len_il3_dis = 0;
1029 : :
1030 : 0 : msk_req->rq_mask.len_il4_dis = 0;
1031 : 0 : msk_req->rq_mask.csum_ol4_dis = 0;
1032 : 0 : msk_req->rq_mask.csum_il4_dis = 0;
1033 : :
1034 : 0 : msk_req->rq_mask.lenerr_dis = 0;
1035 : 0 : msk_req->rq_mask.port_ol4_dis = 0;
1036 : 0 : msk_req->rq_mask.port_il4_dis = 0;
1037 : :
1038 : 0 : msk_req->rq_mask.lpb_drop_ena = 0;
1039 : 0 : msk_req->rq_mask.spb_drop_ena = 0;
1040 : 0 : msk_req->rq_mask.xqe_drop_ena = 0;
1041 : 0 : msk_req->rq_mask.spb_ena = 0;
1042 : 0 : }
1043 : :
1044 : : static int
1045 : 0 : nix_inl_legacy_rq_mask_setup(struct roc_nix *roc_nix, bool enable)
1046 : : {
1047 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1048 : : struct nix_rq_cpt_field_mask_cfg_req *msk_req;
1049 : 0 : struct idev_cfg *idev = idev_get_cfg();
1050 : 0 : struct mbox *mbox = mbox_get((&nix->dev)->mbox);
1051 : : struct idev_nix_inl_cfg *inl_cfg;
1052 : : uint64_t aura_handle;
1053 : : int rc = -ENOSPC;
1054 : : uint32_t buf_sz;
1055 : :
1056 [ # # ]: 0 : if (!idev)
1057 : 0 : goto exit;
1058 : :
1059 : : inl_cfg = &idev->inl_cfg;
1060 : 0 : msk_req = mbox_alloc_msg_nix_lf_inline_rq_cfg(mbox);
1061 [ # # ]: 0 : if (msk_req == NULL)
1062 : 0 : goto exit;
1063 : :
1064 : 0 : nix_inl_rq_mask_init(msk_req);
1065 [ # # ]: 0 : if (roc_nix->local_meta_aura_ena) {
1066 : 0 : aura_handle = roc_nix->meta_aura_handle;
1067 : 0 : buf_sz = roc_nix->buf_sz;
1068 [ # # ]: 0 : if (!aura_handle && enable) {
1069 : 0 : plt_err("NULL meta aura handle");
1070 : 0 : goto exit;
1071 : : }
1072 : : } else {
1073 : 0 : aura_handle = roc_npa_zero_aura_handle();
1074 : 0 : buf_sz = inl_cfg->buf_sz;
1075 : : }
1076 : :
1077 : 0 : msk_req->ipsec_cfg1.spb_cpt_aura = roc_npa_aura_handle_to_aura(aura_handle);
1078 : 0 : msk_req->ipsec_cfg1.rq_mask_enable = enable;
1079 : 0 : msk_req->ipsec_cfg1.spb_cpt_sizem1 = (buf_sz >> 7) - 1;
1080 : 0 : msk_req->ipsec_cfg1.spb_cpt_enable = enable;
1081 : :
1082 : 0 : rc = mbox_process(mbox);
1083 : 0 : exit:
1084 : : mbox_put(mbox);
1085 : 0 : return rc;
1086 : : }
1087 : :
1088 : : static int
1089 : 0 : nix_inl_rq_mask_cfg(struct roc_nix *roc_nix, bool enable)
1090 : : {
1091 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1092 : : struct nix_rq_cpt_field_mask_cfg_req *msk_req;
1093 : 0 : struct idev_cfg *idev = idev_get_cfg();
1094 : : struct nix_rx_inl_lf_cfg_req *lf_cfg;
1095 : : struct idev_nix_inl_cfg *inl_cfg;
1096 : : uint64_t aura_handle;
1097 : : struct mbox *mbox;
1098 : : int rc = -ENOSPC;
1099 : : uint64_t buf_sz;
1100 : :
1101 [ # # ]: 0 : if (roc_model_is_cn9k() | roc_model_is_cn10k())
1102 : 0 : return nix_inl_legacy_rq_mask_setup(roc_nix, enable);
1103 : :
1104 : 0 : mbox = mbox_get((&nix->dev)->mbox);
1105 : : /* RQ mask alloc and setup */
1106 : 0 : msk_req = mbox_alloc_msg_nix_lf_inline_rq_cfg(mbox);
1107 [ # # ]: 0 : if (msk_req == NULL)
1108 : 0 : goto exit;
1109 : :
1110 : 0 : nix_inl_rq_mask_init(msk_req);
1111 : 0 : rc = mbox_process(mbox);
1112 [ # # ]: 0 : if (rc) {
1113 : 0 : plt_err("Failed to setup NIX Inline RQ mask, rc=%d", rc);
1114 : 0 : goto exit;
1115 : : }
1116 : :
1117 : : /* SPB setup */
1118 [ # # # # ]: 0 : if (!roc_nix->local_meta_aura_ena && !roc_nix->custom_meta_aura_ena)
1119 : 0 : goto exit;
1120 : :
1121 [ # # ]: 0 : if (!idev)
1122 : : return -ENOENT;
1123 : :
1124 : : inl_cfg = &idev->inl_cfg;
1125 : :
1126 [ # # ]: 0 : if (roc_nix->local_meta_aura_ena) {
1127 : 0 : aura_handle = roc_nix->meta_aura_handle;
1128 : 0 : buf_sz = roc_nix->buf_sz;
1129 [ # # ]: 0 : if (!aura_handle && enable) {
1130 : 0 : plt_err("NULL meta aura handle");
1131 : : rc = -EINVAL;
1132 : 0 : goto exit;
1133 : : }
1134 : : } else {
1135 : 0 : aura_handle = roc_npa_zero_aura_handle();
1136 : 0 : buf_sz = inl_cfg->buf_sz;
1137 : : }
1138 : :
1139 : : /* SPB setup */
1140 : 0 : lf_cfg = mbox_alloc_msg_nix_rx_inl_lf_cfg(mbox);
1141 [ # # ]: 0 : if (lf_cfg == NULL) {
1142 : : rc = -ENOSPC;
1143 : 0 : goto exit;
1144 : : }
1145 : :
1146 : 0 : lf_cfg->rx_inline_sa_base = (uintptr_t)nix->inb_sa_base;
1147 : 0 : lf_cfg->rx_inline_cfg0 = nix->rx_inline_cfg0;
1148 : 0 : lf_cfg->profile_id = nix->ipsec_prof_id;
1149 [ # # ]: 0 : if (enable)
1150 : 0 : lf_cfg->rx_inline_cfg1 =
1151 : 0 : (nix->rx_inline_cfg1 | BIT_ULL(37) | ((buf_sz >> 7) - 1) << 38 |
1152 : 0 : roc_npa_aura_handle_to_aura(aura_handle) << 44);
1153 : : else
1154 : 0 : lf_cfg->rx_inline_cfg1 = nix->rx_inline_cfg1;
1155 : 0 : rc = mbox_process(mbox);
1156 : 0 : exit:
1157 : : mbox_put(mbox);
1158 : 0 : return rc;
1159 : : }
1160 : :
1161 : : static void
1162 : 0 : nix_inl_eng_caps_get(struct nix *nix)
1163 : : {
1164 : 0 : struct roc_cpt_lf *lf = nix->cpt_lf_base;
1165 : 0 : uintptr_t lmt_base = lf->lmt_base;
1166 : : union cpt_res_s res, *hw_res;
1167 : : struct cpt_inst_s inst;
1168 : : uint64_t *rptr;
1169 : :
1170 : 0 : hw_res = plt_zmalloc(sizeof(*hw_res), ROC_CPT_RES_ALIGN);
1171 [ # # ]: 0 : if (hw_res == NULL) {
1172 : 0 : plt_err("Couldn't allocate memory for result address");
1173 : 0 : return;
1174 : : }
1175 : :
1176 : 0 : rptr = plt_zmalloc(ROC_ALIGN, 0);
1177 [ # # ]: 0 : if (rptr == NULL) {
1178 : 0 : plt_err("Couldn't allocate memory for rptr");
1179 : 0 : plt_free(hw_res);
1180 : 0 : return;
1181 : : }
1182 : :
1183 : : /* Fill CPT_INST_S for LOAD_FVC/HW_CRYPTO_SUPPORT microcode op */
1184 : : memset(&inst, 0, sizeof(struct cpt_inst_s));
1185 : 0 : inst.res_addr = (uint64_t)hw_res;
1186 : 0 : inst.rptr = (uint64_t)rptr;
1187 : 0 : inst.w4.s.opcode_major = ROC_LOADFVC_MAJOR_OP;
1188 : 0 : inst.w4.s.opcode_minor = ROC_LOADFVC_MINOR_OP;
1189 : : if (roc_model_is_cn9k() || roc_model_is_cn10k())
1190 : : inst.w7.s.egrp = ROC_LEGACY_CPT_DFLT_ENG_GRP_SE;
1191 : : else
1192 : : inst.w7.s.egrp = ROC_CPT_DFLT_ENG_GRP_SE;
1193 : :
1194 : : /* Use 1 min timeout for the poll */
1195 [ # # ]: 0 : const uint64_t timeout = plt_tsc_cycles() + 60 * plt_tsc_hz();
1196 : :
1197 [ # # ]: 0 : if (roc_model_is_cn9k()) {
1198 : : uint64_t lmt_status;
1199 : :
1200 : 0 : hw_res->cn9k.compcode = CPT_COMP_NOT_DONE;
1201 : 0 : plt_io_wmb();
1202 : :
1203 : : do {
1204 : : roc_lmt_mov_seg((void *)lmt_base, &inst, 4);
1205 : : lmt_status = roc_lmt_submit_ldeor(lf->io_addr);
1206 : : } while (lmt_status != 0);
1207 : :
1208 : : /* Wait until CPT instruction completes */
1209 : : do {
1210 : 0 : res.u64[0] = __atomic_load_n(&hw_res->u64[0], __ATOMIC_RELAXED);
1211 [ # # ]: 0 : if (unlikely(plt_tsc_cycles() > timeout))
1212 : : break;
1213 [ # # ]: 0 : } while (res.cn9k.compcode == CPT_COMP_NOT_DONE);
1214 : :
1215 [ # # ]: 0 : if (res.cn9k.compcode != CPT_COMP_GOOD) {
1216 : 0 : plt_err("LOAD FVC operation timed out");
1217 : 0 : return;
1218 : : }
1219 [ # # ]: 0 : } else if (roc_model_is_cn10k()) {
1220 : : uint64_t lmt_arg, io_addr;
1221 : : uint16_t lmt_id;
1222 : :
1223 : 0 : hw_res->cn10k.compcode = CPT_COMP_NOT_DONE;
1224 : :
1225 : : /* Use this reserved LMT line as no one else is using it */
1226 : 0 : lmt_id = roc_plt_control_lmt_id_get();
1227 : 0 : lmt_base += ((uint64_t)lmt_id << ROC_LMT_LINE_SIZE_LOG2);
1228 : :
1229 : 0 : memcpy((void *)lmt_base, &inst, sizeof(inst));
1230 : :
1231 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (uint64_t)lmt_id;
1232 : : io_addr = lf->io_addr | ROC_CN10K_CPT_INST_DW_M1 << 4;
1233 : :
1234 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
1235 : 0 : plt_io_wmb();
1236 : :
1237 : : /* Wait until CPT instruction completes */
1238 : : do {
1239 : 0 : res.u64[0] = __atomic_load_n(&hw_res->u64[0], __ATOMIC_RELAXED);
1240 [ # # ]: 0 : if (unlikely(plt_tsc_cycles() > timeout))
1241 : : break;
1242 [ # # ]: 0 : } while (res.cn10k.compcode == CPT_COMP_NOT_DONE);
1243 : :
1244 [ # # ]: 0 : if (res.cn10k.compcode != CPT_COMP_GOOD || res.cn10k.uc_compcode) {
1245 : 0 : plt_err("LOAD FVC operation timed out");
1246 : 0 : goto exit;
1247 : : }
1248 : : } else {
1249 : : uint64_t lmt_arg, io_addr;
1250 : : uint16_t lmt_id;
1251 : :
1252 : 0 : hw_res->cn20k.compcode = CPT_COMP_NOT_DONE;
1253 : :
1254 : : /* Use this reserved LMT line as no one else is using it */
1255 : 0 : lmt_id = roc_plt_control_lmt_id_get();
1256 : 0 : lmt_base += ((uint64_t)lmt_id << ROC_LMT_LINE_SIZE_LOG2);
1257 : :
1258 : 0 : memcpy((void *)lmt_base, &inst, sizeof(inst));
1259 : :
1260 : : lmt_arg = ROC_CN20K_CPT_LMT_ARG | (uint64_t)lmt_id;
1261 : : io_addr = lf->io_addr | ROC_CN20K_CPT_INST_DW_M1 << 4;
1262 : :
1263 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
1264 : 0 : plt_io_wmb();
1265 : :
1266 : : /* Wait until CPT instruction completes */
1267 : : do {
1268 : 0 : res.u64[0] = __atomic_load_n(&hw_res->u64[0], __ATOMIC_RELAXED);
1269 [ # # ]: 0 : if (unlikely(plt_tsc_cycles() > timeout))
1270 : : break;
1271 [ # # ]: 0 : } while (res.cn20k.compcode == CPT_COMP_NOT_DONE);
1272 : :
1273 [ # # ]: 0 : if (res.cn20k.compcode != CPT_COMP_GOOD || res.cn20k.uc_compcode) {
1274 : 0 : plt_err("LOAD FVC operation timed out");
1275 : 0 : goto exit;
1276 : : }
1277 : : }
1278 : :
1279 [ # # ]: 0 : nix->cpt_eng_caps = plt_be_to_cpu_64(*rptr);
1280 : 0 : exit:
1281 : 0 : plt_free(rptr);
1282 : 0 : plt_free(hw_res);
1283 : : }
1284 : :
1285 : : static int
1286 : 0 : nix_inl_legacy_inb_init(struct roc_nix *roc_nix)
1287 : : {
1288 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1289 : : struct roc_cpt_inline_ipsec_inb_cfg cfg;
1290 : 0 : struct idev_cfg *idev = idev_get_cfg();
1291 : : uint16_t bpids[ROC_NIX_MAX_BPID_CNT];
1292 : : struct roc_cpt *roc_cpt;
1293 : : int rc;
1294 : :
1295 [ # # ]: 0 : if (idev == NULL)
1296 : : return -ENOTSUP;
1297 : :
1298 : : /* Unless we have another mechanism to trigger
1299 : : * onetime Inline config in CPTPF, we cannot
1300 : : * support without CPT being probed.
1301 : : */
1302 : 0 : roc_cpt = idev->cpt;
1303 [ # # ]: 0 : if (!roc_cpt) {
1304 : 0 : plt_err("Cannot support inline inbound, cryptodev not probed");
1305 : 0 : return -ENOTSUP;
1306 : : }
1307 : :
1308 [ # # ]: 0 : nix->ipsec_prof_id = 0;
1309 : : memset(&cfg, 0, sizeof(cfg));
1310 [ # # ]: 0 : if (roc_model_is_cn9k()) {
1311 : 0 : cfg.param1 = (ROC_ONF_IPSEC_INB_MAX_L2_SZ >> 3) & 0xf;
1312 : 0 : cfg.param2 = ROC_IE_ON_INB_IKEV2_SINGLE_SA_SUPPORT;
1313 : 0 : cfg.opcode =
1314 : : ((ROC_IE_ON_INB_MAX_CTX_LEN << 8) |
1315 : : (ROC_IE_ON_MAJOR_OP_PROCESS_INBOUND_IPSEC | (1 << 6)));
1316 : : } else {
1317 : : union roc_ot_ipsec_inb_param1 u;
1318 : :
1319 : : u.u16 = 0;
1320 : : u.s.esp_trailer_disable = 1;
1321 : 0 : cfg.param1 = u.u16;
1322 : : cfg.param2 = 0;
1323 : 0 : cfg.opcode = (ROC_IE_OT_MAJOR_OP_PROCESS_INBOUND_IPSEC | (1 << 6));
1324 : :
1325 [ # # ]: 0 : if (roc_nix->custom_inb_sa) {
1326 : 0 : cfg.param1 = roc_nix->inb_cfg_param1;
1327 : 0 : cfg.param2 = roc_nix->inb_cfg_param2;
1328 : : }
1329 : 0 : rc = roc_nix_bpids_alloc(roc_nix, ROC_NIX_INTF_TYPE_CPT_NIX, 1, bpids);
1330 [ # # ]: 0 : if (rc > 0) {
1331 : 0 : nix->cpt_nixbpid = bpids[0];
1332 : 0 : cfg.bpid = nix->cpt_nixbpid;
1333 : : }
1334 : :
1335 [ # # ]: 0 : if (roc_errata_cpt_has_ctx_fetch_issue()) {
1336 : 0 : cfg.ctx_ilen_valid = true;
1337 : 0 : cfg.ctx_ilen = (ROC_NIX_INL_OT_IPSEC_INB_HW_SZ / 128) - 1;
1338 : : }
1339 : : }
1340 : :
1341 : : /* Do onetime Inbound Inline config in CPTPF */
1342 : 0 : rc = roc_cpt_inline_ipsec_inb_cfg(roc_cpt, &cfg);
1343 [ # # ]: 0 : if (rc && rc != -EEXIST) {
1344 : 0 : plt_err("Failed to setup inbound lf, rc=%d", rc);
1345 : 0 : return rc;
1346 : : }
1347 : 0 : nix->cpt_eng_caps = roc_cpt->hw_caps[CPT_ENG_TYPE_SE].u;
1348 : :
1349 : : /* Setup Inbound SA table */
1350 : 0 : rc = nix_inl_inb_ipsec_sa_tbl_setup(roc_nix);
1351 [ # # ]: 0 : if (rc)
1352 : : return rc;
1353 : :
1354 [ # # # # ]: 0 : if (!roc_model_is_cn9k() && !roc_errata_nix_no_meta_aura()) {
1355 : 0 : nix->need_meta_aura = true;
1356 [ # # # # ]: 0 : if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
1357 : 0 : idev->inl_cfg.refs++;
1358 : : }
1359 : :
1360 : 0 : nix->inl_inb_ena = true;
1361 : 0 : return 0;
1362 : : }
1363 : :
1364 : : static int
1365 : 0 : nix_inl_inb_init(struct roc_nix *roc_nix)
1366 : : {
1367 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1368 : 0 : struct idev_cfg *idev = idev_get_cfg();
1369 : : struct nix_inl_dev *inl_dev;
1370 : : int rc;
1371 : :
1372 [ # # ]: 0 : if (idev == NULL)
1373 : : return -ENOTSUP;
1374 : :
1375 : 0 : inl_dev = idev->nix_inl_dev;
1376 : :
1377 [ # # # # ]: 0 : if (!inl_dev || !inl_dev->nb_inb_cptlfs) {
1378 : 0 : plt_err("Cannot support inline inbound without inline dev");
1379 : 0 : return -ENOTSUP;
1380 : : }
1381 : :
1382 : : /* FIXME get engine caps from inline device */
1383 : 0 : nix->cpt_eng_caps = 0;
1384 : :
1385 : : /* Setup Inbound SA table */
1386 : 0 : rc = nix_inl_inb_ipsec_sa_tbl_setup(roc_nix);
1387 [ # # ]: 0 : if (rc)
1388 : : return rc;
1389 : :
1390 [ # # ]: 0 : if (roc_nix->reass_ena) {
1391 : 0 : rc = nix_inl_reass_inb_sa_tbl_setup(roc_nix);
1392 [ # # ]: 0 : if (rc)
1393 : : return rc;
1394 : : }
1395 : :
1396 [ # # # # ]: 0 : if (roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena) {
1397 : 0 : nix->need_meta_aura = true;
1398 : :
1399 [ # # ]: 0 : if (roc_nix->custom_meta_aura_ena)
1400 : 0 : idev->inl_cfg.refs++;
1401 : : }
1402 : :
1403 : 0 : nix->inl_inb_ena = true;
1404 : 0 : return 0;
1405 : : }
1406 : :
1407 : : int
1408 [ # # ]: 0 : roc_nix_inl_inb_init(struct roc_nix *roc_nix)
1409 : : {
1410 [ # # # # ]: 0 : if (roc_model_is_cn9k() || roc_model_is_cn10k())
1411 : 0 : return nix_inl_legacy_inb_init(roc_nix);
1412 : :
1413 : 0 : return nix_inl_inb_init(roc_nix);
1414 : : }
1415 : : int
1416 : 0 : roc_nix_inl_inb_fini(struct roc_nix *roc_nix)
1417 : : {
1418 : 0 : struct idev_cfg *idev = idev_get_cfg();
1419 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1420 : : int rc;
1421 : :
1422 [ # # ]: 0 : if (!nix->inl_inb_ena)
1423 : : return 0;
1424 : :
1425 [ # # ]: 0 : if (!idev)
1426 : : return -EFAULT;
1427 : :
1428 : 0 : nix->inl_inb_ena = false;
1429 : :
1430 [ # # ]: 0 : if (nix->need_meta_aura) {
1431 : 0 : nix->need_meta_aura = false;
1432 [ # # # # ]: 0 : if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
1433 : 0 : idev->inl_cfg.refs--;
1434 : :
1435 [ # # ]: 0 : if (roc_nix->custom_meta_aura_ena)
1436 : 0 : nix_inl_custom_meta_aura_destroy(roc_nix);
1437 : :
1438 [ # # ]: 0 : if (!idev->inl_cfg.refs)
1439 : 0 : nix_inl_meta_aura_destroy(roc_nix);
1440 : : }
1441 : :
1442 [ # # ]: 0 : if (roc_feature_nix_has_inl_rq_mask()) {
1443 : 0 : rc = nix_inl_rq_mask_cfg(roc_nix, false);
1444 [ # # ]: 0 : if (rc) {
1445 : 0 : plt_err("Failed to get rq mask rc=%d", rc);
1446 : 0 : return rc;
1447 : : }
1448 : : }
1449 : :
1450 : : /* Flush Inbound CTX cache entries */
1451 : 0 : roc_nix_cpt_ctx_cache_sync(roc_nix);
1452 : :
1453 [ # # ]: 0 : if (roc_nix->reass_ena)
1454 : 0 : nix_inl_reass_sa_tbl_release(roc_nix);
1455 : :
1456 : : /* Disable Inbound SA */
1457 : 0 : return nix_inl_ipsec_sa_tbl_release(roc_nix);
1458 : : }
1459 : :
1460 : : int
1461 : 0 : roc_nix_inl_outb_init(struct roc_nix *roc_nix)
1462 : : {
1463 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1464 : 0 : struct idev_cfg *idev = idev_get_cfg();
1465 : : struct roc_cpt_lf *lf_base, *lf;
1466 : 0 : struct dev *dev = &nix->dev;
1467 : : struct msix_offset_rsp *rsp;
1468 : : struct nix_inl_dev *inl_dev;
1469 : : bool ctx_ilen_valid = false;
1470 : : size_t sa_sz, ring_sz;
1471 : : uint8_t ctx_ilen = 0;
1472 : : bool rx_inj = false;
1473 : : uint16_t sso_pffunc;
1474 : : uint8_t eng_grpmask;
1475 : : uint64_t blkaddr, i;
1476 : : uint64_t *ring_base;
1477 : : uint16_t nb_lf;
1478 : : void *sa_base;
1479 : : int j, rc;
1480 : : void *sa;
1481 : :
1482 [ # # ]: 0 : if (idev == NULL)
1483 : : return -ENOTSUP;
1484 : :
1485 : 0 : nb_lf = roc_nix->outb_nb_crypto_qs;
1486 [ # # ]: 0 : blkaddr = nix->is_nix1 ? RVU_BLOCK_ADDR_CPT1 : RVU_BLOCK_ADDR_CPT0;
1487 : :
1488 : : /* Retrieve inline device if present */
1489 : 0 : inl_dev = idev->nix_inl_dev;
1490 [ # # # # : 0 : if (roc_nix->rx_inj_ena && !(nix->inb_inl_dev && inl_dev && inl_dev->attach_cptlf &&
# # # # ]
1491 [ # # ]: 0 : inl_dev->rx_inj_ena)) {
1492 : 0 : nb_lf++;
1493 : : rx_inj = true;
1494 : : }
1495 : :
1496 [ # # ]: 0 : sso_pffunc = inl_dev ? inl_dev->dev.pf_func : idev_sso_pffunc_get();
1497 : : /* Use sso_pffunc if explicitly requested */
1498 [ # # ]: 0 : if (roc_nix->ipsec_out_sso_pffunc)
1499 : 0 : sso_pffunc = idev_sso_pffunc_get();
1500 : :
1501 [ # # ]: 0 : if (!sso_pffunc) {
1502 : 0 : plt_err("Failed to setup inline outb, need either "
1503 : : "inline device or sso device");
1504 : 0 : return -ENOTSUP;
1505 : : }
1506 : :
1507 : : /* Attach CPT LF for outbound */
1508 : 0 : rc = cpt_lfs_attach(dev, blkaddr, true, nb_lf);
1509 [ # # ]: 0 : if (rc) {
1510 : 0 : plt_err("Failed to attach CPT LF for inline outb, rc=%d", rc);
1511 : 0 : return rc;
1512 : : }
1513 : :
1514 [ # # # # ]: 0 : if (!roc_model_is_cn9k() && roc_errata_cpt_has_ctx_fetch_issue()) {
1515 : : ctx_ilen = (ROC_NIX_INL_OT_IPSEC_OUTB_HW_SZ / 128) - 1;
1516 : : ctx_ilen_valid = true;
1517 : : }
1518 : :
1519 [ # # # # ]: 0 : if (roc_model_is_cn9k() || roc_model_is_cn10k())
1520 : : eng_grpmask = (1ULL << ROC_LEGACY_CPT_DFLT_ENG_GRP_SE |
1521 : : 1ULL << ROC_LEGACY_CPT_DFLT_ENG_GRP_SE_IE |
1522 : : 1ULL << ROC_LEGACY_CPT_DFLT_ENG_GRP_AE);
1523 : : else
1524 : : eng_grpmask = (1ULL << ROC_CPT_DFLT_ENG_GRP_SE | 1ULL << ROC_CPT_DFLT_ENG_GRP_AE);
1525 : :
1526 : : /* Alloc CPT LF */
1527 : 0 : rc = cpt_lfs_alloc(dev, eng_grpmask, blkaddr,
1528 : 0 : !roc_nix->ipsec_out_sso_pffunc, ctx_ilen_valid, ctx_ilen,
1529 : 0 : rx_inj, nb_lf - 1);
1530 [ # # ]: 0 : if (rc) {
1531 : 0 : plt_err("Failed to alloc CPT LF resources, rc=%d", rc);
1532 : 0 : goto lf_detach;
1533 : : }
1534 : :
1535 : : /* Get msix offsets */
1536 : 0 : rc = cpt_get_msix_offset(dev, &rsp);
1537 [ # # ]: 0 : if (rc) {
1538 : 0 : plt_err("Failed to get CPT LF msix offset, rc=%d", rc);
1539 : 0 : goto lf_free;
1540 : : }
1541 : :
1542 : 0 : mbox_memcpy(nix->cpt_msixoff,
1543 [ # # ]: 0 : nix->is_nix1 ? rsp->cpt1_lf_msixoff : rsp->cptlf_msixoff,
1544 : : sizeof(nix->cpt_msixoff));
1545 : :
1546 : : /* Alloc required num of cpt lfs */
1547 : 0 : lf_base = plt_zmalloc(nb_lf * sizeof(struct roc_cpt_lf), 0);
1548 [ # # ]: 0 : if (!lf_base) {
1549 : 0 : plt_err("Failed to alloc cpt lf memory");
1550 : : rc = -ENOMEM;
1551 : 0 : goto lf_free;
1552 : : }
1553 : :
1554 : : /* Initialize CPT LF's */
1555 [ # # ]: 0 : for (i = 0; i < nb_lf; i++) {
1556 : 0 : lf = &lf_base[i];
1557 : :
1558 : 0 : lf->lf_id = i;
1559 : 0 : lf->nb_desc = roc_nix->outb_nb_desc;
1560 : 0 : lf->dev = &nix->dev;
1561 : 0 : lf->msixoff = nix->cpt_msixoff[i];
1562 : 0 : lf->pci_dev = nix->pci_dev;
1563 : :
1564 : : /* Setup CPT LF instruction queue */
1565 : 0 : rc = cpt_lf_init(lf);
1566 [ # # ]: 0 : if (rc) {
1567 : 0 : plt_err("Failed to initialize CPT LF, rc=%d", rc);
1568 : 0 : goto lf_fini;
1569 : : }
1570 : :
1571 : : /* Associate this CPT LF with NIX PFFUNC */
1572 : 0 : rc = cpt_lf_outb_cfg(dev, sso_pffunc, nix->dev.pf_func, i,
1573 : : true);
1574 [ # # ]: 0 : if (rc) {
1575 : 0 : plt_err("Failed to setup CPT LF->(NIX,SSO) link, rc=%d",
1576 : : rc);
1577 : 0 : goto lf_fini;
1578 : : }
1579 : :
1580 : : /* Enable IQ */
1581 : 0 : roc_cpt_iq_enable(lf);
1582 : : }
1583 : :
1584 [ # # ]: 0 : if (!roc_nix->ipsec_out_max_sa)
1585 : 0 : goto skip_sa_alloc;
1586 : :
1587 : : /* CN9K SA size is different */
1588 : : if (roc_model_is_cn9k())
1589 : : sa_sz = ROC_NIX_INL_ON_IPSEC_OUTB_SA_SZ;
1590 : : else if (roc_model_is_cn10k())
1591 : : sa_sz = ROC_NIX_INL_OT_IPSEC_OUTB_SA_SZ;
1592 : : else
1593 : : sa_sz = ROC_NIX_INL_OW_IPSEC_OUTB_SA_SZ;
1594 : :
1595 : : /* Alloc contiguous memory of outbound SA */
1596 : 0 : sa_base = plt_zmalloc(sa_sz * roc_nix->ipsec_out_max_sa,
1597 : : ROC_NIX_INL_SA_BASE_ALIGN);
1598 [ # # ]: 0 : if (!sa_base) {
1599 : 0 : plt_err("Outbound SA base alloc failed");
1600 : 0 : goto lf_fini;
1601 : : }
1602 : :
1603 [ # # ]: 0 : if (!roc_model_is_cn9k()) {
1604 [ # # ]: 0 : for (i = 0; i < roc_nix->ipsec_out_max_sa; i++) {
1605 [ # # ]: 0 : sa = ((uint8_t *)sa_base) + (i * sa_sz);
1606 [ # # ]: 0 : if (roc_model_is_cn10k())
1607 : 0 : roc_ot_ipsec_outb_sa_init(sa);
1608 : : else
1609 : 0 : roc_ow_ipsec_outb_sa_init(sa);
1610 : : }
1611 : : }
1612 : 0 : nix->outb_sa_base = sa_base;
1613 : 0 : nix->outb_sa_sz = sa_sz;
1614 : :
1615 : 0 : skip_sa_alloc:
1616 : :
1617 : 0 : nix->cpt_lf_base = lf_base;
1618 : 0 : nix->nb_cpt_lf = nb_lf;
1619 : 0 : nix->outb_err_sso_pffunc = sso_pffunc;
1620 : 0 : nix->inl_outb_ena = true;
1621 : 0 : nix->outb_se_ring_cnt =
1622 : 0 : roc_nix->ipsec_out_max_sa / ROC_IPSEC_ERR_RING_MAX_ENTRY + 1;
1623 : 0 : nix->outb_se_ring_base =
1624 : 0 : roc_nix->port_id * ROC_NIX_SOFT_EXP_PER_PORT_MAX_RINGS;
1625 : :
1626 [ # # # # ]: 0 : if (inl_dev == NULL || !inl_dev->set_soft_exp_poll) {
1627 : 0 : nix->outb_se_ring_cnt = 0;
1628 : 0 : return 0;
1629 : : }
1630 : :
1631 : : /* Allocate memory to be used as a ring buffer to poll for
1632 : : * soft expiry event from ucode
1633 : : */
1634 : : ring_sz = (ROC_IPSEC_ERR_RING_MAX_ENTRY + 1) * sizeof(uint64_t);
1635 : 0 : ring_base = inl_dev->sa_soft_exp_ring;
1636 [ # # ]: 0 : for (i = 0; i < nix->outb_se_ring_cnt; i++) {
1637 : 0 : ring_base[nix->outb_se_ring_base + i] =
1638 : 0 : PLT_U64_CAST(plt_zmalloc(ring_sz, 0));
1639 [ # # ]: 0 : if (!ring_base[nix->outb_se_ring_base + i]) {
1640 : 0 : plt_err("Couldn't allocate memory for soft exp ring");
1641 [ # # ]: 0 : while (i--)
1642 : 0 : plt_free(PLT_PTR_CAST(
1643 : : ring_base[nix->outb_se_ring_base + i]));
1644 : : rc = -ENOMEM;
1645 : 0 : goto lf_fini;
1646 : : }
1647 : : }
1648 : :
1649 : : /* Fetch engine capabilities */
1650 : 0 : nix_inl_eng_caps_get(nix);
1651 : 0 : return 0;
1652 : :
1653 : 0 : lf_fini:
1654 [ # # ]: 0 : for (j = i - 1; j >= 0; j--)
1655 : 0 : cpt_lf_fini(&lf_base[j]);
1656 : 0 : plt_free(lf_base);
1657 : 0 : lf_free:
1658 : 0 : rc |= cpt_lfs_free(dev);
1659 : 0 : lf_detach:
1660 : 0 : rc |= cpt_lfs_detach(dev);
1661 : 0 : return rc;
1662 : : }
1663 : :
1664 : : int
1665 : 0 : roc_nix_inl_outb_fini(struct roc_nix *roc_nix)
1666 : : {
1667 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1668 : 0 : struct roc_cpt_lf *lf_base = nix->cpt_lf_base;
1669 : 0 : struct idev_cfg *idev = idev_get_cfg();
1670 : 0 : struct dev *dev = &nix->dev;
1671 : : struct nix_inl_dev *inl_dev;
1672 : : uint64_t *ring_base;
1673 : : int i, rc, ret = 0;
1674 : :
1675 [ # # ]: 0 : if (!nix->inl_outb_ena)
1676 : : return 0;
1677 : :
1678 : 0 : nix->inl_outb_ena = false;
1679 : :
1680 : : /* Cleanup CPT LF instruction queue */
1681 [ # # ]: 0 : for (i = 0; i < nix->nb_cpt_lf; i++)
1682 : 0 : cpt_lf_fini(&lf_base[i]);
1683 : :
1684 : : /* Free LF resources */
1685 : 0 : rc = cpt_lfs_free(dev);
1686 [ # # ]: 0 : if (rc)
1687 : 0 : plt_err("Failed to free CPT LF resources, rc=%d", rc);
1688 : : ret |= rc;
1689 : :
1690 : : /* Detach LF */
1691 : 0 : rc = cpt_lfs_detach(dev);
1692 [ # # ]: 0 : if (rc)
1693 : 0 : plt_err("Failed to detach CPT LF, rc=%d", rc);
1694 : :
1695 : : /* Free LF memory */
1696 : 0 : plt_free(lf_base);
1697 : 0 : nix->cpt_lf_base = NULL;
1698 : 0 : nix->nb_cpt_lf = 0;
1699 : :
1700 : : /* Free outbound SA base */
1701 : 0 : plt_free(nix->outb_sa_base);
1702 : 0 : nix->outb_sa_base = NULL;
1703 : :
1704 [ # # # # : 0 : if (idev && idev->nix_inl_dev && nix->outb_se_ring_cnt) {
# # ]
1705 : : inl_dev = idev->nix_inl_dev;
1706 : 0 : ring_base = inl_dev->sa_soft_exp_ring;
1707 : 0 : ring_base += nix->outb_se_ring_base;
1708 : :
1709 [ # # ]: 0 : for (i = 0; i < nix->outb_se_ring_cnt; i++) {
1710 [ # # ]: 0 : if (ring_base[i])
1711 : 0 : plt_free(PLT_PTR_CAST(ring_base[i]));
1712 : : }
1713 : : }
1714 : :
1715 : 0 : ret |= rc;
1716 : 0 : return ret;
1717 : : }
1718 : :
1719 : : bool
1720 : 0 : roc_nix_inl_dev_is_probed(void)
1721 : : {
1722 : 0 : struct idev_cfg *idev = idev_get_cfg();
1723 : :
1724 [ # # ]: 0 : if (idev == NULL)
1725 : : return 0;
1726 : :
1727 : 0 : return !!idev->nix_inl_dev;
1728 : : }
1729 : :
1730 : : bool
1731 : 0 : roc_nix_inl_dev_is_multi_channel(void)
1732 : : {
1733 : 0 : struct idev_cfg *idev = idev_get_cfg();
1734 : : struct nix_inl_dev *inl_dev;
1735 : :
1736 [ # # # # ]: 0 : if (idev == NULL || !idev->nix_inl_dev)
1737 : : return false;
1738 : :
1739 : : inl_dev = idev->nix_inl_dev;
1740 : 0 : return inl_dev->is_multi_channel;
1741 : : }
1742 : :
1743 : : bool
1744 : 0 : roc_nix_inl_inb_is_enabled(struct roc_nix *roc_nix)
1745 : : {
1746 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1747 : :
1748 : 0 : return nix->inl_inb_ena;
1749 : : }
1750 : :
1751 : : bool
1752 : 0 : roc_nix_inl_outb_is_enabled(struct roc_nix *roc_nix)
1753 : : {
1754 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1755 : :
1756 : 0 : return nix->inl_outb_ena;
1757 : : }
1758 : :
1759 : : int
1760 : 0 : roc_nix_inl_dev_rq_get(struct roc_nix_rq *rq, bool enable)
1761 : : {
1762 : 0 : struct nix *nix = roc_nix_to_nix_priv(rq->roc_nix);
1763 : 0 : struct idev_cfg *idev = idev_get_cfg();
1764 : 0 : int port_id = rq->roc_nix->port_id;
1765 : : struct nix_inl_dev *inl_dev;
1766 : : struct roc_nix_rq *inl_rq;
1767 : : uint16_t inl_rq_id;
1768 : : struct mbox *mbox;
1769 : : struct dev *dev;
1770 : : int rc;
1771 : :
1772 [ # # ]: 0 : if (idev == NULL)
1773 : : return 0;
1774 : :
1775 : : /* Update meta aura handle in RQ */
1776 [ # # ]: 0 : if (nix->need_meta_aura)
1777 : 0 : rq->meta_aura_handle = roc_npa_zero_aura_handle();
1778 : :
1779 : 0 : inl_dev = idev->nix_inl_dev;
1780 : : /* Nothing to do if no inline device */
1781 [ # # ]: 0 : if (!inl_dev)
1782 : : return 0;
1783 : :
1784 : : /* Check if this RQ is already holding reference */
1785 [ # # ]: 0 : if (rq->inl_dev_refs)
1786 : : return 0;
1787 : :
1788 [ # # ]: 0 : inl_rq_id = inl_dev->nb_rqs > 1 ? port_id : 0;
1789 : 0 : dev = &inl_dev->dev;
1790 : 0 : inl_rq = &inl_dev->rqs[inl_rq_id];
1791 : :
1792 : : /* Just take reference if already inited */
1793 [ # # ]: 0 : if (inl_rq->inl_dev_refs) {
1794 : 0 : inl_rq->inl_dev_refs++;
1795 : 0 : rq->inl_dev_refs = 1;
1796 : 0 : return 0;
1797 : : }
1798 : : memset(inl_rq, 0, sizeof(struct roc_nix_rq));
1799 : :
1800 : : /* Take RQ pool attributes from the first ethdev RQ */
1801 : 0 : inl_rq->qid = inl_rq_id;
1802 : 0 : inl_rq->aura_handle = rq->aura_handle;
1803 : 0 : inl_rq->first_skip = rq->first_skip;
1804 : 0 : inl_rq->later_skip = rq->later_skip;
1805 : 0 : inl_rq->lpb_size = rq->lpb_size;
1806 : 0 : inl_rq->spb_ena = rq->spb_ena;
1807 : 0 : inl_rq->spb_aura_handle = rq->spb_aura_handle;
1808 [ # # ]: 0 : inl_rq->spb_size = rq->spb_size;
1809 : :
1810 [ # # ]: 0 : if (roc_errata_nix_no_meta_aura()) {
1811 : : uint64_t aura_limit =
1812 : : roc_npa_aura_op_limit_get(inl_rq->aura_handle);
1813 : : uint64_t aura_shift = plt_log2_u32(aura_limit);
1814 : : uint64_t aura_drop, drop_pc;
1815 : :
1816 : 0 : inl_rq->lpb_drop_ena = true;
1817 : :
1818 : : if (aura_shift < 8)
1819 : : aura_shift = 0;
1820 : : else
1821 : : aura_shift = aura_shift - 8;
1822 : :
1823 : : /* Set first pass RQ to drop after part of buffers are in
1824 : : * use to avoid metabuf alloc failure. This is needed as long
1825 : : * as we cannot use different aura.
1826 : : */
1827 : : drop_pc = inl_dev->lpb_drop_pc;
1828 : : aura_drop = ((aura_limit * drop_pc) / 100) >> aura_shift;
1829 : 0 : roc_npa_aura_drop_set(inl_rq->aura_handle, aura_drop, true);
1830 : : }
1831 : :
1832 [ # # # # ]: 0 : if (roc_errata_nix_no_meta_aura() && inl_rq->spb_ena) {
1833 : : uint64_t aura_limit =
1834 : 0 : roc_npa_aura_op_limit_get(inl_rq->spb_aura_handle);
1835 : : uint64_t aura_shift = plt_log2_u32(aura_limit);
1836 : : uint64_t aura_drop, drop_pc;
1837 : :
1838 : 0 : inl_rq->spb_drop_ena = true;
1839 : :
1840 : : if (aura_shift < 8)
1841 : : aura_shift = 0;
1842 : : else
1843 : : aura_shift = aura_shift - 8;
1844 : :
1845 : : /* Set first pass RQ to drop after part of buffers are in
1846 : : * use to avoid metabuf alloc failure. This is needed as long
1847 : : * as we cannot use different aura.
1848 : : */
1849 : : drop_pc = inl_dev->spb_drop_pc;
1850 : : aura_drop = ((aura_limit * drop_pc) / 100) >> aura_shift;
1851 : 0 : roc_npa_aura_drop_set(inl_rq->spb_aura_handle, aura_drop, true);
1852 : : }
1853 : :
1854 : : /* Enable IPSec */
1855 : 0 : inl_rq->ipsech_ena = true;
1856 : :
1857 : 0 : inl_rq->flow_tag_width = 20;
1858 : : /* Special tag mask */
1859 : 0 : inl_rq->tag_mask = rq->tag_mask;
1860 : 0 : inl_rq->tt = SSO_TT_ORDERED;
1861 : 0 : inl_rq->hwgrp = 0;
1862 : 0 : inl_rq->wqe_skip = inl_dev->wqe_skip;
1863 : 0 : inl_rq->sso_ena = true;
1864 : :
1865 : : /* Prepare and send RQ init mbox */
1866 : 0 : mbox = mbox_get(dev->mbox);
1867 [ # # ]: 0 : if (roc_model_is_cn9k())
1868 : 0 : rc = nix_rq_cn9k_cfg(dev, inl_rq, inl_dev->qints, false, enable);
1869 [ # # ]: 0 : else if (roc_model_is_cn10k())
1870 : 0 : rc = nix_rq_cn10k_cfg(dev, inl_rq, inl_dev->qints, false, enable);
1871 : : else
1872 : 0 : rc = nix_rq_cfg(dev, inl_rq, inl_dev->qints, false, enable);
1873 [ # # ]: 0 : if (rc) {
1874 : 0 : plt_err("Failed to prepare aq_enq msg, rc=%d", rc);
1875 : : mbox_put(mbox);
1876 : 0 : return rc;
1877 : : }
1878 : :
1879 : 0 : rc = mbox_process(dev->mbox);
1880 [ # # ]: 0 : if (rc) {
1881 : 0 : plt_err("Failed to send aq_enq msg, rc=%d", rc);
1882 : : mbox_put(mbox);
1883 : 0 : return rc;
1884 : : }
1885 : : mbox_put(mbox);
1886 : :
1887 : : /* Check meta aura */
1888 [ # # # # ]: 0 : if (enable && nix->need_meta_aura) {
1889 : 0 : rc = roc_nix_inl_meta_aura_check(rq->roc_nix, rq);
1890 [ # # ]: 0 : if (rc)
1891 : : return rc;
1892 : : }
1893 : :
1894 : 0 : inl_rq->inl_dev_refs++;
1895 : 0 : rq->inl_dev_refs = 1;
1896 : 0 : return 0;
1897 : : }
1898 : :
1899 : : int
1900 : 0 : roc_nix_inl_dev_rq_put(struct roc_nix_rq *rq)
1901 : : {
1902 : 0 : struct idev_cfg *idev = idev_get_cfg();
1903 : 0 : int port_id = rq->roc_nix->port_id;
1904 : : struct nix_inl_dev *inl_dev;
1905 : : struct roc_nix_rq *inl_rq;
1906 : : uint16_t inl_rq_id;
1907 : : struct dev *dev;
1908 : : int rc;
1909 : :
1910 [ # # ]: 0 : if (idev == NULL)
1911 : : return 0;
1912 : :
1913 : 0 : rq->meta_aura_handle = 0;
1914 [ # # ]: 0 : if (!rq->inl_dev_refs)
1915 : : return 0;
1916 : :
1917 : 0 : inl_dev = idev->nix_inl_dev;
1918 : : /* Inline device should be there if we have ref */
1919 [ # # ]: 0 : if (!inl_dev) {
1920 : 0 : plt_err("Failed to find inline device with refs");
1921 : 0 : return -EFAULT;
1922 : : }
1923 : :
1924 : 0 : dev = &inl_dev->dev;
1925 [ # # ]: 0 : inl_rq_id = inl_dev->nb_rqs > 1 ? port_id : 0;
1926 : 0 : inl_rq = &inl_dev->rqs[inl_rq_id];
1927 : :
1928 : 0 : rq->inl_dev_refs = 0;
1929 : 0 : inl_rq->inl_dev_refs--;
1930 [ # # ]: 0 : if (inl_rq->inl_dev_refs)
1931 : : return 0;
1932 : :
1933 : : /* There are no more references, disable RQ */
1934 : 0 : rc = nix_rq_ena_dis(dev, inl_rq, false);
1935 [ # # ]: 0 : if (rc)
1936 : 0 : plt_err("Failed to disable inline device rq, rc=%d", rc);
1937 : :
1938 : 0 : roc_npa_aura_drop_set(inl_rq->aura_handle, 0, false);
1939 [ # # ]: 0 : if (inl_rq->spb_ena)
1940 : 0 : roc_npa_aura_drop_set(inl_rq->spb_aura_handle, 0, false);
1941 : :
1942 : : /* Flush NIX LF for CN10K */
1943 : 0 : nix_rq_vwqe_flush(rq, inl_dev->vwqe_interval);
1944 : :
1945 : 0 : return rc;
1946 : : }
1947 : :
1948 : : int
1949 : 0 : roc_nix_inl_rq_ena_dis(struct roc_nix *roc_nix, bool enable)
1950 : : {
1951 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1952 : 0 : struct roc_nix_rq *inl_rq = roc_nix_inl_dev_rq(roc_nix);
1953 : 0 : struct idev_cfg *idev = idev_get_cfg();
1954 : : struct nix_inl_dev *inl_dev;
1955 : : int rc;
1956 : :
1957 [ # # ]: 0 : if (!idev)
1958 : : return -EFAULT;
1959 : :
1960 [ # # # # ]: 0 : if (roc_feature_nix_has_inl_rq_mask() && enable) {
1961 : 0 : rc = nix_inl_rq_mask_cfg(roc_nix, enable);
1962 [ # # ]: 0 : if (rc) {
1963 : 0 : plt_err("Failed to get rq mask rc=%d", rc);
1964 : 0 : return rc;
1965 : : }
1966 : : }
1967 : :
1968 [ # # ]: 0 : if (nix->inb_inl_dev) {
1969 [ # # # # ]: 0 : if (!inl_rq || !idev->nix_inl_dev)
1970 : : return -EFAULT;
1971 : :
1972 : : inl_dev = idev->nix_inl_dev;
1973 : :
1974 : 0 : rc = nix_rq_ena_dis(&inl_dev->dev, inl_rq, enable);
1975 [ # # ]: 0 : if (rc)
1976 : : return rc;
1977 : :
1978 [ # # # # ]: 0 : if (enable && nix->need_meta_aura)
1979 : 0 : return roc_nix_inl_meta_aura_check(roc_nix, inl_rq);
1980 : : }
1981 : : return 0;
1982 : : }
1983 : :
1984 : : void
1985 : 0 : roc_nix_inb_mode_set(struct roc_nix *roc_nix, bool use_inl_dev)
1986 : : {
1987 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1988 : :
1989 : : /* Info used by NPC flow rule add */
1990 : 0 : nix->inb_inl_dev = use_inl_dev;
1991 : 0 : }
1992 : :
1993 : : void
1994 : 0 : roc_nix_inl_inb_set(struct roc_nix *roc_nix, bool ena)
1995 : : {
1996 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1997 : 0 : struct idev_cfg *idev = idev_get_cfg();
1998 : :
1999 [ # # ]: 0 : if (!idev)
2000 : : return;
2001 : : /* Need to set here for cases when inbound SA table is
2002 : : * managed outside RoC.
2003 : : */
2004 [ # # ]: 0 : nix->inl_inb_ena = ena;
2005 : :
2006 [ # # # # ]: 0 : if (roc_model_is_cn9k() || roc_errata_nix_no_meta_aura())
2007 : : return;
2008 : :
2009 [ # # ]: 0 : if (ena) {
2010 : 0 : nix->need_meta_aura = true;
2011 [ # # # # ]: 0 : if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
2012 : 0 : idev->inl_cfg.refs++;
2013 [ # # ]: 0 : } else if (nix->need_meta_aura) {
2014 : 0 : nix->need_meta_aura = false;
2015 [ # # # # ]: 0 : if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
2016 : 0 : idev->inl_cfg.refs--;
2017 : :
2018 [ # # ]: 0 : if (roc_nix->custom_meta_aura_ena)
2019 : 0 : nix_inl_custom_meta_aura_destroy(roc_nix);
2020 : :
2021 [ # # ]: 0 : if (!idev->inl_cfg.refs)
2022 : 0 : nix_inl_meta_aura_destroy(roc_nix);
2023 : : }
2024 : : }
2025 : :
2026 : : int
2027 : 0 : roc_nix_inl_outb_soft_exp_poll_switch(struct roc_nix *roc_nix, bool poll)
2028 : : {
2029 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
2030 : 0 : struct idev_cfg *idev = idev_get_cfg();
2031 : : struct nix_inl_dev *inl_dev;
2032 : : uint16_t ring_idx, i;
2033 : :
2034 [ # # # # ]: 0 : if (!idev || !idev->nix_inl_dev)
2035 : : return 0;
2036 : :
2037 : : inl_dev = idev->nix_inl_dev;
2038 : :
2039 [ # # ]: 0 : for (i = 0; i < nix->outb_se_ring_cnt; i++) {
2040 : 0 : ring_idx = nix->outb_se_ring_base + i;
2041 : :
2042 [ # # ]: 0 : if (poll)
2043 : 0 : plt_bitmap_set(inl_dev->soft_exp_ring_bmap, ring_idx);
2044 : : else
2045 : 0 : plt_bitmap_clear(inl_dev->soft_exp_ring_bmap, ring_idx);
2046 : : }
2047 : :
2048 [ # # ]: 0 : if (poll)
2049 : 0 : soft_exp_consumer_cnt++;
2050 : : else
2051 : 0 : soft_exp_consumer_cnt--;
2052 : :
2053 : : return 0;
2054 : : }
2055 : :
2056 : : bool
2057 : 0 : roc_nix_inb_is_with_inl_dev(struct roc_nix *roc_nix)
2058 : : {
2059 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
2060 : :
2061 : 0 : return nix->inb_inl_dev;
2062 : : }
2063 : :
2064 : : struct roc_nix_rq *
2065 : 0 : roc_nix_inl_dev_rq(struct roc_nix *roc_nix)
2066 : : {
2067 : 0 : struct idev_cfg *idev = idev_get_cfg();
2068 : 0 : int port_id = roc_nix->port_id;
2069 : : struct nix_inl_dev *inl_dev;
2070 : : struct roc_nix_rq *inl_rq;
2071 : : uint16_t inl_rq_id;
2072 : :
2073 [ # # ]: 0 : if (idev != NULL) {
2074 : 0 : inl_dev = idev->nix_inl_dev;
2075 [ # # ]: 0 : if (inl_dev != NULL) {
2076 [ # # ]: 0 : inl_rq_id = inl_dev->nb_rqs > 1 ? port_id : 0;
2077 : 0 : inl_rq = &inl_dev->rqs[inl_rq_id];
2078 [ # # ]: 0 : if (inl_rq->inl_dev_refs)
2079 : 0 : return inl_rq;
2080 : : }
2081 : : }
2082 : :
2083 : : return NULL;
2084 : : }
2085 : :
2086 : : uint16_t __roc_api
2087 : 0 : roc_nix_inl_outb_sso_pffunc_get(struct roc_nix *roc_nix)
2088 : : {
2089 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
2090 : :
2091 : 0 : return nix->outb_err_sso_pffunc;
2092 : : }
2093 : :
2094 : : int
2095 : 0 : roc_nix_inl_cb_register(roc_nix_inl_sso_work_cb_t cb, void *args)
2096 : : {
2097 : 0 : struct idev_cfg *idev = idev_get_cfg();
2098 : : struct nix_inl_dev *inl_dev;
2099 : :
2100 [ # # ]: 0 : if (idev == NULL)
2101 : : return -EIO;
2102 : :
2103 : 0 : inl_dev = idev->nix_inl_dev;
2104 [ # # ]: 0 : if (!inl_dev)
2105 : : return -EIO;
2106 : :
2107 : : /* Be silent if registration called with same cb and args */
2108 [ # # # # ]: 0 : if (inl_dev->work_cb == cb && inl_dev->cb_args == args)
2109 : : return 0;
2110 : :
2111 : : /* Don't allow registration again if registered with different cb */
2112 [ # # ]: 0 : if (inl_dev->work_cb)
2113 : : return -EBUSY;
2114 : :
2115 : 0 : inl_dev->work_cb = cb;
2116 : 0 : inl_dev->cb_args = args;
2117 : 0 : return 0;
2118 : : }
2119 : :
2120 : : int
2121 : 0 : roc_nix_inl_cb_unregister(roc_nix_inl_sso_work_cb_t cb, void *args)
2122 : : {
2123 : 0 : struct idev_cfg *idev = idev_get_cfg();
2124 : : struct nix_inl_dev *inl_dev;
2125 : :
2126 [ # # ]: 0 : if (idev == NULL)
2127 : : return -ENOENT;
2128 : :
2129 : 0 : inl_dev = idev->nix_inl_dev;
2130 [ # # ]: 0 : if (!inl_dev)
2131 : : return -ENOENT;
2132 : :
2133 [ # # # # ]: 0 : if (inl_dev->work_cb != cb || inl_dev->cb_args != args)
2134 : : return -EINVAL;
2135 : :
2136 : 0 : inl_dev->work_cb = NULL;
2137 : 0 : inl_dev->cb_args = NULL;
2138 : 0 : return 0;
2139 : : }
2140 : :
2141 : : int
2142 : 0 : roc_nix_inl_inb_tag_update(struct roc_nix *roc_nix, uint32_t tag_const,
2143 : : uint8_t tt)
2144 : : {
2145 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
2146 : : struct roc_nix_ipsec_cfg cfg;
2147 : :
2148 : : /* Be silent if inline inbound not enabled */
2149 [ # # ]: 0 : if (!nix->inl_inb_ena)
2150 : : return 0;
2151 : :
2152 : : memset(&cfg, 0, sizeof(cfg));
2153 : 0 : cfg.sa_size = nix->inb_sa_sz[nix->ipsec_prof_id];
2154 : 0 : cfg.iova = (uintptr_t)nix->inb_sa_base[nix->ipsec_prof_id];
2155 : 0 : cfg.max_sa = nix->inb_spi_mask + 1;
2156 : 0 : cfg.tt = tt;
2157 : 0 : cfg.tag_const = tag_const;
2158 : :
2159 : 0 : return roc_nix_lf_inl_ipsec_cfg(roc_nix, &cfg, true);
2160 : : }
2161 : :
2162 : : int
2163 : 0 : roc_nix_inl_sa_sync(struct roc_nix *roc_nix, void *sa, bool inb,
2164 : : enum roc_nix_inl_sa_sync_op op)
2165 : : {
2166 : 0 : struct idev_cfg *idev = idev_get_cfg();
2167 : : struct nix_inl_dev *inl_dev = NULL;
2168 : : struct roc_cpt_lf *outb_lf = NULL;
2169 : : union cpt_lf_ctx_reload reload;
2170 : : union cpt_lf_ctx_flush flush;
2171 : : union cpt_lf_ctx_err err;
2172 : : union cpt_lf_ctx_inval inval;
2173 : : bool get_inl_lf = true;
2174 : : uintptr_t rbase;
2175 : : struct nix *nix;
2176 : :
2177 : : /* Nothing much to do on cn9k */
2178 [ # # ]: 0 : if (roc_model_is_cn9k()) {
2179 : : plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
2180 : 0 : return 0;
2181 : : }
2182 : :
2183 [ # # ]: 0 : if (idev)
2184 : 0 : inl_dev = idev->nix_inl_dev;
2185 : :
2186 [ # # ]: 0 : if (!inl_dev && roc_nix == NULL)
2187 : : return -EINVAL;
2188 : :
2189 [ # # ]: 0 : if (roc_nix) {
2190 : : nix = roc_nix_to_nix_priv(roc_nix);
2191 : 0 : outb_lf = nix->cpt_lf_base;
2192 [ # # # # ]: 0 : if (inb && !nix->inb_inl_dev)
2193 : : get_inl_lf = false;
2194 : : }
2195 : :
2196 [ # # ]: 0 : if (inb && get_inl_lf) {
2197 : : outb_lf = NULL;
2198 [ # # # # ]: 0 : if (inl_dev && inl_dev->attach_cptlf)
2199 : 0 : outb_lf = &inl_dev->cpt_lf[0];
2200 : : }
2201 : :
2202 [ # # ]: 0 : if (outb_lf) {
2203 : 0 : rbase = outb_lf->rbase;
2204 : :
2205 : 0 : flush.u = 0;
2206 : 0 : reload.u = 0;
2207 : 0 : inval.u = 0;
2208 [ # # # # ]: 0 : switch (op) {
2209 : : case ROC_NIX_INL_SA_OP_FLUSH_INVAL:
2210 [ # # ]: 0 : if (!roc_model_is_cn10k()) {
2211 : 0 : inval.s.cptr = ((uintptr_t)sa) >> 7;
2212 : 0 : plt_write64(inval.u, rbase + CPT_LF_CTX_INVAL);
2213 : : break;
2214 : : }
2215 : :
2216 : 0 : flush.s.inval = 1;
2217 : : /* fall through */
2218 : 0 : case ROC_NIX_INL_SA_OP_FLUSH:
2219 : 0 : flush.s.cptr = ((uintptr_t)sa) >> 7;
2220 [ # # ]: 0 : plt_write64(flush.u, rbase + CPT_LF_CTX_FLUSH);
2221 : : plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
2222 : : /* Read a CSR to ensure that the FLUSH operation is complete */
2223 [ # # ]: 0 : err.u = plt_read64(rbase + CPT_LF_CTX_ERR);
2224 : :
2225 [ # # ]: 0 : if (err.s.flush_st_flt) {
2226 : 0 : plt_warn("CTX flush could not complete");
2227 : 0 : return -EIO;
2228 : : }
2229 : : break;
2230 : 0 : case ROC_NIX_INL_SA_OP_RELOAD:
2231 : 0 : reload.s.cptr = ((uintptr_t)sa) >> 7;
2232 : 0 : plt_write64(reload.u, rbase + CPT_LF_CTX_RELOAD);
2233 : : break;
2234 : : default:
2235 : : return -EINVAL;
2236 : : }
2237 : 0 : return 0;
2238 : : }
2239 : 0 : plt_err("Could not get CPT LF for SA sync");
2240 : 0 : return -ENOTSUP;
2241 : : }
2242 : :
2243 : : int
2244 : 0 : roc_nix_inl_ctx_write(struct roc_nix *roc_nix, void *sa_dptr, void *sa_cptr,
2245 : : bool inb, uint16_t sa_len)
2246 : : {
2247 : 0 : struct idev_cfg *idev = idev_get_cfg();
2248 : : struct nix_inl_dev *inl_dev = NULL;
2249 : : struct roc_cpt_lf *outb_lf = NULL;
2250 : : union cpt_lf_ctx_flush flush;
2251 : : union cpt_lf_ctx_inval inval;
2252 : : union cpt_lf_ctx_err err;
2253 : : bool get_inl_lf = true;
2254 : : uintptr_t rbase;
2255 : : struct nix *nix;
2256 : : uint64_t *sa;
2257 : : int rc;
2258 : :
2259 : : /* Nothing much to do on cn9k */
2260 [ # # ]: 0 : if (roc_model_is_cn9k()) {
2261 : : return 0;
2262 : : }
2263 [ # # ]: 0 : if (idev)
2264 : 0 : inl_dev = idev->nix_inl_dev;
2265 : :
2266 [ # # ]: 0 : if (!inl_dev && roc_nix == NULL)
2267 : : return -EINVAL;
2268 : :
2269 [ # # ]: 0 : if (roc_nix) {
2270 [ # # # # : 0 : if (inb && roc_nix->custom_inb_sa && sa_len > ROC_NIX_INL_INB_CUSTOM_SA_SZ) {
# # ]
2271 : 0 : plt_nix_dbg("SA length: %u is more than allocated length: %u", sa_len,
2272 : : ROC_NIX_INL_INB_CUSTOM_SA_SZ);
2273 : 0 : return -EINVAL;
2274 : : }
2275 : : nix = roc_nix_to_nix_priv(roc_nix);
2276 : 0 : outb_lf = nix->cpt_lf_base;
2277 : :
2278 [ # # # # ]: 0 : if (inb && !nix->inb_inl_dev)
2279 : : get_inl_lf = false;
2280 : : }
2281 : :
2282 [ # # ]: 0 : if (inb && get_inl_lf) {
2283 : : outb_lf = NULL;
2284 [ # # # # ]: 0 : if (inl_dev && inl_dev->attach_cptlf)
2285 : 0 : outb_lf = &inl_dev->cpt_lf[0];
2286 : : }
2287 : :
2288 [ # # ]: 0 : if (outb_lf == NULL)
2289 : 0 : goto exit;
2290 : :
2291 [ # # # # ]: 0 : if (roc_model_is_cn10k() || roc_nix->use_write_sa) {
2292 : 0 : rbase = outb_lf->rbase;
2293 : 0 : flush.u = 0;
2294 : :
2295 : 0 : rc = roc_cpt_ctx_write(outb_lf, sa_dptr, sa_cptr, sa_len);
2296 [ # # ]: 0 : if (rc)
2297 : : return rc;
2298 : : /* Trigger CTX flush to write dirty data back to DRAM */
2299 : 0 : flush.s.cptr = ((uintptr_t)sa_cptr) >> 7;
2300 [ # # ]: 0 : plt_write64(flush.u, rbase + CPT_LF_CTX_FLUSH);
2301 : :
2302 : : plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
2303 : :
2304 : : /* Read a CSR to ensure that the FLUSH operation is complete */
2305 [ # # ]: 0 : err.u = plt_read64(rbase + CPT_LF_CTX_ERR);
2306 : :
2307 [ # # ]: 0 : if (err.s.flush_st_flt)
2308 : 0 : plt_warn("CTX flush could not complete");
2309 : 0 : return 0;
2310 : : } else {
2311 : : sa = sa_dptr;
2312 : :
2313 : : /* Clear bit 58 aop_valid */
2314 : 0 : sa[0] &= ~(1ULL << 58);
2315 : 0 : memcpy(sa_cptr, sa_dptr, sa_len);
2316 : 0 : plt_io_wmb();
2317 : :
2318 : : /* Trigger CTX invalidate */
2319 : 0 : rbase = outb_lf->rbase;
2320 : 0 : inval.u = 0;
2321 : 0 : inval.s.cptr = ((uintptr_t)sa_cptr) >> 7;
2322 : 0 : plt_write64(inval.u, rbase + CPT_LF_CTX_INVAL);
2323 : :
2324 : : /* Set bit 58 aop_valid */
2325 : : sa = sa_cptr;
2326 : 0 : sa[0] |= (1ULL << 58);
2327 : 0 : plt_io_wmb();
2328 : :
2329 : 0 : return 0;
2330 : : }
2331 : :
2332 : : exit:
2333 : 0 : plt_nix_dbg("Could not get CPT LF for CTX write");
2334 : 0 : return -ENOTSUP;
2335 : : }
2336 : :
2337 : : static inline int
2338 : 0 : nix_inl_dev_cpt_lf_stats_get(struct roc_nix *roc_nix, struct roc_nix_cpt_lf_stats *stats,
2339 : : uint16_t idx)
2340 : : {
2341 : 0 : struct idev_cfg *idev = idev_get_cfg();
2342 : : struct nix_inl_dev *inl_dev = NULL;
2343 : : struct roc_cpt_lf *lf = NULL;
2344 : :
2345 : : PLT_SET_USED(roc_nix);
2346 [ # # ]: 0 : if (idev)
2347 : 0 : inl_dev = idev->nix_inl_dev;
2348 : :
2349 [ # # # # ]: 0 : if (inl_dev && inl_dev->attach_cptlf) {
2350 [ # # ]: 0 : if (idx >= inl_dev->nb_cptlf) {
2351 : 0 : plt_err("Invalid idx: %u total lfs: %d", idx, inl_dev->nb_cptlf);
2352 : 0 : return -EINVAL;
2353 : : }
2354 : 0 : lf = &inl_dev->cpt_lf[idx];
2355 : : } else {
2356 : 0 : plt_err("No CPT LF(s) are found for Inline Device");
2357 : 0 : return -EINVAL;
2358 : : }
2359 : 0 : stats->enc_pkts = plt_read64(lf->rbase + CPT_LF_CTX_ENC_PKT_CNT);
2360 : 0 : stats->enc_bytes = plt_read64(lf->rbase + CPT_LF_CTX_ENC_BYTE_CNT);
2361 : 0 : stats->dec_pkts = plt_read64(lf->rbase + CPT_LF_CTX_DEC_PKT_CNT);
2362 : 0 : stats->dec_bytes = plt_read64(lf->rbase + CPT_LF_CTX_DEC_BYTE_CNT);
2363 : :
2364 : 0 : return 0;
2365 : : }
2366 : :
2367 : : static inline int
2368 : 0 : nix_eth_dev_cpt_lf_stats_get(struct roc_nix *roc_nix, struct roc_nix_cpt_lf_stats *stats,
2369 : : uint16_t idx)
2370 : : {
2371 : : struct roc_cpt_lf *lf;
2372 : : struct nix *nix;
2373 : :
2374 [ # # ]: 0 : if (!roc_nix)
2375 : : return -EINVAL;
2376 : : nix = roc_nix_to_nix_priv(roc_nix);
2377 [ # # ]: 0 : if (idx >= nix->nb_cpt_lf) {
2378 : 0 : plt_err("Invalid idx: %u total lfs: %d", idx, nix->nb_cpt_lf);
2379 : 0 : return -EINVAL;
2380 : : }
2381 : 0 : lf = &nix->cpt_lf_base[idx];
2382 : 0 : stats->enc_pkts = plt_read64(lf->rbase + CPT_LF_CTX_ENC_PKT_CNT);
2383 : 0 : stats->enc_bytes = plt_read64(lf->rbase + CPT_LF_CTX_ENC_BYTE_CNT);
2384 : 0 : stats->dec_pkts = plt_read64(lf->rbase + CPT_LF_CTX_DEC_PKT_CNT);
2385 : 0 : stats->dec_bytes = plt_read64(lf->rbase + CPT_LF_CTX_DEC_BYTE_CNT);
2386 : :
2387 : 0 : return 0;
2388 : : }
2389 : :
2390 : : int
2391 : 0 : roc_nix_inl_cpt_lf_stats_get(struct roc_nix *roc_nix, enum roc_nix_cpt_lf_stats_type type,
2392 : : struct roc_nix_cpt_lf_stats *stats, uint16_t idx)
2393 : : {
2394 [ # # # ]: 0 : switch (type) {
2395 : 0 : case ROC_NIX_CPT_LF_STATS_INL_DEV:
2396 : 0 : return nix_inl_dev_cpt_lf_stats_get(roc_nix, stats, idx);
2397 : 0 : case ROC_NIX_CPT_LF_STATS_ETHDEV:
2398 : 0 : return nix_eth_dev_cpt_lf_stats_get(roc_nix, stats, idx);
2399 : : default:
2400 : : return -EINVAL;
2401 : : }
2402 : : }
2403 : :
2404 : : static int
2405 : 0 : nix_inl_ts_pkind_set(struct roc_nix *roc_nix, bool ts_ena, bool inb_inl_dev, uint8_t profile_id)
2406 : : {
2407 : 0 : struct idev_cfg *idev = idev_get_cfg();
2408 : : struct nix_inl_dev *inl_dev = NULL;
2409 : : void *sa, *sa_base = NULL;
2410 : : struct nix *nix = NULL;
2411 : : uint32_t rq_refs = 0;
2412 : : uint16_t max_sa = 0;
2413 : : uint8_t pkind = 0;
2414 : : size_t inb_sa_sz;
2415 : : int i;
2416 : :
2417 [ # # ]: 0 : if (roc_model_is_cn9k())
2418 : : return 0;
2419 : :
2420 [ # # # # ]: 0 : if (!inb_inl_dev && (roc_nix == NULL) && profile_id >= ROC_NIX_INL_PROFILE_CNT)
2421 : : return -EINVAL;
2422 : :
2423 [ # # ]: 0 : if (inb_inl_dev) {
2424 [ # # # # ]: 0 : if ((idev == NULL) || (idev->nix_inl_dev == NULL))
2425 : : return 0;
2426 : : inl_dev = idev->nix_inl_dev;
2427 : : } else {
2428 : : nix = roc_nix_to_nix_priv(roc_nix);
2429 [ # # ]: 0 : if (!nix->inl_inb_ena)
2430 : : return 0;
2431 : :
2432 : 0 : sa_base = nix->inb_sa_base[profile_id];
2433 [ # # ]: 0 : if (sa_base == NULL)
2434 : : return 0;
2435 : 0 : inb_sa_sz = nix->inb_sa_sz[profile_id];
2436 : 0 : max_sa = nix->inb_sa_max[profile_id];
2437 : : }
2438 : :
2439 [ # # ]: 0 : if (inl_dev) {
2440 [ # # ]: 0 : for (i = 0; i < inl_dev->nb_rqs; i++)
2441 : 0 : rq_refs += inl_dev->rqs[i].inl_dev_refs;
2442 : :
2443 [ # # ]: 0 : if (rq_refs == 0) {
2444 : 0 : sa_base = inl_dev->inb_sa_base[profile_id];
2445 [ # # ]: 0 : if (sa_base == NULL)
2446 : : return 0;
2447 : 0 : inl_dev->ts_ena = ts_ena;
2448 : 0 : max_sa = inl_dev->inb_sa_max[profile_id];
2449 : 0 : inb_sa_sz = inl_dev->inb_sa_sz[profile_id];
2450 [ # # ]: 0 : } else if (inl_dev->ts_ena != ts_ena) {
2451 [ # # ]: 0 : if (inl_dev->ts_ena)
2452 : 0 : plt_err("Inline device is already configured with TS enable");
2453 : : else
2454 : 0 : plt_err("Inline device is already configured with TS disable");
2455 : 0 : return -ENOTSUP;
2456 : : } else {
2457 : : return 0;
2458 : : }
2459 : : }
2460 : :
2461 [ # # ]: 0 : pkind = ts_ena ? ROC_IE_OT_CPT_TS_PKIND : ROC_IE_OT_CPT_PKIND;
2462 : :
2463 : : sa = (uint8_t *)sa_base;
2464 [ # # ]: 0 : if (pkind == ((struct roc_ot_ipsec_inb_sa *)sa)->w0.s.pkind)
2465 : : return 0;
2466 : :
2467 [ # # ]: 0 : for (i = 0; i < max_sa; i++) {
2468 : 0 : sa = ((uint8_t *)sa_base) + (i * inb_sa_sz);
2469 : 0 : ((struct roc_ot_ipsec_inb_sa *)sa)->w0.s.pkind = pkind;
2470 : : }
2471 : : return 0;
2472 : : }
2473 : :
2474 : : int
2475 : 0 : roc_nix_inl_ts_pkind_set(struct roc_nix *roc_nix, bool ts_ena, bool inb_inl_dev, uint8_t profile_id)
2476 : : {
2477 : : int cnt = 0;
2478 : :
2479 [ # # ]: 0 : if (profile_id < ROC_NIX_INL_PROFILE_CNT) {
2480 : 0 : return nix_inl_ts_pkind_set(roc_nix, ts_ena, inb_inl_dev, profile_id);
2481 [ # # ]: 0 : } else if (profile_id == 0xFF) {
2482 : : /* Configure for all valid profiles */
2483 [ # # ]: 0 : for (cnt = 0; cnt < ROC_NIX_INL_PROFILE_CNT; cnt++)
2484 [ # # ]: 0 : if (nix_inl_ts_pkind_set(roc_nix, ts_ena, inb_inl_dev, cnt))
2485 : : return -EINVAL;
2486 : : return 0;
2487 : : }
2488 : :
2489 : 0 : plt_err("Invalid NIX inline profile_id: %u", profile_id);
2490 : 0 : return -EINVAL;
2491 : : }
2492 : :
2493 : : void
2494 : 0 : roc_nix_inl_dev_lock(void)
2495 : : {
2496 : 0 : struct idev_cfg *idev = idev_get_cfg();
2497 : :
2498 [ # # ]: 0 : if (idev != NULL)
2499 : 0 : plt_spinlock_lock(&idev->nix_inl_dev_lock);
2500 : 0 : }
2501 : :
2502 : : void
2503 : 0 : roc_nix_inl_dev_unlock(void)
2504 : : {
2505 : 0 : struct idev_cfg *idev = idev_get_cfg();
2506 : :
2507 [ # # ]: 0 : if (idev != NULL)
2508 : 0 : plt_spinlock_unlock(&idev->nix_inl_dev_lock);
2509 : 0 : }
2510 : :
2511 : : void
2512 : 0 : roc_nix_inl_meta_pool_cb_register(roc_nix_inl_meta_pool_cb_t cb)
2513 : : {
2514 : 0 : meta_pool_cb = cb;
2515 : 0 : }
2516 : :
2517 : : uint64_t
2518 : 0 : roc_nix_inl_eng_caps_get(struct roc_nix *roc_nix)
2519 : : {
2520 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
2521 : :
2522 : 0 : return nix->cpt_eng_caps;
2523 : : }
2524 : :
2525 : : void
2526 : 0 : roc_nix_inl_custom_meta_pool_cb_register(roc_nix_inl_custom_meta_pool_cb_t cb)
2527 : : {
2528 : 0 : custom_meta_pool_cb = cb;
2529 : 0 : }
|