View | Details | Raw Unified | Return to bug 197143 | Differences between
and this patch

Collapse All | Expand All

(-)sys/dev/wpi/if_wpi.c (-518 / +1076 lines)
Lines 76-81 Link Here
76
#include <sys/linker.h>
76
#include <sys/linker.h>
77
#include <sys/firmware.h>
77
#include <sys/firmware.h>
78
78
79
#include <machine/atomic.h>
79
#include <machine/bus.h>
80
#include <machine/bus.h>
80
#include <machine/resource.h>
81
#include <machine/resource.h>
81
#include <sys/rman.h>
82
#include <sys/rman.h>
Lines 130-135 Link Here
130
static int	wpi_attach(device_t);
131
static int	wpi_attach(device_t);
131
static void	wpi_radiotap_attach(struct wpi_softc *);
132
static void	wpi_radiotap_attach(struct wpi_softc *);
132
static void	wpi_sysctlattach(struct wpi_softc *);
133
static void	wpi_sysctlattach(struct wpi_softc *);
134
static void	wpi_init_beacon(struct wpi_vap *);
133
static struct ieee80211vap *wpi_vap_create(struct ieee80211com *,
135
static struct ieee80211vap *wpi_vap_create(struct ieee80211com *,
134
		    const char [IFNAMSIZ], int, enum ieee80211_opmode, int,
136
		    const char [IFNAMSIZ], int, enum ieee80211_opmode, int,
135
		    const uint8_t [IEEE80211_ADDR_LEN],
137
		    const uint8_t [IEEE80211_ADDR_LEN],
Lines 169-174 Link Here
169
		    struct ieee80211_regdomain *, int,
171
		    struct ieee80211_regdomain *, int,
170
		    struct ieee80211_channel[]);
172
		    struct ieee80211_channel[]);
171
static int	wpi_read_eeprom_group(struct wpi_softc *, int);
173
static int	wpi_read_eeprom_group(struct wpi_softc *, int);
174
static int	wpi_add_node_entry_adhoc(struct wpi_softc *);
172
static void	wpi_node_free(struct ieee80211_node *);
175
static void	wpi_node_free(struct ieee80211_node *);
173
static struct ieee80211_node *wpi_node_alloc(struct ieee80211vap *,
176
static struct ieee80211_node *wpi_node_alloc(struct ieee80211vap *,
174
		    const uint8_t mac[IEEE80211_ADDR_LEN]);
177
		    const uint8_t mac[IEEE80211_ADDR_LEN]);
Lines 182-190 Link Here
182
static void	wpi_cmd_done(struct wpi_softc *, struct wpi_rx_desc *);
185
static void	wpi_cmd_done(struct wpi_softc *, struct wpi_rx_desc *);
183
static void	wpi_notif_intr(struct wpi_softc *);
186
static void	wpi_notif_intr(struct wpi_softc *);
184
static void	wpi_wakeup_intr(struct wpi_softc *);
187
static void	wpi_wakeup_intr(struct wpi_softc *);
188
#ifdef WPI_DEBUG
189
static void	wpi_debug_registers(struct wpi_softc *);
190
#endif
185
static void	wpi_fatal_intr(struct wpi_softc *);
191
static void	wpi_fatal_intr(struct wpi_softc *);
186
static void	wpi_intr(void *);
192
static void	wpi_intr(void *);
187
static int	wpi_cmd2(struct wpi_softc *, struct wpi_buf *);
193
static int	wpi_cmd2(struct wpi_softc *, struct wpi_buf *, int);
188
static int	wpi_tx_data(struct wpi_softc *, struct mbuf *,
194
static int	wpi_tx_data(struct wpi_softc *, struct mbuf *,
189
		    struct ieee80211_node *);
195
		    struct ieee80211_node *);
190
static int	wpi_tx_data_raw(struct wpi_softc *, struct mbuf *,
196
static int	wpi_tx_data_raw(struct wpi_softc *, struct mbuf *,
Lines 193-199 Link Here
193
static int	wpi_raw_xmit(struct ieee80211_node *, struct mbuf *,
199
static int	wpi_raw_xmit(struct ieee80211_node *, struct mbuf *,
194
		    const struct ieee80211_bpf_params *);
200
		    const struct ieee80211_bpf_params *);
195
static void	wpi_start(struct ifnet *);
201
static void	wpi_start(struct ifnet *);
196
static void	wpi_start_locked(struct ifnet *);
202
static void	wpi_start_task(void *, int);
197
static void	wpi_watchdog_rfkill(void *);
203
static void	wpi_watchdog_rfkill(void *);
198
static void	wpi_watchdog(void *);
204
static void	wpi_watchdog(void *);
199
static int	wpi_ioctl(struct ifnet *, u_long, caddr_t);
205
static int	wpi_ioctl(struct ifnet *, u_long, caddr_t);
Lines 224-234 Link Here
224
		    struct ieee80211_channel *);
230
		    struct ieee80211_channel *);
225
static int	wpi_scan(struct wpi_softc *, struct ieee80211_channel *);
231
static int	wpi_scan(struct wpi_softc *, struct ieee80211_channel *);
226
static int	wpi_auth(struct wpi_softc *, struct ieee80211vap *);
232
static int	wpi_auth(struct wpi_softc *, struct ieee80211vap *);
233
static int	wpi_config_beacon(struct wpi_vap *);
234
static int	wpi_setup_beacon(struct wpi_softc *, struct ieee80211_node *);
227
static void	wpi_update_beacon(struct ieee80211vap *, int);
235
static void	wpi_update_beacon(struct ieee80211vap *, int);
228
static int	wpi_setup_beacon(struct wpi_softc *, struct ieee80211_node *);
236
static void	wpi_newassoc(struct ieee80211_node *, int);
229
static int	wpi_run(struct wpi_softc *, struct ieee80211vap *);
237
static int	wpi_run(struct wpi_softc *, struct ieee80211vap *);
230
static int	wpi_key_alloc(struct ieee80211vap *, struct ieee80211_key *,
238
static int	wpi_load_key(struct ieee80211_node *,
231
		    ieee80211_keyix *, ieee80211_keyix *);
239
		    const struct ieee80211_key *);
240
static void	wpi_load_key_cb(void *, struct ieee80211_node *);
241
static int	wpi_set_global_keys(struct ieee80211_node *);
242
static int	wpi_del_key(struct ieee80211_node *,
243
		    const struct ieee80211_key *);
244
static void	wpi_del_key_cb(void *, struct ieee80211_node *);
245
static int	wpi_process_key(struct ieee80211vap *,
246
		    const struct ieee80211_key *, int);
232
static int	wpi_key_set(struct ieee80211vap *,
247
static int	wpi_key_set(struct ieee80211vap *,
233
		    const struct ieee80211_key *,
248
		    const struct ieee80211_key *,
234
		    const uint8_t mac[IEEE80211_ADDR_LEN]);
249
		    const uint8_t mac[IEEE80211_ADDR_LEN]);
Lines 248-254 Link Here
248
static void	wpi_hw_stop(struct wpi_softc *);
263
static void	wpi_hw_stop(struct wpi_softc *);
249
static void	wpi_radio_on(void *, int);
264
static void	wpi_radio_on(void *, int);
250
static void	wpi_radio_off(void *, int);
265
static void	wpi_radio_off(void *, int);
251
static void	wpi_init_locked(struct wpi_softc *);
252
static void	wpi_init(void *);
266
static void	wpi_init(void *);
253
static void	wpi_stop_locked(struct wpi_softc *);
267
static void	wpi_stop_locked(struct wpi_softc *);
254
static void	wpi_stop(struct wpi_softc *);
268
static void	wpi_stop(struct wpi_softc *);
Lines 307-319 Link Here
307
	struct wpi_softc *sc = (struct wpi_softc *)device_get_softc(dev);
321
	struct wpi_softc *sc = (struct wpi_softc *)device_get_softc(dev);
308
	struct ieee80211com *ic;
322
	struct ieee80211com *ic;
309
	struct ifnet *ifp;
323
	struct ifnet *ifp;
310
	int i, error, rid, supportsa = 1;
324
	int i, error, rid;
325
#ifdef WPI_DEBUG
326
	int supportsa = 1;
311
	const struct wpi_ident *ident;
327
	const struct wpi_ident *ident;
328
#endif
312
	uint8_t macaddr[IEEE80211_ADDR_LEN];
329
	uint8_t macaddr[IEEE80211_ADDR_LEN];
313
330
314
	sc->sc_dev = dev;
331
	sc->sc_dev = dev;
315
332
316
#ifdef	WPI_DEBUG
333
#ifdef WPI_DEBUG
317
	error = resource_int_value(device_get_name(sc->sc_dev),
334
	error = resource_int_value(device_get_name(sc->sc_dev),
318
	    device_get_unit(sc->sc_dev), "debug", &(sc->sc_debug));
335
	    device_get_unit(sc->sc_dev), "debug", &(sc->sc_debug));
319
	if (error != 0)
336
	if (error != 0)
Lines 339-344 Link Here
339
	 * this is one such card. A 0x0 in the subdevice table indicates
356
	 * this is one such card. A 0x0 in the subdevice table indicates
340
	 * the entire subdevice range is to be ignored.
357
	 * the entire subdevice range is to be ignored.
341
	 */
358
	 */
359
#ifdef WPI_DEBUG
342
	for (ident = wpi_ident_table; ident->name != NULL; ident++) {
360
	for (ident = wpi_ident_table; ident->name != NULL; ident++) {
343
		if (ident->subdevice &&
361
		if (ident->subdevice &&
344
		    pci_get_subdevice(dev) == ident->subdevice) {
362
		    pci_get_subdevice(dev) == ident->subdevice) {
Lines 346-351 Link Here
346
		    break;
364
		    break;
347
		}
365
		}
348
	}
366
	}
367
#endif
349
368
350
	/* Clear device-specific "PCI retry timeout" register (41h). */
369
	/* Clear device-specific "PCI retry timeout" register (41h). */
351
	pci_write_config(dev, 0x41, 0, 1);
370
	pci_write_config(dev, 0x41, 0, 1);
Lines 358-365 Link Here
358
	    RF_ACTIVE);
377
	    RF_ACTIVE);
359
	if (sc->mem == NULL) {
378
	if (sc->mem == NULL) {
360
		device_printf(dev, "can't map mem space\n");
379
		device_printf(dev, "can't map mem space\n");
361
		error = ENOMEM;
380
		return ENOMEM;
362
		return error;
363
	}
381
	}
364
	sc->sc_st = rman_get_bustag(sc->mem);
382
	sc->sc_st = rman_get_bustag(sc->mem);
365
	sc->sc_sh = rman_get_bushandle(sc->mem);
383
	sc->sc_sh = rman_get_bushandle(sc->mem);
Lines 378-386 Link Here
378
	}
396
	}
379
397
380
	WPI_LOCK_INIT(sc);
398
	WPI_LOCK_INIT(sc);
399
	WPI_RXON_LOCK_INIT(sc);
400
	WPI_TX_LOCK_INIT(sc);
401
	WPI_NT_LOCK_INIT(sc);
402
	WPI_TXQ_LOCK_INIT(sc);
381
403
382
	sc->sc_unr = new_unrhdr(WPI_ID_IBSS_MIN, WPI_ID_IBSS_MAX, &sc->sc_mtx);
383
384
	/* Allocate DMA memory for firmware transfers. */
404
	/* Allocate DMA memory for firmware transfers. */
385
	if ((error = wpi_alloc_fwmem(sc)) != 0) {
405
	if ((error = wpi_alloc_fwmem(sc)) != 0) {
386
		device_printf(dev,
406
		device_printf(dev,
Lines 430-435 Link Here
430
	ic->ic_caps =
450
	ic->ic_caps =
431
		  IEEE80211_C_STA		/* station mode supported */
451
		  IEEE80211_C_STA		/* station mode supported */
432
		| IEEE80211_C_IBSS		/* IBSS mode supported */
452
		| IEEE80211_C_IBSS		/* IBSS mode supported */
453
		| IEEE80211_C_HOSTAP		/* Host access point mode */
433
		| IEEE80211_C_MONITOR		/* monitor mode supported */
454
		| IEEE80211_C_MONITOR		/* monitor mode supported */
434
		| IEEE80211_C_AHDEMO		/* adhoc demo mode */
455
		| IEEE80211_C_AHDEMO		/* adhoc demo mode */
435
		| IEEE80211_C_BGSCAN		/* capable of bg scanning */
456
		| IEEE80211_C_BGSCAN		/* capable of bg scanning */
Lines 437-445 Link Here
437
		| IEEE80211_C_SHSLOT		/* short slot time supported */
458
		| IEEE80211_C_SHSLOT		/* short slot time supported */
438
		| IEEE80211_C_WPA		/* 802.11i */
459
		| IEEE80211_C_WPA		/* 802.11i */
439
		| IEEE80211_C_SHPREAMBLE	/* short preamble supported */
460
		| IEEE80211_C_SHPREAMBLE	/* short preamble supported */
440
#if 0
441
		| IEEE80211_C_HOSTAP		/* Host access point mode */
442
#endif
443
		| IEEE80211_C_WME		/* 802.11e */
461
		| IEEE80211_C_WME		/* 802.11e */
444
		| IEEE80211_C_PMGT		/* Station-side power mgmt */
462
		| IEEE80211_C_PMGT		/* Station-side power mgmt */
445
		;
463
		;
Lines 447-454 Link Here
447
	ic->ic_cryptocaps =
465
	ic->ic_cryptocaps =
448
		  IEEE80211_CRYPTO_AES_CCM;
466
		  IEEE80211_CRYPTO_AES_CCM;
449
467
450
	ic->ic_flags |= IEEE80211_F_DATAPAD;
451
452
	/*
468
	/*
453
	 * Read in the eeprom and also setup the channels for
469
	 * Read in the eeprom and also setup the channels for
454
	 * net80211. We don't set the rates as net80211 does this for us
470
	 * net80211. We don't set the rates as net80211 does this for us
Lines 457-476 Link Here
457
		device_printf(dev, "could not read EEPROM, error %d\n",
473
		device_printf(dev, "could not read EEPROM, error %d\n",
458
		    error);
474
		    error);
459
		goto fail;
475
		goto fail;
460
        }
476
	}
461
477
462
#ifdef	WPI_DEBUG
478
#ifdef WPI_DEBUG
463
	if (bootverbose) {
479
	if (bootverbose) {
464
	    device_printf(sc->sc_dev, "Regulatory Domain: %.4s\n", sc->domain);
480
		device_printf(sc->sc_dev, "Regulatory Domain: %.4s\n",
465
	    device_printf(sc->sc_dev, "Hardware Type: %c\n",
481
		    sc->domain);
466
			  sc->type > 1 ? 'B': '?');
482
		device_printf(sc->sc_dev, "Hardware Type: %c\n",
467
	    device_printf(sc->sc_dev, "Hardware Revision: %c\n",
483
		    sc->type > 1 ? 'B': '?');
468
			  ((le16toh(sc->rev) & 0xf0) == 0xd0) ? 'D': '?');
484
		device_printf(sc->sc_dev, "Hardware Revision: %c\n",
469
	    device_printf(sc->sc_dev, "SKU %s support 802.11a\n",
485
		    ((sc->rev & 0xf0) == 0xd0) ? 'D': '?');
470
			  supportsa ? "does" : "does not");
486
		device_printf(sc->sc_dev, "SKU %s support 802.11a\n",
487
		    supportsa ? "does" : "does not");
471
488
472
	    /* XXX hw_config uses the PCIDEV for the Hardware rev. Must check
489
		/* XXX hw_config uses the PCIDEV for the Hardware rev. Must
473
	       what sc->rev really represents - benjsc 20070615 */
490
		   check what sc->rev really represents - benjsc 20070615 */
474
	}
491
	}
475
#endif
492
#endif
476
493
Lines 494-499 Link Here
494
	ic->ic_wme.wme_update = wpi_updateedca;
511
	ic->ic_wme.wme_update = wpi_updateedca;
495
	ic->ic_update_promisc = wpi_update_promisc;
512
	ic->ic_update_promisc = wpi_update_promisc;
496
	ic->ic_update_mcast = wpi_update_mcast;
513
	ic->ic_update_mcast = wpi_update_mcast;
514
	ic->ic_newassoc = wpi_newassoc;
497
	ic->ic_scan_start = wpi_scan_start;
515
	ic->ic_scan_start = wpi_scan_start;
498
	ic->ic_scan_end = wpi_scan_end;
516
	ic->ic_scan_end = wpi_scan_end;
499
	ic->ic_set_channel = wpi_set_channel;
517
	ic->ic_set_channel = wpi_set_channel;
Lines 504-515 Link Here
504
522
505
	wpi_radiotap_attach(sc);
523
	wpi_radiotap_attach(sc);
506
524
507
	callout_init_mtx(&sc->calib_to, &sc->sc_mtx, 0);
525
	callout_init_mtx(&sc->calib_to, &sc->rxon_mtx, 0);
508
	callout_init_mtx(&sc->watchdog_to, &sc->sc_mtx, 0);
526
	callout_init_mtx(&sc->watchdog_to, &sc->sc_mtx, 0);
509
	callout_init_mtx(&sc->watchdog_rfkill, &sc->sc_mtx, 0);
527
	callout_init_mtx(&sc->watchdog_rfkill, &sc->sc_mtx, 0);
510
	TASK_INIT(&sc->sc_reinittask, 0, wpi_hw_reset, sc);
528
	TASK_INIT(&sc->sc_reinittask, 0, wpi_hw_reset, sc);
511
	TASK_INIT(&sc->sc_radiooff_task, 0, wpi_radio_off, sc);
529
	TASK_INIT(&sc->sc_radiooff_task, 0, wpi_radio_off, sc);
512
	TASK_INIT(&sc->sc_radioon_task, 0, wpi_radio_on, sc);
530
	TASK_INIT(&sc->sc_radioon_task, 0, wpi_radio_on, sc);
531
	TASK_INIT(&sc->sc_start_task, 0, wpi_start_task, sc);
513
532
514
	wpi_sysctlattach(sc);
533
	wpi_sysctlattach(sc);
515
534
Lines 560-566 Link Here
560
static void
579
static void
561
wpi_sysctlattach(struct wpi_softc *sc)
580
wpi_sysctlattach(struct wpi_softc *sc)
562
{
581
{
563
#ifdef  WPI_DEBUG
582
#ifdef WPI_DEBUG
564
	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
583
	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
565
	struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
584
	struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
566
585
Lines 570-575 Link Here
570
#endif
589
#endif
571
}
590
}
572
591
592
static void
593
wpi_init_beacon(struct wpi_vap *wvp)
594
{
595
	struct wpi_buf *bcn = &wvp->wv_bcbuf;
596
	struct wpi_cmd_beacon *cmd = (struct wpi_cmd_beacon *)&bcn->data;
597
598
	cmd->id = WPI_ID_BROADCAST;
599
	cmd->ofdm_mask = 0xff;
600
	cmd->cck_mask = 0x0f;
601
	cmd->lifetime = htole32(WPI_LIFETIME_INFINITE);
602
	cmd->flags = htole32(WPI_TX_AUTO_SEQ | WPI_TX_INSERT_TSTAMP);
603
604
	bcn->code = WPI_CMD_SET_BEACON;
605
	bcn->ac = WPI_CMD_QUEUE_NUM;
606
	bcn->size = sizeof(struct wpi_cmd_beacon);
607
}
608
573
static struct ieee80211vap *
609
static struct ieee80211vap *
574
wpi_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
610
wpi_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
575
    enum ieee80211_opmode opmode, int flags,
611
    enum ieee80211_opmode opmode, int flags,
Lines 577-583 Link Here
577
    const uint8_t mac[IEEE80211_ADDR_LEN])
613
    const uint8_t mac[IEEE80211_ADDR_LEN])
578
{
614
{
579
	struct wpi_vap *wvp;
615
	struct wpi_vap *wvp;
580
	struct wpi_buf *bcn;
581
	struct ieee80211vap *vap;
616
	struct ieee80211vap *vap;
582
617
583
	if (!TAILQ_EMPTY(&ic->ic_vaps))		/* only one at a time */
618
	if (!TAILQ_EMPTY(&ic->ic_vaps))		/* only one at a time */
Lines 587-609 Link Here
587
	    M_80211_VAP, M_NOWAIT | M_ZERO);
622
	    M_80211_VAP, M_NOWAIT | M_ZERO);
588
	if (wvp == NULL)
623
	if (wvp == NULL)
589
		return NULL;
624
		return NULL;
590
	vap = &wvp->vap;
625
	vap = &wvp->wv_vap;
591
	ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac);
626
	ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac);
592
627
593
	bcn = &wvp->wv_bcbuf;
628
	if (opmode == IEEE80211_M_IBSS || opmode == IEEE80211_M_HOSTAP) {
594
	bcn->data = NULL;
629
		WPI_VAP_LOCK_INIT(wvp);
630
		wpi_init_beacon(wvp);
631
	}
595
632
596
	/* Override with driver methods. */
633
	/* Override with driver methods. */
597
	wvp->newstate = vap->iv_newstate;
598
	vap->iv_key_alloc = wpi_key_alloc;
599
	vap->iv_key_set = wpi_key_set;
634
	vap->iv_key_set = wpi_key_set;
600
	vap->iv_key_delete = wpi_key_delete;
635
	vap->iv_key_delete = wpi_key_delete;
636
	wvp->wv_newstate = vap->iv_newstate;
601
	vap->iv_newstate = wpi_newstate;
637
	vap->iv_newstate = wpi_newstate;
602
	vap->iv_update_beacon = wpi_update_beacon;
638
	vap->iv_update_beacon = wpi_update_beacon;
639
	vap->iv_max_aid = WPI_ID_IBSS_MAX - WPI_ID_IBSS_MIN + 1;
603
640
604
	ieee80211_ratectl_init(vap);
641
	ieee80211_ratectl_init(vap);
605
	/* Complete setup. */
642
	/* Complete setup. */
606
	ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status);
643
	ieee80211_vap_attach(vap, ieee80211_media_change,
644
	    ieee80211_media_status);
645
607
	ic->ic_opmode = opmode;
646
	ic->ic_opmode = opmode;
608
	return vap;
647
	return vap;
609
}
648
}
Lines 613-624 Link Here
613
{
652
{
614
	struct wpi_vap *wvp = WPI_VAP(vap);
653
	struct wpi_vap *wvp = WPI_VAP(vap);
615
	struct wpi_buf *bcn = &wvp->wv_bcbuf;
654
	struct wpi_buf *bcn = &wvp->wv_bcbuf;
655
	enum ieee80211_opmode opmode = vap->iv_opmode;
616
656
617
	ieee80211_ratectl_deinit(vap);
657
	ieee80211_ratectl_deinit(vap);
618
	ieee80211_vap_detach(vap);
658
	ieee80211_vap_detach(vap);
619
659
620
	if (bcn->data != NULL)
660
	if (opmode == IEEE80211_M_IBSS || opmode == IEEE80211_M_HOSTAP) {
621
		free(bcn->data, M_DEVBUF);
661
		if (bcn->m != NULL)
662
			m_freem(bcn->m);
663
664
		WPI_VAP_LOCK_DESTROY(wvp);
665
	}
666
622
	free(wvp, M_80211_VAP);
667
	free(wvp, M_80211_VAP);
623
}
668
}
624
669
Lines 637-642 Link Here
637
682
638
		ieee80211_draintask(ic, &sc->sc_reinittask);
683
		ieee80211_draintask(ic, &sc->sc_reinittask);
639
		ieee80211_draintask(ic, &sc->sc_radiooff_task);
684
		ieee80211_draintask(ic, &sc->sc_radiooff_task);
685
		ieee80211_draintask(ic, &sc->sc_radioon_task);
686
		ieee80211_draintask(ic, &sc->sc_start_task);
640
687
641
		wpi_stop(sc);
688
		wpi_stop(sc);
642
689
Lines 673-681 Link Here
673
	if (ifp != NULL)
720
	if (ifp != NULL)
674
		if_free(ifp);
721
		if_free(ifp);
675
722
676
	delete_unrhdr(sc->sc_unr);
677
678
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
723
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
724
	WPI_TXQ_LOCK_DESTROY(sc);
725
	WPI_NT_LOCK_DESTROY(sc);
726
	WPI_TX_LOCK_DESTROY(sc);
727
	WPI_RXON_LOCK_DESTROY(sc);
679
	WPI_LOCK_DESTROY(sc);
728
	WPI_LOCK_DESTROY(sc);
680
	return 0;
729
	return 0;
681
}
730
}
Lines 726-732 Link Here
726
	/* Spin until we actually get the lock. */
775
	/* Spin until we actually get the lock. */
