This source file includes following definitions.
- qbman_read_register
- qbman_write_register
- qbman_get_cmd
- qbman_set_swp_cfg
- qbman_swp_init
- qbman_swp_finish
- qbman_swp_interrupt_read_status
- qbman_swp_interrupt_clear_status
- qbman_swp_interrupt_get_trigger
- qbman_swp_interrupt_set_trigger
- qbman_swp_interrupt_get_inhibit
- qbman_swp_interrupt_set_inhibit
- qbman_swp_mc_start
- qbman_swp_mc_submit
- qbman_swp_mc_result
- qbman_eq_desc_clear
- qbman_eq_desc_set_no_orp
- qbman_eq_desc_set_fq
- qbman_eq_desc_set_qd
- qbman_write_eqcr_am_rt_register
- qbman_swp_enqueue
- qbman_swp_push_get
- qbman_swp_push_set
- qbman_pull_desc_clear
- qbman_pull_desc_set_storage
- qbman_pull_desc_set_numframes
- qbman_pull_desc_set_fq
- qbman_pull_desc_set_wq
- qbman_pull_desc_set_channel
- qbman_swp_pull
- qbman_swp_dqrr_next
- qbman_swp_dqrr_consume
- qbman_result_has_new_result
- qbman_release_desc_clear
- qbman_release_desc_set_bpid
- qbman_release_desc_set_rcdi
- qbman_swp_release
- qbman_swp_acquire
- qbman_swp_alt_fq_state
- qbman_swp_CDAN_set
- qbman_fq_query_state
- qbman_fq_state_frame_count
- qbman_fq_state_byte_count
- qbman_bp_query
- qbman_bp_info_num_free_bufs
1
2
3
4
5
6
7
8 #include <asm/cacheflush.h>
9 #include <linux/io.h>
10 #include <linux/slab.h>
11 #include <soc/fsl/dpaa2-global.h>
12
13 #include "qbman-portal.h"
14
15 #define QMAN_REV_4000 0x04000000
16 #define QMAN_REV_4100 0x04010000
17 #define QMAN_REV_4101 0x04010001
18 #define QMAN_REV_5000 0x05000000
19
20 #define QMAN_REV_MASK 0xffff0000
21
22
23 #define QB_VALID_BIT ((u32)0x80)
24
25
26 #define QBMAN_MC_ACQUIRE 0x30
27 #define QBMAN_WQCHAN_CONFIGURE 0x46
28
29
30 #define QBMAN_CINH_SWP_EQCR_PI 0x800
31 #define QBMAN_CINH_SWP_EQAR 0x8c0
32 #define QBMAN_CINH_SWP_CR_RT 0x900
33 #define QBMAN_CINH_SWP_VDQCR_RT 0x940
34 #define QBMAN_CINH_SWP_EQCR_AM_RT 0x980
35 #define QBMAN_CINH_SWP_RCR_AM_RT 0x9c0
36 #define QBMAN_CINH_SWP_DQPI 0xa00
37 #define QBMAN_CINH_SWP_DCAP 0xac0
38 #define QBMAN_CINH_SWP_SDQCR 0xb00
39 #define QBMAN_CINH_SWP_EQCR_AM_RT2 0xb40
40 #define QBMAN_CINH_SWP_RCR_PI 0xc00
41 #define QBMAN_CINH_SWP_RAR 0xcc0
42 #define QBMAN_CINH_SWP_ISR 0xe00
43 #define QBMAN_CINH_SWP_IER 0xe40
44 #define QBMAN_CINH_SWP_ISDR 0xe80
45 #define QBMAN_CINH_SWP_IIR 0xec0
46
47
48 #define QBMAN_CENA_SWP_EQCR(n) (0x000 + ((u32)(n) << 6))
49 #define QBMAN_CENA_SWP_DQRR(n) (0x200 + ((u32)(n) << 6))
50 #define QBMAN_CENA_SWP_RCR(n) (0x400 + ((u32)(n) << 6))
51 #define QBMAN_CENA_SWP_CR 0x600
52 #define QBMAN_CENA_SWP_RR(vb) (0x700 + ((u32)(vb) >> 1))
53 #define QBMAN_CENA_SWP_VDQCR 0x780
54
55
56 #define QBMAN_CENA_SWP_DQRR_MEM(n) (0x800 + ((u32)(n) << 6))
57 #define QBMAN_CENA_SWP_RCR_MEM(n) (0x1400 + ((u32)(n) << 6))
58 #define QBMAN_CENA_SWP_CR_MEM 0x1600
59 #define QBMAN_CENA_SWP_RR_MEM 0x1680
60 #define QBMAN_CENA_SWP_VDQCR_MEM 0x1780
61
62
63 #define QBMAN_IDX_FROM_DQRR(p) (((unsigned long)(p) & 0x1ff) >> 6)
64
65
66 #define QMAN_DQ_TOKEN_VALID 1
67
68
69 #define QB_SDQCR_FC_SHIFT 29
70 #define QB_SDQCR_FC_MASK 0x1
71 #define QB_SDQCR_DCT_SHIFT 24
72 #define QB_SDQCR_DCT_MASK 0x3
73 #define QB_SDQCR_TOK_SHIFT 16
74 #define QB_SDQCR_TOK_MASK 0xff
75 #define QB_SDQCR_SRC_SHIFT 0
76 #define QB_SDQCR_SRC_MASK 0xffff
77
78
79 #define QMAN_SDQCR_TOKEN 0xbb
80
81 enum qbman_sdqcr_dct {
82 qbman_sdqcr_dct_null = 0,
83 qbman_sdqcr_dct_prio_ics,
84 qbman_sdqcr_dct_active_ics,
85 qbman_sdqcr_dct_active
86 };
87
88 enum qbman_sdqcr_fc {
89 qbman_sdqcr_fc_one = 0,
90 qbman_sdqcr_fc_up_to_3 = 1
91 };
92
93
94
95 static inline u32 qbman_read_register(struct qbman_swp *p, u32 offset)
96 {
97 return readl_relaxed(p->addr_cinh + offset);
98 }
99
100 static inline void qbman_write_register(struct qbman_swp *p, u32 offset,
101 u32 value)
102 {
103 writel_relaxed(value, p->addr_cinh + offset);
104 }
105
106 static inline void *qbman_get_cmd(struct qbman_swp *p, u32 offset)
107 {
108 return p->addr_cena + offset;
109 }
110
111 #define QBMAN_CINH_SWP_CFG 0xd00
112
113 #define SWP_CFG_DQRR_MF_SHIFT 20
114 #define SWP_CFG_EST_SHIFT 16
115 #define SWP_CFG_CPBS_SHIFT 15
116 #define SWP_CFG_WN_SHIFT 14
117 #define SWP_CFG_RPM_SHIFT 12
118 #define SWP_CFG_DCM_SHIFT 10
119 #define SWP_CFG_EPM_SHIFT 8
120 #define SWP_CFG_VPM_SHIFT 7
121 #define SWP_CFG_CPM_SHIFT 6
122 #define SWP_CFG_SD_SHIFT 5
123 #define SWP_CFG_SP_SHIFT 4
124 #define SWP_CFG_SE_SHIFT 3
125 #define SWP_CFG_DP_SHIFT 2
126 #define SWP_CFG_DE_SHIFT 1
127 #define SWP_CFG_EP_SHIFT 0
128
129 static inline u32 qbman_set_swp_cfg(u8 max_fill, u8 wn, u8 est, u8 rpm, u8 dcm,
130 u8 epm, int sd, int sp, int se,
131 int dp, int de, int ep)
132 {
133 return (max_fill << SWP_CFG_DQRR_MF_SHIFT |
134 est << SWP_CFG_EST_SHIFT |
135 wn << SWP_CFG_WN_SHIFT |
136 rpm << SWP_CFG_RPM_SHIFT |
137 dcm << SWP_CFG_DCM_SHIFT |
138 epm << SWP_CFG_EPM_SHIFT |
139 sd << SWP_CFG_SD_SHIFT |
140 sp << SWP_CFG_SP_SHIFT |
141 se << SWP_CFG_SE_SHIFT |
142 dp << SWP_CFG_DP_SHIFT |
143 de << SWP_CFG_DE_SHIFT |
144 ep << SWP_CFG_EP_SHIFT);
145 }
146
147 #define QMAN_RT_MODE 0x00000100
148
149
150
151
152
153
154
155
156
157 struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d)
158 {
159 struct qbman_swp *p = kmalloc(sizeof(*p), GFP_KERNEL);
160 u32 reg;
161
162 if (!p)
163 return NULL;
164 p->desc = d;
165 p->mc.valid_bit = QB_VALID_BIT;
166 p->sdq = 0;
167 p->sdq |= qbman_sdqcr_dct_prio_ics << QB_SDQCR_DCT_SHIFT;
168 p->sdq |= qbman_sdqcr_fc_up_to_3 << QB_SDQCR_FC_SHIFT;
169 p->sdq |= QMAN_SDQCR_TOKEN << QB_SDQCR_TOK_SHIFT;
170 if ((p->desc->qman_version & QMAN_REV_MASK) >= QMAN_REV_5000)
171 p->mr.valid_bit = QB_VALID_BIT;
172
173 atomic_set(&p->vdq.available, 1);
174 p->vdq.valid_bit = QB_VALID_BIT;
175 p->dqrr.next_idx = 0;
176 p->dqrr.valid_bit = QB_VALID_BIT;
177
178 if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_4100) {
179 p->dqrr.dqrr_size = 4;
180 p->dqrr.reset_bug = 1;
181 } else {
182 p->dqrr.dqrr_size = 8;
183 p->dqrr.reset_bug = 0;
184 }
185
186 p->addr_cena = d->cena_bar;
187 p->addr_cinh = d->cinh_bar;
188
189 if ((p->desc->qman_version & QMAN_REV_MASK) >= QMAN_REV_5000)
190 memset(p->addr_cena, 0, 64 * 1024);
191
192 reg = qbman_set_swp_cfg(p->dqrr.dqrr_size,
193 1,
194 0,
195 3,
196 2,
197 3,
198 1,
199 1,
200 1,
201 1,
202 0,
203 0);
204 if ((p->desc->qman_version & QMAN_REV_MASK) >= QMAN_REV_5000)
205 reg |= 1 << SWP_CFG_CPBS_SHIFT |
206 1 << SWP_CFG_VPM_SHIFT |
207 1 << SWP_CFG_CPM_SHIFT;
208
209 qbman_write_register(p, QBMAN_CINH_SWP_CFG, reg);
210 reg = qbman_read_register(p, QBMAN_CINH_SWP_CFG);
211 if (!reg) {
212 pr_err("qbman: the portal is not enabled!\n");
213 kfree(p);
214 return NULL;
215 }
216
217 if ((p->desc->qman_version & QMAN_REV_MASK) >= QMAN_REV_5000) {
218 qbman_write_register(p, QBMAN_CINH_SWP_EQCR_PI, QMAN_RT_MODE);
219 qbman_write_register(p, QBMAN_CINH_SWP_RCR_PI, QMAN_RT_MODE);
220 }
221
222
223
224
225
226
227 qbman_write_register(p, QBMAN_CINH_SWP_SDQCR, 0);
228 return p;
229 }
230
231
232
233
234
235
236 void qbman_swp_finish(struct qbman_swp *p)
237 {
238 kfree(p);
239 }
240
241
242
243
244
245
246
247 u32 qbman_swp_interrupt_read_status(struct qbman_swp *p)
248 {
249 return qbman_read_register(p, QBMAN_CINH_SWP_ISR);
250 }
251
252
253
254
255
256
257 void qbman_swp_interrupt_clear_status(struct qbman_swp *p, u32 mask)
258 {
259 qbman_write_register(p, QBMAN_CINH_SWP_ISR, mask);
260 }
261
262
263
264
265
266
267
268 u32 qbman_swp_interrupt_get_trigger(struct qbman_swp *p)
269 {
270 return qbman_read_register(p, QBMAN_CINH_SWP_IER);
271 }
272
273
274
275
276
277
278 void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, u32 mask)
279 {
280 qbman_write_register(p, QBMAN_CINH_SWP_IER, mask);
281 }
282
283
284
285
286
287
288
289 int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p)
290 {
291 return qbman_read_register(p, QBMAN_CINH_SWP_IIR);
292 }
293
294
295
296
297
298
299 void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit)
300 {
301 qbman_write_register(p, QBMAN_CINH_SWP_IIR, inhibit ? 0xffffffff : 0);
302 }
303
304
305
306
307
308
309
310
311
312
313 void *qbman_swp_mc_start(struct qbman_swp *p)
314 {
315 if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000)
316 return qbman_get_cmd(p, QBMAN_CENA_SWP_CR);
317 else
318 return qbman_get_cmd(p, QBMAN_CENA_SWP_CR_MEM);
319 }
320
321
322
323
324
325 void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, u8 cmd_verb)
326 {
327 u8 *v = cmd;
328
329 if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
330 dma_wmb();
331 *v = cmd_verb | p->mc.valid_bit;
332 } else {
333 *v = cmd_verb | p->mc.valid_bit;
334 dma_wmb();
335 qbman_write_register(p, QBMAN_CINH_SWP_CR_RT, QMAN_RT_MODE);
336 }
337 }
338
339
340
341
342
343 void *qbman_swp_mc_result(struct qbman_swp *p)
344 {
345 u32 *ret, verb;
346
347 if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
348 ret = qbman_get_cmd(p, QBMAN_CENA_SWP_RR(p->mc.valid_bit));
349
350
351
352 verb = ret[0] & ~QB_VALID_BIT;
353 if (!verb)
354 return NULL;
355 p->mc.valid_bit ^= QB_VALID_BIT;
356 } else {
357 ret = qbman_get_cmd(p, QBMAN_CENA_SWP_RR_MEM);
358
359 if (p->mr.valid_bit != (ret[0] & QB_VALID_BIT))
360 return NULL;
361
362 verb = ret[0] & ~QB_VALID_BIT;
363 if (!verb)
364 return NULL;
365 p->mr.valid_bit ^= QB_VALID_BIT;
366 }
367
368 return ret;
369 }
370
371 #define QB_ENQUEUE_CMD_OPTIONS_SHIFT 0
372 enum qb_enqueue_commands {
373 enqueue_empty = 0,
374 enqueue_response_always = 1,
375 enqueue_rejects_to_fq = 2
376 };
377
378 #define QB_ENQUEUE_CMD_ORP_ENABLE_SHIFT 2
379 #define QB_ENQUEUE_CMD_IRQ_ON_DISPATCH_SHIFT 3
380 #define QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT 4
381
382
383
384
385
386 void qbman_eq_desc_clear(struct qbman_eq_desc *d)
387 {
388 memset(d, 0, sizeof(*d));
389 }
390
391
392
393
394
395
396
397 void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success)
398 {
399 d->verb &= ~(1 << QB_ENQUEUE_CMD_ORP_ENABLE_SHIFT);
400 if (respond_success)
401 d->verb |= enqueue_response_always;
402 else
403 d->verb |= enqueue_rejects_to_fq;
404 }
405
406
407
408
409
410
411
412
413
414
415
416
417
418 void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, u32 fqid)
419 {
420 d->verb &= ~(1 << QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT);
421 d->tgtid = cpu_to_le32(fqid);
422 }
423
424
425
426
427
428
429
430
431 void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, u32 qdid,
432 u32 qd_bin, u32 qd_prio)
433 {
434 d->verb |= 1 << QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT;
435 d->tgtid = cpu_to_le32(qdid);
436 d->qdbin = cpu_to_le16(qd_bin);
437 d->qpri = qd_prio;
438 }
439
440 #define EQAR_IDX(eqar) ((eqar) & 0x7)
441 #define EQAR_VB(eqar) ((eqar) & 0x80)
442 #define EQAR_SUCCESS(eqar) ((eqar) & 0x100)
443
444 static inline void qbman_write_eqcr_am_rt_register(struct qbman_swp *p,
445 u8 idx)
446 {
447 if (idx < 16)
448 qbman_write_register(p, QBMAN_CINH_SWP_EQCR_AM_RT + idx * 4,
449 QMAN_RT_MODE);
450 else
451 qbman_write_register(p, QBMAN_CINH_SWP_EQCR_AM_RT2 +
452 (idx - 16) * 4,
453 QMAN_RT_MODE);
454 }
455
456
457
458
459
460
461
462
463
464
465
466
467 int qbman_swp_enqueue(struct qbman_swp *s, const struct qbman_eq_desc *d,
468 const struct dpaa2_fd *fd)
469 {
470 struct qbman_eq_desc *p;
471 u32 eqar = qbman_read_register(s, QBMAN_CINH_SWP_EQAR);
472
473 if (!EQAR_SUCCESS(eqar))
474 return -EBUSY;
475
476 p = qbman_get_cmd(s, QBMAN_CENA_SWP_EQCR(EQAR_IDX(eqar)));
477 memcpy(&p->dca, &d->dca, 31);
478 memcpy(&p->fd, fd, sizeof(*fd));
479
480 if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
481
482 dma_wmb();
483 p->verb = d->verb | EQAR_VB(eqar);
484 } else {
485 p->verb = d->verb | EQAR_VB(eqar);
486 dma_wmb();
487 qbman_write_eqcr_am_rt_register(s, EQAR_IDX(eqar));
488 }
489
490 return 0;
491 }
492
493
494
495
496
497
498
499
500
501
502 void qbman_swp_push_get(struct qbman_swp *s, u8 channel_idx, int *enabled)
503 {
504 u16 src = (s->sdq >> QB_SDQCR_SRC_SHIFT) & QB_SDQCR_SRC_MASK;
505
506 WARN_ON(channel_idx > 15);
507 *enabled = src | (1 << channel_idx);
508 }
509
510
511
512
513
514
515
516 void qbman_swp_push_set(struct qbman_swp *s, u8 channel_idx, int enable)
517 {
518 u16 dqsrc;
519
520 WARN_ON(channel_idx > 15);
521 if (enable)
522 s->sdq |= 1 << channel_idx;
523 else
524 s->sdq &= ~(1 << channel_idx);
525
526
527
528
529 dqsrc = (s->sdq >> QB_SDQCR_SRC_SHIFT) & QB_SDQCR_SRC_MASK;
530 if (dqsrc != 0)
531 qbman_write_register(s, QBMAN_CINH_SWP_SDQCR, s->sdq);
532 else
533 qbman_write_register(s, QBMAN_CINH_SWP_SDQCR, 0);
534 }
535
536 #define QB_VDQCR_VERB_DCT_SHIFT 0
537 #define QB_VDQCR_VERB_DT_SHIFT 2
538 #define QB_VDQCR_VERB_RLS_SHIFT 4
539 #define QB_VDQCR_VERB_WAE_SHIFT 5
540
541 enum qb_pull_dt_e {
542 qb_pull_dt_channel,
543 qb_pull_dt_workqueue,
544 qb_pull_dt_framequeue
545 };
546
547
548
549
550
551
552 void qbman_pull_desc_clear(struct qbman_pull_desc *d)
553 {
554 memset(d, 0, sizeof(*d));
555 }
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570 void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
571 struct dpaa2_dq *storage,
572 dma_addr_t storage_phys,
573 int stash)
574 {
575
576 d->rsp_addr_virt = (u64)(uintptr_t)storage;
577
578 if (!storage) {
579 d->verb &= ~(1 << QB_VDQCR_VERB_RLS_SHIFT);
580 return;
581 }
582 d->verb |= 1 << QB_VDQCR_VERB_RLS_SHIFT;
583 if (stash)
584 d->verb |= 1 << QB_VDQCR_VERB_WAE_SHIFT;
585 else
586 d->verb &= ~(1 << QB_VDQCR_VERB_WAE_SHIFT);
587
588 d->rsp_addr = cpu_to_le64(storage_phys);
589 }
590
591
592
593
594
595
596 void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d, u8 numframes)
597 {
598 d->numf = numframes - 1;
599 }
600
601
602
603
604
605
606
607
608
609
610
611
612
613 void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, u32 fqid)
614 {
615 d->verb |= 1 << QB_VDQCR_VERB_DCT_SHIFT;
616 d->verb |= qb_pull_dt_framequeue << QB_VDQCR_VERB_DT_SHIFT;
617 d->dq_src = cpu_to_le32(fqid);
618 }
619
620
621
622
623
624
625 void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, u32 wqid,
626 enum qbman_pull_type_e dct)
627 {
628 d->verb |= dct << QB_VDQCR_VERB_DCT_SHIFT;
629 d->verb |= qb_pull_dt_workqueue << QB_VDQCR_VERB_DT_SHIFT;
630 d->dq_src = cpu_to_le32(wqid);
631 }
632
633
634
635
636
637
638
639 void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, u32 chid,
640 enum qbman_pull_type_e dct)
641 {
642 d->verb |= dct << QB_VDQCR_VERB_DCT_SHIFT;
643 d->verb |= qb_pull_dt_channel << QB_VDQCR_VERB_DT_SHIFT;
644 d->dq_src = cpu_to_le32(chid);
645 }
646
647
648
649
650
651
652
653
654
655
656 int qbman_swp_pull(struct qbman_swp *s, struct qbman_pull_desc *d)
657 {
658 struct qbman_pull_desc *p;
659
660 if (!atomic_dec_and_test(&s->vdq.available)) {
661 atomic_inc(&s->vdq.available);
662 return -EBUSY;
663 }
664 s->vdq.storage = (void *)(uintptr_t)d->rsp_addr_virt;
665 if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000)
666 p = qbman_get_cmd(s, QBMAN_CENA_SWP_VDQCR);
667 else
668 p = qbman_get_cmd(s, QBMAN_CENA_SWP_VDQCR_MEM);
669 p->numf = d->numf;
670 p->tok = QMAN_DQ_TOKEN_VALID;
671 p->dq_src = d->dq_src;
672 p->rsp_addr = d->rsp_addr;
673 p->rsp_addr_virt = d->rsp_addr_virt;
674
675 if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
676 dma_wmb();
677
678 p->verb = d->verb | s->vdq.valid_bit;
679 s->vdq.valid_bit ^= QB_VALID_BIT;
680 } else {
681 p->verb = d->verb | s->vdq.valid_bit;
682 s->vdq.valid_bit ^= QB_VALID_BIT;
683 dma_wmb();
684 qbman_write_register(s, QBMAN_CINH_SWP_VDQCR_RT, QMAN_RT_MODE);
685 }
686
687 return 0;
688 }
689
690 #define QMAN_DQRR_PI_MASK 0xf
691
692
693
694
695
696
697
698
699
700 const struct dpaa2_dq *qbman_swp_dqrr_next(struct qbman_swp *s)
701 {
702 u32 verb;
703 u32 response_verb;
704 u32 flags;
705 struct dpaa2_dq *p;
706
707
708
709
710 if (unlikely(s->dqrr.reset_bug)) {
711
712
713
714
715
716
717
718
719 u8 pi = qbman_read_register(s, QBMAN_CINH_SWP_DQPI) &
720 QMAN_DQRR_PI_MASK;
721
722
723 if (pi == s->dqrr.next_idx)
724 return NULL;
725
726
727
728
729
730
731
732
733
734 if (s->dqrr.next_idx == (s->dqrr.dqrr_size - 1)) {
735 pr_debug("next_idx=%d, pi=%d, clear reset bug\n",
736 s->dqrr.next_idx, pi);
737 s->dqrr.reset_bug = 0;
738 }
739 prefetch(qbman_get_cmd(s,
740 QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx)));
741 }
742
743 if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000)
744 p = qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
745 else
746 p = qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR_MEM(s->dqrr.next_idx));
747 verb = p->dq.verb;
748
749
750
751
752
753
754
755
756
757 if ((verb & QB_VALID_BIT) != s->dqrr.valid_bit) {
758 prefetch(qbman_get_cmd(s,
759 QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx)));
760 return NULL;
761 }
762
763
764
765
766 s->dqrr.next_idx++;
767 s->dqrr.next_idx &= s->dqrr.dqrr_size - 1;
768 if (!s->dqrr.next_idx)
769 s->dqrr.valid_bit ^= QB_VALID_BIT;
770
771
772
773
774
775 flags = p->dq.stat;
776 response_verb = verb & QBMAN_RESULT_MASK;
777 if ((response_verb == QBMAN_RESULT_DQ) &&
778 (flags & DPAA2_DQ_STAT_VOLATILE) &&
779 (flags & DPAA2_DQ_STAT_EXPIRED))
780 atomic_inc(&s->vdq.available);
781
782 prefetch(qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx)));
783
784 return p;
785 }
786
787
788
789
790
791
792
793 void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct dpaa2_dq *dq)
794 {
795 qbman_write_register(s, QBMAN_CINH_SWP_DCAP, QBMAN_IDX_FROM_DQRR(dq));
796 }
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815 int qbman_result_has_new_result(struct qbman_swp *s, const struct dpaa2_dq *dq)
816 {
817 if (dq->dq.tok != QMAN_DQ_TOKEN_VALID)
818 return 0;
819
820
821
822
823
824
825 ((struct dpaa2_dq *)dq)->dq.tok = 0;
826
827
828
829
830
831
832 if (s->vdq.storage == dq) {
833 s->vdq.storage = NULL;
834 atomic_inc(&s->vdq.available);
835 }
836
837 return 1;
838 }
839
840
841
842
843
844 void qbman_release_desc_clear(struct qbman_release_desc *d)
845 {
846 memset(d, 0, sizeof(*d));
847 d->verb = 1 << 5;
848 }
849
850
851
852
853 void qbman_release_desc_set_bpid(struct qbman_release_desc *d, u16 bpid)
854 {
855 d->bpid = cpu_to_le16(bpid);
856 }
857
858
859
860
861
862 void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable)
863 {
864 if (enable)
865 d->verb |= 1 << 6;
866 else
867 d->verb &= ~(1 << 6);
868 }
869
870 #define RAR_IDX(rar) ((rar) & 0x7)
871 #define RAR_VB(rar) ((rar) & 0x80)
872 #define RAR_SUCCESS(rar) ((rar) & 0x100)
873
874
875
876
877
878
879
880
881
882
883 int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
884 const u64 *buffers, unsigned int num_buffers)
885 {
886 int i;
887 struct qbman_release_desc *p;
888 u32 rar;
889
890 if (!num_buffers || (num_buffers > 7))
891 return -EINVAL;
892
893 rar = qbman_read_register(s, QBMAN_CINH_SWP_RAR);
894 if (!RAR_SUCCESS(rar))
895 return -EBUSY;
896
897
898 if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000)
899 p = qbman_get_cmd(s, QBMAN_CENA_SWP_RCR(RAR_IDX(rar)));
900 else
901 p = qbman_get_cmd(s, QBMAN_CENA_SWP_RCR_MEM(RAR_IDX(rar)));
902
903 for (i = 0; i < num_buffers; i++)
904 p->buf[i] = cpu_to_le64(buffers[i]);
905 p->bpid = d->bpid;
906
907 if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
908
909
910
911
912 dma_wmb();
913 p->verb = d->verb | RAR_VB(rar) | num_buffers;
914 } else {
915 p->verb = d->verb | RAR_VB(rar) | num_buffers;
916 dma_wmb();
917 qbman_write_register(s, QBMAN_CINH_SWP_RCR_AM_RT +
918 RAR_IDX(rar) * 4, QMAN_RT_MODE);
919 }
920
921 return 0;
922 }
923
924 struct qbman_acquire_desc {
925 u8 verb;
926 u8 reserved;
927 __le16 bpid;
928 u8 num;
929 u8 reserved2[59];
930 };
931
932 struct qbman_acquire_rslt {
933 u8 verb;
934 u8 rslt;
935 __le16 reserved;
936 u8 num;
937 u8 reserved2[3];
938 __le64 buf[7];
939 };
940
941
942
943
944
945
946
947
948
949
950
951 int qbman_swp_acquire(struct qbman_swp *s, u16 bpid, u64 *buffers,
952 unsigned int num_buffers)
953 {
954 struct qbman_acquire_desc *p;
955 struct qbman_acquire_rslt *r;
956 int i;
957
958 if (!num_buffers || (num_buffers > 7))
959 return -EINVAL;
960
961
962 p = qbman_swp_mc_start(s);
963
964 if (!p)
965 return -EBUSY;
966
967
968 p->bpid = cpu_to_le16(bpid);
969 p->num = num_buffers;
970
971
972 r = qbman_swp_mc_complete(s, p, QBMAN_MC_ACQUIRE);
973 if (unlikely(!r)) {
974 pr_err("qbman: acquire from BPID %d failed, no response\n",
975 bpid);
976 return -EIO;
977 }
978
979
980 WARN_ON((r->verb & 0x7f) != QBMAN_MC_ACQUIRE);
981
982
983 if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
984 pr_err("qbman: acquire from BPID 0x%x failed, code=0x%02x\n",
985 bpid, r->rslt);
986 return -EIO;
987 }
988
989 WARN_ON(r->num > num_buffers);
990
991
992 for (i = 0; i < r->num; i++)
993 buffers[i] = le64_to_cpu(r->buf[i]);
994
995 return (int)r->num;
996 }
997
998 struct qbman_alt_fq_state_desc {
999 u8 verb;
1000 u8 reserved[3];
1001 __le32 fqid;
1002 u8 reserved2[56];
1003 };
1004
1005 struct qbman_alt_fq_state_rslt {
1006 u8 verb;
1007 u8 rslt;
1008 u8 reserved[62];
1009 };
1010
1011 #define ALT_FQ_FQID_MASK 0x00FFFFFF
1012
1013 int qbman_swp_alt_fq_state(struct qbman_swp *s, u32 fqid,
1014 u8 alt_fq_verb)
1015 {
1016 struct qbman_alt_fq_state_desc *p;
1017 struct qbman_alt_fq_state_rslt *r;
1018
1019
1020 p = qbman_swp_mc_start(s);
1021 if (!p)
1022 return -EBUSY;
1023
1024 p->fqid = cpu_to_le32(fqid & ALT_FQ_FQID_MASK);
1025
1026
1027 r = qbman_swp_mc_complete(s, p, alt_fq_verb);
1028 if (unlikely(!r)) {
1029 pr_err("qbman: mgmt cmd failed, no response (verb=0x%x)\n",
1030 alt_fq_verb);
1031 return -EIO;
1032 }
1033
1034
1035 WARN_ON((r->verb & QBMAN_RESULT_MASK) != alt_fq_verb);
1036
1037
1038 if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
1039 pr_err("qbman: ALT FQID %d failed: verb = 0x%08x code = 0x%02x\n",
1040 fqid, r->verb, r->rslt);
1041 return -EIO;
1042 }
1043
1044 return 0;
1045 }
1046
1047 struct qbman_cdan_ctrl_desc {
1048 u8 verb;
1049 u8 reserved;
1050 __le16 ch;
1051 u8 we;
1052 u8 ctrl;
1053 __le16 reserved2;
1054 __le64 cdan_ctx;
1055 u8 reserved3[48];
1056
1057 };
1058
1059 struct qbman_cdan_ctrl_rslt {
1060 u8 verb;
1061 u8 rslt;
1062 __le16 ch;
1063 u8 reserved[60];
1064 };
1065
1066 int qbman_swp_CDAN_set(struct qbman_swp *s, u16 channelid,
1067 u8 we_mask, u8 cdan_en,
1068 u64 ctx)
1069 {
1070 struct qbman_cdan_ctrl_desc *p = NULL;
1071 struct qbman_cdan_ctrl_rslt *r = NULL;
1072
1073
1074 p = qbman_swp_mc_start(s);
1075 if (!p)
1076 return -EBUSY;
1077
1078
1079 p->ch = cpu_to_le16(channelid);
1080 p->we = we_mask;
1081 if (cdan_en)
1082 p->ctrl = 1;
1083 else
1084 p->ctrl = 0;
1085 p->cdan_ctx = cpu_to_le64(ctx);
1086
1087
1088 r = qbman_swp_mc_complete(s, p, QBMAN_WQCHAN_CONFIGURE);
1089 if (unlikely(!r)) {
1090 pr_err("qbman: wqchan config failed, no response\n");
1091 return -EIO;
1092 }
1093
1094 WARN_ON((r->verb & 0x7f) != QBMAN_WQCHAN_CONFIGURE);
1095
1096
1097 if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
1098 pr_err("qbman: CDAN cQID %d failed: code = 0x%02x\n",
1099 channelid, r->rslt);
1100 return -EIO;
1101 }
1102
1103 return 0;
1104 }
1105
1106 #define QBMAN_RESPONSE_VERB_MASK 0x7f
1107 #define QBMAN_FQ_QUERY_NP 0x45
1108 #define QBMAN_BP_QUERY 0x32
1109
1110 struct qbman_fq_query_desc {
1111 u8 verb;
1112 u8 reserved[3];
1113 __le32 fqid;
1114 u8 reserved2[56];
1115 };
1116
1117 int qbman_fq_query_state(struct qbman_swp *s, u32 fqid,
1118 struct qbman_fq_query_np_rslt *r)
1119 {
1120 struct qbman_fq_query_desc *p;
1121 void *resp;
1122
1123 p = (struct qbman_fq_query_desc *)qbman_swp_mc_start(s);
1124 if (!p)
1125 return -EBUSY;
1126
1127
1128 p->fqid = cpu_to_le32(fqid & 0x00FFFFFF);
1129 resp = qbman_swp_mc_complete(s, p, QBMAN_FQ_QUERY_NP);
1130 if (!resp) {
1131 pr_err("qbman: Query FQID %d NP fields failed, no response\n",
1132 fqid);
1133 return -EIO;
1134 }
1135 *r = *(struct qbman_fq_query_np_rslt *)resp;
1136
1137 WARN_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_FQ_QUERY_NP);
1138
1139
1140 if (r->rslt != QBMAN_MC_RSLT_OK) {
1141 pr_err("Query NP fields of FQID 0x%x failed, code=0x%02x\n",
1142 p->fqid, r->rslt);
1143 return -EIO;
1144 }
1145
1146 return 0;
1147 }
1148
1149 u32 qbman_fq_state_frame_count(const struct qbman_fq_query_np_rslt *r)
1150 {
1151 return (le32_to_cpu(r->frm_cnt) & 0x00FFFFFF);
1152 }
1153
1154 u32 qbman_fq_state_byte_count(const struct qbman_fq_query_np_rslt *r)
1155 {
1156 return le32_to_cpu(r->byte_cnt);
1157 }
1158
1159 struct qbman_bp_query_desc {
1160 u8 verb;
1161 u8 reserved;
1162 __le16 bpid;
1163 u8 reserved2[60];
1164 };
1165
1166 int qbman_bp_query(struct qbman_swp *s, u16 bpid,
1167 struct qbman_bp_query_rslt *r)
1168 {
1169 struct qbman_bp_query_desc *p;
1170 void *resp;
1171
1172 p = (struct qbman_bp_query_desc *)qbman_swp_mc_start(s);
1173 if (!p)
1174 return -EBUSY;
1175
1176 p->bpid = cpu_to_le16(bpid);
1177 resp = qbman_swp_mc_complete(s, p, QBMAN_BP_QUERY);
1178 if (!resp) {
1179 pr_err("qbman: Query BPID %d fields failed, no response\n",
1180 bpid);
1181 return -EIO;
1182 }
1183 *r = *(struct qbman_bp_query_rslt *)resp;
1184
1185 WARN_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_BP_QUERY);
1186
1187
1188 if (r->rslt != QBMAN_MC_RSLT_OK) {
1189 pr_err("Query fields of BPID 0x%x failed, code=0x%02x\n",
1190 bpid, r->rslt);
1191 return -EIO;
1192 }
1193
1194 return 0;
1195 }
1196
1197 u32 qbman_bp_info_num_free_bufs(struct qbman_bp_query_rslt *a)
1198 {
1199 return le32_to_cpu(a->fill);
1200 }