x86/oprofile: Fix bogus GCC-8 warning in nmi_setup()
[cris-mirror.git] / arch / arm64 / include / asm / checksum.h
blob0b6f5a7d4027c56fcd868e3aecc0f93ef1f10432
1 /*
2 * Copyright (C) 2016 ARM Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #ifndef __ASM_CHECKSUM_H
17 #define __ASM_CHECKSUM_H
19 #include <linux/types.h>
21 static inline __sum16 csum_fold(__wsum csum)
23 u32 sum = (__force u32)csum;
24 sum += (sum >> 16) | (sum << 16);
25 return ~(__force __sum16)(sum >> 16);
27 #define csum_fold csum_fold
29 static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
31 __uint128_t tmp;
32 u64 sum;
34 tmp = *(const __uint128_t *)iph;
35 iph += 16;
36 ihl -= 4;
37 tmp += ((tmp >> 64) | (tmp << 64));
38 sum = tmp >> 64;
39 do {
40 sum += *(const u32 *)iph;
41 iph += 4;
42 } while (--ihl);
44 sum += ((sum >> 32) | (sum << 32));
45 return csum_fold((__force u32)(sum >> 32));
47 #define ip_fast_csum ip_fast_csum
49 #include <asm-generic/checksum.h>
51 #endif /* __ASM_CHECKSUM_H */