Blame view

drivers/dma/mv_xor.h 6.64 KB
2025cf9e1   Thomas Gleixner   treewide: Replace...
1
  /* SPDX-License-Identifier: GPL-2.0-only */
ff7b04796   Saeed Bishara   dmaengine: DMA en...
2
3
  /*
   * Copyright (C) 2007, 2008, Marvell International Ltd.
ff7b04796   Saeed Bishara   dmaengine: DMA en...
4
5
6
7
8
9
10
11
12
   */
  
  #ifndef MV_XOR_H
  #define MV_XOR_H
  
  #include <linux/types.h>
  #include <linux/io.h>
  #include <linux/dmaengine.h>
  #include <linux/interrupt.h>
f1d25e0a9   Lior Amsalem   dmaengine: mv_xor...
13
  #define MV_XOR_POOL_SIZE		(MV_XOR_SLOT_SIZE * 3072)
ff7b04796   Saeed Bishara   dmaengine: DMA en...
14
15
  #define MV_XOR_SLOT_SIZE		64
  #define MV_XOR_THRESHOLD		1
60d151f38   Thomas Petazzoni   dma: mv_xor: allo...
16
  #define MV_XOR_MAX_CHANNELS             2
ff7b04796   Saeed Bishara   dmaengine: DMA en...
17

22843545b   Lior Amsalem   dma: mv_xor: Add ...
18
19
  #define MV_XOR_MIN_BYTE_COUNT		SZ_128
  #define MV_XOR_MAX_BYTE_COUNT		(SZ_16M - 1)
e03bc654f   Thomas Petazzoni   mv_xor: support b...
20
  /* Values for the XOR_CONFIG register */
ff7b04796   Saeed Bishara   dmaengine: DMA en...
21
22
  #define XOR_OPERATION_MODE_XOR		0
  #define XOR_OPERATION_MODE_MEMCPY	2
6f166312c   Lior Amsalem   dmaengine: mv_xor...
23
  #define XOR_OPERATION_MODE_IN_DESC      7
e03bc654f   Thomas Petazzoni   mv_xor: support b...
24
  #define XOR_DESCRIPTOR_SWAP		BIT(14)
9136291f1   Lior Amsalem   dmaengine: mv_xor...
25
  #define XOR_DESC_SUCCESS		0x40000000
ff7b04796   Saeed Bishara   dmaengine: DMA en...
26

6f166312c   Lior Amsalem   dmaengine: mv_xor...
27
28
29
  #define XOR_DESC_OPERATION_XOR          (0 << 24)
  #define XOR_DESC_OPERATION_CRC32C       (1 << 24)
  #define XOR_DESC_OPERATION_MEMCPY       (2 << 24)
0e7488ed0   Ezequiel Garcia   dma: mv_xor: Remo...
30
31
  #define XOR_DESC_DMA_OWNED		BIT(31)
  #define XOR_DESC_EOD_INT_EN		BIT(31)
82a1402ea   Ezequiel Garcia   dma: mv_xor: Fix ...
32
33
34
35
36
37
38
  #define XOR_CURR_DESC(chan)	(chan->mmr_high_base + 0x10 + (chan->idx * 4))
  #define XOR_NEXT_DESC(chan)	(chan->mmr_high_base + 0x00 + (chan->idx * 4))
  #define XOR_BYTE_COUNT(chan)	(chan->mmr_high_base + 0x20 + (chan->idx * 4))
  #define XOR_DEST_POINTER(chan)	(chan->mmr_high_base + 0xB0 + (chan->idx * 4))
  #define XOR_BLOCK_SIZE(chan)	(chan->mmr_high_base + 0xC0 + (chan->idx * 4))
  #define XOR_INIT_VALUE_LOW(chan)	(chan->mmr_high_base + 0xE0)
  #define XOR_INIT_VALUE_HIGH(chan)	(chan->mmr_high_base + 0xE4)
