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 : : #define SSO_XAQ_CACHE_CNT (0x3)
9 : : #define SSO_XAQ_RSVD_CNT (0x4)
10 : : #define SSO_XAQ_SLACK (16)
11 : :
12 : : /* Private functions. */
13 : : int
14 : 0 : sso_lf_alloc(struct dev *dev, enum sso_lf_type lf_type, uint16_t nb_lf,
15 : : void **rsp)
16 : : {
17 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
18 : : int rc = -ENOSPC;
19 : :
20 [ # # # ]: 0 : switch (lf_type) {
21 : 0 : case SSO_LF_TYPE_HWS: {
22 : : struct ssow_lf_alloc_req *req;
23 : :
24 : 0 : req = mbox_alloc_msg_ssow_lf_alloc(mbox);
25 [ # # ]: 0 : if (req == NULL)
26 : 0 : goto exit;
27 : 0 : req->hws = nb_lf;
28 : 0 : } break;
29 : 0 : case SSO_LF_TYPE_HWGRP: {
30 : : struct sso_lf_alloc_req *req;
31 : :
32 : 0 : req = mbox_alloc_msg_sso_lf_alloc(mbox);
33 [ # # ]: 0 : if (req == NULL)
34 : 0 : goto exit;
35 : 0 : req->hwgrps = nb_lf;
36 : 0 : } break;
37 : : default:
38 : : break;
39 : : }
40 : :
41 : : rc = mbox_process_msg(mbox, rsp);
42 [ # # ]: 0 : if (rc) {
43 : : rc = -EIO;
44 : 0 : goto exit;
45 : : }
46 : :
47 : : rc = 0;
48 : 0 : exit:
49 : : mbox_put(mbox);
50 : 0 : return rc;
51 : : }
52 : :
53 : : int
54 : 0 : sso_lf_free(struct dev *dev, enum sso_lf_type lf_type, uint16_t nb_lf)
55 : : {
56 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
57 : : int rc = -ENOSPC;
58 : :
59 [ # # # ]: 0 : switch (lf_type) {
60 : 0 : case SSO_LF_TYPE_HWS: {
61 : : struct ssow_lf_free_req *req;
62 : :
63 : 0 : req = mbox_alloc_msg_ssow_lf_free(mbox);
64 [ # # ]: 0 : if (req == NULL)
65 : 0 : goto exit;
66 : 0 : req->hws = nb_lf;
67 : 0 : } break;
68 : 0 : case SSO_LF_TYPE_HWGRP: {
69 : : struct sso_lf_free_req *req;
70 : :
71 : 0 : req = mbox_alloc_msg_sso_lf_free(mbox);
72 [ # # ]: 0 : if (req == NULL)
73 : 0 : goto exit;
74 : 0 : req->hwgrps = nb_lf;
75 : 0 : } break;
76 : : default:
77 : : break;
78 : : }
79 : :
80 : 0 : rc = mbox_process(mbox);
81 [ # # ]: 0 : if (rc) {
82 : : rc = -EIO;
83 : 0 : goto exit;
84 : : }
85 : :
86 : : rc = 0;
87 : 0 : exit:
88 : : mbox_put(mbox);
89 : 0 : return rc;
90 : : }
91 : :
92 : : static int
93 : 0 : sso_rsrc_attach(struct roc_sso *roc_sso, enum sso_lf_type lf_type,
94 : : uint16_t nb_lf)
95 : : {
96 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
97 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
98 : : struct rsrc_attach_req *req;
99 : : int rc = -ENOSPC;
100 : :
101 : 0 : req = mbox_alloc_msg_attach_resources(mbox);
102 [ # # ]: 0 : if (req == NULL)
103 : 0 : goto exit;
104 [ # # # ]: 0 : switch (lf_type) {
105 : 0 : case SSO_LF_TYPE_HWS:
106 : 0 : req->ssow = nb_lf;
107 : 0 : break;
108 : 0 : case SSO_LF_TYPE_HWGRP:
109 : 0 : req->sso = nb_lf;
110 : 0 : break;
111 : 0 : default:
112 : : rc = SSO_ERR_PARAM;
113 : 0 : goto exit;
114 : : }
115 : :
116 : 0 : req->modify = true;
117 [ # # ]: 0 : if (mbox_process(mbox)) {
118 : : rc = -EIO;
119 : 0 : goto exit;
120 : : }
121 : :
122 : : rc = 0;
123 : 0 : exit:
124 : : mbox_put(mbox);
125 : 0 : return rc;
126 : : }
127 : :
128 : : static int
129 : 0 : sso_rsrc_detach(struct roc_sso *roc_sso, enum sso_lf_type lf_type)
130 : : {
131 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
132 : : struct rsrc_detach_req *req;
133 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
134 : : int rc = -ENOSPC;
135 : :
136 : 0 : req = mbox_alloc_msg_detach_resources(mbox);
137 [ # # ]: 0 : if (req == NULL)
138 : 0 : goto exit;
139 [ # # # ]: 0 : switch (lf_type) {
140 : 0 : case SSO_LF_TYPE_HWS:
141 : 0 : req->ssow = true;
142 : 0 : break;
143 : 0 : case SSO_LF_TYPE_HWGRP:
144 : 0 : req->sso = true;
145 : 0 : break;
146 : 0 : default:
147 : : rc = SSO_ERR_PARAM;
148 : 0 : goto exit;
149 : : }
150 : :
151 : 0 : req->partial = true;
152 [ # # ]: 0 : if (mbox_process(mbox)) {
153 : : rc = -EIO;
154 : 0 : goto exit;
155 : : }
156 : :
157 : : rc = 0;
158 : 0 : exit:
159 : : mbox_put(mbox);
160 : 0 : return rc;
161 : : }
162 : :
163 : : static int
164 : 0 : sso_rsrc_get(struct roc_sso *roc_sso)
165 : : {
166 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
167 : : struct free_rsrcs_rsp *rsrc_cnt;
168 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
169 : : int rc;
170 : :
171 : 0 : mbox_alloc_msg_free_rsrc_cnt(mbox);
172 : : rc = mbox_process_msg(mbox, (void **)&rsrc_cnt);
173 [ # # ]: 0 : if (rc) {
174 : 0 : plt_err("Failed to get free resource count\n");
175 : : rc = -EIO;
176 : 0 : goto exit;
177 : : }
178 : :
179 : 0 : roc_sso->max_hwgrp = rsrc_cnt->sso;
180 : 0 : roc_sso->max_hws = rsrc_cnt->ssow;
181 : :
182 : : rc = 0;
183 : 0 : exit:
184 : : mbox_put(mbox);
185 : 0 : return rc;
186 : : }
187 : :
188 : : void
189 : 0 : sso_hws_link_modify(uint8_t hws, uintptr_t base, struct plt_bitmap *bmp, uint16_t hwgrp[],
190 : : uint16_t n, uint8_t set, uint16_t enable)
191 : : {
192 : : uint64_t reg;
193 : : int i, j, k;
194 : :
195 : : i = 0;
196 [ # # ]: 0 : while (n) {
197 : 0 : uint64_t mask[4] = {
198 : : 0x8000,
199 : : 0x8000,
200 : : 0x8000,
201 : : 0x8000,
202 : : };
203 : :
204 : 0 : k = n % 4;
205 [ # # ]: 0 : k = k ? k : 4;
206 [ # # ]: 0 : for (j = 0; j < k; j++) {
207 : 0 : mask[j] = hwgrp[i + j] | (uint32_t)set << 12 | enable << 14;
208 [ # # ]: 0 : if (bmp) {
209 [ # # ]: 0 : enable ? plt_bitmap_set(bmp, hwgrp[i + j]) :
210 : 0 : plt_bitmap_clear(bmp, hwgrp[i + j]);
211 : : }
212 : 0 : plt_sso_dbg("HWS %d Linked to HWGRP %d", hws,
213 : : hwgrp[i + j]);
214 : : }
215 : :
216 : 0 : n -= j;
217 : 0 : i += j;
218 : 0 : reg = mask[0] | mask[1] << 16 | mask[2] << 32 | mask[3] << 48;
219 : 0 : plt_write64(reg, base + SSOW_LF_GWS_GRPMSK_CHG);
220 : : }
221 : 0 : }
222 : :
223 : : static int
224 : 0 : sso_msix_fill(struct roc_sso *roc_sso, uint16_t nb_hws, uint16_t nb_hwgrp)
225 : : {
226 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
227 : : struct msix_offset_rsp *rsp;
228 : : struct dev *dev = &sso->dev;
229 : : int i, rc;
230 : :
231 : 0 : mbox_alloc_msg_msix_offset(mbox_get(dev->mbox));
232 : 0 : rc = mbox_process_msg(dev->mbox, (void **)&rsp);
233 [ # # ]: 0 : if (rc) {
234 : : rc = -EIO;
235 : 0 : goto exit;
236 : : }
237 : :
238 [ # # ]: 0 : for (i = 0; i < nb_hws; i++)
239 : 0 : sso->hws_msix_offset[i] = rsp->ssow_msixoff[i];
240 [ # # ]: 0 : for (i = 0; i < nb_hwgrp; i++)
241 : 0 : sso->hwgrp_msix_offset[i] = rsp->sso_msixoff[i];
242 : :
243 : : rc = 0;
244 : 0 : exit:
245 : 0 : mbox_put(dev->mbox);
246 : 0 : return rc;
247 : : }
248 : :
249 : : /* Public Functions. */
250 : : uintptr_t
251 : 0 : roc_sso_hws_base_get(struct roc_sso *roc_sso, uint8_t hws)
252 : : {
253 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
254 : :
255 : 0 : return dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | hws << 12);
256 : : }
257 : :
258 : : uintptr_t
259 : 0 : roc_sso_hwgrp_base_get(struct roc_sso *roc_sso, uint16_t hwgrp)
260 : : {
261 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
262 : :
263 : 0 : return dev->bar2 + (RVU_BLOCK_ADDR_SSO << 20 | hwgrp << 12);
264 : : }
265 : :
266 : : uint64_t
267 : 0 : roc_sso_ns_to_gw(struct roc_sso *roc_sso, uint64_t ns)
268 : : {
269 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
270 : : uint64_t current_us, current_ns, new_ns;
271 : : uintptr_t base;
272 : :
273 : 0 : base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20);
274 : 0 : current_us = plt_read64(base + SSOW_LF_GWS_NW_TIM);
275 : : /* From HRM, table 14-19:
276 : : * The SSOW_LF_GWS_NW_TIM[NW_TIM] period is specified in n-1 notation.
277 : : */
278 : : current_us += 1;
279 : :
280 : : /* From HRM, table 14-1:
281 : : * SSOW_LF_GWS_NW_TIM[NW_TIM] specifies the minimum timeout. The SSO
282 : : * hardware times out a GET_WORK request within 2 usec of the minimum
283 : : * timeout specified by SSOW_LF_GWS_NW_TIM[NW_TIM].
284 : : */
285 : 0 : current_us += 2;
286 : 0 : current_ns = current_us * 1E3;
287 : 0 : new_ns = (ns - PLT_MIN(ns, current_ns));
288 : : new_ns = !new_ns ? 1 : new_ns;
289 : 0 : return (new_ns * plt_tsc_hz()) / 1E9;
290 : : }
291 : :
292 : : int
293 : 0 : roc_sso_hws_link(struct roc_sso *roc_sso, uint8_t hws, uint16_t hwgrp[], uint16_t nb_hwgrp,
294 : : uint8_t set)
295 : : {
296 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
297 : : struct sso *sso;
298 : : uintptr_t base;
299 : :
300 : : sso = roc_sso_to_sso_priv(roc_sso);
301 : 0 : base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | hws << 12);
302 : 0 : sso_hws_link_modify(hws, base, sso->link_map[hws], hwgrp, nb_hwgrp, set, 1);
303 : :
304 : 0 : return nb_hwgrp;
305 : : }
306 : :
307 : : int
308 : 0 : roc_sso_hws_unlink(struct roc_sso *roc_sso, uint8_t hws, uint16_t hwgrp[], uint16_t nb_hwgrp,
309 : : uint8_t set)
310 : : {
311 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
312 : : struct sso *sso;
313 : : uintptr_t base;
314 : :
315 : : sso = roc_sso_to_sso_priv(roc_sso);
316 : 0 : base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | hws << 12);
317 : 0 : sso_hws_link_modify(hws, base, sso->link_map[hws], hwgrp, nb_hwgrp, set, 0);
318 : :
319 : 0 : return nb_hwgrp;
320 : : }
321 : :
322 : : int
323 : 0 : roc_sso_hws_stats_get(struct roc_sso *roc_sso, uint8_t hws,
324 : : struct roc_sso_hws_stats *stats)
325 : : {
326 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
327 : : struct sso_hws_stats *req_rsp;
328 : : struct dev *dev = &sso->dev;
329 : : struct mbox *mbox;
330 : : int rc;
331 : :
332 : 0 : mbox = mbox_get(dev->mbox);
333 : 0 : req_rsp = (struct sso_hws_stats *)mbox_alloc_msg_sso_hws_get_stats(
334 : : mbox);
335 [ # # ]: 0 : if (req_rsp == NULL) {
336 : 0 : rc = mbox_process(mbox);
337 [ # # ]: 0 : if (rc) {
338 : : rc = -EIO;
339 : 0 : goto fail;
340 : : }
341 : 0 : req_rsp = (struct sso_hws_stats *)
342 : 0 : mbox_alloc_msg_sso_hws_get_stats(mbox);
343 [ # # ]: 0 : if (req_rsp == NULL) {
344 : : rc = -ENOSPC;
345 : 0 : goto fail;
346 : : }
347 : : }
348 : 0 : req_rsp->hws = hws;
349 : : rc = mbox_process_msg(mbox, (void **)&req_rsp);
350 [ # # ]: 0 : if (rc) {
351 : : rc = -EIO;
352 : 0 : goto fail;
353 : : }
354 : :
355 : 0 : stats->arbitration = req_rsp->arbitration;
356 : 0 : fail:
357 : : mbox_put(mbox);
358 : 0 : return rc;
359 : : }
360 : :
361 : : void
362 : 0 : roc_sso_hws_gwc_invalidate(struct roc_sso *roc_sso, uint8_t *hws,
363 : : uint8_t nb_hws)
364 : : {
365 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
366 : : struct ssow_lf_inv_req *req;
367 : : struct dev *dev = &sso->dev;
368 : : struct mbox *mbox;
369 : : int i;
370 : :
371 [ # # ]: 0 : if (!nb_hws)
372 : : return;
373 : :
374 : 0 : mbox = mbox_get(dev->mbox);
375 : 0 : req = mbox_alloc_msg_sso_ws_cache_inv(mbox);
376 [ # # ]: 0 : if (req == NULL) {
377 : 0 : mbox_process(mbox);
378 : 0 : req = mbox_alloc_msg_sso_ws_cache_inv(mbox);
379 [ # # ]: 0 : if (req == NULL) {
380 : : mbox_put(mbox);
381 : 0 : return;
382 : : }
383 : : }
384 : 0 : req->hdr.ver = SSOW_INVAL_SELECTIVE_VER;
385 : 0 : req->nb_hws = nb_hws;
386 [ # # ]: 0 : for (i = 0; i < nb_hws; i++)
387 : 0 : req->hws[i] = hws[i];
388 : 0 : mbox_process(mbox);
389 : : mbox_put(mbox);
390 : : }
391 : :
392 : : int
393 : 0 : roc_sso_hwgrp_stats_get(struct roc_sso *roc_sso, uint8_t hwgrp,
394 : : struct roc_sso_hwgrp_stats *stats)
395 : : {
396 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
397 : : struct sso_grp_stats *req_rsp;
398 : : struct dev *dev = &sso->dev;
399 : : struct mbox *mbox;
400 : : int rc;
401 : :
402 : 0 : mbox = mbox_get(dev->mbox);
403 : 0 : req_rsp = (struct sso_grp_stats *)mbox_alloc_msg_sso_grp_get_stats(
404 : : mbox);
405 [ # # ]: 0 : if (req_rsp == NULL) {
406 : 0 : rc = mbox_process(mbox);
407 [ # # ]: 0 : if (rc) {
408 : : rc = -EIO;
409 : 0 : goto fail;
410 : : }
411 : 0 : req_rsp = (struct sso_grp_stats *)
412 : 0 : mbox_alloc_msg_sso_grp_get_stats(mbox);
413 [ # # ]: 0 : if (req_rsp == NULL) {
414 : : rc = -ENOSPC;
415 : 0 : goto fail;
416 : : }
417 : : }
418 : 0 : req_rsp->grp = hwgrp;
419 : : rc = mbox_process_msg(mbox, (void **)&req_rsp);
420 [ # # ]: 0 : if (rc) {
421 : : rc = -EIO;
422 : 0 : goto fail;
423 : : }
424 : :
425 : 0 : stats->aw_status = req_rsp->aw_status;
426 : 0 : stats->dq_pc = req_rsp->dq_pc;
427 : 0 : stats->ds_pc = req_rsp->ds_pc;
428 : 0 : stats->ext_pc = req_rsp->ext_pc;
429 : 0 : stats->page_cnt = req_rsp->page_cnt;
430 : 0 : stats->ts_pc = req_rsp->ts_pc;
431 : 0 : stats->wa_pc = req_rsp->wa_pc;
432 : 0 : stats->ws_pc = req_rsp->ws_pc;
433 : :
434 : 0 : fail:
435 : : mbox_put(mbox);
436 : 0 : return rc;
437 : : }
438 : :
439 : : int
440 : 0 : roc_sso_hwgrp_hws_link_status(struct roc_sso *roc_sso, uint8_t hws,
441 : : uint16_t hwgrp)
442 : : {
443 : : struct sso *sso;
444 : :
445 : : sso = roc_sso_to_sso_priv(roc_sso);
446 : 0 : return plt_bitmap_get(sso->link_map[hws], hwgrp);
447 : : }
448 : :
449 : : int
450 : 0 : roc_sso_hwgrp_qos_config(struct roc_sso *roc_sso, struct roc_sso_hwgrp_qos *qos, uint16_t nb_qos)
451 : : {
452 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
453 : : struct dev *dev = &sso->dev;
454 : : struct sso_grp_qos_cfg *req;
455 : : struct mbox *mbox;
456 : : int i, rc;
457 : :
458 [ # # ]: 0 : if (!nb_qos)
459 : : return 0;
460 : :
461 : 0 : mbox = mbox_get(dev->mbox);
462 [ # # ]: 0 : for (i = 0; i < nb_qos; i++) {
463 : 0 : uint8_t iaq_prcnt = qos[i].iaq_prcnt;
464 : 0 : uint8_t taq_prcnt = qos[i].taq_prcnt;
465 : :
466 : 0 : req = mbox_alloc_msg_sso_grp_qos_config(mbox);
467 [ # # ]: 0 : if (req == NULL) {
468 : 0 : rc = mbox_process(mbox);
469 [ # # ]: 0 : if (rc) {
470 : : rc = -EIO;
471 : 0 : goto fail;
472 : : }
473 : :
474 : 0 : req = mbox_alloc_msg_sso_grp_qos_config(mbox);
475 [ # # ]: 0 : if (req == NULL) {
476 : : rc = -ENOSPC;
477 : 0 : goto fail;
478 : : }
479 : : }
480 : 0 : req->grp = qos[i].hwgrp;
481 [ # # ]: 0 : req->iaq_thr = (SSO_HWGRP_IAQ_MAX_THR_MASK *
482 : 0 : (iaq_prcnt ? iaq_prcnt : 100)) /
483 : : 100;
484 [ # # ]: 0 : req->taq_thr = (SSO_HWGRP_TAQ_MAX_THR_MASK *
485 : 0 : (taq_prcnt ? taq_prcnt : 100)) /
486 : : 100;
487 : : }
488 : :
489 : 0 : rc = mbox_process(mbox);
490 [ # # ]: 0 : if (rc)
491 : : rc = -EIO;
492 : 0 : fail:
493 : : mbox_put(mbox);
494 : 0 : return rc;
495 : : }
496 : :
497 : : int
498 : 0 : sso_hwgrp_init_xaq_aura(struct dev *dev, struct roc_sso_xaq_data *xaq,
499 : : uint32_t nb_xae, uint32_t xae_waes,
500 : : uint32_t xaq_buf_size, uint16_t nb_hwgrp)
501 : : {
502 : : struct npa_pool_s pool;
503 : : struct npa_aura_s aura;
504 : : plt_iova_t iova;
505 : : uint32_t i;
506 : : int rc;
507 : :
508 [ # # ]: 0 : if (xaq->mem != NULL) {
509 : 0 : rc = sso_hwgrp_release_xaq(dev, nb_hwgrp);
510 [ # # ]: 0 : if (rc < 0) {
511 : 0 : plt_err("Failed to release XAQ %d", rc);
512 : 0 : return rc;
513 : : }
514 : 0 : roc_npa_pool_destroy(xaq->aura_handle);
515 : 0 : plt_free(xaq->fc);
516 : 0 : plt_free(xaq->mem);
517 : : memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
518 : : }
519 : :
520 : 0 : xaq->fc = plt_zmalloc(ROC_ALIGN, ROC_ALIGN);
521 [ # # ]: 0 : if (xaq->fc == NULL) {
522 : 0 : plt_err("Failed to allocate XAQ FC");
523 : : rc = -ENOMEM;
524 : 0 : goto fail;
525 : : }
526 : :
527 : 0 : xaq->nb_xae = nb_xae;
528 : :
529 : : /** SSO will reserve up to 0x4 XAQ buffers per group when GetWork engine
530 : : * is inactive and it might prefetch an additional 0x3 buffers due to
531 : : * pipelining.
532 : : */
533 : 0 : xaq->nb_xaq = (SSO_XAQ_CACHE_CNT * nb_hwgrp);
534 : 0 : xaq->nb_xaq += (SSO_XAQ_RSVD_CNT * nb_hwgrp);
535 : 0 : xaq->nb_xaq += PLT_MAX(1 + ((xaq->nb_xae - 1) / xae_waes), xaq->nb_xaq);
536 : 0 : xaq->nb_xaq += SSO_XAQ_SLACK;
537 : :
538 : 0 : xaq->mem = plt_zmalloc(xaq_buf_size * xaq->nb_xaq, xaq_buf_size);
539 [ # # ]: 0 : if (xaq->mem == NULL) {
540 : 0 : plt_err("Failed to allocate XAQ mem");
541 : : rc = -ENOMEM;
542 : 0 : goto free_fc;
543 : : }
544 : :
545 : : memset(&pool, 0, sizeof(struct npa_pool_s));
546 : 0 : pool.nat_align = 1;
547 : :
548 : : memset(&aura, 0, sizeof(aura));
549 : 0 : aura.fc_ena = 1;
550 : 0 : aura.fc_addr = (uint64_t)xaq->fc;
551 : : aura.fc_hyst_bits = 0; /* Store count on all updates */
552 : 0 : rc = roc_npa_pool_create(&xaq->aura_handle, xaq_buf_size, xaq->nb_xaq,
553 : : &aura, &pool, 0);
554 [ # # ]: 0 : if (rc) {
555 : 0 : plt_err("Failed to create XAQ pool");
556 : 0 : goto npa_fail;
557 : : }
558 : :
559 : 0 : iova = (uint64_t)xaq->mem;
560 [ # # ]: 0 : for (i = 0; i < xaq->nb_xaq; i++) {
561 : 0 : roc_npa_aura_op_free(xaq->aura_handle, 0, iova);
562 : 0 : iova += xaq_buf_size;
563 : : }
564 : 0 : roc_npa_pool_op_range_set(xaq->aura_handle, (uint64_t)xaq->mem, iova);
565 : :
566 : 0 : if (roc_npa_aura_op_available_wait(xaq->aura_handle, xaq->nb_xaq, 0) !=
567 [ # # ]: 0 : xaq->nb_xaq) {
568 : 0 : plt_err("Failed to free all pointers to the pool");
569 : : rc = -ENOMEM;
570 : 0 : goto npa_fill_fail;
571 : : }
572 : :
573 : : /* When SW does addwork (enqueue) check if there is space in XAQ by
574 : : * comparing fc_addr above against the xaq_lmt calculated below.
575 : : * There should be a minimum headroom of 7 XAQs per HWGRP for SSO
576 : : * to request XAQ to cache them even before enqueue is called.
577 : : */
578 : 0 : xaq->xaq_lmt = xaq->nb_xaq - (nb_hwgrp * SSO_XAQ_CACHE_CNT) - SSO_XAQ_SLACK;
579 : :
580 : 0 : return 0;
581 : : npa_fill_fail:
582 : 0 : roc_npa_pool_destroy(xaq->aura_handle);
583 : 0 : npa_fail:
584 : 0 : plt_free(xaq->mem);
585 : 0 : free_fc:
586 : 0 : plt_free(xaq->fc);
587 : 0 : fail:
588 : : memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
589 : 0 : return rc;
590 : : }
591 : :
592 : : int
593 : 0 : roc_sso_hwgrp_init_xaq_aura(struct roc_sso *roc_sso, uint32_t nb_xae)
594 : : {
595 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
596 : 0 : struct dev *dev = &sso->dev;
597 : : int rc;
598 : :
599 : 0 : rc = sso_hwgrp_init_xaq_aura(dev, &roc_sso->xaq, nb_xae,
600 : : roc_sso->xae_waes, roc_sso->xaq_buf_size,
601 : 0 : roc_sso->nb_hwgrp);
602 : 0 : return rc;
603 : : }
604 : :
605 : : int
606 : 0 : sso_hwgrp_free_xaq_aura(struct dev *dev, struct roc_sso_xaq_data *xaq,
607 : : uint16_t nb_hwgrp)
608 : : {
609 : : int rc;
610 : :
611 [ # # ]: 0 : if (xaq->mem != NULL) {
612 [ # # ]: 0 : if (nb_hwgrp) {
613 : 0 : rc = sso_hwgrp_release_xaq(dev, nb_hwgrp);
614 [ # # ]: 0 : if (rc < 0) {
615 : 0 : plt_err("Failed to release XAQ %d", rc);
616 : 0 : return rc;
617 : : }
618 : : }
619 : 0 : roc_npa_pool_destroy(xaq->aura_handle);
620 : 0 : plt_free(xaq->fc);
621 : 0 : plt_free(xaq->mem);
622 : : }
623 : : memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
624 : :
625 : 0 : return 0;
626 : : }
627 : :
628 : : int
629 : 0 : roc_sso_hwgrp_free_xaq_aura(struct roc_sso *roc_sso, uint16_t nb_hwgrp)
630 : : {
631 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
632 : 0 : struct dev *dev = &sso->dev;
633 : : int rc;
634 : :
635 : 0 : rc = sso_hwgrp_free_xaq_aura(dev, &roc_sso->xaq, nb_hwgrp);
636 : 0 : return rc;
637 : : }
638 : :
639 : : int
640 : 0 : sso_hwgrp_alloc_xaq(struct dev *dev, uint32_t npa_aura_id, uint16_t hwgrps)
641 : : {
642 : : struct sso_hw_setconfig *req;
643 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
644 : : int rc = -ENOSPC;
645 : :
646 : 0 : req = mbox_alloc_msg_sso_hw_setconfig(mbox);
647 [ # # ]: 0 : if (req == NULL)
648 : 0 : goto exit;
649 : 0 : req->npa_pf_func = idev_npa_pffunc_get();
650 : 0 : req->npa_aura_id = npa_aura_id;
651 : 0 : req->hwgrps = hwgrps;
652 : :
653 [ # # ]: 0 : if (mbox_process(dev->mbox)) {
654 : : rc = -EIO;
655 : 0 : goto exit;
656 : : }
657 : :
658 : : rc = 0;
659 : 0 : exit:
660 : : mbox_put(mbox);
661 : 0 : return rc;
662 : : }
663 : :
664 : : int
665 : 0 : roc_sso_hwgrp_alloc_xaq(struct roc_sso *roc_sso, uint32_t npa_aura_id,
666 : : uint16_t hwgrps)
667 : : {
668 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
669 : 0 : struct dev *dev = &sso->dev;
670 : : int rc;
671 : :
672 : 0 : rc = sso_hwgrp_alloc_xaq(dev, npa_aura_id, hwgrps);
673 : 0 : return rc;
674 : : }
675 : :
676 : : int
677 : 0 : sso_hwgrp_release_xaq(struct dev *dev, uint16_t hwgrps)
678 : : {
679 : : struct sso_hw_xaq_release *req;
680 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
681 : : int rc;
682 : :
683 : 0 : req = mbox_alloc_msg_sso_hw_release_xaq_aura(mbox);
684 [ # # ]: 0 : if (req == NULL) {
685 : : rc = -EINVAL;
686 : 0 : goto exit;
687 : : }
688 : 0 : req->hwgrps = hwgrps;
689 : :
690 [ # # ]: 0 : if (mbox_process(mbox)) {
691 : : rc = -EIO;
692 : 0 : goto exit;
693 : : }
694 : :
695 : : rc = 0;
696 : 0 : exit:
697 : : mbox_put(mbox);
698 : 0 : return rc;
699 : : }
700 : :
701 : : int
702 : 0 : roc_sso_hwgrp_release_xaq(struct roc_sso *roc_sso, uint16_t hwgrps)
703 : : {
704 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
705 : 0 : struct dev *dev = &sso->dev;
706 : : int rc;
707 : :
708 : 0 : rc = sso_hwgrp_release_xaq(dev, hwgrps);
709 : 0 : return rc;
710 : : }
711 : :
712 : : int
713 : 0 : roc_sso_hwgrp_set_priority(struct roc_sso *roc_sso, uint16_t hwgrp,
714 : : uint8_t weight, uint8_t affinity, uint8_t priority)
715 : : {
716 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
717 : : struct dev *dev = &sso->dev;
718 : : struct sso_grp_priority *req;
719 : : struct mbox *mbox;
720 : : int rc = -ENOSPC;
721 : :
722 : 0 : mbox = mbox_get(dev->mbox);
723 : 0 : req = mbox_alloc_msg_sso_grp_set_priority(mbox);
724 [ # # ]: 0 : if (req == NULL)
725 : 0 : goto fail;
726 : 0 : req->grp = hwgrp;
727 : 0 : req->weight = weight;
728 : 0 : req->affinity = affinity;
729 : 0 : req->priority = priority;
730 : :
731 : 0 : rc = mbox_process(mbox);
732 [ # # ]: 0 : if (rc) {
733 : : rc = -EIO;
734 : 0 : goto fail;
735 : : }
736 : : mbox_put(mbox);
737 : 0 : plt_sso_dbg("HWGRP %d weight %d affinity %d priority %d", hwgrp, weight,
738 : : affinity, priority);
739 : :
740 : 0 : return 0;
741 : 0 : fail:
742 : : mbox_put(mbox);
743 : 0 : return rc;
744 : : }
745 : :
746 : : static int
747 : 0 : sso_update_msix_vec_count(struct roc_sso *roc_sso, uint16_t sso_vec_cnt)
748 : : {
749 : 0 : struct plt_pci_device *pci_dev = roc_sso->pci_dev;
750 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
751 : : uint16_t mbox_vec_cnt, npa_vec_cnt;
752 : 0 : struct dev *dev = &sso->dev;
753 : : struct idev_cfg *idev;
754 : : int rc;
755 : :
756 : 0 : idev = idev_get_cfg();
757 [ # # ]: 0 : if (idev == NULL)
758 : : return -ENODEV;
759 : :
760 : : mbox_vec_cnt = RVU_PF_INT_VEC_AFPF_MBOX + 1;
761 : :
762 : : /* Allocating vectors for the first time */
763 [ # # ]: 0 : if (plt_intr_max_intr_get(pci_dev->intr_handle) == 0) {
764 [ # # ]: 0 : npa_vec_cnt = idev->npa_refcnt ? 0 : NPA_LF_INT_VEC_POISON + 1;
765 : 0 : return dev_irq_reconfigure(pci_dev->intr_handle, mbox_vec_cnt + npa_vec_cnt);
766 : : }
767 : :
768 [ # # ]: 0 : npa_vec_cnt = (dev->npa.pci_dev == pci_dev) ? NPA_LF_INT_VEC_POISON + 1 : 0;
769 : :
770 : : /* Re-configure to include SSO vectors */
771 : 0 : rc = dev_irq_reconfigure(pci_dev->intr_handle, mbox_vec_cnt + npa_vec_cnt + sso_vec_cnt);
772 [ # # ]: 0 : if (rc)
773 : : return rc;
774 : :
775 : 0 : rc = dev_mbox_register_irq(pci_dev, dev);
776 [ # # ]: 0 : if (rc)
777 : : return rc;
778 : :
779 [ # # ]: 0 : if (!dev_is_vf(dev)) {
780 : 0 : rc = dev_vf_flr_register_irqs(pci_dev, dev);
781 [ # # ]: 0 : if (rc)
782 : : return rc;
783 : : }
784 : :
785 [ # # ]: 0 : if (npa_vec_cnt)
786 : 0 : rc = npa_register_irqs(&dev->npa);
787 : :
788 : : return rc;
789 : : }
790 : :
791 : : int
792 : 0 : roc_sso_hwgrp_stash_config(struct roc_sso *roc_sso, struct roc_sso_hwgrp_stash *stash,
793 : : uint16_t nb_stash)
794 : : {
795 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
796 : : struct sso_grp_stash_cfg *req;
797 : : struct dev *dev = &sso->dev;
798 : : struct mbox *mbox;
799 : : int i, rc;
800 : :
801 [ # # ]: 0 : if (!nb_stash)
802 : : return 0;
803 : :
804 : 0 : mbox = mbox_get(dev->mbox);
805 [ # # ]: 0 : for (i = 0; i < nb_stash; i++) {
806 : 0 : req = mbox_alloc_msg_sso_grp_stash_config(mbox);
807 [ # # ]: 0 : if (req == NULL) {
808 : 0 : rc = mbox_process(mbox);
809 [ # # ]: 0 : if (rc) {
810 : : rc = -EIO;
811 : 0 : goto fail;
812 : : }
813 : :
814 : 0 : req = mbox_alloc_msg_sso_grp_stash_config(mbox);
815 [ # # ]: 0 : if (req == NULL) {
816 : : rc = -ENOSPC;
817 : 0 : goto fail;
818 : : }
819 : : }
820 : 0 : req->ena = true;
821 : 0 : req->grp = stash[i].hwgrp;
822 : 0 : req->offset = stash[i].stash_offset;
823 : 0 : req->num_linesm1 = stash[i].stash_count - 1;
824 : : }
825 : :
826 : 0 : rc = mbox_process(mbox);
827 [ # # ]: 0 : if (rc)
828 : : rc = -EIO;
829 : 0 : fail:
830 : : mbox_put(mbox);
831 : 0 : return rc;
832 : : }
833 : :
834 : : int
835 : 0 : roc_sso_rsrc_init(struct roc_sso *roc_sso, uint8_t nb_hws, uint16_t nb_hwgrp, uint16_t nb_tim_lfs)
836 : : {
837 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
838 : : struct sso_lf_alloc_rsp *rsp_hwgrp;
839 : : uint16_t sso_vec_cnt, free_tim_lfs;
840 : : int rc;
841 : :
842 [ # # # # ]: 0 : if (!nb_hwgrp || roc_sso->max_hwgrp < nb_hwgrp)
843 : : return -ENOENT;
844 [ # # # # ]: 0 : if (!nb_hws || roc_sso->max_hws < nb_hws)
845 : : return -ENOENT;
846 : :
847 : 0 : rc = sso_rsrc_attach(roc_sso, SSO_LF_TYPE_HWS, nb_hws);
848 [ # # ]: 0 : if (rc < 0) {
849 : 0 : plt_err("Unable to attach SSO HWS LFs");
850 : 0 : goto fail;
851 : : }
852 : :
853 : 0 : rc = sso_rsrc_attach(roc_sso, SSO_LF_TYPE_HWGRP, nb_hwgrp);
854 [ # # ]: 0 : if (rc < 0) {
855 : 0 : plt_err("Unable to attach SSO HWGRP LFs");
856 : 0 : goto hwgrp_atch_fail;
857 : : }
858 : :
859 : 0 : rc = sso_lf_alloc(&sso->dev, SSO_LF_TYPE_HWS, nb_hws, NULL);
860 [ # # ]: 0 : if (rc < 0) {
861 : 0 : plt_err("Unable to alloc SSO HWS LFs");
862 : 0 : goto hws_alloc_fail;
863 : : }
864 : :
865 : 0 : rc = sso_lf_alloc(&sso->dev, SSO_LF_TYPE_HWGRP, nb_hwgrp,
866 : : (void **)&rsp_hwgrp);
867 [ # # ]: 0 : if (rc < 0) {
868 : 0 : plt_err("Unable to alloc SSO HWGRP Lfs");
869 : 0 : goto hwgrp_alloc_fail;
870 : : }
871 : :
872 : 0 : roc_sso->xaq_buf_size = rsp_hwgrp->xaq_buf_size;
873 : 0 : roc_sso->xae_waes = rsp_hwgrp->xaq_wq_entries;
874 : 0 : roc_sso->iue = rsp_hwgrp->in_unit_entries;
875 : :
876 : 0 : rc = sso_msix_fill(roc_sso, nb_hws, nb_hwgrp);
877 [ # # ]: 0 : if (rc < 0) {
878 : 0 : plt_err("Unable to get MSIX offsets for SSO LFs");
879 : 0 : goto sso_msix_fail;
880 : : }
881 : :
882 : : /* 1 error interrupt per SSO HWS/HWGRP */
883 : 0 : sso_vec_cnt = nb_hws + nb_hwgrp;
884 : :
885 [ # # ]: 0 : if (sso->dev.roc_tim) {
886 : 0 : nb_tim_lfs = ((struct roc_tim *)sso->dev.roc_tim)->nb_lfs;
887 : : } else {
888 : 0 : rc = tim_free_lf_count_get(&sso->dev, &free_tim_lfs);
889 [ # # ]: 0 : if (rc < 0) {
890 : 0 : plt_err("Failed to get TIM resource count");
891 : 0 : goto sso_msix_fail;
892 : : }
893 : :
894 [ # # ]: 0 : nb_tim_lfs = nb_tim_lfs ? PLT_MIN(nb_tim_lfs, free_tim_lfs) : free_tim_lfs;
895 : : }
896 : :
897 : : /* 2 error interrupt per TIM LF */
898 : 0 : sso_vec_cnt += 2 * nb_tim_lfs;
899 : :
900 : 0 : rc = sso_update_msix_vec_count(roc_sso, sso_vec_cnt);
901 [ # # ]: 0 : if (rc < 0) {
902 : 0 : plt_err("Failed to update SSO MSIX vector count");
903 : 0 : goto sso_msix_fail;
904 : : }
905 : :
906 : 0 : rc = sso_register_irqs_priv(roc_sso, sso->pci_dev->intr_handle, nb_hws,
907 : : nb_hwgrp);
908 [ # # ]: 0 : if (rc < 0) {
909 : 0 : plt_err("Failed to register SSO LF IRQs");
910 : 0 : goto sso_msix_fail;
911 : : }
912 : :
913 : 0 : roc_sso->nb_hwgrp = nb_hwgrp;
914 : 0 : roc_sso->nb_hws = nb_hws;
915 : :
916 : 0 : return 0;
917 : 0 : sso_msix_fail:
918 : 0 : sso_lf_free(&sso->dev, SSO_LF_TYPE_HWGRP, nb_hwgrp);
919 : 0 : hwgrp_alloc_fail:
920 : 0 : sso_lf_free(&sso->dev, SSO_LF_TYPE_HWS, nb_hws);
921 : 0 : hws_alloc_fail:
922 : 0 : sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWGRP);
923 : 0 : hwgrp_atch_fail:
924 : 0 : sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWS);
925 : : fail:
926 : : return rc;
927 : : }
928 : :
929 : : void
930 : 0 : roc_sso_rsrc_fini(struct roc_sso *roc_sso)
931 : : {
932 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
933 : :
934 [ # # ]: 0 : if (!roc_sso->nb_hws && !roc_sso->nb_hwgrp)
935 : : return;
936 : :
937 : 0 : sso_unregister_irqs_priv(roc_sso, sso->pci_dev->intr_handle,
938 : 0 : roc_sso->nb_hws, roc_sso->nb_hwgrp);
939 : 0 : sso_lf_free(&sso->dev, SSO_LF_TYPE_HWS, roc_sso->nb_hws);
940 : 0 : sso_lf_free(&sso->dev, SSO_LF_TYPE_HWGRP, roc_sso->nb_hwgrp);
941 : :
942 : 0 : sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWS);
943 : 0 : sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWGRP);
944 : :
945 : 0 : roc_sso->nb_hwgrp = 0;
946 : 0 : roc_sso->nb_hws = 0;
947 : : }
948 : :
949 : : int
950 : 0 : roc_sso_dev_init(struct roc_sso *roc_sso)
951 : : {
952 : : struct plt_pci_device *pci_dev;
953 : : uint32_t link_map_sz;
954 : : struct sso *sso;
955 : : void *link_mem;
956 : : int i, rc;
957 : :
958 [ # # # # ]: 0 : if (roc_sso == NULL || roc_sso->pci_dev == NULL)
959 : : return SSO_ERR_PARAM;
960 : :
961 : : PLT_STATIC_ASSERT(sizeof(struct sso) <= ROC_SSO_MEM_SZ);
962 : : sso = roc_sso_to_sso_priv(roc_sso);
963 : : memset(sso, 0, sizeof(*sso));
964 : : pci_dev = roc_sso->pci_dev;
965 : :
966 : 0 : rc = sso_update_msix_vec_count(roc_sso, 0);
967 [ # # ]: 0 : if (rc < 0) {
968 : 0 : plt_err("Failed to set SSO MSIX vector count");
969 : 0 : return rc;
970 : : }
971 : :
972 : 0 : rc = dev_init(&sso->dev, pci_dev);
973 [ # # ]: 0 : if (rc < 0) {
974 : 0 : plt_err("Failed to init roc device");
975 : 0 : goto fail;
976 : : }
977 : :
978 : 0 : rc = sso_rsrc_get(roc_sso);
979 [ # # ]: 0 : if (rc < 0) {
980 : 0 : plt_err("Failed to get SSO resources");
981 : 0 : goto rsrc_fail;
982 : : }
983 : : rc = -ENOMEM;
984 : :
985 [ # # ]: 0 : if (roc_sso->max_hws) {
986 : 0 : sso->link_map = plt_zmalloc(
987 : : sizeof(struct plt_bitmap *) * roc_sso->max_hws, 0);
988 [ # # ]: 0 : if (sso->link_map == NULL) {
989 : 0 : plt_err("Failed to allocate memory for link_map array");
990 : 0 : goto rsrc_fail;
991 : : }
992 : :
993 : : link_map_sz =
994 : 0 : plt_bitmap_get_memory_footprint(roc_sso->max_hwgrp);
995 : 0 : sso->link_map_mem =
996 : 0 : plt_zmalloc(link_map_sz * roc_sso->max_hws, 0);
997 [ # # ]: 0 : if (sso->link_map_mem == NULL) {
998 : 0 : plt_err("Failed to get link_map memory");
999 : 0 : goto rsrc_fail;
1000 : : }
1001 : :
1002 : : link_mem = sso->link_map_mem;
1003 : :
1004 [ # # ]: 0 : for (i = 0; i < roc_sso->max_hws; i++) {
1005 : 0 : sso->link_map[i] = plt_bitmap_init(
1006 : 0 : roc_sso->max_hwgrp, link_mem, link_map_sz);
1007 [ # # ]: 0 : if (sso->link_map[i] == NULL) {
1008 : 0 : plt_err("Failed to allocate link map");
1009 : 0 : goto link_mem_free;
1010 : : }
1011 : 0 : link_mem = PLT_PTR_ADD(link_mem, link_map_sz);
1012 : : }
1013 : : }
1014 : 0 : idev_sso_pffunc_set(sso->dev.pf_func);
1015 : 0 : idev_sso_set(roc_sso);
1016 : 0 : sso->pci_dev = pci_dev;
1017 : 0 : sso->dev.drv_inited = true;
1018 : 0 : roc_sso->lmt_base = sso->dev.lmt_base;
1019 : :
1020 : 0 : return 0;
1021 : : link_mem_free:
1022 : 0 : plt_free(sso->link_map_mem);
1023 : 0 : rsrc_fail:
1024 : 0 : rc |= dev_fini(&sso->dev, pci_dev);
1025 : : fail:
1026 : : return rc;
1027 : : }
1028 : :
1029 : : int
1030 : 0 : roc_sso_dev_fini(struct roc_sso *roc_sso)
1031 : : {
1032 : : struct sso *sso;
1033 : :
1034 : : sso = roc_sso_to_sso_priv(roc_sso);
1035 : 0 : sso->dev.drv_inited = false;
1036 : :
1037 : 0 : return dev_fini(&sso->dev, sso->pci_dev);
1038 : : }
|