|
@@ -115,3 +115,35 @@ int mii_reset ( struct mii_interface *mii ) {
|
115
|
115
|
DBGC ( mii, "MII %p timed out waiting for reset\n", mii );
|
116
|
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
|
+}
|