checksum_64.h 2.1 KB

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