1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2006-2009 DENX Software Engineering.
5 * Author: Yuri Tikhonov <yur@emcraft.com>
7 * Further porting to arch/powerpc by
8 * Anatolij Gustschin <agust@denx.de>
12 * This driver supports the asynchrounous DMA copy and RAID engines available
13 * on the AMCC PPC440SPe Processors.
14 * Based on the Intel Xscale(R) family of I/O Processors (IOP 32x, 33x, 134x)
15 * ADMA driver written by D.Williams.
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/async_tx.h>
21 #include <linux/delay.h>
22 #include <linux/dma-mapping.h>
23 #include <linux/spinlock.h>
24 #include <linux/interrupt.h>
25 #include <linux/slab.h>
26 #include <linux/uaccess.h>
27 #include <linux/proc_fs.h>
29 #include <linux/of_address.h>
30 #include <linux/of_irq.h>
31 #include <linux/of_platform.h>
33 #include <asm/dcr-regs.h>
35 #include "../dmaengine.h"
37 enum ppc_adma_init_code
{
42 PPC_ADMA_INIT_COHERENT
,
43 PPC_ADMA_INIT_CHANNEL
,
46 PPC_ADMA_INIT_REGISTER
49 static char *ppc_adma_errors
[] = {
50 [PPC_ADMA_INIT_OK
] = "ok",
51 [PPC_ADMA_INIT_MEMRES
] = "failed to get memory resource",
52 [PPC_ADMA_INIT_MEMREG
] = "failed to request memory region",
53 [PPC_ADMA_INIT_ALLOC
] = "failed to allocate memory for adev "
55 [PPC_ADMA_INIT_COHERENT
] = "failed to allocate coherent memory for "
56 "hardware descriptors",
57 [PPC_ADMA_INIT_CHANNEL
] = "failed to allocate memory for channel",
58 [PPC_ADMA_INIT_IRQ1
] = "failed to request first irq",
59 [PPC_ADMA_INIT_IRQ2
] = "failed to request second irq",
60 [PPC_ADMA_INIT_REGISTER
] = "failed to register dma async device",
63 static enum ppc_adma_init_code
64 ppc440spe_adma_devices
[PPC440SPE_ADMA_ENGINES_NUM
];
66 struct ppc_dma_chan_ref
{
67 struct dma_chan
*chan
;
68 struct list_head node
;
71 /* The list of channels exported by ppc440spe ADMA */
72 static struct list_head
73 ppc440spe_adma_chan_list
= LIST_HEAD_INIT(ppc440spe_adma_chan_list
);
75 /* This flag is set when want to refetch the xor chain in the interrupt
78 static u32 do_xor_refetch
;
80 /* Pointer to DMA0, DMA1 CP/CS FIFO */
81 static void *ppc440spe_dma_fifo_buf
;
83 /* Pointers to last submitted to DMA0, DMA1 CDBs */
84 static struct ppc440spe_adma_desc_slot
*chan_last_sub
[3];
85 static struct ppc440spe_adma_desc_slot
*chan_first_cdb
[3];
87 /* Pointer to last linked and submitted xor CB */
88 static struct ppc440spe_adma_desc_slot
*xor_last_linked
;
89 static struct ppc440spe_adma_desc_slot
*xor_last_submit
;
91 /* This array is used in data-check operations for storing a pattern */
92 static char ppc440spe_qword
[16];
94 static atomic_t ppc440spe_adma_err_irq_ref
;
95 static dcr_host_t ppc440spe_mq_dcr_host
;
96 static unsigned int ppc440spe_mq_dcr_len
;
98 /* Since RXOR operations use the common register (MQ0_CF2H) for setting-up
99 * the block size in transactions, then we do not allow to activate more than
100 * only one RXOR transactions simultaneously. So use this var to store
101 * the information about is RXOR currently active (PPC440SPE_RXOR_RUN bit is
102 * set) or not (PPC440SPE_RXOR_RUN is clear).
104 static unsigned long ppc440spe_rxor_state
;
106 /* These are used in enable & check routines
108 static u32 ppc440spe_r6_enabled
;
109 static struct ppc440spe_adma_chan
*ppc440spe_r6_tchan
;
110 static struct completion ppc440spe_r6_test_comp
;
112 static int ppc440spe_adma_dma2rxor_prep_src(
113 struct ppc440spe_adma_desc_slot
*desc
,
114 struct ppc440spe_rxor
*cursor
, int index
,
115 int src_cnt
, u32 addr
);
116 static void ppc440spe_adma_dma2rxor_set_src(
117 struct ppc440spe_adma_desc_slot
*desc
,
118 int index
, dma_addr_t addr
);
119 static void ppc440spe_adma_dma2rxor_set_mult(
120 struct ppc440spe_adma_desc_slot
*desc
,
124 #define ADMA_LL_DBG(x) ({ if (1) x; 0; })
126 #define ADMA_LL_DBG(x) ({ if (0) x; 0; })
129 static void print_cb(struct ppc440spe_adma_chan
*chan
, void *block
)
135 switch (chan
->device
->id
) {
140 pr_debug("CDB at %p [%d]:\n"
141 "\t attr 0x%02x opc 0x%02x cnt 0x%08x\n"
142 "\t sg1u 0x%08x sg1l 0x%08x\n"
143 "\t sg2u 0x%08x sg2l 0x%08x\n"
144 "\t sg3u 0x%08x sg3l 0x%08x\n",
145 cdb
, chan
->device
->id
,
146 cdb
->attr
, cdb
->opc
, le32_to_cpu(cdb
->cnt
),
147 le32_to_cpu(cdb
->sg1u
), le32_to_cpu(cdb
->sg1l
),
148 le32_to_cpu(cdb
->sg2u
), le32_to_cpu(cdb
->sg2l
),
149 le32_to_cpu(cdb
->sg3u
), le32_to_cpu(cdb
->sg3l
)
155 pr_debug("CB at %p [%d]:\n"
156 "\t cbc 0x%08x cbbc 0x%08x cbs 0x%08x\n"
157 "\t cbtah 0x%08x cbtal 0x%08x\n"
158 "\t cblah 0x%08x cblal 0x%08x\n",
159 cb
, chan
->device
->id
,
160 cb
->cbc
, cb
->cbbc
, cb
->cbs
,
161 cb
->cbtah
, cb
->cbtal
,
162 cb
->cblah
, cb
->cblal
);
163 for (i
= 0; i
< 16; i
++) {
164 if (i
&& !cb
->ops
[i
].h
&& !cb
->ops
[i
].l
)
166 pr_debug("\t ops[%2d]: h 0x%08x l 0x%08x\n",
167 i
, cb
->ops
[i
].h
, cb
->ops
[i
].l
);
173 static void print_cb_list(struct ppc440spe_adma_chan
*chan
,
174 struct ppc440spe_adma_desc_slot
*iter
)
176 for (; iter
; iter
= iter
->hw_next
)
177 print_cb(chan
, iter
->hw_desc
);
180 static void prep_dma_xor_dbg(int id
, dma_addr_t dst
, dma_addr_t
*src
,
181 unsigned int src_cnt
)
185 pr_debug("\n%s(%d):\nsrc: ", __func__
, id
);
186 for (i
= 0; i
< src_cnt
; i
++)
187 pr_debug("\t0x%016llx ", src
[i
]);
188 pr_debug("dst:\n\t0x%016llx\n", dst
);
191 static void prep_dma_pq_dbg(int id
, dma_addr_t
*dst
, dma_addr_t
*src
,
192 unsigned int src_cnt
)
196 pr_debug("\n%s(%d):\nsrc: ", __func__
, id
);
197 for (i
= 0; i
< src_cnt
; i
++)
198 pr_debug("\t0x%016llx ", src
[i
]);
200 for (i
= 0; i
< 2; i
++)
201 pr_debug("\t0x%016llx ", dst
[i
]);
204 static void prep_dma_pqzero_sum_dbg(int id
, dma_addr_t
*src
,
205 unsigned int src_cnt
,
206 const unsigned char *scf
)
210 pr_debug("\n%s(%d):\nsrc(coef): ", __func__
, id
);
212 for (i
= 0; i
< src_cnt
; i
++)
213 pr_debug("\t0x%016llx(0x%02x) ", src
[i
], scf
[i
]);
215 for (i
= 0; i
< src_cnt
; i
++)
216 pr_debug("\t0x%016llx(no) ", src
[i
]);
220 for (i
= 0; i
< 2; i
++)
221 pr_debug("\t0x%016llx ", src
[src_cnt
+ i
]);
224 /******************************************************************************
225 * Command (Descriptor) Blocks low-level routines
226 ******************************************************************************/
228 * ppc440spe_desc_init_interrupt - initialize the descriptor for INTERRUPT
231 static void ppc440spe_desc_init_interrupt(struct ppc440spe_adma_desc_slot
*desc
,
232 struct ppc440spe_adma_chan
*chan
)
236 switch (chan
->device
->id
) {
237 case PPC440SPE_XOR_ID
:
239 memset(desc
->hw_desc
, 0, sizeof(struct xor_cb
));
240 /* NOP with Command Block Complete Enable */
241 p
->cbc
= XOR_CBCR_CBCE_BIT
;
243 case PPC440SPE_DMA0_ID
:
244 case PPC440SPE_DMA1_ID
:
245 memset(desc
->hw_desc
, 0, sizeof(struct dma_cdb
));
246 /* NOP with interrupt */
247 set_bit(PPC440SPE_DESC_INT
, &desc
->flags
);
250 printk(KERN_ERR
"Unsupported id %d in %s\n", chan
->device
->id
,
257 * ppc440spe_desc_init_null_xor - initialize the descriptor for NULL XOR
260 static void ppc440spe_desc_init_null_xor(struct ppc440spe_adma_desc_slot
*desc
)
262 memset(desc
->hw_desc
, 0, sizeof(struct xor_cb
));
263 desc
->hw_next
= NULL
;
269 * ppc440spe_desc_init_xor - initialize the descriptor for XOR operation
271 static void ppc440spe_desc_init_xor(struct ppc440spe_adma_desc_slot
*desc
,
272 int src_cnt
, unsigned long flags
)
274 struct xor_cb
*hw_desc
= desc
->hw_desc
;
276 memset(desc
->hw_desc
, 0, sizeof(struct xor_cb
));
277 desc
->hw_next
= NULL
;
278 desc
->src_cnt
= src_cnt
;
281 hw_desc
->cbc
= XOR_CBCR_TGT_BIT
| src_cnt
;
282 if (flags
& DMA_PREP_INTERRUPT
)
283 /* Enable interrupt on completion */
284 hw_desc
->cbc
|= XOR_CBCR_CBCE_BIT
;
288 * ppc440spe_desc_init_dma2pq - initialize the descriptor for PQ
289 * operation in DMA2 controller
291 static void ppc440spe_desc_init_dma2pq(struct ppc440spe_adma_desc_slot
*desc
,
292 int dst_cnt
, int src_cnt
, unsigned long flags
)
294 struct xor_cb
*hw_desc
= desc
->hw_desc
;
296 memset(desc
->hw_desc
, 0, sizeof(struct xor_cb
));
297 desc
->hw_next
= NULL
;
298 desc
->src_cnt
= src_cnt
;
299 desc
->dst_cnt
= dst_cnt
;
300 memset(desc
->reverse_flags
, 0, sizeof(desc
->reverse_flags
));
301 desc
->descs_per_op
= 0;
303 hw_desc
->cbc
= XOR_CBCR_TGT_BIT
;
304 if (flags
& DMA_PREP_INTERRUPT
)
305 /* Enable interrupt on completion */
306 hw_desc
->cbc
|= XOR_CBCR_CBCE_BIT
;
309 #define DMA_CTRL_FLAGS_LAST DMA_PREP_FENCE
310 #define DMA_PREP_ZERO_P (DMA_CTRL_FLAGS_LAST << 1)
311 #define DMA_PREP_ZERO_Q (DMA_PREP_ZERO_P << 1)
314 * ppc440spe_desc_init_dma01pq - initialize the descriptors for PQ operation
317 static void ppc440spe_desc_init_dma01pq(struct ppc440spe_adma_desc_slot
*desc
,
318 int dst_cnt
, int src_cnt
, unsigned long flags
,
321 struct dma_cdb
*hw_desc
;
322 struct ppc440spe_adma_desc_slot
*iter
;
325 /* Common initialization of a PQ descriptors chain */
326 set_bits(op
, &desc
->flags
);
327 desc
->src_cnt
= src_cnt
;
328 desc
->dst_cnt
= dst_cnt
;
330 /* WXOR MULTICAST if both P and Q are being computed
331 * MV_SG1_SG2 if Q only
333 dopc
= (desc
->dst_cnt
== DMA_DEST_MAX_NUM
) ?
334 DMA_CDB_OPC_MULTICAST
: DMA_CDB_OPC_MV_SG1_SG2
;
336 list_for_each_entry(iter
, &desc
->group_list
, chain_node
) {
337 hw_desc
= iter
->hw_desc
;
338 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
340 if (likely(!list_is_last(&iter
->chain_node
,
341 &desc
->group_list
))) {
342 /* set 'next' pointer */
343 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
344 struct ppc440spe_adma_desc_slot
, chain_node
);
345 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
347 /* this is the last descriptor.
348 * this slot will be pasted from ADMA level
349 * each time it wants to configure parameters
350 * of the transaction (src, dst, ...)
352 iter
->hw_next
= NULL
;
353 if (flags
& DMA_PREP_INTERRUPT
)
354 set_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
356 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
360 /* Set OPS depending on WXOR/RXOR type of operation */
361 if (!test_bit(PPC440SPE_DESC_RXOR
, &desc
->flags
)) {
362 /* This is a WXOR only chain:
363 * - first descriptors are for zeroing destinations
364 * if PPC440SPE_ZERO_P/Q set;
365 * - descriptors remained are for GF-XOR operations.
367 iter
= list_first_entry(&desc
->group_list
,
368 struct ppc440spe_adma_desc_slot
,
371 if (test_bit(PPC440SPE_ZERO_P
, &desc
->flags
)) {
372 hw_desc
= iter
->hw_desc
;
373 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
374 iter
= list_first_entry(&iter
->chain_node
,
375 struct ppc440spe_adma_desc_slot
,
379 if (test_bit(PPC440SPE_ZERO_Q
, &desc
->flags
)) {
380 hw_desc
= iter
->hw_desc
;
381 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
382 iter
= list_first_entry(&iter
->chain_node
,
383 struct ppc440spe_adma_desc_slot
,
387 list_for_each_entry_from(iter
, &desc
->group_list
, chain_node
) {
388 hw_desc
= iter
->hw_desc
;
392 /* This is either RXOR-only or mixed RXOR/WXOR */
394 /* The first 1 or 2 slots in chain are always RXOR,
395 * if need to calculate P & Q, then there are two
396 * RXOR slots; if only P or only Q, then there is one
398 iter
= list_first_entry(&desc
->group_list
,
399 struct ppc440spe_adma_desc_slot
,
401 hw_desc
= iter
->hw_desc
;
402 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
404 if (desc
->dst_cnt
== DMA_DEST_MAX_NUM
) {
405 iter
= list_first_entry(&iter
->chain_node
,
406 struct ppc440spe_adma_desc_slot
,
408 hw_desc
= iter
->hw_desc
;
409 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
412 /* The remaining descs (if any) are WXORs */
413 if (test_bit(PPC440SPE_DESC_WXOR
, &desc
->flags
)) {
414 iter
= list_first_entry(&iter
->chain_node
,
415 struct ppc440spe_adma_desc_slot
,
417 list_for_each_entry_from(iter
, &desc
->group_list
,
419 hw_desc
= iter
->hw_desc
;
427 * ppc440spe_desc_init_dma01pqzero_sum - initialize the descriptor
428 * for PQ_ZERO_SUM operation
430 static void ppc440spe_desc_init_dma01pqzero_sum(
431 struct ppc440spe_adma_desc_slot
*desc
,
432 int dst_cnt
, int src_cnt
)
434 struct dma_cdb
*hw_desc
;
435 struct ppc440spe_adma_desc_slot
*iter
;
437 u8 dopc
= (dst_cnt
== 2) ? DMA_CDB_OPC_MULTICAST
:
438 DMA_CDB_OPC_MV_SG1_SG2
;
440 * Initialize starting from 2nd or 3rd descriptor dependent
441 * on dst_cnt. First one or two slots are for cloning P
442 * and/or Q to chan->pdest and/or chan->qdest as we have
443 * to preserve original P/Q.
445 iter
= list_first_entry(&desc
->group_list
,
446 struct ppc440spe_adma_desc_slot
, chain_node
);
447 iter
= list_entry(iter
->chain_node
.next
,
448 struct ppc440spe_adma_desc_slot
, chain_node
);
451 iter
= list_entry(iter
->chain_node
.next
,
452 struct ppc440spe_adma_desc_slot
, chain_node
);
454 /* initialize each source descriptor in chain */
455 list_for_each_entry_from(iter
, &desc
->group_list
, chain_node
) {
456 hw_desc
= iter
->hw_desc
;
457 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
461 /* This is a ZERO_SUM operation:
462 * - <src_cnt> descriptors starting from 2nd or 3rd
463 * descriptor are for GF-XOR operations;
464 * - remaining <dst_cnt> descriptors are for checking the result
467 /* MV_SG1_SG2 if only Q is being verified
468 * MULTICAST if both P and Q are being verified
472 /* DMA_CDB_OPC_DCHECK128 operation */
473 hw_desc
->opc
= DMA_CDB_OPC_DCHECK128
;
475 if (likely(!list_is_last(&iter
->chain_node
,
476 &desc
->group_list
))) {
477 /* set 'next' pointer */
478 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
479 struct ppc440spe_adma_desc_slot
,
482 /* this is the last descriptor.
483 * this slot will be pasted from ADMA level
484 * each time it wants to configure parameters
485 * of the transaction (src, dst, ...)
487 iter
->hw_next
= NULL
;
488 /* always enable interrupt generation since we get
489 * the status of pqzero from the handler
491 set_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
494 desc
->src_cnt
= src_cnt
;
495 desc
->dst_cnt
= dst_cnt
;
499 * ppc440spe_desc_init_memcpy - initialize the descriptor for MEMCPY operation
501 static void ppc440spe_desc_init_memcpy(struct ppc440spe_adma_desc_slot
*desc
,
504 struct dma_cdb
*hw_desc
= desc
->hw_desc
;
506 memset(desc
->hw_desc
, 0, sizeof(struct dma_cdb
));
507 desc
->hw_next
= NULL
;
511 if (flags
& DMA_PREP_INTERRUPT
)
512 set_bit(PPC440SPE_DESC_INT
, &desc
->flags
);
514 clear_bit(PPC440SPE_DESC_INT
, &desc
->flags
);
516 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
520 * ppc440spe_desc_set_src_addr - set source address into the descriptor
522 static void ppc440spe_desc_set_src_addr(struct ppc440spe_adma_desc_slot
*desc
,
523 struct ppc440spe_adma_chan
*chan
,
524 int src_idx
, dma_addr_t addrh
,
527 struct dma_cdb
*dma_hw_desc
;
528 struct xor_cb
*xor_hw_desc
;
529 phys_addr_t addr64
, tmplow
, tmphi
;
531 switch (chan
->device
->id
) {
532 case PPC440SPE_DMA0_ID
:
533 case PPC440SPE_DMA1_ID
:
536 tmphi
= (addr64
>> 32);
537 tmplow
= (addr64
& 0xFFFFFFFF);
542 dma_hw_desc
= desc
->hw_desc
;
543 dma_hw_desc
->sg1l
= cpu_to_le32((u32
)tmplow
);
544 dma_hw_desc
->sg1u
|= cpu_to_le32((u32
)tmphi
);
546 case PPC440SPE_XOR_ID
:
547 xor_hw_desc
= desc
->hw_desc
;
548 xor_hw_desc
->ops
[src_idx
].l
= addrl
;
549 xor_hw_desc
->ops
[src_idx
].h
|= addrh
;
555 * ppc440spe_desc_set_src_mult - set source address mult into the descriptor
557 static void ppc440spe_desc_set_src_mult(struct ppc440spe_adma_desc_slot
*desc
,
558 struct ppc440spe_adma_chan
*chan
, u32 mult_index
,
559 int sg_index
, unsigned char mult_value
)
561 struct dma_cdb
*dma_hw_desc
;
564 switch (chan
->device
->id
) {
565 case PPC440SPE_DMA0_ID
:
566 case PPC440SPE_DMA1_ID
:
567 dma_hw_desc
= desc
->hw_desc
;
570 /* for RXOR operations set multiplier
571 * into source cued address
574 psgu
= &dma_hw_desc
->sg1u
;
576 /* for WXOR operations set multiplier
577 * into destination cued address(es)
579 case DMA_CDB_SG_DST1
:
580 psgu
= &dma_hw_desc
->sg2u
;
582 case DMA_CDB_SG_DST2
:
583 psgu
= &dma_hw_desc
->sg3u
;
589 *psgu
|= cpu_to_le32(mult_value
<< mult_index
);
591 case PPC440SPE_XOR_ID
:
599 * ppc440spe_desc_set_dest_addr - set destination address into the descriptor
601 static void ppc440spe_desc_set_dest_addr(struct ppc440spe_adma_desc_slot
*desc
,
602 struct ppc440spe_adma_chan
*chan
,
603 dma_addr_t addrh
, dma_addr_t addrl
,
606 struct dma_cdb
*dma_hw_desc
;
607 struct xor_cb
*xor_hw_desc
;
608 phys_addr_t addr64
, tmphi
, tmplow
;
611 switch (chan
->device
->id
) {
612 case PPC440SPE_DMA0_ID
:
613 case PPC440SPE_DMA1_ID
:
616 tmphi
= (addr64
>> 32);
617 tmplow
= (addr64
& 0xFFFFFFFF);
622 dma_hw_desc
= desc
->hw_desc
;
624 psgu
= dst_idx
? &dma_hw_desc
->sg3u
: &dma_hw_desc
->sg2u
;
625 psgl
= dst_idx
? &dma_hw_desc
->sg3l
: &dma_hw_desc
->sg2l
;
627 *psgl
= cpu_to_le32((u32
)tmplow
);
628 *psgu
|= cpu_to_le32((u32
)tmphi
);
630 case PPC440SPE_XOR_ID
:
631 xor_hw_desc
= desc
->hw_desc
;
632 xor_hw_desc
->cbtal
= addrl
;
633 xor_hw_desc
->cbtah
|= addrh
;
639 * ppc440spe_desc_set_byte_count - set number of data bytes involved
642 static void ppc440spe_desc_set_byte_count(struct ppc440spe_adma_desc_slot
*desc
,
643 struct ppc440spe_adma_chan
*chan
,
646 struct dma_cdb
*dma_hw_desc
;
647 struct xor_cb
*xor_hw_desc
;
649 switch (chan
->device
->id
) {
650 case PPC440SPE_DMA0_ID
:
651 case PPC440SPE_DMA1_ID
:
652 dma_hw_desc
= desc
->hw_desc
;
653 dma_hw_desc
->cnt
= cpu_to_le32(byte_count
);
655 case PPC440SPE_XOR_ID
:
656 xor_hw_desc
= desc
->hw_desc
;
657 xor_hw_desc
->cbbc
= byte_count
;
663 * ppc440spe_desc_set_rxor_block_size - set RXOR block size
665 static inline void ppc440spe_desc_set_rxor_block_size(u32 byte_count
)
667 /* assume that byte_count is aligned on the 512-boundary;
668 * thus write it directly to the register (bits 23:31 are
671 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_CF2H
, byte_count
);
675 * ppc440spe_desc_set_dcheck - set CHECK pattern
677 static void ppc440spe_desc_set_dcheck(struct ppc440spe_adma_desc_slot
*desc
,
678 struct ppc440spe_adma_chan
*chan
, u8
*qword
)
680 struct dma_cdb
*dma_hw_desc
;
682 switch (chan
->device
->id
) {
683 case PPC440SPE_DMA0_ID
:
684 case PPC440SPE_DMA1_ID
:
685 dma_hw_desc
= desc
->hw_desc
;
686 iowrite32(qword
[0], &dma_hw_desc
->sg3l
);
687 iowrite32(qword
[4], &dma_hw_desc
->sg3u
);
688 iowrite32(qword
[8], &dma_hw_desc
->sg2l
);
689 iowrite32(qword
[12], &dma_hw_desc
->sg2u
);
697 * ppc440spe_xor_set_link - set link address in xor CB
699 static void ppc440spe_xor_set_link(struct ppc440spe_adma_desc_slot
*prev_desc
,
700 struct ppc440spe_adma_desc_slot
*next_desc
)
702 struct xor_cb
*xor_hw_desc
= prev_desc
->hw_desc
;
704 if (unlikely(!next_desc
|| !(next_desc
->phys
))) {
705 printk(KERN_ERR
"%s: next_desc=0x%p; next_desc->phys=0x%llx\n",
707 next_desc
? next_desc
->phys
: 0);
711 xor_hw_desc
->cbs
= 0;
712 xor_hw_desc
->cblal
= next_desc
->phys
;
713 xor_hw_desc
->cblah
= 0;
714 xor_hw_desc
->cbc
|= XOR_CBCR_LNK_BIT
;
718 * ppc440spe_desc_set_link - set the address of descriptor following this
719 * descriptor in chain
721 static void ppc440spe_desc_set_link(struct ppc440spe_adma_chan
*chan
,
722 struct ppc440spe_adma_desc_slot
*prev_desc
,
723 struct ppc440spe_adma_desc_slot
*next_desc
)
726 struct ppc440spe_adma_desc_slot
*tail
= next_desc
;
728 if (unlikely(!prev_desc
|| !next_desc
||
729 (prev_desc
->hw_next
&& prev_desc
->hw_next
!= next_desc
))) {
730 /* If previous next is overwritten something is wrong.
731 * though we may refetch from append to initiate list
732 * processing; in this case - it's ok.
734 printk(KERN_ERR
"%s: prev_desc=0x%p; next_desc=0x%p; "
735 "prev->hw_next=0x%p\n", __func__
, prev_desc
,
736 next_desc
, prev_desc
? prev_desc
->hw_next
: 0);
740 local_irq_save(flags
);
742 /* do s/w chaining both for DMA and XOR descriptors */
743 prev_desc
->hw_next
= next_desc
;
745 switch (chan
->device
->id
) {
746 case PPC440SPE_DMA0_ID
:
747 case PPC440SPE_DMA1_ID
:
749 case PPC440SPE_XOR_ID
:
750 /* bind descriptor to the chain */
751 while (tail
->hw_next
)
752 tail
= tail
->hw_next
;
753 xor_last_linked
= tail
;
755 if (prev_desc
== xor_last_submit
)
756 /* do not link to the last submitted CB */
758 ppc440spe_xor_set_link(prev_desc
, next_desc
);
762 local_irq_restore(flags
);
766 * ppc440spe_desc_get_link - get the address of the descriptor that
769 static inline u32
ppc440spe_desc_get_link(struct ppc440spe_adma_desc_slot
*desc
,
770 struct ppc440spe_adma_chan
*chan
)
775 return desc
->hw_next
->phys
;
779 * ppc440spe_desc_is_aligned - check alignment
781 static inline int ppc440spe_desc_is_aligned(
782 struct ppc440spe_adma_desc_slot
*desc
, int num_slots
)
784 return (desc
->idx
& (num_slots
- 1)) ? 0 : 1;
788 * ppc440spe_chan_xor_slot_count - get the number of slots necessary for
791 static int ppc440spe_chan_xor_slot_count(size_t len
, int src_cnt
,
796 /* each XOR descriptor provides up to 16 source operands */
797 slot_cnt
= *slots_per_op
= (src_cnt
+ XOR_MAX_OPS
- 1)/XOR_MAX_OPS
;
799 if (likely(len
<= PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT
))
802 printk(KERN_ERR
"%s: len %d > max %d !!\n",
803 __func__
, len
, PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT
);
809 * ppc440spe_dma2_pq_slot_count - get the number of slots necessary for
812 static int ppc440spe_dma2_pq_slot_count(dma_addr_t
*srcs
,
813 int src_cnt
, size_t len
)
815 signed long long order
= 0;
819 for (i
= 1; i
< src_cnt
; i
++) {
820 dma_addr_t cur_addr
= srcs
[i
];
821 dma_addr_t old_addr
= srcs
[i
-1];
824 if (cur_addr
== old_addr
+ len
) {
830 } else if (old_addr
== cur_addr
+ len
) {
841 if (i
== src_cnt
-2 || (order
== -1
842 && cur_addr
!= old_addr
- len
)) {
846 } else if (cur_addr
== old_addr
+ len
*order
) {
850 } else if (cur_addr
== old_addr
+ 2*len
) {
854 } else if (cur_addr
== old_addr
+ 3*len
) {
873 if (src_cnt
<= 1 || (state
!= 1 && state
!= 2)) {
874 pr_err("%s: src_cnt=%d, state=%d, addr_count=%d, order=%lld\n",
875 __func__
, src_cnt
, state
, addr_count
, order
);
876 for (i
= 0; i
< src_cnt
; i
++)
877 pr_err("\t[%d] 0x%llx \n", i
, srcs
[i
]);
881 return (addr_count
+ XOR_MAX_OPS
- 1) / XOR_MAX_OPS
;
885 /******************************************************************************
886 * ADMA channel low-level routines
887 ******************************************************************************/
890 ppc440spe_chan_get_current_descriptor(struct ppc440spe_adma_chan
*chan
);
891 static void ppc440spe_chan_append(struct ppc440spe_adma_chan
*chan
);
894 * ppc440spe_adma_device_clear_eot_status - interrupt ack to XOR or DMA engine
896 static void ppc440spe_adma_device_clear_eot_status(
897 struct ppc440spe_adma_chan
*chan
)
899 struct dma_regs
*dma_reg
;
900 struct xor_regs
*xor_reg
;
901 u8
*p
= chan
->device
->dma_desc_pool_virt
;
905 switch (chan
->device
->id
) {
906 case PPC440SPE_DMA0_ID
:
907 case PPC440SPE_DMA1_ID
:
908 /* read FIFO to ack */
909 dma_reg
= chan
->device
->dma_reg
;
910 while ((rv
= ioread32(&dma_reg
->csfpl
))) {
911 i
= rv
& DMA_CDB_ADDR_MSK
;
912 cdb
= (struct dma_cdb
*)&p
[i
-
913 (u32
)chan
->device
->dma_desc_pool
];
915 /* Clear opcode to ack. This is necessary for
916 * ZeroSum operations only
920 if (test_bit(PPC440SPE_RXOR_RUN
,
921 &ppc440spe_rxor_state
)) {
922 /* probably this is a completed RXOR op,
923 * get pointer to CDB using the fact that
924 * physical and virtual addresses of CDB
925 * in pools have the same offsets
927 if (le32_to_cpu(cdb
->sg1u
) &
930 clear_bit(PPC440SPE_RXOR_RUN
,
931 &ppc440spe_rxor_state
);
935 if (rv
& DMA_CDB_STATUS_MSK
) {
936 /* ZeroSum check failed
938 struct ppc440spe_adma_desc_slot
*iter
;
939 dma_addr_t phys
= rv
& ~DMA_CDB_MSK
;
942 * Update the status of corresponding
945 list_for_each_entry(iter
, &chan
->chain
,
947 if (iter
->phys
== phys
)
951 * if cannot find the corresponding
954 BUG_ON(&iter
->chain_node
== &chan
->chain
);
956 if (iter
->xor_check_result
) {
957 if (test_bit(PPC440SPE_DESC_PCHECK
,
959 *iter
->xor_check_result
|=
962 if (test_bit(PPC440SPE_DESC_QCHECK
,
964 *iter
->xor_check_result
|=
972 rv
= ioread32(&dma_reg
->dsts
);
974 pr_err("DMA%d err status: 0x%x\n",
975 chan
->device
->id
, rv
);
976 /* write back to clear */
977 iowrite32(rv
, &dma_reg
->dsts
);
980 case PPC440SPE_XOR_ID
:
981 /* reset status bits to ack */
982 xor_reg
= chan
->device
->xor_reg
;
983 rv
= ioread32be(&xor_reg
->sr
);
984 iowrite32be(rv
, &xor_reg
->sr
);
986 if (rv
& (XOR_IE_ICBIE_BIT
|XOR_IE_ICIE_BIT
|XOR_IE_RPTIE_BIT
)) {
987 if (rv
& XOR_IE_RPTIE_BIT
) {
988 /* Read PLB Timeout Error.
989 * Try to resubmit the CB
991 u32 val
= ioread32be(&xor_reg
->ccbalr
);
993 iowrite32be(val
, &xor_reg
->cblalr
);
995 val
= ioread32be(&xor_reg
->crsr
);
996 iowrite32be(val
| XOR_CRSR_XAE_BIT
,
999 pr_err("XOR ERR 0x%x status\n", rv
);
1003 /* if the XORcore is idle, but there are unprocessed CBs
1004 * then refetch the s/w chain here
1006 if (!(ioread32be(&xor_reg
->sr
) & XOR_SR_XCP_BIT
) &&
1008 ppc440spe_chan_append(chan
);
1014 * ppc440spe_chan_is_busy - get the channel status
1016 static int ppc440spe_chan_is_busy(struct ppc440spe_adma_chan
*chan
)
1018 struct dma_regs
*dma_reg
;
1019 struct xor_regs
*xor_reg
;
1022 switch (chan
->device
->id
) {
1023 case PPC440SPE_DMA0_ID
:
1024 case PPC440SPE_DMA1_ID
:
1025 dma_reg
= chan
->device
->dma_reg
;
1026 /* if command FIFO's head and tail pointers are equal and
1027 * status tail is the same as command, then channel is free
1029 if (ioread16(&dma_reg
->cpfhp
) != ioread16(&dma_reg
->cpftp
) ||
1030 ioread16(&dma_reg
->cpftp
) != ioread16(&dma_reg
->csftp
))
1033 case PPC440SPE_XOR_ID
:
1034 /* use the special status bit for the XORcore
1036 xor_reg
= chan
->device
->xor_reg
;
1037 busy
= (ioread32be(&xor_reg
->sr
) & XOR_SR_XCP_BIT
) ? 1 : 0;
1045 * ppc440spe_chan_set_first_xor_descriptor - init XORcore chain
1047 static void ppc440spe_chan_set_first_xor_descriptor(
1048 struct ppc440spe_adma_chan
*chan
,
1049 struct ppc440spe_adma_desc_slot
*next_desc
)
1051 struct xor_regs
*xor_reg
= chan
->device
->xor_reg
;
1053 if (ioread32be(&xor_reg
->sr
) & XOR_SR_XCP_BIT
)
1054 printk(KERN_INFO
"%s: Warn: XORcore is running "
1055 "when try to set the first CDB!\n",
1058 xor_last_submit
= xor_last_linked
= next_desc
;
1060 iowrite32be(XOR_CRSR_64BA_BIT
, &xor_reg
->crsr
);
1062 iowrite32be(next_desc
->phys
, &xor_reg
->cblalr
);
1063 iowrite32be(0, &xor_reg
->cblahr
);
1064 iowrite32be(ioread32be(&xor_reg
->cbcr
) | XOR_CBCR_LNK_BIT
,
1067 chan
->hw_chain_inited
= 1;
1071 * ppc440spe_dma_put_desc - put DMA0,1 descriptor to FIFO.
1072 * called with irqs disabled
1074 static void ppc440spe_dma_put_desc(struct ppc440spe_adma_chan
*chan
,
1075 struct ppc440spe_adma_desc_slot
*desc
)
1078 struct dma_regs
*dma_reg
= chan
->device
->dma_reg
;
1081 if (!test_bit(PPC440SPE_DESC_INT
, &desc
->flags
))
1082 pcdb
|= DMA_CDB_NO_INT
;
1084 chan_last_sub
[chan
->device
->id
] = desc
;
1086 ADMA_LL_DBG(print_cb(chan
, desc
->hw_desc
));
1088 iowrite32(pcdb
, &dma_reg
->cpfpl
);
1092 * ppc440spe_chan_append - update the h/w chain in the channel
1094 static void ppc440spe_chan_append(struct ppc440spe_adma_chan
*chan
)
1096 struct xor_regs
*xor_reg
;
1097 struct ppc440spe_adma_desc_slot
*iter
;
1100 unsigned long flags
;
1102 local_irq_save(flags
);
1104 switch (chan
->device
->id
) {
1105 case PPC440SPE_DMA0_ID
:
1106 case PPC440SPE_DMA1_ID
:
1107 cur_desc
= ppc440spe_chan_get_current_descriptor(chan
);
1109 if (likely(cur_desc
)) {
1110 iter
= chan_last_sub
[chan
->device
->id
];
1114 iter
= chan_first_cdb
[chan
->device
->id
];
1116 ppc440spe_dma_put_desc(chan
, iter
);
1117 chan
->hw_chain_inited
= 1;
1120 /* is there something new to append */
1124 /* flush descriptors from the s/w queue to fifo */
1125 list_for_each_entry_continue(iter
, &chan
->chain
, chain_node
) {
1126 ppc440spe_dma_put_desc(chan
, iter
);
1131 case PPC440SPE_XOR_ID
:
1132 /* update h/w links and refetch */
1133 if (!xor_last_submit
->hw_next
)
1136 xor_reg
= chan
->device
->xor_reg
;
1137 /* the last linked CDB has to generate an interrupt
1138 * that we'd be able to append the next lists to h/w
1139 * regardless of the XOR engine state at the moment of
1140 * appending of these next lists
1142 xcb
= xor_last_linked
->hw_desc
;
1143 xcb
->cbc
|= XOR_CBCR_CBCE_BIT
;
1145 if (!(ioread32be(&xor_reg
->sr
) & XOR_SR_XCP_BIT
)) {
1146 /* XORcore is idle. Refetch now */
1148 ppc440spe_xor_set_link(xor_last_submit
,
1149 xor_last_submit
->hw_next
);
1151 ADMA_LL_DBG(print_cb_list(chan
,
1152 xor_last_submit
->hw_next
));
1154 xor_last_submit
= xor_last_linked
;
1155 iowrite32be(ioread32be(&xor_reg
->crsr
) |
1156 XOR_CRSR_RCBE_BIT
| XOR_CRSR_64BA_BIT
,
1159 /* XORcore is running. Refetch later in the handler */
1166 local_irq_restore(flags
);
1170 * ppc440spe_chan_get_current_descriptor - get the currently executed descriptor
1173 ppc440spe_chan_get_current_descriptor(struct ppc440spe_adma_chan
*chan
)
1175 struct dma_regs
*dma_reg
;
1176 struct xor_regs
*xor_reg
;
1178 if (unlikely(!chan
->hw_chain_inited
))
1179 /* h/w descriptor chain is not initialized yet */
1182 switch (chan
->device
->id
) {
1183 case PPC440SPE_DMA0_ID
:
1184 case PPC440SPE_DMA1_ID
:
1185 dma_reg
= chan
->device
->dma_reg
;
1186 return ioread32(&dma_reg
->acpl
) & (~DMA_CDB_MSK
);
1187 case PPC440SPE_XOR_ID
:
1188 xor_reg
= chan
->device
->xor_reg
;
1189 return ioread32be(&xor_reg
->ccbalr
);
1195 * ppc440spe_chan_run - enable the channel
1197 static void ppc440spe_chan_run(struct ppc440spe_adma_chan
*chan
)
1199 struct xor_regs
*xor_reg
;
1201 switch (chan
->device
->id
) {
1202 case PPC440SPE_DMA0_ID
:
1203 case PPC440SPE_DMA1_ID
:
1204 /* DMAs are always enabled, do nothing */
1206 case PPC440SPE_XOR_ID
:
1207 /* drain write buffer */
1208 xor_reg
= chan
->device
->xor_reg
;
1210 /* fetch descriptor pointed to in <link> */
1211 iowrite32be(XOR_CRSR_64BA_BIT
| XOR_CRSR_XAE_BIT
,
1217 /******************************************************************************
1219 ******************************************************************************/
1221 static void ppc440spe_chan_start_null_xor(struct ppc440spe_adma_chan
*chan
);
1222 static int ppc440spe_adma_alloc_chan_resources(struct dma_chan
*chan
);
1225 ppc440spe_adma_tx_submit(struct dma_async_tx_descriptor
*tx
);
1227 static void ppc440spe_adma_set_dest(struct ppc440spe_adma_desc_slot
*tx
,
1228 dma_addr_t addr
, int index
);
1230 ppc440spe_adma_memcpy_xor_set_src(struct ppc440spe_adma_desc_slot
*tx
,
1231 dma_addr_t addr
, int index
);
1234 ppc440spe_adma_pq_set_dest(struct ppc440spe_adma_desc_slot
*tx
,
1235 dma_addr_t
*paddr
, unsigned long flags
);
1237 ppc440spe_adma_pq_set_src(struct ppc440spe_adma_desc_slot
*tx
,
1238 dma_addr_t addr
, int index
);
1240 ppc440spe_adma_pq_set_src_mult(struct ppc440spe_adma_desc_slot
*tx
,
1241 unsigned char mult
, int index
, int dst_pos
);
1243 ppc440spe_adma_pqzero_sum_set_dest(struct ppc440spe_adma_desc_slot
*tx
,
1244 dma_addr_t paddr
, dma_addr_t qaddr
);
1246 static struct page
*ppc440spe_rxor_srcs
[32];
1249 * ppc440spe_can_rxor - check if the operands may be processed with RXOR
1251 static int ppc440spe_can_rxor(struct page
**srcs
, int src_cnt
, size_t len
)
1253 int i
, order
= 0, state
= 0;
1256 if (unlikely(!(src_cnt
> 1)))
1259 BUG_ON(src_cnt
> ARRAY_SIZE(ppc440spe_rxor_srcs
));
1261 /* Skip holes in the source list before checking */
1262 for (i
= 0; i
< src_cnt
; i
++) {
1265 ppc440spe_rxor_srcs
[idx
++] = srcs
[i
];
1269 for (i
= 1; i
< src_cnt
; i
++) {
1270 char *cur_addr
= page_address(ppc440spe_rxor_srcs
[i
]);
1271 char *old_addr
= page_address(ppc440spe_rxor_srcs
[i
- 1]);
1275 if (cur_addr
== old_addr
+ len
) {
1279 } else if (old_addr
== cur_addr
+ len
) {
1287 if ((i
== src_cnt
- 2) ||
1288 (order
== -1 && cur_addr
!= old_addr
- len
)) {
1291 } else if ((cur_addr
== old_addr
+ len
* order
) ||
1292 (cur_addr
== old_addr
+ 2 * len
) ||
1293 (cur_addr
== old_addr
+ 3 * len
)) {
1308 if (state
== 1 || state
== 2)
1315 * ppc440spe_adma_device_estimate - estimate the efficiency of processing
1316 * the operation given on this channel. It's assumed that 'chan' is
1317 * capable to process 'cap' type of operation.
1318 * @chan: channel to use
1319 * @cap: type of transaction
1320 * @dst_lst: array of destination pointers
1321 * @dst_cnt: number of destination operands
1322 * @src_lst: array of source pointers
1323 * @src_cnt: number of source operands
1324 * @src_sz: size of each source operand
1326 static int ppc440spe_adma_estimate(struct dma_chan
*chan
,
1327 enum dma_transaction_type cap
, struct page
**dst_lst
, int dst_cnt
,
1328 struct page
**src_lst
, int src_cnt
, size_t src_sz
)
1332 if (cap
== DMA_PQ
|| cap
== DMA_PQ_VAL
) {
1333 /* If RAID-6 capabilities were not activated don't try
1336 if (unlikely(!ppc440spe_r6_enabled
))
1339 /* In the current implementation of ppc440spe ADMA driver it
1340 * makes sense to pick out only pq case, because it may be
1342 * (1) either using Biskup method on DMA2;
1344 * Thus we give a favour to (1) if the sources are suitable;
1345 * else let it be processed on one of the DMA0/1 engines.
1346 * In the sum_product case where destination is also the
1347 * source process it on DMA0/1 only.
1349 if (cap
== DMA_PQ
&& chan
->chan_id
== PPC440SPE_XOR_ID
) {
1351 if (dst_cnt
== 1 && src_cnt
== 2 && dst_lst
[0] == src_lst
[1])
1352 ef
= 0; /* sum_product case, process on DMA0/1 */
1353 else if (ppc440spe_can_rxor(src_lst
, src_cnt
, src_sz
))
1354 ef
= 3; /* override (DMA0/1 + idle) */
1356 ef
= 0; /* can't process on DMA2 if !rxor */
1359 /* channel idleness increases the priority */
1361 !ppc440spe_chan_is_busy(to_ppc440spe_adma_chan(chan
)))
1368 ppc440spe_async_tx_find_best_channel(enum dma_transaction_type cap
,
1369 struct page
**dst_lst
, int dst_cnt
, struct page
**src_lst
,
1370 int src_cnt
, size_t src_sz
)
1372 struct dma_chan
*best_chan
= NULL
;
1373 struct ppc_dma_chan_ref
*ref
;
1376 if (unlikely(!src_sz
))
1378 if (src_sz
> PAGE_SIZE
) {
1380 * should a user of the api ever pass > PAGE_SIZE requests
1381 * we sort out cases where temporary page-sized buffers
1386 if (src_cnt
== 1 && dst_lst
[1] == src_lst
[0])
1388 if (src_cnt
== 2 && dst_lst
[1] == src_lst
[1])
1399 list_for_each_entry(ref
, &ppc440spe_adma_chan_list
, node
) {
1400 if (dma_has_cap(cap
, ref
->chan
->device
->cap_mask
)) {
1403 rank
= ppc440spe_adma_estimate(ref
->chan
, cap
, dst_lst
,
1404 dst_cnt
, src_lst
, src_cnt
, src_sz
);
1405 if (rank
> best_rank
) {
1407 best_chan
= ref
->chan
;
1414 EXPORT_SYMBOL_GPL(ppc440spe_async_tx_find_best_channel
);
1417 * ppc440spe_get_group_entry - get group entry with index idx
1418 * @tdesc: is the last allocated slot in the group.
1420 static struct ppc440spe_adma_desc_slot
*
1421 ppc440spe_get_group_entry(struct ppc440spe_adma_desc_slot
*tdesc
, u32 entry_idx
)
1423 struct ppc440spe_adma_desc_slot
*iter
= tdesc
->group_head
;
1426 if (entry_idx
< 0 || entry_idx
>= (tdesc
->src_cnt
+ tdesc
->dst_cnt
)) {
1427 printk("%s: entry_idx %d, src_cnt %d, dst_cnt %d\n",
1428 __func__
, entry_idx
, tdesc
->src_cnt
, tdesc
->dst_cnt
);
1432 list_for_each_entry(iter
, &tdesc
->group_list
, chain_node
) {
1433 if (i
++ == entry_idx
)
1440 * ppc440spe_adma_free_slots - flags descriptor slots for reuse
1441 * @slot: Slot to free
1442 * Caller must hold &ppc440spe_chan->lock while calling this function
1444 static void ppc440spe_adma_free_slots(struct ppc440spe_adma_desc_slot
*slot
,
1445 struct ppc440spe_adma_chan
*chan
)
1447 int stride
= slot
->slots_per_op
;
1450 slot
->slots_per_op
= 0;
1451 slot
= list_entry(slot
->slot_node
.next
,
1452 struct ppc440spe_adma_desc_slot
,
1458 * ppc440spe_adma_run_tx_complete_actions - call functions to be called
1461 static dma_cookie_t
ppc440spe_adma_run_tx_complete_actions(
1462 struct ppc440spe_adma_desc_slot
*desc
,
1463 struct ppc440spe_adma_chan
*chan
,
1464 dma_cookie_t cookie
)
1466 BUG_ON(desc
->async_tx
.cookie
< 0);
1467 if (desc
->async_tx
.cookie
> 0) {
1468 cookie
= desc
->async_tx
.cookie
;
1469 desc
->async_tx
.cookie
= 0;
1471 dma_descriptor_unmap(&desc
->async_tx
);
1472 /* call the callback (must not sleep or submit new
1473 * operations to this channel)
1475 dmaengine_desc_get_callback_invoke(&desc
->async_tx
, NULL
);
1478 /* run dependent operations */
1479 dma_run_dependencies(&desc
->async_tx
);
1485 * ppc440spe_adma_clean_slot - clean up CDB slot (if ack is set)
1487 static int ppc440spe_adma_clean_slot(struct ppc440spe_adma_desc_slot
*desc
,
1488 struct ppc440spe_adma_chan
*chan
)
1490 /* the client is allowed to attach dependent operations
1491 * until 'ack' is set
1493 if (!async_tx_test_ack(&desc
->async_tx
))
1496 /* leave the last descriptor in the chain
1497 * so we can append to it
1499 if (list_is_last(&desc
->chain_node
, &chan
->chain
) ||
1500 desc
->phys
== ppc440spe_chan_get_current_descriptor(chan
))
1503 if (chan
->device
->id
!= PPC440SPE_XOR_ID
) {
1504 /* our DMA interrupt handler clears opc field of
1505 * each processed descriptor. For all types of
1506 * operations except for ZeroSum we do not actually
1507 * need ack from the interrupt handler. ZeroSum is a
1508 * special case since the result of this operation
1509 * is available from the handler only, so if we see
1510 * such type of descriptor (which is unprocessed yet)
1511 * then leave it in chain.
1513 struct dma_cdb
*cdb
= desc
->hw_desc
;
1514 if (cdb
->opc
== DMA_CDB_OPC_DCHECK128
)
1518 dev_dbg(chan
->device
->common
.dev
, "\tfree slot %llx: %d stride: %d\n",
1519 desc
->phys
, desc
->idx
, desc
->slots_per_op
);
1521 list_del(&desc
->chain_node
);
1522 ppc440spe_adma_free_slots(desc
, chan
);
1527 * __ppc440spe_adma_slot_cleanup - this is the common clean-up routine
1528 * which runs through the channel CDBs list until reach the descriptor
1529 * currently processed. When routine determines that all CDBs of group
1530 * are completed then corresponding callbacks (if any) are called and slots
1533 static void __ppc440spe_adma_slot_cleanup(struct ppc440spe_adma_chan
*chan
)
1535 struct ppc440spe_adma_desc_slot
*iter
, *_iter
, *group_start
= NULL
;
1536 dma_cookie_t cookie
= 0;
1537 u32 current_desc
= ppc440spe_chan_get_current_descriptor(chan
);
1538 int busy
= ppc440spe_chan_is_busy(chan
);
1539 int seen_current
= 0, slot_cnt
= 0, slots_per_op
= 0;
1541 dev_dbg(chan
->device
->common
.dev
, "ppc440spe adma%d: %s\n",
1542 chan
->device
->id
, __func__
);
1544 if (!current_desc
) {
1545 /* There were no transactions yet, so
1551 /* free completed slots from the chain starting with
1552 * the oldest descriptor
1554 list_for_each_entry_safe(iter
, _iter
, &chan
->chain
,
1556 dev_dbg(chan
->device
->common
.dev
, "\tcookie: %d slot: %d "
1557 "busy: %d this_desc: %#llx next_desc: %#x "
1558 "cur: %#x ack: %d\n",
1559 iter
->async_tx
.cookie
, iter
->idx
, busy
, iter
->phys
,
1560 ppc440spe_desc_get_link(iter
, chan
), current_desc
,
1561 async_tx_test_ack(&iter
->async_tx
));
1563 prefetch(&_iter
->async_tx
);
1565 /* do not advance past the current descriptor loaded into the
1566 * hardware channel,subsequent descriptors are either in process
1567 * or have not been submitted
1572 /* stop the search if we reach the current descriptor and the
1573 * channel is busy, or if it appears that the current descriptor
1574 * needs to be re-read (i.e. has been appended to)
1576 if (iter
->phys
== current_desc
) {
1577 BUG_ON(seen_current
++);
1578 if (busy
|| ppc440spe_desc_get_link(iter
, chan
)) {
1579 /* not all descriptors of the group have
1580 * been completed; exit.
1586 /* detect the start of a group transaction */
1587 if (!slot_cnt
&& !slots_per_op
) {
1588 slot_cnt
= iter
->slot_cnt
;
1589 slots_per_op
= iter
->slots_per_op
;
1590 if (slot_cnt
<= slots_per_op
) {
1599 slot_cnt
-= slots_per_op
;
1602 /* all the members of a group are complete */
1603 if (slots_per_op
!= 0 && slot_cnt
== 0) {
1604 struct ppc440spe_adma_desc_slot
*grp_iter
, *_grp_iter
;
1605 int end_of_chain
= 0;
1607 /* clean up the group */
1608 slot_cnt
= group_start
->slot_cnt
;
1609 grp_iter
= group_start
;
1610 list_for_each_entry_safe_from(grp_iter
, _grp_iter
,
1611 &chan
->chain
, chain_node
) {
1613 cookie
= ppc440spe_adma_run_tx_complete_actions(
1614 grp_iter
, chan
, cookie
);
1616 slot_cnt
-= slots_per_op
;
1617 end_of_chain
= ppc440spe_adma_clean_slot(
1619 if (end_of_chain
&& slot_cnt
) {
1620 /* Should wait for ZeroSum completion */
1622 chan
->common
.completed_cookie
= cookie
;
1626 if (slot_cnt
== 0 || end_of_chain
)
1630 /* the group should be complete at this point */
1639 } else if (slots_per_op
) /* wait for group completion */
1642 cookie
= ppc440spe_adma_run_tx_complete_actions(iter
, chan
,
1645 if (ppc440spe_adma_clean_slot(iter
, chan
))
1649 BUG_ON(!seen_current
);
1652 chan
->common
.completed_cookie
= cookie
;
1653 pr_debug("\tcompleted cookie %d\n", cookie
);
1659 * ppc440spe_adma_tasklet - clean up watch-dog initiator
1661 static void ppc440spe_adma_tasklet(struct tasklet_struct
*t
)
1663 struct ppc440spe_adma_chan
*chan
= from_tasklet(chan
, t
, irq_tasklet
);
1665 spin_lock_nested(&chan
->lock
, SINGLE_DEPTH_NESTING
);
1666 __ppc440spe_adma_slot_cleanup(chan
);
1667 spin_unlock(&chan
->lock
);
1671 * ppc440spe_adma_slot_cleanup - clean up scheduled initiator
1673 static void ppc440spe_adma_slot_cleanup(struct ppc440spe_adma_chan
*chan
)
1675 spin_lock_bh(&chan
->lock
);
1676 __ppc440spe_adma_slot_cleanup(chan
);
1677 spin_unlock_bh(&chan
->lock
);
1681 * ppc440spe_adma_alloc_slots - allocate free slots (if any)
1683 static struct ppc440spe_adma_desc_slot
*ppc440spe_adma_alloc_slots(
1684 struct ppc440spe_adma_chan
*chan
, int num_slots
,
1687 struct ppc440spe_adma_desc_slot
*iter
= NULL
, *_iter
;
1688 struct ppc440spe_adma_desc_slot
*alloc_start
= NULL
;
1689 struct list_head chain
= LIST_HEAD_INIT(chain
);
1690 int slots_found
, retry
= 0;
1693 BUG_ON(!num_slots
|| !slots_per_op
);
1694 /* start search from the last allocated descrtiptor
1695 * if a contiguous allocation can not be found start searching
1696 * from the beginning of the list
1701 iter
= chan
->last_used
;
1703 iter
= list_entry(&chan
->all_slots
,
1704 struct ppc440spe_adma_desc_slot
,
1706 list_for_each_entry_safe_continue(iter
, _iter
, &chan
->all_slots
,
1709 prefetch(&_iter
->async_tx
);
1710 if (iter
->slots_per_op
) {
1715 /* start the allocation if the slot is correctly aligned */
1719 if (slots_found
== num_slots
) {
1720 struct ppc440spe_adma_desc_slot
*alloc_tail
= NULL
;
1721 struct ppc440spe_adma_desc_slot
*last_used
= NULL
;
1726 /* pre-ack all but the last descriptor */
1727 if (num_slots
!= slots_per_op
)
1728 async_tx_ack(&iter
->async_tx
);
1730 list_add_tail(&iter
->chain_node
, &chain
);
1732 iter
->async_tx
.cookie
= 0;
1733 iter
->hw_next
= NULL
;
1735 iter
->slot_cnt
= num_slots
;
1736 iter
->xor_check_result
= NULL
;
1737 for (i
= 0; i
< slots_per_op
; i
++) {
1738 iter
->slots_per_op
= slots_per_op
- i
;
1740 iter
= list_entry(iter
->slot_node
.next
,
1741 struct ppc440spe_adma_desc_slot
,
1744 num_slots
-= slots_per_op
;
1746 alloc_tail
->group_head
= alloc_start
;
1747 alloc_tail
->async_tx
.cookie
= -EBUSY
;
1748 list_splice(&chain
, &alloc_tail
->group_list
);
1749 chan
->last_used
= last_used
;
1756 /* try to free some slots if the allocation fails */
1757 tasklet_schedule(&chan
->irq_tasklet
);
1762 * ppc440spe_adma_alloc_chan_resources - allocate pools for CDB slots
1764 static int ppc440spe_adma_alloc_chan_resources(struct dma_chan
*chan
)
1766 struct ppc440spe_adma_chan
*ppc440spe_chan
;
1767 struct ppc440spe_adma_desc_slot
*slot
= NULL
;
1772 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
1773 init
= ppc440spe_chan
->slots_allocated
? 0 : 1;
1774 chan
->chan_id
= ppc440spe_chan
->device
->id
;
1776 /* Allocate descriptor slots */
1777 i
= ppc440spe_chan
->slots_allocated
;
1778 if (ppc440spe_chan
->device
->id
!= PPC440SPE_XOR_ID
)
1779 db_sz
= sizeof(struct dma_cdb
);
1781 db_sz
= sizeof(struct xor_cb
);
1783 for (; i
< (ppc440spe_chan
->device
->pool_size
/ db_sz
); i
++) {
1784 slot
= kzalloc(sizeof(struct ppc440spe_adma_desc_slot
),
1787 printk(KERN_INFO
"SPE ADMA Channel only initialized"
1788 " %d descriptor slots", i
--);
1792 hw_desc
= (char *) ppc440spe_chan
->device
->dma_desc_pool_virt
;
1793 slot
->hw_desc
= (void *) &hw_desc
[i
* db_sz
];
1794 dma_async_tx_descriptor_init(&slot
->async_tx
, chan
);
1795 slot
->async_tx
.tx_submit
= ppc440spe_adma_tx_submit
;
1796 INIT_LIST_HEAD(&slot
->chain_node
);
1797 INIT_LIST_HEAD(&slot
->slot_node
);
1798 INIT_LIST_HEAD(&slot
->group_list
);
1799 slot
->phys
= ppc440spe_chan
->device
->dma_desc_pool
+ i
* db_sz
;
1802 spin_lock_bh(&ppc440spe_chan
->lock
);
1803 ppc440spe_chan
->slots_allocated
++;
1804 list_add_tail(&slot
->slot_node
, &ppc440spe_chan
->all_slots
);
1805 spin_unlock_bh(&ppc440spe_chan
->lock
);
1808 if (i
&& !ppc440spe_chan
->last_used
) {
1809 ppc440spe_chan
->last_used
=
1810 list_entry(ppc440spe_chan
->all_slots
.next
,
1811 struct ppc440spe_adma_desc_slot
,
1815 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
1816 "ppc440spe adma%d: allocated %d descriptor slots\n",
1817 ppc440spe_chan
->device
->id
, i
);
1819 /* initialize the channel and the chain with a null operation */
1821 switch (ppc440spe_chan
->device
->id
) {
1822 case PPC440SPE_DMA0_ID
:
1823 case PPC440SPE_DMA1_ID
:
1824 ppc440spe_chan
->hw_chain_inited
= 0;
1825 /* Use WXOR for self-testing */
1826 if (!ppc440spe_r6_tchan
)
1827 ppc440spe_r6_tchan
= ppc440spe_chan
;
1829 case PPC440SPE_XOR_ID
:
1830 ppc440spe_chan_start_null_xor(ppc440spe_chan
);
1835 ppc440spe_chan
->needs_unmap
= 1;
1838 return (i
> 0) ? i
: -ENOMEM
;
1842 * ppc440spe_rxor_set_region_data -
1844 static void ppc440spe_rxor_set_region(struct ppc440spe_adma_desc_slot
*desc
,
1845 u8 xor_arg_no
, u32 mask
)
1847 struct xor_cb
*xcb
= desc
->hw_desc
;
1849 xcb
->ops
[xor_arg_no
].h
|= mask
;
1853 * ppc440spe_rxor_set_src -
1855 static void ppc440spe_rxor_set_src(struct ppc440spe_adma_desc_slot
*desc
,
1856 u8 xor_arg_no
, dma_addr_t addr
)
1858 struct xor_cb
*xcb
= desc
->hw_desc
;
1860 xcb
->ops
[xor_arg_no
].h
|= DMA_CUED_XOR_BASE
;
1861 xcb
->ops
[xor_arg_no
].l
= addr
;
1865 * ppc440spe_rxor_set_mult -
1867 static void ppc440spe_rxor_set_mult(struct ppc440spe_adma_desc_slot
*desc
,
1868 u8 xor_arg_no
, u8 idx
, u8 mult
)
1870 struct xor_cb
*xcb
= desc
->hw_desc
;
1872 xcb
->ops
[xor_arg_no
].h
|= mult
<< (DMA_CUED_MULT1_OFF
+ idx
* 8);
1876 * ppc440spe_adma_check_threshold - append CDBs to h/w chain if threshold
1879 static void ppc440spe_adma_check_threshold(struct ppc440spe_adma_chan
*chan
)
1881 dev_dbg(chan
->device
->common
.dev
, "ppc440spe adma%d: pending: %d\n",
1882 chan
->device
->id
, chan
->pending
);
1884 if (chan
->pending
>= PPC440SPE_ADMA_THRESHOLD
) {
1886 ppc440spe_chan_append(chan
);
1891 * ppc440spe_adma_tx_submit - submit new descriptor group to the channel
1892 * (it's not necessary that descriptors will be submitted to the h/w
1893 * chains too right now)
1895 static dma_cookie_t
ppc440spe_adma_tx_submit(struct dma_async_tx_descriptor
*tx
)
1897 struct ppc440spe_adma_desc_slot
*sw_desc
;
1898 struct ppc440spe_adma_chan
*chan
= to_ppc440spe_adma_chan(tx
->chan
);
1899 struct ppc440spe_adma_desc_slot
*group_start
, *old_chain_tail
;
1902 dma_cookie_t cookie
;
1904 sw_desc
= tx_to_ppc440spe_adma_slot(tx
);
1906 group_start
= sw_desc
->group_head
;
1907 slot_cnt
= group_start
->slot_cnt
;
1908 slots_per_op
= group_start
->slots_per_op
;
1910 spin_lock_bh(&chan
->lock
);
1911 cookie
= dma_cookie_assign(tx
);
1913 if (unlikely(list_empty(&chan
->chain
))) {
1915 list_splice_init(&sw_desc
->group_list
, &chan
->chain
);
1916 chan_first_cdb
[chan
->device
->id
] = group_start
;
1918 /* isn't first peer, bind CDBs to chain */
1919 old_chain_tail
= list_entry(chan
->chain
.prev
,
1920 struct ppc440spe_adma_desc_slot
,
1922 list_splice_init(&sw_desc
->group_list
,
1923 &old_chain_tail
->chain_node
);
1924 /* fix up the hardware chain */
1925 ppc440spe_desc_set_link(chan
, old_chain_tail
, group_start
);
1928 /* increment the pending count by the number of operations */
1929 chan
->pending
+= slot_cnt
/ slots_per_op
;
1930 ppc440spe_adma_check_threshold(chan
);
1931 spin_unlock_bh(&chan
->lock
);
1933 dev_dbg(chan
->device
->common
.dev
,
1934 "ppc440spe adma%d: %s cookie: %d slot: %d tx %p\n",
1935 chan
->device
->id
, __func__
,
1936 sw_desc
->async_tx
.cookie
, sw_desc
->idx
, sw_desc
);
1942 * ppc440spe_adma_prep_dma_interrupt - prepare CDB for a pseudo DMA operation
1944 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_interrupt(
1945 struct dma_chan
*chan
, unsigned long flags
)
1947 struct ppc440spe_adma_chan
*ppc440spe_chan
;
1948 struct ppc440spe_adma_desc_slot
*sw_desc
, *group_start
;
1949 int slot_cnt
, slots_per_op
;
1951 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
1953 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
1954 "ppc440spe adma%d: %s\n", ppc440spe_chan
->device
->id
,
1957 spin_lock_bh(&ppc440spe_chan
->lock
);
1958 slot_cnt
= slots_per_op
= 1;
1959 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
,
1962 group_start
= sw_desc
->group_head
;
1963 ppc440spe_desc_init_interrupt(group_start
, ppc440spe_chan
);
1964 group_start
->unmap_len
= 0;
1965 sw_desc
->async_tx
.flags
= flags
;
1967 spin_unlock_bh(&ppc440spe_chan
->lock
);
1969 return sw_desc
? &sw_desc
->async_tx
: NULL
;
1973 * ppc440spe_adma_prep_dma_memcpy - prepare CDB for a MEMCPY operation
1975 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_memcpy(
1976 struct dma_chan
*chan
, dma_addr_t dma_dest
,
1977 dma_addr_t dma_src
, size_t len
, unsigned long flags
)
1979 struct ppc440spe_adma_chan
*ppc440spe_chan
;
1980 struct ppc440spe_adma_desc_slot
*sw_desc
, *group_start
;
1981 int slot_cnt
, slots_per_op
;
1983 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
1988 BUG_ON(len
> PPC440SPE_ADMA_DMA_MAX_BYTE_COUNT
);
1990 spin_lock_bh(&ppc440spe_chan
->lock
);
1992 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
1993 "ppc440spe adma%d: %s len: %u int_en %d\n",
1994 ppc440spe_chan
->device
->id
, __func__
, len
,
1995 flags
& DMA_PREP_INTERRUPT
? 1 : 0);
1996 slot_cnt
= slots_per_op
= 1;
1997 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
,
2000 group_start
= sw_desc
->group_head
;
2001 ppc440spe_desc_init_memcpy(group_start
, flags
);
2002 ppc440spe_adma_set_dest(group_start
, dma_dest
, 0);
2003 ppc440spe_adma_memcpy_xor_set_src(group_start
, dma_src
, 0);
2004 ppc440spe_desc_set_byte_count(group_start
, ppc440spe_chan
, len
);
2005 sw_desc
->unmap_len
= len
;
2006 sw_desc
->async_tx
.flags
= flags
;
2008 spin_unlock_bh(&ppc440spe_chan
->lock
);
2010 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2014 * ppc440spe_adma_prep_dma_xor - prepare CDB for a XOR operation
2016 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_xor(
2017 struct dma_chan
*chan
, dma_addr_t dma_dest
,
2018 dma_addr_t
*dma_src
, u32 src_cnt
, size_t len
,
2019 unsigned long flags
)
2021 struct ppc440spe_adma_chan
*ppc440spe_chan
;
2022 struct ppc440spe_adma_desc_slot
*sw_desc
, *group_start
;
2023 int slot_cnt
, slots_per_op
;
2025 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
2027 ADMA_LL_DBG(prep_dma_xor_dbg(ppc440spe_chan
->device
->id
,
2028 dma_dest
, dma_src
, src_cnt
));
2031 BUG_ON(len
> PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT
);
2033 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
2034 "ppc440spe adma%d: %s src_cnt: %d len: %u int_en: %d\n",
2035 ppc440spe_chan
->device
->id
, __func__
, src_cnt
, len
,
2036 flags
& DMA_PREP_INTERRUPT
? 1 : 0);
2038 spin_lock_bh(&ppc440spe_chan
->lock
);
2039 slot_cnt
= ppc440spe_chan_xor_slot_count(len
, src_cnt
, &slots_per_op
);
2040 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
,
2043 group_start
= sw_desc
->group_head
;
2044 ppc440spe_desc_init_xor(group_start
, src_cnt
, flags
);
2045 ppc440spe_adma_set_dest(group_start
, dma_dest
, 0);
2047 ppc440spe_adma_memcpy_xor_set_src(group_start
,
2048 dma_src
[src_cnt
], src_cnt
);
2049 ppc440spe_desc_set_byte_count(group_start
, ppc440spe_chan
, len
);
2050 sw_desc
->unmap_len
= len
;
2051 sw_desc
->async_tx
.flags
= flags
;
2053 spin_unlock_bh(&ppc440spe_chan
->lock
);
2055 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2059 ppc440spe_desc_set_xor_src_cnt(struct ppc440spe_adma_desc_slot
*desc
,
2061 static void ppc440spe_init_rxor_cursor(struct ppc440spe_rxor
*cursor
);
2064 * ppc440spe_adma_init_dma2rxor_slot -
2066 static void ppc440spe_adma_init_dma2rxor_slot(
2067 struct ppc440spe_adma_desc_slot
*desc
,
2068 dma_addr_t
*src
, int src_cnt
)
2072 /* initialize CDB */
2073 for (i
= 0; i
< src_cnt
; i
++) {
2074 ppc440spe_adma_dma2rxor_prep_src(desc
, &desc
->rxor_cursor
, i
,
2075 desc
->src_cnt
, (u32
)src
[i
]);
2080 * ppc440spe_dma01_prep_mult -
2081 * for Q operation where destination is also the source
2083 static struct ppc440spe_adma_desc_slot
*ppc440spe_dma01_prep_mult(
2084 struct ppc440spe_adma_chan
*ppc440spe_chan
,
2085 dma_addr_t
*dst
, int dst_cnt
, dma_addr_t
*src
, int src_cnt
,
2086 const unsigned char *scf
, size_t len
, unsigned long flags
)
2088 struct ppc440spe_adma_desc_slot
*sw_desc
= NULL
;
2089 unsigned long op
= 0;
2092 set_bit(PPC440SPE_DESC_WXOR
, &op
);
2095 spin_lock_bh(&ppc440spe_chan
->lock
);
2097 /* use WXOR, each descriptor occupies one slot */
2098 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
, 1);
2100 struct ppc440spe_adma_chan
*chan
;
2101 struct ppc440spe_adma_desc_slot
*iter
;
2102 struct dma_cdb
*hw_desc
;
2104 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
2105 set_bits(op
, &sw_desc
->flags
);
2106 sw_desc
->src_cnt
= src_cnt
;
2107 sw_desc
->dst_cnt
= dst_cnt
;
2108 /* First descriptor, zero data in the destination and copy it
2109 * to q page using MULTICAST transfer.
2111 iter
= list_first_entry(&sw_desc
->group_list
,
2112 struct ppc440spe_adma_desc_slot
,
2114 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
2115 /* set 'next' pointer */
2116 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
2117 struct ppc440spe_adma_desc_slot
,
2119 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2120 hw_desc
= iter
->hw_desc
;
2121 hw_desc
->opc
= DMA_CDB_OPC_MULTICAST
;
2123 ppc440spe_desc_set_dest_addr(iter
, chan
,
2124 DMA_CUED_XOR_BASE
, dst
[0], 0);
2125 ppc440spe_desc_set_dest_addr(iter
, chan
, 0, dst
[1], 1);
2126 ppc440spe_desc_set_src_addr(iter
, chan
, 0, DMA_CUED_XOR_HB
,
2128 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
, len
);
2129 iter
->unmap_len
= len
;
2132 * Second descriptor, multiply data from the q page
2133 * and store the result in real destination.
2135 iter
= list_first_entry(&iter
->chain_node
,
2136 struct ppc440spe_adma_desc_slot
,
2138 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
2139 iter
->hw_next
= NULL
;
2140 if (flags
& DMA_PREP_INTERRUPT
)
2141 set_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2143 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2145 hw_desc
= iter
->hw_desc
;
2146 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
2147 ppc440spe_desc_set_src_addr(iter
, chan
, 0,
2148 DMA_CUED_XOR_HB
, dst
[1]);
2149 ppc440spe_desc_set_dest_addr(iter
, chan
,
2150 DMA_CUED_XOR_BASE
, dst
[0], 0);
2152 ppc440spe_desc_set_src_mult(iter
, chan
, DMA_CUED_MULT1_OFF
,
2153 DMA_CDB_SG_DST1
, scf
[0]);
2154 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
, len
);
2155 iter
->unmap_len
= len
;
2156 sw_desc
->async_tx
.flags
= flags
;
2159 spin_unlock_bh(&ppc440spe_chan
->lock
);
2165 * ppc440spe_dma01_prep_sum_product -
2166 * Dx = A*(P+Pxy) + B*(Q+Qxy) operation where destination is also
2169 static struct ppc440spe_adma_desc_slot
*ppc440spe_dma01_prep_sum_product(
2170 struct ppc440spe_adma_chan
*ppc440spe_chan
,
2171 dma_addr_t
*dst
, dma_addr_t
*src
, int src_cnt
,
2172 const unsigned char *scf
, size_t len
, unsigned long flags
)
2174 struct ppc440spe_adma_desc_slot
*sw_desc
= NULL
;
2175 unsigned long op
= 0;
2178 set_bit(PPC440SPE_DESC_WXOR
, &op
);
2181 spin_lock_bh(&ppc440spe_chan
->lock
);
2183 /* WXOR, each descriptor occupies one slot */
2184 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
, 1);
2186 struct ppc440spe_adma_chan
*chan
;
2187 struct ppc440spe_adma_desc_slot
*iter
;
2188 struct dma_cdb
*hw_desc
;
2190 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
2191 set_bits(op
, &sw_desc
->flags
);
2192 sw_desc
->src_cnt
= src_cnt
;
2193 sw_desc
->dst_cnt
= 1;
2194 /* 1st descriptor, src[1] data to q page and zero destination */
2195 iter
= list_first_entry(&sw_desc
->group_list
,
2196 struct ppc440spe_adma_desc_slot
,
2198 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
2199 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
2200 struct ppc440spe_adma_desc_slot
,
2202 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2203 hw_desc
= iter
->hw_desc
;
2204 hw_desc
->opc
= DMA_CDB_OPC_MULTICAST
;
2206 ppc440spe_desc_set_dest_addr(iter
, chan
, DMA_CUED_XOR_BASE
,
2208 ppc440spe_desc_set_dest_addr(iter
, chan
, 0,
2209 ppc440spe_chan
->qdest
, 1);
2210 ppc440spe_desc_set_src_addr(iter
, chan
, 0, DMA_CUED_XOR_HB
,
2212 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
, len
);
2213 iter
->unmap_len
= len
;
2215 /* 2nd descriptor, multiply src[1] data and store the
2216 * result in destination */
2217 iter
= list_first_entry(&iter
->chain_node
,
2218 struct ppc440spe_adma_desc_slot
,
2220 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
2221 /* set 'next' pointer */
2222 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
2223 struct ppc440spe_adma_desc_slot
,
2225 if (flags
& DMA_PREP_INTERRUPT
)
2226 set_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2228 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2230 hw_desc
= iter
->hw_desc
;
2231 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
2232 ppc440spe_desc_set_src_addr(iter
, chan
, 0, DMA_CUED_XOR_HB
,
2233 ppc440spe_chan
->qdest
);
2234 ppc440spe_desc_set_dest_addr(iter
, chan
, DMA_CUED_XOR_BASE
,
2236 ppc440spe_desc_set_src_mult(iter
, chan
, DMA_CUED_MULT1_OFF
,
2237 DMA_CDB_SG_DST1
, scf
[1]);
2238 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
, len
);
2239 iter
->unmap_len
= len
;
2242 * 3rd descriptor, multiply src[0] data and xor it
2245 iter
= list_first_entry(&iter
->chain_node
,
2246 struct ppc440spe_adma_desc_slot
,
2248 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
2249 iter
->hw_next
= NULL
;
2250 if (flags
& DMA_PREP_INTERRUPT
)
2251 set_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2253 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2255 hw_desc
= iter
->hw_desc
;
2256 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
2257 ppc440spe_desc_set_src_addr(iter
, chan
, 0, DMA_CUED_XOR_HB
,
2259 ppc440spe_desc_set_dest_addr(iter
, chan
, DMA_CUED_XOR_BASE
,
2261 ppc440spe_desc_set_src_mult(iter
, chan
, DMA_CUED_MULT1_OFF
,
2262 DMA_CDB_SG_DST1
, scf
[0]);
2263 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
, len
);
2264 iter
->unmap_len
= len
;
2265 sw_desc
->async_tx
.flags
= flags
;
2268 spin_unlock_bh(&ppc440spe_chan
->lock
);
2273 static struct ppc440spe_adma_desc_slot
*ppc440spe_dma01_prep_pq(
2274 struct ppc440spe_adma_chan
*ppc440spe_chan
,
2275 dma_addr_t
*dst
, int dst_cnt
, dma_addr_t
*src
, int src_cnt
,
2276 const unsigned char *scf
, size_t len
, unsigned long flags
)
2279 struct ppc440spe_adma_desc_slot
*sw_desc
= NULL
, *iter
;
2280 unsigned long op
= 0;
2281 unsigned char mult
= 1;
2283 pr_debug("%s: dst_cnt %d, src_cnt %d, len %d\n",
2284 __func__
, dst_cnt
, src_cnt
, len
);
2285 /* select operations WXOR/RXOR depending on the
2286 * source addresses of operators and the number
2287 * of destinations (RXOR support only Q-parity calculations)
2289 set_bit(PPC440SPE_DESC_WXOR
, &op
);
2290 if (!test_and_set_bit(PPC440SPE_RXOR_RUN
, &ppc440spe_rxor_state
)) {
2293 * - there are more than 1 source,
2294 * - len is aligned on 512-byte boundary,
2295 * - source addresses fit to one of 4 possible regions.
2298 !(len
& MQ0_CF2H_RXOR_BS_MASK
) &&
2299 (src
[0] + len
) == src
[1]) {
2300 /* may do RXOR R1 R2 */
2301 set_bit(PPC440SPE_DESC_RXOR
, &op
);
2303 /* may try to enhance region of RXOR */
2304 if ((src
[1] + len
) == src
[2]) {
2305 /* do RXOR R1 R2 R3 */
2306 set_bit(PPC440SPE_DESC_RXOR123
,
2308 } else if ((src
[1] + len
* 2) == src
[2]) {
2309 /* do RXOR R1 R2 R4 */
2310 set_bit(PPC440SPE_DESC_RXOR124
, &op
);
2311 } else if ((src
[1] + len
* 3) == src
[2]) {
2312 /* do RXOR R1 R2 R5 */
2313 set_bit(PPC440SPE_DESC_RXOR125
,
2317 set_bit(PPC440SPE_DESC_RXOR12
,
2322 set_bit(PPC440SPE_DESC_RXOR12
, &op
);
2326 if (!test_bit(PPC440SPE_DESC_RXOR
, &op
)) {
2327 /* can not do this operation with RXOR */
2328 clear_bit(PPC440SPE_RXOR_RUN
,
2329 &ppc440spe_rxor_state
);
2331 /* can do; set block size right now */
2332 ppc440spe_desc_set_rxor_block_size(len
);
2336 /* Number of necessary slots depends on operation type selected */
2337 if (!test_bit(PPC440SPE_DESC_RXOR
, &op
)) {
2338 /* This is a WXOR only chain. Need descriptors for each
2339 * source to GF-XOR them with WXOR, and need descriptors
2340 * for each destination to zero them with WXOR
2344 if (flags
& DMA_PREP_ZERO_P
) {
2346 set_bit(PPC440SPE_ZERO_P
, &op
);
2348 if (flags
& DMA_PREP_ZERO_Q
) {
2350 set_bit(PPC440SPE_ZERO_Q
, &op
);
2353 /* Need 1/2 descriptor for RXOR operation, and
2354 * need (src_cnt - (2 or 3)) for WXOR of sources
2359 if (flags
& DMA_PREP_ZERO_P
)
2360 set_bit(PPC440SPE_ZERO_P
, &op
);
2361 if (flags
& DMA_PREP_ZERO_Q
)
2362 set_bit(PPC440SPE_ZERO_Q
, &op
);
2364 if (test_bit(PPC440SPE_DESC_RXOR12
, &op
))
2365 slot_cnt
+= src_cnt
- 2;
2367 slot_cnt
+= src_cnt
- 3;
2369 /* Thus we have either RXOR only chain or
2372 if (slot_cnt
== dst_cnt
)
2373 /* RXOR only chain */
2374 clear_bit(PPC440SPE_DESC_WXOR
, &op
);
2377 spin_lock_bh(&ppc440spe_chan
->lock
);
2378 /* for both RXOR/WXOR each descriptor occupies one slot */
2379 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
, 1);
2381 ppc440spe_desc_init_dma01pq(sw_desc
, dst_cnt
, src_cnt
,
2384 /* setup dst/src/mult */
2385 pr_debug("%s: set dst descriptor 0, 1: 0x%016llx, 0x%016llx\n",
2386 __func__
, dst
[0], dst
[1]);
2387 ppc440spe_adma_pq_set_dest(sw_desc
, dst
, flags
);
2389 ppc440spe_adma_pq_set_src(sw_desc
, src
[src_cnt
],
2392 /* NOTE: "Multi = 0 is equivalent to = 1" as it
2393 * stated in 440SPSPe_RAID6_Addendum_UM_1_17.pdf
2394 * doesn't work for RXOR with DMA0/1! Instead, multi=0
2395 * leads to zeroing source data after RXOR.
2396 * So, for P case set-up mult=1 explicitly.
2398 if (!(flags
& DMA_PREP_PQ_DISABLE_Q
))
2399 mult
= scf
[src_cnt
];
2400 ppc440spe_adma_pq_set_src_mult(sw_desc
,
2401 mult
, src_cnt
, dst_cnt
- 1);
2404 /* Setup byte count foreach slot just allocated */
2405 sw_desc
->async_tx
.flags
= flags
;
2406 list_for_each_entry(iter
, &sw_desc
->group_list
,
2408 ppc440spe_desc_set_byte_count(iter
,
2409 ppc440spe_chan
, len
);
2410 iter
->unmap_len
= len
;
2413 spin_unlock_bh(&ppc440spe_chan
->lock
);
2418 static struct ppc440spe_adma_desc_slot
*ppc440spe_dma2_prep_pq(
2419 struct ppc440spe_adma_chan
*ppc440spe_chan
,
2420 dma_addr_t
*dst
, int dst_cnt
, dma_addr_t
*src
, int src_cnt
,
2421 const unsigned char *scf
, size_t len
, unsigned long flags
)
2423 int slot_cnt
, descs_per_op
;
2424 struct ppc440spe_adma_desc_slot
*sw_desc
= NULL
, *iter
;
2425 unsigned long op
= 0;
2426 unsigned char mult
= 1;
2429 /*pr_debug("%s: dst_cnt %d, src_cnt %d, len %d\n",
2430 __func__, dst_cnt, src_cnt, len);*/
2432 spin_lock_bh(&ppc440spe_chan
->lock
);
2433 descs_per_op
= ppc440spe_dma2_pq_slot_count(src
, src_cnt
, len
);
2434 if (descs_per_op
< 0) {
2435 spin_unlock_bh(&ppc440spe_chan
->lock
);
2439 /* depending on number of sources we have 1 or 2 RXOR chains */
2440 slot_cnt
= descs_per_op
* dst_cnt
;
2442 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
, 1);
2445 sw_desc
->async_tx
.flags
= flags
;
2446 list_for_each_entry(iter
, &sw_desc
->group_list
, chain_node
) {
2447 ppc440spe_desc_init_dma2pq(iter
, dst_cnt
, src_cnt
,
2449 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
,
2451 iter
->unmap_len
= len
;
2453 ppc440spe_init_rxor_cursor(&(iter
->rxor_cursor
));
2454 iter
->rxor_cursor
.len
= len
;
2455 iter
->descs_per_op
= descs_per_op
;
2458 list_for_each_entry(iter
, &sw_desc
->group_list
, chain_node
) {
2460 if (op
% descs_per_op
== 0)
2461 ppc440spe_adma_init_dma2rxor_slot(iter
, src
,
2463 if (likely(!list_is_last(&iter
->chain_node
,
2464 &sw_desc
->group_list
))) {
2465 /* set 'next' pointer */
2467 list_entry(iter
->chain_node
.next
,
2468 struct ppc440spe_adma_desc_slot
,
2470 ppc440spe_xor_set_link(iter
, iter
->hw_next
);
2472 /* this is the last descriptor. */
2473 iter
->hw_next
= NULL
;
2477 /* fixup head descriptor */
2478 sw_desc
->dst_cnt
= dst_cnt
;
2479 if (flags
& DMA_PREP_ZERO_P
)
2480 set_bit(PPC440SPE_ZERO_P
, &sw_desc
->flags
);
2481 if (flags
& DMA_PREP_ZERO_Q
)
2482 set_bit(PPC440SPE_ZERO_Q
, &sw_desc
->flags
);
2484 /* setup dst/src/mult */
2485 ppc440spe_adma_pq_set_dest(sw_desc
, dst
, flags
);
2488 /* handle descriptors (if dst_cnt == 2) inside
2489 * the ppc440spe_adma_pq_set_srcxxx() functions
2491 ppc440spe_adma_pq_set_src(sw_desc
, src
[src_cnt
],
2493 if (!(flags
& DMA_PREP_PQ_DISABLE_Q
))
2494 mult
= scf
[src_cnt
];
2495 ppc440spe_adma_pq_set_src_mult(sw_desc
,
2496 mult
, src_cnt
, dst_cnt
- 1);
2499 spin_unlock_bh(&ppc440spe_chan
->lock
);
2500 ppc440spe_desc_set_rxor_block_size(len
);
2505 * ppc440spe_adma_prep_dma_pq - prepare CDB (group) for a GF-XOR operation
2507 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_pq(
2508 struct dma_chan
*chan
, dma_addr_t
*dst
, dma_addr_t
*src
,
2509 unsigned int src_cnt
, const unsigned char *scf
,
2510 size_t len
, unsigned long flags
)
2512 struct ppc440spe_adma_chan
*ppc440spe_chan
;
2513 struct ppc440spe_adma_desc_slot
*sw_desc
= NULL
;
2516 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
2518 ADMA_LL_DBG(prep_dma_pq_dbg(ppc440spe_chan
->device
->id
,
2519 dst
, src
, src_cnt
));
2521 BUG_ON(len
> PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT
);
2524 if (src_cnt
== 1 && dst
[1] == src
[0]) {
2527 /* dst[1] is real destination (Q) */
2529 /* this is the page to multicast source data to */
2530 dest
[1] = ppc440spe_chan
->qdest
;
2531 sw_desc
= ppc440spe_dma01_prep_mult(ppc440spe_chan
,
2532 dest
, 2, src
, src_cnt
, scf
, len
, flags
);
2533 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2536 if (src_cnt
== 2 && dst
[1] == src
[1]) {
2537 sw_desc
= ppc440spe_dma01_prep_sum_product(ppc440spe_chan
,
2538 &dst
[1], src
, 2, scf
, len
, flags
);
2539 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2542 if (!(flags
& DMA_PREP_PQ_DISABLE_P
)) {
2545 flags
|= DMA_PREP_ZERO_P
;
2548 if (!(flags
& DMA_PREP_PQ_DISABLE_Q
)) {
2551 flags
|= DMA_PREP_ZERO_Q
;
2556 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
2557 "ppc440spe adma%d: %s src_cnt: %d len: %u int_en: %d\n",
2558 ppc440spe_chan
->device
->id
, __func__
, src_cnt
, len
,
2559 flags
& DMA_PREP_INTERRUPT
? 1 : 0);
2561 switch (ppc440spe_chan
->device
->id
) {
2562 case PPC440SPE_DMA0_ID
:
2563 case PPC440SPE_DMA1_ID
:
2564 sw_desc
= ppc440spe_dma01_prep_pq(ppc440spe_chan
,
2565 dst
, dst_cnt
, src
, src_cnt
, scf
,
2569 case PPC440SPE_XOR_ID
:
2570 sw_desc
= ppc440spe_dma2_prep_pq(ppc440spe_chan
,
2571 dst
, dst_cnt
, src
, src_cnt
, scf
,
2576 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2580 * ppc440spe_adma_prep_dma_pqzero_sum - prepare CDB group for
2581 * a PQ_ZERO_SUM operation
2583 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_pqzero_sum(
2584 struct dma_chan
*chan
, dma_addr_t
*pq
, dma_addr_t
*src
,
2585 unsigned int src_cnt
, const unsigned char *scf
, size_t len
,
2586 enum sum_check_flags
*pqres
, unsigned long flags
)
2588 struct ppc440spe_adma_chan
*ppc440spe_chan
;
2589 struct ppc440spe_adma_desc_slot
*sw_desc
, *iter
;
2590 dma_addr_t pdest
, qdest
;
2591 int slot_cnt
, slots_per_op
, idst
, dst_cnt
;
2593 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
2595 if (flags
& DMA_PREP_PQ_DISABLE_P
)
2600 if (flags
& DMA_PREP_PQ_DISABLE_Q
)
2605 ADMA_LL_DBG(prep_dma_pqzero_sum_dbg(ppc440spe_chan
->device
->id
,
2606 src
, src_cnt
, scf
));
2608 /* Always use WXOR for P/Q calculations (two destinations).
2609 * Need 1 or 2 extra slots to verify results are zero.
2611 idst
= dst_cnt
= (pdest
&& qdest
) ? 2 : 1;
2613 /* One additional slot per destination to clone P/Q
2614 * before calculation (we have to preserve destinations).
2616 slot_cnt
= src_cnt
+ dst_cnt
* 2;
2619 spin_lock_bh(&ppc440spe_chan
->lock
);
2620 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
,
2623 ppc440spe_desc_init_dma01pqzero_sum(sw_desc
, dst_cnt
, src_cnt
);
2625 /* Setup byte count for each slot just allocated */
2626 sw_desc
->async_tx
.flags
= flags
;
2627 list_for_each_entry(iter
, &sw_desc
->group_list
, chain_node
) {
2628 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
,
2630 iter
->unmap_len
= len
;
2634 struct dma_cdb
*hw_desc
;
2635 struct ppc440spe_adma_chan
*chan
;
2637 iter
= sw_desc
->group_head
;
2638 chan
= to_ppc440spe_adma_chan(iter
->async_tx
.chan
);
2639 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
2640 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
2641 struct ppc440spe_adma_desc_slot
,
2643 hw_desc
= iter
->hw_desc
;
2644 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
2647 ppc440spe_desc_set_dest_addr(iter
, chan
, 0,
2648 ppc440spe_chan
->pdest
, 0);
2649 ppc440spe_desc_set_src_addr(iter
, chan
, 0, 0, pdest
);
2650 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
,
2652 iter
->unmap_len
= 0;
2653 /* override pdest to preserve original P */
2654 pdest
= ppc440spe_chan
->pdest
;
2657 struct dma_cdb
*hw_desc
;
2658 struct ppc440spe_adma_chan
*chan
;
2660 iter
= list_first_entry(&sw_desc
->group_list
,
2661 struct ppc440spe_adma_desc_slot
,
2663 chan
= to_ppc440spe_adma_chan(iter
->async_tx
.chan
);
2666 iter
= list_entry(iter
->chain_node
.next
,
2667 struct ppc440spe_adma_desc_slot
,
2671 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
2672 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
2673 struct ppc440spe_adma_desc_slot
,
2675 hw_desc
= iter
->hw_desc
;
2676 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
2679 ppc440spe_desc_set_dest_addr(iter
, chan
, 0,
2680 ppc440spe_chan
->qdest
, 0);
2681 ppc440spe_desc_set_src_addr(iter
, chan
, 0, 0, qdest
);
2682 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
,
2684 iter
->unmap_len
= 0;
2685 /* override qdest to preserve original Q */
2686 qdest
= ppc440spe_chan
->qdest
;
2689 /* Setup destinations for P/Q ops */
2690 ppc440spe_adma_pqzero_sum_set_dest(sw_desc
, pdest
, qdest
);
2692 /* Setup zero QWORDs into DCHECK CDBs */
2694 list_for_each_entry_reverse(iter
, &sw_desc
->group_list
,
2697 * The last CDB corresponds to Q-parity check,
2698 * the one before last CDB corresponds
2701 if (idst
== DMA_DEST_MAX_NUM
) {
2702 if (idst
== dst_cnt
) {
2703 set_bit(PPC440SPE_DESC_QCHECK
,
2706 set_bit(PPC440SPE_DESC_PCHECK
,
2711 set_bit(PPC440SPE_DESC_QCHECK
,
2714 set_bit(PPC440SPE_DESC_PCHECK
,
2718 iter
->xor_check_result
= pqres
;
2721 * set it to zero, if check fail then result will
2724 *iter
->xor_check_result
= 0;
2725 ppc440spe_desc_set_dcheck(iter
, ppc440spe_chan
,
2732 /* Setup sources and mults for P/Q ops */
2733 list_for_each_entry_continue_reverse(iter
, &sw_desc
->group_list
,
2735 struct ppc440spe_adma_chan
*chan
;
2738 chan
= to_ppc440spe_adma_chan(iter
->async_tx
.chan
);
2739 ppc440spe_desc_set_src_addr(iter
, chan
, 0,
2743 mult_dst
= (dst_cnt
- 1) ? DMA_CDB_SG_DST2
:
2745 ppc440spe_desc_set_src_mult(iter
, chan
,
2754 spin_unlock_bh(&ppc440spe_chan
->lock
);
2755 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2759 * ppc440spe_adma_prep_dma_xor_zero_sum - prepare CDB group for
2760 * XOR ZERO_SUM operation
2762 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_xor_zero_sum(
2763 struct dma_chan
*chan
, dma_addr_t
*src
, unsigned int src_cnt
,
2764 size_t len
, enum sum_check_flags
*result
, unsigned long flags
)
2766 struct dma_async_tx_descriptor
*tx
;
2769 /* validate P, disable Q */
2772 flags
|= DMA_PREP_PQ_DISABLE_Q
;
2774 tx
= ppc440spe_adma_prep_dma_pqzero_sum(chan
, pq
, &src
[1],
2775 src_cnt
- 1, 0, len
,
2781 * ppc440spe_adma_set_dest - set destination address into descriptor
2783 static void ppc440spe_adma_set_dest(struct ppc440spe_adma_desc_slot
*sw_desc
,
2784 dma_addr_t addr
, int index
)
2786 struct ppc440spe_adma_chan
*chan
;
2788 BUG_ON(index
>= sw_desc
->dst_cnt
);
2790 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
2792 switch (chan
->device
->id
) {
2793 case PPC440SPE_DMA0_ID
:
2794 case PPC440SPE_DMA1_ID
:
2795 /* to do: support transfers lengths >
2796 * PPC440SPE_ADMA_DMA/XOR_MAX_BYTE_COUNT
2798 ppc440spe_desc_set_dest_addr(sw_desc
->group_head
,
2799 chan
, 0, addr
, index
);
2801 case PPC440SPE_XOR_ID
:
2802 sw_desc
= ppc440spe_get_group_entry(sw_desc
, index
);
2803 ppc440spe_desc_set_dest_addr(sw_desc
,
2804 chan
, 0, addr
, index
);
2809 static void ppc440spe_adma_pq_zero_op(struct ppc440spe_adma_desc_slot
*iter
,
2810 struct ppc440spe_adma_chan
*chan
, dma_addr_t addr
)
2812 /* To clear destinations update the descriptor
2813 * (P or Q depending on index) as follows:
2814 * addr is destination (0 corresponds to SG2):
2816 ppc440spe_desc_set_dest_addr(iter
, chan
, DMA_CUED_XOR_BASE
, addr
, 0);
2818 /* ... and the addr is source: */
2819 ppc440spe_desc_set_src_addr(iter
, chan
, 0, DMA_CUED_XOR_HB
, addr
);
2821 /* addr is always SG2 then the mult is always DST1 */
2822 ppc440spe_desc_set_src_mult(iter
, chan
, DMA_CUED_MULT1_OFF
,
2823 DMA_CDB_SG_DST1
, 1);
2827 * ppc440spe_adma_pq_set_dest - set destination address into descriptor
2828 * for the PQXOR operation
2830 static void ppc440spe_adma_pq_set_dest(struct ppc440spe_adma_desc_slot
*sw_desc
,
2831 dma_addr_t
*addrs
, unsigned long flags
)
2833 struct ppc440spe_adma_desc_slot
*iter
;
2834 struct ppc440spe_adma_chan
*chan
;
2835 dma_addr_t paddr
, qaddr
;
2836 dma_addr_t addr
= 0, ppath
, qpath
;
2839 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
2841 if (flags
& DMA_PREP_PQ_DISABLE_P
)
2846 if (flags
& DMA_PREP_PQ_DISABLE_Q
)
2851 if (!paddr
|| !qaddr
)
2852 addr
= paddr
? paddr
: qaddr
;
2854 switch (chan
->device
->id
) {
2855 case PPC440SPE_DMA0_ID
:
2856 case PPC440SPE_DMA1_ID
:
2857 /* walk through the WXOR source list and set P/Q-destinations
2860 if (!test_bit(PPC440SPE_DESC_RXOR
, &sw_desc
->flags
)) {
2861 /* This is WXOR-only chain; may have 1/2 zero descs */
2862 if (test_bit(PPC440SPE_ZERO_P
, &sw_desc
->flags
))
2864 if (test_bit(PPC440SPE_ZERO_Q
, &sw_desc
->flags
))
2867 iter
= ppc440spe_get_group_entry(sw_desc
, index
);
2869 /* one destination */
2870 list_for_each_entry_from(iter
,
2871 &sw_desc
->group_list
, chain_node
)
2872 ppc440spe_desc_set_dest_addr(iter
, chan
,
2873 DMA_CUED_XOR_BASE
, addr
, 0);
2875 /* two destinations */
2876 list_for_each_entry_from(iter
,
2877 &sw_desc
->group_list
, chain_node
) {
2878 ppc440spe_desc_set_dest_addr(iter
, chan
,
2879 DMA_CUED_XOR_BASE
, paddr
, 0);
2880 ppc440spe_desc_set_dest_addr(iter
, chan
,
2881 DMA_CUED_XOR_BASE
, qaddr
, 1);
2886 /* To clear destinations update the descriptor
2887 * (1st,2nd, or both depending on flags)
2890 if (test_bit(PPC440SPE_ZERO_P
,
2892 iter
= ppc440spe_get_group_entry(
2894 ppc440spe_adma_pq_zero_op(iter
, chan
,
2898 if (test_bit(PPC440SPE_ZERO_Q
,
2900 iter
= ppc440spe_get_group_entry(
2902 ppc440spe_adma_pq_zero_op(iter
, chan
,
2909 /* This is RXOR-only or RXOR/WXOR mixed chain */
2911 /* If we want to include destination into calculations,
2912 * then make dest addresses cued with mult=1 (XOR).
2914 ppath
= test_bit(PPC440SPE_ZERO_P
, &sw_desc
->flags
) ?
2917 (1 << DMA_CUED_MULT1_OFF
);
2918 qpath
= test_bit(PPC440SPE_ZERO_Q
, &sw_desc
->flags
) ?
2921 (1 << DMA_CUED_MULT1_OFF
);
2923 /* Setup destination(s) in RXOR slot(s) */
2924 iter
= ppc440spe_get_group_entry(sw_desc
, index
++);
2925 ppc440spe_desc_set_dest_addr(iter
, chan
,
2926 paddr
? ppath
: qpath
,
2927 paddr
? paddr
: qaddr
, 0);
2929 /* two destinations */
2930 iter
= ppc440spe_get_group_entry(sw_desc
,
2932 ppc440spe_desc_set_dest_addr(iter
, chan
,
2936 if (test_bit(PPC440SPE_DESC_WXOR
, &sw_desc
->flags
)) {
2937 /* Setup destination(s) in remaining WXOR
2940 iter
= ppc440spe_get_group_entry(sw_desc
,
2943 /* one destination */
2944 list_for_each_entry_from(iter
,
2945 &sw_desc
->group_list
,
2947 ppc440spe_desc_set_dest_addr(
2953 /* two destinations */
2954 list_for_each_entry_from(iter
,
2955 &sw_desc
->group_list
,
2957 ppc440spe_desc_set_dest_addr(
2961 ppc440spe_desc_set_dest_addr(
2972 case PPC440SPE_XOR_ID
:
2973 /* DMA2 descriptors have only 1 destination, so there are
2974 * two chains - one for each dest.
2975 * If we want to include destination into calculations,
2976 * then make dest addresses cued with mult=1 (XOR).
2978 ppath
= test_bit(PPC440SPE_ZERO_P
, &sw_desc
->flags
) ?
2981 (1 << DMA_CUED_MULT1_OFF
);
2983 qpath
= test_bit(PPC440SPE_ZERO_Q
, &sw_desc
->flags
) ?
2986 (1 << DMA_CUED_MULT1_OFF
);
2988 iter
= ppc440spe_get_group_entry(sw_desc
, 0);
2989 for (i
= 0; i
< sw_desc
->descs_per_op
; i
++) {
2990 ppc440spe_desc_set_dest_addr(iter
, chan
,
2991 paddr
? ppath
: qpath
,
2992 paddr
? paddr
: qaddr
, 0);
2993 iter
= list_entry(iter
->chain_node
.next
,
2994 struct ppc440spe_adma_desc_slot
,
2999 /* Two destinations; setup Q here */
3000 iter
= ppc440spe_get_group_entry(sw_desc
,
3001 sw_desc
->descs_per_op
);
3002 for (i
= 0; i
< sw_desc
->descs_per_op
; i
++) {
3003 ppc440spe_desc_set_dest_addr(iter
,
3004 chan
, qpath
, qaddr
, 0);
3005 iter
= list_entry(iter
->chain_node
.next
,
3006 struct ppc440spe_adma_desc_slot
,
3016 * ppc440spe_adma_pq_zero_sum_set_dest - set destination address into descriptor
3017 * for the PQ_ZERO_SUM operation
3019 static void ppc440spe_adma_pqzero_sum_set_dest(
3020 struct ppc440spe_adma_desc_slot
*sw_desc
,
3021 dma_addr_t paddr
, dma_addr_t qaddr
)
3023 struct ppc440spe_adma_desc_slot
*iter
, *end
;
3024 struct ppc440spe_adma_chan
*chan
;
3025 dma_addr_t addr
= 0;
3028 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
3030 /* walk through the WXOR source list and set P/Q-destinations
3033 idx
= (paddr
&& qaddr
) ? 2 : 1;
3035 list_for_each_entry_reverse(end
, &sw_desc
->group_list
,
3041 idx
= (paddr
&& qaddr
) ? 2 : 1;
3042 iter
= ppc440spe_get_group_entry(sw_desc
, idx
);
3044 if (paddr
&& qaddr
) {
3045 /* two destinations */
3046 list_for_each_entry_from(iter
, &sw_desc
->group_list
,
3048 if (unlikely(iter
== end
))
3050 ppc440spe_desc_set_dest_addr(iter
, chan
,
3051 DMA_CUED_XOR_BASE
, paddr
, 0);
3052 ppc440spe_desc_set_dest_addr(iter
, chan
,
3053 DMA_CUED_XOR_BASE
, qaddr
, 1);
3056 /* one destination */
3057 addr
= paddr
? paddr
: qaddr
;
3058 list_for_each_entry_from(iter
, &sw_desc
->group_list
,
3060 if (unlikely(iter
== end
))
3062 ppc440spe_desc_set_dest_addr(iter
, chan
,
3063 DMA_CUED_XOR_BASE
, addr
, 0);
3067 /* The remaining descriptors are DATACHECK. These have no need in
3068 * destination. Actually, these destinations are used there
3069 * as sources for check operation. So, set addr as source.
3071 ppc440spe_desc_set_src_addr(end
, chan
, 0, 0, addr
? addr
: paddr
);
3074 end
= list_entry(end
->chain_node
.next
,
3075 struct ppc440spe_adma_desc_slot
, chain_node
);
3076 ppc440spe_desc_set_src_addr(end
, chan
, 0, 0, qaddr
);
3081 * ppc440spe_desc_set_xor_src_cnt - set source count into descriptor
3083 static inline void ppc440spe_desc_set_xor_src_cnt(
3084 struct ppc440spe_adma_desc_slot
*desc
,
3087 struct xor_cb
*hw_desc
= desc
->hw_desc
;
3089 hw_desc
->cbc
&= ~XOR_CDCR_OAC_MSK
;
3090 hw_desc
->cbc
|= src_cnt
;
3094 * ppc440spe_adma_pq_set_src - set source address into descriptor
3096 static void ppc440spe_adma_pq_set_src(struct ppc440spe_adma_desc_slot
*sw_desc
,
3097 dma_addr_t addr
, int index
)
3099 struct ppc440spe_adma_chan
*chan
;
3100 dma_addr_t haddr
= 0;
3101 struct ppc440spe_adma_desc_slot
*iter
= NULL
;
3103 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
3105 switch (chan
->device
->id
) {
3106 case PPC440SPE_DMA0_ID
:
3107 case PPC440SPE_DMA1_ID
:
3108 /* DMA0,1 may do: WXOR, RXOR, RXOR+WXORs chain
3110 if (test_bit(PPC440SPE_DESC_RXOR
, &sw_desc
->flags
)) {
3111 /* RXOR-only or RXOR/WXOR operation */
3112 int iskip
= test_bit(PPC440SPE_DESC_RXOR12
,
3113 &sw_desc
->flags
) ? 2 : 3;
3116 /* 1st slot (RXOR) */
3117 /* setup sources region (R1-2-3, R1-2-4,
3120 if (test_bit(PPC440SPE_DESC_RXOR12
,
3122 haddr
= DMA_RXOR12
<<
3123 DMA_CUED_REGION_OFF
;
3124 else if (test_bit(PPC440SPE_DESC_RXOR123
,
3126 haddr
= DMA_RXOR123
<<
3127 DMA_CUED_REGION_OFF
;
3128 else if (test_bit(PPC440SPE_DESC_RXOR124
,
3130 haddr
= DMA_RXOR124
<<
3131 DMA_CUED_REGION_OFF
;
3132 else if (test_bit(PPC440SPE_DESC_RXOR125
,
3134 haddr
= DMA_RXOR125
<<
3135 DMA_CUED_REGION_OFF
;
3138 haddr
|= DMA_CUED_XOR_BASE
;
3139 iter
= ppc440spe_get_group_entry(sw_desc
, 0);
3140 } else if (index
< iskip
) {
3142 * shall actually set source address only once
3143 * instead of first <iskip>
3147 /* 2nd/3d and next slots (WXOR);
3148 * skip first slot with RXOR
3150 haddr
= DMA_CUED_XOR_HB
;
3151 iter
= ppc440spe_get_group_entry(sw_desc
,
3152 index
- iskip
+ sw_desc
->dst_cnt
);
3157 /* WXOR-only operation; skip first slots with
3158 * zeroing destinations
3160 if (test_bit(PPC440SPE_ZERO_P
, &sw_desc
->flags
))
3162 if (test_bit(PPC440SPE_ZERO_Q
, &sw_desc
->flags
))
3165 haddr
= DMA_CUED_XOR_HB
;
3166 iter
= ppc440spe_get_group_entry(sw_desc
,
3171 ppc440spe_desc_set_src_addr(iter
, chan
, 0, haddr
, addr
);
3174 test_bit(PPC440SPE_DESC_RXOR
, &sw_desc
->flags
) &&
3175 sw_desc
->dst_cnt
== 2) {
3176 /* if we have two destinations for RXOR, then
3177 * setup source in the second descr too
3179 iter
= ppc440spe_get_group_entry(sw_desc
, 1);
3180 ppc440spe_desc_set_src_addr(iter
, chan
, 0,
3186 case PPC440SPE_XOR_ID
:
3187 /* DMA2 may do Biskup */
3188 iter
= sw_desc
->group_head
;
3189 if (iter
->dst_cnt
== 2) {
3190 /* both P & Q calculations required; set P src here */
3191 ppc440spe_adma_dma2rxor_set_src(iter
, index
, addr
);
3194 iter
= ppc440spe_get_group_entry(sw_desc
,
3195 sw_desc
->descs_per_op
);
3197 ppc440spe_adma_dma2rxor_set_src(iter
, index
, addr
);
3203 * ppc440spe_adma_memcpy_xor_set_src - set source address into descriptor
3205 static void ppc440spe_adma_memcpy_xor_set_src(
3206 struct ppc440spe_adma_desc_slot
*sw_desc
,
3207 dma_addr_t addr
, int index
)
3209 struct ppc440spe_adma_chan
*chan
;
3211 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
3212 sw_desc
= sw_desc
->group_head
;
3214 if (likely(sw_desc
))
3215 ppc440spe_desc_set_src_addr(sw_desc
, chan
, index
, 0, addr
);
3219 * ppc440spe_adma_dma2rxor_inc_addr -
3221 static void ppc440spe_adma_dma2rxor_inc_addr(
3222 struct ppc440spe_adma_desc_slot
*desc
,
3223 struct ppc440spe_rxor
*cursor
, int index
, int src_cnt
)
3225 cursor
->addr_count
++;
3226 if (index
== src_cnt
- 1) {
3227 ppc440spe_desc_set_xor_src_cnt(desc
, cursor
->addr_count
);
3228 } else if (cursor
->addr_count
== XOR_MAX_OPS
) {
3229 ppc440spe_desc_set_xor_src_cnt(desc
, cursor
->addr_count
);
3230 cursor
->addr_count
= 0;
3231 cursor
->desc_count
++;
3236 * ppc440spe_adma_dma2rxor_prep_src - setup RXOR types in DMA2 CDB
3238 static int ppc440spe_adma_dma2rxor_prep_src(
3239 struct ppc440spe_adma_desc_slot
*hdesc
,
3240 struct ppc440spe_rxor
*cursor
, int index
,
3241 int src_cnt
, u32 addr
)
3245 struct ppc440spe_adma_desc_slot
*desc
= hdesc
;
3248 for (i
= 0; i
< cursor
->desc_count
; i
++) {
3249 desc
= list_entry(hdesc
->chain_node
.next
,
3250 struct ppc440spe_adma_desc_slot
,
3254 switch (cursor
->state
) {
3256 if (addr
== cursor
->addrl
+ cursor
->len
) {
3259 cursor
->xor_count
++;
3260 if (index
== src_cnt
-1) {
3261 ppc440spe_rxor_set_region(desc
,
3263 DMA_RXOR12
<< DMA_CUED_REGION_OFF
);
3264 ppc440spe_adma_dma2rxor_inc_addr(
3265 desc
, cursor
, index
, src_cnt
);
3267 } else if (cursor
->addrl
== addr
+ cursor
->len
) {
3270 cursor
->xor_count
++;
3271 set_bit(cursor
->addr_count
, &desc
->reverse_flags
[0]);
3272 if (index
== src_cnt
-1) {
3273 ppc440spe_rxor_set_region(desc
,
3275 DMA_RXOR12
<< DMA_CUED_REGION_OFF
);
3276 ppc440spe_adma_dma2rxor_inc_addr(
3277 desc
, cursor
, index
, src_cnt
);
3280 printk(KERN_ERR
"Cannot build "
3281 "DMA2 RXOR command block.\n");
3286 sign
= test_bit(cursor
->addr_count
,
3287 desc
->reverse_flags
)
3289 if (index
== src_cnt
-2 || (sign
== -1
3290 && addr
!= cursor
->addrl
- 2*cursor
->len
)) {
3292 cursor
->xor_count
= 1;
3293 cursor
->addrl
= addr
;
3294 ppc440spe_rxor_set_region(desc
,
3296 DMA_RXOR12
<< DMA_CUED_REGION_OFF
);
3297 ppc440spe_adma_dma2rxor_inc_addr(
3298 desc
, cursor
, index
, src_cnt
);
3299 } else if (addr
== cursor
->addrl
+ 2*sign
*cursor
->len
) {
3301 cursor
->xor_count
= 0;
3302 ppc440spe_rxor_set_region(desc
,
3304 DMA_RXOR123
<< DMA_CUED_REGION_OFF
);
3305 if (index
== src_cnt
-1) {
3306 ppc440spe_adma_dma2rxor_inc_addr(
3307 desc
, cursor
, index
, src_cnt
);
3309 } else if (addr
== cursor
->addrl
+ 3*cursor
->len
) {
3311 cursor
->xor_count
= 0;
3312 ppc440spe_rxor_set_region(desc
,
3314 DMA_RXOR124
<< DMA_CUED_REGION_OFF
);
3315 if (index
== src_cnt
-1) {
3316 ppc440spe_adma_dma2rxor_inc_addr(
3317 desc
, cursor
, index
, src_cnt
);
3319 } else if (addr
== cursor
->addrl
+ 4*cursor
->len
) {
3321 cursor
->xor_count
= 0;
3322 ppc440spe_rxor_set_region(desc
,
3324 DMA_RXOR125
<< DMA_CUED_REGION_OFF
);
3325 if (index
== src_cnt
-1) {
3326 ppc440spe_adma_dma2rxor_inc_addr(
3327 desc
, cursor
, index
, src_cnt
);
3331 cursor
->xor_count
= 1;
3332 cursor
->addrl
= addr
;
3333 ppc440spe_rxor_set_region(desc
,
3335 DMA_RXOR12
<< DMA_CUED_REGION_OFF
);
3336 ppc440spe_adma_dma2rxor_inc_addr(
3337 desc
, cursor
, index
, src_cnt
);
3342 cursor
->addrl
= addr
;
3343 cursor
->xor_count
++;
3345 ppc440spe_adma_dma2rxor_inc_addr(
3346 desc
, cursor
, index
, src_cnt
);
3355 * ppc440spe_adma_dma2rxor_set_src - set RXOR source address; it's assumed that
3356 * ppc440spe_adma_dma2rxor_prep_src() has already done prior this call
3358 static void ppc440spe_adma_dma2rxor_set_src(
3359 struct ppc440spe_adma_desc_slot
*desc
,
3360 int index
, dma_addr_t addr
)
3362 struct xor_cb
*xcb
= desc
->hw_desc
;
3363 int k
= 0, op
= 0, lop
= 0;
3365 /* get the RXOR operand which corresponds to index addr */
3366 while (op
<= index
) {
3368 if (k
== XOR_MAX_OPS
) {
3370 desc
= list_entry(desc
->chain_node
.next
,
3371 struct ppc440spe_adma_desc_slot
, chain_node
);
3372 xcb
= desc
->hw_desc
;
3375 if ((xcb
->ops
[k
++].h
& (DMA_RXOR12
<< DMA_CUED_REGION_OFF
)) ==
3376 (DMA_RXOR12
<< DMA_CUED_REGION_OFF
))
3384 if (test_bit(k
-1, desc
->reverse_flags
)) {
3385 /* reverse operand order; put last op in RXOR group */
3386 if (index
== op
- 1)
3387 ppc440spe_rxor_set_src(desc
, k
- 1, addr
);
3389 /* direct operand order; put first op in RXOR group */
3391 ppc440spe_rxor_set_src(desc
, k
- 1, addr
);
3396 * ppc440spe_adma_dma2rxor_set_mult - set RXOR multipliers; it's assumed that
3397 * ppc440spe_adma_dma2rxor_prep_src() has already done prior this call
3399 static void ppc440spe_adma_dma2rxor_set_mult(
3400 struct ppc440spe_adma_desc_slot
*desc
,
3403 struct xor_cb
*xcb
= desc
->hw_desc
;
3404 int k
= 0, op
= 0, lop
= 0;
3406 /* get the RXOR operand which corresponds to index mult */
3407 while (op
<= index
) {
3409 if (k
== XOR_MAX_OPS
) {
3411 desc
= list_entry(desc
->chain_node
.next
,
3412 struct ppc440spe_adma_desc_slot
,
3414 xcb
= desc
->hw_desc
;
3417 if ((xcb
->ops
[k
++].h
& (DMA_RXOR12
<< DMA_CUED_REGION_OFF
)) ==
3418 (DMA_RXOR12
<< DMA_CUED_REGION_OFF
))
3425 if (test_bit(k
-1, desc
->reverse_flags
)) {
3427 ppc440spe_rxor_set_mult(desc
, k
- 1, op
- index
- 1, mult
);
3430 ppc440spe_rxor_set_mult(desc
, k
- 1, index
- lop
, mult
);
3435 * ppc440spe_init_rxor_cursor -
3437 static void ppc440spe_init_rxor_cursor(struct ppc440spe_rxor
*cursor
)
3439 memset(cursor
, 0, sizeof(struct ppc440spe_rxor
));
3444 * ppc440spe_adma_pq_set_src_mult - set multiplication coefficient into
3445 * descriptor for the PQXOR operation
3447 static void ppc440spe_adma_pq_set_src_mult(
3448 struct ppc440spe_adma_desc_slot
*sw_desc
,
3449 unsigned char mult
, int index
, int dst_pos
)
3451 struct ppc440spe_adma_chan
*chan
;
3452 u32 mult_idx
, mult_dst
;
3453 struct ppc440spe_adma_desc_slot
*iter
= NULL
, *iter1
= NULL
;
3455 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
3457 switch (chan
->device
->id
) {
3458 case PPC440SPE_DMA0_ID
:
3459 case PPC440SPE_DMA1_ID
:
3460 if (test_bit(PPC440SPE_DESC_RXOR
, &sw_desc
->flags
)) {
3461 int region
= test_bit(PPC440SPE_DESC_RXOR12
,
3462 &sw_desc
->flags
) ? 2 : 3;
3464 if (index
< region
) {
3465 /* RXOR multipliers */
3466 iter
= ppc440spe_get_group_entry(sw_desc
,
3467 sw_desc
->dst_cnt
- 1);
3468 if (sw_desc
->dst_cnt
== 2)
3469 iter1
= ppc440spe_get_group_entry(
3472 mult_idx
= DMA_CUED_MULT1_OFF
+ (index
<< 3);
3473 mult_dst
= DMA_CDB_SG_SRC
;
3475 /* WXOR multiplier */
3476 iter
= ppc440spe_get_group_entry(sw_desc
,
3479 mult_idx
= DMA_CUED_MULT1_OFF
;
3480 mult_dst
= dst_pos
? DMA_CDB_SG_DST2
:
3487 * skip first slots with destinations (if ZERO_DST has
3490 if (test_bit(PPC440SPE_ZERO_P
, &sw_desc
->flags
))
3492 if (test_bit(PPC440SPE_ZERO_Q
, &sw_desc
->flags
))
3495 iter
= ppc440spe_get_group_entry(sw_desc
, index
+ znum
);
3496 mult_idx
= DMA_CUED_MULT1_OFF
;
3497 mult_dst
= dst_pos
? DMA_CDB_SG_DST2
: DMA_CDB_SG_DST1
;
3501 ppc440spe_desc_set_src_mult(iter
, chan
,
3502 mult_idx
, mult_dst
, mult
);
3504 if (unlikely(iter1
)) {
3505 /* if we have two destinations for RXOR, then
3506 * we've just set Q mult. Set-up P now.
3508 ppc440spe_desc_set_src_mult(iter1
, chan
,
3509 mult_idx
, mult_dst
, 1);
3515 case PPC440SPE_XOR_ID
:
3516 iter
= sw_desc
->group_head
;
3517 if (sw_desc
->dst_cnt
== 2) {
3518 /* both P & Q calculations required; set P mult here */
3519 ppc440spe_adma_dma2rxor_set_mult(iter
, index
, 1);
3521 /* and then set Q mult */
3522 iter
= ppc440spe_get_group_entry(sw_desc
,
3523 sw_desc
->descs_per_op
);
3525 ppc440spe_adma_dma2rxor_set_mult(iter
, index
, mult
);
3531 * ppc440spe_adma_free_chan_resources - free the resources allocated
3533 static void ppc440spe_adma_free_chan_resources(struct dma_chan
*chan
)
3535 struct ppc440spe_adma_chan
*ppc440spe_chan
;
3536 struct ppc440spe_adma_desc_slot
*iter
, *_iter
;
3537 int in_use_descs
= 0;
3539 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
3540 ppc440spe_adma_slot_cleanup(ppc440spe_chan
);
3542 spin_lock_bh(&ppc440spe_chan
->lock
);
3543 list_for_each_entry_safe(iter
, _iter
, &ppc440spe_chan
->chain
,
3546 list_del(&iter
->chain_node
);
3548 list_for_each_entry_safe_reverse(iter
, _iter
,
3549 &ppc440spe_chan
->all_slots
, slot_node
) {
3550 list_del(&iter
->slot_node
);
3552 ppc440spe_chan
->slots_allocated
--;
3554 ppc440spe_chan
->last_used
= NULL
;
3556 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
3557 "ppc440spe adma%d %s slots_allocated %d\n",
3558 ppc440spe_chan
->device
->id
,
3559 __func__
, ppc440spe_chan
->slots_allocated
);
3560 spin_unlock_bh(&ppc440spe_chan
->lock
);
3562 /* one is ok since we left it on there on purpose */
3563 if (in_use_descs
> 1)
3564 printk(KERN_ERR
"SPE: Freeing %d in use descriptors!\n",
3569 * ppc440spe_adma_tx_status - poll the status of an ADMA transaction
3570 * @chan: ADMA channel handle
3571 * @cookie: ADMA transaction identifier
3572 * @txstate: a holder for the current state of the channel
3574 static enum dma_status
ppc440spe_adma_tx_status(struct dma_chan
*chan
,
3575 dma_cookie_t cookie
, struct dma_tx_state
*txstate
)
3577 struct ppc440spe_adma_chan
*ppc440spe_chan
;
3578 enum dma_status ret
;
3580 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
3581 ret
= dma_cookie_status(chan
, cookie
, txstate
);
3582 if (ret
== DMA_COMPLETE
)
3585 ppc440spe_adma_slot_cleanup(ppc440spe_chan
);
3587 return dma_cookie_status(chan
, cookie
, txstate
);
3591 * ppc440spe_adma_eot_handler - end of transfer interrupt handler
3593 static irqreturn_t
ppc440spe_adma_eot_handler(int irq
, void *data
)
3595 struct ppc440spe_adma_chan
*chan
= data
;
3597 dev_dbg(chan
->device
->common
.dev
,
3598 "ppc440spe adma%d: %s\n", chan
->device
->id
, __func__
);
3600 tasklet_schedule(&chan
->irq_tasklet
);
3601 ppc440spe_adma_device_clear_eot_status(chan
);
3607 * ppc440spe_adma_err_handler - DMA error interrupt handler;
3608 * do the same things as a eot handler
3610 static irqreturn_t
ppc440spe_adma_err_handler(int irq
, void *data
)
3612 struct ppc440spe_adma_chan
*chan
= data
;
3614 dev_dbg(chan
->device
->common
.dev
,
3615 "ppc440spe adma%d: %s\n", chan
->device
->id
, __func__
);
3617 tasklet_schedule(&chan
->irq_tasklet
);
3618 ppc440spe_adma_device_clear_eot_status(chan
);
3624 * ppc440spe_test_callback - called when test operation has been done
3626 static void ppc440spe_test_callback(void *unused
)
3628 complete(&ppc440spe_r6_test_comp
);
3632 * ppc440spe_adma_issue_pending - flush all pending descriptors to h/w
3634 static void ppc440spe_adma_issue_pending(struct dma_chan
*chan
)
3636 struct ppc440spe_adma_chan
*ppc440spe_chan
;
3638 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
3639 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
3640 "ppc440spe adma%d: %s %d \n", ppc440spe_chan
->device
->id
,
3641 __func__
, ppc440spe_chan
->pending
);
3643 if (ppc440spe_chan
->pending
) {
3644 ppc440spe_chan
->pending
= 0;
3645 ppc440spe_chan_append(ppc440spe_chan
);
3650 * ppc440spe_chan_start_null_xor - initiate the first XOR operation (DMA engines
3651 * use FIFOs (as opposite to chains used in XOR) so this is a XOR
3652 * specific operation)
3654 static void ppc440spe_chan_start_null_xor(struct ppc440spe_adma_chan
*chan
)
3656 struct ppc440spe_adma_desc_slot
*sw_desc
, *group_start
;
3657 dma_cookie_t cookie
;
3658 int slot_cnt
, slots_per_op
;
3660 dev_dbg(chan
->device
->common
.dev
,
3661 "ppc440spe adma%d: %s\n", chan
->device
->id
, __func__
);
3663 spin_lock_bh(&chan
->lock
);
3664 slot_cnt
= ppc440spe_chan_xor_slot_count(0, 2, &slots_per_op
);
3665 sw_desc
= ppc440spe_adma_alloc_slots(chan
, slot_cnt
, slots_per_op
);
3667 group_start
= sw_desc
->group_head
;
3668 list_splice_init(&sw_desc
->group_list
, &chan
->chain
);
3669 async_tx_ack(&sw_desc
->async_tx
);
3670 ppc440spe_desc_init_null_xor(group_start
);
3672 cookie
= dma_cookie_assign(&sw_desc
->async_tx
);
3674 /* initialize the completed cookie to be less than
3675 * the most recently used cookie
3677 chan
->common
.completed_cookie
= cookie
- 1;
3679 /* channel should not be busy */
3680 BUG_ON(ppc440spe_chan_is_busy(chan
));
3682 /* set the descriptor address */
3683 ppc440spe_chan_set_first_xor_descriptor(chan
, sw_desc
);
3685 /* run the descriptor */
3686 ppc440spe_chan_run(chan
);
3688 printk(KERN_ERR
"ppc440spe adma%d"
3689 " failed to allocate null descriptor\n",
3691 spin_unlock_bh(&chan
->lock
);
3695 * ppc440spe_test_raid6 - test are RAID-6 capabilities enabled successfully.
3696 * For this we just perform one WXOR operation with the same source
3697 * and destination addresses, the GF-multiplier is 1; so if RAID-6
3698 * capabilities are enabled then we'll get src/dst filled with zero.
3700 static int ppc440spe_test_raid6(struct ppc440spe_adma_chan
*chan
)
3702 struct ppc440spe_adma_desc_slot
*sw_desc
, *iter
;
3705 dma_addr_t dma_addr
, addrs
[2];
3706 unsigned long op
= 0;
3709 set_bit(PPC440SPE_DESC_WXOR
, &op
);
3711 pg
= alloc_page(GFP_KERNEL
);
3715 spin_lock_bh(&chan
->lock
);
3716 sw_desc
= ppc440spe_adma_alloc_slots(chan
, 1, 1);
3718 /* 1 src, 1 dsr, int_ena, WXOR */
3719 ppc440spe_desc_init_dma01pq(sw_desc
, 1, 1, 1, op
);
3720 list_for_each_entry(iter
, &sw_desc
->group_list
, chain_node
) {
3721 ppc440spe_desc_set_byte_count(iter
, chan
, PAGE_SIZE
);
3722 iter
->unmap_len
= PAGE_SIZE
;
3726 spin_unlock_bh(&chan
->lock
);
3729 spin_unlock_bh(&chan
->lock
);
3731 /* Fill the test page with ones */
3732 memset(page_address(pg
), 0xFF, PAGE_SIZE
);
3733 dma_addr
= dma_map_page(chan
->device
->dev
, pg
, 0,
3734 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
3736 /* Setup addresses */
3737 ppc440spe_adma_pq_set_src(sw_desc
, dma_addr
, 0);
3738 ppc440spe_adma_pq_set_src_mult(sw_desc
, 1, 0, 0);
3739 addrs
[0] = dma_addr
;
3741 ppc440spe_adma_pq_set_dest(sw_desc
, addrs
, DMA_PREP_PQ_DISABLE_Q
);
3743 async_tx_ack(&sw_desc
->async_tx
);
3744 sw_desc
->async_tx
.callback
= ppc440spe_test_callback
;
3745 sw_desc
->async_tx
.callback_param
= NULL
;
3747 init_completion(&ppc440spe_r6_test_comp
);
3749 ppc440spe_adma_tx_submit(&sw_desc
->async_tx
);
3750 ppc440spe_adma_issue_pending(&chan
->common
);
3752 wait_for_completion(&ppc440spe_r6_test_comp
);
3754 /* Now check if the test page is zeroed */
3755 a
= page_address(pg
);
3756 if ((*(u32
*)a
) == 0 && memcmp(a
, a
+4, PAGE_SIZE
-4) == 0) {
3757 /* page is zero - RAID-6 enabled */
3760 /* RAID-6 was not enabled */
3768 static void ppc440spe_adma_init_capabilities(struct ppc440spe_adma_device
*adev
)
3771 case PPC440SPE_DMA0_ID
:
3772 case PPC440SPE_DMA1_ID
:
3773 dma_cap_set(DMA_MEMCPY
, adev
->common
.cap_mask
);
3774 dma_cap_set(DMA_INTERRUPT
, adev
->common
.cap_mask
);
3775 dma_cap_set(DMA_PQ
, adev
->common
.cap_mask
);
3776 dma_cap_set(DMA_PQ_VAL
, adev
->common
.cap_mask
);
3777 dma_cap_set(DMA_XOR_VAL
, adev
->common
.cap_mask
);
3779 case PPC440SPE_XOR_ID
:
3780 dma_cap_set(DMA_XOR
, adev
->common
.cap_mask
);
3781 dma_cap_set(DMA_PQ
, adev
->common
.cap_mask
);
3782 dma_cap_set(DMA_INTERRUPT
, adev
->common
.cap_mask
);
3783 adev
->common
.cap_mask
= adev
->common
.cap_mask
;
3787 /* Set base routines */
3788 adev
->common
.device_alloc_chan_resources
=
3789 ppc440spe_adma_alloc_chan_resources
;
3790 adev
->common
.device_free_chan_resources
=
3791 ppc440spe_adma_free_chan_resources
;
3792 adev
->common
.device_tx_status
= ppc440spe_adma_tx_status
;
3793 adev
->common
.device_issue_pending
= ppc440spe_adma_issue_pending
;
3795 /* Set prep routines based on capability */
3796 if (dma_has_cap(DMA_MEMCPY
, adev
->common
.cap_mask
)) {
3797 adev
->common
.device_prep_dma_memcpy
=
3798 ppc440spe_adma_prep_dma_memcpy
;
3800 if (dma_has_cap(DMA_XOR
, adev
->common
.cap_mask
)) {
3801 adev
->common
.max_xor
= XOR_MAX_OPS
;
3802 adev
->common
.device_prep_dma_xor
=
3803 ppc440spe_adma_prep_dma_xor
;
3805 if (dma_has_cap(DMA_PQ
, adev
->common
.cap_mask
)) {
3807 case PPC440SPE_DMA0_ID
:
3808 dma_set_maxpq(&adev
->common
,
3809 DMA0_FIFO_SIZE
/ sizeof(struct dma_cdb
), 0);
3811 case PPC440SPE_DMA1_ID
:
3812 dma_set_maxpq(&adev
->common
,
3813 DMA1_FIFO_SIZE
/ sizeof(struct dma_cdb
), 0);
3815 case PPC440SPE_XOR_ID
:
3816 adev
->common
.max_pq
= XOR_MAX_OPS
* 3;
3819 adev
->common
.device_prep_dma_pq
=
3820 ppc440spe_adma_prep_dma_pq
;
3822 if (dma_has_cap(DMA_PQ_VAL
, adev
->common
.cap_mask
)) {
3824 case PPC440SPE_DMA0_ID
:
3825 adev
->common
.max_pq
= DMA0_FIFO_SIZE
/
3826 sizeof(struct dma_cdb
);
3828 case PPC440SPE_DMA1_ID
:
3829 adev
->common
.max_pq
= DMA1_FIFO_SIZE
/
3830 sizeof(struct dma_cdb
);
3833 adev
->common
.device_prep_dma_pq_val
=
3834 ppc440spe_adma_prep_dma_pqzero_sum
;
3836 if (dma_has_cap(DMA_XOR_VAL
, adev
->common
.cap_mask
)) {
3838 case PPC440SPE_DMA0_ID
:
3839 adev
->common
.max_xor
= DMA0_FIFO_SIZE
/
3840 sizeof(struct dma_cdb
);
3842 case PPC440SPE_DMA1_ID
:
3843 adev
->common
.max_xor
= DMA1_FIFO_SIZE
/
3844 sizeof(struct dma_cdb
);
3847 adev
->common
.device_prep_dma_xor_val
=
3848 ppc440spe_adma_prep_dma_xor_zero_sum
;
3850 if (dma_has_cap(DMA_INTERRUPT
, adev
->common
.cap_mask
)) {
3851 adev
->common
.device_prep_dma_interrupt
=
3852 ppc440spe_adma_prep_dma_interrupt
;
3854 pr_info("%s: AMCC(R) PPC440SP(E) ADMA Engine: "
3855 "( %s%s%s%s%s%s)\n",
3856 dev_name(adev
->dev
),
3857 dma_has_cap(DMA_PQ
, adev
->common
.cap_mask
) ? "pq " : "",
3858 dma_has_cap(DMA_PQ_VAL
, adev
->common
.cap_mask
) ? "pq_val " : "",
3859 dma_has_cap(DMA_XOR
, adev
->common
.cap_mask
) ? "xor " : "",
3860 dma_has_cap(DMA_XOR_VAL
, adev
->common
.cap_mask
) ? "xor_val " : "",
3861 dma_has_cap(DMA_MEMCPY
, adev
->common
.cap_mask
) ? "memcpy " : "",
3862 dma_has_cap(DMA_INTERRUPT
, adev
->common
.cap_mask
) ? "intr " : "");
3865 static int ppc440spe_adma_setup_irqs(struct ppc440spe_adma_device
*adev
,
3866 struct ppc440spe_adma_chan
*chan
,
3869 struct platform_device
*ofdev
;
3870 struct device_node
*np
;
3873 ofdev
= container_of(adev
->dev
, struct platform_device
, dev
);
3874 np
= ofdev
->dev
.of_node
;
3875 if (adev
->id
!= PPC440SPE_XOR_ID
) {
3876 adev
->err_irq
= irq_of_parse_and_map(np
, 1);
3877 if (!adev
->err_irq
) {
3878 dev_warn(adev
->dev
, "no err irq resource?\n");
3879 *initcode
= PPC_ADMA_INIT_IRQ2
;
3880 adev
->err_irq
= -ENXIO
;
3882 atomic_inc(&ppc440spe_adma_err_irq_ref
);
3884 adev
->err_irq
= -ENXIO
;
3887 adev
->irq
= irq_of_parse_and_map(np
, 0);
3889 dev_err(adev
->dev
, "no irq resource\n");
3890 *initcode
= PPC_ADMA_INIT_IRQ1
;
3894 dev_dbg(adev
->dev
, "irq %d, err irq %d\n",
3895 adev
->irq
, adev
->err_irq
);
3897 ret
= request_irq(adev
->irq
, ppc440spe_adma_eot_handler
,
3898 0, dev_driver_string(adev
->dev
), chan
);
3900 dev_err(adev
->dev
, "can't request irq %d\n",
3902 *initcode
= PPC_ADMA_INIT_IRQ1
;
3907 /* only DMA engines have a separate error IRQ
3908 * so it's Ok if err_irq < 0 in XOR engine case.
3910 if (adev
->err_irq
> 0) {
3911 /* both DMA engines share common error IRQ */
3912 ret
= request_irq(adev
->err_irq
,
3913 ppc440spe_adma_err_handler
,
3915 dev_driver_string(adev
->dev
),
3918 dev_err(adev
->dev
, "can't request irq %d\n",
3920 *initcode
= PPC_ADMA_INIT_IRQ2
;
3926 if (adev
->id
== PPC440SPE_XOR_ID
) {
3927 /* enable XOR engine interrupts */
3928 iowrite32be(XOR_IE_CBCIE_BIT
| XOR_IE_ICBIE_BIT
|
3929 XOR_IE_ICIE_BIT
| XOR_IE_RPTIE_BIT
,
3930 &adev
->xor_reg
->ier
);
3934 np
= of_find_compatible_node(NULL
, NULL
, "ibm,i2o-440spe");
3936 pr_err("%s: can't find I2O device tree node\n",
3941 adev
->i2o_reg
= of_iomap(np
, 0);
3942 if (!adev
->i2o_reg
) {
3943 pr_err("%s: failed to map I2O registers\n", __func__
);
3949 /* Unmask 'CS FIFO Attention' interrupts and
3950 * enable generating interrupts on errors
3952 enable
= (adev
->id
== PPC440SPE_DMA0_ID
) ?
3953 ~(I2O_IOPIM_P0SNE
| I2O_IOPIM_P0EM
) :
3954 ~(I2O_IOPIM_P1SNE
| I2O_IOPIM_P1EM
);
3955 mask
= ioread32(&adev
->i2o_reg
->iopim
) & enable
;
3956 iowrite32(mask
, &adev
->i2o_reg
->iopim
);
3961 free_irq(adev
->irq
, chan
);
3963 irq_dispose_mapping(adev
->irq
);
3965 if (adev
->err_irq
> 0) {
3966 if (atomic_dec_and_test(&ppc440spe_adma_err_irq_ref
))
3967 irq_dispose_mapping(adev
->err_irq
);
3972 static void ppc440spe_adma_release_irqs(struct ppc440spe_adma_device
*adev
,
3973 struct ppc440spe_adma_chan
*chan
)
3977 if (adev
->id
== PPC440SPE_XOR_ID
) {
3978 /* disable XOR engine interrupts */
3979 mask
= ioread32be(&adev
->xor_reg
->ier
);
3980 mask
&= ~(XOR_IE_CBCIE_BIT
| XOR_IE_ICBIE_BIT
|
3981 XOR_IE_ICIE_BIT
| XOR_IE_RPTIE_BIT
);
3982 iowrite32be(mask
, &adev
->xor_reg
->ier
);
3984 /* disable DMAx engine interrupts */
3985 disable
= (adev
->id
== PPC440SPE_DMA0_ID
) ?
3986 (I2O_IOPIM_P0SNE
| I2O_IOPIM_P0EM
) :
3987 (I2O_IOPIM_P1SNE
| I2O_IOPIM_P1EM
);
3988 mask
= ioread32(&adev
->i2o_reg
->iopim
) | disable
;
3989 iowrite32(mask
, &adev
->i2o_reg
->iopim
);
3991 free_irq(adev
->irq
, chan
);
3992 irq_dispose_mapping(adev
->irq
);
3993 if (adev
->err_irq
> 0) {
3994 free_irq(adev
->err_irq
, chan
);
3995 if (atomic_dec_and_test(&ppc440spe_adma_err_irq_ref
)) {
3996 irq_dispose_mapping(adev
->err_irq
);
3997 iounmap(adev
->i2o_reg
);
4003 * ppc440spe_adma_probe - probe the asynch device
4005 static int ppc440spe_adma_probe(struct platform_device
*ofdev
)
4007 struct device_node
*np
= ofdev
->dev
.of_node
;
4008 struct resource res
;
4009 struct ppc440spe_adma_device
*adev
;
4010 struct ppc440spe_adma_chan
*chan
;
4011 struct ppc_dma_chan_ref
*ref
, *_ref
;
4012 int ret
= 0, initcode
= PPC_ADMA_INIT_OK
;
4018 if (of_device_is_compatible(np
, "amcc,xor-accelerator")) {
4019 id
= PPC440SPE_XOR_ID
;
4020 /* As far as the XOR engine is concerned, it does not
4021 * use FIFOs but uses linked list. So there is no dependency
4022 * between pool size to allocate and the engine configuration.
4024 pool_size
= PAGE_SIZE
<< 1;
4026 /* it is DMA0 or DMA1 */
4027 idx
= of_get_property(np
, "cell-index", &len
);
4028 if (!idx
|| (len
!= sizeof(u32
))) {
4029 dev_err(&ofdev
->dev
, "Device node %pOF has missing "
4030 "or invalid cell-index property\n",
4035 /* DMA0,1 engines use FIFO to maintain CDBs, so we
4036 * should allocate the pool accordingly to size of this
4037 * FIFO. Thus, the pool size depends on the FIFO depth:
4038 * how much CDBs pointers the FIFO may contain then so
4039 * much CDBs we should provide in the pool.
4042 * CDBs number = (DMA0_FIFO_SIZE >> 3);
4043 * Pool size = CDBs number * CDB size =
4044 * = (DMA0_FIFO_SIZE >> 3) << 5 = DMA0_FIFO_SIZE << 2.
4046 pool_size
= (id
== PPC440SPE_DMA0_ID
) ?
4047 DMA0_FIFO_SIZE
: DMA1_FIFO_SIZE
;
4051 if (of_address_to_resource(np
, 0, &res
)) {
4052 dev_err(&ofdev
->dev
, "failed to get memory resource\n");
4053 initcode
= PPC_ADMA_INIT_MEMRES
;
4058 if (!request_mem_region(res
.start
, resource_size(&res
),
4059 dev_driver_string(&ofdev
->dev
))) {
4060 dev_err(&ofdev
->dev
, "failed to request memory region %pR\n",
4062 initcode
= PPC_ADMA_INIT_MEMREG
;
4067 /* create a device */
4068 adev
= kzalloc(sizeof(*adev
), GFP_KERNEL
);
4070 initcode
= PPC_ADMA_INIT_ALLOC
;
4072 goto err_adev_alloc
;
4076 adev
->pool_size
= pool_size
;
4077 /* allocate coherent memory for hardware descriptors */
4078 adev
->dma_desc_pool_virt
= dma_alloc_coherent(&ofdev
->dev
,
4079 adev
->pool_size
, &adev
->dma_desc_pool
,
4081 if (adev
->dma_desc_pool_virt
== NULL
) {
4082 dev_err(&ofdev
->dev
, "failed to allocate %d bytes of coherent "
4083 "memory for hardware descriptors\n",
4085 initcode
= PPC_ADMA_INIT_COHERENT
;
4089 dev_dbg(&ofdev
->dev
, "allocated descriptor pool virt 0x%p phys 0x%llx\n",
4090 adev
->dma_desc_pool_virt
, (u64
)adev
->dma_desc_pool
);
4092 regs
= ioremap(res
.start
, resource_size(&res
));
4094 dev_err(&ofdev
->dev
, "failed to ioremap regs!\n");
4096 goto err_regs_alloc
;
4099 if (adev
->id
== PPC440SPE_XOR_ID
) {
4100 adev
->xor_reg
= regs
;
4102 iowrite32be(XOR_CRSR_XASR_BIT
, &adev
->xor_reg
->crsr
);
4103 iowrite32be(XOR_CRSR_64BA_BIT
, &adev
->xor_reg
->crrr
);
4105 size_t fifo_size
= (adev
->id
== PPC440SPE_DMA0_ID
) ?
4106 DMA0_FIFO_SIZE
: DMA1_FIFO_SIZE
;
4107 adev
->dma_reg
= regs
;
4108 /* DMAx_FIFO_SIZE is defined in bytes,
4109 * <fsiz> - is defined in number of CDB pointers (8byte).
4110 * DMA FIFO Length = CSlength + CPlength, where
4111 * CSlength = CPlength = (fsiz + 1) * 8.
4113 iowrite32(DMA_FIFO_ENABLE
| ((fifo_size
>> 3) - 2),
4114 &adev
->dma_reg
->fsiz
);
4115 /* Configure DMA engine */
4116 iowrite32(DMA_CFG_DXEPR_HP
| DMA_CFG_DFMPP_HP
| DMA_CFG_FALGN
,
4117 &adev
->dma_reg
->cfg
);
4119 iowrite32(~0, &adev
->dma_reg
->dsts
);
4122 adev
->dev
= &ofdev
->dev
;
4123 adev
->common
.dev
= &ofdev
->dev
;
4124 INIT_LIST_HEAD(&adev
->common
.channels
);
4125 platform_set_drvdata(ofdev
, adev
);
4127 /* create a channel */
4128 chan
= kzalloc(sizeof(*chan
), GFP_KERNEL
);
4130 initcode
= PPC_ADMA_INIT_CHANNEL
;
4132 goto err_chan_alloc
;
4135 spin_lock_init(&chan
->lock
);
4136 INIT_LIST_HEAD(&chan
->chain
);
4137 INIT_LIST_HEAD(&chan
->all_slots
);
4138 chan
->device
= adev
;
4139 chan
->common
.device
= &adev
->common
;
4140 dma_cookie_init(&chan
->common
);
4141 list_add_tail(&chan
->common
.device_node
, &adev
->common
.channels
);
4142 tasklet_setup(&chan
->irq_tasklet
, ppc440spe_adma_tasklet
);
4144 /* allocate and map helper pages for async validation or
4145 * async_mult/async_sum_product operations on DMA0/1.
4147 if (adev
->id
!= PPC440SPE_XOR_ID
) {
4148 chan
->pdest_page
= alloc_page(GFP_KERNEL
);
4149 chan
->qdest_page
= alloc_page(GFP_KERNEL
);
4150 if (!chan
->pdest_page
||
4151 !chan
->qdest_page
) {
4152 if (chan
->pdest_page
)
4153 __free_page(chan
->pdest_page
);
4154 if (chan
->qdest_page
)
4155 __free_page(chan
->qdest_page
);
4157 goto err_page_alloc
;
4159 chan
->pdest
= dma_map_page(&ofdev
->dev
, chan
->pdest_page
, 0,
4160 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4161 chan
->qdest
= dma_map_page(&ofdev
->dev
, chan
->qdest_page
, 0,
4162 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4165 ref
= kmalloc(sizeof(*ref
), GFP_KERNEL
);
4167 ref
->chan
= &chan
->common
;
4168 INIT_LIST_HEAD(&ref
->node
);
4169 list_add_tail(&ref
->node
, &ppc440spe_adma_chan_list
);
4171 dev_err(&ofdev
->dev
, "failed to allocate channel reference!\n");
4176 ret
= ppc440spe_adma_setup_irqs(adev
, chan
, &initcode
);
4180 ppc440spe_adma_init_capabilities(adev
);
4182 ret
= dma_async_device_register(&adev
->common
);
4184 initcode
= PPC_ADMA_INIT_REGISTER
;
4185 dev_err(&ofdev
->dev
, "failed to register dma device\n");
4192 ppc440spe_adma_release_irqs(adev
, chan
);
4194 list_for_each_entry_safe(ref
, _ref
, &ppc440spe_adma_chan_list
, node
) {
4195 if (chan
== to_ppc440spe_adma_chan(ref
->chan
)) {
4196 list_del(&ref
->node
);
4201 if (adev
->id
!= PPC440SPE_XOR_ID
) {
4202 dma_unmap_page(&ofdev
->dev
, chan
->pdest
,
4203 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4204 dma_unmap_page(&ofdev
->dev
, chan
->qdest
,
4205 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4206 __free_page(chan
->pdest_page
);
4207 __free_page(chan
->qdest_page
);
4212 if (adev
->id
== PPC440SPE_XOR_ID
)
4213 iounmap(adev
->xor_reg
);
4215 iounmap(adev
->dma_reg
);
4217 dma_free_coherent(adev
->dev
, adev
->pool_size
,
4218 adev
->dma_desc_pool_virt
,
4219 adev
->dma_desc_pool
);
4223 release_mem_region(res
.start
, resource_size(&res
));
4225 if (id
< PPC440SPE_ADMA_ENGINES_NUM
)
4226 ppc440spe_adma_devices
[id
] = initcode
;
4232 * ppc440spe_adma_remove - remove the asynch device
4234 static int ppc440spe_adma_remove(struct platform_device
*ofdev
)
4236 struct ppc440spe_adma_device
*adev
= platform_get_drvdata(ofdev
);
4237 struct device_node
*np
= ofdev
->dev
.of_node
;
4238 struct resource res
;
4239 struct dma_chan
*chan
, *_chan
;
4240 struct ppc_dma_chan_ref
*ref
, *_ref
;
4241 struct ppc440spe_adma_chan
*ppc440spe_chan
;
4243 if (adev
->id
< PPC440SPE_ADMA_ENGINES_NUM
)
4244 ppc440spe_adma_devices
[adev
->id
] = -1;
4246 dma_async_device_unregister(&adev
->common
);
4248 list_for_each_entry_safe(chan
, _chan
, &adev
->common
.channels
,
4250 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
4251 ppc440spe_adma_release_irqs(adev
, ppc440spe_chan
);
4252 tasklet_kill(&ppc440spe_chan
->irq_tasklet
);
4253 if (adev
->id
!= PPC440SPE_XOR_ID
) {
4254 dma_unmap_page(&ofdev
->dev
, ppc440spe_chan
->pdest
,
4255 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4256 dma_unmap_page(&ofdev
->dev
, ppc440spe_chan
->qdest
,
4257 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4258 __free_page(ppc440spe_chan
->pdest_page
);
4259 __free_page(ppc440spe_chan
->qdest_page
);
4261 list_for_each_entry_safe(ref
, _ref
, &ppc440spe_adma_chan_list
,
4263 if (ppc440spe_chan
==
4264 to_ppc440spe_adma_chan(ref
->chan
)) {
4265 list_del(&ref
->node
);
4269 list_del(&chan
->device_node
);
4270 kfree(ppc440spe_chan
);
4273 dma_free_coherent(adev
->dev
, adev
->pool_size
,
4274 adev
->dma_desc_pool_virt
, adev
->dma_desc_pool
);
4275 if (adev
->id
== PPC440SPE_XOR_ID
)
4276 iounmap(adev
->xor_reg
);
4278 iounmap(adev
->dma_reg
);
4279 of_address_to_resource(np
, 0, &res
);
4280 release_mem_region(res
.start
, resource_size(&res
));
4286 * /sys driver interface to enable h/w RAID-6 capabilities
4287 * Files created in e.g. /sys/devices/plb.0/400100100.dma0/driver/
4288 * directory are "devices", "enable" and "poly".
4289 * "devices" shows available engines.
4290 * "enable" is used to enable RAID-6 capabilities or to check
4291 * whether these has been activated.
4292 * "poly" allows setting/checking used polynomial (for PPC440SPe only).
4295 static ssize_t
devices_show(struct device_driver
*dev
, char *buf
)
4300 for (i
= 0; i
< PPC440SPE_ADMA_ENGINES_NUM
; i
++) {
4301 if (ppc440spe_adma_devices
[i
] == -1)
4303 size
+= scnprintf(buf
+ size
, PAGE_SIZE
- size
,
4304 "PPC440SP(E)-ADMA.%d: %s\n", i
,
4305 ppc_adma_errors
[ppc440spe_adma_devices
[i
]]);
4309 static DRIVER_ATTR_RO(devices
);
4311 static ssize_t
enable_show(struct device_driver
*dev
, char *buf
)
4313 return snprintf(buf
, PAGE_SIZE
,
4314 "PPC440SP(e) RAID-6 capabilities are %sABLED.\n",
4315 ppc440spe_r6_enabled
? "EN" : "DIS");
4318 static ssize_t
enable_store(struct device_driver
*dev
, const char *buf
,
4323 if (!count
|| count
> 11)
4326 if (!ppc440spe_r6_tchan
)
4330 sscanf(buf
, "%lx", &val
);
4331 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_XORBA
, val
);
4334 /* Verify whether it really works now */
4335 if (ppc440spe_test_raid6(ppc440spe_r6_tchan
) == 0) {
4336 pr_info("PPC440SP(e) RAID-6 has been activated "
4338 ppc440spe_r6_enabled
= 1;
4340 pr_info("PPC440SP(e) RAID-6 hasn't been activated!"
4342 ppc440spe_r6_enabled
= 0;
4346 static DRIVER_ATTR_RW(enable
);
4348 static ssize_t
poly_show(struct device_driver
*dev
, char *buf
)
4354 /* 440SP has fixed polynomial */
4357 reg
= dcr_read(ppc440spe_mq_dcr_host
, DCRN_MQ0_CFBHL
);
4358 reg
>>= MQ0_CFBHL_POLY
;
4362 size
= snprintf(buf
, PAGE_SIZE
, "PPC440SP(e) RAID-6 driver "
4363 "uses 0x1%02x polynomial.\n", reg
);
4367 static ssize_t
poly_store(struct device_driver
*dev
, const char *buf
,
4370 unsigned long reg
, val
;
4373 /* 440SP uses default 0x14D polynomial only */
4377 if (!count
|| count
> 6)
4380 /* e.g., 0x14D or 0x11D */
4381 sscanf(buf
, "%lx", &val
);
4387 reg
= dcr_read(ppc440spe_mq_dcr_host
, DCRN_MQ0_CFBHL
);
4388 reg
&= ~(0xFF << MQ0_CFBHL_POLY
);
4389 reg
|= val
<< MQ0_CFBHL_POLY
;
4390 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_CFBHL
, reg
);
4394 static DRIVER_ATTR_RW(poly
);
4397 * Common initialisation for RAID engines; allocate memory for
4398 * DMAx FIFOs, perform configuration common for all DMA engines.
4399 * Further DMA engine specific configuration is done at probe time.
4401 static int ppc440spe_configure_raid_devices(void)
4403 struct device_node
*np
;
4404 struct resource i2o_res
;
4405 struct i2o_regs __iomem
*i2o_reg
;
4406 dcr_host_t i2o_dcr_host
;
4407 unsigned int dcr_base
, dcr_len
;
4410 np
= of_find_compatible_node(NULL
, NULL
, "ibm,i2o-440spe");
4412 pr_err("%s: can't find I2O device tree node\n",
4417 if (of_address_to_resource(np
, 0, &i2o_res
)) {
4422 i2o_reg
= of_iomap(np
, 0);
4424 pr_err("%s: failed to map I2O registers\n", __func__
);
4429 /* Get I2O DCRs base */
4430 dcr_base
= dcr_resource_start(np
, 0);
4431 dcr_len
= dcr_resource_len(np
, 0);
4432 if (!dcr_base
&& !dcr_len
) {
4433 pr_err("%pOF: can't get DCR registers base/len!\n", np
);
4439 i2o_dcr_host
= dcr_map(np
, dcr_base
, dcr_len
);
4440 if (!DCR_MAP_OK(i2o_dcr_host
)) {
4441 pr_err("%pOF: failed to map DCRs!\n", np
);
4448 /* Provide memory regions for DMA's FIFOs: I2O, DMA0 and DMA1 share
4449 * the base address of FIFO memory space.
4450 * Actually we need twice more physical memory than programmed in the
4451 * <fsiz> register (because there are two FIFOs for each DMA: CP and CS)
4453 ppc440spe_dma_fifo_buf
= kmalloc((DMA0_FIFO_SIZE
+ DMA1_FIFO_SIZE
) << 1,
4455 if (!ppc440spe_dma_fifo_buf
) {
4456 pr_err("%s: DMA FIFO buffer allocation failed.\n", __func__
);
4458 dcr_unmap(i2o_dcr_host
, dcr_len
);
4466 mtdcri(SDR0
, DCRN_SDR0_SRST
, DCRN_SDR0_SRST_I2ODMA
);
4467 mtdcri(SDR0
, DCRN_SDR0_SRST
, 0);
4469 /* Setup the base address of mmaped registers */
4470 dcr_write(i2o_dcr_host
, DCRN_I2O0_IBAH
, (u32
)(i2o_res
.start
>> 32));
4471 dcr_write(i2o_dcr_host
, DCRN_I2O0_IBAL
, (u32
)(i2o_res
.start
) |
4473 dcr_unmap(i2o_dcr_host
, dcr_len
);
4475 /* Setup FIFO memory space base address */
4476 iowrite32(0, &i2o_reg
->ifbah
);
4477 iowrite32(((u32
)__pa(ppc440spe_dma_fifo_buf
)), &i2o_reg
->ifbal
);
4479 /* set zero FIFO size for I2O, so the whole
4480 * ppc440spe_dma_fifo_buf is used by DMAs.
4481 * DMAx_FIFOs will be configured while probe.
4483 iowrite32(0, &i2o_reg
->ifsiz
);
4486 /* To prepare WXOR/RXOR functionality we need access to
4487 * Memory Queue Module DCRs (finally it will be enabled
4488 * via /sys interface of the ppc440spe ADMA driver).
4490 np
= of_find_compatible_node(NULL
, NULL
, "ibm,mq-440spe");
4492 pr_err("%s: can't find MQ device tree node\n",
4498 /* Get MQ DCRs base */
4499 dcr_base
= dcr_resource_start(np
, 0);
4500 dcr_len
= dcr_resource_len(np
, 0);
4501 if (!dcr_base
&& !dcr_len
) {
4502 pr_err("%pOF: can't get DCR registers base/len!\n", np
);
4507 ppc440spe_mq_dcr_host
= dcr_map(np
, dcr_base
, dcr_len
);
4508 if (!DCR_MAP_OK(ppc440spe_mq_dcr_host
)) {
4509 pr_err("%pOF: failed to map DCRs!\n", np
);
4514 ppc440spe_mq_dcr_len
= dcr_len
;
4517 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_BAUH
, DMA_CUED_XOR_HB
);
4520 * - LL transaction passing limit to 1;
4521 * - Memory controller cycle limit to 1;
4522 * - Galois Polynomial to 0x14d (default)
4524 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_CFBHL
,
4525 (1 << MQ0_CFBHL_TPLM
) | (1 << MQ0_CFBHL_HBCL
) |
4526 (PPC440SPE_DEFAULT_POLY
<< MQ0_CFBHL_POLY
));
4528 atomic_set(&ppc440spe_adma_err_irq_ref
, 0);
4529 for (i
= 0; i
< PPC440SPE_ADMA_ENGINES_NUM
; i
++)
4530 ppc440spe_adma_devices
[i
] = -1;
4537 kfree(ppc440spe_dma_fifo_buf
);
4541 static const struct of_device_id ppc440spe_adma_of_match
[] = {
4542 { .compatible
= "ibm,dma-440spe", },
4543 { .compatible
= "amcc,xor-accelerator", },
4546 MODULE_DEVICE_TABLE(of
, ppc440spe_adma_of_match
);
4548 static struct platform_driver ppc440spe_adma_driver
= {
4549 .probe
= ppc440spe_adma_probe
,
4550 .remove
= ppc440spe_adma_remove
,
4552 .name
= "PPC440SP(E)-ADMA",
4553 .of_match_table
= ppc440spe_adma_of_match
,
4557 static __init
int ppc440spe_adma_init(void)
4561 ret
= ppc440spe_configure_raid_devices();
4565 ret
= platform_driver_register(&ppc440spe_adma_driver
);
4567 pr_err("%s: failed to register platform driver\n",
4572 /* Initialization status */
4573 ret
= driver_create_file(&ppc440spe_adma_driver
.driver
,
4574 &driver_attr_devices
);
4578 /* RAID-6 h/w enable entry */
4579 ret
= driver_create_file(&ppc440spe_adma_driver
.driver
,
4580 &driver_attr_enable
);
4584 /* GF polynomial to use */
4585 ret
= driver_create_file(&ppc440spe_adma_driver
.driver
,
4590 driver_remove_file(&ppc440spe_adma_driver
.driver
,
4591 &driver_attr_enable
);
4593 driver_remove_file(&ppc440spe_adma_driver
.driver
,
4594 &driver_attr_devices
);
4596 /* User will not be able to enable h/w RAID-6 */
4597 pr_err("%s: failed to create RAID-6 driver interface\n",
4599 platform_driver_unregister(&ppc440spe_adma_driver
);
4601 dcr_unmap(ppc440spe_mq_dcr_host
, ppc440spe_mq_dcr_len
);
4602 kfree(ppc440spe_dma_fifo_buf
);
4606 static void __exit
ppc440spe_adma_exit(void)
4608 driver_remove_file(&ppc440spe_adma_driver
.driver
,
4610 driver_remove_file(&ppc440spe_adma_driver
.driver
,
4611 &driver_attr_enable
);
4612 driver_remove_file(&ppc440spe_adma_driver
.driver
,
4613 &driver_attr_devices
);
4614 platform_driver_unregister(&ppc440spe_adma_driver
);
4615 dcr_unmap(ppc440spe_mq_dcr_host
, ppc440spe_mq_dcr_len
);
4616 kfree(ppc440spe_dma_fifo_buf
);
4619 arch_initcall(ppc440spe_adma_init
);
4620 module_exit(ppc440spe_adma_exit
);
4622 MODULE_AUTHOR("Yuri Tikhonov <yur@emcraft.com>");
4623 MODULE_DESCRIPTION("PPC440SPE ADMA Engine Driver");
4624 MODULE_LICENSE("GPL");