Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * offload engine driver for the Intel Xscale series of i/o processors |
| 3 | * Copyright © 2006, Intel Corporation. |
| 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 | * |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * This driver supports the asynchrounous DMA copy and RAID engines available |
| 18 | * on the Intel Xscale(R) family of I/O Processors (IOP 32x, 33x, 134x) |
| 19 | */ |
| 20 | |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/module.h> |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 23 | #include <linux/delay.h> |
| 24 | #include <linux/dma-mapping.h> |
| 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/memory.h> |
| 29 | #include <linux/ioport.h> |
Dan Williams | f6dbf65 | 2009-08-29 19:12:40 -0700 | [diff] [blame] | 30 | #include <linux/raid/pq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 32 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 33 | #include <mach/adma.h> |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 34 | |
Russell King - ARM Linux | d2ebfb3 | 2012-03-06 22:34:26 +0000 | [diff] [blame] | 35 | #include "dmaengine.h" |
| 36 | |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 37 | #define to_iop_adma_chan(chan) container_of(chan, struct iop_adma_chan, common) |
| 38 | #define to_iop_adma_device(dev) \ |
| 39 | container_of(dev, struct iop_adma_device, common) |
| 40 | #define tx_to_iop_adma_slot(tx) \ |
| 41 | container_of(tx, struct iop_adma_desc_slot, async_tx) |
| 42 | |
| 43 | /** |
| 44 | * iop_adma_free_slots - flags descriptor slots for reuse |
| 45 | * @slot: Slot to free |
| 46 | * Caller must hold &iop_chan->lock while calling this function |
| 47 | */ |
| 48 | static void iop_adma_free_slots(struct iop_adma_desc_slot *slot) |
| 49 | { |
| 50 | int stride = slot->slots_per_op; |
| 51 | |
| 52 | while (stride--) { |
| 53 | slot->slots_per_op = 0; |
| 54 | slot = list_entry(slot->slot_node.next, |
| 55 | struct iop_adma_desc_slot, |
| 56 | slot_node); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | static dma_cookie_t |
| 61 | iop_adma_run_tx_complete_actions(struct iop_adma_desc_slot *desc, |
| 62 | struct iop_adma_chan *iop_chan, dma_cookie_t cookie) |
| 63 | { |
Dan Williams | 507fbec | 2009-08-29 19:12:39 -0700 | [diff] [blame] | 64 | struct dma_async_tx_descriptor *tx = &desc->async_tx; |
| 65 | |
| 66 | BUG_ON(tx->cookie < 0); |
| 67 | if (tx->cookie > 0) { |
| 68 | cookie = tx->cookie; |
| 69 | tx->cookie = 0; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 70 | |
| 71 | /* call the callback (must not sleep or submit new |
| 72 | * operations to this channel) |
| 73 | */ |
Dan Williams | 507fbec | 2009-08-29 19:12:39 -0700 | [diff] [blame] | 74 | if (tx->callback) |
| 75 | tx->callback(tx->callback_param); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 76 | |
Dan Williams | d38a8c6 | 2013-10-18 19:35:23 +0200 | [diff] [blame] | 77 | dma_descriptor_unmap(tx); |
Bartlomiej Zolnierkiewicz | 54f8d50 | 2013-10-18 19:35:32 +0200 | [diff] [blame] | 78 | if (desc->group_head) |
| 79 | desc->group_head = NULL; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* run dependent operations */ |
Dan Williams | 507fbec | 2009-08-29 19:12:39 -0700 | [diff] [blame] | 83 | dma_run_dependencies(tx); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 84 | |
| 85 | return cookie; |
| 86 | } |
| 87 | |
| 88 | static int |
| 89 | iop_adma_clean_slot(struct iop_adma_desc_slot *desc, |
| 90 | struct iop_adma_chan *iop_chan) |
| 91 | { |
| 92 | /* the client is allowed to attach dependent operations |
| 93 | * until 'ack' is set |
| 94 | */ |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 95 | if (!async_tx_test_ack(&desc->async_tx)) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 96 | return 0; |
| 97 | |
| 98 | /* leave the last descriptor in the chain |
| 99 | * so we can append to it |
| 100 | */ |
| 101 | if (desc->chain_node.next == &iop_chan->chain) |
| 102 | return 1; |
| 103 | |
| 104 | dev_dbg(iop_chan->device->common.dev, |
| 105 | "\tfree slot: %d slots_per_op: %d\n", |
| 106 | desc->idx, desc->slots_per_op); |
| 107 | |
| 108 | list_del(&desc->chain_node); |
| 109 | iop_adma_free_slots(desc); |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static void __iop_adma_slot_cleanup(struct iop_adma_chan *iop_chan) |
| 115 | { |
| 116 | struct iop_adma_desc_slot *iter, *_iter, *grp_start = NULL; |
| 117 | dma_cookie_t cookie = 0; |
| 118 | u32 current_desc = iop_chan_get_current_descriptor(iop_chan); |
| 119 | int busy = iop_chan_is_busy(iop_chan); |
| 120 | int seen_current = 0, slot_cnt = 0, slots_per_op = 0; |
| 121 | |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 122 | dev_dbg(iop_chan->device->common.dev, "%s\n", __func__); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 123 | /* free completed slots from the chain starting with |
| 124 | * the oldest descriptor |
| 125 | */ |
| 126 | list_for_each_entry_safe(iter, _iter, &iop_chan->chain, |
| 127 | chain_node) { |
| 128 | pr_debug("\tcookie: %d slot: %d busy: %d " |
| 129 | "this_desc: %#x next_desc: %#x ack: %d\n", |
| 130 | iter->async_tx.cookie, iter->idx, busy, |
| 131 | iter->async_tx.phys, iop_desc_get_next_desc(iter), |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 132 | async_tx_test_ack(&iter->async_tx)); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 133 | prefetch(_iter); |
| 134 | prefetch(&_iter->async_tx); |
| 135 | |
| 136 | /* do not advance past the current descriptor loaded into the |
| 137 | * hardware channel, subsequent descriptors are either in |
| 138 | * process or have not been submitted |
| 139 | */ |
| 140 | if (seen_current) |
| 141 | break; |
| 142 | |
| 143 | /* stop the search if we reach the current descriptor and the |
| 144 | * channel is busy, or if it appears that the current descriptor |
| 145 | * needs to be re-read (i.e. has been appended to) |
| 146 | */ |
| 147 | if (iter->async_tx.phys == current_desc) { |
| 148 | BUG_ON(seen_current++); |
| 149 | if (busy || iop_desc_get_next_desc(iter)) |
| 150 | break; |
| 151 | } |
| 152 | |
| 153 | /* detect the start of a group transaction */ |
| 154 | if (!slot_cnt && !slots_per_op) { |
| 155 | slot_cnt = iter->slot_cnt; |
| 156 | slots_per_op = iter->slots_per_op; |
| 157 | if (slot_cnt <= slots_per_op) { |
| 158 | slot_cnt = 0; |
| 159 | slots_per_op = 0; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if (slot_cnt) { |
| 164 | pr_debug("\tgroup++\n"); |
| 165 | if (!grp_start) |
| 166 | grp_start = iter; |
| 167 | slot_cnt -= slots_per_op; |
| 168 | } |
| 169 | |
| 170 | /* all the members of a group are complete */ |
| 171 | if (slots_per_op != 0 && slot_cnt == 0) { |
| 172 | struct iop_adma_desc_slot *grp_iter, *_grp_iter; |
| 173 | int end_of_chain = 0; |
| 174 | pr_debug("\tgroup end\n"); |
| 175 | |
| 176 | /* collect the total results */ |
| 177 | if (grp_start->xor_check_result) { |
| 178 | u32 zero_sum_result = 0; |
| 179 | slot_cnt = grp_start->slot_cnt; |
| 180 | grp_iter = grp_start; |
| 181 | |
| 182 | list_for_each_entry_from(grp_iter, |
| 183 | &iop_chan->chain, chain_node) { |
| 184 | zero_sum_result |= |
| 185 | iop_desc_get_zero_result(grp_iter); |
| 186 | pr_debug("\titer%d result: %d\n", |
| 187 | grp_iter->idx, zero_sum_result); |
| 188 | slot_cnt -= slots_per_op; |
| 189 | if (slot_cnt == 0) |
| 190 | break; |
| 191 | } |
| 192 | pr_debug("\tgrp_start->xor_check_result: %p\n", |
| 193 | grp_start->xor_check_result); |
| 194 | *grp_start->xor_check_result = zero_sum_result; |
| 195 | } |
| 196 | |
| 197 | /* clean up the group */ |
| 198 | slot_cnt = grp_start->slot_cnt; |
| 199 | grp_iter = grp_start; |
| 200 | list_for_each_entry_safe_from(grp_iter, _grp_iter, |
| 201 | &iop_chan->chain, chain_node) { |
| 202 | cookie = iop_adma_run_tx_complete_actions( |
| 203 | grp_iter, iop_chan, cookie); |
| 204 | |
| 205 | slot_cnt -= slots_per_op; |
| 206 | end_of_chain = iop_adma_clean_slot(grp_iter, |
| 207 | iop_chan); |
| 208 | |
| 209 | if (slot_cnt == 0 || end_of_chain) |
| 210 | break; |
| 211 | } |
| 212 | |
| 213 | /* the group should be complete at this point */ |
| 214 | BUG_ON(slot_cnt); |
| 215 | |
| 216 | slots_per_op = 0; |
| 217 | grp_start = NULL; |
| 218 | if (end_of_chain) |
| 219 | break; |
| 220 | else |
| 221 | continue; |
| 222 | } else if (slots_per_op) /* wait for group completion */ |
| 223 | continue; |
| 224 | |
| 225 | /* write back zero sum results (single descriptor case) */ |
| 226 | if (iter->xor_check_result && iter->async_tx.cookie) |
| 227 | *iter->xor_check_result = |
| 228 | iop_desc_get_zero_result(iter); |
| 229 | |
| 230 | cookie = iop_adma_run_tx_complete_actions( |
| 231 | iter, iop_chan, cookie); |
| 232 | |
| 233 | if (iop_adma_clean_slot(iter, iop_chan)) |
| 234 | break; |
| 235 | } |
| 236 | |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 237 | if (cookie > 0) { |
Russell King - ARM Linux | 4d4e58d | 2012-03-06 22:34:06 +0000 | [diff] [blame] | 238 | iop_chan->common.completed_cookie = cookie; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 239 | pr_debug("\tcompleted cookie %d\n", cookie); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | static void |
| 244 | iop_adma_slot_cleanup(struct iop_adma_chan *iop_chan) |
| 245 | { |
| 246 | spin_lock_bh(&iop_chan->lock); |
| 247 | __iop_adma_slot_cleanup(iop_chan); |
| 248 | spin_unlock_bh(&iop_chan->lock); |
| 249 | } |
| 250 | |
| 251 | static void iop_adma_tasklet(unsigned long data) |
| 252 | { |
Dan Williams | 19242d7 | 2008-04-17 20:17:25 -0700 | [diff] [blame] | 253 | struct iop_adma_chan *iop_chan = (struct iop_adma_chan *) data; |
| 254 | |
Dan Williams | 72be12f | 2009-07-14 13:38:29 -0700 | [diff] [blame] | 255 | /* lockdep will flag depedency submissions as potentially |
| 256 | * recursive locking, this is not the case as a dependency |
| 257 | * submission will never recurse a channels submit routine. |
| 258 | * There are checks in async_tx.c to prevent this. |
| 259 | */ |
| 260 | spin_lock_nested(&iop_chan->lock, SINGLE_DEPTH_NESTING); |
Dan Williams | 19242d7 | 2008-04-17 20:17:25 -0700 | [diff] [blame] | 261 | __iop_adma_slot_cleanup(iop_chan); |
| 262 | spin_unlock(&iop_chan->lock); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static struct iop_adma_desc_slot * |
| 266 | iop_adma_alloc_slots(struct iop_adma_chan *iop_chan, int num_slots, |
| 267 | int slots_per_op) |
| 268 | { |
| 269 | struct iop_adma_desc_slot *iter, *_iter, *alloc_start = NULL; |
Denis Cheng | e73ef9a | 2008-02-02 19:30:01 -0700 | [diff] [blame] | 270 | LIST_HEAD(chain); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 271 | int slots_found, retry = 0; |
| 272 | |
| 273 | /* start search from the last allocated descrtiptor |
| 274 | * if a contiguous allocation can not be found start searching |
| 275 | * from the beginning of the list |
| 276 | */ |
| 277 | retry: |
| 278 | slots_found = 0; |
| 279 | if (retry == 0) |
| 280 | iter = iop_chan->last_used; |
| 281 | else |
| 282 | iter = list_entry(&iop_chan->all_slots, |
| 283 | struct iop_adma_desc_slot, |
| 284 | slot_node); |
| 285 | |
| 286 | list_for_each_entry_safe_continue( |
| 287 | iter, _iter, &iop_chan->all_slots, slot_node) { |
| 288 | prefetch(_iter); |
| 289 | prefetch(&_iter->async_tx); |
| 290 | if (iter->slots_per_op) { |
| 291 | /* give up after finding the first busy slot |
| 292 | * on the second pass through the list |
| 293 | */ |
| 294 | if (retry) |
| 295 | break; |
| 296 | |
| 297 | slots_found = 0; |
| 298 | continue; |
| 299 | } |
| 300 | |
| 301 | /* start the allocation if the slot is correctly aligned */ |
| 302 | if (!slots_found++) { |
| 303 | if (iop_desc_is_aligned(iter, slots_per_op)) |
| 304 | alloc_start = iter; |
| 305 | else { |
| 306 | slots_found = 0; |
| 307 | continue; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | if (slots_found == num_slots) { |
| 312 | struct iop_adma_desc_slot *alloc_tail = NULL; |
| 313 | struct iop_adma_desc_slot *last_used = NULL; |
| 314 | iter = alloc_start; |
| 315 | while (num_slots) { |
| 316 | int i; |
| 317 | dev_dbg(iop_chan->device->common.dev, |
| 318 | "allocated slot: %d " |
| 319 | "(desc %p phys: %#x) slots_per_op %d\n", |
| 320 | iter->idx, iter->hw_desc, |
| 321 | iter->async_tx.phys, slots_per_op); |
| 322 | |
| 323 | /* pre-ack all but the last descriptor */ |
| 324 | if (num_slots != slots_per_op) |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 325 | async_tx_ack(&iter->async_tx); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 326 | |
| 327 | list_add_tail(&iter->chain_node, &chain); |
| 328 | alloc_tail = iter; |
| 329 | iter->async_tx.cookie = 0; |
| 330 | iter->slot_cnt = num_slots; |
| 331 | iter->xor_check_result = NULL; |
| 332 | for (i = 0; i < slots_per_op; i++) { |
| 333 | iter->slots_per_op = slots_per_op - i; |
| 334 | last_used = iter; |
| 335 | iter = list_entry(iter->slot_node.next, |
| 336 | struct iop_adma_desc_slot, |
| 337 | slot_node); |
| 338 | } |
| 339 | num_slots -= slots_per_op; |
| 340 | } |
| 341 | alloc_tail->group_head = alloc_start; |
| 342 | alloc_tail->async_tx.cookie = -EBUSY; |
Dan Williams | 308136d | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 343 | list_splice(&chain, &alloc_tail->tx_list); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 344 | iop_chan->last_used = last_used; |
| 345 | iop_desc_clear_next_desc(alloc_start); |
| 346 | iop_desc_clear_next_desc(alloc_tail); |
| 347 | return alloc_tail; |
| 348 | } |
| 349 | } |
| 350 | if (!retry++) |
| 351 | goto retry; |
| 352 | |
Dan Williams | c7141d0 | 2008-07-17 17:59:56 -0700 | [diff] [blame] | 353 | /* perform direct reclaim if the allocation fails */ |
| 354 | __iop_adma_slot_cleanup(iop_chan); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 355 | |
| 356 | return NULL; |
| 357 | } |
| 358 | |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 359 | static void iop_adma_check_threshold(struct iop_adma_chan *iop_chan) |
| 360 | { |
| 361 | dev_dbg(iop_chan->device->common.dev, "pending: %d\n", |
| 362 | iop_chan->pending); |
| 363 | |
| 364 | if (iop_chan->pending >= IOP_ADMA_THRESHOLD) { |
| 365 | iop_chan->pending = 0; |
| 366 | iop_chan_append(iop_chan); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | static dma_cookie_t |
| 371 | iop_adma_tx_submit(struct dma_async_tx_descriptor *tx) |
| 372 | { |
| 373 | struct iop_adma_desc_slot *sw_desc = tx_to_iop_adma_slot(tx); |
| 374 | struct iop_adma_chan *iop_chan = to_iop_adma_chan(tx->chan); |
| 375 | struct iop_adma_desc_slot *grp_start, *old_chain_tail; |
| 376 | int slot_cnt; |
| 377 | int slots_per_op; |
| 378 | dma_cookie_t cookie; |
Dan Williams | 137cb55 | 2008-11-11 13:12:33 -0700 | [diff] [blame] | 379 | dma_addr_t next_dma; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 380 | |
| 381 | grp_start = sw_desc->group_head; |
| 382 | slot_cnt = grp_start->slot_cnt; |
| 383 | slots_per_op = grp_start->slots_per_op; |
| 384 | |
| 385 | spin_lock_bh(&iop_chan->lock); |
Russell King - ARM Linux | 884485e | 2012-03-06 22:34:46 +0000 | [diff] [blame] | 386 | cookie = dma_cookie_assign(tx); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 387 | |
| 388 | old_chain_tail = list_entry(iop_chan->chain.prev, |
| 389 | struct iop_adma_desc_slot, chain_node); |
Dan Williams | 308136d | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 390 | list_splice_init(&sw_desc->tx_list, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 391 | &old_chain_tail->chain_node); |
| 392 | |
| 393 | /* fix up the hardware chain */ |
Dan Williams | 137cb55 | 2008-11-11 13:12:33 -0700 | [diff] [blame] | 394 | next_dma = grp_start->async_tx.phys; |
| 395 | iop_desc_set_next_desc(old_chain_tail, next_dma); |
| 396 | BUG_ON(iop_desc_get_next_desc(old_chain_tail) != next_dma); /* flush */ |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 397 | |
Dan Williams | 137cb55 | 2008-11-11 13:12:33 -0700 | [diff] [blame] | 398 | /* check for pre-chained descriptors */ |
Dan Williams | 65e5038 | 2008-11-11 13:12:33 -0700 | [diff] [blame] | 399 | iop_paranoia(iop_desc_get_next_desc(sw_desc)); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 400 | |
| 401 | /* increment the pending count by the number of slots |
| 402 | * memcpy operations have a 1:1 (slot:operation) relation |
| 403 | * other operations are heavier and will pop the threshold |
| 404 | * more often. |
| 405 | */ |
| 406 | iop_chan->pending += slot_cnt; |
| 407 | iop_adma_check_threshold(iop_chan); |
| 408 | spin_unlock_bh(&iop_chan->lock); |
| 409 | |
| 410 | dev_dbg(iop_chan->device->common.dev, "%s cookie: %d slot: %d\n", |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 411 | __func__, sw_desc->async_tx.cookie, sw_desc->idx); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 412 | |
| 413 | return cookie; |
| 414 | } |
| 415 | |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 416 | static void iop_chan_start_null_memcpy(struct iop_adma_chan *iop_chan); |
| 417 | static void iop_chan_start_null_xor(struct iop_adma_chan *iop_chan); |
| 418 | |
Dan Williams | 5eb907a | 2008-07-17 17:59:56 -0700 | [diff] [blame] | 419 | /** |
| 420 | * iop_adma_alloc_chan_resources - returns the number of allocated descriptors |
| 421 | * @chan - allocate descriptor resources for this channel |
| 422 | * @client - current client requesting the channel be ready for requests |
| 423 | * |
| 424 | * Note: We keep the slots for 1 operation on iop_chan->chain at all times. To |
| 425 | * avoid deadlock, via async_xor, num_descs_in_pool must at a minimum be |
| 426 | * greater than 2x the number slots needed to satisfy a device->max_xor |
| 427 | * request. |
| 428 | * */ |
Dan Williams | aa1e6f1 | 2009-01-06 11:38:17 -0700 | [diff] [blame] | 429 | static int iop_adma_alloc_chan_resources(struct dma_chan *chan) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 430 | { |
| 431 | char *hw_desc; |
| 432 | int idx; |
| 433 | struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan); |
| 434 | struct iop_adma_desc_slot *slot = NULL; |
| 435 | int init = iop_chan->slots_allocated ? 0 : 1; |
| 436 | struct iop_adma_platform_data *plat_data = |
Jingoo Han | d4adcc0 | 2013-07-30 17:09:11 +0900 | [diff] [blame] | 437 | dev_get_platdata(&iop_chan->device->pdev->dev); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 438 | int num_descs_in_pool = plat_data->pool_size/IOP_ADMA_SLOT_SIZE; |
| 439 | |
| 440 | /* Allocate descriptor slots */ |
| 441 | do { |
| 442 | idx = iop_chan->slots_allocated; |
| 443 | if (idx == num_descs_in_pool) |
| 444 | break; |
| 445 | |
| 446 | slot = kzalloc(sizeof(*slot), GFP_KERNEL); |
| 447 | if (!slot) { |
| 448 | printk(KERN_INFO "IOP ADMA Channel only initialized" |
| 449 | " %d descriptor slots", idx); |
| 450 | break; |
| 451 | } |
| 452 | hw_desc = (char *) iop_chan->device->dma_desc_pool_virt; |
| 453 | slot->hw_desc = (void *) &hw_desc[idx * IOP_ADMA_SLOT_SIZE]; |
| 454 | |
| 455 | dma_async_tx_descriptor_init(&slot->async_tx, chan); |
| 456 | slot->async_tx.tx_submit = iop_adma_tx_submit; |
Dan Williams | 308136d | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 457 | INIT_LIST_HEAD(&slot->tx_list); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 458 | INIT_LIST_HEAD(&slot->chain_node); |
| 459 | INIT_LIST_HEAD(&slot->slot_node); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 460 | hw_desc = (char *) iop_chan->device->dma_desc_pool; |
| 461 | slot->async_tx.phys = |
| 462 | (dma_addr_t) &hw_desc[idx * IOP_ADMA_SLOT_SIZE]; |
| 463 | slot->idx = idx; |
| 464 | |
| 465 | spin_lock_bh(&iop_chan->lock); |
| 466 | iop_chan->slots_allocated++; |
| 467 | list_add_tail(&slot->slot_node, &iop_chan->all_slots); |
| 468 | spin_unlock_bh(&iop_chan->lock); |
| 469 | } while (iop_chan->slots_allocated < num_descs_in_pool); |
| 470 | |
| 471 | if (idx && !iop_chan->last_used) |
| 472 | iop_chan->last_used = list_entry(iop_chan->all_slots.next, |
| 473 | struct iop_adma_desc_slot, |
| 474 | slot_node); |
| 475 | |
| 476 | dev_dbg(iop_chan->device->common.dev, |
| 477 | "allocated %d descriptor slots last_used: %p\n", |
| 478 | iop_chan->slots_allocated, iop_chan->last_used); |
| 479 | |
| 480 | /* initialize the channel and the chain with a null operation */ |
| 481 | if (init) { |
| 482 | if (dma_has_cap(DMA_MEMCPY, |
| 483 | iop_chan->device->common.cap_mask)) |
| 484 | iop_chan_start_null_memcpy(iop_chan); |
| 485 | else if (dma_has_cap(DMA_XOR, |
| 486 | iop_chan->device->common.cap_mask)) |
| 487 | iop_chan_start_null_xor(iop_chan); |
| 488 | else |
| 489 | BUG(); |
| 490 | } |
| 491 | |
| 492 | return (idx > 0) ? idx : -ENOMEM; |
| 493 | } |
| 494 | |
| 495 | static struct dma_async_tx_descriptor * |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 496 | iop_adma_prep_dma_interrupt(struct dma_chan *chan, unsigned long flags) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 497 | { |
| 498 | struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan); |
| 499 | struct iop_adma_desc_slot *sw_desc, *grp_start; |
| 500 | int slot_cnt, slots_per_op; |
| 501 | |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 502 | dev_dbg(iop_chan->device->common.dev, "%s\n", __func__); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 503 | |
| 504 | spin_lock_bh(&iop_chan->lock); |
| 505 | slot_cnt = iop_chan_interrupt_slot_count(&slots_per_op, iop_chan); |
| 506 | sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op); |
| 507 | if (sw_desc) { |
| 508 | grp_start = sw_desc->group_head; |
| 509 | iop_desc_init_interrupt(grp_start, iop_chan); |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 510 | sw_desc->async_tx.flags = flags; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 511 | } |
| 512 | spin_unlock_bh(&iop_chan->lock); |
| 513 | |
| 514 | return sw_desc ? &sw_desc->async_tx : NULL; |
| 515 | } |
| 516 | |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 517 | static struct dma_async_tx_descriptor * |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 518 | iop_adma_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dma_dest, |
Dan Williams | d4c56f9 | 2008-02-02 19:49:58 -0700 | [diff] [blame] | 519 | dma_addr_t dma_src, size_t len, unsigned long flags) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 520 | { |
| 521 | struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan); |
| 522 | struct iop_adma_desc_slot *sw_desc, *grp_start; |
| 523 | int slot_cnt, slots_per_op; |
| 524 | |
| 525 | if (unlikely(!len)) |
| 526 | return NULL; |
Coly Li | e2ec771 | 2011-03-27 01:26:52 +0800 | [diff] [blame] | 527 | BUG_ON(len > IOP_ADMA_MAX_BYTE_COUNT); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 528 | |
| 529 | dev_dbg(iop_chan->device->common.dev, "%s len: %u\n", |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 530 | __func__, len); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 531 | |
| 532 | spin_lock_bh(&iop_chan->lock); |
| 533 | slot_cnt = iop_chan_memcpy_slot_count(len, &slots_per_op); |
| 534 | sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op); |
| 535 | if (sw_desc) { |
| 536 | grp_start = sw_desc->group_head; |
Dan Williams | d4c56f9 | 2008-02-02 19:49:58 -0700 | [diff] [blame] | 537 | iop_desc_init_memcpy(grp_start, flags); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 538 | iop_desc_set_byte_count(grp_start, iop_chan, len); |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 539 | iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest); |
| 540 | iop_desc_set_memcpy_src_addr(grp_start, dma_src); |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 541 | sw_desc->async_tx.flags = flags; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 542 | } |
| 543 | spin_unlock_bh(&iop_chan->lock); |
| 544 | |
| 545 | return sw_desc ? &sw_desc->async_tx : NULL; |
| 546 | } |
| 547 | |
| 548 | static struct dma_async_tx_descriptor * |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 549 | iop_adma_prep_dma_xor(struct dma_chan *chan, dma_addr_t dma_dest, |
| 550 | dma_addr_t *dma_src, unsigned int src_cnt, size_t len, |
Dan Williams | d4c56f9 | 2008-02-02 19:49:58 -0700 | [diff] [blame] | 551 | unsigned long flags) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 552 | { |
| 553 | struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan); |
| 554 | struct iop_adma_desc_slot *sw_desc, *grp_start; |
| 555 | int slot_cnt, slots_per_op; |
| 556 | |
| 557 | if (unlikely(!len)) |
| 558 | return NULL; |
Coly Li | e2ec771 | 2011-03-27 01:26:52 +0800 | [diff] [blame] | 559 | BUG_ON(len > IOP_ADMA_XOR_MAX_BYTE_COUNT); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 560 | |
| 561 | dev_dbg(iop_chan->device->common.dev, |
Dan Williams | d4c56f9 | 2008-02-02 19:49:58 -0700 | [diff] [blame] | 562 | "%s src_cnt: %d len: %u flags: %lx\n", |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 563 | __func__, src_cnt, len, flags); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 564 | |
| 565 | spin_lock_bh(&iop_chan->lock); |
| 566 | slot_cnt = iop_chan_xor_slot_count(len, src_cnt, &slots_per_op); |
| 567 | sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op); |
| 568 | if (sw_desc) { |
| 569 | grp_start = sw_desc->group_head; |
Dan Williams | d4c56f9 | 2008-02-02 19:49:58 -0700 | [diff] [blame] | 570 | iop_desc_init_xor(grp_start, src_cnt, flags); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 571 | iop_desc_set_byte_count(grp_start, iop_chan, len); |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 572 | iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest); |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 573 | sw_desc->async_tx.flags = flags; |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 574 | while (src_cnt--) |
| 575 | iop_desc_set_xor_src_addr(grp_start, src_cnt, |
| 576 | dma_src[src_cnt]); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 577 | } |
| 578 | spin_unlock_bh(&iop_chan->lock); |
| 579 | |
| 580 | return sw_desc ? &sw_desc->async_tx : NULL; |
| 581 | } |
| 582 | |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 583 | static struct dma_async_tx_descriptor * |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 584 | iop_adma_prep_dma_xor_val(struct dma_chan *chan, dma_addr_t *dma_src, |
| 585 | unsigned int src_cnt, size_t len, u32 *result, |
| 586 | unsigned long flags) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 587 | { |
| 588 | struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan); |
| 589 | struct iop_adma_desc_slot *sw_desc, *grp_start; |
| 590 | int slot_cnt, slots_per_op; |
| 591 | |
| 592 | if (unlikely(!len)) |
| 593 | return NULL; |
| 594 | |
| 595 | dev_dbg(iop_chan->device->common.dev, "%s src_cnt: %d len: %u\n", |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 596 | __func__, src_cnt, len); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 597 | |
| 598 | spin_lock_bh(&iop_chan->lock); |
| 599 | slot_cnt = iop_chan_zero_sum_slot_count(len, src_cnt, &slots_per_op); |
| 600 | sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op); |
| 601 | if (sw_desc) { |
| 602 | grp_start = sw_desc->group_head; |
Dan Williams | d4c56f9 | 2008-02-02 19:49:58 -0700 | [diff] [blame] | 603 | iop_desc_init_zero_sum(grp_start, src_cnt, flags); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 604 | iop_desc_set_zero_sum_byte_count(grp_start, len); |
| 605 | grp_start->xor_check_result = result; |
| 606 | pr_debug("\t%s: grp_start->xor_check_result: %p\n", |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 607 | __func__, grp_start->xor_check_result); |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 608 | sw_desc->async_tx.flags = flags; |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 609 | while (src_cnt--) |
| 610 | iop_desc_set_zero_sum_src_addr(grp_start, src_cnt, |
| 611 | dma_src[src_cnt]); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 612 | } |
| 613 | spin_unlock_bh(&iop_chan->lock); |
| 614 | |
| 615 | return sw_desc ? &sw_desc->async_tx : NULL; |
| 616 | } |
| 617 | |
Dan Williams | 7bf649a | 2009-08-28 14:32:04 -0700 | [diff] [blame] | 618 | static struct dma_async_tx_descriptor * |
| 619 | iop_adma_prep_dma_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src, |
| 620 | unsigned int src_cnt, const unsigned char *scf, size_t len, |
| 621 | unsigned long flags) |
| 622 | { |
| 623 | struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan); |
| 624 | struct iop_adma_desc_slot *sw_desc, *g; |
| 625 | int slot_cnt, slots_per_op; |
| 626 | int continue_srcs; |
| 627 | |
| 628 | if (unlikely(!len)) |
| 629 | return NULL; |
| 630 | BUG_ON(len > IOP_ADMA_XOR_MAX_BYTE_COUNT); |
| 631 | |
| 632 | dev_dbg(iop_chan->device->common.dev, |
| 633 | "%s src_cnt: %d len: %u flags: %lx\n", |
| 634 | __func__, src_cnt, len, flags); |
| 635 | |
| 636 | if (dmaf_p_disabled_continue(flags)) |
| 637 | continue_srcs = 1+src_cnt; |
| 638 | else if (dmaf_continue(flags)) |
| 639 | continue_srcs = 3+src_cnt; |
| 640 | else |
| 641 | continue_srcs = 0+src_cnt; |
| 642 | |
| 643 | spin_lock_bh(&iop_chan->lock); |
| 644 | slot_cnt = iop_chan_pq_slot_count(len, continue_srcs, &slots_per_op); |
| 645 | sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op); |
| 646 | if (sw_desc) { |
| 647 | int i; |
| 648 | |
| 649 | g = sw_desc->group_head; |
| 650 | iop_desc_set_byte_count(g, iop_chan, len); |
| 651 | |
| 652 | /* even if P is disabled its destination address (bits |
| 653 | * [3:0]) must match Q. It is ok if P points to an |
| 654 | * invalid address, it won't be written. |
| 655 | */ |
| 656 | if (flags & DMA_PREP_PQ_DISABLE_P) |
| 657 | dst[0] = dst[1] & 0x7; |
| 658 | |
| 659 | iop_desc_set_pq_addr(g, dst); |
Dan Williams | 7bf649a | 2009-08-28 14:32:04 -0700 | [diff] [blame] | 660 | sw_desc->async_tx.flags = flags; |
| 661 | for (i = 0; i < src_cnt; i++) |
| 662 | iop_desc_set_pq_src_addr(g, i, src[i], scf[i]); |
| 663 | |
| 664 | /* if we are continuing a previous operation factor in |
| 665 | * the old p and q values, see the comment for dma_maxpq |
| 666 | * in include/linux/dmaengine.h |
| 667 | */ |
| 668 | if (dmaf_p_disabled_continue(flags)) |
| 669 | iop_desc_set_pq_src_addr(g, i++, dst[1], 1); |
| 670 | else if (dmaf_continue(flags)) { |
| 671 | iop_desc_set_pq_src_addr(g, i++, dst[0], 0); |
| 672 | iop_desc_set_pq_src_addr(g, i++, dst[1], 1); |
| 673 | iop_desc_set_pq_src_addr(g, i++, dst[1], 0); |
| 674 | } |
| 675 | iop_desc_init_pq(g, i, flags); |
| 676 | } |
| 677 | spin_unlock_bh(&iop_chan->lock); |
| 678 | |
| 679 | return sw_desc ? &sw_desc->async_tx : NULL; |
| 680 | } |
| 681 | |
| 682 | static struct dma_async_tx_descriptor * |
| 683 | iop_adma_prep_dma_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src, |
| 684 | unsigned int src_cnt, const unsigned char *scf, |
| 685 | size_t len, enum sum_check_flags *pqres, |
| 686 | unsigned long flags) |
| 687 | { |
| 688 | struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan); |
| 689 | struct iop_adma_desc_slot *sw_desc, *g; |
| 690 | int slot_cnt, slots_per_op; |
| 691 | |
| 692 | if (unlikely(!len)) |
| 693 | return NULL; |
| 694 | BUG_ON(len > IOP_ADMA_XOR_MAX_BYTE_COUNT); |
| 695 | |
| 696 | dev_dbg(iop_chan->device->common.dev, "%s src_cnt: %d len: %u\n", |
| 697 | __func__, src_cnt, len); |
| 698 | |
| 699 | spin_lock_bh(&iop_chan->lock); |
| 700 | slot_cnt = iop_chan_pq_zero_sum_slot_count(len, src_cnt + 2, &slots_per_op); |
| 701 | sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op); |
| 702 | if (sw_desc) { |
| 703 | /* for validate operations p and q are tagged onto the |
| 704 | * end of the source list |
| 705 | */ |
| 706 | int pq_idx = src_cnt; |
| 707 | |
| 708 | g = sw_desc->group_head; |
| 709 | iop_desc_init_pq_zero_sum(g, src_cnt+2, flags); |
| 710 | iop_desc_set_pq_zero_sum_byte_count(g, len); |
| 711 | g->pq_check_result = pqres; |
| 712 | pr_debug("\t%s: g->pq_check_result: %p\n", |
| 713 | __func__, g->pq_check_result); |
Dan Williams | 7bf649a | 2009-08-28 14:32:04 -0700 | [diff] [blame] | 714 | sw_desc->async_tx.flags = flags; |
| 715 | while (src_cnt--) |
| 716 | iop_desc_set_pq_zero_sum_src_addr(g, src_cnt, |
| 717 | src[src_cnt], |
| 718 | scf[src_cnt]); |
| 719 | iop_desc_set_pq_zero_sum_addr(g, pq_idx, src); |
| 720 | } |
| 721 | spin_unlock_bh(&iop_chan->lock); |
| 722 | |
| 723 | return sw_desc ? &sw_desc->async_tx : NULL; |
| 724 | } |
| 725 | |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 726 | static void iop_adma_free_chan_resources(struct dma_chan *chan) |
| 727 | { |
| 728 | struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan); |
| 729 | struct iop_adma_desc_slot *iter, *_iter; |
| 730 | int in_use_descs = 0; |
| 731 | |
| 732 | iop_adma_slot_cleanup(iop_chan); |
| 733 | |
| 734 | spin_lock_bh(&iop_chan->lock); |
| 735 | list_for_each_entry_safe(iter, _iter, &iop_chan->chain, |
| 736 | chain_node) { |
| 737 | in_use_descs++; |
| 738 | list_del(&iter->chain_node); |
| 739 | } |
| 740 | list_for_each_entry_safe_reverse( |
| 741 | iter, _iter, &iop_chan->all_slots, slot_node) { |
| 742 | list_del(&iter->slot_node); |
| 743 | kfree(iter); |
| 744 | iop_chan->slots_allocated--; |
| 745 | } |
| 746 | iop_chan->last_used = NULL; |
| 747 | |
| 748 | dev_dbg(iop_chan->device->common.dev, "%s slots_allocated %d\n", |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 749 | __func__, iop_chan->slots_allocated); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 750 | spin_unlock_bh(&iop_chan->lock); |
| 751 | |
| 752 | /* one is ok since we left it on there on purpose */ |
| 753 | if (in_use_descs > 1) |
| 754 | printk(KERN_ERR "IOP: Freeing %d in use descriptors!\n", |
| 755 | in_use_descs - 1); |
| 756 | } |
| 757 | |
| 758 | /** |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 759 | * iop_adma_status - poll the status of an ADMA transaction |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 760 | * @chan: ADMA channel handle |
| 761 | * @cookie: ADMA transaction identifier |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 762 | * @txstate: a holder for the current state of the channel or NULL |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 763 | */ |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 764 | static enum dma_status iop_adma_status(struct dma_chan *chan, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 765 | dma_cookie_t cookie, |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 766 | struct dma_tx_state *txstate) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 767 | { |
| 768 | struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan); |
Vinod Koul | 949ff5b | 2012-03-13 11:58:12 +0530 | [diff] [blame] | 769 | int ret; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 770 | |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 771 | ret = dma_cookie_status(chan, cookie, txstate); |
Vinod Koul | 9f571502 | 2013-10-16 20:49:42 +0530 | [diff] [blame] | 772 | if (ret == DMA_COMPLETE) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 773 | return ret; |
| 774 | |
| 775 | iop_adma_slot_cleanup(iop_chan); |
| 776 | |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 777 | return dma_cookie_status(chan, cookie, txstate); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | static irqreturn_t iop_adma_eot_handler(int irq, void *data) |
| 781 | { |
| 782 | struct iop_adma_chan *chan = data; |
| 783 | |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 784 | dev_dbg(chan->device->common.dev, "%s\n", __func__); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 785 | |
| 786 | tasklet_schedule(&chan->irq_tasklet); |
| 787 | |
| 788 | iop_adma_device_clear_eot_status(chan); |
| 789 | |
| 790 | return IRQ_HANDLED; |
| 791 | } |
| 792 | |
| 793 | static irqreturn_t iop_adma_eoc_handler(int irq, void *data) |
| 794 | { |
| 795 | struct iop_adma_chan *chan = data; |
| 796 | |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 797 | dev_dbg(chan->device->common.dev, "%s\n", __func__); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 798 | |
| 799 | tasklet_schedule(&chan->irq_tasklet); |
| 800 | |
| 801 | iop_adma_device_clear_eoc_status(chan); |
| 802 | |
| 803 | return IRQ_HANDLED; |
| 804 | } |
| 805 | |
| 806 | static irqreturn_t iop_adma_err_handler(int irq, void *data) |
| 807 | { |
| 808 | struct iop_adma_chan *chan = data; |
| 809 | unsigned long status = iop_chan_get_status(chan); |
| 810 | |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 811 | dev_err(chan->device->common.dev, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 812 | "error ( %s%s%s%s%s%s%s)\n", |
| 813 | iop_is_err_int_parity(status, chan) ? "int_parity " : "", |
| 814 | iop_is_err_mcu_abort(status, chan) ? "mcu_abort " : "", |
| 815 | iop_is_err_int_tabort(status, chan) ? "int_tabort " : "", |
| 816 | iop_is_err_int_mabort(status, chan) ? "int_mabort " : "", |
| 817 | iop_is_err_pci_tabort(status, chan) ? "pci_tabort " : "", |
| 818 | iop_is_err_pci_mabort(status, chan) ? "pci_mabort " : "", |
| 819 | iop_is_err_split_tx(status, chan) ? "split_tx " : ""); |
| 820 | |
| 821 | iop_adma_device_clear_err_status(chan); |
| 822 | |
| 823 | BUG(); |
| 824 | |
| 825 | return IRQ_HANDLED; |
| 826 | } |
| 827 | |
| 828 | static void iop_adma_issue_pending(struct dma_chan *chan) |
| 829 | { |
| 830 | struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan); |
| 831 | |
| 832 | if (iop_chan->pending) { |
| 833 | iop_chan->pending = 0; |
| 834 | iop_chan_append(iop_chan); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | /* |
| 839 | * Perform a transaction to verify the HW works. |
| 840 | */ |
| 841 | #define IOP_ADMA_TEST_SIZE 2000 |
| 842 | |
Bill Pemberton | 463a1f8 | 2012-11-19 13:22:55 -0500 | [diff] [blame] | 843 | static int iop_adma_memcpy_self_test(struct iop_adma_device *device) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 844 | { |
| 845 | int i; |
| 846 | void *src, *dest; |
| 847 | dma_addr_t src_dma, dest_dma; |
| 848 | struct dma_chan *dma_chan; |
| 849 | dma_cookie_t cookie; |
| 850 | struct dma_async_tx_descriptor *tx; |
| 851 | int err = 0; |
| 852 | struct iop_adma_chan *iop_chan; |
| 853 | |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 854 | dev_dbg(device->common.dev, "%s\n", __func__); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 855 | |
Christophe Jaillet | eccf214 | 2008-05-20 16:33:06 -0700 | [diff] [blame] | 856 | src = kmalloc(IOP_ADMA_TEST_SIZE, GFP_KERNEL); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 857 | if (!src) |
| 858 | return -ENOMEM; |
Christophe Jaillet | eccf214 | 2008-05-20 16:33:06 -0700 | [diff] [blame] | 859 | dest = kzalloc(IOP_ADMA_TEST_SIZE, GFP_KERNEL); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 860 | if (!dest) { |
| 861 | kfree(src); |
| 862 | return -ENOMEM; |
| 863 | } |
| 864 | |
| 865 | /* Fill in src buffer */ |
| 866 | for (i = 0; i < IOP_ADMA_TEST_SIZE; i++) |
| 867 | ((u8 *) src)[i] = (u8)i; |
| 868 | |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 869 | /* Start copy, using first DMA channel */ |
| 870 | dma_chan = container_of(device->common.channels.next, |
| 871 | struct dma_chan, |
| 872 | device_node); |
Dan Williams | aa1e6f1 | 2009-01-06 11:38:17 -0700 | [diff] [blame] | 873 | if (iop_adma_alloc_chan_resources(dma_chan) < 1) { |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 874 | err = -ENODEV; |
| 875 | goto out; |
| 876 | } |
| 877 | |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 878 | dest_dma = dma_map_single(dma_chan->device->dev, dest, |
| 879 | IOP_ADMA_TEST_SIZE, DMA_FROM_DEVICE); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 880 | src_dma = dma_map_single(dma_chan->device->dev, src, |
| 881 | IOP_ADMA_TEST_SIZE, DMA_TO_DEVICE); |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 882 | tx = iop_adma_prep_dma_memcpy(dma_chan, dest_dma, src_dma, |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 883 | IOP_ADMA_TEST_SIZE, |
| 884 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 885 | |
| 886 | cookie = iop_adma_tx_submit(tx); |
| 887 | iop_adma_issue_pending(dma_chan); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 888 | msleep(1); |
| 889 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 890 | if (iop_adma_status(dma_chan, cookie, NULL) != |
Vinod Koul | 9f571502 | 2013-10-16 20:49:42 +0530 | [diff] [blame] | 891 | DMA_COMPLETE) { |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 892 | dev_err(dma_chan->device->dev, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 893 | "Self-test copy timed out, disabling\n"); |
| 894 | err = -ENODEV; |
| 895 | goto free_resources; |
| 896 | } |
| 897 | |
| 898 | iop_chan = to_iop_adma_chan(dma_chan); |
| 899 | dma_sync_single_for_cpu(&iop_chan->device->pdev->dev, dest_dma, |
| 900 | IOP_ADMA_TEST_SIZE, DMA_FROM_DEVICE); |
| 901 | if (memcmp(src, dest, IOP_ADMA_TEST_SIZE)) { |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 902 | dev_err(dma_chan->device->dev, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 903 | "Self-test copy failed compare, disabling\n"); |
| 904 | err = -ENODEV; |
| 905 | goto free_resources; |
| 906 | } |
| 907 | |
| 908 | free_resources: |
| 909 | iop_adma_free_chan_resources(dma_chan); |
| 910 | out: |
| 911 | kfree(src); |
| 912 | kfree(dest); |
| 913 | return err; |
| 914 | } |
| 915 | |
| 916 | #define IOP_ADMA_NUM_SRC_TEST 4 /* must be <= 15 */ |
Bill Pemberton | 463a1f8 | 2012-11-19 13:22:55 -0500 | [diff] [blame] | 917 | static int |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 918 | iop_adma_xor_val_self_test(struct iop_adma_device *device) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 919 | { |
| 920 | int i, src_idx; |
| 921 | struct page *dest; |
| 922 | struct page *xor_srcs[IOP_ADMA_NUM_SRC_TEST]; |
| 923 | struct page *zero_sum_srcs[IOP_ADMA_NUM_SRC_TEST + 1]; |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 924 | dma_addr_t dma_srcs[IOP_ADMA_NUM_SRC_TEST + 1]; |
Olof Johansson | f9f0a7d | 2013-07-08 15:59:35 -0700 | [diff] [blame] | 925 | dma_addr_t dest_dma; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 926 | struct dma_async_tx_descriptor *tx; |
| 927 | struct dma_chan *dma_chan; |
| 928 | dma_cookie_t cookie; |
| 929 | u8 cmp_byte = 0; |
| 930 | u32 cmp_word; |
| 931 | u32 zero_sum_result; |
| 932 | int err = 0; |
| 933 | struct iop_adma_chan *iop_chan; |
| 934 | |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 935 | dev_dbg(device->common.dev, "%s\n", __func__); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 936 | |
| 937 | for (src_idx = 0; src_idx < IOP_ADMA_NUM_SRC_TEST; src_idx++) { |
| 938 | xor_srcs[src_idx] = alloc_page(GFP_KERNEL); |
Roel Kluin | a09b09a | 2009-02-25 13:56:21 +0100 | [diff] [blame] | 939 | if (!xor_srcs[src_idx]) { |
| 940 | while (src_idx--) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 941 | __free_page(xor_srcs[src_idx]); |
Roel Kluin | a09b09a | 2009-02-25 13:56:21 +0100 | [diff] [blame] | 942 | return -ENOMEM; |
| 943 | } |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | dest = alloc_page(GFP_KERNEL); |
Roel Kluin | a09b09a | 2009-02-25 13:56:21 +0100 | [diff] [blame] | 947 | if (!dest) { |
| 948 | while (src_idx--) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 949 | __free_page(xor_srcs[src_idx]); |
Roel Kluin | a09b09a | 2009-02-25 13:56:21 +0100 | [diff] [blame] | 950 | return -ENOMEM; |
| 951 | } |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 952 | |
| 953 | /* Fill in src buffers */ |
| 954 | for (src_idx = 0; src_idx < IOP_ADMA_NUM_SRC_TEST; src_idx++) { |
| 955 | u8 *ptr = page_address(xor_srcs[src_idx]); |
| 956 | for (i = 0; i < PAGE_SIZE; i++) |
| 957 | ptr[i] = (1 << src_idx); |
| 958 | } |
| 959 | |
| 960 | for (src_idx = 0; src_idx < IOP_ADMA_NUM_SRC_TEST; src_idx++) |
| 961 | cmp_byte ^= (u8) (1 << src_idx); |
| 962 | |
| 963 | cmp_word = (cmp_byte << 24) | (cmp_byte << 16) | |
| 964 | (cmp_byte << 8) | cmp_byte; |
| 965 | |
| 966 | memset(page_address(dest), 0, PAGE_SIZE); |
| 967 | |
| 968 | dma_chan = container_of(device->common.channels.next, |
| 969 | struct dma_chan, |
| 970 | device_node); |
Dan Williams | aa1e6f1 | 2009-01-06 11:38:17 -0700 | [diff] [blame] | 971 | if (iop_adma_alloc_chan_resources(dma_chan) < 1) { |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 972 | err = -ENODEV; |
| 973 | goto out; |
| 974 | } |
| 975 | |
| 976 | /* test xor */ |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 977 | dest_dma = dma_map_page(dma_chan->device->dev, dest, 0, |
| 978 | PAGE_SIZE, DMA_FROM_DEVICE); |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 979 | for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++) |
| 980 | dma_srcs[i] = dma_map_page(dma_chan->device->dev, xor_srcs[i], |
| 981 | 0, PAGE_SIZE, DMA_TO_DEVICE); |
| 982 | tx = iop_adma_prep_dma_xor(dma_chan, dest_dma, dma_srcs, |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 983 | IOP_ADMA_NUM_SRC_TEST, PAGE_SIZE, |
| 984 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 985 | |
| 986 | cookie = iop_adma_tx_submit(tx); |
| 987 | iop_adma_issue_pending(dma_chan); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 988 | msleep(8); |
| 989 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 990 | if (iop_adma_status(dma_chan, cookie, NULL) != |
Vinod Koul | 9f571502 | 2013-10-16 20:49:42 +0530 | [diff] [blame] | 991 | DMA_COMPLETE) { |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 992 | dev_err(dma_chan->device->dev, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 993 | "Self-test xor timed out, disabling\n"); |
| 994 | err = -ENODEV; |
| 995 | goto free_resources; |
| 996 | } |
| 997 | |
| 998 | iop_chan = to_iop_adma_chan(dma_chan); |
| 999 | dma_sync_single_for_cpu(&iop_chan->device->pdev->dev, dest_dma, |
| 1000 | PAGE_SIZE, DMA_FROM_DEVICE); |
| 1001 | for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) { |
| 1002 | u32 *ptr = page_address(dest); |
| 1003 | if (ptr[i] != cmp_word) { |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 1004 | dev_err(dma_chan->device->dev, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1005 | "Self-test xor failed compare, disabling\n"); |
| 1006 | err = -ENODEV; |
| 1007 | goto free_resources; |
| 1008 | } |
| 1009 | } |
| 1010 | dma_sync_single_for_device(&iop_chan->device->pdev->dev, dest_dma, |
| 1011 | PAGE_SIZE, DMA_TO_DEVICE); |
| 1012 | |
| 1013 | /* skip zero sum if the capability is not present */ |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 1014 | if (!dma_has_cap(DMA_XOR_VAL, dma_chan->device->cap_mask)) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1015 | goto free_resources; |
| 1016 | |
| 1017 | /* zero sum the sources with the destintation page */ |
| 1018 | for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++) |
| 1019 | zero_sum_srcs[i] = xor_srcs[i]; |
| 1020 | zero_sum_srcs[i] = dest; |
| 1021 | |
| 1022 | zero_sum_result = 1; |
| 1023 | |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 1024 | for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++) |
| 1025 | dma_srcs[i] = dma_map_page(dma_chan->device->dev, |
| 1026 | zero_sum_srcs[i], 0, PAGE_SIZE, |
| 1027 | DMA_TO_DEVICE); |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 1028 | tx = iop_adma_prep_dma_xor_val(dma_chan, dma_srcs, |
| 1029 | IOP_ADMA_NUM_SRC_TEST + 1, PAGE_SIZE, |
| 1030 | &zero_sum_result, |
| 1031 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1032 | |
| 1033 | cookie = iop_adma_tx_submit(tx); |
| 1034 | iop_adma_issue_pending(dma_chan); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1035 | msleep(8); |
| 1036 | |
Vinod Koul | 9f571502 | 2013-10-16 20:49:42 +0530 | [diff] [blame] | 1037 | if (iop_adma_status(dma_chan, cookie, NULL) != DMA_COMPLETE) { |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 1038 | dev_err(dma_chan->device->dev, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1039 | "Self-test zero sum timed out, disabling\n"); |
| 1040 | err = -ENODEV; |
| 1041 | goto free_resources; |
| 1042 | } |
| 1043 | |
| 1044 | if (zero_sum_result != 0) { |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 1045 | dev_err(dma_chan->device->dev, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1046 | "Self-test zero sum failed compare, disabling\n"); |
| 1047 | err = -ENODEV; |
| 1048 | goto free_resources; |
| 1049 | } |
| 1050 | |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1051 | /* test for non-zero parity sum */ |
| 1052 | zero_sum_result = 0; |
Dan Williams | 0036731 | 2008-02-02 19:49:57 -0700 | [diff] [blame] | 1053 | for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++) |
| 1054 | dma_srcs[i] = dma_map_page(dma_chan->device->dev, |
| 1055 | zero_sum_srcs[i], 0, PAGE_SIZE, |
| 1056 | DMA_TO_DEVICE); |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 1057 | tx = iop_adma_prep_dma_xor_val(dma_chan, dma_srcs, |
| 1058 | IOP_ADMA_NUM_SRC_TEST + 1, PAGE_SIZE, |
| 1059 | &zero_sum_result, |
| 1060 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1061 | |
| 1062 | cookie = iop_adma_tx_submit(tx); |
| 1063 | iop_adma_issue_pending(dma_chan); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1064 | msleep(8); |
| 1065 | |
Vinod Koul | 9f571502 | 2013-10-16 20:49:42 +0530 | [diff] [blame] | 1066 | if (iop_adma_status(dma_chan, cookie, NULL) != DMA_COMPLETE) { |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 1067 | dev_err(dma_chan->device->dev, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1068 | "Self-test non-zero sum timed out, disabling\n"); |
| 1069 | err = -ENODEV; |
| 1070 | goto free_resources; |
| 1071 | } |
| 1072 | |
| 1073 | if (zero_sum_result != 1) { |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 1074 | dev_err(dma_chan->device->dev, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1075 | "Self-test non-zero sum failed compare, disabling\n"); |
| 1076 | err = -ENODEV; |
| 1077 | goto free_resources; |
| 1078 | } |
| 1079 | |
| 1080 | free_resources: |
| 1081 | iop_adma_free_chan_resources(dma_chan); |
| 1082 | out: |
| 1083 | src_idx = IOP_ADMA_NUM_SRC_TEST; |
| 1084 | while (src_idx--) |
| 1085 | __free_page(xor_srcs[src_idx]); |
| 1086 | __free_page(dest); |
| 1087 | return err; |
| 1088 | } |
| 1089 | |
Wei Yongquan | 0261f74 | 2010-12-29 20:30:55 +0800 | [diff] [blame] | 1090 | #ifdef CONFIG_RAID6_PQ |
Bill Pemberton | 463a1f8 | 2012-11-19 13:22:55 -0500 | [diff] [blame] | 1091 | static int |
Dan Williams | f6dbf65 | 2009-08-29 19:12:40 -0700 | [diff] [blame] | 1092 | iop_adma_pq_zero_sum_self_test(struct iop_adma_device *device) |
| 1093 | { |
| 1094 | /* combined sources, software pq results, and extra hw pq results */ |
| 1095 | struct page *pq[IOP_ADMA_NUM_SRC_TEST+2+2]; |
| 1096 | /* ptr to the extra hw pq buffers defined above */ |
| 1097 | struct page **pq_hw = &pq[IOP_ADMA_NUM_SRC_TEST+2]; |
| 1098 | /* address conversion buffers (dma_map / page_address) */ |
| 1099 | void *pq_sw[IOP_ADMA_NUM_SRC_TEST+2]; |
Don Morris | 3d9ea9e | 2012-03-15 11:07:30 -0700 | [diff] [blame] | 1100 | dma_addr_t pq_src[IOP_ADMA_NUM_SRC_TEST+2]; |
| 1101 | dma_addr_t *pq_dest = &pq_src[IOP_ADMA_NUM_SRC_TEST]; |
Dan Williams | f6dbf65 | 2009-08-29 19:12:40 -0700 | [diff] [blame] | 1102 | |
| 1103 | int i; |
| 1104 | struct dma_async_tx_descriptor *tx; |
| 1105 | struct dma_chan *dma_chan; |
| 1106 | dma_cookie_t cookie; |
| 1107 | u32 zero_sum_result; |
| 1108 | int err = 0; |
| 1109 | struct device *dev; |
| 1110 | |
| 1111 | dev_dbg(device->common.dev, "%s\n", __func__); |
| 1112 | |
| 1113 | for (i = 0; i < ARRAY_SIZE(pq); i++) { |
| 1114 | pq[i] = alloc_page(GFP_KERNEL); |
| 1115 | if (!pq[i]) { |
| 1116 | while (i--) |
| 1117 | __free_page(pq[i]); |
| 1118 | return -ENOMEM; |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | /* Fill in src buffers */ |
| 1123 | for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++) { |
| 1124 | pq_sw[i] = page_address(pq[i]); |
| 1125 | memset(pq_sw[i], 0x11111111 * (1<<i), PAGE_SIZE); |
| 1126 | } |
| 1127 | pq_sw[i] = page_address(pq[i]); |
| 1128 | pq_sw[i+1] = page_address(pq[i+1]); |
| 1129 | |
| 1130 | dma_chan = container_of(device->common.channels.next, |
| 1131 | struct dma_chan, |
| 1132 | device_node); |
| 1133 | if (iop_adma_alloc_chan_resources(dma_chan) < 1) { |
| 1134 | err = -ENODEV; |
| 1135 | goto out; |
| 1136 | } |
| 1137 | |
| 1138 | dev = dma_chan->device->dev; |
| 1139 | |
| 1140 | /* initialize the dests */ |
| 1141 | memset(page_address(pq_hw[0]), 0 , PAGE_SIZE); |
| 1142 | memset(page_address(pq_hw[1]), 0 , PAGE_SIZE); |
| 1143 | |
| 1144 | /* test pq */ |
| 1145 | pq_dest[0] = dma_map_page(dev, pq_hw[0], 0, PAGE_SIZE, DMA_FROM_DEVICE); |
| 1146 | pq_dest[1] = dma_map_page(dev, pq_hw[1], 0, PAGE_SIZE, DMA_FROM_DEVICE); |
| 1147 | for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++) |
| 1148 | pq_src[i] = dma_map_page(dev, pq[i], 0, PAGE_SIZE, |
| 1149 | DMA_TO_DEVICE); |
| 1150 | |
| 1151 | tx = iop_adma_prep_dma_pq(dma_chan, pq_dest, pq_src, |
| 1152 | IOP_ADMA_NUM_SRC_TEST, (u8 *)raid6_gfexp, |
| 1153 | PAGE_SIZE, |
| 1154 | DMA_PREP_INTERRUPT | |
| 1155 | DMA_CTRL_ACK); |
| 1156 | |
| 1157 | cookie = iop_adma_tx_submit(tx); |
| 1158 | iop_adma_issue_pending(dma_chan); |
| 1159 | msleep(8); |
| 1160 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1161 | if (iop_adma_status(dma_chan, cookie, NULL) != |
Vinod Koul | 9f571502 | 2013-10-16 20:49:42 +0530 | [diff] [blame] | 1162 | DMA_COMPLETE) { |
Dan Williams | f6dbf65 | 2009-08-29 19:12:40 -0700 | [diff] [blame] | 1163 | dev_err(dev, "Self-test pq timed out, disabling\n"); |
| 1164 | err = -ENODEV; |
| 1165 | goto free_resources; |
| 1166 | } |
| 1167 | |
| 1168 | raid6_call.gen_syndrome(IOP_ADMA_NUM_SRC_TEST+2, PAGE_SIZE, pq_sw); |
| 1169 | |
| 1170 | if (memcmp(pq_sw[IOP_ADMA_NUM_SRC_TEST], |
| 1171 | page_address(pq_hw[0]), PAGE_SIZE) != 0) { |
| 1172 | dev_err(dev, "Self-test p failed compare, disabling\n"); |
| 1173 | err = -ENODEV; |
| 1174 | goto free_resources; |
| 1175 | } |
| 1176 | if (memcmp(pq_sw[IOP_ADMA_NUM_SRC_TEST+1], |
| 1177 | page_address(pq_hw[1]), PAGE_SIZE) != 0) { |
| 1178 | dev_err(dev, "Self-test q failed compare, disabling\n"); |
| 1179 | err = -ENODEV; |
| 1180 | goto free_resources; |
| 1181 | } |
| 1182 | |
| 1183 | /* test correct zero sum using the software generated pq values */ |
| 1184 | for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 2; i++) |
| 1185 | pq_src[i] = dma_map_page(dev, pq[i], 0, PAGE_SIZE, |
| 1186 | DMA_TO_DEVICE); |
| 1187 | |
| 1188 | zero_sum_result = ~0; |
| 1189 | tx = iop_adma_prep_dma_pq_val(dma_chan, &pq_src[IOP_ADMA_NUM_SRC_TEST], |
| 1190 | pq_src, IOP_ADMA_NUM_SRC_TEST, |
| 1191 | raid6_gfexp, PAGE_SIZE, &zero_sum_result, |
| 1192 | DMA_PREP_INTERRUPT|DMA_CTRL_ACK); |
| 1193 | |
| 1194 | cookie = iop_adma_tx_submit(tx); |
| 1195 | iop_adma_issue_pending(dma_chan); |
| 1196 | msleep(8); |
| 1197 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1198 | if (iop_adma_status(dma_chan, cookie, NULL) != |
Vinod Koul | 9f571502 | 2013-10-16 20:49:42 +0530 | [diff] [blame] | 1199 | DMA_COMPLETE) { |
Dan Williams | f6dbf65 | 2009-08-29 19:12:40 -0700 | [diff] [blame] | 1200 | dev_err(dev, "Self-test pq-zero-sum timed out, disabling\n"); |
| 1201 | err = -ENODEV; |
| 1202 | goto free_resources; |
| 1203 | } |
| 1204 | |
| 1205 | if (zero_sum_result != 0) { |
| 1206 | dev_err(dev, "Self-test pq-zero-sum failed to validate: %x\n", |
| 1207 | zero_sum_result); |
| 1208 | err = -ENODEV; |
| 1209 | goto free_resources; |
| 1210 | } |
| 1211 | |
| 1212 | /* test incorrect zero sum */ |
| 1213 | i = IOP_ADMA_NUM_SRC_TEST; |
| 1214 | memset(pq_sw[i] + 100, 0, 100); |
| 1215 | memset(pq_sw[i+1] + 200, 0, 200); |
| 1216 | for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 2; i++) |
| 1217 | pq_src[i] = dma_map_page(dev, pq[i], 0, PAGE_SIZE, |
| 1218 | DMA_TO_DEVICE); |
| 1219 | |
| 1220 | zero_sum_result = 0; |
| 1221 | tx = iop_adma_prep_dma_pq_val(dma_chan, &pq_src[IOP_ADMA_NUM_SRC_TEST], |
| 1222 | pq_src, IOP_ADMA_NUM_SRC_TEST, |
| 1223 | raid6_gfexp, PAGE_SIZE, &zero_sum_result, |
| 1224 | DMA_PREP_INTERRUPT|DMA_CTRL_ACK); |
| 1225 | |
| 1226 | cookie = iop_adma_tx_submit(tx); |
| 1227 | iop_adma_issue_pending(dma_chan); |
| 1228 | msleep(8); |
| 1229 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1230 | if (iop_adma_status(dma_chan, cookie, NULL) != |
Vinod Koul | 9f571502 | 2013-10-16 20:49:42 +0530 | [diff] [blame] | 1231 | DMA_COMPLETE) { |
Dan Williams | f6dbf65 | 2009-08-29 19:12:40 -0700 | [diff] [blame] | 1232 | dev_err(dev, "Self-test !pq-zero-sum timed out, disabling\n"); |
| 1233 | err = -ENODEV; |
| 1234 | goto free_resources; |
| 1235 | } |
| 1236 | |
| 1237 | if (zero_sum_result != (SUM_CHECK_P_RESULT | SUM_CHECK_Q_RESULT)) { |
| 1238 | dev_err(dev, "Self-test !pq-zero-sum failed to validate: %x\n", |
| 1239 | zero_sum_result); |
| 1240 | err = -ENODEV; |
| 1241 | goto free_resources; |
| 1242 | } |
| 1243 | |
| 1244 | free_resources: |
| 1245 | iop_adma_free_chan_resources(dma_chan); |
| 1246 | out: |
| 1247 | i = ARRAY_SIZE(pq); |
| 1248 | while (i--) |
| 1249 | __free_page(pq[i]); |
| 1250 | return err; |
| 1251 | } |
| 1252 | #endif |
| 1253 | |
Greg Kroah-Hartman | 4bf27b8 | 2012-12-21 15:09:59 -0800 | [diff] [blame] | 1254 | static int iop_adma_remove(struct platform_device *dev) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1255 | { |
| 1256 | struct iop_adma_device *device = platform_get_drvdata(dev); |
| 1257 | struct dma_chan *chan, *_chan; |
| 1258 | struct iop_adma_chan *iop_chan; |
Jingoo Han | d4adcc0 | 2013-07-30 17:09:11 +0900 | [diff] [blame] | 1259 | struct iop_adma_platform_data *plat_data = dev_get_platdata(&dev->dev); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1260 | |
| 1261 | dma_async_device_unregister(&device->common); |
| 1262 | |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1263 | dma_free_coherent(&dev->dev, plat_data->pool_size, |
| 1264 | device->dma_desc_pool_virt, device->dma_desc_pool); |
| 1265 | |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1266 | list_for_each_entry_safe(chan, _chan, &device->common.channels, |
| 1267 | device_node) { |
| 1268 | iop_chan = to_iop_adma_chan(chan); |
| 1269 | list_del(&chan->device_node); |
| 1270 | kfree(iop_chan); |
| 1271 | } |
| 1272 | kfree(device); |
| 1273 | |
| 1274 | return 0; |
| 1275 | } |
| 1276 | |
Bill Pemberton | 463a1f8 | 2012-11-19 13:22:55 -0500 | [diff] [blame] | 1277 | static int iop_adma_probe(struct platform_device *pdev) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1278 | { |
| 1279 | struct resource *res; |
| 1280 | int ret = 0, i; |
| 1281 | struct iop_adma_device *adev; |
| 1282 | struct iop_adma_chan *iop_chan; |
| 1283 | struct dma_device *dma_dev; |
Jingoo Han | d4adcc0 | 2013-07-30 17:09:11 +0900 | [diff] [blame] | 1284 | struct iop_adma_platform_data *plat_data = dev_get_platdata(&pdev->dev); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1285 | |
| 1286 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1287 | if (!res) |
| 1288 | return -ENODEV; |
| 1289 | |
| 1290 | if (!devm_request_mem_region(&pdev->dev, res->start, |
H Hartley Sweeten | 2e032b6 | 2009-12-11 21:24:33 -0700 | [diff] [blame] | 1291 | resource_size(res), pdev->name)) |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1292 | return -EBUSY; |
| 1293 | |
| 1294 | adev = kzalloc(sizeof(*adev), GFP_KERNEL); |
| 1295 | if (!adev) |
| 1296 | return -ENOMEM; |
| 1297 | dma_dev = &adev->common; |
| 1298 | |
| 1299 | /* allocate coherent memory for hardware descriptors |
| 1300 | * note: writecombine gives slightly better performance, but |
| 1301 | * requires that we explicitly flush the writes |
| 1302 | */ |
| 1303 | if ((adev->dma_desc_pool_virt = dma_alloc_writecombine(&pdev->dev, |
| 1304 | plat_data->pool_size, |
| 1305 | &adev->dma_desc_pool, |
| 1306 | GFP_KERNEL)) == NULL) { |
| 1307 | ret = -ENOMEM; |
| 1308 | goto err_free_adev; |
| 1309 | } |
| 1310 | |
Masanari Iida | b6695e4 | 2012-01-27 23:00:53 +0900 | [diff] [blame] | 1311 | dev_dbg(&pdev->dev, "%s: allocated descriptor pool virt %p phys %p\n", |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 1312 | __func__, adev->dma_desc_pool_virt, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1313 | (void *) adev->dma_desc_pool); |
| 1314 | |
| 1315 | adev->id = plat_data->hw_id; |
| 1316 | |
| 1317 | /* discover transaction capabilites from the platform data */ |
| 1318 | dma_dev->cap_mask = plat_data->cap_mask; |
| 1319 | |
| 1320 | adev->pdev = pdev; |
| 1321 | platform_set_drvdata(pdev, adev); |
| 1322 | |
| 1323 | INIT_LIST_HEAD(&dma_dev->channels); |
| 1324 | |
| 1325 | /* set base routines */ |
| 1326 | dma_dev->device_alloc_chan_resources = iop_adma_alloc_chan_resources; |
| 1327 | dma_dev->device_free_chan_resources = iop_adma_free_chan_resources; |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1328 | dma_dev->device_tx_status = iop_adma_status; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1329 | dma_dev->device_issue_pending = iop_adma_issue_pending; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1330 | dma_dev->dev = &pdev->dev; |
| 1331 | |
| 1332 | /* set prep routines based on capability */ |
| 1333 | if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) |
| 1334 | dma_dev->device_prep_dma_memcpy = iop_adma_prep_dma_memcpy; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1335 | if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) { |
| 1336 | dma_dev->max_xor = iop_adma_get_max_xor(); |
| 1337 | dma_dev->device_prep_dma_xor = iop_adma_prep_dma_xor; |
| 1338 | } |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 1339 | if (dma_has_cap(DMA_XOR_VAL, dma_dev->cap_mask)) |
| 1340 | dma_dev->device_prep_dma_xor_val = |
| 1341 | iop_adma_prep_dma_xor_val; |
Dan Williams | 7bf649a | 2009-08-28 14:32:04 -0700 | [diff] [blame] | 1342 | if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) { |
| 1343 | dma_set_maxpq(dma_dev, iop_adma_get_max_pq(), 0); |
| 1344 | dma_dev->device_prep_dma_pq = iop_adma_prep_dma_pq; |
| 1345 | } |
| 1346 | if (dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask)) |
| 1347 | dma_dev->device_prep_dma_pq_val = |
| 1348 | iop_adma_prep_dma_pq_val; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1349 | if (dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask)) |
| 1350 | dma_dev->device_prep_dma_interrupt = |
| 1351 | iop_adma_prep_dma_interrupt; |
| 1352 | |
| 1353 | iop_chan = kzalloc(sizeof(*iop_chan), GFP_KERNEL); |
| 1354 | if (!iop_chan) { |
| 1355 | ret = -ENOMEM; |
| 1356 | goto err_free_dma; |
| 1357 | } |
| 1358 | iop_chan->device = adev; |
| 1359 | |
| 1360 | iop_chan->mmr_base = devm_ioremap(&pdev->dev, res->start, |
H Hartley Sweeten | 2e032b6 | 2009-12-11 21:24:33 -0700 | [diff] [blame] | 1361 | resource_size(res)); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1362 | if (!iop_chan->mmr_base) { |
| 1363 | ret = -ENOMEM; |
| 1364 | goto err_free_iop_chan; |
| 1365 | } |
| 1366 | tasklet_init(&iop_chan->irq_tasklet, iop_adma_tasklet, (unsigned long) |
| 1367 | iop_chan); |
| 1368 | |
| 1369 | /* clear errors before enabling interrupts */ |
| 1370 | iop_adma_device_clear_err_status(iop_chan); |
| 1371 | |
| 1372 | for (i = 0; i < 3; i++) { |
| 1373 | irq_handler_t handler[] = { iop_adma_eot_handler, |
| 1374 | iop_adma_eoc_handler, |
| 1375 | iop_adma_err_handler }; |
| 1376 | int irq = platform_get_irq(pdev, i); |
| 1377 | if (irq < 0) { |
| 1378 | ret = -ENXIO; |
| 1379 | goto err_free_iop_chan; |
| 1380 | } else { |
| 1381 | ret = devm_request_irq(&pdev->dev, irq, |
| 1382 | handler[i], 0, pdev->name, iop_chan); |
| 1383 | if (ret) |
| 1384 | goto err_free_iop_chan; |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | spin_lock_init(&iop_chan->lock); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1389 | INIT_LIST_HEAD(&iop_chan->chain); |
| 1390 | INIT_LIST_HEAD(&iop_chan->all_slots); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1391 | iop_chan->common.device = dma_dev; |
Russell King - ARM Linux | 8ac6954 | 2012-03-06 22:36:27 +0000 | [diff] [blame] | 1392 | dma_cookie_init(&iop_chan->common); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1393 | list_add_tail(&iop_chan->common.device_node, &dma_dev->channels); |
| 1394 | |
| 1395 | if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) { |
| 1396 | ret = iop_adma_memcpy_self_test(adev); |
| 1397 | dev_dbg(&pdev->dev, "memcpy self test returned %d\n", ret); |
| 1398 | if (ret) |
| 1399 | goto err_free_iop_chan; |
| 1400 | } |
| 1401 | |
Bartlomiej Zolnierkiewicz | 48a9db4 | 2013-07-03 15:05:06 -0700 | [diff] [blame] | 1402 | if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) { |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 1403 | ret = iop_adma_xor_val_self_test(adev); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1404 | dev_dbg(&pdev->dev, "xor self test returned %d\n", ret); |
| 1405 | if (ret) |
| 1406 | goto err_free_iop_chan; |
| 1407 | } |
| 1408 | |
Dan Williams | f6dbf65 | 2009-08-29 19:12:40 -0700 | [diff] [blame] | 1409 | if (dma_has_cap(DMA_PQ, dma_dev->cap_mask) && |
| 1410 | dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask)) { |
Wei Yongquan | 0261f74 | 2010-12-29 20:30:55 +0800 | [diff] [blame] | 1411 | #ifdef CONFIG_RAID6_PQ |
Dan Williams | f6dbf65 | 2009-08-29 19:12:40 -0700 | [diff] [blame] | 1412 | ret = iop_adma_pq_zero_sum_self_test(adev); |
| 1413 | dev_dbg(&pdev->dev, "pq self test returned %d\n", ret); |
| 1414 | #else |
| 1415 | /* can not test raid6, so do not publish capability */ |
| 1416 | dma_cap_clear(DMA_PQ, dma_dev->cap_mask); |
| 1417 | dma_cap_clear(DMA_PQ_VAL, dma_dev->cap_mask); |
| 1418 | ret = 0; |
| 1419 | #endif |
| 1420 | if (ret) |
| 1421 | goto err_free_iop_chan; |
| 1422 | } |
| 1423 | |
Olof Johansson | f9f0a7d | 2013-07-08 15:59:35 -0700 | [diff] [blame] | 1424 | dev_info(&pdev->dev, "Intel(R) IOP: ( %s%s%s%s%s%s)\n", |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 1425 | dma_has_cap(DMA_PQ, dma_dev->cap_mask) ? "pq " : "", |
| 1426 | dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask) ? "pq_val " : "", |
| 1427 | dma_has_cap(DMA_XOR, dma_dev->cap_mask) ? "xor " : "", |
| 1428 | dma_has_cap(DMA_XOR_VAL, dma_dev->cap_mask) ? "xor_val " : "", |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 1429 | dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask) ? "cpy " : "", |
| 1430 | dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : ""); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1431 | |
| 1432 | dma_async_device_register(dma_dev); |
| 1433 | goto out; |
| 1434 | |
| 1435 | err_free_iop_chan: |
| 1436 | kfree(iop_chan); |
| 1437 | err_free_dma: |
| 1438 | dma_free_coherent(&adev->pdev->dev, plat_data->pool_size, |
| 1439 | adev->dma_desc_pool_virt, adev->dma_desc_pool); |
| 1440 | err_free_adev: |
| 1441 | kfree(adev); |
| 1442 | out: |
| 1443 | return ret; |
| 1444 | } |
| 1445 | |
| 1446 | static void iop_chan_start_null_memcpy(struct iop_adma_chan *iop_chan) |
| 1447 | { |
| 1448 | struct iop_adma_desc_slot *sw_desc, *grp_start; |
| 1449 | dma_cookie_t cookie; |
| 1450 | int slot_cnt, slots_per_op; |
| 1451 | |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 1452 | dev_dbg(iop_chan->device->common.dev, "%s\n", __func__); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1453 | |
| 1454 | spin_lock_bh(&iop_chan->lock); |
| 1455 | slot_cnt = iop_chan_memcpy_slot_count(0, &slots_per_op); |
| 1456 | sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op); |
| 1457 | if (sw_desc) { |
| 1458 | grp_start = sw_desc->group_head; |
| 1459 | |
Dan Williams | 308136d | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 1460 | list_splice_init(&sw_desc->tx_list, &iop_chan->chain); |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 1461 | async_tx_ack(&sw_desc->async_tx); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1462 | iop_desc_init_memcpy(grp_start, 0); |
| 1463 | iop_desc_set_byte_count(grp_start, iop_chan, 0); |
| 1464 | iop_desc_set_dest_addr(grp_start, iop_chan, 0); |
| 1465 | iop_desc_set_memcpy_src_addr(grp_start, 0); |
| 1466 | |
Russell King - ARM Linux | 2a926e4 | 2012-03-06 22:36:07 +0000 | [diff] [blame] | 1467 | cookie = dma_cookie_assign(&sw_desc->async_tx); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1468 | |
| 1469 | /* initialize the completed cookie to be less than |
| 1470 | * the most recently used cookie |
| 1471 | */ |
Russell King - ARM Linux | 4d4e58d | 2012-03-06 22:34:06 +0000 | [diff] [blame] | 1472 | iop_chan->common.completed_cookie = cookie - 1; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1473 | |
| 1474 | /* channel should not be busy */ |
| 1475 | BUG_ON(iop_chan_is_busy(iop_chan)); |
| 1476 | |
| 1477 | /* clear any prior error-status bits */ |
| 1478 | iop_adma_device_clear_err_status(iop_chan); |
| 1479 | |
| 1480 | /* disable operation */ |
| 1481 | iop_chan_disable(iop_chan); |
| 1482 | |
| 1483 | /* set the descriptor address */ |
| 1484 | iop_chan_set_next_descriptor(iop_chan, sw_desc->async_tx.phys); |
| 1485 | |
| 1486 | /* 1/ don't add pre-chained descriptors |
| 1487 | * 2/ dummy read to flush next_desc write |
| 1488 | */ |
| 1489 | BUG_ON(iop_desc_get_next_desc(sw_desc)); |
| 1490 | |
| 1491 | /* run the descriptor */ |
| 1492 | iop_chan_enable(iop_chan); |
| 1493 | } else |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 1494 | dev_err(iop_chan->device->common.dev, |
| 1495 | "failed to allocate null descriptor\n"); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1496 | spin_unlock_bh(&iop_chan->lock); |
| 1497 | } |
| 1498 | |
| 1499 | static void iop_chan_start_null_xor(struct iop_adma_chan *iop_chan) |
| 1500 | { |
| 1501 | struct iop_adma_desc_slot *sw_desc, *grp_start; |
| 1502 | dma_cookie_t cookie; |
| 1503 | int slot_cnt, slots_per_op; |
| 1504 | |
Harvey Harrison | 3d9b525 | 2008-03-13 17:45:28 -0700 | [diff] [blame] | 1505 | dev_dbg(iop_chan->device->common.dev, "%s\n", __func__); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1506 | |
| 1507 | spin_lock_bh(&iop_chan->lock); |
| 1508 | slot_cnt = iop_chan_xor_slot_count(0, 2, &slots_per_op); |
| 1509 | sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op); |
| 1510 | if (sw_desc) { |
| 1511 | grp_start = sw_desc->group_head; |
Dan Williams | 308136d | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 1512 | list_splice_init(&sw_desc->tx_list, &iop_chan->chain); |
Dan Williams | 636bdea | 2008-04-17 20:17:26 -0700 | [diff] [blame] | 1513 | async_tx_ack(&sw_desc->async_tx); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1514 | iop_desc_init_null_xor(grp_start, 2, 0); |
| 1515 | iop_desc_set_byte_count(grp_start, iop_chan, 0); |
| 1516 | iop_desc_set_dest_addr(grp_start, iop_chan, 0); |
| 1517 | iop_desc_set_xor_src_addr(grp_start, 0, 0); |
| 1518 | iop_desc_set_xor_src_addr(grp_start, 1, 0); |
| 1519 | |
Russell King - ARM Linux | 2a926e4 | 2012-03-06 22:36:07 +0000 | [diff] [blame] | 1520 | cookie = dma_cookie_assign(&sw_desc->async_tx); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1521 | |
| 1522 | /* initialize the completed cookie to be less than |
| 1523 | * the most recently used cookie |
| 1524 | */ |
Russell King - ARM Linux | 4d4e58d | 2012-03-06 22:34:06 +0000 | [diff] [blame] | 1525 | iop_chan->common.completed_cookie = cookie - 1; |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1526 | |
| 1527 | /* channel should not be busy */ |
| 1528 | BUG_ON(iop_chan_is_busy(iop_chan)); |
| 1529 | |
| 1530 | /* clear any prior error-status bits */ |
| 1531 | iop_adma_device_clear_err_status(iop_chan); |
| 1532 | |
| 1533 | /* disable operation */ |
| 1534 | iop_chan_disable(iop_chan); |
| 1535 | |
| 1536 | /* set the descriptor address */ |
| 1537 | iop_chan_set_next_descriptor(iop_chan, sw_desc->async_tx.phys); |
| 1538 | |
| 1539 | /* 1/ don't add pre-chained descriptors |
| 1540 | * 2/ dummy read to flush next_desc write |
| 1541 | */ |
| 1542 | BUG_ON(iop_desc_get_next_desc(sw_desc)); |
| 1543 | |
| 1544 | /* run the descriptor */ |
| 1545 | iop_chan_enable(iop_chan); |
| 1546 | } else |
Joe Perches | 1ba151c | 2012-10-28 01:05:44 -0700 | [diff] [blame] | 1547 | dev_err(iop_chan->device->common.dev, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1548 | "failed to allocate null descriptor\n"); |
| 1549 | spin_unlock_bh(&iop_chan->lock); |
| 1550 | } |
| 1551 | |
| 1552 | static struct platform_driver iop_adma_driver = { |
| 1553 | .probe = iop_adma_probe, |
Bill Pemberton | a7d6e3e | 2012-11-19 13:20:04 -0500 | [diff] [blame] | 1554 | .remove = iop_adma_remove, |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1555 | .driver = { |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1556 | .name = "iop-adma", |
| 1557 | }, |
| 1558 | }; |
| 1559 | |
Axel Lin | c94e910 | 2011-11-26 15:11:12 +0800 | [diff] [blame] | 1560 | module_platform_driver(iop_adma_driver); |
Dan Williams | c211092 | 2007-01-02 13:52:26 -0700 | [diff] [blame] | 1561 | |
| 1562 | MODULE_AUTHOR("Intel Corporation"); |
| 1563 | MODULE_DESCRIPTION("IOP ADMA Engine Driver"); |
| 1564 | MODULE_LICENSE("GPL"); |
Axel Lin | c94e910 | 2011-11-26 15:11:12 +0800 | [diff] [blame] | 1565 | MODULE_ALIAS("platform:iop-adma"); |