Deleted Added
sdiff udiff text old ( 285234 ) new ( 286410 )
full compact
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 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 *);
238static int iwn_transmit(struct ieee80211com *, struct mbuf *);
239static void iwn_start_locked(struct iwn_softc *);
240static void iwn_watchdog(void *);
241static int iwn_ioctl(struct ieee80211com *, u_long , void *);
242static void iwn_parent(struct ieee80211com *);
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 *);
340static void iwn_init(struct iwn_softc *);
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;
410 int i, error, rid;
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
552 ic = &sc->sc_ic;
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. */
577 if ((error = iwn_read_eeprom(sc, ic->ic_macaddr)) != 0) {
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,
595 ic->ic_macaddr, ":");
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
636 ieee80211_ifattach(ic);
637 ic->ic_vap_create = iwn_vap_create;
638 ic->ic_ioctl = iwn_ioctl;
639 ic->ic_parent = iwn_parent;
640 ic->ic_vap_delete = iwn_vap_delete;
641 ic->ic_transmit = iwn_transmit;
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{
1282
1283 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
1284 ieee80211_radiotap_attach(&sc->sc_ic,
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;
1314
1315 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */
1316 return NULL;
1317
1318 ivp = malloc(sizeof(struct iwn_vap), M_80211_VAP, M_WAITOK | M_ZERO);
1319 vap = &ivp->iv_vap;
1320 ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid);
1321 ivp->ctx = IWN_RXON_BSS_CTX;
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. */
1330 ieee80211_vap_attach(vap, iwn_media_change, ieee80211_media_status,
1331 mac);
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);
1372 int qid;
1373
1374 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);
1375
1376 if (sc->sc_ic.ic_softc != NULL) {
1377 /* Free the mbuf queue and node references */
1378 IWN_LOCK(sc);
1379 iwn_xmit_queue_drain(sc);
1380 IWN_UNLOCK(sc);
1381
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);
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);
1392 ieee80211_ifdetach(&sc->sc_ic);
1393 }
1394
1395 mbufq_drain(&sc->sc_snd);
1396
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
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);
1437
1438 ieee80211_suspend_all(&sc->sc_ic);
1439 return 0;
1440}
1441
1442static int
1443iwn_resume(device_t dev)
1444{
1445 struct iwn_softc *sc = device_get_softc(dev);
1446
1447 /* Clear device-specific "PCI retry timeout" register (41h). */
1448 pci_write_config(dev, 0x41, 0, 1);
1449
1450 ieee80211_resume_all(&sc->sc_ic);
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{
2359 struct ieee80211com *ic = &sc->sc_ic;
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{
2418 struct ieee80211com *ic = &sc->sc_ic;
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{
2486 struct ieee80211com *ic = &sc->sc_ic;
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];
2554 struct ieee80211com *ic = &sc->sc_ic;
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;
2937 struct ieee80211com *ic = &sc->sc_ic;
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);
2984 counter_u64_add(ic->ic_ierrors, 1);
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);
2991 counter_u64_add(ic->ic_ierrors, 1);
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__);
2999 counter_u64_add(ic->ic_ierrors, 1);
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);
3022 counter_u64_add(ic->ic_ierrors, 1);
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. */
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;
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) {
3207 tx_err ++;
3208 ieee80211_ratectl_tx_complete(ni->ni_vap, ni,
3209 IEEE80211_RATECTL_TX_FAILURE, &ackfailcnt, NULL);
3210 } else {
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;
3356 struct ieee80211com *ic = &sc->sc_ic;
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{
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 */
3549 if (status & IWN_TX_FAIL)
3550 ieee80211_ratectl_tx_complete(vap, ni,
3551 IEEE80211_RATECTL_TX_FAILURE, &ackfailcnt, NULL);
3552 else
3553 ieee80211_ratectl_tx_complete(vap, ni,
3554 IEEE80211_RATECTL_TX_SUCCESS, &ackfailcnt, NULL);
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);
3580 if (sc->qfullmsk == 0)
3581 iwn_start_locked(sc);
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;
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);
3764 if (sc->qfullmsk == 0)
3765 iwn_start_locked(sc);
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;
3779 struct ieee80211com *ic = &sc->sc_ic;
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{
3973 struct ieee80211com *ic = &sc->sc_ic;
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;
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. */
4144 if (sc->sc_flags & IWN_FLAG_RUNNING)
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;
4628 struct ieee80211vap *vap = ni->ni_vap;
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;
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);
4856 ieee80211_free_node(ni);
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;
4869 struct iwn_softc *sc = ic->ic_softc;
4870 int error = 0;
4871
4872 DPRINTF(sc, IWN_DEBUG_XMIT | IWN_DEBUG_TRACE, "->%s begin\n", __func__);
4873
4874 if ((sc->sc_flags & IWN_FLAG_RUNNING) == 0) {
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);
4891 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);
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
4926static int
4927iwn_transmit(struct ieee80211com *ic, struct mbuf *m)
4928{
4929 struct iwn_softc *sc;
4930 int error;
4931
4932 sc = ic->ic_softc;
4933
4934 IWN_LOCK(sc);
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);
4945 IWN_UNLOCK(sc);
4946 return (0);
4947}
4948
4949static void
4950iwn_start_locked(struct iwn_softc *sc)
4951{
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__);
4966 while (sc->qfullmsk == 0 &&
4967 (m = mbufq_dequeue(&sc->sc_snd)) != NULL) {
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);
4972 ieee80211_free_node(ni);
4973 } else
4974 sc->sc_tx_timer = 5;
4975 }
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;
4983 struct ieee80211com *ic = &sc->sc_ic;
4984
4985 IWN_LOCK_ASSERT(sc);
4986
4987 KASSERT(sc->sc_flags & IWN_FLAG_RUNNING, ("not running"));
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
5002iwn_ioctl(struct ieee80211com *ic, u_long cmd, void *data)
5003{
5004 struct ifreq *ifr = data;
5005 struct iwn_softc *sc = ic->ic_softc;
5006 int error = 0;
5007
5008 switch (cmd) {
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:
5022 error = ENOTTY;
5023 break;
5024 }
5025 return (error);
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
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;
5284 struct ieee80211com *ic = &sc->sc_ic;
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);
5295 IEEE80211_ADDR_COPY(node.macaddr, ieee80211broadcastaddr);
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{
5444 struct ieee80211com *ic = &sc->sc_ic;
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;
5814 struct ieee80211com *ic = &sc->sc_ic;
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;
6448 uint32_t htflags = 0;
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;
6475 struct ieee80211com *ic = &sc->sc_ic;
6476 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
6477 const uint8_t *macaddr;
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));
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);
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{
6674 struct ieee80211com *ic = &sc->sc_ic;
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{
6722 struct ieee80211com *ic = &sc->sc_ic;
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;
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);
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;
6981 struct ieee80211com *ic = &sc->sc_ic;
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;
7053 struct ieee80211com *ic = &sc->sc_ic;
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;
8624 struct ieee80211com *ic = &sc->sc_ic;
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;
8639 struct ieee80211com *ic = &sc->sc_ic;
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;
8659 struct ieee80211com *ic = &sc->sc_ic;
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 */
8687 iwn_start_locked(sc);
8688
8689 IWN_UNLOCK(sc);
8690}
8691
8692static void
8693iwn_init_locked(struct iwn_softc *sc)
8694{
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
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
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
8756fail:
8757 sc->sc_flags &= ~IWN_FLAG_RUNNING;
8758 iwn_stop_locked(sc);
8759 DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end in error\n",__func__);
8760}
8761
8762static void
8763iwn_init(struct iwn_softc *sc)
8764{
8765
8766 IWN_LOCK(sc);
8767 iwn_init_locked(sc);
8768 IWN_UNLOCK(sc);
8769
8770 if (sc->sc_flags & IWN_FLAG_RUNNING)
8771 ieee80211_start_all(&sc->sc_ic);
8772}
8773
8774static void
8775iwn_stop_locked(struct iwn_softc *sc)
8776{
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);
8784 sc->sc_flags &= ~IWN_FLAG_RUNNING;
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{
8804 struct iwn_softc *sc = ic->ic_softc;
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{
8818 struct iwn_softc *sc = ic->ic_softc;
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;
8836 struct iwn_softc *sc = ic->ic_softc;
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;
8893 struct ieee80211com *ic = &sc->sc_ic;
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 ---