summaryrefslogtreecommitdiffstats
path: root/drivers/dma/fsl_raid.h
blob: 69d743c04973a1e5e2a1234926b433a989fcf774 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
 * drivers/dma/fsl_raid.h
 *
 * Freescale RAID Engine device driver
 *
 * Author:
 *	Harninder Rai <harninder.rai@freescale.com>
 *	Naveen Burmi <naveenburmi@freescale.com>
 *
 * Rewrite:
 *	Xuelin Shi <xuelin.shi@freescale.com>

 * Copyright (c) 2010-2012 Freescale Semiconductor, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Freescale Semiconductor nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * ALTERNATIVELY, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") as published by the Free Software
 * Foundation, either version 2 of that License or (at your option) any
 * later version.
 *
 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#define FSL_RE_MAX_CHANS		4
#define FSL_RE_DPAA_MODE		BIT(30)
#define FSL_RE_NON_DPAA_MODE		BIT(31)
#define FSL_RE_GFM_POLY			0x1d000000
#define FSL_RE_ADD_JOB(x)		((x) << 16)
#define FSL_RE_RMVD_JOB(x)		((x) << 16)
#define FSL_RE_CFG1_CBSI		0x08000000
#define FSL_RE_CFG1_CBS0		0x00080000
#define FSL_RE_SLOT_FULL_SHIFT		8
#define FSL_RE_SLOT_FULL(x)		((x) >> FSL_RE_SLOT_FULL_SHIFT)
#define FSL_RE_SLOT_AVAIL_SHIFT		8
#define FSL_RE_SLOT_AVAIL(x)		((x) >> FSL_RE_SLOT_AVAIL_SHIFT)
#define FSL_RE_PQ_OPCODE		0x1B
#define FSL_RE_XOR_OPCODE		0x1A
#define FSL_RE_MOVE_OPCODE		0x8
#define FSL_RE_FRAME_ALIGN		16
#define FSL_RE_BLOCK_SIZE		0x3 /* 4096 bytes */
#define FSL_RE_CACHEABLE_IO		0x0
#define FSL_RE_BUFFER_OUTPUT		0x0
#define FSL_RE_INTR_ON_ERROR		0x1
#define FSL_RE_DATA_DEP			0x1
#define FSL_RE_ENABLE_DPI		0x0
#define FSL_RE_RING_SIZE		0x400
#define FSL_RE_RING_SIZE_MASK		(FSL_RE_RING_SIZE - 1)
#define FSL_RE_RING_SIZE_SHIFT		8
#define FSL_RE_ADDR_BIT_SHIFT		4
#define FSL_RE_ADDR_BIT_MASK		(BIT(FSL_RE_ADDR_BIT_SHIFT) - 1)
#define FSL_RE_ERROR			0x40000000
#define FSL_RE_INTR			0x80000000
#define FSL_RE_CLR_INTR			0x80000000
#define FSL_RE_PAUSE			0x80000000
#define FSL_RE_ENABLE			0x80000000
#define FSL_RE_REG_LIODN_MASK		0x00000FFF

#define FSL_RE_CDB_OPCODE_MASK		0xF8000000
#define FSL_RE_CDB_OPCODE_SHIFT		27
#define FSL_RE_CDB_EXCLEN_MASK		0x03000000
#define FSL_RE_CDB_EXCLEN_SHIFT		24
#define FSL_RE_CDB_EXCLQ1_MASK		0x00F00000
#define FSL_RE_CDB_EXCLQ1_SHIFT		20
#define FSL_RE_CDB_EXCLQ2_MASK		0x000F0000
#define FSL_RE_CDB_EXCLQ2_SHIFT		16
#define FSL_RE_CDB_BLKSIZE_MASK		0x0000C000
#define FSL_RE_CDB_BLKSIZE_SHIFT	14
#define FSL_RE_CDB_CACHE_MASK		0x00003000
#define FSL_RE_CDB_CACHE_SHIFT		12
#define FSL_RE_CDB_BUFFER_MASK		0x00000800
#define FSL_RE_CDB_BUFFER_SHIFT		11
#define FSL_RE_CDB_ERROR_MASK		0x00000400
#define FSL_RE_CDB_ERROR_SHIFT		10
#define FSL_RE_CDB_NRCS_MASK		0x0000003C
#define FSL_RE_CDB_NRCS_SHIFT		6
#define FSL_RE_CDB_DEPEND_MASK		0x00000008
#define FSL_RE_CDB_DEPEND_SHIFT		3
#define FSL_RE_CDB_DPI_MASK		0x00000004
#define FSL_RE_CDB_DPI_SHIFT		2

