Path: blob/master/arch/loongarch/include/asm/checksum.h
52464 views
/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Copyright (C) 2016 ARM Ltd.3* Copyright (C) 2023 Loongson Technology Corporation Limited4*/5#ifndef __ASM_CHECKSUM_H6#define __ASM_CHECKSUM_H78#include <linux/bitops.h>9#include <linux/in6.h>1011#ifdef CONFIG_64BIT1213#define _HAVE_ARCH_IPV6_CSUM14__sum16 csum_ipv6_magic(const struct in6_addr *saddr,15const struct in6_addr *daddr,16__u32 len, __u8 proto, __wsum sum);1718/*19* turns a 32-bit partial checksum (e.g. from csum_partial) into a20* 1's complement 16-bit checksum.21*/22static inline __sum16 csum_fold(__wsum sum)23{24u32 tmp = (__force u32)sum;2526/*27* swap the two 16-bit halves of sum28* if there is a carry from adding the two 16-bit halves,29* it will carry from the lower half into the upper half,30* giving us the correct sum in the upper half.31*/32return (__force __sum16)(~(tmp + rol32(tmp, 16)) >> 16);33}34#define csum_fold csum_fold3536/*37* This is a version of ip_compute_csum() optimized for IP headers,38* which always checksum on 4 octet boundaries. ihl is the number39* of 32-bit words and is always >= 5.40*/41static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)42{43u64 sum;44__uint128_t tmp;45int n = ihl; /* we want it signed */4647tmp = *(const __uint128_t *)iph;48iph += 16;49n -= 4;50tmp += ((tmp >> 64) | (tmp << 64));51sum = tmp >> 64;52do {53sum += *(const u32 *)iph;54iph += 4;55} while (--n > 0);5657sum += ror64(sum, 32);58return csum_fold((__force __wsum)(sum >> 32));59}60#define ip_fast_csum ip_fast_csum6162extern unsigned int do_csum(const unsigned char *buff, int len);63#define do_csum do_csum6465#endif6667#include <asm-generic/checksum.h>6869#endif /* __ASM_CHECKSUM_H */707172