Path: blob/master/arch/cris/include/asm/checksum.h
15126 views
/* TODO: csum_tcpudp_magic could be speeded up, and csum_fold as well */12#ifndef _CRIS_CHECKSUM_H3#define _CRIS_CHECKSUM_H45#include <arch/checksum.h>67/*8* computes the checksum of a memory block at buff, length len,9* and adds in "sum" (32-bit)10*11* returns a 32-bit number suitable for feeding into itself12* or csum_tcpudp_magic13*14* this function must be called with even lengths, except15* for the last fragment, which may be odd16*17* it's best to have buff aligned on a 32-bit boundary18*/19__wsum csum_partial(const void *buff, int len, __wsum sum);2021/*22* the same as csum_partial, but copies from src while it23* checksums24*25* here even more important to align src and dst on a 32-bit (or even26* better 64-bit) boundary27*/2829__wsum csum_partial_copy_nocheck(const void *src, void *dst,30int len, __wsum sum);3132/*33* Fold a partial checksum into a word34*/3536static inline __sum16 csum_fold(__wsum csum)37{38u32 sum = (__force u32)csum;39sum = (sum & 0xffff) + (sum >> 16); /* add in end-around carry */40sum = (sum & 0xffff) + (sum >> 16); /* add in end-around carry */41return (__force __sum16)~sum;42}4344extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,45int len, __wsum sum,46int *errptr);4748/*49* This is a version of ip_compute_csum() optimized for IP headers,50* which always checksum on 4 octet boundaries.51*52*/5354static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)55{56return csum_fold(csum_partial(iph, ihl * 4, 0));57}5859/*60* computes the checksum of the TCP/UDP pseudo-header61* returns a 16-bit checksum, already complemented62*/6364static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,65unsigned short len,66unsigned short proto,67__wsum sum)68{69return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));70}7172/*73* this routine is used for miscellaneous IP-like checksums, mainly74* in icmp.c75*/7677static inline __sum16 ip_compute_csum(const void *buff, int len)78{79return csum_fold (csum_partial(buff, len, 0));80}8182#endif838485