/*
 * the largest cf block is 19*sizeof(struct cmpnd_frame), which is 304 bytes.
 * here 19 = 1(cdb)+2(dest)+16(src), align to 64bytes, that is 320 bytes.
 * the largest cdb block: struct pq_cdb which is 180 bytes, adding to cf block
 * 320+180=500, align to 64bytes, that is 512 bytes.
 */
#define FSL_RE_CF_DESC_SIZE		320
#define FSL_RE_CF_CDB_SIZE		512
#define FSL_RE_CF_CDB_ALIGN		64

struct fsl_re_ctrl {
	/* General Configuration Registers */
	__be32 global_config;	/* Global Configuration Register */
	u8     rsvd1[4];
	__be32 galois_field_config; /* Galois Field Configuration Register */
	u8     rsvd2[4];
	__be32 jq_wrr_config;   /* WRR Configuration register */
	u8     rsvd3[4];
	__be32 crc_config;	/* CRC Configuration register */
	u8     rsvd4[228];
	__be32 system_reset;	/* System Reset Register */
	u8     rsvd5[252];
	__be32 global_status;	/* Global Status Register */
	u8     rsvd6[832];
	__be32 re_liodn_base;	/* LIODN Base Register */
	u8     rsvd7[1712];
	__be32 re_version_id;	/* Version ID register of RE */
	__be32 re_version_id_2; /* Version ID 2 register of RE */
	u8     rsvd8[512];
	__be32 host_config;	/* Host I/F Configuration Register */
};

struct fsl_re_chan_cfg {
	/* Registers for JR interface */
	__be32 jr_config_0;	/* Job Queue Configuration 0 Register */
	__be32 jr_config_1;	/* Job Queue Configuration 1 Register */
	__be32 jr_interrupt_status; /* Job Queue Interrupt Status Register */
	u8     rsvd1[4];
	__be32 jr_command;	/* Job Queue Command Register */
	u8     rsvd2[4];
	__be32 jr_status;	/* Job Queue Status Register */
	u8     rsvd3[228];

	/* Input Ring */
	__be32 inbring_base_h;	/* Inbound Ring Base Address Register - High */
	__be32 inbring_base_l;	/* Inbound Ring Base Address Register - Low */
	__be32 inbring_size;	/* Inbound Ring Size Register */
	u8     rsvd4[4];
	__be32 inbring_slot_avail; /* Inbound Ring Slot Available Register */
	u8     rsvd5[4];
	__be32 inbring_add_job;	/* Inbound Ring Add Job Register */
	u8     rsvd6[4];
	__be32 inbring_cnsmr_indx; /* Inbound Ring Consumer Index Register */
	u8     rsvd7[220];

	/* Output Ring */
	__be32 oubring_base_h;	/* Outbound Ring Base Address Register - High */
	__be32 oubring_base_l;	/* Outbound Ring Base Address Register - Low */
	__be32 oubring_size;	/* Outbound Ring Size Register */
	u8     rsvd8[4];
	__be32 oubring_job_rmvd; /* Outbound Ring Job Removed Register */
	u8     rsvd9[4];
	__be32 oubring_slot_full; /* Outbound Ring Slot Full Register */
	u8     rsvd10[4];
	__be32 oubring_prdcr_indx; /* Outbound Ring Producer Index */
};

/*
 * Command Descriptor Block (CDB) for unicast move command.
 * In RAID Engine terms, memcpy is done through move command
 */
struct fsl_re_move_cdb {
	__be32 cdb32;
};

/* Data protection/integrity related fields */
#define FSL_RE_DPI_APPS_MASK		0xC0000000
#define FSL_RE_DPI_APPS_SHIFT		30
#define FSL_RE_DPI_REF_MASK		0x30000000
#define FSL_RE_DPI_REF_SHIFT		28
#define FSL_RE_DPI_GUARD_MASK		0x0C000000
#define FSL_RE_DPI_GUARD_SHIFT		26
#define FSL_RE_DPI_ATTR_MASK		0x03000000
#define FSL_RE_DPI_ATTR_SHIFT		24
#define FSL_RE_DPI_META_MASK		0x0000FFFF

