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

Collapse All | Expand All

(-)sys/dev/wpi/if_wpi.c (-515 / +1086 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-1798 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);
Lines 1802-1819 Link Here
1802
1901
1803
	/* Send the frame to the 802.11 layer. */
1902
	/* Send the frame to the 802.11 layer. */
1804
	if (ni != NULL) {
1903
	if (ni != NULL) {
1805
		(void)ieee80211_input(ni, m, stat->rssi, -WPI_RSSI_OFFSET);
1904
		(void)ieee80211_input(ni, m, stat->rssi, WPI_RSSI_OFFSET);
1806
		/* Node is no longer needed. */
1905
		/* Node is no longer needed. */
1807
		ieee80211_free_node(ni);
1906
		ieee80211_free_node(ni);
1808
	} else
1907
	} else
1809
		(void)ieee80211_input_all(ic, m, stat->rssi, -WPI_RSSI_OFFSET);
1908
		(void)ieee80211_input_all(ic, m, stat->rssi, WPI_RSSI_OFFSET);
1810
1909
1811
	WPI_LOCK(sc);
1910
	WPI_LOCK(sc);
1812
1911
1813
	return;
1912
	return;
1814
1913
1815
fail2:	ieee80211_free_node(ni);
1914
fail2:	m_freem(m);
1816
	m_freem(m);
1817
1915
1818
fail1:	if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1916
fail1:	if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1819
}
1917
}
Lines 1835-1844 Link Here
1835
	struct mbuf *m;
1933
	struct mbuf *m;
1836
	struct ieee80211_node *ni;
1934
	struct ieee80211_node *ni;
1837
	struct ieee80211vap *vap;
1935
	struct ieee80211vap *vap;
1838
	int ackfailcnt = stat->ackfailcnt;
1936
	struct ieee80211com *ic;
1839
	int status = le32toh(stat->status);
1937
	uint32_t queued, status = le32toh(stat->status);
1938
	int ackfailcnt = stat->ackfailcnt / 2;	/* wpi_mrr_setup() */
1840
1939
1841
	KASSERT(data->ni != NULL, ("no node"));
1940
	KASSERT(data->ni != NULL, ("no node"));
1941
	KASSERT(data->m != NULL, ("no mbuf"));
1842
1942
1843
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
1943
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
1844
1944
Lines 1853-1863 Link Here
1853
	m = data->m, data->m = NULL;
1953
	m = data->m, data->m = NULL;
1854
	ni = data->ni, data->ni = NULL;
1954
	ni = data->ni, data->ni = NULL;
1855
	vap = ni->ni_vap;
1955
	vap = ni->ni_vap;
1956
	ic = vap->iv_ic;
1856
1957
1958
	queued = atomic_fetchadd_32(&ring->queued, -1);
1959
	atomic_store_rel_32(&sc->sc_tx_timer, 0);
1960
1857
	/*
1961
	/*
1858
	 * Update rate control statistics for the node.
1962
	 * Update rate control statistics for the node.
1859
	 */
1963
	 */
1860
	WPI_UNLOCK(sc);
1861
	if ((status & 0xff) != 1) {
1964
	if ((status & 0xff) != 1) {
1862
		if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1965
		if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1863
		ieee80211_ratectl_tx_complete(vap, ni,
1966
		ieee80211_ratectl_tx_complete(vap, ni,
Lines 1869-1885 Link Here
1869
	}
1972
	}
1870
1973
1871
	ieee80211_tx_complete(ni, m, (status & 0xff) != 1);
1974
	ieee80211_tx_complete(ni, m, (status & 0xff) != 1);
1872
	WPI_LOCK(sc);
1873
1975
1874
	sc->sc_tx_timer = 0;
1976
	IF_LOCK(&ifp->if_snd);
1875
	if (--ring->queued < WPI_TX_RING_LOMARK) {
1977
	if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) &&
1876
		sc->qfullmsk &= ~(1 << ring->qid);
1978
	     queued <= WPI_TX_RING_LOMARK) {
1877
		if (sc->qfullmsk == 0 &&
1979
		IF_UNLOCK(&ifp->if_snd);
1878
		    (ifp->if_drv_flags & IFF_DRV_OACTIVE)) {
1980
1981
		if (atomic_load_acq_32(&sc->qfullmsk) != 0) {
1982
			WPI_TXQ_LOCK(sc);
1983
			queued = atomic_load_acq_32(&ring->queued);
1984
			if (queued < WPI_TX_RING_LOMARK)
1985
				atomic_clear_32(&sc->qfullmsk, 1 << ring->qid);
1986
			WPI_TXQ_UNLOCK(sc);
1987
		}
1988
1989
		if (atomic_load_acq_32(&sc->qfullmsk) == 0) {
1990
			IF_LOCK(&ifp->if_snd);
1879
			ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1991
			ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1880
			wpi_start_locked(ifp);
1992
			IF_UNLOCK(&ifp->if_snd);
1993
			ieee80211_runtask(ic, &sc->sc_start_task);
1881
		}
1994
		}
1882
	}
1995
	} else
1996
		IF_UNLOCK(&ifp->if_snd);
1883
1997
1884
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
1998
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
1885
}
1999
}
Lines 1891-1905 Link Here
1891
static void
2005
static void
1892
wpi_cmd_done(struct wpi_softc *sc, struct wpi_rx_desc *desc)
2006
wpi_cmd_done(struct wpi_softc *sc, struct wpi_rx_desc *desc)
1893
{
2007
{
1894
	struct wpi_tx_ring *ring = &sc->txq[4];
2008
	struct wpi_tx_ring *ring = &sc->txq[WPI_CMD_QUEUE_NUM];
1895
	struct wpi_tx_data *data;
2009
	struct wpi_tx_data *data;
1896
2010
1897
	DPRINTF(sc, WPI_DEBUG_CMD, "cmd notification qid=%x idx=%d flags=%x "
2011
	DPRINTF(sc, WPI_DEBUG_CMD, "cmd notification qid %x idx %d flags %x "
1898
				   "type=%s len=%d\n", desc->qid, desc->idx,
2012
				   "type %s len %d\n", desc->qid, desc->idx,
1899
				   desc->flags, wpi_cmd_str(desc->type),
2013
				   desc->flags, wpi_cmd_str(desc->type),
1900
				   le32toh(desc->len));
2014
				   le32toh(desc->len));
1901
2015
1902
	if ((desc->qid & 7) != 4)
2016
	if ((desc->qid & WPI_RX_DESC_QID_MSK) != WPI_CMD_QUEUE_NUM)
1903
		return;	/* Not a command ack. */
2017
		return;	/* Not a command ack. */
1904
2018
1905
	data = &ring->data[desc->idx];
2019
	data = &ring->data[desc->idx];
Lines 1913-1919 Link Here
1913
		data->m = NULL;
2027
		data->m = NULL;
1914
	}
2028
	}
1915
2029
1916
	sc->flags &= ~WPI_FLAG_BUSY;
1917
	wakeup(&ring->cmd[desc->idx]);
2030
	wakeup(&ring->cmd[desc->idx]);
1918
}
2031
}
1919
2032
Lines 1928-1933 Link Here
1928
	bus_dmamap_sync(sc->shared_dma.tag, sc->shared_dma.map,
2041
	bus_dmamap_sync(sc->shared_dma.tag, sc->shared_dma.map,
1929
	    BUS_DMASYNC_POSTREAD);
2042
	    BUS_DMASYNC_POSTREAD);
1930
2043
2044
	/* This field may be corrupted when DIAGNOSTIC option is used. */
1931
	hw = le32toh(sc->shared->next);
2045
	hw = le32toh(sc->shared->next);
1932
	hw = (hw == 0) ? WPI_RX_RING_COUNT - 1 : hw - 1;
2046
	hw = (hw == 0) ? WPI_RX_RING_COUNT - 1 : hw - 1;
1933
2047
Lines 1946-1958 Link Here
1946
		    __func__, sc->rxq.cur, desc->qid, desc->idx, desc->flags,
2060
		    __func__, sc->rxq.cur, desc->qid, desc->idx, desc->flags,
1947
		    desc->type, wpi_cmd_str(desc->type), le32toh(desc->len));
2061
		    desc->type, wpi_cmd_str(desc->type), le32toh(desc->len));
1948
2062
1949
		if (!(desc->qid & 0x80))	/* Reply to a command. */
2063
		if (!(desc->qid & WPI_UNSOLICITED_RX_NOTIF)) {
2064
			/* Reply to a command. */
1950
			wpi_cmd_done(sc, desc);
2065
			wpi_cmd_done(sc, desc);
2066
		}
1951
2067
1952
		switch (desc->type) {
2068
		switch (desc->type) {
1953
		case WPI_RX_DONE:
2069
		case WPI_RX_DONE:
1954
			/* An 802.11 frame has been received. */
2070
			/* An 802.11 frame has been received. */
1955
			wpi_rx_done(sc, desc, data);
2071
			wpi_rx_done(sc, desc, data);
2072
2073
			if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
2074
				/* wpi_stop() was called. */
2075
				return;
2076
			}
2077
1956
			break;
2078
			break;
1957
2079
1958
		case WPI_TX_DONE:
2080
		case WPI_TX_DONE:
Lines 1980-1992 Link Here
1980
			    le32toh(miss->total));
2102
			    le32toh(miss->total));
1981
2103
1982
			if (vap->iv_state == IEEE80211_S_RUN &&
2104
			if (vap->iv_state == IEEE80211_S_RUN &&
1983
			    (ic->ic_flags & IEEE80211_S_SCAN) == 0) {
2105
			    (ic->ic_flags & IEEE80211_F_SCAN) == 0 &&
1984
				if (misses >=  vap->iv_bmissthreshold) {
2106
			    misses >= vap->iv_bmissthreshold)
1985
					WPI_UNLOCK(sc);
2107
				ieee80211_beacon_miss(ic);
1986
					ieee80211_beacon_miss(ic);
2108
1987
					WPI_LOCK(sc);
1988
				}
1989
			}
1990
			break;
2109
			break;
1991
		}
2110
		}
1992
		case WPI_UC_READY:
2111
		case WPI_UC_READY:
Lines 2013-2020 Link Here
2013
		}
2132
		}
2014
		case WPI_STATE_CHANGED:
2133
		case WPI_STATE_CHANGED:
2015
		{
2134
		{
2016
                        bus_dmamap_sync(sc->rxq.data_dmat, data->map,
2135
			bus_dmamap_sync(sc->rxq.data_dmat, data->map,
2017
                            BUS_DMASYNC_POSTREAD);
2136
			    BUS_DMASYNC_POSTREAD);
2018
2137
2019
			uint32_t *status = (uint32_t *)(desc + 1);
2138
			uint32_t *status = (uint32_t *)(desc + 1);
2020
2139
Lines 2022-2027 Link Here
2022
			    le32toh(*status));
2141
			    le32toh(*status));
2023
2142
2024
			if (le32toh(*status) & 1) {
2143
			if (le32toh(*status) & 1) {
2144
				WPI_NT_LOCK(sc);
2145
				wpi_clear_node_table(sc);
2146
				WPI_NT_UNLOCK(sc);
2025
				ieee80211_runtask(ic, &sc->sc_radiooff_task);
2147
				ieee80211_runtask(ic, &sc->sc_radiooff_task);
2026
				return;
2148
				return;
2027
			}
2149
			}
Lines 2051-2060 Link Here
2051
			    "scan finished nchan=%d status=%d chan=%d\n",
2173
			    "scan finished nchan=%d status=%d chan=%d\n",
2052
			    scan->nchan, scan->status, scan->chan);
2174
			    scan->nchan, scan->status, scan->chan);
2053
#endif
2175
#endif
2054
			sc->sc_scan_timer = 0;
2176
			atomic_store_rel_32(&sc->sc_scan_timer, 0);
2055
			WPI_UNLOCK(sc);
2056
			ieee80211_scan_next(vap);
2177
			ieee80211_scan_next(vap);
2057
			WPI_LOCK(sc);
2058
			break;
2178
			break;
2059
		}
2179
		}
2060
		}
2180
		}
Lines 2068-2074 Link Here
2068
 * Process an INT_WAKEUP interrupt raised when the microcontroller wakes up
2188
 * Process an INT_WAKEUP interrupt raised when the microcontroller wakes up
2069
 * from power-down sleep mode.
2189
 * from power-down sleep mode.
2070
 */
2190
 */
2071
static void     
2191
static void
2072
wpi_wakeup_intr(struct wpi_softc *sc)
2192
wpi_wakeup_intr(struct wpi_softc *sc)
2073
{
2193
{
2074
	int qid;
2194
	int qid;
Lines 2077-2099 Link Here
2077
	    "%s: ucode wakeup from power-down sleep\n", __func__);
2197
	    "%s: ucode wakeup from power-down sleep\n", __func__);
2078
2198
2079
	/* Wakeup RX and TX rings. */
2199
	/* Wakeup RX and TX rings. */
2080
	if (sc->rxq.update) {
2200
	if (sc->rxq.update != 0) {
2081
		sc->rxq.update = 0;
2201
		sc->rxq.update = 0;
2082
		wpi_update_rx_ring(sc);
2202
		wpi_update_rx_ring(sc);
2083
	}
2203
	}
2084
	for (qid = 0; qid < WPI_NTXQUEUES; qid++) {
2204
2205
	WPI_TXQ_LOCK(sc);
2206
	for (qid = 0; qid < WPI_DRV_NTXQUEUES; qid++) {
2085
		struct wpi_tx_ring *ring = &sc->txq[qid];
2207
		struct wpi_tx_ring *ring = &sc->txq[qid];
2086
2208
2087
		if (ring->update) {
2209
		if (ring->update != 0) {
2088
			ring->update = 0;
2210
			ring->update = 0;
2089
			wpi_update_tx_ring(sc, ring);
2211
			wpi_update_tx_ring(sc, ring);
2090
		}
2212
		}
2091
	}
2213
	}
2214
	WPI_TXQ_UNLOCK(sc);
2092
2215
2093
	WPI_CLRBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ);
2216
	WPI_CLRBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ);
2094
}
2217
}
2095
2218
2096
/*
2219
/*
2220
 * This function prints firmware registers
2221
 */
