x86/amd-iommu: Pt mode fix for domain_destroy
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / crypto / async_tx / raid6test.c
blobf84f6b4301d98df03dd02c05db9d4351885bc39e
1 /*
2 * asynchronous raid6 recovery self test
3 * Copyright (c) 2009, Intel Corporation.
5 * based on drivers/md/raid6test/test.c:
6 * Copyright 2002-2007 H. Peter Anvin
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <linux/async_tx.h>
23 #include <linux/random.h>
25 #undef pr
26 #define pr(fmt, args...) pr_info("raid6test: " fmt, ##args)
28 #define NDISKS 16 /* Including P and Q */
30 static struct page *dataptrs[NDISKS];
31 static addr_conv_t addr_conv[NDISKS];
32 static struct page *data[NDISKS+3];
33 static struct page *spare;
34 static struct page *recovi;
35 static struct page *recovj;
37 static void callback(void *param)
39 struct completion *cmp = param;
41 complete(cmp);
44 static void makedata(int disks)
46 int i, j;
48 for (i = 0; i < disks; i++) {
49 for (j = 0; j < PAGE_SIZE/sizeof(u32); j += sizeof(u32)) {
50 u32 *p = page_address(data[i]) + j;
52 *p = random32();
55 dataptrs[i] = data[i];
59 static char disk_type(int d, int disks)
61 if (d == disks - 2)
62 return 'P';
63 else if (d == disks - 1)
64 return 'Q';
65 else
66 return 'D';
69 /* Recover two failed blocks. */
70 static void raid6_dual_recov(int disks, size_t bytes, int faila, int failb, struct page **ptrs)
72 struct async_submit_ctl submit;
73 struct completion cmp;
74 struct dma_async_tx_descriptor *tx = NULL;
75 enum sum_check_flags result = ~0;
77 if (faila > failb)
78 swap(faila, failb);
80 if (failb == disks-1) {
81 if (faila == disks-2) {
82 /* P+Q failure. Just rebuild the syndrome. */
83 init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
84 tx = async_gen_syndrome(ptrs, 0, disks, bytes, &submit);
85 } else {
86 struct page *blocks[disks];
87 struct page *dest;
88 int count = 0;
89 int i;
91 /* data+Q failure. Reconstruct data from P,
92 * then rebuild syndrome
94 for (i = disks; i-- ; ) {
95 if (i == faila || i == failb)
96 continue;
97 blocks[count++] = ptrs[i];
99 dest = ptrs[faila];
100 init_async_submit(&submit, ASYNC_TX_XOR_ZERO_DST, NULL,
101 NULL, NULL, addr_conv);
102 tx = async_xor(dest, blocks, 0, count, bytes, &submit);
104 init_async_submit(&submit, 0, tx, NULL, NULL, addr_conv);
105 tx = async_gen_syndrome(ptrs, 0, disks, bytes, &submit);
107 } else {
108 if (failb == disks-2) {
109 /* data+P failure. */
110 init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
111 tx = async_raid6_datap_recov(disks, bytes, faila, ptrs, &submit);
112 } else {
113 /* data+data failure. */
114 init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
115 tx = async_raid6_2data_recov(disks, bytes, faila, failb, ptrs, &submit);
118 init_completion(&cmp);
119 init_async_submit(&submit, ASYNC_TX_ACK, tx, callback, &cmp, addr_conv);
120 tx = async_syndrome_val(ptrs, 0, disks, bytes, &result, spare, &submit);
121 async_tx_issue_pending(tx);
123 if (wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)) == 0)
124 pr("%s: timeout! (faila: %d failb: %d disks: %d)\n",
125 __func__, faila, failb, disks);
127 if (result != 0)
128 pr("%s: validation failure! faila: %d failb: %d sum_check_flags: %x\n",
129 __func__, faila, failb, result);
132 static int test_disks(int i, int j, int disks)
134 int erra, errb;
136 memset(page_address(recovi), 0xf0, PAGE_SIZE);
137 memset(page_address(recovj), 0xba, PAGE_SIZE);
139 dataptrs[i] = recovi;
140 dataptrs[j] = recovj;
142 raid6_dual_recov(disks, PAGE_SIZE, i, j, dataptrs);
144 erra = memcmp(page_address(data[i]), page_address(recovi), PAGE_SIZE);
145 errb = memcmp(page_address(data[j]), page_address(recovj), PAGE_SIZE);
147 pr("%s(%d, %d): faila=%3d(%c) failb=%3d(%c) %s\n",
148 __func__, i, j, i, disk_type(i, disks), j, disk_type(j, disks),
149 (!erra && !errb) ? "OK" : !erra ? "ERRB" : !errb ? "ERRA" : "ERRAB");
151 dataptrs[i] = data[i];
152 dataptrs[j] = data[j];
154 return erra || errb;
157 static int test(int disks, int *tests)
159 struct dma_async_tx_descriptor *tx;
160 struct async_submit_ctl submit;
161 struct completion cmp;
162 int err = 0;
163 int i, j;
165 recovi = data[disks];
166 recovj = data[disks+1];
167 spare = data[disks+2];
169 makedata(disks);
171 /* Nuke syndromes */
172 memset(page_address(data[disks-2]), 0xee, PAGE_SIZE);
173 memset(page_address(data[disks-1]), 0xee, PAGE_SIZE);
175 /* Generate assumed good syndrome */
176 init_completion(&cmp);
177 init_async_submit(&submit, ASYNC_TX_ACK, NULL, callback, &cmp, addr_conv);
178 tx = async_gen_syndrome(dataptrs, 0, disks, PAGE_SIZE, &submit);
179 async_tx_issue_pending(tx);
181 if (wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)) == 0) {
182 pr("error: initial gen_syndrome(%d) timed out\n", disks);
183 return 1;
186 pr("testing the %d-disk case...\n", disks);
187 for (i = 0; i < disks-1; i++)
188 for (j = i+1; j < disks; j++) {
189 (*tests)++;
190 err += test_disks(i, j, disks);
193 return err;
197 static int raid6_test(void)
199 int err = 0;
200 int tests = 0;
201 int i;
203 for (i = 0; i < NDISKS+3; i++) {
204 data[i] = alloc_page(GFP_KERNEL);
205 if (!data[i]) {
206 while (i--)
207 put_page(data[i]);
208 return -ENOMEM;
212 /* the 4-disk and 5-disk cases are special for the recovery code */
213 if (NDISKS > 4)
214 err += test(4, &tests);
215 if (NDISKS > 5)
216 err += test(5, &tests);
217 /* the 11 and 12 disk cases are special for ioatdma (p-disabled
218 * q-continuation without extended descriptor)
220 if (NDISKS > 12) {
221 err += test(11, &tests);
222 err += test(12, &tests);
224 err += test(NDISKS, &tests);
226 pr("\n");
227 pr("complete (%d tests, %d failure%s)\n",
228 tests, err, err == 1 ? "" : "s");
230 for (i = 0; i < NDISKS+3; i++)
231 put_page(data[i]);
233 return 0;
236 static void raid6_test_exit(void)
240 /* when compiled-in wait for drivers to load first (assumes dma drivers
241 * are also compliled-in)
243 late_initcall(raid6_test);
244 module_exit(raid6_test_exit);
245 MODULE_AUTHOR("Dan Williams <dan.j.williams@intel.com>");
246 MODULE_DESCRIPTION("asynchronous RAID-6 recovery self tests");
247 MODULE_LICENSE("GPL");