18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright 2019 NXP */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef __DPAA2_QDMA_H 58c2ecf20Sopenharmony_ci#define __DPAA2_QDMA_H 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#define DPAA2_QDMA_STORE_SIZE 16 88c2ecf20Sopenharmony_ci#define NUM_CH 8 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_cistruct dpaa2_qdma_sd_d { 118c2ecf20Sopenharmony_ci u32 rsv:32; 128c2ecf20Sopenharmony_ci union { 138c2ecf20Sopenharmony_ci struct { 148c2ecf20Sopenharmony_ci u32 ssd:12; /* souce stride distance */ 158c2ecf20Sopenharmony_ci u32 sss:12; /* souce stride size */ 168c2ecf20Sopenharmony_ci u32 rsv1:8; 178c2ecf20Sopenharmony_ci } sdf; 188c2ecf20Sopenharmony_ci struct { 198c2ecf20Sopenharmony_ci u32 dsd:12; /* Destination stride distance */ 208c2ecf20Sopenharmony_ci u32 dss:12; /* Destination stride size */ 218c2ecf20Sopenharmony_ci u32 rsv2:8; 228c2ecf20Sopenharmony_ci } ddf; 238c2ecf20Sopenharmony_ci } df; 248c2ecf20Sopenharmony_ci u32 rbpcmd; /* Route-by-port command */ 258c2ecf20Sopenharmony_ci u32 cmd; 268c2ecf20Sopenharmony_ci} __attribute__((__packed__)); 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* Source descriptor command read transaction type for RBP=0: */ 298c2ecf20Sopenharmony_ci/* coherent copy of cacheable memory */ 308c2ecf20Sopenharmony_ci#define QDMA_SD_CMD_RDTTYPE_COHERENT (0xb << 28) 318c2ecf20Sopenharmony_ci/* Destination descriptor command write transaction type for RBP=0: */ 328c2ecf20Sopenharmony_ci/* coherent copy of cacheable memory */ 338c2ecf20Sopenharmony_ci#define QDMA_DD_CMD_WRTTYPE_COHERENT (0x6 << 28) 348c2ecf20Sopenharmony_ci#define LX2160_QDMA_DD_CMD_WRTTYPE_COHERENT (0xb << 28) 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define QMAN_FD_FMT_ENABLE BIT(0) /* frame list table enable */ 378c2ecf20Sopenharmony_ci#define QMAN_FD_BMT_ENABLE BIT(15) /* bypass memory translation */ 388c2ecf20Sopenharmony_ci#define QMAN_FD_BMT_DISABLE (0) /* bypass memory translation */ 398c2ecf20Sopenharmony_ci#define QMAN_FD_SL_DISABLE (0) /* short lengthe disabled */ 408c2ecf20Sopenharmony_ci#define QMAN_FD_SL_ENABLE BIT(14) /* short lengthe enabled */ 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define QDMA_FINAL_BIT_DISABLE (0) /* final bit disable */ 438c2ecf20Sopenharmony_ci#define QDMA_FINAL_BIT_ENABLE BIT(31) /* final bit enable */ 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define QDMA_FD_SHORT_FORMAT BIT(11) /* short format */ 468c2ecf20Sopenharmony_ci#define QDMA_FD_LONG_FORMAT (0) /* long format */ 478c2ecf20Sopenharmony_ci#define QDMA_SER_DISABLE (8) /* no notification */ 488c2ecf20Sopenharmony_ci#define QDMA_SER_CTX BIT(8) /* notification by FQD_CTX[fqid] */ 498c2ecf20Sopenharmony_ci#define QDMA_SER_DEST (2 << 8) /* notification by destination desc */ 508c2ecf20Sopenharmony_ci#define QDMA_SER_BOTH (3 << 8) /* soruce and dest notification */ 518c2ecf20Sopenharmony_ci#define QDMA_FD_SPF_ENALBE BIT(30) /* source prefetch enable */ 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define QMAN_FD_VA_ENABLE BIT(14) /* Address used is virtual address */ 548c2ecf20Sopenharmony_ci#define QMAN_FD_VA_DISABLE (0)/* Address used is a real address */ 558c2ecf20Sopenharmony_ci/* Flow Context: 49bit physical address */ 568c2ecf20Sopenharmony_ci#define QMAN_FD_CBMT_ENABLE BIT(15) 578c2ecf20Sopenharmony_ci#define QMAN_FD_CBMT_DISABLE (0) /* Flow Context: 64bit virtual address */ 588c2ecf20Sopenharmony_ci#define QMAN_FD_SC_DISABLE (0) /* stashing control */ 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#define QDMA_FL_FMT_SBF (0x0) /* Single buffer frame */ 618c2ecf20Sopenharmony_ci#define QDMA_FL_FMT_SGE (0x2) /* Scatter gather frame */ 628c2ecf20Sopenharmony_ci#define QDMA_FL_BMT_ENABLE BIT(15) /* enable bypass memory translation */ 638c2ecf20Sopenharmony_ci#define QDMA_FL_BMT_DISABLE (0x0) /* enable bypass memory translation */ 648c2ecf20Sopenharmony_ci#define QDMA_FL_SL_LONG (0x0)/* long length */ 658c2ecf20Sopenharmony_ci#define QDMA_FL_SL_SHORT (0x1) /* short length */ 668c2ecf20Sopenharmony_ci#define QDMA_FL_F (0x1)/* last frame list bit */ 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/*Description of Frame list table structure*/ 698c2ecf20Sopenharmony_cistruct dpaa2_qdma_chan { 708c2ecf20Sopenharmony_ci struct dpaa2_qdma_engine *qdma; 718c2ecf20Sopenharmony_ci struct virt_dma_chan vchan; 728c2ecf20Sopenharmony_ci struct virt_dma_desc vdesc; 738c2ecf20Sopenharmony_ci enum dma_status status; 748c2ecf20Sopenharmony_ci u32 fqid; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci /* spinlock used by dpaa2 qdma driver */ 778c2ecf20Sopenharmony_ci spinlock_t queue_lock; 788c2ecf20Sopenharmony_ci struct dma_pool *fd_pool; 798c2ecf20Sopenharmony_ci struct dma_pool *fl_pool; 808c2ecf20Sopenharmony_ci struct dma_pool *sdd_pool; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci struct list_head comp_used; 838c2ecf20Sopenharmony_ci struct list_head comp_free; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci}; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_cistruct dpaa2_qdma_comp { 888c2ecf20Sopenharmony_ci dma_addr_t fd_bus_addr; 898c2ecf20Sopenharmony_ci dma_addr_t fl_bus_addr; 908c2ecf20Sopenharmony_ci dma_addr_t desc_bus_addr; 918c2ecf20Sopenharmony_ci struct dpaa2_fd *fd_virt_addr; 928c2ecf20Sopenharmony_ci struct dpaa2_fl_entry *fl_virt_addr; 938c2ecf20Sopenharmony_ci struct dpaa2_qdma_sd_d *desc_virt_addr; 948c2ecf20Sopenharmony_ci struct dpaa2_qdma_chan *qchan; 958c2ecf20Sopenharmony_ci struct virt_dma_desc vdesc; 968c2ecf20Sopenharmony_ci struct list_head list; 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_cistruct dpaa2_qdma_engine { 1008c2ecf20Sopenharmony_ci struct dma_device dma_dev; 1018c2ecf20Sopenharmony_ci u32 n_chans; 1028c2ecf20Sopenharmony_ci struct dpaa2_qdma_chan chans[NUM_CH]; 1038c2ecf20Sopenharmony_ci int qdma_wrtype_fixup; 1048c2ecf20Sopenharmony_ci int desc_allocated; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci struct dpaa2_qdma_priv *priv; 1078c2ecf20Sopenharmony_ci}; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci/* 1108c2ecf20Sopenharmony_ci * dpaa2_qdma_priv - driver private data 1118c2ecf20Sopenharmony_ci */ 1128c2ecf20Sopenharmony_cistruct dpaa2_qdma_priv { 1138c2ecf20Sopenharmony_ci int dpqdma_id; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci struct iommu_domain *iommu_domain; 1168c2ecf20Sopenharmony_ci struct dpdmai_attr dpdmai_attr; 1178c2ecf20Sopenharmony_ci struct device *dev; 1188c2ecf20Sopenharmony_ci struct fsl_mc_io *mc_io; 1198c2ecf20Sopenharmony_ci struct fsl_mc_device *dpdmai_dev; 1208c2ecf20Sopenharmony_ci u8 num_pairs; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci struct dpaa2_qdma_engine *dpaa2_qdma; 1238c2ecf20Sopenharmony_ci struct dpaa2_qdma_priv_per_prio *ppriv; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci struct dpdmai_rx_queue_attr rx_queue_attr[DPDMAI_PRIO_NUM]; 1268c2ecf20Sopenharmony_ci u32 tx_fqid[DPDMAI_PRIO_NUM]; 1278c2ecf20Sopenharmony_ci}; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistruct dpaa2_qdma_priv_per_prio { 1308c2ecf20Sopenharmony_ci int req_fqid; 1318c2ecf20Sopenharmony_ci int rsp_fqid; 1328c2ecf20Sopenharmony_ci int prio; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci struct dpaa2_io_store *store; 1358c2ecf20Sopenharmony_ci struct dpaa2_io_notification_ctx nctx; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci struct dpaa2_qdma_priv *priv; 1388c2ecf20Sopenharmony_ci}; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_cistatic struct soc_device_attribute soc_fixup_tuning[] = { 1418c2ecf20Sopenharmony_ci { .family = "QorIQ LX2160A"}, 1428c2ecf20Sopenharmony_ci { }, 1438c2ecf20Sopenharmony_ci}; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci/* FD pool size: one FD + 3 Frame list + 2 source/destination descriptor */ 1468c2ecf20Sopenharmony_ci#define FD_POOL_SIZE (sizeof(struct dpaa2_fd) + \ 1478c2ecf20Sopenharmony_ci sizeof(struct dpaa2_fl_entry) * 3 + \ 1488c2ecf20Sopenharmony_ci sizeof(struct dpaa2_qdma_sd_d) * 2) 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistatic void dpaa2_dpdmai_free_channels(struct dpaa2_qdma_engine *dpaa2_qdma); 1518c2ecf20Sopenharmony_cistatic void dpaa2_dpdmai_free_comp(struct dpaa2_qdma_chan *qchan, 1528c2ecf20Sopenharmony_ci struct list_head *head); 1538c2ecf20Sopenharmony_ci#endif /* __DPAA2_QDMA_H */ 154