2 * Licensed under the GPL
5 #ifndef __UM_SYSDEP_CHECKSUM_H
6 #define __UM_SYSDEP_CHECKSUM_H
8 #include "linux/string.h"
10 #include "asm/uaccess.h"
12 extern __wsum
csum_partial(const void *buff
, int len
, __wsum sum
);
15 * Note: when you get a NULL pointer exception here this means someone
16 * passed in an incorrect kernel address to one of these functions.
18 * If you use these functions directly please don't forget the
23 __wsum
csum_partial_copy_nocheck(const void *src
, void *dst
,
26 memcpy(dst
, src
, len
);
27 return(csum_partial(dst
, len
, sum
));
31 __wsum
csum_partial_copy_from_user(const void __user
*src
,
32 void *dst
, int len
, __wsum sum
,
35 if (copy_from_user(dst
, src
, len
)) {
37 return (__force __wsum
)-1;
39 return csum_partial(dst
, len
, sum
);
43 * csum_fold - Fold and invert a 32bit checksum.
44 * sum: 32bit unfolded sum
46 * Fold a 32bit running checksum to 16bit and invert it. This is usually
47 * the last step before putting a checksum into a packet.
48 * Make sure not to mix with 64bit checksums.
50 static inline __sum16
csum_fold(__wsum sum
)
56 : "r" ((__force u32
)sum
<< 16),
57 "0" ((__force u32
)sum
& 0xffff0000)
59 return (__force __sum16
)(~(__force u32
)sum
>> 16);
63 * csum_tcpup_nofold - Compute an IPv4 pseudo header checksum.
64 * @saddr: source address
65 * @daddr: destination address
66 * @len: length of packet
67 * @proto: ip protocol of packet
68 * @sum: initial sum to be added in (32bit unfolded)
70 * Returns the pseudo header checksum the input data. Result is
74 csum_tcpudp_nofold(__be32 saddr
, __be32 daddr
, unsigned short len
,
75 unsigned short proto
, __wsum sum
)
82 : "g" (daddr
), "g" (saddr
), "g" ((len
+ proto
) << 8), "0" (sum
));
87 * computes the checksum of the TCP/UDP pseudo-header
88 * returns a 16-bit checksum, already complemented
90 static inline __sum16
csum_tcpudp_magic(__be32 saddr
, __be32 daddr
,
95 return csum_fold(csum_tcpudp_nofold(saddr
,daddr
,len
,proto
,sum
));
99 * ip_fast_csum - Compute the IPv4 header checksum efficiently.
101 * ihl: length of header / 4
103 static inline __sum16
ip_fast_csum(const void *iph
, unsigned int ihl
)
107 asm( " movl (%1), %0\n"
113 "1: adcl 16(%1), %0\n"
124 /* Since the input registers which are loaded with iph and ipl
125 are modified, we must also specify them as outputs, or gcc
126 will assume they contain their original values. */
127 : "=r" (sum
), "=r" (iph
), "=r" (ihl
)
128 : "1" (iph
), "2" (ihl
)
130 return (__force __sum16
)sum
;
133 static inline unsigned add32_with_carry(unsigned a
, unsigned b
)
142 extern __sum16
ip_compute_csum(const void *buff
, int len
);