18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * CPPI5 descriptors interface 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef __TI_CPPI5_H__ 98c2ecf20Sopenharmony_ci#define __TI_CPPI5_H__ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/bitops.h> 128c2ecf20Sopenharmony_ci#include <linux/printk.h> 138c2ecf20Sopenharmony_ci#include <linux/bug.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/** 168c2ecf20Sopenharmony_ci * struct cppi5_desc_hdr_t - Descriptor header, present in all types of 178c2ecf20Sopenharmony_ci * descriptors 188c2ecf20Sopenharmony_ci * @pkt_info0: Packet info word 0 (n/a in Buffer desc) 198c2ecf20Sopenharmony_ci * @pkt_info0: Packet info word 1 (n/a in Buffer desc) 208c2ecf20Sopenharmony_ci * @pkt_info0: Packet info word 2 (n/a in Buffer desc) 218c2ecf20Sopenharmony_ci * @src_dst_tag: Packet info word 3 (n/a in Buffer desc) 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_cistruct cppi5_desc_hdr_t { 248c2ecf20Sopenharmony_ci u32 pkt_info0; 258c2ecf20Sopenharmony_ci u32 pkt_info1; 268c2ecf20Sopenharmony_ci u32 pkt_info2; 278c2ecf20Sopenharmony_ci u32 src_dst_tag; 288c2ecf20Sopenharmony_ci} __packed; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/** 318c2ecf20Sopenharmony_ci * struct cppi5_host_desc_t - Host-mode packet and buffer descriptor definition 328c2ecf20Sopenharmony_ci * @hdr: Descriptor header 338c2ecf20Sopenharmony_ci * @next_desc: word 4/5: Linking word 348c2ecf20Sopenharmony_ci * @buf_ptr: word 6/7: Buffer pointer 358c2ecf20Sopenharmony_ci * @buf_info1: word 8: Buffer valid data length 368c2ecf20Sopenharmony_ci * @org_buf_len: word 9: Original buffer length 378c2ecf20Sopenharmony_ci * @org_buf_ptr: word 10/11: Original buffer pointer 388c2ecf20Sopenharmony_ci * @epib[0]: Extended Packet Info Data (optional, 4 words), and/or 398c2ecf20Sopenharmony_ci * Protocol Specific Data (optional, 0-128 bytes in 408c2ecf20Sopenharmony_ci * multiples of 4), and/or 418c2ecf20Sopenharmony_ci * Other Software Data (0-N bytes, optional) 428c2ecf20Sopenharmony_ci */ 438c2ecf20Sopenharmony_cistruct cppi5_host_desc_t { 448c2ecf20Sopenharmony_ci struct cppi5_desc_hdr_t hdr; 458c2ecf20Sopenharmony_ci u64 next_desc; 468c2ecf20Sopenharmony_ci u64 buf_ptr; 478c2ecf20Sopenharmony_ci u32 buf_info1; 488c2ecf20Sopenharmony_ci u32 org_buf_len; 498c2ecf20Sopenharmony_ci u64 org_buf_ptr; 508c2ecf20Sopenharmony_ci u32 epib[]; 518c2ecf20Sopenharmony_ci} __packed; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define CPPI5_DESC_MIN_ALIGN (16U) 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#define CPPI5_INFO0_HDESC_EPIB_SIZE (16U) 568c2ecf20Sopenharmony_ci#define CPPI5_INFO0_HDESC_PSDATA_MAX_SIZE (128U) 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#define CPPI5_INFO0_HDESC_TYPE_SHIFT (30U) 598c2ecf20Sopenharmony_ci#define CPPI5_INFO0_HDESC_TYPE_MASK GENMASK(31, 30) 608c2ecf20Sopenharmony_ci#define CPPI5_INFO0_DESC_TYPE_VAL_HOST (1U) 618c2ecf20Sopenharmony_ci#define CPPI5_INFO0_DESC_TYPE_VAL_MONO (2U) 628c2ecf20Sopenharmony_ci#define CPPI5_INFO0_DESC_TYPE_VAL_TR (3U) 638c2ecf20Sopenharmony_ci#define CPPI5_INFO0_HDESC_EPIB_PRESENT BIT(29) 648c2ecf20Sopenharmony_ci/* 658c2ecf20Sopenharmony_ci * Protocol Specific Words location: 668c2ecf20Sopenharmony_ci * 0 - located in the descriptor, 678c2ecf20Sopenharmony_ci * 1 = located in the SOP Buffer immediately prior to the data. 688c2ecf20Sopenharmony_ci */ 698c2ecf20Sopenharmony_ci#define CPPI5_INFO0_HDESC_PSINFO_LOCATION BIT(28) 708c2ecf20Sopenharmony_ci#define CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT (22U) 718c2ecf20Sopenharmony_ci#define CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK GENMASK(27, 22) 728c2ecf20Sopenharmony_ci#define CPPI5_INFO0_HDESC_PKTLEN_SHIFT (0) 738c2ecf20Sopenharmony_ci#define CPPI5_INFO0_HDESC_PKTLEN_MASK GENMASK(21, 0) 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#define CPPI5_INFO1_DESC_PKTERROR_SHIFT (28U) 768c2ecf20Sopenharmony_ci#define CPPI5_INFO1_DESC_PKTERROR_MASK GENMASK(31, 28) 778c2ecf20Sopenharmony_ci#define CPPI5_INFO1_HDESC_PSFLGS_SHIFT (24U) 788c2ecf20Sopenharmony_ci#define CPPI5_INFO1_HDESC_PSFLGS_MASK GENMASK(27, 24) 798c2ecf20Sopenharmony_ci#define CPPI5_INFO1_DESC_PKTID_SHIFT (14U) 808c2ecf20Sopenharmony_ci#define CPPI5_INFO1_DESC_PKTID_MASK GENMASK(23, 14) 818c2ecf20Sopenharmony_ci#define CPPI5_INFO1_DESC_FLOWID_SHIFT (0) 828c2ecf20Sopenharmony_ci#define CPPI5_INFO1_DESC_FLOWID_MASK GENMASK(13, 0) 838c2ecf20Sopenharmony_ci#define CPPI5_INFO1_DESC_FLOWID_DEFAULT CPPI5_INFO1_DESC_FLOWID_MASK 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define CPPI5_INFO2_HDESC_PKTTYPE_SHIFT (27U) 868c2ecf20Sopenharmony_ci#define CPPI5_INFO2_HDESC_PKTTYPE_MASK GENMASK(31, 27) 878c2ecf20Sopenharmony_ci/* Return Policy: 0 - Entire packet 1 - Each buffer */ 888c2ecf20Sopenharmony_ci#define CPPI5_INFO2_HDESC_RETPOLICY BIT(18) 898c2ecf20Sopenharmony_ci/* 908c2ecf20Sopenharmony_ci * Early Return: 918c2ecf20Sopenharmony_ci * 0 = desc pointers should be returned after all reads have been completed 928c2ecf20Sopenharmony_ci * 1 = desc pointers should be returned immediately upon fetching 938c2ecf20Sopenharmony_ci * the descriptor and beginning to transfer data. 948c2ecf20Sopenharmony_ci */ 958c2ecf20Sopenharmony_ci#define CPPI5_INFO2_HDESC_EARLYRET BIT(17) 968c2ecf20Sopenharmony_ci/* 978c2ecf20Sopenharmony_ci * Return Push Policy: 988c2ecf20Sopenharmony_ci * 0 = Descriptor must be returned to tail of queue 998c2ecf20Sopenharmony_ci * 1 = Descriptor must be returned to head of queue 1008c2ecf20Sopenharmony_ci */ 1018c2ecf20Sopenharmony_ci#define CPPI5_INFO2_DESC_RETPUSHPOLICY BIT(16) 1028c2ecf20Sopenharmony_ci#define CPPI5_INFO2_DESC_RETP_MASK GENMASK(18, 16) 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci#define CPPI5_INFO2_DESC_RETQ_SHIFT (0) 1058c2ecf20Sopenharmony_ci#define CPPI5_INFO2_DESC_RETQ_MASK GENMASK(15, 0) 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#define CPPI5_INFO3_DESC_SRCTAG_SHIFT (16U) 1088c2ecf20Sopenharmony_ci#define CPPI5_INFO3_DESC_SRCTAG_MASK GENMASK(31, 16) 1098c2ecf20Sopenharmony_ci#define CPPI5_INFO3_DESC_DSTTAG_SHIFT (0) 1108c2ecf20Sopenharmony_ci#define CPPI5_INFO3_DESC_DSTTAG_MASK GENMASK(15, 0) 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#define CPPI5_BUFINFO1_HDESC_DATA_LEN_SHIFT (0) 1138c2ecf20Sopenharmony_ci#define CPPI5_BUFINFO1_HDESC_DATA_LEN_MASK GENMASK(27, 0) 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci#define CPPI5_OBUFINFO0_HDESC_BUF_LEN_SHIFT (0) 1168c2ecf20Sopenharmony_ci#define CPPI5_OBUFINFO0_HDESC_BUF_LEN_MASK GENMASK(27, 0) 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci/** 1198c2ecf20Sopenharmony_ci * struct cppi5_desc_epib_t - Host Packet Descriptor Extended Packet Info Block 1208c2ecf20Sopenharmony_ci * @timestamp: word 0: application specific timestamp 1218c2ecf20Sopenharmony_ci * @sw_info0: word 1: Software Info 0 1228c2ecf20Sopenharmony_ci * @sw_info1: word 1: Software Info 1 1238c2ecf20Sopenharmony_ci * @sw_info2: word 1: Software Info 2 1248c2ecf20Sopenharmony_ci */ 1258c2ecf20Sopenharmony_cistruct cppi5_desc_epib_t { 1268c2ecf20Sopenharmony_ci u32 timestamp; /* w0: application specific timestamp */ 1278c2ecf20Sopenharmony_ci u32 sw_info0; /* w1: Software Info 0 */ 1288c2ecf20Sopenharmony_ci u32 sw_info1; /* w2: Software Info 1 */ 1298c2ecf20Sopenharmony_ci u32 sw_info2; /* w3: Software Info 2 */ 1308c2ecf20Sopenharmony_ci}; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci/** 1338c2ecf20Sopenharmony_ci * struct cppi5_monolithic_desc_t - Monolithic-mode packet descriptor 1348c2ecf20Sopenharmony_ci * @hdr: Descriptor header 1358c2ecf20Sopenharmony_ci * @epib[0]: Extended Packet Info Data (optional, 4 words), and/or 1368c2ecf20Sopenharmony_ci * Protocol Specific Data (optional, 0-128 bytes in 1378c2ecf20Sopenharmony_ci * multiples of 4), and/or 1388c2ecf20Sopenharmony_ci * Other Software Data (0-N bytes, optional) 1398c2ecf20Sopenharmony_ci */ 1408c2ecf20Sopenharmony_cistruct cppi5_monolithic_desc_t { 1418c2ecf20Sopenharmony_ci struct cppi5_desc_hdr_t hdr; 1428c2ecf20Sopenharmony_ci u32 epib[]; 1438c2ecf20Sopenharmony_ci}; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci#define CPPI5_INFO2_MDESC_DATA_OFFSET_SHIFT (18U) 1468c2ecf20Sopenharmony_ci#define CPPI5_INFO2_MDESC_DATA_OFFSET_MASK GENMASK(26, 18) 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/* 1498c2ecf20Sopenharmony_ci * Reload Count: 1508c2ecf20Sopenharmony_ci * 0 = Finish the packet and place the descriptor back on the return queue 1518c2ecf20Sopenharmony_ci * 1-0x1ff = Vector to the Reload Index and resume processing 1528c2ecf20Sopenharmony_ci * 0x1ff indicates perpetual loop, infinite reload until the channel is stopped 1538c2ecf20Sopenharmony_ci */ 1548c2ecf20Sopenharmony_ci#define CPPI5_INFO0_TRDESC_RLDCNT_SHIFT (20U) 1558c2ecf20Sopenharmony_ci#define CPPI5_INFO0_TRDESC_RLDCNT_MASK GENMASK(28, 20) 1568c2ecf20Sopenharmony_ci#define CPPI5_INFO0_TRDESC_RLDCNT_MAX (0x1ff) 1578c2ecf20Sopenharmony_ci#define CPPI5_INFO0_TRDESC_RLDCNT_INFINITE CPPI5_INFO0_TRDESC_RLDCNT_MAX 1588c2ecf20Sopenharmony_ci#define CPPI5_INFO0_TRDESC_RLDIDX_SHIFT (14U) 1598c2ecf20Sopenharmony_ci#define CPPI5_INFO0_TRDESC_RLDIDX_MASK GENMASK(19, 14) 1608c2ecf20Sopenharmony_ci#define CPPI5_INFO0_TRDESC_RLDIDX_MAX (0x3f) 1618c2ecf20Sopenharmony_ci#define CPPI5_INFO0_TRDESC_LASTIDX_SHIFT (0) 1628c2ecf20Sopenharmony_ci#define CPPI5_INFO0_TRDESC_LASTIDX_MASK GENMASK(13, 0) 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci#define CPPI5_INFO1_TRDESC_RECSIZE_SHIFT (24U) 1658c2ecf20Sopenharmony_ci#define CPPI5_INFO1_TRDESC_RECSIZE_MASK GENMASK(26, 24) 1668c2ecf20Sopenharmony_ci#define CPPI5_INFO1_TRDESC_RECSIZE_VAL_16B (0) 1678c2ecf20Sopenharmony_ci#define CPPI5_INFO1_TRDESC_RECSIZE_VAL_32B (1U) 1688c2ecf20Sopenharmony_ci#define CPPI5_INFO1_TRDESC_RECSIZE_VAL_64B (2U) 1698c2ecf20Sopenharmony_ci#define CPPI5_INFO1_TRDESC_RECSIZE_VAL_128B (3U) 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_cistatic inline void cppi5_desc_dump(void *desc, u32 size) 1728c2ecf20Sopenharmony_ci{ 1738c2ecf20Sopenharmony_ci print_hex_dump(KERN_ERR, "dump udmap_desc: ", DUMP_PREFIX_NONE, 1748c2ecf20Sopenharmony_ci 32, 4, desc, size, false); 1758c2ecf20Sopenharmony_ci} 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci#define CPPI5_TDCM_MARKER (0x1) 1788c2ecf20Sopenharmony_ci/** 1798c2ecf20Sopenharmony_ci * cppi5_desc_is_tdcm - check if the paddr indicates Teardown Complete Message 1808c2ecf20Sopenharmony_ci * @paddr: Physical address of the packet popped from the ring 1818c2ecf20Sopenharmony_ci * 1828c2ecf20Sopenharmony_ci * Returns true if the address indicates TDCM 1838c2ecf20Sopenharmony_ci */ 1848c2ecf20Sopenharmony_cistatic inline bool cppi5_desc_is_tdcm(dma_addr_t paddr) 1858c2ecf20Sopenharmony_ci{ 1868c2ecf20Sopenharmony_ci return (paddr & CPPI5_TDCM_MARKER) ? true : false; 1878c2ecf20Sopenharmony_ci} 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci/** 1908c2ecf20Sopenharmony_ci * cppi5_desc_get_type - get descriptor type 1918c2ecf20Sopenharmony_ci * @desc_hdr: packet descriptor/TR header 1928c2ecf20Sopenharmony_ci * 1938c2ecf20Sopenharmony_ci * Returns descriptor type: 1948c2ecf20Sopenharmony_ci * CPPI5_INFO0_DESC_TYPE_VAL_HOST 1958c2ecf20Sopenharmony_ci * CPPI5_INFO0_DESC_TYPE_VAL_MONO 1968c2ecf20Sopenharmony_ci * CPPI5_INFO0_DESC_TYPE_VAL_TR 1978c2ecf20Sopenharmony_ci */ 1988c2ecf20Sopenharmony_cistatic inline u32 cppi5_desc_get_type(struct cppi5_desc_hdr_t *desc_hdr) 1998c2ecf20Sopenharmony_ci{ 2008c2ecf20Sopenharmony_ci return (desc_hdr->pkt_info0 & CPPI5_INFO0_HDESC_TYPE_MASK) >> 2018c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_TYPE_SHIFT; 2028c2ecf20Sopenharmony_ci} 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci/** 2058c2ecf20Sopenharmony_ci * cppi5_desc_get_errflags - get Error Flags from Desc 2068c2ecf20Sopenharmony_ci * @desc_hdr: packet/TR descriptor header 2078c2ecf20Sopenharmony_ci * 2088c2ecf20Sopenharmony_ci * Returns Error Flags from Packet/TR Descriptor 2098c2ecf20Sopenharmony_ci */ 2108c2ecf20Sopenharmony_cistatic inline u32 cppi5_desc_get_errflags(struct cppi5_desc_hdr_t *desc_hdr) 2118c2ecf20Sopenharmony_ci{ 2128c2ecf20Sopenharmony_ci return (desc_hdr->pkt_info1 & CPPI5_INFO1_DESC_PKTERROR_MASK) >> 2138c2ecf20Sopenharmony_ci CPPI5_INFO1_DESC_PKTERROR_SHIFT; 2148c2ecf20Sopenharmony_ci} 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci/** 2178c2ecf20Sopenharmony_ci * cppi5_desc_get_pktids - get Packet and Flow ids from Desc 2188c2ecf20Sopenharmony_ci * @desc_hdr: packet/TR descriptor header 2198c2ecf20Sopenharmony_ci * @pkt_id: Packet ID 2208c2ecf20Sopenharmony_ci * @flow_id: Flow ID 2218c2ecf20Sopenharmony_ci * 2228c2ecf20Sopenharmony_ci * Returns Packet and Flow ids from packet/TR descriptor 2238c2ecf20Sopenharmony_ci */ 2248c2ecf20Sopenharmony_cistatic inline void cppi5_desc_get_pktids(struct cppi5_desc_hdr_t *desc_hdr, 2258c2ecf20Sopenharmony_ci u32 *pkt_id, u32 *flow_id) 2268c2ecf20Sopenharmony_ci{ 2278c2ecf20Sopenharmony_ci *pkt_id = (desc_hdr->pkt_info1 & CPPI5_INFO1_DESC_PKTID_MASK) >> 2288c2ecf20Sopenharmony_ci CPPI5_INFO1_DESC_PKTID_SHIFT; 2298c2ecf20Sopenharmony_ci *flow_id = (desc_hdr->pkt_info1 & CPPI5_INFO1_DESC_FLOWID_MASK) >> 2308c2ecf20Sopenharmony_ci CPPI5_INFO1_DESC_FLOWID_SHIFT; 2318c2ecf20Sopenharmony_ci} 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci/** 2348c2ecf20Sopenharmony_ci * cppi5_desc_set_pktids - set Packet and Flow ids in Desc 2358c2ecf20Sopenharmony_ci * @desc_hdr: packet/TR descriptor header 2368c2ecf20Sopenharmony_ci * @pkt_id: Packet ID 2378c2ecf20Sopenharmony_ci * @flow_id: Flow ID 2388c2ecf20Sopenharmony_ci */ 2398c2ecf20Sopenharmony_cistatic inline void cppi5_desc_set_pktids(struct cppi5_desc_hdr_t *desc_hdr, 2408c2ecf20Sopenharmony_ci u32 pkt_id, u32 flow_id) 2418c2ecf20Sopenharmony_ci{ 2428c2ecf20Sopenharmony_ci desc_hdr->pkt_info1 &= ~(CPPI5_INFO1_DESC_PKTID_MASK | 2438c2ecf20Sopenharmony_ci CPPI5_INFO1_DESC_FLOWID_MASK); 2448c2ecf20Sopenharmony_ci desc_hdr->pkt_info1 |= (pkt_id << CPPI5_INFO1_DESC_PKTID_SHIFT) & 2458c2ecf20Sopenharmony_ci CPPI5_INFO1_DESC_PKTID_MASK; 2468c2ecf20Sopenharmony_ci desc_hdr->pkt_info1 |= (flow_id << CPPI5_INFO1_DESC_FLOWID_SHIFT) & 2478c2ecf20Sopenharmony_ci CPPI5_INFO1_DESC_FLOWID_MASK; 2488c2ecf20Sopenharmony_ci} 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci/** 2518c2ecf20Sopenharmony_ci * cppi5_desc_set_retpolicy - set Packet Return Policy in Desc 2528c2ecf20Sopenharmony_ci * @desc_hdr: packet/TR descriptor header 2538c2ecf20Sopenharmony_ci * @flags: fags, supported values 2548c2ecf20Sopenharmony_ci * CPPI5_INFO2_HDESC_RETPOLICY 2558c2ecf20Sopenharmony_ci * CPPI5_INFO2_HDESC_EARLYRET 2568c2ecf20Sopenharmony_ci * CPPI5_INFO2_DESC_RETPUSHPOLICY 2578c2ecf20Sopenharmony_ci * @return_ring_id: Packet Return Queue/Ring id, value 0xFFFF reserved 2588c2ecf20Sopenharmony_ci */ 2598c2ecf20Sopenharmony_cistatic inline void cppi5_desc_set_retpolicy(struct cppi5_desc_hdr_t *desc_hdr, 2608c2ecf20Sopenharmony_ci u32 flags, u32 return_ring_id) 2618c2ecf20Sopenharmony_ci{ 2628c2ecf20Sopenharmony_ci desc_hdr->pkt_info2 &= ~(CPPI5_INFO2_DESC_RETP_MASK | 2638c2ecf20Sopenharmony_ci CPPI5_INFO2_DESC_RETQ_MASK); 2648c2ecf20Sopenharmony_ci desc_hdr->pkt_info2 |= flags & CPPI5_INFO2_DESC_RETP_MASK; 2658c2ecf20Sopenharmony_ci desc_hdr->pkt_info2 |= return_ring_id & CPPI5_INFO2_DESC_RETQ_MASK; 2668c2ecf20Sopenharmony_ci} 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci/** 2698c2ecf20Sopenharmony_ci * cppi5_desc_get_tags_ids - get Packet Src/Dst Tags from Desc 2708c2ecf20Sopenharmony_ci * @desc_hdr: packet/TR descriptor header 2718c2ecf20Sopenharmony_ci * @src_tag_id: Source Tag 2728c2ecf20Sopenharmony_ci * @dst_tag_id: Dest Tag 2738c2ecf20Sopenharmony_ci * 2748c2ecf20Sopenharmony_ci * Returns Packet Src/Dst Tags from packet/TR descriptor 2758c2ecf20Sopenharmony_ci */ 2768c2ecf20Sopenharmony_cistatic inline void cppi5_desc_get_tags_ids(struct cppi5_desc_hdr_t *desc_hdr, 2778c2ecf20Sopenharmony_ci u32 *src_tag_id, u32 *dst_tag_id) 2788c2ecf20Sopenharmony_ci{ 2798c2ecf20Sopenharmony_ci if (src_tag_id) 2808c2ecf20Sopenharmony_ci *src_tag_id = (desc_hdr->src_dst_tag & 2818c2ecf20Sopenharmony_ci CPPI5_INFO3_DESC_SRCTAG_MASK) >> 2828c2ecf20Sopenharmony_ci CPPI5_INFO3_DESC_SRCTAG_SHIFT; 2838c2ecf20Sopenharmony_ci if (dst_tag_id) 2848c2ecf20Sopenharmony_ci *dst_tag_id = desc_hdr->src_dst_tag & 2858c2ecf20Sopenharmony_ci CPPI5_INFO3_DESC_DSTTAG_MASK; 2868c2ecf20Sopenharmony_ci} 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci/** 2898c2ecf20Sopenharmony_ci * cppi5_desc_set_tags_ids - set Packet Src/Dst Tags in HDesc 2908c2ecf20Sopenharmony_ci * @desc_hdr: packet/TR descriptor header 2918c2ecf20Sopenharmony_ci * @src_tag_id: Source Tag 2928c2ecf20Sopenharmony_ci * @dst_tag_id: Dest Tag 2938c2ecf20Sopenharmony_ci * 2948c2ecf20Sopenharmony_ci * Returns Packet Src/Dst Tags from packet/TR descriptor 2958c2ecf20Sopenharmony_ci */ 2968c2ecf20Sopenharmony_cistatic inline void cppi5_desc_set_tags_ids(struct cppi5_desc_hdr_t *desc_hdr, 2978c2ecf20Sopenharmony_ci u32 src_tag_id, u32 dst_tag_id) 2988c2ecf20Sopenharmony_ci{ 2998c2ecf20Sopenharmony_ci desc_hdr->src_dst_tag = (src_tag_id << CPPI5_INFO3_DESC_SRCTAG_SHIFT) & 3008c2ecf20Sopenharmony_ci CPPI5_INFO3_DESC_SRCTAG_MASK; 3018c2ecf20Sopenharmony_ci desc_hdr->src_dst_tag |= dst_tag_id & CPPI5_INFO3_DESC_DSTTAG_MASK; 3028c2ecf20Sopenharmony_ci} 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci/** 3058c2ecf20Sopenharmony_ci * cppi5_hdesc_calc_size - Calculate Host Packet Descriptor size 3068c2ecf20Sopenharmony_ci * @epib: is EPIB present 3078c2ecf20Sopenharmony_ci * @psdata_size: PSDATA size 3088c2ecf20Sopenharmony_ci * @sw_data_size: SWDATA size 3098c2ecf20Sopenharmony_ci * 3108c2ecf20Sopenharmony_ci * Returns required Host Packet Descriptor size 3118c2ecf20Sopenharmony_ci * 0 - if PSDATA > CPPI5_INFO0_HDESC_PSDATA_MAX_SIZE 3128c2ecf20Sopenharmony_ci */ 3138c2ecf20Sopenharmony_cistatic inline u32 cppi5_hdesc_calc_size(bool epib, u32 psdata_size, 3148c2ecf20Sopenharmony_ci u32 sw_data_size) 3158c2ecf20Sopenharmony_ci{ 3168c2ecf20Sopenharmony_ci u32 desc_size; 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci if (psdata_size > CPPI5_INFO0_HDESC_PSDATA_MAX_SIZE) 3198c2ecf20Sopenharmony_ci return 0; 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci desc_size = sizeof(struct cppi5_host_desc_t) + psdata_size + 3228c2ecf20Sopenharmony_ci sw_data_size; 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci if (epib) 3258c2ecf20Sopenharmony_ci desc_size += CPPI5_INFO0_HDESC_EPIB_SIZE; 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci return ALIGN(desc_size, CPPI5_DESC_MIN_ALIGN); 3288c2ecf20Sopenharmony_ci} 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci/** 3318c2ecf20Sopenharmony_ci * cppi5_hdesc_init - Init Host Packet Descriptor size 3328c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 3338c2ecf20Sopenharmony_ci * @flags: supported values 3348c2ecf20Sopenharmony_ci * CPPI5_INFO0_HDESC_EPIB_PRESENT 3358c2ecf20Sopenharmony_ci * CPPI5_INFO0_HDESC_PSINFO_LOCATION 3368c2ecf20Sopenharmony_ci * @psdata_size: PSDATA size 3378c2ecf20Sopenharmony_ci * 3388c2ecf20Sopenharmony_ci * Returns required Host Packet Descriptor size 3398c2ecf20Sopenharmony_ci * 0 - if PSDATA > CPPI5_INFO0_HDESC_PSDATA_MAX_SIZE 3408c2ecf20Sopenharmony_ci */ 3418c2ecf20Sopenharmony_cistatic inline void cppi5_hdesc_init(struct cppi5_host_desc_t *desc, u32 flags, 3428c2ecf20Sopenharmony_ci u32 psdata_size) 3438c2ecf20Sopenharmony_ci{ 3448c2ecf20Sopenharmony_ci desc->hdr.pkt_info0 = (CPPI5_INFO0_DESC_TYPE_VAL_HOST << 3458c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_TYPE_SHIFT) | (flags); 3468c2ecf20Sopenharmony_ci desc->hdr.pkt_info0 |= ((psdata_size >> 2) << 3478c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT) & 3488c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK; 3498c2ecf20Sopenharmony_ci desc->next_desc = 0; 3508c2ecf20Sopenharmony_ci} 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci/** 3538c2ecf20Sopenharmony_ci * cppi5_hdesc_update_flags - Replace descriptor flags 3548c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 3558c2ecf20Sopenharmony_ci * @flags: supported values 3568c2ecf20Sopenharmony_ci * CPPI5_INFO0_HDESC_EPIB_PRESENT 3578c2ecf20Sopenharmony_ci * CPPI5_INFO0_HDESC_PSINFO_LOCATION 3588c2ecf20Sopenharmony_ci */ 3598c2ecf20Sopenharmony_cistatic inline void cppi5_hdesc_update_flags(struct cppi5_host_desc_t *desc, 3608c2ecf20Sopenharmony_ci u32 flags) 3618c2ecf20Sopenharmony_ci{ 3628c2ecf20Sopenharmony_ci desc->hdr.pkt_info0 &= ~(CPPI5_INFO0_HDESC_EPIB_PRESENT | 3638c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_PSINFO_LOCATION); 3648c2ecf20Sopenharmony_ci desc->hdr.pkt_info0 |= flags; 3658c2ecf20Sopenharmony_ci} 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci/** 3688c2ecf20Sopenharmony_ci * cppi5_hdesc_update_psdata_size - Replace PSdata size 3698c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 3708c2ecf20Sopenharmony_ci * @psdata_size: PSDATA size 3718c2ecf20Sopenharmony_ci */ 3728c2ecf20Sopenharmony_cistatic inline void 3738c2ecf20Sopenharmony_cicppi5_hdesc_update_psdata_size(struct cppi5_host_desc_t *desc, u32 psdata_size) 3748c2ecf20Sopenharmony_ci{ 3758c2ecf20Sopenharmony_ci desc->hdr.pkt_info0 &= ~CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK; 3768c2ecf20Sopenharmony_ci desc->hdr.pkt_info0 |= ((psdata_size >> 2) << 3778c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT) & 3788c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK; 3798c2ecf20Sopenharmony_ci} 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci/** 3828c2ecf20Sopenharmony_ci * cppi5_hdesc_get_psdata_size - get PSdata size in bytes 3838c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 3848c2ecf20Sopenharmony_ci */ 3858c2ecf20Sopenharmony_cistatic inline u32 cppi5_hdesc_get_psdata_size(struct cppi5_host_desc_t *desc) 3868c2ecf20Sopenharmony_ci{ 3878c2ecf20Sopenharmony_ci u32 psdata_size = 0; 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci if (!(desc->hdr.pkt_info0 & CPPI5_INFO0_HDESC_PSINFO_LOCATION)) 3908c2ecf20Sopenharmony_ci psdata_size = (desc->hdr.pkt_info0 & 3918c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK) >> 3928c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT; 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci return (psdata_size << 2); 3958c2ecf20Sopenharmony_ci} 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci/** 3988c2ecf20Sopenharmony_ci * cppi5_hdesc_get_pktlen - get Packet Length from HDesc 3998c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 4008c2ecf20Sopenharmony_ci * 4018c2ecf20Sopenharmony_ci * Returns Packet Length from Host Packet Descriptor 4028c2ecf20Sopenharmony_ci */ 4038c2ecf20Sopenharmony_cistatic inline u32 cppi5_hdesc_get_pktlen(struct cppi5_host_desc_t *desc) 4048c2ecf20Sopenharmony_ci{ 4058c2ecf20Sopenharmony_ci return (desc->hdr.pkt_info0 & CPPI5_INFO0_HDESC_PKTLEN_MASK); 4068c2ecf20Sopenharmony_ci} 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci/** 4098c2ecf20Sopenharmony_ci * cppi5_hdesc_set_pktlen - set Packet Length in HDesc 4108c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 4118c2ecf20Sopenharmony_ci */ 4128c2ecf20Sopenharmony_cistatic inline void cppi5_hdesc_set_pktlen(struct cppi5_host_desc_t *desc, 4138c2ecf20Sopenharmony_ci u32 pkt_len) 4148c2ecf20Sopenharmony_ci{ 4158c2ecf20Sopenharmony_ci desc->hdr.pkt_info0 &= ~CPPI5_INFO0_HDESC_PKTLEN_MASK; 4168c2ecf20Sopenharmony_ci desc->hdr.pkt_info0 |= (pkt_len & CPPI5_INFO0_HDESC_PKTLEN_MASK); 4178c2ecf20Sopenharmony_ci} 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci/** 4208c2ecf20Sopenharmony_ci * cppi5_hdesc_get_psflags - get Protocol Specific Flags from HDesc 4218c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 4228c2ecf20Sopenharmony_ci * 4238c2ecf20Sopenharmony_ci * Returns Protocol Specific Flags from Host Packet Descriptor 4248c2ecf20Sopenharmony_ci */ 4258c2ecf20Sopenharmony_cistatic inline u32 cppi5_hdesc_get_psflags(struct cppi5_host_desc_t *desc) 4268c2ecf20Sopenharmony_ci{ 4278c2ecf20Sopenharmony_ci return (desc->hdr.pkt_info1 & CPPI5_INFO1_HDESC_PSFLGS_MASK) >> 4288c2ecf20Sopenharmony_ci CPPI5_INFO1_HDESC_PSFLGS_SHIFT; 4298c2ecf20Sopenharmony_ci} 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci/** 4328c2ecf20Sopenharmony_ci * cppi5_hdesc_set_psflags - set Protocol Specific Flags in HDesc 4338c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 4348c2ecf20Sopenharmony_ci */ 4358c2ecf20Sopenharmony_cistatic inline void cppi5_hdesc_set_psflags(struct cppi5_host_desc_t *desc, 4368c2ecf20Sopenharmony_ci u32 ps_flags) 4378c2ecf20Sopenharmony_ci{ 4388c2ecf20Sopenharmony_ci desc->hdr.pkt_info1 &= ~CPPI5_INFO1_HDESC_PSFLGS_MASK; 4398c2ecf20Sopenharmony_ci desc->hdr.pkt_info1 |= (ps_flags << 4408c2ecf20Sopenharmony_ci CPPI5_INFO1_HDESC_PSFLGS_SHIFT) & 4418c2ecf20Sopenharmony_ci CPPI5_INFO1_HDESC_PSFLGS_MASK; 4428c2ecf20Sopenharmony_ci} 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci/** 4458c2ecf20Sopenharmony_ci * cppi5_hdesc_get_errflags - get Packet Type from HDesc 4468c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 4478c2ecf20Sopenharmony_ci */ 4488c2ecf20Sopenharmony_cistatic inline u32 cppi5_hdesc_get_pkttype(struct cppi5_host_desc_t *desc) 4498c2ecf20Sopenharmony_ci{ 4508c2ecf20Sopenharmony_ci return (desc->hdr.pkt_info2 & CPPI5_INFO2_HDESC_PKTTYPE_MASK) >> 4518c2ecf20Sopenharmony_ci CPPI5_INFO2_HDESC_PKTTYPE_SHIFT; 4528c2ecf20Sopenharmony_ci} 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci/** 4558c2ecf20Sopenharmony_ci * cppi5_hdesc_get_errflags - set Packet Type in HDesc 4568c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 4578c2ecf20Sopenharmony_ci * @pkt_type: Packet Type 4588c2ecf20Sopenharmony_ci */ 4598c2ecf20Sopenharmony_cistatic inline void cppi5_hdesc_set_pkttype(struct cppi5_host_desc_t *desc, 4608c2ecf20Sopenharmony_ci u32 pkt_type) 4618c2ecf20Sopenharmony_ci{ 4628c2ecf20Sopenharmony_ci desc->hdr.pkt_info2 &= ~CPPI5_INFO2_HDESC_PKTTYPE_MASK; 4638c2ecf20Sopenharmony_ci desc->hdr.pkt_info2 |= 4648c2ecf20Sopenharmony_ci (pkt_type << CPPI5_INFO2_HDESC_PKTTYPE_SHIFT) & 4658c2ecf20Sopenharmony_ci CPPI5_INFO2_HDESC_PKTTYPE_MASK; 4668c2ecf20Sopenharmony_ci} 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci/** 4698c2ecf20Sopenharmony_ci * cppi5_hdesc_attach_buf - attach buffer to HDesc 4708c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 4718c2ecf20Sopenharmony_ci * @buf: Buffer physical address 4728c2ecf20Sopenharmony_ci * @buf_data_len: Buffer length 4738c2ecf20Sopenharmony_ci * @obuf: Original Buffer physical address 4748c2ecf20Sopenharmony_ci * @obuf_len: Original Buffer length 4758c2ecf20Sopenharmony_ci * 4768c2ecf20Sopenharmony_ci * Attaches buffer to Host Packet Descriptor 4778c2ecf20Sopenharmony_ci */ 4788c2ecf20Sopenharmony_cistatic inline void cppi5_hdesc_attach_buf(struct cppi5_host_desc_t *desc, 4798c2ecf20Sopenharmony_ci dma_addr_t buf, u32 buf_data_len, 4808c2ecf20Sopenharmony_ci dma_addr_t obuf, u32 obuf_len) 4818c2ecf20Sopenharmony_ci{ 4828c2ecf20Sopenharmony_ci desc->buf_ptr = buf; 4838c2ecf20Sopenharmony_ci desc->buf_info1 = buf_data_len & CPPI5_BUFINFO1_HDESC_DATA_LEN_MASK; 4848c2ecf20Sopenharmony_ci desc->org_buf_ptr = obuf; 4858c2ecf20Sopenharmony_ci desc->org_buf_len = obuf_len & CPPI5_OBUFINFO0_HDESC_BUF_LEN_MASK; 4868c2ecf20Sopenharmony_ci} 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_cistatic inline void cppi5_hdesc_get_obuf(struct cppi5_host_desc_t *desc, 4898c2ecf20Sopenharmony_ci dma_addr_t *obuf, u32 *obuf_len) 4908c2ecf20Sopenharmony_ci{ 4918c2ecf20Sopenharmony_ci *obuf = desc->org_buf_ptr; 4928c2ecf20Sopenharmony_ci *obuf_len = desc->org_buf_len & CPPI5_OBUFINFO0_HDESC_BUF_LEN_MASK; 4938c2ecf20Sopenharmony_ci} 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_cistatic inline void cppi5_hdesc_reset_to_original(struct cppi5_host_desc_t *desc) 4968c2ecf20Sopenharmony_ci{ 4978c2ecf20Sopenharmony_ci desc->buf_ptr = desc->org_buf_ptr; 4988c2ecf20Sopenharmony_ci desc->buf_info1 = desc->org_buf_len; 4998c2ecf20Sopenharmony_ci} 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci/** 5028c2ecf20Sopenharmony_ci * cppi5_hdesc_link_hbdesc - link Host Buffer Descriptor to HDesc 5038c2ecf20Sopenharmony_ci * @desc: Host Packet Descriptor 5048c2ecf20Sopenharmony_ci * @buf_desc: Host Buffer Descriptor physical address 5058c2ecf20Sopenharmony_ci * 5068c2ecf20Sopenharmony_ci * add and link Host Buffer Descriptor to HDesc 5078c2ecf20Sopenharmony_ci */ 5088c2ecf20Sopenharmony_cistatic inline void cppi5_hdesc_link_hbdesc(struct cppi5_host_desc_t *desc, 5098c2ecf20Sopenharmony_ci dma_addr_t hbuf_desc) 5108c2ecf20Sopenharmony_ci{ 5118c2ecf20Sopenharmony_ci desc->next_desc = hbuf_desc; 5128c2ecf20Sopenharmony_ci} 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_cistatic inline dma_addr_t 5158c2ecf20Sopenharmony_cicppi5_hdesc_get_next_hbdesc(struct cppi5_host_desc_t *desc) 5168c2ecf20Sopenharmony_ci{ 5178c2ecf20Sopenharmony_ci return (dma_addr_t)desc->next_desc; 5188c2ecf20Sopenharmony_ci} 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_cistatic inline void cppi5_hdesc_reset_hbdesc(struct cppi5_host_desc_t *desc) 5218c2ecf20Sopenharmony_ci{ 5228c2ecf20Sopenharmony_ci desc->hdr = (struct cppi5_desc_hdr_t) { 0 }; 5238c2ecf20Sopenharmony_ci desc->next_desc = 0; 5248c2ecf20Sopenharmony_ci} 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci/** 5278c2ecf20Sopenharmony_ci * cppi5_hdesc_epib_present - check if EPIB present 5288c2ecf20Sopenharmony_ci * @desc_hdr: packet descriptor/TR header 5298c2ecf20Sopenharmony_ci * 5308c2ecf20Sopenharmony_ci * Returns true if EPIB present in the packet 5318c2ecf20Sopenharmony_ci */ 5328c2ecf20Sopenharmony_cistatic inline bool cppi5_hdesc_epib_present(struct cppi5_desc_hdr_t *desc_hdr) 5338c2ecf20Sopenharmony_ci{ 5348c2ecf20Sopenharmony_ci return !!(desc_hdr->pkt_info0 & CPPI5_INFO0_HDESC_EPIB_PRESENT); 5358c2ecf20Sopenharmony_ci} 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci/** 5388c2ecf20Sopenharmony_ci * cppi5_hdesc_get_psdata - Get pointer on PSDATA 5398c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 5408c2ecf20Sopenharmony_ci * 5418c2ecf20Sopenharmony_ci * Returns pointer on PSDATA in HDesc. 5428c2ecf20Sopenharmony_ci * NULL - if ps_data placed at the start of data buffer. 5438c2ecf20Sopenharmony_ci */ 5448c2ecf20Sopenharmony_cistatic inline void *cppi5_hdesc_get_psdata(struct cppi5_host_desc_t *desc) 5458c2ecf20Sopenharmony_ci{ 5468c2ecf20Sopenharmony_ci u32 psdata_size; 5478c2ecf20Sopenharmony_ci void *psdata; 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci if (desc->hdr.pkt_info0 & CPPI5_INFO0_HDESC_PSINFO_LOCATION) 5508c2ecf20Sopenharmony_ci return NULL; 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci psdata_size = (desc->hdr.pkt_info0 & 5538c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK) >> 5548c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT; 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci if (!psdata_size) 5578c2ecf20Sopenharmony_ci return NULL; 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci psdata = &desc->epib; 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci if (cppi5_hdesc_epib_present(&desc->hdr)) 5628c2ecf20Sopenharmony_ci psdata += CPPI5_INFO0_HDESC_EPIB_SIZE; 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci return psdata; 5658c2ecf20Sopenharmony_ci} 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci/** 5688c2ecf20Sopenharmony_ci * cppi5_hdesc_get_swdata - Get pointer on swdata 5698c2ecf20Sopenharmony_ci * @desc: Host packet descriptor 5708c2ecf20Sopenharmony_ci * 5718c2ecf20Sopenharmony_ci * Returns pointer on SWDATA in HDesc. 5728c2ecf20Sopenharmony_ci * NOTE. It's caller responsibility to be sure hdesc actually has swdata. 5738c2ecf20Sopenharmony_ci */ 5748c2ecf20Sopenharmony_cistatic inline void *cppi5_hdesc_get_swdata(struct cppi5_host_desc_t *desc) 5758c2ecf20Sopenharmony_ci{ 5768c2ecf20Sopenharmony_ci u32 psdata_size = 0; 5778c2ecf20Sopenharmony_ci void *swdata; 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci if (!(desc->hdr.pkt_info0 & CPPI5_INFO0_HDESC_PSINFO_LOCATION)) 5808c2ecf20Sopenharmony_ci psdata_size = (desc->hdr.pkt_info0 & 5818c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_PSINFO_SIZE_MASK) >> 5828c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_PSINFO_SIZE_SHIFT; 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci swdata = &desc->epib; 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci if (cppi5_hdesc_epib_present(&desc->hdr)) 5878c2ecf20Sopenharmony_ci swdata += CPPI5_INFO0_HDESC_EPIB_SIZE; 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci swdata += (psdata_size << 2); 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci return swdata; 5928c2ecf20Sopenharmony_ci} 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci/* ================================== TR ================================== */ 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci#define CPPI5_TR_TYPE_SHIFT (0U) 5978c2ecf20Sopenharmony_ci#define CPPI5_TR_TYPE_MASK GENMASK(3, 0) 5988c2ecf20Sopenharmony_ci#define CPPI5_TR_STATIC BIT(4) 5998c2ecf20Sopenharmony_ci#define CPPI5_TR_WAIT BIT(5) 6008c2ecf20Sopenharmony_ci#define CPPI5_TR_EVENT_SIZE_SHIFT (6U) 6018c2ecf20Sopenharmony_ci#define CPPI5_TR_EVENT_SIZE_MASK GENMASK(7, 6) 6028c2ecf20Sopenharmony_ci#define CPPI5_TR_TRIGGER0_SHIFT (8U) 6038c2ecf20Sopenharmony_ci#define CPPI5_TR_TRIGGER0_MASK GENMASK(9, 8) 6048c2ecf20Sopenharmony_ci#define CPPI5_TR_TRIGGER0_TYPE_SHIFT (10U) 6058c2ecf20Sopenharmony_ci#define CPPI5_TR_TRIGGER0_TYPE_MASK GENMASK(11, 10) 6068c2ecf20Sopenharmony_ci#define CPPI5_TR_TRIGGER1_SHIFT (12U) 6078c2ecf20Sopenharmony_ci#define CPPI5_TR_TRIGGER1_MASK GENMASK(13, 12) 6088c2ecf20Sopenharmony_ci#define CPPI5_TR_TRIGGER1_TYPE_SHIFT (14U) 6098c2ecf20Sopenharmony_ci#define CPPI5_TR_TRIGGER1_TYPE_MASK GENMASK(15, 14) 6108c2ecf20Sopenharmony_ci#define CPPI5_TR_CMD_ID_SHIFT (16U) 6118c2ecf20Sopenharmony_ci#define CPPI5_TR_CMD_ID_MASK GENMASK(23, 16) 6128c2ecf20Sopenharmony_ci#define CPPI5_TR_CSF_FLAGS_SHIFT (24U) 6138c2ecf20Sopenharmony_ci#define CPPI5_TR_CSF_FLAGS_MASK GENMASK(31, 24) 6148c2ecf20Sopenharmony_ci#define CPPI5_TR_CSF_SA_INDIRECT BIT(0) 6158c2ecf20Sopenharmony_ci#define CPPI5_TR_CSF_DA_INDIRECT BIT(1) 6168c2ecf20Sopenharmony_ci#define CPPI5_TR_CSF_SUPR_EVT BIT(2) 6178c2ecf20Sopenharmony_ci#define CPPI5_TR_CSF_EOL_ADV_SHIFT (4U) 6188c2ecf20Sopenharmony_ci#define CPPI5_TR_CSF_EOL_ADV_MASK GENMASK(6, 4) 6198c2ecf20Sopenharmony_ci#define CPPI5_TR_CSF_EOP BIT(7) 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci/** 6228c2ecf20Sopenharmony_ci * enum cppi5_tr_types - TR types 6238c2ecf20Sopenharmony_ci * @CPPI5_TR_TYPE0: One dimensional data move 6248c2ecf20Sopenharmony_ci * @CPPI5_TR_TYPE1: Two dimensional data move 6258c2ecf20Sopenharmony_ci * @CPPI5_TR_TYPE2: Three dimensional data move 6268c2ecf20Sopenharmony_ci * @CPPI5_TR_TYPE3: Four dimensional data move 6278c2ecf20Sopenharmony_ci * @CPPI5_TR_TYPE4: Four dimensional data move with data formatting 6288c2ecf20Sopenharmony_ci * @CPPI5_TR_TYPE5: Four dimensional Cache Warm 6298c2ecf20Sopenharmony_ci * @CPPI5_TR_TYPE8: Four Dimensional Block Move 6308c2ecf20Sopenharmony_ci * @CPPI5_TR_TYPE9: Four Dimensional Block Move with Repacking 6318c2ecf20Sopenharmony_ci * @CPPI5_TR_TYPE10: Two Dimensional Block Move 6328c2ecf20Sopenharmony_ci * @CPPI5_TR_TYPE11: Two Dimensional Block Move with Repacking 6338c2ecf20Sopenharmony_ci * @CPPI5_TR_TYPE15: Four Dimensional Block Move with Repacking and 6348c2ecf20Sopenharmony_ci * Indirection 6358c2ecf20Sopenharmony_ci */ 6368c2ecf20Sopenharmony_cienum cppi5_tr_types { 6378c2ecf20Sopenharmony_ci CPPI5_TR_TYPE0 = 0, 6388c2ecf20Sopenharmony_ci CPPI5_TR_TYPE1, 6398c2ecf20Sopenharmony_ci CPPI5_TR_TYPE2, 6408c2ecf20Sopenharmony_ci CPPI5_TR_TYPE3, 6418c2ecf20Sopenharmony_ci CPPI5_TR_TYPE4, 6428c2ecf20Sopenharmony_ci CPPI5_TR_TYPE5, 6438c2ecf20Sopenharmony_ci /* type6-7: Reserved */ 6448c2ecf20Sopenharmony_ci CPPI5_TR_TYPE8 = 8, 6458c2ecf20Sopenharmony_ci CPPI5_TR_TYPE9, 6468c2ecf20Sopenharmony_ci CPPI5_TR_TYPE10, 6478c2ecf20Sopenharmony_ci CPPI5_TR_TYPE11, 6488c2ecf20Sopenharmony_ci /* type12-14: Reserved */ 6498c2ecf20Sopenharmony_ci CPPI5_TR_TYPE15 = 15, 6508c2ecf20Sopenharmony_ci CPPI5_TR_TYPE_MAX 6518c2ecf20Sopenharmony_ci}; 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci/** 6548c2ecf20Sopenharmony_ci * enum cppi5_tr_event_size - TR Flags EVENT_SIZE field specifies when an event 6558c2ecf20Sopenharmony_ci * is generated for each TR. 6568c2ecf20Sopenharmony_ci * @CPPI5_TR_EVENT_SIZE_COMPLETION: When TR is complete and all status for 6578c2ecf20Sopenharmony_ci * the TR has been received 6588c2ecf20Sopenharmony_ci * @CPPI5_TR_EVENT_SIZE_ICNT1_DEC: Type 0: when the last data transaction 6598c2ecf20Sopenharmony_ci * is sent for the TR 6608c2ecf20Sopenharmony_ci * Type 1-11: when ICNT1 is decremented 6618c2ecf20Sopenharmony_ci * @CPPI5_TR_EVENT_SIZE_ICNT2_DEC: Type 0-1,10-11: when the last data 6628c2ecf20Sopenharmony_ci * transaction is sent for the TR 6638c2ecf20Sopenharmony_ci * All other types: when ICNT2 is 6648c2ecf20Sopenharmony_ci * decremented 6658c2ecf20Sopenharmony_ci * @CPPI5_TR_EVENT_SIZE_ICNT3_DEC: Type 0-2,10-11: when the last data 6668c2ecf20Sopenharmony_ci * transaction is sent for the TR 6678c2ecf20Sopenharmony_ci * All other types: when ICNT3 is 6688c2ecf20Sopenharmony_ci * decremented 6698c2ecf20Sopenharmony_ci */ 6708c2ecf20Sopenharmony_cienum cppi5_tr_event_size { 6718c2ecf20Sopenharmony_ci CPPI5_TR_EVENT_SIZE_COMPLETION, 6728c2ecf20Sopenharmony_ci CPPI5_TR_EVENT_SIZE_ICNT1_DEC, 6738c2ecf20Sopenharmony_ci CPPI5_TR_EVENT_SIZE_ICNT2_DEC, 6748c2ecf20Sopenharmony_ci CPPI5_TR_EVENT_SIZE_ICNT3_DEC, 6758c2ecf20Sopenharmony_ci CPPI5_TR_EVENT_SIZE_MAX 6768c2ecf20Sopenharmony_ci}; 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci/** 6798c2ecf20Sopenharmony_ci * enum cppi5_tr_trigger - TR Flags TRIGGERx field specifies the type of trigger 6808c2ecf20Sopenharmony_ci * used to enable the TR to transfer data as specified 6818c2ecf20Sopenharmony_ci * by TRIGGERx_TYPE field. 6828c2ecf20Sopenharmony_ci * @CPPI5_TR_TRIGGER_NONE: No trigger 6838c2ecf20Sopenharmony_ci * @CPPI5_TR_TRIGGER_GLOBAL0: Global trigger 0 6848c2ecf20Sopenharmony_ci * @CPPI5_TR_TRIGGER_GLOBAL1: Global trigger 1 6858c2ecf20Sopenharmony_ci * @CPPI5_TR_TRIGGER_LOCAL_EVENT: Local Event 6868c2ecf20Sopenharmony_ci */ 6878c2ecf20Sopenharmony_cienum cppi5_tr_trigger { 6888c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER_NONE, 6898c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER_GLOBAL0, 6908c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER_GLOBAL1, 6918c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER_LOCAL_EVENT, 6928c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER_MAX 6938c2ecf20Sopenharmony_ci}; 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci/** 6968c2ecf20Sopenharmony_ci * enum cppi5_tr_trigger_type - TR Flags TRIGGERx_TYPE field specifies the type 6978c2ecf20Sopenharmony_ci * of data transfer that will be enabled by 6988c2ecf20Sopenharmony_ci * receiving a trigger as specified by TRIGGERx. 6998c2ecf20Sopenharmony_ci * @CPPI5_TR_TRIGGER_TYPE_ICNT1_DEC: The second inner most loop (ICNT1) will 7008c2ecf20Sopenharmony_ci * be decremented by 1 7018c2ecf20Sopenharmony_ci * @CPPI5_TR_TRIGGER_TYPE_ICNT2_DEC: The third inner most loop (ICNT2) will 7028c2ecf20Sopenharmony_ci * be decremented by 1 7038c2ecf20Sopenharmony_ci * @CPPI5_TR_TRIGGER_TYPE_ICNT3_DEC: The outer most loop (ICNT3) will be 7048c2ecf20Sopenharmony_ci * decremented by 1 7058c2ecf20Sopenharmony_ci * @CPPI5_TR_TRIGGER_TYPE_ALL: The entire TR will be allowed to 7068c2ecf20Sopenharmony_ci * complete 7078c2ecf20Sopenharmony_ci */ 7088c2ecf20Sopenharmony_cienum cppi5_tr_trigger_type { 7098c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER_TYPE_ICNT1_DEC, 7108c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER_TYPE_ICNT2_DEC, 7118c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER_TYPE_ICNT3_DEC, 7128c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER_TYPE_ALL, 7138c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER_TYPE_MAX 7148c2ecf20Sopenharmony_ci}; 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_citypedef u32 cppi5_tr_flags_t; 7178c2ecf20Sopenharmony_ci 7188c2ecf20Sopenharmony_ci/** 7198c2ecf20Sopenharmony_ci * struct cppi5_tr_type0_t - Type 0 (One dimensional data move) TR (16 byte) 7208c2ecf20Sopenharmony_ci * @flags: TR flags (type, triggers, event, configuration) 7218c2ecf20Sopenharmony_ci * @icnt0: Total loop iteration count for level 0 (innermost) 7228c2ecf20Sopenharmony_ci * @_reserved: Not used 7238c2ecf20Sopenharmony_ci * @addr: Starting address for the source data or destination data 7248c2ecf20Sopenharmony_ci */ 7258c2ecf20Sopenharmony_cistruct cppi5_tr_type0_t { 7268c2ecf20Sopenharmony_ci cppi5_tr_flags_t flags; 7278c2ecf20Sopenharmony_ci u16 icnt0; 7288c2ecf20Sopenharmony_ci u16 _reserved; 7298c2ecf20Sopenharmony_ci u64 addr; 7308c2ecf20Sopenharmony_ci} __aligned(16) __packed; 7318c2ecf20Sopenharmony_ci 7328c2ecf20Sopenharmony_ci/** 7338c2ecf20Sopenharmony_ci * struct cppi5_tr_type1_t - Type 1 (Two dimensional data move) TR (32 byte) 7348c2ecf20Sopenharmony_ci * @flags: TR flags (type, triggers, event, configuration) 7358c2ecf20Sopenharmony_ci * @icnt0: Total loop iteration count for level 0 (innermost) 7368c2ecf20Sopenharmony_ci * @icnt1: Total loop iteration count for level 1 7378c2ecf20Sopenharmony_ci * @addr: Starting address for the source data or destination data 7388c2ecf20Sopenharmony_ci * @dim1: Signed dimension for loop level 1 7398c2ecf20Sopenharmony_ci */ 7408c2ecf20Sopenharmony_cistruct cppi5_tr_type1_t { 7418c2ecf20Sopenharmony_ci cppi5_tr_flags_t flags; 7428c2ecf20Sopenharmony_ci u16 icnt0; 7438c2ecf20Sopenharmony_ci u16 icnt1; 7448c2ecf20Sopenharmony_ci u64 addr; 7458c2ecf20Sopenharmony_ci s32 dim1; 7468c2ecf20Sopenharmony_ci} __aligned(32) __packed; 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci/** 7498c2ecf20Sopenharmony_ci * struct cppi5_tr_type2_t - Type 2 (Three dimensional data move) TR (32 byte) 7508c2ecf20Sopenharmony_ci * @flags: TR flags (type, triggers, event, configuration) 7518c2ecf20Sopenharmony_ci * @icnt0: Total loop iteration count for level 0 (innermost) 7528c2ecf20Sopenharmony_ci * @icnt1: Total loop iteration count for level 1 7538c2ecf20Sopenharmony_ci * @addr: Starting address for the source data or destination data 7548c2ecf20Sopenharmony_ci * @dim1: Signed dimension for loop level 1 7558c2ecf20Sopenharmony_ci * @icnt2: Total loop iteration count for level 2 7568c2ecf20Sopenharmony_ci * @_reserved: Not used 7578c2ecf20Sopenharmony_ci * @dim2: Signed dimension for loop level 2 7588c2ecf20Sopenharmony_ci */ 7598c2ecf20Sopenharmony_cistruct cppi5_tr_type2_t { 7608c2ecf20Sopenharmony_ci cppi5_tr_flags_t flags; 7618c2ecf20Sopenharmony_ci u16 icnt0; 7628c2ecf20Sopenharmony_ci u16 icnt1; 7638c2ecf20Sopenharmony_ci u64 addr; 7648c2ecf20Sopenharmony_ci s32 dim1; 7658c2ecf20Sopenharmony_ci u16 icnt2; 7668c2ecf20Sopenharmony_ci u16 _reserved; 7678c2ecf20Sopenharmony_ci s32 dim2; 7688c2ecf20Sopenharmony_ci} __aligned(32) __packed; 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_ci/** 7718c2ecf20Sopenharmony_ci * struct cppi5_tr_type3_t - Type 3 (Four dimensional data move) TR (32 byte) 7728c2ecf20Sopenharmony_ci * @flags: TR flags (type, triggers, event, configuration) 7738c2ecf20Sopenharmony_ci * @icnt0: Total loop iteration count for level 0 (innermost) 7748c2ecf20Sopenharmony_ci * @icnt1: Total loop iteration count for level 1 7758c2ecf20Sopenharmony_ci * @addr: Starting address for the source data or destination data 7768c2ecf20Sopenharmony_ci * @dim1: Signed dimension for loop level 1 7778c2ecf20Sopenharmony_ci * @icnt2: Total loop iteration count for level 2 7788c2ecf20Sopenharmony_ci * @icnt3: Total loop iteration count for level 3 (outermost) 7798c2ecf20Sopenharmony_ci * @dim2: Signed dimension for loop level 2 7808c2ecf20Sopenharmony_ci * @dim3: Signed dimension for loop level 3 7818c2ecf20Sopenharmony_ci */ 7828c2ecf20Sopenharmony_cistruct cppi5_tr_type3_t { 7838c2ecf20Sopenharmony_ci cppi5_tr_flags_t flags; 7848c2ecf20Sopenharmony_ci u16 icnt0; 7858c2ecf20Sopenharmony_ci u16 icnt1; 7868c2ecf20Sopenharmony_ci u64 addr; 7878c2ecf20Sopenharmony_ci s32 dim1; 7888c2ecf20Sopenharmony_ci u16 icnt2; 7898c2ecf20Sopenharmony_ci u16 icnt3; 7908c2ecf20Sopenharmony_ci s32 dim2; 7918c2ecf20Sopenharmony_ci s32 dim3; 7928c2ecf20Sopenharmony_ci} __aligned(32) __packed; 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci/** 7958c2ecf20Sopenharmony_ci * struct cppi5_tr_type15_t - Type 15 (Four Dimensional Block Copy with 7968c2ecf20Sopenharmony_ci * Repacking and Indirection Support) TR (64 byte) 7978c2ecf20Sopenharmony_ci * @flags: TR flags (type, triggers, event, configuration) 7988c2ecf20Sopenharmony_ci * @icnt0: Total loop iteration count for level 0 (innermost) for 7998c2ecf20Sopenharmony_ci * source 8008c2ecf20Sopenharmony_ci * @icnt1: Total loop iteration count for level 1 for source 8018c2ecf20Sopenharmony_ci * @addr: Starting address for the source data 8028c2ecf20Sopenharmony_ci * @dim1: Signed dimension for loop level 1 for source 8038c2ecf20Sopenharmony_ci * @icnt2: Total loop iteration count for level 2 for source 8048c2ecf20Sopenharmony_ci * @icnt3: Total loop iteration count for level 3 (outermost) for 8058c2ecf20Sopenharmony_ci * source 8068c2ecf20Sopenharmony_ci * @dim2: Signed dimension for loop level 2 for source 8078c2ecf20Sopenharmony_ci * @dim3: Signed dimension for loop level 3 for source 8088c2ecf20Sopenharmony_ci * @_reserved: Not used 8098c2ecf20Sopenharmony_ci * @ddim1: Signed dimension for loop level 1 for destination 8108c2ecf20Sopenharmony_ci * @daddr: Starting address for the destination data 8118c2ecf20Sopenharmony_ci * @ddim2: Signed dimension for loop level 2 for destination 8128c2ecf20Sopenharmony_ci * @ddim3: Signed dimension for loop level 3 for destination 8138c2ecf20Sopenharmony_ci * @dicnt0: Total loop iteration count for level 0 (innermost) for 8148c2ecf20Sopenharmony_ci * destination 8158c2ecf20Sopenharmony_ci * @dicnt1: Total loop iteration count for level 1 for destination 8168c2ecf20Sopenharmony_ci * @dicnt2: Total loop iteration count for level 2 for destination 8178c2ecf20Sopenharmony_ci * @sicnt3: Total loop iteration count for level 3 (outermost) for 8188c2ecf20Sopenharmony_ci * destination 8198c2ecf20Sopenharmony_ci */ 8208c2ecf20Sopenharmony_cistruct cppi5_tr_type15_t { 8218c2ecf20Sopenharmony_ci cppi5_tr_flags_t flags; 8228c2ecf20Sopenharmony_ci u16 icnt0; 8238c2ecf20Sopenharmony_ci u16 icnt1; 8248c2ecf20Sopenharmony_ci u64 addr; 8258c2ecf20Sopenharmony_ci s32 dim1; 8268c2ecf20Sopenharmony_ci u16 icnt2; 8278c2ecf20Sopenharmony_ci u16 icnt3; 8288c2ecf20Sopenharmony_ci s32 dim2; 8298c2ecf20Sopenharmony_ci s32 dim3; 8308c2ecf20Sopenharmony_ci u32 _reserved; 8318c2ecf20Sopenharmony_ci s32 ddim1; 8328c2ecf20Sopenharmony_ci u64 daddr; 8338c2ecf20Sopenharmony_ci s32 ddim2; 8348c2ecf20Sopenharmony_ci s32 ddim3; 8358c2ecf20Sopenharmony_ci u16 dicnt0; 8368c2ecf20Sopenharmony_ci u16 dicnt1; 8378c2ecf20Sopenharmony_ci u16 dicnt2; 8388c2ecf20Sopenharmony_ci u16 dicnt3; 8398c2ecf20Sopenharmony_ci} __aligned(64) __packed; 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci/** 8428c2ecf20Sopenharmony_ci * struct cppi5_tr_resp_t - TR response record 8438c2ecf20Sopenharmony_ci * @status: Status type and info 8448c2ecf20Sopenharmony_ci * @_reserved: Not used 8458c2ecf20Sopenharmony_ci * @cmd_id: Command ID for the TR for TR identification 8468c2ecf20Sopenharmony_ci * @flags: Configuration Specific Flags 8478c2ecf20Sopenharmony_ci */ 8488c2ecf20Sopenharmony_cistruct cppi5_tr_resp_t { 8498c2ecf20Sopenharmony_ci u8 status; 8508c2ecf20Sopenharmony_ci u8 _reserved; 8518c2ecf20Sopenharmony_ci u8 cmd_id; 8528c2ecf20Sopenharmony_ci u8 flags; 8538c2ecf20Sopenharmony_ci} __packed; 8548c2ecf20Sopenharmony_ci 8558c2ecf20Sopenharmony_ci#define CPPI5_TR_RESPONSE_STATUS_TYPE_SHIFT (0U) 8568c2ecf20Sopenharmony_ci#define CPPI5_TR_RESPONSE_STATUS_TYPE_MASK GENMASK(3, 0) 8578c2ecf20Sopenharmony_ci#define CPPI5_TR_RESPONSE_STATUS_INFO_SHIFT (4U) 8588c2ecf20Sopenharmony_ci#define CPPI5_TR_RESPONSE_STATUS_INFO_MASK GENMASK(7, 4) 8598c2ecf20Sopenharmony_ci#define CPPI5_TR_RESPONSE_CMDID_SHIFT (16U) 8608c2ecf20Sopenharmony_ci#define CPPI5_TR_RESPONSE_CMDID_MASK GENMASK(23, 16) 8618c2ecf20Sopenharmony_ci#define CPPI5_TR_RESPONSE_CFG_SPECIFIC_SHIFT (24U) 8628c2ecf20Sopenharmony_ci#define CPPI5_TR_RESPONSE_CFG_SPECIFIC_MASK GENMASK(31, 24) 8638c2ecf20Sopenharmony_ci 8648c2ecf20Sopenharmony_ci/** 8658c2ecf20Sopenharmony_ci * enum cppi5_tr_resp_status_type - TR Response Status Type field is used to 8668c2ecf20Sopenharmony_ci * determine what type of status is being 8678c2ecf20Sopenharmony_ci * returned. 8688c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_NONE: No error, completion: completed 8698c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_TRANSFER_ERR: Transfer Error, completion: none 8708c2ecf20Sopenharmony_ci * or partially completed 8718c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_ABORTED_ERR: Aborted Error, completion: none 8728c2ecf20Sopenharmony_ci * or partially completed 8738c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_SUBMISSION_ERR: Submission Error, completion: 8748c2ecf20Sopenharmony_ci * none 8758c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_ERR: Unsupported Error, completion: 8768c2ecf20Sopenharmony_ci * none 8778c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_TRANSFER_EXCEPTION: Transfer Exception, completion: 8788c2ecf20Sopenharmony_ci * partially completed 8798c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS__TEARDOWN_FLUSH: Teardown Flush, completion: none 8808c2ecf20Sopenharmony_ci */ 8818c2ecf20Sopenharmony_cienum cppi5_tr_resp_status_type { 8828c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_NONE, 8838c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_TRANSFER_ERR, 8848c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_ABORTED_ERR, 8858c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_SUBMISSION_ERR, 8868c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_ERR, 8878c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_TRANSFER_EXCEPTION, 8888c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS__TEARDOWN_FLUSH, 8898c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_MAX 8908c2ecf20Sopenharmony_ci}; 8918c2ecf20Sopenharmony_ci 8928c2ecf20Sopenharmony_ci/** 8938c2ecf20Sopenharmony_ci * enum cppi5_tr_resp_status_submission - TR Response Status field values which 8948c2ecf20Sopenharmony_ci * corresponds Submission Error 8958c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_SUBMISSION_ICNT0: ICNT0 was 0 8968c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_SUBMISSION_FIFO_FULL: Channel FIFO was full when TR 8978c2ecf20Sopenharmony_ci * received 8988c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_SUBMISSION_OWN: Channel is not owned by the 8998c2ecf20Sopenharmony_ci * submitter 9008c2ecf20Sopenharmony_ci */ 9018c2ecf20Sopenharmony_cienum cppi5_tr_resp_status_submission { 9028c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_SUBMISSION_ICNT0, 9038c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_SUBMISSION_FIFO_FULL, 9048c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_SUBMISSION_OWN, 9058c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_SUBMISSION_MAX 9068c2ecf20Sopenharmony_ci}; 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_ci/** 9098c2ecf20Sopenharmony_ci * enum cppi5_tr_resp_status_unsupported - TR Response Status field values which 9108c2ecf20Sopenharmony_ci * corresponds Unsupported Error 9118c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_TR_TYPE: TR Type not supported 9128c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_STATIC: STATIC not supported 9138c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_EOL: EOL not supported 9148c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_CFG_SPECIFIC: CONFIGURATION SPECIFIC 9158c2ecf20Sopenharmony_ci * not supported 9168c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_AMODE: AMODE not supported 9178c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_ELTYPE: ELTYPE not supported 9188c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_DFMT: DFMT not supported 9198c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_SECTR: SECTR not supported 9208c2ecf20Sopenharmony_ci * @CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_AMODE_SPECIFIC: AMODE SPECIFIC field 9218c2ecf20Sopenharmony_ci * not supported 9228c2ecf20Sopenharmony_ci */ 9238c2ecf20Sopenharmony_cienum cppi5_tr_resp_status_unsupported { 9248c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_TR_TYPE, 9258c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_STATIC, 9268c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_EOL, 9278c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_CFG_SPECIFIC, 9288c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_AMODE, 9298c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_ELTYPE, 9308c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_DFMT, 9318c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_SECTR, 9328c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_AMODE_SPECIFIC, 9338c2ecf20Sopenharmony_ci CPPI5_TR_RESPONSE_STATUS_UNSUPPORTED_MAX 9348c2ecf20Sopenharmony_ci}; 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci/** 9378c2ecf20Sopenharmony_ci * cppi5_trdesc_calc_size - Calculate TR Descriptor size 9388c2ecf20Sopenharmony_ci * @tr_count: number of TR records 9398c2ecf20Sopenharmony_ci * @tr_size: Nominal size of TR record (max) [16, 32, 64, 128] 9408c2ecf20Sopenharmony_ci * 9418c2ecf20Sopenharmony_ci * Returns required TR Descriptor size 9428c2ecf20Sopenharmony_ci */ 9438c2ecf20Sopenharmony_cistatic inline size_t cppi5_trdesc_calc_size(u32 tr_count, u32 tr_size) 9448c2ecf20Sopenharmony_ci{ 9458c2ecf20Sopenharmony_ci /* 9468c2ecf20Sopenharmony_ci * The Size of a TR descriptor is: 9478c2ecf20Sopenharmony_ci * 1 x tr_size : the first 16 bytes is used by the packet info block + 9488c2ecf20Sopenharmony_ci * tr_count x tr_size : Transfer Request Records + 9498c2ecf20Sopenharmony_ci * tr_count x sizeof(struct cppi5_tr_resp_t) : Transfer Response Records 9508c2ecf20Sopenharmony_ci */ 9518c2ecf20Sopenharmony_ci return tr_size * (tr_count + 1) + 9528c2ecf20Sopenharmony_ci sizeof(struct cppi5_tr_resp_t) * tr_count; 9538c2ecf20Sopenharmony_ci} 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_ci/** 9568c2ecf20Sopenharmony_ci * cppi5_trdesc_init - Init TR Descriptor 9578c2ecf20Sopenharmony_ci * @desc: TR Descriptor 9588c2ecf20Sopenharmony_ci * @tr_count: number of TR records 9598c2ecf20Sopenharmony_ci * @tr_size: Nominal size of TR record (max) [16, 32, 64, 128] 9608c2ecf20Sopenharmony_ci * @reload_idx: Absolute index to jump to on the 2nd and following passes 9618c2ecf20Sopenharmony_ci * through the TR packet. 9628c2ecf20Sopenharmony_ci * @reload_count: Number of times to jump from last entry to reload_idx. 0x1ff 9638c2ecf20Sopenharmony_ci * indicates infinite looping. 9648c2ecf20Sopenharmony_ci * 9658c2ecf20Sopenharmony_ci * Init TR Descriptor 9668c2ecf20Sopenharmony_ci */ 9678c2ecf20Sopenharmony_cistatic inline void cppi5_trdesc_init(struct cppi5_desc_hdr_t *desc_hdr, 9688c2ecf20Sopenharmony_ci u32 tr_count, u32 tr_size, u32 reload_idx, 9698c2ecf20Sopenharmony_ci u32 reload_count) 9708c2ecf20Sopenharmony_ci{ 9718c2ecf20Sopenharmony_ci desc_hdr->pkt_info0 = CPPI5_INFO0_DESC_TYPE_VAL_TR << 9728c2ecf20Sopenharmony_ci CPPI5_INFO0_HDESC_TYPE_SHIFT; 9738c2ecf20Sopenharmony_ci desc_hdr->pkt_info0 |= 9748c2ecf20Sopenharmony_ci (reload_count << CPPI5_INFO0_TRDESC_RLDCNT_SHIFT) & 9758c2ecf20Sopenharmony_ci CPPI5_INFO0_TRDESC_RLDCNT_MASK; 9768c2ecf20Sopenharmony_ci desc_hdr->pkt_info0 |= 9778c2ecf20Sopenharmony_ci (reload_idx << CPPI5_INFO0_TRDESC_RLDIDX_SHIFT) & 9788c2ecf20Sopenharmony_ci CPPI5_INFO0_TRDESC_RLDIDX_MASK; 9798c2ecf20Sopenharmony_ci desc_hdr->pkt_info0 |= (tr_count - 1) & CPPI5_INFO0_TRDESC_LASTIDX_MASK; 9808c2ecf20Sopenharmony_ci 9818c2ecf20Sopenharmony_ci desc_hdr->pkt_info1 |= ((ffs(tr_size >> 4) - 1) << 9828c2ecf20Sopenharmony_ci CPPI5_INFO1_TRDESC_RECSIZE_SHIFT) & 9838c2ecf20Sopenharmony_ci CPPI5_INFO1_TRDESC_RECSIZE_MASK; 9848c2ecf20Sopenharmony_ci} 9858c2ecf20Sopenharmony_ci 9868c2ecf20Sopenharmony_ci/** 9878c2ecf20Sopenharmony_ci * cppi5_tr_init - Init TR record 9888c2ecf20Sopenharmony_ci * @flags: Pointer to the TR's flags 9898c2ecf20Sopenharmony_ci * @type: TR type 9908c2ecf20Sopenharmony_ci * @static_tr: TR is static 9918c2ecf20Sopenharmony_ci * @wait: Wait for TR completion before allow the next TR to start 9928c2ecf20Sopenharmony_ci * @event_size: output event generation cfg 9938c2ecf20Sopenharmony_ci * @cmd_id: TR identifier (application specifics) 9948c2ecf20Sopenharmony_ci * 9958c2ecf20Sopenharmony_ci * Init TR record 9968c2ecf20Sopenharmony_ci */ 9978c2ecf20Sopenharmony_cistatic inline void cppi5_tr_init(cppi5_tr_flags_t *flags, 9988c2ecf20Sopenharmony_ci enum cppi5_tr_types type, bool static_tr, 9998c2ecf20Sopenharmony_ci bool wait, enum cppi5_tr_event_size event_size, 10008c2ecf20Sopenharmony_ci u32 cmd_id) 10018c2ecf20Sopenharmony_ci{ 10028c2ecf20Sopenharmony_ci *flags = type; 10038c2ecf20Sopenharmony_ci *flags |= (event_size << CPPI5_TR_EVENT_SIZE_SHIFT) & 10048c2ecf20Sopenharmony_ci CPPI5_TR_EVENT_SIZE_MASK; 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_ci *flags |= (cmd_id << CPPI5_TR_CMD_ID_SHIFT) & 10078c2ecf20Sopenharmony_ci CPPI5_TR_CMD_ID_MASK; 10088c2ecf20Sopenharmony_ci 10098c2ecf20Sopenharmony_ci if (static_tr && (type == CPPI5_TR_TYPE8 || type == CPPI5_TR_TYPE9)) 10108c2ecf20Sopenharmony_ci *flags |= CPPI5_TR_STATIC; 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_ci if (wait) 10138c2ecf20Sopenharmony_ci *flags |= CPPI5_TR_WAIT; 10148c2ecf20Sopenharmony_ci} 10158c2ecf20Sopenharmony_ci 10168c2ecf20Sopenharmony_ci/** 10178c2ecf20Sopenharmony_ci * cppi5_tr_set_trigger - Configure trigger0/1 and trigger0/1_type 10188c2ecf20Sopenharmony_ci * @flags: Pointer to the TR's flags 10198c2ecf20Sopenharmony_ci * @trigger0: trigger0 selection 10208c2ecf20Sopenharmony_ci * @trigger0_type: type of data transfer that will be enabled by trigger0 10218c2ecf20Sopenharmony_ci * @trigger1: trigger1 selection 10228c2ecf20Sopenharmony_ci * @trigger1_type: type of data transfer that will be enabled by trigger1 10238c2ecf20Sopenharmony_ci * 10248c2ecf20Sopenharmony_ci * Configure the triggers for the TR 10258c2ecf20Sopenharmony_ci */ 10268c2ecf20Sopenharmony_cistatic inline void cppi5_tr_set_trigger(cppi5_tr_flags_t *flags, 10278c2ecf20Sopenharmony_ci enum cppi5_tr_trigger trigger0, 10288c2ecf20Sopenharmony_ci enum cppi5_tr_trigger_type trigger0_type, 10298c2ecf20Sopenharmony_ci enum cppi5_tr_trigger trigger1, 10308c2ecf20Sopenharmony_ci enum cppi5_tr_trigger_type trigger1_type) 10318c2ecf20Sopenharmony_ci{ 10328c2ecf20Sopenharmony_ci *flags &= ~(CPPI5_TR_TRIGGER0_MASK | CPPI5_TR_TRIGGER0_TYPE_MASK | 10338c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER1_MASK | CPPI5_TR_TRIGGER1_TYPE_MASK); 10348c2ecf20Sopenharmony_ci *flags |= (trigger0 << CPPI5_TR_TRIGGER0_SHIFT) & 10358c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER0_MASK; 10368c2ecf20Sopenharmony_ci *flags |= (trigger0_type << CPPI5_TR_TRIGGER0_TYPE_SHIFT) & 10378c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER0_TYPE_MASK; 10388c2ecf20Sopenharmony_ci 10398c2ecf20Sopenharmony_ci *flags |= (trigger1 << CPPI5_TR_TRIGGER1_SHIFT) & 10408c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER1_MASK; 10418c2ecf20Sopenharmony_ci *flags |= (trigger1_type << CPPI5_TR_TRIGGER1_TYPE_SHIFT) & 10428c2ecf20Sopenharmony_ci CPPI5_TR_TRIGGER1_TYPE_MASK; 10438c2ecf20Sopenharmony_ci} 10448c2ecf20Sopenharmony_ci 10458c2ecf20Sopenharmony_ci/** 10468c2ecf20Sopenharmony_ci * cppi5_tr_cflag_set - Update the Configuration specific flags 10478c2ecf20Sopenharmony_ci * @flags: Pointer to the TR's flags 10488c2ecf20Sopenharmony_ci * @csf: Configuration specific flags 10498c2ecf20Sopenharmony_ci * 10508c2ecf20Sopenharmony_ci * Set a bit in Configuration Specific Flags section of the TR flags. 10518c2ecf20Sopenharmony_ci */ 10528c2ecf20Sopenharmony_cistatic inline void cppi5_tr_csf_set(cppi5_tr_flags_t *flags, u32 csf) 10538c2ecf20Sopenharmony_ci{ 10548c2ecf20Sopenharmony_ci *flags &= ~CPPI5_TR_CSF_FLAGS_MASK; 10558c2ecf20Sopenharmony_ci *flags |= (csf << CPPI5_TR_CSF_FLAGS_SHIFT) & 10568c2ecf20Sopenharmony_ci CPPI5_TR_CSF_FLAGS_MASK; 10578c2ecf20Sopenharmony_ci} 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_ci#endif /* __TI_CPPI5_H__ */ 1060