This source file includes following definitions.
- ip_fast_csum
- csum_tcpudp_magic
- csum_fold
- ip_compute_csum
- ip_compute_csum
1 #ifndef _M68K_CHECKSUM_H
2 #define _M68K_CHECKSUM_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16 unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum);
17
18
19
20
21
22
23
24
25
26 unsigned int csum_partial_copy(const char *src, char *dst, int len, int sum);
27
28
29
30
31
32
33
34
35
36 unsigned int csum_partial_copy_fromuser(const char *src, char *dst, int len, int sum);
37
38
39
40
41
42
43
44 static inline unsigned short
45 ip_fast_csum(unsigned char *iph, unsigned int ihl)
46 {
47 unsigned int sum = 0;
48
49 __asm__ ("subqw #1,%2\n"
50 "1:\t"
51 "movel %1@+,%/d0\n\t"
52 "addxl %/d0,%0\n\t"
53 "dbra %2,1b\n\t"
54 "movel %0,%/d0\n\t"
55 "swap %/d0\n\t"
56 "addxw %/d0,%0\n\t"
57 "clrw %/d0\n\t"
58 "addxw %/d0,%0\n\t"
59 : "=d" (sum), "=a" (iph), "=d" (ihl)
60 : "0" (sum), "1" (iph), "2" (ihl)
61 : "d0");
62 return ~sum;
63 }
64
65
66
67
68
69
70
71
72 static inline unsigned short int
73 csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len,
74 unsigned short proto, unsigned int sum)
75 {
76 __asm__ ("addl %1,%0\n\t"
77 "addxl %4,%0\n\t"
78 "addxl %5,%0\n\t"
79 "movl %0,%1\n\t"
80 "swap %1\n\t"
81 "addxw %1,%0\n\t"
82 "clrw %1\n\t"
83 "addxw %1,%0\n\t"
84 : "=&d" (sum), "=&d" (saddr)
85 : "0" (daddr), "1" (saddr), "d" (len + proto),
86 "d"(sum));
87 return ~sum;
88 }
89
90
91
92
93
94 static inline unsigned int csum_fold(unsigned int sum)
95 {
96 unsigned int tmp = sum;
97 __asm__("swap %1\n\t"
98 "addw %1, %0\n\t"
99 "clrw %1\n\t"
100 "addxw %1, %0"
101 : "=&d" (sum), "=&d" (tmp)
102 : "0" (sum), "1" (sum));
103 return ~sum;
104 }
105
106
107
108
109
110
111 #if 1
112 static inline unsigned short
113 ip_compute_csum(unsigned char * buff, int len)
114 {
115 unsigned int sum;
116 unsigned int scratch;
117
118 __asm__("movel %0,%1\n\t"
119 "swap %1\n\t"
120 "addw %1,%0\n\t"
121 "clrw %1\n\t"
122 "addxw %1,%0\n\t"
123 : "=d" (sum), "=d" (scratch)
124 : "0" (csum_partial(buff, len, 0)));
125 return ~sum;
126 }
127 #else
128 static inline unsigned short
129 ip_compute_csum(unsigned char * buff, int len)
130 {
131 unsigned long sum = 0;
132
133
134 if (len > 3)
135 {
136 int dummy;
137 __asm__ ("subql #1,%2\n\t"
138 "1:\t"
139 "movel %1@+,%/d0\n\t"
140 "addxl %/d0,%0\n\t"
141 "dbra %2,1b\n\t"
142 "movel %0,%/d0\n\t"
143 "swap %/d0\n\t"
144 "addxw %/d0,%0\n\t"
145 "clrw %/d0\n\t"
146 "addxw %/d0,%0"
147 : "=d" (sum), "=a" (buff), "=d" (dummy)
148 : "0" (sum), "1" (buff), "2" (len >> 2)
149 : "d0");
150 }
151 if (len & 2)
152 {
153 __asm__ ("addw %1@+,%0\n\t"
154 "addxw %2,%0"
155 : "=d" (sum), "=a" (buff)
156 : "d" (0), "0" (sum), "1" (buff));
157 }
158 if (len & 1)
159 {
160 __asm__ ("movew %1@,%/d0\n\t"
161 "clrb %/d0\n\t"
162 "addw %/d0,%0\n\t"
163 "clrw %/d0\n\t"
164 "addxw %/d0,%0"
165 : "=d" (sum)
166 : "a" (buff), "0" (sum)
167 : "d0");
168 }
169
170 sum =~sum;
171 return(sum & 0xffff);
172 }
173 #endif
174
175 #endif