PERFORCE change 112394 for review

Kip Macy kmacy at FreeBSD.org
Sun Dec 31 22:34:11 PST 2006


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

Change 112394 by kmacy at kmacy_serendipity:sam_wifi on 2007/01/01 06:33:49

	myriad cleanups to get ral up and going under sam_wifi
	convert channels to new packed format - don't overlap b/g
	add scan_start, scan_end, and set_channel
	
	copy over power management from ath
	
	TODO: locking needs some serious re-working to interact 
	happily with FreeBSD's network stack - avoid running ral 
	under SMP

Affected files ...

.. //depot/projects/wifi/sys/dev/ral/rt2560.c#4 edit

Differences ...

==== //depot/projects/wifi/sys/dev/ral/rt2560.c#4 (text) ====

@@ -64,6 +64,7 @@
 #include <dev/ral/rt2560reg.h>
 #include <dev/ral/rt2560var.h>
 
+
 #ifdef RAL_DEBUG
 #define DPRINTF(x)	do { if (ral_debug > 0) printf x; } while (0)
 #define DPRINTFN(n, x)	do { if (ral_debug >= (n)) printf x; } while (0)
@@ -104,6 +105,9 @@
 static void		rt2560_wakeup_expire(struct rt2560_softc *);
 static uint8_t		rt2560_rxrate(struct rt2560_rx_desc *);
 static int		rt2560_ack_rate(struct ieee80211com *, int);
+static void		rt2560_scan_start(struct ieee80211com *);
+static void		rt2560_scan_end(struct ieee80211com *);
+static void		rt2560_set_channel(struct ieee80211com *);
 static uint16_t		rt2560_txtime(int, int, uint32_t);
 static uint8_t		rt2560_plcp_signal(int);
 static void		rt2560_setup_tx_desc(struct rt2560_softc *,
@@ -136,7 +140,7 @@
 static void		rt2560_update_slot(struct ifnet *);
 static void		rt2560_set_basicrates(struct rt2560_softc *);
 static void		rt2560_update_led(struct rt2560_softc *, int, int);
-static void		rt2560_set_bssid(struct rt2560_softc *, uint8_t *);
+static void		rt2560_set_bssid(struct rt2560_softc *, const uint8_t *);
 static void		rt2560_set_macaddr(struct rt2560_softc *, uint8_t *);
 static void		rt2560_get_macaddr(struct rt2560_softc *, uint8_t *);
 static void		rt2560_update_promisc(struct rt2560_softc *);
@@ -198,7 +202,7 @@
 	struct rt2560_softc *sc = device_get_softc(dev);
 	struct ieee80211com *ic = &sc->sc_ic;
 	struct ifnet *ifp;
-	int error, i;
+	int error, i, j;
 
 	sc->sc_dev = dev;
 
@@ -284,42 +288,54 @@
 	    IEEE80211_C_SHSLOT |	/* short slot time supported */
 	    IEEE80211_C_WPA;		/* 802.11i */
 
+	/* set supported .11b and .11g channels (1 through 14) */
+	for (j = 0, i = 1; i <= 14; i++) {
+		ic->ic_channels[j].ic_freq =
+		    ieee80211_ieee2mhz(i, IEEE80211_CHAN_2GHZ);
+		ic->ic_channels[j].ic_flags = IEEE80211_CHAN_B;
+		ic->ic_channels[j].ic_ieee = i;
+		j++;
+
+		ic->ic_channels[j].ic_freq =
+		    ieee80211_ieee2mhz(i, IEEE80211_CHAN_2GHZ);
+		ic->ic_channels[j].ic_flags = IEEE80211_CHAN_G;
+		ic->ic_channels[j].ic_ieee = i;
+		j++;
+	}
+
 	if (sc->rf_rev == RT2560_RF_5222) {
 		/* set supported .11a rates */
 		ic->ic_sup_rates[IEEE80211_MODE_11A] = rt2560_rateset_11a;
 
 		/* set supported .11a channels */
-		for (i = 36; i <= 64; i += 4) {
-			ic->ic_channels[i].ic_freq =
+		for (i = 36; i <= 64; i += 4, j++) {
+			ic->ic_channels[j].ic_freq =
 			    ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ);
-			ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A;
+			ic->ic_channels[j].ic_flags = IEEE80211_CHAN_A;
+			ic->ic_channels[j].ic_ieee = i;
 		}
-		for (i = 100; i <= 140; i += 4) {
-			ic->ic_channels[i].ic_freq =
+		for (i = 100; i <= 140; i += 4, j++) {
+			ic->ic_channels[j].ic_freq =
 			    ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ);
-			ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A;
+			ic->ic_channels[j].ic_flags = IEEE80211_CHAN_A;
+			ic->ic_channels[j].ic_ieee = i;
 		}
-		for (i = 149; i <= 161; i += 4) {
-			ic->ic_channels[i].ic_freq =
+		for (i = 149; i <= 161; i += 4, j++) {
+			ic->ic_channels[j].ic_freq =
 			    ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ);
-			ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A;
+			ic->ic_channels[j].ic_flags = IEEE80211_CHAN_A;
+			ic->ic_channels[j].ic_ieee = i;
 		}
 	}
 
 	/* set supported .11b and .11g rates */
 	ic->ic_sup_rates[IEEE80211_MODE_11B] = rt2560_rateset_11b;
 	ic->ic_sup_rates[IEEE80211_MODE_11G] = rt2560_rateset_11g;
-
-	/* set supported .11b and .11g channels (1 through 14) */
-	for (i = 1; i <= 14; i++) {
-		ic->ic_channels[i].ic_freq =
-		    ieee80211_ieee2mhz(i, IEEE80211_CHAN_2GHZ);
-		ic->ic_channels[i].ic_flags =
-		    IEEE80211_CHAN_CCK | IEEE80211_CHAN_OFDM |
-		    IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
-	}
-
+	ic->ic_nchans = j;
 	ieee80211_ifattach(ic);
+	ic->ic_scan_start = rt2560_scan_start;
+	ic->ic_scan_end = rt2560_scan_end;
+	ic->ic_set_channel = rt2560_set_channel;
 	ic->ic_node_alloc = rt2560_node_alloc;
 	ic->ic_updateslot = rt2560_update_slot;
 	ic->ic_reset = rt2560_reset;
@@ -749,14 +765,13 @@
 	int error;
 
 	error = ieee80211_media_change(ifp);
-	if (error != ENETRESET)
-		return error;
 
-	if ((ifp->if_flags & IFF_UP) &&
-	    (ifp->if_drv_flags & IFF_DRV_RUNNING))
-		rt2560_init(sc);
-
-	return 0;
+	if (error == ENETRESET) {
+		if ((ifp->if_flags & IFF_UP) &&
+		    (ifp->if_drv_flags & IFF_DRV_RUNNING))
+		        rt2560_init(sc);
+	}
+	return error;
 }
 
 /*
@@ -2042,6 +2057,28 @@
 				m_freem(m0);
 				continue;
 			}
+			if ((ni->ni_flags & IEEE80211_NODE_PWR_MGT) &&
+			    (m0->m_flags & M_PWR_SAV) == 0) {
+				/*
+				 * Station in power save mode; pass the frame
+				 * to the 802.11 layer and continue.  We'll get
+				 * the frame back when the time is right.
+				 */
+				ieee80211_pwrsave(ni, m0);
+				/*
+				 * If we're in power save mode 'cuz of a bg
+				 * scan cancel it so the traffic can flow.
+				 * The packet we just queued will automatically
+				 * get sent when we drop out of power save.
+				 * XXX locking
+				 */
+				if (ic->ic_flags & IEEE80211_F_SCAN)
+					ieee80211_cancel_scan(ic);
+				ieee80211_free_node(ni);
+				continue;
+
+			}
+
 			BPF_MTAP(ifp, m0);
 
 			m0 = ieee80211_encap(ic, m0, ni);
