blob: a30e221ed1ba75edc49b3092bd4c96dde49d50c5 [file] [log] [blame]
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001/*
2 * offload engine driver for the Marvell XOR engine
3 * Copyright (C) 2007, 2008, Marvell International Ltd.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#include <linux/init.h>
20#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Saeed Bisharaff7b0472008-07-08 11:58:36 -070022#include <linux/delay.h>
23#include <linux/dma-mapping.h>
24#include <linux/spinlock.h>
25#include <linux/interrupt.h>
26#include <linux/platform_device.h>
27#include <linux/memory.h>
Andrew Lunnc5101822012-02-19 13:30:26 +010028#include <linux/clk.h>
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +010029#include <linux/of.h>
30#include <linux/of_irq.h>
31#include <linux/irqdomain.h>
Arnd Bergmannc02cecb2012-08-24 15:21:54 +020032#include <linux/platform_data/dma-mv_xor.h>
Russell King - ARM Linuxd2ebfb32012-03-06 22:34:26 +000033
34#include "dmaengine.h"
Saeed Bisharaff7b0472008-07-08 11:58:36 -070035#include "mv_xor.h"
36
37static void mv_xor_issue_pending(struct dma_chan *chan);
38
39#define to_mv_xor_chan(chan) \
Thomas Petazzoni98817b92012-11-15 14:57:44 +010040 container_of(chan, struct mv_xor_chan, dmachan)
Saeed Bisharaff7b0472008-07-08 11:58:36 -070041
42#define to_mv_xor_slot(tx) \
43 container_of(tx, struct mv_xor_desc_slot, async_tx)
44
Thomas Petazzonic98c1782012-11-15 14:17:18 +010045#define mv_chan_to_devp(chan) \
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +010046 ((chan)->dmadev.dev)
Thomas Petazzonic98c1782012-11-15 14:17:18 +010047
Lior Amsalemdfc97662014-08-27 10:52:51 -030048static void mv_desc_init(struct mv_xor_desc_slot *desc,
49 dma_addr_t addr, u32 byte_count)
Saeed Bisharaff7b0472008-07-08 11:58:36 -070050{
51 struct mv_xor_desc *hw_desc = desc->hw_desc;
52
53 hw_desc->status = (1 << 31);
54 hw_desc->phy_next_desc = 0;
55 hw_desc->desc_command = (1 << 31);
Lior Amsalemdfc97662014-08-27 10:52:51 -030056 hw_desc->phy_dest_addr = addr;
Saeed Bisharaff7b0472008-07-08 11:58:36 -070057 hw_desc->byte_count = byte_count;
58}
59
60static void mv_desc_set_next_desc(struct mv_xor_desc_slot *desc,
61 u32 next_desc_addr)
62{
63 struct mv_xor_desc *hw_desc = desc->hw_desc;
64 BUG_ON(hw_desc->phy_next_desc);
65 hw_desc->phy_next_desc = next_desc_addr;
66}
67
68static void mv_desc_clear_next_desc(struct mv_xor_desc_slot *desc)
69{
70 struct mv_xor_desc *hw_desc = desc->hw_desc;
71 hw_desc->phy_next_desc = 0;
72}
73
Saeed Bisharaff7b0472008-07-08 11:58:36 -070074static void mv_desc_set_src_addr(struct mv_xor_desc_slot *desc,
75 int index, dma_addr_t addr)
76{
77 struct mv_xor_desc *hw_desc = desc->hw_desc;
Thomas Petazzonie03bc652013-07-29 17:42:14 +020078 hw_desc->phy_src_addr[mv_phy_src_idx(index)] = addr;
Saeed Bisharaff7b0472008-07-08 11:58:36 -070079 if (desc->type == DMA_XOR)
80 hw_desc->desc_command |= (1 << index);
81}
82
83static u32 mv_chan_get_current_desc(struct mv_xor_chan *chan)
84{
Thomas Petazzoni5733c382013-07-29 17:42:13 +020085 return readl_relaxed(XOR_CURR_DESC(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -070086}
87
88static void mv_chan_set_next_descriptor(struct mv_xor_chan *chan,
89 u32 next_desc_addr)
90{
Thomas Petazzoni5733c382013-07-29 17:42:13 +020091 writel_relaxed(next_desc_addr, XOR_NEXT_DESC(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -070092}
93
Saeed Bisharaff7b0472008-07-08 11:58:36 -070094static void mv_chan_unmask_interrupts(struct mv_xor_chan *chan)
95{
Thomas Petazzoni5733c382013-07-29 17:42:13 +020096 u32 val = readl_relaxed(XOR_INTR_MASK(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -070097 val |= XOR_INTR_MASK_VALUE << (chan->idx * 16);
Thomas Petazzoni5733c382013-07-29 17:42:13 +020098 writel_relaxed(val, XOR_INTR_MASK(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -070099}
100
101static u32 mv_chan_get_intr_cause(struct mv_xor_chan *chan)
102{
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200103 u32 intr_cause = readl_relaxed(XOR_INTR_CAUSE(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700104 intr_cause = (intr_cause >> (chan->idx * 16)) & 0xFFFF;
105 return intr_cause;
106}
107
108static int mv_is_err_intr(u32 intr_cause)
109{
110 if (intr_cause & ((1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)))
111 return 1;
112
113 return 0;
114}
115
116static void mv_xor_device_clear_eoc_cause(struct mv_xor_chan *chan)
117{
Simon Guinot86363682010-09-17 23:33:51 +0200118 u32 val = ~(1 << (chan->idx * 16));
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100119 dev_dbg(mv_chan_to_devp(chan), "%s, val 0x%08x\n", __func__, val);
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200120 writel_relaxed(val, XOR_INTR_CAUSE(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700121}
122
123static void mv_xor_device_clear_err_status(struct mv_xor_chan *chan)
124{
125 u32 val = 0xFFFF0000 >> (chan->idx * 16);
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200126 writel_relaxed(val, XOR_INTR_CAUSE(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700127}
128
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700129static void mv_set_mode(struct mv_xor_chan *chan,
130 enum dma_transaction_type type)
131{
132 u32 op_mode;
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200133 u32 config = readl_relaxed(XOR_CONFIG(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700134
135 switch (type) {
136 case DMA_XOR:
137 op_mode = XOR_OPERATION_MODE_XOR;
138 break;
139 case DMA_MEMCPY:
140 op_mode = XOR_OPERATION_MODE_MEMCPY;
141 break;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700142 default:
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100143 dev_err(mv_chan_to_devp(chan),
Joe Perches1ba151c2012-10-28 01:05:44 -0700144 "error: unsupported operation %d\n",
Thomas Petazzonia3fc74b2012-11-15 12:50:27 +0100145 type);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700146 BUG();
147 return;
148 }
149
150 config &= ~0x7;
151 config |= op_mode;
Thomas Petazzonie03bc652013-07-29 17:42:14 +0200152
153#if defined(__BIG_ENDIAN)
154 config |= XOR_DESCRIPTOR_SWAP;
155#else
156 config &= ~XOR_DESCRIPTOR_SWAP;
157#endif
158
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200159 writel_relaxed(config, XOR_CONFIG(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700160 chan->current_type = type;
161}
162
163static void mv_chan_activate(struct mv_xor_chan *chan)
164{
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100165 dev_dbg(mv_chan_to_devp(chan), " activate chan.\n");
Ezequiel Garcia5a9a55b2014-05-21 14:02:35 -0700166
167 /* writel ensures all descriptors are flushed before activation */
168 writel(BIT(0), XOR_ACTIVATION(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700169}
170
171static char mv_chan_is_busy(struct mv_xor_chan *chan)
172{
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200173 u32 state = readl_relaxed(XOR_ACTIVATION(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700174
175 state = (state >> 4) & 0x3;
176
177 return (state == 1) ? 1 : 0;
178}
179
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700180/**
181 * mv_xor_free_slots - flags descriptor slots for reuse
182 * @slot: Slot to free
183 * Caller must hold &mv_chan->lock while calling this function
184 */
185static void mv_xor_free_slots(struct mv_xor_chan *mv_chan,
186 struct mv_xor_desc_slot *slot)
187{
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100188 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d slot %p\n",
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700189 __func__, __LINE__, slot);
190
Lior Amsalemdfc97662014-08-27 10:52:51 -0300191 slot->slot_used = 0;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700192
193}
194
195/*
196 * mv_xor_start_new_chain - program the engine to operate on new chain headed by
197 * sw_desc
198 * Caller must hold &mv_chan->lock while calling this function
199 */
200static void mv_xor_start_new_chain(struct mv_xor_chan *mv_chan,
201 struct mv_xor_desc_slot *sw_desc)
202{
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100203 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d: sw_desc %p\n",
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700204 __func__, __LINE__, sw_desc);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700205
Bartlomiej Zolnierkiewicz48a9db42013-07-03 15:05:06 -0700206 /* set the hardware chain */
207 mv_chan_set_next_descriptor(mv_chan, sw_desc->async_tx.phys);
208
Lior Amsalemdfc97662014-08-27 10:52:51 -0300209 mv_chan->pending++;
Thomas Petazzoni98817b92012-11-15 14:57:44 +0100210 mv_xor_issue_pending(&mv_chan->dmachan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700211}
212
213static dma_cookie_t
214mv_xor_run_tx_complete_actions(struct mv_xor_desc_slot *desc,
215 struct mv_xor_chan *mv_chan, dma_cookie_t cookie)
216{
217 BUG_ON(desc->async_tx.cookie < 0);
218
219 if (desc->async_tx.cookie > 0) {
220 cookie = desc->async_tx.cookie;
221
222 /* call the callback (must not sleep or submit new
223 * operations to this channel)
224 */
225 if (desc->async_tx.callback)
226 desc->async_tx.callback(
227 desc->async_tx.callback_param);
228
Dan Williamsd38a8c62013-10-18 19:35:23 +0200229 dma_descriptor_unmap(&desc->async_tx);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700230 }
231
232 /* run dependent operations */
Dan Williams07f22112009-01-05 17:14:31 -0700233 dma_run_dependencies(&desc->async_tx);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700234
235 return cookie;
236}
237
238static int
239mv_xor_clean_completed_slots(struct mv_xor_chan *mv_chan)
240{
241 struct mv_xor_desc_slot *iter, *_iter;
242
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100243 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d\n", __func__, __LINE__);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700244 list_for_each_entry_safe(iter, _iter, &mv_chan->completed_slots,
245 completed_node) {
246
247 if (async_tx_test_ack(&iter->async_tx)) {
248 list_del(&iter->completed_node);
249 mv_xor_free_slots(mv_chan, iter);
250 }
251 }
252 return 0;
253}
254
255static int
256mv_xor_clean_slot(struct mv_xor_desc_slot *desc,
257 struct mv_xor_chan *mv_chan)
258{
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100259 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d: desc %p flags %d\n",
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700260 __func__, __LINE__, desc, desc->async_tx.flags);
261 list_del(&desc->chain_node);
262 /* the client is allowed to attach dependent operations
263 * until 'ack' is set
264 */
265 if (!async_tx_test_ack(&desc->async_tx)) {
266 /* move this slot to the completed_slots */
267 list_add_tail(&desc->completed_node, &mv_chan->completed_slots);
268 return 0;
269 }
270
271 mv_xor_free_slots(mv_chan, desc);
272 return 0;
273}
274
275static void __mv_xor_slot_cleanup(struct mv_xor_chan *mv_chan)
276{
277 struct mv_xor_desc_slot *iter, *_iter;
278 dma_cookie_t cookie = 0;
279 int busy = mv_chan_is_busy(mv_chan);
280 u32 current_desc = mv_chan_get_current_desc(mv_chan);
281 int seen_current = 0;
282
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100283 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d\n", __func__, __LINE__);
284 dev_dbg(mv_chan_to_devp(mv_chan), "current_desc %x\n", current_desc);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700285 mv_xor_clean_completed_slots(mv_chan);
286
287 /* free completed slots from the chain starting with
288 * the oldest descriptor
289 */
290
291 list_for_each_entry_safe(iter, _iter, &mv_chan->chain,
292 chain_node) {
293 prefetch(_iter);
294 prefetch(&_iter->async_tx);
295
296 /* do not advance past the current descriptor loaded into the
297 * hardware channel, subsequent descriptors are either in
298 * process or have not been submitted
299 */
300 if (seen_current)
301 break;
302
303 /* stop the search if we reach the current descriptor and the
304 * channel is busy
305 */
306 if (iter->async_tx.phys == current_desc) {
307 seen_current = 1;
308 if (busy)
309 break;
310 }
311
312 cookie = mv_xor_run_tx_complete_actions(iter, mv_chan, cookie);
313
314 if (mv_xor_clean_slot(iter, mv_chan))
315 break;
316 }
317
318 if ((busy == 0) && !list_empty(&mv_chan->chain)) {
319 struct mv_xor_desc_slot *chain_head;
320 chain_head = list_entry(mv_chan->chain.next,
321 struct mv_xor_desc_slot,
322 chain_node);
323
324 mv_xor_start_new_chain(mv_chan, chain_head);
325 }
326
327 if (cookie > 0)
Thomas Petazzoni98817b92012-11-15 14:57:44 +0100328 mv_chan->dmachan.completed_cookie = cookie;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700329}
330
331static void
332mv_xor_slot_cleanup(struct mv_xor_chan *mv_chan)
333{
334 spin_lock_bh(&mv_chan->lock);
335 __mv_xor_slot_cleanup(mv_chan);
336 spin_unlock_bh(&mv_chan->lock);
337}
338
339static void mv_xor_tasklet(unsigned long data)
340{
341 struct mv_xor_chan *chan = (struct mv_xor_chan *) data;
Saeed Bishara8333f652010-12-21 16:53:39 +0200342 mv_xor_slot_cleanup(chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700343}
344
345static struct mv_xor_desc_slot *
Lior Amsalemdfc97662014-08-27 10:52:51 -0300346mv_xor_alloc_slot(struct mv_xor_chan *mv_chan)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700347{
Lior Amsalemdfc97662014-08-27 10:52:51 -0300348 struct mv_xor_desc_slot *iter, *_iter;
349 int retry = 0;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700350
351 /* start search from the last allocated descrtiptor
352 * if a contiguous allocation can not be found start searching
353 * from the beginning of the list
354 */
355retry:
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700356 if (retry == 0)
357 iter = mv_chan->last_used;
358 else
359 iter = list_entry(&mv_chan->all_slots,
360 struct mv_xor_desc_slot,
361 slot_node);
362
363 list_for_each_entry_safe_continue(
364 iter, _iter, &mv_chan->all_slots, slot_node) {
Lior Amsalemdfc97662014-08-27 10:52:51 -0300365
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700366 prefetch(_iter);
367 prefetch(&_iter->async_tx);
Lior Amsalemdfc97662014-08-27 10:52:51 -0300368 if (iter->slot_used) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700369 /* give up after finding the first busy slot
370 * on the second pass through the list
371 */
372 if (retry)
373 break;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700374 continue;
375 }
376
Lior Amsalemdfc97662014-08-27 10:52:51 -0300377 /* pre-ack descriptor */
378 async_tx_ack(&iter->async_tx);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700379
Lior Amsalemdfc97662014-08-27 10:52:51 -0300380 iter->slot_used = 1;
381 INIT_LIST_HEAD(&iter->chain_node);
382 iter->async_tx.cookie = -EBUSY;
383 mv_chan->last_used = iter;
384 mv_desc_clear_next_desc(iter);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700385
Lior Amsalemdfc97662014-08-27 10:52:51 -0300386 return iter;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700387
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700388 }
389 if (!retry++)
390 goto retry;
391
392 /* try to free some slots if the allocation fails */
393 tasklet_schedule(&mv_chan->irq_tasklet);
394
395 return NULL;
396}
397
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700398/************************ DMA engine API functions ****************************/
399static dma_cookie_t
400mv_xor_tx_submit(struct dma_async_tx_descriptor *tx)
401{
402 struct mv_xor_desc_slot *sw_desc = to_mv_xor_slot(tx);
403 struct mv_xor_chan *mv_chan = to_mv_xor_chan(tx->chan);
Lior Amsalemdfc97662014-08-27 10:52:51 -0300404 struct mv_xor_desc_slot *old_chain_tail;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700405 dma_cookie_t cookie;
406 int new_hw_chain = 1;
407
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100408 dev_dbg(mv_chan_to_devp(mv_chan),
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700409 "%s sw_desc %p: async_tx %p\n",
410 __func__, sw_desc, &sw_desc->async_tx);
411
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700412 spin_lock_bh(&mv_chan->lock);
Russell King - ARM Linux884485e2012-03-06 22:34:46 +0000413 cookie = dma_cookie_assign(tx);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700414
415 if (list_empty(&mv_chan->chain))
Lior Amsalemdfc97662014-08-27 10:52:51 -0300416 list_add_tail(&sw_desc->chain_node, &mv_chan->chain);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700417 else {
418 new_hw_chain = 0;
419
420 old_chain_tail = list_entry(mv_chan->chain.prev,
421 struct mv_xor_desc_slot,
422 chain_node);
Lior Amsalemdfc97662014-08-27 10:52:51 -0300423 list_add_tail(&sw_desc->chain_node, &mv_chan->chain);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700424
Olof Johansson31fd8f52014-02-03 17:13:23 -0800425 dev_dbg(mv_chan_to_devp(mv_chan), "Append to last desc %pa\n",
426 &old_chain_tail->async_tx.phys);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700427
428 /* fix up the hardware chain */
Lior Amsalemdfc97662014-08-27 10:52:51 -0300429 mv_desc_set_next_desc(old_chain_tail, sw_desc->async_tx.phys);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700430
431 /* if the channel is not busy */
432 if (!mv_chan_is_busy(mv_chan)) {
433 u32 current_desc = mv_chan_get_current_desc(mv_chan);
434 /*
435 * and the curren desc is the end of the chain before
436 * the append, then we need to start the channel
437 */
438 if (current_desc == old_chain_tail->async_tx.phys)
439 new_hw_chain = 1;
440 }
441 }
442
443 if (new_hw_chain)
Lior Amsalemdfc97662014-08-27 10:52:51 -0300444 mv_xor_start_new_chain(mv_chan, sw_desc);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700445
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700446 spin_unlock_bh(&mv_chan->lock);
447
448 return cookie;
449}
450
451/* returns the number of allocated descriptors */
Dan Williamsaa1e6f12009-01-06 11:38:17 -0700452static int mv_xor_alloc_chan_resources(struct dma_chan *chan)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700453{
Olof Johansson31fd8f52014-02-03 17:13:23 -0800454 void *virt_desc;
455 dma_addr_t dma_desc;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700456 int idx;
457 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
458 struct mv_xor_desc_slot *slot = NULL;
Thomas Petazzonib503fa02012-11-15 15:55:30 +0100459 int num_descs_in_pool = MV_XOR_POOL_SIZE/MV_XOR_SLOT_SIZE;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700460
461 /* Allocate descriptor slots */
462 idx = mv_chan->slots_allocated;
463 while (idx < num_descs_in_pool) {
464 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
465 if (!slot) {
Ezequiel Garciab8291dd2014-08-27 10:52:49 -0300466 dev_info(mv_chan_to_devp(mv_chan),
467 "channel only initialized %d descriptor slots",
468 idx);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700469 break;
470 }
Olof Johansson31fd8f52014-02-03 17:13:23 -0800471 virt_desc = mv_chan->dma_desc_pool_virt;
472 slot->hw_desc = virt_desc + idx * MV_XOR_SLOT_SIZE;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700473
474 dma_async_tx_descriptor_init(&slot->async_tx, chan);
475 slot->async_tx.tx_submit = mv_xor_tx_submit;
476 INIT_LIST_HEAD(&slot->chain_node);
477 INIT_LIST_HEAD(&slot->slot_node);
Olof Johansson31fd8f52014-02-03 17:13:23 -0800478 dma_desc = mv_chan->dma_desc_pool;
479 slot->async_tx.phys = dma_desc + idx * MV_XOR_SLOT_SIZE;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700480 slot->idx = idx++;
481
482 spin_lock_bh(&mv_chan->lock);
483 mv_chan->slots_allocated = idx;
484 list_add_tail(&slot->slot_node, &mv_chan->all_slots);
485 spin_unlock_bh(&mv_chan->lock);
486 }
487
488 if (mv_chan->slots_allocated && !mv_chan->last_used)
489 mv_chan->last_used = list_entry(mv_chan->all_slots.next,
490 struct mv_xor_desc_slot,
491 slot_node);
492
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100493 dev_dbg(mv_chan_to_devp(mv_chan),
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700494 "allocated %d descriptor slots last_used: %p\n",
495 mv_chan->slots_allocated, mv_chan->last_used);
496
497 return mv_chan->slots_allocated ? : -ENOMEM;
498}
499
500static struct dma_async_tx_descriptor *
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700501mv_xor_prep_dma_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
502 unsigned int src_cnt, size_t len, unsigned long flags)
503{
504 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
Lior Amsalemdfc97662014-08-27 10:52:51 -0300505 struct mv_xor_desc_slot *sw_desc;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700506
507 if (unlikely(len < MV_XOR_MIN_BYTE_COUNT))
508 return NULL;
509
Coly Li7912d302011-03-27 01:26:53 +0800510 BUG_ON(len > MV_XOR_MAX_BYTE_COUNT);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700511
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100512 dev_dbg(mv_chan_to_devp(mv_chan),
Olof Johansson31fd8f52014-02-03 17:13:23 -0800513 "%s src_cnt: %d len: %u dest %pad flags: %ld\n",
514 __func__, src_cnt, len, &dest, flags);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700515
516 spin_lock_bh(&mv_chan->lock);
Lior Amsalemdfc97662014-08-27 10:52:51 -0300517 sw_desc = mv_xor_alloc_slot(mv_chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700518 if (sw_desc) {
519 sw_desc->type = DMA_XOR;
520 sw_desc->async_tx.flags = flags;
Lior Amsalemdfc97662014-08-27 10:52:51 -0300521 mv_desc_init(sw_desc, dest, len);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700522 sw_desc->unmap_src_cnt = src_cnt;
523 sw_desc->unmap_len = len;
524 while (src_cnt--)
Lior Amsalemdfc97662014-08-27 10:52:51 -0300525 mv_desc_set_src_addr(sw_desc, src_cnt, src[src_cnt]);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700526 }
527 spin_unlock_bh(&mv_chan->lock);
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100528 dev_dbg(mv_chan_to_devp(mv_chan),
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700529 "%s sw_desc %p async_tx %p \n",
530 __func__, sw_desc, &sw_desc->async_tx);
531 return sw_desc ? &sw_desc->async_tx : NULL;
532}
533
Lior Amsalem3e4f52e2014-08-27 10:52:50 -0300534static struct dma_async_tx_descriptor *
535mv_xor_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
536 size_t len, unsigned long flags)
537{
538 /*
539 * A MEMCPY operation is identical to an XOR operation with only
540 * a single source address.
541 */
542 return mv_xor_prep_dma_xor(chan, dest, &src, 1, len, flags);
543}
544
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700545static void mv_xor_free_chan_resources(struct dma_chan *chan)
546{
547 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
548 struct mv_xor_desc_slot *iter, *_iter;
549 int in_use_descs = 0;
550
551 mv_xor_slot_cleanup(mv_chan);
552
553 spin_lock_bh(&mv_chan->lock);
554 list_for_each_entry_safe(iter, _iter, &mv_chan->chain,
555 chain_node) {
556 in_use_descs++;
557 list_del(&iter->chain_node);
558 }
559 list_for_each_entry_safe(iter, _iter, &mv_chan->completed_slots,
560 completed_node) {
561 in_use_descs++;
562 list_del(&iter->completed_node);
563 }
564 list_for_each_entry_safe_reverse(
565 iter, _iter, &mv_chan->all_slots, slot_node) {
566 list_del(&iter->slot_node);
567 kfree(iter);
568 mv_chan->slots_allocated--;
569 }
570 mv_chan->last_used = NULL;
571
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100572 dev_dbg(mv_chan_to_devp(mv_chan), "%s slots_allocated %d\n",
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700573 __func__, mv_chan->slots_allocated);
574 spin_unlock_bh(&mv_chan->lock);
575
576 if (in_use_descs)
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100577 dev_err(mv_chan_to_devp(mv_chan),
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700578 "freeing %d in use descriptors!\n", in_use_descs);
579}
580
581/**
Linus Walleij07934482010-03-26 16:50:49 -0700582 * mv_xor_status - poll the status of an XOR transaction
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700583 * @chan: XOR channel handle
584 * @cookie: XOR transaction identifier
Linus Walleij07934482010-03-26 16:50:49 -0700585 * @txstate: XOR transactions state holder (or NULL)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700586 */
Linus Walleij07934482010-03-26 16:50:49 -0700587static enum dma_status mv_xor_status(struct dma_chan *chan,
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700588 dma_cookie_t cookie,
Linus Walleij07934482010-03-26 16:50:49 -0700589 struct dma_tx_state *txstate)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700590{
591 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700592 enum dma_status ret;
593
Russell King - ARM Linux96a2af42012-03-06 22:35:27 +0000594 ret = dma_cookie_status(chan, cookie, txstate);
Vinod Koulb3efb8f2013-10-16 20:51:04 +0530595 if (ret == DMA_COMPLETE) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700596 mv_xor_clean_completed_slots(mv_chan);
597 return ret;
598 }
599 mv_xor_slot_cleanup(mv_chan);
600
Russell King - ARM Linux96a2af42012-03-06 22:35:27 +0000601 return dma_cookie_status(chan, cookie, txstate);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700602}
603
604static void mv_dump_xor_regs(struct mv_xor_chan *chan)
605{
606 u32 val;
607
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200608 val = readl_relaxed(XOR_CONFIG(chan));
Joe Perches1ba151c2012-10-28 01:05:44 -0700609 dev_err(mv_chan_to_devp(chan), "config 0x%08x\n", val);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700610
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200611 val = readl_relaxed(XOR_ACTIVATION(chan));
Joe Perches1ba151c2012-10-28 01:05:44 -0700612 dev_err(mv_chan_to_devp(chan), "activation 0x%08x\n", val);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700613
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200614 val = readl_relaxed(XOR_INTR_CAUSE(chan));
Joe Perches1ba151c2012-10-28 01:05:44 -0700615 dev_err(mv_chan_to_devp(chan), "intr cause 0x%08x\n", val);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700616
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200617 val = readl_relaxed(XOR_INTR_MASK(chan));
Joe Perches1ba151c2012-10-28 01:05:44 -0700618 dev_err(mv_chan_to_devp(chan), "intr mask 0x%08x\n", val);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700619
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200620 val = readl_relaxed(XOR_ERROR_CAUSE(chan));
Joe Perches1ba151c2012-10-28 01:05:44 -0700621 dev_err(mv_chan_to_devp(chan), "error cause 0x%08x\n", val);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700622
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200623 val = readl_relaxed(XOR_ERROR_ADDR(chan));
Joe Perches1ba151c2012-10-28 01:05:44 -0700624 dev_err(mv_chan_to_devp(chan), "error addr 0x%08x\n", val);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700625}
626
627static void mv_xor_err_interrupt_handler(struct mv_xor_chan *chan,
628 u32 intr_cause)
629{
630 if (intr_cause & (1 << 4)) {
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100631 dev_dbg(mv_chan_to_devp(chan),
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700632 "ignore this error\n");
633 return;
634 }
635
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100636 dev_err(mv_chan_to_devp(chan),
Joe Perches1ba151c2012-10-28 01:05:44 -0700637 "error on chan %d. intr cause 0x%08x\n",
Thomas Petazzonia3fc74b2012-11-15 12:50:27 +0100638 chan->idx, intr_cause);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700639
640 mv_dump_xor_regs(chan);
641 BUG();
642}
643
644static irqreturn_t mv_xor_interrupt_handler(int irq, void *data)
645{
646 struct mv_xor_chan *chan = data;
647 u32 intr_cause = mv_chan_get_intr_cause(chan);
648
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100649 dev_dbg(mv_chan_to_devp(chan), "intr cause %x\n", intr_cause);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700650
651 if (mv_is_err_intr(intr_cause))
652 mv_xor_err_interrupt_handler(chan, intr_cause);
653
654 tasklet_schedule(&chan->irq_tasklet);
655
656 mv_xor_device_clear_eoc_cause(chan);
657
658 return IRQ_HANDLED;
659}
660
661static void mv_xor_issue_pending(struct dma_chan *chan)
662{
663 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
664
665 if (mv_chan->pending >= MV_XOR_THRESHOLD) {
666 mv_chan->pending = 0;
667 mv_chan_activate(mv_chan);
668 }
669}
670
671/*
672 * Perform a transaction to verify the HW works.
673 */
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700674
Linus Torvaldsc2714332012-12-14 14:54:26 -0800675static int mv_xor_memcpy_self_test(struct mv_xor_chan *mv_chan)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700676{
677 int i;
678 void *src, *dest;
679 dma_addr_t src_dma, dest_dma;
680 struct dma_chan *dma_chan;
681 dma_cookie_t cookie;
682 struct dma_async_tx_descriptor *tx;
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300683 struct dmaengine_unmap_data *unmap;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700684 int err = 0;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700685
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300686 src = kmalloc(sizeof(u8) * PAGE_SIZE, GFP_KERNEL);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700687 if (!src)
688 return -ENOMEM;
689
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300690 dest = kzalloc(sizeof(u8) * PAGE_SIZE, GFP_KERNEL);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700691 if (!dest) {
692 kfree(src);
693 return -ENOMEM;
694 }
695
696 /* Fill in src buffer */
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300697 for (i = 0; i < PAGE_SIZE; i++)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700698 ((u8 *) src)[i] = (u8)i;
699
Thomas Petazzoni275cc0c2012-11-15 15:09:42 +0100700 dma_chan = &mv_chan->dmachan;
Dan Williamsaa1e6f12009-01-06 11:38:17 -0700701 if (mv_xor_alloc_chan_resources(dma_chan) < 1) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700702 err = -ENODEV;
703 goto out;
704 }
705
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300706 unmap = dmaengine_get_unmap_data(dma_chan->device->dev, 2, GFP_KERNEL);
707 if (!unmap) {
708 err = -ENOMEM;
709 goto free_resources;
710 }
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700711
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300712 src_dma = dma_map_page(dma_chan->device->dev, virt_to_page(src), 0,
713 PAGE_SIZE, DMA_TO_DEVICE);
714 unmap->to_cnt = 1;
715 unmap->addr[0] = src_dma;
716
717 dest_dma = dma_map_page(dma_chan->device->dev, virt_to_page(dest), 0,
718 PAGE_SIZE, DMA_FROM_DEVICE);
719 unmap->from_cnt = 1;
720 unmap->addr[1] = dest_dma;
721
722 unmap->len = PAGE_SIZE;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700723
724 tx = mv_xor_prep_dma_memcpy(dma_chan, dest_dma, src_dma,
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300725 PAGE_SIZE, 0);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700726 cookie = mv_xor_tx_submit(tx);
727 mv_xor_issue_pending(dma_chan);
728 async_tx_ack(tx);
729 msleep(1);
730
Linus Walleij07934482010-03-26 16:50:49 -0700731 if (mv_xor_status(dma_chan, cookie, NULL) !=
Vinod Koulb3efb8f2013-10-16 20:51:04 +0530732 DMA_COMPLETE) {
Thomas Petazzonia3fc74b2012-11-15 12:50:27 +0100733 dev_err(dma_chan->device->dev,
734 "Self-test copy timed out, disabling\n");
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700735 err = -ENODEV;
736 goto free_resources;
737 }
738
Thomas Petazzonic35064c2012-11-15 13:01:59 +0100739 dma_sync_single_for_cpu(dma_chan->device->dev, dest_dma,
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300740 PAGE_SIZE, DMA_FROM_DEVICE);
741 if (memcmp(src, dest, PAGE_SIZE)) {
Thomas Petazzonia3fc74b2012-11-15 12:50:27 +0100742 dev_err(dma_chan->device->dev,
743 "Self-test copy failed compare, disabling\n");
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700744 err = -ENODEV;
745 goto free_resources;
746 }
747
748free_resources:
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300749 dmaengine_unmap_put(unmap);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700750 mv_xor_free_chan_resources(dma_chan);
751out:
752 kfree(src);
753 kfree(dest);
754 return err;
755}
756
757#define MV_XOR_NUM_SRC_TEST 4 /* must be <= 15 */
Bill Pemberton463a1f82012-11-19 13:22:55 -0500758static int
Thomas Petazzoni275cc0c2012-11-15 15:09:42 +0100759mv_xor_xor_self_test(struct mv_xor_chan *mv_chan)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700760{
761 int i, src_idx;
762 struct page *dest;
763 struct page *xor_srcs[MV_XOR_NUM_SRC_TEST];
764 dma_addr_t dma_srcs[MV_XOR_NUM_SRC_TEST];
765 dma_addr_t dest_dma;
766 struct dma_async_tx_descriptor *tx;
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300767 struct dmaengine_unmap_data *unmap;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700768 struct dma_chan *dma_chan;
769 dma_cookie_t cookie;
770 u8 cmp_byte = 0;
771 u32 cmp_word;
772 int err = 0;
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300773 int src_count = MV_XOR_NUM_SRC_TEST;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700774
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300775 for (src_idx = 0; src_idx < src_count; src_idx++) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700776 xor_srcs[src_idx] = alloc_page(GFP_KERNEL);
Roel Kluina09b09a2009-02-25 13:56:21 +0100777 if (!xor_srcs[src_idx]) {
778 while (src_idx--)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700779 __free_page(xor_srcs[src_idx]);
Roel Kluina09b09a2009-02-25 13:56:21 +0100780 return -ENOMEM;
781 }
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700782 }
783
784 dest = alloc_page(GFP_KERNEL);
Roel Kluina09b09a2009-02-25 13:56:21 +0100785 if (!dest) {
786 while (src_idx--)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700787 __free_page(xor_srcs[src_idx]);
Roel Kluina09b09a2009-02-25 13:56:21 +0100788 return -ENOMEM;
789 }
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700790
791 /* Fill in src buffers */
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300792 for (src_idx = 0; src_idx < src_count; src_idx++) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700793 u8 *ptr = page_address(xor_srcs[src_idx]);
794 for (i = 0; i < PAGE_SIZE; i++)
795 ptr[i] = (1 << src_idx);
796 }
797
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300798 for (src_idx = 0; src_idx < src_count; src_idx++)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700799 cmp_byte ^= (u8) (1 << src_idx);
800
801 cmp_word = (cmp_byte << 24) | (cmp_byte << 16) |
802 (cmp_byte << 8) | cmp_byte;
803
804 memset(page_address(dest), 0, PAGE_SIZE);
805
Thomas Petazzoni275cc0c2012-11-15 15:09:42 +0100806 dma_chan = &mv_chan->dmachan;
Dan Williamsaa1e6f12009-01-06 11:38:17 -0700807 if (mv_xor_alloc_chan_resources(dma_chan) < 1) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700808 err = -ENODEV;
809 goto out;
810 }
811
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300812 unmap = dmaengine_get_unmap_data(dma_chan->device->dev, src_count + 1,
813 GFP_KERNEL);
814 if (!unmap) {
815 err = -ENOMEM;
816 goto free_resources;
817 }
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700818
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300819 /* test xor */
820 for (i = 0; i < src_count; i++) {
821 unmap->addr[i] = dma_map_page(dma_chan->device->dev, xor_srcs[i],
822 0, PAGE_SIZE, DMA_TO_DEVICE);
823 dma_srcs[i] = unmap->addr[i];
824 unmap->to_cnt++;
825 }
826
827 unmap->addr[src_count] = dma_map_page(dma_chan->device->dev, dest, 0, PAGE_SIZE,
828 DMA_FROM_DEVICE);
829 dest_dma = unmap->addr[src_count];
830 unmap->from_cnt = 1;
831 unmap->len = PAGE_SIZE;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700832
833 tx = mv_xor_prep_dma_xor(dma_chan, dest_dma, dma_srcs,
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300834 src_count, PAGE_SIZE, 0);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700835
836 cookie = mv_xor_tx_submit(tx);
837 mv_xor_issue_pending(dma_chan);
838 async_tx_ack(tx);
839 msleep(8);
840
Linus Walleij07934482010-03-26 16:50:49 -0700841 if (mv_xor_status(dma_chan, cookie, NULL) !=
Vinod Koulb3efb8f2013-10-16 20:51:04 +0530842 DMA_COMPLETE) {
Thomas Petazzonia3fc74b2012-11-15 12:50:27 +0100843 dev_err(dma_chan->device->dev,
844 "Self-test xor timed out, disabling\n");
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700845 err = -ENODEV;
846 goto free_resources;
847 }
848
Thomas Petazzonic35064c2012-11-15 13:01:59 +0100849 dma_sync_single_for_cpu(dma_chan->device->dev, dest_dma,
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700850 PAGE_SIZE, DMA_FROM_DEVICE);
851 for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) {
852 u32 *ptr = page_address(dest);
853 if (ptr[i] != cmp_word) {
Thomas Petazzonia3fc74b2012-11-15 12:50:27 +0100854 dev_err(dma_chan->device->dev,
Joe Perches1ba151c2012-10-28 01:05:44 -0700855 "Self-test xor failed compare, disabling. index %d, data %x, expected %x\n",
856 i, ptr[i], cmp_word);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700857 err = -ENODEV;
858 goto free_resources;
859 }
860 }
861
862free_resources:
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300863 dmaengine_unmap_put(unmap);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700864 mv_xor_free_chan_resources(dma_chan);
865out:
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300866 src_idx = src_count;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700867 while (src_idx--)
868 __free_page(xor_srcs[src_idx]);
869 __free_page(dest);
870 return err;
871}
872
Andrew Lunn34c93c82012-11-18 11:44:56 +0100873/* This driver does not implement any of the optional DMA operations. */
874static int
875mv_xor_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
876 unsigned long arg)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700877{
Andrew Lunn34c93c82012-11-18 11:44:56 +0100878 return -ENOSYS;
879}
880
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100881static int mv_xor_channel_remove(struct mv_xor_chan *mv_chan)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700882{
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700883 struct dma_chan *chan, *_chan;
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100884 struct device *dev = mv_chan->dmadev.dev;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700885
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100886 dma_async_device_unregister(&mv_chan->dmadev);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700887
Thomas Petazzonib503fa02012-11-15 15:55:30 +0100888 dma_free_coherent(dev, MV_XOR_POOL_SIZE,
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100889 mv_chan->dma_desc_pool_virt, mv_chan->dma_desc_pool);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700890
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100891 list_for_each_entry_safe(chan, _chan, &mv_chan->dmadev.channels,
Thomas Petazzonia6b4a9d2012-10-29 16:45:46 +0100892 device_node) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700893 list_del(&chan->device_node);
894 }
895
Thomas Petazzoni88eb92c2012-11-15 16:11:18 +0100896 free_irq(mv_chan->irq, mv_chan);
897
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700898 return 0;
899}
900
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100901static struct mv_xor_chan *
Thomas Petazzoni297eedb2012-11-15 15:29:53 +0100902mv_xor_channel_add(struct mv_xor_device *xordev,
Thomas Petazzonia6b4a9d2012-10-29 16:45:46 +0100903 struct platform_device *pdev,
Thomas Petazzonib503fa02012-11-15 15:55:30 +0100904 int idx, dma_cap_mask_t cap_mask, int irq)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700905{
906 int ret = 0;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700907 struct mv_xor_chan *mv_chan;
908 struct dma_device *dma_dev;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700909
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100910 mv_chan = devm_kzalloc(&pdev->dev, sizeof(*mv_chan), GFP_KERNEL);
Sachin Kamata5776592013-09-02 13:54:20 +0530911 if (!mv_chan)
912 return ERR_PTR(-ENOMEM);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700913
Thomas Petazzoni9aedbdb2012-11-15 15:36:37 +0100914 mv_chan->idx = idx;
Thomas Petazzoni88eb92c2012-11-15 16:11:18 +0100915 mv_chan->irq = irq;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700916
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100917 dma_dev = &mv_chan->dmadev;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700918
919 /* allocate coherent memory for hardware descriptors
920 * note: writecombine gives slightly better performance, but
921 * requires that we explicitly flush the writes
922 */
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100923 mv_chan->dma_desc_pool_virt =
Thomas Petazzonib503fa02012-11-15 15:55:30 +0100924 dma_alloc_writecombine(&pdev->dev, MV_XOR_POOL_SIZE,
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100925 &mv_chan->dma_desc_pool, GFP_KERNEL);
926 if (!mv_chan->dma_desc_pool_virt)
Thomas Petazzonia6b4a9d2012-10-29 16:45:46 +0100927 return ERR_PTR(-ENOMEM);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700928
929 /* discover transaction capabilites from the platform data */
Thomas Petazzonia6b4a9d2012-10-29 16:45:46 +0100930 dma_dev->cap_mask = cap_mask;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700931
932 INIT_LIST_HEAD(&dma_dev->channels);
933
934 /* set base routines */
935 dma_dev->device_alloc_chan_resources = mv_xor_alloc_chan_resources;
936 dma_dev->device_free_chan_resources = mv_xor_free_chan_resources;
Linus Walleij07934482010-03-26 16:50:49 -0700937 dma_dev->device_tx_status = mv_xor_status;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700938 dma_dev->device_issue_pending = mv_xor_issue_pending;
Andrew Lunn34c93c82012-11-18 11:44:56 +0100939 dma_dev->device_control = mv_xor_control;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700940 dma_dev->dev = &pdev->dev;
941
942 /* set prep routines based on capability */
943 if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask))
944 dma_dev->device_prep_dma_memcpy = mv_xor_prep_dma_memcpy;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700945 if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
Joe Perchesc0198942009-06-28 09:26:21 -0700946 dma_dev->max_xor = 8;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700947 dma_dev->device_prep_dma_xor = mv_xor_prep_dma_xor;
948 }
949
Thomas Petazzoni297eedb2012-11-15 15:29:53 +0100950 mv_chan->mmr_base = xordev->xor_base;
Ezequiel Garcia82a14022013-10-30 12:01:43 -0300951 mv_chan->mmr_high_base = xordev->xor_high_base;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700952 tasklet_init(&mv_chan->irq_tasklet, mv_xor_tasklet, (unsigned long)
953 mv_chan);
954
955 /* clear errors before enabling interrupts */
956 mv_xor_device_clear_err_status(mv_chan);
957
Thomas Petazzoni2d0a0742012-11-22 18:19:09 +0100958 ret = request_irq(mv_chan->irq, mv_xor_interrupt_handler,
959 0, dev_name(&pdev->dev), mv_chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700960 if (ret)
961 goto err_free_dma;
962
963 mv_chan_unmask_interrupts(mv_chan);
964
Lior Amsalem3e4f52e2014-08-27 10:52:50 -0300965 mv_set_mode(mv_chan, DMA_XOR);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700966
967 spin_lock_init(&mv_chan->lock);
968 INIT_LIST_HEAD(&mv_chan->chain);
969 INIT_LIST_HEAD(&mv_chan->completed_slots);
970 INIT_LIST_HEAD(&mv_chan->all_slots);
Thomas Petazzoni98817b92012-11-15 14:57:44 +0100971 mv_chan->dmachan.device = dma_dev;
972 dma_cookie_init(&mv_chan->dmachan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700973
Thomas Petazzoni98817b92012-11-15 14:57:44 +0100974 list_add_tail(&mv_chan->dmachan.device_node, &dma_dev->channels);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700975
976 if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
Thomas Petazzoni275cc0c2012-11-15 15:09:42 +0100977 ret = mv_xor_memcpy_self_test(mv_chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700978 dev_dbg(&pdev->dev, "memcpy self test returned %d\n", ret);
979 if (ret)
Thomas Petazzoni2d0a0742012-11-22 18:19:09 +0100980 goto err_free_irq;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700981 }
982
983 if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
Thomas Petazzoni275cc0c2012-11-15 15:09:42 +0100984 ret = mv_xor_xor_self_test(mv_chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700985 dev_dbg(&pdev->dev, "xor self test returned %d\n", ret);
986 if (ret)
Thomas Petazzoni2d0a0742012-11-22 18:19:09 +0100987 goto err_free_irq;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700988 }
989
Bartlomiej Zolnierkiewicz48a9db42013-07-03 15:05:06 -0700990 dev_info(&pdev->dev, "Marvell XOR: ( %s%s%s)\n",
Joe Perches1ba151c2012-10-28 01:05:44 -0700991 dma_has_cap(DMA_XOR, dma_dev->cap_mask) ? "xor " : "",
Joe Perches1ba151c2012-10-28 01:05:44 -0700992 dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask) ? "cpy " : "",
993 dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : "");
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700994
995 dma_async_device_register(dma_dev);
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100996 return mv_chan;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700997
Thomas Petazzoni2d0a0742012-11-22 18:19:09 +0100998err_free_irq:
999 free_irq(mv_chan->irq, mv_chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001000 err_free_dma:
Thomas Petazzonib503fa02012-11-15 15:55:30 +01001001 dma_free_coherent(&pdev->dev, MV_XOR_POOL_SIZE,
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +01001002 mv_chan->dma_desc_pool_virt, mv_chan->dma_desc_pool);
Thomas Petazzonia6b4a9d2012-10-29 16:45:46 +01001003 return ERR_PTR(ret);
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001004}
1005
1006static void
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001007mv_xor_conf_mbus_windows(struct mv_xor_device *xordev,
Andrew Lunn63a93322011-12-07 21:48:07 +01001008 const struct mbus_dram_target_info *dram)
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001009{
Ezequiel Garcia82a14022013-10-30 12:01:43 -03001010 void __iomem *base = xordev->xor_high_base;
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001011 u32 win_enable = 0;
1012 int i;
1013
1014 for (i = 0; i < 8; i++) {
1015 writel(0, base + WINDOW_BASE(i));
1016 writel(0, base + WINDOW_SIZE(i));
1017 if (i < 4)
1018 writel(0, base + WINDOW_REMAP_HIGH(i));
1019 }
1020
1021 for (i = 0; i < dram->num_cs; i++) {
Andrew Lunn63a93322011-12-07 21:48:07 +01001022 const struct mbus_dram_window *cs = dram->cs + i;
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001023
1024 writel((cs->base & 0xffff0000) |
1025 (cs->mbus_attr << 8) |
1026 dram->mbus_dram_target_id, base + WINDOW_BASE(i));
1027 writel((cs->size - 1) & 0xffff0000, base + WINDOW_SIZE(i));
1028
1029 win_enable |= (1 << i);
1030 win_enable |= 3 << (16 + (2 * i));
1031 }
1032
1033 writel(win_enable, base + WINDOW_BAR_ENABLE(0));
1034 writel(win_enable, base + WINDOW_BAR_ENABLE(1));
Thomas Petazzonic4b4b732012-11-22 18:16:37 +01001035 writel(0, base + WINDOW_OVERRIDE_CTRL(0));
1036 writel(0, base + WINDOW_OVERRIDE_CTRL(1));
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001037}
1038
Linus Torvaldsc2714332012-12-14 14:54:26 -08001039static int mv_xor_probe(struct platform_device *pdev)
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001040{
Andrew Lunn63a93322011-12-07 21:48:07 +01001041 const struct mbus_dram_target_info *dram;
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001042 struct mv_xor_device *xordev;
Jingoo Hand4adcc02013-07-30 17:09:11 +09001043 struct mv_xor_platform_data *pdata = dev_get_platdata(&pdev->dev);
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001044 struct resource *res;
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001045 int i, ret;
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001046
Joe Perches1ba151c2012-10-28 01:05:44 -07001047 dev_notice(&pdev->dev, "Marvell shared XOR driver\n");
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001048
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001049 xordev = devm_kzalloc(&pdev->dev, sizeof(*xordev), GFP_KERNEL);
1050 if (!xordev)
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001051 return -ENOMEM;
1052
1053 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1054 if (!res)
1055 return -ENODEV;
1056
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001057 xordev->xor_base = devm_ioremap(&pdev->dev, res->start,
1058 resource_size(res));
1059 if (!xordev->xor_base)
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001060 return -EBUSY;
1061
1062 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1063 if (!res)
1064 return -ENODEV;
1065
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001066 xordev->xor_high_base = devm_ioremap(&pdev->dev, res->start,
1067 resource_size(res));
1068 if (!xordev->xor_high_base)
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001069 return -EBUSY;
1070
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001071 platform_set_drvdata(pdev, xordev);
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001072
1073 /*
1074 * (Re-)program MBUS remapping windows if we are asked to.
1075 */
Andrew Lunn63a93322011-12-07 21:48:07 +01001076 dram = mv_mbus_dram_info();
1077 if (dram)
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001078 mv_xor_conf_mbus_windows(xordev, dram);
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001079
Andrew Lunnc5101822012-02-19 13:30:26 +01001080 /* Not all platforms can gate the clock, so it is not
1081 * an error if the clock does not exists.
1082 */
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001083 xordev->clk = clk_get(&pdev->dev, NULL);
1084 if (!IS_ERR(xordev->clk))
1085 clk_prepare_enable(xordev->clk);
Andrew Lunnc5101822012-02-19 13:30:26 +01001086
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001087 if (pdev->dev.of_node) {
1088 struct device_node *np;
1089 int i = 0;
1090
1091 for_each_child_of_node(pdev->dev.of_node, np) {
Russell King0be82532013-12-12 23:59:08 +00001092 struct mv_xor_chan *chan;
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001093 dma_cap_mask_t cap_mask;
1094 int irq;
1095
1096 dma_cap_zero(cap_mask);
1097 if (of_property_read_bool(np, "dmacap,memcpy"))
1098 dma_cap_set(DMA_MEMCPY, cap_mask);
1099 if (of_property_read_bool(np, "dmacap,xor"))
1100 dma_cap_set(DMA_XOR, cap_mask);
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001101 if (of_property_read_bool(np, "dmacap,interrupt"))
1102 dma_cap_set(DMA_INTERRUPT, cap_mask);
1103
1104 irq = irq_of_parse_and_map(np, 0);
Thomas Petazzonif8eb9e72012-11-22 18:22:12 +01001105 if (!irq) {
1106 ret = -ENODEV;
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001107 goto err_channel_add;
1108 }
1109
Russell King0be82532013-12-12 23:59:08 +00001110 chan = mv_xor_channel_add(xordev, pdev, i,
1111 cap_mask, irq);
1112 if (IS_ERR(chan)) {
1113 ret = PTR_ERR(chan);
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001114 irq_dispose_mapping(irq);
1115 goto err_channel_add;
1116 }
1117
Russell King0be82532013-12-12 23:59:08 +00001118 xordev->channels[i] = chan;
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001119 i++;
1120 }
1121 } else if (pdata && pdata->channels) {
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001122 for (i = 0; i < MV_XOR_MAX_CHANNELS; i++) {
Thomas Petazzonie39f6ec2012-10-30 11:56:26 +01001123 struct mv_xor_channel_data *cd;
Russell King0be82532013-12-12 23:59:08 +00001124 struct mv_xor_chan *chan;
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001125 int irq;
1126
1127 cd = &pdata->channels[i];
1128 if (!cd) {
1129 ret = -ENODEV;
1130 goto err_channel_add;
1131 }
1132
1133 irq = platform_get_irq(pdev, i);
1134 if (irq < 0) {
1135 ret = irq;
1136 goto err_channel_add;
1137 }
1138
Russell King0be82532013-12-12 23:59:08 +00001139 chan = mv_xor_channel_add(xordev, pdev, i,
1140 cd->cap_mask, irq);
1141 if (IS_ERR(chan)) {
1142 ret = PTR_ERR(chan);
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001143 goto err_channel_add;
1144 }
Russell King0be82532013-12-12 23:59:08 +00001145
1146 xordev->channels[i] = chan;
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001147 }
1148 }
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001149
1150 return 0;
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001151
1152err_channel_add:
1153 for (i = 0; i < MV_XOR_MAX_CHANNELS; i++)
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001154 if (xordev->channels[i]) {
Thomas Petazzoniab6e4392013-01-06 11:10:43 +01001155 mv_xor_channel_remove(xordev->channels[i]);
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001156 if (pdev->dev.of_node)
1157 irq_dispose_mapping(xordev->channels[i]->irq);
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001158 }
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001159
Thomas Petazzonidab92062013-01-06 11:10:44 +01001160 if (!IS_ERR(xordev->clk)) {
1161 clk_disable_unprepare(xordev->clk);
1162 clk_put(xordev->clk);
1163 }
1164
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001165 return ret;
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001166}
1167
Linus Torvaldsc2714332012-12-14 14:54:26 -08001168static int mv_xor_remove(struct platform_device *pdev)
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001169{
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001170 struct mv_xor_device *xordev = platform_get_drvdata(pdev);
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001171 int i;
Andrew Lunnc5101822012-02-19 13:30:26 +01001172
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001173 for (i = 0; i < MV_XOR_MAX_CHANNELS; i++) {
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001174 if (xordev->channels[i])
1175 mv_xor_channel_remove(xordev->channels[i]);
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001176 }
Andrew Lunnc5101822012-02-19 13:30:26 +01001177
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001178 if (!IS_ERR(xordev->clk)) {
1179 clk_disable_unprepare(xordev->clk);
1180 clk_put(xordev->clk);
Andrew Lunnc5101822012-02-19 13:30:26 +01001181 }
1182
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001183 return 0;
1184}
1185
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001186#ifdef CONFIG_OF
Linus Torvaldsc2714332012-12-14 14:54:26 -08001187static struct of_device_id mv_xor_dt_ids[] = {
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001188 { .compatible = "marvell,orion-xor", },
1189 {},
1190};
1191MODULE_DEVICE_TABLE(of, mv_xor_dt_ids);
1192#endif
1193
Thomas Petazzoni61971652012-10-30 12:05:40 +01001194static struct platform_driver mv_xor_driver = {
1195 .probe = mv_xor_probe,
Linus Torvaldsc2714332012-12-14 14:54:26 -08001196 .remove = mv_xor_remove,
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001197 .driver = {
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001198 .owner = THIS_MODULE,
1199 .name = MV_XOR_NAME,
1200 .of_match_table = of_match_ptr(mv_xor_dt_ids),
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001201 },
1202};
1203
1204
1205static int __init mv_xor_init(void)
1206{
Thomas Petazzoni61971652012-10-30 12:05:40 +01001207 return platform_driver_register(&mv_xor_driver);
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001208}
1209module_init(mv_xor_init);
1210
1211/* it's currently unsafe to unload this module */
1212#if 0
1213static void __exit mv_xor_exit(void)
1214{
1215 platform_driver_unregister(&mv_xor_driver);
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001216 return;
1217}
1218
1219module_exit(mv_xor_exit);
1220#endif
1221
1222MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>");
1223MODULE_DESCRIPTION("DMA engine driver for Marvell's XOR engine");
1224MODULE_LICENSE("GPL");