This source file includes following definitions.
- ip_fast_csum
- csum_tcpudp_magic
- csum_fold
- ip_compute_csum
1
2
3
4
5
6
7
8
9
10 #ifndef __ASM_MIPS_CHECKSUM_H
11 #define __ASM_MIPS_CHECKSUM_H
12
13
14
15
16
17
18
19
20
21
22
23
24
25 unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum);
26
27
28
29
30
31
32
33
34 unsigned int csum_partial_copy(const char *src, char *dst, int len, int sum);
35
36
37
38
39
40 #define csum_partial_copy_fromuser csum_partial_copy
41
42
43
44
45
46
47
48
49 static inline unsigned short ip_fast_csum(unsigned char * iph,
50 unsigned int ihl)
51 {
52 unsigned short int sum;
53 unsigned long dummy1, dummy2;
54
55
56
57
58
59
60
61 __asm__("
62 .set noreorder
63 .set noat
64 lw %0,(%3)
65 subu %1,4
66 blez %1,2f
67 sll %1,%4,2 # delay slot
68 lw %2,4(%3)
69 addu %1,%3 # delay slot
70 addu %0,%2
71 sltu $1,%0,%2
72 lw %2,8(%3)
73 addu %0,$1
74 addu %0,%2
75 sltu $1,%0,%2
76 lw %2,12(%3)
77 addu %0,$1
78 addu %0,%2
79 sltu $1,%0,%2
80 addu %0,$1
81 1: lw %2,16(%3)
82 addu %1,4
83 addu %0,%2
84 sltu $1,%0,%2
85 bne %1,%3,1b
86 addu %0,$1 # delay slot
87 srl $1,%0,16
88 addu %0,$1
89 sltu $1,%0,$1
90 addu %0,$1
91 nor %0,$0,%0
92 andi %0,0xffff
93 2: .set at
94 .set reorder"
95 : "=r" (sum), "=r" (dummy1), "=r" (dummy2)
96 : "r" (iph), "r"(ihl)
97 : "$1");
98
99 return sum;
100 }
101
102
103
104
105
106 static inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
107 unsigned long daddr,
108 unsigned short len,
109 unsigned short proto,
110 unsigned int sum)
111 {
112 __asm__("
113 .set noat
114 addu %0,%2
115 sltu $1,%0,%2
116 addu %0,$1
117 addu %0,%3
118 sltu $1,%0,%3
119 addu %0,$1
120 addu %0,%4
121 sltu $1,%0,%4
122 addu %0,$1
123 srl $1,%0,16
124 addu %0,$1
125 sltu $1,%0,$1
126 addu %0,$1
127 nor %0,$0,%0
128 andi %0,0xffff
129 .set at"
130 : "=r" (sum)
131 : "0" (daddr), "r"(saddr), "r"((ntohs(len)<<16)+proto*256), "r"(sum)
132 : "$1");
133
134 return (unsigned short)sum;
135 }
136
137
138
139
140 static inline unsigned short int csum_fold(unsigned int sum)
141 {
142 __asm__("
143 .set noat
144 srl $1,%0,16
145 addu %0,$1
146 sltu $1,%0,$1
147 nor %0,$0,%0
148 andi %0,0xffff
149 .set at"
150 : "=r"(sum)
151 : "0" (sum)
152 : "$1");
153
154 return sum;
155 }
156
157
158
159
160
161 static inline unsigned short ip_compute_csum(unsigned char * buff, int len) {
162 unsigned short int sum;
163
164 __asm__("
165 .set noat
166 srl $1,%0,16
167 addu %0,$1
168 sltu $1,%0,$1
169 nor %0,$0,%0
170 andi %0,0xffff
171 .set at"
172 : "=r"(sum)
173 : "r" (csum_partial(buff, len, 0))
174 : "$1");
175
176 return sum;
177 }
178
179 #endif