Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[mii] Add mii_find()
Add the function mii_find() in order to locate the PHY address.

Signed-off-by: Sylvie Barlow <sylvie.c.barlow@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
sylviebarlow authored and mcb30 committed Apr 20, 2018
1 parent 6047b7c commit 7ed1dc9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/drivers/net/mii.c
Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions src/include/ipxe/mii.h
Expand Up @@ -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 */

0 comments on commit 7ed1dc9

Please sign in to comment.