old_checksum.c 2.1 KB

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