Deleted Added
full compact
if_iwn.c (285234) if_iwn.c (286410)
1/*-
2 * Copyright (c) 2007-2009 Damien Bergamini <damien.bergamini@free.fr>
3 * Copyright (c) 2008 Benjamin Close <benjsc@FreeBSD.org>
4 * Copyright (c) 2008 Sam Leffler, Errno Consulting
5 * Copyright (c) 2011 Intel Corporation
6 * Copyright (c) 2013 Cedric GROSS <c.gross@kreiz-it.fr>
7 * Copyright (c) 2013 Adrian Chadd <adrian@FreeBSD.org>
8 *

--- 11 unchanged lines hidden (view full) ---

20 */
21
22/*
23 * Driver for Intel WiFi Link 4965 and 1000/5000/6000 Series 802.11 network
24 * adapters.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2007-2009 Damien Bergamini <damien.bergamini@free.fr>
3 * Copyright (c) 2008 Benjamin Close <benjsc@FreeBSD.org>
4 * Copyright (c) 2008 Sam Leffler, Errno Consulting
5 * Copyright (c) 2011 Intel Corporation
6 * Copyright (c) 2013 Cedric GROSS <c.gross@kreiz-it.fr>
7 * Copyright (c) 2013 Adrian Chadd <adrian@FreeBSD.org>
8 *

--- 11 unchanged lines hidden (view full) ---

20 */
21
22/*
23 * Driver for Intel WiFi Link 4965 and 1000/5000/6000 Series 802.11 network
24 * adapters.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/iwn/if_iwn.c 285234 2015-07-07 03:51:29Z adrian $");
28__FBSDID("$FreeBSD: head/sys/dev/iwn/if_iwn.c 286410 2015-08-07 11:43:14Z glebius $");
29
30#include "opt_wlan.h"
31#include "opt_iwn.h"
32
33#include <sys/param.h>
34#include <sys/sockio.h>
35#include <sys/sysctl.h>
36#include <sys/mbuf.h>

--- 193 unchanged lines hidden (view full) ---

230static int iwn_tx_data(struct iwn_softc *, struct mbuf *,
231 struct ieee80211_node *);
232static int iwn_tx_data_raw(struct iwn_softc *, struct mbuf *,
233 struct ieee80211_node *,
234 const struct ieee80211_bpf_params *params);
235static void iwn_xmit_task(void *arg0, int pending);
236static int iwn_raw_xmit(struct ieee80211_node *, struct mbuf *,
237 const struct ieee80211_bpf_params *);
29
30#include "opt_wlan.h"
31#include "opt_iwn.h"
32
33#include <sys/param.h>
34#include <sys/sockio.h>
35#include <sys/sysctl.h>
36#include <sys/mbuf.h>

--- 193 unchanged lines hidden (view full) ---

230static int iwn_tx_data(struct iwn_softc *, struct mbuf *,
231 struct ieee80211_node *);
232static int iwn_tx_data_raw(struct iwn_softc *, struct mbuf *,
233 struct ieee80211_node *,
234 const struct ieee80211_bpf_params *params);
235static void iwn_xmit_task(void *arg0, int pending);
236static int iwn_raw_xmit(struct ieee80211_node *, struct mbuf *,
237 const struct ieee80211_bpf_params *);
238static void iwn_start(struct ifnet *);
239static void iwn_start_locked(struct ifnet *);
238static int iwn_transmit(struct ieee80211com *, struct mbuf *);
239static void iwn_start_locked(struct iwn_softc *);
240static void iwn_watchdog(void *);
240static void iwn_watchdog(void *);
241static int iwn_ioctl(struct ifnet *, u_long, caddr_t);
241static int iwn_ioctl(struct ieee80211com *, u_long , void *);
242static void iwn_parent(struct ieee80211com *);
242static int iwn_cmd(struct iwn_softc *, int, const void *, int, int);
243static int iwn4965_add_node(struct iwn_softc *, struct iwn_node_info *,
244 int);
245static int iwn5000_add_node(struct iwn_softc *, struct iwn_node_info *,
246 int);
247static int iwn_set_link_quality(struct iwn_softc *,
248 struct ieee80211_node *);
249static int iwn_add_broadcast_node(struct iwn_softc *, int);

--- 81 unchanged lines hidden (view full) ---

331static int iwn5000_nic_config(struct iwn_softc *);
332static int iwn_hw_prepare(struct iwn_softc *);
333static int iwn_hw_init(struct iwn_softc *);
334static void iwn_hw_stop(struct iwn_softc *);
335static void iwn_radio_on(void *, int);
336static void iwn_radio_off(void *, int);
337static void iwn_panicked(void *, int);
338static void iwn_init_locked(struct iwn_softc *);
243static int iwn_cmd(struct iwn_softc *, int, const void *, int, int);
244static int iwn4965_add_node(struct iwn_softc *, struct iwn_node_info *,
245 int);
246static int iwn5000_add_node(struct iwn_softc *, struct iwn_node_info *,
247 int);
248static int iwn_set_link_quality(struct iwn_softc *,
249 struct ieee80211_node *);
250static int iwn_add_broadcast_node(struct iwn_softc *, int);

--- 81 unchanged lines hidden (view full) ---

332static int iwn5000_nic_config(struct iwn_softc *);
333static int iwn_hw_prepare(struct iwn_softc *);
334static int iwn_hw_init(struct iwn_softc *);
335static void iwn_hw_stop(struct iwn_softc *);
336static void iwn_radio_on(void *, int);
337static void iwn_radio_off(void *, int);
338static void iwn_panicked(void *, int);
339static void iwn_init_locked(struct iwn_softc *);
339static void iwn_init(void *);
340static void iwn_init(struct iwn_softc *);
340static void iwn_stop_locked(struct iwn_softc *);
341static void iwn_stop(struct iwn_softc *);
342static void iwn_scan_start(struct ieee80211com *);
343static void iwn_scan_end(struct ieee80211com *);
344static void iwn_set_channel(struct ieee80211com *);
345static void iwn_scan_curchan(struct ieee80211_scan_state *, unsigned long);
346static void iwn_scan_mindwell(struct ieee80211_scan_state *);
347static void iwn_hw_reset(void *, int);

--- 53 unchanged lines hidden (view full) ---

401 return (0);
402}
403
404static int
405iwn_attach(device_t dev)
406{
407 struct iwn_softc *sc = (struct iwn_softc *)device_get_softc(dev);
408 struct ieee80211com *ic;
341static void iwn_stop_locked(struct iwn_softc *);
342static void iwn_stop(struct iwn_softc *);
343static void iwn_scan_start(struct ieee80211com *);
344static void iwn_scan_end(struct ieee80211com *);
345static void iwn_set_channel(struct ieee80211com *);
346static void iwn_scan_curchan(struct ieee80211_scan_state *, unsigned long);
347static void iwn_scan_mindwell(struct ieee80211_scan_state *);
348static void iwn_hw_reset(void *, int);

--- 53 unchanged lines hidden (view full) ---

402 return (0);
403}
404
405static int
406iwn_attach(device_t dev)
407{
408 struct iwn_softc *sc = (struct iwn_softc *)device_get_softc(dev);
409 struct ieee80211com *ic;
409 struct ifnet *ifp;
410 int i, error, rid;
410 int i, error, rid;
411 uint8_t macaddr[IEEE80211_ADDR_LEN];
412
413 sc->sc_dev = dev;
414
415#ifdef IWN_DEBUG
416 error = resource_int_value(device_get_name(sc->sc_dev),
417 device_get_unit(sc->sc_dev), "debug", &(sc->sc_debug));
418 if (error != 0)
419 sc->sc_debug = 0;

--- 39 unchanged lines hidden (view full) ---

459 (rid != 0 ? 0 : RF_SHAREABLE));
460 if (sc->irq == NULL) {
461 device_printf(dev, "can't map interrupt\n");
462 error = ENOMEM;
463 goto fail;
464 }
465
466 IWN_LOCK_INIT(sc);
411
412 sc->sc_dev = dev;
413
414#ifdef IWN_DEBUG
415 error = resource_int_value(device_get_name(sc->sc_dev),
416 device_get_unit(sc->sc_dev), "debug", &(sc->sc_debug));
417 if (error != 0)
418 sc->sc_debug = 0;

--- 39 unchanged lines hidden (view full) ---

458 (rid != 0 ? 0 : RF_SHAREABLE));
459 if (sc->irq == NULL) {
460 device_printf(dev, "can't map interrupt\n");
461 error = ENOMEM;
462 goto fail;
463 }
464
465 IWN_LOCK_INIT(sc);
466 mbufq_init(&sc->sc_snd, ifqmaxlen);
467
468 /* Read hardware revision and attach. */
469 sc->hw_type = (IWN_READ(sc, IWN_HW_REV) >> IWN_HW_REV_TYPE_SHIFT)
470 & IWN_HW_REV_TYPE_MASK;
471 sc->subdevice_id = pci_get_subdevice(dev);
472
473 /*
474 * 4965 versus 5000 and later have different methods.

--- 69 unchanged lines hidden (view full) ---

544 device_printf(dev, "could not allocate RX ring, error %d\n",
545 error);
546 goto fail;
547 }
548
549 /* Clear pending interrupts. */
550 IWN_WRITE(sc, IWN_INT, 0xffffffff);
551
467
468 /* Read hardware revision and attach. */
469 sc->hw_type = (IWN_READ(sc, IWN_HW_REV) >> IWN_HW_REV_TYPE_SHIFT)
470 & IWN_HW_REV_TYPE_MASK;
471 sc->subdevice_id = pci_get_subdevice(dev);
472
473 /*
474 * 4965 versus 5000 and later have different methods.

--- 69 unchanged lines hidden (view full) ---

544 device_printf(dev, "could not allocate RX ring, error %d\n",
545 error);
546 goto fail;
547 }
548
549 /* Clear pending interrupts. */
550 IWN_WRITE(sc, IWN_INT, 0xffffffff);
551
552 ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211);
553 if (ifp == NULL) {
554 device_printf(dev, "can not allocate ifnet structure\n");
555 goto fail;
556 }
557
558 ic = ifp->if_l2com;
559 ic->ic_ifp = ifp;
552 ic = &sc->sc_ic;
560 ic->ic_softc = sc;
561 ic->ic_name = device_get_nameunit(dev);
562 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
563 ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */
564
565 /* Set device capabilities. */
566 ic->ic_caps =
567 IEEE80211_C_STA /* station mode supported */

--- 8 unchanged lines hidden (view full) ---

576#if 0
577 | IEEE80211_C_IBSS /* ibss/adhoc mode */
578#endif
579 | IEEE80211_C_WME /* WME */
580 | IEEE80211_C_PMGT /* Station-side power mgmt */
581 ;
582
583 /* Read MAC address, channels, etc from EEPROM. */
553 ic->ic_softc = sc;
554 ic->ic_name = device_get_nameunit(dev);
555 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
556 ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */
557
558 /* Set device capabilities. */
559 ic->ic_caps =
560 IEEE80211_C_STA /* station mode supported */

--- 8 unchanged lines hidden (view full) ---

569#if 0
570 | IEEE80211_C_IBSS /* ibss/adhoc mode */
571#endif
572 | IEEE80211_C_WME /* WME */
573 | IEEE80211_C_PMGT /* Station-side power mgmt */
574 ;
575
576 /* Read MAC address, channels, etc from EEPROM. */
584 if ((error = iwn_read_eeprom(sc, macaddr)) != 0) {
577 if ((error = iwn_read_eeprom(sc, ic->ic_macaddr)) != 0) {
585 device_printf(dev, "could not read EEPROM, error %d\n",
586 error);
587 goto fail;
588 }
589
590 /* Count the number of available chains. */
591 sc->ntxchains =
592 ((sc->txchainmask >> 2) & 1) +
593 ((sc->txchainmask >> 1) & 1) +
594 ((sc->txchainmask >> 0) & 1);
595 sc->nrxchains =
596 ((sc->rxchainmask >> 2) & 1) +
597 ((sc->rxchainmask >> 1) & 1) +
598 ((sc->rxchainmask >> 0) & 1);
599 if (bootverbose) {
600 device_printf(dev, "MIMO %dT%dR, %.4s, address %6D\n",
601 sc->ntxchains, sc->nrxchains, sc->eeprom_domain,
578 device_printf(dev, "could not read EEPROM, error %d\n",
579 error);
580 goto fail;
581 }
582
583 /* Count the number of available chains. */
584 sc->ntxchains =
585 ((sc->txchainmask >> 2) & 1) +
586 ((sc->txchainmask >> 1) & 1) +
587 ((sc->txchainmask >> 0) & 1);
588 sc->nrxchains =
589 ((sc->rxchainmask >> 2) & 1) +
590 ((sc->rxchainmask >> 1) & 1) +
591 ((sc->rxchainmask >> 0) & 1);
592 if (bootverbose) {
593 device_printf(dev, "MIMO %dT%dR, %.4s, address %6D\n",
594 sc->ntxchains, sc->nrxchains, sc->eeprom_domain,
602 macaddr, ":");
595 ic->ic_macaddr, ":");
603 }
604
605 if (sc->sc_flags & IWN_FLAG_HAS_11N) {
606 ic->ic_rxstream = sc->nrxchains;
607 ic->ic_txstream = sc->ntxchains;
608
609 /*
610 * Some of the 3 antenna devices (ie, the 4965) only supports

--- 24 unchanged lines hidden (view full) ---

635 | IEEE80211_HTC_HT /* HT operation */
636 | IEEE80211_HTC_AMPDU /* tx A-MPDU */
637#ifdef notyet
638 | IEEE80211_HTC_AMSDU /* tx A-MSDU */
639#endif
640 ;
641 }
642
596 }
597
598 if (sc->sc_flags & IWN_FLAG_HAS_11N) {
599 ic->ic_rxstream = sc->nrxchains;
600 ic->ic_txstream = sc->ntxchains;
601
602 /*
603 * Some of the 3 antenna devices (ie, the 4965) only supports

--- 24 unchanged lines hidden (view full) ---

628 | IEEE80211_HTC_HT /* HT operation */
629 | IEEE80211_HTC_AMPDU /* tx A-MPDU */
630#ifdef notyet
631 | IEEE80211_HTC_AMSDU /* tx A-MSDU */
632#endif
633 ;
634 }
635
643 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
644 ifp->if_softc = sc;
645 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
646 ifp->if_init = iwn_init;
647 ifp->if_ioctl = iwn_ioctl;
648 ifp->if_start = iwn_start;
649 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
650 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
651 IFQ_SET_READY(&ifp->if_snd);
652
653 ieee80211_ifattach(ic, macaddr);
636 ieee80211_ifattach(ic);
654 ic->ic_vap_create = iwn_vap_create;
637 ic->ic_vap_create = iwn_vap_create;
638 ic->ic_ioctl = iwn_ioctl;
639 ic->ic_parent = iwn_parent;
655 ic->ic_vap_delete = iwn_vap_delete;
640 ic->ic_vap_delete = iwn_vap_delete;
641 ic->ic_transmit = iwn_transmit;
656 ic->ic_raw_xmit = iwn_raw_xmit;
657 ic->ic_node_alloc = iwn_node_alloc;
658 sc->sc_ampdu_rx_start = ic->ic_ampdu_rx_start;
659 ic->ic_ampdu_rx_start = iwn_ampdu_rx_start;
660 sc->sc_ampdu_rx_stop = ic->ic_ampdu_rx_stop;
661 ic->ic_ampdu_rx_stop = iwn_ampdu_rx_stop;
662 sc->sc_addba_request = ic->ic_addba_request;
663 ic->ic_addba_request = iwn_addba_request;

