Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Jan 2009 01:29:22 +0000 (UTC)
From:      Andrew Thompson <thompsa@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r187753 - user/thompsa/usb/sys/dev/usb2/wlan
Message-ID:  <200901270129.n0R1TMr9069496@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: thompsa
Date: Tue Jan 27 01:29:22 2009
New Revision: 187753
URL: http://svn.freebsd.org/changeset/base/187753

Log:
  Revert back to the sys/dev/usb copy of the wlan drivers in preparation of
  removing the config thread.

Modified:
  user/thompsa/usb/sys/dev/usb2/wlan/if_rum2.c
  user/thompsa/usb/sys/dev/usb2/wlan/if_rumreg.h
  user/thompsa/usb/sys/dev/usb2/wlan/if_rumvar.h
  user/thompsa/usb/sys/dev/usb2/wlan/if_ural2.c
  user/thompsa/usb/sys/dev/usb2/wlan/if_uralreg.h
  user/thompsa/usb/sys/dev/usb2/wlan/if_uralvar.h
  user/thompsa/usb/sys/dev/usb2/wlan/if_zyd2.c
  user/thompsa/usb/sys/dev/usb2/wlan/if_zydfw.h
  user/thompsa/usb/sys/dev/usb2/wlan/if_zydreg.h

Modified: user/thompsa/usb/sys/dev/usb2/wlan/if_rum2.c
==============================================================================
--- user/thompsa/usb/sys/dev/usb2/wlan/if_rum2.c	Tue Jan 27 01:27:28 2009	(r187752)
+++ user/thompsa/usb/sys/dev/usb2/wlan/if_rum2.c	Tue Jan 27 01:29:22 2009	(r187753)
@@ -1,7 +1,8 @@
+/*	$FreeBSD$	*/
+
 /*-
  * Copyright (c) 2005-2007 Damien Bergamini <damien.bergamini@free.fr>
  * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org>
- * Copyright (c) 2007-2008 Hans Petter Selasky <hselasky@freebsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -16,11 +17,6 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/*
- * NOTE: all function names beginning like "rum_cfg_" can only
- * be called from within the config thread function !
- */
-
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
@@ -29,1191 +25,1213 @@ __FBSDID("$FreeBSD$");
  * http://www.ralinktech.com.tw/
  */
 
-#include <dev/usb2/include/usb2_devid.h>
-#include <dev/usb2/include/usb2_standard.h>
-#include <dev/usb2/include/usb2_mfunc.h>
-#include <dev/usb2/include/usb2_error.h>
-
-#define	usb2_config_td_cc rum_config_copy
-#define	usb2_config_td_softc rum_softc
-
-#define	USB_DEBUG_VAR rum_debug
-
-#include <dev/usb2/core/usb2_core.h>
-#include <dev/usb2/core/usb2_lookup.h>
-#include <dev/usb2/core/usb2_process.h>
-#include <dev/usb2/core/usb2_config_td.h>
-#include <dev/usb2/core/usb2_debug.h>
-#include <dev/usb2/core/usb2_request.h>
-#include <dev/usb2/core/usb2_busdma.h>
-#include <dev/usb2/core/usb2_util.h>
-
-#include <dev/usb2/wlan/usb2_wlan.h>
-#include <dev/usb2/wlan/if_rumreg.h>
-#include <dev/usb2/wlan/if_rumvar.h>
-#include <dev/usb2/wlan/if_rumfw.h>
-
-#if USB_DEBUG
-static int rum_debug = 0;
-
-SYSCTL_NODE(_hw_usb2, OID_AUTO, rum, CTLFLAG_RW, 0, "USB rum");
-SYSCTL_INT(_hw_usb2_rum, OID_AUTO, debug, CTLFLAG_RW, &rum_debug, 0,
-    "Debug level");
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/sockio.h>
+#include <sys/mbuf.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/bus.h>
+#include <sys/endian.h>
+
+#include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/rman.h>
+
+#include <net/bpf.h>
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <net/ethernet.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+#include <net/if_types.h>
+
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_amrr.h>
+#include <net80211/ieee80211_phy.h>
+#include <net80211/ieee80211_radiotap.h>
+#include <net80211/ieee80211_regdomain.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+#include "usbdevs.h"
+
+#include <dev/usb/if_rumreg.h>
+#include <dev/usb/if_rumvar.h>
+#include <dev/usb/rt2573_ucode.h>
+
+#ifdef USB_DEBUG
+#define DPRINTF(x)	do { if (rumdebug > 0) printf x; } while (0)
+#define DPRINTFN(n, x)	do { if (rumdebug >= (n)) printf x; } while (0)
+int rumdebug = 0;
+SYSCTL_NODE(_hw_usb, OID_AUTO, rum, CTLFLAG_RW, 0, "USB rum");
+SYSCTL_INT(_hw_usb_rum, OID_AUTO, debug, CTLFLAG_RW, &rumdebug, 0,
+    "rum debug level");
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n, x)
 #endif
 
