checksum.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _H8300_CHECKSUM_H
  2. #define _H8300_CHECKSUM_H
  3. /*
  4. * computes the checksum of a memory block at buff, length len,
  5. * and adds in "sum" (32-bit)
  6. *
  7. * returns a 32-bit number suitable for feeding into itself
  8. * or csum_tcpudp_magic
  9. *
  10. * this function must be called with even lengths, except
  11. * for the last fragment, which may be odd
  12. *
  13. * it's best to have buff aligned on a 32-bit boundary
  14. */
  15. __wsum csum_partial(const void *buff, int len, __wsum sum);
  16. /*
  17. * the same as csum_partial, but copies from src while it
  18. * checksums
  19. *
  20. * here even more important to align src and dst on a 32-bit (or even
  21. * better 64-bit) boundary
  22. */
  23. __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
  24. /*
  25. * the same as csum_partial_copy, but copies from user space.
  26. *
  27. * here even more important to align src and dst on a 32-bit (or even
  28. * better 64-bit) boundary
  29. */
  30. extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
  31. int len, __wsum sum, int *csum_err);
  32. __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
  33. /*
  34. * Fold a partial checksum
  35. */
  36. static inline __sum16 csum_fold(__wsum sum)
  37. {
  38. __asm__("mov.l %0,er0\n\t"
  39. "add.w e0,r0\n\t"
  40. "xor.w e0,e0\n\t"
  41. "rotxl.w e0\n\t"
  42. "add.w e0,r0\n\t"
  43. "sub.w e0,e0\n\t"
  44. "mov.l er0,%0"
  45. : "=r"(sum)
  46. : "0"(sum)
  47. : "er0");
  48. return (__force __sum16)~sum;
  49. }
  50. /*
  51. * computes the checksum of the TCP/UDP pseudo-header
  52. * returns a 16-bit checksum, already complemented
  53. */
  54. static inline __wsum
  55. csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,
  56. unsigned short proto, __wsum sum)
  57. {
  58. __asm__ ("sub.l er0,er0\n\t"
  59. "add.l %2,%0\n\t"
  60. "addx #0,r0l\n\t"
  61. "add.l %3,%0\n\t"
  62. "addx #0,r0l\n\t"
  63. "add.l %4,%0\n\t"
  64. "addx #0,r0l\n\t"
  65. "add.l er0,%0\n\t"
  66. "bcc 1f\n\t"
  67. "inc.l #1,%0\n"
  68. "1:"
  69. : "=&r" (sum)
  70. : "0" (sum), "r" (daddr), "r" (saddr), "r" (len + proto)
  71. :"er0");
  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 void *buff, int len);
  85. #endif /* _H8300_CHECKSUM_H */