checksum.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef __ASM_SH64_CHECKSUM_H
  2. #define __ASM_SH64_CHECKSUM_H
  3. /*
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * include/asm-sh64/checksum.h
  9. *
  10. * Copyright (C) 2000, 2001 Paolo Alberelli
  11. *
  12. */
  13. #include <asm/registers.h>
  14. /*
  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. */
  26. asmlinkage __wsum csum_partial(const void *buff, int len, __wsum sum);
  27. /*
  28. * Note: when you get a NULL pointer exception here this means someone
  29. * passed in an incorrect kernel address to one of these functions.
  30. *
  31. * If you use these functions directly please don't forget the
  32. * access_ok().
  33. */
  34. __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len,
  35. __wsum sum);
  36. __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
  37. int len, __wsum sum, int *err_ptr);
  38. static inline __sum16 csum_fold(__wsum csum)
  39. {
  40. u32 sum = (__force u32)csum;
  41. sum = (sum & 0xffff) + (sum >> 16);
  42. sum = (sum & 0xffff) + (sum >> 16);
  43. return (__force __sum16)~sum;
  44. }
  45. __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
  46. __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
  47. unsigned short len, unsigned short proto,
  48. __wsum sum);
  49. /*
  50. * computes the checksum of the TCP/UDP pseudo-header
  51. * returns a 16-bit checksum, already complemented
  52. */
  53. static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
  54. unsigned short len,
  55. unsigned short proto,
  56. __wsum sum)
  57. {
  58. return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
  59. }
  60. /*
  61. * this routine is used for miscellaneous IP-like checksums, mainly
  62. * in icmp.c
  63. */
  64. static inline __sum16 ip_compute_csum(const void *buff, int len)
  65. {
  66. return csum_fold(csum_partial(buff, len, 0));
  67. }
  68. #endif /* __ASM_SH64_CHECKSUM_H */