-/* prototypes */
-
-static device_probe_t rum_probe;
-static device_attach_t rum_attach;
-static device_detach_t rum_detach;
-
-static usb2_callback_t rum_bulk_read_callback;
-static usb2_callback_t rum_bulk_read_clear_stall_callback;
-static usb2_callback_t rum_bulk_write_callback;
-static usb2_callback_t rum_bulk_write_clear_stall_callback;
-
-static usb2_config_td_command_t rum_cfg_first_time_setup;
-static usb2_config_td_command_t rum_config_copy;
-static usb2_config_td_command_t rum_cfg_scan_start;
-static usb2_config_td_command_t rum_cfg_scan_end;
-static usb2_config_td_command_t rum_cfg_select_band;
-static usb2_config_td_command_t rum_cfg_set_chan;
-static usb2_config_td_command_t rum_cfg_enable_tsf_sync;
-static usb2_config_td_command_t rum_cfg_enable_mrr;
-static usb2_config_td_command_t rum_cfg_update_slot;
-static usb2_config_td_command_t rum_cfg_select_antenna;
-static usb2_config_td_command_t rum_cfg_set_txpreamble;
-static usb2_config_td_command_t rum_cfg_update_promisc;
-static usb2_config_td_command_t rum_cfg_pre_init;
-static usb2_config_td_command_t rum_cfg_init;
-static usb2_config_td_command_t rum_cfg_pre_stop;
-static usb2_config_td_command_t rum_cfg_stop;
-static usb2_config_td_command_t rum_cfg_amrr_timeout;
-static usb2_config_td_command_t rum_cfg_prepare_beacon;
-static usb2_config_td_command_t rum_cfg_newstate;
-
-static const char *rum_get_rf(uint32_t);
-static int	rum_ioctl_cb(struct ifnet *, u_long, caddr_t);
-static void	rum_std_command(struct ieee80211com *, usb2_config_td_command_t *);
-static void	rum_scan_start_cb(struct ieee80211com *);
-static void	rum_scan_end_cb(struct ieee80211com *);
-static void	rum_set_channel_cb(struct ieee80211com *);
-static uint16_t	rum_cfg_eeprom_read_2(struct rum_softc *, uint16_t);
-static uint32_t	rum_cfg_bbp_disbusy(struct rum_softc *);
-static uint32_t	rum_cfg_read(struct rum_softc *, uint16_t);
-static uint8_t	rum_cfg_bbp_init(struct rum_softc *);
-static uint8_t	rum_cfg_bbp_read(struct rum_softc *, uint8_t);
-static void	rum_cfg_amrr_start(struct rum_softc *);
-static void	rum_cfg_bbp_write(struct rum_softc *, uint8_t, uint8_t);
-static void	rum_cfg_do_request(struct rum_softc *,
-		    struct usb2_device_request *, void *);
-static void	rum_cfg_eeprom_read(struct rum_softc *, uint16_t, void *,
-		    uint16_t);
-static void	rum_cfg_load_microcode(struct rum_softc *, const uint8_t *,
-		    uint16_t);
-static void	rum_cfg_read_eeprom(struct rum_softc *);
-static void	rum_cfg_read_multi(struct rum_softc *, uint16_t, void *,
-		    uint16_t);
-static void	rum_cfg_rf_write(struct rum_softc *, uint8_t, uint32_t);
-static void	rum_cfg_set_bssid(struct rum_softc *, uint8_t *);
-static void	rum_cfg_set_macaddr(struct rum_softc *, uint8_t *);
-static void	rum_cfg_write(struct rum_softc *, uint16_t, uint32_t);
-static void	rum_cfg_write_multi(struct rum_softc *, uint16_t, void *,
-		    uint16_t);
-static void	rum_end_of_commands(struct rum_softc *);
-static void	rum_init_cb(void *);
-static void	rum_start_cb(struct ifnet *);
-static void	rum_watchdog(void *);
-static uint8_t	rum_get_rssi(struct rum_softc *, uint8_t);
-static struct ieee80211vap *rum_vap_create(struct ieee80211com *,
-		    const char[], int, int, int, const uint8_t[],
-		    const uint8_t[]);
-static void	rum_vap_delete(struct ieee80211vap *);
-static struct ieee80211_node *rum_node_alloc(struct ieee80211vap *,
-		    const uint8_t[]);
-static void	rum_newassoc(struct ieee80211_node *, int);
-static void	rum_cfg_disable_tsf_sync(struct rum_softc *);
-static void	rum_cfg_set_run(struct rum_softc *, struct rum_config_copy *);
-static void	rum_fill_write_queue(struct rum_softc *);
-static void	rum_tx_clean_queue(struct rum_softc *);
-static void	rum_tx_freem(struct mbuf *);
-static void	rum_tx_mgt(struct rum_softc *, struct mbuf *,
-		    struct ieee80211_node *);
-static struct ieee80211vap *rum_get_vap(struct rum_softc *);
-static void	rum_tx_data(struct rum_softc *, struct mbuf *,
-		    struct ieee80211_node *);
-static void	rum_tx_prot(struct rum_softc *, const struct mbuf *,
-		    struct ieee80211_node *, uint8_t, uint16_t);
-static void	rum_tx_raw(struct rum_softc *, struct mbuf *,
-		    struct ieee80211_node *,
-		    const struct ieee80211_bpf_params *);
-static int	rum_raw_xmit_cb(struct ieee80211_node *, struct mbuf *,
-		    const struct ieee80211_bpf_params *);
-static void	rum_setup_desc_and_tx(struct rum_softc *, struct mbuf *,
-		    uint32_t, uint16_t, uint16_t);
-static int	rum_newstate_cb(struct ieee80211vap *,
-		    enum ieee80211_state nstate, int arg);
-static void	rum_update_mcast_cb(struct ifnet *);
-static void	rum_update_promisc_cb(struct ifnet *);
-
 /* various supported device vendors/products */
