arch/powerpc/include/asm/checksum.h

Source file repositories/reference/linux-study-clean/arch/powerpc/include/asm/checksum.h

File Facts

System
Linux kernel
Corpus path
arch/powerpc/include/asm/checksum.h
Extension
.h
Size
6166 bytes
Lines
236
Domain
Architecture Layer
Bucket
arch/powerpc
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

#ifndef _ASM_POWERPC_CHECKSUM_H
#define _ASM_POWERPC_CHECKSUM_H
#ifdef __KERNEL__

/*
 */

#include <linux/bitops.h>
#include <linux/in6.h>
#include <linux/uaccess.h>
/*
 * Computes the checksum of a memory block at src, length len,
 * and adds in "sum" (32-bit), while copying the block to dst.
 * If an access exception occurs on src or dst, it stores -EFAULT
 * to *src_err or *dst_err respectively (if that pointer is not
 * NULL), and, for an error on src, zeroes the rest of dst.
 *
 * Like csum_partial, this must be called with even lengths,
 * except for the last fragment.
 */
extern __wsum csum_partial_copy_generic(const void *src, void *dst, int len);

#define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
static inline __wsum csum_and_copy_from_user(const void __user *src, void *dst, int len)
{
	scoped_user_read_access_size(src, len, efault)
		return csum_partial_copy_generic((void __force *)src, dst, len);

efault:
	return 0;
}

#define HAVE_CSUM_COPY_USER
static inline __wsum csum_and_copy_to_user(const void *src, void __user *dst, int len)
{
	scoped_user_write_access_size(dst, len, efault)
		return csum_partial_copy_generic(src, (void __force *)dst, len);

efault:
	return 0;
}

#define _HAVE_ARCH_CSUM_AND_COPY
#define csum_partial_copy_nocheck(src, dst, len)   \
        csum_partial_copy_generic((src), (dst), (len))


/*
 * turns a 32-bit partial checksum (e.g. from csum_partial) into a
 * 1's complement 16-bit checksum.
 */
static inline __sum16 csum_fold(__wsum sum)
{
	u32 tmp = (__force u32)sum;

	/*
	 * swap the two 16-bit halves of sum
	 * if there is a carry from adding the two 16-bit halves,
	 * it will carry from the lower half into the upper half,
	 * giving us the correct sum in the upper half.
	 */
	return (__force __sum16)(~(tmp + rol32(tmp, 16)) >> 16);
}

static inline u32 from64to32(u64 x)
{
	return (x + ror64(x, 32)) >> 32;
}

static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len,
					__u8 proto, __wsum sum)
{
#ifdef __powerpc64__
	u64 s = (__force u32)sum;

	s += (__force u32)saddr;
	s += (__force u32)daddr;
#ifdef __BIG_ENDIAN__
	s += proto + len;
#else
	s += (proto + len) << 8;
#endif
	return (__force __wsum) from64to32(s);
#else
    __asm__("\n\
	addc %0,%0,%1 \n\
	adde %0,%0,%2 \n\
	adde %0,%0,%3 \n\
	addze %0,%0 \n\
	"

Annotation

Implementation Notes