This source file includes following definitions.
- csum_partial_copy_nocheck
- csum_partial_copy_from_user
- csum_fold
- csum_tcpudp_nofold
- csum_tcpudp_magic
- ip_fast_csum
1
2 #ifndef __UM_CHECKSUM_H
3 #define __UM_CHECKSUM_H
4
5 #include <linux/string.h>
6 #include <linux/in6.h>
7 #include <linux/uaccess.h>
8
9
10
11
12
13
14
15
16
17
18
19
20
21 extern __wsum csum_partial(const void *buff, int len, __wsum sum);
22
23
24
25
26
27
28
29
30
31 static __inline__
32 __wsum csum_partial_copy_nocheck(const void *src, void *dst,
33 int len, __wsum sum)
34 {
35 memcpy(dst, src, len);
36 return csum_partial(dst, len, sum);
37 }
38
39
40
41
42
43
44
45
46
47 static __inline__
48 __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
49 int len, __wsum sum, int *err_ptr)
50 {
51 if (copy_from_user(dst, src, len)) {
52 *err_ptr = -EFAULT;
53 return (__force __wsum)-1;
54 }
55
56 return csum_partial(dst, len, sum);
57 }
58
59
60
61
62
63
64
65
66
67 static inline __sum16 csum_fold(__wsum sum)
68 {
69 __asm__(
70 " addl %1,%0\n"
71 " adcl $0xffff,%0"
72 : "=r" (sum)
73 : "r" ((__force u32)sum << 16),
74 "0" ((__force u32)sum & 0xffff0000)
75 );
76 return (__force __sum16)(~(__force u32)sum >> 16);
77 }
78
79
80
81
82
83
84
85
86
87
88
89
90 static inline __wsum
91 csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len,
92 __u8 proto, __wsum sum)
93 {
94 asm(" addl %1, %0\n"
95 " adcl %2, %0\n"
96 " adcl %3, %0\n"
97 " adcl $0, %0\n"
98 : "=r" (sum)
99 : "g" (daddr), "g" (saddr), "g" ((len + proto) << 8), "0" (sum));
100 return sum;
101 }
102
103
104
105
106
107 static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
108 __u32 len, __u8 proto,
109 __wsum sum)
110 {
111 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
112 }
113
114
115
116
117
118
119 static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
120 {
121 unsigned int sum;
122
123 asm( " movl (%1), %0\n"
124 " subl $4, %2\n"
125 " jbe 2f\n"
126 " addl 4(%1), %0\n"
127 " adcl 8(%1), %0\n"
128 " adcl 12(%1), %0\n"
129 "1: adcl 16(%1), %0\n"
130 " lea 4(%1), %1\n"
131 " decl %2\n"
132 " jne 1b\n"
133 " adcl $0, %0\n"
134 " movl %0, %2\n"
135 " shrl $16, %0\n"
136 " addw %w2, %w0\n"
137 " adcl $0, %0\n"
138 " notl %0\n"
139 "2:"
140
141
142
143 : "=r" (sum), "=r" (iph), "=r" (ihl)
144 : "1" (iph), "2" (ihl)
145 : "memory");
146 return (__force __sum16)sum;
147 }
148
149 #ifdef CONFIG_X86_32
150 # include "checksum_32.h"
151 #else
152 # include "checksum_64.h"
153 #endif
154
155 #endif