Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_SH64_CHECKSUM_H |
| 2 | #define __ASM_SH64_CHECKSUM_H |
| 3 | |
| 4 | /* |
| 5 | * This file is subject to the terms and conditions of the GNU General Public |
| 6 | * License. See the file "COPYING" in the main directory of this archive |
| 7 | * for more details. |
| 8 | * |
| 9 | * include/asm-sh64/checksum.h |
| 10 | * |
| 11 | * Copyright (C) 2000, 2001 Paolo Alberelli |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #include <asm/registers.h> |
| 16 | |
| 17 | /* |
| 18 | * computes the checksum of a memory block at buff, length len, |
| 19 | * and adds in "sum" (32-bit) |
| 20 | * |
| 21 | * returns a 32-bit number suitable for feeding into itself |
| 22 | * or csum_tcpudp_magic |
| 23 | * |
| 24 | * this function must be called with even lengths, except |
| 25 | * for the last fragment, which may be odd |
| 26 | * |
| 27 | * it's best to have buff aligned on a 32-bit boundary |
| 28 | */ |
Al Viro | c459dd9 | 2006-11-14 21:19:01 -0800 | [diff] [blame] | 29 | asmlinkage __wsum csum_partial(const void *buff, int len, __wsum sum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | * Note: when you get a NULL pointer exception here this means someone |
| 33 | * passed in an incorrect kernel address to one of these functions. |
| 34 | * |
| 35 | * If you use these functions directly please don't forget the |
Jesper Juhl | e49332b | 2005-05-01 08:59:08 -0700 | [diff] [blame] | 36 | * access_ok(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | |
Al Viro | c459dd9 | 2006-11-14 21:19:01 -0800 | [diff] [blame] | 40 | __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len, |
| 41 | __wsum sum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Al Viro | c459dd9 | 2006-11-14 21:19:01 -0800 | [diff] [blame] | 43 | __wsum csum_partial_copy_from_user(const void __user *src, void *dst, |
| 44 | int len, __wsum sum, int *err_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Al Viro | c459dd9 | 2006-11-14 21:19:01 -0800 | [diff] [blame] | 46 | static inline __sum16 csum_fold(__wsum csum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
Al Viro | c459dd9 | 2006-11-14 21:19:01 -0800 | [diff] [blame] | 48 | u32 sum = (__force u32)csum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | sum = (sum & 0xffff) + (sum >> 16); |
| 50 | sum = (sum & 0xffff) + (sum >> 16); |
Al Viro | c459dd9 | 2006-11-14 21:19:01 -0800 | [diff] [blame] | 51 | return (__force __sum16)~sum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Al Viro | c459dd9 | 2006-11-14 21:19:01 -0800 | [diff] [blame] | 54 | __sum16 ip_fast_csum(const void *iph, unsigned int ihl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Al Viro | c459dd9 | 2006-11-14 21:19:01 -0800 | [diff] [blame] | 56 | __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | unsigned short len, unsigned short proto, |
Al Viro | c459dd9 | 2006-11-14 21:19:01 -0800 | [diff] [blame] | 58 | __wsum sum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * computes the checksum of the TCP/UDP pseudo-header |
| 62 | * returns a 16-bit checksum, already complemented |
| 63 | */ |
Al Viro | c459dd9 | 2006-11-14 21:19:01 -0800 | [diff] [blame] | 64 | static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | unsigned short len, |
| 66 | unsigned short proto, |
Al Viro | c459dd9 | 2006-11-14 21:19:01 -0800 | [diff] [blame] | 67 | __wsum sum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
| 69 | return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | * this routine is used for miscellaneous IP-like checksums, mainly |
| 74 | * in icmp.c |
| 75 | */ |
Al Viro | c459dd9 | 2006-11-14 21:19:01 -0800 | [diff] [blame] | 76 | static inline __sum16 ip_compute_csum(const void *buff, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
| 78 | return csum_fold(csum_partial(buff, len, 0)); |
| 79 | } |
| 80 | |
| 81 | #endif /* __ASM_SH64_CHECKSUM_H */ |
| 82 | |