root/arch/mips/lib/checksum.c

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

DEFINITIONS

This source file includes following definitions.
  1. csum_partial
  2. csum_partial_copy

   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  *              MIPS specific IP/TCP/UDP checksumming routines
   7  *
   8  * Authors:     Ralf Baechle, <ralf@waldorf-gmbh.de>
   9  *              Lots of code moved from tcp.c and ip.c; see those files
  10  *              for more names.
  11  *
  12  *              This program is free software; you can redistribute it and/or
  13  *              modify it under the terms of the GNU General Public License
  14  *              as published by the Free Software Foundation; either version
  15  *              2 of the License, or (at your option) any later version.
  16  */
  17 #include <net/checksum.h>
  18 #include <asm/string.h>
  19 
  20 /*
  21  * computes a partial checksum, e.g. for TCP/UDP fragments
  22  */
  23 
  24 unsigned int csum_partial(const unsigned char *buff, int len, unsigned int sum)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 {
  26         unsigned long   scratch1;
  27         unsigned long   scratch2;
  28 
  29         /*
  30          * The GCC generated code for handling carry bits makes
  31          * it strongly desireable to do this in assembler!
  32          */
  33     __asm__("
  34         .set    noreorder
  35         .set    noat
  36         andi    $1,%5,2         # Check alignment
  37         beqz    $1,2f           # Branch if ok
  38         subu    $1,%4,2         # delay slot, Alignment uses up two bytes
  39         bgez    $1,1f           # Jump if we had at least two bytes
  40         move    %4,$1           # delay slot
  41         j       4f
  42         addiu   %4,2            # delay slot; len was < 2.  Deal with it
  43 
  44 1:      lw      %2,(%5)
  45         addiu   %4,2
  46         addu    %0,%2
  47         sltu    $1,%0,%2
  48         addu    %0,$1
  49 
  50 2:      move    %1,%4
  51         srl     %1,%1,5
  52         beqz    %1,2f
  53         sll     %1,%1,5         # delay slot
  54 
  55         addu    %1,%5
  56 1:      lw      %2,0(%5)
  57         addu    %5,32
  58         addu    %0,%2
  59         sltu    $1,%0,%2
  60 
  61         lw      %2,-28(%5)
  62         addu    %0,$1
  63         addu    %0,%2
  64         sltu    $1,%0,%2
  65 
  66         lw      %2,-24(%5)
  67         addu    %0,$1
  68         addu    %0,%2
  69         sltu    $1,%0,%2
  70 
  71         lw      %2,-20(%5)
  72         addu    %0,$1
  73         addu    %0,%2
  74         sltu    $1,%0,%2
  75 
  76         lw      %2,-16(%5)
  77         addu    %0,$1
  78         addu    %0,%2
  79         sltu    $1,%0,%2
  80 
  81         lw      %2,-12(%5)
  82         addu    %0,$1
  83         addu    %0,%2
  84         sltu    $1,%0,%2
  85 
  86         lw      %2,-8(%5)
  87         addu    %0,$1
  88         addu    %0,%2
  89         sltu    $1,%0,%2
  90 
  91         lw      %2,-4(%5)
  92         addu    %0,$1
  93         addu    %0,%2
  94         sltu    $1,%0,%2
  95 
  96         bne     %5,%1,1b
  97         addu    %0,$1           # delay slot
  98 
  99 2:      andi    %1,%4,0x1c
 100         srl     %1,%1,2
 101         beqz    %1,4f
 102         addu    %1,%5           # delay slot
 103 3:      lw      %2,0(%5)
 104         addu    %5,4
 105         addu    %0,%2
 106         sltu    $1,%0,%2
 107         bne     %5,%1,3b
 108         addu    %0,$1           # delay slot
 109 
 110 4:      andi    $1,%3,2
 111         beqz    $1,5f
 112         move    %2,$0           # delay slot
 113         lhu     %2,(%5)
 114         addiu   %5,2
 115 
 116 5:      andi    $1,%3,1
 117         beqz    $1,6f
 118         sll     %1,16           # delay slot
 119         lbu     %1,(%5)
 120         nop                     # NOP ALERT (spit, gasp)
 121 6:      or      %2,%1
 122         addu    %0,%2
 123         sltu    $1,%0,%2
 124         addu    %0,$1
 125 7:      .set    at
 126         .set    reorder"
 127         : "=r"(sum), "=r" (scratch1), "=r" (scratch2)
 128         : "0"(sum), "r"(len), "r"(buff)
 129         : "$1");
 130 
 131         return sum;
 132 }
 133 
 134 /*
 135  * copy from fs while checksumming, otherwise like csum_partial
 136  */
 137 unsigned int csum_partial_copy(const char *src, char *dst, 
     /* [previous][next][first][last][top][bottom][index][help] */
 138                                   int len, int sum)
 139 {
 140         /*
 141          * It's 2:30 am and I don't feel like doing it real ...
 142          * This is lots slower than the real thing (tm)
 143          */
 144         sum = csum_partial(src, len, sum);
 145         memcpy(dst, src, len);
 146 
 147         return sum;
 148 }

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