]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[mii] Add mii_find()
authorSylvie Barlow <sylvie.c.barlow@gmail.com>
Fri, 20 Apr 2018 12:37:20 +0000 (13:37 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 20 Apr 2018 14:21:32 +0000 (15:21 +0100)
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>
src/drivers/net/mii.c
src/include/ipxe/mii.h

index f6db307409a1be5afd1efadf63f42aee9306c465..87605f0cb8cf301cd081fb40e25e1cc3c459264b 100644 (file)
@@ -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;
+}
index aaeae3db5ae21ae965032f659763200a522cf2ec..89fc92a4af4ce349d8ac45993909a51decb2854b 100644 (file)
@@ -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 */