Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb From Anon Ymous:



details:   https://anonhg.NetBSD.org/src/rev/5e4f1b2cf0f7
branches:  trunk
changeset: 758374:5e4f1b2cf0f7
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Nov 03 20:03:02 2010 +0000

description:
>From Anon Ymous:

Port of the otus driver from OpenBSD.  This driver supports USB 2.0
wireless network devices based on Atheros Communications AR9001U
chipset.  It claims to support several AR9001U based adapters, but has
only been tested with a NetGear WNDA3100 adapter (0x0846/0x9010).

XXX: The EDCA support is currently missing from our network stack
(hopefully coming soon), but the driver hooks for it are there.

diffstat:

 sys/dev/usb/if_otus.c    |  1710 ++++++++++++++++++++++++++++++---------------
 sys/dev/usb/if_otusreg.h |   575 +---------------
 sys/dev/usb/if_otusvar.h |   279 +++++++
 sys/dev/usb/usbdevs      |   148 +++-
 4 files changed, 1567 insertions(+), 1145 deletions(-)

diffs (truncated from 4225 to 300 lines):

diff -r 109687a72fe0 -r 5e4f1b2cf0f7 sys/dev/usb/if_otus.c
--- a/sys/dev/usb/if_otus.c     Wed Nov 03 19:59:34 2010 +0000
+++ b/sys/dev/usb/if_otus.c     Wed Nov 03 20:03:02 2010 +0000
@@ -1,3 +1,4 @@
+/*     $NetBSD: if_otus.c,v 1.2 2010/11/03 20:03:02 christos Exp $     */
 /*     $OpenBSD: if_otus.c,v 1.18 2010/08/27 17:08:00 jsg Exp $        */
 
 /*-
@@ -21,60 +22,516 @@
  * http://www.atheros.com/pt/bulletins/AR9001USBBulletin.pdf
  */
 
-#include "bpfilter.h"
-
 #include <sys/param.h>
 #include <sys/sockio.h>
 #include <sys/mbuf.h>
 #include <sys/kernel.h>
-#include <sys/socket.h>
+#include <sys/kthread.h>
 #include <sys/systm.h>
-#include <sys/timeout.h>
-#include <sys/conf.h>
+#include <sys/callout.h>
 #include <sys/device.h>
-
-#include <machine/bus.h>
-#include <machine/endian.h>
-#include <machine/intr.h>
-
-#if NBPFILTER > 0
+#include <sys/proc.h>
+
+#include <sys/bus.h>
+#include <sys/endian.h>
+#include <sys/intr.h>
+
 #include <net/bpf.h>
-#endif
 #include <net/if.h>
 #include <net/if_arp.h>
 #include <net/if_dl.h>
+#include <net/if_ether.h>
 #include <net/if_media.h>
 #include <net/if_types.h>
 
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
 #include <netinet/in_var.h>
-#include <netinet/if_ether.h>
 #include <netinet/ip.h>
 
 #include <net80211/ieee80211_var.h>
 #include <net80211/ieee80211_amrr.h>
 #include <net80211/ieee80211_radiotap.h>
 
+#include <dev/firmload.h>
+
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
 #include <dev/usb/usbdi_util.h>
 #include <dev/usb/usbdevs.h>
 
 #include <dev/usb/if_otusreg.h>
+#include <dev/usb/if_otusvar.h>
 
 #ifdef USB_DEBUG
 #define OTUS_DEBUG
 #endif
 
 #ifdef OTUS_DEBUG
-#define DPRINTF(x)     do { if (otus_debug) printf x; } while (0)
-#define DPRINTFN(n, x) do { if (otus_debug >= (n)) printf x; } while (0)
-int otus_debug = 1;
+int otus_debug = 0;
+#define DPRINTFN(n, ...) \
+       do { if (otus_debug >= (n)) printf(__VA_ARGS__); } while (0)
 #else
-#define DPRINTF(x)
-#define DPRINTFN(n, x)
+#define DPRINTFN(n, ...) \
+       do { } while (0)
 #endif
