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.
17 * @isum: initial sum that is added into the result (32bit unfolded)
18 * @errp: set to -EFAULT for an bad source address.
20 * Returns an 32bit unfolded checksum of the buffer.
21 * src and dst are best aligned to 64bits.
24 csum_and_copy_from_user(const void __user
*src
, void *dst
, int len
)
29 if (!user_access_begin(src
, len
))
31 sum
= csum_partial_copy_generic((__force
const void *)src
, dst
, len
);
35 EXPORT_SYMBOL(csum_and_copy_from_user
);
38 * csum_and_copy_to_user - Copy and checksum to user space.
39 * @src: source address
40 * @dst: destination address (user space)
41 * @len: number of bytes to be copied.
42 * @isum: initial sum that is added into the result (32bit unfolded)
43 * @errp: set to -EFAULT for an bad destination address.
45 * Returns an 32bit unfolded checksum of the buffer.
46 * src and dst are best aligned to 64bits.
49 csum_and_copy_to_user(const void *src
, void __user
*dst
, int len
)
54 if (!user_access_begin(dst
, len
))
56 sum
= csum_partial_copy_generic(src
, (void __force
*)dst
, len
);
60 EXPORT_SYMBOL(csum_and_copy_to_user
);
63 * csum_partial_copy_nocheck - Copy and checksum.
64 * @src: source address
65 * @dst: destination address
66 * @len: number of bytes to be copied.
67 * @sum: initial sum that is added into the result (32bit unfolded)
69 * Returns an 32bit unfolded checksum of the buffer.
72 csum_partial_copy_nocheck(const void *src
, void *dst
, int len
)
74 return csum_partial_copy_generic(src
, dst
, len
);
76 EXPORT_SYMBOL(csum_partial_copy_nocheck
);
78 __sum16
csum_ipv6_magic(const struct in6_addr
*saddr
,
79 const struct in6_addr
*daddr
,
80 __u32 len
, __u8 proto
, __wsum sum
)
84 rest
= (__force __u64
)htonl(len
) + (__force __u64
)htons(proto
) +
87 asm(" addq (%[saddr]),%[sum]\n"
88 " adcq 8(%[saddr]),%[sum]\n"
89 " adcq (%[daddr]),%[sum]\n"
90 " adcq 8(%[daddr]),%[sum]\n"
94 : "[sum]" (rest
), [saddr
] "r" (saddr
), [daddr
] "r" (daddr
));
97 (__force __wsum
)add32_with_carry(sum64
& 0xffffffff, sum64
>>32));
99 EXPORT_SYMBOL(csum_ipv6_magic
);