Deleted Added
full compact
if_ural.c (191710) if_ural.c (191746)
1/* $FreeBSD: head/sys/dev/usb/wlan/if_ural.c 191710 2009-04-30 22:30:01Z thompsa $ */
1/* $FreeBSD: head/sys/dev/usb/wlan/if_ural.c 191746 2009-05-02 15:14:18Z thompsa $ */
2
3/*-
4 * Copyright (c) 2005, 2006
5 * Damien Bergamini <damien.bergamini@free.fr>
6 *
7 * Copyright (c) 2006, 2008
8 * Hans Petter Selasky <hselasky@FreeBSD.org>
9 *

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

16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#include <sys/cdefs.h>
2
3/*-
4 * Copyright (c) 2005, 2006
5 * Damien Bergamini <damien.bergamini@free.fr>
6 *
7 * Copyright (c) 2006, 2008
8 * Hans Petter Selasky <hselasky@FreeBSD.org>
9 *

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

16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#include <sys/cdefs.h>
24__FBSDID("$FreeBSD: head/sys/dev/usb/wlan/if_ural.c 191710 2009-04-30 22:30:01Z thompsa $");
24__FBSDID("$FreeBSD: head/sys/dev/usb/wlan/if_ural.c 191746 2009-05-02 15:14:18Z thompsa $");
25
26/*-
27 * Ralink Technology RT2500USB chipset driver
28 * http://www.ralinktech.com/
29 */
30
25
26/*-
27 * Ralink Technology RT2500USB chipset driver
28 * http://www.ralinktech.com/
29 */
30
31#include "usbdevs.h"
32#include <dev/usb/usb.h>
33#include <dev/usb/usb_mfunc.h>
34#include <dev/usb/usb_error.h>
31#include <sys/param.h>
32#include <sys/sockio.h>
33#include <sys/sysctl.h>
34#include <sys/lock.h>
35#include <sys/mutex.h>
36#include <sys/mbuf.h>
37#include <sys/kernel.h>
38#include <sys/socket.h>
39#include <sys/systm.h>
40#include <sys/malloc.h>
41#include <sys/module.h>
42#include <sys/bus.h>
43#include <sys/endian.h>
44#include <sys/kdb.h>
35
45
46#include <machine/bus.h>
47#include <machine/resource.h>
48#include <sys/rman.h>
49
50#include <net/bpf.h>
51#include <net/if.h>
52#include <net/if_arp.h>
53#include <net/ethernet.h>
54#include <net/if_dl.h>
55#include <net/if_media.h>
56#include <net/if_types.h>
57
58#ifdef INET
59#include <netinet/in.h>
60#include <netinet/in_systm.h>
61#include <netinet/in_var.h>
62#include <netinet/if_ether.h>
63#include <netinet/ip.h>
64#endif
65
66#include <net80211/ieee80211_var.h>
67#include <net80211/ieee80211_regdomain.h>
68#include <net80211/ieee80211_radiotap.h>
69#include <net80211/ieee80211_amrr.h>
70
36#define USB_DEBUG_VAR ural_debug
37
71#define USB_DEBUG_VAR ural_debug
72
73#include <dev/usb/usb.h>
74#include <dev/usb/usb_error.h>
38#include <dev/usb/usb_core.h>
39#include <dev/usb/usb_lookup.h>
75#include <dev/usb/usb_core.h>
76#include <dev/usb/usb_lookup.h>
40#include <dev/usb/usb_process.h>
41#include <dev/usb/usb_debug.h>
42#include <dev/usb/usb_request.h>
43#include <dev/usb/usb_busdma.h>
44#include <dev/usb/usb_util.h>
77#include <dev/usb/usb_debug.h>
78#include <dev/usb/usb_request.h>
79#include <dev/usb/usb_busdma.h>
80#include <dev/usb/usb_util.h>
81#include "usbdevs.h"
45
82
46#include <dev/usb/wlan/usb_wlan.h>
83
47#include <dev/usb/wlan/if_uralreg.h>
48#include <dev/usb/wlan/if_uralvar.h>
49
50#if USB_DEBUG
51static int ural_debug = 0;
52
53SYSCTL_NODE(_hw_usb2, OID_AUTO, ural, CTLFLAG_RW, 0, "USB ural");
54SYSCTL_INT(_hw_usb2_ural, OID_AUTO, debug, CTLFLAG_RW, &ural_debug, 0,

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

90 { USB_VP(USB_VENDOR_SURECOM, USB_PRODUCT_SURECOM_RT2570) },
91 { USB_VP(USB_VENDOR_VTECH, USB_PRODUCT_VTECH_RT2570) },
92 { USB_VP(USB_VENDOR_ZINWELL, USB_PRODUCT_ZINWELL_RT2570) },
93};
94
95static usb2_callback_t ural_bulk_read_callback;
96static usb2_callback_t ural_bulk_write_callback;
97
84#include <dev/usb/wlan/if_uralreg.h>
85#include <dev/usb/wlan/if_uralvar.h>
86
87#if USB_DEBUG
88static int ural_debug = 0;
89
90SYSCTL_NODE(_hw_usb2, OID_AUTO, ural, CTLFLAG_RW, 0, "USB ural");
91SYSCTL_INT(_hw_usb2_ural, OID_AUTO, debug, CTLFLAG_RW, &ural_debug, 0,

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

127 { USB_VP(USB_VENDOR_SURECOM, USB_PRODUCT_SURECOM_RT2570) },
128 { USB_VP(USB_VENDOR_VTECH, USB_PRODUCT_VTECH_RT2570) },
129 { USB_VP(USB_VENDOR_ZINWELL, USB_PRODUCT_ZINWELL_RT2570) },
130};
131
132static usb2_callback_t ural_bulk_read_callback;
133static usb2_callback_t ural_bulk_write_callback;
134
98static usb2_proc_callback_t ural_command_wrapper;
99static usb2_proc_callback_t ural_attach_post;
100static usb2_proc_callback_t ural_task;
101static usb2_proc_callback_t ural_scantask;
102static usb2_proc_callback_t ural_promisctask;
103static usb2_proc_callback_t ural_amrr_task;
104static usb2_proc_callback_t ural_init_task;
105static usb2_proc_callback_t ural_stop_task;
106static usb2_proc_callback_t ural_flush_task;
107
108static usb2_error_t ural_do_request(struct ural_softc *sc,
109 struct usb2_device_request *req, void *data);
110static struct ieee80211vap *ural_vap_create(struct ieee80211com *,
111 const char name[IFNAMSIZ], int unit, int opmode,
112 int flags, const uint8_t bssid[IEEE80211_ADDR_LEN],
113 const uint8_t mac[IEEE80211_ADDR_LEN]);
114static void ural_vap_delete(struct ieee80211vap *);
115static void ural_tx_free(struct ural_tx_data *, int);

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

