Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc: add support for csum_add()

The C version of csum_add() as defined in include/net/checksum.h gives
the following assembly in ppc32:
0: 7c 04 1a 14 add r0,r4,r3
4: 7c 64 00 10 subfc r3,r4,r0
8: 7c 63 19 10 subfe r3,r3,r3
c: 7c 63 00 50 subf r3,r3,r0
and the following in ppc64:
0xc000000000001af8 <+0>: add r3,r3,r4
0xc000000000001afc <+4>: cmplw cr7,r3,r4
0xc000000000001b00 <+8>: mfcr r4
0xc000000000001b04 <+12>: rlwinm r4,r4,29,31,31
0xc000000000001b08 <+16>: add r3,r4,r3
0xc000000000001b0c <+20>: clrldi r3,r3,32
0xc000000000001b10 <+24>: blr

include/net/checksum.h also offers the possibility to define an arch
specific function. This patch provides a specific csum_add() inline
function.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <scottwood@freescale.com>

authored by

LEROY Christophe and committed by
Scott Wood
501c8de7 92c985f1

+16
+16
arch/powerpc/include/asm/checksum.h
··· 130 130 return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum)); 131 131 } 132 132 133 + #define HAVE_ARCH_CSUM_ADD 134 + static inline __wsum csum_add(__wsum csum, __wsum addend) 135 + { 136 + #ifdef __powerpc64__ 137 + u64 res = (__force u64)csum; 138 + 139 + res += (__force u64)addend; 140 + return (__force __wsum)((u32)res + (res >> 32)); 141 + #else 142 + asm("addc %0,%0,%1;" 143 + "addze %0,%0;" 144 + : "+r" (csum) : "r" (addend)); 145 + return csum; 146 + #endif 147 + } 148 + 133 149 #endif 134 150 #endif /* __KERNEL__ */ 135 151 #endif