2 * Copyright (C) 2006-2009 DENX Software Engineering.
4 * Author: Yuri Tikhonov <yur@emcraft.com>
6 * Further porting to arch/powerpc by
7 * Anatolij Gustschin <agust@denx.de>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along with
20 * this program; if not, write to the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * The full GNU General Public License is included in this distribution in the
24 * file called COPYING.
28 * This driver supports the asynchrounous DMA copy and RAID engines available
29 * on the AMCC PPC440SPe Processors.
30 * Based on the Intel Xscale(R) family of I/O Processors (IOP 32x, 33x, 134x)
31 * ADMA driver written by D.Williams.
34 #include <linux/init.h>
35 #include <linux/module.h>
36 #include <linux/async_tx.h>
37 #include <linux/delay.h>
38 #include <linux/dma-mapping.h>
39 #include <linux/spinlock.h>
40 #include <linux/interrupt.h>
41 #include <linux/slab.h>
42 #include <linux/uaccess.h>
43 #include <linux/proc_fs.h>
45 #include <linux/of_platform.h>
47 #include <asm/dcr-regs.h>
50 enum ppc_adma_init_code
{
55 PPC_ADMA_INIT_COHERENT
,
56 PPC_ADMA_INIT_CHANNEL
,
59 PPC_ADMA_INIT_REGISTER
62 static char *ppc_adma_errors
[] = {
63 [PPC_ADMA_INIT_OK
] = "ok",
64 [PPC_ADMA_INIT_MEMRES
] = "failed to get memory resource",
65 [PPC_ADMA_INIT_MEMREG
] = "failed to request memory region",
66 [PPC_ADMA_INIT_ALLOC
] = "failed to allocate memory for adev "
68 [PPC_ADMA_INIT_COHERENT
] = "failed to allocate coherent memory for "
69 "hardware descriptors",
70 [PPC_ADMA_INIT_CHANNEL
] = "failed to allocate memory for channel",
71 [PPC_ADMA_INIT_IRQ1
] = "failed to request first irq",
72 [PPC_ADMA_INIT_IRQ2
] = "failed to request second irq",
73 [PPC_ADMA_INIT_REGISTER
] = "failed to register dma async device",
76 static enum ppc_adma_init_code
77 ppc440spe_adma_devices
[PPC440SPE_ADMA_ENGINES_NUM
];
79 struct ppc_dma_chan_ref
{
80 struct dma_chan
*chan
;
81 struct list_head node
;
84 /* The list of channels exported by ppc440spe ADMA */
86 ppc440spe_adma_chan_list
= LIST_HEAD_INIT(ppc440spe_adma_chan_list
);
88 /* This flag is set when want to refetch the xor chain in the interrupt
91 static u32 do_xor_refetch
;
93 /* Pointer to DMA0, DMA1 CP/CS FIFO */
94 static void *ppc440spe_dma_fifo_buf
;
96 /* Pointers to last submitted to DMA0, DMA1 CDBs */
97 static struct ppc440spe_adma_desc_slot
*chan_last_sub
[3];
98 static struct ppc440spe_adma_desc_slot
*chan_first_cdb
[3];
100 /* Pointer to last linked and submitted xor CB */
101 static struct ppc440spe_adma_desc_slot
*xor_last_linked
;
102 static struct ppc440spe_adma_desc_slot
*xor_last_submit
;
104 /* This array is used in data-check operations for storing a pattern */
105 static char ppc440spe_qword
[16];
107 static atomic_t ppc440spe_adma_err_irq_ref
;
108 static dcr_host_t ppc440spe_mq_dcr_host
;
109 static unsigned int ppc440spe_mq_dcr_len
;
111 /* Since RXOR operations use the common register (MQ0_CF2H) for setting-up
112 * the block size in transactions, then we do not allow to activate more than
113 * only one RXOR transactions simultaneously. So use this var to store
114 * the information about is RXOR currently active (PPC440SPE_RXOR_RUN bit is
115 * set) or not (PPC440SPE_RXOR_RUN is clear).
117 static unsigned long ppc440spe_rxor_state
;
119 /* These are used in enable & check routines
121 static u32 ppc440spe_r6_enabled
;
122 static struct ppc440spe_adma_chan
*ppc440spe_r6_tchan
;
123 static struct completion ppc440spe_r6_test_comp
;
125 static int ppc440spe_adma_dma2rxor_prep_src(
126 struct ppc440spe_adma_desc_slot
*desc
,
127 struct ppc440spe_rxor
*cursor
, int index
,
128 int src_cnt
, u32 addr
);
129 static void ppc440spe_adma_dma2rxor_set_src(
130 struct ppc440spe_adma_desc_slot
*desc
,
131 int index
, dma_addr_t addr
);
132 static void ppc440spe_adma_dma2rxor_set_mult(
133 struct ppc440spe_adma_desc_slot
*desc
,
137 #define ADMA_LL_DBG(x) ({ if (1) x; 0; })
139 #define ADMA_LL_DBG(x) ({ if (0) x; 0; })
142 static void print_cb(struct ppc440spe_adma_chan
*chan
, void *block
)
148 switch (chan
->device
->id
) {
153 pr_debug("CDB at %p [%d]:\n"
154 "\t attr 0x%02x opc 0x%02x cnt 0x%08x\n"
155 "\t sg1u 0x%08x sg1l 0x%08x\n"
156 "\t sg2u 0x%08x sg2l 0x%08x\n"
157 "\t sg3u 0x%08x sg3l 0x%08x\n",
158 cdb
, chan
->device
->id
,
159 cdb
->attr
, cdb
->opc
, le32_to_cpu(cdb
->cnt
),
160 le32_to_cpu(cdb
->sg1u
), le32_to_cpu(cdb
->sg1l
),
161 le32_to_cpu(cdb
->sg2u
), le32_to_cpu(cdb
->sg2l
),
162 le32_to_cpu(cdb
->sg3u
), le32_to_cpu(cdb
->sg3l
)
168 pr_debug("CB at %p [%d]:\n"
169 "\t cbc 0x%08x cbbc 0x%08x cbs 0x%08x\n"
170 "\t cbtah 0x%08x cbtal 0x%08x\n"
171 "\t cblah 0x%08x cblal 0x%08x\n",
172 cb
, chan
->device
->id
,
173 cb
->cbc
, cb
->cbbc
, cb
->cbs
,
174 cb
->cbtah
, cb
->cbtal
,
175 cb
->cblah
, cb
->cblal
);
176 for (i
= 0; i
< 16; i
++) {
177 if (i
&& !cb
->ops
[i
].h
&& !cb
->ops
[i
].l
)
179 pr_debug("\t ops[%2d]: h 0x%08x l 0x%08x\n",
180 i
, cb
->ops
[i
].h
, cb
->ops
[i
].l
);
186 static void print_cb_list(struct ppc440spe_adma_chan
*chan
,
187 struct ppc440spe_adma_desc_slot
*iter
)
189 for (; iter
; iter
= iter
->hw_next
)
190 print_cb(chan
, iter
->hw_desc
);
193 static void prep_dma_xor_dbg(int id
, dma_addr_t dst
, dma_addr_t
*src
,
194 unsigned int src_cnt
)
198 pr_debug("\n%s(%d):\nsrc: ", __func__
, id
);
199 for (i
= 0; i
< src_cnt
; i
++)
200 pr_debug("\t0x%016llx ", src
[i
]);
201 pr_debug("dst:\n\t0x%016llx\n", dst
);
204 static void prep_dma_pq_dbg(int id
, dma_addr_t
*dst
, dma_addr_t
*src
,
205 unsigned int src_cnt
)
209 pr_debug("\n%s(%d):\nsrc: ", __func__
, id
);
210 for (i
= 0; i
< src_cnt
; i
++)
211 pr_debug("\t0x%016llx ", src
[i
]);
213 for (i
= 0; i
< 2; i
++)
214 pr_debug("\t0x%016llx ", dst
[i
]);
217 static void prep_dma_pqzero_sum_dbg(int id
, dma_addr_t
*src
,
218 unsigned int src_cnt
,
219 const unsigned char *scf
)
223 pr_debug("\n%s(%d):\nsrc(coef): ", __func__
, id
);
225 for (i
= 0; i
< src_cnt
; i
++)
226 pr_debug("\t0x%016llx(0x%02x) ", src
[i
], scf
[i
]);
228 for (i
= 0; i
< src_cnt
; i
++)
229 pr_debug("\t0x%016llx(no) ", src
[i
]);
233 for (i
= 0; i
< 2; i
++)
234 pr_debug("\t0x%016llx ", src
[src_cnt
+ i
]);
237 /******************************************************************************
238 * Command (Descriptor) Blocks low-level routines
239 ******************************************************************************/
241 * ppc440spe_desc_init_interrupt - initialize the descriptor for INTERRUPT
244 static void ppc440spe_desc_init_interrupt(struct ppc440spe_adma_desc_slot
*desc
,
245 struct ppc440spe_adma_chan
*chan
)
249 switch (chan
->device
->id
) {
250 case PPC440SPE_XOR_ID
:
252 memset(desc
->hw_desc
, 0, sizeof(struct xor_cb
));
253 /* NOP with Command Block Complete Enable */
254 p
->cbc
= XOR_CBCR_CBCE_BIT
;
256 case PPC440SPE_DMA0_ID
:
257 case PPC440SPE_DMA1_ID
:
258 memset(desc
->hw_desc
, 0, sizeof(struct dma_cdb
));
259 /* NOP with interrupt */
260 set_bit(PPC440SPE_DESC_INT
, &desc
->flags
);
263 printk(KERN_ERR
"Unsupported id %d in %s\n", chan
->device
->id
,
270 * ppc440spe_desc_init_null_xor - initialize the descriptor for NULL XOR
273 static void ppc440spe_desc_init_null_xor(struct ppc440spe_adma_desc_slot
*desc
)
275 memset(desc
->hw_desc
, 0, sizeof(struct xor_cb
));
276 desc
->hw_next
= NULL
;
282 * ppc440spe_desc_init_xor - initialize the descriptor for XOR operation
284 static void ppc440spe_desc_init_xor(struct ppc440spe_adma_desc_slot
*desc
,
285 int src_cnt
, unsigned long flags
)
287 struct xor_cb
*hw_desc
= desc
->hw_desc
;
289 memset(desc
->hw_desc
, 0, sizeof(struct xor_cb
));
290 desc
->hw_next
= NULL
;
291 desc
->src_cnt
= src_cnt
;
294 hw_desc
->cbc
= XOR_CBCR_TGT_BIT
| src_cnt
;
295 if (flags
& DMA_PREP_INTERRUPT
)
296 /* Enable interrupt on completion */
297 hw_desc
->cbc
|= XOR_CBCR_CBCE_BIT
;
301 * ppc440spe_desc_init_dma2pq - initialize the descriptor for PQ
302 * operation in DMA2 controller
304 static void ppc440spe_desc_init_dma2pq(struct ppc440spe_adma_desc_slot
*desc
,
305 int dst_cnt
, int src_cnt
, unsigned long flags
)
307 struct xor_cb
*hw_desc
= desc
->hw_desc
;
309 memset(desc
->hw_desc
, 0, sizeof(struct xor_cb
));
310 desc
->hw_next
= NULL
;
311 desc
->src_cnt
= src_cnt
;
312 desc
->dst_cnt
= dst_cnt
;
313 memset(desc
->reverse_flags
, 0, sizeof(desc
->reverse_flags
));
314 desc
->descs_per_op
= 0;
316 hw_desc
->cbc
= XOR_CBCR_TGT_BIT
;
317 if (flags
& DMA_PREP_INTERRUPT
)
318 /* Enable interrupt on completion */
319 hw_desc
->cbc
|= XOR_CBCR_CBCE_BIT
;
322 #define DMA_CTRL_FLAGS_LAST DMA_PREP_FENCE
323 #define DMA_PREP_ZERO_P (DMA_CTRL_FLAGS_LAST << 1)
324 #define DMA_PREP_ZERO_Q (DMA_PREP_ZERO_P << 1)
327 * ppc440spe_desc_init_dma01pq - initialize the descriptors for PQ operation
330 static void ppc440spe_desc_init_dma01pq(struct ppc440spe_adma_desc_slot
*desc
,
331 int dst_cnt
, int src_cnt
, unsigned long flags
,
334 struct dma_cdb
*hw_desc
;
335 struct ppc440spe_adma_desc_slot
*iter
;
338 /* Common initialization of a PQ descriptors chain */
339 set_bits(op
, &desc
->flags
);
340 desc
->src_cnt
= src_cnt
;
341 desc
->dst_cnt
= dst_cnt
;
343 /* WXOR MULTICAST if both P and Q are being computed
344 * MV_SG1_SG2 if Q only
346 dopc
= (desc
->dst_cnt
== DMA_DEST_MAX_NUM
) ?
347 DMA_CDB_OPC_MULTICAST
: DMA_CDB_OPC_MV_SG1_SG2
;
349 list_for_each_entry(iter
, &desc
->group_list
, chain_node
) {
350 hw_desc
= iter
->hw_desc
;
351 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
353 if (likely(!list_is_last(&iter
->chain_node
,
354 &desc
->group_list
))) {
355 /* set 'next' pointer */
356 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
357 struct ppc440spe_adma_desc_slot
, chain_node
);
358 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
360 /* this is the last descriptor.
361 * this slot will be pasted from ADMA level
362 * each time it wants to configure parameters
363 * of the transaction (src, dst, ...)
365 iter
->hw_next
= NULL
;
366 if (flags
& DMA_PREP_INTERRUPT
)
367 set_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
369 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
373 /* Set OPS depending on WXOR/RXOR type of operation */
374 if (!test_bit(PPC440SPE_DESC_RXOR
, &desc
->flags
)) {
375 /* This is a WXOR only chain:
376 * - first descriptors are for zeroing destinations
377 * if PPC440SPE_ZERO_P/Q set;
378 * - descriptors remained are for GF-XOR operations.
380 iter
= list_first_entry(&desc
->group_list
,
381 struct ppc440spe_adma_desc_slot
,
384 if (test_bit(PPC440SPE_ZERO_P
, &desc
->flags
)) {
385 hw_desc
= iter
->hw_desc
;
386 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
387 iter
= list_first_entry(&iter
->chain_node
,
388 struct ppc440spe_adma_desc_slot
,
392 if (test_bit(PPC440SPE_ZERO_Q
, &desc
->flags
)) {
393 hw_desc
= iter
->hw_desc
;
394 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
395 iter
= list_first_entry(&iter
->chain_node
,
396 struct ppc440spe_adma_desc_slot
,
400 list_for_each_entry_from(iter
, &desc
->group_list
, chain_node
) {
401 hw_desc
= iter
->hw_desc
;
405 /* This is either RXOR-only or mixed RXOR/WXOR */
407 /* The first 1 or 2 slots in chain are always RXOR,
408 * if need to calculate P & Q, then there are two
409 * RXOR slots; if only P or only Q, then there is one
411 iter
= list_first_entry(&desc
->group_list
,
412 struct ppc440spe_adma_desc_slot
,
414 hw_desc
= iter
->hw_desc
;
415 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
417 if (desc
->dst_cnt
== DMA_DEST_MAX_NUM
) {
418 iter
= list_first_entry(&iter
->chain_node
,
419 struct ppc440spe_adma_desc_slot
,
421 hw_desc
= iter
->hw_desc
;
422 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
425 /* The remaining descs (if any) are WXORs */
426 if (test_bit(PPC440SPE_DESC_WXOR
, &desc
->flags
)) {
427 iter
= list_first_entry(&iter
->chain_node
,
428 struct ppc440spe_adma_desc_slot
,
430 list_for_each_entry_from(iter
, &desc
->group_list
,
432 hw_desc
= iter
->hw_desc
;
440 * ppc440spe_desc_init_dma01pqzero_sum - initialize the descriptor
441 * for PQ_ZERO_SUM operation
443 static void ppc440spe_desc_init_dma01pqzero_sum(
444 struct ppc440spe_adma_desc_slot
*desc
,
445 int dst_cnt
, int src_cnt
)
447 struct dma_cdb
*hw_desc
;
448 struct ppc440spe_adma_desc_slot
*iter
;
450 u8 dopc
= (dst_cnt
== 2) ? DMA_CDB_OPC_MULTICAST
:
451 DMA_CDB_OPC_MV_SG1_SG2
;
453 * Initialize starting from 2nd or 3rd descriptor dependent
454 * on dst_cnt. First one or two slots are for cloning P
455 * and/or Q to chan->pdest and/or chan->qdest as we have
456 * to preserve original P/Q.
458 iter
= list_first_entry(&desc
->group_list
,
459 struct ppc440spe_adma_desc_slot
, chain_node
);
460 iter
= list_entry(iter
->chain_node
.next
,
461 struct ppc440spe_adma_desc_slot
, chain_node
);
464 iter
= list_entry(iter
->chain_node
.next
,
465 struct ppc440spe_adma_desc_slot
, chain_node
);
467 /* initialize each source descriptor in chain */
468 list_for_each_entry_from(iter
, &desc
->group_list
, chain_node
) {
469 hw_desc
= iter
->hw_desc
;
470 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
474 /* This is a ZERO_SUM operation:
475 * - <src_cnt> descriptors starting from 2nd or 3rd
476 * descriptor are for GF-XOR operations;
477 * - remaining <dst_cnt> descriptors are for checking the result
480 /* MV_SG1_SG2 if only Q is being verified
481 * MULTICAST if both P and Q are being verified
485 /* DMA_CDB_OPC_DCHECK128 operation */
486 hw_desc
->opc
= DMA_CDB_OPC_DCHECK128
;
488 if (likely(!list_is_last(&iter
->chain_node
,
489 &desc
->group_list
))) {
490 /* set 'next' pointer */
491 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
492 struct ppc440spe_adma_desc_slot
,
495 /* this is the last descriptor.
496 * this slot will be pasted from ADMA level
497 * each time it wants to configure parameters
498 * of the transaction (src, dst, ...)
500 iter
->hw_next
= NULL
;
501 /* always enable interrupt generation since we get
502 * the status of pqzero from the handler
504 set_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
507 desc
->src_cnt
= src_cnt
;
508 desc
->dst_cnt
= dst_cnt
;
512 * ppc440spe_desc_init_memcpy - initialize the descriptor for MEMCPY operation
514 static void ppc440spe_desc_init_memcpy(struct ppc440spe_adma_desc_slot
*desc
,
517 struct dma_cdb
*hw_desc
= desc
->hw_desc
;
519 memset(desc
->hw_desc
, 0, sizeof(struct dma_cdb
));
520 desc
->hw_next
= NULL
;
524 if (flags
& DMA_PREP_INTERRUPT
)
525 set_bit(PPC440SPE_DESC_INT
, &desc
->flags
);
527 clear_bit(PPC440SPE_DESC_INT
, &desc
->flags
);
529 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
533 * ppc440spe_desc_init_memset - initialize the descriptor for MEMSET operation
535 static void ppc440spe_desc_init_memset(struct ppc440spe_adma_desc_slot
*desc
,
536 int value
, unsigned long flags
)
538 struct dma_cdb
*hw_desc
= desc
->hw_desc
;
540 memset(desc
->hw_desc
, 0, sizeof(struct dma_cdb
));
541 desc
->hw_next
= NULL
;
545 if (flags
& DMA_PREP_INTERRUPT
)
546 set_bit(PPC440SPE_DESC_INT
, &desc
->flags
);
548 clear_bit(PPC440SPE_DESC_INT
, &desc
->flags
);
550 hw_desc
->sg1u
= hw_desc
->sg1l
= cpu_to_le32((u32
)value
);
551 hw_desc
->sg3u
= hw_desc
->sg3l
= cpu_to_le32((u32
)value
);
552 hw_desc
->opc
= DMA_CDB_OPC_DFILL128
;
556 * ppc440spe_desc_set_src_addr - set source address into the descriptor
558 static void ppc440spe_desc_set_src_addr(struct ppc440spe_adma_desc_slot
*desc
,
559 struct ppc440spe_adma_chan
*chan
,
560 int src_idx
, dma_addr_t addrh
,
563 struct dma_cdb
*dma_hw_desc
;
564 struct xor_cb
*xor_hw_desc
;
565 phys_addr_t addr64
, tmplow
, tmphi
;
567 switch (chan
->device
->id
) {
568 case PPC440SPE_DMA0_ID
:
569 case PPC440SPE_DMA1_ID
:
572 tmphi
= (addr64
>> 32);
573 tmplow
= (addr64
& 0xFFFFFFFF);
578 dma_hw_desc
= desc
->hw_desc
;
579 dma_hw_desc
->sg1l
= cpu_to_le32((u32
)tmplow
);
580 dma_hw_desc
->sg1u
|= cpu_to_le32((u32
)tmphi
);
582 case PPC440SPE_XOR_ID
:
583 xor_hw_desc
= desc
->hw_desc
;
584 xor_hw_desc
->ops
[src_idx
].l
= addrl
;
585 xor_hw_desc
->ops
[src_idx
].h
|= addrh
;
591 * ppc440spe_desc_set_src_mult - set source address mult into the descriptor
593 static void ppc440spe_desc_set_src_mult(struct ppc440spe_adma_desc_slot
*desc
,
594 struct ppc440spe_adma_chan
*chan
, u32 mult_index
,
595 int sg_index
, unsigned char mult_value
)
597 struct dma_cdb
*dma_hw_desc
;
598 struct xor_cb
*xor_hw_desc
;
601 switch (chan
->device
->id
) {
602 case PPC440SPE_DMA0_ID
:
603 case PPC440SPE_DMA1_ID
:
604 dma_hw_desc
= desc
->hw_desc
;
607 /* for RXOR operations set multiplier
608 * into source cued address
611 psgu
= &dma_hw_desc
->sg1u
;
613 /* for WXOR operations set multiplier
614 * into destination cued address(es)
616 case DMA_CDB_SG_DST1
:
617 psgu
= &dma_hw_desc
->sg2u
;
619 case DMA_CDB_SG_DST2
:
620 psgu
= &dma_hw_desc
->sg3u
;
626 *psgu
|= cpu_to_le32(mult_value
<< mult_index
);
628 case PPC440SPE_XOR_ID
:
629 xor_hw_desc
= desc
->hw_desc
;
637 * ppc440spe_desc_set_dest_addr - set destination address into the descriptor
639 static void ppc440spe_desc_set_dest_addr(struct ppc440spe_adma_desc_slot
*desc
,
640 struct ppc440spe_adma_chan
*chan
,
641 dma_addr_t addrh
, dma_addr_t addrl
,
644 struct dma_cdb
*dma_hw_desc
;
645 struct xor_cb
*xor_hw_desc
;
646 phys_addr_t addr64
, tmphi
, tmplow
;
649 switch (chan
->device
->id
) {
650 case PPC440SPE_DMA0_ID
:
651 case PPC440SPE_DMA1_ID
:
654 tmphi
= (addr64
>> 32);
655 tmplow
= (addr64
& 0xFFFFFFFF);
660 dma_hw_desc
= desc
->hw_desc
;
662 psgu
= dst_idx
? &dma_hw_desc
->sg3u
: &dma_hw_desc
->sg2u
;
663 psgl
= dst_idx
? &dma_hw_desc
->sg3l
: &dma_hw_desc
->sg2l
;
665 *psgl
= cpu_to_le32((u32
)tmplow
);
666 *psgu
|= cpu_to_le32((u32
)tmphi
);
668 case PPC440SPE_XOR_ID
:
669 xor_hw_desc
= desc
->hw_desc
;
670 xor_hw_desc
->cbtal
= addrl
;
671 xor_hw_desc
->cbtah
|= addrh
;
677 * ppc440spe_desc_set_byte_count - set number of data bytes involved
680 static void ppc440spe_desc_set_byte_count(struct ppc440spe_adma_desc_slot
*desc
,
681 struct ppc440spe_adma_chan
*chan
,
684 struct dma_cdb
*dma_hw_desc
;
685 struct xor_cb
*xor_hw_desc
;
687 switch (chan
->device
->id
) {
688 case PPC440SPE_DMA0_ID
:
689 case PPC440SPE_DMA1_ID
:
690 dma_hw_desc
= desc
->hw_desc
;
691 dma_hw_desc
->cnt
= cpu_to_le32(byte_count
);
693 case PPC440SPE_XOR_ID
:
694 xor_hw_desc
= desc
->hw_desc
;
695 xor_hw_desc
->cbbc
= byte_count
;
701 * ppc440spe_desc_set_rxor_block_size - set RXOR block size
703 static inline void ppc440spe_desc_set_rxor_block_size(u32 byte_count
)
705 /* assume that byte_count is aligned on the 512-boundary;
706 * thus write it directly to the register (bits 23:31 are
709 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_CF2H
, byte_count
);
713 * ppc440spe_desc_set_dcheck - set CHECK pattern
715 static void ppc440spe_desc_set_dcheck(struct ppc440spe_adma_desc_slot
*desc
,
716 struct ppc440spe_adma_chan
*chan
, u8
*qword
)
718 struct dma_cdb
*dma_hw_desc
;
720 switch (chan
->device
->id
) {
721 case PPC440SPE_DMA0_ID
:
722 case PPC440SPE_DMA1_ID
:
723 dma_hw_desc
= desc
->hw_desc
;
724 iowrite32(qword
[0], &dma_hw_desc
->sg3l
);
725 iowrite32(qword
[4], &dma_hw_desc
->sg3u
);
726 iowrite32(qword
[8], &dma_hw_desc
->sg2l
);
727 iowrite32(qword
[12], &dma_hw_desc
->sg2u
);
735 * ppc440spe_xor_set_link - set link address in xor CB
737 static void ppc440spe_xor_set_link(struct ppc440spe_adma_desc_slot
*prev_desc
,
738 struct ppc440spe_adma_desc_slot
*next_desc
)
740 struct xor_cb
*xor_hw_desc
= prev_desc
->hw_desc
;
742 if (unlikely(!next_desc
|| !(next_desc
->phys
))) {
743 printk(KERN_ERR
"%s: next_desc=0x%p; next_desc->phys=0x%llx\n",
745 next_desc
? next_desc
->phys
: 0);
749 xor_hw_desc
->cbs
= 0;
750 xor_hw_desc
->cblal
= next_desc
->phys
;
751 xor_hw_desc
->cblah
= 0;
752 xor_hw_desc
->cbc
|= XOR_CBCR_LNK_BIT
;
756 * ppc440spe_desc_set_link - set the address of descriptor following this
757 * descriptor in chain
759 static void ppc440spe_desc_set_link(struct ppc440spe_adma_chan
*chan
,
760 struct ppc440spe_adma_desc_slot
*prev_desc
,
761 struct ppc440spe_adma_desc_slot
*next_desc
)
764 struct ppc440spe_adma_desc_slot
*tail
= next_desc
;
766 if (unlikely(!prev_desc
|| !next_desc
||
767 (prev_desc
->hw_next
&& prev_desc
->hw_next
!= next_desc
))) {
768 /* If previous next is overwritten something is wrong.
769 * though we may refetch from append to initiate list
770 * processing; in this case - it's ok.
772 printk(KERN_ERR
"%s: prev_desc=0x%p; next_desc=0x%p; "
773 "prev->hw_next=0x%p\n", __func__
, prev_desc
,
774 next_desc
, prev_desc
? prev_desc
->hw_next
: 0);
778 local_irq_save(flags
);
780 /* do s/w chaining both for DMA and XOR descriptors */
781 prev_desc
->hw_next
= next_desc
;
783 switch (chan
->device
->id
) {
784 case PPC440SPE_DMA0_ID
:
785 case PPC440SPE_DMA1_ID
:
787 case PPC440SPE_XOR_ID
:
788 /* bind descriptor to the chain */
789 while (tail
->hw_next
)
790 tail
= tail
->hw_next
;
791 xor_last_linked
= tail
;
793 if (prev_desc
== xor_last_submit
)
794 /* do not link to the last submitted CB */
796 ppc440spe_xor_set_link(prev_desc
, next_desc
);
800 local_irq_restore(flags
);
804 * ppc440spe_desc_get_src_addr - extract the source address from the descriptor
806 static u32
ppc440spe_desc_get_src_addr(struct ppc440spe_adma_desc_slot
*desc
,
807 struct ppc440spe_adma_chan
*chan
, int src_idx
)
809 struct dma_cdb
*dma_hw_desc
;
810 struct xor_cb
*xor_hw_desc
;
812 switch (chan
->device
->id
) {
813 case PPC440SPE_DMA0_ID
:
814 case PPC440SPE_DMA1_ID
:
815 dma_hw_desc
= desc
->hw_desc
;
816 /* May have 0, 1, 2, or 3 sources */
817 switch (dma_hw_desc
->opc
) {
818 case DMA_CDB_OPC_NO_OP
:
819 case DMA_CDB_OPC_DFILL128
:
821 case DMA_CDB_OPC_DCHECK128
:
822 if (unlikely(src_idx
)) {
823 printk(KERN_ERR
"%s: try to get %d source for"
824 " DCHECK128\n", __func__
, src_idx
);
827 return le32_to_cpu(dma_hw_desc
->sg1l
);
828 case DMA_CDB_OPC_MULTICAST
:
829 case DMA_CDB_OPC_MV_SG1_SG2
:
830 if (unlikely(src_idx
> 2)) {
831 printk(KERN_ERR
"%s: try to get %d source from"
832 " DMA descr\n", __func__
, src_idx
);
836 if (le32_to_cpu(dma_hw_desc
->sg1u
) &
837 DMA_CUED_XOR_WIN_MSK
) {
845 region
= (le32_to_cpu(
846 dma_hw_desc
->sg1u
)) >>
849 region
&= DMA_CUED_REGION_MSK
;
854 (desc
->unmap_len
<< 1);
858 (desc
->unmap_len
* 3);
862 (desc
->unmap_len
<< 2);
866 " get src3 for region %02x"
867 "PPC440SPE_DESC_RXOR12?\n",
874 " source for non-cued descr\n",
879 return le32_to_cpu(dma_hw_desc
->sg1l
);
881 printk(KERN_ERR
"%s: unknown OPC 0x%02x\n",
882 __func__
, dma_hw_desc
->opc
);
885 return le32_to_cpu(dma_hw_desc
->sg1l
);
886 case PPC440SPE_XOR_ID
:
887 /* May have up to 16 sources */
888 xor_hw_desc
= desc
->hw_desc
;
889 return xor_hw_desc
->ops
[src_idx
].l
;
895 * ppc440spe_desc_get_dest_addr - extract the destination address from the
898 static u32
ppc440spe_desc_get_dest_addr(struct ppc440spe_adma_desc_slot
*desc
,
899 struct ppc440spe_adma_chan
*chan
, int idx
)
901 struct dma_cdb
*dma_hw_desc
;
902 struct xor_cb
*xor_hw_desc
;
904 switch (chan
->device
->id
) {
905 case PPC440SPE_DMA0_ID
:
906 case PPC440SPE_DMA1_ID
:
907 dma_hw_desc
= desc
->hw_desc
;
910 return le32_to_cpu(dma_hw_desc
->sg2l
);
911 return le32_to_cpu(dma_hw_desc
->sg3l
);
912 case PPC440SPE_XOR_ID
:
913 xor_hw_desc
= desc
->hw_desc
;
914 return xor_hw_desc
->cbtal
;
920 * ppc440spe_desc_get_src_num - extract the number of source addresses from
923 static u32
ppc440spe_desc_get_src_num(struct ppc440spe_adma_desc_slot
*desc
,
924 struct ppc440spe_adma_chan
*chan
)
926 struct dma_cdb
*dma_hw_desc
;
927 struct xor_cb
*xor_hw_desc
;
929 switch (chan
->device
->id
) {
930 case PPC440SPE_DMA0_ID
:
931 case PPC440SPE_DMA1_ID
:
932 dma_hw_desc
= desc
->hw_desc
;
934 switch (dma_hw_desc
->opc
) {
935 case DMA_CDB_OPC_NO_OP
:
936 case DMA_CDB_OPC_DFILL128
:
938 case DMA_CDB_OPC_DCHECK128
:
940 case DMA_CDB_OPC_MV_SG1_SG2
:
941 case DMA_CDB_OPC_MULTICAST
:
943 * Only for RXOR operations we have more than
946 if (le32_to_cpu(dma_hw_desc
->sg1u
) &
947 DMA_CUED_XOR_WIN_MSK
) {
948 /* RXOR op, there are 2 or 3 sources */
949 if (((le32_to_cpu(dma_hw_desc
->sg1u
) >>
950 DMA_CUED_REGION_OFF
) &
951 DMA_CUED_REGION_MSK
) == DMA_RXOR12
) {
955 /* RXOR 1-2-3/1-2-4/1-2-5 */
961 printk(KERN_ERR
"%s: unknown OPC 0x%02x\n",
962 __func__
, dma_hw_desc
->opc
);
965 case PPC440SPE_XOR_ID
:
966 /* up to 16 sources */
967 xor_hw_desc
= desc
->hw_desc
;
968 return xor_hw_desc
->cbc
& XOR_CDCR_OAC_MSK
;
976 * ppc440spe_desc_get_dst_num - get the number of destination addresses in
979 static u32
ppc440spe_desc_get_dst_num(struct ppc440spe_adma_desc_slot
*desc
,
980 struct ppc440spe_adma_chan
*chan
)
982 struct dma_cdb
*dma_hw_desc
;
984 switch (chan
->device
->id
) {
985 case PPC440SPE_DMA0_ID
:
986 case PPC440SPE_DMA1_ID
:
987 /* May be 1 or 2 destinations */
988 dma_hw_desc
= desc
->hw_desc
;
989 switch (dma_hw_desc
->opc
) {
990 case DMA_CDB_OPC_NO_OP
:
991 case DMA_CDB_OPC_DCHECK128
:
993 case DMA_CDB_OPC_MV_SG1_SG2
:
994 case DMA_CDB_OPC_DFILL128
:
996 case DMA_CDB_OPC_MULTICAST
:
997 if (desc
->dst_cnt
== 2)
1002 printk(KERN_ERR
"%s: unknown OPC 0x%02x\n",
1003 __func__
, dma_hw_desc
->opc
);
1006 case PPC440SPE_XOR_ID
:
1007 /* Always only 1 destination */
1016 * ppc440spe_desc_get_link - get the address of the descriptor that
1019 static inline u32
ppc440spe_desc_get_link(struct ppc440spe_adma_desc_slot
*desc
,
1020 struct ppc440spe_adma_chan
*chan
)
1025 return desc
->hw_next
->phys
;
1029 * ppc440spe_desc_is_aligned - check alignment
1031 static inline int ppc440spe_desc_is_aligned(
1032 struct ppc440spe_adma_desc_slot
*desc
, int num_slots
)
1034 return (desc
->idx
& (num_slots
- 1)) ? 0 : 1;
1038 * ppc440spe_chan_xor_slot_count - get the number of slots necessary for
1041 static int ppc440spe_chan_xor_slot_count(size_t len
, int src_cnt
,
1046 /* each XOR descriptor provides up to 16 source operands */
1047 slot_cnt
= *slots_per_op
= (src_cnt
+ XOR_MAX_OPS
- 1)/XOR_MAX_OPS
;
1049 if (likely(len
<= PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT
))
1052 printk(KERN_ERR
"%s: len %d > max %d !!\n",
1053 __func__
, len
, PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT
);
1059 * ppc440spe_dma2_pq_slot_count - get the number of slots necessary for
1062 static int ppc440spe_dma2_pq_slot_count(dma_addr_t
*srcs
,
1063 int src_cnt
, size_t len
)
1065 signed long long order
= 0;
1069 for (i
= 1; i
< src_cnt
; i
++) {
1070 dma_addr_t cur_addr
= srcs
[i
];
1071 dma_addr_t old_addr
= srcs
[i
-1];
1074 if (cur_addr
== old_addr
+ len
) {
1080 } else if (old_addr
== cur_addr
+ len
) {
1091 if (i
== src_cnt
-2 || (order
== -1
1092 && cur_addr
!= old_addr
- len
)) {
1096 } else if (cur_addr
== old_addr
+ len
*order
) {
1100 } else if (cur_addr
== old_addr
+ 2*len
) {
1104 } else if (cur_addr
== old_addr
+ 3*len
) {
1123 if (src_cnt
<= 1 || (state
!= 1 && state
!= 2)) {
1124 pr_err("%s: src_cnt=%d, state=%d, addr_count=%d, order=%lld\n",
1125 __func__
, src_cnt
, state
, addr_count
, order
);
1126 for (i
= 0; i
< src_cnt
; i
++)
1127 pr_err("\t[%d] 0x%llx \n", i
, srcs
[i
]);
1131 return (addr_count
+ XOR_MAX_OPS
- 1) / XOR_MAX_OPS
;
1135 /******************************************************************************
1136 * ADMA channel low-level routines
1137 ******************************************************************************/
1140 ppc440spe_chan_get_current_descriptor(struct ppc440spe_adma_chan
*chan
);
1141 static void ppc440spe_chan_append(struct ppc440spe_adma_chan
*chan
);
1144 * ppc440spe_adma_device_clear_eot_status - interrupt ack to XOR or DMA engine
1146 static void ppc440spe_adma_device_clear_eot_status(
1147 struct ppc440spe_adma_chan
*chan
)
1149 struct dma_regs
*dma_reg
;
1150 struct xor_regs
*xor_reg
;
1151 u8
*p
= chan
->device
->dma_desc_pool_virt
;
1152 struct dma_cdb
*cdb
;
1155 switch (chan
->device
->id
) {
1156 case PPC440SPE_DMA0_ID
:
1157 case PPC440SPE_DMA1_ID
:
1158 /* read FIFO to ack */
1159 dma_reg
= chan
->device
->dma_reg
;
1160 while ((rv
= ioread32(&dma_reg
->csfpl
))) {
1161 i
= rv
& DMA_CDB_ADDR_MSK
;
1162 cdb
= (struct dma_cdb
*)&p
[i
-
1163 (u32
)chan
->device
->dma_desc_pool
];
1165 /* Clear opcode to ack. This is necessary for
1166 * ZeroSum operations only
1170 if (test_bit(PPC440SPE_RXOR_RUN
,
1171 &ppc440spe_rxor_state
)) {
1172 /* probably this is a completed RXOR op,
1173 * get pointer to CDB using the fact that
1174 * physical and virtual addresses of CDB
1175 * in pools have the same offsets
1177 if (le32_to_cpu(cdb
->sg1u
) &
1178 DMA_CUED_XOR_BASE
) {
1179 /* this is a RXOR */
1180 clear_bit(PPC440SPE_RXOR_RUN
,
1181 &ppc440spe_rxor_state
);
1185 if (rv
& DMA_CDB_STATUS_MSK
) {
1186 /* ZeroSum check failed
1188 struct ppc440spe_adma_desc_slot
*iter
;
1189 dma_addr_t phys
= rv
& ~DMA_CDB_MSK
;
1192 * Update the status of corresponding
1195 list_for_each_entry(iter
, &chan
->chain
,
1197 if (iter
->phys
== phys
)
1201 * if cannot find the corresponding
1204 BUG_ON(&iter
->chain_node
== &chan
->chain
);
1206 if (iter
->xor_check_result
) {
1207 if (test_bit(PPC440SPE_DESC_PCHECK
,
1209 *iter
->xor_check_result
|=
1212 if (test_bit(PPC440SPE_DESC_QCHECK
,
1214 *iter
->xor_check_result
|=
1222 rv
= ioread32(&dma_reg
->dsts
);
1224 pr_err("DMA%d err status: 0x%x\n",
1225 chan
->device
->id
, rv
);
1226 /* write back to clear */
1227 iowrite32(rv
, &dma_reg
->dsts
);
1230 case PPC440SPE_XOR_ID
:
1231 /* reset status bits to ack */
1232 xor_reg
= chan
->device
->xor_reg
;
1233 rv
= ioread32be(&xor_reg
->sr
);
1234 iowrite32be(rv
, &xor_reg
->sr
);
1236 if (rv
& (XOR_IE_ICBIE_BIT
|XOR_IE_ICIE_BIT
|XOR_IE_RPTIE_BIT
)) {
1237 if (rv
& XOR_IE_RPTIE_BIT
) {
1238 /* Read PLB Timeout Error.
1239 * Try to resubmit the CB
1241 u32 val
= ioread32be(&xor_reg
->ccbalr
);
1243 iowrite32be(val
, &xor_reg
->cblalr
);
1245 val
= ioread32be(&xor_reg
->crsr
);
1246 iowrite32be(val
| XOR_CRSR_XAE_BIT
,
1249 pr_err("XOR ERR 0x%x status\n", rv
);
1253 /* if the XORcore is idle, but there are unprocessed CBs
1254 * then refetch the s/w chain here
1256 if (!(ioread32be(&xor_reg
->sr
) & XOR_SR_XCP_BIT
) &&
1258 ppc440spe_chan_append(chan
);
1264 * ppc440spe_chan_is_busy - get the channel status
1266 static int ppc440spe_chan_is_busy(struct ppc440spe_adma_chan
*chan
)
1268 struct dma_regs
*dma_reg
;
1269 struct xor_regs
*xor_reg
;
1272 switch (chan
->device
->id
) {
1273 case PPC440SPE_DMA0_ID
:
1274 case PPC440SPE_DMA1_ID
:
1275 dma_reg
= chan
->device
->dma_reg
;
1276 /* if command FIFO's head and tail pointers are equal and
1277 * status tail is the same as command, then channel is free
1279 if (ioread16(&dma_reg
->cpfhp
) != ioread16(&dma_reg
->cpftp
) ||
1280 ioread16(&dma_reg
->cpftp
) != ioread16(&dma_reg
->csftp
))
1283 case PPC440SPE_XOR_ID
:
1284 /* use the special status bit for the XORcore
1286 xor_reg
= chan
->device
->xor_reg
;
1287 busy
= (ioread32be(&xor_reg
->sr
) & XOR_SR_XCP_BIT
) ? 1 : 0;
1295 * ppc440spe_chan_set_first_xor_descriptor - init XORcore chain
1297 static void ppc440spe_chan_set_first_xor_descriptor(
1298 struct ppc440spe_adma_chan
*chan
,
1299 struct ppc440spe_adma_desc_slot
*next_desc
)
1301 struct xor_regs
*xor_reg
= chan
->device
->xor_reg
;
1303 if (ioread32be(&xor_reg
->sr
) & XOR_SR_XCP_BIT
)
1304 printk(KERN_INFO
"%s: Warn: XORcore is running "
1305 "when try to set the first CDB!\n",
1308 xor_last_submit
= xor_last_linked
= next_desc
;
1310 iowrite32be(XOR_CRSR_64BA_BIT
, &xor_reg
->crsr
);
1312 iowrite32be(next_desc
->phys
, &xor_reg
->cblalr
);
1313 iowrite32be(0, &xor_reg
->cblahr
);
1314 iowrite32be(ioread32be(&xor_reg
->cbcr
) | XOR_CBCR_LNK_BIT
,
1317 chan
->hw_chain_inited
= 1;
1321 * ppc440spe_dma_put_desc - put DMA0,1 descriptor to FIFO.
1322 * called with irqs disabled
1324 static void ppc440spe_dma_put_desc(struct ppc440spe_adma_chan
*chan
,
1325 struct ppc440spe_adma_desc_slot
*desc
)
1328 struct dma_regs
*dma_reg
= chan
->device
->dma_reg
;
1331 if (!test_bit(PPC440SPE_DESC_INT
, &desc
->flags
))
1332 pcdb
|= DMA_CDB_NO_INT
;
1334 chan_last_sub
[chan
->device
->id
] = desc
;
1336 ADMA_LL_DBG(print_cb(chan
, desc
->hw_desc
));
1338 iowrite32(pcdb
, &dma_reg
->cpfpl
);
1342 * ppc440spe_chan_append - update the h/w chain in the channel
1344 static void ppc440spe_chan_append(struct ppc440spe_adma_chan
*chan
)
1346 struct xor_regs
*xor_reg
;
1347 struct ppc440spe_adma_desc_slot
*iter
;
1350 unsigned long flags
;
1352 local_irq_save(flags
);
1354 switch (chan
->device
->id
) {
1355 case PPC440SPE_DMA0_ID
:
1356 case PPC440SPE_DMA1_ID
:
1357 cur_desc
= ppc440spe_chan_get_current_descriptor(chan
);
1359 if (likely(cur_desc
)) {
1360 iter
= chan_last_sub
[chan
->device
->id
];
1364 iter
= chan_first_cdb
[chan
->device
->id
];
1366 ppc440spe_dma_put_desc(chan
, iter
);
1367 chan
->hw_chain_inited
= 1;
1370 /* is there something new to append */
1374 /* flush descriptors from the s/w queue to fifo */
1375 list_for_each_entry_continue(iter
, &chan
->chain
, chain_node
) {
1376 ppc440spe_dma_put_desc(chan
, iter
);
1381 case PPC440SPE_XOR_ID
:
1382 /* update h/w links and refetch */
1383 if (!xor_last_submit
->hw_next
)
1386 xor_reg
= chan
->device
->xor_reg
;
1387 /* the last linked CDB has to generate an interrupt
1388 * that we'd be able to append the next lists to h/w
1389 * regardless of the XOR engine state at the moment of
1390 * appending of these next lists
1392 xcb
= xor_last_linked
->hw_desc
;
1393 xcb
->cbc
|= XOR_CBCR_CBCE_BIT
;
1395 if (!(ioread32be(&xor_reg
->sr
) & XOR_SR_XCP_BIT
)) {
1396 /* XORcore is idle. Refetch now */
1398 ppc440spe_xor_set_link(xor_last_submit
,
1399 xor_last_submit
->hw_next
);
1401 ADMA_LL_DBG(print_cb_list(chan
,
1402 xor_last_submit
->hw_next
));
1404 xor_last_submit
= xor_last_linked
;
1405 iowrite32be(ioread32be(&xor_reg
->crsr
) |
1406 XOR_CRSR_RCBE_BIT
| XOR_CRSR_64BA_BIT
,
1409 /* XORcore is running. Refetch later in the handler */
1416 local_irq_restore(flags
);
1420 * ppc440spe_chan_get_current_descriptor - get the currently executed descriptor
1423 ppc440spe_chan_get_current_descriptor(struct ppc440spe_adma_chan
*chan
)
1425 struct dma_regs
*dma_reg
;
1426 struct xor_regs
*xor_reg
;
1428 if (unlikely(!chan
->hw_chain_inited
))
1429 /* h/w descriptor chain is not initialized yet */
1432 switch (chan
->device
->id
) {
1433 case PPC440SPE_DMA0_ID
:
1434 case PPC440SPE_DMA1_ID
:
1435 dma_reg
= chan
->device
->dma_reg
;
1436 return ioread32(&dma_reg
->acpl
) & (~DMA_CDB_MSK
);
1437 case PPC440SPE_XOR_ID
:
1438 xor_reg
= chan
->device
->xor_reg
;
1439 return ioread32be(&xor_reg
->ccbalr
);
1445 * ppc440spe_chan_run - enable the channel
1447 static void ppc440spe_chan_run(struct ppc440spe_adma_chan
*chan
)
1449 struct xor_regs
*xor_reg
;
1451 switch (chan
->device
->id
) {
1452 case PPC440SPE_DMA0_ID
:
1453 case PPC440SPE_DMA1_ID
:
1454 /* DMAs are always enabled, do nothing */
1456 case PPC440SPE_XOR_ID
:
1457 /* drain write buffer */
1458 xor_reg
= chan
->device
->xor_reg
;
1460 /* fetch descriptor pointed to in <link> */
1461 iowrite32be(XOR_CRSR_64BA_BIT
| XOR_CRSR_XAE_BIT
,
1467 /******************************************************************************
1469 ******************************************************************************/
1471 static void ppc440spe_chan_start_null_xor(struct ppc440spe_adma_chan
*chan
);
1472 static int ppc440spe_adma_alloc_chan_resources(struct dma_chan
*chan
);
1475 ppc440spe_adma_tx_submit(struct dma_async_tx_descriptor
*tx
);
1477 static void ppc440spe_adma_set_dest(struct ppc440spe_adma_desc_slot
*tx
,
1478 dma_addr_t addr
, int index
);
1480 ppc440spe_adma_memcpy_xor_set_src(struct ppc440spe_adma_desc_slot
*tx
,
1481 dma_addr_t addr
, int index
);
1484 ppc440spe_adma_pq_set_dest(struct ppc440spe_adma_desc_slot
*tx
,
1485 dma_addr_t
*paddr
, unsigned long flags
);
1487 ppc440spe_adma_pq_set_src(struct ppc440spe_adma_desc_slot
*tx
,
1488 dma_addr_t addr
, int index
);
1490 ppc440spe_adma_pq_set_src_mult(struct ppc440spe_adma_desc_slot
*tx
,
1491 unsigned char mult
, int index
, int dst_pos
);
1493 ppc440spe_adma_pqzero_sum_set_dest(struct ppc440spe_adma_desc_slot
*tx
,
1494 dma_addr_t paddr
, dma_addr_t qaddr
);
1496 static struct page
*ppc440spe_rxor_srcs
[32];
1499 * ppc440spe_can_rxor - check if the operands may be processed with RXOR
1501 static int ppc440spe_can_rxor(struct page
**srcs
, int src_cnt
, size_t len
)
1503 int i
, order
= 0, state
= 0;
1506 if (unlikely(!(src_cnt
> 1)))
1509 BUG_ON(src_cnt
> ARRAY_SIZE(ppc440spe_rxor_srcs
));
1511 /* Skip holes in the source list before checking */
1512 for (i
= 0; i
< src_cnt
; i
++) {
1515 ppc440spe_rxor_srcs
[idx
++] = srcs
[i
];
1519 for (i
= 1; i
< src_cnt
; i
++) {
1520 char *cur_addr
= page_address(ppc440spe_rxor_srcs
[i
]);
1521 char *old_addr
= page_address(ppc440spe_rxor_srcs
[i
- 1]);
1525 if (cur_addr
== old_addr
+ len
) {
1529 } else if (old_addr
== cur_addr
+ len
) {
1537 if ((i
== src_cnt
- 2) ||
1538 (order
== -1 && cur_addr
!= old_addr
- len
)) {
1541 } else if ((cur_addr
== old_addr
+ len
* order
) ||
1542 (cur_addr
== old_addr
+ 2 * len
) ||
1543 (cur_addr
== old_addr
+ 3 * len
)) {
1558 if (state
== 1 || state
== 2)
1565 * ppc440spe_adma_device_estimate - estimate the efficiency of processing
1566 * the operation given on this channel. It's assumed that 'chan' is
1567 * capable to process 'cap' type of operation.
1568 * @chan: channel to use
1569 * @cap: type of transaction
1570 * @dst_lst: array of destination pointers
1571 * @dst_cnt: number of destination operands
1572 * @src_lst: array of source pointers
1573 * @src_cnt: number of source operands
1574 * @src_sz: size of each source operand
1576 static int ppc440spe_adma_estimate(struct dma_chan
*chan
,
1577 enum dma_transaction_type cap
, struct page
**dst_lst
, int dst_cnt
,
1578 struct page
**src_lst
, int src_cnt
, size_t src_sz
)
1582 if (cap
== DMA_PQ
|| cap
== DMA_PQ_VAL
) {
1583 /* If RAID-6 capabilities were not activated don't try
1586 if (unlikely(!ppc440spe_r6_enabled
))
1589 /* In the current implementation of ppc440spe ADMA driver it
1590 * makes sense to pick out only pq case, because it may be
1592 * (1) either using Biskup method on DMA2;
1594 * Thus we give a favour to (1) if the sources are suitable;
1595 * else let it be processed on one of the DMA0/1 engines.
1596 * In the sum_product case where destination is also the
1597 * source process it on DMA0/1 only.
1599 if (cap
== DMA_PQ
&& chan
->chan_id
== PPC440SPE_XOR_ID
) {
1601 if (dst_cnt
== 1 && src_cnt
== 2 && dst_lst
[0] == src_lst
[1])
1602 ef
= 0; /* sum_product case, process on DMA0/1 */
1603 else if (ppc440spe_can_rxor(src_lst
, src_cnt
, src_sz
))
1604 ef
= 3; /* override (DMA0/1 + idle) */
1606 ef
= 0; /* can't process on DMA2 if !rxor */
1609 /* channel idleness increases the priority */
1611 !ppc440spe_chan_is_busy(to_ppc440spe_adma_chan(chan
)))
1618 ppc440spe_async_tx_find_best_channel(enum dma_transaction_type cap
,
1619 struct page
**dst_lst
, int dst_cnt
, struct page
**src_lst
,
1620 int src_cnt
, size_t src_sz
)
1622 struct dma_chan
*best_chan
= NULL
;
1623 struct ppc_dma_chan_ref
*ref
;
1626 if (unlikely(!src_sz
))
1628 if (src_sz
> PAGE_SIZE
) {
1630 * should a user of the api ever pass > PAGE_SIZE requests
1631 * we sort out cases where temporary page-sized buffers
1636 if (src_cnt
== 1 && dst_lst
[1] == src_lst
[0])
1638 if (src_cnt
== 2 && dst_lst
[1] == src_lst
[1])
1649 list_for_each_entry(ref
, &ppc440spe_adma_chan_list
, node
) {
1650 if (dma_has_cap(cap
, ref
->chan
->device
->cap_mask
)) {
1653 rank
= ppc440spe_adma_estimate(ref
->chan
, cap
, dst_lst
,
1654 dst_cnt
, src_lst
, src_cnt
, src_sz
);
1655 if (rank
> best_rank
) {
1657 best_chan
= ref
->chan
;
1664 EXPORT_SYMBOL_GPL(ppc440spe_async_tx_find_best_channel
);
1667 * ppc440spe_get_group_entry - get group entry with index idx
1668 * @tdesc: is the last allocated slot in the group.
1670 static struct ppc440spe_adma_desc_slot
*
1671 ppc440spe_get_group_entry(struct ppc440spe_adma_desc_slot
*tdesc
, u32 entry_idx
)
1673 struct ppc440spe_adma_desc_slot
*iter
= tdesc
->group_head
;
1676 if (entry_idx
< 0 || entry_idx
>= (tdesc
->src_cnt
+ tdesc
->dst_cnt
)) {
1677 printk("%s: entry_idx %d, src_cnt %d, dst_cnt %d\n",
1678 __func__
, entry_idx
, tdesc
->src_cnt
, tdesc
->dst_cnt
);
1682 list_for_each_entry(iter
, &tdesc
->group_list
, chain_node
) {
1683 if (i
++ == entry_idx
)
1690 * ppc440spe_adma_free_slots - flags descriptor slots for reuse
1691 * @slot: Slot to free
1692 * Caller must hold &ppc440spe_chan->lock while calling this function
1694 static void ppc440spe_adma_free_slots(struct ppc440spe_adma_desc_slot
*slot
,
1695 struct ppc440spe_adma_chan
*chan
)
1697 int stride
= slot
->slots_per_op
;
1700 slot
->slots_per_op
= 0;
1701 slot
= list_entry(slot
->slot_node
.next
,
1702 struct ppc440spe_adma_desc_slot
,
1707 static void ppc440spe_adma_unmap(struct ppc440spe_adma_chan
*chan
,
1708 struct ppc440spe_adma_desc_slot
*desc
)
1710 u32 src_cnt
, dst_cnt
;
1714 * get the number of sources & destination
1715 * included in this descriptor and unmap
1718 src_cnt
= ppc440spe_desc_get_src_num(desc
, chan
);
1719 dst_cnt
= ppc440spe_desc_get_dst_num(desc
, chan
);
1721 /* unmap destinations */
1722 if (!(desc
->async_tx
.flags
& DMA_COMPL_SKIP_DEST_UNMAP
)) {
1724 addr
= ppc440spe_desc_get_dest_addr(
1725 desc
, chan
, dst_cnt
);
1726 dma_unmap_page(chan
->device
->dev
,
1727 addr
, desc
->unmap_len
,
1733 if (!(desc
->async_tx
.flags
& DMA_COMPL_SKIP_SRC_UNMAP
)) {
1735 addr
= ppc440spe_desc_get_src_addr(
1736 desc
, chan
, src_cnt
);
1737 dma_unmap_page(chan
->device
->dev
,
1738 addr
, desc
->unmap_len
,
1745 * ppc440spe_adma_run_tx_complete_actions - call functions to be called
1748 static dma_cookie_t
ppc440spe_adma_run_tx_complete_actions(
1749 struct ppc440spe_adma_desc_slot
*desc
,
1750 struct ppc440spe_adma_chan
*chan
,
1751 dma_cookie_t cookie
)
1755 BUG_ON(desc
->async_tx
.cookie
< 0);
1756 if (desc
->async_tx
.cookie
> 0) {
1757 cookie
= desc
->async_tx
.cookie
;
1758 desc
->async_tx
.cookie
= 0;
1760 /* call the callback (must not sleep or submit new
1761 * operations to this channel)
1763 if (desc
->async_tx
.callback
)
1764 desc
->async_tx
.callback(
1765 desc
->async_tx
.callback_param
);
1767 /* unmap dma addresses
1768 * (unmap_single vs unmap_page?)
1770 * actually, ppc's dma_unmap_page() functions are empty, so
1771 * the following code is just for the sake of completeness
1773 if (chan
&& chan
->needs_unmap
&& desc
->group_head
&&
1775 struct ppc440spe_adma_desc_slot
*unmap
=
1777 /* assume 1 slot per op always */
1778 u32 slot_count
= unmap
->slot_cnt
;
1780 /* Run through the group list and unmap addresses */
1781 for (i
= 0; i
< slot_count
; i
++) {
1783 ppc440spe_adma_unmap(chan
, unmap
);
1784 unmap
= unmap
->hw_next
;
1789 /* run dependent operations */
1790 dma_run_dependencies(&desc
->async_tx
);
1796 * ppc440spe_adma_clean_slot - clean up CDB slot (if ack is set)
1798 static int ppc440spe_adma_clean_slot(struct ppc440spe_adma_desc_slot
*desc
,
1799 struct ppc440spe_adma_chan
*chan
)
1801 /* the client is allowed to attach dependent operations
1802 * until 'ack' is set
1804 if (!async_tx_test_ack(&desc
->async_tx
))
1807 /* leave the last descriptor in the chain
1808 * so we can append to it
1810 if (list_is_last(&desc
->chain_node
, &chan
->chain
) ||
1811 desc
->phys
== ppc440spe_chan_get_current_descriptor(chan
))
1814 if (chan
->device
->id
!= PPC440SPE_XOR_ID
) {
1815 /* our DMA interrupt handler clears opc field of
1816 * each processed descriptor. For all types of
1817 * operations except for ZeroSum we do not actually
1818 * need ack from the interrupt handler. ZeroSum is a
1819 * special case since the result of this operation
1820 * is available from the handler only, so if we see
1821 * such type of descriptor (which is unprocessed yet)
1822 * then leave it in chain.
1824 struct dma_cdb
*cdb
= desc
->hw_desc
;
1825 if (cdb
->opc
== DMA_CDB_OPC_DCHECK128
)
1829 dev_dbg(chan
->device
->common
.dev
, "\tfree slot %llx: %d stride: %d\n",
1830 desc
->phys
, desc
->idx
, desc
->slots_per_op
);
1832 list_del(&desc
->chain_node
);
1833 ppc440spe_adma_free_slots(desc
, chan
);
1838 * __ppc440spe_adma_slot_cleanup - this is the common clean-up routine
1839 * which runs through the channel CDBs list until reach the descriptor
1840 * currently processed. When routine determines that all CDBs of group
1841 * are completed then corresponding callbacks (if any) are called and slots
1844 static void __ppc440spe_adma_slot_cleanup(struct ppc440spe_adma_chan
*chan
)
1846 struct ppc440spe_adma_desc_slot
*iter
, *_iter
, *group_start
= NULL
;
1847 dma_cookie_t cookie
= 0;
1848 u32 current_desc
= ppc440spe_chan_get_current_descriptor(chan
);
1849 int busy
= ppc440spe_chan_is_busy(chan
);
1850 int seen_current
= 0, slot_cnt
= 0, slots_per_op
= 0;
1852 dev_dbg(chan
->device
->common
.dev
, "ppc440spe adma%d: %s\n",
1853 chan
->device
->id
, __func__
);
1855 if (!current_desc
) {
1856 /* There were no transactions yet, so
1862 /* free completed slots from the chain starting with
1863 * the oldest descriptor
1865 list_for_each_entry_safe(iter
, _iter
, &chan
->chain
,
1867 dev_dbg(chan
->device
->common
.dev
, "\tcookie: %d slot: %d "
1868 "busy: %d this_desc: %#llx next_desc: %#x "
1869 "cur: %#x ack: %d\n",
1870 iter
->async_tx
.cookie
, iter
->idx
, busy
, iter
->phys
,
1871 ppc440spe_desc_get_link(iter
, chan
), current_desc
,
1872 async_tx_test_ack(&iter
->async_tx
));
1874 prefetch(&_iter
->async_tx
);
1876 /* do not advance past the current descriptor loaded into the
1877 * hardware channel,subsequent descriptors are either in process
1878 * or have not been submitted
1883 /* stop the search if we reach the current descriptor and the
1884 * channel is busy, or if it appears that the current descriptor
1885 * needs to be re-read (i.e. has been appended to)
1887 if (iter
->phys
== current_desc
) {
1888 BUG_ON(seen_current
++);
1889 if (busy
|| ppc440spe_desc_get_link(iter
, chan
)) {
1890 /* not all descriptors of the group have
1891 * been completed; exit.
1897 /* detect the start of a group transaction */
1898 if (!slot_cnt
&& !slots_per_op
) {
1899 slot_cnt
= iter
->slot_cnt
;
1900 slots_per_op
= iter
->slots_per_op
;
1901 if (slot_cnt
<= slots_per_op
) {
1910 slot_cnt
-= slots_per_op
;
1913 /* all the members of a group are complete */
1914 if (slots_per_op
!= 0 && slot_cnt
== 0) {
1915 struct ppc440spe_adma_desc_slot
*grp_iter
, *_grp_iter
;
1916 int end_of_chain
= 0;
1918 /* clean up the group */
1919 slot_cnt
= group_start
->slot_cnt
;
1920 grp_iter
= group_start
;
1921 list_for_each_entry_safe_from(grp_iter
, _grp_iter
,
1922 &chan
->chain
, chain_node
) {
1924 cookie
= ppc440spe_adma_run_tx_complete_actions(
1925 grp_iter
, chan
, cookie
);
1927 slot_cnt
-= slots_per_op
;
1928 end_of_chain
= ppc440spe_adma_clean_slot(
1930 if (end_of_chain
&& slot_cnt
) {
1931 /* Should wait for ZeroSum completion */
1933 chan
->completed_cookie
= cookie
;
1937 if (slot_cnt
== 0 || end_of_chain
)
1941 /* the group should be complete at this point */
1950 } else if (slots_per_op
) /* wait for group completion */
1953 cookie
= ppc440spe_adma_run_tx_complete_actions(iter
, chan
,
1956 if (ppc440spe_adma_clean_slot(iter
, chan
))
1960 BUG_ON(!seen_current
);
1963 chan
->completed_cookie
= cookie
;
1964 pr_debug("\tcompleted cookie %d\n", cookie
);
1970 * ppc440spe_adma_tasklet - clean up watch-dog initiator
1972 static void ppc440spe_adma_tasklet(unsigned long data
)
1974 struct ppc440spe_adma_chan
*chan
= (struct ppc440spe_adma_chan
*) data
;
1976 spin_lock_nested(&chan
->lock
, SINGLE_DEPTH_NESTING
);
1977 __ppc440spe_adma_slot_cleanup(chan
);
1978 spin_unlock(&chan
->lock
);
1982 * ppc440spe_adma_slot_cleanup - clean up scheduled initiator
1984 static void ppc440spe_adma_slot_cleanup(struct ppc440spe_adma_chan
*chan
)
1986 spin_lock_bh(&chan
->lock
);
1987 __ppc440spe_adma_slot_cleanup(chan
);
1988 spin_unlock_bh(&chan
->lock
);
1992 * ppc440spe_adma_alloc_slots - allocate free slots (if any)
1994 static struct ppc440spe_adma_desc_slot
*ppc440spe_adma_alloc_slots(
1995 struct ppc440spe_adma_chan
*chan
, int num_slots
,
1998 struct ppc440spe_adma_desc_slot
*iter
= NULL
, *_iter
;
1999 struct ppc440spe_adma_desc_slot
*alloc_start
= NULL
;
2000 struct list_head chain
= LIST_HEAD_INIT(chain
);
2001 int slots_found
, retry
= 0;
2004 BUG_ON(!num_slots
|| !slots_per_op
);
2005 /* start search from the last allocated descrtiptor
2006 * if a contiguous allocation can not be found start searching
2007 * from the beginning of the list
2012 iter
= chan
->last_used
;
2014 iter
= list_entry(&chan
->all_slots
,
2015 struct ppc440spe_adma_desc_slot
,
2017 list_for_each_entry_safe_continue(iter
, _iter
, &chan
->all_slots
,
2020 prefetch(&_iter
->async_tx
);
2021 if (iter
->slots_per_op
) {
2026 /* start the allocation if the slot is correctly aligned */
2030 if (slots_found
== num_slots
) {
2031 struct ppc440spe_adma_desc_slot
*alloc_tail
= NULL
;
2032 struct ppc440spe_adma_desc_slot
*last_used
= NULL
;
2037 /* pre-ack all but the last descriptor */
2038 if (num_slots
!= slots_per_op
)
2039 async_tx_ack(&iter
->async_tx
);
2041 list_add_tail(&iter
->chain_node
, &chain
);
2043 iter
->async_tx
.cookie
= 0;
2044 iter
->hw_next
= NULL
;
2046 iter
->slot_cnt
= num_slots
;
2047 iter
->xor_check_result
= NULL
;
2048 for (i
= 0; i
< slots_per_op
; i
++) {
2049 iter
->slots_per_op
= slots_per_op
- i
;
2051 iter
= list_entry(iter
->slot_node
.next
,
2052 struct ppc440spe_adma_desc_slot
,
2055 num_slots
-= slots_per_op
;
2057 alloc_tail
->group_head
= alloc_start
;
2058 alloc_tail
->async_tx
.cookie
= -EBUSY
;
2059 list_splice(&chain
, &alloc_tail
->group_list
);
2060 chan
->last_used
= last_used
;
2067 /* try to free some slots if the allocation fails */
2068 tasklet_schedule(&chan
->irq_tasklet
);
2073 * ppc440spe_adma_alloc_chan_resources - allocate pools for CDB slots
2075 static int ppc440spe_adma_alloc_chan_resources(struct dma_chan
*chan
)
2077 struct ppc440spe_adma_chan
*ppc440spe_chan
;
2078 struct ppc440spe_adma_desc_slot
*slot
= NULL
;
2083 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
2084 init
= ppc440spe_chan
->slots_allocated
? 0 : 1;
2085 chan
->chan_id
= ppc440spe_chan
->device
->id
;
2087 /* Allocate descriptor slots */
2088 i
= ppc440spe_chan
->slots_allocated
;
2089 if (ppc440spe_chan
->device
->id
!= PPC440SPE_XOR_ID
)
2090 db_sz
= sizeof(struct dma_cdb
);
2092 db_sz
= sizeof(struct xor_cb
);
2094 for (; i
< (ppc440spe_chan
->device
->pool_size
/ db_sz
); i
++) {
2095 slot
= kzalloc(sizeof(struct ppc440spe_adma_desc_slot
),
2098 printk(KERN_INFO
"SPE ADMA Channel only initialized"
2099 " %d descriptor slots", i
--);
2103 hw_desc
= (char *) ppc440spe_chan
->device
->dma_desc_pool_virt
;
2104 slot
->hw_desc
= (void *) &hw_desc
[i
* db_sz
];
2105 dma_async_tx_descriptor_init(&slot
->async_tx
, chan
);
2106 slot
->async_tx
.tx_submit
= ppc440spe_adma_tx_submit
;
2107 INIT_LIST_HEAD(&slot
->chain_node
);
2108 INIT_LIST_HEAD(&slot
->slot_node
);
2109 INIT_LIST_HEAD(&slot
->group_list
);
2110 slot
->phys
= ppc440spe_chan
->device
->dma_desc_pool
+ i
* db_sz
;
2113 spin_lock_bh(&ppc440spe_chan
->lock
);
2114 ppc440spe_chan
->slots_allocated
++;
2115 list_add_tail(&slot
->slot_node
, &ppc440spe_chan
->all_slots
);
2116 spin_unlock_bh(&ppc440spe_chan
->lock
);
2119 if (i
&& !ppc440spe_chan
->last_used
) {
2120 ppc440spe_chan
->last_used
=
2121 list_entry(ppc440spe_chan
->all_slots
.next
,
2122 struct ppc440spe_adma_desc_slot
,
2126 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
2127 "ppc440spe adma%d: allocated %d descriptor slots\n",
2128 ppc440spe_chan
->device
->id
, i
);
2130 /* initialize the channel and the chain with a null operation */
2132 switch (ppc440spe_chan
->device
->id
) {
2133 case PPC440SPE_DMA0_ID
:
2134 case PPC440SPE_DMA1_ID
:
2135 ppc440spe_chan
->hw_chain_inited
= 0;
2136 /* Use WXOR for self-testing */
2137 if (!ppc440spe_r6_tchan
)
2138 ppc440spe_r6_tchan
= ppc440spe_chan
;
2140 case PPC440SPE_XOR_ID
:
2141 ppc440spe_chan_start_null_xor(ppc440spe_chan
);
2146 ppc440spe_chan
->needs_unmap
= 1;
2149 return (i
> 0) ? i
: -ENOMEM
;
2153 * ppc440spe_desc_assign_cookie - assign a cookie
2155 static dma_cookie_t
ppc440spe_desc_assign_cookie(
2156 struct ppc440spe_adma_chan
*chan
,
2157 struct ppc440spe_adma_desc_slot
*desc
)
2159 dma_cookie_t cookie
= chan
->common
.cookie
;
2164 chan
->common
.cookie
= desc
->async_tx
.cookie
= cookie
;
2169 * ppc440spe_rxor_set_region_data -
2171 static void ppc440spe_rxor_set_region(struct ppc440spe_adma_desc_slot
*desc
,
2172 u8 xor_arg_no
, u32 mask
)
2174 struct xor_cb
*xcb
= desc
->hw_desc
;
2176 xcb
->ops
[xor_arg_no
].h
|= mask
;
2180 * ppc440spe_rxor_set_src -
2182 static void ppc440spe_rxor_set_src(struct ppc440spe_adma_desc_slot
*desc
,
2183 u8 xor_arg_no
, dma_addr_t addr
)
2185 struct xor_cb
*xcb
= desc
->hw_desc
;
2187 xcb
->ops
[xor_arg_no
].h
|= DMA_CUED_XOR_BASE
;
2188 xcb
->ops
[xor_arg_no
].l
= addr
;
2192 * ppc440spe_rxor_set_mult -
2194 static void ppc440spe_rxor_set_mult(struct ppc440spe_adma_desc_slot
*desc
,
2195 u8 xor_arg_no
, u8 idx
, u8 mult
)
2197 struct xor_cb
*xcb
= desc
->hw_desc
;
2199 xcb
->ops
[xor_arg_no
].h
|= mult
<< (DMA_CUED_MULT1_OFF
+ idx
* 8);
2203 * ppc440spe_adma_check_threshold - append CDBs to h/w chain if threshold
2206 static void ppc440spe_adma_check_threshold(struct ppc440spe_adma_chan
*chan
)
2208 dev_dbg(chan
->device
->common
.dev
, "ppc440spe adma%d: pending: %d\n",
2209 chan
->device
->id
, chan
->pending
);
2211 if (chan
->pending
>= PPC440SPE_ADMA_THRESHOLD
) {
2213 ppc440spe_chan_append(chan
);
2218 * ppc440spe_adma_tx_submit - submit new descriptor group to the channel
2219 * (it's not necessary that descriptors will be submitted to the h/w
2220 * chains too right now)
2222 static dma_cookie_t
ppc440spe_adma_tx_submit(struct dma_async_tx_descriptor
*tx
)
2224 struct ppc440spe_adma_desc_slot
*sw_desc
;
2225 struct ppc440spe_adma_chan
*chan
= to_ppc440spe_adma_chan(tx
->chan
);
2226 struct ppc440spe_adma_desc_slot
*group_start
, *old_chain_tail
;
2229 dma_cookie_t cookie
;
2231 sw_desc
= tx_to_ppc440spe_adma_slot(tx
);
2233 group_start
= sw_desc
->group_head
;
2234 slot_cnt
= group_start
->slot_cnt
;
2235 slots_per_op
= group_start
->slots_per_op
;
2237 spin_lock_bh(&chan
->lock
);
2239 cookie
= ppc440spe_desc_assign_cookie(chan
, sw_desc
);
2241 if (unlikely(list_empty(&chan
->chain
))) {
2243 list_splice_init(&sw_desc
->group_list
, &chan
->chain
);
2244 chan_first_cdb
[chan
->device
->id
] = group_start
;
2246 /* isn't first peer, bind CDBs to chain */
2247 old_chain_tail
= list_entry(chan
->chain
.prev
,
2248 struct ppc440spe_adma_desc_slot
,
2250 list_splice_init(&sw_desc
->group_list
,
2251 &old_chain_tail
->chain_node
);
2252 /* fix up the hardware chain */
2253 ppc440spe_desc_set_link(chan
, old_chain_tail
, group_start
);
2256 /* increment the pending count by the number of operations */
2257 chan
->pending
+= slot_cnt
/ slots_per_op
;
2258 ppc440spe_adma_check_threshold(chan
);
2259 spin_unlock_bh(&chan
->lock
);
2261 dev_dbg(chan
->device
->common
.dev
,
2262 "ppc440spe adma%d: %s cookie: %d slot: %d tx %p\n",
2263 chan
->device
->id
, __func__
,
2264 sw_desc
->async_tx
.cookie
, sw_desc
->idx
, sw_desc
);
2270 * ppc440spe_adma_prep_dma_interrupt - prepare CDB for a pseudo DMA operation
2272 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_interrupt(
2273 struct dma_chan
*chan
, unsigned long flags
)
2275 struct ppc440spe_adma_chan
*ppc440spe_chan
;
2276 struct ppc440spe_adma_desc_slot
*sw_desc
, *group_start
;
2277 int slot_cnt
, slots_per_op
;
2279 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
2281 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
2282 "ppc440spe adma%d: %s\n", ppc440spe_chan
->device
->id
,
2285 spin_lock_bh(&ppc440spe_chan
->lock
);
2286 slot_cnt
= slots_per_op
= 1;
2287 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
,
2290 group_start
= sw_desc
->group_head
;
2291 ppc440spe_desc_init_interrupt(group_start
, ppc440spe_chan
);
2292 group_start
->unmap_len
= 0;
2293 sw_desc
->async_tx
.flags
= flags
;
2295 spin_unlock_bh(&ppc440spe_chan
->lock
);
2297 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2301 * ppc440spe_adma_prep_dma_memcpy - prepare CDB for a MEMCPY operation
2303 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_memcpy(
2304 struct dma_chan
*chan
, dma_addr_t dma_dest
,
2305 dma_addr_t dma_src
, size_t len
, unsigned long flags
)
2307 struct ppc440spe_adma_chan
*ppc440spe_chan
;
2308 struct ppc440spe_adma_desc_slot
*sw_desc
, *group_start
;
2309 int slot_cnt
, slots_per_op
;
2311 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
2316 BUG_ON(unlikely(len
> PPC440SPE_ADMA_DMA_MAX_BYTE_COUNT
));
2318 spin_lock_bh(&ppc440spe_chan
->lock
);
2320 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
2321 "ppc440spe adma%d: %s len: %u int_en %d\n",
2322 ppc440spe_chan
->device
->id
, __func__
, len
,
2323 flags
& DMA_PREP_INTERRUPT
? 1 : 0);
2324 slot_cnt
= slots_per_op
= 1;
2325 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
,
2328 group_start
= sw_desc
->group_head
;
2329 ppc440spe_desc_init_memcpy(group_start
, flags
);
2330 ppc440spe_adma_set_dest(group_start
, dma_dest
, 0);
2331 ppc440spe_adma_memcpy_xor_set_src(group_start
, dma_src
, 0);
2332 ppc440spe_desc_set_byte_count(group_start
, ppc440spe_chan
, len
);
2333 sw_desc
->unmap_len
= len
;
2334 sw_desc
->async_tx
.flags
= flags
;
2336 spin_unlock_bh(&ppc440spe_chan
->lock
);
2338 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2342 * ppc440spe_adma_prep_dma_memset - prepare CDB for a MEMSET operation
2344 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_memset(
2345 struct dma_chan
*chan
, dma_addr_t dma_dest
, int value
,
2346 size_t len
, unsigned long flags
)
2348 struct ppc440spe_adma_chan
*ppc440spe_chan
;
2349 struct ppc440spe_adma_desc_slot
*sw_desc
, *group_start
;
2350 int slot_cnt
, slots_per_op
;
2352 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
2357 BUG_ON(unlikely(len
> PPC440SPE_ADMA_DMA_MAX_BYTE_COUNT
));
2359 spin_lock_bh(&ppc440spe_chan
->lock
);
2361 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
2362 "ppc440spe adma%d: %s cal: %u len: %u int_en %d\n",
2363 ppc440spe_chan
->device
->id
, __func__
, value
, len
,
2364 flags
& DMA_PREP_INTERRUPT
? 1 : 0);
2366 slot_cnt
= slots_per_op
= 1;
2367 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
,
2370 group_start
= sw_desc
->group_head
;
2371 ppc440spe_desc_init_memset(group_start
, value
, flags
);
2372 ppc440spe_adma_set_dest(group_start
, dma_dest
, 0);
2373 ppc440spe_desc_set_byte_count(group_start
, ppc440spe_chan
, len
);
2374 sw_desc
->unmap_len
= len
;
2375 sw_desc
->async_tx
.flags
= flags
;
2377 spin_unlock_bh(&ppc440spe_chan
->lock
);
2379 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2383 * ppc440spe_adma_prep_dma_xor - prepare CDB for a XOR operation
2385 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_xor(
2386 struct dma_chan
*chan
, dma_addr_t dma_dest
,
2387 dma_addr_t
*dma_src
, u32 src_cnt
, size_t len
,
2388 unsigned long flags
)
2390 struct ppc440spe_adma_chan
*ppc440spe_chan
;
2391 struct ppc440spe_adma_desc_slot
*sw_desc
, *group_start
;
2392 int slot_cnt
, slots_per_op
;
2394 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
2396 ADMA_LL_DBG(prep_dma_xor_dbg(ppc440spe_chan
->device
->id
,
2397 dma_dest
, dma_src
, src_cnt
));
2400 BUG_ON(unlikely(len
> PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT
));
2402 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
2403 "ppc440spe adma%d: %s src_cnt: %d len: %u int_en: %d\n",
2404 ppc440spe_chan
->device
->id
, __func__
, src_cnt
, len
,
2405 flags
& DMA_PREP_INTERRUPT
? 1 : 0);
2407 spin_lock_bh(&ppc440spe_chan
->lock
);
2408 slot_cnt
= ppc440spe_chan_xor_slot_count(len
, src_cnt
, &slots_per_op
);
2409 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
,
2412 group_start
= sw_desc
->group_head
;
2413 ppc440spe_desc_init_xor(group_start
, src_cnt
, flags
);
2414 ppc440spe_adma_set_dest(group_start
, dma_dest
, 0);
2416 ppc440spe_adma_memcpy_xor_set_src(group_start
,
2417 dma_src
[src_cnt
], src_cnt
);
2418 ppc440spe_desc_set_byte_count(group_start
, ppc440spe_chan
, len
);
2419 sw_desc
->unmap_len
= len
;
2420 sw_desc
->async_tx
.flags
= flags
;
2422 spin_unlock_bh(&ppc440spe_chan
->lock
);
2424 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2428 ppc440spe_desc_set_xor_src_cnt(struct ppc440spe_adma_desc_slot
*desc
,
2430 static void ppc440spe_init_rxor_cursor(struct ppc440spe_rxor
*cursor
);
2433 * ppc440spe_adma_init_dma2rxor_slot -
2435 static void ppc440spe_adma_init_dma2rxor_slot(
2436 struct ppc440spe_adma_desc_slot
*desc
,
2437 dma_addr_t
*src
, int src_cnt
)
2441 /* initialize CDB */
2442 for (i
= 0; i
< src_cnt
; i
++) {
2443 ppc440spe_adma_dma2rxor_prep_src(desc
, &desc
->rxor_cursor
, i
,
2444 desc
->src_cnt
, (u32
)src
[i
]);
2449 * ppc440spe_dma01_prep_mult -
2450 * for Q operation where destination is also the source
2452 static struct ppc440spe_adma_desc_slot
*ppc440spe_dma01_prep_mult(
2453 struct ppc440spe_adma_chan
*ppc440spe_chan
,
2454 dma_addr_t
*dst
, int dst_cnt
, dma_addr_t
*src
, int src_cnt
,
2455 const unsigned char *scf
, size_t len
, unsigned long flags
)
2457 struct ppc440spe_adma_desc_slot
*sw_desc
= NULL
;
2458 unsigned long op
= 0;
2461 set_bit(PPC440SPE_DESC_WXOR
, &op
);
2464 spin_lock_bh(&ppc440spe_chan
->lock
);
2466 /* use WXOR, each descriptor occupies one slot */
2467 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
, 1);
2469 struct ppc440spe_adma_chan
*chan
;
2470 struct ppc440spe_adma_desc_slot
*iter
;
2471 struct dma_cdb
*hw_desc
;
2473 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
2474 set_bits(op
, &sw_desc
->flags
);
2475 sw_desc
->src_cnt
= src_cnt
;
2476 sw_desc
->dst_cnt
= dst_cnt
;
2477 /* First descriptor, zero data in the destination and copy it
2478 * to q page using MULTICAST transfer.
2480 iter
= list_first_entry(&sw_desc
->group_list
,
2481 struct ppc440spe_adma_desc_slot
,
2483 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
2484 /* set 'next' pointer */
2485 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
2486 struct ppc440spe_adma_desc_slot
,
2488 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2489 hw_desc
= iter
->hw_desc
;
2490 hw_desc
->opc
= DMA_CDB_OPC_MULTICAST
;
2492 ppc440spe_desc_set_dest_addr(iter
, chan
,
2493 DMA_CUED_XOR_BASE
, dst
[0], 0);
2494 ppc440spe_desc_set_dest_addr(iter
, chan
, 0, dst
[1], 1);
2495 ppc440spe_desc_set_src_addr(iter
, chan
, 0, DMA_CUED_XOR_HB
,
2497 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
, len
);
2498 iter
->unmap_len
= len
;
2501 * Second descriptor, multiply data from the q page
2502 * and store the result in real destination.
2504 iter
= list_first_entry(&iter
->chain_node
,
2505 struct ppc440spe_adma_desc_slot
,
2507 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
2508 iter
->hw_next
= NULL
;
2509 if (flags
& DMA_PREP_INTERRUPT
)
2510 set_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2512 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2514 hw_desc
= iter
->hw_desc
;
2515 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
2516 ppc440spe_desc_set_src_addr(iter
, chan
, 0,
2517 DMA_CUED_XOR_HB
, dst
[1]);
2518 ppc440spe_desc_set_dest_addr(iter
, chan
,
2519 DMA_CUED_XOR_BASE
, dst
[0], 0);
2521 ppc440spe_desc_set_src_mult(iter
, chan
, DMA_CUED_MULT1_OFF
,
2522 DMA_CDB_SG_DST1
, scf
[0]);
2523 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
, len
);
2524 iter
->unmap_len
= len
;
2525 sw_desc
->async_tx
.flags
= flags
;
2528 spin_unlock_bh(&ppc440spe_chan
->lock
);
2534 * ppc440spe_dma01_prep_sum_product -
2535 * Dx = A*(P+Pxy) + B*(Q+Qxy) operation where destination is also
2538 static struct ppc440spe_adma_desc_slot
*ppc440spe_dma01_prep_sum_product(
2539 struct ppc440spe_adma_chan
*ppc440spe_chan
,
2540 dma_addr_t
*dst
, dma_addr_t
*src
, int src_cnt
,
2541 const unsigned char *scf
, size_t len
, unsigned long flags
)
2543 struct ppc440spe_adma_desc_slot
*sw_desc
= NULL
;
2544 unsigned long op
= 0;
2547 set_bit(PPC440SPE_DESC_WXOR
, &op
);
2550 spin_lock_bh(&ppc440spe_chan
->lock
);
2552 /* WXOR, each descriptor occupies one slot */
2553 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
, 1);
2555 struct ppc440spe_adma_chan
*chan
;
2556 struct ppc440spe_adma_desc_slot
*iter
;
2557 struct dma_cdb
*hw_desc
;
2559 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
2560 set_bits(op
, &sw_desc
->flags
);
2561 sw_desc
->src_cnt
= src_cnt
;
2562 sw_desc
->dst_cnt
= 1;
2563 /* 1st descriptor, src[1] data to q page and zero destination */
2564 iter
= list_first_entry(&sw_desc
->group_list
,
2565 struct ppc440spe_adma_desc_slot
,
2567 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
2568 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
2569 struct ppc440spe_adma_desc_slot
,
2571 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2572 hw_desc
= iter
->hw_desc
;
2573 hw_desc
->opc
= DMA_CDB_OPC_MULTICAST
;
2575 ppc440spe_desc_set_dest_addr(iter
, chan
, DMA_CUED_XOR_BASE
,
2577 ppc440spe_desc_set_dest_addr(iter
, chan
, 0,
2578 ppc440spe_chan
->qdest
, 1);
2579 ppc440spe_desc_set_src_addr(iter
, chan
, 0, DMA_CUED_XOR_HB
,
2581 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
, len
);
2582 iter
->unmap_len
= len
;
2584 /* 2nd descriptor, multiply src[1] data and store the
2585 * result in destination */
2586 iter
= list_first_entry(&iter
->chain_node
,
2587 struct ppc440spe_adma_desc_slot
,
2589 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
2590 /* set 'next' pointer */
2591 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
2592 struct ppc440spe_adma_desc_slot
,
2594 if (flags
& DMA_PREP_INTERRUPT
)
2595 set_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2597 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2599 hw_desc
= iter
->hw_desc
;
2600 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
2601 ppc440spe_desc_set_src_addr(iter
, chan
, 0, DMA_CUED_XOR_HB
,
2602 ppc440spe_chan
->qdest
);
2603 ppc440spe_desc_set_dest_addr(iter
, chan
, DMA_CUED_XOR_BASE
,
2605 ppc440spe_desc_set_src_mult(iter
, chan
, DMA_CUED_MULT1_OFF
,
2606 DMA_CDB_SG_DST1
, scf
[1]);
2607 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
, len
);
2608 iter
->unmap_len
= len
;
2611 * 3rd descriptor, multiply src[0] data and xor it
2614 iter
= list_first_entry(&iter
->chain_node
,
2615 struct ppc440spe_adma_desc_slot
,
2617 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
2618 iter
->hw_next
= NULL
;
2619 if (flags
& DMA_PREP_INTERRUPT
)
2620 set_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2622 clear_bit(PPC440SPE_DESC_INT
, &iter
->flags
);
2624 hw_desc
= iter
->hw_desc
;
2625 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
2626 ppc440spe_desc_set_src_addr(iter
, chan
, 0, DMA_CUED_XOR_HB
,
2628 ppc440spe_desc_set_dest_addr(iter
, chan
, DMA_CUED_XOR_BASE
,
2630 ppc440spe_desc_set_src_mult(iter
, chan
, DMA_CUED_MULT1_OFF
,
2631 DMA_CDB_SG_DST1
, scf
[0]);
2632 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
, len
);
2633 iter
->unmap_len
= len
;
2634 sw_desc
->async_tx
.flags
= flags
;
2637 spin_unlock_bh(&ppc440spe_chan
->lock
);
2642 static struct ppc440spe_adma_desc_slot
*ppc440spe_dma01_prep_pq(
2643 struct ppc440spe_adma_chan
*ppc440spe_chan
,
2644 dma_addr_t
*dst
, int dst_cnt
, dma_addr_t
*src
, int src_cnt
,
2645 const unsigned char *scf
, size_t len
, unsigned long flags
)
2648 struct ppc440spe_adma_desc_slot
*sw_desc
= NULL
, *iter
;
2649 unsigned long op
= 0;
2650 unsigned char mult
= 1;
2652 pr_debug("%s: dst_cnt %d, src_cnt %d, len %d\n",
2653 __func__
, dst_cnt
, src_cnt
, len
);
2654 /* select operations WXOR/RXOR depending on the
2655 * source addresses of operators and the number
2656 * of destinations (RXOR support only Q-parity calculations)
2658 set_bit(PPC440SPE_DESC_WXOR
, &op
);
2659 if (!test_and_set_bit(PPC440SPE_RXOR_RUN
, &ppc440spe_rxor_state
)) {
2662 * - there are more than 1 source,
2663 * - len is aligned on 512-byte boundary,
2664 * - source addresses fit to one of 4 possible regions.
2667 !(len
& MQ0_CF2H_RXOR_BS_MASK
) &&
2668 (src
[0] + len
) == src
[1]) {
2669 /* may do RXOR R1 R2 */
2670 set_bit(PPC440SPE_DESC_RXOR
, &op
);
2672 /* may try to enhance region of RXOR */
2673 if ((src
[1] + len
) == src
[2]) {
2674 /* do RXOR R1 R2 R3 */
2675 set_bit(PPC440SPE_DESC_RXOR123
,
2677 } else if ((src
[1] + len
* 2) == src
[2]) {
2678 /* do RXOR R1 R2 R4 */
2679 set_bit(PPC440SPE_DESC_RXOR124
, &op
);
2680 } else if ((src
[1] + len
* 3) == src
[2]) {
2681 /* do RXOR R1 R2 R5 */
2682 set_bit(PPC440SPE_DESC_RXOR125
,
2686 set_bit(PPC440SPE_DESC_RXOR12
,
2691 set_bit(PPC440SPE_DESC_RXOR12
, &op
);
2695 if (!test_bit(PPC440SPE_DESC_RXOR
, &op
)) {
2696 /* can not do this operation with RXOR */
2697 clear_bit(PPC440SPE_RXOR_RUN
,
2698 &ppc440spe_rxor_state
);
2700 /* can do; set block size right now */
2701 ppc440spe_desc_set_rxor_block_size(len
);
2705 /* Number of necessary slots depends on operation type selected */
2706 if (!test_bit(PPC440SPE_DESC_RXOR
, &op
)) {
2707 /* This is a WXOR only chain. Need descriptors for each
2708 * source to GF-XOR them with WXOR, and need descriptors
2709 * for each destination to zero them with WXOR
2713 if (flags
& DMA_PREP_ZERO_P
) {
2715 set_bit(PPC440SPE_ZERO_P
, &op
);
2717 if (flags
& DMA_PREP_ZERO_Q
) {
2719 set_bit(PPC440SPE_ZERO_Q
, &op
);
2722 /* Need 1/2 descriptor for RXOR operation, and
2723 * need (src_cnt - (2 or 3)) for WXOR of sources
2728 if (flags
& DMA_PREP_ZERO_P
)
2729 set_bit(PPC440SPE_ZERO_P
, &op
);
2730 if (flags
& DMA_PREP_ZERO_Q
)
2731 set_bit(PPC440SPE_ZERO_Q
, &op
);
2733 if (test_bit(PPC440SPE_DESC_RXOR12
, &op
))
2734 slot_cnt
+= src_cnt
- 2;
2736 slot_cnt
+= src_cnt
- 3;
2738 /* Thus we have either RXOR only chain or
2741 if (slot_cnt
== dst_cnt
)
2742 /* RXOR only chain */
2743 clear_bit(PPC440SPE_DESC_WXOR
, &op
);
2746 spin_lock_bh(&ppc440spe_chan
->lock
);
2747 /* for both RXOR/WXOR each descriptor occupies one slot */
2748 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
, 1);
2750 ppc440spe_desc_init_dma01pq(sw_desc
, dst_cnt
, src_cnt
,
2753 /* setup dst/src/mult */
2754 pr_debug("%s: set dst descriptor 0, 1: 0x%016llx, 0x%016llx\n",
2755 __func__
, dst
[0], dst
[1]);
2756 ppc440spe_adma_pq_set_dest(sw_desc
, dst
, flags
);
2758 ppc440spe_adma_pq_set_src(sw_desc
, src
[src_cnt
],
2761 /* NOTE: "Multi = 0 is equivalent to = 1" as it
2762 * stated in 440SPSPe_RAID6_Addendum_UM_1_17.pdf
2763 * doesn't work for RXOR with DMA0/1! Instead, multi=0
2764 * leads to zeroing source data after RXOR.
2765 * So, for P case set-up mult=1 explicitly.
2767 if (!(flags
& DMA_PREP_PQ_DISABLE_Q
))
2768 mult
= scf
[src_cnt
];
2769 ppc440spe_adma_pq_set_src_mult(sw_desc
,
2770 mult
, src_cnt
, dst_cnt
- 1);
2773 /* Setup byte count foreach slot just allocated */
2774 sw_desc
->async_tx
.flags
= flags
;
2775 list_for_each_entry(iter
, &sw_desc
->group_list
,
2777 ppc440spe_desc_set_byte_count(iter
,
2778 ppc440spe_chan
, len
);
2779 iter
->unmap_len
= len
;
2782 spin_unlock_bh(&ppc440spe_chan
->lock
);
2787 static struct ppc440spe_adma_desc_slot
*ppc440spe_dma2_prep_pq(
2788 struct ppc440spe_adma_chan
*ppc440spe_chan
,
2789 dma_addr_t
*dst
, int dst_cnt
, dma_addr_t
*src
, int src_cnt
,
2790 const unsigned char *scf
, size_t len
, unsigned long flags
)
2792 int slot_cnt
, descs_per_op
;
2793 struct ppc440spe_adma_desc_slot
*sw_desc
= NULL
, *iter
;
2794 unsigned long op
= 0;
2795 unsigned char mult
= 1;
2798 /*pr_debug("%s: dst_cnt %d, src_cnt %d, len %d\n",
2799 __func__, dst_cnt, src_cnt, len);*/
2801 spin_lock_bh(&ppc440spe_chan
->lock
);
2802 descs_per_op
= ppc440spe_dma2_pq_slot_count(src
, src_cnt
, len
);
2803 if (descs_per_op
< 0) {
2804 spin_unlock_bh(&ppc440spe_chan
->lock
);
2808 /* depending on number of sources we have 1 or 2 RXOR chains */
2809 slot_cnt
= descs_per_op
* dst_cnt
;
2811 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
, 1);
2814 sw_desc
->async_tx
.flags
= flags
;
2815 list_for_each_entry(iter
, &sw_desc
->group_list
, chain_node
) {
2816 ppc440spe_desc_init_dma2pq(iter
, dst_cnt
, src_cnt
,
2818 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
,
2820 iter
->unmap_len
= len
;
2822 ppc440spe_init_rxor_cursor(&(iter
->rxor_cursor
));
2823 iter
->rxor_cursor
.len
= len
;
2824 iter
->descs_per_op
= descs_per_op
;
2827 list_for_each_entry(iter
, &sw_desc
->group_list
, chain_node
) {
2829 if (op
% descs_per_op
== 0)
2830 ppc440spe_adma_init_dma2rxor_slot(iter
, src
,
2832 if (likely(!list_is_last(&iter
->chain_node
,
2833 &sw_desc
->group_list
))) {
2834 /* set 'next' pointer */
2836 list_entry(iter
->chain_node
.next
,
2837 struct ppc440spe_adma_desc_slot
,
2839 ppc440spe_xor_set_link(iter
, iter
->hw_next
);
2841 /* this is the last descriptor. */
2842 iter
->hw_next
= NULL
;
2846 /* fixup head descriptor */
2847 sw_desc
->dst_cnt
= dst_cnt
;
2848 if (flags
& DMA_PREP_ZERO_P
)
2849 set_bit(PPC440SPE_ZERO_P
, &sw_desc
->flags
);
2850 if (flags
& DMA_PREP_ZERO_Q
)
2851 set_bit(PPC440SPE_ZERO_Q
, &sw_desc
->flags
);
2853 /* setup dst/src/mult */
2854 ppc440spe_adma_pq_set_dest(sw_desc
, dst
, flags
);
2857 /* handle descriptors (if dst_cnt == 2) inside
2858 * the ppc440spe_adma_pq_set_srcxxx() functions
2860 ppc440spe_adma_pq_set_src(sw_desc
, src
[src_cnt
],
2862 if (!(flags
& DMA_PREP_PQ_DISABLE_Q
))
2863 mult
= scf
[src_cnt
];
2864 ppc440spe_adma_pq_set_src_mult(sw_desc
,
2865 mult
, src_cnt
, dst_cnt
- 1);
2868 spin_unlock_bh(&ppc440spe_chan
->lock
);
2869 ppc440spe_desc_set_rxor_block_size(len
);
2874 * ppc440spe_adma_prep_dma_pq - prepare CDB (group) for a GF-XOR operation
2876 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_pq(
2877 struct dma_chan
*chan
, dma_addr_t
*dst
, dma_addr_t
*src
,
2878 unsigned int src_cnt
, const unsigned char *scf
,
2879 size_t len
, unsigned long flags
)
2881 struct ppc440spe_adma_chan
*ppc440spe_chan
;
2882 struct ppc440spe_adma_desc_slot
*sw_desc
= NULL
;
2885 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
2887 ADMA_LL_DBG(prep_dma_pq_dbg(ppc440spe_chan
->device
->id
,
2888 dst
, src
, src_cnt
));
2890 BUG_ON(unlikely(len
> PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT
));
2893 if (src_cnt
== 1 && dst
[1] == src
[0]) {
2896 /* dst[1] is real destination (Q) */
2898 /* this is the page to multicast source data to */
2899 dest
[1] = ppc440spe_chan
->qdest
;
2900 sw_desc
= ppc440spe_dma01_prep_mult(ppc440spe_chan
,
2901 dest
, 2, src
, src_cnt
, scf
, len
, flags
);
2902 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2905 if (src_cnt
== 2 && dst
[1] == src
[1]) {
2906 sw_desc
= ppc440spe_dma01_prep_sum_product(ppc440spe_chan
,
2907 &dst
[1], src
, 2, scf
, len
, flags
);
2908 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2911 if (!(flags
& DMA_PREP_PQ_DISABLE_P
)) {
2914 flags
|= DMA_PREP_ZERO_P
;
2917 if (!(flags
& DMA_PREP_PQ_DISABLE_Q
)) {
2920 flags
|= DMA_PREP_ZERO_Q
;
2925 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
2926 "ppc440spe adma%d: %s src_cnt: %d len: %u int_en: %d\n",
2927 ppc440spe_chan
->device
->id
, __func__
, src_cnt
, len
,
2928 flags
& DMA_PREP_INTERRUPT
? 1 : 0);
2930 switch (ppc440spe_chan
->device
->id
) {
2931 case PPC440SPE_DMA0_ID
:
2932 case PPC440SPE_DMA1_ID
:
2933 sw_desc
= ppc440spe_dma01_prep_pq(ppc440spe_chan
,
2934 dst
, dst_cnt
, src
, src_cnt
, scf
,
2938 case PPC440SPE_XOR_ID
:
2939 sw_desc
= ppc440spe_dma2_prep_pq(ppc440spe_chan
,
2940 dst
, dst_cnt
, src
, src_cnt
, scf
,
2945 return sw_desc
? &sw_desc
->async_tx
: NULL
;
2949 * ppc440spe_adma_prep_dma_pqzero_sum - prepare CDB group for
2950 * a PQ_ZERO_SUM operation
2952 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_pqzero_sum(
2953 struct dma_chan
*chan
, dma_addr_t
*pq
, dma_addr_t
*src
,
2954 unsigned int src_cnt
, const unsigned char *scf
, size_t len
,
2955 enum sum_check_flags
*pqres
, unsigned long flags
)
2957 struct ppc440spe_adma_chan
*ppc440spe_chan
;
2958 struct ppc440spe_adma_desc_slot
*sw_desc
, *iter
;
2959 dma_addr_t pdest
, qdest
;
2960 int slot_cnt
, slots_per_op
, idst
, dst_cnt
;
2962 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
2964 if (flags
& DMA_PREP_PQ_DISABLE_P
)
2969 if (flags
& DMA_PREP_PQ_DISABLE_Q
)
2974 ADMA_LL_DBG(prep_dma_pqzero_sum_dbg(ppc440spe_chan
->device
->id
,
2975 src
, src_cnt
, scf
));
2977 /* Always use WXOR for P/Q calculations (two destinations).
2978 * Need 1 or 2 extra slots to verify results are zero.
2980 idst
= dst_cnt
= (pdest
&& qdest
) ? 2 : 1;
2982 /* One additional slot per destination to clone P/Q
2983 * before calculation (we have to preserve destinations).
2985 slot_cnt
= src_cnt
+ dst_cnt
* 2;
2988 spin_lock_bh(&ppc440spe_chan
->lock
);
2989 sw_desc
= ppc440spe_adma_alloc_slots(ppc440spe_chan
, slot_cnt
,
2992 ppc440spe_desc_init_dma01pqzero_sum(sw_desc
, dst_cnt
, src_cnt
);
2994 /* Setup byte count for each slot just allocated */
2995 sw_desc
->async_tx
.flags
= flags
;
2996 list_for_each_entry(iter
, &sw_desc
->group_list
, chain_node
) {
2997 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
,
2999 iter
->unmap_len
= len
;
3003 struct dma_cdb
*hw_desc
;
3004 struct ppc440spe_adma_chan
*chan
;
3006 iter
= sw_desc
->group_head
;
3007 chan
= to_ppc440spe_adma_chan(iter
->async_tx
.chan
);
3008 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
3009 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
3010 struct ppc440spe_adma_desc_slot
,
3012 hw_desc
= iter
->hw_desc
;
3013 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
3016 ppc440spe_desc_set_dest_addr(iter
, chan
, 0,
3017 ppc440spe_chan
->pdest
, 0);
3018 ppc440spe_desc_set_src_addr(iter
, chan
, 0, 0, pdest
);
3019 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
,
3021 iter
->unmap_len
= 0;
3022 /* override pdest to preserve original P */
3023 pdest
= ppc440spe_chan
->pdest
;
3026 struct dma_cdb
*hw_desc
;
3027 struct ppc440spe_adma_chan
*chan
;
3029 iter
= list_first_entry(&sw_desc
->group_list
,
3030 struct ppc440spe_adma_desc_slot
,
3032 chan
= to_ppc440spe_adma_chan(iter
->async_tx
.chan
);
3035 iter
= list_entry(iter
->chain_node
.next
,
3036 struct ppc440spe_adma_desc_slot
,
3040 memset(iter
->hw_desc
, 0, sizeof(struct dma_cdb
));
3041 iter
->hw_next
= list_entry(iter
->chain_node
.next
,
3042 struct ppc440spe_adma_desc_slot
,
3044 hw_desc
= iter
->hw_desc
;
3045 hw_desc
->opc
= DMA_CDB_OPC_MV_SG1_SG2
;
3048 ppc440spe_desc_set_dest_addr(iter
, chan
, 0,
3049 ppc440spe_chan
->qdest
, 0);
3050 ppc440spe_desc_set_src_addr(iter
, chan
, 0, 0, qdest
);
3051 ppc440spe_desc_set_byte_count(iter
, ppc440spe_chan
,
3053 iter
->unmap_len
= 0;
3054 /* override qdest to preserve original Q */
3055 qdest
= ppc440spe_chan
->qdest
;
3058 /* Setup destinations for P/Q ops */
3059 ppc440spe_adma_pqzero_sum_set_dest(sw_desc
, pdest
, qdest
);
3061 /* Setup zero QWORDs into DCHECK CDBs */
3063 list_for_each_entry_reverse(iter
, &sw_desc
->group_list
,
3066 * The last CDB corresponds to Q-parity check,
3067 * the one before last CDB corresponds
3070 if (idst
== DMA_DEST_MAX_NUM
) {
3071 if (idst
== dst_cnt
) {
3072 set_bit(PPC440SPE_DESC_QCHECK
,
3075 set_bit(PPC440SPE_DESC_PCHECK
,
3080 set_bit(PPC440SPE_DESC_QCHECK
,
3083 set_bit(PPC440SPE_DESC_PCHECK
,
3087 iter
->xor_check_result
= pqres
;
3090 * set it to zero, if check fail then result will
3093 *iter
->xor_check_result
= 0;
3094 ppc440spe_desc_set_dcheck(iter
, ppc440spe_chan
,
3101 /* Setup sources and mults for P/Q ops */
3102 list_for_each_entry_continue_reverse(iter
, &sw_desc
->group_list
,
3104 struct ppc440spe_adma_chan
*chan
;
3107 chan
= to_ppc440spe_adma_chan(iter
->async_tx
.chan
);
3108 ppc440spe_desc_set_src_addr(iter
, chan
, 0,
3112 mult_dst
= (dst_cnt
- 1) ? DMA_CDB_SG_DST2
:
3114 ppc440spe_desc_set_src_mult(iter
, chan
,
3123 spin_unlock_bh(&ppc440spe_chan
->lock
);
3124 return sw_desc
? &sw_desc
->async_tx
: NULL
;
3128 * ppc440spe_adma_prep_dma_xor_zero_sum - prepare CDB group for
3129 * XOR ZERO_SUM operation
3131 static struct dma_async_tx_descriptor
*ppc440spe_adma_prep_dma_xor_zero_sum(
3132 struct dma_chan
*chan
, dma_addr_t
*src
, unsigned int src_cnt
,
3133 size_t len
, enum sum_check_flags
*result
, unsigned long flags
)
3135 struct dma_async_tx_descriptor
*tx
;
3138 /* validate P, disable Q */
3141 flags
|= DMA_PREP_PQ_DISABLE_Q
;
3143 tx
= ppc440spe_adma_prep_dma_pqzero_sum(chan
, pq
, &src
[1],
3144 src_cnt
- 1, 0, len
,
3150 * ppc440spe_adma_set_dest - set destination address into descriptor
3152 static void ppc440spe_adma_set_dest(struct ppc440spe_adma_desc_slot
*sw_desc
,
3153 dma_addr_t addr
, int index
)
3155 struct ppc440spe_adma_chan
*chan
;
3157 BUG_ON(index
>= sw_desc
->dst_cnt
);
3159 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
3161 switch (chan
->device
->id
) {
3162 case PPC440SPE_DMA0_ID
:
3163 case PPC440SPE_DMA1_ID
:
3164 /* to do: support transfers lengths >
3165 * PPC440SPE_ADMA_DMA/XOR_MAX_BYTE_COUNT
3167 ppc440spe_desc_set_dest_addr(sw_desc
->group_head
,
3168 chan
, 0, addr
, index
);
3170 case PPC440SPE_XOR_ID
:
3171 sw_desc
= ppc440spe_get_group_entry(sw_desc
, index
);
3172 ppc440spe_desc_set_dest_addr(sw_desc
,
3173 chan
, 0, addr
, index
);
3178 static void ppc440spe_adma_pq_zero_op(struct ppc440spe_adma_desc_slot
*iter
,
3179 struct ppc440spe_adma_chan
*chan
, dma_addr_t addr
)
3181 /* To clear destinations update the descriptor
3182 * (P or Q depending on index) as follows:
3183 * addr is destination (0 corresponds to SG2):
3185 ppc440spe_desc_set_dest_addr(iter
, chan
, DMA_CUED_XOR_BASE
, addr
, 0);
3187 /* ... and the addr is source: */
3188 ppc440spe_desc_set_src_addr(iter
, chan
, 0, DMA_CUED_XOR_HB
, addr
);
3190 /* addr is always SG2 then the mult is always DST1 */
3191 ppc440spe_desc_set_src_mult(iter
, chan
, DMA_CUED_MULT1_OFF
,
3192 DMA_CDB_SG_DST1
, 1);
3196 * ppc440spe_adma_pq_set_dest - set destination address into descriptor
3197 * for the PQXOR operation
3199 static void ppc440spe_adma_pq_set_dest(struct ppc440spe_adma_desc_slot
*sw_desc
,
3200 dma_addr_t
*addrs
, unsigned long flags
)
3202 struct ppc440spe_adma_desc_slot
*iter
;
3203 struct ppc440spe_adma_chan
*chan
;
3204 dma_addr_t paddr
, qaddr
;
3205 dma_addr_t addr
= 0, ppath
, qpath
;
3208 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
3210 if (flags
& DMA_PREP_PQ_DISABLE_P
)
3215 if (flags
& DMA_PREP_PQ_DISABLE_Q
)
3220 if (!paddr
|| !qaddr
)
3221 addr
= paddr
? paddr
: qaddr
;
3223 switch (chan
->device
->id
) {
3224 case PPC440SPE_DMA0_ID
:
3225 case PPC440SPE_DMA1_ID
:
3226 /* walk through the WXOR source list and set P/Q-destinations
3229 if (!test_bit(PPC440SPE_DESC_RXOR
, &sw_desc
->flags
)) {
3230 /* This is WXOR-only chain; may have 1/2 zero descs */
3231 if (test_bit(PPC440SPE_ZERO_P
, &sw_desc
->flags
))
3233 if (test_bit(PPC440SPE_ZERO_Q
, &sw_desc
->flags
))
3236 iter
= ppc440spe_get_group_entry(sw_desc
, index
);
3238 /* one destination */
3239 list_for_each_entry_from(iter
,
3240 &sw_desc
->group_list
, chain_node
)
3241 ppc440spe_desc_set_dest_addr(iter
, chan
,
3242 DMA_CUED_XOR_BASE
, addr
, 0);
3244 /* two destinations */
3245 list_for_each_entry_from(iter
,
3246 &sw_desc
->group_list
, chain_node
) {
3247 ppc440spe_desc_set_dest_addr(iter
, chan
,
3248 DMA_CUED_XOR_BASE
, paddr
, 0);
3249 ppc440spe_desc_set_dest_addr(iter
, chan
,
3250 DMA_CUED_XOR_BASE
, qaddr
, 1);
3255 /* To clear destinations update the descriptor
3256 * (1st,2nd, or both depending on flags)
3259 if (test_bit(PPC440SPE_ZERO_P
,
3261 iter
= ppc440spe_get_group_entry(
3263 ppc440spe_adma_pq_zero_op(iter
, chan
,
3267 if (test_bit(PPC440SPE_ZERO_Q
,
3269 iter
= ppc440spe_get_group_entry(
3271 ppc440spe_adma_pq_zero_op(iter
, chan
,
3278 /* This is RXOR-only or RXOR/WXOR mixed chain */
3280 /* If we want to include destination into calculations,
3281 * then make dest addresses cued with mult=1 (XOR).
3283 ppath
= test_bit(PPC440SPE_ZERO_P
, &sw_desc
->flags
) ?
3286 (1 << DMA_CUED_MULT1_OFF
);
3287 qpath
= test_bit(PPC440SPE_ZERO_Q
, &sw_desc
->flags
) ?
3290 (1 << DMA_CUED_MULT1_OFF
);
3292 /* Setup destination(s) in RXOR slot(s) */
3293 iter
= ppc440spe_get_group_entry(sw_desc
, index
++);
3294 ppc440spe_desc_set_dest_addr(iter
, chan
,
3295 paddr
? ppath
: qpath
,
3296 paddr
? paddr
: qaddr
, 0);
3298 /* two destinations */
3299 iter
= ppc440spe_get_group_entry(sw_desc
,
3301 ppc440spe_desc_set_dest_addr(iter
, chan
,
3305 if (test_bit(PPC440SPE_DESC_WXOR
, &sw_desc
->flags
)) {
3306 /* Setup destination(s) in remaining WXOR
3309 iter
= ppc440spe_get_group_entry(sw_desc
,
3312 /* one destination */
3313 list_for_each_entry_from(iter
,
3314 &sw_desc
->group_list
,
3316 ppc440spe_desc_set_dest_addr(
3322 /* two destinations */
3323 list_for_each_entry_from(iter
,
3324 &sw_desc
->group_list
,
3326 ppc440spe_desc_set_dest_addr(
3330 ppc440spe_desc_set_dest_addr(
3341 case PPC440SPE_XOR_ID
:
3342 /* DMA2 descriptors have only 1 destination, so there are
3343 * two chains - one for each dest.
3344 * If we want to include destination into calculations,
3345 * then make dest addresses cued with mult=1 (XOR).
3347 ppath
= test_bit(PPC440SPE_ZERO_P
, &sw_desc
->flags
) ?
3350 (1 << DMA_CUED_MULT1_OFF
);
3352 qpath
= test_bit(PPC440SPE_ZERO_Q
, &sw_desc
->flags
) ?
3355 (1 << DMA_CUED_MULT1_OFF
);
3357 iter
= ppc440spe_get_group_entry(sw_desc
, 0);
3358 for (i
= 0; i
< sw_desc
->descs_per_op
; i
++) {
3359 ppc440spe_desc_set_dest_addr(iter
, chan
,
3360 paddr
? ppath
: qpath
,
3361 paddr
? paddr
: qaddr
, 0);
3362 iter
= list_entry(iter
->chain_node
.next
,
3363 struct ppc440spe_adma_desc_slot
,
3368 /* Two destinations; setup Q here */
3369 iter
= ppc440spe_get_group_entry(sw_desc
,
3370 sw_desc
->descs_per_op
);
3371 for (i
= 0; i
< sw_desc
->descs_per_op
; i
++) {
3372 ppc440spe_desc_set_dest_addr(iter
,
3373 chan
, qpath
, qaddr
, 0);
3374 iter
= list_entry(iter
->chain_node
.next
,
3375 struct ppc440spe_adma_desc_slot
,
3385 * ppc440spe_adma_pq_zero_sum_set_dest - set destination address into descriptor
3386 * for the PQ_ZERO_SUM operation
3388 static void ppc440spe_adma_pqzero_sum_set_dest(
3389 struct ppc440spe_adma_desc_slot
*sw_desc
,
3390 dma_addr_t paddr
, dma_addr_t qaddr
)
3392 struct ppc440spe_adma_desc_slot
*iter
, *end
;
3393 struct ppc440spe_adma_chan
*chan
;
3394 dma_addr_t addr
= 0;
3397 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
3399 /* walk through the WXOR source list and set P/Q-destinations
3402 idx
= (paddr
&& qaddr
) ? 2 : 1;
3404 list_for_each_entry_reverse(end
, &sw_desc
->group_list
,
3410 idx
= (paddr
&& qaddr
) ? 2 : 1;
3411 iter
= ppc440spe_get_group_entry(sw_desc
, idx
);
3413 if (paddr
&& qaddr
) {
3414 /* two destinations */
3415 list_for_each_entry_from(iter
, &sw_desc
->group_list
,
3417 if (unlikely(iter
== end
))
3419 ppc440spe_desc_set_dest_addr(iter
, chan
,
3420 DMA_CUED_XOR_BASE
, paddr
, 0);
3421 ppc440spe_desc_set_dest_addr(iter
, chan
,
3422 DMA_CUED_XOR_BASE
, qaddr
, 1);
3425 /* one destination */
3426 addr
= paddr
? paddr
: qaddr
;
3427 list_for_each_entry_from(iter
, &sw_desc
->group_list
,
3429 if (unlikely(iter
== end
))
3431 ppc440spe_desc_set_dest_addr(iter
, chan
,
3432 DMA_CUED_XOR_BASE
, addr
, 0);
3436 /* The remaining descriptors are DATACHECK. These have no need in
3437 * destination. Actually, these destinations are used there
3438 * as sources for check operation. So, set addr as source.
3440 ppc440spe_desc_set_src_addr(end
, chan
, 0, 0, addr
? addr
: paddr
);
3443 end
= list_entry(end
->chain_node
.next
,
3444 struct ppc440spe_adma_desc_slot
, chain_node
);
3445 ppc440spe_desc_set_src_addr(end
, chan
, 0, 0, qaddr
);
3450 * ppc440spe_desc_set_xor_src_cnt - set source count into descriptor
3452 static inline void ppc440spe_desc_set_xor_src_cnt(
3453 struct ppc440spe_adma_desc_slot
*desc
,
3456 struct xor_cb
*hw_desc
= desc
->hw_desc
;
3458 hw_desc
->cbc
&= ~XOR_CDCR_OAC_MSK
;
3459 hw_desc
->cbc
|= src_cnt
;
3463 * ppc440spe_adma_pq_set_src - set source address into descriptor
3465 static void ppc440spe_adma_pq_set_src(struct ppc440spe_adma_desc_slot
*sw_desc
,
3466 dma_addr_t addr
, int index
)
3468 struct ppc440spe_adma_chan
*chan
;
3469 dma_addr_t haddr
= 0;
3470 struct ppc440spe_adma_desc_slot
*iter
= NULL
;
3472 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
3474 switch (chan
->device
->id
) {
3475 case PPC440SPE_DMA0_ID
:
3476 case PPC440SPE_DMA1_ID
:
3477 /* DMA0,1 may do: WXOR, RXOR, RXOR+WXORs chain
3479 if (test_bit(PPC440SPE_DESC_RXOR
, &sw_desc
->flags
)) {
3480 /* RXOR-only or RXOR/WXOR operation */
3481 int iskip
= test_bit(PPC440SPE_DESC_RXOR12
,
3482 &sw_desc
->flags
) ? 2 : 3;
3485 /* 1st slot (RXOR) */
3486 /* setup sources region (R1-2-3, R1-2-4,
3489 if (test_bit(PPC440SPE_DESC_RXOR12
,
3491 haddr
= DMA_RXOR12
<<
3492 DMA_CUED_REGION_OFF
;
3493 else if (test_bit(PPC440SPE_DESC_RXOR123
,
3495 haddr
= DMA_RXOR123
<<
3496 DMA_CUED_REGION_OFF
;
3497 else if (test_bit(PPC440SPE_DESC_RXOR124
,
3499 haddr
= DMA_RXOR124
<<
3500 DMA_CUED_REGION_OFF
;
3501 else if (test_bit(PPC440SPE_DESC_RXOR125
,
3503 haddr
= DMA_RXOR125
<<
3504 DMA_CUED_REGION_OFF
;
3507 haddr
|= DMA_CUED_XOR_BASE
;
3508 iter
= ppc440spe_get_group_entry(sw_desc
, 0);
3509 } else if (index
< iskip
) {
3511 * shall actually set source address only once
3512 * instead of first <iskip>
3516 /* 2nd/3d and next slots (WXOR);
3517 * skip first slot with RXOR
3519 haddr
= DMA_CUED_XOR_HB
;
3520 iter
= ppc440spe_get_group_entry(sw_desc
,
3521 index
- iskip
+ sw_desc
->dst_cnt
);
3526 /* WXOR-only operation; skip first slots with
3527 * zeroing destinations
3529 if (test_bit(PPC440SPE_ZERO_P
, &sw_desc
->flags
))
3531 if (test_bit(PPC440SPE_ZERO_Q
, &sw_desc
->flags
))
3534 haddr
= DMA_CUED_XOR_HB
;
3535 iter
= ppc440spe_get_group_entry(sw_desc
,
3540 ppc440spe_desc_set_src_addr(iter
, chan
, 0, haddr
, addr
);
3543 test_bit(PPC440SPE_DESC_RXOR
, &sw_desc
->flags
) &&
3544 sw_desc
->dst_cnt
== 2) {
3545 /* if we have two destinations for RXOR, then
3546 * setup source in the second descr too
3548 iter
= ppc440spe_get_group_entry(sw_desc
, 1);
3549 ppc440spe_desc_set_src_addr(iter
, chan
, 0,
3555 case PPC440SPE_XOR_ID
:
3556 /* DMA2 may do Biskup */
3557 iter
= sw_desc
->group_head
;
3558 if (iter
->dst_cnt
== 2) {
3559 /* both P & Q calculations required; set P src here */
3560 ppc440spe_adma_dma2rxor_set_src(iter
, index
, addr
);
3563 iter
= ppc440spe_get_group_entry(sw_desc
,
3564 sw_desc
->descs_per_op
);
3566 ppc440spe_adma_dma2rxor_set_src(iter
, index
, addr
);
3572 * ppc440spe_adma_memcpy_xor_set_src - set source address into descriptor
3574 static void ppc440spe_adma_memcpy_xor_set_src(
3575 struct ppc440spe_adma_desc_slot
*sw_desc
,
3576 dma_addr_t addr
, int index
)
3578 struct ppc440spe_adma_chan
*chan
;
3580 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
3581 sw_desc
= sw_desc
->group_head
;
3583 if (likely(sw_desc
))
3584 ppc440spe_desc_set_src_addr(sw_desc
, chan
, index
, 0, addr
);
3588 * ppc440spe_adma_dma2rxor_inc_addr -
3590 static void ppc440spe_adma_dma2rxor_inc_addr(
3591 struct ppc440spe_adma_desc_slot
*desc
,
3592 struct ppc440spe_rxor
*cursor
, int index
, int src_cnt
)
3594 cursor
->addr_count
++;
3595 if (index
== src_cnt
- 1) {
3596 ppc440spe_desc_set_xor_src_cnt(desc
, cursor
->addr_count
);
3597 } else if (cursor
->addr_count
== XOR_MAX_OPS
) {
3598 ppc440spe_desc_set_xor_src_cnt(desc
, cursor
->addr_count
);
3599 cursor
->addr_count
= 0;
3600 cursor
->desc_count
++;
3605 * ppc440spe_adma_dma2rxor_prep_src - setup RXOR types in DMA2 CDB
3607 static int ppc440spe_adma_dma2rxor_prep_src(
3608 struct ppc440spe_adma_desc_slot
*hdesc
,
3609 struct ppc440spe_rxor
*cursor
, int index
,
3610 int src_cnt
, u32 addr
)
3614 struct ppc440spe_adma_desc_slot
*desc
= hdesc
;
3617 for (i
= 0; i
< cursor
->desc_count
; i
++) {
3618 desc
= list_entry(hdesc
->chain_node
.next
,
3619 struct ppc440spe_adma_desc_slot
,
3623 switch (cursor
->state
) {
3625 if (addr
== cursor
->addrl
+ cursor
->len
) {
3628 cursor
->xor_count
++;
3629 if (index
== src_cnt
-1) {
3630 ppc440spe_rxor_set_region(desc
,
3632 DMA_RXOR12
<< DMA_CUED_REGION_OFF
);
3633 ppc440spe_adma_dma2rxor_inc_addr(
3634 desc
, cursor
, index
, src_cnt
);
3636 } else if (cursor
->addrl
== addr
+ cursor
->len
) {
3639 cursor
->xor_count
++;
3640 set_bit(cursor
->addr_count
, &desc
->reverse_flags
[0]);
3641 if (index
== src_cnt
-1) {
3642 ppc440spe_rxor_set_region(desc
,
3644 DMA_RXOR12
<< DMA_CUED_REGION_OFF
);
3645 ppc440spe_adma_dma2rxor_inc_addr(
3646 desc
, cursor
, index
, src_cnt
);
3649 printk(KERN_ERR
"Cannot build "
3650 "DMA2 RXOR command block.\n");
3655 sign
= test_bit(cursor
->addr_count
,
3656 desc
->reverse_flags
)
3658 if (index
== src_cnt
-2 || (sign
== -1
3659 && addr
!= cursor
->addrl
- 2*cursor
->len
)) {
3661 cursor
->xor_count
= 1;
3662 cursor
->addrl
= addr
;
3663 ppc440spe_rxor_set_region(desc
,
3665 DMA_RXOR12
<< DMA_CUED_REGION_OFF
);
3666 ppc440spe_adma_dma2rxor_inc_addr(
3667 desc
, cursor
, index
, src_cnt
);
3668 } else if (addr
== cursor
->addrl
+ 2*sign
*cursor
->len
) {
3670 cursor
->xor_count
= 0;
3671 ppc440spe_rxor_set_region(desc
,
3673 DMA_RXOR123
<< DMA_CUED_REGION_OFF
);
3674 if (index
== src_cnt
-1) {
3675 ppc440spe_adma_dma2rxor_inc_addr(
3676 desc
, cursor
, index
, src_cnt
);
3678 } else if (addr
== cursor
->addrl
+ 3*cursor
->len
) {
3680 cursor
->xor_count
= 0;
3681 ppc440spe_rxor_set_region(desc
,
3683 DMA_RXOR124
<< DMA_CUED_REGION_OFF
);
3684 if (index
== src_cnt
-1) {
3685 ppc440spe_adma_dma2rxor_inc_addr(
3686 desc
, cursor
, index
, src_cnt
);
3688 } else if (addr
== cursor
->addrl
+ 4*cursor
->len
) {
3690 cursor
->xor_count
= 0;
3691 ppc440spe_rxor_set_region(desc
,
3693 DMA_RXOR125
<< DMA_CUED_REGION_OFF
);
3694 if (index
== src_cnt
-1) {
3695 ppc440spe_adma_dma2rxor_inc_addr(
3696 desc
, cursor
, index
, src_cnt
);
3700 cursor
->xor_count
= 1;
3701 cursor
->addrl
= addr
;
3702 ppc440spe_rxor_set_region(desc
,
3704 DMA_RXOR12
<< DMA_CUED_REGION_OFF
);
3705 ppc440spe_adma_dma2rxor_inc_addr(
3706 desc
, cursor
, index
, src_cnt
);
3711 cursor
->addrl
= addr
;
3712 cursor
->xor_count
++;
3714 ppc440spe_adma_dma2rxor_inc_addr(
3715 desc
, cursor
, index
, src_cnt
);
3724 * ppc440spe_adma_dma2rxor_set_src - set RXOR source address; it's assumed that
3725 * ppc440spe_adma_dma2rxor_prep_src() has already done prior this call
3727 static void ppc440spe_adma_dma2rxor_set_src(
3728 struct ppc440spe_adma_desc_slot
*desc
,
3729 int index
, dma_addr_t addr
)
3731 struct xor_cb
*xcb
= desc
->hw_desc
;
3732 int k
= 0, op
= 0, lop
= 0;
3734 /* get the RXOR operand which corresponds to index addr */
3735 while (op
<= index
) {
3737 if (k
== XOR_MAX_OPS
) {
3739 desc
= list_entry(desc
->chain_node
.next
,
3740 struct ppc440spe_adma_desc_slot
, chain_node
);
3741 xcb
= desc
->hw_desc
;
3744 if ((xcb
->ops
[k
++].h
& (DMA_RXOR12
<< DMA_CUED_REGION_OFF
)) ==
3745 (DMA_RXOR12
<< DMA_CUED_REGION_OFF
))
3753 if (test_bit(k
-1, desc
->reverse_flags
)) {
3754 /* reverse operand order; put last op in RXOR group */
3755 if (index
== op
- 1)
3756 ppc440spe_rxor_set_src(desc
, k
- 1, addr
);
3758 /* direct operand order; put first op in RXOR group */
3760 ppc440spe_rxor_set_src(desc
, k
- 1, addr
);
3765 * ppc440spe_adma_dma2rxor_set_mult - set RXOR multipliers; it's assumed that
3766 * ppc440spe_adma_dma2rxor_prep_src() has already done prior this call
3768 static void ppc440spe_adma_dma2rxor_set_mult(
3769 struct ppc440spe_adma_desc_slot
*desc
,
3772 struct xor_cb
*xcb
= desc
->hw_desc
;
3773 int k
= 0, op
= 0, lop
= 0;
3775 /* get the RXOR operand which corresponds to index mult */
3776 while (op
<= index
) {
3778 if (k
== XOR_MAX_OPS
) {
3780 desc
= list_entry(desc
->chain_node
.next
,
3781 struct ppc440spe_adma_desc_slot
,
3783 xcb
= desc
->hw_desc
;
3786 if ((xcb
->ops
[k
++].h
& (DMA_RXOR12
<< DMA_CUED_REGION_OFF
)) ==
3787 (DMA_RXOR12
<< DMA_CUED_REGION_OFF
))
3794 if (test_bit(k
-1, desc
->reverse_flags
)) {
3796 ppc440spe_rxor_set_mult(desc
, k
- 1, op
- index
- 1, mult
);
3799 ppc440spe_rxor_set_mult(desc
, k
- 1, index
- lop
, mult
);
3804 * ppc440spe_init_rxor_cursor -
3806 static void ppc440spe_init_rxor_cursor(struct ppc440spe_rxor
*cursor
)
3808 memset(cursor
, 0, sizeof(struct ppc440spe_rxor
));
3813 * ppc440spe_adma_pq_set_src_mult - set multiplication coefficient into
3814 * descriptor for the PQXOR operation
3816 static void ppc440spe_adma_pq_set_src_mult(
3817 struct ppc440spe_adma_desc_slot
*sw_desc
,
3818 unsigned char mult
, int index
, int dst_pos
)
3820 struct ppc440spe_adma_chan
*chan
;
3821 u32 mult_idx
, mult_dst
;
3822 struct ppc440spe_adma_desc_slot
*iter
= NULL
, *iter1
= NULL
;
3824 chan
= to_ppc440spe_adma_chan(sw_desc
->async_tx
.chan
);
3826 switch (chan
->device
->id
) {
3827 case PPC440SPE_DMA0_ID
:
3828 case PPC440SPE_DMA1_ID
:
3829 if (test_bit(PPC440SPE_DESC_RXOR
, &sw_desc
->flags
)) {
3830 int region
= test_bit(PPC440SPE_DESC_RXOR12
,
3831 &sw_desc
->flags
) ? 2 : 3;
3833 if (index
< region
) {
3834 /* RXOR multipliers */
3835 iter
= ppc440spe_get_group_entry(sw_desc
,
3836 sw_desc
->dst_cnt
- 1);
3837 if (sw_desc
->dst_cnt
== 2)
3838 iter1
= ppc440spe_get_group_entry(
3841 mult_idx
= DMA_CUED_MULT1_OFF
+ (index
<< 3);
3842 mult_dst
= DMA_CDB_SG_SRC
;
3844 /* WXOR multiplier */
3845 iter
= ppc440spe_get_group_entry(sw_desc
,
3848 mult_idx
= DMA_CUED_MULT1_OFF
;
3849 mult_dst
= dst_pos
? DMA_CDB_SG_DST2
:
3856 * skip first slots with destinations (if ZERO_DST has
3859 if (test_bit(PPC440SPE_ZERO_P
, &sw_desc
->flags
))
3861 if (test_bit(PPC440SPE_ZERO_Q
, &sw_desc
->flags
))
3864 iter
= ppc440spe_get_group_entry(sw_desc
, index
+ znum
);
3865 mult_idx
= DMA_CUED_MULT1_OFF
;
3866 mult_dst
= dst_pos
? DMA_CDB_SG_DST2
: DMA_CDB_SG_DST1
;
3870 ppc440spe_desc_set_src_mult(iter
, chan
,
3871 mult_idx
, mult_dst
, mult
);
3873 if (unlikely(iter1
)) {
3874 /* if we have two destinations for RXOR, then
3875 * we've just set Q mult. Set-up P now.
3877 ppc440spe_desc_set_src_mult(iter1
, chan
,
3878 mult_idx
, mult_dst
, 1);
3884 case PPC440SPE_XOR_ID
:
3885 iter
= sw_desc
->group_head
;
3886 if (sw_desc
->dst_cnt
== 2) {
3887 /* both P & Q calculations required; set P mult here */
3888 ppc440spe_adma_dma2rxor_set_mult(iter
, index
, 1);
3890 /* and then set Q mult */
3891 iter
= ppc440spe_get_group_entry(sw_desc
,
3892 sw_desc
->descs_per_op
);
3894 ppc440spe_adma_dma2rxor_set_mult(iter
, index
, mult
);
3900 * ppc440spe_adma_free_chan_resources - free the resources allocated
3902 static void ppc440spe_adma_free_chan_resources(struct dma_chan
*chan
)
3904 struct ppc440spe_adma_chan
*ppc440spe_chan
;
3905 struct ppc440spe_adma_desc_slot
*iter
, *_iter
;
3906 int in_use_descs
= 0;
3908 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
3909 ppc440spe_adma_slot_cleanup(ppc440spe_chan
);
3911 spin_lock_bh(&ppc440spe_chan
->lock
);
3912 list_for_each_entry_safe(iter
, _iter
, &ppc440spe_chan
->chain
,
3915 list_del(&iter
->chain_node
);
3917 list_for_each_entry_safe_reverse(iter
, _iter
,
3918 &ppc440spe_chan
->all_slots
, slot_node
) {
3919 list_del(&iter
->slot_node
);
3921 ppc440spe_chan
->slots_allocated
--;
3923 ppc440spe_chan
->last_used
= NULL
;
3925 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
3926 "ppc440spe adma%d %s slots_allocated %d\n",
3927 ppc440spe_chan
->device
->id
,
3928 __func__
, ppc440spe_chan
->slots_allocated
);
3929 spin_unlock_bh(&ppc440spe_chan
->lock
);
3931 /* one is ok since we left it on there on purpose */
3932 if (in_use_descs
> 1)
3933 printk(KERN_ERR
"SPE: Freeing %d in use descriptors!\n",
3938 * ppc440spe_adma_is_complete - poll the status of an ADMA transaction
3939 * @chan: ADMA channel handle
3940 * @cookie: ADMA transaction identifier
3942 static enum dma_status
ppc440spe_adma_is_complete(struct dma_chan
*chan
,
3943 dma_cookie_t cookie
, dma_cookie_t
*done
, dma_cookie_t
*used
)
3945 struct ppc440spe_adma_chan
*ppc440spe_chan
;
3946 dma_cookie_t last_used
;
3947 dma_cookie_t last_complete
;
3948 enum dma_status ret
;
3950 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
3951 last_used
= chan
->cookie
;
3952 last_complete
= ppc440spe_chan
->completed_cookie
;
3955 *done
= last_complete
;
3959 ret
= dma_async_is_complete(cookie
, last_complete
, last_used
);
3960 if (ret
== DMA_SUCCESS
)
3963 ppc440spe_adma_slot_cleanup(ppc440spe_chan
);
3965 last_used
= chan
->cookie
;
3966 last_complete
= ppc440spe_chan
->completed_cookie
;
3969 *done
= last_complete
;
3973 return dma_async_is_complete(cookie
, last_complete
, last_used
);
3977 * ppc440spe_adma_eot_handler - end of transfer interrupt handler
3979 static irqreturn_t
ppc440spe_adma_eot_handler(int irq
, void *data
)
3981 struct ppc440spe_adma_chan
*chan
= data
;
3983 dev_dbg(chan
->device
->common
.dev
,
3984 "ppc440spe adma%d: %s\n", chan
->device
->id
, __func__
);
3986 tasklet_schedule(&chan
->irq_tasklet
);
3987 ppc440spe_adma_device_clear_eot_status(chan
);
3993 * ppc440spe_adma_err_handler - DMA error interrupt handler;
3994 * do the same things as a eot handler
3996 static irqreturn_t
ppc440spe_adma_err_handler(int irq
, void *data
)
3998 struct ppc440spe_adma_chan
*chan
= data
;
4000 dev_dbg(chan
->device
->common
.dev
,
4001 "ppc440spe adma%d: %s\n", chan
->device
->id
, __func__
);
4003 tasklet_schedule(&chan
->irq_tasklet
);
4004 ppc440spe_adma_device_clear_eot_status(chan
);
4010 * ppc440spe_test_callback - called when test operation has been done
4012 static void ppc440spe_test_callback(void *unused
)
4014 complete(&ppc440spe_r6_test_comp
);
4018 * ppc440spe_adma_issue_pending - flush all pending descriptors to h/w
4020 static void ppc440spe_adma_issue_pending(struct dma_chan
*chan
)
4022 struct ppc440spe_adma_chan
*ppc440spe_chan
;
4024 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
4025 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
4026 "ppc440spe adma%d: %s %d \n", ppc440spe_chan
->device
->id
,
4027 __func__
, ppc440spe_chan
->pending
);
4029 if (ppc440spe_chan
->pending
) {
4030 ppc440spe_chan
->pending
= 0;
4031 ppc440spe_chan_append(ppc440spe_chan
);
4036 * ppc440spe_chan_start_null_xor - initiate the first XOR operation (DMA engines
4037 * use FIFOs (as opposite to chains used in XOR) so this is a XOR
4038 * specific operation)
4040 static void ppc440spe_chan_start_null_xor(struct ppc440spe_adma_chan
*chan
)
4042 struct ppc440spe_adma_desc_slot
*sw_desc
, *group_start
;
4043 dma_cookie_t cookie
;
4044 int slot_cnt
, slots_per_op
;
4046 dev_dbg(chan
->device
->common
.dev
,
4047 "ppc440spe adma%d: %s\n", chan
->device
->id
, __func__
);
4049 spin_lock_bh(&chan
->lock
);
4050 slot_cnt
= ppc440spe_chan_xor_slot_count(0, 2, &slots_per_op
);
4051 sw_desc
= ppc440spe_adma_alloc_slots(chan
, slot_cnt
, slots_per_op
);
4053 group_start
= sw_desc
->group_head
;
4054 list_splice_init(&sw_desc
->group_list
, &chan
->chain
);
4055 async_tx_ack(&sw_desc
->async_tx
);
4056 ppc440spe_desc_init_null_xor(group_start
);
4058 cookie
= chan
->common
.cookie
;
4063 /* initialize the completed cookie to be less than
4064 * the most recently used cookie
4066 chan
->completed_cookie
= cookie
- 1;
4067 chan
->common
.cookie
= sw_desc
->async_tx
.cookie
= cookie
;
4069 /* channel should not be busy */
4070 BUG_ON(ppc440spe_chan_is_busy(chan
));
4072 /* set the descriptor address */
4073 ppc440spe_chan_set_first_xor_descriptor(chan
, sw_desc
);
4075 /* run the descriptor */
4076 ppc440spe_chan_run(chan
);
4078 printk(KERN_ERR
"ppc440spe adma%d"
4079 " failed to allocate null descriptor\n",
4081 spin_unlock_bh(&chan
->lock
);
4085 * ppc440spe_test_raid6 - test are RAID-6 capabilities enabled successfully.
4086 * For this we just perform one WXOR operation with the same source
4087 * and destination addresses, the GF-multiplier is 1; so if RAID-6
4088 * capabilities are enabled then we'll get src/dst filled with zero.
4090 static int ppc440spe_test_raid6(struct ppc440spe_adma_chan
*chan
)
4092 struct ppc440spe_adma_desc_slot
*sw_desc
, *iter
;
4095 dma_addr_t dma_addr
, addrs
[2];
4096 unsigned long op
= 0;
4099 set_bit(PPC440SPE_DESC_WXOR
, &op
);
4101 pg
= alloc_page(GFP_KERNEL
);
4105 spin_lock_bh(&chan
->lock
);
4106 sw_desc
= ppc440spe_adma_alloc_slots(chan
, 1, 1);
4108 /* 1 src, 1 dsr, int_ena, WXOR */
4109 ppc440spe_desc_init_dma01pq(sw_desc
, 1, 1, 1, op
);
4110 list_for_each_entry(iter
, &sw_desc
->group_list
, chain_node
) {
4111 ppc440spe_desc_set_byte_count(iter
, chan
, PAGE_SIZE
);
4112 iter
->unmap_len
= PAGE_SIZE
;
4116 spin_unlock_bh(&chan
->lock
);
4119 spin_unlock_bh(&chan
->lock
);
4121 /* Fill the test page with ones */
4122 memset(page_address(pg
), 0xFF, PAGE_SIZE
);
4123 dma_addr
= dma_map_page(chan
->device
->dev
, pg
, 0,
4124 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4126 /* Setup addresses */
4127 ppc440spe_adma_pq_set_src(sw_desc
, dma_addr
, 0);
4128 ppc440spe_adma_pq_set_src_mult(sw_desc
, 1, 0, 0);
4129 addrs
[0] = dma_addr
;
4131 ppc440spe_adma_pq_set_dest(sw_desc
, addrs
, DMA_PREP_PQ_DISABLE_Q
);
4133 async_tx_ack(&sw_desc
->async_tx
);
4134 sw_desc
->async_tx
.callback
= ppc440spe_test_callback
;
4135 sw_desc
->async_tx
.callback_param
= NULL
;
4137 init_completion(&ppc440spe_r6_test_comp
);
4139 ppc440spe_adma_tx_submit(&sw_desc
->async_tx
);
4140 ppc440spe_adma_issue_pending(&chan
->common
);
4142 wait_for_completion(&ppc440spe_r6_test_comp
);
4144 /* Now check if the test page is zeroed */
4145 a
= page_address(pg
);
4146 if ((*(u32
*)a
) == 0 && memcmp(a
, a
+4, PAGE_SIZE
-4) == 0) {
4147 /* page is zero - RAID-6 enabled */
4150 /* RAID-6 was not enabled */
4158 static void ppc440spe_adma_init_capabilities(struct ppc440spe_adma_device
*adev
)
4161 case PPC440SPE_DMA0_ID
:
4162 case PPC440SPE_DMA1_ID
:
4163 dma_cap_set(DMA_MEMCPY
, adev
->common
.cap_mask
);
4164 dma_cap_set(DMA_INTERRUPT
, adev
->common
.cap_mask
);
4165 dma_cap_set(DMA_MEMSET
, adev
->common
.cap_mask
);
4166 dma_cap_set(DMA_PQ
, adev
->common
.cap_mask
);
4167 dma_cap_set(DMA_PQ_VAL
, adev
->common
.cap_mask
);
4168 dma_cap_set(DMA_XOR_VAL
, adev
->common
.cap_mask
);
4170 case PPC440SPE_XOR_ID
:
4171 dma_cap_set(DMA_XOR
, adev
->common
.cap_mask
);
4172 dma_cap_set(DMA_PQ
, adev
->common
.cap_mask
);
4173 dma_cap_set(DMA_INTERRUPT
, adev
->common
.cap_mask
);
4174 adev
->common
.cap_mask
= adev
->common
.cap_mask
;
4178 /* Set base routines */
4179 adev
->common
.device_alloc_chan_resources
=
4180 ppc440spe_adma_alloc_chan_resources
;
4181 adev
->common
.device_free_chan_resources
=
4182 ppc440spe_adma_free_chan_resources
;
4183 adev
->common
.device_is_tx_complete
= ppc440spe_adma_is_complete
;
4184 adev
->common
.device_issue_pending
= ppc440spe_adma_issue_pending
;
4186 /* Set prep routines based on capability */
4187 if (dma_has_cap(DMA_MEMCPY
, adev
->common
.cap_mask
)) {
4188 adev
->common
.device_prep_dma_memcpy
=
4189 ppc440spe_adma_prep_dma_memcpy
;
4191 if (dma_has_cap(DMA_MEMSET
, adev
->common
.cap_mask
)) {
4192 adev
->common
.device_prep_dma_memset
=
4193 ppc440spe_adma_prep_dma_memset
;
4195 if (dma_has_cap(DMA_XOR
, adev
->common
.cap_mask
)) {
4196 adev
->common
.max_xor
= XOR_MAX_OPS
;
4197 adev
->common
.device_prep_dma_xor
=
4198 ppc440spe_adma_prep_dma_xor
;
4200 if (dma_has_cap(DMA_PQ
, adev
->common
.cap_mask
)) {
4202 case PPC440SPE_DMA0_ID
:
4203 dma_set_maxpq(&adev
->common
,
4204 DMA0_FIFO_SIZE
/ sizeof(struct dma_cdb
), 0);
4206 case PPC440SPE_DMA1_ID
:
4207 dma_set_maxpq(&adev
->common
,
4208 DMA1_FIFO_SIZE
/ sizeof(struct dma_cdb
), 0);
4210 case PPC440SPE_XOR_ID
:
4211 adev
->common
.max_pq
= XOR_MAX_OPS
* 3;
4214 adev
->common
.device_prep_dma_pq
=
4215 ppc440spe_adma_prep_dma_pq
;
4217 if (dma_has_cap(DMA_PQ_VAL
, adev
->common
.cap_mask
)) {
4219 case PPC440SPE_DMA0_ID
:
4220 adev
->common
.max_pq
= DMA0_FIFO_SIZE
/
4221 sizeof(struct dma_cdb
);
4223 case PPC440SPE_DMA1_ID
:
4224 adev
->common
.max_pq
= DMA1_FIFO_SIZE
/
4225 sizeof(struct dma_cdb
);
4228 adev
->common
.device_prep_dma_pq_val
=
4229 ppc440spe_adma_prep_dma_pqzero_sum
;
4231 if (dma_has_cap(DMA_XOR_VAL
, adev
->common
.cap_mask
)) {
4233 case PPC440SPE_DMA0_ID
:
4234 adev
->common
.max_xor
= DMA0_FIFO_SIZE
/
4235 sizeof(struct dma_cdb
);
4237 case PPC440SPE_DMA1_ID
:
4238 adev
->common
.max_xor
= DMA1_FIFO_SIZE
/
4239 sizeof(struct dma_cdb
);
4242 adev
->common
.device_prep_dma_xor_val
=
4243 ppc440spe_adma_prep_dma_xor_zero_sum
;
4245 if (dma_has_cap(DMA_INTERRUPT
, adev
->common
.cap_mask
)) {
4246 adev
->common
.device_prep_dma_interrupt
=
4247 ppc440spe_adma_prep_dma_interrupt
;
4249 pr_info("%s: AMCC(R) PPC440SP(E) ADMA Engine: "
4250 "( %s%s%s%s%s%s%s)\n",
4251 dev_name(adev
->dev
),
4252 dma_has_cap(DMA_PQ
, adev
->common
.cap_mask
) ? "pq " : "",
4253 dma_has_cap(DMA_PQ_VAL
, adev
->common
.cap_mask
) ? "pq_val " : "",
4254 dma_has_cap(DMA_XOR
, adev
->common
.cap_mask
) ? "xor " : "",
4255 dma_has_cap(DMA_XOR_VAL
, adev
->common
.cap_mask
) ? "xor_val " : "",
4256 dma_has_cap(DMA_MEMCPY
, adev
->common
.cap_mask
) ? "memcpy " : "",
4257 dma_has_cap(DMA_MEMSET
, adev
->common
.cap_mask
) ? "memset " : "",
4258 dma_has_cap(DMA_INTERRUPT
, adev
->common
.cap_mask
) ? "intr " : "");
4261 static int ppc440spe_adma_setup_irqs(struct ppc440spe_adma_device
*adev
,
4262 struct ppc440spe_adma_chan
*chan
,
4265 struct device_node
*np
;
4268 np
= container_of(adev
->dev
, struct of_device
, dev
)->node
;
4269 if (adev
->id
!= PPC440SPE_XOR_ID
) {
4270 adev
->err_irq
= irq_of_parse_and_map(np
, 1);
4271 if (adev
->err_irq
== NO_IRQ
) {
4272 dev_warn(adev
->dev
, "no err irq resource?\n");
4273 *initcode
= PPC_ADMA_INIT_IRQ2
;
4274 adev
->err_irq
= -ENXIO
;
4276 atomic_inc(&ppc440spe_adma_err_irq_ref
);
4278 adev
->err_irq
= -ENXIO
;
4281 adev
->irq
= irq_of_parse_and_map(np
, 0);
4282 if (adev
->irq
== NO_IRQ
) {
4283 dev_err(adev
->dev
, "no irq resource\n");
4284 *initcode
= PPC_ADMA_INIT_IRQ1
;
4288 dev_dbg(adev
->dev
, "irq %d, err irq %d\n",
4289 adev
->irq
, adev
->err_irq
);
4291 ret
= request_irq(adev
->irq
, ppc440spe_adma_eot_handler
,
4292 0, dev_driver_string(adev
->dev
), chan
);
4294 dev_err(adev
->dev
, "can't request irq %d\n",
4296 *initcode
= PPC_ADMA_INIT_IRQ1
;
4301 /* only DMA engines have a separate error IRQ
4302 * so it's Ok if err_irq < 0 in XOR engine case.
4304 if (adev
->err_irq
> 0) {
4305 /* both DMA engines share common error IRQ */
4306 ret
= request_irq(adev
->err_irq
,
4307 ppc440spe_adma_err_handler
,
4309 dev_driver_string(adev
->dev
),
4312 dev_err(adev
->dev
, "can't request irq %d\n",
4314 *initcode
= PPC_ADMA_INIT_IRQ2
;
4320 if (adev
->id
== PPC440SPE_XOR_ID
) {
4321 /* enable XOR engine interrupts */
4322 iowrite32be(XOR_IE_CBCIE_BIT
| XOR_IE_ICBIE_BIT
|
4323 XOR_IE_ICIE_BIT
| XOR_IE_RPTIE_BIT
,
4324 &adev
->xor_reg
->ier
);
4328 np
= of_find_compatible_node(NULL
, NULL
, "ibm,i2o-440spe");
4330 pr_err("%s: can't find I2O device tree node\n",
4335 adev
->i2o_reg
= of_iomap(np
, 0);
4336 if (!adev
->i2o_reg
) {
4337 pr_err("%s: failed to map I2O registers\n", __func__
);
4343 /* Unmask 'CS FIFO Attention' interrupts and
4344 * enable generating interrupts on errors
4346 enable
= (adev
->id
== PPC440SPE_DMA0_ID
) ?
4347 ~(I2O_IOPIM_P0SNE
| I2O_IOPIM_P0EM
) :
4348 ~(I2O_IOPIM_P1SNE
| I2O_IOPIM_P1EM
);
4349 mask
= ioread32(&adev
->i2o_reg
->iopim
) & enable
;
4350 iowrite32(mask
, &adev
->i2o_reg
->iopim
);
4355 free_irq(adev
->irq
, chan
);
4357 irq_dispose_mapping(adev
->irq
);
4359 if (adev
->err_irq
> 0) {
4360 if (atomic_dec_and_test(&ppc440spe_adma_err_irq_ref
))
4361 irq_dispose_mapping(adev
->err_irq
);
4366 static void ppc440spe_adma_release_irqs(struct ppc440spe_adma_device
*adev
,
4367 struct ppc440spe_adma_chan
*chan
)
4371 if (adev
->id
== PPC440SPE_XOR_ID
) {
4372 /* disable XOR engine interrupts */
4373 mask
= ioread32be(&adev
->xor_reg
->ier
);
4374 mask
&= ~(XOR_IE_CBCIE_BIT
| XOR_IE_ICBIE_BIT
|
4375 XOR_IE_ICIE_BIT
| XOR_IE_RPTIE_BIT
);
4376 iowrite32be(mask
, &adev
->xor_reg
->ier
);
4378 /* disable DMAx engine interrupts */
4379 disable
= (adev
->id
== PPC440SPE_DMA0_ID
) ?
4380 (I2O_IOPIM_P0SNE
| I2O_IOPIM_P0EM
) :
4381 (I2O_IOPIM_P1SNE
| I2O_IOPIM_P1EM
);
4382 mask
= ioread32(&adev
->i2o_reg
->iopim
) | disable
;
4383 iowrite32(mask
, &adev
->i2o_reg
->iopim
);
4385 free_irq(adev
->irq
, chan
);
4386 irq_dispose_mapping(adev
->irq
);
4387 if (adev
->err_irq
> 0) {
4388 free_irq(adev
->err_irq
, chan
);
4389 if (atomic_dec_and_test(&ppc440spe_adma_err_irq_ref
)) {
4390 irq_dispose_mapping(adev
->err_irq
);
4391 iounmap(adev
->i2o_reg
);
4397 * ppc440spe_adma_probe - probe the asynch device
4399 static int __devinit
ppc440spe_adma_probe(struct of_device
*ofdev
,
4400 const struct of_device_id
*match
)
4402 struct device_node
*np
= ofdev
->node
;
4403 struct resource res
;
4404 struct ppc440spe_adma_device
*adev
;
4405 struct ppc440spe_adma_chan
*chan
;
4406 struct ppc_dma_chan_ref
*ref
, *_ref
;
4407 int ret
= 0, initcode
= PPC_ADMA_INIT_OK
;
4413 if (of_device_is_compatible(np
, "amcc,xor-accelerator")) {
4414 id
= PPC440SPE_XOR_ID
;
4415 /* As far as the XOR engine is concerned, it does not
4416 * use FIFOs but uses linked list. So there is no dependency
4417 * between pool size to allocate and the engine configuration.
4419 pool_size
= PAGE_SIZE
<< 1;
4421 /* it is DMA0 or DMA1 */
4422 idx
= of_get_property(np
, "cell-index", &len
);
4423 if (!idx
|| (len
!= sizeof(u32
))) {
4424 dev_err(&ofdev
->dev
, "Device node %s has missing "
4425 "or invalid cell-index property\n",
4430 /* DMA0,1 engines use FIFO to maintain CDBs, so we
4431 * should allocate the pool accordingly to size of this
4432 * FIFO. Thus, the pool size depends on the FIFO depth:
4433 * how much CDBs pointers the FIFO may contain then so
4434 * much CDBs we should provide in the pool.
4437 * CDBs number = (DMA0_FIFO_SIZE >> 3);
4438 * Pool size = CDBs number * CDB size =
4439 * = (DMA0_FIFO_SIZE >> 3) << 5 = DMA0_FIFO_SIZE << 2.
4441 pool_size
= (id
== PPC440SPE_DMA0_ID
) ?
4442 DMA0_FIFO_SIZE
: DMA1_FIFO_SIZE
;
4446 if (of_address_to_resource(np
, 0, &res
)) {
4447 dev_err(&ofdev
->dev
, "failed to get memory resource\n");
4448 initcode
= PPC_ADMA_INIT_MEMRES
;
4453 if (!request_mem_region(res
.start
, resource_size(&res
),
4454 dev_driver_string(&ofdev
->dev
))) {
4455 dev_err(&ofdev
->dev
, "failed to request memory region "
4456 "(0x%016llx-0x%016llx)\n",
4457 (u64
)res
.start
, (u64
)res
.end
);
4458 initcode
= PPC_ADMA_INIT_MEMREG
;
4463 /* create a device */
4464 adev
= kzalloc(sizeof(*adev
), GFP_KERNEL
);
4466 dev_err(&ofdev
->dev
, "failed to allocate device\n");
4467 initcode
= PPC_ADMA_INIT_ALLOC
;
4469 goto err_adev_alloc
;
4473 adev
->pool_size
= pool_size
;
4474 /* allocate coherent memory for hardware descriptors */
4475 adev
->dma_desc_pool_virt
= dma_alloc_coherent(&ofdev
->dev
,
4476 adev
->pool_size
, &adev
->dma_desc_pool
,
4478 if (adev
->dma_desc_pool_virt
== NULL
) {
4479 dev_err(&ofdev
->dev
, "failed to allocate %d bytes of coherent "
4480 "memory for hardware descriptors\n",
4482 initcode
= PPC_ADMA_INIT_COHERENT
;
4486 dev_dbg(&ofdev
->dev
, "allocted descriptor pool virt 0x%p phys 0x%llx\n",
4487 adev
->dma_desc_pool_virt
, (u64
)adev
->dma_desc_pool
);
4489 regs
= ioremap(res
.start
, resource_size(&res
));
4491 dev_err(&ofdev
->dev
, "failed to ioremap regs!\n");
4492 goto err_regs_alloc
;
4495 if (adev
->id
== PPC440SPE_XOR_ID
) {
4496 adev
->xor_reg
= regs
;
4498 iowrite32be(XOR_CRSR_XASR_BIT
, &adev
->xor_reg
->crsr
);
4499 iowrite32be(XOR_CRSR_64BA_BIT
, &adev
->xor_reg
->crrr
);
4501 size_t fifo_size
= (adev
->id
== PPC440SPE_DMA0_ID
) ?
4502 DMA0_FIFO_SIZE
: DMA1_FIFO_SIZE
;
4503 adev
->dma_reg
= regs
;
4504 /* DMAx_FIFO_SIZE is defined in bytes,
4505 * <fsiz> - is defined in number of CDB pointers (8byte).
4506 * DMA FIFO Length = CSlength + CPlength, where
4507 * CSlength = CPlength = (fsiz + 1) * 8.
4509 iowrite32(DMA_FIFO_ENABLE
| ((fifo_size
>> 3) - 2),
4510 &adev
->dma_reg
->fsiz
);
4511 /* Configure DMA engine */
4512 iowrite32(DMA_CFG_DXEPR_HP
| DMA_CFG_DFMPP_HP
| DMA_CFG_FALGN
,
4513 &adev
->dma_reg
->cfg
);
4515 iowrite32(~0, &adev
->dma_reg
->dsts
);
4518 adev
->dev
= &ofdev
->dev
;
4519 adev
->common
.dev
= &ofdev
->dev
;
4520 INIT_LIST_HEAD(&adev
->common
.channels
);
4521 dev_set_drvdata(&ofdev
->dev
, adev
);
4523 /* create a channel */
4524 chan
= kzalloc(sizeof(*chan
), GFP_KERNEL
);
4526 dev_err(&ofdev
->dev
, "can't allocate channel structure\n");
4527 initcode
= PPC_ADMA_INIT_CHANNEL
;
4529 goto err_chan_alloc
;
4532 spin_lock_init(&chan
->lock
);
4533 INIT_LIST_HEAD(&chan
->chain
);
4534 INIT_LIST_HEAD(&chan
->all_slots
);
4535 chan
->device
= adev
;
4536 chan
->common
.device
= &adev
->common
;
4537 list_add_tail(&chan
->common
.device_node
, &adev
->common
.channels
);
4538 tasklet_init(&chan
->irq_tasklet
, ppc440spe_adma_tasklet
,
4539 (unsigned long)chan
);
4541 /* allocate and map helper pages for async validation or
4542 * async_mult/async_sum_product operations on DMA0/1.
4544 if (adev
->id
!= PPC440SPE_XOR_ID
) {
4545 chan
->pdest_page
= alloc_page(GFP_KERNEL
);
4546 chan
->qdest_page
= alloc_page(GFP_KERNEL
);
4547 if (!chan
->pdest_page
||
4548 !chan
->qdest_page
) {
4549 if (chan
->pdest_page
)
4550 __free_page(chan
->pdest_page
);
4551 if (chan
->qdest_page
)
4552 __free_page(chan
->qdest_page
);
4554 goto err_page_alloc
;
4556 chan
->pdest
= dma_map_page(&ofdev
->dev
, chan
->pdest_page
, 0,
4557 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4558 chan
->qdest
= dma_map_page(&ofdev
->dev
, chan
->qdest_page
, 0,
4559 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4562 ref
= kmalloc(sizeof(*ref
), GFP_KERNEL
);
4564 ref
->chan
= &chan
->common
;
4565 INIT_LIST_HEAD(&ref
->node
);
4566 list_add_tail(&ref
->node
, &ppc440spe_adma_chan_list
);
4568 dev_err(&ofdev
->dev
, "failed to allocate channel reference!\n");
4573 ret
= ppc440spe_adma_setup_irqs(adev
, chan
, &initcode
);
4577 ppc440spe_adma_init_capabilities(adev
);
4579 ret
= dma_async_device_register(&adev
->common
);
4581 initcode
= PPC_ADMA_INIT_REGISTER
;
4582 dev_err(&ofdev
->dev
, "failed to register dma device\n");
4589 ppc440spe_adma_release_irqs(adev
, chan
);
4591 list_for_each_entry_safe(ref
, _ref
, &ppc440spe_adma_chan_list
, node
) {
4592 if (chan
== to_ppc440spe_adma_chan(ref
->chan
)) {
4593 list_del(&ref
->node
);
4598 if (adev
->id
!= PPC440SPE_XOR_ID
) {
4599 dma_unmap_page(&ofdev
->dev
, chan
->pdest
,
4600 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4601 dma_unmap_page(&ofdev
->dev
, chan
->qdest
,
4602 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4603 __free_page(chan
->pdest_page
);
4604 __free_page(chan
->qdest_page
);
4609 if (adev
->id
== PPC440SPE_XOR_ID
)
4610 iounmap(adev
->xor_reg
);
4612 iounmap(adev
->dma_reg
);
4614 dma_free_coherent(adev
->dev
, adev
->pool_size
,
4615 adev
->dma_desc_pool_virt
,
4616 adev
->dma_desc_pool
);
4620 release_mem_region(res
.start
, resource_size(&res
));
4622 if (id
< PPC440SPE_ADMA_ENGINES_NUM
)
4623 ppc440spe_adma_devices
[id
] = initcode
;
4629 * ppc440spe_adma_remove - remove the asynch device
4631 static int __devexit
ppc440spe_adma_remove(struct of_device
*ofdev
)
4633 struct ppc440spe_adma_device
*adev
= dev_get_drvdata(&ofdev
->dev
);
4634 struct device_node
*np
= ofdev
->node
;
4635 struct resource res
;
4636 struct dma_chan
*chan
, *_chan
;
4637 struct ppc_dma_chan_ref
*ref
, *_ref
;
4638 struct ppc440spe_adma_chan
*ppc440spe_chan
;
4640 dev_set_drvdata(&ofdev
->dev
, NULL
);
4641 if (adev
->id
< PPC440SPE_ADMA_ENGINES_NUM
)
4642 ppc440spe_adma_devices
[adev
->id
] = -1;
4644 dma_async_device_unregister(&adev
->common
);
4646 list_for_each_entry_safe(chan
, _chan
, &adev
->common
.channels
,
4648 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
4649 ppc440spe_adma_release_irqs(adev
, ppc440spe_chan
);
4650 tasklet_kill(&ppc440spe_chan
->irq_tasklet
);
4651 if (adev
->id
!= PPC440SPE_XOR_ID
) {
4652 dma_unmap_page(&ofdev
->dev
, ppc440spe_chan
->pdest
,
4653 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4654 dma_unmap_page(&ofdev
->dev
, ppc440spe_chan
->qdest
,
4655 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4656 __free_page(ppc440spe_chan
->pdest_page
);
4657 __free_page(ppc440spe_chan
->qdest_page
);
4659 list_for_each_entry_safe(ref
, _ref
, &ppc440spe_adma_chan_list
,
4661 if (ppc440spe_chan
==
4662 to_ppc440spe_adma_chan(ref
->chan
)) {
4663 list_del(&ref
->node
);
4667 list_del(&chan
->device_node
);
4668 kfree(ppc440spe_chan
);
4671 dma_free_coherent(adev
->dev
, adev
->pool_size
,
4672 adev
->dma_desc_pool_virt
, adev
->dma_desc_pool
);
4673 if (adev
->id
== PPC440SPE_XOR_ID
)
4674 iounmap(adev
->xor_reg
);
4676 iounmap(adev
->dma_reg
);
4677 of_address_to_resource(np
, 0, &res
);
4678 release_mem_region(res
.start
, resource_size(&res
));
4684 * /sys driver interface to enable h/w RAID-6 capabilities
4685 * Files created in e.g. /sys/devices/plb.0/400100100.dma0/driver/
4686 * directory are "devices", "enable" and "poly".
4687 * "devices" shows available engines.
4688 * "enable" is used to enable RAID-6 capabilities or to check
4689 * whether these has been activated.
4690 * "poly" allows setting/checking used polynomial (for PPC440SPe only).
4693 static ssize_t
show_ppc440spe_devices(struct device_driver
*dev
, char *buf
)
4698 for (i
= 0; i
< PPC440SPE_ADMA_ENGINES_NUM
; i
++) {
4699 if (ppc440spe_adma_devices
[i
] == -1)
4701 size
+= snprintf(buf
+ size
, PAGE_SIZE
- size
,
4702 "PPC440SP(E)-ADMA.%d: %s\n", i
,
4703 ppc_adma_errors
[ppc440spe_adma_devices
[i
]]);
4708 static ssize_t
show_ppc440spe_r6enable(struct device_driver
*dev
, char *buf
)
4710 return snprintf(buf
, PAGE_SIZE
,
4711 "PPC440SP(e) RAID-6 capabilities are %sABLED.\n",
4712 ppc440spe_r6_enabled
? "EN" : "DIS");
4715 static ssize_t
store_ppc440spe_r6enable(struct device_driver
*dev
,
4716 const char *buf
, size_t count
)
4720 if (!count
|| count
> 11)
4723 if (!ppc440spe_r6_tchan
)
4727 sscanf(buf
, "%lx", &val
);
4728 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_XORBA
, val
);
4731 /* Verify whether it really works now */
4732 if (ppc440spe_test_raid6(ppc440spe_r6_tchan
) == 0) {
4733 pr_info("PPC440SP(e) RAID-6 has been activated "
4735 ppc440spe_r6_enabled
= 1;
4737 pr_info("PPC440SP(e) RAID-6 hasn't been activated!"
4739 ppc440spe_r6_enabled
= 0;
4744 static ssize_t
show_ppc440spe_r6poly(struct device_driver
*dev
, char *buf
)
4750 /* 440SP has fixed polynomial */
4753 reg
= dcr_read(ppc440spe_mq_dcr_host
, DCRN_MQ0_CFBHL
);
4754 reg
>>= MQ0_CFBHL_POLY
;
4758 size
= snprintf(buf
, PAGE_SIZE
, "PPC440SP(e) RAID-6 driver "
4759 "uses 0x1%02x polynomial.\n", reg
);
4763 static ssize_t
store_ppc440spe_r6poly(struct device_driver
*dev
,
4764 const char *buf
, size_t count
)
4766 unsigned long reg
, val
;
4769 /* 440SP uses default 0x14D polynomial only */
4773 if (!count
|| count
> 6)
4776 /* e.g., 0x14D or 0x11D */
4777 sscanf(buf
, "%lx", &val
);
4783 reg
= dcr_read(ppc440spe_mq_dcr_host
, DCRN_MQ0_CFBHL
);
4784 reg
&= ~(0xFF << MQ0_CFBHL_POLY
);
4785 reg
|= val
<< MQ0_CFBHL_POLY
;
4786 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_CFBHL
, reg
);
4791 static DRIVER_ATTR(devices
, S_IRUGO
, show_ppc440spe_devices
, NULL
);
4792 static DRIVER_ATTR(enable
, S_IRUGO
| S_IWUSR
, show_ppc440spe_r6enable
,
4793 store_ppc440spe_r6enable
);
4794 static DRIVER_ATTR(poly
, S_IRUGO
| S_IWUSR
, show_ppc440spe_r6poly
,
4795 store_ppc440spe_r6poly
);
4798 * Common initialisation for RAID engines; allocate memory for
4799 * DMAx FIFOs, perform configuration common for all DMA engines.
4800 * Further DMA engine specific configuration is done at probe time.
4802 static int ppc440spe_configure_raid_devices(void)
4804 struct device_node
*np
;
4805 struct resource i2o_res
;
4806 struct i2o_regs __iomem
*i2o_reg
;
4807 dcr_host_t i2o_dcr_host
;
4808 unsigned int dcr_base
, dcr_len
;
4811 np
= of_find_compatible_node(NULL
, NULL
, "ibm,i2o-440spe");
4813 pr_err("%s: can't find I2O device tree node\n",
4818 if (of_address_to_resource(np
, 0, &i2o_res
)) {
4823 i2o_reg
= of_iomap(np
, 0);
4825 pr_err("%s: failed to map I2O registers\n", __func__
);
4830 /* Get I2O DCRs base */
4831 dcr_base
= dcr_resource_start(np
, 0);
4832 dcr_len
= dcr_resource_len(np
, 0);
4833 if (!dcr_base
&& !dcr_len
) {
4834 pr_err("%s: can't get DCR registers base/len!\n",
4841 i2o_dcr_host
= dcr_map(np
, dcr_base
, dcr_len
);
4842 if (!DCR_MAP_OK(i2o_dcr_host
)) {
4843 pr_err("%s: failed to map DCRs!\n", np
->full_name
);
4850 /* Provide memory regions for DMA's FIFOs: I2O, DMA0 and DMA1 share
4851 * the base address of FIFO memory space.
4852 * Actually we need twice more physical memory than programmed in the
4853 * <fsiz> register (because there are two FIFOs for each DMA: CP and CS)
4855 ppc440spe_dma_fifo_buf
= kmalloc((DMA0_FIFO_SIZE
+ DMA1_FIFO_SIZE
) << 1,
4857 if (!ppc440spe_dma_fifo_buf
) {
4858 pr_err("%s: DMA FIFO buffer allocation failed.\n", __func__
);
4860 dcr_unmap(i2o_dcr_host
, dcr_len
);
4868 mtdcri(SDR0
, DCRN_SDR0_SRST
, DCRN_SDR0_SRST_I2ODMA
);
4869 mtdcri(SDR0
, DCRN_SDR0_SRST
, 0);
4871 /* Setup the base address of mmaped registers */
4872 dcr_write(i2o_dcr_host
, DCRN_I2O0_IBAH
, (u32
)(i2o_res
.start
>> 32));
4873 dcr_write(i2o_dcr_host
, DCRN_I2O0_IBAL
, (u32
)(i2o_res
.start
) |
4875 dcr_unmap(i2o_dcr_host
, dcr_len
);
4877 /* Setup FIFO memory space base address */
4878 iowrite32(0, &i2o_reg
->ifbah
);
4879 iowrite32(((u32
)__pa(ppc440spe_dma_fifo_buf
)), &i2o_reg
->ifbal
);
4881 /* set zero FIFO size for I2O, so the whole
4882 * ppc440spe_dma_fifo_buf is used by DMAs.
4883 * DMAx_FIFOs will be configured while probe.
4885 iowrite32(0, &i2o_reg
->ifsiz
);
4888 /* To prepare WXOR/RXOR functionality we need access to
4889 * Memory Queue Module DCRs (finally it will be enabled
4890 * via /sys interface of the ppc440spe ADMA driver).
4892 np
= of_find_compatible_node(NULL
, NULL
, "ibm,mq-440spe");
4894 pr_err("%s: can't find MQ device tree node\n",
4900 /* Get MQ DCRs base */
4901 dcr_base
= dcr_resource_start(np
, 0);
4902 dcr_len
= dcr_resource_len(np
, 0);
4903 if (!dcr_base
&& !dcr_len
) {
4904 pr_err("%s: can't get DCR registers base/len!\n",
4910 ppc440spe_mq_dcr_host
= dcr_map(np
, dcr_base
, dcr_len
);
4911 if (!DCR_MAP_OK(ppc440spe_mq_dcr_host
)) {
4912 pr_err("%s: failed to map DCRs!\n", np
->full_name
);
4917 ppc440spe_mq_dcr_len
= dcr_len
;
4920 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_BAUH
, DMA_CUED_XOR_HB
);
4923 * - LL transaction passing limit to 1;
4924 * - Memory controller cycle limit to 1;
4925 * - Galois Polynomial to 0x14d (default)
4927 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_CFBHL
,
4928 (1 << MQ0_CFBHL_TPLM
) | (1 << MQ0_CFBHL_HBCL
) |
4929 (PPC440SPE_DEFAULT_POLY
<< MQ0_CFBHL_POLY
));
4931 atomic_set(&ppc440spe_adma_err_irq_ref
, 0);
4932 for (i
= 0; i
< PPC440SPE_ADMA_ENGINES_NUM
; i
++)
4933 ppc440spe_adma_devices
[i
] = -1;
4940 kfree(ppc440spe_dma_fifo_buf
);
4944 static const struct of_device_id ppc440spe_adma_of_match
[] __devinitconst
= {
4945 { .compatible
= "ibm,dma-440spe", },
4946 { .compatible
= "amcc,xor-accelerator", },
4949 MODULE_DEVICE_TABLE(of
, ppc440spe_adma_of_match
);
4951 static struct of_platform_driver ppc440spe_adma_driver
= {
4952 .match_table
= ppc440spe_adma_of_match
,
4953 .probe
= ppc440spe_adma_probe
,
4954 .remove
= __devexit_p(ppc440spe_adma_remove
),
4956 .name
= "PPC440SP(E)-ADMA",
4957 .owner
= THIS_MODULE
,
4961 static __init
int ppc440spe_adma_init(void)
4965 ret
= ppc440spe_configure_raid_devices();
4969 ret
= of_register_platform_driver(&ppc440spe_adma_driver
);
4971 pr_err("%s: failed to register platform driver\n",
4976 /* Initialization status */
4977 ret
= driver_create_file(&ppc440spe_adma_driver
.driver
,
4978 &driver_attr_devices
);
4982 /* RAID-6 h/w enable entry */
4983 ret
= driver_create_file(&ppc440spe_adma_driver
.driver
,
4984 &driver_attr_enable
);
4988 /* GF polynomial to use */
4989 ret
= driver_create_file(&ppc440spe_adma_driver
.driver
,
4994 driver_remove_file(&ppc440spe_adma_driver
.driver
,
4995 &driver_attr_enable
);
4997 driver_remove_file(&ppc440spe_adma_driver
.driver
,
4998 &driver_attr_devices
);
5000 /* User will not be able to enable h/w RAID-6 */
5001 pr_err("%s: failed to create RAID-6 driver interface\n",
5003 of_unregister_platform_driver(&ppc440spe_adma_driver
);
5005 dcr_unmap(ppc440spe_mq_dcr_host
, ppc440spe_mq_dcr_len
);
5006 kfree(ppc440spe_dma_fifo_buf
);
5010 static void __exit
ppc440spe_adma_exit(void)
5012 driver_remove_file(&ppc440spe_adma_driver
.driver
,
5014 driver_remove_file(&ppc440spe_adma_driver
.driver
,
5015 &driver_attr_enable
);
5016 driver_remove_file(&ppc440spe_adma_driver
.driver
,
5017 &driver_attr_devices
);
5018 of_unregister_platform_driver(&ppc440spe_adma_driver
);
5019 dcr_unmap(ppc440spe_mq_dcr_host
, ppc440spe_mq_dcr_len
);
5020 kfree(ppc440spe_dma_fifo_buf
);
5023 arch_initcall(ppc440spe_adma_init
);
5024 module_exit(ppc440spe_adma_exit
);
5026 MODULE_AUTHOR("Yuri Tikhonov <yur@emcraft.com>");
5027 MODULE_DESCRIPTION("PPC440SPE ADMA Engine Driver");
5028 MODULE_LICENSE("GPL");