2 * Copyright(c) 2006, Intel Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <linux/types.h>
22 #include <mach/hardware.h>
23 #include <asm/hardware/iop_adma.h>
25 #define ADMA_ACCR(chan) (chan->mmr_base + 0x0)
26 #define ADMA_ACSR(chan) (chan->mmr_base + 0x4)
27 #define ADMA_ADAR(chan) (chan->mmr_base + 0x8)
28 #define ADMA_IIPCR(chan) (chan->mmr_base + 0x18)
29 #define ADMA_IIPAR(chan) (chan->mmr_base + 0x1c)
30 #define ADMA_IIPUAR(chan) (chan->mmr_base + 0x20)
31 #define ADMA_ANDAR(chan) (chan->mmr_base + 0x24)
32 #define ADMA_ADCR(chan) (chan->mmr_base + 0x28)
33 #define ADMA_CARMD(chan) (chan->mmr_base + 0x2c)
34 #define ADMA_ABCR(chan) (chan->mmr_base + 0x30)
35 #define ADMA_DLADR(chan) (chan->mmr_base + 0x34)
36 #define ADMA_DUADR(chan) (chan->mmr_base + 0x38)
37 #define ADMA_SLAR(src, chan) (chan->mmr_base + (0x3c + (src << 3)))
38 #define ADMA_SUAR(src, chan) (chan->mmr_base + (0x40 + (src << 3)))
40 struct iop13xx_adma_src
{
45 unsigned int pq_upper_src_addr
:24;
46 unsigned int pq_dmlt
:8;
51 struct iop13xx_adma_desc_ctrl
{
52 unsigned int int_en
:1;
53 unsigned int xfer_dir
:2;
54 unsigned int src_select
:4;
55 unsigned int zero_result
:1;
56 unsigned int block_fill_en
:1;
57 unsigned int crc_gen_en
:1;
58 unsigned int crc_xfer_dis
:1;
59 unsigned int crc_seed_fetch_dis
:1;
60 unsigned int status_write_back_en
:1;
61 unsigned int endian_swap_en
:1;
62 unsigned int reserved0
:2;
63 unsigned int pq_update_xfer_en
:1;
64 unsigned int dual_xor_en
:1;
65 unsigned int pq_xfer_en
:1;
66 unsigned int p_xfer_dis
:1;
67 unsigned int reserved1
:10;
68 unsigned int relax_order_en
:1;
69 unsigned int no_snoop_en
:1;
72 struct iop13xx_adma_byte_count
{
73 unsigned int byte_count
:24;
74 unsigned int host_if
:3;
75 unsigned int reserved
:2;
76 unsigned int zero_result_err_q
:1;
77 unsigned int zero_result_err
:1;
78 unsigned int tx_complete
:1;
81 struct iop13xx_adma_desc_hw
{
85 struct iop13xx_adma_desc_ctrl desc_ctrl_field
;
94 struct iop13xx_adma_byte_count byte_count_field
;
102 u32 pq_upper_dest_addr
;
104 struct iop13xx_adma_src src
[1];
107 struct iop13xx_adma_desc_dual_xor
{
113 u32 h_upper_dest_addr
;
119 u32 h_upper_src_addr
;
121 u32 d_upper_src_addr
;
123 u32 d_upper_dest_addr
;
126 struct iop13xx_adma_desc_pq_update
{
132 u32 p_upper_dest_addr
;
138 u32 p_upper_src_addr
;
141 unsigned int q_upper_src_addr
:24;
142 unsigned int q_dmlt
:8;
145 u32 q_upper_dest_addr
;
148 static inline int iop_adma_get_max_xor(void)
153 static inline u32
iop_chan_get_current_descriptor(struct iop_adma_chan
*chan
)
155 return __raw_readl(ADMA_ADAR(chan
));
158 static inline void iop_chan_set_next_descriptor(struct iop_adma_chan
*chan
,
161 __raw_writel(next_desc_addr
, ADMA_ANDAR(chan
));
164 #define ADMA_STATUS_BUSY (1 << 13)
166 static inline char iop_chan_is_busy(struct iop_adma_chan
*chan
)
168 if (__raw_readl(ADMA_ACSR(chan
)) &
176 iop_chan_get_desc_align(struct iop_adma_chan
*chan
, int num_slots
)
180 #define iop_desc_is_aligned(x, y) 1
183 iop_chan_memcpy_slot_count(size_t len
, int *slots_per_op
)
189 #define iop_chan_interrupt_slot_count(s, c) iop_chan_memcpy_slot_count(0, s)
192 iop_chan_memset_slot_count(size_t len
, int *slots_per_op
)
199 iop_chan_xor_slot_count(size_t len
, int src_cnt
, int *slots_per_op
)
201 static const char slot_count_table
[] = { 1, 2, 2, 2,
206 *slots_per_op
= slot_count_table
[src_cnt
- 1];
207 return *slots_per_op
;
210 #define ADMA_MAX_BYTE_COUNT (16 * 1024 * 1024)
211 #define IOP_ADMA_MAX_BYTE_COUNT ADMA_MAX_BYTE_COUNT
212 #define IOP_ADMA_ZERO_SUM_MAX_BYTE_COUNT ADMA_MAX_BYTE_COUNT
213 #define IOP_ADMA_XOR_MAX_BYTE_COUNT ADMA_MAX_BYTE_COUNT
214 #define iop_chan_zero_sum_slot_count(l, s, o) iop_chan_xor_slot_count(l, s, o)
216 static inline u32
iop_desc_get_dest_addr(struct iop_adma_desc_slot
*desc
,
217 struct iop_adma_chan
*chan
)
219 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
220 return hw_desc
->dest_addr
;
223 static inline u32
iop_desc_get_byte_count(struct iop_adma_desc_slot
*desc
,
224 struct iop_adma_chan
*chan
)
226 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
227 return hw_desc
->byte_count_field
.byte_count
;
230 static inline u32
iop_desc_get_src_addr(struct iop_adma_desc_slot
*desc
,
231 struct iop_adma_chan
*chan
,
234 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
235 return hw_desc
->src
[src_idx
].src_addr
;
238 static inline u32
iop_desc_get_src_count(struct iop_adma_desc_slot
*desc
,
239 struct iop_adma_chan
*chan
)
241 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
242 return hw_desc
->desc_ctrl_field
.src_select
+ 1;
246 iop_desc_init_memcpy(struct iop_adma_desc_slot
*desc
, unsigned long flags
)
248 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
251 struct iop13xx_adma_desc_ctrl field
;
254 u_desc_ctrl
.value
= 0;
255 u_desc_ctrl
.field
.xfer_dir
= 3; /* local to internal bus */
256 u_desc_ctrl
.field
.int_en
= flags
& DMA_PREP_INTERRUPT
;
257 hw_desc
->desc_ctrl
= u_desc_ctrl
.value
;
258 hw_desc
->crc_addr
= 0;
262 iop_desc_init_memset(struct iop_adma_desc_slot
*desc
, unsigned long flags
)
264 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
267 struct iop13xx_adma_desc_ctrl field
;
270 u_desc_ctrl
.value
= 0;
271 u_desc_ctrl
.field
.xfer_dir
= 3; /* local to internal bus */
272 u_desc_ctrl
.field
.block_fill_en
= 1;
273 u_desc_ctrl
.field
.int_en
= flags
& DMA_PREP_INTERRUPT
;
274 hw_desc
->desc_ctrl
= u_desc_ctrl
.value
;
275 hw_desc
->crc_addr
= 0;
278 /* to do: support buffers larger than ADMA_MAX_BYTE_COUNT */
280 iop_desc_init_xor(struct iop_adma_desc_slot
*desc
, int src_cnt
,
283 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
286 struct iop13xx_adma_desc_ctrl field
;
289 u_desc_ctrl
.value
= 0;
290 u_desc_ctrl
.field
.src_select
= src_cnt
- 1;
291 u_desc_ctrl
.field
.xfer_dir
= 3; /* local to internal bus */
292 u_desc_ctrl
.field
.int_en
= flags
& DMA_PREP_INTERRUPT
;
293 hw_desc
->desc_ctrl
= u_desc_ctrl
.value
;
294 hw_desc
->crc_addr
= 0;
297 #define iop_desc_init_null_xor(d, s, i) iop_desc_init_xor(d, s, i)
299 /* to do: support buffers larger than ADMA_MAX_BYTE_COUNT */
301 iop_desc_init_zero_sum(struct iop_adma_desc_slot
*desc
, int src_cnt
,
304 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
307 struct iop13xx_adma_desc_ctrl field
;
310 u_desc_ctrl
.value
= 0;
311 u_desc_ctrl
.field
.src_select
= src_cnt
- 1;
312 u_desc_ctrl
.field
.xfer_dir
= 3; /* local to internal bus */
313 u_desc_ctrl
.field
.zero_result
= 1;
314 u_desc_ctrl
.field
.status_write_back_en
= 1;
315 u_desc_ctrl
.field
.int_en
= flags
& DMA_PREP_INTERRUPT
;
316 hw_desc
->desc_ctrl
= u_desc_ctrl
.value
;
317 hw_desc
->crc_addr
= 0;
322 static inline void iop_desc_set_byte_count(struct iop_adma_desc_slot
*desc
,
323 struct iop_adma_chan
*chan
,
326 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
327 hw_desc
->byte_count
= byte_count
;
331 iop_desc_set_zero_sum_byte_count(struct iop_adma_desc_slot
*desc
, u32 len
)
333 int slots_per_op
= desc
->slots_per_op
;
334 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
, *iter
;
337 if (len
<= IOP_ADMA_ZERO_SUM_MAX_BYTE_COUNT
) {
338 hw_desc
->byte_count
= len
;
341 iter
= iop_hw_desc_slot_idx(hw_desc
, i
);
342 iter
->byte_count
= IOP_ADMA_ZERO_SUM_MAX_BYTE_COUNT
;
343 len
-= IOP_ADMA_ZERO_SUM_MAX_BYTE_COUNT
;
345 } while (len
> IOP_ADMA_ZERO_SUM_MAX_BYTE_COUNT
);
348 iter
= iop_hw_desc_slot_idx(hw_desc
, i
);
349 iter
->byte_count
= len
;
355 static inline void iop_desc_set_dest_addr(struct iop_adma_desc_slot
*desc
,
356 struct iop_adma_chan
*chan
,
359 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
360 hw_desc
->dest_addr
= addr
;
361 hw_desc
->upper_dest_addr
= 0;
364 static inline void iop_desc_set_memcpy_src_addr(struct iop_adma_desc_slot
*desc
,
367 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
368 hw_desc
->src
[0].src_addr
= addr
;
369 hw_desc
->src
[0].upper_src_addr
= 0;
372 static inline void iop_desc_set_xor_src_addr(struct iop_adma_desc_slot
*desc
,
373 int src_idx
, dma_addr_t addr
)
375 int slot_cnt
= desc
->slot_cnt
, slots_per_op
= desc
->slots_per_op
;
376 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
, *iter
;
380 iter
= iop_hw_desc_slot_idx(hw_desc
, i
);
381 iter
->src
[src_idx
].src_addr
= addr
;
382 iter
->src
[src_idx
].upper_src_addr
= 0;
383 slot_cnt
-= slots_per_op
;
386 addr
+= IOP_ADMA_XOR_MAX_BYTE_COUNT
;
392 iop_desc_init_interrupt(struct iop_adma_desc_slot
*desc
,
393 struct iop_adma_chan
*chan
)
395 iop_desc_init_memcpy(desc
, 1);
396 iop_desc_set_byte_count(desc
, chan
, 0);
397 iop_desc_set_dest_addr(desc
, chan
, 0);
398 iop_desc_set_memcpy_src_addr(desc
, 0);
401 #define iop_desc_set_zero_sum_src_addr iop_desc_set_xor_src_addr
403 static inline void iop_desc_set_next_desc(struct iop_adma_desc_slot
*desc
,
406 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
408 iop_paranoia(hw_desc
->next_desc
);
409 hw_desc
->next_desc
= next_desc_addr
;
412 static inline u32
iop_desc_get_next_desc(struct iop_adma_desc_slot
*desc
)
414 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
415 return hw_desc
->next_desc
;
418 static inline void iop_desc_clear_next_desc(struct iop_adma_desc_slot
*desc
)
420 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
421 hw_desc
->next_desc
= 0;
424 static inline void iop_desc_set_block_fill_val(struct iop_adma_desc_slot
*desc
,
427 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
428 hw_desc
->block_fill_data
= val
;
431 static inline int iop_desc_get_zero_result(struct iop_adma_desc_slot
*desc
)
433 struct iop13xx_adma_desc_hw
*hw_desc
= desc
->hw_desc
;
434 struct iop13xx_adma_desc_ctrl desc_ctrl
= hw_desc
->desc_ctrl_field
;
435 struct iop13xx_adma_byte_count byte_count
= hw_desc
->byte_count_field
;
437 BUG_ON(!(byte_count
.tx_complete
&& desc_ctrl
.zero_result
));
439 if (desc_ctrl
.pq_xfer_en
)
440 return byte_count
.zero_result_err_q
;
442 return byte_count
.zero_result_err
;
445 static inline void iop_chan_append(struct iop_adma_chan
*chan
)
449 adma_accr
= __raw_readl(ADMA_ACCR(chan
));
451 __raw_writel(adma_accr
, ADMA_ACCR(chan
));
454 static inline u32
iop_chan_get_status(struct iop_adma_chan
*chan
)
456 return __raw_readl(ADMA_ACSR(chan
));
459 static inline void iop_chan_disable(struct iop_adma_chan
*chan
)
461 u32 adma_chan_ctrl
= __raw_readl(ADMA_ACCR(chan
));
462 adma_chan_ctrl
&= ~0x1;
463 __raw_writel(adma_chan_ctrl
, ADMA_ACCR(chan
));
466 static inline void iop_chan_enable(struct iop_adma_chan
*chan
)
470 adma_chan_ctrl
= __raw_readl(ADMA_ACCR(chan
));
471 adma_chan_ctrl
|= 0x1;
472 __raw_writel(adma_chan_ctrl
, ADMA_ACCR(chan
));
475 static inline void iop_adma_device_clear_eot_status(struct iop_adma_chan
*chan
)
477 u32 status
= __raw_readl(ADMA_ACSR(chan
));
479 __raw_writel(status
, ADMA_ACSR(chan
));
482 static inline void iop_adma_device_clear_eoc_status(struct iop_adma_chan
*chan
)
484 u32 status
= __raw_readl(ADMA_ACSR(chan
));
486 __raw_writel(status
, ADMA_ACSR(chan
));
489 static inline void iop_adma_device_clear_err_status(struct iop_adma_chan
*chan
)
491 u32 status
= __raw_readl(ADMA_ACSR(chan
));
492 status
&= (1 << 9) | (1 << 5) | (1 << 4) | (1 << 3);
493 __raw_writel(status
, ADMA_ACSR(chan
));
497 iop_is_err_int_parity(unsigned long status
, struct iop_adma_chan
*chan
)
499 return test_bit(9, &status
);
503 iop_is_err_mcu_abort(unsigned long status
, struct iop_adma_chan
*chan
)
505 return test_bit(5, &status
);
509 iop_is_err_int_tabort(unsigned long status
, struct iop_adma_chan
*chan
)
511 return test_bit(4, &status
);
515 iop_is_err_int_mabort(unsigned long status
, struct iop_adma_chan
*chan
)
517 return test_bit(3, &status
);
521 iop_is_err_pci_tabort(unsigned long status
, struct iop_adma_chan
*chan
)
527 iop_is_err_pci_mabort(unsigned long status
, struct iop_adma_chan
*chan
)
533 iop_is_err_split_tx(unsigned long status
, struct iop_adma_chan
*chan
)