checksum.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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(__be32 saddr, __be32 daddr,
  37. __u32 len, __u8 proto,
  38. __wsum sum)
  39. {
  40. __wsum tmp = (__wsum)((len + proto) << 8);
  41. asm(
  42. " add %1,%0 \n"
  43. " addc %2,%0 \n"
  44. " addc %3,%0 \n"
  45. " addc 0,%0 \n"
  46. : "=r" (sum)
  47. : "r" (daddr), "r"(saddr), "r"(tmp), "0"(sum)
  48. : "cc"
  49. );
  50. return sum;
  51. }
  52. /*
  53. * computes the checksum of the TCP/UDP pseudo-header
  54. * returns a 16-bit checksum, already complemented
  55. */
  56. static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
  57. __u32 len, __u8 proto,
  58. __wsum sum)
  59. {
  60. return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
  61. }
  62. #undef _HAVE_ARCH_IPV6_CSUM
  63. /*
  64. * Copy and checksum to user
  65. */
  66. #define HAVE_CSUM_COPY_USER
  67. extern __wsum csum_and_copy_to_user(const void *src, void *dst, int len,
  68. __wsum sum, int *err_ptr);
  69. #endif /* _ASM_CHECKSUM_H */