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 : : static roc_npa_lf_init_cb_t lf_init_cb;
9 : :
10 : : int
11 : 302 : roc_npa_lf_init_cb_register(roc_npa_lf_init_cb_t cb)
12 : : {
13 [ + - ]: 302 : if (lf_init_cb != NULL)
14 : : return -EEXIST;
15 : :
16 : 302 : lf_init_cb = cb;
17 : 302 : return 0;
18 : : }
19 : :
20 : : uint16_t
21 : 0 : roc_npa_pf_func_get(void)
22 : : {
23 : 0 : return idev_npa_pffunc_get();
24 : : }
25 : :
26 : : void
27 : 0 : roc_npa_pool_op_range_set(uint64_t aura_handle, uint64_t start_iova,
28 : : uint64_t end_iova)
29 : : {
30 : 0 : const uint64_t start = roc_npa_aura_handle_to_base(aura_handle) +
31 : : NPA_LF_POOL_OP_PTR_START0;
32 : 0 : const uint64_t end = roc_npa_aura_handle_to_base(aura_handle) +
33 : : NPA_LF_POOL_OP_PTR_END0;
34 : : uint64_t reg = roc_npa_aura_handle_to_aura(aura_handle);
35 : 0 : struct npa_lf *lf = idev_npa_obj_get();
36 : : struct npa_aura_lim *lim;
37 : :
38 : : PLT_ASSERT(lf);
39 : 0 : lim = lf->aura_lim;
40 : :
41 : : /* Change the range bookkeeping in software as well as in hardware */
42 : 0 : lim[reg].ptr_start = PLT_MIN(lim[reg].ptr_start, start_iova);
43 : 0 : lim[reg].ptr_end = PLT_MAX(lim[reg].ptr_end, end_iova);
44 : :
45 : 0 : roc_store_pair(lim[reg].ptr_start, reg, start);
46 : 0 : roc_store_pair(lim[reg].ptr_end, reg, end);
47 : 0 : }
48 : :
49 : : void
50 : 0 : roc_npa_aura_op_range_set(uint64_t aura_handle, uint64_t start_iova,
51 : : uint64_t end_iova)
52 : : {
53 : : uint64_t reg = roc_npa_aura_handle_to_aura(aura_handle);
54 : 0 : struct npa_lf *lf = idev_npa_obj_get();
55 : : struct npa_aura_lim *lim;
56 : :
57 : : PLT_ASSERT(lf);
58 : 0 : lim = lf->aura_lim;
59 : :
60 : : /* Change only the bookkeeping in software */
61 : 0 : lim[reg].ptr_start = PLT_MIN(lim[reg].ptr_start, start_iova);
62 : 0 : lim[reg].ptr_end = PLT_MAX(lim[reg].ptr_end, end_iova);
63 : 0 : }
64 : :
65 : : void
66 : 0 : roc_npa_aura_op_range_get(uint64_t aura_handle, uint64_t *start_iova,
67 : : uint64_t *end_iova)
68 : : {
69 : : uint64_t aura_id = roc_npa_aura_handle_to_aura(aura_handle);
70 : : struct npa_aura_lim *lim;
71 : : struct npa_lf *lf;
72 : :
73 : 0 : lf = idev_npa_obj_get();
74 : : PLT_ASSERT(lf);
75 : :
76 : 0 : lim = lf->aura_lim;
77 : 0 : *start_iova = lim[aura_id].ptr_start;
78 : 0 : *end_iova = lim[aura_id].ptr_end;
79 : 0 : }
80 : :
81 : : static int
82 : 0 : npa_aura_pool_init(struct mbox *m_box, uint32_t aura_id, struct npa_aura_s *aura,
83 : : struct npa_pool_s *pool)
84 : : {
85 : : struct npa_aq_enq_req *aura_init_req, *pool_init_req;
86 : : struct npa_aq_enq_rsp *aura_init_rsp, *pool_init_rsp;
87 : 0 : struct mbox_dev *mdev = &m_box->dev[0];
88 : : int rc = -ENOSPC, off;
89 : : struct mbox *mbox;
90 : :
91 : : mbox = mbox_get(m_box);
92 [ # # ]: 0 : if (roc_model_is_cn20k()) {
93 : : struct npa_cn20k_aq_enq_req *aura_init_req_cn20k;
94 : 0 : aura_init_req_cn20k = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
95 : : aura_init_req = (struct npa_aq_enq_req *)aura_init_req_cn20k;
96 : : } else {
97 : 0 : aura_init_req = mbox_alloc_msg_npa_aq_enq(mbox);
98 : : }
99 [ # # ]: 0 : if (aura_init_req == NULL)
100 : 0 : goto exit;
101 : 0 : aura_init_req->aura_id = aura_id;
102 : 0 : aura_init_req->ctype = NPA_AQ_CTYPE_AURA;
103 : 0 : aura_init_req->op = NPA_AQ_INSTOP_INIT;
104 [ # # ]: 0 : mbox_memcpy(&aura_init_req->aura, aura, sizeof(*aura));
105 : :
106 [ # # ]: 0 : if (roc_model_is_cn20k()) {
107 : : struct npa_cn20k_aq_enq_req *pool_init_req_cn20k;
108 : 0 : pool_init_req_cn20k = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
109 : : pool_init_req = (struct npa_aq_enq_req *)pool_init_req_cn20k;
110 : : } else {
111 : 0 : pool_init_req = mbox_alloc_msg_npa_aq_enq(mbox);
112 : : }
113 [ # # ]: 0 : if (pool_init_req == NULL)
114 : 0 : goto exit;
115 : 0 : pool_init_req->aura_id = aura_id;
116 : 0 : pool_init_req->ctype = NPA_AQ_CTYPE_POOL;
117 : 0 : pool_init_req->op = NPA_AQ_INSTOP_INIT;
118 [ # # ]: 0 : mbox_memcpy(&pool_init_req->pool, pool, sizeof(*pool));
119 : :
120 : 0 : rc = mbox_process(mbox);
121 [ # # ]: 0 : if (rc < 0)
122 : 0 : goto exit;
123 : :
124 : 0 : off = mbox->rx_start +
125 : : PLT_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
126 : 0 : aura_init_rsp = (struct npa_aq_enq_rsp *)((uintptr_t)mdev->mbase + off);
127 : 0 : off = mbox->rx_start + aura_init_rsp->hdr.next_msgoff;
128 : 0 : pool_init_rsp = (struct npa_aq_enq_rsp *)((uintptr_t)mdev->mbase + off);
129 : :
130 [ # # # # ]: 0 : if (aura_init_rsp->hdr.rc == 0 && pool_init_rsp->hdr.rc == 0)
131 : : rc = 0;
132 : : else
133 : : rc = NPA_ERR_AURA_POOL_INIT;
134 : 0 : exit:
135 : : mbox_put(mbox);
136 : 0 : return rc;
137 : : }
138 : :
139 : : static int
140 : 0 : npa_aura_init(struct mbox *m_box, uint32_t aura_id, struct npa_aura_s *aura)
141 : : {
142 : : struct npa_aq_enq_req *aura_init_req;
143 : : struct npa_aq_enq_rsp *aura_init_rsp;
144 : : struct mbox *mbox;
145 : : int rc = -ENOSPC;
146 : :
147 : : mbox = mbox_get(m_box);
148 [ # # ]: 0 : if (roc_model_is_cn20k()) {
149 : : struct npa_cn20k_aq_enq_req *aura_init_req_cn20k;
150 : 0 : aura_init_req_cn20k = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
151 : : aura_init_req = (struct npa_aq_enq_req *)aura_init_req_cn20k;
152 : : } else {
153 : 0 : aura_init_req = mbox_alloc_msg_npa_aq_enq(mbox);
154 : : }
155 [ # # ]: 0 : if (aura_init_req == NULL)
156 : 0 : goto exit;
157 : 0 : aura_init_req->aura_id = aura_id;
158 : 0 : aura_init_req->ctype = NPA_AQ_CTYPE_AURA;
159 : 0 : aura_init_req->op = NPA_AQ_INSTOP_INIT;
160 [ # # ]: 0 : mbox_memcpy(&aura_init_req->aura, aura, sizeof(*aura));
161 : :
162 : : rc = mbox_process_msg(mbox, (void **)&aura_init_rsp);
163 [ # # ]: 0 : if (rc < 0)
164 : 0 : goto exit;
165 : :
166 [ # # ]: 0 : if (aura_init_rsp->hdr.rc == 0)
167 : : rc = 0;
168 : : else
169 : : rc = NPA_ERR_AURA_POOL_INIT;
170 : 0 : exit:
171 : : mbox_put(mbox);
172 : 0 : return rc;
173 : : }
174 : :
175 : : static inline void
176 : 0 : npa_pool_multi_bp_reset(struct npa_cn20k_aq_enq_req *pool_req)
177 : : {
178 : 0 : pool_req->pool.bp_0 = 0;
179 : 0 : pool_req->pool.bp_1 = 0;
180 : 0 : pool_req->pool.bp_2 = 0;
181 : 0 : pool_req->pool.bp_3 = 0;
182 : 0 : pool_req->pool.bp_4 = 0;
183 : 0 : pool_req->pool.bp_5 = 0;
184 : 0 : pool_req->pool.bp_6 = 0;
185 : 0 : pool_req->pool.bp_7 = 0;
186 : 0 : pool_req->pool.bp_ena_0 = 0;
187 : 0 : pool_req->pool.bp_ena_1 = 0;
188 : 0 : pool_req->pool.bp_ena_2 = 0;
189 : 0 : pool_req->pool.bp_ena_3 = 0;
190 : 0 : pool_req->pool.bp_ena_4 = 0;
191 : 0 : pool_req->pool.bp_ena_5 = 0;
192 : 0 : pool_req->pool.bp_ena_6 = 0;
193 : 0 : pool_req->pool.bp_ena_7 = 0;
194 : 0 : pool_req->pool_mask.bp_0 = ~(pool_req->pool_mask.bp_0);
195 : 0 : pool_req->pool_mask.bp_1 = ~(pool_req->pool_mask.bp_1);
196 : 0 : pool_req->pool_mask.bp_2 = ~(pool_req->pool_mask.bp_2);
197 : 0 : pool_req->pool_mask.bp_3 = ~(pool_req->pool_mask.bp_3);
198 : 0 : pool_req->pool_mask.bp_4 = ~(pool_req->pool_mask.bp_4);
199 : 0 : pool_req->pool_mask.bp_5 = ~(pool_req->pool_mask.bp_5);
200 : 0 : pool_req->pool_mask.bp_6 = ~(pool_req->pool_mask.bp_6);
201 : 0 : pool_req->pool_mask.bp_7 = ~(pool_req->pool_mask.bp_7);
202 : 0 : pool_req->pool_mask.bp_ena_0 = ~(pool_req->pool_mask.bp_ena_0);
203 : 0 : pool_req->pool_mask.bp_ena_1 = ~(pool_req->pool_mask.bp_ena_1);
204 : 0 : pool_req->pool_mask.bp_ena_2 = ~(pool_req->pool_mask.bp_ena_2);
205 : 0 : pool_req->pool_mask.bp_ena_3 = ~(pool_req->pool_mask.bp_ena_3);
206 : 0 : pool_req->pool_mask.bp_ena_4 = ~(pool_req->pool_mask.bp_ena_4);
207 : 0 : pool_req->pool_mask.bp_ena_5 = ~(pool_req->pool_mask.bp_ena_5);
208 : 0 : pool_req->pool_mask.bp_ena_6 = ~(pool_req->pool_mask.bp_ena_6);
209 : 0 : pool_req->pool_mask.bp_ena_7 = ~(pool_req->pool_mask.bp_ena_7);
210 : 0 : }
211 : :
212 : : static int
213 : 0 : npa_halo_init(struct mbox *m_box, uint32_t aura_id, struct npa_cn20k_halo_s *halo)
214 : : {
215 : : struct npa_cn20k_aq_enq_req *req;
216 : : struct npa_aq_enq_rsp *rsp;
217 : : struct mbox *mbox;
218 : : int rc = -ENOSPC;
219 : :
220 : : mbox = mbox_get(m_box);
221 : 0 : req = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
222 [ # # ]: 0 : if (req == NULL)
223 : 0 : goto exit;
224 : 0 : req->aura_id = aura_id;
225 : 0 : req->ctype = NPA_AQ_CTYPE_HALO;
226 : 0 : req->op = NPA_AQ_INSTOP_INIT;
227 [ # # ]: 0 : mbox_memcpy(&req->halo, halo, sizeof(*halo));
228 : :
229 : : rc = mbox_process_msg(mbox, (void **)&rsp);
230 [ # # ]: 0 : if (rc < 0)
231 : 0 : goto exit;
232 : :
233 [ # # ]: 0 : if (rsp->hdr.rc == 0)
234 : : rc = 0;
235 : : else
236 : : rc = NPA_ERR_HALO_INIT;
237 : 0 : exit:
238 : : mbox_put(mbox);
239 : 0 : return rc;
240 : : }
241 : :
242 : : static int
243 : 0 : npa_halo_fini(struct mbox *m_box, uint32_t aura_id, uint64_t aura_handle)
244 : : {
245 : 0 : struct mbox_dev *mdev = &m_box->dev[0];
246 : : struct npa_cn20k_aq_enq_req *req;
247 : : struct npa_aq_enq_rsp *rsp;
248 : : int rc = -ENOSPC, off;
249 : : struct mbox *mbox;
250 : : uint64_t ptr;
251 : :
252 : : /* Procedure for disabling an aura/pool */
253 : 0 : plt_delay_us(10);
254 : :
255 : : /* Clear all the pointers from the aura */
256 : : do {
257 : : ptr = roc_npa_aura_op_alloc(aura_handle, 0);
258 : : } while (ptr);
259 : :
260 : : mbox = mbox_get(m_box);
261 : 0 : req = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
262 [ # # ]: 0 : if (req == NULL)
263 : 0 : goto exit;
264 : :
265 : : /* Disable backpressure on halo on CN20K */
266 [ # # ]: 0 : if (roc_model_is_cn20k())
267 : 0 : npa_pool_multi_bp_reset(req);
268 : :
269 : 0 : req->aura_id = aura_id;
270 : 0 : req->ctype = NPA_AQ_CTYPE_HALO;
271 : 0 : req->op = NPA_AQ_INSTOP_WRITE;
272 : 0 : req->halo.ena = 0;
273 : 0 : req->halo_mask.ena = ~req->halo_mask.ena;
274 : :
275 : 0 : rc = mbox_process(mbox);
276 [ # # ]: 0 : if (rc < 0)
277 : 0 : goto exit;
278 : :
279 : 0 : off = mbox->rx_start +
280 : : PLT_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
281 : 0 : rsp = (struct npa_aq_enq_rsp *)((uintptr_t)mdev->mbase + off);
282 : :
283 [ # # ]: 0 : if (rsp->hdr.rc != 0) {
284 : : rc = NPA_ERR_HALO_FINI;
285 : 0 : goto exit;
286 : : }
287 : :
288 : : rc = 0;
289 : 0 : exit:
290 : : mbox_put(mbox);
291 : 0 : return rc;
292 : : }
293 : :
294 : : static int
295 : 0 : npa_aura_pool_fini(struct mbox *m_box, uint32_t aura_id, uint64_t aura_handle)
296 : : {
297 : : struct npa_cn20k_aq_enq_req *pool_req_cn20k = NULL;
298 : : struct npa_aq_enq_req *aura_req, *pool_req;
299 : : struct npa_aq_enq_rsp *aura_rsp, *pool_rsp;
300 : 0 : struct mbox_dev *mdev = &m_box->dev[0];
301 : : struct ndc_sync_op *ndc_req;
302 : : int rc = -ENOSPC, off;
303 : : struct mbox *mbox;
304 : : uint64_t ptr;
305 : :
306 : : /* Procedure for disabling an aura/pool */
307 : 0 : plt_delay_us(10);
308 : :
309 : : /* Clear all the pointers from the aura */
310 : : do {
311 : : ptr = roc_npa_aura_op_alloc(aura_handle, 0);
312 : : } while (ptr);
313 : :
314 : : mbox = mbox_get(m_box);
315 [ # # ]: 0 : if (roc_model_is_cn20k()) {
316 : 0 : pool_req_cn20k = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
317 : : pool_req = (struct npa_aq_enq_req *)pool_req_cn20k;
318 : : } else {
319 : 0 : pool_req = mbox_alloc_msg_npa_aq_enq(mbox);
320 : : }
321 [ # # ]: 0 : if (pool_req == NULL)
322 : 0 : goto exit;
323 : :
324 : : /* Disable backpressure on pool on CN20K */
325 [ # # ]: 0 : if (roc_model_is_cn20k())
326 : 0 : npa_pool_multi_bp_reset(pool_req_cn20k);
327 : 0 : pool_req->aura_id = aura_id;
328 : 0 : pool_req->ctype = NPA_AQ_CTYPE_POOL;
329 : 0 : pool_req->op = NPA_AQ_INSTOP_WRITE;
330 : 0 : pool_req->pool.ena = 0;
331 : 0 : pool_req->pool_mask.ena = ~pool_req->pool_mask.ena;
332 : :
333 [ # # ]: 0 : if (roc_model_is_cn20k()) {
334 : : struct npa_cn20k_aq_enq_req *aura_req_cn20k;
335 : 0 : aura_req_cn20k = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
336 : : aura_req = (struct npa_aq_enq_req *)aura_req_cn20k;
337 : : } else {
338 : 0 : aura_req = mbox_alloc_msg_npa_aq_enq(mbox);
339 : : }
340 [ # # ]: 0 : if (aura_req == NULL)
341 : 0 : goto exit;
342 : 0 : aura_req->aura_id = aura_id;
343 : 0 : aura_req->ctype = NPA_AQ_CTYPE_AURA;
344 : 0 : aura_req->op = NPA_AQ_INSTOP_WRITE;
345 : 0 : aura_req->aura.ena = 0;
346 [ # # ]: 0 : aura_req->aura_mask.ena = ~aura_req->aura_mask.ena;
347 [ # # ]: 0 : if (roc_model_is_cn20k()) {
348 : : __io struct npa_cn20k_aura_s *aura_cn20k, *aura_mask_cn20k;
349 : :
350 : : /* The bit positions/width of bp_ena has changed in cn20k */
351 : : aura_cn20k = (__io struct npa_cn20k_aura_s *)&aura_req->aura;
352 : 0 : aura_cn20k->bp_ena = 0;
353 : : aura_mask_cn20k = (__io struct npa_cn20k_aura_s *)&aura_req->aura_mask;
354 : 0 : aura_mask_cn20k->bp_ena = ~aura_mask_cn20k->bp_ena;
355 : : } else {
356 : 0 : aura_req->aura.bp_ena = 0;
357 : 0 : aura_req->aura_mask.bp_ena = ~aura_req->aura_mask.bp_ena;
358 : : }
359 : :
360 : 0 : rc = mbox_process(mbox);
361 [ # # ]: 0 : if (rc < 0)
362 : 0 : goto exit;
363 : :
364 : 0 : off = mbox->rx_start +
365 : : PLT_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
366 : 0 : pool_rsp = (struct npa_aq_enq_rsp *)((uintptr_t)mdev->mbase + off);
367 : :
368 : 0 : off = mbox->rx_start + pool_rsp->hdr.next_msgoff;
369 : 0 : aura_rsp = (struct npa_aq_enq_rsp *)((uintptr_t)mdev->mbase + off);
370 : :
371 [ # # # # ]: 0 : if (aura_rsp->hdr.rc != 0 || pool_rsp->hdr.rc != 0) {
372 : : rc = NPA_ERR_AURA_POOL_FINI;
373 : 0 : goto exit;
374 : : }
375 : :
376 [ # # ]: 0 : if (roc_model_is_cn20k()) {
377 : : /* In cn20k, NPA does not use NDC */
378 : : rc = 0;
379 : 0 : goto exit;
380 : : }
381 : :
382 : : /* Sync NDC-NPA for LF */
383 : 0 : ndc_req = mbox_alloc_msg_ndc_sync_op(mbox);
384 [ # # ]: 0 : if (ndc_req == NULL) {
385 : : rc = -ENOSPC;
386 : 0 : goto exit;
387 : : }
388 : 0 : ndc_req->npa_lf_sync = 1;
389 : 0 : rc = mbox_process(mbox);
390 [ # # ]: 0 : if (rc) {
391 : 0 : plt_err("Error on NDC-NPA LF sync, rc %d", rc);
392 : : rc = NPA_ERR_AURA_POOL_FINI;
393 : 0 : goto exit;
394 : : }
395 : : rc = 0;
396 : 0 : exit:
397 : : mbox_put(mbox);
398 : 0 : return rc;
399 : : }
400 : :
401 : : static int
402 : 0 : npa_aura_fini(struct mbox *m_box, uint32_t aura_id)
403 : : {
404 : : struct npa_aq_enq_req *aura_req;
405 : : struct npa_aq_enq_rsp *aura_rsp;
406 : : struct ndc_sync_op *ndc_req;
407 : : struct mbox *mbox;
408 : : int rc = -ENOSPC;
409 : :
410 : : /* Procedure for disabling an aura/pool */
411 : 0 : plt_delay_us(10);
412 : :
413 : : mbox = mbox_get(m_box);
414 [ # # ]: 0 : if (roc_model_is_cn20k()) {
415 : : struct npa_cn20k_aq_enq_req *aura_req_cn20k;
416 : 0 : aura_req_cn20k = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
417 : : aura_req = (struct npa_aq_enq_req *)aura_req_cn20k;
418 : : } else {
419 : 0 : aura_req = mbox_alloc_msg_npa_aq_enq(mbox);
420 : : }
421 [ # # ]: 0 : if (aura_req == NULL)
422 : 0 : goto exit;
423 : 0 : aura_req->aura_id = aura_id;
424 : 0 : aura_req->ctype = NPA_AQ_CTYPE_AURA;
425 : 0 : aura_req->op = NPA_AQ_INSTOP_WRITE;
426 : 0 : aura_req->aura.ena = 0;
427 : 0 : aura_req->aura_mask.ena = ~aura_req->aura_mask.ena;
428 : :
429 : : rc = mbox_process_msg(mbox, (void **)&aura_rsp);
430 [ # # ]: 0 : if (rc < 0)
431 : 0 : goto exit;
432 : :
433 [ # # ]: 0 : if (aura_rsp->hdr.rc != 0) {
434 : : rc = NPA_ERR_AURA_POOL_FINI;
435 : 0 : goto exit;
436 : : }
437 : :
438 [ # # ]: 0 : if (roc_model_is_cn20k()) {
439 : : /* In cn20k, NPA does not use NDC */
440 : : rc = 0;
441 : 0 : goto exit;
442 : : }
443 : :
444 : : /* Sync NDC-NPA for LF */
445 : 0 : ndc_req = mbox_alloc_msg_ndc_sync_op(mbox);
446 [ # # ]: 0 : if (ndc_req == NULL) {
447 : : rc = -ENOSPC;
448 : 0 : goto exit;
449 : : }
450 : 0 : ndc_req->npa_lf_sync = 1;
451 : 0 : rc = mbox_process(mbox);
452 [ # # ]: 0 : if (rc) {
453 : 0 : plt_err("Error on NDC-NPA LF sync, rc %d", rc);
454 : : rc = NPA_ERR_AURA_POOL_FINI;
455 : 0 : goto exit;
456 : : }
457 : : rc = 0;
458 : 0 : exit:
459 : : mbox_put(mbox);
460 : 0 : return rc;
461 : : }
462 : :
463 : : int
464 : 0 : roc_npa_pool_op_pc_reset(uint64_t aura_handle)
465 : : {
466 : 0 : struct npa_lf *lf = idev_npa_obj_get();
467 : : struct npa_aq_enq_req *pool_req;
468 : : struct npa_aq_enq_rsp *pool_rsp;
469 : : struct ndc_sync_op *ndc_req;
470 : : struct mbox_dev *mdev;
471 : : int rc = -ENOSPC, off;
472 : : struct mbox *mbox;
473 : :
474 [ # # ]: 0 : if (lf == NULL)
475 : : return NPA_ERR_PARAM;
476 : :
477 : 0 : mbox = mbox_get(lf->mbox);
478 : 0 : mdev = &mbox->dev[0];
479 : 0 : plt_npa_dbg("lf=%p aura_handle=0x%" PRIx64, lf, aura_handle);
480 : :
481 : 0 : pool_req = mbox_alloc_msg_npa_aq_enq(mbox);
482 [ # # ]: 0 : if (pool_req == NULL)
483 : 0 : goto exit;
484 : 0 : pool_req->aura_id = roc_npa_aura_handle_to_aura(aura_handle);
485 : 0 : pool_req->ctype = NPA_AQ_CTYPE_POOL;
486 : 0 : pool_req->op = NPA_AQ_INSTOP_WRITE;
487 : 0 : pool_req->pool.op_pc = 0;
488 : 0 : pool_req->pool_mask.op_pc = ~pool_req->pool_mask.op_pc;
489 : :
490 : 0 : rc = mbox_process(mbox);
491 [ # # ]: 0 : if (rc < 0)
492 : 0 : goto exit;
493 : :
494 : 0 : off = mbox->rx_start +
495 : : PLT_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
496 : 0 : pool_rsp = (struct npa_aq_enq_rsp *)((uintptr_t)mdev->mbase + off);
497 : :
498 [ # # ]: 0 : if (pool_rsp->hdr.rc != 0) {
499 : : rc = NPA_ERR_AURA_POOL_FINI;
500 : 0 : goto exit;
501 : : }
502 : :
503 : : /* Sync NDC-NPA for LF */
504 : 0 : ndc_req = mbox_alloc_msg_ndc_sync_op(mbox);
505 [ # # ]: 0 : if (ndc_req == NULL) {
506 : : rc = -ENOSPC;
507 : 0 : goto exit;
508 : : }
509 : 0 : ndc_req->npa_lf_sync = 1;
510 : 0 : rc = mbox_process(mbox);
511 [ # # ]: 0 : if (rc) {
512 : 0 : plt_err("Error on NDC-NPA LF sync, rc %d", rc);
513 : : rc = NPA_ERR_AURA_POOL_FINI;
514 : 0 : goto exit;
515 : : }
516 : : rc = 0;
517 : 0 : exit:
518 : : mbox_put(mbox);
519 : 0 : return rc;
520 : : }
521 : :
522 : : int
523 : 0 : roc_npa_aura_drop_set(uint64_t aura_handle, uint64_t limit, bool ena)
524 : : {
525 : : struct npa_aq_enq_req *aura_req;
526 : : struct npa_lf *lf;
527 : : struct mbox *mbox;
528 : : uint64_t aura_id;
529 : : int rc;
530 : :
531 : 0 : lf = idev_npa_obj_get();
532 [ # # ]: 0 : if (lf == NULL)
533 : : return NPA_ERR_DEVICE_NOT_BOUNDED;
534 : 0 : mbox = mbox_get(lf->mbox);
535 [ # # ]: 0 : if (roc_model_is_cn20k()) {
536 : : struct npa_cn20k_aq_enq_req *aura_req_cn20k;
537 : 0 : aura_req_cn20k = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
538 : : aura_req = (struct npa_aq_enq_req *)aura_req_cn20k;
539 : : } else {
540 : 0 : aura_req = mbox_alloc_msg_npa_aq_enq(mbox);
541 : : }
542 [ # # ]: 0 : if (aura_req == NULL) {
543 : : rc = -ENOMEM;
544 : 0 : goto exit;
545 : : }
546 : : aura_id = roc_npa_aura_handle_to_aura(aura_handle);
547 : 0 : aura_req->aura_id = aura_id;
548 [ # # ]: 0 : if (lf->aura_attr[aura_id].halo)
549 : 0 : aura_req->ctype = NPA_AQ_CTYPE_HALO;
550 : : else
551 : 0 : aura_req->ctype = NPA_AQ_CTYPE_AURA;
552 : 0 : aura_req->op = NPA_AQ_INSTOP_WRITE;
553 : :
554 : 0 : aura_req->aura.aura_drop_ena = ena;
555 : 0 : aura_req->aura.aura_drop = limit;
556 : 0 : aura_req->aura_mask.aura_drop_ena =
557 : 0 : ~(aura_req->aura_mask.aura_drop_ena);
558 : 0 : aura_req->aura_mask.aura_drop = ~(aura_req->aura_mask.aura_drop);
559 : 0 : rc = mbox_process(mbox);
560 : :
561 : 0 : exit:
562 : : mbox_put(mbox);
563 : 0 : return rc;
564 : : }
565 : :
566 : : static inline char *
567 : : npa_stack_memzone_name(struct npa_lf *lf, int pool_id, char *name)
568 : : {
569 : 0 : snprintf(name, PLT_MEMZONE_NAMESIZE, "roc_npa_stack_%x_%d", lf->pf_func,
570 : : pool_id);
571 : : return name;
572 : : }
573 : :
574 : : static inline const struct plt_memzone *
575 : 0 : npa_stack_dma_alloc(struct npa_lf *lf, char *name, int pool_id, size_t size)
576 : : {
577 : : const char *mz_name = npa_stack_memzone_name(lf, pool_id, name);
578 : 0 : size = PLT_ALIGN_CEIL(size, ROC_ALIGN);
579 : :
580 : 0 : return plt_memzone_reserve_aligned(mz_name, size, 0, ROC_ALIGN);
581 : : }
582 : :
583 : : static inline int
584 : 0 : npa_stack_dma_free(struct npa_lf *lf, char *name, int pool_id)
585 : : {
586 : : const struct plt_memzone *mz;
587 : :
588 : 0 : mz = plt_memzone_lookup(npa_stack_memzone_name(lf, pool_id, name));
589 [ # # ]: 0 : if (mz == NULL)
590 : : return NPA_ERR_PARAM;
591 : :
592 : 0 : return plt_memzone_free(mz);
593 : : }
594 : :
595 : : static inline int
596 : : bitmap_ctzll(uint64_t slab)
597 : : {
598 : 0 : if (slab == 0)
599 : : return 0;
600 : :
601 : 0 : return plt_ctz64(slab);
602 : : }
603 : :
604 : : static int
605 : 0 : find_free_aura(struct npa_lf *lf, uint32_t flags)
606 : : {
607 : 0 : struct plt_bitmap *bmp = lf->npa_bmp;
608 : : uint64_t aura0_state = 0;
609 : : uint64_t slab;
610 : : uint32_t pos;
611 : : int idx = -1;
612 : : int rc;
613 : :
614 [ # # ]: 0 : if (flags & ROC_NPA_ZERO_AURA_F) {
615 : : /* Only look for zero aura */
616 [ # # ]: 0 : if (plt_bitmap_get(bmp, 0))
617 : : return 0;
618 : 0 : plt_err("Zero aura already in use");
619 : 0 : return -1;
620 : : }
621 : :
622 [ # # ]: 0 : if (lf->zero_aura_rsvd) {
623 : : /* Save and clear zero aura bit if needed */
624 : : aura0_state = plt_bitmap_get(bmp, 0);
625 [ # # ]: 0 : if (aura0_state)
626 : 0 : plt_bitmap_clear(bmp, 0);
627 : : }
628 : :
629 : 0 : pos = 0;
630 : 0 : slab = 0;
631 : : /* Scan from the beginning */
632 : : plt_bitmap_scan_init(bmp);
633 : : /* Scan bitmap to get the free pool */
634 : 0 : rc = plt_bitmap_scan(bmp, &pos, &slab);
635 : : /* Empty bitmap */
636 [ # # ]: 0 : if (rc == 0) {
637 : 0 : plt_err("Aura's exhausted");
638 : 0 : goto empty;
639 : : }
640 : :
641 [ # # ]: 0 : idx = pos + bitmap_ctzll(slab);
642 : 0 : empty:
643 [ # # # # ]: 0 : if (lf->zero_aura_rsvd && aura0_state)
644 : : plt_bitmap_set(bmp, 0);
645 : :
646 : : return idx;
647 : : }
648 : :
649 : : static int
650 : 0 : npa_aura_pool_pair_alloc(struct npa_lf *lf, const uint32_t block_size,
651 : : const uint32_t block_count, struct npa_aura_s *aura,
652 : : struct npa_pool_s *pool, uint64_t *aura_handle,
653 : : uint32_t flags)
654 : : {
655 : : int rc, aura_id, pool_id, stack_size, alloc_size;
656 : : char name[PLT_MEMZONE_NAMESIZE];
657 : : const struct plt_memzone *mz;
658 : :
659 : : /* Sanity check */
660 [ # # # # ]: 0 : if (!lf || !block_size || !block_count || !pool || !aura ||
661 [ # # ]: 0 : !aura_handle)
662 : : return NPA_ERR_PARAM;
663 : :
664 : : /* Block size should be cache line aligned and in range of 128B-128KB */
665 [ # # # # : 0 : if (block_size % ROC_ALIGN || block_size < 128 ||
# # ]
666 : : block_size > roc_npa_max_block_size())
667 : : return NPA_ERR_INVALID_BLOCK_SZ;
668 : :
669 : : /* Get aura_id from resource bitmap */
670 : 0 : roc_npa_dev_lock();
671 : 0 : aura_id = find_free_aura(lf, flags);
672 [ # # ]: 0 : if (aura_id < 0) {
673 : 0 : roc_npa_dev_unlock();
674 : 0 : return NPA_ERR_AURA_ID_ALLOC;
675 : : }
676 : :
677 : : /* Mark pool as reserved */
678 : 0 : plt_bitmap_clear(lf->npa_bmp, aura_id);
679 : 0 : roc_npa_dev_unlock();
680 : :
681 : : /* Configuration based on each aura has separate pool(aura-pool pair) */
682 : : pool_id = aura_id;
683 [ # # ]: 0 : rc = (aura_id < 0 || pool_id >= (int)lf->nr_pools ||
684 [ # # ]: 0 : aura_id >= (int)BIT_ULL(6 + lf->aura_sz)) ?
685 : : NPA_ERR_AURA_ID_ALLOC :
686 : : 0;
687 : : if (rc)
688 : 0 : goto exit;
689 : :
690 : : /* Allocate stack memory */
691 : 0 : stack_size = (block_count + lf->stack_pg_ptrs - 1) / lf->stack_pg_ptrs;
692 : 0 : alloc_size = stack_size * lf->stack_pg_bytes;
693 : :
694 : 0 : mz = npa_stack_dma_alloc(lf, name, pool_id, alloc_size);
695 [ # # ]: 0 : if (mz == NULL) {
696 : : rc = NPA_ERR_ALLOC;
697 : 0 : goto aura_res_put;
698 : : }
699 : :
700 : : /* Update aura fields */
701 : 0 : aura->pool_addr = pool_id; /* AF will translate to associated poolctx */
702 [ # # ]: 0 : aura->ena = 1;
703 : 0 : aura->shift = plt_log2_u32(block_count);
704 [ # # ]: 0 : aura->shift = aura->shift < 8 ? 0 : aura->shift - 8;
705 : 0 : aura->limit = block_count;
706 : 0 : aura->pool_caching = 1;
707 : : aura->err_int_ena = BIT(NPA_AURA_ERR_INT_AURA_ADD_OVER);
708 : : aura->err_int_ena |= BIT(NPA_AURA_ERR_INT_AURA_ADD_UNDER);
709 : : aura->err_int_ena |= BIT(NPA_AURA_ERR_INT_AURA_FREE_UNDER);
710 : 0 : aura->err_int_ena |= BIT(NPA_AURA_ERR_INT_POOL_DIS);
711 : 0 : aura->avg_con = 0;
712 : : /* Many to one reduction */
713 : 0 : aura->err_qint_idx = aura_id % lf->qints;
714 : :
715 : : /* Update pool fields */
716 : 0 : pool->stack_base = mz->iova;
717 : 0 : pool->ena = 1;
718 : :
719 : : /* In opaque mode buffer size must be 0 */
720 [ # # ]: 0 : if (!pool->nat_align) {
721 : 0 : pool->buf_size = 0;
722 : : } else {
723 [ # # ]: 0 : uint64_t buf_sz = block_size / ROC_ALIGN;
724 [ # # ]: 0 : if (roc_model_is_cn20k()) {
725 : : __io struct npa_cn20k_pool_s *cn20k_pool =
726 : : (__io struct npa_cn20k_pool_s *)pool;
727 : 0 : cn20k_pool->buf_size = buf_sz;
728 : : } else {
729 : 0 : pool->buf_size = buf_sz;
730 : : }
731 : : }
732 : :
733 : 0 : pool->stack_max_pages = stack_size;
734 : : pool->shift = plt_log2_u32(block_count);
735 : 0 : pool->shift = pool->shift < 8 ? 0 : pool->shift - 8;
736 : 0 : pool->ptr_start = 0;
737 : 0 : pool->ptr_end = ~0;
738 : 0 : pool->stack_caching = 1;
739 : : pool->err_int_ena = BIT(NPA_POOL_ERR_INT_OVFLS);
740 : : pool->err_int_ena |= BIT(NPA_POOL_ERR_INT_RANGE);
741 : 0 : pool->err_int_ena |= BIT(NPA_POOL_ERR_INT_PERR);
742 : 0 : pool->avg_con = 0;
743 : :
744 : : /* Many to one reduction */
745 : 0 : pool->err_qint_idx = pool_id % lf->qints;
746 : :
747 : : /* Issue AURA_INIT and POOL_INIT op */
748 : 0 : rc = npa_aura_pool_init(lf->mbox, aura_id, aura, pool);
749 [ # # ]: 0 : if (rc)
750 : 0 : goto stack_mem_free;
751 : :
752 : 0 : lf->aura_attr[aura_id].shift = aura->shift;
753 : 0 : lf->aura_attr[aura_id].limit = aura->limit;
754 : 0 : lf->aura_attr[aura_id].halo = 0;
755 [ # # ]: 0 : *aura_handle = roc_npa_aura_handle_gen(aura_id, lf->base);
756 : : /* Update aura count */
757 [ # # ]: 0 : roc_npa_aura_op_cnt_set(*aura_handle, 0, block_count);
758 : : /* Read it back to make sure aura count is updated */
759 : : roc_npa_aura_op_cnt_get(*aura_handle);
760 : :
761 : 0 : return 0;
762 : :
763 : : stack_mem_free:
764 : 0 : plt_memzone_free(mz);
765 : 0 : aura_res_put:
766 : 0 : roc_npa_dev_lock();
767 : 0 : plt_bitmap_set(lf->npa_bmp, aura_id);
768 : 0 : roc_npa_dev_unlock();
769 : : exit:
770 : : return rc;
771 : : }
772 : :
773 : : static int
774 : 0 : npa_halo_alloc(struct npa_lf *lf, const uint32_t block_size, const uint32_t block_count,
775 : : struct npa_cn20k_halo_s *halo, uint64_t *aura_handle, uint32_t flags)
776 : : {
777 : : int rc, aura_id, stack_size, alloc_size, pool_id;
778 : : char name[PLT_MEMZONE_NAMESIZE];
779 : : const struct plt_memzone *mz;
780 : :
781 : : /* Sanity check */
782 [ # # # # ]: 0 : if (!lf || !halo || !aura_handle)
783 : : return NPA_ERR_PARAM;
784 : :
785 : 0 : roc_npa_dev_lock();
786 : : /* Get aura_id from resource bitmap */
787 : 0 : aura_id = find_free_aura(lf, flags);
788 [ # # ]: 0 : if (aura_id < 0) {
789 : 0 : roc_npa_dev_unlock();
790 : 0 : return NPA_ERR_AURA_ID_ALLOC;
791 : : }
792 : :
793 : : /* Mark aura as reserved */
794 : 0 : plt_bitmap_clear(lf->npa_bmp, aura_id);
795 : :
796 : 0 : roc_npa_dev_unlock();
797 [ # # ]: 0 : rc = (aura_id < 0 || aura_id >= (int)BIT_ULL(6 + lf->aura_sz)) ? NPA_ERR_AURA_ID_ALLOC : 0;
798 : : if (rc)
799 : 0 : goto exit;
800 : :
801 : : /* Allocate stack memory */
802 : 0 : stack_size = (block_count + lf->stack_pg_ptrs - 1) / lf->stack_pg_ptrs;
803 : 0 : alloc_size = stack_size * lf->stack_pg_bytes;
804 : :
805 : : pool_id = aura_id;
806 : 0 : mz = npa_stack_dma_alloc(lf, name, pool_id, alloc_size);
807 [ # # ]: 0 : if (mz == NULL) {
808 : : rc = NPA_ERR_ALLOC;
809 : 0 : goto aura_res_put;
810 : : }
811 : :
812 : : /* Update halo fields */
813 [ # # ]: 0 : halo->ena = 1;
814 : 0 : halo->shift = plt_log2_u32(block_count);
815 [ # # ]: 0 : halo->shift = halo->shift < 8 ? 0 : halo->shift - 8;
816 : : halo->err_int_ena = BIT(NPA_AURA_ERR_INT_AURA_ADD_OVER);
817 : : halo->err_int_ena |= BIT(NPA_AURA_ERR_INT_AURA_ADD_UNDER);
818 : : halo->err_int_ena |= BIT(NPA_AURA_ERR_INT_AURA_FREE_UNDER);
819 : 0 : halo->err_int_ena |= BIT(NPA_AURA_ERR_INT_POOL_DIS);
820 : 0 : halo->avg_con = 0;
821 : : /* Many to one reduction */
822 : 0 : halo->err_qint_idx = aura_id % lf->qints;
823 : 0 : halo->stack_base = mz->iova;
824 : : /* In opaque mode buffer size must be 0 */
825 [ # # ]: 0 : halo->buf_size = !halo->nat_align ? 0 : block_size / ROC_ALIGN;
826 : 0 : halo->stack_max_pages = stack_size;
827 : 0 : halo->ptr_start = 0;
828 : 0 : halo->ptr_end = ~0;
829 : 0 : halo->stack_caching = 1;
830 : 0 : halo->unified_ctx = 1;
831 : :
832 : : /* Issue HALO_INIT op */
833 : 0 : rc = npa_halo_init(lf->mbox, aura_id, halo);
834 [ # # ]: 0 : if (rc)
835 : 0 : goto stack_mem_free;
836 : :
837 : 0 : lf->aura_attr[aura_id].shift = halo->shift;
838 : 0 : lf->aura_attr[aura_id].halo = 1;
839 : 0 : *aura_handle = roc_npa_aura_handle_gen(aura_id, lf->base);
840 : :
841 : 0 : return 0;
842 : :
843 : : stack_mem_free:
844 : 0 : plt_memzone_free(mz);
845 : 0 : aura_res_put:
846 : 0 : roc_npa_dev_lock();
847 : 0 : plt_bitmap_set(lf->npa_bmp, aura_id);
848 : 0 : roc_npa_dev_unlock();
849 : : exit:
850 : : return rc;
851 : : }
852 : :
853 : : int
854 : 0 : roc_npa_pool_create(uint64_t *aura_handle, uint32_t block_size,
855 : : uint32_t block_count, struct npa_aura_s *aura,
856 : : struct npa_pool_s *pool, uint32_t flags)
857 : : {
858 : : struct npa_aura_s defaura;
859 : : struct npa_pool_s defpool;
860 : : struct idev_cfg *idev;
861 : : struct npa_lf *lf;
862 : : int rc;
863 : :
864 : 0 : lf = idev_npa_obj_get();
865 [ # # ]: 0 : if (lf == NULL) {
866 : : rc = NPA_ERR_DEVICE_NOT_BOUNDED;
867 : 0 : goto error;
868 : : }
869 : :
870 : 0 : idev = idev_get_cfg();
871 [ # # ]: 0 : if (idev == NULL) {
872 : : rc = NPA_ERR_ALLOC;
873 : 0 : goto error;
874 : : }
875 : :
876 [ # # # # ]: 0 : if (flags & ROC_NPA_ZERO_AURA_F && !lf->zero_aura_rsvd) {
877 : : rc = NPA_ERR_ALLOC;
878 : 0 : goto error;
879 : : }
880 : :
881 [ # # ]: 0 : if (aura == NULL) {
882 : : memset(&defaura, 0, sizeof(struct npa_aura_s));
883 : : aura = &defaura;
884 : : }
885 [ # # ]: 0 : if (pool == NULL) {
886 : : memset(&defpool, 0, sizeof(struct npa_pool_s));
887 : 0 : defpool.nat_align = 1;
888 : 0 : defpool.buf_offset = 1;
889 : : pool = &defpool;
890 : : }
891 : :
892 [ # # ]: 0 : if (flags & ROC_NPA_FORCE_OPAQUE_MODE_F)
893 : 0 : pool->nat_align = 0;
894 : :
895 : : /* The pool argument will be a pointer to a npa_cn20k_halo_s structure
896 : : * when ROC_NPA_HALO_F flag is set. Note that halo and pool contexts
897 : : * are same in size and the fields that are modified here are 1:1
898 : : * mapped in these structures.
899 : : */
900 [ # # # # ]: 0 : if (roc_feature_npa_has_halo() && (flags & ROC_NPA_HALO_F)) {
901 : : struct npa_cn20k_halo_s *halo = (struct npa_cn20k_halo_s *)pool;
902 : 0 : rc = npa_halo_alloc(lf, block_size, block_count, halo, aura_handle, flags);
903 : : } else {
904 : 0 : rc = npa_aura_pool_pair_alloc(lf, block_size, block_count, aura, pool,
905 : : aura_handle, flags);
906 : : }
907 : :
908 [ # # ]: 0 : if (rc) {
909 : 0 : plt_err("Failed to alloc pool/aura/halo rc=%d", rc);
910 : 0 : goto error;
911 : : }
912 : :
913 : 0 : plt_npa_dbg("lf=%p block_sz=%d block_count=%d aura_handle=0x%" PRIx64,
914 : : lf, block_size, block_count, *aura_handle);
915 : :
916 : : /* Just hold the reference of the object */
917 : 0 : __atomic_fetch_add(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST);
918 : 0 : error:
919 : 0 : return rc;
920 : : }
921 : :
922 : : static int
923 : 0 : npa_aura_alloc(struct npa_lf *lf, const uint32_t block_count, int pool_id,
924 : : struct npa_aura_s *aura, uint64_t *aura_handle, uint32_t flags)
925 : : {
926 : : int rc, aura_id;
927 : :
928 : : /* Sanity check */
929 [ # # # # ]: 0 : if (!lf || !aura || !aura_handle)
930 : : return NPA_ERR_PARAM;
931 : :
932 : 0 : roc_npa_dev_lock();
933 : : /* Get aura_id from resource bitmap */
934 : 0 : aura_id = find_free_aura(lf, flags);
935 [ # # ]: 0 : if (aura_id < 0) {
936 : 0 : roc_npa_dev_unlock();
937 : 0 : return NPA_ERR_AURA_ID_ALLOC;
938 : : }
939 : :
940 : : /* Mark aura as reserved */
941 : 0 : plt_bitmap_clear(lf->npa_bmp, aura_id);
942 : :
943 : 0 : roc_npa_dev_unlock();
944 [ # # ]: 0 : rc = (aura_id < 0 || pool_id >= (int)lf->nr_pools ||
945 [ # # ]: 0 : aura_id >= (int)BIT_ULL(6 + lf->aura_sz)) ?
946 : : NPA_ERR_AURA_ID_ALLOC :
947 : : 0;
948 : : if (rc)
949 : 0 : goto exit;
950 : :
951 : : /* Update aura fields */
952 : 0 : aura->pool_addr = pool_id; /* AF will translate to associated poolctx */
953 [ # # ]: 0 : aura->ena = 1;
954 : 0 : aura->shift = plt_log2_u32(block_count);
955 [ # # ]: 0 : aura->shift = aura->shift < 8 ? 0 : aura->shift - 8;
956 : 0 : aura->limit = block_count;
957 : 0 : aura->pool_caching = 1;
958 : : aura->err_int_ena = BIT(NPA_AURA_ERR_INT_AURA_ADD_OVER);
959 : : aura->err_int_ena |= BIT(NPA_AURA_ERR_INT_AURA_ADD_UNDER);
960 : : aura->err_int_ena |= BIT(NPA_AURA_ERR_INT_AURA_FREE_UNDER);
961 : 0 : aura->err_int_ena |= BIT(NPA_AURA_ERR_INT_POOL_DIS);
962 : 0 : aura->avg_con = 0;
963 : : /* Many to one reduction */
964 : 0 : aura->err_qint_idx = aura_id % lf->qints;
965 : :
966 : : /* Issue AURA_INIT op */
967 : 0 : rc = npa_aura_init(lf->mbox, aura_id, aura);
968 [ # # ]: 0 : if (rc)
969 : : return rc;
970 : :
971 : 0 : lf->aura_attr[aura_id].shift = aura->shift;
972 : 0 : lf->aura_attr[aura_id].limit = aura->limit;
973 : 0 : *aura_handle = roc_npa_aura_handle_gen(aura_id, lf->base);
974 : :
975 : 0 : return 0;
976 : :
977 : : exit:
978 : 0 : return rc;
979 : : }
980 : :
981 : : int
982 : 0 : roc_npa_aura_create(uint64_t *aura_handle, uint32_t block_count,
983 : : struct npa_aura_s *aura, int pool_id, uint32_t flags)
984 : : {
985 : : struct npa_aura_s defaura;
986 : : struct idev_cfg *idev;
987 : : struct npa_lf *lf;
988 : : int rc;
989 : :
990 : 0 : lf = idev_npa_obj_get();
991 [ # # ]: 0 : if (lf == NULL) {
992 : : rc = NPA_ERR_DEVICE_NOT_BOUNDED;
993 : 0 : goto error;
994 : : }
995 : :
996 : 0 : idev = idev_get_cfg();
997 [ # # ]: 0 : if (idev == NULL) {
998 : : rc = NPA_ERR_ALLOC;
999 : 0 : goto error;
1000 : : }
1001 : :
1002 [ # # # # ]: 0 : if (flags & ROC_NPA_ZERO_AURA_F && !lf->zero_aura_rsvd) {
1003 : : rc = NPA_ERR_ALLOC;
1004 : 0 : goto error;
1005 : : }
1006 : :
1007 [ # # ]: 0 : if (aura == NULL) {
1008 : : memset(&defaura, 0, sizeof(struct npa_aura_s));
1009 : : aura = &defaura;
1010 : : }
1011 : :
1012 : 0 : rc = npa_aura_alloc(lf, block_count, pool_id, aura, aura_handle, flags);
1013 [ # # ]: 0 : if (rc) {
1014 : 0 : plt_err("Failed to alloc aura rc=%d", rc);
1015 : 0 : goto error;
1016 : : }
1017 : :
1018 : 0 : plt_npa_dbg("lf=%p aura_handle=0x%" PRIx64, lf, *aura_handle);
1019 : :
1020 : : /* Just hold the reference of the object */
1021 : 0 : __atomic_fetch_add(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST);
1022 : 0 : error:
1023 : 0 : return rc;
1024 : : }
1025 : :
1026 : : int
1027 : 0 : roc_npa_aura_limit_modify(uint64_t aura_handle, uint16_t aura_limit)
1028 : : {
1029 : : struct npa_aq_enq_req *aura_req;
1030 : : struct npa_lf *lf;
1031 : : struct mbox *mbox;
1032 : : int rc;
1033 : :
1034 : 0 : lf = idev_npa_obj_get();
1035 [ # # ]: 0 : if (lf == NULL)
1036 : : return NPA_ERR_DEVICE_NOT_BOUNDED;
1037 : :
1038 : 0 : mbox = mbox_get(lf->mbox);
1039 [ # # ]: 0 : if (roc_model_is_cn20k()) {
1040 : : struct npa_cn20k_aq_enq_req *aura_req_cn20k;
1041 : 0 : aura_req_cn20k = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
1042 : : aura_req = (struct npa_aq_enq_req *)aura_req_cn20k;
1043 : : } else {
1044 : 0 : aura_req = mbox_alloc_msg_npa_aq_enq(mbox);
1045 : : }
1046 [ # # ]: 0 : if (aura_req == NULL) {
1047 : : rc = -ENOMEM;
1048 : 0 : goto exit;
1049 : : }
1050 : 0 : aura_req->aura_id = roc_npa_aura_handle_to_aura(aura_handle);
1051 : 0 : aura_req->ctype = NPA_AQ_CTYPE_AURA;
1052 : 0 : aura_req->op = NPA_AQ_INSTOP_WRITE;
1053 : :
1054 : 0 : aura_req->aura.limit = aura_limit;
1055 : 0 : aura_req->aura_mask.limit = ~(aura_req->aura_mask.limit);
1056 : 0 : rc = mbox_process(mbox);
1057 [ # # ]: 0 : if (rc)
1058 : 0 : goto exit;
1059 : 0 : lf->aura_attr[aura_req->aura_id].limit = aura_req->aura.limit;
1060 : 0 : exit:
1061 : : mbox_put(mbox);
1062 : 0 : return rc;
1063 : : }
1064 : :
1065 : : static int
1066 : 0 : npa_halo_free(struct npa_lf *lf, uint64_t aura_handle)
1067 : : {
1068 : : char name[PLT_MEMZONE_NAMESIZE];
1069 : : int aura_id, pool_id, rc;
1070 : :
1071 [ # # ]: 0 : if (!lf || !aura_handle)
1072 : : return NPA_ERR_PARAM;
1073 : :
1074 : 0 : aura_id = roc_npa_aura_handle_to_aura(aura_handle);
1075 : : pool_id = aura_id;
1076 : 0 : rc = npa_halo_fini(lf->mbox, aura_id, aura_handle);
1077 : 0 : rc |= npa_stack_dma_free(lf, name, pool_id);
1078 : 0 : memset(&lf->aura_attr[aura_id], 0, sizeof(struct npa_aura_attr));
1079 : :
1080 : 0 : roc_npa_dev_lock();
1081 : 0 : plt_bitmap_set(lf->npa_bmp, aura_id);
1082 : 0 : roc_npa_dev_unlock();
1083 : :
1084 : 0 : return rc;
1085 : : }
1086 : :
1087 : : static int
1088 : 0 : npa_aura_pool_pair_free(struct npa_lf *lf, uint64_t aura_handle)
1089 : : {
1090 : : char name[PLT_MEMZONE_NAMESIZE];
1091 : : int aura_id, pool_id, rc;
1092 : :
1093 [ # # ]: 0 : if (!lf || !aura_handle)
1094 : : return NPA_ERR_PARAM;
1095 : :
1096 : 0 : aura_id = roc_npa_aura_handle_to_aura(aura_handle);
1097 : : pool_id = aura_id;
1098 : 0 : rc = npa_aura_pool_fini(lf->mbox, aura_id, aura_handle);
1099 : 0 : rc |= npa_stack_dma_free(lf, name, pool_id);
1100 : 0 : memset(&lf->aura_attr[aura_id], 0, sizeof(struct npa_aura_attr));
1101 : :
1102 : 0 : roc_npa_dev_lock();
1103 : 0 : plt_bitmap_set(lf->npa_bmp, aura_id);
1104 : 0 : roc_npa_dev_unlock();
1105 : :
1106 : 0 : return rc;
1107 : : }
1108 : :
1109 : : int
1110 : 0 : roc_npa_pool_destroy(uint64_t aura_handle)
1111 : : {
1112 : 0 : struct npa_lf *lf = idev_npa_obj_get();
1113 : : int rc = 0, aura_id;
1114 : :
1115 [ # # ]: 0 : if (lf == NULL)
1116 : : return NPA_ERR_DEVICE_NOT_BOUNDED;
1117 : :
1118 : 0 : plt_npa_dbg("lf=%p aura_handle=0x%" PRIx64, lf, aura_handle);
1119 : : aura_id = roc_npa_aura_handle_to_aura(aura_handle);
1120 : :
1121 [ # # ]: 0 : if (lf->aura_attr[aura_id].halo)
1122 : 0 : rc = npa_halo_free(lf, aura_handle);
1123 : : else
1124 : 0 : rc = npa_aura_pool_pair_free(lf, aura_handle);
1125 : :
1126 [ # # ]: 0 : if (rc)
1127 : 0 : plt_err("Failed to destroy pool/aura/halo rc=%d", rc);
1128 : :
1129 : : /* Release the reference of npa */
1130 : 0 : rc |= npa_lf_fini();
1131 : 0 : return rc;
1132 : : }
1133 : :
1134 : : static int
1135 : 0 : npa_aura_free(struct npa_lf *lf, uint64_t aura_handle)
1136 : : {
1137 : : int aura_id, rc;
1138 : :
1139 [ # # ]: 0 : if (!lf || !aura_handle)
1140 : : return NPA_ERR_PARAM;
1141 : :
1142 : : aura_id = roc_npa_aura_handle_to_aura(aura_handle);
1143 : 0 : rc = npa_aura_fini(lf->mbox, aura_id);
1144 : :
1145 [ # # ]: 0 : if (rc)
1146 : : return rc;
1147 : :
1148 : 0 : memset(&lf->aura_attr[aura_id], 0, sizeof(struct npa_aura_attr));
1149 : :
1150 : 0 : roc_npa_dev_lock();
1151 : 0 : plt_bitmap_set(lf->npa_bmp, aura_id);
1152 : 0 : roc_npa_dev_unlock();
1153 : :
1154 : 0 : return rc;
1155 : : }
1156 : :
1157 : : int
1158 : 0 : roc_npa_aura_destroy(uint64_t aura_handle)
1159 : : {
1160 : 0 : struct npa_lf *lf = idev_npa_obj_get();
1161 : : int rc = 0;
1162 : :
1163 : 0 : plt_npa_dbg("lf=%p aura_handle=0x%" PRIx64, lf, aura_handle);
1164 : 0 : rc = npa_aura_free(lf, aura_handle);
1165 [ # # ]: 0 : if (rc)
1166 : 0 : plt_err("Failed to destroy aura rc=%d", rc);
1167 : :
1168 : : /* Release the reference of npa */
1169 : 0 : rc |= npa_lf_fini();
1170 : 0 : return rc;
1171 : : }
1172 : :
1173 : : int
1174 : 0 : roc_npa_pool_range_update_check(uint64_t aura_handle)
1175 : : {
1176 : : __io struct npa_pool_s *pool;
1177 : : struct npa_aq_enq_req *req;
1178 : : struct npa_aq_enq_rsp *rsp;
1179 : : struct npa_aura_lim *lim;
1180 : : struct mbox *mbox;
1181 : : struct npa_lf *lf;
1182 : : uint64_t aura_id;
1183 : : int rc;
1184 : :
1185 : 0 : lf = idev_npa_obj_get();
1186 [ # # ]: 0 : if (lf == NULL)
1187 : : return NPA_ERR_PARAM;
1188 : :
1189 : 0 : lim = lf->aura_lim;
1190 : :
1191 : 0 : mbox = mbox_get(lf->mbox);
1192 [ # # ]: 0 : if (roc_model_is_cn20k()) {
1193 : : struct npa_cn20k_aq_enq_req *req_cn20k;
1194 : 0 : req_cn20k = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
1195 : : req = (struct npa_aq_enq_req *)req_cn20k;
1196 : : } else {
1197 : 0 : req = mbox_alloc_msg_npa_aq_enq(mbox);
1198 : : }
1199 [ # # ]: 0 : if (req == NULL) {
1200 : : rc = -ENOSPC;
1201 : 0 : goto exit;
1202 : : }
1203 : :
1204 : : aura_id = roc_npa_aura_handle_to_aura(aura_handle);
1205 : 0 : req->aura_id = aura_id;
1206 [ # # ]: 0 : if (lf->aura_attr[aura_id].halo)
1207 : 0 : req->ctype = NPA_AQ_CTYPE_HALO;
1208 : : else
1209 : 0 : req->ctype = NPA_AQ_CTYPE_POOL;
1210 : 0 : req->op = NPA_AQ_INSTOP_READ;
1211 : :
1212 : : rc = mbox_process_msg(mbox, (void *)&rsp);
1213 [ # # ]: 0 : if (rc) {
1214 : 0 : plt_err("Failed to get pool(0x%" PRIx64 ") context", aura_id);
1215 : 0 : goto exit;
1216 : : }
1217 : :
1218 : 0 : pool = &rsp->pool;
1219 [ # # ]: 0 : if (lim[aura_id].ptr_start != pool->ptr_start ||
1220 [ # # ]: 0 : lim[aura_id].ptr_end != pool->ptr_end) {
1221 : 0 : plt_err("Range update failed on pool(0x%" PRIx64 ")", aura_id);
1222 : : rc = NPA_ERR_PARAM;
1223 : 0 : goto exit;
1224 : : }
1225 : :
1226 : : rc = 0;
1227 : 0 : exit:
1228 : : mbox_put(mbox);
1229 : 0 : return rc;
1230 : : }
1231 : :
1232 : : uint64_t
1233 : 0 : roc_npa_zero_aura_handle(void)
1234 : : {
1235 : : struct idev_cfg *idev;
1236 : : struct npa_lf *lf;
1237 : :
1238 : 0 : lf = idev_npa_obj_get();
1239 [ # # ]: 0 : if (lf == NULL)
1240 : : return NPA_ERR_DEVICE_NOT_BOUNDED;
1241 : :
1242 : 0 : idev = idev_get_cfg();
1243 [ # # ]: 0 : if (idev == NULL)
1244 : : return NPA_ERR_ALLOC;
1245 : :
1246 : : /* Return aura handle only if reserved */
1247 [ # # ]: 0 : if (lf->zero_aura_rsvd)
1248 : 0 : return roc_npa_aura_handle_gen(0, lf->base);
1249 : : return 0;
1250 : : }
1251 : :
1252 : : int
1253 : 0 : roc_npa_pool_bp_configure(uint64_t aura_handle, uint16_t bpid, uint8_t bp_thresh, uint8_t bp_class,
1254 : : bool enable)
1255 : : {
1256 : 0 : uint32_t pool_id = roc_npa_aura_handle_to_aura(aura_handle);
1257 : 0 : struct npa_lf *lf = idev_npa_obj_get();
1258 : : struct npa_cn20k_aq_enq_req *aq;
1259 : : uint8_t bp, bp_ena;
1260 : : struct mbox *mbox;
1261 : : int rc = 0;
1262 : :
1263 : 0 : plt_npa_dbg("Setting BPID %u BP_CLASS %u enable %u on pool %" PRIx64, bpid, bp_class,
1264 : : bp_thresh, aura_handle);
1265 : :
1266 [ # # ]: 0 : if (lf == NULL)
1267 : : return NPA_ERR_PARAM;
1268 : :
1269 : 0 : mbox = mbox_get(lf->mbox);
1270 : 0 : aq = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
1271 [ # # ]: 0 : if (aq == NULL) {
1272 : : rc = -ENOSPC;
1273 : 0 : goto fail;
1274 : : }
1275 : :
1276 : 0 : aq->aura_id = pool_id;
1277 : 0 : aq->ctype = NPA_AQ_CTYPE_POOL;
1278 : 0 : aq->op = NPA_AQ_INSTOP_WRITE;
1279 : :
1280 [ # # ]: 0 : if (enable) {
1281 : 0 : aq->pool.bpid_0 = bpid;
1282 : 0 : aq->pool_mask.bpid_0 = ~(aq->pool_mask.bpid_0);
1283 : :
1284 : : bp = bp_thresh;
1285 : : } else {
1286 : : bp = 0;
1287 : : }
1288 : :
1289 [ # # # # : 0 : switch (bp_class) {
# # # #
# ]
1290 : 0 : case 0:
1291 : 0 : aq->pool.bp_0 = bp;
1292 : 0 : aq->pool_mask.bp_0 = ~(aq->pool_mask.bp_0);
1293 : 0 : aq->pool.bp_ena_0 = enable;
1294 : 0 : aq->pool_mask.bp_ena_0 = ~(aq->pool_mask.bp_ena_0);
1295 : 0 : break;
1296 : 0 : case 1:
1297 : 0 : aq->pool.bp_1 = bp;
1298 : 0 : aq->pool_mask.bp_1 = ~(aq->pool_mask.bp_1);
1299 : 0 : aq->pool.bp_ena_1 = enable;
1300 : 0 : aq->pool_mask.bp_ena_1 = ~(aq->pool_mask.bp_ena_1);
1301 : 0 : break;
1302 : 0 : case 2:
1303 : 0 : aq->pool.bp_2 = bp;
1304 : 0 : aq->pool_mask.bp_2 = ~(aq->pool_mask.bp_2);
1305 : 0 : aq->pool.bp_ena_2 = enable;
1306 : 0 : aq->pool_mask.bp_ena_2 = ~(aq->pool_mask.bp_ena_2);
1307 : 0 : break;
1308 : 0 : case 3:
1309 : 0 : aq->pool.bp_3 = bp;
1310 : 0 : aq->pool_mask.bp_3 = ~(aq->pool_mask.bp_3);
1311 : 0 : aq->pool.bp_ena_3 = enable;
1312 : 0 : aq->pool_mask.bp_ena_3 = ~(aq->pool_mask.bp_ena_3);
1313 : 0 : break;
1314 : 0 : case 4:
1315 : 0 : aq->pool.bp_4 = bp;
1316 : 0 : aq->pool_mask.bp_4 = ~(aq->pool_mask.bp_4);
1317 : 0 : aq->pool.bp_ena_4 = enable;
1318 : 0 : aq->pool_mask.bp_ena_4 = ~(aq->pool_mask.bp_ena_4);
1319 : 0 : break;
1320 : 0 : case 5:
1321 : 0 : aq->pool.bp_5 = bp;
1322 : 0 : aq->pool_mask.bp_5 = ~(aq->pool_mask.bp_5);
1323 : 0 : aq->pool.bp_ena_5 = enable;
1324 : 0 : aq->pool_mask.bp_ena_5 = ~(aq->pool_mask.bp_ena_5);
1325 : 0 : break;
1326 : 0 : case 6:
1327 : 0 : aq->pool.bp_6 = bp;
1328 : 0 : aq->pool_mask.bp_6 = ~(aq->pool_mask.bp_6);
1329 : 0 : aq->pool.bp_ena_6 = enable;
1330 : 0 : aq->pool_mask.bp_ena_6 = ~(aq->pool_mask.bp_ena_6);
1331 : 0 : break;
1332 : 0 : case 7:
1333 : 0 : aq->pool.bp_7 = bp;
1334 : 0 : aq->pool_mask.bp_7 = ~(aq->pool_mask.bp_7);
1335 : 0 : aq->pool.bp_ena_7 = enable;
1336 : 0 : aq->pool_mask.bp_ena_7 = ~(aq->pool_mask.bp_ena_7);
1337 : 0 : break;
1338 : 0 : default:
1339 : : rc = -EINVAL;
1340 : 0 : goto fail;
1341 : : }
1342 : :
1343 : 0 : rc = mbox_process(mbox);
1344 [ # # ]: 0 : if (rc)
1345 : 0 : goto fail;
1346 : :
1347 : 0 : bp_ena = lf->aura_attr[pool_id].bp_ena;
1348 : 0 : bp_ena &= ~(1 << bp_class);
1349 : 0 : bp_ena |= (enable << bp_class);
1350 : :
1351 [ # # # # ]: 0 : if (enable && !lf->aura_attr[pool_id].bp_ena)
1352 : 0 : lf->aura_attr[pool_id].nix0_bpid = bpid;
1353 [ # # # # ]: 0 : else if (!enable && !lf->aura_attr[pool_id].bp_ena)
1354 : 0 : lf->aura_attr[pool_id].nix0_bpid = 0;
1355 : :
1356 : 0 : lf->aura_attr[pool_id].bp_ena = bp_ena;
1357 : 0 : lf->aura_attr[pool_id].bp_thresh[bp_class] = bp;
1358 : :
1359 : 0 : fail:
1360 : : mbox_put(mbox);
1361 : 0 : return rc;
1362 : : }
1363 : :
1364 : : int
1365 : 0 : roc_npa_aura_bp_configure(uint64_t aura_handle, uint16_t bpid, uint8_t bp_intf, uint8_t bp_thresh,
1366 : : bool enable)
1367 : : {
1368 : 0 : uint32_t aura_id = roc_npa_aura_handle_to_aura(aura_handle);
1369 : 0 : struct npa_lf *lf = idev_npa_obj_get();
1370 : : struct npa_aq_enq_req *req;
1371 : : struct mbox *mbox;
1372 : : int rc = 0;
1373 : :
1374 : 0 : plt_npa_dbg("Setting BPID %u BP_INTF 0x%x BP_THRESH %u enable %u on aura %" PRIx64,
1375 : : bpid, bp_intf, bp_thresh, enable, aura_handle);
1376 : :
1377 [ # # ]: 0 : if (lf == NULL)
1378 : : return NPA_ERR_PARAM;
1379 : :
1380 : 0 : mbox = mbox_get(lf->mbox);
1381 : 0 : req = mbox_alloc_msg_npa_aq_enq(mbox);
1382 [ # # ]: 0 : if (req == NULL) {
1383 : : rc = -ENOMEM;
1384 : 0 : goto fail;
1385 : : }
1386 : :
1387 : 0 : req->aura_id = aura_id;
1388 : 0 : req->ctype = NPA_AQ_CTYPE_AURA;
1389 : 0 : req->op = NPA_AQ_INSTOP_WRITE;
1390 : :
1391 [ # # ]: 0 : if (enable) {
1392 [ # # ]: 0 : if (bp_intf & 0x1) {
1393 : 0 : req->aura.nix0_bpid = bpid;
1394 : 0 : req->aura_mask.nix0_bpid = ~(req->aura_mask.nix0_bpid);
1395 : : } else {
1396 : 0 : req->aura.nix1_bpid = bpid;
1397 : 0 : req->aura_mask.nix1_bpid = ~(req->aura_mask.nix1_bpid);
1398 : : }
1399 : 0 : req->aura.bp = bp_thresh;
1400 : 0 : req->aura_mask.bp = ~(req->aura_mask.bp);
1401 : : } else {
1402 : 0 : req->aura.bp = 0;
1403 : 0 : req->aura_mask.bp = ~(req->aura_mask.bp);
1404 : : }
1405 : :
1406 : 0 : req->aura.bp_ena = bp_intf;
1407 : 0 : req->aura_mask.bp_ena = ~(req->aura_mask.bp_ena);
1408 : :
1409 : 0 : rc = mbox_process(mbox);
1410 [ # # ]: 0 : if (rc)
1411 : 0 : goto fail;
1412 : :
1413 : 0 : lf->aura_attr[aura_id].nix0_bpid = req->aura.nix0_bpid;
1414 : 0 : lf->aura_attr[aura_id].nix1_bpid = req->aura.nix1_bpid;
1415 : 0 : lf->aura_attr[aura_id].bp_ena = req->aura.bp_ena;
1416 : 0 : lf->aura_attr[aura_id].bp = req->aura.bp;
1417 : 0 : fail:
1418 : : mbox_put(mbox);
1419 : 0 : return rc;
1420 : : }
1421 : :
1422 : : static inline int
1423 : 0 : npa_attach(struct mbox *m_box)
1424 : : {
1425 : : struct mbox *mbox = mbox_get(m_box);
1426 : : struct rsrc_attach_req *req;
1427 : : int rc;
1428 : :
1429 : 0 : req = mbox_alloc_msg_attach_resources(mbox);
1430 [ # # ]: 0 : if (req == NULL) {
1431 : : rc = -ENOSPC;
1432 : 0 : goto exit;
1433 : : }
1434 : 0 : req->modify = true;
1435 : 0 : req->npalf = true;
1436 : :
1437 : 0 : rc = mbox_process(mbox);
1438 : 0 : exit:
1439 : : mbox_put(mbox);
1440 : 0 : return rc;
1441 : : }
1442 : :
1443 : : static inline int
1444 : 0 : npa_detach(struct mbox *m_box)
1445 : : {
1446 : : struct mbox *mbox = mbox_get(m_box);
1447 : : struct rsrc_detach_req *req;
1448 : : int rc;
1449 : :
1450 : 0 : req = mbox_alloc_msg_detach_resources(mbox);
1451 [ # # ]: 0 : if (req == NULL) {
1452 : : rc = -ENOSPC;
1453 : 0 : goto exit;
1454 : : }
1455 : 0 : req->partial = true;
1456 : 0 : req->npalf = true;
1457 : :
1458 : 0 : rc = mbox_process(mbox);
1459 : 0 : exit:
1460 : : mbox_put(mbox);
1461 : 0 : return rc;
1462 : : }
1463 : :
1464 : : static inline int
1465 : 0 : npa_get_msix_offset(struct mbox *m_box, uint16_t *npa_msixoff)
1466 : : {
1467 : : struct mbox *mbox = mbox_get(m_box);
1468 : : struct msix_offset_rsp *msix_rsp;
1469 : : int rc;
1470 : :
1471 : : /* Initialize msixoff */
1472 : 0 : *npa_msixoff = 0;
1473 : : /* Get NPA MSIX vector offsets */
1474 : 0 : mbox_alloc_msg_msix_offset(mbox);
1475 : : rc = mbox_process_msg(mbox, (void *)&msix_rsp);
1476 [ # # ]: 0 : if (rc == 0)
1477 : 0 : *npa_msixoff = msix_rsp->npa_msixoff;
1478 : :
1479 : : mbox_put(mbox);
1480 : 0 : return rc;
1481 : : }
1482 : :
1483 : : static inline int
1484 : 0 : npa_lf_alloc(struct npa_lf *lf)
1485 : : {
1486 : 0 : struct mbox *mbox = mbox_get(lf->mbox);
1487 : : struct npa_lf_alloc_req *req;
1488 : : struct npa_lf_alloc_rsp *rsp;
1489 : : int rc;
1490 : :
1491 : 0 : req = mbox_alloc_msg_npa_lf_alloc(mbox);
1492 [ # # ]: 0 : if (req == NULL) {
1493 : : rc = -ENOSPC;
1494 : 0 : goto exit;
1495 : : }
1496 : 0 : req->aura_sz = lf->aura_sz;
1497 : 0 : req->nr_pools = lf->nr_pools;
1498 : :
1499 : : rc = mbox_process_msg(mbox, (void *)&rsp);
1500 [ # # ]: 0 : if (rc) {
1501 : : rc = NPA_ERR_ALLOC;
1502 : 0 : goto exit;
1503 : : }
1504 : :
1505 : 0 : lf->stack_pg_ptrs = rsp->stack_pg_ptrs;
1506 : 0 : lf->stack_pg_bytes = rsp->stack_pg_bytes;
1507 : 0 : lf->qints = rsp->qints;
1508 : :
1509 : : rc = 0;
1510 : 0 : exit:
1511 : : mbox_put(mbox);
1512 : 0 : return rc;
1513 : : }
1514 : :
1515 : : static int
1516 : 0 : npa_lf_free(struct mbox *mail_box)
1517 : : {
1518 : : struct mbox *mbox = mbox_get(mail_box);
1519 : : int rc;
1520 : :
1521 : 0 : mbox_alloc_msg_npa_lf_free(mbox);
1522 : 0 : rc = mbox_process(mbox);
1523 : : mbox_put(mbox);
1524 : 0 : return rc;
1525 : : }
1526 : :
1527 : : static inline uint32_t
1528 : : aura_size_to_u32(uint8_t val)
1529 : : {
1530 : : if (val == NPA_AURA_SZ_0)
1531 : : return 128;
1532 : : if (val >= NPA_AURA_SZ_MAX)
1533 : : return BIT_ULL(20);
1534 : :
1535 : : return 1 << (val + 6);
1536 : : }
1537 : :
1538 : : static inline void
1539 : 0 : pool_count_aura_sz_get(uint32_t *nr_pools, uint8_t *aura_sz)
1540 : : {
1541 : : uint32_t val;
1542 : :
1543 : 0 : val = roc_idev_npa_maxpools_get();
1544 : : if (val < aura_size_to_u32(NPA_AURA_SZ_128))
1545 : : val = 128;
1546 : : if (val > aura_size_to_u32(NPA_AURA_SZ_1M))
1547 : : val = BIT_ULL(20);
1548 : :
1549 : 0 : roc_idev_npa_maxpools_set(val);
1550 : 0 : *nr_pools = val;
1551 : 0 : *aura_sz = plt_log2_u32(val) - 6;
1552 : 0 : }
1553 : :
1554 : : static int
1555 : 0 : npa_dev_init(struct npa_lf *lf, uintptr_t base, struct mbox *mbox)
1556 : : {
1557 : : uint32_t i, bmp_sz, nr_pools;
1558 : : uint8_t aura_sz;
1559 : : int rc;
1560 : :
1561 : : /* Sanity checks */
1562 [ # # # # ]: 0 : if (!lf || !base || !mbox)
1563 : : return NPA_ERR_PARAM;
1564 : :
1565 [ # # ]: 0 : if (base & ROC_AURA_ID_MASK)
1566 : : return NPA_ERR_BASE_INVALID;
1567 : :
1568 : 0 : pool_count_aura_sz_get(&nr_pools, &aura_sz);
1569 [ # # ]: 0 : if (aura_sz == NPA_AURA_SZ_0 || aura_sz >= NPA_AURA_SZ_MAX)
1570 : : return NPA_ERR_PARAM;
1571 : :
1572 : : memset(lf, 0x0, sizeof(*lf));
1573 : 0 : lf->base = base;
1574 : 0 : lf->aura_sz = aura_sz;
1575 : 0 : lf->nr_pools = nr_pools;
1576 : 0 : lf->mbox = mbox;
1577 : :
1578 : 0 : rc = npa_lf_alloc(lf);
1579 [ # # ]: 0 : if (rc)
1580 : 0 : goto exit;
1581 : :
1582 : 0 : bmp_sz = plt_bitmap_get_memory_footprint(nr_pools);
1583 : :
1584 : : /* Allocate memory for bitmap */
1585 : 0 : lf->npa_bmp_mem = plt_zmalloc(bmp_sz, ROC_ALIGN);
1586 [ # # ]: 0 : if (lf->npa_bmp_mem == NULL) {
1587 : : rc = NPA_ERR_ALLOC;
1588 : 0 : goto lf_free;
1589 : : }
1590 : :
1591 : : /* Initialize pool resource bitmap array */
1592 : 0 : lf->npa_bmp = plt_bitmap_init(nr_pools, lf->npa_bmp_mem, bmp_sz);
1593 [ # # ]: 0 : if (lf->npa_bmp == NULL) {
1594 : : rc = NPA_ERR_PARAM;
1595 : 0 : goto bmap_mem_free;
1596 : : }
1597 : :
1598 : : /* Mark all pools available */
1599 [ # # ]: 0 : for (i = 0; i < nr_pools; i++)
1600 : 0 : plt_bitmap_set(lf->npa_bmp, i);
1601 : :
1602 : : /* Reserve zero aura for all models other than CN9K */
1603 [ # # ]: 0 : if (!roc_model_is_cn9k())
1604 : 0 : lf->zero_aura_rsvd = true;
1605 : :
1606 : : /* Allocate memory for qint context */
1607 : 0 : lf->npa_qint_mem = plt_zmalloc(sizeof(struct npa_qint) * nr_pools, 0);
1608 [ # # ]: 0 : if (lf->npa_qint_mem == NULL) {
1609 : : rc = NPA_ERR_ALLOC;
1610 : 0 : goto bmap_free;
1611 : : }
1612 : :
1613 : : /* Allocate memory for nap_aura_lim memory */
1614 : 0 : lf->aura_lim = plt_zmalloc(sizeof(struct npa_aura_lim) * nr_pools, 0);
1615 [ # # ]: 0 : if (lf->aura_lim == NULL) {
1616 : : rc = NPA_ERR_ALLOC;
1617 : 0 : goto qint_free;
1618 : : }
1619 : :
1620 : : /* Allocate per-aura attribute */
1621 : 0 : lf->aura_attr = plt_zmalloc(sizeof(struct npa_aura_attr) * nr_pools, 0);
1622 [ # # ]: 0 : if (lf->aura_attr == NULL) {
1623 : : rc = NPA_ERR_PARAM;
1624 : 0 : goto lim_free;
1625 : : }
1626 : :
1627 : : /* Init aura start & end limits */
1628 [ # # ]: 0 : for (i = 0; i < nr_pools; i++) {
1629 : 0 : lf->aura_lim[i].ptr_start = UINT64_MAX;
1630 : 0 : lf->aura_lim[i].ptr_end = 0x0ull;
1631 : : }
1632 : :
1633 : : return 0;
1634 : :
1635 : : lim_free:
1636 : 0 : plt_free(lf->aura_lim);
1637 : 0 : qint_free:
1638 : 0 : plt_free(lf->npa_qint_mem);
1639 : 0 : bmap_free:
1640 : : plt_bitmap_free(lf->npa_bmp);
1641 : 0 : bmap_mem_free:
1642 : 0 : plt_free(lf->npa_bmp_mem);
1643 : 0 : lf_free:
1644 : 0 : npa_lf_free(lf->mbox);
1645 : : exit:
1646 : : return rc;
1647 : : }
1648 : :
1649 : : static int
1650 : 0 : npa_dev_fini(struct npa_lf *lf)
1651 : : {
1652 [ # # ]: 0 : if (!lf)
1653 : : return NPA_ERR_PARAM;
1654 : :
1655 : 0 : plt_free(lf->aura_lim);
1656 : 0 : plt_free(lf->npa_qint_mem);
1657 : : plt_bitmap_free(lf->npa_bmp);
1658 : 0 : plt_free(lf->npa_bmp_mem);
1659 : 0 : plt_free(lf->aura_attr);
1660 : :
1661 : 0 : return npa_lf_free(lf->mbox);
1662 : : }
1663 : :
1664 : : int
1665 : 0 : npa_lf_init(struct dev *dev, struct plt_pci_device *pci_dev)
1666 : : {
1667 : 0 : uint16_t npa_msixoff = 0;
1668 : : struct idev_cfg *idev;
1669 : : struct npa_lf *lf;
1670 : : int rc;
1671 : :
1672 : 0 : idev = idev_get_cfg();
1673 [ # # ]: 0 : if (idev == NULL)
1674 : : return NPA_ERR_ALLOC;
1675 : :
1676 : : /* Not the first PCI device */
1677 [ # # ]: 0 : if (__atomic_fetch_add(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST) != 0)
1678 : : return 0;
1679 : :
1680 [ # # ]: 0 : if (lf_init_cb) {
1681 : 0 : rc = (*lf_init_cb)(pci_dev);
1682 [ # # ]: 0 : if (rc)
1683 : 0 : goto fail;
1684 : : }
1685 : :
1686 : 0 : rc = npa_attach(dev->mbox);
1687 [ # # ]: 0 : if (rc)
1688 : 0 : goto fail;
1689 : :
1690 : 0 : rc = npa_get_msix_offset(dev->mbox, &npa_msixoff);
1691 [ # # ]: 0 : if (rc)
1692 : 0 : goto npa_detach;
1693 : :
1694 : 0 : lf = &dev->npa;
1695 : 0 : rc = npa_dev_init(lf, dev->bar2 + (RVU_BLOCK_ADDR_NPA << 20),
1696 : : dev->mbox);
1697 [ # # ]: 0 : if (rc)
1698 : 0 : goto npa_detach;
1699 : :
1700 : 0 : lf->pf_func = dev->pf_func;
1701 : 0 : lf->npa_msixoff = npa_msixoff;
1702 : 0 : lf->intr_handle = pci_dev->intr_handle;
1703 : 0 : lf->pci_dev = pci_dev;
1704 : :
1705 : 0 : idev->npa_pf_func = dev->pf_func;
1706 : 0 : idev->npa = lf;
1707 : : plt_wmb();
1708 : :
1709 : 0 : rc = npa_register_irqs(lf);
1710 [ # # ]: 0 : if (rc)
1711 : 0 : goto npa_fini;
1712 : :
1713 : 0 : plt_npa_dbg("npa=%p max_pools=%d pf_func=0x%x msix=0x%x", lf,
1714 : : roc_idev_npa_maxpools_get(), lf->pf_func, npa_msixoff);
1715 : :
1716 : 0 : return 0;
1717 : :
1718 : : npa_fini:
1719 : 0 : npa_dev_fini(idev->npa);
1720 : 0 : npa_detach:
1721 : 0 : npa_detach(dev->mbox);
1722 : 0 : fail:
1723 : 0 : __atomic_fetch_sub(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST);
1724 : 0 : return rc;
1725 : : }
1726 : :
1727 : : int
1728 : 0 : npa_lf_fini(void)
1729 : : {
1730 : : struct idev_cfg *idev;
1731 : : int rc = 0;
1732 : :
1733 : 0 : idev = idev_get_cfg();
1734 [ # # ]: 0 : if (idev == NULL)
1735 : : return NPA_ERR_ALLOC;
1736 : :
1737 : : /* Not the last PCI device */
1738 [ # # ]: 0 : if (__atomic_fetch_sub(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST) - 1 != 0)
1739 : : return 0;
1740 : :
1741 : 0 : npa_unregister_irqs(idev->npa);
1742 : 0 : rc |= npa_dev_fini(idev->npa);
1743 : 0 : rc |= npa_detach(idev->npa->mbox);
1744 : 0 : idev_set_defaults(idev);
1745 : :
1746 : 0 : return rc;
1747 : : }
1748 : :
1749 : : int
1750 : 0 : roc_npa_dev_init(struct roc_npa *roc_npa)
1751 : : {
1752 : : struct plt_pci_device *pci_dev;
1753 : : struct npa *npa;
1754 : : struct dev *dev;
1755 : : int rc;
1756 : :
1757 [ # # # # ]: 0 : if (roc_npa == NULL || roc_npa->pci_dev == NULL)
1758 : : return NPA_ERR_PARAM;
1759 : :
1760 : : PLT_STATIC_ASSERT(sizeof(struct npa) <= ROC_NPA_MEM_SZ);
1761 : : npa = roc_npa_to_npa_priv(roc_npa);
1762 : : memset(npa, 0, sizeof(*npa));
1763 : : pci_dev = roc_npa->pci_dev;
1764 : 0 : dev = &npa->dev;
1765 : :
1766 : : /* Initialize device */
1767 : 0 : rc = dev_init(dev, pci_dev);
1768 [ # # ]: 0 : if (rc) {
1769 : 0 : plt_err("Failed to init roc device");
1770 : 0 : goto fail;
1771 : : }
1772 : :
1773 : 0 : npa->pci_dev = pci_dev;
1774 : 0 : dev->drv_inited = true;
1775 : : fail:
1776 : : return rc;
1777 : : }
1778 : :
1779 : : int
1780 : 0 : roc_npa_dev_fini(struct roc_npa *roc_npa)
1781 : : {
1782 : : struct npa *npa = roc_npa_to_npa_priv(roc_npa);
1783 : :
1784 : : if (npa == NULL)
1785 : : return NPA_ERR_PARAM;
1786 : :
1787 : 0 : npa->dev.drv_inited = false;
1788 : 0 : return dev_fini(&npa->dev, npa->pci_dev);
1789 : : }
1790 : :
1791 : : void
1792 : 0 : roc_npa_dev_lock(void)
1793 : : {
1794 : 0 : struct idev_cfg *idev = idev_get_cfg();
1795 : :
1796 [ # # ]: 0 : if (idev != NULL)
1797 : 0 : plt_spinlock_lock(&idev->npa_dev_lock);
1798 : 0 : }
1799 : :
1800 : : void
1801 : 0 : roc_npa_dev_unlock(void)
1802 : : {
1803 : 0 : struct idev_cfg *idev = idev_get_cfg();
1804 : :
1805 [ # # ]: 0 : if (idev != NULL)
1806 : 0 : plt_spinlock_unlock(&idev->npa_dev_lock);
1807 : 0 : }
1808 : :
1809 : : int
1810 : 0 : roc_npa_dpc_alloc(uint8_t *counter_id, uint16_t conf)
1811 : : {
1812 : : struct npa_cn20k_dpc_alloc_req *req;
1813 : : struct npa_cn20k_dpc_alloc_rsp *rsp;
1814 : : int rc = NPA_ERR_DPC_ALLOC, off;
1815 : : struct mbox_dev *mdev;
1816 : : struct mbox *mbox;
1817 : : struct npa_lf *lf;
1818 : :
1819 : 0 : lf = idev_npa_obj_get();
1820 [ # # ]: 0 : if (lf == NULL) {
1821 : : rc = NPA_ERR_DEVICE_NOT_BOUNDED;
1822 : : return rc;
1823 : : }
1824 : 0 : mdev = &lf->mbox->dev[0];
1825 : :
1826 : : mbox = mbox_get(lf->mbox);
1827 : 0 : req = mbox_alloc_msg_npa_cn20k_dpc_alloc(mbox);
1828 [ # # ]: 0 : if (req == NULL)
1829 : 0 : goto exit;
1830 : :
1831 : 0 : req->dpc_conf = conf;
1832 : 0 : rc = mbox_process(mbox);
1833 [ # # ]: 0 : if (rc < 0)
1834 : 0 : goto exit;
1835 : :
1836 : 0 : off = mbox->rx_start +
1837 : : PLT_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
1838 : 0 : rsp = (struct npa_cn20k_dpc_alloc_rsp *)((uintptr_t)mdev->mbase + off);
1839 : :
1840 [ # # ]: 0 : if (rsp->hdr.rc != 0)
1841 : 0 : goto exit;
1842 : :
1843 : 0 : *counter_id = rsp->cntr_id;
1844 : : rc = 0;
1845 : 0 : exit:
1846 : : mbox_put(mbox);
1847 : 0 : return rc;
1848 : : }
1849 : :
1850 : : int
1851 : 0 : roc_npa_dpc_free(uint8_t counter_id)
1852 : : {
1853 : : struct npa_cn20k_dpc_free_req *free_req;
1854 : : int rc = NPA_ERR_DPC_FREE, off;
1855 : : struct mbox_dev *mdev;
1856 : : struct msg_rsp *rsp;
1857 : : struct mbox *mbox;
1858 : : struct npa_lf *lf;
1859 : :
1860 : 0 : lf = idev_npa_obj_get();
1861 [ # # ]: 0 : if (lf == NULL) {
1862 : : rc = NPA_ERR_DEVICE_NOT_BOUNDED;
1863 : : return rc;
1864 : : }
1865 : 0 : mdev = &lf->mbox->dev[0];
1866 : : mbox = mbox_get(lf->mbox);
1867 : 0 : free_req = mbox_alloc_msg_npa_cn20k_dpc_free(mbox);
1868 [ # # ]: 0 : if (free_req == NULL)
1869 : 0 : goto exit;
1870 : :
1871 : 0 : free_req->cntr_id = counter_id;
1872 : 0 : rc = mbox_process(mbox);
1873 [ # # ]: 0 : if (rc < 0)
1874 : 0 : goto exit;
1875 : :
1876 : 0 : off = mbox->rx_start +
1877 : : PLT_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
1878 : 0 : rsp = (struct msg_rsp *)((uintptr_t)mdev->mbase + off);
1879 [ # # ]: 0 : if (rsp->hdr.rc != 0)
1880 : 0 : goto exit;
1881 : :
1882 : : rc = 0;
1883 : 0 : exit:
1884 : : mbox_put(mbox);
1885 : 0 : return rc;
1886 : : }
1887 : :
1888 : : int
1889 : 0 : roc_npa_pool_dpc_enable(uint64_t aura_handle, uint8_t counter_id, uint32_t flags)
1890 : : {
1891 : : struct npa_cn20k_aq_enq_req *req;
1892 : : struct npa_cn20k_aq_enq_rsp *rsp;
1893 : : int rc = -ENOSPC, off;
1894 : : struct mbox_dev *mdev;
1895 : : struct mbox *mbox;
1896 : : struct npa_lf *lf;
1897 : :
1898 : 0 : lf = idev_npa_obj_get();
1899 [ # # ]: 0 : if (lf == NULL) {
1900 : : rc = NPA_ERR_DEVICE_NOT_BOUNDED;
1901 : : return rc;
1902 : : }
1903 : 0 : mdev = &lf->mbox->dev[0];
1904 : : mbox = mbox_get(lf->mbox);
1905 : 0 : req = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
1906 [ # # ]: 0 : if (req == NULL)
1907 : 0 : goto exit;
1908 : :
1909 : 0 : req->aura_id = roc_npa_aura_handle_to_aura(aura_handle);
1910 : 0 : req->op = NPA_AQ_INSTOP_WRITE;
1911 [ # # ]: 0 : if (!(flags & ROC_NPA_HALO_F)) {
1912 : : /* Enable DPC in Pool */
1913 : 0 : req->ctype = NPA_AQ_CTYPE_POOL;
1914 : 0 : req->pool.op_dpc_ena = 1;
1915 : 0 : req->pool.op_dpc_set = counter_id;
1916 : 0 : req->pool_mask.op_dpc_ena = 1;
1917 : 0 : req->pool_mask.op_dpc_set = 0;
1918 : 0 : req->pool_mask.op_dpc_set = ~req->pool_mask.op_dpc_set;
1919 : : } else {
1920 : : /* Enable DPC in Halo */
1921 : 0 : req->ctype = NPA_AQ_CTYPE_HALO;
1922 : 0 : req->halo.op_dpc_ena = 1;
1923 : 0 : req->halo.op_dpc_set = counter_id;
1924 : 0 : req->halo_mask.op_dpc_ena = 1;
1925 : 0 : req->halo_mask.op_dpc_set = 0;
1926 : 0 : req->halo_mask.op_dpc_set = ~req->halo_mask.op_dpc_set;
1927 : : }
1928 : :
1929 : 0 : rc = mbox_process(mbox);
1930 [ # # ]: 0 : if (rc < 0)
1931 : 0 : goto exit;
1932 : :
1933 : 0 : off = mbox->rx_start +
1934 : : PLT_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
1935 : 0 : rsp = (struct npa_cn20k_aq_enq_rsp *)((uintptr_t)mdev->mbase + off);
1936 [ # # ]: 0 : if (rsp->hdr.rc != 0)
1937 : 0 : goto exit;
1938 : :
1939 [ # # ]: 0 : if (!(flags & ROC_NPA_HALO_F)) {
1940 : 0 : req = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
1941 [ # # ]: 0 : if (req == NULL)
1942 : 0 : goto disable;
1943 : :
1944 : : /* Enable DPC in Aura */
1945 : 0 : req->aura_id = roc_npa_aura_handle_to_aura(aura_handle);
1946 : 0 : req->op = NPA_AQ_INSTOP_WRITE;
1947 : 0 : req->ctype = NPA_AQ_CTYPE_AURA;
1948 : 0 : req->aura.op_dpc_ena = 1;
1949 : 0 : req->aura.op_dpc_set = counter_id;
1950 : 0 : req->aura_mask.op_dpc_ena = 1;
1951 : 0 : req->aura_mask.op_dpc_set = 0;
1952 : 0 : req->aura_mask.op_dpc_set = ~req->aura_mask.op_dpc_set;
1953 : :
1954 : 0 : rc = mbox_process(mbox);
1955 [ # # ]: 0 : if (rc < 0)
1956 : 0 : goto disable;
1957 : :
1958 : 0 : off = mbox->rx_start +
1959 : : PLT_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
1960 : 0 : rsp = (struct npa_cn20k_aq_enq_rsp *)((uintptr_t)mdev->mbase + off);
1961 [ # # ]: 0 : if (rsp->hdr.rc != 0)
1962 : 0 : goto disable;
1963 : : }
1964 : : rc = 0;
1965 : 0 : goto exit;
1966 : :
1967 : 0 : disable:
1968 : 0 : roc_npa_pool_dpc_disable(aura_handle, flags);
1969 : 0 : exit:
1970 : : mbox_put(mbox);
1971 : 0 : return rc;
1972 : : }
1973 : :
1974 : : int
1975 : 0 : roc_npa_pool_dpc_disable(uint64_t aura_handle, uint32_t flags)
1976 : : {
1977 : : struct npa_cn20k_aq_enq_req *req;
1978 : : struct npa_cn20k_aq_enq_rsp *rsp;
1979 : : int rc = -ENOSPC, off;
1980 : : struct mbox_dev *mdev;
1981 : : struct mbox *mbox;
1982 : : struct npa_lf *lf;
1983 : :
1984 : 0 : lf = idev_npa_obj_get();
1985 [ # # ]: 0 : if (lf == NULL) {
1986 : : rc = NPA_ERR_DEVICE_NOT_BOUNDED;
1987 : : return rc;
1988 : : }
1989 : 0 : mdev = &lf->mbox->dev[0];
1990 : : mbox = mbox_get(lf->mbox);
1991 : 0 : req = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
1992 [ # # ]: 0 : if (req == NULL)
1993 : 0 : goto exit;
1994 : :
1995 : 0 : req->aura_id = roc_npa_aura_handle_to_aura(aura_handle);
1996 : 0 : req->op = NPA_AQ_INSTOP_WRITE;
1997 [ # # ]: 0 : if (!(flags & ROC_NPA_HALO_F)) {
1998 : 0 : req->ctype = NPA_AQ_CTYPE_POOL;
1999 : 0 : req->pool.op_dpc_ena = 0;
2000 : 0 : req->pool_mask.op_dpc_ena = 1;
2001 : : } else {
2002 : 0 : req->ctype = NPA_AQ_CTYPE_HALO;
2003 : 0 : req->halo.op_dpc_ena = 0;
2004 : 0 : req->halo_mask.op_dpc_ena = 1;
2005 : : }
2006 : :
2007 : 0 : rc = mbox_process(mbox);
2008 [ # # ]: 0 : if (rc < 0)
2009 : 0 : goto exit;
2010 : :
2011 : 0 : off = mbox->rx_start +
2012 : : PLT_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
2013 : 0 : rsp = (struct npa_cn20k_aq_enq_rsp *)((uintptr_t)mdev->mbase + off);
2014 [ # # ]: 0 : if (rsp->hdr.rc != 0)
2015 : 0 : goto exit;
2016 : :
2017 [ # # ]: 0 : if (!(flags & ROC_NPA_HALO_F)) {
2018 : 0 : req = mbox_alloc_msg_npa_cn20k_aq_enq(mbox);
2019 [ # # ]: 0 : if (req == NULL)
2020 : 0 : goto exit;
2021 : :
2022 : 0 : req->aura_id = roc_npa_aura_handle_to_aura(aura_handle);
2023 : 0 : req->op = NPA_AQ_INSTOP_WRITE;
2024 : 0 : req->ctype = NPA_AQ_CTYPE_AURA;
2025 : 0 : req->aura.op_dpc_ena = 0;
2026 : 0 : req->aura_mask.op_dpc_ena = 1;
2027 : 0 : rc = mbox_process(mbox);
2028 [ # # ]: 0 : if (rc < 0)
2029 : 0 : goto exit;
2030 : :
2031 : 0 : off = mbox->rx_start + PLT_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
2032 : 0 : rsp = (struct npa_cn20k_aq_enq_rsp *)((uintptr_t)mdev->mbase + off);
2033 [ # # ]: 0 : if (rsp->hdr.rc != 0)
2034 : 0 : goto exit;
2035 : : }
2036 : :
2037 : : rc = 0;
2038 : :
2039 : 0 : exit:
2040 : : mbox_put(mbox);
2041 : 0 : return rc;
2042 : : }
|