struct fsl_re_dpi {
	__be32 dpi32;
	__be32 ref;
};

/*
 * CDB for GenQ command. In RAID Engine terminology, XOR is
 * done through this command
 */
struct fsl_re_xor_cdb {
	__be32 cdb32;
	u8 gfm[16];
	struct fsl_re_dpi dpi_dest_spec;
	struct fsl_re_dpi dpi_src_spec[16];
};

/* CDB for no-op command */
struct fsl_re_noop_cdb {
	__be32 cdb32;
};

/*
 * CDB for GenQQ command. In RAID Engine terminology, P/Q is
 * done through this command
 */
struct fsl_re_pq_cdb {
	__be32 cdb32;
	u8 gfm_q1[16];
	u8 gfm_q2[16];
	struct fsl_re_dpi dpi_dest_spec[2];
	struct fsl_re_dpi dpi_src_spec[16];
};

/* Compound frame */
#define FSL_RE_CF_ADDR_HIGH_MASK	0x000000FF
#define FSL_RE_CF_EXT_MASK		0x80000000
#define FSL_RE_CF_EXT_SHIFT		31
#define FSL_RE_CF_FINAL_MASK		0x40000000
#define FSL_RE_CF_FINAL_SHIFT		30
#define FSL_RE_CF_LENGTH_MASK		0x000FFFFF
#define FSL_RE_CF_BPID_MASK		0x00FF0000
#define FSL_RE_CF_BPID_SHIFT		16
#define FSL_RE_CF_OFFSET_MASK		0x00001FFF

struct fsl_re_cmpnd_frame {
	__be32 addr_high;
	__be32 addr_low;
	__be32 efrl32;
	__be32 rbro32;
};

/* Frame descriptor */
#define FSL_RE_HWDESC_LIODN_MASK	0x3F000000
#define FSL_RE_HWDESC_LIODN_SHIFT	24
#define FSL_RE_HWDESC_BPID_MASK		0x00FF0000
#define FSL_RE_HWDESC_BPID_SHIFT	16
#define FSL_RE_HWDESC_ELIODN_MASK	0x0000F000
#define FSL_RE_HWDESC_ELIODN_SHIFT	12
#define FSL_RE_HWDESC_FMT_SHIFT		29
#define FSL_RE_HWDESC_FMT_MASK		(0x3 << FSL_RE_HWDESC_FMT_SHIFT)

struct fsl_re_hw_desc {
	__be32 lbea32;
	__be32 addr_low;
	__be32 fmt32;
	__be32 status;
};

/* Raid Engine device private data */
struct fsl_re_drv_private {
	u8 total_chans;
	struct dma_device dma_dev;
	struct fsl_re_ctrl *re_regs;
	struct fsl_re_chan *re_jrs[FSL_RE_MAX_CHANS];
	struct dma_pool *cf_desc_pool;
	struct dma_pool *hw_desc_pool;
};

/* Per job ring data structure */
struct fsl_re_chan {
	char name[16];
	spinlock_t desc_lock; /* queue lock */
	struct list_head ack_q;  /* wait to acked queue */
	struct list_head active_q; /* already issued on hw, not completed */
	struct list_head submit_q;
	struct list_head free_q; /* alloc available queue */
	struct device *dev;
	struct fsl_re_drv_private *re_dev;
	struct dma_chan chan;
	struct fsl_re_chan_cfg *jrregs;
	int irq;
	struct tasklet_struct irqtask;
	u32 alloc_count;

	/* hw descriptor ring for inbound queue*/
	dma_addr_t inb_phys_addr;
	struct fsl_re_hw_desc *inb_ring_virt_addr;
	u32 inb_count;

	/* hw descriptor ring for outbound queue */
	dma_addr_t oub_phys_addr;
	struct fsl_re_hw_desc *oub_ring_virt_addr;
	u32 oub_count;
};

/* Async transaction descriptor */
struct fsl_re_desc {
	struct dma_async_tx_descriptor async_tx;
	struct list_head node;
	struct fsl_re_hw_desc hwdesc;
	struct fsl_re_chan *re_chan;

	/* hwdesc will point to cf_addr */
	void *cf_addr;
	dma_addr_t cf_paddr;

	void *cdb_addr;
	dma_addr_t cdb_paddr;
	int status;
};