xref: /openbmc/linux/crypto/async_tx/async_pq.c (revision 0403e3827788d878163f9ef0541b748b0f88ca5d)
1b2f46fd8SDan Williams /*
2b2f46fd8SDan Williams  * Copyright(c) 2007 Yuri Tikhonov <yur@emcraft.com>
3b2f46fd8SDan Williams  * Copyright(c) 2009 Intel Corporation
4b2f46fd8SDan Williams  *
5b2f46fd8SDan Williams  * This program is free software; you can redistribute it and/or modify it
6b2f46fd8SDan Williams  * under the terms of the GNU General Public License as published by the Free
7b2f46fd8SDan Williams  * Software Foundation; either version 2 of the License, or (at your option)
8b2f46fd8SDan Williams  * any later version.
9b2f46fd8SDan Williams  *
10b2f46fd8SDan Williams  * This program is distributed in the hope that it will be useful, but WITHOUT
11b2f46fd8SDan Williams  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12b2f46fd8SDan Williams  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13b2f46fd8SDan Williams  * more details.
14b2f46fd8SDan Williams  *
15b2f46fd8SDan Williams  * You should have received a copy of the GNU General Public License along with
16b2f46fd8SDan Williams  * this program; if not, write to the Free Software Foundation, Inc., 59
17b2f46fd8SDan Williams  * Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18b2f46fd8SDan Williams  *
19b2f46fd8SDan Williams  * The full GNU General Public License is included in this distribution in the
20b2f46fd8SDan Williams  * file called COPYING.
21b2f46fd8SDan Williams  */
22b2f46fd8SDan Williams #include <linux/kernel.h>
23b2f46fd8SDan Williams #include <linux/interrupt.h>
24b2f46fd8SDan Williams #include <linux/dma-mapping.h>
25b2f46fd8SDan Williams #include <linux/raid/pq.h>
26b2f46fd8SDan Williams #include <linux/async_tx.h>
27b2f46fd8SDan Williams 
28b2f46fd8SDan Williams /**
29b2f46fd8SDan Williams  * scribble - space to hold throwaway P buffer for synchronous gen_syndrome
30b2f46fd8SDan Williams  */
31b2f46fd8SDan Williams static struct page *scribble;
32b2f46fd8SDan Williams 
33b2f46fd8SDan Williams static bool is_raid6_zero_block(struct page *p)
34b2f46fd8SDan Williams {
35b2f46fd8SDan Williams 	return p == (void *) raid6_empty_zero_page;
36b2f46fd8SDan Williams }
37b2f46fd8SDan Williams 
38b2f46fd8SDan Williams /* the struct page *blocks[] parameter passed to async_gen_syndrome()
39b2f46fd8SDan Williams  * and async_syndrome_val() contains the 'P' destination address at
40b2f46fd8SDan Williams  * blocks[disks-2] and the 'Q' destination address at blocks[disks-1]
41b2f46fd8SDan Williams  *
42b2f46fd8SDan Williams  * note: these are macros as they are used as lvalues
43b2f46fd8SDan Williams  */
44b2f46fd8SDan Williams #define P(b, d) (b[d-2])
45b2f46fd8SDan Williams #define Q(b, d) (b[d-1])
46b2f46fd8SDan Williams 
47b2f46fd8SDan Williams /**
48b2f46fd8SDan Williams  * do_async_gen_syndrome - asynchronously calculate P and/or Q
49b2f46fd8SDan Williams  */
50b2f46fd8SDan Williams static __async_inline struct dma_async_tx_descriptor *
51b2f46fd8SDan Williams do_async_gen_syndrome(struct dma_chan *chan, struct page **blocks,
52b2f46fd8SDan Williams 		      const unsigned char *scfs, unsigned int offset, int disks,
53b2f46fd8SDan Williams 		      size_t len, dma_addr_t *dma_src,
54b2f46fd8SDan Williams 		      struct async_submit_ctl *submit)
55b2f46fd8SDan Williams {
56b2f46fd8SDan Williams 	struct dma_async_tx_descriptor *tx = NULL;
57b2f46fd8SDan Williams 	struct dma_device *dma = chan->device;
58b2f46fd8SDan Williams 	enum dma_ctrl_flags dma_flags = 0;
59b2f46fd8SDan Williams 	enum async_tx_flags flags_orig = submit->flags;
60b2f46fd8SDan Williams 	dma_async_tx_callback cb_fn_orig = submit->cb_fn;
61b2f46fd8SDan Williams 	dma_async_tx_callback cb_param_orig = submit->cb_param;
62b2f46fd8SDan Williams 	int src_cnt = disks - 2;
63b2f46fd8SDan Williams 	unsigned char coefs[src_cnt];
64b2f46fd8SDan Williams 	unsigned short pq_src_cnt;
65b2f46fd8SDan Williams 	dma_addr_t dma_dest[2];
66b2f46fd8SDan Williams 	int src_off = 0;
67b2f46fd8SDan Williams 	int idx;
68b2f46fd8SDan Williams 	int i;
69b2f46fd8SDan Williams 
70b2f46fd8SDan Williams 	/* DMAs use destinations as sources, so use BIDIRECTIONAL mapping */
71b2f46fd8SDan Williams 	if (P(blocks, disks))
72b2f46fd8SDan Williams 		dma_dest[0] = dma_map_page(dma->dev, P(blocks, disks), offset,
73b2f46fd8SDan Williams 					   len, DMA_BIDIRECTIONAL);
74b2f46fd8SDan Williams 	else
75b2f46fd8SDan Williams 		dma_flags |= DMA_PREP_PQ_DISABLE_P;
76b2f46fd8SDan Williams 	if (Q(blocks, disks))
77b2f46fd8SDan Williams 		dma_dest[1] = dma_map_page(dma->dev, Q(blocks, disks), offset,
78b2f46fd8SDan Williams 					   len, DMA_BIDIRECTIONAL);
79b2f46fd8SDan Williams 	else
80b2f46fd8SDan Williams 		dma_flags |= DMA_PREP_PQ_DISABLE_Q;
81b2f46fd8SDan Williams 
82b2f46fd8SDan Williams 	/* convert source addresses being careful to collapse 'empty'
83b2f46fd8SDan Williams 	 * sources and update the coefficients accordingly
84b2f46fd8SDan Williams 	 */
85b2f46fd8SDan Williams 	for (i = 0, idx = 0; i < src_cnt; i++) {
86b2f46fd8SDan Williams 		if (is_raid6_zero_block(blocks[i]))
87b2f46fd8SDan Williams 			continue;
88b2f46fd8SDan Williams 		dma_src[idx] = dma_map_page(dma->dev, blocks[i], offset, len,
89b2f46fd8SDan Williams 					    DMA_TO_DEVICE);
90b2f46fd8SDan Williams 		coefs[idx] = scfs[i];
91b2f46fd8SDan Williams 		idx++;
92b2f46fd8SDan Williams 	}
93b2f46fd8SDan Williams 	src_cnt = idx;
94b2f46fd8SDan Williams 
95b2f46fd8SDan Williams 	while (src_cnt > 0) {
96b2f46fd8SDan Williams 		submit->flags = flags_orig;
97b2f46fd8SDan Williams 		pq_src_cnt = min(src_cnt, dma_maxpq(dma, dma_flags));
98b2f46fd8SDan Williams 		/* if we are submitting additional pqs, leave the chain open,
99b2f46fd8SDan Williams 		 * clear the callback parameters, and leave the destination
100b2f46fd8SDan Williams 		 * buffers mapped
101b2f46fd8SDan Williams 		 */
102b2f46fd8SDan Williams 		if (src_cnt > pq_src_cnt) {
103b2f46fd8SDan Williams 			submit->flags &= ~ASYNC_TX_ACK;
104*0403e382SDan Williams 			submit->flags |= ASYNC_TX_FENCE;
105b2f46fd8SDan Williams 			dma_flags |= DMA_COMPL_SKIP_DEST_UNMAP;
106b2f46fd8SDan Williams 			submit->cb_fn = NULL;
107b2f46fd8SDan Williams 			submit->cb_param = NULL;
108b2f46fd8SDan Williams 		} else {
109b2f46fd8SDan Williams 			dma_flags &= ~DMA_COMPL_SKIP_DEST_UNMAP;
110b2f46fd8SDan Williams 			submit->cb_fn = cb_fn_orig;
111b2f46fd8SDan Williams 			submit->cb_param = cb_param_orig;
112b2f46fd8SDan Williams 			if (cb_fn_orig)
113b2f46fd8SDan Williams 				dma_flags |= DMA_PREP_INTERRUPT;
114b2f46fd8SDan Williams 		}
115*0403e382SDan Williams 		if (submit->flags & ASYNC_TX_FENCE)
116*0403e382SDan Williams 			dma_flags |= DMA_PREP_FENCE;
117b2f46fd8SDan Williams 
118b2f46fd8SDan Williams 		/* Since we have clobbered the src_list we are committed
119b2f46fd8SDan Williams 		 * to doing this asynchronously.  Drivers force forward
120b2f46fd8SDan Williams 		 * progress in case they can not provide a descriptor
121b2f46fd8SDan Williams 		 */
122b2f46fd8SDan Williams 		for (;;) {
123b2f46fd8SDan Williams 			tx = dma->device_prep_dma_pq(chan, dma_dest,
124b2f46fd8SDan Williams 						     &dma_src[src_off],
125b2f46fd8SDan Williams 						     pq_src_cnt,
126b2f46fd8SDan Williams 						     &coefs[src_off], len,
127b2f46fd8SDan Williams 						     dma_flags);
128b2f46fd8SDan Williams 			if (likely(tx))
129b2f46fd8SDan Williams 				break;
130b2f46fd8SDan Williams 			async_tx_quiesce(&submit->depend_tx);
131b2f46fd8SDan Williams 			dma_async_issue_pending(chan);
132b2f46fd8SDan Williams 		}
133b2f46fd8SDan Williams 
134b2f46fd8SDan Williams 		async_tx_submit(chan, tx, submit);
135b2f46fd8SDan Williams 		submit->depend_tx = tx;
136b2f46fd8SDan Williams 
137b2f46fd8SDan Williams 		/* drop completed sources */
138b2f46fd8SDan Williams 		src_cnt -= pq_src_cnt;
139b2f46fd8SDan Williams 		src_off += pq_src_cnt;
140b2f46fd8SDan Williams 
141b2f46fd8SDan Williams 		dma_flags |= DMA_PREP_CONTINUE;
142b2f46fd8SDan Williams 	}
143b2f46fd8SDan Williams 
144b2f46fd8SDan Williams 	return tx;
145b2f46fd8SDan Williams }
146b2f46fd8SDan Williams 
147b2f46fd8SDan Williams /**
148b2f46fd8SDan Williams  * do_sync_gen_syndrome - synchronously calculate a raid6 syndrome
149b2f46fd8SDan Williams  */
150b2f46fd8SDan Williams static void
151b2f46fd8SDan Williams do_sync_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
152b2f46fd8SDan Williams 		     size_t len, struct async_submit_ctl *submit)
153b2f46fd8SDan Williams {
154b2f46fd8SDan Williams 	void **srcs;
155b2f46fd8SDan Williams 	int i;
156b2f46fd8SDan Williams 
157b2f46fd8SDan Williams 	if (submit->scribble)
158b2f46fd8SDan Williams 		srcs = submit->scribble;
159b2f46fd8SDan Williams 	else
160b2f46fd8SDan Williams 		srcs = (void **) blocks;
161b2f46fd8SDan Williams 
162b2f46fd8SDan Williams 	for (i = 0; i < disks; i++) {
163b2f46fd8SDan Williams 		if (is_raid6_zero_block(blocks[i])) {
164b2f46fd8SDan Williams 			BUG_ON(i > disks - 3); /* P or Q can't be zero */
165b2f46fd8SDan Williams 			srcs[i] = blocks[i];
166b2f46fd8SDan Williams 		} else
167b2f46fd8SDan Williams 			srcs[i] = page_address(blocks[i]) + offset;
168b2f46fd8SDan Williams 	}
169b2f46fd8SDan Williams 	raid6_call.gen_syndrome(disks, len, srcs);
170b2f46fd8SDan Williams 	async_tx_sync_epilog(submit);
171b2f46fd8SDan Williams }
172b2f46fd8SDan Williams 
173b2f46fd8SDan Williams /**
174b2f46fd8SDan Williams  * async_gen_syndrome - asynchronously calculate a raid6 syndrome
175b2f46fd8SDan Williams  * @blocks: source blocks from idx 0..disks-3, P @ disks-2 and Q @ disks-1
176b2f46fd8SDan Williams  * @offset: common offset into each block (src and dest) to start transaction
177b2f46fd8SDan Williams  * @disks: number of blocks (including missing P or Q, see below)
178b2f46fd8SDan Williams  * @len: length of operation in bytes
179b2f46fd8SDan Williams  * @submit: submission/completion modifiers
180b2f46fd8SDan Williams  *
181b2f46fd8SDan Williams  * General note: This routine assumes a field of GF(2^8) with a
182b2f46fd8SDan Williams  * primitive polynomial of 0x11d and a generator of {02}.
183b2f46fd8SDan Williams  *
184b2f46fd8SDan Williams  * 'disks' note: callers can optionally omit either P or Q (but not
185b2f46fd8SDan Williams  * both) from the calculation by setting blocks[disks-2] or
186b2f46fd8SDan Williams  * blocks[disks-1] to NULL.  When P or Q is omitted 'len' must be <=
187b2f46fd8SDan Williams  * PAGE_SIZE as a temporary buffer of this size is used in the
188b2f46fd8SDan Williams  * synchronous path.  'disks' always accounts for both destination
189b2f46fd8SDan Williams  * buffers.
190b2f46fd8SDan Williams  *
191b2f46fd8SDan Williams  * 'blocks' note: if submit->scribble is NULL then the contents of
192b2f46fd8SDan Williams  * 'blocks' may be overridden
193b2f46fd8SDan Williams  */
194b2f46fd8SDan Williams struct dma_async_tx_descriptor *
195b2f46fd8SDan Williams async_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
196b2f46fd8SDan Williams 		   size_t len, struct async_submit_ctl *submit)
197b2f46fd8SDan Williams {
198b2f46fd8SDan Williams 	int src_cnt = disks - 2;
199b2f46fd8SDan Williams 	struct dma_chan *chan = async_tx_find_channel(submit, DMA_PQ,
200b2f46fd8SDan Williams 						      &P(blocks, disks), 2,
201b2f46fd8SDan Williams 						      blocks, src_cnt, len);
202b2f46fd8SDan Williams 	struct dma_device *device = chan ? chan->device : NULL;
203b2f46fd8SDan Williams 	dma_addr_t *dma_src = NULL;
204b2f46fd8SDan Williams 
205b2f46fd8SDan Williams 	BUG_ON(disks > 255 || !(P(blocks, disks) || Q(blocks, disks)));
206b2f46fd8SDan Williams 
207b2f46fd8SDan Williams 	if (submit->scribble)
208b2f46fd8SDan Williams 		dma_src = submit->scribble;
209b2f46fd8SDan Williams 	else if (sizeof(dma_addr_t) <= sizeof(struct page *))
210b2f46fd8SDan Williams 		dma_src = (dma_addr_t *) blocks;
211b2f46fd8SDan Williams 
212b2f46fd8SDan Williams 	if (dma_src && device &&
213b2f46fd8SDan Williams 	    (src_cnt <= dma_maxpq(device, 0) ||
214b2f46fd8SDan Williams 	     dma_maxpq(device, DMA_PREP_CONTINUE) > 0)) {
215b2f46fd8SDan Williams 		/* run the p+q asynchronously */
216b2f46fd8SDan Williams 		pr_debug("%s: (async) disks: %d len: %zu\n",
217b2f46fd8SDan Williams 			 __func__, disks, len);
218b2f46fd8SDan Williams 		return do_async_gen_syndrome(chan, blocks, raid6_gfexp, offset,
219b2f46fd8SDan Williams 					     disks, len, dma_src, submit);
220b2f46fd8SDan Williams 	}
221b2f46fd8SDan Williams 
222b2f46fd8SDan Williams 	/* run the pq synchronously */
223b2f46fd8SDan Williams 	pr_debug("%s: (sync) disks: %d len: %zu\n", __func__, disks, len);
224b2f46fd8SDan Williams 
225b2f46fd8SDan Williams 	/* wait for any prerequisite operations */
226b2f46fd8SDan Williams 	async_tx_quiesce(&submit->depend_tx);
227b2f46fd8SDan Williams 
228b2f46fd8SDan Williams 	if (!P(blocks, disks)) {
229b2f46fd8SDan Williams 		P(blocks, disks) = scribble;
230b2f46fd8SDan Williams 		BUG_ON(len + offset > PAGE_SIZE);
231b2f46fd8SDan Williams 	}
232b2f46fd8SDan Williams 	if (!Q(blocks, disks)) {
233b2f46fd8SDan Williams 		Q(blocks, disks) = scribble;
234b2f46fd8SDan Williams 		BUG_ON(len + offset > PAGE_SIZE);
235b2f46fd8SDan Williams 	}
236b2f46fd8SDan Williams 	do_sync_gen_syndrome(blocks, offset, disks, len, submit);
237b2f46fd8SDan Williams 
238b2f46fd8SDan Williams 	return NULL;
239b2f46fd8SDan Williams }
240b2f46fd8SDan Williams EXPORT_SYMBOL_GPL(async_gen_syndrome);
241b2f46fd8SDan Williams 
242b2f46fd8SDan Williams /**
243b2f46fd8SDan Williams  * async_syndrome_val - asynchronously validate a raid6 syndrome
244b2f46fd8SDan Williams  * @blocks: source blocks from idx 0..disks-3, P @ disks-2 and Q @ disks-1
245b2f46fd8SDan Williams  * @offset: common offset into each block (src and dest) to start transaction
246b2f46fd8SDan Williams  * @disks: number of blocks (including missing P or Q, see below)
247b2f46fd8SDan Williams  * @len: length of operation in bytes
248b2f46fd8SDan Williams  * @pqres: on val failure SUM_CHECK_P_RESULT and/or SUM_CHECK_Q_RESULT are set
249b2f46fd8SDan Williams  * @spare: temporary result buffer for the synchronous case
250b2f46fd8SDan Williams  * @submit: submission / completion modifiers
251b2f46fd8SDan Williams  *
252b2f46fd8SDan Williams  * The same notes from async_gen_syndrome apply to the 'blocks',
253b2f46fd8SDan Williams  * and 'disks' parameters of this routine.  The synchronous path
254b2f46fd8SDan Williams  * requires a temporary result buffer and submit->scribble to be
255b2f46fd8SDan Williams  * specified.
256b2f46fd8SDan Williams  */
257b2f46fd8SDan Williams struct dma_async_tx_descriptor *
258b2f46fd8SDan Williams async_syndrome_val(struct page **blocks, unsigned int offset, int disks,
259b2f46fd8SDan Williams 		   size_t len, enum sum_check_flags *pqres, struct page *spare,
260b2f46fd8SDan Williams 		   struct async_submit_ctl *submit)
261b2f46fd8SDan Williams {
262b2f46fd8SDan Williams 	struct dma_chan *chan = async_tx_find_channel(submit, DMA_PQ_VAL,
263b2f46fd8SDan Williams 						      NULL, 0,  blocks, disks,
264b2f46fd8SDan Williams 						      len);
265b2f46fd8SDan Williams 	struct dma_device *device = chan ? chan->device : NULL;
266b2f46fd8SDan Williams 	struct dma_async_tx_descriptor *tx;
267b2f46fd8SDan Williams 	enum dma_ctrl_flags dma_flags = submit->cb_fn ? DMA_PREP_INTERRUPT : 0;
268b2f46fd8SDan Williams 	dma_addr_t *dma_src = NULL;
269b2f46fd8SDan Williams 
270b2f46fd8SDan Williams 	BUG_ON(disks < 4);
271b2f46fd8SDan Williams 
272b2f46fd8SDan Williams 	if (submit->scribble)
273b2f46fd8SDan Williams 		dma_src = submit->scribble;
274b2f46fd8SDan Williams 	else if (sizeof(dma_addr_t) <= sizeof(struct page *))
275b2f46fd8SDan Williams 		dma_src = (dma_addr_t *) blocks;
276b2f46fd8SDan Williams 
277b2f46fd8SDan Williams 	if (dma_src && device && disks <= dma_maxpq(device, 0)) {
278b2f46fd8SDan Williams 		struct device *dev = device->dev;
279b2f46fd8SDan Williams 		dma_addr_t *pq = &dma_src[disks-2];
280b2f46fd8SDan Williams 		int i;
281b2f46fd8SDan Williams 
282b2f46fd8SDan Williams 		pr_debug("%s: (async) disks: %d len: %zu\n",
283b2f46fd8SDan Williams 			 __func__, disks, len);
284b2f46fd8SDan Williams 		if (!P(blocks, disks))
285b2f46fd8SDan Williams 			dma_flags |= DMA_PREP_PQ_DISABLE_P;
286b2f46fd8SDan Williams 		if (!Q(blocks, disks))
287b2f46fd8SDan Williams 			dma_flags |= DMA_PREP_PQ_DISABLE_Q;
288*0403e382SDan Williams 		if (submit->flags & ASYNC_TX_FENCE)
289*0403e382SDan Williams 			dma_flags |= DMA_PREP_FENCE;
290b2f46fd8SDan Williams 		for (i = 0; i < disks; i++)
291b2f46fd8SDan Williams 			if (likely(blocks[i])) {
292b2f46fd8SDan Williams 				BUG_ON(is_raid6_zero_block(blocks[i]));
293b2f46fd8SDan Williams 				dma_src[i] = dma_map_page(dev, blocks[i],
294b2f46fd8SDan Williams 							  offset, len,
295b2f46fd8SDan Williams 							  DMA_TO_DEVICE);
296b2f46fd8SDan Williams 			}
297b2f46fd8SDan Williams 
298b2f46fd8SDan Williams 		for (;;) {
299b2f46fd8SDan Williams 			tx = device->device_prep_dma_pq_val(chan, pq, dma_src,
300b2f46fd8SDan Williams 							    disks - 2,
301b2f46fd8SDan Williams 							    raid6_gfexp,
302b2f46fd8SDan Williams 							    len, pqres,
303b2f46fd8SDan Williams 							    dma_flags);
304b2f46fd8SDan Williams 			if (likely(tx))
305b2f46fd8SDan Williams 				break;
306b2f46fd8SDan Williams 			async_tx_quiesce(&submit->depend_tx);
307b2f46fd8SDan Williams 			dma_async_issue_pending(chan);
308b2f46fd8SDan Williams 		}
309b2f46fd8SDan Williams 		async_tx_submit(chan, tx, submit);
310b2f46fd8SDan Williams 
311b2f46fd8SDan Williams 		return tx;
312b2f46fd8SDan Williams 	} else {
313b2f46fd8SDan Williams 		struct page *p_src = P(blocks, disks);
314b2f46fd8SDan Williams 		struct page *q_src = Q(blocks, disks);
315b2f46fd8SDan Williams 		enum async_tx_flags flags_orig = submit->flags;
316b2f46fd8SDan Williams 		dma_async_tx_callback cb_fn_orig = submit->cb_fn;
317b2f46fd8SDan Williams 		void *scribble = submit->scribble;
318b2f46fd8SDan Williams 		void *cb_param_orig = submit->cb_param;
319b2f46fd8SDan Williams 		void *p, *q, *s;
320b2f46fd8SDan Williams 
321b2f46fd8SDan Williams 		pr_debug("%s: (sync) disks: %d len: %zu\n",
322b2f46fd8SDan Williams 			 __func__, disks, len);
323b2f46fd8SDan Williams 
324b2f46fd8SDan Williams 		/* caller must provide a temporary result buffer and
325b2f46fd8SDan Williams 		 * allow the input parameters to be preserved
326b2f46fd8SDan Williams 		 */
327b2f46fd8SDan Williams 		BUG_ON(!spare || !scribble);
328b2f46fd8SDan Williams 
329b2f46fd8SDan Williams 		/* wait for any prerequisite operations */
330b2f46fd8SDan Williams 		async_tx_quiesce(&submit->depend_tx);
331b2f46fd8SDan Williams 
332b2f46fd8SDan Williams 		/* recompute p and/or q into the temporary buffer and then
333b2f46fd8SDan Williams 		 * check to see the result matches the current value
334b2f46fd8SDan Williams 		 */
335b2f46fd8SDan Williams 		tx = NULL;
336b2f46fd8SDan Williams 		*pqres = 0;
337b2f46fd8SDan Williams 		if (p_src) {
338b2f46fd8SDan Williams 			init_async_submit(submit, ASYNC_TX_XOR_ZERO_DST, NULL,
339b2f46fd8SDan Williams 					  NULL, NULL, scribble);
340b2f46fd8SDan Williams 			tx = async_xor(spare, blocks, offset, disks-2, len, submit);
341b2f46fd8SDan Williams 			async_tx_quiesce(&tx);
342b2f46fd8SDan Williams 			p = page_address(p_src) + offset;
343b2f46fd8SDan Williams 			s = page_address(spare) + offset;
344b2f46fd8SDan Williams 			*pqres |= !!memcmp(p, s, len) << SUM_CHECK_P;
345b2f46fd8SDan Williams 		}
346b2f46fd8SDan Williams 
347b2f46fd8SDan Williams 		if (q_src) {
348b2f46fd8SDan Williams 			P(blocks, disks) = NULL;
349b2f46fd8SDan Williams 			Q(blocks, disks) = spare;
350b2f46fd8SDan Williams 			init_async_submit(submit, 0, NULL, NULL, NULL, scribble);
351b2f46fd8SDan Williams 			tx = async_gen_syndrome(blocks, offset, disks, len, submit);
352b2f46fd8SDan Williams 			async_tx_quiesce(&tx);
353b2f46fd8SDan Williams 			q = page_address(q_src) + offset;
354b2f46fd8SDan Williams 			s = page_address(spare) + offset;
355b2f46fd8SDan Williams 			*pqres |= !!memcmp(q, s, len) << SUM_CHECK_Q;
356b2f46fd8SDan Williams 		}
357b2f46fd8SDan Williams 
358b2f46fd8SDan Williams 		/* restore P, Q and submit */
359b2f46fd8SDan Williams 		P(blocks, disks) = p_src;
360b2f46fd8SDan Williams 		Q(blocks, disks) = q_src;
361b2f46fd8SDan Williams 
362b2f46fd8SDan Williams 		submit->cb_fn = cb_fn_orig;
363b2f46fd8SDan Williams 		submit->cb_param = cb_param_orig;
364b2f46fd8SDan Williams 		submit->flags = flags_orig;
365b2f46fd8SDan Williams 		async_tx_sync_epilog(submit);
366b2f46fd8SDan Williams 
367b2f46fd8SDan Williams 		return NULL;
368b2f46fd8SDan Williams 	}
369b2f46fd8SDan Williams }
370b2f46fd8SDan Williams EXPORT_SYMBOL_GPL(async_syndrome_val);
371b2f46fd8SDan Williams 
372b2f46fd8SDan Williams static int __init async_pq_init(void)
373b2f46fd8SDan Williams {
374b2f46fd8SDan Williams 	scribble = alloc_page(GFP_KERNEL);
375b2f46fd8SDan Williams 
376b2f46fd8SDan Williams 	if (scribble)
377b2f46fd8SDan Williams 		return 0;
378b2f46fd8SDan Williams 
379b2f46fd8SDan Williams 	pr_err("%s: failed to allocate required spare page\n", __func__);
380b2f46fd8SDan Williams 
381b2f46fd8SDan Williams 	return -ENOMEM;
382b2f46fd8SDan Williams }
383b2f46fd8SDan Williams 
384b2f46fd8SDan Williams static void __exit async_pq_exit(void)
385b2f46fd8SDan Williams {
386b2f46fd8SDan Williams 	put_page(scribble);
387b2f46fd8SDan Williams }
388b2f46fd8SDan Williams 
389b2f46fd8SDan Williams module_init(async_pq_init);
390b2f46fd8SDan Williams module_exit(async_pq_exit);
391b2f46fd8SDan Williams 
392b2f46fd8SDan Williams MODULE_DESCRIPTION("asynchronous raid6 syndrome generation/validation");
393b2f46fd8SDan Williams MODULE_LICENSE("GPL");
394