1
2
3
4
5
6
7
8#ifndef __TI_CPPI5_H__
9#define __TI_CPPI5_H__
10
11#include <hexdump.h>
12#include <linux/bitops.h>
13#include <linux/bug.h>
14
15
16
17
18struct cppi5_desc_hdr_t {
19 u32 pkt_info0;
20 u32 pkt_info1;
21 u32 pkt_info2;
22 u32 src_dst_tag;
23} __packed;
24
25
26
27
28struct cppi5_host_desc_t {
29 struct cppi5_desc_hdr_t hdr;
30 u64 next_desc;
31 u64 buf_ptr;
32 u32 buf_info1;
33 u32 org_buf_len;
34 u64 org_buf_ptr;
35 u32 epib[0];
36
37
38
39
40} __packed;
41
42#define CPPI5_DESC_MIN_ALIGN (16U)
43
44#define CPPI5_INFO0_HDESC_EPIB_SIZE (16U)
45#define CPPI5_INFO0_HDESC_PSDATA_MAX_SIZE (128U)
46
47#define CPPI5_INFO0_HDESC_TYPE_SHIFT (30U)
48#define CPPI5_INFO0_HDESC_TYPE_MASK GENMASK(31, 30)
49#define CPPI5_INFO0_DESC_TYPE_VAL_HOST (1U)
50#define CPPI5_INFO0_DESC_TYPE_VAL_MONO (2U)
51#define CPPI5_INFO0_DESC_TYPE_VAL_TR (3U)
52#define CPPI5_INFO0_HDESC_EPIB_PRESENT BIT(29)
53
54
55
56
57
58#define CPPI5_INFO0_HDESC_PSINFO_LOCATION BIT(28)
59#define CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT (22U)
60#define CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK GENMASK(27, 22)
61#define CPPI5_INFO0_HDESC_PKTLEN_SHIFT (0)
62#define CPPI5_INFO0_HDESC_PKTLEN_MASK GENMASK(21, 0)
63
64#define CPPI5_INFO1_DESC_PKTERROR_SHIFT (28U)
65#define CPPI5_INFO1_DESC_PKTERROR_MASK GENMASK(31, 28)
66#define CPPI5_INFO1_HDESC_PSFLGS_SHIFT (24U)
67#define CPPI5_INFO1_HDESC_PSFLGS_MASK GENMASK(27, 24)
68#define CPPI5_INFO1_DESC_PKTID_SHIFT (14U)
69#define CPPI5_INFO1_DESC_PKTID_MASK GENMASK(23, 14)
70#define CPPI5_INFO1_DESC_FLOWID_SHIFT (0)
71#define CPPI5_INFO1_DESC_FLOWID_MASK GENMASK(13, 0)
72
73#define CPPI5_INFO2_HDESC_PKTTYPE_SHIFT (27U)
74#define CPPI5_INFO2_HDESC_PKTTYPE_MASK GENMASK(31, 27)
75
76#define CPPI5_INFO2_HDESC_RETPOLICY BIT(18)
77
78
79
80
81
82
83#define CPPI5_INFO2_HDESC_EARLYRET BIT(17)
84
85
86
87
88
89#define CPPI5_INFO2_DESC_RETPUSHPOLICY BIT(16)
90#define CPPI5_INFO2_DESC_RETQ_SHIFT (0)
91#define CPPI5_INFO2_DESC_RETQ_MASK GENMASK(15, 0)
92
93#define CPPI5_INFO3_DESC_SRCTAG_SHIFT (16U)
94#define CPPI5_INFO3_DESC_SRCTAG_MASK GENMASK(31, 16)
95#define CPPI5_INFO3_DESC_DSTTAG_SHIFT (0)
96#define CPPI5_INFO3_DESC_DSTTAG_MASK GENMASK(15, 0)
97
98#define CPPI5_BUFINFO1_HDESC_DATA_LEN_SHIFT (0)
99#define CPPI5_BUFINFO1_HDESC_DATA_LEN_MASK GENMASK(27, 0)
100
101#define CPPI5_OBUFINFO0_HDESC_BUF_LEN_SHIFT (0)
102#define CPPI5_OBUFINFO0_HDESC_BUF_LEN_MASK GENMASK(27, 0)
103
104
105
106
107struct cppi5_desc_epib_t {
108 u32 timestamp;
109 u32 sw_info0;
110 u32 sw_info1;
111 u32 sw_info2;
112};
113
114
115
116
117struct cppi5_monolithic_desc_t {
118 struct cppi5_desc_hdr_t hdr;
119 u32 epib[0];
120
121
122
123
124};
125
126#define CPPI5_INFO2_MDESC_DATA_OFFSET_SHIFT (18U)
127#define CPPI5_INFO2_MDESC_DATA_OFFSET_MASK GENMASK(26, 18)
128
129
130
131
132
133
134#define CPPI5_INFO0_TRDESC_RLDCNT_SHIFT (20U)
135#define CPPI5_INFO0_TRDESC_RLDCNT_MASK GENMASK(28, 20)
136#define CPPI5_INFO0_TRDESC_RLDCNT_MAX (0x1ff)
137#define CPPI5_INFO0_TRDESC_RLDCNT_INFINITE CPPI5_INFO0_TRDESC_RLDCNT_MAX
138#define CPPI5_INFO0_TRDESC_RLDIDX_SHIFT (14U)
139#define CPPI5_INFO0_TRDESC_RLDIDX_MASK GENMASK(19, 14)
140#define CPPI5_INFO0_TRDESC_RLDIDX_MAX (0x3f)
141#define CPPI5_INFO0_TRDESC_LASTIDX_SHIFT (0)
142#define CPPI5_INFO0_TRDESC_LASTIDX_MASK GENMASK(13, 0)
143
144#define CPPI5_INFO1_TRDESC_RECSIZE_SHIFT (24U)
145#define CPPI5_INFO1_TRDESC_RECSIZE_MASK GENMASK(26, 24)
146#define CPPI5_INFO1_TRDESC_RECSIZE_VAL_16B (0)
147#define CPPI5_INFO1_TRDESC_RECSIZE_VAL_32B (1U)
148#define CPPI5_INFO1_TRDESC_RECSIZE_VAL_64B (2U)
149#define CPPI5_INFO1_TRDESC_RECSIZE_VAL_128B (3U)
150
151static inline void cppi5_desc_dump(void *desc, u32 size)
152{
153 print_hex_dump(KERN_ERR "dump udmap_desc: ", DUMP_PREFIX_NONE,
154 32, 4, desc, size, false);
155}
156
157
158
159
160
161
162
163
164
165
166static inline u32 cppi5_desc_get_type(struct cppi5_desc_hdr_t *desc_hdr)
167{
168 WARN_ON(!desc_hdr);
169
170 return (desc_hdr->pkt_info0 & CPPI5_INFO0_HDESC_TYPE_MASK) >>
171 CPPI5_INFO0_HDESC_TYPE_SHIFT;
172}
173
174
175
176
177
178
179
180static inline u32 cppi5_desc_get_errflags(struct cppi5_desc_hdr_t *desc_hdr)
181{
182 WARN_ON(!desc_hdr);
183
184 return (desc_hdr->pkt_info1 & CPPI5_INFO1_DESC_PKTERROR_MASK) >>
185 CPPI5_INFO1_DESC_PKTERROR_SHIFT;
186}
187
188
189
190
191
192
193
194
195
196static inline void cppi5_desc_get_pktids(struct cppi5_desc_hdr_t *desc_hdr,
197 u32 *pkt_id, u32 *flow_id)
198{
199 WARN_ON(!desc_hdr);
200
201 *pkt_id = (desc_hdr->pkt_info1 & CPPI5_INFO1_DESC_PKTID_MASK) >>
202 CPPI5_INFO1_DESC_PKTID_SHIFT;
203 *flow_id = (desc_hdr->pkt_info1 & CPPI5_INFO1_DESC_FLOWID_MASK) >>
204 CPPI5_INFO1_DESC_FLOWID_SHIFT;
205}
206
207
208
209
210
211
212
213static inline void cppi5_desc_set_pktids(struct cppi5_desc_hdr_t *desc_hdr,
214 u32 pkt_id, u32 flow_id)
215{
216 WARN_ON(!desc_hdr);
217
218 desc_hdr->pkt_info1 |= (pkt_id << CPPI5_INFO1_DESC_PKTID_SHIFT) &
219 CPPI5_INFO1_DESC_PKTID_MASK;
220 desc_hdr->pkt_info1 |= (flow_id << CPPI5_INFO1_DESC_FLOWID_SHIFT) &
221 CPPI5_INFO1_DESC_FLOWID_MASK;
222}
223
224
225
226
227
228
229
230
231
232
233static inline void cppi5_desc_set_retpolicy(struct cppi5_desc_hdr_t *desc_hdr,
234 u32 flags, u32 return_ring_id)
235{
236 WARN_ON(!desc_hdr);
237
238 desc_hdr->pkt_info2 |= flags;
239 desc_hdr->pkt_info2 |= return_ring_id & CPPI5_INFO2_DESC_RETQ_MASK;
240}
241
242
243
244
245
246
247
248
249
250static inline void cppi5_desc_get_tags_ids(struct cppi5_desc_hdr_t *desc_hdr,
251 u32 *src_tag_id, u32 *dst_tag_id)
252{
253 WARN_ON(!desc_hdr);
254
255 if (src_tag_id)
256 *src_tag_id = (desc_hdr->src_dst_tag &
257 CPPI5_INFO3_DESC_SRCTAG_MASK) >>
258 CPPI5_INFO3_DESC_SRCTAG_SHIFT;
259 if (dst_tag_id)
260 *dst_tag_id = desc_hdr->src_dst_tag &
261 CPPI5_INFO3_DESC_DSTTAG_MASK;
262}
263
264
265
266
267
268
269
270
271
272static inline void cppi5_desc_set_tags_ids(struct cppi5_desc_hdr_t *desc_hdr,
273 u32 src_tag_id, u32 dst_tag_id)
274{
275 WARN_ON(!desc_hdr);
276
277 desc_hdr->src_dst_tag = (src_tag_id << CPPI5_INFO3_DESC_SRCTAG_SHIFT) &
278 CPPI5_INFO3_DESC_SRCTAG_MASK;
279 desc_hdr->src_dst_tag |= dst_tag_id & CPPI5_INFO3_DESC_DSTTAG_MASK;
280}
281
282
283
284
285
286
287
288
289
290
291static inline u32 cppi5_hdesc_calc_size(bool epib, u32 psdata_size,
292 u32 sw_data_size)
293{
294 u32 desc_size;
295
296 if (psdata_size > CPPI5_INFO0_HDESC_PSDATA_MAX_SIZE)
297 return 0;
298
299 desc_size = sizeof(struct cppi5_host_desc_t) + psdata_size +
300 sw_data_size;
301
302 if (epib)
303 desc_size += CPPI5_INFO0_HDESC_EPIB_SIZE;
304
305 return ALIGN(desc_size, CPPI5_DESC_MIN_ALIGN);
306}
307
308
309
310
311
312
313
314
315
316
317
318
319static inline void cppi5_hdesc_init(struct cppi5_host_desc_t *desc, u32 flags,
320 u32 psdata_size)
321{
322 WARN_ON(!desc);
323 WARN_ON(psdata_size > CPPI5_INFO0_HDESC_PSDATA_MAX_SIZE);
324 WARN_ON(flags & ~(CPPI5_INFO0_HDESC_EPIB_PRESENT |
325 CPPI5_INFO0_HDESC_PSINFO_LOCATION));
326
327 desc->hdr.pkt_info0 = (CPPI5_INFO0_DESC_TYPE_VAL_HOST <<
328 CPPI5_INFO0_HDESC_TYPE_SHIFT) | (flags);
329 desc->hdr.pkt_info0 |= ((psdata_size >> 2) <<
330 CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT) &
331 CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK;
332 desc->next_desc = 0;
333}
334
335
336
337
338
339
340
341
342static inline void cppi5_hdesc_update_flags(struct cppi5_host_desc_t *desc,
343 u32 flags)
344{
345 WARN_ON(!desc);
346 WARN_ON(flags & ~(CPPI5_INFO0_HDESC_EPIB_PRESENT |
347 CPPI5_INFO0_HDESC_PSINFO_LOCATION));
348
349 desc->hdr.pkt_info0 &= ~(CPPI5_INFO0_HDESC_EPIB_PRESENT |
350 CPPI5_INFO0_HDESC_PSINFO_LOCATION);
351 desc->hdr.pkt_info0 |= flags;
352}
353
354
355
356
357
358
359static inline void cppi5_hdesc_update_psdata_size(
360 struct cppi5_host_desc_t *desc, u32 psdata_size)
361{
362 WARN_ON(!desc);
363 WARN_ON(psdata_size > CPPI5_INFO0_HDESC_PSDATA_MAX_SIZE);
364
365 desc->hdr.pkt_info0 &= ~CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK;
366 desc->hdr.pkt_info0 |= ((psdata_size >> 2) <<
367 CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT) &
368 CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK;
369}
370
371
372
373
374
375static inline u32 cppi5_hdesc_get_psdata_size(struct cppi5_host_desc_t *desc)
376{
377 u32 psdata_size = 0;
378
379 WARN_ON(!desc);
380
381 if (!(desc->hdr.pkt_info0 & CPPI5_INFO0_HDESC_PSINFO_LOCATION))
382 psdata_size = (desc->hdr.pkt_info0 &
383 CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK) >>
384 CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT;
385
386 return (psdata_size << 2);
387}
388
389
390
391
392
393
394
395static inline u32 cppi5_hdesc_get_pktlen(struct cppi5_host_desc_t *desc)
396{
397 WARN_ON(!desc);
398
399 return (desc->hdr.pkt_info0 & CPPI5_INFO0_HDESC_PKTLEN_MASK);
400}
401
402
403
404
405
406static inline void cppi5_hdesc_set_pktlen(struct cppi5_host_desc_t *desc,
407 u32 pkt_len)
408{
409 WARN_ON(!desc);
410
411 desc->hdr.pkt_info0 |= (pkt_len & CPPI5_INFO0_HDESC_PKTLEN_MASK);
412}
413
414
415
416
417
418
419
420static inline u32 cppi5_hdesc_get_psflags(struct cppi5_host_desc_t *desc)
421{
422 WARN_ON(!desc);
423
424 return (desc->hdr.pkt_info1 & CPPI5_INFO1_HDESC_PSFLGS_MASK) >>
425 CPPI5_INFO1_HDESC_PSFLGS_SHIFT;
426}
427
428
429
430
431
432static inline void cppi5_hdesc_set_psflags(struct cppi5_host_desc_t *desc,
433 u32 ps_flags)
434{
435 WARN_ON(!desc);
436
437 desc->hdr.pkt_info1 |= (ps_flags <<
438 CPPI5_INFO1_HDESC_PSFLGS_SHIFT) &
439 CPPI5_INFO1_HDESC_PSFLGS_MASK;
440}
441
442
443
444
445
446static inline u32 cppi5_hdesc_get_pkttype(struct cppi5_host_desc_t *desc)
447{
448 WARN_ON(!desc);
449
450 return (desc->hdr.pkt_info2 & CPPI5_INFO2_HDESC_PKTTYPE_MASK) >>
451 CPPI5_INFO2_HDESC_PKTTYPE_SHIFT;
452}
453
454
455
456
457
458
459static inline void cppi5_hdesc_set_pkttype(struct cppi5_host_desc_t *desc,
460 u32 pkt_type)
461{
462 WARN_ON(!desc);
463 desc->hdr.pkt_info2 |=
464 (pkt_type << CPPI5_INFO2_HDESC_PKTTYPE_SHIFT) &
465 CPPI5_INFO2_HDESC_PKTTYPE_MASK;
466}
467
468
469
470
471
472
473
474
475
476
477
478static inline void cppi5_hdesc_attach_buf(struct cppi5_host_desc_t *desc,
479 dma_addr_t buf, u32 buf_data_len,
480 dma_addr_t obuf, u32 obuf_len)
481{
482 WARN_ON(!desc);
483 WARN_ON(!buf && !obuf);
484
485 desc->buf_ptr = buf;
486 desc->buf_info1 = buf_data_len & CPPI5_BUFINFO1_HDESC_DATA_LEN_MASK;
487 desc->org_buf_ptr = obuf;
488 desc->org_buf_len = obuf_len & CPPI5_OBUFINFO0_HDESC_BUF_LEN_MASK;
489}
490
491static inline void cppi5_hdesc_get_obuf(struct cppi5_host_desc_t *desc,
492 dma_addr_t *obuf, u32 *obuf_len)
493{
494 WARN_ON(!desc);
495 WARN_ON(!obuf);
496 WARN_ON(!obuf_len);
497
498 *obuf = desc->org_buf_ptr;
499 *obuf_len = desc->org_buf_len & CPPI5_OBUFINFO0_HDESC_BUF_LEN_MASK;
500}
501
502static inline void cppi5_hdesc_reset_to_original(struct cppi5_host_desc_t *desc)
503{
504 WARN_ON(!desc);
505
506 desc->buf_ptr = desc->org_buf_ptr;
507 desc->buf_info1 = desc->org_buf_len;
508}
509
510
511
512
513
514
515
516
517static inline void cppi5_hdesc_link_hbdesc(struct cppi5_host_desc_t *desc,
518 dma_addr_t hbuf_desc)
519{
520 WARN_ON(!desc);
521 WARN_ON(!hbuf_desc);
522
523 desc->next_desc = hbuf_desc;
524}
525
526static inline dma_addr_t cppi5_hdesc_get_next_hbdesc(
527 struct cppi5_host_desc_t *desc)
528{
529 WARN_ON(!desc);
530
531 return (dma_addr_t)desc->next_desc;
532}
533
534static inline void cppi5_hdesc_reset_hbdesc(struct cppi5_host_desc_t *desc)
535{
536 WARN_ON(!desc);
537
538 desc->hdr = (struct cppi5_desc_hdr_t) { 0 };
539 desc->next_desc = 0;
540}
541
542
543
544
545
546
547
548static inline bool cppi5_hdesc_epib_present(struct cppi5_desc_hdr_t *desc_hdr)
549{
550 WARN_ON(!desc_hdr);
551 return !!(desc_hdr->pkt_info0 & CPPI5_INFO0_HDESC_EPIB_PRESENT);
552}
553
554
555
556
557
558
559
560
561static inline void *cppi5_hdesc_get_psdata(struct cppi5_host_desc_t *desc)
562{
563 u32 psdata_size;
564 void *psdata;
565
566 WARN_ON(!desc);
567
568 if (desc->hdr.pkt_info0 & CPPI5_INFO0_HDESC_PSINFO_LOCATION)
569 return NULL;
570
571 psdata_size = (desc->hdr.pkt_info0 &
572 CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK) >>
573 CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT;
574
575 if (!psdata_size)
576 return NULL;
577
578 psdata = &desc->epib;
579
580 if (cppi5_hdesc_epib_present(&desc->hdr))
581 psdata += CPPI5_INFO0_HDESC_EPIB_SIZE;
582
583 return psdata;
584}
585
586static inline u32 *cppi5_hdesc_get_psdata32(struct cppi5_host_desc_t *desc)
587{
588 return (u32 *)cppi5_hdesc_get_psdata(desc);
589}
590
591
592
593
594
595
596
597
598static inline void *cppi5_hdesc_get_swdata(struct cppi5_host_desc_t *desc)
599{
600 u32 psdata_size = 0;
601 void *swdata;
602
603 WARN_ON(!desc);
604
605 if (!(desc->hdr.pkt_info0 & CPPI5_INFO0_HDESC_PSINFO_LOCATION))
606 psdata_size = (desc->hdr.pkt_info0 &
607 CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK) >>
608 CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT;
609
610 swdata = &desc->epib;
611
612 if (cppi5_hdesc_epib_present(&desc->hdr))
613 swdata += CPPI5_INFO0_HDESC_EPIB_SIZE;
614
615 swdata += (psdata_size << 2);
616
617 return swdata;
618}
619
620
621
622#define CPPI5_TR_TYPE_SHIFT (0U)
623#define CPPI5_TR_TYPE_MASK GENMASK(3, 0)
624#define CPPI5_TR_STATIC BIT(4)
625#define CPPI5_TR_WAIT BIT(5)
626#define CPPI5_TR_EVENT_SIZE_SHIFT (6U)
627#define CPPI5_TR_EVENT_SIZE_MASK GENMASK(7, 6)
628#define CPPI5_TR_TRIGGER0_SHIFT (8U)
629#define CPPI5_TR_TRIGGER0_MASK GENMASK(9, 8)
630#define CPPI5_TR_TRIGGER0_TYPE_SHIFT (10U)
631#define CPPI5_TR_TRIGGER0_TYPE_MASK GENMASK(11, 10)
632#define CPPI5_TR_TRIGGER1_SHIFT (12U)
633#define CPPI5_TR_TRIGGER1_MASK GENMASK(13, 12)
634#define CPPI5_TR_TRIGGER1_TYPE_SHIFT (14U)
635#define CPPI5_TR_TRIGGER1_TYPE_MASK GENMASK(15, 14)
636#define CPPI5_TR_CMD_ID_SHIFT (16U)
637#define CPPI5_TR_CMD_ID_MASK GENMASK(23, 16)
638#define CPPI5_TR_CSF_FLAGS_SHIFT (24U)
639#define CPPI5_TR_CSF_FLAGS_MASK GENMASK(31, 24)
640#define CPPI5_TR_CSF_SA_INDIRECT BIT(0)
641#define CPPI5_TR_CSF_DA_INDIRECT BIT(1)
642#define CPPI5_TR_CSF_SUPR_EVT BIT(2)
643#define CPPI5_TR_CSF_EOL_ADV_SHIFT (4U)
644#define CPPI5_TR_CSF_EOL_ADV_MASK GENMASK(6, 4)
645#define CPPI5_TR_CSF_EOP BIT(7)
646
647
648enum cppi5_tr_types {
649
650 CPPI5_TR_TYPE0 = 0,
651
652 CPPI5_TR_TYPE1,
653
654 CPPI5_TR_TYPE2,
655
656 CPPI5_TR_TYPE3,
657
658 CPPI5_TR_TYPE4,
659
660 CPPI5_TR_TYPE5,
661
662
663 CPPI5_TR_TYPE8 = 8,
664
665 CPPI5_TR_TYPE9,
666
667 CPPI5_TR_TYPE10,
668
669 CPPI5_TR_TYPE11,
670
671
672 CPPI5_TR_TYPE15 = 15,
673 CPPI5_TR_TYPE_MAX
674};
675
676
677
678
679
680enum cppi5_tr_event_size {
681
682 CPPI5_TR_EVENT_SIZE_COMPLETION,
683
684
685
686
687 CPPI5_TR_EVENT_SIZE_ICNT1_DEC,
688
689
690
691
692 CPPI5_TR_EVENT_SIZE_ICNT2_DEC,
693
694
695
696
697 CPPI5_TR_EVENT_SIZE_ICNT3_DEC,
698 CPPI5_TR_EVENT_SIZE_MAX
699};
700
701
702
703
704
705enum cppi5_tr_trigger {
706 CPPI5_TR_TRIGGER_NONE,
707 CPPI5_TR_TRIGGER_GLOBAL0,
708 CPPI5_TR_TRIGGER_GLOBAL1,
709 CPPI5_TR_TRIGGER_LOCAL_EVENT,
710 CPPI5_TR_TRIGGER_MAX
711};
712
713
714
715
716
717enum cppi5_tr_trigger_type {
718
719 CPPI5_TR_TRIGGER_TYPE_ICNT1_DEC,
720
721 CPPI5_TR_TRIGGER_TYPE_ICNT2_DEC,
722
723 CPPI5_TR_TRIGGER_TYPE_ICNT3_DEC,
724
725 CPPI5_TR_TRIGGER_TYPE_ALL,
726 CPPI5_TR_TRIGGER_TYPE_MAX
727};
728
729typedef u32 cppi5_tr_flags_t;
730
731
732struct cppi5_tr_type0_t {
733 cppi5_tr_flags_t flags;
734 u16 icnt0;
735 u16 unused;
736 u64 addr;
737} __aligned(16) __packed;
738
739
740struct cppi5_tr_type1_t {
741 cppi5_tr_flags_t flags;
742 u16 icnt0;
743 u16 icnt1;
744 u64 addr;
745 s32 dim1;
746} __aligned(32) __packed;
747
748
749struct cppi5_tr_type2_t {
750 cppi5_tr_flags_t flags;
751 u16 icnt0;
752 u16 icnt1;
753 u64 addr;
754 s32 dim1;
755 u16 icnt2;
756 u16 unused;
757 s32 dim2;
758} __aligned(32) __packed;
759
760
761struct cppi5_tr_type3_t {
762 cppi5_tr_flags_t flags;
763 u16 icnt0;
764 u16 icnt1;
765 u64 addr;
766 s32 dim1;
767 u16 icnt2;
768 u16 icnt3;
769 s32 dim2;
770 s32 dim3;
771} __aligned(32) __packed;
772
773
774
775
776
777struct cppi5_tr_type15_t {
778 cppi5_tr_flags_t flags;
779 u16 icnt0;
780 u16 icnt1;
781 u64 addr;
782 s32 dim1;
783 u16 icnt2;
784 u16 icnt3;
785 s32 dim2;
786 s32 dim3;
787 u32 _reserved;
788 s32 ddim1;
789 u64 daddr;
790 s32 ddim2;
791 s32 ddim3;
792 u16 dicnt0;
793 u16 dicnt1;
794 u16 dicnt2;
795 u16 dicnt3;
796} __aligned(64) __packed;
797
798struct cppi5_tr_resp_t {
799 u8 status;
800 u8 reserved;
801 u8 cmd_id;
802 u8 flags;
803} __packed;
804
805#define CPPI5_TR_RESPONSE_STATUS_TYPE_SHIFT (0U)
806#define CPPI5_TR_RESPONSE_STATUS_TYPE_MASK GENMASK(3, 0)
807#define CPPI5_TR_RESPONSE_STATUS_INFO_SHIFT (4U)
808#define CPPI5_TR_RESPONSE_STATUS_INFO_MASK GENMASK(7, 4)
809#define CPPI5_TR_RESPONSE_CMDID_SHIFT (16U)
810#define CPPI5_TR_RESPONSE_CMDID_MASK GENMASK(23, 16)
811#define CPPI5_TR_RESPONSE_CFG_SPECIFIC_SHIFT (24U)
812#define CPPI5_TR_RESPONSE_CFG_SPECIFIC_MASK GENMASK(31, 24)
813
814
815
816
817
818enum cppi5_tr_resp_status_type {
819 CPPI5_TR_RESPONSE_STATUS_COMPLETE,
820 CPPI5_TR_RESPONSE_STATUS_TRANSFER_ERR,
821 CPPI5_TR_RESPONSE_STATUS_ABORTED_ERR,
822 CPPI5_TR_RESPONSE_STATUS_SUBMISSION_ERR,
823 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_ERR,
824 CPPI5_TR_RESPONSE_STATUS_MAX
825};
826
827
828
829
830
831enum cppi5_tr_resp_status_submission {
832
833 CPPI5_TR_RESPONSE_STATUS_SUBMISSION_ICNT0,
834
835 CPPI5_TR_RESPONSE_STATUS_SUBMISSION_FIFO_FULL,
836
837 CPPI5_TR_RESPONSE_STATUS_SUBMISSION_OWN,
838 CPPI5_TR_RESPONSE_STATUS_SUBMISSION_MAX
839};
840
841
842
843
844
845enum cppi5_tr_resp_status_unsupported {
846
847 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_TR_TYPE,
848
849 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_STATIC,
850
851 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_EOL,
852
853 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_CFG_SPECIFIC,
854
855 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_AMODE,
856
857 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_ELTYPE,
858
859 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_DFMT,
860
861 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_SECTR,
862
863 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_AMODE_SPECIFIC,
864 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_MAX
865};
866
867
868
869
870
871
872
873
874static inline size_t cppi5_trdesc_calc_size(u32 tr_count, u32 tr_size)
875{
876
877
878
879
880
881
882 return tr_size * (tr_count + 1) +
883 sizeof(struct cppi5_tr_resp_t) * tr_count;
884}
885
886
887
888
889
890
891
892
893
894
895
896
897
898static inline void cppi5_trdesc_init(struct cppi5_desc_hdr_t *desc_hdr,
899 u32 tr_count, u32 tr_size, u32 reload_idx,
900 u32 reload_count)
901{
902 WARN_ON(!desc_hdr);
903 WARN_ON(tr_count & ~CPPI5_INFO0_TRDESC_LASTIDX_MASK);
904 WARN_ON(reload_idx > CPPI5_INFO0_TRDESC_RLDIDX_MAX);
905 WARN_ON(reload_count > CPPI5_INFO0_TRDESC_RLDCNT_MAX);
906
907 desc_hdr->pkt_info0 = CPPI5_INFO0_DESC_TYPE_VAL_TR <<
908 CPPI5_INFO0_HDESC_TYPE_SHIFT;
909 desc_hdr->pkt_info0 |= (reload_count << CPPI5_INFO0_TRDESC_RLDCNT_SHIFT) &
910 CPPI5_INFO0_TRDESC_RLDCNT_MASK;
911 desc_hdr->pkt_info0 |= (reload_idx << CPPI5_INFO0_TRDESC_RLDIDX_SHIFT) &
912 CPPI5_INFO0_TRDESC_RLDIDX_MASK;
913 desc_hdr->pkt_info0 |= (tr_count - 1) & CPPI5_INFO0_TRDESC_LASTIDX_MASK;
914
915 desc_hdr->pkt_info1 |= ((ffs(tr_size >> 4) - 1) <<
916 CPPI5_INFO1_TRDESC_RECSIZE_SHIFT) &
917 CPPI5_INFO1_TRDESC_RECSIZE_MASK;
918}
919
920
921
922
923
924
925
926
927
928
929
930
931static inline void cppi5_tr_init(cppi5_tr_flags_t *flags,
932 enum cppi5_tr_types type, bool static_tr,
933 bool wait, enum cppi5_tr_event_size event_size,
934 u32 cmd_id)
935{
936 WARN_ON(!flags);
937
938 *flags = type;
939 *flags |= (event_size << CPPI5_TR_EVENT_SIZE_SHIFT) &
940 CPPI5_TR_EVENT_SIZE_MASK;
941
942 *flags |= (cmd_id << CPPI5_TR_CMD_ID_SHIFT) &
943 CPPI5_TR_CMD_ID_MASK;
944
945 if (static_tr && (type == CPPI5_TR_TYPE8 || type == CPPI5_TR_TYPE9))
946 *flags |= CPPI5_TR_STATIC;
947
948 if (wait)
949 *flags |= CPPI5_TR_WAIT;
950}
951
952
953
954
955
956
957
958
959
960
961
962static inline void cppi5_tr_set_trigger(cppi5_tr_flags_t *flags,
963 enum cppi5_tr_trigger trigger0,
964 enum cppi5_tr_trigger_type trigger0_type,
965 enum cppi5_tr_trigger trigger1,
966 enum cppi5_tr_trigger_type trigger1_type)
967{
968 WARN_ON(!flags);
969
970 *flags |= (trigger0 << CPPI5_TR_TRIGGER0_SHIFT) &
971 CPPI5_TR_TRIGGER0_MASK;
972 *flags |= (trigger0_type << CPPI5_TR_TRIGGER0_TYPE_SHIFT) &
973 CPPI5_TR_TRIGGER0_TYPE_MASK;
974
975 *flags |= (trigger1 << CPPI5_TR_TRIGGER1_SHIFT) &
976 CPPI5_TR_TRIGGER1_MASK;
977 *flags |= (trigger1_type << CPPI5_TR_TRIGGER1_TYPE_SHIFT) &
978 CPPI5_TR_TRIGGER1_TYPE_MASK;
979}
980
981
982
983
984
985
986
987
988static inline void cppi5_tr_csf_set(cppi5_tr_flags_t *flags, u32 csf)
989{
990 WARN_ON(!flags);
991
992 *flags |= (csf << CPPI5_TR_CSF_FLAGS_SHIFT) &
993 CPPI5_TR_CSF_FLAGS_MASK;
994}
995
996#endif
997