PERFORCE change 136954 for review

Andrew Thompson thompsa at FreeBSD.org
Wed Mar 5 22:37:34 UTC 2008


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

Change 136954 by thompsa at thompsa_burger on 2008/03/05 22:36:42

	Move the firmware frobbing for setting the association id in the RUN
	transition to the taskq.
	
	Obtained from:	iwn

Affected files ...

.. //depot/projects/wifi/sys/dev/wpi/if_wpi.c#16 edit
.. //depot/projects/wifi/sys/dev/wpi/if_wpivar.h#7 edit

Differences ...

==== //depot/projects/wifi/sys/dev/wpi/if_wpi.c#16 (text+ko) ====

@@ -188,7 +188,7 @@
 static void	wpi_intr(void *);
 static void	wpi_ops(void *, int);
 static uint8_t	wpi_plcp_signal(int);
-static int	wpi_queue_cmd(struct wpi_softc *, int, int);
+static int	wpi_queue_cmd(struct wpi_softc *, int, int, int);
 static void	wpi_watchdog(void *);
 static int	wpi_tx_data(struct wpi_softc *, struct mbuf *,
 		    struct ieee80211_node *, int);
@@ -211,6 +211,7 @@
 static int	wpi_setup_beacon(struct wpi_softc *, struct ieee80211_node *);
 #endif
 static int	wpi_auth(struct wpi_softc *);
+static int	wpi_run(struct wpi_softc *);
 static int	wpi_scan(struct wpi_softc *);
 static int	wpi_config(struct wpi_softc *);
 static void	wpi_stop_master(struct wpi_softc *);
