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

Subversion Repositories or1k

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

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

Line No. Rev Author Line
1 666 simons
#ifndef _OR32_CHECKSUM_H
2
#define _OR32_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
/*
43 761 simons
 *      Fold a partial checksum without adding pseudo headers
44 666 simons
 */
45
 
46 761 simons
static inline unsigned short
47
csum_fold(unsigned int sum)
48 666 simons
{
49
        sum = (sum & 0xffff) + (sum >> 16);
50
        sum = (sum & 0xffff) + (sum >> 16);
51
        return ~sum;
52
}
53
 
54
/*
55
 * computes the checksum of the TCP/UDP pseudo-header
56
 * returns a 16-bit checksum, already complemented
57
 */
58
 
59
static inline unsigned short int
60
csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len,
61
                  unsigned short proto, unsigned int sum)
62
{
63 761 simons
        unsigned long result = saddr;
64
 
65
        result += daddr;
66
        result += (daddr > result);
67 666 simons
 
68 1313 jurem
        result += len;
69
        result += (len > result);
70 666 simons
 
71 1313 jurem
        result += proto;
72
        result += (proto > result);
73
 
74 761 simons
        result += sum;
75
        result += (sum > result);
76
 
77
        result = (result >> 16) + (result & 0xffff);
78
        result = (result >> 16) + (result & 0xffff);
79
 
80
        return ~result;
81 666 simons
}
82 761 simons
 
83 666 simons
extern unsigned short
84
ip_compute_csum(const unsigned char * buff, int len);
85
 
86
#endif /* _OR32_CHECKSUM_H */

powered by: WebSVN 2.1.0

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