ff7b04796   Saeed Bishara   dmaengine: DMA en...
39
40
41
42
43
44
45
  
  #define XOR_CONFIG(chan)	(chan->mmr_base + 0x10 + (chan->idx * 4))
  #define XOR_ACTIVATION(chan)	(chan->mmr_base + 0x20 + (chan->idx * 4))
  #define XOR_INTR_CAUSE(chan)	(chan->mmr_base + 0x30)
  #define XOR_INTR_MASK(chan)	(chan->mmr_base + 0x40)
  #define XOR_ERROR_CAUSE(chan)	(chan->mmr_base + 0x50)
  #define XOR_ERROR_ADDR(chan)	(chan->mmr_base + 0x60)
0e7488ed0   Ezequiel Garcia   dma: mv_xor: Remo...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  
  #define XOR_INT_END_OF_DESC	BIT(0)
  #define XOR_INT_END_OF_CHAIN	BIT(1)
  #define XOR_INT_STOPPED		BIT(2)
  #define XOR_INT_PAUSED		BIT(3)
  #define XOR_INT_ERR_DECODE	BIT(4)
  #define XOR_INT_ERR_RDPROT	BIT(5)
  #define XOR_INT_ERR_WRPROT	BIT(6)
  #define XOR_INT_ERR_OWN		BIT(7)
  #define XOR_INT_ERR_PAR		BIT(8)
  #define XOR_INT_ERR_MBUS	BIT(9)
  
  #define XOR_INTR_ERRORS		(XOR_INT_ERR_DECODE | XOR_INT_ERR_RDPROT | \
  				 XOR_INT_ERR_WRPROT | XOR_INT_ERR_OWN    | \
  				 XOR_INT_ERR_PAR    | XOR_INT_ERR_MBUS)
ba87d1372   Lior Amsalem   dma: mv_xor: Redu...
61
  #define XOR_INTR_MASK_VALUE	(XOR_INT_END_OF_DESC | XOR_INT_END_OF_CHAIN | \
0e7488ed0   Ezequiel Garcia   dma: mv_xor: Remo...
62
  				 XOR_INT_STOPPED     | XOR_INTR_ERRORS)
ff7b04796   Saeed Bishara   dmaengine: DMA en...
63

82a1402ea   Ezequiel Garcia   dma: mv_xor: Fix ...
64
65
66
67
68
  #define WINDOW_BASE(w)		(0x50 + ((w) << 2))
  #define WINDOW_SIZE(w)		(0x70 + ((w) << 2))
  #define WINDOW_REMAP_HIGH(w)	(0x90 + ((w) << 2))
  #define WINDOW_BAR_ENABLE(chan)	(0x40 + ((chan) << 2))
  #define WINDOW_OVERRIDE_CTRL(chan)	(0xA0 + ((chan) << 2))
ff7b04796   Saeed Bishara   dmaengine: DMA en...
69

77ff7a706   Stefan Roese   dmaengine: mv_xor...
70
  #define WINDOW_COUNT		8
