checksum.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 void *src, void *dst, int len,
  49. __wsum sum);
  50. /*
  51. * the same as csum_partial_copy, but copies from user space.
  52. *
  53. * here even more important to align src and dst on a 32-bit (or even
  54. * better 64-bit) boundary
  55. */
  56. extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
  57. int len, __wsum sum, int *csum_err);
  58. #define csum_partial_copy_nocheck(src, dst, len, sum) \
  59. csum_partial_copy((src), (dst), (len), (sum))
  60. /*
  61. * This is a version of ip_compute_csum() optimized for IP headers,
  62. * which always checksum on 4 octet boundaries.
  63. *
  64. */
  65. extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
  66. /*
  67. * Fold a partial checksum
  68. */
  69. static inline __sum16 csum_fold(__wsum csum)
  70. {
  71. u32 sum = (__force u32)csum;
  72. sum = (sum & 0xffff) + (sum >> 16);
  73. sum = (sum & 0xffff) + (sum >> 16);
  74. return (__force __sum16)~sum;
  75. }
  76. static inline __sum16
  77. csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,
  78. unsigned short proto, __wsum sum)
  79. {
  80. return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
  81. }
  82. /*
  83. * this routine is used for miscellaneous IP-like checksums, mainly
  84. * in icmp.c
  85. */
  86. extern __sum16 ip_compute_csum(const void *buff, int len);
  87. #endif /* _ASM_MICROBLAZE_CHECKSUM_H */