--- 624 unchanged lines hidden (view full) ---

1288}
1289
1290/*
1291 * Attach the interface to 802.11 radiotap.
1292 */
1293static void
1294iwn_radiotap_attach(struct iwn_softc *sc)
1295{
642 ic->ic_raw_xmit = iwn_raw_xmit;
643 ic->ic_node_alloc = iwn_node_alloc;
644 sc->sc_ampdu_rx_start = ic->ic_ampdu_rx_start;
645 ic->ic_ampdu_rx_start = iwn_ampdu_rx_start;
646 sc->sc_ampdu_rx_stop = ic->ic_ampdu_rx_stop;
647 ic->ic_ampdu_rx_stop = iwn_ampdu_rx_stop;
648 sc->sc_addba_request = ic->ic_addba_request;
649 ic->ic_addba_request = iwn_addba_request;

--- 624 unchanged lines hidden (view full) ---

1274}
1275
1276/*
1277 * Attach the interface to 802.11 radiotap.
1278 */
1279static void
1280iwn_radiotap_attach(struct iwn_softc *sc)
1281{
1296 struct ifnet *ifp = sc->sc_ifp;
1297 struct ieee80211com *ic = ifp->if_l2com;
1282
1298 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
1283 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
1299 ieee80211_radiotap_attach(ic,
1284 ieee80211_radiotap_attach(&sc->sc_ic,
1300 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap),
1301 IWN_TX_RADIOTAP_PRESENT,
1302 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap),
1303 IWN_RX_RADIOTAP_PRESENT);
1304 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);
1305}
1306
1307static void

--- 13 unchanged lines hidden (view full) ---

1321iwn_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
1322 enum ieee80211_opmode opmode, int flags,
1323 const uint8_t bssid[IEEE80211_ADDR_LEN],
1324 const uint8_t mac[IEEE80211_ADDR_LEN])
1325{
1326 struct iwn_softc *sc = ic->ic_softc;
1327 struct iwn_vap *ivp;
1328 struct ieee80211vap *vap;
1285 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap),
1286 IWN_TX_RADIOTAP_PRESENT,
1287 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap),
1288 IWN_RX_RADIOTAP_PRESENT);
1289 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);
1290}
1291
1292static void

--- 13 unchanged lines hidden (view full) ---

1306iwn_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
1307 enum ieee80211_opmode opmode, int flags,
1308 const uint8_t bssid[IEEE80211_ADDR_LEN],
1309 const uint8_t mac[IEEE80211_ADDR_LEN])
1310{
1311 struct iwn_softc *sc = ic->ic_softc;
1312 struct iwn_vap *ivp;
1313 struct ieee80211vap *vap;
1329 uint8_t mac1[IEEE80211_ADDR_LEN];
1330
1331 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */
1332 return NULL;
1333
1314
1315 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */
1316 return NULL;
1317
1334 IEEE80211_ADDR_COPY(mac1, mac);
1335
1336 ivp = (struct iwn_vap *) malloc(sizeof(struct iwn_vap),
1337 M_80211_VAP, M_NOWAIT | M_ZERO);
1338 if (ivp == NULL)
1339 return NULL;
1318 ivp = malloc(sizeof(struct iwn_vap), M_80211_VAP, M_WAITOK | M_ZERO);
1340 vap = &ivp->iv_vap;
1319 vap = &ivp->iv_vap;
1341 ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac1);
1320 ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid);
1342 ivp->ctx = IWN_RXON_BSS_CTX;
1321 ivp->ctx = IWN_RXON_BSS_CTX;
1343 IEEE80211_ADDR_COPY(ivp->macaddr, mac1);
1344 vap->iv_bmissthreshold = 10; /* override default */
1345 /* Override with driver methods. */
1346 ivp->iv_newstate = vap->iv_newstate;
1347 vap->iv_newstate = iwn_newstate;
1348 sc->ivap[IWN_RXON_BSS_CTX] = vap;
1349
1350 ieee80211_ratectl_init(vap);
1351 /* Complete setup. */
1322 vap->iv_bmissthreshold = 10; /* override default */
1323 /* Override with driver methods. */
1324 ivp->iv_newstate = vap->iv_newstate;
1325 vap->iv_newstate = iwn_newstate;
1326 sc->ivap[IWN_RXON_BSS_CTX] = vap;
1327
1328 ieee80211_ratectl_init(vap);
1329 /* Complete setup. */
1352 ieee80211_vap_attach(vap, iwn_media_change, ieee80211_media_status);
1330 ieee80211_vap_attach(vap, iwn_media_change, ieee80211_media_status,
1331 mac);
1353 ic->ic_opmode = opmode;
1354 return vap;
1355}
1356
1357static void
1358iwn_vap_delete(struct ieee80211vap *vap)
1359{
1360 struct iwn_vap *ivp = IWN_VAP(vap);

--- 24 unchanged lines hidden (view full) ---

1385 IWN_LOCK_ASSERT(sc);
1386 return (mbufq_enqueue(&sc->sc_xmit_queue, m));
1387}
1388
1389static int
1390iwn_detach(device_t dev)
1391{
1392 struct iwn_softc *sc = device_get_softc(dev);
1332 ic->ic_opmode = opmode;
1333 return vap;
1334}
1335
1336static void
1337iwn_vap_delete(struct ieee80211vap *vap)
1338{
1339 struct iwn_vap *ivp = IWN_VAP(vap);

--- 24 unchanged lines hidden (view full) ---

1364 IWN_LOCK_ASSERT(sc);
1365 return (mbufq_enqueue(&sc->sc_xmit_queue, m));
1366}
1367
1368static int
1369iwn_detach(device_t dev)
1370{
1371 struct iwn_softc *sc = device_get_softc(dev);
1393 struct ifnet *ifp = sc->sc_ifp;
1394 struct ieee80211com *ic;
1395 int qid;
1396
1397 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
1398
1372 int qid;
1373
1374 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
1375
1399 if (ifp != NULL) {
1400 ic = ifp->if_l2com;
1401
1376 if (sc->sc_ic.ic_softc != NULL) {
1402 /* Free the mbuf queue and node references */
1403 IWN_LOCK(sc);
1404 iwn_xmit_queue_drain(sc);
1405 IWN_UNLOCK(sc);
1406
1377 /* Free the mbuf queue and node references */
1378 IWN_LOCK(sc);
1379 iwn_xmit_queue_drain(sc);
1380 IWN_UNLOCK(sc);
1381
1407 ieee80211_draintask(ic, &sc->sc_reinit_task);
1408 ieee80211_draintask(ic, &sc->sc_radioon_task);
1409 ieee80211_draintask(ic, &sc->sc_radiooff_task);
1410
1382 ieee80211_draintask(&sc->sc_ic, &sc->sc_reinit_task);
1383 ieee80211_draintask(&sc->sc_ic, &sc->sc_radioon_task);
1384 ieee80211_draintask(&sc->sc_ic, &sc->sc_radiooff_task);
1411 iwn_stop(sc);
1412
1413 taskqueue_drain_all(sc->sc_tq);
1414 taskqueue_free(sc->sc_tq);
1415
1416 callout_drain(&sc->watchdog_to);
1417 callout_drain(&sc->calib_to);
1385 iwn_stop(sc);
1386
1387 taskqueue_drain_all(sc->sc_tq);
1388 taskqueue_free(sc->sc_tq);
1389
1390 callout_drain(&sc->watchdog_to);
1391 callout_drain(&sc->calib_to);
1418 ieee80211_ifdetach(ic);
1392 ieee80211_ifdetach(&sc->sc_ic);
1419 }
1420
1393 }
1394
1395 mbufq_drain(&sc->sc_snd);
1396
1421 /* Uninstall interrupt handler. */
1422 if (sc->irq != NULL) {
1423 bus_teardown_intr(dev, sc->irq, sc->sc_ih);
1424 bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(sc->irq),
1425 sc->irq);
1426 pci_release_msi(dev);
1427 }
1428

--- 6 unchanged lines hidden (view full) ---

1435 if (sc->ict != NULL)
1436 iwn_free_ict(sc);
1437 iwn_free_fwmem(sc);
1438
1439 if (sc->mem != NULL)
1440 bus_release_resource(dev, SYS_RES_MEMORY,
1441 rman_get_rid(sc->mem), sc->mem);
1442
1397 /* Uninstall interrupt handler. */
1398 if (sc->irq != NULL) {
1399 bus_teardown_intr(dev, sc->irq, sc->sc_ih);
1400 bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(sc->irq),
1401 sc->irq);
1402 pci_release_msi(dev);
1403 }
1404

--- 6 unchanged lines hidden (view full) ---

