···99#define _BFIN_CHECKSUM_H10101111/*1212- * computes the checksum of a memory block at buff, length len,1313- * and adds in "sum" (32-bit)1414- *1515- * returns a 32-bit number suitable for feeding into itself1616- * or csum_tcpudp_magic1717- *1818- * this function must be called with even lengths, except1919- * for the last fragment, which may be odd2020- *2121- * it's best to have buff aligned on a 32-bit boundary2222- */2323-__wsum csum_partial(const void *buff, int len, __wsum sum);2424-2525-/*2626- * the same as csum_partial, but copies from src while it2727- * checksums2828- *2929- * here even more important to align src and dst on a 32-bit (or even3030- * better 64-bit) boundary3131- */3232-3333-__wsum csum_partial_copy(const void *src, void *dst,3434- int len, __wsum sum);3535-3636-/*3737- * the same as csum_partial_copy, but copies from user space.3838- *3939- * here even more important to align src and dst on a 32-bit (or even4040- * better 64-bit) boundary4141- */4242-4343-extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,4444- int len, __wsum sum, int *csum_err);4545-4646-#define csum_partial_copy_nocheck(src, dst, len, sum) \4747- csum_partial_copy((src), (dst), (len), (sum))4848-4949-__sum16 ip_fast_csum(unsigned char *iph, unsigned int ihl);5050-5151-/*5252- * Fold a partial checksum5353- */5454-5555-static inline __sum16 csum_fold(__wsum sum)5656-{5757- while (sum >> 16)5858- sum = (sum & 0xffff) + (sum >> 16);5959- return ((~(sum << 16)) >> 16);6060-}6161-6262-/*6312 * computes the checksum of the TCP/UDP pseudo-header6413 * returns a 16-bit checksum, already complemented6514 */66156716static inline __wsum6868-csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,1717+__csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,6918 unsigned short proto, __wsum sum)7019{7120 unsigned int carry;···37883889 return (sum);3990}9191+#define csum_tcpudp_nofold __csum_tcpudp_nofold40924141-static inline __sum164242-csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,4343- unsigned short proto, __wsum sum)4444-{4545- return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));4646-}9393+#include <asm-generic/checksum.h>47944848-/*4949- * this routine is used for miscellaneous IP-like checksums, mainly5050- * in icmp.c5151- */5252-5353-extern __sum16 ip_compute_csum(const void *buff, int len);5454-5555-#endif /* _BFIN_CHECKSUM_H */9595+#endif
···11-/*22- * Copyright 2004-2009 Analog Devices Inc.33- *44- * Licensed under the GPL-2 or later.55- *66- * An implementation of the TCP/IP protocol suite for the LINUX operating77- * system. INET is implemented using the BSD Socket interface as the88- * means of communication with the user level.99- *1010- */1111-1212-#include <linux/module.h>1313-#include <net/checksum.h>1414-#include <asm/checksum.h>1515-1616-#ifdef CONFIG_IP_CHECKSUM_L11717-static unsigned short do_csum(const unsigned char *buff, int len)__attribute__((l1_text));1818-#endif1919-2020-static unsigned short do_csum(const unsigned char *buff, int len)2121-{2222- register unsigned long sum = 0;2323- int swappem = 0;2424-2525- if (1 & (unsigned long)buff) {2626- sum = *buff << 8;2727- buff++;2828- len--;2929- ++swappem;3030- }3131-3232- while (len > 1) {3333- sum += *(unsigned short *)buff;3434- buff += 2;3535- len -= 2;3636- }3737-3838- if (len > 0)3939- sum += *buff;4040-4141- /* Fold 32-bit sum to 16 bits */4242- while (sum >> 16)4343- sum = (sum & 0xffff) + (sum >> 16);4444-4545- if (swappem)4646- sum = ((sum & 0xff00) >> 8) + ((sum & 0x00ff) << 8);4747-4848- return sum;4949-5050-}5151-5252-/*5353- * This is a version of ip_compute_csum() optimized for IP headers,5454- * which always checksum on 4 octet boundaries.5555- */5656-__sum16 ip_fast_csum(unsigned char *iph, unsigned int ihl)5757-{5858- return (__force __sum16)~do_csum(iph, ihl * 4);5959-}6060-EXPORT_SYMBOL(ip_fast_csum);6161-6262-/*6363- * computes the checksum of a memory block at buff, length len,6464- * and adds in "sum" (32-bit)6565- *6666- * returns a 32-bit number suitable for feeding into itself6767- * or csum_tcpudp_magic6868- *6969- * this function must be called with even lengths, except7070- * for the last fragment, which may be odd7171- *7272- * it's best to have buff aligned on a 32-bit boundary7373- */7474-__wsum csum_partial(const void *buff, int len, __wsum sum)7575-{7676- /*7777- * Just in case we get nasty checksum data...7878- * Like 0xffff6ec3 in the case of our IPv6 multicast header.7979- * We fold to begin with, as well as at the end.8080- */8181- sum = (sum & 0xffff) + (sum >> 16);8282-8383- sum += do_csum(buff, len);8484-8585- sum = (sum & 0xffff) + (sum >> 16);8686-8787- return sum;8888-}8989-EXPORT_SYMBOL(csum_partial);9090-9191-/*9292- * this routine is used for miscellaneous IP-like checksums, mainly9393- * in icmp.c9494- */9595-__sum16 ip_compute_csum(const void *buff, int len)9696-{9797- return (__force __sum16)~do_csum(buff, len);9898-}9999-EXPORT_SYMBOL(ip_compute_csum);100100-101101-/*102102- * copy from fs while checksumming, otherwise like csum_partial103103- */104104-105105-__wsum106106-csum_partial_copy_from_user(const void __user *src, void *dst,107107- int len, __wsum sum, int *csum_err)108108-{109109- if (csum_err)110110- *csum_err = 0;111111- memcpy(dst, (__force void *)src, len);112112- return csum_partial(dst, len, sum);113113-}114114-EXPORT_SYMBOL(csum_partial_copy_from_user);115115-116116-/*117117- * copy from ds while checksumming, otherwise like csum_partial118118- */119119-120120-__wsum csum_partial_copy(const void *src, void *dst, int len, __wsum sum)121121-{122122- memcpy(dst, src, len);123123- return csum_partial(dst, len, sum);124124-}125125-EXPORT_SYMBOL(csum_partial_copy);