@@ -1240,8 +1241,6 @@
 {
 	struct ifnet *ifp = ic->ic_ifp;
 	struct wpi_softc *sc = ifp->if_softc;
-	struct ieee80211_node *ni;
-	int error;
 
 	DPRINTF(("%s: %s -> %s\n", __func__,
 		 ieee80211_state_name[ic->ic_state],
@@ -1260,11 +1259,10 @@
 		break;
 
 	case IEEE80211_S_AUTH:
-		sc->sc_autharg = arg;
-		sc->config.associd = 0;
-		sc->config.filter &= ~htole32(WPI_FILTER_BSS);
 		/* Delay the auth transition until we can update the firmware */
-		return (wpi_queue_cmd(sc, WPI_AUTH, 0));
+		if (ic->ic_state != IEEE80211_S_AUTH)
+			return wpi_queue_cmd(sc, WPI_AUTH, arg,
+			    WPI_QUEUE_NORMAL);
 
 	case IEEE80211_S_RUN:
 		if (ic->ic_opmode == IEEE80211_M_MONITOR) {
@@ -1272,60 +1270,13 @@
 			wpi_set_led(sc, WPI_LED_LINK, 5, 5);
 			break;
 		}
-
-#if 0
-		if (ic->ic_opmode != IEEE80211_M_STA) {
-			(void) wpi_auth(sc);    /* XXX */
-			wpi_setup_beacon(sc, ic->ic_bss);
-		}
-#endif
-
-		ni = ic->ic_bss;
-		wpi_enable_tsf(sc, ni);
-
-		/* update adapter's configuration */
-		sc->config.associd = htole16(ni->ni_associd & ~0xc000);
-		/* short preamble/slot time are negotiated when associating */
-		sc->config.flags &= ~htole32(WPI_CONFIG_SHPREAMBLE |
-			WPI_CONFIG_SHSLOT);
-		if (ic->ic_flags & IEEE80211_F_SHSLOT)
-			sc->config.flags |= htole32(WPI_CONFIG_SHSLOT);
-		if (ic->ic_flags & IEEE80211_F_SHPREAMBLE)
-			sc->config.flags |= htole32(WPI_CONFIG_SHPREAMBLE);
-		sc->config.filter |= htole32(WPI_FILTER_BSS);
-#if 0
-		if (ic->ic_opmode != IEEE80211_M_STA)
-			sc->config.filter |= htole32(WPI_FILTER_BEACON);
-#endif
-
-/* XXX put somewhere HC_QOS_SUPPORT_ASSOC + HC_IBSS_START */
+		if (ic->ic_state != IEEE80211_S_RUN)
+			/* set the association id first */
+			return wpi_queue_cmd(sc, WPI_RUN, arg,
+			    WPI_QUEUE_NORMAL);
 
-		DPRINTF(("config chan %d flags %x\n", sc->config.chan,
-		    sc->config.flags));
-		error = wpi_cmd(sc, WPI_CMD_CONFIGURE, &sc->config,
-			sizeof (struct wpi_config), 1);
-		if (error != 0) {
-			device_printf(sc->sc_dev,
-			    "could not update configuration\n");
-			return error;
-		}
-
-		if ((error = wpi_set_txpower(sc, ic->ic_bsschan, 1)) != 0) {
-			device_printf(sc->sc_dev,
-			    "could set txpower\n");
-			return error;
-		}
-
-		if (ic->ic_opmode == IEEE80211_M_STA) {
-			/* fake a join to init the tx rate */
-			wpi_newassoc(ic->ic_bss, 1);
-		}
-
 		/* start automatic rate control timer */
 		callout_reset(&sc->calib_to, hz/2, wpi_calib_timeout, sc);
-
-		/* link LED always on while associated */
-		wpi_set_led(sc, WPI_LED_LINK, 0, 1);
 		break;
 
 	default:
@@ -1808,7 +1759,7 @@
 		device_printf(sc->sc_dev, "fatal firmware error\n");
 		DPRINTFN(6,("(%s)\n", (r & WPI_SW_ERROR) ? "(Software Error)" :
 				"(Hardware Error)"));
-		wpi_queue_cmd(sc, WPI_RESTART, 1);
+		wpi_queue_cmd(sc, WPI_RESTART, 0, WPI_QUEUE_CLEAR);
 		sc->flags &= ~WPI_FLAG_BUSY;
 		WPI_UNLOCK(sc);
 		return;
@@ -2456,7 +2407,10 @@
 	struct wpi_node_info node;
 	int error;
 
+
 	/* update adapter's configuration */
+	sc->config.associd = 0;
+	sc->config.filter &= ~htole32(WPI_FILTER_BSS);
 	IEEE80211_ADDR_COPY(sc->config.bssid, ni->ni_bssid);
 	sc->config.chan = ieee80211_chan2ieee(ic, ni->ni_chan);
 	if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) {
@@ -2507,6 +2461,55 @@
 	return (error);
 }
 
+static int
+wpi_run(struct wpi_softc *sc)
+{
+	struct ieee80211com *ic = &sc->sc_ic;
+	struct ieee80211_node *ni = ic->ic_bss;
+	int error;
+
+	ni = ic->ic_bss;
+	wpi_enable_tsf(sc, ni);
+
+	/* update adapter's configuration */
+	sc->config.associd = htole16(ni->ni_associd & ~0xc000);
+	/* short preamble/slot time are negotiated when associating */
+	sc->config.flags &= ~htole32(WPI_CONFIG_SHPREAMBLE |
+	    WPI_CONFIG_SHSLOT);
+	if (ic->ic_flags & IEEE80211_F_SHSLOT)
+		sc->config.flags |= htole32(WPI_CONFIG_SHSLOT);
+	if (ic->ic_flags & IEEE80211_F_SHPREAMBLE)
+		sc->config.flags |= htole32(WPI_CONFIG_SHPREAMBLE);
+	sc->config.filter |= htole32(WPI_FILTER_BSS);
+
+	/* XXX put somewhere HC_QOS_SUPPORT_ASSOC + HC_IBSS_START */
+
+	DPRINTF(("config chan %d flags %x\n", sc->config.chan,
+		    sc->config.flags));
+	error = wpi_cmd(sc, WPI_CMD_CONFIGURE, &sc->config, sizeof (struct
+		    wpi_config), 1);
+	if (error != 0) {
+		device_printf(sc->sc_dev, "could not update configuration\n");
+		return error;
+	}
+
+	error = wpi_set_txpower(sc, ic->ic_bsschan, 1);
+	if (error != 0) {
+		device_printf(sc->sc_dev, "could set txpower\n");
+		return error;
+	}
+
+	if (ic->ic_opmode == IEEE80211_M_STA) {
+		/* fake a join to init the tx rate */
+		wpi_newassoc(ic->ic_bss, 1);
+	}
+
+	/* link LED always on while associated */
+	wpi_set_led(sc, WPI_LED_LINK, 0, 1);
+
+	return (error);
+}
+
 /*
  * Send a scan request to the firmware.  Since this command is huge, we map it
  * into a mbufcluster instead of using the pre-allocated set of commands. Note,
@@ -3184,6 +3187,7 @@
 
 	/* Clear any commands left in the command buffer */
 	memset(sc->sc_cmd, 0, sizeof(sc->sc_cmd));
+	memset(sc->sc_cmd_arg, 0, sizeof(sc->sc_cmd_arg));
 	sc->sc_cmd_cur = 0;
 	sc->sc_cmd_next = 0;
 
@@ -3544,7 +3548,7 @@
 	struct ifnet *ifp = ic->ic_ifp;
 	struct wpi_softc *sc = ifp->if_softc;
 
-	wpi_queue_cmd(sc, WPI_SCAN_START, 0);
+	wpi_queue_cmd(sc, WPI_SCAN_START, 0, WPI_QUEUE_NORMAL);
 }
 
 /**
@@ -3558,7 +3562,7 @@
 	struct ifnet *ifp = ic->ic_ifp;
 	struct wpi_softc *sc = ifp->if_softc;
 
-	wpi_queue_cmd(sc, WPI_SCAN_STOP, 0);
+	wpi_queue_cmd(sc, WPI_SCAN_STOP, 0, WPI_QUEUE_NORMAL);
 }
 
 /**
@@ -3571,7 +3575,7 @@
 	struct ifnet *ifp = ic->ic_ifp;
 	struct wpi_softc *sc = ifp->if_softc;
 
-	wpi_queue_cmd(sc, WPI_SET_CHAN, 0);
+	wpi_queue_cmd(sc, WPI_SET_CHAN, 0, WPI_QUEUE_NORMAL);
 }
 
 /**
@@ -3587,7 +3591,7 @@
 
 	sc->maxdwell = maxdwell;
 
-	wpi_queue_cmd(sc, WPI_SCAN_CURCHAN, 0);
+	wpi_queue_cmd(sc, WPI_SCAN_CURCHAN, 0, WPI_QUEUE_NORMAL);
 }
 
 /**
@@ -3609,15 +3613,16 @@
  * The task that gets cued is a op task, which ends up calling this function.
  */
 static void
-wpi_ops(void *arg, int pending)
+wpi_ops(void *arg0, int pending)
 {
-	struct wpi_softc *sc = arg;
+	struct wpi_softc *sc = arg0;
 	struct ieee80211com *ic = &sc->sc_ic;
-	int cmd;
+	int cmd, arg, error;
 
 again:
 	WPI_CMD_LOCK(sc);
 	cmd = sc->sc_cmd[sc->sc_cmd_cur];
+	arg = sc->sc_cmd_arg[sc->sc_cmd_cur];
 
 	if (cmd == 0) {
 		/* No more commands to process */
@@ -3625,6 +3630,7 @@
 		return;
 	}
 	sc->sc_cmd[sc->sc_cmd_cur] = 0; /* free the slot */
+	sc->sc_cmd_arg[sc->sc_cmd_cur] = 0; /* free the slot */
 	sc->sc_cmd_cur = (sc->sc_cmd_cur + 1) % WPI_CMD_MAXOPS;
 	WPI_CMD_UNLOCK(sc);
 	WPI_LOCK(sc);
@@ -3669,15 +3675,28 @@
 
 	case WPI_AUTH:
 		/* The node must be registered in the firmware before auth */
-		if (wpi_auth(sc) != 0) {
+		error = wpi_auth(sc);
+		if (error != 0) {
 			device_printf(sc->sc_dev,
-			    "could not send authentication request\n");
-			wpi_stop_locked(sc);
+			    "%s: could not move to auth state, error %d\n",
+			    __func__, error);
 			WPI_UNLOCK(sc);
 			return;
 		}
 		/* Send the auth frame now */
-		sc->sc_newstate(ic, IEEE80211_S_AUTH, sc->sc_autharg);
+		sc->sc_newstate(ic, IEEE80211_S_AUTH, arg);
+		break;
+
+	case WPI_RUN:
+		error = wpi_run(sc);
+		if (error != 0) {
+			device_printf(sc->sc_dev,
+			    "%s: could not move to run state, error %d\n",
+			    __func__, error);
+			WPI_UNLOCK(sc);
+			return;
+		}
+		sc->sc_newstate(ic, IEEE80211_S_RUN, arg);
 		break;
 	}
 	WPI_UNLOCK(sc);
@@ -3694,12 +3713,13 @@
  * a sleep enabled thread.
  */
 static int
-wpi_queue_cmd(struct wpi_softc *sc, int cmd, int flush)
+wpi_queue_cmd(struct wpi_softc *sc, int cmd, int arg, int flush)
 {
 	WPI_CMD_LOCK(sc);
 
 	if (flush) {
 		memset(sc->sc_cmd, 0, sizeof (sc->sc_cmd));
+		memset(sc->sc_cmd_arg, 0, sizeof (sc->sc_cmd_arg));
 		sc->sc_cmd_cur = 0;
 		sc->sc_cmd_next = 0;
 	}
@@ -3711,6 +3731,7 @@
 	}
 
 	sc->sc_cmd[sc->sc_cmd_next] = cmd;
+	sc->sc_cmd_arg[sc->sc_cmd_next] = arg;
 	sc->sc_cmd_next = (sc->sc_cmd_next + 1) % WPI_CMD_MAXOPS;
 
 	taskqueue_enqueue(sc->sc_tq, &sc->sc_opstask);
@@ -3762,7 +3783,7 @@
 		}
 
 		device_printf(sc->sc_dev, "Hardware Switch Enabled\n");
