Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / include / asm-parisc / checksum.h
blob9088f979504ea466a8960e9dfd5c270f088b2570
1 #ifndef _PARISC_CHECKSUM_H
2 #define _PARISC_CHECKSUM_H
4 /*
5 * computes the checksum of a memory block at buff, length len,
6 * and adds in "sum" (32-bit)
8 * returns a 32-bit number suitable for feeding into itself
9 * or csum_tcpudp_magic
11 * this function must be called with even lengths, except
12 * for the last fragment, which may be odd
14 * it's best to have buff aligned on a 32-bit boundary
16 extern unsigned int csum_partial(const unsigned char *, int, unsigned int);
19 * the same as csum_partial, but copies from src while it
20 * checksums
22 * here even more important to align src and dst on a 32-bit (or even
23 * better 64-bit) boundary
25 extern unsigned int csum_partial_copy(const char *, char *, int, unsigned int);
28 * the same as csum_partial, but copies from user space
30 * this is obsolete and will go away.
32 #define csum_partial_copy_fromuser csum_partial_copy
35 * this is a new version of the above that records errors it finds in *errp,
36 * but continues and zeros the rest of the buffer.
38 unsigned int csum_partial_copy_from_user(const char *src, char *dst, int len, unsigned int sum, int *errp);
41 * Note: when you get a NULL pointer exception here this means someone
42 * passed in an incorrect kernel address to one of these functions.
44 * If you use these functions directly please don't forget the
45 * verify_area().
47 extern __inline__
48 unsigned int csum_partial_copy_nocheck (const char *src, char *dst,
49 int len, int sum)
51 return csum_partial_copy (src, dst, len, sum);
55 * Optimized for IP headers, which always checksum on 4 octet boundaries.
57 * Written by Randolph Chung <tausq@debian.org>
59 static inline unsigned short ip_fast_csum(unsigned char * iph,
60 unsigned int ihl) {
61 unsigned int sum;
64 __asm__ __volatile__ ("
65 ldws,ma 4(%1), %0
66 addi -4, %2, %2
67 comib,>= 0, %2, 2f
69 ldws,ma 4(%1), %%r19
70 add %0, %%r19, %0
71 ldws,ma 4(%1), %%r19
72 addc %0, %%r19, %0
73 ldws,ma 4(%1), %%r19
74 addc %0, %%r19, %0
75 1: ldws,ma 4(%1), %%r19
76 addib,<> -1, %2, 1b
77 addc %0, %%r19, %0
78 addc %0, %%r0, %0
80 zdepi -1, 31, 16, %%r19
81 and %0, %%r19, %%r20
82 extru %0, 15, 16, %%r21
83 add %%r20, %%r21, %0
84 and %0, %%r19, %%r20
85 extru %0, 15, 16, %%r21
86 add %%r20, %%r21, %0
87 subi -1, %0, %0
90 : "=r" (sum), "=r" (iph), "=r" (ihl)
91 : "1" (iph), "2" (ihl)
92 : "r19", "r20", "r21" );
94 return(sum);
98 * Fold a partial checksum
100 static inline unsigned int csum_fold(unsigned int sum)
102 sum = (sum & 0xffff) + (sum >> 16);
103 sum = (sum & 0xffff) + (sum >> 16);
104 return ~sum;
107 static inline unsigned long csum_tcpudp_nofold(unsigned long saddr,
108 unsigned long daddr,
109 unsigned short len,
110 unsigned short proto,
111 unsigned int sum)
113 __asm__("
114 add %1, %0, %0
115 addc %2, %0, %0
116 addc %3, %0, %0
117 addc %%r0, %0, %0 "
118 : "=r" (sum)
119 : "r" (daddr), "r"(saddr), "r"((proto<<16)+len), "0"(sum));
120 return sum;
124 * computes the checksum of the TCP/UDP pseudo-header
125 * returns a 16-bit checksum, already complemented
127 static inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
128 unsigned long daddr,
129 unsigned short len,
130 unsigned short proto,
131 unsigned int sum)
133 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
137 * this routine is used for miscellaneous IP-like checksums, mainly
138 * in icmp.c
140 static inline unsigned short ip_compute_csum(unsigned char * buf, int len) {
141 return csum_fold (csum_partial(buf, len, 0));
144 #define _HAVE_ARCH_IPV6_CSUM
145 static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr,
146 struct in6_addr *daddr,
147 __u16 len,
148 unsigned short proto,
149 unsigned int sum)
151 BUG();
152 return csum_fold(sum);
156 * Copy and checksum to user
158 #define HAVE_CSUM_COPY_USER
159 static __inline__ unsigned int csum_and_copy_to_user (const char *src, char *dst,
160 int len, int sum, int *err_ptr)
162 /* code stolen from include/asm-mips64 */
163 sum = csum_partial(src, len, sum);
165 if (copy_to_user(dst, src, len)) {
166 *err_ptr = -EFAULT;
167 return -1;
170 return sum;
173 #endif