diff options
author | Chris Metcalf <cmetcalf@tilera.com> | 2012-04-28 15:41:39 -0400 |
---|---|---|
committer | Chris Metcalf <cmetcalf@tilera.com> | 2012-07-11 16:04:57 -0400 |
commit | 10104a1ad670889adc1ae3779df968db621b5dbd (patch) | |
tree | 1a5aa6b3ae5c669b818bf076f748a8a54d27f88f /arch/tile | |
parent | 4875f69fecab08654972d6fb0d71ee2109d2538c (diff) |
arch/tile: break out the "csum a long" function to <asm/checksum.h>
This makes it available to the tilegx network driver.
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
Diffstat (limited to 'arch/tile')
-rw-r--r-- | arch/tile/include/asm/checksum.h | 18 | ||||
-rw-r--r-- | arch/tile/lib/checksum.c | 15 |
2 files changed, 19 insertions, 14 deletions
diff --git a/arch/tile/include/asm/checksum.h b/arch/tile/include/asm/checksum.h index a120766c7264..b21a2fdec9f7 100644 --- a/arch/tile/include/asm/checksum.h +++ b/arch/tile/include/asm/checksum.h | |||
@@ -21,4 +21,22 @@ | |||
21 | __wsum do_csum(const unsigned char *buff, int len); | 21 | __wsum do_csum(const unsigned char *buff, int len); |
22 | #define do_csum do_csum | 22 | #define do_csum do_csum |
23 | 23 | ||
24 | /* | ||
25 | * Return the sum of all the 16-bit subwords in a long. | ||
26 | * This sums two subwords on a 32-bit machine, and four on 64 bits. | ||
27 | * The implementation does two vector adds to capture any overflow. | ||
28 | */ | ||
29 | static inline unsigned int csum_long(unsigned long x) | ||
30 | { | ||
31 | unsigned long ret; | ||
32 | #ifdef __tilegx__ | ||
33 | ret = __insn_v2sadu(x, 0); | ||
34 | ret = __insn_v2sadu(ret, 0); | ||
35 | #else | ||
36 | ret = __insn_sadh_u(x, 0); | ||
37 | ret = __insn_sadh_u(ret, 0); | ||
38 | #endif | ||
39 | return ret; | ||
40 | } | ||
41 | |||
24 | #endif /* _ASM_TILE_CHECKSUM_H */ | 42 | #endif /* _ASM_TILE_CHECKSUM_H */ |
diff --git a/arch/tile/lib/checksum.c b/arch/tile/lib/checksum.c index e4bab5bd3f31..c3ca3e64d9d9 100644 --- a/arch/tile/lib/checksum.c +++ b/arch/tile/lib/checksum.c | |||
@@ -16,19 +16,6 @@ | |||
16 | #include <net/checksum.h> | 16 | #include <net/checksum.h> |
17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | 18 | ||
19 | static inline unsigned int longto16(unsigned long x) | ||
20 | { | ||
21 | unsigned long ret; | ||
22 | #ifdef __tilegx__ | ||
23 | ret = __insn_v2sadu(x, 0); | ||
24 | ret = __insn_v2sadu(ret, 0); | ||
25 | #else | ||
26 | ret = __insn_sadh_u(x, 0); | ||
27 | ret = __insn_sadh_u(ret, 0); | ||
28 | #endif | ||
29 | return ret; | ||
30 | } | ||
31 | |||
32 | __wsum do_csum(const unsigned char *buff, int len) | 19 | __wsum do_csum(const unsigned char *buff, int len) |
33 | { | 20 | { |
34 | int odd, count; | 21 | int odd, count; |
@@ -94,7 +81,7 @@ __wsum do_csum(const unsigned char *buff, int len) | |||
94 | } | 81 | } |
95 | if (len & 1) | 82 | if (len & 1) |
96 | result += *buff; | 83 | result += *buff; |
97 | result = longto16(result); | 84 | result = csum_long(result); |
98 | if (odd) | 85 | if (odd) |
99 | result = swab16(result); | 86 | result = swab16(result); |
100 | out: | 87 | out: |