1
2
3
4
5
6
7
8#ifndef __ASM_AVR32_CHECKSUM_H
9#define __ASM_AVR32_CHECKSUM_H
10
11
12
13
14
15
16
17
18
19
20
21
22
23__wsum csum_partial(const void *buff, int len, __wsum sum);
24
25
26
27
28
29
30
31
32__wsum csum_partial_copy_generic(const void *src, void *dst, int len,
33 __wsum sum, int *src_err_ptr,
34 int *dst_err_ptr);
35
36
37
38
39
40
41
42
43static inline
44__wsum csum_partial_copy_nocheck(const void *src, void *dst,
45 int len, __wsum sum)
46{
47 return csum_partial_copy_generic(src, dst, len, sum, NULL, NULL);
48}
49
50static inline
51__wsum csum_partial_copy_from_user(const void __user *src, void *dst,
52 int len, __wsum sum, int *err_ptr)
53{
54 return csum_partial_copy_generic((const void __force *)src, dst, len,
55 sum, err_ptr, NULL);
56}
57
58
59
60
61
62static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
63{
64 unsigned int sum, tmp;
65
66 __asm__ __volatile__(
67 " ld.w %0, %1++\n"
68 " ld.w %3, %1++\n"
69 " sub %2, 4\n"
70 " add %0, %3\n"
71 " ld.w %3, %1++\n"
72 " adc %0, %0, %3\n"
73 " ld.w %3, %1++\n"
74 " adc %0, %0, %3\n"
75 " acr %0\n"
76 "1: ld.w %3, %1++\n"
77 " add %0, %3\n"
78 " acr %0\n"
79 " sub %2, 1\n"
80 " brne 1b\n"
81 " lsl %3, %0, 16\n"
82 " andl %0, 0\n"
83 " mov %2, 0xffff\n"
84 " add %0, %3\n"
85 " adc %0, %0, %2\n"
86 " com %0\n"
87 " lsr %0, 16\n"
88 : "=r"(sum), "=r"(iph), "=r"(ihl), "=r"(tmp)
89 : "1"(iph), "2"(ihl)
90 : "memory", "cc");
91 return (__force __sum16)sum;
92}
93
94
95
96
97
98static inline __sum16 csum_fold(__wsum sum)
99{
100 unsigned int tmp;
101
102 asm(" bfextu %1, %0, 0, 16\n"
103 " lsr %0, 16\n"
104 " add %0, %1\n"
105 " bfextu %1, %0, 16, 16\n"
106 " add %0, %1"
107 : "=&r"(sum), "=&r"(tmp)
108 : "0"(sum));
109
110 return (__force __sum16)~sum;
111}
112
113static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
114 unsigned short len,
115 unsigned short proto,
116 __wsum sum)
117{
118 asm(" add %0, %1\n"
119 " adc %0, %0, %2\n"
120 " adc %0, %0, %3\n"
121 " acr %0"
122 : "=r"(sum)
123 : "r"(daddr), "r"(saddr), "r"(len + proto),
124 "0"(sum)
125 : "cc");
126
127 return sum;
128}
129
130
131
132
133
134static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
135 unsigned short len,
136 unsigned short proto,
137 __wsum sum)
138{
139 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
140}
141
142
143
144
145
146
147static inline __sum16 ip_compute_csum(const void *buff, int len)
148{
149 return csum_fold(csum_partial(buff, len, 0));
150}
151
152#endif
153