···11+/*22+ * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)33+ *44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License version 2 as66+ * published by the Free Software Foundation.77+ */88+99+#ifndef __ASM_ARC_BYTEORDER_H1010+#define __ASM_ARC_BYTEORDER_H1111+1212+#ifdef CONFIG_CPU_BIG_ENDIAN1313+#include <linux/byteorder/big_endian.h>1414+#else1515+#include <linux/byteorder/little_endian.h>1616+#endif1717+1818+#endif /* ASM_ARC_BYTEORDER_H */
+101
arch/arc/include/asm/checksum.h
···11+/*22+ * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)33+ *44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License version 2 as66+ * published by the Free Software Foundation.77+ *88+ * Joern Rennecke <joern.rennecke@embecosm.com>: Jan 201299+ * -Insn Scheduling improvements to csum core routines.1010+ * = csum_fold( ) largely derived from ARM version.1111+ * = ip_fast_cum( ) to have module scheduling1212+ * -gcc 4.4.x broke networking. Alias analysis needed to be primed.1313+ * worked around by adding memory clobber to ip_fast_csum( )1414+ *1515+ * vineetg: May 20101616+ * -Rewrote ip_fast_cscum( ) and csum_fold( ) with fast inline asm1717+ */1818+1919+#ifndef _ASM_ARC_CHECKSUM_H2020+#define _ASM_ARC_CHECKSUM_H2121+2222+/*2323+ * Fold a partial checksum2424+ *2525+ * The 2 swords comprising the 32bit sum are added, any carry to 16th bit2626+ * added back and final sword result inverted.2727+ */2828+static inline __sum16 csum_fold(__wsum s)2929+{3030+ unsigned r = s << 16 | s >> 16; /* ror */3131+ s = ~s;3232+ s -= r;3333+ return s >> 16;3434+}3535+3636+/*3737+ * This is a version of ip_compute_csum() optimized for IP headers,3838+ * which always checksum on 4 octet boundaries.3939+ */4040+static inline __sum164141+ip_fast_csum(const void *iph, unsigned int ihl)4242+{4343+ const void *ptr = iph;4444+ unsigned int tmp, tmp2, sum;4545+4646+ __asm__(4747+ " ld.ab %0, [%3, 4] \n"4848+ " ld.ab %2, [%3, 4] \n"4949+ " sub %1, %4, 2 \n"5050+ " lsr.f lp_count, %1, 1 \n"5151+ " bcc 0f \n"5252+ " add.f %0, %0, %2 \n"5353+ " ld.ab %2, [%3, 4] \n"5454+ "0: lp 1f \n"5555+ " ld.ab %1, [%3, 4] \n"5656+ " adc.f %0, %0, %2 \n"5757+ " ld.ab %2, [%3, 4] \n"5858+ " adc.f %0, %0, %1 \n"5959+ "1: adc.f %0, %0, %2 \n"6060+ " add.cs %0,%0,1 \n"6161+ : "=&r"(sum), "=r"(tmp), "=&r"(tmp2), "+&r" (ptr)6262+ : "r"(ihl)6363+ : "cc", "lp_count", "memory");6464+6565+ return csum_fold(sum);6666+}6767+6868+/*6969+ * TCP pseudo Header is 12 bytes:7070+ * SA [4], DA [4], zeroes [1], Proto[1], TCP Seg(hdr+data) Len [2]7171+ */7272+static inline __wsum7373+csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,7474+ unsigned short proto, __wsum sum)7575+{7676+ __asm__ __volatile__(7777+ " add.f %0, %0, %1 \n"7878+ " adc.f %0, %0, %2 \n"7979+ " adc.f %0, %0, %3 \n"8080+ " adc.f %0, %0, %4 \n"8181+ " adc %0, %0, 0 \n"8282+ : "+&r"(sum)8383+ : "r"(saddr), "r"(daddr),8484+#ifdef CONFIG_CPU_BIG_ENDIAN8585+ "r"(len),8686+#else8787+ "r"(len << 8),8888+#endif8989+ "r"(htons(proto))9090+ : "cc");9191+9292+ return sum;9393+}9494+9595+#define csum_fold csum_fold9696+#define ip_fast_csum ip_fast_csum9797+#define csum_tcpudp_nofold csum_tcpudp_nofold9898+9999+#include <asm-generic/checksum.h>100100+101101+#endif /* _ASM_ARC_CHECKSUM_H */
+98
arch/arc/include/asm/swab.h
···11+/*22+ * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)33+ *44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License version 2 as66+ * published by the Free Software Foundation.77+ *88+ * vineetg: May 201199+ * -Support single cycle endian-swap insn in ARC700 4.101010+ *1111+ * vineetg: June 20091212+ * -Better htonl implementation (5 instead of 9 ALU instructions)1313+ * -Hardware assisted single cycle bswap (Use Case of ARC custom instrn)1414+ */1515+1616+#ifndef __ASM_ARC_SWAB_H1717+#define __ASM_ARC_SWAB_H1818+1919+#include <linux/types.h>2020+2121+/* Native single cycle endian swap insn */2222+#ifdef CONFIG_ARC_HAS_SWAPE2323+2424+#define __arch_swab32(x) \2525+({ \2626+ unsigned int tmp = x; \2727+ __asm__( \2828+ " swape %0, %1 \n" \2929+ : "=r" (tmp) \3030+ : "r" (tmp)); \3131+ tmp; \3232+})3333+3434+#else3535+3636+/* Several ways of Endian-Swap Emulation for ARC3737+ * 0: kernel generic3838+ * 1: ARC optimised "C"3939+ * 2: ARC Custom instruction4040+ */4141+#define ARC_BSWAP_TYPE 14242+4343+#if (ARC_BSWAP_TYPE == 1) /******* Software only ********/4444+4545+/* The kernel default implementation of htonl is4646+ * return x<<24 | x>>24 |4747+ * (x & (__u32)0x0000ff00UL)<<8 | (x & (__u32)0x00ff0000UL)>>8;4848+ *4949+ * This generates 9 instructions on ARC (excluding the ld/st)5050+ *5151+ * 8051fd8c: ld r3,[r7,20] ; Mem op : Get the value to be swapped5252+ * 8051fd98: asl r5,r3,24 ; get 3rd Byte5353+ * 8051fd9c: lsr r2,r3,24 ; get 0th Byte5454+ * 8051fda0: and r4,r3,0xff005555+ * 8051fda8: asl r4,r4,8 ; get 1st Byte5656+ * 8051fdac: and r3,r3,0x00ff00005757+ * 8051fdb4: or r2,r2,r5 ; combine 0th and 3rd Bytes5858+ * 8051fdb8: lsr r3,r3,8 ; 2nd Byte at correct place in Dst Reg5959+ * 8051fdbc: or r2,r2,r4 ; combine 0,3 Bytes with 1st Byte6060+ * 8051fdc0: or r2,r2,r3 ; combine 0,3,1 Bytes with 2nd Byte6161+ * 8051fdc4: st r2,[r1,20] ; Mem op : save result back to mem6262+ *6363+ * Joern suggested a better "C" algorithm which is great since6464+ * (1) It is portable to any architecure6565+ * (2) At the same time it takes advantage of ARC ISA (rotate intrns)6666+ */6767+6868+#define __arch_swab32(x) \6969+({ unsigned long __in = (x), __tmp; \7070+ __tmp = __in << 8 | __in >> 24; /* ror tmp,in,24 */ \7171+ __in = __in << 24 | __in >> 8; /* ror in,in,8 */ \7272+ __tmp ^= __in; \7373+ __tmp &= 0xff00ff; \7474+ __tmp ^ __in; \7575+})7676+7777+#elif (ARC_BSWAP_TYPE == 2) /* Custom single cycle bwap instruction */7878+7979+#define __arch_swab32(x) \8080+({ \8181+ unsigned int tmp = x; \8282+ __asm__( \8383+ " .extInstruction bswap, 7, 0x00, SUFFIX_NONE, SYNTAX_2OP \n"\8484+ " bswap %0, %1 \n"\8585+ : "=r" (tmp) \8686+ : "r" (tmp)); \8787+ tmp; \8888+})8989+9090+#endif /* ARC_BSWAP_TYPE=zzz */9191+9292+#endif /* CONFIG_ARC_HAS_SWAPE */9393+9494+#if !defined(__STRICT_ANSI__) || defined(__KERNEL__)9595+#define __SWAB_64_THRU_32__9696+#endif9797+9898+#endif