297eedbae   Thomas Petazzoni   dma: mv_xor: rena...
71
  struct mv_xor_device {
60d151f38   Thomas Petazzoni   dma: mv_xor: allo...
72
73
74
  	void __iomem	     *xor_base;
  	void __iomem	     *xor_high_base;
  	struct clk	     *clk;
1ef48a262   Thomas Petazzoni   dma: mv_xor: merg...
75
  	struct mv_xor_chan   *channels[MV_XOR_MAX_CHANNELS];
dd130c652   Gregory CLEMENT   dmaengine: mv_xor...
76
  	int		     xor_type;
77ff7a706   Stefan Roese   dmaengine: mv_xor...
77
78
79
  
  	u32                  win_start[WINDOW_COUNT];
  	u32                  win_end[WINDOW_COUNT];
ff7b04796   Saeed Bishara   dmaengine: DMA en...
80
81
82
83
84
  };
  
  /**
   * struct mv_xor_chan - internal representation of a XOR channel
   * @pending: allows batching of hardware operations
ff7b04796   Saeed Bishara   dmaengine: DMA en...
85
86
87
88
   * @lock: serializes enqueue/dequeue operations to the descriptors pool
   * @mmr_base: memory mapped register base
   * @idx: the index of the xor channel
   * @chain: device chain view of the descriptors
fbea28a2a   Lior Amsalem   dmaengine: mv_xor...
89
90
   * @free_slots: free slots usable by the channel
   * @allocated_slots: slots allocated by the driver
ff7b04796   Saeed Bishara   dmaengine: DMA en...
91
92
93
   * @completed_slots: slots completed by HW but still need to be acked
   * @device: parent device
   * @common: common dmaengine channel object members
ff7b04796   Saeed Bishara   dmaengine: DMA en...
94
95
   * @slots_allocated: records the actual size of the descriptor slot pool
   * @irq_tasklet: bottom half where mv_xor_slot_cleanup runs
6f166312c   Lior Amsalem   dmaengine: mv_xor...
96
   * @op_in_desc: new mode of driver, each op is writen to descriptor.
ff7b04796   Saeed Bishara   dmaengine: DMA en...
97
98
99
   */
  struct mv_xor_chan {
  	int			pending;
ff7b04796   Saeed Bishara   dmaengine: DMA en...
100
101
  	spinlock_t		lock; /* protects the descriptor slot pool */
  	void __iomem		*mmr_base;
82a1402ea   Ezequiel Garcia   dma: mv_xor: Fix ...
102
  	void __iomem		*mmr_high_base;
ff7b04796   Saeed Bishara   dmaengine: DMA en...
103
  	unsigned int		idx;
88eb92cb4   Thomas Petazzoni   dma: mv_xor: add ...
104
  	int                     irq;
ff7b04796   Saeed Bishara   dmaengine: DMA en...
105
  	struct list_head	chain;
fbea28a2a   Lior Amsalem   dmaengine: mv_xor...
106
107
  	struct list_head	free_slots;
  	struct list_head	allocated_slots;
ff7b04796   Saeed Bishara   dmaengine: DMA en...
108
  	struct list_head	completed_slots;
1ef48a262   Thomas Petazzoni   dma: mv_xor: merg...
109
110
111
112
  	dma_addr_t		dma_desc_pool;
  	void			*dma_desc_pool_virt;
  	size_t                  pool_size;
  	struct dma_device	dmadev;
98817b995   Thomas Petazzoni   dma: mv_xor: in m...
113
  	struct dma_chan		dmachan;
ff7b04796   Saeed Bishara   dmaengine: DMA en...
114
115
  	int			slots_allocated;
  	struct tasklet_struct	irq_tasklet;
6f166312c   Lior Amsalem   dmaengine: mv_xor...
116
  	int                     op_in_desc;
22843545b   Lior Amsalem   dma: mv_xor: Add ...
117
118
119
  	char			dummy_src[MV_XOR_MIN_BYTE_COUNT];
  	char			dummy_dst[MV_XOR_MIN_BYTE_COUNT];
  	dma_addr_t		dummy_src_addr, dummy_dst_addr;
8b648436e   Thomas Petazzoni   dmaengine: mv_xor...
120
  	u32                     saved_config_reg, saved_int_mask_reg;
77ff7a706   Stefan Roese   dmaengine: mv_xor...
121
122
  
  	struct mv_xor_device	*xordev;
ff7b04796   Saeed Bishara   dmaengine: DMA en...
123
124
125
126
  };
  
  /**
   * struct mv_xor_desc_slot - software descriptor
fbea28a2a   Lior Amsalem   dmaengine: mv_xor...
127
   * @node: node on the mv_xor_chan lists
ff7b04796   Saeed Bishara   dmaengine: DMA en...
128
129
   * @hw_desc: virtual address of the hardware descriptor chain
   * @phys: hardware address of the hardware descriptor chain
dfc97661b   Lior Amsalem   dma: mv_xor: Remo...
130
   * @slot_used: slot in use or not
ff7b04796   Saeed Bishara   dmaengine: DMA en...
131
   * @idx: pool index
64203b672   Dan Williams   mv_xor: implement...
132
   * @tx_list: list of slots that make up a multi-descriptor transaction
ff7b04796   Saeed Bishara   dmaengine: DMA en...
133
   * @async_tx: support for the async_tx api
ff7b04796   Saeed Bishara   dmaengine: DMA en...
134
135
   */
  struct mv_xor_desc_slot {
fbea28a2a   Lior Amsalem   dmaengine: mv_xor...
136
  	struct list_head	node;
c5db858bd   Stefan Roese   dmaengine: mv_xor...
137
  	struct list_head	sg_tx_list;
ff7b04796   Saeed Bishara   dmaengine: DMA en...
138
139
  	enum dma_transaction_type	type;
  	void			*hw_desc;
ff7b04796   Saeed Bishara   dmaengine: DMA en...
140
  	u16			idx;
ff7b04796   Saeed Bishara   dmaengine: DMA en...
141
  	struct dma_async_tx_descriptor	async_tx;
ff7b04796   Saeed Bishara   dmaengine: DMA en...
142
  };
