Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Feb 2009 21:32:58 GMT
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 157112 for review
Message-ID:  <200902032132.n13LWwvm087839@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=157112

Change 157112 by hselasky@hselasky_laptop001 on 2009/02/03 21:32:50

	
	Fix regressions after patch from Andrew Thompson in
	the USB ethernet drivers.

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb2/ethernet/if_aue2.c#20 edit
.. //depot/projects/usb/src/sys/dev/usb2/ethernet/if_axe2.c#20 edit
.. //depot/projects/usb/src/sys/dev/usb2/ethernet/if_cue2.c#19 edit
.. //depot/projects/usb/src/sys/dev/usb2/ethernet/if_kue2.c#19 edit
.. //depot/projects/usb/src/sys/dev/usb2/ethernet/if_rue2.c#19 edit
.. //depot/projects/usb/src/sys/dev/usb2/ethernet/if_udav2.c#19 edit
.. //depot/projects/usb/src/sys/dev/usb2/ethernet/usb2_ethernet.c#8 edit
.. //depot/projects/usb/src/sys/dev/usb2/ethernet/usb2_ethernet.h#8 edit

Differences ...

==== //depot/projects/usb/src/sys/dev/usb2/ethernet/if_aue2.c#20 (text+ko) ====

@@ -410,6 +410,8 @@
 	for (i = 0; i != AUE_TIMEOUT; i++) {
 		if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE)
 			break;
+		if (usb2_ether_pause(&sc->sc_ue, hz / 100))
+			break;
 	}
 
 	if (i == AUE_TIMEOUT)
@@ -465,6 +467,8 @@
 	for (i = 0; i != AUE_TIMEOUT; i++) {
 		if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
 			break;
+		if (usb2_ether_pause(&sc->sc_ue, hz / 100))
+			break;
 	}
 
 	if (i == AUE_TIMEOUT)
@@ -499,6 +503,8 @@
 	for (i = 0; i != AUE_TIMEOUT; i++) {
 		if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
 			break;
+		if (usb2_ether_pause(&sc->sc_ue, hz / 100))
+			break;
 	}
 
 	if (i == AUE_TIMEOUT)
@@ -608,6 +614,8 @@
 	for (i = 0; i != AUE_TIMEOUT; i++) {
 		if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC))
 			break;
+		if (usb2_ether_pause(&sc->sc_ue, hz / 100))
+			break;
 	}
 
 	if (i == AUE_TIMEOUT)
@@ -635,7 +643,7 @@
 		aue_reset_pegasus_II(sc);
 
 	/* Wait a little while for the chip to get its brains in order: */
-	usb2_pause_mtx(&sc->sc_mtx, hz / 100);
+	usb2_ether_pause(&sc->sc_ue, hz / 100);
 }
 
 static void

==== //depot/projects/usb/src/sys/dev/usb2/ethernet/if_axe2.c#20 (text+ko) ====

@@ -357,7 +357,7 @@
 	val = htole16(val);
 
 	if (sc->sc_phyno != phy)
-		return (val);
+		return (0);
 
 	locked = mtx_owned(&sc->sc_mtx);
 	if (!locked)
@@ -530,35 +530,35 @@
 	}
 
 	axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x008c, NULL);
-	usb2_pause_mtx(&sc->sc_mtx, hz / 16);
+	usb2_ether_pause(&sc->sc_ue, hz / 16);
 
 	if ((eeprom >> 8) != 0x01) {
 		axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x003c, NULL);
-		usb2_pause_mtx(&sc->sc_mtx, hz / 32);
+		usb2_ether_pause(&sc->sc_ue, hz / 32);
 
 		axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x001c, NULL);
-		usb2_pause_mtx(&sc->sc_mtx, hz / 3);
+		usb2_ether_pause(&sc->sc_ue, hz / 3);
 
 		axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x003c, NULL);
-		usb2_pause_mtx(&sc->sc_mtx, hz / 32);
+		usb2_ether_pause(&sc->sc_ue, hz / 32);
 	} else {
 		axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x0004, NULL);
-		usb2_pause_mtx(&sc->sc_mtx, hz / 32);
+		usb2_ether_pause(&sc->sc_ue, hz / 32);
 
 		axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x000c, NULL);
-		usb2_pause_mtx(&sc->sc_mtx, hz / 32);
+		usb2_ether_pause(&sc->sc_ue, hz / 32);
 	}
 
 	/* soft reset */
 	axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0, AXE_SW_RESET_CLEAR, NULL);
