18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * 2006-2009 (C) DENX Software Engineering.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Author: Yuri Tikhonov <yur@emcraft.com>
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public License
78c2ecf20Sopenharmony_ci * version 2.  This program is licensed "as is" without any warranty of
88c2ecf20Sopenharmony_ci * any kind, whether express or implied.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef _PPC440SPE_ADMA_H
128c2ecf20Sopenharmony_ci#define _PPC440SPE_ADMA_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/types.h>
158c2ecf20Sopenharmony_ci#include "dma.h"
168c2ecf20Sopenharmony_ci#include "xor.h"
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define to_ppc440spe_adma_chan(chan) \
198c2ecf20Sopenharmony_ci		container_of(chan, struct ppc440spe_adma_chan, common)
208c2ecf20Sopenharmony_ci#define to_ppc440spe_adma_device(dev) \
218c2ecf20Sopenharmony_ci		container_of(dev, struct ppc440spe_adma_device, common)
228c2ecf20Sopenharmony_ci#define tx_to_ppc440spe_adma_slot(tx) \
238c2ecf20Sopenharmony_ci		container_of(tx, struct ppc440spe_adma_desc_slot, async_tx)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* Default polynomial (for 440SP is only available) */
268c2ecf20Sopenharmony_ci#define PPC440SPE_DEFAULT_POLY	0x4d
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define PPC440SPE_ADMA_ENGINES_NUM	(XOR_ENGINES_NUM + DMA_ENGINES_NUM)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define PPC440SPE_ADMA_WATCHDOG_MSEC	3
318c2ecf20Sopenharmony_ci#define PPC440SPE_ADMA_THRESHOLD	1
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define PPC440SPE_DMA0_ID	0
348c2ecf20Sopenharmony_ci#define PPC440SPE_DMA1_ID	1
358c2ecf20Sopenharmony_ci#define PPC440SPE_XOR_ID	2
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define PPC440SPE_ADMA_DMA_MAX_BYTE_COUNT	0xFFFFFFUL
388c2ecf20Sopenharmony_ci/* this is the XOR_CBBCR width */
398c2ecf20Sopenharmony_ci#define PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT	(1 << 31)
408c2ecf20Sopenharmony_ci#define PPC440SPE_ADMA_ZERO_SUM_MAX_BYTE_COUNT PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define PPC440SPE_RXOR_RUN	0
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define MQ0_CF2H_RXOR_BS_MASK	0x1FF
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#undef ADMA_LL_DEBUG
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/**
498c2ecf20Sopenharmony_ci * struct ppc440spe_adma_device - internal representation of an ADMA device
508c2ecf20Sopenharmony_ci * @dev: device
518c2ecf20Sopenharmony_ci * @dma_reg: base for DMAx register access
528c2ecf20Sopenharmony_ci * @xor_reg: base for XOR register access
538c2ecf20Sopenharmony_ci * @i2o_reg: base for I2O register access
548c2ecf20Sopenharmony_ci * @id: HW ADMA Device selector
558c2ecf20Sopenharmony_ci * @dma_desc_pool_virt: base of DMA descriptor region (CPU address)
568c2ecf20Sopenharmony_ci * @dma_desc_pool: base of DMA descriptor region (DMA address)
578c2ecf20Sopenharmony_ci * @pool_size: size of the pool
588c2ecf20Sopenharmony_ci * @irq: DMAx or XOR irq number
598c2ecf20Sopenharmony_ci * @err_irq: DMAx error irq number
608c2ecf20Sopenharmony_ci * @common: embedded struct dma_device
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_cistruct ppc440spe_adma_device {
638c2ecf20Sopenharmony_ci	struct device *dev;
648c2ecf20Sopenharmony_ci	struct dma_regs __iomem *dma_reg;
658c2ecf20Sopenharmony_ci	struct xor_regs __iomem *xor_reg;
668c2ecf20Sopenharmony_ci	struct i2o_regs __iomem *i2o_reg;
678c2ecf20Sopenharmony_ci	int id;
688c2ecf20Sopenharmony_ci	void *dma_desc_pool_virt;
698c2ecf20Sopenharmony_ci	dma_addr_t dma_desc_pool;
708c2ecf20Sopenharmony_ci	size_t pool_size;
718c2ecf20Sopenharmony_ci	int irq;
728c2ecf20Sopenharmony_ci	int err_irq;
738c2ecf20Sopenharmony_ci	struct dma_device common;
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/**
778c2ecf20Sopenharmony_ci * struct ppc440spe_adma_chan - internal representation of an ADMA channel
788c2ecf20Sopenharmony_ci * @lock: serializes enqueue/dequeue operations to the slot pool
798c2ecf20Sopenharmony_ci * @device: parent device
808c2ecf20Sopenharmony_ci * @chain: device chain view of the descriptors
818c2ecf20Sopenharmony_ci * @common: common dmaengine channel object members
828c2ecf20Sopenharmony_ci * @all_slots: complete domain of slots usable by the channel
838c2ecf20Sopenharmony_ci * @pending: allows batching of hardware operations
848c2ecf20Sopenharmony_ci * @slots_allocated: records the actual size of the descriptor slot pool
858c2ecf20Sopenharmony_ci * @hw_chain_inited: h/w descriptor chain initialization flag
868c2ecf20Sopenharmony_ci * @irq_tasklet: bottom half where ppc440spe_adma_slot_cleanup runs
878c2ecf20Sopenharmony_ci * @needs_unmap: if buffers should not be unmapped upon final processing
888c2ecf20Sopenharmony_ci * @pdest_page: P destination page for async validate operation
898c2ecf20Sopenharmony_ci * @qdest_page: Q destination page for async validate operation
908c2ecf20Sopenharmony_ci * @pdest: P dma addr for async validate operation
918c2ecf20Sopenharmony_ci * @qdest: Q dma addr for async validate operation
928c2ecf20Sopenharmony_ci */
938c2ecf20Sopenharmony_cistruct ppc440spe_adma_chan {
948c2ecf20Sopenharmony_ci	spinlock_t lock;
958c2ecf20Sopenharmony_ci	struct ppc440spe_adma_device *device;
968c2ecf20Sopenharmony_ci	struct list_head chain;
978c2ecf20Sopenharmony_ci	struct dma_chan common;
988c2ecf20Sopenharmony_ci	struct list_head all_slots;
998c2ecf20Sopenharmony_ci	struct ppc440spe_adma_desc_slot *last_used;
1008c2ecf20Sopenharmony_ci	int pending;
1018c2ecf20Sopenharmony_ci	int slots_allocated;
1028c2ecf20Sopenharmony_ci	int hw_chain_inited;
1038c2ecf20Sopenharmony_ci	struct tasklet_struct irq_tasklet;
1048c2ecf20Sopenharmony_ci	u8 needs_unmap;
1058c2ecf20Sopenharmony_ci	struct page *pdest_page;
1068c2ecf20Sopenharmony_ci	struct page *qdest_page;
1078c2ecf20Sopenharmony_ci	dma_addr_t pdest;
1088c2ecf20Sopenharmony_ci	dma_addr_t qdest;
1098c2ecf20Sopenharmony_ci};
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistruct ppc440spe_rxor {
1128c2ecf20Sopenharmony_ci	u32 addrl;
1138c2ecf20Sopenharmony_ci	u32 addrh;
1148c2ecf20Sopenharmony_ci	int len;
1158c2ecf20Sopenharmony_ci	int xor_count;
1168c2ecf20Sopenharmony_ci	int addr_count;
1178c2ecf20Sopenharmony_ci	int desc_count;
1188c2ecf20Sopenharmony_ci	int state;
1198c2ecf20Sopenharmony_ci};
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci/**
1228c2ecf20Sopenharmony_ci * struct ppc440spe_adma_desc_slot - PPC440SPE-ADMA software descriptor
1238c2ecf20Sopenharmony_ci * @phys: hardware address of the hardware descriptor chain
1248c2ecf20Sopenharmony_ci * @group_head: first operation in a transaction
1258c2ecf20Sopenharmony_ci * @hw_next: pointer to the next descriptor in chain
1268c2ecf20Sopenharmony_ci * @async_tx: support for the async_tx api
1278c2ecf20Sopenharmony_ci * @slot_node: node on the iop_adma_chan.all_slots list
1288c2ecf20Sopenharmony_ci * @chain_node: node on the op_adma_chan.chain list
1298c2ecf20Sopenharmony_ci * @group_list: list of slots that make up a multi-descriptor transaction
1308c2ecf20Sopenharmony_ci *              for example transfer lengths larger than the supported hw max
1318c2ecf20Sopenharmony_ci * @unmap_len: transaction bytecount
1328c2ecf20Sopenharmony_ci * @hw_desc: virtual address of the hardware descriptor chain
1338c2ecf20Sopenharmony_ci * @stride: currently chained or not
1348c2ecf20Sopenharmony_ci * @idx: pool index
1358c2ecf20Sopenharmony_ci * @slot_cnt: total slots used in an transaction (group of operations)
1368c2ecf20Sopenharmony_ci * @src_cnt: number of sources set in this descriptor
1378c2ecf20Sopenharmony_ci * @dst_cnt: number of destinations set in the descriptor
1388c2ecf20Sopenharmony_ci * @slots_per_op: number of slots per operation
1398c2ecf20Sopenharmony_ci * @descs_per_op: number of slot per P/Q operation see comment
1408c2ecf20Sopenharmony_ci *                for ppc440spe_prep_dma_pqxor function
1418c2ecf20Sopenharmony_ci * @flags: desc state/type
1428c2ecf20Sopenharmony_ci * @reverse_flags: 1 if a corresponding rxor address uses reversed address order
1438c2ecf20Sopenharmony_ci * @xor_check_result: result of zero sum
1448c2ecf20Sopenharmony_ci * @crc32_result: result crc calculation
1458c2ecf20Sopenharmony_ci */
1468c2ecf20Sopenharmony_cistruct ppc440spe_adma_desc_slot {
1478c2ecf20Sopenharmony_ci	dma_addr_t phys;
1488c2ecf20Sopenharmony_ci	struct ppc440spe_adma_desc_slot *group_head;
1498c2ecf20Sopenharmony_ci	struct ppc440spe_adma_desc_slot *hw_next;
1508c2ecf20Sopenharmony_ci	struct dma_async_tx_descriptor async_tx;
1518c2ecf20Sopenharmony_ci	struct list_head slot_node;
1528c2ecf20Sopenharmony_ci	struct list_head chain_node; /* node in channel ops list */
1538c2ecf20Sopenharmony_ci	struct list_head group_list; /* list */
1548c2ecf20Sopenharmony_ci	unsigned int unmap_len;
1558c2ecf20Sopenharmony_ci	void *hw_desc;
1568c2ecf20Sopenharmony_ci	u16 stride;
1578c2ecf20Sopenharmony_ci	u16 idx;
1588c2ecf20Sopenharmony_ci	u16 slot_cnt;
1598c2ecf20Sopenharmony_ci	u8 src_cnt;
1608c2ecf20Sopenharmony_ci	u8 dst_cnt;
1618c2ecf20Sopenharmony_ci	u8 slots_per_op;
1628c2ecf20Sopenharmony_ci	u8 descs_per_op;
1638c2ecf20Sopenharmony_ci	unsigned long flags;
1648c2ecf20Sopenharmony_ci	unsigned long reverse_flags[8];
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci#define PPC440SPE_DESC_INT	0	/* generate interrupt on complete */
1678c2ecf20Sopenharmony_ci#define PPC440SPE_ZERO_P	1	/* clear P destionaion */
1688c2ecf20Sopenharmony_ci#define PPC440SPE_ZERO_Q	2	/* clear Q destination */
1698c2ecf20Sopenharmony_ci#define PPC440SPE_COHERENT	3	/* src/dst are coherent */
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci#define PPC440SPE_DESC_WXOR	4	/* WXORs are in chain */
1728c2ecf20Sopenharmony_ci#define PPC440SPE_DESC_RXOR	5	/* RXOR is in chain */
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci#define PPC440SPE_DESC_RXOR123	8	/* CDB for RXOR123 operation */
1758c2ecf20Sopenharmony_ci#define PPC440SPE_DESC_RXOR124	9	/* CDB for RXOR124 operation */
1768c2ecf20Sopenharmony_ci#define PPC440SPE_DESC_RXOR125	10	/* CDB for RXOR125 operation */
1778c2ecf20Sopenharmony_ci#define PPC440SPE_DESC_RXOR12	11	/* CDB for RXOR12 operation */
1788c2ecf20Sopenharmony_ci#define PPC440SPE_DESC_RXOR_REV	12	/* CDB has srcs in reversed order */
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci#define PPC440SPE_DESC_PCHECK	13
1818c2ecf20Sopenharmony_ci#define PPC440SPE_DESC_QCHECK	14
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci#define PPC440SPE_DESC_RXOR_MSK	0x3
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci	struct ppc440spe_rxor rxor_cursor;
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	union {
1888c2ecf20Sopenharmony_ci		u32 *xor_check_result;
1898c2ecf20Sopenharmony_ci		u32 *crc32_result;
1908c2ecf20Sopenharmony_ci	};
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci#endif /* _PPC440SPE_ADMA_H */
194