checksum.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * include/asm-v850/checksum.h -- Checksum ops
  3. *
  4. * Copyright (C) 2001,2005 NEC Corporation
  5. * Copyright (C) 2001,2005 Miles Bader <miles@gnu.org>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General
  8. * Public License. See the file COPYING in the main directory of this
  9. * archive for more details.
  10. *
  11. * Written by Miles Bader <miles@gnu.org>
  12. */
  13. #ifndef __V850_CHECKSUM_H__
  14. #define __V850_CHECKSUM_H__
  15. /*
  16. * computes the checksum of a memory block at buff, length len,
  17. * and adds in "sum" (32-bit)
  18. *
  19. * returns a 32-bit number suitable for feeding into itself
  20. * or csum_tcpudp_magic
  21. *
  22. * this function must be called with even lengths, except
  23. * for the last fragment, which may be odd
  24. *
  25. * it's best to have buff aligned on a 32-bit boundary
  26. */
  27. extern __wsum csum_partial(const void *buff, int len, __wsum sum);
  28. /*
  29. * the same as csum_partial, but copies from src while it
  30. * checksums
  31. *
  32. * here even more important to align src and dst on a 32-bit (or even
  33. * better 64-bit) boundary
  34. */
  35. extern __wsum csum_partial_copy_nocheck(const void *src,
  36. void *dst, int len, __wsum sum);
  37. /*
  38. * the same as csum_partial_copy, but copies from user space.
  39. *
  40. * here even more important to align src and dst on a 32-bit (or even
  41. * better 64-bit) boundary
  42. */
  43. extern __wsum csum_partial_copy_from_user (const void *src,
  44. void *dst,
  45. int len, __wsum sum,
  46. int *csum_err);
  47. __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
  48. /*
  49. * Fold a partial checksum
  50. */
  51. static inline __sum16 csum_fold (__wsum sum)
  52. {
  53. unsigned int result;
  54. /*
  55. %0 %1
  56. hsw %1, %0 H L L H
  57. add %1, %0 H L H+L+C H+L
  58. */
  59. asm ("hsw %1, %0; add %1, %0" : "=&r" (result) : "r" (sum));
  60. return (__force __sum16)(~result >> 16);
  61. }
  62. /*
  63. * computes the checksum of the TCP/UDP pseudo-header
  64. * returns a 16-bit checksum, already complemented
  65. */
  66. static inline __wsum
  67. csum_tcpudp_nofold (__be32 saddr, __be32 daddr,
  68. unsigned short len,
  69. unsigned short proto, __wsum sum)
  70. {
  71. int __carry;
  72. __asm__ ("add %2, %0;"
  73. "setf c, %1;"
  74. "add %1, %0;"
  75. "add %3, %0;"
  76. "setf c, %1;"
  77. "add %1, %0;"
  78. "add %4, %0;"
  79. "setf c, %1;"
  80. "add %1, %0"
  81. : "=&r" (sum), "=&r" (__carry)
  82. : "r" (daddr), "r" (saddr),
  83. "r" ((len + proto) << 8),
  84. "0" (sum));
  85. return sum;
  86. }
  87. static inline __sum16
  88. csum_tcpudp_magic (__be32 saddr, __be32 daddr,
  89. unsigned short len,
  90. unsigned short proto, __wsum sum)
  91. {
  92. return csum_fold (csum_tcpudp_nofold (saddr, daddr, len, proto, sum));
  93. }
  94. /*
  95. * this routine is used for miscellaneous IP-like checksums, mainly
  96. * in icmp.c
  97. */
  98. extern __sum16 ip_compute_csum(const void *buff, int len);
  99. #endif /* __V850_CHECKSUM_H__ */