2 * This file contains assembly-language implementations
3 * of IP-style 1's complement checksum routines.
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * Severely hacked about by Paul Mackerras (paulus@cs.anu.edu.au).
15 #include <linux/sys.h>
16 #include <asm/processor.h>
17 #include <asm/cache.h>
18 #include <asm/errno.h>
19 #include <asm/ppc_asm.h>
20 #include <asm/export.h>
25 * computes the checksum of a memory block at buff, length len,
26 * and adds in "sum" (32-bit)
28 * __csum_partial(buff, len, sum)
30 _GLOBAL(__csum_partial)
32 srawi. r6,r4,2 /* Divide len by 4 and also clear carry */
33 beq 3f /* if we're doing < 4 bytes */
34 andi. r0,r3,2 /* Align buffer to longword boundary */
36 lhz r0,4(r3) /* do 2 bytes to get aligned */
39 srwi. r6,r4,2 /* # words to do */
42 1: andi. r6,r6,3 /* Prepare to handle words 4 by 4 */
48 21: srwi. r6,r4,4 /* # blocks of 4 words to do */
68 slwi r0,r0,8 /* Upper byte of word */
70 5: addze r3,r5 /* add in final carry */
72 EXPORT_SYMBOL(__csum_partial)
75 * Computes the checksum of a memory block at src, length len,
76 * and adds in "sum" (32-bit), while copying the block to dst.
77 * If an access exception occurs on src or dst, it stores -EFAULT
78 * to *src_err or *dst_err respectively, and (for an error on
79 * src) zeroes the rest of dst.
81 * csum_partial_copy_generic(src, dst, len, sum, src_err, dst_err)
83 #define CSUM_COPY_16_BYTES_WITHEX(n) \
105 #define CSUM_COPY_16_BYTES_EXCODE(n) \
106 EX_TABLE(8 ## n ## 0b, src_error); \
107 EX_TABLE(8 ## n ## 1b, src_error); \
108 EX_TABLE(8 ## n ## 2b, src_error); \
109 EX_TABLE(8 ## n ## 3b, src_error); \
110 EX_TABLE(8 ## n ## 4b, dst_error); \
111 EX_TABLE(8 ## n ## 5b, dst_error); \
112 EX_TABLE(8 ## n ## 6b, dst_error); \
113 EX_TABLE(8 ## n ## 7b, dst_error);
116 .stabs "arch/powerpc/lib/",N_SO,0,0,0f
117 .stabs "checksum_32.S",N_SO,0,0,0f
120 CACHELINE_BYTES = L1_CACHE_BYTES
121 LG_CACHELINE_BYTES = L1_CACHE_SHIFT
122 CACHELINE_MASK = (L1_CACHE_BYTES-1)
124 _GLOBAL(csum_partial_copy_generic)
133 andi. r0,r0,CACHELINE_MASK /* # bytes to start of cache line */
137 cmplw 0,r5,r0 /* is this more than total to do? */
138 blt 63f /* if not much to do */
140 rlwnm r12,r12,r7,0,31 /* odd destination address: rotate one byte */
141 cmplwi cr7,r7,0 /* is destination address even ? */
142 andi. r8,r0,3 /* get it word-aligned first */
146 70: lbz r9,4(r4) /* do some bytes */
158 72: lwzu r9,4(r4) /* do some words */
163 58: srwi. r0,r5,LG_CACHELINE_BYTES /* # complete cachelines */
164 clrlwi r5,r5,32-LG_CACHELINE_BYTES
168 /* Here we decide how far ahead to prefetch the source */
174 #if MAX_COPY_PREFETCH > 1
175 /* Heuristically, for large transfers we prefetch
176 MAX_COPY_PREFETCH cachelines ahead. For small transfers
177 we prefetch 1 cacheline ahead. */
178 cmpwi r0,MAX_COPY_PREFETCH
180 li r7,MAX_COPY_PREFETCH
183 addi r3,r3,CACHELINE_BYTES
187 addi r3,r3,CACHELINE_BYTES
188 #endif /* MAX_COPY_PREFETCH > 1 */
196 /* the main body of the cacheline loop */
197 CSUM_COPY_16_BYTES_WITHEX(0)
198 #if L1_CACHE_BYTES >= 32
199 CSUM_COPY_16_BYTES_WITHEX(1)
200 #if L1_CACHE_BYTES >= 64
201 CSUM_COPY_16_BYTES_WITHEX(2)
202 CSUM_COPY_16_BYTES_WITHEX(3)
203 #if L1_CACHE_BYTES >= 128
204 CSUM_COPY_16_BYTES_WITHEX(4)
205 CSUM_COPY_16_BYTES_WITHEX(5)
206 CSUM_COPY_16_BYTES_WITHEX(6)
207 CSUM_COPY_16_BYTES_WITHEX(7)
241 rlwinm r3,r3,8,0,31 /* odd destination address: rotate one byte */
263 EX_TABLE(70b, src_error);
264 EX_TABLE(71b, dst_error);
265 EX_TABLE(72b, src_error);
266 EX_TABLE(73b, dst_error);
267 EX_TABLE(54b, dst_error);
270 * this stuff handles faults in the cacheline loop and branches to either
271 * src_error (if in read part) or dst_error (if in write part)
273 CSUM_COPY_16_BYTES_EXCODE(0)
274 #if L1_CACHE_BYTES >= 32
275 CSUM_COPY_16_BYTES_EXCODE(1)
276 #if L1_CACHE_BYTES >= 64
277 CSUM_COPY_16_BYTES_EXCODE(2)
278 CSUM_COPY_16_BYTES_EXCODE(3)
279 #if L1_CACHE_BYTES >= 128
280 CSUM_COPY_16_BYTES_EXCODE(4)
281 CSUM_COPY_16_BYTES_EXCODE(5)
282 CSUM_COPY_16_BYTES_EXCODE(6)
283 CSUM_COPY_16_BYTES_EXCODE(7)
288 EX_TABLE(30b, src_error);
289 EX_TABLE(31b, dst_error);
290 EX_TABLE(40b, src_error);
291 EX_TABLE(41b, dst_error);
292 EX_TABLE(50b, src_error);
293 EX_TABLE(51b, dst_error);
295 EXPORT_SYMBOL(csum_partial_copy_generic)