e03bc654f   Thomas Petazzoni   mv_xor: support b...
143
144
145
146
147
148
149
150
151
152
  /*
   * This structure describes XOR descriptor size 64bytes. The
   * mv_phy_src_idx() macro must be used when indexing the values of the
   * phy_src_addr[] array. This is due to the fact that the 'descriptor
   * swap' feature, used on big endian systems, swaps descriptors data
   * within blocks of 8 bytes. So two consecutive values of the
   * phy_src_addr[] array are actually swapped in big-endian, which
   * explains the different mv_phy_src_idx() implementation.
   */
  #if defined(__LITTLE_ENDIAN)
ff7b04796   Saeed Bishara   dmaengine: DMA en...
153
154
155
156
157
158
159
160
161
162
163
  struct mv_xor_desc {
  	u32 status;		/* descriptor execution status */
  	u32 crc32_result;	/* result of CRC-32 calculation */
  	u32 desc_command;	/* type of operation to be carried out */
  	u32 phy_next_desc;	/* next descriptor address pointer */
  	u32 byte_count;		/* size of src/dst blocks in bytes */
  	u32 phy_dest_addr;	/* destination block address */
  	u32 phy_src_addr[8];	/* source block addresses */
  	u32 reserved0;
  	u32 reserved1;
  };
e03bc654f   Thomas Petazzoni   mv_xor: support b...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  #define mv_phy_src_idx(src_idx) (src_idx)
  #else
  struct mv_xor_desc {
  	u32 crc32_result;	/* result of CRC-32 calculation */
  	u32 status;		/* descriptor execution status */
  	u32 phy_next_desc;	/* next descriptor address pointer */
  	u32 desc_command;	/* type of operation to be carried out */
  	u32 phy_dest_addr;	/* destination block address */
  	u32 byte_count;		/* size of src/dst blocks in bytes */
  	u32 phy_src_addr[8];	/* source block addresses */
  	u32 reserved1;
  	u32 reserved0;
  };
  #define mv_phy_src_idx(src_idx) (src_idx ^ 1)
  #endif
ff7b04796   Saeed Bishara   dmaengine: DMA en...
179
180
181
182
183
184
  
  #define to_mv_sw_desc(addr_hw_desc)		\
  	container_of(addr_hw_desc, struct mv_xor_desc_slot, hw_desc)
  
  #define mv_hw_desc_slot_idx(hw_desc, idx)	\
  	((void *)(((unsigned long)hw_desc) + ((idx) << 5)))
ff7b04796   Saeed Bishara   dmaengine: DMA en...
185
  #endif