blob: 4ee5bb194fd558766f813a3f1359de501749b964 [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
Ezequiel Garcia0e7488e2014-08-27 10:52:52 -030053 hw_desc->status = XOR_DESC_DMA_OWNED;
Saeed Bisharaff7b0472008-07-08 11:58:36 -070054 hw_desc->phy_next_desc = 0;
Ezequiel Garcia0e7488e2014-08-27 10:52:52 -030055 hw_desc->desc_command = XOR_DESC_EOD_INT_EN;
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
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700108static void mv_xor_device_clear_eoc_cause(struct mv_xor_chan *chan)
109{
Ezequiel Garcia0e7488e2014-08-27 10:52:52 -0300110 u32 val = ~(XOR_INT_END_OF_DESC << (chan->idx * 16));
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100111 dev_dbg(mv_chan_to_devp(chan), "%s, val 0x%08x\n", __func__, val);
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200112 writel_relaxed(val, XOR_INTR_CAUSE(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700113}
114
115static void mv_xor_device_clear_err_status(struct mv_xor_chan *chan)
116{
117 u32 val = 0xFFFF0000 >> (chan->idx * 16);
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200118 writel_relaxed(val, XOR_INTR_CAUSE(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700119}
120
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700121static void mv_set_mode(struct mv_xor_chan *chan,
122 enum dma_transaction_type type)
123{
124 u32 op_mode;
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200125 u32 config = readl_relaxed(XOR_CONFIG(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700126
127 switch (type) {
128 case DMA_XOR:
129 op_mode = XOR_OPERATION_MODE_XOR;
130 break;
131 case DMA_MEMCPY:
132 op_mode = XOR_OPERATION_MODE_MEMCPY;
133 break;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700134 default:
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100135 dev_err(mv_chan_to_devp(chan),
Joe Perches1ba151c2012-10-28 01:05:44 -0700136 "error: unsupported operation %d\n",
Thomas Petazzonia3fc74b2012-11-15 12:50:27 +0100137 type);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700138 BUG();
139 return;
140 }
141
142 config &= ~0x7;
143 config |= op_mode;
Thomas Petazzonie03bc652013-07-29 17:42:14 +0200144
145#if defined(__BIG_ENDIAN)
146 config |= XOR_DESCRIPTOR_SWAP;
147#else
148 config &= ~XOR_DESCRIPTOR_SWAP;
149#endif
150
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200151 writel_relaxed(config, XOR_CONFIG(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700152 chan->current_type = type;
153}
154
155static void mv_chan_activate(struct mv_xor_chan *chan)
156{
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100157 dev_dbg(mv_chan_to_devp(chan), " activate chan.\n");
Ezequiel Garcia5a9a55b2014-05-21 14:02:35 -0700158
159 /* writel ensures all descriptors are flushed before activation */
160 writel(BIT(0), XOR_ACTIVATION(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700161}
162
163static char mv_chan_is_busy(struct mv_xor_chan *chan)
164{
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200165 u32 state = readl_relaxed(XOR_ACTIVATION(chan));
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700166
167 state = (state >> 4) & 0x3;
168
169 return (state == 1) ? 1 : 0;
170}
171
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700172/**
173 * mv_xor_free_slots - flags descriptor slots for reuse
174 * @slot: Slot to free
175 * Caller must hold &mv_chan->lock while calling this function
176 */
177static void mv_xor_free_slots(struct mv_xor_chan *mv_chan,
178 struct mv_xor_desc_slot *slot)
179{
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100180 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d slot %p\n",
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700181 __func__, __LINE__, slot);
182
Lior Amsalemdfc97662014-08-27 10:52:51 -0300183 slot->slot_used = 0;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700184
185}
186
187/*
188 * mv_xor_start_new_chain - program the engine to operate on new chain headed by
189 * sw_desc
190 * Caller must hold &mv_chan->lock while calling this function
191 */
192static void mv_xor_start_new_chain(struct mv_xor_chan *mv_chan,
193 struct mv_xor_desc_slot *sw_desc)
194{
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100195 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d: sw_desc %p\n",
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700196 __func__, __LINE__, sw_desc);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700197
Bartlomiej Zolnierkiewicz48a9db42013-07-03 15:05:06 -0700198 /* set the hardware chain */
199 mv_chan_set_next_descriptor(mv_chan, sw_desc->async_tx.phys);
200
Lior Amsalemdfc97662014-08-27 10:52:51 -0300201 mv_chan->pending++;
Thomas Petazzoni98817b92012-11-15 14:57:44 +0100202 mv_xor_issue_pending(&mv_chan->dmachan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700203}
204
205static dma_cookie_t
206mv_xor_run_tx_complete_actions(struct mv_xor_desc_slot *desc,
207 struct mv_xor_chan *mv_chan, dma_cookie_t cookie)
208{
209 BUG_ON(desc->async_tx.cookie < 0);
210
211 if (desc->async_tx.cookie > 0) {
212 cookie = desc->async_tx.cookie;
213
214 /* call the callback (must not sleep or submit new
215 * operations to this channel)
216 */
217 if (desc->async_tx.callback)
218 desc->async_tx.callback(
219 desc->async_tx.callback_param);
220
Dan Williamsd38a8c62013-10-18 19:35:23 +0200221 dma_descriptor_unmap(&desc->async_tx);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700222 }
223
224 /* run dependent operations */
Dan Williams07f22112009-01-05 17:14:31 -0700225 dma_run_dependencies(&desc->async_tx);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700226
227 return cookie;
228}
229
230static int
231mv_xor_clean_completed_slots(struct mv_xor_chan *mv_chan)
232{
233 struct mv_xor_desc_slot *iter, *_iter;
234
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100235 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d\n", __func__, __LINE__);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700236 list_for_each_entry_safe(iter, _iter, &mv_chan->completed_slots,
237 completed_node) {
238
239 if (async_tx_test_ack(&iter->async_tx)) {
240 list_del(&iter->completed_node);
241 mv_xor_free_slots(mv_chan, iter);
242 }
243 }
244 return 0;
245}
246
247static int
248mv_xor_clean_slot(struct mv_xor_desc_slot *desc,
249 struct mv_xor_chan *mv_chan)
250{
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100251 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d: desc %p flags %d\n",
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700252 __func__, __LINE__, desc, desc->async_tx.flags);
253 list_del(&desc->chain_node);
254 /* the client is allowed to attach dependent operations
255 * until 'ack' is set
256 */
257 if (!async_tx_test_ack(&desc->async_tx)) {
258 /* move this slot to the completed_slots */
259 list_add_tail(&desc->completed_node, &mv_chan->completed_slots);
260 return 0;
261 }
262
263 mv_xor_free_slots(mv_chan, desc);
264 return 0;
265}
266
267static void __mv_xor_slot_cleanup(struct mv_xor_chan *mv_chan)
268{
269 struct mv_xor_desc_slot *iter, *_iter;
270 dma_cookie_t cookie = 0;
271 int busy = mv_chan_is_busy(mv_chan);
272 u32 current_desc = mv_chan_get_current_desc(mv_chan);
273 int seen_current = 0;
274
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100275 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d\n", __func__, __LINE__);
276 dev_dbg(mv_chan_to_devp(mv_chan), "current_desc %x\n", current_desc);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700277 mv_xor_clean_completed_slots(mv_chan);
278
279 /* free completed slots from the chain starting with
280 * the oldest descriptor
281 */
282
283 list_for_each_entry_safe(iter, _iter, &mv_chan->chain,
284 chain_node) {
285 prefetch(_iter);
286 prefetch(&_iter->async_tx);
287
288 /* do not advance past the current descriptor loaded into the
289 * hardware channel, subsequent descriptors are either in
290 * process or have not been submitted
291 */
292 if (seen_current)
293 break;
294
295 /* stop the search if we reach the current descriptor and the
296 * channel is busy
297 */
298 if (iter->async_tx.phys == current_desc) {
299 seen_current = 1;
300 if (busy)
301 break;
302 }
303
304 cookie = mv_xor_run_tx_complete_actions(iter, mv_chan, cookie);
305
306 if (mv_xor_clean_slot(iter, mv_chan))
307 break;
308 }
309
310 if ((busy == 0) && !list_empty(&mv_chan->chain)) {
311 struct mv_xor_desc_slot *chain_head;
312 chain_head = list_entry(mv_chan->chain.next,
313 struct mv_xor_desc_slot,
314 chain_node);
315
316 mv_xor_start_new_chain(mv_chan, chain_head);
317 }
318
319 if (cookie > 0)
Thomas Petazzoni98817b92012-11-15 14:57:44 +0100320 mv_chan->dmachan.completed_cookie = cookie;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700321}
322
323static void
324mv_xor_slot_cleanup(struct mv_xor_chan *mv_chan)
325{
326 spin_lock_bh(&mv_chan->lock);
327 __mv_xor_slot_cleanup(mv_chan);
328 spin_unlock_bh(&mv_chan->lock);
329}
330
331static void mv_xor_tasklet(unsigned long data)
332{
333 struct mv_xor_chan *chan = (struct mv_xor_chan *) data;
Saeed Bishara8333f652010-12-21 16:53:39 +0200334 mv_xor_slot_cleanup(chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700335}
336
337static struct mv_xor_desc_slot *
Lior Amsalemdfc97662014-08-27 10:52:51 -0300338mv_xor_alloc_slot(struct mv_xor_chan *mv_chan)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700339{
Lior Amsalemdfc97662014-08-27 10:52:51 -0300340 struct mv_xor_desc_slot *iter, *_iter;
341 int retry = 0;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700342
343 /* start search from the last allocated descrtiptor
344 * if a contiguous allocation can not be found start searching
345 * from the beginning of the list
346 */
347retry:
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700348 if (retry == 0)
349 iter = mv_chan->last_used;
350 else
351 iter = list_entry(&mv_chan->all_slots,
352 struct mv_xor_desc_slot,
353 slot_node);
354
355 list_for_each_entry_safe_continue(
356 iter, _iter, &mv_chan->all_slots, slot_node) {
Lior Amsalemdfc97662014-08-27 10:52:51 -0300357
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700358 prefetch(_iter);
359 prefetch(&_iter->async_tx);
Lior Amsalemdfc97662014-08-27 10:52:51 -0300360 if (iter->slot_used) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700361 /* give up after finding the first busy slot
362 * on the second pass through the list
363 */
364 if (retry)
365 break;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700366 continue;
367 }
368
Lior Amsalemdfc97662014-08-27 10:52:51 -0300369 /* pre-ack descriptor */
370 async_tx_ack(&iter->async_tx);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700371
Lior Amsalemdfc97662014-08-27 10:52:51 -0300372 iter->slot_used = 1;
373 INIT_LIST_HEAD(&iter->chain_node);
374 iter->async_tx.cookie = -EBUSY;
375 mv_chan->last_used = iter;
376 mv_desc_clear_next_desc(iter);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700377
Lior Amsalemdfc97662014-08-27 10:52:51 -0300378 return iter;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700379
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700380 }
381 if (!retry++)
382 goto retry;
383
384 /* try to free some slots if the allocation fails */
385 tasklet_schedule(&mv_chan->irq_tasklet);
386
387 return NULL;
388}
389
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700390/************************ DMA engine API functions ****************************/
391static dma_cookie_t
392mv_xor_tx_submit(struct dma_async_tx_descriptor *tx)
393{
394 struct mv_xor_desc_slot *sw_desc = to_mv_xor_slot(tx);
395 struct mv_xor_chan *mv_chan = to_mv_xor_chan(tx->chan);
Lior Amsalemdfc97662014-08-27 10:52:51 -0300396 struct mv_xor_desc_slot *old_chain_tail;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700397 dma_cookie_t cookie;
398 int new_hw_chain = 1;
399
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100400 dev_dbg(mv_chan_to_devp(mv_chan),
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700401 "%s sw_desc %p: async_tx %p\n",
402 __func__, sw_desc, &sw_desc->async_tx);
403
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700404 spin_lock_bh(&mv_chan->lock);
Russell King - ARM Linux884485e2012-03-06 22:34:46 +0000405 cookie = dma_cookie_assign(tx);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700406
407 if (list_empty(&mv_chan->chain))
Lior Amsalemdfc97662014-08-27 10:52:51 -0300408 list_add_tail(&sw_desc->chain_node, &mv_chan->chain);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700409 else {
410 new_hw_chain = 0;
411
412 old_chain_tail = list_entry(mv_chan->chain.prev,
413 struct mv_xor_desc_slot,
414 chain_node);
Lior Amsalemdfc97662014-08-27 10:52:51 -0300415 list_add_tail(&sw_desc->chain_node, &mv_chan->chain);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700416
Olof Johansson31fd8f52014-02-03 17:13:23 -0800417 dev_dbg(mv_chan_to_devp(mv_chan), "Append to last desc %pa\n",
418 &old_chain_tail->async_tx.phys);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700419
420 /* fix up the hardware chain */
Lior Amsalemdfc97662014-08-27 10:52:51 -0300421 mv_desc_set_next_desc(old_chain_tail, sw_desc->async_tx.phys);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700422
423 /* if the channel is not busy */
424 if (!mv_chan_is_busy(mv_chan)) {
425 u32 current_desc = mv_chan_get_current_desc(mv_chan);
426 /*
427 * and the curren desc is the end of the chain before
428 * the append, then we need to start the channel
429 */
430 if (current_desc == old_chain_tail->async_tx.phys)
431 new_hw_chain = 1;
432 }
433 }
434
435 if (new_hw_chain)
Lior Amsalemdfc97662014-08-27 10:52:51 -0300436 mv_xor_start_new_chain(mv_chan, sw_desc);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700437
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700438 spin_unlock_bh(&mv_chan->lock);
439
440 return cookie;
441}
442
443/* returns the number of allocated descriptors */
Dan Williamsaa1e6f12009-01-06 11:38:17 -0700444static int mv_xor_alloc_chan_resources(struct dma_chan *chan)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700445{
Olof Johansson31fd8f52014-02-03 17:13:23 -0800446 void *virt_desc;
447 dma_addr_t dma_desc;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700448 int idx;
449 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
450 struct mv_xor_desc_slot *slot = NULL;
Thomas Petazzonib503fa02012-11-15 15:55:30 +0100451 int num_descs_in_pool = MV_XOR_POOL_SIZE/MV_XOR_SLOT_SIZE;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700452
453 /* Allocate descriptor slots */
454 idx = mv_chan->slots_allocated;
455 while (idx < num_descs_in_pool) {
456 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
457 if (!slot) {
Ezequiel Garciab8291dd2014-08-27 10:52:49 -0300458 dev_info(mv_chan_to_devp(mv_chan),
459 "channel only initialized %d descriptor slots",
460 idx);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700461 break;
462 }
Olof Johansson31fd8f52014-02-03 17:13:23 -0800463 virt_desc = mv_chan->dma_desc_pool_virt;
464 slot->hw_desc = virt_desc + idx * MV_XOR_SLOT_SIZE;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700465
466 dma_async_tx_descriptor_init(&slot->async_tx, chan);
467 slot->async_tx.tx_submit = mv_xor_tx_submit;
468 INIT_LIST_HEAD(&slot->chain_node);
469 INIT_LIST_HEAD(&slot->slot_node);
Olof Johansson31fd8f52014-02-03 17:13:23 -0800470 dma_desc = mv_chan->dma_desc_pool;
471 slot->async_tx.phys = dma_desc + idx * MV_XOR_SLOT_SIZE;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700472 slot->idx = idx++;
473
474 spin_lock_bh(&mv_chan->lock);
475 mv_chan->slots_allocated = idx;
476 list_add_tail(&slot->slot_node, &mv_chan->all_slots);
477 spin_unlock_bh(&mv_chan->lock);
478 }
479
480 if (mv_chan->slots_allocated && !mv_chan->last_used)
481 mv_chan->last_used = list_entry(mv_chan->all_slots.next,
482 struct mv_xor_desc_slot,
483 slot_node);
484
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100485 dev_dbg(mv_chan_to_devp(mv_chan),
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700486 "allocated %d descriptor slots last_used: %p\n",
487 mv_chan->slots_allocated, mv_chan->last_used);
488
489 return mv_chan->slots_allocated ? : -ENOMEM;
490}
491
492static struct dma_async_tx_descriptor *
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700493mv_xor_prep_dma_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
494 unsigned int src_cnt, size_t len, unsigned long flags)
495{
496 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
Lior Amsalemdfc97662014-08-27 10:52:51 -0300497 struct mv_xor_desc_slot *sw_desc;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700498
499 if (unlikely(len < MV_XOR_MIN_BYTE_COUNT))
500 return NULL;
501
Coly Li7912d302011-03-27 01:26:53 +0800502 BUG_ON(len > MV_XOR_MAX_BYTE_COUNT);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700503
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100504 dev_dbg(mv_chan_to_devp(mv_chan),
Olof Johansson31fd8f52014-02-03 17:13:23 -0800505 "%s src_cnt: %d len: %u dest %pad flags: %ld\n",
506 __func__, src_cnt, len, &dest, flags);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700507
508 spin_lock_bh(&mv_chan->lock);
Lior Amsalemdfc97662014-08-27 10:52:51 -0300509 sw_desc = mv_xor_alloc_slot(mv_chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700510 if (sw_desc) {
511 sw_desc->type = DMA_XOR;
512 sw_desc->async_tx.flags = flags;
Lior Amsalemdfc97662014-08-27 10:52:51 -0300513 mv_desc_init(sw_desc, dest, len);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700514 sw_desc->unmap_src_cnt = src_cnt;
515 sw_desc->unmap_len = len;
516 while (src_cnt--)
Lior Amsalemdfc97662014-08-27 10:52:51 -0300517 mv_desc_set_src_addr(sw_desc, src_cnt, src[src_cnt]);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700518 }
519 spin_unlock_bh(&mv_chan->lock);
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100520 dev_dbg(mv_chan_to_devp(mv_chan),
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700521 "%s sw_desc %p async_tx %p \n",
522 __func__, sw_desc, &sw_desc->async_tx);
523 return sw_desc ? &sw_desc->async_tx : NULL;
524}
525
Lior Amsalem3e4f52e2014-08-27 10:52:50 -0300526static struct dma_async_tx_descriptor *
527mv_xor_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
528 size_t len, unsigned long flags)
529{
530 /*
531 * A MEMCPY operation is identical to an XOR operation with only
532 * a single source address.
533 */
534 return mv_xor_prep_dma_xor(chan, dest, &src, 1, len, flags);
535}
536
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700537static void mv_xor_free_chan_resources(struct dma_chan *chan)
538{
539 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
540 struct mv_xor_desc_slot *iter, *_iter;
541 int in_use_descs = 0;
542
543 mv_xor_slot_cleanup(mv_chan);
544
545 spin_lock_bh(&mv_chan->lock);
546 list_for_each_entry_safe(iter, _iter, &mv_chan->chain,
547 chain_node) {
548 in_use_descs++;
549 list_del(&iter->chain_node);
550 }
551 list_for_each_entry_safe(iter, _iter, &mv_chan->completed_slots,
552 completed_node) {
553 in_use_descs++;
554 list_del(&iter->completed_node);
555 }
556 list_for_each_entry_safe_reverse(
557 iter, _iter, &mv_chan->all_slots, slot_node) {
558 list_del(&iter->slot_node);
559 kfree(iter);
560 mv_chan->slots_allocated--;
561 }
562 mv_chan->last_used = NULL;
563
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100564 dev_dbg(mv_chan_to_devp(mv_chan), "%s slots_allocated %d\n",
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700565 __func__, mv_chan->slots_allocated);
566 spin_unlock_bh(&mv_chan->lock);
567
568 if (in_use_descs)
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100569 dev_err(mv_chan_to_devp(mv_chan),
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700570 "freeing %d in use descriptors!\n", in_use_descs);
571}
572
573/**
Linus Walleij07934482010-03-26 16:50:49 -0700574 * mv_xor_status - poll the status of an XOR transaction
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700575 * @chan: XOR channel handle
576 * @cookie: XOR transaction identifier
Linus Walleij07934482010-03-26 16:50:49 -0700577 * @txstate: XOR transactions state holder (or NULL)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700578 */
Linus Walleij07934482010-03-26 16:50:49 -0700579static enum dma_status mv_xor_status(struct dma_chan *chan,
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700580 dma_cookie_t cookie,
Linus Walleij07934482010-03-26 16:50:49 -0700581 struct dma_tx_state *txstate)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700582{
583 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700584 enum dma_status ret;
585
Russell King - ARM Linux96a2af42012-03-06 22:35:27 +0000586 ret = dma_cookie_status(chan, cookie, txstate);
Vinod Koulb3efb8f2013-10-16 20:51:04 +0530587 if (ret == DMA_COMPLETE) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700588 mv_xor_clean_completed_slots(mv_chan);
589 return ret;
590 }
591 mv_xor_slot_cleanup(mv_chan);
592
Russell King - ARM Linux96a2af42012-03-06 22:35:27 +0000593 return dma_cookie_status(chan, cookie, txstate);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700594}
595
596static void mv_dump_xor_regs(struct mv_xor_chan *chan)
597{
598 u32 val;
599
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200600 val = readl_relaxed(XOR_CONFIG(chan));
Joe Perches1ba151c2012-10-28 01:05:44 -0700601 dev_err(mv_chan_to_devp(chan), "config 0x%08x\n", val);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700602
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200603 val = readl_relaxed(XOR_ACTIVATION(chan));
Joe Perches1ba151c2012-10-28 01:05:44 -0700604 dev_err(mv_chan_to_devp(chan), "activation 0x%08x\n", val);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700605
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200606 val = readl_relaxed(XOR_INTR_CAUSE(chan));
Joe Perches1ba151c2012-10-28 01:05:44 -0700607 dev_err(mv_chan_to_devp(chan), "intr cause 0x%08x\n", val);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700608
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200609 val = readl_relaxed(XOR_INTR_MASK(chan));
Joe Perches1ba151c2012-10-28 01:05:44 -0700610 dev_err(mv_chan_to_devp(chan), "intr mask 0x%08x\n", val);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700611
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200612 val = readl_relaxed(XOR_ERROR_CAUSE(chan));
Joe Perches1ba151c2012-10-28 01:05:44 -0700613 dev_err(mv_chan_to_devp(chan), "error cause 0x%08x\n", val);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700614
Thomas Petazzoni5733c382013-07-29 17:42:13 +0200615 val = readl_relaxed(XOR_ERROR_ADDR(chan));
Joe Perches1ba151c2012-10-28 01:05:44 -0700616 dev_err(mv_chan_to_devp(chan), "error addr 0x%08x\n", val);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700617}
618
619static void mv_xor_err_interrupt_handler(struct mv_xor_chan *chan,
620 u32 intr_cause)
621{
Ezequiel Garcia0e7488e2014-08-27 10:52:52 -0300622 if (intr_cause & XOR_INT_ERR_DECODE) {
623 dev_dbg(mv_chan_to_devp(chan), "ignoring address decode error\n");
624 return;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700625 }
626
Ezequiel Garcia0e7488e2014-08-27 10:52:52 -0300627 dev_err(mv_chan_to_devp(chan), "error on chan %d. intr cause 0x%08x\n",
Thomas Petazzonia3fc74b2012-11-15 12:50:27 +0100628 chan->idx, intr_cause);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700629
630 mv_dump_xor_regs(chan);
Ezequiel Garcia0e7488e2014-08-27 10:52:52 -0300631 WARN_ON(1);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700632}
633
634static irqreturn_t mv_xor_interrupt_handler(int irq, void *data)
635{
636 struct mv_xor_chan *chan = data;
637 u32 intr_cause = mv_chan_get_intr_cause(chan);
638
Thomas Petazzonic98c1782012-11-15 14:17:18 +0100639 dev_dbg(mv_chan_to_devp(chan), "intr cause %x\n", intr_cause);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700640
Ezequiel Garcia0e7488e2014-08-27 10:52:52 -0300641 if (intr_cause & XOR_INTR_ERRORS)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700642 mv_xor_err_interrupt_handler(chan, intr_cause);
643
644 tasklet_schedule(&chan->irq_tasklet);
645
646 mv_xor_device_clear_eoc_cause(chan);
647
648 return IRQ_HANDLED;
649}
650
651static void mv_xor_issue_pending(struct dma_chan *chan)
652{
653 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
654
655 if (mv_chan->pending >= MV_XOR_THRESHOLD) {
656 mv_chan->pending = 0;
657 mv_chan_activate(mv_chan);
658 }
659}
660
661/*
662 * Perform a transaction to verify the HW works.
663 */
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700664
Linus Torvaldsc2714332012-12-14 14:54:26 -0800665static int mv_xor_memcpy_self_test(struct mv_xor_chan *mv_chan)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700666{
667 int i;
668 void *src, *dest;
669 dma_addr_t src_dma, dest_dma;
670 struct dma_chan *dma_chan;
671 dma_cookie_t cookie;
672 struct dma_async_tx_descriptor *tx;
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300673 struct dmaengine_unmap_data *unmap;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700674 int err = 0;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700675
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300676 src = kmalloc(sizeof(u8) * PAGE_SIZE, GFP_KERNEL);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700677 if (!src)
678 return -ENOMEM;
679
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300680 dest = kzalloc(sizeof(u8) * PAGE_SIZE, GFP_KERNEL);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700681 if (!dest) {
682 kfree(src);
683 return -ENOMEM;
684 }
685
686 /* Fill in src buffer */
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300687 for (i = 0; i < PAGE_SIZE; i++)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700688 ((u8 *) src)[i] = (u8)i;
689
Thomas Petazzoni275cc0c2012-11-15 15:09:42 +0100690 dma_chan = &mv_chan->dmachan;
Dan Williamsaa1e6f12009-01-06 11:38:17 -0700691 if (mv_xor_alloc_chan_resources(dma_chan) < 1) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700692 err = -ENODEV;
693 goto out;
694 }
695
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300696 unmap = dmaengine_get_unmap_data(dma_chan->device->dev, 2, GFP_KERNEL);
697 if (!unmap) {
698 err = -ENOMEM;
699 goto free_resources;
700 }
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700701
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300702 src_dma = dma_map_page(dma_chan->device->dev, virt_to_page(src), 0,
703 PAGE_SIZE, DMA_TO_DEVICE);
704 unmap->to_cnt = 1;
705 unmap->addr[0] = src_dma;
706
707 dest_dma = dma_map_page(dma_chan->device->dev, virt_to_page(dest), 0,
708 PAGE_SIZE, DMA_FROM_DEVICE);
709 unmap->from_cnt = 1;
710 unmap->addr[1] = dest_dma;
711
712 unmap->len = PAGE_SIZE;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700713
714 tx = mv_xor_prep_dma_memcpy(dma_chan, dest_dma, src_dma,
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300715 PAGE_SIZE, 0);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700716 cookie = mv_xor_tx_submit(tx);
717 mv_xor_issue_pending(dma_chan);
718 async_tx_ack(tx);
719 msleep(1);
720
Linus Walleij07934482010-03-26 16:50:49 -0700721 if (mv_xor_status(dma_chan, cookie, NULL) !=
Vinod Koulb3efb8f2013-10-16 20:51:04 +0530722 DMA_COMPLETE) {
Thomas Petazzonia3fc74b2012-11-15 12:50:27 +0100723 dev_err(dma_chan->device->dev,
724 "Self-test copy timed out, disabling\n");
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700725 err = -ENODEV;
726 goto free_resources;
727 }
728
Thomas Petazzonic35064c2012-11-15 13:01:59 +0100729 dma_sync_single_for_cpu(dma_chan->device->dev, dest_dma,
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300730 PAGE_SIZE, DMA_FROM_DEVICE);
731 if (memcmp(src, dest, PAGE_SIZE)) {
Thomas Petazzonia3fc74b2012-11-15 12:50:27 +0100732 dev_err(dma_chan->device->dev,
733 "Self-test copy failed compare, disabling\n");
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700734 err = -ENODEV;
735 goto free_resources;
736 }
737
738free_resources:
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300739 dmaengine_unmap_put(unmap);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700740 mv_xor_free_chan_resources(dma_chan);
741out:
742 kfree(src);
743 kfree(dest);
744 return err;
745}
746
747#define MV_XOR_NUM_SRC_TEST 4 /* must be <= 15 */
Bill Pemberton463a1f82012-11-19 13:22:55 -0500748static int
Thomas Petazzoni275cc0c2012-11-15 15:09:42 +0100749mv_xor_xor_self_test(struct mv_xor_chan *mv_chan)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700750{
751 int i, src_idx;
752 struct page *dest;
753 struct page *xor_srcs[MV_XOR_NUM_SRC_TEST];
754 dma_addr_t dma_srcs[MV_XOR_NUM_SRC_TEST];
755 dma_addr_t dest_dma;
756 struct dma_async_tx_descriptor *tx;
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300757 struct dmaengine_unmap_data *unmap;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700758 struct dma_chan *dma_chan;
759 dma_cookie_t cookie;
760 u8 cmp_byte = 0;
761 u32 cmp_word;
762 int err = 0;
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300763 int src_count = MV_XOR_NUM_SRC_TEST;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700764
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300765 for (src_idx = 0; src_idx < src_count; src_idx++) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700766 xor_srcs[src_idx] = alloc_page(GFP_KERNEL);
Roel Kluina09b09a2009-02-25 13:56:21 +0100767 if (!xor_srcs[src_idx]) {
768 while (src_idx--)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700769 __free_page(xor_srcs[src_idx]);
Roel Kluina09b09a2009-02-25 13:56:21 +0100770 return -ENOMEM;
771 }
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700772 }
773
774 dest = alloc_page(GFP_KERNEL);
Roel Kluina09b09a2009-02-25 13:56:21 +0100775 if (!dest) {
776 while (src_idx--)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700777 __free_page(xor_srcs[src_idx]);
Roel Kluina09b09a2009-02-25 13:56:21 +0100778 return -ENOMEM;
779 }
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700780
781 /* Fill in src buffers */
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300782 for (src_idx = 0; src_idx < src_count; src_idx++) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700783 u8 *ptr = page_address(xor_srcs[src_idx]);
784 for (i = 0; i < PAGE_SIZE; i++)
785 ptr[i] = (1 << src_idx);
786 }
787
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300788 for (src_idx = 0; src_idx < src_count; src_idx++)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700789 cmp_byte ^= (u8) (1 << src_idx);
790
791 cmp_word = (cmp_byte << 24) | (cmp_byte << 16) |
792 (cmp_byte << 8) | cmp_byte;
793
794 memset(page_address(dest), 0, PAGE_SIZE);
795
Thomas Petazzoni275cc0c2012-11-15 15:09:42 +0100796 dma_chan = &mv_chan->dmachan;
Dan Williamsaa1e6f12009-01-06 11:38:17 -0700797 if (mv_xor_alloc_chan_resources(dma_chan) < 1) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700798 err = -ENODEV;
799 goto out;
800 }
801
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300802 unmap = dmaengine_get_unmap_data(dma_chan->device->dev, src_count + 1,
803 GFP_KERNEL);
804 if (!unmap) {
805 err = -ENOMEM;
806 goto free_resources;
807 }
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700808
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300809 /* test xor */
810 for (i = 0; i < src_count; i++) {
811 unmap->addr[i] = dma_map_page(dma_chan->device->dev, xor_srcs[i],
812 0, PAGE_SIZE, DMA_TO_DEVICE);
813 dma_srcs[i] = unmap->addr[i];
814 unmap->to_cnt++;
815 }
816
817 unmap->addr[src_count] = dma_map_page(dma_chan->device->dev, dest, 0, PAGE_SIZE,
818 DMA_FROM_DEVICE);
819 dest_dma = unmap->addr[src_count];
820 unmap->from_cnt = 1;
821 unmap->len = PAGE_SIZE;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700822
823 tx = mv_xor_prep_dma_xor(dma_chan, dest_dma, dma_srcs,
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300824 src_count, PAGE_SIZE, 0);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700825
826 cookie = mv_xor_tx_submit(tx);
827 mv_xor_issue_pending(dma_chan);
828 async_tx_ack(tx);
829 msleep(8);
830
Linus Walleij07934482010-03-26 16:50:49 -0700831 if (mv_xor_status(dma_chan, cookie, NULL) !=
Vinod Koulb3efb8f2013-10-16 20:51:04 +0530832 DMA_COMPLETE) {
Thomas Petazzonia3fc74b2012-11-15 12:50:27 +0100833 dev_err(dma_chan->device->dev,
834 "Self-test xor timed out, disabling\n");
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700835 err = -ENODEV;
836 goto free_resources;
837 }
838
Thomas Petazzonic35064c2012-11-15 13:01:59 +0100839 dma_sync_single_for_cpu(dma_chan->device->dev, dest_dma,
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700840 PAGE_SIZE, DMA_FROM_DEVICE);
841 for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) {
842 u32 *ptr = page_address(dest);
843 if (ptr[i] != cmp_word) {
Thomas Petazzonia3fc74b2012-11-15 12:50:27 +0100844 dev_err(dma_chan->device->dev,
Joe Perches1ba151c2012-10-28 01:05:44 -0700845 "Self-test xor failed compare, disabling. index %d, data %x, expected %x\n",
846 i, ptr[i], cmp_word);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700847 err = -ENODEV;
848 goto free_resources;
849 }
850 }
851
852free_resources:
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300853 dmaengine_unmap_put(unmap);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700854 mv_xor_free_chan_resources(dma_chan);
855out:
Ezequiel Garciad16695a2013-12-10 09:32:36 -0300856 src_idx = src_count;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700857 while (src_idx--)
858 __free_page(xor_srcs[src_idx]);
859 __free_page(dest);
860 return err;
861}
862
Andrew Lunn34c93c82012-11-18 11:44:56 +0100863/* This driver does not implement any of the optional DMA operations. */
864static int
865mv_xor_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
866 unsigned long arg)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700867{
Andrew Lunn34c93c82012-11-18 11:44:56 +0100868 return -ENOSYS;
869}
870
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100871static int mv_xor_channel_remove(struct mv_xor_chan *mv_chan)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700872{
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700873 struct dma_chan *chan, *_chan;
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100874 struct device *dev = mv_chan->dmadev.dev;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700875
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100876 dma_async_device_unregister(&mv_chan->dmadev);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700877
Thomas Petazzonib503fa02012-11-15 15:55:30 +0100878 dma_free_coherent(dev, MV_XOR_POOL_SIZE,
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100879 mv_chan->dma_desc_pool_virt, mv_chan->dma_desc_pool);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700880
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100881 list_for_each_entry_safe(chan, _chan, &mv_chan->dmadev.channels,
Thomas Petazzonia6b4a9d2012-10-29 16:45:46 +0100882 device_node) {
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700883 list_del(&chan->device_node);
884 }
885
Thomas Petazzoni88eb92c2012-11-15 16:11:18 +0100886 free_irq(mv_chan->irq, mv_chan);
887
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700888 return 0;
889}
890
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100891static struct mv_xor_chan *
Thomas Petazzoni297eedb2012-11-15 15:29:53 +0100892mv_xor_channel_add(struct mv_xor_device *xordev,
Thomas Petazzonia6b4a9d2012-10-29 16:45:46 +0100893 struct platform_device *pdev,
Thomas Petazzonib503fa02012-11-15 15:55:30 +0100894 int idx, dma_cap_mask_t cap_mask, int irq)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700895{
896 int ret = 0;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700897 struct mv_xor_chan *mv_chan;
898 struct dma_device *dma_dev;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700899
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100900 mv_chan = devm_kzalloc(&pdev->dev, sizeof(*mv_chan), GFP_KERNEL);
Sachin Kamata5776592013-09-02 13:54:20 +0530901 if (!mv_chan)
902 return ERR_PTR(-ENOMEM);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700903
Thomas Petazzoni9aedbdb2012-11-15 15:36:37 +0100904 mv_chan->idx = idx;
Thomas Petazzoni88eb92c2012-11-15 16:11:18 +0100905 mv_chan->irq = irq;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700906
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100907 dma_dev = &mv_chan->dmadev;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700908
909 /* allocate coherent memory for hardware descriptors
910 * note: writecombine gives slightly better performance, but
911 * requires that we explicitly flush the writes
912 */
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100913 mv_chan->dma_desc_pool_virt =
Thomas Petazzonib503fa02012-11-15 15:55:30 +0100914 dma_alloc_writecombine(&pdev->dev, MV_XOR_POOL_SIZE,
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100915 &mv_chan->dma_desc_pool, GFP_KERNEL);
916 if (!mv_chan->dma_desc_pool_virt)
Thomas Petazzonia6b4a9d2012-10-29 16:45:46 +0100917 return ERR_PTR(-ENOMEM);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700918
919 /* discover transaction capabilites from the platform data */
Thomas Petazzonia6b4a9d2012-10-29 16:45:46 +0100920 dma_dev->cap_mask = cap_mask;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700921
922 INIT_LIST_HEAD(&dma_dev->channels);
923
924 /* set base routines */
925 dma_dev->device_alloc_chan_resources = mv_xor_alloc_chan_resources;
926 dma_dev->device_free_chan_resources = mv_xor_free_chan_resources;
Linus Walleij07934482010-03-26 16:50:49 -0700927 dma_dev->device_tx_status = mv_xor_status;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700928 dma_dev->device_issue_pending = mv_xor_issue_pending;
Andrew Lunn34c93c82012-11-18 11:44:56 +0100929 dma_dev->device_control = mv_xor_control;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700930 dma_dev->dev = &pdev->dev;
931
932 /* set prep routines based on capability */
933 if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask))
934 dma_dev->device_prep_dma_memcpy = mv_xor_prep_dma_memcpy;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700935 if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
Joe Perchesc0198942009-06-28 09:26:21 -0700936 dma_dev->max_xor = 8;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700937 dma_dev->device_prep_dma_xor = mv_xor_prep_dma_xor;
938 }
939
Thomas Petazzoni297eedb2012-11-15 15:29:53 +0100940 mv_chan->mmr_base = xordev->xor_base;
Ezequiel Garcia82a14022013-10-30 12:01:43 -0300941 mv_chan->mmr_high_base = xordev->xor_high_base;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700942 tasklet_init(&mv_chan->irq_tasklet, mv_xor_tasklet, (unsigned long)
943 mv_chan);
944
945 /* clear errors before enabling interrupts */
946 mv_xor_device_clear_err_status(mv_chan);
947
Thomas Petazzoni2d0a0742012-11-22 18:19:09 +0100948 ret = request_irq(mv_chan->irq, mv_xor_interrupt_handler,
949 0, dev_name(&pdev->dev), mv_chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700950 if (ret)
951 goto err_free_dma;
952
953 mv_chan_unmask_interrupts(mv_chan);
954
Lior Amsalem3e4f52e2014-08-27 10:52:50 -0300955 mv_set_mode(mv_chan, DMA_XOR);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700956
957 spin_lock_init(&mv_chan->lock);
958 INIT_LIST_HEAD(&mv_chan->chain);
959 INIT_LIST_HEAD(&mv_chan->completed_slots);
960 INIT_LIST_HEAD(&mv_chan->all_slots);
Thomas Petazzoni98817b92012-11-15 14:57:44 +0100961 mv_chan->dmachan.device = dma_dev;
962 dma_cookie_init(&mv_chan->dmachan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700963
Thomas Petazzoni98817b92012-11-15 14:57:44 +0100964 list_add_tail(&mv_chan->dmachan.device_node, &dma_dev->channels);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700965
966 if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
Thomas Petazzoni275cc0c2012-11-15 15:09:42 +0100967 ret = mv_xor_memcpy_self_test(mv_chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700968 dev_dbg(&pdev->dev, "memcpy self test returned %d\n", ret);
969 if (ret)
Thomas Petazzoni2d0a0742012-11-22 18:19:09 +0100970 goto err_free_irq;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700971 }
972
973 if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
Thomas Petazzoni275cc0c2012-11-15 15:09:42 +0100974 ret = mv_xor_xor_self_test(mv_chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700975 dev_dbg(&pdev->dev, "xor self test returned %d\n", ret);
976 if (ret)
Thomas Petazzoni2d0a0742012-11-22 18:19:09 +0100977 goto err_free_irq;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700978 }
979
Bartlomiej Zolnierkiewicz48a9db42013-07-03 15:05:06 -0700980 dev_info(&pdev->dev, "Marvell XOR: ( %s%s%s)\n",
Joe Perches1ba151c2012-10-28 01:05:44 -0700981 dma_has_cap(DMA_XOR, dma_dev->cap_mask) ? "xor " : "",
Joe Perches1ba151c2012-10-28 01:05:44 -0700982 dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask) ? "cpy " : "",
983 dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : "");
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700984
985 dma_async_device_register(dma_dev);
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100986 return mv_chan;
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700987
Thomas Petazzoni2d0a0742012-11-22 18:19:09 +0100988err_free_irq:
989 free_irq(mv_chan->irq, mv_chan);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700990 err_free_dma:
Thomas Petazzonib503fa02012-11-15 15:55:30 +0100991 dma_free_coherent(&pdev->dev, MV_XOR_POOL_SIZE,
Thomas Petazzoni1ef48a22012-11-15 15:17:05 +0100992 mv_chan->dma_desc_pool_virt, mv_chan->dma_desc_pool);
Thomas Petazzonia6b4a9d2012-10-29 16:45:46 +0100993 return ERR_PTR(ret);
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700994}
995
996static void
Thomas Petazzoni297eedb2012-11-15 15:29:53 +0100997mv_xor_conf_mbus_windows(struct mv_xor_device *xordev,
Andrew Lunn63a93322011-12-07 21:48:07 +0100998 const struct mbus_dram_target_info *dram)
Saeed Bisharaff7b0472008-07-08 11:58:36 -0700999{
Ezequiel Garcia82a14022013-10-30 12:01:43 -03001000 void __iomem *base = xordev->xor_high_base;
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001001 u32 win_enable = 0;
1002 int i;
1003
1004 for (i = 0; i < 8; i++) {
1005 writel(0, base + WINDOW_BASE(i));
1006 writel(0, base + WINDOW_SIZE(i));
1007 if (i < 4)
1008 writel(0, base + WINDOW_REMAP_HIGH(i));
1009 }
1010
1011 for (i = 0; i < dram->num_cs; i++) {
Andrew Lunn63a93322011-12-07 21:48:07 +01001012 const struct mbus_dram_window *cs = dram->cs + i;
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001013
1014 writel((cs->base & 0xffff0000) |
1015 (cs->mbus_attr << 8) |
1016 dram->mbus_dram_target_id, base + WINDOW_BASE(i));
1017 writel((cs->size - 1) & 0xffff0000, base + WINDOW_SIZE(i));
1018
1019 win_enable |= (1 << i);
1020 win_enable |= 3 << (16 + (2 * i));
1021 }
1022
1023 writel(win_enable, base + WINDOW_BAR_ENABLE(0));
1024 writel(win_enable, base + WINDOW_BAR_ENABLE(1));
Thomas Petazzonic4b4b732012-11-22 18:16:37 +01001025 writel(0, base + WINDOW_OVERRIDE_CTRL(0));
1026 writel(0, base + WINDOW_OVERRIDE_CTRL(1));
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001027}
1028
Linus Torvaldsc2714332012-12-14 14:54:26 -08001029static int mv_xor_probe(struct platform_device *pdev)
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001030{
Andrew Lunn63a93322011-12-07 21:48:07 +01001031 const struct mbus_dram_target_info *dram;
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001032 struct mv_xor_device *xordev;
Jingoo Hand4adcc02013-07-30 17:09:11 +09001033 struct mv_xor_platform_data *pdata = dev_get_platdata(&pdev->dev);
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001034 struct resource *res;
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001035 int i, ret;
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001036
Joe Perches1ba151c2012-10-28 01:05:44 -07001037 dev_notice(&pdev->dev, "Marvell shared XOR driver\n");
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001038
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001039 xordev = devm_kzalloc(&pdev->dev, sizeof(*xordev), GFP_KERNEL);
1040 if (!xordev)
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001041 return -ENOMEM;
1042
1043 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1044 if (!res)
1045 return -ENODEV;
1046
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001047 xordev->xor_base = devm_ioremap(&pdev->dev, res->start,
1048 resource_size(res));
1049 if (!xordev->xor_base)
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001050 return -EBUSY;
1051
1052 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1053 if (!res)
1054 return -ENODEV;
1055
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001056 xordev->xor_high_base = devm_ioremap(&pdev->dev, res->start,
1057 resource_size(res));
1058 if (!xordev->xor_high_base)
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001059 return -EBUSY;
1060
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001061 platform_set_drvdata(pdev, xordev);
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001062
1063 /*
1064 * (Re-)program MBUS remapping windows if we are asked to.
1065 */
Andrew Lunn63a93322011-12-07 21:48:07 +01001066 dram = mv_mbus_dram_info();
1067 if (dram)
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001068 mv_xor_conf_mbus_windows(xordev, dram);
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001069
Andrew Lunnc5101822012-02-19 13:30:26 +01001070 /* Not all platforms can gate the clock, so it is not
1071 * an error if the clock does not exists.
1072 */
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001073 xordev->clk = clk_get(&pdev->dev, NULL);
1074 if (!IS_ERR(xordev->clk))
1075 clk_prepare_enable(xordev->clk);
Andrew Lunnc5101822012-02-19 13:30:26 +01001076
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001077 if (pdev->dev.of_node) {
1078 struct device_node *np;
1079 int i = 0;
1080
1081 for_each_child_of_node(pdev->dev.of_node, np) {
Russell King0be82532013-12-12 23:59:08 +00001082 struct mv_xor_chan *chan;
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001083 dma_cap_mask_t cap_mask;
1084 int irq;
1085
1086 dma_cap_zero(cap_mask);
1087 if (of_property_read_bool(np, "dmacap,memcpy"))
1088 dma_cap_set(DMA_MEMCPY, cap_mask);
1089 if (of_property_read_bool(np, "dmacap,xor"))
1090 dma_cap_set(DMA_XOR, cap_mask);
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001091 if (of_property_read_bool(np, "dmacap,interrupt"))
1092 dma_cap_set(DMA_INTERRUPT, cap_mask);
1093
1094 irq = irq_of_parse_and_map(np, 0);
Thomas Petazzonif8eb9e72012-11-22 18:22:12 +01001095 if (!irq) {
1096 ret = -ENODEV;
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001097 goto err_channel_add;
1098 }
1099
Russell King0be82532013-12-12 23:59:08 +00001100 chan = mv_xor_channel_add(xordev, pdev, i,
1101 cap_mask, irq);
1102 if (IS_ERR(chan)) {
1103 ret = PTR_ERR(chan);
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001104 irq_dispose_mapping(irq);
1105 goto err_channel_add;
1106 }
1107
Russell King0be82532013-12-12 23:59:08 +00001108 xordev->channels[i] = chan;
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001109 i++;
1110 }
1111 } else if (pdata && pdata->channels) {
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001112 for (i = 0; i < MV_XOR_MAX_CHANNELS; i++) {
Thomas Petazzonie39f6ec2012-10-30 11:56:26 +01001113 struct mv_xor_channel_data *cd;
Russell King0be82532013-12-12 23:59:08 +00001114 struct mv_xor_chan *chan;
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001115 int irq;
1116
1117 cd = &pdata->channels[i];
1118 if (!cd) {
1119 ret = -ENODEV;
1120 goto err_channel_add;
1121 }
1122
1123 irq = platform_get_irq(pdev, i);
1124 if (irq < 0) {
1125 ret = irq;
1126 goto err_channel_add;
1127 }
1128
Russell King0be82532013-12-12 23:59:08 +00001129 chan = mv_xor_channel_add(xordev, pdev, i,
1130 cd->cap_mask, irq);
1131 if (IS_ERR(chan)) {
1132 ret = PTR_ERR(chan);
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001133 goto err_channel_add;
1134 }
Russell King0be82532013-12-12 23:59:08 +00001135
1136 xordev->channels[i] = chan;
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001137 }
1138 }
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001139
1140 return 0;
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001141
1142err_channel_add:
1143 for (i = 0; i < MV_XOR_MAX_CHANNELS; i++)
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001144 if (xordev->channels[i]) {
Thomas Petazzoniab6e4392013-01-06 11:10:43 +01001145 mv_xor_channel_remove(xordev->channels[i]);
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001146 if (pdev->dev.of_node)
1147 irq_dispose_mapping(xordev->channels[i]->irq);
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001148 }
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001149
Thomas Petazzonidab92062013-01-06 11:10:44 +01001150 if (!IS_ERR(xordev->clk)) {
1151 clk_disable_unprepare(xordev->clk);
1152 clk_put(xordev->clk);
1153 }
1154
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001155 return ret;
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001156}
1157
Linus Torvaldsc2714332012-12-14 14:54:26 -08001158static int mv_xor_remove(struct platform_device *pdev)
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001159{
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001160 struct mv_xor_device *xordev = platform_get_drvdata(pdev);
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001161 int i;
Andrew Lunnc5101822012-02-19 13:30:26 +01001162
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001163 for (i = 0; i < MV_XOR_MAX_CHANNELS; i++) {
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001164 if (xordev->channels[i])
1165 mv_xor_channel_remove(xordev->channels[i]);
Thomas Petazzoni60d151f2012-10-29 16:54:49 +01001166 }
Andrew Lunnc5101822012-02-19 13:30:26 +01001167
Thomas Petazzoni297eedb2012-11-15 15:29:53 +01001168 if (!IS_ERR(xordev->clk)) {
1169 clk_disable_unprepare(xordev->clk);
1170 clk_put(xordev->clk);
Andrew Lunnc5101822012-02-19 13:30:26 +01001171 }
1172
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001173 return 0;
1174}
1175
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001176#ifdef CONFIG_OF
Linus Torvaldsc2714332012-12-14 14:54:26 -08001177static struct of_device_id mv_xor_dt_ids[] = {
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001178 { .compatible = "marvell,orion-xor", },
1179 {},
1180};
1181MODULE_DEVICE_TABLE(of, mv_xor_dt_ids);
1182#endif
1183
Thomas Petazzoni61971652012-10-30 12:05:40 +01001184static struct platform_driver mv_xor_driver = {
1185 .probe = mv_xor_probe,
Linus Torvaldsc2714332012-12-14 14:54:26 -08001186 .remove = mv_xor_remove,
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001187 .driver = {
Thomas Petazzonif7d12ef2012-11-15 16:47:58 +01001188 .owner = THIS_MODULE,
1189 .name = MV_XOR_NAME,
1190 .of_match_table = of_match_ptr(mv_xor_dt_ids),
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001191 },
1192};
1193
1194
1195static int __init mv_xor_init(void)
1196{
Thomas Petazzoni61971652012-10-30 12:05:40 +01001197 return platform_driver_register(&mv_xor_driver);
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001198}
1199module_init(mv_xor_init);
1200
1201/* it's currently unsafe to unload this module */
1202#if 0
1203static void __exit mv_xor_exit(void)
1204{
1205 platform_driver_unregister(&mv_xor_driver);
Saeed Bisharaff7b0472008-07-08 11:58:36 -07001206 return;
1207}
1208
1209module_exit(mv_xor_exit);
1210#endif
1211
1212MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>");
1213MODULE_DESCRIPTION("DMA engine driver for Marvell's XOR engine");
1214MODULE_LICENSE("GPL");