-static const struct usb2_device_id rum_devs[] = {
-	{USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_HWU54DM, 0)},
-	{USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_RT2573_2, 0)},
-	{USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_RT2573_3, 0)},
-	{USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_RT2573_4, 0)},
-	{USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_WUG2700, 0)},
-	{USB_VPI(USB_VENDOR_AMIT, USB_PRODUCT_AMIT_CGWLUSB2GO, 0)},
-	{USB_VPI(USB_VENDOR_ASUS, USB_PRODUCT_ASUS_RT2573_1, 0)},
-	{USB_VPI(USB_VENDOR_ASUS, USB_PRODUCT_ASUS_RT2573_2, 0)},
-	{USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5D7050A, 0)},
-	{USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5D9050V3, 0)},
-	{USB_VPI(USB_VENDOR_CISCOLINKSYS, USB_PRODUCT_CISCOLINKSYS_WUSB54GC, 0)},
-	{USB_VPI(USB_VENDOR_CISCOLINKSYS, USB_PRODUCT_CISCOLINKSYS_WUSB54GR, 0)},
-	{USB_VPI(USB_VENDOR_CONCEPTRONIC2, USB_PRODUCT_CONCEPTRONIC2_C54RU2, 0)},
-	{USB_VPI(USB_VENDOR_COREGA, USB_PRODUCT_COREGA_CGWLUSB2GL, 0)},
-	{USB_VPI(USB_VENDOR_COREGA, USB_PRODUCT_COREGA_CGWLUSB2GPX, 0)},
-	{USB_VPI(USB_VENDOR_DICKSMITH, USB_PRODUCT_DICKSMITH_CWD854F, 0)},
-	{USB_VPI(USB_VENDOR_DICKSMITH, USB_PRODUCT_DICKSMITH_RT2573, 0)},
-	{USB_VPI(USB_VENDOR_DLINK2, USB_PRODUCT_DLINK2_DWLG122C1, 0)},
-	{USB_VPI(USB_VENDOR_DLINK2, USB_PRODUCT_DLINK2_WUA1340, 0)},
-	{USB_VPI(USB_VENDOR_DLINK2, USB_PRODUCT_DLINK2_DWA111, 0)},
-	{USB_VPI(USB_VENDOR_DLINK2, USB_PRODUCT_DLINK2_DWA110, 0)},
-	{USB_VPI(USB_VENDOR_GIGABYTE, USB_PRODUCT_GIGABYTE_GNWB01GS, 0)},
-	{USB_VPI(USB_VENDOR_GIGABYTE, USB_PRODUCT_GIGABYTE_GNWI05GS, 0)},
-	{USB_VPI(USB_VENDOR_GIGASET, USB_PRODUCT_GIGASET_RT2573, 0)},
-	{USB_VPI(USB_VENDOR_GOODWAY, USB_PRODUCT_GOODWAY_RT2573, 0)},
-	{USB_VPI(USB_VENDOR_GUILLEMOT, USB_PRODUCT_GUILLEMOT_HWGUSB254LB, 0)},
-	{USB_VPI(USB_VENDOR_GUILLEMOT, USB_PRODUCT_GUILLEMOT_HWGUSB254V2AP, 0)},
-	{USB_VPI(USB_VENDOR_HUAWEI3COM, USB_PRODUCT_HUAWEI3COM_WUB320G, 0)},
-	{USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_G54HP, 0)},
-	{USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_SG54HP, 0)},
-	{USB_VPI(USB_VENDOR_MSI, USB_PRODUCT_MSI_RT2573_1, 0)},
-	{USB_VPI(USB_VENDOR_MSI, USB_PRODUCT_MSI_RT2573_2, 0)},
-	{USB_VPI(USB_VENDOR_MSI, USB_PRODUCT_MSI_RT2573_3, 0)},
-	{USB_VPI(USB_VENDOR_MSI, USB_PRODUCT_MSI_RT2573_4, 0)},
-	{USB_VPI(USB_VENDOR_NOVATECH, USB_PRODUCT_NOVATECH_RT2573, 0)},
-	{USB_VPI(USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GWUS54HP, 0)},
-	{USB_VPI(USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GWUS54MINI2, 0)},
-	{USB_VPI(USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GWUSMM, 0)},
-	{USB_VPI(USB_VENDOR_QCOM, USB_PRODUCT_QCOM_RT2573, 0)},
-	{USB_VPI(USB_VENDOR_QCOM, USB_PRODUCT_QCOM_RT2573_2, 0)},
-	{USB_VPI(USB_VENDOR_RALINK, USB_PRODUCT_RALINK_RT2573, 0)},
-	{USB_VPI(USB_VENDOR_RALINK, USB_PRODUCT_RALINK_RT2573_2, 0)},
-	{USB_VPI(USB_VENDOR_RALINK, USB_PRODUCT_RALINK_RT2671, 0)},
-	{USB_VPI(USB_VENDOR_SITECOMEU, USB_PRODUCT_SITECOMEU_WL113R2, 0)},
-	{USB_VPI(USB_VENDOR_SITECOMEU, USB_PRODUCT_SITECOMEU_WL172, 0)},
-	{USB_VPI(USB_VENDOR_SPARKLAN, USB_PRODUCT_SPARKLAN_RT2573, 0)},
-	{USB_VPI(USB_VENDOR_SURECOM, USB_PRODUCT_SURECOM_RT2573, 0)},
+static const struct usb_devno rum_devs[] = {
+	{ USB_VENDOR_ABOCOM,            USB_PRODUCT_ABOCOM_HWU54DM },
+	{ USB_VENDOR_ABOCOM,            USB_PRODUCT_ABOCOM_RT2573_2 },
+	{ USB_VENDOR_ABOCOM,            USB_PRODUCT_ABOCOM_RT2573_3 },
+	{ USB_VENDOR_ABOCOM,            USB_PRODUCT_ABOCOM_RT2573_4 },
+	{ USB_VENDOR_ABOCOM,            USB_PRODUCT_ABOCOM_WUG2700 },
+	{ USB_VENDOR_AMIT,              USB_PRODUCT_AMIT_CGWLUSB2GO },
+	{ USB_VENDOR_ASUS,              USB_PRODUCT_ASUS_RT2573_1 },
+	{ USB_VENDOR_ASUS,              USB_PRODUCT_ASUS_RT2573_2 },
+	{ USB_VENDOR_BELKIN,            USB_PRODUCT_BELKIN_F5D7050A },
+	{ USB_VENDOR_BELKIN,            USB_PRODUCT_BELKIN_F5D9050V3 },
+	{ USB_VENDOR_CISCOLINKSYS,      USB_PRODUCT_CISCOLINKSYS_WUSB54GC },
+	{ USB_VENDOR_CISCOLINKSYS,      USB_PRODUCT_CISCOLINKSYS_WUSB54GR },
+	{ USB_VENDOR_CONCEPTRONIC2,     USB_PRODUCT_CONCEPTRONIC2_C54RU2 },
+	{ USB_VENDOR_COREGA,		USB_PRODUCT_COREGA_CGWLUSB2GL },
+	{ USB_VENDOR_COREGA,		USB_PRODUCT_COREGA_CGWLUSB2GPX },
+	{ USB_VENDOR_DICKSMITH,         USB_PRODUCT_DICKSMITH_CWD854F },
+	{ USB_VENDOR_DICKSMITH,         USB_PRODUCT_DICKSMITH_RT2573 },
+	{ USB_VENDOR_DLINK2,		USB_PRODUCT_DLINK2_DWLG122C1 },
+	{ USB_VENDOR_DLINK2,            USB_PRODUCT_DLINK2_WUA1340 },
+	{ USB_VENDOR_DLINK2,            USB_PRODUCT_DLINK2_DWA111 },
+	{ USB_VENDOR_DLINK2,            USB_PRODUCT_DLINK2_DWA110 },
+	{ USB_VENDOR_GIGABYTE,          USB_PRODUCT_GIGABYTE_GNWB01GS },
+	{ USB_VENDOR_GIGABYTE,          USB_PRODUCT_GIGABYTE_GNWI05GS },
+	{ USB_VENDOR_GIGASET,           USB_PRODUCT_GIGASET_RT2573 },
+	{ USB_VENDOR_GOODWAY,           USB_PRODUCT_GOODWAY_RT2573 },
+	{ USB_VENDOR_GUILLEMOT,         USB_PRODUCT_GUILLEMOT_HWGUSB254LB },
+	{ USB_VENDOR_GUILLEMOT,         USB_PRODUCT_GUILLEMOT_HWGUSB254V2AP },
+	{ USB_VENDOR_HUAWEI3COM,        USB_PRODUCT_HUAWEI3COM_WUB320G },
+	{ USB_VENDOR_MELCO,             USB_PRODUCT_MELCO_G54HP },
+	{ USB_VENDOR_MELCO,             USB_PRODUCT_MELCO_SG54HP },
+	{ USB_VENDOR_MSI,               USB_PRODUCT_MSI_RT2573_1 },
+	{ USB_VENDOR_MSI,               USB_PRODUCT_MSI_RT2573_2 },
+	{ USB_VENDOR_MSI,               USB_PRODUCT_MSI_RT2573_3 },
+	{ USB_VENDOR_MSI,               USB_PRODUCT_MSI_RT2573_4 },
+	{ USB_VENDOR_NOVATECH,          USB_PRODUCT_NOVATECH_RT2573 },
+	{ USB_VENDOR_PLANEX2,           USB_PRODUCT_PLANEX2_GWUS54HP },
+	{ USB_VENDOR_PLANEX2,           USB_PRODUCT_PLANEX2_GWUS54MINI2 },
+	{ USB_VENDOR_PLANEX2,           USB_PRODUCT_PLANEX2_GWUSMM },
+	{ USB_VENDOR_QCOM,              USB_PRODUCT_QCOM_RT2573 },
+	{ USB_VENDOR_QCOM,              USB_PRODUCT_QCOM_RT2573_2 },
+	{ USB_VENDOR_RALINK,		USB_PRODUCT_RALINK_RT2573 },
+	{ USB_VENDOR_RALINK,            USB_PRODUCT_RALINK_RT2573_2 },
+	{ USB_VENDOR_RALINK,            USB_PRODUCT_RALINK_RT2671 },
+	{ USB_VENDOR_SITECOMEU,         USB_PRODUCT_SITECOMEU_WL113R2 },
+	{ USB_VENDOR_SITECOMEU,         USB_PRODUCT_SITECOMEU_WL172 },
+	{ USB_VENDOR_SPARKLAN,		USB_PRODUCT_SPARKLAN_RT2573 },
+	{ USB_VENDOR_SURECOM,           USB_PRODUCT_SURECOM_RT2573 }
 };
 
