Source-Changes-HG archive

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

[src-draft/trunk]: src/sys/dev/usb Adapt to latest usbwifi changes



details:   https://anonhg.NetBSD.org/src-all/rev/48967b87bad4
branches:  trunk
changeset: 360732:48967b87bad4
user:      Martin Husemann <martin%NetBSD.org@localhost>
date:      Tue Feb 08 21:07:14 2022 +0100

description:
Adapt to latest usbwifi changes

diffstat:

 sys/dev/usb/if_urtwn.c    |  212 ++++++++++++++++++++++-----------------------
 sys/dev/usb/if_urtwnvar.h |    6 +-
 2 files changed, 108 insertions(+), 110 deletions(-)

diffs (truncated from 779 to 300 lines):

diff -r 096239db8cbf -r 48967b87bad4 sys/dev/usb/if_urtwn.c
--- a/sys/dev/usb/if_urtwn.c    Tue Feb 08 21:04:15 2022 +0100
+++ b/sys/dev/usb/if_urtwn.c    Tue Feb 08 21:07:14 2022 +0100
@@ -65,7 +65,6 @@
 #include <machine/endian.h>
 #include <sys/intr.h>
 
-#include <net/bpf.h>
 #include <net/if.h>
 #include <net/if_arp.h>
 #include <net/if_dl.h>
@@ -334,7 +333,6 @@
 static void    urtwn_temp_calib(struct urtwn_softc *);
 static void    urtwn_newassoc(struct ieee80211_node *, int);
 static void    urtwn_delay_ms(struct urtwn_softc *, int ms);
-static void    urtwn_chip_stop(struct urtwn_softc *);
 /* Functions for wifi refresh */
 static struct ieee80211vap *
                urtwn_vap_create(struct ieee80211com *,
@@ -385,7 +383,7 @@
 urtwn_attach( device_t parent, device_t self, void *aux)
 {
        struct urtwn_softc *sc = device_private(self);
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
        struct usb_attach_arg *uaa = aux;
        char *devinfop;
        const struct urtwn_dev *dev;
@@ -432,12 +430,10 @@
 
        (void) usbd_do_request(sc->sc_uw.uw_udev, &req, 0);
 
+       cv_init(&sc->sc_task_cv, "urtwntsk");
        mutex_init(&sc->sc_task_mtx, MUTEX_DEFAULT, IPL_NET);
 
-       usbwifi_attach(&sc->sc_uw, "urtwndet");
-
-       usbwifi_lock_core(&sc->sc_uw);
-       usb_init_task(&sc->sc_task, urtwn_task, sc, 0);
+       usbwifi_attach(&sc->sc_uw);
 
        /* NNN make these callouts use a vap ... in vap create??? */
        callout_init(&sc->sc_calib_to, CALLOUT_MPSAFE);
@@ -503,6 +499,9 @@
            num_rx, num_rx > 1 ? "s" : "",
            num_tx, num_tx > 1 ? "s" : "");
 
+       /* use usbwifi tick instead? */
+       usb_init_task(&sc->sc_task, urtwn_task, sc, 0);
+
        /* Set device capabilities. */
        ic->ic_caps =
            IEEE80211_C_STA |           /* station mode */
@@ -568,14 +567,9 @@
        ic->ic_th = &sc->sc_txtapu.th.wt_ihdr;
 
        usbwifi_attach_finalize(&sc->sc_uw);
-
-       usbwifi_unlock_core(&sc->sc_uw);
-
        return;
 
 fail:
-       usbwifi_set_dying(&sc->sc_uw, true);
-       usbwifi_unlock_core(&sc->sc_uw);
        aprint_error_dev(self, "attach failed\n");
 }
 
@@ -583,24 +577,21 @@
 urtwn_detach(device_t self, int flags)
 {
        struct urtwn_softc *sc = device_private(self);
+       int err;
 
        URTWNHIST_FUNC(); URTWNHIST_CALLED();
 
-       usbwifi_set_dying(&sc->sc_uw, true);
+       err = usbwifi_detach(self, flags);
+       if (err)
+               return err;
 
        callout_halt(&sc->sc_calib_to, NULL);
-
-       usbwifi_detach(self, flags);
-
-       if (ISSET(sc->sc_uw.uw_flags, URTWN_FLAG_ATTACHED)) {
-               usb_rem_task_wait(sc->sc_uw.uw_udev, &sc->sc_task, USB_TASKQ_DRIVER,
-                   NULL);
-       }
-
+       if (sc->sc_uw.uw_pri != NULL)
+               usb_rem_task_wait(sc->sc_uw.uw_udev, &sc->sc_task,
+                   USB_TASKQ_DRIVER, NULL);
        callout_destroy(&sc->sc_calib_to);
-
+       cv_destroy(&sc->sc_task_cv);
        mutex_destroy(&sc->sc_task_mtx);
-
        return 0;
 }
 