2222
#ifdef WPI_DEBUG
2223
static void
2224
wpi_debug_registers(struct wpi_softc *sc)
2225
{
2226
#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
2227
	int i;
2228
	static const uint32_t csr_tbl[] = {
2229
		WPI_HW_IF_CONFIG,
2230
		WPI_INT,
2231
		WPI_INT_MASK,
2232
		WPI_FH_INT,
2233
		WPI_GPIO_IN,
2234
		WPI_RESET,
2235
		WPI_GP_CNTRL,
2236
		WPI_EEPROM,
2237
		WPI_EEPROM_GP,
2238
		WPI_GIO,
2239
		WPI_UCODE_GP1,
2240
		WPI_UCODE_GP2,
2241
		WPI_GIO_CHICKEN,
2242
		WPI_ANA_PLL,
2243
		WPI_DBG_HPET_MEM,
2244
	};
2245
	static const uint32_t prph_tbl[] = {
2246
		WPI_APMG_CLK_CTRL,
2247
		WPI_APMG_PS,
2248
		WPI_APMG_PCI_STT,
2249
		WPI_APMG_RFKILL,
2250
	};
2251
	/* Undocumented */
2252
	static const uint32_t prph2_tbl[] = {
2253
		0x302c,
2254
		0x3044,
2255
		0x3048,
2256
		0x3050,
2257
		0x3054,
2258
		0x3080,
2259
		0x3084,
2260
	};
2261
2262
	DPRINTF(sc, WPI_DEBUG_REGISTER,"%s","\n");
2263
2264
	for (i = 0; i <  COUNTOF(csr_tbl); i++) {
2265
		DPRINTF(sc, WPI_DEBUG_REGISTER, "  %-18s: 0x%08x ",
2266
		    wpi_get_csr_string(csr_tbl[i]), WPI_READ(sc, csr_tbl[i]));
2267
2268
		if ((i + 1) % 2 == 0)
2269
			DPRINTF(sc, WPI_DEBUG_REGISTER, "\n");
2270
	}
2271
	DPRINTF(sc, WPI_DEBUG_REGISTER, "\n\n");
2272
2273
	if (wpi_nic_lock(sc) == 0) {
2274
		for (i = 0; i < COUNTOF(prph_tbl); i++) {
2275
			DPRINTF(sc, WPI_DEBUG_REGISTER, "  %-18s: 0x%08x ",
2276
			    wpi_get_prph_string(prph_tbl[i]),
2277
			    wpi_prph_read(sc, prph_tbl[i]));
2278
2279
			if ((i + 1) % 2 == 0)
2280
				DPRINTF(sc, WPI_DEBUG_REGISTER, "\n");
2281
		}
2282
		DPRINTF(sc, WPI_DEBUG_REGISTER, "\n");
2283
2284
		for (i = 0; i < COUNTOF(prph2_tbl); i++) {
2285
			DPRINTF(sc, WPI_DEBUG_REGISTER, "  0x%04x: 0x%08x ",
2286
			    prph2_tbl[i], wpi_prph_read(sc, prph2_tbl[i]));
2287
2288
			if ((i + 1) % 3 == 0)
2289
				DPRINTF(sc, WPI_DEBUG_REGISTER, "\n");
2290
		}
2291
		DPRINTF(sc, WPI_DEBUG_REGISTER, "\n\n");
2292
		wpi_nic_unlock(sc);
2293
	} else {
2294
		DPRINTF(sc, WPI_DEBUG_REGISTER,
2295
		    "Cannot access internal registers.\n");
2296
	}
2297
#undef COUNTOF
2298
}
2299
#endif
2300
2301
/*
2097
 * Dump the error log of the firmware when a firmware panic occurs.  Although
2302
 * 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
2303
 * 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.
2304
 * can help us to identify certain classes of problems.
Lines 2112-2123 Link Here
2112
	    WPI_FW_DATA_BASE + WPI_FW_DATA_MAXSZ) {
2317
	    WPI_FW_DATA_BASE + WPI_FW_DATA_MAXSZ) {
2113
		printf("%s: bad firmware error log address 0x%08x\n", __func__,
2318
		printf("%s: bad firmware error log address 0x%08x\n", __func__,
2114
		    sc->errptr);
2319
		    sc->errptr);
2115
                return;
2320
		return;
2116
        }
2321
	}
2117
	if (wpi_nic_lock(sc) != 0) {
2322
	if (wpi_nic_lock(sc) != 0) {
2118
		printf("%s: could not read firmware error log\n", __func__);
2323
		printf("%s: could not read firmware error log\n", __func__);
2119
                return;
2324
		return;
2120
        }
2325
	}
2121
	/* Read number of entries in the log. */
2326
	/* Read number of entries in the log. */
2122
	count = wpi_mem_read(sc, sc->errptr);
2327
	count = wpi_mem_read(sc, sc->errptr);
2123
	if (count == 0 || count * sizeof (dump) > WPI_FW_DATA_MAXSZ) {
2328
	if (count == 0 || count * sizeof (dump) > WPI_FW_DATA_MAXSZ) {
Lines 2150-2160 Link Here
2150
	wpi_nic_unlock(sc);
2355
	wpi_nic_unlock(sc);
2151
	/* Dump driver status (TX and RX rings) while we're here. */
2356
	/* Dump driver status (TX and RX rings) while we're here. */
2152
	printf("driver status:\n");
2357
	printf("driver status:\n");
2153
	for (i = 0; i < WPI_NTXQUEUES; i++) {
2358
	WPI_TXQ_LOCK(sc);
2359
	for (i = 0; i < WPI_DRV_NTXQUEUES; i++) {
2154
		struct wpi_tx_ring *ring = &sc->txq[i];
2360
		struct wpi_tx_ring *ring = &sc->txq[i];
2155
		printf("  tx ring %2d: qid=%-2d cur=%-3d queued=%-3d\n",
2361
		printf("  tx ring %2d: qid=%-2d cur=%-3d queued=%-3d\n",
2156
		    i, ring->qid, ring->cur, ring->queued);
2362
		    i, ring->qid, ring->cur, ring->queued);
2157
	}
2363
	}
2364
	WPI_TXQ_UNLOCK(sc);
2158
	printf("  rx ring: cur=%d\n", sc->rxq.cur);
2365
	printf("  rx ring: cur=%d\n", sc->rxq.cur);
2159
}
2366
}
2160
2367
Lines 2172-2181 Link Here
2172
2379
2173
	r1 = WPI_READ(sc, WPI_INT);
2380
	r1 = WPI_READ(sc, WPI_INT);
2174
2381
2175
	if (r1 == 0xffffffff || (r1 & 0xfffffff0) == 0xa5a5a5a0) {
2382
	if (r1 == 0xffffffff || (r1 & 0xfffffff0) == 0xa5a5a5a0)
2176
		WPI_UNLOCK(sc);
2383
		goto end;	/* Hardware gone! */
2177
		return;	/* Hardware gone! */
2178
	}
2179
2384
2180
	r2 = WPI_READ(sc, WPI_FH_INT);
2385
	r2 = WPI_READ(sc, WPI_FH_INT);
2181
2386
Lines 2193-2206 Link Here
2193
		struct ieee80211com *ic = ifp->if_l2com;
2398
		struct ieee80211com *ic = ifp->if_l2com;
2194
2399
2195
		device_printf(sc->sc_dev, "fatal firmware error\n");
2400
		device_printf(sc->sc_dev, "fatal firmware error\n");
2401
#ifdef WPI_DEBUG
2402
		wpi_debug_registers(sc);
2403
#endif
2196
		wpi_fatal_intr(sc);
2404
		wpi_fatal_intr(sc);
2197
		DPRINTF(sc, WPI_DEBUG_HW,
2405
		DPRINTF(sc, WPI_DEBUG_HW,
2198
		    "(%s)\n", (r1 & WPI_INT_SW_ERR) ? "(Software Error)" :
2406
		    "(%s)\n", (r1 & WPI_INT_SW_ERR) ? "(Software Error)" :
2199
		    "(Hardware Error)");
2407
		    "(Hardware Error)");
2200
		ieee80211_runtask(ic, &sc->sc_reinittask);
2408
		ieee80211_runtask(ic, &sc->sc_reinittask);
2201
		sc->flags &= ~WPI_FLAG_BUSY;
2409
		goto end;
2202
		WPI_UNLOCK(sc);
2203
		return;
2204
	}
2410
	}
2205
2411
2206
	if ((r1 & (WPI_INT_FH_RX | WPI_INT_SW_RX)) ||
2412
	if ((r1 & (WPI_INT_FH_RX | WPI_INT_SW_RX)) ||
Lines 2218-2231 Link Here
2218
	if (ifp->if_flags & IFF_UP)
2424
	if (ifp->if_flags & IFF_UP)
2219
		WPI_WRITE(sc, WPI_INT_MASK, WPI_INT_MASK_DEF);
2425
		WPI_WRITE(sc, WPI_INT_MASK, WPI_INT_MASK_DEF);
2220
2426
2221
	WPI_UNLOCK(sc);
2427
end:	WPI_UNLOCK(sc);
2222
}
2428
}
2223
2429
2224
static int
2430
static int
2225
wpi_cmd2(struct wpi_softc *sc, struct wpi_buf *buf)
2431
wpi_cmd2(struct wpi_softc *sc, struct wpi_buf *buf, int count)
2226
{
2432
{
2227
	struct ifnet *ifp = sc->sc_ifp;
2228
	struct ieee80211com *ic = ifp->if_l2com;
2229
	struct ieee80211_frame *wh;
2433
	struct ieee80211_frame *wh;
2230
	struct wpi_tx_cmd *cmd;
2434
	struct wpi_tx_cmd *cmd;
2231
	struct wpi_tx_data *data;
2435
	struct wpi_tx_data *data;
Lines 2233-2252 Link Here
2233
	struct wpi_tx_ring *ring;
2437
	struct wpi_tx_ring *ring;
2234
	struct mbuf *m1;
2438
	struct mbuf *m1;
2235
	bus_dma_segment_t *seg, segs[WPI_MAX_SCATTER];
2439
	bus_dma_segment_t *seg, segs[WPI_MAX_SCATTER];
2236
	int error, i, hdrspace, nsegs, totlen;
2440
	int error, i, hdrlen, nsegs, totlen, pad;
2237
2441
2238
	WPI_LOCK_ASSERT(sc);
2442
	WPI_TXQ_LOCK(sc);
2239
2443
2240
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
2444
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
2241
2445
2446
	if (atomic_load_acq_32(&sc->txq_active) == 0) {
2447
		error = ENETDOWN;
2448
		goto fail;
2449
	}
2450
2242
	wh = mtod(buf->m, struct ieee80211_frame *);
2451
	wh = mtod(buf->m, struct ieee80211_frame *);
2243
	hdrspace = ieee80211_anyhdrspace(ic, wh);
2452
	hdrlen = ieee80211_anyhdrsize(wh);
2244
	totlen = buf->m->m_pkthdr.len;
2453
	totlen = buf->m->m_pkthdr.len;
2245
2454
2455
	if (hdrlen & 3) {
2456
		/* First segment length must be a multiple of 4. */
2457
		pad = 4 - (hdrlen & 3);
2458
	} else
2459
		pad = 0;
2460
2246
	ring = &sc->txq[buf->ac];
2461
	ring = &sc->txq[buf->ac];
2247
	desc = &ring->desc[ring->cur];
2462
	desc = &ring->desc[ring->cur];
2248
	data = &ring->data[ring->cur];
2463
	data = &ring->data[ring->cur];
2249
2464
2465
	if (atomic_load_acq_32(&ring->queued) > WPI_TX_RING_HIMARK) {
2466
		error = ENOMEM;
2467
		goto fail;
2468
	}
2469
2250
	/* Prepare TX firmware command. */
2470
	/* Prepare TX firmware command. */
2251
	cmd = &ring->cmd[ring->cur];
2471
	cmd = &ring->cmd[ring->cur];
2252
	cmd->code = buf->code;
2472
	cmd->code = buf->code;
Lines 2257-2264 Link Here
2257
	memcpy(cmd->data, buf->data, buf->size);
2477
	memcpy(cmd->data, buf->data, buf->size);
2258
2478
2259
	/* Save and trim IEEE802.11 header. */
2479
	/* Save and trim IEEE802.11 header. */
2260
	memcpy((uint8_t *)(cmd->data + buf->size), wh, hdrspace);
2480
	memcpy((uint8_t *)(cmd->data + buf->size), wh, hdrlen);
2261
	m_adj(buf->m, hdrspace);
2481
	m_adj(buf->m, hdrlen);
2262
2482
2263
	error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, buf->m,
2483
	error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, buf->m,
2264
	    segs, &nsegs, BUS_DMA_NOWAIT);
2484
	    segs, &nsegs, BUS_DMA_NOWAIT);
Lines 2265-2281 Link Here
2265
	if (error != 0 && error != EFBIG) {
2485
	if (error != 0 && error != EFBIG) {
2266
		device_printf(sc->sc_dev,
2486
		device_printf(sc->sc_dev,
2267
		    "%s: can't map mbuf (error %d)\n", __func__, error);
2487
		    "%s: can't map mbuf (error %d)\n", __func__, error);
2268
		m_freem(buf->m);
2488
		goto fail;
2269
		return error;
2270
	}
2489
	}
2271
	if (error != 0) {
2490
	if (error != 0) {
2272
		/* Too many DMA segments, linearize mbuf. */
2491
		/* Too many DMA segments, linearize mbuf. */
2273
		m1 = m_collapse(buf->m, M_NOWAIT, WPI_MAX_SCATTER);
2492
		m1 = m_collapse(buf->m, M_NOWAIT, WPI_MAX_SCATTER - 1);
2274
		if (m1 == NULL) {
2493
		if (m1 == NULL) {
2275
			device_printf(sc->sc_dev,
2494
			device_printf(sc->sc_dev,
2276
			    "%s: could not defrag mbuf\n", __func__);
2495
			    "%s: could not defrag mbuf\n", __func__);
2277
			m_freem(buf->m);
2496
			error = ENOBUFS;
2278
			return ENOBUFS;
2497
			goto fail;
2279
		}
2498
		}
2280
		buf->m = m1;
2499
		buf->m = m1;
2281
2500
Lines 2283-2291 Link Here
2283
		    buf->m, segs, &nsegs, BUS_DMA_NOWAIT);
2502
		    buf->m, segs, &nsegs, BUS_DMA_NOWAIT);
2284
		if (error != 0) {
2503
		if (error != 0) {
2285
			device_printf(sc->sc_dev,
2504
			device_printf(sc->sc_dev,
2286
			    "%s: can't map mbuf (error %d)\n", __func__, error);
2505
			    "%s: can't map mbuf (error %d)\n", __func__,
2287
			m_freem(buf->m);
2506
			    error);
2288
			return error;
2507
			goto fail;
2289
		}
2508
		}
2290
	}
2509
	}
2291
2510
Lines 2296-2305 Link Here
2296
	    __func__, ring->qid, ring->cur, totlen, nsegs);
2515
	    __func__, ring->qid, ring->cur, totlen, nsegs);
2297
2516
2298
	/* Fill TX descriptor. */
2517
	/* Fill TX descriptor. */
2299
	desc->nsegs = WPI_PAD32(totlen) << 4 | (1 + nsegs);
2518
	desc->nsegs = WPI_PAD32(totlen + pad) << 4 | (1 + nsegs);
2519
2300
	/* First DMA segment is used by the TX command. */
2520
	/* First DMA segment is used by the TX command. */
2301
	desc->segs[0].addr = htole32(data->cmd_paddr);
2521
	desc->segs[0].addr = htole32(data->cmd_paddr);
2302
	desc->segs[0].len  = htole32(4 + buf->size + hdrspace);
2522
	desc->segs[0].len  = htole32(4 + buf->size + hdrlen + pad);
2303
	/* Other DMA segments are for data payload. */
2523
	/* Other DMA segments are for data payload. */
2304
	seg = &segs[0];
2524
	seg = &segs[0];