-struct rum_def_mac {
-	uint32_t reg;
-	uint32_t val;
-};
+MODULE_DEPEND(rum, wlan, 1, 1, 1);
+MODULE_DEPEND(rum, wlan_amrr, 1, 1, 1);
+MODULE_DEPEND(rum, usb, 1, 1, 1);
 
-static const struct rum_def_mac rum_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}
+static struct ieee80211vap *rum_vap_create(struct ieee80211com *,
+			    const char name[IFNAMSIZ], int unit, int opmode,
+			    int flags, const uint8_t bssid[IEEE80211_ADDR_LEN],
+			    const uint8_t mac[IEEE80211_ADDR_LEN]);
+static void		rum_vap_delete(struct ieee80211vap *);
+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 void		rum_task(void *);
+static void		rum_scantask(void *);
+static int		rum_newstate(struct ieee80211vap *,
+			    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 void		rum_setup_tx_desc(struct rum_softc *,
+			    struct rum_tx_desc *, uint32_t, uint16_t, int,
+			    int);
+static int		rum_tx_mgt(struct rum_softc *, struct mbuf *,
+			    struct ieee80211_node *);
+static int		rum_tx_raw(struct rum_softc *, struct mbuf *,
+			    struct ieee80211_node *, 
+			    const struct ieee80211_bpf_params *);
+static int		rum_tx_data(struct rum_softc *, struct mbuf *,
+			    struct ieee80211_node *);
+static void		rum_start(struct ifnet *);
+static void		rum_watchdog(void *);
+static int		rum_ioctl(struct ifnet *, u_long, caddr_t);
+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 ifnet *);
+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_locked(struct rum_softc *);
+static void		rum_init(void *);
+static void		rum_stop(void *);
+static int		rum_load_microcode(struct rum_softc *, const u_char *,
+			    size_t);
+static int		rum_prepare_beacon(struct rum_softc *,
+			    struct ieee80211vap *);
+static int		rum_raw_xmit(struct ieee80211_node *, struct mbuf *,
+			    const struct ieee80211_bpf_params *);
+static struct ieee80211_node *rum_node_alloc(struct ieee80211vap *,
+			    const uint8_t mac[IEEE80211_ADDR_LEN]);
+static void		rum_newassoc(struct ieee80211_node *, int);
+static void		rum_scan_start(struct ieee80211com *);
+static void		rum_scan_end(struct ieee80211com *);
+static void		rum_set_channel(struct ieee80211com *);
+static int		rum_get_rssi(struct rum_softc *, uint8_t);
+static void		rum_amrr_start(struct rum_softc *,
+			    struct ieee80211_node *);
+static void		rum_amrr_timeout(void *);
+static void		rum_amrr_update(usbd_xfer_handle, usbd_private_handle,
+			    usbd_status);
+
+static const struct {
+	uint32_t	reg;
+	uint32_t	val;
+} rum_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 }
 };
 
