1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2002, 2003 Andi Kleen, SuSE Labs.
5 * Wrappers of assembly checksum functions for x86-64.
7 #include <asm/checksum.h>
8 #include <linux/export.h>
9 #include <linux/uaccess.h>
13 * csum_and_copy_from_user - Copy and checksum from user space.
14 * @src: source address (user space)
15 * @dst: destination address
16 * @len: number of bytes to be copied.
18 * Returns an 32bit unfolded checksum of the buffer.
19 * src and dst are best aligned to 64bits.
22 csum_and_copy_from_user(const void __user
*src
, void *dst
, int len
)
27 if (!user_access_begin(src
, len
))
29 sum
= csum_partial_copy_generic((__force
const void *)src
, dst
, len
);
35 * csum_and_copy_to_user - Copy and checksum to user space.
36 * @src: source address
37 * @dst: destination address (user space)
38 * @len: number of bytes to be copied.
40 * Returns an 32bit unfolded checksum of the buffer.
41 * src and dst are best aligned to 64bits.
44 csum_and_copy_to_user(const void *src
, void __user
*dst
, int len
)
49 if (!user_access_begin(dst
, len
))
51 sum
= csum_partial_copy_generic(src
, (void __force
*)dst
, len
);
57 * csum_partial_copy_nocheck - Copy and checksum.
58 * @src: source address
59 * @dst: destination address
60 * @len: number of bytes to be copied.
62 * Returns an 32bit unfolded checksum of the buffer.
65 csum_partial_copy_nocheck(const void *src
, void *dst
, int len
)
67 return csum_partial_copy_generic(src
, dst
, len
);
69 EXPORT_SYMBOL(csum_partial_copy_nocheck
);
71 __sum16
csum_ipv6_magic(const struct in6_addr
*saddr
,
72 const struct in6_addr
*daddr
,
73 __u32 len
, __u8 proto
, __wsum sum
)
77 rest
= (__force __u64
)htonl(len
) + (__force __u64
)htons(proto
) +
80 asm(" addq (%[saddr]),%[sum]\n"
81 " adcq 8(%[saddr]),%[sum]\n"
82 " adcq (%[daddr]),%[sum]\n"
83 " adcq 8(%[daddr]),%[sum]\n"
87 : "[sum]" (rest
), [saddr
] "r" (saddr
), [daddr
] "r" (daddr
));
90 (__force __wsum
)add32_with_carry(sum64
& 0xffffffff, sum64
>>32));
92 EXPORT_SYMBOL(csum_ipv6_magic
);