Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Locking fixes and more for otus.



details:   https://anonhg.NetBSD.org/src/rev/b5be9371a85b
branches:  trunk
changeset: 784172:b5be9371a85b
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jan 20 21:50:41 2013 +0000

description:
Locking fixes and more for otus.

diffstat:

 sys/dev/usb/if_otus.c    |  1046 +++++++++++++++++++++++++++++++++------------
 sys/dev/usb/if_otusreg.h |   128 +++++-
 sys/dev/usb/if_otusvar.h |    31 +-
 3 files changed, 900 insertions(+), 305 deletions(-)

diffs (truncated from 2408 to 300 lines):

diff -r 45a4e5b20dfa -r b5be9371a85b sys/dev/usb/if_otus.c
--- a/sys/dev/usb/if_otus.c     Sun Jan 20 21:02:11 2013 +0000
+++ b/sys/dev/usb/if_otus.c     Sun Jan 20 21:50:41 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_otus.c,v 1.19 2013/01/05 23:34:17 christos Exp $    */
+/*     $NetBSD: if_otus.c,v 1.20 2013/01/20 21:50:41 christos Exp $    */
 /*     $OpenBSD: if_otus.c,v 1.18 2010/08/27 17:08:00 jsg Exp $        */
 
 /*-
@@ -23,7 +23,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.19 2013/01/05 23:34:17 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.20 2013/01/20 21:50:41 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/sockio.h>
@@ -67,15 +67,36 @@
 #include <dev/usb/if_otusvar.h>
 
 #ifdef OTUS_DEBUG
-int otus_debug = 0;
-#define DPRINTFN(n, ...) \
-       do { if (otus_debug >= (n)) printf(__VA_ARGS__); } while (0)
-#else
+
+#define        DBG_INIT        __BIT(0)
+#define        DBG_FN          __BIT(1)
+#define        DBG_TX          __BIT(2)
+#define        DBG_RX          __BIT(3)
+#define        DBG_STM         __BIT(4)
+#define        DBG_CHAN        __BIT(5)
+#define        DBG_REG         __BIT(6)
+#define        DBG_CMD         __BIT(7)
+#define        DBG_ALL         0xffffffffU
+#define DBG_NO_SC      (struct otus_softc *)NULL
+
+unsigned int otus_debug = 0;
+#define DPRINTFN(n, s, ...) do { \
+       if (otus_debug & (n)) { \
+               if ((s) != NULL) \
+                       printf("%s: ", device_xname((s)->sc_dev)); \
+               else \
+                       printf("otus0: "); \
+               printf("%s: ", __func__); \
+               printf(__VA_ARGS__); \
+       } \
+} while (0)
+
+#else  /* ! OTUS_DEBUG */
+
 #define DPRINTFN(n, ...) \
        do { } while (0)
-#endif
-#define DPRINTF(...) \
-       DPRINTFN(1, __VA_ARGS__)
+
+#endif /* OTUS_DEBUG */
 
 Static int     otus_match(device_t, cfdata_t, void *);
 Static void    otus_attach(device_t, device_t, void *);
@@ -114,7 +135,7 @@
 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 *);
+                   struct ieee80211_node *, struct otus_tx_data *);
 Static void    otus_start(struct ifnet *);
 Static void    otus_watchdog(struct ifnet *);
 Static int     otus_ioctl(struct ifnet *, u_long, void *);
@@ -146,7 +167,7 @@
                    struct ieee80211_key *);
 Static void    otus_delete_key_cb(struct otus_softc *, void *);
 #endif /* notyet */
-Static void    otus_calibrate_to(void *);
+Static void    otus_calib_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
@@ -156,6 +177,14 @@
 Static void    otus_led_newstate_type3(struct otus_softc *);
 Static int     otus_init(struct ifnet *);
 Static void    otus_stop(struct ifnet *);