727
	for (ntries = 0; ntries < 1000; ntries++) {
776
	for (ntries = 0; ntries < 1000; ntries++) {
728
		if ((WPI_READ(sc, WPI_GP_CNTRL) &
777
		if ((WPI_READ(sc, WPI_GP_CNTRL) &
729
		     (WPI_GP_CNTRL_MAC_ACCESS_ENA | WPI_GP_CNTRL_SLEEP)) ==
778
		    (WPI_GP_CNTRL_MAC_ACCESS_ENA | WPI_GP_CNTRL_SLEEP)) ==
730
		    WPI_GP_CNTRL_MAC_ACCESS_ENA)
779
		    WPI_GP_CNTRL_MAC_ACCESS_ENA)
731
			return 0;
780
			return 0;
732
		DELAY(10);
781
		DELAY(10);
Lines 958-973 Link Here
958
	}
1007
	}
959
1008
960
	/* Create RX buffer DMA tag. */
1009
	/* Create RX buffer DMA tag. */
961
        error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, 
1010
	error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, 
962
	    BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1011
	    BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
963
	    MJUMPAGESIZE, 1, MJUMPAGESIZE, BUS_DMA_NOWAIT, NULL, NULL,
1012
	    MJUMPAGESIZE, 1, MJUMPAGESIZE, BUS_DMA_NOWAIT, NULL, NULL,
964
	    &ring->data_dmat);
1013
	    &ring->data_dmat);
965
        if (error != 0) {
1014
	if (error != 0) {
966
                device_printf(sc->sc_dev,
1015
		device_printf(sc->sc_dev,
967
		    "%s: could not create RX buf DMA tag, error %d\n",
1016
		    "%s: could not create RX buf DMA tag, error %d\n",
968
		    __func__, error);
1017
		    __func__, error);
969
                goto fail;
1018
		goto fail;
970
        }
1019
	}
971
1020
972
	/*
1021
	/*
973
	 * Allocate and map RX buffers.
1022
	 * Allocate and map RX buffers.
Lines 1024-1029 Link Here
1024
wpi_update_rx_ring(struct wpi_softc *sc)
1073
wpi_update_rx_ring(struct wpi_softc *sc)
1025
{
1074
{
1026
	struct wpi_rx_ring *ring = &sc->rxq;
1075
	struct wpi_rx_ring *ring = &sc->rxq;
1076
	if (ring->update != 0) {
1077
		/* Wait for INT_WAKEUP event. */
1078
		return;
1079
	}
1027
1080
1028
	if (WPI_READ(sc, WPI_UCODE_GP1) & WPI_UCODE_GP1_MAC_SLEEP) {
1081
	if (WPI_READ(sc, WPI_UCODE_GP1) & WPI_UCODE_GP1_MAC_SLEEP) {
1029
		DPRINTF(sc, WPI_DEBUG_PWRSAVE, "%s: wakeup request\n",
1082
		DPRINTF(sc, WPI_DEBUG_PWRSAVE, "%s: wakeup request\n",
Lines 1051-1062 Link Here
1051
				break;
1104
				break;
1052
			DELAY(10);
1105
			DELAY(10);
1053
		}
1106
		}
1054
#ifdef WPI_DEBUG
1055
		if (ntries == 1000) {
1056
			device_printf(sc->sc_dev,
1057
			    "timeout resetting Rx ring\n");
1058
		}
1059
#endif
1060
		wpi_nic_unlock(sc);
1107
		wpi_nic_unlock(sc);
1061
	}
1108
	}
1062
1109
Lines 1126-1135 Link Here
1126
	/*
1173
	/*
1127
	 * We only use rings 0 through 4 (4 EDCA + cmd) so there is no need
1174
	 * We only use rings 0 through 4 (4 EDCA + cmd) so there is no need
1128
	 * to allocate commands space for other rings.
1175
	 * to allocate commands space for other rings.
1129
	 * XXX Do we really need to allocate descriptors for other rings?
1130
	 */
1176
	 */
1131
	if (qid > 4)
1177
	if (qid > WPI_CMD_QUEUE_NUM) {
1178
		DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
1132
		return 0;
1179
		return 0;
1180
	}
1133
1181
1134
	size = WPI_TX_RING_COUNT * sizeof (struct wpi_tx_cmd);
1182
	size = WPI_TX_RING_COUNT * sizeof (struct wpi_tx_cmd);
1135
	error = wpi_dma_contig_alloc(sc, &ring->cmd_dma, (void **)&ring->cmd,
1183
	error = wpi_dma_contig_alloc(sc, &ring->cmd_dma, (void **)&ring->cmd,
Lines 1180-1185 Link Here
1180
static void
1228
static void
1181
wpi_update_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring)
1229
wpi_update_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring)
1182
{
1230
{
1231
	if (ring->update != 0) {
1232
		/* Wait for INT_WAKEUP event. */
1233
		return;
1234
	}
1235
1183
	if (WPI_READ(sc, WPI_UCODE_GP1) & WPI_UCODE_GP1_MAC_SLEEP) {
1236
	if (WPI_READ(sc, WPI_UCODE_GP1) & WPI_UCODE_GP1_MAC_SLEEP) {
1184
		DPRINTF(sc, WPI_DEBUG_PWRSAVE, "%s (%d): requesting wakeup\n",
1237
		DPRINTF(sc, WPI_DEBUG_PWRSAVE, "%s (%d): requesting wakeup\n",
1185
		    __func__, ring->qid);
1238
		    __func__, ring->qid);
Lines 1195-1200 Link Here
1195
{
1248
{
1196
	int i;
1249
	int i;
1197
1250
1251
	WPI_TXQ_LOCK(sc);
1252
1198
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
1253
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
1199
1254
1200
	for (i = 0; i < WPI_TX_RING_COUNT; i++) {
1255
	for (i = 0; i < WPI_TX_RING_COUNT; i++) {
Lines 1212-1221 Link Here
1212
	memset(ring->desc, 0, ring->desc_dma.size);
1267
	memset(ring->desc, 0, ring->desc_dma.size);
1213
	bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map,
1268
	bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map,
1214
	    BUS_DMASYNC_PREWRITE);
1269
	    BUS_DMASYNC_PREWRITE);
1215
	sc->qfullmsk &= ~(1 << ring->qid);
1270
	atomic_clear_32(&sc->qfullmsk, 1 << ring->qid);
1216
	ring->queued = 0;
1271
	atomic_store_rel_32(&ring->queued, 0);
1217
	ring->cur = 0;
1272
	ring->cur = 0;
1218
	ring->update = 0;
1273
	ring->update = 0;
1274
	WPI_TXQ_UNLOCK(sc);
1219
}
1275
}
1220
1276
1221
static void
1277
static void
Lines 1284-1291 Link Here
1284
	WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_TYPE, &sc->type,
1340
	WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_TYPE, &sc->type,
1285
	    sizeof(sc->type)));
1341
	    sizeof(sc->type)));
1286
1342
1287
	DPRINTF(sc, WPI_DEBUG_EEPROM, "cap=%x rev=%x type=%x\n", sc->cap, le16toh(sc->rev),
1343
	sc->rev = le16toh(sc->rev);
1288
	    sc->type);
1344
	DPRINTF(sc, WPI_DEBUG_EEPROM, "cap=%x rev=%x type=%x\n", sc->cap,
1345
	    sc->rev, sc->type);
1289
1346
1290
	/* Read the regulatory domain (4 ASCII characters.) */
1347
	/* Read the regulatory domain (4 ASCII characters.) */
1291
	WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_DOMAIN, sc->domain,
1348
	WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_DOMAIN, sc->domain,
Lines 1331-1336 Link Here
1331
		nflags |= IEEE80211_CHAN_NOADHOC;
1388
		nflags |= IEEE80211_CHAN_NOADHOC;
1332
	}
1389
	}
1333
1390
1391
	/* XXX HOSTAP uses WPI_MODE_IBSS */
1392
	if (nflags & IEEE80211_CHAN_NOADHOC)
1393
		nflags |= IEEE80211_CHAN_NOHOSTAP;
1394
1334
	return nflags;
1395
	return nflags;
1335
}
1396
}
1336
1397
Lines 1347-1353 Link Here
1347
1408
1348
	for (i = 0; i < band->nchan; i++) {
1409
	for (i = 0; i < band->nchan; i++) {
1349
		if (!(channels[i].flags & WPI_EEPROM_CHAN_VALID)) {
1410
		if (!(channels[i].flags & WPI_EEPROM_CHAN_VALID)) {
1350
			DPRINTF(sc, WPI_DEBUG_HW,
1411
			DPRINTF(sc, WPI_DEBUG_EEPROM,
1351
			    "Channel Not Valid: %d, band %d\n",
1412
			    "Channel Not Valid: %d, band %d\n",
1352
			     band->chan[i],n);
1413
			     band->chan[i],n);
1353
			continue;
1414
			continue;
Lines 1362-1368 Link Here
1362
		c->ic_maxpower = 2*c->ic_maxregpower;
1423
		c->ic_maxpower = 2*c->ic_maxregpower;
1363
1424
1364
		if (n == 0) {	/* 2GHz band */
1425
		if (n == 0) {	/* 2GHz band */
1365
			c->ic_freq = ieee80211_ieee2mhz(chan, IEEE80211_CHAN_G);
1426
			c->ic_freq = ieee80211_ieee2mhz(chan,
1427
			    IEEE80211_CHAN_G);
1428
1366
			/* G =>'s B is supported */
1429
			/* G =>'s B is supported */
1367
			c->ic_flags = IEEE80211_CHAN_B | nflags;
1430
			c->ic_flags = IEEE80211_CHAN_B | nflags;
1368
			c = &ic->ic_channels[ic->ic_nchans++];
1431
			c = &ic->ic_channels[ic->ic_nchans++];
Lines 1369-1375 Link Here
1369
			c[0] = c[-1];
1432
			c[0] = c[-1];
1370
			c->ic_flags = IEEE80211_CHAN_G | nflags;
1433
			c->ic_flags = IEEE80211_CHAN_G | nflags;
1371
		} else {	/* 5GHz band */
1434
		} else {	/* 5GHz band */
1372
			c->ic_freq = ieee80211_ieee2mhz(chan, IEEE80211_CHAN_A);
1435
			c->ic_freq = ieee80211_ieee2mhz(chan,
1436
			    IEEE80211_CHAN_A);
1437
1373
			c->ic_flags = IEEE80211_CHAN_A | nflags;
1438
			c->ic_flags = IEEE80211_CHAN_A | nflags;
1374
		}
1439
		}
1375
1440
Lines 1494-1499 Link Here
1494
	return 0;
1559
	return 0;
1495
}
1560
}
1496
1561
1562
static int
1563
wpi_add_node_entry_adhoc(struct wpi_softc *sc)
1564
{
1565
	int newid = WPI_ID_IBSS_MIN;
1566
1567
	for (; newid <= WPI_ID_IBSS_MAX; newid++) {
1568
		if ((sc->nodesmsk & (1 << newid)) == 0) {
1569
			sc->nodesmsk |= 1 << newid;
1570
			return newid;
1571
		}
1572
	}
1573
1574
	return WPI_ID_UNDEFINED;
1575
}
1576
1577
static __inline int
1578
wpi_add_node_entry_sta(struct wpi_softc *sc)
1579
{
1580
	sc->nodesmsk |= 1 << WPI_ID_BSS;
1581
1582
	return WPI_ID_BSS;
1583
}
1584
1585
static __inline int
1586
wpi_check_node_entry(struct wpi_softc *sc, uint8_t id)
1587
{
1588
	if (id == WPI_ID_UNDEFINED)
1589
		return 0;
1590
1591
	return (sc->nodesmsk >> id) & 1;
1592
}
1593
1594
static __inline void
1595
wpi_clear_node_table(struct wpi_softc *sc)
1596
{
1597
	sc->nodesmsk = 0;
1598
}
1599
1600
static __inline void
1601
wpi_del_node_entry(struct wpi_softc *sc, uint8_t id)
1602
{
1603
	sc->nodesmsk &= ~(1 << id);
1604
}
1605
1497
static struct ieee80211_node *
1606
static struct ieee80211_node *
1498
wpi_node_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN])
1607
wpi_node_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN])
1499
{
1608
{
Lines 1515-1529 Link Here
1515
{
1624
{
1516
	struct ieee80211com *ic = ni->ni_ic;
1625
	struct ieee80211com *ic = ni->ni_ic;
1517
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
1626
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
1518
	struct wpi_node *wn = (struct wpi_node *)ni;
1627
	struct wpi_node *wn = WPI_NODE(ni);
1519
1628
1520
	if (wn->id >= WPI_ID_IBSS_MIN && wn->id <= WPI_ID_IBSS_MAX) {
1629
	if (wn->id != WPI_ID_UNDEFINED) {
1521
		free_unr(sc->sc_unr, wn->id);
1630
		WPI_NT_LOCK(sc);
1522
1631
		if (wpi_check_node_entry(sc, wn->id)) {
1523
		WPI_LOCK(sc);
1632
			wpi_del_node_entry(sc, wn->id);
1524
		if (sc->rxon.filter & htole32(WPI_FILTER_BSS))
1525
			wpi_del_node(sc, ni);
1633
			wpi_del_node(sc, ni);
1526
		WPI_UNLOCK(sc);
1634
		}
1635
		WPI_NT_UNLOCK(sc);
1527
	}
1636
	}
1528
1637
1529
	sc->sc_node_free(ni);
1638
	sc->sc_node_free(ni);
Lines 1547-1559 Link Here
1547
		ieee80211_state_name[vap->iv_state],
1656
		ieee80211_state_name[vap->iv_state],
1548
		ieee80211_state_name[nstate]);
1657
		ieee80211_state_name[nstate]);
1549
1658
1550
	IEEE80211_UNLOCK(ic);
1551
	WPI_LOCK(sc);
1552
	switch (nstate) {
1659
	switch (nstate) {
1553
	case IEEE80211_S_SCAN:
1660
	case IEEE80211_S_SCAN:
1554
		if ((vap->iv_opmode == IEEE80211_M_IBSS ||
1661
		WPI_RXON_LOCK(sc);
1555
		    vap->iv_opmode == IEEE80211_M_AHDEMO) &&
1662
		if (sc->rxon.filter & htole32(WPI_FILTER_BSS) &&
1556
		    (sc->rxon.filter & htole32(WPI_FILTER_BSS))) {
1663
		    vap->iv_opmode != IEEE80211_M_STA) {
1557
			sc->rxon.filter &= ~htole32(WPI_FILTER_BSS);
1664
			sc->rxon.filter &= ~htole32(WPI_FILTER_BSS);
1558
			if ((error = wpi_send_rxon(sc, 0, 1)) != 0) {
1665
			if ((error = wpi_send_rxon(sc, 0, 1)) != 0) {
1559
				device_printf(sc->sc_dev,
1666
				device_printf(sc->sc_dev,
Lines 1560-1565 Link Here
1560
				    "%s: could not send RXON\n", __func__);
1667
				    "%s: could not send RXON\n", __func__);
1561
			}
1668
			}
1562
		}
1669
		}
1670
		WPI_RXON_UNLOCK(sc);
1563
		break;
1671
		break;
1564
1672
1565
	case IEEE80211_S_ASSOC:
1673
	case IEEE80211_S_ASSOC:
Lines 1584-1590 Link Here
1584
		 * RUN -> RUN transition; Just restart the timers.
1692
		 * RUN -> RUN transition; Just restart the timers.
1585
		 */
1693
		 */
1586
		if (vap->iv_state == IEEE80211_S_RUN) {
1694
		if (vap->iv_state == IEEE80211_S_RUN) {
1695
			WPI_RXON_LOCK(sc);
1587
			wpi_calib_timeout(sc);
1696
			wpi_calib_timeout(sc);
1697
			WPI_RXON_UNLOCK(sc);
1588
			break;
1698
			break;
1589
		}
1699
		}
1590
1700
Lines 1602-1609 Link Here
1602
	default:
1712
	default:
1603
		break;
1713
		break;
1604
	}
1714
	}
1605
	WPI_UNLOCK(sc);
1606
	IEEE80211_LOCK(ic);
1607
	if (error != 0) {
1715
	if (error != 0) {
1608
		DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
1716
		DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
1609
		return error;
1717
		return error;
Lines 1611-1617 Link Here
1611
1719
1612
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
1720
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
1613
1721
1614
	return wvp->newstate(vap, nstate, arg);
1722
	return wvp->wv_newstate(vap, nstate, arg);
1615
}
1723
}
1616
1724
1617
static void
1725
static void
Lines 1618-1628 Link Here
1618
wpi_calib_timeout(void *arg)
1726
wpi_calib_timeout(void *arg)
1619
{
1727
{
1620
	struct wpi_softc *sc = arg;
1728
	struct wpi_softc *sc = arg;
1621
	struct ifnet *ifp = sc->sc_ifp;
1622
	struct ieee80211com *ic = ifp->if_l2com;
1623
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
1624
1729
1625
	if (vap->iv_state != IEEE80211_S_RUN)
1730
	if (!(sc->rxon.filter & htole32(WPI_FILTER_BSS)))
1626
		return;
1731
		return;
1627
1732
1628
	wpi_power_calibration(sc);
1733
	wpi_power_calibration(sc);
Lines 1678-1684 Link Here
1678
    struct wpi_rx_data *data)
1783
    struct wpi_rx_data *data)
1679
{
1784
{
1680
	struct ifnet *ifp = sc->sc_ifp;
1785
	struct ifnet *ifp = sc->sc_ifp;
1681
	const struct ieee80211_cipher *cip = NULL;
1682
	struct ieee80211com *ic = ifp->if_l2com;
1786
	struct ieee80211com *ic = ifp->if_l2com;
1683
	struct wpi_rx_ring *ring = &sc->rxq;
1787
	struct wpi_rx_ring *ring = &sc->rxq;
1684
	struct wpi_rx_stat *stat;
1788
	struct wpi_rx_stat *stat;
Lines 1766-1781 Link Here
1766
1870
1767
	/* Grab a reference to the source node. */
1871
	/* Grab a reference to the source node. */
1768
	wh = mtod(m, struct ieee80211_frame *);
1872
	wh = mtod(m, struct ieee80211_frame *);
1769
	ni = ieee80211_find_rxnode(ic, (struct ieee80211_frame_min *)wh);
1770
1873
1771
	if (ni != NULL)
1772
		cip = ni->ni_ucastkey.wk_cipher;
1773
	if ((wh->i_fc[1] & IEEE80211_FC1_PROTECTED) &&
1874
	if ((wh->i_fc[1] & IEEE80211_FC1_PROTECTED) &&
1774
	    !IEEE80211_IS_MULTICAST(wh->i_addr1) &&
1875
	    (flags & WPI_RX_CIPHER_MASK) == WPI_RX_CIPHER_CCMP) {
1775
	    cip != NULL && cip->ic_cipher == IEEE80211_CIPHER_AES_CCM) {
1776
		if ((flags & WPI_RX_CIPHER_MASK) != WPI_RX_CIPHER_CCMP)
1777
			goto fail2;
1778
1779
		/* Check whether decryption was successful or not. */
1876
		/* Check whether decryption was successful or not. */
1780
		if ((flags & WPI_RX_DECRYPT_MASK) != WPI_RX_DECRYPT_OK) {
1877
		if ((flags & WPI_RX_DECRYPT_MASK) != WPI_RX_DECRYPT_OK) {
1781
			DPRINTF(sc, WPI_DEBUG_RECV,
1878
			DPRINTF(sc, WPI_DEBUG_RECV,
Lines 1785-1790 Link Here
1785
		m->m_flags |= M_WEP;
1882
		m->m_flags |= M_WEP;
1786
	}
1883
	}
1787
1884
1885
	ni = ieee80211_find_rxnode(ic, (struct ieee80211_frame_min *)wh);
1886
1788
	if (ieee80211_radiotap_active(ic)) {
1887
	if (ieee80211_radiotap_active(ic)) {
1789
		struct wpi_rx_radiotap_header *tap = &sc->sc_rxtap;
1888
		struct wpi_rx_radiotap_header *tap = &sc->sc_rxtap;
1790
1889
Lines 1791-1819 Link Here
1791
		tap->wr_flags = 0;
1890
		tap->wr_flags = 0;
1792
		if (head->flags & htole16(WPI_STAT_FLAG_SHPREAMBLE))
1891
		if (head->flags & htole16(WPI_STAT_FLAG_SHPREAMBLE))
1793
			tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
1892
			tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
1794
		tap->wr_dbm_antsignal = (int8_t)(stat->rssi - WPI_RSSI_OFFSET);
1893
		tap->wr_dbm_antsignal = (int8_t)(stat->rssi + WPI_RSSI_OFFSET);
1795
		tap->wr_dbm_antnoise = (int8_t)le16toh(stat->noise);
1894
		tap->wr_dbm_antnoise = WPI_RSSI_OFFSET;
1796
		tap->wr_tsft = tail->tstamp;
1895
		tap->wr_tsft = tail->tstamp;
1797
		tap->wr_antenna = (le16toh(head->flags) >> 4) & 0xf;
1896
		tap->wr_antenna = (le16toh(head->flags) >> 4) & 0xf;
1798
		tap->wr_rate = plcp2rate(head->plcp);
1897
		tap->wr_rate = plcp2rate(head->plcp);
1799
	}
1898
	}
1800
1899
1801
	WPI_UNLOCK(sc);
1802
1803
	/* Send the frame to the 802.11 layer. */
1900
	/* Send the frame to the 802.11 layer. */
1804
	if (ni != NULL) {
1901
	if (ni != NULL) {
1805
		(void)ieee80211_input(ni, m, stat->rssi, -WPI_RSSI_OFFSET);
1902
		(void)ieee80211_input(ni, m, stat->rssi, WPI_RSSI_OFFSET);
1806
		/* Node is no longer needed. */
1903
		/* Node is no longer needed. */
1807
		ieee80211_free_node(ni);
1904
		ieee80211_free_node(ni);
1808
	} else
1905
	} else
1809
		(void)ieee80211_input_all(ic, m, stat->rssi, -WPI_RSSI_OFFSET);
1906
		(void)ieee80211_input_all(ic, m, stat->rssi, WPI_RSSI_OFFSET);
1810
1907
1811
	WPI_LOCK(sc);
1812
1813
	return;
1908
	return;
1814
1909
1815
fail2:	ieee80211_free_node(ni);
1910
fail2:	m_freem(m);
1816
	m_freem(m);
1817
1911
1818
fail1:	if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1912
fail1:	if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1819
}
1913
}
Lines 1835-1844 Link Here
1835
	struct mbuf *m;
1929
	struct mbuf *m;
1836
	struct ieee80211_node *ni;
1930
	struct ieee80211_node *ni;
1837
	struct ieee80211vap *vap;
1931
	struct ieee80211vap *vap;
1838
	int ackfailcnt = stat->ackfailcnt;
1932
	struct ieee80211com *ic;
1839
	int status = le32toh(stat->status);
1933
	uint32_t queued, status = le32toh(stat->status);
1934
	int ackfailcnt = stat->ackfailcnt / 2;	/* wpi_mrr_setup() */
1840
1935
1841
	KASSERT(data->ni != NULL, ("no node"));
1936
	KASSERT(data->ni != NULL, ("no node"));
1937
	KASSERT(data->m != NULL, ("no mbuf"));
1842
1938
1843
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
1939
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
1844
1940
Lines 1853-1863 Link Here
1853
	m = data->m, data->m = NULL;
1949
	m = data->m, data->m = NULL;
1854
	ni = data->ni, data->ni = NULL;
1950
	ni = data->ni, data->ni = NULL;
1855
	vap = ni->ni_vap;
1951
	vap = ni->ni_vap;
1952
	ic = vap->iv_ic;
1856
1953
1954
	queued = atomic_fetchadd_32(&ring->queued, -1);
1955
	atomic_store_rel_32(&sc->sc_tx_timer, 0);
1956
1857
	/*
1957
	/*
1858
	 * Update rate control statistics for the node.
1958
	 * Update rate control statistics for the node.
1859
	 */
1959
	 */
1860
	WPI_UNLOCK(sc);
1861
	if ((status & 0xff) != 1) {
1960
	if ((status & 0xff) != 1) {
1862
		if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1961
		if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1863
		ieee80211_ratectl_tx_complete(vap, ni,
1962
		ieee80211_ratectl_tx_complete(vap, ni,
Lines 1869-1885 Link Here
1869
	}
1968
	}
1870
1969
1871
	ieee80211_tx_complete(ni, m, (status & 0xff) != 1);
1970
	ieee80211_tx_complete(ni, m, (status & 0xff) != 1);
1872
	WPI_LOCK(sc);
1873
1971
1874
	sc->sc_tx_timer = 0;
1972
	IF_LOCK(&ifp->if_snd);
1875
	if (--ring->queued < WPI_TX_RING_LOMARK) {
1973
	if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) &&
1876
		sc->qfullmsk &= ~(1 << ring->qid);
1974
	     queued <= WPI_TX_RING_LOMARK) {
1877
		if (sc->qfullmsk == 0 &&
1975
		IF_UNLOCK(&ifp->if_snd);
1878
		    (ifp->if_drv_flags & IFF_DRV_OACTIVE)) {
1976
1977
		if (atomic_load_acq_32(&sc->qfullmsk) != 0) {
1978
			WPI_TXQ_LOCK(sc);
1979
			queued = atomic_load_acq_32(&ring->queued);
1980
			if (queued < WPI_TX_RING_LOMARK)
1981
				atomic_clear_32(&sc->qfullmsk, 1 << ring->qid);
1982
			WPI_TXQ_UNLOCK(sc);
1983
		}
1984
1985
		if (atomic_load_acq_32(&sc->qfullmsk) == 0) {
1986
			IF_LOCK(&ifp->if_snd);
1879
			ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1987
			ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1880
			wpi_start_locked(ifp);
1988
			IF_UNLOCK(&ifp->if_snd);
1989
			ieee80211_runtask(ic, &sc->sc_start_task);
1881
		}
1990
		}
1882
	}
1991
	} else
1992
		IF_UNLOCK(&ifp->if_snd);
1883
1993
1884
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
1994
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
1885
}
1995
}
Lines 1891-1905 Link Here
1891
static void
2001
static void
1892
wpi_cmd_done(struct wpi_softc *sc, struct wpi_rx_desc *desc)
2002
wpi_cmd_done(struct wpi_softc *sc, struct wpi_rx_desc *desc)
1893
{
2003
{
1894
	struct wpi_tx_ring *ring = &sc->txq[4];
2004
	struct wpi_tx_ring *ring = &sc->txq[WPI_CMD_QUEUE_NUM];
1895
	struct wpi_tx_data *data;
2005
	struct wpi_tx_data *data;
1896
2006
1897
	DPRINTF(sc, WPI_DEBUG_CMD, "cmd notification qid=%x idx=%d flags=%x "
2007
	DPRINTF(sc, WPI_DEBUG_CMD, "cmd notification qid %x idx %d flags %x "
1898
				   "type=%s len=%d\n", desc->qid, desc->idx,
2008
				   "type %s len %d\n", desc->qid, desc->idx,
1899
				   desc->flags, wpi_cmd_str(desc->type),
2009
				   desc->flags, wpi_cmd_str(desc->type),
1900
				   le32toh(desc->len));
2010
				   le32toh(desc->len));
1901
2011
1902
	if ((desc->qid & 7) != 4)
2012
	if ((desc->qid & WPI_RX_DESC_QID_MSK) != WPI_CMD_QUEUE_NUM)
1903
		return;	/* Not a command ack. */
2013
		return;	/* Not a command ack. */
1904
2014
1905
	data = &ring->data[desc->idx];
2015
	data = &ring->data[desc->idx];
Lines 1913-1919 Link Here
1913
		data->m = NULL;
2023
		data->m = NULL;
1914
	}
2024
	}
1915
2025
1916
	sc->flags &= ~WPI_FLAG_BUSY;
1917
	wakeup(&ring->cmd[desc->idx]);
2026
	wakeup(&ring->cmd[desc->idx]);
1918
}
2027
}
1919
2028
Lines 1946-1953 Link Here
1946
		    __func__, sc->rxq.cur, desc->qid, desc->idx, desc->flags,
2055
		    __func__, sc->rxq.cur, desc->qid, desc->idx, desc->flags,
1947
		    desc->type, wpi_cmd_str(desc->type), le32toh(desc->len));
2056
		    desc->type, wpi_cmd_str(desc->type), le32toh(desc->len));
