Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : :
5 : : #include <fcntl.h>
6 : : #include <sys/stat.h>
7 : : #include <sys/types.h>
8 : : #include <unistd.h>
9 : : #include <stdarg.h>
10 : :
11 : : #include "roc_api.h"
12 : : #include "roc_priv.h"
13 : :
14 : : #define ROC_DPI_DEV_NAME "roc_dpi_dev_"
15 : : #define ROC_DPI_DEV_NAME_LEN (sizeof(ROC_DPI_DEV_NAME) + PCI_PRI_STR_SIZE)
16 : :
17 : : #define DPI_PF_MBOX_SYSFS_ENTRY "dpi_device_config"
18 : :
19 : : static inline int
20 : 0 : send_msg_to_pf(struct plt_pci_addr *pci_addr, const char *value, int size)
21 : : {
22 : 0 : char buf[255] = {0};
23 : : int res, fd;
24 : :
25 : 0 : res = snprintf(
26 : : buf, sizeof(buf), "/sys/bus/pci/devices/" PCI_PRI_FMT "/%s",
27 [ # # ]: 0 : pci_addr->domain, pci_addr->bus, DPI_PF_DBDF_DEVICE & 0x7,
28 : : DPI_PF_DBDF_FUNCTION & 0x7, DPI_PF_MBOX_SYSFS_ENTRY);
29 : :
30 [ # # ]: 0 : if ((res < 0) || ((size_t)res > sizeof(buf)))
31 : : return -ERANGE;
32 : :
33 : : fd = open(buf, O_WRONLY);
34 [ # # ]: 0 : if (fd < 0)
35 : : return -EACCES;
36 : :
37 : 0 : res = write(fd, value, size);
38 : 0 : close(fd);
39 [ # # ]: 0 : if (res < 0)
40 : 0 : return -EACCES;
41 : :
42 : : return 0;
43 : : }
44 : :
45 : : int
46 : 0 : roc_dpi_wait_queue_idle(struct roc_dpi *roc_dpi)
47 : : {
48 : 0 : const uint64_t cyc = (DPI_QUEUE_IDLE_TMO_MS * plt_tsc_hz()) / 1E3;
49 : : const uint64_t start = plt_tsc_cycles();
50 : : uint64_t reg;
51 : :
52 : : /* Wait for SADDR to become idle */
53 : 0 : reg = plt_read64(roc_dpi->rbase + DPI_VDMA_SADDR);
54 [ # # ]: 0 : while (!(reg & BIT_ULL(63))) {
55 : 0 : reg = plt_read64(roc_dpi->rbase + DPI_VDMA_SADDR);
56 [ # # ]: 0 : if (plt_tsc_cycles() - start == cyc)
57 : : return -ETIMEDOUT;
58 : : }
59 : :
60 : : return 0;
61 : : }
62 : :
63 : : void
64 : 0 : dpi_lf_ena_dis(struct roc_dpi_lf *lf, uint8_t enb)
65 : : {
66 : : uint64_t reg;
67 : : int ring_idx;
68 : :
69 [ # # ]: 0 : for (ring_idx = 0; ring_idx < ROC_DPI_LF_RINGS; ring_idx++) {
70 [ # # ]: 0 : reg = plt_read64(lf->rbase + DPI_LF_RINGX_CFG(ring_idx));
71 : :
72 [ # # ]: 0 : if (enb)
73 : 0 : reg |= DPI_LF_QCFG_QEN;
74 : : else
75 : 0 : reg &= ~DPI_LF_QCFG_QEN;
76 : :
77 : : plt_write64(reg, lf->rbase + DPI_LF_RINGX_CFG(ring_idx));
78 : : }
79 : 0 : }
80 : :
81 : : int
82 : 0 : dpi_lf_reset(struct roc_dpi_lf *lf)
83 : : {
84 : : uint64_t start_cycle;
85 : : uint64_t wait_cycles;
86 : : uintptr_t reg_addr;
87 : : int ring_idx;
88 : :
89 : 0 : wait_cycles = (DPI_LF_RESET_TMO_US * plt_tsc_hz()) / 1000000;
90 : :
91 [ # # ]: 0 : for (ring_idx = 0; ring_idx < ROC_DPI_LF_RINGS; ring_idx++) {
92 : 0 : reg_addr = lf->rbase + DPI_LF_RINGX_RST(ring_idx);
93 : 0 : plt_write64(DPI_LF_QUEUE_RST, reg_addr);
94 : :
95 : : start_cycle = plt_tsc_cycles();
96 [ # # ]: 0 : while (plt_read64(reg_addr) & DPI_LF_QUEUE_RST) {
97 [ # # ]: 0 : if (plt_tsc_cycles() - start_cycle >= wait_cycles) {
98 : 0 : plt_err("DPI LF[%u]: ring[%u] reset timed out", lf->slot, ring_idx);
99 : 0 : return -ETIMEDOUT;
100 : : }
101 : : }
102 : : }
103 : :
104 : : return 0;
105 : : }
106 : :
107 : : int
108 : 0 : roc_dpi_access_pair_group_create(struct roc_dpi_lf *lf, plt_uuid_t domain_id, plt_uuid_t token,
109 : : int16_t *group_id)
110 : : {
111 : 0 : struct mbox *mbox = mbox_get(lf->dev->mbox);
112 : : struct dpi_lf_access_group_alloc_req *req;
113 : : struct dpi_lf_access_group_alloc_rsp *rsp;
114 : : int rc;
115 : :
116 : 0 : req = mbox_alloc_msg_dpi_lf_access_group_alloc(mbox);
117 [ # # ]: 0 : if (req == NULL) {
118 : : rc = -ENOSPC;
119 : 0 : goto exit;
120 : : }
121 : :
122 : 0 : req->dpi_blkaddr = lf->blk_addr;
123 [ # # ]: 0 : mbox_memcpy(req->lf_handle, domain_id, sizeof(plt_uuid_t));
124 [ # # ]: 0 : mbox_memcpy(req->access_key, token, sizeof(plt_uuid_t));
125 : :
126 : : rc = mbox_process_msg(mbox, (void **)&rsp);
127 [ # # ]: 0 : if (rc)
128 : 0 : goto exit;
129 : :
130 : 0 : *group_id = rsp->group_id;
131 : 0 : lf->group_id = rsp->group_id;
132 : 0 : exit:
133 : : mbox_put(mbox);
134 : 0 : return rc;
135 : : }
136 : :
137 : : int
138 : 0 : roc_dpi_access_pair_group_destroy(struct roc_dpi_lf *lf, int16_t group_id)
139 : : {
140 : 0 : struct mbox *mbox = mbox_get(lf->dev->mbox);
141 : : struct dpi_lf_access_group_free_req *req;
142 : : int rc;
143 : :
144 : 0 : req = mbox_alloc_msg_dpi_lf_access_group_free(mbox);
145 [ # # ]: 0 : if (req == NULL) {
146 : : rc = -ENOSPC;
147 : 0 : goto exit;
148 : : }
149 : :
150 : 0 : req->dpi_blkaddr = lf->blk_addr;
151 : 0 : req->group_id = group_id;
152 : 0 : rc = mbox_process(mbox);
153 : 0 : exit:
154 : : mbox_put(mbox);
155 : 0 : return rc;
156 : : }
157 : :
158 : : int
159 : 0 : roc_dpi_access_pair_group_join(struct roc_dpi_lf *lf, plt_uuid_t domain_id, plt_uuid_t token,
160 : : int16_t group_id)
161 : : {
162 : 0 : struct mbox *mbox = mbox_get(lf->dev->mbox);
163 : : struct dpi_lf_access_group_join_req *req;
164 : : int rc;
165 : :
166 : 0 : req = mbox_alloc_msg_dpi_lf_access_group_join(mbox);
167 [ # # ]: 0 : if (req == NULL) {
168 : : rc = -ENOSPC;
169 : 0 : goto exit;
170 : : }
171 : :
172 [ # # ]: 0 : mbox_memcpy(req->lf_handle, domain_id, sizeof(plt_uuid_t));
173 [ # # ]: 0 : mbox_memcpy(req->access_key, token, sizeof(plt_uuid_t));
174 : 0 : req->dpi_blkaddr = lf->blk_addr;
175 : 0 : req->group_id = group_id;
176 : :
177 : 0 : rc = mbox_process(mbox);
178 [ # # ]: 0 : if (rc)
179 : 0 : goto exit;
180 : :
181 : 0 : lf->group_id = group_id;
182 : 0 : exit:
183 : : mbox_put(mbox);
184 : 0 : return rc;
185 : : }
186 : :
187 : : int
188 : 0 : roc_dpi_access_pair_group_leave(struct roc_dpi_lf *lf, int16_t group_id)
189 : : {
190 : 0 : struct mbox *mbox = mbox_get(lf->dev->mbox);
191 : : struct dpi_lf_access_group_leave_req *req;
192 : : int rc;
193 : :
194 : 0 : req = mbox_alloc_msg_dpi_lf_access_group_leave(mbox);
195 [ # # ]: 0 : if (req == NULL) {
196 : : rc = -ENOSPC;
197 : 0 : goto exit;
198 : : }
199 : :
200 : 0 : req->dpi_blkaddr = lf->blk_addr;
201 : 0 : req->group_id = group_id;
202 : :
203 : 0 : rc = mbox_process(mbox);
204 : 0 : exit:
205 : : mbox_put(mbox);
206 : 0 : return rc;
207 : : }
208 : :
209 : : int
210 : 0 : roc_dpi_access_pair_group_handler_get(struct roc_dpi_lf *lf, int16_t group_id, plt_uuid_t domain_id,
211 : : uint16_t *handler)
212 : : {
213 : 0 : struct mbox *mbox = mbox_get(lf->dev->mbox);
214 : : struct dpi_lf_access_group_handle_get_req *req;
215 : : struct dpi_lf_access_group_handle_get_rsp *rsp;
216 : : int rc;
217 : :
218 : 0 : req = mbox_alloc_msg_dpi_lf_access_group_handle_get(mbox);
219 [ # # ]: 0 : if (req == NULL) {
220 : : rc = -ENOSPC;
221 : 0 : goto exit;
222 : : }
223 : :
224 [ # # ]: 0 : mbox_memcpy(req->lf_handle, domain_id, sizeof(plt_uuid_t));
225 : 0 : req->dpi_blkaddr = lf->blk_addr;
226 : 0 : req->group_id = group_id;
227 : :
228 : : rc = mbox_process_msg(mbox, (void **)&rsp);
229 [ # # ]: 0 : if (rc)
230 : 0 : goto exit;
231 : :
232 : 0 : *handler = rsp->handle;
233 : 0 : exit:
234 : : mbox_put(mbox);
235 : 0 : return rc;
236 : : }
237 : :
238 : : int
239 [ # # ]: 0 : roc_dpi_reset(struct roc_dpi *dpi)
240 : : {
241 : : uint16_t i;
242 : : int rc = 0;
243 : :
244 [ # # ]: 0 : if (roc_model_is_cn20k()) {
245 [ # # ]: 0 : for (i = 0; i < dpi->nr_lfs; i++) {
246 : 0 : rc |= dpi_lf_reset(&dpi->lfs[i]);
247 [ # # ]: 0 : if (rc)
248 : 0 : plt_err("Reset failed for DPI LF - %u", i);
249 : : }
250 : : }
251 : :
252 : 0 : return rc;
253 : : }
254 : :
255 : : int
256 [ # # ]: 0 : roc_dpi_enable(struct roc_dpi *roc_dpi)
257 : : {
258 : : uint16_t i;
259 : :
260 [ # # ]: 0 : if (roc_model_is_cn20k()) {
261 [ # # ]: 0 : for (i = 0; i < roc_dpi->nr_lfs; i++)
262 : 0 : dpi_lf_ena_dis(&roc_dpi->lfs[i], true);
263 : : } else {
264 : 0 : plt_write64(0x1, roc_dpi->rbase + DPI_VDMA_EN);
265 : : }
266 : :
267 : 0 : return 0;
268 : : }
269 : :
270 : : int
271 [ # # ]: 0 : roc_dpi_disable(struct roc_dpi *roc_dpi)
272 : : {
273 : : uint16_t i;
274 : :
275 [ # # ]: 0 : if (roc_model_is_cn20k()) {
276 [ # # ]: 0 : for (i = 0; i < roc_dpi->nr_lfs; i++)
277 : 0 : dpi_lf_ena_dis(&roc_dpi->lfs[i], false);
278 : : } else {
279 : 0 : plt_write64(0x0, roc_dpi->rbase + DPI_VDMA_EN);
280 : : }
281 : :
282 : 0 : return 0;
283 : : }
284 : :
285 : : int
286 : 0 : roc_dpi_configure(struct roc_dpi *roc_dpi, uint32_t chunk_sz, uint64_t aura, uint64_t chunk_base)
287 : : {
288 : : struct plt_pci_device *pci_dev;
289 : : dpi_mbox_msg_t mbox_msg;
290 : : int rc;
291 : :
292 [ # # ]: 0 : if (!roc_dpi) {
293 : 0 : plt_err("roc_dpi is NULL");
294 : 0 : return -EINVAL;
295 : : }
296 : :
297 : 0 : pci_dev = roc_dpi->pci_dev;
298 : :
299 : 0 : roc_dpi_disable(roc_dpi);
300 : 0 : rc = roc_dpi_wait_queue_idle(roc_dpi);
301 [ # # ]: 0 : if (rc)
302 : : return rc;
303 : :
304 : 0 : plt_write64(0x0, roc_dpi->rbase + DPI_VDMA_REQQ_CTL);
305 : : plt_write64(chunk_base, roc_dpi->rbase + DPI_VDMA_SADDR);
306 : 0 : mbox_msg.u[0] = 0;
307 : 0 : mbox_msg.u[1] = 0;
308 : : /* DPI PF driver expects vfid starts from index 0 */
309 : 0 : mbox_msg.s.vfid = roc_dpi->vfid;
310 : 0 : mbox_msg.s.pri = roc_dpi->priority;
311 : 0 : mbox_msg.s.cmd = DPI_QUEUE_OPEN;
312 : 0 : mbox_msg.s.csize = chunk_sz;
313 : 0 : mbox_msg.s.aura = aura;
314 : 0 : mbox_msg.s.sso_pf_func = idev_sso_pffunc_get();
315 : 0 : mbox_msg.s.npa_pf_func = idev_npa_pffunc_get();
316 : 0 : mbox_msg.s.wqecsoff = idev_dma_cs_offset_get();
317 [ # # ]: 0 : if (mbox_msg.s.wqecsoff)
318 : 0 : mbox_msg.s.wqecs = 1;
319 : :
320 : 0 : rc = send_msg_to_pf(&pci_dev->addr, (const char *)&mbox_msg, sizeof(dpi_mbox_msg_t));
321 [ # # ]: 0 : if (rc < 0)
322 : 0 : plt_err("Failed to send mbox message %d to DPI PF, err %d", mbox_msg.s.cmd, rc);
323 : :
324 : : return rc;
325 : : }
326 : :
327 : : int
328 : 0 : roc_dpi_configure_v2(struct roc_dpi *roc_dpi, uint32_t chunk_sz, uint64_t aura, uint64_t chunk_base)
329 : : {
330 : : struct plt_pci_device *pci_dev;
331 : : dpi_mbox_msg_t mbox_msg;
332 : : int rc;
333 : :
334 [ # # ]: 0 : if (!roc_dpi) {
335 : 0 : plt_err("roc_dpi is NULL");
336 : 0 : return -EINVAL;
337 : : }
338 : :
339 : 0 : pci_dev = roc_dpi->pci_dev;
340 : :
341 : 0 : roc_dpi_disable(roc_dpi);
342 : :
343 : 0 : rc = roc_dpi_wait_queue_idle(roc_dpi);
344 [ # # ]: 0 : if (rc)
345 : : return rc;
346 : :
347 : 0 : plt_write64(0x0, roc_dpi->rbase + DPI_VDMA_REQQ_CTL);
348 : : plt_write64(chunk_base, roc_dpi->rbase + DPI_VDMA_SADDR);
349 : 0 : mbox_msg.u[0] = 0;
350 : 0 : mbox_msg.u[1] = 0;
351 : : /* DPI PF driver expects vfid starts from index 0 */
352 : 0 : mbox_msg.s.vfid = roc_dpi->vfid;
353 : 0 : mbox_msg.s.pri = roc_dpi->priority;
354 : 0 : mbox_msg.s.cmd = DPI_QUEUE_OPEN_V2;
355 : 0 : mbox_msg.s.csize = chunk_sz / 8;
356 : 0 : mbox_msg.s.aura = aura;
357 : 0 : mbox_msg.s.sso_pf_func = idev_sso_pffunc_get();
358 : 0 : mbox_msg.s.npa_pf_func = idev_npa_pffunc_get();
359 : :
360 : 0 : rc = send_msg_to_pf(&pci_dev->addr, (const char *)&mbox_msg,
361 : : sizeof(dpi_mbox_msg_t));
362 [ # # ]: 0 : if (rc < 0)
363 : 0 : plt_err("Failed to send mbox message %d to DPI PF, err %d",
364 : : mbox_msg.s.cmd, rc);
365 : :
366 : : return rc;
367 : : }
368 : :
369 : : int
370 : 0 : dpi_lf_attach(struct dev *dev, uint8_t blk_addr, bool modify, uint16_t nb_lf)
371 : : {
372 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
373 : : struct dpi_rsrc_attach_req *req;
374 : : int rc;
375 : :
376 : 0 : req = mbox_alloc_msg_dpi_attach_resources(mbox);
377 [ # # ]: 0 : if (req == NULL) {
378 : : rc = -ENOSPC;
379 : 0 : goto exit;
380 : : }
381 : :
382 : 0 : req->dpi_lfs = nb_lf;
383 : 0 : req->dpilfs = 1;
384 : 0 : req->modify = modify;
385 : 0 : req->dpi_blkaddr = blk_addr;
386 : :
387 : 0 : rc = mbox_process(mbox);
388 : 0 : exit:
389 : : mbox_put(mbox);
390 : 0 : return rc;
391 : : }
392 : :
393 : : int
394 : 0 : dpi_lf_detach(struct dev *dev)
395 : : {
396 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
397 : : uint8_t blk_addr = RVU_BLOCK_ADDR_DPI0;
398 : : struct dpi_rsrc_detach *req;
399 : : int rc;
400 : :
401 : 0 : req = mbox_alloc_msg_dpi_detach_resources(mbox);
402 [ # # ]: 0 : if (req == NULL) {
403 : : rc = -ENOSPC;
404 : 0 : goto exit;
405 : : }
406 : :
407 : 0 : req->dpi_blkaddr = blk_addr;
408 : 0 : req->dpilfs = 1;
409 : 0 : req->partial = 1;
410 : :
411 : 0 : rc = mbox_process(mbox);
412 : 0 : exit:
413 : : mbox_put(mbox);
414 : 0 : return rc;
415 : : }
416 : :
417 : : int
418 : 0 : dpi_chan_tbl_alloc(struct dev *dev, uint8_t blk_addr, uint16_t tbl_sz)
419 : : {
420 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
421 : : struct dpi_lf_chan_tbl_alloc_req *req;
422 : : struct dpi_lf_chan_tbl_alloc_rsp *rsp;
423 : : int rc;
424 : :
425 : 0 : req = mbox_alloc_msg_dpi_lf_chan_tbl_alloc(mbox);
426 [ # # ]: 0 : if (req == NULL) {
427 : : rc = -ENOSPC;
428 : 0 : goto exit;
429 : : }
430 : :
431 : 0 : req->tbl_size = tbl_sz;
432 : 0 : req->dpi_blkaddr = blk_addr;
433 : :
434 : : rc = mbox_process_msg(mbox, (void **)&rsp);
435 [ # # ]: 0 : if (rc)
436 : 0 : goto exit;
437 : 0 : rc = rsp->tbl_num;
438 : 0 : exit:
439 : : mbox_put(mbox);
440 : 0 : return rc;
441 : : }
442 : :
443 : : int
444 : 0 : dpi_chan_tbl_free(struct dev *dev, uint8_t blk_addr, uint16_t tbl_num)
445 : : {
446 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
447 : : struct dpi_lf_chan_tbl_free_req *req;
448 : : int rc;
449 : :
450 : 0 : req = mbox_alloc_msg_dpi_lf_chan_tbl_free(mbox);
451 [ # # ]: 0 : if (req == NULL) {
452 : : rc = -ENOSPC;
453 : 0 : goto exit;
454 : : }
455 : :
456 : 0 : req->tbl_num = tbl_num;
457 : 0 : req->dpi_blkaddr = blk_addr;
458 : :
459 : 0 : rc = mbox_process(mbox);
460 : :
461 : 0 : exit:
462 : : mbox_put(mbox);
463 : 0 : return rc;
464 : : }
465 : :
466 : : int
467 : 0 : roc_dpi_lf_chan_tbl_select(struct roc_dpi_lf *lf)
468 : : {
469 : 0 : struct mbox *mbox = mbox_get(lf->dev->mbox);
470 : : struct dpi_lf_chan_tbl_select_req *req;
471 : : int rc;
472 : :
473 : 0 : req = mbox_alloc_msg_dpi_lf_chan_tbl_select(mbox);
474 [ # # ]: 0 : if (req == NULL) {
475 : : rc = -ENOSPC;
476 : 0 : goto exit;
477 : : }
478 : :
479 : 0 : req->lf_slot = lf->slot;
480 : 0 : req->chan_tbl = lf->chan_tbl;
481 : 0 : req->dpi_blkaddr = lf->blk_addr;
482 : 0 : req->ena = true;
483 : :
484 : 0 : rc = mbox_process(mbox);
485 : 0 : exit:
486 : : mbox_put(mbox);
487 : 0 : return rc;
488 : : }
489 : :
490 : : int
491 : 0 : roc_dpi_lf_chan_tbl_ena_dis(struct roc_dpi_lf *lf, bool ena)
492 : : {
493 : 0 : struct mbox *mbox = mbox_get(lf->dev->mbox);
494 : : struct dpi_lf_chan_tbl_ena_dis_req *req;
495 : : int rc;
496 : :
497 : 0 : req = mbox_alloc_msg_dpi_lf_chan_tbl_ena_dis(mbox);
498 [ # # ]: 0 : if (req == NULL) {
499 : : rc = -ENOSPC;
500 : 0 : goto exit;
501 : : }
502 : :
503 : 0 : req->lf_slot = lf->slot;
504 : 0 : req->dpi_blkaddr = lf->blk_addr;
505 : 0 : req->ena_dis = ena;
506 : :
507 : 0 : rc = mbox_process(mbox);
508 : :
509 : 0 : exit:
510 : : mbox_put(mbox);
511 : 0 : return rc;
512 : : }
513 : :
514 : : int
515 : 0 : dpi_chan_tbl_update(struct dev *dev, uint8_t blk_addr, uint16_t chan_tbl, uint64_t *tbl,
516 : : uint16_t off, uint16_t nb_entries)
517 : : {
518 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
519 : : struct dpi_lf_chan_tbl_update_req *req;
520 : : int rc;
521 : :
522 : 0 : req = mbox_alloc_msg_dpi_lf_chan_tbl_update(mbox);
523 [ # # ]: 0 : if (req == NULL) {
524 : : rc = -ENOSPC;
525 : 0 : goto exit;
526 : : }
527 : :
528 [ # # ]: 0 : mbox_memcpy(req->config, tbl, nb_entries * sizeof(uint64_t));
529 : :
530 : 0 : req->chan_tbl = chan_tbl;
531 : 0 : req->num_entries = nb_entries;
532 : 0 : req->idx_offset = off;
533 : 0 : req->dpi_blkaddr = blk_addr;
534 : :
535 : 0 : rc = mbox_process(mbox);
536 : 0 : exit:
537 : : mbox_put(mbox);
538 : 0 : return rc;
539 : : }
540 : :
541 : : int
542 : 0 : roc_dpi_lf_chan_tbl_update(struct roc_dpi_lf *lf, uint64_t *config, uint16_t offset,
543 : : uint16_t entries)
544 : : {
545 [ # # ]: 0 : if (entries > DPI_LF_CHAN_TBL_UPDATE_SIZE)
546 : : return -EINVAL;
547 : :
548 : 0 : return dpi_chan_tbl_update(lf->dev, lf->blk_addr, lf->chan_tbl, config, offset, entries);
549 : : }
550 : :
551 : : int
552 : 0 : dpi_chan_tbl_ena_dis(struct dev *dev, uint32_t blkaddr, uint16_t lfid, uint16_t chan_tbl,
553 : : bool enable)
554 : : {
555 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
556 : : struct dpi_lf_chan_tbl_select_req *req;
557 : : int rc;
558 : :
559 : 0 : req = mbox_alloc_msg_dpi_lf_chan_tbl_select(mbox);
560 [ # # ]: 0 : if (req == NULL) {
561 : : rc = -ENOSPC;
562 : 0 : goto exit;
563 : : }
564 : :
565 : 0 : req->chan_tbl = chan_tbl;
566 : 0 : req->lf_slot = lfid;
567 : 0 : req->ena = enable;
568 : 0 : req->dpi_blkaddr = blkaddr;
569 : :
570 : 0 : rc = mbox_process(mbox);
571 : 0 : exit:
572 : : mbox_put(mbox);
573 : 0 : return rc;
574 : : }
575 : :
576 : : int
577 : 0 : roc_dpi_lf_chan_tbl_alloc(struct roc_dpi_lf *lf, uint16_t tbl_sz)
578 : : {
579 : : int rc;
580 : :
581 : 0 : rc = dpi_chan_tbl_alloc(lf->dev, lf->blk_addr, tbl_sz);
582 [ # # ]: 0 : if (rc < 0)
583 : : return rc;
584 : :
585 : 0 : lf->chan_tbl_sz = tbl_sz;
586 : 0 : lf->chan_tbl = rc;
587 : 0 : return 0;
588 : : }
589 : :
590 : : int
591 : 0 : roc_dpi_lf_chan_tbl_free(struct roc_dpi_lf *lf)
592 : : {
593 : 0 : return dpi_chan_tbl_free(lf->dev, lf->blk_addr, lf->chan_tbl);
594 : : }
595 : :
596 : : int
597 : 0 : roc_dpi_lf_pffunc_cfg(struct roc_dpi_lf *lf)
598 : : {
599 : 0 : struct mbox *mbox = mbox_get(lf->dev->mbox);
600 : : struct dpi_lf_pf_func_cfg_req *req;
601 : : int rc = -ENOSPC;
602 : :
603 : 0 : req = mbox_alloc_msg_dpi_lf_pf_func_cfg(mbox);
604 [ # # ]: 0 : if (req == NULL) {
605 : : rc = -ENOSPC;
606 : 0 : goto exit;
607 : : }
608 : :
609 : 0 : req->dpi_blkaddr = lf->blk_addr;
610 : 0 : req->sso_pf_func = idev_sso_pffunc_get();
611 : 0 : req->npa_pf_func = idev_npa_pffunc_get();
612 : 0 : req->lf_slot = lf->slot;
613 : :
614 : 0 : rc = mbox_process(mbox);
615 : :
616 : 0 : exit:
617 : : mbox_put(mbox);
618 : 0 : return rc;
619 : : }
620 : :
621 : : static int
622 : 0 : dpi_lf_queue_configure(struct roc_dpi_lf_que *que, struct roc_dpi_lf_ring_cfg *rcfg)
623 : : {
624 : 0 : char nm[ROC_DPI_DEV_NAME_LEN] = {'\0'};
625 : 0 : struct roc_dpi_lf *lf = que->lf;
626 : : const struct plt_memzone *mz;
627 : : uint64_t reg;
628 : :
629 : 0 : snprintf(nm, sizeof(nm), "%s_%u_%u_%x", "dpi_lf_q", lf->slot, rcfg->ring_idx,
630 : 0 : lf->dev->pf_func);
631 : 0 : mz = plt_memzone_reserve_aligned(nm, que->qsize * que->cmd_len, 0, 128);
632 [ # # ]: 0 : if (!mz) {
633 : 0 : plt_err("Cannot alloc buffer for DPI LF ring command buffer: %s", nm);
634 : 0 : return -ENOMEM;
635 : : }
636 : :
637 : 0 : que->mz = mz;
638 : 0 : que->cmd_base = (uint64_t *)mz->addr;
639 : :
640 [ # # ]: 0 : reg = plt_read64(lf->rbase + DPI_LF_RINGX_CFG(rcfg->ring_idx));
641 : :
642 [ # # ]: 0 : if (rcfg->isize)
643 : 0 : reg |= DPI_LF_QCFG_ISIZE;
644 : : else
645 : 0 : reg &= ~DPI_LF_QCFG_ISIZE;
646 : :
647 : 0 : reg |= (((uint64_t)que->first_skip << 20) | ((uint64_t)que->later_skip << 28));
648 : 0 : reg |= BIT_ULL(7);
649 : :
650 : : plt_write64(reg, lf->rbase + DPI_LF_RINGX_CFG(rcfg->ring_idx));
651 : :
652 : 0 : reg = plt_read64(lf->rbase + DPI_LF_RINGX_BASE(rcfg->ring_idx));
653 : 0 : reg = (uint64_t)que->cmd_base;
654 : 0 : reg |= ((((que->mz->len >> 10) - 1) & DPI_LF_QSIZE_MASK) << DPI_LF_QSIZE_SHIFT);
655 : : plt_write64(reg, lf->rbase + DPI_LF_RINGX_BASE(rcfg->ring_idx));
656 : :
657 : 0 : return 0;
658 : : }
659 : :
660 : : int
661 : 0 : roc_dpi_lf_ring_init(struct roc_dpi_lf_que *que, struct roc_dpi_lf_ring_cfg *rcfg)
662 : : {
663 : 0 : struct roc_dpi_lf *lf = que->lf;
664 : 0 : struct mbox *mbox = mbox_get(lf->dev->mbox);
665 : : struct dpi_lf_ring_cfg_req *req;
666 : : int rc = -ENOSPC;
667 : :
668 : 0 : req = mbox_alloc_msg_dpi_lf_ring_cfg(mbox);
669 [ # # ]: 0 : if (req == NULL)
670 : 0 : goto fail;
671 : :
672 : 0 : req->dpi_blkaddr = lf->blk_addr;
673 : 0 : req->lf_slot = lf->slot;
674 : 0 : req->xtype = rcfg->xtype;
675 : 0 : req->rport = rcfg->rport;
676 : 0 : req->wport = rcfg->wport;
677 : 0 : req->ring_idx = rcfg->ring_idx;
678 : 0 : req->pri = rcfg->pri;
679 : :
680 : 0 : rc = mbox_process(mbox);
681 [ # # ]: 0 : if (rc)
682 : 0 : goto fail;
683 : :
684 : 0 : rc = dpi_lf_queue_configure(que, rcfg);
685 : :
686 : 0 : fail:
687 : : mbox_put(mbox);
688 : 0 : return rc;
689 : : }
690 : :
691 : : void
692 : 0 : roc_dpi_lf_ring_fini(struct roc_dpi_lf_que *que)
693 : : {
694 [ # # ]: 0 : if (que->mz) {
695 : 0 : plt_memzone_free(que->mz);
696 : 0 : que->mz = NULL;
697 : : }
698 : 0 : }
699 : :
700 : : int
701 : 0 : roc_dpi_lf_ring_chan_cfg(struct roc_dpi_lf_que *que, union roc_dpi_lf_ccfg *ccfg)
702 : : {
703 : 0 : struct roc_dpi_lf *lf = que->lf;
704 : 0 : struct mbox *mbox = mbox_get(lf->dev->mbox);
705 : : struct dpi_lf_chan_cfg_req *req;
706 : : int rc = -ENOSPC;
707 : :
708 : 0 : req = mbox_alloc_msg_dpi_lf_chan_cfg(mbox);
709 [ # # ]: 0 : if (req == NULL)
710 : 0 : goto fail;
711 : :
712 : 0 : req->dpi_blkaddr = lf->blk_addr;
713 : 0 : req->def_config = ccfg->u;
714 : 0 : req->lf_slot = lf->slot;
715 : 0 : req->ring_idx = que == lf->queue ? 0 : 1;
716 : :
717 : 0 : rc = mbox_process(mbox);
718 : :
719 : 0 : fail:
720 : : mbox_put(mbox);
721 : 0 : return rc;
722 : : }
723 : :
724 : : int
725 : 0 : dpi_lf_init(struct roc_dpi_lf *lf, struct dev *dev, uint8_t slot)
726 : : {
727 : : uint8_t blk_addr = RVU_BLOCK_ADDR_DPI0;
728 : :
729 : 0 : lf->dev = dev;
730 : 0 : lf->slot = slot;
731 : 0 : lf->rbase = dev->bar2 + (RVU_BLOCK_ADDR_DPI0 << 20 | slot << 12);
732 : 0 : lf->queue[0].lf = lf;
733 : 0 : lf->queue[1].lf = lf;
734 : 0 : lf->blk_addr = blk_addr;
735 : 0 : return 0;
736 : : }
737 : :
738 : : int
739 : 0 : roc_dpi_rsrc_init(struct roc_dpi *roc_dpi)
740 : : {
741 : 0 : struct plt_pci_device *pci_dev = roc_dpi->pci_dev;
742 : : struct dpi *dpi = roc_dpi_to_dpi_priv(roc_dpi);
743 : : uint8_t blk_addr = RVU_BLOCK_ADDR_DPI0;
744 : : char name[ROC_DPI_DEV_NAME_LEN];
745 : : const struct plt_memzone *mz;
746 : 0 : struct dev *dev = &dpi->dev;
747 : : uint16_t slot;
748 : : int rc;
749 : :
750 : 0 : mz = plt_memzone_reserve_cache_align(plt_pci_dev_name(name, ROC_DPI_DEV_NAME, pci_dev),
751 : : roc_dpi->nr_lfs * sizeof(struct roc_dpi_lf));
752 [ # # ]: 0 : if (!mz)
753 : : return -ENOMEM;
754 : :
755 : 0 : roc_dpi->mz = mz;
756 : 0 : roc_dpi->lfs = mz->addr;
757 : :
758 : 0 : rc = dpi_lf_attach(dev, blk_addr, true, roc_dpi->nr_lfs);
759 [ # # ]: 0 : if (rc) {
760 : 0 : plt_err("Could not attach LFs");
761 : 0 : plt_memzone_free(mz);
762 : 0 : roc_dpi->mz = NULL;
763 : 0 : roc_dpi->lfs = NULL;
764 : 0 : return rc;
765 : : }
766 : :
767 [ # # ]: 0 : for (slot = 0; slot < roc_dpi->nr_lfs; slot++)
768 : 0 : dpi_lf_init(&(roc_dpi->lfs[slot]), dev, slot);
769 : :
770 : : return rc;
771 : : }
772 : :
773 : : int
774 : 0 : roc_dpi_rsrc_fini(struct roc_dpi *roc_dpi)
775 : : {
776 : : struct dpi *dpi = roc_dpi_to_dpi_priv(roc_dpi);
777 : 0 : struct dev *dev = &dpi->dev;
778 : : struct roc_dpi_lf_que *que;
779 : : struct roc_dpi_lf *lf;
780 : : uint16_t slot, qid;
781 : : int rc;
782 : :
783 : 0 : roc_dpi_disable(roc_dpi);
784 : :
785 [ # # ]: 0 : for (slot = 0; slot < roc_dpi->nr_lfs; slot++) {
786 : 0 : lf = &roc_dpi->lfs[slot];
787 : :
788 [ # # ]: 0 : for (qid = 0; qid < ROC_DPI_LF_RINGS; qid++) {
789 : 0 : que = &lf->queue[qid];
790 [ # # ]: 0 : if (que->mz) {
791 : 0 : plt_memzone_free(que->mz);
792 : 0 : que->mz = NULL;
793 : : }
794 : : }
795 : : }
796 : :
797 : 0 : rc = dpi_lf_detach(dev);
798 : 0 : plt_memzone_free(roc_dpi->mz);
799 : 0 : roc_dpi->mz = NULL;
800 : 0 : roc_dpi->lfs = NULL;
801 : :
802 : 0 : return rc;
803 : : }
804 : :
805 : : int
806 : 0 : roc_dpi_dev_init(struct roc_dpi *roc_dpi, uint8_t offset)
807 : : {
808 : 0 : struct plt_pci_device *pci_dev = roc_dpi->pci_dev;
809 : : struct dpi *dpi = roc_dpi_to_dpi_priv(roc_dpi);
810 : 0 : struct dev *dev = &dpi->dev;
811 : : uint16_t vfid;
812 : : int rc = 0;
813 : :
814 [ # # ]: 0 : roc_dpi->rbase = pci_dev->mem_resource[0].addr;
815 : :
816 [ # # ]: 0 : if (roc_model_is_cn20k()) {
817 : 0 : rc = dev_init(dev, pci_dev);
818 [ # # ]: 0 : if (rc)
819 : 0 : plt_err("Failed to init dpi roc device");
820 : : } else {
821 : 0 : vfid = ((pci_dev->addr.devid & 0x1F) << 3) | (pci_dev->addr.function & 0x7);
822 : 0 : vfid -= 1;
823 : 0 : roc_dpi->vfid = vfid;
824 : 0 : idev_dma_cs_offset_set(offset);
825 : : }
826 : :
827 : 0 : return rc;
828 : : }
829 : :
830 : : int
831 : 0 : roc_dpi_dev_fini(struct roc_dpi *roc_dpi)
832 : : {
833 : 0 : struct plt_pci_device *pci_dev = roc_dpi->pci_dev;
834 : : struct dpi *dpi = roc_dpi_to_dpi_priv(roc_dpi);
835 [ # # ]: 0 : struct dev *dev = &dpi->dev;
836 : : dpi_mbox_msg_t mbox_msg;
837 : : int rc;
838 : :
839 [ # # ]: 0 : if (roc_model_is_cn20k()) {
840 : 0 : rc = dev_fini(dev, pci_dev);
841 : 0 : return rc;
842 : : }
843 : :
844 : 0 : rc = roc_dpi_wait_queue_idle(roc_dpi);
845 [ # # ]: 0 : if (rc)
846 : : return rc;
847 : :
848 : 0 : mbox_msg.u[0] = 0;
849 : 0 : mbox_msg.u[1] = 0;
850 : 0 : mbox_msg.s.vfid = roc_dpi->vfid;
851 : 0 : mbox_msg.s.cmd = DPI_QUEUE_CLOSE;
852 : :
853 : 0 : rc = send_msg_to_pf(&pci_dev->addr, (const char *)&mbox_msg, sizeof(dpi_mbox_msg_t));
854 [ # # ]: 0 : if (rc < 0)
855 : 0 : plt_err("Failed to send mbox message %d to DPI PF, err %d", mbox_msg.s.cmd, rc);
856 : :
857 : : return rc;
858 : : }
|