2 #ifndef _ASM_M32R_CHECKSUM_H
3 #define _ASM_M32R_CHECKSUM_H
6 * include/asm-m32r/checksum.h
8 * IP/TCP/UDP checksum routines
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
14 * Some code taken from mips and parisc architecture.
16 * Copyright (C) 2001, 2002 Hiroyuki Kondo, Hirokazu Takata
17 * Copyright (C) 2004 Hirokazu Takata <takata at linux-m32r.org>
20 #include <linux/in6.h>
23 * computes the checksum of a memory block at buff, length len,
24 * and adds in "sum" (32-bit)
26 * returns a 32-bit number suitable for feeding into itself
27 * or csum_tcpudp_magic
29 * this function must be called with even lengths, except
30 * for the last fragment, which may be odd
32 * it's best to have buff aligned on a 32-bit boundary
34 asmlinkage
unsigned int csum_partial(const unsigned char *buff
,
35 int len
, unsigned int sum
);
38 * The same as csum_partial, but copies from src while it checksums.
40 * Here even more important to align src and dst on a 32-bit (or even
41 * better 64-bit) boundary
43 extern unsigned int csum_partial_copy_nocheck(const unsigned char *src
,
45 int len
, unsigned int sum
);
48 * This is a new version of the above that records errors it finds in *errp,
49 * but continues and zeros thre rest of the buffer.
51 extern unsigned int csum_partial_copy_from_user(const unsigned char __user
*src
,
53 int len
, unsigned int sum
,
57 * Fold a partial checksum
60 static inline unsigned int csum_fold(unsigned int sum
)
64 " sll3 %1, %0, #16 \n"
70 " xor3 %0, %0, #0x0000ffff \n"
71 : "=r" (sum
), "=&r" (tmpreg
)
79 * This is a version of ip_compute_csum() optimized for IP headers,
80 * which always checksum on 4 octet boundaries.
82 static inline unsigned short ip_fast_csum(unsigned char * iph
,
84 unsigned long sum
, tmpreg0
, tmpreg1
;
108 /* Since the input registers which are loaded with iph and ipl
109 are modified, we must also specify them as outputs, or gcc
110 will assume they contain their original values. */
111 : "=&r" (sum
), "=r" (iph
), "=r" (ihl
), "=&r" (tmpreg0
), "=&r" (tmpreg1
)
112 : "1" (iph
), "2" (ihl
)
115 return csum_fold(sum
);
118 static inline unsigned long csum_tcpudp_nofold(unsigned long saddr
,
121 unsigned short proto
,
124 #if defined(__LITTLE_ENDIAN)
125 unsigned long len_proto
= (ntohs(len
)<<16)+proto
*256;
127 unsigned long len_proto
= (proto
<<16)+len
;
129 unsigned long tmpreg
;
138 : "=r" (sum
), "=&r" (tmpreg
)
139 : "r" (daddr
), "r" (saddr
), "r" (len_proto
), "0" (sum
)
147 * computes the checksum of the TCP/UDP pseudo-header
148 * returns a 16-bit checksum, already complemented
150 static inline unsigned short int csum_tcpudp_magic(unsigned long saddr
,
153 unsigned short proto
,
156 return csum_fold(csum_tcpudp_nofold(saddr
,daddr
,len
,proto
,sum
));
160 * this routine is used for miscellaneous IP-like checksums, mainly
164 static inline unsigned short ip_compute_csum(unsigned char * buff
, int len
) {
165 return csum_fold (csum_partial(buff
, len
, 0));
168 #define _HAVE_ARCH_IPV6_CSUM
169 static inline unsigned short int csum_ipv6_magic(struct in6_addr
*saddr
,
170 struct in6_addr
*daddr
,
172 unsigned short proto
,
175 unsigned long tmpreg0
, tmpreg1
, tmpreg2
, tmpreg3
;
180 " ld %4, @(12,%5) \n"
188 " ld %4, @(12,%6) \n"
197 : "=&r" (sum
), "=&r" (tmpreg0
), "=&r" (tmpreg1
),
198 "=&r" (tmpreg2
), "=&r" (tmpreg3
)
199 : "r" (saddr
), "r" (daddr
),
200 "r" (htonl((__u32
) (len
))), "r" (htonl(proto
)), "0" (sum
)
204 return csum_fold(sum
);
207 #endif /* _ASM_M32R_CHECKSUM_H */
208 #endif /* __KERNEL__ */