1948
2057
1949
		if (!(desc->qid & 0x80))	/* Reply to a command. */
2058
		if (!(desc->qid & WPI_UNSOLICITED_RX_NOTIF)) {
2059
			/* Reply to a command. */
1950
			wpi_cmd_done(sc, desc);
2060
			wpi_cmd_done(sc, desc);
2061
		}
1951
2062
1952
		switch (desc->type) {
2063
		switch (desc->type) {
1953
		case WPI_RX_DONE:
2064
		case WPI_RX_DONE:
Lines 1980-1992 Link Here
1980
			    le32toh(miss->total));
2091
			    le32toh(miss->total));
1981
2092
1982
			if (vap->iv_state == IEEE80211_S_RUN &&
2093
			if (vap->iv_state == IEEE80211_S_RUN &&
1983
			    (ic->ic_flags & IEEE80211_S_SCAN) == 0) {
2094
			    (ic->ic_flags & IEEE80211_F_SCAN) == 0 &&
1984
				if (misses >=  vap->iv_bmissthreshold) {
2095
			    misses >= vap->iv_bmissthreshold)
1985
					WPI_UNLOCK(sc);
2096
				ieee80211_beacon_miss(ic);
1986
					ieee80211_beacon_miss(ic);
2097
1987
					WPI_LOCK(sc);
1988
				}
1989
			}
1990
			break;
2098
			break;
1991
		}
2099
		}
1992
		case WPI_UC_READY:
2100
		case WPI_UC_READY:
Lines 2013-2020 Link Here
2013
		}
2121
		}
2014
		case WPI_STATE_CHANGED:
2122
		case WPI_STATE_CHANGED:
2015
		{
2123
		{
2016
                        bus_dmamap_sync(sc->rxq.data_dmat, data->map,
2124
			bus_dmamap_sync(sc->rxq.data_dmat, data->map,
2017
                            BUS_DMASYNC_POSTREAD);
2125
			    BUS_DMASYNC_POSTREAD);
2018
2126
2019
			uint32_t *status = (uint32_t *)(desc + 1);
2127
			uint32_t *status = (uint32_t *)(desc + 1);
2020
2128
Lines 2022-2027 Link Here
2022
			    le32toh(*status));
2130
			    le32toh(*status));
2023
2131
2024
			if (le32toh(*status) & 1) {
2132
			if (le32toh(*status) & 1) {
2133
				WPI_NT_LOCK(sc);
2134
				wpi_clear_node_table(sc);
2135
				WPI_NT_UNLOCK(sc);
2025
				ieee80211_runtask(ic, &sc->sc_radiooff_task);
2136
				ieee80211_runtask(ic, &sc->sc_radiooff_task);
2026
				return;
2137
				return;
2027
			}
2138
			}
Lines 2051-2060 Link Here
2051
			    "scan finished nchan=%d status=%d chan=%d\n",
2162
			    "scan finished nchan=%d status=%d chan=%d\n",
2052
			    scan->nchan, scan->status, scan->chan);
2163
			    scan->nchan, scan->status, scan->chan);
2053
#endif
2164
#endif
2054
			sc->sc_scan_timer = 0;
2165
			atomic_store_rel_32(&sc->sc_scan_timer, 0);
2055
			WPI_UNLOCK(sc);
2056
			ieee80211_scan_next(vap);
2166
			ieee80211_scan_next(vap);
2057
			WPI_LOCK(sc);
2058
			break;
2167
			break;
2059
		}
2168
		}
2060
		}
2169
		}
Lines 2068-2074 Link Here
2068
 * Process an INT_WAKEUP interrupt raised when the microcontroller wakes up
2177
 * Process an INT_WAKEUP interrupt raised when the microcontroller wakes up
2069
 * from power-down sleep mode.
2178
 * from power-down sleep mode.
2070
 */
2179
 */
2071
static void     
2180
static void
2072
wpi_wakeup_intr(struct wpi_softc *sc)
2181
wpi_wakeup_intr(struct wpi_softc *sc)
2073
{
2182
{
2074
	int qid;
2183
	int qid;
Lines 2077-2099 Link Here
2077
	    "%s: ucode wakeup from power-down sleep\n", __func__);
2186
	    "%s: ucode wakeup from power-down sleep\n", __func__);
2078
2187
2079
	/* Wakeup RX and TX rings. */
2188
	/* Wakeup RX and TX rings. */
2080
	if (sc->rxq.update) {
2189
	if (sc->rxq.update != 0) {
2081
		sc->rxq.update = 0;
2190
		sc->rxq.update = 0;
2082
		wpi_update_rx_ring(sc);
2191
		wpi_update_rx_ring(sc);
2083
	}
2192
	}
2084
	for (qid = 0; qid < WPI_NTXQUEUES; qid++) {
2193
2194
	WPI_TXQ_LOCK(sc);
2195
	for (qid = 0; qid < WPI_DRV_NTXQUEUES; qid++) {
2085
		struct wpi_tx_ring *ring = &sc->txq[qid];
2196
		struct wpi_tx_ring *ring = &sc->txq[qid];
2086
2197
2087
		if (ring->update) {
2198
		if (ring->update != 0) {
2088
			ring->update = 0;
2199
			ring->update = 0;
2089
			wpi_update_tx_ring(sc, ring);
2200
			wpi_update_tx_ring(sc, ring);
2090
		}
2201
		}
2091
	}
2202
	}
2203
	WPI_TXQ_UNLOCK(sc);
2092
2204
2093
	WPI_CLRBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ);
2205
	WPI_CLRBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ);
2094
}
2206
}
2095
2207
2096
/*
2208
/*
2209
 * This function prints firmware registers
2210
 */
2211
#ifdef WPI_DEBUG
2212
static void
2213
wpi_debug_registers(struct wpi_softc *sc)
2214
{
2215
#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
2216
	int i;
2217
	static const uint32_t csr_tbl[] = {
2218
		WPI_HW_IF_CONFIG,
2219
		WPI_INT,
2220
		WPI_INT_MASK,
2221
		WPI_FH_INT,
2222
		WPI_GPIO_IN,
2223
		WPI_RESET,
2224
		WPI_GP_CNTRL,
2225
		WPI_EEPROM,
2226
		WPI_EEPROM_GP,
2227
		WPI_GIO,
2228
		WPI_UCODE_GP1,
2229
		WPI_UCODE_GP2,
2230
		WPI_GIO_CHICKEN,
2231
		WPI_ANA_PLL,
2232
		WPI_DBG_HPET_MEM,
2233
	};
2234
	static const uint32_t prph_tbl[] = {
2235
		WPI_APMG_CLK_CTRL,
2236
		WPI_APMG_PS,
2237
		WPI_APMG_PCI_STT,
2238
		WPI_APMG_RFKILL,
2239
	};
2240
	/* Undocumented */
2241
	static const uint32_t prph2_tbl[] = {
2242
		0x302c,
2243
		0x3044,
2244
		0x3048,
2245
		0x3050,
2246
		0x3054,
2247
		0x3080,
2248
		0x3084,
2249
	};
2250
2251
	DPRINTF(sc, WPI_DEBUG_REGISTER,"%s","\n");
2252
2253
	for (i = 0; i <  COUNTOF(csr_tbl); i++) {
2254
		DPRINTF(sc, WPI_DEBUG_REGISTER, "  %-18s: 0x%08x ",
2255
		    wpi_get_csr_string(csr_tbl[i]), WPI_READ(sc, csr_tbl[i]));
2256
2257
		if ((i + 1) % 2 == 0)
2258
			DPRINTF(sc, WPI_DEBUG_REGISTER, "\n");
2259
	}
2260
	DPRINTF(sc, WPI_DEBUG_REGISTER, "\n\n");
2261
2262
	if (wpi_nic_lock(sc) == 0) {
2263
		for (i = 0; i < COUNTOF(prph_tbl); i++) {
2264
			DPRINTF(sc, WPI_DEBUG_REGISTER, "  %-18s: 0x%08x ",
2265
			    wpi_get_prph_string(prph_tbl[i]),
2266
			    wpi_prph_read(sc, prph_tbl[i]));
2267
2268
			if ((i + 1) % 2 == 0)
2269
				DPRINTF(sc, WPI_DEBUG_REGISTER, "\n");
2270
		}
2271
		DPRINTF(sc, WPI_DEBUG_REGISTER, "\n");
2272
2273
		for (i = 0; i < COUNTOF(prph2_tbl); i++) {
2274
			DPRINTF(sc, WPI_DEBUG_REGISTER, "  0x%04x: 0x%08x ",
2275
			    prph2_tbl[i], wpi_prph_read(sc, prph2_tbl[i]));
2276
2277
			if ((i + 1) % 3 == 0)
2278
				DPRINTF(sc, WPI_DEBUG_REGISTER, "\n");
2279
		}
2280
		DPRINTF(sc, WPI_DEBUG_REGISTER, "\n\n");
2281
		wpi_nic_unlock(sc);
2282
	} else {
2283
		DPRINTF(sc, WPI_DEBUG_REGISTER,
2284
		    "Cannot access internal registers.\n");
2285
	}
2286
#undef COUNTOF
2287
}
2288
#endif
2289
2290
/*
2097
 * Dump the error log of the firmware when a firmware panic occurs.  Although
2291
 * Dump the error log of the firmware when a firmware panic occurs.  Although
2098
 * we can't debug the firmware because it is neither open source nor free, it
2292
 * we can't debug the firmware because it is neither open source nor free, it
2099
 * can help us to identify certain classes of problems.
2293
 * can help us to identify certain classes of problems.
Lines 2112-2123 Link Here
2112
	    WPI_FW_DATA_BASE + WPI_FW_DATA_MAXSZ) {
2306
	    WPI_FW_DATA_BASE + WPI_FW_DATA_MAXSZ) {
2113
		printf("%s: bad firmware error log address 0x%08x\n", __func__,
2307
		printf("%s: bad firmware error log address 0x%08x\n", __func__,
2114
		    sc->errptr);
2308
		    sc->errptr);
2115
                return;
2309
		return;
2116
        }
2310
	}
2117
	if (wpi_nic_lock(sc) != 0) {
2311
	if (wpi_nic_lock(sc) != 0) {
2118
		printf("%s: could not read firmware error log\n", __func__);
2312
		printf("%s: could not read firmware error log\n", __func__);
2119
                return;
2313
		return;
2120
        }
2314
	}
2121
	/* Read number of entries in the log. */
2315
	/* Read number of entries in the log. */
2122
	count = wpi_mem_read(sc, sc->errptr);
2316
	count = wpi_mem_read(sc, sc->errptr);
2123
	if (count == 0 || count * sizeof (dump) > WPI_FW_DATA_MAXSZ) {
2317
	if (count == 0 || count * sizeof (dump) > WPI_FW_DATA_MAXSZ) {
Lines 2150-2160 Link Here
2150
	wpi_nic_unlock(sc);
2344
	wpi_nic_unlock(sc);
2151
	/* Dump driver status (TX and RX rings) while we're here. */
2345
	/* Dump driver status (TX and RX rings) while we're here. */
2152
	printf("driver status:\n");
2346
	printf("driver status:\n");
2153
	for (i = 0; i < WPI_NTXQUEUES; i++) {
2347
	WPI_TXQ_LOCK(sc);
2348
	for (i = 0; i < WPI_DRV_NTXQUEUES; i++) {
2154
		struct wpi_tx_ring *ring = &sc->txq[i];
2349
		struct wpi_tx_ring *ring = &sc->txq[i];
2155
		printf("  tx ring %2d: qid=%-2d cur=%-3d queued=%-3d\n",
2350
		printf("  tx ring %2d: qid=%-2d cur=%-3d queued=%-3d\n",
2156
		    i, ring->qid, ring->cur, ring->queued);
2351
		    i, ring->qid, ring->cur, ring->queued);
2157
	}
2352
	}
2353
	WPI_TXQ_UNLOCK(sc);
2158
	printf("  rx ring: cur=%d\n", sc->rxq.cur);
2354
	printf("  rx ring: cur=%d\n", sc->rxq.cur);
2159
}
2355
}
2160
2356
Lines 2172-2181 Link Here
2172
2368
2173
	r1 = WPI_READ(sc, WPI_INT);
2369
	r1 = WPI_READ(sc, WPI_INT);
2174
2370
2175
	if (r1 == 0xffffffff || (r1 & 0xfffffff0) == 0xa5a5a5a0) {
2371
	if (r1 == 0xffffffff || (r1 & 0xfffffff0) == 0xa5a5a5a0)
2176
		WPI_UNLOCK(sc);
2372
		goto end;	/* Hardware gone! */
2177
		return;	/* Hardware gone! */
2178
	}
2179
2373
2180
	r2 = WPI_READ(sc, WPI_FH_INT);
2374
	r2 = WPI_READ(sc, WPI_FH_INT);
2181
2375
Lines 2193-2206 Link Here
2193
		struct ieee80211com *ic = ifp->if_l2com;
2387
		struct ieee80211com *ic = ifp->if_l2com;
2194
2388
2195
		device_printf(sc->sc_dev, "fatal firmware error\n");
2389
		device_printf(sc->sc_dev, "fatal firmware error\n");
2390
#ifdef WPI_DEBUG
2391
		wpi_debug_registers(sc);
2392
#endif
2196
		wpi_fatal_intr(sc);
2393
		wpi_fatal_intr(sc);
2197
		DPRINTF(sc, WPI_DEBUG_HW,
2394
		DPRINTF(sc, WPI_DEBUG_HW,
2198
		    "(%s)\n", (r1 & WPI_INT_SW_ERR) ? "(Software Error)" :
2395
		    "(%s)\n", (r1 & WPI_INT_SW_ERR) ? "(Software Error)" :
2199
		    "(Hardware Error)");
2396
		    "(Hardware Error)");
2200
		ieee80211_runtask(ic, &sc->sc_reinittask);
2397
		ieee80211_runtask(ic, &sc->sc_reinittask);
2201
		sc->flags &= ~WPI_FLAG_BUSY;
2398
		goto end;
2202
		WPI_UNLOCK(sc);
2203
		return;
2204
	}
2399
	}
2205
2400
2206
	if ((r1 & (WPI_INT_FH_RX | WPI_INT_SW_RX)) ||
2401
	if ((r1 & (WPI_INT_FH_RX | WPI_INT_SW_RX)) ||
Lines 2218-2231 Link Here
2218
	if (ifp->if_flags & IFF_UP)
2413
	if (ifp->if_flags & IFF_UP)
2219
		WPI_WRITE(sc, WPI_INT_MASK, WPI_INT_MASK_DEF);
2414
		WPI_WRITE(sc, WPI_INT_MASK, WPI_INT_MASK_DEF);
2220
2415
2221
	WPI_UNLOCK(sc);
2416
end:	WPI_UNLOCK(sc);
2222
}
2417
}
2223
2418
2224
static int
2419
static int
2225
wpi_cmd2(struct wpi_softc *sc, struct wpi_buf *buf)
2420
wpi_cmd2(struct wpi_softc *sc, struct wpi_buf *buf, int count)
2226
{
2421
{
2227
	struct ifnet *ifp = sc->sc_ifp;
2228
	struct ieee80211com *ic = ifp->if_l2com;
2229
	struct ieee80211_frame *wh;
2422
	struct ieee80211_frame *wh;
2230
	struct wpi_tx_cmd *cmd;
2423
	struct wpi_tx_cmd *cmd;
2231
	struct wpi_tx_data *data;
2424
	struct wpi_tx_data *data;
Lines 2233-2252 Link Here
2233
	struct wpi_tx_ring *ring;
2426
	struct wpi_tx_ring *ring;
2234
	struct mbuf *m1;
2427
	struct mbuf *m1;
2235
	bus_dma_segment_t *seg, segs[WPI_MAX_SCATTER];
2428
	bus_dma_segment_t *seg, segs[WPI_MAX_SCATTER];
2236
	int error, i, hdrspace, nsegs, totlen;
2429
	int error, i, hdrlen, nsegs, totlen, pad;
2237
2430
2238
	WPI_LOCK_ASSERT(sc);
2431
	WPI_TXQ_LOCK(sc);
2239
2432
2240
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
2433
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
2241
2434
2435
	if (atomic_load_acq_32(&sc->txq_active) == 0) {
2436
		error = ENETDOWN;
2437
		goto fail;
2438
	}
2439
2242
	wh = mtod(buf->m, struct ieee80211_frame *);
2440
	wh = mtod(buf->m, struct ieee80211_frame *);
2243
	hdrspace = ieee80211_anyhdrspace(ic, wh);
2441
	hdrlen = ieee80211_anyhdrsize(wh);
2244
	totlen = buf->m->m_pkthdr.len;
2442
	totlen = buf->m->m_pkthdr.len;
2245
2443
2444
	if (hdrlen & 3) {
2445
		/* First segment length must be a multiple of 4. */
2446
		pad = 4 - (hdrlen & 3);
2447
	} else
2448
		pad = 0;
2449
2246
	ring = &sc->txq[buf->ac];
2450
	ring = &sc->txq[buf->ac];
2247
	desc = &ring->desc[ring->cur];
2451
	desc = &ring->desc[ring->cur];
2248
	data = &ring->data[ring->cur];
2452
	data = &ring->data[ring->cur];
2249
2453
2454
	if (atomic_load_acq_32(&ring->queued) > WPI_TX_RING_HIMARK) {
2455
		error = ENOMEM;
2456
		goto fail;
2457
	}
2458
2250
	/* Prepare TX firmware command. */
2459
	/* Prepare TX firmware command. */
2251
	cmd = &ring->cmd[ring->cur];
2460
	cmd = &ring->cmd[ring->cur];
2252
	cmd->code = buf->code;
2461
	cmd->code = buf->code;
Lines 2257-2264 Link Here
2257
	memcpy(cmd->data, buf->data, buf->size);
2466
	memcpy(cmd->data, buf->data, buf->size);
2258
2467
2259
	/* Save and trim IEEE802.11 header. */
2468
	/* Save and trim IEEE802.11 header. */
2260
	memcpy((uint8_t *)(cmd->data + buf->size), wh, hdrspace);
2469
	memcpy((uint8_t *)(cmd->data + buf->size), wh, hdrlen);
2261
	m_adj(buf->m, hdrspace);
2470
	m_adj(buf->m, hdrlen);
2262
2471
2263
	error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, buf->m,
2472
	error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, buf->m,
2264
	    segs, &nsegs, BUS_DMA_NOWAIT);
2473
	    segs, &nsegs, BUS_DMA_NOWAIT);
Lines 2265-2272 Link Here
2265
	if (error != 0 && error != EFBIG) {
2474
	if (error != 0 && error != EFBIG) {
2266
		device_printf(sc->sc_dev,
2475
		device_printf(sc->sc_dev,
2267
		    "%s: can't map mbuf (error %d)\n", __func__, error);
2476
		    "%s: can't map mbuf (error %d)\n", __func__, error);
2268
		m_freem(buf->m);
2477
		goto fail;
2269
		return error;
2270
	}
2478
	}
2271
	if (error != 0) {
2479
	if (error != 0) {
2272
		/* Too many DMA segments, linearize mbuf. */
2480
		/* Too many DMA segments, linearize mbuf. */
Lines 2274-2281 Link Here
2274
		if (m1 == NULL) {
2482
		if (m1 == NULL) {
2275
			device_printf(sc->sc_dev,
2483
			device_printf(sc->sc_dev,
2276
			    "%s: could not defrag mbuf\n", __func__);
2484
			    "%s: could not defrag mbuf\n", __func__);
2277
			m_freem(buf->m);
2485
			error = ENOBUFS;
2278
			return ENOBUFS;
2486
			goto fail;
2279
		}
2487
		}
2280
		buf->m = m1;
2488
		buf->m = m1;
2281
2489
Lines 2283-2291 Link Here
2283
		    buf->m, segs, &nsegs, BUS_DMA_NOWAIT);
2491
		    buf->m, segs, &nsegs, BUS_DMA_NOWAIT);
2284
		if (error != 0) {
2492
		if (error != 0) {
2285
			device_printf(sc->sc_dev,
2493
			device_printf(sc->sc_dev,
2286
			    "%s: can't map mbuf (error %d)\n", __func__, error);
2494
			    "%s: can't map mbuf (error %d)\n", __func__,
2287
			m_freem(buf->m);
2495
			    error);
2288
			return error;
2496
			goto fail;
2289
		}
2497
		}
2290
	}
2498
	}
2291
2499
Lines 2296-2305 Link Here
2296
	    __func__, ring->qid, ring->cur, totlen, nsegs);
2504
	    __func__, ring->qid, ring->cur, totlen, nsegs);
2297
2505
2298
	/* Fill TX descriptor. */
2506
	/* Fill TX descriptor. */
2299
	desc->nsegs = WPI_PAD32(totlen) << 4 | (1 + nsegs);
2507
	desc->nsegs = WPI_PAD32(totlen + pad) << 4 | (1 + nsegs);
2508
2300
	/* First DMA segment is used by the TX command. */
2509
	/* First DMA segment is used by the TX command. */
2301
	desc->segs[0].addr = htole32(data->cmd_paddr);
2510
	desc->segs[0].addr = htole32(data->cmd_paddr);
2302
	desc->segs[0].len  = htole32(4 + buf->size + hdrspace);
2511
	desc->segs[0].len  = htole32(4 + buf->size + hdrlen + pad);
2303
	/* Other DMA segments are for data payload. */
2512
	/* Other DMA segments are for data payload. */
2304
	seg = &segs[0];
2513
	seg = &segs[0];
