blob: d8a91521144e0a58d0e8797d07cd13b09ec7f7a1 [file] [log] [blame]
Thomas Gleixnera61127c2019-05-29 16:57:49 -07001// SPDX-License-Identifier: GPL-2.0-only
Dan Williams9bc89cd2007-01-02 11:10:44 -07002/*
3 * xor offload engine api
4 *
5 * Copyright © 2006, Intel Corporation.
6 *
7 * Dan Williams <dan.j.williams@intel.com>
8 *
9 * with architecture considerations by:
10 * Neil Brown <neilb@suse.de>
11 * Jeff Garzik <jeff@garzik.org>
Dan Williams9bc89cd2007-01-02 11:10:44 -070012 */
13#include <linux/kernel.h>
14#include <linux/interrupt.h>
Paul Gortmaker4bb33cc2011-05-27 14:41:48 -040015#include <linux/module.h>
Dan Williams9bc89cd2007-01-02 11:10:44 -070016#include <linux/mm.h>
17#include <linux/dma-mapping.h>
18#include <linux/raid/xor.h>
19#include <linux/async_tx.h>
20
Dan Williams06164f32009-03-25 09:13:25 -070021/* do_async_xor - dma map the pages and perform the xor with an engine */
22static __async_inline struct dma_async_tx_descriptor *
Dan Williamsfb36ab12013-10-18 19:35:26 +020023do_async_xor(struct dma_chan *chan, struct dmaengine_unmap_data *unmap,
Dan Williamsa08abd82009-06-03 11:43:59 -070024 struct async_submit_ctl *submit)
Dan Williams9bc89cd2007-01-02 11:10:44 -070025{
Dan Williams1e55db22008-07-16 19:44:56 -070026 struct dma_device *dma = chan->device;
Dan Williams1e55db22008-07-16 19:44:56 -070027 struct dma_async_tx_descriptor *tx = NULL;
Dan Williamsa08abd82009-06-03 11:43:59 -070028 dma_async_tx_callback cb_fn_orig = submit->cb_fn;
29 void *cb_param_orig = submit->cb_param;
30 enum async_tx_flags flags_orig = submit->flags;
Bartlomiej Zolnierkiewicz0776ae72013-10-18 19:35:33 +020031 enum dma_ctrl_flags dma_flags = 0;
Dan Williamsfb36ab12013-10-18 19:35:26 +020032 int src_cnt = unmap->to_cnt;
33 int xor_src_cnt;
34 dma_addr_t dma_dest = unmap->addr[unmap->to_cnt];
35 dma_addr_t *src_list = unmap->addr;
Dan Williams00367312008-02-02 19:49:57 -070036
Dan Williams1e55db22008-07-16 19:44:56 -070037 while (src_cnt) {
Dan Williamsfb36ab12013-10-18 19:35:26 +020038 dma_addr_t tmp;
39
Dan Williamsa08abd82009-06-03 11:43:59 -070040 submit->flags = flags_orig;
Dan Williamsb2f46fd2009-07-14 12:20:36 -070041 xor_src_cnt = min(src_cnt, (int)dma->max_xor);
Dan Williamsfb36ab12013-10-18 19:35:26 +020042 /* if we are submitting additional xors, leave the chain open
43 * and clear the callback parameters
Dan Williams1e55db22008-07-16 19:44:56 -070044 */
45 if (src_cnt > xor_src_cnt) {
Dan Williamsa08abd82009-06-03 11:43:59 -070046 submit->flags &= ~ASYNC_TX_ACK;
Dan Williams0403e382009-09-08 17:42:50 -070047 submit->flags |= ASYNC_TX_FENCE;
Dan Williamsa08abd82009-06-03 11:43:59 -070048 submit->cb_fn = NULL;
49 submit->cb_param = NULL;
Dan Williams1e55db22008-07-16 19:44:56 -070050 } else {
Dan Williamsa08abd82009-06-03 11:43:59 -070051 submit->cb_fn = cb_fn_orig;
52 submit->cb_param = cb_param_orig;
Dan Williams1e55db22008-07-16 19:44:56 -070053 }
Dan Williamsa08abd82009-06-03 11:43:59 -070054 if (submit->cb_fn)
Dan Williams1e55db22008-07-16 19:44:56 -070055 dma_flags |= DMA_PREP_INTERRUPT;
Dan Williams0403e382009-09-08 17:42:50 -070056 if (submit->flags & ASYNC_TX_FENCE)
57 dma_flags |= DMA_PREP_FENCE;
Dan Williamsfb36ab12013-10-18 19:35:26 +020058
59 /* Drivers force forward progress in case they can not provide a
60 * descriptor
Dan Williams1e55db22008-07-16 19:44:56 -070061 */
Dan Williamsfb36ab12013-10-18 19:35:26 +020062 tmp = src_list[0];
63 if (src_list > unmap->addr)
64 src_list[0] = dma_dest;
65 tx = dma->device_prep_dma_xor(chan, dma_dest, src_list,
66 xor_src_cnt, unmap->len,
67 dma_flags);
Dan Williams1e55db22008-07-16 19:44:56 -070068
Dan Williams669ab0b2008-07-17 17:59:55 -070069 if (unlikely(!tx))
Dan Williamsa08abd82009-06-03 11:43:59 -070070 async_tx_quiesce(&submit->depend_tx);
Dan Williams00367312008-02-02 19:49:57 -070071
Lucas De Marchi25985ed2011-03-30 22:57:33 -030072 /* spin wait for the preceding transactions to complete */
Dan Williams669ab0b2008-07-17 17:59:55 -070073 while (unlikely(!tx)) {
74 dma_async_issue_pending(chan);
Dan Williams1e55db22008-07-16 19:44:56 -070075 tx = dma->device_prep_dma_xor(chan, dma_dest,
Dan Williamsfb36ab12013-10-18 19:35:26 +020076 src_list,
77 xor_src_cnt, unmap->len,
Dan Williams1e55db22008-07-16 19:44:56 -070078 dma_flags);
Dan Williams669ab0b2008-07-17 17:59:55 -070079 }
Xuelin Shi87cea762014-07-01 16:32:38 +080080 src_list[0] = tmp;
Dan Williams9bc89cd2007-01-02 11:10:44 -070081
Dan Williamsfb36ab12013-10-18 19:35:26 +020082 dma_set_unmap(tx, unmap);
Dan Williamsa08abd82009-06-03 11:43:59 -070083 async_tx_submit(chan, tx, submit);
84 submit->depend_tx = tx;
Dan Williams1e55db22008-07-16 19:44:56 -070085
86 if (src_cnt > xor_src_cnt) {
87 /* drop completed sources */
88 src_cnt -= xor_src_cnt;
Dan Williams1e55db22008-07-16 19:44:56 -070089 /* use the intermediate result a source */
Dan Williams1e55db22008-07-16 19:44:56 -070090 src_cnt++;
Dan Williamsfb36ab12013-10-18 19:35:26 +020091 src_list += xor_src_cnt - 1;
Dan Williams1e55db22008-07-16 19:44:56 -070092 } else
93 break;
94 }
Dan Williams00367312008-02-02 19:49:57 -070095
96 return tx;
Dan Williams9bc89cd2007-01-02 11:10:44 -070097}
98
99static void
Yufen Yu29bcff72020-08-20 09:22:08 -0400100do_sync_xor_offs(struct page *dest, unsigned int offset,
101 struct page **src_list, unsigned int *src_offs,
Dan Williamsa08abd82009-06-03 11:43:59 -0700102 int src_cnt, size_t len, struct async_submit_ctl *submit)
Dan Williams9bc89cd2007-01-02 11:10:44 -0700103{
Dan Williams9bc89cd2007-01-02 11:10:44 -0700104 int i;
NeilBrownb2141e62009-10-16 16:40:34 +1100105 int xor_src_cnt = 0;
Dan Williams1e55db22008-07-16 19:44:56 -0700106 int src_off = 0;
107 void *dest_buf;
Dan Williams04ce9ab2009-06-03 14:22:28 -0700108 void **srcs;
Dan Williams9bc89cd2007-01-02 11:10:44 -0700109
Dan Williams04ce9ab2009-06-03 14:22:28 -0700110 if (submit->scribble)
111 srcs = submit->scribble;
112 else
113 srcs = (void **) src_list;
114
115 /* convert to buffer pointers */
Dan Williams9bc89cd2007-01-02 11:10:44 -0700116 for (i = 0; i < src_cnt; i++)
NeilBrownb2141e62009-10-16 16:40:34 +1100117 if (src_list[i])
Yufen Yu29bcff72020-08-20 09:22:08 -0400118 srcs[xor_src_cnt++] = page_address(src_list[i]) +
119 (src_offs ? src_offs[i] : offset);
NeilBrownb2141e62009-10-16 16:40:34 +1100120 src_cnt = xor_src_cnt;
Dan Williams9bc89cd2007-01-02 11:10:44 -0700121 /* set destination address */
Dan Williams1e55db22008-07-16 19:44:56 -0700122 dest_buf = page_address(dest) + offset;
Dan Williams9bc89cd2007-01-02 11:10:44 -0700123
Dan Williamsa08abd82009-06-03 11:43:59 -0700124 if (submit->flags & ASYNC_TX_XOR_ZERO_DST)
Dan Williams1e55db22008-07-16 19:44:56 -0700125 memset(dest_buf, 0, len);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700126
Dan Williams1e55db22008-07-16 19:44:56 -0700127 while (src_cnt > 0) {
128 /* process up to 'MAX_XOR_BLOCKS' sources */
129 xor_src_cnt = min(src_cnt, MAX_XOR_BLOCKS);
130 xor_blocks(xor_src_cnt, len, dest_buf, &srcs[src_off]);
131
132 /* drop completed sources */
133 src_cnt -= xor_src_cnt;
134 src_off += xor_src_cnt;
135 }
Dan Williams9bc89cd2007-01-02 11:10:44 -0700136
Dan Williamsa08abd82009-06-03 11:43:59 -0700137 async_tx_sync_epilog(submit);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700138}
139
Yufen Yu29bcff72020-08-20 09:22:08 -0400140static inline bool
141dma_xor_aligned_offsets(struct dma_device *device, unsigned int offset,
142 unsigned int *src_offs, int src_cnt, int len)
143{
144 int i;
145
146 if (!is_dma_xor_aligned(device, offset, 0, len))
147 return false;
148
149 if (!src_offs)
150 return true;
151
152 for (i = 0; i < src_cnt; i++) {
153 if (!is_dma_xor_aligned(device, src_offs[i], 0, len))
154 return false;
155 }
156 return true;
157}
158
Dan Williams9bc89cd2007-01-02 11:10:44 -0700159/**
Yufen Yu29bcff72020-08-20 09:22:08 -0400160 * async_xor_offs - attempt to xor a set of blocks with a dma engine.
Dan Williams9bc89cd2007-01-02 11:10:44 -0700161 * @dest: destination page
Yufen Yu29bcff72020-08-20 09:22:08 -0400162 * @offset: dst offset to start transaction
Dan Williamsa08abd82009-06-03 11:43:59 -0700163 * @src_list: array of source pages
Yufen Yu29bcff72020-08-20 09:22:08 -0400164 * @src_offs: array of source pages offset, NULL means common src/dst offset
Dan Williams9bc89cd2007-01-02 11:10:44 -0700165 * @src_cnt: number of source pages
166 * @len: length in bytes
Dan Williamsa08abd82009-06-03 11:43:59 -0700167 * @submit: submission / completion modifiers
168 *
169 * honored flags: ASYNC_TX_ACK, ASYNC_TX_XOR_ZERO_DST, ASYNC_TX_XOR_DROP_DST
170 *
171 * xor_blocks always uses the dest as a source so the
172 * ASYNC_TX_XOR_ZERO_DST flag must be set to not include dest data in
173 * the calculation. The assumption with dma eninges is that they only
174 * use the destination buffer as a source when it is explicity specified
175 * in the source list.
176 *
177 * src_list note: if the dest is also a source it must be at index zero.
178 * The contents of this array will be overwritten if a scribble region
179 * is not specified.
Dan Williams9bc89cd2007-01-02 11:10:44 -0700180 */
181struct dma_async_tx_descriptor *
Yufen Yu29bcff72020-08-20 09:22:08 -0400182async_xor_offs(struct page *dest, unsigned int offset,
183 struct page **src_list, unsigned int *src_offs,
184 int src_cnt, size_t len, struct async_submit_ctl *submit)
Dan Williams9bc89cd2007-01-02 11:10:44 -0700185{
Dan Williamsa08abd82009-06-03 11:43:59 -0700186 struct dma_chan *chan = async_tx_find_channel(submit, DMA_XOR,
Dan Williams47437b22008-02-02 19:49:59 -0700187 &dest, 1, src_list,
188 src_cnt, len);
Dan Williamsfb36ab12013-10-18 19:35:26 +0200189 struct dma_device *device = chan ? chan->device : NULL;
190 struct dmaengine_unmap_data *unmap = NULL;
Dan Williams04ce9ab2009-06-03 14:22:28 -0700191
Dan Williams9bc89cd2007-01-02 11:10:44 -0700192 BUG_ON(src_cnt <= 1);
193
Dan Williamsfb36ab12013-10-18 19:35:26 +0200194 if (device)
NeilBrownb02bab62016-01-07 11:02:34 +1100195 unmap = dmaengine_get_unmap_data(device->dev, src_cnt+1, GFP_NOWAIT);
Dan Williams04ce9ab2009-06-03 14:22:28 -0700196
Yufen Yu29bcff72020-08-20 09:22:08 -0400197 if (unmap && dma_xor_aligned_offsets(device, offset,
198 src_offs, src_cnt, len)) {
Dan Williamsfb36ab12013-10-18 19:35:26 +0200199 struct dma_async_tx_descriptor *tx;
200 int i, j;
201
Dan Williams1e55db22008-07-16 19:44:56 -0700202 /* run the xor asynchronously */
203 pr_debug("%s (async): len: %zu\n", __func__, len);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700204
Dan Williamsfb36ab12013-10-18 19:35:26 +0200205 unmap->len = len;
206 for (i = 0, j = 0; i < src_cnt; i++) {
207 if (!src_list[i])
208 continue;
209 unmap->to_cnt++;
210 unmap->addr[j++] = dma_map_page(device->dev, src_list[i],
Yufen Yu29bcff72020-08-20 09:22:08 -0400211 src_offs ? src_offs[i] : offset,
212 len, DMA_TO_DEVICE);
Dan Williamsfb36ab12013-10-18 19:35:26 +0200213 }
214
215 /* map it bidirectional as it may be re-used as a source */
216 unmap->addr[j] = dma_map_page(device->dev, dest, offset, len,
217 DMA_BIDIRECTIONAL);
218 unmap->bidi_cnt = 1;
219
220 tx = do_async_xor(chan, unmap, submit);
221 dmaengine_unmap_put(unmap);
222 return tx;
Dan Williams1e55db22008-07-16 19:44:56 -0700223 } else {
Dan Williamsfb36ab12013-10-18 19:35:26 +0200224 dmaengine_unmap_put(unmap);
Dan Williams1e55db22008-07-16 19:44:56 -0700225 /* run the xor synchronously */
226 pr_debug("%s (sync): len: %zu\n", __func__, len);
Dan Williams04ce9ab2009-06-03 14:22:28 -0700227 WARN_ONCE(chan, "%s: no space for dma address conversion\n",
228 __func__);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700229
Dan Williams1e55db22008-07-16 19:44:56 -0700230 /* in the sync case the dest is an implied source
231 * (assumes the dest is the first source)
232 */
Dan Williamsa08abd82009-06-03 11:43:59 -0700233 if (submit->flags & ASYNC_TX_XOR_DROP_DST) {
Dan Williams1e55db22008-07-16 19:44:56 -0700234 src_cnt--;
235 src_list++;
Xiao Ni9be148e2021-05-28 14:16:38 +0800236 if (src_offs)
237 src_offs++;
Dan Williams9bc89cd2007-01-02 11:10:44 -0700238 }
239
Dan Williams1e55db22008-07-16 19:44:56 -0700240 /* wait for any prerequisite operations */
Dan Williamsa08abd82009-06-03 11:43:59 -0700241 async_tx_quiesce(&submit->depend_tx);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700242
Yufen Yu29bcff72020-08-20 09:22:08 -0400243 do_sync_xor_offs(dest, offset, src_list, src_offs,
244 src_cnt, len, submit);
Dan Williams1e55db22008-07-16 19:44:56 -0700245
246 return NULL;
247 }
Dan Williams9bc89cd2007-01-02 11:10:44 -0700248}
Yufen Yu29bcff72020-08-20 09:22:08 -0400249EXPORT_SYMBOL_GPL(async_xor_offs);
250
251/**
252 * async_xor - attempt to xor a set of blocks with a dma engine.
253 * @dest: destination page
254 * @src_list: array of source pages
255 * @offset: common src/dst offset to start transaction
256 * @src_cnt: number of source pages
257 * @len: length in bytes
258 * @submit: submission / completion modifiers
259 *
260 * honored flags: ASYNC_TX_ACK, ASYNC_TX_XOR_ZERO_DST, ASYNC_TX_XOR_DROP_DST
261 *
262 * xor_blocks always uses the dest as a source so the
263 * ASYNC_TX_XOR_ZERO_DST flag must be set to not include dest data in
264 * the calculation. The assumption with dma eninges is that they only
265 * use the destination buffer as a source when it is explicity specified
266 * in the source list.
267 *
268 * src_list note: if the dest is also a source it must be at index zero.
269 * The contents of this array will be overwritten if a scribble region
270 * is not specified.
271 */
272struct dma_async_tx_descriptor *
273async_xor(struct page *dest, struct page **src_list, unsigned int offset,
274 int src_cnt, size_t len, struct async_submit_ctl *submit)
275{
276 return async_xor_offs(dest, offset, src_list, NULL,
277 src_cnt, len, submit);
278}
Dan Williams9bc89cd2007-01-02 11:10:44 -0700279EXPORT_SYMBOL_GPL(async_xor);
280
281static int page_is_zero(struct page *p, unsigned int offset, size_t len)
282{
Akinobu Mita2c88ae92012-10-28 00:49:33 +0900283 return !memchr_inv(page_address(p) + offset, 0, len);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700284}
285
Dan Williams7b3cc2b2009-11-19 17:10:37 -0700286static inline struct dma_chan *
287xor_val_chan(struct async_submit_ctl *submit, struct page *dest,
288 struct page **src_list, int src_cnt, size_t len)
289{
290 #ifdef CONFIG_ASYNC_TX_DISABLE_XOR_VAL_DMA
291 return NULL;
292 #endif
293 return async_tx_find_channel(submit, DMA_XOR_VAL, &dest, 1, src_list,
294 src_cnt, len);
295}
296
Dan Williams9bc89cd2007-01-02 11:10:44 -0700297/**
Yufen Yu29bcff72020-08-20 09:22:08 -0400298 * async_xor_val_offs - attempt a xor parity check with a dma engine.
Dan Williams9bc89cd2007-01-02 11:10:44 -0700299 * @dest: destination page used if the xor is performed synchronously
Yufen Yu29bcff72020-08-20 09:22:08 -0400300 * @offset: des offset in pages to start transaction
Dan Williamsa08abd82009-06-03 11:43:59 -0700301 * @src_list: array of source pages
Yufen Yu29bcff72020-08-20 09:22:08 -0400302 * @src_offs: array of source pages offset, NULL means common src/det offset
Dan Williams9bc89cd2007-01-02 11:10:44 -0700303 * @src_cnt: number of source pages
304 * @len: length in bytes
305 * @result: 0 if sum == 0 else non-zero
Dan Williamsa08abd82009-06-03 11:43:59 -0700306 * @submit: submission / completion modifiers
307 *
308 * honored flags: ASYNC_TX_ACK
309 *
310 * src_list note: if the dest is also a source it must be at index zero.
311 * The contents of this array will be overwritten if a scribble region
312 * is not specified.
Dan Williams9bc89cd2007-01-02 11:10:44 -0700313 */
314struct dma_async_tx_descriptor *
Yufen Yu29bcff72020-08-20 09:22:08 -0400315async_xor_val_offs(struct page *dest, unsigned int offset,
316 struct page **src_list, unsigned int *src_offs,
317 int src_cnt, size_t len, enum sum_check_flags *result,
318 struct async_submit_ctl *submit)
Dan Williams9bc89cd2007-01-02 11:10:44 -0700319{
Dan Williams7b3cc2b2009-11-19 17:10:37 -0700320 struct dma_chan *chan = xor_val_chan(submit, dest, src_list, src_cnt, len);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700321 struct dma_device *device = chan ? chan->device : NULL;
Dan Williams00367312008-02-02 19:49:57 -0700322 struct dma_async_tx_descriptor *tx = NULL;
Dan Williams173e86b2013-10-18 19:35:27 +0200323 struct dmaengine_unmap_data *unmap = NULL;
Dan Williams9bc89cd2007-01-02 11:10:44 -0700324
325 BUG_ON(src_cnt <= 1);
326
Dan Williams173e86b2013-10-18 19:35:27 +0200327 if (device)
NeilBrownb02bab62016-01-07 11:02:34 +1100328 unmap = dmaengine_get_unmap_data(device->dev, src_cnt, GFP_NOWAIT);
Dan Williams04ce9ab2009-06-03 14:22:28 -0700329
Dan Williams173e86b2013-10-18 19:35:27 +0200330 if (unmap && src_cnt <= device->max_xor &&
Yufen Yu29bcff72020-08-20 09:22:08 -0400331 dma_xor_aligned_offsets(device, offset, src_offs, src_cnt, len)) {
Bartlomiej Zolnierkiewicz0776ae72013-10-18 19:35:33 +0200332 unsigned long dma_prep_flags = 0;
Dan Williams00367312008-02-02 19:49:57 -0700333 int i;
Dan Williams9bc89cd2007-01-02 11:10:44 -0700334
Dan Williams3280ab3e2008-03-13 17:45:28 -0700335 pr_debug("%s: (async) len: %zu\n", __func__, len);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700336
Dan Williams0403e382009-09-08 17:42:50 -0700337 if (submit->cb_fn)
338 dma_prep_flags |= DMA_PREP_INTERRUPT;
339 if (submit->flags & ASYNC_TX_FENCE)
340 dma_prep_flags |= DMA_PREP_FENCE;
Dan Williams00367312008-02-02 19:49:57 -0700341
Dan Williams173e86b2013-10-18 19:35:27 +0200342 for (i = 0; i < src_cnt; i++) {
343 unmap->addr[i] = dma_map_page(device->dev, src_list[i],
Yufen Yu29bcff72020-08-20 09:22:08 -0400344 src_offs ? src_offs[i] : offset,
345 len, DMA_TO_DEVICE);
Dan Williams173e86b2013-10-18 19:35:27 +0200346 unmap->to_cnt++;
347 }
348 unmap->len = len;
349
350 tx = device->device_prep_dma_xor_val(chan, unmap->addr, src_cnt,
Dan Williams099f53c2009-04-08 14:28:37 -0700351 len, result,
352 dma_prep_flags);
Dan Williams669ab0b2008-07-17 17:59:55 -0700353 if (unlikely(!tx)) {
Dan Williamsa08abd82009-06-03 11:43:59 -0700354 async_tx_quiesce(&submit->depend_tx);
Dan Williams00367312008-02-02 19:49:57 -0700355
Dan Williamse34a8ae2008-08-05 10:22:05 -0700356 while (!tx) {
Dan Williams669ab0b2008-07-17 17:59:55 -0700357 dma_async_issue_pending(chan);
Dan Williams099f53c2009-04-08 14:28:37 -0700358 tx = device->device_prep_dma_xor_val(chan,
Dan Williams173e86b2013-10-18 19:35:27 +0200359 unmap->addr, src_cnt, len, result,
Dan Williamsd4c56f92008-02-02 19:49:58 -0700360 dma_prep_flags);
Dan Williamse34a8ae2008-08-05 10:22:05 -0700361 }
Dan Williams9bc89cd2007-01-02 11:10:44 -0700362 }
Dan Williams173e86b2013-10-18 19:35:27 +0200363 dma_set_unmap(tx, unmap);
Dan Williamsa08abd82009-06-03 11:43:59 -0700364 async_tx_submit(chan, tx, submit);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700365 } else {
Dan Williamsa08abd82009-06-03 11:43:59 -0700366 enum async_tx_flags flags_orig = submit->flags;
Dan Williams9bc89cd2007-01-02 11:10:44 -0700367
Dan Williams3280ab3e2008-03-13 17:45:28 -0700368 pr_debug("%s: (sync) len: %zu\n", __func__, len);
Dan Williams04ce9ab2009-06-03 14:22:28 -0700369 WARN_ONCE(device && src_cnt <= device->max_xor,
370 "%s: no space for dma address conversion\n",
371 __func__);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700372
Dan Williamsa08abd82009-06-03 11:43:59 -0700373 submit->flags |= ASYNC_TX_XOR_DROP_DST;
374 submit->flags &= ~ASYNC_TX_ACK;
Dan Williams9bc89cd2007-01-02 11:10:44 -0700375
Yufen Yu29bcff72020-08-20 09:22:08 -0400376 tx = async_xor_offs(dest, offset, src_list, src_offs,
377 src_cnt, len, submit);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700378
Dan Williamsd2c52b72008-07-17 17:59:55 -0700379 async_tx_quiesce(&tx);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700380
Dan Williamsad283ea2009-08-29 19:09:26 -0700381 *result = !page_is_zero(dest, offset, len) << SUM_CHECK_P;
Dan Williams9bc89cd2007-01-02 11:10:44 -0700382
Dan Williamsa08abd82009-06-03 11:43:59 -0700383 async_tx_sync_epilog(submit);
384 submit->flags = flags_orig;
Dan Williams9bc89cd2007-01-02 11:10:44 -0700385 }
Dan Williams173e86b2013-10-18 19:35:27 +0200386 dmaengine_unmap_put(unmap);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700387
388 return tx;
389}
Yufen Yu29bcff72020-08-20 09:22:08 -0400390EXPORT_SYMBOL_GPL(async_xor_val_offs);
391
392/**
393 * async_xor_val - attempt a xor parity check with a dma engine.
394 * @dest: destination page used if the xor is performed synchronously
395 * @src_list: array of source pages
396 * @offset: offset in pages to start transaction
397 * @src_cnt: number of source pages
398 * @len: length in bytes
399 * @result: 0 if sum == 0 else non-zero
400 * @submit: submission / completion modifiers
401 *
402 * honored flags: ASYNC_TX_ACK
403 *
404 * src_list note: if the dest is also a source it must be at index zero.
405 * The contents of this array will be overwritten if a scribble region
406 * is not specified.
407 */
408struct dma_async_tx_descriptor *
409async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
410 int src_cnt, size_t len, enum sum_check_flags *result,
411 struct async_submit_ctl *submit)
412{
413 return async_xor_val_offs(dest, offset, src_list, NULL, src_cnt,
414 len, result, submit);
415}
Dan Williams099f53c2009-04-08 14:28:37 -0700416EXPORT_SYMBOL_GPL(async_xor_val);
Dan Williams9bc89cd2007-01-02 11:10:44 -0700417
Dan Williams9bc89cd2007-01-02 11:10:44 -0700418MODULE_AUTHOR("Intel Corporation");
419MODULE_DESCRIPTION("asynchronous xor/xor-zero-sum api");
420MODULE_LICENSE("GPL");