Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Jan 2015 22:27:39 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r277093 - head/sys/dev/mii
Message-ID:  <201501122227.t0CMRdKA073432@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Mon Jan 12 22:27:38 2015
New Revision: 277093
URL: https://svnweb.freebsd.org/changeset/base/277093

Log:
  In miibus(4) drivers provide functions that allow to get NIC
  driver name and NIC driver softc via the device(9) tree,
  instead of going dirty through the ifnet(9) layer.
  
  Differential Revision:	D1506
  Reviewed by:		imp, jhb

Modified:
  head/sys/dev/mii/brgphy.c
  head/sys/dev/mii/ciphy.c
  head/sys/dev/mii/e1000phy.c
  head/sys/dev/mii/ip1000phy.c
  head/sys/dev/mii/jmphy.c
  head/sys/dev/mii/mii.c
  head/sys/dev/mii/miivar.h
  head/sys/dev/mii/mlphy.c
  head/sys/dev/mii/nsphy.c
  head/sys/dev/mii/rgephy.c
  head/sys/dev/mii/rlphy.c
  head/sys/dev/mii/tlphy.c

Modified: head/sys/dev/mii/brgphy.c
==============================================================================
--- head/sys/dev/mii/brgphy.c	Mon Jan 12 21:55:48 2015	(r277092)
+++ head/sys/dev/mii/brgphy.c	Mon Jan 12 22:27:38 2015	(r277093)
@@ -198,7 +198,6 @@ brgphy_attach(device_t dev)
 	struct bge_softc *bge_sc = NULL;
 	struct bce_softc *bce_sc = NULL;
 	struct mii_softc *sc;
-	if_t ifp;
 
 	bsc = device_get_softc(dev);
 	sc = &bsc->mii_sc;
@@ -207,13 +206,12 @@ brgphy_attach(device_t dev)
 	    &brgphy_funcs, 0);
 
 	bsc->serdes_flags = 0;
-	ifp = sc->mii_pdata->mii_ifp;
 
 	/* Find the MAC driver associated with this PHY. */