1411 if (sc->ict != NULL)
1412 iwn_free_ict(sc);
1413 iwn_free_fwmem(sc);
1414
1415 if (sc->mem != NULL)
1416 bus_release_resource(dev, SYS_RES_MEMORY,
1417 rman_get_rid(sc->mem), sc->mem);
1418
1443 if (ifp != NULL)
1444 if_free(ifp);
1445
1446 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n", __func__);
1447 IWN_LOCK_DESTROY(sc);
1448 return 0;
1449}
1450
1451static int
1452iwn_shutdown(device_t dev)
1453{
1454 struct iwn_softc *sc = device_get_softc(dev);
1455
1456 iwn_stop(sc);
1457 return 0;
1458}
1459
1460static int
1461iwn_suspend(device_t dev)
1462{
1463 struct iwn_softc *sc = device_get_softc(dev);
1419 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n", __func__);
1420 IWN_LOCK_DESTROY(sc);
1421 return 0;
1422}
1423
1424static int
1425iwn_shutdown(device_t dev)
1426{
1427 struct iwn_softc *sc = device_get_softc(dev);
1428
1429 iwn_stop(sc);
1430 return 0;
1431}
1432
1433static int
1434iwn_suspend(device_t dev)
1435{
1436 struct iwn_softc *sc = device_get_softc(dev);
1464 struct ieee80211com *ic = sc->sc_ifp->if_l2com;
1465
1437
1466 ieee80211_suspend_all(ic);
1438 ieee80211_suspend_all(&sc->sc_ic);
1467 return 0;
1468}
1469
1470static int
1471iwn_resume(device_t dev)
1472{
1473 struct iwn_softc *sc = device_get_softc(dev);
1439 return 0;
1440}
1441
1442static int
1443iwn_resume(device_t dev)
1444{
1445 struct iwn_softc *sc = device_get_softc(dev);
1474 struct ieee80211com *ic = sc->sc_ifp->if_l2com;
1475
1476 /* Clear device-specific "PCI retry timeout" register (41h). */
1477 pci_write_config(dev, 0x41, 0, 1);
1478
1446
1447 /* Clear device-specific "PCI retry timeout" register (41h). */
1448 pci_write_config(dev, 0x41, 0, 1);
1449
1479 ieee80211_resume_all(ic);
1450 ieee80211_resume_all(&sc->sc_ic);
1480 return 0;
1481}
1482
1483static int
1484iwn_nic_lock(struct iwn_softc *sc)
1485{
1486 int ntries;
1487

--- 892 unchanged lines hidden (view full) ---

2380 }
2381
2382 return nflags;
2383}
2384
2385static void
2386iwn_read_eeprom_band(struct iwn_softc *sc, int n)
2387{
1451 return 0;
1452}
1453
1454static int
1455iwn_nic_lock(struct iwn_softc *sc)
1456{
1457 int ntries;
1458

--- 892 unchanged lines hidden (view full) ---

2351 }
2352
2353 return nflags;
2354}
2355
2356static void
2357iwn_read_eeprom_band(struct iwn_softc *sc, int n)
2358{
2388 struct ifnet *ifp = sc->sc_ifp;
2389 struct ieee80211com *ic = ifp->if_l2com;
2359 struct ieee80211com *ic = &sc->sc_ic;
2390 struct iwn_eeprom_chan *channels = sc->eeprom_channels[n];
2391 const struct iwn_chan_band *band = &iwn_bands[n];
2392 struct ieee80211_channel *c;
2393 uint8_t chan;
2394 int i, nflags;
2395
2396 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
2397

--- 42 unchanged lines hidden (view full) ---

2440
2441 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);
2442
2443}
2444
2445static void
2446iwn_read_eeprom_ht40(struct iwn_softc *sc, int n)
2447{
2360 struct iwn_eeprom_chan *channels = sc->eeprom_channels[n];
2361 const struct iwn_chan_band *band = &iwn_bands[n];
2362 struct ieee80211_channel *c;
2363 uint8_t chan;
2364 int i, nflags;
2365
2366 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
2367

--- 42 unchanged lines hidden (view full) ---

2410
2411 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);
2412
2413}
2414
2415static void
2416iwn_read_eeprom_ht40(struct iwn_softc *sc, int n)
2417{
2448 struct ifnet *ifp = sc->sc_ifp;
2449 struct ieee80211com *ic = ifp->if_l2com;
2418 struct ieee80211com *ic = &sc->sc_ic;
2450 struct iwn_eeprom_chan *channels = sc->eeprom_channels[n];
2451 const struct iwn_chan_band *band = &iwn_bands[n];
2452 struct ieee80211_channel *c, *cent, *extc;
2453 uint8_t chan;
2454 int i, nflags;
2455
2456 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s start\n", __func__);
2457

--- 51 unchanged lines hidden (view full) ---

2509
2510 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);
2511
2512}
2513
2514static void
2515iwn_read_eeprom_channels(struct iwn_softc *sc, int n, uint32_t addr)
2516{
2419 struct iwn_eeprom_chan *channels = sc->eeprom_channels[n];
2420 const struct iwn_chan_band *band = &iwn_bands[n];
2421 struct ieee80211_channel *c, *cent, *extc;
2422 uint8_t chan;
2423 int i, nflags;
2424
2425 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s start\n", __func__);
2426

--- 51 unchanged lines hidden (view full) ---

2478
2479 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);
2480
2481}
2482
2483static void
2484iwn_read_eeprom_channels(struct iwn_softc *sc, int n, uint32_t addr)
2485{
2517 struct ifnet *ifp = sc->sc_ifp;
2518 struct ieee80211com *ic = ifp->if_l2com;
2486 struct ieee80211com *ic = &sc->sc_ic;
2519
2520 iwn_read_prom_data(sc, addr, &sc->eeprom_channels[n],
2521 iwn_bands[n].nchan * sizeof (struct iwn_eeprom_chan));
2522
2523 if (n < 5)
2524 iwn_read_eeprom_band(sc, n);
2525 else
2526 iwn_read_eeprom_ht40(sc, n);

--- 51 unchanged lines hidden (view full) ---

2578
2579 return 0;
2580}
2581
2582static void
2583iwn_read_eeprom_enhinfo(struct iwn_softc *sc)
2584{
2585 struct iwn_eeprom_enhinfo enhinfo[35];
2487
2488 iwn_read_prom_data(sc, addr, &sc->eeprom_channels[n],
2489 iwn_bands[n].nchan * sizeof (struct iwn_eeprom_chan));
2490
2491 if (n < 5)
2492 iwn_read_eeprom_band(sc, n);
2493 else
2494 iwn_read_eeprom_ht40(sc, n);

--- 51 unchanged lines hidden (view full) ---

2546
2547 return 0;
2548}
2549
2550static void
2551iwn_read_eeprom_enhinfo(struct iwn_softc *sc)
2552{
2553 struct iwn_eeprom_enhinfo enhinfo[35];
2586 struct ifnet *ifp = sc->sc_ifp;
2587 struct ieee80211com *ic = ifp->if_l2com;
2554 struct ieee80211com *ic = &sc->sc_ic;
2588 struct ieee80211_channel *c;
2589 uint16_t val, base;
2590 int8_t maxpwr;
2591 uint8_t flags;
2592 int i, j;
2593
2594 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
2595

--- 366 unchanged lines hidden (view full) ---

2962 * Process an RX_DONE (4965AGN only) or MPDU_RX_DONE firmware notification.
2963 * Each MPDU_RX_DONE notification must be preceded by an RX_PHY one.
2964 */
2965static void
2966iwn_rx_done(struct iwn_softc *sc, struct iwn_rx_desc *desc,
2967 struct iwn_rx_data *data)
2968{
2969 struct iwn_ops *ops = &sc->ops;
2555 struct ieee80211_channel *c;
2556 uint16_t val, base;
2557 int8_t maxpwr;
2558 uint8_t flags;
2559 int i, j;
2560
2561 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
2562

--- 366 unchanged lines hidden (view full) ---

2929 * Process an RX_DONE (4965AGN only) or MPDU_RX_DONE firmware notification.
2930 * Each MPDU_RX_DONE notification must be preceded by an RX_PHY one.
2931 */
2932static void
2933iwn_rx_done(struct iwn_softc *sc, struct iwn_rx_desc *desc,
2934 struct iwn_rx_data *data)
2935{
2936 struct iwn_ops *ops = &sc->ops;
2970 struct ifnet *ifp = sc->sc_ifp;
2971 struct ieee80211com *ic = ifp->if_l2com;
2937 struct ieee80211com *ic = &sc->sc_ic;
2972 struct iwn_rx_ring *ring = &sc->rxq;
2973 struct ieee80211_frame *wh;
2974 struct ieee80211_node *ni;
2975 struct mbuf *m, *m1;
2976 struct iwn_rx_stat *stat;
2977 caddr_t head;
2978 bus_addr_t paddr;
2979 uint32_t flags;

--- 30 unchanged lines hidden (view full) ---

3010 }
3011
3012 flags = le32toh(*(uint32_t *)(head + len));
3013
3014 /* Discard frames with a bad FCS early. */
3015 if ((flags & IWN_RX_NOERROR) != IWN_RX_NOERROR) {
3016 DPRINTF(sc, IWN_DEBUG_RECV, "%s: RX flags error %x\n",
3017 __func__, flags);
2938 struct iwn_rx_ring *ring = &sc->rxq;
2939 struct ieee80211_frame *wh;
2940 struct ieee80211_node *ni;
2941 struct mbuf *m, *m1;
2942 struct iwn_rx_stat *stat;
2943 caddr_t head;
2944 bus_addr_t paddr;
2945 uint32_t flags;

--- 30 unchanged lines hidden (view full) ---

2976 }
2977
2978 flags = le32toh(*(uint32_t *)(head + len));
2979
2980 /* Discard frames with a bad FCS early. */
2981 if ((flags & IWN_RX_NOERROR) != IWN_RX_NOERROR) {
2982 DPRINTF(sc, IWN_DEBUG_RECV, "%s: RX flags error %x\n",
2983 __func__, flags);
3018 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
2984 counter_u64_add(ic->ic_ierrors, 1);
3019 return;
3020 }
3021 /* Discard frames that are too short. */
3022 if (len < sizeof (struct ieee80211_frame_ack)) {
3023 DPRINTF(sc, IWN_DEBUG_RECV, "%s: frame too short: %d\n",
3024 __func__, len);
2985 return;
2986 }
2987 /* Discard frames that are too short. */
2988 if (len < sizeof (struct ieee80211_frame_ack)) {
2989 DPRINTF(sc, IWN_DEBUG_RECV, "%s: frame too short: %d\n",
2990 __func__, len);
3025 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
2991 counter_u64_add(ic->ic_ierrors, 1);
3026 return;
3027 }
3028
3029 m1 = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, IWN_RBUF_SIZE);
3030 if (m1 == NULL) {
3031 DPRINTF(sc, IWN_DEBUG_ANY, "%s: no mbuf to restock ring\n",
3032 __func__);
2992 return;
2993 }
2994
2995 m1 = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, IWN_RBUF_SIZE);
2996 if (m1 == NULL) {
2997 DPRINTF(sc, IWN_DEBUG_ANY, "%s: no mbuf to restock ring\n",
2998 __func__);
3033 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
2999 counter_u64_add(ic->ic_ierrors, 1);
3034 return;
3035 }
3036 bus_dmamap_unload(ring->data_dmat, data->map);
3037
3038 error = bus_dmamap_load(ring->data_dmat, data->map, mtod(m1, void *),
3039 IWN_RBUF_SIZE, iwn_dma_map_addr, &paddr, BUS_DMA_NOWAIT);
3040 if (error != 0 && error != EFBIG) {
3041 device_printf(sc->sc_dev,

--- 6 unchanged lines hidden (view full) ---

3048 &paddr, BUS_DMA_NOWAIT);
3049 if (error != 0 && error != EFBIG) {
3050 panic("%s: could not load old RX mbuf", __func__);
3051 }
3052 /* Physical address may have changed. */
3053 ring->desc[ring->cur] = htole32(paddr >> 8);
3054 bus_dmamap_sync(ring->data_dmat, ring->desc_dma.map,
3055 BUS_DMASYNC_PREWRITE);
3000 return;
3001 }
3002 bus_dmamap_unload(ring->data_dmat, data->map);
3003
3004 error = bus_dmamap_load(ring->data_dmat, data->map, mtod(m1, void *),
3005 IWN_RBUF_SIZE, iwn_dma_map_addr, &paddr, BUS_DMA_NOWAIT);
3006 if (error != 0 && error != EFBIG) {
3007 device_printf(sc->sc_dev,

--- 6 unchanged lines hidden (view full) ---

3014 &paddr, BUS_DMA_NOWAIT);
3015 if (error != 0 && error != EFBIG) {
3016 panic("%s: could not load old RX mbuf", __func__);
3017 }
3018 /* Physical address may have changed. */
3019 ring->desc[ring->cur] = htole32(paddr >> 8);
3020 bus_dmamap_sync(ring->data_dmat, ring->desc_dma.map,
3021 BUS_DMASYNC_PREWRITE);
3056 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
3022 counter_u64_add(ic->ic_ierrors, 1);
3057 return;
3058 }
3059
3060 m = data->m;
3061 data->m = m1;
3062 /* Update RX descriptor. */
3063 ring->desc[ring->cur] = htole32(paddr >> 8);
3064 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map,
3065 BUS_DMASYNC_PREWRITE);
3066
3067 /* Finalize mbuf. */
3023 return;
3024 }
3025
3026 m = data->m;
3027 data->m = m1;
3028 /* Update RX descriptor. */
3029 ring->desc[ring->cur] = htole32(paddr >> 8);
3030 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map,
3031 BUS_DMASYNC_PREWRITE);
3032
3033 /* Finalize mbuf. */
3068 m->m_pkthdr.rcvif = ifp;
3069 m->m_data = head;
3070 m->m_pkthdr.len = m->m_len = len;
3071
3072 /* Grab a reference to the source node. */
3073 wh = mtod(m, struct ieee80211_frame *);
3074 if (len >= sizeof(struct ieee80211_frame_min))
3075 ni = ieee80211_find_rxnode(ic, (struct ieee80211_frame_min *)wh);
3076 else

--- 77 unchanged lines hidden (view full) ---