2305
	for (i = 1; i <= nsegs; i++) {
2514
	for (i = 1; i <= nsegs; i++) {
Lines 2318-2330 Link Here
2318
	ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT;
2527
	ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT;
2319
	wpi_update_tx_ring(sc, ring);
2528
	wpi_update_tx_ring(sc, ring);
2320
2529
2321
	/* Mark TX ring as full if we reach a certain threshold. */
2530
	if (ring->qid < WPI_CMD_QUEUE_NUM) {
2322
	if (++ring->queued > WPI_TX_RING_HIMARK)
2531
		int diff = WPI_TX_RING_HIMARK - count;
2323
		sc->qfullmsk |= 1 << ring->qid;
2324
2532
2533
		/* Mark TX ring as full if we reach a certain threshold. */
2534
		if (atomic_fetchadd_32(&ring->queued, count) > diff)
2535
			atomic_set_32(&sc->qfullmsk, 1 << ring->qid);
2536
2537
		atomic_store_rel_32(&sc->sc_tx_timer, 5);
2538
	}
2539
2540
	WPI_TXQ_UNLOCK(sc);
2541
2325
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
2542
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
2326
2543
2327
	return 0;
2544
	return 0;
2545
2546
fail:	WPI_TXQ_UNLOCK(sc);
2547
2548
	m_freem(buf->m);
2549
2550
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
2551
2552
	return error;
2328
}
2553
}
2329
2554
2330
/*
2555
/*
Lines 2336-2354 Link Here
2336
	const struct ieee80211_txparam *tp;
2561
	const struct ieee80211_txparam *tp;
2337
	struct ieee80211vap *vap = ni->ni_vap;
2562
	struct ieee80211vap *vap = ni->ni_vap;
2338
	struct ieee80211com *ic = ni->ni_ic;
2563
	struct ieee80211com *ic = ni->ni_ic;
2339
	struct wpi_node *wn = (void *)ni;
2564
	struct wpi_node *wn = WPI_NODE(ni);
2340
	struct ieee80211_channel *chan;
2565
	struct ieee80211_channel *chan;
2341
	struct ieee80211_frame *wh;
2566
	struct ieee80211_frame *wh;
2342
	struct ieee80211_key *k = NULL;
2567
	struct ieee80211_key *k = NULL;
2343
	struct wpi_cmd_data tx;
2344
	struct wpi_buf tx_data;
2568
	struct wpi_buf tx_data;
2569
	struct wpi_cmd_data *tx = (struct wpi_cmd_data *)&tx_data.data;
2345
	uint32_t flags;
2570
	uint32_t flags;
2346
	uint16_t qos;
2571
	uint16_t qos;
2347
	uint8_t tid, type;
2572
	uint8_t tid, type;
2348
	int ac, error, rate, ismcast, hdrlen, totlen;
2573
	int ac, error, swcrypt, rate, ismcast, totlen;
2349
2574
2350
	wh = mtod(m, struct ieee80211_frame *);
2575
	wh = mtod(m, struct ieee80211_frame *);
2351
	hdrlen = ieee80211_anyhdrsize(wh);
2352
	type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2576
	type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2353
	ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
2577
	ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
2354
2578
Lines 2359-2365 Link Here
2359
	} else {
2583
	} else {
2360
		qos = 0;
2584
		qos = 0;
2361
		tid = 0;
2585
		tid = 0;
2362
        }
2586
	}
2363
	ac = M_WME_GETAC(m);
2587
	ac = M_WME_GETAC(m);
2364
2588
2365
	chan = (ni->ni_chan != IEEE80211_CHAN_ANYC) ?
2589
	chan = (ni->ni_chan != IEEE80211_CHAN_ANYC) ?
Lines 2389-2403 Link Here
2389
			error = ENOBUFS;
2613
			error = ENOBUFS;
2390
			goto fail;
2614
			goto fail;
2391
		}
2615
		}
2616
		swcrypt = k->wk_flags & IEEE80211_KEY_SWCRYPT;
2617
2392
		/* 802.11 header may have moved. */
2618
		/* 802.11 header may have moved. */
2393
		wh = mtod(m, struct ieee80211_frame *);
2619
		wh = mtod(m, struct ieee80211_frame *);
2394
	}
2620
	}
2395
	totlen = m->m_pkthdr.len - (hdrlen & 3);
2621
	totlen = m->m_pkthdr.len;
2396
2622
2397
	if (ieee80211_radiotap_active_vap(vap)) {
2623
	if (ieee80211_radiotap_active_vap(vap)) {
2398
		struct wpi_tx_radiotap_header *tap = &sc->sc_txtap;
2624
		struct wpi_tx_radiotap_header *tap = &sc->sc_txtap;
2399
2625
2400
		tap->wt_flags = IEEE80211_RADIOTAP_F_DATAPAD;
2626
		tap->wt_flags = 0;
2401
		tap->wt_rate = rate;
2627
		tap->wt_rate = rate;
2402
		if (k != NULL)
2628
		if (k != NULL)
2403
			tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
2629
			tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
Lines 2433-2439 Link Here
2433
			flags |= WPI_TX_FULL_TXOP;
2659
			flags |= WPI_TX_FULL_TXOP;
2434
	}
2660
	}
2435
2661
2436
	memset(&tx, 0, sizeof (struct wpi_cmd_data));
2662
	memset(tx, 0, sizeof (struct wpi_cmd_data));
2437
	if (type == IEEE80211_FC0_TYPE_MGT) {
2663
	if (type == IEEE80211_FC0_TYPE_MGT) {
2438
		uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
2664
		uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
2439
2665
Lines 2442-2467 Link Here
2442
			flags |= WPI_TX_INSERT_TSTAMP;
2668
			flags |= WPI_TX_INSERT_TSTAMP;
2443
		if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ ||
2669
		if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ ||
2444
		    subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ)
2670
		    subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ)
2445
			tx.timeout = htole16(3);
2671
			tx->timeout = htole16(3);
2446
		else
2672
		else
2447
			tx.timeout = htole16(2);
2673
			tx->timeout = htole16(2);
2448
	}
2674
	}
2449
2675
2450
	if (ismcast || type != IEEE80211_FC0_TYPE_DATA)
2676
	if (ismcast || type != IEEE80211_FC0_TYPE_DATA)
2451
		tx.id = WPI_ID_BROADCAST;
2677
		tx->id = WPI_ID_BROADCAST;
2452
	else {
2678
	else {
2453
		if (wn->id == WPI_ID_UNDEFINED &&
2454
		    (vap->iv_opmode == IEEE80211_M_IBSS ||
2455
		    vap->iv_opmode == IEEE80211_M_AHDEMO)) {
2456
			error = wpi_add_ibss_node(sc, ni);
2457
			if (error != 0) {
2458
				device_printf(sc->sc_dev,
2459
				    "%s: could not add IBSS node, error %d\n",
2460
				    __func__, error);
2461
				goto fail;
2462
			}
2463
		}
2464
2465
		if (wn->id == WPI_ID_UNDEFINED) {
2679
		if (wn->id == WPI_ID_UNDEFINED) {
2466
			device_printf(sc->sc_dev,
2680
			device_printf(sc->sc_dev,
2467
			    "%s: undefined node id\n", __func__);
2681
			    "%s: undefined node id\n", __func__);
Lines 2469-2504 Link Here
2469
			goto fail;
2683
			goto fail;
2470
		}
2684
		}
2471
2685
2472
		tx.id = wn->id;
2686
		tx->id = wn->id;
2473
	}
2687
	}
2474
2688
2475
	if (type != IEEE80211_FC0_TYPE_MGT)
2689
	if (type != IEEE80211_FC0_TYPE_MGT)
2476
		tx.data_ntries = tp->maxretry;
2690
		tx->data_ntries = tp->maxretry;
2477
2691
2478
	tx.len = htole16(totlen);
2692
	if (k != NULL && !swcrypt) {
2479
	tx.flags = htole32(flags);
2693
		switch (k->wk_cipher->ic_cipher) {
2480
	tx.plcp = rate2plcp(rate);
2694
		case IEEE80211_CIPHER_AES_CCM:
2481
	tx.tid = tid;
2695
			tx->security = WPI_CIPHER_CCMP;
2482
	tx.lifetime = htole32(WPI_LIFETIME_INFINITE);
2696
			break;
2483
	tx.ofdm_mask = 0xff;
2484
	tx.cck_mask = 0x0f;
2485
	tx.rts_ntries = 7;
2486
2697
2487
	if (k != NULL && k->wk_cipher->ic_cipher == IEEE80211_CIPHER_AES_CCM) {
2698
		default:
2488
		if (!(k->wk_flags & IEEE80211_KEY_SWCRYPT)) {
2699
			break;
2489
			tx.security = WPI_CIPHER_CCMP;
2490
			memcpy(tx.key, k->wk_key, k->wk_keylen);
2491
		}
2700
		}
2701
2702
		memcpy(tx->key, k->wk_key, k->wk_keylen);
2492
	}
2703
	}
2493
2704
2494
	tx_data.data = &tx;
2705
	tx->len = htole16(totlen);
2706
	tx->flags = htole32(flags);
2707
	tx->plcp = rate2plcp(rate);
2708
	tx->tid = tid;
2709
	tx->lifetime = htole32(WPI_LIFETIME_INFINITE);
2710
	tx->ofdm_mask = 0xff;
2711
	tx->cck_mask = 0x0f;
2712
	tx->rts_ntries = 7;
2713
2495
	tx_data.ni = ni;
2714
	tx_data.ni = ni;
2496
	tx_data.m = m;
2715
	tx_data.m = m;
2497
	tx_data.size = sizeof(tx);
2716
	tx_data.size = sizeof(struct wpi_cmd_data);
2498
	tx_data.code = WPI_CMD_TX_DATA;
2717
	tx_data.code = WPI_CMD_TX_DATA;
2499
	tx_data.ac = ac;
2718
	tx_data.ac = ac;
2500
2719
2501
	return wpi_cmd2(sc, &tx_data);
2720
	return wpi_cmd2(sc, &tx_data, 1);
2502
2721
2503
fail:	m_freem(m);
2722
fail:	m_freem(m);
2504
	return error;
2723
	return error;
Lines 2505-2525 Link Here
2505
}
2724
}
2506
2725
2507
static int
2726
static int
2508
wpi_tx_data_raw(struct wpi_softc *sc, struct mbuf *m, struct ieee80211_node *ni,
2727
wpi_tx_data_raw(struct wpi_softc *sc, struct mbuf *m,
2509
    const struct ieee80211_bpf_params *params)
2728
    struct ieee80211_node *ni, const struct ieee80211_bpf_params *params)
2510
{
2729
{
2511
	struct ieee80211vap *vap = ni->ni_vap;
2730
	struct ieee80211vap *vap = ni->ni_vap;
2731
	struct ieee80211_key *k = NULL;
2512
	struct ieee80211_frame *wh;
2732
	struct ieee80211_frame *wh;
2513
	struct wpi_cmd_data tx;
2514
	struct wpi_buf tx_data;
2733
	struct wpi_buf tx_data;
2734
	struct wpi_cmd_data *tx = (struct wpi_cmd_data *)&tx_data.data;
2515
	uint32_t flags;
2735
	uint32_t flags;
2516
	uint8_t type;
2736
	uint8_t type;
2517
	int ac, rate, hdrlen, totlen;
2737
	int ac, swcrypt, rate, totlen;
2518
2738
2519
	wh = mtod(m, struct ieee80211_frame *);
2739
	wh = mtod(m, struct ieee80211_frame *);
2520
	hdrlen = ieee80211_anyhdrsize(wh);
2521
	type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2740
	type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2522
	totlen = m->m_pkthdr.len - (hdrlen & 3);
2523
2741
2524
	ac = params->ibp_pri & 3;
2742
	ac = params->ibp_pri & 3;
2525
2743
Lines 2536-2553 Link Here
2536
	if (flags & (WPI_TX_NEED_RTS | WPI_TX_NEED_CTS))
2754
	if (flags & (WPI_TX_NEED_RTS | WPI_TX_NEED_CTS))
2537
		flags |= WPI_TX_FULL_TXOP;
2755
		flags |= WPI_TX_FULL_TXOP;
2538
2756
2757
	/* Encrypt the frame if need be. */
2758
	if (params->ibp_flags & IEEE80211_BPF_CRYPTO) {
2759
		/* Retrieve key for TX. */
2760
		k = ieee80211_crypto_encap(ni, m);
2761
		if (k == NULL) {
2762
			m_freem(m);
2763
			return ENOBUFS;
2764
		}
2765
		swcrypt = k->wk_flags & IEEE80211_KEY_SWCRYPT;
2766
2767
		/* 802.11 header may have moved. */
2768
		wh = mtod(m, struct ieee80211_frame *);
2769
	}
2770
	totlen = m->m_pkthdr.len;
2771
2539
	if (ieee80211_radiotap_active_vap(vap)) {
2772
	if (ieee80211_radiotap_active_vap(vap)) {
2540
		struct wpi_tx_radiotap_header *tap = &sc->sc_txtap;
2773
		struct wpi_tx_radiotap_header *tap = &sc->sc_txtap;
2541
2774
2542
		tap->wt_flags = 0;
2775
		tap->wt_flags = 0;
2543
		tap->wt_rate = rate;
2776
		tap->wt_rate = rate;
2544
		if (params->ibp_flags & IEEE80211_BPF_DATAPAD)
2777
		if (params->ibp_flags & IEEE80211_BPF_CRYPTO)
2545
			tap->wt_flags |= IEEE80211_RADIOTAP_F_DATAPAD;
2778
			tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
2546
2779
2547
		ieee80211_radiotap_tx(vap, m);
2780
		ieee80211_radiotap_tx(vap, m);
2548
	}
2781
	}
2549
2782
2550
	memset(&tx, 0, sizeof (struct wpi_cmd_data));
2783
	memset(tx, 0, sizeof (struct wpi_cmd_data));
2551
	if (type == IEEE80211_FC0_TYPE_MGT) {
2784
	if (type == IEEE80211_FC0_TYPE_MGT) {
2552
		uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
2785
		uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
2553
2786
Lines 2556-2582 Link Here
2556
			flags |= WPI_TX_INSERT_TSTAMP;
2789
			flags |= WPI_TX_INSERT_TSTAMP;
2557
		if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ ||
2790
		if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ ||
2558
		    subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ)
2791
		    subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ)
2559
			tx.timeout = htole16(3);
2792
			tx->timeout = htole16(3);
2560
		else
2793
		else
2561
			tx.timeout = htole16(2);
2794
			tx->timeout = htole16(2);
2562
	}
2795
	}
2563
2796
2564
	tx.len = htole16(totlen);
2797
	if (k != NULL && !swcrypt) {
2565
	tx.flags = htole32(flags);
2798
		switch (k->wk_cipher->ic_cipher) {
2566
	tx.plcp = rate2plcp(rate);
2799
		case IEEE80211_CIPHER_AES_CCM:
2567
	tx.id = WPI_ID_BROADCAST;
2800
			tx->security = WPI_CIPHER_CCMP;
2568
	tx.lifetime = htole32(WPI_LIFETIME_INFINITE);
2801
			break;
2569
	tx.rts_ntries = params->ibp_try1;
2570
	tx.data_ntries = params->ibp_try0;
2571
2802
2572
	tx_data.data = &tx;
2803
		default:
2804
			break;
2805
		}
2806
2807
		memcpy(tx->key, k->wk_key, k->wk_keylen);
2808
	}
2809
2810
	tx->len = htole16(totlen);
2811
	tx->flags = htole32(flags);
2812
	tx->plcp = rate2plcp(rate);
2813
	tx->id = WPI_ID_BROADCAST;
2814
	tx->lifetime = htole32(WPI_LIFETIME_INFINITE);
2815
	tx->rts_ntries = params->ibp_try1;
2816
	tx->data_ntries = params->ibp_try0;
2817
2573
	tx_data.ni = ni;
2818
	tx_data.ni = ni;
2574
	tx_data.m = m;
2819
	tx_data.m = m;
2575
	tx_data.size = sizeof(tx);
2820
	tx_data.size = sizeof(struct wpi_cmd_data);
2576
	tx_data.code = WPI_CMD_TX_DATA;
2821
	tx_data.code = WPI_CMD_TX_DATA;
2577
	tx_data.ac = ac;
2822
	tx_data.ac = ac;
2578
2823
2579
	return wpi_cmd2(sc, &tx_data);
2824
	return wpi_cmd2(sc, &tx_data, 1);
2580
}
2825
}
2581
2826
2582
static int
2827
static int
Lines 2596-2602 Link Here
2596
		return ENETDOWN;
2841
		return ENETDOWN;
2597
	}
2842
	}
2598
2843
2599
	WPI_LOCK(sc);
2844
	WPI_TX_LOCK(sc);
2600
	if (params == NULL) {
2845
	if (params == NULL) {
2601
		/*
2846
		/*
2602
		 * Legacy path; interpret frame contents to decide
2847
		 * Legacy path; interpret frame contents to decide
Lines 2610-2616 Link Here
2610
		 */
2855
		 */
2611
		error = wpi_tx_data_raw(sc, m, ni, params);
2856
		error = wpi_tx_data_raw(sc, m, ni, params);
2612
	}
2857
	}
2613
	WPI_UNLOCK(sc);
2858
	WPI_TX_UNLOCK(sc);
2614
2859
2615
	if (error != 0) {
2860
	if (error != 0) {
2616
		/* NB: m is reclaimed on tx failure */
2861
		/* NB: m is reclaimed on tx failure */
Lines 2622-2629 Link Here
2622
		return error;
2867
		return error;
2623
	}
2868
	}
2624
2869
2625
	sc->sc_tx_timer = 5;
2626
2627
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
2870
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
2628
2871
2629
	return 0;
2872
	return 0;
Lines 2636-2665 Link Here
2636
wpi_start(struct ifnet *ifp)
2879
wpi_start(struct ifnet *ifp)
2637
{
2880
{
2638
	struct wpi_softc *sc = ifp->if_softc;
2881
	struct wpi_softc *sc = ifp->if_softc;
2639
2640
	WPI_LOCK(sc);
2641
	wpi_start_locked(ifp);
2642
	WPI_UNLOCK(sc);
2643
}
2644
2645
static void
2646
wpi_start_locked(struct ifnet *ifp)
2647
{
2648
	struct wpi_softc *sc = ifp->if_softc;
2649
	struct ieee80211_node *ni;
2882
	struct ieee80211_node *ni;
2650
	struct mbuf *m;
2883
	struct mbuf *m;
2651
2884
2652
	WPI_LOCK_ASSERT(sc);
2653
2654
	DPRINTF(sc, WPI_DEBUG_XMIT, "%s: called\n", __func__);
2885
	DPRINTF(sc, WPI_DEBUG_XMIT, "%s: called\n", __func__);
2655
2886
2887
	IF_LOCK(&ifp->if_snd);
2656
	if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ||
2888
	if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ||
2657
	    (ifp->if_drv_flags & IFF_DRV_OACTIVE))
2889
	    (ifp->if_drv_flags & IFF_DRV_OACTIVE)) {
2890
		IF_UNLOCK(&ifp->if_snd);
2658
		return;
2891
		return;
2892
	}
2893
	IF_UNLOCK(&ifp->if_snd);
2659
2894
2895
	WPI_TX_LOCK(sc);
2660
	for (;;) {
2896
	for (;;) {
2661
		if (sc->qfullmsk != 0) {
2897
		if (atomic_load_acq_32(&sc->qfullmsk) != 0) {
2898
			IF_LOCK(&ifp->if_snd);
2662
			ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2899
			ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2900
			IF_UNLOCK(&ifp->if_snd);
2663
			break;
2901
			break;
2664
		}
2902
		}
2665
		IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
2903
		IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
Lines 2667-2684 Link Here
2667
			break;
2905
			break;
2668
		ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
2906
		ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
2669
		if (wpi_tx_data(sc, m, ni) != 0) {
2907
		if (wpi_tx_data(sc, m, ni) != 0) {
2670
			WPI_UNLOCK(sc);
2671
			ieee80211_free_node(ni);
2908
			ieee80211_free_node(ni);
2672
			WPI_LOCK(sc);
2673
			if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2909
			if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2674
		} else
2910
		}
2675
			sc->sc_tx_timer = 5;
2676
	}
2911
	}
2912
	WPI_TX_UNLOCK(sc);
2677
2913
2678
	DPRINTF(sc, WPI_DEBUG_XMIT, "%s: done\n", __func__);
2914
	DPRINTF(sc, WPI_DEBUG_XMIT, "%s: done\n", __func__);
2679
}
2915
}
2680
2916
2681
static void
2917
static void
2918
wpi_start_task(void *arg0, int pending)
2919
{
2920
	struct wpi_softc *sc = arg0;
2921
	struct ifnet *ifp = sc->sc_ifp;
2922
2923
	wpi_start(ifp);
2924
}
2925
2926
static void
2682
wpi_watchdog_rfkill(void *arg)
2927
wpi_watchdog_rfkill(void *arg)
2683
{
2928
{
2684
	struct wpi_softc *sc = arg;
2929
	struct wpi_softc *sc = arg;
Lines 2706-2716 Link Here
2706
	struct wpi_softc *sc = arg;
2951
	struct wpi_softc *sc = arg;
2707
	struct ifnet *ifp = sc->sc_ifp;
2952
	struct ifnet *ifp = sc->sc_ifp;
2708
	struct ieee80211com *ic = ifp->if_l2com;
2953
	struct ieee80211com *ic = ifp->if_l2com;
2954
	int32_t tmp;
2709
2955
2710
	DPRINTF(sc, WPI_DEBUG_WATCHDOG, "Watchdog: tick\n");
2956
	DPRINTF(sc, WPI_DEBUG_WATCHDOG, "Watchdog: tick\n");
2711
2957
2712
	if (sc->sc_tx_timer > 0) {
2958
	tmp = atomic_load_acq_32(&sc->sc_tx_timer);
2713
		if (--sc->sc_tx_timer == 0) {
2959
	if (tmp > 0) {
2960
		tmp -= 1;
2961
		atomic_cmpset_rel_32(&sc->sc_tx_timer, tmp + 1, tmp);
2962
		if (tmp == 0) {
2714
			if_printf(ifp, "device timeout\n");
2963
			if_printf(ifp, "device timeout\n");
2715
			if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2964
			if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2716
			ieee80211_runtask(ic, &sc->sc_reinittask);
2965
			ieee80211_runtask(ic, &sc->sc_reinittask);
Lines 2717-2725 Link Here
2717
		}
2966
		}
2718
	}
2967
	}
2719
2968
2720
	if (sc->sc_scan_timer > 0) {
2969
	tmp = atomic_load_acq_32(&sc->sc_scan_timer);
2970
	if (tmp > 0) {
2721
		struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2971
		struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2722
		if (--sc->sc_scan_timer == 0 && vap != NULL) {
2972
		tmp -= 1;
2973
		atomic_cmpset_rel_32(&sc->sc_scan_timer, tmp + 1, tmp);
2974
		if (tmp == 0 && vap != NULL) {
2723
			if_printf(ifp, "scan timeout\n");
2975
			if_printf(ifp, "scan timeout\n");
2724
			ieee80211_cancel_scan(vap);
2976
			ieee80211_cancel_scan(vap);
2725
			ieee80211_runtask(ic, &sc->sc_reinittask);
2977
			ieee80211_runtask(ic, &sc->sc_reinittask);
Lines 2726-2732 Link Here
2726
		}
2978
		}
2727
	}
2979
	}
2728
2980
2729
	if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2981
	if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
2730
		callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
2982
		callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
2731
}
2983
}
2732
2984
Lines 2737-2743 Link Here
2737
	struct ieee80211com *ic = ifp->if_l2com;
2989
	struct ieee80211com *ic = ifp->if_l2com;
2738
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2990
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2739
	struct ifreq *ifr = (struct ifreq *) data;
2991
	struct ifreq *ifr = (struct ifreq *) data;
2740
	int error = 0, startall = 0, stop = 0;
2992
	int error = 0;
2741
2993
2742
	switch (cmd) {
2994
	switch (cmd) {
2743
	case SIOCGIFADDR:
2995
	case SIOCGIFADDR:
Lines 2744-2766 Link Here
2744
		error = ether_ioctl(ifp, cmd, data);
2996
		error = ether_ioctl(ifp, cmd, data);
2745
		break;
2997
		break;
2746
	case SIOCSIFFLAGS:
2998
	case SIOCSIFFLAGS:
2747
		WPI_LOCK(sc);
2748
		if (ifp->if_flags & IFF_UP) {
2999
		if (ifp->if_flags & IFF_UP) {
2749
			if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
3000
			wpi_init(sc);
2750
				wpi_init_locked(sc);
3001
2751
				if (WPI_READ(sc, WPI_GP_CNTRL) &
3002
			if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 &&
2752
				    WPI_GP_CNTRL_RFKILL)
3003
			    vap != NULL)
2753
					startall = 1;
3004
				ieee80211_stop(vap);
2754
				else
3005
		} else if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
2755
					stop = 1;
3006
			wpi_stop(sc);
2756
			}
2757
		} else if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2758
			wpi_stop_locked(sc);
2759
		WPI_UNLOCK(sc);
2760
		if (startall)
2761
			ieee80211_start_all(ic);
