1*4fa9c49fSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2599d49deSDave Jiang /*
3599d49deSDave Jiang * Intel I/OAT DMA Linux driver
4599d49deSDave Jiang * Copyright(c) 2004 - 2015 Intel Corporation.
5599d49deSDave Jiang */
6599d49deSDave Jiang #include <linux/module.h>
7599d49deSDave Jiang #include <linux/pci.h>
8599d49deSDave Jiang #include <linux/gfp.h>
9599d49deSDave Jiang #include <linux/dmaengine.h>
10599d49deSDave Jiang #include <linux/dma-mapping.h>
11599d49deSDave Jiang #include <linux/prefetch.h>
12599d49deSDave Jiang #include "../dmaengine.h"
13599d49deSDave Jiang #include "registers.h"
14599d49deSDave Jiang #include "hw.h"
15599d49deSDave Jiang #include "dma.h"
16599d49deSDave Jiang
178319f84aSTim Gardner #define MAX_SCF 256
187b7d0ca7SDave Jiang
19599d49deSDave Jiang /* provide a lookup table for setting the source address in the base or
20599d49deSDave Jiang * extended descriptor of an xor or pq descriptor
21599d49deSDave Jiang */
22599d49deSDave Jiang static const u8 xor_idx_to_desc = 0xe0;
23599d49deSDave Jiang static const u8 xor_idx_to_field[] = { 1, 4, 5, 6, 7, 0, 1, 2 };
24599d49deSDave Jiang static const u8 pq_idx_to_desc = 0xf8;
25599d49deSDave Jiang static const u8 pq16_idx_to_desc[] = { 0, 0, 1, 1, 1, 1, 1, 1, 1,
26599d49deSDave Jiang 2, 2, 2, 2, 2, 2, 2 };
27599d49deSDave Jiang static const u8 pq_idx_to_field[] = { 1, 4, 5, 0, 1, 2, 4, 5 };
28599d49deSDave Jiang static const u8 pq16_idx_to_field[] = { 1, 4, 1, 2, 3, 4, 5, 6, 7,
29599d49deSDave Jiang 0, 1, 2, 3, 4, 5, 6 };
30599d49deSDave Jiang
xor_set_src(struct ioat_raw_descriptor * descs[2],dma_addr_t addr,u32 offset,int idx)31599d49deSDave Jiang static void xor_set_src(struct ioat_raw_descriptor *descs[2],
32599d49deSDave Jiang dma_addr_t addr, u32 offset, int idx)
33599d49deSDave Jiang {
34599d49deSDave Jiang struct ioat_raw_descriptor *raw = descs[xor_idx_to_desc >> idx & 1];
35599d49deSDave Jiang
36599d49deSDave Jiang raw->field[xor_idx_to_field[idx]] = addr + offset;
37599d49deSDave Jiang }
38599d49deSDave Jiang
pq_get_src(struct ioat_raw_descriptor * descs[2],int idx)39599d49deSDave Jiang static dma_addr_t pq_get_src(struct ioat_raw_descriptor *descs[2], int idx)
40599d49deSDave Jiang {
41599d49deSDave Jiang struct ioat_raw_descriptor *raw = descs[pq_idx_to_desc >> idx & 1];
42599d49deSDave Jiang
43599d49deSDave Jiang return raw->field[pq_idx_to_field[idx]];
44599d49deSDave Jiang }
45599d49deSDave Jiang
pq16_get_src(struct ioat_raw_descriptor * desc[3],int idx)46599d49deSDave Jiang static dma_addr_t pq16_get_src(struct ioat_raw_descriptor *desc[3], int idx)
47599d49deSDave Jiang {
48599d49deSDave Jiang struct ioat_raw_descriptor *raw = desc[pq16_idx_to_desc[idx]];
49599d49deSDave Jiang
50599d49deSDave Jiang return raw->field[pq16_idx_to_field[idx]];
51599d49deSDave Jiang }
52599d49deSDave Jiang
pq_set_src(struct ioat_raw_descriptor * descs[2],dma_addr_t addr,u32 offset,u8 coef,int idx)53599d49deSDave Jiang static void pq_set_src(struct ioat_raw_descriptor *descs[2],
54599d49deSDave Jiang dma_addr_t addr, u32 offset, u8 coef, int idx)
55599d49deSDave Jiang {
56599d49deSDave Jiang struct ioat_pq_descriptor *pq = (struct ioat_pq_descriptor *) descs[0];
57599d49deSDave Jiang struct ioat_raw_descriptor *raw = descs[pq_idx_to_desc >> idx & 1];
58599d49deSDave Jiang
59599d49deSDave Jiang raw->field[pq_idx_to_field[idx]] = addr + offset;
60599d49deSDave Jiang pq->coef[idx] = coef;
61599d49deSDave Jiang }
62599d49deSDave Jiang
pq16_set_src(struct ioat_raw_descriptor * desc[3],dma_addr_t addr,u32 offset,u8 coef,unsigned idx)63599d49deSDave Jiang static void pq16_set_src(struct ioat_raw_descriptor *desc[3],
64599d49deSDave Jiang dma_addr_t addr, u32 offset, u8 coef, unsigned idx)
65599d49deSDave Jiang {
66599d49deSDave Jiang struct ioat_pq_descriptor *pq = (struct ioat_pq_descriptor *)desc[0];
67599d49deSDave Jiang struct ioat_pq16a_descriptor *pq16 =
68599d49deSDave Jiang (struct ioat_pq16a_descriptor *)desc[1];
69599d49deSDave Jiang struct ioat_raw_descriptor *raw = desc[pq16_idx_to_desc[idx]];
70599d49deSDave Jiang
71599d49deSDave Jiang raw->field[pq16_idx_to_field[idx]] = addr + offset;
72599d49deSDave Jiang
73599d49deSDave Jiang if (idx < 8)
74599d49deSDave Jiang pq->coef[idx] = coef;
75599d49deSDave Jiang else
76599d49deSDave Jiang pq16->coef[idx - 8] = coef;
77599d49deSDave Jiang }
78599d49deSDave Jiang
79599d49deSDave Jiang static struct ioat_sed_ent *
ioat3_alloc_sed(struct ioatdma_device * ioat_dma,unsigned int hw_pool)80599d49deSDave Jiang ioat3_alloc_sed(struct ioatdma_device *ioat_dma, unsigned int hw_pool)
81599d49deSDave Jiang {
82599d49deSDave Jiang struct ioat_sed_ent *sed;
83599d49deSDave Jiang gfp_t flags = __GFP_ZERO | GFP_ATOMIC;
84599d49deSDave Jiang
85599d49deSDave Jiang sed = kmem_cache_alloc(ioat_sed_cache, flags);
86599d49deSDave Jiang if (!sed)
87599d49deSDave Jiang return NULL;
88599d49deSDave Jiang
89599d49deSDave Jiang sed->hw_pool = hw_pool;
90599d49deSDave Jiang sed->hw = dma_pool_alloc(ioat_dma->sed_hw_pool[hw_pool],
91599d49deSDave Jiang flags, &sed->dma);
92599d49deSDave Jiang if (!sed->hw) {
93599d49deSDave Jiang kmem_cache_free(ioat_sed_cache, sed);
94599d49deSDave Jiang return NULL;
95599d49deSDave Jiang }
96599d49deSDave Jiang
97599d49deSDave Jiang return sed;
98599d49deSDave Jiang }
99599d49deSDave Jiang
100599d49deSDave Jiang struct dma_async_tx_descriptor *
ioat_dma_prep_memcpy_lock(struct dma_chan * c,dma_addr_t dma_dest,dma_addr_t dma_src,size_t len,unsigned long flags)101599d49deSDave Jiang ioat_dma_prep_memcpy_lock(struct dma_chan *c, dma_addr_t dma_dest,
102599d49deSDave Jiang dma_addr_t dma_src, size_t len, unsigned long flags)
103599d49deSDave Jiang {
104599d49deSDave Jiang struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
105599d49deSDave Jiang struct ioat_dma_descriptor *hw;
106599d49deSDave Jiang struct ioat_ring_ent *desc;
107599d49deSDave Jiang dma_addr_t dst = dma_dest;
108599d49deSDave Jiang dma_addr_t src = dma_src;
109599d49deSDave Jiang size_t total_len = len;
110599d49deSDave Jiang int num_descs, idx, i;
111599d49deSDave Jiang
112ad4a7b50SDave Jiang if (test_bit(IOAT_CHAN_DOWN, &ioat_chan->state))
113ad4a7b50SDave Jiang return NULL;
114ad4a7b50SDave Jiang
115599d49deSDave Jiang num_descs = ioat_xferlen_to_descs(ioat_chan, len);
116599d49deSDave Jiang if (likely(num_descs) &&
117599d49deSDave Jiang ioat_check_space_lock(ioat_chan, num_descs) == 0)
118599d49deSDave Jiang idx = ioat_chan->head;
119599d49deSDave Jiang else
120599d49deSDave Jiang return NULL;
121599d49deSDave Jiang i = 0;
122599d49deSDave Jiang do {
123599d49deSDave Jiang size_t copy = min_t(size_t, len, 1 << ioat_chan->xfercap_log);
124599d49deSDave Jiang
125599d49deSDave Jiang desc = ioat_get_ring_ent(ioat_chan, idx + i);
126599d49deSDave Jiang hw = desc->hw;
127599d49deSDave Jiang
128599d49deSDave Jiang hw->size = copy;
129599d49deSDave Jiang hw->ctl = 0;
130599d49deSDave Jiang hw->src_addr = src;
131599d49deSDave Jiang hw->dst_addr = dst;
132599d49deSDave Jiang
133599d49deSDave Jiang len -= copy;
134599d49deSDave Jiang dst += copy;
135599d49deSDave Jiang src += copy;
136599d49deSDave Jiang dump_desc_dbg(ioat_chan, desc);
137599d49deSDave Jiang } while (++i < num_descs);
138599d49deSDave Jiang
139599d49deSDave Jiang desc->txd.flags = flags;
140599d49deSDave Jiang desc->len = total_len;
141599d49deSDave Jiang hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
142599d49deSDave Jiang hw->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
143599d49deSDave Jiang hw->ctl_f.compl_write = 1;
144599d49deSDave Jiang dump_desc_dbg(ioat_chan, desc);
145599d49deSDave Jiang /* we leave the channel locked to ensure in order submission */
146599d49deSDave Jiang
147599d49deSDave Jiang return &desc->txd;
148599d49deSDave Jiang }
149599d49deSDave Jiang
150599d49deSDave Jiang
151599d49deSDave Jiang static struct dma_async_tx_descriptor *
__ioat_prep_xor_lock(struct dma_chan * c,enum sum_check_flags * result,dma_addr_t dest,dma_addr_t * src,unsigned int src_cnt,size_t len,unsigned long flags)152599d49deSDave Jiang __ioat_prep_xor_lock(struct dma_chan *c, enum sum_check_flags *result,
153599d49deSDave Jiang dma_addr_t dest, dma_addr_t *src, unsigned int src_cnt,
154599d49deSDave Jiang size_t len, unsigned long flags)
155599d49deSDave Jiang {
156599d49deSDave Jiang struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
157599d49deSDave Jiang struct ioat_ring_ent *compl_desc;
158599d49deSDave Jiang struct ioat_ring_ent *desc;
159599d49deSDave Jiang struct ioat_ring_ent *ext;
160599d49deSDave Jiang size_t total_len = len;
161599d49deSDave Jiang struct ioat_xor_descriptor *xor;
162599d49deSDave Jiang struct ioat_xor_ext_descriptor *xor_ex = NULL;
163599d49deSDave Jiang struct ioat_dma_descriptor *hw;
164599d49deSDave Jiang int num_descs, with_ext, idx, i;
165599d49deSDave Jiang u32 offset = 0;
166599d49deSDave Jiang u8 op = result ? IOAT_OP_XOR_VAL : IOAT_OP_XOR;
167599d49deSDave Jiang
168599d49deSDave Jiang BUG_ON(src_cnt < 2);
169599d49deSDave Jiang
170599d49deSDave Jiang num_descs = ioat_xferlen_to_descs(ioat_chan, len);
171599d49deSDave Jiang /* we need 2x the number of descriptors to cover greater than 5
172599d49deSDave Jiang * sources
173599d49deSDave Jiang */
174599d49deSDave Jiang if (src_cnt > 5) {
175599d49deSDave Jiang with_ext = 1;
176599d49deSDave Jiang num_descs *= 2;
177599d49deSDave Jiang } else
178599d49deSDave Jiang with_ext = 0;
179599d49deSDave Jiang
180599d49deSDave Jiang /* completion writes from the raid engine may pass completion
181599d49deSDave Jiang * writes from the legacy engine, so we need one extra null
182599d49deSDave Jiang * (legacy) descriptor to ensure all completion writes arrive in
183599d49deSDave Jiang * order.
184599d49deSDave Jiang */
185599d49deSDave Jiang if (likely(num_descs) &&
186599d49deSDave Jiang ioat_check_space_lock(ioat_chan, num_descs+1) == 0)
187599d49deSDave Jiang idx = ioat_chan->head;
188599d49deSDave Jiang else
189599d49deSDave Jiang return NULL;
190599d49deSDave Jiang i = 0;
191599d49deSDave Jiang do {
192599d49deSDave Jiang struct ioat_raw_descriptor *descs[2];
193599d49deSDave Jiang size_t xfer_size = min_t(size_t,
194599d49deSDave Jiang len, 1 << ioat_chan->xfercap_log);
195599d49deSDave Jiang int s;
196599d49deSDave Jiang
197599d49deSDave Jiang desc = ioat_get_ring_ent(ioat_chan, idx + i);
198599d49deSDave Jiang xor = desc->xor;
199599d49deSDave Jiang
200599d49deSDave Jiang /* save a branch by unconditionally retrieving the
201599d49deSDave Jiang * extended descriptor xor_set_src() knows to not write
202599d49deSDave Jiang * to it in the single descriptor case
203599d49deSDave Jiang */
204599d49deSDave Jiang ext = ioat_get_ring_ent(ioat_chan, idx + i + 1);
205599d49deSDave Jiang xor_ex = ext->xor_ex;
206599d49deSDave Jiang
207599d49deSDave Jiang descs[0] = (struct ioat_raw_descriptor *) xor;
208599d49deSDave Jiang descs[1] = (struct ioat_raw_descriptor *) xor_ex;
209599d49deSDave Jiang for (s = 0; s < src_cnt; s++)
210599d49deSDave Jiang xor_set_src(descs, src[s], offset, s);
211599d49deSDave Jiang xor->size = xfer_size;
212599d49deSDave Jiang xor->dst_addr = dest + offset;
213599d49deSDave Jiang xor->ctl = 0;
214599d49deSDave Jiang xor->ctl_f.op = op;
215599d49deSDave Jiang xor->ctl_f.src_cnt = src_cnt_to_hw(src_cnt);
216599d49deSDave Jiang
217599d49deSDave Jiang len -= xfer_size;
218599d49deSDave Jiang offset += xfer_size;
219599d49deSDave Jiang dump_desc_dbg(ioat_chan, desc);
220599d49deSDave Jiang } while ((i += 1 + with_ext) < num_descs);
221599d49deSDave Jiang
222599d49deSDave Jiang /* last xor descriptor carries the unmap parameters and fence bit */
223599d49deSDave Jiang desc->txd.flags = flags;
224599d49deSDave Jiang desc->len = total_len;
225599d49deSDave Jiang if (result)
226599d49deSDave Jiang desc->result = result;
227599d49deSDave Jiang xor->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
228599d49deSDave Jiang
229599d49deSDave Jiang /* completion descriptor carries interrupt bit */
230599d49deSDave Jiang compl_desc = ioat_get_ring_ent(ioat_chan, idx + i);
231599d49deSDave Jiang compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT;
232599d49deSDave Jiang hw = compl_desc->hw;
233599d49deSDave Jiang hw->ctl = 0;
234599d49deSDave Jiang hw->ctl_f.null = 1;
235599d49deSDave Jiang hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
236599d49deSDave Jiang hw->ctl_f.compl_write = 1;
237599d49deSDave Jiang hw->size = NULL_DESC_BUFFER_SIZE;
238599d49deSDave Jiang dump_desc_dbg(ioat_chan, compl_desc);
239599d49deSDave Jiang
240599d49deSDave Jiang /* we leave the channel locked to ensure in order submission */
241599d49deSDave Jiang return &compl_desc->txd;
242599d49deSDave Jiang }
243599d49deSDave Jiang
244599d49deSDave Jiang struct dma_async_tx_descriptor *
ioat_prep_xor(struct dma_chan * chan,dma_addr_t dest,dma_addr_t * src,unsigned int src_cnt,size_t len,unsigned long flags)245599d49deSDave Jiang ioat_prep_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
246599d49deSDave Jiang unsigned int src_cnt, size_t len, unsigned long flags)
247599d49deSDave Jiang {
248ad4a7b50SDave Jiang struct ioatdma_chan *ioat_chan = to_ioat_chan(chan);
249ad4a7b50SDave Jiang
250ad4a7b50SDave Jiang if (test_bit(IOAT_CHAN_DOWN, &ioat_chan->state))
251ad4a7b50SDave Jiang return NULL;
252ad4a7b50SDave Jiang
253599d49deSDave Jiang return __ioat_prep_xor_lock(chan, NULL, dest, src, src_cnt, len, flags);
254599d49deSDave Jiang }
255599d49deSDave Jiang
256599d49deSDave Jiang struct dma_async_tx_descriptor *
ioat_prep_xor_val(struct dma_chan * chan,dma_addr_t * src,unsigned int src_cnt,size_t len,enum sum_check_flags * result,unsigned long flags)257599d49deSDave Jiang ioat_prep_xor_val(struct dma_chan *chan, dma_addr_t *src,
258599d49deSDave Jiang unsigned int src_cnt, size_t len,
259599d49deSDave Jiang enum sum_check_flags *result, unsigned long flags)
260599d49deSDave Jiang {
261ad4a7b50SDave Jiang struct ioatdma_chan *ioat_chan = to_ioat_chan(chan);
262ad4a7b50SDave Jiang
263ad4a7b50SDave Jiang if (test_bit(IOAT_CHAN_DOWN, &ioat_chan->state))
264ad4a7b50SDave Jiang return NULL;
265ad4a7b50SDave Jiang
266599d49deSDave Jiang /* the cleanup routine only sets bits on validate failure, it
267599d49deSDave Jiang * does not clear bits on validate success... so clear it here
268599d49deSDave Jiang */
269599d49deSDave Jiang *result = 0;
270599d49deSDave Jiang
271599d49deSDave Jiang return __ioat_prep_xor_lock(chan, result, src[0], &src[1],
272599d49deSDave Jiang src_cnt - 1, len, flags);
273599d49deSDave Jiang }
274599d49deSDave Jiang
275599d49deSDave Jiang static void
dump_pq_desc_dbg(struct ioatdma_chan * ioat_chan,struct ioat_ring_ent * desc,struct ioat_ring_ent * ext)276599d49deSDave Jiang dump_pq_desc_dbg(struct ioatdma_chan *ioat_chan, struct ioat_ring_ent *desc,
277599d49deSDave Jiang struct ioat_ring_ent *ext)
278599d49deSDave Jiang {
279599d49deSDave Jiang struct device *dev = to_dev(ioat_chan);
280599d49deSDave Jiang struct ioat_pq_descriptor *pq = desc->pq;
281599d49deSDave Jiang struct ioat_pq_ext_descriptor *pq_ex = ext ? ext->pq_ex : NULL;
282599d49deSDave Jiang struct ioat_raw_descriptor *descs[] = { (void *) pq, (void *) pq_ex };
283599d49deSDave Jiang int src_cnt = src_cnt_to_sw(pq->ctl_f.src_cnt);
284599d49deSDave Jiang int i;
285599d49deSDave Jiang
286599d49deSDave Jiang dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x"
287599d49deSDave Jiang " sz: %#10.8x ctl: %#x (op: %#x int: %d compl: %d pq: '%s%s'"
288599d49deSDave Jiang " src_cnt: %d)\n",
289599d49deSDave Jiang desc_id(desc), (unsigned long long) desc->txd.phys,
290599d49deSDave Jiang (unsigned long long) (pq_ex ? pq_ex->next : pq->next),
291599d49deSDave Jiang desc->txd.flags, pq->size, pq->ctl, pq->ctl_f.op,
292599d49deSDave Jiang pq->ctl_f.int_en, pq->ctl_f.compl_write,
293599d49deSDave Jiang pq->ctl_f.p_disable ? "" : "p", pq->ctl_f.q_disable ? "" : "q",
294599d49deSDave Jiang pq->ctl_f.src_cnt);
295599d49deSDave Jiang for (i = 0; i < src_cnt; i++)
296599d49deSDave Jiang dev_dbg(dev, "\tsrc[%d]: %#llx coef: %#x\n", i,
297599d49deSDave Jiang (unsigned long long) pq_get_src(descs, i), pq->coef[i]);
298599d49deSDave Jiang dev_dbg(dev, "\tP: %#llx\n", pq->p_addr);
299599d49deSDave Jiang dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr);
300599d49deSDave Jiang dev_dbg(dev, "\tNEXT: %#llx\n", pq->next);
301599d49deSDave Jiang }
302599d49deSDave Jiang
dump_pq16_desc_dbg(struct ioatdma_chan * ioat_chan,struct ioat_ring_ent * desc)303599d49deSDave Jiang static void dump_pq16_desc_dbg(struct ioatdma_chan *ioat_chan,
304599d49deSDave Jiang struct ioat_ring_ent *desc)
305599d49deSDave Jiang {
306599d49deSDave Jiang struct device *dev = to_dev(ioat_chan);
307599d49deSDave Jiang struct ioat_pq_descriptor *pq = desc->pq;
308599d49deSDave Jiang struct ioat_raw_descriptor *descs[] = { (void *)pq,
309599d49deSDave Jiang (void *)pq,
310599d49deSDave Jiang (void *)pq };
311599d49deSDave Jiang int src_cnt = src16_cnt_to_sw(pq->ctl_f.src_cnt);
312599d49deSDave Jiang int i;
313599d49deSDave Jiang
314599d49deSDave Jiang if (desc->sed) {
315599d49deSDave Jiang descs[1] = (void *)desc->sed->hw;
316599d49deSDave Jiang descs[2] = (void *)desc->sed->hw + 64;
317599d49deSDave Jiang }
318599d49deSDave Jiang
319599d49deSDave Jiang dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x"
320599d49deSDave Jiang " sz: %#x ctl: %#x (op: %#x int: %d compl: %d pq: '%s%s'"
321599d49deSDave Jiang " src_cnt: %d)\n",
322599d49deSDave Jiang desc_id(desc), (unsigned long long) desc->txd.phys,
323599d49deSDave Jiang (unsigned long long) pq->next,
324599d49deSDave Jiang desc->txd.flags, pq->size, pq->ctl,
325599d49deSDave Jiang pq->ctl_f.op, pq->ctl_f.int_en,
326599d49deSDave Jiang pq->ctl_f.compl_write,
327599d49deSDave Jiang pq->ctl_f.p_disable ? "" : "p", pq->ctl_f.q_disable ? "" : "q",
328599d49deSDave Jiang pq->ctl_f.src_cnt);
329599d49deSDave Jiang for (i = 0; i < src_cnt; i++) {
330599d49deSDave Jiang dev_dbg(dev, "\tsrc[%d]: %#llx coef: %#x\n", i,
331599d49deSDave Jiang (unsigned long long) pq16_get_src(descs, i),
332599d49deSDave Jiang pq->coef[i]);
333599d49deSDave Jiang }
334599d49deSDave Jiang dev_dbg(dev, "\tP: %#llx\n", pq->p_addr);
335599d49deSDave Jiang dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr);
336599d49deSDave Jiang }
337599d49deSDave Jiang
338599d49deSDave Jiang static struct dma_async_tx_descriptor *
__ioat_prep_pq_lock(struct dma_chan * c,enum sum_check_flags * result,const dma_addr_t * dst,const dma_addr_t * src,unsigned int src_cnt,const unsigned char * scf,size_t len,unsigned long flags)339599d49deSDave Jiang __ioat_prep_pq_lock(struct dma_chan *c, enum sum_check_flags *result,
340599d49deSDave Jiang const dma_addr_t *dst, const dma_addr_t *src,
341599d49deSDave Jiang unsigned int src_cnt, const unsigned char *scf,
342599d49deSDave Jiang size_t len, unsigned long flags)
343599d49deSDave Jiang {
344599d49deSDave Jiang struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
345599d49deSDave Jiang struct ioatdma_device *ioat_dma = ioat_chan->ioat_dma;
346599d49deSDave Jiang struct ioat_ring_ent *compl_desc;
347599d49deSDave Jiang struct ioat_ring_ent *desc;
348599d49deSDave Jiang struct ioat_ring_ent *ext;
349599d49deSDave Jiang size_t total_len = len;
350599d49deSDave Jiang struct ioat_pq_descriptor *pq;
351599d49deSDave Jiang struct ioat_pq_ext_descriptor *pq_ex = NULL;
352599d49deSDave Jiang struct ioat_dma_descriptor *hw;
353599d49deSDave Jiang u32 offset = 0;
354599d49deSDave Jiang u8 op = result ? IOAT_OP_PQ_VAL : IOAT_OP_PQ;
355599d49deSDave Jiang int i, s, idx, with_ext, num_descs;
356599d49deSDave Jiang int cb32 = (ioat_dma->version < IOAT_VER_3_3) ? 1 : 0;
357599d49deSDave Jiang
358599d49deSDave Jiang dev_dbg(to_dev(ioat_chan), "%s\n", __func__);
359599d49deSDave Jiang /* the engine requires at least two sources (we provide
360599d49deSDave Jiang * at least 1 implied source in the DMA_PREP_CONTINUE case)
361599d49deSDave Jiang */
362599d49deSDave Jiang BUG_ON(src_cnt + dmaf_continue(flags) < 2);
363599d49deSDave Jiang
364599d49deSDave Jiang num_descs = ioat_xferlen_to_descs(ioat_chan, len);
365599d49deSDave Jiang /* we need 2x the number of descriptors to cover greater than 3
366599d49deSDave Jiang * sources (we need 1 extra source in the q-only continuation
367599d49deSDave Jiang * case and 3 extra sources in the p+q continuation case.
368599d49deSDave Jiang */
369599d49deSDave Jiang if (src_cnt + dmaf_p_disabled_continue(flags) > 3 ||
370599d49deSDave Jiang (dmaf_continue(flags) && !dmaf_p_disabled_continue(flags))) {
371599d49deSDave Jiang with_ext = 1;
372599d49deSDave Jiang num_descs *= 2;
373599d49deSDave Jiang } else
374599d49deSDave Jiang with_ext = 0;
375599d49deSDave Jiang
376599d49deSDave Jiang /* completion writes from the raid engine may pass completion
377599d49deSDave Jiang * writes from the legacy engine, so we need one extra null
378599d49deSDave Jiang * (legacy) descriptor to ensure all completion writes arrive in
379599d49deSDave Jiang * order.
380599d49deSDave Jiang */
381599d49deSDave Jiang if (likely(num_descs) &&
382599d49deSDave Jiang ioat_check_space_lock(ioat_chan, num_descs + cb32) == 0)
383599d49deSDave Jiang idx = ioat_chan->head;
384599d49deSDave Jiang else
385599d49deSDave Jiang return NULL;
386599d49deSDave Jiang i = 0;
387599d49deSDave Jiang do {
388599d49deSDave Jiang struct ioat_raw_descriptor *descs[2];
389599d49deSDave Jiang size_t xfer_size = min_t(size_t, len,
390599d49deSDave Jiang 1 << ioat_chan->xfercap_log);
391599d49deSDave Jiang
392599d49deSDave Jiang desc = ioat_get_ring_ent(ioat_chan, idx + i);
393599d49deSDave Jiang pq = desc->pq;
394599d49deSDave Jiang
395599d49deSDave Jiang /* save a branch by unconditionally retrieving the
396599d49deSDave Jiang * extended descriptor pq_set_src() knows to not write
397599d49deSDave Jiang * to it in the single descriptor case
398599d49deSDave Jiang */
399599d49deSDave Jiang ext = ioat_get_ring_ent(ioat_chan, idx + i + with_ext);
400599d49deSDave Jiang pq_ex = ext->pq_ex;
401599d49deSDave Jiang
402599d49deSDave Jiang descs[0] = (struct ioat_raw_descriptor *) pq;
403599d49deSDave Jiang descs[1] = (struct ioat_raw_descriptor *) pq_ex;
404599d49deSDave Jiang
405599d49deSDave Jiang for (s = 0; s < src_cnt; s++)
406599d49deSDave Jiang pq_set_src(descs, src[s], offset, scf[s], s);
407599d49deSDave Jiang
408599d49deSDave Jiang /* see the comment for dma_maxpq in include/linux/dmaengine.h */
409599d49deSDave Jiang if (dmaf_p_disabled_continue(flags))
410599d49deSDave Jiang pq_set_src(descs, dst[1], offset, 1, s++);
411599d49deSDave Jiang else if (dmaf_continue(flags)) {
412599d49deSDave Jiang pq_set_src(descs, dst[0], offset, 0, s++);
413599d49deSDave Jiang pq_set_src(descs, dst[1], offset, 1, s++);
414599d49deSDave Jiang pq_set_src(descs, dst[1], offset, 0, s++);
415599d49deSDave Jiang }
416599d49deSDave Jiang pq->size = xfer_size;
417599d49deSDave Jiang pq->p_addr = dst[0] + offset;
418599d49deSDave Jiang pq->q_addr = dst[1] + offset;
419599d49deSDave Jiang pq->ctl = 0;
420599d49deSDave Jiang pq->ctl_f.op = op;
421599d49deSDave Jiang /* we turn on descriptor write back error status */
422599d49deSDave Jiang if (ioat_dma->cap & IOAT_CAP_DWBES)
423599d49deSDave Jiang pq->ctl_f.wb_en = result ? 1 : 0;
424599d49deSDave Jiang pq->ctl_f.src_cnt = src_cnt_to_hw(s);
425599d49deSDave Jiang pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P);
426599d49deSDave Jiang pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q);
427599d49deSDave Jiang
428599d49deSDave Jiang len -= xfer_size;
429599d49deSDave Jiang offset += xfer_size;
430599d49deSDave Jiang } while ((i += 1 + with_ext) < num_descs);
431599d49deSDave Jiang
432599d49deSDave Jiang /* last pq descriptor carries the unmap parameters and fence bit */
433599d49deSDave Jiang desc->txd.flags = flags;
434599d49deSDave Jiang desc->len = total_len;
435599d49deSDave Jiang if (result)
436599d49deSDave Jiang desc->result = result;
437599d49deSDave Jiang pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
438599d49deSDave Jiang dump_pq_desc_dbg(ioat_chan, desc, ext);
439599d49deSDave Jiang
440599d49deSDave Jiang if (!cb32) {
441599d49deSDave Jiang pq->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
442599d49deSDave Jiang pq->ctl_f.compl_write = 1;
443599d49deSDave Jiang compl_desc = desc;
444599d49deSDave Jiang } else {
445599d49deSDave Jiang /* completion descriptor carries interrupt bit */
446599d49deSDave Jiang compl_desc = ioat_get_ring_ent(ioat_chan, idx + i);
447599d49deSDave Jiang compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT;
448599d49deSDave Jiang hw = compl_desc->hw;
449599d49deSDave Jiang hw->ctl = 0;
450599d49deSDave Jiang hw->ctl_f.null = 1;
451599d49deSDave Jiang hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
452599d49deSDave Jiang hw->ctl_f.compl_write = 1;
453599d49deSDave Jiang hw->size = NULL_DESC_BUFFER_SIZE;
454599d49deSDave Jiang dump_desc_dbg(ioat_chan, compl_desc);
455599d49deSDave Jiang }
456599d49deSDave Jiang
457599d49deSDave Jiang
458599d49deSDave Jiang /* we leave the channel locked to ensure in order submission */
459599d49deSDave Jiang return &compl_desc->txd;
460599d49deSDave Jiang }
461599d49deSDave Jiang
462599d49deSDave Jiang static struct dma_async_tx_descriptor *
__ioat_prep_pq16_lock(struct dma_chan * c,enum sum_check_flags * result,const dma_addr_t * dst,const dma_addr_t * src,unsigned int src_cnt,const unsigned char * scf,size_t len,unsigned long flags)463599d49deSDave Jiang __ioat_prep_pq16_lock(struct dma_chan *c, enum sum_check_flags *result,
464599d49deSDave Jiang const dma_addr_t *dst, const dma_addr_t *src,
465599d49deSDave Jiang unsigned int src_cnt, const unsigned char *scf,
466599d49deSDave Jiang size_t len, unsigned long flags)
467599d49deSDave Jiang {
468599d49deSDave Jiang struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
469599d49deSDave Jiang struct ioatdma_device *ioat_dma = ioat_chan->ioat_dma;
470599d49deSDave Jiang struct ioat_ring_ent *desc;
471599d49deSDave Jiang size_t total_len = len;
472599d49deSDave Jiang struct ioat_pq_descriptor *pq;
473599d49deSDave Jiang u32 offset = 0;
474599d49deSDave Jiang u8 op;
475599d49deSDave Jiang int i, s, idx, num_descs;
476599d49deSDave Jiang
477599d49deSDave Jiang /* this function is only called with 9-16 sources */
478599d49deSDave Jiang op = result ? IOAT_OP_PQ_VAL_16S : IOAT_OP_PQ_16S;
479599d49deSDave Jiang
480599d49deSDave Jiang dev_dbg(to_dev(ioat_chan), "%s\n", __func__);
481599d49deSDave Jiang
482599d49deSDave Jiang num_descs = ioat_xferlen_to_descs(ioat_chan, len);
483599d49deSDave Jiang
484599d49deSDave Jiang /*
485599d49deSDave Jiang * 16 source pq is only available on cb3.3 and has no completion
486599d49deSDave Jiang * write hw bug.
487599d49deSDave Jiang */
488599d49deSDave Jiang if (num_descs && ioat_check_space_lock(ioat_chan, num_descs) == 0)
489599d49deSDave Jiang idx = ioat_chan->head;
490599d49deSDave Jiang else
491599d49deSDave Jiang return NULL;
492599d49deSDave Jiang
493599d49deSDave Jiang i = 0;
494599d49deSDave Jiang
495599d49deSDave Jiang do {
496599d49deSDave Jiang struct ioat_raw_descriptor *descs[4];
497599d49deSDave Jiang size_t xfer_size = min_t(size_t, len,
498599d49deSDave Jiang 1 << ioat_chan->xfercap_log);
499599d49deSDave Jiang
500599d49deSDave Jiang desc = ioat_get_ring_ent(ioat_chan, idx + i);
501599d49deSDave Jiang pq = desc->pq;
502599d49deSDave Jiang
503599d49deSDave Jiang descs[0] = (struct ioat_raw_descriptor *) pq;
504599d49deSDave Jiang
505599d49deSDave Jiang desc->sed = ioat3_alloc_sed(ioat_dma, (src_cnt-2) >> 3);
506599d49deSDave Jiang if (!desc->sed) {
507599d49deSDave Jiang dev_err(to_dev(ioat_chan),
508599d49deSDave Jiang "%s: no free sed entries\n", __func__);
509599d49deSDave Jiang return NULL;
510599d49deSDave Jiang }
511599d49deSDave Jiang
512599d49deSDave Jiang pq->sed_addr = desc->sed->dma;
513599d49deSDave Jiang desc->sed->parent = desc;
514599d49deSDave Jiang
515599d49deSDave Jiang descs[1] = (struct ioat_raw_descriptor *)desc->sed->hw;
516599d49deSDave Jiang descs[2] = (void *)descs[1] + 64;
517599d49deSDave Jiang
518599d49deSDave Jiang for (s = 0; s < src_cnt; s++)
519599d49deSDave Jiang pq16_set_src(descs, src[s], offset, scf[s], s);
520599d49deSDave Jiang
521599d49deSDave Jiang /* see the comment for dma_maxpq in include/linux/dmaengine.h */
522599d49deSDave Jiang if (dmaf_p_disabled_continue(flags))
523599d49deSDave Jiang pq16_set_src(descs, dst[1], offset, 1, s++);
524599d49deSDave Jiang else if (dmaf_continue(flags)) {
525599d49deSDave Jiang pq16_set_src(descs, dst[0], offset, 0, s++);
526599d49deSDave Jiang pq16_set_src(descs, dst[1], offset, 1, s++);
527599d49deSDave Jiang pq16_set_src(descs, dst[1], offset, 0, s++);
528599d49deSDave Jiang }
529599d49deSDave Jiang
530599d49deSDave Jiang pq->size = xfer_size;
531599d49deSDave Jiang pq->p_addr = dst[0] + offset;
532599d49deSDave Jiang pq->q_addr = dst[1] + offset;
533599d49deSDave Jiang pq->ctl = 0;
534599d49deSDave Jiang pq->ctl_f.op = op;
535599d49deSDave Jiang pq->ctl_f.src_cnt = src16_cnt_to_hw(s);
536599d49deSDave Jiang /* we turn on descriptor write back error status */
537599d49deSDave Jiang if (ioat_dma->cap & IOAT_CAP_DWBES)
538599d49deSDave Jiang pq->ctl_f.wb_en = result ? 1 : 0;
539599d49deSDave Jiang pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P);
540599d49deSDave Jiang pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q);
541599d49deSDave Jiang
542599d49deSDave Jiang len -= xfer_size;
543599d49deSDave Jiang offset += xfer_size;
544599d49deSDave Jiang } while (++i < num_descs);
545599d49deSDave Jiang
546599d49deSDave Jiang /* last pq descriptor carries the unmap parameters and fence bit */
547599d49deSDave Jiang desc->txd.flags = flags;
548599d49deSDave Jiang desc->len = total_len;
549599d49deSDave Jiang if (result)
550599d49deSDave Jiang desc->result = result;
551599d49deSDave Jiang pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
552599d49deSDave Jiang
553599d49deSDave Jiang /* with cb3.3 we should be able to do completion w/o a null desc */
554599d49deSDave Jiang pq->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
555599d49deSDave Jiang pq->ctl_f.compl_write = 1;
556599d49deSDave Jiang
557599d49deSDave Jiang dump_pq16_desc_dbg(ioat_chan, desc);
558599d49deSDave Jiang
559599d49deSDave Jiang /* we leave the channel locked to ensure in order submission */
560599d49deSDave Jiang return &desc->txd;
561599d49deSDave Jiang }
562599d49deSDave Jiang
src_cnt_flags(unsigned int src_cnt,unsigned long flags)563599d49deSDave Jiang static int src_cnt_flags(unsigned int src_cnt, unsigned long flags)
564599d49deSDave Jiang {
565599d49deSDave Jiang if (dmaf_p_disabled_continue(flags))
566599d49deSDave Jiang return src_cnt + 1;
567599d49deSDave Jiang else if (dmaf_continue(flags))
568599d49deSDave Jiang return src_cnt + 3;
569599d49deSDave Jiang else
570599d49deSDave Jiang return src_cnt;
571599d49deSDave Jiang }
572599d49deSDave Jiang
573599d49deSDave Jiang struct dma_async_tx_descriptor *
ioat_prep_pq(struct dma_chan * chan,dma_addr_t * dst,dma_addr_t * src,unsigned int src_cnt,const unsigned char * scf,size_t len,unsigned long flags)574599d49deSDave Jiang ioat_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
575599d49deSDave Jiang unsigned int src_cnt, const unsigned char *scf, size_t len,
576599d49deSDave Jiang unsigned long flags)
577599d49deSDave Jiang {
578ad4a7b50SDave Jiang struct ioatdma_chan *ioat_chan = to_ioat_chan(chan);
579ad4a7b50SDave Jiang
580ad4a7b50SDave Jiang if (test_bit(IOAT_CHAN_DOWN, &ioat_chan->state))
581ad4a7b50SDave Jiang return NULL;
582ad4a7b50SDave Jiang
583599d49deSDave Jiang /* specify valid address for disabled result */
584599d49deSDave Jiang if (flags & DMA_PREP_PQ_DISABLE_P)
585599d49deSDave Jiang dst[0] = dst[1];
586599d49deSDave Jiang if (flags & DMA_PREP_PQ_DISABLE_Q)
587599d49deSDave Jiang dst[1] = dst[0];
588599d49deSDave Jiang
589599d49deSDave Jiang /* handle the single source multiply case from the raid6
590599d49deSDave Jiang * recovery path
591599d49deSDave Jiang */
592599d49deSDave Jiang if ((flags & DMA_PREP_PQ_DISABLE_P) && src_cnt == 1) {
593599d49deSDave Jiang dma_addr_t single_source[2];
594599d49deSDave Jiang unsigned char single_source_coef[2];
595599d49deSDave Jiang
596599d49deSDave Jiang BUG_ON(flags & DMA_PREP_PQ_DISABLE_Q);
597599d49deSDave Jiang single_source[0] = src[0];
598599d49deSDave Jiang single_source[1] = src[0];
599599d49deSDave Jiang single_source_coef[0] = scf[0];
600599d49deSDave Jiang single_source_coef[1] = 0;
601599d49deSDave Jiang
602599d49deSDave Jiang return src_cnt_flags(src_cnt, flags) > 8 ?
603599d49deSDave Jiang __ioat_prep_pq16_lock(chan, NULL, dst, single_source,
604599d49deSDave Jiang 2, single_source_coef, len,
605599d49deSDave Jiang flags) :
606599d49deSDave Jiang __ioat_prep_pq_lock(chan, NULL, dst, single_source, 2,
607599d49deSDave Jiang single_source_coef, len, flags);
608599d49deSDave Jiang
609599d49deSDave Jiang } else {
610599d49deSDave Jiang return src_cnt_flags(src_cnt, flags) > 8 ?
611599d49deSDave Jiang __ioat_prep_pq16_lock(chan, NULL, dst, src, src_cnt,
612599d49deSDave Jiang scf, len, flags) :
613599d49deSDave Jiang __ioat_prep_pq_lock(chan, NULL, dst, src, src_cnt,
614599d49deSDave Jiang scf, len, flags);
615599d49deSDave Jiang }
616599d49deSDave Jiang }
617599d49deSDave Jiang
618599d49deSDave Jiang struct dma_async_tx_descriptor *
ioat_prep_pq_val(struct dma_chan * chan,dma_addr_t * pq,dma_addr_t * src,unsigned int src_cnt,const unsigned char * scf,size_t len,enum sum_check_flags * pqres,unsigned long flags)619599d49deSDave Jiang ioat_prep_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
620599d49deSDave Jiang unsigned int src_cnt, const unsigned char *scf, size_t len,
621599d49deSDave Jiang enum sum_check_flags *pqres, unsigned long flags)
622599d49deSDave Jiang {
623ad4a7b50SDave Jiang struct ioatdma_chan *ioat_chan = to_ioat_chan(chan);
624ad4a7b50SDave Jiang
625ad4a7b50SDave Jiang if (test_bit(IOAT_CHAN_DOWN, &ioat_chan->state))
626ad4a7b50SDave Jiang return NULL;
627ad4a7b50SDave Jiang
628599d49deSDave Jiang /* specify valid address for disabled result */
629599d49deSDave Jiang if (flags & DMA_PREP_PQ_DISABLE_P)
630599d49deSDave Jiang pq[0] = pq[1];
631599d49deSDave Jiang if (flags & DMA_PREP_PQ_DISABLE_Q)
632599d49deSDave Jiang pq[1] = pq[0];
633599d49deSDave Jiang
634599d49deSDave Jiang /* the cleanup routine only sets bits on validate failure, it
635599d49deSDave Jiang * does not clear bits on validate success... so clear it here
636599d49deSDave Jiang */
637599d49deSDave Jiang *pqres = 0;
638599d49deSDave Jiang
639599d49deSDave Jiang return src_cnt_flags(src_cnt, flags) > 8 ?
640599d49deSDave Jiang __ioat_prep_pq16_lock(chan, pqres, pq, src, src_cnt, scf, len,
641599d49deSDave Jiang flags) :
642599d49deSDave Jiang __ioat_prep_pq_lock(chan, pqres, pq, src, src_cnt, scf, len,
643599d49deSDave Jiang flags);
644599d49deSDave Jiang }
645599d49deSDave Jiang
646599d49deSDave Jiang struct dma_async_tx_descriptor *
ioat_prep_pqxor(struct dma_chan * chan,dma_addr_t dst,dma_addr_t * src,unsigned int src_cnt,size_t len,unsigned long flags)647599d49deSDave Jiang ioat_prep_pqxor(struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
648599d49deSDave Jiang unsigned int src_cnt, size_t len, unsigned long flags)
649599d49deSDave Jiang {
6507b7d0ca7SDave Jiang unsigned char scf[MAX_SCF];
651599d49deSDave Jiang dma_addr_t pq[2];
652ad4a7b50SDave Jiang struct ioatdma_chan *ioat_chan = to_ioat_chan(chan);
653ad4a7b50SDave Jiang
654ad4a7b50SDave Jiang if (test_bit(IOAT_CHAN_DOWN, &ioat_chan->state))
655ad4a7b50SDave Jiang return NULL;
656599d49deSDave Jiang
6577b7d0ca7SDave Jiang if (src_cnt > MAX_SCF)
6587b7d0ca7SDave Jiang return NULL;
6597b7d0ca7SDave Jiang
660599d49deSDave Jiang memset(scf, 0, src_cnt);
661599d49deSDave Jiang pq[0] = dst;
662599d49deSDave Jiang flags |= DMA_PREP_PQ_DISABLE_Q;
663599d49deSDave Jiang pq[1] = dst; /* specify valid address for disabled result */
664599d49deSDave Jiang
665599d49deSDave Jiang return src_cnt_flags(src_cnt, flags) > 8 ?
666599d49deSDave Jiang __ioat_prep_pq16_lock(chan, NULL, pq, src, src_cnt, scf, len,
667599d49deSDave Jiang flags) :
668599d49deSDave Jiang __ioat_prep_pq_lock(chan, NULL, pq, src, src_cnt, scf, len,
669599d49deSDave Jiang flags);
670599d49deSDave Jiang }
671599d49deSDave Jiang
672599d49deSDave Jiang struct dma_async_tx_descriptor *
ioat_prep_pqxor_val(struct dma_chan * chan,dma_addr_t * src,unsigned int src_cnt,size_t len,enum sum_check_flags * result,unsigned long flags)673599d49deSDave Jiang ioat_prep_pqxor_val(struct dma_chan *chan, dma_addr_t *src,
674599d49deSDave Jiang unsigned int src_cnt, size_t len,
675599d49deSDave Jiang enum sum_check_flags *result, unsigned long flags)
676599d49deSDave Jiang {
6777b7d0ca7SDave Jiang unsigned char scf[MAX_SCF];
678599d49deSDave Jiang dma_addr_t pq[2];
679ad4a7b50SDave Jiang struct ioatdma_chan *ioat_chan = to_ioat_chan(chan);
680ad4a7b50SDave Jiang
681ad4a7b50SDave Jiang if (test_bit(IOAT_CHAN_DOWN, &ioat_chan->state))
682ad4a7b50SDave Jiang return NULL;
683599d49deSDave Jiang
6847b7d0ca7SDave Jiang if (src_cnt > MAX_SCF)
6857b7d0ca7SDave Jiang return NULL;
6867b7d0ca7SDave Jiang
687599d49deSDave Jiang /* the cleanup routine only sets bits on validate failure, it
688599d49deSDave Jiang * does not clear bits on validate success... so clear it here
689599d49deSDave Jiang */
690599d49deSDave Jiang *result = 0;
691599d49deSDave Jiang
692599d49deSDave Jiang memset(scf, 0, src_cnt);
693599d49deSDave Jiang pq[0] = src[0];
694599d49deSDave Jiang flags |= DMA_PREP_PQ_DISABLE_Q;
695599d49deSDave Jiang pq[1] = pq[0]; /* specify valid address for disabled result */
696599d49deSDave Jiang
697599d49deSDave Jiang return src_cnt_flags(src_cnt, flags) > 8 ?
698599d49deSDave Jiang __ioat_prep_pq16_lock(chan, result, pq, &src[1], src_cnt - 1,
699599d49deSDave Jiang scf, len, flags) :
700599d49deSDave Jiang __ioat_prep_pq_lock(chan, result, pq, &src[1], src_cnt - 1,
701599d49deSDave Jiang scf, len, flags);
702599d49deSDave Jiang }
703599d49deSDave Jiang
704599d49deSDave Jiang struct dma_async_tx_descriptor *
ioat_prep_interrupt_lock(struct dma_chan * c,unsigned long flags)705599d49deSDave Jiang ioat_prep_interrupt_lock(struct dma_chan *c, unsigned long flags)
706599d49deSDave Jiang {
707599d49deSDave Jiang struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
708599d49deSDave Jiang struct ioat_ring_ent *desc;
709599d49deSDave Jiang struct ioat_dma_descriptor *hw;
710599d49deSDave Jiang
711ad4a7b50SDave Jiang if (test_bit(IOAT_CHAN_DOWN, &ioat_chan->state))
712ad4a7b50SDave Jiang return NULL;
713ad4a7b50SDave Jiang
714599d49deSDave Jiang if (ioat_check_space_lock(ioat_chan, 1) == 0)
715599d49deSDave Jiang desc = ioat_get_ring_ent(ioat_chan, ioat_chan->head);
716599d49deSDave Jiang else
717599d49deSDave Jiang return NULL;
718599d49deSDave Jiang
719599d49deSDave Jiang hw = desc->hw;
720599d49deSDave Jiang hw->ctl = 0;
721599d49deSDave Jiang hw->ctl_f.null = 1;
722599d49deSDave Jiang hw->ctl_f.int_en = 1;
723599d49deSDave Jiang hw->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
724599d49deSDave Jiang hw->ctl_f.compl_write = 1;
725599d49deSDave Jiang hw->size = NULL_DESC_BUFFER_SIZE;
726599d49deSDave Jiang hw->src_addr = 0;
727599d49deSDave Jiang hw->dst_addr = 0;
728599d49deSDave Jiang
729599d49deSDave Jiang desc->txd.flags = flags;
730599d49deSDave Jiang desc->len = 1;
731599d49deSDave Jiang
732599d49deSDave Jiang dump_desc_dbg(ioat_chan, desc);
733599d49deSDave Jiang
734599d49deSDave Jiang /* we leave the channel locked to ensure in order submission */
735599d49deSDave Jiang return &desc->txd;
736599d49deSDave Jiang }
737599d49deSDave Jiang
738