1 #ifndef _PARISC_CHECKSUM_H
2 #define _PARISC_CHECKSUM_H
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
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
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
48 unsigned int csum_partial_copy_nocheck (const char *src
, char *dst
,
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
,
64 __asm__
__volatile__ ("
75 1: ldws,ma 4(%1), %%r19
80 zdepi -1, 31, 16, %%r19
82 extru %0, 15, 16, %%r21
85 extru %0, 15, 16, %%r21
90 : "=r" (sum
), "=r" (iph
), "=r" (ihl
)
91 : "1" (iph
), "2" (ihl
)
92 : "r19", "r20", "r21" );
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);
107 static inline unsigned long csum_tcpudp_nofold(unsigned long saddr
,
110 unsigned short proto
,
119 : "r" (daddr
), "r"(saddr
), "r"((proto
<<16)+len
), "0"(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
,
130 unsigned short proto
,
133 return csum_fold(csum_tcpudp_nofold(saddr
,daddr
,len
,proto
,sum
));
137 * this routine is used for miscellaneous IP-like checksums, mainly
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
,
148 unsigned short proto
,
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
)) {