old_checksum.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* $Id: old_checksum.c,v 1.3 2003/10/27 08:04:32 starvik Exp $
  2. *
  3. * INET An implementation of the TCP/IP protocol suite for the LINUX
  4. * operating system. INET is implemented using the BSD Socket
  5. * interface as the means of communication with the user level.
  6. *
  7. * IP/TCP/UDP checksumming routines
  8. *
  9. * Authors: Jorge Cwik, <jorge@laser.satlink.net>
  10. * Arnt Gulbrandsen, <agulbra@nvg.unit.no>
  11. * Tom May, <ftom@netcom.com>
  12. * Lots of code moved from tcp.c and ip.c; see those files
  13. * for more names.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. */
  20. #include <net/checksum.h>
  21. #include <net/module.h>
  22. #undef PROFILE_CHECKSUM
  23. #ifdef PROFILE_CHECKSUM
  24. /* these are just for profiling the checksum code with an oscillioscope.. uh */
  25. #if 0
  26. #define BITOFF *((unsigned char *)0xb0000030) = 0xff
  27. #define BITON *((unsigned char *)0xb0000030) = 0x0
  28. #endif
  29. #include <asm/io.h>
  30. #define CBITON LED_ACTIVE_SET(1)
  31. #define CBITOFF LED_ACTIVE_SET(0)
  32. #define BITOFF
  33. #define BITON
  34. #else
  35. #define BITOFF
  36. #define BITON
  37. #define CBITOFF
  38. #define CBITON
  39. #endif
  40. /*
  41. * computes a partial checksum, e.g. for TCP/UDP fragments
  42. */
  43. #include <asm/delay.h>
  44. unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
  45. {
  46. /*
  47. * Experiments with ethernet and slip connections show that buff
  48. * is aligned on either a 2-byte or 4-byte boundary.
  49. */
  50. const unsigned char *endMarker = buff + len;
  51. const unsigned char *marker = endMarker - (len % 16);
  52. #if 0
  53. if((int)buff & 0x3)
  54. printk("unaligned buff %p\n", buff);
  55. __delay(900); /* extra delay of 90 us to test performance hit */
  56. #endif
  57. BITON;
  58. while (buff < marker) {
  59. sum += *((unsigned short *)buff)++;
  60. sum += *((unsigned short *)buff)++;
  61. sum += *((unsigned short *)buff)++;
  62. sum += *((unsigned short *)buff)++;
  63. sum += *((unsigned short *)buff)++;
  64. sum += *((unsigned short *)buff)++;
  65. sum += *((unsigned short *)buff)++;
  66. sum += *((unsigned short *)buff)++;
  67. }
  68. marker = endMarker - (len % 2);
  69. while(buff < marker) {
  70. sum += *((unsigned short *)buff)++;
  71. }
  72. if(endMarker - buff > 0) {
  73. sum += *buff; /* add extra byte seperately */
  74. }
  75. BITOFF;
  76. return(sum);
  77. }
  78. EXPORT_SYMBOL(csum_partial);