194fb0ef4SVince Bridgers /* Altera TSE SGDMA and MSGDMA Linux driver 294fb0ef4SVince Bridgers * Copyright (C) 2014 Altera Corporation. All rights reserved 394fb0ef4SVince Bridgers * 494fb0ef4SVince Bridgers * This program is free software; you can redistribute it and/or modify it 594fb0ef4SVince Bridgers * under the terms and conditions of the GNU General Public License, 694fb0ef4SVince Bridgers * version 2, as published by the Free Software Foundation. 794fb0ef4SVince Bridgers * 894fb0ef4SVince Bridgers * This program is distributed in the hope it will be useful, but WITHOUT 994fb0ef4SVince Bridgers * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1094fb0ef4SVince Bridgers * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 1194fb0ef4SVince Bridgers * more details. 1294fb0ef4SVince Bridgers * 1394fb0ef4SVince Bridgers * You should have received a copy of the GNU General Public License along with 1494fb0ef4SVince Bridgers * this program. If not, see <http://www.gnu.org/licenses/>. 1594fb0ef4SVince Bridgers */ 1694fb0ef4SVince Bridgers 1794fb0ef4SVince Bridgers #ifndef __ALTERA_MSGDMAHW_H__ 1894fb0ef4SVince Bridgers #define __ALTERA_MSGDMAHW_H__ 1994fb0ef4SVince Bridgers 2094fb0ef4SVince Bridgers /* mSGDMA extended descriptor format 2194fb0ef4SVince Bridgers */ 2294fb0ef4SVince Bridgers struct msgdma_extended_desc { 2394fb0ef4SVince Bridgers u32 read_addr_lo; /* data buffer source address low bits */ 2494fb0ef4SVince Bridgers u32 write_addr_lo; /* data buffer destination address low bits */ 2594fb0ef4SVince Bridgers u32 len; /* the number of bytes to transfer 2694fb0ef4SVince Bridgers * per descriptor 2794fb0ef4SVince Bridgers */ 2894fb0ef4SVince Bridgers u32 burst_seq_num; /* bit 31:24 write burst 2994fb0ef4SVince Bridgers * bit 23:16 read burst 3094fb0ef4SVince Bridgers * bit 15:0 sequence number 3194fb0ef4SVince Bridgers */ 3294fb0ef4SVince Bridgers u32 stride; /* bit 31:16 write stride 3394fb0ef4SVince Bridgers * bit 15:0 read stride 3494fb0ef4SVince Bridgers */ 3594fb0ef4SVince Bridgers u32 read_addr_hi; /* data buffer source address high bits */ 3694fb0ef4SVince Bridgers u32 write_addr_hi; /* data buffer destination address high bits */ 3794fb0ef4SVince Bridgers u32 control; /* characteristics of the transfer */ 3894fb0ef4SVince Bridgers }; 3994fb0ef4SVince Bridgers 4094fb0ef4SVince Bridgers /* mSGDMA descriptor control field bit definitions 4194fb0ef4SVince Bridgers */ 4294fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_SET_CH(x) ((x) & 0xff) 4394fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_GEN_SOP BIT(8) 4494fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_GEN_EOP BIT(9) 4594fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_PARK_READS BIT(10) 4694fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_PARK_WRITES BIT(11) 4794fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_END_ON_EOP BIT(12) 4894fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_END_ON_LEN BIT(13) 4994fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TR_COMP_IRQ BIT(14) 5094fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_EARLY_IRQ BIT(15) 5194fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TR_ERR_IRQ (0xff << 16) 5294fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_EARLY_DONE BIT(24) 5394fb0ef4SVince Bridgers /* Writing ‘1’ to the ‘go’ bit commits the entire descriptor into the 5494fb0ef4SVince Bridgers * descriptor FIFO(s) 5594fb0ef4SVince Bridgers */ 5694fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_GO BIT(31) 5794fb0ef4SVince Bridgers 5894fb0ef4SVince Bridgers /* Tx buffer control flags 5994fb0ef4SVince Bridgers */ 6094fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TX_FIRST (MSGDMA_DESC_CTL_GEN_SOP | \ 6194fb0ef4SVince Bridgers MSGDMA_DESC_CTL_TR_ERR_IRQ | \ 6294fb0ef4SVince Bridgers MSGDMA_DESC_CTL_GO) 6394fb0ef4SVince Bridgers 6494fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TX_MIDDLE (MSGDMA_DESC_CTL_TR_ERR_IRQ | \ 6594fb0ef4SVince Bridgers MSGDMA_DESC_CTL_GO) 6694fb0ef4SVince Bridgers 6794fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TX_LAST (MSGDMA_DESC_CTL_GEN_EOP | \ 6894fb0ef4SVince Bridgers MSGDMA_DESC_CTL_TR_COMP_IRQ | \ 6994fb0ef4SVince Bridgers MSGDMA_DESC_CTL_TR_ERR_IRQ | \ 7094fb0ef4SVince Bridgers MSGDMA_DESC_CTL_GO) 7194fb0ef4SVince Bridgers 7294fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TX_SINGLE (MSGDMA_DESC_CTL_GEN_SOP | \ 7394fb0ef4SVince Bridgers MSGDMA_DESC_CTL_GEN_EOP | \ 7494fb0ef4SVince Bridgers MSGDMA_DESC_CTL_TR_COMP_IRQ | \ 7594fb0ef4SVince Bridgers MSGDMA_DESC_CTL_TR_ERR_IRQ | \ 7694fb0ef4SVince Bridgers MSGDMA_DESC_CTL_GO) 7794fb0ef4SVince Bridgers 7894fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_RX_SINGLE (MSGDMA_DESC_CTL_END_ON_EOP | \ 7994fb0ef4SVince Bridgers MSGDMA_DESC_CTL_END_ON_LEN | \ 8094fb0ef4SVince Bridgers MSGDMA_DESC_CTL_TR_COMP_IRQ | \ 8194fb0ef4SVince Bridgers MSGDMA_DESC_CTL_EARLY_IRQ | \ 8294fb0ef4SVince Bridgers MSGDMA_DESC_CTL_TR_ERR_IRQ | \ 8394fb0ef4SVince Bridgers MSGDMA_DESC_CTL_GO) 8494fb0ef4SVince Bridgers 8594fb0ef4SVince Bridgers /* mSGDMA extended descriptor stride definitions 8694fb0ef4SVince Bridgers */ 8794fb0ef4SVince Bridgers #define MSGDMA_DESC_TX_STRIDE (0x00010001) 8894fb0ef4SVince Bridgers #define MSGDMA_DESC_RX_STRIDE (0x00010001) 8994fb0ef4SVince Bridgers 9094fb0ef4SVince Bridgers /* mSGDMA dispatcher control and status register map 9194fb0ef4SVince Bridgers */ 9294fb0ef4SVince Bridgers struct msgdma_csr { 9394fb0ef4SVince Bridgers u32 status; /* Read/Clear */ 9494fb0ef4SVince Bridgers u32 control; /* Read/Write */ 9594fb0ef4SVince Bridgers u32 rw_fill_level; /* bit 31:16 - write fill level 9694fb0ef4SVince Bridgers * bit 15:0 - read fill level 9794fb0ef4SVince Bridgers */ 9894fb0ef4SVince Bridgers u32 resp_fill_level; /* bit 15:0 */ 9994fb0ef4SVince Bridgers u32 rw_seq_num; /* bit 31:16 - write sequence number 10094fb0ef4SVince Bridgers * bit 15:0 - read sequence number 10194fb0ef4SVince Bridgers */ 10294fb0ef4SVince Bridgers u32 pad[3]; /* reserved */ 10394fb0ef4SVince Bridgers }; 10494fb0ef4SVince Bridgers 10594fb0ef4SVince Bridgers /* mSGDMA CSR status register bit definitions 10694fb0ef4SVince Bridgers */ 10794fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_BUSY BIT(0) 10894fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_DESC_BUF_EMPTY BIT(1) 10994fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_DESC_BUF_FULL BIT(2) 11094fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESP_BUF_EMPTY BIT(3) 11194fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESP_BUF_FULL BIT(4) 11294fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED BIT(5) 11394fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESETTING BIT(6) 11494fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_ON_ERR BIT(7) 11594fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_ON_EARLY BIT(8) 11694fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_IRQ BIT(9) 11794fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_MASK 0x3FF 11894fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_MASK_WITHOUT_IRQ 0x1FF 11994fb0ef4SVince Bridgers 12094fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_BUSY_GET(v) GET_BIT_VALUE(v, 0) 12194fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_DESC_BUF_EMPTY_GET(v) GET_BIT_VALUE(v, 1) 12294fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_DESC_BUF_FULL_GET(v) GET_BIT_VALUE(v, 2) 12394fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESP_BUF_EMPTY_GET(v) GET_BIT_VALUE(v, 3) 12494fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESP_BUF_FULL_GET(v) GET_BIT_VALUE(v, 4) 12594fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_GET(v) GET_BIT_VALUE(v, 5) 12694fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESETTING_GET(v) GET_BIT_VALUE(v, 6) 12794fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_ON_ERR_GET(v) GET_BIT_VALUE(v, 7) 12894fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_ON_EARLY_GET(v) GET_BIT_VALUE(v, 8) 12994fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_IRQ_GET(v) GET_BIT_VALUE(v, 9) 13094fb0ef4SVince Bridgers 13194fb0ef4SVince Bridgers /* mSGDMA CSR control register bit definitions 13294fb0ef4SVince Bridgers */ 13394fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_STOP BIT(0) 13494fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_RESET BIT(1) 13594fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_STOP_ON_ERR BIT(2) 13694fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_STOP_ON_EARLY BIT(3) 13794fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_GLOBAL_INTR BIT(4) 13894fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_STOP_DESCS BIT(5) 13994fb0ef4SVince Bridgers 14094fb0ef4SVince Bridgers /* mSGDMA CSR fill level bits 14194fb0ef4SVince Bridgers */ 14294fb0ef4SVince Bridgers #define MSGDMA_CSR_WR_FILL_LEVEL_GET(v) (((v) & 0xffff0000) >> 16) 14394fb0ef4SVince Bridgers #define MSGDMA_CSR_RD_FILL_LEVEL_GET(v) ((v) & 0x0000ffff) 14494fb0ef4SVince Bridgers #define MSGDMA_CSR_RESP_FILL_LEVEL_GET(v) ((v) & 0x0000ffff) 14594fb0ef4SVince Bridgers 14694fb0ef4SVince Bridgers /* mSGDMA response register map 14794fb0ef4SVince Bridgers */ 14894fb0ef4SVince Bridgers struct msgdma_response { 14994fb0ef4SVince Bridgers u32 bytes_transferred; 15094fb0ef4SVince Bridgers u32 status; 15194fb0ef4SVince Bridgers }; 15294fb0ef4SVince Bridgers 153*89830580SVince Bridgers #define msgdma_respoffs(a) (offsetof(struct msgdma_response, a)) 154*89830580SVince Bridgers #define msgdma_csroffs(a) (offsetof(struct msgdma_csr, a)) 155*89830580SVince Bridgers #define msgdma_descroffs(a) (offsetof(struct msgdma_extended_desc, a)) 156*89830580SVince Bridgers 15794fb0ef4SVince Bridgers /* mSGDMA response register bit definitions 15894fb0ef4SVince Bridgers */ 15994fb0ef4SVince Bridgers #define MSGDMA_RESP_EARLY_TERM BIT(8) 16094fb0ef4SVince Bridgers #define MSGDMA_RESP_ERR_MASK 0xFF 16194fb0ef4SVince Bridgers 16294fb0ef4SVince Bridgers #endif /* __ALTERA_MSGDMA_H__*/ 163