0001
0002
0003
0004
0005
0006 #ifndef MV_XOR_H
0007 #define MV_XOR_H
0008
0009 #include <linux/types.h>
0010 #include <linux/io.h>
0011 #include <linux/dmaengine.h>
0012 #include <linux/interrupt.h>
0013
0014 #define MV_XOR_POOL_SIZE (MV_XOR_SLOT_SIZE * 3072)
0015 #define MV_XOR_SLOT_SIZE 64
0016 #define MV_XOR_THRESHOLD 1
0017 #define MV_XOR_MAX_CHANNELS 2
0018
0019 #define MV_XOR_MIN_BYTE_COUNT SZ_128
0020 #define MV_XOR_MAX_BYTE_COUNT (SZ_16M - 1)
0021
0022
0023 #define XOR_OPERATION_MODE_XOR 0
0024 #define XOR_OPERATION_MODE_MEMCPY 2
0025 #define XOR_OPERATION_MODE_IN_DESC 7
0026 #define XOR_DESCRIPTOR_SWAP BIT(14)
0027 #define XOR_DESC_SUCCESS 0x40000000
0028
0029 #define XOR_DESC_OPERATION_XOR (0 << 24)
0030 #define XOR_DESC_OPERATION_CRC32C (1 << 24)
0031 #define XOR_DESC_OPERATION_MEMCPY (2 << 24)
0032
0033 #define XOR_DESC_DMA_OWNED BIT(31)
0034 #define XOR_DESC_EOD_INT_EN BIT(31)
0035
0036 #define XOR_CURR_DESC(chan) (chan->mmr_high_base + 0x10 + (chan->idx * 4))
0037 #define XOR_NEXT_DESC(chan) (chan->mmr_high_base + 0x00 + (chan->idx * 4))
0038 #define XOR_BYTE_COUNT(chan) (chan->mmr_high_base + 0x20 + (chan->idx * 4))
0039 #define XOR_DEST_POINTER(chan) (chan->mmr_high_base + 0xB0 + (chan->idx * 4))
0040 #define XOR_BLOCK_SIZE(chan) (chan->mmr_high_base + 0xC0 + (chan->idx * 4))
0041 #define XOR_INIT_VALUE_LOW(chan) (chan->mmr_high_base + 0xE0)
0042 #define XOR_INIT_VALUE_HIGH(chan) (chan->mmr_high_base + 0xE4)
0043
0044 #define XOR_CONFIG(chan) (chan->mmr_base + 0x10 + (chan->idx * 4))
0045 #define XOR_ACTIVATION(chan) (chan->mmr_base + 0x20 + (chan->idx * 4))
0046 #define XOR_INTR_CAUSE(chan) (chan->mmr_base + 0x30)
0047 #define XOR_INTR_MASK(chan) (chan->mmr_base + 0x40)
0048 #define XOR_ERROR_CAUSE(chan) (chan->mmr_base + 0x50)
0049 #define XOR_ERROR_ADDR(chan) (chan->mmr_base + 0x60)
0050
0051 #define XOR_INT_END_OF_DESC BIT(0)
0052 #define XOR_INT_END_OF_CHAIN BIT(1)
0053 #define XOR_INT_STOPPED BIT(2)
0054 #define XOR_INT_PAUSED BIT(3)
0055 #define XOR_INT_ERR_DECODE BIT(4)
0056 #define XOR_INT_ERR_RDPROT BIT(5)
0057 #define XOR_INT_ERR_WRPROT BIT(6)
0058 #define XOR_INT_ERR_OWN BIT(7)
0059 #define XOR_INT_ERR_PAR BIT(8)
0060 #define XOR_INT_ERR_MBUS BIT(9)
0061
0062 #define XOR_INTR_ERRORS (XOR_INT_ERR_DECODE | XOR_INT_ERR_RDPROT | \
0063 XOR_INT_ERR_WRPROT | XOR_INT_ERR_OWN | \
0064 XOR_INT_ERR_PAR | XOR_INT_ERR_MBUS)
0065
0066 #define XOR_INTR_MASK_VALUE (XOR_INT_END_OF_DESC | XOR_INT_END_OF_CHAIN | \
0067 XOR_INT_STOPPED | XOR_INTR_ERRORS)
0068
0069 #define WINDOW_BASE(w) (0x50 + ((w) << 2))
0070 #define WINDOW_SIZE(w) (0x70 + ((w) << 2))
0071 #define WINDOW_REMAP_HIGH(w) (0x90 + ((w) << 2))
0072 #define WINDOW_BAR_ENABLE(chan) (0x40 + ((chan) << 2))
0073 #define WINDOW_OVERRIDE_CTRL(chan) (0xA0 + ((chan) << 2))
0074
0075 #define WINDOW_COUNT 8
0076
0077 struct mv_xor_device {
0078 void __iomem *xor_base;
0079 void __iomem *xor_high_base;
0080 struct clk *clk;
0081 struct mv_xor_chan *channels[MV_XOR_MAX_CHANNELS];
0082 int xor_type;
0083
0084 u32 win_start[WINDOW_COUNT];
0085 u32 win_end[WINDOW_COUNT];
0086 };
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 struct mv_xor_chan {
0105 int pending;
0106 spinlock_t lock;
0107 void __iomem *mmr_base;
0108 void __iomem *mmr_high_base;
0109 unsigned int idx;
0110 int irq;
0111 struct list_head chain;
0112 struct list_head free_slots;
0113 struct list_head allocated_slots;
0114 struct list_head completed_slots;
0115 dma_addr_t dma_desc_pool;
0116 void *dma_desc_pool_virt;
0117 size_t pool_size;
0118 struct dma_device dmadev;
0119 struct dma_chan dmachan;
0120 int slots_allocated;
0121 struct tasklet_struct irq_tasklet;
0122 int op_in_desc;
0123 char dummy_src[MV_XOR_MIN_BYTE_COUNT];
0124 char dummy_dst[MV_XOR_MIN_BYTE_COUNT];
0125 dma_addr_t dummy_src_addr, dummy_dst_addr;
0126 u32 saved_config_reg, saved_int_mask_reg;
0127
0128 struct mv_xor_device *xordev;
0129 };
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 struct mv_xor_desc_slot {
0142 struct list_head node;
0143 struct list_head sg_tx_list;
0144 enum dma_transaction_type type;
0145 void *hw_desc;
0146 u16 idx;
0147 struct dma_async_tx_descriptor async_tx;
0148 };
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159 #if defined(__LITTLE_ENDIAN)
0160 struct mv_xor_desc {
0161 u32 status;
0162 u32 crc32_result;
0163 u32 desc_command;
0164 u32 phy_next_desc;
0165 u32 byte_count;
0166 u32 phy_dest_addr;
0167 u32 phy_src_addr[8];
0168 u32 reserved0;
0169 u32 reserved1;
0170 };
0171 #define mv_phy_src_idx(src_idx) (src_idx)
0172 #else
0173 struct mv_xor_desc {
0174 u32 crc32_result;
0175 u32 status;
0176 u32 phy_next_desc;
0177 u32 desc_command;
0178 u32 phy_dest_addr;
0179 u32 byte_count;
0180 u32 phy_src_addr[8];
0181 u32 reserved1;
0182 u32 reserved0;
0183 };
0184 #define mv_phy_src_idx(src_idx) (src_idx ^ 1)
0185 #endif
0186
0187 #define to_mv_sw_desc(addr_hw_desc) \
0188 container_of(addr_hw_desc, struct mv_xor_desc_slot, hw_desc)
0189
0190 #define mv_hw_desc_slot_idx(hw_desc, idx) \
0191 ((void *)(((unsigned long)hw_desc) + ((idx) << 5)))
0192
0193 #endif