-	usb2_pause_mtx(&sc->sc_mtx, hz / 4);
+	usb2_ether_pause(&sc->sc_ue, hz / 4);
 
 	axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0,
 	    AXE_SW_RESET_PRL | AXE_178_RESET_MAGIC, NULL);
-	usb2_pause_mtx(&sc->sc_mtx, hz / 4);
+	usb2_ether_pause(&sc->sc_ue, hz / 4);
 	/* Enable MII/GMII/RGMII interface to work with external PHY. */
 	axe_cmd(sc, AXE_CMD_SW_PHY_SELECT, 0, 0, NULL);
-	usb2_pause_mtx(&sc->sc_mtx, hz / 4);
+	usb2_ether_pause(&sc->sc_ue, hz / 4);
 
 	axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, 0, NULL);
 }
@@ -567,22 +567,22 @@
 axe_ax88772_init(struct axe_softc *sc)
 {
 	axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x00b0, NULL);
-	usb2_pause_mtx(&sc->sc_mtx, hz / 16);
+	usb2_ether_pause(&sc->sc_ue, hz / 16);
 
 	if (sc->sc_phyno == AXE_772_PHY_NO_EPHY) {
 		/* ask for the embedded PHY */
 		axe_cmd(sc, AXE_CMD_SW_PHY_SELECT, 0, 0x01, NULL);
-		usb2_pause_mtx(&sc->sc_mtx, hz / 64);
+		usb2_ether_pause(&sc->sc_ue, hz / 64);
 
 		/* power down and reset state, pin reset state */
 		axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0,
 		    AXE_SW_RESET_CLEAR, NULL);
-		usb2_pause_mtx(&sc->sc_mtx, hz / 16);
+		usb2_ether_pause(&sc->sc_ue, hz / 16);
 
 		/* power down/reset state, pin operating state */
 		axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0,
 		    AXE_SW_RESET_IPPD | AXE_SW_RESET_PRL, NULL);
-		usb2_pause_mtx(&sc->sc_mtx, hz / 4);
+		usb2_ether_pause(&sc->sc_ue, hz / 4);
 
 		/* power up, reset */
 		axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0, AXE_SW_RESET_PRL, NULL);
@@ -593,14 +593,14 @@
 	} else {
 		/* ask for external PHY */
 		axe_cmd(sc, AXE_CMD_SW_PHY_SELECT, 0, 0x00, NULL);
-		usb2_pause_mtx(&sc->sc_mtx, hz / 64);
+		usb2_ether_pause(&sc->sc_ue, hz / 64);
 
 		/* power down internal PHY */
 		axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0,
 		    AXE_SW_RESET_IPPD | AXE_SW_RESET_PRL, NULL);
 	}
 
-	usb2_pause_mtx(&sc->sc_mtx, hz / 4);
+	usb2_ether_pause(&sc->sc_ue, hz / 4);
 	axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, 0, NULL);
 }
 
@@ -618,7 +618,7 @@
 		DPRINTF("reset failed (ignored)\n");
 
 	/* Wait a little while for the chip to get its brains in order. */
-	usb2_pause_mtx(&sc->sc_mtx, hz / 100);
+	usb2_ether_pause(&sc->sc_ue, hz / 100);
 }
 
 static void

==== //depot/projects/usb/src/sys/dev/usb2/ethernet/if_cue2.c#19 (text+ko) ====

@@ -370,7 +370,7 @@
 	/*
 	 * wait a little while for the chip to get its brains in order:
 	 */
-	usb2_pause_mtx(&sc->sc_mtx, hz / 100);
+	usb2_ether_pause(&sc->sc_ue, hz / 100);
 }
 
 static void

==== //depot/projects/usb/src/sys/dev/usb2/ethernet/if_kue2.c#19 (text+ko) ====

@@ -427,7 +427,7 @@
 		DPRINTF("reset failed (ignored)\n");
 
 	/* wait a little while for the chip to get its brains in order */
-	usb2_pause_mtx(&sc->sc_mtx, hz / 100);
+	usb2_ether_pause(&sc->sc_ue, hz / 100);
 }
 
 static void

==== //depot/projects/usb/src/sys/dev/usb2/ethernet/if_rue2.c#19 (text+ko) ====

@@ -553,14 +553,15 @@
 	rue_csr_write_1(sc, RUE_CR, RUE_CR_SOFT_RST);
 
 	for (i = 0; i != RUE_TIMEOUT; i++) {
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (usb2_ether_pause(&sc->sc_ue, hz / 1000))
+			break;
 		if (!(rue_csr_read_1(sc, RUE_CR) & RUE_CR_SOFT_RST))
 			break;
 	}
 	if (i == RUE_TIMEOUT)
 		device_printf(sc->sc_ue.ue_dev, "reset never completed!\n");
 