2762
		else if (vap != NULL && stop)
2763
			ieee80211_stop(vap);
2764
		break;
3007
		break;
2765
	case SIOCGIFMEDIA:
3008
	case SIOCGIFMEDIA:
2766
		error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd);
3009
		error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd);
Lines 2779-2785 Link Here
2779
wpi_cmd(struct wpi_softc *sc, int code, const void *buf, size_t size,
3022
wpi_cmd(struct wpi_softc *sc, int code, const void *buf, size_t size,
2780
    int async)
3023
    int async)
2781
{
3024
{
2782
	struct wpi_tx_ring *ring = &sc->txq[4];
3025
	struct wpi_tx_ring *ring = &sc->txq[WPI_CMD_QUEUE_NUM];
2783
	struct wpi_tx_desc *desc;
3026
	struct wpi_tx_desc *desc;
2784
	struct wpi_tx_data *data;
3027
	struct wpi_tx_data *data;
2785
	struct wpi_tx_cmd *cmd;
3028
	struct wpi_tx_cmd *cmd;
Lines 2787-2807 Link Here
2787
	bus_addr_t paddr;
3030
	bus_addr_t paddr;
2788
	int totlen, error;
3031
	int totlen, error;
2789
3032
3033
	WPI_TXQ_LOCK(sc);
3034
2790
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
3035
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
2791
3036
2792
	if (async == 0)
3037
	if (atomic_load_acq_32(&sc->txq_active) == 0) {
2793
		WPI_LOCK_ASSERT(sc);
3038
		error = 0;
3039
		goto fail;
3040
	}
2794
3041
2795
	DPRINTF(sc, WPI_DEBUG_CMD, "wpi_cmd %s size %zu async %d\n",
3042
	DPRINTF(sc, WPI_DEBUG_CMD, "%s: cmd %s size %zu async %d\n",
2796
	    wpi_cmd_str(code), size, async);
3043
	    __func__, wpi_cmd_str(code), size, async);
2797
3044
2798
	if (sc->flags & WPI_FLAG_BUSY) {
2799
		device_printf(sc->sc_dev, "%s: cmd %d not sent, busy\n",
2800
		    __func__, code);
2801
		return EAGAIN;
2802
	}
2803
	sc->flags |= WPI_FLAG_BUSY;
2804
2805
	desc = &ring->desc[ring->cur];
3045
	desc = &ring->desc[ring->cur];
2806
	data = &ring->data[ring->cur];
3046
	data = &ring->data[ring->cur];
2807
	totlen = 4 + size;
3047
	totlen = 4 + size;
Lines 2808-2824 Link Here
2808
3048
2809
	if (size > sizeof cmd->data) {
3049
	if (size > sizeof cmd->data) {
2810
		/* Command is too large to fit in a descriptor. */
3050
		/* Command is too large to fit in a descriptor. */
2811
		if (totlen > MCLBYTES)
3051
		if (totlen > MCLBYTES) {
2812
			return EINVAL;
3052
			error = EINVAL;
3053
			goto fail;
3054
		}
2813
		m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE);
3055
		m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE);
2814
		if (m == NULL)
3056
		if (m == NULL) {
2815
			return ENOMEM;
3057
			error = ENOMEM;
3058
			goto fail;
3059
		}
2816
		cmd = mtod(m, struct wpi_tx_cmd *);
3060
		cmd = mtod(m, struct wpi_tx_cmd *);
2817
		error = bus_dmamap_load(ring->data_dmat, data->map, cmd,
3061
		error = bus_dmamap_load(ring->data_dmat, data->map, cmd,
2818
		    totlen, wpi_dma_map_addr, &paddr, BUS_DMA_NOWAIT);
3062
		    totlen, wpi_dma_map_addr, &paddr, BUS_DMA_NOWAIT);
2819
		if (error != 0) {
3063
		if (error != 0) {
2820
			m_freem(m);
3064
			m_freem(m);
2821
			return error;
3065
			goto fail;
2822
		}
3066
		}
2823
		data->m = m;
3067
		data->m = m;
2824
	} else {
3068
	} else {
Lines 2850-2863 Link Here
2850
	ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT;
3094
	ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT;
2851
	wpi_update_tx_ring(sc, ring);
3095
	wpi_update_tx_ring(sc, ring);
2852
3096
3097
	WPI_TXQ_UNLOCK(sc);
3098
2853
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3099
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
2854
3100
2855
	if (async) {
3101
	if (async)
2856
		sc->flags &= ~WPI_FLAG_BUSY;
2857
		return 0;
3102
		return 0;
2858
	}
2859
3103
2860
	return msleep(cmd, &sc->sc_mtx, PCATCH, "wpicmd", hz);
3104
	return mtx_sleep(cmd, &sc->sc_mtx, PCATCH, "wpicmd", hz);
3105
3106
fail:	WPI_TXQ_UNLOCK(sc);
3107
3108
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
3109
3110
	return error;
2861
}
3111
}
2862
3112
2863
/*
3113
/*
Lines 2917-2924 Link Here
2917
wpi_add_node(struct wpi_softc *sc, struct ieee80211_node *ni)
3167
wpi_add_node(struct wpi_softc *sc, struct ieee80211_node *ni)
2918
{
3168
{
2919
	struct ieee80211com *ic = ni->ni_ic;
3169
	struct ieee80211com *ic = ni->ni_ic;
2920
	struct wpi_node *wn = (void *)ni;
3170
	struct ieee80211vap *vap = ni->ni_vap;
3171
	struct wpi_vap *wvp = WPI_VAP(vap);
3172
	struct wpi_node *wn = WPI_NODE(ni);
2921
	struct wpi_node_info node;
3173
	struct wpi_node_info node;
3174
	int error;
2922
3175
2923
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3176
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
2924
3177
Lines 2926-2932 Link Here
2926
		return EINVAL;
3179
		return EINVAL;
2927
3180
2928
	memset(&node, 0, sizeof node);
3181
	memset(&node, 0, sizeof node);
2929
	IEEE80211_ADDR_COPY(node.macaddr, ni->ni_bssid);
3182
	IEEE80211_ADDR_COPY(node.macaddr, ni->ni_macaddr);
2930
	node.id = wn->id;
3183
	node.id = wn->id;
2931
	node.plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ?
3184
	node.plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ?
2932
	    wpi_ridx_to_plcp[WPI_RIDX_OFDM6] : wpi_ridx_to_plcp[WPI_RIDX_CCK1];
3185
	    wpi_ridx_to_plcp[WPI_RIDX_OFDM6] : wpi_ridx_to_plcp[WPI_RIDX_CCK1];
Lines 2933-2939 Link Here
2933
	node.action = htole32(WPI_ACTION_SET_RATE);
3186
	node.action = htole32(WPI_ACTION_SET_RATE);
2934
	node.antenna = WPI_ANTENNA_BOTH;
3187
	node.antenna = WPI_ANTENNA_BOTH;
2935
3188
2936
	return wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
3189
	DPRINTF(sc, WPI_DEBUG_NODE, "%s: adding node %d (%s)\n", __func__,
3190
	    wn->id, ether_sprintf(ni->ni_macaddr));
3191
3192
	error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
3193
	if (error != 0) {
3194
		device_printf(sc->sc_dev,
3195
		    "%s: wpi_cmd() call failed with error code %d\n", __func__,
3196
		    error);
3197
		return error;
3198
	}
3199
3200
	if (atomic_load_acq_32(&wvp->wv_gtk) != 0) {
3201
		error = wpi_set_global_keys(ni);
3202
		if (error != 0) {
3203
			device_printf(sc->sc_dev,
3204
			    "%s: error while setting global keys\n", __func__);
3205
			return ENXIO;
3206
		}
3207
	}
3208
3209
	return 0;
2937
}
3210
}
2938
3211
2939
/*
3212
/*
Lines 2956-2968 Link Here
2956
	node.action = htole32(WPI_ACTION_SET_RATE);
3229
	node.action = htole32(WPI_ACTION_SET_RATE);
2957
	node.antenna = WPI_ANTENNA_BOTH;
3230
	node.antenna = WPI_ANTENNA_BOTH;
2958
3231
3232
	DPRINTF(sc, WPI_DEBUG_NODE, "%s: adding broadcast node\n", __func__);
3233
2959
	return wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, async);
3234
	return wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, async);
2960
}
3235
}
2961
3236
2962
static int
3237
static int
3238
wpi_add_sta_node(struct wpi_softc *sc, struct ieee80211_node *ni)
3239
{
3240
	struct wpi_node *wn = WPI_NODE(ni);
3241
	int error;
3242
3243
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3244
3245
	wn->id = wpi_add_node_entry_sta(sc);
3246
3247
	if ((error = wpi_add_node(sc, ni)) != 0) {
3248
		wpi_del_node_entry(sc, wn->id);
3249
		wn->id = WPI_ID_UNDEFINED;
3250
		return error;
3251
	}
3252
3253
	return 0;
3254
}
3255
3256
static int
2963
wpi_add_ibss_node(struct wpi_softc *sc, struct ieee80211_node *ni)
3257
wpi_add_ibss_node(struct wpi_softc *sc, struct ieee80211_node *ni)
2964
{
3258
{
2965
	struct wpi_node *wn = (void *)ni;
3259
	struct wpi_node *wn = WPI_NODE(ni);
3260
	int error;
2966
3261
2967
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3262
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
2968
3263
Lines 2969-3001 Link Here
2969
	if (wn->id != WPI_ID_UNDEFINED)
3264
	if (wn->id != WPI_ID_UNDEFINED)
2970
		return EINVAL;
3265
		return EINVAL;
2971
3266
2972
	wn->id = alloc_unrl(sc->sc_unr);
3267
	if ((wn->id = wpi_add_node_entry_adhoc(sc)) == WPI_ID_UNDEFINED) {
3268
		device_printf(sc->sc_dev, "%s: h/w table is full\n", __func__);
3269
		return ENOMEM;
3270
	}
2973
3271
2974
	if (wn->id == (uint8_t)-1)
3272
	if ((error = wpi_add_node(sc, ni)) != 0) {
2975
		return ENOBUFS;
3273
		wpi_del_node_entry(sc, wn->id);
3274
		wn->id = WPI_ID_UNDEFINED;
3275
		return error;
3276
	}
2976
3277
2977
	return wpi_add_node(sc, ni);
3278
	return 0;
2978
}
3279
}
2979
3280
2980
static void
3281
static void
2981
wpi_del_node(struct wpi_softc *sc, struct ieee80211_node *ni)
3282
wpi_del_node(struct wpi_softc *sc, struct ieee80211_node *ni)
2982
{
3283
{
2983
	struct wpi_node *wn = (void *)ni;
3284
	struct wpi_node *wn = WPI_NODE(ni);
2984
	struct wpi_cmd_del_node node;
3285
	struct wpi_cmd_del_node node;
2985
	int error;
3286
	int error;
2986
3287
3288
	KASSERT(wn->id != WPI_ID_UNDEFINED, ("undefined node id passed"));
3289
2987
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3290
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
2988
3291
2989
	if (wn->id == WPI_ID_UNDEFINED) {
2990
		device_printf(sc->sc_dev, "%s: undefined node id passed\n",
2991
		    __func__);
2992
		return;
2993
	}
2994
2995
	memset(&node, 0, sizeof node);
3292
	memset(&node, 0, sizeof node);
2996
	IEEE80211_ADDR_COPY(node.macaddr, ni->ni_bssid);
3293
	IEEE80211_ADDR_COPY(node.macaddr, ni->ni_macaddr);
2997
	node.count = 1;
3294
	node.count = 1;
2998
3295
3296
	DPRINTF(sc, WPI_DEBUG_NODE, "%s: deleting node %d (%s)\n", __func__,
3297
	    wn->id, ether_sprintf(ni->ni_macaddr));
3298
2999
	error = wpi_cmd(sc, WPI_CMD_DEL_NODE, &node, sizeof node, 1);
3299
	error = wpi_cmd(sc, WPI_CMD_DEL_NODE, &node, sizeof node, 1);
3000
	if (error != 0) {
3300
	if (error != 0) {
3001
		device_printf(sc->sc_dev,
3301
		device_printf(sc->sc_dev,
Lines 3031-3041 Link Here
3031
		    cmd.ac[aci].cwmin, cmd.ac[aci].cwmax,
3331
		    cmd.ac[aci].cwmin, cmd.ac[aci].cwmax,
3032
		    cmd.ac[aci].txoplimit);
3332
		    cmd.ac[aci].txoplimit);
3033
	}
3333
	}
3034
	IEEE80211_UNLOCK(ic);
3035
	WPI_LOCK(sc);
3036
	error = wpi_cmd(sc, WPI_CMD_EDCA_PARAMS, &cmd, sizeof cmd, 1);
3334
	error = wpi_cmd(sc, WPI_CMD_EDCA_PARAMS, &cmd, sizeof cmd, 1);
3037
	WPI_UNLOCK(sc);
3038
	IEEE80211_LOCK(ic);
3039
3335
3040
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3336
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3041
3337
Lines 3047-3055 Link Here
3047
wpi_set_promisc(struct wpi_softc *sc)
3343
wpi_set_promisc(struct wpi_softc *sc)
3048
{
3344
{
3049
	struct ifnet *ifp = sc->sc_ifp;
3345
	struct ifnet *ifp = sc->sc_ifp;
3346
	struct ieee80211com *ic = ifp->if_l2com;
3347
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3050
	uint32_t promisc_filter;
3348
	uint32_t promisc_filter;
3051
3349
3052
	promisc_filter = WPI_FILTER_PROMISC | WPI_FILTER_CTL;
3350
	promisc_filter = WPI_FILTER_CTL;
3351
	if (vap != NULL && vap->iv_opmode != IEEE80211_M_HOSTAP)
3352
		promisc_filter |= WPI_FILTER_PROMISC;
3053
3353
3054
	if (ifp->if_flags & IFF_PROMISC)
3354
	if (ifp->if_flags & IFF_PROMISC)
3055
		sc->rxon.filter |= htole32(promisc_filter);
3355
		sc->rxon.filter |= htole32(promisc_filter);
Lines 3062-3075 Link Here
3062
{
3362
{
3063
	struct wpi_softc *sc = ifp->if_softc;
3363
	struct wpi_softc *sc = ifp->if_softc;
3064
3364
3365
	WPI_RXON_LOCK(sc);
3065
	wpi_set_promisc(sc);
3366
	wpi_set_promisc(sc);
3066
3367
3067
	WPI_LOCK(sc);
3068
	if (wpi_send_rxon(sc, 1, 1) != 0) {
3368
	if (wpi_send_rxon(sc, 1, 1) != 0) {
3069
		device_printf(sc->sc_dev, "%s: could not send RXON\n",
3369
		device_printf(sc->sc_dev, "%s: could not send RXON\n",
3070
		    __func__);
3370
		    __func__);
3071
	}
3371
	}
3072
	WPI_UNLOCK(sc);
3372
	WPI_RXON_UNLOCK(sc);
3073
}
3373
}
3074
3374
3075
static void
3375
static void
Lines 3159-3166 Link Here
3159
static int
3459
static int
3160
wpi_set_txpower(struct wpi_softc *sc, int async)
3460
wpi_set_txpower(struct wpi_softc *sc, int async)
3161
{
3461
{
3162
	struct ifnet *ifp = sc->sc_ifp;
3462
	struct ieee80211com *ic = sc->sc_ifp->if_l2com;
3163
	struct ieee80211com *ic = ifp->if_l2com;
3164
	struct ieee80211_channel *ch;
3463
	struct ieee80211_channel *ch;
3165
	struct wpi_power_group *group;
3464
	struct wpi_power_group *group;
3166
	struct wpi_cmd_txpower cmd;
3465
	struct wpi_cmd_txpower cmd;
Lines 3214-3228 Link Here
3214
    struct ieee80211_channel *c, int ridx)
3513
    struct ieee80211_channel *c, int ridx)
3215
{
3514
{
3216
/* Fixed-point arithmetic division using a n-bit fractional part. */
3515
/* Fixed-point arithmetic division using a n-bit fractional part. */
3217
#define fdivround(a, b, n)      \
3516
#define fdivround(a, b, n)	\
3218
	((((1 << n) * (a)) / (b) + (1 << n) / 2) / (1 << n))
3517
	((((1 << n) * (a)) / (b) + (1 << n) / 2) / (1 << n))
3219
3518
3220
/* Linear interpolation. */
3519
/* Linear interpolation. */
3221
#define interpolate(x, x1, y1, x2, y2, n)       \
3520
#define interpolate(x, x1, y1, x2, y2, n)	\
3222
	((y1) + fdivround(((x) - (x1)) * ((y2) - (y1)), (x2) - (x1), n))
3521
	((y1) + fdivround(((x) - (x1)) * ((y2) - (y1)), (x2) - (x1), n))
3223
3522
3224
	struct ifnet *ifp = sc->sc_ifp;
3523
	struct ieee80211com *ic = sc->sc_ifp->if_l2com;
3225
	struct ieee80211com *ic = ifp->if_l2com;
3226
	struct wpi_power_sample *sample;
3524
	struct wpi_power_sample *sample;
3227
	int pwr, idx;
3525
	int pwr, idx;
3228
	u_int chan;
3526
	u_int chan;
Lines 3335-3352 Link Here
3335
	return wpi_cmd(sc, WPI_CMD_SET_POWER_MODE, &cmd, sizeof cmd, async);
3633
	return wpi_cmd(sc, WPI_CMD_SET_POWER_MODE, &cmd, sizeof cmd, async);
3336
}
3634
}
3337
3635
3338
static int      
3636
static int
3339
wpi_send_btcoex(struct wpi_softc *sc)
3637
wpi_send_btcoex(struct wpi_softc *sc)
3340
{
3638
{
3341
	struct wpi_bluetooth cmd;
3639
	struct wpi_bluetooth cmd;
3342
3640
3343
        memset(&cmd, 0, sizeof cmd);
3641
	memset(&cmd, 0, sizeof cmd);
3344
        cmd.flags = WPI_BT_COEX_MODE_4WIRE;
3642
	cmd.flags = WPI_BT_COEX_MODE_4WIRE;
3345
        cmd.lead_time = WPI_BT_LEAD_TIME_DEF;
3643
	cmd.lead_time = WPI_BT_LEAD_TIME_DEF;
3346
        cmd.max_kill = WPI_BT_MAX_KILL_DEF;
3644
	cmd.max_kill = WPI_BT_MAX_KILL_DEF;
3347
	DPRINTF(sc, WPI_DEBUG_RESET, "%s: configuring bluetooth coexistence\n",
3645
	DPRINTF(sc, WPI_DEBUG_RESET, "%s: configuring bluetooth coexistence\n",
3348
	    __func__);
3646
	    __func__);
3349
        return wpi_cmd(sc, WPI_CMD_BT_COEX, &cmd, sizeof(cmd), 0);
3647
	return wpi_cmd(sc, WPI_CMD_BT_COEX, &cmd, sizeof(cmd), 0);
3350
}
3648
}
3351
3649
3352
static int
3650
static int
Lines 3354-3359 Link Here
3354
{
3652
{
3355
	int error;
3653
	int error;
3356
3654
3655
	if (async)
3656
		WPI_RXON_LOCK_ASSERT(sc);
3657
3357
	if (assoc && (sc->rxon.filter & htole32(WPI_FILTER_BSS))) {
3658
	if (assoc && (sc->rxon.filter & htole32(WPI_FILTER_BSS))) {
3358
		struct wpi_assoc rxon_assoc;
3659
		struct wpi_assoc rxon_assoc;
3359
3660
Lines 3365-3388 Link Here
3365
3666
3366
		error = wpi_cmd(sc, WPI_CMD_RXON_ASSOC, &rxon_assoc,
3667
		error = wpi_cmd(sc, WPI_CMD_RXON_ASSOC, &rxon_assoc,
3367
		    sizeof (struct wpi_assoc), async);
3668
		    sizeof (struct wpi_assoc), async);
3669
		if (error != 0) {
3670
			device_printf(sc->sc_dev,
3671
			    "RXON_ASSOC command failed, error %d\n", error);
3672
			return error;
3673
		}
3368
	} else {
3674
	} else {
3675
		if (async)
3676
			WPI_NT_LOCK(sc);
3677
3369
		error = wpi_cmd(sc, WPI_CMD_RXON, &sc->rxon,
3678
		error = wpi_cmd(sc, WPI_CMD_RXON, &sc->rxon,
3370
		    sizeof (struct wpi_rxon), async);
3679
		    sizeof (struct wpi_rxon), async);
3371
	}
3680
		if (error != 0) {
3372
	if (error != 0) {
3681
			device_printf(sc->sc_dev,
3373
		device_printf(sc->sc_dev, "RXON command failed, error %d\n",
3682
			    "RXON command failed, error %d\n", error);
3374
		    error);
3683
			return error;
3375
		return error;
3684
		}
3376
	}
3377
3685
3378
	/* Configuration has changed, set Tx power accordingly. */
3686
		wpi_clear_node_table(sc);
3379
	if ((error = wpi_set_txpower(sc, async)) != 0) {
3380
		device_printf(sc->sc_dev,
3381
		    "%s: could not set TX power, error %d\n", __func__, error);
3382
		return error;
3383
	}
3384
3687
3385
	if (!(sc->rxon.filter & htole32(WPI_FILTER_BSS))) {
3688
		if (async)
3689
			WPI_NT_UNLOCK(sc);
3690
3386
		/* Add broadcast node. */
3691
		/* Add broadcast node. */
3387
		error = wpi_add_broadcast_node(sc, async);
3692
		error = wpi_add_broadcast_node(sc, async);
3388
		if (error != 0) {
3693
		if (error != 0) {
Lines 3392-3397 Link Here
3392
		}
3697
		}
3393
	}
3698
	}
3394
3699
3700
	/* Configuration has changed, set Tx power accordingly. */
3701
	if ((error = wpi_set_txpower(sc, async)) != 0) {
3702
		device_printf(sc->sc_dev,
3703
		    "%s: could not set TX power, error %d\n", __func__, error);
3704
		return error;
3705
	}
3706
3395
	return 0;
3707
	return 0;
3396
}
3708
}
3397
3709
Lines 3404-3409 Link Here
3404
{
3716
{
3405
	struct ifnet *ifp = sc->sc_ifp;
3717
	struct ifnet *ifp = sc->sc_ifp;
3406
	struct ieee80211com *ic = ifp->if_l2com;
3718
	struct ieee80211com *ic = ifp->if_l2com;
3719
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3407
	uint32_t flags;
3720
	uint32_t flags;
3408
	int error;
3721
	int error;
3409
3722
Lines 3425-3431 Link Here
3425
3738
3426
	/* Configure adapter. */
3739
	/* Configure adapter. */
3427
	memset(&sc->rxon, 0, sizeof (struct wpi_rxon));
3740
	memset(&sc->rxon, 0, sizeof (struct wpi_rxon));
3428
	IEEE80211_ADDR_COPY(sc->rxon.myaddr, IF_LLADDR(ifp));
3741
	IEEE80211_ADDR_COPY(sc->rxon.myaddr, vap->iv_myaddr);
3429
3742
3430
	/* Set default channel. */
3743
	/* Set default channel. */
3431
	sc->rxon.chan = ieee80211_chan2ieee(ic, ic->ic_curchan);
3744
	sc->rxon.chan = ieee80211_chan2ieee(ic, ic->ic_curchan);
Lines 3442-3450 Link Here
3442
		sc->rxon.mode = WPI_MODE_IBSS;
3755
		sc->rxon.mode = WPI_MODE_IBSS;
3443
		sc->rxon.filter |= WPI_FILTER_BEACON;
3756
		sc->rxon.filter |= WPI_FILTER_BEACON;
3444
		break;
3757
		break;
3445
	/* XXX workaround for passive channels selection */
3758
	case IEEE80211_M_HOSTAP:
3759
		/* XXX workaround for beaconing */
3760
		sc->rxon.mode = WPI_MODE_IBSS;
3761
		sc->rxon.filter |= WPI_FILTER_ASSOC | WPI_FILTER_PROMISC;
3762
		break;
3446
	case IEEE80211_M_AHDEMO:
3763
	case IEEE80211_M_AHDEMO:
3447
	case IEEE80211_M_HOSTAP:
3764
		/* XXX workaround for passive channels selection */
3448
		sc->rxon.mode = WPI_MODE_HOSTAP;
3765
		sc->rxon.mode = WPI_MODE_HOSTAP;
3449
		break;
3766
		break;
3450
	case IEEE80211_M_MONITOR:
3767
	case IEEE80211_M_MONITOR:
Lines 3451-3457 Link Here
3451
		sc->rxon.mode = WPI_MODE_MONITOR;
3768
		sc->rxon.mode = WPI_MODE_MONITOR;
3452
		break;
3769
		break;
3453
	default:
3770
	default:
3454
		device_printf(sc->sc_dev, "unknown opmode %d\n", ic->ic_opmode);
3771
		device_printf(sc->sc_dev, "unknown opmode %d\n",
3772
		    ic->ic_opmode);
3455
		return EINVAL;
3773
		return EINVAL;
3456
	}
3774
	}
