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_tx_status - poll the status of an ADMA transaction
3939 * @chan: ADMA channel handle
3940 * @cookie: ADMA transaction identifier
3941 * @txstate: a holder for the current state of the channel
3943 static enum dma_status
ppc440spe_adma_tx_status(struct dma_chan
*chan
,
3944 dma_cookie_t cookie
, struct dma_tx_state
*txstate
)
3946 struct ppc440spe_adma_chan
*ppc440spe_chan
;
3947 dma_cookie_t last_used
;
3948 dma_cookie_t last_complete
;
3949 enum dma_status ret
;
3951 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
3952 last_used
= chan
->cookie
;
3953 last_complete
= ppc440spe_chan
->completed_cookie
;
3955 dma_set_tx_state(txstate
, last_complete
, last_used
, 0);
3957 ret
= dma_async_is_complete(cookie
, last_complete
, last_used
);
3958 if (ret
== DMA_SUCCESS
)
3961 ppc440spe_adma_slot_cleanup(ppc440spe_chan
);
3963 last_used
= chan
->cookie
;
3964 last_complete
= ppc440spe_chan
->completed_cookie
;
3966 dma_set_tx_state(txstate
, last_complete
, last_used
, 0);
3968 return dma_async_is_complete(cookie
, last_complete
, last_used
);
3972 * ppc440spe_adma_eot_handler - end of transfer interrupt handler
3974 static irqreturn_t
ppc440spe_adma_eot_handler(int irq
, void *data
)
3976 struct ppc440spe_adma_chan
*chan
= data
;
3978 dev_dbg(chan
->device
->common
.dev
,
3979 "ppc440spe adma%d: %s\n", chan
->device
->id
, __func__
);
3981 tasklet_schedule(&chan
->irq_tasklet
);
3982 ppc440spe_adma_device_clear_eot_status(chan
);
3988 * ppc440spe_adma_err_handler - DMA error interrupt handler;
3989 * do the same things as a eot handler
3991 static irqreturn_t
ppc440spe_adma_err_handler(int irq
, void *data
)
3993 struct ppc440spe_adma_chan
*chan
= data
;
3995 dev_dbg(chan
->device
->common
.dev
,
3996 "ppc440spe adma%d: %s\n", chan
->device
->id
, __func__
);
3998 tasklet_schedule(&chan
->irq_tasklet
);
3999 ppc440spe_adma_device_clear_eot_status(chan
);
4005 * ppc440spe_test_callback - called when test operation has been done
4007 static void ppc440spe_test_callback(void *unused
)
4009 complete(&ppc440spe_r6_test_comp
);
4013 * ppc440spe_adma_issue_pending - flush all pending descriptors to h/w
4015 static void ppc440spe_adma_issue_pending(struct dma_chan
*chan
)
4017 struct ppc440spe_adma_chan
*ppc440spe_chan
;
4019 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
4020 dev_dbg(ppc440spe_chan
->device
->common
.dev
,
4021 "ppc440spe adma%d: %s %d \n", ppc440spe_chan
->device
->id
,
4022 __func__
, ppc440spe_chan
->pending
);
4024 if (ppc440spe_chan
->pending
) {
4025 ppc440spe_chan
->pending
= 0;
4026 ppc440spe_chan_append(ppc440spe_chan
);
4031 * ppc440spe_chan_start_null_xor - initiate the first XOR operation (DMA engines
4032 * use FIFOs (as opposite to chains used in XOR) so this is a XOR
4033 * specific operation)
4035 static void ppc440spe_chan_start_null_xor(struct ppc440spe_adma_chan
*chan
)
4037 struct ppc440spe_adma_desc_slot
*sw_desc
, *group_start
;
4038 dma_cookie_t cookie
;
4039 int slot_cnt
, slots_per_op
;
4041 dev_dbg(chan
->device
->common
.dev
,
4042 "ppc440spe adma%d: %s\n", chan
->device
->id
, __func__
);
4044 spin_lock_bh(&chan
->lock
);
4045 slot_cnt
= ppc440spe_chan_xor_slot_count(0, 2, &slots_per_op
);
4046 sw_desc
= ppc440spe_adma_alloc_slots(chan
, slot_cnt
, slots_per_op
);
4048 group_start
= sw_desc
->group_head
;
4049 list_splice_init(&sw_desc
->group_list
, &chan
->chain
);
4050 async_tx_ack(&sw_desc
->async_tx
);
4051 ppc440spe_desc_init_null_xor(group_start
);
4053 cookie
= chan
->common
.cookie
;
4058 /* initialize the completed cookie to be less than
4059 * the most recently used cookie
4061 chan
->completed_cookie
= cookie
- 1;
4062 chan
->common
.cookie
= sw_desc
->async_tx
.cookie
= cookie
;
4064 /* channel should not be busy */
4065 BUG_ON(ppc440spe_chan_is_busy(chan
));
4067 /* set the descriptor address */
4068 ppc440spe_chan_set_first_xor_descriptor(chan
, sw_desc
);
4070 /* run the descriptor */
4071 ppc440spe_chan_run(chan
);
4073 printk(KERN_ERR
"ppc440spe adma%d"
4074 " failed to allocate null descriptor\n",
4076 spin_unlock_bh(&chan
->lock
);
4080 * ppc440spe_test_raid6 - test are RAID-6 capabilities enabled successfully.
4081 * For this we just perform one WXOR operation with the same source
4082 * and destination addresses, the GF-multiplier is 1; so if RAID-6
4083 * capabilities are enabled then we'll get src/dst filled with zero.
4085 static int ppc440spe_test_raid6(struct ppc440spe_adma_chan
*chan
)
4087 struct ppc440spe_adma_desc_slot
*sw_desc
, *iter
;
4090 dma_addr_t dma_addr
, addrs
[2];
4091 unsigned long op
= 0;
4094 set_bit(PPC440SPE_DESC_WXOR
, &op
);
4096 pg
= alloc_page(GFP_KERNEL
);
4100 spin_lock_bh(&chan
->lock
);
4101 sw_desc
= ppc440spe_adma_alloc_slots(chan
, 1, 1);
4103 /* 1 src, 1 dsr, int_ena, WXOR */
4104 ppc440spe_desc_init_dma01pq(sw_desc
, 1, 1, 1, op
);
4105 list_for_each_entry(iter
, &sw_desc
->group_list
, chain_node
) {
4106 ppc440spe_desc_set_byte_count(iter
, chan
, PAGE_SIZE
);
4107 iter
->unmap_len
= PAGE_SIZE
;
4111 spin_unlock_bh(&chan
->lock
);
4114 spin_unlock_bh(&chan
->lock
);
4116 /* Fill the test page with ones */
4117 memset(page_address(pg
), 0xFF, PAGE_SIZE
);
4118 dma_addr
= dma_map_page(chan
->device
->dev
, pg
, 0,
4119 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4121 /* Setup addresses */
4122 ppc440spe_adma_pq_set_src(sw_desc
, dma_addr
, 0);
4123 ppc440spe_adma_pq_set_src_mult(sw_desc
, 1, 0, 0);
4124 addrs
[0] = dma_addr
;
4126 ppc440spe_adma_pq_set_dest(sw_desc
, addrs
, DMA_PREP_PQ_DISABLE_Q
);
4128 async_tx_ack(&sw_desc
->async_tx
);
4129 sw_desc
->async_tx
.callback
= ppc440spe_test_callback
;
4130 sw_desc
->async_tx
.callback_param
= NULL
;
4132 init_completion(&ppc440spe_r6_test_comp
);
4134 ppc440spe_adma_tx_submit(&sw_desc
->async_tx
);
4135 ppc440spe_adma_issue_pending(&chan
->common
);
4137 wait_for_completion(&ppc440spe_r6_test_comp
);
4139 /* Now check if the test page is zeroed */
4140 a
= page_address(pg
);
4141 if ((*(u32
*)a
) == 0 && memcmp(a
, a
+4, PAGE_SIZE
-4) == 0) {
4142 /* page is zero - RAID-6 enabled */
4145 /* RAID-6 was not enabled */
4153 static void ppc440spe_adma_init_capabilities(struct ppc440spe_adma_device
*adev
)
4156 case PPC440SPE_DMA0_ID
:
4157 case PPC440SPE_DMA1_ID
:
4158 dma_cap_set(DMA_MEMCPY
, adev
->common
.cap_mask
);
4159 dma_cap_set(DMA_INTERRUPT
, adev
->common
.cap_mask
);
4160 dma_cap_set(DMA_MEMSET
, adev
->common
.cap_mask
);
4161 dma_cap_set(DMA_PQ
, adev
->common
.cap_mask
);
4162 dma_cap_set(DMA_PQ_VAL
, adev
->common
.cap_mask
);
4163 dma_cap_set(DMA_XOR_VAL
, adev
->common
.cap_mask
);
4165 case PPC440SPE_XOR_ID
:
4166 dma_cap_set(DMA_XOR
, adev
->common
.cap_mask
);
4167 dma_cap_set(DMA_PQ
, adev
->common
.cap_mask
);
4168 dma_cap_set(DMA_INTERRUPT
, adev
->common
.cap_mask
);
4169 adev
->common
.cap_mask
= adev
->common
.cap_mask
;
4173 /* Set base routines */
4174 adev
->common
.device_alloc_chan_resources
=
4175 ppc440spe_adma_alloc_chan_resources
;
4176 adev
->common
.device_free_chan_resources
=
4177 ppc440spe_adma_free_chan_resources
;
4178 adev
->common
.device_tx_status
= ppc440spe_adma_tx_status
;
4179 adev
->common
.device_issue_pending
= ppc440spe_adma_issue_pending
;
4181 /* Set prep routines based on capability */
4182 if (dma_has_cap(DMA_MEMCPY
, adev
->common
.cap_mask
)) {
4183 adev
->common
.device_prep_dma_memcpy
=
4184 ppc440spe_adma_prep_dma_memcpy
;
4186 if (dma_has_cap(DMA_MEMSET
, adev
->common
.cap_mask
)) {
4187 adev
->common
.device_prep_dma_memset
=
4188 ppc440spe_adma_prep_dma_memset
;
4190 if (dma_has_cap(DMA_XOR
, adev
->common
.cap_mask
)) {
4191 adev
->common
.max_xor
= XOR_MAX_OPS
;
4192 adev
->common
.device_prep_dma_xor
=
4193 ppc440spe_adma_prep_dma_xor
;
4195 if (dma_has_cap(DMA_PQ
, adev
->common
.cap_mask
)) {
4197 case PPC440SPE_DMA0_ID
:
4198 dma_set_maxpq(&adev
->common
,
4199 DMA0_FIFO_SIZE
/ sizeof(struct dma_cdb
), 0);
4201 case PPC440SPE_DMA1_ID
:
4202 dma_set_maxpq(&adev
->common
,
4203 DMA1_FIFO_SIZE
/ sizeof(struct dma_cdb
), 0);
4205 case PPC440SPE_XOR_ID
:
4206 adev
->common
.max_pq
= XOR_MAX_OPS
* 3;
4209 adev
->common
.device_prep_dma_pq
=
4210 ppc440spe_adma_prep_dma_pq
;
4212 if (dma_has_cap(DMA_PQ_VAL
, adev
->common
.cap_mask
)) {
4214 case PPC440SPE_DMA0_ID
:
4215 adev
->common
.max_pq
= DMA0_FIFO_SIZE
/
4216 sizeof(struct dma_cdb
);
4218 case PPC440SPE_DMA1_ID
:
4219 adev
->common
.max_pq
= DMA1_FIFO_SIZE
/
4220 sizeof(struct dma_cdb
);
4223 adev
->common
.device_prep_dma_pq_val
=
4224 ppc440spe_adma_prep_dma_pqzero_sum
;
4226 if (dma_has_cap(DMA_XOR_VAL
, adev
->common
.cap_mask
)) {
4228 case PPC440SPE_DMA0_ID
:
4229 adev
->common
.max_xor
= DMA0_FIFO_SIZE
/
4230 sizeof(struct dma_cdb
);
4232 case PPC440SPE_DMA1_ID
:
4233 adev
->common
.max_xor
= DMA1_FIFO_SIZE
/
4234 sizeof(struct dma_cdb
);
4237 adev
->common
.device_prep_dma_xor_val
=
4238 ppc440spe_adma_prep_dma_xor_zero_sum
;
4240 if (dma_has_cap(DMA_INTERRUPT
, adev
->common
.cap_mask
)) {
4241 adev
->common
.device_prep_dma_interrupt
=
4242 ppc440spe_adma_prep_dma_interrupt
;
4244 pr_info("%s: AMCC(R) PPC440SP(E) ADMA Engine: "
4245 "( %s%s%s%s%s%s%s)\n",
4246 dev_name(adev
->dev
),
4247 dma_has_cap(DMA_PQ
, adev
->common
.cap_mask
) ? "pq " : "",
4248 dma_has_cap(DMA_PQ_VAL
, adev
->common
.cap_mask
) ? "pq_val " : "",
4249 dma_has_cap(DMA_XOR
, adev
->common
.cap_mask
) ? "xor " : "",
4250 dma_has_cap(DMA_XOR_VAL
, adev
->common
.cap_mask
) ? "xor_val " : "",
4251 dma_has_cap(DMA_MEMCPY
, adev
->common
.cap_mask
) ? "memcpy " : "",
4252 dma_has_cap(DMA_MEMSET
, adev
->common
.cap_mask
) ? "memset " : "",
4253 dma_has_cap(DMA_INTERRUPT
, adev
->common
.cap_mask
) ? "intr " : "");
4256 static int ppc440spe_adma_setup_irqs(struct ppc440spe_adma_device
*adev
,
4257 struct ppc440spe_adma_chan
*chan
,
4260 struct platform_device
*ofdev
;
4261 struct device_node
*np
;
4264 ofdev
= container_of(adev
->dev
, struct platform_device
, dev
);
4265 np
= ofdev
->dev
.of_node
;
4266 if (adev
->id
!= PPC440SPE_XOR_ID
) {
4267 adev
->err_irq
= irq_of_parse_and_map(np
, 1);
4268 if (adev
->err_irq
== NO_IRQ
) {
4269 dev_warn(adev
->dev
, "no err irq resource?\n");
4270 *initcode
= PPC_ADMA_INIT_IRQ2
;
4271 adev
->err_irq
= -ENXIO
;
4273 atomic_inc(&ppc440spe_adma_err_irq_ref
);
4275 adev
->err_irq
= -ENXIO
;
4278 adev
->irq
= irq_of_parse_and_map(np
, 0);
4279 if (adev
->irq
== NO_IRQ
) {
4280 dev_err(adev
->dev
, "no irq resource\n");
4281 *initcode
= PPC_ADMA_INIT_IRQ1
;
4285 dev_dbg(adev
->dev
, "irq %d, err irq %d\n",
4286 adev
->irq
, adev
->err_irq
);
4288 ret
= request_irq(adev
->irq
, ppc440spe_adma_eot_handler
,
4289 0, dev_driver_string(adev
->dev
), chan
);
4291 dev_err(adev
->dev
, "can't request irq %d\n",
4293 *initcode
= PPC_ADMA_INIT_IRQ1
;
4298 /* only DMA engines have a separate error IRQ
4299 * so it's Ok if err_irq < 0 in XOR engine case.
4301 if (adev
->err_irq
> 0) {
4302 /* both DMA engines share common error IRQ */
4303 ret
= request_irq(adev
->err_irq
,
4304 ppc440spe_adma_err_handler
,
4306 dev_driver_string(adev
->dev
),
4309 dev_err(adev
->dev
, "can't request irq %d\n",
4311 *initcode
= PPC_ADMA_INIT_IRQ2
;
4317 if (adev
->id
== PPC440SPE_XOR_ID
) {
4318 /* enable XOR engine interrupts */
4319 iowrite32be(XOR_IE_CBCIE_BIT
| XOR_IE_ICBIE_BIT
|
4320 XOR_IE_ICIE_BIT
| XOR_IE_RPTIE_BIT
,
4321 &adev
->xor_reg
->ier
);
4325 np
= of_find_compatible_node(NULL
, NULL
, "ibm,i2o-440spe");
4327 pr_err("%s: can't find I2O device tree node\n",
4332 adev
->i2o_reg
= of_iomap(np
, 0);
4333 if (!adev
->i2o_reg
) {
4334 pr_err("%s: failed to map I2O registers\n", __func__
);
4340 /* Unmask 'CS FIFO Attention' interrupts and
4341 * enable generating interrupts on errors
4343 enable
= (adev
->id
== PPC440SPE_DMA0_ID
) ?
4344 ~(I2O_IOPIM_P0SNE
| I2O_IOPIM_P0EM
) :
4345 ~(I2O_IOPIM_P1SNE
| I2O_IOPIM_P1EM
);
4346 mask
= ioread32(&adev
->i2o_reg
->iopim
) & enable
;
4347 iowrite32(mask
, &adev
->i2o_reg
->iopim
);
4352 free_irq(adev
->irq
, chan
);
4354 irq_dispose_mapping(adev
->irq
);
4356 if (adev
->err_irq
> 0) {
4357 if (atomic_dec_and_test(&ppc440spe_adma_err_irq_ref
))
4358 irq_dispose_mapping(adev
->err_irq
);
4363 static void ppc440spe_adma_release_irqs(struct ppc440spe_adma_device
*adev
,
4364 struct ppc440spe_adma_chan
*chan
)
4368 if (adev
->id
== PPC440SPE_XOR_ID
) {
4369 /* disable XOR engine interrupts */
4370 mask
= ioread32be(&adev
->xor_reg
->ier
);
4371 mask
&= ~(XOR_IE_CBCIE_BIT
| XOR_IE_ICBIE_BIT
|
4372 XOR_IE_ICIE_BIT
| XOR_IE_RPTIE_BIT
);
4373 iowrite32be(mask
, &adev
->xor_reg
->ier
);
4375 /* disable DMAx engine interrupts */
4376 disable
= (adev
->id
== PPC440SPE_DMA0_ID
) ?
4377 (I2O_IOPIM_P0SNE
| I2O_IOPIM_P0EM
) :
4378 (I2O_IOPIM_P1SNE
| I2O_IOPIM_P1EM
);
4379 mask
= ioread32(&adev
->i2o_reg
->iopim
) | disable
;
4380 iowrite32(mask
, &adev
->i2o_reg
->iopim
);
4382 free_irq(adev
->irq
, chan
);
4383 irq_dispose_mapping(adev
->irq
);
4384 if (adev
->err_irq
> 0) {
4385 free_irq(adev
->err_irq
, chan
);
4386 if (atomic_dec_and_test(&ppc440spe_adma_err_irq_ref
)) {
4387 irq_dispose_mapping(adev
->err_irq
);
4388 iounmap(adev
->i2o_reg
);
4394 * ppc440spe_adma_probe - probe the asynch device
4396 static int __devinit
ppc440spe_adma_probe(struct platform_device
*ofdev
)
4398 struct device_node
*np
= ofdev
->dev
.of_node
;
4399 struct resource res
;
4400 struct ppc440spe_adma_device
*adev
;
4401 struct ppc440spe_adma_chan
*chan
;
4402 struct ppc_dma_chan_ref
*ref
, *_ref
;
4403 int ret
= 0, initcode
= PPC_ADMA_INIT_OK
;
4409 if (of_device_is_compatible(np
, "amcc,xor-accelerator")) {
4410 id
= PPC440SPE_XOR_ID
;
4411 /* As far as the XOR engine is concerned, it does not
4412 * use FIFOs but uses linked list. So there is no dependency
4413 * between pool size to allocate and the engine configuration.
4415 pool_size
= PAGE_SIZE
<< 1;
4417 /* it is DMA0 or DMA1 */
4418 idx
= of_get_property(np
, "cell-index", &len
);
4419 if (!idx
|| (len
!= sizeof(u32
))) {
4420 dev_err(&ofdev
->dev
, "Device node %s has missing "
4421 "or invalid cell-index property\n",
4426 /* DMA0,1 engines use FIFO to maintain CDBs, so we
4427 * should allocate the pool accordingly to size of this
4428 * FIFO. Thus, the pool size depends on the FIFO depth:
4429 * how much CDBs pointers the FIFO may contain then so
4430 * much CDBs we should provide in the pool.
4433 * CDBs number = (DMA0_FIFO_SIZE >> 3);
4434 * Pool size = CDBs number * CDB size =
4435 * = (DMA0_FIFO_SIZE >> 3) << 5 = DMA0_FIFO_SIZE << 2.
4437 pool_size
= (id
== PPC440SPE_DMA0_ID
) ?
4438 DMA0_FIFO_SIZE
: DMA1_FIFO_SIZE
;
4442 if (of_address_to_resource(np
, 0, &res
)) {
4443 dev_err(&ofdev
->dev
, "failed to get memory resource\n");
4444 initcode
= PPC_ADMA_INIT_MEMRES
;
4449 if (!request_mem_region(res
.start
, resource_size(&res
),
4450 dev_driver_string(&ofdev
->dev
))) {
4451 dev_err(&ofdev
->dev
, "failed to request memory region %pR\n",
4453 initcode
= PPC_ADMA_INIT_MEMREG
;
4458 /* create a device */
4459 adev
= kzalloc(sizeof(*adev
), GFP_KERNEL
);
4461 dev_err(&ofdev
->dev
, "failed to allocate device\n");
4462 initcode
= PPC_ADMA_INIT_ALLOC
;
4464 goto err_adev_alloc
;
4468 adev
->pool_size
= pool_size
;
4469 /* allocate coherent memory for hardware descriptors */
4470 adev
->dma_desc_pool_virt
= dma_alloc_coherent(&ofdev
->dev
,
4471 adev
->pool_size
, &adev
->dma_desc_pool
,
4473 if (adev
->dma_desc_pool_virt
== NULL
) {
4474 dev_err(&ofdev
->dev
, "failed to allocate %d bytes of coherent "
4475 "memory for hardware descriptors\n",
4477 initcode
= PPC_ADMA_INIT_COHERENT
;
4481 dev_dbg(&ofdev
->dev
, "allocted descriptor pool virt 0x%p phys 0x%llx\n",
4482 adev
->dma_desc_pool_virt
, (u64
)adev
->dma_desc_pool
);
4484 regs
= ioremap(res
.start
, resource_size(&res
));
4486 dev_err(&ofdev
->dev
, "failed to ioremap regs!\n");
4487 goto err_regs_alloc
;
4490 if (adev
->id
== PPC440SPE_XOR_ID
) {
4491 adev
->xor_reg
= regs
;
4493 iowrite32be(XOR_CRSR_XASR_BIT
, &adev
->xor_reg
->crsr
);
4494 iowrite32be(XOR_CRSR_64BA_BIT
, &adev
->xor_reg
->crrr
);
4496 size_t fifo_size
= (adev
->id
== PPC440SPE_DMA0_ID
) ?
4497 DMA0_FIFO_SIZE
: DMA1_FIFO_SIZE
;
4498 adev
->dma_reg
= regs
;
4499 /* DMAx_FIFO_SIZE is defined in bytes,
4500 * <fsiz> - is defined in number of CDB pointers (8byte).
4501 * DMA FIFO Length = CSlength + CPlength, where
4502 * CSlength = CPlength = (fsiz + 1) * 8.
4504 iowrite32(DMA_FIFO_ENABLE
| ((fifo_size
>> 3) - 2),
4505 &adev
->dma_reg
->fsiz
);
4506 /* Configure DMA engine */
4507 iowrite32(DMA_CFG_DXEPR_HP
| DMA_CFG_DFMPP_HP
| DMA_CFG_FALGN
,
4508 &adev
->dma_reg
->cfg
);
4510 iowrite32(~0, &adev
->dma_reg
->dsts
);
4513 adev
->dev
= &ofdev
->dev
;
4514 adev
->common
.dev
= &ofdev
->dev
;
4515 INIT_LIST_HEAD(&adev
->common
.channels
);
4516 dev_set_drvdata(&ofdev
->dev
, adev
);
4518 /* create a channel */
4519 chan
= kzalloc(sizeof(*chan
), GFP_KERNEL
);
4521 dev_err(&ofdev
->dev
, "can't allocate channel structure\n");
4522 initcode
= PPC_ADMA_INIT_CHANNEL
;
4524 goto err_chan_alloc
;
4527 spin_lock_init(&chan
->lock
);
4528 INIT_LIST_HEAD(&chan
->chain
);
4529 INIT_LIST_HEAD(&chan
->all_slots
);
4530 chan
->device
= adev
;
4531 chan
->common
.device
= &adev
->common
;
4532 list_add_tail(&chan
->common
.device_node
, &adev
->common
.channels
);
4533 tasklet_init(&chan
->irq_tasklet
, ppc440spe_adma_tasklet
,
4534 (unsigned long)chan
);
4536 /* allocate and map helper pages for async validation or
4537 * async_mult/async_sum_product operations on DMA0/1.
4539 if (adev
->id
!= PPC440SPE_XOR_ID
) {
4540 chan
->pdest_page
= alloc_page(GFP_KERNEL
);
4541 chan
->qdest_page
= alloc_page(GFP_KERNEL
);
4542 if (!chan
->pdest_page
||
4543 !chan
->qdest_page
) {
4544 if (chan
->pdest_page
)
4545 __free_page(chan
->pdest_page
);
4546 if (chan
->qdest_page
)
4547 __free_page(chan
->qdest_page
);
4549 goto err_page_alloc
;
4551 chan
->pdest
= dma_map_page(&ofdev
->dev
, chan
->pdest_page
, 0,
4552 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4553 chan
->qdest
= dma_map_page(&ofdev
->dev
, chan
->qdest_page
, 0,
4554 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4557 ref
= kmalloc(sizeof(*ref
), GFP_KERNEL
);
4559 ref
->chan
= &chan
->common
;
4560 INIT_LIST_HEAD(&ref
->node
);
4561 list_add_tail(&ref
->node
, &ppc440spe_adma_chan_list
);
4563 dev_err(&ofdev
->dev
, "failed to allocate channel reference!\n");
4568 ret
= ppc440spe_adma_setup_irqs(adev
, chan
, &initcode
);
4572 ppc440spe_adma_init_capabilities(adev
);
4574 ret
= dma_async_device_register(&adev
->common
);
4576 initcode
= PPC_ADMA_INIT_REGISTER
;
4577 dev_err(&ofdev
->dev
, "failed to register dma device\n");
4584 ppc440spe_adma_release_irqs(adev
, chan
);
4586 list_for_each_entry_safe(ref
, _ref
, &ppc440spe_adma_chan_list
, node
) {
4587 if (chan
== to_ppc440spe_adma_chan(ref
->chan
)) {
4588 list_del(&ref
->node
);
4593 if (adev
->id
!= PPC440SPE_XOR_ID
) {
4594 dma_unmap_page(&ofdev
->dev
, chan
->pdest
,
4595 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4596 dma_unmap_page(&ofdev
->dev
, chan
->qdest
,
4597 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4598 __free_page(chan
->pdest_page
);
4599 __free_page(chan
->qdest_page
);
4604 if (adev
->id
== PPC440SPE_XOR_ID
)
4605 iounmap(adev
->xor_reg
);
4607 iounmap(adev
->dma_reg
);
4609 dma_free_coherent(adev
->dev
, adev
->pool_size
,
4610 adev
->dma_desc_pool_virt
,
4611 adev
->dma_desc_pool
);
4615 release_mem_region(res
.start
, resource_size(&res
));
4617 if (id
< PPC440SPE_ADMA_ENGINES_NUM
)
4618 ppc440spe_adma_devices
[id
] = initcode
;
4624 * ppc440spe_adma_remove - remove the asynch device
4626 static int __devexit
ppc440spe_adma_remove(struct platform_device
*ofdev
)
4628 struct ppc440spe_adma_device
*adev
= dev_get_drvdata(&ofdev
->dev
);
4629 struct device_node
*np
= ofdev
->dev
.of_node
;
4630 struct resource res
;
4631 struct dma_chan
*chan
, *_chan
;
4632 struct ppc_dma_chan_ref
*ref
, *_ref
;
4633 struct ppc440spe_adma_chan
*ppc440spe_chan
;
4635 dev_set_drvdata(&ofdev
->dev
, NULL
);
4636 if (adev
->id
< PPC440SPE_ADMA_ENGINES_NUM
)
4637 ppc440spe_adma_devices
[adev
->id
] = -1;
4639 dma_async_device_unregister(&adev
->common
);
4641 list_for_each_entry_safe(chan
, _chan
, &adev
->common
.channels
,
4643 ppc440spe_chan
= to_ppc440spe_adma_chan(chan
);
4644 ppc440spe_adma_release_irqs(adev
, ppc440spe_chan
);
4645 tasklet_kill(&ppc440spe_chan
->irq_tasklet
);
4646 if (adev
->id
!= PPC440SPE_XOR_ID
) {
4647 dma_unmap_page(&ofdev
->dev
, ppc440spe_chan
->pdest
,
4648 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4649 dma_unmap_page(&ofdev
->dev
, ppc440spe_chan
->qdest
,
4650 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
4651 __free_page(ppc440spe_chan
->pdest_page
);
4652 __free_page(ppc440spe_chan
->qdest_page
);
4654 list_for_each_entry_safe(ref
, _ref
, &ppc440spe_adma_chan_list
,
4656 if (ppc440spe_chan
==
4657 to_ppc440spe_adma_chan(ref
->chan
)) {
4658 list_del(&ref
->node
);
4662 list_del(&chan
->device_node
);
4663 kfree(ppc440spe_chan
);
4666 dma_free_coherent(adev
->dev
, adev
->pool_size
,
4667 adev
->dma_desc_pool_virt
, adev
->dma_desc_pool
);
4668 if (adev
->id
== PPC440SPE_XOR_ID
)
4669 iounmap(adev
->xor_reg
);
4671 iounmap(adev
->dma_reg
);
4672 of_address_to_resource(np
, 0, &res
);
4673 release_mem_region(res
.start
, resource_size(&res
));
4679 * /sys driver interface to enable h/w RAID-6 capabilities
4680 * Files created in e.g. /sys/devices/plb.0/400100100.dma0/driver/
4681 * directory are "devices", "enable" and "poly".
4682 * "devices" shows available engines.
4683 * "enable" is used to enable RAID-6 capabilities or to check
4684 * whether these has been activated.
4685 * "poly" allows setting/checking used polynomial (for PPC440SPe only).
4688 static ssize_t
show_ppc440spe_devices(struct device_driver
*dev
, char *buf
)
4693 for (i
= 0; i
< PPC440SPE_ADMA_ENGINES_NUM
; i
++) {
4694 if (ppc440spe_adma_devices
[i
] == -1)
4696 size
+= snprintf(buf
+ size
, PAGE_SIZE
- size
,
4697 "PPC440SP(E)-ADMA.%d: %s\n", i
,
4698 ppc_adma_errors
[ppc440spe_adma_devices
[i
]]);
4703 static ssize_t
show_ppc440spe_r6enable(struct device_driver
*dev
, char *buf
)
4705 return snprintf(buf
, PAGE_SIZE
,
4706 "PPC440SP(e) RAID-6 capabilities are %sABLED.\n",
4707 ppc440spe_r6_enabled
? "EN" : "DIS");
4710 static ssize_t
store_ppc440spe_r6enable(struct device_driver
*dev
,
4711 const char *buf
, size_t count
)
4715 if (!count
|| count
> 11)
4718 if (!ppc440spe_r6_tchan
)
4722 sscanf(buf
, "%lx", &val
);
4723 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_XORBA
, val
);
4726 /* Verify whether it really works now */
4727 if (ppc440spe_test_raid6(ppc440spe_r6_tchan
) == 0) {
4728 pr_info("PPC440SP(e) RAID-6 has been activated "
4730 ppc440spe_r6_enabled
= 1;
4732 pr_info("PPC440SP(e) RAID-6 hasn't been activated!"
4734 ppc440spe_r6_enabled
= 0;
4739 static ssize_t
show_ppc440spe_r6poly(struct device_driver
*dev
, char *buf
)
4745 /* 440SP has fixed polynomial */
4748 reg
= dcr_read(ppc440spe_mq_dcr_host
, DCRN_MQ0_CFBHL
);
4749 reg
>>= MQ0_CFBHL_POLY
;
4753 size
= snprintf(buf
, PAGE_SIZE
, "PPC440SP(e) RAID-6 driver "
4754 "uses 0x1%02x polynomial.\n", reg
);
4758 static ssize_t
store_ppc440spe_r6poly(struct device_driver
*dev
,
4759 const char *buf
, size_t count
)
4761 unsigned long reg
, val
;
4764 /* 440SP uses default 0x14D polynomial only */
4768 if (!count
|| count
> 6)
4771 /* e.g., 0x14D or 0x11D */
4772 sscanf(buf
, "%lx", &val
);
4778 reg
= dcr_read(ppc440spe_mq_dcr_host
, DCRN_MQ0_CFBHL
);
4779 reg
&= ~(0xFF << MQ0_CFBHL_POLY
);
4780 reg
|= val
<< MQ0_CFBHL_POLY
;
4781 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_CFBHL
, reg
);
4786 static DRIVER_ATTR(devices
, S_IRUGO
, show_ppc440spe_devices
, NULL
);
4787 static DRIVER_ATTR(enable
, S_IRUGO
| S_IWUSR
, show_ppc440spe_r6enable
,
4788 store_ppc440spe_r6enable
);
4789 static DRIVER_ATTR(poly
, S_IRUGO
| S_IWUSR
, show_ppc440spe_r6poly
,
4790 store_ppc440spe_r6poly
);
4793 * Common initialisation for RAID engines; allocate memory for
4794 * DMAx FIFOs, perform configuration common for all DMA engines.
4795 * Further DMA engine specific configuration is done at probe time.
4797 static int ppc440spe_configure_raid_devices(void)
4799 struct device_node
*np
;
4800 struct resource i2o_res
;
4801 struct i2o_regs __iomem
*i2o_reg
;
4802 dcr_host_t i2o_dcr_host
;
4803 unsigned int dcr_base
, dcr_len
;
4806 np
= of_find_compatible_node(NULL
, NULL
, "ibm,i2o-440spe");
4808 pr_err("%s: can't find I2O device tree node\n",
4813 if (of_address_to_resource(np
, 0, &i2o_res
)) {
4818 i2o_reg
= of_iomap(np
, 0);
4820 pr_err("%s: failed to map I2O registers\n", __func__
);
4825 /* Get I2O DCRs base */
4826 dcr_base
= dcr_resource_start(np
, 0);
4827 dcr_len
= dcr_resource_len(np
, 0);
4828 if (!dcr_base
&& !dcr_len
) {
4829 pr_err("%s: can't get DCR registers base/len!\n",
4836 i2o_dcr_host
= dcr_map(np
, dcr_base
, dcr_len
);
4837 if (!DCR_MAP_OK(i2o_dcr_host
)) {
4838 pr_err("%s: failed to map DCRs!\n", np
->full_name
);
4845 /* Provide memory regions for DMA's FIFOs: I2O, DMA0 and DMA1 share
4846 * the base address of FIFO memory space.
4847 * Actually we need twice more physical memory than programmed in the
4848 * <fsiz> register (because there are two FIFOs for each DMA: CP and CS)
4850 ppc440spe_dma_fifo_buf
= kmalloc((DMA0_FIFO_SIZE
+ DMA1_FIFO_SIZE
) << 1,
4852 if (!ppc440spe_dma_fifo_buf
) {
4853 pr_err("%s: DMA FIFO buffer allocation failed.\n", __func__
);
4855 dcr_unmap(i2o_dcr_host
, dcr_len
);
4863 mtdcri(SDR0
, DCRN_SDR0_SRST
, DCRN_SDR0_SRST_I2ODMA
);
4864 mtdcri(SDR0
, DCRN_SDR0_SRST
, 0);
4866 /* Setup the base address of mmaped registers */
4867 dcr_write(i2o_dcr_host
, DCRN_I2O0_IBAH
, (u32
)(i2o_res
.start
>> 32));
4868 dcr_write(i2o_dcr_host
, DCRN_I2O0_IBAL
, (u32
)(i2o_res
.start
) |
4870 dcr_unmap(i2o_dcr_host
, dcr_len
);
4872 /* Setup FIFO memory space base address */
4873 iowrite32(0, &i2o_reg
->ifbah
);
4874 iowrite32(((u32
)__pa(ppc440spe_dma_fifo_buf
)), &i2o_reg
->ifbal
);
4876 /* set zero FIFO size for I2O, so the whole
4877 * ppc440spe_dma_fifo_buf is used by DMAs.
4878 * DMAx_FIFOs will be configured while probe.
4880 iowrite32(0, &i2o_reg
->ifsiz
);
4883 /* To prepare WXOR/RXOR functionality we need access to
4884 * Memory Queue Module DCRs (finally it will be enabled
4885 * via /sys interface of the ppc440spe ADMA driver).
4887 np
= of_find_compatible_node(NULL
, NULL
, "ibm,mq-440spe");
4889 pr_err("%s: can't find MQ device tree node\n",
4895 /* Get MQ DCRs base */
4896 dcr_base
= dcr_resource_start(np
, 0);
4897 dcr_len
= dcr_resource_len(np
, 0);
4898 if (!dcr_base
&& !dcr_len
) {
4899 pr_err("%s: can't get DCR registers base/len!\n",
4905 ppc440spe_mq_dcr_host
= dcr_map(np
, dcr_base
, dcr_len
);
4906 if (!DCR_MAP_OK(ppc440spe_mq_dcr_host
)) {
4907 pr_err("%s: failed to map DCRs!\n", np
->full_name
);
4912 ppc440spe_mq_dcr_len
= dcr_len
;
4915 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_BAUH
, DMA_CUED_XOR_HB
);
4918 * - LL transaction passing limit to 1;
4919 * - Memory controller cycle limit to 1;
4920 * - Galois Polynomial to 0x14d (default)
4922 dcr_write(ppc440spe_mq_dcr_host
, DCRN_MQ0_CFBHL
,
4923 (1 << MQ0_CFBHL_TPLM
) | (1 << MQ0_CFBHL_HBCL
) |
4924 (PPC440SPE_DEFAULT_POLY
<< MQ0_CFBHL_POLY
));
4926 atomic_set(&ppc440spe_adma_err_irq_ref
, 0);
4927 for (i
= 0; i
< PPC440SPE_ADMA_ENGINES_NUM
; i
++)
4928 ppc440spe_adma_devices
[i
] = -1;
4935 kfree(ppc440spe_dma_fifo_buf
);
4939 static const struct of_device_id ppc440spe_adma_of_match
[] __devinitconst
= {
4940 { .compatible
= "ibm,dma-440spe", },
4941 { .compatible
= "amcc,xor-accelerator", },
4944 MODULE_DEVICE_TABLE(of
, ppc440spe_adma_of_match
);
4946 static struct platform_driver ppc440spe_adma_driver
= {
4947 .probe
= ppc440spe_adma_probe
,
4948 .remove
= __devexit_p(ppc440spe_adma_remove
),
4950 .name
= "PPC440SP(E)-ADMA",
4951 .owner
= THIS_MODULE
,
4952 .of_match_table
= ppc440spe_adma_of_match
,
4956 static __init
int ppc440spe_adma_init(void)
4960 ret
= ppc440spe_configure_raid_devices();
4964 ret
= platform_driver_register(&ppc440spe_adma_driver
);
4966 pr_err("%s: failed to register platform driver\n",
4971 /* Initialization status */
4972 ret
= driver_create_file(&ppc440spe_adma_driver
.driver
,
4973 &driver_attr_devices
);
4977 /* RAID-6 h/w enable entry */
4978 ret
= driver_create_file(&ppc440spe_adma_driver
.driver
,
4979 &driver_attr_enable
);
4983 /* GF polynomial to use */
4984 ret
= driver_create_file(&ppc440spe_adma_driver
.driver
,
4989 driver_remove_file(&ppc440spe_adma_driver
.driver
,
4990 &driver_attr_enable
);
4992 driver_remove_file(&ppc440spe_adma_driver
.driver
,
4993 &driver_attr_devices
);
4995 /* User will not be able to enable h/w RAID-6 */
4996 pr_err("%s: failed to create RAID-6 driver interface\n",
4998 platform_driver_unregister(&ppc440spe_adma_driver
);
5000 dcr_unmap(ppc440spe_mq_dcr_host
, ppc440spe_mq_dcr_len
);
5001 kfree(ppc440spe_dma_fifo_buf
);
5005 static void __exit
ppc440spe_adma_exit(void)
5007 driver_remove_file(&ppc440spe_adma_driver
.driver
,
5009 driver_remove_file(&ppc440spe_adma_driver
.driver
,
5010 &driver_attr_enable
);
5011 driver_remove_file(&ppc440spe_adma_driver
.driver
,
5012 &driver_attr_devices
);
5013 platform_driver_unregister(&ppc440spe_adma_driver
);
5014 dcr_unmap(ppc440spe_mq_dcr_host
, ppc440spe_mq_dcr_len
);
5015 kfree(ppc440spe_dma_fifo_buf
);
5018 arch_initcall(ppc440spe_adma_init
);
5019 module_exit(ppc440spe_adma_exit
);
5021 MODULE_AUTHOR("Yuri Tikhonov <yur@emcraft.com>");
5022 MODULE_DESCRIPTION("PPC440SPE ADMA Engine Driver");
5023 MODULE_LICENSE("GPL");