checksum.h 825 B

1234567891011121314151617181920212223242526272829
  1. #ifndef _ASM_CRIS_ARCH_CHECKSUM_H
  2. #define _ASM_CRIS_ARCH_CHECKSUM_H
  3. /*
  4. * Check values used in TCP/UDP headers.
  5. *
  6. * The gain of doing this in assembler instead of C, is that C doesn't
  7. * generate carry-additions for the 32-bit components of the
  8. * checksum. Which means it would be necessary to split all those into
  9. * 16-bit components and then add.
  10. */
  11. static inline unsigned int
  12. csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr,
  13. unsigned short len, unsigned short proto, unsigned int sum)
  14. {
  15. int res;
  16. __asm__ __volatile__ ("add.d %2, %0\n\t"
  17. "addc %3, %0\n\t"
  18. "addc %4, %0\n\t"
  19. "addc 0, %0\n\t"
  20. : "=r" (res)
  21. : "0" (sum), "r" (daddr), "r" (saddr), \
  22. "r" ((ntohs(len) << 16) + (proto << 8)));
  23. return res;
  24. }
  25. #endif /* _ASM_CRIS_ARCH_CHECKSUM_H */