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