1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/export.h>
4 #include <asm/checksum.h>
8 * Computes the checksum of a memory block at src, length len,
9 * and adds in "sum" (32-bit). If copy is true copies to dst.
11 * Returns a 32-bit number suitable for feeding into itself
12 * or csum_tcpudp_magic.
14 * This function must be called with even lengths, except
15 * for the last fragment, which may be odd.
17 * It's best to have src and dst aligned on a 64-bit boundary.
19 static __always_inline __wsum csum_copy(void *dst, const void *src, int len, __wsum sum, bool copy)
21 DECLARE_KERNEL_FPU_ONSTACK8(vxstate);
25 memcpy(dst, src, len);
26 return cksm(dst, len, sum);
28 kernel_fpu_begin(&vxstate, KERNEL_VXR_V16V23);
29 fpu_vlvgf(16, (__force u32)sum, 1);
36 fpu_vstm(20, 23, dst);
39 fpu_vcksm(16, 20, 16);
40 fpu_vcksm(17, 21, 17);
41 fpu_vcksm(18, 22, 18);
42 fpu_vcksm(19, 23, 19);
49 fpu_vstm(20, 21, dst);
52 fpu_vcksm(16, 20, 16);
53 fpu_vcksm(17, 21, 17);
63 fpu_vcksm(16, 20, 16);
68 fpu_vll(20, len - 1, src);
70 fpu_vstl(20, len - 1, dst);
71 fpu_vcksm(16, 20, 16);
73 fpu_vcksm(18, 19, 18);
74 fpu_vcksm(16, 17, 16);
75 fpu_vcksm(16, 18, 16);
76 sum = (__force __wsum)fpu_vlgvf(16, 1);
77 kernel_fpu_end(&vxstate, KERNEL_VXR_V16V23);
81 __wsum csum_partial(const void *buff, int len, __wsum sum)
83 return csum_copy(NULL, buff, len, sum, false);
85 EXPORT_SYMBOL(csum_partial);
87 __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len)
89 return csum_copy(dst, src, len, 0, true);
91 EXPORT_SYMBOL(csum_partial_copy_nocheck);