2305
	for (i = 1; i <= nsegs; i++) {
2525
	for (i = 1; i <= nsegs; i++) {
Lines 2318-2330 Link Here
2318
	ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT;
2538
	ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT;
2319
	wpi_update_tx_ring(sc, ring);
2539
	wpi_update_tx_ring(sc, ring);
2320
2540
2321
	/* Mark TX ring as full if we reach a certain threshold. */
2541
	if (ring->qid < WPI_CMD_QUEUE_NUM) {
2322
	if (++ring->queued > WPI_TX_RING_HIMARK)
2542
		int diff = WPI_TX_RING_HIMARK - count;
2323
		sc->qfullmsk |= 1 << ring->qid;
2324
2543
2544
		/* Mark TX ring as full if we reach a certain threshold. */
2545
		if (atomic_fetchadd_32(&ring->queued, count) > diff)
2546
			atomic_set_32(&sc->qfullmsk, 1 << ring->qid);
2547
2548
		atomic_store_rel_32(&sc->sc_tx_timer, 5);
2549
	}
2550
2551
	WPI_TXQ_UNLOCK(sc);
2552
2325
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
2553
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
2326
2554
2327
	return 0;
2555
	return 0;
2556
2557
fail:	WPI_TXQ_UNLOCK(sc);
2558
2559
	m_freem(buf->m);
2560
2561
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
2562
2563
	return error;
2328
}
2564
}
2329
2565
2330
/*
2566
/*
Lines 2336-2354 Link Here
2336
	const struct ieee80211_txparam *tp;
2572
	const struct ieee80211_txparam *tp;
2337
	struct ieee80211vap *vap = ni->ni_vap;
2573
	struct ieee80211vap *vap = ni->ni_vap;
2338
	struct ieee80211com *ic = ni->ni_ic;
2574
	struct ieee80211com *ic = ni->ni_ic;
2339
	struct wpi_node *wn = (void *)ni;
2575
	struct wpi_node *wn = WPI_NODE(ni);
2340
	struct ieee80211_channel *chan;
2576
	struct ieee80211_channel *chan;
2341
	struct ieee80211_frame *wh;
2577
	struct ieee80211_frame *wh;
2342
	struct ieee80211_key *k = NULL;
2578
	struct ieee80211_key *k = NULL;
2343
	struct wpi_cmd_data tx;
2344
	struct wpi_buf tx_data;
2579
	struct wpi_buf tx_data;
2580
	struct wpi_cmd_data *tx = (struct wpi_cmd_data *)&tx_data.data;
2345
	uint32_t flags;
2581
	uint32_t flags;
2346
	uint16_t qos;
2582
	uint16_t qos;
2347
	uint8_t tid, type;
2583
	uint8_t tid, type;
2348
	int ac, error, rate, ismcast, hdrlen, totlen;
2584
	int ac, error, swcrypt, rate, ismcast, totlen;
2349
2585
2350
	wh = mtod(m, struct ieee80211_frame *);
2586
	wh = mtod(m, struct ieee80211_frame *);
2351
	hdrlen = ieee80211_anyhdrsize(wh);
2352
	type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2587
	type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2353
	ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
2588
	ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
2354
2589
Lines 2359-2365 Link Here
2359
	} else {
2594
	} else {
2360
		qos = 0;
2595
		qos = 0;
2361
		tid = 0;
2596
		tid = 0;
2362
        }
2597
	}
2363
	ac = M_WME_GETAC(m);
2598
	ac = M_WME_GETAC(m);
2364
2599
2365
	chan = (ni->ni_chan != IEEE80211_CHAN_ANYC) ?
2600
	chan = (ni->ni_chan != IEEE80211_CHAN_ANYC) ?
Lines 2389-2403 Link Here
2389
			error = ENOBUFS;
2624
			error = ENOBUFS;
2390
			goto fail;
2625
			goto fail;
2391
		}
2626
		}
2627
		swcrypt = k->wk_flags & IEEE80211_KEY_SWCRYPT;
2628
2392
		/* 802.11 header may have moved. */
2629
		/* 802.11 header may have moved. */
2393
		wh = mtod(m, struct ieee80211_frame *);
2630
		wh = mtod(m, struct ieee80211_frame *);
2394
	}
2631
	}
2395
	totlen = m->m_pkthdr.len - (hdrlen & 3);
2632
	totlen = m->m_pkthdr.len;
2396
2633
2397
	if (ieee80211_radiotap_active_vap(vap)) {
2634
	if (ieee80211_radiotap_active_vap(vap)) {
2398
		struct wpi_tx_radiotap_header *tap = &sc->sc_txtap;
2635
		struct wpi_tx_radiotap_header *tap = &sc->sc_txtap;
2399
2636
2400
		tap->wt_flags = IEEE80211_RADIOTAP_F_DATAPAD;
2637
		tap->wt_flags = 0;
2401
		tap->wt_rate = rate;
2638
		tap->wt_rate = rate;
2402
		if (k != NULL)
2639
		if (k != NULL)
2403
			tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
2640
			tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
Lines 2433-2439 Link Here
2433
			flags |= WPI_TX_FULL_TXOP;
2670
			flags |= WPI_TX_FULL_TXOP;
2434
	}
2671
	}
2435
2672
2436
	memset(&tx, 0, sizeof (struct wpi_cmd_data));
2673
	memset(tx, 0, sizeof (struct wpi_cmd_data));
2437
	if (type == IEEE80211_FC0_TYPE_MGT) {
2674
	if (type == IEEE80211_FC0_TYPE_MGT) {
2438
		uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
2675
		uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
2439
2676
Lines 2442-2467 Link Here
2442
			flags |= WPI_TX_INSERT_TSTAMP;
2679
			flags |= WPI_TX_INSERT_TSTAMP;
2443
		if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ ||
2680
		if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ ||
2444
		    subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ)
2681
		    subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ)
2445
			tx.timeout = htole16(3);
2682
			tx->timeout = htole16(3);
2446
		else
2683
		else
2447
			tx.timeout = htole16(2);
2684
			tx->timeout = htole16(2);
2448
	}
2685
	}
2449
2686
2450
	if (ismcast || type != IEEE80211_FC0_TYPE_DATA)
2687
	if (ismcast || type != IEEE80211_FC0_TYPE_DATA)
2451
		tx.id = WPI_ID_BROADCAST;
2688
		tx->id = WPI_ID_BROADCAST;
2452
	else {
2689
	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) {
2690
		if (wn->id == WPI_ID_UNDEFINED) {
2466
			device_printf(sc->sc_dev,
2691
			device_printf(sc->sc_dev,
2467
			    "%s: undefined node id\n", __func__);
2692
			    "%s: undefined node id\n", __func__);
Lines 2469-2504 Link Here
2469
			goto fail;
2694
			goto fail;
2470
		}
2695
		}
2471
2696
2472
		tx.id = wn->id;
2697
		tx->id = wn->id;
2473
	}
2698
	}
2474
2699
2475
	if (type != IEEE80211_FC0_TYPE_MGT)
2700
	if (type != IEEE80211_FC0_TYPE_MGT)
2476
		tx.data_ntries = tp->maxretry;
2701
		tx->data_ntries = tp->maxretry;
2477
2702
2478
	tx.len = htole16(totlen);
2703
	if (k != NULL && !swcrypt) {
2479
	tx.flags = htole32(flags);
2704
		switch (k->wk_cipher->ic_cipher) {
2480
	tx.plcp = rate2plcp(rate);
2705
		case IEEE80211_CIPHER_AES_CCM:
2481
	tx.tid = tid;
2706
			tx->security = WPI_CIPHER_CCMP;
2482
	tx.lifetime = htole32(WPI_LIFETIME_INFINITE);
2707
			break;
2483
	tx.ofdm_mask = 0xff;
2484
	tx.cck_mask = 0x0f;
2485
	tx.rts_ntries = 7;
2486
2708
2487
	if (k != NULL && k->wk_cipher->ic_cipher == IEEE80211_CIPHER_AES_CCM) {
2709
		default:
2488
		if (!(k->wk_flags & IEEE80211_KEY_SWCRYPT)) {
2710
			break;
2489
			tx.security = WPI_CIPHER_CCMP;
2490
			memcpy(tx.key, k->wk_key, k->wk_keylen);
2491
		}
2711
		}
2712
2713
		memcpy(tx->key, k->wk_key, k->wk_keylen);
2492
	}
2714
	}
2493
2715
2494
	tx_data.data = &tx;
2716
	tx->len = htole16(totlen);
2717
	tx->flags = htole32(flags);
2718
	tx->plcp = rate2plcp(rate);
2719
	tx->tid = tid;
2720
	tx->lifetime = htole32(WPI_LIFETIME_INFINITE);
2721
	tx->ofdm_mask = 0xff;
2722
	tx->cck_mask = 0x0f;
2723
	tx->rts_ntries = 7;
2724
2495
	tx_data.ni = ni;
2725
	tx_data.ni = ni;
2496
	tx_data.m = m;
2726
	tx_data.m = m;
2497
	tx_data.size = sizeof(tx);
2727
	tx_data.size = sizeof(struct wpi_cmd_data);
2498
	tx_data.code = WPI_CMD_TX_DATA;
2728
	tx_data.code = WPI_CMD_TX_DATA;
2499
	tx_data.ac = ac;
2729
	tx_data.ac = ac;
2500
2730
2501
	return wpi_cmd2(sc, &tx_data);
2731
	return wpi_cmd2(sc, &tx_data, 1);
2502
2732
2503
fail:	m_freem(m);
2733
fail:	m_freem(m);
2504
	return error;
2734
	return error;
Lines 2505-2525 Link Here
2505
}
2735
}
2506
2736
2507
static int
2737
static int
2508
wpi_tx_data_raw(struct wpi_softc *sc, struct mbuf *m, struct ieee80211_node *ni,
2738
wpi_tx_data_raw(struct wpi_softc *sc, struct mbuf *m,
2509
    const struct ieee80211_bpf_params *params)
2739
    struct ieee80211_node *ni, const struct ieee80211_bpf_params *params)
2510
{
2740
{
2511
	struct ieee80211vap *vap = ni->ni_vap;
2741
	struct ieee80211vap *vap = ni->ni_vap;
2742
	struct ieee80211_key *k = NULL;
2512
	struct ieee80211_frame *wh;
2743
	struct ieee80211_frame *wh;
2513
	struct wpi_cmd_data tx;
2514
	struct wpi_buf tx_data;
2744
	struct wpi_buf tx_data;
2745
	struct wpi_cmd_data *tx = (struct wpi_cmd_data *)&tx_data.data;
2515
	uint32_t flags;
2746
	uint32_t flags;
2516
	uint8_t type;
2747
	uint8_t type;
2517
	int ac, rate, hdrlen, totlen;
2748
	int ac, swcrypt, rate, totlen;
2518
2749
2519
	wh = mtod(m, struct ieee80211_frame *);
2750
	wh = mtod(m, struct ieee80211_frame *);
2520
	hdrlen = ieee80211_anyhdrsize(wh);
2521
	type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2751
	type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2522
	totlen = m->m_pkthdr.len - (hdrlen & 3);
2523
2752
2524
	ac = params->ibp_pri & 3;
2753
	ac = params->ibp_pri & 3;
2525
2754
Lines 2536-2553 Link Here
2536
	if (flags & (WPI_TX_NEED_RTS | WPI_TX_NEED_CTS))
2765
	if (flags & (WPI_TX_NEED_RTS | WPI_TX_NEED_CTS))
2537
		flags |= WPI_TX_FULL_TXOP;
2766
		flags |= WPI_TX_FULL_TXOP;
2538
2767
2768
	/* Encrypt the frame if need be. */
2769
	if (params->ibp_flags & IEEE80211_BPF_CRYPTO) {
2770
		/* Retrieve key for TX. */
2771
		k = ieee80211_crypto_encap(ni, m);
2772
		if (k == NULL) {
2773
			m_freem(m);
2774
			return ENOBUFS;
2775
		}
2776
		swcrypt = k->wk_flags & IEEE80211_KEY_SWCRYPT;
2777
2778
		/* 802.11 header may have moved. */
2779
		wh = mtod(m, struct ieee80211_frame *);
2780
	}
2781
	totlen = m->m_pkthdr.len;
2782
2539
	if (ieee80211_radiotap_active_vap(vap)) {
2783
	if (ieee80211_radiotap_active_vap(vap)) {
2540
		struct wpi_tx_radiotap_header *tap = &sc->sc_txtap;
2784
		struct wpi_tx_radiotap_header *tap = &sc->sc_txtap;
2541
2785
2542
		tap->wt_flags = 0;
2786
		tap->wt_flags = 0;
2543
		tap->wt_rate = rate;
2787
		tap->wt_rate = rate;
2544
		if (params->ibp_flags & IEEE80211_BPF_DATAPAD)
2788
		if (params->ibp_flags & IEEE80211_BPF_CRYPTO)
2545
			tap->wt_flags |= IEEE80211_RADIOTAP_F_DATAPAD;
2789
			tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
2546
2790
2547
		ieee80211_radiotap_tx(vap, m);
2791
		ieee80211_radiotap_tx(vap, m);
2548
	}
2792
	}
2549
2793
2550
	memset(&tx, 0, sizeof (struct wpi_cmd_data));
2794
	memset(tx, 0, sizeof (struct wpi_cmd_data));
2551
	if (type == IEEE80211_FC0_TYPE_MGT) {
2795
	if (type == IEEE80211_FC0_TYPE_MGT) {
2552
		uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
2796
		uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
2553
2797
Lines 2556-2582 Link Here
2556
			flags |= WPI_TX_INSERT_TSTAMP;
2800
			flags |= WPI_TX_INSERT_TSTAMP;
2557
		if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ ||
2801
		if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ ||
2558
		    subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ)
2802
		    subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ)
2559
			tx.timeout = htole16(3);
2803
			tx->timeout = htole16(3);
2560
		else
2804
		else
2561
			tx.timeout = htole16(2);
2805
			tx->timeout = htole16(2);
2562
	}
2806
	}
2563
2807
2564
	tx.len = htole16(totlen);
2808
	if (k != NULL && !swcrypt) {
2565
	tx.flags = htole32(flags);
2809
		switch (k->wk_cipher->ic_cipher) {
2566
	tx.plcp = rate2plcp(rate);
2810
		case IEEE80211_CIPHER_AES_CCM:
2567
	tx.id = WPI_ID_BROADCAST;
2811
			tx->security = WPI_CIPHER_CCMP;
2568
	tx.lifetime = htole32(WPI_LIFETIME_INFINITE);
2812
			break;
2569
	tx.rts_ntries = params->ibp_try1;
2570
	tx.data_ntries = params->ibp_try0;
2571
2813
2572
	tx_data.data = &tx;
2814
		default:
2815
			break;
2816
		}
2817
2818
		memcpy(tx->key, k->wk_key, k->wk_keylen);
2819
	}
2820
2821
	tx->len = htole16(totlen);
2822
	tx->flags = htole32(flags);
2823
	tx->plcp = rate2plcp(rate);
2824
	tx->id = WPI_ID_BROADCAST;
2825
	tx->lifetime = htole32(WPI_LIFETIME_INFINITE);
2826
	tx->rts_ntries = params->ibp_try1;
2827
	tx->data_ntries = params->ibp_try0;
2828
2573
	tx_data.ni = ni;
2829
	tx_data.ni = ni;
2574
	tx_data.m = m;
2830
	tx_data.m = m;
2575
	tx_data.size = sizeof(tx);
2831
	tx_data.size = sizeof(struct wpi_cmd_data);
2576
	tx_data.code = WPI_CMD_TX_DATA;
2832
	tx_data.code = WPI_CMD_TX_DATA;
2577
	tx_data.ac = ac;
2833
	tx_data.ac = ac;
2578
2834
2579
	return wpi_cmd2(sc, &tx_data);
2835
	return wpi_cmd2(sc, &tx_data, 1);
2580
}
2836
}
2581
2837
2582
static int
2838
static int
Lines 2596-2602 Link Here
2596
		return ENETDOWN;
2852
		return ENETDOWN;
2597
	}
2853
	}
2598
2854
2599
	WPI_LOCK(sc);
2855
	WPI_TX_LOCK(sc);
2600
	if (params == NULL) {
2856
	if (params == NULL) {
2601
		/*
2857
		/*
2602
		 * Legacy path; interpret frame contents to decide
2858
		 * Legacy path; interpret frame contents to decide
Lines 2610-2616 Link Here
2610
		 */
2866
		 */
2611
		error = wpi_tx_data_raw(sc, m, ni, params);
2867
		error = wpi_tx_data_raw(sc, m, ni, params);
2612
	}
2868
	}
2613
	WPI_UNLOCK(sc);
2869
	WPI_TX_UNLOCK(sc);
2614
2870
2615
	if (error != 0) {
2871
	if (error != 0) {
2616
		/* NB: m is reclaimed on tx failure */
2872
		/* NB: m is reclaimed on tx failure */
Lines 2622-2629 Link Here
2622
		return error;
2878
		return error;
2623
	}
2879
	}
2624
2880
2625
	sc->sc_tx_timer = 5;
2626
2627
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
2881
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
2628
2882
2629
	return 0;
2883
	return 0;
