checksum.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2008 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2006 Atmark Techno, Inc.
  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. #ifndef _ASM_MICROBLAZE_CHECKSUM_H
  10. #define _ASM_MICROBLAZE_CHECKSUM_H
  11. #include <linux/in6.h>
  12. /*
  13. * computes the checksum of the TCP/UDP pseudo-header
  14. * returns a 16-bit checksum, already complemented
  15. */
  16. static inline __wsum
  17. csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,
  18. unsigned short proto, __wsum sum)
  19. {
  20. __asm__("add %0, %0, %1\n\t"
  21. "addc %0, %0, %2\n\t"
  22. "addc %0, %0, %3\n\t"
  23. "addc %0, %0, r0\n\t"
  24. : "+&d" (sum)
  25. : "d" (saddr), "d" (daddr), "d" (len + proto));
  26. return sum;
  27. }
  28. /*
  29. * computes the checksum of a memory block at buff, length len,
  30. * and adds in "sum" (32-bit)
  31. *
  32. * returns a 32-bit number suitable for feeding into itself
  33. * or csum_tcpudp_magic
  34. *
  35. * this function must be called with even lengths, except
  36. * for the last fragment, which may be odd
  37. *
  38. * it's best to have buff aligned on a 32-bit boundary
  39. */
  40. extern __wsum csum_partial(const void *buff, int len, __wsum sum);
  41. /*
  42. * the same as csum_partial, but copies from src while it
  43. * checksums
  44. *
  45. * here even more important to align src and dst on a 32-bit (or even
  46. * better 64-bit) boundary
  47. */
  48. extern __wsum csum_partial_copy(const char *src, char *dst, int len, int sum);
  49. /*
  50. * the same as csum_partial_copy, but copies from user space.
  51. *
  52. * here even more important to align src and dst on a 32-bit (or even
  53. * better 64-bit) boundary
  54. */
  55. extern __wsum csum_partial_copy_from_user(const char *src, char *dst,
  56. int len, int sum, int *csum_err);
  57. #define csum_partial_copy_nocheck(src, dst, len, sum) \
  58. csum_partial_copy((src), (dst), (len), (sum))
  59. /*
  60. * This is a version of ip_compute_csum() optimized for IP headers,
  61. * which always checksum on 4 octet boundaries.
  62. *
  63. */
  64. extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
  65. /*
  66. * Fold a partial checksum
  67. */
  68. static inline __sum16 csum_fold(unsigned int sum)
  69. {
  70. sum = (sum & 0xffff) + (sum >> 16);
  71. sum = (sum & 0xffff) + (sum >> 16);
  72. return ~sum;
  73. }
  74. static inline __sum16
  75. csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,
  76. unsigned short proto, __wsum sum)
  77. {
  78. return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
  79. }
  80. /*
  81. * this routine is used for miscellaneous IP-like checksums, mainly
  82. * in icmp.c
  83. */
  84. extern __sum16 ip_compute_csum(const unsigned char *buff, int len);
  85. #endif /* _ASM_MICROBLAZE_CHECKSUM_H */