Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 22 | #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 Lunn | c510182 | 2012-02-19 13:30:26 +0100 | [diff] [blame] | 28 | #include <linux/clk.h> |
Thomas Petazzoni | f7d12ef | 2012-11-15 16:47:58 +0100 | [diff] [blame] | 29 | #include <linux/of.h> |
| 30 | #include <linux/of_irq.h> |
| 31 | #include <linux/irqdomain.h> |
Arnd Bergmann | c02cecb | 2012-08-24 15:21:54 +0200 | [diff] [blame] | 32 | #include <linux/platform_data/dma-mv_xor.h> |
Russell King - ARM Linux | d2ebfb3 | 2012-03-06 22:34:26 +0000 | [diff] [blame] | 33 | |
| 34 | #include "dmaengine.h" |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 35 | #include "mv_xor.h" |
| 36 | |
| 37 | static void mv_xor_issue_pending(struct dma_chan *chan); |
| 38 | |
| 39 | #define to_mv_xor_chan(chan) \ |
Thomas Petazzoni | 98817b9 | 2012-11-15 14:57:44 +0100 | [diff] [blame] | 40 | container_of(chan, struct mv_xor_chan, dmachan) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 41 | |
| 42 | #define to_mv_xor_slot(tx) \ |
| 43 | container_of(tx, struct mv_xor_desc_slot, async_tx) |
| 44 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 45 | #define mv_chan_to_devp(chan) \ |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 46 | ((chan)->dmadev.dev) |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 47 | |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 48 | static void mv_desc_init(struct mv_xor_desc_slot *desc, unsigned long flags) |
| 49 | { |
| 50 | struct mv_xor_desc *hw_desc = desc->hw_desc; |
| 51 | |
| 52 | hw_desc->status = (1 << 31); |
| 53 | hw_desc->phy_next_desc = 0; |
| 54 | hw_desc->desc_command = (1 << 31); |
| 55 | } |
| 56 | |
| 57 | static u32 mv_desc_get_dest_addr(struct mv_xor_desc_slot *desc) |
| 58 | { |
| 59 | struct mv_xor_desc *hw_desc = desc->hw_desc; |
| 60 | return hw_desc->phy_dest_addr; |
| 61 | } |
| 62 | |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 63 | static void mv_desc_set_byte_count(struct mv_xor_desc_slot *desc, |
| 64 | u32 byte_count) |
| 65 | { |
| 66 | struct mv_xor_desc *hw_desc = desc->hw_desc; |
| 67 | hw_desc->byte_count = byte_count; |
| 68 | } |
| 69 | |
| 70 | static void mv_desc_set_next_desc(struct mv_xor_desc_slot *desc, |
| 71 | u32 next_desc_addr) |
| 72 | { |
| 73 | struct mv_xor_desc *hw_desc = desc->hw_desc; |
| 74 | BUG_ON(hw_desc->phy_next_desc); |
| 75 | hw_desc->phy_next_desc = next_desc_addr; |
| 76 | } |
| 77 | |
| 78 | static void mv_desc_clear_next_desc(struct mv_xor_desc_slot *desc) |
| 79 | { |
| 80 | struct mv_xor_desc *hw_desc = desc->hw_desc; |
| 81 | hw_desc->phy_next_desc = 0; |
| 82 | } |
| 83 | |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 84 | static void mv_desc_set_dest_addr(struct mv_xor_desc_slot *desc, |
| 85 | dma_addr_t addr) |
| 86 | { |
| 87 | struct mv_xor_desc *hw_desc = desc->hw_desc; |
| 88 | hw_desc->phy_dest_addr = addr; |
| 89 | } |
| 90 | |
| 91 | static int mv_chan_memset_slot_count(size_t len) |
| 92 | { |
| 93 | return 1; |
| 94 | } |
| 95 | |
| 96 | #define mv_chan_memcpy_slot_count(c) mv_chan_memset_slot_count(c) |
| 97 | |
| 98 | static void mv_desc_set_src_addr(struct mv_xor_desc_slot *desc, |
| 99 | int index, dma_addr_t addr) |
| 100 | { |
| 101 | struct mv_xor_desc *hw_desc = desc->hw_desc; |
Thomas Petazzoni | e03bc65 | 2013-07-29 17:42:14 +0200 | [diff] [blame] | 102 | hw_desc->phy_src_addr[mv_phy_src_idx(index)] = addr; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 103 | if (desc->type == DMA_XOR) |
| 104 | hw_desc->desc_command |= (1 << index); |
| 105 | } |
| 106 | |
| 107 | static u32 mv_chan_get_current_desc(struct mv_xor_chan *chan) |
| 108 | { |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 109 | return readl_relaxed(XOR_CURR_DESC(chan)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static void mv_chan_set_next_descriptor(struct mv_xor_chan *chan, |
| 113 | u32 next_desc_addr) |
| 114 | { |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 115 | writel_relaxed(next_desc_addr, XOR_NEXT_DESC(chan)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 118 | static void mv_chan_unmask_interrupts(struct mv_xor_chan *chan) |
| 119 | { |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 120 | u32 val = readl_relaxed(XOR_INTR_MASK(chan)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 121 | val |= XOR_INTR_MASK_VALUE << (chan->idx * 16); |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 122 | writel_relaxed(val, XOR_INTR_MASK(chan)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static u32 mv_chan_get_intr_cause(struct mv_xor_chan *chan) |
| 126 | { |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 127 | u32 intr_cause = readl_relaxed(XOR_INTR_CAUSE(chan)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 128 | intr_cause = (intr_cause >> (chan->idx * 16)) & 0xFFFF; |
| 129 | return intr_cause; |
| 130 | } |
| 131 | |
| 132 | static int mv_is_err_intr(u32 intr_cause) |
| 133 | { |
| 134 | if (intr_cause & ((1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9))) |
| 135 | return 1; |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | static void mv_xor_device_clear_eoc_cause(struct mv_xor_chan *chan) |
| 141 | { |
Simon Guinot | 8636368 | 2010-09-17 23:33:51 +0200 | [diff] [blame] | 142 | u32 val = ~(1 << (chan->idx * 16)); |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 143 | dev_dbg(mv_chan_to_devp(chan), "%s, val 0x%08x\n", __func__, val); |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 144 | writel_relaxed(val, XOR_INTR_CAUSE(chan)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static void mv_xor_device_clear_err_status(struct mv_xor_chan *chan) |
| 148 | { |
| 149 | u32 val = 0xFFFF0000 >> (chan->idx * 16); |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 150 | writel_relaxed(val, XOR_INTR_CAUSE(chan)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | static int mv_can_chain(struct mv_xor_desc_slot *desc) |
| 154 | { |
| 155 | struct mv_xor_desc_slot *chain_old_tail = list_entry( |
| 156 | desc->chain_node.prev, struct mv_xor_desc_slot, chain_node); |
| 157 | |
| 158 | if (chain_old_tail->type != desc->type) |
| 159 | return 0; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 160 | |
| 161 | return 1; |
| 162 | } |
| 163 | |
| 164 | static void mv_set_mode(struct mv_xor_chan *chan, |
| 165 | enum dma_transaction_type type) |
| 166 | { |
| 167 | u32 op_mode; |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 168 | u32 config = readl_relaxed(XOR_CONFIG(chan)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 169 | |
| 170 | switch (type) { |
| 171 | case DMA_XOR: |
| 172 | op_mode = XOR_OPERATION_MODE_XOR; |
| 173 | break; |
| 174 | case DMA_MEMCPY: |
| 175 | op_mode = XOR_OPERATION_MODE_MEMCPY; |
| 176 | break; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 177 | default: |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 178 | dev_err(mv_chan_to_devp(chan), |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 179 | "error: unsupported operation %d\n", |
Thomas Petazzoni | a3fc74b | 2012-11-15 12:50:27 +0100 | [diff] [blame] | 180 | type); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 181 | BUG(); |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | config &= ~0x7; |
| 186 | config |= op_mode; |
Thomas Petazzoni | e03bc65 | 2013-07-29 17:42:14 +0200 | [diff] [blame] | 187 | |
| 188 | #if defined(__BIG_ENDIAN) |
| 189 | config |= XOR_DESCRIPTOR_SWAP; |
| 190 | #else |
| 191 | config &= ~XOR_DESCRIPTOR_SWAP; |
| 192 | #endif |
| 193 | |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 194 | writel_relaxed(config, XOR_CONFIG(chan)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 195 | chan->current_type = type; |
| 196 | } |
| 197 | |
| 198 | static void mv_chan_activate(struct mv_xor_chan *chan) |
| 199 | { |
| 200 | u32 activation; |
| 201 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 202 | dev_dbg(mv_chan_to_devp(chan), " activate chan.\n"); |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 203 | activation = readl_relaxed(XOR_ACTIVATION(chan)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 204 | activation |= 0x1; |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 205 | writel_relaxed(activation, XOR_ACTIVATION(chan)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static char mv_chan_is_busy(struct mv_xor_chan *chan) |
| 209 | { |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 210 | u32 state = readl_relaxed(XOR_ACTIVATION(chan)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 211 | |
| 212 | state = (state >> 4) & 0x3; |
| 213 | |
| 214 | return (state == 1) ? 1 : 0; |
| 215 | } |
| 216 | |
| 217 | static int mv_chan_xor_slot_count(size_t len, int src_cnt) |
| 218 | { |
| 219 | return 1; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * mv_xor_free_slots - flags descriptor slots for reuse |
| 224 | * @slot: Slot to free |
| 225 | * Caller must hold &mv_chan->lock while calling this function |
| 226 | */ |
| 227 | static void mv_xor_free_slots(struct mv_xor_chan *mv_chan, |
| 228 | struct mv_xor_desc_slot *slot) |
| 229 | { |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 230 | dev_dbg(mv_chan_to_devp(mv_chan), "%s %d slot %p\n", |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 231 | __func__, __LINE__, slot); |
| 232 | |
| 233 | slot->slots_per_op = 0; |
| 234 | |
| 235 | } |
| 236 | |
| 237 | /* |
| 238 | * mv_xor_start_new_chain - program the engine to operate on new chain headed by |
| 239 | * sw_desc |
| 240 | * Caller must hold &mv_chan->lock while calling this function |
| 241 | */ |
| 242 | static void mv_xor_start_new_chain(struct mv_xor_chan *mv_chan, |
| 243 | struct mv_xor_desc_slot *sw_desc) |
| 244 | { |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 245 | dev_dbg(mv_chan_to_devp(mv_chan), "%s %d: sw_desc %p\n", |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 246 | __func__, __LINE__, sw_desc); |
| 247 | if (sw_desc->type != mv_chan->current_type) |
| 248 | mv_set_mode(mv_chan, sw_desc->type); |
| 249 | |
Bartlomiej Zolnierkiewicz | 48a9db4 | 2013-07-03 15:05:06 -0700 | [diff] [blame] | 250 | /* set the hardware chain */ |
| 251 | mv_chan_set_next_descriptor(mv_chan, sw_desc->async_tx.phys); |
| 252 | |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 253 | mv_chan->pending += sw_desc->slot_cnt; |
Thomas Petazzoni | 98817b9 | 2012-11-15 14:57:44 +0100 | [diff] [blame] | 254 | mv_xor_issue_pending(&mv_chan->dmachan); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | static dma_cookie_t |
| 258 | mv_xor_run_tx_complete_actions(struct mv_xor_desc_slot *desc, |
| 259 | struct mv_xor_chan *mv_chan, dma_cookie_t cookie) |
| 260 | { |
| 261 | BUG_ON(desc->async_tx.cookie < 0); |
| 262 | |
| 263 | if (desc->async_tx.cookie > 0) { |
| 264 | cookie = desc->async_tx.cookie; |
| 265 | |
| 266 | /* call the callback (must not sleep or submit new |
| 267 | * operations to this channel) |
| 268 | */ |
| 269 | if (desc->async_tx.callback) |
| 270 | desc->async_tx.callback( |
| 271 | desc->async_tx.callback_param); |
| 272 | |
Dan Williams | d38a8c6 | 2013-10-18 19:35:23 +0200 | [diff] [blame] | 273 | dma_descriptor_unmap(&desc->async_tx); |
Bartlomiej Zolnierkiewicz | 54f8d50 | 2013-10-18 19:35:32 +0200 | [diff] [blame^] | 274 | if (desc->group_head) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 275 | desc->group_head = NULL; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /* run dependent operations */ |
Dan Williams | 07f2211 | 2009-01-05 17:14:31 -0700 | [diff] [blame] | 279 | dma_run_dependencies(&desc->async_tx); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 280 | |
| 281 | return cookie; |
| 282 | } |
| 283 | |
| 284 | static int |
| 285 | mv_xor_clean_completed_slots(struct mv_xor_chan *mv_chan) |
| 286 | { |
| 287 | struct mv_xor_desc_slot *iter, *_iter; |
| 288 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 289 | dev_dbg(mv_chan_to_devp(mv_chan), "%s %d\n", __func__, __LINE__); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 290 | list_for_each_entry_safe(iter, _iter, &mv_chan->completed_slots, |
| 291 | completed_node) { |
| 292 | |
| 293 | if (async_tx_test_ack(&iter->async_tx)) { |
| 294 | list_del(&iter->completed_node); |
| 295 | mv_xor_free_slots(mv_chan, iter); |
| 296 | } |
| 297 | } |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | static int |
| 302 | mv_xor_clean_slot(struct mv_xor_desc_slot *desc, |
| 303 | struct mv_xor_chan *mv_chan) |
| 304 | { |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 305 | dev_dbg(mv_chan_to_devp(mv_chan), "%s %d: desc %p flags %d\n", |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 306 | __func__, __LINE__, desc, desc->async_tx.flags); |
| 307 | list_del(&desc->chain_node); |
| 308 | /* the client is allowed to attach dependent operations |
| 309 | * until 'ack' is set |
| 310 | */ |
| 311 | if (!async_tx_test_ack(&desc->async_tx)) { |
| 312 | /* move this slot to the completed_slots */ |
| 313 | list_add_tail(&desc->completed_node, &mv_chan->completed_slots); |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | mv_xor_free_slots(mv_chan, desc); |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | static void __mv_xor_slot_cleanup(struct mv_xor_chan *mv_chan) |
| 322 | { |
| 323 | struct mv_xor_desc_slot *iter, *_iter; |
| 324 | dma_cookie_t cookie = 0; |
| 325 | int busy = mv_chan_is_busy(mv_chan); |
| 326 | u32 current_desc = mv_chan_get_current_desc(mv_chan); |
| 327 | int seen_current = 0; |
| 328 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 329 | dev_dbg(mv_chan_to_devp(mv_chan), "%s %d\n", __func__, __LINE__); |
| 330 | dev_dbg(mv_chan_to_devp(mv_chan), "current_desc %x\n", current_desc); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 331 | mv_xor_clean_completed_slots(mv_chan); |
| 332 | |
| 333 | /* free completed slots from the chain starting with |
| 334 | * the oldest descriptor |
| 335 | */ |
| 336 | |
| 337 | list_for_each_entry_safe(iter, _iter, &mv_chan->chain, |
| 338 | chain_node) { |
| 339 | prefetch(_iter); |
| 340 | prefetch(&_iter->async_tx); |
| 341 | |
| 342 | /* do not advance past the current descriptor loaded into the |
| 343 | * hardware channel, subsequent descriptors are either in |
| 344 | * process or have not been submitted |
| 345 | */ |
| 346 | if (seen_current) |
| 347 | break; |
| 348 | |
| 349 | /* stop the search if we reach the current descriptor and the |
| 350 | * channel is busy |
| 351 | */ |
| 352 | if (iter->async_tx.phys == current_desc) { |
| 353 | seen_current = 1; |
| 354 | if (busy) |
| 355 | break; |
| 356 | } |
| 357 | |
| 358 | cookie = mv_xor_run_tx_complete_actions(iter, mv_chan, cookie); |
| 359 | |
| 360 | if (mv_xor_clean_slot(iter, mv_chan)) |
| 361 | break; |
| 362 | } |
| 363 | |
| 364 | if ((busy == 0) && !list_empty(&mv_chan->chain)) { |
| 365 | struct mv_xor_desc_slot *chain_head; |
| 366 | chain_head = list_entry(mv_chan->chain.next, |
| 367 | struct mv_xor_desc_slot, |
| 368 | chain_node); |
| 369 | |
| 370 | mv_xor_start_new_chain(mv_chan, chain_head); |
| 371 | } |
| 372 | |
| 373 | if (cookie > 0) |
Thomas Petazzoni | 98817b9 | 2012-11-15 14:57:44 +0100 | [diff] [blame] | 374 | mv_chan->dmachan.completed_cookie = cookie; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static void |
| 378 | mv_xor_slot_cleanup(struct mv_xor_chan *mv_chan) |
| 379 | { |
| 380 | spin_lock_bh(&mv_chan->lock); |
| 381 | __mv_xor_slot_cleanup(mv_chan); |
| 382 | spin_unlock_bh(&mv_chan->lock); |
| 383 | } |
| 384 | |
| 385 | static void mv_xor_tasklet(unsigned long data) |
| 386 | { |
| 387 | struct mv_xor_chan *chan = (struct mv_xor_chan *) data; |
Saeed Bishara | 8333f65 | 2010-12-21 16:53:39 +0200 | [diff] [blame] | 388 | mv_xor_slot_cleanup(chan); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static struct mv_xor_desc_slot * |
| 392 | mv_xor_alloc_slots(struct mv_xor_chan *mv_chan, int num_slots, |
| 393 | int slots_per_op) |
| 394 | { |
| 395 | struct mv_xor_desc_slot *iter, *_iter, *alloc_start = NULL; |
| 396 | LIST_HEAD(chain); |
| 397 | int slots_found, retry = 0; |
| 398 | |
| 399 | /* start search from the last allocated descrtiptor |
| 400 | * if a contiguous allocation can not be found start searching |
| 401 | * from the beginning of the list |
| 402 | */ |
| 403 | retry: |
| 404 | slots_found = 0; |
| 405 | if (retry == 0) |
| 406 | iter = mv_chan->last_used; |
| 407 | else |
| 408 | iter = list_entry(&mv_chan->all_slots, |
| 409 | struct mv_xor_desc_slot, |
| 410 | slot_node); |
| 411 | |
| 412 | list_for_each_entry_safe_continue( |
| 413 | iter, _iter, &mv_chan->all_slots, slot_node) { |
| 414 | prefetch(_iter); |
| 415 | prefetch(&_iter->async_tx); |
| 416 | if (iter->slots_per_op) { |
| 417 | /* give up after finding the first busy slot |
| 418 | * on the second pass through the list |
| 419 | */ |
| 420 | if (retry) |
| 421 | break; |
| 422 | |
| 423 | slots_found = 0; |
| 424 | continue; |
| 425 | } |
| 426 | |
| 427 | /* start the allocation if the slot is correctly aligned */ |
| 428 | if (!slots_found++) |
| 429 | alloc_start = iter; |
| 430 | |
| 431 | if (slots_found == num_slots) { |
| 432 | struct mv_xor_desc_slot *alloc_tail = NULL; |
| 433 | struct mv_xor_desc_slot *last_used = NULL; |
| 434 | iter = alloc_start; |
| 435 | while (num_slots) { |
| 436 | int i; |
| 437 | |
| 438 | /* pre-ack all but the last descriptor */ |
| 439 | async_tx_ack(&iter->async_tx); |
| 440 | |
| 441 | list_add_tail(&iter->chain_node, &chain); |
| 442 | alloc_tail = iter; |
| 443 | iter->async_tx.cookie = 0; |
| 444 | iter->slot_cnt = num_slots; |
| 445 | iter->xor_check_result = NULL; |
| 446 | for (i = 0; i < slots_per_op; i++) { |
| 447 | iter->slots_per_op = slots_per_op - i; |
| 448 | last_used = iter; |
| 449 | iter = list_entry(iter->slot_node.next, |
| 450 | struct mv_xor_desc_slot, |
| 451 | slot_node); |
| 452 | } |
| 453 | num_slots -= slots_per_op; |
| 454 | } |
| 455 | alloc_tail->group_head = alloc_start; |
| 456 | alloc_tail->async_tx.cookie = -EBUSY; |
Dan Williams | 64203b6 | 2009-09-08 17:53:03 -0700 | [diff] [blame] | 457 | list_splice(&chain, &alloc_tail->tx_list); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 458 | mv_chan->last_used = last_used; |
| 459 | mv_desc_clear_next_desc(alloc_start); |
| 460 | mv_desc_clear_next_desc(alloc_tail); |
| 461 | return alloc_tail; |
| 462 | } |
| 463 | } |
| 464 | if (!retry++) |
| 465 | goto retry; |
| 466 | |
| 467 | /* try to free some slots if the allocation fails */ |
| 468 | tasklet_schedule(&mv_chan->irq_tasklet); |
| 469 | |
| 470 | return NULL; |
| 471 | } |
| 472 | |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 473 | /************************ DMA engine API functions ****************************/ |
| 474 | static dma_cookie_t |
| 475 | mv_xor_tx_submit(struct dma_async_tx_descriptor *tx) |
| 476 | { |
| 477 | struct mv_xor_desc_slot *sw_desc = to_mv_xor_slot(tx); |
| 478 | struct mv_xor_chan *mv_chan = to_mv_xor_chan(tx->chan); |
| 479 | struct mv_xor_desc_slot *grp_start, *old_chain_tail; |
| 480 | dma_cookie_t cookie; |
| 481 | int new_hw_chain = 1; |
| 482 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 483 | dev_dbg(mv_chan_to_devp(mv_chan), |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 484 | "%s sw_desc %p: async_tx %p\n", |
| 485 | __func__, sw_desc, &sw_desc->async_tx); |
| 486 | |
| 487 | grp_start = sw_desc->group_head; |
| 488 | |
| 489 | spin_lock_bh(&mv_chan->lock); |
Russell King - ARM Linux | 884485e | 2012-03-06 22:34:46 +0000 | [diff] [blame] | 490 | cookie = dma_cookie_assign(tx); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 491 | |
| 492 | if (list_empty(&mv_chan->chain)) |
Dan Williams | 64203b6 | 2009-09-08 17:53:03 -0700 | [diff] [blame] | 493 | list_splice_init(&sw_desc->tx_list, &mv_chan->chain); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 494 | else { |
| 495 | new_hw_chain = 0; |
| 496 | |
| 497 | old_chain_tail = list_entry(mv_chan->chain.prev, |
| 498 | struct mv_xor_desc_slot, |
| 499 | chain_node); |
Dan Williams | 64203b6 | 2009-09-08 17:53:03 -0700 | [diff] [blame] | 500 | list_splice_init(&grp_start->tx_list, |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 501 | &old_chain_tail->chain_node); |
| 502 | |
| 503 | if (!mv_can_chain(grp_start)) |
| 504 | goto submit_done; |
| 505 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 506 | dev_dbg(mv_chan_to_devp(mv_chan), "Append to last desc %x\n", |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 507 | old_chain_tail->async_tx.phys); |
| 508 | |
| 509 | /* fix up the hardware chain */ |
| 510 | mv_desc_set_next_desc(old_chain_tail, grp_start->async_tx.phys); |
| 511 | |
| 512 | /* if the channel is not busy */ |
| 513 | if (!mv_chan_is_busy(mv_chan)) { |
| 514 | u32 current_desc = mv_chan_get_current_desc(mv_chan); |
| 515 | /* |
| 516 | * and the curren desc is the end of the chain before |
| 517 | * the append, then we need to start the channel |
| 518 | */ |
| 519 | if (current_desc == old_chain_tail->async_tx.phys) |
| 520 | new_hw_chain = 1; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | if (new_hw_chain) |
| 525 | mv_xor_start_new_chain(mv_chan, grp_start); |
| 526 | |
| 527 | submit_done: |
| 528 | spin_unlock_bh(&mv_chan->lock); |
| 529 | |
| 530 | return cookie; |
| 531 | } |
| 532 | |
| 533 | /* returns the number of allocated descriptors */ |
Dan Williams | aa1e6f1 | 2009-01-06 11:38:17 -0700 | [diff] [blame] | 534 | static int mv_xor_alloc_chan_resources(struct dma_chan *chan) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 535 | { |
| 536 | char *hw_desc; |
| 537 | int idx; |
| 538 | struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan); |
| 539 | struct mv_xor_desc_slot *slot = NULL; |
Thomas Petazzoni | b503fa0 | 2012-11-15 15:55:30 +0100 | [diff] [blame] | 540 | int num_descs_in_pool = MV_XOR_POOL_SIZE/MV_XOR_SLOT_SIZE; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 541 | |
| 542 | /* Allocate descriptor slots */ |
| 543 | idx = mv_chan->slots_allocated; |
| 544 | while (idx < num_descs_in_pool) { |
| 545 | slot = kzalloc(sizeof(*slot), GFP_KERNEL); |
| 546 | if (!slot) { |
| 547 | printk(KERN_INFO "MV XOR Channel only initialized" |
| 548 | " %d descriptor slots", idx); |
| 549 | break; |
| 550 | } |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 551 | hw_desc = (char *) mv_chan->dma_desc_pool_virt; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 552 | slot->hw_desc = (void *) &hw_desc[idx * MV_XOR_SLOT_SIZE]; |
| 553 | |
| 554 | dma_async_tx_descriptor_init(&slot->async_tx, chan); |
| 555 | slot->async_tx.tx_submit = mv_xor_tx_submit; |
| 556 | INIT_LIST_HEAD(&slot->chain_node); |
| 557 | INIT_LIST_HEAD(&slot->slot_node); |
Dan Williams | 64203b6 | 2009-09-08 17:53:03 -0700 | [diff] [blame] | 558 | INIT_LIST_HEAD(&slot->tx_list); |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 559 | hw_desc = (char *) mv_chan->dma_desc_pool; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 560 | slot->async_tx.phys = |
| 561 | (dma_addr_t) &hw_desc[idx * MV_XOR_SLOT_SIZE]; |
| 562 | slot->idx = idx++; |
| 563 | |
| 564 | spin_lock_bh(&mv_chan->lock); |
| 565 | mv_chan->slots_allocated = idx; |
| 566 | list_add_tail(&slot->slot_node, &mv_chan->all_slots); |
| 567 | spin_unlock_bh(&mv_chan->lock); |
| 568 | } |
| 569 | |
| 570 | if (mv_chan->slots_allocated && !mv_chan->last_used) |
| 571 | mv_chan->last_used = list_entry(mv_chan->all_slots.next, |
| 572 | struct mv_xor_desc_slot, |
| 573 | slot_node); |
| 574 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 575 | dev_dbg(mv_chan_to_devp(mv_chan), |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 576 | "allocated %d descriptor slots last_used: %p\n", |
| 577 | mv_chan->slots_allocated, mv_chan->last_used); |
| 578 | |
| 579 | return mv_chan->slots_allocated ? : -ENOMEM; |
| 580 | } |
| 581 | |
| 582 | static struct dma_async_tx_descriptor * |
| 583 | mv_xor_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, |
| 584 | size_t len, unsigned long flags) |
| 585 | { |
| 586 | struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan); |
| 587 | struct mv_xor_desc_slot *sw_desc, *grp_start; |
| 588 | int slot_cnt; |
| 589 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 590 | dev_dbg(mv_chan_to_devp(mv_chan), |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 591 | "%s dest: %x src %x len: %u flags: %ld\n", |
| 592 | __func__, dest, src, len, flags); |
| 593 | if (unlikely(len < MV_XOR_MIN_BYTE_COUNT)) |
| 594 | return NULL; |
| 595 | |
Coly Li | 7912d30 | 2011-03-27 01:26:53 +0800 | [diff] [blame] | 596 | BUG_ON(len > MV_XOR_MAX_BYTE_COUNT); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 597 | |
| 598 | spin_lock_bh(&mv_chan->lock); |
| 599 | slot_cnt = mv_chan_memcpy_slot_count(len); |
| 600 | sw_desc = mv_xor_alloc_slots(mv_chan, slot_cnt, 1); |
| 601 | if (sw_desc) { |
| 602 | sw_desc->type = DMA_MEMCPY; |
| 603 | sw_desc->async_tx.flags = flags; |
| 604 | grp_start = sw_desc->group_head; |
| 605 | mv_desc_init(grp_start, flags); |
| 606 | mv_desc_set_byte_count(grp_start, len); |
| 607 | mv_desc_set_dest_addr(sw_desc->group_head, dest); |
| 608 | mv_desc_set_src_addr(grp_start, 0, src); |
| 609 | sw_desc->unmap_src_cnt = 1; |
| 610 | sw_desc->unmap_len = len; |
| 611 | } |
| 612 | spin_unlock_bh(&mv_chan->lock); |
| 613 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 614 | dev_dbg(mv_chan_to_devp(mv_chan), |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 615 | "%s sw_desc %p async_tx %p\n", |
Jingoo Han | 4c14372 | 2013-08-06 19:37:08 +0900 | [diff] [blame] | 616 | __func__, sw_desc, sw_desc ? &sw_desc->async_tx : NULL); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 617 | |
| 618 | return sw_desc ? &sw_desc->async_tx : NULL; |
| 619 | } |
| 620 | |
| 621 | static struct dma_async_tx_descriptor * |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 622 | mv_xor_prep_dma_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src, |
| 623 | unsigned int src_cnt, size_t len, unsigned long flags) |
| 624 | { |
| 625 | struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan); |
| 626 | struct mv_xor_desc_slot *sw_desc, *grp_start; |
| 627 | int slot_cnt; |
| 628 | |
| 629 | if (unlikely(len < MV_XOR_MIN_BYTE_COUNT)) |
| 630 | return NULL; |
| 631 | |
Coly Li | 7912d30 | 2011-03-27 01:26:53 +0800 | [diff] [blame] | 632 | BUG_ON(len > MV_XOR_MAX_BYTE_COUNT); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 633 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 634 | dev_dbg(mv_chan_to_devp(mv_chan), |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 635 | "%s src_cnt: %d len: dest %x %u flags: %ld\n", |
| 636 | __func__, src_cnt, len, dest, flags); |
| 637 | |
| 638 | spin_lock_bh(&mv_chan->lock); |
| 639 | slot_cnt = mv_chan_xor_slot_count(len, src_cnt); |
| 640 | sw_desc = mv_xor_alloc_slots(mv_chan, slot_cnt, 1); |
| 641 | if (sw_desc) { |
| 642 | sw_desc->type = DMA_XOR; |
| 643 | sw_desc->async_tx.flags = flags; |
| 644 | grp_start = sw_desc->group_head; |
| 645 | mv_desc_init(grp_start, flags); |
| 646 | /* the byte count field is the same as in memcpy desc*/ |
| 647 | mv_desc_set_byte_count(grp_start, len); |
| 648 | mv_desc_set_dest_addr(sw_desc->group_head, dest); |
| 649 | sw_desc->unmap_src_cnt = src_cnt; |
| 650 | sw_desc->unmap_len = len; |
| 651 | while (src_cnt--) |
| 652 | mv_desc_set_src_addr(grp_start, src_cnt, src[src_cnt]); |
| 653 | } |
| 654 | spin_unlock_bh(&mv_chan->lock); |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 655 | dev_dbg(mv_chan_to_devp(mv_chan), |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 656 | "%s sw_desc %p async_tx %p \n", |
| 657 | __func__, sw_desc, &sw_desc->async_tx); |
| 658 | return sw_desc ? &sw_desc->async_tx : NULL; |
| 659 | } |
| 660 | |
| 661 | static void mv_xor_free_chan_resources(struct dma_chan *chan) |
| 662 | { |
| 663 | struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan); |
| 664 | struct mv_xor_desc_slot *iter, *_iter; |
| 665 | int in_use_descs = 0; |
| 666 | |
| 667 | mv_xor_slot_cleanup(mv_chan); |
| 668 | |
| 669 | spin_lock_bh(&mv_chan->lock); |
| 670 | list_for_each_entry_safe(iter, _iter, &mv_chan->chain, |
| 671 | chain_node) { |
| 672 | in_use_descs++; |
| 673 | list_del(&iter->chain_node); |
| 674 | } |
| 675 | list_for_each_entry_safe(iter, _iter, &mv_chan->completed_slots, |
| 676 | completed_node) { |
| 677 | in_use_descs++; |
| 678 | list_del(&iter->completed_node); |
| 679 | } |
| 680 | list_for_each_entry_safe_reverse( |
| 681 | iter, _iter, &mv_chan->all_slots, slot_node) { |
| 682 | list_del(&iter->slot_node); |
| 683 | kfree(iter); |
| 684 | mv_chan->slots_allocated--; |
| 685 | } |
| 686 | mv_chan->last_used = NULL; |
| 687 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 688 | dev_dbg(mv_chan_to_devp(mv_chan), "%s slots_allocated %d\n", |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 689 | __func__, mv_chan->slots_allocated); |
| 690 | spin_unlock_bh(&mv_chan->lock); |
| 691 | |
| 692 | if (in_use_descs) |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 693 | dev_err(mv_chan_to_devp(mv_chan), |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 694 | "freeing %d in use descriptors!\n", in_use_descs); |
| 695 | } |
| 696 | |
| 697 | /** |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 698 | * mv_xor_status - poll the status of an XOR transaction |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 699 | * @chan: XOR channel handle |
| 700 | * @cookie: XOR transaction identifier |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 701 | * @txstate: XOR transactions state holder (or NULL) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 702 | */ |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 703 | static enum dma_status mv_xor_status(struct dma_chan *chan, |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 704 | dma_cookie_t cookie, |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 705 | struct dma_tx_state *txstate) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 706 | { |
| 707 | struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 708 | enum dma_status ret; |
| 709 | |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 710 | ret = dma_cookie_status(chan, cookie, txstate); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 711 | if (ret == DMA_SUCCESS) { |
| 712 | mv_xor_clean_completed_slots(mv_chan); |
| 713 | return ret; |
| 714 | } |
| 715 | mv_xor_slot_cleanup(mv_chan); |
| 716 | |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 717 | return dma_cookie_status(chan, cookie, txstate); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | static void mv_dump_xor_regs(struct mv_xor_chan *chan) |
| 721 | { |
| 722 | u32 val; |
| 723 | |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 724 | val = readl_relaxed(XOR_CONFIG(chan)); |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 725 | dev_err(mv_chan_to_devp(chan), "config 0x%08x\n", val); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 726 | |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 727 | val = readl_relaxed(XOR_ACTIVATION(chan)); |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 728 | dev_err(mv_chan_to_devp(chan), "activation 0x%08x\n", val); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 729 | |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 730 | val = readl_relaxed(XOR_INTR_CAUSE(chan)); |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 731 | dev_err(mv_chan_to_devp(chan), "intr cause 0x%08x\n", val); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 732 | |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 733 | val = readl_relaxed(XOR_INTR_MASK(chan)); |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 734 | dev_err(mv_chan_to_devp(chan), "intr mask 0x%08x\n", val); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 735 | |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 736 | val = readl_relaxed(XOR_ERROR_CAUSE(chan)); |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 737 | dev_err(mv_chan_to_devp(chan), "error cause 0x%08x\n", val); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 738 | |
Thomas Petazzoni | 5733c38 | 2013-07-29 17:42:13 +0200 | [diff] [blame] | 739 | val = readl_relaxed(XOR_ERROR_ADDR(chan)); |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 740 | dev_err(mv_chan_to_devp(chan), "error addr 0x%08x\n", val); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | static void mv_xor_err_interrupt_handler(struct mv_xor_chan *chan, |
| 744 | u32 intr_cause) |
| 745 | { |
| 746 | if (intr_cause & (1 << 4)) { |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 747 | dev_dbg(mv_chan_to_devp(chan), |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 748 | "ignore this error\n"); |
| 749 | return; |
| 750 | } |
| 751 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 752 | dev_err(mv_chan_to_devp(chan), |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 753 | "error on chan %d. intr cause 0x%08x\n", |
Thomas Petazzoni | a3fc74b | 2012-11-15 12:50:27 +0100 | [diff] [blame] | 754 | chan->idx, intr_cause); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 755 | |
| 756 | mv_dump_xor_regs(chan); |
| 757 | BUG(); |
| 758 | } |
| 759 | |
| 760 | static irqreturn_t mv_xor_interrupt_handler(int irq, void *data) |
| 761 | { |
| 762 | struct mv_xor_chan *chan = data; |
| 763 | u32 intr_cause = mv_chan_get_intr_cause(chan); |
| 764 | |
Thomas Petazzoni | c98c178 | 2012-11-15 14:17:18 +0100 | [diff] [blame] | 765 | dev_dbg(mv_chan_to_devp(chan), "intr cause %x\n", intr_cause); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 766 | |
| 767 | if (mv_is_err_intr(intr_cause)) |
| 768 | mv_xor_err_interrupt_handler(chan, intr_cause); |
| 769 | |
| 770 | tasklet_schedule(&chan->irq_tasklet); |
| 771 | |
| 772 | mv_xor_device_clear_eoc_cause(chan); |
| 773 | |
| 774 | return IRQ_HANDLED; |
| 775 | } |
| 776 | |
| 777 | static void mv_xor_issue_pending(struct dma_chan *chan) |
| 778 | { |
| 779 | struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan); |
| 780 | |
| 781 | if (mv_chan->pending >= MV_XOR_THRESHOLD) { |
| 782 | mv_chan->pending = 0; |
| 783 | mv_chan_activate(mv_chan); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | /* |
| 788 | * Perform a transaction to verify the HW works. |
| 789 | */ |
| 790 | #define MV_XOR_TEST_SIZE 2000 |
| 791 | |
Linus Torvalds | c271433 | 2012-12-14 14:54:26 -0800 | [diff] [blame] | 792 | static int mv_xor_memcpy_self_test(struct mv_xor_chan *mv_chan) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 793 | { |
| 794 | int i; |
| 795 | void *src, *dest; |
| 796 | dma_addr_t src_dma, dest_dma; |
| 797 | struct dma_chan *dma_chan; |
| 798 | dma_cookie_t cookie; |
| 799 | struct dma_async_tx_descriptor *tx; |
| 800 | int err = 0; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 801 | |
| 802 | src = kmalloc(sizeof(u8) * MV_XOR_TEST_SIZE, GFP_KERNEL); |
| 803 | if (!src) |
| 804 | return -ENOMEM; |
| 805 | |
| 806 | dest = kzalloc(sizeof(u8) * MV_XOR_TEST_SIZE, GFP_KERNEL); |
| 807 | if (!dest) { |
| 808 | kfree(src); |
| 809 | return -ENOMEM; |
| 810 | } |
| 811 | |
| 812 | /* Fill in src buffer */ |
| 813 | for (i = 0; i < MV_XOR_TEST_SIZE; i++) |
| 814 | ((u8 *) src)[i] = (u8)i; |
| 815 | |
Thomas Petazzoni | 275cc0c | 2012-11-15 15:09:42 +0100 | [diff] [blame] | 816 | dma_chan = &mv_chan->dmachan; |
Dan Williams | aa1e6f1 | 2009-01-06 11:38:17 -0700 | [diff] [blame] | 817 | if (mv_xor_alloc_chan_resources(dma_chan) < 1) { |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 818 | err = -ENODEV; |
| 819 | goto out; |
| 820 | } |
| 821 | |
| 822 | dest_dma = dma_map_single(dma_chan->device->dev, dest, |
| 823 | MV_XOR_TEST_SIZE, DMA_FROM_DEVICE); |
| 824 | |
| 825 | src_dma = dma_map_single(dma_chan->device->dev, src, |
| 826 | MV_XOR_TEST_SIZE, DMA_TO_DEVICE); |
| 827 | |
| 828 | tx = mv_xor_prep_dma_memcpy(dma_chan, dest_dma, src_dma, |
| 829 | MV_XOR_TEST_SIZE, 0); |
| 830 | cookie = mv_xor_tx_submit(tx); |
| 831 | mv_xor_issue_pending(dma_chan); |
| 832 | async_tx_ack(tx); |
| 833 | msleep(1); |
| 834 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 835 | if (mv_xor_status(dma_chan, cookie, NULL) != |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 836 | DMA_SUCCESS) { |
Thomas Petazzoni | a3fc74b | 2012-11-15 12:50:27 +0100 | [diff] [blame] | 837 | dev_err(dma_chan->device->dev, |
| 838 | "Self-test copy timed out, disabling\n"); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 839 | err = -ENODEV; |
| 840 | goto free_resources; |
| 841 | } |
| 842 | |
Thomas Petazzoni | c35064c | 2012-11-15 13:01:59 +0100 | [diff] [blame] | 843 | dma_sync_single_for_cpu(dma_chan->device->dev, dest_dma, |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 844 | MV_XOR_TEST_SIZE, DMA_FROM_DEVICE); |
| 845 | if (memcmp(src, dest, MV_XOR_TEST_SIZE)) { |
Thomas Petazzoni | a3fc74b | 2012-11-15 12:50:27 +0100 | [diff] [blame] | 846 | dev_err(dma_chan->device->dev, |
| 847 | "Self-test copy failed compare, disabling\n"); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 848 | err = -ENODEV; |
| 849 | goto free_resources; |
| 850 | } |
| 851 | |
| 852 | free_resources: |
| 853 | mv_xor_free_chan_resources(dma_chan); |
| 854 | out: |
| 855 | kfree(src); |
| 856 | kfree(dest); |
| 857 | return err; |
| 858 | } |
| 859 | |
| 860 | #define MV_XOR_NUM_SRC_TEST 4 /* must be <= 15 */ |
Bill Pemberton | 463a1f8 | 2012-11-19 13:22:55 -0500 | [diff] [blame] | 861 | static int |
Thomas Petazzoni | 275cc0c | 2012-11-15 15:09:42 +0100 | [diff] [blame] | 862 | mv_xor_xor_self_test(struct mv_xor_chan *mv_chan) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 863 | { |
| 864 | int i, src_idx; |
| 865 | struct page *dest; |
| 866 | struct page *xor_srcs[MV_XOR_NUM_SRC_TEST]; |
| 867 | dma_addr_t dma_srcs[MV_XOR_NUM_SRC_TEST]; |
| 868 | dma_addr_t dest_dma; |
| 869 | struct dma_async_tx_descriptor *tx; |
| 870 | struct dma_chan *dma_chan; |
| 871 | dma_cookie_t cookie; |
| 872 | u8 cmp_byte = 0; |
| 873 | u32 cmp_word; |
| 874 | int err = 0; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 875 | |
| 876 | for (src_idx = 0; src_idx < MV_XOR_NUM_SRC_TEST; src_idx++) { |
| 877 | xor_srcs[src_idx] = alloc_page(GFP_KERNEL); |
Roel Kluin | a09b09a | 2009-02-25 13:56:21 +0100 | [diff] [blame] | 878 | if (!xor_srcs[src_idx]) { |
| 879 | while (src_idx--) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 880 | __free_page(xor_srcs[src_idx]); |
Roel Kluin | a09b09a | 2009-02-25 13:56:21 +0100 | [diff] [blame] | 881 | return -ENOMEM; |
| 882 | } |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | dest = alloc_page(GFP_KERNEL); |
Roel Kluin | a09b09a | 2009-02-25 13:56:21 +0100 | [diff] [blame] | 886 | if (!dest) { |
| 887 | while (src_idx--) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 888 | __free_page(xor_srcs[src_idx]); |
Roel Kluin | a09b09a | 2009-02-25 13:56:21 +0100 | [diff] [blame] | 889 | return -ENOMEM; |
| 890 | } |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 891 | |
| 892 | /* Fill in src buffers */ |
| 893 | for (src_idx = 0; src_idx < MV_XOR_NUM_SRC_TEST; src_idx++) { |
| 894 | u8 *ptr = page_address(xor_srcs[src_idx]); |
| 895 | for (i = 0; i < PAGE_SIZE; i++) |
| 896 | ptr[i] = (1 << src_idx); |
| 897 | } |
| 898 | |
| 899 | for (src_idx = 0; src_idx < MV_XOR_NUM_SRC_TEST; src_idx++) |
| 900 | cmp_byte ^= (u8) (1 << src_idx); |
| 901 | |
| 902 | cmp_word = (cmp_byte << 24) | (cmp_byte << 16) | |
| 903 | (cmp_byte << 8) | cmp_byte; |
| 904 | |
| 905 | memset(page_address(dest), 0, PAGE_SIZE); |
| 906 | |
Thomas Petazzoni | 275cc0c | 2012-11-15 15:09:42 +0100 | [diff] [blame] | 907 | dma_chan = &mv_chan->dmachan; |
Dan Williams | aa1e6f1 | 2009-01-06 11:38:17 -0700 | [diff] [blame] | 908 | if (mv_xor_alloc_chan_resources(dma_chan) < 1) { |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 909 | err = -ENODEV; |
| 910 | goto out; |
| 911 | } |
| 912 | |
| 913 | /* test xor */ |
| 914 | dest_dma = dma_map_page(dma_chan->device->dev, dest, 0, PAGE_SIZE, |
| 915 | DMA_FROM_DEVICE); |
| 916 | |
| 917 | for (i = 0; i < MV_XOR_NUM_SRC_TEST; i++) |
| 918 | dma_srcs[i] = dma_map_page(dma_chan->device->dev, xor_srcs[i], |
| 919 | 0, PAGE_SIZE, DMA_TO_DEVICE); |
| 920 | |
| 921 | tx = mv_xor_prep_dma_xor(dma_chan, dest_dma, dma_srcs, |
| 922 | MV_XOR_NUM_SRC_TEST, PAGE_SIZE, 0); |
| 923 | |
| 924 | cookie = mv_xor_tx_submit(tx); |
| 925 | mv_xor_issue_pending(dma_chan); |
| 926 | async_tx_ack(tx); |
| 927 | msleep(8); |
| 928 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 929 | if (mv_xor_status(dma_chan, cookie, NULL) != |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 930 | DMA_SUCCESS) { |
Thomas Petazzoni | a3fc74b | 2012-11-15 12:50:27 +0100 | [diff] [blame] | 931 | dev_err(dma_chan->device->dev, |
| 932 | "Self-test xor timed out, disabling\n"); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 933 | err = -ENODEV; |
| 934 | goto free_resources; |
| 935 | } |
| 936 | |
Thomas Petazzoni | c35064c | 2012-11-15 13:01:59 +0100 | [diff] [blame] | 937 | dma_sync_single_for_cpu(dma_chan->device->dev, dest_dma, |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 938 | PAGE_SIZE, DMA_FROM_DEVICE); |
| 939 | for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) { |
| 940 | u32 *ptr = page_address(dest); |
| 941 | if (ptr[i] != cmp_word) { |
Thomas Petazzoni | a3fc74b | 2012-11-15 12:50:27 +0100 | [diff] [blame] | 942 | dev_err(dma_chan->device->dev, |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 943 | "Self-test xor failed compare, disabling. index %d, data %x, expected %x\n", |
| 944 | i, ptr[i], cmp_word); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 945 | err = -ENODEV; |
| 946 | goto free_resources; |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | free_resources: |
| 951 | mv_xor_free_chan_resources(dma_chan); |
| 952 | out: |
| 953 | src_idx = MV_XOR_NUM_SRC_TEST; |
| 954 | while (src_idx--) |
| 955 | __free_page(xor_srcs[src_idx]); |
| 956 | __free_page(dest); |
| 957 | return err; |
| 958 | } |
| 959 | |
Andrew Lunn | 34c93c8 | 2012-11-18 11:44:56 +0100 | [diff] [blame] | 960 | /* This driver does not implement any of the optional DMA operations. */ |
| 961 | static int |
| 962 | mv_xor_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, |
| 963 | unsigned long arg) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 964 | { |
Andrew Lunn | 34c93c8 | 2012-11-18 11:44:56 +0100 | [diff] [blame] | 965 | return -ENOSYS; |
| 966 | } |
| 967 | |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 968 | static int mv_xor_channel_remove(struct mv_xor_chan *mv_chan) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 969 | { |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 970 | struct dma_chan *chan, *_chan; |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 971 | struct device *dev = mv_chan->dmadev.dev; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 972 | |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 973 | dma_async_device_unregister(&mv_chan->dmadev); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 974 | |
Thomas Petazzoni | b503fa0 | 2012-11-15 15:55:30 +0100 | [diff] [blame] | 975 | dma_free_coherent(dev, MV_XOR_POOL_SIZE, |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 976 | mv_chan->dma_desc_pool_virt, mv_chan->dma_desc_pool); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 977 | |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 978 | list_for_each_entry_safe(chan, _chan, &mv_chan->dmadev.channels, |
Thomas Petazzoni | a6b4a9d | 2012-10-29 16:45:46 +0100 | [diff] [blame] | 979 | device_node) { |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 980 | list_del(&chan->device_node); |
| 981 | } |
| 982 | |
Thomas Petazzoni | 88eb92c | 2012-11-15 16:11:18 +0100 | [diff] [blame] | 983 | free_irq(mv_chan->irq, mv_chan); |
| 984 | |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 985 | return 0; |
| 986 | } |
| 987 | |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 988 | static struct mv_xor_chan * |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 989 | mv_xor_channel_add(struct mv_xor_device *xordev, |
Thomas Petazzoni | a6b4a9d | 2012-10-29 16:45:46 +0100 | [diff] [blame] | 990 | struct platform_device *pdev, |
Thomas Petazzoni | b503fa0 | 2012-11-15 15:55:30 +0100 | [diff] [blame] | 991 | int idx, dma_cap_mask_t cap_mask, int irq) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 992 | { |
| 993 | int ret = 0; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 994 | struct mv_xor_chan *mv_chan; |
| 995 | struct dma_device *dma_dev; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 996 | |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 997 | mv_chan = devm_kzalloc(&pdev->dev, sizeof(*mv_chan), GFP_KERNEL); |
Sachin Kamat | a577659 | 2013-09-02 13:54:20 +0530 | [diff] [blame] | 998 | if (!mv_chan) |
| 999 | return ERR_PTR(-ENOMEM); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1000 | |
Thomas Petazzoni | 9aedbdb | 2012-11-15 15:36:37 +0100 | [diff] [blame] | 1001 | mv_chan->idx = idx; |
Thomas Petazzoni | 88eb92c | 2012-11-15 16:11:18 +0100 | [diff] [blame] | 1002 | mv_chan->irq = irq; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1003 | |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 1004 | dma_dev = &mv_chan->dmadev; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1005 | |
| 1006 | /* allocate coherent memory for hardware descriptors |
| 1007 | * note: writecombine gives slightly better performance, but |
| 1008 | * requires that we explicitly flush the writes |
| 1009 | */ |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 1010 | mv_chan->dma_desc_pool_virt = |
Thomas Petazzoni | b503fa0 | 2012-11-15 15:55:30 +0100 | [diff] [blame] | 1011 | dma_alloc_writecombine(&pdev->dev, MV_XOR_POOL_SIZE, |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 1012 | &mv_chan->dma_desc_pool, GFP_KERNEL); |
| 1013 | if (!mv_chan->dma_desc_pool_virt) |
Thomas Petazzoni | a6b4a9d | 2012-10-29 16:45:46 +0100 | [diff] [blame] | 1014 | return ERR_PTR(-ENOMEM); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1015 | |
| 1016 | /* discover transaction capabilites from the platform data */ |
Thomas Petazzoni | a6b4a9d | 2012-10-29 16:45:46 +0100 | [diff] [blame] | 1017 | dma_dev->cap_mask = cap_mask; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1018 | |
| 1019 | INIT_LIST_HEAD(&dma_dev->channels); |
| 1020 | |
| 1021 | /* set base routines */ |
| 1022 | dma_dev->device_alloc_chan_resources = mv_xor_alloc_chan_resources; |
| 1023 | dma_dev->device_free_chan_resources = mv_xor_free_chan_resources; |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1024 | dma_dev->device_tx_status = mv_xor_status; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1025 | dma_dev->device_issue_pending = mv_xor_issue_pending; |
Andrew Lunn | 34c93c8 | 2012-11-18 11:44:56 +0100 | [diff] [blame] | 1026 | dma_dev->device_control = mv_xor_control; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1027 | dma_dev->dev = &pdev->dev; |
| 1028 | |
| 1029 | /* set prep routines based on capability */ |
| 1030 | if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) |
| 1031 | dma_dev->device_prep_dma_memcpy = mv_xor_prep_dma_memcpy; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1032 | if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) { |
Joe Perches | c019894 | 2009-06-28 09:26:21 -0700 | [diff] [blame] | 1033 | dma_dev->max_xor = 8; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1034 | dma_dev->device_prep_dma_xor = mv_xor_prep_dma_xor; |
| 1035 | } |
| 1036 | |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1037 | mv_chan->mmr_base = xordev->xor_base; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1038 | if (!mv_chan->mmr_base) { |
| 1039 | ret = -ENOMEM; |
| 1040 | goto err_free_dma; |
| 1041 | } |
| 1042 | tasklet_init(&mv_chan->irq_tasklet, mv_xor_tasklet, (unsigned long) |
| 1043 | mv_chan); |
| 1044 | |
| 1045 | /* clear errors before enabling interrupts */ |
| 1046 | mv_xor_device_clear_err_status(mv_chan); |
| 1047 | |
Thomas Petazzoni | 2d0a074 | 2012-11-22 18:19:09 +0100 | [diff] [blame] | 1048 | ret = request_irq(mv_chan->irq, mv_xor_interrupt_handler, |
| 1049 | 0, dev_name(&pdev->dev), mv_chan); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1050 | if (ret) |
| 1051 | goto err_free_dma; |
| 1052 | |
| 1053 | mv_chan_unmask_interrupts(mv_chan); |
| 1054 | |
| 1055 | mv_set_mode(mv_chan, DMA_MEMCPY); |
| 1056 | |
| 1057 | spin_lock_init(&mv_chan->lock); |
| 1058 | INIT_LIST_HEAD(&mv_chan->chain); |
| 1059 | INIT_LIST_HEAD(&mv_chan->completed_slots); |
| 1060 | INIT_LIST_HEAD(&mv_chan->all_slots); |
Thomas Petazzoni | 98817b9 | 2012-11-15 14:57:44 +0100 | [diff] [blame] | 1061 | mv_chan->dmachan.device = dma_dev; |
| 1062 | dma_cookie_init(&mv_chan->dmachan); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1063 | |
Thomas Petazzoni | 98817b9 | 2012-11-15 14:57:44 +0100 | [diff] [blame] | 1064 | list_add_tail(&mv_chan->dmachan.device_node, &dma_dev->channels); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1065 | |
| 1066 | if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) { |
Thomas Petazzoni | 275cc0c | 2012-11-15 15:09:42 +0100 | [diff] [blame] | 1067 | ret = mv_xor_memcpy_self_test(mv_chan); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1068 | dev_dbg(&pdev->dev, "memcpy self test returned %d\n", ret); |
| 1069 | if (ret) |
Thomas Petazzoni | 2d0a074 | 2012-11-22 18:19:09 +0100 | [diff] [blame] | 1070 | goto err_free_irq; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) { |
Thomas Petazzoni | 275cc0c | 2012-11-15 15:09:42 +0100 | [diff] [blame] | 1074 | ret = mv_xor_xor_self_test(mv_chan); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1075 | dev_dbg(&pdev->dev, "xor self test returned %d\n", ret); |
| 1076 | if (ret) |
Thomas Petazzoni | 2d0a074 | 2012-11-22 18:19:09 +0100 | [diff] [blame] | 1077 | goto err_free_irq; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
Bartlomiej Zolnierkiewicz | 48a9db4 | 2013-07-03 15:05:06 -0700 | [diff] [blame] | 1080 | dev_info(&pdev->dev, "Marvell XOR: ( %s%s%s)\n", |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 1081 | dma_has_cap(DMA_XOR, dma_dev->cap_mask) ? "xor " : "", |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 1082 | dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask) ? "cpy " : "", |
| 1083 | dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : ""); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1084 | |
| 1085 | dma_async_device_register(dma_dev); |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 1086 | return mv_chan; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1087 | |
Thomas Petazzoni | 2d0a074 | 2012-11-22 18:19:09 +0100 | [diff] [blame] | 1088 | err_free_irq: |
| 1089 | free_irq(mv_chan->irq, mv_chan); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1090 | err_free_dma: |
Thomas Petazzoni | b503fa0 | 2012-11-15 15:55:30 +0100 | [diff] [blame] | 1091 | dma_free_coherent(&pdev->dev, MV_XOR_POOL_SIZE, |
Thomas Petazzoni | 1ef48a2 | 2012-11-15 15:17:05 +0100 | [diff] [blame] | 1092 | mv_chan->dma_desc_pool_virt, mv_chan->dma_desc_pool); |
Thomas Petazzoni | a6b4a9d | 2012-10-29 16:45:46 +0100 | [diff] [blame] | 1093 | return ERR_PTR(ret); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | static void |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1097 | mv_xor_conf_mbus_windows(struct mv_xor_device *xordev, |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 1098 | const struct mbus_dram_target_info *dram) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1099 | { |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1100 | void __iomem *base = xordev->xor_base; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1101 | u32 win_enable = 0; |
| 1102 | int i; |
| 1103 | |
| 1104 | for (i = 0; i < 8; i++) { |
| 1105 | writel(0, base + WINDOW_BASE(i)); |
| 1106 | writel(0, base + WINDOW_SIZE(i)); |
| 1107 | if (i < 4) |
| 1108 | writel(0, base + WINDOW_REMAP_HIGH(i)); |
| 1109 | } |
| 1110 | |
| 1111 | for (i = 0; i < dram->num_cs; i++) { |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 1112 | const struct mbus_dram_window *cs = dram->cs + i; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1113 | |
| 1114 | writel((cs->base & 0xffff0000) | |
| 1115 | (cs->mbus_attr << 8) | |
| 1116 | dram->mbus_dram_target_id, base + WINDOW_BASE(i)); |
| 1117 | writel((cs->size - 1) & 0xffff0000, base + WINDOW_SIZE(i)); |
| 1118 | |
| 1119 | win_enable |= (1 << i); |
| 1120 | win_enable |= 3 << (16 + (2 * i)); |
| 1121 | } |
| 1122 | |
| 1123 | writel(win_enable, base + WINDOW_BAR_ENABLE(0)); |
| 1124 | writel(win_enable, base + WINDOW_BAR_ENABLE(1)); |
Thomas Petazzoni | c4b4b73 | 2012-11-22 18:16:37 +0100 | [diff] [blame] | 1125 | writel(0, base + WINDOW_OVERRIDE_CTRL(0)); |
| 1126 | writel(0, base + WINDOW_OVERRIDE_CTRL(1)); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Linus Torvalds | c271433 | 2012-12-14 14:54:26 -0800 | [diff] [blame] | 1129 | static int mv_xor_probe(struct platform_device *pdev) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1130 | { |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 1131 | const struct mbus_dram_target_info *dram; |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1132 | struct mv_xor_device *xordev; |
Jingoo Han | d4adcc0 | 2013-07-30 17:09:11 +0900 | [diff] [blame] | 1133 | struct mv_xor_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1134 | struct resource *res; |
Thomas Petazzoni | 60d151f | 2012-10-29 16:54:49 +0100 | [diff] [blame] | 1135 | int i, ret; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1136 | |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 1137 | dev_notice(&pdev->dev, "Marvell shared XOR driver\n"); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1138 | |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1139 | xordev = devm_kzalloc(&pdev->dev, sizeof(*xordev), GFP_KERNEL); |
| 1140 | if (!xordev) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1141 | return -ENOMEM; |
| 1142 | |
| 1143 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1144 | if (!res) |
| 1145 | return -ENODEV; |
| 1146 | |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1147 | xordev->xor_base = devm_ioremap(&pdev->dev, res->start, |
| 1148 | resource_size(res)); |
| 1149 | if (!xordev->xor_base) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1150 | return -EBUSY; |
| 1151 | |
| 1152 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 1153 | if (!res) |
| 1154 | return -ENODEV; |
| 1155 | |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1156 | xordev->xor_high_base = devm_ioremap(&pdev->dev, res->start, |
| 1157 | resource_size(res)); |
| 1158 | if (!xordev->xor_high_base) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1159 | return -EBUSY; |
| 1160 | |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1161 | platform_set_drvdata(pdev, xordev); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1162 | |
| 1163 | /* |
| 1164 | * (Re-)program MBUS remapping windows if we are asked to. |
| 1165 | */ |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 1166 | dram = mv_mbus_dram_info(); |
| 1167 | if (dram) |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1168 | mv_xor_conf_mbus_windows(xordev, dram); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1169 | |
Andrew Lunn | c510182 | 2012-02-19 13:30:26 +0100 | [diff] [blame] | 1170 | /* Not all platforms can gate the clock, so it is not |
| 1171 | * an error if the clock does not exists. |
| 1172 | */ |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1173 | xordev->clk = clk_get(&pdev->dev, NULL); |
| 1174 | if (!IS_ERR(xordev->clk)) |
| 1175 | clk_prepare_enable(xordev->clk); |
Andrew Lunn | c510182 | 2012-02-19 13:30:26 +0100 | [diff] [blame] | 1176 | |
Thomas Petazzoni | f7d12ef | 2012-11-15 16:47:58 +0100 | [diff] [blame] | 1177 | if (pdev->dev.of_node) { |
| 1178 | struct device_node *np; |
| 1179 | int i = 0; |
| 1180 | |
| 1181 | for_each_child_of_node(pdev->dev.of_node, np) { |
| 1182 | dma_cap_mask_t cap_mask; |
| 1183 | int irq; |
| 1184 | |
| 1185 | dma_cap_zero(cap_mask); |
| 1186 | if (of_property_read_bool(np, "dmacap,memcpy")) |
| 1187 | dma_cap_set(DMA_MEMCPY, cap_mask); |
| 1188 | if (of_property_read_bool(np, "dmacap,xor")) |
| 1189 | dma_cap_set(DMA_XOR, cap_mask); |
Thomas Petazzoni | f7d12ef | 2012-11-15 16:47:58 +0100 | [diff] [blame] | 1190 | if (of_property_read_bool(np, "dmacap,interrupt")) |
| 1191 | dma_cap_set(DMA_INTERRUPT, cap_mask); |
| 1192 | |
| 1193 | irq = irq_of_parse_and_map(np, 0); |
Thomas Petazzoni | f8eb9e7 | 2012-11-22 18:22:12 +0100 | [diff] [blame] | 1194 | if (!irq) { |
| 1195 | ret = -ENODEV; |
Thomas Petazzoni | f7d12ef | 2012-11-15 16:47:58 +0100 | [diff] [blame] | 1196 | goto err_channel_add; |
| 1197 | } |
| 1198 | |
| 1199 | xordev->channels[i] = |
| 1200 | mv_xor_channel_add(xordev, pdev, i, |
| 1201 | cap_mask, irq); |
| 1202 | if (IS_ERR(xordev->channels[i])) { |
| 1203 | ret = PTR_ERR(xordev->channels[i]); |
Thomas Petazzoni | 73d9cdc | 2012-11-22 18:22:59 +0100 | [diff] [blame] | 1204 | xordev->channels[i] = NULL; |
Thomas Petazzoni | f7d12ef | 2012-11-15 16:47:58 +0100 | [diff] [blame] | 1205 | irq_dispose_mapping(irq); |
| 1206 | goto err_channel_add; |
| 1207 | } |
| 1208 | |
| 1209 | i++; |
| 1210 | } |
| 1211 | } else if (pdata && pdata->channels) { |
Thomas Petazzoni | 60d151f | 2012-10-29 16:54:49 +0100 | [diff] [blame] | 1212 | for (i = 0; i < MV_XOR_MAX_CHANNELS; i++) { |
Thomas Petazzoni | e39f6ec | 2012-10-30 11:56:26 +0100 | [diff] [blame] | 1213 | struct mv_xor_channel_data *cd; |
Thomas Petazzoni | 60d151f | 2012-10-29 16:54:49 +0100 | [diff] [blame] | 1214 | int irq; |
| 1215 | |
| 1216 | cd = &pdata->channels[i]; |
| 1217 | if (!cd) { |
| 1218 | ret = -ENODEV; |
| 1219 | goto err_channel_add; |
| 1220 | } |
| 1221 | |
| 1222 | irq = platform_get_irq(pdev, i); |
| 1223 | if (irq < 0) { |
| 1224 | ret = irq; |
| 1225 | goto err_channel_add; |
| 1226 | } |
| 1227 | |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1228 | xordev->channels[i] = |
Thomas Petazzoni | 9aedbdb | 2012-11-15 15:36:37 +0100 | [diff] [blame] | 1229 | mv_xor_channel_add(xordev, pdev, i, |
Thomas Petazzoni | b503fa0 | 2012-11-15 15:55:30 +0100 | [diff] [blame] | 1230 | cd->cap_mask, irq); |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1231 | if (IS_ERR(xordev->channels[i])) { |
| 1232 | ret = PTR_ERR(xordev->channels[i]); |
Thomas Petazzoni | 60d151f | 2012-10-29 16:54:49 +0100 | [diff] [blame] | 1233 | goto err_channel_add; |
| 1234 | } |
| 1235 | } |
| 1236 | } |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1237 | |
| 1238 | return 0; |
Thomas Petazzoni | 60d151f | 2012-10-29 16:54:49 +0100 | [diff] [blame] | 1239 | |
| 1240 | err_channel_add: |
| 1241 | for (i = 0; i < MV_XOR_MAX_CHANNELS; i++) |
Thomas Petazzoni | f7d12ef | 2012-11-15 16:47:58 +0100 | [diff] [blame] | 1242 | if (xordev->channels[i]) { |
Thomas Petazzoni | ab6e439 | 2013-01-06 11:10:43 +0100 | [diff] [blame] | 1243 | mv_xor_channel_remove(xordev->channels[i]); |
Thomas Petazzoni | f7d12ef | 2012-11-15 16:47:58 +0100 | [diff] [blame] | 1244 | if (pdev->dev.of_node) |
| 1245 | irq_dispose_mapping(xordev->channels[i]->irq); |
Thomas Petazzoni | f7d12ef | 2012-11-15 16:47:58 +0100 | [diff] [blame] | 1246 | } |
Thomas Petazzoni | 60d151f | 2012-10-29 16:54:49 +0100 | [diff] [blame] | 1247 | |
Thomas Petazzoni | dab9206 | 2013-01-06 11:10:44 +0100 | [diff] [blame] | 1248 | if (!IS_ERR(xordev->clk)) { |
| 1249 | clk_disable_unprepare(xordev->clk); |
| 1250 | clk_put(xordev->clk); |
| 1251 | } |
| 1252 | |
Thomas Petazzoni | 60d151f | 2012-10-29 16:54:49 +0100 | [diff] [blame] | 1253 | return ret; |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
Linus Torvalds | c271433 | 2012-12-14 14:54:26 -0800 | [diff] [blame] | 1256 | static int mv_xor_remove(struct platform_device *pdev) |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1257 | { |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1258 | struct mv_xor_device *xordev = platform_get_drvdata(pdev); |
Thomas Petazzoni | 60d151f | 2012-10-29 16:54:49 +0100 | [diff] [blame] | 1259 | int i; |
Andrew Lunn | c510182 | 2012-02-19 13:30:26 +0100 | [diff] [blame] | 1260 | |
Thomas Petazzoni | 60d151f | 2012-10-29 16:54:49 +0100 | [diff] [blame] | 1261 | for (i = 0; i < MV_XOR_MAX_CHANNELS; i++) { |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1262 | if (xordev->channels[i]) |
| 1263 | mv_xor_channel_remove(xordev->channels[i]); |
Thomas Petazzoni | 60d151f | 2012-10-29 16:54:49 +0100 | [diff] [blame] | 1264 | } |
Andrew Lunn | c510182 | 2012-02-19 13:30:26 +0100 | [diff] [blame] | 1265 | |
Thomas Petazzoni | 297eedb | 2012-11-15 15:29:53 +0100 | [diff] [blame] | 1266 | if (!IS_ERR(xordev->clk)) { |
| 1267 | clk_disable_unprepare(xordev->clk); |
| 1268 | clk_put(xordev->clk); |
Andrew Lunn | c510182 | 2012-02-19 13:30:26 +0100 | [diff] [blame] | 1269 | } |
| 1270 | |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1271 | return 0; |
| 1272 | } |
| 1273 | |
Thomas Petazzoni | f7d12ef | 2012-11-15 16:47:58 +0100 | [diff] [blame] | 1274 | #ifdef CONFIG_OF |
Linus Torvalds | c271433 | 2012-12-14 14:54:26 -0800 | [diff] [blame] | 1275 | static struct of_device_id mv_xor_dt_ids[] = { |
Thomas Petazzoni | f7d12ef | 2012-11-15 16:47:58 +0100 | [diff] [blame] | 1276 | { .compatible = "marvell,orion-xor", }, |
| 1277 | {}, |
| 1278 | }; |
| 1279 | MODULE_DEVICE_TABLE(of, mv_xor_dt_ids); |
| 1280 | #endif |
| 1281 | |
Thomas Petazzoni | 6197165 | 2012-10-30 12:05:40 +0100 | [diff] [blame] | 1282 | static struct platform_driver mv_xor_driver = { |
| 1283 | .probe = mv_xor_probe, |
Linus Torvalds | c271433 | 2012-12-14 14:54:26 -0800 | [diff] [blame] | 1284 | .remove = mv_xor_remove, |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1285 | .driver = { |
Thomas Petazzoni | f7d12ef | 2012-11-15 16:47:58 +0100 | [diff] [blame] | 1286 | .owner = THIS_MODULE, |
| 1287 | .name = MV_XOR_NAME, |
| 1288 | .of_match_table = of_match_ptr(mv_xor_dt_ids), |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1289 | }, |
| 1290 | }; |
| 1291 | |
| 1292 | |
| 1293 | static int __init mv_xor_init(void) |
| 1294 | { |
Thomas Petazzoni | 6197165 | 2012-10-30 12:05:40 +0100 | [diff] [blame] | 1295 | return platform_driver_register(&mv_xor_driver); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1296 | } |
| 1297 | module_init(mv_xor_init); |
| 1298 | |
| 1299 | /* it's currently unsafe to unload this module */ |
| 1300 | #if 0 |
| 1301 | static void __exit mv_xor_exit(void) |
| 1302 | { |
| 1303 | platform_driver_unregister(&mv_xor_driver); |
Saeed Bishara | ff7b047 | 2008-07-08 11:58:36 -0700 | [diff] [blame] | 1304 | return; |
| 1305 | } |
| 1306 | |
| 1307 | module_exit(mv_xor_exit); |
| 1308 | #endif |
| 1309 | |
| 1310 | MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>"); |
| 1311 | MODULE_DESCRIPTION("DMA engine driver for Marvell's XOR engine"); |
| 1312 | MODULE_LICENSE("GPL"); |