Lines 2636-2665 Link Here
2636
wpi_start(struct ifnet *ifp)
2890
wpi_start(struct ifnet *ifp)
2637
{
2891
{
2638
	struct wpi_softc *sc = ifp->if_softc;
2892
	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;
2893
	struct ieee80211_node *ni;
2650
	struct mbuf *m;
2894
	struct mbuf *m;
2651
2895
2652
	WPI_LOCK_ASSERT(sc);
2653
2654
	DPRINTF(sc, WPI_DEBUG_XMIT, "%s: called\n", __func__);
2896
	DPRINTF(sc, WPI_DEBUG_XMIT, "%s: called\n", __func__);
2655
2897
2898
	IF_LOCK(&ifp->if_snd);
2656
	if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ||
2899
	if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ||
2657
	    (ifp->if_drv_flags & IFF_DRV_OACTIVE))
2900
	    (ifp->if_drv_flags & IFF_DRV_OACTIVE)) {
2901
		IF_UNLOCK(&ifp->if_snd);
2658
		return;
2902
		return;
2903
	}
2904
	IF_UNLOCK(&ifp->if_snd);
2659
2905
2906
	WPI_TX_LOCK(sc);
2660
	for (;;) {
2907
	for (;;) {
2661
		if (sc->qfullmsk != 0) {
2908
		if (atomic_load_acq_32(&sc->qfullmsk) != 0) {
2909
			IF_LOCK(&ifp->if_snd);
2662
			ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2910
			ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2911
			IF_UNLOCK(&ifp->if_snd);
2663
			break;
2912
			break;
2664
		}
2913
		}
2665
		IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
2914
		IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
Lines 2667-2684 Link Here
2667
			break;
2916
			break;
2668
		ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
2917
		ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
2669
		if (wpi_tx_data(sc, m, ni) != 0) {
2918
		if (wpi_tx_data(sc, m, ni) != 0) {
2670
			WPI_UNLOCK(sc);
2671
			ieee80211_free_node(ni);
2919
			ieee80211_free_node(ni);
2672
			WPI_LOCK(sc);
2673
			if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2920
			if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2674
		} else
2921
		}
2675
			sc->sc_tx_timer = 5;
2676
	}
2922
	}
2923
	WPI_TX_UNLOCK(sc);
2677
2924
2678
	DPRINTF(sc, WPI_DEBUG_XMIT, "%s: done\n", __func__);
2925
	DPRINTF(sc, WPI_DEBUG_XMIT, "%s: done\n", __func__);
2679
}
2926
}
2680
2927
2681
static void
2928
static void
2929
wpi_start_task(void *arg0, int pending)
2930
{
2931
	struct wpi_softc *sc = arg0;
2932
	struct ifnet *ifp = sc->sc_ifp;
2933
2934
	wpi_start(ifp);
2935
}
2936
2937
static void
2682
wpi_watchdog_rfkill(void *arg)
2938
wpi_watchdog_rfkill(void *arg)
2683
{
2939
{
2684
	struct wpi_softc *sc = arg;
2940
	struct wpi_softc *sc = arg;
Lines 2706-2716 Link Here
2706
	struct wpi_softc *sc = arg;
2962
	struct wpi_softc *sc = arg;
2707
	struct ifnet *ifp = sc->sc_ifp;
2963
	struct ifnet *ifp = sc->sc_ifp;
2708
	struct ieee80211com *ic = ifp->if_l2com;
2964
	struct ieee80211com *ic = ifp->if_l2com;
2965
	int32_t tmp;
2709
2966
2710
	DPRINTF(sc, WPI_DEBUG_WATCHDOG, "Watchdog: tick\n");
2967
	DPRINTF(sc, WPI_DEBUG_WATCHDOG, "Watchdog: tick\n");
2711
2968
2712
	if (sc->sc_tx_timer > 0) {
2969
	tmp = atomic_load_acq_32(&sc->sc_tx_timer);
2713
		if (--sc->sc_tx_timer == 0) {
2970
	if (tmp > 0) {
2971
		tmp -= 1;
2972
		atomic_cmpset_rel_32(&sc->sc_tx_timer, tmp + 1, tmp);
2973
		if (tmp == 0) {
2714
			if_printf(ifp, "device timeout\n");
2974
			if_printf(ifp, "device timeout\n");
2715
			if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2975
			if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2716
			ieee80211_runtask(ic, &sc->sc_reinittask);
2976
			ieee80211_runtask(ic, &sc->sc_reinittask);
Lines 2717-2725 Link Here
2717
		}
2977
		}
2718
	}
2978
	}
2719
2979
2720
	if (sc->sc_scan_timer > 0) {
2980
	tmp = atomic_load_acq_32(&sc->sc_scan_timer);
2981
	if (tmp > 0) {
2721
		struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2982
		struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2722
		if (--sc->sc_scan_timer == 0 && vap != NULL) {
2983
		tmp -= 1;
2984
		atomic_cmpset_rel_32(&sc->sc_scan_timer, tmp + 1, tmp);
2985
		if (tmp == 0 && vap != NULL) {
2723
			if_printf(ifp, "scan timeout\n");
2986
			if_printf(ifp, "scan timeout\n");
2724
			ieee80211_cancel_scan(vap);
2987
			ieee80211_cancel_scan(vap);
2725
			ieee80211_runtask(ic, &sc->sc_reinittask);
2988
			ieee80211_runtask(ic, &sc->sc_reinittask);
Lines 2726-2732 Link Here
2726
		}
2989
		}
2727
	}
2990
	}
2728
2991
2729
	if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2992
	if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
2730
		callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
2993
		callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
2731
}
2994
}
2732
2995
Lines 2737-2743 Link Here
2737
	struct ieee80211com *ic = ifp->if_l2com;
3000
	struct ieee80211com *ic = ifp->if_l2com;
2738
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3001
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2739
	struct ifreq *ifr = (struct ifreq *) data;
3002
	struct ifreq *ifr = (struct ifreq *) data;
2740
	int error = 0, startall = 0, stop = 0;
3003
	int error = 0;
2741
3004
2742
	switch (cmd) {
3005
	switch (cmd) {
2743
	case SIOCGIFADDR:
3006
	case SIOCGIFADDR:
Lines 2744-2766 Link Here
2744
		error = ether_ioctl(ifp, cmd, data);
3007
		error = ether_ioctl(ifp, cmd, data);
2745
		break;
3008
		break;
2746
	case SIOCSIFFLAGS:
3009
	case SIOCSIFFLAGS:
2747
		WPI_LOCK(sc);
2748
		if (ifp->if_flags & IFF_UP) {
3010
		if (ifp->if_flags & IFF_UP) {
2749
			if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
3011
			wpi_init(sc);
2750
				wpi_init_locked(sc);
3012
2751
				if (WPI_READ(sc, WPI_GP_CNTRL) &
3013
			if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 &&
2752
				    WPI_GP_CNTRL_RFKILL)
3014
			    vap != NULL)
2753
					startall = 1;
3015
				ieee80211_stop(vap);
2754
				else
3016
		} else if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
2755
					stop = 1;
3017
			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;
3018
		break;
2765
	case SIOCGIFMEDIA:
3019
	case SIOCGIFMEDIA:
2766
		error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd);
3020
		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,
3033
wpi_cmd(struct wpi_softc *sc, int code, const void *buf, size_t size,
2780
    int async)
3034
    int async)
2781
{
3035
{
2782
	struct wpi_tx_ring *ring = &sc->txq[4];
3036
	struct wpi_tx_ring *ring = &sc->txq[WPI_CMD_QUEUE_NUM];
2783
	struct wpi_tx_desc *desc;
3037
	struct wpi_tx_desc *desc;
2784
	struct wpi_tx_data *data;
3038
	struct wpi_tx_data *data;
2785
	struct wpi_tx_cmd *cmd;
3039
	struct wpi_tx_cmd *cmd;
Lines 2787-2807 Link Here
2787
	bus_addr_t paddr;
3041
	bus_addr_t paddr;
2788
	int totlen, error;
3042
	int totlen, error;
2789
3043
3044
	WPI_TXQ_LOCK(sc);
3045
2790
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
3046
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
2791
3047
2792
	if (async == 0)
3048
	if (atomic_load_acq_32(&sc->txq_active) == 0) {
2793
		WPI_LOCK_ASSERT(sc);
3049
		error = 0;
3050
		goto fail;
3051
	}
2794
3052
2795
	DPRINTF(sc, WPI_DEBUG_CMD, "wpi_cmd %s size %zu async %d\n",
3053
	DPRINTF(sc, WPI_DEBUG_CMD, "%s: cmd %s size %zu async %d\n",
2796
	    wpi_cmd_str(code), size, async);
3054
	    __func__, wpi_cmd_str(code), size, async);
2797
3055
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];
3056
	desc = &ring->desc[ring->cur];
2806
	data = &ring->data[ring->cur];
3057
	data = &ring->data[ring->cur];
2807
	totlen = 4 + size;
3058
	totlen = 4 + size;
Lines 2808-2824 Link Here
2808
3059
2809
	if (size > sizeof cmd->data) {
3060
	if (size > sizeof cmd->data) {
2810
		/* Command is too large to fit in a descriptor. */
3061
		/* Command is too large to fit in a descriptor. */
2811
		if (totlen > MCLBYTES)
3062
		if (totlen > MCLBYTES) {
2812
			return EINVAL;
3063
			error = EINVAL;
3064
			goto fail;
3065
		}
2813
		m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE);
3066
		m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE);
2814
		if (m == NULL)
3067
		if (m == NULL) {
2815
			return ENOMEM;
3068
			error = ENOMEM;
3069
			goto fail;
3070
		}
2816
		cmd = mtod(m, struct wpi_tx_cmd *);
3071
		cmd = mtod(m, struct wpi_tx_cmd *);
2817
		error = bus_dmamap_load(ring->data_dmat, data->map, cmd,
3072
		error = bus_dmamap_load(ring->data_dmat, data->map, cmd,
2818
		    totlen, wpi_dma_map_addr, &paddr, BUS_DMA_NOWAIT);
3073
		    totlen, wpi_dma_map_addr, &paddr, BUS_DMA_NOWAIT);
2819
		if (error != 0) {
3074
		if (error != 0) {
2820
			m_freem(m);
3075
			m_freem(m);
2821
			return error;
3076
			goto fail;
2822
		}
3077
		}
2823
		data->m = m;
3078
		data->m = m;
2824
	} else {
3079
	} else {
Lines 2850-2863 Link Here
2850
	ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT;
3105
	ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT;
2851
	wpi_update_tx_ring(sc, ring);
3106
	wpi_update_tx_ring(sc, ring);
2852
3107
3108
	WPI_TXQ_UNLOCK(sc);
3109
2853
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3110
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
2854
3111
2855
	if (async) {
3112
	if (async)
2856
		sc->flags &= ~WPI_FLAG_BUSY;
2857
		return 0;
3113
		return 0;
2858
	}
2859
3114
2860
	return msleep(cmd, &sc->sc_mtx, PCATCH, "wpicmd", hz);
3115
	return mtx_sleep(cmd, &sc->sc_mtx, PCATCH, "wpicmd", hz);
3116
3117
fail:	WPI_TXQ_UNLOCK(sc);
3118
3119
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
3120
3121
	return error;
2861
}
3122
}
2862
3123
2863
/*
3124
/*
Lines 2917-2924 Link Here
2917
wpi_add_node(struct wpi_softc *sc, struct ieee80211_node *ni)
3178
wpi_add_node(struct wpi_softc *sc, struct ieee80211_node *ni)
2918
{
3179
{
2919
	struct ieee80211com *ic = ni->ni_ic;
3180
	struct ieee80211com *ic = ni->ni_ic;
2920
	struct wpi_node *wn = (void *)ni;
3181
	struct ieee80211vap *vap = ni->ni_vap;
3182
	struct wpi_vap *wvp = WPI_VAP(vap);
3183
	struct wpi_node *wn = WPI_NODE(ni);
2921
	struct wpi_node_info node;
3184
	struct wpi_node_info node;
3185
	int error;
2922
3186
2923
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3187
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
2924
3188
Lines 2926-2932 Link Here
2926
		return EINVAL;
3190
		return EINVAL;
2927
3191
2928
	memset(&node, 0, sizeof node);
3192
	memset(&node, 0, sizeof node);
2929
	IEEE80211_ADDR_COPY(node.macaddr, ni->ni_bssid);
3193
	IEEE80211_ADDR_COPY(node.macaddr, ni->ni_macaddr);
2930
	node.id = wn->id;
3194
	node.id = wn->id;
2931
	node.plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ?
3195
	node.plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ?
2932
	    wpi_ridx_to_plcp[WPI_RIDX_OFDM6] : wpi_ridx_to_plcp[WPI_RIDX_CCK1];
3196
	    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);
3197
	node.action = htole32(WPI_ACTION_SET_RATE);
2934
	node.antenna = WPI_ANTENNA_BOTH;
3198
	node.antenna = WPI_ANTENNA_BOTH;
2935
3199
2936
	return wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
3200
	DPRINTF(sc, WPI_DEBUG_NODE, "%s: adding node %d (%s)\n", __func__,
3201
	    wn->id, ether_sprintf(ni->ni_macaddr));
3202
3203
	error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
3204
	if (error != 0) {
3205
		device_printf(sc->sc_dev,
3206
		    "%s: wpi_cmd() call failed with error code %d\n", __func__,
3207
		    error);
3208
		return error;
3209
	}
3210
3211
	if (atomic_load_acq_32(&wvp->wv_gtk) != 0) {
3212
		error = wpi_set_global_keys(ni);
3213
		if (error != 0) {
3214
			device_printf(sc->sc_dev,
3215
			    "%s: error while setting global keys\n", __func__);
3216
			return ENXIO;
3217
		}
3218
	}
3219
3220
	return 0;
2937
}
3221
}
2938
3222
2939
/*
3223
/*
Lines 2956-2968 Link Here
2956
	node.action = htole32(WPI_ACTION_SET_RATE);
3240
	node.action = htole32(WPI_ACTION_SET_RATE);
2957
	node.antenna = WPI_ANTENNA_BOTH;
3241
	node.antenna = WPI_ANTENNA_BOTH;
2958
3242
3243
	DPRINTF(sc, WPI_DEBUG_NODE, "%s: adding broadcast node\n", __func__);
3244
2959
	return wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, async);
3245
	return wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, async);
2960
}
3246
}
2961
3247
2962
static int
3248
static int
3249
wpi_add_sta_node(struct wpi_softc *sc, struct ieee80211_node *ni)
3250
{
3251
	struct wpi_node *wn = WPI_NODE(ni);
3252
	int error;
3253
3254
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3255
3256
	wn->id = wpi_add_node_entry_sta(sc);
3257
3258
	if ((error = wpi_add_node(sc, ni)) != 0) {
3259
		wpi_del_node_entry(sc, wn->id);
3260
		wn->id = WPI_ID_UNDEFINED;
3261
		return error;
3262
	}
3263
3264
	return 0;
3265
}
3266
3267
static int
2963
wpi_add_ibss_node(struct wpi_softc *sc, struct ieee80211_node *ni)
3268
wpi_add_ibss_node(struct wpi_softc *sc, struct ieee80211_node *ni)
2964
{
3269
{
2965
	struct wpi_node *wn = (void *)ni;
3270
	struct wpi_node *wn = WPI_NODE(ni);
3271
	int error;
2966
3272
2967
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3273
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
2968
3274
Lines 2969-3001 Link Here
2969
	if (wn->id != WPI_ID_UNDEFINED)
3275
	if (wn->id != WPI_ID_UNDEFINED)
2970
		return EINVAL;
3276
		return EINVAL;
2971
3277
2972
	wn->id = alloc_unrl(sc->sc_unr);
3278
	if ((wn->id = wpi_add_node_entry_adhoc(sc)) == WPI_ID_UNDEFINED) {
3279
		device_printf(sc->sc_dev, "%s: h/w table is full\n", __func__);
3280
		return ENOMEM;
3281
	}
2973
3282
2974
	if (wn->id == (uint8_t)-1)
3283
	if ((error = wpi_add_node(sc, ni)) != 0) {
2975
		return ENOBUFS;
3284
		wpi_del_node_entry(sc, wn->id);
3285
		wn->id = WPI_ID_UNDEFINED;
3286
		return error;
3287
	}
2976
3288
2977
	return wpi_add_node(sc, ni);
3289
	return 0;
2978
}
3290
}
2979
3291
2980
static void
3292
static void
2981
wpi_del_node(struct wpi_softc *sc, struct ieee80211_node *ni)
3293
wpi_del_node(struct wpi_softc *sc, struct ieee80211_node *ni)
2982
{
3294
{
2983
	struct wpi_node *wn = (void *)ni;
3295
	struct wpi_node *wn = WPI_NODE(ni);
2984
	struct wpi_cmd_del_node node;
3296
	struct wpi_cmd_del_node node;
2985
	int error;
3297
	int error;
2986
3298
3299
	KASSERT(wn->id != WPI_ID_UNDEFINED, ("undefined node id passed"));
3300
2987
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3301
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
2988
3302
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);
3303
	memset(&node, 0, sizeof node);
2996
	IEEE80211_ADDR_COPY(node.macaddr, ni->ni_bssid);
3304
	IEEE80211_ADDR_COPY(node.macaddr, ni->ni_macaddr);
2997
	node.count = 1;
3305
	node.count = 1;
2998
3306
3307
	DPRINTF(sc, WPI_DEBUG_NODE, "%s: deleting node %d (%s)\n", __func__,
3308
	    wn->id, ether_sprintf(ni->ni_macaddr));
3309
2999
	error = wpi_cmd(sc, WPI_CMD_DEL_NODE, &node, sizeof node, 1);
3310
	error = wpi_cmd(sc, WPI_CMD_DEL_NODE, &node, sizeof node, 1);
3000
	if (error != 0) {
3311
	if (error != 0) {
3001
		device_printf(sc->sc_dev,
3312
		device_printf(sc->sc_dev,
Lines 3031-3041 Link Here
3031
		    cmd.ac[aci].cwmin, cmd.ac[aci].cwmax,
3342
		    cmd.ac[aci].cwmin, cmd.ac[aci].cwmax,
3032
		    cmd.ac[aci].txoplimit);
3343
		    cmd.ac[aci].txoplimit);
3033
	}
3344
	}
3034
	IEEE80211_UNLOCK(ic);
3035
	WPI_LOCK(sc);
3036
	error = wpi_cmd(sc, WPI_CMD_EDCA_PARAMS, &cmd, sizeof cmd, 1);
3345
	error = wpi_cmd(sc, WPI_CMD_EDCA_PARAMS, &cmd, sizeof cmd, 1);
3037
	WPI_UNLOCK(sc);
3038
	IEEE80211_LOCK(ic);
3039
3346
3040
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3347
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3041
3348
Lines 3047-3055 Link Here
3047
wpi_set_promisc(struct wpi_softc *sc)
3354
wpi_set_promisc(struct wpi_softc *sc)
3048
{
3355
{
3049
	struct ifnet *ifp = sc->sc_ifp;
3356
	struct ifnet *ifp = sc->sc_ifp;
3357
	struct ieee80211com *ic = ifp->if_l2com;
3358
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3050
	uint32_t promisc_filter;
3359
	uint32_t promisc_filter;
3051
3360
3052
	promisc_filter = WPI_FILTER_PROMISC | WPI_FILTER_CTL;
3361
	promisc_filter = WPI_FILTER_CTL;
3362
	if (vap != NULL && vap->iv_opmode != IEEE80211_M_HOSTAP)
3363
		promisc_filter |= WPI_FILTER_PROMISC;
3053
3364
3054
	if (ifp->if_flags & IFF_PROMISC)
3365
	if (ifp->if_flags & IFF_PROMISC)
3055
		sc->rxon.filter |= htole32(promisc_filter);
3366
		sc->rxon.filter |= htole32(promisc_filter);
Lines 3062-3075 Link Here
3062
{
3373
{
3063
	struct wpi_softc *sc = ifp->if_softc;
3374
	struct wpi_softc *sc = ifp->if_softc;
3064
3375
3376
	WPI_RXON_LOCK(sc);
3065
	wpi_set_promisc(sc);
3377
	wpi_set_promisc(sc);
3066
3378
3067
	WPI_LOCK(sc);
3068
	if (wpi_send_rxon(sc, 1, 1) != 0) {
3379
	if (wpi_send_rxon(sc, 1, 1) != 0) {
3069
		device_printf(sc->sc_dev, "%s: could not send RXON\n",
3380
		device_printf(sc->sc_dev, "%s: could not send RXON\n",
3070
		    __func__);
3381
		    __func__);
3071
	}
3382
	}
3072
	WPI_UNLOCK(sc);
3383
	WPI_RXON_UNLOCK(sc);
3073
}
3384
}
3074
3385
3075
static void
3386
static void
Lines 3159-3166 Link Here
3159
static int
3470
static int
3160
wpi_set_txpower(struct wpi_softc *sc, int async)
3471
wpi_set_txpower(struct wpi_softc *sc, int async)
3161
{
3472
{
3162
	struct ifnet *ifp = sc->sc_ifp;
3473
	struct ieee80211com *ic = sc->sc_ifp->if_l2com;
3163
	struct ieee80211com *ic = ifp->if_l2com;
3164
	struct ieee80211_channel *ch;
3474
	struct ieee80211_channel *ch;
3165
	struct wpi_power_group *group;
3475
	struct wpi_power_group *group;
3166
	struct wpi_cmd_txpower cmd;
3476
	struct wpi_cmd_txpower cmd;
Lines 3214-3228 Link Here
3214
    struct ieee80211_channel *c, int ridx)
3524
    struct ieee80211_channel *c, int ridx)
3215
{
3525
{
3216
/* Fixed-point arithmetic division using a n-bit fractional part. */
3526
/* Fixed-point arithmetic division using a n-bit fractional part. */
3217
#define fdivround(a, b, n)      \
3527
#define fdivround(a, b, n)	\
3218
	((((1 << n) * (a)) / (b) + (1 << n) / 2) / (1 << n))
