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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [include/] [asm-or32/] [checksum.h] - Blame information for rev 1774

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

Line No. Rev Author Line
1 1276 phoenix
/*
2
 * based on ppc, cris
3
 *
4
 *
5
 */
6
 
7
#ifdef __KERNEL__
8
#ifndef _OR32_CHECKSUM_H
9
#define _OR32_CHECKSUM_H
10
 
11
#include <asm/spr_defs.h>
12
 
13
/*
14
 * computes the checksum of a memory block at buff, length len,
15
 * and adds in "sum" (32-bit)
16
 *
17
 * returns a 32-bit number suitable for feeding into itself
18
 * or csum_tcpudp_magic
19
 *
20
 * this function must be called with even lengths, except
21
 * for the last fragment, which may be odd
22
 *
23
 * it's best to have buff aligned on a 32-bit boundary
24
 */
25
extern unsigned int csum_partial(const unsigned char * buff, int len,
26
                                 unsigned int sum);
27
 
28
/*
29
 * Computes the checksum of a memory block at src, length len,
30
 * and adds in "sum" (32-bit), while copying the block to dst.
31
 * If an access exception occurs on src or dst, it stores -EFAULT
32
 * to *src_err or *dst_err respectively (if that pointer is not
33
 * NULL), and, for an error on src, zeroes the rest of dst.
34
 *
35
 * Like csum_partial, this must be called with even lengths,
36
 * except for the last fragment.
37
 */
38
unsigned int csum_partial_copy_from_user (const char *src, char *dst,
39
                                          int len, unsigned int sum,
40
                                          int *err_ptr);
41
 
42
unsigned int csum_partial_copy_nocheck(const char *src, char *dst,
43
                                       int len, unsigned int sum);
44
 
45
/*
46
 * Old versions which ignore errors.
47
 */
48
#define csum_partial_copy(src, dst, len, sum)   \
49
        csum_partial_copy_nocheck((src), (dst), (len), (sum))
50
 
51
/*
52
 * turns a 32-bit partial checksum (e.g. from csum_partial) into a
53
 * 1's complement 16-bit checksum.
54
 */
55
static inline unsigned int csum_fold(unsigned int sum)
56
{
57
        sum = (sum & 0xffff) + (sum >> 16);
58
        sum = (sum & 0xffff) + (sum >> 16);
59
        return ~sum;
60
}
61
 
62
static inline unsigned long csum_tcpudp_nofold(unsigned long saddr,
63
                                               unsigned long daddr,
64
                                               unsigned short len,
65
                                               unsigned short proto,
66
                                               unsigned int sum)
67
{
68
        sum += saddr;
69
        sum += (saddr > sum) ? 1 : 0;
70
 
71
        sum += daddr;
72
        sum += (daddr > sum) ? 1 : 0;
73
 
74
        sum += ((proto<<16)+len);
75
        sum += (((proto<<16)+len) > sum) ? 1 : 0;
76
 
77
        return sum;
78
}
79
 
80
/*
81
 *  This is a version of ip_compute_csum() optimized for IP headers,
82
 *  which always checksum on 4 octet boundaries.
83
 */
84
 
85
static inline unsigned short ip_fast_csum(unsigned char * iph,
86
                                          unsigned int ihl)
87
{
88
        return csum_fold(csum_partial(iph, ihl * 4, 0));
89
}
90
 
91
/*
92
 * computes the checksum of the TCP/UDP pseudo-header
93
 * returns a 16-bit checksum, already complemented
94
 */
95
 
96
static inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
97
                                                   unsigned long daddr,
98
                                                   unsigned short len,
99
                                                   unsigned short proto,
100
                                                   unsigned int sum)
101
{
102
        return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
103
}
104
 
105
/*
106
 * this routine is used for miscellaneous IP-like checksums, mainly
107
 * in icmp.c
108
 */
109
 
110
static inline unsigned short ip_compute_csum(unsigned char * buff, int len)
111
{
112
        return csum_fold (csum_partial(buff, len, 0));
113
}
114
 
115
 
116
#endif /* __KERNEL__ */
117
#endif /* _OR32_CHECKSUM_H */

powered by: WebSVN 2.1.0

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