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