3528
	((((1 << n) * (a)) / (b) + (1 << n) / 2) / (1 << n))
3219
3529
3220
/* Linear interpolation. */
3530
/* Linear interpolation. */
3221
#define interpolate(x, x1, y1, x2, y2, n)       \
3531
#define interpolate(x, x1, y1, x2, y2, n)	\
3222
	((y1) + fdivround(((x) - (x1)) * ((y2) - (y1)), (x2) - (x1), n))
3532
	((y1) + fdivround(((x) - (x1)) * ((y2) - (y1)), (x2) - (x1), n))
3223
3533
3224
	struct ifnet *ifp = sc->sc_ifp;
3534
	struct ieee80211com *ic = sc->sc_ifp->if_l2com;
3225
	struct ieee80211com *ic = ifp->if_l2com;
3226
	struct wpi_power_sample *sample;
3535
	struct wpi_power_sample *sample;
3227
	int pwr, idx;
3536
	int pwr, idx;
3228
	u_int chan;
3537
	u_int chan;
Lines 3335-3352 Link Here
3335
	return wpi_cmd(sc, WPI_CMD_SET_POWER_MODE, &cmd, sizeof cmd, async);
3644
	return wpi_cmd(sc, WPI_CMD_SET_POWER_MODE, &cmd, sizeof cmd, async);
3336
}
3645
}
3337
3646
3338
static int      
3647
static int
3339
wpi_send_btcoex(struct wpi_softc *sc)
3648
wpi_send_btcoex(struct wpi_softc *sc)
3340
{
3649
{
3341
	struct wpi_bluetooth cmd;
3650
	struct wpi_bluetooth cmd;
3342
3651
3343
        memset(&cmd, 0, sizeof cmd);
3652
	memset(&cmd, 0, sizeof cmd);
3344
        cmd.flags = WPI_BT_COEX_MODE_4WIRE;
3653
	cmd.flags = WPI_BT_COEX_MODE_4WIRE;
3345
        cmd.lead_time = WPI_BT_LEAD_TIME_DEF;
3654
	cmd.lead_time = WPI_BT_LEAD_TIME_DEF;
3346
        cmd.max_kill = WPI_BT_MAX_KILL_DEF;
3655
	cmd.max_kill = WPI_BT_MAX_KILL_DEF;
3347
	DPRINTF(sc, WPI_DEBUG_RESET, "%s: configuring bluetooth coexistence\n",
3656
	DPRINTF(sc, WPI_DEBUG_RESET, "%s: configuring bluetooth coexistence\n",
3348
	    __func__);
3657
	    __func__);
3349
        return wpi_cmd(sc, WPI_CMD_BT_COEX, &cmd, sizeof(cmd), 0);
3658
	return wpi_cmd(sc, WPI_CMD_BT_COEX, &cmd, sizeof(cmd), 0);
3350
}
3659
}
3351
3660
3352
static int
3661
static int
Lines 3354-3359 Link Here
3354
{
3663
{
3355
	int error;
3664
	int error;
3356
3665
3666
	if (async)
3667
		WPI_RXON_LOCK_ASSERT(sc);
3668
3357
	if (assoc && (sc->rxon.filter & htole32(WPI_FILTER_BSS))) {
3669
	if (assoc && (sc->rxon.filter & htole32(WPI_FILTER_BSS))) {
3358
		struct wpi_assoc rxon_assoc;
3670
		struct wpi_assoc rxon_assoc;
3359
3671
Lines 3365-3388 Link Here
3365
3677
3366
		error = wpi_cmd(sc, WPI_CMD_RXON_ASSOC, &rxon_assoc,
3678
		error = wpi_cmd(sc, WPI_CMD_RXON_ASSOC, &rxon_assoc,
3367
		    sizeof (struct wpi_assoc), async);
3679
		    sizeof (struct wpi_assoc), async);
3680
		if (error != 0) {
3681
			device_printf(sc->sc_dev,
3682
			    "RXON_ASSOC command failed, error %d\n", error);
3683
			return error;
3684
		}
3368
	} else {
3685
	} else {
3686
		if (async)
3687
			WPI_NT_LOCK(sc);
3688
3369
		error = wpi_cmd(sc, WPI_CMD_RXON, &sc->rxon,
3689
		error = wpi_cmd(sc, WPI_CMD_RXON, &sc->rxon,
3370
		    sizeof (struct wpi_rxon), async);
3690
		    sizeof (struct wpi_rxon), async);
3371
	}
3691
		if (error != 0) {
3372
	if (error != 0) {
3692
			device_printf(sc->sc_dev,
3373
		device_printf(sc->sc_dev, "RXON command failed, error %d\n",
3693
			    "RXON command failed, error %d\n", error);
3374
		    error);
3694
			return error;
3375
		return error;
3695
		}
3376
	}
3377
3696
3378
	/* Configuration has changed, set Tx power accordingly. */
3697
		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
3698
3385
	if (!(sc->rxon.filter & htole32(WPI_FILTER_BSS))) {
3699
		if (async)
3700
			WPI_NT_UNLOCK(sc);
3701
3386
		/* Add broadcast node. */
3702
		/* Add broadcast node. */
3387
		error = wpi_add_broadcast_node(sc, async);
3703
		error = wpi_add_broadcast_node(sc, async);
3388
		if (error != 0) {
3704
		if (error != 0) {
Lines 3392-3397 Link Here
3392
		}
3708
		}
3393
	}
3709
	}
3394
3710
3711
	/* Configuration has changed, set Tx power accordingly. */
3712
	if ((error = wpi_set_txpower(sc, async)) != 0) {
3713
		device_printf(sc->sc_dev,
3714
		    "%s: could not set TX power, error %d\n", __func__, error);
3715
		return error;
3716
	}
3717
3395
	return 0;
3718
	return 0;
3396
}
3719
}
3397
3720
Lines 3404-3409 Link Here
3404
{
3727
{
3405
	struct ifnet *ifp = sc->sc_ifp;
3728
	struct ifnet *ifp = sc->sc_ifp;
3406
	struct ieee80211com *ic = ifp->if_l2com;
3729
	struct ieee80211com *ic = ifp->if_l2com;
3730
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3407
	uint32_t flags;
3731
	uint32_t flags;
3408
	int error;
3732
	int error;
3409
3733
Lines 3425-3431 Link Here
3425
3749
3426
	/* Configure adapter. */
3750
	/* Configure adapter. */
3427
	memset(&sc->rxon, 0, sizeof (struct wpi_rxon));
3751
	memset(&sc->rxon, 0, sizeof (struct wpi_rxon));
3428
	IEEE80211_ADDR_COPY(sc->rxon.myaddr, IF_LLADDR(ifp));
3752
	IEEE80211_ADDR_COPY(sc->rxon.myaddr, vap->iv_myaddr);
3429
3753
3430
	/* Set default channel. */
3754
	/* Set default channel. */
3431
	sc->rxon.chan = ieee80211_chan2ieee(ic, ic->ic_curchan);
3755
	sc->rxon.chan = ieee80211_chan2ieee(ic, ic->ic_curchan);
Lines 3442-3450 Link Here
3442
		sc->rxon.mode = WPI_MODE_IBSS;
3766
		sc->rxon.mode = WPI_MODE_IBSS;
3443
		sc->rxon.filter |= WPI_FILTER_BEACON;
3767
		sc->rxon.filter |= WPI_FILTER_BEACON;
3444
		break;
3768
		break;
3445
	/* XXX workaround for passive channels selection */
3769
	case IEEE80211_M_HOSTAP:
3770
		/* XXX workaround for beaconing */
3771
		sc->rxon.mode = WPI_MODE_IBSS;
3772
		sc->rxon.filter |= WPI_FILTER_ASSOC | WPI_FILTER_PROMISC;
3773
		break;
3446
	case IEEE80211_M_AHDEMO:
3774
	case IEEE80211_M_AHDEMO:
3447
	case IEEE80211_M_HOSTAP:
3775
		/* XXX workaround for passive channels selection */
3448
		sc->rxon.mode = WPI_MODE_HOSTAP;
3776
		sc->rxon.mode = WPI_MODE_HOSTAP;
3449
		break;
3777
		break;
3450
	case IEEE80211_M_MONITOR:
3778
	case IEEE80211_M_MONITOR:
Lines 3451-3457 Link Here
3451
		sc->rxon.mode = WPI_MODE_MONITOR;
3779
		sc->rxon.mode = WPI_MODE_MONITOR;
3452
		break;
3780
		break;
3453
	default:
3781
	default:
3454
		device_printf(sc->sc_dev, "unknown opmode %d\n", ic->ic_opmode);
3782
		device_printf(sc->sc_dev, "unknown opmode %d\n",
3783
		    ic->ic_opmode);
3455
		return EINVAL;
3784
		return EINVAL;
3456
	}
3785
	}
3457
	sc->rxon.filter = htole32(sc->rxon.filter);
3786
	sc->rxon.filter = htole32(sc->rxon.filter);
