1
2
3
4
5
6
7
8
9#ifndef __ASM_ARM_CHECKSUM_H
10#define __ASM_ARM_CHECKSUM_H
11
12#include <linux/in6.h>
13
14
15
16
17
18
19
20
21
22
23
24
25
26__wsum csum_partial(const void *buff, int len, __wsum sum);
27
28
29
30
31
32
33
34
35
36__wsum
37csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
38
39__wsum
40csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
41
42
43
44
45static inline __sum16 csum_fold(__wsum sum)
46{
47 __asm__(
48 "add %0, %1, %1, ror #16 @ csum_fold"
49 : "=r" (sum)
50 : "r" (sum)
51 : "cc");
52 return (__force __sum16)(~(__force u32)sum >> 16);
53}
54
55
56
57
58
59static inline __sum16
60ip_fast_csum(const void *iph, unsigned int ihl)
61{
62 unsigned int tmp1;
63 __wsum sum;
64
65 __asm__ __volatile__(
66 "ldr %0, [%1], #4 @ ip_fast_csum \n\
67 ldr %3, [%1], #4 \n\
68 sub %2, %2, #5 \n\
69 adds %0, %0, %3 \n\
70 ldr %3, [%1], #4 \n\
71 adcs %0, %0, %3 \n\
72 ldr %3, [%1], #4 \n\
731: adcs %0, %0, %3 \n\
74 ldr %3, [%1], #4 \n\
75 tst %2, #15 @ do this carefully \n\
76 subne %2, %2, #1 @ without destroying \n\
77 bne 1b @ the carry flag \n\
78 adcs %0, %0, %3 \n\
79 adc %0, %0, #0"
80 : "=r" (sum), "=r" (iph), "=r" (ihl), "=r" (tmp1)
81 : "1" (iph), "2" (ihl)
82 : "cc", "memory");
83 return csum_fold(sum);
84}
85
86static inline __wsum
87csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len,
88 __u8 proto, __wsum sum)
89{
90 u32 lenprot = len + proto;
91 if (__builtin_constant_p(sum) && sum == 0) {
92 __asm__(
93 "adds %0, %1, %2 @ csum_tcpudp_nofold0 \n\t"
94#ifdef __ARMEB__
95 "adcs %0, %0, %3 \n\t"
96#else
97 "adcs %0, %0, %3, ror #8 \n\t"
98#endif
99 "adc %0, %0, #0"
100 : "=&r" (sum)
101 : "r" (daddr), "r" (saddr), "r" (lenprot)
102 : "cc");
103 } else {
104 __asm__(
105 "adds %0, %1, %2 @ csum_tcpudp_nofold \n\t"
106 "adcs %0, %0, %3 \n\t"
107#ifdef __ARMEB__
108 "adcs %0, %0, %4 \n\t"
109#else
110 "adcs %0, %0, %4, ror #8 \n\t"
111#endif
112 "adc %0, %0, #0"
113 : "=&r"(sum)
114 : "r" (sum), "r" (daddr), "r" (saddr), "r" (lenprot)
115 : "cc");
116 }
117 return sum;
118}
119
120
121
122
123static inline __sum16
124csum_tcpudp_magic(__be32 saddr, __be32 daddr, __u32 len,
125 __u8 proto, __wsum sum)
126{
127 return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
128}
129
130
131
132
133
134
135static inline __sum16
136ip_compute_csum(const void *buff, int len)
137{
138 return csum_fold(csum_partial(buff, len, 0));
139}
140
141#define _HAVE_ARCH_IPV6_CSUM
142extern __wsum
143__csum_ipv6_magic(const struct in6_addr *saddr, const struct in6_addr *daddr, __be32 len,
144 __be32 proto, __wsum sum);
145
146static inline __sum16
147csum_ipv6_magic(const struct in6_addr *saddr, const struct in6_addr *daddr,
148 __u32 len, __u8 proto, __wsum sum)
149{
150 return csum_fold(__csum_ipv6_magic(saddr, daddr, htonl(len),
151 htonl(proto), sum));
152}
153#endif
154