From a9f34b79757de68cdd3f951077be0dd65da6354c Mon Sep 17 00:00:00 2001 From: cvs2git Date: Sun, 7 Mar 2010 17:11:24 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'R_20100307_p0'. Sprout from base 2009-04-22 22:06:58 UTC Till Straumann ' - importing updated version from SLAC as of 20090422' Cherrypick from master 2010-03-07 17:11:23 UTC Till Straumann '2010-03-07 Till Straumann ': bsd_eth_drivers/.cvsignore bsd_eth_drivers/ChangeLog bsd_eth_drivers/Makefile.am bsd_eth_drivers/if_bge/.cvsignore bsd_eth_drivers/if_bge/Makefile.am bsd_eth_drivers/if_bge/if_bge.c bsd_eth_drivers/if_bge/if_bgereg.h bsd_eth_drivers/if_em/.cvsignore bsd_eth_drivers/if_em/Makefile.am bsd_eth_drivers/if_em/e1000_manage.c bsd_eth_drivers/if_em/e1000_manage.h bsd_eth_drivers/if_em/e1000_osdep.h bsd_eth_drivers/if_em/if_em.c bsd_eth_drivers/if_fxp/.cvsignore bsd_eth_drivers/if_fxp/Makefile.am bsd_eth_drivers/if_fxp/if_fxp.c bsd_eth_drivers/if_fxp/if_fxpvar.h bsd_eth_drivers/if_le/.cvsignore bsd_eth_drivers/if_pcn/.cvsignore bsd_eth_drivers/if_pcn/if_pcn.c bsd_eth_drivers/if_re/.cvsignore bsd_eth_drivers/if_re/Makefile.am bsd_eth_drivers/if_re/if_re.c bsd_eth_drivers/if_re/if_rl.c bsd_eth_drivers/if_re/if_rlreg.h bsd_eth_drivers/libbsdport/.cvsignore bsd_eth_drivers/libbsdport/Makefile.am bsd_eth_drivers/libbsdport/alldrv.c bsd_eth_drivers/libbsdport/bus.h bsd_eth_drivers/libbsdport/callout.h bsd_eth_drivers/libbsdport/devicet.c bsd_eth_drivers/libbsdport/ifmedia.c bsd_eth_drivers/libbsdport/libbsdport.h bsd_eth_drivers/libbsdport/libbsdport_api.h bsd_eth_drivers/libbsdport/libbsdport_post.h bsd_eth_drivers/libbsdport/miistuff.c bsd_eth_drivers/libbsdport/misc.c bsd_eth_drivers/libbsdport/mutex.h bsd_eth_drivers/libbsdport/rtems_callout.c bsd_eth_drivers/libbsdport/sysbus.c bsd_eth_drivers/libbsdport/taskqueue.h bsd_eth_drivers/links.am Cherrypick from freebsd_orig 2009-04-23 04:52:05 UTC Till Straumann ' - importing original 'releng_7_1' version of FXP driver from FreeBSD.': bsd_eth_drivers/if_fxp/if_fxpreg.h bsd_eth_drivers/if_fxp/rcvbundl.h Delete: INSTALL Makefile.am bootstrap config.h.in configure.ac m4/acinclude.m4 m4/config-if-present.m4 m4/cvstag.m4 m4/multilib-fix.m4 m4/multilib-installdir.m4 m4/rtems-bsp-postlink.m4 m4/rtems-bsplist.m4 m4/rtems-check-libargs.m4 m4/rtems-checkprog.m4 m4/rtems-checktool.m4 m4/rtems-checktop.m4 m4/rtems-fixup-prefix.m4 m4/rtems-isml.m4 m4/rtems-ismultibsp.m4 m4/rtems-isrtems.m4 m4/rtems-makevars.m4 m4/rtems-multilib.m4 m4/rtems-options.m4 m4/rtems-setup-recurse.m4 m4/rtems-tools.m4 m4/rtems-trim-builddir.m4 m4/rtems-verscheck.m4 makefile.top.am makefile.top.in rtems-pre.am rtems.am ssrlApps.components.in --- bsd_eth_drivers/if_em/.cvsignore | 1 + bsd_eth_drivers/if_em/Makefile.am | 1 + bsd_eth_drivers/if_em/e1000_osdep.h | 227 ++++++++++++++++++++---------------- bsd_eth_drivers/if_em/if_em.c | 17 ++- 4 files changed, 145 insertions(+), 101 deletions(-) create mode 100644 bsd_eth_drivers/if_em/.cvsignore (limited to 'bsd_eth_drivers/if_em') diff --git a/bsd_eth_drivers/if_em/.cvsignore b/bsd_eth_drivers/if_em/.cvsignore new file mode 100644 index 0000000..70845e0 --- /dev/null +++ b/bsd_eth_drivers/if_em/.cvsignore @@ -0,0 +1 @@ +Makefile.in diff --git a/bsd_eth_drivers/if_em/Makefile.am b/bsd_eth_drivers/if_em/Makefile.am index 1a6a12f..a795ef8 100644 --- a/bsd_eth_drivers/if_em/Makefile.am +++ b/bsd_eth_drivers/if_em/Makefile.am @@ -31,6 +31,7 @@ libif_em_a_DEPENDENCIES = $(libif_em_a_LIBADD) lib_LIBRARIES = libif_em.a +AM_CPPFLAGS += -D_KERNEL AM_CPPFLAGS += -I$(srcdir) AM_CPPFLAGS += -I$(srcdir)/../libbsdport -I../libbsdport -I../libbsdport/dummyheaders AM_CPPFLAGS += $(CPPFLAGS_82542_SUPPORT_$(ENBL_82542_SUPPORT)) diff --git a/bsd_eth_drivers/if_em/e1000_osdep.h b/bsd_eth_drivers/if_em/e1000_osdep.h index b5aa603..96a7d84 100644 --- a/bsd_eth_drivers/if_em/e1000_osdep.h +++ b/bsd_eth_drivers/if_em/e1000_osdep.h @@ -37,9 +37,16 @@ POSSIBILITY OF SUCH DAMAGE. #define _FREEBSD_OS_H_ #include -#define _KERNEL -#include #include +#include +#include /* for non-_KERNEL boolean_t :-( */ + +#ifdef _KERNEL +#ifndef __INSIDE_RTEMS_BSD_TCPIP_STACK__ +#define __INSIDE_RTEMS_BSD_TCPIP_STACK__ +#endif +#include +#include #include #include @@ -50,7 +57,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #define ASSERT(x) if(!(x)) panic("EM: x") @@ -69,13 +75,30 @@ POSSIBILITY OF SUCH DAMAGE. #define DEBUGOUT3(S,A,B,C) #define DEBUGOUT7(S,A,B,C,D,E,F,G) +#include + +struct e1000_osdep +{ + uint32_t mem_bus_space_handle; + uint32_t io_bus_space_handle; + uint32_t flash_bus_space_handle; + /* these are currently unused; present for freebsd compatibility only */ + uint32_t mem_bus_space_tag; + uint32_t io_bus_space_tag; + uint32_t flash_bus_space_tag; + device_t dev; +}; + #define STATIC static +#endif + #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE 1 #endif + #define CMD_MEM_WRT_INVALIDATE 0x0010 /* BIT_4 */ #define PCI_COMMAND_REGISTER PCIR_COMMAND @@ -92,90 +115,71 @@ typedef int32_t s32; typedef int16_t s16; typedef int8_t s8 ; -#include +typedef volatile uint32_t __uint32_va_t __attribute__((may_alias)); +typedef volatile uint16_t __uint16_va_t __attribute__((may_alias)); -struct e1000_osdep -{ - uint32_t mem_bus_space_handle; - uint32_t io_bus_space_handle; - uint32_t flash_bus_space_handle; - /* these are currently unused; present for freebsd compatibility only */ - uint32_t mem_bus_space_tag; - uint32_t io_bus_space_tag; - uint32_t flash_bus_space_tag; - device_t dev; -}; +#ifdef NO_82542_SUPPORT +#define E1000_REGISTER(hw, reg) reg +#else +#define E1000_REGISTER(hw, reg) (((hw)->mac.type >= e1000_82543) \ + ? reg : e1000_translate_register_82542(reg)) +#endif -typedef volatile uint32_t __attribute__((may_alias)) *__uint32_a_p_t; -typedef volatile uint16_t __attribute__((may_alias)) *__uint16_a_p_t; -typedef volatile uint8_t __attribute__((may_alias)) * __uint8_a_p_t; +#define E1000_WRITE_FLUSH(a) E1000_READ_REG(a, E1000_STATUS) +/* Provide our own I/O so that the low-level driver API can + * be used independently from the BSD stuff. + * This is useful for people who want to use an e1000 adapter + * for special ethernet links that do not use BSD TCP/IP. + */ #ifdef __PPC__ -#include -static inline uint8_t __in_8(uint32_t base, uint32_t offset) -{ -__uint8_a_p_t a = (__uint8_a_p_t)(base+offset); -uint8_t rval; - __asm__ __volatile__( - "sync;\n" - "lbz%U1%X1 %0,%1;\n" - "twi 0,%0,0;\n" - "isync" : "=r" (rval) : "m"(*a)); - return rval; -} -static inline void __out_8(uint32_t base, uint32_t offset, uint8_t val) -{ -__uint8_a_p_t a = (__uint8_a_p_t)(base+offset); - __asm__ __volatile__( - "stb%U0%X0 %1,%0; eieio" : "=m" (*a) : "r"(val) - ); -} +#include -static inline uint16_t __in_le16(uint32_t base, uint32_t offset) +static inline uint16_t __in_le16(uint8_t *base, uint32_t offset) { -__uint16_a_p_t a = (__uint16_a_p_t)(base+offset); uint16_t rval; - __asm__ __volatile__( - "sync;\n" - "lhbrx %0,0,%1;\n" - "twi 0,%0,0;\n" - "isync" : "=r" (rval) : "r"(a), "m"(*a)); - return rval; + __asm__ __volatile__( + "lhbrx %0,%2,%1; eieio\n" + : "=r" (rval) + : "r"(base), "b"(offset), "m"(*(__uint16_va_t*)(base + offset)) + ); + return rval; } -static inline void __out_le16(uint32_t base, uint32_t offset, uint16_t val) +static inline void __out_le16(uint8_t *base, uint32_t offset, uint16_t val) { -__uint16_a_p_t a = (__uint16_a_p_t)(base+offset); - __asm__ __volatile__( - "sync; sthbrx %1,0,%2" : "=m" (*a) : "r"(val), "r"(a) - ); + __asm__ __volatile__( + "sthbrx %1,%3,%2; eieio" + : "=o"(*(__uint16_va_t*)(base+offset)) + : "r"(val), "r"(base), "b"(offset) + ); } -static inline uint32_t __in_le32(uint32_t base, uint32_t offset) +static inline uint32_t __in_le32(uint8_t *base, uint32_t offset) { -__uint32_a_p_t a = (__uint32_a_p_t)(base+offset); uint32_t rval; - __asm__ __volatile__( - "sync;\n" - "lwbrx %0,0,%1;\n" - "twi 0,%0,0;\n" - "isync" : "=r" (rval) : "r"(a), "m"(*a)); - return rval; + __asm__ __volatile__( + "lwbrx %0,%2,%1; eieio\n" + : "=r" (rval) + : "r"(base), "b"(offset), "m"(*(__uint32_va_t*)(base + offset)) + ); + return rval; } -static inline void __out_le32(uint32_t base, uint32_t offset, uint32_t val) +static inline void __out_le32(uint8_t *base, uint32_t offset, uint32_t val) { -__uint32_a_p_t a = (__uint32_a_p_t)(base+offset); - __asm__ __volatile__( - "sync; stwbrx %1,0,%2" : "=m" (*a) : "r"(val), "r"(a) - ); + __asm__ __volatile__( + "stwbrx %1,%3,%2; eieio" + : "=o"(*(__uint32_va_t*)(base+offset)) + : "r"(val), "r"(base), "b"(offset) + ); } #ifdef _IO_BASE -static inline void __outport_dword(uint32_t base, uint32_t off, uint32_t val) +static inline void __outport_dword(unsigned long base, uint32_t off, uint32_t val) { - __out_le32(_IO_BASE+base+off,0,val); + __out_le32((uint8_t*)(_IO_BASE+base), off, val); } #else #error "_IO_BASE needs to be defined by BSP (bsp.h)" @@ -183,60 +187,38 @@ static inline void __outport_dword(uint32_t base, uint32_t off, uint32_t val) #elif defined(__i386__) #include -static inline uint8_t __in_8(uint32_t base, uint32_t offset) -{ -__uint8_a_p_t a = (__uint8_a_p_t)(base+offset); - return *a; -} - -static inline void __out_8(uint32_t base, uint32_t offset, uint8_t val) -{ -__uint8_a_p_t a = (__uint8_a_p_t)(base+offset); - *a = val; -} -static inline uint16_t __in_le16(uint32_t base, uint32_t offset) +static inline uint16_t __in_le16(uint8_t *base, uint32_t offset) { -__uint16_a_p_t a = (__uint16_a_p_t)(base+offset); - return *a; + return *(__uint16_va_t*)(base + offset); } -static inline void __out_le16(uint32_t base, uint32_t offset, uint16_t val) +static inline void __out_le16(uint8_t *base, uint32_t offset, uint16_t val) { -__uint16_a_p_t a = (__uint16_a_p_t)(base+offset); - *a = val; + *(__uint16_va_t*)(base + offset) = val; } -static inline uint32_t __in_le32(uint32_t base, uint32_t offset) +static inline uint32_t __in_le32(uint8_t *base, uint32_t offset) { -__uint32_a_p_t a = (__uint32_a_p_t)(base+offset); - return *a; + return *(__uint32_va_t*)(base + offset); } -static inline void __out_le32(uint32_t base, uint32_t offset, uint32_t val) +static inline void __out_le32(uint8_t *base, uint32_t offset, uint32_t val) { -__uint32_a_p_t a = (__uint32_a_p_t)(base+offset); - *a = val; + *(__uint32_va_t*)(base + offset) = val; } - -static inline void __outport_dword(uint32_t base, uint32_t off, uint32_t val) +static inline void __outport_dword(unsigned long base, uint32_t off, uint32_t val) { i386_outport_long( (base + off), val ); } #else -#error "not ported to this CPU architecture yet" +#warning "not ported to this CPU architecture yet -- using libbsdport I/O" +#define USE_LIBBSDPORT_IO #endif -#ifdef NO_82542_SUPPORT -#define E1000_REGISTER(hw, reg) reg -#else -#define E1000_REGISTER(hw, reg) (((hw)->mac.type >= e1000_82543) \ - ? reg : e1000_translate_register_82542(reg)) -#endif - -#define E1000_WRITE_FLUSH(a) E1000_READ_REG(a, E1000_STATUS) +#ifdef USE_LIBBSDPORT_IO #define USE_EXPLICIT_BUSTAGS @@ -393,5 +375,52 @@ static inline void __outport_dword(uint32_t base, uint32_t off, uint32_t val) ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg, value) #endif /* USE_EXPLICIT_BUSTAGS */ +#else /* USE_LIBBSDPORT_IO */ + +/* Read from an absolute offset in the adapter's memory space */ +#define E1000_READ_OFFSET(hw, offset) \ + __in_le32((hw)->hw_addr, offset) + +/* Write to an absolute offset in the adapter's memory space */ +#define E1000_WRITE_OFFSET(hw, offset, value) \ + __out_le32((hw)->hw_addr, offset, value) + +/* Register READ/WRITE macros */ + +#define E1000_READ_REG(hw, reg) \ + __in_le32((hw)->hw_addr, E1000_REGISTER(hw, reg)) + +#define E1000_WRITE_REG(hw, reg, value) \ + __out_le32((hw)->hw_addr, E1000_REGISTER(hw, reg), value) + +#define E1000_READ_REG_ARRAY(hw, reg, index) \ + __in_le32((hw)->hw_addr, E1000_REGISTER(hw, reg) + ((index)<< 2)) + +#define E1000_WRITE_REG_ARRAY(hw, reg, index, value) \ + __out_le32((hw)->hw_addr, E1000_REGISTER(hw, reg) + ((index)<< 2), value) + +#define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY +#define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY + +#define E1000_WRITE_REG_IO(hw, reg, value) do { \ + __outport_dword((hw)->io_base, 0, reg); \ + __outport_dword((hw)->io_base, 4, value); \ + } while (0) + +#define E1000_READ_FLASH_REG(hw, reg) \ + __in_le32( (hw)->flash_address, reg ) + +#define E1000_READ_FLASH_REG16(hw, reg) \ + __in_le16( (hw)->flash_address, reg ) + +#define E1000_WRITE_FLASH_REG(hw, reg, value) \ + __out_le32( (hw)->flash_address, reg, value ) + +#define E1000_WRITE_FLASH_REG16(hw, reg, value) \ + __out_le16( (hw)->flash_address, reg, value ) + +#endif /* USE_LIBBSDPORT_IO */ + + #endif /* _FREEBSD_OS_H_ */ diff --git a/bsd_eth_drivers/if_em/if_em.c b/bsd_eth_drivers/if_em/if_em.c index 71d1227..05d4216 100644 --- a/bsd_eth_drivers/if_em/if_em.c +++ b/bsd_eth_drivers/if_em/if_em.c @@ -413,8 +413,6 @@ TUNABLE_INT("hw.em.rx_process_limit", &em_rx_process_limit); #endif #ifdef __rtems__ -int em_bootverbose = 0; -#define bootverbose em_bootverbose #undef static #define static static #endif @@ -2663,7 +2661,11 @@ em_allocate_pci_resources(struct adapter *adapter) rman_get_bustag(adapter->res_memory); adapter->osdep.mem_bus_space_handle = rman_get_bushandle(adapter->res_memory); +#ifndef __rtems__ adapter->hw.hw_addr = (uint8_t*)&adapter->osdep.mem_bus_space_handle; +#else + adapter->hw.hw_addr = (uint8_t*)adapter->res_memory; +#endif /* Only older adapters use IO mapping */ if ((adapter->hw.mac.type >= e1000_82543) && /* __rtems__ >82542 -> >= 82543 */ @@ -2691,7 +2693,12 @@ em_allocate_pci_resources(struct adapter *adapter) "ioport\n"); return (ENXIO); } +#ifndef __rtems__ adapter->hw.io_base = 0; +#else + adapter->hw.io_base = (unsigned long)adapter->res_ioport + & PCI_BASE_ADDRESS_IO_MASK; +#endif adapter->osdep.io_bus_space_tag = rman_get_bustag(adapter->res_ioport); adapter->osdep.io_bus_space_handle = @@ -3281,9 +3288,15 @@ em_initialize_transmit_unit(struct adapter *adapter) E1000_WRITE_REG(&adapter->hw, E1000_TDT, 0); E1000_WRITE_REG(&adapter->hw, E1000_TDH, 0); +#ifndef __rtems__ HW_DEBUGOUT2("Base = %x, Length = %x\n", E1000_READ_REG(&adapter->hw, E1000_TDBAL), E1000_READ_REG(&adapter->hw, E1000_TDLEN)); +#else + HW_DEBUGOUT2("Base = %x, Length = %x\n", + (unsigned)E1000_READ_REG(&adapter->hw, E1000_TDBAL), + (unsigned)E1000_READ_REG(&adapter->hw, E1000_TDLEN)); +#endif /* Set the default values for the Tx Inter Packet Gap timer */ switch (adapter->hw.mac.type) { -- cgit v1.2.3