35 #include <linux/module.h>
41 #include <linux/slab.h>
49 #include "../dmaengine.h"
63 static char *ppc_adma_errors[] = {
70 "hardware descriptors",
92 static u32 do_xor_refetch;
95 static void *ppc440spe_dma_fifo_buf;
106 static char ppc440spe_qword[16];
108 static atomic_t ppc440spe_adma_err_irq_ref;
109 static dcr_host_t ppc440spe_mq_dcr_host;
110 static unsigned int ppc440spe_mq_dcr_len;
118 static unsigned long ppc440spe_rxor_state;
122 static u32 ppc440spe_r6_enabled;
124 static struct completion ppc440spe_r6_test_comp;
126 static int ppc440spe_adma_dma2rxor_prep_src(
130 static void ppc440spe_adma_dma2rxor_set_src(
133 static void ppc440spe_adma_dma2rxor_set_mult(
138 #define ADMA_LL_DBG(x) ({ if (1) x; 0; })
140 #define ADMA_LL_DBG(x) ({ if (0) x; 0; })
149 switch (chan->
device->id) {
155 "\t attr 0x%02x opc 0x%02x cnt 0x%08x\n"
156 "\t sg1u 0x%08x sg1l 0x%08x\n"
157 "\t sg2u 0x%08x sg2l 0x%08x\n"
158 "\t sg3u 0x%08x sg3l 0x%08x\n",
170 "\t cbc 0x%08x cbbc 0x%08x cbs 0x%08x\n"
171 "\t cbtah 0x%08x cbtal 0x%08x\n"
172 "\t cblah 0x%08x cblal 0x%08x\n",
177 for (i = 0; i < 16; i++) {
178 if (i && !cb->ops[i].
h && !cb->ops[i].
l)
180 pr_debug(
"\t ops[%2d]: h 0x%08x l 0x%08x\n",
181 i, cb->ops[i].
h, cb->ops[i].
l);
190 for (; iter; iter = iter->
hw_next)
195 unsigned int src_cnt)
199 pr_debug(
"\n%s(%d):\nsrc: ", __func__,
id);
200 for (i = 0; i < src_cnt; i++)
202 pr_debug(
"dst:\n\t0x%016llx\n", dst);
206 unsigned int src_cnt)
210 pr_debug(
"\n%s(%d):\nsrc: ", __func__,
id);
211 for (i = 0; i < src_cnt; i++)
214 for (i = 0; i < 2; i++)
218 static void prep_dma_pqzero_sum_dbg(
int id,
dma_addr_t *src,
219 unsigned int src_cnt,
220 const unsigned char *scf)
224 pr_debug(
"\n%s(%d):\nsrc(coef): ", __func__,
id);
226 for (i = 0; i < src_cnt; i++)
227 pr_debug(
"\t0x%016llx(0x%02x) ", src[i], scf[i]);
229 for (i = 0; i < src_cnt; i++)
230 pr_debug(
"\t0x%016llx(no) ", src[i]);
234 for (i = 0; i < 2; i++)
235 pr_debug(
"\t0x%016llx ", src[src_cnt + i]);
250 switch (chan->
device->id) {
286 int src_cnt,
unsigned long flags)
306 int dst_cnt,
int src_cnt,
unsigned long flags)
323 #define DMA_CTRL_FLAGS_LAST DMA_PREP_FENCE
324 #define DMA_PREP_ZERO_P (DMA_CTRL_FLAGS_LAST << 1)
325 #define DMA_PREP_ZERO_Q (DMA_PREP_ZERO_P << 1)
332 int dst_cnt,
int src_cnt,
unsigned long flags,
444 static void ppc440spe_desc_init_dma01pqzero_sum(
446 int dst_cnt,
int src_cnt)
537 int value,
unsigned long flags)
565 struct xor_cb *xor_hw_desc;
568 switch (chan->
device->id) {
573 tmphi = (addr64 >> 32);
574 tmplow = (addr64 & 0xFFFFFFFF);
585 xor_hw_desc->ops[src_idx].
l = addrl;
586 xor_hw_desc->ops[src_idx].
h |= addrh;
596 int sg_index,
unsigned char mult_value)
599 struct xor_cb *xor_hw_desc;
602 switch (chan->
device->id) {
612 psgu = &dma_hw_desc->
sg1u;
618 psgu = &dma_hw_desc->
sg2u;
621 psgu = &dma_hw_desc->
sg3u;
646 struct xor_cb *xor_hw_desc;
650 switch (chan->
device->id) {
655 tmphi = (addr64 >> 32);
656 tmplow = (addr64 & 0xFFFFFFFF);
663 psgu = dst_idx ? &dma_hw_desc->
sg3u : &dma_hw_desc->
sg2u;
664 psgl = dst_idx ? &dma_hw_desc->
sg3l : &dma_hw_desc->
sg2l;
671 xor_hw_desc->
cbtal = addrl;
672 xor_hw_desc->
cbtah |= addrh;
686 struct xor_cb *xor_hw_desc;
688 switch (chan->
device->id) {
696 xor_hw_desc->
cbbc = byte_count;
704 static inline void ppc440spe_desc_set_rxor_block_size(
u32 byte_count)
721 switch (chan->
device->id) {
746 next_desc ? next_desc->
phys : 0);
750 xor_hw_desc->
cbs = 0;
752 xor_hw_desc->
cblah = 0;
767 if (
unlikely(!prev_desc || !next_desc ||
774 "prev->hw_next=0x%p\n", __func__, prev_desc,
775 next_desc, prev_desc ? prev_desc->
hw_next : 0);
784 switch (chan->
device->id) {
792 xor_last_linked =
tail;
794 if (prev_desc == xor_last_submit)
797 ppc440spe_xor_set_link(prev_desc, next_desc);
811 struct xor_cb *xor_hw_desc;
813 switch (chan->
device->id) {
818 switch (dma_hw_desc->
opc) {
825 " DCHECK128\n", __func__, src_idx);
833 " DMA descr\n", __func__, src_idx);
847 dma_hw_desc->
sg1u)) >>
867 " get src3 for region %02x"
868 "PPC440SPE_DESC_RXOR12?\n",
875 " source for non-cued descr\n",
883 __func__, dma_hw_desc->
opc);
890 return xor_hw_desc->ops[src_idx].
l;
903 struct xor_cb *xor_hw_desc;
905 switch (chan->
device->id) {
915 return xor_hw_desc->
cbtal;
928 struct xor_cb *xor_hw_desc;
930 switch (chan->
device->id) {
935 switch (dma_hw_desc->
opc) {
963 __func__, dma_hw_desc->
opc);
985 switch (chan->
device->id) {
990 switch (dma_hw_desc->
opc) {
1004 __func__, dma_hw_desc->
opc);
1032 static inline int ppc440spe_desc_is_aligned(
1035 return (desc->
idx & (num_slots - 1)) ? 0 : 1;
1042 static int ppc440spe_chan_xor_slot_count(
size_t len,
int src_cnt,
1063 static int ppc440spe_dma2_pq_slot_count(
dma_addr_t *srcs,
1064 int src_cnt,
size_t len)
1066 signed long long order = 0;
1070 for (i = 1; i < src_cnt; i++) {
1075 if (cur_addr == old_addr + len) {
1081 }
else if (old_addr == cur_addr + len) {
1092 if (i == src_cnt-2 || (order == -1
1093 && cur_addr != old_addr - len)) {
1097 }
else if (cur_addr == old_addr + len*order) {
1101 }
else if (cur_addr == old_addr + 2*len) {
1105 }
else if (cur_addr == old_addr + 3*len) {
1124 if (src_cnt <= 1 || (state != 1 && state != 2)) {
1125 pr_err(
"%s: src_cnt=%d, state=%d, addr_count=%d, order=%lld\n",
1126 __func__, src_cnt, state, addr_count, order);
1127 for (i = 0; i < src_cnt; i++)
1128 pr_err(
"\t[%d] 0x%llx \n", i, srcs[i]);
1147 static void ppc440spe_adma_device_clear_eot_status(
1152 u8 *p = chan->
device->dma_desc_pool_virt;
1156 switch (chan->
device->id) {
1160 dma_reg = chan->
device->dma_reg;
1163 cdb = (
struct dma_cdb *)&p[i -
1172 &ppc440spe_rxor_state)) {
1182 &ppc440spe_rxor_state);
1198 if (iter->
phys == phys)
1225 pr_err(
"DMA%d err status: 0x%x\n",
1233 xor_reg = chan->
device->xor_reg;
1250 pr_err(
"XOR ERR 0x%x status\n", rv);
1259 ppc440spe_chan_append(chan);
1273 switch (chan->
device->id) {
1276 dma_reg = chan->
device->dma_reg;
1287 xor_reg = chan->
device->xor_reg;
1298 static void ppc440spe_chan_set_first_xor_descriptor(
1306 "when try to set the first CDB!\n",
1309 xor_last_submit = xor_last_linked =
next_desc;
1335 chan_last_sub[chan->
device->id] = desc;
1351 unsigned long flags;
1355 switch (chan->
device->id) {
1358 cur_desc = ppc440spe_chan_get_current_descriptor(chan);
1361 iter = chan_last_sub[chan->
device->id];
1365 iter = chan_first_cdb[chan->
device->id];
1367 ppc440spe_dma_put_desc(chan, iter);
1377 ppc440spe_dma_put_desc(chan, iter);
1384 if (!xor_last_submit->
hw_next)
1387 xor_reg = chan->
device->xor_reg;
1393 xcb = xor_last_linked->
hw_desc;
1399 ppc440spe_xor_set_link(xor_last_submit,
1405 xor_last_submit = xor_last_linked;
1433 switch (chan->
device->id) {
1436 dma_reg = chan->
device->dma_reg;
1439 xor_reg = chan->
device->xor_reg;
1452 switch (chan->
device->id) {
1459 xor_reg = chan->
device->xor_reg;
1473 static int ppc440spe_adma_alloc_chan_resources(
struct dma_chan *chan);
1492 unsigned char mult,
int index,
int dst_pos);
1497 static struct page *ppc440spe_rxor_srcs[32];
1502 static int ppc440spe_can_rxor(
struct page **srcs,
int src_cnt,
size_t len)
1504 int i, order = 0, state = 0;
1513 for (i = 0; i < src_cnt; i++) {
1516 ppc440spe_rxor_srcs[idx++] = srcs[
i];
1520 for (i = 1; i < src_cnt; i++) {
1522 char *old_addr =
page_address(ppc440spe_rxor_srcs[i - 1]);
1526 if (cur_addr == old_addr + len) {
1530 }
else if (old_addr == cur_addr + len) {
1538 if ((i == src_cnt - 2) ||
1539 (order == -1 && cur_addr != old_addr - len)) {
1542 }
else if ((cur_addr == old_addr + len * order) ||
1543 (cur_addr == old_addr + 2 * len) ||
1544 (cur_addr == old_addr + 3 * len)) {
1559 if (state == 1 || state == 2)
1577 static int ppc440spe_adma_estimate(
struct dma_chan *chan,
1579 struct page **src_lst,
int src_cnt,
size_t src_sz)
1587 if (
unlikely(!ppc440spe_r6_enabled))
1602 if (dst_cnt == 1 && src_cnt == 2 && dst_lst[0] == src_lst[1])
1604 else if (ppc440spe_can_rxor(src_lst, src_cnt, src_sz))
1620 struct page **dst_lst,
int dst_cnt,
struct page **src_lst,
1621 int src_cnt,
size_t src_sz)
1637 if (src_cnt == 1 && dst_lst[1] == src_lst[0])
1639 if (src_cnt == 2 && dst_lst[1] == src_lst[1])
1654 rank = ppc440spe_adma_estimate(ref->
chan, cap, dst_lst,
1655 dst_cnt, src_lst, src_cnt, src_sz);
1656 if (rank > best_rank) {
1658 best_chan = ref->
chan;
1677 if (entry_idx < 0 || entry_idx >= (tdesc->
src_cnt + tdesc->
dst_cnt)) {
1678 printk(
"%s: entry_idx %d, src_cnt %d, dst_cnt %d\n",
1684 if (i++ == entry_idx)
1719 src_cnt = ppc440spe_desc_get_src_num(desc, chan);
1720 dst_cnt = ppc440spe_desc_get_dst_num(desc, chan);
1725 addr = ppc440spe_desc_get_dest_addr(
1726 desc, chan, dst_cnt);
1736 addr = ppc440spe_desc_get_src_addr(
1737 desc, chan, src_cnt);
1749 static dma_cookie_t ppc440spe_adma_run_tx_complete_actions(
1782 for (i = 0; i < slot_count; i++) {
1784 ppc440spe_adma_unmap(chan, unmap);
1805 if (!async_tx_test_ack(&desc->
async_tx))
1812 desc->
phys == ppc440spe_chan_get_current_descriptor(chan))
1830 dev_dbg(chan->
device->common.dev,
"\tfree slot %llx: %d stride: %d\n",
1834 ppc440spe_adma_free_slots(desc, chan);
1849 u32 current_desc = ppc440spe_chan_get_current_descriptor(chan);
1850 int busy = ppc440spe_chan_is_busy(chan);
1851 int seen_current = 0, slot_cnt = 0, slots_per_op = 0;
1854 chan->
device->id, __func__);
1856 if (!current_desc) {
1869 "busy: %d this_desc: %#llx next_desc: %#x "
1870 "cur: %#x ack: %d\n",
1872 ppc440spe_desc_get_link(iter, chan), current_desc,
1873 async_tx_test_ack(&iter->
async_tx));
1888 if (iter->
phys == current_desc) {
1890 if (busy || ppc440spe_desc_get_link(iter, chan)) {
1899 if (!slot_cnt && !slots_per_op) {
1902 if (slot_cnt <= slots_per_op) {
1915 if (slots_per_op != 0 && slot_cnt == 0) {
1917 int end_of_chain = 0;
1921 grp_iter = group_start;
1925 cookie = ppc440spe_adma_run_tx_complete_actions(
1926 grp_iter, chan, cookie);
1929 end_of_chain = ppc440spe_adma_clean_slot(
1931 if (end_of_chain && slot_cnt) {
1938 if (slot_cnt == 0 || end_of_chain)
1951 }
else if (slots_per_op)
1954 cookie = ppc440spe_adma_run_tx_complete_actions(iter, chan,
1957 if (ppc440spe_adma_clean_slot(iter, chan))
1965 pr_debug(
"\tcompleted cookie %d\n", cookie);
1973 static void ppc440spe_adma_tasklet(
unsigned long data)
1978 __ppc440spe_adma_slot_cleanup(chan);
1979 spin_unlock(&chan->
lock);
1987 spin_lock_bh(&chan->
lock);
1988 __ppc440spe_adma_slot_cleanup(chan);
1989 spin_unlock_bh(&chan->
lock);
2002 int slots_found,
retry = 0;
2005 BUG_ON(!num_slots || !slots_per_op);
2031 if (slots_found == num_slots) {
2039 if (num_slots != slots_per_op)
2060 list_splice(&chain, &alloc_tail->
group_list);
2076 static int ppc440spe_adma_alloc_chan_resources(
struct dma_chan *chan)
2091 db_sz =
sizeof(
struct dma_cdb);
2093 db_sz =
sizeof(
struct xor_cb);
2095 for (; i < (ppc440spe_chan->
device->pool_size / db_sz); i++) {
2100 " %d descriptor slots", i--);
2104 hw_desc = (
char *) ppc440spe_chan->
device->dma_desc_pool_virt;
2105 slot->
hw_desc = (
void *) &hw_desc[i * db_sz];
2107 slot->
async_tx.tx_submit = ppc440spe_adma_tx_submit;
2111 slot->
phys = ppc440spe_chan->
device->dma_desc_pool + i * db_sz;
2114 spin_lock_bh(&ppc440spe_chan->
lock);
2117 spin_unlock_bh(&ppc440spe_chan->
lock);
2128 "ppc440spe adma%d: allocated %d descriptor slots\n",
2129 ppc440spe_chan->
device->id, i);
2133 switch (ppc440spe_chan->
device->id) {
2138 if (!ppc440spe_r6_tchan)
2139 ppc440spe_r6_tchan = ppc440spe_chan;
2142 ppc440spe_chan_start_null_xor(ppc440spe_chan);
2150 return (i > 0) ? i : -
ENOMEM;
2161 xcb->ops[xor_arg_no].
h |=
mask;
2173 xcb->ops[xor_arg_no].
l =
addr;
2193 dev_dbg(chan->
device->common.dev,
"ppc440spe adma%d: pending: %d\n",
2198 ppc440spe_chan_append(chan);
2222 spin_lock_bh(&chan->
lock);
2223 cookie = dma_cookie_assign(tx);
2228 chan_first_cdb[chan->
device->id] = group_start;
2237 ppc440spe_desc_set_link(chan, old_chain_tail, group_start);
2242 ppc440spe_adma_check_threshold(chan);
2243 spin_unlock_bh(&chan->
lock);
2246 "ppc440spe adma%d: %s cookie: %d slot: %d tx %p\n",
2247 chan->
device->id, __func__,
2257 struct dma_chan *chan,
unsigned long flags)
2266 "ppc440spe adma%d: %s\n", ppc440spe_chan->
device->id,
2269 spin_lock_bh(&ppc440spe_chan->
lock);
2270 slot_cnt = slots_per_op = 1;
2271 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt,
2275 ppc440spe_desc_init_interrupt(group_start, ppc440spe_chan);
2279 spin_unlock_bh(&ppc440spe_chan->
lock);
2289 dma_addr_t dma_src,
size_t len,
unsigned long flags)
2302 spin_lock_bh(&ppc440spe_chan->
lock);
2305 "ppc440spe adma%d: %s len: %u int_en %d\n",
2306 ppc440spe_chan->
device->id, __func__, len,
2307 flags & DMA_PREP_INTERRUPT ? 1 : 0);
2308 slot_cnt = slots_per_op = 1;
2309 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt,
2313 ppc440spe_desc_init_memcpy(group_start, flags);
2314 ppc440spe_adma_set_dest(group_start, dma_dest, 0);
2315 ppc440spe_adma_memcpy_xor_set_src(group_start, dma_src, 0);
2316 ppc440spe_desc_set_byte_count(group_start, ppc440spe_chan, len);
2320 spin_unlock_bh(&ppc440spe_chan->
lock);
2330 size_t len,
unsigned long flags)
2343 spin_lock_bh(&ppc440spe_chan->
lock);
2346 "ppc440spe adma%d: %s cal: %u len: %u int_en %d\n",
2347 ppc440spe_chan->
device->id, __func__, value, len,
2348 flags & DMA_PREP_INTERRUPT ? 1 : 0);
2350 slot_cnt = slots_per_op = 1;
2351 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt,
2355 ppc440spe_desc_init_memset(group_start, value, flags);
2356 ppc440spe_adma_set_dest(group_start, dma_dest, 0);
2357 ppc440spe_desc_set_byte_count(group_start, ppc440spe_chan, len);
2361 spin_unlock_bh(&ppc440spe_chan->
lock);
2372 unsigned long flags)
2381 dma_dest, dma_src, src_cnt));
2387 "ppc440spe adma%d: %s src_cnt: %d len: %u int_en: %d\n",
2388 ppc440spe_chan->
device->id, __func__, src_cnt, len,
2389 flags & DMA_PREP_INTERRUPT ? 1 : 0);
2391 spin_lock_bh(&ppc440spe_chan->
lock);
2392 slot_cnt = ppc440spe_chan_xor_slot_count(len, src_cnt, &slots_per_op);
2393 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt,
2397 ppc440spe_desc_init_xor(group_start, src_cnt, flags);
2398 ppc440spe_adma_set_dest(group_start, dma_dest, 0);
2400 ppc440spe_adma_memcpy_xor_set_src(group_start,
2401 dma_src[src_cnt], src_cnt);
2402 ppc440spe_desc_set_byte_count(group_start, ppc440spe_chan, len);
2406 spin_unlock_bh(&ppc440spe_chan->
lock);
2414 static void ppc440spe_init_rxor_cursor(
struct ppc440spe_rxor *cursor);
2419 static void ppc440spe_adma_init_dma2rxor_slot(
2426 for (i = 0; i <
src_cnt; i++) {
2427 ppc440spe_adma_dma2rxor_prep_src(desc, &desc->
rxor_cursor, i,
2439 const unsigned char *scf,
size_t len,
unsigned long flags)
2442 unsigned long op = 0;
2448 spin_lock_bh(&ppc440spe_chan->
lock);
2451 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt, 1);
2476 ppc440spe_desc_set_dest_addr(iter, chan,
2478 ppc440spe_desc_set_dest_addr(iter, chan, 0, dst[1], 1);
2481 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan, len);
2493 if (flags & DMA_PREP_INTERRUPT)
2500 ppc440spe_desc_set_src_addr(iter, chan, 0,
2502 ppc440spe_desc_set_dest_addr(iter, chan,
2507 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan, len);
2512 spin_unlock_bh(&ppc440spe_chan->
lock);
2525 const unsigned char *scf,
size_t len,
unsigned long flags)
2528 unsigned long op = 0;
2534 spin_lock_bh(&ppc440spe_chan->
lock);
2537 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt, 1);
2561 ppc440spe_desc_set_dest_addr(iter, chan, 0,
2562 ppc440spe_chan->
qdest, 1);
2565 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan, len);
2578 if (flags & DMA_PREP_INTERRUPT)
2586 ppc440spe_chan->
qdest);
2591 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan, len);
2603 if (flags & DMA_PREP_INTERRUPT)
2616 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan, len);
2621 spin_unlock_bh(&ppc440spe_chan->
lock);
2629 const unsigned char *scf,
size_t len,
unsigned long flags)
2633 unsigned long op = 0;
2634 unsigned char mult = 1;
2636 pr_debug(
"%s: dst_cnt %d, src_cnt %d, len %d\n",
2637 __func__, dst_cnt, src_cnt, len);
2652 (src[0] + len) == src[1]) {
2657 if ((src[1] + len) == src[2]) {
2661 }
else if ((src[1] + len * 2) == src[2]) {
2664 }
else if ((src[1] + len * 3) == src[2]) {
2682 &ppc440spe_rxor_state);
2685 ppc440spe_desc_set_rxor_block_size(len);
2712 if (flags & DMA_PREP_ZERO_P)
2718 slot_cnt += src_cnt - 2;
2720 slot_cnt += src_cnt - 3;
2725 if (slot_cnt == dst_cnt)
2730 spin_lock_bh(&ppc440spe_chan->
lock);
2732 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt, 1);
2734 ppc440spe_desc_init_dma01pq(sw_desc, dst_cnt, src_cnt,
2738 pr_debug(
"%s: set dst descriptor 0, 1: 0x%016llx, 0x%016llx\n",
2739 __func__, dst[0], dst[1]);
2740 ppc440spe_adma_pq_set_dest(sw_desc, dst, flags);
2742 ppc440spe_adma_pq_set_src(sw_desc, src[src_cnt],
2753 ppc440spe_adma_pq_set_src_mult(sw_desc,
2754 mult, src_cnt, dst_cnt - 1);
2761 ppc440spe_desc_set_byte_count(iter,
2762 ppc440spe_chan, len);
2763 iter->unmap_len = len;
2766 spin_unlock_bh(&ppc440spe_chan->
lock);
2774 const unsigned char *scf,
size_t len,
unsigned long flags)
2778 unsigned long op = 0;
2779 unsigned char mult = 1;
2785 spin_lock_bh(&ppc440spe_chan->
lock);
2786 descs_per_op = ppc440spe_dma2_pq_slot_count(src, src_cnt, len);
2787 if (descs_per_op < 0) {
2788 spin_unlock_bh(&ppc440spe_chan->
lock);
2793 slot_cnt = descs_per_op *
dst_cnt;
2795 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt, 1);
2800 ppc440spe_desc_init_dma2pq(iter, dst_cnt, src_cnt,
2802 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan,
2804 iter->unmap_len = len;
2806 ppc440spe_init_rxor_cursor(&(iter->rxor_cursor));
2807 iter->rxor_cursor.len = len;
2813 if (op % descs_per_op == 0)
2814 ppc440spe_adma_init_dma2rxor_slot(iter, src,
2816 if (
likely(!list_is_last(&iter->chain_node,
2823 ppc440spe_xor_set_link(iter, iter->hw_next);
2826 iter->hw_next =
NULL;
2832 if (flags & DMA_PREP_ZERO_P)
2834 if (flags & DMA_PREP_ZERO_Q)
2838 ppc440spe_adma_pq_set_dest(sw_desc, dst, flags);
2844 ppc440spe_adma_pq_set_src(sw_desc, src[src_cnt],
2848 ppc440spe_adma_pq_set_src_mult(sw_desc,
2849 mult, src_cnt, dst_cnt - 1);
2852 spin_unlock_bh(&ppc440spe_chan->
lock);
2853 ppc440spe_desc_set_rxor_block_size(len);
2862 unsigned int src_cnt,
const unsigned char *scf,
2863 size_t len,
unsigned long flags)
2872 dst, src, src_cnt));
2877 if (src_cnt == 1 && dst[1] == src[0]) {
2883 dest[1] = ppc440spe_chan->
qdest;
2884 sw_desc = ppc440spe_dma01_prep_mult(ppc440spe_chan,
2885 dest, 2, src, src_cnt, scf, len, flags);
2889 if (src_cnt == 2 && dst[1] == src[1]) {
2890 sw_desc = ppc440spe_dma01_prep_sum_product(ppc440spe_chan,
2891 &dst[1], src, 2, scf, len, flags);
2910 "ppc440spe adma%d: %s src_cnt: %d len: %u int_en: %d\n",
2911 ppc440spe_chan->
device->id, __func__, src_cnt, len,
2912 flags & DMA_PREP_INTERRUPT ? 1 : 0);
2914 switch (ppc440spe_chan->
device->id) {
2917 sw_desc = ppc440spe_dma01_prep_pq(ppc440spe_chan,
2918 dst, dst_cnt, src, src_cnt, scf,
2923 sw_desc = ppc440spe_dma2_prep_pq(ppc440spe_chan,
2924 dst, dst_cnt, src, src_cnt, scf,
2938 unsigned int src_cnt,
const unsigned char *scf,
size_t len,
2948 if (flags & DMA_PREP_PQ_DISABLE_P)
2953 if (flags & DMA_PREP_PQ_DISABLE_Q)
2959 src, src_cnt, scf));
2964 idst = dst_cnt = (pdest && qdest) ? 2 : 1;
2969 slot_cnt = src_cnt + dst_cnt * 2;
2972 spin_lock_bh(&ppc440spe_chan->
lock);
2973 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt,
2976 ppc440spe_desc_init_dma01pqzero_sum(sw_desc, dst_cnt, src_cnt);
2981 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan,
3000 ppc440spe_desc_set_dest_addr(iter, chan, 0,
3001 ppc440spe_chan->
pdest, 0);
3002 ppc440spe_desc_set_src_addr(iter, chan, 0, 0, pdest);
3003 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan,
3007 pdest = ppc440spe_chan->
pdest;
3032 ppc440spe_desc_set_dest_addr(iter, chan, 0,
3033 ppc440spe_chan->
qdest, 0);
3034 ppc440spe_desc_set_src_addr(iter, chan, 0, 0, qdest);
3035 ppc440spe_desc_set_byte_count(iter, ppc440spe_chan,
3039 qdest = ppc440spe_chan->
qdest;
3043 ppc440spe_adma_pqzero_sum_set_dest(sw_desc, pdest, qdest);
3055 if (idst == dst_cnt) {
3078 ppc440spe_desc_set_dcheck(iter, ppc440spe_chan,
3092 ppc440spe_desc_set_src_addr(iter, chan, 0,
3098 ppc440spe_desc_set_src_mult(iter, chan,
3107 spin_unlock_bh(&ppc440spe_chan->
lock);
3127 tx = ppc440spe_adma_prep_dma_pqzero_sum(chan, pq, &src[1],
3128 src_cnt - 1, 0, len,
3145 switch (chan->
device->id) {
3151 ppc440spe_desc_set_dest_addr(sw_desc->
group_head,
3152 chan, 0, addr, index);
3155 sw_desc = ppc440spe_get_group_entry(sw_desc, index);
3156 ppc440spe_desc_set_dest_addr(sw_desc,
3157 chan, 0, addr, index);
3194 if (flags & DMA_PREP_PQ_DISABLE_P)
3199 if (flags & DMA_PREP_PQ_DISABLE_Q)
3204 if (!paddr || !qaddr)
3205 addr = paddr ? paddr : qaddr;
3207 switch (chan->
device->id) {
3220 iter = ppc440spe_get_group_entry(sw_desc, index);
3225 ppc440spe_desc_set_dest_addr(iter, chan,
3231 ppc440spe_desc_set_dest_addr(iter, chan,
3232 DMA_CUED_XOR_BASE, paddr, 0);
3233 ppc440spe_desc_set_dest_addr(iter, chan,
3234 DMA_CUED_XOR_BASE, qaddr, 1);
3245 iter = ppc440spe_get_group_entry(
3247 ppc440spe_adma_pq_zero_op(iter, chan,
3253 iter = ppc440spe_get_group_entry(
3255 ppc440spe_adma_pq_zero_op(iter, chan,
3277 iter = ppc440spe_get_group_entry(sw_desc, index++);
3278 ppc440spe_desc_set_dest_addr(iter, chan,
3279 paddr ? ppath : qpath,
3280 paddr ? paddr : qaddr, 0);
3283 iter = ppc440spe_get_group_entry(sw_desc,
3285 ppc440spe_desc_set_dest_addr(iter, chan,
3293 iter = ppc440spe_get_group_entry(sw_desc,
3300 ppc440spe_desc_set_dest_addr(
3310 ppc440spe_desc_set_dest_addr(
3314 ppc440spe_desc_set_dest_addr(
3341 iter = ppc440spe_get_group_entry(sw_desc, 0);
3343 ppc440spe_desc_set_dest_addr(iter, chan,
3344 paddr ? ppath : qpath,
3345 paddr ? paddr : qaddr, 0);
3353 iter = ppc440spe_get_group_entry(sw_desc,
3356 ppc440spe_desc_set_dest_addr(iter,
3357 chan, qpath, qaddr, 0);
3372 static void ppc440spe_adma_pqzero_sum_set_dest(
3386 idx = (paddr && qaddr) ? 2 : 1;
3394 idx = (paddr && qaddr) ? 2 : 1;
3395 iter = ppc440spe_get_group_entry(sw_desc, idx);
3397 if (paddr && qaddr) {
3403 ppc440spe_desc_set_dest_addr(iter, chan,
3405 ppc440spe_desc_set_dest_addr(iter, chan,
3410 addr = paddr ? paddr : qaddr;
3415 ppc440spe_desc_set_dest_addr(iter, chan,
3424 ppc440spe_desc_set_src_addr(end, chan, 0, 0, addr ? addr : paddr);
3429 ppc440spe_desc_set_src_addr(end, chan, 0, 0, qaddr);
3436 static inline void ppc440spe_desc_set_xor_src_cnt(
3443 hw_desc->
cbc |= src_cnt;
3458 switch (chan->
device->id) {
3466 &sw_desc->
flags) ? 2 : 3;
3492 iter = ppc440spe_get_group_entry(sw_desc, 0);
3493 }
else if (index < iskip) {
3504 iter = ppc440spe_get_group_entry(sw_desc,
3505 index - iskip + sw_desc->
dst_cnt);
3519 iter = ppc440spe_get_group_entry(sw_desc,
3524 ppc440spe_desc_set_src_addr(iter, chan, 0, haddr, addr);
3532 iter = ppc440spe_get_group_entry(sw_desc, 1);
3533 ppc440spe_desc_set_src_addr(iter, chan, 0,
3544 ppc440spe_adma_dma2rxor_set_src(iter, index, addr);
3547 iter = ppc440spe_get_group_entry(sw_desc,
3550 ppc440spe_adma_dma2rxor_set_src(iter, index, addr);
3558 static void ppc440spe_adma_memcpy_xor_set_src(
3568 ppc440spe_desc_set_src_addr(sw_desc, chan, index, 0, addr);
3574 static void ppc440spe_adma_dma2rxor_inc_addr(
3579 if (index == src_cnt - 1) {
3580 ppc440spe_desc_set_xor_src_cnt(desc, cursor->
addr_count);
3582 ppc440spe_desc_set_xor_src_cnt(desc, cursor->
addr_count);
3591 static int ppc440spe_adma_dma2rxor_prep_src(
3594 int src_cnt,
u32 addr)
3607 switch (cursor->
state) {
3609 if (addr == cursor->
addrl + cursor->
len) {
3613 if (index == src_cnt-1) {
3614 ppc440spe_rxor_set_region(desc,
3617 ppc440spe_adma_dma2rxor_inc_addr(
3618 desc, cursor, index, src_cnt);
3620 }
else if (cursor->
addrl == addr + cursor->
len) {
3625 if (index == src_cnt-1) {
3626 ppc440spe_rxor_set_region(desc,
3629 ppc440spe_adma_dma2rxor_inc_addr(
3630 desc, cursor, index, src_cnt);
3634 "DMA2 RXOR command block.\n");
3642 if (index == src_cnt-2 || (sign == -1
3643 && addr != cursor->
addrl - 2*cursor->
len)) {
3647 ppc440spe_rxor_set_region(desc,
3650 ppc440spe_adma_dma2rxor_inc_addr(
3651 desc, cursor, index, src_cnt);
3652 }
else if (addr == cursor->
addrl + 2*sign*cursor->
len) {
3655 ppc440spe_rxor_set_region(desc,
3658 if (index == src_cnt-1) {
3659 ppc440spe_adma_dma2rxor_inc_addr(
3660 desc, cursor, index, src_cnt);
3662 }
else if (addr == cursor->
addrl + 3*cursor->
len) {
3665 ppc440spe_rxor_set_region(desc,
3668 if (index == src_cnt-1) {
3669 ppc440spe_adma_dma2rxor_inc_addr(
3670 desc, cursor, index, src_cnt);
3672 }
else if (addr == cursor->
addrl + 4*cursor->
len) {
3675 ppc440spe_rxor_set_region(desc,
3678 if (index == src_cnt-1) {
3679 ppc440spe_adma_dma2rxor_inc_addr(
3680 desc, cursor, index, src_cnt);
3686 ppc440spe_rxor_set_region(desc,
3689 ppc440spe_adma_dma2rxor_inc_addr(
3690 desc, cursor, index, src_cnt);
3698 ppc440spe_adma_dma2rxor_inc_addr(
3699 desc, cursor, index, src_cnt);
3711 static void ppc440spe_adma_dma2rxor_set_src(
3716 int k = 0, op = 0, lop = 0;
3719 while (op <= index) {
3728 if ((xcb->ops[k++].
h & (
DMA_RXOR12 << DMA_CUED_REGION_OFF)) ==
3739 if (index == op - 1)
3740 ppc440spe_rxor_set_src(desc, k - 1, addr);
3744 ppc440spe_rxor_set_src(desc, k - 1, addr);
3752 static void ppc440spe_adma_dma2rxor_set_mult(
3757 int k = 0, op = 0, lop = 0;
3760 while (op <= index) {
3770 if ((xcb->ops[k++].
h & (
DMA_RXOR12 << DMA_CUED_REGION_OFF)) ==
3780 ppc440spe_rxor_set_mult(desc, k - 1, op - index - 1, mult);
3783 ppc440spe_rxor_set_mult(desc, k - 1, index - lop, mult);
3790 static void ppc440spe_init_rxor_cursor(
struct ppc440spe_rxor *cursor)
3800 static void ppc440spe_adma_pq_set_src_mult(
3802 unsigned char mult,
int index,
int dst_pos)
3805 u32 mult_idx, mult_dst;
3810 switch (chan->
device->id) {
3815 &sw_desc->
flags) ? 2 : 3;
3817 if (index < region) {
3819 iter = ppc440spe_get_group_entry(sw_desc,
3822 iter1 = ppc440spe_get_group_entry(
3829 iter = ppc440spe_get_group_entry(sw_desc,
3848 iter = ppc440spe_get_group_entry(sw_desc, index + znum);
3854 ppc440spe_desc_set_src_mult(iter, chan,
3855 mult_idx, mult_dst, mult);
3861 ppc440spe_desc_set_src_mult(iter1, chan,
3862 mult_idx, mult_dst, 1);
3872 ppc440spe_adma_dma2rxor_set_mult(iter, index, 1);
3875 iter = ppc440spe_get_group_entry(sw_desc,
3878 ppc440spe_adma_dma2rxor_set_mult(iter, index, mult);
3886 static void ppc440spe_adma_free_chan_resources(
struct dma_chan *chan)
3890 int in_use_descs = 0;
3893 ppc440spe_adma_slot_cleanup(ppc440spe_chan);
3895 spin_lock_bh(&ppc440spe_chan->
lock);
3910 "ppc440spe adma%d %s slots_allocated %d\n",
3911 ppc440spe_chan->
device->id,
3913 spin_unlock_bh(&ppc440spe_chan->
lock);
3916 if (in_use_descs > 1)
3934 ret = dma_cookie_status(chan, cookie, txstate);
3938 ppc440spe_adma_slot_cleanup(ppc440spe_chan);
3940 return dma_cookie_status(chan, cookie, txstate);
3951 "ppc440spe adma%d: %s\n", chan->
device->id, __func__);
3954 ppc440spe_adma_device_clear_eot_status(chan);
3968 "ppc440spe adma%d: %s\n", chan->
device->id, __func__);
3971 ppc440spe_adma_device_clear_eot_status(chan);
3979 static void ppc440spe_test_callback(
void *
unused)
3987 static void ppc440spe_adma_issue_pending(
struct dma_chan *chan)
3993 "ppc440spe adma%d: %s %d \n", ppc440spe_chan->
device->id,
3994 __func__, ppc440spe_chan->
pending);
3996 if (ppc440spe_chan->
pending) {
3998 ppc440spe_chan_append(ppc440spe_chan);
4014 "ppc440spe adma%d: %s\n", chan->
device->id, __func__);
4016 spin_lock_bh(&chan->
lock);
4017 slot_cnt = ppc440spe_chan_xor_slot_count(0, 2, &slots_per_op);
4018 sw_desc = ppc440spe_adma_alloc_slots(chan, slot_cnt, slots_per_op);
4023 ppc440spe_desc_init_null_xor(group_start);
4025 cookie = dma_cookie_assign(&sw_desc->
async_tx);
4030 chan->
common.completed_cookie = cookie - 1;
4033 BUG_ON(ppc440spe_chan_is_busy(chan));
4036 ppc440spe_chan_set_first_xor_descriptor(chan, sw_desc);
4039 ppc440spe_chan_run(chan);
4042 " failed to allocate null descriptor\n",
4044 spin_unlock_bh(&chan->
lock);
4059 unsigned long op = 0;
4068 spin_lock_bh(&chan->
lock);
4069 sw_desc = ppc440spe_adma_alloc_slots(chan, 1, 1);
4072 ppc440spe_desc_init_dma01pq(sw_desc, 1, 1, 1, op);
4074 ppc440spe_desc_set_byte_count(iter, chan,
PAGE_SIZE);
4079 spin_unlock_bh(&chan->
lock);
4082 spin_unlock_bh(&chan->
lock);
4090 ppc440spe_adma_pq_set_src(sw_desc, dma_addr, 0);
4091 ppc440spe_adma_pq_set_src_mult(sw_desc, 1, 0, 0);
4094 ppc440spe_adma_pq_set_dest(sw_desc, addrs, DMA_PREP_PQ_DISABLE_Q);
4097 sw_desc->
async_tx.callback = ppc440spe_test_callback;
4100 init_completion(&ppc440spe_r6_test_comp);
4102 ppc440spe_adma_tx_submit(&sw_desc->
async_tx);
4103 ppc440spe_adma_issue_pending(&chan->
common);
4142 adev->
common.device_alloc_chan_resources =
4143 ppc440spe_adma_alloc_chan_resources;
4144 adev->
common.device_free_chan_resources =
4145 ppc440spe_adma_free_chan_resources;
4146 adev->
common.device_tx_status = ppc440spe_adma_tx_status;
4147 adev->
common.device_issue_pending = ppc440spe_adma_issue_pending;
4151 adev->
common.device_prep_dma_memcpy =
4152 ppc440spe_adma_prep_dma_memcpy;
4155 adev->
common.device_prep_dma_memset =
4156 ppc440spe_adma_prep_dma_memset;
4160 adev->
common.device_prep_dma_xor =
4161 ppc440spe_adma_prep_dma_xor;
4166 dma_set_maxpq(&adev->
common,
4170 dma_set_maxpq(&adev->
common,
4177 adev->
common.device_prep_dma_pq =
4178 ppc440spe_adma_prep_dma_pq;
4191 adev->
common.device_prep_dma_pq_val =
4192 ppc440spe_adma_prep_dma_pqzero_sum;
4205 adev->
common.device_prep_dma_xor_val =
4206 ppc440spe_adma_prep_dma_xor_zero_sum;
4209 adev->
common.device_prep_dma_interrupt =
4210 ppc440spe_adma_prep_dma_interrupt;
4212 pr_info(
"%s: AMCC(R) PPC440SP(E) ADMA Engine: "
4213 "( %s%s%s%s%s%s%s)\n",
4214 dev_name(adev->
dev),
4233 np = ofdev->
dev.of_node;
4272 ppc440spe_adma_err_handler,
4295 pr_err(
"%s: can't find I2O device tree node\n",
4302 pr_err(
"%s: failed to map I2O registers\n", __func__);
4387 if (!idx || (len !=
sizeof(
u32))) {
4388 dev_err(&ofdev->
dev,
"Device node %s has missing "
4389 "or invalid cell-index property\n",
4411 dev_err(&ofdev->
dev,
"failed to get memory resource\n");
4419 dev_err(&ofdev->
dev,
"failed to request memory region %pR\n",
4429 dev_err(&ofdev->
dev,
"failed to allocate device\n");
4432 goto err_adev_alloc;
4442 dev_err(&ofdev->
dev,
"failed to allocate %d bytes of coherent "
4443 "memory for hardware descriptors\n",
4449 dev_dbg(&ofdev->
dev,
"allocated descriptor pool virt 0x%p phys 0x%llx\n",
4454 dev_err(&ofdev->
dev,
"failed to ioremap regs!\n");
4455 goto err_regs_alloc;
4483 INIT_LIST_HEAD(&adev->
common.channels);
4489 dev_err(&ofdev->
dev,
"can't allocate channel structure\n");
4492 goto err_chan_alloc;
4496 INIT_LIST_HEAD(&chan->
chain);
4500 dma_cookie_init(&chan->
common);
4503 (
unsigned long)chan);
4518 goto err_page_alloc;
4529 INIT_LIST_HEAD(&ref->
node);
4532 dev_err(&ofdev->
dev,
"failed to allocate channel reference!\n");
4537 ret = ppc440spe_adma_setup_irqs(adev, chan, &initcode);
4541 ppc440spe_adma_init_capabilities(adev);
4546 dev_err(&ofdev->
dev,
"failed to register dma device\n");
4553 ppc440spe_adma_release_irqs(adev, chan);
4587 ppc440spe_adma_devices[
id] = initcode;
4606 ppc440spe_adma_devices[adev->
id] = -1;
4613 ppc440spe_adma_release_irqs(adev, ppc440spe_chan);
4625 if (ppc440spe_chan ==
4632 kfree(ppc440spe_chan);
4663 if (ppc440spe_adma_devices[i] == -1)
4666 "PPC440SP(E)-ADMA.%d: %s\n", i,
4667 ppc_adma_errors[ppc440spe_adma_devices[i]]);
4675 "PPC440SP(e) RAID-6 capabilities are %sABLED.\n",
4676 ppc440spe_r6_enabled ?
"EN" :
"DIS");
4680 const char *buf,
size_t count)
4684 if (!count || count > 11)
4687 if (!ppc440spe_r6_tchan)
4691 sscanf(buf,
"%lx", &val);
4696 if (ppc440spe_test_raid6(ppc440spe_r6_tchan) == 0) {
4697 pr_info(
"PPC440SP(e) RAID-6 has been activated "
4699 ppc440spe_r6_enabled = 1;
4701 pr_info(
"PPC440SP(e) RAID-6 hasn't been activated!"
4703 ppc440spe_r6_enabled = 0;
4723 "uses 0x1%02x polynomial.\n", reg);
4728 const char *buf,
size_t count)
4737 if (!count || count > 6)
4741 sscanf(buf,
"%lx", &val);
4757 store_ppc440spe_r6enable);
4759 store_ppc440spe_r6poly);
4766 static int ppc440spe_configure_raid_devices(
void)
4771 dcr_host_t i2o_dcr_host;
4772 unsigned int dcr_base, dcr_len;
4777 pr_err(
"%s: can't find I2O device tree node\n",
4789 pr_err(
"%s: failed to map I2O registers\n", __func__);
4797 if (!dcr_base && !dcr_len) {
4798 pr_err(
"%s: can't get DCR registers base/len!\n",
4805 i2o_dcr_host = dcr_map(np, dcr_base, dcr_len);
4806 if (!DCR_MAP_OK(i2o_dcr_host)) {
4821 if (!ppc440spe_dma_fifo_buf) {
4822 pr_err(
"%s: DMA FIFO buffer allocation failed.\n", __func__);
4824 dcr_unmap(i2o_dcr_host, dcr_len);
4839 dcr_unmap(i2o_dcr_host, dcr_len);
4858 pr_err(
"%s: can't find MQ device tree node\n",
4867 if (!dcr_base && !dcr_len) {
4868 pr_err(
"%s: can't get DCR registers base/len!\n",
4874 ppc440spe_mq_dcr_host = dcr_map(np, dcr_base, dcr_len);
4875 if (!DCR_MAP_OK(ppc440spe_mq_dcr_host)) {
4881 ppc440spe_mq_dcr_len = dcr_len;
4897 ppc440spe_adma_devices[i] = -1;
4904 kfree(ppc440spe_dma_fifo_buf);
4909 { .compatible =
"ibm,dma-440spe", },
4910 { .compatible =
"amcc,xor-accelerator", },
4916 .probe = ppc440spe_adma_probe,
4919 .name =
"PPC440SP(E)-ADMA",
4921 .of_match_table = ppc440spe_adma_of_match,
4925 static __init int ppc440spe_adma_init(
void)
4929 ret = ppc440spe_configure_raid_devices();
4935 pr_err(
"%s: failed to register platform driver\n",
4942 &driver_attr_devices);
4948 &driver_attr_enable);
4959 &driver_attr_enable);
4962 &driver_attr_devices);
4965 pr_err(
"%s: failed to create RAID-6 driver interface\n",
4969 dcr_unmap(ppc440spe_mq_dcr_host, ppc440spe_mq_dcr_len);
4970 kfree(ppc440spe_dma_fifo_buf);
4974 static void __exit ppc440spe_adma_exit(
void)
4979 &driver_attr_enable);
4981 &driver_attr_devices);
4983 dcr_unmap(ppc440spe_mq_dcr_host, ppc440spe_mq_dcr_len);
4984 kfree(ppc440spe_dma_fifo_buf);