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 : if (!nb_lf) {
21 : : mbox_put(mbox);
22 : 0 : return 0;
23 : : }
24 : :
25 [ # # # ]: 0 : switch (lf_type) {
26 : 0 : case SSO_LF_TYPE_HWS: {
27 : : struct ssow_lf_alloc_req *req;
28 : :
29 : 0 : req = mbox_alloc_msg_ssow_lf_alloc(mbox);
30 [ # # ]: 0 : if (req == NULL)
31 : 0 : goto exit;
32 : 0 : req->hws = nb_lf;
33 : 0 : } break;
34 : 0 : case SSO_LF_TYPE_HWGRP: {
35 : : struct sso_lf_alloc_req *req;
36 : :
37 : 0 : req = mbox_alloc_msg_sso_lf_alloc(mbox);
38 [ # # ]: 0 : if (req == NULL)
39 : 0 : goto exit;
40 : 0 : req->hwgrps = nb_lf;
41 : 0 : } break;
42 : : default:
43 : : break;
44 : : }
45 : :
46 : : rc = mbox_process_msg(mbox, rsp);
47 [ # # ]: 0 : if (rc) {
48 : : rc = -EIO;
49 : 0 : goto exit;
50 : : }
51 : :
52 : : rc = 0;
53 : 0 : exit:
54 : : mbox_put(mbox);
55 : 0 : return rc;
56 : : }
57 : :
58 : : int
59 : 0 : sso_lf_free(struct dev *dev, enum sso_lf_type lf_type, uint16_t nb_lf)
60 : : {
61 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
62 : : int rc = -ENOSPC;
63 : :
64 [ # # ]: 0 : if (!nb_lf) {
65 : : mbox_put(mbox);
66 : 0 : return 0;
67 : : }
68 : :
69 [ # # # ]: 0 : switch (lf_type) {
70 : 0 : case SSO_LF_TYPE_HWS: {
71 : : struct ssow_lf_free_req *req;
72 : :
73 : 0 : req = mbox_alloc_msg_ssow_lf_free(mbox);
74 [ # # ]: 0 : if (req == NULL)
75 : 0 : goto exit;
76 : 0 : req->hws = nb_lf;
77 : 0 : } break;
78 : 0 : case SSO_LF_TYPE_HWGRP: {
79 : : struct sso_lf_free_req *req;
80 : :
81 : 0 : req = mbox_alloc_msg_sso_lf_free(mbox);
82 [ # # ]: 0 : if (req == NULL)
83 : 0 : goto exit;
84 : 0 : req->hwgrps = nb_lf;
85 : 0 : } break;
86 : : default:
87 : : break;
88 : : }
89 : :
90 : 0 : rc = mbox_process(mbox);
91 [ # # ]: 0 : if (rc) {
92 : : rc = -EIO;
93 : 0 : goto exit;
94 : : }
95 : :
96 : : rc = 0;
97 : 0 : exit:
98 : : mbox_put(mbox);
99 : 0 : return rc;
100 : : }
101 : :
102 : : static int
103 : 0 : sso_rsrc_attach(struct roc_sso *roc_sso, enum sso_lf_type lf_type,
104 : : uint16_t nb_lf)
105 : : {
106 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
107 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
108 : : struct rsrc_attach_req *req;
109 : : int rc = -ENOSPC;
110 : :
111 [ # # ]: 0 : if (!nb_lf) {
112 : : mbox_put(mbox);
113 : 0 : return 0;
114 : : }
115 : :
116 : 0 : req = mbox_alloc_msg_attach_resources(mbox);
117 [ # # ]: 0 : if (req == NULL)
118 : 0 : goto exit;
119 [ # # # ]: 0 : switch (lf_type) {
120 : 0 : case SSO_LF_TYPE_HWS:
121 : 0 : req->ssow = nb_lf;
122 : 0 : break;
123 : 0 : case SSO_LF_TYPE_HWGRP:
124 : 0 : req->sso = nb_lf;
125 : 0 : break;
126 : 0 : default:
127 : : rc = SSO_ERR_PARAM;
128 : 0 : goto exit;
129 : : }
130 : :
131 : 0 : req->modify = true;
132 [ # # ]: 0 : if (mbox_process(mbox)) {
133 : : rc = -EIO;
134 : 0 : goto exit;
135 : : }
136 : :
137 : : rc = 0;
138 : 0 : exit:
139 : : mbox_put(mbox);
140 : 0 : return rc;
141 : : }
142 : :
143 : : static int
144 : 0 : sso_rsrc_detach(struct roc_sso *roc_sso, enum sso_lf_type lf_type)
145 : : {
146 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
147 : : struct rsrc_detach_req *req;
148 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
149 : : int rc = -ENOSPC;
150 : :
151 : 0 : req = mbox_alloc_msg_detach_resources(mbox);
152 [ # # ]: 0 : if (req == NULL)
153 : 0 : goto exit;
154 [ # # # ]: 0 : switch (lf_type) {
155 : 0 : case SSO_LF_TYPE_HWS:
156 : 0 : req->ssow = true;
157 : 0 : break;
158 : 0 : case SSO_LF_TYPE_HWGRP:
159 : 0 : req->sso = true;
160 : 0 : break;
161 : 0 : default:
162 : : rc = SSO_ERR_PARAM;
163 : 0 : goto exit;
164 : : }
165 : :
166 : 0 : req->partial = true;
167 [ # # ]: 0 : if (mbox_process(mbox)) {
168 : : rc = -EIO;
169 : 0 : goto exit;
170 : : }
171 : :
172 : : rc = 0;
173 : 0 : exit:
174 : : mbox_put(mbox);
175 : 0 : return rc;
176 : : }
177 : :
178 : : static int
179 : 0 : sso_rsrc_get(struct roc_sso *roc_sso)
180 : : {
181 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
182 : : struct free_rsrcs_rsp *rsrc_cnt;
183 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
184 : : int rc;
185 : :
186 : 0 : mbox_alloc_msg_free_rsrc_cnt(mbox);
187 : : rc = mbox_process_msg(mbox, (void **)&rsrc_cnt);
188 [ # # ]: 0 : if (rc) {
189 : 0 : plt_err("Failed to get free resource count");
190 : : rc = -EIO;
191 : 0 : goto exit;
192 : : }
193 : :
194 [ # # ]: 0 : roc_sso->max_hwgrp = PLT_MIN(rsrc_cnt->sso, roc_sso->feat.hwgrps_per_pf);
195 : 0 : roc_sso->max_hws = rsrc_cnt->ssow;
196 : :
197 : : rc = 0;
198 : 0 : exit:
199 : : mbox_put(mbox);
200 : 0 : return rc;
201 : : }
202 : :
203 : : static int
204 : 0 : sso_hw_info_get(struct roc_sso *roc_sso)
205 : : {
206 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
207 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
208 : : struct sso_hw_info *rsp;
209 : : int rc;
210 : :
211 : 0 : mbox_alloc_msg_sso_get_hw_info(mbox);
212 : : rc = mbox_process_msg(mbox, (void **)&rsp);
213 [ # # ]: 0 : if (rc && rc != MBOX_MSG_INVALID) {
214 : 0 : plt_err("Failed to get SSO HW info");
215 : : rc = -EIO;
216 : 0 : goto exit;
217 : : }
218 : :
219 [ # # ]: 0 : if (rc == MBOX_MSG_INVALID) {
220 : 0 : roc_sso->feat.hwgrps_per_pf = ROC_SSO_MAX_HWGRP_PER_PF;
221 : : } else {
222 : 0 : mbox_memcpy(&roc_sso->feat, &rsp->feat, sizeof(roc_sso->feat));
223 : :
224 [ # # ]: 0 : if (!roc_sso->feat.hwgrps_per_pf)
225 : 0 : roc_sso->feat.hwgrps_per_pf = ROC_SSO_MAX_HWGRP_PER_PF;
226 : : }
227 : :
228 : : rc = 0;
229 : 0 : exit:
230 : : mbox_put(mbox);
231 : 0 : return rc;
232 : : }
233 : :
234 : : void
235 : 0 : sso_hws_link_modify(uint8_t hws, uintptr_t base, struct plt_bitmap *bmp, uint16_t hwgrp[],
236 : : uint16_t n, uint8_t set, uint16_t enable)
237 : : {
238 : : uint64_t reg;
239 : : int i, j, k;
240 : :
241 : : i = 0;
242 [ # # ]: 0 : while (n) {
243 : 0 : uint64_t mask[4] = {
244 : : 0x8000,
245 : : 0x8000,
246 : : 0x8000,
247 : : 0x8000,
248 : : };
249 : :
250 : 0 : k = n % 4;
251 [ # # ]: 0 : k = k ? k : 4;
252 [ # # ]: 0 : for (j = 0; j < k; j++) {
253 : 0 : mask[j] = hwgrp[i + j] | (uint32_t)set << 12 | enable << 14;
254 [ # # ]: 0 : if (bmp) {
255 [ # # ]: 0 : enable ? plt_bitmap_set(bmp, hwgrp[i + j]) :
256 : 0 : plt_bitmap_clear(bmp, hwgrp[i + j]);
257 : : }
258 : 0 : plt_sso_dbg("HWS %d Linked to HWGRP %d", hws,
259 : : hwgrp[i + j]);
260 : : }
261 : :
262 : 0 : n -= j;
263 : 0 : i += j;
264 : 0 : reg = mask[0] | mask[1] << 16 | mask[2] << 32 | mask[3] << 48;
265 : 0 : plt_write64(reg, base + SSOW_LF_GWS_GRPMSK_CHG);
266 : : }
267 : 0 : }
268 : :
269 : : static int
270 : 0 : sso_hws_link_modify_af(struct dev *dev, uint8_t hws, struct plt_bitmap *bmp, uint16_t hwgrp[],
271 : : uint16_t n, uint8_t set, uint16_t enable)
272 : : {
273 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
274 : : struct ssow_chng_mship *req;
275 : : int rc, i;
276 : :
277 : 0 : req = mbox_alloc_msg_ssow_chng_mship(mbox);
278 [ # # ]: 0 : if (req == NULL) {
279 : 0 : rc = mbox_process(mbox);
280 [ # # ]: 0 : if (rc) {
281 : : mbox_put(mbox);
282 : 0 : return -EIO;
283 : : }
284 : 0 : req = mbox_alloc_msg_ssow_chng_mship(mbox);
285 [ # # ]: 0 : if (req == NULL) {
286 : : mbox_put(mbox);
287 : 0 : return -ENOSPC;
288 : : }
289 : : }
290 : 0 : req->enable = enable;
291 : 0 : req->set = set;
292 : 0 : req->hws = hws;
293 : 0 : req->nb_hwgrps = n;
294 [ # # ]: 0 : for (i = 0; i < n; i++)
295 : 0 : req->hwgrps[i] = hwgrp[i];
296 : 0 : rc = mbox_process(mbox);
297 : : mbox_put(mbox);
298 [ # # ]: 0 : if (rc == MBOX_MSG_INVALID)
299 : : return rc;
300 [ # # ]: 0 : if (rc)
301 : : return -EIO;
302 : :
303 [ # # ]: 0 : for (i = 0; i < n; i++)
304 [ # # ]: 0 : enable ? plt_bitmap_set(bmp, hwgrp[i]) :
305 : 0 : plt_bitmap_clear(bmp, hwgrp[i]);
306 : :
307 : : return 0;
308 : : }
309 : :
310 : : static int
311 : 0 : sso_msix_fill(struct roc_sso *roc_sso, uint16_t nb_hws, uint16_t nb_hwgrp)
312 : : {
313 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
314 : : struct msix_offset_rsp *rsp;
315 : : struct dev *dev = &sso->dev;
316 : : int i, rc;
317 : :
318 : 0 : mbox_alloc_msg_msix_offset(mbox_get(dev->mbox));
319 : 0 : rc = mbox_process_msg(dev->mbox, (void **)&rsp);
320 [ # # ]: 0 : if (rc) {
321 : : rc = -EIO;
322 : 0 : goto exit;
323 : : }
324 : :
325 [ # # ]: 0 : for (i = 0; i < nb_hws; i++)
326 : 0 : sso->hws_msix_offset[i] = rsp->ssow_msixoff[i];
327 [ # # ]: 0 : for (i = 0; i < nb_hwgrp; i++)
328 : 0 : sso->hwgrp_msix_offset[i] = rsp->sso_msixoff[i];
329 : :
330 : : rc = 0;
331 : 0 : exit:
332 : 0 : mbox_put(dev->mbox);
333 : 0 : return rc;
334 : : }
335 : :
336 : : /* Public Functions. */
337 : : uintptr_t
338 : 0 : roc_sso_hws_base_get(struct roc_sso *roc_sso, uint8_t hws)
339 : : {
340 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
341 : :
342 : 0 : return dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | hws << 12);
343 : : }
344 : :
345 : : uintptr_t
346 : 0 : roc_sso_hwgrp_base_get(struct roc_sso *roc_sso, uint16_t hwgrp)
347 : : {
348 : : struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
349 : :
350 : 0 : return dev->bar2 + (RVU_BLOCK_ADDR_SSO << 20 | hwgrp << 12);
351 : : }
352 : :
353 : : uint16_t
354 : 0 : roc_sso_pf_func_get(void)
355 : : {
356 : 0 : return idev_sso_pffunc_get();
357 : : }
358 : :
359 : : uint64_t
360 : 0 : roc_sso_ns_to_gw(uint64_t base, uint64_t ns)
361 : : {
362 : : uint64_t current_us;
363 : :
364 : 0 : current_us = plt_read64(base + SSOW_LF_GWS_NW_TIM);
365 : : /* From HRM, table 14-19:
366 : : * The SSOW_LF_GWS_NW_TIM[NW_TIM] period is specified in n-1 notation.
367 : : */
368 : : current_us += 1;
369 : :
370 : : /* From HRM, table 14-1:
371 : : * SSOW_LF_GWS_NW_TIM[NW_TIM] specifies the minimum timeout. The SSO
372 : : * hardware times out a GET_WORK request within 1 usec of the minimum
373 : : * timeout specified by SSOW_LF_GWS_NW_TIM[NW_TIM].
374 : : */
375 : 0 : current_us += 1;
376 : 0 : return PLT_MAX(1UL, (uint64_t)PLT_DIV_CEIL(ns, (current_us * 1E3)));
377 : : }
378 : :
379 : : int
380 : 0 : roc_sso_hws_link(struct roc_sso *roc_sso, uint8_t hws, uint16_t hwgrp[], uint16_t nb_hwgrp,
381 : : uint8_t set, bool use_mbox)
382 : : {
383 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
384 : 0 : struct dev *dev = &sso->dev;
385 : : uintptr_t base;
386 : : int rc;
387 : :
388 [ # # ]: 0 : if (!nb_hwgrp)
389 : : return 0;
390 : :
391 [ # # # # ]: 0 : if (use_mbox && roc_model_is_cn10k()) {
392 : 0 : rc = sso_hws_link_modify_af(dev, hws, sso->link_map[hws], hwgrp, nb_hwgrp, set, 1);
393 [ # # ]: 0 : if (rc == MBOX_MSG_INVALID)
394 : 0 : goto lf_access;
395 [ # # ]: 0 : if (rc < 0)
396 : : return 0;
397 : 0 : goto done;
398 : : }
399 : 0 : lf_access:
400 : 0 : base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | hws << 12);
401 : 0 : sso_hws_link_modify(hws, base, sso->link_map[hws], hwgrp, nb_hwgrp, set, 1);
402 : 0 : done:
403 : 0 : return nb_hwgrp;
404 : : }
405 : :
406 : : int
407 : 0 : roc_sso_hws_unlink(struct roc_sso *roc_sso, uint8_t hws, uint16_t hwgrp[],
408 : : uint16_t nb_hwgrp, uint8_t set, bool use_mbox)
409 : : {
410 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
411 : 0 : struct dev *dev = &sso->dev;
412 : : uintptr_t base;
413 : : int rc;
414 : :
415 [ # # ]: 0 : if (!nb_hwgrp)
416 : : return 0;
417 : :
418 [ # # # # ]: 0 : if (use_mbox && roc_model_is_cn10k()) {
419 : 0 : rc = sso_hws_link_modify_af(dev, hws, sso->link_map[hws], hwgrp, nb_hwgrp, set, 0);
420 [ # # ]: 0 : if (rc == MBOX_MSG_INVALID)
421 : 0 : goto lf_access;
422 [ # # ]: 0 : if (rc < 0)
423 : : return 0;
424 : 0 : goto done;
425 : : }
426 : 0 : lf_access:
427 : 0 : base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | hws << 12);
428 : 0 : sso_hws_link_modify(hws, base, sso->link_map[hws], hwgrp, nb_hwgrp, set, 0);
429 : 0 : done:
430 : 0 : return nb_hwgrp;
431 : : }
432 : :
433 : : int
434 : 0 : roc_sso_hws_stats_get(struct roc_sso *roc_sso, uint8_t hws,
435 : : struct roc_sso_hws_stats *stats)
436 : : {
437 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
438 : : struct sso_hws_stats *req_rsp;
439 : : struct dev *dev = &sso->dev;
440 : : struct mbox *mbox;
441 : : int rc;
442 : :
443 : 0 : mbox = mbox_get(dev->mbox);
444 : 0 : req_rsp = (struct sso_hws_stats *)mbox_alloc_msg_sso_hws_get_stats(
445 : : mbox);
446 [ # # ]: 0 : if (req_rsp == NULL) {
447 : 0 : rc = mbox_process(mbox);
448 [ # # ]: 0 : if (rc) {
449 : : rc = -EIO;
450 : 0 : goto fail;
451 : : }
452 : 0 : req_rsp = (struct sso_hws_stats *)
453 : 0 : mbox_alloc_msg_sso_hws_get_stats(mbox);
454 [ # # ]: 0 : if (req_rsp == NULL) {
455 : : rc = -ENOSPC;
456 : 0 : goto fail;
457 : : }
458 : : }
459 : 0 : req_rsp->hws = hws;
460 : : rc = mbox_process_msg(mbox, (void **)&req_rsp);
461 [ # # ]: 0 : if (rc) {
462 : : rc = -EIO;
463 : 0 : goto fail;
464 : : }
465 : :
466 : 0 : stats->arbitration = req_rsp->arbitration;
467 : 0 : fail:
468 : : mbox_put(mbox);
469 : 0 : return rc;
470 : : }
471 : :
472 : : void
473 : 0 : roc_sso_hws_gwc_invalidate(struct roc_sso *roc_sso, uint8_t *hws,
474 : : uint8_t nb_hws)
475 : : {
476 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
477 : : struct ssow_lf_inv_req *req;
478 : : struct dev *dev = &sso->dev;
479 : : struct mbox *mbox;
480 : : int i;
481 : :
482 [ # # ]: 0 : if (!nb_hws)
483 : : return;
484 : :
485 : 0 : mbox = mbox_get(dev->mbox);
486 : 0 : req = mbox_alloc_msg_sso_ws_cache_inv(mbox);
487 [ # # ]: 0 : if (req == NULL) {
488 : 0 : mbox_process(mbox);
489 : 0 : req = mbox_alloc_msg_sso_ws_cache_inv(mbox);
490 [ # # ]: 0 : if (req == NULL) {
491 : : mbox_put(mbox);
492 : 0 : return;
493 : : }
494 : : }
495 : 0 : req->hdr.ver = SSOW_INVAL_SELECTIVE_VER;
496 : 0 : req->nb_hws = nb_hws;
497 [ # # ]: 0 : for (i = 0; i < nb_hws; i++)
498 : 0 : req->hws[i] = hws[i];
499 : 0 : mbox_process(mbox);
500 : : mbox_put(mbox);
501 : : }
502 : :
503 : : static void
504 : 0 : sso_agq_op_wait(struct roc_sso *roc_sso, uint16_t hwgrp)
505 : : {
506 : : uint64_t reg;
507 : :
508 : 0 : reg = plt_read64(roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_INSTOP);
509 [ # # ]: 0 : while (reg & BIT_ULL(2)) {
510 : 0 : plt_delay_us(100);
511 : 0 : reg = plt_read64(roc_sso_hwgrp_base_get(roc_sso, hwgrp) +
512 : : SSO_LF_GGRP_AGGR_CTX_INSTOP);
513 : : }
514 : 0 : }
515 : :
516 : : int
517 : 0 : roc_sso_hwgrp_agq_alloc(struct roc_sso *roc_sso, uint16_t hwgrp, struct roc_sso_agq_data *data,
518 : : uint32_t *agq_id)
519 : : {
520 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
521 : : struct sso_aggr_setconfig *req;
522 : : struct sso_agq_ctx *ctx;
523 : : uint32_t cnt, off;
524 : : struct mbox *mbox;
525 : : uintptr_t ptr;
526 : : uint64_t reg;
527 : : int rc;
528 : :
529 [ # # ]: 0 : if (sso->agg_mem[hwgrp] == 0) {
530 : 0 : mbox = mbox_get(sso->dev.mbox);
531 : 0 : req = mbox_alloc_msg_sso_aggr_setconfig(mbox);
532 [ # # ]: 0 : if (req == NULL) {
533 : 0 : mbox_process(mbox);
534 : 0 : req = mbox_alloc_msg_sso_aggr_setconfig(mbox);
535 [ # # ]: 0 : if (req == NULL) {
536 : 0 : plt_err("Failed to allocate AGQ config mbox.");
537 : : mbox_put(mbox);
538 : 0 : return -EIO;
539 : : }
540 : : }
541 : :
542 : 0 : req->hwgrp = hwgrp;
543 : 0 : req->npa_pf_func = idev_npa_pffunc_get();
544 : 0 : rc = mbox_process(mbox);
545 [ # # ]: 0 : if (rc < 0) {
546 : 0 : plt_err("Failed to set HWGRP AGQ config rc=%d", rc);
547 : : mbox_put(mbox);
548 : 0 : return rc;
549 : : }
550 : :
551 : : mbox_put(mbox);
552 : :
553 : 0 : sso->agg_mem[hwgrp] =
554 : 0 : (uintptr_t)plt_zmalloc(SSO_AGGR_MIN_CTX * sizeof(struct sso_agq_ctx),
555 : : roc_model_optimal_align_sz());
556 [ # # ]: 0 : if (sso->agg_mem[hwgrp] == 0)
557 : : return -ENOMEM;
558 : 0 : sso->agg_cnt[hwgrp] = SSO_AGGR_MIN_CTX;
559 : 0 : sso->agg_used[hwgrp] = 0;
560 : : plt_wmb();
561 : 0 : plt_write64(sso->agg_mem[hwgrp],
562 : : roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_BASE);
563 : : reg = (plt_log2_u32(SSO_AGGR_MIN_CTX) - 6) << 16;
564 : : reg |= (SSO_AGGR_DEF_TMO << 4) | 1;
565 : 0 : plt_write64(reg, roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CFG);
566 : : }
567 : :
568 [ # # ]: 0 : if (sso->agg_cnt[hwgrp] >= SSO_AGGR_MAX_CTX)
569 : : return -ENOSPC;
570 : :
571 [ # # ]: 0 : if (sso->agg_cnt[hwgrp] == sso->agg_used[hwgrp]) {
572 : 0 : ptr = sso->agg_mem[hwgrp];
573 [ # # ]: 0 : cnt = sso->agg_cnt[hwgrp] << 1;
574 : 0 : sso->agg_mem[hwgrp] = (uintptr_t)plt_zmalloc(cnt * sizeof(struct sso_agq_ctx),
575 : : roc_model_optimal_align_sz());
576 [ # # ]: 0 : if (sso->agg_mem[hwgrp] == 0) {
577 : 0 : sso->agg_mem[hwgrp] = ptr;
578 : 0 : return -ENOMEM;
579 : : }
580 : :
581 : 0 : memcpy((void *)sso->agg_mem[hwgrp], (void *)ptr,
582 : 0 : sso->agg_cnt[hwgrp] * sizeof(struct sso_agq_ctx));
583 : : plt_wmb();
584 : 0 : sso_agq_op_wait(roc_sso, hwgrp);
585 : : /* Base address has changed, evict old entries. */
586 : 0 : plt_write64(sso->agg_mem[hwgrp],
587 : : roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_BASE);
588 [ # # ]: 0 : reg = plt_read64(roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CFG);
589 [ # # ]: 0 : reg &= ~GENMASK_ULL(19, 16);
590 : 0 : reg |= (uint64_t)(plt_log2_u32(cnt) - 6) << 16;
591 : 0 : plt_write64(reg, roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CFG);
592 : : reg = SSO_LF_AGGR_INSTOP_GLOBAL_EVICT << 4;
593 : 0 : plt_write64(reg,
594 : : roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_INSTOP);
595 : 0 : sso_agq_op_wait(roc_sso, hwgrp);
596 : 0 : plt_free((void *)ptr);
597 : :
598 : 0 : sso->agg_cnt[hwgrp] = cnt;
599 : 0 : off = sso->agg_used[hwgrp];
600 : : } else {
601 : 0 : ctx = (struct sso_agq_ctx *)sso->agg_mem[hwgrp];
602 [ # # ]: 0 : for (cnt = 0; cnt < sso->agg_cnt[hwgrp]; cnt++) {
603 [ # # ]: 0 : if (!ctx[cnt].ena)
604 : : break;
605 : : }
606 [ # # ]: 0 : if (cnt == sso->agg_cnt[hwgrp])
607 : : return -EINVAL;
608 : : off = cnt;
609 : : }
610 : :
611 : 0 : ctx = (struct sso_agq_ctx *)sso->agg_mem[hwgrp];
612 : 0 : ctx += off;
613 : 0 : ctx->ena = 1;
614 : 0 : ctx->tt = data->tt;
615 : 0 : ctx->tag = data->tag;
616 : 0 : ctx->swqe_tag = data->stag;
617 : 0 : ctx->cnt_ena = data->cnt_ena;
618 : 0 : ctx->xqe_type = data->xqe_type;
619 : 0 : ctx->vtimewait = data->vwqe_wait_tmo;
620 : 0 : ctx->vwqe_aura = data->vwqe_aura;
621 : 0 : ctx->max_vsize_exp = data->vwqe_max_sz_exp - 2;
622 : :
623 : : plt_wmb();
624 : 0 : sso->agg_used[hwgrp]++;
625 : 0 : *agq_id = off;
626 : :
627 : 0 : return 0;
628 : : }
629 : :
630 : : void
631 : 0 : roc_sso_hwgrp_agq_free(struct roc_sso *roc_sso, uint16_t hwgrp, uint32_t agq_id)
632 : : {
633 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
634 : : struct sso_agq_ctx *ctx;
635 : : uint64_t reg;
636 : :
637 : 0 : ctx = (struct sso_agq_ctx *)sso->agg_mem[hwgrp];
638 : 0 : ctx += agq_id;
639 : :
640 [ # # ]: 0 : if (!ctx->ena)
641 : : return;
642 : :
643 : : reg = SSO_LF_AGGR_INSTOP_FLUSH << 4;
644 : 0 : reg |= (uint64_t)(agq_id << 8);
645 : :
646 : 0 : plt_write64(reg, roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_INSTOP);
647 : 0 : sso_agq_op_wait(roc_sso, hwgrp);
648 : :
649 : : memset(ctx, 0, sizeof(struct sso_agq_ctx));
650 : : plt_wmb();
651 : 0 : sso->agg_used[hwgrp]--;
652 : :
653 : : /* Flush the context from CTX Cache */
654 : : reg = SSO_LF_AGGR_INSTOP_EVICT << 4;
655 : 0 : reg |= (uint64_t)(agq_id << 8);
656 : :
657 : 0 : plt_write64(reg, roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_INSTOP);
658 : 0 : sso_agq_op_wait(roc_sso, hwgrp);
659 : : }
660 : :
661 : : void
662 : 0 : roc_sso_hwgrp_agq_release(struct roc_sso *roc_sso, uint16_t hwgrp)
663 : : {
664 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
665 : : struct sso_aggr_setconfig *req;
666 : : struct sso_agq_ctx *ctx;
667 : : struct mbox *mbox;
668 : : uint32_t cnt;
669 : : int rc;
670 : :
671 [ # # ]: 0 : if (!roc_sso->feat.eva_present)
672 : : return;
673 : :
674 : 0 : plt_write64(0, roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CFG);
675 : 0 : ctx = (struct sso_agq_ctx *)sso->agg_mem[hwgrp];
676 [ # # ]: 0 : for (cnt = 0; cnt < sso->agg_cnt[hwgrp]; cnt++) {
677 [ # # ]: 0 : if (!ctx[cnt].ena)
678 : 0 : continue;
679 : 0 : roc_sso_hwgrp_agq_free(roc_sso, hwgrp, cnt);
680 : : }
681 : :
682 : 0 : plt_write64(0, roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_BASE);
683 : 0 : plt_free((void *)sso->agg_mem[hwgrp]);
684 : 0 : sso->agg_mem[hwgrp] = 0;
685 : 0 : sso->agg_cnt[hwgrp] = 0;
686 : 0 : sso->agg_used[hwgrp] = 0;
687 : :
688 : 0 : mbox = mbox_get(sso->dev.mbox);
689 : 0 : req = mbox_alloc_msg_sso_aggr_setconfig(mbox);
690 [ # # ]: 0 : if (req == NULL) {
691 : 0 : mbox_process(mbox);
692 : 0 : req = mbox_alloc_msg_sso_aggr_setconfig(mbox);
693 [ # # ]: 0 : if (req == NULL) {
694 : 0 : plt_err("Failed to allocate AGQ config mbox.");
695 : : mbox_put(mbox);
696 : 0 : return;
697 : : }
698 : : }
699 : :
700 : 0 : req->hwgrp = hwgrp;
701 : 0 : req->npa_pf_func = 0;
702 : 0 : rc = mbox_process(mbox);
703 [ # # ]: 0 : if (rc < 0)
704 : 0 : plt_err("Failed to set HWGRP AGQ config rc=%d", rc);
705 : : mbox_put(mbox);
706 : : }
707 : :
708 : : uint32_t
709 : 0 : roc_sso_hwgrp_agq_from_tag(struct roc_sso *roc_sso, uint16_t hwgrp, uint32_t tag_mask,
710 : : uint8_t xqe_type)
711 : : {
712 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
713 : : struct sso_agq_ctx *ctx;
714 : : uint32_t i;
715 : :
716 : : plt_rmb();
717 : 0 : ctx = (struct sso_agq_ctx *)sso->agg_mem[hwgrp];
718 [ # # ]: 0 : for (i = 0; i < sso->agg_used[hwgrp]; i++) {
719 [ # # ]: 0 : if (!ctx[i].ena)
720 : 0 : continue;
721 [ # # # # ]: 0 : if (ctx[i].tag == tag_mask && ctx[i].xqe_type == xqe_type)
722 : 0 : return i;
723 : : }
724 : :
725 : : return UINT32_MAX;
726 : : }
727 : :
728 : : int
729 : 0 : roc_sso_hwgrp_stats_get(struct roc_sso *roc_sso, uint16_t hwgrp, struct roc_sso_hwgrp_stats *stats)
730 : : {
731 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
732 : : struct sso_grp_stats *req_rsp;
733 : : struct dev *dev = &sso->dev;
734 : : struct mbox *mbox;
735 : : int rc;
736 : :
737 : 0 : mbox = mbox_get(dev->mbox);
738 : 0 : req_rsp = (struct sso_grp_stats *)mbox_alloc_msg_sso_grp_get_stats(
739 : : mbox);
740 [ # # ]: 0 : if (req_rsp == NULL) {
741 : 0 : rc = mbox_process(mbox);
742 [ # # ]: 0 : if (rc) {
743 : : rc = -EIO;
744 : 0 : goto fail;
745 : : }
746 : 0 : req_rsp = (struct sso_grp_stats *)
747 : 0 : mbox_alloc_msg_sso_grp_get_stats(mbox);
748 [ # # ]: 0 : if (req_rsp == NULL) {
749 : : rc = -ENOSPC;
750 : 0 : goto fail;
751 : : }
752 : : }
753 : 0 : req_rsp->grp = hwgrp;
754 : : rc = mbox_process_msg(mbox, (void **)&req_rsp);
755 [ # # ]: 0 : if (rc) {
756 : : rc = -EIO;
757 : 0 : goto fail;
758 : : }
759 : :
760 : 0 : stats->aw_status = req_rsp->aw_status;
761 : 0 : stats->dq_pc = req_rsp->dq_pc;
762 : 0 : stats->ds_pc = req_rsp->ds_pc;
763 : 0 : stats->ext_pc = req_rsp->ext_pc;
764 : 0 : stats->page_cnt = req_rsp->page_cnt;
765 : 0 : stats->ts_pc = req_rsp->ts_pc;
766 : 0 : stats->wa_pc = req_rsp->wa_pc;
767 : 0 : stats->ws_pc = req_rsp->ws_pc;
768 : :
769 : 0 : fail:
770 : : mbox_put(mbox);
771 : 0 : return rc;
772 : : }
773 : :
774 : : int
775 : 0 : roc_sso_hwgrp_hws_link_status(struct roc_sso *roc_sso, uint8_t hws,
776 : : uint16_t hwgrp)
777 : : {
778 : : struct sso *sso;
779 : :
780 : : sso = roc_sso_to_sso_priv(roc_sso);
781 : 0 : return plt_bitmap_get(sso->link_map[hws], hwgrp);
782 : : }
783 : :
784 : : int
785 : 0 : roc_sso_hwgrp_qos_config(struct roc_sso *roc_sso, struct roc_sso_hwgrp_qos *qos, uint16_t nb_qos)
786 : : {
787 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
788 : : struct dev *dev = &sso->dev;
789 : : struct sso_grp_qos_cfg *req;
790 : : struct mbox *mbox;
791 : : int i, rc;
792 : :
793 [ # # ]: 0 : if (!nb_qos)
794 : : return 0;
795 : :
796 : 0 : mbox = mbox_get(dev->mbox);
797 [ # # ]: 0 : for (i = 0; i < nb_qos; i++) {
798 : 0 : uint8_t iaq_prcnt = qos[i].iaq_prcnt;
799 : 0 : uint8_t taq_prcnt = qos[i].taq_prcnt;
800 : :
801 : 0 : req = mbox_alloc_msg_sso_grp_qos_config(mbox);
802 [ # # ]: 0 : if (req == NULL) {
803 : 0 : rc = mbox_process(mbox);
804 [ # # ]: 0 : if (rc) {
805 : : rc = -EIO;
806 : 0 : goto fail;
807 : : }
808 : :
809 : 0 : req = mbox_alloc_msg_sso_grp_qos_config(mbox);
810 [ # # ]: 0 : if (req == NULL) {
811 : : rc = -ENOSPC;
812 : 0 : goto fail;
813 : : }
814 : : }
815 : 0 : req->grp = qos[i].hwgrp;
816 [ # # ]: 0 : req->iaq_thr = (SSO_HWGRP_IAQ_MAX_THR_MASK *
817 : 0 : (iaq_prcnt ? iaq_prcnt : 100)) /
818 : : 100;
819 [ # # ]: 0 : req->taq_thr = (SSO_HWGRP_TAQ_MAX_THR_MASK *
820 : 0 : (taq_prcnt ? taq_prcnt : 100)) /
821 : : 100;
822 : : }
823 : :
824 : 0 : rc = mbox_process(mbox);
825 [ # # ]: 0 : if (rc)
826 : : rc = -EIO;
827 : 0 : fail:
828 : : mbox_put(mbox);
829 : 0 : return rc;
830 : : }
831 : :
832 : : int
833 : 0 : sso_hwgrp_init_xaq_aura(struct dev *dev, struct roc_sso_xaq_data *xaq,
834 : : uint32_t nb_xae, uint32_t xae_waes,
835 : : uint32_t xaq_buf_size, uint16_t nb_hwgrp)
836 : : {
837 : : plt_iova_t iova;
838 : : uint32_t i;
839 : : int rc;
840 : :
841 [ # # ]: 0 : if (xaq->mem != NULL) {
842 : 0 : rc = sso_hwgrp_release_xaq(dev, nb_hwgrp);
843 [ # # ]: 0 : if (rc < 0) {
844 : 0 : plt_err("Failed to release XAQ %d", rc);
845 : 0 : return rc;
846 : : }
847 : 0 : roc_npa_pool_destroy(xaq->aura_handle);
848 : 0 : plt_free(xaq->fc);
849 : 0 : plt_free(xaq->mem);
850 : : memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
851 : : }
852 : :
853 : 0 : xaq->fc = plt_zmalloc(ROC_ALIGN, ROC_ALIGN);
854 [ # # ]: 0 : if (xaq->fc == NULL) {
855 : 0 : plt_err("Failed to allocate XAQ FC");
856 : : rc = -ENOMEM;
857 : 0 : goto fail;
858 : : }
859 : :
860 : 0 : xaq->nb_xae = nb_xae;
861 : :
862 : : /** SSO will reserve up to 0x4 XAQ buffers per group when GetWork engine
863 : : * is inactive and it might prefetch an additional 0x3 buffers due to
864 : : * pipelining.
865 : : */
866 : 0 : xaq->nb_xaq = (SSO_XAQ_CACHE_CNT * nb_hwgrp);
867 : 0 : xaq->nb_xaq += (SSO_XAQ_RSVD_CNT * nb_hwgrp);
868 : 0 : xaq->nb_xaq += PLT_MAX(1 + ((xaq->nb_xae - 1) / xae_waes), xaq->nb_xaq);
869 : 0 : xaq->nb_xaq += SSO_XAQ_SLACK;
870 : :
871 : 0 : xaq->mem = plt_zmalloc(xaq_buf_size * xaq->nb_xaq, xaq_buf_size);
872 [ # # ]: 0 : if (xaq->mem == NULL) {
873 : 0 : plt_err("Failed to allocate XAQ mem");
874 : : rc = -ENOMEM;
875 : 0 : goto free_fc;
876 : : }
877 : :
878 [ # # # # ]: 0 : if (roc_feature_npa_has_halo() && xaq->halo_ena) {
879 : : struct npa_cn20k_halo_s halo;
880 : :
881 : : memset(&halo, 0, sizeof(struct npa_cn20k_halo_s));
882 : 0 : halo.nat_align = 1;
883 : 0 : halo.fc_ena = 1;
884 : 0 : halo.fc_addr = (uint64_t)xaq->fc;
885 : : halo.fc_hyst_bits = 0; /* Store count on all updates */
886 : 0 : halo.unified_ctx = 1;
887 : 0 : rc = roc_npa_pool_create(&xaq->aura_handle, xaq_buf_size, xaq->nb_xaq,
888 : : NULL, (struct npa_pool_s *)&halo, ROC_NPA_HALO_F);
889 : : } else {
890 : : struct npa_pool_s pool;
891 : : struct npa_aura_s aura;
892 : :
893 : : memset(&pool, 0, sizeof(struct npa_pool_s));
894 : 0 : pool.nat_align = 1;
895 : :
896 : : memset(&aura, 0, sizeof(aura));
897 : 0 : aura.fc_ena = 1;
898 : 0 : aura.fc_addr = (uint64_t)xaq->fc;
899 : : aura.fc_hyst_bits = 0; /* Store count on all updates */
900 : 0 : rc = roc_npa_pool_create(&xaq->aura_handle, xaq_buf_size, xaq->nb_xaq,
901 : : &aura, &pool, 0);
902 : : }
903 : :
904 [ # # ]: 0 : if (rc) {
905 : 0 : plt_err("Failed to create XAQ pool");
906 : 0 : goto npa_fail;
907 : : }
908 : :
909 : 0 : iova = (uint64_t)xaq->mem;
910 [ # # ]: 0 : for (i = 0; i < xaq->nb_xaq; i++) {
911 : 0 : roc_npa_aura_op_free(xaq->aura_handle, 0, iova);
912 : 0 : iova += xaq_buf_size;
913 : : }
914 : 0 : roc_npa_pool_op_range_set(xaq->aura_handle, (uint64_t)xaq->mem, iova);
915 : :
916 : 0 : if (roc_npa_aura_op_available_wait(xaq->aura_handle, xaq->nb_xaq, 0) !=
917 [ # # ]: 0 : xaq->nb_xaq) {
918 : 0 : plt_err("Failed to free all pointers to the pool");
919 : : rc = -ENOMEM;
920 : 0 : goto npa_fill_fail;
921 : : }
922 : :
923 : : /* When SW does addwork (enqueue) check if there is space in XAQ by
924 : : * comparing fc_addr above against the xaq_lmt calculated below.
925 : : * There should be a minimum headroom of 7 XAQs per HWGRP for SSO
926 : : * to request XAQ to cache them even before enqueue is called.
927 : : */
928 : 0 : xaq->xaq_lmt = xaq->nb_xaq - (nb_hwgrp * SSO_XAQ_CACHE_CNT) - SSO_XAQ_SLACK;
929 : :
930 : 0 : return 0;
931 : : npa_fill_fail:
932 : 0 : roc_npa_pool_destroy(xaq->aura_handle);
933 : 0 : npa_fail:
934 : 0 : plt_free(xaq->mem);
935 : 0 : free_fc:
936 : 0 : plt_free(xaq->fc);
937 : 0 : fail:
938 : : memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
939 : 0 : return rc;
940 : : }
941 : :
942 : : int
943 : 0 : roc_sso_hwgrp_init_xaq_aura(struct roc_sso *roc_sso, uint32_t nb_xae)
944 : : {
945 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
946 : 0 : struct dev *dev = &sso->dev;
947 : : int rc;
948 : :
949 : 0 : rc = sso_hwgrp_init_xaq_aura(dev, &roc_sso->xaq, nb_xae, roc_sso->feat.xaq_wq_entries,
950 : 0 : roc_sso->feat.xaq_buf_size, roc_sso->nb_hwgrp);
951 : 0 : return rc;
952 : : }
953 : :
954 : : int
955 : 0 : sso_hwgrp_free_xaq_aura(struct dev *dev, struct roc_sso_xaq_data *xaq,
956 : : uint16_t nb_hwgrp)
957 : : {
958 : : int rc;
959 : :
960 [ # # ]: 0 : if (xaq->mem != NULL) {
961 [ # # ]: 0 : if (nb_hwgrp) {
962 : 0 : rc = sso_hwgrp_release_xaq(dev, nb_hwgrp);
963 [ # # ]: 0 : if (rc < 0) {
964 : 0 : plt_err("Failed to release XAQ %d", rc);
965 : 0 : return rc;
966 : : }
967 : : }
968 : 0 : roc_npa_pool_destroy(xaq->aura_handle);
969 : 0 : plt_free(xaq->fc);
970 : 0 : plt_free(xaq->mem);
971 : : }
972 : : memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
973 : :
974 : 0 : return 0;
975 : : }
976 : :
977 : : int
978 : 0 : roc_sso_hwgrp_free_xaq_aura(struct roc_sso *roc_sso, uint16_t nb_hwgrp)
979 : : {
980 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
981 : 0 : struct dev *dev = &sso->dev;
982 : : int rc;
983 : :
984 : 0 : rc = sso_hwgrp_free_xaq_aura(dev, &roc_sso->xaq, nb_hwgrp);
985 : 0 : return rc;
986 : : }
987 : :
988 : : int
989 : 0 : sso_hwgrp_alloc_xaq(struct dev *dev, uint32_t npa_aura_id, uint16_t hwgrps)
990 : : {
991 : : struct sso_hw_setconfig *req;
992 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
993 : : int rc = -ENOSPC;
994 : :
995 : 0 : req = mbox_alloc_msg_sso_hw_setconfig(mbox);
996 [ # # ]: 0 : if (req == NULL)
997 : 0 : goto exit;
998 : 0 : req->npa_pf_func = idev_npa_pffunc_get();
999 : 0 : req->npa_aura_id = npa_aura_id;
1000 : 0 : req->hwgrps = hwgrps;
1001 : :
1002 [ # # ]: 0 : if (mbox_process(dev->mbox)) {
1003 : : rc = -EIO;
1004 : 0 : goto exit;
1005 : : }
1006 : :
1007 : : rc = 0;
1008 : 0 : exit:
1009 : : mbox_put(mbox);
1010 : 0 : return rc;
1011 : : }
1012 : :
1013 : : int
1014 : 0 : roc_sso_hwgrp_alloc_xaq(struct roc_sso *roc_sso, uint32_t npa_aura_id,
1015 : : uint16_t hwgrps)
1016 : : {
1017 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1018 : 0 : struct dev *dev = &sso->dev;
1019 : : int rc;
1020 : :
1021 : 0 : rc = sso_hwgrp_alloc_xaq(dev, npa_aura_id, hwgrps);
1022 : 0 : return rc;
1023 : : }
1024 : :
1025 : : int
1026 : 0 : sso_hwgrp_release_xaq(struct dev *dev, uint16_t hwgrps)
1027 : : {
1028 : : struct sso_hw_xaq_release *req;
1029 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
1030 : : int rc;
1031 : :
1032 : 0 : req = mbox_alloc_msg_sso_hw_release_xaq_aura(mbox);
1033 [ # # ]: 0 : if (req == NULL) {
1034 : : rc = -EINVAL;
1035 : 0 : goto exit;
1036 : : }
1037 : 0 : req->hwgrps = hwgrps;
1038 : :
1039 [ # # ]: 0 : if (mbox_process(mbox)) {
1040 : : rc = -EIO;
1041 : 0 : goto exit;
1042 : : }
1043 : :
1044 : : rc = 0;
1045 : 0 : exit:
1046 : : mbox_put(mbox);
1047 : 0 : return rc;
1048 : : }
1049 : :
1050 : : int
1051 : 0 : roc_sso_hwgrp_release_xaq(struct roc_sso *roc_sso, uint16_t hwgrps)
1052 : : {
1053 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1054 : 0 : struct dev *dev = &sso->dev;
1055 : : int rc;
1056 : :
1057 [ # # ]: 0 : if (!hwgrps)
1058 : : return 0;
1059 : :
1060 : 0 : rc = sso_hwgrp_release_xaq(dev, hwgrps);
1061 : 0 : return rc;
1062 : : }
1063 : :
1064 : : int
1065 : 0 : roc_sso_hwgrp_set_priority(struct roc_sso *roc_sso, uint16_t hwgrp,
1066 : : uint8_t weight, uint8_t affinity, uint8_t priority)
1067 : : {
1068 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1069 : : struct dev *dev = &sso->dev;
1070 : : struct sso_grp_priority *req;
1071 : : struct mbox *mbox;
1072 : : int rc = -ENOSPC;
1073 : :
1074 : 0 : mbox = mbox_get(dev->mbox);
1075 : 0 : req = mbox_alloc_msg_sso_grp_set_priority(mbox);
1076 [ # # ]: 0 : if (req == NULL)
1077 : 0 : goto fail;
1078 : 0 : req->grp = hwgrp;
1079 : 0 : req->weight = weight;
1080 : 0 : req->affinity = affinity;
1081 : 0 : req->priority = priority;
1082 : :
1083 : 0 : rc = mbox_process(mbox);
1084 [ # # ]: 0 : if (rc) {
1085 : : rc = -EIO;
1086 : 0 : goto fail;
1087 : : }
1088 : : mbox_put(mbox);
1089 : 0 : plt_sso_dbg("HWGRP %d weight %d affinity %d priority %d", hwgrp, weight,
1090 : : affinity, priority);
1091 : :
1092 : 0 : return 0;
1093 : 0 : fail:
1094 : : mbox_put(mbox);
1095 : 0 : return rc;
1096 : : }
1097 : :
1098 : : static int
1099 : 0 : sso_update_msix_vec_count(struct roc_sso *roc_sso, uint16_t sso_vec_cnt)
1100 : : {
1101 : 0 : struct plt_pci_device *pci_dev = roc_sso->pci_dev;
1102 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1103 : : uint16_t mbox_vec_cnt, npa_vec_cnt;
1104 : 0 : struct dev *dev = &sso->dev;
1105 : : struct idev_cfg *idev;
1106 : : int rc;
1107 : :
1108 : 0 : idev = idev_get_cfg();
1109 [ # # ]: 0 : if (idev == NULL)
1110 : : return -ENODEV;
1111 : :
1112 [ # # ]: 0 : if (roc_model_is_cn20k())
1113 : : mbox_vec_cnt = RVU_MBOX_PF_INT_VEC_AFPF_MBOX + 1;
1114 : : else
1115 : : mbox_vec_cnt = RVU_PF_INT_VEC_AFPF_MBOX + 1;
1116 : :
1117 : : /* Allocating vectors for the first time */
1118 [ # # ]: 0 : if (plt_intr_max_intr_get(pci_dev->intr_handle) == 0) {
1119 [ # # ]: 0 : npa_vec_cnt = idev->npa_refcnt ? 0 : NPA_LF_INT_VEC_POISON + 1;
1120 : 0 : return dev_irq_reconfigure(pci_dev->intr_handle, mbox_vec_cnt + npa_vec_cnt);
1121 : : }
1122 : :
1123 : : /* Before re-configuring unregister irqs */
1124 [ # # ]: 0 : npa_vec_cnt = (dev->npa.pci_dev == pci_dev) ? NPA_LF_INT_VEC_POISON + 1 : 0;
1125 : : if (npa_vec_cnt)
1126 : 0 : npa_unregister_irqs(&dev->npa);
1127 : :
1128 : 0 : dev_mbox_unregister_irq(pci_dev, dev);
1129 [ # # ]: 0 : if (!dev_is_vf(dev))
1130 : 0 : dev_vf_flr_unregister_irqs(pci_dev, dev);
1131 : :
1132 : : /* Re-configure to include SSO vectors */
1133 : 0 : rc = dev_irq_reconfigure(pci_dev->intr_handle, mbox_vec_cnt + npa_vec_cnt + sso_vec_cnt);
1134 [ # # ]: 0 : if (rc)
1135 : : return rc;
1136 : :
1137 : 0 : rc = dev_mbox_register_irq(pci_dev, dev);
1138 [ # # ]: 0 : if (rc)
1139 : : return rc;
1140 : :
1141 [ # # ]: 0 : if (!dev_is_vf(dev)) {
1142 : 0 : rc = dev_vf_flr_register_irqs(pci_dev, dev);
1143 [ # # ]: 0 : if (rc)
1144 : : return rc;
1145 : : }
1146 : :
1147 [ # # ]: 0 : if (npa_vec_cnt)
1148 : 0 : rc = npa_register_irqs(&dev->npa);
1149 : :
1150 : : return rc;
1151 : : }
1152 : :
1153 : : int
1154 : 0 : roc_sso_hwgrp_stash_config(struct roc_sso *roc_sso, struct roc_sso_hwgrp_stash *stash,
1155 : : uint16_t nb_stash)
1156 : : {
1157 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1158 : : struct sso_grp_stash_cfg *req;
1159 : : struct dev *dev = &sso->dev;
1160 : : struct mbox *mbox;
1161 : : int i, rc;
1162 : :
1163 [ # # ]: 0 : if (!nb_stash)
1164 : : return 0;
1165 : :
1166 : 0 : mbox = mbox_get(dev->mbox);
1167 [ # # ]: 0 : for (i = 0; i < nb_stash; i++) {
1168 : 0 : req = mbox_alloc_msg_sso_grp_stash_config(mbox);
1169 [ # # ]: 0 : if (req == NULL) {
1170 : 0 : rc = mbox_process(mbox);
1171 [ # # ]: 0 : if (rc) {
1172 : : rc = -EIO;
1173 : 0 : goto fail;
1174 : : }
1175 : :
1176 : 0 : req = mbox_alloc_msg_sso_grp_stash_config(mbox);
1177 [ # # ]: 0 : if (req == NULL) {
1178 : : rc = -ENOSPC;
1179 : 0 : goto fail;
1180 : : }
1181 : : }
1182 : 0 : req->ena = true;
1183 : 0 : req->grp = stash[i].hwgrp;
1184 : 0 : req->offset = stash[i].stash_offset;
1185 : 0 : req->num_linesm1 = stash[i].stash_count - 1;
1186 : : }
1187 : :
1188 : 0 : rc = mbox_process(mbox);
1189 [ # # ]: 0 : if (rc)
1190 : : rc = -EIO;
1191 : 0 : fail:
1192 : : mbox_put(mbox);
1193 : 0 : return rc;
1194 : : }
1195 : :
1196 : : int
1197 : 0 : roc_sso_rsrc_init(struct roc_sso *roc_sso, uint8_t nb_hws, uint16_t nb_hwgrp, uint16_t nb_tim_lfs)
1198 : : {
1199 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1200 : : struct sso_lf_alloc_rsp *rsp_hwgrp;
1201 : : uint16_t sso_vec_cnt, free_tim_lfs;
1202 : : int rc;
1203 : :
1204 [ # # # # ]: 0 : if (!nb_hwgrp || roc_sso->max_hwgrp < nb_hwgrp)
1205 : : return -ENOENT;
1206 [ # # # # ]: 0 : if (!nb_hws || roc_sso->max_hws < nb_hws)
1207 : : return -ENOENT;
1208 : :
1209 : 0 : rc = sso_rsrc_attach(roc_sso, SSO_LF_TYPE_HWS, nb_hws);
1210 [ # # ]: 0 : if (rc < 0) {
1211 : 0 : plt_err("Unable to attach SSO HWS LFs");
1212 : 0 : goto fail;
1213 : : }
1214 : :
1215 : 0 : rc = sso_rsrc_attach(roc_sso, SSO_LF_TYPE_HWGRP, nb_hwgrp);
1216 [ # # ]: 0 : if (rc < 0) {
1217 : 0 : plt_err("Unable to attach SSO HWGRP LFs");
1218 : 0 : goto hwgrp_atch_fail;
1219 : : }
1220 : :
1221 : 0 : rc = sso_lf_alloc(&sso->dev, SSO_LF_TYPE_HWS, nb_hws, NULL);
1222 [ # # ]: 0 : if (rc < 0) {
1223 : 0 : plt_err("Unable to alloc SSO HWS LFs");
1224 : 0 : goto hws_alloc_fail;
1225 : : }
1226 : :
1227 : 0 : rc = sso_lf_alloc(&sso->dev, SSO_LF_TYPE_HWGRP, nb_hwgrp,
1228 : : (void **)&rsp_hwgrp);
1229 [ # # ]: 0 : if (rc < 0) {
1230 : 0 : plt_err("Unable to alloc SSO HWGRP Lfs");
1231 : 0 : goto hwgrp_alloc_fail;
1232 : : }
1233 : :
1234 [ # # # # : 0 : if (!roc_sso->feat.xaq_buf_size || !roc_sso->feat.xaq_wq_entries || !roc_sso->feat.iue) {
# # ]
1235 : 0 : roc_sso->feat.xaq_buf_size = rsp_hwgrp->xaq_buf_size;
1236 : 0 : roc_sso->feat.xaq_wq_entries = rsp_hwgrp->xaq_wq_entries;
1237 : 0 : roc_sso->feat.iue = rsp_hwgrp->in_unit_entries;
1238 : : }
1239 : :
1240 : 0 : rc = sso_msix_fill(roc_sso, nb_hws, nb_hwgrp);
1241 [ # # ]: 0 : if (rc < 0) {
1242 : 0 : plt_err("Unable to get MSIX offsets for SSO LFs");
1243 : 0 : goto sso_msix_fail;
1244 : : }
1245 : :
1246 : : /* 1 error interrupt per SSO HWS/HWGRP */
1247 : 0 : sso_vec_cnt = nb_hws + nb_hwgrp;
1248 : :
1249 [ # # ]: 0 : if (sso->dev.roc_tim) {
1250 : 0 : nb_tim_lfs = ((struct roc_tim *)sso->dev.roc_tim)->nb_lfs;
1251 : : } else {
1252 : 0 : rc = tim_free_lf_count_get(&sso->dev, &free_tim_lfs);
1253 [ # # ]: 0 : if (rc < 0) {
1254 : 0 : plt_err("Failed to get TIM resource count");
1255 : 0 : goto sso_msix_fail;
1256 : : }
1257 : :
1258 : 0 : nb_tim_lfs = PLT_MIN(nb_tim_lfs, free_tim_lfs);
1259 : : }
1260 : :
1261 : : /* 2 error interrupt per TIM LF */
1262 [ # # ]: 0 : if (roc_model_is_cn20k())
1263 : 0 : sso_vec_cnt += 3 * nb_tim_lfs;
1264 : : else
1265 : 0 : sso_vec_cnt += 2 * nb_tim_lfs;
1266 : :
1267 : 0 : rc = sso_update_msix_vec_count(roc_sso, sso_vec_cnt);
1268 [ # # ]: 0 : if (rc < 0) {
1269 : 0 : plt_err("Failed to update SSO MSIX vector count");
1270 : 0 : goto sso_msix_fail;
1271 : : }
1272 : :
1273 : 0 : rc = sso_register_irqs_priv(roc_sso, sso->pci_dev->intr_handle, nb_hws,
1274 : : nb_hwgrp);
1275 [ # # ]: 0 : if (rc < 0) {
1276 : 0 : plt_err("Failed to register SSO LF IRQs");
1277 : 0 : goto sso_msix_fail;
1278 : : }
1279 : :
1280 : 0 : roc_sso->nb_hwgrp = nb_hwgrp;
1281 : 0 : roc_sso->nb_hws = nb_hws;
1282 : :
1283 : 0 : return 0;
1284 : 0 : sso_msix_fail:
1285 : 0 : sso_lf_free(&sso->dev, SSO_LF_TYPE_HWGRP, nb_hwgrp);
1286 : 0 : hwgrp_alloc_fail:
1287 : 0 : sso_lf_free(&sso->dev, SSO_LF_TYPE_HWS, nb_hws);
1288 : 0 : hws_alloc_fail:
1289 : 0 : sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWGRP);
1290 : 0 : hwgrp_atch_fail:
1291 : 0 : sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWS);
1292 : : fail:
1293 : : return rc;
1294 : : }
1295 : :
1296 : : void
1297 : 0 : roc_sso_rsrc_fini(struct roc_sso *roc_sso)
1298 : : {
1299 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1300 : : uint32_t cnt;
1301 : :
1302 [ # # ]: 0 : if (!roc_sso->nb_hws && !roc_sso->nb_hwgrp)
1303 : : return;
1304 : :
1305 [ # # ]: 0 : for (cnt = 0; cnt < roc_sso->nb_hwgrp; cnt++)
1306 : 0 : roc_sso_hwgrp_agq_release(roc_sso, cnt);
1307 : :
1308 : 0 : sso_unregister_irqs_priv(roc_sso, sso->pci_dev->intr_handle,
1309 : 0 : roc_sso->nb_hws, roc_sso->nb_hwgrp);
1310 : 0 : sso_lf_free(&sso->dev, SSO_LF_TYPE_HWS, roc_sso->nb_hws);
1311 : 0 : sso_lf_free(&sso->dev, SSO_LF_TYPE_HWGRP, roc_sso->nb_hwgrp);
1312 : :
1313 : 0 : sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWS);
1314 : 0 : sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWGRP);
1315 : :
1316 : 0 : roc_sso->nb_hwgrp = 0;
1317 : 0 : roc_sso->nb_hws = 0;
1318 : : }
1319 : :
1320 : : int
1321 : 0 : roc_sso_dev_init(struct roc_sso *roc_sso)
1322 : : {
1323 : : struct plt_pci_device *pci_dev;
1324 : : uint32_t link_map_sz;
1325 : : struct sso *sso;
1326 : : void *link_mem;
1327 : : int i, rc;
1328 : :
1329 [ # # # # ]: 0 : if (roc_sso == NULL || roc_sso->pci_dev == NULL)
1330 : : return SSO_ERR_PARAM;
1331 : :
1332 : : PLT_STATIC_ASSERT(sizeof(struct sso) <= ROC_SSO_MEM_SZ);
1333 : : sso = roc_sso_to_sso_priv(roc_sso);
1334 : : memset(sso, 0, sizeof(*sso));
1335 : : pci_dev = roc_sso->pci_dev;
1336 : :
1337 : 0 : rc = sso_update_msix_vec_count(roc_sso, 0);
1338 [ # # ]: 0 : if (rc < 0) {
1339 : 0 : plt_err("Failed to set SSO MSIX vector count");
1340 : 0 : return rc;
1341 : : }
1342 : :
1343 : 0 : rc = dev_init(&sso->dev, pci_dev);
1344 [ # # ]: 0 : if (rc < 0) {
1345 : 0 : plt_err("Failed to init roc device");
1346 : 0 : goto fail;
1347 : : }
1348 : :
1349 : 0 : rc = sso_hw_info_get(roc_sso);
1350 [ # # ]: 0 : if (rc < 0) {
1351 : 0 : plt_err("Failed to get SSO HW info");
1352 : 0 : goto fail;
1353 : : }
1354 : :
1355 : 0 : rc = sso_rsrc_get(roc_sso);
1356 [ # # ]: 0 : if (rc < 0) {
1357 : 0 : plt_err("Failed to get SSO resources");
1358 : 0 : goto rsrc_fail;
1359 : : }
1360 : : rc = -ENOMEM;
1361 : :
1362 [ # # ]: 0 : if (roc_sso->max_hws) {
1363 : 0 : sso->link_map = plt_zmalloc(
1364 : : sizeof(struct plt_bitmap *) * roc_sso->max_hws, 0);
1365 [ # # ]: 0 : if (sso->link_map == NULL) {
1366 : 0 : plt_err("Failed to allocate memory for link_map array");
1367 : 0 : goto rsrc_fail;
1368 : : }
1369 : :
1370 : : link_map_sz =
1371 : 0 : plt_bitmap_get_memory_footprint(roc_sso->max_hwgrp);
1372 : 0 : sso->link_map_mem =
1373 : 0 : plt_zmalloc(link_map_sz * roc_sso->max_hws, 0);
1374 [ # # ]: 0 : if (sso->link_map_mem == NULL) {
1375 : 0 : plt_err("Failed to get link_map memory");
1376 : 0 : goto rsrc_fail;
1377 : : }
1378 : :
1379 : : link_mem = sso->link_map_mem;
1380 : :
1381 [ # # ]: 0 : for (i = 0; i < roc_sso->max_hws; i++) {
1382 : 0 : sso->link_map[i] = plt_bitmap_init(
1383 : 0 : roc_sso->max_hwgrp, link_mem, link_map_sz);
1384 [ # # ]: 0 : if (sso->link_map[i] == NULL) {
1385 : 0 : plt_err("Failed to allocate link map");
1386 : 0 : goto link_mem_free;
1387 : : }
1388 : 0 : link_mem = PLT_PTR_ADD(link_mem, link_map_sz);
1389 : : }
1390 : : }
1391 : 0 : idev_sso_pffunc_set(sso->dev.pf_func);
1392 : 0 : idev_sso_set(roc_sso);
1393 : 0 : sso->pci_dev = pci_dev;
1394 : 0 : sso->dev.drv_inited = true;
1395 : 0 : roc_sso->lmt_base = sso->dev.lmt_base;
1396 : :
1397 : 0 : return 0;
1398 : : link_mem_free:
1399 : 0 : plt_free(sso->link_map_mem);
1400 : 0 : rsrc_fail:
1401 : 0 : rc |= dev_fini(&sso->dev, pci_dev);
1402 : : fail:
1403 : : return rc;
1404 : : }
1405 : :
1406 : : int
1407 : 0 : roc_sso_dev_fini(struct roc_sso *roc_sso)
1408 : : {
1409 : : struct sso *sso;
1410 : :
1411 : : sso = roc_sso_to_sso_priv(roc_sso);
1412 : 0 : sso->dev.drv_inited = false;
1413 : :
1414 : 0 : return dev_fini(&sso->dev, sso->pci_dev);
1415 : : }
|