3457
	sc->rxon.filter = htole32(sc->rxon.filter);
3775
	sc->rxon.filter = htole32(sc->rxon.filter);
Lines 3510-3523 Link Here
3510
wpi_limit_dwell(struct wpi_softc *sc, uint16_t dwell_time)
3828
wpi_limit_dwell(struct wpi_softc *sc, uint16_t dwell_time)
3511
{
3829
{
3512
	struct ieee80211com *ic = sc->sc_ifp->if_l2com;
3830
	struct ieee80211com *ic = sc->sc_ifp->if_l2com;
3513
	struct ieee80211vap *vap = NULL;
3831
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3514
	int bintval = 0;
3832
	int bintval = 0;
3515
3833
3516
	/* bintval is in TU (1.024mS) */
3834
	/* bintval is in TU (1.024mS) */
3517
	if (! TAILQ_EMPTY(&ic->ic_vaps)) {
3835
	if (vap != NULL)
3518
		vap = TAILQ_FIRST(&ic->ic_vaps);
3519
		bintval = vap->iv_bss->ni_intval;
3836
		bintval = vap->iv_bss->ni_intval;
3520
	}
3521
3837
3522
	/*
3838
	/*
3523
	 * If it's non-zero, we should calculate the minimum of
3839
	 * If it's non-zero, we should calculate the minimum of
Lines 3559-3564 Link Here
3559
	struct ifnet *ifp = sc->sc_ifp;
3875
	struct ifnet *ifp = sc->sc_ifp;
3560
	struct ieee80211com *ic = ifp->if_l2com;
3876
	struct ieee80211com *ic = ifp->if_l2com;
3561
	struct ieee80211_scan_state *ss = ic->ic_scan;
3877
	struct ieee80211_scan_state *ss = ic->ic_scan;
3878
	struct ieee80211vap *vap = ss->ss_vap;
3562
	struct wpi_scan_hdr *hdr;
3879
	struct wpi_scan_hdr *hdr;
3563
	struct wpi_cmd_data *tx;
3880
	struct wpi_cmd_data *tx;
3564
	struct wpi_scan_essid *essids;
3881
	struct wpi_scan_essid *essids;
Lines 3575-3583 Link Here
3575
	 * We are absolutely not allowed to send a scan command when another
3892
	 * We are absolutely not allowed to send a scan command when another
3576
	 * scan command is pending.
3893
	 * scan command is pending.
3577
	 */
3894
	 */
3578
	if (sc->sc_scan_timer) {
3895
	if (atomic_cmpset_acq_32(&sc->sc_scan_timer, 0, 5) == 0) {
3579
		device_printf(sc->sc_dev, "%s: called whilst scanning!\n",
3896
		device_printf(sc->sc_dev, "%s: called whilst scanning!\n",
3580
		    __func__);
3897
		    __func__);
3898
3899
		DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
3900
3581
		return (EAGAIN);
3901
		return (EAGAIN);
3582
	}
3902
	}
3583
3903
Lines 3586-3592 Link Here
3586
		device_printf(sc->sc_dev,
3906
		device_printf(sc->sc_dev,
3587
		    "%s: could not allocate buffer for scan command\n",
3907
		    "%s: could not allocate buffer for scan command\n",
3588
		    __func__);
3908
		    __func__);
3589
		return ENOMEM;
3909
		error = ENOMEM;
3910
		goto fail;
3590
	}
3911
	}
3591
	hdr = (struct wpi_scan_hdr *)buf;
3912
	hdr = (struct wpi_scan_hdr *)buf;
3592
3913
Lines 3645-3651 Link Here
3645
		IEEE80211_FC0_SUBTYPE_PROBE_REQ;
3966
		IEEE80211_FC0_SUBTYPE_PROBE_REQ;
3646
	wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
3967
	wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
3647
	IEEE80211_ADDR_COPY(wh->i_addr1, ifp->if_broadcastaddr);
3968
	IEEE80211_ADDR_COPY(wh->i_addr1, ifp->if_broadcastaddr);
3648
	IEEE80211_ADDR_COPY(wh->i_addr2, IF_LLADDR(ifp));
3969
	IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
3649
	IEEE80211_ADDR_COPY(wh->i_addr3, ifp->if_broadcastaddr);
3970
	IEEE80211_ADDR_COPY(wh->i_addr3, ifp->if_broadcastaddr);
3650
	*(uint16_t *)&wh->i_dur[0] = 0;	/* filled by h/w */
3971
	*(uint16_t *)&wh->i_dur[0] = 0;	/* filled by h/w */
3651
	*(uint16_t *)&wh->i_seq[0] = 0;	/* filled by h/w */
3972
	*(uint16_t *)&wh->i_seq[0] = 0;	/* filled by h/w */
Lines 3698-3704 Link Here
3698
		chan->rf_gain = 0x28;
4019
		chan->rf_gain = 0x28;
3699
4020
3700
	DPRINTF(sc, WPI_DEBUG_SCAN, "Scanning %u Passive: %d\n",
4021
	DPRINTF(sc, WPI_DEBUG_SCAN, "Scanning %u Passive: %d\n",
3701
	     chan->chan, IEEE80211_IS_CHAN_PASSIVE(c));
4022
	    chan->chan, IEEE80211_IS_CHAN_PASSIVE(c));
3702
4023
3703
	hdr->nchan++;
4024
	hdr->nchan++;
3704
	chan++;
4025
	chan++;
Lines 3711-3720 Link Here
3711
	error = wpi_cmd(sc, WPI_CMD_SCAN, buf, buflen, 1);
4032
	error = wpi_cmd(sc, WPI_CMD_SCAN, buf, buflen, 1);
3712
	free(buf, M_DEVBUF);
4033
	free(buf, M_DEVBUF);
3713
4034
3714
	sc->sc_scan_timer = 5;
4035
	if (error != 0)
4036
		goto fail;
3715
4037
3716
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
4038
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3717
4039
4040
	return 0;
4041
4042
fail:	atomic_store_rel_32(&sc->sc_scan_timer, 0);
4043
4044
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
4045
3718
	return error;
4046
	return error;
3719
}
4047
}
3720
4048
Lines 3728-3733 Link Here
3728
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
4056
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
3729
4057
3730
	/* Update adapter configuration. */
4058
	/* Update adapter configuration. */
4059
	WPI_RXON_LOCK(sc);
3731
	sc->rxon.associd = 0;
4060
	sc->rxon.associd = 0;
3732
	sc->rxon.filter &= ~htole32(WPI_FILTER_BSS);
4061
	sc->rxon.filter &= ~htole32(WPI_FILTER_BSS);
3733
	IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid);
4062
	IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid);
Lines 3759-3764 Link Here
3759
		device_printf(sc->sc_dev, "%s: could not send RXON\n",
4088
		device_printf(sc->sc_dev, "%s: could not send RXON\n",
3760
		    __func__);
4089
		    __func__);
3761
	}
4090
	}
4091
	WPI_RXON_UNLOCK(sc);
3762
4092
3763
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
4093
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3764
4094
Lines 3766-3782 Link Here
3766
}
4096
}
3767
4097
3768
static int
4098
static int
4099
wpi_config_beacon(struct wpi_vap *wvp)
4100
{
4101
	struct ieee80211com *ic = wvp->wv_vap.iv_ic;
4102
	struct ieee80211_beacon_offsets *bo = &wvp->wv_boff;
4103
	struct wpi_buf *bcn = &wvp->wv_bcbuf;
4104
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
4105
	struct wpi_cmd_beacon *cmd = (struct wpi_cmd_beacon *)&bcn->data;
4106
	struct ieee80211_tim_ie *tie;
4107
	struct mbuf *m;
4108
	uint8_t *ptr;
4109
	int error;
4110
4111
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4112
4113
	WPI_VAP_LOCK_ASSERT(wvp);
4114
4115
	cmd->len = htole16(bcn->m->m_pkthdr.len);
4116
	cmd->plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ?
4117
	    wpi_ridx_to_plcp[WPI_RIDX_OFDM6] : wpi_ridx_to_plcp[WPI_RIDX_CCK1];
4118
4119
	/* XXX seems to be unused */
4120
	if (*(bo->bo_tim) == IEEE80211_ELEMID_TIM) {
4121
		tie = (struct ieee80211_tim_ie *) bo->bo_tim;
4122
		ptr = mtod(bcn->m, uint8_t *);
4123
4124
		cmd->tim = htole16(bo->bo_tim - ptr);
4125
		cmd->timsz = tie->tim_len;
4126
	}
4127
4128
	/* Necessary for recursion in ieee80211_beacon_update(). */
4129
	m = bcn->m;
4130
	bcn->m = m_dup(m, M_NOWAIT);
4131
	if (bcn->m == NULL) {
4132
		device_printf(sc->sc_dev,
4133
		    "%s: could not copy beacon frame\n", __func__);
4134
		error = ENOMEM;
4135
		goto end;
4136
	}
4137
4138
	if ((error = wpi_cmd2(sc, bcn, 1)) != 0) {
4139
		device_printf(sc->sc_dev,
4140
		    "%s: could not update beacon frame, error %d", __func__,
4141
		    error);
4142
	}
4143
4144
	/* Restore mbuf. */
4145
end:	bcn->m = m;
4146
4147
	return error;
4148
}
4149
4150
static int
3769
wpi_setup_beacon(struct wpi_softc *sc, struct ieee80211_node *ni)
4151
wpi_setup_beacon(struct wpi_softc *sc, struct ieee80211_node *ni)
3770
{
4152
{
3771
	struct ifnet *ifp = sc->sc_ifp;
4153
	struct wpi_vap *wvp = WPI_VAP(ni->ni_vap);
3772
	struct ieee80211com *ic = ifp->if_l2com;
3773
	struct ieee80211vap *vap = ni->ni_vap;
3774
	struct wpi_vap *wvp = WPI_VAP(vap);
3775
	struct wpi_buf *bcn = &wvp->wv_bcbuf;
4154
	struct wpi_buf *bcn = &wvp->wv_bcbuf;
3776
	struct ieee80211_beacon_offsets bo;
4155
	struct ieee80211_beacon_offsets *bo = &wvp->wv_boff;
3777
	struct wpi_cmd_beacon *cmd;
3778
	struct mbuf *m;
4156
	struct mbuf *m;
3779
	int totlen;
4157
	int error;
3780
4158
3781
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4159
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3782
4160
Lines 3783-3846 Link Here
3783
	if (ni->ni_chan == IEEE80211_CHAN_ANYC)
4161
	if (ni->ni_chan == IEEE80211_CHAN_ANYC)
3784
		return EINVAL;
4162
		return EINVAL;
3785
4163
3786
	m = ieee80211_beacon_alloc(ni, &bo);
4164
	m = ieee80211_beacon_alloc(ni, bo);
3787
	if (m == NULL) {
4165
	if (m == NULL) {
3788
		device_printf(sc->sc_dev,
4166
		device_printf(sc->sc_dev,
3789
		    "%s: could not allocate beacon frame\n", __func__);
4167
		    "%s: could not allocate beacon frame\n", __func__);
3790
		return ENOMEM;
4168
		return ENOMEM;
3791
	}
4169
	}
3792
	totlen = m->m_pkthdr.len;
3793
4170
3794
	if (bcn->data == NULL) {
4171
	WPI_VAP_LOCK(wvp);
3795
		cmd = malloc(sizeof(struct wpi_cmd_beacon), M_DEVBUF,
4172
	if (bcn->m != NULL)
3796
		    M_NOWAIT | M_ZERO);
4173
		m_freem(bcn->m);
3797
4174
3798
		if (cmd == NULL) {
4175
	bcn->m = m;
4176
4177
	error = wpi_config_beacon(wvp);
4178
	WPI_VAP_UNLOCK(wvp);
4179
4180
	return error;
4181
}
4182
4183
static void
4184
wpi_update_beacon(struct ieee80211vap *vap, int item)
4185
{
4186
	struct wpi_softc *sc = vap->iv_ic->ic_ifp->if_softc;
4187
	struct wpi_vap *wvp = WPI_VAP(vap);
4188
	struct wpi_buf *bcn = &wvp->wv_bcbuf;
4189
	struct ieee80211_beacon_offsets *bo = &wvp->wv_boff;
4190
	struct ieee80211_node *ni = vap->iv_bss;
4191
	int mcast = 0;
4192
4193
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
4194
4195
	WPI_VAP_LOCK(wvp);
4196
	if (bcn->m == NULL) {
4197
		bcn->m = ieee80211_beacon_alloc(ni, bo);
4198
		if (bcn->m == NULL) {
3799
			device_printf(sc->sc_dev,
4199
			device_printf(sc->sc_dev,
3800
			    "could not allocate buffer for beacon command\n");
4200
			    "%s: could not allocate beacon frame\n", __func__);
3801
			m_freem(m);
4201
			WPI_VAP_UNLOCK(wvp);
3802
			return ENOMEM;
4202
4203
			DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR,
4204
			    __func__);
4205
4206
			return;
3803
		}
4207
		}
4208
	}
4209
	WPI_VAP_UNLOCK(wvp);
3804
4210
3805
		cmd->id = WPI_ID_BROADCAST;
4211
	if (item == IEEE80211_BEACON_TIM)
3806
		cmd->ofdm_mask = 0xff;
4212
		mcast = 1;	/* TODO */
3807
		cmd->cck_mask = 0x0f;
3808
		cmd->lifetime = htole32(WPI_LIFETIME_INFINITE);
3809
		cmd->flags = htole32(WPI_TX_AUTO_SEQ | WPI_TX_INSERT_TSTAMP);
3810
4213
3811
		bcn->data = cmd;
4214
	setbit(bo->bo_flags, item);
3812
		bcn->ni = NULL;
4215
	ieee80211_beacon_update(ni, bo, bcn->m, mcast);
3813
		bcn->code = WPI_CMD_SET_BEACON;
3814
		bcn->ac = 4;
3815
		bcn->size = sizeof(struct wpi_cmd_beacon);
3816
	} else
3817
		cmd = bcn->data;
3818
4216
3819
	cmd->len = htole16(totlen);
4217
	WPI_VAP_LOCK(wvp);
3820
	cmd->plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ?
4218
	wpi_config_beacon(wvp);
3821
	    wpi_ridx_to_plcp[WPI_RIDX_OFDM6] : wpi_ridx_to_plcp[WPI_RIDX_CCK1];
4219
	WPI_VAP_UNLOCK(wvp);
3822
4220
3823
	/* NB: m will be freed in wpi_cmd_done() */
4221
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3824
	bcn->m = m;
3825
3826
	return wpi_cmd2(sc, bcn);
3827
}
4222
}
3828
4223
3829
static void
4224
static void
3830
wpi_update_beacon(struct ieee80211vap *vap, int item)
4225
wpi_newassoc(struct ieee80211_node *ni, int isnew)
3831
{
4226
{
3832
	struct ieee80211_node *ni = vap->iv_bss;
4227
	struct ieee80211vap *vap = ni->ni_vap;
3833
	struct ifnet *ifp = vap->iv_ifp;
4228
	struct wpi_softc *sc = ni->ni_ic->ic_ifp->if_softc;
3834
	struct wpi_softc *sc = ifp->if_softc;
4229
	struct wpi_node *wn = WPI_NODE(ni);
3835
	int error;
4230
	int error;
3836
4231
3837
	WPI_LOCK(sc);
4232
	WPI_NT_LOCK(sc);
3838
	if ((error = wpi_setup_beacon(sc, ni)) != 0) {
4233
3839
		device_printf(sc->sc_dev,
4234
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3840
		    "%s: could not update beacon frame, error %d", __func__,
4235
3841
		    error);
4236
	if (vap->iv_opmode != IEEE80211_M_STA && wn->id == WPI_ID_UNDEFINED) {
4237
		if ((error = wpi_add_ibss_node(sc, ni)) != 0) {
4238
			device_printf(sc->sc_dev,
4239
			    "%s: could not add IBSS node, error %d\n",
4240
			    __func__, error);
4241
		}
3842
	}
4242
	}
3843
	WPI_UNLOCK(sc);
4243
	WPI_NT_UNLOCK(sc);
3844
}
4244
}
3845
4245
3846
static int
4246
static int
Lines 3872-3877 Link Here
3872
	}
4272
	}
3873
4273
3874
	/* Update adapter configuration. */
4274
	/* Update adapter configuration. */
4275
	WPI_RXON_LOCK(sc);
3875
	IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid);
4276
	IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid);
3876
	sc->rxon.associd = htole16(IEEE80211_NODE_AID(ni));
4277
	sc->rxon.associd = htole16(IEEE80211_NODE_AID(ni));
3877
	sc->rxon.chan = ieee80211_chan2ieee(ic, ni->ni_chan);
4278
	sc->rxon.chan = ieee80211_chan2ieee(ic, ni->ni_chan);
Lines 3897-3904 Link Here
3897
	}
4298
	}
3898
	sc->rxon.filter |= htole32(WPI_FILTER_BSS);
4299
	sc->rxon.filter |= htole32(WPI_FILTER_BSS);
3899
4300
3900
	/* XXX put somewhere HC_QOS_SUPPORT_ASSOC + HC_IBSS_START */
3901
3902
	DPRINTF(sc, WPI_DEBUG_STATE, "rxon chan %d flags %x\n",
4301
	DPRINTF(sc, WPI_DEBUG_STATE, "rxon chan %d flags %x\n",
3903
	    sc->rxon.chan, sc->rxon.flags);
4302
	    sc->rxon.chan, sc->rxon.flags);
3904
4303
Lines 3908-3914 Link Here
3908
		return error;
4307
		return error;
3909
	}
4308
	}
3910
4309
3911
	if (vap->iv_opmode == IEEE80211_M_IBSS) {
4310
	/* Start periodic calibration timer. */
4311
	callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc);
4312
4313
	WPI_RXON_UNLOCK(sc);
