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