-	usb2_pause_mtx(&sc->sc_mtx, hz / 100);
+	usb2_ether_pause(&sc->sc_ue, hz / 100);
 }
 
 static void

==== //depot/projects/usb/src/sys/dev/usb2/ethernet/if_udav2.c#19 (text+ko) ====

@@ -488,10 +488,11 @@
 	for (i = 0; i < UDAV_TX_TIMEOUT; i++) {
 		if (!(udav_csr_read1(sc, UDAV_NCR) & UDAV_NCR_RST))
 			break;
-		usb2_pause_mtx(&sc->sc_mtx, hz / 100);
+		if (usb2_ether_pause(&sc->sc_ue, hz / 100))
+			break;
 	}
 
-	usb2_pause_mtx(&sc->sc_mtx, hz / 100);
+	usb2_ether_pause(&sc->sc_ue, hz / 100);
 }
 
 #define	UDAV_BITS	6

==== //depot/projects/usb/src/sys/dev/usb2/ethernet/usb2_ethernet.c#8 (text+ko) ====

@@ -33,6 +33,7 @@
 #include <dev/usb2/core/usb2_process.h>
 #include <dev/usb2/core/usb2_busdma.h>
 #include <dev/usb2/core/usb2_request.h>
+#include <dev/usb2/core/usb2_util.h>
 
 #include <dev/usb2/ethernet/usb2_ethernet.h>
 
@@ -57,8 +58,24 @@
 static int	ue_ifmedia_upd(struct ifnet *);
 static void	ue_watchdog(void *);
 
+/*
+ * Return values:
+ *    0: success
+ * Else: device has been detached
+ */
+uint8_t
+usb2_ether_pause(struct usb2_ether *ue, unsigned int _ticks)
+{
+	if (usb2_proc_is_gone(&ue->ue_tq)) {
+		/* nothing to do */
+		return (1);
+	}
+	usb2_pause_mtx(ue->ue_mtx, _ticks);
+	return (0);
+}
+
 static void
