Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Jun 2005 19:07:08 -0700
From:      Brooks Davis <brooks@one-eyed-alien.net>
To:        net@freebsd.org
Cc:        scottl@freebsd.org, imp@freebsd.org
Subject:   RFC: mii_phy_probe API change
Message-ID:  <20050611020708.GA10602@odin.ac.hmc.edu>

next in thread | raw e-mail | index | archive | help

--UlVJffcvxoiEqYs2
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

I'd like to change mii_phy_probe to take an additional argument, a
pointer to the parent's struct ifnet.  This would allow use to remove
the disgusting cast from the first bit of the softc to an ifnet.  The
following totally untested diff is what I'm thinking about.  Is there
anything wrong with the idea?

-- Brooks

Index: miivar.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/dev/mii/miivar.h,v
retrieving revision 1.15
diff -u -r1.15 miivar.h
--- miivar.h	4 May 2002 11:00:30 -0000	1.15
+++ miivar.h	11 Jun 2005 02:00:44 -0000
@@ -203,7 +203,7 @@
 int	mii_mediachg(struct mii_data *);
 void	mii_tick(struct mii_data *);
 void	mii_pollstat(struct mii_data *);
-int	mii_phy_probe(device_t, device_t *, ifm_change_cb_t, ifm_stat_cb_t);
+int	mii_phy_probe(device_t, struct ifnet, device_t *, ifm_change_cb_t, ifm=
_stat_cb_t);
 void	mii_add_media(struct mii_softc *);
 void	mii_phy_add_media(struct mii_softc *);
=20
Index: mii.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/dev/mii/mii.c,v
retrieving revision 1.26
diff -u -r1.26 mii.c
--- mii.c	11 Jun 2005 00:20:38 -0000	1.26
+++ mii.c	11 Jun 2005 02:00:44 -0000
@@ -171,14 +171,10 @@
 	struct mii_data		*mii;
=20
 	mii =3D device_get_softc(dev);
-	/*
-	 * Note that each NIC's softc must start with an ifnet pointer.
-	 * XXX: EVIL HACK!
-	 */
-	mii->mii_ifp =3D *(struct ifnet**)device_get_softc(device_get_parent(dev)=
);
 	v =3D device_get_ivars(dev);
 	ifmedia_upd =3D v[0];
 	ifmedia_sts =3D v[1];
+	mii->mii_ifp =3D v[2];
 	ifmedia_init(&mii->mii_media, IFM_IMASK, ifmedia_upd, ifmedia_sts);
 	bus_generic_attach(dev);
=20
@@ -265,11 +261,7 @@
 			link_state =3D LINK_STATE_DOWN;
 	} else
 		link_state =3D LINK_STATE_UNKNOWN;
-	/*
-	 * Note that each NIC's softc must start with an ifnet pointer.
-	 * XXX: EVIL HACK!
-	 */
-	if_link_state_change(*(struct ifnet**)device_get_softc(parent), link_stat=
e);
+	if_link_state_change(mii->mii_ifp, link_state);
 }
=20
 static void
@@ -295,18 +287,19 @@
 }
=20
 int
-mii_phy_probe(device_t dev, device_t *child, ifm_change_cb_t ifmedia_upd,
-    ifm_stat_cb_t ifmedia_sts)
+mii_phy_probe(device_t dev, struct ifnet *ifp, device_t *child,
+    ifm_change_cb_t ifmedia_upd, ifm_stat_cb_t ifmedia_sts)
 {
 	void			**v;
 	int			bmsr, i;
=20
-	v =3D malloc(sizeof(vm_offset_t) * 2, M_DEVBUF, M_NOWAIT);
+	v =3D malloc(sizeof(vm_offset_t) * 3, M_DEVBUF, M_NOWAIT);
 	if (v =3D=3D 0) {
 		return (ENOMEM);
 	}
 	v[0] =3D ifmedia_upd;
 	v[1] =3D ifmedia_sts;
+	v[2] =3D ifp;
 	*child =3D device_add_child(dev, "miibus", -1);
 	device_set_ivars(*child, v);
=20

--=20
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4

--UlVJffcvxoiEqYs2
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFCqkdLXY6L6fI4GtQRAgmEAKCE08lXaZJxBvpX/a5WCiF1FlyfewCgvKD2
Q4dreIia4W1IHAJeaTjbkWI=
=dTLZ
-----END PGP SIGNATURE-----

--UlVJffcvxoiEqYs2--



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