-		wpi_queue_cmd(sc, WPI_RF_RESTART, 1);
+		wpi_queue_cmd(sc, WPI_RF_RESTART, 0, WPI_QUEUE_CLEAR);
 		return;
 	}
 
@@ -3770,14 +3791,14 @@
 		if (--sc->sc_tx_timer == 0) {
 			device_printf(sc->sc_dev,"device timeout\n");
 			ifp->if_oerrors++;
-			wpi_queue_cmd(sc, WPI_RESTART, 1);
+			wpi_queue_cmd(sc, WPI_RESTART, 0, WPI_QUEUE_CLEAR);
 		}
 	}
 	if (sc->sc_scan_timer > 0) {
 		if (--sc->sc_scan_timer == 0) {
 			device_printf(sc->sc_dev,"scan timeout\n");
 			ieee80211_cancel_scan(&sc->sc_ic);
-			wpi_queue_cmd(sc, WPI_RESTART, 1);
+			wpi_queue_cmd(sc, WPI_RESTART, 0, WPI_QUEUE_CLEAR);
 		}
 	}
 

==== //depot/projects/wifi/sys/dev/wpi/if_wpivar.h#7 (text+ko) ====

@@ -133,7 +133,6 @@
 	int			(*sc_newstate)(struct ieee80211com *,
 				    enum ieee80211_state, int);
 	unsigned long		maxdwell; /* Max dwell time whilst scanning */
