checksum.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 unsigned int csum_partial(const unsigned char *buff, int len,
  27. unsigned int sum);
  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
  33. * access_ok().
  34. */
  35. unsigned int csum_partial_copy_nocheck(const char *src, char *dst, int len,
  36. unsigned int sum);
  37. unsigned int csum_partial_copy_from_user(const char *src, char *dst,
  38. int len, int sum, int *err_ptr);
  39. /*
  40. * These are the old (and unsafe) way of doing checksums, a warning message will be
  41. * printed if they are used and an exeption occurs.
  42. *
  43. * these functions should go away after some time.
  44. */
  45. #define csum_partial_copy_fromuser csum_partial_copy
  46. unsigned int csum_partial_copy(const char *src, char *dst, int len,
  47. unsigned int sum);
  48. static inline unsigned short csum_fold(unsigned int sum)
  49. {
  50. sum = (sum & 0xffff) + (sum >> 16);
  51. sum = (sum & 0xffff) + (sum >> 16);
  52. return ~(sum);
  53. }
  54. unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl);
  55. unsigned long csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr,
  56. unsigned short len, unsigned short proto,
  57. unsigned int sum);
  58. /*
  59. * computes the checksum of the TCP/UDP pseudo-header
  60. * returns a 16-bit checksum, already complemented
  61. */
  62. static inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
  63. unsigned long daddr,
  64. unsigned short len,
  65. unsigned short proto,
  66. unsigned int sum)
  67. {
  68. return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
  69. }
  70. /*
  71. * this routine is used for miscellaneous IP-like checksums, mainly
  72. * in icmp.c
  73. */
  74. static inline unsigned short ip_compute_csum(unsigned char * buff, int len)
  75. {
  76. return csum_fold(csum_partial(buff, len, 0));
  77. }
  78. #endif /* __ASM_SH64_CHECKSUM_H */