Lines 3510-3523 Link Here
3510
wpi_limit_dwell(struct wpi_softc *sc, uint16_t dwell_time)
3839
wpi_limit_dwell(struct wpi_softc *sc, uint16_t dwell_time)
3511
{
3840
{
3512
	struct ieee80211com *ic = sc->sc_ifp->if_l2com;
3841
	struct ieee80211com *ic = sc->sc_ifp->if_l2com;
3513
	struct ieee80211vap *vap = NULL;
3842
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3514
	int bintval = 0;
3843
	int bintval = 0;
3515
3844
3516
	/* bintval is in TU (1.024mS) */
3845
	/* bintval is in TU (1.024mS) */
3517
	if (! TAILQ_EMPTY(&ic->ic_vaps)) {
3846
	if (vap != NULL)
3518
		vap = TAILQ_FIRST(&ic->ic_vaps);
3519
		bintval = vap->iv_bss->ni_intval;
3847
		bintval = vap->iv_bss->ni_intval;
3520
	}
3521
3848
3522
	/*
3849
	/*
3523
	 * If it's non-zero, we should calculate the minimum of
3850
	 * If it's non-zero, we should calculate the minimum of
Lines 3559-3564 Link Here
3559
	struct ifnet *ifp = sc->sc_ifp;
3886
	struct ifnet *ifp = sc->sc_ifp;
3560
	struct ieee80211com *ic = ifp->if_l2com;
3887
	struct ieee80211com *ic = ifp->if_l2com;
3561
	struct ieee80211_scan_state *ss = ic->ic_scan;
3888
	struct ieee80211_scan_state *ss = ic->ic_scan;
3889
	struct ieee80211vap *vap = ss->ss_vap;
3562
	struct wpi_scan_hdr *hdr;
3890
	struct wpi_scan_hdr *hdr;
3563
	struct wpi_cmd_data *tx;
3891
	struct wpi_cmd_data *tx;
3564
	struct wpi_scan_essid *essids;
3892
	struct wpi_scan_essid *essids;
Lines 3575-3583 Link Here
3575
	 * We are absolutely not allowed to send a scan command when another
3903
	 * We are absolutely not allowed to send a scan command when another
3576
	 * scan command is pending.
3904
	 * scan command is pending.
3577
	 */
3905
	 */
3578
	if (sc->sc_scan_timer) {
3906
	if (atomic_cmpset_acq_32(&sc->sc_scan_timer, 0, 5) == 0) {
3579
		device_printf(sc->sc_dev, "%s: called whilst scanning!\n",
3907
		device_printf(sc->sc_dev, "%s: called whilst scanning!\n",
3580
		    __func__);
3908
		    __func__);
3909
3910
		DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
3911
3581
		return (EAGAIN);
3912
		return (EAGAIN);
3582
	}
3913
	}
3583
3914
Lines 3586-3592 Link Here
3586
		device_printf(sc->sc_dev,
3917
		device_printf(sc->sc_dev,
3587
		    "%s: could not allocate buffer for scan command\n",
3918
		    "%s: could not allocate buffer for scan command\n",
3588
		    __func__);
3919
		    __func__);
3589
		return ENOMEM;
3920
		error = ENOMEM;
3921
		goto fail;
3590
	}
3922
	}
3591
	hdr = (struct wpi_scan_hdr *)buf;
3923
	hdr = (struct wpi_scan_hdr *)buf;
3592
3924
Lines 3645-3651 Link Here
3645
		IEEE80211_FC0_SUBTYPE_PROBE_REQ;
3977
		IEEE80211_FC0_SUBTYPE_PROBE_REQ;
3646
	wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
3978
	wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
3647
	IEEE80211_ADDR_COPY(wh->i_addr1, ifp->if_broadcastaddr);
3979
	IEEE80211_ADDR_COPY(wh->i_addr1, ifp->if_broadcastaddr);
3648
	IEEE80211_ADDR_COPY(wh->i_addr2, IF_LLADDR(ifp));
3980
	IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
3649
	IEEE80211_ADDR_COPY(wh->i_addr3, ifp->if_broadcastaddr);
3981
	IEEE80211_ADDR_COPY(wh->i_addr3, ifp->if_broadcastaddr);
3650
	*(uint16_t *)&wh->i_dur[0] = 0;	/* filled by h/w */
3982
	*(uint16_t *)&wh->i_dur[0] = 0;	/* filled by h/w */
3651
	*(uint16_t *)&wh->i_seq[0] = 0;	/* filled by h/w */
3983
	*(uint16_t *)&wh->i_seq[0] = 0;	/* filled by h/w */
Lines 3698-3704 Link Here
3698
		chan->rf_gain = 0x28;
4030
		chan->rf_gain = 0x28;
3699
4031
3700
	DPRINTF(sc, WPI_DEBUG_SCAN, "Scanning %u Passive: %d\n",
4032
	DPRINTF(sc, WPI_DEBUG_SCAN, "Scanning %u Passive: %d\n",
3701
	     chan->chan, IEEE80211_IS_CHAN_PASSIVE(c));
4033
	    chan->chan, IEEE80211_IS_CHAN_PASSIVE(c));
3702
4034
3703
	hdr->nchan++;
4035
	hdr->nchan++;
3704
	chan++;
4036
	chan++;
Lines 3711-3720 Link Here
3711
	error = wpi_cmd(sc, WPI_CMD_SCAN, buf, buflen, 1);
4043
	error = wpi_cmd(sc, WPI_CMD_SCAN, buf, buflen, 1);
3712
	free(buf, M_DEVBUF);
4044
	free(buf, M_DEVBUF);
3713
4045
3714
	sc->sc_scan_timer = 5;
4046
	if (error != 0)
4047
		goto fail;
3715
4048
3716
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
4049
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3717
4050
4051
	return 0;
4052
4053
fail:	atomic_store_rel_32(&sc->sc_scan_timer, 0);
4054
4055
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
4056
3718
	return error;
4057
	return error;
3719
}
4058
}
3720
4059
Lines 3728-3733 Link Here
3728
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
4067
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
3729
4068
3730
	/* Update adapter configuration. */
4069
	/* Update adapter configuration. */
4070
	WPI_RXON_LOCK(sc);
3731
	sc->rxon.associd = 0;
4071
	sc->rxon.associd = 0;
3732
	sc->rxon.filter &= ~htole32(WPI_FILTER_BSS);
4072
	sc->rxon.filter &= ~htole32(WPI_FILTER_BSS);
3733
	IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid);
4073
	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",
4099
		device_printf(sc->sc_dev, "%s: could not send RXON\n",
3760
		    __func__);
4100
		    __func__);
3761
	}
4101
	}
4102
	WPI_RXON_UNLOCK(sc);
3762
4103
3763
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
4104
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3764
4105
Lines 3766-3782 Link Here
3766
}
4107
}
3767
4108
3768
static int
4109
static int
4110
wpi_config_beacon(struct wpi_vap *wvp)
4111
{
4112
	struct ieee80211com *ic = wvp->wv_vap.iv_ic;
4113
	struct ieee80211_beacon_offsets *bo = &wvp->wv_boff;
4114
	struct wpi_buf *bcn = &wvp->wv_bcbuf;
4115
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
4116
	struct wpi_cmd_beacon *cmd = (struct wpi_cmd_beacon *)&bcn->data;
4117
	struct ieee80211_tim_ie *tie;
4118
	struct mbuf *m;
4119
	uint8_t *ptr;
4120
	int error;
4121
4122
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4123
4124
	WPI_VAP_LOCK_ASSERT(wvp);
4125
4126
	cmd->len = htole16(bcn->m->m_pkthdr.len);
4127
	cmd->plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ?
4128
	    wpi_ridx_to_plcp[WPI_RIDX_OFDM6] : wpi_ridx_to_plcp[WPI_RIDX_CCK1];
4129
4130
	/* XXX seems to be unused */
4131
	if (*(bo->bo_tim) == IEEE80211_ELEMID_TIM) {
4132
		tie = (struct ieee80211_tim_ie *) bo->bo_tim;
4133
		ptr = mtod(bcn->m, uint8_t *);
4134
4135
		cmd->tim = htole16(bo->bo_tim - ptr);
4136
		cmd->timsz = tie->tim_len;
4137
	}
4138
4139
	/* Necessary for recursion in ieee80211_beacon_update(). */
4140
	m = bcn->m;
4141
	bcn->m = m_dup(m, M_NOWAIT);
4142
	if (bcn->m == NULL) {
4143
		device_printf(sc->sc_dev,
4144
		    "%s: could not copy beacon frame\n", __func__);
4145
		error = ENOMEM;
4146
		goto end;
4147
	}
4148
4149
	if ((error = wpi_cmd2(sc, bcn, 1)) != 0) {
4150
		device_printf(sc->sc_dev,
4151
		    "%s: could not update beacon frame, error %d", __func__,
4152
		    error);
4153
	}
4154
4155
	/* Restore mbuf. */
4156
end:	bcn->m = m;
4157
4158
	return error;
4159
}
4160
4161
static int
3769
wpi_setup_beacon(struct wpi_softc *sc, struct ieee80211_node *ni)
4162
wpi_setup_beacon(struct wpi_softc *sc, struct ieee80211_node *ni)
3770
{
4163
{
3771
	struct ifnet *ifp = sc->sc_ifp;
4164
	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;
4165
	struct wpi_buf *bcn = &wvp->wv_bcbuf;
3776
	struct ieee80211_beacon_offsets bo;
4166
	struct ieee80211_beacon_offsets *bo = &wvp->wv_boff;
3777
	struct wpi_cmd_beacon *cmd;
3778
	struct mbuf *m;
4167
	struct mbuf *m;
3779
	int totlen;
4168
	int error;
3780
4169
3781
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4170
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3782
4171
Lines 3783-3846 Link Here
3783
	if (ni->ni_chan == IEEE80211_CHAN_ANYC)
4172
	if (ni->ni_chan == IEEE80211_CHAN_ANYC)
3784
		return EINVAL;
4173
		return EINVAL;
3785
4174
3786
	m = ieee80211_beacon_alloc(ni, &bo);
4175
	m = ieee80211_beacon_alloc(ni, bo);
3787
	if (m == NULL) {
4176
	if (m == NULL) {
3788
		device_printf(sc->sc_dev,
4177
		device_printf(sc->sc_dev,
3789
		    "%s: could not allocate beacon frame\n", __func__);
4178
		    "%s: could not allocate beacon frame\n", __func__);
3790
		return ENOMEM;
4179
		return ENOMEM;
3791
	}
4180
	}
3792
	totlen = m->m_pkthdr.len;
3793
4181
3794
	if (bcn->data == NULL) {
4182
	WPI_VAP_LOCK(wvp);
3795
		cmd = malloc(sizeof(struct wpi_cmd_beacon), M_DEVBUF,
4183
	if (bcn->m != NULL)
3796
		    M_NOWAIT | M_ZERO);
4184
		m_freem(bcn->m);
3797
4185
3798
		if (cmd == NULL) {
4186
	bcn->m = m;
4187
4188
	error = wpi_config_beacon(wvp);
4189
	WPI_VAP_UNLOCK(wvp);
4190
4191
	return error;
4192
}
4193
4194
static void
4195
wpi_update_beacon(struct ieee80211vap *vap, int item)
4196
{
4197
	struct wpi_softc *sc = vap->iv_ic->ic_ifp->if_softc;
4198
	struct wpi_vap *wvp = WPI_VAP(vap);
4199
	struct wpi_buf *bcn = &wvp->wv_bcbuf;
4200
	struct ieee80211_beacon_offsets *bo = &wvp->wv_boff;
4201
	struct ieee80211_node *ni = vap->iv_bss;
4202
	int mcast = 0;
4203
4204
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
4205
4206
	WPI_VAP_LOCK(wvp);
4207
	if (bcn->m == NULL) {
4208
		bcn->m = ieee80211_beacon_alloc(ni, bo);
4209
		if (bcn->m == NULL) {
3799
			device_printf(sc->sc_dev,
4210
			device_printf(sc->sc_dev,
3800
			    "could not allocate buffer for beacon command\n");
4211
			    "%s: could not allocate beacon frame\n", __func__);
3801
			m_freem(m);
4212
			WPI_VAP_UNLOCK(wvp);
3802
			return ENOMEM;
4213
4214
			DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR,
4215
			    __func__);
4216
4217
			return;
3803
		}
4218
		}
4219
	}
4220
	WPI_VAP_UNLOCK(wvp);
3804
4221
3805
		cmd->id = WPI_ID_BROADCAST;
4222
	if (item == IEEE80211_BEACON_TIM)
3806
		cmd->ofdm_mask = 0xff;
4223
		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
4224
3811
		bcn->data = cmd;
4225
	setbit(bo->bo_flags, item);
3812
		bcn->ni = NULL;
4226
	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
4227
3819
	cmd->len = htole16(totlen);
4228
	WPI_VAP_LOCK(wvp);
3820
	cmd->plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ?
4229
	wpi_config_beacon(wvp);
3821
	    wpi_ridx_to_plcp[WPI_RIDX_OFDM6] : wpi_ridx_to_plcp[WPI_RIDX_CCK1];
4230
	WPI_VAP_UNLOCK(wvp);
3822
4231
3823
	/* NB: m will be freed in wpi_cmd_done() */
4232
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3824
	bcn->m = m;
3825
3826
	return wpi_cmd2(sc, bcn);
3827
}
4233
}
3828
4234
3829
static void
4235
static void
3830
wpi_update_beacon(struct ieee80211vap *vap, int item)
4236
wpi_newassoc(struct ieee80211_node *ni, int isnew)
3831
{
4237
{
3832
	struct ieee80211_node *ni = vap->iv_bss;
4238
	struct ieee80211vap *vap = ni->ni_vap;
3833
	struct ifnet *ifp = vap->iv_ifp;
4239
	struct wpi_softc *sc = ni->ni_ic->ic_ifp->if_softc;
3834
	struct wpi_softc *sc = ifp->if_softc;
4240
	struct wpi_node *wn = WPI_NODE(ni);
3835
	int error;
4241
	int error;
3836
4242
3837
	WPI_LOCK(sc);
4243
	WPI_NT_LOCK(sc);
3838
	if ((error = wpi_setup_beacon(sc, ni)) != 0) {
4244
3839
		device_printf(sc->sc_dev,
4245
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3840
		    "%s: could not update beacon frame, error %d", __func__,
4246
3841
		    error);
4247
	if (vap->iv_opmode != IEEE80211_M_STA && wn->id == WPI_ID_UNDEFINED) {
4248
		if ((error = wpi_add_ibss_node(sc, ni)) != 0) {
4249
			device_printf(sc->sc_dev,
4250
			    "%s: could not add IBSS node, error %d\n",
4251
			    __func__, error);
4252
		}
3842
	}
4253
	}
3843
	WPI_UNLOCK(sc);
4254
	WPI_NT_UNLOCK(sc);
3844
}
4255
}
3845
4256
3846
static int
4257
static int
Lines 3872-3877 Link Here
3872
	}
4283
	}
3873
4284
3874
	/* Update adapter configuration. */
4285
	/* Update adapter configuration. */
4286
	WPI_RXON_LOCK(sc);
3875
	IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid);
4287
	IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid);
3876
	sc->rxon.associd = htole16(IEEE80211_NODE_AID(ni));
4288
	sc->rxon.associd = htole16(IEEE80211_NODE_AID(ni));
3877
	sc->rxon.chan = ieee80211_chan2ieee(ic, ni->ni_chan);
4289
	sc->rxon.chan = ieee80211_chan2ieee(ic, ni->ni_chan);
Lines 3897-3904 Link Here
3897
	}
4309
	}
3898
	sc->rxon.filter |= htole32(WPI_FILTER_BSS);
4310
	sc->rxon.filter |= htole32(WPI_FILTER_BSS);
3899
4311
3900
	/* XXX put somewhere HC_QOS_SUPPORT_ASSOC + HC_IBSS_START */
3901
3902
	DPRINTF(sc, WPI_DEBUG_STATE, "rxon chan %d flags %x\n",
4312
	DPRINTF(sc, WPI_DEBUG_STATE, "rxon chan %d flags %x\n",
3903
	    sc->rxon.chan, sc->rxon.flags);
4313
	    sc->rxon.chan, sc->rxon.flags);
3904
4314
Lines 3908-3914 Link Here
3908
		return error;
4318
		return error;
3909
	}
4319
	}
3910
4320
3911
	if (vap->iv_opmode == IEEE80211_M_IBSS) {
4321
	/* Start periodic calibration timer. */
4322
	callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc);
