diff options
author | Till Straumann <strauman@slac.stanford.edu> | 2009-04-23 04:21:10 +0000 |
---|---|---|
committer | Till Straumann <strauman@slac.stanford.edu> | 2009-04-23 04:21:10 +0000 |
commit | 7d9bd41111430c047b7a751ce6163d92afa9228a (patch) | |
tree | a139f4510ef47df56d7f04dbf07f0b96013a4c1d /bsd_eth_drivers/libbsdport/miistuff.c | |
parent | - reverted AC_PREREQ to 2.62 (diff) | |
download | libbsdport-7d9bd41111430c047b7a751ce6163d92afa9228a.tar.bz2 |
- added 'bootverbose' (in new 'misc.c' file)
- added rtems_mii_phy_probe(). This is a helper albeit RTEMS specific.
Porting the whole MII/media stuff is still too much ATM.
Diffstat (limited to 'bsd_eth_drivers/libbsdport/miistuff.c')
-rw-r--r-- | bsd_eth_drivers/libbsdport/miistuff.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/bsd_eth_drivers/libbsdport/miistuff.c b/bsd_eth_drivers/libbsdport/miistuff.c new file mode 100644 index 0000000..b15545f --- /dev/null +++ b/bsd_eth_drivers/libbsdport/miistuff.c @@ -0,0 +1,58 @@ +#include <rtems.h> +#define _KERNEL +#include <rtems/rtems_bsdnet.h> +#include <rtems/rtems_bsdnet_internal.h> + +#include <bsp/rtems_verscheck.h> + +#include <sys/malloc.h> +#include <sys/errno.h> +#include <sys/socket.h> +#include <sys/sockio.h> +#include <net/if.h> +#include <net/if_media.h> +#include <rtems/rtems_mii_ioctl.h> + +#define PHY_MAX 32 + +#undef DEBUG + +/* A helper to find the active PHY. We really should port + * the entire BSD miibus/phy support but that's a bigger + * project... + */ +int +rtems_mii_phy_probe(struct rtems_mdio_info *mdio, void *softc) +{ +int phy; +uint32_t bmsr, bmcr; + for ( phy = 0; phy<PHY_MAX; phy++ ) { + if ( mdio->mdio_r(phy, softc, MII_BMSR, &bmsr) ) + continue; + + bmsr &= 0xffff; + + if ( 0 == bmsr || 0xffff == bmsr ) + continue; /* nothing here */ + + /* no media supported ? */ + if ( 0 == ((BMSR_EXTSTAT | 0xfe00) & bmsr ) ) + continue; /* probably nothing there */ + + if ( mdio->mdio_r(phy, softc, MII_BMCR, &bmcr) ) + continue; + + /* skip isolated or powered-down phys */ + if ( (BMCR_PDOWN | BMCR_ISO) & bmcr ) + continue; + +#ifdef DEBUG + printk("PHY #%u seems active; link status is %s\n", phy, BMSR_LINK & bmsr ? "UP" : "DOWN"); +#endif + + /* seems we found one */ + return phy; + } + + return -1; +} |