Pārlūkot izejas kodu

[mii] Add generic mii_check_link() function

Most devices expose at least the link up/down status via a bit in a
MAC register, since the MAC generally already needs to know whether or
not the link is up.  Some devices (e.g. the SMSC75xx USB NIC) expose
this information to software only via the MII registers.

Provide a generic mii_check_link() implementation to check the BMSR
and report the link status via netdev_link_{up,down}().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 gadus atpakaļ
vecāks
revīzija
6ad02e78bb
2 mainītis faili ar 34 papildinājumiem un 0 dzēšanām
  1. 32
    0
      src/drivers/net/mii.c
  2. 2
    0
      src/include/ipxe/mii.h

+ 32
- 0
src/drivers/net/mii.c Parādīt failu

115
 	DBGC ( mii, "MII %p timed out waiting for reset\n", mii );
115
 	DBGC ( mii, "MII %p timed out waiting for reset\n", mii );
116
 	return -ETIMEDOUT;
116
 	return -ETIMEDOUT;
117
 }
117
 }
118
+
119
+/**
120
+ * Update link status via MII
121
+ *
122
+ * @v mii		MII interface
123
+ * @v netdev		Network device
124
+ * @ret rc		Return status code
125
+ */
126
+int mii_check_link ( struct mii_interface *mii, struct net_device *netdev ) {
127
+	int bmsr;
128
+	int link;
129
+	int rc;
130
+
131
+	/* Read BMSR */
132
+	bmsr = mii_read ( mii, MII_BMSR );
133
+	if ( bmsr < 0 ) {
134
+		rc = bmsr;
135
+		return rc;
136
+	}
137
+
138
+	/* Report link status */
139
+	link = ( bmsr & BMSR_LSTATUS );
140
+	DBGC ( mii, "MII %p link %s (BMSR %#04x)\n",
141
+	       mii, ( link ? "up" : "down" ), bmsr );
142
+	if ( link ) {
143
+		netdev_link_up ( netdev );
144
+	} else {
145
+		netdev_link_down ( netdev );
146
+	}
147
+
148
+	return 0;
149
+}

+ 2
- 0
src/include/ipxe/mii.h Parādīt failu

114
 
114
 
115
 extern int mii_restart ( struct mii_interface *mii );
115
 extern int mii_restart ( struct mii_interface *mii );
116
 extern int mii_reset ( struct mii_interface *mii );
116
 extern int mii_reset ( struct mii_interface *mii );
117
+extern int mii_check_link ( struct mii_interface *mii,
118
+			    struct net_device *netdev );
117
 
119
 
118
 #endif /* _IPXE_MII_H */
120
 #endif /* _IPXE_MII_H */

Notiek ielāde…
Atcelt
Saglabāt