From 097eca3a40242ef738edf9015baf1cf8950fd095 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Wed, 7 May 2014 15:01:43 +0200 Subject: [PATCH] kernel: Remove two oldusb wlan drivers, rum and ural. Both don't work even with oldusb because they have never been ported to the current ieee80211 framework. In fact, they were unhooked from the build at the time. Both also exist for usb4bsd. rum(4) was ported to DragonFly while ural(4) has yet to be ported. --- sys/conf/files | 2 - sys/dev/netif/Makefile | 5 - sys/dev/netif/rum/Makefile | 7 - sys/dev/netif/rum/if_rum.c | 2293 ----------------------------- sys/dev/netif/rum/if_rumreg.h | 395 ----- sys/dev/netif/rum/if_rumvar.h | 159 -- sys/dev/netif/rum/rum_ucode.h | 214 --- sys/dev/netif/ural/Makefile | 7 - sys/dev/netif/ural/if_ural.c | 2456 ------------------------------- sys/dev/netif/ural/if_uralreg.h | 211 --- sys/dev/netif/ural/if_uralvar.h | 159 -- 11 files changed, 5908 deletions(-) delete mode 100644 sys/dev/netif/rum/Makefile delete mode 100644 sys/dev/netif/rum/if_rum.c delete mode 100644 sys/dev/netif/rum/if_rumreg.h delete mode 100644 sys/dev/netif/rum/if_rumvar.h delete mode 100644 sys/dev/netif/rum/rum_ucode.h delete mode 100644 sys/dev/netif/ural/Makefile delete mode 100644 sys/dev/netif/ural/if_ural.c delete mode 100644 sys/dev/netif/ural/if_uralreg.h delete mode 100644 sys/dev/netif/ural/if_uralvar.h diff --git a/sys/conf/files b/sys/conf/files index c63f083feb..6f5a62b1e9 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -658,8 +658,6 @@ rt2860.fw optional ralfw \ compile-with "${NORMAL_FW}" \ no-obj no-implicit-rule \ clean "rt2860.fw" -#dev/netif/rum/if_rum.c optional rum oldusb -#dev/netif/ural/if_ural.c optional ural oldusb dev/netif/lge/if_lge.c optional lge dev/disk/md/md.c optional md dev/raid/mfi/mfi.c optional mfi diff --git a/sys/dev/netif/Makefile b/sys/dev/netif/Makefile index 12861df95c..b6978b0957 100644 --- a/sys/dev/netif/Makefile +++ b/sys/dev/netif/Makefile @@ -12,11 +12,6 @@ SUBDIR+=ar sbni # XXX need to be updated to the new net80211 stack # SUBDIR+= acx bwi iwl rtw # .endif -# -# ...and to the new USB stack -# .if defined(WANT_OLDUSB) -# SUBDIR+= ural -# .endif .if defined(WANT_OLDUSB) SUBDIR+=aue axe cue kue lgue rue diff --git a/sys/dev/netif/rum/Makefile b/sys/dev/netif/rum/Makefile deleted file mode 100644 index deb4537c24..0000000000 --- a/sys/dev/netif/rum/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $DragonFly: src/sys/dev/netif/rum/Makefile,v 1.1 2006/12/10 03:24:25 sephe Exp $ - -KMOD= if_rum -SRCS= if_rum.c -SRCS+= device_if.h bus_if.h opt_usb.h - -.include diff --git a/sys/dev/netif/rum/if_rum.c b/sys/dev/netif/rum/if_rum.c deleted file mode 100644 index 4b923380b4..0000000000 --- a/sys/dev/netif/rum/if_rum.c +++ /dev/null @@ -1,2293 +0,0 @@ -/* $OpenBSD: if_rum.c,v 1.40 2006/09/18 16:20:20 damien Exp $ */ - -/*- - * Copyright (c) 2005, 2006 Damien Bergamini - * Copyright (c) 2006 Niall O'Higgins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/*- - * Ralink Technology RT2501USB/RT2601USB chipset driver - * http://www.ralinktech.com/ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include "if_rumreg.h" -#include "if_rumvar.h" -#include "rum_ucode.h" - -#ifdef USB_DEBUG -#define RUM_DEBUG -#endif - -#ifdef RUM_DEBUG -#define DPRINTF(x) do { if (rum_debug) kprintf x; } while (0) -#define DPRINTFN(n, x) do { if (rum_debug >= (n)) kprintf x; } while (0) -int rum_debug = 0; -#else -#define DPRINTF(x) -#define DPRINTFN(n, x) -#endif - -/* various supported device vendors/products */ -static const struct usb_devno rum_devs[] = { - { USB_DEVICE(0x0411, 0x00d8) }, /* Melco WLI-U2-SG54HP */ - { USB_DEVICE(0x0411, 0x00d9) }, /* Melco WLI-U2-G54HP */ - { USB_DEVICE(0x050d, 0x705a) }, /* Belkin F5D7050A */ - { USB_DEVICE(0x050d, 0x905b) }, /* Belkin F5D9050 ver3 */ - { USB_DEVICE(0x0586, 0x3415) }, /* ZyXEL RT2573 */ - { USB_DEVICE(0x06f8, 0xe010) }, /* Guillemot HWGUSB2-54-LB */ - { USB_DEVICE(0x06f8, 0xe020) }, /* Guillemot HWGUSB2-54V2-AP */ - { USB_DEVICE(0x0769, 0x31f3) }, /* Surecom RT2573 */ - { USB_DEVICE(0x07b8, 0xb21b) }, /* AboCom HWU54DM */ - { USB_DEVICE(0x07b8, 0xb21c) }, /* AboCom RT2573 */ - { USB_DEVICE(0x07b8, 0xb21d) }, /* AboCom RT2573 */ - { USB_DEVICE(0x07b8, 0xb21e) }, /* AboCom RT2573 */ - { USB_DEVICE(0x07b8, 0xb21f) }, /* AboCom WUG2700 */ - { USB_DEVICE(0x07d1, 0x3c03) }, /* D-Link DWL-G122 rev c1 */ - { USB_DEVICE(0x07d1, 0x3c04) }, /* D-Link WUA-1340 */ - { USB_DEVICE(0x0b05, 0x1723) }, /* Asus WL-167g */ - { USB_DEVICE(0x0b05, 0x1724) }, /* Asus WL-167g */ - { USB_DEVICE(0x0db0, 0x6874) }, /* MSI RT2573 */ - { USB_DEVICE(0x0db0, 0x6877) }, /* MSI RT2573 */ - { USB_DEVICE(0x0db0, 0xa861) }, /* MSI RT2573 */ - { USB_DEVICE(0x0db0, 0xa874) }, /* MSI RT2573 */ - { USB_DEVICE(0x0df6, 0x90ac) }, /* Sitecom WL-172 */ - { USB_DEVICE(0x0df6, 0x9712) }, /* Sitecom WL-113 rev 2 */ - { USB_DEVICE(0x0eb0, 0x9021) }, /* Nova Technology RT2573 */ - { USB_DEVICE(0x1044, 0x8008) }, /* GIGABYTE GN-WB01GS */ - { USB_DEVICE(0x1044, 0x800a) }, /* GIGABYTE GN-WI05GS */ - { USB_DEVICE(0x1371, 0x9022) }, /* (really) C-Net RT2573 */ - { USB_DEVICE(0x1371, 0x9032) }, /* (really) C-Net CWD854F */ - { USB_DEVICE(0x13b1, 0x0020) }, /* Cisco-Linksys WUSB54GC */ - { USB_DEVICE(0x13b1, 0x0023) }, /* Cisco-Linksys WUSB54GR */ - { USB_DEVICE(0x1472, 0x0009) }, /* Huawei RT2573 */ - { USB_DEVICE(0x148f, 0x2573) }, /* Ralink RT2573 */ - { USB_DEVICE(0x148f, 0x2671) }, /* Ralink RT2671 */ - { USB_DEVICE(0x148f, 0x9021) }, /* Ralink RT2573 */ - { USB_DEVICE(0x14b2, 0x3c22) }, /* Conceptronic C54RU */ - { USB_DEVICE(0x15a9, 0x0004) }, /* SparkLan RT2573 */ - { USB_DEVICE(0x1631, 0xc019) }, /* Good Way Technology RT2573 */ - { USB_DEVICE(0x1690, 0x0722) }, /* Gigaset RT2573 */ - { USB_DEVICE(0x1737, 0x0020) }, /* Linksys WUSB54GC */ - { USB_DEVICE(0x1737, 0x0023) }, /* Linksys WUSB54GR */ - { USB_DEVICE(0x18c5, 0x0002) }, /* AMIT CG-WLUSB2GO */ - { USB_DEVICE(0x18e8, 0x6196) }, /* Qcom RT2573 */ - { USB_DEVICE(0x18e8, 0x6229) }, /* Qcom RT2573 */ - { USB_DEVICE(0x18e8, 0x6238) }, /* Qcom RT2573 */ - { USB_DEVICE(0x2019, 0xab01) }, /* Planex GW-US54HP */ - { USB_DEVICE(0x2019, 0xab50) }, /* Planex GW-US54Mini2 */ - { USB_DEVICE(0x2019, 0xed02) }, /* Planex GW-USMM */ -}; - -static int rum_alloc_tx_list(struct rum_softc *); -static void rum_free_tx_list(struct rum_softc *); -static int rum_alloc_rx_list(struct rum_softc *); -static void rum_free_rx_list(struct rum_softc *); -static int rum_media_change(struct ifnet *); -static void rum_next_scan(void *); -static void rum_task(void *); -static int rum_newstate(struct ieee80211com *, - enum ieee80211_state, int); -static void rum_txeof(usbd_xfer_handle, usbd_private_handle, - usbd_status); -static void rum_rxeof(usbd_xfer_handle, usbd_private_handle, - usbd_status); -static uint8_t rum_rxrate(struct rum_rx_desc *); -static uint8_t rum_plcp_signal(int); -static void rum_setup_tx_desc(struct rum_softc *, - struct rum_tx_desc *, uint32_t, uint16_t, int, - int); -static int rum_tx_data(struct rum_softc *, struct mbuf *, - struct ieee80211_node *); -static void rum_start(struct ifnet *, struct ifaltq_subque *); -static void rum_watchdog(struct ifnet *); -static int rum_ioctl(struct ifnet *, u_long, caddr_t, - struct ucred *); -static void rum_eeprom_read(struct rum_softc *, uint16_t, void *, - int); -static uint32_t rum_read(struct rum_softc *, uint16_t); -static void rum_read_multi(struct rum_softc *, uint16_t, void *, - int); -static void rum_write(struct rum_softc *, uint16_t, uint32_t); -static void rum_write_multi(struct rum_softc *, uint16_t, void *, - size_t); -static void rum_bbp_write(struct rum_softc *, uint8_t, uint8_t); -static uint8_t rum_bbp_read(struct rum_softc *, uint8_t); -static void rum_rf_write(struct rum_softc *, uint8_t, uint32_t); -static void rum_select_antenna(struct rum_softc *); -static void rum_enable_mrr(struct rum_softc *); -static void rum_set_txpreamble(struct rum_softc *); -static void rum_set_basicrates(struct rum_softc *); -static void rum_select_band(struct rum_softc *, - struct ieee80211_channel *); -static void rum_set_chan(struct rum_softc *, - struct ieee80211_channel *); -static void rum_enable_tsf_sync(struct rum_softc *); -static void rum_update_slot(struct rum_softc *); -static void rum_set_bssid(struct rum_softc *, const uint8_t *); -static void rum_set_macaddr(struct rum_softc *, const uint8_t *); -static void rum_update_promisc(struct rum_softc *); -static const char *rum_get_rf(int); -static void rum_read_eeprom(struct rum_softc *); -static int rum_bbp_init(struct rum_softc *); -static void rum_init(void *); -static void rum_stop(struct rum_softc *); -static int rum_load_microcode(struct rum_softc *, const uint8_t *, - size_t); -static int rum_prepare_beacon(struct rum_softc *); - -static void rum_stats_timeout(void *); -static void rum_stats_update(usbd_xfer_handle, usbd_private_handle, - usbd_status); -static void rum_stats(struct ieee80211com *, - struct ieee80211_node *, - struct ieee80211_ratectl_stats *); -static void *rum_ratectl_attach(struct ieee80211com *, u_int); -static int rum_get_rssi(struct rum_softc *, uint8_t); - -/* - * Supported rates for 802.11a/b/g modes (in 500Kbps unit). - */ -static const struct ieee80211_rateset rum_rateset_11a = - { 8, { 12, 18, 24, 36, 48, 72, 96, 108 } }; - -static const struct ieee80211_rateset rum_rateset_11b = - { 4, { 2, 4, 11, 22 } }; - -static const struct ieee80211_rateset rum_rateset_11g = - { 12, { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 } }; - -static const struct { - uint32_t reg; - uint32_t val; -} rum_def_mac[] = { - RT2573_DEF_MAC -}; - -static const struct { - uint8_t reg; - uint8_t val; -} rum_def_bbp[] = { - RT2573_DEF_BBP -}; - -static const struct rfprog { - uint8_t chan; - uint32_t r1, r2, r3, r4; -} rum_rf5226[] = { - RT2573_RF5226 -}, rum_rf5225[] = { - RT2573_RF5225 -}; - -static device_probe_t rum_match; -static device_attach_t rum_attach; -static device_detach_t rum_detach; - -static devclass_t rum_devclass; - -static kobj_method_t rum_methods[] = { - DEVMETHOD(device_probe, rum_match), - DEVMETHOD(device_attach, rum_attach), - DEVMETHOD(device_detach, rum_detach), - DEVMETHOD_END -}; - -static driver_t rum_driver = { - "rum", - rum_methods, - sizeof(struct rum_softc) -}; - -DRIVER_MODULE(rum, uhub, rum_driver, rum_devclass, usbd_driver_load, NULL); - -MODULE_DEPEND(rum, usb, 1, 1, 1); -MODULE_DEPEND(rum, wlan, 1, 1, 1); -MODULE_DEPEND(rum, wlan_ratectl_onoe, 1, 1, 1); - -static int -rum_match(device_t self) -{ - struct usb_attach_arg *uaa = device_get_ivars(self); - - if (uaa->iface != NULL) - return UMATCH_NONE; - - return (usb_lookup(rum_devs, uaa->vendor, uaa->product) != NULL) ? - UMATCH_VENDOR_PRODUCT : UMATCH_NONE; -} - -static int -rum_attach(device_t self) -{ - struct rum_softc *sc = device_get_softc(self); - struct usb_attach_arg *uaa = device_get_ivars(self); - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - usb_interface_descriptor_t *id; - usb_endpoint_descriptor_t *ed; - usbd_status error; - int i, ntries; - uint32_t tmp; - char ethstr[ETHER_ADDRSTRLEN + 1]; - - sc->sc_udev = uaa->device; - sc->sc_dev = self; - - if (usbd_set_config_no(sc->sc_udev, RT2573_CONFIG_NO, 0) != 0) { - kprintf("%s: could not set configuration no\n", - device_get_nameunit(sc->sc_dev)); - return ENXIO; - } - - /* get the first interface handle */ - error = usbd_device2interface_handle(sc->sc_udev, RT2573_IFACE_INDEX, - &sc->sc_iface); - if (error != 0) { - kprintf("%s: could not get interface handle\n", - device_get_nameunit(sc->sc_dev)); - return ENXIO; - } - - /* - * Find endpoints. - */ - id = usbd_get_interface_descriptor(sc->sc_iface); - - sc->sc_rx_no = sc->sc_tx_no = -1; - for (i = 0; i < id->bNumEndpoints; i++) { - ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i); - if (ed == NULL) { - kprintf("%s: no endpoint descriptor for iface %d\n", - device_get_nameunit(sc->sc_dev), i); - return ENXIO; - } - - if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && - UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) - sc->sc_rx_no = ed->bEndpointAddress; - else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && - UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) - sc->sc_tx_no = ed->bEndpointAddress; - } - if (sc->sc_rx_no == -1 || sc->sc_tx_no == -1) { - kprintf("%s: missing endpoint\n", device_get_nameunit(sc->sc_dev)); - return ENXIO; - } - - usb_init_task(&sc->sc_task, rum_task, sc); - - callout_init(&sc->scan_ch); - callout_init(&sc->stats_ch); - - /* retrieve RT2573 rev. no */ - for (ntries = 0; ntries < 1000; ntries++) { - if ((tmp = rum_read(sc, RT2573_MAC_CSR0)) != 0) - break; - DELAY(1000); - } - if (ntries == 1000) { - kprintf("%s: timeout waiting for chip to settle\n", - device_get_nameunit(sc->sc_dev)); - return ENXIO; - } - - /* retrieve MAC address and various other things from EEPROM */ - rum_read_eeprom(sc); - - kprintf("%s: MAC/BBP RT%04x (rev 0x%05x), RF %s, address %s\n", - device_get_nameunit(sc->sc_dev), sc->macbbp_rev, tmp, - rum_get_rf(sc->rf_rev), kether_addr(ic->ic_myaddr, ethstr)); - - error = rum_load_microcode(sc, rt2573, sizeof(rt2573)); - if (error != 0) { - device_printf(self, "can't load microcode\n"); - return ENXIO; - } - - ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ - ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */ - ic->ic_state = IEEE80211_S_INIT; - - /* set device capabilities */ - ic->ic_caps = - IEEE80211_C_IBSS | /* IBSS mode supported */ - IEEE80211_C_MONITOR | /* monitor mode supported */ - IEEE80211_C_HOSTAP | /* HostAp mode supported */ - IEEE80211_C_TXPMGT | /* tx power management */ - IEEE80211_C_SHPREAMBLE | /* short preamble supported */ - IEEE80211_C_SHSLOT | /* short slot time supported */ - IEEE80211_C_WPA; /* WPA 1+2 */ - - if (sc->rf_rev == RT2573_RF_5225 || sc->rf_rev == RT2573_RF_5226) { - /* set supported .11a rates */ - ic->ic_sup_rates[IEEE80211_MODE_11A] = rum_rateset_11a; - - /* set supported .11a channels */ - for (i = 34; i <= 46; i += 4) { - ic->ic_channels[i].ic_freq = - ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ); - ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A; - } - for (i = 36; i <= 64; i += 4) { - ic->ic_channels[i].ic_freq = - ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ); - ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A; - } - for (i = 100; i <= 140; i += 4) { - ic->ic_channels[i].ic_freq = - ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ); - ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A; - } - for (i = 149; i <= 165; i += 4) { - ic->ic_channels[i].ic_freq = - ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ); - ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A; - } - } - - /* set supported .11b and .11g rates */ - ic->ic_sup_rates[IEEE80211_MODE_11B] = rum_rateset_11b; - ic->ic_sup_rates[IEEE80211_MODE_11G] = rum_rateset_11g; - - /* set supported .11b and .11g channels (1 through 14) */ - for (i = 1; i <= 14; i++) { - ic->ic_channels[i].ic_freq = - ieee80211_ieee2mhz(i, IEEE80211_CHAN_2GHZ); - ic->ic_channels[i].ic_flags = - IEEE80211_CHAN_CCK | IEEE80211_CHAN_OFDM | - IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ; - } - - sc->sc_sifs = IEEE80211_DUR_SIFS; /* Default SIFS */ - - if_initname(ifp, device_get_name(self), device_get_unit(self)); - ifp->if_softc = sc; - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; - ifp->if_init = rum_init; - ifp->if_ioctl = rum_ioctl; - ifp->if_start = rum_start; - ifp->if_watchdog = rum_watchdog; - ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN); -#ifdef notyet - ifq_set_ready(&ifp->if_snd); -#endif - - IEEE80211_ONOE_PARAM_SETUP(&sc->sc_onoe_param); - sc->sc_onoe_param.onoe_raise = 15; - ic->ic_ratectl.rc_st_ratectl_cap = IEEE80211_RATECTL_CAP_ONOE; - ic->ic_ratectl.rc_st_ratectl = IEEE80211_RATECTL_ONOE; - ic->ic_ratectl.rc_st_stats = rum_stats; - ic->ic_ratectl.rc_st_attach = rum_ratectl_attach; - - ieee80211_ifattach(ic); - - /* Enable software beacon missing handling. */ - ic->ic_flags_ext |= IEEE80211_FEXT_SWBMISS; - - /* override state transition machine */ - sc->sc_newstate = ic->ic_newstate; - ic->ic_newstate = rum_newstate; - ieee80211_media_init(ic, rum_media_change, ieee80211_media_status); - - bpfattach_dlt(ifp, DLT_IEEE802_11_RADIO, - sizeof(struct ieee80211_frame) + IEEE80211_RADIOTAP_HDRLEN, - &sc->sc_drvbpf); - - sc->sc_rxtap_len = sizeof sc->sc_rxtapu; - sc->sc_rxtap.wr_ihdr.it_len = htole16(sc->sc_rxtap_len); - sc->sc_rxtap.wr_ihdr.it_present = htole32(RT2573_RX_RADIOTAP_PRESENT); - - sc->sc_txtap_len = sizeof sc->sc_txtapu; - sc->sc_txtap.wt_ihdr.it_len = htole16(sc->sc_txtap_len); - sc->sc_txtap.wt_ihdr.it_present = htole32(RT2573_TX_RADIOTAP_PRESENT); - - if (bootverbose) - ieee80211_announce(ic); - - return 0; -} - -static int -rum_detach(device_t self) -{ - struct rum_softc *sc = device_get_softc(self); - struct ifnet *ifp = &sc->sc_ic.ic_if; -#ifdef INVARIANTS - int i; -#endif - - crit_enter(); - - callout_stop(&sc->scan_ch); - callout_stop(&sc->stats_ch); - - lwkt_serialize_enter(ifp->if_serializer); - rum_stop(sc); - lwkt_serialize_exit(ifp->if_serializer); - - usb_rem_task(sc->sc_udev, &sc->sc_task); - - bpfdetach(ifp); - ieee80211_ifdetach(&sc->sc_ic); /* free all nodes */ - - crit_exit(); - - KKASSERT(sc->stats_xfer == NULL); - KKASSERT(sc->sc_rx_pipeh == NULL); - KKASSERT(sc->sc_tx_pipeh == NULL); - -#ifdef INVARIANTS - /* - * Make sure TX/RX list is empty - */ - for (i = 0; i < RT2573_TX_LIST_COUNT; i++) { - struct rum_tx_data *data = &sc->tx_data[i]; - - KKASSERT(data->xfer == NULL); - KKASSERT(data->ni == NULL); - KKASSERT(data->m == NULL); - } - for (i = 0; i < RT2573_RX_LIST_COUNT; i++) { - struct rum_rx_data *data = &sc->rx_data[i]; - - KKASSERT(data->xfer == NULL); - KKASSERT(data->m == NULL); - } -#endif - return 0; -} - -static int -rum_alloc_tx_list(struct rum_softc *sc) -{ - int i; - - sc->tx_queued = 0; - for (i = 0; i < RT2573_TX_LIST_COUNT; i++) { - struct rum_tx_data *data = &sc->tx_data[i]; - - data->sc = sc; - - data->xfer = usbd_alloc_xfer(sc->sc_udev); - if (data->xfer == NULL) { - kprintf("%s: could not allocate tx xfer\n", - device_get_nameunit(sc->sc_dev)); - return ENOMEM; - } - - data->buf = usbd_alloc_buffer(data->xfer, - RT2573_TX_DESC_SIZE + IEEE80211_MAX_LEN); - if (data->buf == NULL) { - kprintf("%s: could not allocate tx buffer\n", - device_get_nameunit(sc->sc_dev)); - return ENOMEM; - } - - /* clean Tx descriptor */ - bzero(data->buf, RT2573_TX_DESC_SIZE); - } - return 0; -} - -static void -rum_free_tx_list(struct rum_softc *sc) -{ - int i; - - for (i = 0; i < RT2573_TX_LIST_COUNT; i++) { - struct rum_tx_data *data = &sc->tx_data[i]; - - if (data->xfer != NULL) { - usbd_free_xfer(data->xfer); - data->xfer = NULL; - } - if (data->ni != NULL) { - ieee80211_free_node(data->ni); - data->ni = NULL; - } - if (data->m != NULL) { - m_freem(data->m); - data->m = NULL; - } - } - sc->tx_queued = 0; -} - -static int -rum_alloc_rx_list(struct rum_softc *sc) -{ - int i; - - for (i = 0; i < RT2573_RX_LIST_COUNT; i++) { - struct rum_rx_data *data = &sc->rx_data[i]; - - data->sc = sc; - - data->xfer = usbd_alloc_xfer(sc->sc_udev); - if (data->xfer == NULL) { - kprintf("%s: could not allocate rx xfer\n", - device_get_nameunit(sc->sc_dev)); - return ENOMEM; - } - - if (usbd_alloc_buffer(data->xfer, MCLBYTES) == NULL) { - kprintf("%s: could not allocate rx buffer\n", - device_get_nameunit(sc->sc_dev)); - return ENOMEM; - } - - data->m = m_getcl(MB_WAIT, MT_DATA, M_PKTHDR); - - data->buf = mtod(data->m, uint8_t *); - bzero(data->buf, sizeof(struct rum_rx_desc)); - } - return 0; -} - -static void -rum_free_rx_list(struct rum_softc *sc) -{ - int i; - - for (i = 0; i < RT2573_RX_LIST_COUNT; i++) { - struct rum_rx_data *data = &sc->rx_data[i]; - - if (data->xfer != NULL) { - usbd_free_xfer(data->xfer); - data->xfer = NULL; - } - if (data->m != NULL) { - m_freem(data->m); - data->m = NULL; - } - } -} - -static int -rum_media_change(struct ifnet *ifp) -{ - int error; - - error = ieee80211_media_change(ifp); - if (error != ENETRESET) - return error; - - if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) == (IFF_UP | IFF_RUNNING)) - rum_init(ifp->if_softc); - - return 0; -} - -/* - * This function is called periodically (every 200ms) during scanning to - * switch from one channel to another. - */ -static void -rum_next_scan(void *arg) -{ - struct rum_softc *sc = arg; - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - - if (sc->sc_stopped) - return; - - crit_enter(); - - if (ic->ic_state == IEEE80211_S_SCAN) { - lwkt_serialize_enter(ifp->if_serializer); - ieee80211_next_scan(ic); - lwkt_serialize_exit(ifp->if_serializer); - } - - crit_exit(); -} - -static void -rum_task(void *xarg) -{ - struct rum_softc *sc = xarg; - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - enum ieee80211_state nstate; - struct ieee80211_node *ni; - int arg; - - if (sc->sc_stopped) - return; - - crit_enter(); - - nstate = sc->sc_state; - arg = sc->sc_arg; - - KASSERT(nstate != IEEE80211_S_INIT, - ("->INIT state transition should not be defered\n")); - rum_set_chan(sc, ic->ic_curchan); - - switch (nstate) { - case IEEE80211_S_RUN: - ni = ic->ic_bss; - - if (ic->ic_opmode != IEEE80211_M_MONITOR) { - rum_update_slot(sc); - rum_enable_mrr(sc); - rum_set_txpreamble(sc); - rum_set_basicrates(sc); - rum_set_bssid(sc, ni->ni_bssid); - } - - if (ic->ic_opmode == IEEE80211_M_HOSTAP || - ic->ic_opmode == IEEE80211_M_IBSS) - rum_prepare_beacon(sc); - - if (ic->ic_opmode != IEEE80211_M_MONITOR) - rum_enable_tsf_sync(sc); - - /* clear statistic registers (STA_CSR0 to STA_CSR5) */ - rum_read_multi(sc, RT2573_STA_CSR0, sc->sta, sizeof(sc->sta)); - callout_reset(&sc->stats_ch, 4 * hz / 5, rum_stats_timeout, sc); - break; - - case IEEE80211_S_SCAN: - callout_reset(&sc->scan_ch, hz / 5, rum_next_scan, sc); - break; - - default: - break; - } - - lwkt_serialize_enter(ifp->if_serializer); - ieee80211_ratectl_newstate(ic, nstate); - sc->sc_newstate(ic, nstate, arg); - lwkt_serialize_exit(ifp->if_serializer); - - crit_exit(); -} - -static int -rum_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg) -{ - struct rum_softc *sc = ic->ic_if.if_softc; - struct ifnet *ifp = &ic->ic_if; - - crit_enter(); - - ASSERT_SERIALIZED(ifp->if_serializer); - - callout_stop(&sc->scan_ch); - callout_stop(&sc->stats_ch); - - /* do it in a process context */ - sc->sc_state = nstate; - sc->sc_arg = arg; - - lwkt_serialize_exit(ifp->if_serializer); - usb_rem_task(sc->sc_udev, &sc->sc_task); - - if (nstate == IEEE80211_S_INIT) { - lwkt_serialize_enter(ifp->if_serializer); - ieee80211_ratectl_newstate(ic, nstate); - sc->sc_newstate(ic, nstate, arg); - } else { - usb_add_task(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER); - lwkt_serialize_enter(ifp->if_serializer); - } - - crit_exit(); - return 0; -} - -/* quickly determine if a given rate is CCK or OFDM */ -#define RUM_RATE_IS_OFDM(rate) ((rate) >= 12 && (rate) != 22) - -#define RUM_ACK_SIZE (sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN) - -static void -rum_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) -{ - struct rum_tx_data *data = priv; - struct rum_softc *sc = data->sc; - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - struct ieee80211_node *ni; - - if (sc->sc_stopped) - return; - - crit_enter(); - - if (status != USBD_NORMAL_COMPLETION) { - if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { - crit_exit(); - return; - } - - kprintf("%s: could not transmit buffer: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(status)); - - if (status == USBD_STALLED) - usbd_clear_endpoint_stall_async(sc->sc_tx_pipeh); - - IFNET_STAT_INC(ifp, oerrors, 1); - crit_exit(); - return; - } - - m_freem(data->m); - data->m = NULL; - ni = data->ni; - data->ni = NULL; - - bzero(data->buf, sizeof(struct rum_tx_data)); - sc->tx_queued--; - IFNET_STAT_INC(ifp, opackets, 1); /* XXX may fail too */ - - DPRINTFN(10, ("tx done\n")); - - sc->sc_tx_timer = 0; - ifq_clr_oactive(&ifp->if_snd); - - lwkt_serialize_enter(ifp->if_serializer); - ieee80211_free_node(ni); - ifp->if_start(ifp); - lwkt_serialize_exit(ifp->if_serializer); - - crit_exit(); -} - -static void -rum_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) -{ - struct rum_rx_data *data = priv; - struct rum_softc *sc = data->sc; - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - struct rum_rx_desc *desc; - struct ieee80211_frame_min *wh; - struct ieee80211_node *ni; - struct mbuf *mnew, *m; - int len, rssi; - - if (sc->sc_stopped) - return; - - crit_enter(); - - if (status != USBD_NORMAL_COMPLETION) { - if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { - crit_exit(); - return; - } - - if (status == USBD_STALLED) - usbd_clear_endpoint_stall_async(sc->sc_rx_pipeh); - goto skip; - } - - usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL); - - if (len < RT2573_RX_DESC_SIZE + sizeof(struct ieee80211_frame_min)) { - DPRINTF(("%s: xfer too short %d\n", device_get_nameunit(sc->sc_dev), - len)); - IFNET_STAT_INC(ifp, ierrors, 1); - goto skip; - } - - desc = (struct rum_rx_desc *)data->buf; - - if (le32toh(desc->flags) & RT2573_RX_CRC_ERROR) { - /* - * This should not happen since we did not request to receive - * those frames when we filled RT2573_TXRX_CSR0. - */ - DPRINTFN(5, ("CRC error\n")); - IFNET_STAT_INC(ifp, ierrors, 1); - goto skip; - } - - mnew = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR); - if (mnew == NULL) { - kprintf("%s: could not allocate rx mbuf\n", - device_get_nameunit(sc->sc_dev)); - IFNET_STAT_INC(ifp, ierrors, 1); - goto skip; - } - - m = data->m; - data->m = NULL; - data->buf = NULL; - - lwkt_serialize_enter(ifp->if_serializer); - - /* finalize mbuf */ - m->m_pkthdr.rcvif = ifp; - m->m_data = (caddr_t)(desc + 1); - m->m_pkthdr.len = m->m_len = (le32toh(desc->flags) >> 16) & 0xfff; - - rssi = rum_get_rssi(sc, desc->rssi); - - wh = mtod(m, struct ieee80211_frame_min *); - ni = ieee80211_find_rxnode(ic, wh); - - /* Error happened during RSSI conversion. */ - if (rssi < 0) - rssi = ni->ni_rssi; - - if (sc->sc_drvbpf != NULL) { - struct rum_rx_radiotap_header *tap = &sc->sc_rxtap; - - tap->wr_flags = 0; - tap->wr_rate = rum_rxrate(desc); - tap->wr_chan_freq = htole16(ic->ic_bss->ni_chan->ic_freq); - tap->wr_chan_flags = htole16(ic->ic_bss->ni_chan->ic_flags); - tap->wr_antenna = sc->rx_ant; - tap->wr_antsignal = rssi; - - bpf_ptap(sc->sc_drvbpf, m, tap, sc->sc_rxtap_len); - } - - /* send the frame to the 802.11 layer */ - ieee80211_input(ic, m, ni, rssi, 0); - - /* node is no longer needed */ - ieee80211_free_node(ni); - - if (!ifq_is_oactive(&ifp->if_snd)) - ifp->if_start(ifp); - - lwkt_serialize_exit(ifp->if_serializer); - - data->m = mnew; - data->buf = mtod(data->m, uint8_t *); - - DPRINTFN(15, ("rx done\n")); - -skip: /* setup a new transfer */ - bzero(data->buf, sizeof(struct rum_rx_desc)); - usbd_setup_xfer(xfer, sc->sc_rx_pipeh, data, data->buf, MCLBYTES, - USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, rum_rxeof); - usbd_transfer(xfer); - - crit_exit(); -} - -/* - * This function is only used by the Rx radiotap code. It returns the rate at - * which a given frame was received. - */ -static uint8_t -rum_rxrate(struct rum_rx_desc *desc) -{ - if (le32toh(desc->flags) & RT2573_RX_OFDM) { - /* reverse function of rum_plcp_signal */ - switch (desc->rate) { - case 0xb: return 12; - case 0xf: return 18; - case 0xa: return 24; - case 0xe: return 36; - case 0x9: return 48; - case 0xd: return 72; - case 0x8: return 96; - case 0xc: return 108; - } - } else { - if (desc->rate == 10) - return 2; - if (desc->rate == 20) - return 4; - if (desc->rate == 55) - return 11; - if (desc->rate == 110) - return 22; - } - return 2; /* should not get there */ -} - -static uint8_t -rum_plcp_signal(int rate) -{ - switch (rate) { - /* CCK rates (returned values are device-dependent) */ - case 2: return 0x0; - case 4: return 0x1; - case 11: return 0x2; - case 22: return 0x3; - - /* OFDM rates (cf IEEE Std 802.11a-1999, pp. 14 Table 80) */ - case 12: return 0xb; - case 18: return 0xf; - case 24: return 0xa; - case 36: return 0xe; - case 48: return 0x9; - case 72: return 0xd; - case 96: return 0x8; - case 108: return 0xc; - - /* unsupported rates (should not get there) */ - default: return 0xff; - } -} - -static void -rum_setup_tx_desc(struct rum_softc *sc, struct rum_tx_desc *desc, - uint32_t flags, uint16_t xflags, int len, int rate) -{ - struct ieee80211com *ic = &sc->sc_ic; - uint16_t plcp_length; - int remainder; - - desc->flags = htole32(flags); - desc->flags |= htole32(len << 16); - - desc->xflags = htole16(xflags); - - desc->wme = htole16( - RT2573_QID(0) | - RT2573_AIFSN(2) | - RT2573_LOGCWMIN(4) | - RT2573_LOGCWMAX(10)); - - /* setup PLCP fields */ - desc->plcp_signal = rum_plcp_signal(rate); - desc->plcp_service = 4; - - len += IEEE80211_CRC_LEN; - if (RUM_RATE_IS_OFDM(rate)) { - desc->flags |= htole32(RT2573_TX_OFDM); - - plcp_length = len & 0xfff; - desc->plcp_length_hi = plcp_length >> 6; - desc->plcp_length_lo = plcp_length & 0x3f; - } else { - plcp_length = (16 * len + rate - 1) / rate; - if (rate == 22) { - remainder = (16 * len) % 22; - if (remainder != 0 && remainder < 7) - desc->plcp_service |= RT2573_PLCP_LENGEXT; - } - desc->plcp_length_hi = plcp_length >> 8; - desc->plcp_length_lo = plcp_length & 0xff; - - if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) - desc->plcp_signal |= 0x08; - } - desc->flags |= htole32(RT2573_TX_VALID); -} - -#define RUM_TX_TIMEOUT 5000 - -static int -rum_tx_data(struct rum_softc *sc, struct mbuf *m0, struct ieee80211_node *ni) -{ - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - struct rum_tx_desc *desc; - struct rum_tx_data *data; - struct ieee80211_frame *wh; - uint32_t flags = 0; - uint16_t dur; - usbd_status error; - int xferlen, rate, rateidx; - - wh = mtod(m0, struct ieee80211_frame *); - - if (wh->i_fc[1] & IEEE80211_FC1_WEP) { - if (ieee80211_crypto_encap(ic, ni, m0) == NULL) { - m_freem(m0); - return ENOBUFS; - } - - /* packet header may have moved, reset our local pointer */ - wh = mtod(m0, struct ieee80211_frame *); - } - - /* pickup a rate */ - if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == - IEEE80211_FC0_TYPE_MGT) { - /* mgmt frames are sent at the lowest available bit-rate */ - rateidx = 0; - } else { - ieee80211_ratectl_findrate(ni, m0->m_pkthdr.len, &rateidx, 1); - } - rate = IEEE80211_RS_RATE(&ni->ni_rates, rateidx); - - data = &sc->tx_data[0]; - desc = (struct rum_tx_desc *)data->buf; - - data->m = m0; - data->ni = ni; - - if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { - flags |= RT2573_TX_ACK; - - dur = ieee80211_txtime(ni, RUM_ACK_SIZE, - ieee80211_ack_rate(ni, rate), ic->ic_flags) + - sc->sc_sifs; - *(uint16_t *)wh->i_dur = htole16(dur); - - /* tell hardware to set timestamp in probe responses */ - if ((wh->i_fc[0] & - (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) == - (IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_RESP)) - flags |= RT2573_TX_TIMESTAMP; - } - - if (sc->sc_drvbpf != NULL) { - struct rum_tx_radiotap_header *tap = &sc->sc_txtap; - - tap->wt_flags = 0; - tap->wt_rate = rate; - tap->wt_chan_freq = htole16(ic->ic_bss->ni_chan->ic_freq); - tap->wt_chan_flags = htole16(ic->ic_bss->ni_chan->ic_flags); - tap->wt_antenna = sc->tx_ant; - - bpf_ptap(sc->sc_drvbpf, m0, tap, sc->sc_txtap_len); - } - - m_copydata(m0, 0, m0->m_pkthdr.len, data->buf + RT2573_TX_DESC_SIZE); - rum_setup_tx_desc(sc, desc, flags, 0, m0->m_pkthdr.len, rate); - - /* Align end on a 4-bytes boundary */ - xferlen = roundup(RT2573_TX_DESC_SIZE + m0->m_pkthdr.len, 4); - - /* - * No space left in the last URB to store the extra 4 bytes, force - * sending of another URB. - */ - if ((xferlen % 64) == 0) - xferlen += 4; - - DPRINTFN(10, ("sending frame len=%u rate=%u xfer len=%u\n", - m0->m_pkthdr.len + RT2573_TX_DESC_SIZE, rate, xferlen)); - - lwkt_serialize_exit(ifp->if_serializer); - - usbd_setup_xfer(data->xfer, sc->sc_tx_pipeh, data, data->buf, xferlen, - USBD_FORCE_SHORT_XFER | USBD_NO_COPY, RUM_TX_TIMEOUT, rum_txeof); - - error = usbd_transfer(data->xfer); - if (error != USBD_NORMAL_COMPLETION && error != USBD_IN_PROGRESS) { - m_freem(m0); - data->m = NULL; - data->ni = NULL; - } else { - sc->tx_queued++; - error = 0; - } - - lwkt_serialize_enter(ifp->if_serializer); - return error; -} - -static void -rum_start(struct ifnet *ifp, struct ifaltq_subque *ifsq) -{ - struct rum_softc *sc = ifp->if_softc; - struct ieee80211com *ic = &sc->sc_ic; - - ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq); - ASSERT_SERIALIZED(ifp->if_serializer); - - if (sc->sc_stopped) { - ifq_purge(&ifp->if_snd); - return; - } - - crit_enter(); - - if ((ifp->if_flags & IFF_RUNNING) == 0 || - ifq_is_oactive(&ifp->if_snd)) { - crit_exit(); - return; - } - - for (;;) { - struct ieee80211_node *ni; - struct mbuf *m0; - - if (!IF_QEMPTY(&ic->ic_mgtq)) { - if (sc->tx_queued >= RT2573_TX_LIST_COUNT) { - ifq_set_oactive(&ifp->if_snd); - break; - } - IF_DEQUEUE(&ic->ic_mgtq, m0); - - ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif; - m0->m_pkthdr.rcvif = NULL; - - BPF_MTAP(ifp, m0); - - if (rum_tx_data(sc, m0, ni) != 0) { - ieee80211_free_node(ni); - break; - } - } else { - struct ether_header *eh; - - if (ic->ic_state != IEEE80211_S_RUN) { - ifq_purge(&ifp->if_snd); - break; - } - - if (sc->tx_queued >= RT2573_TX_LIST_COUNT) { - ifq_set_oactive(&ifp->if_snd); - break; - } - - m0 = ifq_dequeue(&ifp->if_snd); - if (m0 == NULL) - break; - - if (m0->m_len < sizeof(struct ether_header)) { - m0 = m_pullup(m0, sizeof(struct ether_header)); - if (m0 == NULL) { - IFNET_STAT_INC(ifp, oerrors, 1); - continue; - } - } - eh = mtod(m0, struct ether_header *); - - ni = ieee80211_find_txnode(ic, eh->ether_dhost); - if (ni == NULL) { - m_freem(m0); - continue; - } - - BPF_MTAP(ifp, m0); - - m0 = ieee80211_encap(ic, m0, ni); - if (m0 == NULL) { - ieee80211_free_node(ni); - continue; - } - - if (ic->ic_rawbpf != NULL) - bpf_mtap(ic->ic_rawbpf, m0); - - if (rum_tx_data(sc, m0, ni) != 0) { - ieee80211_free_node(ni); - IFNET_STAT_INC(ifp, oerrors, 1); - break; - } - } - - sc->sc_tx_timer = 5; - ifp->if_timer = 1; - } - - crit_exit(); -} - -static void -rum_watchdog(struct ifnet *ifp) -{ - struct rum_softc *sc = ifp->if_softc; - - ASSERT_SERIALIZED(ifp->if_serializer); - - crit_enter(); - - ifp->if_timer = 0; - - if (sc->sc_tx_timer > 0) { - if (--sc->sc_tx_timer == 0) { - kprintf("%s: device timeout\n", device_get_nameunit(sc->sc_dev)); - /*rum_init(sc); XXX needs a process context! */ - IFNET_STAT_INC(ifp, oerrors, 1); - - crit_exit(); - return; - } - ifp->if_timer = 1; - } - - ieee80211_watchdog(&sc->sc_ic); - - crit_exit(); -} - -static int -rum_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) -{ - struct rum_softc *sc = ifp->if_softc; - struct ieee80211com *ic = &sc->sc_ic; - int error = 0; - - ASSERT_SERIALIZED(ifp->if_serializer); - - crit_enter(); - - switch (cmd) { - case SIOCSIFFLAGS: - if (ifp->if_flags & IFF_UP) { - if (ifp->if_flags & IFF_RUNNING) { - lwkt_serialize_exit(ifp->if_serializer); - rum_update_promisc(sc); - lwkt_serialize_enter(ifp->if_serializer); - } else { - rum_init(sc); - } - } else { - if (ifp->if_flags & IFF_RUNNING) - rum_stop(sc); - } - break; - default: - error = ieee80211_ioctl(ic, cmd, data, cr); - break; - } - - if (error == ENETRESET) { - struct ieee80211req *ireq = (struct ieee80211req *)data; - - if (cmd == SIOCS80211 && - ireq->i_type == IEEE80211_IOC_CHANNEL && - ic->ic_opmode == IEEE80211_M_MONITOR) { - /* - * This allows for fast channel switching in monitor - * mode (used by kismet). In IBSS mode, we must - * explicitly reset the interface to generate a new - * beacon frame. - */ - lwkt_serialize_exit(ifp->if_serializer); - rum_set_chan(sc, ic->ic_ibss_chan); - lwkt_serialize_enter(ifp->if_serializer); - } else if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) == - (IFF_UP | IFF_RUNNING)) { - rum_init(sc); - } - error = 0; - } - - crit_exit(); - return error; -} - -static void -rum_eeprom_read(struct rum_softc *sc, uint16_t addr, void *buf, int len) -{ - usb_device_request_t req; - usbd_status error; - - req.bmRequestType = UT_READ_VENDOR_DEVICE; - req.bRequest = RT2573_READ_EEPROM; - USETW(req.wValue, 0); - USETW(req.wIndex, addr); - USETW(req.wLength, len); - - error = usbd_do_request(sc->sc_udev, &req, buf); - if (error != 0) { - kprintf("%s: could not read EEPROM: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(error)); - } -} - -static uint32_t -rum_read(struct rum_softc *sc, uint16_t reg) -{ - uint32_t val; - - rum_read_multi(sc, reg, &val, sizeof val); - - return le32toh(val); -} - -static void -rum_read_multi(struct rum_softc *sc, uint16_t reg, void *buf, int len) -{ - usb_device_request_t req; - usbd_status error; - - req.bmRequestType = UT_READ_VENDOR_DEVICE; - req.bRequest = RT2573_READ_MULTI_MAC; - USETW(req.wValue, 0); - USETW(req.wIndex, reg); - USETW(req.wLength, len); - - error = usbd_do_request(sc->sc_udev, &req, buf); - if (error != 0) { - kprintf("%s: could not multi read MAC register: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(error)); - } -} - -static void -rum_write(struct rum_softc *sc, uint16_t reg, uint32_t val) -{ - uint32_t tmp = htole32(val); - - rum_write_multi(sc, reg, &tmp, sizeof tmp); -} - -static void -rum_write_multi(struct rum_softc *sc, uint16_t reg, void *buf, size_t len) -{ - usb_device_request_t req; - usbd_status error; - - req.bmRequestType = UT_WRITE_VENDOR_DEVICE; - req.bRequest = RT2573_WRITE_MULTI_MAC; - USETW(req.wValue, 0); - USETW(req.wIndex, reg); - USETW(req.wLength, len); - - error = usbd_do_request(sc->sc_udev, &req, buf); - if (error != 0) { - kprintf("%s: could not multi write MAC register: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(error)); - } -} - -static void -rum_bbp_write(struct rum_softc *sc, uint8_t reg, uint8_t val) -{ - uint32_t tmp; - int ntries; - - for (ntries = 0; ntries < 5; ntries++) { - if (!(rum_read(sc, RT2573_PHY_CSR3) & RT2573_BBP_BUSY)) - break; - } - if (ntries == 5) { - kprintf("%s: could not write to BBP\n", device_get_nameunit(sc->sc_dev)); - return; - } - - tmp = RT2573_BBP_BUSY | (reg & 0x7f) << 8 | val; - rum_write(sc, RT2573_PHY_CSR3, tmp); -} - -static uint8_t -rum_bbp_read(struct rum_softc *sc, uint8_t reg) -{ - uint32_t val; - int ntries; - - for (ntries = 0; ntries < 5; ntries++) { - if (!(rum_read(sc, RT2573_PHY_CSR3) & RT2573_BBP_BUSY)) - break; - } - if (ntries == 5) { - kprintf("%s: could not read BBP\n", device_get_nameunit(sc->sc_dev)); - return 0; - } - - val = RT2573_BBP_BUSY | RT2573_BBP_READ | reg << 8; - rum_write(sc, RT2573_PHY_CSR3, val); - - for (ntries = 0; ntries < 100; ntries++) { - val = rum_read(sc, RT2573_PHY_CSR3); - if (!(val & RT2573_BBP_BUSY)) - return val & 0xff; - DELAY(1); - } - - kprintf("%s: could not read BBP\n", device_get_nameunit(sc->sc_dev)); - return 0; -} - -static void -rum_rf_write(struct rum_softc *sc, uint8_t reg, uint32_t val) -{ - uint32_t tmp; - int ntries; - - for (ntries = 0; ntries < 5; ntries++) { - if (!(rum_read(sc, RT2573_PHY_CSR4) & RT2573_RF_BUSY)) - break; - } - if (ntries == 5) { - kprintf("%s: could not write to RF\n", device_get_nameunit(sc->sc_dev)); - return; - } - - tmp = RT2573_RF_BUSY | RT2573_RF_20BIT | (val & 0xfffff) << 2 | - (reg & 3); - rum_write(sc, RT2573_PHY_CSR4, tmp); - - /* remember last written value in sc */ - sc->rf_regs[reg] = val; - - DPRINTFN(15, ("RF R[%u] <- 0x%05x\n", reg & 3, val & 0xfffff)); -} - -static void -rum_select_antenna(struct rum_softc *sc) -{ - uint8_t bbp4, bbp77; - uint32_t tmp; - - bbp4 = rum_bbp_read(sc, 4); - bbp77 = rum_bbp_read(sc, 77); - - /* TBD */ - - /* make sure Rx is disabled before switching antenna */ - tmp = rum_read(sc, RT2573_TXRX_CSR0); - rum_write(sc, RT2573_TXRX_CSR0, tmp | RT2573_DISABLE_RX); - - rum_bbp_write(sc, 4, bbp4); - rum_bbp_write(sc, 77, bbp77); - - rum_write(sc, RT2573_TXRX_CSR0, tmp); -} - -/* - * Enable multi-rate retries for frames sent at OFDM rates. - * In 802.11b/g mode, allow fallback to CCK rates. - */ -static void -rum_enable_mrr(struct rum_softc *sc) -{ - struct ieee80211com *ic = &sc->sc_ic; - uint32_t tmp; - - tmp = rum_read(sc, RT2573_TXRX_CSR4); - - tmp &= ~RT2573_MRR_CCK_FALLBACK; - if (!IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan)) - tmp |= RT2573_MRR_CCK_FALLBACK; - tmp |= RT2573_MRR_ENABLED; - - rum_write(sc, RT2573_TXRX_CSR4, tmp); -} - -static void -rum_set_txpreamble(struct rum_softc *sc) -{ - uint32_t tmp; - - tmp = rum_read(sc, RT2573_TXRX_CSR4); - - tmp &= ~RT2573_SHORT_PREAMBLE; - if (sc->sc_ic.ic_flags & IEEE80211_F_SHPREAMBLE) - tmp |= RT2573_SHORT_PREAMBLE; - - rum_write(sc, RT2573_TXRX_CSR4, tmp); -} - -static void -rum_set_basicrates(struct rum_softc *sc) -{ - struct ieee80211com *ic = &sc->sc_ic; - - /* update basic rate set */ - if (ic->ic_curmode == IEEE80211_MODE_11B) { - /* 11b basic rates: 1, 2Mbps */ - rum_write(sc, RT2573_TXRX_CSR5, 0x3); - } else if (IEEE80211_IS_CHAN_5GHZ(ic->ic_bss->ni_chan)) { - /* 11a basic rates: 6, 12, 24Mbps */ - rum_write(sc, RT2573_TXRX_CSR5, 0x150); - } else { - /* 11g basic rates: 1, 2, 5.5, 11, 6, 12, 24Mbps */ - rum_write(sc, RT2573_TXRX_CSR5, 0x15f); - } -} - -/* - * Reprogram MAC/BBP to switch to a new band. Values taken from the reference - * driver. - */ -static void -rum_select_band(struct rum_softc *sc, struct ieee80211_channel *c) -{ - uint8_t bbp17, bbp35, bbp96, bbp97, bbp98, bbp104; - uint32_t tmp; - - /* update all BBP registers that depend on the band */ - bbp17 = 0x20; bbp96 = 0x48; bbp104 = 0x2c; - bbp35 = 0x50; bbp97 = 0x48; bbp98 = 0x48; - if (IEEE80211_IS_CHAN_5GHZ(c)) { - bbp17 += 0x08; bbp96 += 0x10; bbp104 += 0x0c; - bbp35 += 0x10; bbp97 += 0x10; bbp98 += 0x10; - } - if ((IEEE80211_IS_CHAN_2GHZ(c) && sc->ext_2ghz_lna) || - (IEEE80211_IS_CHAN_5GHZ(c) && sc->ext_5ghz_lna)) { - bbp17 += 0x10; bbp96 += 0x10; bbp104 += 0x10; - } - - sc->bbp17 = bbp17; - rum_bbp_write(sc, 17, bbp17); - rum_bbp_write(sc, 96, bbp96); - rum_bbp_write(sc, 104, bbp104); - - if ((IEEE80211_IS_CHAN_2GHZ(c) && sc->ext_2ghz_lna) || - (IEEE80211_IS_CHAN_5GHZ(c) && sc->ext_5ghz_lna)) { - rum_bbp_write(sc, 75, 0x80); - rum_bbp_write(sc, 86, 0x80); - rum_bbp_write(sc, 88, 0x80); - } - - rum_bbp_write(sc, 35, bbp35); - rum_bbp_write(sc, 97, bbp97); - rum_bbp_write(sc, 98, bbp98); - - tmp = rum_read(sc, RT2573_PHY_CSR0); - tmp &= ~(RT2573_PA_PE_2GHZ | RT2573_PA_PE_5GHZ); - if (IEEE80211_IS_CHAN_2GHZ(c)) - tmp |= RT2573_PA_PE_2GHZ; - else - tmp |= RT2573_PA_PE_5GHZ; - rum_write(sc, RT2573_PHY_CSR0, tmp); -} - -static void -rum_set_chan(struct rum_softc *sc, struct ieee80211_channel *c) -{ - struct ieee80211com *ic = &sc->sc_ic; - const struct rfprog *rfprog; - uint8_t bbp3, bbp94 = RT2573_BBPR94_DEFAULT; - int8_t power; - u_int i, chan; - - chan = ieee80211_chan2ieee(ic, c); - if (chan == 0 || chan == IEEE80211_CHAN_ANY) - return; - - /* select the appropriate RF settings based on what EEPROM says */ - rfprog = (sc->rf_rev == RT2573_RF_5225 || - sc->rf_rev == RT2573_RF_2527) ? rum_rf5225 : rum_rf5226; - - /* find the settings for this channel (we know it exists) */ - for (i = 0; rfprog[i].chan != chan; i++) - ; /* EMPTY */ - - power = sc->txpow[i]; - if (power < 0) { - bbp94 += power; - power = 0; - } else if (power > 31) { - bbp94 += power - 31; - power = 31; - } - - /* - * If we are switching from the 2GHz band to the 5GHz band or - * vice-versa, BBP registers need to be reprogrammed. - */ - if (c->ic_flags != sc->sc_curchan->ic_flags) { - rum_select_band(sc, c); - rum_select_antenna(sc); - } - sc->sc_curchan = c; - - rum_rf_write(sc, RT2573_RF1, rfprog[i].r1); - rum_rf_write(sc, RT2573_RF2, rfprog[i].r2); - rum_rf_write(sc, RT2573_RF3, rfprog[i].r3 | power << 7); - rum_rf_write(sc, RT2573_RF4, rfprog[i].r4 | sc->rffreq << 10); - - rum_rf_write(sc, RT2573_RF1, rfprog[i].r1); - rum_rf_write(sc, RT2573_RF2, rfprog[i].r2); - rum_rf_write(sc, RT2573_RF3, rfprog[i].r3 | power << 7 | 1); - rum_rf_write(sc, RT2573_RF4, rfprog[i].r4 | sc->rffreq << 10); - - rum_rf_write(sc, RT2573_RF1, rfprog[i].r1); - rum_rf_write(sc, RT2573_RF2, rfprog[i].r2); - rum_rf_write(sc, RT2573_RF3, rfprog[i].r3 | power << 7); - rum_rf_write(sc, RT2573_RF4, rfprog[i].r4 | sc->rffreq << 10); - - DELAY(10); - - /* enable smart mode for MIMO-capable RFs */ - bbp3 = rum_bbp_read(sc, 3); - - if (sc->rf_rev == RT2573_RF_5225 || sc->rf_rev == RT2573_RF_2527) - bbp3 &= ~RT2573_SMART_MODE; - else - bbp3 |= RT2573_SMART_MODE; - - rum_bbp_write(sc, 3, bbp3); - - if (bbp94 != RT2573_BBPR94_DEFAULT) - rum_bbp_write(sc, 94, bbp94); - - sc->sc_sifs = IEEE80211_IS_CHAN_5GHZ(c) ? IEEE80211_DUR_OFDM_SIFS - : IEEE80211_DUR_SIFS; -} - -/* - * Enable TSF synchronization and tell h/w to start sending beacons for IBSS - * and HostAP operating modes. - */ -static void -rum_enable_tsf_sync(struct rum_softc *sc) -{ - struct ieee80211com *ic = &sc->sc_ic; - uint32_t tmp; - - if (ic->ic_opmode != IEEE80211_M_STA) { - /* - * Change default 16ms TBTT adjustment to 8ms. - * Must be done before enabling beacon generation. - */ - rum_write(sc, RT2573_TXRX_CSR10, 1 << 12 | 8); - } - - tmp = rum_read(sc, RT2573_TXRX_CSR9) & 0xff000000; - - /* set beacon interval (in 1/16ms unit) */ - tmp |= ic->ic_bss->ni_intval * 16; - - tmp |= RT2573_TSF_TICKING | RT2573_ENABLE_TBTT; - if (ic->ic_opmode == IEEE80211_M_STA) - tmp |= RT2573_TSF_MODE(1); - else - tmp |= RT2573_TSF_MODE(2) | RT2573_GENERATE_BEACON; - - rum_write(sc, RT2573_TXRX_CSR9, tmp); -} - -static void -rum_update_slot(struct rum_softc *sc) -{ - struct ieee80211com *ic = &sc->sc_ic; - uint8_t slottime; - uint32_t tmp; - - slottime = (ic->ic_flags & IEEE80211_F_SHSLOT) ? 9 : 20; - - tmp = rum_read(sc, RT2573_MAC_CSR9); - tmp = (tmp & ~0xff) | slottime; - rum_write(sc, RT2573_MAC_CSR9, tmp); - - DPRINTF(("setting slot time to %uus\n", slottime)); -} - -static void -rum_set_bssid(struct rum_softc *sc, const uint8_t *bssid) -{ - uint32_t tmp; - - tmp = bssid[0] | bssid[1] << 8 | bssid[2] << 16 | bssid[3] << 24; - rum_write(sc, RT2573_MAC_CSR4, tmp); - - tmp = bssid[4] | bssid[5] << 8 | RT2573_ONE_BSSID << 16; - rum_write(sc, RT2573_MAC_CSR5, tmp); -} - -static void -rum_set_macaddr(struct rum_softc *sc, const uint8_t *addr) -{ - uint32_t tmp; - - tmp = addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24; - rum_write(sc, RT2573_MAC_CSR2, tmp); - - tmp = addr[4] | addr[5] << 8 | 0xff << 16; - rum_write(sc, RT2573_MAC_CSR3, tmp); -} - -static void -rum_update_promisc(struct rum_softc *sc) -{ - struct ifnet *ifp = &sc->sc_ic.ic_if; - uint32_t tmp; - - tmp = rum_read(sc, RT2573_TXRX_CSR0); - - tmp &= ~RT2573_DROP_NOT_TO_ME; - if (!(ifp->if_flags & IFF_PROMISC)) - tmp |= RT2573_DROP_NOT_TO_ME; - - rum_write(sc, RT2573_TXRX_CSR0, tmp); - - DPRINTF(("%s promiscuous mode\n", (ifp->if_flags & IFF_PROMISC) ? - "entering" : "leaving")); -} - -static const char * -rum_get_rf(int rev) -{ - switch (rev) { - case RT2573_RF_2527: return "RT2527 (MIMO XR)"; - case RT2573_RF_2528: return "RT2528"; - case RT2573_RF_5225: return "RT5225 (MIMO XR)"; - case RT2573_RF_5226: return "RT5226"; - default: return "unknown"; - } -} - -static void -rum_read_eeprom(struct rum_softc *sc) -{ - struct ieee80211com *ic = &sc->sc_ic; - uint16_t val; -#ifdef RUM_DEBUG - int i; -#endif - - /* read MAC/BBP type */ - rum_eeprom_read(sc, RT2573_EEPROM_MACBBP, &val, 2); - sc->macbbp_rev = le16toh(val); - - /* read MAC address */ - rum_eeprom_read(sc, RT2573_EEPROM_ADDRESS, ic->ic_myaddr, 6); - - rum_eeprom_read(sc, RT2573_EEPROM_ANTENNA, &val, 2); - val = le16toh(val); - sc->rf_rev = (val >> 11) & 0x1f; - sc->hw_radio = (val >> 10) & 0x1; - sc->rx_ant = (val >> 4) & 0x3; - sc->tx_ant = (val >> 2) & 0x3; - sc->nb_ant = val & 0x3; - - DPRINTF(("RF revision=%d\n", sc->rf_rev)); - - rum_eeprom_read(sc, RT2573_EEPROM_CONFIG2, &val, 2); - val = le16toh(val); - sc->ext_5ghz_lna = (val >> 6) & 0x1; - sc->ext_2ghz_lna = (val >> 4) & 0x1; - - DPRINTF(("External 2GHz LNA=%d\nExternal 5GHz LNA=%d\n", - sc->ext_2ghz_lna, sc->ext_5ghz_lna)); - - rum_eeprom_read(sc, RT2573_EEPROM_RSSI_2GHZ_OFFSET, &val, 2); - val = le16toh(val); - if ((val & 0xff) != 0xff) - sc->rssi_2ghz_corr = (int8_t)(val & 0xff); /* signed */ - - /* Only [-10, 10] is valid */ - if (sc->rssi_2ghz_corr < -10 || sc->rssi_2ghz_corr > 10) - sc->rssi_2ghz_corr = 0; - - rum_eeprom_read(sc, RT2573_EEPROM_RSSI_5GHZ_OFFSET, &val, 2); - val = le16toh(val); - if ((val & 0xff) != 0xff) - sc->rssi_5ghz_corr = (int8_t)(val & 0xff); /* signed */ - - /* Only [-10, 10] is valid */ - if (sc->rssi_5ghz_corr < -10 || sc->rssi_5ghz_corr > 10) - sc->rssi_5ghz_corr = 0; - - if (sc->ext_2ghz_lna) - sc->rssi_2ghz_corr -= 14; - if (sc->ext_5ghz_lna) - sc->rssi_5ghz_corr -= 14; - - DPRINTF(("RSSI 2GHz corr=%d\nRSSI 5GHz corr=%d\n", - sc->rssi_2ghz_corr, sc->rssi_5ghz_corr)); - - rum_eeprom_read(sc, RT2573_EEPROM_FREQ_OFFSET, &val, 2); - val = le16toh(val); - if ((val & 0xff) != 0xff) - sc->rffreq = val & 0xff; - - DPRINTF(("RF freq=%d\n", sc->rffreq)); - - /* read Tx power for all a/b/g channels */ - rum_eeprom_read(sc, RT2573_EEPROM_TXPOWER, sc->txpow, 14); - /* XXX default Tx power for 802.11a channels */ - memset(sc->txpow + 14, 24, sizeof (sc->txpow) - 14); -#ifdef RUM_DEBUG - for (i = 0; i < 14; i++) - DPRINTF(("Channel=%d Tx power=%d\n", i + 1, sc->txpow[i])); -#endif - - /* read default values for BBP registers */ - rum_eeprom_read(sc, RT2573_EEPROM_BBP_BASE, sc->bbp_prom, 2 * 16); -#ifdef RUM_DEBUG - for (i = 0; i < 14; i++) { - if (sc->bbp_prom[i].reg == 0 || sc->bbp_prom[i].reg == 0xff) - continue; - DPRINTF(("BBP R%d=%02x\n", sc->bbp_prom[i].reg, - sc->bbp_prom[i].val)); - } -#endif -} - -static int -rum_bbp_init(struct rum_softc *sc) -{ -#define N(a) (sizeof (a) / sizeof ((a)[0])) - int i, ntries; - uint8_t val; - - /* wait for BBP to be ready */ - for (ntries = 0; ntries < 100; ntries++) { - val = rum_bbp_read(sc, 0); - if (val != 0 && val != 0xff) - break; - DELAY(1000); - } - if (ntries == 100) { - kprintf("%s: timeout waiting for BBP\n", - device_get_nameunit(sc->sc_dev)); - return EIO; - } - - /* initialize BBP registers to default values */ - for (i = 0; i < N(rum_def_bbp); i++) - rum_bbp_write(sc, rum_def_bbp[i].reg, rum_def_bbp[i].val); - - /* write vendor-specific BBP values (from EEPROM) */ - for (i = 0; i < 16; i++) { - if (sc->bbp_prom[i].reg == 0 || sc->bbp_prom[i].reg == 0xff) - continue; - rum_bbp_write(sc, sc->bbp_prom[i].reg, sc->bbp_prom[i].val); - } - - return 0; -#undef N -} - -static void -rum_init(void *xsc) -{ -#define N(a) (sizeof(a) / sizeof((a)[0])) - struct rum_softc *sc = xsc; - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - struct rum_rx_data *data; - uint32_t tmp; - usbd_status usb_err; - int i, ntries, error; - - ASSERT_SERIALIZED(ifp->if_serializer); - - crit_enter(); - - rum_stop(sc); - sc->sc_stopped = 0; - - lwkt_serialize_exit(ifp->if_serializer); - - /* initialize MAC registers to default values */ - for (i = 0; i < N(rum_def_mac); i++) - rum_write(sc, rum_def_mac[i].reg, rum_def_mac[i].val); - - /* set host ready */ - rum_write(sc, RT2573_MAC_CSR1, 3); - rum_write(sc, RT2573_MAC_CSR1, 0); - - /* wait for BBP/RF to wakeup */ - for (ntries = 0; ntries < 1000; ntries++) { - if (rum_read(sc, RT2573_MAC_CSR12) & 8) - break; - rum_write(sc, RT2573_MAC_CSR12, 4); /* force wakeup */ - DELAY(1000); - } - if (ntries == 1000) { - kprintf("%s: timeout waiting for BBP/RF to wakeup\n", - device_get_nameunit(sc->sc_dev)); - error = ETIMEDOUT; - goto fail; - } - - error = rum_bbp_init(sc); - if (error) - goto fail; - - /* select default channel */ - sc->sc_curchan = ic->ic_curchan = ic->ic_ibss_chan; - - rum_select_band(sc, sc->sc_curchan); - rum_select_antenna(sc); - rum_set_chan(sc, sc->sc_curchan); - - /* clear STA registers */ - rum_read_multi(sc, RT2573_STA_CSR0, sc->sta, sizeof sc->sta); - - IEEE80211_ADDR_COPY(ic->ic_myaddr, IF_LLADDR(ifp)); - rum_set_macaddr(sc, ic->ic_myaddr); - - /* initialize ASIC */ - rum_write(sc, RT2573_MAC_CSR1, 4); - - /* - * Allocate xfer for AMRR statistics requests. - */ - sc->stats_xfer = usbd_alloc_xfer(sc->sc_udev); - if (sc->stats_xfer == NULL) { - kprintf("%s: could not allocate AMRR xfer\n", - device_get_nameunit(sc->sc_dev)); - error = ENOMEM; - goto fail; - } - - /* - * Open Tx and Rx USB bulk pipes. - */ - usb_err = usbd_open_pipe(sc->sc_iface, sc->sc_tx_no, USBD_EXCLUSIVE_USE, - &sc->sc_tx_pipeh); - if (usb_err != USBD_NORMAL_COMPLETION) { - kprintf("%s: could not open Tx pipe: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(usb_err)); - error = EIO; - goto fail; - } - - usb_err = usbd_open_pipe(sc->sc_iface, sc->sc_rx_no, USBD_EXCLUSIVE_USE, - &sc->sc_rx_pipeh); - if (usb_err != USBD_NORMAL_COMPLETION) { - kprintf("%s: could not open Rx pipe: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(usb_err)); - error = EIO; - goto fail; - } - - /* - * Allocate Tx and Rx xfer queues. - */ - error = rum_alloc_tx_list(sc); - if (error) { - kprintf("%s: could not allocate Tx list\n", - device_get_nameunit(sc->sc_dev)); - goto fail; - } - - error = rum_alloc_rx_list(sc); - if (error) { - kprintf("%s: could not allocate Rx list\n", - device_get_nameunit(sc->sc_dev)); - goto fail; - } - - /* - * Start up the receive pipe. - */ - for (i = 0; i < RT2573_RX_LIST_COUNT; i++) { - data = &sc->rx_data[i]; - - usbd_setup_xfer(data->xfer, sc->sc_rx_pipeh, data, data->buf, - MCLBYTES, USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, rum_rxeof); - usbd_transfer(data->xfer); - } - - /* update Rx filter */ - tmp = rum_read(sc, RT2573_TXRX_CSR0) & 0xffff; - - tmp |= RT2573_DROP_PHY_ERROR | RT2573_DROP_CRC_ERROR; - if (ic->ic_opmode != IEEE80211_M_MONITOR) { - tmp |= RT2573_DROP_CTL | RT2573_DROP_VER_ERROR | - RT2573_DROP_ACKCTS; - if (ic->ic_opmode != IEEE80211_M_HOSTAP) - tmp |= RT2573_DROP_TODS; - if (!(ifp->if_flags & IFF_PROMISC)) - tmp |= RT2573_DROP_NOT_TO_ME; - } - rum_write(sc, RT2573_TXRX_CSR0, tmp); -fail: - lwkt_serialize_enter(ifp->if_serializer); - - if (error) { - rum_stop(sc); - } else { - ifq_clr_oactive(&ifp->if_snd); - ifp->if_flags |= IFF_RUNNING; - - if (ic->ic_opmode != IEEE80211_M_MONITOR) { - if (ic->ic_roaming != IEEE80211_ROAMING_MANUAL) - ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); - } else { - ieee80211_new_state(ic, IEEE80211_S_RUN, -1); - } - } - - crit_exit(); -#undef N -} - -static void -rum_stop(struct rum_softc *sc) -{ - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - uint32_t tmp; - - ASSERT_SERIALIZED(ifp->if_serializer); - - crit_enter(); - - ifp->if_flags &= ~IFF_RUNNING; - ifq_clr_oactive(&ifp->if_snd); - sc->sc_stopped = 1; - - ieee80211_new_state(ic, IEEE80211_S_INIT, -1); /* free all nodes */ - - sc->sc_tx_timer = 0; - ifp->if_timer = 0; - - lwkt_serialize_exit(ifp->if_serializer); - - /* disable Rx */ - tmp = rum_read(sc, RT2573_TXRX_CSR0); - rum_write(sc, RT2573_TXRX_CSR0, tmp | RT2573_DISABLE_RX); - - /* reset ASIC */ - rum_write(sc, RT2573_MAC_CSR1, 3); - rum_write(sc, RT2573_MAC_CSR1, 0); - - if (sc->stats_xfer != NULL) { - usbd_free_xfer(sc->stats_xfer); - sc->stats_xfer = NULL; - } - - if (sc->sc_rx_pipeh != NULL) { - usbd_abort_pipe(sc->sc_rx_pipeh); - usbd_close_pipe(sc->sc_rx_pipeh); - sc->sc_rx_pipeh = NULL; - } - - if (sc->sc_tx_pipeh != NULL) { - usbd_abort_pipe(sc->sc_tx_pipeh); - usbd_close_pipe(sc->sc_tx_pipeh); - sc->sc_tx_pipeh = NULL; - } - - lwkt_serialize_enter(ifp->if_serializer); - - rum_free_rx_list(sc); - rum_free_tx_list(sc); - - crit_exit(); -} - -static int -rum_load_microcode(struct rum_softc *sc, const uint8_t *ucode, size_t size) -{ - usb_device_request_t req; - uint16_t reg = RT2573_MCU_CODE_BASE; - usbd_status error; - - /* copy firmware image into NIC */ - for (; size >= 4; reg += 4, ucode += 4, size -= 4) - rum_write(sc, reg, UGETDW(ucode)); - - req.bmRequestType = UT_WRITE_VENDOR_DEVICE; - req.bRequest = RT2573_MCU_CNTL; - USETW(req.wValue, RT2573_MCU_RUN); - USETW(req.wIndex, 0); - USETW(req.wLength, 0); - - error = usbd_do_request(sc->sc_udev, &req, NULL); - if (error != 0) { - kprintf("%s: could not run firmware: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(error)); - } - return error; -} - -static int -rum_prepare_beacon(struct rum_softc *sc) -{ - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - struct ieee80211_beacon_offsets bo; - struct rum_tx_desc desc; - struct mbuf *m0; - int rate; - - lwkt_serialize_enter(ifp->if_serializer); - m0 = ieee80211_beacon_alloc(ic, ic->ic_bss, &bo); - lwkt_serialize_exit(ifp->if_serializer); - - if (m0 == NULL) { - if_printf(&ic->ic_if, "could not allocate beacon frame\n"); - return ENOBUFS; - } - - /* send beacons at the lowest available rate */ - rate = IEEE80211_IS_CHAN_5GHZ(ic->ic_bss->ni_chan) ? 12 : 2; - - rum_setup_tx_desc(sc, &desc, RT2573_TX_TIMESTAMP, RT2573_TX_HWSEQ, - m0->m_pkthdr.len, rate); - - /* copy the first 24 bytes of Tx descriptor into NIC memory */ - rum_write_multi(sc, RT2573_HW_BEACON_BASE0, (uint8_t *)&desc, 24); - - /* copy beacon header and payload into NIC memory */ - rum_write_multi(sc, RT2573_HW_BEACON_BASE0 + 24, mtod(m0, uint8_t *), - m0->m_pkthdr.len); - - m_freem(m0); - - return 0; -} - -static void -rum_stats_timeout(void *arg) -{ - struct rum_softc *sc = arg; - usb_device_request_t req; - - if (sc->sc_stopped) - return; - - crit_enter(); - - /* - * Asynchronously read statistic registers (cleared by read). - */ - req.bmRequestType = UT_READ_VENDOR_DEVICE; - req.bRequest = RT2573_READ_MULTI_MAC; - USETW(req.wValue, 0); - USETW(req.wIndex, RT2573_STA_CSR0); - USETW(req.wLength, sizeof(sc->sta)); - - usbd_setup_default_xfer(sc->stats_xfer, sc->sc_udev, sc, - USBD_DEFAULT_TIMEOUT, &req, - sc->sta, sizeof(sc->sta), 0, - rum_stats_update); - usbd_transfer(sc->stats_xfer); - - crit_exit(); -} - -static void -rum_stats_update(usbd_xfer_handle xfer, usbd_private_handle priv, - usbd_status status) -{ - struct rum_softc *sc = (struct rum_softc *)priv; - struct ifnet *ifp = &sc->sc_ic.ic_if; - struct ieee80211_ratectl_stats *stats = &sc->sc_stats; - - if (status != USBD_NORMAL_COMPLETION) { - kprintf("%s: could not retrieve Tx statistics - cancelling " - "automatic rate control\n", device_get_nameunit(sc->sc_dev)); - return; - } - - crit_enter(); - - /* count TX retry-fail as Tx errors */ - IFNET_STAT_INC(ifp, oerrors, RUM_TX_PKT_FAIL(sc)); - - stats->stats_pkt_noretry += RUM_TX_PKT_NO_RETRY(sc); - stats->stats_pkt_ok += RUM_TX_PKT_NO_RETRY(sc) + - RUM_TX_PKT_ONE_RETRY(sc) + - RUM_TX_PKT_MULTI_RETRY(sc); - stats->stats_pkt_err += RUM_TX_PKT_FAIL(sc); - - stats->stats_retries += RUM_TX_PKT_ONE_RETRY(sc); -#if 1 - /* - * XXX Estimated average: - * Actual number of retries for each packet should belong to - * [2, RUM_TX_SHORT_RETRY_MAX] - */ - stats->stats_retries += RUM_TX_PKT_MULTI_RETRY(sc) * - ((2 + RUM_TX_SHORT_RETRY_MAX) / 2); -#else - stats->stats_retries += RUM_TX_PKT_MULTI_RETRY(sc); -#endif - stats->stats_retries += RUM_TX_PKT_FAIL(sc) * RUM_TX_SHORT_RETRY_MAX; - - callout_reset(&sc->stats_ch, 4 * hz / 5, rum_stats_timeout, sc); - - crit_exit(); -} - -static void -rum_stats(struct ieee80211com *ic, struct ieee80211_node *ni __unused, - struct ieee80211_ratectl_stats *stats) -{ - struct ifnet *ifp = &ic->ic_if; - struct rum_softc *sc = ifp->if_softc; - - ASSERT_SERIALIZED(ifp->if_serializer); - - bcopy(&sc->sc_stats, stats, sizeof(*stats)); - bzero(&sc->sc_stats, sizeof(sc->sc_stats)); -} - -static void * -rum_ratectl_attach(struct ieee80211com *ic, u_int rc) -{ - struct rum_softc *sc = ic->ic_if.if_softc; - - switch (rc) { - case IEEE80211_RATECTL_ONOE: - return &sc->sc_onoe_param; - case IEEE80211_RATECTL_NONE: - /* This could only happen during detaching */ - return NULL; - default: - panic("unknown rate control algo %u", rc); - return NULL; - } -} - -static int -rum_get_rssi(struct rum_softc *sc, uint8_t raw) -{ - int lna, agc, rssi; - - lna = (raw >> 5) & 0x3; - agc = raw & 0x1f; - - if (lna == 0) { - /* - * No RSSI mapping - * - * NB: Since RSSI is relative to noise floor, -1 is - * adequate for caller to know error happened. - */ - return -1; - } - - rssi = (2 * agc) - RT2573_NOISE_FLOOR; - - if (IEEE80211_IS_CHAN_2GHZ(sc->sc_curchan)) { - rssi += sc->rssi_2ghz_corr; - - if (lna == 1) - rssi -= 64; - else if (lna == 2) - rssi -= 74; - else if (lna == 3) - rssi -= 90; - } else { - rssi += sc->rssi_5ghz_corr; - - if (!sc->ext_5ghz_lna && lna != 1) - rssi += 4; - - if (lna == 1) - rssi -= 64; - else if (lna == 2) - rssi -= 86; - else if (lna == 3) - rssi -= 100; - } - return rssi; -} diff --git a/sys/dev/netif/rum/if_rumreg.h b/sys/dev/netif/rum/if_rumreg.h deleted file mode 100644 index dbdc632281..0000000000 --- a/sys/dev/netif/rum/if_rumreg.h +++ /dev/null @@ -1,395 +0,0 @@ -/* $OpenBSD: if_rumreg.h,v 1.12 2006/08/09 08:21:08 damien Exp $ */ -/* $DragonFly: src/sys/dev/netif/rum/if_rumreg.h,v 1.2 2007/02/06 14:33:39 sephe Exp $ */ - -/*- - * Copyright (c) 2005, 2006 Damien Bergamini - * Copyright (c) 2006 Niall O'Higgins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#define RT2573_NOISE_FLOOR -95 - -#define RT2573_TX_DESC_SIZE (sizeof (struct rum_tx_desc)) -#define RT2573_RX_DESC_SIZE (sizeof (struct rum_rx_desc)) - -#define RT2573_CONFIG_NO 1 -#define RT2573_IFACE_INDEX 0 - -#define RT2573_MCU_CNTL 0x01 -#define RT2573_WRITE_MAC 0x02 -#define RT2573_READ_MAC 0x03 -#define RT2573_WRITE_MULTI_MAC 0x06 -#define RT2573_READ_MULTI_MAC 0x07 -#define RT2573_READ_EEPROM 0x09 -#define RT2573_WRITE_LED 0x0a - -/* - * Control and status registers. - */ -#define RT2573_AIFSN_CSR 0x0400 -#define RT2573_CWMIN_CSR 0x0404 -#define RT2573_CWMAX_CSR 0x0408 -#define RT2573_MCU_CODE_BASE 0x0800 -#define RT2573_HW_BEACON_BASE0 0x2400 -#define RT2573_MAC_CSR0 0x3000 -#define RT2573_MAC_CSR1 0x3004 -#define RT2573_MAC_CSR2 0x3008 -#define RT2573_MAC_CSR3 0x300c -#define RT2573_MAC_CSR4 0x3010 -#define RT2573_MAC_CSR5 0x3014 -#define RT2573_MAC_CSR6 0x3018 -#define RT2573_MAC_CSR7 0x301c -#define RT2573_MAC_CSR8 0x3020 -#define RT2573_MAC_CSR9 0x3024 -#define RT2573_MAC_CSR10 0x3028 -#define RT2573_MAC_CSR11 0x302c -#define RT2573_MAC_CSR12 0x3030 -#define RT2573_MAC_CSR13 0x3034 -#define RT2573_MAC_CSR14 0x3038 -#define RT2573_MAC_CSR15 0x303c -#define RT2573_TXRX_CSR0 0x3040 -#define RT2573_TXRX_CSR1 0x3044 -#define RT2573_TXRX_CSR2 0x3048 -#define RT2573_TXRX_CSR3 0x304c -#define RT2573_TXRX_CSR4 0x3050 -#define RT2573_TXRX_CSR5 0x3054 -#define RT2573_TXRX_CSR6 0x3058 -#define RT2573_TXRX_CSR7 0x305c -#define RT2573_TXRX_CSR8 0x3060 -#define RT2573_TXRX_CSR9 0x3064 -#define RT2573_TXRX_CSR10 0x3068 -#define RT2573_TXRX_CSR11 0x306c -#define RT2573_TXRX_CSR12 0x3070 -#define RT2573_TXRX_CSR13 0x3074 -#define RT2573_TXRX_CSR14 0x3078 -#define RT2573_TXRX_CSR15 0x307c -#define RT2573_PHY_CSR0 0x3080 -#define RT2573_PHY_CSR1 0x3084 -#define RT2573_PHY_CSR2 0x3088 -#define RT2573_PHY_CSR3 0x308c -#define RT2573_PHY_CSR4 0x3090 -#define RT2573_PHY_CSR5 0x3094 -#define RT2573_PHY_CSR6 0x3098 -#define RT2573_PHY_CSR7 0x309c -#define RT2573_SEC_CSR0 0x30a0 -#define RT2573_SEC_CSR1 0x30a4 -#define RT2573_SEC_CSR2 0x30a8 -#define RT2573_SEC_CSR3 0x30ac -#define RT2573_SEC_CSR4 0x30b0 -#define RT2573_SEC_CSR5 0x30b4 -#define RT2573_STA_CSR0 0x30c0 -#define RT2573_STA_CSR1 0x30c4 -#define RT2573_STA_CSR2 0x30c8 -#define RT2573_STA_CSR3 0x30cc -#define RT2573_STA_CSR4 0x30d0 -#define RT2573_STA_CSR5 0x30d4 - - -/* possible flags for register RT2573_MAC_CSR1 */ -#define RT2573_RESET_ASIC (1 << 0) -#define RT2573_RESET_BBP (1 << 1) -#define RT2573_HOST_READY (1 << 2) - -/* possible flags for register MAC_CSR5 */ -#define RT2573_ONE_BSSID 3 - -/* possible flags for register TXRX_CSR0 */ -/* Tx filter flags are in the low 16 bits */ -#define RT2573_AUTO_TX_SEQ (1 << 15) -/* Rx filter flags are in the high 16 bits */ -#define RT2573_DISABLE_RX (1 << 16) -#define RT2573_DROP_CRC_ERROR (1 << 17) -#define RT2573_DROP_PHY_ERROR (1 << 18) -#define RT2573_DROP_CTL (1 << 19) -#define RT2573_DROP_NOT_TO_ME (1 << 20) -#define RT2573_DROP_TODS (1 << 21) -#define RT2573_DROP_VER_ERROR (1 << 22) -#define RT2573_DROP_MULTICAST (1 << 23) -#define RT2573_DROP_BROADCAST (1 << 24) -#define RT2573_DROP_ACKCTS (1 << 25) - -/* possible flags for register TXRX_CSR4 */ -#define RT2573_SHORT_PREAMBLE (1 << 18) -#define RT2573_MRR_ENABLED (1 << 19) -#define RT2573_MRR_CCK_FALLBACK (1 << 22) - -/* possible flags for register TXRX_CSR9 */ -#define RT2573_TSF_TICKING (1 << 16) -#define RT2573_TSF_MODE(x) (((x) & 0x3) << 17) -/* TBTT stands for Target Beacon Transmission Time */ -#define RT2573_ENABLE_TBTT (1 << 19) -#define RT2573_GENERATE_BEACON (1 << 20) - -/* possible flags for register PHY_CSR0 */ -#define RT2573_PA_PE_2GHZ (1 << 16) -#define RT2573_PA_PE_5GHZ (1 << 17) - -/* possible flags for register PHY_CSR3 */ -#define RT2573_BBP_READ (1 << 15) -#define RT2573_BBP_BUSY (1 << 16) -/* possible flags for register PHY_CSR4 */ -#define RT2573_RF_20BIT (20 << 24) -#define RT2573_RF_BUSY (1 << 31) - -/* LED values */ -#define RT2573_LED_RADIO (1 << 8) -#define RT2573_LED_G (1 << 9) -#define RT2573_LED_A (1 << 10) -#define RT2573_LED_ON 0x1e1e -#define RT2573_LED_OFF 0x0 - -#define RT2573_MCU_RUN (1 << 3) - -#define RT2573_SMART_MODE (1 << 0) - -#define RT2573_BBPR94_DEFAULT 6 - -#define RT2573_BBP_WRITE (1 << 15) - -/* dual-band RF */ -#define RT2573_RF_5226 1 -#define RT2573_RF_5225 3 -/* single-band RF */ -#define RT2573_RF_2528 2 -#define RT2573_RF_2527 4 - -#define RT2573_BBP_VERSION 0 - -struct rum_tx_desc { - uint32_t flags; -#define RT2573_TX_BURST (1 << 0) -#define RT2573_TX_VALID (1 << 1) -#define RT2573_TX_MORE_FRAG (1 << 2) -#define RT2573_TX_ACK (1 << 3) -#define RT2573_TX_TIMESTAMP (1 << 4) -#define RT2573_TX_OFDM (1 << 5) -#define RT2573_TX_IFS_SIFS (1 << 6) -#define RT2573_TX_LONG_RETRY (1 << 7) /* Long retry 4 times, - * short retry 7 times - */ - - uint16_t wme; -#define RT2573_QID(v) (v) -#define RT2573_AIFSN(v) ((v) << 4) -#define RT2573_LOGCWMIN(v) ((v) << 8) -#define RT2573_LOGCWMAX(v) ((v) << 12) - - uint16_t xflags; -#define RT2573_TX_HWSEQ (1 << 12) - - uint8_t plcp_signal; - uint8_t plcp_service; -#define RT2573_PLCP_LENGEXT 0x80 - - uint8_t plcp_length_lo; - uint8_t plcp_length_hi; - - uint32_t iv; - uint32_t eiv; - - uint8_t offset; - uint8_t qid; - uint8_t txpower; -#define RT2573_DEFAULT_TXPOWER 0 - - uint8_t reserved; -} __packed; - -struct rum_rx_desc { - uint32_t flags; -#define RT2573_RX_BUSY (1 << 0) -#define RT2573_RX_DROP (1 << 1) -#define RT2573_RX_CRC_ERROR (1 << 6) -#define RT2573_RX_OFDM (1 << 7) - - uint8_t rate; - uint8_t rssi; - uint8_t reserved1; - uint8_t offset; - uint32_t iv; - uint32_t eiv; - uint32_t reserved2[2]; -} __packed; - -#define RT2573_RF1 0 -#define RT2573_RF2 2 -#define RT2573_RF3 1 -#define RT2573_RF4 3 - -#define RT2573_EEPROM_MACBBP 0x0000 -#define RT2573_EEPROM_ADDRESS 0x0004 -#define RT2573_EEPROM_ANTENNA 0x0020 -#define RT2573_EEPROM_CONFIG2 0x0022 -#define RT2573_EEPROM_BBP_BASE 0x0026 -#define RT2573_EEPROM_TXPOWER 0x0046 -#define RT2573_EEPROM_FREQ_OFFSET 0x005e -#define RT2573_EEPROM_RSSI_2GHZ_OFFSET 0x009a -#define RT2573_EEPROM_RSSI_5GHZ_OFFSET 0x009c - -/* - * Default values for MAC registers; values taken from the reference driver. - */ -#define RT2573_DEF_MAC \ - { RT2573_TXRX_CSR0, 0x025fb032 }, \ - { RT2573_TXRX_CSR1, 0x9eaa9eaf }, \ - { RT2573_TXRX_CSR2, 0x8a8b8c8d }, \ - { RT2573_TXRX_CSR3, 0x00858687 }, \ - { RT2573_TXRX_CSR7, 0x2e31353b }, \ - { RT2573_TXRX_CSR8, 0x2a2a2a2c }, \ - { RT2573_TXRX_CSR15, 0x0000000f }, \ - { RT2573_MAC_CSR6, 0x00000fff }, \ - { RT2573_MAC_CSR8, 0x016c030a }, \ - { RT2573_MAC_CSR10, 0x00000718 }, \ - { RT2573_MAC_CSR12, 0x00000004 }, \ - { RT2573_MAC_CSR13, 0x00007f00 }, \ - { RT2573_SEC_CSR0, 0x00000000 }, \ - { RT2573_SEC_CSR1, 0x00000000 }, \ - { RT2573_SEC_CSR5, 0x00000000 }, \ - { RT2573_PHY_CSR1, 0x000023b0 }, \ - { RT2573_PHY_CSR5, 0x00040a06 }, \ - { RT2573_PHY_CSR6, 0x00080606 }, \ - { RT2573_PHY_CSR7, 0x00000408 }, \ - { RT2573_AIFSN_CSR, 0x00002273 }, \ - { RT2573_CWMIN_CSR, 0x00002344 }, \ - { RT2573_CWMAX_CSR, 0x000034aa } - -/* - * Default values for BBP registers; values taken from the reference driver. - */ -#define RT2573_DEF_BBP \ - { 3, 0x80 }, \ - { 15, 0x30 }, \ - { 17, 0x20 }, \ - { 21, 0xc8 }, \ - { 22, 0x38 }, \ - { 23, 0x06 }, \ - { 24, 0xfe }, \ - { 25, 0x0a }, \ - { 26, 0x0d }, \ - { 32, 0x0b }, \ - { 34, 0x12 }, \ - { 37, 0x07 }, \ - { 39, 0xf8 }, \ - { 41, 0x60 }, \ - { 53, 0x10 }, \ - { 54, 0x18 }, \ - { 60, 0x10 }, \ - { 61, 0x04 }, \ - { 62, 0x04 }, \ - { 75, 0xfe }, \ - { 86, 0xfe }, \ - { 88, 0xfe }, \ - { 90, 0x0f }, \ - { 99, 0x00 }, \ - { 102, 0x16 }, \ - { 107, 0x04 } - -/* - * Default settings for RF registers; values taken from the reference driver. - */ -#define RT2573_RF5226 \ - { 1, 0x00b03, 0x001e1, 0x1a014, 0x30282 }, \ - { 2, 0x00b03, 0x001e1, 0x1a014, 0x30287 }, \ - { 3, 0x00b03, 0x001e2, 0x1a014, 0x30282 }, \ - { 4, 0x00b03, 0x001e2, 0x1a014, 0x30287 }, \ - { 5, 0x00b03, 0x001e3, 0x1a014, 0x30282 }, \ - { 6, 0x00b03, 0x001e3, 0x1a014, 0x30287 }, \ - { 7, 0x00b03, 0x001e4, 0x1a014, 0x30282 }, \ - { 8, 0x00b03, 0x001e4, 0x1a014, 0x30287 }, \ - { 9, 0x00b03, 0x001e5, 0x1a014, 0x30282 }, \ - { 10, 0x00b03, 0x001e5, 0x1a014, 0x30287 }, \ - { 11, 0x00b03, 0x001e6, 0x1a014, 0x30282 }, \ - { 12, 0x00b03, 0x001e6, 0x1a014, 0x30287 }, \ - { 13, 0x00b03, 0x001e7, 0x1a014, 0x30282 }, \ - { 14, 0x00b03, 0x001e8, 0x1a014, 0x30284 }, \ - \ - { 34, 0x00b03, 0x20266, 0x36014, 0x30282 }, \ - { 38, 0x00b03, 0x20267, 0x36014, 0x30284 }, \ - { 42, 0x00b03, 0x20268, 0x36014, 0x30286 }, \ - { 46, 0x00b03, 0x20269, 0x36014, 0x30288 }, \ - \ - { 36, 0x00b03, 0x00266, 0x26014, 0x30288 }, \ - { 40, 0x00b03, 0x00268, 0x26014, 0x30280 }, \ - { 44, 0x00b03, 0x00269, 0x26014, 0x30282 }, \ - { 48, 0x00b03, 0x0026a, 0x26014, 0x30284 }, \ - { 52, 0x00b03, 0x0026b, 0x26014, 0x30286 }, \ - { 56, 0x00b03, 0x0026c, 0x26014, 0x30288 }, \ - { 60, 0x00b03, 0x0026e, 0x26014, 0x30280 }, \ - { 64, 0x00b03, 0x0026f, 0x26014, 0x30282 }, \ - \ - { 100, 0x00b03, 0x0028a, 0x2e014, 0x30280 }, \ - { 104, 0x00b03, 0x0028b, 0x2e014, 0x30282 }, \ - { 108, 0x00b03, 0x0028c, 0x2e014, 0x30284 }, \ - { 112, 0x00b03, 0x0028d, 0x2e014, 0x30286 }, \ - { 116, 0x00b03, 0x0028e, 0x2e014, 0x30288 }, \ - { 120, 0x00b03, 0x002a0, 0x2e014, 0x30280 }, \ - { 124, 0x00b03, 0x002a1, 0x2e014, 0x30282 }, \ - { 128, 0x00b03, 0x002a2, 0x2e014, 0x30284 }, \ - { 132, 0x00b03, 0x002a3, 0x2e014, 0x30286 }, \ - { 136, 0x00b03, 0x002a4, 0x2e014, 0x30288 }, \ - { 140, 0x00b03, 0x002a6, 0x2e014, 0x30280 }, \ - \ - { 149, 0x00b03, 0x002a8, 0x2e014, 0x30287 }, \ - { 153, 0x00b03, 0x002a9, 0x2e014, 0x30289 }, \ - { 157, 0x00b03, 0x002ab, 0x2e014, 0x30281 }, \ - { 161, 0x00b03, 0x002ac, 0x2e014, 0x30283 }, \ - { 165, 0x00b03, 0x002ad, 0x2e014, 0x30285 } - -#define RT2573_RF5225 \ - { 1, 0x00b33, 0x011e1, 0x1a014, 0x30282 }, \ - { 2, 0x00b33, 0x011e1, 0x1a014, 0x30287 }, \ - { 3, 0x00b33, 0x011e2, 0x1a014, 0x30282 }, \ - { 4, 0x00b33, 0x011e2, 0x1a014, 0x30287 }, \ - { 5, 0x00b33, 0x011e3, 0x1a014, 0x30282 }, \ - { 6, 0x00b33, 0x011e3, 0x1a014, 0x30287 }, \ - { 7, 0x00b33, 0x011e4, 0x1a014, 0x30282 }, \ - { 8, 0x00b33, 0x011e4, 0x1a014, 0x30287 }, \ - { 9, 0x00b33, 0x011e5, 0x1a014, 0x30282 }, \ - { 10, 0x00b33, 0x011e5, 0x1a014, 0x30287 }, \ - { 11, 0x00b33, 0x011e6, 0x1a014, 0x30282 }, \ - { 12, 0x00b33, 0x011e6, 0x1a014, 0x30287 }, \ - { 13, 0x00b33, 0x011e7, 0x1a014, 0x30282 }, \ - { 14, 0x00b33, 0x011e8, 0x1a014, 0x30284 }, \ - \ - { 34, 0x00b33, 0x01266, 0x26014, 0x30282 }, \ - { 38, 0x00b33, 0x01267, 0x26014, 0x30284 }, \ - { 42, 0x00b33, 0x01268, 0x26014, 0x30286 }, \ - { 46, 0x00b33, 0x01269, 0x26014, 0x30288 }, \ - \ - { 36, 0x00b33, 0x01266, 0x26014, 0x30288 }, \ - { 40, 0x00b33, 0x01268, 0x26014, 0x30280 }, \ - { 44, 0x00b33, 0x01269, 0x26014, 0x30282 }, \ - { 48, 0x00b33, 0x0126a, 0x26014, 0x30284 }, \ - { 52, 0x00b33, 0x0126b, 0x26014, 0x30286 }, \ - { 56, 0x00b33, 0x0126c, 0x26014, 0x30288 }, \ - { 60, 0x00b33, 0x0126e, 0x26014, 0x30280 }, \ - { 64, 0x00b33, 0x0126f, 0x26014, 0x30282 }, \ - \ - { 100, 0x00b33, 0x0128a, 0x2e014, 0x30280 }, \ - { 104, 0x00b33, 0x0128b, 0x2e014, 0x30282 }, \ - { 108, 0x00b33, 0x0128c, 0x2e014, 0x30284 }, \ - { 112, 0x00b33, 0x0128d, 0x2e014, 0x30286 }, \ - { 116, 0x00b33, 0x0128e, 0x2e014, 0x30288 }, \ - { 120, 0x00b33, 0x012a0, 0x2e014, 0x30280 }, \ - { 124, 0x00b33, 0x012a1, 0x2e014, 0x30282 }, \ - { 128, 0x00b33, 0x012a2, 0x2e014, 0x30284 }, \ - { 132, 0x00b33, 0x012a3, 0x2e014, 0x30286 }, \ - { 136, 0x00b33, 0x012a4, 0x2e014, 0x30288 }, \ - { 140, 0x00b33, 0x012a6, 0x2e014, 0x30280 }, \ - \ - { 149, 0x00b33, 0x012a8, 0x2e014, 0x30287 }, \ - { 153, 0x00b33, 0x012a9, 0x2e014, 0x30289 }, \ - { 157, 0x00b33, 0x012ab, 0x2e014, 0x30281 }, \ - { 161, 0x00b33, 0x012ac, 0x2e014, 0x30283 }, \ - { 165, 0x00b33, 0x012ad, 0x2e014, 0x30285 } diff --git a/sys/dev/netif/rum/if_rumvar.h b/sys/dev/netif/rum/if_rumvar.h deleted file mode 100644 index 3c2ac15df8..0000000000 --- a/sys/dev/netif/rum/if_rumvar.h +++ /dev/null @@ -1,159 +0,0 @@ -/* $OpenBSD: if_rumvar.h,v 1.6 2006/08/18 15:11:12 damien Exp $ */ -/* $DragonFly: src/sys/dev/netif/rum/if_rumvar.h,v 1.6 2008/01/15 09:01:13 sephe Exp $ */ - -/*- - * Copyright (c) 2005, 2006 Damien Bergamini - * Copyright (c) 2006 Niall O'Higgins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#define RT2573_RX_LIST_COUNT 1 -#define RT2573_TX_LIST_COUNT 1 - -struct rum_rx_radiotap_header { - struct ieee80211_radiotap_header wr_ihdr; - uint8_t wr_flags; - uint8_t wr_rate; - uint16_t wr_chan_freq; - uint16_t wr_chan_flags; - uint8_t wr_antenna; - uint8_t wr_antsignal; -} __packed; - -#define RT2573_RX_RADIOTAP_PRESENT \ - ((1 << IEEE80211_RADIOTAP_FLAGS) | \ - (1 << IEEE80211_RADIOTAP_RATE) | \ - (1 << IEEE80211_RADIOTAP_CHANNEL) | \ - (1 << IEEE80211_RADIOTAP_ANTENNA) | \ - (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)) - -struct rum_tx_radiotap_header { - struct ieee80211_radiotap_header wt_ihdr; - uint8_t wt_flags; - uint8_t wt_rate; - uint16_t wt_chan_freq; - uint16_t wt_chan_flags; - uint8_t wt_antenna; -} __packed; - -#define RT2573_TX_RADIOTAP_PRESENT \ - ((1 << IEEE80211_RADIOTAP_FLAGS) | \ - (1 << IEEE80211_RADIOTAP_RATE) | \ - (1 << IEEE80211_RADIOTAP_CHANNEL) | \ - (1 << IEEE80211_RADIOTAP_ANTENNA)) - -struct rum_softc; - -struct rum_tx_data { - struct rum_softc *sc; - usbd_xfer_handle xfer; - uint8_t *buf; - struct mbuf *m; - struct ieee80211_node *ni; -}; - -struct rum_rx_data { - struct rum_softc *sc; - usbd_xfer_handle xfer; - uint8_t *buf; - struct mbuf *m; -}; - -struct rum_softc { - device_t sc_dev; - struct ieee80211com sc_ic; - int (*sc_newstate)(struct ieee80211com *, - enum ieee80211_state, int); - - int sc_stopped; - - usbd_device_handle sc_udev; - usbd_interface_handle sc_iface; - - struct ieee80211_channel *sc_curchan; - - int sc_rx_no; - int sc_tx_no; - - uint16_t macbbp_rev; - uint8_t rf_rev; - uint8_t rffreq; - - usbd_xfer_handle stats_xfer; - - usbd_pipe_handle sc_rx_pipeh; - usbd_pipe_handle sc_tx_pipeh; - - enum ieee80211_state sc_state; - int sc_arg; - int sc_sifs; - struct usb_task sc_task; - - struct ieee80211_ratectl_stats sc_stats; - - struct rum_rx_data rx_data[RT2573_RX_LIST_COUNT]; - struct rum_tx_data tx_data[RT2573_TX_LIST_COUNT]; - int tx_queued; - - struct callout scan_ch; - struct callout stats_ch; - - int sc_tx_timer; - - uint32_t sta[6]; - uint32_t rf_regs[4]; - uint8_t txpow[44]; - - struct { - uint8_t val; - uint8_t reg; - } __packed bbp_prom[16]; - - int hw_radio; - int rx_ant; - int tx_ant; - int nb_ant; - int ext_2ghz_lna; - int ext_5ghz_lna; - int rssi_2ghz_corr; - int rssi_5ghz_corr; - uint8_t bbp17; - - struct bpf_if *sc_drvbpf; - - union { - struct rum_rx_radiotap_header th; - uint8_t pad[64]; - } sc_rxtapu; -#define sc_rxtap sc_rxtapu.th - int sc_rxtap_len; - - union { - struct rum_tx_radiotap_header th; - uint8_t pad[64]; - } sc_txtapu; -#define sc_txtap sc_txtapu.th - int sc_txtap_len; - - struct ieee80211_onoe_param sc_onoe_param; -}; - -/* See the comment take from rt73 near RT2573_TX_LONG_RETRY */ -#define RUM_TX_SHORT_RETRY_MAX 7 -#define RUM_TX_LONG_RETRY_MAX 4 - -#define RUM_TX_PKT_NO_RETRY(sc) (le32toh((sc)->sta[4]) & 0xffff) -#define RUM_TX_PKT_ONE_RETRY(sc) (le32toh((sc)->sta[4]) >> 16) -#define RUM_TX_PKT_MULTI_RETRY(sc) (le32toh((sc)->sta[5]) & 0xffff) -#define RUM_TX_PKT_FAIL(sc) (le32toh((sc)->sta[5]) >> 16) diff --git a/sys/dev/netif/rum/rum_ucode.h b/sys/dev/netif/rum/rum_ucode.h deleted file mode 100644 index 4b9afe4ace..0000000000 --- a/sys/dev/netif/rum/rum_ucode.h +++ /dev/null @@ -1,214 +0,0 @@ -/* $OpenBSD: microcode.h,v 1.1 2006/08/17 08:32:30 damien Exp $ */ -/* $DragonFly: src/sys/dev/netif/rum/rum_ucode.h,v 1.1 2006/12/10 03:24:25 sephe Exp $ */ - -/*- - * Copyright (c) 2005-2006, Ralink Technology, Corp. - * Paul Lin - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * This file contains the loadable 8051 microcode for the Ralink RT2573 - * chipset. - */ - -static const uint8_t rt2573[] = { - 0x02, 0x13, 0x25, 0x12, 0x10, 0xd9, 0x02, 0x12, 0x58, 0x02, 0x13, - 0x58, 0x02, 0x13, 0x5a, 0xc0, 0xd0, 0x75, 0xd0, 0x18, 0x12, 0x13, - 0x5c, 0xd0, 0xd0, 0x22, 0x02, 0x14, 0x5c, 0x02, 0x14, 0xe7, 0xed, - 0x4c, 0x70, 0x44, 0x90, 0x01, 0xa8, 0x74, 0x80, 0xf0, 0xef, 0x30, - 0xe5, 0x07, 0xe4, 0x90, 0x00, 0x0f, 0xf0, 0x80, 0x2c, 0xe5, 0x40, - 0x24, 0xc0, 0x60, 0x13, 0x24, 0xc0, 0x60, 0x16, 0x24, 0xc0, 0x60, - 0x19, 0x24, 0xc0, 0x70, 0x1a, 0xe4, 0x90, 0x00, 0x0b, 0xf0, 0x80, - 0x13, 0xe4, 0x90, 0x00, 0x13, 0xf0, 0x80, 0x0c, 0xe4, 0x90, 0x00, - 0x1b, 0xf0, 0x80, 0x05, 0xe4, 0x90, 0x00, 0x23, 0xf0, 0xe4, 0x90, - 0x01, 0xa8, 0xf0, 0xd3, 0x22, 0x90, 0x02, 0x02, 0xed, 0xf0, 0x90, - 0x02, 0x01, 0xef, 0xf0, 0xd3, 0x22, 0xef, 0x24, 0xc0, 0x60, 0x1f, - 0x24, 0xc0, 0x60, 0x2e, 0x24, 0xc0, 0x60, 0x3d, 0x24, 0xc0, 0x70, - 0x53, 0x90, 0x00, 0x0b, 0xe0, 0x30, 0xe1, 0x02, 0xc3, 0x22, 0x90, - 0x00, 0x09, 0xe0, 0xfe, 0x90, 0x00, 0x08, 0x80, 0x37, 0x90, 0x00, - 0x13, 0xe0, 0x30, 0xe1, 0x02, 0xc3, 0x22, 0x90, 0x00, 0x11, 0xe0, - 0xfe, 0x90, 0x00, 0x10, 0x80, 0x24, 0x90, 0x00, 0x1b, 0xe0, 0x30, - 0xe1, 0x02, 0xc3, 0x22, 0x90, 0x00, 0x19, 0xe0, 0xfe, 0x90, 0x00, - 0x18, 0x80, 0x11, 0x90, 0x00, 0x23, 0xe0, 0x30, 0xe1, 0x02, 0xc3, - 0x22, 0x90, 0x00, 0x21, 0xe0, 0xfe, 0x90, 0x00, 0x20, 0xe0, 0xfd, - 0xee, 0xf5, 0x37, 0xed, 0xf5, 0x38, 0xd3, 0x22, 0x30, 0x09, 0x20, - 0x20, 0x04, 0x0b, 0x90, 0x02, 0x08, 0xe0, 0x54, 0x0f, 0x70, 0x03, - 0x02, 0x12, 0x57, 0xc2, 0x09, 0x90, 0x02, 0x00, 0xe0, 0x44, 0x04, - 0xf0, 0x74, 0x04, 0x12, 0x0c, 0x3a, 0xc2, 0x04, 0xc2, 0x07, 0x90, - 0x02, 0x01, 0xe0, 0x30, 0xe0, 0x03, 0x00, 0x80, 0xf6, 0x90, 0x03, - 0x26, 0xe0, 0x20, 0xe2, 0x03, 0x02, 0x12, 0x57, 0x90, 0x02, 0x08, - 0xe0, 0x70, 0x1b, 0x20, 0x07, 0x03, 0x02, 0x12, 0x57, 0x90, 0x03, - 0x12, 0xe0, 0x64, 0x22, 0x60, 0x03, 0x02, 0x12, 0x57, 0xd2, 0x09, - 0xc2, 0x07, 0x74, 0x02, 0x12, 0x0c, 0x3a, 0x22, 0x90, 0x02, 0x03, - 0xe0, 0x30, 0xe4, 0x47, 0x20, 0x06, 0x44, 0xe5, 0x3c, 0x60, 0x34, - 0xe5, 0x40, 0x24, 0xc0, 0x60, 0x14, 0x24, 0xc0, 0x60, 0x18, 0x24, - 0xc0, 0x60, 0x1c, 0x24, 0xc0, 0x70, 0x22, 0x90, 0x00, 0x0b, 0xe0, - 0x30, 0xe1, 0x1b, 0x22, 0x90, 0x00, 0x13, 0xe0, 0x30, 0xe1, 0x13, - 0x22, 0x90, 0x00, 0x1b, 0xe0, 0x30, 0xe1, 0x0b, 0x22, 0x90, 0x00, - 0x23, 0xe0, 0x30, 0xe1, 0x03, 0x02, 0x12, 0x57, 0x90, 0x02, 0x03, - 0x74, 0x01, 0xf0, 0x00, 0xe0, 0x54, 0xc0, 0xf5, 0x40, 0xe5, 0x40, - 0x24, 0xc0, 0x60, 0x20, 0x24, 0xc0, 0x60, 0x30, 0x24, 0xc0, 0x60, - 0x40, 0x24, 0xc0, 0x70, 0x56, 0x90, 0x00, 0x0b, 0xe0, 0x30, 0xe1, - 0x03, 0x02, 0x12, 0x57, 0x90, 0x00, 0x09, 0xe0, 0xfe, 0x90, 0x00, - 0x08, 0x80, 0x3a, 0x90, 0x00, 0x13, 0xe0, 0x30, 0xe1, 0x03, 0x02, - 0x12, 0x57, 0x90, 0x00, 0x11, 0xe0, 0xfe, 0x90, 0x00, 0x10, 0x80, - 0x26, 0x90, 0x00, 0x1b, 0xe0, 0x30, 0xe1, 0x03, 0x02, 0x12, 0x57, - 0x90, 0x00, 0x19, 0xe0, 0xfe, 0x90, 0x00, 0x18, 0x80, 0x12, 0x90, - 0x00, 0x23, 0xe0, 0x30, 0xe1, 0x03, 0x02, 0x12, 0x57, 0x90, 0x00, - 0x21, 0xe0, 0xfe, 0x90, 0x00, 0x20, 0xe0, 0xfd, 0xee, 0xf5, 0x37, - 0xed, 0xf5, 0x38, 0x90, 0x03, 0x27, 0x74, 0x82, 0xf0, 0x90, 0x02, - 0x01, 0xe5, 0x40, 0xf0, 0x90, 0x02, 0x06, 0xe0, 0xf5, 0x3c, 0xc3, - 0xe5, 0x38, 0x95, 0x3a, 0xe5, 0x37, 0x95, 0x39, 0x50, 0x21, 0xe5, - 0x40, 0x44, 0x05, 0xff, 0xe5, 0x37, 0xa2, 0xe7, 0x13, 0xfc, 0xe5, - 0x38, 0x13, 0xfd, 0x12, 0x10, 0x20, 0xe5, 0x3c, 0x30, 0xe2, 0x04, - 0xd2, 0x06, 0x80, 0x02, 0xc2, 0x06, 0x53, 0x3c, 0x01, 0x22, 0x30, - 0x0b, 0x07, 0xe4, 0x90, 0x02, 0x02, 0xf0, 0x80, 0x06, 0x90, 0x02, - 0x02, 0x74, 0x20, 0xf0, 0xe5, 0x40, 0x44, 0x01, 0x90, 0x02, 0x01, - 0xf0, 0x90, 0x02, 0x01, 0xe0, 0x30, 0xe0, 0x03, 0x00, 0x80, 0xf6, - 0x90, 0x03, 0x27, 0x74, 0x02, 0xf0, 0xaf, 0x40, 0x12, 0x10, 0x74, - 0x40, 0xa5, 0x00, 0x80, 0xf6, 0x22, 0x90, 0x7f, 0xf8, 0xe0, 0xb4, - 0x02, 0x03, 0x12, 0x16, 0x38, 0x90, 0x02, 0x01, 0xe0, 0x30, 0xe0, - 0x03, 0x00, 0x80, 0xf6, 0x90, 0x03, 0x26, 0xe0, 0x20, 0xe1, 0x07, - 0xe5, 0x3b, 0x70, 0x03, 0x02, 0x13, 0x24, 0xe5, 0x3b, 0x70, 0x15, - 0x90, 0x03, 0x24, 0xe0, 0x75, 0xf0, 0x40, 0xa4, 0xf5, 0x36, 0x85, - 0xf0, 0x35, 0x75, 0x24, 0x83, 0x75, 0x3b, 0x01, 0x80, 0x03, 0x75, - 0x24, 0x03, 0xd3, 0xe5, 0x36, 0x95, 0x3a, 0xe5, 0x35, 0x95, 0x39, - 0x40, 0x36, 0x90, 0x02, 0x01, 0xe0, 0x30, 0xe0, 0x03, 0x00, 0x80, - 0xf6, 0x90, 0x03, 0x27, 0xe5, 0x24, 0xf0, 0x90, 0x00, 0x0f, 0xe0, - 0x30, 0xe1, 0x04, 0x30, 0x0e, 0xf6, 0x22, 0x30, 0x0b, 0x07, 0xe4, - 0x90, 0x02, 0x02, 0xf0, 0x80, 0x06, 0x90, 0x02, 0x02, 0x74, 0x20, - 0xf0, 0x90, 0x02, 0x01, 0x74, 0x21, 0xf0, 0x75, 0x24, 0x03, 0x80, - 0x3d, 0xe5, 0x35, 0xa2, 0xe7, 0x13, 0xfe, 0xe5, 0x36, 0x13, 0xfd, - 0xac, 0x06, 0x90, 0x02, 0x01, 0xe0, 0x30, 0xe0, 0x03, 0x00, 0x80, - 0xf6, 0x90, 0x03, 0x27, 0xe5, 0x24, 0xf0, 0x90, 0x00, 0x0f, 0xe0, - 0x30, 0xe1, 0x04, 0x30, 0x0e, 0xf6, 0x22, 0x7f, 0x25, 0x12, 0x10, - 0x20, 0xe5, 0x36, 0xb5, 0x3a, 0x08, 0xe5, 0x35, 0xb5, 0x39, 0x03, - 0x00, 0x80, 0x04, 0xe4, 0xf5, 0x3b, 0x22, 0xc3, 0xe5, 0x36, 0x95, - 0x3a, 0xf5, 0x36, 0xe5, 0x35, 0x95, 0x39, 0xf5, 0x35, 0x02, 0x12, - 0x96, 0x22, 0x75, 0xa8, 0x0f, 0x90, 0x03, 0x06, 0x74, 0x01, 0xf0, - 0x90, 0x03, 0x07, 0xf0, 0x90, 0x03, 0x08, 0x04, 0xf0, 0x90, 0x03, - 0x09, 0x74, 0x6c, 0xf0, 0x90, 0x03, 0x0a, 0x74, 0xff, 0xf0, 0x90, - 0x03, 0x02, 0x74, 0x1f, 0xf0, 0x90, 0x03, 0x00, 0x74, 0x04, 0xf0, - 0x90, 0x03, 0x25, 0x74, 0x31, 0xf0, 0xd2, 0xaf, 0x22, 0x00, 0x22, - 0x00, 0x22, 0x90, 0x03, 0x05, 0xe0, 0x30, 0xe0, 0x0b, 0xe0, 0x44, - 0x01, 0xf0, 0x30, 0x09, 0x02, 0xd2, 0x04, 0xc2, 0x07, 0x22, 0x8d, - 0x24, 0xa9, 0x07, 0x90, 0x7f, 0xfc, 0xe0, 0x75, 0x25, 0x00, 0xf5, - 0x26, 0xa3, 0xe0, 0x75, 0x27, 0x00, 0xf5, 0x28, 0xa3, 0xe0, 0xff, - 0xa3, 0xe0, 0xfd, 0xe9, 0x30, 0xe5, 0x14, 0x54, 0xc0, 0x60, 0x05, - 0x43, 0x05, 0x03, 0x80, 0x03, 0x53, 0x05, 0xfc, 0xef, 0x54, 0x3f, - 0x44, 0x40, 0xff, 0x80, 0x06, 0x53, 0x07, 0x3f, 0x53, 0x05, 0xf0, - 0xe5, 0x24, 0x30, 0xe0, 0x05, 0x43, 0x05, 0x10, 0x80, 0x03, 0x53, - 0x05, 0xef, 0x90, 0x7f, 0xfc, 0xe5, 0x26, 0xf0, 0xa3, 0xe5, 0x28, - 0xf0, 0xa3, 0xef, 0xf0, 0xa3, 0xed, 0xf0, 0x22, 0x8f, 0x24, 0xa9, - 0x05, 0x90, 0x7f, 0xfc, 0xe0, 0x75, 0x25, 0x00, 0xf5, 0x26, 0xa3, - 0xe0, 0x75, 0x27, 0x00, 0xf5, 0x28, 0xa3, 0xe0, 0xff, 0xa3, 0xe0, - 0xfd, 0xe5, 0x24, 0x30, 0xe5, 0x0b, 0x43, 0x05, 0x0f, 0xef, 0x54, - 0x3f, 0x44, 0x40, 0xff, 0x80, 0x06, 0x53, 0x05, 0xf0, 0x53, 0x07, - 0x3f, 0xe9, 0x30, 0xe0, 0x05, 0x43, 0x05, 0x10, 0x80, 0x03, 0x53, - 0x05, 0xef, 0x90, 0x7f, 0xfc, 0xe5, 0x26, 0xf0, 0xa3, 0xe5, 0x28, - 0xf0, 0xa3, 0xef, 0xf0, 0xa3, 0xed, 0xf0, 0x22, 0x90, 0x7f, 0xfc, - 0xe0, 0xf9, 0xa3, 0xe0, 0xfe, 0xa3, 0xe0, 0xfc, 0xa3, 0xe0, 0xfb, - 0xef, 0x30, 0xe5, 0x0b, 0x43, 0x03, 0x0f, 0xec, 0x54, 0x3f, 0x44, - 0x40, 0xfc, 0x80, 0x06, 0x53, 0x03, 0xf0, 0x53, 0x04, 0x3f, 0xed, - 0x30, 0xe0, 0x07, 0xef, 0x54, 0xc0, 0x60, 0x07, 0x80, 0x0a, 0xef, - 0x54, 0xc0, 0x60, 0x05, 0x43, 0x03, 0x10, 0x80, 0x03, 0x53, 0x03, - 0xef, 0x90, 0x7f, 0xfc, 0xe9, 0xf0, 0xa3, 0xee, 0xf0, 0xa3, 0xec, - 0xf0, 0xa3, 0xeb, 0xf0, 0x22, 0xe5, 0x4b, 0xfd, 0x54, 0x1f, 0x90, - 0x7f, 0xf8, 0xf0, 0xe5, 0x4a, 0xf5, 0x09, 0x90, 0x30, 0x38, 0xe0, - 0x90, 0x7f, 0xfc, 0xf0, 0x90, 0x30, 0x39, 0xe0, 0x90, 0x7f, 0xfd, - 0xf0, 0x90, 0x30, 0x3a, 0xe0, 0x90, 0x7f, 0xfe, 0xf0, 0x90, 0x30, - 0x3b, 0xe0, 0x90, 0x7f, 0xff, 0xf0, 0xed, 0x30, 0xe5, 0x0c, 0x54, - 0xc0, 0x60, 0x0d, 0x90, 0x7f, 0xf0, 0xe5, 0x47, 0xf0, 0x80, 0x05, - 0xe4, 0x90, 0x7f, 0xf0, 0xf0, 0x90, 0x7f, 0xf8, 0xe0, 0x14, 0x60, - 0x08, 0x24, 0xfe, 0x60, 0x0d, 0x24, 0x03, 0x80, 0x12, 0xaf, 0x05, - 0xad, 0x09, 0x12, 0x13, 0xc5, 0x80, 0x10, 0xaf, 0x05, 0xad, 0x09, - 0x12, 0x14, 0x12, 0x80, 0x07, 0xaf, 0x05, 0xad, 0x09, 0x12, 0x13, - 0x6f, 0x90, 0x7f, 0xfc, 0xe0, 0x90, 0x30, 0x38, 0xf0, 0x90, 0x7f, - 0xfd, 0xe0, 0x90, 0x30, 0x39, 0xf0, 0x90, 0x7f, 0xfe, 0xe0, 0x90, - 0x30, 0x3a, 0xf0, 0x90, 0x7f, 0xff, 0xe0, 0x90, 0x30, 0x3b, 0xf0, - 0x22, 0xe5, 0x4b, 0x64, 0x01, 0x60, 0x03, 0x02, 0x15, 0x71, 0xf5, - 0x4b, 0xe5, 0x44, 0x45, 0x43, 0x70, 0x03, 0x02, 0x15, 0xa0, 0x12, - 0x0c, 0x14, 0x12, 0x0b, 0x86, 0x50, 0xfb, 0x90, 0x00, 0x00, 0xe0, - 0xf5, 0x25, 0x12, 0x15, 0xb4, 0xc2, 0x92, 0xe4, 0xf5, 0x24, 0xe5, - 0x24, 0xc3, 0x95, 0x25, 0x50, 0x49, 0x7e, 0x00, 0x7f, 0x4c, 0x74, - 0x40, 0x25, 0x24, 0xf5, 0x82, 0xe4, 0x34, 0x01, 0xad, 0x82, 0xfc, - 0x75, 0x2b, 0x02, 0x7b, 0x10, 0x12, 0x07, 0x1e, 0xc2, 0x93, 0x12, - 0x15, 0xa1, 0x7d, 0xa0, 0x12, 0x15, 0xd0, 0xe5, 0x24, 0x54, 0x0f, - 0x24, 0x4c, 0xf8, 0xe6, 0xfd, 0xaf, 0x4b, 0xae, 0x4a, 0x12, 0x15, - 0xd8, 0x05, 0x4b, 0xe5, 0x4b, 0x70, 0x02, 0x05, 0x4a, 0x12, 0x0a, - 0x5f, 0x05, 0x24, 0xe5, 0x24, 0x54, 0x0f, 0x70, 0xd5, 0xd2, 0x93, - 0x80, 0xb0, 0xc3, 0xe5, 0x44, 0x95, 0x25, 0xf5, 0x44, 0xe5, 0x43, - 0x94, 0x00, 0xf5, 0x43, 0x02, 0x14, 0xf2, 0x12, 0x15, 0xb4, 0xc2, - 0x93, 0xc2, 0x92, 0x12, 0x15, 0xa1, 0x7d, 0x80, 0x12, 0x15, 0xd0, - 0x7d, 0xaa, 0x74, 0x55, 0xff, 0xfe, 0x12, 0x15, 0xd8, 0x7d, 0x55, - 0x7f, 0xaa, 0x7e, 0x2a, 0x12, 0x15, 0xd8, 0x7d, 0x30, 0xaf, 0x4b, - 0xae, 0x4a, 0x12, 0x15, 0xd8, 0x12, 0x0a, 0x5f, 0xd2, 0x93, 0x22, - 0x7d, 0xaa, 0x74, 0x55, 0xff, 0xfe, 0x12, 0x15, 0xd8, 0x7d, 0x55, - 0x7f, 0xaa, 0x7e, 0x2a, 0x12, 0x15, 0xd8, 0x22, 0xad, 0x47, 0x7f, - 0x34, 0x7e, 0x30, 0x12, 0x15, 0xd8, 0x7d, 0xff, 0x7f, 0x35, 0x7e, - 0x30, 0x12, 0x15, 0xd8, 0xe4, 0xfd, 0x7f, 0x37, 0x7e, 0x30, 0x12, - 0x15, 0xd8, 0x22, 0x74, 0x55, 0xff, 0xfe, 0x12, 0x15, 0xd8, 0x22, - 0x8f, 0x82, 0x8e, 0x83, 0xed, 0xf0, 0x22, 0xe4, 0xfc, 0x90, 0x7f, - 0xf0, 0xe0, 0xaf, 0x09, 0x14, 0x60, 0x14, 0x14, 0x60, 0x15, 0x14, - 0x60, 0x16, 0x14, 0x60, 0x17, 0x14, 0x60, 0x18, 0x24, 0x05, 0x70, - 0x16, 0xe4, 0xfc, 0x80, 0x12, 0x7c, 0x01, 0x80, 0x0e, 0x7c, 0x03, - 0x80, 0x0a, 0x7c, 0x07, 0x80, 0x06, 0x7c, 0x0f, 0x80, 0x02, 0x7c, - 0x1f, 0xec, 0x6f, 0xf4, 0x54, 0x1f, 0xfc, 0x90, 0x30, 0x34, 0xe0, - 0x54, 0xe0, 0x4c, 0xfd, 0xa3, 0xe0, 0xfc, 0x43, 0x04, 0x1f, 0x7f, - 0x34, 0x7e, 0x30, 0x12, 0x15, 0xd8, 0xad, 0x04, 0x0f, 0x12, 0x15, - 0xd8, 0xe4, 0xfd, 0x7f, 0x37, 0x02, 0x15, 0xd8, 0x02, 0x15, 0xdf, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, - 0x29, 0xe9 -}; diff --git a/sys/dev/netif/ural/Makefile b/sys/dev/netif/ural/Makefile deleted file mode 100644 index 6ff86f47cf..0000000000 --- a/sys/dev/netif/ural/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $DragonFly: src/sys/dev/netif/ural/Makefile,v 1.1 2006/12/10 02:53:34 sephe Exp $ - -KMOD= if_ural -SRCS= if_ural.c -SRCS+= device_if.h bus_if.h opt_usb.h - -.include diff --git a/sys/dev/netif/ural/if_ural.c b/sys/dev/netif/ural/if_ural.c deleted file mode 100644 index 98019eb0b4..0000000000 --- a/sys/dev/netif/ural/if_ural.c +++ /dev/null @@ -1,2456 +0,0 @@ -/* $FreeBSD: src/sys/dev/usb/if_ural.c,v 1.10.2.8 2006/07/08 07:48:43 maxim Exp $ */ - -/*- - * Copyright (c) 2005, 2006 - * Damien Bergamini - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/*- - * Ralink Technology RT2500USB chipset driver - * http://www.ralinktech.com/ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include -#include - -#ifdef USB_DEBUG -#define DPRINTF(x) do { if (uraldebug > 0) kprintf x; } while (0) -#define DPRINTFN(n, x) do { if (uraldebug >= (n)) kprintf x; } while (0) -int uraldebug = 0; -SYSCTL_NODE(_hw_usb, OID_AUTO, ural, CTLFLAG_RW, 0, "USB ural"); -SYSCTL_INT(_hw_usb_ural, OID_AUTO, debug, CTLFLAG_RW, &uraldebug, 0, - "ural debug level"); -#else -#define DPRINTF(x) -#define DPRINTFN(n, x) -#endif - -#define URAL_RSSI(rssi) \ - ((rssi) > (RAL_NOISE_FLOOR + RAL_RSSI_CORR) ? \ - ((rssi) - (RAL_NOISE_FLOOR + RAL_RSSI_CORR)) : 0) - -/* various supported device vendors/products */ -static const struct usb_devno ural_devs[] = { - { USB_DEVICE(0x0411, 0x005e) }, /* Melco WLI-U2-KG54-YB */ - { USB_DEVICE(0x0411, 0x0066) }, /* Melco WLI-U2-KG54 */ - { USB_DEVICE(0x0411, 0x0067) }, /* Melco WLI-U2-KG54-AI */ - { USB_DEVICE(0x0411, 0x008b) }, /* Melco Nintendo Wi-Fi */ - { USB_DEVICE(0x050d, 0x7050) }, /* Belkin Components F5D7050 */ - { USB_DEVICE(0x06f8, 0xe000) }, /* Guillemot HWGUSB254 */ - { USB_DEVICE(0x0769, 0x11f3) }, /* Surecom RT2570 */ - { USB_DEVICE(0x0b05, 0x1706) }, /* Ralink (XXX) RT2500USB */ - { USB_DEVICE(0x0b05, 0x1707) }, /* Asus WL167G */ - { USB_DEVICE(0x0db0, 0x6861) }, /* MSI RT2570 */ - { USB_DEVICE(0x0db0, 0x6865) }, /* MSI RT2570 */ - { USB_DEVICE(0x0db0, 0x6869) }, /* MSI RT2570 */ - { USB_DEVICE(0x0eb0, 0x9020) }, /* Nova Technology NV-902W */ - { USB_DEVICE(0x0f88, 0x3012) }, /* VTech RT2570 */ - { USB_DEVICE(0x1044, 0x8007) }, /* GIGABYTE GN-WBKG */ - { USB_DEVICE(0x114b, 0x0110) }, /* Sphairon UB801R */ - { USB_DEVICE(0x148f, 0x1706) }, /* Ralink RT2570 */ - { USB_DEVICE(0x148f, 0x2570) }, /* Ralink RT2570 */ - { USB_DEVICE(0x148f, 0x9020) }, /* Ralink RT2570 */ - { USB_DEVICE(0x14b2, 0x3c02) }, /* Conceptronic C54RU */ - { USB_DEVICE(0x1737, 0x000d) }, /* Linksys WUSB54G */ - { USB_DEVICE(0x1737, 0x0011) }, /* Linksys WUSB54GP */ - { USB_DEVICE(0x1737, 0x001a) }, /* Linksys HU200TS */ - { USB_DEVICE(0x2001, 0x3c00) }, /* D-Link DWL-G122 */ - { USB_DEVICE(0x5a57, 0x0260) }, /* Zinwell RT2570 */ -}; - -static int ural_alloc_tx_list(struct ural_softc *); -static void ural_free_tx_list(struct ural_softc *); -static int ural_alloc_rx_list(struct ural_softc *); -static void ural_free_rx_list(struct ural_softc *); -static int ural_media_change(struct ifnet *); -static void ural_next_scan(void *); -static void ural_task(void *); -static int ural_newstate(struct ieee80211com *, - enum ieee80211_state, int); -static int ural_rxrate(struct ural_rx_desc *); -static void ural_txeof(usbd_xfer_handle, usbd_private_handle, - usbd_status); -static void ural_rxeof(usbd_xfer_handle, usbd_private_handle, - usbd_status); -static uint8_t ural_plcp_signal(int); -static void ural_setup_tx_desc(struct ural_softc *, - struct ural_tx_desc *, uint32_t, int, int); -static int ural_tx_bcn(struct ural_softc *, struct mbuf *, - struct ieee80211_node *); -static int ural_tx_mgt(struct ural_softc *, struct mbuf *, - struct ieee80211_node *); -static int ural_tx_data(struct ural_softc *, struct mbuf *, - struct ieee80211_node *); -static void ural_start(struct ifnet *, struct ifaltq_subque *); -static void ural_watchdog(struct ifnet *); -static int ural_reset(struct ifnet *); -static int ural_ioctl(struct ifnet *, u_long, caddr_t, - struct ucred *); -static void ural_set_testmode(struct ural_softc *); -static void ural_eeprom_read(struct ural_softc *, uint16_t, void *, - int); -static uint16_t ural_read(struct ural_softc *, uint16_t); -static void ural_read_multi(struct ural_softc *, uint16_t, void *, - int); -static void ural_write(struct ural_softc *, uint16_t, uint16_t); -static void ural_write_multi(struct ural_softc *, uint16_t, void *, - int) __unused; -static void ural_bbp_write(struct ural_softc *, uint8_t, uint8_t); -static uint8_t ural_bbp_read(struct ural_softc *, uint8_t); -static void ural_rf_write(struct ural_softc *, uint8_t, uint32_t); -static void ural_set_chan(struct ural_softc *, - struct ieee80211_channel *); -static void ural_disable_rf_tune(struct ural_softc *); -static void ural_enable_tsf_sync(struct ural_softc *); -static void ural_update_slot(struct ifnet *); -static void ural_set_txpreamble(struct ural_softc *); -static void ural_set_basicrates(struct ural_softc *); -static void ural_set_bssid(struct ural_softc *, uint8_t *); -static void ural_set_macaddr(struct ural_softc *, uint8_t *); -static void ural_update_promisc(struct ural_softc *); -static const char *ural_get_rf(int); -static void ural_read_eeprom(struct ural_softc *); -static int ural_bbp_init(struct ural_softc *); -static void ural_set_txantenna(struct ural_softc *, int); -static void ural_set_rxantenna(struct ural_softc *, int); -static void ural_init(void *); -static void ural_stop(struct ural_softc *); -static void ural_stats(struct ieee80211com *, - struct ieee80211_node *, - struct ieee80211_ratectl_stats *); -static void ural_stats_update(usbd_xfer_handle, - usbd_private_handle, usbd_status); -static void ural_stats_timeout(void *); -static void *ural_ratectl_attach(struct ieee80211com *ic, u_int); - -/* - * Supported rates for 802.11a/b/g modes (in 500Kbps unit). - */ -static const struct ieee80211_rateset ural_rateset_11a = - { 8, { 12, 18, 24, 36, 48, 72, 96, 108 } }; - -static const struct ieee80211_rateset ural_rateset_11b = - { 4, { 2, 4, 11, 22 } }; - -static const struct ieee80211_rateset ural_rateset_11g = - { 12, { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 } }; - -/* - * Default values for MAC registers; values taken from the reference driver. - */ -static const struct { - uint16_t reg; - uint16_t val; -} ural_def_mac[] = { - { RAL_TXRX_CSR5, 0x8c8d }, - { RAL_TXRX_CSR6, 0x8b8a }, - { RAL_TXRX_CSR7, 0x8687 }, - { RAL_TXRX_CSR8, 0x0085 }, - { RAL_MAC_CSR13, 0x1111 }, - { RAL_MAC_CSR14, 0x1e11 }, - { RAL_TXRX_CSR21, 0xe78f }, - { RAL_MAC_CSR9, 0xff1d }, - { RAL_MAC_CSR11, 0x0002 }, - { RAL_MAC_CSR22, 0x0053 }, - { RAL_MAC_CSR15, 0x0000 }, - { RAL_MAC_CSR8, 0x0780 }, - { RAL_TXRX_CSR19, 0x0000 }, - { RAL_TXRX_CSR18, 0x005a }, - { RAL_PHY_CSR2, 0x0000 }, - { RAL_TXRX_CSR0, 0x1ec0 }, - { RAL_PHY_CSR4, 0x000f } -}; - -/* - * Default values for BBP registers; values taken from the reference driver. - */ -static const struct { - uint8_t reg; - uint8_t val; -} ural_def_bbp[] = { - { 3, 0x02 }, - { 4, 0x19 }, - { 14, 0x1c }, - { 15, 0x30 }, - { 16, 0xac }, - { 17, 0x48 }, - { 18, 0x18 }, - { 19, 0xff }, - { 20, 0x1e }, - { 21, 0x08 }, - { 22, 0x08 }, - { 23, 0x08 }, - { 24, 0x80 }, - { 25, 0x50 }, - { 26, 0x08 }, - { 27, 0x23 }, - { 30, 0x10 }, - { 31, 0x2b }, - { 32, 0xb9 }, - { 34, 0x12 }, - { 35, 0x50 }, - { 39, 0xc4 }, - { 40, 0x02 }, - { 41, 0x60 }, - { 53, 0x10 }, - { 54, 0x18 }, - { 56, 0x08 }, - { 57, 0x10 }, - { 58, 0x08 }, - { 61, 0x60 }, - { 62, 0x10 }, - { 75, 0xff } -}; - -/* - * Default values for RF register R2 indexed by channel numbers. - */ -static const uint32_t ural_rf2522_r2[] = { - 0x307f6, 0x307fb, 0x30800, 0x30805, 0x3080a, 0x3080f, 0x30814, - 0x30819, 0x3081e, 0x30823, 0x30828, 0x3082d, 0x30832, 0x3083e -}; - -static const uint32_t ural_rf2523_r2[] = { - 0x00327, 0x00328, 0x00329, 0x0032a, 0x0032b, 0x0032c, 0x0032d, - 0x0032e, 0x0032f, 0x00340, 0x00341, 0x00342, 0x00343, 0x00346 -}; - -static const uint32_t ural_rf2524_r2[] = { - 0x00327, 0x00328, 0x00329, 0x0032a, 0x0032b, 0x0032c, 0x0032d, - 0x0032e, 0x0032f, 0x00340, 0x00341, 0x00342, 0x00343, 0x00346 -}; - -static const uint32_t ural_rf2525_r2[] = { - 0x20327, 0x20328, 0x20329, 0x2032a, 0x2032b, 0x2032c, 0x2032d, - 0x2032e, 0x2032f, 0x20340, 0x20341, 0x20342, 0x20343, 0x20346 -}; - -static const uint32_t ural_rf2525_hi_r2[] = { - 0x2032f, 0x20340, 0x20341, 0x20342, 0x20343, 0x20344, 0x20345, - 0x20346, 0x20347, 0x20348, 0x20349, 0x2034a, 0x2034b, 0x2034e -}; - -static const uint32_t ural_rf2525e_r2[] = { - 0x2044d, 0x2044e, 0x2044f, 0x20460, 0x20461, 0x20462, 0x20463, - 0x20464, 0x20465, 0x20466, 0x20467, 0x20468, 0x20469, 0x2046b -}; - -static const uint32_t ural_rf2526_hi_r2[] = { - 0x0022a, 0x0022b, 0x0022b, 0x0022c, 0x0022c, 0x0022d, 0x0022d, - 0x0022e, 0x0022e, 0x0022f, 0x0022d, 0x00240, 0x00240, 0x00241 -}; - -static const uint32_t ural_rf2526_r2[] = { - 0x00226, 0x00227, 0x00227, 0x00228, 0x00228, 0x00229, 0x00229, - 0x0022a, 0x0022a, 0x0022b, 0x0022b, 0x0022c, 0x0022c, 0x0022d -}; - -/* - * For dual-band RF, RF registers R1 and R4 also depend on channel number; - * values taken from the reference driver. - */ -static const struct { - uint8_t chan; - uint32_t r1; - uint32_t r2; - uint32_t r4; -} ural_rf5222[] = { - { 1, 0x08808, 0x0044d, 0x00282 }, - { 2, 0x08808, 0x0044e, 0x00282 }, - { 3, 0x08808, 0x0044f, 0x00282 }, - { 4, 0x08808, 0x00460, 0x00282 }, - { 5, 0x08808, 0x00461, 0x00282 }, - { 6, 0x08808, 0x00462, 0x00282 }, - { 7, 0x08808, 0x00463, 0x00282 }, - { 8, 0x08808, 0x00464, 0x00282 }, - { 9, 0x08808, 0x00465, 0x00282 }, - { 10, 0x08808, 0x00466, 0x00282 }, - { 11, 0x08808, 0x00467, 0x00282 }, - { 12, 0x08808, 0x00468, 0x00282 }, - { 13, 0x08808, 0x00469, 0x00282 }, - { 14, 0x08808, 0x0046b, 0x00286 }, - - { 36, 0x08804, 0x06225, 0x00287 }, - { 40, 0x08804, 0x06226, 0x00287 }, - { 44, 0x08804, 0x06227, 0x00287 }, - { 48, 0x08804, 0x06228, 0x00287 }, - { 52, 0x08804, 0x06229, 0x00287 }, - { 56, 0x08804, 0x0622a, 0x00287 }, - { 60, 0x08804, 0x0622b, 0x00287 }, - { 64, 0x08804, 0x0622c, 0x00287 }, - - { 100, 0x08804, 0x02200, 0x00283 }, - { 104, 0x08804, 0x02201, 0x00283 }, - { 108, 0x08804, 0x02202, 0x00283 }, - { 112, 0x08804, 0x02203, 0x00283 }, - { 116, 0x08804, 0x02204, 0x00283 }, - { 120, 0x08804, 0x02205, 0x00283 }, - { 124, 0x08804, 0x02206, 0x00283 }, - { 128, 0x08804, 0x02207, 0x00283 }, - { 132, 0x08804, 0x02208, 0x00283 }, - { 136, 0x08804, 0x02209, 0x00283 }, - { 140, 0x08804, 0x0220a, 0x00283 }, - - { 149, 0x08808, 0x02429, 0x00281 }, - { 153, 0x08808, 0x0242b, 0x00281 }, - { 157, 0x08808, 0x0242d, 0x00281 }, - { 161, 0x08808, 0x0242f, 0x00281 } -}; - -static device_probe_t ural_match; -static device_attach_t ural_attach; -static device_detach_t ural_detach; - -static devclass_t ural_devclass; - -static kobj_method_t ural_methods[] = { - DEVMETHOD(device_probe, ural_match), - DEVMETHOD(device_attach, ural_attach), - DEVMETHOD(device_detach, ural_detach), - DEVMETHOD_END -}; - -static driver_t ural_driver = { - "ural", - ural_methods, - sizeof(struct ural_softc) -}; - -DRIVER_MODULE(ural, uhub, ural_driver, ural_devclass, usbd_driver_load, NULL); - -MODULE_DEPEND(ural, usb, 1, 1, 1); -MODULE_DEPEND(ural, wlan, 1, 1, 1); -MODULE_DEPEND(ural, wlan_ratectl_onoe, 1, 1, 1); - -static int -ural_match(device_t self) -{ - struct usb_attach_arg *uaa = device_get_ivars(self); - - if (uaa->iface != NULL) - return UMATCH_NONE; - - return (usb_lookup(ural_devs, uaa->vendor, uaa->product) != NULL) ? - UMATCH_VENDOR_PRODUCT : UMATCH_NONE; -} - -static int -ural_attach(device_t self) -{ - struct ural_softc *sc = device_get_softc(self); - struct usb_attach_arg *uaa = device_get_ivars(self); - struct ifnet *ifp; - struct ieee80211com *ic = &sc->sc_ic; - usb_interface_descriptor_t *id; - usb_endpoint_descriptor_t *ed; - usbd_status error; - int i; - - sc->sc_udev = uaa->device; - sc->sc_tx_retries = 7; /* TODO tunable/sysctl */ - - sc->sc_dev = self; - - if (usbd_set_config_no(sc->sc_udev, RAL_CONFIG_NO, 0) != 0) { - kprintf("%s: could not set configuration no\n", - device_get_nameunit(sc->sc_dev)); - return ENXIO; - } - - /* get the first interface handle */ - error = usbd_device2interface_handle(sc->sc_udev, RAL_IFACE_INDEX, - &sc->sc_iface); - if (error != 0) { - kprintf("%s: could not get interface handle\n", - device_get_nameunit(sc->sc_dev)); - return ENXIO; - } - - /* - * Find endpoints. - */ - id = usbd_get_interface_descriptor(sc->sc_iface); - - sc->sc_rx_no = sc->sc_tx_no = -1; - for (i = 0; i < id->bNumEndpoints; i++) { - ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i); - if (ed == NULL) { - kprintf("%s: no endpoint descriptor for %d\n", - device_get_nameunit(sc->sc_dev), i); - return ENXIO; - } - - if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && - UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) - sc->sc_rx_no = ed->bEndpointAddress; - else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && - UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) - sc->sc_tx_no = ed->bEndpointAddress; - } - if (sc->sc_rx_no == -1 || sc->sc_tx_no == -1) { - kprintf("%s: missing endpoint\n", device_get_nameunit(sc->sc_dev)); - return ENXIO; - } - - usb_init_task(&sc->sc_task, ural_task, sc); - callout_init(&sc->scan_ch); - callout_init(&sc->stats_ch); - - /* retrieve RT2570 rev. no */ - sc->asic_rev = ural_read(sc, RAL_MAC_CSR0); - - /* retrieve MAC address and various other things from EEPROM */ - ural_read_eeprom(sc); - - kprintf("%s: MAC/BBP RT2570 (rev 0x%02x), RF %s\n", - device_get_nameunit(sc->sc_dev), sc->asic_rev, ural_get_rf(sc->rf_rev)); - - ifp = &ic->ic_if; - ifp->if_softc = sc; - if_initname(ifp, "ural", device_get_unit(sc->sc_dev)); - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; - ifp->if_init = ural_init; - ifp->if_ioctl = ural_ioctl; - ifp->if_start = ural_start; - ifp->if_watchdog = ural_watchdog; - ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN); -#ifdef notyet - ifq_set_ready(&ifp->if_snd); -#endif - - IEEE80211_ONOE_PARAM_SETUP(&sc->sc_onoe_param); - sc->sc_onoe_param.onoe_raise = 20; - ic->ic_ratectl.rc_st_ratectl_cap = IEEE80211_RATECTL_CAP_ONOE; - ic->ic_ratectl.rc_st_ratectl = IEEE80211_RATECTL_ONOE; - ic->ic_ratectl.rc_st_stats = ural_stats; - ic->ic_ratectl.rc_st_attach = ural_ratectl_attach; - - ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ - ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */ - ic->ic_state = IEEE80211_S_INIT; - - /* set device capabilities */ - ic->ic_caps = - IEEE80211_C_IBSS | /* IBSS mode supported */ - IEEE80211_C_MONITOR | /* monitor mode supported */ - IEEE80211_C_HOSTAP | /* HostAp mode supported */ - IEEE80211_C_TXPMGT | /* tx power management */ - IEEE80211_C_SHPREAMBLE | /* short preamble supported */ - IEEE80211_C_SHSLOT | /* short slot time supported */ - IEEE80211_C_WPA; /* 802.11i */ - - if (sc->rf_rev == RAL_RF_5222) { - /* set supported .11a rates */ - ic->ic_sup_rates[IEEE80211_MODE_11A] = ural_rateset_11a; - - /* set supported .11a channels */ - for (i = 36; i <= 64; i += 4) { - ic->ic_channels[i].ic_freq = - ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ); - ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A; - } - for (i = 100; i <= 140; i += 4) { - ic->ic_channels[i].ic_freq = - ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ); - ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A; - } - for (i = 149; i <= 161; i += 4) { - ic->ic_channels[i].ic_freq = - ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ); - ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A; - } - } - - /* set supported .11b and .11g rates */ - ic->ic_sup_rates[IEEE80211_MODE_11B] = ural_rateset_11b; - ic->ic_sup_rates[IEEE80211_MODE_11G] = ural_rateset_11g; - - /* set supported .11b and .11g channels (1 through 14) */ - for (i = 1; i <= 14; i++) { - ic->ic_channels[i].ic_freq = - ieee80211_ieee2mhz(i, IEEE80211_CHAN_2GHZ); - ic->ic_channels[i].ic_flags = - IEEE80211_CHAN_CCK | IEEE80211_CHAN_OFDM | - IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ; - } - - sc->sc_sifs = IEEE80211_DUR_SIFS; /* Default SIFS */ - - ieee80211_ifattach(ic); - ic->ic_reset = ural_reset; - /* enable s/w bmiss handling in sta mode */ - ic->ic_flags_ext |= IEEE80211_FEXT_SWBMISS; - - /* override state transition machine */ - sc->sc_newstate = ic->ic_newstate; - ic->ic_newstate = ural_newstate; - ieee80211_media_init(ic, ural_media_change, ieee80211_media_status); - - bpfattach_dlt(ifp, DLT_IEEE802_11_RADIO, - sizeof(struct ieee80211_frame) + 64, &sc->sc_drvbpf); - - sc->sc_rxtap_len = sizeof sc->sc_rxtapu; - sc->sc_rxtap.wr_ihdr.it_len = htole16(sc->sc_rxtap_len); - sc->sc_rxtap.wr_ihdr.it_present = htole32(RAL_RX_RADIOTAP_PRESENT); - - sc->sc_txtap_len = sizeof sc->sc_txtapu; - sc->sc_txtap.wt_ihdr.it_len = htole16(sc->sc_txtap_len); - sc->sc_txtap.wt_ihdr.it_present = htole32(RAL_TX_RADIOTAP_PRESENT); - - if (bootverbose) - ieee80211_announce(ic); - - return 0; -} - -static int -ural_detach(device_t self) -{ - struct ural_softc *sc = device_get_softc(self); - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; -#ifdef INVARIANTS - int i; -#endif - - crit_enter(); - - callout_stop(&sc->scan_ch); - callout_stop(&sc->stats_ch); - - lwkt_serialize_enter(ifp->if_serializer); - ural_stop(sc); - lwkt_serialize_exit(ifp->if_serializer); - - usb_rem_task(sc->sc_udev, &sc->sc_task); - - bpfdetach(ifp); - ieee80211_ifdetach(ic); - - crit_exit(); - - KKASSERT(sc->stats_xfer == NULL); - KKASSERT(sc->sc_rx_pipeh == NULL); - KKASSERT(sc->sc_tx_pipeh == NULL); - -#ifdef INVARIANTS - /* - * Make sure TX/RX list is empty - */ - for (i = 0; i < RAL_TX_LIST_COUNT; i++) { - struct ural_tx_data *data = &sc->tx_data[i]; - - KKASSERT(data->xfer == NULL); - KKASSERT(data->ni == NULL); - KKASSERT(data->m == NULL); - } - for (i = 0; i < RAL_RX_LIST_COUNT; i++) { - struct ural_rx_data *data = &sc->rx_data[i]; - - KKASSERT(data->xfer == NULL); - KKASSERT(data->m == NULL); - } -#endif - - return 0; -} - -static int -ural_alloc_tx_list(struct ural_softc *sc) -{ - int i; - - sc->tx_queued = 0; - - for (i = 0; i < RAL_TX_LIST_COUNT; i++) { - struct ural_tx_data *data = &sc->tx_data[i]; - - data->sc = sc; - - data->xfer = usbd_alloc_xfer(sc->sc_udev); - if (data->xfer == NULL) { - kprintf("%s: could not allocate tx xfer\n", - device_get_nameunit(sc->sc_dev)); - return ENOMEM; - } - - data->buf = usbd_alloc_buffer(data->xfer, - RAL_TX_DESC_SIZE + MCLBYTES); - if (data->buf == NULL) { - kprintf("%s: could not allocate tx buffer\n", - device_get_nameunit(sc->sc_dev)); - return ENOMEM; - } - } - return 0; -} - -static void -ural_free_tx_list(struct ural_softc *sc) -{ - int i; - - for (i = 0; i < RAL_TX_LIST_COUNT; i++) { - struct ural_tx_data *data = &sc->tx_data[i]; - - if (data->xfer != NULL) { - usbd_free_xfer(data->xfer); - data->xfer = NULL; - } - - if (data->ni != NULL) { - ieee80211_free_node(data->ni); - data->ni = NULL; - } - if (data->m != NULL) { - m_freem(data->m); - data->m = NULL; - } - } - sc->tx_queued = 0; -} - -static int -ural_alloc_rx_list(struct ural_softc *sc) -{ - int i; - - for (i = 0; i < RAL_RX_LIST_COUNT; i++) { - struct ural_rx_data *data = &sc->rx_data[i]; - - data->sc = sc; - - data->xfer = usbd_alloc_xfer(sc->sc_udev); - if (data->xfer == NULL) { - kprintf("%s: could not allocate rx xfer\n", - device_get_nameunit(sc->sc_dev)); - return ENOMEM; - } - - if (usbd_alloc_buffer(data->xfer, MCLBYTES) == NULL) { - kprintf("%s: could not allocate rx buffer\n", - device_get_nameunit(sc->sc_dev)); - return ENOMEM; - } - - data->m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR); - if (data->m == NULL) { - kprintf("%s: could not allocate rx mbuf\n", - device_get_nameunit(sc->sc_dev)); - return ENOMEM; - } - - data->buf = mtod(data->m, uint8_t *); - } - return 0; -} - -static void -ural_free_rx_list(struct ural_softc *sc) -{ - int i; - - for (i = 0; i < RAL_RX_LIST_COUNT; i++) { - struct ural_rx_data *data = &sc->rx_data[i]; - - if (data->xfer != NULL) { - usbd_free_xfer(data->xfer); - data->xfer = NULL; - } - - if (data->m != NULL) { - m_freem(data->m); - data->m = NULL; - } - } -} - -static int -ural_media_change(struct ifnet *ifp) -{ - struct ural_softc *sc = ifp->if_softc; - int error; - - error = ieee80211_media_change(ifp); - if (error != ENETRESET) - return error; - - if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) == (IFF_UP | IFF_RUNNING)) - ural_init(sc); - - return 0; -} - -/* - * This function is called periodically (every 200ms) during scanning to - * switch from one channel to another. - */ -static void -ural_next_scan(void *arg) -{ - struct ural_softc *sc = arg; - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - - if (sc->sc_stopped) - return; - - crit_enter(); - - if (ic->ic_state == IEEE80211_S_SCAN) { - lwkt_serialize_enter(ifp->if_serializer); - ieee80211_next_scan(ic); - lwkt_serialize_exit(ifp->if_serializer); - } - - crit_exit(); -} - -static void -ural_task(void *xarg) -{ - struct ural_softc *sc = xarg; - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - enum ieee80211_state nstate; - struct ieee80211_node *ni; - struct mbuf *m; - int arg; - - if (sc->sc_stopped) - return; - - crit_enter(); - - nstate = sc->sc_state; - arg = sc->sc_arg; - - KASSERT(nstate != IEEE80211_S_INIT, - ("->INIT state transition should not be defered\n")); - ural_set_chan(sc, ic->ic_curchan); - - switch (sc->sc_state) { - case IEEE80211_S_RUN: - ni = ic->ic_bss; - - if (ic->ic_opmode != IEEE80211_M_MONITOR) { - ural_update_slot(&ic->ic_if); - ural_set_txpreamble(sc); - ural_set_basicrates(sc); - ural_set_bssid(sc, ni->ni_bssid); - } - - if (ic->ic_opmode == IEEE80211_M_HOSTAP || - ic->ic_opmode == IEEE80211_M_IBSS) { - lwkt_serialize_enter(ifp->if_serializer); - m = ieee80211_beacon_alloc(ic, ni, &sc->sc_bo); - lwkt_serialize_exit(ifp->if_serializer); - - if (m == NULL) { - kprintf("%s: could not allocate beacon\n", - device_get_nameunit(sc->sc_dev)); - crit_exit(); - return; - } - - if (ural_tx_bcn(sc, m, ni) != 0) { - kprintf("%s: could not send beacon\n", - device_get_nameunit(sc->sc_dev)); - crit_exit(); - return; - } - } - - /* make tx led blink on tx (controlled by ASIC) */ - ural_write(sc, RAL_MAC_CSR20, 1); - - if (ic->ic_opmode != IEEE80211_M_MONITOR) - ural_enable_tsf_sync(sc); - - /* clear statistic registers (STA_CSR0 to STA_CSR10) */ - ural_read_multi(sc, RAL_STA_CSR0, sc->sta, sizeof(sc->sta)); - - callout_reset(&sc->stats_ch, 4 * hz / 5, - ural_stats_timeout, sc); - break; - - case IEEE80211_S_SCAN: - callout_reset(&sc->scan_ch, hz / 5, ural_next_scan, sc); - break; - - default: - break; - } - - lwkt_serialize_enter(ifp->if_serializer); - ieee80211_ratectl_newstate(ic, sc->sc_state); - sc->sc_newstate(ic, sc->sc_state, arg); - lwkt_serialize_exit(ifp->if_serializer); - - crit_exit(); -} - -static int -ural_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg) -{ - struct ifnet *ifp = &ic->ic_if; - struct ural_softc *sc = ifp->if_softc; - - ASSERT_SERIALIZED(ifp->if_serializer); - - crit_enter(); - - callout_stop(&sc->scan_ch); - callout_stop(&sc->stats_ch); - - /* do it in a process context */ - sc->sc_state = nstate; - sc->sc_arg = arg; - - lwkt_serialize_exit(ifp->if_serializer); - usb_rem_task(sc->sc_udev, &sc->sc_task); - - if (nstate == IEEE80211_S_INIT) { - lwkt_serialize_enter(ifp->if_serializer); - ieee80211_ratectl_newstate(ic, nstate); - sc->sc_newstate(ic, nstate, arg); - } else { - usb_add_task(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER); - lwkt_serialize_enter(ifp->if_serializer); - } - - crit_exit(); - return 0; -} - -/* quickly determine if a given rate is CCK or OFDM */ -#define RAL_RATE_IS_OFDM(rate) ((rate) >= 12 && (rate) != 22) - -#define RAL_ACK_SIZE (sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN) - -#define RAL_RXTX_TURNAROUND 5 /* us */ - -/* - * This function is only used by the Rx radiotap code. - */ -static int -ural_rxrate(struct ural_rx_desc *desc) -{ - if (le32toh(desc->flags) & RAL_RX_OFDM) { - /* reverse function of ural_plcp_signal */ - switch (desc->rate) { - case 0xb: return 12; - case 0xf: return 18; - case 0xa: return 24; - case 0xe: return 36; - case 0x9: return 48; - case 0xd: return 72; - case 0x8: return 96; - case 0xc: return 108; - } - } else { - if (desc->rate == 10) - return 2; - if (desc->rate == 20) - return 4; - if (desc->rate == 55) - return 11; - if (desc->rate == 110) - return 22; - } - return 2; /* should not get there */ -} - -static void -ural_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) -{ - struct ural_tx_data *data = priv; - struct ural_softc *sc = data->sc; - struct ieee80211_node *ni; - struct ifnet *ifp = &sc->sc_ic.ic_if; - - if (sc->sc_stopped) - return; - - crit_enter(); - - if (status != USBD_NORMAL_COMPLETION) { - if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { - crit_exit(); - return; - } - - kprintf("%s: could not transmit buffer: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(status)); - - if (status == USBD_STALLED) - usbd_clear_endpoint_stall_async(sc->sc_rx_pipeh); - - IFNET_STAT_INC(ifp, oerrors, 1); - crit_exit(); - return; - } - - m_freem(data->m); - data->m = NULL; - ni = data->ni; - data->ni = NULL; - - sc->tx_queued--; - IFNET_STAT_INC(ifp, opackets, 1); - - DPRINTFN(10, ("tx done\n")); - - sc->sc_tx_timer = 0; - ifq_clr_oactive(&ifp->if_snd); - - lwkt_serialize_enter(ifp->if_serializer); - ieee80211_free_node(ni); - ifp->if_start(ifp); - lwkt_serialize_exit(ifp->if_serializer); - - crit_exit(); -} - -static void -ural_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) -{ - struct ural_rx_data *data = priv; - struct ural_softc *sc = data->sc; - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - struct ural_rx_desc *desc; - struct ieee80211_frame *wh; - struct ieee80211_node *ni; - struct mbuf *mnew, *m; - int len; - - if (sc->sc_stopped) - return; - - crit_enter(); - - if (status != USBD_NORMAL_COMPLETION) { - if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { - crit_exit(); - return; - } - - if (status == USBD_STALLED) - usbd_clear_endpoint_stall_async(sc->sc_rx_pipeh); - goto skip; - } - - usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL); - - if (len < RAL_RX_DESC_SIZE + IEEE80211_MIN_LEN) { - DPRINTF(("%s: xfer too short %d\n", device_get_nameunit(sc->sc_dev), - len)); - IFNET_STAT_INC(ifp, ierrors, 1); - goto skip; - } - - /* rx descriptor is located at the end */ - desc = (struct ural_rx_desc *)(data->buf + len - RAL_RX_DESC_SIZE); - - if ((le32toh(desc->flags) & RAL_RX_PHY_ERROR) || - (le32toh(desc->flags) & RAL_RX_CRC_ERROR)) { - /* - * This should not happen since we did not request to receive - * those frames when we filled RAL_TXRX_CSR2. - */ - DPRINTFN(5, ("PHY or CRC error\n")); - IFNET_STAT_INC(ifp, ierrors, 1); - goto skip; - } - - mnew = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR); - if (mnew == NULL) { - IFNET_STAT_INC(ifp, ierrors, 1); - goto skip; - } - - m = data->m; - data->m = NULL; - data->buf = NULL; - - lwkt_serialize_enter(ifp->if_serializer); - - /* finalize mbuf */ - m->m_pkthdr.rcvif = ifp; - m->m_pkthdr.len = m->m_len = (le32toh(desc->flags) >> 16) & 0xfff; - - if (sc->sc_drvbpf != NULL) { - struct ural_rx_radiotap_header *tap = &sc->sc_rxtap; - - tap->wr_flags = IEEE80211_RADIOTAP_F_FCS; /* h/w leaves FCS */ - tap->wr_rate = ural_rxrate(desc); - tap->wr_chan_freq = htole16(ic->ic_curchan->ic_freq); - tap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); - tap->wr_antenna = sc->rx_ant; - tap->wr_antsignal = URAL_RSSI(desc->rssi); - - bpf_ptap(sc->sc_drvbpf, m, tap, sc->sc_rxtap_len); - } - - /* trim CRC here so WEP can find its own CRC at the end of packet. */ - m_adj(m, -IEEE80211_CRC_LEN); - - wh = mtod(m, struct ieee80211_frame *); - ni = ieee80211_find_rxnode(ic, (struct ieee80211_frame_min *)wh); - - /* send the frame to the 802.11 layer */ - ieee80211_input(ic, m, ni, URAL_RSSI(desc->rssi), 0); - - /* node is no longer needed */ - ieee80211_free_node(ni); - - lwkt_serialize_exit(ifp->if_serializer); - - data->m = mnew; - data->buf = mtod(data->m, uint8_t *); - - DPRINTFN(15, ("rx done\n")); - -skip: /* setup a new transfer */ - usbd_setup_xfer(xfer, sc->sc_rx_pipeh, data, data->buf, MCLBYTES, - USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, ural_rxeof); - usbd_transfer(xfer); - - crit_exit(); -} - -static uint8_t -ural_plcp_signal(int rate) -{ - switch (rate) { - /* CCK rates (returned values are device-dependent) */ - case 2: return 0x0; - case 4: return 0x1; - case 11: return 0x2; - case 22: return 0x3; - - /* OFDM rates (cf IEEE Std 802.11a-1999, pp. 14 Table 80) */ - case 12: return 0xb; - case 18: return 0xf; - case 24: return 0xa; - case 36: return 0xe; - case 48: return 0x9; - case 72: return 0xd; - case 96: return 0x8; - case 108: return 0xc; - - /* unsupported rates (should not get there) */ - default: return 0xff; - } -} - -static void -ural_setup_tx_desc(struct ural_softc *sc, struct ural_tx_desc *desc, - uint32_t flags, int len, int rate) -{ - struct ieee80211com *ic = &sc->sc_ic; - uint16_t plcp_length; - int remainder; - - desc->flags = htole32(flags); - desc->flags |= htole32(RAL_TX_NEWSEQ); - desc->flags |= htole32(len << 16); - - desc->wme = htole16(RAL_AIFSN(2) | RAL_LOGCWMIN(3) | RAL_LOGCWMAX(5)); - desc->wme |= htole16(RAL_IVOFFSET(sizeof (struct ieee80211_frame))); - - /* setup PLCP fields */ - desc->plcp_signal = ural_plcp_signal(rate); - desc->plcp_service = 4; - - len += IEEE80211_CRC_LEN; - if (RAL_RATE_IS_OFDM(rate)) { - desc->flags |= htole32(RAL_TX_OFDM); - - plcp_length = len & 0xfff; - desc->plcp_length_hi = plcp_length >> 6; - desc->plcp_length_lo = plcp_length & 0x3f; - } else { - plcp_length = (16 * len + rate - 1) / rate; - if (rate == 22) { - remainder = (16 * len) % 22; - if (remainder != 0 && remainder < 7) - desc->plcp_service |= RAL_PLCP_LENGEXT; - } - desc->plcp_length_hi = plcp_length >> 8; - desc->plcp_length_lo = plcp_length & 0xff; - - if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) - desc->plcp_signal |= 0x08; - } - - desc->iv = 0; - desc->eiv = 0; -} - -#define RAL_TX_TIMEOUT 5000 - -static int -ural_tx_bcn(struct ural_softc *sc, struct mbuf *m0, struct ieee80211_node *ni) -{ - struct ural_tx_desc *desc; - usbd_xfer_handle xfer; - uint8_t cmd = 0; - usbd_status error; - uint8_t *buf; - int xferlen, rate; - - rate = IEEE80211_IS_CHAN_5GHZ(ni->ni_chan) ? 12 : 2; - - xfer = usbd_alloc_xfer(sc->sc_udev); - if (xfer == NULL) - return ENOMEM; - - /* xfer length needs to be a multiple of two! */ - xferlen = (RAL_TX_DESC_SIZE + m0->m_pkthdr.len + 1) & ~1; - - buf = usbd_alloc_buffer(xfer, xferlen); - if (buf == NULL) { - usbd_free_xfer(xfer); - return ENOMEM; - } - - usbd_setup_xfer(xfer, sc->sc_tx_pipeh, NULL, &cmd, sizeof cmd, - USBD_FORCE_SHORT_XFER, RAL_TX_TIMEOUT, NULL); - - error = usbd_sync_transfer(xfer); - if (error != 0) { - usbd_free_xfer(xfer); - return error; - } - - desc = (struct ural_tx_desc *)buf; - - m_copydata(m0, 0, m0->m_pkthdr.len, buf + RAL_TX_DESC_SIZE); - ural_setup_tx_desc(sc, desc, RAL_TX_IFS_NEWBACKOFF | RAL_TX_TIMESTAMP, - m0->m_pkthdr.len, rate); - - DPRINTFN(10, ("sending beacon frame len=%u rate=%u xfer len=%u\n", - m0->m_pkthdr.len, rate, xferlen)); - - usbd_setup_xfer(xfer, sc->sc_tx_pipeh, NULL, buf, xferlen, - USBD_FORCE_SHORT_XFER | USBD_NO_COPY, RAL_TX_TIMEOUT, NULL); - - error = usbd_sync_transfer(xfer); - usbd_free_xfer(xfer); - - return error; -} - -static int -ural_tx_mgt(struct ural_softc *sc, struct mbuf *m0, struct ieee80211_node *ni) -{ - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - struct ural_tx_desc *desc; - struct ural_tx_data *data; - struct ieee80211_frame *wh; - uint32_t flags = 0; - uint16_t dur; - usbd_status error; - int xferlen, rate; - - data = &sc->tx_data[0]; - desc = (struct ural_tx_desc *)data->buf; - - rate = IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan) ? 12 : 2; - - data->m = m0; - data->ni = ni; - - wh = mtod(m0, struct ieee80211_frame *); - - if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { - flags |= RAL_TX_ACK; - - dur = ieee80211_txtime(ni, RAL_ACK_SIZE, rate, ic->ic_flags) + - sc->sc_sifs; - *(uint16_t *)wh->i_dur = htole16(dur); - - /* tell hardware to add timestamp for probe responses */ - if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == - IEEE80211_FC0_TYPE_MGT && - (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == - IEEE80211_FC0_SUBTYPE_PROBE_RESP) - flags |= RAL_TX_TIMESTAMP; - } - - if (sc->sc_drvbpf != NULL) { - struct ural_tx_radiotap_header *tap = &sc->sc_txtap; - - tap->wt_flags = 0; - tap->wt_rate = rate; - tap->wt_chan_freq = htole16(ic->ic_curchan->ic_freq); - tap->wt_chan_flags = htole16(ic->ic_curchan->ic_flags); - tap->wt_antenna = sc->tx_ant; - - bpf_ptap(sc->sc_drvbpf, m0, tap, sc->sc_txtap_len); - } - - m_copydata(m0, 0, m0->m_pkthdr.len, data->buf + RAL_TX_DESC_SIZE); - ural_setup_tx_desc(sc, desc, flags, m0->m_pkthdr.len, rate); - - /* align end on a 2-bytes boundary */ - xferlen = (RAL_TX_DESC_SIZE + m0->m_pkthdr.len + 1) & ~1; - - /* - * No space left in the last URB to store the extra 2 bytes, force - * sending of another URB. - */ - if ((xferlen % 64) == 0) - xferlen += 2; - - DPRINTFN(10, ("sending mgt frame len=%u rate=%u xfer len=%u\n", - m0->m_pkthdr.len, rate, xferlen)); - - lwkt_serialize_exit(ifp->if_serializer); - - usbd_setup_xfer(data->xfer, sc->sc_tx_pipeh, data, data->buf, - xferlen, USBD_FORCE_SHORT_XFER | USBD_NO_COPY, RAL_TX_TIMEOUT, - ural_txeof); - - error = usbd_transfer(data->xfer); - if (error != USBD_NORMAL_COMPLETION && error != USBD_IN_PROGRESS) { - m_freem(m0); - data->m = NULL; - data->ni = NULL; - } else { - sc->tx_queued++; - error = 0; - } - - lwkt_serialize_enter(ifp->if_serializer); - return error; -} - -static int -ural_tx_data(struct ural_softc *sc, struct mbuf *m0, struct ieee80211_node *ni) -{ - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - struct ural_tx_desc *desc; - struct ural_tx_data *data; - struct ieee80211_frame *wh; - struct ieee80211_key *k; - uint32_t flags = 0; - uint16_t dur; - usbd_status error; - int xferlen, rate, rate_idx; - - wh = mtod(m0, struct ieee80211_frame *); - - ieee80211_ratectl_findrate(ni, m0->m_pkthdr.len, &rate_idx, 1); - rate = IEEE80211_RS_RATE(&ni->ni_rates, rate_idx); - - if (wh->i_fc[1] & IEEE80211_FC1_WEP) { - k = ieee80211_crypto_encap(ic, ni, m0); - if (k == NULL) { - m_freem(m0); - return ENOBUFS; - } - - /* packet header may have moved, reset our local pointer */ - wh = mtod(m0, struct ieee80211_frame *); - } - - data = &sc->tx_data[0]; - desc = (struct ural_tx_desc *)data->buf; - - data->m = m0; - data->ni = ni; - - if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { - flags |= RAL_TX_ACK; - flags |= RAL_TX_RETRY(sc->sc_tx_retries); - - dur = ieee80211_txtime(ni, RAL_ACK_SIZE, - ieee80211_ack_rate(ni, rate), ic->ic_flags) + - sc->sc_sifs; - *(uint16_t *)wh->i_dur = htole16(dur); - } - - if (sc->sc_drvbpf != NULL) { - struct ural_tx_radiotap_header *tap = &sc->sc_txtap; - - tap->wt_flags = 0; - tap->wt_rate = rate; - tap->wt_chan_freq = htole16(ic->ic_curchan->ic_freq); - tap->wt_chan_flags = htole16(ic->ic_curchan->ic_flags); - tap->wt_antenna = sc->tx_ant; - - bpf_ptap(sc->sc_drvbpf, m0, tap, sc->sc_txtap_len); - } - - m_copydata(m0, 0, m0->m_pkthdr.len, data->buf + RAL_TX_DESC_SIZE); - ural_setup_tx_desc(sc, desc, flags, m0->m_pkthdr.len, rate); - - /* align end on a 2-bytes boundary */ - xferlen = (RAL_TX_DESC_SIZE + m0->m_pkthdr.len + 1) & ~1; - - /* - * No space left in the last URB to store the extra 2 bytes, force - * sending of another URB. - */ - if ((xferlen % 64) == 0) - xferlen += 2; - - DPRINTFN(10, ("sending data frame len=%u rate=%u xfer len=%u\n", - m0->m_pkthdr.len, rate, xferlen)); - - lwkt_serialize_exit(ifp->if_serializer); - - usbd_setup_xfer(data->xfer, sc->sc_tx_pipeh, data, data->buf, - xferlen, USBD_FORCE_SHORT_XFER | USBD_NO_COPY, RAL_TX_TIMEOUT, - ural_txeof); - - error = usbd_transfer(data->xfer); - if (error != USBD_NORMAL_COMPLETION && error != USBD_IN_PROGRESS) { - m_freem(m0); - data->m = NULL; - data->ni = NULL; - } else { - sc->tx_queued++; - error = 0; - } - - lwkt_serialize_enter(ifp->if_serializer); - return error; -} - -static void -ural_start(struct ifnet *ifp, struct ifaltq_subque *ifsq) -{ - struct ural_softc *sc = ifp->if_softc; - struct ieee80211com *ic = &sc->sc_ic; - - ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq); - ASSERT_SERIALIZED(ifp->if_serializer); - - if (sc->sc_stopped) { - ifq_purge(&ifp->if_snd); - return; - } - - crit_enter(); - - if ((ifp->if_flags & IFF_RUNNING) == 0 || - ifq_is_oactive(&ifp->if_snd)) { - crit_exit(); - return; - } - - for (;;) { - struct ieee80211_node *ni; - struct mbuf *m0; - - if (!IF_QEMPTY(&ic->ic_mgtq)) { - if (sc->tx_queued >= RAL_TX_LIST_COUNT) { - ifq_set_oactive(&ifp->if_snd); - break; - } - IF_DEQUEUE(&ic->ic_mgtq, m0); - - ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif; - m0->m_pkthdr.rcvif = NULL; - - if (ic->ic_rawbpf != NULL) - bpf_mtap(ic->ic_rawbpf, m0); - - if (ural_tx_mgt(sc, m0, ni) != 0) { - ieee80211_free_node(ni); - break; - } - } else { - struct ether_header *eh; - - if (ic->ic_state != IEEE80211_S_RUN) { - ifq_purge(&ifp->if_snd); - break; - } - - if (sc->tx_queued >= RAL_TX_LIST_COUNT) { - ifq_set_oactive(&ifp->if_snd); - break; - } - - m0 = ifq_dequeue(&ifp->if_snd); - if (m0 == NULL) - break; - - if (m0->m_len < sizeof (struct ether_header)) { - m0 = m_pullup(m0, sizeof (struct ether_header)); - if (m0 == NULL) { - IFNET_STAT_INC(ifp, oerrors, 1); - continue; - } - } - - eh = mtod(m0, struct ether_header *); - ni = ieee80211_find_txnode(ic, eh->ether_dhost); - if (ni == NULL) { - m_freem(m0); - continue; - } - BPF_MTAP(ifp, m0); - - m0 = ieee80211_encap(ic, m0, ni); - if (m0 == NULL) { - ieee80211_free_node(ni); - continue; - } - - if (ic->ic_rawbpf != NULL) - bpf_mtap(ic->ic_rawbpf, m0); - - if (ural_tx_data(sc, m0, ni) != 0) { - ieee80211_free_node(ni); - IFNET_STAT_INC(ifp, oerrors, 1); - break; - } - } - - sc->sc_tx_timer = 5; - ifp->if_timer = 1; - } - - crit_exit(); -} - -static void -ural_watchdog(struct ifnet *ifp) -{ - struct ural_softc *sc = ifp->if_softc; - struct ieee80211com *ic = &sc->sc_ic; - - ASSERT_SERIALIZED(ifp->if_serializer); - - crit_enter(); - - ifp->if_timer = 0; - - if (sc->sc_tx_timer > 0) { - if (--sc->sc_tx_timer == 0) { - device_printf(sc->sc_dev, "device timeout\n"); - /*ural_init(sc); XXX needs a process context! */ - IFNET_STAT_INC(ifp, oerrors, 1); - - crit_exit(); - return; - } - ifp->if_timer = 1; - } - ieee80211_watchdog(ic); - - crit_exit(); -} - -/* - * This function allows for fast channel switching in monitor mode (used by - * net-mgmt/kismet). In IBSS mode, we must explicitly reset the interface to - * generate a new beacon frame. - */ -static int -ural_reset(struct ifnet *ifp) -{ - struct ural_softc *sc = ifp->if_softc; - struct ieee80211com *ic = &sc->sc_ic; - - ASSERT_SERIALIZED(ifp->if_serializer); - - if (ic->ic_opmode != IEEE80211_M_MONITOR) - return ENETRESET; - - crit_enter(); - - lwkt_serialize_exit(ifp->if_serializer); - ural_set_chan(sc, ic->ic_curchan); - lwkt_serialize_enter(ifp->if_serializer); - - crit_exit(); - - return 0; -} - -static int -ural_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) -{ - struct ural_softc *sc = ifp->if_softc; - struct ieee80211com *ic = &sc->sc_ic; - int error = 0; - - ASSERT_SERIALIZED(ifp->if_serializer); - - crit_enter(); - - switch (cmd) { - case SIOCSIFFLAGS: - if (ifp->if_flags & IFF_UP) { - if (ifp->if_flags & IFF_RUNNING) { - lwkt_serialize_exit(ifp->if_serializer); - ural_update_promisc(sc); - lwkt_serialize_enter(ifp->if_serializer); - } else { - ural_init(sc); - } - } else { - if (ifp->if_flags & IFF_RUNNING) - ural_stop(sc); - } - break; - - default: - error = ieee80211_ioctl(ic, cmd, data, cr); - } - - if (error == ENETRESET) { - if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) == - (IFF_UP | IFF_RUNNING) && - ic->ic_roaming != IEEE80211_ROAMING_MANUAL) - ural_init(sc); - error = 0; - } - - crit_exit(); - return error; -} - -static void -ural_set_testmode(struct ural_softc *sc) -{ - usb_device_request_t req; - usbd_status error; - - req.bmRequestType = UT_WRITE_VENDOR_DEVICE; - req.bRequest = RAL_VENDOR_REQUEST; - USETW(req.wValue, 4); - USETW(req.wIndex, 1); - USETW(req.wLength, 0); - - error = usbd_do_request(sc->sc_udev, &req, NULL); - if (error != 0) { - kprintf("%s: could not set test mode: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(error)); - } -} - -static void -ural_eeprom_read(struct ural_softc *sc, uint16_t addr, void *buf, int len) -{ - usb_device_request_t req; - usbd_status error; - - req.bmRequestType = UT_READ_VENDOR_DEVICE; - req.bRequest = RAL_READ_EEPROM; - USETW(req.wValue, 0); - USETW(req.wIndex, addr); - USETW(req.wLength, len); - - error = usbd_do_request(sc->sc_udev, &req, buf); - if (error != 0) { - kprintf("%s: could not read EEPROM: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(error)); - } -} - -static uint16_t -ural_read(struct ural_softc *sc, uint16_t reg) -{ - usb_device_request_t req; - usbd_status error; - uint16_t val; - - req.bmRequestType = UT_READ_VENDOR_DEVICE; - req.bRequest = RAL_READ_MAC; - USETW(req.wValue, 0); - USETW(req.wIndex, reg); - USETW(req.wLength, sizeof (uint16_t)); - - error = usbd_do_request(sc->sc_udev, &req, &val); - if (error != 0) { - kprintf("%s: could not read MAC register: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(error)); - return 0; - } - - return le16toh(val); -} - -static void -ural_read_multi(struct ural_softc *sc, uint16_t reg, void *buf, int len) -{ - usb_device_request_t req; - usbd_status error; - - req.bmRequestType = UT_READ_VENDOR_DEVICE; - req.bRequest = RAL_READ_MULTI_MAC; - USETW(req.wValue, 0); - USETW(req.wIndex, reg); - USETW(req.wLength, len); - - error = usbd_do_request(sc->sc_udev, &req, buf); - if (error != 0) { - kprintf("%s: could not read MAC register: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(error)); - } -} - -static void -ural_write(struct ural_softc *sc, uint16_t reg, uint16_t val) -{ - usb_device_request_t req; - usbd_status error; - - req.bmRequestType = UT_WRITE_VENDOR_DEVICE; - req.bRequest = RAL_WRITE_MAC; - USETW(req.wValue, val); - USETW(req.wIndex, reg); - USETW(req.wLength, 0); - - error = usbd_do_request(sc->sc_udev, &req, NULL); - if (error != 0) { - kprintf("%s: could not write MAC register: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(error)); - } -} - -static void -ural_write_multi(struct ural_softc *sc, uint16_t reg, void *buf, int len) -{ - usb_device_request_t req; - usbd_status error; - - req.bmRequestType = UT_WRITE_VENDOR_DEVICE; - req.bRequest = RAL_WRITE_MULTI_MAC; - USETW(req.wValue, 0); - USETW(req.wIndex, reg); - USETW(req.wLength, len); - - error = usbd_do_request(sc->sc_udev, &req, buf); - if (error != 0) { - kprintf("%s: could not write MAC register: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(error)); - } -} - -static void -ural_bbp_write(struct ural_softc *sc, uint8_t reg, uint8_t val) -{ - uint16_t tmp; - int ntries; - - for (ntries = 0; ntries < 5; ntries++) { - if (!(ural_read(sc, RAL_PHY_CSR8) & RAL_BBP_BUSY)) - break; - } - if (ntries == 5) { - kprintf("%s: could not write to BBP\n", device_get_nameunit(sc->sc_dev)); - return; - } - - tmp = reg << 8 | val; - ural_write(sc, RAL_PHY_CSR7, tmp); -} - -static uint8_t -ural_bbp_read(struct ural_softc *sc, uint8_t reg) -{ - uint16_t val; - int ntries; - - val = RAL_BBP_WRITE | reg << 8; - ural_write(sc, RAL_PHY_CSR7, val); - - for (ntries = 0; ntries < 5; ntries++) { - if (!(ural_read(sc, RAL_PHY_CSR8) & RAL_BBP_BUSY)) - break; - } - if (ntries == 5) { - kprintf("%s: could not read BBP\n", device_get_nameunit(sc->sc_dev)); - return 0; - } - - return ural_read(sc, RAL_PHY_CSR7) & 0xff; -} - -static void -ural_rf_write(struct ural_softc *sc, uint8_t reg, uint32_t val) -{ - uint32_t tmp; - int ntries; - - for (ntries = 0; ntries < 5; ntries++) { - if (!(ural_read(sc, RAL_PHY_CSR10) & RAL_RF_LOBUSY)) - break; - } - if (ntries == 5) { - kprintf("%s: could not write to RF\n", device_get_nameunit(sc->sc_dev)); - return; - } - - tmp = RAL_RF_BUSY | RAL_RF_20BIT | (val & 0xfffff) << 2 | (reg & 0x3); - ural_write(sc, RAL_PHY_CSR9, tmp & 0xffff); - ural_write(sc, RAL_PHY_CSR10, tmp >> 16); - - /* remember last written value in sc */ - sc->rf_regs[reg] = val; - - DPRINTFN(15, ("RF R[%u] <- 0x%05x\n", reg & 0x3, val & 0xfffff)); -} - -static void -ural_set_chan(struct ural_softc *sc, struct ieee80211_channel *c) -{ - struct ieee80211com *ic = &sc->sc_ic; - uint8_t power, tmp; - u_int i, chan; - - chan = ieee80211_chan2ieee(ic, c); - if (chan == 0 || chan == IEEE80211_CHAN_ANY) - return; - - if (IEEE80211_IS_CHAN_2GHZ(c)) - power = min(sc->txpow[chan - 1], 31); - else - power = 31; - - /* adjust txpower using ifconfig settings */ - power -= (100 - ic->ic_txpowlimit) / 8; - - DPRINTFN(2, ("setting channel to %u, txpower to %u\n", chan, power)); - - switch (sc->rf_rev) { - case RAL_RF_2522: - ural_rf_write(sc, RAL_RF1, 0x00814); - ural_rf_write(sc, RAL_RF2, ural_rf2522_r2[chan - 1]); - ural_rf_write(sc, RAL_RF3, power << 7 | 0x00040); - break; - - case RAL_RF_2523: - ural_rf_write(sc, RAL_RF1, 0x08804); - ural_rf_write(sc, RAL_RF2, ural_rf2523_r2[chan - 1]); - ural_rf_write(sc, RAL_RF3, power << 7 | 0x38044); - ural_rf_write(sc, RAL_RF4, (chan == 14) ? 0x00280 : 0x00286); - break; - - case RAL_RF_2524: - ural_rf_write(sc, RAL_RF1, 0x0c808); - ural_rf_write(sc, RAL_RF2, ural_rf2524_r2[chan - 1]); - ural_rf_write(sc, RAL_RF3, power << 7 | 0x00040); - ural_rf_write(sc, RAL_RF4, (chan == 14) ? 0x00280 : 0x00286); - break; - - case RAL_RF_2525: - ural_rf_write(sc, RAL_RF1, 0x08808); - ural_rf_write(sc, RAL_RF2, ural_rf2525_hi_r2[chan - 1]); - ural_rf_write(sc, RAL_RF3, power << 7 | 0x18044); - ural_rf_write(sc, RAL_RF4, (chan == 14) ? 0x00280 : 0x00286); - - ural_rf_write(sc, RAL_RF1, 0x08808); - ural_rf_write(sc, RAL_RF2, ural_rf2525_r2[chan - 1]); - ural_rf_write(sc, RAL_RF3, power << 7 | 0x18044); - ural_rf_write(sc, RAL_RF4, (chan == 14) ? 0x00280 : 0x00286); - break; - - case RAL_RF_2525E: - ural_rf_write(sc, RAL_RF1, 0x08808); - ural_rf_write(sc, RAL_RF2, ural_rf2525e_r2[chan - 1]); - ural_rf_write(sc, RAL_RF3, power << 7 | 0x18044); - ural_rf_write(sc, RAL_RF4, (chan == 14) ? 0x00286 : 0x00282); - break; - - case RAL_RF_2526: - ural_rf_write(sc, RAL_RF2, ural_rf2526_hi_r2[chan - 1]); - ural_rf_write(sc, RAL_RF4, (chan & 1) ? 0x00386 : 0x00381); - ural_rf_write(sc, RAL_RF1, 0x08804); - - ural_rf_write(sc, RAL_RF2, ural_rf2526_r2[chan - 1]); - ural_rf_write(sc, RAL_RF3, power << 7 | 0x18044); - ural_rf_write(sc, RAL_RF4, (chan & 1) ? 0x00386 : 0x00381); - break; - - /* dual-band RF */ - case RAL_RF_5222: - for (i = 0; ural_rf5222[i].chan != chan; i++) - ; /* EMPTY */ - - ural_rf_write(sc, RAL_RF1, ural_rf5222[i].r1); - ural_rf_write(sc, RAL_RF2, ural_rf5222[i].r2); - ural_rf_write(sc, RAL_RF3, power << 7 | 0x00040); - ural_rf_write(sc, RAL_RF4, ural_rf5222[i].r4); - break; - } - - if (ic->ic_opmode != IEEE80211_M_MONITOR && - ic->ic_state != IEEE80211_S_SCAN) { - /* set Japan filter bit for channel 14 */ - tmp = ural_bbp_read(sc, 70); - - tmp &= ~RAL_JAPAN_FILTER; - if (chan == 14) - tmp |= RAL_JAPAN_FILTER; - - ural_bbp_write(sc, 70, tmp); - - /* clear CRC errors */ - ural_read(sc, RAL_STA_CSR0); - - DELAY(10000); - ural_disable_rf_tune(sc); - } - - sc->sc_sifs = IEEE80211_IS_CHAN_5GHZ(c) ? IEEE80211_DUR_OFDM_SIFS - : IEEE80211_DUR_SIFS; -} - -/* - * Disable RF auto-tuning. - */ -static void -ural_disable_rf_tune(struct ural_softc *sc) -{ - uint32_t tmp; - - if (sc->rf_rev != RAL_RF_2523) { - tmp = sc->rf_regs[RAL_RF1] & ~RAL_RF1_AUTOTUNE; - ural_rf_write(sc, RAL_RF1, tmp); - } - - tmp = sc->rf_regs[RAL_RF3] & ~RAL_RF3_AUTOTUNE; - ural_rf_write(sc, RAL_RF3, tmp); - - DPRINTFN(2, ("disabling RF autotune\n")); -} - -/* - * Refer to IEEE Std 802.11-1999 pp. 123 for more information on TSF - * synchronization. - */ -static void -ural_enable_tsf_sync(struct ural_softc *sc) -{ - struct ieee80211com *ic = &sc->sc_ic; - uint16_t logcwmin, preload, tmp; - - /* first, disable TSF synchronization */ - ural_write(sc, RAL_TXRX_CSR19, 0); - - tmp = (16 * ic->ic_bss->ni_intval) << 4; - ural_write(sc, RAL_TXRX_CSR18, tmp); - - logcwmin = (ic->ic_opmode == IEEE80211_M_IBSS) ? 2 : 0; - preload = (ic->ic_opmode == IEEE80211_M_IBSS) ? 320 : 6; - tmp = logcwmin << 12 | preload; - ural_write(sc, RAL_TXRX_CSR20, tmp); - - /* finally, enable TSF synchronization */ - tmp = RAL_ENABLE_TSF | RAL_ENABLE_TBCN; - if (ic->ic_opmode == IEEE80211_M_STA) - tmp |= RAL_ENABLE_TSF_SYNC(1); - else - tmp |= RAL_ENABLE_TSF_SYNC(2) | RAL_ENABLE_BEACON_GENERATOR; - ural_write(sc, RAL_TXRX_CSR19, tmp); - - DPRINTF(("enabling TSF synchronization\n")); -} - -static void -ural_update_slot(struct ifnet *ifp) -{ - struct ural_softc *sc = ifp->if_softc; - struct ieee80211com *ic = &sc->sc_ic; - uint16_t slottime, sifs, eifs; - - slottime = (ic->ic_flags & IEEE80211_F_SHSLOT) ? 9 : 20; - - /* - * These settings may sound a bit inconsistent but this is what the - * reference driver does. - */ - if (ic->ic_curmode == IEEE80211_MODE_11B) { - sifs = 16 - RAL_RXTX_TURNAROUND; - eifs = 364; - } else { - sifs = 10 - RAL_RXTX_TURNAROUND; - eifs = 64; - } - - ural_write(sc, RAL_MAC_CSR10, slottime); - ural_write(sc, RAL_MAC_CSR11, sifs); - ural_write(sc, RAL_MAC_CSR12, eifs); -} - -static void -ural_set_txpreamble(struct ural_softc *sc) -{ - uint16_t tmp; - - tmp = ural_read(sc, RAL_TXRX_CSR10); - - tmp &= ~RAL_SHORT_PREAMBLE; - if (sc->sc_ic.ic_flags & IEEE80211_F_SHPREAMBLE) - tmp |= RAL_SHORT_PREAMBLE; - - ural_write(sc, RAL_TXRX_CSR10, tmp); -} - -static void -ural_set_basicrates(struct ural_softc *sc) -{ - struct ieee80211com *ic = &sc->sc_ic; - - /* update basic rate set */ - if (ic->ic_curmode == IEEE80211_MODE_11B) { - /* 11b basic rates: 1, 2Mbps */ - ural_write(sc, RAL_TXRX_CSR11, 0x3); - } else if (IEEE80211_IS_CHAN_5GHZ(ic->ic_bss->ni_chan)) { - /* 11a basic rates: 6, 12, 24Mbps */ - ural_write(sc, RAL_TXRX_CSR11, 0x150); - } else { - /* 11g basic rates: 1, 2, 5.5, 11, 6, 12, 24Mbps */ - ural_write(sc, RAL_TXRX_CSR11, 0x15f); - } -} - -static void -ural_set_bssid(struct ural_softc *sc, uint8_t *bssid) -{ - uint16_t tmp; - struct ether_addr eaddr; - char ethstr[ETHER_ADDRSTRLEN + 1]; - - tmp = bssid[0] | bssid[1] << 8; - ural_write(sc, RAL_MAC_CSR5, tmp); - - tmp = bssid[2] | bssid[3] << 8; - ural_write(sc, RAL_MAC_CSR6, tmp); - - tmp = bssid[4] | bssid[5] << 8; - ural_write(sc, RAL_MAC_CSR7, tmp); - - bcopy(bssid, &eaddr.octet, sizeof(eaddr.octet)); - DPRINTF(("setting BSSID to %s\n", kether_ntoa(&eaddr, ethstr))); -} - -static void -ural_set_macaddr(struct ural_softc *sc, uint8_t *addr) -{ - uint16_t tmp; - struct ether_addr eaddr; - char ethstr[ETHER_ADDRSTRLEN + 1]; - - tmp = addr[0] | addr[1] << 8; - ural_write(sc, RAL_MAC_CSR2, tmp); - - tmp = addr[2] | addr[3] << 8; - ural_write(sc, RAL_MAC_CSR3, tmp); - - tmp = addr[4] | addr[5] << 8; - ural_write(sc, RAL_MAC_CSR4, tmp); - - bcopy(bssid, &eaddr.octet, sizeof(eaddr.octet)); - DPRINTF(("setting MAC address to %s\n", kether_ntoa(&eaddr, ethstr))); -} - -static void -ural_update_promisc(struct ural_softc *sc) -{ - struct ifnet *ifp = &sc->sc_ic.ic_if; - uint32_t tmp; - - tmp = ural_read(sc, RAL_TXRX_CSR2); - - tmp &= ~RAL_DROP_NOT_TO_ME; - if (!(ifp->if_flags & IFF_PROMISC)) - tmp |= RAL_DROP_NOT_TO_ME; - - ural_write(sc, RAL_TXRX_CSR2, tmp); - - DPRINTF(("%s promiscuous mode\n", (ifp->if_flags & IFF_PROMISC) ? - "entering" : "leaving")); -} - -static const char * -ural_get_rf(int rev) -{ - switch (rev) { - case RAL_RF_2522: return "RT2522"; - case RAL_RF_2523: return "RT2523"; - case RAL_RF_2524: return "RT2524"; - case RAL_RF_2525: return "RT2525"; - case RAL_RF_2525E: return "RT2525e"; - case RAL_RF_2526: return "RT2526"; - case RAL_RF_5222: return "RT5222"; - default: return "unknown"; - } -} - -static void -ural_read_eeprom(struct ural_softc *sc) -{ - struct ieee80211com *ic = &sc->sc_ic; - uint16_t val; - - ural_eeprom_read(sc, RAL_EEPROM_CONFIG0, &val, 2); - val = le16toh(val); - sc->rf_rev = (val >> 11) & 0x7; - sc->hw_radio = (val >> 10) & 0x1; - sc->led_mode = (val >> 6) & 0x7; - sc->rx_ant = (val >> 4) & 0x3; - sc->tx_ant = (val >> 2) & 0x3; - sc->nb_ant = val & 0x3; - - /* read MAC address */ - ural_eeprom_read(sc, RAL_EEPROM_ADDRESS, ic->ic_myaddr, 6); - - /* read default values for BBP registers */ - ural_eeprom_read(sc, RAL_EEPROM_BBP_BASE, sc->bbp_prom, 2 * 16); - - /* read Tx power for all b/g channels */ - ural_eeprom_read(sc, RAL_EEPROM_TXPOWER, sc->txpow, 14); -} - -static int -ural_bbp_init(struct ural_softc *sc) -{ -#define N(a) (sizeof (a) / sizeof ((a)[0])) - int i, ntries; - - /* wait for BBP to be ready */ - for (ntries = 0; ntries < 100; ntries++) { - if (ural_bbp_read(sc, RAL_BBP_VERSION) != 0) - break; - DELAY(1000); - } - if (ntries == 100) { - device_printf(sc->sc_dev, "timeout waiting for BBP\n"); - return EIO; - } - - /* initialize BBP registers to default values */ - for (i = 0; i < N(ural_def_bbp); i++) - ural_bbp_write(sc, ural_def_bbp[i].reg, ural_def_bbp[i].val); - -#if 0 - /* initialize BBP registers to values stored in EEPROM */ - for (i = 0; i < 16; i++) { - if (sc->bbp_prom[i].reg == 0xff) - continue; - ural_bbp_write(sc, sc->bbp_prom[i].reg, sc->bbp_prom[i].val); - } -#endif - - return 0; -#undef N -} - -static void -ural_set_txantenna(struct ural_softc *sc, int antenna) -{ - uint16_t tmp; - uint8_t tx; - - tx = ural_bbp_read(sc, RAL_BBP_TX) & ~RAL_BBP_ANTMASK; - if (antenna == 1) - tx |= RAL_BBP_ANTA; - else if (antenna == 2) - tx |= RAL_BBP_ANTB; - else - tx |= RAL_BBP_DIVERSITY; - - /* need to force I/Q flip for RF 2525e, 2526 and 5222 */ - if (sc->rf_rev == RAL_RF_2525E || sc->rf_rev == RAL_RF_2526 || - sc->rf_rev == RAL_RF_5222) - tx |= RAL_BBP_FLIPIQ; - - ural_bbp_write(sc, RAL_BBP_TX, tx); - - /* update values in PHY_CSR5 and PHY_CSR6 */ - tmp = ural_read(sc, RAL_PHY_CSR5) & ~0x7; - ural_write(sc, RAL_PHY_CSR5, tmp | (tx & 0x7)); - - tmp = ural_read(sc, RAL_PHY_CSR6) & ~0x7; - ural_write(sc, RAL_PHY_CSR6, tmp | (tx & 0x7)); -} - -static void -ural_set_rxantenna(struct ural_softc *sc, int antenna) -{ - uint8_t rx; - - rx = ural_bbp_read(sc, RAL_BBP_RX) & ~RAL_BBP_ANTMASK; - if (antenna == 1) - rx |= RAL_BBP_ANTA; - else if (antenna == 2) - rx |= RAL_BBP_ANTB; - else - rx |= RAL_BBP_DIVERSITY; - - /* need to force no I/Q flip for RF 2525e and 2526 */ - if (sc->rf_rev == RAL_RF_2525E || sc->rf_rev == RAL_RF_2526) - rx &= ~RAL_BBP_FLIPIQ; - - ural_bbp_write(sc, RAL_BBP_RX, rx); -} - -static void -ural_init(void *priv) -{ -#define N(a) (sizeof (a) / sizeof ((a)[0])) - struct ural_softc *sc = priv; - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - struct ural_rx_data *data; - uint16_t tmp; - usbd_status usb_err; - int i, ntries, error; - - ASSERT_SERIALIZED(ifp->if_serializer); - - crit_enter(); - - lwkt_serialize_exit(ifp->if_serializer); - ural_set_testmode(sc); - ural_write(sc, 0x308, 0x00f0); /* XXX magic */ - lwkt_serialize_enter(ifp->if_serializer); - - ural_stop(sc); - sc->sc_stopped = 0; - - lwkt_serialize_exit(ifp->if_serializer); - - /* initialize MAC registers to default values */ - for (i = 0; i < N(ural_def_mac); i++) - ural_write(sc, ural_def_mac[i].reg, ural_def_mac[i].val); - - /* wait for BBP and RF to wake up (this can take a long time!) */ - for (ntries = 0; ntries < 100; ntries++) { - tmp = ural_read(sc, RAL_MAC_CSR17); - if ((tmp & (RAL_BBP_AWAKE | RAL_RF_AWAKE)) == - (RAL_BBP_AWAKE | RAL_RF_AWAKE)) - break; - DELAY(1000); - } - if (ntries == 100) { - kprintf("%s: timeout waiting for BBP/RF to wakeup\n", - device_get_nameunit(sc->sc_dev)); - error = ETIMEDOUT; - goto fail; - } - - /* we're ready! */ - ural_write(sc, RAL_MAC_CSR1, RAL_HOST_READY); - - /* set basic rate set (will be updated later) */ - ural_write(sc, RAL_TXRX_CSR11, 0x15f); - - error = ural_bbp_init(sc); - if (error) - goto fail; - - /* set default BSS channel */ - ural_set_chan(sc, ic->ic_curchan); - - /* clear statistic registers (STA_CSR0 to STA_CSR10) */ - ural_read_multi(sc, RAL_STA_CSR0, sc->sta, sizeof sc->sta); - - ural_set_txantenna(sc, sc->tx_ant); - ural_set_rxantenna(sc, sc->rx_ant); - - IEEE80211_ADDR_COPY(ic->ic_myaddr, IF_LLADDR(ifp)); - ural_set_macaddr(sc, ic->ic_myaddr); - - /* - * Allocate xfer for AMRR statistics requests. - */ - sc->stats_xfer = usbd_alloc_xfer(sc->sc_udev); - if (sc->stats_xfer == NULL) { - kprintf("%s: could not allocate AMRR xfer\n", - device_get_nameunit(sc->sc_dev)); - error = ENOMEM; - goto fail; - } - - /* - * Open Tx and Rx USB bulk pipes. - */ - usb_err = usbd_open_pipe(sc->sc_iface, sc->sc_tx_no, USBD_EXCLUSIVE_USE, - &sc->sc_tx_pipeh); - if (usb_err != 0) { - kprintf("%s: could not open Tx pipe: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(usb_err)); - error = ENOMEM; - goto fail; - } - - usb_err = usbd_open_pipe(sc->sc_iface, sc->sc_rx_no, USBD_EXCLUSIVE_USE, - &sc->sc_rx_pipeh); - if (usb_err != 0) { - kprintf("%s: could not open Rx pipe: %s\n", - device_get_nameunit(sc->sc_dev), usbd_errstr(usb_err)); - error = ENOMEM; - goto fail; - } - - /* - * Allocate Tx and Rx xfer queues. - */ - error = ural_alloc_tx_list(sc); - if (error) { - kprintf("%s: could not allocate Tx list\n", - device_get_nameunit(sc->sc_dev)); - goto fail; - } - - error = ural_alloc_rx_list(sc); - if (error) { - kprintf("%s: could not allocate Rx list\n", - device_get_nameunit(sc->sc_dev)); - goto fail; - } - - /* - * Start up the receive pipe. - */ - for (i = 0; i < RAL_RX_LIST_COUNT; i++) { - data = &sc->rx_data[i]; - - usbd_setup_xfer(data->xfer, sc->sc_rx_pipeh, data, data->buf, - MCLBYTES, USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, ural_rxeof); - usbd_transfer(data->xfer); - } - - /* kick Rx */ - tmp = RAL_DROP_PHY | RAL_DROP_CRC; - if (ic->ic_opmode != IEEE80211_M_MONITOR) { - tmp |= RAL_DROP_CTL | RAL_DROP_BAD_VERSION; - if (ic->ic_opmode != IEEE80211_M_HOSTAP) - tmp |= RAL_DROP_TODS; - if (!(ifp->if_flags & IFF_PROMISC)) - tmp |= RAL_DROP_NOT_TO_ME; - } - ural_write(sc, RAL_TXRX_CSR2, tmp); - - /* clear statistic registers (STA_CSR0 to STA_CSR10) */ - ural_read_multi(sc, RAL_STA_CSR0, sc->sta, sizeof(sc->sta)); -fail: - lwkt_serialize_enter(ifp->if_serializer); - if (error) { - ural_stop(sc); - } else { - ifq_clr_oactive(&ifp->if_snd); - ifp->if_flags |= IFF_RUNNING; - - if (ic->ic_opmode != IEEE80211_M_MONITOR) { - if (ic->ic_roaming != IEEE80211_ROAMING_MANUAL) - ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); - } else { - ieee80211_new_state(ic, IEEE80211_S_RUN, -1); - } - } - - crit_exit(); -#undef N -} - -static void -ural_stop(struct ural_softc *sc) -{ - struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; - - ASSERT_SERIALIZED(ifp->if_serializer); - - crit_enter(); - - ifp->if_flags &= ~IFF_RUNNING; - ifq_clr_oactive(&ifp->if_snd); - sc->sc_stopped = 1; - - ieee80211_new_state(ic, IEEE80211_S_INIT, -1); - - sc->sc_tx_timer = 0; - ifp->if_timer = 0; - - lwkt_serialize_exit(ifp->if_serializer); - - /* disable Rx */ - ural_write(sc, RAL_TXRX_CSR2, RAL_DISABLE_RX); - - /* reset ASIC and BBP (but won't reset MAC registers!) */ - ural_write(sc, RAL_MAC_CSR1, RAL_RESET_ASIC | RAL_RESET_BBP); - ural_write(sc, RAL_MAC_CSR1, 0); - - if (sc->stats_xfer != NULL) { - usbd_free_xfer(sc->stats_xfer); - sc->stats_xfer = NULL; - } - - if (sc->sc_rx_pipeh != NULL) { - usbd_abort_pipe(sc->sc_rx_pipeh); - usbd_close_pipe(sc->sc_rx_pipeh); - sc->sc_rx_pipeh = NULL; - } - - if (sc->sc_tx_pipeh != NULL) { - usbd_abort_pipe(sc->sc_tx_pipeh); - usbd_close_pipe(sc->sc_tx_pipeh); - sc->sc_tx_pipeh = NULL; - } - - lwkt_serialize_enter(ifp->if_serializer); - - ural_free_rx_list(sc); - ural_free_tx_list(sc); - - crit_exit(); -} - -static void -ural_stats_timeout(void *arg) -{ - struct ural_softc *sc = (struct ural_softc *)arg; - usb_device_request_t req; - - if (sc->sc_stopped) - return; - - crit_enter(); - - /* - * Asynchronously read statistic registers (cleared by read). - */ - req.bmRequestType = UT_READ_VENDOR_DEVICE; - req.bRequest = RAL_READ_MULTI_MAC; - USETW(req.wValue, 0); - USETW(req.wIndex, RAL_STA_CSR0); - USETW(req.wLength, sizeof(sc->sta)); - - usbd_setup_default_xfer(sc->stats_xfer, sc->sc_udev, sc, - USBD_DEFAULT_TIMEOUT, &req, - sc->sta, sizeof(sc->sta), 0, - ural_stats_update); - usbd_transfer(sc->stats_xfer); - - crit_exit(); -} - -static void -ural_stats_update(usbd_xfer_handle xfer, usbd_private_handle priv, - usbd_status status) -{ - struct ural_softc *sc = (struct ural_softc *)priv; - struct ifnet *ifp = &sc->sc_ic.ic_if; - struct ieee80211_ratectl_stats *stats = &sc->sc_stats; - - if (status != USBD_NORMAL_COMPLETION) { - device_printf(sc->sc_dev, "could not retrieve Tx statistics - " - "cancelling automatic rate control\n"); - return; - } - - crit_enter(); - - /* count TX retry-fail as Tx errors */ - IFNET_STAT_INC(ifp, oerrors, sc->sta[RAL_TX_PKT_FAIL]); - - stats->stats_pkt_ok += sc->sta[RAL_TX_PKT_NO_RETRY] + - sc->sta[RAL_TX_PKT_ONE_RETRY] + - sc->sta[RAL_TX_PKT_MULTI_RETRY]; - - stats->stats_pkt_err += sc->sta[RAL_TX_PKT_FAIL]; - - stats->stats_pkt_noretry += sc->sta[RAL_TX_PKT_NO_RETRY]; - - stats->stats_retries += sc->sta[RAL_TX_PKT_ONE_RETRY]; -#if 1 - /* - * XXX Estimated average: - * Actual number of retries for each packet should belong to - * [2, sc->sc_tx_retries] - */ - stats->stats_retries += sc->sta[RAL_TX_PKT_MULTI_RETRY] * - ((2 + sc->sc_tx_retries) / 2); -#else - stats->stats_retries += sc->sta[RAL_TX_PKT_MULTI_RETRY]; -#endif - stats->stats_retries += sc->sta[RAL_TX_PKT_FAIL] * sc->sc_tx_retries; - - callout_reset(&sc->stats_ch, 4 * hz / 5, ural_stats_timeout, sc); - - crit_exit(); -} - -static void -ural_stats(struct ieee80211com *ic, struct ieee80211_node *ni __unused, - struct ieee80211_ratectl_stats *stats) -{ - struct ifnet *ifp = &ic->ic_if; - struct ural_softc *sc = ifp->if_softc; - - ASSERT_SERIALIZED(ifp->if_serializer); - - bcopy(&sc->sc_stats, stats, sizeof(*stats)); - bzero(&sc->sc_stats, sizeof(sc->sc_stats)); -} - -static void * -ural_ratectl_attach(struct ieee80211com *ic, u_int rc) -{ - struct ural_softc *sc = ic->ic_if.if_softc; - - switch (rc) { - case IEEE80211_RATECTL_ONOE: - return &sc->sc_onoe_param; - case IEEE80211_RATECTL_NONE: - /* This could only happen during detaching */ - return NULL; - default: - panic("unknown rate control algo %u", rc); - return NULL; - } -} diff --git a/sys/dev/netif/ural/if_uralreg.h b/sys/dev/netif/ural/if_uralreg.h deleted file mode 100644 index f82e9cf36a..0000000000 --- a/sys/dev/netif/ural/if_uralreg.h +++ /dev/null @@ -1,211 +0,0 @@ -/* $FreeBSD: src/sys/dev/usb/if_uralreg.h,v 1.1.2.1 2006/01/29 14:16:36 damien Exp $ */ -/* $DragonFly: src/sys/dev/netif/ural/if_uralreg.h,v 1.2 2007/02/06 13:50:25 sephe Exp $ */ - -/*- - * Copyright (c) 2005, 2006 - * Damien Bergamini - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#define RAL_NOISE_FLOOR -95 -#define RAL_RSSI_CORR 120 - -#define RAL_RX_DESC_SIZE (sizeof (struct ural_rx_desc)) -#define RAL_TX_DESC_SIZE (sizeof (struct ural_tx_desc)) - -#define RAL_CONFIG_NO 1 -#define RAL_IFACE_INDEX 0 - -#define RAL_VENDOR_REQUEST 0x01 -#define RAL_WRITE_MAC 0x02 -#define RAL_READ_MAC 0x03 -#define RAL_WRITE_MULTI_MAC 0x06 -#define RAL_READ_MULTI_MAC 0x07 -#define RAL_READ_EEPROM 0x09 - -/* - * MAC registers. - */ -#define RAL_MAC_CSR0 0x0400 /* ASIC Version */ -#define RAL_MAC_CSR1 0x0402 /* System control */ -#define RAL_MAC_CSR2 0x0404 /* MAC addr0 */ -#define RAL_MAC_CSR3 0x0406 /* MAC addr1 */ -#define RAL_MAC_CSR4 0x0408 /* MAC addr2 */ -#define RAL_MAC_CSR5 0x040a /* BSSID0 */ -#define RAL_MAC_CSR6 0x040c /* BSSID1 */ -#define RAL_MAC_CSR7 0x040e /* BSSID2 */ -#define RAL_MAC_CSR8 0x0410 /* Max frame length */ -#define RAL_MAC_CSR9 0x0412 /* Timer control */ -#define RAL_MAC_CSR10 0x0414 /* Slot time */ -#define RAL_MAC_CSR11 0x0416 /* IFS */ -#define RAL_MAC_CSR12 0x0418 /* EIFS */ -#define RAL_MAC_CSR13 0x041a /* Power mode0 */ -#define RAL_MAC_CSR14 0x041c /* Power mode1 */ -#define RAL_MAC_CSR15 0x041e /* Power saving transition0 */ -#define RAL_MAC_CSR16 0x0420 /* Power saving transition1 */ -#define RAL_MAC_CSR17 0x0422 /* Power state control */ -#define RAL_MAC_CSR18 0x0424 /* Auto wake-up control */ -#define RAL_MAC_CSR19 0x0426 /* GPIO control */ -#define RAL_MAC_CSR20 0x0428 /* LED control0 */ -#define RAL_MAC_CSR22 0x042c /* XXX not documented */ - -/* - * Tx/Rx Registers. - */ -#define RAL_TXRX_CSR0 0x0440 /* Security control */ -#define RAL_TXRX_CSR2 0x0444 /* Rx control */ -#define RAL_TXRX_CSR5 0x044a /* CCK Tx BBP ID0 */ -#define RAL_TXRX_CSR6 0x044c /* CCK Tx BBP ID1 */ -#define RAL_TXRX_CSR7 0x044e /* OFDM Tx BBP ID0 */ -#define RAL_TXRX_CSR8 0x0450 /* OFDM Tx BBP ID1 */ -#define RAL_TXRX_CSR10 0x0454 /* Auto responder control */ -#define RAL_TXRX_CSR11 0x0456 /* Auto responder basic rate */ -#define RAL_TXRX_CSR18 0x0464 /* Beacon interval */ -#define RAL_TXRX_CSR19 0x0466 /* Beacon/sync control */ -#define RAL_TXRX_CSR20 0x0468 /* Beacon alignment */ -#define RAL_TXRX_CSR21 0x046a /* XXX not documented */ - -/* - * Security registers. - */ -#define RAL_SEC_CSR0 0x0480 /* Shared key 0, word 0 */ - -/* - * PHY registers. - */ -#define RAL_PHY_CSR2 0x04c4 /* Tx MAC configuration */ -#define RAL_PHY_CSR4 0x04c8 /* Interface configuration */ -#define RAL_PHY_CSR5 0x04ca /* BBP Pre-Tx CCK */ -#define RAL_PHY_CSR6 0x04cc /* BBP Pre-Tx OFDM */ -#define RAL_PHY_CSR7 0x04ce /* BBP serial control */ -#define RAL_PHY_CSR8 0x04d0 /* BBP serial status */ -#define RAL_PHY_CSR9 0x04d2 /* RF serial control0 */ -#define RAL_PHY_CSR10 0x04d4 /* RF serial control1 */ - -/* - * Statistics registers. - */ -#define RAL_STA_CSR0 0x04e0 /* FCS error */ - - -#define RAL_DISABLE_RX (1 << 0) -#define RAL_DROP_CRC (1 << 1) -#define RAL_DROP_PHY (1 << 2) -#define RAL_DROP_CTL (1 << 3) -#define RAL_DROP_NOT_TO_ME (1 << 4) -#define RAL_DROP_TODS (1 << 5) -#define RAL_DROP_BAD_VERSION (1 << 6) -#define RAL_DROP_MULTICAST (1 << 9) -#define RAL_DROP_BROADCAST (1 << 10) - -#define RAL_SHORT_PREAMBLE (1 << 2) - -#define RAL_RESET_ASIC (1 << 0) -#define RAL_RESET_BBP (1 << 1) -#define RAL_HOST_READY (1 << 2) - -#define RAL_ENABLE_TSF (1 << 0) -#define RAL_ENABLE_TSF_SYNC(x) (((x) & 0x3) << 1) -#define RAL_ENABLE_TBCN (1 << 3) -#define RAL_ENABLE_BEACON_GENERATOR (1 << 4) - -#define RAL_RF_AWAKE (3 << 7) -#define RAL_BBP_AWAKE (3 << 5) - -#define RAL_BBP_WRITE (1 << 15) -#define RAL_BBP_BUSY (1 << 0) - -#define RAL_RF1_AUTOTUNE 0x08000 -#define RAL_RF3_AUTOTUNE 0x00040 - -#define RAL_RF_2522 0x00 -#define RAL_RF_2523 0x01 -#define RAL_RF_2524 0x02 -#define RAL_RF_2525 0x03 -#define RAL_RF_2525E 0x04 -#define RAL_RF_2526 0x05 -/* dual-band RF */ -#define RAL_RF_5222 0x10 - -#define RAL_BBP_VERSION 0 -#define RAL_BBP_TX 2 -#define RAL_BBP_RX 14 - -#define RAL_BBP_ANTA 0x00 -#define RAL_BBP_DIVERSITY 0x01 -#define RAL_BBP_ANTB 0x02 -#define RAL_BBP_ANTMASK 0x03 -#define RAL_BBP_FLIPIQ 0x04 - -#define RAL_JAPAN_FILTER 0x08 - -struct ural_tx_desc { - uint32_t flags; -#define RAL_TX_RETRY(x) ((x) << 4) -#define RAL_TX_MORE_FRAG (1 << 8) -#define RAL_TX_ACK (1 << 9) -#define RAL_TX_TIMESTAMP (1 << 10) -#define RAL_TX_OFDM (1 << 11) -#define RAL_TX_NEWSEQ (1 << 12) - -#define RAL_TX_IFS_MASK 0x00006000 -#define RAL_TX_IFS_BACKOFF (0 << 13) -#define RAL_TX_IFS_SIFS (1 << 13) -#define RAL_TX_IFS_NEWBACKOFF (2 << 13) -#define RAL_TX_IFS_NONE (3 << 13) - - uint16_t wme; -#define RAL_LOGCWMAX(x) (((x) & 0xf) << 12) -#define RAL_LOGCWMIN(x) (((x) & 0xf) << 8) -#define RAL_AIFSN(x) (((x) & 0x3) << 6) -#define RAL_IVOFFSET(x) (((x) & 0x3f)) - - uint16_t reserved1; - uint8_t plcp_signal; - uint8_t plcp_service; -#define RAL_PLCP_LENGEXT 0x80 - - uint8_t plcp_length_lo; - uint8_t plcp_length_hi; - uint32_t iv; - uint32_t eiv; -} __packed; - -struct ural_rx_desc { - uint32_t flags; -#define RAL_RX_CRC_ERROR (1 << 5) -#define RAL_RX_OFDM (1 << 6) -#define RAL_RX_PHY_ERROR (1 << 7) - - uint8_t rssi; - uint8_t rate; - uint16_t reserved; - - uint32_t iv; - uint32_t eiv; -} __packed; - -#define RAL_RF_LOBUSY (1 << 15) -#define RAL_RF_BUSY (1 << 31) -#define RAL_RF_20BIT (20 << 24) - -#define RAL_RF1 0 -#define RAL_RF2 2 -#define RAL_RF3 1 -#define RAL_RF4 3 - -#define RAL_EEPROM_ADDRESS 0x0004 -#define RAL_EEPROM_TXPOWER 0x003c -#define RAL_EEPROM_CONFIG0 0x0016 -#define RAL_EEPROM_BBP_BASE 0x001c diff --git a/sys/dev/netif/ural/if_uralvar.h b/sys/dev/netif/ural/if_uralvar.h deleted file mode 100644 index 603d774749..0000000000 --- a/sys/dev/netif/ural/if_uralvar.h +++ /dev/null @@ -1,159 +0,0 @@ -/* $FreeBSD: src/sys/dev/usb/if_uralvar.h,v 1.3.2.3 2006/01/29 14:16:36 damien Exp $ */ -/* $DragonFly: src/sys/dev/netif/ural/if_uralvar.h,v 1.7 2008/01/15 09:01:13 sephe Exp $ */ - -/*- - * Copyright (c) 2005, 2006 - * Damien Bergamini - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#define RAL_RX_LIST_COUNT 1 -#define RAL_TX_LIST_COUNT 1 - -struct ural_rx_radiotap_header { - struct ieee80211_radiotap_header wr_ihdr; - uint8_t wr_flags; - uint8_t wr_rate; - uint16_t wr_chan_freq; - uint16_t wr_chan_flags; - uint8_t wr_antenna; - uint8_t wr_antsignal; -}; - -#define RAL_RX_RADIOTAP_PRESENT \ - ((1 << IEEE80211_RADIOTAP_FLAGS) | \ - (1 << IEEE80211_RADIOTAP_RATE) | \ - (1 << IEEE80211_RADIOTAP_CHANNEL) | \ - (1 << IEEE80211_RADIOTAP_ANTENNA) | \ - (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)) - -struct ural_tx_radiotap_header { - struct ieee80211_radiotap_header wt_ihdr; - uint8_t wt_flags; - uint8_t wt_rate; - uint16_t wt_chan_freq; - uint16_t wt_chan_flags; - uint8_t wt_antenna; -}; - -#define RAL_TX_RADIOTAP_PRESENT \ - ((1 << IEEE80211_RADIOTAP_FLAGS) | \ - (1 << IEEE80211_RADIOTAP_RATE) | \ - (1 << IEEE80211_RADIOTAP_CHANNEL) | \ - (1 << IEEE80211_RADIOTAP_ANTENNA)) - -struct ural_softc; - -struct ural_tx_data { - struct ural_softc *sc; - usbd_xfer_handle xfer; - uint8_t *buf; - struct mbuf *m; - struct ieee80211_node *ni; -}; - -struct ural_rx_data { - struct ural_softc *sc; - usbd_xfer_handle xfer; - uint8_t *buf; - struct mbuf *m; -}; - -struct ural_softc { - struct ieee80211com sc_ic; - int sc_stopped; - - int (*sc_newstate)(struct ieee80211com *, - enum ieee80211_state, int); - device_t sc_dev; - usbd_device_handle sc_udev; - usbd_interface_handle sc_iface; - - int sc_rx_no; - int sc_tx_no; - - uint32_t asic_rev; - uint8_t rf_rev; - - usbd_xfer_handle stats_xfer; - - usbd_pipe_handle sc_rx_pipeh; - usbd_pipe_handle sc_tx_pipeh; - - enum ieee80211_state sc_state; - int sc_arg; - int sc_sifs; - struct usb_task sc_task; - - struct ural_rx_data rx_data[RAL_RX_LIST_COUNT]; - struct ural_tx_data tx_data[RAL_TX_LIST_COUNT]; - int tx_queued; - - struct ieee80211_beacon_offsets sc_bo; - - struct ieee80211_ratectl_stats sc_stats; - int sc_tx_retries; - - struct callout scan_ch; - struct callout stats_ch; - - int sc_tx_timer; - - uint16_t sta[11]; - uint32_t rf_regs[4]; - uint8_t txpow[14]; - - struct { - uint8_t val; - uint8_t reg; - } __packed bbp_prom[16]; - - int led_mode; - int hw_radio; - int rx_ant; - int tx_ant; - int nb_ant; - - struct bpf_if *sc_drvbpf; - - union { - struct ural_rx_radiotap_header th; - uint8_t pad[64]; - } sc_rxtapu; -#define sc_rxtap sc_rxtapu.th - int sc_rxtap_len; - - union { - struct ural_tx_radiotap_header th; - uint8_t pad[64]; - } sc_txtapu; -#define sc_txtap sc_txtapu.th - int sc_txtap_len; - - struct ieee80211_onoe_param sc_onoe_param; -}; - -/* - * Offsets into ural_softc.stap[] - */ -/* - * Counters located at RAL_TX_PKT_ are the numbers of packets successfully - * or unsuccessfully transmitted. Though you can calculate the number of - * transmissions from certain counter (e.g. NO_RETRY, ONE_RETRY and FAIL), - * the counters are NOT the number of transmissions (e.g. MULTI_RETRY). - */ -#define RAL_TX_PKT_NO_RETRY 6 -#define RAL_TX_PKT_ONE_RETRY 7 -#define RAL_TX_PKT_MULTI_RETRY 8 -#define RAL_TX_PKT_FAIL 9 -- 2.41.0