18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright 2019 NXP */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef __FSL_DPDMAI_H 58c2ecf20Sopenharmony_ci#define __FSL_DPDMAI_H 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/* DPDMAI Version */ 88c2ecf20Sopenharmony_ci#define DPDMAI_VER_MAJOR 2 98c2ecf20Sopenharmony_ci#define DPDMAI_VER_MINOR 2 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define DPDMAI_CMD_BASE_VERSION 0 128c2ecf20Sopenharmony_ci#define DPDMAI_CMD_ID_OFFSET 4 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_FORMAT(x) (((x) << DPDMAI_CMD_ID_OFFSET) | \ 158c2ecf20Sopenharmony_ci DPDMAI_CMD_BASE_VERSION) 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* Command IDs */ 188c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_CLOSE DPDMAI_CMDID_FORMAT(0x800) 198c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_OPEN DPDMAI_CMDID_FORMAT(0x80E) 208c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_CREATE DPDMAI_CMDID_FORMAT(0x90E) 218c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_DESTROY DPDMAI_CMDID_FORMAT(0x900) 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_ENABLE DPDMAI_CMDID_FORMAT(0x002) 248c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_DISABLE DPDMAI_CMDID_FORMAT(0x003) 258c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_GET_ATTR DPDMAI_CMDID_FORMAT(0x004) 268c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_RESET DPDMAI_CMDID_FORMAT(0x005) 278c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_IS_ENABLED DPDMAI_CMDID_FORMAT(0x006) 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_SET_IRQ DPDMAI_CMDID_FORMAT(0x010) 308c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_GET_IRQ DPDMAI_CMDID_FORMAT(0x011) 318c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_SET_IRQ_ENABLE DPDMAI_CMDID_FORMAT(0x012) 328c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_GET_IRQ_ENABLE DPDMAI_CMDID_FORMAT(0x013) 338c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_SET_IRQ_MASK DPDMAI_CMDID_FORMAT(0x014) 348c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_GET_IRQ_MASK DPDMAI_CMDID_FORMAT(0x015) 358c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_GET_IRQ_STATUS DPDMAI_CMDID_FORMAT(0x016) 368c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_CLEAR_IRQ_STATUS DPDMAI_CMDID_FORMAT(0x017) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_SET_RX_QUEUE DPDMAI_CMDID_FORMAT(0x1A0) 398c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_GET_RX_QUEUE DPDMAI_CMDID_FORMAT(0x1A1) 408c2ecf20Sopenharmony_ci#define DPDMAI_CMDID_GET_TX_QUEUE DPDMAI_CMDID_FORMAT(0x1A2) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define MC_CMD_HDR_TOKEN_O 32 /* Token field offset */ 438c2ecf20Sopenharmony_ci#define MC_CMD_HDR_TOKEN_S 16 /* Token field size */ 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define MAKE_UMASK64(_width) \ 468c2ecf20Sopenharmony_ci ((u64)((_width) < 64 ? ((u64)1 << (_width)) - 1 : (u64)-1)) 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* Data Path DMA Interface API 498c2ecf20Sopenharmony_ci * Contains initialization APIs and runtime control APIs for DPDMAI 508c2ecf20Sopenharmony_ci */ 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/** 538c2ecf20Sopenharmony_ci * Maximum number of Tx/Rx priorities per DPDMAI object 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_ci#define DPDMAI_PRIO_NUM 2 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/* DPDMAI queue modification options */ 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/** 608c2ecf20Sopenharmony_ci * Select to modify the user's context associated with the queue 618c2ecf20Sopenharmony_ci */ 628c2ecf20Sopenharmony_ci#define DPDMAI_QUEUE_OPT_USER_CTX 0x1 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/** 658c2ecf20Sopenharmony_ci * Select to modify the queue's destination 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_ci#define DPDMAI_QUEUE_OPT_DEST 0x2 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/** 708c2ecf20Sopenharmony_ci * struct dpdmai_cfg - Structure representing DPDMAI configuration 718c2ecf20Sopenharmony_ci * @priorities: Priorities for the DMA hardware processing; valid priorities are 728c2ecf20Sopenharmony_ci * configured with values 1-8; the entry following last valid entry 738c2ecf20Sopenharmony_ci * should be configured with 0 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_cistruct dpdmai_cfg { 768c2ecf20Sopenharmony_ci u8 priorities[DPDMAI_PRIO_NUM]; 778c2ecf20Sopenharmony_ci}; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci/** 808c2ecf20Sopenharmony_ci * struct dpdmai_attr - Structure representing DPDMAI attributes 818c2ecf20Sopenharmony_ci * @id: DPDMAI object ID 828c2ecf20Sopenharmony_ci * @version: DPDMAI version 838c2ecf20Sopenharmony_ci * @num_of_priorities: number of priorities 848c2ecf20Sopenharmony_ci */ 858c2ecf20Sopenharmony_cistruct dpdmai_attr { 868c2ecf20Sopenharmony_ci int id; 878c2ecf20Sopenharmony_ci /** 888c2ecf20Sopenharmony_ci * struct version - DPDMAI version 898c2ecf20Sopenharmony_ci * @major: DPDMAI major version 908c2ecf20Sopenharmony_ci * @minor: DPDMAI minor version 918c2ecf20Sopenharmony_ci */ 928c2ecf20Sopenharmony_ci struct { 938c2ecf20Sopenharmony_ci u16 major; 948c2ecf20Sopenharmony_ci u16 minor; 958c2ecf20Sopenharmony_ci } version; 968c2ecf20Sopenharmony_ci u8 num_of_priorities; 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/** 1008c2ecf20Sopenharmony_ci * enum dpdmai_dest - DPDMAI destination types 1018c2ecf20Sopenharmony_ci * @DPDMAI_DEST_NONE: Unassigned destination; The queue is set in parked mode 1028c2ecf20Sopenharmony_ci * and does not generate FQDAN notifications; user is expected to dequeue 1038c2ecf20Sopenharmony_ci * from the queue based on polling or other user-defined method 1048c2ecf20Sopenharmony_ci * @DPDMAI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN 1058c2ecf20Sopenharmony_ci * notifications to the specified DPIO; user is expected to dequeue 1068c2ecf20Sopenharmony_ci * from the queue only after notification is received 1078c2ecf20Sopenharmony_ci * @DPDMAI_DEST_DPCON: The queue is set in schedule mode and does not generate 1088c2ecf20Sopenharmony_ci * FQDAN notifications, but is connected to the specified DPCON object; 1098c2ecf20Sopenharmony_ci * user is expected to dequeue from the DPCON channel 1108c2ecf20Sopenharmony_ci */ 1118c2ecf20Sopenharmony_cienum dpdmai_dest { 1128c2ecf20Sopenharmony_ci DPDMAI_DEST_NONE = 0, 1138c2ecf20Sopenharmony_ci DPDMAI_DEST_DPIO = 1, 1148c2ecf20Sopenharmony_ci DPDMAI_DEST_DPCON = 2 1158c2ecf20Sopenharmony_ci}; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci/** 1188c2ecf20Sopenharmony_ci * struct dpdmai_dest_cfg - Structure representing DPDMAI destination parameters 1198c2ecf20Sopenharmony_ci * @dest_type: Destination type 1208c2ecf20Sopenharmony_ci * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type 1218c2ecf20Sopenharmony_ci * @priority: Priority selection within the DPIO or DPCON channel; valid values 1228c2ecf20Sopenharmony_ci * are 0-1 or 0-7, depending on the number of priorities in that 1238c2ecf20Sopenharmony_ci * channel; not relevant for 'DPDMAI_DEST_NONE' option 1248c2ecf20Sopenharmony_ci */ 1258c2ecf20Sopenharmony_cistruct dpdmai_dest_cfg { 1268c2ecf20Sopenharmony_ci enum dpdmai_dest dest_type; 1278c2ecf20Sopenharmony_ci int dest_id; 1288c2ecf20Sopenharmony_ci u8 priority; 1298c2ecf20Sopenharmony_ci}; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci/** 1328c2ecf20Sopenharmony_ci * struct dpdmai_rx_queue_cfg - DPDMAI RX queue configuration 1338c2ecf20Sopenharmony_ci * @options: Flags representing the suggested modifications to the queue; 1348c2ecf20Sopenharmony_ci * Use any combination of 'DPDMAI_QUEUE_OPT_<X>' flags 1358c2ecf20Sopenharmony_ci * @user_ctx: User context value provided in the frame descriptor of each 1368c2ecf20Sopenharmony_ci * dequeued frame; 1378c2ecf20Sopenharmony_ci * valid only if 'DPDMAI_QUEUE_OPT_USER_CTX' is contained in 'options' 1388c2ecf20Sopenharmony_ci * @dest_cfg: Queue destination parameters; 1398c2ecf20Sopenharmony_ci * valid only if 'DPDMAI_QUEUE_OPT_DEST' is contained in 'options' 1408c2ecf20Sopenharmony_ci */ 1418c2ecf20Sopenharmony_cistruct dpdmai_rx_queue_cfg { 1428c2ecf20Sopenharmony_ci struct dpdmai_dest_cfg dest_cfg; 1438c2ecf20Sopenharmony_ci u32 options; 1448c2ecf20Sopenharmony_ci u64 user_ctx; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci}; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/** 1498c2ecf20Sopenharmony_ci * struct dpdmai_rx_queue_attr - Structure representing attributes of Rx queues 1508c2ecf20Sopenharmony_ci * @user_ctx: User context value provided in the frame descriptor of each 1518c2ecf20Sopenharmony_ci * dequeued frame 1528c2ecf20Sopenharmony_ci * @dest_cfg: Queue destination configuration 1538c2ecf20Sopenharmony_ci * @fqid: Virtual FQID value to be used for dequeue operations 1548c2ecf20Sopenharmony_ci */ 1558c2ecf20Sopenharmony_cistruct dpdmai_rx_queue_attr { 1568c2ecf20Sopenharmony_ci struct dpdmai_dest_cfg dest_cfg; 1578c2ecf20Sopenharmony_ci u64 user_ctx; 1588c2ecf20Sopenharmony_ci u32 fqid; 1598c2ecf20Sopenharmony_ci}; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ciint dpdmai_open(struct fsl_mc_io *mc_io, u32 cmd_flags, 1628c2ecf20Sopenharmony_ci int dpdmai_id, u16 *token); 1638c2ecf20Sopenharmony_ciint dpdmai_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token); 1648c2ecf20Sopenharmony_ciint dpdmai_destroy(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token); 1658c2ecf20Sopenharmony_ciint dpdmai_create(struct fsl_mc_io *mc_io, u32 cmd_flags, 1668c2ecf20Sopenharmony_ci const struct dpdmai_cfg *cfg, u16 *token); 1678c2ecf20Sopenharmony_ciint dpdmai_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token); 1688c2ecf20Sopenharmony_ciint dpdmai_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token); 1698c2ecf20Sopenharmony_ciint dpdmai_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token); 1708c2ecf20Sopenharmony_ciint dpdmai_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, 1718c2ecf20Sopenharmony_ci u16 token, struct dpdmai_attr *attr); 1728c2ecf20Sopenharmony_ciint dpdmai_set_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, 1738c2ecf20Sopenharmony_ci u8 priority, const struct dpdmai_rx_queue_cfg *cfg); 1748c2ecf20Sopenharmony_ciint dpdmai_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, 1758c2ecf20Sopenharmony_ci u8 priority, struct dpdmai_rx_queue_attr *attr); 1768c2ecf20Sopenharmony_ciint dpdmai_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, 1778c2ecf20Sopenharmony_ci u16 token, u8 priority, u32 *fqid); 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci#endif /* __FSL_DPDMAI_H */ 180