wait_task_stopped/continued: remove unneeded p->signal != NULL check
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / asm-s390 / checksum.h
blobd5a8e7c1477cb51996abed9e9b2f7d65b9c5d06a
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 __wsum
31 csum_partial(const void *buff, int len, __wsum 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 __wsum
53 csum_partial_copy_from_user(const void __user *src, void *dst,
54 int len, __wsum 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 __wsum
70 csum_partial_copy_nocheck (const void *src, void *dst, int len, __wsum 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 __sum16 csum_fold(__wsum sum)
81 #ifndef __s390x__
82 register_pair rp;
84 asm volatile(
85 " slr %N1,%N1\n" /* %0 = H L */
86 " lr %1,%0\n" /* %0 = H L, %1 = H L 0 0 */
87 " srdl %1,16\n" /* %0 = H L, %1 = 0 H L 0 */
88 " alr %1,%N1\n" /* %0 = H L, %1 = L H L 0 */
89 " alr %0,%1\n" /* %0 = H+L+C L+H */
90 " srl %0,16\n" /* %0 = H+L+C */
91 : "+&d" (sum), "=d" (rp) : : "cc");
92 #else /* __s390x__ */
93 asm volatile(
94 " sr 3,3\n" /* %0 = H*65536 + L */
95 " lr 2,%0\n" /* %0 = H L, 2/3 = H L / 0 0 */
96 " srdl 2,16\n" /* %0 = H L, 2/3 = 0 H / L 0 */
97 " alr 2,3\n" /* %0 = H L, 2/3 = L H / L 0 */
98 " alr %0,2\n" /* %0 = H+L+C L+H */
99 " srl %0,16\n" /* %0 = H+L+C */
100 : "+&d" (sum) : : "cc", "2", "3");
101 #endif /* __s390x__ */
102 return (__force __sum16) ~sum;
106 * This is a version of ip_compute_csum() optimized for IP headers,
107 * which always checksum on 4 octet boundaries.
110 static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
112 return csum_fold(csum_partial(iph, ihl*4, 0));
116 * computes the checksum of the TCP/UDP pseudo-header
117 * returns a 32-bit checksum
119 static inline __wsum
120 csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
121 unsigned short len, unsigned short proto,
122 __wsum sum)
124 __u32 csum = (__force __u32)sum;
126 csum += (__force __u32)saddr;
127 if (csum < (__force __u32)saddr)
128 csum++;
130 csum += (__force __u32)daddr;
131 if (csum < (__force __u32)daddr)
132 csum++;
134 csum += len + proto;
135 if (csum < len + proto)
136 csum++;
138 return (__force __wsum)csum;
142 * computes the checksum of the TCP/UDP pseudo-header
143 * returns a 16-bit checksum, already complemented
146 static inline __sum16
147 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
148 unsigned short len, unsigned short proto,
149 __wsum sum)
151 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
155 * this routine is used for miscellaneous IP-like checksums, mainly
156 * in icmp.c
159 static inline __sum16 ip_compute_csum(const void *buff, int len)
161 return csum_fold(csum_partial(buff, len, 0));
164 #endif /* _S390_CHECKSUM_H */