Path: blob/master/arch/loongarch/include/asm/checksum.h
26488 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#define _HAVE_ARCH_IPV6_CSUM12__sum16 csum_ipv6_magic(const struct in6_addr *saddr,13const struct in6_addr *daddr,14__u32 len, __u8 proto, __wsum sum);1516/*17* turns a 32-bit partial checksum (e.g. from csum_partial) into a18* 1's complement 16-bit checksum.19*/20static inline __sum16 csum_fold(__wsum sum)21{22u32 tmp = (__force u32)sum;2324/*25* swap the two 16-bit halves of sum26* if there is a carry from adding the two 16-bit halves,27* it will carry from the lower half into the upper half,28* giving us the correct sum in the upper half.29*/30return (__force __sum16)(~(tmp + rol32(tmp, 16)) >> 16);31}32#define csum_fold csum_fold3334/*35* This is a version of ip_compute_csum() optimized for IP headers,36* which always checksum on 4 octet boundaries. ihl is the number37* of 32-bit words and is always >= 5.38*/39static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)40{41u64 sum;42__uint128_t tmp;43int n = ihl; /* we want it signed */4445tmp = *(const __uint128_t *)iph;46iph += 16;47n -= 4;48tmp += ((tmp >> 64) | (tmp << 64));49sum = tmp >> 64;50do {51sum += *(const u32 *)iph;52iph += 4;53} while (--n > 0);5455sum += ror64(sum, 32);56return csum_fold((__force __wsum)(sum >> 32));57}58#define ip_fast_csum ip_fast_csum5960extern unsigned int do_csum(const unsigned char *buff, int len);61#define do_csum do_csum6263#include <asm-generic/checksum.h>6465#endif /* __ASM_CHECKSUM_H */666768