Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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