2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * IP/TCP/UDP checksumming routines
8 * Authors: Jorge Cwik, <jorge@laser.satlink.net>
9 * Arnt Gulbrandsen, <agulbra@nvg.unit.no>
10 * Tom May, <ftom@netcom.com>
11 * Pentium Pro/II routines:
12 * Alexander Kjeldaas <astor@guardian.no>
13 * Finn Arne Gangstad <finnag@guardian.no>
14 * Lots of code moved from tcp.c and ip.c; see those files
17 * Changes: Ingo Molnar, converted csum_partial_copy() to 2.1 exception
19 * Andi Kleen, add zeroing on error
20 * converted to pure assembler
21 * Hirokazu Takata,Hiroyuki Kondo rewrite for the m32r architecture.
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * as published by the Free Software Foundation; either version
26 * 2 of the License, or (at your option) any later version.
31 #include <linux/linkage.h>
32 #include <asm/assembler.h>
33 #include <asm/errno.h>
36 * computes a partial checksum, e.g. for TCP/UDP fragments
40 unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
44 #ifdef CONFIG_ISA_DUAL_ISSUE
47 * Experiments with Ethernet and SLIP connections show that buff
48 * is aligned on either a 2-byte or 4-byte boundary. We get at
49 * least a twofold speedup on 486 and Pentium if it is 4-byte aligned.
50 * Fortunately, it is easy to convert 2-byte alignment to 4-byte
51 * alignment for the unrolled loop.
57 ; r0: unsigned char *buff
59 ; r2: unsigned int sum
62 and3 r7, r0, #1 ; Check alignment.
63 beqz r7, 1f ; Jump if alignment is ok.
65 ldub r4, @r0 || addi r0, #1
66 ; clear c-bit || Alignment uses up bytes.
67 cmp r0, r0 || addi r1, #-1
68 ldi r3, #0 || addx r2, r4
72 and3 r4, r0, #2 ; Check alignment.
73 beqz r4, 2f ; Jump if alignment is ok.
74 ; clear c-bit || Alignment uses up two bytes.
75 cmp r0, r0 || addi r1, #-2
76 bgtz r1, 1f ; Jump if we had at least two bytes.
78 .fillinsn ; len(r1) was < 2. Deal with it.
81 lduh r4, @r0 || ldi r3, #0
82 addx r2, r4 || addi r0, #2
87 cmp r0, r0 ; clear c-bit
95 ld r3, @r0+ || addx r2, r3 ; +12
96 ld r4, @r0+ || addx r2, r4 ; +16
97 ld r5, @r0+ || addx r2, r5 ; +20
98 ld r3, @r0+ || addx r2, r3 ; +24
99 ld r4, @r0+ || addx r2, r4 ; +28
100 addx r2, r5 || addi r6, #-1
106 cmp r0, r0 ; This clears c-bit
108 2: and3 r6, r1, #0x1c ; withdraw len
113 3: ld r4, @r0+ || addi r6, #-1
118 cmp r0, r0 ; This clears c-bit
121 beqz r1, 7f ; if len == 0 goto end
123 beqz r6, 5f ; if len < 2 goto 5f(1byte)
124 lduh r4, @r0 || addi r0, #2
125 addi r1, #-2 || slli r4, #16
129 5: ldub r4, @r0 || ldi r1, #0
130 #ifndef __LITTLE_ENDIAN__
147 beqz r7, 1f ; swap the upper byte for the lower
155 addx r0, r2 || ldi r2, #0
159 #else /* not CONFIG_ISA_DUAL_ISSUE */
162 * Experiments with Ethernet and SLIP connections show that buff
163 * is aligned on either a 2-byte or 4-byte boundary. We get at
164 * least a twofold speedup on 486 and Pentium if it is 4-byte aligned.
165 * Fortunately, it is easy to convert 2-byte alignment to 4-byte
166 * alignment for the unrolled loop.
172 ; r0: unsigned char *buff
174 ; r2: unsigned int sum
178 and3 r7, r0, #1 ; Check alignment.
179 beqz r7, 1f ; Jump if alignment is ok.
183 addi r1, #-1 ; Alignment uses up bytes.
184 cmp r0, r0 ; clear c-bit
190 and3 r4, r0, #2 ; Check alignment.
191 beqz r4, 2f ; Jump if alignment is ok.
192 addi r1, #-2 ; Alignment uses up two bytes.
193 cmp r0, r0 ; clear c-bit
194 bgtz r1, 1f ; Jump if we had at least two bytes.
195 addi r1, #2 ; len(r1) was < 2. Deal with it.
208 cmp r0, r0 ; clear c-bit
232 cmp r0, r0 ; This clears c-bit
235 2: and3 r6, r1, #0x1c ; withdraw len
245 cmp r0, r0 ; This clears c-bit
249 beqz r1, 7f ; if len == 0 goto end
251 beqz r6, 5f ; if len < 2 goto 5f(1byte)
261 #ifndef __LITTLE_ENDIAN__
294 #endif /* not CONFIG_ISA_DUAL_ISSUE */
297 unsigned int csum_partial_copy_generic (const char *src, char *dst,
298 int len, int sum, int *src_err_ptr, int *dst_err_ptr)
302 * Copy from ds while checksumming, otherwise like csum_partial
304 * The macros SRC and DST specify the type of access for the instruction.
305 * thus we can call a custom exception handler for all access types.
307 * FIXME: could someone double-check whether I haven't mixed up some SRC and
308 * DST definitions? It's damn hard to trigger all cases. I hope I got
309 * them all but there's no guarantee.
312 ENTRY(csum_partial_copy_generic)