Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Robin Murphy | 0e455d8 | 2016-05-31 18:04:40 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 ARM Ltd. |
Robin Murphy | 0e455d8 | 2016-05-31 18:04:40 +0100 | [diff] [blame] | 4 | */ |
| 5 | #ifndef __ASM_CHECKSUM_H |
| 6 | #define __ASM_CHECKSUM_H |
| 7 | |
| 8 | #include <linux/types.h> |
| 9 | |
| 10 | static inline __sum16 csum_fold(__wsum csum) |
| 11 | { |
| 12 | u32 sum = (__force u32)csum; |
| 13 | sum += (sum >> 16) | (sum << 16); |
| 14 | return ~(__force __sum16)(sum >> 16); |
| 15 | } |
| 16 | #define csum_fold csum_fold |
| 17 | |
| 18 | static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) |
| 19 | { |
| 20 | __uint128_t tmp; |
| 21 | u64 sum; |
| 22 | |
| 23 | tmp = *(const __uint128_t *)iph; |
| 24 | iph += 16; |
| 25 | ihl -= 4; |
| 26 | tmp += ((tmp >> 64) | (tmp << 64)); |
| 27 | sum = tmp >> 64; |
| 28 | do { |
| 29 | sum += *(const u32 *)iph; |
| 30 | iph += 4; |
| 31 | } while (--ihl); |
| 32 | |
| 33 | sum += ((sum >> 32) | (sum << 32)); |
Luc Van Oostenryck | 50a4b05 | 2017-06-29 16:31:40 +0200 | [diff] [blame] | 34 | return csum_fold((__force u32)(sum >> 32)); |
Robin Murphy | 0e455d8 | 2016-05-31 18:04:40 +0100 | [diff] [blame] | 35 | } |
| 36 | #define ip_fast_csum ip_fast_csum |
| 37 | |
Robin Murphy | 5777eae | 2020-01-15 16:42:39 +0000 | [diff] [blame] | 38 | extern unsigned int do_csum(const unsigned char *buff, int len); |
| 39 | #define do_csum do_csum |
| 40 | |
Robin Murphy | 0e455d8 | 2016-05-31 18:04:40 +0100 | [diff] [blame] | 41 | #include <asm-generic/checksum.h> |
| 42 | |
| 43 | #endif /* __ASM_CHECKSUM_H */ |