2024-02-03 10:45:22 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
#include <linux/export.h>
|
|
|
|
#include <asm/checksum.h>
|
|
|
|
#include <asm/fpu.h>
|
|
|
|
|
|
|
|
/*
|
2024-02-03 10:45:23 +00:00
|
|
|
* Computes the checksum of a memory block at src, length len,
|
|
|
|
* and adds in "sum" (32-bit). If copy is true copies to dst.
|
2024-02-03 10:45:22 +00:00
|
|
|
*
|
|
|
|
* Returns a 32-bit number suitable for feeding into itself
|
|
|
|
* or csum_tcpudp_magic.
|
|
|
|
*
|
|
|
|
* This function must be called with even lengths, except
|
|
|
|
* for the last fragment, which may be odd.
|
|
|
|
*
|
2024-02-03 10:45:23 +00:00
|
|
|
* It's best to have src and dst aligned on a 64-bit boundary.
|
2024-02-03 10:45:22 +00:00
|
|
|
*/
|
2024-02-03 10:45:23 +00:00
|
|
|
static __always_inline __wsum csum_copy(void *dst, const void *src, int len, __wsum sum, bool copy)
|
2024-02-03 10:45:22 +00:00
|
|
|
{
|
|
|
|
DECLARE_KERNEL_FPU_ONSTACK8(vxstate);
|
|
|
|
|
2024-02-03 10:45:23 +00:00
|
|
|
if (!cpu_has_vx()) {
|
|
|
|
if (copy)
|
|
|
|
memcpy(dst, src, len);
|
|
|
|
return cksm(dst, len, sum);
|
|
|
|
}
|
2024-02-03 10:45:22 +00:00
|
|
|
kernel_fpu_begin(&vxstate, KERNEL_VXR_V16V23);
|
|
|
|
fpu_vlvgf(16, (__force u32)sum, 1);
|
|
|
|
fpu_vzero(17);
|
|
|
|
fpu_vzero(18);
|
|
|
|
fpu_vzero(19);
|
|
|
|
while (len >= 64) {
|
2024-02-03 10:45:23 +00:00
|
|
|
fpu_vlm(20, 23, src);
|
|
|
|
if (copy) {
|
|
|
|
fpu_vstm(20, 23, dst);
|
|
|
|
dst += 64;
|
|
|
|
}
|
2024-02-03 10:45:22 +00:00
|
|
|
fpu_vcksm(16, 20, 16);
|
|
|
|
fpu_vcksm(17, 21, 17);
|
|
|
|
fpu_vcksm(18, 22, 18);
|
|
|
|
fpu_vcksm(19, 23, 19);
|
2024-02-03 10:45:23 +00:00
|
|
|
src += 64;
|
2024-02-03 10:45:22 +00:00
|
|
|
len -= 64;
|
|
|
|
}
|
|
|
|
while (len >= 32) {
|
2024-02-03 10:45:23 +00:00
|
|
|
fpu_vlm(20, 21, src);
|
|
|
|
if (copy) {
|
|
|
|
fpu_vstm(20, 21, dst);
|
|
|
|
dst += 32;
|
|
|
|
}
|
2024-02-03 10:45:22 +00:00
|
|
|
fpu_vcksm(16, 20, 16);
|
|
|
|
fpu_vcksm(17, 21, 17);
|
2024-02-03 10:45:23 +00:00
|
|
|
src += 32;
|
2024-02-03 10:45:22 +00:00
|
|
|
len -= 32;
|
|
|
|
}
|
|
|
|
while (len >= 16) {
|
2024-02-03 10:45:23 +00:00
|
|
|
fpu_vl(20, src);
|
|
|
|
if (copy) {
|
|
|
|
fpu_vst(20, dst);
|
|
|
|
dst += 16;
|
|
|
|
}
|
2024-02-03 10:45:22 +00:00
|
|
|
fpu_vcksm(16, 20, 16);
|
2024-02-03 10:45:23 +00:00
|
|
|
src += 16;
|
2024-02-03 10:45:22 +00:00
|
|
|
len -= 16;
|
|
|
|
}
|
|
|
|
if (len) {
|
2024-02-03 10:45:23 +00:00
|
|
|
fpu_vll(20, len - 1, src);
|
|
|
|
if (copy)
|
|
|
|
fpu_vstl(20, len - 1, dst);
|
2024-02-03 10:45:22 +00:00
|
|
|
fpu_vcksm(16, 20, 16);
|
|
|
|
}
|
|
|
|
fpu_vcksm(18, 19, 18);
|
|
|
|
fpu_vcksm(16, 17, 16);
|
|
|
|
fpu_vcksm(16, 18, 16);
|
|
|
|
sum = (__force __wsum)fpu_vlgvf(16, 1);
|
|
|
|
kernel_fpu_end(&vxstate, KERNEL_VXR_V16V23);
|
|
|
|
return sum;
|
|
|
|
}
|
2024-02-03 10:45:23 +00:00
|
|
|
|
|
|
|
__wsum csum_partial(const void *buff, int len, __wsum sum)
|
|
|
|
{
|
|
|
|
return csum_copy(NULL, buff, len, sum, false);
|
|
|
|
}
|
2024-02-03 10:45:22 +00:00
|
|
|
EXPORT_SYMBOL(csum_partial);
|
2024-02-03 10:45:23 +00:00
|
|
|
|
|
|
|
__wsum csum_partial_copy_nocheck(const void *src, void *dst, int len)
|
|
|
|
{
|
|
|
|
return csum_copy(dst, src, len, 0, true);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(csum_partial_copy_nocheck);
|