/*1* Copyright (C) 2007, 2008, Marvell International Ltd.2*3* This program is free software; you can redistribute it and/or modify4* it under the terms and conditions of the GNU General Public License,5* version 2, as published by the Free Software Foundation.6*7* This program is distributed in the hope it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* for more details.11*12* You should have received a copy of the GNU General Public License13* along with this program; if not, write to the Free Software Foundation,14* Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.15*/1617#ifndef MV_XOR_H18#define MV_XOR_H1920#include <linux/types.h>21#include <linux/io.h>22#include <linux/dmaengine.h>23#include <linux/interrupt.h>2425#define USE_TIMER26#define MV_XOR_SLOT_SIZE 6427#define MV_XOR_THRESHOLD 12829#define XOR_OPERATION_MODE_XOR 030#define XOR_OPERATION_MODE_MEMCPY 231#define XOR_OPERATION_MODE_MEMSET 43233#define XOR_CURR_DESC(chan) (chan->mmr_base + 0x210 + (chan->idx * 4))34#define XOR_NEXT_DESC(chan) (chan->mmr_base + 0x200 + (chan->idx * 4))35#define XOR_BYTE_COUNT(chan) (chan->mmr_base + 0x220 + (chan->idx * 4))36#define XOR_DEST_POINTER(chan) (chan->mmr_base + 0x2B0 + (chan->idx * 4))37#define XOR_BLOCK_SIZE(chan) (chan->mmr_base + 0x2C0 + (chan->idx * 4))38#define XOR_INIT_VALUE_LOW(chan) (chan->mmr_base + 0x2E0)39#define XOR_INIT_VALUE_HIGH(chan) (chan->mmr_base + 0x2E4)4041#define XOR_CONFIG(chan) (chan->mmr_base + 0x10 + (chan->idx * 4))42#define XOR_ACTIVATION(chan) (chan->mmr_base + 0x20 + (chan->idx * 4))43#define XOR_INTR_CAUSE(chan) (chan->mmr_base + 0x30)44#define XOR_INTR_MASK(chan) (chan->mmr_base + 0x40)45#define XOR_ERROR_CAUSE(chan) (chan->mmr_base + 0x50)46#define XOR_ERROR_ADDR(chan) (chan->mmr_base + 0x60)47#define XOR_INTR_MASK_VALUE 0x3F54849#define WINDOW_BASE(w) (0x250 + ((w) << 2))50#define WINDOW_SIZE(w) (0x270 + ((w) << 2))51#define WINDOW_REMAP_HIGH(w) (0x290 + ((w) << 2))52#define WINDOW_BAR_ENABLE(chan) (0x240 + ((chan) << 2))5354struct mv_xor_shared_private {55void __iomem *xor_base;56void __iomem *xor_high_base;57};585960/**61* struct mv_xor_device - internal representation of a XOR device62* @pdev: Platform device63* @id: HW XOR Device selector64* @dma_desc_pool: base of DMA descriptor region (DMA address)65* @dma_desc_pool_virt: base of DMA descriptor region (CPU address)66* @common: embedded struct dma_device67*/68struct mv_xor_device {69struct platform_device *pdev;70int id;71dma_addr_t dma_desc_pool;72void *dma_desc_pool_virt;73struct dma_device common;74struct mv_xor_shared_private *shared;75};7677/**78* struct mv_xor_chan - internal representation of a XOR channel79* @pending: allows batching of hardware operations80* @completed_cookie: identifier for the most recently completed operation81* @lock: serializes enqueue/dequeue operations to the descriptors pool82* @mmr_base: memory mapped register base83* @idx: the index of the xor channel84* @chain: device chain view of the descriptors85* @completed_slots: slots completed by HW but still need to be acked86* @device: parent device87* @common: common dmaengine channel object members88* @last_used: place holder for allocation to continue from where it left off89* @all_slots: complete domain of slots usable by the channel90* @slots_allocated: records the actual size of the descriptor slot pool91* @irq_tasklet: bottom half where mv_xor_slot_cleanup runs92*/93struct mv_xor_chan {94int pending;95dma_cookie_t completed_cookie;96spinlock_t lock; /* protects the descriptor slot pool */97void __iomem *mmr_base;98unsigned int idx;99enum dma_transaction_type current_type;100struct list_head chain;101struct list_head completed_slots;102struct mv_xor_device *device;103struct dma_chan common;104struct mv_xor_desc_slot *last_used;105struct list_head all_slots;106int slots_allocated;107struct tasklet_struct irq_tasklet;108#ifdef USE_TIMER109unsigned long cleanup_time;110u32 current_on_last_cleanup;111dma_cookie_t is_complete_cookie;112#endif113};114115/**116* struct mv_xor_desc_slot - software descriptor117* @slot_node: node on the mv_xor_chan.all_slots list118* @chain_node: node on the mv_xor_chan.chain list119* @completed_node: node on the mv_xor_chan.completed_slots list120* @hw_desc: virtual address of the hardware descriptor chain121* @phys: hardware address of the hardware descriptor chain122* @group_head: first operation in a transaction123* @slot_cnt: total slots used in an transaction (group of operations)124* @slots_per_op: number of slots per operation125* @idx: pool index126* @unmap_src_cnt: number of xor sources127* @unmap_len: transaction bytecount128* @tx_list: list of slots that make up a multi-descriptor transaction129* @async_tx: support for the async_tx api130* @xor_check_result: result of zero sum131* @crc32_result: result crc calculation132*/133struct mv_xor_desc_slot {134struct list_head slot_node;135struct list_head chain_node;136struct list_head completed_node;137enum dma_transaction_type type;138void *hw_desc;139struct mv_xor_desc_slot *group_head;140u16 slot_cnt;141u16 slots_per_op;142u16 idx;143u16 unmap_src_cnt;144u32 value;145size_t unmap_len;146struct list_head tx_list;147struct dma_async_tx_descriptor async_tx;148union {149u32 *xor_check_result;150u32 *crc32_result;151};152#ifdef USE_TIMER153unsigned long arrival_time;154struct timer_list timeout;155#endif156};157158/* This structure describes XOR descriptor size 64bytes */159struct mv_xor_desc {160u32 status; /* descriptor execution status */161u32 crc32_result; /* result of CRC-32 calculation */162u32 desc_command; /* type of operation to be carried out */163u32 phy_next_desc; /* next descriptor address pointer */164u32 byte_count; /* size of src/dst blocks in bytes */165u32 phy_dest_addr; /* destination block address */166u32 phy_src_addr[8]; /* source block addresses */167u32 reserved0;168u32 reserved1;169};170171#define to_mv_sw_desc(addr_hw_desc) \172container_of(addr_hw_desc, struct mv_xor_desc_slot, hw_desc)173174#define mv_hw_desc_slot_idx(hw_desc, idx) \175((void *)(((unsigned long)hw_desc) + ((idx) << 5)))176177#define MV_XOR_MIN_BYTE_COUNT (128)178#define XOR_MAX_BYTE_COUNT ((16 * 1024 * 1024) - 1)179#define MV_XOR_MAX_BYTE_COUNT XOR_MAX_BYTE_COUNT180181182#endif183184185