Browse Source

[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>
tags/v1.20.1
Sylvie Barlow 6 years ago
parent
commit
7ed1dc98c3
2 changed files with 29 additions and 0 deletions
  1. 25
    0
      src/drivers/net/mii.c
  2. 4
    0
      src/include/ipxe/mii.h

+ 25
- 0
src/drivers/net/mii.c View File

@@ -147,3 +147,28 @@ int mii_check_link ( struct mii_device *mii, struct net_device *netdev ) {
147 147
 
148 148
 	return 0;
149 149
 }
150
+
151
+/**
152
+ * Find PHY address
153
+ *
154
+ * @v mii		MII device
155
+ * @ret rc		Return status code
156
+ */
157
+int mii_find ( struct mii_device *mii ) {
158
+	unsigned int address;
159
+	int id;
160
+
161
+	/* Try all possible PHY addresses */
162
+	for ( address = 0 ; address <= MII_MAX_PHY_ADDRESS ; address++ ) {
163
+		mii->address = address;
164
+		id = mii_read ( mii, MII_PHYSID1 );
165
+		if ( ( id > 0x0000 ) && ( id < 0xffff ) ) {
166
+			DBGC ( mii, "MII %p found PHY at address %d\n",
167
+			       mii, address );
168
+			return 0;
169
+		}
170
+	}
171
+
172
+	DBGC ( mii, "MII %p failed to find an address\n", mii );
173
+	return -ENOENT;
174
+}

+ 4
- 0
src/include/ipxe/mii.h View File

@@ -141,9 +141,13 @@ mii_dump ( struct mii_device *mii ) {
141 141
 /** Maximum time to wait for a reset, in milliseconds */
142 142
 #define MII_RESET_MAX_WAIT_MS 500
143 143
 
144
+/** Maximum PHY address */
145
+#define MII_MAX_PHY_ADDRESS 31
146
+
144 147
 extern int mii_restart ( struct mii_device *mii );
145 148
 extern int mii_reset ( struct mii_device *mii );
146 149
 extern int mii_check_link ( struct mii_device *mii,
147 150
 			    struct net_device *netdev );
151
+extern int mii_find ( struct mii_device *mii );
148 152
 
149 153
 #endif /* _IPXE_MII_H */

Loading…
Cancel
Save