4 /* The xor routines to use. */
5 static struct xor_block_template *active_template;
7 +#ifdef CONFIG_CNS3XXX_RAID
8 +extern void do_cns_rdma_xorgen(unsigned int src_no, unsigned int bytes,
9 + void **bh_ptr, void *dst_ptr);
11 + * xor_blocks - one pass xor
12 + * @src_count: source count
13 + * @bytes: length in bytes
18 + * 1. dest = xor(srcs[0...src_count-1]) within one calc
19 + * 2. don't care if dest also be placed in srcs list or not.
21 +void xor_blocks(unsigned int src_count, unsigned int bytes, void *dest,
24 + do_cns_rdma_xorgen(src_count, bytes, srcs, dest);
28 xor_blocks(unsigned int src_count, unsigned int bytes, void *dest, void **srcs)
30 @@ -51,6 +71,7 @@ xor_blocks(unsigned int src_count, unsig
31 p4 = (unsigned long *) srcs[3];
32 active_template->do_5(bytes, dest, p1, p2, p3, p4);
34 +#endif /* CONFIG_CNS3XXX_RAID */
35 EXPORT_SYMBOL(xor_blocks);
37 /* Set of all registered templates. */
38 @@ -95,7 +116,11 @@ do_xor_speed(struct xor_block_template *
39 speed / 1000, speed % 1000);
42 +#ifdef CONFIG_CNS3XXX_RAID
46 +#endif /* CONFIG_CNS3XXX_RAID */
47 calibrate_xor_blocks(void)
50 @@ -139,7 +164,10 @@ calibrate_xor_blocks(void)
51 if (f->speed > fastest->speed)
55 +#ifdef CONFIG_CNS3XXX_RAID
57 + fastest = template_list;
58 +#endif /* CONFIG_CNS3XXX_RAID */
59 printk(KERN_INFO "xor: using function: %s (%d.%03d MB/sec)\n",
60 fastest->name, fastest->speed / 1000, fastest->speed % 1000);
62 @@ -151,10 +179,20 @@ calibrate_xor_blocks(void)
66 -static __exit void xor_exit(void) { }
67 +#ifndef CONFIG_CNS3XXX_RAID
68 +static __exit void xor_exit(void)
71 +#endif /* ! CONFIG_CNS3XXX_RAID */
73 MODULE_LICENSE("GPL");
75 +#ifdef CONFIG_CNS3XXX_RAID
77 + * Calibrate in R5 init.
80 /* when built-in xor.o must initialize before drivers/md/md.o */
81 core_initcall(calibrate_xor_blocks);
82 module_exit(xor_exit);
83 +#endif /* ! CONFIG_CNS3XXX_RAID */
84 --- a/drivers/md/Makefile
85 +++ b/drivers/md/Makefile
86 @@ -17,7 +17,7 @@ raid6_pq-y += raid6algos.o raid6recov.o
87 raid6int8.o raid6int16.o raid6int32.o \
88 raid6altivec1.o raid6altivec2.o raid6altivec4.o \
90 - raid6mmx.o raid6sse1.o raid6sse2.o
91 + raid6mmx.o raid6sse1.o raid6sse2.o raid6cns.o
92 hostprogs-y += mktables
94 # Note: link order is important. All raid personalities
95 --- a/drivers/md/raid5.c
96 +++ b/drivers/md/raid5.c
97 @@ -1817,11 +1817,30 @@ static void compute_block_2(struct strip
98 compute_parity6(sh, UPDATE_PARITY);
101 +#ifdef CONFIG_CNS3XXX_RAID
107 + ptrs[count++] = page_address(sh->dev[i].page);
108 + i = raid6_next_disk(i, disks);
109 + if (i != dd_idx1 && i != dd_idx2 &&
110 + !test_bit(R5_UPTODATE, &sh->dev[i].flags))
112 + ("compute_2 with missing block %d/%d\n",
114 + } while (i != d0_idx);
116 + raid6_dataq_recov(disks, STRIPE_SIZE, faila, ptrs);
119 /* We're missing D+Q; recompute D from P */
120 compute_block_1(sh, ((dd_idx1 == sh->qd_idx) ?
123 compute_parity6(sh, UPDATE_PARITY); /* Is this necessary? */
124 +#endif /* CONFIG_CNS3XXX_RAID */
128 @@ -5412,8 +5431,21 @@ static struct mdk_personality raid4_pers
129 .quiesce = raid5_quiesce,
132 +#ifdef CONFIG_CNS3XXX_RAID
133 +extern int calibrate_xor_blocks(void);
134 +#endif /* CONFIG_CNS3XXX_RAID */
136 static int __init raid5_init(void)
139 +#ifdef CONFIG_CNS3XXX_RAID
140 + /* Just execute calibrate xor blocks */
142 + e = calibrate_xor_blocks();
145 +#endif /* CONFIG_CNS3XXX_RAID */
147 register_md_personality(&raid6_personality);
148 register_md_personality(&raid5_personality);
149 register_md_personality(&raid4_personality);
150 --- a/drivers/md/raid6algos.c
151 +++ b/drivers/md/raid6algos.c
152 @@ -49,6 +49,9 @@ extern const struct raid6_calls raid6_al
153 extern const struct raid6_calls raid6_altivec2;
154 extern const struct raid6_calls raid6_altivec4;
155 extern const struct raid6_calls raid6_altivec8;
156 +#ifdef CONFIG_CNS3XXX_RAID
157 +extern const struct raid6_calls raid6_cns_raid;
158 +#endif /* CONFIG_CNS3XXX_RAID */
160 const struct raid6_calls * const raid6_algos[] = {
162 @@ -78,6 +81,11 @@ const struct raid6_calls * const raid6_a
166 +#ifdef CONFIG_CNS3XXX_RAID
167 + /* CNS3000 HW RAID acceleration */
169 +#endif /* CONFIG_CNS3XXX_RAID */
174 @@ -125,7 +133,9 @@ int __init raid6_select_algo(void)
175 if ( !(*algo)->valid || (*algo)->valid() ) {
178 +#ifndef CONFIG_CNS3XXX_RAID
182 while ( (j1 = jiffies) == j0 )
184 @@ -134,7 +144,9 @@ int __init raid6_select_algo(void)
185 (*algo)->gen_syndrome(disks, PAGE_SIZE, dptrs);
188 +#ifndef CONFIG_CNS3XXX_RAID
192 if ( (*algo)->prefer > bestprefer ||
193 ((*algo)->prefer == bestprefer &&
195 +++ b/drivers/md/raid6cns.c
200 + * CNS3xxx xor & gen_syndrome functions
204 +#ifdef CONFIG_CNS3XXX_RAID
206 +#include <linux/raid/pq.h>
208 +extern void do_cns_rdma_gfgen(unsigned int src_no, unsigned int bytes, void **bh_ptr,
209 + void *p_dst, void *q_dst);
212 + * raid6_cnsraid_gen_syndrome - CNSRAID Syndrome Generate
214 + * @disks: raid disks
216 + * @ptrs: already arranged stripe ptrs,
217 + * disk0=[0], diskNNN=[disks-3],
218 + * P/Q=[z0+1] & [z0+2], or, [disks-2], [disks-1]
220 +static void raid6_cnsraid_gen_syndrome(int disks, size_t bytes, void **ptrs)
222 + do_cns_rdma_gfgen(disks - 2, bytes, ptrs, ptrs[disks-2], ptrs[disks-1]);
225 +const struct raid6_calls raid6_cns_raid = {
226 + raid6_cnsraid_gen_syndrome, /* callback */
227 + NULL, /* always valid */
228 + "CNS-RAID", /* name */
229 + 1 /* preferred: revise it to "0" to compare/compete with others algos */
232 +EXPORT_SYMBOL(raid6_cns_raid);
234 +#endif /* CONFIG_CNS3XXX_RAID */
235 --- a/drivers/md/raid6recov.c
236 +++ b/drivers/md/raid6recov.c
239 #include <linux/raid/pq.h>
241 +#ifdef CONFIG_CNS3XXX_RAID
242 +#define R6_RECOV_PD 1
243 +#define R6_RECOV_DD 2
244 +#define R6_RECOV_DQ 3
245 +extern void do_cns_rdma_gfgen_pd_dd_dq(unsigned int src_no, unsigned int bytes,
246 + void **bh_ptr, void *w1_dst,
247 + void *w2_dst, int pd_dd_qd,
248 + unsigned int w1_idx, unsigned int w2_idx,
249 + unsigned int *src_idx);
254 + * @faila: 1st failed DD
255 + * @ptrs: ptrs by order {d0, d1, ..., da, ..., dn, P, Q}
258 + * new_read_ptrs = {d0, d1, ... dn, Q}
262 +void raid6_datap_recov(int disks, size_t bytes, int faila, void **ptrs)
268 + void *new_read_ptrs[disks - 2];
269 + unsigned int read_idx[disks - 2];
271 + q = ptrs[disks - 1];
272 + p_dst = ptrs[disks - 2];
273 + dd1_dst = ptrs[faila];
275 + while (cnt < disks) {
276 + if (cnt != faila && cnt != disks - 2) {
277 + new_read_ptrs[count] = ptrs[cnt];
278 + read_idx[count] = cnt;
284 + do_cns_rdma_gfgen_pd_dd_dq(disks - 2, bytes,
285 + new_read_ptrs, p_dst, dd1_dst,
286 + R6_RECOV_PD, disks - 1, faila + 1, read_idx);
292 + * @faila: 1st failed DD
293 + * @failb: 2nd failed DD
294 + * @ptrs: ptrs by order {d0, d1, ..., da, ..., db, ..., dn, P, Q}
297 + * new_read_ptrs = {d0, d1, ... dn, P, Q}
301 +void raid6_2data_recov(int disks, size_t bytes, int faila, int failb,
308 + void *dd1_dst, *dd2_dst;
309 + void *new_read_ptrs[disks - 2];
310 + unsigned int read_idx[disks - 2];
312 + q = ptrs[disks - 1];
313 + p = ptrs[disks - 2];
314 + dd1_dst = ptrs[faila];
315 + dd2_dst = ptrs[failb];
317 + while (cnt < disks) {
318 + if (cnt != faila && cnt != failb) {
319 + new_read_ptrs[count] = ptrs[cnt];
320 + read_idx[count] = cnt;
326 + do_cns_rdma_gfgen_pd_dd_dq(disks - 2, bytes,
327 + new_read_ptrs, dd1_dst, dd2_dst,
328 + R6_RECOV_DD, faila + 1, failb + 1, read_idx);
334 + * @faila: 1st failed DD
335 + * @ptrs: ptrs by order {d0, d1, ..., da, ..., dn, P, Q}
338 + * new_read_ptrs = {d0, d1, ... dn, P}
342 +void raid6_dataq_recov(int disks, size_t bytes, int faila, void **ptrs)
348 + void *new_read_ptrs[disks - 2];
349 + unsigned int read_idx[disks - 2];
351 + p = ptrs[disks - 2];
352 + q_dst = ptrs[disks - 1];
353 + dd1_dst = ptrs[faila];
355 + while (cnt < disks) {
356 + if (cnt != faila && cnt != disks - 1) {
357 + new_read_ptrs[count] = ptrs[cnt];
358 + read_idx[count] = cnt;
364 + do_cns_rdma_gfgen_pd_dd_dq(disks - 2, bytes,
365 + new_read_ptrs, dd1_dst, q_dst,
366 + R6_RECOV_DQ, faila + 1, disks, read_idx);
369 +#else /* CONFIG_CNS3XXX_RAID
371 /* Recover two failed data blocks. */
372 void raid6_2data_recov(int disks, size_t bytes, int faila, int failb,
374 @@ -96,6 +226,7 @@ void raid6_datap_recov(int disks, size_t
377 EXPORT_SYMBOL_GPL(raid6_datap_recov);
378 +#endif /* CONFIG_CNS3XXX_RAID */
382 --- a/include/linux/raid/pq.h
383 +++ b/include/linux/raid/pq.h
384 @@ -100,6 +100,9 @@ void raid6_2data_recov(int disks, size_t
385 void raid6_datap_recov(int disks, size_t bytes, int faila, void **ptrs);
386 void raid6_dual_recov(int disks, size_t bytes, int faila, int failb,
388 +#ifdef CONFIG_CNS3XXX_RAID
389 +void raid6_dataq_recov(int disks, size_t bytes, int faila, void **ptrs);
390 +#endif /* CONFIG_CNS3XXX_RAID */
392 /* Some definitions to allow code to be compiled for testing in userspace */
394 --- a/include/linux/raid/xor.h
395 +++ b/include/linux/raid/xor.h
400 +#ifdef CONFIG_CNS3XXX_RAID
401 +#define MAX_XOR_BLOCKS 32
403 #define MAX_XOR_BLOCKS 4
404 +#endif /* CONFIG_CNS3XXX_RAID */
406 extern void xor_blocks(unsigned int count, unsigned int bytes,
407 void *dest, void **srcs);
410 @@ -250,6 +250,28 @@ repeat_alloc:
412 EXPORT_SYMBOL(mempool_alloc);
414 +#ifdef CONFIG_CNS3XXX_RAID
416 + * acs_mempool_alloc - allocate an element from a specific memory pool
417 + * @pool: pointer to the memory pool which was allocated via
418 + * mempool_create().
420 + * this function differs from mempool_alloc by directly allocating an element
421 + * from @pool without calling @pool->alloc().
423 +void *acs_mempool_alloc(mempool_t * pool)
425 + unsigned long flags;
426 + void *element = NULL;
428 + spin_lock_irqsave(&pool->lock, flags);
429 + if (likely(pool->curr_nr))
430 + element = remove_element(pool);
431 + spin_unlock_irqrestore(&pool->lock, flags);
434 +#endif /* CONFIG_CNS3XXX_RAID */
437 * mempool_free - return an element to the pool.
438 * @element: pool element pointer.