4314
4315
	if (vap->iv_opmode == IEEE80211_M_IBSS ||
4316
	    vap->iv_opmode == IEEE80211_M_HOSTAP) {
3912
		if ((error = wpi_setup_beacon(sc, ni)) != 0) {
4317
		if ((error = wpi_setup_beacon(sc, ni)) != 0) {
3913
			device_printf(sc->sc_dev,
4318
			device_printf(sc->sc_dev,
3914
			    "%s: could not setup beacon, error %d\n", __func__,
4319
			    "%s: could not setup beacon, error %d\n", __func__,
Lines 3919-3926 Link Here
3919
4324
3920
	if (vap->iv_opmode == IEEE80211_M_STA) {
4325
	if (vap->iv_opmode == IEEE80211_M_STA) {
3921
		/* Add BSS node. */
4326
		/* Add BSS node. */
3922
		((struct wpi_node *)ni)->id = WPI_ID_BSS;
4327
		WPI_NT_LOCK(sc);
3923
		if ((error = wpi_add_node(sc, ni)) != 0) {
4328
		error = wpi_add_sta_node(sc, ni);
4329
		WPI_NT_UNLOCK(sc);
4330
		if (error != 0) {
3924
			device_printf(sc->sc_dev,
4331
			device_printf(sc->sc_dev,
3925
			    "%s: could not add BSS node, error %d\n", __func__,
4332
			    "%s: could not add BSS node, error %d\n", __func__,
3926
			    error);
4333
			    error);
Lines 3931-3941 Link Here
3931
	/* Link LED always on while associated. */
4338
	/* Link LED always on while associated. */
3932
	wpi_set_led(sc, WPI_LED_LINK, 0, 1);
4339
	wpi_set_led(sc, WPI_LED_LINK, 0, 1);
3933
4340
3934
	/* Start periodic calibration timer. */
3935
	callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc);
3936
3937
	/* Enable power-saving mode if requested by user. */
4341
	/* Enable power-saving mode if requested by user. */
3938
	if (vap->iv_flags & IEEE80211_F_PMGTON)
4342
	if ((vap->iv_flags & IEEE80211_F_PMGTON) &&
4343
	    vap->iv_opmode != IEEE80211_M_IBSS)
3939
		(void)wpi_set_pslevel(sc, 0, 3, 1);
4344
		(void)wpi_set_pslevel(sc, 0, 3, 1);
3940
	else
4345
	else
3941
		(void)wpi_set_pslevel(sc, 0, 0, 1);
4346
		(void)wpi_set_pslevel(sc, 0, 0, 1);
Lines 3946-3984 Link Here
3946
}
4351
}
3947
4352
3948
static int
4353
static int
3949
wpi_key_alloc(struct ieee80211vap *vap, struct ieee80211_key *k,
4354
wpi_load_key(struct ieee80211_node *ni, const struct ieee80211_key *k)
3950
    ieee80211_keyix *keyix, ieee80211_keyix *rxkeyix)
3951
{
4355
{
3952
	struct ifnet *ifp = vap->iv_ifp;
3953
	struct wpi_softc *sc = ifp->if_softc;
3954
3955
	if (!(&vap->iv_nw_keys[0] <= k &&
3956
	    k < &vap->iv_nw_keys[IEEE80211_WEP_NKID])) {
3957
		if (k->wk_flags & IEEE80211_KEY_GROUP) {
3958
			/* should not happen */
3959
			DPRINTF(sc, WPI_DEBUG_KEY, "%s: bogus group key\n",
3960
			    __func__);
3961
			return 0;
3962
		}
3963
		*keyix = 0;	/* NB: use key index 0 for ucast key */
3964
	} else {
3965
		*keyix = *rxkeyix = k - vap->iv_nw_keys;
3966
3967
		if (k->wk_cipher->ic_cipher == IEEE80211_CIPHER_AES_CCM)
3968
			k->wk_flags |= IEEE80211_KEY_SWCRYPT;
3969
	}
3970
	return 1;
3971
}
3972
3973
static int
3974
wpi_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k,
3975
    const uint8_t mac[IEEE80211_ADDR_LEN])
3976
{
3977
	const struct ieee80211_cipher *cip = k->wk_cipher;
4356
	const struct ieee80211_cipher *cip = k->wk_cipher;
3978
	struct ieee80211com *ic = vap->iv_ic;
4357
	struct ieee80211vap *vap = ni->ni_vap;
3979
	struct ieee80211_node *ni = vap->iv_bss;
4358
	struct wpi_softc *sc = ni->ni_ic->ic_ifp->if_softc;
3980
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
4359
	struct wpi_node *wn = WPI_NODE(ni);
3981
	struct wpi_node *wn = (void *)ni;
3982
	struct wpi_node_info node;
4360
	struct wpi_node_info node;
3983
	uint16_t kflags;
4361
	uint16_t kflags;
3984
	int error;
4362
	int error;
Lines 3985-4005 Link Here
3985
4363
3986
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4364
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3987
4365
4366
	if (wpi_check_node_entry(sc, wn->id) == 0) {
4367
		device_printf(sc->sc_dev, "%s: node does not exist\n",
4368
		    __func__);
4369
		return 0;
4370
	}
4371
3988
	switch (cip->ic_cipher) {
4372
	switch (cip->ic_cipher) {
3989
	case IEEE80211_CIPHER_AES_CCM:
4373
	case IEEE80211_CIPHER_AES_CCM:
3990
		if (k->wk_flags & IEEE80211_KEY_GROUP)
3991
			return 1;
3992
3993
		kflags = WPI_KFLAG_CCMP;
4374
		kflags = WPI_KFLAG_CCMP;
3994
		break;
4375
		break;
4376
3995
	default:
4377
	default:
3996
		/* null_key_set() */
4378
		device_printf(sc->sc_dev, "%s: unknown cipher %d\n", __func__,
3997
		return 1;
4379
		    cip->ic_cipher);
4380
		return 0;
3998
	}
4381
	}
3999
4382
4000
	if (wn->id == WPI_ID_UNDEFINED)
4001
		return 0;
4002
4003
	kflags |= WPI_KFLAG_KID(k->wk_keyix);
4383
	kflags |= WPI_KFLAG_KID(k->wk_keyix);
4004
	if (k->wk_flags & IEEE80211_KEY_GROUP)
4384
	if (k->wk_flags & IEEE80211_KEY_GROUP)
4005
		kflags |= WPI_KFLAG_MULTICAST;
4385
		kflags |= WPI_KFLAG_MULTICAST;
Lines 4010-4064 Link Here
4010
	node.flags = WPI_FLAG_KEY_SET;
4390
	node.flags = WPI_FLAG_KEY_SET;
4011
	node.kflags = htole16(kflags);
4391
	node.kflags = htole16(kflags);
4012
	memcpy(node.key, k->wk_key, k->wk_keylen);
4392
	memcpy(node.key, k->wk_key, k->wk_keylen);
4393
again:
4394
	DPRINTF(sc, WPI_DEBUG_KEY,
4395
	    "%s: setting %s key id %d for node %d (%s)\n", __func__,
4396
	    (kflags & WPI_KFLAG_MULTICAST) ? "group" : "ucast", k->wk_keyix,
4397
	    node.id, ether_sprintf(ni->ni_macaddr));
4013
4398
4014
	DPRINTF(sc, WPI_DEBUG_KEY, "set key id=%d for node %d\n", k->wk_keyix,
4015
	    node.id);
4016
4017
	error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
4399
	error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
4018
	if (error != 0) {
4400
	if (error != 0) {
4019
		device_printf(sc->sc_dev, "can't update node info, error %d\n",
4401
		device_printf(sc->sc_dev, "can't update node info, error %d\n",
4020
		    error);
4402
		    error);
4021
		return 0;
4403
		return !error;
4022
	}
4404
	}
4023
4405
4406
	if (!(kflags & WPI_KFLAG_MULTICAST) && &vap->iv_nw_keys[0] <= k &&
4407
	    k < &vap->iv_nw_keys[IEEE80211_WEP_NKID]) {
4408
		kflags |= WPI_KFLAG_MULTICAST;
4409
		node.kflags = htole16(kflags);
4410
4411
		goto again;
4412
	}
4413
4024
	return 1;
4414
	return 1;
4025
}
4415
}
4026
4416
4417
static void
4418
wpi_load_key_cb(void *arg, struct ieee80211_node *ni)
4419
{
4420
	const struct ieee80211_key *k = arg;
4421
	struct ieee80211vap *vap = ni->ni_vap;
4422
	struct wpi_softc *sc = ni->ni_ic->ic_ifp->if_softc;
4423
	struct wpi_node *wn = WPI_NODE(ni);
4424
	int error;
4425
4426
	if (vap->iv_bss == ni && wn->id == WPI_ID_UNDEFINED)
4427
		return;
4428
4429
	WPI_NT_LOCK(sc);
4430
	error = wpi_load_key(ni, k);
4431
	WPI_NT_UNLOCK(sc);
4432
4433
	if (error == 0) {
4434
		device_printf(sc->sc_dev, "%s: error while setting key\n",
4435
		    __func__);
4436
	}
4437
}
4438
4027
static int
4439
static int
4028
wpi_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k)
4440
wpi_set_global_keys(struct ieee80211_node *ni)
4029
{
4441
{
4030
	const struct ieee80211_cipher *cip = k->wk_cipher;
4442
	struct ieee80211vap *vap = ni->ni_vap;
4031
	struct ieee80211com *ic = vap->iv_ic;
4443
	struct ieee80211_key *wk = &vap->iv_nw_keys[0];
4032
	struct ieee80211_node *ni = vap->iv_bss;
4444
	int error = 1;
4033
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
4445
4034
	struct wpi_node *wn = (void *)ni;
4446
	for (; wk < &vap->iv_nw_keys[IEEE80211_WEP_NKID] && error; wk++)
4447
		if (wk->wk_keyix != IEEE80211_KEYIX_NONE)
4448
			error = wpi_load_key(ni, wk);
4449
4450
	return !error;
4451
}
4452
4453
static int
4454
wpi_del_key(struct ieee80211_node *ni, const struct ieee80211_key *k)
4455
{
4456
	struct ieee80211vap *vap = ni->ni_vap;
4457
	struct wpi_softc *sc = ni->ni_ic->ic_ifp->if_softc;
4458
	struct wpi_node *wn = WPI_NODE(ni);
4035
	struct wpi_node_info node;
4459
	struct wpi_node_info node;
4460
	uint16_t kflags;
4461
	int error;
4036
4462
4037
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4463
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4038
4464
4039
	switch (cip->ic_cipher) {
4465
	if (wpi_check_node_entry(sc, wn->id) == 0) {
4040
	case IEEE80211_CIPHER_AES_CCM:
4466
		DPRINTF(sc, WPI_DEBUG_KEY, "%s: node was removed\n", __func__);
4041
		break;
4467
		return 1;	/* Nothing to do. */
4042
	default:
4043
		/* null_key_delete() */
4044
		return 1;
4045
	}
4468
	}
4046
4469
4047
	if (vap->iv_state != IEEE80211_S_RUN ||
4470
	kflags = WPI_KFLAG_KID(k->wk_keyix);
4048
	    (k->wk_flags & IEEE80211_KEY_GROUP))
4471
	if (k->wk_flags & IEEE80211_KEY_GROUP)
4049
		return 1; /* Nothing to do. */
4472
		kflags |= WPI_KFLAG_MULTICAST;
4050
4473
4051
	memset(&node, 0, sizeof node);
4474
	memset(&node, 0, sizeof node);
4052
	node.id = wn->id;
4475
	node.id = wn->id;
4053
	node.control = WPI_NODE_UPDATE;
4476
	node.control = WPI_NODE_UPDATE;
4054
	node.flags = WPI_FLAG_KEY_SET;
4477
	node.flags = WPI_FLAG_KEY_SET;
4478
	node.kflags = htole16(kflags);
4479
again:
4480
	DPRINTF(sc, WPI_DEBUG_KEY, "%s: deleting %s key %d for node %d (%s)\n",
4481
	    __func__, (kflags & WPI_KFLAG_MULTICAST) ? "group" : "ucast",
4482
	    k->wk_keyix, node.id, ether_sprintf(ni->ni_macaddr));
4055
4483
4056
	DPRINTF(sc, WPI_DEBUG_KEY, "delete keys for node %d\n", node.id);
4484
	error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
4057
	(void)wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
4485
	if (error != 0) {
4486
		device_printf(sc->sc_dev, "can't update node info, error %d\n",
4487
		    error);
4488
		return !error;
4489
	}
4058
4490
4491
	if (!(kflags & WPI_KFLAG_MULTICAST) && &vap->iv_nw_keys[0] <= k &&
4492
	    k < &vap->iv_nw_keys[IEEE80211_WEP_NKID]) {
4493
		kflags |= WPI_KFLAG_MULTICAST;
4494
		node.kflags = htole16(kflags);
4495
4496
		goto again;
4497
	}
4498
4059
	return 1;
4499
	return 1;
4060
}
4500
}
4061
4501
4502
static void
4503
wpi_del_key_cb(void *arg, struct ieee80211_node *ni)
4504
{
4505
	const struct ieee80211_key *k = arg;
4506
	struct ieee80211vap *vap = ni->ni_vap;
4507
	struct wpi_softc *sc = ni->ni_ic->ic_ifp->if_softc;
4508
	struct wpi_node *wn = WPI_NODE(ni);
4509
	int error;
4510
4511
	if (vap->iv_bss == ni && wn->id == WPI_ID_UNDEFINED)
4512
		return;
4513
4514
	WPI_NT_LOCK(sc);
4515
	error = wpi_del_key(ni, k);
4516
	WPI_NT_UNLOCK(sc);
4517
4518
	if (error == 0) {
4519
		device_printf(sc->sc_dev, "%s: error while deleting key\n",
4520
		    __func__);
4521
	}
4522
}
4523
4524
static int
4525
wpi_process_key(struct ieee80211vap *vap, const struct ieee80211_key *k,
4526
    int set)
4527
{
4528
	struct ieee80211com *ic = vap->iv_ic;
4529
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
4530
	struct wpi_vap *wvp = WPI_VAP(vap);
4531
	struct ieee80211_node *ni;
4532
	int error, ni_ref = 0;
4533
4534
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4535
4536
	if (k->wk_flags & IEEE80211_KEY_SWCRYPT) {
4537
		/* Not for us. */
4538
		return 1;
4539
	}
4540
4541
	if (!(k->wk_flags & IEEE80211_KEY_RECV)) {
4542
		/* XMIT keys are handled in wpi_tx_data(). */
4543
		return 1;
4544
	}
4545
4546
	/* Handle group keys. */
4547
	if (&vap->iv_nw_keys[0] <= k &&
4548
	    k < &vap->iv_nw_keys[IEEE80211_WEP_NKID]) {
4549
		if (set) {
4550
			atomic_set_acq_32(&wvp->wv_gtk,
4551
			    WPI_VAP_KEY(k->wk_keyix));
4552
		} else {
4553
			atomic_clear_acq_32(&wvp->wv_gtk,
4554
			    WPI_VAP_KEY(k->wk_keyix));
4555
		}
4556
4557
		if (vap->iv_state == IEEE80211_S_RUN) {
4558
			ieee80211_iterate_nodes(&ic->ic_sta,
4559
			    set ? wpi_load_key_cb : wpi_del_key_cb, (void *)k);
4560
		}
4561
4562
		return 1;
4563
	}
4564
4565
	switch (vap->iv_opmode) {
4566
	case IEEE80211_M_STA:
4567
		ni = vap->iv_bss;
4568
		break;
4569
4570
	case IEEE80211_M_IBSS:
4571
	case IEEE80211_M_AHDEMO:
4572
	case IEEE80211_M_HOSTAP:
4573
		ni = ieee80211_find_vap_node(&ic->ic_sta, vap, k->wk_macaddr);
4574
		if (ni == NULL)
4575
			return 0;	/* should not happen */
4576
4577
		ni_ref = 1;
4578
		break;
4579
4580
	default:
4581
		device_printf(sc->sc_dev, "%s: unknown opmode %d\n", __func__,
4582
		    vap->iv_opmode);
4583
		return 0;
4584
	}
4585
4586
	WPI_NT_LOCK(sc);
4587
	if (set)
4588
		error = wpi_load_key(ni, k);
4589
	else
4590
		error = wpi_del_key(ni, k);
4591
	WPI_NT_UNLOCK(sc);
4592
4593
	if (ni_ref)
4594
		ieee80211_node_decref(ni);
4595
4596
	return error;
4597
}
4598
4599
static int
4600
wpi_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k,
4601
    const uint8_t mac[IEEE80211_ADDR_LEN])
4602
{
4603
	return wpi_process_key(vap, k, 1);
4604
}
4605
4606
static int
4607
wpi_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k)
4608
{
4609
	return wpi_process_key(vap, k, 0);
4610
}
4611
4062
/*
4612
/*
4063
 * This function is called after the runtime firmware notifies us of its
4613
 * This function is called after the runtime firmware notifies us of its
4064
 * readiness (called in a process context).
4614
 * readiness (called in a process context).
Lines 4093-4103 Link Here
4093
	if (ntries == 1000) {
4643
	if (ntries == 1000) {
4094
		device_printf(sc->sc_dev,
4644
		device_printf(sc->sc_dev,
4095
		    "timeout waiting for thermal sensor calibration\n");
4645
		    "timeout waiting for thermal sensor calibration\n");
4096
                return ETIMEDOUT;
4646
		return ETIMEDOUT;
4097
        }
4647
	}
4098
4648
4099
        DPRINTF(sc, WPI_DEBUG_TEMP, "temperature %d\n", sc->temp);
4649
	DPRINTF(sc, WPI_DEBUG_TEMP, "temperature %d\n", sc->temp);
4100
        return 0;
4650
	return 0;
4101
}
4651
}
4102
4652
4103
/*
4653
/*
Lines 4192-4198 Link Here
4192
	WPI_WRITE(sc, WPI_RESET, 0);
4742
	WPI_WRITE(sc, WPI_RESET, 0);
4193
4743
4194
	/* Wait at most one second for first alive notification. */
4744
	/* Wait at most one second for first alive notification. */
4195
	if ((error = msleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) {
4745
	if ((error = mtx_sleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) {
4196
		device_printf(sc->sc_dev,
4746
		device_printf(sc->sc_dev,
4197
		    "%s: timeout waiting for adapter to initialize, error %d\n",
4747
		    "%s: timeout waiting for adapter to initialize, error %d\n",
4198
		    __func__, error);
4748
		    __func__, error);
Lines 4297-4304 Link Here
4297
4847
4298
	DPRINTF(sc, WPI_DEBUG_FIRMWARE,
4848
	DPRINTF(sc, WPI_DEBUG_FIRMWARE,
4299
	    "Firmware Version: Major %d, Minor %d, Driver %d, \n"
4849
	    "Firmware Version: Major %d, Minor %d, Driver %d, \n"
4300
	    "runtime (text: %u, data: %u) init (text: %u, data %u) boot (text %u)\n",
4850
	    "runtime (text: %u, data: %u) init (text: %u, data %u) "
4301
	    hdr->major, hdr->minor, le32toh(hdr->driver),
4851
	    "boot (text %u)\n", hdr->major, hdr->minor, le32toh(hdr->driver),
4302
	    fw->main.textsz, fw->main.datasz,
4852
	    fw->main.textsz, fw->main.datasz,
4303
	    fw->init.textsz, fw->init.datasz, fw->boot.textsz);
4853
	    fw->init.textsz, fw->init.datasz, fw->boot.textsz);
4304
4854
Lines 4362-4367 Link Here
4362
	/* Set FH wait threshold to max (HW bug under stress workaround). */
4912
	/* Set FH wait threshold to max (HW bug under stress workaround). */
4363
	WPI_SETBITS(sc, WPI_DBG_HPET_MEM, 0xffff0000);
4913
	WPI_SETBITS(sc, WPI_DBG_HPET_MEM, 0xffff0000);
4364
4914
4915
	/* Cleanup. */
4916
	wpi_prph_write(sc, WPI_APMG_CLK_DIS, 0x00000400);
4917
	wpi_prph_clrbits(sc, WPI_APMG_PS, 0x00000E00);
4918
4365
	/* Retrieve PCIe Active State Power Management (ASPM). */
4919
	/* Retrieve PCIe Active State Power Management (ASPM). */
4366
	reg = pci_read_config(sc->sc_dev, sc->sc_cap_off + 0x10, 1);
4920
	reg = pci_read_config(sc->sc_dev, sc->sc_cap_off + 0x10, 1);
4367
	/* Workaround for HW instability in PCIe L0->L0s->L1 transition. */
4921
	/* Workaround for HW instability in PCIe L0->L0s->L1 transition. */
Lines 4384-4391 Link Here
4384
	DELAY(20);
4938
	DELAY(20);
4385
	/* Disable L1-Active. */
4939
	/* Disable L1-Active. */
4386
	wpi_prph_setbits(sc, WPI_APMG_PCI_STT, WPI_APMG_PCI_STT_L1A_DIS);
4940
	wpi_prph_setbits(sc, WPI_APMG_PCI_STT, WPI_APMG_PCI_STT_L1A_DIS);
4387
	/* ??? */
4388
	wpi_prph_clrbits(sc, WPI_APMG_PS, 0x00000E00);
4389
	wpi_nic_unlock(sc);
4941
	wpi_nic_unlock(sc);
4390
4942
4391
	return 0;
4943
	return 0;
Lines 4408-4414 Link Here
4408
			return;
4960
			return;
4409
		DELAY(10);
4961
		DELAY(10);
4410
	}
4962
	}
4411
	device_printf(sc->sc_dev, "%s: timeout waiting for master\n", __func__);
4963
	device_printf(sc->sc_dev, "%s: timeout waiting for master\n",
4964
	    __func__);
4412
}
4965
}
4413
4966
4414
static void
4967
static void
Lines 4440-4446 Link Here
4440
	if (sc->cap == 0x80)
4993
	if (sc->cap == 0x80)
4441
		WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_SKU_MRC);
4994
		WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_SKU_MRC);
4442
4995
4443
	if ((le16toh(sc->rev) & 0xf0) == 0xd0)
4996
	if ((sc->rev & 0xf0) == 0xd0)
4444
		WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_REV_D);
4997
		WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_REV_D);
4445
	else
4998
	else
4446
		WPI_CLRBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_REV_D);
4999
		WPI_CLRBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_REV_D);
Lines 4551-4557 Link Here
4551
		return error;
5104
		return error;
4552
	}
5105
	}
4553
	/* Wait at most one second for firmware alive notification. */
5106
	/* Wait at most one second for firmware alive notification. */
4554
	if ((error = msleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) {
5107
	if ((error = mtx_sleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) {
4555
		device_printf(sc->sc_dev,
5108
		device_printf(sc->sc_dev,
4556
		    "%s: timeout waiting for adapter to initialize, error %d\n",
5109
		    "%s: timeout waiting for adapter to initialize, error %d\n",
4557
		    __func__, error);
5110
		    __func__, error);
Lines 4659-4672 Link Here
4659
}
5212
}
4660
5213
4661
static void
5214
static void
4662
wpi_init_locked(struct wpi_softc *sc)
5215
wpi_init(void *arg)
4663
{
5216
{
5217
	struct wpi_softc *sc = arg;
4664
	struct ifnet *ifp = sc->sc_ifp;
5218
	struct ifnet *ifp = sc->sc_ifp;
5219
	struct ieee80211com *ic = ifp->if_l2com;
4665
	int error;
5220
	int error;
4666
5221
5222
	WPI_LOCK(sc);
5223
4667
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
5224
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
4668
5225
4669
	WPI_LOCK_ASSERT(sc);
5226
	if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
5227
		goto end;
4670
5228
4671
	/* Check that the radio is not disabled by hardware switch. */
5229
	/* Check that the radio is not disabled by hardware switch. */
4672
	if (!(WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_RFKILL)) {
5230
	if (!(WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_RFKILL)) {
Lines 4674-4680 Link Here
4674
		    "RF switch: radio disabled (%s)\n", __func__);
5232
		    "RF switch: radio disabled (%s)\n", __func__);
4675
		callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill,
5233
		callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill,
4676
		    sc);
5234
		    sc);
4677
		return;
5235
		goto end;
4678
	}
5236
	}
4679
5237
4680
	/* Read firmware images from the filesystem. */
5238
	/* Read firmware images from the filesystem. */
Lines 4695-4700 Link Here
4695
		goto fail;
5253
		goto fail;
4696
	}
5254
	}
4697
5255
5256
	atomic_store_rel_32(&sc->txq_active, 1);
5257
4698
	/* Configure adapter now that it is ready. */
5258
	/* Configure adapter now that it is ready. */
4699
	if ((error = wpi_config(sc)) != 0) {
5259
	if ((error = wpi_config(sc)) != 0) {
4700
		device_printf(sc->sc_dev,
5260
		device_printf(sc->sc_dev,
Lines 4703-4734 Link Here
4703
		goto fail;
5263
		goto fail;
4704
	}
5264
	}
4705
5265
5266
	IF_LOCK(&ifp->if_snd);
4706
	ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
5267
	ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
4707
	ifp->if_drv_flags |= IFF_DRV_RUNNING;
5268
	ifp->if_drv_flags |= IFF_DRV_RUNNING;
5269
	IF_UNLOCK(&ifp->if_snd);
4708
5270
4709
	callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
5271
	callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
4710
5272
5273
	WPI_UNLOCK(sc);
5274
5275
	ieee80211_start_all(ic);
5276
4711
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
5277
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
4712
5278
4713
	return;
5279
	return;
4714
5280
4715
fail:	wpi_stop_locked(sc);
5281
fail:	wpi_stop_locked(sc);
4716
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
5282
end:	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
4717
}
4718
4719
static void
4720
wpi_init(void *arg)
4721
{
4722
	struct wpi_softc *sc = arg;
4723
	struct ifnet *ifp = sc->sc_ifp;
4724
	struct ieee80211com *ic = ifp->if_l2com;
4725
4726
	WPI_LOCK(sc);
4727
	wpi_init_locked(sc);
4728
	WPI_UNLOCK(sc);
5283
	WPI_UNLOCK(sc);
4729
4730
	if (ifp->if_drv_flags & IFF_DRV_RUNNING)
4731
		ieee80211_start_all(ic);
4732
}
5284
}
4733
5285
4734
static void
5286
static void
Lines 4738-4748 Link Here
4738
5290
4739
	WPI_LOCK_ASSERT(sc);
5291
	WPI_LOCK_ASSERT(sc);
4740
5292
4741
	sc->sc_scan_timer = 0;
5293
	atomic_store_rel_32(&sc->txq_active, 0);
4742
	sc->sc_tx_timer = 0;
5294
	atomic_store_rel_32(&sc->sc_scan_timer, 0);
5295
	atomic_store_rel_32(&sc->sc_tx_timer, 0);
5296
4743
	callout_stop(&sc->watchdog_to);
5297
	callout_stop(&sc->watchdog_to);
5298
5299
	WPI_RXON_LOCK(sc);
4744
	callout_stop(&sc->calib_to);
5300
	callout_stop(&sc->calib_to);
5301
	WPI_RXON_UNLOCK(sc);
5302
5303
	IF_LOCK(&ifp->if_snd);
4745
	ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
5304
	ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
5305
	IF_UNLOCK(&ifp->if_snd);
4746
5306
4747
	/* Power OFF hardware. */
5307
	/* Power OFF hardware. */
4748
	wpi_hw_stop(sc);
5308
	wpi_hw_stop(sc);
Lines 4762-4773 Link Here
4762
static void
5322
static void
4763
wpi_scan_start(struct ieee80211com *ic)
5323
wpi_scan_start(struct ieee80211com *ic)
4764
{
5324
{
4765
	struct ifnet *ifp = ic->ic_ifp;
5325
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
4766
	struct wpi_softc *sc = ifp->if_softc;
4767
5326
4768
	WPI_LOCK(sc);
4769
	wpi_set_led(sc, WPI_LED_LINK, 20, 2);
5327
	wpi_set_led(sc, WPI_LED_LINK, 20, 2);
4770
	WPI_UNLOCK(sc);
4771
}
5328
}
4772
5329
4773
/*
5330
/*
Lines 4780-4790 Link Here
4780
	struct wpi_softc *sc = ifp->if_softc;
5337
	struct wpi_softc *sc = ifp->if_softc;
4781
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
5338
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
4782
5339
4783
	if (vap->iv_state == IEEE80211_S_RUN) {
5340
	if (vap->iv_state == IEEE80211_S_RUN)
4784
		WPI_LOCK(sc);
4785
		wpi_set_led(sc, WPI_LED_LINK, 0, 1);
5341
		wpi_set_led(sc, WPI_LED_LINK, 0, 1);
4786
		WPI_UNLOCK(sc);
4787
	}
4788
}
5342
}
4789
5343
4790
/**
5344
/**
Lines 4804-4811 Link Here
4804
	WPI_LOCK(sc);
5358
	WPI_LOCK(sc);
4805
	sc->sc_rxtap.wr_chan_freq = htole16(c->ic_freq);
5359
	sc->sc_rxtap.wr_chan_freq = htole16(c->ic_freq);
4806
	sc->sc_rxtap.wr_chan_flags = htole16(c->ic_flags);
5360
	sc->sc_rxtap.wr_chan_flags = htole16(c->ic_flags);
5361
	WPI_UNLOCK(sc);
5362
	WPI_TX_LOCK(sc);
4807
	sc->sc_txtap.wt_chan_freq = htole16(c->ic_freq);
5363
	sc->sc_txtap.wt_chan_freq = htole16(c->ic_freq);
4808
	sc->sc_txtap.wt_chan_flags = htole16(c->ic_flags);
5364
	sc->sc_txtap.wt_chan_flags = htole16(c->ic_flags);
5365
	WPI_TX_UNLOCK(sc);
4809
5366
4810
	/*
5367
	/*
4811
	 * Only need to set the channel in Monitor mode. AP scanning and auth
5368
	 * Only need to set the channel in Monitor mode. AP scanning and auth
Lines 4812-4817 Link Here
4812
	 * are already taken care of by their respective firmware commands.
5369
	 * are already taken care of by their respective firmware commands.
4813
	 */
5370
	 */
4814
	if (ic->ic_opmode == IEEE80211_M_MONITOR) {
5371
	if (ic->ic_opmode == IEEE80211_M_MONITOR) {
5372
		WPI_RXON_LOCK(sc);
4815
		sc->rxon.chan = ieee80211_chan2ieee(ic, c);
5373
		sc->rxon.chan = ieee80211_chan2ieee(ic, c);
4816
		if (IEEE80211_IS_CHAN_2GHZ(c)) {
5374
		if (IEEE80211_IS_CHAN_2GHZ(c)) {
4817
			sc->rxon.flags |= htole32(WPI_RXON_AUTO |
5375
			sc->rxon.flags |= htole32(WPI_RXON_AUTO |
Lines 4820-4831 Link Here
4820
			sc->rxon.flags &= ~htole32(WPI_RXON_AUTO |
5378
			sc->rxon.flags &= ~htole32(WPI_RXON_AUTO |
4821
			    WPI_RXON_24GHZ);
5379
			    WPI_RXON_24GHZ);
4822
		}
5380
		}
4823
		if ((error = wpi_send_rxon(sc, 0, 0)) != 0)
5381
		if ((error = wpi_send_rxon(sc, 0, 1)) != 0)
4824
			device_printf(sc->sc_dev,
5382
			device_printf(sc->sc_dev,
4825
			    "%s: error %d settting channel\n", __func__,
5383
			    "%s: error %d setting channel\n", __func__,
4826
			    error);
5384
			    error);
5385
		WPI_RXON_UNLOCK(sc);
4827
	}
5386
	}
4828
	WPI_UNLOCK(sc);
4829
}
5387
}
4830
5388
4831
/**
5389
/**
Lines 4838-4852 Link Here
4838
{
5396
{
4839
	struct ieee80211vap *vap = ss->ss_vap;
5397
	struct ieee80211vap *vap = ss->ss_vap;
4840
	struct ieee80211com *ic = vap->iv_ic;
5398
	struct ieee80211com *ic = vap->iv_ic;
4841
	struct ifnet *ifp = ic->ic_ifp;
5399
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
4842
	struct wpi_softc *sc = ifp->if_softc;
5400
	uint8_t curchan;
4843
	int error;
4844
5401
4845
	if (sc->rxon.chan != ieee80211_chan2ieee(ic, ic->ic_curchan)) {
5402
	WPI_RXON_LOCK(sc);
4846
		WPI_LOCK(sc);
5403
	curchan = sc->rxon.chan;
4847
		error = wpi_scan(sc, ic->ic_curchan);
5404
	WPI_RXON_UNLOCK(sc);
4848
		WPI_UNLOCK(sc);
5405
4849
		if (error != 0)
5406
	if (curchan != ieee80211_chan2ieee(ic, ic->ic_curchan)) {
5407
		if (wpi_scan(sc, ic->ic_curchan) != 0)
4850
			ieee80211_cancel_scan(vap);
5408
			ieee80211_cancel_scan(vap);
4851
	} else {
5409
	} else {
4852
		/* Send probe request when associated. */