151static void ural_enable_tsf_sync(struct ural_softc *);
152static void ural_update_slot(struct ifnet *);
153static void ural_set_txpreamble(struct ural_softc *);
154static void ural_set_basicrates(struct ural_softc *,
155 const struct ieee80211_channel *);
156static void ural_set_bssid(struct ural_softc *, const uint8_t *);
157static void ural_set_macaddr(struct ural_softc *, uint8_t *);
158static void ural_update_promisc(struct ifnet *);
135static usb2_error_t ural_do_request(struct ural_softc *sc,
136 struct usb2_device_request *req, void *data);
137static struct ieee80211vap *ural_vap_create(struct ieee80211com *,
138 const char name[IFNAMSIZ], int unit, int opmode,
139 int flags, const uint8_t bssid[IEEE80211_ADDR_LEN],
140 const uint8_t mac[IEEE80211_ADDR_LEN]);
141static void ural_vap_delete(struct ieee80211vap *);
142static void ural_tx_free(struct ural_tx_data *, int);

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

178static void ural_enable_tsf_sync(struct ural_softc *);
179static void ural_update_slot(struct ifnet *);
180static void ural_set_txpreamble(struct ural_softc *);
181static void ural_set_basicrates(struct ural_softc *,
182 const struct ieee80211_channel *);
183static void ural_set_bssid(struct ural_softc *, const uint8_t *);
184static void ural_set_macaddr(struct ural_softc *, uint8_t *);
185static void ural_update_promisc(struct ifnet *);
186static void ural_setpromisc(struct ural_softc *);
159static const char *ural_get_rf(int);
160static void ural_read_eeprom(struct ural_softc *);
161static int ural_bbp_init(struct ural_softc *);
162static void ural_set_txantenna(struct ural_softc *, int);
163static void ural_set_rxantenna(struct ural_softc *, int);
187static const char *ural_get_rf(int);
188static void ural_read_eeprom(struct ural_softc *);
189static int ural_bbp_init(struct ural_softc *);
190static void ural_set_txantenna(struct ural_softc *, int);
191static void ural_set_rxantenna(struct ural_softc *, int);
192static void ural_init_locked(struct ural_softc *);
164static void ural_init(void *);
193static void ural_init(void *);
194static void ural_stop(struct ural_softc *);
165static int ural_raw_xmit(struct ieee80211_node *, struct mbuf *,
166 const struct ieee80211_bpf_params *);
167static void ural_amrr_start(struct ural_softc *,
168 struct ieee80211_node *);
169static void ural_amrr_timeout(void *);
195static int ural_raw_xmit(struct ieee80211_node *, struct mbuf *,
196 const struct ieee80211_bpf_params *);
197static void ural_amrr_start(struct ural_softc *,
198 struct ieee80211_node *);
199static void ural_amrr_timeout(void *);
200static void ural_amrr_task(void *, int);
170static int ural_pause(struct ural_softc *sc, int timeout);
201static int ural_pause(struct ural_softc *sc, int timeout);
171static void ural_queue_command(struct ural_softc *,
172 usb2_proc_callback_t *, struct usb2_proc_msg *,
173 struct usb2_proc_msg *);
174
175/*
176 * Default values for MAC registers; values taken from the reference driver.
177 */
178static const struct {
179 uint16_t reg;
180 uint16_t val;
181} ural_def_mac[] = {

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

395 return (usb2_lookup_id_by_uaa(ural_devs, sizeof(ural_devs), uaa));
396}
397
398static int
399ural_attach(device_t self)
400{
401 struct usb2_attach_arg *uaa = device_get_ivars(self);
402 struct ural_softc *sc = device_get_softc(self);
202
203/*
204 * Default values for MAC registers; values taken from the reference driver.
205 */
206static const struct {
207 uint16_t reg;
208 uint16_t val;
209} ural_def_mac[] = {

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

423 return (usb2_lookup_id_by_uaa(ural_devs, sizeof(ural_devs), uaa));
424}
425
426static int
427ural_attach(device_t self)
428{
429 struct usb2_attach_arg *uaa = device_get_ivars(self);
430 struct ural_softc *sc = device_get_softc(self);
431 struct ifnet *ifp;
432 struct ieee80211com *ic;
433 uint8_t iface_index, bands;
403 int error;
434 int error;
404 uint8_t iface_index;
405
406 device_set_usb2_desc(self);
407 sc->sc_udev = uaa->device;
408 sc->sc_dev = self;
409
410 mtx_init(&sc->sc_mtx, device_get_nameunit(self),
411 MTX_NETWORK_LOCK, MTX_DEF);
412
435
436 device_set_usb2_desc(self);
437 sc->sc_udev = uaa->device;
438 sc->sc_dev = self;
439
440 mtx_init(&sc->sc_mtx, device_get_nameunit(self),
441 MTX_NETWORK_LOCK, MTX_DEF);
442
413 cv_init(&sc->sc_cmd_cv, "wtxdone");
414
415 iface_index = RAL_IFACE_INDEX;
416 error = usb2_transfer_setup(uaa->device,
417 &iface_index, sc->sc_xfer, ural_config,
418 URAL_N_TRANSFER, sc, &sc->sc_mtx);
419 if (error) {
420 device_printf(self, "could not allocate USB transfers, "
421 "err=%s\n", usb2_errstr(error));
422 goto detach;
423 }
443 iface_index = RAL_IFACE_INDEX;
444 error = usb2_transfer_setup(uaa->device,
445 &iface_index, sc->sc_xfer, ural_config,
446 URAL_N_TRANSFER, sc, &sc->sc_mtx);
447 if (error) {
448 device_printf(self, "could not allocate USB transfers, "
449 "err=%s\n", usb2_errstr(error));
450 goto detach;
451 }
424 error = usb2_proc_create(&sc->sc_tq, &sc->sc_mtx,
425 device_get_nameunit(self), USB_PRI_MED);
426 if (error) {
427 device_printf(self, "could not setup config thread!\n");
428 goto detach;
429 }
430
452
431 /* fork rest of the attach code */
432 RAL_LOCK(sc);
453 RAL_LOCK(sc);
433 ural_queue_command(sc, ural_attach_post,
434 &sc->sc_synctask[0].hdr,
435 &sc->sc_synctask[1].hdr);
436 RAL_UNLOCK(sc);
437 return (0);
438
439detach:
440 ural_detach(self);
441 return (ENXIO); /* failure */
442}
443
444static void
445ural_attach_post(struct usb2_proc_msg *pm)
446{
447 struct ural_task *task = (struct ural_task *)pm;
448 struct ural_softc *sc = task->sc;
449 struct ifnet *ifp;
450 struct ieee80211com *ic;
451 uint8_t bands;
452
453 /* retrieve RT2570 rev. no */
454 sc->asic_rev = ural_read(sc, RAL_MAC_CSR0);
455
456 /* retrieve MAC address and various other things from EEPROM */
457 ural_read_eeprom(sc);
454 /* retrieve RT2570 rev. no */
455 sc->asic_rev = ural_read(sc, RAL_MAC_CSR0);
456
457 /* retrieve MAC address and various other things from EEPROM */
458 ural_read_eeprom(sc);
458
459 /* XXX Async attach race */
460 if (usb2_proc_is_gone(&sc->sc_tq))
461 return;
462
463 RAL_UNLOCK(sc);
464
459 RAL_UNLOCK(sc);
460
465 device_printf(sc->sc_dev, "MAC/BBP RT2570 (rev 0x%02x), RF %s\n",
461 device_printf(self, "MAC/BBP RT2570 (rev 0x%02x), RF %s\n",
466 sc->asic_rev, ural_get_rf(sc->rf_rev));
467
468 ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211);
469 if (ifp == NULL) {
470 device_printf(sc->sc_dev, "can not if_alloc()\n");
462 sc->asic_rev, ural_get_rf(sc->rf_rev));
463
464 ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211);
465 if (ifp == NULL) {
466 device_printf(sc->sc_dev, "can not if_alloc()\n");
471 RAL_LOCK(sc);
472 return;
467 goto detach;
473 }
474 ic = ifp->if_l2com;
475
476 ifp->if_softc = sc;
477 if_initname(ifp, "ural", device_get_unit(sc->sc_dev));
478 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
479 ifp->if_init = ural_init;
480 ifp->if_ioctl = ural_ioctl;

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

527
528 sc->sc_txtap_len = sizeof sc->sc_txtap;
529 sc->sc_txtap.wt_ihdr.it_len = htole16(sc->sc_txtap_len);
530 sc->sc_txtap.wt_ihdr.it_present = htole32(RAL_TX_RADIOTAP_PRESENT);
531
532 if (bootverbose)
533 ieee80211_announce(ic);
534
468 }
469 ic = ifp->if_l2com;
470
471 ifp->if_softc = sc;
472 if_initname(ifp, "ural", device_get_unit(sc->sc_dev));
473 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
474 ifp->if_init = ural_init;
475 ifp->if_ioctl = ural_ioctl;

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

