PERFORCE change 157533 for review

Hans Petter Selasky hselasky at FreeBSD.org
Wed Feb 11 02:47:17 PST 2009


http://perforce.freebsd.org/chv.cgi?CH=157533

Change 157533 by hselasky at hselasky_laptop001 on 2009/02/11 10:46:55

	
	USB WLAN patches:
	- adjust timeouts back to the "HPS" values and
	  add detach detection to the pause mechanism.
	- fix an extra unlock in RUM driver.

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb2/wlan/if_rum2.c#34 edit
.. //depot/projects/usb/src/sys/dev/usb2/wlan/if_ural2.c#33 edit
.. //depot/projects/usb/src/sys/dev/usb2/wlan/if_zyd2.c#35 edit

Differences ...

==== //depot/projects/usb/src/sys/dev/usb2/wlan/if_rum2.c#34 (text+ko) ====

@@ -177,7 +177,7 @@
 static void		rum_read_eeprom(struct rum_softc *);
 static int		rum_bbp_init(struct rum_softc *);
 static void		rum_init(void *);
-static int		rum_load_microcode(struct rum_softc *, const u_char *,
+static int		rum_load_microcode(struct rum_softc *, const uint8_t *,
 			    size_t);
 static int		rum_prepare_beacon(struct rum_softc *,
 			    struct ieee80211vap *);
@@ -193,6 +193,7 @@
 static void		rum_amrr_start(struct rum_softc *,
 			    struct ieee80211_node *);
 static void		rum_amrr_timeout(void *);
+static uint8_t		rum_pause(struct rum_softc *, unsigned int);
 static void		rum_queue_command(struct rum_softc *,
 			    usb2_proc_callback_t *, struct usb2_proc_msg *,
 			    struct usb2_proc_msg *);
@@ -447,12 +448,13 @@
 	uint8_t bands;
 
 	/* retrieve RT2573 rev. no */
-	for (ntries = 0; ntries != 1000; ntries++) {
+	for (ntries = 0; ntries != 100; ntries++) {
 		if ((tmp = rum_read(sc, RT2573_MAC_CSR0)) != 0)
 			break;
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (rum_pause(sc, hz / 100))
+			break;
 	}
-	if (ntries == 1000) {
+	if (ntries == 100) {
 		device_printf(sc->sc_dev, "timeout waiting for chip to settle\n");
 		return;
 	}
@@ -465,7 +467,6 @@
 
 	error = rum_load_microcode(sc, rt2573_ucode, sizeof(rt2573_ucode));
 	if (error != 0) {
-		RUM_UNLOCK(sc);
 		device_printf(sc->sc_dev, "could not load 8051 microcode\n");
 		return;
 	}
@@ -1481,12 +1482,13 @@
 	uint32_t tmp;
 	int ntries;
 
-	for (ntries = 0; ntries != 5; ntries++) {
+	for (ntries = 0; ntries != 100; ntries++) {
 		if (!(rum_read(sc, RT2573_PHY_CSR3) & RT2573_BBP_BUSY))
 			break;
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (rum_pause(sc, hz / 100))
+			break;
 	}
-	if (ntries == 5) {
+	if (ntries == 100) {
 		device_printf(sc->sc_dev, "could not write to BBP\n");
 		return;
 	}
@@ -1501,12 +1503,13 @@
 	uint32_t val;
 	int ntries;
 
-	for (ntries = 0; ntries != 5; ntries++) {
+	for (ntries = 0; ntries != 100; ntries++) {
 		if (!(rum_read(sc, RT2573_PHY_CSR3) & RT2573_BBP_BUSY))
 			break;
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (rum_pause(sc, hz / 100))
+			break;
 	}
-	if (ntries == 5) {
+	if (ntries == 100) {
 		device_printf(sc->sc_dev, "could not read BBP\n");
 		return 0;
 	}
@@ -1514,11 +1517,12 @@
 	val = RT2573_BBP_BUSY | RT2573_BBP_READ | reg << 8;
 	rum_write(sc, RT2573_PHY_CSR3, val);
 
-	for (ntries = 0; ntries != 10; ntries++) {
+	for (ntries = 0; ntries != 100; ntries++) {
 		val = rum_read(sc, RT2573_PHY_CSR3);
 		if (!(val & RT2573_BBP_BUSY))
 			return val & 0xff;
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (rum_pause(sc, hz / 100))
+			break;
 	}
 
 	device_printf(sc->sc_dev, "could not read BBP\n");
@@ -1531,12 +1535,13 @@
 	uint32_t tmp;
 	int ntries;
 
-	for (ntries = 0; ntries != 5; ntries++) {
+	for (ntries = 0; ntries != 100; ntries++) {
 		if (!(rum_read(sc, RT2573_PHY_CSR4) & RT2573_RF_BUSY))
 			break;
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (rum_pause(sc, hz / 100))
+			break;
 	}
-	if (ntries == 5) {
+	if (ntries == 100) {
 		device_printf(sc->sc_dev, "could not write to RF\n");
 		return;
 	}
@@ -1683,7 +1688,8 @@
 	const struct rfprog *rfprog;
 	uint8_t bbp3, bbp94 = RT2573_BBPR94_DEFAULT;
 	int8_t power;
-	u_int i, chan;
+	unsigned int i;
+	unsigned int chan;
 
 	chan = ieee80211_chan2ieee(ic, c);
 	if (chan == 0 || chan == IEEE80211_CHAN_ANY)
@@ -1730,7 +1736,7 @@
 	rum_rf_write(sc, RT2573_RF3, rfprog[i].r3 | power << 7);
 	rum_rf_write(sc, RT2573_RF4, rfprog[i].r4 | sc->rffreq << 10);
 
-	usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+	(void)rum_pause(sc, hz / 100);
 
 	/* enable smart mode for MIMO-capable RFs */
 	bbp3 = rum_bbp_read(sc, 3);
@@ -1743,6 +1749,9 @@
 
 	if (bbp94 != RT2573_BBPR94_DEFAULT)
 		rum_bbp_write(sc, 94, bbp94);
+
+	/* give the chip some extra time to do the switchover */
+	(void)rum_pause(sc, hz / 100);
 }
 
 /*
@@ -1946,7 +1955,8 @@
 		const uint8_t val = rum_bbp_read(sc, 0);
 		if (val != 0 && val != 0xff)
 			break;
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (rum_pause(sc, hz / 100))
+			break;
 	}
 	if (ntries == 100) {
 		device_printf(sc->sc_dev, "timeout waiting for BBP\n");
@@ -1993,13 +2003,14 @@
 	rum_write(sc, RT2573_MAC_CSR1, 0);
 
 	/* wait for BBP/RF to wakeup */
-	for (ntries = 0; ntries != 1000; ntries++) {
+	for (ntries = 0; ntries != 100; ntries++) {
 		if (rum_read(sc, RT2573_MAC_CSR12) & 8)
 			break;
 		rum_write(sc, RT2573_MAC_CSR12, 4);	/* force wakeup */
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (rum_pause(sc, hz / 100))
+			break;
 	}
-	if (ntries == 1000) {
+	if (ntries == 100) {
 		device_printf(sc->sc_dev,
 		    "timeout waiting for BBP/RF to wakeup\n");
 		goto fail;
@@ -2101,12 +2112,17 @@
 }
 
 static int
-rum_load_microcode(struct rum_softc *sc, const u_char *ucode, size_t size)
+rum_load_microcode(struct rum_softc *sc, const uint8_t *ucode, size_t size)
 {
 	struct usb2_device_request req;
 	uint16_t reg = RT2573_MCU_CODE_BASE;
 	usb2_error_t error;
 
+	/*
+	 * TODO: If the firmware is already loaded,
+	 * then we need to return from here!
+	 */
+
 	/* copy firmware image into NIC */
 	for (; size >= 4; reg += 4, ucode += 4, size -= 4)
 		rum_write(sc, reg, UGETDW(ucode));
@@ -2405,6 +2421,16 @@
 	return rssi;
 }
 
+static uint8_t
+rum_pause(struct rum_softc *sc, unsigned int timeout)
+{
+	if (usb2_proc_is_gone(&sc->sc_tq))
+		return (1);
+
+	usb2_pause_mtx(&sc->sc_mtx, timeout);
+	return (0);
+}
+
 static void
 rum_queue_command(struct rum_softc *sc, usb2_proc_callback_t *fn,
     struct usb2_proc_msg *t0, struct usb2_proc_msg *t1)
@@ -2413,10 +2439,6 @@
 
 	RUM_LOCK_ASSERT(sc, MA_OWNED);
 
-	if (usb2_proc_is_gone(&sc->sc_tq)) {
-		DPRINTF("proc is gone\n");
-		return;         /* nothing to do */
-	}
 	/*
 	 * NOTE: The task cannot get executed before we drop the
 	 * "sc_mtx" mutex. It is safe to update fields in the message

==== //depot/projects/usb/src/sys/dev/usb2/wlan/if_ural2.c#33 (text+ko) ====

@@ -166,6 +166,7 @@
 static void		ural_amrr_start(struct ural_softc *,
 			    struct ieee80211_node *);
 static void		ural_amrr_timeout(void *);
+static uint8_t		ural_pause(struct ural_softc *sc, unsigned int timeout);
 static void		ural_queue_command(struct ural_softc *,
 			    usb2_proc_callback_t *, struct usb2_proc_msg *,
 			    struct usb2_proc_msg *);
@@ -1595,12 +1596,13 @@
 	uint16_t tmp;
 	int ntries;
 
-	for (ntries = 0; ntries != 5; ntries++) {
+	for (ntries = 0; ntries != 100; ntries++) {
 		if (!(ural_read(sc, RAL_PHY_CSR8) & RAL_BBP_BUSY))
 			break;
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (ural_pause(sc, hz / 100))
+			break;
 	}
-	if (ntries == 5) {
+	if (ntries == 100) {
 		device_printf(sc->sc_dev, "could not write to BBP\n");
 		return;
 	}
@@ -1618,12 +1620,13 @@
 	val = RAL_BBP_WRITE | reg << 8;
 	ural_write(sc, RAL_PHY_CSR7, val);
 
-	for (ntries = 0; ntries != 5; ntries++) {
+	for (ntries = 0; ntries != 100; ntries++) {
 		if (!(ural_read(sc, RAL_PHY_CSR8) & RAL_BBP_BUSY))
 			break;
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (ural_pause(sc, hz / 100))
+			break;
 	}
-	if (ntries == 5) {
+	if (ntries == 100) {
 		device_printf(sc->sc_dev, "could not read BBP\n");
 		return 0;
 	}
@@ -1637,12 +1640,13 @@
 	uint32_t tmp;
 	int ntries;
 
-	for (ntries = 0; ntries != 5; ntries++) {
+	for (ntries = 0; ntries != 100; ntries++) {
 		if (!(ural_read(sc, RAL_PHY_CSR10) & RAL_RF_LOBUSY))
 			break;
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (ural_pause(sc, hz / 100))
+			break;
 	}
-	if (ntries == 5) {
+	if (ntries == 100) {
 		device_printf(sc->sc_dev, "could not write to RF\n");
 		return;
 	}
@@ -1816,7 +1820,7 @@
 		/* clear CRC errors */
 		ural_read(sc, RAL_STA_CSR0);
 
-		usb2_pause_mtx(&sc->sc_mtx, hz / 100);
+		(void)ural_pause(sc, hz / 100);
 
 		ural_disable_rf_tune(sc);
 	}
@@ -1824,6 +1828,9 @@
 	/* XXX doesn't belong here */
 	/* update basic rate set */
 	ural_set_basicrates(sc, c);
+
+	/* give the hardware some time to do the switchover */
+	(void)ural_pause(sc, hz / 100);
 }
 
 /*
@@ -2042,7 +2049,8 @@
 	for (ntries = 0; ntries != 100; ntries++) {
 		if (ural_bbp_read(sc, RAL_BBP_VERSION) != 0)
 			break;
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (ural_pause(sc, hz / 100))
+			break;
 	}
 	if (ntries == 100) {
 		device_printf(sc->sc_dev, "timeout waiting for BBP\n");
@@ -2143,7 +2151,8 @@
 		if ((tmp & (RAL_BBP_AWAKE | RAL_RF_AWAKE)) ==
 		    (RAL_BBP_AWAKE | RAL_RF_AWAKE))
 			break;
-		usb2_pause_mtx(&sc->sc_mtx, hz / 1000);
+		if (ural_pause(sc, hz / 100))
+			break;
 	}
 	if (ntries == 100) {
 		device_printf(sc->sc_dev,
@@ -2238,7 +2247,11 @@
 	ural_write(sc, RAL_TXRX_CSR2, RAL_DISABLE_RX);
 	/* reset ASIC and BBP (but won't reset MAC registers!) */
 	ural_write(sc, RAL_MAC_CSR1, RAL_RESET_ASIC | RAL_RESET_BBP);
+	/* wait a little */
+	(void)ural_pause(sc, hz / 10);
 	ural_write(sc, RAL_MAC_CSR1, 0);
+	/* wait a little */
+	(void)ural_pause(sc, hz / 10);
 }
 
 static int
@@ -2353,6 +2366,16 @@
 	ifp->if_oerrors += fail;	/* count TX retry-fail as Tx errors */
 }
 
+static uint8_t
+ural_pause(struct ural_softc *sc, unsigned int timeout)
+{
+	if (usb2_proc_is_gone(&sc->sc_tq))
+		return (1);
+
+	usb2_pause_mtx(&sc->sc_mtx, timeout);
+	return (0);
+}
+
 static void
 ural_queue_command(struct ural_softc *sc, usb2_proc_callback_t *fn,
     struct usb2_proc_msg *t0, struct usb2_proc_msg *t1)
@@ -2361,10 +2384,6 @@
 
 	RAL_LOCK_ASSERT(sc, MA_OWNED);
 
-	if (usb2_proc_is_gone(&sc->sc_tq)) {
-		DPRINTF("proc is gone\n");
-		return;         /* nothing to do */
-	}
 	/*
 	 * NOTE: The task cannot get executed before we drop the
 	 * "sc_mtx" mutex. It is safe to update fields in the message

==== //depot/projects/usb/src/sys/dev/usb2/wlan/if_zyd2.c#35 (text+ko) ====

@@ -3091,10 +3091,6 @@
 
 	ZYD_LOCK_ASSERT(sc, MA_OWNED);
 
-	if (usb2_proc_is_gone(&sc->sc_tq)) {
-		DPRINTF(sc, ZYD_DEBUG_STATE, "proc is gone\n");
-		return;         /* nothing to do */
-	}
 	/*
 	 * NOTE: The task cannot get executed before we drop the
 	 * "sc_mtx" mutex. It is safe to update fields in the message


More information about the p4-projects mailing list