Import 2.3.99pre8
[davej-history.git] / arch / s390 / lib / checksum.c
blob9411e1c5e93c11681f017f0a8d517e8b2511826f
1 /*
2 * arch/s390/lib/checksum.c
3 * S390 fast network checksum routines
5 * S390 version
6 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Ulrich Hild (first version),
8 * Martin Schwidefsky (schwidefsky@de.ibm.com),
9 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
11 * This file contains network checksum routines
14 #include <linux/string.h>
15 #include <linux/types.h>
16 #include <asm/uaccess.h>
17 #include <asm/byteorder.h>
18 #include <asm/checksum.h>
21 * computes a partial checksum, e.g. for TCP/UDP fragments
23 unsigned int
24 csum_partial (const unsigned char *buff, int len, unsigned int sum)
27 * Experiments with ethernet and slip connections show that buff
28 * is aligned on either a 2-byte or 4-byte boundary.
30 __asm__ __volatile__ (
31 " lr 2,%1\n" /* address in gpr 2 */
32 " lr 3,%2\n" /* length in gpr 3 */
33 "0: cksm %0,2\n" /* do checksum on longs */
34 " jo 0b\n"
35 : "+&d" (sum)
36 : "d" (buff), "d" (len)
37 : "cc", "2", "3" );
38 return sum;
42 * Fold a partial checksum without adding pseudo headers
44 unsigned short csum_fold(unsigned int sum)
46 __asm__ __volatile__ (
47 " sr 3,3\n" /* %0 = H*65536 + L */
48 " lr 2,%0\n" /* %0 = H L, R2/R3 = H L / 0 0 */
49 " srdl 2,16\n" /* %0 = H L, R2/R3 = 0 H / L 0 */
50 " alr 2,3\n" /* %0 = H L, R2/R3 = L H / L 0 */
51 " alr %0,2\n" /* %0 = H+L+C L+H */
52 " srl %0,16\n" /* %0 = H+L+C */
53 : "+d" (sum) : : "cc", "2", "3");
54 return ((unsigned short) ~sum);