-struct rum_def_bbp {
+static const struct {
 	uint8_t	reg;
 	uint8_t	val;
+} rum_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 }
 };
 
-static const struct rum_def_bbp rum_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}
+static const struct rfprog {
+	uint8_t		chan;
+	uint32_t	r1, r2, r3, r4;
+}  rum_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 }
+}, rum_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 }
 };
 
-struct rfprog {
-	uint8_t	chan;
-	uint32_t r1, r2, r3, r4;
-};
+static int
+rum_match(device_t self)
+{
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 
-static const struct rfprog rum_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}
-};
+	if (uaa->iface != NULL)
+		return UMATCH_NONE;
 
-static const struct rfprog rum_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}
-};
+	return (usb_lookup(rum_devs, uaa->vendor, uaa->product) != NULL) ?
+	    UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
+}
 
-static const struct usb2_config rum_config[RUM_N_TRANSFER] = {
-	[RUM_BULK_DT_WR] = {
-		.type = UE_BULK,
-		.endpoint = UE_ADDR_ANY,
-		.direction = UE_DIR_OUT,
-		.mh.bufsize = (MCLBYTES + RT2573_TX_DESC_SIZE + 8),
-		.mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,},
-		.mh.callback = &rum_bulk_write_callback,
-		.mh.timeout = 5000,	/* ms */
-	},
-
-	[RUM_BULK_DT_RD] = {
-		.type = UE_BULK,
-		.endpoint = UE_ADDR_ANY,
-		.direction = UE_DIR_IN,
-		.mh.bufsize = (MCLBYTES + RT2573_RX_DESC_SIZE),
-		.mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
-		.mh.callback = &rum_bulk_read_callback,
-	},
-
-	[RUM_BULK_CS_WR] = {
-		.type = UE_CONTROL,
-		.endpoint = 0x00,	/* Control pipe */
-		.direction = UE_DIR_ANY,
-		.mh.bufsize = sizeof(struct usb2_device_request),
-		.mh.callback = &rum_bulk_write_clear_stall_callback,
-		.mh.timeout = 1000,	/* 1 second */
-		.mh.interval = 50,	/* 50ms */
-	},
-
-	[RUM_BULK_CS_RD] = {
-		.type = UE_CONTROL,
-		.endpoint = 0x00,	/* Control pipe */
-		.direction = UE_DIR_ANY,
-		.mh.bufsize = sizeof(struct usb2_device_request),
-		.mh.callback = &rum_bulk_read_clear_stall_callback,
-		.mh.timeout = 1000,	/* 1 second */
-		.mh.interval = 50,	/* 50ms */
-	},
-};
+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;
+	struct ifnet *ifp;
+	const uint8_t *ucode = NULL;
+	usb_interface_descriptor_t *id;
+	usb_endpoint_descriptor_t *ed;
+	usbd_status error;
+	int i, ntries, size;
+	uint8_t bands;
+	uint32_t tmp;
 