3154}
3155
3156/* Process an incoming Compressed BlockAck. */
3157static void
3158iwn_rx_compressed_ba(struct iwn_softc *sc, struct iwn_rx_desc *desc,
3159 struct iwn_rx_data *data)
3160{
3161 struct iwn_ops *ops = &sc->ops;
3034 m->m_data = head;
3035 m->m_pkthdr.len = m->m_len = len;
3036
3037 /* Grab a reference to the source node. */
3038 wh = mtod(m, struct ieee80211_frame *);
3039 if (len >= sizeof(struct ieee80211_frame_min))
3040 ni = ieee80211_find_rxnode(ic, (struct ieee80211_frame_min *)wh);
3041 else

--- 77 unchanged lines hidden (view full) ---

3119}
3120
3121/* Process an incoming Compressed BlockAck. */
3122static void
3123iwn_rx_compressed_ba(struct iwn_softc *sc, struct iwn_rx_desc *desc,
3124 struct iwn_rx_data *data)
3125{
3126 struct iwn_ops *ops = &sc->ops;
3162 struct ifnet *ifp = sc->sc_ifp;
3163 struct iwn_node *wn;
3164 struct ieee80211_node *ni;
3165 struct iwn_compressed_ba *ba = (struct iwn_compressed_ba *)(desc + 1);
3166 struct iwn_tx_ring *txq;
3167 struct iwn_tx_data *txdata;
3168 struct ieee80211_tx_ampdu *tap;
3169 struct mbuf *m;
3170 uint64_t bitmap;

--- 64 unchanged lines hidden (view full) ---

3235 *
3236 * Yes, the rate control code doesn't know these are A-MPDU
3237 * subframes and that it's okay to fail some of these.
3238 */
3239 ni = tap->txa_ni;
3240 bitmap = (le64toh(ba->bitmap) >> shift) & wn->agg[tid].bitmap;
3241 for (i = 0; bitmap; i++) {
3242 if ((bitmap & 1) == 0) {
3127 struct iwn_node *wn;
3128 struct ieee80211_node *ni;
3129 struct iwn_compressed_ba *ba = (struct iwn_compressed_ba *)(desc + 1);
3130 struct iwn_tx_ring *txq;
3131 struct iwn_tx_data *txdata;
3132 struct ieee80211_tx_ampdu *tap;
3133 struct mbuf *m;
3134 uint64_t bitmap;

--- 64 unchanged lines hidden (view full) ---

3199 *
3200 * Yes, the rate control code doesn't know these are A-MPDU
3201 * subframes and that it's okay to fail some of these.
3202 */
3203 ni = tap->txa_ni;
3204 bitmap = (le64toh(ba->bitmap) >> shift) & wn->agg[tid].bitmap;
3205 for (i = 0; bitmap; i++) {
3206 if ((bitmap & 1) == 0) {
3243 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
3244 tx_err ++;
3245 ieee80211_ratectl_tx_complete(ni->ni_vap, ni,
3246 IEEE80211_RATECTL_TX_FAILURE, &ackfailcnt, NULL);
3247 } else {
3207 tx_err ++;
3208 ieee80211_ratectl_tx_complete(ni->ni_vap, ni,
3209 IEEE80211_RATECTL_TX_FAILURE, &ackfailcnt, NULL);
3210 } else {
3248 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
3249 tx_ok ++;
3250 ieee80211_ratectl_tx_complete(ni->ni_vap, ni,
3251 IEEE80211_RATECTL_TX_SUCCESS, &ackfailcnt, NULL);
3252 }
3253 bitmap >>= 1;
3254 }
3255
3256 DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT,

--- 129 unchanged lines hidden (view full) ---

3386 * Process an RX_STATISTICS or BEACON_STATISTICS firmware notification.
3387 * The latter is sent by the firmware after each received beacon.
3388 */
3389static void
3390iwn_rx_statistics(struct iwn_softc *sc, struct iwn_rx_desc *desc,
3391 struct iwn_rx_data *data)
3392{
3393 struct iwn_ops *ops = &sc->ops;
3211 tx_ok ++;
3212 ieee80211_ratectl_tx_complete(ni->ni_vap, ni,
3213 IEEE80211_RATECTL_TX_SUCCESS, &ackfailcnt, NULL);
3214 }
3215 bitmap >>= 1;
3216 }
3217
3218 DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT,

--- 129 unchanged lines hidden (view full) ---

3348 * Process an RX_STATISTICS or BEACON_STATISTICS firmware notification.
3349 * The latter is sent by the firmware after each received beacon.
3350 */
3351static void
3352iwn_rx_statistics(struct iwn_softc *sc, struct iwn_rx_desc *desc,
3353 struct iwn_rx_data *data)
3354{
3355 struct iwn_ops *ops = &sc->ops;
3394 struct ifnet *ifp = sc->sc_ifp;
3395 struct ieee80211com *ic = ifp->if_l2com;
3356 struct ieee80211com *ic = &sc->sc_ic;
3396 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3397 struct iwn_calib_state *calib = &sc->calib;
3398 struct iwn_stats *stats = (struct iwn_stats *)(desc + 1);
3399 struct iwn_stats *lstats;
3400 int temp;
3401
3402 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
3403

--- 156 unchanged lines hidden (view full) ---

3560
3561/*
3562 * Adapter-independent backend for TX_DONE firmware notifications.
3563 */
3564static void
3565iwn_tx_done(struct iwn_softc *sc, struct iwn_rx_desc *desc, int ackfailcnt,
3566 uint8_t status)
3567{
3357 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3358 struct iwn_calib_state *calib = &sc->calib;
3359 struct iwn_stats *stats = (struct iwn_stats *)(desc + 1);
3360 struct iwn_stats *lstats;
3361 int temp;
3362
3363 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
3364

--- 156 unchanged lines hidden (view full) ---

3521
3522/*
3523 * Adapter-independent backend for TX_DONE firmware notifications.
3524 */
3525static void
3526iwn_tx_done(struct iwn_softc *sc, struct iwn_rx_desc *desc, int ackfailcnt,
3527 uint8_t status)
3528{
3568 struct ifnet *ifp = sc->sc_ifp;
3569 struct iwn_tx_ring *ring = &sc->txq[desc->qid & 0xf];
3570 struct iwn_tx_data *data = &ring->data[desc->idx];
3571 struct mbuf *m;
3572 struct ieee80211_node *ni;
3573 struct ieee80211vap *vap;
3574
3575 KASSERT(data->ni != NULL, ("no node"));
3576

--- 4 unchanged lines hidden (view full) ---

3581 bus_dmamap_unload(ring->data_dmat, data->map);
3582 m = data->m, data->m = NULL;
3583 ni = data->ni, data->ni = NULL;
3584 vap = ni->ni_vap;
3585
3586 /*
3587 * Update rate control statistics for the node.
3588 */
3529 struct iwn_tx_ring *ring = &sc->txq[desc->qid & 0xf];
3530 struct iwn_tx_data *data = &ring->data[desc->idx];
3531 struct mbuf *m;
3532 struct ieee80211_node *ni;
3533 struct ieee80211vap *vap;
3534
3535 KASSERT(data->ni != NULL, ("no node"));
3536

--- 4 unchanged lines hidden (view full) ---

3541 bus_dmamap_unload(ring->data_dmat, data->map);
3542 m = data->m, data->m = NULL;
3543 ni = data->ni, data->ni = NULL;
3544 vap = ni->ni_vap;
3545
3546 /*
3547 * Update rate control statistics for the node.
3548 */
3589 if (status & IWN_TX_FAIL) {
3590 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
3549 if (status & IWN_TX_FAIL)
3591 ieee80211_ratectl_tx_complete(vap, ni,
3592 IEEE80211_RATECTL_TX_FAILURE, &ackfailcnt, NULL);
3550 ieee80211_ratectl_tx_complete(vap, ni,
3551 IEEE80211_RATECTL_TX_FAILURE, &ackfailcnt, NULL);
3593 } else {
3594 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
3552 else
3595 ieee80211_ratectl_tx_complete(vap, ni,
3596 IEEE80211_RATECTL_TX_SUCCESS, &ackfailcnt, NULL);
3553 ieee80211_ratectl_tx_complete(vap, ni,
3554 IEEE80211_RATECTL_TX_SUCCESS, &ackfailcnt, NULL);
3597 }
3598
3599 /*
3600 * Channels marked for "radar" require traffic to be received
3601 * to unlock before we can transmit. Until traffic is seen
3602 * any attempt to transmit is returned immediately with status
3603 * set to IWN_TX_FAIL_TX_LOCKED. Unfortunately this can easily
3604 * happen on first authenticate after scanning. To workaround
3605 * this we ignore a failure of this sort in AUTH state so the

--- 9 unchanged lines hidden (view full) ---

3615 ieee80211_tx_complete(ni, m, 0);
3616 else
3617 ieee80211_tx_complete(ni, m,
3618 (status & IWN_TX_FAIL) != 0);
3619
3620 sc->sc_tx_timer = 0;
3621 if (--ring->queued < IWN_TX_RING_LOMARK) {
3622 sc->qfullmsk &= ~(1 << ring->qid);
3555
3556 /*
3557 * Channels marked for "radar" require traffic to be received
3558 * to unlock before we can transmit. Until traffic is seen
3559 * any attempt to transmit is returned immediately with status
3560 * set to IWN_TX_FAIL_TX_LOCKED. Unfortunately this can easily
3561 * happen on first authenticate after scanning. To workaround
3562 * this we ignore a failure of this sort in AUTH state so the

--- 9 unchanged lines hidden (view full) ---

3572 ieee80211_tx_complete(ni, m, 0);
3573 else
3574 ieee80211_tx_complete(ni, m,
3575 (status & IWN_TX_FAIL) != 0);
3576
3577 sc->sc_tx_timer = 0;
3578 if (--ring->queued < IWN_TX_RING_LOMARK) {
3579 sc->qfullmsk &= ~(1 << ring->qid);
3623 if (sc->qfullmsk == 0 &&
3624 (ifp->if_drv_flags & IFF_DRV_OACTIVE)) {
3625 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
3626 iwn_start_locked(ifp);
3627 }
3580 if (sc->qfullmsk == 0)
3581 iwn_start_locked(sc);
3628 }
3629
3630 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);
3631
3632}
3633
3634/*
3635 * Process a "command done" firmware notification. This is where we wakeup

--- 28 unchanged lines hidden (view full) ---

3664 wakeup(&ring->desc[desc->idx]);
3665}
3666
3667static void
3668iwn_ampdu_tx_done(struct iwn_softc *sc, int qid, int idx, int nframes,
3669 int ackfailcnt, void *stat)
3670{
3671 struct iwn_ops *ops = &sc->ops;
3582 }
3583
3584 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);
3585
3586}
3587
3588/*
3589 * Process a "command done" firmware notification. This is where we wakeup

--- 28 unchanged lines hidden (view full) ---

3618 wakeup(&ring->desc[desc->idx]);
3619}
3620
3621static void
3622iwn_ampdu_tx_done(struct iwn_softc *sc, int qid, int idx, int nframes,
3623 int ackfailcnt, void *stat)
3624{
3625 struct iwn_ops *ops = &sc->ops;
3672 struct ifnet *ifp = sc->sc_ifp;
3673 struct iwn_tx_ring *ring = &sc->txq[qid];
3674 struct iwn_tx_data *data;
3675 struct mbuf *m;
3676 struct iwn_node *wn;
3677 struct ieee80211_node *ni;
3678 struct ieee80211_tx_ampdu *tap;
3679 uint64_t bitmap;
3680 uint32_t *status = stat;

--- 122 unchanged lines hidden (view full) ---

3803 sc->qid2tap[qid] = NULL;
3804 free(res, M_DEVBUF);
3805 return;
3806 }
3807
3808 sc->sc_tx_timer = 0;
3809 if (ring->queued < IWN_TX_RING_LOMARK) {
3810 sc->qfullmsk &= ~(1 << ring->qid);
3626 struct iwn_tx_ring *ring = &sc->txq[qid];
3627 struct iwn_tx_data *data;
3628 struct mbuf *m;
3629 struct iwn_node *wn;
3630 struct ieee80211_node *ni;
3631 struct ieee80211_tx_ampdu *tap;
3632 uint64_t bitmap;
3633 uint32_t *status = stat;

--- 122 unchanged lines hidden (view full) ---

3756 sc->qid2tap[qid] = NULL;
3757 free(res, M_DEVBUF);
3758 return;
3759 }
3760
3761 sc->sc_tx_timer = 0;
3762 if (ring->queued < IWN_TX_RING_LOMARK) {
3763 sc->qfullmsk &= ~(1 << ring->qid);
3811 if (sc->qfullmsk == 0 &&
3812 (ifp->if_drv_flags & IFF_DRV_OACTIVE)) {
3813 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
3814 iwn_start_locked(ifp);
3815 }
3764 if (sc->qfullmsk == 0)
3765 iwn_start_locked(sc);
3816 }
3817
3818 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);
3819
3820}
3821
3822/*
3823 * Process an INT_FH_RX or INT_SW_RX interrupt.
3824 */
3825static void
3826iwn_notif_intr(struct iwn_softc *sc)
3827{
3828 struct iwn_ops *ops = &sc->ops;
3766 }
3767
3768 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);
3769
3770}
3771
3772/*
3773 * Process an INT_FH_RX or INT_SW_RX interrupt.
3774 */
3775static void
3776iwn_notif_intr(struct iwn_softc *sc)
3777{
3778 struct iwn_ops *ops = &sc->ops;
3829 struct ifnet *ifp = sc->sc_ifp;
3830 struct ieee80211com *ic = ifp->if_l2com;
3779 struct ieee80211com *ic = &sc->sc_ic;
3831 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3832 uint16_t hw;
3833
3834 bus_dmamap_sync(sc->rxq.stat_dma.tag, sc->rxq.stat_dma.map,
3835 BUS_DMASYNC_POSTREAD);
3836
3837 hw = le16toh(sc->rxq.stat->closed_count) & 0xfff;
3838 while (sc->rxq.cur != hw) {

--- 177 unchanged lines hidden (view full) ---

4016 struct iwn_tx_ring *ring = &sc->txq[qid];
4017 IWN_WRITE(sc, IWN_HBUS_TARG_WRPTR, qid << 8 | ring->cur);
4018 }
4019}
4020
4021static void
4022iwn_rftoggle_intr(struct iwn_softc *sc)
4023{
3780 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3781 uint16_t hw;
3782
3783 bus_dmamap_sync(sc->rxq.stat_dma.tag, sc->rxq.stat_dma.map,
3784 BUS_DMASYNC_POSTREAD);
3785
3786 hw = le16toh(sc->rxq.stat->closed_count) & 0xfff;
3787 while (sc->rxq.cur != hw) {

--- 177 unchanged lines hidden (view full) ---

3965 struct iwn_tx_ring *ring = &sc->txq[qid];
3966 IWN_WRITE(sc, IWN_HBUS_TARG_WRPTR, qid << 8 | ring->cur);
3967 }
3968}
3969
3970static void
3971iwn_rftoggle_intr(struct iwn_softc *sc)
3972{
4024 struct ifnet *ifp = sc->sc_ifp;
4025 struct ieee80211com *ic = ifp->if_l2com;
3973 struct ieee80211com *ic = &sc->sc_ic;
4026 uint32_t tmp = IWN_READ(sc, IWN_GP_CNTRL);
4027
4028 IWN_LOCK_ASSERT(sc);
4029
4030 device_printf(sc->sc_dev, "RF switch: radio %s\n",
4031 (tmp & IWN_GP_CNTRL_RFKILL) ? "enabled" : "disabled");
4032 if (tmp & IWN_GP_CNTRL_RFKILL)
4033 ieee80211_runtask(ic, &sc->sc_radioon_task);

--- 62 unchanged lines hidden (view full) ---

4096 }
4097 printf(" rx ring: cur=%d\n", sc->rxq.cur);
4098}
4099
4100static void
4101iwn_intr(void *arg)
4102{
4103 struct iwn_softc *sc = arg;
3974 uint32_t tmp = IWN_READ(sc, IWN_GP_CNTRL);
3975
3976 IWN_LOCK_ASSERT(sc);
3977
3978 device_printf(sc->sc_dev, "RF switch: radio %s\n",
3979 (tmp & IWN_GP_CNTRL_RFKILL) ? "enabled" : "disabled");
3980 if (tmp & IWN_GP_CNTRL_RFKILL)
3981 ieee80211_runtask(ic, &sc->sc_radioon_task);

--- 62 unchanged lines hidden (view full) ---

4044 }
4045 printf(" rx ring: cur=%d\n", sc->rxq.cur);
4046}
4047
4048static void
4049iwn_intr(void *arg)
4050{
4051 struct iwn_softc *sc = arg;
4104 struct ifnet *ifp = sc->sc_ifp;
4105 uint32_t r1, r2, tmp;
4106
4107 IWN_LOCK(sc);
4108
4109 /* Disable interrupts. */
4110 IWN_WRITE(sc, IWN_INT_MASK, 0);
4111
4112 /* Read interrupts from ICT (fast) or from registers (slow). */

--- 76 unchanged lines hidden (view full) ---

4189 if (r1 & IWN_INT_ALIVE)
4190 wakeup(sc); /* Firmware is alive. */
4191
4192 if (r1 & IWN_INT_WAKEUP)
4193 iwn_wakeup_intr(sc);
4194
4195done:
4196 /* Re-enable interrupts. */
4052 uint32_t r1, r2, tmp;
4053
4054 IWN_LOCK(sc);
4055
4056 /* Disable interrupts. */
4057 IWN_WRITE(sc, IWN_INT_MASK, 0);
4058
4059 /* Read interrupts from ICT (fast) or from registers (slow). */

--- 76 unchanged lines hidden (view full) ---

4136 if (r1 & IWN_INT_ALIVE)
4137 wakeup(sc); /* Firmware is alive. */
4138
4139 if (r1 & IWN_INT_WAKEUP)
4140 iwn_wakeup_intr(sc);
4141
4142done:
4143 /* Re-enable interrupts. */
4197 if (ifp->if_flags & IFF_UP)
4144 if (sc->sc_flags & IWN_FLAG_RUNNING)
4198 IWN_WRITE(sc, IWN_INT_MASK, sc->int_mask);
4199
4200 IWN_UNLOCK(sc);
4201}
4202
4203/*
4204 * Update TX scheduler ring when transmitting an 802.11 frame (4965AGN and
4205 * 5000 adapters use a slightly different format).

--- 467 unchanged lines hidden (view full) ---

4673 return 0;
4674}
4675
4676static int
4677iwn_tx_data_raw(struct iwn_softc *sc, struct mbuf *m,
4678 struct ieee80211_node *ni, const struct ieee80211_bpf_params *params)
4679{
4680 struct iwn_ops *ops = &sc->ops;
4145 IWN_WRITE(sc, IWN_INT_MASK, sc->int_mask);
4146
4147 IWN_UNLOCK(sc);
4148}
4149
4150/*
4151 * Update TX scheduler ring when transmitting an 802.11 frame (4965AGN and
4152 * 5000 adapters use a slightly different format).

--- 467 unchanged lines hidden (view full) ---

4620 return 0;
4621}
4622
4623static int
4624iwn_tx_data_raw(struct iwn_softc *sc, struct mbuf *m,
4625 struct ieee80211_node *ni, const struct ieee80211_bpf_params *params)
4626{
4627 struct iwn_ops *ops = &sc->ops;
4681// struct ifnet *ifp = sc->sc_ifp;
4682 struct ieee80211vap *vap = ni->ni_vap;
4628 struct ieee80211vap *vap = ni->ni_vap;
4683// struct ieee80211com *ic = ifp->if_l2com;
4684 struct iwn_tx_cmd *cmd;
4685 struct iwn_cmd_data *tx;
4686 struct ieee80211_frame *wh;
4687 struct iwn_tx_ring *ring;
4688 struct iwn_tx_desc *desc;
4689 struct iwn_tx_data *data;
4690 struct mbuf *m1;
4691 bus_dma_segment_t *seg, segs[IWN_MAX_SCATTER];

--- 178 unchanged lines hidden (view full) ---

4870
4871 return 0;
4872}
4873
4874static void
4875iwn_xmit_task(void *arg0, int pending)
4876{
4877 struct iwn_softc *sc = arg0;
4629 struct iwn_tx_cmd *cmd;
4630 struct iwn_cmd_data *tx;
4631 struct ieee80211_frame *wh;
4632 struct iwn_tx_ring *ring;
4633 struct iwn_tx_desc *desc;
4634 struct iwn_tx_data *data;
4635 struct mbuf *m1;
4636 bus_dma_segment_t *seg, segs[IWN_MAX_SCATTER];

--- 178 unchanged lines hidden (view full) ---

4815
4816 return 0;
4817}
4818
4819static void
4820iwn_xmit_task(void *arg0, int pending)
4821{
4822 struct iwn_softc *sc = arg0;
4878 struct ifnet *ifp = sc->sc_ifp;
4879 struct ieee80211_node *ni;
4880 struct mbuf *m;
4881 int error;
4882 struct ieee80211_bpf_params p;
4883 int have_p;
4884
4885 DPRINTF(sc, IWN_DEBUG_XMIT, "%s: called\n", __func__);
4886

--- 15 unchanged lines hidden (view full) ---

4902
4903 /* If we have xmit params, use them */
4904 if (have_p)
4905 error = iwn_tx_data_raw(sc, m, ni, &p);
4906 else
4907 error = iwn_tx_data(sc, m, ni);
4908
4909 if (error != 0) {
4823 struct ieee80211_node *ni;
4824 struct mbuf *m;
4825 int error;
4826 struct ieee80211_bpf_params p;
4827 int have_p;
4828
4829 DPRINTF(sc, IWN_DEBUG_XMIT, "%s: called\n", __func__);
4830

--- 15 unchanged lines hidden (view full) ---

4846
4847 /* If we have xmit params, use them */
4848 if (have_p)
4849 error = iwn_tx_data_raw(sc, m, ni, &p);
4850 else
4851 error = iwn_tx_data(sc, m, ni);
4852
4853 if (error != 0) {
4854 if_inc_counter(ni->ni_vap->iv_ifp,
4855 IFCOUNTER_OERRORS, 1);
4910 ieee80211_free_node(ni);
4856 ieee80211_free_node(ni);
4911 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
4912 }
4913 }
4914
4915 sc->sc_beacon_wait = 0;
4916 IWN_UNLOCK(sc);
4917}
4918
4919static int
4920iwn_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
4921 const struct ieee80211_bpf_params *params)
4922{
4923 struct ieee80211com *ic = ni->ni_ic;
4857 }
4858 }
4859
4860 sc->sc_beacon_wait = 0;
4861 IWN_UNLOCK(sc);
4862}
4863
4864static int
4865iwn_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
4866 const struct ieee80211_bpf_params *params)
4867{
4868 struct ieee80211com *ic = ni->ni_ic;
4924 struct ifnet *ifp = ic->ic_ifp;
4925 struct iwn_softc *sc = ifp->if_softc;
4869 struct iwn_softc *sc = ic->ic_softc;
4926 int error = 0;
4927
4928 DPRINTF(sc, IWN_DEBUG_XMIT | IWN_DEBUG_TRACE, "->%s begin\n", __func__);
4929
4870 int error = 0;
4871
4872 DPRINTF(sc, IWN_DEBUG_XMIT | IWN_DEBUG_TRACE, "->%s begin\n", __func__);
4873
4930 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
4874 if ((sc->sc_flags & IWN_FLAG_RUNNING) == 0) {
4931 ieee80211_free_node(ni);
4932 m_freem(m);
4933 return ENETDOWN;
4934 }
4935
4936 /* XXX? net80211 doesn't set this on xmit'ed raw frames? */
4937 m->m_pkthdr.rcvif = (void *) ni;
4938
4939 IWN_LOCK(sc);
4940
4941 /* queue frame if we have to */
4942 if (sc->sc_beacon_wait) {
4943 if (iwn_xmit_queue_enqueue(sc, m) != 0) {
4944 m_freem(m);
4875 ieee80211_free_node(ni);
4876 m_freem(m);
4877 return ENETDOWN;
4878 }
4879
4880 /* XXX? net80211 doesn't set this on xmit'ed raw frames? */
4881 m->m_pkthdr.rcvif = (void *) ni;
4882
4883 IWN_LOCK(sc);
4884
4885 /* queue frame if we have to */
4886 if (sc->sc_beacon_wait) {
4887 if (iwn_xmit_queue_enqueue(sc, m) != 0) {
4888 m_freem(m);
4889 if_inc_counter(ni->ni_vap->iv_ifp,
4890 IFCOUNTER_OERRORS, 1);
4945 ieee80211_free_node(ni);
4891 ieee80211_free_node(ni);
4946 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
4947 IWN_UNLOCK(sc);
4948 return (ENOBUFS);
4949 }
4950 /* Queued, so just return OK */
4951 IWN_UNLOCK(sc);
4952 return (0);
4953 }
4954

--- 8 unchanged lines hidden (view full) ---

4963 * Caller supplied explicit parameters to use in
4964 * sending the frame.
4965 */
4966 error = iwn_tx_data_raw(sc, m, ni, params);
4967 }
4968 if (error != 0) {
4969 /* NB: m is reclaimed on tx failure */
4970 ieee80211_free_node(ni);
4892 IWN_UNLOCK(sc);
4893 return (ENOBUFS);
4894 }
4895 /* Queued, so just return OK */
4896 IWN_UNLOCK(sc);
4897 return (0);
4898 }
4899

