Index: sys/dev/usb/wlan/if_urtwn.c =================================================================== --- sys/dev/usb/wlan/if_urtwn.c +++ sys/dev/usb/wlan/if_urtwn.c @@ -265,6 +265,7 @@ static void urtwn_set_txpower(struct urtwn_softc *, struct ieee80211_channel *, struct ieee80211_channel *); +static void urtwn_set_gain(struct urtwn_softc *, uint8_t); static void urtwn_scan_start(struct ieee80211com *); static void urtwn_scan_end(struct ieee80211com *); static void urtwn_set_channel(struct ieee80211com *); @@ -1584,38 +1585,11 @@ urtwn_set_led(sc, URTWN_LED_LINK, 0); break; case IEEE80211_S_SCAN: - if (ostate != IEEE80211_S_SCAN) { - /* Allow Rx from any BSSID. */ - urtwn_write_4(sc, R92C_RCR, - urtwn_read_4(sc, R92C_RCR) & - ~(R92C_RCR_CBSSID_DATA | R92C_RCR_CBSSID_BCN)); - - /* Set gain for scanning. */ - reg = urtwn_bb_read(sc, R92C_OFDM0_AGCCORE1(0)); - reg = RW(reg, R92C_OFDM0_AGCCORE1_GAIN, 0x20); - urtwn_bb_write(sc, R92C_OFDM0_AGCCORE1(0), reg); - - if (!(sc->chip & URTWN_CHIP_88E)) { - reg = urtwn_bb_read(sc, R92C_OFDM0_AGCCORE1(1)); - reg = RW(reg, R92C_OFDM0_AGCCORE1_GAIN, 0x20); - urtwn_bb_write(sc, R92C_OFDM0_AGCCORE1(1), reg); - } - } /* Pause AC Tx queues. */ urtwn_write_1(sc, R92C_TXPAUSE, urtwn_read_1(sc, R92C_TXPAUSE) | 0x0f); break; case IEEE80211_S_AUTH: - /* Set initial gain under link. */ - reg = urtwn_bb_read(sc, R92C_OFDM0_AGCCORE1(0)); - reg = RW(reg, R92C_OFDM0_AGCCORE1_GAIN, 0x32); - urtwn_bb_write(sc, R92C_OFDM0_AGCCORE1(0), reg); - - if (!(sc->chip & URTWN_CHIP_88E)) { - reg = urtwn_bb_read(sc, R92C_OFDM0_AGCCORE1(1)); - reg = RW(reg, R92C_OFDM0_AGCCORE1_GAIN, 0x32); - urtwn_bb_write(sc, R92C_OFDM0_AGCCORE1(1), reg); - } urtwn_set_chan(sc, ic->ic_curchan, NULL); break; case IEEE80211_S_RUN: @@ -3088,15 +3062,48 @@ } static void +urtwn_set_gain(struct urtwn_softc *sc, uint8_t gain) +{ + uint32_t reg; + + reg = urtwn_bb_read(sc, R92C_OFDM0_AGCCORE1(0)); + reg = RW(reg, R92C_OFDM0_AGCCORE1_GAIN, gain); + urtwn_bb_write(sc, R92C_OFDM0_AGCCORE1(0), reg); + + if (!(sc->chip & URTWN_CHIP_88E)) { + reg = urtwn_bb_read(sc, R92C_OFDM0_AGCCORE1(1)); + reg = RW(reg, R92C_OFDM0_AGCCORE1_GAIN, gain); + urtwn_bb_write(sc, R92C_OFDM0_AGCCORE1(1), reg); + } +} + +static void urtwn_scan_start(struct ieee80211com *ic) { - /* XXX do nothing? */ + struct urtwn_softc *sc = ic->ic_softc; + + URTWN_LOCK(sc); + /* Receive beacons / probe responses from any BSSID. */ + urtwn_write_4(sc, R92C_RCR, urtwn_read_4(sc, R92C_RCR) & + ~R92C_RCR_CBSSID_BCN); + + /* Set gain for scanning. */ + urtwn_set_gain(sc, 0x20); + URTWN_UNLOCK(sc); } static void urtwn_scan_end(struct ieee80211com *ic) { - /* XXX do nothing? */ + struct urtwn_softc *sc = ic->ic_softc; + + URTWN_LOCK(sc); + urtwn_write_4(sc, R92C_RCR, urtwn_read_4(sc, R92C_RCR) | + R92C_RCR_CBSSID_BCN); + + /* Set gain under link. */ + urtwn_set_gain(sc, 0x32); + URTWN_UNLOCK(sc); } static void