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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [asm-i960/] [checksum.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1633 jcastillo
#ifndef _I960_CHECKSUM_H
2
#define _I960_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
unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl);
39
 
40
static inline unsigned short from32to16(unsigned long sum)
41
{
42
        unsigned long tmp;
43
        asm("addo       %2, %3, %0
44
            shro        16, %0, %1
45
            clrbit      16, %0, %0
46
            addo        %0, %1, %0"
47
            : "=&r" (sum), "=r"(tmp)
48
            : "r"(sum & 0xffff), "r"(sum >> 16), "0"(sum));
49
        return sum;
50
}
51
/*
52
 *      Fold a partial checksum
53
 */
54
 
55
static inline unsigned int csum_fold(unsigned int sum)
56
{
57
#if 1
58
        return ~from32to16(sum);
59
#else
60
        sum = (sum & 0xffff) + (sum >> 16);     /* add top and bottom */
61
        sum = (sum & 0xffff) + (sum >> 16);     /* add carries from previous */
62
        return ~sum;
63
#endif
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
73
csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len,
74
                  unsigned short proto, unsigned int sum)
75
{
76
#if 0
77
        register unsigned long lenproto = ((ntohs(len)<<16) + proto * 256);
78
        sum += saddr;
79
        sum += daddr + (saddr > sum);
80
        sum += lenproto + (daddr > sum);
81
        sum += (lenproto > sum);
82
#else
83
        asm("cmpo       1, 0
84
            addc        %1, %2, %0
85
            addc        %1, %3, %0
86
            addc        %1, %4, %0
87
            addc        0, %1, %0"
88
            : "=&r"(sum)
89
            : "0"(sum), "r"(saddr), "r"(daddr),
90
            "r"((ntohs(len)<<16) + proto * 256));
91
#endif
92
 
93
        return csum_fold(sum);
94
}
95
 
96
 
97
/*
98
 * this routine is used for miscellaneous IP-like checksums, mainly
99
 * in icmp.c
100
 */
101
 
102
extern unsigned short
103
ip_compute_csum(const unsigned char * buff, int len);
104
 
105
#endif /* _I960_CHECKSUM_H */

powered by: WebSVN 2.1.0

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