-usb2_ether_queue_command(struct usb2_ether *ue,
+ue_queue_command(struct usb2_ether *ue,
     usb2_proc_callback_t *fn,
     struct usb2_proc_msg *t0, struct usb2_proc_msg *t1)
 {
@@ -136,9 +153,11 @@
 	}
 
 	/* fork rest of the attach code */
-	usb2_ether_queue_command(ue, ue_attach_post_task,
+	UE_LOCK(ue);
+	ue_queue_command(ue, ue_attach_post_task,
 	    &ue->ue_attach_task[0].hdr,
 	    &ue->ue_attach_task[1].hdr);
+	UE_UNLOCK(ue);
 
 error:
 	return (error);
@@ -154,6 +173,9 @@
 	int error;
 	char num[14];			/* sufficient for 32 bits */
 
+	/* first call driver's post attach routine */
+	ue->ue_methods->ue_attach_post(ue);
+
 	UE_UNLOCK(ue);
 
 	ue->ue_unit = alloc_unr(ueunit);
@@ -183,8 +205,10 @@
 
 	if (ue->ue_methods->ue_mii_upd != NULL && 
 	    ue->ue_methods->ue_mii_sts != NULL) {
+		mtx_lock(&Giant);	/* device_xxx() depends on this */
 		error = mii_phy_probe(ue->ue_dev, &ue->ue_miibus,
 		    ue_ifmedia_upd, ue->ue_methods->ue_mii_sts);
+		mtx_unlock(&Giant);
 		if (error) {
 			device_printf(ue->ue_dev, "MII without any PHY\n");
 			goto error;
@@ -208,7 +232,6 @@
 
 error:
 	free_unr(ueunit, ue->ue_unit);
-	usb2_proc_free(&ue->ue_tq);
 	if (ue->ue_ifp != NULL) {
 		if_free(ue->ue_ifp);
 		ue->ue_ifp = NULL;
@@ -239,8 +262,11 @@
 		usb2_callout_drain(&ue->ue_watchdog);
 
 		/* detach miibus */
-		if (ue->ue_miibus != NULL)
+		if (ue->ue_miibus != NULL) {
+			mtx_lock(&Giant);	/* device_xxx() depends on this */
 			device_delete_child(ue->ue_dev, ue->ue_miibus);
+			mtx_unlock(&Giant);
+		}
 
 		/* detach ethernet */
 		ether_ifdetach(ifp);
@@ -273,7 +299,7 @@
 
 	UE_LOCK(ue);
 	if (ifp->if_drv_flags & IFF_DRV_RUNNING)
-		usb2_ether_queue_command(ue, ue_stop_task,
+		ue_queue_command(ue, ue_stop_task,
 		    &ue->ue_start_stop_task[0].hdr,
 		    &ue->ue_start_stop_task[1].hdr);
 	UE_UNLOCK(ue);
@@ -317,7 +343,7 @@
 	struct usb2_ether *ue = arg;
 
 	UE_LOCK(ue);
-	usb2_ether_queue_command(ue, ue_start_task,
+	ue_queue_command(ue, ue_start_task,
 	    &ue->ue_start_stop_task[0].hdr, 
 	    &ue->ue_start_stop_task[1].hdr);
 	UE_UNLOCK(ue);
@@ -395,9 +421,11 @@
 	struct usb2_ether *ue = ifp->if_softc;
 
 	/* Defer to process context */
-	usb2_ether_queue_command(ue, ue_ifmedia_task,
+	UE_LOCK(ue);
+	ue_queue_command(ue, ue_ifmedia_task,
 	    &ue->ue_media_task[0].hdr,
 	    &ue->ue_media_task[1].hdr);
+	UE_UNLOCK(ue);
 
 	return (0);
 }
@@ -422,7 +450,7 @@
 	if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
 		return;
 
-	usb2_ether_queue_command(ue, ue_tick_task,
+	ue_queue_command(ue, ue_tick_task,
 	    &ue->ue_tick_task[0].hdr, 
 	    &ue->ue_tick_task[1].hdr);
 
@@ -456,15 +484,15 @@
 		UE_LOCK(ue);
 		if (ifp->if_flags & IFF_UP) {
 			if (ifp->if_drv_flags & IFF_DRV_RUNNING)
-				usb2_ether_queue_command(ue, ue_promisc_task,
+				ue_queue_command(ue, ue_promisc_task,
 				    &ue->ue_promisc_task[0].hdr, 
 				    &ue->ue_promisc_task[1].hdr);
 			else
-				usb2_ether_queue_command(ue, ue_start_task,
+				ue_queue_command(ue, ue_start_task,
 				    &ue->ue_start_stop_task[0].hdr, 
 				    &ue->ue_start_stop_task[1].hdr);
 		} else {
-			usb2_ether_queue_command(ue, ue_stop_task,
+			ue_queue_command(ue, ue_stop_task,
 			    &ue->ue_start_stop_task[0].hdr, 
 			    &ue->ue_start_stop_task[1].hdr);
 		}
@@ -473,7 +501,7 @@
 	case SIOCADDMULTI:
 	case SIOCDELMULTI:
 		UE_LOCK(ue);
-		usb2_ether_queue_command(ue, ue_setmulti_task,
+		ue_queue_command(ue, ue_setmulti_task,
 		    &ue->ue_multi_task[0].hdr, 
 		    &ue->ue_multi_task[1].hdr);
 		UE_UNLOCK(ue);

==== //depot/projects/usb/src/sys/dev/usb2/ethernet/usb2_ethernet.h#8 (text+ko) ====

@@ -102,6 +102,7 @@
 	uint8_t			ue_eaddr[ETHER_ADDR_LEN];
 };
 
+uint8_t		usb2_ether_pause(struct usb2_ether *, unsigned int);
 usb2_error_t	usb2_ether_do_request(struct usb2_ether *, 
 		    struct usb2_device_request *, void *,
 		    unsigned int timeout);
@@ -111,10 +112,11 @@
 int		usb2_ether_ifattach(struct usb2_ether *);
 void		usb2_ether_ifdetach(struct usb2_ether *);
 int		usb2_ether_ioctl(struct ifnet *, u_long, caddr_t);
-int		usb2_ether_rxmbuf(struct usb2_ether *ue, struct mbuf *m, 
-		    unsigned int len);
-int		usb2_ether_rxbuf(struct usb2_ether *ue, struct usb2_page_cache *pc, 
-		    unsigned int offset, unsigned int len);
+int		usb2_ether_rxmbuf(struct usb2_ether *, struct mbuf *, 
+		    unsigned int);
+int		usb2_ether_rxbuf(struct usb2_ether *,
+		    struct usb2_page_cache *, 
+		    unsigned int, unsigned int);
 void		usb2_ether_rxflush(struct usb2_ether *);
 void		usb2_ether_ifshutdown(struct usb2_ether *);
 uint8_t		usb2_ether_is_gone(struct usb2_ether *);



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