Path: blob/master/arch/h8300/include/asm/checksum.h
10834 views
#ifndef _H8300_CHECKSUM_H1#define _H8300_CHECKSUM_H23/*4* computes the checksum of a memory block at buff, length len,5* and adds in "sum" (32-bit)6*7* returns a 32-bit number suitable for feeding into itself8* or csum_tcpudp_magic9*10* this function must be called with even lengths, except11* for the last fragment, which may be odd12*13* it's best to have buff aligned on a 32-bit boundary14*/15__wsum csum_partial(const void *buff, int len, __wsum sum);1617/*18* the same as csum_partial, but copies from src while it19* checksums20*21* here even more important to align src and dst on a 32-bit (or even22* better 64-bit) boundary23*/2425__wsum csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);262728/*29* the same as csum_partial_copy, but copies from user space.30*31* here even more important to align src and dst on a 32-bit (or even32* better 64-bit) boundary33*/3435extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,36int len, __wsum sum, int *csum_err);3738__sum16 ip_fast_csum(const void *iph, unsigned int ihl);394041/*42* Fold a partial checksum43*/4445static inline __sum16 csum_fold(__wsum sum)46{47__asm__("mov.l %0,er0\n\t"48"add.w e0,r0\n\t"49"xor.w e0,e0\n\t"50"rotxl.w e0\n\t"51"add.w e0,r0\n\t"52"sub.w e0,e0\n\t"53"mov.l er0,%0"54: "=r"(sum)55: "0"(sum)56: "er0");57return (__force __sum16)~sum;58}596061/*62* computes the checksum of the TCP/UDP pseudo-header63* returns a 16-bit checksum, already complemented64*/6566static inline __wsum67csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,68unsigned short proto, __wsum sum)69{70__asm__ ("sub.l er0,er0\n\t"71"add.l %2,%0\n\t"72"addx #0,r0l\n\t"73"add.l %3,%0\n\t"74"addx #0,r0l\n\t"75"add.l %4,%0\n\t"76"addx #0,r0l\n\t"77"add.l er0,%0\n\t"78"bcc 1f\n\t"79"inc.l #1,%0\n"80"1:"81: "=&r" (sum)82: "0" (sum), "r" (daddr), "r" (saddr), "r" (len + proto)83:"er0");84return sum;85}8687static inline __sum1688csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,89unsigned short proto, __wsum sum)90{91return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));92}9394/*95* this routine is used for miscellaneous IP-like checksums, mainly96* in icmp.c97*/9899extern __sum16 ip_compute_csum(const void *buff, int len);100101#endif /* _H8300_CHECKSUM_H */102103104