-	if (strcmp(if_getdname(ifp), "bge") == 0)
-		bge_sc = if_getsoftc(ifp);
-	else if (strcmp(if_getdname(ifp), "bce") == 0)
-		bce_sc = if_getsoftc(ifp);
+	if (mii_dev_mac_match(dev, "bge"))
+		bge_sc = mii_dev_mac_softc(dev);
+	else if (mii_dev_mac_match(dev, "bce"))
+		bce_sc = mii_dev_mac_softc(dev);
 
 	/* Handle any special cases based on the PHY ID */
 	switch (sc->mii_mpd_oui) {
@@ -933,11 +931,10 @@ brgphy_reset(struct mii_softc *sc)
 	ifp = sc->mii_pdata->mii_ifp;
 
 	/* Find the driver associated with this PHY. */
-	if (strcmp(if_getdname(ifp), "bge") == 0)	{
-		bge_sc = if_getsoftc(ifp);
-	} else if (strcmp(if_getdname(ifp), "bce") == 0) {
-		bce_sc = if_getsoftc(ifp);
-	}
+	if (mii_phy_mac_match(sc, "bge"))
+		bge_sc = mii_phy_mac_softc(sc);
+	else if (mii_phy_mac_match(sc, "bce"))
+		bce_sc = mii_phy_mac_softc(sc);
 
 	if (bge_sc) {
 		/* Fix up various bugs */

Modified: head/sys/dev/mii/ciphy.c
==============================================================================
--- head/sys/dev/mii/ciphy.c	Mon Jan 12 21:55:48 2015	(r277092)
+++ head/sys/dev/mii/ciphy.c	Mon Jan 12 22:27:38 2015	(r277093)
@@ -303,8 +303,7 @@ ciphy_fixup(struct mii_softc *sc)
 	status = PHY_READ(sc, CIPHY_MII_AUXCSR);
 	speed = status & CIPHY_AUXCSR_SPEED;
 
-	if (strcmp(device_get_name(device_get_parent(sc->mii_dev)),
-	    "nfe") == 0) {
+	if (mii_phy_mac_match(sc, "nfe")) {
 		/* need to set for 2.5V RGMII for NVIDIA adapters */
 		val = PHY_READ(sc, CIPHY_MII_ECTL1);
 		val &= ~(CIPHY_ECTL1_IOVOL | CIPHY_ECTL1_INTSEL);

Modified: head/sys/dev/mii/e1000phy.c
==============================================================================
--- head/sys/dev/mii/e1000phy.c	Mon Jan 12 21:55:48 2015	(r277092)
+++ head/sys/dev/mii/e1000phy.c	Mon Jan 12 22:27:38 2015	(r277093)
@@ -139,8 +139,7 @@ e1000phy_attach(device_t dev)
 	mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &e1000phy_funcs, 0);
 
 	ifp = sc->mii_pdata->mii_ifp;
-	if (strcmp(if_getdname(ifp), "msk") == 0 &&
-	    (sc->mii_flags & MIIF_MACPRIV0) != 0)
+	if (mii_dev_mac_match(dev, "msk") && (sc->mii_flags & MIIF_MACPRIV0) != 0)
 		sc->mii_flags |= MIIF_PHYPRIV0;
 
 	switch (sc->mii_mpd_model) {

Modified: head/sys/dev/mii/ip1000phy.c
==============================================================================
--- head/sys/dev/mii/ip1000phy.c	Mon Jan 12 21:55:48 2015	(r277092)
+++ head/sys/dev/mii/ip1000phy.c	Mon Jan 12 22:27:38 2015	(r277093)
@@ -110,7 +110,7 @@ ip1000phy_attach(device_t dev)
 	ma = device_get_ivars(dev);
 	flags = MIIF_NOISOLATE | MIIF_NOMANPAUSE;
 	if (MII_MODEL(ma->mii_id2) == MII_MODEL_xxICPLUS_IP1000A &&
-	     strcmp(if_getdname(ma->mii_data->mii_ifp), "stge") == 0 &&
+	     mii_dev_mac_match(dev, "stge") &&
 	     (miibus_get_flags(dev) & MIIF_MACPRIV0) != 0)
 		flags |= MIIF_PHYPRIV0;
 	mii_phy_dev_attach(dev, flags, &ip1000phy_funcs, 1);

Modified: head/sys/dev/mii/jmphy.c
==============================================================================
--- head/sys/dev/mii/jmphy.c	Mon Jan 12 21:55:48 2015	(r277092)
+++ head/sys/dev/mii/jmphy.c	Mon Jan 12 22:27:38 2015	(r277093)
@@ -105,7 +105,7 @@ jmphy_attach(device_t dev)
 
 	ma = device_get_ivars(dev);
 	flags = 0;
-	if (strcmp(if_getdname(ma->mii_data->mii_ifp), "jme") == 0 &&
+	if (mii_dev_mac_match(dev, "jme") &&
 	    (miibus_get_flags(dev) & MIIF_MACPRIV0) != 0)
 		flags |= MIIF_PHYPRIV0;
 	mii_phy_dev_attach(dev, flags, &jmphy_funcs, 1);

Modified: head/sys/dev/mii/mii.c
==============================================================================
--- head/sys/dev/mii/mii.c	Mon Jan 12 21:55:48 2015	(r277092)
+++ head/sys/dev/mii/mii.c	Mon Jan 12 22:27:38 2015	(r277093)
@@ -645,3 +645,33 @@ mii_oui(u_int id1, u_int id2)
 	    (mii_bitreverse((h >> 8) & 0xff) << 8) |
 	    mii_bitreverse(h & 0xff));
 }
+
+int
+mii_phy_mac_match(struct mii_softc *mii, const char *name)
+{
+
+	return (strcmp(device_get_name(device_get_parent(mii->mii_dev)),
+	    name) == 0);
+}
+
+int
+mii_dev_mac_match(device_t parent, const char *name)
+{
+
+	return (strcmp(device_get_name(device_get_parent(
+	    device_get_parent(parent))), name) == 0);
+}
+
+void *
+mii_phy_mac_softc(struct mii_softc *mii)
+{
+
+	return (device_get_softc(device_get_parent(mii->mii_dev)));
+}
+
+void *
+mii_dev_mac_softc(device_t parent)
+{
+
+	return (device_get_softc(device_get_parent(device_get_parent(parent))));
+}

Modified: head/sys/dev/mii/miivar.h
==============================================================================
--- head/sys/dev/mii/miivar.h	Mon Jan 12 21:55:48 2015	(r277092)
+++ head/sys/dev/mii/miivar.h	Mon Jan 12 22:27:38 2015	(r277093)
@@ -263,6 +263,10 @@ void	mii_phy_reset(struct mii_softc *);
 void	mii_phy_setmedia(struct mii_softc *sc);
 void	mii_phy_update(struct mii_softc *, int);
 int	mii_phy_tick(struct mii_softc *);
+int	mii_phy_mac_match(struct mii_softc *, const char *);
+int	mii_dev_mac_match(device_t, const char *);
+void	*mii_phy_mac_softc(struct mii_softc *);
+void	*mii_dev_mac_softc(device_t);
 
 const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma,
     const struct mii_phydesc *mpd);

Modified: head/sys/dev/mii/mlphy.c
==============================================================================
--- head/sys/dev/mii/mlphy.c	Mon Jan 12 21:55:48 2015	(r277092)
+++ head/sys/dev/mii/mlphy.c	Mon Jan 12 22:27:38 2015	(r277093)
@@ -128,8 +128,7 @@ mlphy_probe(dev)
 	 * encountered the 6692 on an Olicom card with a ThunderLAN
 	 * controller chip.
 	 */
-	if (strcmp(device_get_name(device_get_parent(device_get_parent(dev))),
-	    "tl") != 0)
+	if (!mii_dev_mac_match(dev, "tl"))
 		return (ENXIO);
 
 	device_set_desc(dev, "Micro Linear 6692 media interface");

Modified: head/sys/dev/mii/nsphy.c
==============================================================================
--- head/sys/dev/mii/nsphy.c	Mon Jan 12 21:55:48 2015	(r277092)
+++ head/sys/dev/mii/nsphy.c	Mon Jan 12 22:27:38 2015	(r277093)
@@ -129,15 +129,13 @@ nsphy_probe(device_t dev)
 static int
 nsphy_attach(device_t dev)
 {
-	const char *nic;
 	u_int flags;
 
-	nic = device_get_name(device_get_parent(device_get_parent(dev)));
 	flags = MIIF_NOMANPAUSE;
 	/*
 	 * Am79C971 wedge when isolating all of their external PHYs.
 	 */
-	if (strcmp(nic, "pcn") == 0)
+	if (mii_dev_mac_match(dev,"pcn"))
 		flags |= MIIF_NOISOLATE;
 	mii_phy_dev_attach(dev, flags, &nsphy_funcs, 1);
 	return (0);
@@ -186,7 +184,7 @@ nsphy_service(struct mii_softc *sc, stru
 		 */
 		reg |= 0x0100 | 0x0400;
 
-		if (strcmp(if_getdname(mii->mii_ifp), "fxp") == 0)
+		if (mii_phy_mac_match(sc, "fxp"))
 			PHY_WRITE(sc, MII_NSPHY_PCR, reg);
 
 		mii_phy_setmedia(sc);

Modified: head/sys/dev/mii/rgephy.c
==============================================================================
--- head/sys/dev/mii/rgephy.c	Mon Jan 12 21:55:48 2015	(r277092)
+++ head/sys/dev/mii/rgephy.c	Mon Jan 12 22:27:38 2015	(r277093)
@@ -119,7 +119,7 @@ rgephy_attach(device_t dev)
 	sc = device_get_softc(dev);
 	ma = device_get_ivars(dev);
 	flags = 0;
-	if (strcmp(if_getdname(ma->mii_data->mii_ifp), "re") == 0)
+	if (mii_dev_mac_match(dev, "re"))
 		flags |= MIIF_PHYPRIV0;
 	mii_phy_dev_attach(dev, flags, &rgephy_funcs, 0);
 

Modified: head/sys/dev/mii/rlphy.c
==============================================================================
--- head/sys/dev/mii/rlphy.c	Mon Jan 12 21:55:48 2015	(r277092)
+++ head/sys/dev/mii/rlphy.c	Mon Jan 12 22:27:38 2015	(r277093)
@@ -108,15 +108,13 @@ static const struct mii_phy_funcs rlphy_
 static int
 rlphy_probe(device_t dev)
 {
-	const char *nic;
 	int rv;
 
 	rv = mii_phy_dev_probe(dev, rlphys, BUS_PROBE_DEFAULT);
 	if (rv <= 0)
 		return (rv);
 
-	nic = device_get_name(device_get_parent(device_get_parent(dev)));
-	if (strcmp(nic, "rl") == 0 || strcmp(nic, "re") == 0)
+	if (mii_dev_mac_match(dev, "rl") || mii_dev_mac_match(dev, "re"))
 		return (mii_phy_dev_probe(dev, rlintphys, BUS_PROBE_DEFAULT));
 	return (ENXIO);
 }

Modified: head/sys/dev/mii/tlphy.c
==============================================================================
--- head/sys/dev/mii/tlphy.c	Mon Jan 12 21:55:48 2015	(r277092)
+++ head/sys/dev/mii/tlphy.c	Mon Jan 12 22:27:38 2015	(r277093)
@@ -130,8 +130,7 @@ static int
 tlphy_probe(device_t dev)
 {
 
-	if (strcmp(device_get_name(device_get_parent(device_get_parent(dev))),
-	    "tl") != 0)
+	if (!mii_dev_mac_match(dev, "tl"))
 		return (ENXIO);
 	return (mii_phy_dev_probe(dev, tlphys, BUS_PROBE_DEFAULT));
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201501122227.t0CMRdKA073432>