RFC: mii_phy_probe API change

Brooks Davis brooks at one-eyed-alien.net
Sat Jun 11 02:07:09 GMT 2005


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
===================================================================
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 *);
 
Index: mii.c
===================================================================
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;
 
 	mii = device_get_softc(dev);
-	/*
-	 * Note that each NIC's softc must start with an ifnet pointer.
-	 * XXX: EVIL HACK!
-	 */
-	mii->mii_ifp = *(struct ifnet**)device_get_softc(device_get_parent(dev));
 	v = device_get_ivars(dev);
 	ifmedia_upd = v[0];
 	ifmedia_sts = v[1];
+	mii->mii_ifp = v[2];
 	ifmedia_init(&mii->mii_media, IFM_IMASK, ifmedia_upd, ifmedia_sts);
 	bus_generic_attach(dev);
 
@@ -265,11 +261,7 @@
 			link_state = LINK_STATE_DOWN;
 	} else
 		link_state = 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_state);
+	if_link_state_change(mii->mii_ifp, link_state);
 }
 
 static void
@@ -295,18 +287,19 @@
 }
 
 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;
 
-	v = malloc(sizeof(vm_offset_t) * 2, M_DEVBUF, M_NOWAIT);
+	v = malloc(sizeof(vm_offset_t) * 3, M_DEVBUF, M_NOWAIT);
 	if (v == 0) {
 		return (ENOMEM);
 	}
 	v[0] = ifmedia_upd;
 	v[1] = ifmedia_sts;
+	v[2] = ifp;
 	*child = device_add_child(dev, "miibus", -1);
 	device_set_ivars(*child, v);
 

-- 
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-net/attachments/20050610/be10f3d0/attachment.bin


More information about the freebsd-net mailing list