1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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>
44#include <linux/of.h>
45#include <linux/of_address.h>
46#include <linux/of_irq.h>
47#include <linux/of_platform.h>
48#include <asm/dcr.h>
49#include <asm/dcr-regs.h>
50#include "adma.h"
51#include "../dmaengine.h"
52
53enum ppc_adma_init_code {
54 PPC_ADMA_INIT_OK = 0,
55 PPC_ADMA_INIT_MEMRES,
56 PPC_ADMA_INIT_MEMREG,
57 PPC_ADMA_INIT_ALLOC,
58 PPC_ADMA_INIT_COHERENT,
59 PPC_ADMA_INIT_CHANNEL,
60 PPC_ADMA_INIT_IRQ1,
61 PPC_ADMA_INIT_IRQ2,
62 PPC_ADMA_INIT_REGISTER
63};
64
65static char *ppc_adma_errors[] = {
66 [PPC_ADMA_INIT_OK] = "ok",
67 [PPC_ADMA_INIT_MEMRES] = "failed to get memory resource",
68 [PPC_ADMA_INIT_MEMREG] = "failed to request memory region",
69 [PPC_ADMA_INIT_ALLOC] = "failed to allocate memory for adev "
70 "structure",
71 [PPC_ADMA_INIT_COHERENT] = "failed to allocate coherent memory for "
72 "hardware descriptors",
73 [PPC_ADMA_INIT_CHANNEL] = "failed to allocate memory for channel",
74 [PPC_ADMA_INIT_IRQ1] = "failed to request first irq",
75 [PPC_ADMA_INIT_IRQ2] = "failed to request second irq",
76 [PPC_ADMA_INIT_REGISTER] = "failed to register dma async device",
77};
78
79static enum ppc_adma_init_code
80ppc440spe_adma_devices[PPC440SPE_ADMA_ENGINES_NUM];
81
82struct ppc_dma_chan_ref {
83 struct dma_chan *chan;
84 struct list_head node;
85};
86
87
88struct list_head
89ppc440spe_adma_chan_list = LIST_HEAD_INIT(ppc440spe_adma_chan_list);
90
91
92
93
94static u32 do_xor_refetch;
95
96
97static void *ppc440spe_dma_fifo_buf;
98
99
100static struct ppc440spe_adma_desc_slot *chan_last_sub[3];
101static struct ppc440spe_adma_desc_slot *chan_first_cdb[3];
102
103
104static struct ppc440spe_adma_desc_slot *xor_last_linked;
105static struct ppc440spe_adma_desc_slot *xor_last_submit;
106
107
108static char ppc440spe_qword[16];
109
110static atomic_t ppc440spe_adma_err_irq_ref;
111static dcr_host_t ppc440spe_mq_dcr_host;
112static unsigned int ppc440spe_mq_dcr_len;
113
114
115
116
117
118
119
120static unsigned long ppc440spe_rxor_state;
121
122
123
124static u32 ppc440spe_r6_enabled;
125static struct ppc440spe_adma_chan *ppc440spe_r6_tchan;
126static struct completion ppc440spe_r6_test_comp;
127
128static int ppc440spe_adma_dma2rxor_prep_src(
129 struct ppc440spe_adma_desc_slot *desc,
130 struct ppc440spe_rxor *cursor, int index,
131 int src_cnt, u32 addr);
132static void ppc440spe_adma_dma2rxor_set_src(
133 struct ppc440spe_adma_desc_slot *desc,
134 int index, dma_addr_t addr);
135static void ppc440spe_adma_dma2rxor_set_mult(
136 struct ppc440spe_adma_desc_slot *desc,
137 int index, u8 mult);
138
139#ifdef ADMA_LL_DEBUG
140#define ADMA_LL_DBG(x) ({ if (1) x; 0; })
141#else
142#define ADMA_LL_DBG(x) ({ if (0) x; 0; })
143#endif
144
145static void print_cb(struct ppc440spe_adma_chan *chan, void *block)
146{
147 struct dma_cdb *cdb;
148 struct xor_cb *cb;
149 int i;
150
151 switch (chan->device->id) {
152 case 0:
153 case 1:
154 cdb = block;
155
156 pr_debug("CDB at %p [%d]:\n"
157 "\t attr 0x%02x opc 0x%02x cnt 0x%08x\n"
158 "\t sg1u 0x%08x sg1l 0x%08x\n"
159 "\t sg2u 0x%08x sg2l 0x%08x\n"
160 "\t sg3u 0x%08x sg3l 0x%08x\n",
161 cdb, chan->device->id,
162 cdb->attr, cdb->opc, le32_to_cpu(cdb->cnt),
163 le32_to_cpu(cdb->sg1u), le32_to_cpu(cdb->sg1l),
164 le32_to_cpu(cdb->sg2u), le32_to_cpu(cdb->sg2l),
165 le32_to_cpu(cdb->sg3u), le32_to_cpu(cdb->sg3l)
166 );
167 break;
168 case 2:
169 cb = block;
170
171 pr_debug("CB at %p [%d]:\n"
172 "\t cbc 0x%08x cbbc 0x%08x cbs 0x%08x\n"
173 "\t cbtah 0x%08x cbtal 0x%08x\n"
174 "\t cblah 0x%08x cblal 0x%08x\n",
175 cb, chan->device->id,
176 cb->cbc, cb->cbbc, cb->cbs,
177 cb->cbtah, cb->cbtal,
178 cb->cblah, cb->cblal);
179 for (i = 0; i < 16; i++) {
180 if (i && !cb->ops[i].h && !cb->ops[i].l)
181 continue;
182 pr_debug("\t ops[%2d]: h 0x%08x l 0x%08x\n",
183 i, cb->ops[i].h, cb->ops[i].l);
184 }
185 break;
186 }
187}
188
189static void print_cb_list(struct ppc440spe_adma_chan *chan,
190 struct ppc440spe_adma_desc_slot *iter)
191{
192 for (; iter; iter = iter->hw_next)
193 print_cb(chan, iter->hw_desc);
194}
195
196static void prep_dma_xor_dbg(int id, dma_addr_t dst, dma_addr_t *src,
197 unsigned int src_cnt)
198{
199 int i;
200
201 pr_debug("\n%s(%d):\nsrc: ", __func__, id);
202 for (i = 0; i < src_cnt; i++)
203 pr_debug("\t0x%016llx ", src[i]);
204 pr_debug("dst:\n\t0x%016llx\n", dst);
205}
206
207static void prep_dma_pq_dbg(int id, dma_addr_t *dst, dma_addr_t *src,
208 unsigned int src_cnt)
209{
210 int i;
211
212 pr_debug("\n%s(%d):\nsrc: ", __func__, id);
213 for (i = 0; i < src_cnt; i++)
214 pr_debug("\t0x%016llx ", src[i]);
215 pr_debug("dst: ");
216 for (i = 0; i < 2; i++)
217 pr_debug("\t0x%016llx ", dst[i]);
218}
219
220static void prep_dma_pqzero_sum_dbg(int id, dma_addr_t *src,
221 unsigned int src_cnt,
222 const unsigned char *scf)
223{
224 int i;
225
226 pr_debug("\n%s(%d):\nsrc(coef): ", __func__, id);
227 if (scf) {
228 for (i = 0; i < src_cnt; i++)
229 pr_debug("\t0x%016llx(0x%02x) ", src[i], scf[i]);
230 } else {
231 for (i = 0; i < src_cnt; i++)
232 pr_debug("\t0x%016llx(no) ", src[i]);
233 }
234
235 pr_debug("dst: ");
236 for (i = 0; i < 2; i++)
237 pr_debug("\t0x%016llx ", src[src_cnt + i]);
238}
239
240
241
242
243
244
245
246
247static void ppc440spe_desc_init_interrupt(struct ppc440spe_adma_desc_slot *desc,
248 struct ppc440spe_adma_chan *chan)
249{
250 struct xor_cb *p;
251
252 switch (chan->device->id) {
253 case PPC440SPE_XOR_ID:
254 p = desc->hw_desc;
255 memset(desc->hw_desc, 0, sizeof(struct xor_cb));
256
257 p->cbc = XOR_CBCR_CBCE_BIT;
258 break;
259 case PPC440SPE_DMA0_ID:
260 case PPC440SPE_DMA1_ID:
261 memset(desc->hw_desc, 0, sizeof(struct dma_cdb));
262
263 set_bit(PPC440SPE_DESC_INT, &desc->flags);
264 break;
265 default:
266 printk(KERN_ERR "Unsupported id %d in %s\n", chan->device->id,
267 __func__);
268 break;
269 }
270}
271
272
273
274
275
276static void ppc440spe_desc_init_null_xor(struct ppc440spe_adma_desc_slot *desc)
277{
278 memset(desc->hw_desc, 0, sizeof(struct xor_cb));
279 desc->hw_next = NULL;
280 desc->src_cnt = 0;
281 desc->dst_cnt = 1;
282}
283
284
285
286
287static void ppc440spe_desc_init_xor(struct ppc440spe_adma_desc_slot *desc,
288 int src_cnt, unsigned long flags)
289{
290 struct xor_cb *hw_desc = desc->hw_desc;
291
292 memset(desc->hw_desc, 0, sizeof(struct xor_cb));
293 desc->hw_next = NULL;
294 desc->src_cnt = src_cnt;
295 desc->dst_cnt = 1;
296
297 hw_desc->cbc = XOR_CBCR_TGT_BIT | src_cnt;
298 if (flags & DMA_PREP_INTERRUPT)
299
300 hw_desc->cbc |= XOR_CBCR_CBCE_BIT;
301}
302
303
304
305
306
307static void ppc440spe_desc_init_dma2pq(struct ppc440spe_adma_desc_slot *desc,
308 int dst_cnt, int src_cnt, unsigned long flags)
309{
310 struct xor_cb *hw_desc = desc->hw_desc;
311
312 memset(desc->hw_desc, 0, sizeof(struct xor_cb));
313 desc->hw_next = NULL;
314 desc->src_cnt = src_cnt;
315 desc->dst_cnt = dst_cnt;
316 memset(desc->reverse_flags, 0, sizeof(desc->reverse_flags));
317 desc->descs_per_op = 0;
318
319 hw_desc->cbc = XOR_CBCR_TGT_BIT;
320 if (flags & DMA_PREP_INTERRUPT)
321
322 hw_desc->cbc |= XOR_CBCR_CBCE_BIT;
323}
324
325#define DMA_CTRL_FLAGS_LAST DMA_PREP_FENCE
326#define DMA_PREP_ZERO_P (DMA_CTRL_FLAGS_LAST << 1)
327#define DMA_PREP_ZERO_Q (DMA_PREP_ZERO_P << 1)
328
329
330
331
332
333static void ppc440spe_desc_init_dma01pq(struct ppc440spe_adma_desc_slot *desc,
334 int dst_cnt, int src_cnt, unsigned long flags,
335 unsigned long op)
336{
337 struct dma_cdb *hw_desc;
338 struct ppc440spe_adma_desc_slot *iter;
339 u8 dopc;
340
341
342 set_bits(op, &desc->flags);
343 desc->src_cnt = src_cnt;
344 desc->dst_cnt = dst_cnt;
345
346
347
348
349 dopc = (desc->dst_cnt == DMA_DEST_MAX_NUM) ?
350 DMA_CDB_OPC_MULTICAST : DMA_CDB_OPC_MV_SG1_SG2;
351
352 list_for_each_entry(iter, &desc->group_list, chain_node) {
353 hw_desc = iter->hw_desc;
354 memset(iter->hw_desc, 0, sizeof(struct dma_cdb));
355
356 if (likely(!list_is_last(&iter->chain_node,
357 &desc->group_list))) {
358
359 iter->hw_next = list_entry(iter->chain_node.next,
360 struct ppc440spe_adma_desc_slot, chain_node);
361 clear_bit(PPC440SPE_DESC_INT, &iter->flags);
362 } else {
363
364
365
366
367
368 iter->hw_next = NULL;
369 if (flags & DMA_PREP_INTERRUPT)
370 set_bit(PPC440SPE_DESC_INT, &iter->flags);
371 else
372 clear_bit(PPC440SPE_DESC_INT, &iter->flags);
373 }
374 }
375
376
377 if (!test_bit(PPC440SPE_DESC_RXOR, &desc->flags)) {
378
379
380
381
382
383 iter = list_first_entry(&desc->group_list,
384 struct ppc440spe_adma_desc_slot,
385 chain_node);
386
387 if (test_bit(PPC440SPE_ZERO_P, &desc->flags)) {
388 hw_desc = iter->hw_desc;
389 hw_desc->opc = DMA_CDB_OPC_MV_SG1_SG2;
390 iter = list_first_entry(&iter->chain_node,
391 struct ppc440spe_adma_desc_slot,
392 chain_node);
393 }
394
395 if (test_bit(PPC440SPE_ZERO_Q, &desc->flags)) {
396 hw_desc = iter->hw_desc;
397 hw_desc->opc = DMA_CDB_OPC_MV_SG1_SG2;
398 iter = list_first_entry(&iter->chain_node,
399 struct ppc440spe_adma_desc_slot,
400 chain_node);
401 }
402
403 list_for_each_entry_from(iter, &desc->group_list, chain_node) {
404 hw_desc = iter->hw_desc;
405 hw_desc->opc = dopc;
406 }
407 } else {
408
409
410
411
412
413
414 iter = list_first_entry(&desc->group_list,
415 struct ppc440spe_adma_desc_slot,
416 chain_node);
417 hw_desc = iter->hw_desc;
418 hw_desc->opc = DMA_CDB_OPC_MV_SG1_SG2;
419
420 if (desc->dst_cnt == DMA_DEST_MAX_NUM) {
421 iter = list_first_entry(&iter->chain_node,
422 struct ppc440spe_adma_desc_slot,
423 chain_node);
424 hw_desc = iter->hw_desc;
425 hw_desc->opc = DMA_CDB_OPC_MV_SG1_SG2;
426 }
427
428
429 if (test_bit(PPC440SPE_DESC_WXOR, &desc->flags)) {
430 iter = list_first_entry(&iter->chain_node,
431 struct ppc440spe_adma_desc_slot,
432 chain_node);
433 list_for_each_entry_from(iter, &desc->group_list,
434 chain_node) {
435 hw_desc = iter->hw_desc;
436 hw_desc->opc = dopc;
437 }
438 }
439 }
440}
441
442
443
444
445
446static void ppc440spe_desc_init_dma01pqzero_sum(
447 struct ppc440spe_adma_desc_slot *desc,
448 int dst_cnt, int src_cnt)
449{
450 struct dma_cdb *hw_desc;
451 struct ppc440spe_adma_desc_slot *iter;
452 int i = 0;
453 u8 dopc = (dst_cnt == 2) ? DMA_CDB_OPC_MULTICAST :
454 DMA_CDB_OPC_MV_SG1_SG2;
455
456
457
458
459
460
461 iter = list_first_entry(&desc->group_list,
462 struct ppc440spe_adma_desc_slot, chain_node);
463 iter = list_entry(iter->chain_node.next,
464 struct ppc440spe_adma_desc_slot, chain_node);
465
466 if (dst_cnt > 1) {
467 iter = list_entry(iter->chain_node.next,
468 struct ppc440spe_adma_desc_slot, chain_node);
469 }
470
471 list_for_each_entry_from(iter, &desc->group_list, chain_node) {
472 hw_desc = iter->hw_desc;
473 memset(iter->hw_desc, 0, sizeof(struct dma_cdb));
474 iter->src_cnt = 0;
475 iter->dst_cnt = 0;
476
477
478
479
480
481
482 if (i++ < src_cnt)
483
484
485
486 hw_desc->opc = dopc;
487 else
488
489 hw_desc->opc = DMA_CDB_OPC_DCHECK128;
490
491 if (likely(!list_is_last(&iter->chain_node,
492 &desc->group_list))) {
493
494 iter->hw_next = list_entry(iter->chain_node.next,
495 struct ppc440spe_adma_desc_slot,
496 chain_node);
497 } else {
498
499
500
501
502
503 iter->hw_next = NULL;
504
505
506
507 set_bit(PPC440SPE_DESC_INT, &iter->flags);
508 }
509 }
510 desc->src_cnt = src_cnt;
511 desc->dst_cnt = dst_cnt;
512}
513
514
515
516
517static void ppc440spe_desc_init_memcpy(struct ppc440spe_adma_desc_slot *desc,
518 unsigned long flags)
519{
520 struct dma_cdb *hw_desc = desc->hw_desc;
521
522 memset(desc->hw_desc, 0, sizeof(struct dma_cdb));
523 desc->hw_next = NULL;
524 desc->src_cnt = 1;
525 desc->dst_cnt = 1;
526
527 if (flags & DMA_PREP_INTERRUPT)
528 set_bit(PPC440SPE_DESC_INT, &desc->flags);
529 else
530 clear_bit(PPC440SPE_DESC_INT, &desc->flags);
531
532 hw_desc->opc = DMA_CDB_OPC_MV_SG1_SG2;
533}
534
535
536
537
538static void ppc440spe_desc_init_memset(struct ppc440spe_adma_desc_slot *desc,
539 int value, unsigned long flags)
540{
541 struct dma_cdb *hw_desc = desc->hw_desc;
542
543 memset(desc->hw_desc, 0, sizeof(struct dma_cdb));
544 desc->hw_next = NULL;
545 desc->src_cnt = 1;
546 desc->dst_cnt = 1;
547
548 if (flags & DMA_PREP_INTERRUPT)
549 set_bit(PPC440SPE_DESC_INT, &desc->flags);
550 else
551 clear_bit(PPC440SPE_DESC_INT, &desc->flags);
552
553 hw_desc->sg1u = hw_desc->sg1l = cpu_to_le32((u32)value);
554 hw_desc->sg3u = hw_desc->sg3l = cpu_to_le32((u32)value);
555 hw_desc->opc = DMA_CDB_OPC_DFILL128;
556}
557
558
559
560
561static void ppc440spe_desc_set_src_addr(struct ppc440spe_adma_desc_slot *desc,
562 struct ppc440spe_adma_chan *chan,
563 int src_idx, dma_addr_t addrh,
564 dma_addr_t addrl)
565{
566 struct dma_cdb *dma_hw_desc;
567 struct xor_cb *xor_hw_desc;
568 phys_addr_t addr64, tmplow, tmphi;
569
570 switch (chan->device->id) {
571 case PPC440SPE_DMA0_ID:
572 case PPC440SPE_DMA1_ID:
573 if (!addrh) {
574 addr64 = addrl;
575 tmphi = (addr64 >> 32);
576 tmplow = (addr64 & 0xFFFFFFFF);
577 } else {
578 tmphi = addrh;
579 tmplow = addrl;
580 }
581 dma_hw_desc = desc->hw_desc;
582 dma_hw_desc->sg1l = cpu_to_le32((u32)tmplow);
583 dma_hw_desc->sg1u |= cpu_to_le32((u32)tmphi);
584 break;
585 case PPC440SPE_XOR_ID:
586 xor_hw_desc = desc->hw_desc;
587 xor_hw_desc->ops[src_idx].l = addrl;
588 xor_hw_desc->ops[src_idx].h |= addrh;
589 break;
590 }
591}
592
593
594
595
596static void ppc440spe_desc_set_src_mult(struct ppc440spe_adma_desc_slot *desc,
597 struct ppc440spe_adma_chan *chan, u32 mult_index,
598 int sg_index, unsigned char mult_value)
599{
600 struct dma_cdb *dma_hw_desc;
601 struct xor_cb *xor_hw_desc;
602 u32 *psgu;
603
604 switch (chan->device->id) {
605 case PPC440SPE_DMA0_ID:
606 case PPC440SPE_DMA1_ID:
607 dma_hw_desc = desc->hw_desc;
608
609 switch (sg_index) {
610
611
612
613 case DMA_CDB_SG_SRC:
614 psgu = &dma_hw_desc->sg1u;
615 break;
616
617
618
619 case DMA_CDB_SG_DST1:
620 psgu = &dma_hw_desc->sg2u;
621 break;
622 case DMA_CDB_SG_DST2:
623 psgu = &dma_hw_desc->sg3u;
624 break;
625 default:
626 BUG();
627 }
628
629 *psgu |= cpu_to_le32(mult_value << mult_index);
630 break;
631 case PPC440SPE_XOR_ID:
632 xor_hw_desc = desc->hw_desc;
633 break;
634 default:
635 BUG();
636 }
637}
638
639
640
641
642static void ppc440spe_desc_set_dest_addr(struct ppc440spe_adma_desc_slot *desc,
643 struct ppc440spe_adma_chan *chan,
644 dma_addr_t addrh, dma_addr_t addrl,
645 u32 dst_idx)
646{
647 struct dma_cdb *dma_hw_desc;
648 struct xor_cb *xor_hw_desc;
649 phys_addr_t addr64, tmphi, tmplow;
650 u32 *psgu, *psgl;
651
652 switch (chan->device->id) {
653 case PPC440SPE_DMA0_ID:
654 case PPC440SPE_DMA1_ID:
655 if (!addrh) {
656 addr64 = addrl;
657 tmphi = (addr64 >> 32);
658 tmplow = (addr64 & 0xFFFFFFFF);
659 } else {
660 tmphi = addrh;
661 tmplow = addrl;
662 }
663 dma_hw_desc = desc->hw_desc;
664
665 psgu = dst_idx ? &dma_hw_desc->sg3u : &dma_hw_desc->sg2u;
666 psgl = dst_idx ? &dma_hw_desc->sg3l : &dma_hw_desc->sg2l;
667
668 *psgl = cpu_to_le32((u32)tmplow);
669 *psgu |= cpu_to_le32((u32)tmphi);
670 break;
671 case PPC440SPE_XOR_ID:
672 xor_hw_desc = desc->hw_desc;
673 xor_hw_desc->cbtal = addrl;
674 xor_hw_desc->cbtah |= addrh;
675 break;
676 }
677}
678
679
680
681
682
683static void ppc440spe_desc_set_byte_count(struct ppc440spe_adma_desc_slot *desc,
684 struct ppc440spe_adma_chan *chan,
685 u32 byte_count)
686{
687 struct dma_cdb *dma_hw_desc;
688 struct xor_cb *xor_hw_desc;
689
690 switch (chan->device->id) {
691 case PPC440SPE_DMA0_ID:
692 case PPC440SPE_DMA1_ID:
693 dma_hw_desc = desc->hw_desc;
694 dma_hw_desc->cnt = cpu_to_le32(byte_count);
695 break;
696 case PPC440SPE_XOR_ID:
697 xor_hw_desc = desc->hw_desc;
698 xor_hw_desc->cbbc = byte_count;
699 break;
700 }
701}
702
703
704
705
706static inline void ppc440spe_desc_set_rxor_block_size(u32 byte_count)
707{
708
709
710
711
712 dcr_write(ppc440spe_mq_dcr_host, DCRN_MQ0_CF2H, byte_count);
713}
714
715
716
717
718static void ppc440spe_desc_set_dcheck(struct ppc440spe_adma_desc_slot *desc,
719 struct ppc440spe_adma_chan *chan, u8 *qword)
720{
721 struct dma_cdb *dma_hw_desc;
722
723 switch (chan->device->id) {
724 case PPC440SPE_DMA0_ID:
725 case PPC440SPE_DMA1_ID:
726 dma_hw_desc = desc->hw_desc;
727 iowrite32(qword[0], &dma_hw_desc->sg3l);
728 iowrite32(qword[4], &dma_hw_desc->sg3u);
729 iowrite32(qword[8], &dma_hw_desc->sg2l);
730 iowrite32(qword[12], &dma_hw_desc->sg2u);
731 break;
732 default:
733 BUG();
734 }
735}
736
737
738
739
740static void ppc440spe_xor_set_link(struct ppc440spe_adma_desc_slot *prev_desc,
741 struct ppc440spe_adma_desc_slot *next_desc)
742{
743 struct xor_cb *xor_hw_desc = prev_desc->hw_desc;
744
745 if (unlikely(!next_desc || !(next_desc->phys))) {
746 printk(KERN_ERR "%s: next_desc=0x%p; next_desc->phys=0x%llx\n",
747 __func__, next_desc,
748 next_desc ? next_desc->phys : 0);
749 BUG();
750 }
751
752 xor_hw_desc->cbs = 0;
753 xor_hw_desc->cblal = next_desc->phys;
754 xor_hw_desc->cblah = 0;
755 xor_hw_desc->cbc |= XOR_CBCR_LNK_BIT;
756}
757
758
759
760
761
762static void ppc440spe_desc_set_link(struct ppc440spe_adma_chan *chan,
763 struct ppc440spe_adma_desc_slot *prev_desc,
764 struct ppc440spe_adma_desc_slot *next_desc)
765{
766 unsigned long flags;
767 struct ppc440spe_adma_desc_slot *tail = next_desc;
768
769 if (unlikely(!prev_desc || !next_desc ||
770 (prev_desc->hw_next && prev_desc->hw_next != next_desc))) {
771
772
773
774
775 printk(KERN_ERR "%s: prev_desc=0x%p; next_desc=0x%p; "
776 "prev->hw_next=0x%p\n", __func__, prev_desc,
777 next_desc, prev_desc ? prev_desc->hw_next : 0);
778 BUG();
779 }
780
781 local_irq_save(flags);
782
783
784 prev_desc->hw_next = next_desc;
785
786 switch (chan->device->id) {
787 case PPC440SPE_DMA0_ID:
788 case PPC440SPE_DMA1_ID:
789 break;
790 case PPC440SPE_XOR_ID:
791
792 while (tail->hw_next)
793 tail = tail->hw_next;
794 xor_last_linked = tail;
795
796 if (prev_desc == xor_last_submit)
797
798 break;
799 ppc440spe_xor_set_link(prev_desc, next_desc);
800 break;
801 }
802
803 local_irq_restore(flags);
804}
805
806
807
808
809static u32 ppc440spe_desc_get_src_addr(struct ppc440spe_adma_desc_slot *desc,
810 struct ppc440spe_adma_chan *chan, int src_idx)
811{
812 struct dma_cdb *dma_hw_desc;
813 struct xor_cb *xor_hw_desc;
814
815 switch (chan->device->id) {
816 case PPC440SPE_DMA0_ID:
817 case PPC440SPE_DMA1_ID:
818 dma_hw_desc = desc->hw_desc;
819
820 switch (dma_hw_desc->opc) {
821 case DMA_CDB_OPC_NO_OP:
822 case DMA_CDB_OPC_DFILL128:
823 return 0;
824 case DMA_CDB_OPC_DCHECK128:
825 if (unlikely(src_idx)) {
826 printk(KERN_ERR "%s: try to get %d source for"
827 " DCHECK128\n", __func__, src_idx);
828 BUG();
829 }
830 return le32_to_cpu(dma_hw_desc->sg1l);
831 case DMA_CDB_OPC_MULTICAST:
832 case DMA_CDB_OPC_MV_SG1_SG2:
833 if (unlikely(src_idx > 2)) {
834 printk(KERN_ERR "%s: try to get %d source from"
835 " DMA descr\n", __func__, src_idx);
836 BUG();
837 }
838 if (src_idx) {
839 if (le32_to_cpu(dma_hw_desc->sg1u) &
840 DMA_CUED_XOR_WIN_MSK) {
841 u8 region;
842
843 if (src_idx == 1)
844 return le32_to_cpu(
845 dma_hw_desc->sg1l) +
846 desc->unmap_len;
847
848 region = (le32_to_cpu(
849 dma_hw_desc->sg1u)) >>
850 DMA_CUED_REGION_OFF;
851
852 region &= DMA_CUED_REGION_MSK;
853 switch (region) {
854 case DMA_RXOR123:
855 return le32_to_cpu(
856 dma_hw_desc->sg1l) +
857 (desc->unmap_len << 1);
858 case DMA_RXOR124:
859 return le32_to_cpu(
860 dma_hw_desc->sg1l) +
861 (desc->unmap_len * 3);
862 case DMA_RXOR125:
863 return le32_to_cpu(
864 dma_hw_desc->sg1l) +
865 (desc->unmap_len << 2);
866 default:
867 printk(KERN_ERR
868 "%s: try to"
869 " get src3 for region %02x"
870 "PPC440SPE_DESC_RXOR12?\n",
871 __func__, region);
872 BUG();
873 }
874 } else {
875 printk(KERN_ERR
876 "%s: try to get %d"
877 " source for non-cued descr\n",
878 __func__, src_idx);
879 BUG();
880 }
881 }
882 return le32_to_cpu(dma_hw_desc->sg1l);
883 default:
884 printk(KERN_ERR "%s: unknown OPC 0x%02x\n",
885 __func__, dma_hw_desc->opc);
886 BUG();
887 }
888 return le32_to_cpu(dma_hw_desc->sg1l);
889 case PPC440SPE_XOR_ID:
890
891 xor_hw_desc = desc->hw_desc;
892 return xor_hw_desc->ops[src_idx].l;
893 }
894 return 0;
895}
896
897
898
899
900
901static u32 ppc440spe_desc_get_dest_addr(struct ppc440spe_adma_desc_slot *desc,
902 struct ppc440spe_adma_chan *chan, int idx)
903{
904 struct dma_cdb *dma_hw_desc;
905 struct xor_cb *xor_hw_desc;
906
907 switch (chan->device->id) {
908 case PPC440SPE_DMA0_ID:
909 case PPC440SPE_DMA1_ID:
910 dma_hw_desc = desc->hw_desc;
911
912 if (likely(!idx))
913 return le32_to_cpu(dma_hw_desc->sg2l);
914 return le32_to_cpu(dma_hw_desc->sg3l);
915 case PPC440SPE_XOR_ID:
916 xor_hw_desc = desc->hw_desc;
917 return xor_hw_desc->cbtal;
918 }
919 return 0;
920}
921
922
923
924
925
926static u32 ppc440spe_desc_get_src_num(struct ppc440spe_adma_desc_slot *desc,
927 struct ppc440spe_adma_chan *chan)
928{
929 struct dma_cdb *dma_hw_desc;
930 struct xor_cb *xor_hw_desc;
931
932 switch (chan->device->id) {
933 case PPC440SPE_DMA0_ID:
934 case PPC440SPE_DMA1_ID:
935 dma_hw_desc = desc->hw_desc;
936
937 switch (dma_hw_desc->opc) {
938 case DMA_CDB_OPC_NO_OP:
939 case DMA_CDB_OPC_DFILL128:
940 return 0;
941 case DMA_CDB_OPC_DCHECK128:
942 return 1;
943 case DMA_CDB_OPC_MV_SG1_SG2:
944 case DMA_CDB_OPC_MULTICAST:
945
946
947
948
949 if (le32_to_cpu(dma_hw_desc->sg1u) &
950 DMA_CUED_XOR_WIN_MSK) {
951
952 if (((le32_to_cpu(dma_hw_desc->sg1u) >>
953 DMA_CUED_REGION_OFF) &
954 DMA_CUED_REGION_MSK) == DMA_RXOR12) {
955
956 return 2;
957 } else {
958
959 return 3;
960 }
961 }
962 return 1;
963 default:
964 printk(KERN_ERR "%s: unknown OPC 0x%02x\n",
965 __func__, dma_hw_desc->opc);
966 BUG();
967 }
968 case PPC440SPE_XOR_ID:
969
970 xor_hw_desc = desc->hw_desc;
971 return xor_hw_desc->cbc & XOR_CDCR_OAC_MSK;
972 default:
973 BUG();
974 }
975 return 0;
976}
977
978
979
980
981
982static u32 ppc440spe_desc_get_dst_num(struct ppc440spe_adma_desc_slot *desc,
983 struct ppc440spe_adma_chan *chan)
984{
985 struct dma_cdb *dma_hw_desc;
986
987 switch (chan->device->id) {
988 case PPC440SPE_DMA0_ID:
989 case PPC440SPE_DMA1_ID:
990
991 dma_hw_desc = desc->hw_desc;
992 switch (dma_hw_desc->opc) {
993 case DMA_CDB_OPC_NO_OP:
994 case DMA_CDB_OPC_DCHECK128:
995 return 0;
996 case DMA_CDB_OPC_MV_SG1_SG2:
997 case DMA_CDB_OPC_DFILL128:
998 return 1;
999 case DMA_CDB_OPC_MULTICAST:
1000 if (desc->dst_cnt == 2)
1001 return 2;
1002 else
1003 return 1;
1004 default:
1005 printk(KERN_ERR "%s: unknown OPC 0x%02x\n",
1006 __func__, dma_hw_desc->opc);
1007 BUG();
1008 }
1009 case PPC440SPE_XOR_ID:
1010
1011 return 1;
1012 default:
1013 BUG();
1014 }
1015 return 0;
1016}
1017
1018
1019
1020
1021
1022static inline u32 ppc440spe_desc_get_link(struct ppc440spe_adma_desc_slot *desc,
1023 struct ppc440spe_adma_chan *chan)
1024{
1025 if (!desc->hw_next)
1026 return 0;
1027
1028 return desc->hw_next->phys;
1029}
1030
1031
1032
1033
1034static inline int ppc440spe_desc_is_aligned(
1035 struct ppc440spe_adma_desc_slot *desc, int num_slots)
1036{
1037 return (desc->idx & (num_slots - 1)) ? 0 : 1;
1038}
1039
1040
1041
1042
1043
1044static int ppc440spe_chan_xor_slot_count(size_t len, int src_cnt,
1045 int *slots_per_op)
1046{
1047 int slot_cnt;
1048
1049
1050 slot_cnt = *slots_per_op = (src_cnt + XOR_MAX_OPS - 1)/XOR_MAX_OPS;
1051
1052 if (likely(len <= PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT))
1053 return slot_cnt;
1054
1055 printk(KERN_ERR "%s: len %d > max %d !!\n",
1056 __func__, len, PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT);
1057 BUG();
1058 return slot_cnt;
1059}
1060
1061
1062
1063
1064
1065static int ppc440spe_dma2_pq_slot_count(dma_addr_t *srcs,
1066 int src_cnt, size_t len)
1067{
1068 signed long long order = 0;
1069 int state = 0;
1070 int addr_count = 0;
1071 int i;
1072 for (i = 1; i < src_cnt; i++) {
1073 dma_addr_t cur_addr = srcs[i];
1074 dma_addr_t old_addr = srcs[i-1];
1075 switch (state) {
1076 case 0:
1077 if (cur_addr == old_addr + len) {
1078
1079 order = 1;
1080 state = 1;
1081 if (i == src_cnt-1)
1082 addr_count++;
1083 } else if (old_addr == cur_addr + len) {
1084
1085 order = -1;
1086 state = 1;
1087 if (i == src_cnt-1)
1088 addr_count++;
1089 } else {
1090 state = 3;
1091 }
1092 break;
1093 case 1:
1094 if (i == src_cnt-2 || (order == -1
1095 && cur_addr != old_addr - len)) {
1096 order = 0;
1097 state = 0;
1098 addr_count++;
1099 } else if (cur_addr == old_addr + len*order) {
1100 state = 2;
1101 if (i == src_cnt-1)
1102 addr_count++;
1103 } else if (cur_addr == old_addr + 2*len) {
1104 state = 2;
1105 if (i == src_cnt-1)
1106 addr_count++;
1107 } else if (cur_addr == old_addr + 3*len) {
1108 state = 2;
1109 if (i == src_cnt-1)
1110 addr_count++;
1111 } else {
1112 order = 0;
1113 state = 0;
1114 addr_count++;
1115 }
1116 break;
1117 case 2:
1118 order = 0;
1119 state = 0;
1120 addr_count++;
1121 break;
1122 }
1123 if (state == 3)
1124 break;
1125 }
1126 if (src_cnt <= 1 || (state != 1 && state != 2)) {
1127 pr_err("%s: src_cnt=%d, state=%d, addr_count=%d, order=%lld\n",
1128 __func__, src_cnt, state, addr_count, order);
1129 for (i = 0; i < src_cnt; i++)
1130 pr_err("\t[%d] 0x%llx \n", i, srcs[i]);
1131 BUG();
1132 }
1133
1134 return (addr_count + XOR_MAX_OPS - 1) / XOR_MAX_OPS;
1135}
1136
1137
1138
1139
1140
1141
1142static u32
1143ppc440spe_chan_get_current_descriptor(struct ppc440spe_adma_chan *chan);
1144static void ppc440spe_chan_append(struct ppc440spe_adma_chan *chan);
1145
1146
1147
1148
1149static void ppc440spe_adma_device_clear_eot_status(
1150 struct ppc440spe_adma_chan *chan)
1151{
1152 struct dma_regs *dma_reg;
1153 struct xor_regs *xor_reg;
1154 u8 *p = chan->device->dma_desc_pool_virt;
1155 struct dma_cdb *cdb;
1156 u32 rv, i;
1157
1158 switch (chan->device->id) {
1159 case PPC440SPE_DMA0_ID:
1160 case PPC440SPE_DMA1_ID:
1161
1162 dma_reg = chan->device->dma_reg;
1163 while ((rv = ioread32(&dma_reg->csfpl))) {
1164 i = rv & DMA_CDB_ADDR_MSK;
1165 cdb = (struct dma_cdb *)&p[i -
1166 (u32)chan->device->dma_desc_pool];
1167
1168
1169
1170
1171 cdb->opc = 0;
1172
1173 if (test_bit(PPC440SPE_RXOR_RUN,
1174 &ppc440spe_rxor_state)) {
1175
1176
1177
1178
1179
1180 if (le32_to_cpu(cdb->sg1u) &
1181 DMA_CUED_XOR_BASE) {
1182
1183 clear_bit(PPC440SPE_RXOR_RUN,
1184 &ppc440spe_rxor_state);
1185 }
1186 }
1187
1188 if (rv & DMA_CDB_STATUS_MSK) {
1189
1190
1191 struct ppc440spe_adma_desc_slot *iter;
1192 dma_addr_t phys = rv & ~DMA_CDB_MSK;
1193
1194
1195
1196
1197
1198 list_for_each_entry(iter, &chan->chain,
1199 chain_node) {
1200 if (iter->phys == phys)
1201 break;
1202 }
1203
1204
1205
1206
1207 BUG_ON(&iter->chain_node == &chan->chain);
1208
1209 if (iter->xor_check_result) {
1210 if (test_bit(PPC440SPE_DESC_PCHECK,
1211 &iter->flags)) {
1212 *iter->xor_check_result |=
1213 SUM_CHECK_P_RESULT;
1214 } else
1215 if (test_bit(PPC440SPE_DESC_QCHECK,
1216 &iter->flags)) {
1217 *iter->xor_check_result |=
1218 SUM_CHECK_Q_RESULT;
1219 } else
1220 BUG();
1221 }
1222 }
1223 }
1224
1225 rv = ioread32(&dma_reg->dsts);
1226 if (rv) {
1227 pr_err("DMA%d err status: 0x%x\n",
1228 chan->device->id, rv);
1229
1230 iowrite32(rv, &dma_reg->dsts);
1231 }
1232 break;
1233 case PPC440SPE_XOR_ID:
1234
1235 xor_reg = chan->device->xor_reg;
1236 rv = ioread32be(&xor_reg->sr);
1237 iowrite32be(rv, &xor_reg->sr);
1238
1239 if (rv & (XOR_IE_ICBIE_BIT|XOR_IE_ICIE_BIT|XOR_IE_RPTIE_BIT)) {
1240 if (rv & XOR_IE_RPTIE_BIT) {
1241
1242
1243
1244 u32 val = ioread32be(&xor_reg->ccbalr);
1245
1246 iowrite32be(val, &xor_reg->cblalr);
1247
1248 val = ioread32be(&xor_reg->crsr);
1249 iowrite32be(val | XOR_CRSR_XAE_BIT,
1250 &xor_reg->crsr);
1251 } else
1252 pr_err("XOR ERR 0x%x status\n", rv);
1253 break;
1254 }
1255
1256
1257
1258
1259 if (!(ioread32be(&xor_reg->sr) & XOR_SR_XCP_BIT) &&
1260 do_xor_refetch)
1261 ppc440spe_chan_append(chan);
1262 break;
1263 }
1264}
1265
1266
1267
1268
1269static int ppc440spe_chan_is_busy(struct ppc440spe_adma_chan *chan)
1270{
1271 struct dma_regs *dma_reg;
1272 struct xor_regs *xor_reg;
1273 int busy = 0;
1274
1275 switch (chan->device->id) {
1276 case PPC440SPE_DMA0_ID:
1277 case PPC440SPE_DMA1_ID:
1278 dma_reg = chan->device->dma_reg;
1279
1280
1281
1282 if (ioread16(&dma_reg->cpfhp) != ioread16(&dma_reg->cpftp) ||
1283 ioread16(&dma_reg->cpftp) != ioread16(&dma_reg->csftp))
1284 busy = 1;
1285 break;
1286 case PPC440SPE_XOR_ID:
1287
1288
1289 xor_reg = chan->device->xor_reg;
1290 busy = (ioread32be(&xor_reg->sr) & XOR_SR_XCP_BIT) ? 1 : 0;
1291 break;
1292 }
1293
1294 return busy;
1295}
1296
1297
1298
1299
1300static void ppc440spe_chan_set_first_xor_descriptor(
1301 struct ppc440spe_adma_chan *chan,
1302 struct ppc440spe_adma_desc_slot *next_desc)
1303{
1304 struct xor_regs *xor_reg = chan->device->xor_reg;
1305
1306 if (ioread32be(&xor_reg->sr) & XOR_SR_XCP_BIT)
1307 printk(KERN_INFO "%s: Warn: XORcore is running "
1308 "when try to set the first CDB!\n",
1309 __func__);
1310
1311 xor_last_submit = xor_last_linked = next_desc;
1312
1313 iowrite32be(XOR_CRSR_64BA_BIT, &xor_reg->crsr);
1314
1315 iowrite32be(next_desc->phys, &xor_reg->cblalr);
1316 iowrite32be(0, &xor_reg->cblahr);
1317 iowrite32be(ioread32be(&xor_reg->cbcr) | XOR_CBCR_LNK_BIT,
1318 &xor_reg->cbcr);
1319
1320 chan->hw_chain_inited = 1;
1321}
1322
1323
1324
1325
1326
1327static void ppc440spe_dma_put_desc(struct ppc440spe_adma_chan *chan,
1328 struct ppc440spe_adma_desc_slot *desc)
1329{
1330 u32 pcdb;
1331 struct dma_regs *dma_reg = chan->device->dma_reg;
1332
1333 pcdb = desc->phys;
1334 if (!test_bit(PPC440SPE_DESC_INT, &desc->flags))
1335 pcdb |= DMA_CDB_NO_INT;
1336
1337 chan_last_sub[chan->device->id] = desc;
1338
1339 ADMA_LL_DBG(print_cb(chan, desc->hw_desc));
1340
1341 iowrite32(pcdb, &dma_reg->cpfpl);
1342}
1343
1344
1345
1346
1347static void ppc440spe_chan_append(struct ppc440spe_adma_chan *chan)
1348{
1349 struct xor_regs *xor_reg;
1350 struct ppc440spe_adma_desc_slot *iter;
1351 struct xor_cb *xcb;
1352 u32 cur_desc;
1353 unsigned long flags;
1354
1355 local_irq_save(flags);
1356
1357 switch (chan->device->id) {
1358 case PPC440SPE_DMA0_ID:
1359 case PPC440SPE_DMA1_ID:
1360 cur_desc = ppc440spe_chan_get_current_descriptor(chan);
1361
1362 if (likely(cur_desc)) {
1363 iter = chan_last_sub[chan->device->id];
1364 BUG_ON(!iter);
1365 } else {
1366
1367 iter = chan_first_cdb[chan->device->id];
1368 BUG_ON(!iter);
1369 ppc440spe_dma_put_desc(chan, iter);
1370 chan->hw_chain_inited = 1;
1371 }
1372
1373
1374 if (!iter->hw_next)
1375 break;
1376
1377
1378 list_for_each_entry_continue(iter, &chan->chain, chain_node) {
1379 ppc440spe_dma_put_desc(chan, iter);
1380 if (!iter->hw_next)
1381 break;
1382 }
1383 break;
1384 case PPC440SPE_XOR_ID:
1385
1386 if (!xor_last_submit->hw_next)
1387 break;
1388
1389 xor_reg = chan->device->xor_reg;
1390
1391
1392
1393
1394
1395 xcb = xor_last_linked->hw_desc;
1396 xcb->cbc |= XOR_CBCR_CBCE_BIT;
1397
1398 if (!(ioread32be(&xor_reg->sr) & XOR_SR_XCP_BIT)) {
1399
1400 do_xor_refetch = 0;
1401 ppc440spe_xor_set_link(xor_last_submit,
1402 xor_last_submit->hw_next);
1403
1404 ADMA_LL_DBG(print_cb_list(chan,
1405 xor_last_submit->hw_next));
1406
1407 xor_last_submit = xor_last_linked;
1408 iowrite32be(ioread32be(&xor_reg->crsr) |
1409 XOR_CRSR_RCBE_BIT | XOR_CRSR_64BA_BIT,
1410 &xor_reg->crsr);
1411 } else {
1412
1413 do_xor_refetch = 1;
1414 }
1415
1416 break;
1417 }
1418
1419 local_irq_restore(flags);
1420}
1421
1422
1423
1424
1425static u32
1426ppc440spe_chan_get_current_descriptor(struct ppc440spe_adma_chan *chan)
1427{
1428 struct dma_regs *dma_reg;
1429 struct xor_regs *xor_reg;
1430
1431 if (unlikely(!chan->hw_chain_inited))
1432
1433 return 0;
1434
1435 switch (chan->device->id) {
1436 case PPC440SPE_DMA0_ID:
1437 case PPC440SPE_DMA1_ID:
1438 dma_reg = chan->device->dma_reg;
1439 return ioread32(&dma_reg->acpl) & (~DMA_CDB_MSK);
1440 case PPC440SPE_XOR_ID:
1441 xor_reg = chan->device->xor_reg;
1442 return ioread32be(&xor_reg->ccbalr);
1443 }
1444 return 0;
1445}
1446
1447
1448
1449
1450static void ppc440spe_chan_run(struct ppc440spe_adma_chan *chan)
1451{
1452 struct xor_regs *xor_reg;
1453
1454 switch (chan->device->id) {
1455 case PPC440SPE_DMA0_ID:
1456 case PPC440SPE_DMA1_ID:
1457
1458 break;
1459 case PPC440SPE_XOR_ID:
1460
1461 xor_reg = chan->device->xor_reg;
1462
1463
1464 iowrite32be(XOR_CRSR_64BA_BIT | XOR_CRSR_XAE_BIT,
1465 &xor_reg->crsr);
1466 break;
1467 }
1468}
1469
1470
1471
1472
1473
1474static void ppc440spe_chan_start_null_xor(struct ppc440spe_adma_chan *chan);
1475static int ppc440spe_adma_alloc_chan_resources(struct dma_chan *chan);
1476
1477static dma_cookie_t
1478ppc440spe_adma_tx_submit(struct dma_async_tx_descriptor *tx);
1479
1480static void ppc440spe_adma_set_dest(struct ppc440spe_adma_desc_slot *tx,
1481 dma_addr_t addr, int index);
1482static void
1483ppc440spe_adma_memcpy_xor_set_src(struct ppc440spe_adma_desc_slot *tx,
1484 dma_addr_t addr, int index);
1485
1486static void
1487ppc440spe_adma_pq_set_dest(struct ppc440spe_adma_desc_slot *tx,
1488 dma_addr_t *paddr, unsigned long flags);
1489static void
1490ppc440spe_adma_pq_set_src(struct ppc440spe_adma_desc_slot *tx,
1491 dma_addr_t addr, int index);
1492static void
1493ppc440spe_adma_pq_set_src_mult(struct ppc440spe_adma_desc_slot *tx,
1494 unsigned char mult, int index, int dst_pos);
1495static void
1496ppc440spe_adma_pqzero_sum_set_dest(struct ppc440spe_adma_desc_slot *tx,
1497 dma_addr_t paddr, dma_addr_t qaddr);
1498
1499static struct page *ppc440spe_rxor_srcs[32];
1500
1501
1502
1503
1504static int ppc440spe_can_rxor(struct page **srcs, int src_cnt, size_t len)
1505{
1506 int i, order = 0, state = 0;
1507 int idx = 0;
1508
1509 if (unlikely(!(src_cnt > 1)))
1510 return 0;
1511
1512 BUG_ON(src_cnt > ARRAY_SIZE(ppc440spe_rxor_srcs));
1513
1514
1515 for (i = 0; i < src_cnt; i++) {
1516 if (!srcs[i])
1517 continue;
1518 ppc440spe_rxor_srcs[idx++] = srcs[i];
1519 }
1520 src_cnt = idx;
1521
1522 for (i = 1; i < src_cnt; i++) {
1523 char *cur_addr = page_address(ppc440spe_rxor_srcs[i]);
1524 char *old_addr = page_address(ppc440spe_rxor_srcs[i - 1]);
1525
1526 switch (state) {
1527 case 0:
1528 if (cur_addr == old_addr + len) {
1529
1530 order = 1;
1531 state = 1;
1532 } else if (old_addr == cur_addr + len) {
1533
1534 order = -1;
1535 state = 1;
1536 } else
1537 goto out;
1538 break;
1539 case 1:
1540 if ((i == src_cnt - 2) ||
1541 (order == -1 && cur_addr != old_addr - len)) {
1542 order = 0;
1543 state = 0;
1544 } else if ((cur_addr == old_addr + len * order) ||
1545 (cur_addr == old_addr + 2 * len) ||
1546 (cur_addr == old_addr + 3 * len)) {
1547 state = 2;
1548 } else {
1549 order = 0;
1550 state = 0;
1551 }
1552 break;
1553 case 2:
1554 order = 0;
1555 state = 0;
1556 break;
1557 }
1558 }
1559
1560out:
1561 if (state == 1 || state == 2)
1562 return 1;
1563
1564 return 0;
1565}
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579static int ppc440spe_adma_estimate(struct dma_chan *chan,
1580 enum dma_transaction_type cap, struct page **dst_lst, int dst_cnt,
1581 struct page **src_lst, int src_cnt, size_t src_sz)
1582{
1583 int ef = 1;
1584
1585 if (cap == DMA_PQ || cap == DMA_PQ_VAL) {
1586
1587
1588
1589 if (unlikely(!ppc440spe_r6_enabled))
1590 return -1;
1591 }
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602 if (cap == DMA_PQ && chan->chan_id == PPC440SPE_XOR_ID) {
1603
1604 if (dst_cnt == 1 && src_cnt == 2 && dst_lst[0] == src_lst[1])
1605 ef = 0;
1606 else if (ppc440spe_can_rxor(src_lst, src_cnt, src_sz))
1607 ef = 3;
1608 else
1609 ef = 0;
1610 }
1611
1612
1613 if (likely(ef) &&
1614 !ppc440spe_chan_is_busy(to_ppc440spe_adma_chan(chan)))
1615 ef++;
1616
1617 return ef;
1618}
1619
1620struct dma_chan *
1621ppc440spe_async_tx_find_best_channel(enum dma_transaction_type cap,
1622 struct page **dst_lst, int dst_cnt, struct page **src_lst,
1623 int src_cnt, size_t src_sz)
1624{
1625 struct dma_chan *best_chan = NULL;
1626 struct ppc_dma_chan_ref *ref;
1627 int best_rank = -1;
1628
1629 if (unlikely(!src_sz))
1630 return NULL;
1631 if (src_sz > PAGE_SIZE) {
1632
1633
1634
1635
1636
1637 switch (cap) {
1638 case DMA_PQ:
1639 if (src_cnt == 1 && dst_lst[1] == src_lst[0])
1640 return NULL;
1641 if (src_cnt == 2 && dst_lst[1] == src_lst[1])
1642 return NULL;
1643 break;
1644 case DMA_PQ_VAL:
1645 case DMA_XOR_VAL:
1646 return NULL;
1647 default:
1648 break;
1649 }
1650 }
1651
1652 list_for_each_entry(ref, &ppc440spe_adma_chan_list, node) {
1653 if (dma_has_cap(cap, ref->chan->device->cap_mask)) {
1654 int rank;
1655
1656 rank = ppc440spe_adma_estimate(ref->chan, cap, dst_lst,
1657 dst_cnt, src_lst, src_cnt, src_sz);
1658 if (rank > best_rank) {
1659 best_rank = rank;
1660 best_chan = ref->chan;
1661 }
1662 }
1663 }
1664
1665 return best_chan;
1666}
1667EXPORT_SYMBOL_GPL(ppc440spe_async_tx_find_best_channel);
1668
1669
1670
1671
1672
1673static struct ppc440spe_adma_desc_slot *
1674ppc440spe_get_group_entry(struct ppc440spe_adma_desc_slot *tdesc, u32 entry_idx)
1675{
1676 struct ppc440spe_adma_desc_slot *iter = tdesc->group_head;
1677 int i = 0;
1678
1679 if (entry_idx < 0 || entry_idx >= (tdesc->src_cnt + tdesc->dst_cnt)) {
1680 printk("%s: entry_idx %d, src_cnt %d, dst_cnt %d\n",
1681 __func__, entry_idx, tdesc->src_cnt, tdesc->dst_cnt);
1682 BUG();
1683 }
1684
1685 list_for_each_entry(iter, &tdesc->group_list, chain_node) {
1686 if (i++ == entry_idx)
1687 break;
1688 }
1689 return iter;
1690}
1691
1692
1693
1694
1695
1696
1697static void ppc440spe_adma_free_slots(struct ppc440spe_adma_desc_slot *slot,
1698 struct ppc440spe_adma_chan *chan)
1699{
1700 int stride = slot->slots_per_op;
1701
1702 while (stride--) {
1703 slot->slots_per_op = 0;
1704 slot = list_entry(slot->slot_node.next,
1705 struct ppc440spe_adma_desc_slot,
1706 slot_node);
1707 }
1708}
1709
1710static void ppc440spe_adma_unmap(struct ppc440spe_adma_chan *chan,
1711 struct ppc440spe_adma_desc_slot *desc)
1712{
1713 u32 src_cnt, dst_cnt;
1714 dma_addr_t addr;
1715
1716
1717
1718
1719
1720
1721 src_cnt = ppc440spe_desc_get_src_num(desc, chan);
1722 dst_cnt = ppc440spe_desc_get_dst_num(desc, chan);
1723
1724
1725 if (!(desc->async_tx.flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
1726 while (dst_cnt--) {
1727 addr = ppc440spe_desc_get_dest_addr(
1728 desc, chan, dst_cnt);
1729 dma_unmap_page(chan->device->dev,
1730 addr, desc->unmap_len,
1731 DMA_FROM_DEVICE);
1732 }
1733 }
1734
1735
1736 if (!(desc->async_tx.flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
1737 while (src_cnt--) {
1738 addr = ppc440spe_desc_get_src_addr(
1739 desc, chan, src_cnt);
1740 dma_unmap_page(chan->device->dev,
1741 addr, desc->unmap_len,
1742 DMA_TO_DEVICE);
1743 }
1744 }
1745}
1746
1747
1748
1749
1750
1751static dma_cookie_t ppc440spe_adma_run_tx_complete_actions(
1752 struct ppc440spe_adma_desc_slot *desc,
1753 struct ppc440spe_adma_chan *chan,
1754 dma_cookie_t cookie)
1755{
1756 int i;
1757
1758 BUG_ON(desc->async_tx.cookie < 0);
1759 if (desc->async_tx.cookie > 0) {
1760 cookie = desc->async_tx.cookie;
1761 desc->async_tx.cookie = 0;
1762
1763
1764
1765
1766 if (desc->async_tx.callback)
1767 desc->async_tx.callback(
1768 desc->async_tx.callback_param);
1769
1770 dma_descriptor_unmap(&desc->async_tx);
1771
1772
1773
1774
1775
1776
1777 if (chan && chan->needs_unmap && desc->group_head &&
1778 desc->unmap_len) {
1779 struct ppc440spe_adma_desc_slot *unmap =
1780 desc->group_head;
1781
1782 u32 slot_count = unmap->slot_cnt;
1783
1784
1785 for (i = 0; i < slot_count; i++) {
1786 BUG_ON(!unmap);
1787 ppc440spe_adma_unmap(chan, unmap);
1788 unmap = unmap->hw_next;
1789 }
1790 }
1791 }
1792
1793
1794 dma_run_dependencies(&desc->async_tx);
1795
1796 return cookie;
1797}
1798
1799
1800
1801
1802static int ppc440spe_adma_clean_slot(struct ppc440spe_adma_desc_slot *desc,
1803 struct ppc440spe_adma_chan *chan)
1804{
1805
1806
1807
1808 if (!async_tx_test_ack(&desc->async_tx))
1809 return 0;
1810
1811
1812
1813
1814 if (list_is_last(&desc->chain_node, &chan->chain) ||
1815 desc->phys == ppc440spe_chan_get_current_descriptor(chan))
1816 return 1;
1817
1818 if (chan->device->id != PPC440SPE_XOR_ID) {
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828 struct dma_cdb *cdb = desc->hw_desc;
1829 if (cdb->opc == DMA_CDB_OPC_DCHECK128)
1830 return 1;
1831 }
1832
1833 dev_dbg(chan->device->common.dev, "\tfree slot %llx: %d stride: %d\n",
1834 desc->phys, desc->idx, desc->slots_per_op);
1835
1836 list_del(&desc->chain_node);
1837 ppc440spe_adma_free_slots(desc, chan);
1838 return 0;
1839}
1840
1841
1842
1843
1844
1845
1846
1847
1848static void __ppc440spe_adma_slot_cleanup(struct ppc440spe_adma_chan *chan)
1849{
1850 struct ppc440spe_adma_desc_slot *iter, *_iter, *group_start = NULL;
1851 dma_cookie_t cookie = 0;
1852 u32 current_desc = ppc440spe_chan_get_current_descriptor(chan);
1853 int busy = ppc440spe_chan_is_busy(chan);
1854 int seen_current = 0, slot_cnt = 0, slots_per_op = 0;
1855
1856 dev_dbg(chan->device->common.dev, "ppc440spe adma%d: %s\n",
1857 chan->device->id, __func__);
1858
1859 if (!current_desc) {
1860
1861
1862
1863 return;
1864 }
1865
1866
1867
1868
1869 list_for_each_entry_safe(iter, _iter, &chan->chain,
1870 chain_node) {
1871 dev_dbg(chan->device->common.dev, "\tcookie: %d slot: %d "
1872 "busy: %d this_desc: %#llx next_desc: %#x "
1873 "cur: %#x ack: %d\n",
1874 iter->async_tx.cookie, iter->idx, busy, iter->phys,
1875 ppc440spe_desc_get_link(iter, chan), current_desc,
1876 async_tx_test_ack(&iter->async_tx));
1877 prefetch(_iter);
1878 prefetch(&_iter->async_tx);
1879
1880
1881
1882
1883
1884 if (seen_current)
1885 break;
1886
1887
1888
1889
1890
1891 if (iter->phys == current_desc) {
1892 BUG_ON(seen_current++);
1893 if (busy || ppc440spe_desc_get_link(iter, chan)) {
1894
1895
1896
1897 break;
1898 }
1899 }
1900
1901
1902 if (!slot_cnt && !slots_per_op) {
1903 slot_cnt = iter->slot_cnt;
1904 slots_per_op = iter->slots_per_op;
1905 if (slot_cnt <= slots_per_op) {
1906 slot_cnt = 0;
1907 slots_per_op = 0;
1908 }
1909 }
1910
1911 if (slot_cnt) {
1912 if (!group_start)
1913 group_start = iter;
1914 slot_cnt -= slots_per_op;
1915 }
1916
1917
1918 if (slots_per_op != 0 && slot_cnt == 0) {
1919 struct ppc440spe_adma_desc_slot *grp_iter, *_grp_iter;
1920 int end_of_chain = 0;
1921
1922
1923 slot_cnt = group_start->slot_cnt;
1924 grp_iter = group_start;
1925 list_for_each_entry_safe_from(grp_iter, _grp_iter,
1926 &chan->chain, chain_node) {
1927
1928 cookie = ppc440spe_adma_run_tx_complete_actions(
1929 grp_iter, chan, cookie);
1930
1931 slot_cnt -= slots_per_op;
1932 end_of_chain = ppc440spe_adma_clean_slot(
1933 grp_iter, chan);
1934 if (end_of_chain && slot_cnt) {
1935
1936 if (cookie > 0)
1937 chan->common.completed_cookie = cookie;
1938 return;
1939 }
1940
1941 if (slot_cnt == 0 || end_of_chain)
1942 break;
1943 }
1944
1945
1946 BUG_ON(slot_cnt);
1947
1948 slots_per_op = 0;
1949 group_start = NULL;
1950 if (end_of_chain)
1951 break;
1952 else
1953 continue;
1954 } else if (slots_per_op)
1955 continue;
1956
1957 cookie = ppc440spe_adma_run_tx_complete_actions(iter, chan,
1958 cookie);
1959
1960 if (ppc440spe_adma_clean_slot(iter, chan))
1961 break;
1962 }
1963
1964 BUG_ON(!seen_current);
1965
1966 if (cookie > 0) {
1967 chan->common.completed_cookie = cookie;
1968 pr_debug("\tcompleted cookie %d\n", cookie);
1969 }
1970
1971}
1972
1973
1974
1975
1976static void ppc440spe_adma_tasklet(unsigned long data)
1977{
1978 struct ppc440spe_adma_chan *chan = (struct ppc440spe_adma_chan *) data;
1979
1980 spin_lock_nested(&chan->lock, SINGLE_DEPTH_NESTING);
1981 __ppc440spe_adma_slot_cleanup(chan);
1982 spin_unlock(&chan->lock);
1983}
1984
1985
1986
1987
1988static void ppc440spe_adma_slot_cleanup(struct ppc440spe_adma_chan *chan)
1989{
1990 spin_lock_bh(&chan->lock);
1991 __ppc440spe_adma_slot_cleanup(chan);
1992 spin_unlock_bh(&chan->lock);
1993}
1994
1995
1996
1997
1998static struct ppc440spe_adma_desc_slot *ppc440spe_adma_alloc_slots(
1999 struct ppc440spe_adma_chan *chan, int num_slots,
2000 int slots_per_op)
2001{
2002 struct ppc440spe_adma_desc_slot *iter = NULL, *_iter;
2003 struct ppc440spe_adma_desc_slot *alloc_start = NULL;
2004 struct list_head chain = LIST_HEAD_INIT(chain);
2005 int slots_found, retry = 0;
2006
2007
2008 BUG_ON(!num_slots || !slots_per_op);
2009
2010
2011
2012
2013retry:
2014 slots_found = 0;
2015 if (retry == 0)
2016 iter = chan->last_used;
2017 else
2018 iter = list_entry(&chan->all_slots,
2019 struct ppc440spe_adma_desc_slot,
2020 slot_node);
2021 list_for_each_entry_safe_continue(iter, _iter, &chan->all_slots,
2022 slot_node) {
2023 prefetch(_iter);
2024 prefetch(&_iter->async_tx);
2025 if (iter->slots_per_op) {
2026 slots_found = 0;
2027 continue;
2028 }
2029
2030
2031 if (!slots_found++)
2032 alloc_start = iter;
2033
2034 if (slots_found == num_slots) {
2035 struct ppc440spe_adma_desc_slot *alloc_tail = NULL;
2036 struct ppc440spe_adma_desc_slot *last_used = NULL;
2037
2038 iter = alloc_start;
2039 while (num_slots) {
2040 int i;
2041
2042 if (num_slots != slots_per_op)
2043 async_tx_ack(&iter->async_tx);
2044
2045 list_add_tail(&iter->chain_node, &chain);
2046 alloc_tail = iter;
2047 iter->async_tx.cookie = 0;
2048 iter->hw_next = NULL;
2049 iter->flags = 0;
2050 iter->slot_cnt = num_slots;
2051 iter->xor_check_result = NULL;
2052 for (i = 0; i < slots_per_op; i++) {
2053 iter->slots_per_op = slots_per_op - i;
2054 last_used = iter;
2055 iter = list_entry(iter->slot_node.next,
2056 struct ppc440spe_adma_desc_slot,
2057 slot_node);
2058 }
2059 num_slots -= slots_per_op;
2060 }
2061 alloc_tail->group_head = alloc_start;
2062 alloc_tail->async_tx.cookie = -EBUSY;
2063 list_splice(&chain, &alloc_tail->group_list);
2064 chan->last_used = last_used;
2065 return alloc_tail;
2066 }
2067 }
2068 if (!retry++)
2069 goto retry;
2070
2071
2072 tasklet_schedule(&chan->irq_tasklet);
2073 return NULL;
2074}
2075
2076
2077
2078
2079static int ppc440spe_adma_alloc_chan_resources(struct dma_chan *chan)
2080{
2081 struct ppc440spe_adma_chan *ppc440spe_chan;
2082 struct ppc440spe_adma_desc_slot *slot = NULL;
2083 char *hw_desc;
2084 int i, db_sz;
2085 int init;
2086
2087 ppc440spe_chan = to_ppc440spe_adma_chan(chan);
2088 init = ppc440spe_chan->slots_allocated ? 0 : 1;
2089 chan->chan_id = ppc440spe_chan->device->id;
2090
2091
2092 i = ppc440spe_chan->slots_allocated;
2093 if (ppc440spe_chan->device->id != PPC440SPE_XOR_ID)
2094 db_sz = sizeof(struct dma_cdb);
2095 else
2096 db_sz = sizeof(struct xor_cb);
2097
2098 for (; i < (ppc440spe_chan->device->pool_size / db_sz); i++) {
2099 slot = kzalloc(sizeof(struct ppc440spe_adma_desc_slot),
2100 GFP_KERNEL);
2101 if (!slot) {
2102 printk(KERN_INFO "SPE ADMA Channel only initialized"
2103 " %d descriptor slots", i--);
2104 break;
2105 }
2106
2107 hw_desc = (char *) ppc440spe_chan->device->dma_desc_pool_virt;
2108 slot->hw_desc = (void *) &hw_desc[i * db_sz];
2109 dma_async_tx_descriptor_init(&slot->async_tx, chan);
2110 slot->async_tx.tx_submit = ppc440spe_adma_tx_submit;
2111 INIT_LIST_HEAD(&slot->chain_node);
2112 INIT_LIST_HEAD(&slot->slot_node);
2113 INIT_LIST_HEAD(&slot->group_list);
2114 slot->phys = ppc440spe_chan->device->dma_desc_pool + i * db_sz;
2115 slot->idx = i;
2116
2117 spin_lock_bh(&ppc440spe_chan->lock);
2118 ppc440spe_chan->slots_allocated++;
2119 list_add_tail(&slot->slot_node, &ppc440spe_chan->all_slots);
2120 spin_unlock_bh(&ppc440spe_chan->lock);
2121 }
2122
2123 if (i && !ppc440spe_chan->last_used) {
2124 ppc440spe_chan->last_used =
2125 list_entry(ppc440spe_chan->all_slots.next,
2126 struct ppc440spe_adma_desc_slot,
2127 slot_node);
2128 }
2129
2130 dev_dbg(ppc440spe_chan->device->common.dev,
2131 "ppc440spe adma%d: allocated %d descriptor slots\n",
2132 ppc440spe_chan->device->id, i);
2133
2134
2135 if (init) {
2136 switch (ppc440spe_chan->device->id) {
2137 case PPC440SPE_DMA0_ID:
2138 case PPC440SPE_DMA1_ID:
2139 ppc440spe_chan->hw_chain_inited = 0;
2140
2141 if (!ppc440spe_r6_tchan)
2142 ppc440spe_r6_tchan = ppc440spe_chan;
2143 break;
2144 case PPC440SPE_XOR_ID:
2145 ppc440spe_chan_start_null_xor(ppc440spe_chan);
2146 break;
2147 default:
2148 BUG();
2149 }
2150 ppc440spe_chan->needs_unmap = 1;
2151 }
2152
2153 return (i > 0) ? i : -ENOMEM;
2154}
2155
2156
2157
2158
2159static void ppc440spe_rxor_set_region(struct ppc440spe_adma_desc_slot *desc,
2160 u8 xor_arg_no, u32 mask)
2161{
2162 struct xor_cb *xcb = desc->hw_desc;
2163
2164 xcb->ops[xor_arg_no].h |= mask;
2165}
2166
2167
2168
2169
2170static void ppc440spe_rxor_set_src(struct ppc440spe_adma_desc_slot *desc,
2171 u8 xor_arg_no, dma_addr_t addr)
2172{
2173 struct xor_cb *xcb = desc->hw_desc;
2174
2175 xcb->ops[xor_arg_no].h |= DMA_CUED_XOR_BASE;
2176 xcb->ops[xor_arg_no].l = addr;
2177}
2178
2179
2180
2181
2182static void ppc440spe_rxor_set_mult(struct ppc440spe_adma_desc_slot *desc,
2183 u8 xor_arg_no, u8 idx, u8 mult)
2184{
2185 struct xor_cb *xcb = desc->hw_desc;
2186
2187 xcb->ops[xor_arg_no].h |= mult << (DMA_CUED_MULT1_OFF + idx * 8);
2188}
2189
2190
2191
2192
2193
2194static void ppc440spe_adma_check_threshold(struct ppc440spe_adma_chan *chan)
2195{
2196 dev_dbg(chan->device->common.dev, "ppc440spe adma%d: pending: %d\n",
2197 chan->device->id, chan->pending);
2198
2199 if (chan->pending >= PPC440SPE_ADMA_THRESHOLD) {
2200 chan->pending = 0;
2201 ppc440spe_chan_append(chan);
2202 }
2203}
2204
2205
2206
2207
2208
2209
2210static dma_cookie_t ppc440spe_adma_tx_submit(struct dma_async_tx_descriptor *tx)
2211{
2212 struct ppc440spe_adma_desc_slot *sw_desc;
2213 struct ppc440spe_adma_chan *chan = to_ppc440spe_adma_chan(tx->chan);
2214 struct ppc440spe_adma_desc_slot *group_start, *old_chain_tail;
2215 int slot_cnt;
2216 int slots_per_op;
2217 dma_cookie_t cookie;
2218
2219 sw_desc = tx_to_ppc440spe_adma_slot(tx);
2220
2221 group_start = sw_desc->group_head;
2222 slot_cnt = group_start->slot_cnt;
2223 slots_per_op = group_start->slots_per_op;
2224
2225 spin_lock_bh(&chan->lock);
2226 cookie = dma_cookie_assign(tx);
2227
2228 if (unlikely(list_empty(&chan->chain))) {
2229
2230 list_splice_init(&sw_desc->group_list, &chan->chain);
2231 chan_first_cdb[chan->device->id] = group_start;
2232 } else {
2233
2234 old_chain_tail = list_entry(chan->chain.prev,
2235 struct ppc440spe_adma_desc_slot,
2236 chain_node);
2237 list_splice_init(&sw_desc->group_list,
2238 &old_chain_tail->chain_node);
2239
2240 ppc440spe_desc_set_link(chan, old_chain_tail, group_start);
2241 }
2242
2243
2244 chan->pending += slot_cnt / slots_per_op;
2245 ppc440spe_adma_check_threshold(chan);
2246 spin_unlock_bh(&chan->lock);
2247
2248 dev_dbg(chan->device->common.dev,
2249 "ppc440spe adma%d: %s cookie: %d slot: %d tx %p\n",
2250 chan->device->id, __func__,
2251 sw_desc->async_tx.cookie, sw_desc->idx, sw_desc);
2252
2253 return cookie;
2254}
2255
2256
2257
2258
2259static struct dma_async_tx_descriptor *ppc440spe_adma_prep_dma_interrupt(
2260 struct dma_chan *chan, unsigned long flags)
2261{
2262 struct ppc440spe_adma_chan *ppc440spe_chan;
2263 struct ppc440spe_adma_desc_slot *sw_desc, *group_start;
2264 int slot_cnt, slots_per_op;
2265
2266 ppc440spe_chan = to_ppc440spe_adma_chan(chan);
2267
2268 dev_dbg(ppc440spe_chan->device->common.dev,
2269 "ppc440spe adma%d: %s\n", ppc440spe_chan->device->id,
2270 __func__);
2271
2272 spin_lock_bh(&ppc440spe_chan->lock);
2273 slot_cnt = slots_per_op = 1;
2274 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt,
2275 slots_per_op);
2276 if (sw_desc) {
2277 group_start = sw_desc->group_head;
2278 ppc440spe_desc_init_interrupt(group_start, ppc440spe_chan);
2279 group_start->unmap_len = 0;
2280 sw_desc->async_tx.flags = flags;
2281 }
2282 spin_unlock_bh(&ppc440spe_chan->lock);
2283
2284 return sw_desc ? &sw_desc->async_tx : NULL;
2285}
2286
2287
2288
2289
2290static struct dma_async_tx_descriptor *ppc440spe_adma_prep_dma_memcpy(
2291 struct dma_chan *chan, dma_addr_t dma_dest,
2292 dma_addr_t dma_src, size_t len, unsigned long flags)
2293{
2294 struct ppc440spe_adma_chan *ppc440spe_chan;
2295 struct ppc440spe_adma_desc_slot *sw_desc, *group_start;
2296 int slot_cnt, slots_per_op;
2297
2298 ppc440spe_chan = to_ppc440spe_adma_chan(chan);
2299
2300 if (unlikely(!len))
2301 return NULL;
2302
2303 BUG_ON(len > PPC440SPE_ADMA_DMA_MAX_BYTE_COUNT);
2304
2305 spin_lock_bh(&ppc440spe_chan->lock);
2306
2307 dev_dbg(ppc440spe_chan->device->common.dev,
2308 "ppc440spe adma%d: %s len: %u int_en %d\n",
2309 ppc440spe_chan->device->id, __func__, len,
2310 flags & DMA_PREP_INTERRUPT ? 1 : 0);
2311 slot_cnt = slots_per_op = 1;
2312 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt,
2313 slots_per_op);
2314 if (sw_desc) {
2315 group_start = sw_desc->group_head;
2316 ppc440spe_desc_init_memcpy(group_start, flags);
2317 ppc440spe_adma_set_dest(group_start, dma_dest, 0);
2318 ppc440spe_adma_memcpy_xor_set_src(group_start, dma_src, 0);
2319 ppc440spe_desc_set_byte_count(group_start, ppc440spe_chan, len);
2320 sw_desc->unmap_len = len;
2321 sw_desc->async_tx.flags = flags;
2322 }
2323 spin_unlock_bh(&ppc440spe_chan->lock);
2324
2325 return sw_desc ? &sw_desc->async_tx : NULL;
2326}
2327
2328
2329
2330
2331static struct dma_async_tx_descriptor *ppc440spe_adma_prep_dma_memset(
2332 struct dma_chan *chan, dma_addr_t dma_dest, int value,
2333 size_t len, unsigned long flags)
2334{
2335 struct ppc440spe_adma_chan *ppc440spe_chan;
2336 struct ppc440spe_adma_desc_slot *sw_desc, *group_start;
2337 int slot_cnt, slots_per_op;
2338
2339 ppc440spe_chan = to_ppc440spe_adma_chan(chan);
2340
2341 if (unlikely(!len))
2342 return NULL;
2343
2344 BUG_ON(len > PPC440SPE_ADMA_DMA_MAX_BYTE_COUNT);
2345
2346 spin_lock_bh(&ppc440spe_chan->lock);
2347
2348 dev_dbg(ppc440spe_chan->device->common.dev,
2349 "ppc440spe adma%d: %s cal: %u len: %u int_en %d\n",
2350 ppc440spe_chan->device->id, __func__, value, len,
2351 flags & DMA_PREP_INTERRUPT ? 1 : 0);
2352
2353 slot_cnt = slots_per_op = 1;
2354 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt,
2355 slots_per_op);
2356 if (sw_desc) {
2357 group_start = sw_desc->group_head;
2358 ppc440spe_desc_init_memset(group_start, value, flags);
2359 ppc440spe_adma_set_dest(group_start, dma_dest, 0);
2360 ppc440spe_desc_set_byte_count(group_start, ppc440spe_chan, len);
2361 sw_desc->unmap_len = len;
2362 sw_desc->async_tx.flags = flags;
2363 }
2364 spin_unlock_bh(&ppc440spe_chan->lock);
2365
2366 return sw_desc ? &sw_desc->async_tx : NULL;
2367}
2368
2369
2370
2371
2372static struct dma_async_tx_descriptor *ppc440spe_adma_prep_dma_xor(
2373 struct dma_chan *chan, dma_addr_t dma_dest,
2374 dma_addr_t *dma_src, u32 src_cnt, size_t len,
2375 unsigned long flags)
2376{
2377 struct ppc440spe_adma_chan *ppc440spe_chan;
2378 struct ppc440spe_adma_desc_slot *sw_desc, *group_start;
2379 int slot_cnt, slots_per_op;
2380
2381 ppc440spe_chan = to_ppc440spe_adma_chan(chan);
2382
2383 ADMA_LL_DBG(prep_dma_xor_dbg(ppc440spe_chan->device->id,
2384 dma_dest, dma_src, src_cnt));
2385 if (unlikely(!len))
2386 return NULL;
2387 BUG_ON(len > PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT);
2388
2389 dev_dbg(ppc440spe_chan->device->common.dev,
2390 "ppc440spe adma%d: %s src_cnt: %d len: %u int_en: %d\n",
2391 ppc440spe_chan->device->id, __func__, src_cnt, len,
2392 flags & DMA_PREP_INTERRUPT ? 1 : 0);
2393
2394 spin_lock_bh(&ppc440spe_chan->lock);
2395 slot_cnt = ppc440spe_chan_xor_slot_count(len, src_cnt, &slots_per_op);
2396 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt,
2397 slots_per_op);
2398 if (sw_desc) {
2399 group_start = sw_desc->group_head;
2400 ppc440spe_desc_init_xor(group_start, src_cnt, flags);
2401 ppc440spe_adma_set_dest(group_start, dma_dest, 0);
2402 while (src_cnt--)
2403 ppc440spe_adma_memcpy_xor_set_src(group_start,
2404 dma_src[src_cnt], src_cnt);
2405 ppc440spe_desc_set_byte_count(group_start, ppc440spe_chan, len);
2406 sw_desc->unmap_len = len;
2407 sw_desc->async_tx.flags = flags;
2408 }
2409 spin_unlock_bh(&ppc440spe_chan->lock);
2410
2411 return sw_desc ? &sw_desc->async_tx : NULL;
2412}
2413
2414static inline void
2415ppc440spe_desc_set_xor_src_cnt(struct ppc440spe_adma_desc_slot *desc,
2416 int src_cnt);
2417static void ppc440spe_init_rxor_cursor(struct ppc440spe_rxor *cursor);
2418
2419
2420
2421
2422static void ppc440spe_adma_init_dma2rxor_slot(
2423 struct ppc440spe_adma_desc_slot *desc,
2424 dma_addr_t *src, int src_cnt)
2425{
2426 int i;
2427
2428
2429 for (i = 0; i < src_cnt; i++) {
2430 ppc440spe_adma_dma2rxor_prep_src(desc, &desc->rxor_cursor, i,
2431 desc->src_cnt, (u32)src[i]);
2432 }
2433}
2434
2435
2436
2437
2438
2439static struct ppc440spe_adma_desc_slot *ppc440spe_dma01_prep_mult(
2440 struct ppc440spe_adma_chan *ppc440spe_chan,
2441 dma_addr_t *dst, int dst_cnt, dma_addr_t *src, int src_cnt,
2442 const unsigned char *scf, size_t len, unsigned long flags)
2443{
2444 struct ppc440spe_adma_desc_slot *sw_desc = NULL;
2445 unsigned long op = 0;
2446 int slot_cnt;
2447
2448 set_bit(PPC440SPE_DESC_WXOR, &op);
2449 slot_cnt = 2;
2450
2451 spin_lock_bh(&ppc440spe_chan->lock);
2452
2453
2454 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt, 1);
2455 if (sw_desc) {
2456 struct ppc440spe_adma_chan *chan;
2457 struct ppc440spe_adma_desc_slot *iter;
2458 struct dma_cdb *hw_desc;
2459
2460 chan = to_ppc440spe_adma_chan(sw_desc->async_tx.chan);
2461 set_bits(op, &sw_desc->flags);
2462 sw_desc->src_cnt = src_cnt;
2463 sw_desc->dst_cnt = dst_cnt;
2464
2465
2466
2467 iter = list_first_entry(&sw_desc->group_list,
2468 struct ppc440spe_adma_desc_slot,
2469 chain_node);
2470 memset(iter->hw_desc, 0, sizeof(struct dma_cdb));
2471
2472 iter->hw_next = list_entry(iter->chain_node.next,
2473 struct ppc440spe_adma_desc_slot,
2474 chain_node);
2475 clear_bit(PPC440SPE_DESC_INT, &iter->flags);
2476 hw_desc = iter->hw_desc;
2477 hw_desc->opc = DMA_CDB_OPC_MULTICAST;
2478
2479 ppc440spe_desc_set_dest_addr(iter, chan,
2480 DMA_CUED_XOR_BASE, dst[0], 0);
2481 ppc440spe_desc_set_dest_addr(iter, chan, 0, dst[1], 1);
2482 ppc440spe_desc_set_src_addr(iter, chan, 0, DMA_CUED_XOR_HB,
2483 src[0]);
2484 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan, len);
2485 iter->unmap_len = len;
2486
2487
2488
2489
2490
2491 iter = list_first_entry(&iter->chain_node,
2492 struct ppc440spe_adma_desc_slot,
2493 chain_node);
2494 memset(iter->hw_desc, 0, sizeof(struct dma_cdb));
2495 iter->hw_next = NULL;
2496 if (flags & DMA_PREP_INTERRUPT)
2497 set_bit(PPC440SPE_DESC_INT, &iter->flags);
2498 else
2499 clear_bit(PPC440SPE_DESC_INT, &iter->flags);
2500
2501 hw_desc = iter->hw_desc;
2502 hw_desc->opc = DMA_CDB_OPC_MV_SG1_SG2;
2503 ppc440spe_desc_set_src_addr(iter, chan, 0,
2504 DMA_CUED_XOR_HB, dst[1]);
2505 ppc440spe_desc_set_dest_addr(iter, chan,
2506 DMA_CUED_XOR_BASE, dst[0], 0);
2507
2508 ppc440spe_desc_set_src_mult(iter, chan, DMA_CUED_MULT1_OFF,
2509 DMA_CDB_SG_DST1, scf[0]);
2510 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan, len);
2511 iter->unmap_len = len;
2512 sw_desc->async_tx.flags = flags;
2513 }
2514
2515 spin_unlock_bh(&ppc440spe_chan->lock);
2516
2517 return sw_desc;
2518}
2519
2520
2521
2522
2523
2524
2525static struct ppc440spe_adma_desc_slot *ppc440spe_dma01_prep_sum_product(
2526 struct ppc440spe_adma_chan *ppc440spe_chan,
2527 dma_addr_t *dst, dma_addr_t *src, int src_cnt,
2528 const unsigned char *scf, size_t len, unsigned long flags)
2529{
2530 struct ppc440spe_adma_desc_slot *sw_desc = NULL;
2531 unsigned long op = 0;
2532 int slot_cnt;
2533
2534 set_bit(PPC440SPE_DESC_WXOR, &op);
2535 slot_cnt = 3;
2536
2537 spin_lock_bh(&ppc440spe_chan->lock);
2538
2539
2540 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt, 1);
2541 if (sw_desc) {
2542 struct ppc440spe_adma_chan *chan;
2543 struct ppc440spe_adma_desc_slot *iter;
2544 struct dma_cdb *hw_desc;
2545
2546 chan = to_ppc440spe_adma_chan(sw_desc->async_tx.chan);
2547 set_bits(op, &sw_desc->flags);
2548 sw_desc->src_cnt = src_cnt;
2549 sw_desc->dst_cnt = 1;
2550
2551 iter = list_first_entry(&sw_desc->group_list,
2552 struct ppc440spe_adma_desc_slot,
2553 chain_node);
2554 memset(iter->hw_desc, 0, sizeof(struct dma_cdb));
2555 iter->hw_next = list_entry(iter->chain_node.next,
2556 struct ppc440spe_adma_desc_slot,
2557 chain_node);
2558 clear_bit(PPC440SPE_DESC_INT, &iter->flags);
2559 hw_desc = iter->hw_desc;
2560 hw_desc->opc = DMA_CDB_OPC_MULTICAST;
2561
2562 ppc440spe_desc_set_dest_addr(iter, chan, DMA_CUED_XOR_BASE,
2563 *dst, 0);
2564 ppc440spe_desc_set_dest_addr(iter, chan, 0,
2565 ppc440spe_chan->qdest, 1);
2566 ppc440spe_desc_set_src_addr(iter, chan, 0, DMA_CUED_XOR_HB,
2567 src[1]);
2568 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan, len);
2569 iter->unmap_len = len;
2570
2571
2572
2573 iter = list_first_entry(&iter->chain_node,
2574 struct ppc440spe_adma_desc_slot,
2575 chain_node);
2576 memset(iter->hw_desc, 0, sizeof(struct dma_cdb));
2577
2578 iter->hw_next = list_entry(iter->chain_node.next,
2579 struct ppc440spe_adma_desc_slot,
2580 chain_node);
2581 if (flags & DMA_PREP_INTERRUPT)
2582 set_bit(PPC440SPE_DESC_INT, &iter->flags);
2583 else
2584 clear_bit(PPC440SPE_DESC_INT, &iter->flags);
2585
2586 hw_desc = iter->hw_desc;
2587 hw_desc->opc = DMA_CDB_OPC_MV_SG1_SG2;
2588 ppc440spe_desc_set_src_addr(iter, chan, 0, DMA_CUED_XOR_HB,
2589 ppc440spe_chan->qdest);
2590 ppc440spe_desc_set_dest_addr(iter, chan, DMA_CUED_XOR_BASE,
2591 *dst, 0);
2592 ppc440spe_desc_set_src_mult(iter, chan, DMA_CUED_MULT1_OFF,
2593 DMA_CDB_SG_DST1, scf[1]);
2594 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan, len);
2595 iter->unmap_len = len;
2596
2597
2598
2599
2600
2601 iter = list_first_entry(&iter->chain_node,
2602 struct ppc440spe_adma_desc_slot,
2603 chain_node);
2604 memset(iter->hw_desc, 0, sizeof(struct dma_cdb));
2605 iter->hw_next = NULL;
2606 if (flags & DMA_PREP_INTERRUPT)
2607 set_bit(PPC440SPE_DESC_INT, &iter->flags);
2608 else
2609 clear_bit(PPC440SPE_DESC_INT, &iter->flags);
2610
2611 hw_desc = iter->hw_desc;
2612 hw_desc->opc = DMA_CDB_OPC_MV_SG1_SG2;
2613 ppc440spe_desc_set_src_addr(iter, chan, 0, DMA_CUED_XOR_HB,
2614 src[0]);
2615 ppc440spe_desc_set_dest_addr(iter, chan, DMA_CUED_XOR_BASE,
2616 *dst, 0);
2617 ppc440spe_desc_set_src_mult(iter, chan, DMA_CUED_MULT1_OFF,
2618 DMA_CDB_SG_DST1, scf[0]);
2619 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan, len);
2620 iter->unmap_len = len;
2621 sw_desc->async_tx.flags = flags;
2622 }
2623
2624 spin_unlock_bh(&ppc440spe_chan->lock);
2625
2626 return sw_desc;
2627}
2628
2629static struct ppc440spe_adma_desc_slot *ppc440spe_dma01_prep_pq(
2630 struct ppc440spe_adma_chan *ppc440spe_chan,
2631 dma_addr_t *dst, int dst_cnt, dma_addr_t *src, int src_cnt,
2632 const unsigned char *scf, size_t len, unsigned long flags)
2633{
2634 int slot_cnt;
2635 struct ppc440spe_adma_desc_slot *sw_desc = NULL, *iter;
2636 unsigned long op = 0;
2637 unsigned char mult = 1;
2638
2639 pr_debug("%s: dst_cnt %d, src_cnt %d, len %d\n",
2640 __func__, dst_cnt, src_cnt, len);
2641
2642
2643
2644
2645 set_bit(PPC440SPE_DESC_WXOR, &op);
2646 if (!test_and_set_bit(PPC440SPE_RXOR_RUN, &ppc440spe_rxor_state)) {
2647
2648
2649
2650
2651
2652
2653 if (src_cnt > 1 &&
2654 !(len & MQ0_CF2H_RXOR_BS_MASK) &&
2655 (src[0] + len) == src[1]) {
2656
2657 set_bit(PPC440SPE_DESC_RXOR, &op);
2658 if (src_cnt != 2) {
2659
2660 if ((src[1] + len) == src[2]) {
2661
2662 set_bit(PPC440SPE_DESC_RXOR123,
2663 &op);
2664 } else if ((src[1] + len * 2) == src[2]) {
2665
2666 set_bit(PPC440SPE_DESC_RXOR124, &op);
2667 } else if ((src[1] + len * 3) == src[2]) {
2668
2669 set_bit(PPC440SPE_DESC_RXOR125,
2670 &op);
2671 } else {
2672
2673 set_bit(PPC440SPE_DESC_RXOR12,
2674 &op);
2675 }
2676 } else {
2677
2678 set_bit(PPC440SPE_DESC_RXOR12, &op);
2679 }
2680 }
2681
2682 if (!test_bit(PPC440SPE_DESC_RXOR, &op)) {
2683
2684 clear_bit(PPC440SPE_RXOR_RUN,
2685 &ppc440spe_rxor_state);
2686 } else {
2687
2688 ppc440spe_desc_set_rxor_block_size(len);
2689 }
2690 }
2691
2692
2693 if (!test_bit(PPC440SPE_DESC_RXOR, &op)) {
2694
2695
2696
2697
2698 slot_cnt = src_cnt;
2699
2700 if (flags & DMA_PREP_ZERO_P) {
2701 slot_cnt++;
2702 set_bit(PPC440SPE_ZERO_P, &op);
2703 }
2704 if (flags & DMA_PREP_ZERO_Q) {
2705 slot_cnt++;
2706 set_bit(PPC440SPE_ZERO_Q, &op);
2707 }
2708 } else {
2709
2710
2711
2712
2713 slot_cnt = dst_cnt;
2714
2715 if (flags & DMA_PREP_ZERO_P)
2716 set_bit(PPC440SPE_ZERO_P, &op);
2717 if (flags & DMA_PREP_ZERO_Q)
2718 set_bit(PPC440SPE_ZERO_Q, &op);
2719
2720 if (test_bit(PPC440SPE_DESC_RXOR12, &op))
2721 slot_cnt += src_cnt - 2;
2722 else
2723 slot_cnt += src_cnt - 3;
2724
2725
2726
2727
2728 if (slot_cnt == dst_cnt)
2729
2730 clear_bit(PPC440SPE_DESC_WXOR, &op);
2731 }
2732
2733 spin_lock_bh(&ppc440spe_chan->lock);
2734
2735 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt, 1);
2736 if (sw_desc) {
2737 ppc440spe_desc_init_dma01pq(sw_desc, dst_cnt, src_cnt,
2738 flags, op);
2739
2740
2741 pr_debug("%s: set dst descriptor 0, 1: 0x%016llx, 0x%016llx\n",
2742 __func__, dst[0], dst[1]);
2743 ppc440spe_adma_pq_set_dest(sw_desc, dst, flags);
2744 while (src_cnt--) {
2745 ppc440spe_adma_pq_set_src(sw_desc, src[src_cnt],
2746 src_cnt);
2747
2748
2749
2750
2751
2752
2753
2754 if (!(flags & DMA_PREP_PQ_DISABLE_Q))
2755 mult = scf[src_cnt];
2756 ppc440spe_adma_pq_set_src_mult(sw_desc,
2757 mult, src_cnt, dst_cnt - 1);
2758 }
2759
2760
2761 sw_desc->async_tx.flags = flags;
2762 list_for_each_entry(iter, &sw_desc->group_list,
2763 chain_node) {
2764 ppc440spe_desc_set_byte_count(iter,
2765 ppc440spe_chan, len);
2766 iter->unmap_len = len;
2767 }
2768 }
2769 spin_unlock_bh(&ppc440spe_chan->lock);
2770
2771 return sw_desc;
2772}
2773
2774static struct ppc440spe_adma_desc_slot *ppc440spe_dma2_prep_pq(
2775 struct ppc440spe_adma_chan *ppc440spe_chan,
2776 dma_addr_t *dst, int dst_cnt, dma_addr_t *src, int src_cnt,
2777 const unsigned char *scf, size_t len, unsigned long flags)
2778{
2779 int slot_cnt, descs_per_op;
2780 struct ppc440spe_adma_desc_slot *sw_desc = NULL, *iter;
2781 unsigned long op = 0;
2782 unsigned char mult = 1;
2783
2784 BUG_ON(!dst_cnt);
2785
2786
2787
2788 spin_lock_bh(&ppc440spe_chan->lock);
2789 descs_per_op = ppc440spe_dma2_pq_slot_count(src, src_cnt, len);
2790 if (descs_per_op < 0) {
2791 spin_unlock_bh(&ppc440spe_chan->lock);
2792 return NULL;
2793 }
2794
2795
2796 slot_cnt = descs_per_op * dst_cnt;
2797
2798 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt, 1);
2799 if (sw_desc) {
2800 op = slot_cnt;
2801 sw_desc->async_tx.flags = flags;
2802 list_for_each_entry(iter, &sw_desc->group_list, chain_node) {
2803 ppc440spe_desc_init_dma2pq(iter, dst_cnt, src_cnt,
2804 --op ? 0 : flags);
2805 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan,
2806 len);
2807 iter->unmap_len = len;
2808
2809 ppc440spe_init_rxor_cursor(&(iter->rxor_cursor));
2810 iter->rxor_cursor.len = len;
2811 iter->descs_per_op = descs_per_op;
2812 }
2813 op = 0;
2814 list_for_each_entry(iter, &sw_desc->group_list, chain_node) {
2815 op++;
2816 if (op % descs_per_op == 0)
2817 ppc440spe_adma_init_dma2rxor_slot(iter, src,
2818 src_cnt);
2819 if (likely(!list_is_last(&iter->chain_node,
2820 &sw_desc->group_list))) {
2821
2822 iter->hw_next =
2823 list_entry(iter->chain_node.next,
2824 struct ppc440spe_adma_desc_slot,
2825 chain_node);
2826 ppc440spe_xor_set_link(iter, iter->hw_next);
2827 } else {
2828
2829 iter->hw_next = NULL;
2830 }
2831 }
2832
2833
2834 sw_desc->dst_cnt = dst_cnt;
2835 if (flags & DMA_PREP_ZERO_P)
2836 set_bit(PPC440SPE_ZERO_P, &sw_desc->flags);
2837 if (flags & DMA_PREP_ZERO_Q)
2838 set_bit(PPC440SPE_ZERO_Q, &sw_desc->flags);
2839
2840
2841 ppc440spe_adma_pq_set_dest(sw_desc, dst, flags);
2842
2843 while (src_cnt--) {
2844
2845
2846
2847 ppc440spe_adma_pq_set_src(sw_desc, src[src_cnt],
2848 src_cnt);
2849 if (!(flags & DMA_PREP_PQ_DISABLE_Q))
2850 mult = scf[src_cnt];
2851 ppc440spe_adma_pq_set_src_mult(sw_desc,
2852 mult, src_cnt, dst_cnt - 1);
2853 }
2854 }
2855 spin_unlock_bh(&ppc440spe_chan->lock);
2856 ppc440spe_desc_set_rxor_block_size(len);
2857 return sw_desc;
2858}
2859
2860
2861
2862
2863static struct dma_async_tx_descriptor *ppc440spe_adma_prep_dma_pq(
2864 struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
2865 unsigned int src_cnt, const unsigned char *scf,
2866 size_t len, unsigned long flags)
2867{
2868 struct ppc440spe_adma_chan *ppc440spe_chan;
2869 struct ppc440spe_adma_desc_slot *sw_desc = NULL;
2870 int dst_cnt = 0;
2871
2872 ppc440spe_chan = to_ppc440spe_adma_chan(chan);
2873
2874 ADMA_LL_DBG(prep_dma_pq_dbg(ppc440spe_chan->device->id,
2875 dst, src, src_cnt));
2876 BUG_ON(!len);
2877 BUG_ON(len > PPC440SPE_ADMA_XOR_MAX_BYTE_COUNT);
2878 BUG_ON(!src_cnt);
2879
2880 if (src_cnt == 1 && dst[1] == src[0]) {
2881 dma_addr_t dest[2];
2882
2883
2884 dest[0] = dst[1];
2885
2886 dest[1] = ppc440spe_chan->qdest;
2887 sw_desc = ppc440spe_dma01_prep_mult(ppc440spe_chan,
2888 dest, 2, src, src_cnt, scf, len, flags);
2889 return sw_desc ? &sw_desc->async_tx : NULL;
2890 }
2891
2892 if (src_cnt == 2 && dst[1] == src[1]) {
2893 sw_desc = ppc440spe_dma01_prep_sum_product(ppc440spe_chan,
2894 &dst[1], src, 2, scf, len, flags);
2895 return sw_desc ? &sw_desc->async_tx : NULL;
2896 }
2897
2898 if (!(flags & DMA_PREP_PQ_DISABLE_P)) {
2899 BUG_ON(!dst[0]);
2900 dst_cnt++;
2901 flags |= DMA_PREP_ZERO_P;
2902 }
2903
2904 if (!(flags & DMA_PREP_PQ_DISABLE_Q)) {
2905 BUG_ON(!dst[1]);
2906 dst_cnt++;
2907 flags |= DMA_PREP_ZERO_Q;
2908 }
2909
2910 BUG_ON(!dst_cnt);
2911
2912 dev_dbg(ppc440spe_chan->device->common.dev,
2913 "ppc440spe adma%d: %s src_cnt: %d len: %u int_en: %d\n",
2914 ppc440spe_chan->device->id, __func__, src_cnt, len,
2915 flags & DMA_PREP_INTERRUPT ? 1 : 0);
2916
2917 switch (ppc440spe_chan->device->id) {
2918 case PPC440SPE_DMA0_ID:
2919 case PPC440SPE_DMA1_ID:
2920 sw_desc = ppc440spe_dma01_prep_pq(ppc440spe_chan,
2921 dst, dst_cnt, src, src_cnt, scf,
2922 len, flags);
2923 break;
2924
2925 case PPC440SPE_XOR_ID:
2926 sw_desc = ppc440spe_dma2_prep_pq(ppc440spe_chan,
2927 dst, dst_cnt, src, src_cnt, scf,
2928 len, flags);
2929 break;
2930 }
2931
2932 return sw_desc ? &sw_desc->async_tx : NULL;
2933}
2934
2935
2936
2937
2938
2939static struct dma_async_tx_descriptor *ppc440spe_adma_prep_dma_pqzero_sum(
2940 struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
2941 unsigned int src_cnt, const unsigned char *scf, size_t len,
2942 enum sum_check_flags *pqres, unsigned long flags)
2943{
2944 struct ppc440spe_adma_chan *ppc440spe_chan;
2945 struct ppc440spe_adma_desc_slot *sw_desc, *iter;
2946 dma_addr_t pdest, qdest;
2947 int slot_cnt, slots_per_op, idst, dst_cnt;
2948
2949 ppc440spe_chan = to_ppc440spe_adma_chan(chan);
2950
2951 if (flags & DMA_PREP_PQ_DISABLE_P)
2952 pdest = 0;
2953 else
2954 pdest = pq[0];
2955
2956 if (flags & DMA_PREP_PQ_DISABLE_Q)
2957 qdest = 0;
2958 else
2959 qdest = pq[1];
2960
2961 ADMA_LL_DBG(prep_dma_pqzero_sum_dbg(ppc440spe_chan->device->id,
2962 src, src_cnt, scf));
2963
2964
2965
2966
2967 idst = dst_cnt = (pdest && qdest) ? 2 : 1;
2968
2969
2970
2971
2972 slot_cnt = src_cnt + dst_cnt * 2;
2973 slots_per_op = 1;
2974
2975 spin_lock_bh(&ppc440spe_chan->lock);
2976 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt,
2977 slots_per_op);
2978 if (sw_desc) {
2979 ppc440spe_desc_init_dma01pqzero_sum(sw_desc, dst_cnt, src_cnt);
2980
2981
2982 sw_desc->async_tx.flags = flags;
2983 list_for_each_entry(iter, &sw_desc->group_list, chain_node) {
2984 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan,
2985 len);
2986 iter->unmap_len = len;
2987 }
2988
2989 if (pdest) {
2990 struct dma_cdb *hw_desc;
2991 struct ppc440spe_adma_chan *chan;
2992
2993 iter = sw_desc->group_head;
2994 chan = to_ppc440spe_adma_chan(iter->async_tx.chan);
2995 memset(iter->hw_desc, 0, sizeof(struct dma_cdb));
2996 iter->hw_next = list_entry(iter->chain_node.next,
2997 struct ppc440spe_adma_desc_slot,
2998 chain_node);
2999 hw_desc = iter->hw_desc;
3000 hw_desc->opc = DMA_CDB_OPC_MV_SG1_SG2;
3001 iter->src_cnt = 0;
3002 iter->dst_cnt = 0;
3003 ppc440spe_desc_set_dest_addr(iter, chan, 0,
3004 ppc440spe_chan->pdest, 0);
3005 ppc440spe_desc_set_src_addr(iter, chan, 0, 0, pdest);
3006 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan,
3007 len);
3008 iter->unmap_len = 0;
3009
3010 pdest = ppc440spe_chan->pdest;
3011 }
3012 if (qdest) {
3013 struct dma_cdb *hw_desc;
3014 struct ppc440spe_adma_chan *chan;
3015
3016 iter = list_first_entry(&sw_desc->group_list,
3017 struct ppc440spe_adma_desc_slot,
3018 chain_node);
3019 chan = to_ppc440spe_adma_chan(iter->async_tx.chan);
3020
3021 if (pdest) {
3022 iter = list_entry(iter->chain_node.next,
3023 struct ppc440spe_adma_desc_slot,
3024 chain_node);
3025 }
3026
3027 memset(iter->hw_desc, 0, sizeof(struct dma_cdb));
3028 iter->hw_next = list_entry(iter->chain_node.next,
3029 struct ppc440spe_adma_desc_slot,
3030 chain_node);
3031 hw_desc = iter->hw_desc;
3032 hw_desc->opc = DMA_CDB_OPC_MV_SG1_SG2;
3033 iter->src_cnt = 0;
3034 iter->dst_cnt = 0;
3035 ppc440spe_desc_set_dest_addr(iter, chan, 0,
3036 ppc440spe_chan->qdest, 0);
3037 ppc440spe_desc_set_src_addr(iter, chan, 0, 0, qdest);
3038 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan,
3039 len);
3040 iter->unmap_len = 0;
3041
3042 qdest = ppc440spe_chan->qdest;
3043 }
3044
3045
3046 ppc440spe_adma_pqzero_sum_set_dest(sw_desc, pdest, qdest);
3047
3048
3049 idst = dst_cnt;
3050 list_for_each_entry_reverse(iter, &sw_desc->group_list,
3051 chain_node) {
3052
3053
3054
3055
3056
3057 if (idst == DMA_DEST_MAX_NUM) {
3058 if (idst == dst_cnt) {
3059 set_bit(PPC440SPE_DESC_QCHECK,
3060 &iter->flags);
3061 } else {
3062 set_bit(PPC440SPE_DESC_PCHECK,
3063 &iter->flags);
3064 }
3065 } else {
3066 if (qdest) {
3067 set_bit(PPC440SPE_DESC_QCHECK,
3068 &iter->flags);
3069 } else {
3070 set_bit(PPC440SPE_DESC_PCHECK,
3071 &iter->flags);
3072 }
3073 }
3074 iter->xor_check_result = pqres;
3075
3076
3077
3078
3079
3080 *iter->xor_check_result = 0;
3081 ppc440spe_desc_set_dcheck(iter, ppc440spe_chan,
3082 ppc440spe_qword);
3083
3084 if (!(--dst_cnt))
3085 break;
3086 }
3087
3088
3089 list_for_each_entry_continue_reverse(iter, &sw_desc->group_list,
3090 chain_node) {
3091 struct ppc440spe_adma_chan *chan;
3092 u32 mult_dst;
3093
3094 chan = to_ppc440spe_adma_chan(iter->async_tx.chan);
3095 ppc440spe_desc_set_src_addr(iter, chan, 0,
3096 DMA_CUED_XOR_HB,
3097 src[src_cnt - 1]);
3098 if (qdest) {
3099 mult_dst = (dst_cnt - 1) ? DMA_CDB_SG_DST2 :
3100 DMA_CDB_SG_DST1;
3101 ppc440spe_desc_set_src_mult(iter, chan,
3102 DMA_CUED_MULT1_OFF,
3103 mult_dst,
3104 scf[src_cnt - 1]);
3105 }
3106 if (!(--src_cnt))
3107 break;
3108 }
3109 }
3110 spin_unlock_bh(&ppc440spe_chan->lock);
3111 return sw_desc ? &sw_desc->async_tx : NULL;
3112}
3113
3114
3115
3116
3117
3118static struct dma_async_tx_descriptor *ppc440spe_adma_prep_dma_xor_zero_sum(
3119 struct dma_chan *chan, dma_addr_t *src, unsigned int src_cnt,
3120 size_t len, enum sum_check_flags *result, unsigned long flags)
3121{
3122 struct dma_async_tx_descriptor *tx;
3123 dma_addr_t pq[2];
3124
3125
3126 pq[0] = src[0];
3127 pq[1] = 0;
3128 flags |= DMA_PREP_PQ_DISABLE_Q;
3129
3130 tx = ppc440spe_adma_prep_dma_pqzero_sum(chan, pq, &src[1],
3131 src_cnt - 1, 0, len,
3132 result, flags);
3133 return tx;
3134}
3135
3136
3137
3138
3139static void ppc440spe_adma_set_dest(struct ppc440spe_adma_desc_slot *sw_desc,
3140 dma_addr_t addr, int index)
3141{
3142 struct ppc440spe_adma_chan *chan;
3143
3144 BUG_ON(index >= sw_desc->dst_cnt);
3145
3146 chan = to_ppc440spe_adma_chan(sw_desc->async_tx.chan);
3147
3148 switch (chan->device->id) {
3149 case PPC440SPE_DMA0_ID:
3150 case PPC440SPE_DMA1_ID:
3151
3152
3153
3154 ppc440spe_desc_set_dest_addr(sw_desc->group_head,
3155 chan, 0, addr, index);
3156 break;
3157 case PPC440SPE_XOR_ID:
3158 sw_desc = ppc440spe_get_group_entry(sw_desc, index);
3159 ppc440spe_desc_set_dest_addr(sw_desc,
3160 chan, 0, addr, index);
3161 break;
3162 }
3163}
3164
3165static void ppc440spe_adma_pq_zero_op(struct ppc440spe_adma_desc_slot *iter,
3166 struct ppc440spe_adma_chan *chan, dma_addr_t addr)
3167{
3168
3169
3170
3171
3172 ppc440spe_desc_set_dest_addr(iter, chan, DMA_CUED_XOR_BASE, addr, 0);
3173
3174
3175 ppc440spe_desc_set_src_addr(iter, chan, 0, DMA_CUED_XOR_HB, addr);
3176
3177
3178 ppc440spe_desc_set_src_mult(iter, chan, DMA_CUED_MULT1_OFF,
3179 DMA_CDB_SG_DST1, 1);
3180}
3181
3182
3183
3184
3185
3186static void ppc440spe_adma_pq_set_dest(struct ppc440spe_adma_desc_slot *sw_desc,
3187 dma_addr_t *addrs, unsigned long flags)
3188{
3189 struct ppc440spe_adma_desc_slot *iter;
3190 struct ppc440spe_adma_chan *chan;
3191 dma_addr_t paddr, qaddr;
3192 dma_addr_t addr = 0, ppath, qpath;
3193 int index = 0, i;
3194
3195 chan = to_ppc440spe_adma_chan(sw_desc->async_tx.chan);
3196
3197 if (flags & DMA_PREP_PQ_DISABLE_P)
3198 paddr = 0;
3199 else
3200 paddr = addrs[0];
3201
3202 if (flags & DMA_PREP_PQ_DISABLE_Q)
3203 qaddr = 0;
3204 else
3205 qaddr = addrs[1];
3206
3207 if (!paddr || !qaddr)
3208 addr = paddr ? paddr : qaddr;
3209
3210 switch (chan->device->id) {
3211 case PPC440SPE_DMA0_ID:
3212 case PPC440SPE_DMA1_ID:
3213
3214
3215
3216 if (!test_bit(PPC440SPE_DESC_RXOR, &sw_desc->flags)) {
3217
3218 if (test_bit(PPC440SPE_ZERO_P, &sw_desc->flags))
3219 index++;
3220 if (test_bit(PPC440SPE_ZERO_Q, &sw_desc->flags))
3221 index++;
3222
3223 iter = ppc440spe_get_group_entry(sw_desc, index);
3224 if (addr) {
3225
3226 list_for_each_entry_from(iter,
3227 &sw_desc->group_list, chain_node)
3228 ppc440spe_desc_set_dest_addr(iter, chan,
3229 DMA_CUED_XOR_BASE, addr, 0);
3230 } else {
3231
3232 list_for_each_entry_from(iter,
3233 &sw_desc->group_list, chain_node) {
3234 ppc440spe_desc_set_dest_addr(iter, chan,
3235 DMA_CUED_XOR_BASE, paddr, 0);
3236 ppc440spe_desc_set_dest_addr(iter, chan,
3237 DMA_CUED_XOR_BASE, qaddr, 1);
3238 }
3239 }
3240
3241 if (index) {
3242
3243
3244
3245 index = 0;
3246 if (test_bit(PPC440SPE_ZERO_P,
3247 &sw_desc->flags)) {
3248 iter = ppc440spe_get_group_entry(
3249 sw_desc, index++);
3250 ppc440spe_adma_pq_zero_op(iter, chan,
3251 paddr);
3252 }
3253
3254 if (test_bit(PPC440SPE_ZERO_Q,
3255 &sw_desc->flags)) {
3256 iter = ppc440spe_get_group_entry(
3257 sw_desc, index++);
3258 ppc440spe_adma_pq_zero_op(iter, chan,
3259 qaddr);
3260 }
3261
3262 return;
3263 }
3264 } else {
3265
3266
3267
3268
3269
3270 ppath = test_bit(PPC440SPE_ZERO_P, &sw_desc->flags) ?
3271 DMA_CUED_XOR_HB :
3272 DMA_CUED_XOR_BASE |
3273 (1 << DMA_CUED_MULT1_OFF);
3274 qpath = test_bit(PPC440SPE_ZERO_Q, &sw_desc->flags) ?
3275 DMA_CUED_XOR_HB :
3276 DMA_CUED_XOR_BASE |
3277 (1 << DMA_CUED_MULT1_OFF);
3278
3279
3280 iter = ppc440spe_get_group_entry(sw_desc, index++);
3281 ppc440spe_desc_set_dest_addr(iter, chan,
3282 paddr ? ppath : qpath,
3283 paddr ? paddr : qaddr, 0);
3284 if (!addr) {
3285
3286 iter = ppc440spe_get_group_entry(sw_desc,
3287 index++);
3288 ppc440spe_desc_set_dest_addr(iter, chan,
3289 qpath, qaddr, 0);
3290 }
3291
3292 if (test_bit(PPC440SPE_DESC_WXOR, &sw_desc->flags)) {
3293
3294
3295
3296 iter = ppc440spe_get_group_entry(sw_desc,
3297 index);
3298 if (addr) {
3299
3300 list_for_each_entry_from(iter,
3301 &sw_desc->group_list,
3302 chain_node)
3303 ppc440spe_desc_set_dest_addr(
3304 iter, chan,
3305 DMA_CUED_XOR_BASE,
3306 addr, 0);
3307
3308 } else {
3309
3310 list_for_each_entry_from(iter,
3311 &sw_desc->group_list,
3312 chain_node) {
3313 ppc440spe_desc_set_dest_addr(
3314 iter, chan,
3315 DMA_CUED_XOR_BASE,
3316 paddr, 0);
3317 ppc440spe_desc_set_dest_addr(
3318 iter, chan,
3319 DMA_CUED_XOR_BASE,
3320 qaddr, 1);
3321 }
3322 }
3323 }
3324
3325 }
3326 break;
3327
3328 case PPC440SPE_XOR_ID:
3329
3330
3331
3332
3333
3334 ppath = test_bit(PPC440SPE_ZERO_P, &sw_desc->flags) ?
3335 DMA_CUED_XOR_HB :
3336 DMA_CUED_XOR_BASE |
3337 (1 << DMA_CUED_MULT1_OFF);
3338
3339 qpath = test_bit(PPC440SPE_ZERO_Q, &sw_desc->flags) ?
3340 DMA_CUED_XOR_HB :
3341 DMA_CUED_XOR_BASE |
3342 (1 << DMA_CUED_MULT1_OFF);
3343
3344 iter = ppc440spe_get_group_entry(sw_desc, 0);
3345 for (i = 0; i < sw_desc->descs_per_op; i++) {
3346 ppc440spe_desc_set_dest_addr(iter, chan,
3347 paddr ? ppath : qpath,
3348 paddr ? paddr : qaddr, 0);
3349 iter = list_entry(iter->chain_node.next,
3350 struct ppc440spe_adma_desc_slot,
3351 chain_node);
3352 }
3353
3354 if (!addr) {
3355
3356 iter = ppc440spe_get_group_entry(sw_desc,
3357 sw_desc->descs_per_op);
3358 for (i = 0; i < sw_desc->descs_per_op; i++) {
3359 ppc440spe_desc_set_dest_addr(iter,
3360 chan, qpath, qaddr, 0);
3361 iter = list_entry(iter->chain_node.next,
3362 struct ppc440spe_adma_desc_slot,
3363 chain_node);
3364 }
3365 }
3366
3367 break;
3368 }
3369}
3370
3371
3372
3373
3374
3375static void ppc440spe_adma_pqzero_sum_set_dest(
3376 struct ppc440spe_adma_desc_slot *sw_desc,
3377 dma_addr_t paddr, dma_addr_t qaddr)
3378{
3379 struct ppc440spe_adma_desc_slot *iter, *end;
3380 struct ppc440spe_adma_chan *chan;
3381 dma_addr_t addr = 0;
3382 int idx;
3383
3384 chan = to_ppc440spe_adma_chan(sw_desc->async_tx.chan);
3385
3386
3387
3388
3389 idx = (paddr && qaddr) ? 2 : 1;
3390
3391 list_for_each_entry_reverse(end, &sw_desc->group_list,
3392 chain_node) {
3393 if (!(--idx))
3394 break;
3395 }
3396
3397 idx = (paddr && qaddr) ? 2 : 1;
3398 iter = ppc440spe_get_group_entry(sw_desc, idx);
3399
3400 if (paddr && qaddr) {
3401
3402 list_for_each_entry_from(iter, &sw_desc->group_list,
3403 chain_node) {
3404 if (unlikely(iter == end))
3405 break;
3406 ppc440spe_desc_set_dest_addr(iter, chan,
3407 DMA_CUED_XOR_BASE, paddr, 0);
3408 ppc440spe_desc_set_dest_addr(iter, chan,
3409 DMA_CUED_XOR_BASE, qaddr, 1);
3410 }
3411 } else {
3412
3413 addr = paddr ? paddr : qaddr;
3414 list_for_each_entry_from(iter, &sw_desc->group_list,
3415 chain_node) {
3416 if (unlikely(iter == end))
3417 break;
3418 ppc440spe_desc_set_dest_addr(iter, chan,
3419 DMA_CUED_XOR_BASE, addr, 0);
3420 }
3421 }
3422
3423
3424
3425
3426
3427 ppc440spe_desc_set_src_addr(end, chan, 0, 0, addr ? addr : paddr);
3428
3429 if (!addr) {
3430 end = list_entry(end->chain_node.next,
3431 struct ppc440spe_adma_desc_slot, chain_node);
3432 ppc440spe_desc_set_src_addr(end, chan, 0, 0, qaddr);
3433 }
3434}
3435
3436
3437
3438
3439static inline void ppc440spe_desc_set_xor_src_cnt(
3440 struct ppc440spe_adma_desc_slot *desc,
3441 int src_cnt)
3442{
3443 struct xor_cb *hw_desc = desc->hw_desc;
3444
3445 hw_desc->cbc &= ~XOR_CDCR_OAC_MSK;
3446 hw_desc->cbc |= src_cnt;
3447}
3448
3449
3450
3451
3452static void ppc440spe_adma_pq_set_src(struct ppc440spe_adma_desc_slot *sw_desc,
3453 dma_addr_t addr, int index)
3454{
3455 struct ppc440spe_adma_chan *chan;
3456 dma_addr_t haddr = 0;
3457 struct ppc440spe_adma_desc_slot *iter = NULL;
3458
3459 chan = to_ppc440spe_adma_chan(sw_desc->async_tx.chan);
3460
3461 switch (chan->device->id) {
3462 case PPC440SPE_DMA0_ID:
3463 case PPC440SPE_DMA1_ID:
3464
3465
3466 if (test_bit(PPC440SPE_DESC_RXOR, &sw_desc->flags)) {
3467
3468 int iskip = test_bit(PPC440SPE_DESC_RXOR12,
3469 &sw_desc->flags) ? 2 : 3;
3470
3471 if (index == 0) {
3472
3473
3474
3475
3476 if (test_bit(PPC440SPE_DESC_RXOR12,
3477 &sw_desc->flags))
3478 haddr = DMA_RXOR12 <<
3479 DMA_CUED_REGION_OFF;
3480 else if (test_bit(PPC440SPE_DESC_RXOR123,
3481 &sw_desc->flags))
3482 haddr = DMA_RXOR123 <<
3483 DMA_CUED_REGION_OFF;
3484 else if (test_bit(PPC440SPE_DESC_RXOR124,
3485 &sw_desc->flags))
3486 haddr = DMA_RXOR124 <<
3487 DMA_CUED_REGION_OFF;
3488 else if (test_bit(PPC440SPE_DESC_RXOR125,
3489 &sw_desc->flags))
3490 haddr = DMA_RXOR125 <<
3491 DMA_CUED_REGION_OFF;
3492 else
3493 BUG();
3494 haddr |= DMA_CUED_XOR_BASE;
3495 iter = ppc440spe_get_group_entry(sw_desc, 0);
3496 } else if (index < iskip) {
3497
3498
3499
3500
3501 iter = NULL;
3502 } else {
3503
3504
3505
3506 haddr = DMA_CUED_XOR_HB;
3507 iter = ppc440spe_get_group_entry(sw_desc,
3508 index - iskip + sw_desc->dst_cnt);
3509 }
3510 } else {
3511 int znum = 0;
3512
3513
3514
3515
3516 if (test_bit(PPC440SPE_ZERO_P, &sw_desc->flags))
3517 znum++;
3518 if (test_bit(PPC440SPE_ZERO_Q, &sw_desc->flags))
3519 znum++;
3520
3521 haddr = DMA_CUED_XOR_HB;
3522 iter = ppc440spe_get_group_entry(sw_desc,
3523 index + znum);
3524 }
3525
3526 if (likely(iter)) {
3527 ppc440spe_desc_set_src_addr(iter, chan, 0, haddr, addr);
3528
3529 if (!index &&
3530 test_bit(PPC440SPE_DESC_RXOR, &sw_desc->flags) &&
3531 sw_desc->dst_cnt == 2) {
3532
3533
3534
3535 iter = ppc440spe_get_group_entry(sw_desc, 1);
3536 ppc440spe_desc_set_src_addr(iter, chan, 0,
3537 haddr, addr);
3538 }
3539 }
3540 break;
3541
3542 case PPC440SPE_XOR_ID:
3543
3544 iter = sw_desc->group_head;
3545 if (iter->dst_cnt == 2) {
3546
3547 ppc440spe_adma_dma2rxor_set_src(iter, index, addr);
3548
3549
3550 iter = ppc440spe_get_group_entry(sw_desc,
3551 sw_desc->descs_per_op);
3552 }
3553 ppc440spe_adma_dma2rxor_set_src(iter, index, addr);
3554 break;
3555 }
3556}
3557
3558
3559
3560
3561static void ppc440spe_adma_memcpy_xor_set_src(
3562 struct ppc440spe_adma_desc_slot *sw_desc,
3563 dma_addr_t addr, int index)
3564{
3565 struct ppc440spe_adma_chan *chan;
3566
3567 chan = to_ppc440spe_adma_chan(sw_desc->async_tx.chan);
3568 sw_desc = sw_desc->group_head;
3569
3570 if (likely(sw_desc))
3571 ppc440spe_desc_set_src_addr(sw_desc, chan, index, 0, addr);
3572}
3573
3574
3575
3576
3577static void ppc440spe_adma_dma2rxor_inc_addr(
3578 struct ppc440spe_adma_desc_slot *desc,
3579 struct ppc440spe_rxor *cursor, int index, int src_cnt)
3580{
3581 cursor->addr_count++;
3582 if (index == src_cnt - 1) {
3583 ppc440spe_desc_set_xor_src_cnt(desc, cursor->addr_count);
3584 } else if (cursor->addr_count == XOR_MAX_OPS) {
3585 ppc440spe_desc_set_xor_src_cnt(desc, cursor->addr_count);
3586 cursor->addr_count = 0;
3587 cursor->desc_count++;
3588 }
3589}
3590
3591
3592
3593
3594static int ppc440spe_adma_dma2rxor_prep_src(
3595 struct ppc440spe_adma_desc_slot *hdesc,
3596 struct ppc440spe_rxor *cursor, int index,
3597 int src_cnt, u32 addr)
3598{
3599 int rval = 0;
3600 u32 sign;
3601 struct ppc440spe_adma_desc_slot *desc = hdesc;
3602 int i;
3603
3604 for (i = 0; i < cursor->desc_count; i++) {
3605 desc = list_entry(hdesc->chain_node.next,
3606 struct ppc440spe_adma_desc_slot,
3607 chain_node);
3608 }
3609
3610 switch (cursor->state) {
3611 case 0:
3612 if (addr == cursor->addrl + cursor->len) {
3613
3614 cursor->state = 1;
3615 cursor->xor_count++;
3616 if (index == src_cnt-1) {
3617 ppc440spe_rxor_set_region(desc,
3618 cursor->addr_count,
3619 DMA_RXOR12 << DMA_CUED_REGION_OFF);
3620 ppc440spe_adma_dma2rxor_inc_addr(
3621 desc, cursor, index, src_cnt);
3622 }
3623 } else if (cursor->addrl == addr + cursor->len) {
3624
3625 cursor->state = 1;
3626 cursor->xor_count++;
3627 set_bit(cursor->addr_count, &desc->reverse_flags[0]);
3628 if (index == src_cnt-1) {
3629 ppc440spe_rxor_set_region(desc,
3630 cursor->addr_count,
3631 DMA_RXOR12 << DMA_CUED_REGION_OFF);
3632 ppc440spe_adma_dma2rxor_inc_addr(
3633 desc, cursor, index, src_cnt);
3634 }
3635 } else {
3636 printk(KERN_ERR "Cannot build "
3637 "DMA2 RXOR command block.\n");
3638 BUG();
3639 }
3640 break;
3641 case 1:
3642 sign = test_bit(cursor->addr_count,
3643 desc->reverse_flags)
3644 ? -1 : 1;
3645 if (index == src_cnt-2 || (sign == -1
3646 && addr != cursor->addrl - 2*cursor->len)) {
3647 cursor->state = 0;
3648 cursor->xor_count = 1;
3649 cursor->addrl = addr;
3650 ppc440spe_rxor_set_region(desc,
3651 cursor->addr_count,
3652 DMA_RXOR12 << DMA_CUED_REGION_OFF);
3653 ppc440spe_adma_dma2rxor_inc_addr(
3654 desc, cursor, index, src_cnt);
3655 } else if (addr == cursor->addrl + 2*sign*cursor->len) {
3656 cursor->state = 2;
3657 cursor->xor_count = 0;
3658 ppc440spe_rxor_set_region(desc,
3659 cursor->addr_count,
3660 DMA_RXOR123 << DMA_CUED_REGION_OFF);
3661 if (index == src_cnt-1) {
3662 ppc440spe_adma_dma2rxor_inc_addr(
3663 desc, cursor, index, src_cnt);
3664 }
3665 } else if (addr == cursor->addrl + 3*cursor->len) {
3666 cursor->state = 2;
3667 cursor->xor_count = 0;
3668 ppc440spe_rxor_set_region(desc,
3669 cursor->addr_count,
3670 DMA_RXOR124 << DMA_CUED_REGION_OFF);
3671 if (index == src_cnt-1) {
3672 ppc440spe_adma_dma2rxor_inc_addr(
3673 desc, cursor, index, src_cnt);
3674 }
3675 } else if (addr == cursor->addrl + 4*cursor->len) {
3676 cursor->state = 2;
3677 cursor->xor_count = 0;
3678 ppc440spe_rxor_set_region(desc,
3679 cursor->addr_count,
3680 DMA_RXOR125 << DMA_CUED_REGION_OFF);
3681 if (index == src_cnt-1) {
3682 ppc440spe_adma_dma2rxor_inc_addr(
3683 desc, cursor, index, src_cnt);
3684 }
3685 } else {
3686 cursor->state = 0;
3687 cursor->xor_count = 1;
3688 cursor->addrl = addr;
3689 ppc440spe_rxor_set_region(desc,
3690 cursor->addr_count,
3691 DMA_RXOR12 << DMA_CUED_REGION_OFF);
3692 ppc440spe_adma_dma2rxor_inc_addr(
3693 desc, cursor, index, src_cnt);
3694 }
3695 break;
3696 case 2:
3697 cursor->state = 0;
3698 cursor->addrl = addr;
3699 cursor->xor_count++;
3700 if (index) {
3701 ppc440spe_adma_dma2rxor_inc_addr(
3702 desc, cursor, index, src_cnt);
3703 }
3704 break;
3705 }
3706
3707 return rval;
3708}
3709
3710
3711
3712
3713
3714static void ppc440spe_adma_dma2rxor_set_src(
3715 struct ppc440spe_adma_desc_slot *desc,
3716 int index, dma_addr_t addr)
3717{
3718 struct xor_cb *xcb = desc->hw_desc;
3719 int k = 0, op = 0, lop = 0;
3720
3721
3722 while (op <= index) {
3723 lop = op;
3724 if (k == XOR_MAX_OPS) {
3725 k = 0;
3726 desc = list_entry(desc->chain_node.next,
3727 struct ppc440spe_adma_desc_slot, chain_node);
3728 xcb = desc->hw_desc;
3729
3730 }
3731 if ((xcb->ops[k++].h & (DMA_RXOR12 << DMA_CUED_REGION_OFF)) ==
3732 (DMA_RXOR12 << DMA_CUED_REGION_OFF))
3733 op += 2;
3734 else
3735 op += 3;
3736 }
3737
3738 BUG_ON(k < 1);
3739
3740 if (test_bit(k-1, desc->reverse_flags)) {
3741
3742 if (index == op - 1)
3743 ppc440spe_rxor_set_src(desc, k - 1, addr);
3744 } else {
3745
3746 if (index == lop)
3747 ppc440spe_rxor_set_src(desc, k - 1, addr);
3748 }
3749}
3750
3751
3752
3753
3754
3755static void ppc440spe_adma_dma2rxor_set_mult(
3756 struct ppc440spe_adma_desc_slot *desc,
3757 int index, u8 mult)
3758{
3759 struct xor_cb *xcb = desc->hw_desc;
3760 int k = 0, op = 0, lop = 0;
3761
3762
3763 while (op <= index) {
3764 lop = op;
3765 if (k == XOR_MAX_OPS) {
3766 k = 0;
3767 desc = list_entry(desc->chain_node.next,
3768 struct ppc440spe_adma_desc_slot,
3769 chain_node);
3770 xcb = desc->hw_desc;
3771
3772 }
3773 if ((xcb->ops[k++].h & (DMA_RXOR12 << DMA_CUED_REGION_OFF)) ==
3774 (DMA_RXOR12 << DMA_CUED_REGION_OFF))
3775 op += 2;
3776 else
3777 op += 3;
3778 }
3779
3780 BUG_ON(k < 1);
3781 if (test_bit(k-1, desc->reverse_flags)) {
3782
3783 ppc440spe_rxor_set_mult(desc, k - 1, op - index - 1, mult);
3784 } else {
3785
3786 ppc440spe_rxor_set_mult(desc, k - 1, index - lop, mult);
3787 }
3788}
3789
3790
3791
3792
3793static void ppc440spe_init_rxor_cursor(struct ppc440spe_rxor *cursor)
3794{
3795 memset(cursor, 0, sizeof(struct ppc440spe_rxor));
3796 cursor->state = 2;
3797}
3798
3799
3800
3801
3802
3803static void ppc440spe_adma_pq_set_src_mult(
3804 struct ppc440spe_adma_desc_slot *sw_desc,
3805 unsigned char mult, int index, int dst_pos)
3806{
3807 struct ppc440spe_adma_chan *chan;
3808 u32 mult_idx, mult_dst;
3809 struct ppc440spe_adma_desc_slot *iter = NULL, *iter1 = NULL;
3810
3811 chan = to_ppc440spe_adma_chan(sw_desc->async_tx.chan);
3812
3813 switch (chan->device->id) {
3814 case PPC440SPE_DMA0_ID:
3815 case PPC440SPE_DMA1_ID:
3816 if (test_bit(PPC440SPE_DESC_RXOR, &sw_desc->flags)) {
3817 int region = test_bit(PPC440SPE_DESC_RXOR12,
3818 &sw_desc->flags) ? 2 : 3;
3819
3820 if (index < region) {
3821
3822 iter = ppc440spe_get_group_entry(sw_desc,
3823 sw_desc->dst_cnt - 1);
3824 if (sw_desc->dst_cnt == 2)
3825 iter1 = ppc440spe_get_group_entry(
3826 sw_desc, 0);
3827
3828 mult_idx = DMA_CUED_MULT1_OFF + (index << 3);
3829 mult_dst = DMA_CDB_SG_SRC;
3830 } else {
3831
3832 iter = ppc440spe_get_group_entry(sw_desc,
3833 index - region +
3834 sw_desc->dst_cnt);
3835 mult_idx = DMA_CUED_MULT1_OFF;
3836 mult_dst = dst_pos ? DMA_CDB_SG_DST2 :
3837 DMA_CDB_SG_DST1;
3838 }
3839 } else {
3840 int znum = 0;
3841
3842
3843
3844
3845
3846 if (test_bit(PPC440SPE_ZERO_P, &sw_desc->flags))
3847 znum++;
3848 if (test_bit(PPC440SPE_ZERO_Q, &sw_desc->flags))
3849 znum++;
3850
3851 iter = ppc440spe_get_group_entry(sw_desc, index + znum);
3852 mult_idx = DMA_CUED_MULT1_OFF;
3853 mult_dst = dst_pos ? DMA_CDB_SG_DST2 : DMA_CDB_SG_DST1;
3854 }
3855
3856 if (likely(iter)) {
3857 ppc440spe_desc_set_src_mult(iter, chan,
3858 mult_idx, mult_dst, mult);
3859
3860 if (unlikely(iter1)) {
3861
3862
3863
3864 ppc440spe_desc_set_src_mult(iter1, chan,
3865 mult_idx, mult_dst, 1);
3866 }
3867
3868 }
3869 break;
3870
3871 case PPC440SPE_XOR_ID:
3872 iter = sw_desc->group_head;
3873 if (sw_desc->dst_cnt == 2) {
3874
3875 ppc440spe_adma_dma2rxor_set_mult(iter, index, 1);
3876
3877
3878 iter = ppc440spe_get_group_entry(sw_desc,
3879 sw_desc->descs_per_op);
3880 }
3881 ppc440spe_adma_dma2rxor_set_mult(iter, index, mult);
3882 break;
3883 }
3884}
3885
3886
3887
3888
3889static void ppc440spe_adma_free_chan_resources(struct dma_chan *chan)
3890{
3891 struct ppc440spe_adma_chan *ppc440spe_chan;
3892 struct ppc440spe_adma_desc_slot *iter, *_iter;
3893 int in_use_descs = 0;
3894
3895 ppc440spe_chan = to_ppc440spe_adma_chan(chan);
3896 ppc440spe_adma_slot_cleanup(ppc440spe_chan);
3897
3898 spin_lock_bh(&ppc440spe_chan->lock);
3899 list_for_each_entry_safe(iter, _iter, &ppc440spe_chan->chain,
3900 chain_node) {
3901 in_use_descs++;
3902 list_del(&iter->chain_node);
3903 }
3904 list_for_each_entry_safe_reverse(iter, _iter,
3905 &ppc440spe_chan->all_slots, slot_node) {
3906 list_del(&iter->slot_node);
3907 kfree(iter);
3908 ppc440spe_chan->slots_allocated--;
3909 }
3910 ppc440spe_chan->last_used = NULL;
3911
3912 dev_dbg(ppc440spe_chan->device->common.dev,
3913 "ppc440spe adma%d %s slots_allocated %d\n",
3914 ppc440spe_chan->device->id,
3915 __func__, ppc440spe_chan->slots_allocated);
3916 spin_unlock_bh(&ppc440spe_chan->lock);
3917
3918
3919 if (in_use_descs > 1)
3920 printk(KERN_ERR "SPE: Freeing %d in use descriptors!\n",
3921 in_use_descs - 1);
3922}
3923
3924
3925
3926
3927
3928
3929
3930static enum dma_status ppc440spe_adma_tx_status(struct dma_chan *chan,
3931 dma_cookie_t cookie, struct dma_tx_state *txstate)
3932{
3933 struct ppc440spe_adma_chan *ppc440spe_chan;
3934 enum dma_status ret;
3935
3936 ppc440spe_chan = to_ppc440spe_adma_chan(chan);
3937 ret = dma_cookie_status(chan, cookie, txstate);
3938 if (ret == DMA_SUCCESS)
3939 return ret;
3940
3941 ppc440spe_adma_slot_cleanup(ppc440spe_chan);
3942
3943 return dma_cookie_status(chan, cookie, txstate);
3944}
3945
3946
3947
3948
3949static irqreturn_t ppc440spe_adma_eot_handler(int irq, void *data)
3950{
3951 struct ppc440spe_adma_chan *chan = data;
3952
3953 dev_dbg(chan->device->common.dev,
3954 "ppc440spe adma%d: %s\n", chan->device->id, __func__);
3955
3956 tasklet_schedule(&chan->irq_tasklet);
3957 ppc440spe_adma_device_clear_eot_status(chan);
3958
3959 return IRQ_HANDLED;
3960}
3961
3962
3963
3964
3965
3966static irqreturn_t ppc440spe_adma_err_handler(int irq, void *data)
3967{
3968 struct ppc440spe_adma_chan *chan = data;
3969
3970 dev_dbg(chan->device->common.dev,
3971 "ppc440spe adma%d: %s\n", chan->device->id, __func__);
3972
3973 tasklet_schedule(&chan->irq_tasklet);
3974 ppc440spe_adma_device_clear_eot_status(chan);
3975
3976 return IRQ_HANDLED;
3977}
3978
3979
3980
3981
3982static void ppc440spe_test_callback(void *unused)
3983{
3984 complete(&ppc440spe_r6_test_comp);
3985}
3986
3987
3988
3989
3990static void ppc440spe_adma_issue_pending(struct dma_chan *chan)
3991{
3992 struct ppc440spe_adma_chan *ppc440spe_chan;
3993
3994 ppc440spe_chan = to_ppc440spe_adma_chan(chan);
3995 dev_dbg(ppc440spe_chan->device->common.dev,
3996 "ppc440spe adma%d: %s %d \n", ppc440spe_chan->device->id,
3997 __func__, ppc440spe_chan->pending);
3998
3999 if (ppc440spe_chan->pending) {
4000 ppc440spe_chan->pending = 0;
4001 ppc440spe_chan_append(ppc440spe_chan);
4002 }
4003}
4004
4005
4006
4007
4008
4009
4010static void ppc440spe_chan_start_null_xor(struct ppc440spe_adma_chan *chan)
4011{
4012 struct ppc440spe_adma_desc_slot *sw_desc, *group_start;
4013 dma_cookie_t cookie;
4014 int slot_cnt, slots_per_op;
4015
4016 dev_dbg(chan->device->common.dev,
4017 "ppc440spe adma%d: %s\n", chan->device->id, __func__);
4018
4019 spin_lock_bh(&chan->lock);
4020 slot_cnt = ppc440spe_chan_xor_slot_count(0, 2, &slots_per_op);
4021 sw_desc = ppc440spe_adma_alloc_slots(chan, slot_cnt, slots_per_op);
4022 if (sw_desc) {
4023 group_start = sw_desc->group_head;
4024 list_splice_init(&sw_desc->group_list, &chan->chain);
4025 async_tx_ack(&sw_desc->async_tx);
4026 ppc440spe_desc_init_null_xor(group_start);
4027
4028 cookie = dma_cookie_assign(&sw_desc->async_tx);
4029
4030
4031
4032
4033 chan->common.completed_cookie = cookie - 1;
4034
4035
4036 BUG_ON(ppc440spe_chan_is_busy(chan));
4037
4038
4039 ppc440spe_chan_set_first_xor_descriptor(chan, sw_desc);
4040
4041
4042 ppc440spe_chan_run(chan);
4043 } else
4044 printk(KERN_ERR "ppc440spe adma%d"
4045 " failed to allocate null descriptor\n",
4046 chan->device->id);
4047 spin_unlock_bh(&chan->lock);
4048}
4049
4050
4051
4052
4053
4054
4055
4056static int ppc440spe_test_raid6(struct ppc440spe_adma_chan *chan)
4057{
4058 struct ppc440spe_adma_desc_slot *sw_desc, *iter;
4059 struct page *pg;
4060 char *a;
4061 dma_addr_t dma_addr, addrs[2];
4062 unsigned long op = 0;
4063 int rval = 0;
4064
4065 set_bit(PPC440SPE_DESC_WXOR, &op);
4066
4067 pg = alloc_page(GFP_KERNEL);
4068 if (!pg)
4069 return -ENOMEM;
4070
4071 spin_lock_bh(&chan->lock);
4072 sw_desc = ppc440spe_adma_alloc_slots(chan, 1, 1);
4073 if (sw_desc) {
4074
4075 ppc440spe_desc_init_dma01pq(sw_desc, 1, 1, 1, op);
4076 list_for_each_entry(iter, &sw_desc->group_list, chain_node) {
4077 ppc440spe_desc_set_byte_count(iter, chan, PAGE_SIZE);
4078 iter->unmap_len = PAGE_SIZE;
4079 }
4080 } else {
4081 rval = -EFAULT;
4082 spin_unlock_bh(&chan->lock);
4083 goto exit;
4084 }
4085 spin_unlock_bh(&chan->lock);
4086
4087
4088 memset(page_address(pg), 0xFF, PAGE_SIZE);
4089 dma_addr = dma_map_page(chan->device->dev, pg, 0,
4090 PAGE_SIZE, DMA_BIDIRECTIONAL);
4091
4092
4093 ppc440spe_adma_pq_set_src(sw_desc, dma_addr, 0);
4094 ppc440spe_adma_pq_set_src_mult(sw_desc, 1, 0, 0);
4095 addrs[0] = dma_addr;
4096 addrs[1] = 0;
4097 ppc440spe_adma_pq_set_dest(sw_desc, addrs, DMA_PREP_PQ_DISABLE_Q);
4098
4099 async_tx_ack(&sw_desc->async_tx);
4100 sw_desc->async_tx.callback = ppc440spe_test_callback;
4101 sw_desc->async_tx.callback_param = NULL;
4102
4103 init_completion(&ppc440spe_r6_test_comp);
4104
4105 ppc440spe_adma_tx_submit(&sw_desc->async_tx);
4106 ppc440spe_adma_issue_pending(&chan->common);
4107
4108 wait_for_completion(&ppc440spe_r6_test_comp);
4109
4110
4111 a = page_address(pg);
4112 if ((*(u32 *)a) == 0 && memcmp(a, a+4, PAGE_SIZE-4) == 0) {
4113
4114 rval = 0;
4115 } else {
4116
4117 rval = -EINVAL;
4118 }
4119exit:
4120 __free_page(pg);
4121 return rval;
4122}
4123
4124static void ppc440spe_adma_init_capabilities(struct ppc440spe_adma_device *adev)
4125{
4126 switch (adev->id) {
4127 case PPC440SPE_DMA0_ID:
4128 case PPC440SPE_DMA1_ID:
4129 dma_cap_set(DMA_MEMCPY, adev->common.cap_mask);
4130 dma_cap_set(DMA_INTERRUPT, adev->common.cap_mask);
4131 dma_cap_set(DMA_MEMSET, adev->common.cap_mask);
4132 dma_cap_set(DMA_PQ, adev->common.cap_mask);
4133 dma_cap_set(DMA_PQ_VAL, adev->common.cap_mask);
4134 dma_cap_set(DMA_XOR_VAL, adev->common.cap_mask);
4135 break;
4136 case PPC440SPE_XOR_ID:
4137 dma_cap_set(DMA_XOR, adev->common.cap_mask);
4138 dma_cap_set(DMA_PQ, adev->common.cap_mask);
4139 dma_cap_set(DMA_INTERRUPT, adev->common.cap_mask);
4140 adev->common.cap_mask = adev->common.cap_mask;
4141 break;
4142 }
4143
4144
4145 adev->common.device_alloc_chan_resources =
4146 ppc440spe_adma_alloc_chan_resources;
4147 adev->common.device_free_chan_resources =
4148 ppc440spe_adma_free_chan_resources;
4149 adev->common.device_tx_status = ppc440spe_adma_tx_status;
4150 adev->common.device_issue_pending = ppc440spe_adma_issue_pending;
4151
4152
4153 if (dma_has_cap(DMA_MEMCPY, adev->common.cap_mask)) {
4154 adev->common.device_prep_dma_memcpy =
4155 ppc440spe_adma_prep_dma_memcpy;
4156 }
4157 if (dma_has_cap(DMA_MEMSET, adev->common.cap_mask)) {
4158 adev->common.device_prep_dma_memset =
4159 ppc440spe_adma_prep_dma_memset;
4160 }
4161 if (dma_has_cap(DMA_XOR, adev->common.cap_mask)) {
4162 adev->common.max_xor = XOR_MAX_OPS;
4163 adev->common.device_prep_dma_xor =
4164 ppc440spe_adma_prep_dma_xor;
4165 }
4166 if (dma_has_cap(DMA_PQ, adev->common.cap_mask)) {
4167 switch (adev->id) {
4168 case PPC440SPE_DMA0_ID:
4169 dma_set_maxpq(&adev->common,
4170 DMA0_FIFO_SIZE / sizeof(struct dma_cdb), 0);
4171 break;
4172 case PPC440SPE_DMA1_ID:
4173 dma_set_maxpq(&adev->common,
4174 DMA1_FIFO_SIZE / sizeof(struct dma_cdb), 0);
4175 break;
4176 case PPC440SPE_XOR_ID:
4177 adev->common.max_pq = XOR_MAX_OPS * 3;
4178 break;
4179 }
4180 adev->common.device_prep_dma_pq =
4181 ppc440spe_adma_prep_dma_pq;
4182 }
4183 if (dma_has_cap(DMA_PQ_VAL, adev->common.cap_mask)) {
4184 switch (adev->id) {
4185 case PPC440SPE_DMA0_ID:
4186 adev->common.max_pq = DMA0_FIFO_SIZE /
4187 sizeof(struct dma_cdb);
4188 break;
4189 case PPC440SPE_DMA1_ID:
4190 adev->common.max_pq = DMA1_FIFO_SIZE /
4191 sizeof(struct dma_cdb);
4192 break;
4193 }
4194 adev->common.device_prep_dma_pq_val =
4195 ppc440spe_adma_prep_dma_pqzero_sum;
4196 }
4197 if (dma_has_cap(DMA_XOR_VAL, adev->common.cap_mask)) {
4198 switch (adev->id) {
4199 case PPC440SPE_DMA0_ID:
4200 adev->common.max_xor = DMA0_FIFO_SIZE /
4201 sizeof(struct dma_cdb);
4202 break;
4203 case PPC440SPE_DMA1_ID:
4204 adev->common.max_xor = DMA1_FIFO_SIZE /
4205 sizeof(struct dma_cdb);
4206 break;
4207 }
4208 adev->common.device_prep_dma_xor_val =
4209 ppc440spe_adma_prep_dma_xor_zero_sum;
4210 }
4211 if (dma_has_cap(DMA_INTERRUPT, adev->common.cap_mask)) {
4212 adev->common.device_prep_dma_interrupt =
4213 ppc440spe_adma_prep_dma_interrupt;
4214 }
4215 pr_info("%s: AMCC(R) PPC440SP(E) ADMA Engine: "
4216 "( %s%s%s%s%s%s%s)\n",
4217 dev_name(adev->dev),
4218 dma_has_cap(DMA_PQ, adev->common.cap_mask) ? "pq " : "",
4219 dma_has_cap(DMA_PQ_VAL, adev->common.cap_mask) ? "pq_val " : "",
4220 dma_has_cap(DMA_XOR, adev->common.cap_mask) ? "xor " : "",
4221 dma_has_cap(DMA_XOR_VAL, adev->common.cap_mask) ? "xor_val " : "",
4222 dma_has_cap(DMA_MEMCPY, adev->common.cap_mask) ? "memcpy " : "",
4223 dma_has_cap(DMA_MEMSET, adev->common.cap_mask) ? "memset " : "",
4224 dma_has_cap(DMA_INTERRUPT, adev->common.cap_mask) ? "intr " : "");
4225}
4226
4227static int ppc440spe_adma_setup_irqs(struct ppc440spe_adma_device *adev,
4228 struct ppc440spe_adma_chan *chan,
4229 int *initcode)
4230{
4231 struct platform_device *ofdev;
4232 struct device_node *np;
4233 int ret;
4234
4235 ofdev = container_of(adev->dev, struct platform_device, dev);
4236 np = ofdev->dev.of_node;
4237 if (adev->id != PPC440SPE_XOR_ID) {
4238 adev->err_irq = irq_of_parse_and_map(np, 1);
4239 if (adev->err_irq == NO_IRQ) {
4240 dev_warn(adev->dev, "no err irq resource?\n");
4241 *initcode = PPC_ADMA_INIT_IRQ2;
4242 adev->err_irq = -ENXIO;
4243 } else
4244 atomic_inc(&ppc440spe_adma_err_irq_ref);
4245 } else {
4246 adev->err_irq = -ENXIO;
4247 }
4248
4249 adev->irq = irq_of_parse_and_map(np, 0);
4250 if (adev->irq == NO_IRQ) {
4251 dev_err(adev->dev, "no irq resource\n");
4252 *initcode = PPC_ADMA_INIT_IRQ1;
4253 ret = -ENXIO;
4254 goto err_irq_map;
4255 }
4256 dev_dbg(adev->dev, "irq %d, err irq %d\n",
4257 adev->irq, adev->err_irq);
4258
4259 ret = request_irq(adev->irq, ppc440spe_adma_eot_handler,
4260 0, dev_driver_string(adev->dev), chan);
4261 if (ret) {
4262 dev_err(adev->dev, "can't request irq %d\n",
4263 adev->irq);
4264 *initcode = PPC_ADMA_INIT_IRQ1;
4265 ret = -EIO;
4266 goto err_req1;
4267 }
4268
4269
4270
4271
4272 if (adev->err_irq > 0) {
4273
4274 ret = request_irq(adev->err_irq,
4275 ppc440spe_adma_err_handler,
4276 IRQF_SHARED,
4277 dev_driver_string(adev->dev),
4278 chan);
4279 if (ret) {
4280 dev_err(adev->dev, "can't request irq %d\n",
4281 adev->err_irq);
4282 *initcode = PPC_ADMA_INIT_IRQ2;
4283 ret = -EIO;
4284 goto err_req2;
4285 }
4286 }
4287
4288 if (adev->id == PPC440SPE_XOR_ID) {
4289
4290 iowrite32be(XOR_IE_CBCIE_BIT | XOR_IE_ICBIE_BIT |
4291 XOR_IE_ICIE_BIT | XOR_IE_RPTIE_BIT,
4292 &adev->xor_reg->ier);
4293 } else {
4294 u32 mask, enable;
4295
4296 np = of_find_compatible_node(NULL, NULL, "ibm,i2o-440spe");
4297 if (!np) {
4298 pr_err("%s: can't find I2O device tree node\n",
4299 __func__);
4300 ret = -ENODEV;
4301 goto err_req2;
4302 }
4303 adev->i2o_reg = of_iomap(np, 0);
4304 if (!adev->i2o_reg) {
4305 pr_err("%s: failed to map I2O registers\n", __func__);
4306 of_node_put(np);
4307 ret = -EINVAL;
4308 goto err_req2;
4309 }
4310 of_node_put(np);
4311
4312
4313
4314 enable = (adev->id == PPC440SPE_DMA0_ID) ?
4315 ~(I2O_IOPIM_P0SNE | I2O_IOPIM_P0EM) :
4316 ~(I2O_IOPIM_P1SNE | I2O_IOPIM_P1EM);
4317 mask = ioread32(&adev->i2o_reg->iopim) & enable;
4318 iowrite32(mask, &adev->i2o_reg->iopim);
4319 }
4320 return 0;
4321
4322err_req2:
4323 free_irq(adev->irq, chan);
4324err_req1:
4325 irq_dispose_mapping(adev->irq);
4326err_irq_map:
4327 if (adev->err_irq > 0) {
4328 if (atomic_dec_and_test(&ppc440spe_adma_err_irq_ref))
4329 irq_dispose_mapping(adev->err_irq);
4330 }
4331 return ret;
4332}
4333
4334static void ppc440spe_adma_release_irqs(struct ppc440spe_adma_device *adev,
4335 struct ppc440spe_adma_chan *chan)
4336{
4337 u32 mask, disable;
4338
4339 if (adev->id == PPC440SPE_XOR_ID) {
4340
4341 mask = ioread32be(&adev->xor_reg->ier);
4342 mask &= ~(XOR_IE_CBCIE_BIT | XOR_IE_ICBIE_BIT |
4343 XOR_IE_ICIE_BIT | XOR_IE_RPTIE_BIT);
4344 iowrite32be(mask, &adev->xor_reg->ier);
4345 } else {
4346
4347 disable = (adev->id == PPC440SPE_DMA0_ID) ?
4348 (I2O_IOPIM_P0SNE | I2O_IOPIM_P0EM) :
4349 (I2O_IOPIM_P1SNE | I2O_IOPIM_P1EM);
4350 mask = ioread32(&adev->i2o_reg->iopim) | disable;
4351 iowrite32(mask, &adev->i2o_reg->iopim);
4352 }
4353 free_irq(adev->irq, chan);
4354 irq_dispose_mapping(adev->irq);
4355 if (adev->err_irq > 0) {
4356 free_irq(adev->err_irq, chan);
4357 if (atomic_dec_and_test(&ppc440spe_adma_err_irq_ref)) {
4358 irq_dispose_mapping(adev->err_irq);
4359 iounmap(adev->i2o_reg);
4360 }
4361 }
4362}
4363
4364
4365
4366
4367static int ppc440spe_adma_probe(struct platform_device *ofdev)
4368{
4369 struct device_node *np = ofdev->dev.of_node;
4370 struct resource res;
4371 struct ppc440spe_adma_device *adev;
4372 struct ppc440spe_adma_chan *chan;
4373 struct ppc_dma_chan_ref *ref, *_ref;
4374 int ret = 0, initcode = PPC_ADMA_INIT_OK;
4375 const u32 *idx;
4376 int len;
4377 void *regs;
4378 u32 id, pool_size;
4379
4380 if (of_device_is_compatible(np, "amcc,xor-accelerator")) {
4381 id = PPC440SPE_XOR_ID;
4382
4383
4384
4385
4386 pool_size = PAGE_SIZE << 1;
4387 } else {
4388
4389 idx = of_get_property(np, "cell-index", &len);
4390 if (!idx || (len != sizeof(u32))) {
4391 dev_err(&ofdev->dev, "Device node %s has missing "
4392 "or invalid cell-index property\n",
4393 np->full_name);
4394 return -EINVAL;
4395 }
4396 id = *idx;
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408 pool_size = (id == PPC440SPE_DMA0_ID) ?
4409 DMA0_FIFO_SIZE : DMA1_FIFO_SIZE;
4410 pool_size <<= 2;
4411 }
4412
4413 if (of_address_to_resource(np, 0, &res)) {
4414 dev_err(&ofdev->dev, "failed to get memory resource\n");
4415 initcode = PPC_ADMA_INIT_MEMRES;
4416 ret = -ENODEV;
4417 goto out;
4418 }
4419
4420 if (!request_mem_region(res.start, resource_size(&res),
4421 dev_driver_string(&ofdev->dev))) {
4422 dev_err(&ofdev->dev, "failed to request memory region %pR\n",
4423 &res);
4424 initcode = PPC_ADMA_INIT_MEMREG;
4425 ret = -EBUSY;
4426 goto out;
4427 }
4428
4429
4430 adev = kzalloc(sizeof(*adev), GFP_KERNEL);
4431 if (!adev) {
4432 dev_err(&ofdev->dev, "failed to allocate device\n");
4433 initcode = PPC_ADMA_INIT_ALLOC;
4434 ret = -ENOMEM;
4435 goto err_adev_alloc;
4436 }
4437
4438 adev->id = id;
4439 adev->pool_size = pool_size;
4440
4441 adev->dma_desc_pool_virt = dma_alloc_coherent(&ofdev->dev,
4442 adev->pool_size, &adev->dma_desc_pool,
4443 GFP_KERNEL);
4444 if (adev->dma_desc_pool_virt == NULL) {
4445 dev_err(&ofdev->dev, "failed to allocate %d bytes of coherent "
4446 "memory for hardware descriptors\n",
4447 adev->pool_size);
4448 initcode = PPC_ADMA_INIT_COHERENT;
4449 ret = -ENOMEM;
4450 goto err_dma_alloc;
4451 }
4452 dev_dbg(&ofdev->dev, "allocated descriptor pool virt 0x%p phys 0x%llx\n",
4453 adev->dma_desc_pool_virt, (u64)adev->dma_desc_pool);
4454
4455 regs = ioremap(res.start, resource_size(&res));
4456 if (!regs) {
4457 dev_err(&ofdev->dev, "failed to ioremap regs!\n");
4458 goto err_regs_alloc;
4459 }
4460
4461 if (adev->id == PPC440SPE_XOR_ID) {
4462 adev->xor_reg = regs;
4463
4464 iowrite32be(XOR_CRSR_XASR_BIT, &adev->xor_reg->crsr);
4465 iowrite32be(XOR_CRSR_64BA_BIT, &adev->xor_reg->crrr);
4466 } else {
4467 size_t fifo_size = (adev->id == PPC440SPE_DMA0_ID) ?
4468 DMA0_FIFO_SIZE : DMA1_FIFO_SIZE;
4469 adev->dma_reg = regs;
4470
4471
4472
4473
4474
4475 iowrite32(DMA_FIFO_ENABLE | ((fifo_size >> 3) - 2),
4476 &adev->dma_reg->fsiz);
4477
4478 iowrite32(DMA_CFG_DXEPR_HP | DMA_CFG_DFMPP_HP | DMA_CFG_FALGN,
4479 &adev->dma_reg->cfg);
4480
4481 iowrite32(~0, &adev->dma_reg->dsts);
4482 }
4483
4484 adev->dev = &ofdev->dev;
4485 adev->common.dev = &ofdev->dev;
4486 INIT_LIST_HEAD(&adev->common.channels);
4487 dev_set_drvdata(&ofdev->dev, adev);
4488
4489
4490 chan = kzalloc(sizeof(*chan), GFP_KERNEL);
4491 if (!chan) {
4492 dev_err(&ofdev->dev, "can't allocate channel structure\n");
4493 initcode = PPC_ADMA_INIT_CHANNEL;
4494 ret = -ENOMEM;
4495 goto err_chan_alloc;
4496 }
4497
4498 spin_lock_init(&chan->lock);
4499 INIT_LIST_HEAD(&chan->chain);
4500 INIT_LIST_HEAD(&chan->all_slots);
4501 chan->device = adev;
4502 chan->common.device = &adev->common;
4503 dma_cookie_init(&chan->common);
4504 list_add_tail(&chan->common.device_node, &adev->common.channels);
4505 tasklet_init(&chan->irq_tasklet, ppc440spe_adma_tasklet,
4506 (unsigned long)chan);
4507
4508
4509
4510
4511 if (adev->id != PPC440SPE_XOR_ID) {
4512 chan->pdest_page = alloc_page(GFP_KERNEL);
4513 chan->qdest_page = alloc_page(GFP_KERNEL);
4514 if (!chan->pdest_page ||
4515 !chan->qdest_page) {
4516 if (chan->pdest_page)
4517 __free_page(chan->pdest_page);
4518 if (chan->qdest_page)
4519 __free_page(chan->qdest_page);
4520 ret = -ENOMEM;
4521 goto err_page_alloc;
4522 }
4523 chan->pdest = dma_map_page(&ofdev->dev, chan->pdest_page, 0,
4524 PAGE_SIZE, DMA_BIDIRECTIONAL);
4525 chan->qdest = dma_map_page(&ofdev->dev, chan->qdest_page, 0,
4526 PAGE_SIZE, DMA_BIDIRECTIONAL);
4527 }
4528
4529 ref = kmalloc(sizeof(*ref), GFP_KERNEL);
4530 if (ref) {
4531 ref->chan = &chan->common;
4532 INIT_LIST_HEAD(&ref->node);
4533 list_add_tail(&ref->node, &ppc440spe_adma_chan_list);
4534 } else {
4535 dev_err(&ofdev->dev, "failed to allocate channel reference!\n");
4536 ret = -ENOMEM;
4537 goto err_ref_alloc;
4538 }
4539
4540 ret = ppc440spe_adma_setup_irqs(adev, chan, &initcode);
4541 if (ret)
4542 goto err_irq;
4543
4544 ppc440spe_adma_init_capabilities(adev);
4545
4546 ret = dma_async_device_register(&adev->common);
4547 if (ret) {
4548 initcode = PPC_ADMA_INIT_REGISTER;
4549 dev_err(&ofdev->dev, "failed to register dma device\n");
4550 goto err_dev_reg;
4551 }
4552
4553 goto out;
4554
4555err_dev_reg:
4556 ppc440spe_adma_release_irqs(adev, chan);
4557err_irq:
4558 list_for_each_entry_safe(ref, _ref, &ppc440spe_adma_chan_list, node) {
4559 if (chan == to_ppc440spe_adma_chan(ref->chan)) {
4560 list_del(&ref->node);
4561 kfree(ref);
4562 }
4563 }
4564err_ref_alloc:
4565 if (adev->id != PPC440SPE_XOR_ID) {
4566 dma_unmap_page(&ofdev->dev, chan->pdest,
4567 PAGE_SIZE, DMA_BIDIRECTIONAL);
4568 dma_unmap_page(&ofdev->dev, chan->qdest,
4569 PAGE_SIZE, DMA_BIDIRECTIONAL);
4570 __free_page(chan->pdest_page);
4571 __free_page(chan->qdest_page);
4572 }
4573err_page_alloc:
4574 kfree(chan);
4575err_chan_alloc:
4576 if (adev->id == PPC440SPE_XOR_ID)
4577 iounmap(adev->xor_reg);
4578 else
4579 iounmap(adev->dma_reg);
4580err_regs_alloc:
4581 dma_free_coherent(adev->dev, adev->pool_size,
4582 adev->dma_desc_pool_virt,
4583 adev->dma_desc_pool);
4584err_dma_alloc:
4585 kfree(adev);
4586err_adev_alloc:
4587 release_mem_region(res.start, resource_size(&res));
4588out:
4589 if (id < PPC440SPE_ADMA_ENGINES_NUM)
4590 ppc440spe_adma_devices[id] = initcode;
4591
4592 return ret;
4593}
4594
4595
4596
4597
4598static int ppc440spe_adma_remove(struct platform_device *ofdev)
4599{
4600 struct ppc440spe_adma_device *adev = dev_get_drvdata(&ofdev->dev);
4601 struct device_node *np = ofdev->dev.of_node;
4602 struct resource res;
4603 struct dma_chan *chan, *_chan;
4604 struct ppc_dma_chan_ref *ref, *_ref;
4605 struct ppc440spe_adma_chan *ppc440spe_chan;
4606
4607 dev_set_drvdata(&ofdev->dev, NULL);
4608 if (adev->id < PPC440SPE_ADMA_ENGINES_NUM)
4609 ppc440spe_adma_devices[adev->id] = -1;
4610
4611 dma_async_device_unregister(&adev->common);
4612
4613 list_for_each_entry_safe(chan, _chan, &adev->common.channels,
4614 device_node) {
4615 ppc440spe_chan = to_ppc440spe_adma_chan(chan);
4616 ppc440spe_adma_release_irqs(adev, ppc440spe_chan);
4617 tasklet_kill(&ppc440spe_chan->irq_tasklet);
4618 if (adev->id != PPC440SPE_XOR_ID) {
4619 dma_unmap_page(&ofdev->dev, ppc440spe_chan->pdest,
4620 PAGE_SIZE, DMA_BIDIRECTIONAL);
4621 dma_unmap_page(&ofdev->dev, ppc440spe_chan->qdest,
4622 PAGE_SIZE, DMA_BIDIRECTIONAL);
4623 __free_page(ppc440spe_chan->pdest_page);
4624 __free_page(ppc440spe_chan->qdest_page);
4625 }
4626 list_for_each_entry_safe(ref, _ref, &ppc440spe_adma_chan_list,
4627 node) {
4628 if (ppc440spe_chan ==
4629 to_ppc440spe_adma_chan(ref->chan)) {
4630 list_del(&ref->node);
4631 kfree(ref);
4632 }
4633 }
4634 list_del(&chan->device_node);
4635 kfree(ppc440spe_chan);
4636 }
4637
4638 dma_free_coherent(adev->dev, adev->pool_size,
4639 adev->dma_desc_pool_virt, adev->dma_desc_pool);
4640 if (adev->id == PPC440SPE_XOR_ID)
4641 iounmap(adev->xor_reg);
4642 else
4643 iounmap(adev->dma_reg);
4644 of_address_to_resource(np, 0, &res);
4645 release_mem_region(res.start, resource_size(&res));
4646 kfree(adev);
4647 return 0;
4648}
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660static ssize_t show_ppc440spe_devices(struct device_driver *dev, char *buf)
4661{
4662 ssize_t size = 0;
4663 int i;
4664
4665 for (i = 0; i < PPC440SPE_ADMA_ENGINES_NUM; i++) {
4666 if (ppc440spe_adma_devices[i] == -1)
4667 continue;
4668 size += snprintf(buf + size, PAGE_SIZE - size,
4669 "PPC440SP(E)-ADMA.%d: %s\n", i,
4670 ppc_adma_errors[ppc440spe_adma_devices[i]]);
4671 }
4672 return size;
4673}
4674
4675static ssize_t show_ppc440spe_r6enable(struct device_driver *dev, char *buf)
4676{
4677 return snprintf(buf, PAGE_SIZE,
4678 "PPC440SP(e) RAID-6 capabilities are %sABLED.\n",
4679 ppc440spe_r6_enabled ? "EN" : "DIS");
4680}
4681
4682static ssize_t store_ppc440spe_r6enable(struct device_driver *dev,
4683 const char *buf, size_t count)
4684{
4685 unsigned long val;
4686
4687 if (!count || count > 11)
4688 return -EINVAL;
4689
4690 if (!ppc440spe_r6_tchan)
4691 return -EFAULT;
4692
4693
4694 sscanf(buf, "%lx", &val);
4695 dcr_write(ppc440spe_mq_dcr_host, DCRN_MQ0_XORBA, val);
4696 isync();
4697
4698
4699 if (ppc440spe_test_raid6(ppc440spe_r6_tchan) == 0) {
4700 pr_info("PPC440SP(e) RAID-6 has been activated "
4701 "successfully\n");
4702 ppc440spe_r6_enabled = 1;
4703 } else {
4704 pr_info("PPC440SP(e) RAID-6 hasn't been activated!"
4705 " Error key ?\n");
4706 ppc440spe_r6_enabled = 0;
4707 }
4708 return count;
4709}
4710
4711static ssize_t show_ppc440spe_r6poly(struct device_driver *dev, char *buf)
4712{
4713 ssize_t size = 0;
4714 u32 reg;
4715
4716#ifdef CONFIG_440SP
4717
4718 reg = 0x4d;
4719#else
4720 reg = dcr_read(ppc440spe_mq_dcr_host, DCRN_MQ0_CFBHL);
4721 reg >>= MQ0_CFBHL_POLY;
4722 reg &= 0xFF;
4723#endif
4724
4725 size = snprintf(buf, PAGE_SIZE, "PPC440SP(e) RAID-6 driver "
4726 "uses 0x1%02x polynomial.\n", reg);
4727 return size;
4728}
4729
4730static ssize_t store_ppc440spe_r6poly(struct device_driver *dev,
4731 const char *buf, size_t count)
4732{
4733 unsigned long reg, val;
4734
4735#ifdef CONFIG_440SP
4736
4737 return -EINVAL;
4738#endif
4739
4740 if (!count || count > 6)
4741 return -EINVAL;
4742
4743
4744 sscanf(buf, "%lx", &val);
4745
4746 if (val & ~0x1FF)
4747 return -EINVAL;
4748
4749 val &= 0xFF;
4750 reg = dcr_read(ppc440spe_mq_dcr_host, DCRN_MQ0_CFBHL);
4751 reg &= ~(0xFF << MQ0_CFBHL_POLY);
4752 reg |= val << MQ0_CFBHL_POLY;
4753 dcr_write(ppc440spe_mq_dcr_host, DCRN_MQ0_CFBHL, reg);
4754
4755 return count;
4756}
4757
4758static DRIVER_ATTR(devices, S_IRUGO, show_ppc440spe_devices, NULL);
4759static DRIVER_ATTR(enable, S_IRUGO | S_IWUSR, show_ppc440spe_r6enable,
4760 store_ppc440spe_r6enable);
4761static DRIVER_ATTR(poly, S_IRUGO | S_IWUSR, show_ppc440spe_r6poly,
4762 store_ppc440spe_r6poly);
4763
4764
4765
4766
4767
4768
4769static int ppc440spe_configure_raid_devices(void)
4770{
4771 struct device_node *np;
4772 struct resource i2o_res;
4773 struct i2o_regs __iomem *i2o_reg;
4774 dcr_host_t i2o_dcr_host;
4775 unsigned int dcr_base, dcr_len;
4776 int i, ret;
4777
4778 np = of_find_compatible_node(NULL, NULL, "ibm,i2o-440spe");
4779 if (!np) {
4780 pr_err("%s: can't find I2O device tree node\n",
4781 __func__);
4782 return -ENODEV;
4783 }
4784
4785 if (of_address_to_resource(np, 0, &i2o_res)) {
4786 of_node_put(np);
4787 return -EINVAL;
4788 }
4789
4790 i2o_reg = of_iomap(np, 0);
4791 if (!i2o_reg) {
4792 pr_err("%s: failed to map I2O registers\n", __func__);
4793 of_node_put(np);
4794 return -EINVAL;
4795 }
4796
4797
4798 dcr_base = dcr_resource_start(np, 0);
4799 dcr_len = dcr_resource_len(np, 0);
4800 if (!dcr_base && !dcr_len) {
4801 pr_err("%s: can't get DCR registers base/len!\n",
4802 np->full_name);
4803 of_node_put(np);
4804 iounmap(i2o_reg);
4805 return -ENODEV;
4806 }
4807
4808 i2o_dcr_host = dcr_map(np, dcr_base, dcr_len);
4809 if (!DCR_MAP_OK(i2o_dcr_host)) {
4810 pr_err("%s: failed to map DCRs!\n", np->full_name);
4811 of_node_put(np);
4812 iounmap(i2o_reg);
4813 return -ENODEV;
4814 }
4815 of_node_put(np);
4816
4817
4818
4819
4820
4821
4822 ppc440spe_dma_fifo_buf = kmalloc((DMA0_FIFO_SIZE + DMA1_FIFO_SIZE) << 1,
4823 GFP_KERNEL);
4824 if (!ppc440spe_dma_fifo_buf) {
4825 pr_err("%s: DMA FIFO buffer allocation failed.\n", __func__);
4826 iounmap(i2o_reg);
4827 dcr_unmap(i2o_dcr_host, dcr_len);
4828 return -ENOMEM;
4829 }
4830
4831
4832
4833
4834
4835 mtdcri(SDR0, DCRN_SDR0_SRST, DCRN_SDR0_SRST_I2ODMA);
4836 mtdcri(SDR0, DCRN_SDR0_SRST, 0);
4837
4838
4839 dcr_write(i2o_dcr_host, DCRN_I2O0_IBAH, (u32)(i2o_res.start >> 32));
4840 dcr_write(i2o_dcr_host, DCRN_I2O0_IBAL, (u32)(i2o_res.start) |
4841 I2O_REG_ENABLE);
4842 dcr_unmap(i2o_dcr_host, dcr_len);
4843
4844
4845 iowrite32(0, &i2o_reg->ifbah);
4846 iowrite32(((u32)__pa(ppc440spe_dma_fifo_buf)), &i2o_reg->ifbal);
4847
4848
4849
4850
4851
4852 iowrite32(0, &i2o_reg->ifsiz);
4853 iounmap(i2o_reg);
4854
4855
4856
4857
4858
4859 np = of_find_compatible_node(NULL, NULL, "ibm,mq-440spe");
4860 if (!np) {
4861 pr_err("%s: can't find MQ device tree node\n",
4862 __func__);
4863 ret = -ENODEV;
4864 goto out_free;
4865 }
4866
4867
4868 dcr_base = dcr_resource_start(np, 0);
4869 dcr_len = dcr_resource_len(np, 0);
4870 if (!dcr_base && !dcr_len) {
4871 pr_err("%s: can't get DCR registers base/len!\n",
4872 np->full_name);
4873 ret = -ENODEV;
4874 goto out_mq;
4875 }
4876
4877 ppc440spe_mq_dcr_host = dcr_map(np, dcr_base, dcr_len);
4878 if (!DCR_MAP_OK(ppc440spe_mq_dcr_host)) {
4879 pr_err("%s: failed to map DCRs!\n", np->full_name);
4880 ret = -ENODEV;
4881 goto out_mq;
4882 }
4883 of_node_put(np);
4884 ppc440spe_mq_dcr_len = dcr_len;
4885
4886
4887 dcr_write(ppc440spe_mq_dcr_host, DCRN_MQ0_BAUH, DMA_CUED_XOR_HB);
4888
4889
4890
4891
4892
4893
4894 dcr_write(ppc440spe_mq_dcr_host, DCRN_MQ0_CFBHL,
4895 (1 << MQ0_CFBHL_TPLM) | (1 << MQ0_CFBHL_HBCL) |
4896 (PPC440SPE_DEFAULT_POLY << MQ0_CFBHL_POLY));
4897
4898 atomic_set(&ppc440spe_adma_err_irq_ref, 0);
4899 for (i = 0; i < PPC440SPE_ADMA_ENGINES_NUM; i++)
4900 ppc440spe_adma_devices[i] = -1;
4901
4902 return 0;
4903
4904out_mq:
4905 of_node_put(np);
4906out_free:
4907 kfree(ppc440spe_dma_fifo_buf);
4908 return ret;
4909}
4910
4911static const struct of_device_id ppc440spe_adma_of_match[] = {
4912 { .compatible = "ibm,dma-440spe", },
4913 { .compatible = "amcc,xor-accelerator", },
4914 {},
4915};
4916MODULE_DEVICE_TABLE(of, ppc440spe_adma_of_match);
4917
4918static struct platform_driver ppc440spe_adma_driver = {
4919 .probe = ppc440spe_adma_probe,
4920 .remove = ppc440spe_adma_remove,
4921 .driver = {
4922 .name = "PPC440SP(E)-ADMA",
4923 .owner = THIS_MODULE,
4924 .of_match_table = ppc440spe_adma_of_match,
4925 },
4926};
4927
4928static __init int ppc440spe_adma_init(void)
4929{
4930 int ret;
4931
4932 ret = ppc440spe_configure_raid_devices();
4933 if (ret)
4934 return ret;
4935
4936 ret = platform_driver_register(&ppc440spe_adma_driver);
4937 if (ret) {
4938 pr_err("%s: failed to register platform driver\n",
4939 __func__);
4940 goto out_reg;
4941 }
4942
4943
4944 ret = driver_create_file(&ppc440spe_adma_driver.driver,
4945 &driver_attr_devices);
4946 if (ret)
4947 goto out_dev;
4948
4949
4950 ret = driver_create_file(&ppc440spe_adma_driver.driver,
4951 &driver_attr_enable);
4952 if (ret)
4953 goto out_en;
4954
4955
4956 ret = driver_create_file(&ppc440spe_adma_driver.driver,
4957 &driver_attr_poly);
4958 if (!ret)
4959 return ret;
4960
4961 driver_remove_file(&ppc440spe_adma_driver.driver,
4962 &driver_attr_enable);
4963out_en:
4964 driver_remove_file(&ppc440spe_adma_driver.driver,
4965 &driver_attr_devices);
4966out_dev:
4967
4968 pr_err("%s: failed to create RAID-6 driver interface\n",
4969 __func__);
4970 platform_driver_unregister(&ppc440spe_adma_driver);
4971out_reg:
4972 dcr_unmap(ppc440spe_mq_dcr_host, ppc440spe_mq_dcr_len);
4973 kfree(ppc440spe_dma_fifo_buf);
4974 return ret;
4975}
4976
4977static void __exit ppc440spe_adma_exit(void)
4978{
4979 driver_remove_file(&ppc440spe_adma_driver.driver,
4980 &driver_attr_poly);
4981 driver_remove_file(&ppc440spe_adma_driver.driver,
4982 &driver_attr_enable);
4983 driver_remove_file(&ppc440spe_adma_driver.driver,
4984 &driver_attr_devices);
4985 platform_driver_unregister(&ppc440spe_adma_driver);
4986 dcr_unmap(ppc440spe_mq_dcr_host, ppc440spe_mq_dcr_len);
4987 kfree(ppc440spe_dma_fifo_buf);
4988}
4989
4990arch_initcall(ppc440spe_adma_init);
4991module_exit(ppc440spe_adma_exit);
4992
4993MODULE_AUTHOR("Yuri Tikhonov <yur@emcraft.com>");
4994MODULE_DESCRIPTION("PPC440SPE ADMA Engine Driver");
4995MODULE_LICENSE("GPL");
4996