This source file includes following definitions.
- csum_fold
- ip_fast_csum
- csum_tcpudp_nofold
- csum_tcpudp_magic
- add32_with_carry
- csum_add
1
2 #ifndef _ASM_X86_CHECKSUM_64_H
3 #define _ASM_X86_CHECKSUM_64_H
4
5
6
7
8
9
10
11 #include <linux/compiler.h>
12 #include <linux/uaccess.h>
13 #include <asm/byteorder.h>
14
15
16
17
18
19
20
21
22
23 static inline __sum16 csum_fold(__wsum sum)
24 {
25 asm(" addl %1,%0\n"
26 " adcl $0xffff,%0"
27 : "=r" (sum)
28 : "r" ((__force u32)sum << 16),
29 "0" ((__force u32)sum & 0xffff0000));
30 return (__force __sum16)(~(__force u32)sum >> 16);
31 }
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
47 {
48 unsigned int sum;
49
50 asm(" movl (%1), %0\n"
51 " subl $4, %2\n"
52 " jbe 2f\n"
53 " addl 4(%1), %0\n"
54 " adcl 8(%1), %0\n"
55 " adcl 12(%1), %0\n"
56 "1: adcl 16(%1), %0\n"
57 " lea 4(%1), %1\n"
58 " decl %2\n"
59 " jne 1b\n"
60 " adcl $0, %0\n"
61 " movl %0, %2\n"
62 " shrl $16, %0\n"
63 " addw %w2, %w0\n"
64 " adcl $0, %0\n"
65 " notl %0\n"
66 "2:"
67
68
69
70 : "=r" (sum), "=r" (iph), "=r" (ihl)
71 : "1" (iph), "2" (ihl)
72 : "memory");
73 return (__force __sum16)sum;
74 }
75
76
77
78
79
80
81
82
83
84
85
86
87 static inline __wsum
88 csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len,
89 __u8 proto, __wsum sum)
90 {
91 asm(" addl %1, %0\n"
92 " adcl %2, %0\n"
93 " adcl %3, %0\n"
94 " adcl $0, %0\n"
95 : "=r" (sum)
96 : "g" (daddr), "g" (saddr),
97 "g" ((len + proto)<<8), "0" (sum));
98 return sum;
99 }
100
101
102
103
104
105
106
107
108
109
110
111
112
113 static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
114 __u32 len, __u8 proto,
115 __wsum sum)
116 {
117 return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
118 }
119
120
121
122
123
124
125
126
127
128
129
130 extern __wsum csum_partial(const void *buff, int len, __wsum sum);
131
132 #define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER 1
133 #define HAVE_CSUM_COPY_USER 1
134
135
136
137 extern __visible __wsum csum_partial_copy_generic(const void *src, const void *dst,
138 int len, __wsum sum,
139 int *src_err_ptr, int *dst_err_ptr);
140
141
142 extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
143 int len, __wsum isum, int *errp);
144 extern __wsum csum_partial_copy_to_user(const void *src, void __user *dst,
145 int len, __wsum isum, int *errp);
146 extern __wsum csum_partial_copy_nocheck(const void *src, void *dst,
147 int len, __wsum sum);
148
149
150 #define csum_and_copy_to_user csum_partial_copy_to_user
151 #define csum_and_copy_from_user csum_partial_copy_from_user
152
153
154
155
156
157
158
159
160
161 extern __sum16 ip_compute_csum(const void *buff, int len);
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176 struct in6_addr;
177
178 #define _HAVE_ARCH_IPV6_CSUM 1
179 extern __sum16
180 csum_ipv6_magic(const struct in6_addr *saddr, const struct in6_addr *daddr,
181 __u32 len, __u8 proto, __wsum sum);
182
183 static inline unsigned add32_with_carry(unsigned a, unsigned b)
184 {
185 asm("addl %2,%0\n\t"
186 "adcl $0,%0"
187 : "=r" (a)
188 : "0" (a), "rm" (b));
189 return a;
190 }
191
192 #define HAVE_ARCH_CSUM_ADD
193 static inline __wsum csum_add(__wsum csum, __wsum addend)
194 {
195 return (__force __wsum)add32_with_carry((__force unsigned)csum,
196 (__force unsigned)addend);
197 }
198
199 #endif