[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree

zrouter-src-freebsd at zrouter.org zrouter-src-freebsd at zrouter.org
Sat Dec 31 19:10:08 UTC 2011


details:   http://zrouter.org/hg/FreeBSD/head//rev/bb94474c6eb7
changeset: 253:bb94474c6eb7
user:      ray at terran.dlink.ua
date:      Sat Dec 31 21:05:14 2011 +0200
description:
Fix MDIO attach.

diffstat:

 head/sys/dev/switch/switch_mii.c |  118 +++++++++++++-------------------------
 1 files changed, 42 insertions(+), 76 deletions(-)

diffs (245 lines):

diff -r e18f0d992039 -r bb94474c6eb7 head/sys/dev/switch/switch_mii.c
--- a/head/sys/dev/switch/switch_mii.c	Thu Dec 15 15:08:34 2011 +0200
+++ b/head/sys/dev/switch/switch_mii.c	Sat Dec 31 21:05:14 2011 +0200
@@ -106,23 +106,18 @@
 switch_mii_probe(device_t dev)
 {
 
-	/*
-	 * switch_mii have problems with autodeteaction, so attached
-	 * dirrectly ny hint. Return just BUS_PROBE_GENERIC, so some more
-	 * specific device will have a chance if concurrent.
-	 */
-	return (BUS_PROBE_GENERIC);
+	return (BUS_PROBE_NOWILDCARD);
 }
 
+
 static int
 switch_mii_attach(device_t dev)
 {
 	struct mii_softc *sc;
 	struct switch_mii_softc *ssc;
-	device_t *devlist;
-	int phymask, devs, i, err;
 	struct mii_attach_args	*ma;
 	struct mii_data		*mii;
+	int phymask, err;
 
 	phymask = 1; /* 1 is PHY0, PHY0 is me */
 	ssc = device_get_softc(dev);
@@ -131,7 +126,6 @@
 	mii = device_get_softc(ssc->sc_miidev);
 	sc = &ssc->sc_mii;
 
-
 	ifmedia_add(&mii->mii_media,
 	    IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, 0, sc->mii_inst),
 	    MII_MEDIA_100_TX, NULL);
@@ -144,7 +138,6 @@
 	ifmedia_add(&mii->mii_media,
 	    IFM_MAKEWORD(IFM_ETHER, IFM_1000_T, 0, sc->mii_inst),
 	    MII_MEDIA_1000_T_FDX, NULL);
-
 	ifmedia_add(&mii->mii_media,
 	    IFM_MAKEWORD(IFM_ETHER, IFM_1000_SX, 0, sc->mii_inst),
 	    MII_MEDIA_1000_X, NULL);
@@ -152,7 +145,6 @@
 	    IFM_MAKEWORD(IFM_ETHER, IFM_1000_SX, 0, sc->mii_inst),
 	    MII_MEDIA_1000_X_FDX, NULL);
 
-
 	mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
 	    &switch_mii_funcs, 0);
 
@@ -167,20 +159,9 @@
 	mii_phy_add_media(sc);
 	printf("\n");
 
-	if (device_get_children(ssc->sc_miidev, &devlist, &devs) == 0) {
-		for (i = 0; i < devs; i++) {
-			if (devlist[i] != dev) {
-				ma = device_get_ivars(devlist[i]);
-				phymask |= (1 << ma->mii_phyno);
-			}
-		}
-		free(devlist, M_TEMP);
-	}
-	if (bootverbose)
-		device_printf(dev, "phymask of attached PHYs 0x%08x\n", phymask);
-
 	ssc->sc_switch.sc_dev = dev;
-	ssc->sc_switch.phys = phymask;
+	/* Satisfy all MDIO attached switch drivers */
+	ssc->sc_switch.phys = 0xffffffff;
 	SWITCH_LOCK_INIT(&ssc->sc_switch);
 	err = switch_init(&ssc->sc_switch);
 	if (err)
@@ -214,7 +195,7 @@
 		case IFM_AUTO:
 			mii->mii_media_status = IFM_AVALID | IFM_ACTIVE;
 			mii->mii_media_active = IFM_ETHER | IFM_1000_T |
-			    (ife->ifm_media & IFM_FDX)?IFM_FDX:IFM_HDX;
+			    IFM_FDX;
 			break;
 		case IFM_1000_T:
 			mii->mii_media_status = IFM_AVALID | IFM_ACTIVE;
@@ -235,7 +216,7 @@
 			/* XXX */
 			mii->mii_media_status = IFM_AVALID;
 			mii->mii_media_active = IFM_ETHER | IFM_1000_T |
-			    (ife->ifm_media & IFM_FDX)?IFM_FDX:IFM_HDX;
+			    IFM_FDX;
 			break;
 		default:
 			return (EINVAL);
@@ -301,61 +282,58 @@
 	MIIBUS_WRITEREG(ssc->sc_miidev, phy, reg, (val & 0xffff));
 }
 
+/*
+ * Float PHY satellite driver, used for devices that have PHY but can't
+ * communicate directly to it
+ */
 
+static int 	floatphy_probe(device_t dev);
+static int 	floatphy_attach(device_t dev);
 
