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