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