4323
4324
	WPI_RXON_UNLOCK(sc);
4325
4326
	if (vap->iv_opmode == IEEE80211_M_IBSS ||
4327
	    vap->iv_opmode == IEEE80211_M_HOSTAP) {
3912
		if ((error = wpi_setup_beacon(sc, ni)) != 0) {
4328
		if ((error = wpi_setup_beacon(sc, ni)) != 0) {
3913
			device_printf(sc->sc_dev,
4329
			device_printf(sc->sc_dev,
3914
			    "%s: could not setup beacon, error %d\n", __func__,
4330
			    "%s: could not setup beacon, error %d\n", __func__,
Lines 3919-3926 Link Here
3919
4335
3920
	if (vap->iv_opmode == IEEE80211_M_STA) {
4336
	if (vap->iv_opmode == IEEE80211_M_STA) {
3921
		/* Add BSS node. */
4337
		/* Add BSS node. */
3922
		((struct wpi_node *)ni)->id = WPI_ID_BSS;
4338
		WPI_NT_LOCK(sc);
3923
		if ((error = wpi_add_node(sc, ni)) != 0) {
4339
		error = wpi_add_sta_node(sc, ni);
4340
		WPI_NT_UNLOCK(sc);
4341
		if (error != 0) {
3924
			device_printf(sc->sc_dev,
4342
			device_printf(sc->sc_dev,
3925
			    "%s: could not add BSS node, error %d\n", __func__,
4343
			    "%s: could not add BSS node, error %d\n", __func__,
3926
			    error);
4344
			    error);
Lines 3931-3941 Link Here
3931
	/* Link LED always on while associated. */
4349
	/* Link LED always on while associated. */
3932
	wpi_set_led(sc, WPI_LED_LINK, 0, 1);
4350
	wpi_set_led(sc, WPI_LED_LINK, 0, 1);
3933
4351
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. */
4352
	/* Enable power-saving mode if requested by user. */
3938
	if (vap->iv_flags & IEEE80211_F_PMGTON)
4353
	if ((vap->iv_flags & IEEE80211_F_PMGTON) &&
4354
	    vap->iv_opmode != IEEE80211_M_IBSS)
3939
		(void)wpi_set_pslevel(sc, 0, 3, 1);
4355
		(void)wpi_set_pslevel(sc, 0, 3, 1);
3940
	else
4356
	else
3941
		(void)wpi_set_pslevel(sc, 0, 0, 1);
4357
		(void)wpi_set_pslevel(sc, 0, 0, 1);
Lines 3946-3984 Link Here
3946
}
4362
}
3947
4363
3948
static int
4364
static int
3949
wpi_key_alloc(struct ieee80211vap *vap, struct ieee80211_key *k,
4365
wpi_load_key(struct ieee80211_node *ni, const struct ieee80211_key *k)
3950
    ieee80211_keyix *keyix, ieee80211_keyix *rxkeyix)
3951
{
4366
{
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;
4367
	const struct ieee80211_cipher *cip = k->wk_cipher;
3978
	struct ieee80211com *ic = vap->iv_ic;
4368
	struct ieee80211vap *vap = ni->ni_vap;
3979
	struct ieee80211_node *ni = vap->iv_bss;
4369
	struct wpi_softc *sc = ni->ni_ic->ic_ifp->if_softc;
3980
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
4370
	struct wpi_node *wn = WPI_NODE(ni);
3981
	struct wpi_node *wn = (void *)ni;
3982
	struct wpi_node_info node;
4371
	struct wpi_node_info node;
3983
	uint16_t kflags;
4372
	uint16_t kflags;
3984
	int error;
4373
	int error;
Lines 3985-4005 Link Here
3985
4374
3986
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4375
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3987
4376
4377
	if (wpi_check_node_entry(sc, wn->id) == 0) {
4378
		device_printf(sc->sc_dev, "%s: node does not exist\n",
4379
		    __func__);
4380
		return 0;
4381
	}
4382
3988
	switch (cip->ic_cipher) {
4383
	switch (cip->ic_cipher) {
3989
	case IEEE80211_CIPHER_AES_CCM:
4384
	case IEEE80211_CIPHER_AES_CCM:
3990
		if (k->wk_flags & IEEE80211_KEY_GROUP)
3991
			return 1;
3992
3993
		kflags = WPI_KFLAG_CCMP;
4385
		kflags = WPI_KFLAG_CCMP;
3994
		break;
4386
		break;
4387
3995
	default:
4388
	default:
3996
		/* null_key_set() */
4389
		device_printf(sc->sc_dev, "%s: unknown cipher %d\n", __func__,
3997
		return 1;
4390
		    cip->ic_cipher);
4391
		return 0;
3998
	}
4392
	}
3999
4393
4000
	if (wn->id == WPI_ID_UNDEFINED)
4001
		return 0;
4002
4003
	kflags |= WPI_KFLAG_KID(k->wk_keyix);
4394
	kflags |= WPI_KFLAG_KID(k->wk_keyix);
4004
	if (k->wk_flags & IEEE80211_KEY_GROUP)
4395
	if (k->wk_flags & IEEE80211_KEY_GROUP)
4005
		kflags |= WPI_KFLAG_MULTICAST;
4396
		kflags |= WPI_KFLAG_MULTICAST;
Lines 4010-4064 Link Here
4010
	node.flags = WPI_FLAG_KEY_SET;
4401
	node.flags = WPI_FLAG_KEY_SET;
4011
	node.kflags = htole16(kflags);
4402
	node.kflags = htole16(kflags);
4012
	memcpy(node.key, k->wk_key, k->wk_keylen);
4403
	memcpy(node.key, k->wk_key, k->wk_keylen);
4404
again:
4405
	DPRINTF(sc, WPI_DEBUG_KEY,
4406
	    "%s: setting %s key id %d for node %d (%s)\n", __func__,
4407
	    (kflags & WPI_KFLAG_MULTICAST) ? "group" : "ucast", k->wk_keyix,
4408
	    node.id, ether_sprintf(ni->ni_macaddr));
4013
4409
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);
4410
	error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
4018
	if (error != 0) {
4411
	if (error != 0) {
4019
		device_printf(sc->sc_dev, "can't update node info, error %d\n",
4412
		device_printf(sc->sc_dev, "can't update node info, error %d\n",
4020
		    error);
4413
		    error);
4021
		return 0;
4414
		return !error;
4022
	}
4415
	}
4023
4416
4417
	if (!(kflags & WPI_KFLAG_MULTICAST) && &vap->iv_nw_keys[0] <= k &&
4418
	    k < &vap->iv_nw_keys[IEEE80211_WEP_NKID]) {
4419
		kflags |= WPI_KFLAG_MULTICAST;
4420
		node.kflags = htole16(kflags);
4421
4422
		goto again;
4423
	}
4424
4024
	return 1;
4425
	return 1;
4025
}
4426
}
4026
4427
4428
static void
4429
wpi_load_key_cb(void *arg, struct ieee80211_node *ni)
4430
{
4431
	const struct ieee80211_key *k = arg;
4432
	struct ieee80211vap *vap = ni->ni_vap;
4433
	struct wpi_softc *sc = ni->ni_ic->ic_ifp->if_softc;
4434
	struct wpi_node *wn = WPI_NODE(ni);
4435
	int error;
4436
4437
	if (vap->iv_bss == ni && wn->id == WPI_ID_UNDEFINED)
4438
		return;
4439
4440
	WPI_NT_LOCK(sc);
4441
	error = wpi_load_key(ni, k);
4442
	WPI_NT_UNLOCK(sc);
4443
4444
	if (error == 0) {
4445
		device_printf(sc->sc_dev, "%s: error while setting key\n",
4446
		    __func__);
4447
	}
4448
}
4449
4027
static int
4450
static int
4028
wpi_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k)
4451
wpi_set_global_keys(struct ieee80211_node *ni)
4029
{
4452
{
4030
	const struct ieee80211_cipher *cip = k->wk_cipher;
4453
	struct ieee80211vap *vap = ni->ni_vap;
4031
	struct ieee80211com *ic = vap->iv_ic;
4454
	struct ieee80211_key *wk = &vap->iv_nw_keys[0];
4032
	struct ieee80211_node *ni = vap->iv_bss;
4455
	int error = 1;
4033
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
4456
4034
	struct wpi_node *wn = (void *)ni;
4457
	for (; wk < &vap->iv_nw_keys[IEEE80211_WEP_NKID] && error; wk++)
4458
		if (wk->wk_keyix != IEEE80211_KEYIX_NONE)
4459
			error = wpi_load_key(ni, wk);
4460
4461
	return !error;
4462
}
4463
4464
static int
4465
wpi_del_key(struct ieee80211_node *ni, const struct ieee80211_key *k)
4466
{
4467
	struct ieee80211vap *vap = ni->ni_vap;
4468
	struct wpi_softc *sc = ni->ni_ic->ic_ifp->if_softc;
4469
	struct wpi_node *wn = WPI_NODE(ni);
4035
	struct wpi_node_info node;
4470
	struct wpi_node_info node;
4471
	uint16_t kflags;
4472
	int error;
4036
4473
4037
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4474
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4038
4475
4039
	switch (cip->ic_cipher) {
4476
	if (wpi_check_node_entry(sc, wn->id) == 0) {
4040
	case IEEE80211_CIPHER_AES_CCM:
4477
		DPRINTF(sc, WPI_DEBUG_KEY, "%s: node was removed\n", __func__);
4041
		break;
4478
		return 1;	/* Nothing to do. */
4042
	default:
4043
		/* null_key_delete() */
4044
		return 1;
4045
	}
4479
	}
4046
4480
4047
	if (vap->iv_state != IEEE80211_S_RUN ||
4481
	kflags = WPI_KFLAG_KID(k->wk_keyix);
4048
	    (k->wk_flags & IEEE80211_KEY_GROUP))
4482
	if (k->wk_flags & IEEE80211_KEY_GROUP)
4049
		return 1; /* Nothing to do. */
4483
		kflags |= WPI_KFLAG_MULTICAST;
4050
4484
4051
	memset(&node, 0, sizeof node);
4485
	memset(&node, 0, sizeof node);
4052
	node.id = wn->id;
4486
	node.id = wn->id;
4053
	node.control = WPI_NODE_UPDATE;
4487
	node.control = WPI_NODE_UPDATE;
4054
	node.flags = WPI_FLAG_KEY_SET;
4488
	node.flags = WPI_FLAG_KEY_SET;
4489
	node.kflags = htole16(kflags);
4490
again:
4491
	DPRINTF(sc, WPI_DEBUG_KEY, "%s: deleting %s key %d for node %d (%s)\n",
4492
	    __func__, (kflags & WPI_KFLAG_MULTICAST) ? "group" : "ucast",
4493
	    k->wk_keyix, node.id, ether_sprintf(ni->ni_macaddr));
4055
4494
4056
	DPRINTF(sc, WPI_DEBUG_KEY, "delete keys for node %d\n", node.id);
4495
	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);
4496
	if (error != 0) {
4497
		device_printf(sc->sc_dev, "can't update node info, error %d\n",
4498
		    error);
4499
		return !error;
4500
	}
4058
4501
4502
	if (!(kflags & WPI_KFLAG_MULTICAST) && &vap->iv_nw_keys[0] <= k &&
4503
	    k < &vap->iv_nw_keys[IEEE80211_WEP_NKID]) {
4504
		kflags |= WPI_KFLAG_MULTICAST;
4505
		node.kflags = htole16(kflags);
4506
4507
		goto again;
4508
	}
4509
4059
	return 1;
4510
	return 1;
4060
}
4511
}
4061
4512
4513
static void
4514
wpi_del_key_cb(void *arg, struct ieee80211_node *ni)
4515
{
4516
	const struct ieee80211_key *k = arg;
4517
	struct ieee80211vap *vap = ni->ni_vap;
4518
	struct wpi_softc *sc = ni->ni_ic->ic_ifp->if_softc;
4519
	struct wpi_node *wn = WPI_NODE(ni);
4520
	int error;
4521
4522
	if (vap->iv_bss == ni && wn->id == WPI_ID_UNDEFINED)
4523
		return;
4524
4525
	WPI_NT_LOCK(sc);
4526
	error = wpi_del_key(ni, k);
4527
	WPI_NT_UNLOCK(sc);
4528
4529
	if (error == 0) {
4530
		device_printf(sc->sc_dev, "%s: error while deleting key\n",
4531
		    __func__);
4532
	}
4533
}
4534
4535
static int
4536
wpi_process_key(struct ieee80211vap *vap, const struct ieee80211_key *k,
4537
    int set)
4538
{
4539
	struct ieee80211com *ic = vap->iv_ic;
4540
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
4541
	struct wpi_vap *wvp = WPI_VAP(vap);
4542
	struct ieee80211_node *ni;
4543
	int error, ni_ref = 0;
4544
4545
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4546
4547
	if (k->wk_flags & IEEE80211_KEY_SWCRYPT) {
4548
		/* Not for us. */
4549
		return 1;
4550
	}
4551
4552
	if (!(k->wk_flags & IEEE80211_KEY_RECV)) {
4553
		/* XMIT keys are handled in wpi_tx_data(). */
4554
		return 1;
4555
	}
4556
4557
	/* Handle group keys. */
4558
	if (&vap->iv_nw_keys[0] <= k &&
4559
	    k < &vap->iv_nw_keys[IEEE80211_WEP_NKID]) {
4560
		if (set) {
4561
			atomic_set_acq_32(&wvp->wv_gtk,
4562
			    WPI_VAP_KEY(k->wk_keyix));
4563
		} else {
4564
			atomic_clear_acq_32(&wvp->wv_gtk,
4565
			    WPI_VAP_KEY(k->wk_keyix));
4566
		}
4567
4568
		if (vap->iv_state == IEEE80211_S_RUN) {
4569
			ieee80211_iterate_nodes(&ic->ic_sta,
4570
			    set ? wpi_load_key_cb : wpi_del_key_cb, (void *)k);
4571
		}
4572
4573
		return 1;
4574
	}
4575
4576
	switch (vap->iv_opmode) {
4577
	case IEEE80211_M_STA:
4578
		ni = vap->iv_bss;
4579
		break;
4580
4581
	case IEEE80211_M_IBSS:
4582
	case IEEE80211_M_AHDEMO:
4583
	case IEEE80211_M_HOSTAP:
4584
		ni = ieee80211_find_vap_node(&ic->ic_sta, vap, k->wk_macaddr);
4585
		if (ni == NULL)
4586
			return 0;	/* should not happen */
4587
4588
		ni_ref = 1;
4589
		break;
4590
4591
	default:
4592
		device_printf(sc->sc_dev, "%s: unknown opmode %d\n", __func__,
4593
		    vap->iv_opmode);
4594
		return 0;
4595
	}
4596
4597
	WPI_NT_LOCK(sc);
4598
	if (set)
4599
		error = wpi_load_key(ni, k);
4600
	else
4601
		error = wpi_del_key(ni, k);
4602
	WPI_NT_UNLOCK(sc);
4603
4604
	if (ni_ref)
4605
		ieee80211_node_decref(ni);
4606
4607
	return error;
4608
}
4609
4610
static int
4611
wpi_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k,
4612
    const uint8_t mac[IEEE80211_ADDR_LEN])
4613
{
4614
	return wpi_process_key(vap, k, 1);
4615
}
4616
4617
static int
4618
wpi_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k)
4619
{
4620
	return wpi_process_key(vap, k, 0);
4621
}
4622
4062
/*
4623
/*
4063
 * This function is called after the runtime firmware notifies us of its
4624
 * This function is called after the runtime firmware notifies us of its
4064
 * readiness (called in a process context).
4625
 * readiness (called in a process context).
Lines 4093-4103 Link Here
4093
	if (ntries == 1000) {
4654
	if (ntries == 1000) {
4094
		device_printf(sc->sc_dev,
4655
		device_printf(sc->sc_dev,
4095
		    "timeout waiting for thermal sensor calibration\n");
4656
		    "timeout waiting for thermal sensor calibration\n");
4096
                return ETIMEDOUT;
4657
		return ETIMEDOUT;
4097
        }
4658
	}
4098
4659
4099
        DPRINTF(sc, WPI_DEBUG_TEMP, "temperature %d\n", sc->temp);
4660
	DPRINTF(sc, WPI_DEBUG_TEMP, "temperature %d\n", sc->temp);
4100
        return 0;
4661
	return 0;
4101
}
4662
}
4102
4663
4103
/*
4664
/*
Lines 4192-4198 Link Here
4192
	WPI_WRITE(sc, WPI_RESET, 0);
4753
	WPI_WRITE(sc, WPI_RESET, 0);
4193
4754
4194
	/* Wait at most one second for first alive notification. */
4755
	/* Wait at most one second for first alive notification. */
4195
	if ((error = msleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) {
4756
	if ((error = mtx_sleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) {
4196
		device_printf(sc->sc_dev,
4757
		device_printf(sc->sc_dev,
4197
		    "%s: timeout waiting for adapter to initialize, error %d\n",
4758
		    "%s: timeout waiting for adapter to initialize, error %d\n",
4198
		    __func__, error);
4759
		    __func__, error);
Lines 4297-4304 Link Here
4297
4858
4298
	DPRINTF(sc, WPI_DEBUG_FIRMWARE,
4859
	DPRINTF(sc, WPI_DEBUG_FIRMWARE,
4299
	    "Firmware Version: Major %d, Minor %d, Driver %d, \n"
4860
	    "Firmware Version: Major %d, Minor %d, Driver %d, \n"
4300
	    "runtime (text: %u, data: %u) init (text: %u, data %u) boot (text %u)\n",
4861
	    "runtime (text: %u, data: %u) init (text: %u, data %u) "
4301
	    hdr->major, hdr->minor, le32toh(hdr->driver),
4862
	    "boot (text %u)\n", hdr->major, hdr->minor, le32toh(hdr->driver),
4302
	    fw->main.textsz, fw->main.datasz,
4863
	    fw->main.textsz, fw->main.datasz,
4303
	    fw->init.textsz, fw->init.datasz, fw->boot.textsz);
4864
	    fw->init.textsz, fw->init.datasz, fw->boot.textsz);
4304
4865
Lines 4362-4367 Link Here
4362
	/* Set FH wait threshold to max (HW bug under stress workaround). */
4923
	/* Set FH wait threshold to max (HW bug under stress workaround). */
4363
	WPI_SETBITS(sc, WPI_DBG_HPET_MEM, 0xffff0000);
4924
	WPI_SETBITS(sc, WPI_DBG_HPET_MEM, 0xffff0000);
4364
4925
4926
	/* Cleanup. */
4927
	wpi_prph_write(sc, WPI_APMG_CLK_DIS, 0x00000400);
4928
	wpi_prph_clrbits(sc, WPI_APMG_PS, 0x00000E00);
4929
4365
	/* Retrieve PCIe Active State Power Management (ASPM). */
4930
	/* Retrieve PCIe Active State Power Management (ASPM). */
4366
	reg = pci_read_config(sc->sc_dev, sc->sc_cap_off + 0x10, 1);
4931
	reg = pci_read_config(sc->sc_dev, sc->sc_cap_off + 0x10, 1);
4367
	/* Workaround for HW instability in PCIe L0->L0s->L1 transition. */
4932
	/* Workaround for HW instability in PCIe L0->L0s->L1 transition. */
Lines 4384-4391 Link Here
4384
	DELAY(20);
4949
	DELAY(20);
4385
	/* Disable L1-Active. */
4950
	/* Disable L1-Active. */
4386
	wpi_prph_setbits(sc, WPI_APMG_PCI_STT, WPI_APMG_PCI_STT_L1A_DIS);
4951
	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);
4952
	wpi_nic_unlock(sc);
4390
4953
4391
	return 0;
4954
	return 0;
Lines 4408-4414 Link Here
4408
			return;
4971
			return;
4409
		DELAY(10);
4972
		DELAY(10);
4410
	}
4973
	}
4411
	device_printf(sc->sc_dev, "%s: timeout waiting for master\n", __func__);
4974
	device_printf(sc->sc_dev, "%s: timeout waiting for master\n",
4975
	    __func__);
4412
}
4976
}
4413
4977
4414
static void
4978
static void
Lines 4440-4446 Link Here
4440
	if (sc->cap == 0x80)
5004
	if (sc->cap == 0x80)
4441
		WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_SKU_MRC);
