Subject: Changing the PHY status reporting
To: None <tech-net@netbsd.org>
From: None <joerg@britannica.bec.de>
List: tech-net
Date: 02/18/2006 19:30:10
--82I3+IH0IqGh5yIs
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi all,
attached diff uses if_link_state_change() to send the PHY link changes
and removes mii_phy_statusmsg from public scope. I don't think it makes
sense to export it, since mii_phy_update provides the public information
for this. baudrange changes don't trigger a routing messages, since they
are currently not exported via them anyway.

This makes link state detection work with my wm(4) and many other cards,
it is also a prequirement for CARP. I'd like to commit this ASAP.

Joerg

--82I3+IH0IqGh5yIs
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="mii.diff"

Index: mii_physubr.c
===================================================================
RCS file: /repo/netbsd/src/sys/dev/mii/mii_physubr.c,v
retrieving revision 1.45
diff -u -r1.45 mii_physubr.c
--- mii_physubr.c	11 Dec 2005 12:22:42 -0000	1.45
+++ mii_physubr.c	18 Feb 2006 18:23:59 -0000
@@ -59,6 +59,8 @@
 #include <dev/mii/mii.h>
 #include <dev/mii/miivar.h>
 
+static void mii_phy_statusmsg(struct mii_softc *);
+
 /*
  * Media to register setting conversion table.  Order matters.
  */
@@ -378,58 +380,35 @@
 mii_phy_update(struct mii_softc *sc, int cmd)
 {
 	struct mii_data *mii = sc->mii_pdata;
-	int announce, s;
 
 	if (sc->mii_media_active != mii->mii_media_active ||
 	    sc->mii_media_status != mii->mii_media_status ||
 	    cmd == MII_MEDIACHG) {
-		announce = mii_phy_statusmsg(sc);
+		mii_phy_statusmsg(sc);
 		(*mii->mii_statchg)(sc->mii_dev.dv_parent);
 		sc->mii_media_active = mii->mii_media_active;
 		sc->mii_media_status = mii->mii_media_status;
-
-		if (announce) {
-			s = splnet();
-			rt_ifmsg(mii->mii_ifp);
-			splx(s);
-		}
 	}
 }
 
-int
+static void
 mii_phy_statusmsg(struct mii_softc *sc)
 {
 	struct mii_data *mii = sc->mii_pdata;
 	struct ifnet *ifp = mii->mii_ifp;
-	int link_state, announce = 0;
-	u_int baudrate;
+	int s;
 
+	s = splnet();
 	if (mii->mii_media_status & IFM_AVALID) {
 		if (mii->mii_media_status & IFM_ACTIVE)
-			link_state = LINK_STATE_UP;
+			if_link_state_change(ifp, LINK_STATE_UP);
 		else
-			link_state = LINK_STATE_DOWN;
+			if_link_state_change(ifp, LINK_STATE_DOWN);
 	} else
-		link_state = LINK_STATE_UNKNOWN;
-
-	baudrate = ifmedia_baudrate(mii->mii_media_active);
-
-	if (link_state != ifp->if_link_state) {
-		ifp->if_link_state = link_state;
-		/*
-		 * XXX Right here we'd like to notify protocols
-		 * XXX that the link status has changed, so that
-		 * XXX e.g. Duplicate Address Detection can restart.
-		 */
-		announce = 1;
-	}
-
-	if (baudrate != ifp->if_baudrate) {
-		ifp->if_baudrate = baudrate;
-		announce = 1;
-	}
+		if_link_state_change(ifp, LINK_STATE_UNKNOWN);
+	splx(s);
 
-	return (announce);
+	ifp->if_baudrate = ifmedia_baudrate(mii->mii_media_active);
 }
 
 /*
Index: miivar.h
===================================================================
RCS file: /repo/netbsd/src/sys/dev/mii/miivar.h,v
retrieving revision 1.44
diff -u -r1.44 miivar.h
--- miivar.h	11 Dec 2005 12:22:42 -0000	1.44
+++ miivar.h	16 Feb 2006 23:33:35 -0000
@@ -252,7 +252,6 @@
 
 void	mii_phy_status(struct mii_softc *);
 void	mii_phy_update(struct mii_softc *, int);
-int	mii_phy_statusmsg(struct mii_softc *);
 
 u_int	mii_phy_flowstatus(struct mii_softc *);
 

--82I3+IH0IqGh5yIs--