rt2860.c (286437) | rt2860.c (287197) |
---|---|
1/*- 2 * Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini@free.fr> 3 * Copyright (c) 2012 Bernhard Schmidt <bschmidt@FreeBSD.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * --- 4 unchanged lines hidden (view full) --- 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * 17 * $OpenBSD: rt2860.c,v 1.65 2010/10/23 14:24:54 damien Exp $ 18 */ 19 20#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini@free.fr> 3 * Copyright (c) 2012 Bernhard Schmidt <bschmidt@FreeBSD.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * --- 4 unchanged lines hidden (view full) --- 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * 17 * $OpenBSD: rt2860.c,v 1.65 2010/10/23 14:24:54 damien Exp $ 18 */ 19 20#include <sys/cdefs.h> |
21__FBSDID("$FreeBSD: head/sys/dev/ral/rt2860.c 286437 2015-08-08 01:10:17Z adrian $"); | 21__FBSDID("$FreeBSD: head/sys/dev/ral/rt2860.c 287197 2015-08-27 08:56:39Z glebius $"); |
22 23/*- 24 * Ralink Technology RT2860/RT3090/RT3390/RT3562/RT5390/RT5392 chipset driver 25 * http://www.ralinktech.com/ 26 */ 27 28#include <sys/param.h> 29#include <sys/sysctl.h> --- 87 unchanged lines hidden (view full) --- 117static void rt2860_gp_intr(struct rt2860_softc *); 118static int rt2860_tx(struct rt2860_softc *, struct mbuf *, 119 struct ieee80211_node *); 120static int rt2860_raw_xmit(struct ieee80211_node *, struct mbuf *, 121 const struct ieee80211_bpf_params *); 122static int rt2860_tx_raw(struct rt2860_softc *, struct mbuf *, 123 struct ieee80211_node *, 124 const struct ieee80211_bpf_params *params); | 22 23/*- 24 * Ralink Technology RT2860/RT3090/RT3390/RT3562/RT5390/RT5392 chipset driver 25 * http://www.ralinktech.com/ 26 */ 27 28#include <sys/param.h> 29#include <sys/sysctl.h> --- 87 unchanged lines hidden (view full) --- 117static void rt2860_gp_intr(struct rt2860_softc *); 118static int rt2860_tx(struct rt2860_softc *, struct mbuf *, 119 struct ieee80211_node *); 120static int rt2860_raw_xmit(struct ieee80211_node *, struct mbuf *, 121 const struct ieee80211_bpf_params *); 122static int rt2860_tx_raw(struct rt2860_softc *, struct mbuf *, 123 struct ieee80211_node *, 124 const struct ieee80211_bpf_params *params); |
125static void rt2860_start(struct ifnet *); 126static void rt2860_start_locked(struct ifnet *); | 125static int rt2860_transmit(struct ieee80211com *, struct mbuf *); 126static void rt2860_start(struct rt2860_softc *); |
127static void rt2860_watchdog(void *); | 127static void rt2860_watchdog(void *); |
128static int rt2860_ioctl(struct ifnet *, u_long, caddr_t); | 128static void rt2860_parent(struct ieee80211com *); |
129static void rt2860_mcu_bbp_write(struct rt2860_softc *, uint8_t, uint8_t); 130static uint8_t rt2860_mcu_bbp_read(struct rt2860_softc *, uint8_t); 131static void rt2860_rf_write(struct rt2860_softc *, uint8_t, uint32_t); 132static uint8_t rt3090_rf_read(struct rt2860_softc *, uint8_t); 133static void rt3090_rf_write(struct rt2860_softc *, uint8_t, uint8_t); 134static int rt2860_mcu_cmd(struct rt2860_softc *, uint8_t, uint16_t, int); 135static void rt2860_enable_mrr(struct rt2860_softc *); 136static void rt2860_set_txpreamble(struct rt2860_softc *); --- 14 unchanged lines hidden (view full) --- 151 uint8_t *); 152static void rt3090_rf_setup(struct rt2860_softc *); 153static void rt2860_set_leds(struct rt2860_softc *, uint16_t); 154static void rt2860_set_gp_timer(struct rt2860_softc *, int); 155static void rt2860_set_bssid(struct rt2860_softc *, const uint8_t *); 156static void rt2860_set_macaddr(struct rt2860_softc *, const uint8_t *); 157static void rt2860_update_promisc(struct ieee80211com *); 158static void rt2860_updateslot(struct ieee80211com *); | 129static void rt2860_mcu_bbp_write(struct rt2860_softc *, uint8_t, uint8_t); 130static uint8_t rt2860_mcu_bbp_read(struct rt2860_softc *, uint8_t); 131static void rt2860_rf_write(struct rt2860_softc *, uint8_t, uint32_t); 132static uint8_t rt3090_rf_read(struct rt2860_softc *, uint8_t); 133static void rt3090_rf_write(struct rt2860_softc *, uint8_t, uint8_t); 134static int rt2860_mcu_cmd(struct rt2860_softc *, uint8_t, uint16_t, int); 135static void rt2860_enable_mrr(struct rt2860_softc *); 136static void rt2860_set_txpreamble(struct rt2860_softc *); --- 14 unchanged lines hidden (view full) --- 151 uint8_t *); 152static void rt3090_rf_setup(struct rt2860_softc *); 153static void rt2860_set_leds(struct rt2860_softc *, uint16_t); 154static void rt2860_set_gp_timer(struct rt2860_softc *, int); 155static void rt2860_set_bssid(struct rt2860_softc *, const uint8_t *); 156static void rt2860_set_macaddr(struct rt2860_softc *, const uint8_t *); 157static void rt2860_update_promisc(struct ieee80211com *); 158static void rt2860_updateslot(struct ieee80211com *); |
159static void rt2860_updateprot(struct ifnet *); | 159static void rt2860_updateprot(struct rt2860_softc *); |
160static int rt2860_updateedca(struct ieee80211com *); 161#ifdef HW_CRYPTO 162static int rt2860_set_key(struct ieee80211com *, struct ieee80211_node *, 163 struct ieee80211_key *); 164static void rt2860_delete_key(struct ieee80211com *, 165 struct ieee80211_node *, struct ieee80211_key *); 166#endif 167static int8_t rt2860_rssi2dbm(struct rt2860_softc *, uint8_t, uint8_t); --- 57 unchanged lines hidden (view full) --- 225}, rt5392_def_rf[] = { 226 RT5392_DEF_RF 227}; 228 229int 230rt2860_attach(device_t dev, int id) 231{ 232 struct rt2860_softc *sc = device_get_softc(dev); | 160static int rt2860_updateedca(struct ieee80211com *); 161#ifdef HW_CRYPTO 162static int rt2860_set_key(struct ieee80211com *, struct ieee80211_node *, 163 struct ieee80211_key *); 164static void rt2860_delete_key(struct ieee80211com *, 165 struct ieee80211_node *, struct ieee80211_key *); 166#endif 167static int8_t rt2860_rssi2dbm(struct rt2860_softc *, uint8_t, uint8_t); --- 57 unchanged lines hidden (view full) --- 225}, rt5392_def_rf[] = { 226 RT5392_DEF_RF 227}; 228 229int 230rt2860_attach(device_t dev, int id) 231{ 232 struct rt2860_softc *sc = device_get_softc(dev); |
233 struct ieee80211com *ic; 234 struct ifnet *ifp; | 233 struct ieee80211com *ic = &sc->sc_ic; |
235 uint32_t tmp; 236 int error, ntries, qid; 237 uint8_t bands; | 234 uint32_t tmp; 235 int error, ntries, qid; 236 uint8_t bands; |
238 uint8_t macaddr[IEEE80211_ADDR_LEN]; | |
239 240 sc->sc_dev = dev; 241 sc->sc_debug = 0; 242 | 237 238 sc->sc_dev = dev; 239 sc->sc_debug = 0; 240 |
243 ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211); 244 if (ifp == NULL) { 245 device_printf(sc->sc_dev, "can not if_alloc()\n"); 246 return ENOMEM; 247 } 248 ic = ifp->if_l2com; 249 | |
250 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 251 MTX_DEF | MTX_RECURSE); 252 253 callout_init_mtx(&sc->watchdog_ch, &sc->sc_mtx, 0); | 241 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 242 MTX_DEF | MTX_RECURSE); 243 244 callout_init_mtx(&sc->watchdog_ch, &sc->sc_mtx, 0); |
245 mbufq_init(&sc->sc_snd, ifqmaxlen); |
|
254 255 /* wait for NIC to initialize */ 256 for (ntries = 0; ntries < 100; ntries++) { 257 tmp = RAL_READ(sc, RT2860_ASIC_VER_ID); 258 if (tmp != 0 && tmp != 0xffffffff) 259 break; 260 DELAY(10); 261 } --- 6 unchanged lines hidden (view full) --- 268 sc->mac_ver = tmp >> 16; 269 sc->mac_rev = tmp & 0xffff; 270 271 if (sc->mac_ver != 0x2860 && 272 (id == 0x0681 || id == 0x0781 || id == 0x1059)) 273 sc->sc_flags |= RT2860_ADVANCED_PS; 274 275 /* retrieve RF rev. no and various other things from EEPROM */ | 246 247 /* wait for NIC to initialize */ 248 for (ntries = 0; ntries < 100; ntries++) { 249 tmp = RAL_READ(sc, RT2860_ASIC_VER_ID); 250 if (tmp != 0 && tmp != 0xffffffff) 251 break; 252 DELAY(10); 253 } --- 6 unchanged lines hidden (view full) --- 260 sc->mac_ver = tmp >> 16; 261 sc->mac_rev = tmp & 0xffff; 262 263 if (sc->mac_ver != 0x2860 && 264 (id == 0x0681 || id == 0x0781 || id == 0x1059)) 265 sc->sc_flags |= RT2860_ADVANCED_PS; 266 267 /* retrieve RF rev. no and various other things from EEPROM */ |
276 rt2860_read_eeprom(sc, macaddr); | 268 rt2860_read_eeprom(sc, ic->ic_macaddr); |
277 device_printf(sc->sc_dev, "MAC/BBP RT%X (rev 0x%04X), " 278 "RF %s (MIMO %dT%dR), address %6D\n", 279 sc->mac_ver, sc->mac_rev, rt2860_get_rf(sc->rf_rev), | 269 device_printf(sc->sc_dev, "MAC/BBP RT%X (rev 0x%04X), " 270 "RF %s (MIMO %dT%dR), address %6D\n", 271 sc->mac_ver, sc->mac_rev, rt2860_get_rf(sc->rf_rev), |
280 sc->ntxchains, sc->nrxchains, macaddr, ":"); | 272 sc->ntxchains, sc->nrxchains, ic->ic_macaddr, ":"); |
281 282 /* 283 * Allocate Tx (4 EDCAs + HCCA + Mgt) and Rx rings. 284 */ 285 for (qid = 0; qid < 6; qid++) { 286 if ((error = rt2860_alloc_tx_ring(sc, &sc->txq[qid])) != 0) { 287 device_printf(sc->sc_dev, 288 "could not allocate Tx ring %d\n", qid); --- 10 unchanged lines hidden (view full) --- 299 device_printf(sc->sc_dev, "could not allocate Tx pool\n"); 300 goto fail3; 301 } 302 303 /* mgmt ring is broken on RT2860C, use EDCA AC VO ring instead */ 304 sc->mgtqid = (sc->mac_ver == 0x2860 && sc->mac_rev == 0x0100) ? 305 WME_AC_VO : 5; 306 | 273 274 /* 275 * Allocate Tx (4 EDCAs + HCCA + Mgt) and Rx rings. 276 */ 277 for (qid = 0; qid < 6; qid++) { 278 if ((error = rt2860_alloc_tx_ring(sc, &sc->txq[qid])) != 0) { 279 device_printf(sc->sc_dev, 280 "could not allocate Tx ring %d\n", qid); --- 10 unchanged lines hidden (view full) --- 291 device_printf(sc->sc_dev, "could not allocate Tx pool\n"); 292 goto fail3; 293 } 294 295 /* mgmt ring is broken on RT2860C, use EDCA AC VO ring instead */ 296 sc->mgtqid = (sc->mac_ver == 0x2860 && sc->mac_rev == 0x0100) ? 297 WME_AC_VO : 5; 298 |
307 ifp->if_softc = sc; 308 if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 309 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 310 ifp->if_init = rt2860_init; 311 ifp->if_ioctl = rt2860_ioctl; 312 ifp->if_start = rt2860_start; 313 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); 314 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen; 315 IFQ_SET_READY(&ifp->if_snd); 316 317 ic->ic_ifp = ifp; | |
318 ic->ic_softc = sc; 319 ic->ic_name = device_get_nameunit(dev); 320 ic->ic_opmode = IEEE80211_M_STA; 321 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ 322 323 /* set device capabilities */ 324 ic->ic_caps = 325 IEEE80211_C_STA /* station mode */ --- 14 unchanged lines hidden (view full) --- 340 341 bands = 0; 342 setbit(&bands, IEEE80211_MODE_11B); 343 setbit(&bands, IEEE80211_MODE_11G); 344 if (sc->rf_rev == RT2860_RF_2750 || sc->rf_rev == RT2860_RF_2850) 345 setbit(&bands, IEEE80211_MODE_11A); 346 ieee80211_init_channels(ic, NULL, &bands); 347 | 299 ic->ic_softc = sc; 300 ic->ic_name = device_get_nameunit(dev); 301 ic->ic_opmode = IEEE80211_M_STA; 302 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ 303 304 /* set device capabilities */ 305 ic->ic_caps = 306 IEEE80211_C_STA /* station mode */ --- 14 unchanged lines hidden (view full) --- 321 322 bands = 0; 323 setbit(&bands, IEEE80211_MODE_11B); 324 setbit(&bands, IEEE80211_MODE_11G); 325 if (sc->rf_rev == RT2860_RF_2750 || sc->rf_rev == RT2860_RF_2850) 326 setbit(&bands, IEEE80211_MODE_11A); 327 ieee80211_init_channels(ic, NULL, &bands); 328 |
348 ieee80211_ifattach(ic, macaddr); | 329 ieee80211_ifattach(ic); |
349 350 ic->ic_wme.wme_update = rt2860_updateedca; 351 ic->ic_scan_start = rt2860_scan_start; 352 ic->ic_scan_end = rt2860_scan_end; 353 ic->ic_set_channel = rt2860_set_channel; 354 ic->ic_updateslot = rt2860_updateslot; 355 ic->ic_update_promisc = rt2860_update_promisc; 356 ic->ic_raw_xmit = rt2860_raw_xmit; 357 sc->sc_node_free = ic->ic_node_free; 358 ic->ic_node_free = rt2860_node_free; 359 ic->ic_newassoc = rt2860_newassoc; | 330 331 ic->ic_wme.wme_update = rt2860_updateedca; 332 ic->ic_scan_start = rt2860_scan_start; 333 ic->ic_scan_end = rt2860_scan_end; 334 ic->ic_set_channel = rt2860_set_channel; 335 ic->ic_updateslot = rt2860_updateslot; 336 ic->ic_update_promisc = rt2860_update_promisc; 337 ic->ic_raw_xmit = rt2860_raw_xmit; 338 sc->sc_node_free = ic->ic_node_free; 339 ic->ic_node_free = rt2860_node_free; 340 ic->ic_newassoc = rt2860_newassoc; |
360 | 341 ic->ic_transmit = rt2860_transmit; 342 ic->ic_parent = rt2860_parent; |
361 ic->ic_vap_create = rt2860_vap_create; 362 ic->ic_vap_delete = rt2860_vap_delete; 363 364 ieee80211_radiotap_attach(ic, 365 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), 366 RT2860_TX_RADIOTAP_PRESENT, 367 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), 368 RT2860_RX_RADIOTAP_PRESENT); --- 7 unchanged lines hidden (view full) --- 376 ieee80211_announce(ic); 377 378 return 0; 379 380fail3: rt2860_free_rx_ring(sc, &sc->rxq); 381fail2: while (--qid >= 0) 382 rt2860_free_tx_ring(sc, &sc->txq[qid]); 383fail1: mtx_destroy(&sc->sc_mtx); | 343 ic->ic_vap_create = rt2860_vap_create; 344 ic->ic_vap_delete = rt2860_vap_delete; 345 346 ieee80211_radiotap_attach(ic, 347 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), 348 RT2860_TX_RADIOTAP_PRESENT, 349 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), 350 RT2860_RX_RADIOTAP_PRESENT); --- 7 unchanged lines hidden (view full) --- 358 ieee80211_announce(ic); 359 360 return 0; 361 362fail3: rt2860_free_rx_ring(sc, &sc->rxq); 363fail2: while (--qid >= 0) 364 rt2860_free_tx_ring(sc, &sc->txq[qid]); 365fail1: mtx_destroy(&sc->sc_mtx); |
384 if_free(ifp); | |
385 return error; 386} 387 388int 389rt2860_detach(void *xsc) 390{ 391 struct rt2860_softc *sc = xsc; | 366 return error; 367} 368 369int 370rt2860_detach(void *xsc) 371{ 372 struct rt2860_softc *sc = xsc; |
392 struct ifnet *ifp = sc->sc_ifp; 393 struct ieee80211com *ic = ifp->if_l2com; | 373 struct ieee80211com *ic = &sc->sc_ic; |
394 int qid; 395 396 RAL_LOCK(sc); 397 rt2860_stop_locked(sc); 398 RAL_UNLOCK(sc); 399 400 ieee80211_ifdetach(ic); | 374 int qid; 375 376 RAL_LOCK(sc); 377 rt2860_stop_locked(sc); 378 RAL_UNLOCK(sc); 379 380 ieee80211_ifdetach(ic); |
401 | 381 mbufq_drain(&sc->sc_snd); |
402 for (qid = 0; qid < 6; qid++) 403 rt2860_free_tx_ring(sc, &sc->txq[qid]); 404 rt2860_free_rx_ring(sc, &sc->rxq); 405 rt2860_free_tx_pool(sc); 406 | 382 for (qid = 0; qid < 6; qid++) 383 rt2860_free_tx_ring(sc, &sc->txq[qid]); 384 rt2860_free_rx_ring(sc, &sc->rxq); 385 rt2860_free_tx_pool(sc); 386 |
407 if_free(ifp); 408 | |
409 mtx_destroy(&sc->sc_mtx); 410 411 return 0; 412} 413 414void 415rt2860_shutdown(void *xsc) 416{ --- 9 unchanged lines hidden (view full) --- 426 427 rt2860_stop(sc); 428} 429 430void 431rt2860_resume(void *xsc) 432{ 433 struct rt2860_softc *sc = xsc; | 387 mtx_destroy(&sc->sc_mtx); 388 389 return 0; 390} 391 392void 393rt2860_shutdown(void *xsc) 394{ --- 9 unchanged lines hidden (view full) --- 404 405 rt2860_stop(sc); 406} 407 408void 409rt2860_resume(void *xsc) 410{ 411 struct rt2860_softc *sc = xsc; |
434 struct ifnet *ifp = sc->sc_ifp; | |
435 | 412 |
436 if (ifp->if_flags & IFF_UP) | 413 if (sc->sc_ic.ic_nrunning > 0) |
437 rt2860_init(sc); 438} 439 440static struct ieee80211vap * 441rt2860_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit, 442 enum ieee80211_opmode opmode, int flags, 443 const uint8_t bssid[IEEE80211_ADDR_LEN], 444 const uint8_t mac[IEEE80211_ADDR_LEN]) 445{ | 414 rt2860_init(sc); 415} 416 417static struct ieee80211vap * 418rt2860_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit, 419 enum ieee80211_opmode opmode, int flags, 420 const uint8_t bssid[IEEE80211_ADDR_LEN], 421 const uint8_t mac[IEEE80211_ADDR_LEN]) 422{ |
446 struct ifnet *ifp = ic->ic_ifp; | 423 struct rt2860_softc *sc = ic->ic_softc; |
447 struct rt2860_vap *rvp; 448 struct ieee80211vap *vap; 449 450 switch (opmode) { 451 case IEEE80211_M_STA: 452 case IEEE80211_M_IBSS: 453 case IEEE80211_M_AHDEMO: 454 case IEEE80211_M_MONITOR: 455 case IEEE80211_M_HOSTAP: 456 case IEEE80211_M_MBSS: 457 /* XXXRP: TBD */ 458 if (!TAILQ_EMPTY(&ic->ic_vaps)) { | 424 struct rt2860_vap *rvp; 425 struct ieee80211vap *vap; 426 427 switch (opmode) { 428 case IEEE80211_M_STA: 429 case IEEE80211_M_IBSS: 430 case IEEE80211_M_AHDEMO: 431 case IEEE80211_M_MONITOR: 432 case IEEE80211_M_HOSTAP: 433 case IEEE80211_M_MBSS: 434 /* XXXRP: TBD */ 435 if (!TAILQ_EMPTY(&ic->ic_vaps)) { |
459 if_printf(ifp, "only 1 vap supported\n"); | 436 device_printf(sc->sc_dev, "only 1 vap supported\n"); |
460 return NULL; 461 } 462 if (opmode == IEEE80211_M_STA) 463 flags |= IEEE80211_CLONE_NOBEACONS; 464 break; 465 case IEEE80211_M_WDS: 466 if (TAILQ_EMPTY(&ic->ic_vaps) || 467 ic->ic_opmode != IEEE80211_M_HOSTAP) { | 437 return NULL; 438 } 439 if (opmode == IEEE80211_M_STA) 440 flags |= IEEE80211_CLONE_NOBEACONS; 441 break; 442 case IEEE80211_M_WDS: 443 if (TAILQ_EMPTY(&ic->ic_vaps) || 444 ic->ic_opmode != IEEE80211_M_HOSTAP) { |
468 if_printf(ifp, "wds only supported in ap mode\n"); | 445 device_printf(sc->sc_dev, 446 "wds only supported in ap mode\n"); |
469 return NULL; 470 } 471 /* 472 * Silently remove any request for a unique 473 * bssid; WDS vap's always share the local 474 * mac address. 475 */ 476 flags &= ~IEEE80211_CLONE_BSSID; 477 break; 478 default: | 447 return NULL; 448 } 449 /* 450 * Silently remove any request for a unique 451 * bssid; WDS vap's always share the local 452 * mac address. 453 */ 454 flags &= ~IEEE80211_CLONE_BSSID; 455 break; 456 default: |
479 if_printf(ifp, "unknown opmode %d\n", opmode); | 457 device_printf(sc->sc_dev, "unknown opmode %d\n", opmode); |
480 return NULL; 481 } | 458 return NULL; 459 } |
482 rvp = malloc(sizeof(struct rt2860_vap), M_80211_VAP, M_NOWAIT | M_ZERO); 483 if (rvp == NULL) 484 return NULL; | 460 rvp = malloc(sizeof(struct rt2860_vap), M_80211_VAP, M_WAITOK | M_ZERO); |
485 vap = &rvp->ral_vap; | 461 vap = &rvp->ral_vap; |
486 ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac); | 462 ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid); |
487 488 /* override state transition machine */ 489 rvp->ral_newstate = vap->iv_newstate; 490 vap->iv_newstate = rt2860_newstate; 491#if 0 492 vap->iv_update_beacon = rt2860_beacon_update; 493#endif 494 495 /* HW supports up to 255 STAs (0-254) in HostAP and IBSS modes */ 496 vap->iv_max_aid = min(IEEE80211_AID_MAX, RT2860_WCID_MAX); 497 498 ieee80211_ratectl_init(vap); 499 /* complete setup */ | 463 464 /* override state transition machine */ 465 rvp->ral_newstate = vap->iv_newstate; 466 vap->iv_newstate = rt2860_newstate; 467#if 0 468 vap->iv_update_beacon = rt2860_beacon_update; 469#endif 470 471 /* HW supports up to 255 STAs (0-254) in HostAP and IBSS modes */ 472 vap->iv_max_aid = min(IEEE80211_AID_MAX, RT2860_WCID_MAX); 473 474 ieee80211_ratectl_init(vap); 475 /* complete setup */ |
500 ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status); | 476 ieee80211_vap_attach(vap, ieee80211_media_change, 477 ieee80211_media_status, mac); |
501 if (TAILQ_FIRST(&ic->ic_vaps) == vap) 502 ic->ic_opmode = opmode; 503 return vap; 504} 505 506static void 507rt2860_vap_delete(struct ieee80211vap *vap) 508{ --- 315 unchanged lines hidden (view full) --- 824 } 825 if (ring->data_dmat != NULL) 826 bus_dma_tag_destroy(ring->data_dmat); 827} 828 829static void 830rt2860_updatestats(struct rt2860_softc *sc) 831{ | 478 if (TAILQ_FIRST(&ic->ic_vaps) == vap) 479 ic->ic_opmode = opmode; 480 return vap; 481} 482 483static void 484rt2860_vap_delete(struct ieee80211vap *vap) 485{ --- 315 unchanged lines hidden (view full) --- 801 } 802 if (ring->data_dmat != NULL) 803 bus_dma_tag_destroy(ring->data_dmat); 804} 805 806static void 807rt2860_updatestats(struct rt2860_softc *sc) 808{ |
832 struct ieee80211com *ic = sc->sc_ifp->if_l2com; | 809 struct ieee80211com *ic = &sc->sc_ic; |
833 834 /* 835 * In IBSS or HostAP modes (when the hardware sends beacons), the 836 * MAC can run into a livelock and start sending CTS-to-self frames 837 * like crazy if protection is enabled. Fortunately, we can detect 838 * when such a situation occurs and reset the MAC. 839 */ 840 if (ic->ic_curmode != IEEE80211_M_STA) { --- 10 unchanged lines hidden (view full) --- 851 } 852 } 853} 854 855static void 856rt2860_newassoc(struct ieee80211_node *ni, int isnew) 857{ 858 struct ieee80211com *ic = ni->ni_ic; | 810 811 /* 812 * In IBSS or HostAP modes (when the hardware sends beacons), the 813 * MAC can run into a livelock and start sending CTS-to-self frames 814 * like crazy if protection is enabled. Fortunately, we can detect 815 * when such a situation occurs and reset the MAC. 816 */ 817 if (ic->ic_curmode != IEEE80211_M_STA) { --- 10 unchanged lines hidden (view full) --- 828 } 829 } 830} 831 832static void 833rt2860_newassoc(struct ieee80211_node *ni, int isnew) 834{ 835 struct ieee80211com *ic = ni->ni_ic; |
859 struct rt2860_softc *sc = ic->ic_ifp->if_softc; | 836 struct rt2860_softc *sc = ic->ic_softc; |
860 uint8_t wcid; 861 862 wcid = IEEE80211_AID(ni->ni_associd); 863 if (isnew && ni->ni_associd != 0) { 864 sc->wcid2ni[wcid] = ni; 865 866 /* init WCID table entry */ 867 RAL_WRITE_REGION_1(sc, RT2860_WCID_ENTRY(wcid), 868 ni->ni_macaddr, IEEE80211_ADDR_LEN); 869 } 870 DPRINTF(("new assoc isnew=%d addr=%s WCID=%d\n", 871 isnew, ether_sprintf(ni->ni_macaddr), wcid)); 872} 873 874static void 875rt2860_node_free(struct ieee80211_node *ni) 876{ 877 struct ieee80211com *ic = ni->ni_ic; | 837 uint8_t wcid; 838 839 wcid = IEEE80211_AID(ni->ni_associd); 840 if (isnew && ni->ni_associd != 0) { 841 sc->wcid2ni[wcid] = ni; 842 843 /* init WCID table entry */ 844 RAL_WRITE_REGION_1(sc, RT2860_WCID_ENTRY(wcid), 845 ni->ni_macaddr, IEEE80211_ADDR_LEN); 846 } 847 DPRINTF(("new assoc isnew=%d addr=%s WCID=%d\n", 848 isnew, ether_sprintf(ni->ni_macaddr), wcid)); 849} 850 851static void 852rt2860_node_free(struct ieee80211_node *ni) 853{ 854 struct ieee80211com *ic = ni->ni_ic; |
878 struct rt2860_softc *sc = ic->ic_ifp->if_softc; | 855 struct rt2860_softc *sc = ic->ic_softc; |
879 uint8_t wcid; 880 881 if (ni->ni_associd != 0) { 882 wcid = IEEE80211_AID(ni->ni_associd); 883 884 /* clear Rx WCID search table entry */ 885 RAL_SET_REGION_4(sc, RT2860_WCID_ENTRY(wcid), 0, 2); 886 } --- 31 unchanged lines hidden (view full) --- 918} 919#endif 920 921int 922rt2860_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 923{ 924 struct rt2860_vap *rvp = RT2860_VAP(vap); 925 struct ieee80211com *ic = vap->iv_ic; | 856 uint8_t wcid; 857 858 if (ni->ni_associd != 0) { 859 wcid = IEEE80211_AID(ni->ni_associd); 860 861 /* clear Rx WCID search table entry */ 862 RAL_SET_REGION_4(sc, RT2860_WCID_ENTRY(wcid), 0, 2); 863 } --- 31 unchanged lines hidden (view full) --- 895} 896#endif 897 898int 899rt2860_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 900{ 901 struct rt2860_vap *rvp = RT2860_VAP(vap); 902 struct ieee80211com *ic = vap->iv_ic; |
926 struct rt2860_softc *sc = ic->ic_ifp->if_softc; | 903 struct rt2860_softc *sc = ic->ic_softc; |
927 uint32_t tmp; 928 int error; 929 930 if (vap->iv_state == IEEE80211_S_RUN) { 931 /* turn link LED off */ 932 rt2860_set_leds(sc, RT2860_LED_RADIO); 933 } 934 --- 161 unchanged lines hidden (view full) --- 1096 RAL_WRITE(sc, RT2860_WPDMA_GLO_CFG, tmp); 1097 1098 (void)rt2860_txrx_enable(sc); 1099} 1100 1101static void 1102rt2860_drain_stats_fifo(struct rt2860_softc *sc) 1103{ | 904 uint32_t tmp; 905 int error; 906 907 if (vap->iv_state == IEEE80211_S_RUN) { 908 /* turn link LED off */ 909 rt2860_set_leds(sc, RT2860_LED_RADIO); 910 } 911 --- 161 unchanged lines hidden (view full) --- 1073 RAL_WRITE(sc, RT2860_WPDMA_GLO_CFG, tmp); 1074 1075 (void)rt2860_txrx_enable(sc); 1076} 1077 1078static void 1079rt2860_drain_stats_fifo(struct rt2860_softc *sc) 1080{ |
1104 struct ifnet *ifp = sc->sc_ifp; | |
1105 struct ieee80211_node *ni; 1106 uint32_t stat; 1107 int retrycnt; 1108 uint8_t wcid, mcs, pid; 1109 1110 /* drain Tx status FIFO (maxsize = 16) */ 1111 while ((stat = RAL_READ(sc, RT2860_TX_STAT_FIFO)) & RT2860_TXQ_VLD) { 1112 DPRINTFN(4, ("tx stat 0x%08x\n", stat)); --- 19 unchanged lines hidden (view full) --- 1132 retrycnt = 1; 1133 else 1134 retrycnt = 0; 1135 ieee80211_ratectl_tx_complete(ni->ni_vap, ni, 1136 IEEE80211_RATECTL_TX_SUCCESS, &retrycnt, NULL); 1137 } else { 1138 ieee80211_ratectl_tx_complete(ni->ni_vap, ni, 1139 IEEE80211_RATECTL_TX_FAILURE, &retrycnt, NULL); | 1081 struct ieee80211_node *ni; 1082 uint32_t stat; 1083 int retrycnt; 1084 uint8_t wcid, mcs, pid; 1085 1086 /* drain Tx status FIFO (maxsize = 16) */ 1087 while ((stat = RAL_READ(sc, RT2860_TX_STAT_FIFO)) & RT2860_TXQ_VLD) { 1088 DPRINTFN(4, ("tx stat 0x%08x\n", stat)); --- 19 unchanged lines hidden (view full) --- 1108 retrycnt = 1; 1109 else 1110 retrycnt = 0; 1111 ieee80211_ratectl_tx_complete(ni->ni_vap, ni, 1112 IEEE80211_RATECTL_TX_SUCCESS, &retrycnt, NULL); 1113 } else { 1114 ieee80211_ratectl_tx_complete(ni->ni_vap, ni, 1115 IEEE80211_RATECTL_TX_FAILURE, &retrycnt, NULL); |
1140 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | 1116 if_inc_counter(ni->ni_vap->iv_ifp, 1117 IFCOUNTER_OERRORS, 1); |
1141 } 1142 } 1143} 1144 1145static void 1146rt2860_tx_intr(struct rt2860_softc *sc, int qid) 1147{ | 1118 } 1119 } 1120} 1121 1122static void 1123rt2860_tx_intr(struct rt2860_softc *sc, int qid) 1124{ |
1148 struct ifnet *ifp = sc->sc_ifp; | |
1149 struct rt2860_tx_ring *ring = &sc->txq[qid]; 1150 uint32_t hw; 1151 1152 rt2860_drain_stats_fifo(sc); 1153 1154 hw = RAL_READ(sc, RT2860_TX_DTX_IDX(qid)); 1155 while (ring->next != hw) { 1156 struct rt2860_tx_data *data = ring->data[ring->next]; 1157 1158 if (data != NULL) { 1159 bus_dmamap_sync(sc->txwi_dmat, data->map, 1160 BUS_DMASYNC_POSTWRITE); 1161 bus_dmamap_unload(sc->txwi_dmat, data->map); 1162 if (data->m->m_flags & M_TXCB) { 1163 ieee80211_process_callback(data->ni, data->m, 1164 0); 1165 } | 1125 struct rt2860_tx_ring *ring = &sc->txq[qid]; 1126 uint32_t hw; 1127 1128 rt2860_drain_stats_fifo(sc); 1129 1130 hw = RAL_READ(sc, RT2860_TX_DTX_IDX(qid)); 1131 while (ring->next != hw) { 1132 struct rt2860_tx_data *data = ring->data[ring->next]; 1133 1134 if (data != NULL) { 1135 bus_dmamap_sync(sc->txwi_dmat, data->map, 1136 BUS_DMASYNC_POSTWRITE); 1137 bus_dmamap_unload(sc->txwi_dmat, data->map); 1138 if (data->m->m_flags & M_TXCB) { 1139 ieee80211_process_callback(data->ni, data->m, 1140 0); 1141 } |
1166 m_freem(data->m); 1167 ieee80211_free_node(data->ni); 1168 data->m = NULL; | 1142 ieee80211_tx_complete(data->ni, data->m, 0); |
1169 data->ni = NULL; | 1143 data->ni = NULL; |
1170 | 1144 data->m = NULL; |
1171 SLIST_INSERT_HEAD(&sc->data_pool, data, next); 1172 ring->data[ring->next] = NULL; | 1145 SLIST_INSERT_HEAD(&sc->data_pool, data, next); 1146 ring->data[ring->next] = NULL; |
1173 1174 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); | |
1175 } 1176 ring->queued--; 1177 ring->next = (ring->next + 1) % RT2860_TX_RING_COUNT; 1178 } 1179 1180 sc->sc_tx_timer = 0; 1181 if (ring->queued < RT2860_TX_RING_COUNT) 1182 sc->qfullmsk &= ~(1 << qid); | 1147 } 1148 ring->queued--; 1149 ring->next = (ring->next + 1) % RT2860_TX_RING_COUNT; 1150 } 1151 1152 sc->sc_tx_timer = 0; 1153 if (ring->queued < RT2860_TX_RING_COUNT) 1154 sc->qfullmsk &= ~(1 << qid); |
1183 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 1184 rt2860_start_locked(ifp); | 1155 rt2860_start(sc); |
1185} 1186 1187/* 1188 * Return the Rx chain with the highest RSSI for a given frame. 1189 */ 1190static __inline uint8_t 1191rt2860_maxrssi_chain(struct rt2860_softc *sc, const struct rt2860_rxwi *rxwi) 1192{ --- 8 unchanged lines hidden (view full) --- 1201 } 1202 return rxchain; 1203} 1204 1205static void 1206rt2860_rx_intr(struct rt2860_softc *sc) 1207{ 1208 struct rt2860_rx_radiotap_header *tap; | 1156} 1157 1158/* 1159 * Return the Rx chain with the highest RSSI for a given frame. 1160 */ 1161static __inline uint8_t 1162rt2860_maxrssi_chain(struct rt2860_softc *sc, const struct rt2860_rxwi *rxwi) 1163{ --- 8 unchanged lines hidden (view full) --- 1172 } 1173 return rxchain; 1174} 1175 1176static void 1177rt2860_rx_intr(struct rt2860_softc *sc) 1178{ 1179 struct rt2860_rx_radiotap_header *tap; |
1209 struct ifnet *ifp = sc->sc_ifp; 1210 struct ieee80211com *ic = ifp->if_l2com; | 1180 struct ieee80211com *ic = &sc->sc_ic; |
1211 struct ieee80211_frame *wh; 1212 struct ieee80211_node *ni; 1213 struct mbuf *m, *m1; 1214 bus_addr_t physaddr; 1215 uint32_t hw; 1216 uint16_t phy; 1217 uint8_t ant; 1218 int8_t rssi, nf; --- 10 unchanged lines hidden (view full) --- 1229 1230 if (__predict_false(!(rxd->sdl0 & htole16(RT2860_RX_DDONE)))) { 1231 DPRINTF(("RXD DDONE bit not set!\n")); 1232 break; /* should not happen */ 1233 } 1234 1235 if (__predict_false(rxd->flags & 1236 htole32(RT2860_RX_CRCERR | RT2860_RX_ICVERR))) { | 1181 struct ieee80211_frame *wh; 1182 struct ieee80211_node *ni; 1183 struct mbuf *m, *m1; 1184 bus_addr_t physaddr; 1185 uint32_t hw; 1186 uint16_t phy; 1187 uint8_t ant; 1188 int8_t rssi, nf; --- 10 unchanged lines hidden (view full) --- 1199 1200 if (__predict_false(!(rxd->sdl0 & htole16(RT2860_RX_DDONE)))) { 1201 DPRINTF(("RXD DDONE bit not set!\n")); 1202 break; /* should not happen */ 1203 } 1204 1205 if (__predict_false(rxd->flags & 1206 htole32(RT2860_RX_CRCERR | RT2860_RX_ICVERR))) { |
1237 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | 1207 counter_u64_add(ic->ic_ierrors, 1); |
1238 goto skip; 1239 } 1240 1241#ifdef HW_CRYPTO 1242 if (__predict_false(rxd->flags & htole32(RT2860_RX_MICERR))) { 1243 /* report MIC failures to net80211 for TKIP */ 1244 ic->ic_stats.is_rx_locmicfail++; 1245 ieee80211_michael_mic_failure(ic, 0/* XXX */); | 1208 goto skip; 1209 } 1210 1211#ifdef HW_CRYPTO 1212 if (__predict_false(rxd->flags & htole32(RT2860_RX_MICERR))) { 1213 /* report MIC failures to net80211 for TKIP */ 1214 ic->ic_stats.is_rx_locmicfail++; 1215 ieee80211_michael_mic_failure(ic, 0/* XXX */); |
1246 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | 1216 counter_u64_add(ic->ic_ierrors, 1); |
1247 goto skip; 1248 } 1249#endif 1250 1251 m1 = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); 1252 if (__predict_false(m1 == NULL)) { | 1217 goto skip; 1218 } 1219#endif 1220 1221 m1 = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); 1222 if (__predict_false(m1 == NULL)) { |
1253 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | 1223 counter_u64_add(ic->ic_ierrors, 1); |
1254 goto skip; 1255 } 1256 1257 bus_dmamap_sync(sc->rxq.data_dmat, data->map, 1258 BUS_DMASYNC_POSTREAD); 1259 bus_dmamap_unload(sc->rxq.data_dmat, data->map); 1260 1261 error = bus_dmamap_load(sc->rxq.data_dmat, data->map, --- 7 unchanged lines hidden (view full) --- 1269 mtod(data->m, void *), MCLBYTES, 1270 rt2860_dma_map_addr, &physaddr, 0); 1271 if (__predict_false(error != 0)) { 1272 panic("%s: could not load old rx mbuf", 1273 device_get_name(sc->sc_dev)); 1274 } 1275 /* physical address may have changed */ 1276 rxd->sdp0 = htole32(physaddr); | 1224 goto skip; 1225 } 1226 1227 bus_dmamap_sync(sc->rxq.data_dmat, data->map, 1228 BUS_DMASYNC_POSTREAD); 1229 bus_dmamap_unload(sc->rxq.data_dmat, data->map); 1230 1231 error = bus_dmamap_load(sc->rxq.data_dmat, data->map, --- 7 unchanged lines hidden (view full) --- 1239 mtod(data->m, void *), MCLBYTES, 1240 rt2860_dma_map_addr, &physaddr, 0); 1241 if (__predict_false(error != 0)) { 1242 panic("%s: could not load old rx mbuf", 1243 device_get_name(sc->sc_dev)); 1244 } 1245 /* physical address may have changed */ 1246 rxd->sdp0 = htole32(physaddr); |
1277 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | 1247 counter_u64_add(ic->ic_ierrors, 1); |
1278 goto skip; 1279 } 1280 1281 /* 1282 * New mbuf successfully loaded, update Rx ring and continue 1283 * processing. 1284 */ 1285 m = data->m; 1286 data->m = m1; 1287 rxd->sdp0 = htole32(physaddr); 1288 1289 rxwi = mtod(m, struct rt2860_rxwi *); 1290 1291 /* finalize mbuf */ | 1248 goto skip; 1249 } 1250 1251 /* 1252 * New mbuf successfully loaded, update Rx ring and continue 1253 * processing. 1254 */ 1255 m = data->m; 1256 data->m = m1; 1257 rxd->sdp0 = htole32(physaddr); 1258 1259 rxwi = mtod(m, struct rt2860_rxwi *); 1260 1261 /* finalize mbuf */ |
1292 m->m_pkthdr.rcvif = ifp; | |
1293 m->m_data = (caddr_t)(rxwi + 1); 1294 m->m_pkthdr.len = m->m_len = le16toh(rxwi->len) & 0xfff; 1295 1296 wh = mtod(m, struct ieee80211_frame *); 1297#ifdef HW_CRYPTO 1298 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 1299 /* frame is decrypted by hardware */ 1300 wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED; --- 93 unchanged lines hidden (view full) --- 1394 1395 /* flush buffered multicast frames */ 1396 if (ic->ic_dtim_count == 0) 1397 ieee80211_notify_dtim(ic); 1398 } 1399#endif 1400 /* check if protection mode has changed */ 1401 if ((sc->sc_ic_flags ^ ic->ic_flags) & IEEE80211_F_USEPROT) { | 1262 m->m_data = (caddr_t)(rxwi + 1); 1263 m->m_pkthdr.len = m->m_len = le16toh(rxwi->len) & 0xfff; 1264 1265 wh = mtod(m, struct ieee80211_frame *); 1266#ifdef HW_CRYPTO 1267 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 1268 /* frame is decrypted by hardware */ 1269 wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED; --- 93 unchanged lines hidden (view full) --- 1363 1364 /* flush buffered multicast frames */ 1365 if (ic->ic_dtim_count == 0) 1366 ieee80211_notify_dtim(ic); 1367 } 1368#endif 1369 /* check if protection mode has changed */ 1370 if ((sc->sc_ic_flags ^ ic->ic_flags) & IEEE80211_F_USEPROT) { |
1402 rt2860_updateprot(ic); | 1371 rt2860_updateprot(sc); |
1403 sc->sc_ic_flags = ic->ic_flags; 1404 } 1405#endif 1406} 1407 1408static void 1409rt2860_gp_intr(struct rt2860_softc *sc) 1410{ | 1372 sc->sc_ic_flags = ic->ic_flags; 1373 } 1374#endif 1375} 1376 1377static void 1378rt2860_gp_intr(struct rt2860_softc *sc) 1379{ |
1411 struct ieee80211com *ic = sc->sc_ifp->if_l2com; | 1380 struct ieee80211com *ic = &sc->sc_ic; |
1412 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); 1413 1414 DPRINTFN(2, ("GP timeout state=%d\n", vap->iv_state)); 1415 1416 if (vap->iv_state == IEEE80211_S_RUN) 1417 rt2860_updatestats(sc); 1418} 1419 --- 55 unchanged lines hidden (view full) --- 1475 rt2860_gp_intr(sc); 1476 1477 RAL_UNLOCK(sc); 1478} 1479 1480static int 1481rt2860_tx(struct rt2860_softc *sc, struct mbuf *m, struct ieee80211_node *ni) 1482{ | 1381 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); 1382 1383 DPRINTFN(2, ("GP timeout state=%d\n", vap->iv_state)); 1384 1385 if (vap->iv_state == IEEE80211_S_RUN) 1386 rt2860_updatestats(sc); 1387} 1388 --- 55 unchanged lines hidden (view full) --- 1444 rt2860_gp_intr(sc); 1445 1446 RAL_UNLOCK(sc); 1447} 1448 1449static int 1450rt2860_tx(struct rt2860_softc *sc, struct mbuf *m, struct ieee80211_node *ni) 1451{ |
1483 struct ifnet *ifp = sc->sc_ifp; 1484 struct ieee80211com *ic = ifp->if_l2com; | 1452 struct ieee80211com *ic = &sc->sc_ic; |
1485 struct ieee80211vap *vap = ni->ni_vap; 1486 struct rt2860_tx_ring *ring; 1487 struct rt2860_tx_data *data; 1488 struct rt2860_txd *txd; 1489 struct rt2860_txwi *txwi; 1490 struct ieee80211_frame *wh; 1491 const struct ieee80211_txparam *tp; 1492 struct ieee80211_key *k; --- 227 unchanged lines hidden (view full) --- 1720 return 0; 1721} 1722 1723static int 1724rt2860_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 1725 const struct ieee80211_bpf_params *params) 1726{ 1727 struct ieee80211com *ic = ni->ni_ic; | 1453 struct ieee80211vap *vap = ni->ni_vap; 1454 struct rt2860_tx_ring *ring; 1455 struct rt2860_tx_data *data; 1456 struct rt2860_txd *txd; 1457 struct rt2860_txwi *txwi; 1458 struct ieee80211_frame *wh; 1459 const struct ieee80211_txparam *tp; 1460 struct ieee80211_key *k; --- 227 unchanged lines hidden (view full) --- 1688 return 0; 1689} 1690 1691static int 1692rt2860_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 1693 const struct ieee80211_bpf_params *params) 1694{ 1695 struct ieee80211com *ic = ni->ni_ic; |
1728 struct ifnet *ifp = ic->ic_ifp; 1729 struct rt2860_softc *sc = ifp->if_softc; | 1696 struct rt2860_softc *sc = ic->ic_softc; |
1730 int error; 1731 1732 RAL_LOCK(sc); 1733 1734 /* prevent management frames from being sent if we're not ready */ | 1697 int error; 1698 1699 RAL_LOCK(sc); 1700 1701 /* prevent management frames from being sent if we're not ready */ |
1735 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { | 1702 if (!(sc->sc_flags & RT2860_RUNNNING)) { |
1736 RAL_UNLOCK(sc); 1737 m_freem(m); 1738 ieee80211_free_node(ni); 1739 return ENETDOWN; 1740 } 1741 if (params == NULL) { 1742 /* 1743 * Legacy path; interpret frame contents to decide --- 5 unchanged lines hidden (view full) --- 1749 * Caller supplied explicit parameters to use in 1750 * sending the frame. 1751 */ 1752 error = rt2860_tx_raw(sc, m, ni, params); 1753 } 1754 if (error != 0) { 1755 /* NB: m is reclaimed on tx failure */ 1756 ieee80211_free_node(ni); | 1703 RAL_UNLOCK(sc); 1704 m_freem(m); 1705 ieee80211_free_node(ni); 1706 return ENETDOWN; 1707 } 1708 if (params == NULL) { 1709 /* 1710 * Legacy path; interpret frame contents to decide --- 5 unchanged lines hidden (view full) --- 1716 * Caller supplied explicit parameters to use in 1717 * sending the frame. 1718 */ 1719 error = rt2860_tx_raw(sc, m, ni, params); 1720 } 1721 if (error != 0) { 1722 /* NB: m is reclaimed on tx failure */ 1723 ieee80211_free_node(ni); |
1757 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | |
1758 } 1759 sc->sc_tx_timer = 5; 1760 RAL_UNLOCK(sc); 1761 return error; 1762} 1763 1764static int 1765rt2860_tx_raw(struct rt2860_softc *sc, struct mbuf *m, 1766 struct ieee80211_node *ni, const struct ieee80211_bpf_params *params) 1767{ | 1724 } 1725 sc->sc_tx_timer = 5; 1726 RAL_UNLOCK(sc); 1727 return error; 1728} 1729 1730static int 1731rt2860_tx_raw(struct rt2860_softc *sc, struct mbuf *m, 1732 struct ieee80211_node *ni, const struct ieee80211_bpf_params *params) 1733{ |
1768 struct ifnet *ifp = sc->sc_ifp; 1769 struct ieee80211com *ic = ifp->if_l2com; | 1734 struct ieee80211com *ic = &sc->sc_ic; |
1770 struct ieee80211vap *vap = ni->ni_vap; 1771 struct rt2860_tx_ring *ring; 1772 struct rt2860_tx_data *data; 1773 struct rt2860_txd *txd; 1774 struct rt2860_txwi *txwi; 1775 struct ieee80211_frame *wh; 1776 struct mbuf *m1; 1777 bus_dma_segment_t segs[RT2860_MAX_SCATTER]; --- 190 unchanged lines hidden (view full) --- 1968 sc->qfullmsk |= 1 << qid; 1969 1970 /* kick Tx */ 1971 RAL_WRITE(sc, RT2860_TX_CTX_IDX(qid), ring->cur); 1972 1973 return 0; 1974} 1975 | 1735 struct ieee80211vap *vap = ni->ni_vap; 1736 struct rt2860_tx_ring *ring; 1737 struct rt2860_tx_data *data; 1738 struct rt2860_txd *txd; 1739 struct rt2860_txwi *txwi; 1740 struct ieee80211_frame *wh; 1741 struct mbuf *m1; 1742 bus_dma_segment_t segs[RT2860_MAX_SCATTER]; --- 190 unchanged lines hidden (view full) --- 1933 sc->qfullmsk |= 1 << qid; 1934 1935 /* kick Tx */ 1936 RAL_WRITE(sc, RT2860_TX_CTX_IDX(qid), ring->cur); 1937 1938 return 0; 1939} 1940 |
1976static void 1977rt2860_start(struct ifnet *ifp) | 1941static int 1942rt2860_transmit(struct ieee80211com *ic, struct mbuf *m) |
1978{ | 1943{ |
1979 struct rt2860_softc *sc = ifp->if_softc; | 1944 struct rt2860_softc *sc = ic->ic_softc; 1945 int error; |
1980 1981 RAL_LOCK(sc); | 1946 1947 RAL_LOCK(sc); |
1982 rt2860_start_locked(ifp); | 1948 if ((sc->sc_flags & RT2860_RUNNNING) == 0) { 1949 RAL_UNLOCK(sc); 1950 return (ENXIO); 1951 } 1952 error = mbufq_enqueue(&sc->sc_snd, m); 1953 if (error) { 1954 RAL_UNLOCK(sc); 1955 return (error); 1956 } 1957 rt2860_start(sc); |
1983 RAL_UNLOCK(sc); | 1958 RAL_UNLOCK(sc); |
1959 1960 return (0); |
|
1984} 1985 1986static void | 1961} 1962 1963static void |
1987rt2860_start_locked(struct ifnet *ifp) | 1964rt2860_start(struct rt2860_softc *sc) |
1988{ | 1965{ |
1989 struct rt2860_softc *sc = ifp->if_softc; | |
1990 struct ieee80211_node *ni; 1991 struct mbuf *m; 1992 1993 RAL_LOCK_ASSERT(sc); 1994 | 1966 struct ieee80211_node *ni; 1967 struct mbuf *m; 1968 1969 RAL_LOCK_ASSERT(sc); 1970 |
1995 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 || 1996 (ifp->if_drv_flags & IFF_DRV_OACTIVE)) | 1971 if ((sc->sc_flags & RT2860_RUNNNING) == 0) |
1997 return; 1998 | 1972 return; 1973 |
1999 for (;;) { 2000 if (SLIST_EMPTY(&sc->data_pool) || sc->qfullmsk != 0) { 2001 ifp->if_drv_flags |= IFF_DRV_OACTIVE; 2002 break; 2003 } 2004 IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 2005 if (m == NULL) 2006 break; | 1974 while (!SLIST_EMPTY(&sc->data_pool) && sc->qfullmsk == 0 && 1975 (m = mbufq_dequeue(&sc->sc_snd)) != NULL) { |
2007 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 2008 if (rt2860_tx(sc, m, ni) != 0) { | 1976 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 1977 if (rt2860_tx(sc, m, ni) != 0) { |
1978 if_inc_counter(ni->ni_vap->iv_ifp, 1979 IFCOUNTER_OERRORS, 1); |
|
2009 ieee80211_free_node(ni); | 1980 ieee80211_free_node(ni); |
2010 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | |
2011 continue; 2012 } 2013 sc->sc_tx_timer = 5; 2014 } 2015} 2016 2017static void 2018rt2860_watchdog(void *arg) 2019{ 2020 struct rt2860_softc *sc = arg; | 1981 continue; 1982 } 1983 sc->sc_tx_timer = 5; 1984 } 1985} 1986 1987static void 1988rt2860_watchdog(void *arg) 1989{ 1990 struct rt2860_softc *sc = arg; |
2021 struct ifnet *ifp = sc->sc_ifp; | |
2022 2023 RAL_LOCK_ASSERT(sc); 2024 | 1991 1992 RAL_LOCK_ASSERT(sc); 1993 |
2025 KASSERT(ifp->if_drv_flags & IFF_DRV_RUNNING, ("not running")); | 1994 KASSERT(sc->sc_flags & RT2860_RUNNNING, ("not running")); |
2026 2027 if (sc->sc_invalid) /* card ejected */ 2028 return; 2029 2030 if (sc->sc_tx_timer > 0 && --sc->sc_tx_timer == 0) { | 1995 1996 if (sc->sc_invalid) /* card ejected */ 1997 return; 1998 1999 if (sc->sc_tx_timer > 0 && --sc->sc_tx_timer == 0) { |
2031 if_printf(ifp, "device timeout\n"); | 2000 device_printf(sc->sc_dev, "device timeout\n"); |
2032 rt2860_stop_locked(sc); 2033 rt2860_init_locked(sc); | 2001 rt2860_stop_locked(sc); 2002 rt2860_init_locked(sc); |
2034 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | 2003 counter_u64_add(sc->sc_ic.ic_oerrors, 1); |
2035 return; 2036 } 2037 callout_reset(&sc->watchdog_ch, hz, rt2860_watchdog, sc); 2038} 2039 | 2004 return; 2005 } 2006 callout_reset(&sc->watchdog_ch, hz, rt2860_watchdog, sc); 2007} 2008 |
2040static int 2041rt2860_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) | 2009static void 2010rt2860_parent(struct ieee80211com *ic) |
2042{ | 2011{ |
2043 struct rt2860_softc *sc = ifp->if_softc; 2044 struct ieee80211com *ic = ifp->if_l2com; 2045 struct ifreq *ifr = (struct ifreq *)data; 2046 int error = 0, startall = 0; | 2012 struct rt2860_softc *sc = ic->ic_softc; 2013 int startall = 0; |
2047 | 2014 |
2048 switch (cmd) { 2049 case SIOCSIFFLAGS: 2050 RAL_LOCK(sc); 2051 if (ifp->if_flags & IFF_UP) { 2052 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { 2053 rt2860_init_locked(sc); 2054 startall = 1; 2055 } else 2056 rt2860_update_promisc(ic); 2057 } else { 2058 if (ifp->if_drv_flags & IFF_DRV_RUNNING) 2059 rt2860_stop_locked(sc); 2060 } 2061 RAL_UNLOCK(sc); 2062 if (startall) 2063 ieee80211_start_all(ic); 2064 break; 2065 case SIOCGIFMEDIA: 2066 error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd); 2067 break; 2068 case SIOCSIFADDR: 2069 error = ether_ioctl(ifp, cmd, data); 2070 break; 2071 default: 2072 error = EINVAL; 2073 break; 2074 } 2075 return error; | 2015 RAL_LOCK(sc); 2016 if (ic->ic_nrunning> 0) { 2017 if (!(sc->sc_flags & RT2860_RUNNNING)) { 2018 rt2860_init_locked(sc); 2019 startall = 1; 2020 } else 2021 rt2860_update_promisc(ic); 2022 } else if (sc->sc_flags & RT2860_RUNNNING) 2023 rt2860_stop_locked(sc); 2024 RAL_UNLOCK(sc); 2025 if (startall) 2026 ieee80211_start_all(ic); |
2076} 2077 2078/* 2079 * Reading and writing from/to the BBP is different from RT2560 and RT2661. 2080 * We access the BBP through the 8051 microcontroller unit which means that 2081 * the microcode must be loaded first. 2082 */ 2083void --- 206 unchanged lines hidden (view full) --- 2290 CCK(0)); /* 1-> 1 */ 2291#undef OFDM 2292#undef CCK 2293} 2294 2295static void 2296rt2860_set_txpreamble(struct rt2860_softc *sc) 2297{ | 2027} 2028 2029/* 2030 * Reading and writing from/to the BBP is different from RT2560 and RT2661. 2031 * We access the BBP through the 8051 microcontroller unit which means that 2032 * the microcode must be loaded first. 2033 */ 2034void --- 206 unchanged lines hidden (view full) --- 2241 CCK(0)); /* 1-> 1 */ 2242#undef OFDM 2243#undef CCK 2244} 2245 2246static void 2247rt2860_set_txpreamble(struct rt2860_softc *sc) 2248{ |
2298 struct ifnet *ifp = sc->sc_ifp; 2299 struct ieee80211com *ic = ifp->if_l2com; | 2249 struct ieee80211com *ic = &sc->sc_ic; |
2300 uint32_t tmp; 2301 2302 tmp = RAL_READ(sc, RT2860_AUTO_RSP_CFG); 2303 tmp &= ~RT2860_CCK_SHORT_EN; 2304 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) 2305 tmp |= RT2860_CCK_SHORT_EN; 2306 RAL_WRITE(sc, RT2860_AUTO_RSP_CFG, tmp); 2307} 2308 2309void 2310rt2860_set_basicrates(struct rt2860_softc *sc, 2311 const struct ieee80211_rateset *rs) 2312{ 2313#define RV(r) ((r) & IEEE80211_RATE_VAL) | 2250 uint32_t tmp; 2251 2252 tmp = RAL_READ(sc, RT2860_AUTO_RSP_CFG); 2253 tmp &= ~RT2860_CCK_SHORT_EN; 2254 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) 2255 tmp |= RT2860_CCK_SHORT_EN; 2256 RAL_WRITE(sc, RT2860_AUTO_RSP_CFG, tmp); 2257} 2258 2259void 2260rt2860_set_basicrates(struct rt2860_softc *sc, 2261 const struct ieee80211_rateset *rs) 2262{ 2263#define RV(r) ((r) & IEEE80211_RATE_VAL) |
2314 struct ifnet *ifp = sc->sc_ifp; 2315 struct ieee80211com *ic = ifp->if_l2com; | 2264 struct ieee80211com *ic = &sc->sc_ic; |
2316 uint32_t mask = 0; 2317 uint8_t rate; 2318 int i; 2319 2320 for (i = 0; i < rs->rs_nrates; i++) { 2321 rate = rs->rs_rates[i]; 2322 2323 if (!(rate & IEEE80211_RATE_BASIC)) --- 4 unchanged lines hidden (view full) --- 2328 2329 RAL_WRITE(sc, RT2860_LEGACY_BASIC_RATE, mask); 2330#undef RV 2331} 2332 2333static void 2334rt2860_scan_start(struct ieee80211com *ic) 2335{ | 2265 uint32_t mask = 0; 2266 uint8_t rate; 2267 int i; 2268 2269 for (i = 0; i < rs->rs_nrates; i++) { 2270 rate = rs->rs_rates[i]; 2271 2272 if (!(rate & IEEE80211_RATE_BASIC)) --- 4 unchanged lines hidden (view full) --- 2277 2278 RAL_WRITE(sc, RT2860_LEGACY_BASIC_RATE, mask); 2279#undef RV 2280} 2281 2282static void 2283rt2860_scan_start(struct ieee80211com *ic) 2284{ |
2336 struct ifnet *ifp = ic->ic_ifp; 2337 struct rt2860_softc *sc = ifp->if_softc; | 2285 struct rt2860_softc *sc = ic->ic_softc; |
2338 uint32_t tmp; 2339 2340 tmp = RAL_READ(sc, RT2860_BCN_TIME_CFG); 2341 RAL_WRITE(sc, RT2860_BCN_TIME_CFG, 2342 tmp & ~(RT2860_BCN_TX_EN | RT2860_TSF_TIMER_EN | 2343 RT2860_TBTT_TIMER_EN)); 2344 rt2860_set_gp_timer(sc, 0); 2345} 2346 2347static void 2348rt2860_scan_end(struct ieee80211com *ic) 2349{ | 2286 uint32_t tmp; 2287 2288 tmp = RAL_READ(sc, RT2860_BCN_TIME_CFG); 2289 RAL_WRITE(sc, RT2860_BCN_TIME_CFG, 2290 tmp & ~(RT2860_BCN_TX_EN | RT2860_TSF_TIMER_EN | 2291 RT2860_TBTT_TIMER_EN)); 2292 rt2860_set_gp_timer(sc, 0); 2293} 2294 2295static void 2296rt2860_scan_end(struct ieee80211com *ic) 2297{ |
2350 struct ifnet *ifp = ic->ic_ifp; 2351 struct rt2860_softc *sc = ifp->if_softc; | 2298 struct rt2860_softc *sc = ic->ic_softc; |
2352 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); 2353 2354 if (vap->iv_state == IEEE80211_S_RUN) { 2355 rt2860_enable_tsf_sync(sc); 2356 rt2860_set_gp_timer(sc, 500); 2357 } 2358} 2359 2360static void 2361rt2860_set_channel(struct ieee80211com *ic) 2362{ | 2299 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); 2300 2301 if (vap->iv_state == IEEE80211_S_RUN) { 2302 rt2860_enable_tsf_sync(sc); 2303 rt2860_set_gp_timer(sc, 500); 2304 } 2305} 2306 2307static void 2308rt2860_set_channel(struct ieee80211com *ic) 2309{ |
2363 struct ifnet *ifp = ic->ic_ifp; 2364 struct rt2860_softc *sc = ifp->if_softc; | 2310 struct rt2860_softc *sc = ic->ic_softc; |
2365 2366 RAL_LOCK(sc); 2367 rt2860_switch_chan(sc, ic->ic_curchan); 2368 RAL_UNLOCK(sc); 2369} 2370 2371static void 2372rt2860_select_chan_group(struct rt2860_softc *sc, int group) --- 735 unchanged lines hidden (view full) --- 3108 3109 tmp = RAL_READ(sc, RT2860_BKOFF_SLOT_CFG); 3110 tmp &= ~0xff; 3111 tmp |= (ic->ic_flags & IEEE80211_F_SHSLOT) ? 9 : 20; 3112 RAL_WRITE(sc, RT2860_BKOFF_SLOT_CFG, tmp); 3113} 3114 3115static void | 2311 2312 RAL_LOCK(sc); 2313 rt2860_switch_chan(sc, ic->ic_curchan); 2314 RAL_UNLOCK(sc); 2315} 2316 2317static void 2318rt2860_select_chan_group(struct rt2860_softc *sc, int group) --- 735 unchanged lines hidden (view full) --- 3054 3055 tmp = RAL_READ(sc, RT2860_BKOFF_SLOT_CFG); 3056 tmp &= ~0xff; 3057 tmp |= (ic->ic_flags & IEEE80211_F_SHSLOT) ? 9 : 20; 3058 RAL_WRITE(sc, RT2860_BKOFF_SLOT_CFG, tmp); 3059} 3060 3061static void |
3116rt2860_updateprot(struct ifnet *ifp) | 3062rt2860_updateprot(struct rt2860_softc *sc) |
3117{ | 3063{ |
3118 struct rt2860_softc *sc = ifp->if_softc; 3119 struct ieee80211com *ic = ifp->if_l2com; | 3064 struct ieee80211com *ic = &sc->sc_ic; |
3120 uint32_t tmp; 3121 3122 tmp = RT2860_RTSTH_EN | RT2860_PROT_NAV_SHORT | RT2860_TXOP_ALLOW_ALL; 3123 /* setup protection frame rate (MCS code) */ 3124 tmp |= IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan) ? 3125 rt2860_rates[RT2860_RIDX_OFDM6].mcs : 3126 rt2860_rates[RT2860_RIDX_CCK11].mcs; 3127 --- 12 unchanged lines hidden (view full) --- 3140static void 3141rt2860_update_promisc(struct ieee80211com *ic) 3142{ 3143 struct rt2860_softc *sc = ic->ic_softc; 3144 uint32_t tmp; 3145 3146 tmp = RAL_READ(sc, RT2860_RX_FILTR_CFG); 3147 tmp &= ~RT2860_DROP_NOT_MYBSS; | 3065 uint32_t tmp; 3066 3067 tmp = RT2860_RTSTH_EN | RT2860_PROT_NAV_SHORT | RT2860_TXOP_ALLOW_ALL; 3068 /* setup protection frame rate (MCS code) */ 3069 tmp |= IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan) ? 3070 rt2860_rates[RT2860_RIDX_OFDM6].mcs : 3071 rt2860_rates[RT2860_RIDX_CCK11].mcs; 3072 --- 12 unchanged lines hidden (view full) --- 3085static void 3086rt2860_update_promisc(struct ieee80211com *ic) 3087{ 3088 struct rt2860_softc *sc = ic->ic_softc; 3089 uint32_t tmp; 3090 3091 tmp = RAL_READ(sc, RT2860_RX_FILTR_CFG); 3092 tmp &= ~RT2860_DROP_NOT_MYBSS; |
3148 if (!(ic->ic_ifp->if_flags & IFF_PROMISC)) | 3093 if (ic->ic_promisc == 0) |
3149 tmp |= RT2860_DROP_NOT_MYBSS; 3150 RAL_WRITE(sc, RT2860_RX_FILTR_CFG, tmp); 3151} 3152 3153static int 3154rt2860_updateedca(struct ieee80211com *ic) 3155{ | 3094 tmp |= RT2860_DROP_NOT_MYBSS; 3095 RAL_WRITE(sc, RT2860_RX_FILTR_CFG, tmp); 3096} 3097 3098static int 3099rt2860_updateedca(struct ieee80211com *ic) 3100{ |
3156 struct rt2860_softc *sc = ic->ic_ifp->if_softc; | 3101 struct rt2860_softc *sc = ic->ic_softc; |
3157 const struct wmeParams *wmep; 3158 int aci; 3159 3160 wmep = ic->ic_wme.wme_chanParams.cap_wmeParams; 3161 3162 /* update MAC TX configuration registers */ 3163 for (aci = 0; aci < WME_NUM_AC; aci++) { 3164 RAL_WRITE(sc, RT2860_EDCA_AC_CFG(aci), --- 155 unchanged lines hidden (view full) --- 3320 RAL_WRITE(sc, RT2860_WCID_ATTR(wcid), attr); 3321 } 3322} 3323#endif 3324 3325static int8_t 3326rt2860_rssi2dbm(struct rt2860_softc *sc, uint8_t rssi, uint8_t rxchain) 3327{ | 3102 const struct wmeParams *wmep; 3103 int aci; 3104 3105 wmep = ic->ic_wme.wme_chanParams.cap_wmeParams; 3106 3107 /* update MAC TX configuration registers */ 3108 for (aci = 0; aci < WME_NUM_AC; aci++) { 3109 RAL_WRITE(sc, RT2860_EDCA_AC_CFG(aci), --- 155 unchanged lines hidden (view full) --- 3265 RAL_WRITE(sc, RT2860_WCID_ATTR(wcid), attr); 3266 } 3267} 3268#endif 3269 3270static int8_t 3271rt2860_rssi2dbm(struct rt2860_softc *sc, uint8_t rssi, uint8_t rxchain) 3272{ |
3328 struct ifnet *ifp = sc->sc_ifp; 3329 struct ieee80211com *ic = ifp->if_l2com; | 3273 struct ieee80211com *ic = &sc->sc_ic; |
3330 struct ieee80211_channel *c = ic->ic_curchan; 3331 int delta; 3332 3333 if (IEEE80211_IS_CHAN_5GHZ(c)) { 3334 u_int chan = ieee80211_chan2ieee(ic, c); 3335 delta = sc->rssi_5ghz[rxchain]; 3336 3337 /* determine channel group */ --- 458 unchanged lines hidden (view full) --- 3796 /* Disable hardware antenna diversity. */ 3797 if (sc->mac_ver == 0x5390) 3798 rt2860_mcu_bbp_write(sc, 154, 0); 3799} 3800 3801static int 3802rt2860_txrx_enable(struct rt2860_softc *sc) 3803{ | 3274 struct ieee80211_channel *c = ic->ic_curchan; 3275 int delta; 3276 3277 if (IEEE80211_IS_CHAN_5GHZ(c)) { 3278 u_int chan = ieee80211_chan2ieee(ic, c); 3279 delta = sc->rssi_5ghz[rxchain]; 3280 3281 /* determine channel group */ --- 458 unchanged lines hidden (view full) --- 3740 /* Disable hardware antenna diversity. */ 3741 if (sc->mac_ver == 0x5390) 3742 rt2860_mcu_bbp_write(sc, 154, 0); 3743} 3744 3745static int 3746rt2860_txrx_enable(struct rt2860_softc *sc) 3747{ |
3804 struct ifnet *ifp = sc->sc_ifp; 3805 struct ieee80211com *ic = ifp->if_l2com; | 3748 struct ieee80211com *ic = &sc->sc_ic; |
3806 uint32_t tmp; 3807 int ntries; 3808 3809 /* enable Tx/Rx DMA engine */ 3810 RAL_WRITE(sc, RT2860_MAC_SYS_CTRL, RT2860_MAC_TX_EN); 3811 RAL_BARRIER_READ_WRITE(sc); 3812 for (ntries = 0; ntries < 200; ntries++) { 3813 tmp = RAL_READ(sc, RT2860_WPDMA_GLO_CFG); --- 29 unchanged lines hidden (view full) --- 3843 3844 return 0; 3845} 3846 3847static void 3848rt2860_init(void *arg) 3849{ 3850 struct rt2860_softc *sc = arg; | 3749 uint32_t tmp; 3750 int ntries; 3751 3752 /* enable Tx/Rx DMA engine */ 3753 RAL_WRITE(sc, RT2860_MAC_SYS_CTRL, RT2860_MAC_TX_EN); 3754 RAL_BARRIER_READ_WRITE(sc); 3755 for (ntries = 0; ntries < 200; ntries++) { 3756 tmp = RAL_READ(sc, RT2860_WPDMA_GLO_CFG); --- 29 unchanged lines hidden (view full) --- 3786 3787 return 0; 3788} 3789 3790static void 3791rt2860_init(void *arg) 3792{ 3793 struct rt2860_softc *sc = arg; |
3851 struct ifnet *ifp = sc->sc_ifp; 3852 struct ieee80211com *ic = ifp->if_l2com; | 3794 struct ieee80211com *ic = &sc->sc_ic; |
3853 3854 RAL_LOCK(sc); 3855 rt2860_init_locked(sc); 3856 RAL_UNLOCK(sc); 3857 | 3795 3796 RAL_LOCK(sc); 3797 rt2860_init_locked(sc); 3798 RAL_UNLOCK(sc); 3799 |
3858 if (ifp->if_drv_flags & IFF_DRV_RUNNING) | 3800 if (sc->sc_flags & RT2860_RUNNNING) |
3859 ieee80211_start_all(ic); 3860} 3861 3862static void 3863rt2860_init_locked(struct rt2860_softc *sc) 3864{ | 3801 ieee80211_start_all(ic); 3802} 3803 3804static void 3805rt2860_init_locked(struct rt2860_softc *sc) 3806{ |
3865 struct ifnet *ifp = sc->sc_ifp; 3866 struct ieee80211com *ic = ifp->if_l2com; | 3807 struct ieee80211com *ic = &sc->sc_ic; 3808 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
3867 uint32_t tmp; 3868 uint8_t bbp1, bbp3; 3869 int i, qid, ridx, ntries, error; 3870 3871 RAL_LOCK_ASSERT(sc); 3872 3873 if (sc->rfswitch) { 3874 /* hardware has a radio switch on GPIO pin 2 */ --- 19 unchanged lines hidden (view full) --- 3894 RAL_WRITE(sc, RT2860_SYS_CTRL, 0xe00); 3895 3896 if ((error = rt2860_load_microcode(sc)) != 0) { 3897 device_printf(sc->sc_dev, "could not load 8051 microcode\n"); 3898 rt2860_stop_locked(sc); 3899 return; 3900 } 3901 | 3809 uint32_t tmp; 3810 uint8_t bbp1, bbp3; 3811 int i, qid, ridx, ntries, error; 3812 3813 RAL_LOCK_ASSERT(sc); 3814 3815 if (sc->rfswitch) { 3816 /* hardware has a radio switch on GPIO pin 2 */ --- 19 unchanged lines hidden (view full) --- 3836 RAL_WRITE(sc, RT2860_SYS_CTRL, 0xe00); 3837 3838 if ((error = rt2860_load_microcode(sc)) != 0) { 3839 device_printf(sc->sc_dev, "could not load 8051 microcode\n"); 3840 rt2860_stop_locked(sc); 3841 return; 3842 } 3843 |
3902 rt2860_set_macaddr(sc, IF_LLADDR(ifp)); | 3844 rt2860_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr); |
3903 3904 /* init Tx power for all Tx rates (from EEPROM) */ 3905 for (ridx = 0; ridx < 5; ridx++) { 3906 if (sc->txpow20mhz[ridx] == 0xffffffff) 3907 continue; 3908 RAL_WRITE(sc, RT2860_TX_PWR_CFG(ridx), sc->txpow20mhz[ridx]); 3909 } 3910 --- 180 unchanged lines hidden (view full) --- 4091 4092 /* set RTS threshold */ 4093 tmp = RAL_READ(sc, RT2860_TX_RTS_CFG); 4094 tmp &= ~0xffff00; 4095 tmp |= IEEE80211_RTS_DEFAULT << 8; 4096 RAL_WRITE(sc, RT2860_TX_RTS_CFG, tmp); 4097 4098 /* setup initial protection mode */ | 3845 3846 /* init Tx power for all Tx rates (from EEPROM) */ 3847 for (ridx = 0; ridx < 5; ridx++) { 3848 if (sc->txpow20mhz[ridx] == 0xffffffff) 3849 continue; 3850 RAL_WRITE(sc, RT2860_TX_PWR_CFG(ridx), sc->txpow20mhz[ridx]); 3851 } 3852 --- 180 unchanged lines hidden (view full) --- 4033 4034 /* set RTS threshold */ 4035 tmp = RAL_READ(sc, RT2860_TX_RTS_CFG); 4036 tmp &= ~0xffff00; 4037 tmp |= IEEE80211_RTS_DEFAULT << 8; 4038 RAL_WRITE(sc, RT2860_TX_RTS_CFG, tmp); 4039 4040 /* setup initial protection mode */ |
4099 rt2860_updateprot(ifp); | 4041 rt2860_updateprot(sc); |
4100 4101 /* turn radio LED on */ 4102 rt2860_set_leds(sc, RT2860_LED_RADIO); 4103 4104 /* enable Tx/Rx DMA engine */ 4105 if ((error = rt2860_txrx_enable(sc)) != 0) { 4106 rt2860_stop_locked(sc); 4107 return; 4108 } 4109 4110 /* clear pending interrupts */ 4111 RAL_WRITE(sc, RT2860_INT_STATUS, 0xffffffff); 4112 /* enable interrupts */ 4113 RAL_WRITE(sc, RT2860_INT_MASK, 0x3fffc); 4114 4115 if (sc->sc_flags & RT2860_ADVANCED_PS) 4116 rt2860_mcu_cmd(sc, RT2860_MCU_CMD_PSLEVEL, sc->pslevel, 0); 4117 | 4042 4043 /* turn radio LED on */ 4044 rt2860_set_leds(sc, RT2860_LED_RADIO); 4045 4046 /* enable Tx/Rx DMA engine */ 4047 if ((error = rt2860_txrx_enable(sc)) != 0) { 4048 rt2860_stop_locked(sc); 4049 return; 4050 } 4051 4052 /* clear pending interrupts */ 4053 RAL_WRITE(sc, RT2860_INT_STATUS, 0xffffffff); 4054 /* enable interrupts */ 4055 RAL_WRITE(sc, RT2860_INT_MASK, 0x3fffc); 4056 4057 if (sc->sc_flags & RT2860_ADVANCED_PS) 4058 rt2860_mcu_cmd(sc, RT2860_MCU_CMD_PSLEVEL, sc->pslevel, 0); 4059 |
4118 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 4119 ifp->if_drv_flags |= IFF_DRV_RUNNING; | 4060 sc->sc_flags |= RT2860_RUNNNING; |
4120 4121 callout_reset(&sc->watchdog_ch, hz, rt2860_watchdog, sc); 4122} 4123 4124static void 4125rt2860_stop(void *arg) 4126{ 4127 struct rt2860_softc *sc = arg; 4128 4129 RAL_LOCK(sc); 4130 rt2860_stop_locked(sc); 4131 RAL_UNLOCK(sc); 4132} 4133 4134static void 4135rt2860_stop_locked(struct rt2860_softc *sc) 4136{ | 4061 4062 callout_reset(&sc->watchdog_ch, hz, rt2860_watchdog, sc); 4063} 4064 4065static void 4066rt2860_stop(void *arg) 4067{ 4068 struct rt2860_softc *sc = arg; 4069 4070 RAL_LOCK(sc); 4071 rt2860_stop_locked(sc); 4072 RAL_UNLOCK(sc); 4073} 4074 4075static void 4076rt2860_stop_locked(struct rt2860_softc *sc) 4077{ |
4137 struct ifnet *ifp = sc->sc_ifp; | |
4138 uint32_t tmp; 4139 int qid; 4140 | 4078 uint32_t tmp; 4079 int qid; 4080 |
4141 if (ifp->if_drv_flags & IFF_DRV_RUNNING) | 4081 if (sc->sc_flags & RT2860_RUNNNING) |
4142 rt2860_set_leds(sc, 0); /* turn all LEDs off */ 4143 4144 callout_stop(&sc->watchdog_ch); 4145 sc->sc_tx_timer = 0; | 4082 rt2860_set_leds(sc, 0); /* turn all LEDs off */ 4083 4084 callout_stop(&sc->watchdog_ch); 4085 sc->sc_tx_timer = 0; |
4146 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); | 4086 sc->sc_flags &= ~RT2860_RUNNNING; |
4147 4148 /* disable interrupts */ 4149 RAL_WRITE(sc, RT2860_INT_MASK, 0); 4150 4151 /* disable GP timer */ 4152 rt2860_set_gp_timer(sc, 0); 4153 4154 /* disable Rx */ --- 134 unchanged lines hidden (view full) --- 4289 RAL_WRITE(sc, RT2860_GPIO_CTRL, tmp & ~0x0808); 4290 } 4291 } 4292} 4293 4294static void 4295rt2860_switch_chan(struct rt2860_softc *sc, struct ieee80211_channel *c) 4296{ | 4087 4088 /* disable interrupts */ 4089 RAL_WRITE(sc, RT2860_INT_MASK, 0); 4090 4091 /* disable GP timer */ 4092 rt2860_set_gp_timer(sc, 0); 4093 4094 /* disable Rx */ --- 134 unchanged lines hidden (view full) --- 4229 RAL_WRITE(sc, RT2860_GPIO_CTRL, tmp & ~0x0808); 4230 } 4231 } 4232} 4233 4234static void 4235rt2860_switch_chan(struct rt2860_softc *sc, struct ieee80211_channel *c) 4236{ |
4297 struct ifnet *ifp = sc->sc_ifp; 4298 struct ieee80211com *ic = ifp->if_l2com; | 4237 struct ieee80211com *ic = &sc->sc_ic; |
4299 u_int chan, group; 4300 4301 chan = ieee80211_chan2ieee(ic, c); 4302 if (chan == 0 || chan == IEEE80211_CHAN_ANY) 4303 return; 4304 4305 if (sc->mac_ver >= 0x5390) 4306 rt5390_set_chan(sc, chan); --- 52 unchanged lines hidden (view full) --- 4359 m_freem(m); 4360 4361 return 0; 4362} 4363 4364static void 4365rt2860_enable_tsf_sync(struct rt2860_softc *sc) 4366{ | 4238 u_int chan, group; 4239 4240 chan = ieee80211_chan2ieee(ic, c); 4241 if (chan == 0 || chan == IEEE80211_CHAN_ANY) 4242 return; 4243 4244 if (sc->mac_ver >= 0x5390) 4245 rt5390_set_chan(sc, chan); --- 52 unchanged lines hidden (view full) --- 4298 m_freem(m); 4299 4300 return 0; 4301} 4302 4303static void 4304rt2860_enable_tsf_sync(struct rt2860_softc *sc) 4305{ |
4367 struct ifnet *ifp = sc->sc_ifp; 4368 struct ieee80211com *ic = ifp->if_l2com; | 4306 struct ieee80211com *ic = &sc->sc_ic; |
4369 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); 4370 uint32_t tmp; 4371 4372 tmp = RAL_READ(sc, RT2860_BCN_TIME_CFG); 4373 4374 tmp &= ~0x1fffff; 4375 tmp |= vap->iv_bss->ni_intval * 16; 4376 tmp |= RT2860_TSF_TIMER_EN | RT2860_TBTT_TIMER_EN; --- 23 unchanged lines hidden --- | 4307 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); 4308 uint32_t tmp; 4309 4310 tmp = RAL_READ(sc, RT2860_BCN_TIME_CFG); 4311 4312 tmp &= ~0x1fffff; 4313 tmp |= vap->iv_bss->ni_intval * 16; 4314 tmp |= RT2860_TSF_TIMER_EN | RT2860_TBTT_TIMER_EN; --- 23 unchanged lines hidden --- |