PERFORCE change 112858 for review
Kip Macy
kmacy at FreeBSD.org
Sat Jan 13 05:41:45 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=112858
Change 112858 by kmacy at kmacy_netherworld:sam_wifi on 2007/01/13 05:40:54
remove direct channel initialization
add scanning hooks
remove calls to set channel in newstate
drop softc lock across ieee80211_input
prevent unload using RAL_INPUT_RUNNING flag
make stop a no-op if the driver isn't running (prevents panic in newstate)
don't acquire lock in ioctl, let called routines handle locking
tested cross-section of sta functionality
adhoc mode works in both 11g and 11b
background scanning works
Affected files ...
.. //depot/projects/wifi/sys/dev/ral/rt2661.c#4 edit
.. //depot/projects/wifi/sys/dev/ral/rt2661var.h#4 edit
Differences ...
==== //depot/projects/wifi/sys/dev/ral/rt2661.c#4 (text) ====
@@ -53,6 +53,7 @@
#include <net80211/ieee80211_var.h>
#include <net80211/ieee80211_radiotap.h>
+#include <net80211/ieee80211_regdomain.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@@ -103,6 +104,9 @@
static void rt2661_mcu_wakeup(struct rt2661_softc *);
static void rt2661_mcu_cmd_intr(struct rt2661_softc *);
static int rt2661_ack_rate(struct ieee80211com *, int);
+static void rt2661_scan_start(struct ieee80211com *);
+static void rt2661_scan_end(struct ieee80211com *);
+static void rt2661_set_channel(struct ieee80211com *);
static uint16_t rt2661_txtime(int, int, uint32_t);
static uint8_t rt2661_rxrate(struct rt2661_rx_desc *);
static uint8_t rt2661_plcp_signal(int);
@@ -147,6 +151,7 @@
static int rt2661_bbp_init(struct rt2661_softc *);
static void rt2661_init(void *);
static void rt2661_stop(void *);
+static void rt2661_stop_locked(struct rt2661_softc *);
static int rt2661_load_microcode(struct rt2661_softc *,
const uint8_t *, int);
#ifdef notyet
@@ -201,7 +206,7 @@
struct ifnet *ifp;
uint32_t val;
const uint8_t *ucode = NULL;
- int error, i, ac, ntries, size = 0;
+ int bands, error, ac, ntries, size = 0;
sc->sc_dev = dev;
@@ -314,44 +319,19 @@
#endif
IEEE80211_C_WPA; /* 802.11i */
- if (sc->rf_rev == RT2661_RF_5225 || sc->rf_rev == RT2661_RF_5325) {
- /* set supported .11a rates */
- ic->ic_sup_rates[IEEE80211_MODE_11A] = rt2661_rateset_11a;
-
- /* set supported .11a channels */
- for (i = 36; i <= 64; i += 4) {
- ic->ic_channels[i].ic_freq =
- ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ);
- ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A;
- }
- for (i = 100; i <= 140; i += 4) {
- ic->ic_channels[i].ic_freq =
- ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ);
- ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A;
- }
- for (i = 149; i <= 165; i += 4) {
- ic->ic_channels[i].ic_freq =
- ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ);
- ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A;
- }
- }
-
- /* set supported .11b and .11g rates */
- ic->ic_sup_rates[IEEE80211_MODE_11B] = rt2661_rateset_11b;
- ic->ic_sup_rates[IEEE80211_MODE_11G] = rt2661_rateset_11g;
+ bands = 0;
+ setbit(&bands, IEEE80211_MODE_11B);
+ setbit(&bands, IEEE80211_MODE_11G);
+ if (sc->rf_rev == RT2661_RF_5225 || sc->rf_rev == RT2661_RF_5325)
+ setbit(&bands, IEEE80211_MODE_11A);
+ ieee80211_init_channels(ic, 0, CTRY_DEFAULT, bands, 0, 1);
- /* 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;
- }
-
ieee80211_ifattach(ic);
ic->ic_node_alloc = rt2661_node_alloc;
/* ic->ic_wme.wme_update = rt2661_wme_update;*/
+ ic->ic_scan_start = rt2661_scan_start;
+ ic->ic_scan_end = rt2661_scan_end;
+ ic->ic_set_channel = rt2661_set_channel;
ic->ic_updateslot = rt2661_update_slot;
ic->ic_reset = rt2661_reset;
/* enable s/w bmiss handling in sta mode */
@@ -823,20 +803,7 @@
tmp = RAL_READ(sc, RT2661_TXRX_CSR9);
RAL_WRITE(sc, RT2661_TXRX_CSR9, tmp & ~0x00ffffff);
}
- break;
-
- case IEEE80211_S_SCAN:
- rt2661_set_chan(sc, ic->ic_curchan);
- break;
-
- case IEEE80211_S_AUTH:
- case IEEE80211_S_ASSOC:
- rt2661_set_chan(sc, ic->ic_curchan);
- break;
-
case IEEE80211_S_RUN:
- rt2661_set_chan(sc, ic->ic_curchan);
-
ni = ic->ic_bss;
if (ic->ic_opmode != IEEE80211_M_MONITOR) {
@@ -858,6 +825,10 @@
rt2661_enable_tsf_sync(sc);
}
break;
+ case IEEE80211_S_SCAN:
+ case IEEE80211_S_AUTH:
+ case IEEE80211_S_ASSOC:
+ break;
}
return (error != 0) ? error : sc->sc_newstate(ic, nstate, arg);
@@ -1137,7 +1108,8 @@
bpf_mtap2(sc->sc_drvbpf, tap, sc->sc_rxtap_len, m);
}
-
+ sc->sc_flags |= RAL_INPUT_RUNNING;
+ RAL_UNLOCK(sc);
wh = mtod(m, struct ieee80211_frame *);
ni = ieee80211_find_rxnode(ic,
(struct ieee80211_frame_min *)wh);
@@ -1147,6 +1119,8 @@
/* give rssi to the rate adatation algorithm */
rn = (struct rt2661_node *)ni;
+ RAL_LOCK(sc);
+ sc->sc_flags &= ~RAL_INPUT_RUNNING;
ral_rssadapt_input(ic, ni, &rn->rssadapt,
rt2661_get_rssi(sc, desc->rssi));
@@ -1882,8 +1856,6 @@
struct ieee80211com *ic = &sc->sc_ic;
int error = 0;
- RAL_LOCK(sc);
-
switch (cmd) {
case SIOCSIFFLAGS:
if (ifp->if_flags & IFF_UP) {
@@ -1909,8 +1881,6 @@
error = 0;
}
- RAL_UNLOCK(sc);
-
return error;
}
@@ -2460,7 +2430,7 @@
RAL_LOCK(sc);
- rt2661_stop(sc);
+ rt2661_stop_locked(sc);
/* initialize Tx rings */
RAL_WRITE(sc, RT2661_AC1_BASE_CSR, sc->txq[1].physaddr);
@@ -2520,13 +2490,13 @@
}
if (ntries == 1000) {
printf("timeout waiting for BBP/RF to wakeup\n");
- rt2661_stop(sc);
+ rt2661_stop_locked(sc);
RAL_UNLOCK(sc);
return;
}
if (rt2661_bbp_init(sc) != 0) {
- rt2661_stop(sc);
+ rt2661_stop_locked(sc);
RAL_UNLOCK(sc);
return;
}
@@ -2567,6 +2537,7 @@
/* kick Rx */
RAL_WRITE(sc, RT2661_RX_CNTL_CSR, 1);
+ RAL_UNLOCK(sc);
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
ifp->if_drv_flags |= IFF_DRV_RUNNING;
@@ -2577,7 +2548,7 @@
} else
ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
- RAL_UNLOCK(sc);
+
#undef N
}
@@ -2585,41 +2556,57 @@
rt2661_stop(void *priv)
{
struct rt2661_softc *sc = priv;
+
+ RAL_LOCK(sc);
+ rt2661_stop_locked(sc);
+ RAL_UNLOCK(sc);
+}
+
+void
+rt2661_stop_locked(struct rt2661_softc *sc)
+{
struct ieee80211com *ic = &sc->sc_ic;
struct ifnet *ifp = ic->ic_ifp;
uint32_t tmp;
+ volatile int *flags = &sc->sc_flags;
- sc->sc_tx_timer = 0;
- ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
+ while (*flags & RAL_INPUT_RUNNING) {
+ msleep(sc, &sc->sc_mtx, 0, "ralrunning", hz/10);
+ }
- ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
-
- /* abort Tx (for all 5 Tx rings) */
- RAL_WRITE(sc, RT2661_TX_CNTL_CSR, 0x1f << 16);
-
- /* disable Rx (value remains after reset!) */
- tmp = RAL_READ(sc, RT2661_TXRX_CSR0);
- RAL_WRITE(sc, RT2661_TXRX_CSR0, tmp | RT2661_DISABLE_RX);
-
- /* reset ASIC */
- RAL_WRITE(sc, RT2661_MAC_CSR1, 3);
- RAL_WRITE(sc, RT2661_MAC_CSR1, 0);
-
- /* disable interrupts */
- RAL_WRITE(sc, RT2661_INT_MASK_CSR, 0xffffffff);
- RAL_WRITE(sc, RT2661_MCU_INT_MASK_CSR, 0xffffffff);
-
- /* clear any pending interrupt */
- RAL_WRITE(sc, RT2661_INT_SOURCE_CSR, 0xffffffff);
- RAL_WRITE(sc, RT2661_MCU_INT_SOURCE_CSR, 0xffffffff);
-
- /* reset Tx and Rx rings */
- rt2661_reset_tx_ring(sc, &sc->txq[0]);
- rt2661_reset_tx_ring(sc, &sc->txq[1]);
- rt2661_reset_tx_ring(sc, &sc->txq[2]);
- rt2661_reset_tx_ring(sc, &sc->txq[3]);
- rt2661_reset_tx_ring(sc, &sc->mgtq);
- rt2661_reset_rx_ring(sc, &sc->rxq);
+ if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
+ sc->sc_tx_timer = 0;
+ ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
+
+ ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
+
+ /* abort Tx (for all 5 Tx rings) */
+ RAL_WRITE(sc, RT2661_TX_CNTL_CSR, 0x1f << 16);
+
+ /* disable Rx (value remains after reset!) */
+ tmp = RAL_READ(sc, RT2661_TXRX_CSR0);
+ RAL_WRITE(sc, RT2661_TXRX_CSR0, tmp | RT2661_DISABLE_RX);
+
+ /* reset ASIC */
+ RAL_WRITE(sc, RT2661_MAC_CSR1, 3);
+ RAL_WRITE(sc, RT2661_MAC_CSR1, 0);
+
+ /* disable interrupts */
+ RAL_WRITE(sc, RT2661_INT_MASK_CSR, 0xffffffff);
+ RAL_WRITE(sc, RT2661_MCU_INT_MASK_CSR, 0xffffffff);
+
+ /* clear any pending interrupt */
+ RAL_WRITE(sc, RT2661_INT_SOURCE_CSR, 0xffffffff);
+ RAL_WRITE(sc, RT2661_MCU_INT_SOURCE_CSR, 0xffffffff);
+
+ /* reset Tx and Rx rings */
+ rt2661_reset_tx_ring(sc, &sc->txq[0]);
+ rt2661_reset_tx_ring(sc, &sc->txq[1]);
+ rt2661_reset_tx_ring(sc, &sc->txq[2]);
+ rt2661_reset_tx_ring(sc, &sc->txq[3]);
+ rt2661_reset_tx_ring(sc, &sc->mgtq);
+ rt2661_reset_rx_ring(sc, &sc->rxq);
+ }
}
static int
@@ -2876,3 +2863,39 @@
}
return rssi;
}
+
+static void
+rt2661_scan_start(struct ieee80211com *ic)
+{
+ struct ifnet *ifp = ic->ic_ifp;
+ struct rt2661_softc *sc = ifp->if_softc;
+ uint32_t tmp;
+
+ /* abort TSF synchronization */
+ tmp = RAL_READ(sc, RT2661_TXRX_CSR9);
+ RAL_WRITE(sc, RT2661_TXRX_CSR9, tmp & ~0xffffff);
+ rt2661_set_bssid(sc, ifp->if_broadcastaddr);
+}
+
+static void
+rt2661_scan_end(struct ieee80211com *ic)
+{
+ struct ifnet *ifp = ic->ic_ifp;
+ struct rt2661_softc *sc = ifp->if_softc;
+
+ rt2661_enable_tsf_sync(sc);
+ /* XXX keep local copy */
+ rt2661_set_bssid(sc, ic->ic_bss->ni_bssid);
+}
+
+static void
+rt2661_set_channel(struct ieee80211com *ic)
+{
+ struct ifnet *ifp = ic->ic_ifp;
+ struct rt2661_softc *sc = ifp->if_softc;
+
+ RAL_LOCK(sc);
+ rt2661_set_chan(sc, ic->ic_curchan);
+ RAL_UNLOCK(sc);
+
+}
==== //depot/projects/wifi/sys/dev/ral/rt2661var.h#4 (text) ====
@@ -158,6 +158,8 @@
} sc_txtapu;
#define sc_txtap sc_txtapu.th
int sc_txtap_len;
+#define RAL_INPUT_RUNNING 1
+ int sc_flags;
};
int rt2661_attach(device_t, int);
More information about the p4-projects
mailing list