-static devclass_t rum_devclass;
+	sc->sc_udev = uaa->device;
+	sc->sc_dev = self;
 
-static device_method_t rum_methods[] = {
-	DEVMETHOD(device_probe, rum_probe),
-	DEVMETHOD(device_attach, rum_attach),
-	DEVMETHOD(device_detach, rum_detach),
-	{0, 0}
-};
+	if (usbd_set_config_no(sc->sc_udev, RT2573_CONFIG_NO, 0) != 0) {
+		device_printf(self, "could not set configuration no\n");
+		return ENXIO;
+	}
 
-static driver_t rum_driver = {
-	.name = "rum",
-	.methods = rum_methods,
-	.size = sizeof(struct rum_softc),
-};
+	/* get the first interface handle */
+	error = usbd_device2interface_handle(sc->sc_udev, RT2573_IFACE_INDEX,
+	    &sc->sc_iface);
+	if (error != 0) {
+		device_printf(self, "could not get interface handle\n");
+		return ENXIO;
+	}
 
-DRIVER_MODULE(rum, ushub, rum_driver, rum_devclass, NULL, 0);
-MODULE_DEPEND(rum, usb2_wlan, 1, 1, 1);
-MODULE_DEPEND(rum, usb2_core, 1, 1, 1);
-MODULE_DEPEND(rum, wlan, 1, 1, 1);
-MODULE_DEPEND(rum, wlan_amrr, 1, 1, 1);
+	/*
+	 * Find endpoints.
+	 */
+	id = usbd_get_interface_descriptor(sc->sc_iface);
 
