if_rum.c (203141) | if_rum.c (206358) |
---|---|
1/* $FreeBSD: head/sys/dev/usb/wlan/if_rum.c 203141 2010-01-29 02:31:33Z thompsa $ */ | 1/* $FreeBSD: head/sys/dev/usb/wlan/if_rum.c 206358 2010-04-07 15:29:13Z rpaulo $ */ |
2 3/*- 4 * Copyright (c) 2005-2007 Damien Bergamini <damien.bergamini@free.fr> 5 * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org> 6 * Copyright (c) 2007-2008 Hans Petter Selasky <hselasky@FreeBSD.org> 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above --- 4 unchanged lines hidden (view full) --- 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 */ 20 21#include <sys/cdefs.h> | 2 3/*- 4 * Copyright (c) 2005-2007 Damien Bergamini <damien.bergamini@free.fr> 5 * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org> 6 * Copyright (c) 2007-2008 Hans Petter Selasky <hselasky@FreeBSD.org> 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above --- 4 unchanged lines hidden (view full) --- 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 */ 20 21#include <sys/cdefs.h> |
22__FBSDID("$FreeBSD: head/sys/dev/usb/wlan/if_rum.c 203141 2010-01-29 02:31:33Z thompsa $"); | 22__FBSDID("$FreeBSD: head/sys/dev/usb/wlan/if_rum.c 206358 2010-04-07 15:29:13Z rpaulo $"); |
23 24/*- 25 * Ralink Technology RT2501USB/RT2601USB chipset driver 26 * http://www.ralinktech.com.tw/ 27 */ 28 29#include <sys/param.h> 30#include <sys/sockio.h> --- 28 unchanged lines hidden (view full) --- 59#include <netinet/in_var.h> 60#include <netinet/if_ether.h> 61#include <netinet/ip.h> 62#endif 63 64#include <net80211/ieee80211_var.h> 65#include <net80211/ieee80211_regdomain.h> 66#include <net80211/ieee80211_radiotap.h> | 23 24/*- 25 * Ralink Technology RT2501USB/RT2601USB chipset driver 26 * http://www.ralinktech.com.tw/ 27 */ 28 29#include <sys/param.h> 30#include <sys/sockio.h> --- 28 unchanged lines hidden (view full) --- 59#include <netinet/in_var.h> 60#include <netinet/if_ether.h> 61#include <netinet/ip.h> 62#endif 63 64#include <net80211/ieee80211_var.h> 65#include <net80211/ieee80211_regdomain.h> 66#include <net80211/ieee80211_radiotap.h> |
67#include <net80211/ieee80211_amrr.h> | 67#include <net80211/ieee80211_ratectl.h> |
68 69#include <dev/usb/usb.h> 70#include <dev/usb/usbdi.h> 71#include "usbdevs.h" 72 73#define USB_DEBUG_VAR rum_debug 74#include <dev/usb/usb_debug.h> 75 --- 59 unchanged lines hidden (view full) --- 135 RUM_DEV(SITECOMEU, WL113R2), 136 RUM_DEV(SITECOMEU, WL172), 137 RUM_DEV(SPARKLAN, RT2573), 138 RUM_DEV(SURECOM, RT2573), 139#undef RUM_DEV 140}; 141 142MODULE_DEPEND(rum, wlan, 1, 1, 1); | 68 69#include <dev/usb/usb.h> 70#include <dev/usb/usbdi.h> 71#include "usbdevs.h" 72 73#define USB_DEBUG_VAR rum_debug 74#include <dev/usb/usb_debug.h> 75 --- 59 unchanged lines hidden (view full) --- 135 RUM_DEV(SITECOMEU, WL113R2), 136 RUM_DEV(SITECOMEU, WL172), 137 RUM_DEV(SPARKLAN, RT2573), 138 RUM_DEV(SURECOM, RT2573), 139#undef RUM_DEV 140}; 141 142MODULE_DEPEND(rum, wlan, 1, 1, 1); |
143MODULE_DEPEND(rum, wlan_amrr, 1, 1, 1); | |
144MODULE_DEPEND(rum, usb, 1, 1, 1); 145 146static device_probe_t rum_match; 147static device_attach_t rum_attach; 148static device_detach_t rum_detach; 149 150static usb_callback_t rum_bulk_read_callback; 151static usb_callback_t rum_bulk_write_callback; --- 55 unchanged lines hidden (view full) --- 207static void rum_init(void *); 208static void rum_stop(struct rum_softc *); 209static void rum_load_microcode(struct rum_softc *, const uint8_t *, 210 size_t); 211static int rum_prepare_beacon(struct rum_softc *, 212 struct ieee80211vap *); 213static int rum_raw_xmit(struct ieee80211_node *, struct mbuf *, 214 const struct ieee80211_bpf_params *); | 143MODULE_DEPEND(rum, usb, 1, 1, 1); 144 145static device_probe_t rum_match; 146static device_attach_t rum_attach; 147static device_detach_t rum_detach; 148 149static usb_callback_t rum_bulk_read_callback; 150static usb_callback_t rum_bulk_write_callback; --- 55 unchanged lines hidden (view full) --- 206static void rum_init(void *); 207static void rum_stop(struct rum_softc *); 208static void rum_load_microcode(struct rum_softc *, const uint8_t *, 209 size_t); 210static int rum_prepare_beacon(struct rum_softc *, 211 struct ieee80211vap *); 212static int rum_raw_xmit(struct ieee80211_node *, struct mbuf *, 213 const struct ieee80211_bpf_params *); |
215static struct ieee80211_node *rum_node_alloc(struct ieee80211vap *, 216 const uint8_t mac[IEEE80211_ADDR_LEN]); 217static void rum_newassoc(struct ieee80211_node *, int); | |
218static void rum_scan_start(struct ieee80211com *); 219static void rum_scan_end(struct ieee80211com *); 220static void rum_set_channel(struct ieee80211com *); 221static int rum_get_rssi(struct rum_softc *, uint8_t); | 214static void rum_scan_start(struct ieee80211com *); 215static void rum_scan_end(struct ieee80211com *); 216static void rum_set_channel(struct ieee80211com *); 217static int rum_get_rssi(struct rum_softc *, uint8_t); |
222static void rum_amrr_start(struct rum_softc *, | 218static void rum_ratectl_start(struct rum_softc *, |
223 struct ieee80211_node *); | 219 struct ieee80211_node *); |
224static void rum_amrr_timeout(void *); 225static void rum_amrr_task(void *, int); | 220static void rum_ratectl_timeout(void *); 221static void rum_ratectl_task(void *, int); |
226static int rum_pause(struct rum_softc *, int); 227 228static const struct { 229 uint32_t reg; 230 uint32_t val; 231} rum_def_mac[] = { 232 { RT2573_TXRX_CSR0, 0x025fb032 }, 233 { RT2573_TXRX_CSR1, 0x9eaa9eaf }, --- 272 unchanged lines hidden (view full) --- 506 setbit(&bands, IEEE80211_MODE_11B); 507 setbit(&bands, IEEE80211_MODE_11G); 508 if (sc->rf_rev == RT2573_RF_5225 || sc->rf_rev == RT2573_RF_5226) 509 setbit(&bands, IEEE80211_MODE_11A); 510 ieee80211_init_channels(ic, NULL, &bands); 511 512 ieee80211_ifattach(ic, sc->sc_bssid); 513 ic->ic_update_promisc = rum_update_promisc; | 222static int rum_pause(struct rum_softc *, int); 223 224static const struct { 225 uint32_t reg; 226 uint32_t val; 227} rum_def_mac[] = { 228 { RT2573_TXRX_CSR0, 0x025fb032 }, 229 { RT2573_TXRX_CSR1, 0x9eaa9eaf }, --- 272 unchanged lines hidden (view full) --- 502 setbit(&bands, IEEE80211_MODE_11B); 503 setbit(&bands, IEEE80211_MODE_11G); 504 if (sc->rf_rev == RT2573_RF_5225 || sc->rf_rev == RT2573_RF_5226) 505 setbit(&bands, IEEE80211_MODE_11A); 506 ieee80211_init_channels(ic, NULL, &bands); 507 508 ieee80211_ifattach(ic, sc->sc_bssid); 509 ic->ic_update_promisc = rum_update_promisc; |
514 ic->ic_newassoc = rum_newassoc; | |
515 ic->ic_raw_xmit = rum_raw_xmit; | 510 ic->ic_raw_xmit = rum_raw_xmit; |
516 ic->ic_node_alloc = rum_node_alloc; | |
517 ic->ic_scan_start = rum_scan_start; 518 ic->ic_scan_end = rum_scan_end; 519 ic->ic_set_channel = rum_set_channel; 520 521 ic->ic_vap_create = rum_vap_create; 522 ic->ic_vap_delete = rum_vap_delete; 523 524 ieee80211_radiotap_attach(ic, --- 78 unchanged lines hidden (view full) --- 603 /* enable s/w bmiss handling for sta mode */ 604 ieee80211_vap_setup(ic, vap, name, unit, opmode, 605 flags | IEEE80211_CLONE_NOBEACONS, bssid, mac); 606 607 /* override state transition machine */ 608 rvp->newstate = vap->iv_newstate; 609 vap->iv_newstate = rum_newstate; 610 | 511 ic->ic_scan_start = rum_scan_start; 512 ic->ic_scan_end = rum_scan_end; 513 ic->ic_set_channel = rum_set_channel; 514 515 ic->ic_vap_create = rum_vap_create; 516 ic->ic_vap_delete = rum_vap_delete; 517 518 ieee80211_radiotap_attach(ic, --- 78 unchanged lines hidden (view full) --- 597 /* enable s/w bmiss handling for sta mode */ 598 ieee80211_vap_setup(ic, vap, name, unit, opmode, 599 flags | IEEE80211_CLONE_NOBEACONS, bssid, mac); 600 601 /* override state transition machine */ 602 rvp->newstate = vap->iv_newstate; 603 vap->iv_newstate = rum_newstate; 604 |
611 usb_callout_init_mtx(&rvp->amrr_ch, &sc->sc_mtx, 0); 612 TASK_INIT(&rvp->amrr_task, 0, rum_amrr_task, rvp); 613 ieee80211_amrr_init(&rvp->amrr, vap, 614 IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD, 615 IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD, 616 1000 /* 1 sec */); 617 | 605 usb_callout_init_mtx(&rvp->ratectl_ch, &sc->sc_mtx, 0); 606 TASK_INIT(&rvp->ratectl_task, 0, rum_ratectl_task, rvp); 607 ieee80211_ratectl_init(vap); 608 ieee80211_ratectl_setinterval(vap, 1000 /* 1 sec */); |
618 /* complete setup */ 619 ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status); 620 ic->ic_opmode = opmode; 621 return vap; 622} 623 624static void 625rum_vap_delete(struct ieee80211vap *vap) 626{ 627 struct rum_vap *rvp = RUM_VAP(vap); 628 struct ieee80211com *ic = vap->iv_ic; 629 | 609 /* complete setup */ 610 ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status); 611 ic->ic_opmode = opmode; 612 return vap; 613} 614 615static void 616rum_vap_delete(struct ieee80211vap *vap) 617{ 618 struct rum_vap *rvp = RUM_VAP(vap); 619 struct ieee80211com *ic = vap->iv_ic; 620 |
630 usb_callout_drain(&rvp->amrr_ch); 631 ieee80211_draintask(ic, &rvp->amrr_task); 632 ieee80211_amrr_cleanup(&rvp->amrr); | 621 usb_callout_drain(&rvp->ratectl_ch); 622 ieee80211_draintask(ic, &rvp->ratectl_task); 623 ieee80211_ratectl_deinit(vap); |
633 ieee80211_vap_detach(vap); 634 free(rvp, M_80211_VAP); 635} 636 637static void 638rum_tx_free(struct rum_tx_data *data, int txerr) 639{ 640 struct rum_softc *sc = data->sc; --- 70 unchanged lines hidden (view full) --- 711 712 ostate = vap->iv_state; 713 DPRINTF("%s -> %s\n", 714 ieee80211_state_name[ostate], 715 ieee80211_state_name[nstate]); 716 717 IEEE80211_UNLOCK(ic); 718 RUM_LOCK(sc); | 624 ieee80211_vap_detach(vap); 625 free(rvp, M_80211_VAP); 626} 627 628static void 629rum_tx_free(struct rum_tx_data *data, int txerr) 630{ 631 struct rum_softc *sc = data->sc; --- 70 unchanged lines hidden (view full) --- 702 703 ostate = vap->iv_state; 704 DPRINTF("%s -> %s\n", 705 ieee80211_state_name[ostate], 706 ieee80211_state_name[nstate]); 707 708 IEEE80211_UNLOCK(ic); 709 RUM_LOCK(sc); |
719 usb_callout_stop(&rvp->amrr_ch); | 710 usb_callout_stop(&rvp->ratectl_ch); |
720 721 switch (nstate) { 722 case IEEE80211_S_INIT: 723 if (ostate == IEEE80211_S_RUN) { 724 /* abort TSF synchronization */ 725 tmp = rum_read(sc, RT2573_TXRX_CSR9); 726 rum_write(sc, RT2573_TXRX_CSR9, tmp & ~0x00ffffff); 727 } --- 18 unchanged lines hidden (view full) --- 746 if (vap->iv_opmode != IEEE80211_M_MONITOR) 747 rum_enable_tsf_sync(sc); 748 else 749 rum_enable_tsf(sc); 750 751 /* enable automatic rate adaptation */ 752 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)]; 753 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) | 711 712 switch (nstate) { 713 case IEEE80211_S_INIT: 714 if (ostate == IEEE80211_S_RUN) { 715 /* abort TSF synchronization */ 716 tmp = rum_read(sc, RT2573_TXRX_CSR9); 717 rum_write(sc, RT2573_TXRX_CSR9, tmp & ~0x00ffffff); 718 } --- 18 unchanged lines hidden (view full) --- 737 if (vap->iv_opmode != IEEE80211_M_MONITOR) 738 rum_enable_tsf_sync(sc); 739 else 740 rum_enable_tsf(sc); 741 742 /* enable automatic rate adaptation */ 743 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)]; 744 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) |
754 rum_amrr_start(sc, ni); | 745 rum_ratectl_start(sc, ni); |
755 break; 756 default: 757 break; 758 } 759 RUM_UNLOCK(sc); 760 IEEE80211_LOCK(ic); 761 return (rvp->newstate(vap, nstate, arg)); 762} --- 1426 unchanged lines hidden (view full) --- 2189bad: 2190 ifp->if_oerrors++; 2191 RUM_UNLOCK(sc); 2192 ieee80211_free_node(ni); 2193 return EIO; 2194} 2195 2196static void | 746 break; 747 default: 748 break; 749 } 750 RUM_UNLOCK(sc); 751 IEEE80211_LOCK(ic); 752 return (rvp->newstate(vap, nstate, arg)); 753} --- 1426 unchanged lines hidden (view full) --- 2180bad: 2181 ifp->if_oerrors++; 2182 RUM_UNLOCK(sc); 2183 ieee80211_free_node(ni); 2184 return EIO; 2185} 2186 2187static void |
2197rum_amrr_start(struct rum_softc *sc, struct ieee80211_node *ni) | 2188rum_ratectl_start(struct rum_softc *sc, struct ieee80211_node *ni) |
2198{ 2199 struct ieee80211vap *vap = ni->ni_vap; 2200 struct rum_vap *rvp = RUM_VAP(vap); 2201 2202 /* clear statistic registers (STA_CSR0 to STA_CSR5) */ 2203 rum_read_multi(sc, RT2573_STA_CSR0, sc->sta, sizeof sc->sta); 2204 | 2189{ 2190 struct ieee80211vap *vap = ni->ni_vap; 2191 struct rum_vap *rvp = RUM_VAP(vap); 2192 2193 /* clear statistic registers (STA_CSR0 to STA_CSR5) */ 2194 rum_read_multi(sc, RT2573_STA_CSR0, sc->sta, sizeof sc->sta); 2195 |
2205 ieee80211_amrr_node_init(&rvp->amrr, &RUM_NODE(ni)->amn, ni); | 2196 ieee80211_ratectl_node_init(ni); |
2206 | 2197 |
2207 usb_callout_reset(&rvp->amrr_ch, hz, rum_amrr_timeout, rvp); | 2198 usb_callout_reset(&rvp->ratectl_ch, hz, rum_ratectl_timeout, rvp); |
2208} 2209 2210static void | 2199} 2200 2201static void |
2211rum_amrr_timeout(void *arg) | 2202rum_ratectl_timeout(void *arg) |
2212{ 2213 struct rum_vap *rvp = arg; 2214 struct ieee80211vap *vap = &rvp->vap; 2215 struct ieee80211com *ic = vap->iv_ic; 2216 | 2203{ 2204 struct rum_vap *rvp = arg; 2205 struct ieee80211vap *vap = &rvp->vap; 2206 struct ieee80211com *ic = vap->iv_ic; 2207 |
2217 ieee80211_runtask(ic, &rvp->amrr_task); | 2208 ieee80211_runtask(ic, &rvp->ratectl_task); |
2218} 2219 2220static void | 2209} 2210 2211static void |
2221rum_amrr_task(void *arg, int pending) | 2212rum_ratectl_task(void *arg, int pending) |
2222{ 2223 struct rum_vap *rvp = arg; 2224 struct ieee80211vap *vap = &rvp->vap; 2225 struct ieee80211com *ic = vap->iv_ic; 2226 struct ifnet *ifp = ic->ic_ifp; 2227 struct rum_softc *sc = ifp->if_softc; 2228 struct ieee80211_node *ni = vap->iv_bss; 2229 int ok, fail; | 2213{ 2214 struct rum_vap *rvp = arg; 2215 struct ieee80211vap *vap = &rvp->vap; 2216 struct ieee80211com *ic = vap->iv_ic; 2217 struct ifnet *ifp = ic->ic_ifp; 2218 struct rum_softc *sc = ifp->if_softc; 2219 struct ieee80211_node *ni = vap->iv_bss; 2220 int ok, fail; |
2221 int sum, retrycnt; |
|
2230 2231 RUM_LOCK(sc); 2232 /* read and clear statistic registers (STA_CSR0 to STA_CSR10) */ 2233 rum_read_multi(sc, RT2573_STA_CSR0, sc->sta, sizeof(sc->sta)); 2234 2235 ok = (le32toh(sc->sta[4]) >> 16) + /* TX ok w/o retry */ 2236 (le32toh(sc->sta[5]) & 0xffff); /* TX ok w/ retry */ 2237 fail = (le32toh(sc->sta[5]) >> 16); /* TX retry-fail count */ | 2222 2223 RUM_LOCK(sc); 2224 /* read and clear statistic registers (STA_CSR0 to STA_CSR10) */ 2225 rum_read_multi(sc, RT2573_STA_CSR0, sc->sta, sizeof(sc->sta)); 2226 2227 ok = (le32toh(sc->sta[4]) >> 16) + /* TX ok w/o retry */ 2228 (le32toh(sc->sta[5]) & 0xffff); /* TX ok w/ retry */ 2229 fail = (le32toh(sc->sta[5]) >> 16); /* TX retry-fail count */ |
2230 sum = ok+fail; 2231 retrycnt = (le32toh(sc->sta[5]) & 0xffff) + fail; |
|
2238 | 2232 |
2239 ieee80211_amrr_tx_update(&RUM_NODE(ni)->amn, 2240 ok+fail, ok, (le32toh(sc->sta[5]) & 0xffff) + fail); 2241 (void) ieee80211_amrr_choose(ni, &RUM_NODE(ni)->amn); | 2233 ieee80211_ratectl_tx_update(vap, ni, &sum, &ok, &retrycnt); 2234 (void) ieee80211_ratectl_rate(ni, NULL, 0); |
2242 2243 ifp->if_oerrors += fail; /* count TX retry-fail as Tx errors */ 2244 | 2235 2236 ifp->if_oerrors += fail; /* count TX retry-fail as Tx errors */ 2237 |
2245 usb_callout_reset(&rvp->amrr_ch, hz, rum_amrr_timeout, rvp); | 2238 usb_callout_reset(&rvp->ratectl_ch, hz, rum_ratectl_timeout, rvp); |
2246 RUM_UNLOCK(sc); 2247} 2248 | 2239 RUM_UNLOCK(sc); 2240} 2241 |
2249/* ARGUSED */ 2250static struct ieee80211_node * 2251rum_node_alloc(struct ieee80211vap *vap __unused, 2252 const uint8_t mac[IEEE80211_ADDR_LEN] __unused) 2253{ 2254 struct rum_node *rn; 2255 2256 rn = malloc(sizeof(struct rum_node), M_80211_NODE, M_NOWAIT | M_ZERO); 2257 return rn != NULL ? &rn->ni : NULL; 2258} 2259 | |
2260static void | 2242static void |
2261rum_newassoc(struct ieee80211_node *ni, int isnew) 2262{ 2263 struct ieee80211vap *vap = ni->ni_vap; 2264 2265 ieee80211_amrr_node_init(&RUM_VAP(vap)->amrr, &RUM_NODE(ni)->amn, ni); 2266} 2267 2268static void | |
2269rum_scan_start(struct ieee80211com *ic) 2270{ 2271 struct ifnet *ifp = ic->ic_ifp; 2272 struct rum_softc *sc = ifp->if_softc; 2273 uint32_t tmp; 2274 2275 RUM_LOCK(sc); 2276 /* abort TSF synchronization */ --- 102 unchanged lines hidden --- | 2243rum_scan_start(struct ieee80211com *ic) 2244{ 2245 struct ifnet *ifp = ic->ic_ifp; 2246 struct rum_softc *sc = ifp->if_softc; 2247 uint32_t tmp; 2248 2249 RUM_LOCK(sc); 2250 /* abort TSF synchronization */ --- 102 unchanged lines hidden --- |