root/include/asm-m68k/checksum.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. ip_fast_csum
  2. csum_tcpudp_magic
  3. csum_fold
  4. ip_compute_csum

   1 #ifndef _M68K_CHECKSUM_H
   2 #define _M68K_CHECKSUM_H
   3 
   4 /*
   5  * computes the checksum of a memory block at buff, length len,
   6  * and adds in "sum" (32-bit)
   7  *
   8  * returns a 32-bit number suitable for feeding into itself
   9  * or csum_tcpudp_magic
  10  *
  11  * this function must be called with even lengths, except
  12  * for the last fragment, which may be odd
  13  *
  14  * it's best to have buff aligned on a 32-bit boundary
  15  */
  16 unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum);
  17 
  18 /*
  19  * the same as csum_partial_copy, but copies from src while it
  20  * checksums
  21  *
  22  * here even more important to align src and dst on a 32-bit (or even
  23  * better 64-bit) boundary
  24  */
  25 
  26 unsigned int csum_partial_copy(const char *src, char *dst, int len, int sum);
  27 
  28 
  29 /*
  30  * the same as csum_partial_copy, but copies from user space.
  31  *
  32  * here even more important to align src and dst on a 32-bit (or even
  33  * better 64-bit) boundary
  34  */
  35 
  36 unsigned int csum_partial_copy_fromuser(const char *src, char *dst, int len, int sum);
  37 
  38 
  39 /*
  40  *      This is a version of ip_compute_csum() optimized for IP headers,
  41  *      which always checksum on 4 octet boundaries.
  42  *
  43  */
  44 static inline unsigned short
  45 ip_fast_csum(unsigned char *iph, unsigned int ihl)
     /* [previous][next][first][last][top][bottom][index][help] */
  46 {
  47         unsigned int sum = 0;
  48 
  49         __asm__ ("subqw #1,%2\n"
  50                  "1:\t"
  51                  "movel %1@+,%/d0\n\t"
  52                  "addxl %/d0,%0\n\t"
  53                  "dbra  %2,1b\n\t"
  54                  "movel %0,%/d0\n\t"
  55                  "swap  %/d0\n\t"
  56                  "addxw %/d0,%0\n\t"
  57                  "clrw  %/d0\n\t"
  58                  "addxw %/d0,%0\n\t"
  59                  : "=d" (sum), "=a" (iph), "=d" (ihl)
  60                  : "0" (sum), "1" (iph), "2" (ihl)
  61                  : "d0");
  62         return ~sum;
  63 }
  64 
  65 
  66 
  67 /*
  68  * computes the checksum of the TCP/UDP pseudo-header
  69  * returns a 16-bit checksum, already complemented
  70  */
  71 
  72 static inline unsigned short int
  73 csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len,
     /* [previous][next][first][last][top][bottom][index][help] */
  74                   unsigned short proto, unsigned int sum)
  75 {
  76         __asm__ ("addl  %1,%0\n\t"
  77                  "addxl %4,%0\n\t"
  78                  "addxl %5,%0\n\t"
  79                  "movl  %0,%1\n\t"
  80                  "swap  %1\n\t"
  81                  "addxw %1,%0\n\t"
  82                  "clrw  %1\n\t"
  83                  "addxw %1,%0\n\t"
  84                  : "=&d" (sum), "=&d" (saddr)
  85                  : "0" (daddr), "1" (saddr), "d" (len + proto),
  86                    "d"(sum));
  87         return ~sum;
  88 }
  89 
  90 /*
  91  *      Fold a partial checksum without adding pseudo headers
  92  */
  93 
  94 static inline unsigned int csum_fold(unsigned int sum)
     /* [previous][next][first][last][top][bottom][index][help] */
  95 {
  96         unsigned int tmp = sum;
  97         __asm__("swap %1\n\t"
  98                 "addw %1, %0\n\t"
  99                 "clrw %1\n\t"
 100                 "addxw %1, %0"
 101                 : "=&d" (sum), "=&d" (tmp)
 102                 : "0" (sum), "1" (sum));
 103         return ~sum;
 104 }
 105 
 106 /*
 107  * this routine is used for miscellaneous IP-like checksums, mainly
 108  * in icmp.c
 109  */
 110 
 111 static inline unsigned short
 112 ip_compute_csum(unsigned char * buff, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 113 {
 114         unsigned int sum;
 115         unsigned int scratch;
 116 
 117         __asm__("movel %0,%1\n\t"
 118                 "swap  %1\n\t"
 119                 "addw  %1,%0\n\t"
 120                 "clrw  %1\n\t"
 121                 "addxw %1,%0\n\t"
 122                 : "=d" (sum), "=d" (scratch)
 123                 : "0" (csum_partial(buff, len, 0)));
 124         return ~sum;
 125 }
 126 
 127 #endif /* _M68K_CHECKSUM_H */

/* [previous][next][first][last][top][bottom][index][help] */