-static int
-rum_probe(device_t dev)
-{
-	struct usb2_attach_arg *uaa = device_get_ivars(dev);
+	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) {
+			device_printf(self,
+			    "no endpoint descriptor for iface %d\n", 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) {
+		device_printf(self, "missing endpoint\n");
+		return ENXIO;
+	}
 
-	if (uaa->usb2_mode != USB_MODE_HOST) {
-		return (ENXIO);
+	ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211);
+	if (ifp == NULL) {
+		device_printf(self, "can not if_alloc()\n"); 
+		return ENXIO;
 	}
-	if (uaa->info.bConfigIndex != 0) {
-		return (ENXIO);
+	ic = ifp->if_l2com;
+
+	mtx_init(&sc->sc_mtx, device_get_nameunit(sc->sc_dev), MTX_NETWORK_LOCK,
+	    MTX_DEF | MTX_RECURSE);
+
+	usb_init_task(&sc->sc_task, rum_task, sc);
+	usb_init_task(&sc->sc_scantask, rum_scantask, sc);
+	callout_init(&sc->watchdog_ch, 0);
+
+	/* retrieve RT2573 rev. no */
+	for (ntries = 0; ntries < 1000; ntries++) {
+		if ((tmp = rum_read(sc, RT2573_MAC_CSR0)) != 0)
+			break;
+		DELAY(1000);
 	}
-	if (uaa->info.bIfaceIndex != RT2573_IFACE_INDEX) {
-		return (ENXIO);
+	if (ntries == 1000) {
+		device_printf(self, "timeout waiting for chip to settle\n");
+		goto bad;
 	}
-	return (usb2_lookup_id_by_uaa(rum_devs, sizeof(rum_devs), uaa));
-}
 
-static int
-rum_attach(device_t dev)
-{
-	struct usb2_attach_arg *uaa = device_get_ivars(dev);
-	struct rum_softc *sc = device_get_softc(dev);
-	int error;
-	uint8_t iface_index;
+	/* retrieve MAC address and various other things from EEPROM */
+	rum_read_eeprom(sc);
 
-	if (sc == NULL) {
-		return (ENOMEM);
+	device_printf(self, "MAC/BBP RT2573 (rev 0x%05x), RF %s\n",
+	    tmp, rum_get_rf(sc->rf_rev));
+
+	ucode = rt2573_ucode;
+	size = sizeof rt2573_ucode;
+	error = rum_load_microcode(sc, ucode, size);
+	if (error != 0) {
+		device_printf(self, "could not load 8051 microcode\n");
+		goto bad;
 	}
-	device_set_usb2_desc(dev);
 
-	mtx_init(&sc->sc_mtx, "rum lock", MTX_NETWORK_LOCK,
-	    MTX_DEF | MTX_RECURSE);
+	ifp->if_softc = sc;
+	if_initname(ifp, "rum", device_get_unit(sc->sc_dev));
+	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
+	    IFF_NEEDSGIANT; /* USB stack is still under Giant lock */
+	ifp->if_init = rum_init;
+	ifp->if_ioctl = rum_ioctl;
+	ifp->if_start = rum_start;
+	IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
+	ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN;
+	IFQ_SET_READY(&ifp->if_snd);
 
-	snprintf(sc->sc_name, sizeof(sc->sc_name), "%s",
-	    device_get_nameunit(dev));
+	ic->ic_ifp = ifp;
+	ic->ic_phytype = IEEE80211_T_OFDM;	/* not only, but not used */
 
-	sc->sc_udev = uaa->device;
-	sc->sc_unit = device_get_unit(dev);
+	/* set device capabilities */
+	ic->ic_caps =
+	      IEEE80211_C_STA		/* station mode supported */
+	    | 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_BGSCAN	/* bg scanning supported */
+	    | IEEE80211_C_WPA		/* 802.11i */
+	    ;
 
-	usb2_callout_init_mtx(&sc->sc_watchdog, &sc->sc_mtx, 0);
+	bands = 0;
+	setbit(&bands, IEEE80211_MODE_11B);
+	setbit(&bands, IEEE80211_MODE_11G);
+	if (sc->rf_rev == RT2573_RF_5225 || sc->rf_rev == RT2573_RF_5226)
+		setbit(&bands, IEEE80211_MODE_11A);
+	ieee80211_init_channels(ic, NULL, &bands);
 
-	iface_index = RT2573_IFACE_INDEX;
-	error = usb2_transfer_setup(uaa->device, &iface_index,
-	    sc->sc_xfer, rum_config, RUM_N_TRANSFER, sc, &sc->sc_mtx);
-	if (error) {
-		device_printf(dev, "could not allocate USB transfers, "
-		    "err=%s\n", usb2_errstr(error));
-		goto detach;
-	}
-	error = usb2_config_td_setup(&sc->sc_config_td, sc, &sc->sc_mtx,
-	    &rum_end_of_commands,
-	    sizeof(struct usb2_config_td_cc), 24);
-	if (error) {
-		device_printf(dev, "could not setup config "
-		    "thread!\n");
-		goto detach;
-	}
-	mtx_lock(&sc->sc_mtx);
-
-	/* start setup */
-
-	usb2_config_td_queue_command
-	    (&sc->sc_config_td, NULL, &rum_cfg_first_time_setup, 0, 0);
-
-	rum_watchdog(sc);
-	mtx_unlock(&sc->sc_mtx);
-	return (0);			/* success */
-
-detach:
-	rum_detach(dev);
-	return (ENXIO);			/* failure */
-}
+	ieee80211_ifattach(ic);
+	ic->ic_newassoc = rum_newassoc;
+	ic->ic_raw_xmit = rum_raw_xmit;
+	ic->ic_node_alloc = rum_node_alloc;
+	ic->ic_scan_start = rum_scan_start;
+	ic->ic_scan_end = rum_scan_end;
+	ic->ic_set_channel = rum_set_channel;
 
-static int
-rum_detach(device_t dev)
-{
-	struct rum_softc *sc = device_get_softc(dev);
-	struct ieee80211com *ic;
-	struct ifnet *ifp;
+	ic->ic_vap_create = rum_vap_create;
+	ic->ic_vap_delete = rum_vap_delete;
 
-	usb2_config_td_drain(&sc->sc_config_td);
+	sc->sc_rates = ieee80211_get_ratetable(ic->ic_curchan);
+
+	bpfattach(ifp, DLT_IEEE802_11_RADIO,
+	    sizeof (struct ieee80211_frame) + sizeof(sc->sc_txtap));
 
-	mtx_lock(&sc->sc_mtx);
+	sc->sc_rxtap_len = sizeof sc->sc_rxtap;
+	sc->sc_rxtap.wr_ihdr.it_len = htole16(sc->sc_rxtap_len);
+	sc->sc_rxtap.wr_ihdr.it_present = htole32(RT2573_RX_RADIOTAP_PRESENT);
 
-	usb2_callout_stop(&sc->sc_watchdog);
+	sc->sc_txtap_len = sizeof sc->sc_txtap;
+	sc->sc_txtap.wt_ihdr.it_len = htole16(sc->sc_txtap_len);
+	sc->sc_txtap.wt_ihdr.it_present = htole32(RT2573_TX_RADIOTAP_PRESENT);
 
-	rum_cfg_pre_stop(sc, NULL, 0);
+	if (bootverbose)
+		ieee80211_announce(ic);
 
-	ifp = sc->sc_ifp;
-	ic = ifp->if_l2com;
+	return 0;
+bad:

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200901270129.n0R1TMr9069496>