From 7ed1dc98c325f5d5934fb9806307e0638735304a Mon Sep 17 00:00:00 2001 From: Sylvie Barlow Date: Fri, 20 Apr 2018 13:37:20 +0100 Subject: [mii] Add mii_find() Add the function mii_find() in order to locate the PHY address. Signed-off-by: Sylvie Barlow Signed-off-by: Michael Brown --- src/drivers/net/mii.c | 25 +++++++++++++++++++++++++ src/include/ipxe/mii.h | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/src/drivers/net/mii.c b/src/drivers/net/mii.c index f6db3074..87605f0c 100644 --- a/src/drivers/net/mii.c +++ b/src/drivers/net/mii.c @@ -147,3 +147,28 @@ int mii_check_link ( struct mii_device *mii, struct net_device *netdev ) { return 0; } + +/** + * Find PHY address + * + * @v mii MII device + * @ret rc Return status code + */ +int mii_find ( struct mii_device *mii ) { + unsigned int address; + int id; + + /* Try all possible PHY addresses */ + for ( address = 0 ; address <= MII_MAX_PHY_ADDRESS ; address++ ) { + mii->address = address; + id = mii_read ( mii, MII_PHYSID1 ); + if ( ( id > 0x0000 ) && ( id < 0xffff ) ) { + DBGC ( mii, "MII %p found PHY at address %d\n", + mii, address ); + return 0; + } + } + + DBGC ( mii, "MII %p failed to find an address\n", mii ); + return -ENOENT; +} diff --git a/src/include/ipxe/mii.h b/src/include/ipxe/mii.h index aaeae3db..89fc92a4 100644 --- a/src/include/ipxe/mii.h +++ b/src/include/ipxe/mii.h @@ -141,9 +141,13 @@ mii_dump ( struct mii_device *mii ) { /** Maximum time to wait for a reset, in milliseconds */ #define MII_RESET_MAX_WAIT_MS 500 +/** Maximum PHY address */ +#define MII_MAX_PHY_ADDRESS 31 + extern int mii_restart ( struct mii_device *mii ); extern int mii_reset ( struct mii_device *mii ); extern int mii_check_link ( struct mii_device *mii, struct net_device *netdev ); +extern int mii_find ( struct mii_device *mii ); #endif /* _IPXE_MII_H */ -- cgit v1.2.3-55-g7522