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