aed7ad68ca46e9a9a5f80ddef999ec8f003512d0
2 * include/asm-xtensa/checksum.h
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
8 * Copyright (C) 2001 - 2005 Tensilica Inc.
11 #ifndef _XTENSA_CHECKSUM_H
12 #define _XTENSA_CHECKSUM_H
14 #include <linux/in6.h>
15 #include <variant/core.h>
18 * computes the checksum of a memory block at buff, length len,
19 * and adds in "sum" (32-bit)
21 * returns a 32-bit number suitable for feeding into itself
22 * or csum_tcpudp_magic
24 * this function must be called with even lengths, except
25 * for the last fragment, which may be odd
27 * it's best to have buff aligned on a 32-bit boundary
29 asmlinkage __wsum
csum_partial(const void *buff
, int len
, __wsum sum
);
32 * the same as csum_partial, but copies from src while it
33 * checksums, and handles user-space pointer exceptions correctly, when needed.
35 * here even more important to align src and dst on a 32-bit (or even
36 * better 64-bit) boundary
39 asmlinkage __wsum
csum_partial_copy_generic(const void *src
, void *dst
,
41 int *src_err_ptr
, int *dst_err_ptr
);
44 * Note: when you get a NULL pointer exception here this means someone
45 * passed in an incorrect kernel address to one of these functions.
47 * If you use these functions directly please don't forget the access_ok().
50 __wsum
csum_partial_copy_nocheck(const void *src
, void *dst
,
53 return csum_partial_copy_generic(src
, dst
, len
, sum
, NULL
, NULL
);
57 __wsum
csum_partial_copy_from_user(const void __user
*src
, void *dst
,
58 int len
, __wsum sum
, int *err_ptr
)
60 return csum_partial_copy_generic((__force
const void *)src
, dst
,
61 len
, sum
, err_ptr
, NULL
);
65 * Fold a partial checksum
68 static __inline__ __sum16
csum_fold(__wsum sum
)
71 __asm__("extui %1, %0, 16, 16\n\t"
72 "extui %0 ,%0, 0, 16\n\t"
76 "extui %0, %0, 16, 16\n\t"
79 "extui %0, %0, 0, 16\n\t"
80 : "=r" (sum
), "=&r" (__dummy
)
82 return (__force __sum16
)sum
;
86 * This is a version of ip_compute_csum() optimized for IP headers,
87 * which always checksum on 4 octet boundaries.
89 static __inline__ __sum16
ip_fast_csum(const void *iph
, unsigned int ihl
)
91 unsigned int sum
, tmp
, endaddr
;
105 "bgeu %0, %3, 1f\n\t"
109 #if !XCHAL_HAVE_LOOPS
113 /* Since the input registers which are loaded with iph and ihl
114 are modified, we must also specify them as outputs, or gcc
115 will assume they contain their original values. */
116 : "=r" (sum
), "=r" (iph
), "=r" (ihl
), "=&r" (tmp
),
118 : "1" (iph
), "2" (ihl
)
121 return csum_fold(sum
);
124 static __inline__ __wsum
csum_tcpudp_nofold(__be32 saddr
, __be32 daddr
,
126 unsigned short proto
,
131 unsigned long len_proto
= (len
+ proto
) << 8;
132 #elif defined(__XTENSA_EB__)
133 unsigned long len_proto
= len
+ proto
;
135 # error processor byte order undefined!
137 __asm__("add %0, %0, %1\n\t"
138 "bgeu %0, %1, 1f\n\t"
142 "bgeu %0, %2, 1f\n\t"
146 "bgeu %0, %3, 1f\n\t"
149 : "=r" (sum
), "=r" (len_proto
)
150 : "r" (daddr
), "r" (saddr
), "1" (len_proto
), "0" (sum
));
155 * computes the checksum of the TCP/UDP pseudo-header
156 * returns a 16-bit checksum, already complemented
158 static __inline__ __sum16
csum_tcpudp_magic(__be32 saddr
, __be32 daddr
,
160 unsigned short proto
,
163 return csum_fold(csum_tcpudp_nofold(saddr
,daddr
,len
,proto
,sum
));
167 * this routine is used for miscellaneous IP-like checksums, mainly
171 static __inline__ __sum16
ip_compute_csum(const void *buff
, int len
)
173 return csum_fold (csum_partial(buff
, len
, 0));
176 #define _HAVE_ARCH_IPV6_CSUM
177 static __inline__ __sum16
csum_ipv6_magic(const struct in6_addr
*saddr
,
178 const struct in6_addr
*daddr
,
179 __u32 len
, unsigned short proto
,
182 unsigned int __dummy
;
183 __asm__("l32i %1, %2, 0\n\t"
185 "bgeu %0, %1, 1f\n\t"
190 "bgeu %0, %1, 1f\n\t"
195 "bgeu %0, %1, 1f\n\t"
198 "l32i %1, %2, 12\n\t"
200 "bgeu %0, %1, 1f\n\t"
205 "bgeu %0, %1, 1f\n\t"
210 "bgeu %0, %1, 1f\n\t"
215 "bgeu %0, %1, 1f\n\t"
218 "l32i %1, %3, 12\n\t"
220 "bgeu %0, %1, 1f\n\t"
224 "bgeu %0, %4, 1f\n\t"
228 "bgeu %0, %5, 1f\n\t"
231 : "=r" (sum
), "=&r" (__dummy
)
232 : "r" (saddr
), "r" (daddr
),
233 "r" (htonl(len
)), "r" (htonl(proto
)), "0" (sum
)
236 return csum_fold(sum
);
240 * Copy and checksum to user
242 #define HAVE_CSUM_COPY_USER
243 static __inline__ __wsum
csum_and_copy_to_user(const void *src
,
244 void __user
*dst
, int len
,
245 __wsum sum
, int *err_ptr
)
247 if (access_ok(VERIFY_WRITE
, dst
, len
))
248 return csum_partial_copy_generic(src
,dst
,len
,sum
,NULL
,err_ptr
);
253 return (__force __wsum
)-1; /* invalid checksum */
This page took 0.03927 seconds and 4 git commands to generate.