Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * include/asm-v850/checksum.h -- Checksum ops |
| 3 | * |
Miles Bader | 623cdf4 | 2005-07-11 18:24:50 +0900 | [diff] [blame] | 4 | * Copyright (C) 2001,2005 NEC Corporation |
| 5 | * Copyright (C) 2001,2005 Miles Bader <miles@gnu.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * This file is subject to the terms and conditions of the GNU General |
| 8 | * Public License. See the file COPYING in the main directory of this |
| 9 | * archive for more details. |
| 10 | * |
| 11 | * Written by Miles Bader <miles@gnu.org> |
| 12 | */ |
| 13 | |
| 14 | #ifndef __V850_CHECKSUM_H__ |
| 15 | #define __V850_CHECKSUM_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 | 9d3d419 | 2006-11-14 21:19:44 -0800 | [diff] [blame] | 29 | extern __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 | * the same as csum_partial, but copies from src while it |
| 33 | * checksums |
| 34 | * |
| 35 | * here even more important to align src and dst on a 32-bit (or even |
| 36 | * better 64-bit) boundary |
| 37 | */ |
Al Viro | 9d3d419 | 2006-11-14 21:19:44 -0800 | [diff] [blame] | 38 | extern __wsum csum_partial_copy_nocheck(const void *src, |
| 39 | void *dst, int len, __wsum sum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | |
| 42 | /* |
| 43 | * the same as csum_partial_copy, but copies from user space. |
| 44 | * |
| 45 | * here even more important to align src and dst on a 32-bit (or even |
| 46 | * better 64-bit) boundary |
| 47 | */ |
Al Viro | 9d3d419 | 2006-11-14 21:19:44 -0800 | [diff] [blame] | 48 | extern __wsum csum_partial_copy_from_user (const void *src, |
| 49 | void *dst, |
| 50 | int len, __wsum sum, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | int *csum_err); |
| 52 | |
Al Viro | 9d3d419 | 2006-11-14 21:19:44 -0800 | [diff] [blame] | 53 | __sum16 ip_fast_csum(const void *iph, unsigned int ihl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Fold a partial checksum |
| 57 | */ |
Al Viro | 9d3d419 | 2006-11-14 21:19:44 -0800 | [diff] [blame] | 58 | static inline __sum16 csum_fold (__wsum sum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
| 60 | unsigned int result; |
| 61 | /* |
| 62 | %0 %1 |
| 63 | hsw %1, %0 H L L H |
| 64 | add %1, %0 H L H+L+C H+L |
| 65 | */ |
| 66 | asm ("hsw %1, %0; add %1, %0" : "=&r" (result) : "r" (sum)); |
Al Viro | 9d3d419 | 2006-11-14 21:19:44 -0800 | [diff] [blame] | 67 | return (__force __sum16)(~result >> 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | |
| 71 | /* |
| 72 | * computes the checksum of the TCP/UDP pseudo-header |
| 73 | * returns a 16-bit checksum, already complemented |
| 74 | */ |
Al Viro | 9d3d419 | 2006-11-14 21:19:44 -0800 | [diff] [blame] | 75 | static inline __wsum |
| 76 | csum_tcpudp_nofold (__be32 saddr, __be32 daddr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | unsigned short len, |
Al Viro | 9d3d419 | 2006-11-14 21:19:44 -0800 | [diff] [blame] | 78 | unsigned short proto, __wsum sum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
| 80 | int __carry; |
| 81 | __asm__ ("add %2, %0;" |
| 82 | "setf c, %1;" |
| 83 | "add %1, %0;" |
| 84 | "add %3, %0;" |
| 85 | "setf c, %1;" |
| 86 | "add %1, %0;" |
| 87 | "add %4, %0;" |
| 88 | "setf c, %1;" |
| 89 | "add %1, %0" |
| 90 | : "=&r" (sum), "=&r" (__carry) |
| 91 | : "r" (daddr), "r" (saddr), |
Al Viro | 9d3d419 | 2006-11-14 21:19:44 -0800 | [diff] [blame] | 92 | "r" ((len + proto) << 8), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | "0" (sum)); |
| 94 | return sum; |
| 95 | } |
| 96 | |
Al Viro | 9d3d419 | 2006-11-14 21:19:44 -0800 | [diff] [blame] | 97 | static inline __sum16 |
| 98 | csum_tcpudp_magic (__be32 saddr, __be32 daddr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | unsigned short len, |
Al Viro | 9d3d419 | 2006-11-14 21:19:44 -0800 | [diff] [blame] | 100 | unsigned short proto, __wsum sum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
| 102 | return csum_fold (csum_tcpudp_nofold (saddr, daddr, len, proto, sum)); |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * this routine is used for miscellaneous IP-like checksums, mainly |
| 107 | * in icmp.c |
| 108 | */ |
Al Viro | 9d3d419 | 2006-11-14 21:19:44 -0800 | [diff] [blame] | 109 | extern __sum16 ip_compute_csum(const void *buff, int len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | |
| 112 | #endif /* __V850_CHECKSUM_H__ */ |