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