1
2
3
4
5
6
7
8
9
10
11
12#ifndef _S390_CHECKSUM_H
13#define _S390_CHECKSUM_H
14
15#include <linux/uaccess.h>
16
17
18
19
20
21
22
23
24
25
26
27
28
29static inline __wsum
30csum_partial(const void *buff, int len, __wsum sum)
31{
32 register unsigned long reg2 asm("2") = (unsigned long) buff;
33 register unsigned long reg3 asm("3") = (unsigned long) len;
34
35 asm volatile(
36 "0: cksm %0,%1\n"
37 " jo 0b\n"
38 : "+d" (sum), "+d" (reg2), "+d" (reg3) : : "cc", "memory");
39 return sum;
40}
41
42
43
44
45
46
47
48
49
50static inline __wsum
51csum_partial_copy_from_user(const void __user *src, void *dst,
52 int len, __wsum sum,
53 int *err_ptr)
54{
55 if (unlikely(copy_from_user(dst, src, len)))
56 *err_ptr = -EFAULT;
57 return csum_partial(dst, len, sum);
58}
59
60
61static inline __wsum
62csum_partial_copy_nocheck (const void *src, void *dst, int len, __wsum sum)
63{
64 memcpy(dst,src,len);
65 return csum_partial(dst, len, sum);
66}
67
68
69
70
71static inline __sum16 csum_fold(__wsum sum)
72{
73 u32 csum = (__force u32) sum;
74
75 csum += (csum >> 16) + (csum << 16);
76 csum >>= 16;
77 return (__force __sum16) ~csum;
78}
79
80
81
82
83
84
85static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
86{
87 return csum_fold(csum_partial(iph, ihl*4, 0));
88}
89
90
91
92
93
94static inline __wsum
95csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len, __u8 proto,
96 __wsum sum)
97{
98 __u32 csum = (__force __u32)sum;
99
100 csum += (__force __u32)saddr;
101 if (csum < (__force __u32)saddr)
102 csum++;
103
104 csum += (__force __u32)daddr;
105 if (csum < (__force __u32)daddr)
106 csum++;
107
108 csum += len + proto;
109 if (csum < len + proto)
110 csum++;
111
112 return (__force __wsum)csum;
113}
114
115
116
117
118
119
120static inline __sum16
121csum_tcpudp_magic(__be32 saddr, __be32 daddr, __u32 len, __u8 proto,
122 __wsum sum)
123{
124 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
125}
126
127
128
129
130
131
132static inline __sum16 ip_compute_csum(const void *buff, int len)
133{
134 return csum_fold(csum_partial(buff, len, 0));
135}
136
137#endif
138
139
140