summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Straumann <strauman@slac.stanford.edu>2009-08-05 21:41:20 +0000
committerTill Straumann <strauman@slac.stanford.edu>2009-08-05 21:41:20 +0000
commit370f3c5469cbc626113a3a53dde09bb86d50d788 (patch)
treeaf0c4f64be1c85bc4b01608f55737f9eeb28fb1c
parentc47c1f8277459394ac017ec34ac51f0198ebe9b9 (diff)
downloadlibbsdport-370f3c5469cbc626113a3a53dde09bb86d50d788.tar.bz2
2009-08-05 Till Straumann <Till.Straumann@TU-Berlin.de>
* if_em/Makefile.am, if_em/e1000_osdep.h, if_em/if_em.c: Changed 'e1000_osdep.h' to provide stdalone I/O methods for select architectures (x86 and PPC -- others fall back on libbsdport/bus.h). This lets the low-level driver (everything except for 'if_em.c/if_em.h') API be independent of BSD networking and libbsdport which is desirable since certain applications may wish to just use the low-level API for implementing dedicated 'raw-ethernet' drivers for BSD-independent, proprietary GigE communication.
-rw-r--r--bsd_eth_drivers/ChangeLog12
-rw-r--r--bsd_eth_drivers/if_em/Makefile.am1
-rw-r--r--bsd_eth_drivers/if_em/e1000_osdep.h223
-rw-r--r--bsd_eth_drivers/if_em/if_em.c15
4 files changed, 152 insertions, 99 deletions
diff --git a/bsd_eth_drivers/ChangeLog b/bsd_eth_drivers/ChangeLog
index b8ad81f..18bfe6f 100644
--- a/bsd_eth_drivers/ChangeLog
+++ b/bsd_eth_drivers/ChangeLog
@@ -1,5 +1,17 @@
2009-08-05 Till Straumann <Till.Straumann@TU-Berlin.de>
+ * if_em/Makefile.am, if_em/e1000_osdep.h, if_em/if_em.c:
+ Changed 'e1000_osdep.h' to provide stdalone I/O methods for
+ select architectures (x86 and PPC -- others fall back on
+ libbsdport/bus.h). This lets the low-level driver (everything
+ except for 'if_em.c/if_em.h') API be independent of
+ BSD networking and libbsdport which is desirable since
+ certain applications may wish to just use the low-level
+ API for implementing dedicated 'raw-ethernet' drivers
+ for BSD-independent, proprietary GigE communication.
+
+2009-08-05 Till Straumann <Till.Straumann@TU-Berlin.de>
+
* libbsdport/alldrv.c: reactivate weak aliases for all
known/supported drivers. This magic allows the user to
just link the desired (sub-)set of drivers.
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..6817e36 100644
--- a/bsd_eth_drivers/if_em/e1000_osdep.h
+++ b/bsd_eth_drivers/if_em/e1000_osdep.h
@@ -37,9 +37,12 @@ POSSIBILITY OF SUCH DAMAGE.
#define _FREEBSD_OS_H_
#include <rtems.h>
-#define _KERNEL
-#include <rtems/rtems_bsdnet_internal.h>
#include <bsp.h>
+#include <rtems/pci.h>
+#include <vm/vm.h> /* for non-_KERNEL boolean_t :-( */
+
+#ifdef _KERNEL
+#include <rtems/rtems_bsdnet_internal.h>
#include <sys/types.h>
#include <sys/param.h>
@@ -50,7 +53,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/bus.h>
-#include <rtems/pci.h>
#define ASSERT(x) if(!(x)) panic("EM: x")
@@ -69,13 +71,30 @@ POSSIBILITY OF SUCH DAMAGE.
#define DEBUGOUT3(S,A,B,C)
#define DEBUGOUT7(S,A,B,C,D,E,F,G)
+#include <devicet.h>
+
+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 +111,71 @@ typedef int32_t s32;
typedef int16_t s16;
typedef int8_t s8 ;
-#include <devicet.h>
+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 <libcpu/io.h>
-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 <libcpu/io.h>
-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 __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 __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 +183,38 @@ static inline void __outport_dword(uint32_t base, uint32_t off, uint32_t val)
#elif defined(__i386__)
#include <libcpu/cpu.h>
-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 +371,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 449ef5b..05d4216 100644
--- a/bsd_eth_drivers/if_em/if_em.c
+++ b/bsd_eth_drivers/if_em/if_em.c
@@ -2661,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 */
@@ -2689,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 =
@@ -3279,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) {