1
2
3
4
5
6
7#include <asm/checksum.h>
8#include <linux/export.h>
9#include <linux/uaccess.h>
10#include <asm/smap.h>
11
12
13
14
15
16
17
18
19
20
21
22
23__wsum
24csum_and_copy_from_user(const void __user *src, void *dst, int len)
25{
26 __wsum sum;
27
28 might_sleep();
29 if (!user_access_begin(src, len))
30 return 0;
31 sum = csum_partial_copy_generic((__force const void *)src, dst, len);
32 user_access_end();
33 return sum;
34}
35EXPORT_SYMBOL(csum_and_copy_from_user);
36
37
38
39
40
41
42
43
44
45
46
47
48__wsum
49csum_and_copy_to_user(const void *src, void __user *dst, int len)
50{
51 __wsum sum;
52
53 might_sleep();
54 if (!user_access_begin(dst, len))
55 return 0;
56 sum = csum_partial_copy_generic(src, (void __force *)dst, len);
57 user_access_end();
58 return sum;
59}
60EXPORT_SYMBOL(csum_and_copy_to_user);
61
62
63
64
65
66
67
68
69
70
71__wsum
72csum_partial_copy_nocheck(const void *src, void *dst, int len)
73{
74 return csum_partial_copy_generic(src, dst, len);
75}
76EXPORT_SYMBOL(csum_partial_copy_nocheck);
77
78__sum16 csum_ipv6_magic(const struct in6_addr *saddr,
79 const struct in6_addr *daddr,
80 __u32 len, __u8 proto, __wsum sum)
81{
82 __u64 rest, sum64;
83
84 rest = (__force __u64)htonl(len) + (__force __u64)htons(proto) +
85 (__force __u64)sum;
86
87 asm(" addq (%[saddr]),%[sum]\n"
88 " adcq 8(%[saddr]),%[sum]\n"
89 " adcq (%[daddr]),%[sum]\n"
90 " adcq 8(%[daddr]),%[sum]\n"
91 " adcq $0,%[sum]\n"
92
93 : [sum] "=r" (sum64)
94 : "[sum]" (rest), [saddr] "r" (saddr), [daddr] "r" (daddr));
95
96 return csum_fold(
97 (__force __wsum)add32_with_carry(sum64 & 0xffffffff, sum64>>32));
98}
99EXPORT_SYMBOL(csum_ipv6_magic);
100