@@ -2049,7 +2086,7 @@
 				ieee80211_free_node(ni);
 				continue;
 			}
-
+			
 			if (bpf_peers_present(ic->ic_rawbpf))
 				bpf_mtap(ic->ic_rawbpf, m0);
 
@@ -2289,6 +2326,8 @@
 		rt2560_rf_write(sc, RAL_RF3, power << 7 | 0x00040);
 		rt2560_rf_write(sc, RAL_RF4, rt2560_rf5222[i].r4);
 		break;
+	default: 
+ 	        printf("unknown ral rev=%d\n", sc->rf_rev);
 	}
 
 	if (ic->ic_state != IEEE80211_S_SCAN) {
@@ -2306,6 +2345,18 @@
 	}
 }
 
+static void
+rt2560_set_channel(struct ieee80211com *ic)
+{
+	struct ifnet *ifp = ic->ic_ifp;
+	struct rt2560_softc *sc = ifp->if_softc;
+
+	RAL_LOCK(sc);
+	rt2560_set_chan(sc, ic->ic_curchan);
+	RAL_UNLOCK(sc);
+
+}
+
 #if 0
 /*
  * Disable RF auto-tuning.
@@ -2450,7 +2501,7 @@
 }
 
 static void
-rt2560_set_bssid(struct rt2560_softc *sc, uint8_t *bssid)
+rt2560_set_bssid(struct rt2560_softc *sc, const uint8_t *bssid)
 {
 	uint32_t tmp;
 
@@ -2555,6 +2606,30 @@
 	}
 }
 
+
+static void
+rt2560_scan_start(struct ieee80211com *ic)
+{
+	struct ifnet *ifp = ic->ic_ifp;
+	struct rt2560_softc *sc = ifp->if_softc;
+
+	printf("starting scan\n");
+	/* abort TSF synchronization */
+	RAL_WRITE(sc, RT2560_CSR14, 0);
+	rt2560_set_bssid(sc, ifp->if_broadcastaddr);
+}
+
+static void
+rt2560_scan_end(struct ieee80211com *ic)
+{
+	struct ifnet *ifp = ic->ic_ifp;
+	struct rt2560_softc *sc = ifp->if_softc;
+	printf("ending scan\n");
+	rt2560_enable_tsf_sync(sc);
+	/* XXX keep local copy */
+	rt2560_set_bssid(sc, ic->ic_bss->ni_bssid);
+}
+
 static int
 rt2560_bbp_init(struct rt2560_softc *sc)
 {


More information about the p4-projects mailing list