diff options
author | cvs2git <rtems-devel@rtems.org> | 2011-07-21 23:24:55 +0000 |
---|---|---|
committer | cvs2git <rtems-devel@rtems.org> | 2011-07-21 23:24:55 +0000 |
commit | 914cc24b3f44c6de62403d168eb413f469dddc98 (patch) | |
tree | e275210405f24b149e15f00e1912d8d849b63b7f /bsd_eth_drivers/if_em/e1000_osdep.c | |
parent | - importing updated version from SLAC as of 20090422 (diff) | |
download | libbsdport-914cc24b3f44c6de62403d168eb413f469dddc98.tar.bz2 |
This commit was manufactured by cvs2svn to create tagssrlApps_R20110804_p0
'ssrlApps_R20110804_p0'.
Sprout from base 2009-04-22 22:06:58 UTC Till Straumann <strauman@slac.stanford.edu> ' - importing updated version from SLAC as of 20090422'
Cherrypick from master 2011-07-21 23:24:54 UTC Till Straumann <strauman@slac.stanford.edu> '2011-07-21 Till Straumann <Till.Straumann@TU-Berlin.de>':
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.c
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 <strauman@slac.stanford.edu> ' - 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
Diffstat (limited to 'bsd_eth_drivers/if_em/e1000_osdep.c')
-rw-r--r-- | bsd_eth_drivers/if_em/e1000_osdep.c | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/bsd_eth_drivers/if_em/e1000_osdep.c b/bsd_eth_drivers/if_em/e1000_osdep.c new file mode 100644 index 0000000..eec749b --- /dev/null +++ b/bsd_eth_drivers/if_em/e1000_osdep.c @@ -0,0 +1,233 @@ +/************************************************************************** + +Copyright (c) 2001-2007, Intel Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. Neither the name of the Intel Corporation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +***************************************************************************/ + +/* + * NOTE: the following routines using the e1000 + * naming style are provided to the shared + * code which expects that rather than 'em' + */ + +#include <rtems.h> +#include <bsp.h> +#include <rtems/pci.h> +#include <e1000_api.h> +#include <errno.h> +#include <stdlib.h> +#include <time.h> + +#ifndef PCIR_COMMAND +#define PCIR_COMMAND PCI_COMMAND +#endif + +#define PCISIG_INVAL 0xffffffff + +#define PCISIG_MK(b,d,f) ( ((b)<<8) | (((d)&0x1f)<<3) | ((f)&7) ) + +#define PCISIG_BUS(sig) ( ((sig) >> 8) & 0xffffff ) +#define PCISIG_DEV(sig) ( ((sig) >> 3) & 0x1f ) +#define PCISIG_FUN(sig) ( (sig) & 0x07 ) + + +static uint32_t e1k_devs[]={ + PCISIG_INVAL, + PCISIG_INVAL, + PCISIG_INVAL, + PCISIG_INVAL, + PCISIG_INVAL, + PCISIG_INVAL, + PCISIG_INVAL, + PCISIG_INVAL +}; + +#define N_E1K_DEVS (sizeof(e1k_devs)/sizeof(e1k_devs[0])) + +void +e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) +{ +struct e1000_pcisig *s_p = hw->back; +uint32_t s = s_p->sig; + + pci_write_config_word( PCISIG_BUS(s), PCISIG_DEV(s), PCISIG_FUN(s), reg, *value ); +} + +void +e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) +{ +struct e1000_pcisig *s_p = hw->back; +uint32_t s = s_p->sig; + pci_read_config_word( PCISIG_BUS(s), PCISIG_DEV(s), PCISIG_FUN(s), reg, value ); +} + +void +e1000_pci_set_mwi(struct e1000_hw *hw) +{ +uint16_t v = (hw->bus.pci_cmd_word | CMD_MEM_WRT_INVALIDATE); + e1000_write_pci_cfg( hw, PCIR_COMMAND, &v ); +} + +void +e1000_pci_clear_mwi(struct e1000_hw *hw) +{ +uint16_t v = (hw->bus.pci_cmd_word & ~CMD_MEM_WRT_INVALIDATE); + e1000_write_pci_cfg( hw, PCIR_COMMAND, &v ); +} + +/* + * Read the PCI Express capabilities + */ +int32_t +e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) +{ + int32_t error = E1000_SUCCESS; + uint16_t cap_off; + + switch (hw->mac.type) { + + case e1000_82571: + case e1000_82572: + case e1000_82573: + case e1000_80003es2lan: + cap_off = 0xE0; + e1000_read_pci_cfg(hw, cap_off + reg, value); + break; + default: + error = ~E1000_NOT_IMPLEMENTED; + break; + } + + return (error); +} + +int32_t +e1000_alloc_zeroed_dev_spec_struct(struct e1000_hw *hw, uint32_t size) +{ + return (hw->dev_spec = calloc(1, size)) ? 0 : ENOMEM; +} + +void +e1000_free_dev_spec_struct(struct e1000_hw *hw) +{ + free ( hw->dev_spec ); + hw->dev_spec = 0; +} + + +void +e1000_udelay(unsigned usecs) +{ +rtems_interval clock_f, ticks; +uint64_t tmp; +struct timespec then, now; + rtems_clock_get( RTEMS_CLOCK_GET_TICKS_PER_SECOND, &clock_f ); + + /* round up to next tick: + floor( f*T + .5 ) = floor( f*T_us/1e6 + 0.5 ) + = floor( (f * T_us + 5e5) / 1e6 ) + */ + tmp = (uint64_t)clock_f * (uint64_t)usecs; + + if ( tmp < 500000ULL ) { + /* less than half a tick -- busy wait */ + clock_gettime( CLOCK_REALTIME, &then ); + then.tv_sec += usecs/1000000; + then.tv_nsec += (usecs % 1000000)*1000; + if ( then.tv_nsec >= 1000000000 ) { + then.tv_nsec -= 1000000000; + then.tv_sec++; + } + + do { + clock_gettime( CLOCK_REALTIME, &now ); + + } while ( now.tv_sec < then.tv_sec || + (now.tv_sec == then.tv_sec && now.tv_nsec < then.tv_nsec) ); + } else { + tmp += 500000ULL; + tmp /= 1000000ULL; + + ticks = (rtems_interval)tmp; + + rtems_task_wake_after( ticks ); + } +} + +int +e1000_register(struct e1000_pcisig *s_p, unsigned b, unsigned d, unsigned f ) +{ +int i,j,key; +uint32_t sig = PCISIG_MK(b,d,f); + + if ( PCISIG_INVAL == sig ) + return -1; + + j = -1; + + rtems_interrupt_disable(key); + for ( i = 0; i<N_E1K_DEVS; i++ ) { + if ( PCISIG_INVAL == e1k_devs[i] ) { + j = i; + } else if ( sig == e1k_devs[i] ) { + j = -1; + break; + } + } + if ( j >= 0 ) { + e1k_devs[j] = sig; + if ( s_p ) + s_p->sig = sig; + } + rtems_interrupt_enable(key); + + return j < 0; +} + +void +e1000_unregister(struct e1000_pcisig *s_p) +{ +int i,key; +uint32_t sig = s_p ? s_p->sig : PCISIG_INVAL; + + if ( PCISIG_INVAL == sig ) + return; + + rtems_interrupt_disable(key); + for ( i = 0; i<N_E1K_DEVS; i++ ) { + if ( sig == e1k_devs[i] ) { + e1k_devs[i] = PCISIG_INVAL; + if ( s_p ) + s_p->sig = PCISIG_INVAL; + break; + } + } + rtems_interrupt_enable(key); +} |