1 /* SPDX-License-Identifier: GPL-2.0 */
3 * CPPI5 descriptors interface
5 * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com
11 #include <linux/bitops.h>
12 #include <linux/printk.h>
13 #include <linux/bug.h>
16 * struct cppi5_desc_hdr_t - Descriptor header, present in all types of
18 * @pkt_info0: Packet info word 0 (n/a in Buffer desc)
19 * @pkt_info0: Packet info word 1 (n/a in Buffer desc)
20 * @pkt_info0: Packet info word 2 (n/a in Buffer desc)
21 * @src_dst_tag: Packet info word 3 (n/a in Buffer desc)
23 struct cppi5_desc_hdr_t {
31 * struct cppi5_host_desc_t - Host-mode packet and buffer descriptor definition
32 * @hdr: Descriptor header
33 * @next_desc: word 4/5: Linking word
34 * @buf_ptr: word 6/7: Buffer pointer
35 * @buf_info1: word 8: Buffer valid data length
36 * @org_buf_len: word 9: Original buffer length
37 * @org_buf_ptr: word 10/11: Original buffer pointer
38 * @epib[0]: Extended Packet Info Data (optional, 4 words), and/or
39 * Protocol Specific Data (optional, 0-128 bytes in
40 * multiples of 4), and/or
41 * Other Software Data (0-N bytes, optional)
43 struct cppi5_host_desc_t {
44 struct cppi5_desc_hdr_t hdr;
53 #define CPPI5_DESC_MIN_ALIGN (16U)
55 #define CPPI5_INFO0_HDESC_EPIB_SIZE (16U)
56 #define CPPI5_INFO0_HDESC_PSDATA_MAX_SIZE (128U)
58 #define CPPI5_INFO0_HDESC_TYPE_SHIFT (30U)
59 #define CPPI5_INFO0_HDESC_TYPE_MASK GENMASK(31, 30)
60 #define CPPI5_INFO0_DESC_TYPE_VAL_HOST (1U)
61 #define CPPI5_INFO0_DESC_TYPE_VAL_MONO (2U)
62 #define CPPI5_INFO0_DESC_TYPE_VAL_TR (3U)
63 #define CPPI5_INFO0_HDESC_EPIB_PRESENT BIT(29)
65 * Protocol Specific Words location:
66 * 0 - located in the descriptor,
67 * 1 = located in the SOP Buffer immediately prior to the data.
69 #define CPPI5_INFO0_HDESC_PSINFO_LOCATION BIT(28)
70 #define CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT (22U)
71 #define CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK GENMASK(27, 22)
72 #define CPPI5_INFO0_HDESC_PKTLEN_SHIFT (0)
73 #define CPPI5_INFO0_HDESC_PKTLEN_MASK GENMASK(21, 0)
75 #define CPPI5_INFO1_DESC_PKTERROR_SHIFT (28U)
76 #define CPPI5_INFO1_DESC_PKTERROR_MASK GENMASK(31, 28)
77 #define CPPI5_INFO1_HDESC_PSFLGS_SHIFT (24U)
78 #define CPPI5_INFO1_HDESC_PSFLGS_MASK GENMASK(27, 24)
79 #define CPPI5_INFO1_DESC_PKTID_SHIFT (14U)
80 #define CPPI5_INFO1_DESC_PKTID_MASK GENMASK(23, 14)
81 #define CPPI5_INFO1_DESC_FLOWID_SHIFT (0)
82 #define CPPI5_INFO1_DESC_FLOWID_MASK GENMASK(13, 0)
83 #define CPPI5_INFO1_DESC_FLOWID_DEFAULT CPPI5_INFO1_DESC_FLOWID_MASK
85 #define CPPI5_INFO2_HDESC_PKTTYPE_SHIFT (27U)
86 #define CPPI5_INFO2_HDESC_PKTTYPE_MASK GENMASK(31, 27)
87 /* Return Policy: 0 - Entire packet 1 - Each buffer */
88 #define CPPI5_INFO2_HDESC_RETPOLICY BIT(18)
91 * 0 = desc pointers should be returned after all reads have been completed
92 * 1 = desc pointers should be returned immediately upon fetching
93 * the descriptor and beginning to transfer data.
95 #define CPPI5_INFO2_HDESC_EARLYRET BIT(17)
98 * 0 = Descriptor must be returned to tail of queue
99 * 1 = Descriptor must be returned to head of queue
101 #define CPPI5_INFO2_DESC_RETPUSHPOLICY BIT(16)
102 #define CPPI5_INFO2_DESC_RETP_MASK GENMASK(18, 16)
104 #define CPPI5_INFO2_DESC_RETQ_SHIFT (0)
105 #define CPPI5_INFO2_DESC_RETQ_MASK GENMASK(15, 0)
107 #define CPPI5_INFO3_DESC_SRCTAG_SHIFT (16U)
108 #define CPPI5_INFO3_DESC_SRCTAG_MASK GENMASK(31, 16)
109 #define CPPI5_INFO3_DESC_DSTTAG_SHIFT (0)
110 #define CPPI5_INFO3_DESC_DSTTAG_MASK GENMASK(15, 0)
112 #define CPPI5_BUFINFO1_HDESC_DATA_LEN_SHIFT (0)
113 #define CPPI5_BUFINFO1_HDESC_DATA_LEN_MASK GENMASK(27, 0)
115 #define CPPI5_OBUFINFO0_HDESC_BUF_LEN_SHIFT (0)
116 #define CPPI5_OBUFINFO0_HDESC_BUF_LEN_MASK GENMASK(27, 0)
119 * struct cppi5_desc_epib_t - Host Packet Descriptor Extended Packet Info Block
120 * @timestamp: word 0: application specific timestamp
121 * @sw_info0: word 1: Software Info 0
122 * @sw_info1: word 1: Software Info 1
123 * @sw_info2: word 1: Software Info 2
125 struct cppi5_desc_epib_t {
126 u32 timestamp; /* w0: application specific timestamp */
127 u32 sw_info0; /* w1: Software Info 0 */
128 u32 sw_info1; /* w2: Software Info 1 */
129 u32 sw_info2; /* w3: Software Info 2 */
133 * struct cppi5_monolithic_desc_t - Monolithic-mode packet descriptor
134 * @hdr: Descriptor header
135 * @epib[0]: Extended Packet Info Data (optional, 4 words), and/or
136 * Protocol Specific Data (optional, 0-128 bytes in
137 * multiples of 4), and/or
138 * Other Software Data (0-N bytes, optional)
140 struct cppi5_monolithic_desc_t {
141 struct cppi5_desc_hdr_t hdr;
145 #define CPPI5_INFO2_MDESC_DATA_OFFSET_SHIFT (18U)
146 #define CPPI5_INFO2_MDESC_DATA_OFFSET_MASK GENMASK(26, 18)
150 * 0 = Finish the packet and place the descriptor back on the return queue
151 * 1-0x1ff = Vector to the Reload Index and resume processing
152 * 0x1ff indicates perpetual loop, infinite reload until the channel is stopped
154 #define CPPI5_INFO0_TRDESC_RLDCNT_SHIFT (20U)
155 #define CPPI5_INFO0_TRDESC_RLDCNT_MASK GENMASK(28, 20)
156 #define CPPI5_INFO0_TRDESC_RLDCNT_MAX (0x1ff)
157 #define CPPI5_INFO0_TRDESC_RLDCNT_INFINITE CPPI5_INFO0_TRDESC_RLDCNT_MAX
158 #define CPPI5_INFO0_TRDESC_RLDIDX_SHIFT (14U)
159 #define CPPI5_INFO0_TRDESC_RLDIDX_MASK GENMASK(19, 14)
160 #define CPPI5_INFO0_TRDESC_RLDIDX_MAX (0x3f)
161 #define CPPI5_INFO0_TRDESC_LASTIDX_SHIFT (0)
162 #define CPPI5_INFO0_TRDESC_LASTIDX_MASK GENMASK(13, 0)
164 #define CPPI5_INFO1_TRDESC_RECSIZE_SHIFT (24U)
165 #define CPPI5_INFO1_TRDESC_RECSIZE_MASK GENMASK(26, 24)
166 #define CPPI5_INFO1_TRDESC_RECSIZE_VAL_16B (0)
167 #define CPPI5_INFO1_TRDESC_RECSIZE_VAL_32B (1U)
168 #define CPPI5_INFO1_TRDESC_RECSIZE_VAL_64B (2U)
169 #define CPPI5_INFO1_TRDESC_RECSIZE_VAL_128B (3U)
171 static inline void cppi5_desc_dump(void *desc, u32 size)
173 print_hex_dump(KERN_ERR, "dump udmap_desc: ", DUMP_PREFIX_NONE,
174 32, 4, desc, size, false);
177 #define CPPI5_TDCM_MARKER (0x1)
179 * cppi5_desc_is_tdcm - check if the paddr indicates Teardown Complete Message
180 * @paddr: Physical address of the packet popped from the ring
182 * Returns true if the address indicates TDCM
184 static inline bool cppi5_desc_is_tdcm(dma_addr_t paddr)
186 return (paddr & CPPI5_TDCM_MARKER) ? true : false;
190 * cppi5_desc_get_type - get descriptor type
191 * @desc_hdr: packet descriptor/TR header
193 * Returns descriptor type:
194 * CPPI5_INFO0_DESC_TYPE_VAL_HOST
195 * CPPI5_INFO0_DESC_TYPE_VAL_MONO
196 * CPPI5_INFO0_DESC_TYPE_VAL_TR
198 static inline u32 cppi5_desc_get_type(struct cppi5_desc_hdr_t *desc_hdr)
200 return (desc_hdr->pkt_info0 & CPPI5_INFO0_HDESC_TYPE_MASK) >>
201 CPPI5_INFO0_HDESC_TYPE_SHIFT;
205 * cppi5_desc_get_errflags - get Error Flags from Desc
206 * @desc_hdr: packet/TR descriptor header
208 * Returns Error Flags from Packet/TR Descriptor
210 static inline u32 cppi5_desc_get_errflags(struct cppi5_desc_hdr_t *desc_hdr)
212 return (desc_hdr->pkt_info1 & CPPI5_INFO1_DESC_PKTERROR_MASK) >>
213 CPPI5_INFO1_DESC_PKTERROR_SHIFT;
217 * cppi5_desc_get_pktids - get Packet and Flow ids from Desc
218 * @desc_hdr: packet/TR descriptor header
222 * Returns Packet and Flow ids from packet/TR descriptor
224 static inline void cppi5_desc_get_pktids(struct cppi5_desc_hdr_t *desc_hdr,
225 u32 *pkt_id, u32 *flow_id)
227 *pkt_id = (desc_hdr->pkt_info1 & CPPI5_INFO1_DESC_PKTID_MASK) >>
228 CPPI5_INFO1_DESC_PKTID_SHIFT;
229 *flow_id = (desc_hdr->pkt_info1 & CPPI5_INFO1_DESC_FLOWID_MASK) >>
230 CPPI5_INFO1_DESC_FLOWID_SHIFT;
234 * cppi5_desc_set_pktids - set Packet and Flow ids in Desc
235 * @desc_hdr: packet/TR descriptor header
239 static inline void cppi5_desc_set_pktids(struct cppi5_desc_hdr_t *desc_hdr,
240 u32 pkt_id, u32 flow_id)
242 desc_hdr->pkt_info1 &= ~(CPPI5_INFO1_DESC_PKTID_MASK |
243 CPPI5_INFO1_DESC_FLOWID_MASK);
244 desc_hdr->pkt_info1 |= (pkt_id << CPPI5_INFO1_DESC_PKTID_SHIFT) &
245 CPPI5_INFO1_DESC_PKTID_MASK;
246 desc_hdr->pkt_info1 |= (flow_id << CPPI5_INFO1_DESC_FLOWID_SHIFT) &
247 CPPI5_INFO1_DESC_FLOWID_MASK;
251 * cppi5_desc_set_retpolicy - set Packet Return Policy in Desc
252 * @desc_hdr: packet/TR descriptor header
253 * @flags: fags, supported values
254 * CPPI5_INFO2_HDESC_RETPOLICY
255 * CPPI5_INFO2_HDESC_EARLYRET
256 * CPPI5_INFO2_DESC_RETPUSHPOLICY
257 * @return_ring_id: Packet Return Queue/Ring id, value 0xFFFF reserved
259 static inline void cppi5_desc_set_retpolicy(struct cppi5_desc_hdr_t *desc_hdr,
260 u32 flags, u32 return_ring_id)
262 desc_hdr->pkt_info2 &= ~(CPPI5_INFO2_DESC_RETP_MASK |
263 CPPI5_INFO2_DESC_RETQ_MASK);
264 desc_hdr->pkt_info2 |= flags & CPPI5_INFO2_DESC_RETP_MASK;
265 desc_hdr->pkt_info2 |= return_ring_id & CPPI5_INFO2_DESC_RETQ_MASK;
269 * cppi5_desc_get_tags_ids - get Packet Src/Dst Tags from Desc
270 * @desc_hdr: packet/TR descriptor header
271 * @src_tag_id: Source Tag
272 * @dst_tag_id: Dest Tag
274 * Returns Packet Src/Dst Tags from packet/TR descriptor
276 static inline void cppi5_desc_get_tags_ids(struct cppi5_desc_hdr_t *desc_hdr,
277 u32 *src_tag_id, u32 *dst_tag_id)
280 *src_tag_id = (desc_hdr->src_dst_tag &
281 CPPI5_INFO3_DESC_SRCTAG_MASK) >>
282 CPPI5_INFO3_DESC_SRCTAG_SHIFT;
284 *dst_tag_id = desc_hdr->src_dst_tag &
285 CPPI5_INFO3_DESC_DSTTAG_MASK;
289 * cppi5_desc_set_tags_ids - set Packet Src/Dst Tags in HDesc
290 * @desc_hdr: packet/TR descriptor header
291 * @src_tag_id: Source Tag
292 * @dst_tag_id: Dest Tag
294 * Returns Packet Src/Dst Tags from packet/TR descriptor
296 static inline void cppi5_desc_set_tags_ids(struct cppi5_desc_hdr_t *desc_hdr,
297 u32 src_tag_id, u32 dst_tag_id)
299 desc_hdr->src_dst_tag = (src_tag_id << CPPI5_INFO3_DESC_SRCTAG_SHIFT) &
300 CPPI5_INFO3_DESC_SRCTAG_MASK;
301 desc_hdr->src_dst_tag |= dst_tag_id & CPPI5_INFO3_DESC_DSTTAG_MASK;
305 * cppi5_hdesc_calc_size - Calculate Host Packet Descriptor size
306 * @epib: is EPIB present
307 * @psdata_size: PSDATA size
308 * @sw_data_size: SWDATA size
310 * Returns required Host Packet Descriptor size
311 * 0 - if PSDATA > CPPI5_INFO0_HDESC_PSDATA_MAX_SIZE
313 static inline u32 cppi5_hdesc_calc_size(bool epib, u32 psdata_size,
318 if (psdata_size > CPPI5_INFO0_HDESC_PSDATA_MAX_SIZE)
321 desc_size = sizeof(struct cppi5_host_desc_t) + psdata_size +
325 desc_size += CPPI5_INFO0_HDESC_EPIB_SIZE;
327 return ALIGN(desc_size, CPPI5_DESC_MIN_ALIGN);
331 * cppi5_hdesc_init - Init Host Packet Descriptor size
332 * @desc: Host packet descriptor
333 * @flags: supported values
334 * CPPI5_INFO0_HDESC_EPIB_PRESENT
335 * CPPI5_INFO0_HDESC_PSINFO_LOCATION
336 * @psdata_size: PSDATA size
338 * Returns required Host Packet Descriptor size
339 * 0 - if PSDATA > CPPI5_INFO0_HDESC_PSDATA_MAX_SIZE
341 static inline void cppi5_hdesc_init(struct cppi5_host_desc_t *desc, u32 flags,
344 desc->hdr.pkt_info0 = (CPPI5_INFO0_DESC_TYPE_VAL_HOST <<
345 CPPI5_INFO0_HDESC_TYPE_SHIFT) | (flags);
346 desc->hdr.pkt_info0 |= ((psdata_size >> 2) <<
347 CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT) &
348 CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK;
353 * cppi5_hdesc_update_flags - Replace descriptor flags
354 * @desc: Host packet descriptor
355 * @flags: supported values
356 * CPPI5_INFO0_HDESC_EPIB_PRESENT
357 * CPPI5_INFO0_HDESC_PSINFO_LOCATION
359 static inline void cppi5_hdesc_update_flags(struct cppi5_host_desc_t *desc,
362 desc->hdr.pkt_info0 &= ~(CPPI5_INFO0_HDESC_EPIB_PRESENT |
363 CPPI5_INFO0_HDESC_PSINFO_LOCATION);
364 desc->hdr.pkt_info0 |= flags;
368 * cppi5_hdesc_update_psdata_size - Replace PSdata size
369 * @desc: Host packet descriptor
370 * @psdata_size: PSDATA size
373 cppi5_hdesc_update_psdata_size(struct cppi5_host_desc_t *desc, u32 psdata_size)
375 desc->hdr.pkt_info0 &= ~CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK;
376 desc->hdr.pkt_info0 |= ((psdata_size >> 2) <<
377 CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT) &
378 CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK;
382 * cppi5_hdesc_get_psdata_size - get PSdata size in bytes
383 * @desc: Host packet descriptor
385 static inline u32 cppi5_hdesc_get_psdata_size(struct cppi5_host_desc_t *desc)
389 if (!(desc->hdr.pkt_info0 & CPPI5_INFO0_HDESC_PSINFO_LOCATION))
390 psdata_size = (desc->hdr.pkt_info0 &
391 CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK) >>
392 CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT;
394 return (psdata_size << 2);
398 * cppi5_hdesc_get_pktlen - get Packet Length from HDesc
399 * @desc: Host packet descriptor
401 * Returns Packet Length from Host Packet Descriptor
403 static inline u32 cppi5_hdesc_get_pktlen(struct cppi5_host_desc_t *desc)
405 return (desc->hdr.pkt_info0 & CPPI5_INFO0_HDESC_PKTLEN_MASK);
409 * cppi5_hdesc_set_pktlen - set Packet Length in HDesc
410 * @desc: Host packet descriptor
412 static inline void cppi5_hdesc_set_pktlen(struct cppi5_host_desc_t *desc,
415 desc->hdr.pkt_info0 &= ~CPPI5_INFO0_HDESC_PKTLEN_MASK;
416 desc->hdr.pkt_info0 |= (pkt_len & CPPI5_INFO0_HDESC_PKTLEN_MASK);
420 * cppi5_hdesc_get_psflags - get Protocol Specific Flags from HDesc
421 * @desc: Host packet descriptor
423 * Returns Protocol Specific Flags from Host Packet Descriptor
425 static inline u32 cppi5_hdesc_get_psflags(struct cppi5_host_desc_t *desc)
427 return (desc->hdr.pkt_info1 & CPPI5_INFO1_HDESC_PSFLGS_MASK) >>
428 CPPI5_INFO1_HDESC_PSFLGS_SHIFT;
432 * cppi5_hdesc_set_psflags - set Protocol Specific Flags in HDesc
433 * @desc: Host packet descriptor
435 static inline void cppi5_hdesc_set_psflags(struct cppi5_host_desc_t *desc,
438 desc->hdr.pkt_info1 &= ~CPPI5_INFO1_HDESC_PSFLGS_MASK;
439 desc->hdr.pkt_info1 |= (ps_flags <<
440 CPPI5_INFO1_HDESC_PSFLGS_SHIFT) &
441 CPPI5_INFO1_HDESC_PSFLGS_MASK;
445 * cppi5_hdesc_get_errflags - get Packet Type from HDesc
446 * @desc: Host packet descriptor
448 static inline u32 cppi5_hdesc_get_pkttype(struct cppi5_host_desc_t *desc)
450 return (desc->hdr.pkt_info2 & CPPI5_INFO2_HDESC_PKTTYPE_MASK) >>
451 CPPI5_INFO2_HDESC_PKTTYPE_SHIFT;
455 * cppi5_hdesc_get_errflags - set Packet Type in HDesc
456 * @desc: Host packet descriptor
457 * @pkt_type: Packet Type
459 static inline void cppi5_hdesc_set_pkttype(struct cppi5_host_desc_t *desc,
462 desc->hdr.pkt_info2 &= ~CPPI5_INFO2_HDESC_PKTTYPE_MASK;
463 desc->hdr.pkt_info2 |=
464 (pkt_type << CPPI5_INFO2_HDESC_PKTTYPE_SHIFT) &
465 CPPI5_INFO2_HDESC_PKTTYPE_MASK;
469 * cppi5_hdesc_attach_buf - attach buffer to HDesc
470 * @desc: Host packet descriptor
471 * @buf: Buffer physical address
472 * @buf_data_len: Buffer length
473 * @obuf: Original Buffer physical address
474 * @obuf_len: Original Buffer length
476 * Attaches buffer to Host Packet Descriptor
478 static 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)
483 desc->buf_info1 = buf_data_len & CPPI5_BUFINFO1_HDESC_DATA_LEN_MASK;
484 desc->org_buf_ptr = obuf;
485 desc->org_buf_len = obuf_len & CPPI5_OBUFINFO0_HDESC_BUF_LEN_MASK;
488 static inline void cppi5_hdesc_get_obuf(struct cppi5_host_desc_t *desc,
489 dma_addr_t *obuf, u32 *obuf_len)
491 *obuf = desc->org_buf_ptr;
492 *obuf_len = desc->org_buf_len & CPPI5_OBUFINFO0_HDESC_BUF_LEN_MASK;
495 static inline void cppi5_hdesc_reset_to_original(struct cppi5_host_desc_t *desc)
497 desc->buf_ptr = desc->org_buf_ptr;
498 desc->buf_info1 = desc->org_buf_len;
502 * cppi5_hdesc_link_hbdesc - link Host Buffer Descriptor to HDesc
503 * @desc: Host Packet Descriptor
504 * @buf_desc: Host Buffer Descriptor physical address
506 * add and link Host Buffer Descriptor to HDesc
508 static inline void cppi5_hdesc_link_hbdesc(struct cppi5_host_desc_t *desc,
509 dma_addr_t hbuf_desc)
511 desc->next_desc = hbuf_desc;
514 static inline dma_addr_t
515 cppi5_hdesc_get_next_hbdesc(struct cppi5_host_desc_t *desc)
517 return (dma_addr_t)desc->next_desc;
520 static inline void cppi5_hdesc_reset_hbdesc(struct cppi5_host_desc_t *desc)
522 desc->hdr = (struct cppi5_desc_hdr_t) { 0 };
527 * cppi5_hdesc_epib_present - check if EPIB present
528 * @desc_hdr: packet descriptor/TR header
530 * Returns true if EPIB present in the packet
532 static inline bool cppi5_hdesc_epib_present(struct cppi5_desc_hdr_t *desc_hdr)
534 return !!(desc_hdr->pkt_info0 & CPPI5_INFO0_HDESC_EPIB_PRESENT);
538 * cppi5_hdesc_get_psdata - Get pointer on PSDATA
539 * @desc: Host packet descriptor
541 * Returns pointer on PSDATA in HDesc.
542 * NULL - if ps_data placed at the start of data buffer.
544 static inline void *cppi5_hdesc_get_psdata(struct cppi5_host_desc_t *desc)
549 if (desc->hdr.pkt_info0 & CPPI5_INFO0_HDESC_PSINFO_LOCATION)
552 psdata_size = (desc->hdr.pkt_info0 &
553 CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK) >>
554 CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT;
559 psdata = &desc->epib;
561 if (cppi5_hdesc_epib_present(&desc->hdr))
562 psdata += CPPI5_INFO0_HDESC_EPIB_SIZE;
568 * cppi5_hdesc_get_swdata - Get pointer on swdata
569 * @desc: Host packet descriptor
571 * Returns pointer on SWDATA in HDesc.
572 * NOTE. It's caller responsibility to be sure hdesc actually has swdata.
574 static inline void *cppi5_hdesc_get_swdata(struct cppi5_host_desc_t *desc)
579 if (!(desc->hdr.pkt_info0 & CPPI5_INFO0_HDESC_PSINFO_LOCATION))
580 psdata_size = (desc->hdr.pkt_info0 &
581 CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK) >>
582 CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT;
584 swdata = &desc->epib;
586 if (cppi5_hdesc_epib_present(&desc->hdr))
587 swdata += CPPI5_INFO0_HDESC_EPIB_SIZE;
589 swdata += (psdata_size << 2);
594 /* ================================== TR ================================== */
596 #define CPPI5_TR_TYPE_SHIFT (0U)
597 #define CPPI5_TR_TYPE_MASK GENMASK(3, 0)
598 #define CPPI5_TR_STATIC BIT(4)
599 #define CPPI5_TR_WAIT BIT(5)
600 #define CPPI5_TR_EVENT_SIZE_SHIFT (6U)
601 #define CPPI5_TR_EVENT_SIZE_MASK GENMASK(7, 6)
602 #define CPPI5_TR_TRIGGER0_SHIFT (8U)
603 #define CPPI5_TR_TRIGGER0_MASK GENMASK(9, 8)
604 #define CPPI5_TR_TRIGGER0_TYPE_SHIFT (10U)
605 #define CPPI5_TR_TRIGGER0_TYPE_MASK GENMASK(11, 10)
606 #define CPPI5_TR_TRIGGER1_SHIFT (12U)
607 #define CPPI5_TR_TRIGGER1_MASK GENMASK(13, 12)
608 #define CPPI5_TR_TRIGGER1_TYPE_SHIFT (14U)
609 #define CPPI5_TR_TRIGGER1_TYPE_MASK GENMASK(15, 14)
610 #define CPPI5_TR_CMD_ID_SHIFT (16U)
611 #define CPPI5_TR_CMD_ID_MASK GENMASK(23, 16)
612 #define CPPI5_TR_CSF_FLAGS_SHIFT (24U)
613 #define CPPI5_TR_CSF_FLAGS_MASK GENMASK(31, 24)
614 #define CPPI5_TR_CSF_SA_INDIRECT BIT(0)
615 #define CPPI5_TR_CSF_DA_INDIRECT BIT(1)
616 #define CPPI5_TR_CSF_SUPR_EVT BIT(2)
617 #define CPPI5_TR_CSF_EOL_ADV_SHIFT (4U)
618 #define CPPI5_TR_CSF_EOL_ADV_MASK GENMASK(6, 4)
619 #define CPPI5_TR_CSF_EOP BIT(7)
622 * enum cppi5_tr_types - TR types
623 * @CPPI5_TR_TYPE0: One dimensional data move
624 * @CPPI5_TR_TYPE1: Two dimensional data move
625 * @CPPI5_TR_TYPE2: Three dimensional data move
626 * @CPPI5_TR_TYPE3: Four dimensional data move
627 * @CPPI5_TR_TYPE4: Four dimensional data move with data formatting
628 * @CPPI5_TR_TYPE5: Four dimensional Cache Warm
629 * @CPPI5_TR_TYPE8: Four Dimensional Block Move
630 * @CPPI5_TR_TYPE9: Four Dimensional Block Move with Repacking
631 * @CPPI5_TR_TYPE10: Two Dimensional Block Move
632 * @CPPI5_TR_TYPE11: Two Dimensional Block Move with Repacking
633 * @CPPI5_TR_TYPE15: Four Dimensional Block Move with Repacking and
636 enum cppi5_tr_types {
643 /* type6-7: Reserved */
648 /* type12-14: Reserved */
649 CPPI5_TR_TYPE15 = 15,
654 * enum cppi5_tr_event_size - TR Flags EVENT_SIZE field specifies when an event
655 * is generated for each TR.
656 * @CPPI5_TR_EVENT_SIZE_COMPLETION: When TR is complete and all status for
657 * the TR has been received
658 * @CPPI5_TR_EVENT_SIZE_ICNT1_DEC: Type 0: when the last data transaction
660 * Type 1-11: when ICNT1 is decremented
661 * @CPPI5_TR_EVENT_SIZE_ICNT2_DEC: Type 0-1,10-11: when the last data
662 * transaction is sent for the TR
663 * All other types: when ICNT2 is
665 * @CPPI5_TR_EVENT_SIZE_ICNT3_DEC: Type 0-2,10-11: when the last data
666 * transaction is sent for the TR
667 * All other types: when ICNT3 is
670 enum cppi5_tr_event_size {
671 CPPI5_TR_EVENT_SIZE_COMPLETION,
672 CPPI5_TR_EVENT_SIZE_ICNT1_DEC,
673 CPPI5_TR_EVENT_SIZE_ICNT2_DEC,
674 CPPI5_TR_EVENT_SIZE_ICNT3_DEC,
675 CPPI5_TR_EVENT_SIZE_MAX
679 * enum cppi5_tr_trigger - TR Flags TRIGGERx field specifies the type of trigger
680 * used to enable the TR to transfer data as specified
681 * by TRIGGERx_TYPE field.
682 * @CPPI5_TR_TRIGGER_NONE: No trigger
683 * @CPPI5_TR_TRIGGER_GLOBAL0: Global trigger 0
684 * @CPPI5_TR_TRIGGER_GLOBAL1: Global trigger 1
685 * @CPPI5_TR_TRIGGER_LOCAL_EVENT: Local Event
687 enum cppi5_tr_trigger {
688 CPPI5_TR_TRIGGER_NONE,
689 CPPI5_TR_TRIGGER_GLOBAL0,
690 CPPI5_TR_TRIGGER_GLOBAL1,
691 CPPI5_TR_TRIGGER_LOCAL_EVENT,
696 * enum cppi5_tr_trigger_type - TR Flags TRIGGERx_TYPE field specifies the type
697 * of data transfer that will be enabled by
698 * receiving a trigger as specified by TRIGGERx.
699 * @CPPI5_TR_TRIGGER_TYPE_ICNT1_DEC: The second inner most loop (ICNT1) will
700 * be decremented by 1
701 * @CPPI5_TR_TRIGGER_TYPE_ICNT2_DEC: The third inner most loop (ICNT2) will
702 * be decremented by 1
703 * @CPPI5_TR_TRIGGER_TYPE_ICNT3_DEC: The outer most loop (ICNT3) will be
705 * @CPPI5_TR_TRIGGER_TYPE_ALL: The entire TR will be allowed to
708 enum cppi5_tr_trigger_type {
709 CPPI5_TR_TRIGGER_TYPE_ICNT1_DEC,
710 CPPI5_TR_TRIGGER_TYPE_ICNT2_DEC,
711 CPPI5_TR_TRIGGER_TYPE_ICNT3_DEC,
712 CPPI5_TR_TRIGGER_TYPE_ALL,
713 CPPI5_TR_TRIGGER_TYPE_MAX
716 typedef u32 cppi5_tr_flags_t;
719 * struct cppi5_tr_type0_t - Type 0 (One dimensional data move) TR (16 byte)
720 * @flags: TR flags (type, triggers, event, configuration)
721 * @icnt0: Total loop iteration count for level 0 (innermost)
722 * @_reserved: Not used
723 * @addr: Starting address for the source data or destination data
725 struct cppi5_tr_type0_t {
726 cppi5_tr_flags_t flags;
730 } __aligned(16) __packed;
733 * struct cppi5_tr_type1_t - Type 1 (Two dimensional data move) TR (32 byte)
734 * @flags: TR flags (type, triggers, event, configuration)
735 * @icnt0: Total loop iteration count for level 0 (innermost)
736 * @icnt1: Total loop iteration count for level 1
737 * @addr: Starting address for the source data or destination data
738 * @dim1: Signed dimension for loop level 1
740 struct cppi5_tr_type1_t {
741 cppi5_tr_flags_t flags;
746 } __aligned(32) __packed;
749 * struct cppi5_tr_type2_t - Type 2 (Three dimensional data move) TR (32 byte)
750 * @flags: TR flags (type, triggers, event, configuration)
751 * @icnt0: Total loop iteration count for level 0 (innermost)
752 * @icnt1: Total loop iteration count for level 1
753 * @addr: Starting address for the source data or destination data
754 * @dim1: Signed dimension for loop level 1
755 * @icnt2: Total loop iteration count for level 2
756 * @_reserved: Not used
757 * @dim2: Signed dimension for loop level 2
759 struct cppi5_tr_type2_t {
760 cppi5_tr_flags_t flags;
768 } __aligned(32) __packed;
771 * struct cppi5_tr_type3_t - Type 3 (Four dimensional data move) TR (32 byte)
772 * @flags: TR flags (type, triggers, event, configuration)
773 * @icnt0: Total loop iteration count for level 0 (innermost)
774 * @icnt1: Total loop iteration count for level 1
775 * @addr: Starting address for the source data or destination data
776 * @dim1: Signed dimension for loop level 1
777 * @icnt2: Total loop iteration count for level 2
778 * @icnt3: Total loop iteration count for level 3 (outermost)
779 * @dim2: Signed dimension for loop level 2
780 * @dim3: Signed dimension for loop level 3
782 struct cppi5_tr_type3_t {
783 cppi5_tr_flags_t flags;
792 } __aligned(32) __packed;
795 * struct cppi5_tr_type15_t - Type 15 (Four Dimensional Block Copy with
796 * Repacking and Indirection Support) TR (64 byte)
797 * @flags: TR flags (type, triggers, event, configuration)
798 * @icnt0: Total loop iteration count for level 0 (innermost) for
800 * @icnt1: Total loop iteration count for level 1 for source
801 * @addr: Starting address for the source data
802 * @dim1: Signed dimension for loop level 1 for source
803 * @icnt2: Total loop iteration count for level 2 for source
804 * @icnt3: Total loop iteration count for level 3 (outermost) for
806 * @dim2: Signed dimension for loop level 2 for source
807 * @dim3: Signed dimension for loop level 3 for source
808 * @_reserved: Not used
809 * @ddim1: Signed dimension for loop level 1 for destination
810 * @daddr: Starting address for the destination data
811 * @ddim2: Signed dimension for loop level 2 for destination
812 * @ddim3: Signed dimension for loop level 3 for destination
813 * @dicnt0: Total loop iteration count for level 0 (innermost) for
815 * @dicnt1: Total loop iteration count for level 1 for destination
816 * @dicnt2: Total loop iteration count for level 2 for destination
817 * @sicnt3: Total loop iteration count for level 3 (outermost) for
820 struct cppi5_tr_type15_t {
821 cppi5_tr_flags_t flags;
839 } __aligned(64) __packed;
842 * struct cppi5_tr_resp_t - TR response record
843 * @status: Status type and info
844 * @_reserved: Not used
845 * @cmd_id: Command ID for the TR for TR identification
846 * @flags: Configuration Specific Flags
848 struct cppi5_tr_resp_t {
855 #define CPPI5_TR_RESPONSE_STATUS_TYPE_SHIFT (0U)
856 #define CPPI5_TR_RESPONSE_STATUS_TYPE_MASK GENMASK(3, 0)
857 #define CPPI5_TR_RESPONSE_STATUS_INFO_SHIFT (4U)
858 #define CPPI5_TR_RESPONSE_STATUS_INFO_MASK GENMASK(7, 4)
859 #define CPPI5_TR_RESPONSE_CMDID_SHIFT (16U)
860 #define CPPI5_TR_RESPONSE_CMDID_MASK GENMASK(23, 16)
861 #define CPPI5_TR_RESPONSE_CFG_SPECIFIC_SHIFT (24U)
862 #define CPPI5_TR_RESPONSE_CFG_SPECIFIC_MASK GENMASK(31, 24)
865 * enum cppi5_tr_resp_status_type - TR Response Status Type field is used to
866 * determine what type of status is being
868 * @CPPI5_TR_RESPONSE_STATUS_NONE: No error, completion: completed
869 * @CPPI5_TR_RESPONSE_STATUS_TRANSFER_ERR: Transfer Error, completion: none
870 * or partially completed
871 * @CPPI5_TR_RESPONSE_STATUS_ABORTED_ERR: Aborted Error, completion: none
872 * or partially completed
873 * @CPPI5_TR_RESPONSE_STATUS_SUBMISSION_ERR: Submission Error, completion:
875 * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_ERR: Unsupported Error, completion:
877 * @CPPI5_TR_RESPONSE_STATUS_TRANSFER_EXCEPTION: Transfer Exception, completion:
878 * partially completed
879 * @CPPI5_TR_RESPONSE_STATUS__TEARDOWN_FLUSH: Teardown Flush, completion: none
881 enum cppi5_tr_resp_status_type {
882 CPPI5_TR_RESPONSE_STATUS_NONE,
883 CPPI5_TR_RESPONSE_STATUS_TRANSFER_ERR,
884 CPPI5_TR_RESPONSE_STATUS_ABORTED_ERR,
885 CPPI5_TR_RESPONSE_STATUS_SUBMISSION_ERR,
886 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_ERR,
887 CPPI5_TR_RESPONSE_STATUS_TRANSFER_EXCEPTION,
888 CPPI5_TR_RESPONSE_STATUS__TEARDOWN_FLUSH,
889 CPPI5_TR_RESPONSE_STATUS_MAX
893 * enum cppi5_tr_resp_status_submission - TR Response Status field values which
894 * corresponds Submission Error
895 * @CPPI5_TR_RESPONSE_STATUS_SUBMISSION_ICNT0: ICNT0 was 0
896 * @CPPI5_TR_RESPONSE_STATUS_SUBMISSION_FIFO_FULL: Channel FIFO was full when TR
898 * @CPPI5_TR_RESPONSE_STATUS_SUBMISSION_OWN: Channel is not owned by the
901 enum cppi5_tr_resp_status_submission {
902 CPPI5_TR_RESPONSE_STATUS_SUBMISSION_ICNT0,
903 CPPI5_TR_RESPONSE_STATUS_SUBMISSION_FIFO_FULL,
904 CPPI5_TR_RESPONSE_STATUS_SUBMISSION_OWN,
905 CPPI5_TR_RESPONSE_STATUS_SUBMISSION_MAX
909 * enum cppi5_tr_resp_status_unsupported - TR Response Status field values which
910 * corresponds Unsupported Error
911 * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_TR_TYPE: TR Type not supported
912 * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_STATIC: STATIC not supported
913 * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_EOL: EOL not supported
914 * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_CFG_SPECIFIC: CONFIGURATION SPECIFIC
916 * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_AMODE: AMODE not supported
917 * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_ELTYPE: ELTYPE not supported
918 * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_DFMT: DFMT not supported
919 * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_SECTR: SECTR not supported
920 * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_AMODE_SPECIFIC: AMODE SPECIFIC field
923 enum cppi5_tr_resp_status_unsupported {
924 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_TR_TYPE,
925 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_STATIC,
926 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_EOL,
927 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_CFG_SPECIFIC,
928 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_AMODE,
929 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_ELTYPE,
930 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_DFMT,
931 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_SECTR,
932 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_AMODE_SPECIFIC,
933 CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_MAX
937 * cppi5_trdesc_calc_size - Calculate TR Descriptor size
938 * @tr_count: number of TR records
939 * @tr_size: Nominal size of TR record (max) [16, 32, 64, 128]
941 * Returns required TR Descriptor size
943 static inline size_t cppi5_trdesc_calc_size(u32 tr_count, u32 tr_size)
946 * The Size of a TR descriptor is:
947 * 1 x tr_size : the first 16 bytes is used by the packet info block +
948 * tr_count x tr_size : Transfer Request Records +
949 * tr_count x sizeof(struct cppi5_tr_resp_t) : Transfer Response Records
951 return tr_size * (tr_count + 1) +
952 sizeof(struct cppi5_tr_resp_t) * tr_count;
956 * cppi5_trdesc_init - Init TR Descriptor
957 * @desc: TR Descriptor
958 * @tr_count: number of TR records
959 * @tr_size: Nominal size of TR record (max) [16, 32, 64, 128]
960 * @reload_idx: Absolute index to jump to on the 2nd and following passes
961 * through the TR packet.
962 * @reload_count: Number of times to jump from last entry to reload_idx. 0x1ff
963 * indicates infinite looping.
967 static inline void cppi5_trdesc_init(struct cppi5_desc_hdr_t *desc_hdr,
968 u32 tr_count, u32 tr_size, u32 reload_idx,
971 desc_hdr->pkt_info0 = CPPI5_INFO0_DESC_TYPE_VAL_TR <<
972 CPPI5_INFO0_HDESC_TYPE_SHIFT;
973 desc_hdr->pkt_info0 |=
974 (reload_count << CPPI5_INFO0_TRDESC_RLDCNT_SHIFT) &
975 CPPI5_INFO0_TRDESC_RLDCNT_MASK;
976 desc_hdr->pkt_info0 |=
977 (reload_idx << CPPI5_INFO0_TRDESC_RLDIDX_SHIFT) &
978 CPPI5_INFO0_TRDESC_RLDIDX_MASK;
979 desc_hdr->pkt_info0 |= (tr_count - 1) & CPPI5_INFO0_TRDESC_LASTIDX_MASK;
981 desc_hdr->pkt_info1 |= ((ffs(tr_size >> 4) - 1) <<
982 CPPI5_INFO1_TRDESC_RECSIZE_SHIFT) &
983 CPPI5_INFO1_TRDESC_RECSIZE_MASK;
987 * cppi5_tr_init - Init TR record
988 * @flags: Pointer to the TR's flags
990 * @static_tr: TR is static
991 * @wait: Wait for TR completion before allow the next TR to start
992 * @event_size: output event generation cfg
993 * @cmd_id: TR identifier (application specifics)
997 static inline void cppi5_tr_init(cppi5_tr_flags_t *flags,
998 enum cppi5_tr_types type, bool static_tr,
999 bool wait, enum cppi5_tr_event_size event_size,
1003 *flags |= (event_size << CPPI5_TR_EVENT_SIZE_SHIFT) &
1004 CPPI5_TR_EVENT_SIZE_MASK;
1006 *flags |= (cmd_id << CPPI5_TR_CMD_ID_SHIFT) &
1007 CPPI5_TR_CMD_ID_MASK;
1009 if (static_tr && (type == CPPI5_TR_TYPE8 || type == CPPI5_TR_TYPE9))
1010 *flags |= CPPI5_TR_STATIC;
1013 *flags |= CPPI5_TR_WAIT;
1017 * cppi5_tr_set_trigger - Configure trigger0/1 and trigger0/1_type
1018 * @flags: Pointer to the TR's flags
1019 * @trigger0: trigger0 selection
1020 * @trigger0_type: type of data transfer that will be enabled by trigger0
1021 * @trigger1: trigger1 selection
1022 * @trigger1_type: type of data transfer that will be enabled by trigger1
1024 * Configure the triggers for the TR
1026 static inline void cppi5_tr_set_trigger(cppi5_tr_flags_t *flags,
1027 enum cppi5_tr_trigger trigger0,
1028 enum cppi5_tr_trigger_type trigger0_type,
1029 enum cppi5_tr_trigger trigger1,
1030 enum cppi5_tr_trigger_type trigger1_type)
1032 *flags &= ~(CPPI5_TR_TRIGGER0_MASK | CPPI5_TR_TRIGGER0_TYPE_MASK |
1033 CPPI5_TR_TRIGGER1_MASK | CPPI5_TR_TRIGGER1_TYPE_MASK);
1034 *flags |= (trigger0 << CPPI5_TR_TRIGGER0_SHIFT) &
1035 CPPI5_TR_TRIGGER0_MASK;
1036 *flags |= (trigger0_type << CPPI5_TR_TRIGGER0_TYPE_SHIFT) &
1037 CPPI5_TR_TRIGGER0_TYPE_MASK;
1039 *flags |= (trigger1 << CPPI5_TR_TRIGGER1_SHIFT) &
1040 CPPI5_TR_TRIGGER1_MASK;
1041 *flags |= (trigger1_type << CPPI5_TR_TRIGGER1_TYPE_SHIFT) &
1042 CPPI5_TR_TRIGGER1_TYPE_MASK;
1046 * cppi5_tr_cflag_set - Update the Configuration specific flags
1047 * @flags: Pointer to the TR's flags
1048 * @csf: Configuration specific flags
1050 * Set a bit in Configuration Specific Flags section of the TR flags.
1052 static inline void cppi5_tr_csf_set(cppi5_tr_flags_t *flags, u32 csf)
1054 *flags &= ~CPPI5_TR_CSF_FLAGS_MASK;
1055 *flags |= (csf << CPPI5_TR_CSF_FLAGS_SHIFT) &
1056 CPPI5_TR_CSF_FLAGS_MASK;
1059 #endif /* __TI_CPPI5_H__ */