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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [asm-m68knommu/] [checksum.h] - Blame information for rev 1782

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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