rt2661.c (167470) | rt2661.c (170530) |
---|---|
1/* $FreeBSD: head/sys/dev/ral/rt2661.c 167470 2007-03-11 22:43:35Z sam $ */ | 1/* $FreeBSD: head/sys/dev/ral/rt2661.c 170530 2007-06-11 03:36:55Z sam $ */ |
2 3/*- 4 * Copyright (c) 2006 5 * Damien Bergamini <damien.bergamini@free.fr> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20#include <sys/cdefs.h> | 2 3/*- 4 * Copyright (c) 2006 5 * Damien Bergamini <damien.bergamini@free.fr> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20#include <sys/cdefs.h> |
21__FBSDID("$FreeBSD: head/sys/dev/ral/rt2661.c 167470 2007-03-11 22:43:35Z sam $"); | 21__FBSDID("$FreeBSD: head/sys/dev/ral/rt2661.c 170530 2007-06-11 03:36:55Z sam $"); |
22 23/*- 24 * Ralink Technology RT2561, RT2561S and RT2661 chipset driver 25 * http://www.ralinktech.com/ 26 */ 27 28#include <sys/param.h> 29#include <sys/sysctl.h> --- 18 unchanged lines hidden (view full) --- 48#include <net/if_arp.h> 49#include <net/ethernet.h> 50#include <net/if_dl.h> 51#include <net/if_media.h> 52#include <net/if_types.h> 53 54#include <net80211/ieee80211_var.h> 55#include <net80211/ieee80211_radiotap.h> | 22 23/*- 24 * Ralink Technology RT2561, RT2561S and RT2661 chipset driver 25 * http://www.ralinktech.com/ 26 */ 27 28#include <sys/param.h> 29#include <sys/sysctl.h> --- 18 unchanged lines hidden (view full) --- 48#include <net/if_arp.h> 49#include <net/ethernet.h> 50#include <net/if_dl.h> 51#include <net/if_media.h> 52#include <net/if_types.h> 53 54#include <net80211/ieee80211_var.h> 55#include <net80211/ieee80211_radiotap.h> |
56#include <net80211/ieee80211_regdomain.h> |
|
56 57#include <netinet/in.h> 58#include <netinet/in_systm.h> 59#include <netinet/in_var.h> 60#include <netinet/ip.h> 61#include <netinet/if_ether.h> 62 63#include <dev/ral/if_ralrate.h> --- 23 unchanged lines hidden (view full) --- 87 struct rt2661_rx_ring *, int); 88static void rt2661_reset_rx_ring(struct rt2661_softc *, 89 struct rt2661_rx_ring *); 90static void rt2661_free_rx_ring(struct rt2661_softc *, 91 struct rt2661_rx_ring *); 92static struct ieee80211_node *rt2661_node_alloc( 93 struct ieee80211_node_table *); 94static int rt2661_media_change(struct ifnet *); | 57 58#include <netinet/in.h> 59#include <netinet/in_systm.h> 60#include <netinet/in_var.h> 61#include <netinet/ip.h> 62#include <netinet/if_ether.h> 63 64#include <dev/ral/if_ralrate.h> --- 23 unchanged lines hidden (view full) --- 88 struct rt2661_rx_ring *, int); 89static void rt2661_reset_rx_ring(struct rt2661_softc *, 90 struct rt2661_rx_ring *); 91static void rt2661_free_rx_ring(struct rt2661_softc *, 92 struct rt2661_rx_ring *); 93static struct ieee80211_node *rt2661_node_alloc( 94 struct ieee80211_node_table *); 95static int rt2661_media_change(struct ifnet *); |
95static void rt2661_next_scan(void *); | |
96static int rt2661_newstate(struct ieee80211com *, 97 enum ieee80211_state, int); 98static uint16_t rt2661_eeprom_read(struct rt2661_softc *, uint8_t); 99static void rt2661_rx_intr(struct rt2661_softc *); 100static void rt2661_tx_intr(struct rt2661_softc *); 101static void rt2661_tx_dma_intr(struct rt2661_softc *, 102 struct rt2661_tx_ring *); 103static void rt2661_mcu_beacon_expire(struct rt2661_softc *); 104static void rt2661_mcu_wakeup(struct rt2661_softc *); 105static void rt2661_mcu_cmd_intr(struct rt2661_softc *); 106static int rt2661_ack_rate(struct ieee80211com *, int); | 96static int rt2661_newstate(struct ieee80211com *, 97 enum ieee80211_state, int); 98static uint16_t rt2661_eeprom_read(struct rt2661_softc *, uint8_t); 99static void rt2661_rx_intr(struct rt2661_softc *); 100static void rt2661_tx_intr(struct rt2661_softc *); 101static void rt2661_tx_dma_intr(struct rt2661_softc *, 102 struct rt2661_tx_ring *); 103static void rt2661_mcu_beacon_expire(struct rt2661_softc *); 104static void rt2661_mcu_wakeup(struct rt2661_softc *); 105static void rt2661_mcu_cmd_intr(struct rt2661_softc *); 106static int rt2661_ack_rate(struct ieee80211com *, int); |
107static void rt2661_scan_start(struct ieee80211com *); 108static void rt2661_scan_end(struct ieee80211com *); 109static void rt2661_set_channel(struct ieee80211com *); |
|
107static uint16_t rt2661_txtime(int, int, uint32_t); 108static uint8_t rt2661_rxrate(struct rt2661_rx_desc *); 109static uint8_t rt2661_plcp_signal(int); 110static void rt2661_setup_tx_desc(struct rt2661_softc *, 111 struct rt2661_tx_desc *, uint32_t, uint16_t, int, 112 int, const bus_dma_segment_t *, int, int); 113static struct mbuf * rt2661_get_rts(struct rt2661_softc *, 114 struct ieee80211_frame *, uint16_t); --- 28 unchanged lines hidden (view full) --- 143static void rt2661_update_promisc(struct rt2661_softc *); 144static int rt2661_wme_update(struct ieee80211com *) __unused; 145static void rt2661_update_slot(struct ifnet *); 146static const char *rt2661_get_rf(int); 147static void rt2661_read_eeprom(struct rt2661_softc *); 148static int rt2661_bbp_init(struct rt2661_softc *); 149static void rt2661_init(void *); 150static void rt2661_stop(void *); | 110static uint16_t rt2661_txtime(int, int, uint32_t); 111static uint8_t rt2661_rxrate(struct rt2661_rx_desc *); 112static uint8_t rt2661_plcp_signal(int); 113static void rt2661_setup_tx_desc(struct rt2661_softc *, 114 struct rt2661_tx_desc *, uint32_t, uint16_t, int, 115 int, const bus_dma_segment_t *, int, int); 116static struct mbuf * rt2661_get_rts(struct rt2661_softc *, 117 struct ieee80211_frame *, uint16_t); --- 28 unchanged lines hidden (view full) --- 146static void rt2661_update_promisc(struct rt2661_softc *); 147static int rt2661_wme_update(struct ieee80211com *) __unused; 148static void rt2661_update_slot(struct ifnet *); 149static const char *rt2661_get_rf(int); 150static void rt2661_read_eeprom(struct rt2661_softc *); 151static int rt2661_bbp_init(struct rt2661_softc *); 152static void rt2661_init(void *); 153static void rt2661_stop(void *); |
154static void rt2661_stop_locked(struct rt2661_softc *); |
|
151static int rt2661_load_microcode(struct rt2661_softc *, 152 const uint8_t *, int); 153#ifdef notyet 154static void rt2661_rx_tune(struct rt2661_softc *); 155static void rt2661_radar_start(struct rt2661_softc *); 156static int rt2661_radar_stop(struct rt2661_softc *); 157#endif 158static int rt2661_prepare_beacon(struct rt2661_softc *); --- 26 unchanged lines hidden (view full) --- 185int 186rt2661_attach(device_t dev, int id) 187{ 188 struct rt2661_softc *sc = device_get_softc(dev); 189 struct ieee80211com *ic = &sc->sc_ic; 190 struct ifnet *ifp; 191 uint32_t val; 192 const uint8_t *ucode = NULL; | 155static int rt2661_load_microcode(struct rt2661_softc *, 156 const uint8_t *, int); 157#ifdef notyet 158static void rt2661_rx_tune(struct rt2661_softc *); 159static void rt2661_radar_start(struct rt2661_softc *); 160static int rt2661_radar_stop(struct rt2661_softc *); 161#endif 162static int rt2661_prepare_beacon(struct rt2661_softc *); --- 26 unchanged lines hidden (view full) --- 189int 190rt2661_attach(device_t dev, int id) 191{ 192 struct rt2661_softc *sc = device_get_softc(dev); 193 struct ieee80211com *ic = &sc->sc_ic; 194 struct ifnet *ifp; 195 uint32_t val; 196 const uint8_t *ucode = NULL; |
193 int error, i, ac, ntries, size = 0; | 197 int bands, error, ac, ntries, size = 0; |
194 195 sc->sc_dev = dev; 196 197 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 198 MTX_DEF | MTX_RECURSE); 199 200 callout_init_mtx(&sc->watchdog_ch, &sc->sc_mtx, 0); | 198 199 sc->sc_dev = dev; 200 201 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 202 MTX_DEF | MTX_RECURSE); 203 204 callout_init_mtx(&sc->watchdog_ch, &sc->sc_mtx, 0); |
201 callout_init(&sc->scan_ch, debug_mpsafenet ? CALLOUT_MPSAFE : 0); | |
202 callout_init(&sc->rssadapt_ch, CALLOUT_MPSAFE); 203 204 /* wait for NIC to initialize */ 205 for (ntries = 0; ntries < 1000; ntries++) { 206 if ((val = RAL_READ(sc, RT2661_MAC_CSR0)) != 0) 207 break; 208 DELAY(1000); 209 } --- 87 unchanged lines hidden (view full) --- 297 IEEE80211_C_MONITOR | /* monitor mode supported */ 298 IEEE80211_C_HOSTAP | /* HostAp mode supported */ 299 IEEE80211_C_TXPMGT | /* tx power management */ 300 IEEE80211_C_SHPREAMBLE | /* short preamble supported */ 301 IEEE80211_C_SHSLOT | /* short slot time supported */ 302#ifdef notyet 303 IEEE80211_C_WME | /* 802.11e */ 304#endif | 205 callout_init(&sc->rssadapt_ch, CALLOUT_MPSAFE); 206 207 /* wait for NIC to initialize */ 208 for (ntries = 0; ntries < 1000; ntries++) { 209 if ((val = RAL_READ(sc, RT2661_MAC_CSR0)) != 0) 210 break; 211 DELAY(1000); 212 } --- 87 unchanged lines hidden (view full) --- 300 IEEE80211_C_MONITOR | /* monitor mode supported */ 301 IEEE80211_C_HOSTAP | /* HostAp mode supported */ 302 IEEE80211_C_TXPMGT | /* tx power management */ 303 IEEE80211_C_SHPREAMBLE | /* short preamble supported */ 304 IEEE80211_C_SHSLOT | /* short slot time supported */ 305#ifdef notyet 306 IEEE80211_C_WME | /* 802.11e */ 307#endif |
308 IEEE80211_C_BGSCAN | /* bg scanning support */ |
|
305 IEEE80211_C_WPA; /* 802.11i */ 306 | 309 IEEE80211_C_WPA; /* 802.11i */ 310 |
307 if (sc->rf_rev == RT2661_RF_5225 || sc->rf_rev == RT2661_RF_5325) { 308 /* set supported .11a channels */ 309 for (i = 36; i <= 64; i += 4) { 310 ic->ic_channels[i].ic_freq = 311 ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ); 312 ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A; 313 } 314 for (i = 100; i <= 140; i += 4) { 315 ic->ic_channels[i].ic_freq = 316 ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ); 317 ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A; 318 } 319 for (i = 149; i <= 165; i += 4) { 320 ic->ic_channels[i].ic_freq = 321 ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ); 322 ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A; 323 } 324 } | 311 bands = 0; 312 setbit(&bands, IEEE80211_MODE_11B); 313 setbit(&bands, IEEE80211_MODE_11G); 314 if (sc->rf_rev == RT2661_RF_5225 || sc->rf_rev == RT2661_RF_5325) 315 setbit(&bands, IEEE80211_MODE_11A); 316 ieee80211_init_channels(ic, 0, CTRY_DEFAULT, bands, 0, 1); |
325 | 317 |
326 /* set supported .11b and .11g channels (1 through 14) */ 327 for (i = 1; i <= 14; i++) { 328 ic->ic_channels[i].ic_freq = 329 ieee80211_ieee2mhz(i, IEEE80211_CHAN_2GHZ); 330 ic->ic_channels[i].ic_flags = 331 IEEE80211_CHAN_CCK | IEEE80211_CHAN_OFDM | 332 IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ; 333 } 334 | |
335 ieee80211_ifattach(ic); 336 ic->ic_node_alloc = rt2661_node_alloc; 337/* ic->ic_wme.wme_update = rt2661_wme_update;*/ | 318 ieee80211_ifattach(ic); 319 ic->ic_node_alloc = rt2661_node_alloc; 320/* ic->ic_wme.wme_update = rt2661_wme_update;*/ |
321 ic->ic_scan_start = rt2661_scan_start; 322 ic->ic_scan_end = rt2661_scan_end; 323 ic->ic_set_channel = rt2661_set_channel; |
|
338 ic->ic_updateslot = rt2661_update_slot; 339 ic->ic_reset = rt2661_reset; 340 /* enable s/w bmiss handling in sta mode */ 341 ic->ic_flags_ext |= IEEE80211_FEXT_SWBMISS; 342 343 /* override state transition machine */ 344 sc->sc_newstate = ic->ic_newstate; 345 ic->ic_newstate = rt2661_newstate; --- 5 unchanged lines hidden (view full) --- 351 sc->sc_rxtap_len = sizeof sc->sc_rxtapu; 352 sc->sc_rxtap.wr_ihdr.it_len = htole16(sc->sc_rxtap_len); 353 sc->sc_rxtap.wr_ihdr.it_present = htole32(RT2661_RX_RADIOTAP_PRESENT); 354 355 sc->sc_txtap_len = sizeof sc->sc_txtapu; 356 sc->sc_txtap.wt_ihdr.it_len = htole16(sc->sc_txtap_len); 357 sc->sc_txtap.wt_ihdr.it_present = htole32(RT2661_TX_RADIOTAP_PRESENT); 358 | 324 ic->ic_updateslot = rt2661_update_slot; 325 ic->ic_reset = rt2661_reset; 326 /* enable s/w bmiss handling in sta mode */ 327 ic->ic_flags_ext |= IEEE80211_FEXT_SWBMISS; 328 329 /* override state transition machine */ 330 sc->sc_newstate = ic->ic_newstate; 331 ic->ic_newstate = rt2661_newstate; --- 5 unchanged lines hidden (view full) --- 337 sc->sc_rxtap_len = sizeof sc->sc_rxtapu; 338 sc->sc_rxtap.wr_ihdr.it_len = htole16(sc->sc_rxtap_len); 339 sc->sc_rxtap.wr_ihdr.it_present = htole32(RT2661_RX_RADIOTAP_PRESENT); 340 341 sc->sc_txtap_len = sizeof sc->sc_txtapu; 342 sc->sc_txtap.wt_ihdr.it_len = htole16(sc->sc_txtap_len); 343 sc->sc_txtap.wt_ihdr.it_present = htole32(RT2661_TX_RADIOTAP_PRESENT); 344 |
345 |
|
359 /* 360 * Add a few sysctl knobs. 361 */ 362 sc->dwelltime = 200; 363 364 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), 365 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "dwell", 366 CTLFLAG_RW, &sc->dwelltime, 0, --- 4 unchanged lines hidden (view full) --- 371 372 return 0; 373 374fail4: rt2661_free_rx_ring(sc, &sc->rxq); 375fail3: rt2661_free_tx_ring(sc, &sc->mgtq); 376fail2: while (--ac >= 0) 377 rt2661_free_tx_ring(sc, &sc->txq[ac]); 378fail1: mtx_destroy(&sc->sc_mtx); | 346 /* 347 * Add a few sysctl knobs. 348 */ 349 sc->dwelltime = 200; 350 351 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), 352 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "dwell", 353 CTLFLAG_RW, &sc->dwelltime, 0, --- 4 unchanged lines hidden (view full) --- 358 359 return 0; 360 361fail4: rt2661_free_rx_ring(sc, &sc->rxq); 362fail3: rt2661_free_tx_ring(sc, &sc->mgtq); 363fail2: while (--ac >= 0) 364 rt2661_free_tx_ring(sc, &sc->txq[ac]); 365fail1: mtx_destroy(&sc->sc_mtx); |
379 | |
380 return error; 381} 382 383int 384rt2661_detach(void *xsc) 385{ 386 struct rt2661_softc *sc = xsc; 387 struct ieee80211com *ic = &sc->sc_ic; 388 struct ifnet *ifp = ic->ic_ifp; | 366 return error; 367} 368 369int 370rt2661_detach(void *xsc) 371{ 372 struct rt2661_softc *sc = xsc; 373 struct ieee80211com *ic = &sc->sc_ic; 374 struct ifnet *ifp = ic->ic_ifp; |
389 | 375 |
390 rt2661_stop(sc); 391 callout_stop(&sc->watchdog_ch); | 376 rt2661_stop(sc); 377 callout_stop(&sc->watchdog_ch); |
392 callout_stop(&sc->scan_ch); | |
393 callout_stop(&sc->rssadapt_ch); 394 395 bpfdetach(ifp); 396 ieee80211_ifdetach(ic); 397 398 rt2661_free_tx_ring(sc, &sc->txq[0]); 399 rt2661_free_tx_ring(sc, &sc->txq[1]); 400 rt2661_free_tx_ring(sc, &sc->txq[2]); --- 353 unchanged lines hidden (view full) --- 754 755 if ((ifp->if_flags & IFF_UP) && (ifp->if_drv_flags & IFF_DRV_RUNNING)) 756 rt2661_init(sc); 757 758 return 0; 759} 760 761/* | 378 callout_stop(&sc->rssadapt_ch); 379 380 bpfdetach(ifp); 381 ieee80211_ifdetach(ic); 382 383 rt2661_free_tx_ring(sc, &sc->txq[0]); 384 rt2661_free_tx_ring(sc, &sc->txq[1]); 385 rt2661_free_tx_ring(sc, &sc->txq[2]); --- 353 unchanged lines hidden (view full) --- 739 740 if ((ifp->if_flags & IFF_UP) && (ifp->if_drv_flags & IFF_DRV_RUNNING)) 741 rt2661_init(sc); 742 743 return 0; 744} 745 746/* |
762 * This function is called periodically (every 200ms) during scanning to 763 * switch from one channel to another. 764 */ 765static void 766rt2661_next_scan(void *arg) 767{ 768 struct rt2661_softc *sc = arg; 769 struct ieee80211com *ic = &sc->sc_ic; 770 771 if (ic->ic_state == IEEE80211_S_SCAN) 772 ieee80211_next_scan(ic); 773} 774 775/* | |
776 * This function is called for each node present in the node station table. 777 */ 778static void 779rt2661_iter_func(void *arg, struct ieee80211_node *ni) 780{ 781 struct rt2661_node *rn = (struct rt2661_node *)ni; 782 783 ral_rssadapt_updatestats(&rn->rssadapt); --- 22 unchanged lines hidden (view full) --- 806{ 807 struct rt2661_softc *sc = ic->ic_ifp->if_softc; 808 enum ieee80211_state ostate; 809 struct ieee80211_node *ni; 810 uint32_t tmp; 811 int error = 0; 812 813 ostate = ic->ic_state; | 747 * This function is called for each node present in the node station table. 748 */ 749static void 750rt2661_iter_func(void *arg, struct ieee80211_node *ni) 751{ 752 struct rt2661_node *rn = (struct rt2661_node *)ni; 753 754 ral_rssadapt_updatestats(&rn->rssadapt); --- 22 unchanged lines hidden (view full) --- 777{ 778 struct rt2661_softc *sc = ic->ic_ifp->if_softc; 779 enum ieee80211_state ostate; 780 struct ieee80211_node *ni; 781 uint32_t tmp; 782 int error = 0; 783 784 ostate = ic->ic_state; |
814 callout_stop(&sc->scan_ch); | |
815 816 switch (nstate) { 817 case IEEE80211_S_INIT: 818 callout_stop(&sc->rssadapt_ch); 819 820 if (ostate == IEEE80211_S_RUN) { 821 /* abort TSF synchronization */ 822 tmp = RAL_READ(sc, RT2661_TXRX_CSR9); 823 RAL_WRITE(sc, RT2661_TXRX_CSR9, tmp & ~0x00ffffff); 824 } 825 break; | 785 786 switch (nstate) { 787 case IEEE80211_S_INIT: 788 callout_stop(&sc->rssadapt_ch); 789 790 if (ostate == IEEE80211_S_RUN) { 791 /* abort TSF synchronization */ 792 tmp = RAL_READ(sc, RT2661_TXRX_CSR9); 793 RAL_WRITE(sc, RT2661_TXRX_CSR9, tmp & ~0x00ffffff); 794 } 795 break; |
826 827 case IEEE80211_S_SCAN: 828 rt2661_set_chan(sc, ic->ic_curchan); 829 callout_reset(&sc->scan_ch, (sc->dwelltime * hz) / 1000, 830 rt2661_next_scan, sc); 831 break; 832 833 case IEEE80211_S_AUTH: 834 case IEEE80211_S_ASSOC: 835 rt2661_set_chan(sc, ic->ic_curchan); 836 break; 837 | |
838 case IEEE80211_S_RUN: | 796 case IEEE80211_S_RUN: |
839 rt2661_set_chan(sc, ic->ic_curchan); 840 | |
841 ni = ic->ic_bss; 842 843 if (ic->ic_opmode != IEEE80211_M_MONITOR) { 844 rt2661_enable_mrr(sc); 845 rt2661_set_txpreamble(sc); 846 rt2661_set_basicrates(sc, &ni->ni_rates); 847 rt2661_set_bssid(sc, ni->ni_bssid); 848 } --- 5 unchanged lines hidden (view full) --- 854 } 855 856 if (ic->ic_opmode != IEEE80211_M_MONITOR) { 857 callout_reset(&sc->rssadapt_ch, hz / 10, 858 rt2661_update_rssadapt, sc); 859 rt2661_enable_tsf_sync(sc); 860 } 861 break; | 797 ni = ic->ic_bss; 798 799 if (ic->ic_opmode != IEEE80211_M_MONITOR) { 800 rt2661_enable_mrr(sc); 801 rt2661_set_txpreamble(sc); 802 rt2661_set_basicrates(sc, &ni->ni_rates); 803 rt2661_set_bssid(sc, ni->ni_bssid); 804 } --- 5 unchanged lines hidden (view full) --- 810 } 811 812 if (ic->ic_opmode != IEEE80211_M_MONITOR) { 813 callout_reset(&sc->rssadapt_ch, hz / 10, 814 rt2661_update_rssadapt, sc); 815 rt2661_enable_tsf_sync(sc); 816 } 817 break; |
818 case IEEE80211_S_SCAN: 819 case IEEE80211_S_AUTH: 820 case IEEE80211_S_ASSOC: 821 break; |
|
862 } 863 864 return (error != 0) ? error : sc->sc_newstate(ic, nstate, arg); 865} 866 867/* 868 * Read 16 bits at address 'addr' from the serial EEPROM (either 93C46 or 869 * 93C66). --- 59 unchanged lines hidden (view full) --- 929 struct ifnet *ifp = ic->ic_ifp; 930 struct rt2661_tx_ring *txq; 931 struct rt2661_tx_data *data; 932 struct rt2661_node *rn; 933 uint32_t val; 934 int qid, retrycnt; 935 936 for (;;) { | 822 } 823 824 return (error != 0) ? error : sc->sc_newstate(ic, nstate, arg); 825} 826 827/* 828 * Read 16 bits at address 'addr' from the serial EEPROM (either 93C46 or 829 * 93C66). --- 59 unchanged lines hidden (view full) --- 889 struct ifnet *ifp = ic->ic_ifp; 890 struct rt2661_tx_ring *txq; 891 struct rt2661_tx_data *data; 892 struct rt2661_node *rn; 893 uint32_t val; 894 int qid, retrycnt; 895 896 for (;;) { |
897 struct ieee80211_node *ni; 898 struct mbuf *m; 899 |
|
937 val = RAL_READ(sc, RT2661_STA_CSR4); 938 if (!(val & RT2661_TX_STAT_VALID)) 939 break; 940 941 /* retrieve the queue in which this frame was sent */ 942 qid = RT2661_TX_QID(val); 943 txq = (qid <= 3) ? &sc->txq[qid] : &sc->mgtq; 944 945 /* retrieve rate control algorithm context */ 946 data = &txq->data[txq->stat]; | 900 val = RAL_READ(sc, RT2661_STA_CSR4); 901 if (!(val & RT2661_TX_STAT_VALID)) 902 break; 903 904 /* retrieve the queue in which this frame was sent */ 905 qid = RT2661_TX_QID(val); 906 txq = (qid <= 3) ? &sc->txq[qid] : &sc->mgtq; 907 908 /* retrieve rate control algorithm context */ 909 data = &txq->data[txq->stat]; |
947 rn = (struct rt2661_node *)data->ni; | 910 m = data->m; 911 data->m = NULL; 912 ni = data->ni; 913 data->ni = NULL; |
948 949 /* if no frame has been sent, ignore */ | 914 915 /* if no frame has been sent, ignore */ |
950 if (rn == NULL) | 916 if (ni == NULL) |
951 continue; 952 | 917 continue; 918 |
919 rn = (struct rt2661_node *)ni; 920 |
|
953 switch (RT2661_TX_RESULT(val)) { 954 case RT2661_TX_SUCCESS: 955 retrycnt = RT2661_TX_RETRYCNT(val); 956 957 DPRINTFN(10, ("data frame sent successfully after " 958 "%d retries\n", retrycnt)); 959 if (retrycnt == 0 && data->id.id_node != NULL) { 960 ral_rssadapt_raise_rate(ic, &rn->rssadapt, 961 &data->id); 962 } 963 ifp->if_opackets++; 964 break; 965 966 case RT2661_TX_RETRY_FAIL: 967 DPRINTFN(9, ("sending data frame failed (too much " 968 "retries)\n")); 969 if (data->id.id_node != NULL) { | 921 switch (RT2661_TX_RESULT(val)) { 922 case RT2661_TX_SUCCESS: 923 retrycnt = RT2661_TX_RETRYCNT(val); 924 925 DPRINTFN(10, ("data frame sent successfully after " 926 "%d retries\n", retrycnt)); 927 if (retrycnt == 0 && data->id.id_node != NULL) { 928 ral_rssadapt_raise_rate(ic, &rn->rssadapt, 929 &data->id); 930 } 931 ifp->if_opackets++; 932 break; 933 934 case RT2661_TX_RETRY_FAIL: 935 DPRINTFN(9, ("sending data frame failed (too much " 936 "retries)\n")); 937 if (data->id.id_node != NULL) { |
970 ral_rssadapt_lower_rate(ic, data->ni, | 938 ral_rssadapt_lower_rate(ic, ni, |
971 &rn->rssadapt, &data->id); 972 } 973 ifp->if_oerrors++; 974 break; 975 976 default: 977 /* other failure */ 978 device_printf(sc->sc_dev, 979 "sending data frame failed 0x%08x\n", val); 980 ifp->if_oerrors++; 981 } 982 | 939 &rn->rssadapt, &data->id); 940 } 941 ifp->if_oerrors++; 942 break; 943 944 default: 945 /* other failure */ 946 device_printf(sc->sc_dev, 947 "sending data frame failed 0x%08x\n", val); 948 ifp->if_oerrors++; 949 } 950 |
983 ieee80211_free_node(data->ni); 984 data->ni = NULL; 985 | |
986 DPRINTFN(15, ("tx done q=%d idx=%u\n", qid, txq->stat)); 987 988 txq->queued--; 989 if (++txq->stat >= txq->count) /* faster than % count */ 990 txq->stat = 0; | 951 DPRINTFN(15, ("tx done q=%d idx=%u\n", qid, txq->stat)); 952 953 txq->queued--; 954 if (++txq->stat >= txq->count) /* faster than % count */ 955 txq->stat = 0; |
956 957 if (m->m_flags & M_TXCB) 958 ieee80211_process_callback(ni, m, 959 RT2661_TX_RESULT(val) != RT2661_TX_SUCCESS); 960 m_freem(m); 961 ieee80211_free_node(ni); |
|
991 } 992 993 sc->sc_tx_timer = 0; 994 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 995 rt2661_start(ifp); 996} 997 998static void --- 10 unchanged lines hidden (view full) --- 1009 1010 if ((le32toh(desc->flags) & RT2661_TX_BUSY) || 1011 !(le32toh(desc->flags) & RT2661_TX_VALID)) 1012 break; 1013 1014 bus_dmamap_sync(txq->data_dmat, data->map, 1015 BUS_DMASYNC_POSTWRITE); 1016 bus_dmamap_unload(txq->data_dmat, data->map); | 962 } 963 964 sc->sc_tx_timer = 0; 965 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 966 rt2661_start(ifp); 967} 968 969static void --- 10 unchanged lines hidden (view full) --- 980 981 if ((le32toh(desc->flags) & RT2661_TX_BUSY) || 982 !(le32toh(desc->flags) & RT2661_TX_VALID)) 983 break; 984 985 bus_dmamap_sync(txq->data_dmat, data->map, 986 BUS_DMASYNC_POSTWRITE); 987 bus_dmamap_unload(txq->data_dmat, data->map); |
1017 m_freem(data->m); 1018 data->m = NULL; 1019 /* node reference is released in rt2661_tx_intr() */ | |
1020 1021 /* descriptor is no longer valid */ 1022 desc->flags &= ~htole32(RT2661_TX_VALID); 1023 1024 DPRINTFN(15, ("tx dma done q=%p idx=%u\n", txq, txq->next)); 1025 1026 if (++txq->next >= txq->count) /* faster than % count */ 1027 txq->next = 0; --- 15 unchanged lines hidden (view full) --- 1043 struct rt2661_node *rn; 1044 struct mbuf *mnew, *m; 1045 int error; 1046 1047 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, 1048 BUS_DMASYNC_POSTREAD); 1049 1050 for (;;) { | 988 989 /* descriptor is no longer valid */ 990 desc->flags &= ~htole32(RT2661_TX_VALID); 991 992 DPRINTFN(15, ("tx dma done q=%p idx=%u\n", txq, txq->next)); 993 994 if (++txq->next >= txq->count) /* faster than % count */ 995 txq->next = 0; --- 15 unchanged lines hidden (view full) --- 1011 struct rt2661_node *rn; 1012 struct mbuf *mnew, *m; 1013 int error; 1014 1015 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, 1016 BUS_DMASYNC_POSTREAD); 1017 1018 for (;;) { |
1019 int rssi; 1020 |
|
1051 desc = &sc->rxq.desc[sc->rxq.cur]; 1052 data = &sc->rxq.data[sc->rxq.cur]; 1053 1054 if (le32toh(desc->flags) & RT2661_RX_BUSY) 1055 break; 1056 1057 if ((le32toh(desc->flags) & RT2661_RX_PHY_ERROR) || 1058 (le32toh(desc->flags) & RT2661_RX_CRC_ERROR)) { --- 56 unchanged lines hidden (view full) --- 1115 data->m = mnew; 1116 desc->physaddr = htole32(physaddr); 1117 1118 /* finalize mbuf */ 1119 m->m_pkthdr.rcvif = ifp; 1120 m->m_pkthdr.len = m->m_len = 1121 (le32toh(desc->flags) >> 16) & 0xfff; 1122 | 1021 desc = &sc->rxq.desc[sc->rxq.cur]; 1022 data = &sc->rxq.data[sc->rxq.cur]; 1023 1024 if (le32toh(desc->flags) & RT2661_RX_BUSY) 1025 break; 1026 1027 if ((le32toh(desc->flags) & RT2661_RX_PHY_ERROR) || 1028 (le32toh(desc->flags) & RT2661_RX_CRC_ERROR)) { --- 56 unchanged lines hidden (view full) --- 1085 data->m = mnew; 1086 desc->physaddr = htole32(physaddr); 1087 1088 /* finalize mbuf */ 1089 m->m_pkthdr.rcvif = ifp; 1090 m->m_pkthdr.len = m->m_len = 1091 (le32toh(desc->flags) >> 16) & 0xfff; 1092 |
1093 rssi = rt2661_get_rssi(sc, desc->rssi); 1094 |
|
1123 if (bpf_peers_present(sc->sc_drvbpf)) { 1124 struct rt2661_rx_radiotap_header *tap = &sc->sc_rxtap; 1125 uint32_t tsf_lo, tsf_hi; 1126 1127 /* get timestamp (low and high 32 bits) */ 1128 tsf_hi = RAL_READ(sc, RT2661_TXRX_CSR13); 1129 tsf_lo = RAL_READ(sc, RT2661_TXRX_CSR12); 1130 1131 tap->wr_tsf = 1132 htole64(((uint64_t)tsf_hi << 32) | tsf_lo); 1133 tap->wr_flags = 0; 1134 tap->wr_rate = rt2661_rxrate(desc); 1135 tap->wr_chan_freq = htole16(ic->ic_curchan->ic_freq); 1136 tap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); | 1095 if (bpf_peers_present(sc->sc_drvbpf)) { 1096 struct rt2661_rx_radiotap_header *tap = &sc->sc_rxtap; 1097 uint32_t tsf_lo, tsf_hi; 1098 1099 /* get timestamp (low and high 32 bits) */ 1100 tsf_hi = RAL_READ(sc, RT2661_TXRX_CSR13); 1101 tsf_lo = RAL_READ(sc, RT2661_TXRX_CSR12); 1102 1103 tap->wr_tsf = 1104 htole64(((uint64_t)tsf_hi << 32) | tsf_lo); 1105 tap->wr_flags = 0; 1106 tap->wr_rate = rt2661_rxrate(desc); 1107 tap->wr_chan_freq = htole16(ic->ic_curchan->ic_freq); 1108 tap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); |
1137 tap->wr_antsignal = desc->rssi; | 1109 tap->wr_antsignal = rssi < 0 ? 0 : rssi; |
1138 1139 bpf_mtap2(sc->sc_drvbpf, tap, sc->sc_rxtap_len, m); 1140 } | 1110 1111 bpf_mtap2(sc->sc_drvbpf, tap, sc->sc_rxtap_len, m); 1112 } |
1141 | 1113 sc->sc_flags |= RAL_INPUT_RUNNING; 1114 RAL_UNLOCK(sc); |
1142 wh = mtod(m, struct ieee80211_frame *); 1143 ni = ieee80211_find_rxnode(ic, 1144 (struct ieee80211_frame_min *)wh); 1145 | 1115 wh = mtod(m, struct ieee80211_frame *); 1116 ni = ieee80211_find_rxnode(ic, 1117 (struct ieee80211_frame_min *)wh); 1118 |
1119 /* Error happened during RSSI conversion. */ 1120 if (rssi < 0) 1121 rssi = ni->ni_rssi; 1122 |
|
1146 /* send the frame to the 802.11 layer */ | 1123 /* send the frame to the 802.11 layer */ |
1147 ieee80211_input(ic, m, ni, desc->rssi, 0); | 1124 ieee80211_input(ic, m, ni, rssi, RT2661_NOISE_FLOOR, 0); |
1148 1149 /* give rssi to the rate adatation algorithm */ 1150 rn = (struct rt2661_node *)ni; | 1125 1126 /* give rssi to the rate adatation algorithm */ 1127 rn = (struct rt2661_node *)ni; |
1151 ral_rssadapt_input(ic, ni, &rn->rssadapt, 1152 rt2661_get_rssi(sc, desc->rssi)); | 1128 RAL_LOCK(sc); 1129 sc->sc_flags &= ~RAL_INPUT_RUNNING; 1130 ral_rssadapt_input(ic, ni, &rn->rssadapt, rssi); |
1153 1154 /* node is no longer needed */ 1155 ieee80211_free_node(ni); 1156 1157skip: desc->flags |= htole32(RT2661_RX_BUSY); 1158 1159 DPRINTFN(15, ("rx intr idx=%u\n", sc->rxq.cur)); 1160 --- 390 unchanged lines hidden (view full) --- 1551rt2661_tx_data(struct rt2661_softc *sc, struct mbuf *m0, 1552 struct ieee80211_node *ni, int ac) 1553{ 1554 struct ieee80211com *ic = &sc->sc_ic; 1555 struct rt2661_tx_ring *txq = &sc->txq[ac]; 1556 struct rt2661_tx_desc *desc; 1557 struct rt2661_tx_data *data; 1558 struct rt2661_node *rn; | 1131 1132 /* node is no longer needed */ 1133 ieee80211_free_node(ni); 1134 1135skip: desc->flags |= htole32(RT2661_RX_BUSY); 1136 1137 DPRINTFN(15, ("rx intr idx=%u\n", sc->rxq.cur)); 1138 --- 390 unchanged lines hidden (view full) --- 1529rt2661_tx_data(struct rt2661_softc *sc, struct mbuf *m0, 1530 struct ieee80211_node *ni, int ac) 1531{ 1532 struct ieee80211com *ic = &sc->sc_ic; 1533 struct rt2661_tx_ring *txq = &sc->txq[ac]; 1534 struct rt2661_tx_desc *desc; 1535 struct rt2661_tx_data *data; 1536 struct rt2661_node *rn; |
1559 struct ieee80211_rateset *rs; | |
1560 struct ieee80211_frame *wh; 1561 struct ieee80211_key *k; 1562 const struct chanAccParams *cap; 1563 struct mbuf *mnew; 1564 bus_dma_segment_t segs[RT2661_MAX_SCATTER]; 1565 uint16_t dur; 1566 uint32_t flags = 0; 1567 int error, nsegs, rate, noack = 0; 1568 1569 wh = mtod(m0, struct ieee80211_frame *); 1570 1571 if (ic->ic_fixed_rate != IEEE80211_FIXED_RATE_NONE) { | 1537 struct ieee80211_frame *wh; 1538 struct ieee80211_key *k; 1539 const struct chanAccParams *cap; 1540 struct mbuf *mnew; 1541 bus_dma_segment_t segs[RT2661_MAX_SCATTER]; 1542 uint16_t dur; 1543 uint32_t flags = 0; 1544 int error, nsegs, rate, noack = 0; 1545 1546 wh = mtod(m0, struct ieee80211_frame *); 1547 1548 if (ic->ic_fixed_rate != IEEE80211_FIXED_RATE_NONE) { |
1572 rs = &ic->ic_sup_rates[ic->ic_curmode]; 1573 rate = rs->rs_rates[ic->ic_fixed_rate]; | 1549 rate = ic->ic_fixed_rate; |
1574 } else { | 1550 } else { |
1551 struct ieee80211_rateset *rs; 1552 |
|
1575 rs = &ni->ni_rates; 1576 rn = (struct rt2661_node *)ni; 1577 ni->ni_txrate = ral_rssadapt_choose(&rn->rssadapt, rs, 1578 wh, m0->m_pkthdr.len, NULL, 0); 1579 rate = rs->rs_rates[ni->ni_txrate]; 1580 } 1581 rate &= IEEE80211_RATE_VAL; 1582 --- 165 unchanged lines hidden (view full) --- 1748 struct mbuf *m0; 1749 struct ether_header *eh; 1750 struct ieee80211_node *ni; 1751 int ac; 1752 1753 RAL_LOCK(sc); 1754 1755 /* prevent management frames from being sent if we're not ready */ | 1553 rs = &ni->ni_rates; 1554 rn = (struct rt2661_node *)ni; 1555 ni->ni_txrate = ral_rssadapt_choose(&rn->rssadapt, rs, 1556 wh, m0->m_pkthdr.len, NULL, 0); 1557 rate = rs->rs_rates[ni->ni_txrate]; 1558 } 1559 rate &= IEEE80211_RATE_VAL; 1560 --- 165 unchanged lines hidden (view full) --- 1726 struct mbuf *m0; 1727 struct ether_header *eh; 1728 struct ieee80211_node *ni; 1729 int ac; 1730 1731 RAL_LOCK(sc); 1732 1733 /* prevent management frames from being sent if we're not ready */ |
1756 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { | 1734 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING) || sc->sc_invalid) { |
1757 RAL_UNLOCK(sc); 1758 return; 1759 } 1760 1761 for (;;) { 1762 IF_POLL(&ic->ic_mgtq, m0); 1763 if (m0 != NULL) { 1764 if (sc->mgtq.queued >= RT2661_MGT_RING_COUNT) { 1765 ifp->if_drv_flags |= IFF_DRV_OACTIVE; 1766 break; 1767 } 1768 IF_DEQUEUE(&ic->ic_mgtq, m0); 1769 1770 ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif; 1771 m0->m_pkthdr.rcvif = NULL; 1772 1773 if (bpf_peers_present(ic->ic_rawbpf)) 1774 bpf_mtap(ic->ic_rawbpf, m0); 1775 | 1735 RAL_UNLOCK(sc); 1736 return; 1737 } 1738 1739 for (;;) { 1740 IF_POLL(&ic->ic_mgtq, m0); 1741 if (m0 != NULL) { 1742 if (sc->mgtq.queued >= RT2661_MGT_RING_COUNT) { 1743 ifp->if_drv_flags |= IFF_DRV_OACTIVE; 1744 break; 1745 } 1746 IF_DEQUEUE(&ic->ic_mgtq, m0); 1747 1748 ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif; 1749 m0->m_pkthdr.rcvif = NULL; 1750 1751 if (bpf_peers_present(ic->ic_rawbpf)) 1752 bpf_mtap(ic->ic_rawbpf, m0); 1753 |
1776 if (rt2661_tx_mgt(sc, m0, ni) != 0) | 1754 if (rt2661_tx_mgt(sc, m0, ni) != 0) { 1755 ieee80211_free_node(ni); |
1777 break; | 1756 break; |
1778 | 1757 } |
1779 } else { 1780 if (ic->ic_state != IEEE80211_S_RUN) 1781 break; 1782 1783 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0); 1784 if (m0 == NULL) 1785 break; 1786 --- 20 unchanged lines hidden (view full) --- 1807 /* no QoS encapsulation for EAPOL frames */ 1808 ac = (eh->ether_type != htons(ETHERTYPE_PAE)) ? 1809 M_WME_GETAC(m0) : WME_AC_BE; 1810 1811 if (sc->txq[ac].queued >= RT2661_TX_RING_COUNT - 1) { 1812 /* there is no place left in this ring */ 1813 IFQ_DRV_PREPEND(&ifp->if_snd, m0); 1814 ifp->if_drv_flags |= IFF_DRV_OACTIVE; | 1758 } else { 1759 if (ic->ic_state != IEEE80211_S_RUN) 1760 break; 1761 1762 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0); 1763 if (m0 == NULL) 1764 break; 1765 --- 20 unchanged lines hidden (view full) --- 1786 /* no QoS encapsulation for EAPOL frames */ 1787 ac = (eh->ether_type != htons(ETHERTYPE_PAE)) ? 1788 M_WME_GETAC(m0) : WME_AC_BE; 1789 1790 if (sc->txq[ac].queued >= RT2661_TX_RING_COUNT - 1) { 1791 /* there is no place left in this ring */ 1792 IFQ_DRV_PREPEND(&ifp->if_snd, m0); 1793 ifp->if_drv_flags |= IFF_DRV_OACTIVE; |
1794 ieee80211_free_node(ni); |
|
1815 break; 1816 } 1817 1818 BPF_MTAP(ifp, m0); 1819 1820 m0 = ieee80211_encap(ic, m0, ni); 1821 if (m0 == NULL) { 1822 ieee80211_free_node(ni); --- 17 unchanged lines hidden (view full) --- 1840 1841 RAL_UNLOCK(sc); 1842} 1843 1844static void 1845rt2661_watchdog(void *arg) 1846{ 1847 struct rt2661_softc *sc = (struct rt2661_softc *)arg; | 1795 break; 1796 } 1797 1798 BPF_MTAP(ifp, m0); 1799 1800 m0 = ieee80211_encap(ic, m0, ni); 1801 if (m0 == NULL) { 1802 ieee80211_free_node(ni); --- 17 unchanged lines hidden (view full) --- 1820 1821 RAL_UNLOCK(sc); 1822} 1823 1824static void 1825rt2661_watchdog(void *arg) 1826{ 1827 struct rt2661_softc *sc = (struct rt2661_softc *)arg; |
1848 struct ieee80211com *ic = &sc->sc_ic; | |
1849 | 1828 |
1850 if (sc->sc_tx_timer > 0) { | 1829 if (sc->sc_tx_timer > 0 && !sc->sc_invalid) { |
1851 if (--sc->sc_tx_timer == 0) { 1852 device_printf(sc->sc_dev, "device timeout\n"); 1853 rt2661_init(sc); 1854 sc->sc_ifp->if_oerrors++; 1855 return; 1856 } 1857 callout_reset(&sc->watchdog_ch, hz, rt2661_watchdog, sc); 1858 } | 1830 if (--sc->sc_tx_timer == 0) { 1831 device_printf(sc->sc_dev, "device timeout\n"); 1832 rt2661_init(sc); 1833 sc->sc_ifp->if_oerrors++; 1834 return; 1835 } 1836 callout_reset(&sc->watchdog_ch, hz, rt2661_watchdog, sc); 1837 } |
1859 1860 ieee80211_watchdog(ic); | |
1861} 1862 1863/* 1864 * This function allows for fast channel switching in monitor mode (used by 1865 * net-mgmt/kismet). In IBSS mode, we must explicitly reset the interface to 1866 * generate a new beacon frame. 1867 */ 1868static int --- 12 unchanged lines hidden (view full) --- 1881 1882static int 1883rt2661_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) 1884{ 1885 struct rt2661_softc *sc = ifp->if_softc; 1886 struct ieee80211com *ic = &sc->sc_ic; 1887 int error = 0; 1888 | 1838} 1839 1840/* 1841 * This function allows for fast channel switching in monitor mode (used by 1842 * net-mgmt/kismet). In IBSS mode, we must explicitly reset the interface to 1843 * generate a new beacon frame. 1844 */ 1845static int --- 12 unchanged lines hidden (view full) --- 1858 1859static int 1860rt2661_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) 1861{ 1862 struct rt2661_softc *sc = ifp->if_softc; 1863 struct ieee80211com *ic = &sc->sc_ic; 1864 int error = 0; 1865 |
1889 RAL_LOCK(sc); 1890 | |
1891 switch (cmd) { 1892 case SIOCSIFFLAGS: 1893 if (ifp->if_flags & IFF_UP) { 1894 if (ifp->if_drv_flags & IFF_DRV_RUNNING) 1895 rt2661_update_promisc(sc); 1896 else 1897 rt2661_init(sc); 1898 } else { --- 9 unchanged lines hidden (view full) --- 1908 if (error == ENETRESET) { 1909 if ((ifp->if_flags & IFF_UP) && 1910 (ifp->if_drv_flags & IFF_DRV_RUNNING) && 1911 (ic->ic_roaming != IEEE80211_ROAMING_MANUAL)) 1912 rt2661_init(sc); 1913 error = 0; 1914 } 1915 | 1866 switch (cmd) { 1867 case SIOCSIFFLAGS: 1868 if (ifp->if_flags & IFF_UP) { 1869 if (ifp->if_drv_flags & IFF_DRV_RUNNING) 1870 rt2661_update_promisc(sc); 1871 else 1872 rt2661_init(sc); 1873 } else { --- 9 unchanged lines hidden (view full) --- 1883 if (error == ENETRESET) { 1884 if ((ifp->if_flags & IFF_UP) && 1885 (ifp->if_drv_flags & IFF_DRV_RUNNING) && 1886 (ic->ic_roaming != IEEE80211_ROAMING_MANUAL)) 1887 rt2661_init(sc); 1888 error = 0; 1889 } 1890 |
1916 RAL_UNLOCK(sc); 1917 | |
1918 return error; 1919} 1920 1921static void 1922rt2661_bbp_write(struct rt2661_softc *sc, uint8_t reg, uint8_t val) 1923{ 1924 uint32_t tmp; 1925 int ntries; --- 135 unchanged lines hidden (view full) --- 2061 2062 tmp &= ~RT2661_SHORT_PREAMBLE; 2063 if (sc->sc_ic.ic_flags & IEEE80211_F_SHPREAMBLE) 2064 tmp |= RT2661_SHORT_PREAMBLE; 2065 2066 RAL_WRITE(sc, RT2661_TXRX_CSR4, tmp); 2067} 2068 | 1891 return error; 1892} 1893 1894static void 1895rt2661_bbp_write(struct rt2661_softc *sc, uint8_t reg, uint8_t val) 1896{ 1897 uint32_t tmp; 1898 int ntries; --- 135 unchanged lines hidden (view full) --- 2034 2035 tmp &= ~RT2661_SHORT_PREAMBLE; 2036 if (sc->sc_ic.ic_flags & IEEE80211_F_SHPREAMBLE) 2037 tmp |= RT2661_SHORT_PREAMBLE; 2038 2039 RAL_WRITE(sc, RT2661_TXRX_CSR4, tmp); 2040} 2041 |
2042/* 2043 * Supported rates for 802.11g. XXX should use ic_sup_rates. 2044 */ 2045static const struct ieee80211_rateset rt2661_rateset_11g = 2046 { 12, { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 } }; 2047 |
|
2069static void 2070rt2661_set_basicrates(struct rt2661_softc *sc, 2071 const struct ieee80211_rateset *rs) 2072{ 2073#define RV(r) ((r) & IEEE80211_RATE_VAL) 2074 struct ieee80211com *ic = &sc->sc_ic; 2075 uint32_t mask = 0; 2076 uint8_t rate; --- 291 unchanged lines hidden (view full) --- 2368 2369 DPRINTF(("External 2GHz LNA=%d\nExternal 5GHz LNA=%d\n", 2370 sc->ext_2ghz_lna, sc->ext_5ghz_lna)); 2371 2372 val = rt2661_eeprom_read(sc, RT2661_EEPROM_RSSI_2GHZ_OFFSET); 2373 if ((val & 0xff) != 0xff) 2374 sc->rssi_2ghz_corr = (int8_t)(val & 0xff); /* signed */ 2375 | 2048static void 2049rt2661_set_basicrates(struct rt2661_softc *sc, 2050 const struct ieee80211_rateset *rs) 2051{ 2052#define RV(r) ((r) & IEEE80211_RATE_VAL) 2053 struct ieee80211com *ic = &sc->sc_ic; 2054 uint32_t mask = 0; 2055 uint8_t rate; --- 291 unchanged lines hidden (view full) --- 2347 2348 DPRINTF(("External 2GHz LNA=%d\nExternal 5GHz LNA=%d\n", 2349 sc->ext_2ghz_lna, sc->ext_5ghz_lna)); 2350 2351 val = rt2661_eeprom_read(sc, RT2661_EEPROM_RSSI_2GHZ_OFFSET); 2352 if ((val & 0xff) != 0xff) 2353 sc->rssi_2ghz_corr = (int8_t)(val & 0xff); /* signed */ 2354 |
2355 /* Only [-10, 10] is valid */ 2356 if (sc->rssi_2ghz_corr < -10 || sc->rssi_2ghz_corr > 10) 2357 sc->rssi_2ghz_corr = 0; 2358 |
|
2376 val = rt2661_eeprom_read(sc, RT2661_EEPROM_RSSI_5GHZ_OFFSET); 2377 if ((val & 0xff) != 0xff) 2378 sc->rssi_5ghz_corr = (int8_t)(val & 0xff); /* signed */ 2379 | 2359 val = rt2661_eeprom_read(sc, RT2661_EEPROM_RSSI_5GHZ_OFFSET); 2360 if ((val & 0xff) != 0xff) 2361 sc->rssi_5ghz_corr = (int8_t)(val & 0xff); /* signed */ 2362 |
2363 /* Only [-10, 10] is valid */ 2364 if (sc->rssi_5ghz_corr < -10 || sc->rssi_5ghz_corr > 10) 2365 sc->rssi_5ghz_corr = 0; 2366 |
|
2380 /* adjust RSSI correction for external low-noise amplifier */ 2381 if (sc->ext_2ghz_lna) 2382 sc->rssi_2ghz_corr -= 14; 2383 if (sc->ext_5ghz_lna) 2384 sc->rssi_5ghz_corr -= 14; 2385 2386 DPRINTF(("RSSI 2GHz corr=%d\nRSSI 5GHz corr=%d\n", 2387 sc->rssi_2ghz_corr, sc->rssi_5ghz_corr)); --- 72 unchanged lines hidden (view full) --- 2460 struct rt2661_softc *sc = priv; 2461 struct ieee80211com *ic = &sc->sc_ic; 2462 struct ifnet *ifp = ic->ic_ifp; 2463 uint32_t tmp, sta[3]; 2464 int i, ntries; 2465 2466 RAL_LOCK(sc); 2467 | 2367 /* adjust RSSI correction for external low-noise amplifier */ 2368 if (sc->ext_2ghz_lna) 2369 sc->rssi_2ghz_corr -= 14; 2370 if (sc->ext_5ghz_lna) 2371 sc->rssi_5ghz_corr -= 14; 2372 2373 DPRINTF(("RSSI 2GHz corr=%d\nRSSI 5GHz corr=%d\n", 2374 sc->rssi_2ghz_corr, sc->rssi_5ghz_corr)); --- 72 unchanged lines hidden (view full) --- 2447 struct rt2661_softc *sc = priv; 2448 struct ieee80211com *ic = &sc->sc_ic; 2449 struct ifnet *ifp = ic->ic_ifp; 2450 uint32_t tmp, sta[3]; 2451 int i, ntries; 2452 2453 RAL_LOCK(sc); 2454 |
2468 rt2661_stop(sc); | 2455 rt2661_stop_locked(sc); |
2469 2470 /* initialize Tx rings */ 2471 RAL_WRITE(sc, RT2661_AC1_BASE_CSR, sc->txq[1].physaddr); 2472 RAL_WRITE(sc, RT2661_AC0_BASE_CSR, sc->txq[0].physaddr); 2473 RAL_WRITE(sc, RT2661_AC2_BASE_CSR, sc->txq[2].physaddr); 2474 RAL_WRITE(sc, RT2661_AC3_BASE_CSR, sc->txq[3].physaddr); 2475 2476 /* initialize Mgt ring */ --- 43 unchanged lines hidden (view full) --- 2520 /* wait for BBP/RF to wakeup */ 2521 for (ntries = 0; ntries < 1000; ntries++) { 2522 if (RAL_READ(sc, RT2661_MAC_CSR12) & 8) 2523 break; 2524 DELAY(1000); 2525 } 2526 if (ntries == 1000) { 2527 printf("timeout waiting for BBP/RF to wakeup\n"); | 2456 2457 /* initialize Tx rings */ 2458 RAL_WRITE(sc, RT2661_AC1_BASE_CSR, sc->txq[1].physaddr); 2459 RAL_WRITE(sc, RT2661_AC0_BASE_CSR, sc->txq[0].physaddr); 2460 RAL_WRITE(sc, RT2661_AC2_BASE_CSR, sc->txq[2].physaddr); 2461 RAL_WRITE(sc, RT2661_AC3_BASE_CSR, sc->txq[3].physaddr); 2462 2463 /* initialize Mgt ring */ --- 43 unchanged lines hidden (view full) --- 2507 /* wait for BBP/RF to wakeup */ 2508 for (ntries = 0; ntries < 1000; ntries++) { 2509 if (RAL_READ(sc, RT2661_MAC_CSR12) & 8) 2510 break; 2511 DELAY(1000); 2512 } 2513 if (ntries == 1000) { 2514 printf("timeout waiting for BBP/RF to wakeup\n"); |
2528 rt2661_stop(sc); | 2515 rt2661_stop_locked(sc); |
2529 RAL_UNLOCK(sc); 2530 return; 2531 } 2532 2533 if (rt2661_bbp_init(sc) != 0) { | 2516 RAL_UNLOCK(sc); 2517 return; 2518 } 2519 2520 if (rt2661_bbp_init(sc) != 0) { |
2534 rt2661_stop(sc); | 2521 rt2661_stop_locked(sc); |
2535 RAL_UNLOCK(sc); 2536 return; 2537 } 2538 2539 /* select default channel */ 2540 sc->sc_curchan = ic->ic_curchan; 2541 rt2661_select_band(sc, sc->sc_curchan); 2542 rt2661_select_antenna(sc); --- 24 unchanged lines hidden (view full) --- 2567 RAL_WRITE(sc, RT2661_INT_SOURCE_CSR, 0xffffffff); 2568 2569 /* enable interrupts */ 2570 RAL_WRITE(sc, RT2661_INT_MASK_CSR, 0x0000ff10); 2571 RAL_WRITE(sc, RT2661_MCU_INT_MASK_CSR, 0); 2572 2573 /* kick Rx */ 2574 RAL_WRITE(sc, RT2661_RX_CNTL_CSR, 1); | 2522 RAL_UNLOCK(sc); 2523 return; 2524 } 2525 2526 /* select default channel */ 2527 sc->sc_curchan = ic->ic_curchan; 2528 rt2661_select_band(sc, sc->sc_curchan); 2529 rt2661_select_antenna(sc); --- 24 unchanged lines hidden (view full) --- 2554 RAL_WRITE(sc, RT2661_INT_SOURCE_CSR, 0xffffffff); 2555 2556 /* enable interrupts */ 2557 RAL_WRITE(sc, RT2661_INT_MASK_CSR, 0x0000ff10); 2558 RAL_WRITE(sc, RT2661_MCU_INT_MASK_CSR, 0); 2559 2560 /* kick Rx */ 2561 RAL_WRITE(sc, RT2661_RX_CNTL_CSR, 1); |
2562 RAL_UNLOCK(sc); |
|
2575 2576 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 2577 ifp->if_drv_flags |= IFF_DRV_RUNNING; 2578 2579 if (ic->ic_opmode != IEEE80211_M_MONITOR) { 2580 if (ic->ic_roaming != IEEE80211_ROAMING_MANUAL) 2581 ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); 2582 } else 2583 ieee80211_new_state(ic, IEEE80211_S_RUN, -1); 2584 | 2563 2564 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 2565 ifp->if_drv_flags |= IFF_DRV_RUNNING; 2566 2567 if (ic->ic_opmode != IEEE80211_M_MONITOR) { 2568 if (ic->ic_roaming != IEEE80211_ROAMING_MANUAL) 2569 ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); 2570 } else 2571 ieee80211_new_state(ic, IEEE80211_S_RUN, -1); 2572 |
2585 RAL_UNLOCK(sc); | 2573 |
2586#undef N 2587} 2588 2589void 2590rt2661_stop(void *priv) 2591{ 2592 struct rt2661_softc *sc = priv; | 2574#undef N 2575} 2576 2577void 2578rt2661_stop(void *priv) 2579{ 2580 struct rt2661_softc *sc = priv; |
2581 2582 RAL_LOCK(sc); 2583 rt2661_stop_locked(sc); 2584 RAL_UNLOCK(sc); 2585} 2586 2587void 2588rt2661_stop_locked(struct rt2661_softc *sc) 2589{ |
|
2593 struct ieee80211com *ic = &sc->sc_ic; 2594 struct ifnet *ifp = ic->ic_ifp; 2595 uint32_t tmp; | 2590 struct ieee80211com *ic = &sc->sc_ic; 2591 struct ifnet *ifp = ic->ic_ifp; 2592 uint32_t tmp; |
2593 volatile int *flags = &sc->sc_flags; |
|
2596 | 2594 |
2597 sc->sc_tx_timer = 0; 2598 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); | 2595 while (*flags & RAL_INPUT_RUNNING) { 2596 msleep(sc, &sc->sc_mtx, 0, "ralrunning", hz/10); 2597 } |
2599 | 2598 |
2600 ieee80211_new_state(ic, IEEE80211_S_INIT, -1); 2601 2602 /* abort Tx (for all 5 Tx rings) */ 2603 RAL_WRITE(sc, RT2661_TX_CNTL_CSR, 0x1f << 16); 2604 2605 /* disable Rx (value remains after reset!) */ 2606 tmp = RAL_READ(sc, RT2661_TXRX_CSR0); 2607 RAL_WRITE(sc, RT2661_TXRX_CSR0, tmp | RT2661_DISABLE_RX); 2608 2609 /* reset ASIC */ 2610 RAL_WRITE(sc, RT2661_MAC_CSR1, 3); 2611 RAL_WRITE(sc, RT2661_MAC_CSR1, 0); 2612 2613 /* disable interrupts */ 2614 RAL_WRITE(sc, RT2661_INT_MASK_CSR, 0xffffffff); 2615 RAL_WRITE(sc, RT2661_MCU_INT_MASK_CSR, 0xffffffff); 2616 2617 /* clear any pending interrupt */ 2618 RAL_WRITE(sc, RT2661_INT_SOURCE_CSR, 0xffffffff); 2619 RAL_WRITE(sc, RT2661_MCU_INT_SOURCE_CSR, 0xffffffff); 2620 2621 /* reset Tx and Rx rings */ 2622 rt2661_reset_tx_ring(sc, &sc->txq[0]); 2623 rt2661_reset_tx_ring(sc, &sc->txq[1]); 2624 rt2661_reset_tx_ring(sc, &sc->txq[2]); 2625 rt2661_reset_tx_ring(sc, &sc->txq[3]); 2626 rt2661_reset_tx_ring(sc, &sc->mgtq); 2627 rt2661_reset_rx_ring(sc, &sc->rxq); | 2599 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 2600 sc->sc_tx_timer = 0; 2601 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); 2602 2603 ieee80211_new_state(ic, IEEE80211_S_INIT, -1); 2604 2605 /* abort Tx (for all 5 Tx rings) */ 2606 RAL_WRITE(sc, RT2661_TX_CNTL_CSR, 0x1f << 16); 2607 2608 /* disable Rx (value remains after reset!) */ 2609 tmp = RAL_READ(sc, RT2661_TXRX_CSR0); 2610 RAL_WRITE(sc, RT2661_TXRX_CSR0, tmp | RT2661_DISABLE_RX); 2611 2612 /* reset ASIC */ 2613 RAL_WRITE(sc, RT2661_MAC_CSR1, 3); 2614 RAL_WRITE(sc, RT2661_MAC_CSR1, 0); 2615 2616 /* disable interrupts */ 2617 RAL_WRITE(sc, RT2661_INT_MASK_CSR, 0xffffffff); 2618 RAL_WRITE(sc, RT2661_MCU_INT_MASK_CSR, 0xffffffff); 2619 2620 /* clear any pending interrupt */ 2621 RAL_WRITE(sc, RT2661_INT_SOURCE_CSR, 0xffffffff); 2622 RAL_WRITE(sc, RT2661_MCU_INT_SOURCE_CSR, 0xffffffff); 2623 2624 /* reset Tx and Rx rings */ 2625 rt2661_reset_tx_ring(sc, &sc->txq[0]); 2626 rt2661_reset_tx_ring(sc, &sc->txq[1]); 2627 rt2661_reset_tx_ring(sc, &sc->txq[2]); 2628 rt2661_reset_tx_ring(sc, &sc->txq[3]); 2629 rt2661_reset_tx_ring(sc, &sc->mgtq); 2630 rt2661_reset_rx_ring(sc, &sc->rxq); 2631 } |
2628} 2629 2630static int 2631rt2661_load_microcode(struct rt2661_softc *sc, const uint8_t *ucode, int size) 2632{ 2633 int ntries; 2634 2635 /* reset 8051 */ --- 217 unchanged lines hidden (view full) --- 2853static int 2854rt2661_get_rssi(struct rt2661_softc *sc, uint8_t raw) 2855{ 2856 int lna, agc, rssi; 2857 2858 lna = (raw >> 5) & 0x3; 2859 agc = raw & 0x1f; 2860 | 2632} 2633 2634static int 2635rt2661_load_microcode(struct rt2661_softc *sc, const uint8_t *ucode, int size) 2636{ 2637 int ntries; 2638 2639 /* reset 8051 */ --- 217 unchanged lines hidden (view full) --- 2857static int 2858rt2661_get_rssi(struct rt2661_softc *sc, uint8_t raw) 2859{ 2860 int lna, agc, rssi; 2861 2862 lna = (raw >> 5) & 0x3; 2863 agc = raw & 0x1f; 2864 |
2861 rssi = 2 * agc; | 2865 if (lna == 0) { 2866 /* 2867 * No mapping available. 2868 * 2869 * NB: Since RSSI is relative to noise floor, -1 is 2870 * adequate for caller to know error happened. 2871 */ 2872 return -1; 2873 } |
2862 | 2874 |
2875 rssi = (2 * agc) - RT2661_NOISE_FLOOR; 2876 |
|
2863 if (IEEE80211_IS_CHAN_2GHZ(sc->sc_curchan)) { 2864 rssi += sc->rssi_2ghz_corr; 2865 2866 if (lna == 1) 2867 rssi -= 64; 2868 else if (lna == 2) 2869 rssi -= 74; 2870 else if (lna == 3) --- 5 unchanged lines hidden (view full) --- 2876 rssi -= 64; 2877 else if (lna == 2) 2878 rssi -= 86; 2879 else if (lna == 3) 2880 rssi -= 100; 2881 } 2882 return rssi; 2883} | 2877 if (IEEE80211_IS_CHAN_2GHZ(sc->sc_curchan)) { 2878 rssi += sc->rssi_2ghz_corr; 2879 2880 if (lna == 1) 2881 rssi -= 64; 2882 else if (lna == 2) 2883 rssi -= 74; 2884 else if (lna == 3) --- 5 unchanged lines hidden (view full) --- 2890 rssi -= 64; 2891 else if (lna == 2) 2892 rssi -= 86; 2893 else if (lna == 3) 2894 rssi -= 100; 2895 } 2896 return rssi; 2897} |
2898 2899static void 2900rt2661_scan_start(struct ieee80211com *ic) 2901{ 2902 struct ifnet *ifp = ic->ic_ifp; 2903 struct rt2661_softc *sc = ifp->if_softc; 2904 uint32_t tmp; 2905 2906 /* abort TSF synchronization */ 2907 tmp = RAL_READ(sc, RT2661_TXRX_CSR9); 2908 RAL_WRITE(sc, RT2661_TXRX_CSR9, tmp & ~0xffffff); 2909 rt2661_set_bssid(sc, ifp->if_broadcastaddr); 2910} 2911 2912static void 2913rt2661_scan_end(struct ieee80211com *ic) 2914{ 2915 struct ifnet *ifp = ic->ic_ifp; 2916 struct rt2661_softc *sc = ifp->if_softc; 2917 2918 rt2661_enable_tsf_sync(sc); 2919 /* XXX keep local copy */ 2920 rt2661_set_bssid(sc, ic->ic_bss->ni_bssid); 2921} 2922 2923static void 2924rt2661_set_channel(struct ieee80211com *ic) 2925{ 2926 struct ifnet *ifp = ic->ic_ifp; 2927 struct rt2661_softc *sc = ifp->if_softc; 2928 2929 RAL_LOCK(sc); 2930 rt2661_set_chan(sc, ic->ic_curchan); 2931 RAL_UNLOCK(sc); 2932 2933} |
|