summaryrefslogtreecommitdiffstats
path: root/include/net
diff options
context:
space:
mode:
authorAlexander Duyck <aduyck@mirantis.com>2016-03-09 09:25:26 -0800
committerDavid S. Miller <davem@davemloft.net>2016-03-13 15:01:00 -0400
commit338039635d01524090e7bd706a3e555e20d5b337 (patch)
tree057defd0704c2fcb6500c062037f2657710b73e2 /include/net
parentc194cf93c164ed1c71142485ee0f70f9f2d1fe35 (diff)
downloadop-kernel-dev-338039635d01524090e7bd706a3e555e20d5b337.zip
op-kernel-dev-338039635d01524090e7bd706a3e555e20d5b337.tar.gz
csum: Update csum_block_add to use rotate instead of byteswap
The code for csum_block_add was doing a funky byteswap to swap the even and odd bytes of the checksum if the offset was odd. Instead of doing this we can save ourselves some trouble and just shift by 8 as this should have the same effect in terms of the final checksum value and only requires one instruction. In addition we can update csum_block_sub to just use csum_block_add with a inverse value for csum2. This way we follow the same code path as csum_block_add without having to duplicate it. Signed-off-by: Alexander Duyck <aduyck@mirantis.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net')
-rw-r--r--include/net/checksum.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/include/net/checksum.h b/include/net/checksum.h
index abffc64..5c30891 100644
--- a/include/net/checksum.h
+++ b/include/net/checksum.h
@@ -88,8 +88,11 @@ static inline __wsum
csum_block_add(__wsum csum, __wsum csum2, int offset)
{
u32 sum = (__force u32)csum2;
- if (offset&1)
- sum = ((sum&0xFF00FF)<<8)+((sum>>8)&0xFF00FF);
+
+ /* rotate sum to align it with a 16b boundary */
+ if (offset & 1)
+ sum = ror32(sum, 8);
+
return csum_add(csum, (__force __wsum)sum);
}
@@ -102,10 +105,7 @@ csum_block_add_ext(__wsum csum, __wsum csum2, int offset, int len)
static inline __wsum
csum_block_sub(__wsum csum, __wsum csum2, int offset)
{
- u32 sum = (__force u32)csum2;
- if (offset&1)
- sum = ((sum&0xFF00FF)<<8)+((sum>>8)&0xFF00FF);
- return csum_sub(csum, (__force __wsum)sum);
+ return csum_block_add(csum, ~csum2, offset);
}
static inline __wsum csum_unfold(__sum16 n)
OpenPOWER on IntegriCloud