19952f691SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
294fb0ef4SVince Bridgers /* Altera TSE SGDMA and MSGDMA Linux driver
394fb0ef4SVince Bridgers  * Copyright (C) 2014 Altera Corporation. All rights reserved
494fb0ef4SVince Bridgers  */
594fb0ef4SVince Bridgers 
694fb0ef4SVince Bridgers #ifndef __ALTERA_MSGDMAHW_H__
794fb0ef4SVince Bridgers #define __ALTERA_MSGDMAHW_H__
894fb0ef4SVince Bridgers 
994fb0ef4SVince Bridgers /* mSGDMA extended descriptor format
1094fb0ef4SVince Bridgers  */
1194fb0ef4SVince Bridgers struct msgdma_extended_desc {
1294fb0ef4SVince Bridgers 	u32 read_addr_lo;	/* data buffer source address low bits */
1394fb0ef4SVince Bridgers 	u32 write_addr_lo;	/* data buffer destination address low bits */
1494fb0ef4SVince Bridgers 	u32 len;		/* the number of bytes to transfer
1594fb0ef4SVince Bridgers 				 * per descriptor
1694fb0ef4SVince Bridgers 				 */
1794fb0ef4SVince Bridgers 	u32 burst_seq_num;	/* bit 31:24 write burst
1894fb0ef4SVince Bridgers 				 * bit 23:16 read burst
1994fb0ef4SVince Bridgers 				 * bit 15:0  sequence number
2094fb0ef4SVince Bridgers 				 */
2194fb0ef4SVince Bridgers 	u32 stride;		/* bit 31:16 write stride
2294fb0ef4SVince Bridgers 				 * bit 15:0  read stride
2394fb0ef4SVince Bridgers 				 */
2494fb0ef4SVince Bridgers 	u32 read_addr_hi;	/* data buffer source address high bits */
2594fb0ef4SVince Bridgers 	u32 write_addr_hi;	/* data buffer destination address high bits */
2694fb0ef4SVince Bridgers 	u32 control;		/* characteristics of the transfer */
2794fb0ef4SVince Bridgers };
2894fb0ef4SVince Bridgers 
2994fb0ef4SVince Bridgers /* mSGDMA descriptor control field bit definitions
3094fb0ef4SVince Bridgers  */
3194fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_SET_CH(x)	((x) & 0xff)
3294fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_GEN_SOP		BIT(8)
3394fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_GEN_EOP		BIT(9)
3494fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_PARK_READS	BIT(10)
3594fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_PARK_WRITES	BIT(11)
3694fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_END_ON_EOP	BIT(12)
3794fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_END_ON_LEN	BIT(13)
3894fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TR_COMP_IRQ	BIT(14)
3994fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_EARLY_IRQ	BIT(15)
4094fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TR_ERR_IRQ	(0xff << 16)
4194fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_EARLY_DONE	BIT(24)
4294fb0ef4SVince Bridgers /* Writing ‘1’ to the ‘go’ bit commits the entire descriptor into the
4394fb0ef4SVince Bridgers  * descriptor FIFO(s)
4494fb0ef4SVince Bridgers  */
4594fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_GO		BIT(31)
4694fb0ef4SVince Bridgers 
4794fb0ef4SVince Bridgers /* Tx buffer control flags
4894fb0ef4SVince Bridgers  */
4994fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TX_FIRST	(MSGDMA_DESC_CTL_GEN_SOP |	\
5094fb0ef4SVince Bridgers 					 MSGDMA_DESC_CTL_GO)
5194fb0ef4SVince Bridgers 
5220d96964SChee Nouk Phoon #define MSGDMA_DESC_CTL_TX_MIDDLE	(MSGDMA_DESC_CTL_GO)
5394fb0ef4SVince Bridgers 
5494fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TX_LAST		(MSGDMA_DESC_CTL_GEN_EOP |	\
5594fb0ef4SVince Bridgers 					 MSGDMA_DESC_CTL_TR_COMP_IRQ |	\
5694fb0ef4SVince Bridgers 					 MSGDMA_DESC_CTL_GO)
5794fb0ef4SVince Bridgers 
5894fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TX_SINGLE	(MSGDMA_DESC_CTL_GEN_SOP |	\
5994fb0ef4SVince Bridgers 					 MSGDMA_DESC_CTL_GEN_EOP |	\
6094fb0ef4SVince Bridgers 					 MSGDMA_DESC_CTL_TR_COMP_IRQ |	\
6194fb0ef4SVince Bridgers 					 MSGDMA_DESC_CTL_GO)
6294fb0ef4SVince Bridgers 
6394fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_RX_SINGLE	(MSGDMA_DESC_CTL_END_ON_EOP |	\
6494fb0ef4SVince Bridgers 					 MSGDMA_DESC_CTL_END_ON_LEN |	\
6594fb0ef4SVince Bridgers 					 MSGDMA_DESC_CTL_TR_COMP_IRQ |	\
6694fb0ef4SVince Bridgers 					 MSGDMA_DESC_CTL_EARLY_IRQ |	\
6794fb0ef4SVince Bridgers 					 MSGDMA_DESC_CTL_TR_ERR_IRQ |	\
6894fb0ef4SVince Bridgers 					 MSGDMA_DESC_CTL_GO)
6994fb0ef4SVince Bridgers 
7094fb0ef4SVince Bridgers /* mSGDMA extended descriptor stride definitions
7194fb0ef4SVince Bridgers  */
7294fb0ef4SVince Bridgers #define MSGDMA_DESC_TX_STRIDE		(0x00010001)
7394fb0ef4SVince Bridgers #define MSGDMA_DESC_RX_STRIDE		(0x00010001)
7494fb0ef4SVince Bridgers 
7594fb0ef4SVince Bridgers /* mSGDMA dispatcher control and status register map
7694fb0ef4SVince Bridgers  */
7794fb0ef4SVince Bridgers struct msgdma_csr {
7894fb0ef4SVince Bridgers 	u32 status;		/* Read/Clear */
7994fb0ef4SVince Bridgers 	u32 control;		/* Read/Write */
8094fb0ef4SVince Bridgers 	u32 rw_fill_level;	/* bit 31:16 - write fill level
8194fb0ef4SVince Bridgers 				 * bit 15:0  - read fill level
8294fb0ef4SVince Bridgers 				 */
8394fb0ef4SVince Bridgers 	u32 resp_fill_level;	/* bit 15:0 */
8494fb0ef4SVince Bridgers 	u32 rw_seq_num;		/* bit 31:16 - write sequence number
8594fb0ef4SVince Bridgers 				 * bit 15:0  - read sequence number
8694fb0ef4SVince Bridgers 				 */
8794fb0ef4SVince Bridgers 	u32 pad[3];		/* reserved */
8894fb0ef4SVince Bridgers };
8994fb0ef4SVince Bridgers 
9094fb0ef4SVince Bridgers /* mSGDMA CSR status register bit definitions
9194fb0ef4SVince Bridgers  */
9294fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_BUSY			BIT(0)
9394fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_DESC_BUF_EMPTY		BIT(1)
9494fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_DESC_BUF_FULL		BIT(2)
9594fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESP_BUF_EMPTY		BIT(3)
9694fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESP_BUF_FULL		BIT(4)
9794fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED			BIT(5)
9894fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESETTING		BIT(6)
9994fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_ON_ERR		BIT(7)
10094fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_ON_EARLY	BIT(8)
10194fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_IRQ			BIT(9)
10294fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_MASK			0x3FF
10394fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_MASK_WITHOUT_IRQ	0x1FF
10494fb0ef4SVince Bridgers 
10594fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_BUSY_GET(v)			GET_BIT_VALUE(v, 0)
10694fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_DESC_BUF_EMPTY_GET(v)		GET_BIT_VALUE(v, 1)
10794fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_DESC_BUF_FULL_GET(v)		GET_BIT_VALUE(v, 2)
10894fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESP_BUF_EMPTY_GET(v)		GET_BIT_VALUE(v, 3)
10994fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESP_BUF_FULL_GET(v)		GET_BIT_VALUE(v, 4)
11094fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_GET(v)			GET_BIT_VALUE(v, 5)
11194fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESETTING_GET(v)		GET_BIT_VALUE(v, 6)
11294fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_ON_ERR_GET(v)		GET_BIT_VALUE(v, 7)
11394fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_ON_EARLY_GET(v)		GET_BIT_VALUE(v, 8)
11494fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_IRQ_GET(v)			GET_BIT_VALUE(v, 9)
11594fb0ef4SVince Bridgers 
11694fb0ef4SVince Bridgers /* mSGDMA CSR control register bit definitions
11794fb0ef4SVince Bridgers  */
11894fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_STOP			BIT(0)
11994fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_RESET			BIT(1)
12094fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_STOP_ON_ERR		BIT(2)
12194fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_STOP_ON_EARLY		BIT(3)
12294fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_GLOBAL_INTR		BIT(4)
12394fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_STOP_DESCS		BIT(5)
12494fb0ef4SVince Bridgers 
12594fb0ef4SVince Bridgers /* mSGDMA CSR fill level bits
12694fb0ef4SVince Bridgers  */
12794fb0ef4SVince Bridgers #define MSGDMA_CSR_WR_FILL_LEVEL_GET(v)		(((v) & 0xffff0000) >> 16)
12894fb0ef4SVince Bridgers #define MSGDMA_CSR_RD_FILL_LEVEL_GET(v)		((v) & 0x0000ffff)
12994fb0ef4SVince Bridgers #define MSGDMA_CSR_RESP_FILL_LEVEL_GET(v)	((v) & 0x0000ffff)
13094fb0ef4SVince Bridgers 
13194fb0ef4SVince Bridgers /* mSGDMA response register map
13294fb0ef4SVince Bridgers  */
13394fb0ef4SVince Bridgers struct msgdma_response {
13494fb0ef4SVince Bridgers 	u32 bytes_transferred;
13594fb0ef4SVince Bridgers 	u32 status;
13694fb0ef4SVince Bridgers };
13794fb0ef4SVince Bridgers 
13889830580SVince Bridgers #define msgdma_respoffs(a) (offsetof(struct msgdma_response, a))
13989830580SVince Bridgers #define msgdma_csroffs(a) (offsetof(struct msgdma_csr, a))
14089830580SVince Bridgers #define msgdma_descroffs(a) (offsetof(struct msgdma_extended_desc, a))
14189830580SVince Bridgers 
14294fb0ef4SVince Bridgers /* mSGDMA response register bit definitions
14394fb0ef4SVince Bridgers  */
14494fb0ef4SVince Bridgers #define MSGDMA_RESP_EARLY_TERM	BIT(8)
14594fb0ef4SVince Bridgers #define MSGDMA_RESP_ERR_MASK	0xFF
14694fb0ef4SVince Bridgers 
14794fb0ef4SVince Bridgers #endif /* __ALTERA_MSGDMA_H__*/
148