[PATCH] Update Documentation/kprobes.txt
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / asm-s390 / checksum.h
blob37c362d89fad62210c78d8068b953c66679f11dc
1 #ifndef _S390_CHECKSUM_H
2 #define _S390_CHECKSUM_H
4 /*
5 * include/asm-s390/checksum.h
6 * S390 fast network checksum routines
7 * see also arch/S390/lib/checksum.c
9 * S390 version
10 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
11 * Author(s): Ulrich Hild (first version)
12 * Martin Schwidefsky (heavily optimized CKSM version)
13 * D.J. Barrow (third attempt)
16 #include <asm/uaccess.h>
19 * computes the checksum of a memory block at buff, length len,
20 * and adds in "sum" (32-bit)
22 * returns a 32-bit number suitable for feeding into itself
23 * or csum_tcpudp_magic
25 * this function must be called with even lengths, except
26 * for the last fragment, which may be odd
28 * it's best to have buff aligned on a 32-bit boundary
30 static inline unsigned int
31 csum_partial(const unsigned char * buff, int len, unsigned int sum)
33 register unsigned long reg2 asm("2") = (unsigned long) buff;
34 register unsigned long reg3 asm("3") = (unsigned long) len;
36 asm volatile(
37 "0: cksm %0,%1\n" /* do checksum on longs */
38 " jo 0b\n"
39 : "+d" (sum), "+d" (reg2), "+d" (reg3) : : "cc", "memory");
40 return sum;
44 * the same as csum_partial_copy, but copies from user space.
46 * here even more important to align src and dst on a 32-bit (or even
47 * better 64-bit) boundary
49 * Copy from userspace and compute checksum. If we catch an exception
50 * then zero the rest of the buffer.
52 static inline unsigned int
53 csum_partial_copy_from_user(const char __user *src, char *dst,
54 int len, unsigned int sum,
55 int *err_ptr)
57 int missing;
59 missing = copy_from_user(dst, src, len);
60 if (missing) {
61 memset(dst + len - missing, 0, missing);
62 *err_ptr = -EFAULT;
65 return csum_partial(dst, len, sum);
69 static inline unsigned int
70 csum_partial_copy_nocheck (const char *src, char *dst, int len, unsigned int sum)
72 memcpy(dst,src,len);
73 return csum_partial(dst, len, sum);
77 * Fold a partial checksum without adding pseudo headers
79 static inline unsigned short
80 csum_fold(unsigned int sum)
82 #ifndef __s390x__
83 register_pair rp;
85 asm volatile(
86 " slr %N1,%N1\n" /* %0 = H L */
87 " lr %1,%0\n" /* %0 = H L, %1 = H L 0 0 */
88 " srdl %1,16\n" /* %0 = H L, %1 = 0 H L 0 */
89 " alr %1,%N1\n" /* %0 = H L, %1 = L H L 0 */
90 " alr %0,%1\n" /* %0 = H+L+C L+H */
91 " srl %0,16\n" /* %0 = H+L+C */
92 : "+&d" (sum), "=d" (rp) : : "cc");
93 #else /* __s390x__ */
94 asm volatile(
95 " sr 3,3\n" /* %0 = H*65536 + L */
96 " lr 2,%0\n" /* %0 = H L, 2/3 = H L / 0 0 */
97 " srdl 2,16\n" /* %0 = H L, 2/3 = 0 H / L 0 */
98 " alr 2,3\n" /* %0 = H L, 2/3 = L H / L 0 */
99 " alr %0,2\n" /* %0 = H+L+C L+H */
100 " srl %0,16\n" /* %0 = H+L+C */
101 : "+&d" (sum) : : "cc", "2", "3");
102 #endif /* __s390x__ */
103 return ((unsigned short) ~sum);
107 * This is a version of ip_compute_csum() optimized for IP headers,
108 * which always checksum on 4 octet boundaries.
111 static inline unsigned short
112 ip_fast_csum(unsigned char *iph, unsigned int ihl)
114 return csum_fold(csum_partial(iph, ihl*4, 0));
118 * computes the checksum of the TCP/UDP pseudo-header
119 * returns a 32-bit checksum
121 static inline unsigned int
122 csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr,
123 unsigned short len, unsigned short proto,
124 unsigned int sum)
126 #ifndef __s390x__
127 asm volatile(
128 " alr %0,%1\n" /* sum += saddr */
129 " brc 12,0f\n"
130 " ahi %0,1\n" /* add carry */
131 "0:"
132 : "+&d" (sum) : "d" (saddr) : "cc");
133 asm volatile(
134 " alr %0,%1\n" /* sum += daddr */
135 " brc 12,1f\n"
136 " ahi %0,1\n" /* add carry */
137 "1:"
138 : "+&d" (sum) : "d" (daddr) : "cc");
139 asm volatile(
140 " alr %0,%1\n" /* sum += (len<<16) + (proto<<8) */
141 " brc 12,2f\n"
142 " ahi %0,1\n" /* add carry */
143 "2:"
144 : "+&d" (sum)
145 : "d" (((unsigned int) len<<16) + (unsigned int) proto)
146 : "cc");
147 #else /* __s390x__ */
148 asm volatile(
149 " lgfr %0,%0\n"
150 " algr %0,%1\n" /* sum += saddr */
151 " brc 12,0f\n"
152 " aghi %0,1\n" /* add carry */
153 "0: algr %0,%2\n" /* sum += daddr */
154 " brc 12,1f\n"
155 " aghi %0,1\n" /* add carry */
156 "1: algfr %0,%3\n" /* sum += (len<<16) + proto */
157 " brc 12,2f\n"
158 " aghi %0,1\n" /* add carry */
159 "2: srlg 0,%0,32\n"
160 " alr %0,0\n" /* fold to 32 bits */
161 " brc 12,3f\n"
162 " ahi %0,1\n" /* add carry */
163 "3: llgfr %0,%0"
164 : "+&d" (sum)
165 : "d" (saddr), "d" (daddr),
166 "d" (((unsigned int) len<<16) + (unsigned int) proto)
167 : "cc", "0");
168 #endif /* __s390x__ */
169 return sum;
173 * computes the checksum of the TCP/UDP pseudo-header
174 * returns a 16-bit checksum, already complemented
177 static inline unsigned short int
178 csum_tcpudp_magic(unsigned long saddr, unsigned long daddr,
179 unsigned short len, unsigned short proto,
180 unsigned int sum)
182 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
186 * this routine is used for miscellaneous IP-like checksums, mainly
187 * in icmp.c
190 static inline unsigned short
191 ip_compute_csum(unsigned char * buff, int len)
193 return csum_fold(csum_partial(buff, len, 0));
196 #endif /* _S390_CHECKSUM_H */