1 /* $Id: checksum.h,v 1.6 1998/09/16 13:30:51 ralf Exp $
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
7 * Copyright (C) 1995, 1996, 1997, 1998 by Ralf Baechle
9 #ifndef __ASM_MIPS_CHECKSUM_H
10 #define __ASM_MIPS_CHECKSUM_H
13 * computes the checksum of a memory block at buff, length len,
14 * and adds in "sum" (32-bit)
16 * returns a 32-bit number suitable for feeding into itself
17 * or csum_tcpudp_magic
19 * this function must be called with even lengths, except
20 * for the last fragment, which may be odd
22 * it's best to have buff aligned on a 32-bit boundary
24 unsigned int csum_partial(const unsigned char * buff
, int len
, unsigned int sum
);
27 * this is a new version of the above that records errors it finds in *errp,
28 * but continues and zeros the rest of the buffer.
30 #define csum_partial_copy_nocheck csum_partial_copy
33 * this is a new version of the above that records errors it finds in *errp,
34 * but continues and zeros the rest of the buffer.
36 unsigned int csum_partial_copy_from_user(const char *src
, char *dst
, int len
,
37 unsigned int sum
, int *errp
);
39 #define HAVE_CSUM_COPY_USER
40 unsigned int csum_and_copy_to_user (const char *src
, char *dst
,
41 int len
, int sum
, int *err_ptr
);
44 * the same as csum_partial, but copies from user space (but on MIPS
45 * we have just one address space, so this is identical to the above)
47 * this is obsolete and will go away.
49 #define csum_partial_copy_fromuser csum_partial_copy
50 unsigned int csum_partial_copy(const char *src
, char *dst
, int len
, unsigned int sum
);
53 * Fold a partial checksum without adding pseudo headers
55 static inline unsigned short int csum_fold(unsigned int sum
)
74 * This is a version of ip_compute_csum() optimized for IP headers,
75 * which always checksum on 4 octet boundaries.
77 * By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by
80 static inline unsigned short ip_fast_csum(unsigned char * iph
,
87 * This is for 32-bit MIPS processors.
89 __asm__
__volatile__("
98 addu %2,%1 # delay slot
116 addu %0,$1 # delay slot
120 : "=&r" (sum
), "=&r" (iph
), "=&r" (ihl
), "=&r" (dummy
)
121 : "1" (iph
), "2" (ihl
)
124 return csum_fold(sum
);
128 * computes the checksum of the TCP/UDP pseudo-header
129 * returns a 16-bit checksum, already complemented
131 static inline unsigned long csum_tcpudp_nofold(unsigned long saddr
,
134 unsigned short proto
,
152 : "0" (daddr
), "r"(saddr
),
154 "r" ((ntohs(len
)<<16)+proto
*256),
156 "r" (((proto
)<<16)+len
),
165 * computes the checksum of the TCP/UDP pseudo-header
166 * returns a 16-bit checksum, already complemented
168 static inline unsigned short int csum_tcpudp_magic(unsigned long saddr
,
171 unsigned short proto
,
174 return csum_fold(csum_tcpudp_nofold(saddr
,daddr
,len
,proto
,sum
));
178 * this routine is used for miscellaneous IP-like checksums, mainly
181 static inline unsigned short ip_compute_csum(unsigned char * buff
, int len
)
183 return csum_fold(csum_partial(buff
, len
, 0));
186 #define _HAVE_ARCH_IPV6_CSUM
187 static __inline__
unsigned short int csum_ipv6_magic(struct in6_addr
*saddr
,
188 struct in6_addr
*daddr
,
190 unsigned short proto
,
196 addu %0,%5 # proto (long in network byte order)
202 lw %1,0(%2) # four words source address
247 "0" (htonl((__u32
) (len
))),
252 return csum_fold(sum
);
255 #endif /* __ASM_MIPS_CHECKSUM_H */