-
-static int 	plumbphy_probe(device_t dev);
-static int 	plumbphy_attach(device_t dev);
-
-static device_method_t plumbphy_methods[] = {
+static device_method_t floatphy_methods[] = {
 	/* device interface */
-	DEVMETHOD(device_probe,		plumbphy_probe),
-	DEVMETHOD(device_attach,	plumbphy_attach),
+	DEVMETHOD(device_probe,		floatphy_probe),
+	DEVMETHOD(device_attach,	floatphy_attach),
 	DEVMETHOD(device_detach,	mii_phy_detach),
 	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
 	{ 0, 0 }
 };
 
-static devclass_t plumbphy_devclass;
+static devclass_t floatphy_devclass;
 
-static driver_t plumbphy_driver = {
-	"plumbphy",
-	plumbphy_methods,
+static driver_t floatphy_driver = {
+	"floatphy",
+	floatphy_methods,
 	sizeof(struct mii_softc)
 };
 
-DRIVER_MODULE(plumbphy, miibus, plumbphy_driver, plumbphy_devclass, 0, 0);
+DRIVER_MODULE(floatphy, miibus, floatphy_driver, floatphy_devclass, 0, 0);
+DRIVER_MODULE(floatphy, mii, floatphy_driver, floatphy_devclass, 0, 0);
 
-static int	plumbphy_service(struct mii_softc *, struct mii_data *, int);
-static void	plumbphy_status(struct mii_softc *);
+static int	floatphy_service(struct mii_softc *, struct mii_data *, int);
+static void	floatphy_status(struct mii_softc *);
 
 
-static const struct mii_phy_funcs plumbphy_funcs = {
-	plumbphy_service,
-	plumbphy_status,
+static const struct mii_phy_funcs floatphy_funcs = {
+	floatphy_service,
+	floatphy_status,
 	mii_phy_reset
 };
 
-static const struct mii_phydesc plumbphyid[] = {
-	MII_PHY_DESC(SWITCHFW, PSEUDO),
-	MII_PHY_END
-};
+static int
+floatphy_probe(device_t dev)
+{
 
-static int
-plumbphy_probe(device_t dev)
-{
-	return (mii_phy_dev_probe(dev, plumbphyid, BUS_PROBE_DEFAULT));
+	return (BUS_PROBE_NOWILDCARD);
 }
 
 static int
-plumbphy_attach(device_t dev)
+floatphy_attach(device_t dev)
 {
-	struct mii_attach_args	*ma;
 	struct mii_softc *sc;
 
 	sc = device_get_softc(dev);
-	ma = device_get_ivars(dev);
-	mii_phy_dev_attach(dev, 0, &plumbphy_funcs, 0);
+	mii_phy_dev_attach(dev, 0, &floatphy_funcs, 0);
 	sc->mii_capabilities = BMSR_100TXFDX | BMSR_100TXHDX | BMSR_EXTCAP;
 	sc->mii_extcapabilities = EXTSR_1000TFDX | EXTSR_1000THDX |
 	    EXTSR_1000XFDX | EXTSR_1000XHDX;
@@ -364,17 +342,18 @@
 	mii_phy_add_media(sc);
 	printf("\n");
 
-
+	MIIBUS_MEDIAINIT(sc->mii_dev);
 	return (0);
 }
 
 static int
-plumbphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
+floatphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
 {
 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
 
 	switch (cmd) {
 	case MII_POLLSTAT:
+		break;
 	case MII_MEDIACHG:
 		switch (IFM_SUBTYPE(ife->ifm_media)) {
 		case IFM_AUTO:
@@ -384,7 +363,8 @@
 			break;
 		case IFM_NONE:
 			mii->mii_media_status = IFM_AVALID;
-			mii->mii_media_active = IFM_ETHER;
+			mii->mii_media_active = IFM_ETHER |
+			    IFM_SUBTYPE(ife->ifm_media) | IFM_FDX;
 			break;
 		default:
 			mii->mii_media_status = IFM_AVALID | IFM_ACTIVE;
@@ -410,26 +390,12 @@
 }
 
 static void
-plumbphy_status(struct mii_softc *sc)
+floatphy_status(struct mii_softc *sc)
 {
 	struct mii_data *mii = sc->mii_pdata;
-	device_t switch_drv, switchdev;
+	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
 
-	/* Use hint hint.plumbphy.0.master="ar8x16_switch0" */
-	/* XXX */
-	switch_drv = devclass_get_device(devclass_find("ar8x16_switch"), 0);
-	if (switch_drv) {
-		switchdev = device_get_parent(switch_drv);
-		if (switchdev) {
-			printf("%s: found master %s at %s\n", __func__,
-			    device_get_nameunit(switchdev),
-			    device_get_nameunit(switch_drv));
-			/* TODO: Ask PHY driver and return here */
-		}
-	}
-
-	mii->mii_media_status = IFM_AVALID;
-	mii->mii_media_active = IFM_ETHER|IFM_100_TX|IFM_FDX;
-
+	mii->mii_media_status = IFM_AVALID | IFM_ACTIVE;
+	mii->mii_media_active = ife->ifm_media;
 }
 


More information about the Zrouter-src-freebsd mailing list