@@ -677,8 +668,9 @@
 urtwn_task(void *arg)
 {
        struct urtwn_softc *sc = arg;
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
        struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
+/* XXX VAP is wrong */
        struct urtwn_host_cmd_ring *ring = &sc->cmdq;
        struct urtwn_host_cmd *cmd;
        int s;
@@ -721,8 +713,8 @@
                ring->queued--;
                ring->next = (ring->next + 1) % URTWN_HOST_CMD_RING_COUNT;
        }
+       cv_broadcast(&sc->sc_task_cv);
        mutex_spin_exit(&sc->sc_task_mtx);
-       wakeup(&sc->cmdq);
        splx(s);
 }
 
@@ -763,8 +755,10 @@
        URTWNHIST_FUNC(); URTWNHIST_CALLED();
 
        /* Wait for all queued asynchronous commands to complete. */
+       mutex_spin_enter(&sc->sc_task_mtx);
        while (sc->cmdq.queued > 0)
-               tsleep(&sc->cmdq, 0, "endtask", 0);
+               cv_wait(&sc->sc_task_cv, &sc->sc_task_mtx);
+       mutex_spin_exit(&sc->sc_task_mtx);
 }
 
 static int
@@ -775,7 +769,7 @@
        usbd_status error;
 
        URTWNHIST_FUNC(); URTWNHIST_CALLED();
-       usbwifi_isowned_core(&sc->sc_uw);
+       usbwifi_isowned_ic(&sc->sc_uw);
 
        req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
        req.bRequest = R92C_REQ_REGS;
@@ -847,7 +841,7 @@
        usbd_status error;
 
        URTWNHIST_FUNC(); URTWNHIST_CALLED();
-       usbwifi_isowned_core(&sc->sc_uw);
+       usbwifi_isowned_ic(&sc->sc_uw);
 
        req.bmRequestType = UT_READ_VENDOR_DEVICE;
        req.bRequest = R92C_REQ_REGS;
@@ -921,7 +915,12 @@
        DPRINTFN(DBG_REG, "id=%jd, buf=%#jx, len=%jd", id, (intptr_t)buf,
            len, 0);
 
-       usbwifi_isowned_core(&sc->sc_uw);
+       usbwifi_isowned_ic(&sc->sc_uw);
+       if (!ISSET(sc->sc_uw.uw_flags, URTWN_FLAG_FWREADY)) {
+               DPRINTFN(DBG_INIT, "fw not running, uw_flags=%jx",
+                   sc->sc_uw.uw_flags, 0, 0, 0);
+               return EAGAIN;
+       }
 
        fwcur = sc->fwcur;
        sc->fwcur = (sc->fwcur + 1) % R92C_H2C_NBOX;
