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 openbsd.



details:   https://anonhg.NetBSD.org/src/rev/0c0fe593074b
branches:  trunk
changeset: 758372:0c0fe593074b
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Nov 03 19:58:17 2010 +0000

description:
from openbsd.

diffstat:

 sys/dev/usb/if_otus.c    |  2317 ++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/usb/if_otusreg.h |   987 +++++++++++++++++++
 2 files changed, 3304 insertions(+), 0 deletions(-)

diffs (truncated from 3312 to 300 lines):

diff -r 292710e5a590 -r 0c0fe593074b sys/dev/usb/if_otus.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/if_otus.c     Wed Nov 03 19:58:17 2010 +0000
@@ -0,0 +1,2317 @@
+/*     $OpenBSD: if_otus.c,v 1.18 2010/08/27 17:08:00 jsg Exp $        */
+
+/*-
+ * Copyright (c) 2009 Damien Bergamini <damien.bergamini%free.fr@localhost>
+ *
+ * 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.
+ */
+
+/*-
+ * Driver for Atheros AR9001U chipset.
+ * 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/systm.h>
+#include <sys/timeout.h>
+#include <sys/conf.h>
+#include <sys/device.h>
+
+#include <machine/bus.h>
+#include <machine/endian.h>
+#include <machine/intr.h>
+
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#endif
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <net/if_dl.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/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>
+
+#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;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n, x)
+#endif
+
+static const struct usb_devno otus_devs[] = {
+       { USB_VENDOR_ACCTON,            USB_PRODUCT_ACCTON_WN7512 },
+       { USB_VENDOR_ATHEROS2,          USB_PRODUCT_ATHEROS2_3CRUSBN275 },
+       { USB_VENDOR_ATHEROS2,          USB_PRODUCT_ATHEROS2_TG121N },
+       { USB_VENDOR_ATHEROS2,          USB_PRODUCT_ATHEROS2_AR9170 },
+       { USB_VENDOR_ATHEROS2,          USB_PRODUCT_ATHEROS2_WN612 },
+       { USB_VENDOR_ATHEROS2,          USB_PRODUCT_ATHEROS2_WN821NV2 },
+       { USB_VENDOR_AVM,               USB_PRODUCT_AVM_FRITZWLAN },
+       { USB_VENDOR_CACE,              USB_PRODUCT_CACE_AIRPCAPNX },
+       { USB_VENDOR_DLINK2,            USB_PRODUCT_DLINK2_DWA130D1 },
+       { USB_VENDOR_DLINK2,            USB_PRODUCT_DLINK2_DWA160A1 },
+       { USB_VENDOR_DLINK2,            USB_PRODUCT_DLINK2_DWA160A2 },
+       { USB_VENDOR_IODATA,            USB_PRODUCT_IODATA_WNGDNUS2 },
+       { USB_VENDOR_NEC,               USB_PRODUCT_NEC_WL300NUG },
+       { USB_VENDOR_NETGEAR,           USB_PRODUCT_NETGEAR_WN111V2 },
+       { USB_VENDOR_NETGEAR,           USB_PRODUCT_NETGEAR_WNA1000 },
+       { USB_VENDOR_NETGEAR,           USB_PRODUCT_NETGEAR_WNDA3100 },
+       { USB_VENDOR_PLANEX2,           USB_PRODUCT_PLANEX2_GW_US300 },
+       { USB_VENDOR_WISTRONNEWEB,      USB_PRODUCT_WISTRONNEWEB_O8494 },
+       { USB_VENDOR_WISTRONNEWEB,      USB_PRODUCT_WISTRONNEWEB_WNC0600 },
+       { USB_VENDOR_ZCOM,              USB_PRODUCT_ZCOM_UB81 },
+       { USB_VENDOR_ZCOM,              USB_PRODUCT_ZCOM_UB82 },
+       { USB_VENDOR_ZYDAS,             USB_PRODUCT_ZYDAS_ZD1221 },
+       { USB_VENDOR_ZYXEL,             USB_PRODUCT_ZYXEL_NWD271N }
+};
+
+int            otus_match(struct device *, void *, void *);
+void           otus_attach(struct device *, struct device *, void *);
+int            otus_detach(struct device *, int);
+void           otus_attachhook(void *);
+void           otus_get_chanlist(struct otus_softc *);
+int            otus_load_firmware(struct otus_softc *, const char *,
+                   uint32_t);
+int            otus_open_pipes(struct otus_softc *);
+void           otus_close_pipes(struct otus_softc *);
+int            otus_alloc_tx_cmd(struct otus_softc *);
+void           otus_free_tx_cmd(struct otus_softc *);
+int            otus_alloc_tx_data_list(struct otus_softc *);
+void           otus_free_tx_data_list(struct otus_softc *);
+int            otus_alloc_rx_data_list(struct otus_softc *);
+void           otus_free_rx_data_list(struct otus_softc *);
+void           otus_next_scan(void *);
+void           otus_task(void *);
+void           otus_do_async(struct otus_softc *,
+                   void (*)(struct otus_softc *, void *), void *, int);
+int            otus_newstate(struct ieee80211com *, enum ieee80211_state,
+                   int);
+void           otus_newstate_cb(struct otus_softc *, void *);
+int            otus_cmd(struct otus_softc *, uint8_t, const void *, int,
+                   void *);
+void           otus_write(struct otus_softc *, uint32_t, uint32_t);
+int            otus_write_barrier(struct otus_softc *);
+struct         ieee80211_node *otus_node_alloc(struct ieee80211com *);
+int            otus_media_change(struct ifnet *);
+int            otus_read_eeprom(struct otus_softc *);
+void           otus_newassoc(struct ieee80211com *, struct ieee80211_node *,
+                   int);
+void           otus_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
+void           otus_cmd_rxeof(struct otus_softc *, uint8_t *, int);
+void           otus_sub_rxeof(struct otus_softc *, uint8_t *, int);
+void           otus_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+void           otus_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+int            otus_tx(struct otus_softc *, struct mbuf *,
+                   struct ieee80211_node *);
+void           otus_start(struct ifnet *);
+void           otus_watchdog(struct ifnet *);
+int            otus_ioctl(struct ifnet *, u_long, caddr_t);
+int            otus_set_multi(struct otus_softc *);
+void           otus_updateedca(struct ieee80211com *);
+void           otus_updateedca_cb(struct otus_softc *, void *);
+void           otus_updateslot(struct ieee80211com *);
+void           otus_updateslot_cb(struct otus_softc *, void *);
+int            otus_init_mac(struct otus_softc *);
+uint32_t       otus_phy_get_def(struct otus_softc *, uint32_t);
+int            otus_set_board_values(struct otus_softc *,
+                   struct ieee80211_channel *);
+int            otus_program_phy(struct otus_softc *,
+                   struct ieee80211_channel *);
+int            otus_set_rf_bank4(struct otus_softc *,
+                   struct ieee80211_channel *);
+void           otus_get_delta_slope(uint32_t, uint32_t *, uint32_t *);
+int            otus_set_chan(struct otus_softc *, struct ieee80211_channel *,
+                   int);
+int            otus_set_key(struct ieee80211com *, struct ieee80211_node *,
+                   struct ieee80211_key *);
+void           otus_set_key_cb(struct otus_softc *, void *);
+void           otus_delete_key(struct ieee80211com *, struct ieee80211_node *,
+                   struct ieee80211_key *);
+void           otus_delete_key_cb(struct otus_softc *, void *);
+void           otus_calibrate_to(void *);
+int            otus_set_bssid(struct otus_softc *, const uint8_t *);
+int            otus_set_macaddr(struct otus_softc *, const uint8_t *);
+void           otus_led_newstate_type1(struct otus_softc *);
+void           otus_led_newstate_type2(struct otus_softc *);
+void           otus_led_newstate_type3(struct otus_softc *);
+int            otus_init(struct ifnet *);
+void           otus_stop(struct ifnet *);
+
+struct cfdriver otus_cd = {
+       NULL, "otus", DV_IFNET
+};
+
+const struct cfattach otus_ca = {
+       sizeof (struct otus_softc), otus_match, otus_attach, otus_detach
+};
+
+int
+otus_match(struct device *parent, void *match, void *aux)
+{
+       struct usb_attach_arg *uaa = aux;
+
+       if (uaa->iface != NULL)
+               return UMATCH_NONE;
+
+       return (usb_lookup(otus_devs, uaa->vendor, uaa->product) != NULL) ?
+           UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
+}
+
+void
+otus_attach(struct device *parent, struct device *self, void *aux)
+{
+       struct otus_softc *sc = (struct otus_softc *)self;
+       struct usb_attach_arg *uaa = aux;
+       int error;
+
+       sc->sc_udev = uaa->device;
+
+       usb_init_task(&sc->sc_task, otus_task, sc);
+       timeout_set(&sc->scan_to, otus_next_scan, sc);
+       timeout_set(&sc->calib_to, otus_calibrate_to, sc);
+
+       sc->amrr.amrr_min_success_threshold =  1;
+       sc->amrr.amrr_max_success_threshold = 10;
+
+       if (usbd_set_config_no(sc->sc_udev, 1, 0) != 0) {
+               printf("%s: could not set configuration no\n",
+                   sc->sc_dev.dv_xname);
+               return;
+       }
+
+       /* Get the first interface handle. */
+       error = usbd_device2interface_handle(sc->sc_udev, 0, &sc->sc_iface);
+       if (error != 0) {
+               printf("%s: could not get interface handle\n",
+                   sc->sc_dev.dv_xname);
+               return;
+       }
+
+       if ((error = otus_open_pipes(sc)) != 0) {
+               printf("%s: could not open pipes\n", sc->sc_dev.dv_xname);
+               return;
+       }
+
+       if (rootvp == NULL)
+               mountroothook_establish(otus_attachhook, sc);
+       else
+               otus_attachhook(sc);
+
+       usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, &sc->sc_dev);
+}
+
+int
+otus_detach(struct device *self, int flags)
+{
+       struct otus_softc *sc = (struct otus_softc *)self;
+       struct ifnet *ifp = &sc->sc_ic.ic_if;
+       int s;
+
+       s = splnet();
+
+       /* Wait for all queued asynchronous commands to complete. */
+       while (sc->cmdq.queued > 0)
+               tsleep(&sc->cmdq, 0, "cmdq", 0);
+
+       timeout_del(&sc->scan_to);
+       timeout_del(&sc->calib_to);
+
+       if (ifp->if_flags != 0) {       /* if_attach() has been called. */
+               ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
+               ieee80211_ifdetach(ifp);
+               if_detach(ifp);
+       }
+
+       otus_close_pipes(sc);
+
+       splx(s);
+
+       usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, &sc->sc_dev);
+
+       return 0;
+}
+
+void
+otus_attachhook(void *xsc)
+{
+       struct otus_softc *sc = xsc;
+       struct ieee80211com *ic = &sc->sc_ic;
+       struct ifnet *ifp = &ic->ic_if;
+       usb_device_request_t req;
+       uint32_t in, out;
+       int error;
+
+       error = otus_load_firmware(sc, "otus-init", AR_FW_INIT_ADDR);
+       if (error != 0) {
+               printf("%s: could not load %s firmware\n",
+                   sc->sc_dev.dv_xname, "init");
+               return;
+       }
+
+       usbd_delay_ms(sc->sc_udev, 1000);
+
+       error = otus_load_firmware(sc, "otus-main", AR_FW_MAIN_ADDR);
+       if (error != 0) {
+               printf("%s: could not load %s firmware\n",
+                   sc->sc_dev.dv_xname, "main");
+               return;
+       }
+



Home | Main Index | Thread Index | Old Index