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 : : struct npa_pool_s pool;
838 : : struct npa_aura_s aura;
839 : : plt_iova_t iova;
840 : : uint32_t i;
841 : : int rc;
842 : :
843 [ # # ]: 0 : if (xaq->mem != NULL) {
844 : 0 : rc = sso_hwgrp_release_xaq(dev, nb_hwgrp);
845 [ # # ]: 0 : if (rc < 0) {
846 : 0 : plt_err("Failed to release XAQ %d", rc);
847 : 0 : return rc;
848 : : }
849 : 0 : roc_npa_pool_destroy(xaq->aura_handle);
850 : 0 : plt_free(xaq->fc);
851 : 0 : plt_free(xaq->mem);
852 : : memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
853 : : }
854 : :
855 : 0 : xaq->fc = plt_zmalloc(ROC_ALIGN, ROC_ALIGN);
856 [ # # ]: 0 : if (xaq->fc == NULL) {
857 : 0 : plt_err("Failed to allocate XAQ FC");
858 : : rc = -ENOMEM;
859 : 0 : goto fail;
860 : : }
861 : :
862 : 0 : xaq->nb_xae = nb_xae;
863 : :
864 : : /** SSO will reserve up to 0x4 XAQ buffers per group when GetWork engine
865 : : * is inactive and it might prefetch an additional 0x3 buffers due to
866 : : * pipelining.
867 : : */
868 : 0 : xaq->nb_xaq = (SSO_XAQ_CACHE_CNT * nb_hwgrp);
869 : 0 : xaq->nb_xaq += (SSO_XAQ_RSVD_CNT * nb_hwgrp);
870 : 0 : xaq->nb_xaq += PLT_MAX(1 + ((xaq->nb_xae - 1) / xae_waes), xaq->nb_xaq);
871 : 0 : xaq->nb_xaq += SSO_XAQ_SLACK;
872 : :
873 : 0 : xaq->mem = plt_zmalloc(xaq_buf_size * xaq->nb_xaq, xaq_buf_size);
874 [ # # ]: 0 : if (xaq->mem == NULL) {
875 : 0 : plt_err("Failed to allocate XAQ mem");
876 : : rc = -ENOMEM;
877 : 0 : goto free_fc;
878 : : }
879 : :
880 : : memset(&pool, 0, sizeof(struct npa_pool_s));
881 : 0 : pool.nat_align = 1;
882 : :
883 : : memset(&aura, 0, sizeof(aura));
884 : 0 : aura.fc_ena = 1;
885 : 0 : aura.fc_addr = (uint64_t)xaq->fc;
886 : : aura.fc_hyst_bits = 0; /* Store count on all updates */
887 : 0 : rc = roc_npa_pool_create(&xaq->aura_handle, xaq_buf_size, xaq->nb_xaq,
888 : : &aura, &pool, 0);
889 [ # # ]: 0 : if (rc) {
890 : 0 : plt_err("Failed to create XAQ pool");
891 : 0 : goto npa_fail;
892 : : }
893 : :
894 : 0 : iova = (uint64_t)xaq->mem;
895 [ # # ]: 0 : for (i = 0; i < xaq->nb_xaq; i++) {
896 : 0 : roc_npa_aura_op_free(xaq->aura_handle, 0, iova);
897 : 0 : iova += xaq_buf_size;
898 : : }
899 : 0 : roc_npa_pool_op_range_set(xaq->aura_handle, (uint64_t)xaq->mem, iova);
900 : :
901 : 0 : if (roc_npa_aura_op_available_wait(xaq->aura_handle, xaq->nb_xaq, 0) !=
902 [ # # ]: 0 : xaq->nb_xaq) {
903 : 0 : plt_err("Failed to free all pointers to the pool");
904 : : rc = -ENOMEM;
905 : 0 : goto npa_fill_fail;
906 : : }
907 : :
908 : : /* When SW does addwork (enqueue) check if there is space in XAQ by
909 : : * comparing fc_addr above against the xaq_lmt calculated below.
910 : : * There should be a minimum headroom of 7 XAQs per HWGRP for SSO
911 : : * to request XAQ to cache them even before enqueue is called.
912 : : */
913 : 0 : xaq->xaq_lmt = xaq->nb_xaq - (nb_hwgrp * SSO_XAQ_CACHE_CNT) - SSO_XAQ_SLACK;
914 : :
915 : 0 : return 0;
916 : : npa_fill_fail:
917 : 0 : roc_npa_pool_destroy(xaq->aura_handle);
918 : 0 : npa_fail:
919 : 0 : plt_free(xaq->mem);
920 : 0 : free_fc:
921 : 0 : plt_free(xaq->fc);
922 : 0 : fail:
923 : : memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
924 : 0 : return rc;
925 : : }
926 : :
927 : : int
928 : 0 : roc_sso_hwgrp_init_xaq_aura(struct roc_sso *roc_sso, uint32_t nb_xae)
929 : : {
930 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
931 : 0 : struct dev *dev = &sso->dev;
932 : : int rc;
933 : :
934 : 0 : rc = sso_hwgrp_init_xaq_aura(dev, &roc_sso->xaq, nb_xae, roc_sso->feat.xaq_wq_entries,
935 : 0 : roc_sso->feat.xaq_buf_size, roc_sso->nb_hwgrp);
936 : 0 : return rc;
937 : : }
938 : :
939 : : int
940 : 0 : sso_hwgrp_free_xaq_aura(struct dev *dev, struct roc_sso_xaq_data *xaq,
941 : : uint16_t nb_hwgrp)
942 : : {
943 : : int rc;
944 : :
945 [ # # ]: 0 : if (xaq->mem != NULL) {
946 [ # # ]: 0 : if (nb_hwgrp) {
947 : 0 : rc = sso_hwgrp_release_xaq(dev, nb_hwgrp);
948 [ # # ]: 0 : if (rc < 0) {
949 : 0 : plt_err("Failed to release XAQ %d", rc);
950 : 0 : return rc;
951 : : }
952 : : }
953 : 0 : roc_npa_pool_destroy(xaq->aura_handle);
954 : 0 : plt_free(xaq->fc);
955 : 0 : plt_free(xaq->mem);
956 : : }
957 : : memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
958 : :
959 : 0 : return 0;
960 : : }
961 : :
962 : : int
963 : 0 : roc_sso_hwgrp_free_xaq_aura(struct roc_sso *roc_sso, uint16_t nb_hwgrp)
964 : : {
965 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
966 : 0 : struct dev *dev = &sso->dev;
967 : : int rc;
968 : :
969 : 0 : rc = sso_hwgrp_free_xaq_aura(dev, &roc_sso->xaq, nb_hwgrp);
970 : 0 : return rc;
971 : : }
972 : :
973 : : int
974 : 0 : sso_hwgrp_alloc_xaq(struct dev *dev, uint32_t npa_aura_id, uint16_t hwgrps)
975 : : {
976 : : struct sso_hw_setconfig *req;
977 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
978 : : int rc = -ENOSPC;
979 : :
980 : 0 : req = mbox_alloc_msg_sso_hw_setconfig(mbox);
981 [ # # ]: 0 : if (req == NULL)
982 : 0 : goto exit;
983 : 0 : req->npa_pf_func = idev_npa_pffunc_get();
984 : 0 : req->npa_aura_id = npa_aura_id;
985 : 0 : req->hwgrps = hwgrps;
986 : :
987 [ # # ]: 0 : if (mbox_process(dev->mbox)) {
988 : : rc = -EIO;
989 : 0 : goto exit;
990 : : }
991 : :
992 : : rc = 0;
993 : 0 : exit:
994 : : mbox_put(mbox);
995 : 0 : return rc;
996 : : }
997 : :
998 : : int
999 : 0 : roc_sso_hwgrp_alloc_xaq(struct roc_sso *roc_sso, uint32_t npa_aura_id,
1000 : : uint16_t hwgrps)
1001 : : {
1002 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1003 : 0 : struct dev *dev = &sso->dev;
1004 : : int rc;
1005 : :
1006 : 0 : rc = sso_hwgrp_alloc_xaq(dev, npa_aura_id, hwgrps);
1007 : 0 : return rc;
1008 : : }
1009 : :
1010 : : int
1011 : 0 : sso_hwgrp_release_xaq(struct dev *dev, uint16_t hwgrps)
1012 : : {
1013 : : struct sso_hw_xaq_release *req;
1014 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
1015 : : int rc;
1016 : :
1017 : 0 : req = mbox_alloc_msg_sso_hw_release_xaq_aura(mbox);
1018 [ # # ]: 0 : if (req == NULL) {
1019 : : rc = -EINVAL;
1020 : 0 : goto exit;
1021 : : }
1022 : 0 : req->hwgrps = hwgrps;
1023 : :
1024 [ # # ]: 0 : if (mbox_process(mbox)) {
1025 : : rc = -EIO;
1026 : 0 : goto exit;
1027 : : }
1028 : :
1029 : : rc = 0;
1030 : 0 : exit:
1031 : : mbox_put(mbox);
1032 : 0 : return rc;
1033 : : }
1034 : :
1035 : : int
1036 : 0 : roc_sso_hwgrp_release_xaq(struct roc_sso *roc_sso, uint16_t hwgrps)
1037 : : {
1038 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1039 : 0 : struct dev *dev = &sso->dev;
1040 : : int rc;
1041 : :
1042 [ # # ]: 0 : if (!hwgrps)
1043 : : return 0;
1044 : :
1045 : 0 : rc = sso_hwgrp_release_xaq(dev, hwgrps);
1046 : 0 : return rc;
1047 : : }
1048 : :
1049 : : int
1050 : 0 : roc_sso_hwgrp_set_priority(struct roc_sso *roc_sso, uint16_t hwgrp,
1051 : : uint8_t weight, uint8_t affinity, uint8_t priority)
1052 : : {
1053 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1054 : : struct dev *dev = &sso->dev;
1055 : : struct sso_grp_priority *req;
1056 : : struct mbox *mbox;
1057 : : int rc = -ENOSPC;
1058 : :
1059 : 0 : mbox = mbox_get(dev->mbox);
1060 : 0 : req = mbox_alloc_msg_sso_grp_set_priority(mbox);
1061 [ # # ]: 0 : if (req == NULL)
1062 : 0 : goto fail;
1063 : 0 : req->grp = hwgrp;
1064 : 0 : req->weight = weight;
1065 : 0 : req->affinity = affinity;
1066 : 0 : req->priority = priority;
1067 : :
1068 : 0 : rc = mbox_process(mbox);
1069 [ # # ]: 0 : if (rc) {
1070 : : rc = -EIO;
1071 : 0 : goto fail;
1072 : : }
1073 : : mbox_put(mbox);
1074 : 0 : plt_sso_dbg("HWGRP %d weight %d affinity %d priority %d", hwgrp, weight,
1075 : : affinity, priority);
1076 : :
1077 : 0 : return 0;
1078 : 0 : fail:
1079 : : mbox_put(mbox);
1080 : 0 : return rc;
1081 : : }
1082 : :
1083 : : static int
1084 : 0 : sso_update_msix_vec_count(struct roc_sso *roc_sso, uint16_t sso_vec_cnt)
1085 : : {
1086 : 0 : struct plt_pci_device *pci_dev = roc_sso->pci_dev;
1087 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1088 : : uint16_t mbox_vec_cnt, npa_vec_cnt;
1089 : 0 : struct dev *dev = &sso->dev;
1090 : : struct idev_cfg *idev;
1091 : : int rc;
1092 : :
1093 : 0 : idev = idev_get_cfg();
1094 [ # # ]: 0 : if (idev == NULL)
1095 : : return -ENODEV;
1096 : :
1097 [ # # ]: 0 : if (roc_model_is_cn20k())
1098 : : mbox_vec_cnt = RVU_MBOX_PF_INT_VEC_AFPF_MBOX + 1;
1099 : : else
1100 : : mbox_vec_cnt = RVU_PF_INT_VEC_AFPF_MBOX + 1;
1101 : :
1102 : : /* Allocating vectors for the first time */
1103 [ # # ]: 0 : if (plt_intr_max_intr_get(pci_dev->intr_handle) == 0) {
1104 [ # # ]: 0 : npa_vec_cnt = idev->npa_refcnt ? 0 : NPA_LF_INT_VEC_POISON + 1;
1105 : 0 : return dev_irq_reconfigure(pci_dev->intr_handle, mbox_vec_cnt + npa_vec_cnt);
1106 : : }
1107 : :
1108 : : /* Before re-configuring unregister irqs */
1109 [ # # ]: 0 : npa_vec_cnt = (dev->npa.pci_dev == pci_dev) ? NPA_LF_INT_VEC_POISON + 1 : 0;
1110 : : if (npa_vec_cnt)
1111 : 0 : npa_unregister_irqs(&dev->npa);
1112 : :
1113 : 0 : dev_mbox_unregister_irq(pci_dev, dev);
1114 [ # # ]: 0 : if (!dev_is_vf(dev))
1115 : 0 : dev_vf_flr_unregister_irqs(pci_dev, dev);
1116 : :
1117 : : /* Re-configure to include SSO vectors */
1118 : 0 : rc = dev_irq_reconfigure(pci_dev->intr_handle, mbox_vec_cnt + npa_vec_cnt + sso_vec_cnt);
1119 [ # # ]: 0 : if (rc)
1120 : : return rc;
1121 : :
1122 : 0 : rc = dev_mbox_register_irq(pci_dev, dev);
1123 [ # # ]: 0 : if (rc)
1124 : : return rc;
1125 : :
1126 [ # # ]: 0 : if (!dev_is_vf(dev)) {
1127 : 0 : rc = dev_vf_flr_register_irqs(pci_dev, dev);
1128 [ # # ]: 0 : if (rc)
1129 : : return rc;
1130 : : }
1131 : :
1132 [ # # ]: 0 : if (npa_vec_cnt)
1133 : 0 : rc = npa_register_irqs(&dev->npa);
1134 : :
1135 : : return rc;
1136 : : }
1137 : :
1138 : : int
1139 : 0 : roc_sso_hwgrp_stash_config(struct roc_sso *roc_sso, struct roc_sso_hwgrp_stash *stash,
1140 : : uint16_t nb_stash)
1141 : : {
1142 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1143 : : struct sso_grp_stash_cfg *req;
1144 : : struct dev *dev = &sso->dev;
1145 : : struct mbox *mbox;
1146 : : int i, rc;
1147 : :
1148 [ # # ]: 0 : if (!nb_stash)
1149 : : return 0;
1150 : :
1151 : 0 : mbox = mbox_get(dev->mbox);
1152 [ # # ]: 0 : for (i = 0; i < nb_stash; i++) {
1153 : 0 : req = mbox_alloc_msg_sso_grp_stash_config(mbox);
1154 [ # # ]: 0 : if (req == NULL) {
1155 : 0 : rc = mbox_process(mbox);
1156 [ # # ]: 0 : if (rc) {
1157 : : rc = -EIO;
1158 : 0 : goto fail;
1159 : : }
1160 : :
1161 : 0 : req = mbox_alloc_msg_sso_grp_stash_config(mbox);
1162 [ # # ]: 0 : if (req == NULL) {
1163 : : rc = -ENOSPC;
1164 : 0 : goto fail;
1165 : : }
1166 : : }
1167 : 0 : req->ena = true;
1168 : 0 : req->grp = stash[i].hwgrp;
1169 : 0 : req->offset = stash[i].stash_offset;
1170 : 0 : req->num_linesm1 = stash[i].stash_count - 1;
1171 : : }
1172 : :
1173 : 0 : rc = mbox_process(mbox);
1174 [ # # ]: 0 : if (rc)
1175 : : rc = -EIO;
1176 : 0 : fail:
1177 : : mbox_put(mbox);
1178 : 0 : return rc;
1179 : : }
1180 : :
1181 : : int
1182 : 0 : roc_sso_rsrc_init(struct roc_sso *roc_sso, uint8_t nb_hws, uint16_t nb_hwgrp, uint16_t nb_tim_lfs)
1183 : : {
1184 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1185 : : struct sso_lf_alloc_rsp *rsp_hwgrp;
1186 : : uint16_t sso_vec_cnt, free_tim_lfs;
1187 : : int rc;
1188 : :
1189 [ # # # # ]: 0 : if (!nb_hwgrp || roc_sso->max_hwgrp < nb_hwgrp)
1190 : : return -ENOENT;
1191 [ # # # # ]: 0 : if (!nb_hws || roc_sso->max_hws < nb_hws)
1192 : : return -ENOENT;
1193 : :
1194 : 0 : rc = sso_rsrc_attach(roc_sso, SSO_LF_TYPE_HWS, nb_hws);
1195 [ # # ]: 0 : if (rc < 0) {
1196 : 0 : plt_err("Unable to attach SSO HWS LFs");
1197 : 0 : goto fail;
1198 : : }
1199 : :
1200 : 0 : rc = sso_rsrc_attach(roc_sso, SSO_LF_TYPE_HWGRP, nb_hwgrp);
1201 [ # # ]: 0 : if (rc < 0) {
1202 : 0 : plt_err("Unable to attach SSO HWGRP LFs");
1203 : 0 : goto hwgrp_atch_fail;
1204 : : }
1205 : :
1206 : 0 : rc = sso_lf_alloc(&sso->dev, SSO_LF_TYPE_HWS, nb_hws, NULL);
1207 [ # # ]: 0 : if (rc < 0) {
1208 : 0 : plt_err("Unable to alloc SSO HWS LFs");
1209 : 0 : goto hws_alloc_fail;
1210 : : }
1211 : :
1212 : 0 : rc = sso_lf_alloc(&sso->dev, SSO_LF_TYPE_HWGRP, nb_hwgrp,
1213 : : (void **)&rsp_hwgrp);
1214 [ # # ]: 0 : if (rc < 0) {
1215 : 0 : plt_err("Unable to alloc SSO HWGRP Lfs");
1216 : 0 : goto hwgrp_alloc_fail;
1217 : : }
1218 : :
1219 [ # # # # : 0 : if (!roc_sso->feat.xaq_buf_size || !roc_sso->feat.xaq_wq_entries || !roc_sso->feat.iue) {
# # ]
1220 : 0 : roc_sso->feat.xaq_buf_size = rsp_hwgrp->xaq_buf_size;
1221 : 0 : roc_sso->feat.xaq_wq_entries = rsp_hwgrp->xaq_wq_entries;
1222 : 0 : roc_sso->feat.iue = rsp_hwgrp->in_unit_entries;
1223 : : }
1224 : :
1225 : 0 : rc = sso_msix_fill(roc_sso, nb_hws, nb_hwgrp);
1226 [ # # ]: 0 : if (rc < 0) {
1227 : 0 : plt_err("Unable to get MSIX offsets for SSO LFs");
1228 : 0 : goto sso_msix_fail;
1229 : : }
1230 : :
1231 : : /* 1 error interrupt per SSO HWS/HWGRP */
1232 : 0 : sso_vec_cnt = nb_hws + nb_hwgrp;
1233 : :
1234 [ # # ]: 0 : if (sso->dev.roc_tim) {
1235 : 0 : nb_tim_lfs = ((struct roc_tim *)sso->dev.roc_tim)->nb_lfs;
1236 : : } else {
1237 : 0 : rc = tim_free_lf_count_get(&sso->dev, &free_tim_lfs);
1238 [ # # ]: 0 : if (rc < 0) {
1239 : 0 : plt_err("Failed to get TIM resource count");
1240 : 0 : goto sso_msix_fail;
1241 : : }
1242 : :
1243 : 0 : nb_tim_lfs = PLT_MIN(nb_tim_lfs, free_tim_lfs);
1244 : : }
1245 : :
1246 : : /* 2 error interrupt per TIM LF */
1247 [ # # ]: 0 : if (roc_model_is_cn20k())
1248 : 0 : sso_vec_cnt += 3 * nb_tim_lfs;
1249 : : else
1250 : 0 : sso_vec_cnt += 2 * nb_tim_lfs;
1251 : :
1252 : 0 : rc = sso_update_msix_vec_count(roc_sso, sso_vec_cnt);
1253 [ # # ]: 0 : if (rc < 0) {
1254 : 0 : plt_err("Failed to update SSO MSIX vector count");
1255 : 0 : goto sso_msix_fail;
1256 : : }
1257 : :
1258 : 0 : rc = sso_register_irqs_priv(roc_sso, sso->pci_dev->intr_handle, nb_hws,
1259 : : nb_hwgrp);
1260 [ # # ]: 0 : if (rc < 0) {
1261 : 0 : plt_err("Failed to register SSO LF IRQs");
1262 : 0 : goto sso_msix_fail;
1263 : : }
1264 : :
1265 : 0 : roc_sso->nb_hwgrp = nb_hwgrp;
1266 : 0 : roc_sso->nb_hws = nb_hws;
1267 : :
1268 : 0 : return 0;
1269 : 0 : sso_msix_fail:
1270 : 0 : sso_lf_free(&sso->dev, SSO_LF_TYPE_HWGRP, nb_hwgrp);
1271 : 0 : hwgrp_alloc_fail:
1272 : 0 : sso_lf_free(&sso->dev, SSO_LF_TYPE_HWS, nb_hws);
1273 : 0 : hws_alloc_fail:
1274 : 0 : sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWGRP);
1275 : 0 : hwgrp_atch_fail:
1276 : 0 : sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWS);
1277 : : fail:
1278 : : return rc;
1279 : : }
1280 : :
1281 : : void
1282 : 0 : roc_sso_rsrc_fini(struct roc_sso *roc_sso)
1283 : : {
1284 : : struct sso *sso = roc_sso_to_sso_priv(roc_sso);
1285 : : uint32_t cnt;
1286 : :
1287 [ # # ]: 0 : if (!roc_sso->nb_hws && !roc_sso->nb_hwgrp)
1288 : : return;
1289 : :
1290 [ # # ]: 0 : for (cnt = 0; cnt < roc_sso->nb_hwgrp; cnt++)
1291 : 0 : roc_sso_hwgrp_agq_release(roc_sso, cnt);
1292 : :
1293 : 0 : sso_unregister_irqs_priv(roc_sso, sso->pci_dev->intr_handle,
1294 : 0 : roc_sso->nb_hws, roc_sso->nb_hwgrp);
1295 : 0 : sso_lf_free(&sso->dev, SSO_LF_TYPE_HWS, roc_sso->nb_hws);
1296 : 0 : sso_lf_free(&sso->dev, SSO_LF_TYPE_HWGRP, roc_sso->nb_hwgrp);
1297 : :
1298 : 0 : sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWS);
1299 : 0 : sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWGRP);
1300 : :
1301 : 0 : roc_sso->nb_hwgrp = 0;
1302 : 0 : roc_sso->nb_hws = 0;
1303 : : }
1304 : :
1305 : : int
1306 : 0 : roc_sso_dev_init(struct roc_sso *roc_sso)
1307 : : {
1308 : : struct plt_pci_device *pci_dev;
1309 : : uint32_t link_map_sz;
1310 : : struct sso *sso;
1311 : : void *link_mem;
1312 : : int i, rc;
1313 : :
1314 [ # # # # ]: 0 : if (roc_sso == NULL || roc_sso->pci_dev == NULL)
1315 : : return SSO_ERR_PARAM;
1316 : :
1317 : : PLT_STATIC_ASSERT(sizeof(struct sso) <= ROC_SSO_MEM_SZ);
1318 : : sso = roc_sso_to_sso_priv(roc_sso);
1319 : : memset(sso, 0, sizeof(*sso));
1320 : : pci_dev = roc_sso->pci_dev;
1321 : :
1322 : 0 : rc = sso_update_msix_vec_count(roc_sso, 0);
1323 [ # # ]: 0 : if (rc < 0) {
1324 : 0 : plt_err("Failed to set SSO MSIX vector count");
1325 : 0 : return rc;
1326 : : }
1327 : :
1328 : 0 : rc = dev_init(&sso->dev, pci_dev);
1329 [ # # ]: 0 : if (rc < 0) {
1330 : 0 : plt_err("Failed to init roc device");
1331 : 0 : goto fail;
1332 : : }
1333 : :
1334 : 0 : rc = sso_hw_info_get(roc_sso);
1335 [ # # ]: 0 : if (rc < 0) {
1336 : 0 : plt_err("Failed to get SSO HW info");
1337 : 0 : goto fail;
1338 : : }
1339 : :
1340 : 0 : rc = sso_rsrc_get(roc_sso);
1341 [ # # ]: 0 : if (rc < 0) {
1342 : 0 : plt_err("Failed to get SSO resources");
1343 : 0 : goto rsrc_fail;
1344 : : }
1345 : : rc = -ENOMEM;
1346 : :
1347 [ # # ]: 0 : if (roc_sso->max_hws) {
1348 : 0 : sso->link_map = plt_zmalloc(
1349 : : sizeof(struct plt_bitmap *) * roc_sso->max_hws, 0);
1350 [ # # ]: 0 : if (sso->link_map == NULL) {
1351 : 0 : plt_err("Failed to allocate memory for link_map array");
1352 : 0 : goto rsrc_fail;
1353 : : }
1354 : :
1355 : : link_map_sz =
1356 : 0 : plt_bitmap_get_memory_footprint(roc_sso->max_hwgrp);
1357 : 0 : sso->link_map_mem =
1358 : 0 : plt_zmalloc(link_map_sz * roc_sso->max_hws, 0);
1359 [ # # ]: 0 : if (sso->link_map_mem == NULL) {
1360 : 0 : plt_err("Failed to get link_map memory");
1361 : 0 : goto rsrc_fail;
1362 : : }
1363 : :
1364 : : link_mem = sso->link_map_mem;
1365 : :
1366 [ # # ]: 0 : for (i = 0; i < roc_sso->max_hws; i++) {
1367 : 0 : sso->link_map[i] = plt_bitmap_init(
1368 : 0 : roc_sso->max_hwgrp, link_mem, link_map_sz);
1369 [ # # ]: 0 : if (sso->link_map[i] == NULL) {
1370 : 0 : plt_err("Failed to allocate link map");
1371 : 0 : goto link_mem_free;
1372 : : }
1373 : 0 : link_mem = PLT_PTR_ADD(link_mem, link_map_sz);
1374 : : }
1375 : : }
1376 : 0 : idev_sso_pffunc_set(sso->dev.pf_func);
1377 : 0 : idev_sso_set(roc_sso);
1378 : 0 : sso->pci_dev = pci_dev;
1379 : 0 : sso->dev.drv_inited = true;
1380 : 0 : roc_sso->lmt_base = sso->dev.lmt_base;
1381 : :
1382 : 0 : return 0;
1383 : : link_mem_free:
1384 : 0 : plt_free(sso->link_map_mem);
1385 : 0 : rsrc_fail:
1386 : 0 : rc |= dev_fini(&sso->dev, pci_dev);
1387 : : fail:
1388 : : return rc;
1389 : : }
1390 : :
1391 : : int
1392 : 0 : roc_sso_dev_fini(struct roc_sso *roc_sso)
1393 : : {
1394 : : struct sso *sso;
1395 : :
1396 : : sso = roc_sso_to_sso_priv(roc_sso);
1397 : 0 : sso->dev.drv_inited = false;
1398 : :
1399 : 0 : return dev_fini(&sso->dev, sso->pci_dev);
1400 : : }
|