@@ -952,13 +951,13 @@
                            &cp[1], 2);
                        urtwn_write_4(sc, R92C_HMEBOX(fwcur),
                            cp[0] + (cp[3] << 8) + (cp[4] << 16) +
-                           (cp[5] << 24));
+                           ((uint32_t)cp[5] << 24));
                } else {
                        urtwn_write_region(sc, R92E_HMEBOX_EXT(fwcur),
                            &cp[4], 2);
                        urtwn_write_4(sc, R92C_HMEBOX(fwcur),
                            cp[0] + (cp[1] << 8) + (cp[2] << 16) +
-                           (cp[3] << 24));
+                           ((uint32_t)cp[3] << 24));
                }
        } else {
                urtwn_write_region(sc, R92C_HMEBOX(fwcur), cp, len);
@@ -1037,7 +1036,7 @@
 {
        int ntries;
 
-       usbwifi_isowned_core(&sc->sc_uw);
+       usbwifi_isowned_ic(&sc->sc_uw);
 
        urtwn_write_4(sc, R92C_LLT_INIT,
            SM(R92C_LLT_INIT_OP, R92C_LLT_INIT_OP_WRITE) |
@@ -1061,7 +1060,7 @@
        uint32_t reg;
        int ntries;
 
-       usbwifi_isowned_core(&sc->sc_uw);
+       usbwifi_isowned_ic(&sc->sc_uw);
 
        reg = urtwn_read_4(sc, R92C_EFUSE_CTRL);
        reg = RW(reg, R92C_EFUSE_CTRL_ADDR, addr);
@@ -1093,7 +1092,7 @@
 
        URTWNHIST_FUNC(); URTWNHIST_CALLED();
 
-       usbwifi_isowned_core(&sc->sc_uw);
+       usbwifi_isowned_ic(&sc->sc_uw);
 
        urtwn_efuse_switch_power(sc);
 
@@ -1270,12 +1269,12 @@
 static void
 urtwn_read_rom(struct urtwn_softc *sc)
 {
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
        struct r92c_rom *rom = &sc->rom;
 
        URTWNHIST_FUNC(); URTWNHIST_CALLED();
 
-       usbwifi_isowned_core(&sc->sc_uw);
+       usbwifi_isowned_ic(&sc->sc_uw);
 
        /* Read full ROM image. */
        urtwn_efuse_read(sc);
@@ -1302,7 +1301,7 @@
 static void
 urtwn_r88e_read_rom(struct urtwn_softc *sc)
 {
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
        uint8_t *rom = sc->r88e_rom;
        uint32_t reg;
        uint16_t addr = 0;
@@ -1311,7 +1310,7 @@
 
        URTWNHIST_FUNC(); URTWNHIST_CALLED();
 
-       usbwifi_isowned_core(&sc->sc_uw);
+       usbwifi_isowned_ic(&sc->sc_uw);
 
        off = 0;
        urtwn_efuse_switch_power(sc);
@@ -1395,7 +1394,7 @@
 
        URTWNHIST_FUNC(); URTWNHIST_CALLED();
 
-       usbwifi_isowned_core(&sc->sc_uw);
+       usbwifi_isowned_ic(&sc->sc_uw);
 
        /* Get normal and basic rates mask. */
        rates = basicrates = 1;
@@ -1489,7 +1488,7 @@
 static int
 urtwn_get_nettype(struct urtwn_softc *sc)
 {
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
        int type;
 
        URTWNHIST_FUNC(); URTWNHIST_CALLED();
@@ -1519,7 +1518,7 @@
        URTWNHIST_FUNC();
        URTWNHIST_CALLARGS("type=%jd", type, 0, 0, 0);
 
-       usbwifi_isowned_core(&sc->sc_uw);
+       usbwifi_isowned_ic(&sc->sc_uw);
 
        reg = urtwn_read_1(sc, R92C_CR + 2) & 0x0c;
        urtwn_write_1(sc, R92C_CR + 2, reg | type);
@@ -1529,12 +1528,13 @@
 urtwn_tsf_sync_enable(struct urtwn_softc *sc)
 {
        struct ieee80211vap *vap  = TAILQ_FIRST(&sc->sc_uw.uw_ic.ic_vaps);
+/* XXX VAP is wrong */
        struct ieee80211_node *ni = vap->iv_bss;
        uint64_t tsf;
 
        URTWNHIST_FUNC(); URTWNHIST_CALLED();
 
-       usbwifi_isowned_core(&sc->sc_uw);
+       usbwifi_isowned_ic(&sc->sc_uw);
 
        /* Enable TSF synchronization. */
        urtwn_write_1(sc, R92C_BCN_CTRL,
@@ -1564,7 +1564,7 @@
        URTWNHIST_FUNC();
        URTWNHIST_CALLARGS("led=%jd, on=%jd", led, on, 0, 0);
 
-       usbwifi_isowned_core(&sc->sc_uw);
+       usbwifi_isowned_ic(&sc->sc_uw);
 
        if (led == URTWN_LED_LINK) {
                if (ISSET(sc->chip, URTWN_CHIP_92EU)) {
@@ -1604,6 +1604,7 @@
 {
        struct urtwn_softc *sc = arg;
        struct ieee80211vap *vap = TAILQ_FIRST(&(sc->sc_uw.uw_ic.ic_vaps));
+/* XXX VAP is wrong */
 
        URTWNHIST_FUNC(); URTWNHIST_CALLED();



Home | Main Index | Thread Index | Old Index