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.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/in6.hlinux/uaccess.h
Detected Declarations
function csum_and_copy_from_userfunction csum_and_copy_to_userfunction csum_partial_copy_genericfunction from64to32function csum_tcpudp_nofoldfunction csum_tcpudp_magicfunction csum_addfunction csum_shiftfunction ip_compute_csumfunction ip_fast_csumfunction csum_partialfunction ip_compute_csum
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
- Immediate include surface: `linux/bitops.h`, `linux/in6.h`, `linux/uaccess.h`.
- Detected declarations: `function csum_and_copy_from_user`, `function csum_and_copy_to_user`, `function csum_partial_copy_generic`, `function from64to32`, `function csum_tcpudp_nofold`, `function csum_tcpudp_magic`, `function csum_add`, `function csum_shift`, `function ip_compute_csum`, `function ip_fast_csum`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.