1 /* MN10300 Optimised checksumming wrappers
3 * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public Licence
9 * as published by the Free Software Foundation; either version
10 * 2 of the Licence, or (at your option) any later version.
12 #include <linux/module.h>
13 #include <linux/errno.h>
14 #include <asm/byteorder.h>
15 #include <asm/uaccess.h>
16 #include <asm/checksum.h>
19 static inline unsigned short from32to16(__wsum sum
)
24 : "r" (sum
<< 16), "0" (sum
& 0xffff0000)
30 __sum16
ip_fast_csum(const void *iph
, unsigned int ihl
)
32 return ~do_csum(iph
, ihl
* 4);
34 EXPORT_SYMBOL(ip_fast_csum
);
36 __wsum
csum_partial(const void *buff
, int len
, __wsum sum
)
40 result
= do_csum(buff
, len
);
46 EXPORT_SYMBOL(csum_partial
);
48 __sum16
ip_compute_csum(const void *buff
, int len
)
50 return ~from32to16(do_csum(buff
, len
));
52 EXPORT_SYMBOL(ip_compute_csum
);
54 __wsum
csum_partial_copy(const void *src
, void *dst
, int len
, __wsum sum
)
56 copy_from_user(dst
, src
, len
);
57 return csum_partial(dst
, len
, sum
);
59 EXPORT_SYMBOL(csum_partial_copy
);
61 __wsum
csum_partial_copy_nocheck(const void *src
, void *dst
,
64 sum
= csum_partial(src
, len
, sum
);
65 memcpy(dst
, src
, len
);
68 EXPORT_SYMBOL(csum_partial_copy_nocheck
);
70 __wsum
csum_partial_copy_from_user(const void *src
, void *dst
,
76 missing
= copy_from_user(dst
, src
, len
);
78 memset(dst
+ len
- missing
, 0, missing
);
82 return csum_partial(dst
, len
, sum
);
84 EXPORT_SYMBOL(csum_partial_copy_from_user
);
86 __wsum
csum_and_copy_to_user(const void *src
, void *dst
,
92 missing
= copy_to_user(dst
, src
, len
);
94 memset(dst
+ len
- missing
, 0, missing
);
98 return csum_partial(src
, len
, sum
);
100 EXPORT_SYMBOL(csum_and_copy_to_user
);