--- 8 unchanged lines hidden (view full) ---

4908 * Caller supplied explicit parameters to use in
4909 * sending the frame.
4910 */
4911 error = iwn_tx_data_raw(sc, m, ni, params);
4912 }
4913 if (error != 0) {
4914 /* NB: m is reclaimed on tx failure */
4915 ieee80211_free_node(ni);
4971 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
4972 } else
4973 sc->sc_tx_timer = 5;
4974
4975 IWN_UNLOCK(sc);
4976
4977 DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT, "->%s: end\n",__func__);
4978
4979 return error;
4980}
4981
4916 } else
4917 sc->sc_tx_timer = 5;
4918
4919 IWN_UNLOCK(sc);
4920
4921 DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT, "->%s: end\n",__func__);
4922
4923 return error;
4924}
4925
4982static void
4983iwn_start(struct ifnet *ifp)
4926static int
4927iwn_transmit(struct ieee80211com *ic, struct mbuf *m)
4984{
4928{
4985 struct iwn_softc *sc = ifp->if_softc;
4929 struct iwn_softc *sc;
4930 int error;
4986
4931
4932 sc = ic->ic_softc;
4933
4987 IWN_LOCK(sc);
4934 IWN_LOCK(sc);
4988 iwn_start_locked(ifp);
4935 if ((sc->sc_flags & IWN_FLAG_RUNNING) == 0) {
4936 IWN_UNLOCK(sc);
4937 return (ENXIO);
4938 }
4939 error = mbufq_enqueue(&sc->sc_snd, m);
4940 if (error) {
4941 IWN_UNLOCK(sc);
4942 return (error);
4943 }
4944 iwn_start_locked(sc);
4989 IWN_UNLOCK(sc);
4945 IWN_UNLOCK(sc);
4946 return (0);
4990}
4991
4992static void
4947}
4948
4949static void
4993iwn_start_locked(struct ifnet *ifp)
4950iwn_start_locked(struct iwn_softc *sc)
4994{
4951{
4995 struct iwn_softc *sc = ifp->if_softc;
4996 struct ieee80211_node *ni;
4997 struct mbuf *m;
4998
4999 IWN_LOCK_ASSERT(sc);
5000
5001 /*
5002 * If we're waiting for a beacon, we can just exit out here
5003 * and wait for the taskqueue to be kicked.
5004 */
5005 if (sc->sc_beacon_wait) {
5006 return;
5007 }
5008
5009 DPRINTF(sc, IWN_DEBUG_XMIT, "%s: called\n", __func__);
4952 struct ieee80211_node *ni;
4953 struct mbuf *m;
4954
4955 IWN_LOCK_ASSERT(sc);
4956
4957 /*
4958 * If we're waiting for a beacon, we can just exit out here
4959 * and wait for the taskqueue to be kicked.
4960 */
4961 if (sc->sc_beacon_wait) {
4962 return;
4963 }
4964
4965 DPRINTF(sc, IWN_DEBUG_XMIT, "%s: called\n", __func__);
5010
5011 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ||
5012 (ifp->if_drv_flags & IFF_DRV_OACTIVE))
5013 return;
5014
5015 for (;;) {
5016 if (sc->qfullmsk != 0) {
5017 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
5018 break;
5019 }
5020 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
5021 if (m == NULL)
5022 break;
4966 while (sc->qfullmsk == 0 &&
4967 (m = mbufq_dequeue(&sc->sc_snd)) != NULL) {
5023 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
5024 if (iwn_tx_data(sc, m, ni) != 0) {
4968 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
4969 if (iwn_tx_data(sc, m, ni) != 0) {
4970 if_inc_counter(ni->ni_vap->iv_ifp,
4971 IFCOUNTER_OERRORS, 1);
5025 ieee80211_free_node(ni);
4972 ieee80211_free_node(ni);
5026 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
5027 } else
5028 sc->sc_tx_timer = 5;
5029 }
4973 } else
4974 sc->sc_tx_timer = 5;
4975 }
5030
5031 DPRINTF(sc, IWN_DEBUG_XMIT, "%s: done\n", __func__);
5032}
5033
5034static void
5035iwn_watchdog(void *arg)
5036{
5037 struct iwn_softc *sc = arg;
4976 DPRINTF(sc, IWN_DEBUG_XMIT, "%s: done\n", __func__);
4977}
4978
4979static void
4980iwn_watchdog(void *arg)
4981{
4982 struct iwn_softc *sc = arg;
5038 struct ifnet *ifp = sc->sc_ifp;
5039 struct ieee80211com *ic = ifp->if_l2com;
4983 struct ieee80211com *ic = &sc->sc_ic;
5040
5041 IWN_LOCK_ASSERT(sc);
5042
4984
4985 IWN_LOCK_ASSERT(sc);
4986
5043 KASSERT(ifp->if_drv_flags & IFF_DRV_RUNNING, ("not running"));
4987 KASSERT(sc->sc_flags & IWN_FLAG_RUNNING, ("not running"));
5044
5045 DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
5046
5047 if (sc->sc_tx_timer > 0) {
5048 if (--sc->sc_tx_timer == 0) {
5049 ic_printf(ic, "device timeout\n");
5050 ieee80211_runtask(ic, &sc->sc_reinit_task);
5051 return;
5052 }
5053 }
5054 callout_reset(&sc->watchdog_to, hz, iwn_watchdog, sc);
5055}
5056
5057static int
4988
4989 DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
4990
4991 if (sc->sc_tx_timer > 0) {
4992 if (--sc->sc_tx_timer == 0) {
4993 ic_printf(ic, "device timeout\n");
4994 ieee80211_runtask(ic, &sc->sc_reinit_task);
4995 return;
4996 }
4997 }
4998 callout_reset(&sc->watchdog_to, hz, iwn_watchdog, sc);
4999}
5000
5001static int
5058iwn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
5002iwn_ioctl(struct ieee80211com *ic, u_long cmd, void *data)
5059{
5003{
5060 struct iwn_softc *sc = ifp->if_softc;
5061 struct ieee80211com *ic = ifp->if_l2com;
5062 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
5063 struct ifreq *ifr = (struct ifreq *) data;
5064 int error = 0, startall = 0, stop = 0;
5065
5004 struct ifreq *ifr = data;
5005 struct iwn_softc *sc = ic->ic_softc;
5006 int error = 0;
5007
5066 switch (cmd) {
5008 switch (cmd) {
5067 case SIOCGIFADDR:
5068 error = ether_ioctl(ifp, cmd, data);
5069 break;
5070 case SIOCSIFFLAGS:
5071 IWN_LOCK(sc);
5072 if (ifp->if_flags & IFF_UP) {
5073 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
5074 iwn_init_locked(sc);
5075 if (IWN_READ(sc, IWN_GP_CNTRL) & IWN_GP_CNTRL_RFKILL)
5076 startall = 1;
5077 else
5078 stop = 1;
5079 }
5080 } else {
5081 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
5082 iwn_stop_locked(sc);
5083 }
5084 IWN_UNLOCK(sc);
5085 if (startall)
5086 ieee80211_start_all(ic);
5087 else if (vap != NULL && stop)
5088 ieee80211_stop(vap);
5089 break;
5090 case SIOCGIFMEDIA:
5091 error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd);
5092 break;
5093 case SIOCGIWNSTATS:
5094 IWN_LOCK(sc);
5095 /* XXX validate permissions/memory/etc? */
5096 error = copyout(&sc->last_stat, ifr->ifr_data,
5097 sizeof(struct iwn_stats));
5098 IWN_UNLOCK(sc);
5099 break;
5100 case SIOCZIWNSTATS:
5101 IWN_LOCK(sc);
5102 memset(&sc->last_stat, 0, sizeof(struct iwn_stats));
5103 IWN_UNLOCK(sc);
5104 break;
5105 default:
5009 case SIOCGIWNSTATS:
5010 IWN_LOCK(sc);
5011 /* XXX validate permissions/memory/etc? */
5012 error = copyout(&sc->last_stat, ifr->ifr_data,
5013 sizeof(struct iwn_stats));
5014 IWN_UNLOCK(sc);
5015 break;
5016 case SIOCZIWNSTATS:
5017 IWN_LOCK(sc);
5018 memset(&sc->last_stat, 0, sizeof(struct iwn_stats));
5019 IWN_UNLOCK(sc);
5020 break;
5021 default:
5106 error = EINVAL;
5022 error = ENOTTY;
5107 break;
5108 }
5023 break;
5024 }
5109 return error;
5025 return (error);
5110}
5111
5026}
5027
5028static void
5029iwn_parent(struct ieee80211com *ic)
5030{
5031 struct iwn_softc *sc = ic->ic_softc;
5032 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
5033 int startall = 0, stop = 0;
5034
5035 IWN_LOCK(sc);
5036 if (ic->ic_nrunning > 0) {
5037 if (!(sc->sc_flags & IWN_FLAG_RUNNING)) {
5038 iwn_init_locked(sc);
5039 if (IWN_READ(sc, IWN_GP_CNTRL) & IWN_GP_CNTRL_RFKILL)
5040 startall = 1;
5041 else
5042 stop = 1;
5043 }
5044 } else if (sc->sc_flags & IWN_FLAG_RUNNING)
5045 iwn_stop_locked(sc);
5046 IWN_UNLOCK(sc);
5047 if (startall)
5048 ieee80211_start_all(ic);
5049 else if (vap != NULL && stop)
5050 ieee80211_stop(vap);
5051}
5052
5112/*
5113 * Send a command to the firmware.
5114 */
5115static int
5116iwn_cmd(struct iwn_softc *sc, int code, const void *buf, int size, int async)
5117{
5118 struct iwn_tx_ring *ring;
5119 struct iwn_tx_desc *desc;

--- 215 unchanged lines hidden (view full) ---

5335
5336/*
5337 * Broadcast node is used to send group-addressed and management frames.
5338 */
5339static int
5340iwn_add_broadcast_node(struct iwn_softc *sc, int async)
5341{
5342 struct iwn_ops *ops = &sc->ops;
5053/*
5054 * Send a command to the firmware.
5055 */
5056static int
5057iwn_cmd(struct iwn_softc *sc, int code, const void *buf, int size, int async)
5058{
5059 struct iwn_tx_ring *ring;
5060 struct iwn_tx_desc *desc;

--- 215 unchanged lines hidden (view full) ---

5276
5277/*
5278 * Broadcast node is used to send group-addressed and management frames.
5279 */
5280static int
5281iwn_add_broadcast_node(struct iwn_softc *sc, int async)
5282{
5283 struct iwn_ops *ops = &sc->ops;
5343 struct ifnet *ifp = sc->sc_ifp;
5344 struct ieee80211com *ic = ifp->if_l2com;
5284 struct ieee80211com *ic = &sc->sc_ic;
5345 struct iwn_node_info node;
5346 struct iwn_cmd_link_quality linkq;
5347 uint8_t txant;
5348 int i, error;
5349
5350 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
5351
5352 sc->rxon = &sc->rx_on[IWN_RXON_BSS_CTX];
5353
5354 memset(&node, 0, sizeof node);
5285 struct iwn_node_info node;
5286 struct iwn_cmd_link_quality linkq;
5287 uint8_t txant;
5288 int i, error;
5289
5290 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
5291
5292 sc->rxon = &sc->rx_on[IWN_RXON_BSS_CTX];
5293
5294 memset(&node, 0, sizeof node);
5355 IEEE80211_ADDR_COPY(node.macaddr, ifp->if_broadcastaddr);
5295 IEEE80211_ADDR_COPY(node.macaddr, ieee80211broadcastaddr);
5356 node.id = sc->broadcast_id;
5357 DPRINTF(sc, IWN_DEBUG_RESET, "%s: adding broadcast node\n", __func__);
5358 if ((error = ops->add_node(sc, &node, async)) != 0)
5359 return error;
5360
5361 /* Use the first valid TX antenna. */
5362 txant = IWN_LSB(sc->txchainmask);
5363

--- 132 unchanged lines hidden (view full) ---

5496 ni->ni_intval, le64toh(cmd.tstamp), (uint32_t)(val - mod));
5497
5498 return iwn_cmd(sc, IWN_CMD_TIMING, &cmd, sizeof cmd, 1);
5499}
5500
5501static void
5502iwn4965_power_calibration(struct iwn_softc *sc, int temp)
5503{
5296 node.id = sc->broadcast_id;
5297 DPRINTF(sc, IWN_DEBUG_RESET, "%s: adding broadcast node\n", __func__);
5298 if ((error = ops->add_node(sc, &node, async)) != 0)
5299 return error;
5300
5301 /* Use the first valid TX antenna. */
5302 txant = IWN_LSB(sc->txchainmask);
5303

--- 132 unchanged lines hidden (view full) ---

5436 ni->ni_intval, le64toh(cmd.tstamp), (uint32_t)(val - mod));
5437
5438 return iwn_cmd(sc, IWN_CMD_TIMING, &cmd, sizeof cmd, 1);
5439}
5440
5441static void
5442iwn4965_power_calibration(struct iwn_softc *sc, int temp)
5443{
5504 struct ifnet *ifp = sc->sc_ifp;
5505 struct ieee80211com *ic = ifp->if_l2com;
5444 struct ieee80211com *ic = &sc->sc_ic;
5506
5507 DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
5508
5509 /* Adjust TX power if need be (delta >= 3 degC). */
5510 DPRINTF(sc, IWN_DEBUG_CALIBRATE, "%s: temperature %d->%d\n",
5511 __func__, sc->temp, temp);
5512 if (abs(temp - sc->temp) >= 3) {
5513 /* Record temperature of last calibration. */

--- 353 unchanged lines hidden (view full) ---

5867 * to set differential gains.
5868 */
5869static void
5870iwn_collect_noise(struct iwn_softc *sc,
5871 const struct iwn_rx_general_stats *stats)
5872{
5873 struct iwn_ops *ops = &sc->ops;
5874 struct iwn_calib_state *calib = &sc->calib;
5445
5446 DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
5447
5448 /* Adjust TX power if need be (delta >= 3 degC). */
5449 DPRINTF(sc, IWN_DEBUG_CALIBRATE, "%s: temperature %d->%d\n",
5450 __func__, sc->temp, temp);
5451 if (abs(temp - sc->temp) >= 3) {
5452 /* Record temperature of last calibration. */

--- 353 unchanged lines hidden (view full) ---

5806 * to set differential gains.
5807 */
5808static void
5809iwn_collect_noise(struct iwn_softc *sc,
5810 const struct iwn_rx_general_stats *stats)
5811{
5812 struct iwn_ops *ops = &sc->ops;
5813 struct iwn_calib_state *calib = &sc->calib;
5875 struct ifnet *ifp = sc->sc_ifp;
5876 struct ieee80211com *ic = ifp->if_l2com;
5814 struct ieee80211com *ic = &sc->sc_ic;
5877 uint32_t val;
5878 int i;
5879
5880 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
5881
5882 /* Accumulate RSSI and noise for all 3 antennas. */
5883 for (i = 0; i < 3; i++) {
5884 calib->rssi[i] += le32toh(stats->rssi[i]) & 0xff;

--- 616 unchanged lines hidden (view full) ---

6501 DPRINTF(sc, IWN_DEBUG_CALIBRATE,
6502 "%s: configuring runtime calibration\n", __func__);
6503 return iwn_cmd(sc, IWN5000_CMD_CALIB_CONFIG, &cmd, sizeof(cmd), 0);
6504}
6505
6506static uint32_t
6507iwn_get_rxon_ht_flags(struct iwn_softc *sc, struct ieee80211_channel *c)
6508{
5815 uint32_t val;
5816 int i;
5817
5818 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
5819
5820 /* Accumulate RSSI and noise for all 3 antennas. */
5821 for (i = 0; i < 3; i++) {
5822 calib->rssi[i] += le32toh(stats->rssi[i]) & 0xff;

--- 616 unchanged lines hidden (view full) ---

6439 DPRINTF(sc, IWN_DEBUG_CALIBRATE,
6440 "%s: configuring runtime calibration\n", __func__);
6441 return iwn_cmd(sc, IWN5000_CMD_CALIB_CONFIG, &cmd, sizeof(cmd), 0);
6442}
6443
6444static uint32_t
6445iwn_get_rxon_ht_flags(struct iwn_softc *sc, struct ieee80211_channel *c)
6446{
6447 struct ieee80211com *ic = &sc->sc_ic;
6509 uint32_t htflags = 0;
6448 uint32_t htflags = 0;
6510 struct ifnet *ifp = sc->sc_ifp;
6511 struct ieee80211com *ic = ifp->if_l2com;
6512
6513 if (! IEEE80211_IS_CHAN_HT(c))
6514 return (0);
6515
6516 htflags |= IWN_RXON_HT_PROTMODE(ic->ic_curhtprotmode);
6517
6518 if (IEEE80211_IS_CHAN_HT40(c)) {
6519 switch (ic->ic_curhtprotmode) {

--- 10 unchanged lines hidden (view full) ---

6530
6531 return (htflags);
6532}
6533
6534static int
6535iwn_config(struct iwn_softc *sc)
6536{
6537 struct iwn_ops *ops = &sc->ops;
6449
6450 if (! IEEE80211_IS_CHAN_HT(c))
6451 return (0);
6452
6453 htflags |= IWN_RXON_HT_PROTMODE(ic->ic_curhtprotmode);
6454
6455 if (IEEE80211_IS_CHAN_HT40(c)) {
6456 switch (ic->ic_curhtprotmode) {

--- 10 unchanged lines hidden (view full) ---

6467
6468 return (htflags);
6469}
6470
6471static int
6472iwn_config(struct iwn_softc *sc)
6473{
6474 struct iwn_ops *ops = &sc->ops;
6538 struct ifnet *ifp = sc->sc_ifp;
6539 struct ieee80211com *ic = ifp->if_l2com;
6475 struct ieee80211com *ic = &sc->sc_ic;
6476 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
6477 const uint8_t *macaddr;
6540 uint32_t txmask;
6541 uint16_t rxchain;
6542 int error;
6543
6544 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
6545
6546 if ((sc->base_params->calib_need & IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET)
6547 && (sc->base_params->calib_need & IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSETv2)) {

--- 65 unchanged lines hidden (view full) ---

6613 "%s: could not configure bluetooth coexistence, error %d\n",
6614 __func__, error);
6615 return error;
6616 }
6617
6618 /* Set mode, channel, RX filter and enable RX. */
6619 sc->rxon = &sc->rx_on[IWN_RXON_BSS_CTX];
6620 memset(sc->rxon, 0, sizeof (struct iwn_rxon));
6478 uint32_t txmask;
6479 uint16_t rxchain;
6480 int error;
6481
6482 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
6483
6484 if ((sc->base_params->calib_need & IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET)
6485 && (sc->base_params->calib_need & IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSETv2)) {

--- 65 unchanged lines hidden (view full) ---

6551 "%s: could not configure bluetooth coexistence, error %d\n",
6552 __func__, error);
6553 return error;
6554 }
6555
6556 /* Set mode, channel, RX filter and enable RX. */
6557 sc->rxon = &sc->rx_on[IWN_RXON_BSS_CTX];
6558 memset(sc->rxon, 0, sizeof (struct iwn_rxon));
6621 IEEE80211_ADDR_COPY(sc->rxon->myaddr, IF_LLADDR(ifp));
6622 IEEE80211_ADDR_COPY(sc->rxon->wlap, IF_LLADDR(ifp));
6559 macaddr = vap ? vap->iv_myaddr : ic->ic_macaddr;
6560 IEEE80211_ADDR_COPY(sc->rxon->myaddr, macaddr);
6561 IEEE80211_ADDR_COPY(sc->rxon->wlap, macaddr);
6623 sc->rxon->chan = ieee80211_chan2ieee(ic, ic->ic_curchan);
6624 sc->rxon->flags = htole32(IWN_RXON_TSF | IWN_RXON_CTS_TO_SELF);
6625 if (IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan))
6626 sc->rxon->flags |= htole32(IWN_RXON_AUTO | IWN_RXON_24GHZ);
6627 switch (ic->ic_opmode) {
6628 case IEEE80211_M_STA:
6629 sc->rxon->mode = IWN_MODE_STA;
6630 sc->rxon->filter = htole32(IWN_FILTER_MULTICAST);

--- 96 unchanged lines hidden (view full) ---

6727/*
6728 * Limit the total dwell time to 85% of the beacon interval.
6729 *
6730 * Returns the dwell time in milliseconds.
6731 */
6732static uint16_t
6733iwn_limit_dwell(struct iwn_softc *sc, uint16_t dwell_time)
6734{
6562 sc->rxon->chan = ieee80211_chan2ieee(ic, ic->ic_curchan);
6563 sc->rxon->flags = htole32(IWN_RXON_TSF | IWN_RXON_CTS_TO_SELF);
6564 if (IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan))
6565 sc->rxon->flags |= htole32(IWN_RXON_AUTO | IWN_RXON_24GHZ);
6566 switch (ic->ic_opmode) {
6567 case IEEE80211_M_STA:
6568 sc->rxon->mode = IWN_MODE_STA;
6569 sc->rxon->filter = htole32(IWN_FILTER_MULTICAST);

--- 96 unchanged lines hidden (view full) ---

6666/*
6667 * Limit the total dwell time to 85% of the beacon interval.
6668 *
6669 * Returns the dwell time in milliseconds.
6670 */
6671static uint16_t
6672iwn_limit_dwell(struct iwn_softc *sc, uint16_t dwell_time)
6673{
6735 struct ieee80211com *ic = sc->sc_ifp->if_l2com;
6674 struct ieee80211com *ic = &sc->sc_ic;
6736 struct ieee80211vap *vap = NULL;
6737 int bintval = 0;
6738
6739 /* bintval is in TU (1.024mS) */
6740 if (! TAILQ_EMPTY(&ic->ic_vaps)) {
6741 vap = TAILQ_FIRST(&ic->ic_vaps);
6742 bintval = vap->iv_bss->ni_intval;
6743 }

--- 31 unchanged lines hidden (view full) ---

6775 /* Clamp to the beacon interval if we're associated */
6776 return (iwn_limit_dwell(sc, passive));
6777}
6778
6779static int
6780iwn_scan(struct iwn_softc *sc, struct ieee80211vap *vap,
6781 struct ieee80211_scan_state *ss, struct ieee80211_channel *c)
6782{
6675 struct ieee80211vap *vap = NULL;
6676 int bintval = 0;
6677
6678 /* bintval is in TU (1.024mS) */
6679 if (! TAILQ_EMPTY(&ic->ic_vaps)) {
6680 vap = TAILQ_FIRST(&ic->ic_vaps);
6681 bintval = vap->iv_bss->ni_intval;
6682 }

--- 31 unchanged lines hidden (view full) ---

6714 /* Clamp to the beacon interval if we're associated */
6715 return (iwn_limit_dwell(sc, passive));
6716}
6717
6718static int
6719iwn_scan(struct iwn_softc *sc, struct ieee80211vap *vap,
6720 struct ieee80211_scan_state *ss, struct ieee80211_channel *c)
6721{
6783 struct ifnet *ifp = sc->sc_ifp;
6784 struct ieee80211com *ic = ifp->if_l2com;
6722 struct ieee80211com *ic = &sc->sc_ic;
6785 struct ieee80211_node *ni = vap->iv_bss;
6786 struct iwn_scan_hdr *hdr;
6787 struct iwn_cmd_data *tx;
6788 struct iwn_scan_essid *essid;
6789 struct iwn_scan_chan *chan;
6790 struct ieee80211_frame *wh;
6791 struct ieee80211_rateset *rs;
6792 uint8_t *buf, *frm;

--- 121 unchanged lines hidden (view full) ---

6914 /*
6915 * Build a probe request frame. Most of the following code is a
6916 * copy & paste of what is done in net80211.
6917 */
6918 wh = (struct ieee80211_frame *)(essid + 20);
6919 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT |
6920 IEEE80211_FC0_SUBTYPE_PROBE_REQ;
6921 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
6723 struct ieee80211_node *ni = vap->iv_bss;
6724 struct iwn_scan_hdr *hdr;
6725 struct iwn_cmd_data *tx;
6726 struct iwn_scan_essid *essid;
6727 struct iwn_scan_chan *chan;
6728 struct ieee80211_frame *wh;
6729 struct ieee80211_rateset *rs;
6730 uint8_t *buf, *frm;

--- 121 unchanged lines hidden (view full) ---

6852 /*
6853 * Build a probe request frame. Most of the following code is a
6854 * copy & paste of what is done in net80211.
6855 */
6856 wh = (struct ieee80211_frame *)(essid + 20);
6857 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT |
6858 IEEE80211_FC0_SUBTYPE_PROBE_REQ;
6859 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
6922 IEEE80211_ADDR_COPY(wh->i_addr1, ifp->if_broadcastaddr);
6923 IEEE80211_ADDR_COPY(wh->i_addr2, IF_LLADDR(ifp));
6924 IEEE80211_ADDR_COPY(wh->i_addr3, ifp->if_broadcastaddr);
6860 IEEE80211_ADDR_COPY(wh->i_addr1, vap->iv_ifp->if_broadcastaddr);
6861 IEEE80211_ADDR_COPY(wh->i_addr2, IF_LLADDR(vap->iv_ifp));
6862 IEEE80211_ADDR_COPY(wh->i_addr3, vap->iv_ifp->if_broadcastaddr);
6925 *(uint16_t *)&wh->i_dur[0] = 0; /* filled by HW */
6926 *(uint16_t *)&wh->i_seq[0] = 0; /* filled by HW */
6927
6928 frm = (uint8_t *)(wh + 1);
6929 frm = ieee80211_add_ssid(frm, NULL, 0);
6930 frm = ieee80211_add_rates(frm, rs);
6931 if (rs->rs_nrates > IEEE80211_RATE_SIZE)
6932 frm = ieee80211_add_xrates(frm, rs);

--- 102 unchanged lines hidden (view full) ---

7035
7036 return error;
7037}
7038
7039static int
7040iwn_auth(struct iwn_softc *sc, struct ieee80211vap *vap)
7041{
7042 struct iwn_ops *ops = &sc->ops;
6863 *(uint16_t *)&wh->i_dur[0] = 0; /* filled by HW */
6864 *(uint16_t *)&wh->i_seq[0] = 0; /* filled by HW */
6865
6866 frm = (uint8_t *)(wh + 1);
6867 frm = ieee80211_add_ssid(frm, NULL, 0);
6868 frm = ieee80211_add_rates(frm, rs);
6869 if (rs->rs_nrates > IEEE80211_RATE_SIZE)
6870 frm = ieee80211_add_xrates(frm, rs);

--- 102 unchanged lines hidden (view full) ---

6973
6974 return error;
6975}
6976
6977static int
6978iwn_auth(struct iwn_softc *sc, struct ieee80211vap *vap)
6979{
6980 struct iwn_ops *ops = &sc->ops;
7043 struct ifnet *ifp = sc->sc_ifp;
7044 struct ieee80211com *ic = ifp->if_l2com;
6981 struct ieee80211com *ic = &sc->sc_ic;
7045 struct ieee80211_node *ni = vap->iv_bss;
7046 int error;
7047
7048 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
7049
7050 sc->rxon = &sc->rx_on[IWN_RXON_BSS_CTX];
7051 /* Update adapter configuration. */
7052 IEEE80211_ADDR_COPY(sc->rxon->bssid, ni->ni_bssid);

--- 55 unchanged lines hidden (view full) ---

7108
7109 return 0;
7110}
7111
7112static int
7113iwn_run(struct iwn_softc *sc, struct ieee80211vap *vap)
7114{
7115 struct iwn_ops *ops = &sc->ops;
6982 struct ieee80211_node *ni = vap->iv_bss;
6983 int error;
6984
6985 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
6986
6987 sc->rxon = &sc->rx_on[IWN_RXON_BSS_CTX];
6988 /* Update adapter configuration. */
6989 IEEE80211_ADDR_COPY(sc->rxon->bssid, ni->ni_bssid);

--- 55 unchanged lines hidden (view full) ---

7045
7046 return 0;
7047}
7048
7049static int
7050iwn_run(struct iwn_softc *sc, struct ieee80211vap *vap)
7051{
7052 struct iwn_ops *ops = &sc->ops;
7116 struct ifnet *ifp = sc->sc_ifp;
7117 struct ieee80211com *ic = ifp->if_l2com;
7053 struct ieee80211com *ic = &sc->sc_ic;
7118 struct ieee80211_node *ni = vap->iv_bss;
7119 struct iwn_node_info node;
7120 int error;
7121
7122 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
7123
7124 sc->rxon = &sc->rx_on[IWN_RXON_BSS_CTX];
7125 if (ic->ic_opmode == IEEE80211_M_MONITOR) {

--- 1554 unchanged lines hidden (view full) ---

8680 /* Power OFF adapter. */
8681 iwn_apm_stop(sc);
8682}
8683
8684static void
8685iwn_radio_on(void *arg0, int pending)
8686{
8687 struct iwn_softc *sc = arg0;
7054 struct ieee80211_node *ni = vap->iv_bss;
7055 struct iwn_node_info node;
7056 int error;
7057
7058 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
7059
7060 sc->rxon = &sc->rx_on[IWN_RXON_BSS_CTX];
7061 if (ic->ic_opmode == IEEE80211_M_MONITOR) {

--- 1554 unchanged lines hidden (view full) ---

8616 /* Power OFF adapter. */
8617 iwn_apm_stop(sc);
8618}
8619
8620static void
8621iwn_radio_on(void *arg0, int pending)
8622{
8623 struct iwn_softc *sc = arg0;
8688 struct ifnet *ifp = sc->sc_ifp;
8689 struct ieee80211com *ic = ifp->if_l2com;
8624 struct ieee80211com *ic = &sc->sc_ic;
8690 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
8691
8692 DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
8693
8694 if (vap != NULL) {
8695 iwn_init(sc);
8696 ieee80211_init(vap);
8697 }
8698}
8699
8700static void
8701iwn_radio_off(void *arg0, int pending)
8702{
8703 struct iwn_softc *sc = arg0;
8625 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
8626
8627 DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
8628
8629 if (vap != NULL) {
8630 iwn_init(sc);
8631 ieee80211_init(vap);
8632 }
8633}
8634
8635static void
8636iwn_radio_off(void *arg0, int pending)
8637{
8638 struct iwn_softc *sc = arg0;
8704 struct ifnet *ifp = sc->sc_ifp;
8705 struct ieee80211com *ic = ifp->if_l2com;
8639 struct ieee80211com *ic = &sc->sc_ic;
8706 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
8707
8708 DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
8709
8710 iwn_stop(sc);
8711 if (vap != NULL)
8712 ieee80211_stop(vap);
8713
8714 /* Enable interrupts to get RF toggle notification. */
8715 IWN_LOCK(sc);
8716 IWN_WRITE(sc, IWN_INT, 0xffffffff);
8717 IWN_WRITE(sc, IWN_INT_MASK, sc->int_mask);
8718 IWN_UNLOCK(sc);
8719}
8720
8721static void
8722iwn_panicked(void *arg0, int pending)
8723{
8724 struct iwn_softc *sc = arg0;
8640 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
8641
8642 DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
8643
8644 iwn_stop(sc);
8645 if (vap != NULL)
8646 ieee80211_stop(vap);
8647
8648 /* Enable interrupts to get RF toggle notification. */
8649 IWN_LOCK(sc);
8650 IWN_WRITE(sc, IWN_INT, 0xffffffff);
8651 IWN_WRITE(sc, IWN_INT_MASK, sc->int_mask);
8652 IWN_UNLOCK(sc);
8653}
8654
8655static void
8656iwn_panicked(void *arg0, int pending)
8657{
8658 struct iwn_softc *sc = arg0;
8725 struct ifnet *ifp = sc->sc_ifp;
8726 struct ieee80211com *ic = ifp->if_l2com;
8659 struct ieee80211com *ic = &sc->sc_ic;
8727 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
8728 int error;
8729
8730 if (vap == NULL) {
8731 printf("%s: null vap\n", __func__);
8732 return;
8733 }
8734

--- 11 unchanged lines hidden (view full) ---

8746 }
8747 if (vap->iv_state >= IEEE80211_S_RUN &&
8748 (error = iwn_run(sc, vap)) != 0) {
8749 device_printf(sc->sc_dev,
8750 "%s: could not move to run state\n", __func__);
8751 }
8752
8753 /* Only run start once the NIC is in a useful state, like associated */
8660 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
8661 int error;
8662
8663 if (vap == NULL) {
8664 printf("%s: null vap\n", __func__);
8665 return;
8666 }
8667

--- 11 unchanged lines hidden (view full) ---

8679 }
8680 if (vap->iv_state >= IEEE80211_S_RUN &&
8681 (error = iwn_run(sc, vap)) != 0) {
8682 device_printf(sc->sc_dev,
8683 "%s: could not move to run state\n", __func__);
8684 }
8685
8686 /* Only run start once the NIC is in a useful state, like associated */
8754 iwn_start_locked(sc->sc_ifp);
8687 iwn_start_locked(sc);
8755
8756 IWN_UNLOCK(sc);
8757}
8758
8759static void
8760iwn_init_locked(struct iwn_softc *sc)
8761{
8688
8689 IWN_UNLOCK(sc);
8690}
8691
8692static void
8693iwn_init_locked(struct iwn_softc *sc)
8694{
8762 struct ifnet *ifp = sc->sc_ifp;
8763 int error;
8764
8765 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
8766
8767 IWN_LOCK_ASSERT(sc);
8768
8695 int error;
8696
8697 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
8698
8699 IWN_LOCK_ASSERT(sc);
8700
8701 sc->sc_flags |= IWN_FLAG_RUNNING;
8702
8769 if ((error = iwn_hw_prepare(sc)) != 0) {
8770 device_printf(sc->sc_dev, "%s: hardware not ready, error %d\n",
8771 __func__, error);
8772 goto fail;
8773 }
8774
8775 /* Initialize interrupt mask to default value. */
8776 sc->int_mask = IWN_INT_MASK_DEF;

--- 31 unchanged lines hidden (view full) ---

8808 /* Configure adapter now that it is ready. */
8809 if ((error = iwn_config(sc)) != 0) {
8810 device_printf(sc->sc_dev,
8811 "%s: could not configure device, error %d\n", __func__,
8812 error);
8813 goto fail;
8814 }
8815
8703 if ((error = iwn_hw_prepare(sc)) != 0) {
8704 device_printf(sc->sc_dev, "%s: hardware not ready, error %d\n",
8705 __func__, error);
8706 goto fail;
8707 }
8708
8709 /* Initialize interrupt mask to default value. */
8710 sc->int_mask = IWN_INT_MASK_DEF;

--- 31 unchanged lines hidden (view full) ---

8742 /* Configure adapter now that it is ready. */
8743 if ((error = iwn_config(sc)) != 0) {
8744 device_printf(sc->sc_dev,
8745 "%s: could not configure device, error %d\n", __func__,
8746 error);
8747 goto fail;
8748 }
8749
8816 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
8817 ifp->if_drv_flags |= IFF_DRV_RUNNING;
8818
8819 callout_reset(&sc->watchdog_to, hz, iwn_watchdog, sc);
8820
8821 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);
8822
8823 return;
8824
8750 callout_reset(&sc->watchdog_to, hz, iwn_watchdog, sc);
8751
8752 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);
8753
8754 return;
8755
8825fail: iwn_stop_locked(sc);
8756fail:
8757 sc->sc_flags &= ~IWN_FLAG_RUNNING;
8758 iwn_stop_locked(sc);
8826 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end in error\n",__func__);
8827}
8828
8829static void
8759 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end in error\n",__func__);
8760}
8761
8762static void
8830iwn_init(void *arg)
8763iwn_init(struct iwn_softc *sc)
8831{
8764{
8832 struct iwn_softc *sc = arg;
8833 struct ifnet *ifp = sc->sc_ifp;
8834 struct ieee80211com *ic = ifp->if_l2com;
8835
8836 IWN_LOCK(sc);
8837 iwn_init_locked(sc);
8838 IWN_UNLOCK(sc);
8839
8765
8766 IWN_LOCK(sc);
8767 iwn_init_locked(sc);
8768 IWN_UNLOCK(sc);
8769
8840 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
8841 ieee80211_start_all(ic);
8770 if (sc->sc_flags & IWN_FLAG_RUNNING)
8771 ieee80211_start_all(&sc->sc_ic);
8842}
8843
8844static void
8845iwn_stop_locked(struct iwn_softc *sc)
8846{
8772}
8773
8774static void
8775iwn_stop_locked(struct iwn_softc *sc)
8776{
8847 struct ifnet *ifp = sc->sc_ifp;
8848
8849 IWN_LOCK_ASSERT(sc);
8850
8851 sc->sc_is_scanning = 0;
8852 sc->sc_tx_timer = 0;
8853 callout_stop(&sc->watchdog_to);
8854 callout_stop(&sc->calib_to);
8777
8778 IWN_LOCK_ASSERT(sc);
8779
8780 sc->sc_is_scanning = 0;
8781 sc->sc_tx_timer = 0;
8782 callout_stop(&sc->watchdog_to);
8783 callout_stop(&sc->calib_to);
8855 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
8784 sc->sc_flags &= ~IWN_FLAG_RUNNING;
8856
8857 /* Power OFF hardware. */
8858 iwn_hw_stop(sc);
8859}
8860
8861static void
8862iwn_stop(struct iwn_softc *sc)
8863{
8864 IWN_LOCK(sc);
8865 iwn_stop_locked(sc);
8866 IWN_UNLOCK(sc);
8867}
8868
8869/*
8870 * Callback from net80211 to start a scan.
8871 */
8872static void
8873iwn_scan_start(struct ieee80211com *ic)
8874{
8785
8786 /* Power OFF hardware. */
8787 iwn_hw_stop(sc);
8788}
8789
8790static void
8791iwn_stop(struct iwn_softc *sc)
8792{
8793 IWN_LOCK(sc);
8794 iwn_stop_locked(sc);
8795 IWN_UNLOCK(sc);
8796}
8797
8798/*
8799 * Callback from net80211 to start a scan.
8800 */
8801static void
8802iwn_scan_start(struct ieee80211com *ic)
8803{
8875 struct ifnet *ifp = ic->ic_ifp;
8876 struct iwn_softc *sc = ifp->if_softc;
8804 struct iwn_softc *sc = ic->ic_softc;
8877
8878 IWN_LOCK(sc);
8879 /* make the link LED blink while we're scanning */
8880 iwn_set_led(sc, IWN_LED_LINK, 20, 2);
8881 IWN_UNLOCK(sc);
8882}
8883
8884/*
8885 * Callback from net80211 to terminate a scan.
8886 */
8887static void
8888iwn_scan_end(struct ieee80211com *ic)
8889{
8805
8806 IWN_LOCK(sc);
8807 /* make the link LED blink while we're scanning */
8808 iwn_set_led(sc, IWN_LED_LINK, 20, 2);
8809 IWN_UNLOCK(sc);
8810}
8811
8812/*
8813 * Callback from net80211 to terminate a scan.
8814 */
8815static void
8816iwn_scan_end(struct ieee80211com *ic)
8817{
8890 struct ifnet *ifp = ic->ic_ifp;
8891 struct iwn_softc *sc = ifp->if_softc;
8818 struct iwn_softc *sc = ic->ic_softc;
8892 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
8893
8894 IWN_LOCK(sc);
8895 if (vap->iv_state == IEEE80211_S_RUN) {
8896 /* Set link LED to ON status if we are associated */
8897 iwn_set_led(sc, IWN_LED_LINK, 0, 1);
8898 }
8899 IWN_UNLOCK(sc);
8900}
8901
8902/*
8903 * Callback from net80211 to force a channel change.
8904 */
8905static void
8906iwn_set_channel(struct ieee80211com *ic)
8907{
8908 const struct ieee80211_channel *c = ic->ic_curchan;
8819 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
8820
8821 IWN_LOCK(sc);
8822 if (vap->iv_state == IEEE80211_S_RUN) {
8823 /* Set link LED to ON status if we are associated */
8824 iwn_set_led(sc, IWN_LED_LINK, 0, 1);
8825 }
8826 IWN_UNLOCK(sc);
8827}
8828
8829/*
8830 * Callback from net80211 to force a channel change.
8831 */
8832static void
8833iwn_set_channel(struct ieee80211com *ic)
8834{
8835 const struct ieee80211_channel *c = ic->ic_curchan;
8909 struct ifnet *ifp = ic->ic_ifp;
8910 struct iwn_softc *sc = ifp->if_softc;
8836 struct iwn_softc *sc = ic->ic_softc;
8911 int error;
8912
8913 DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
8914
8915 IWN_LOCK(sc);
8916 sc->sc_rxtap.wr_chan_freq = htole16(c->ic_freq);
8917 sc->sc_rxtap.wr_chan_flags = htole16(c->ic_flags);
8918 sc->sc_txtap.wt_chan_freq = htole16(c->ic_freq);

--- 40 unchanged lines hidden (view full) ---

8959{
8960 /* NB: don't try to abort scan; wait for firmware to finish */
8961}
8962
8963static void
8964iwn_hw_reset(void *arg0, int pending)
8965{
8966 struct iwn_softc *sc = arg0;
8837 int error;
8838
8839 DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
8840
8841 IWN_LOCK(sc);
8842 sc->sc_rxtap.wr_chan_freq = htole16(c->ic_freq);
8843 sc->sc_rxtap.wr_chan_flags = htole16(c->ic_flags);
8844 sc->sc_txtap.wt_chan_freq = htole16(c->ic_freq);

--- 40 unchanged lines hidden (view full) ---

8885{
8886 /* NB: don't try to abort scan; wait for firmware to finish */
8887}
8888
8889static void
8890iwn_hw_reset(void *arg0, int pending)
8891{
8892 struct iwn_softc *sc = arg0;
8967 struct ifnet *ifp = sc->sc_ifp;
8968 struct ieee80211com *ic = ifp->if_l2com;
8893 struct ieee80211com *ic = &sc->sc_ic;
8969
8970 DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
8971
8972 iwn_stop(sc);
8973 iwn_init(sc);
8974 ieee80211_notify_radio(ic, 1);
8975}
8976#ifdef IWN_DEBUG

--- 80 unchanged lines hidden ---
8894
8895 DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
8896
8897 iwn_stop(sc);
8898 iwn_init(sc);
8899 ieee80211_notify_radio(ic, 1);
8900}
8901#ifdef IWN_DEBUG

--- 80 unchanged lines hidden ---