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
  5. 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 #if 1
 112 static inline unsigned short
 113 ip_compute_csum(unsigned char * buff, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 114 {
 115         unsigned int sum;
 116         unsigned int scratch;
 117 
 118         __asm__("movel %0,%1\n\t"
 119                 "swap  %1\n\t"
 120                 "addw  %1,%0\n\t"
 121                 "clrw  %1\n\t"
 122                 "addxw %1,%0\n\t"
 123                 : "=d" (sum), "=d" (scratch)
 124                 : "0" (csum_partial(buff, len, 0)));
 125         return ~sum;
 126 }
 127 #else
 128 static inline unsigned short
 129 ip_compute_csum(unsigned char * buff, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 130 {
 131         unsigned long sum = 0;
 132 
 133   /* Do the first multiple of 4 bytes and convert to 16 bits. */
 134   if (len > 3)
 135     {
 136       int dummy;
 137       __asm__ ("subql #1,%2\n\t"
 138                "1:\t"
 139                "movel %1@+,%/d0\n\t"
 140                "addxl %/d0,%0\n\t"
 141                "dbra %2,1b\n\t"
 142                "movel %0,%/d0\n\t"
 143                "swap %/d0\n\t"
 144                "addxw %/d0,%0\n\t"
 145                "clrw %/d0\n\t"
 146                "addxw %/d0,%0"
 147                : "=d" (sum), "=a" (buff), "=d" (dummy)
 148                : "0" (sum), "1" (buff), "2" (len >> 2)
 149                : "d0");
 150     }
 151   if (len & 2)
 152     {
 153       __asm__ ("addw %1@+,%0\n\t"
 154                "addxw %2,%0"
 155                : "=d" (sum), "=a" (buff)
 156                : "d" (0), "0" (sum), "1" (buff));
 157     }
 158   if (len & 1)
 159     {
 160       __asm__ ("movew %1@,%/d0\n\t"
 161                "clrb %/d0\n\t"
 162                "addw %/d0,%0\n\t"
 163                "clrw %/d0\n\t"
 164                "addxw %/d0,%0"
 165                : "=d" (sum)
 166                : "a" (buff), "0" (sum)
 167                : "d0");
 168     }
 169 
 170         sum =~sum;
 171         return(sum & 0xffff);
 172 }
 173 #endif
 174 
 175 #endif /* _M68K_CHECKSUM_H */

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