OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [include/] [asm-m68k/] [checksum.h] - Blame information for rev 199

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
#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)
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
 *      Fold a partial checksum
67
 */
68
 
69
static inline unsigned int csum_fold(unsigned int sum)
70
{
71
        unsigned int tmp = sum;
72
        __asm__("swap %1\n\t"
73
                "addw %1, %0\n\t"
74
                "clrw %1\n\t"
75
                "addxw %1, %0"
76
                : "=&d" (sum), "=&d" (tmp)
77
                : "0" (sum), "1" (sum));
78
        return ~sum;
79
}
80
 
81
 
82
/*
83
 * computes the checksum of the TCP/UDP pseudo-header
84
 * returns a 16-bit checksum, already complemented
85
 */
86
 
87
static inline unsigned short int
88
csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len,
89
                  unsigned short proto, unsigned int sum)
90
{
91
        __asm__ ("addl  %1,%0\n\t"
92
                 "addxl %4,%0\n\t"
93
                 "addxl %5,%0\n\t"
94
                 "clrl %1\n\t"
95
                 "addxl %1,%0"
96
                 : "=&d" (sum), "=&d" (saddr)
97
                 : "0" (daddr), "1" (saddr), "d" (len + proto),
98
                   "d"(sum));
99
        return csum_fold(sum);
100
}
101
 
102
/*
103
 * this routine is used for miscellaneous IP-like checksums, mainly
104
 * in icmp.c
105
 */
106
 
107
static inline unsigned short
108
ip_compute_csum(unsigned char * buff, int len)
109
{
110
        return csum_fold (csum_partial(buff, len, 0));
111
}
112
 
113
#endif /* _M68K_CHECKSUM_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.