blob: 9c62a031a8f5654dd83f40235eb6422e24a7aac2 [file] [log] [blame]
Paul Mundta23ba432007-11-28 20:19:38 +09001#ifndef __ASM_SH_CHECKSUM_64_H
2#define __ASM_SH_CHECKSUM_64_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
4/*
Paul Mundta23ba432007-11-28 20:19:38 +09005 * include/asm-sh/checksum_64.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * Copyright (C) 2000, 2001 Paolo Alberelli
8 *
Paul Mundta23ba432007-11-28 20:19:38 +09009 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014/*
15 * computes the checksum of a memory block at buff, length len,
16 * and adds in "sum" (32-bit)
17 *
18 * returns a 32-bit number suitable for feeding into itself
19 * or csum_tcpudp_magic
20 *
21 * this function must be called with even lengths, except
22 * for the last fragment, which may be odd
23 *
24 * it's best to have buff aligned on a 32-bit boundary
25 */
Al Viroc459dd92006-11-14 21:19:01 -080026asmlinkage __wsum csum_partial(const void *buff, int len, __wsum sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28/*
29 * Note: when you get a NULL pointer exception here this means someone
30 * passed in an incorrect kernel address to one of these functions.
31 *
32 * If you use these functions directly please don't forget the
Jesper Juhle49332b2005-05-01 08:59:08 -070033 * access_ok().
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 */
35
36
Al Viroc459dd92006-11-14 21:19:01 -080037__wsum csum_partial_copy_nocheck(const void *src, void *dst, int len,
38 __wsum sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Al Viroc459dd92006-11-14 21:19:01 -080040__wsum csum_partial_copy_from_user(const void __user *src, void *dst,
41 int len, __wsum sum, int *err_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Al Viroc459dd92006-11-14 21:19:01 -080043static inline __sum16 csum_fold(__wsum csum)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
Al Viroc459dd92006-11-14 21:19:01 -080045 u32 sum = (__force u32)csum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 sum = (sum & 0xffff) + (sum >> 16);
47 sum = (sum & 0xffff) + (sum >> 16);
Al Viroc459dd92006-11-14 21:19:01 -080048 return (__force __sum16)~sum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Al Viroc459dd92006-11-14 21:19:01 -080051__sum16 ip_fast_csum(const void *iph, unsigned int ihl);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Al Viroc459dd92006-11-14 21:19:01 -080053__wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 unsigned short len, unsigned short proto,
Al Viroc459dd92006-11-14 21:19:01 -080055 __wsum sum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57/*
58 * computes the checksum of the TCP/UDP pseudo-header
59 * returns a 16-bit checksum, already complemented
60 */
Al Viroc459dd92006-11-14 21:19:01 -080061static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 unsigned short len,
63 unsigned short proto,
Al Viroc459dd92006-11-14 21:19:01 -080064 __wsum sum)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
66 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
67}
68
69/*
70 * this routine is used for miscellaneous IP-like checksums, mainly
71 * in icmp.c
72 */
Al Viroc459dd92006-11-14 21:19:01 -080073static inline __sum16 ip_compute_csum(const void *buff, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 return csum_fold(csum_partial(buff, len, 0));
76}
77
Paul Mundta23ba432007-11-28 20:19:38 +090078#endif /* __ASM_SH_CHECKSUM_64_H */