522
523 sc->sc_txtap_len = sizeof sc->sc_txtap;
524 sc->sc_txtap.wt_ihdr.it_len = htole16(sc->sc_txtap_len);
525 sc->sc_txtap.wt_ihdr.it_present = htole32(RAL_TX_RADIOTAP_PRESENT);
526
527 if (bootverbose)
528 ieee80211_announce(ic);
529
535 RAL_LOCK(sc);
530 return (0);
531
532detach:
533 ural_detach(self);
534 return (ENXIO); /* failure */
536}
537
538static int
539ural_detach(device_t self)
540{
541 struct ural_softc *sc = device_get_softc(self);
542 struct ifnet *ifp = sc->sc_ifp;
543 struct ieee80211com *ic;
544
535}
536
537static int
538ural_detach(device_t self)
539{
540 struct ural_softc *sc = device_get_softc(self);
541 struct ifnet *ifp = sc->sc_ifp;
542 struct ieee80211com *ic;
543
545 /* wait for any post attach or other command to complete */
546 usb2_proc_drain(&sc->sc_tq);
547
548 /* stop all USB transfers */
549 usb2_transfer_unsetup(sc->sc_xfer, URAL_N_TRANSFER);
544 /* stop all USB transfers */
545 usb2_transfer_unsetup(sc->sc_xfer, URAL_N_TRANSFER);
550 usb2_proc_free(&sc->sc_tq);
551
552 /* free TX list, if any */
553 RAL_LOCK(sc);
554 ural_unsetup_tx_list(sc);
555 RAL_UNLOCK(sc);
556
557 if (ifp) {
558 ic = ifp->if_l2com;
559 bpfdetach(ifp);
560 ieee80211_ifdetach(ic);
561 if_free(ifp);
562 }
546
547 /* free TX list, if any */
548 RAL_LOCK(sc);
549 ural_unsetup_tx_list(sc);
550 RAL_UNLOCK(sc);
551
552 if (ifp) {
553 ic = ifp->if_l2com;
554 bpfdetach(ifp);
555 ieee80211_ifdetach(ic);
556 if_free(ifp);
557 }
563 cv_destroy(&sc->sc_cmd_cv);
564 mtx_destroy(&sc->sc_mtx);
565
566 return (0);
567}
568
569static usb2_error_t
570ural_do_request(struct ural_softc *sc,
571 struct usb2_device_request *req, void *data)
572{
573 usb2_error_t err;
574 int ntries = 10;
575
576 while (ntries--) {
558 mtx_destroy(&sc->sc_mtx);
559
560 return (0);
561}
562
563static usb2_error_t
564ural_do_request(struct ural_softc *sc,
565 struct usb2_device_request *req, void *data)
566{
567 usb2_error_t err;
568 int ntries = 10;
569
570 while (ntries--) {
577 err = usb2_do_request_proc(sc->sc_udev, &sc->sc_tq,
571 err = usb2_do_request_flags(sc->sc_udev, &sc->sc_mtx,
578 req, data, 0, NULL, 250 /* ms */);
579 if (err == 0)
580 break;
581
582 DPRINTFN(1, "Control request failed, %s (retrying)\n",
583 usb2_errstr(err));
584 if (ural_pause(sc, hz / 100))
585 break;

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

607 /* enable s/w bmiss handling for sta mode */
608 ieee80211_vap_setup(ic, vap, name, unit, opmode,
609 flags | IEEE80211_CLONE_NOBEACONS, bssid, mac);
610
611 /* override state transition machine */
612 uvp->newstate = vap->iv_newstate;
613 vap->iv_newstate = ural_newstate;
614
572 req, data, 0, NULL, 250 /* ms */);
573 if (err == 0)
574 break;
575
576 DPRINTFN(1, "Control request failed, %s (retrying)\n",
577 usb2_errstr(err));
578 if (ural_pause(sc, hz / 100))
579 break;

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

601 /* enable s/w bmiss handling for sta mode */
602 ieee80211_vap_setup(ic, vap, name, unit, opmode,
603 flags | IEEE80211_CLONE_NOBEACONS, bssid, mac);
604
605 /* override state transition machine */
606 uvp->newstate = vap->iv_newstate;
607 vap->iv_newstate = ural_newstate;
608
615 uvp->sc = sc;
616 usb2_callout_init_mtx(&uvp->amrr_ch, &sc->sc_mtx, 0);
609 usb2_callout_init_mtx(&uvp->amrr_ch, &sc->sc_mtx, 0);
610 TASK_INIT(&uvp->amrr_task, 0, ural_amrr_task, uvp);
617 ieee80211_amrr_init(&uvp->amrr, vap,
618 IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD,
619 IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD,
620 1000 /* 1 sec */);
621
622 /* complete setup */
623 ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status);
624 ic->ic_opmode = opmode;
625 return vap;
626}
627
628static void
611 ieee80211_amrr_init(&uvp->amrr, vap,
612 IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD,
613 IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD,
614 1000 /* 1 sec */);
615
616 /* complete setup */
617 ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status);
618 ic->ic_opmode = opmode;
619 return vap;
620}
621
622static void
629ural_flush_task(struct usb2_proc_msg *pm)
630{
631 /* nothing to do */
632}
633
634static void
635ural_vap_delete(struct ieee80211vap *vap)
636{
637 struct ural_vap *uvp = URAL_VAP(vap);
623ural_vap_delete(struct ieee80211vap *vap)
624{
625 struct ural_vap *uvp = URAL_VAP(vap);
638 struct ural_softc *sc = uvp->sc;
626 struct ieee80211com *ic = vap->iv_ic;
639
627
640 RAL_LOCK(sc);
641 /* wait for any pending tasks to complete */
642 ural_queue_command(sc, ural_flush_task,
643 &sc->sc_synctask[0].hdr,
644 &sc->sc_synctask[1].hdr);
645 RAL_UNLOCK(sc);
646
647 usb2_callout_drain(&uvp->amrr_ch);
628 usb2_callout_drain(&uvp->amrr_ch);
629 ieee80211_draintask(ic, &uvp->amrr_task);
648 ieee80211_amrr_cleanup(&uvp->amrr);
649 ieee80211_vap_detach(vap);
650 free(uvp, M_80211_VAP);
651}
652
653static void
654ural_tx_free(struct ural_tx_data *data, int txerr)
655{

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

709 }
710 if (data->ni != NULL) {
711 ieee80211_free_node(data->ni);
712 data->ni = NULL;
713 }
714 }
715}
716
630 ieee80211_amrr_cleanup(&uvp->amrr);
631 ieee80211_vap_detach(vap);
632 free(uvp, M_80211_VAP);
633}
634
635static void
636ural_tx_free(struct ural_tx_data *data, int txerr)
637{

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

691 }
692 if (data->ni != NULL) {
693 ieee80211_free_node(data->ni);
694 data->ni = NULL;
695 }
696 }
697}
698
717static void
718ural_task(struct usb2_proc_msg *pm)
699static int
700ural_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
719{
701{
720 struct ural_task *task = (struct ural_task *)pm;
721 struct ural_softc *sc = task->sc;
722 struct ifnet *ifp = sc->sc_ifp;
723 struct ieee80211com *ic = ifp->if_l2com;
724 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
725 struct ural_vap *uvp = URAL_VAP(vap);
702 struct ural_vap *uvp = URAL_VAP(vap);
703 struct ieee80211com *ic = vap->iv_ic;
704 struct ural_softc *sc = ic->ic_ifp->if_softc;
726 const struct ieee80211_txparam *tp;
705 const struct ieee80211_txparam *tp;
727 enum ieee80211_state ostate;
728 struct ieee80211_node *ni;
729 struct mbuf *m;
730
706 struct ieee80211_node *ni;
707 struct mbuf *m;
708
731 ostate = vap->iv_state;
709 DPRINTF("%s -> %s\n",
710 ieee80211_state_name[vap->iv_state],
711 ieee80211_state_name[nstate]);
732
712
733 switch (sc->sc_state) {
713 IEEE80211_UNLOCK(ic);
714 RAL_LOCK(sc);
715 usb2_callout_stop(&uvp->amrr_ch);
716
717 switch (nstate) {
734 case IEEE80211_S_INIT:
718 case IEEE80211_S_INIT:
735 if (ostate == IEEE80211_S_RUN) {
719 if (vap->iv_state == IEEE80211_S_RUN) {
736 /* abort TSF synchronization */
737 ural_write(sc, RAL_TXRX_CSR19, 0);
738
739 /* force tx led to stop blinking */
740 ural_write(sc, RAL_MAC_CSR20, 0);
741 }
742 break;
743

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

753 }
754
755 if (vap->iv_opmode == IEEE80211_M_HOSTAP ||
756 vap->iv_opmode == IEEE80211_M_IBSS) {
757 m = ieee80211_beacon_alloc(ni, &uvp->bo);
758 if (m == NULL) {
759 device_printf(sc->sc_dev,
760 "could not allocate beacon\n");
720 /* abort TSF synchronization */
721 ural_write(sc, RAL_TXRX_CSR19, 0);
722
723 /* force tx led to stop blinking */
724 ural_write(sc, RAL_MAC_CSR20, 0);
725 }
726 break;
727

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

737 }
738
739 if (vap->iv_opmode == IEEE80211_M_HOSTAP ||
740 vap->iv_opmode == IEEE80211_M_IBSS) {
741 m = ieee80211_beacon_alloc(ni, &uvp->bo);
742 if (m == NULL) {
743 device_printf(sc->sc_dev,
744 "could not allocate beacon\n");
761 return;
745 RAL_UNLOCK(sc);
746 IEEE80211_LOCK(ic);
747 return (-1);
762 }
763 ieee80211_ref_node(ni);
764 if (ural_tx_bcn(sc, m, ni) != 0) {
765 device_printf(sc->sc_dev,
766 "could not send beacon\n");
748 }
749 ieee80211_ref_node(ni);
750 if (ural_tx_bcn(sc, m, ni) != 0) {
751 device_printf(sc->sc_dev,
752 "could not send beacon\n");
767 return;
753 RAL_UNLOCK(sc);
754 IEEE80211_LOCK(ic);
755 return (-1);
768 }
769 }
770
771 /* make tx led blink on tx (controlled by ASIC) */
772 ural_write(sc, RAL_MAC_CSR20, 1);
773
774 if (vap->iv_opmode != IEEE80211_M_MONITOR)
775 ural_enable_tsf_sync(sc);
776
777 /* enable automatic rate adaptation */
778 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_bsschan)];
779 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
780 ural_amrr_start(sc, ni);
781
782 break;
783
784 default:
785 break;
786 }
756 }
757 }
758
759 /* make tx led blink on tx (controlled by ASIC) */
760 ural_write(sc, RAL_MAC_CSR20, 1);
761
762 if (vap->iv_opmode != IEEE80211_M_MONITOR)
763 ural_enable_tsf_sync(sc);
764
765 /* enable automatic rate adaptation */
766 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_bsschan)];
767 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
768 ural_amrr_start(sc, ni);
769
770 break;
771
772 default:
773 break;
774 }
787
788 RAL_UNLOCK(sc);
789 IEEE80211_LOCK(ic);
775 RAL_UNLOCK(sc);
776 IEEE80211_LOCK(ic);
790 uvp->newstate(vap, sc->sc_state, sc->sc_arg);
791 if (vap->iv_newstate_cb != NULL)
792 vap->iv_newstate_cb(vap, sc->sc_state, sc->sc_arg);
793 IEEE80211_UNLOCK(ic);
794 RAL_LOCK(sc);
777 return (uvp->newstate(vap, nstate, arg));
795}
796
778}
779
797static void
798ural_scantask(struct usb2_proc_msg *pm)
799{
800 struct ural_task *task = (struct ural_task *)pm;
801 struct ural_softc *sc = task->sc;
802 struct ifnet *ifp = sc->sc_ifp;
803 struct ieee80211com *ic = ifp->if_l2com;
804
780
805 RAL_LOCK_ASSERT(sc, MA_OWNED);
806
807 switch (sc->sc_scan_action) {
808 case URAL_SCAN_START:
809 /* abort TSF synchronization */
810 DPRINTF("starting scan\n");
811 ural_write(sc, RAL_TXRX_CSR19, 0);
812 ural_set_bssid(sc, ifp->if_broadcastaddr);
813 break;
814
815 case URAL_SET_CHANNEL:
816 ural_set_chan(sc, ic->ic_curchan);
817 break;
818
819 default: /* URAL_SCAN_END */
820 DPRINTF("stopping scan\n");
821 ural_enable_tsf_sync(sc);
822 ural_set_bssid(sc, sc->sc_bssid);
823 break;
824 }
825}
826
827static int
828ural_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
829{
830 struct ural_vap *uvp = URAL_VAP(vap);
831 struct ieee80211com *ic = vap->iv_ic;
832 struct ural_softc *sc = ic->ic_ifp->if_softc;
833
834 DPRINTF("%s -> %s\n",
835 ieee80211_state_name[vap->iv_state],
836 ieee80211_state_name[nstate]);
837
838 RAL_LOCK(sc);
839 usb2_callout_stop(&uvp->amrr_ch);
840
841 /* do it in a process context */
842 sc->sc_state = nstate;
843 sc->sc_arg = arg;
844 RAL_UNLOCK(sc);
845
846 if (nstate == IEEE80211_S_INIT) {
847 uvp->newstate(vap, nstate, arg);
848 return 0;
849 } else {
850 RAL_LOCK(sc);
851 ural_queue_command(sc, ural_task, &sc->sc_task[0].hdr,
852 &sc->sc_task[1].hdr);
853 RAL_UNLOCK(sc);
854 return EINPROGRESS;
855 }
856}
857
858
859static void
860ural_bulk_write_callback(struct usb2_xfer *xfer)
861{
862 struct ural_softc *sc = xfer->priv_sc;
863 struct ifnet *ifp = sc->sc_ifp;
864 struct ieee80211com *ic = ifp->if_l2com;
865 struct ieee80211_channel *c = ic->ic_curchan;
866 struct ural_tx_data *data;
867 struct mbuf *m;
868 unsigned int len;
869
781static void
782ural_bulk_write_callback(struct usb2_xfer *xfer)
783{
784 struct ural_softc *sc = xfer->priv_sc;
785 struct ifnet *ifp = sc->sc_ifp;
786 struct ieee80211com *ic = ifp->if_l2com;
787 struct ieee80211_channel *c = ic->ic_curchan;
788 struct ural_tx_data *data;
789 struct mbuf *m;
790 unsigned int len;
791
870 /* wakeup waiting command, if any */
871 if (sc->sc_last_task != NULL)
872 cv_signal(&sc->sc_cmd_cv);
873
874 switch (USB_GET_STATE(xfer)) {
875 case USB_ST_TRANSFERRED:
876 DPRINTFN(11, "transfer complete, %d bytes\n", xfer->actlen);
877
878 /* free resources */
879 data = xfer->priv_fifo;
880 ural_tx_free(data, 0);
881 xfer->priv_fifo = NULL;
882
883 ifp->if_opackets++;
884 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
885
886 /* FALLTHROUGH */
887 case USB_ST_SETUP:
888tr_setup:
792 switch (USB_GET_STATE(xfer)) {
793 case USB_ST_TRANSFERRED:
794 DPRINTFN(11, "transfer complete, %d bytes\n", xfer->actlen);
795
796 /* free resources */
797 data = xfer->priv_fifo;
798 ural_tx_free(data, 0);
799 xfer->priv_fifo = NULL;
800
801 ifp->if_opackets++;
802 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
803
804 /* FALLTHROUGH */
805 case USB_ST_SETUP:
806tr_setup:
889 /* wait for command to complete, if any */
890 if (sc->sc_last_task != NULL)
891 break;
892
893 data = STAILQ_FIRST(&sc->tx_q);
894 if (data) {
895 STAILQ_REMOVE_HEAD(&sc->tx_q, next);
896 m = data->m;
897
898 if (m->m_pkthdr.len > (RAL_FRAME_SIZE + RAL_TX_DESC_SIZE)) {
899 DPRINTFN(0, "data overflow, %u bytes\n",
900 m->m_pkthdr.len);

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

1453 struct ifreq *ifr = (struct ifreq *) data;
1454 int error = 0, startall = 0;
1455
1456 switch (cmd) {
1457 case SIOCSIFFLAGS:
1458 RAL_LOCK(sc);
1459 if (ifp->if_flags & IFF_UP) {
1460 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
807 data = STAILQ_FIRST(&sc->tx_q);
808 if (data) {
809 STAILQ_REMOVE_HEAD(&sc->tx_q, next);
810 m = data->m;
811
812 if (m->m_pkthdr.len > (RAL_FRAME_SIZE + RAL_TX_DESC_SIZE)) {
813 DPRINTFN(0, "data overflow, %u bytes\n",
814 m->m_pkthdr.len);

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

1367 struct ifreq *ifr = (struct ifreq *) data;
1368 int error = 0, startall = 0;
1369
1370 switch (cmd) {
1371 case SIOCSIFFLAGS:
1372 RAL_LOCK(sc);
1373 if (ifp->if_flags & IFF_UP) {
1374 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
1461 ural_queue_command(sc, ural_init_task,
1462 &sc->sc_synctask[0].hdr,
1463 &sc->sc_synctask[1].hdr);
1375 ural_init_locked(sc);
1464 startall = 1;
1465 } else
1376 startall = 1;
1377 } else
1466 ural_queue_command(sc, ural_promisctask,
1467 &sc->sc_promisctask[0].hdr,
1468 &sc->sc_promisctask[1].hdr);
1378 ural_setpromisc(sc);
1469 } else {
1379 } else {
1470 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1471 ural_queue_command(sc, ural_stop_task,
1472 &sc->sc_synctask[0].hdr,
1473 &sc->sc_synctask[1].hdr);
1474 }
1380 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1381 ural_stop(sc);
1475 }
1476 RAL_UNLOCK(sc);
1477 if (startall)
1478 ieee80211_start_all(ic);
1479 break;
1480 case SIOCGIFMEDIA:
1481 case SIOCSIFMEDIA:
1482 error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd);

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

1694 struct ieee80211vap *vap = ni->ni_vap;
1695
1696 ieee80211_amrr_node_init(&URAL_VAP(vap)->amrr, &URAL_NODE(ni)->amn, ni);
1697}
1698
1699static void
1700ural_scan_start(struct ieee80211com *ic)
1701{
1382 }
1383 RAL_UNLOCK(sc);
1384 if (startall)
1385 ieee80211_start_all(ic);
1386 break;
1387 case SIOCGIFMEDIA:
1388 case SIOCSIFMEDIA:
1389 error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd);

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

1601 struct ieee80211vap *vap = ni->ni_vap;
1602
1603 ieee80211_amrr_node_init(&URAL_VAP(vap)->amrr, &URAL_NODE(ni)->amn, ni);
1604}
1605
1606static void
1607ural_scan_start(struct ieee80211com *ic)
1608{
1702 struct ural_softc *sc = ic->ic_ifp->if_softc;
1609 struct ifnet *ifp = ic->ic_ifp;
1610 struct ural_softc *sc = ifp->if_softc;
1703
1704 RAL_LOCK(sc);
1611
1612 RAL_LOCK(sc);
1705 /* do it in a process context */
1706 sc->sc_scan_action = URAL_SCAN_START;
1707 ural_queue_command(sc, ural_scantask,
1708 &sc->sc_scantask[0].hdr, &sc->sc_scantask[1].hdr);
1613 ural_write(sc, RAL_TXRX_CSR19, 0);
1614 ural_set_bssid(sc, ifp->if_broadcastaddr);
1709 RAL_UNLOCK(sc);
1615 RAL_UNLOCK(sc);
1710
1711}
1712
1713static void
1714ural_scan_end(struct ieee80211com *ic)
1715{
1716 struct ural_softc *sc = ic->ic_ifp->if_softc;
1717
1718 RAL_LOCK(sc);
1616}
1617
1618static void
1619ural_scan_end(struct ieee80211com *ic)
1620{
1621 struct ural_softc *sc = ic->ic_ifp->if_softc;
1622
1623 RAL_LOCK(sc);
1719 /* do it in a process context */
1720 sc->sc_scan_action = URAL_SCAN_END;
1721 ural_queue_command(sc, ural_scantask,
1722 &sc->sc_scantask[0].hdr, &sc->sc_scantask[1].hdr);
1624 ural_enable_tsf_sync(sc);
1625 ural_set_bssid(sc, sc->sc_bssid);
1723 RAL_UNLOCK(sc);
1724
1725}
1726
1727static void
1728ural_set_channel(struct ieee80211com *ic)
1729{
1730 struct ural_softc *sc = ic->ic_ifp->if_softc;
1731
1732 RAL_LOCK(sc);
1626 RAL_UNLOCK(sc);
1627
1628}
1629
1630static void
1631ural_set_channel(struct ieee80211com *ic)
1632{
1633 struct ural_softc *sc = ic->ic_ifp->if_softc;
1634
1635 RAL_LOCK(sc);
1733 /* do it in a process context */
1734 sc->sc_scan_action = URAL_SET_CHANNEL;
1735 ural_queue_command(sc, ural_scantask,
1736 &sc->sc_scantask[0].hdr, &sc->sc_scantask[1].hdr);
1636 ural_set_chan(sc, ic->ic_curchan);
1737 RAL_UNLOCK(sc);
1738}
1739
1740static void
1741ural_set_chan(struct ural_softc *sc, struct ieee80211_channel *c)
1742{
1743 struct ifnet *ifp = sc->sc_ifp;
1744 struct ieee80211com *ic = ifp->if_l2com;

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

1989
1990 tmp = addr[4] | addr[5] << 8;
1991 ural_write(sc, RAL_MAC_CSR4, tmp);
1992
1993 DPRINTF("setting MAC address to %6D\n", addr, ":");
1994}
1995
1996static void
1637 RAL_UNLOCK(sc);
1638}
1639
1640static void
1641ural_set_chan(struct ural_softc *sc, struct ieee80211_channel *c)
1642{
1643 struct ifnet *ifp = sc->sc_ifp;
1644 struct ieee80211com *ic = ifp->if_l2com;

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

1889
1890 tmp = addr[4] | addr[5] << 8;
1891 ural_write(sc, RAL_MAC_CSR4, tmp);
1892
1893 DPRINTF("setting MAC address to %6D\n", addr, ":");
1894}
1895
1896static void
1997ural_promisctask(struct usb2_proc_msg *pm)
1897ural_setpromisc(struct ural_softc *sc)
1998{
1898{
1999 struct ural_task *task = (struct ural_task *)pm;
2000 struct ural_softc *sc = task->sc;
2001 struct ifnet *ifp = sc->sc_ifp;
2002 uint32_t tmp;
2003
2004 tmp = ural_read(sc, RAL_TXRX_CSR2);
2005
2006 tmp &= ~RAL_DROP_NOT_TO_ME;
2007 if (!(ifp->if_flags & IFF_PROMISC))
2008 tmp |= RAL_DROP_NOT_TO_ME;

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

2017ural_update_promisc(struct ifnet *ifp)
2018{
2019 struct ural_softc *sc = ifp->if_softc;
2020
2021 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
2022 return;
2023
2024 RAL_LOCK(sc);
1899 struct ifnet *ifp = sc->sc_ifp;
1900 uint32_t tmp;
1901
1902 tmp = ural_read(sc, RAL_TXRX_CSR2);
1903
1904 tmp &= ~RAL_DROP_NOT_TO_ME;
1905 if (!(ifp->if_flags & IFF_PROMISC))
1906 tmp |= RAL_DROP_NOT_TO_ME;

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

1915ural_update_promisc(struct ifnet *ifp)
1916{
1917 struct ural_softc *sc = ifp->if_softc;
1918
1919 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
1920 return;
1921
1922 RAL_LOCK(sc);
2025 ural_queue_command(sc, ural_promisctask,
2026 &sc->sc_promisctask[0].hdr,
2027 &sc->sc_promisctask[1].hdr);
1923 ural_setpromisc(sc);
2028 RAL_UNLOCK(sc);
2029}
2030
2031static const char *
2032ural_get_rf(int rev)
2033{
2034 switch (rev) {
2035 case RAL_RF_2522: return "RT2522";

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

2147 /* need to force no I/Q flip for RF 2525e and 2526 */
2148 if (sc->rf_rev == RAL_RF_2525E || sc->rf_rev == RAL_RF_2526)
2149 rx &= ~RAL_BBP_FLIPIQ;
2150
2151 ural_bbp_write(sc, RAL_BBP_RX, rx);
2152}
2153
2154static void
1924 RAL_UNLOCK(sc);
1925}
1926
1927static const char *
1928ural_get_rf(int rev)
1929{
1930 switch (rev) {
1931 case RAL_RF_2522: return "RT2522";

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

2043 /* need to force no I/Q flip for RF 2525e and 2526 */
2044 if (sc->rf_rev == RAL_RF_2525E || sc->rf_rev == RAL_RF_2526)
2045 rx &= ~RAL_BBP_FLIPIQ;
2046
2047 ural_bbp_write(sc, RAL_BBP_RX, rx);
2048}
2049
2050static void
2155ural_init_task(struct usb2_proc_msg *pm)
2051ural_init_locked(struct ural_softc *sc)
2156{
2157#define N(a) (sizeof (a) / sizeof ((a)[0]))
2052{
2053#define N(a) (sizeof (a) / sizeof ((a)[0]))
2158 struct ural_task *task = (struct ural_task *)pm;
2159 struct ural_softc *sc = task->sc;
2160 struct ifnet *ifp = sc->sc_ifp;
2161 struct ieee80211com *ic = ifp->if_l2com;
2162 uint16_t tmp;
2163 int i, ntries;
2164
2165 RAL_LOCK_ASSERT(sc, MA_OWNED);
2166
2167 ural_set_testmode(sc);
2168 ural_write(sc, 0x308, 0x00f0); /* XXX magic */
2169
2054 struct ifnet *ifp = sc->sc_ifp;
2055 struct ieee80211com *ic = ifp->if_l2com;
2056 uint16_t tmp;
2057 int i, ntries;
2058
2059 RAL_LOCK_ASSERT(sc, MA_OWNED);
2060
2061 ural_set_testmode(sc);
2062 ural_write(sc, 0x308, 0x00f0); /* XXX magic */
2063
2170 ural_stop_task(pm);
2064 ural_stop(sc);
2171
2172 /* initialize MAC registers to default values */
2173 for (i = 0; i < N(ural_def_mac); i++)
2174 ural_write(sc, ural_def_mac[i].reg, ural_def_mac[i].val);
2175
2176 /* wait for BBP and RF to wake up (this can take a long time!) */
2177 for (ntries = 0; ntries < 100; ntries++) {
2178 tmp = ural_read(sc, RAL_MAC_CSR17);

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

2224 ural_write(sc, RAL_TXRX_CSR2, tmp);
2225
2226 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2227 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2228 usb2_transfer_set_stall(sc->sc_xfer[URAL_BULK_WR]);
2229 usb2_transfer_start(sc->sc_xfer[URAL_BULK_RD]);
2230 return;
2231
2065
2066 /* initialize MAC registers to default values */
2067 for (i = 0; i < N(ural_def_mac); i++)
2068 ural_write(sc, ural_def_mac[i].reg, ural_def_mac[i].val);
2069
2070 /* wait for BBP and RF to wake up (this can take a long time!) */
2071 for (ntries = 0; ntries < 100; ntries++) {
2072 tmp = ural_read(sc, RAL_MAC_CSR17);

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

2118 ural_write(sc, RAL_TXRX_CSR2, tmp);
2119
2120 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2121 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2122 usb2_transfer_set_stall(sc->sc_xfer[URAL_BULK_WR]);
2123 usb2_transfer_start(sc->sc_xfer[URAL_BULK_RD]);
2124 return;
2125
2232fail: ural_stop_task(pm);
2126fail: ural_stop(sc);
2233#undef N
2234}
2235
2236static void
2237ural_init(void *priv)
2238{
2239 struct ural_softc *sc = priv;
2240 struct ifnet *ifp = sc->sc_ifp;
2241 struct ieee80211com *ic = ifp->if_l2com;
2242
2243 RAL_LOCK(sc);
2127#undef N
2128}
2129
2130static void
2131ural_init(void *priv)
2132{
2133 struct ural_softc *sc = priv;
2134 struct ifnet *ifp = sc->sc_ifp;
2135 struct ieee80211com *ic = ifp->if_l2com;
2136
2137 RAL_LOCK(sc);
2244 ural_queue_command(sc, ural_init_task,
2245 &sc->sc_synctask[0].hdr,
2246 &sc->sc_synctask[1].hdr);
2138 ural_init_locked(sc);
2247 RAL_UNLOCK(sc);
2248
2249 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2250 ieee80211_start_all(ic); /* start all vap's */
2251}
2252
2253static void
2139 RAL_UNLOCK(sc);
2140
2141 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2142 ieee80211_start_all(ic); /* start all vap's */
2143}
2144
2145static void
2254ural_stop_task(struct usb2_proc_msg *pm)
2146ural_stop(struct ural_softc *sc)
2255{
2147{
2256 struct ural_task *task = (struct ural_task *)pm;
2257 struct ural_softc *sc = task->sc;
2258 struct ifnet *ifp = sc->sc_ifp;
2259
2260 RAL_LOCK_ASSERT(sc, MA_OWNED);
2261
2262 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
2263
2264 /*
2265 * Drain all the transfers, if not already drained:

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

2345
2346 usb2_callout_reset(&uvp->amrr_ch, hz, ural_amrr_timeout, uvp);
2347}
2348
2349static void
2350ural_amrr_timeout(void *arg)
2351{
2352 struct ural_vap *uvp = arg;
2148 struct ifnet *ifp = sc->sc_ifp;
2149
2150 RAL_LOCK_ASSERT(sc, MA_OWNED);
2151
2152 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
2153
2154 /*
2155 * Drain all the transfers, if not already drained:

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

2235
2236 usb2_callout_reset(&uvp->amrr_ch, hz, ural_amrr_timeout, uvp);
2237}
2238
2239static void
2240ural_amrr_timeout(void *arg)
2241{
2242 struct ural_vap *uvp = arg;
2353 struct ural_softc *sc = uvp->sc;
2243 struct ieee80211vap *vap = &uvp->vap;
2244 struct ieee80211com *ic = vap->iv_ic;
2354
2245
2355 ural_queue_command(sc, ural_amrr_task,
2356 &uvp->amrr_task[0].hdr, &uvp->amrr_task[1].hdr);
2246 ieee80211_runtask(ic, &uvp->amrr_task);
2357}
2358
2359static void
2247}
2248
2249static void
2360ural_amrr_task(struct usb2_proc_msg *pm)
2250ural_amrr_task(void *arg, int pending)
2361{
2251{
2362 struct ural_task *task = (struct ural_task *)pm;
2363 struct ural_softc *sc = task->sc;
2364 struct ifnet *ifp = sc->sc_ifp;
2365 struct ieee80211com *ic = ifp->if_l2com;
2366 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2367 struct ural_vap *uvp = URAL_VAP(vap);
2252 struct ural_vap *uvp = arg;
2253 struct ieee80211vap *vap = &uvp->vap;
2254 struct ieee80211com *ic = vap->iv_ic;
2255 struct ifnet *ifp = ic->ic_ifp;
2256 struct ural_softc *sc = ifp->if_softc;
2368 struct ieee80211_node *ni = vap->iv_bss;
2369 int ok, fail;
2370
2257 struct ieee80211_node *ni = vap->iv_bss;
2258 int ok, fail;
2259
2260 RAL_LOCK(sc);
2371 /* read and clear statistic registers (STA_CSR0 to STA_CSR10) */
2372 ural_read_multi(sc, RAL_STA_CSR0, sc->sta, sizeof(sc->sta));
2373
2374 ok = sc->sta[7] + /* TX ok w/o retry */
2375 sc->sta[8]; /* TX ok w/ retry */
2376 fail = sc->sta[9]; /* TX retry-fail count */
2377
2378 ieee80211_amrr_tx_update(&URAL_NODE(ni)->amn,
2379 ok+fail, ok, sc->sta[8] + fail);
2380 (void) ieee80211_amrr_choose(ni, &URAL_NODE(ni)->amn);
2381
2382 ifp->if_oerrors += fail; /* count TX retry-fail as Tx errors */
2383
2384 usb2_callout_reset(&uvp->amrr_ch, hz, ural_amrr_timeout, uvp);
2261 /* read and clear statistic registers (STA_CSR0 to STA_CSR10) */
2262 ural_read_multi(sc, RAL_STA_CSR0, sc->sta, sizeof(sc->sta));
2263
2264 ok = sc->sta[7] + /* TX ok w/o retry */
2265 sc->sta[8]; /* TX ok w/ retry */
2266 fail = sc->sta[9]; /* TX retry-fail count */
2267
2268 ieee80211_amrr_tx_update(&URAL_NODE(ni)->amn,
2269 ok+fail, ok, sc->sta[8] + fail);
2270 (void) ieee80211_amrr_choose(ni, &URAL_NODE(ni)->amn);
2271
2272 ifp->if_oerrors += fail; /* count TX retry-fail as Tx errors */
2273
2274 usb2_callout_reset(&uvp->amrr_ch, hz, ural_amrr_timeout, uvp);
2275 RAL_UNLOCK(sc);
2385}
2386
2387static int
2388ural_pause(struct ural_softc *sc, int timeout)
2389{
2276}
2277
2278static int
2279ural_pause(struct ural_softc *sc, int timeout)
2280{
2390 if (usb2_proc_is_gone(&sc->sc_tq))
2391 return (1);
2392
2393 usb2_pause_mtx(&sc->sc_mtx, timeout);
2394 return (0);
2395}
2281
2282 usb2_pause_mtx(&sc->sc_mtx, timeout);
2283 return (0);
2284}
2396
2397static void
2398ural_command_wrapper(struct usb2_proc_msg *pm)
2399{
2400 struct ural_task *task = (struct ural_task *)pm;
2401 struct ural_softc *sc = task->sc;
2402 struct ifnet *ifp;
2403
2404 /* wait for pending transfer, if any */
2405 while (usb2_transfer_pending(sc->sc_xfer[URAL_BULK_WR]))
2406 cv_wait(&sc->sc_cmd_cv, &sc->sc_mtx);
2407
2408 /* make sure any hardware FIFOs are emptied */
2409 ural_pause(sc, hz / 1000);
2410
2411 /* execute task */
2412 task->func(pm);
2413
2414 /* check if this is the last task executed */
2415 if (sc->sc_last_task == task) {
2416 sc->sc_last_task = NULL;
2417 ifp = sc->sc_ifp;
2418 /* re-start TX, if any */
2419 if ((ifp != NULL) && (ifp->if_drv_flags & IFF_DRV_RUNNING))
2420 usb2_transfer_start(sc->sc_xfer[URAL_BULK_WR]);
2421 }
2422}
2423
2424static void
2425ural_queue_command(struct ural_softc *sc, usb2_proc_callback_t *fn,
2426 struct usb2_proc_msg *t0, struct usb2_proc_msg *t1)
2427{
2428 struct ural_task *task;
2429
2430 RAL_LOCK_ASSERT(sc, MA_OWNED);
2431
2432 /*
2433 * NOTE: The task cannot get executed before we drop the
2434 * "sc_mtx" mutex. It is safe to update fields in the message
2435 * structure after that the message got queued.
2436 */
2437 task = (struct ural_task *)
2438 usb2_proc_msignal(&sc->sc_tq, t0, t1);
2439
2440 /* Setup callback and softc pointers */
2441 task->hdr.pm_callback = ural_command_wrapper;
2442 task->func = fn;
2443 task->sc = sc;
2444
2445 /* Make sure that any TX operation will stop */
2446 sc->sc_last_task = task;
2447
2448 /*
2449 * Init, stop and flush must be synchronous!
2450 */
2451 if ((fn == ural_init_task) || (fn == ural_stop_task) ||
2452 (fn == ural_stop_task))
2453 usb2_proc_mwait(&sc->sc_tq, t0, t1);
2454}