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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [include/] [asm/] [checksum.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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