checksum.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* MN10300 Optimised checksumming code
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #ifndef _ASM_CHECKSUM_H
  12. #define _ASM_CHECKSUM_H
  13. extern __wsum csum_partial(const void *buff, int len, __wsum sum);
  14. extern __wsum csum_partial_copy_nocheck(const void *src, void *dst,
  15. int len, __wsum sum);
  16. extern __wsum csum_partial_copy_from_user(const void *src, void *dst,
  17. int len, __wsum sum,
  18. int *err_ptr);
  19. extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
  20. extern __wsum csum_partial(const void *buff, int len, __wsum sum);
  21. extern __sum16 ip_compute_csum(const void *buff, int len);
  22. #define csum_partial_copy_fromuser csum_partial_copy
  23. extern __wsum csum_partial_copy(const void *src, void *dst, int len,
  24. __wsum sum);
  25. static inline __sum16 csum_fold(__wsum sum)
  26. {
  27. asm(
  28. " add %1,%0 \n"
  29. " addc 0xffff,%0 \n"
  30. : "=r" (sum)
  31. : "r" (sum << 16), "0" (sum & 0xffff0000)
  32. : "cc"
  33. );
  34. return (~sum) >> 16;
  35. }
  36. static inline __wsum csum_tcpudp_nofold(unsigned long saddr,
  37. unsigned long daddr,
  38. unsigned short len,
  39. unsigned short proto,
  40. __wsum sum)
  41. {
  42. __wsum tmp;
  43. tmp = (__wsum) ntohs(len) << 16;
  44. tmp += (__wsum) proto << 8;
  45. asm(
  46. " add %1,%0 \n"
  47. " addc %2,%0 \n"
  48. " addc %3,%0 \n"
  49. " addc 0,%0 \n"
  50. : "=r" (sum)
  51. : "r" (daddr), "r"(saddr), "r"(tmp), "0"(sum)
  52. : "cc"
  53. );
  54. return sum;
  55. }
  56. /*
  57. * computes the checksum of the TCP/UDP pseudo-header
  58. * returns a 16-bit checksum, already complemented
  59. */
  60. static inline __sum16 csum_tcpudp_magic(unsigned long saddr,
  61. unsigned long daddr,
  62. unsigned short len,
  63. unsigned short proto,
  64. __wsum sum)
  65. {
  66. return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
  67. }
  68. #undef _HAVE_ARCH_IPV6_CSUM
  69. /*
  70. * Copy and checksum to user
  71. */
  72. #define HAVE_CSUM_COPY_USER
  73. extern __wsum csum_and_copy_to_user(const void *src, void *dst, int len,
  74. __wsum sum, int *err_ptr);
  75. #endif /* _ASM_CHECKSUM_H */