5410
		/* Send probe request when associated. */
(-)sys/dev/wpi/if_wpi_debug.h (-28 / +72 lines)
Lines 39-46 Link Here
39
	WPI_DEBUG_TRACE		= 0x00002000,	/* Print begin and start driver function */
39
	WPI_DEBUG_TRACE		= 0x00002000,	/* Print begin and start driver function */
40
	WPI_DEBUG_PWRSAVE	= 0x00004000,	/* Power save operations */
40
	WPI_DEBUG_PWRSAVE	= 0x00004000,	/* Power save operations */
41
	WPI_DEBUG_EEPROM	= 0x00008000,	/* EEPROM info */
41
	WPI_DEBUG_EEPROM	= 0x00008000,	/* EEPROM info */
42
	WPI_DEBUG_KEY		= 0x00010000,	/* node key management */
42
	WPI_DEBUG_NODE		= 0x00010000,	/* node addition/removal */
43
	WPI_DEBUG_EDCA		= 0x00020000,	/* WME info */
43
	WPI_DEBUG_KEY		= 0x00020000,	/* node key management */
44
	WPI_DEBUG_EDCA		= 0x00040000,	/* WME info */
45
	WPI_DEBUG_REGISTER	= 0x00080000,	/* print chipset register */
44
	WPI_DEBUG_ANY		= 0xffffffff
46
	WPI_DEBUG_ANY		= 0xffffffff
45
};
47
};
46
48
Lines 54-89 Link Here
54
#define TRACE_STR_END		"->%s: end\n"
56
#define TRACE_STR_END		"->%s: end\n"
55
#define TRACE_STR_END_ERR	"->%s: end in error\n"
57
#define TRACE_STR_END_ERR	"->%s: end in error\n"
56
58
59
#define WPI_DESC(x) case x:	return #x
60
57
static const char *wpi_cmd_str(int cmd)
61
static const char *wpi_cmd_str(int cmd)
58
{
62
{
59
	switch (cmd) {
63
	switch (cmd) {
60
	/* Notifications */
64
		/* Notifications. */
61
	case WPI_UC_READY:		return "UC_READY";
65
		WPI_DESC(WPI_UC_READY);
62
	case WPI_RX_DONE:		return "RX_DONE";
66
		WPI_DESC(WPI_RX_DONE);
63
	case WPI_START_SCAN:		return "START_SCAN";
67
		WPI_DESC(WPI_START_SCAN);
64
	case WPI_SCAN_RESULTS:		return "SCAN_RESULTS";
68
		WPI_DESC(WPI_SCAN_RESULTS);
65
	case WPI_STOP_SCAN:		return "STOP_SCAN";
69
		WPI_DESC(WPI_STOP_SCAN);
66
	case WPI_BEACON_SENT:		return "BEACON_SENT";
70
		WPI_DESC(WPI_BEACON_SENT);
67
	case WPI_RX_STATISTICS:		return "RX_STATS";
71
		WPI_DESC(WPI_RX_STATISTICS);
68
	case WPI_BEACON_STATISTICS:	return "BEACON_STATS";
72
		WPI_DESC(WPI_BEACON_STATISTICS);
69
	case WPI_STATE_CHANGED:		return "STATE_CHANGED";
73
		WPI_DESC(WPI_STATE_CHANGED);
70
	case WPI_BEACON_MISSED:		return "BEACON_MISSED";
74
		WPI_DESC(WPI_BEACON_MISSED);
71
75
72
	/* Command notifications */
76
		/* Command notifications. */
73
	case WPI_CMD_RXON:		return "WPI_CMD_RXON";
77
		WPI_DESC(WPI_CMD_RXON);
74
	case WPI_CMD_RXON_ASSOC:	return "WPI_CMD_RXON_ASSOC";
78
		WPI_DESC(WPI_CMD_RXON_ASSOC);
75
	case WPI_CMD_EDCA_PARAMS:	return "WPI_CMD_EDCA_PARAMS";
79
		WPI_DESC(WPI_CMD_EDCA_PARAMS);
76
	case WPI_CMD_TIMING:		return "WPI_CMD_TIMING";
80
		WPI_DESC(WPI_CMD_TIMING);
77
	case WPI_CMD_ADD_NODE:		return "WPI_CMD_ADD_NODE";
81
		WPI_DESC(WPI_CMD_ADD_NODE);
78
	case WPI_CMD_DEL_NODE:		return "WPI_CMD_DEL_NODE";
82
		WPI_DESC(WPI_CMD_DEL_NODE);
79
	case WPI_CMD_TX_DATA:		return "WPI_CMD_TX_DATA";
83
		WPI_DESC(WPI_CMD_TX_DATA);
80
	case WPI_CMD_MRR_SETUP:		return "WPI_CMD_MRR_SETUP";
84
		WPI_DESC(WPI_CMD_MRR_SETUP);
81
	case WPI_CMD_SET_LED:		return "WPI_CMD_SET_LED";
85
		WPI_DESC(WPI_CMD_SET_LED);
82
	case WPI_CMD_SET_POWER_MODE:	return "WPI_CMD_SET_POWER_MODE";
86
		WPI_DESC(WPI_CMD_SET_POWER_MODE);
83
	case WPI_CMD_SCAN:		return "WPI_CMD_SCAN";
87
		WPI_DESC(WPI_CMD_SCAN);
84
	case WPI_CMD_SET_BEACON:	return "WPI_CMD_SET_BEACON";
88
		WPI_DESC(WPI_CMD_SET_BEACON);
85
	case WPI_CMD_TXPOWER:		return "WPI_CMD_TXPOWER";
89
		WPI_DESC(WPI_CMD_TXPOWER);
86
	case WPI_CMD_BT_COEX:		return "WPI_CMD_BT_COEX";
90
		WPI_DESC(WPI_CMD_BT_COEX);
87
91
88
	default:
92
	default:
89
		KASSERT(1, ("Unknown Command: %d\n", cmd));
93
		KASSERT(1, ("Unknown Command: %d\n", cmd));
Lines 91-96 Link Here
91
	}
95
	}
92
}
96
}
93
97
98
/*
99
 * Translate CSR code to string
100
 */
101
static const char *wpi_get_csr_string(int csr)
102
{
103
	switch (csr) {
104
		WPI_DESC(WPI_HW_IF_CONFIG);
105
		WPI_DESC(WPI_INT);
106
		WPI_DESC(WPI_INT_MASK);
107
		WPI_DESC(WPI_FH_INT);
108
		WPI_DESC(WPI_GPIO_IN);
109
		WPI_DESC(WPI_RESET);
110
		WPI_DESC(WPI_GP_CNTRL);
111
		WPI_DESC(WPI_EEPROM);
112
		WPI_DESC(WPI_EEPROM_GP);
113
		WPI_DESC(WPI_GIO);
114
		WPI_DESC(WPI_UCODE_GP1);
115
		WPI_DESC(WPI_UCODE_GP2);
116
		WPI_DESC(WPI_GIO_CHICKEN);
117
		WPI_DESC(WPI_ANA_PLL);
118
		WPI_DESC(WPI_DBG_HPET_MEM);
119
	default:
120
		KASSERT(1, ("Unknown CSR: %d\n", csr));
121
		return "UNKNOWN CSR";
122
	}
123
}
124
125
static const char *wpi_get_prph_string(int prph)
126
{
127
	switch (prph) {
128
		WPI_DESC(WPI_APMG_CLK_CTRL);
129
		WPI_DESC(WPI_APMG_PS);
130
		WPI_DESC(WPI_APMG_PCI_STT);
131
		WPI_DESC(WPI_APMG_RFKILL);
132
	default:
133
		KASSERT(1, ("Unknown register: %d\n", prph));
134
		return "UNKNOWN PRPH";
135
	}
136
}
137
94
#else
138
#else
95
#define DPRINTF(sc, m, ...)	do { (void) sc; } while (0)
139
#define DPRINTF(sc, m, ...)	do { (void) sc; } while (0)
96
#endif
140
#endif
(-)sys/dev/wpi/if_wpireg.h (-8 / +16 lines)
Lines 24-33 Link Here
24
#define WPI_RX_RING_COUNT	(1 << WPI_RX_RING_COUNT_LOG)
24
#define WPI_RX_RING_COUNT	(1 << WPI_RX_RING_COUNT_LOG)
25
25
26
#define WPI_NTXQUEUES		8
26
#define WPI_NTXQUEUES		8
27
#define WPI_DRV_NTXQUEUES	5
28
#define WPI_CMD_QUEUE_NUM	4
29
27
#define WPI_NDMACHNLS		6
30
#define WPI_NDMACHNLS		6
28
31
29
/* Maximum scatter/gather. */
32
/* Maximum scatter/gather. */
30
#define WPI_MAX_SCATTER	4
33
#define WPI_MAX_SCATTER		4
31
34
32
/*
35
/*
33
 * Rings must be aligned on a 16K boundary.
36
 * Rings must be aligned on a 16K boundary.
Lines 94-99 Link Here
94
#define WPI_ALM_SCHED_TXF5MF		0x2e20
97
#define WPI_ALM_SCHED_TXF5MF		0x2e20
95
#define WPI_ALM_SCHED_SBYPASS_MODE1	0x2e2c
98
#define WPI_ALM_SCHED_SBYPASS_MODE1	0x2e2c
96
#define WPI_ALM_SCHED_SBYPASS_MODE2	0x2e30
99
#define WPI_ALM_SCHED_SBYPASS_MODE2	0x2e30
100
#define WPI_APMG_CLK_CTRL		0x3000
97
#define WPI_APMG_CLK_EN			0x3004
101
#define WPI_APMG_CLK_EN			0x3004
98
#define WPI_APMG_CLK_DIS		0x3008
102
#define WPI_APMG_CLK_DIS		0x3008
99
#define WPI_APMG_PS			0x300c
103
#define WPI_APMG_PS			0x300c
Lines 221-227 Link Here
221
#define WPI_APMG_PCI_STT_L1A_DIS	(1 << 11)
225
#define WPI_APMG_PCI_STT_L1A_DIS	(1 << 11)
222
226
223
struct wpi_shared {
227
struct wpi_shared {
224
	uint32_t	txbase[8];
228
	uint32_t	txbase[WPI_NTXQUEUES];
225
	uint32_t	next;
229
	uint32_t	next;
226
	uint32_t	reserved[2];
230
	uint32_t	reserved[2];
227
} __packed;
231
} __packed;
Lines 268-273 Link Here
268
	uint8_t		qid;
272
	uint8_t		qid;
269
} __packed;
273
} __packed;
270
274
275
#define WPI_RX_DESC_QID_MSK		0x07
276
#define WPI_UNSOLICITED_RX_NOTIF	0x80
277
271
struct wpi_rx_stat {
278
struct wpi_rx_stat {
272
	uint8_t		len;
279
	uint8_t		len;
273
#define WPI_STAT_MAXLEN	20
280
#define WPI_STAT_MAXLEN	20
Lines 274-280 Link Here
274
281
275
	uint8_t		id;
282
	uint8_t		id;
276
	uint8_t		rssi;	/* received signal strength */
283
	uint8_t		rssi;	/* received signal strength */
277
#define WPI_RSSI_OFFSET	95
284
#define WPI_RSSI_OFFSET	-95
278
285
279
	uint8_t		agc;	/* access gain control */
286
	uint8_t		agc;	/* access gain control */
280
	uint16_t	signal;
287
	uint16_t	signal;
Lines 368-373 Link Here
368
#define WPI_FILTER_NODECRYPT	(1 << 3)
375
#define WPI_FILTER_NODECRYPT	(1 << 3)
369
#define WPI_FILTER_BSS		(1 << 5)
376
#define WPI_FILTER_BSS		(1 << 5)
370
#define WPI_FILTER_BEACON	(1 << 6)
377
#define WPI_FILTER_BEACON	(1 << 6)
378
#define WPI_FILTER_ASSOC	(1 << 7)    /* Accept associaton requests. */
371
379
372
	uint8_t		chan;
380
	uint8_t		chan;
373
	uint16_t	reserved5;
381
	uint16_t	reserved5;
Lines 465-471 Link Here
465
	uint16_t	lnext;
473
	uint16_t	lnext;
466
	uint32_t	flags;
474
	uint32_t	flags;
467
#define WPI_TX_NEED_RTS		(1 <<  1)
475
#define WPI_TX_NEED_RTS		(1 <<  1)
468
#define WPI_TX_NEED_CTS         (1 <<  2)
476
#define WPI_TX_NEED_CTS		(1 <<  2)
469
#define WPI_TX_NEED_ACK		(1 <<  3)
477
#define WPI_TX_NEED_ACK		(1 <<  3)
470
#define WPI_TX_FULL_TXOP	(1 <<  7)
478
#define WPI_TX_FULL_TXOP	(1 <<  7)
471
#define WPI_TX_BT_DISABLE	(1 << 12) 	/* bluetooth coexistence */
479
#define WPI_TX_BT_DISABLE	(1 << 12) 	/* bluetooth coexistence */
Lines 515-524 Link Here
515
523
516
/* Structure for notification WPI_BEACON_MISSED. */
524
/* Structure for notification WPI_BEACON_MISSED. */
517
struct wpi_beacon_missed {
525
struct wpi_beacon_missed {
518
    uint32_t consecutive;
526
	uint32_t consecutive;
519
    uint32_t total;
527
	uint32_t total;
520
    uint32_t expected;
528
	uint32_t expected;
521
    uint32_t received;
529
	uint32_t received;
522
} __packed;
530
} __packed;
523
531
524
532
(-)sys/dev/wpi/if_wpivar.h (-22 / +69 lines)
Lines 52-58 Link Here
52
52
53
struct wpi_dma_info {
53
struct wpi_dma_info {
54
	bus_dma_tag_t		tag;
54
	bus_dma_tag_t		tag;
55
	bus_dmamap_t            map;
55
	bus_dmamap_t		map;
56
	bus_addr_t		paddr;
56
	bus_addr_t		paddr;
57
	caddr_t			vaddr;
57
	caddr_t			vaddr;
58
	bus_size_t		size;
58
	bus_size_t		size;
Lines 73-79 Link Here
73
	struct wpi_tx_data	data[WPI_TX_RING_COUNT];
73
	struct wpi_tx_data	data[WPI_TX_RING_COUNT];
74
	bus_dma_tag_t		data_dmat;
74
	bus_dma_tag_t		data_dmat;
75
	int			qid;
75
	int			qid;
76
	int			queued;
76
	volatile uint32_t	queued;
77
	int			cur;
77
	int			cur;
78
	int			update;
78
	int			update;
79
};
79
};
Lines 96-101 Link Here
96
	struct ieee80211_node	ni;	/* must be the first */
96
	struct ieee80211_node	ni;	/* must be the first */
97
	uint8_t			id;
97
	uint8_t			id;
98
};
98
};
99
#define WPI_NODE(ni)	((struct wpi_node *)(ni))
99
100
100
struct wpi_power_sample {
101
struct wpi_power_sample {
101
	uint8_t	index;
102
	uint8_t	index;
Lines 111-117 Link Here
111
};
112
};
112
113
113
struct wpi_buf {
114
struct wpi_buf {
114
	void			*data;
115
	uint8_t			data[56];  /* sizeof(struct wpi_cmd_beacon) */
115
	struct ieee80211_node	*ni;
116
	struct ieee80211_node	*ni;
116
	struct mbuf		*m;
117
	struct mbuf		*m;
117
	size_t			size;
118
	size_t			size;
Lines 120-133 Link Here
120
};
121
};
121
122
122
struct wpi_vap {
123
struct wpi_vap {
123
	struct ieee80211vap	vap;
124
	struct ieee80211vap		wv_vap;
124
	struct wpi_buf		wv_bcbuf;
125
125
126
	int			(*newstate)(struct ieee80211vap *,
126
	struct wpi_buf			wv_bcbuf;
127
				    enum ieee80211_state, int);
127
	struct ieee80211_beacon_offsets	wv_boff;
128
	struct mtx			wv_mtx;
129
130
	volatile uint32_t		wv_gtk;
131
#define WPI_VAP_KEY(kid)		(1 << kid)
132
133
	int				(*wv_newstate)(struct ieee80211vap *,
134
					    enum ieee80211_state, int);
128
};
135
};
129
#define	WPI_VAP(vap)	((struct wpi_vap *)(vap))
136
#define	WPI_VAP(vap)	((struct wpi_vap *)(vap))
130
137
138
#define WPI_VAP_LOCK_INIT(_wvp) \
139
	mtx_init(&(_wvp)->wv_mtx, "lock for wv_bcbuf/wv_boff structures", \
140
	    NULL, MTX_DEF)
141
#define WPI_VAP_LOCK(_wvp)		mtx_lock(&(_wvp)->wv_mtx)
142
#define WPI_VAP_UNLOCK(_wvp)		mtx_unlock(&(_wvp)->wv_mtx)
143
#define WPI_VAP_LOCK_ASSERT(_wvp)	mtx_assert(&(_wvp)->wv_mtx, MA_OWNED)
144
#define WPI_VAP_LOCK_DESTROY(_wvp)	mtx_destroy(&(_wvp)->wv_mtx)
145
131
struct wpi_fw_part {
146
struct wpi_fw_part {
132
	const uint8_t	*text;
147
	const uint8_t	*text;
133
	uint32_t	textsz;
148
	uint32_t	textsz;
Lines 150-168 Link Here
150
	int			sc_debug;
165
	int			sc_debug;
151
166
152
	struct mtx		sc_mtx;
167
	struct mtx		sc_mtx;
153
	struct unrhdr		*sc_unr;
168
	struct mtx		tx_mtx;
154
169
155
	/* Flags indicating the current state the driver
156
	 * expects the hardware to be in
157
	 */
158
	uint32_t		flags;
159
#define WPI_FLAG_BUSY		(1 << 0)
160
161
	/* Shared area. */
170
	/* Shared area. */
162
	struct wpi_dma_info	shared_dma;
171
	struct wpi_dma_info	shared_dma;
163
	struct wpi_shared	*shared;
172
	struct wpi_shared	*shared;
164
173
165
	struct wpi_tx_ring	txq[WPI_NTXQUEUES];
174
	struct wpi_tx_ring	txq[WPI_NTXQUEUES];
175
	struct mtx		txq_mtx;
176
	volatile uint32_t	txq_active;
177
166
	struct wpi_rx_ring	rxq;
178
	struct wpi_rx_ring	rxq;
167
179
168
	/* TX Thermal Callibration. */
180
	/* TX Thermal Callibration. */
Lines 183-203 Link Here
183
	bus_space_handle_t	sc_sh;
195
	bus_space_handle_t	sc_sh;
184
	void			*sc_ih;
196
	void			*sc_ih;
185
	bus_size_t		sc_sz;
197
	bus_size_t		sc_sz;
186
	int			sc_cap_off;     /* PCIe Capabilities. */
198
	int			sc_cap_off;	/* PCIe Capabilities. */
187
199
188
	struct wpi_rxon		rxon;
200
	struct wpi_rxon		rxon;
201
	struct mtx		rxon_mtx;
202
189
	int			temp;
203
	int			temp;
190
	uint32_t		qfullmsk;
191
204
192
	int			sc_tx_timer;
205
	volatile uint32_t	qfullmsk;
193
	int			sc_scan_timer;
194
206
207
	uint32_t		nodesmsk;
208
	struct mtx		nt_mtx;
209
210
	volatile int32_t	sc_tx_timer;
211
	volatile int32_t	sc_scan_timer;
212
195
	void			(*sc_node_free)(struct ieee80211_node *);
213
	void			(*sc_node_free)(struct ieee80211_node *);
196
	void			(*sc_scan_curchan)(struct ieee80211_scan_state *,
214
	void			(*sc_scan_curchan)(struct ieee80211_scan_state *,
197
				    unsigned long);
215
				    unsigned long);
198
216
199
	struct wpi_rx_radiotap_header sc_rxtap;
217
	struct wpi_rx_radiotap_header	sc_rxtap;
200
	struct wpi_tx_radiotap_header sc_txtap;
218
	struct wpi_tx_radiotap_header	sc_txtap;
201
219
202
	/* Firmware image. */
220
	/* Firmware image. */
203
	const struct firmware	*fw_fp;
221
	const struct firmware	*fw_fp;
Lines 209-214 Link Here
209
	struct task		sc_reinittask;
227
	struct task		sc_reinittask;
210
	struct task		sc_radiooff_task;
228
	struct task		sc_radiooff_task;
211
	struct task		sc_radioon_task;
229
	struct task		sc_radioon_task;
230
	struct task		sc_start_task;
212
231
213
	/* Eeprom info. */
232
	/* Eeprom info. */
214
	uint8_t			cap;
233
	uint8_t			cap;
Lines 221-230 Link Here
221
	char			domain[4];	/* Regulatory domain. */
240
	char			domain[4];	/* Regulatory domain. */
222
};
241
};
223
242
243
/* WPI_LOCK > WPI_RXON_LOCK / WPI_TX_LOCK > WPI_NT_LOCK > WPI_TXQ_LOCK */
244
224
#define WPI_LOCK_INIT(_sc) \
245
#define WPI_LOCK_INIT(_sc) \
225
	mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
246
	mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
226
            MTX_NETWORK_LOCK, MTX_DEF)
247
	    MTX_NETWORK_LOCK, MTX_DEF)
227
#define WPI_LOCK(_sc)		mtx_lock(&(_sc)->sc_mtx)
248
#define WPI_LOCK(_sc)		mtx_lock(&(_sc)->sc_mtx)
228
#define WPI_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
249
#define WPI_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
229
#define WPI_LOCK_ASSERT(sc)     mtx_assert(&(sc)->sc_mtx, MA_OWNED)
250
#define WPI_LOCK_ASSERT(_sc)	mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
230
#define WPI_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->sc_mtx)
251
#define WPI_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->sc_mtx)
252
253
#define WPI_RXON_LOCK_INIT(_sc) \
254
	mtx_init(&(_sc)->rxon_mtx, "lock for wpi_rxon structure", NULL, MTX_DEF)
255
#define WPI_RXON_LOCK(_sc)		mtx_lock(&(_sc)->rxon_mtx)
256
#define WPI_RXON_UNLOCK(_sc)		mtx_unlock(&(_sc)->rxon_mtx)
257
#define WPI_RXON_LOCK_ASSERT(_sc)	mtx_assert(&(_sc)->rxon_mtx, MA_OWNED)
258
#define WPI_RXON_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->rxon_mtx)
259
260
#define WPI_TX_LOCK_INIT(_sc) \
261
	mtx_init(&(_sc)->tx_mtx, "tx path lock", \
262
	    NULL, MTX_DEF)
263
#define WPI_TX_LOCK(_sc)		mtx_lock(&(_sc)->tx_mtx)
264
#define WPI_TX_UNLOCK(_sc)		mtx_unlock(&(_sc)->tx_mtx)
265
#define WPI_TX_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->tx_mtx)
266
267
#define WPI_NT_LOCK_INIT(_sc) \
268
	mtx_init(&(_sc)->nt_mtx, "node table lock", NULL, MTX_DEF)
269
#define WPI_NT_LOCK(_sc)		mtx_lock(&(_sc)->nt_mtx)
270
#define WPI_NT_UNLOCK(_sc)		mtx_unlock(&(_sc)->nt_mtx)
271
#define WPI_NT_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->nt_mtx)
272
273
#define WPI_TXQ_LOCK_INIT(_sc) \
274
	mtx_init(&(_sc)->txq_mtx, "txq/cmdq lock", NULL, MTX_DEF)
275
#define WPI_TXQ_LOCK(_sc)		mtx_lock(&(_sc)->txq_mtx)
276
#define WPI_TXQ_UNLOCK(_sc)		mtx_unlock(&(_sc)->txq_mtx)
277
#define WPI_TXQ_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->txq_mtx)

Return to bug 197143