1
2
3
4
5
6
7
8
9
10#ifndef _ASM_NIOS_CHECKSUM_H
11#define _ASM_NIOS_CHECKSUM_H
12
13
14extern __wsum csum_partial(const void *buff, int len, __wsum sum);
15extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
16extern __sum16 ip_compute_csum(const void *buff, int len);
17
18
19
20
21static inline __sum16 csum_fold(__wsum sum)
22{
23 __asm__ __volatile__(
24 "add %0, %1, %0\n"
25 "cmpltu r8, %0, %1\n"
26 "srli %0, %0, 16\n"
27 "add %0, %0, r8\n"
28 "nor %0, %0, %0\n"
29 : "=r" (sum)
30 : "r" (sum << 16), "0" (sum)
31 : "r8");
32 return (__force __sum16) sum;
33}
34
35
36
37
38
39#define csum_tcpudp_nofold csum_tcpudp_nofold
40static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
41 __u32 len, __u8 proto,
42 __wsum sum)
43{
44 __asm__ __volatile__(
45 "add %0, %1, %0\n"
46 "cmpltu r8, %0, %1\n"
47 "add %0, %0, r8\n"
48 "add %0, %2, %0\n"
49 "cmpltu r8, %0, %2\n"
50 "add %0, %0, r8\n"
51 "add %0, %3, %0\n"
52 "cmpltu r8, %0, %3\n"
53 "add %0, %0, r8\n"
54 : "=r" (sum), "=r" (saddr)
55 : "r" (daddr), "r" ((len + proto) << 8),
56 "0" (sum),
57 "1" (saddr)
58 : "r8");
59
60 return sum;
61}
62
63static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
64 __u32 len, __u8 proto,
65 __wsum sum)
66{
67 return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
68}
69
70#endif
71