-	int			sc_autharg;
 
 	struct mtx		sc_mtx;
 
@@ -194,16 +193,21 @@
 	struct wpi_dma_info	fw_dma;
 
 	/* command queue related variables */
-	#define WPI_CMD_MAXOPS		10
-	#define WPI_SCAN_START		(1<<0)
-	#define WPI_SCAN_CURCHAN	(1<<1)
-	#define WPI_SCAN_STOP		(1<<2)
-	#define WPI_SET_CHAN		(1<<3)
-	#define WPI_AUTH		(1<<4)
-	#define WPI_SCAN_NEXT		(1<<5)
-	#define WPI_RESTART		(1<<6)
-	#define WPI_RF_RESTART		(1<<7)
+#define WPI_SCAN_START		(1<<0)
+#define WPI_SCAN_CURCHAN	(1<<1)
+#define WPI_SCAN_STOP		(1<<2)
+#define WPI_SET_CHAN		(1<<3)
+#define WPI_AUTH		(1<<4)
+#define WPI_RUN			(1<<5)
+#define WPI_SCAN_NEXT		(1<<6)
+#define WPI_RESTART		(1<<7)
+#define WPI_RF_RESTART		(1<<8)
+#define WPI_CMD_MAXOPS		10
+	/* command queuing request type */
+#define WPI_QUEUE_NORMAL	0
+#define WPI_QUEUE_CLEAR		1
 	int                     sc_cmd[WPI_CMD_MAXOPS];
+	int                     sc_cmd_arg[WPI_CMD_MAXOPS];
 	int                     sc_cmd_cur;    /* current queued scan task */
 	int                     sc_cmd_next;   /* last queued scan task */
 	struct mtx              sc_cmdlock;


More information about the p4-projects mailing list