5005
		WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_SKU_MRC);
4442
5006
4443
	if ((le16toh(sc->rev) & 0xf0) == 0xd0)
5007
	if ((sc->rev & 0xf0) == 0xd0)
4444
		WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_REV_D);
5008
		WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_REV_D);
4445
	else
5009
	else
4446
		WPI_CLRBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_REV_D);
5010
		WPI_CLRBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_REV_D);
Lines 4551-4557 Link Here
4551
		return error;
5115
		return error;
4552
	}
5116
	}
4553
	/* Wait at most one second for firmware alive notification. */
5117
	/* Wait at most one second for firmware alive notification. */
4554
	if ((error = msleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) {
5118
	if ((error = mtx_sleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) {
4555
		device_printf(sc->sc_dev,
5119
		device_printf(sc->sc_dev,
4556
		    "%s: timeout waiting for adapter to initialize, error %d\n",
5120
		    "%s: timeout waiting for adapter to initialize, error %d\n",
4557
		    __func__, error);
5121
		    __func__, error);
Lines 4655-4672 Link Here
4655
	if (vap != NULL)
5219
	if (vap != NULL)
4656
		ieee80211_stop(vap);
5220
		ieee80211_stop(vap);
4657
5221
5222
	WPI_LOCK(sc);
4658
	callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill, sc);
5223
	callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill, sc);
5224
	WPI_UNLOCK(sc);
4659
}
5225
}
4660
5226
4661
static void
5227
static void
4662
wpi_init_locked(struct wpi_softc *sc)
5228
wpi_init(void *arg)
4663
{
5229
{
5230
	struct wpi_softc *sc = arg;
4664
	struct ifnet *ifp = sc->sc_ifp;
5231
	struct ifnet *ifp = sc->sc_ifp;
5232
	struct ieee80211com *ic = ifp->if_l2com;
4665
	int error;
5233
	int error;
4666
5234
5235
	WPI_LOCK(sc);
5236
4667
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
5237
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
4668
5238
4669
	WPI_LOCK_ASSERT(sc);
5239
	if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
5240
		goto end;
4670
5241
4671
	/* Check that the radio is not disabled by hardware switch. */
5242
	/* Check that the radio is not disabled by hardware switch. */
4672
	if (!(WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_RFKILL)) {
5243
	if (!(WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_RFKILL)) {
Lines 4674-4680 Link Here
4674
		    "RF switch: radio disabled (%s)\n", __func__);
5245
		    "RF switch: radio disabled (%s)\n", __func__);
4675
		callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill,
5246
		callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill,
4676
		    sc);
5247
		    sc);
4677
		return;
5248
		goto end;
4678
	}
5249
	}
4679
5250
4680
	/* Read firmware images from the filesystem. */
5251
	/* Read firmware images from the filesystem. */
Lines 4695-4700 Link Here
4695
		goto fail;
5266
		goto fail;
4696
	}
5267
	}
4697
5268
5269
	atomic_store_rel_32(&sc->txq_active, 1);
5270
4698
	/* Configure adapter now that it is ready. */
5271
	/* Configure adapter now that it is ready. */
4699
	if ((error = wpi_config(sc)) != 0) {
5272
	if ((error = wpi_config(sc)) != 0) {
4700
		device_printf(sc->sc_dev,
5273
		device_printf(sc->sc_dev,
Lines 4703-4734 Link Here
4703
		goto fail;
5276
		goto fail;
4704
	}
5277
	}
4705
5278
5279
	IF_LOCK(&ifp->if_snd);
4706
	ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
5280
	ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
4707
	ifp->if_drv_flags |= IFF_DRV_RUNNING;
5281
	ifp->if_drv_flags |= IFF_DRV_RUNNING;
5282
	IF_UNLOCK(&ifp->if_snd);
4708
5283
4709
	callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
5284
	callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
4710
5285
5286
	WPI_UNLOCK(sc);
5287
5288
	ieee80211_start_all(ic);
5289
4711
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
5290
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
4712
5291
4713
	return;
5292
	return;
4714
5293
4715
fail:	wpi_stop_locked(sc);
5294
fail:	wpi_stop_locked(sc);
4716
	DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
5295
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);
5296
	WPI_UNLOCK(sc);
4729
4730
	if (ifp->if_drv_flags & IFF_DRV_RUNNING)
4731
		ieee80211_start_all(ic);
4732
}
5297
}
4733
5298
4734
static void
5299
static void
Lines 4738-4748 Link Here
4738
5303
4739
	WPI_LOCK_ASSERT(sc);
5304
	WPI_LOCK_ASSERT(sc);
4740
5305
4741
	sc->sc_scan_timer = 0;
5306
	atomic_store_rel_32(&sc->txq_active, 0);
4742
	sc->sc_tx_timer = 0;
5307
	atomic_store_rel_32(&sc->sc_scan_timer, 0);
5308
	atomic_store_rel_32(&sc->sc_tx_timer, 0);
5309
4743
	callout_stop(&sc->watchdog_to);
5310
	callout_stop(&sc->watchdog_to);
5311
5312
	WPI_RXON_LOCK(sc);
4744
	callout_stop(&sc->calib_to);
5313
	callout_stop(&sc->calib_to);
5314
	WPI_RXON_UNLOCK(sc);
5315
5316
	IF_LOCK(&ifp->if_snd);
4745
	ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
5317
	ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
5318
	IF_UNLOCK(&ifp->if_snd);
4746
5319
4747
	/* Power OFF hardware. */
5320
	/* Power OFF hardware. */
4748
	wpi_hw_stop(sc);
5321
	wpi_hw_stop(sc);
Lines 4762-4773 Link Here
4762
static void
5335
static void
4763
wpi_scan_start(struct ieee80211com *ic)
5336
wpi_scan_start(struct ieee80211com *ic)
4764
{
5337
{
4765
	struct ifnet *ifp = ic->ic_ifp;
5338
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
4766
	struct wpi_softc *sc = ifp->if_softc;
4767
5339
4768
	WPI_LOCK(sc);
4769
	wpi_set_led(sc, WPI_LED_LINK, 20, 2);
5340
	wpi_set_led(sc, WPI_LED_LINK, 20, 2);
4770
	WPI_UNLOCK(sc);
4771
}
5341
}
4772
5342
4773
/*
5343
/*
Lines 4780-4790 Link Here
4780
	struct wpi_softc *sc = ifp->if_softc;
5350
	struct wpi_softc *sc = ifp->if_softc;
4781
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
5351
	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
4782
5352
4783
	if (vap->iv_state == IEEE80211_S_RUN) {
5353
	if (vap->iv_state == IEEE80211_S_RUN)
4784
		WPI_LOCK(sc);
4785
		wpi_set_led(sc, WPI_LED_LINK, 0, 1);
5354
		wpi_set_led(sc, WPI_LED_LINK, 0, 1);
4786
		WPI_UNLOCK(sc);
4787
	}
4788
}
5355
}
4789
5356
4790
/**
5357
/**
Lines 4804-4811 Link Here
4804
	WPI_LOCK(sc);
5371
	WPI_LOCK(sc);
4805
	sc->sc_rxtap.wr_chan_freq = htole16(c->ic_freq);
5372
	sc->sc_rxtap.wr_chan_freq = htole16(c->ic_freq);
4806
	sc->sc_rxtap.wr_chan_flags = htole16(c->ic_flags);
5373
	sc->sc_rxtap.wr_chan_flags = htole16(c->ic_flags);
5374
	WPI_UNLOCK(sc);
5375
	WPI_TX_LOCK(sc);
4807
	sc->sc_txtap.wt_chan_freq = htole16(c->ic_freq);
5376
	sc->sc_txtap.wt_chan_freq = htole16(c->ic_freq);
4808
	sc->sc_txtap.wt_chan_flags = htole16(c->ic_flags);
5377
	sc->sc_txtap.wt_chan_flags = htole16(c->ic_flags);
5378
	WPI_TX_UNLOCK(sc);
4809
5379
4810
	/*
5380
	/*
4811
	 * Only need to set the channel in Monitor mode. AP scanning and auth
5381
	 * 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.
5382
	 * are already taken care of by their respective firmware commands.
4813
	 */
5383
	 */
4814
	if (ic->ic_opmode == IEEE80211_M_MONITOR) {
5384
	if (ic->ic_opmode == IEEE80211_M_MONITOR) {
5385
		WPI_RXON_LOCK(sc);
4815
		sc->rxon.chan = ieee80211_chan2ieee(ic, c);
5386
		sc->rxon.chan = ieee80211_chan2ieee(ic, c);
4816
		if (IEEE80211_IS_CHAN_2GHZ(c)) {
5387
		if (IEEE80211_IS_CHAN_2GHZ(c)) {
4817
			sc->rxon.flags |= htole32(WPI_RXON_AUTO |
5388
			sc->rxon.flags |= htole32(WPI_RXON_AUTO |
Lines 4820-4831 Link Here
4820
			sc->rxon.flags &= ~htole32(WPI_RXON_AUTO |
5391
			sc->rxon.flags &= ~htole32(WPI_RXON_AUTO |
4821
			    WPI_RXON_24GHZ);
5392
			    WPI_RXON_24GHZ);
4822
		}
5393
		}
4823
		if ((error = wpi_send_rxon(sc, 0, 0)) != 0)
5394
		if ((error = wpi_send_rxon(sc, 0, 1)) != 0)
4824
			device_printf(sc->sc_dev,
5395
			device_printf(sc->sc_dev,
4825
			    "%s: error %d settting channel\n", __func__,
5396
			    "%s: error %d setting channel\n", __func__,
4826
			    error);
5397
			    error);
5398
		WPI_RXON_UNLOCK(sc);
4827
	}
5399
	}
4828
	WPI_UNLOCK(sc);
4829
}
5400
}
4830
5401
4831
/**
5402
/**
Lines 4838-4852 Link Here
4838
{
5409
{
4839
	struct ieee80211vap *vap = ss->ss_vap;
5410
	struct ieee80211vap *vap = ss->ss_vap;
4840
	struct ieee80211com *ic = vap->iv_ic;
5411
	struct ieee80211com *ic = vap->iv_ic;
4841
	struct ifnet *ifp = ic->ic_ifp;
5412
	struct wpi_softc *sc = ic->ic_ifp->if_softc;
4842
	struct wpi_softc *sc = ifp->if_softc;
5413
	uint8_t curchan;
4843
	int error;
4844
5414
4845
	if (sc->rxon.chan != ieee80211_chan2ieee(ic, ic->ic_curchan)) {
5415
	WPI_RXON_LOCK(sc);
4846
		WPI_LOCK(sc);
5416
	curchan = sc->rxon.chan;
4847
		error = wpi_scan(sc, ic->ic_curchan);
5417
	WPI_RXON_UNLOCK(sc);
4848
		WPI_UNLOCK(sc);
5418
4849
		if (error != 0)
5419
	if (curchan != ieee80211_chan2ieee(ic, ic->ic_curchan)) {
5420
		if (wpi_scan(sc, ic->ic_curchan) != 0)
4850
			ieee80211_cancel_scan(vap);
5421
			ieee80211_cancel_scan(vap);
4851
	} else {
5422
	} else {
4852
		/* Send probe request when associated. */
5423
		/* 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