Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* -*- linux-c -*- ------------------------------------------------------- * |
| 2 | * |
| 3 | * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, Inc., 53 Temple Place Ste 330, |
Atsushi SAKAI | 93ed05e | 2009-03-31 14:57:37 +1100 | [diff] [blame] | 8 | * Boston MA 02111-1307, USA; either version 2 of the License, or |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * (at your option) any later version; incorporated herein by reference. |
| 10 | * |
| 11 | * ----------------------------------------------------------------------- */ |
| 12 | |
| 13 | /* |
| 14 | * raid6altivec$#.c |
| 15 | * |
| 16 | * $#-way unrolled portable integer math RAID-6 instruction set |
| 17 | * |
Vladimir Dronnikov | dce3a7a | 2009-10-16 16:25:19 +1100 | [diff] [blame] | 18 | * This file is postprocessed using unroll.awk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * |
| 20 | * <benh> hpa: in process, |
| 21 | * you can just "steal" the vec unit with enable_kernel_altivec() (but |
| 22 | * bracked this with preempt_disable/enable or in a lock) |
| 23 | */ |
| 24 | |
Dan Williams | f701d58 | 2009-03-31 15:09:39 +1100 | [diff] [blame] | 25 | #include <linux/raid/pq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <altivec.h> |
H. Peter Anvin | d7e70ba | 2005-09-16 19:27:29 -0700 | [diff] [blame] | 28 | #ifdef __KERNEL__ |
H. Peter Anvin | d7e70ba | 2005-09-16 19:27:29 -0700 | [diff] [blame] | 29 | # include <asm/cputable.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 30 | # include <asm/switch_to.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | /* |
H. Peter Anvin | d7e70ba | 2005-09-16 19:27:29 -0700 | [diff] [blame] | 33 | * This is the C data type to use. We use a vector of |
| 34 | * signed char so vec_cmpgt() will generate the right |
| 35 | * instruction. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | */ |
| 37 | |
H. Peter Anvin | d7e70ba | 2005-09-16 19:27:29 -0700 | [diff] [blame] | 38 | typedef vector signed char unative_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
H. Peter Anvin | d7e70ba | 2005-09-16 19:27:29 -0700 | [diff] [blame] | 40 | #define NBYTES(x) ((vector signed char) {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define NSIZE sizeof(unative_t) |
| 42 | |
| 43 | /* |
| 44 | * The SHLBYTE() operation shifts each byte left by 1, *not* |
| 45 | * rolling over into the next byte |
| 46 | */ |
| 47 | static inline __attribute_const__ unative_t SHLBYTE(unative_t v) |
| 48 | { |
| 49 | return vec_add(v,v); |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * The MASK() operation returns 0xFF in any byte for which the high |
| 54 | * bit is 1, 0x00 for any byte for which the high bit is 0. |
| 55 | */ |
| 56 | static inline __attribute_const__ unative_t MASK(unative_t v) |
| 57 | { |
| 58 | unative_t zv = NBYTES(0); |
| 59 | |
| 60 | /* vec_cmpgt returns a vector bool char; thus the need for the cast */ |
| 61 | return (unative_t)vec_cmpgt(zv, v); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | /* This is noinline to make damned sure that gcc doesn't move any of the |
| 66 | Altivec code around the enable/disable code */ |
| 67 | static void noinline |
| 68 | raid6_altivec$#_gen_syndrome_real(int disks, size_t bytes, void **ptrs) |
| 69 | { |
| 70 | u8 **dptr = (u8 **)ptrs; |
| 71 | u8 *p, *q; |
| 72 | int d, z, z0; |
| 73 | |
| 74 | unative_t wd$$, wq$$, wp$$, w1$$, w2$$; |
| 75 | unative_t x1d = NBYTES(0x1d); |
| 76 | |
| 77 | z0 = disks - 3; /* Highest data disk */ |
| 78 | p = dptr[z0+1]; /* XOR parity */ |
| 79 | q = dptr[z0+2]; /* RS syndrome */ |
| 80 | |
| 81 | for ( d = 0 ; d < bytes ; d += NSIZE*$# ) { |
| 82 | wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE]; |
| 83 | for ( z = z0-1 ; z >= 0 ; z-- ) { |
| 84 | wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE]; |
| 85 | wp$$ = vec_xor(wp$$, wd$$); |
| 86 | w2$$ = MASK(wq$$); |
| 87 | w1$$ = SHLBYTE(wq$$); |
| 88 | w2$$ = vec_and(w2$$, x1d); |
| 89 | w1$$ = vec_xor(w1$$, w2$$); |
| 90 | wq$$ = vec_xor(w1$$, wd$$); |
| 91 | } |
| 92 | *(unative_t *)&p[d+NSIZE*$$] = wp$$; |
| 93 | *(unative_t *)&q[d+NSIZE*$$] = wq$$; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | static void raid6_altivec$#_gen_syndrome(int disks, size_t bytes, void **ptrs) |
| 98 | { |
| 99 | preempt_disable(); |
| 100 | enable_kernel_altivec(); |
| 101 | |
| 102 | raid6_altivec$#_gen_syndrome_real(disks, bytes, ptrs); |
| 103 | |
Anton Blanchard | dc4fbba | 2015-10-29 11:44:05 +1100 | [diff] [blame] | 104 | disable_kernel_altivec(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | preempt_enable(); |
| 106 | } |
| 107 | |
| 108 | int raid6_have_altivec(void); |
| 109 | #if $# == 1 |
| 110 | int raid6_have_altivec(void) |
| 111 | { |
| 112 | /* This assumes either all CPUs have Altivec or none does */ |
H. Peter Anvin | d7e70ba | 2005-09-16 19:27:29 -0700 | [diff] [blame] | 113 | # ifdef __KERNEL__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return cpu_has_feature(CPU_FTR_ALTIVEC); |
H. Peter Anvin | d7e70ba | 2005-09-16 19:27:29 -0700 | [diff] [blame] | 115 | # else |
| 116 | return 1; |
| 117 | # endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | #endif |
| 120 | |
| 121 | const struct raid6_calls raid6_altivec$# = { |
| 122 | raid6_altivec$#_gen_syndrome, |
Markus Stockhausen | fe5cbc6 | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 123 | NULL, /* XOR not yet implemented */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | raid6_have_altivec, |
| 125 | "altivecx$#", |
| 126 | 0 |
| 127 | }; |
| 128 | |
| 129 | #endif /* CONFIG_ALTIVEC */ |