+Static void    otus_wait_async(struct otus_softc *);
+
+#if IEEE80211_INJECTION
+#define IS_INJECTED(m) (((m)->m_flags & M_INJECT) != 0)
+
+static int     otus_output(struct ifnet *, struct mbuf *,
+    const struct sockaddr *, struct rtentry *);
+#endif /* IEEE80211_INJECTION */
 
 /* List of supported channels. */
 static const uint8_t ar_chans[] = {
@@ -568,9 +597,12 @@
 Static int
 otus_match(device_t parent, cfdata_t match, void *aux)
 {
-       struct usb_attach_arg *uaa = aux;
-
-       DPRINTF("otus_match: vendor=0x%x product=0x%x revision=0x%x\n",
+       struct usb_attach_arg *uaa;
+
+       uaa = aux;
+
+       DPRINTFN(DBG_FN, DBG_NO_SC,
+           "otus_match: vendor=0x%x product=0x%x revision=0x%x\n",
                    uaa->vendor, uaa->product, uaa->release);
 
        return usb_lookup(otus_devs, uaa->vendor, uaa->product) != NULL ?
@@ -580,38 +612,44 @@
 Static void
 otus_attach(device_t parent, device_t self, void *aux)
 {
-       struct otus_softc *sc = device_private(self);
-       struct usb_attach_arg *uaa = aux;
+       struct otus_softc *sc;
+       struct usb_attach_arg *uaa;
        char *devinfop;
        int error;
 
-       DPRINTF("otus_attach\n");
+       sc = device_private(self);
+
+       DPRINTFN(DBG_FN, sc, "\n");
 
        sc->sc_dev = self;
+       uaa = aux;
        sc->sc_udev = uaa->device;
 
-       mutex_init(&sc->sc_cmd_mtx,   MUTEX_DEFAULT, IPL_NONE);
-       mutex_init(&sc->sc_task_mtx,  MUTEX_DEFAULT, IPL_NET);
-       mutex_init(&sc->sc_write_mtx, MUTEX_DEFAULT, IPL_NONE);
+       aprint_naive("\n");
+       aprint_normal("\n");
 
        devinfop = usbd_devinfo_alloc(sc->sc_udev, 0);
        aprint_normal_dev(sc->sc_dev, "%s\n", devinfop);
        usbd_devinfo_free(devinfop);
 
+       mutex_init(&sc->sc_cmd_mtx,   MUTEX_DEFAULT, IPL_NONE);
+       mutex_init(&sc->sc_task_mtx,  MUTEX_DEFAULT, IPL_NET);
+       mutex_init(&sc->sc_tx_mtx,    MUTEX_DEFAULT, IPL_NONE);
+       mutex_init(&sc->sc_write_mtx, MUTEX_DEFAULT, IPL_NONE);
+
        usb_init_task(&sc->sc_task, otus_task, sc);
 
        callout_init(&sc->sc_scan_to, 0);
        callout_setfunc(&sc->sc_scan_to, otus_next_scan, sc);
        callout_init(&sc->sc_calib_to, 0);
-       callout_setfunc(&sc->sc_calib_to, otus_calibrate_to, sc);
+       callout_setfunc(&sc->sc_calib_to, otus_calib_to, sc);
 
        sc->sc_amrr.amrr_min_success_threshold =  1;
        sc->sc_amrr.amrr_max_success_threshold = 10;
 
-       error = usbd_set_config_no(sc->sc_udev, 1, 0);
-       if (error != 0) {
-               aprint_error_dev(sc->sc_dev, "failed to set configuration"
-                   ", err=%s\n", usbd_errstr(error));
+       if (usbd_set_config_no(sc->sc_udev, 1, 0) != 0) {
+               aprint_error_dev(sc->sc_dev,
+                   "could not set configuration no\n");
                return;
        }
 
@@ -636,26 +674,35 @@
        usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
 }
 
+Static void
+otus_wait_async(struct otus_softc *sc)
+{
+
+       DPRINTFN(DBG_FN, sc, "\n");
+
+       while (sc->sc_cmdq.queued > 0)
+               tsleep(&sc->sc_cmdq, 0, "sc_cmdq", 0);
+}
+
 Static int
 otus_detach(device_t self, int flags)
 {
-       struct otus_softc *sc = device_private(self);
-       struct ifnet *ifp = sc->sc_ic.ic_ifp;
+       struct otus_softc *sc;
+       struct ifnet *ifp;
        int s;
 
-       DPRINTF("otus_detach\n");
-
+       sc = device_private(self);
+
+       DPRINTFN(DBG_FN, sc, "\n");
+
+       s = splusb();
+
+       sc->sc_dying = 1;
+
+       ifp = sc->sc_ic.ic_ifp;
        if (ifp != NULL)        /* Failed to attach properly */
                otus_stop(ifp);
 
-       s = splnet();
-
-       /* Wait for all queued asynchronous commands to complete. */
-       if (ifp != NULL) {
-               while (sc->sc_cmdq.queued > 0)
-                       tsleep(&sc->sc_cmdq, 0, "sc_cmdq", 0);
-       }
-
        usb_rem_task(sc->sc_udev, &sc->sc_task);
        callout_destroy(&sc->sc_scan_to);
        callout_destroy(&sc->sc_calib_to);
@@ -672,6 +719,7 @@
        usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
 
        mutex_destroy(&sc->sc_write_mtx);
+       mutex_destroy(&sc->sc_tx_mtx);
        mutex_destroy(&sc->sc_task_mtx);
        mutex_destroy(&sc->sc_cmd_mtx);
        return 0;
@@ -680,12 +728,15 @@
 Static int
 otus_activate(device_t self, devact_t act)
 {
-       struct otus_softc *sc = device_private(self);
-
-       DPRINTF("otus_activate: %d\n", act);
+       struct otus_softc *sc;
+
+       sc = device_private(self);
+
+       DPRINTFN(DBG_FN, sc, "%d\n", act);
 
        switch (act) {
        case DVACT_DEACTIVATE:
+               sc->sc_dying = 1;
                if_deactivate(sc->sc_ic.ic_ifp);
                return 0;
        default:
@@ -696,14 +747,19 @@
 Static void
 otus_attachhook(device_t arg)
 {
-       struct otus_softc *sc = device_private(arg);
-       struct ieee80211com *ic = &sc->sc_ic;
-       struct ifnet *ifp = &sc->sc_if;
+       struct otus_softc *sc;
+       struct ieee80211com *ic;
+       struct ifnet *ifp;
        usb_device_request_t req;
        uint32_t in, out;
        int error;
 
-       DPRINTF("otus_attachhook\n");
+       sc = device_private(arg);
+
+       DPRINTFN(DBG_FN, sc, "\n");
+
+       ic = &sc->sc_ic;
+       ifp = &sc->sc_if;
 
        error = otus_load_firmware(sc, "otus-init", AR_FW_INIT_ADDR);
        if (error != 0) {
@@ -774,8 +830,7 @@
            IEEE80211_C_MONITOR |       /* monitor mode supported */
            IEEE80211_C_SHPREAMBLE |    /* short preamble supported */
            IEEE80211_C_SHSLOT |        /* short slot time supported */
-           IEEE80211_C_WEP |           /* WEP */
-           IEEE80211_C_WPA;            /* WPA1+WPA2 */
+           IEEE80211_C_WPA;            /* 802.11i */
 
        if (sc->sc_eeprom.baseEepHeader.opCapFlags & AR5416_OPFLAGS_11G) {
                /* Set supported .11b and .11g rates. */
@@ -816,6 +871,13 @@
        ic->ic_set_key = otus_set_key;
        ic->ic_delete_key = otus_delete_key;
 #endif /* notyet */
+
+#if IEEE80211_INJECTION
+       /* hook our packet injection output routine */
+       sc->sc_if_output = ifp->if_output;
+       ifp->if_output = otus_output;
+#endif
+
        /* Override state transition machine. */
        sc->sc_newstate = ic->ic_newstate;
        ic->ic_newstate = otus_newstate;
@@ -839,15 +901,17 @@
 Static void
 otus_get_chanlist(struct otus_softc *sc)
 {
-       struct ieee80211com *ic = &sc->sc_ic;
+       struct ieee80211com *ic;
        uint16_t domain;
        uint8_t chan;
        int i;
 



Home | Main Index | Thread Index | Old Index