+#define DPRINTF(...) \
+       DPRINTFN(1, __VA_ARGS__)
+
+Static int     otus_detach(struct device *, int);
+Static int     otus_activate(device_t, devact_t);
+Static void    otus_attachhook(device_t);
+Static void    otus_get_chanlist(struct otus_softc *);
+Static int     otus_load_firmware(struct otus_softc *, const char *,
+                   uint32_t);
+Static int     otus_open_pipes(struct otus_softc *);
+Static void    otus_close_pipes(struct otus_softc *);
+Static int     otus_alloc_tx_cmd(struct otus_softc *);
+Static void    otus_free_tx_cmd(struct otus_softc *);
+Static int     otus_alloc_tx_data_list(struct otus_softc *);
+Static void    otus_free_tx_data_list(struct otus_softc *);
+Static int     otus_alloc_rx_data_list(struct otus_softc *);
+Static void    otus_free_rx_data_list(struct otus_softc *);
+Static void    otus_next_scan(void *);
+Static void    otus_task(void *);
+Static void    otus_do_async(struct otus_softc *,
+                   void (*)(struct otus_softc *, void *), void *, int);
+Static int     otus_newstate(struct ieee80211com *, enum ieee80211_state,
+                   int);
+Static void    otus_newstate_cb(struct otus_softc *, void *);
+Static int     otus_cmd(struct otus_softc *, uint8_t, const void *, int,
+                   void *);
+Static void    otus_write(struct otus_softc *, uint32_t, uint32_t);
+Static int     otus_write_barrier(struct otus_softc *);
+Static struct  ieee80211_node *otus_node_alloc(struct ieee80211_node_table *);
+Static int     otus_media_change(struct ifnet *);
+Static int     otus_read_eeprom(struct otus_softc *);
+Static void    otus_newassoc(struct ieee80211_node *, int);
+Static void    otus_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
+Static void    otus_cmd_rxeof(struct otus_softc *, uint8_t *, int);
+Static void    otus_sub_rxeof(struct otus_softc *, uint8_t *, int);
+Static void    otus_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+Static void    otus_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+Static int     otus_tx(struct otus_softc *, struct mbuf *,
+                   struct ieee80211_node *);
+Static void    otus_start(struct ifnet *);
+Static void    otus_watchdog(struct ifnet *);
+Static int     otus_ioctl(struct ifnet *, u_long, void *);
+Static int     otus_set_multi(struct otus_softc *);
+Static void    otus_updateedca(struct ieee80211com *);
+Static void    otus_updateedca_cb(struct otus_softc *, void *);
+Static void    otus_updateedca_cb_locked(struct otus_softc *);
+Static void    otus_updateslot(struct ifnet *);
+Static void    otus_updateslot_cb(struct otus_softc *, void *);
+Static void    otus_updateslot_cb_locked(struct otus_softc *);
+Static int     otus_init_mac(struct otus_softc *);
+Static uint32_t        otus_phy_get_def(struct otus_softc *, uint32_t);
+Static int     otus_set_board_values(struct otus_softc *,
+                   struct ieee80211_channel *);
+Static int     otus_program_phy(struct otus_softc *,
+                   struct ieee80211_channel *);
+Static int     otus_set_rf_bank4(struct otus_softc *,
+                   struct ieee80211_channel *);
+Static void    otus_get_delta_slope(uint32_t, uint32_t *, uint32_t *);
+Static int     otus_set_chan(struct otus_softc *, struct ieee80211_channel *,
+                   int);
+#ifdef notyet
+Static int     otus_set_key(struct ieee80211com *, struct ieee80211_node *,
+                   struct ieee80211_key *);
+Static void    otus_set_key_cb(struct otus_softc *, void *);
+Static void    otus_delete_key(struct ieee80211com *, struct ieee80211_node *,
+                   struct ieee80211_key *);
+Static void    otus_delete_key_cb(struct otus_softc *, void *);
+#endif /* notyet */
+Static void    otus_calibrate_to(void *);
+Static int     otus_set_bssid(struct otus_softc *, const uint8_t *);
+Static int     otus_set_macaddr(struct otus_softc *, const uint8_t *);
+#ifdef notyet
+Static void    otus_led_newstate_type1(struct otus_softc *);
+Static void    otus_led_newstate_type2(struct otus_softc *);
+#endif /* notyet */
+Static void    otus_led_newstate_type3(struct otus_softc *);
+Static int     otus_init(struct ifnet *);
+Static void    otus_stop(struct ifnet *);
+
+/* List of supported channels. */
+static const uint8_t ar_chans[] = {
+       1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+       36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124,
+       128, 132, 136, 140, 149, 153, 157, 161, 165, 34, 38, 42, 46
+};
+
+/*
+ * This data is automatically generated from the "otus.ini" file.
+ * It is stored in a different way though, to reduce kernel's .rodata
+ * section overhead (5.1KB instead of 8.5KB).
+ */
+
+/* NB: apply AR_PHY(). */
+static const uint16_t ar5416_phy_regs[] = {
+       0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007, 0x008,
+       0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f, 0x010, 0x011,
+       0x012, 0x013, 0x014, 0x015, 0x016, 0x017, 0x018, 0x01a, 0x01b,
+       0x040, 0x041, 0x042, 0x043, 0x045, 0x046, 0x047, 0x048, 0x049,
+       0x04a, 0x04b, 0x04d, 0x04e, 0x04f, 0x051, 0x052, 0x053, 0x055,
+       0x056, 0x058, 0x059, 0x05c, 0x05d, 0x05e, 0x05f, 0x060, 0x061,
+       0x062, 0x063, 0x064, 0x065, 0x066, 0x067, 0x068, 0x069, 0x06a,
+       0x06b, 0x06c, 0x06d, 0x070, 0x071, 0x072, 0x073, 0x074, 0x075,
+       0x076, 0x077, 0x078, 0x079, 0x07a, 0x07b, 0x07c, 0x07f, 0x080,
+       0x081, 0x082, 0x083, 0x084, 0x085, 0x086, 0x087, 0x088, 0x089,
+       0x08a, 0x08b, 0x08c, 0x08d, 0x08e, 0x08f, 0x090, 0x091, 0x092,
+       0x093, 0x094, 0x095, 0x096, 0x097, 0x098, 0x099, 0x09a, 0x09b,
+       0x09c, 0x09d, 0x09e, 0x09f, 0x0a0, 0x0a1, 0x0a2, 0x0a3, 0x0a4,
+       0x0a5, 0x0a6, 0x0a7, 0x0a8, 0x0a9, 0x0aa, 0x0ab, 0x0ac, 0x0ad,
+       0x0ae, 0x0af, 0x0b0, 0x0b1, 0x0b2, 0x0b3, 0x0b4, 0x0b5, 0x0b6,
+       0x0b7, 0x0b8, 0x0b9, 0x0ba, 0x0bb, 0x0bc, 0x0bd, 0x0be, 0x0bf,
+       0x0c0, 0x0c1, 0x0c2, 0x0c3, 0x0c4, 0x0c5, 0x0c6, 0x0c7, 0x0c8,
+       0x0c9, 0x0ca, 0x0cb, 0x0cc, 0x0cd, 0x0ce, 0x0cf, 0x0d0, 0x0d1,
+       0x0d2, 0x0d3, 0x0d4, 0x0d5, 0x0d6, 0x0d7, 0x0d8, 0x0d9, 0x0da,
+       0x0db, 0x0dc, 0x0dd, 0x0de, 0x0df, 0x0e0, 0x0e1, 0x0e2, 0x0e3,
+       0x0e4, 0x0e5, 0x0e6, 0x0e7, 0x0e8, 0x0e9, 0x0ea, 0x0eb, 0x0ec,
+       0x0ed, 0x0ee, 0x0ef, 0x0f0, 0x0f1, 0x0f2, 0x0f3, 0x0f4, 0x0f5,
+       0x0f6, 0x0f7, 0x0f8, 0x0f9, 0x0fa, 0x0fb, 0x0fc, 0x0fd, 0x0fe,
+       0x0ff, 0x100, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109,
+       0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x13c, 0x13d, 0x13e,
+       0x13f, 0x280, 0x281, 0x282, 0x283, 0x284, 0x285, 0x286, 0x287,
+       0x288, 0x289, 0x28a, 0x28b, 0x28c, 0x28d, 0x28e, 0x28f, 0x290,
+       0x291, 0x292, 0x293, 0x294, 0x295, 0x296, 0x297, 0x298, 0x299,
+       0x29a, 0x29b, 0x29d, 0x29e, 0x29f, 0x2c0, 0x2c1, 0x2c2, 0x2c3,
+       0x2c4, 0x2c5, 0x2c6, 0x2c7, 0x2c8, 0x2c9, 0x2ca, 0x2cb, 0x2cc,
+       0x2cd, 0x2ce, 0x2cf, 0x2d0, 0x2d1, 0x2d2, 0x2d3, 0x2d4, 0x2d5,
+       0x2d6, 0x2e2, 0x2e3, 0x2e4, 0x2e5, 0x2e6, 0x2e7, 0x2e8, 0x2e9,
+       0x2ea, 0x2eb, 0x2ec, 0x2ed, 0x2ee, 0x2ef, 0x2f0, 0x2f1, 0x2f2,
+       0x2f3, 0x2f4, 0x2f5, 0x2f6, 0x2f7, 0x2f8, 0x412, 0x448, 0x458,
+       0x683, 0x69b, 0x812, 0x848, 0x858, 0xa83, 0xa9b, 0xc19, 0xc57,
+       0xc5a, 0xc6f, 0xe9c, 0xed7, 0xed8, 0xed9, 0xeda, 0xedb, 0xedc,
+       0xedd, 0xede, 0xedf, 0xee0, 0xee1
+};
+
+static const uint32_t ar5416_phy_vals_5ghz_20mhz[] = {
+       0x00000007, 0x00000300, 0x00000000, 0xad848e19, 0x7d14e000,
+       0x9c0a9f6b, 0x00000090, 0x00000000, 0x02020200, 0x00000e0e,
+       0x0a020001, 0x0000a000, 0x00000000, 0x00000e0e, 0x00000007,
+       0x00200400, 0x206a002e, 0x1372161e, 0x001a6a65, 0x1284233c,
+       0x6c48b4e4, 0x00000859, 0x7ec80d2e, 0x31395c5e, 0x0004dd10,
+       0x409a4190, 0x050cb081, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x000007d0, 0x00000118, 0x10000fff, 0x0510081c,
+       0xd0058a15, 0x00000001, 0x00000004, 0x3f3f3f3f, 0x3f3f3f3f,
+       0x0000007f, 0xdfb81020, 0x9280b212, 0x00020028, 0x5d50e188,
+       0x00081fff, 0x00009b40, 0x00001120, 0x190fb515, 0x00000000,
+       0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x00000007, 0x001fff00, 0x006f00c4, 0x03051000,
+       0x00000820, 0x038919be, 0x06336f77, 0x60f6532c, 0x08f186c8,
+       0x00046384, 0x00000000, 0x00000000, 0x00000000, 0x00000200,
+       0x64646464, 0x3c787878, 0x000000aa, 0x00000000, 0x00001042,
+       0x00000000, 0x00000040, 0x00000080, 0x000001a1, 0x000001e1,
+       0x00000021, 0x00000061, 0x00000168, 0x000001a8, 0x000001e8,
+       0x00000028, 0x00000068, 0x00000189, 0x000001c9, 0x00000009,
+       0x00000049, 0x00000089, 0x00000170, 0x000001b0, 0x000001f0,
+       0x00000030, 0x00000070, 0x00000191, 0x000001d1, 0x00000011,
+       0x00000051, 0x00000091, 0x000001b8, 0x000001f8, 0x00000038,
+       0x00000078, 0x00000199, 0x000001d9, 0x00000019, 0x00000059,
+       0x00000099, 0x000000d9, 0x000000f9, 0x000000f9, 0x000000f9,
+       0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9,
+       0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9,
+       0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9,
+       0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9,
+       0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, 0x00000000,
+       0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005,
+       0x00000008, 0x00000009, 0x0000000a, 0x0000000b, 0x0000000c,
+       0x0000000d, 0x00000010, 0x00000011, 0x00000012, 0x00000013,
+       0x00000014, 0x00000015, 0x00000018, 0x00000019, 0x0000001a,
+       0x0000001b, 0x0000001c, 0x0000001d, 0x00000020, 0x00000021,
+       0x00000022, 0x00000023, 0x00000024, 0x00000025, 0x00000028,
+       0x00000029, 0x0000002a, 0x0000002b, 0x0000002c, 0x0000002d,
+       0x00000030, 0x00000031, 0x00000032, 0x00000033, 0x00000034,
+       0x00000035, 0x00000035, 0x00000035, 0x00000035, 0x00000035,
+       0x00000035, 0x00000035, 0x00000035, 0x00000035, 0x00000035,
+       0x00000035, 0x00000035, 0x00000035, 0x00000035, 0x00000035,
+       0x00000035, 0x00000035, 0x00000035, 0x00000035, 0x00000035,
+       0x00000035, 0x00000010, 0x0000001a, 0x00000000, 0x00000000,
+       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x00000008, 0x00000440, 0xd6be4788, 0x012e8160,
+       0x40806333, 0x00106c10, 0x009c4060, 0x1883800a, 0x018830c6,
+       0x00000400, 0x000009b5, 0x00000000, 0x00000108, 0x3f3f3f3f,
+       0x3f3f3f3f, 0x13c889af, 0x38490a20, 0x00007bb6, 0x0fff3ffc,
+       0x00000001, 0x0000a000, 0x00000000, 0x0cc75380, 0x0f0f0f01,
+       0xdfa91f01, 0x00418a11, 0x00000000, 0x09249126, 0x0a1a9caa,
+       0x1ce739ce, 0x051701ce, 0x18010000, 0x30032602, 0x48073e06,
+       0x560b4c0a, 0x641a600f, 0x7a4f6e1b, 0x8c5b7e5a, 0x9d0f96cf,
+       0xb51fa69f, 0xcb3fbd07, 0x0000d7bf, 0x00000000, 0x00000000,
+       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x3fffffff, 0x3fffffff, 0x3fffffff, 0x0003ffff, 0x79a8aa1f,
+       0x08000000, 0x3f3f3f3f, 0x3f3f3f3f, 0x1ce739ce, 0x000001ce,
+       0x00000007, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x00000000, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f,
+       0x00000000, 0x1ce739ce, 0x000000c0, 0x00180a65, 0x0510001c,
+       0x00009b40, 0x012e8160, 0x09249126, 0x00180a65, 0x0510001c,
+       0x00009b40, 0x012e8160, 0x09249126, 0x0001c600, 0x004b6a8e,
+       0x000003ce, 0x00181400, 0x00820820, 0x066c420f, 0x0f282207,
+       0x17601685, 0x1f801104, 0x37a00c03, 0x3fc40883, 0x57c00803,
+       0x5fd80682, 0x7fe00482, 0x7f3c7bba, 0xf3307ff0
+};
+
+#ifdef notyet
+static const uint32_t ar5416_phy_vals_5ghz_40mhz[] = {
+       0x00000007, 0x000003c4, 0x00000000, 0xad848e19, 0x7d14e000,
+       0x9c0a9f6b, 0x00000090, 0x00000000, 0x02020200, 0x00000e0e,
+       0x0a020001, 0x0000a000, 0x00000000, 0x00000e0e, 0x00000007,
+       0x00200400, 0x206a002e, 0x13721c1e, 0x001a6a65, 0x1284233c,
+       0x6c48b4e4, 0x00000859, 0x7ec80d2e, 0x31395c5e, 0x0004dd10,
+       0x409a4190, 0x050cb081, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x000007d0, 0x00000230, 0x10000fff, 0x0510081c,
+       0xd0058a15, 0x00000001, 0x00000004, 0x3f3f3f3f, 0x3f3f3f3f,
+       0x0000007f, 0xdfb81020, 0x9280b212, 0x00020028, 0x5d50e188,
+       0x00081fff, 0x00009b40, 0x00001120, 0x190fb515, 0x00000000,
+       0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+       0x00000000, 0x00000007, 0x001fff00, 0x006f00c4, 0x03051000,



Home | Main Index | Thread Index | Old Index