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 Simplify and adapt to latest usbwifi changes.



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

description:
Simplify and adapt to latest usbwifi changes.

diffstat:

 sys/dev/usb/if_run.c    |  121 +++++++++++++++++++++++------------------------
 sys/dev/usb/if_runvar.h |    9 +--
 2 files changed, 62 insertions(+), 68 deletions(-)

diffs (truncated from 459 to 300 lines):

diff -r 5cac783e877a -r 14c67d704826 sys/dev/usb/if_run.c
--- a/sys/dev/usb/if_run.c      Tue Feb 08 21:03:01 2022 +0100
+++ b/sys/dev/usb/if_run.c      Tue Feb 08 21:04:15 2022 +0100
@@ -47,7 +47,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>
@@ -585,7 +584,7 @@
 {
        struct run_softc *sc = device_private(self);
        struct usb_attach_arg *uaa = aux;
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
        usb_interface_descriptor_t *id;
        usb_endpoint_descriptor_t *ed;
        char *devinfop;
@@ -618,9 +617,7 @@
        aprint_normal_dev(self, "%s\n", devinfop);
        usbd_devinfo_free(devinfop);
 
-       usbwifi_attach(&sc->sc_uw, "rundet");
-
-       usbwifi_lock_core(&sc->sc_uw);
+       usbwifi_attach(&sc->sc_uw);
 
        error = usbd_set_config_no(sc->sc_uw.uw_udev, 1, 0);
        if (error != 0) {
@@ -707,7 +704,7 @@
        * here.
        */
        if (sc->mac_ver == 0x5390)
-               sc->sc_flags |= RUN_USE_BLOCK_WRITE;
+               sc->sc_uw.uw_flags |= RUN_USE_BLOCK_WRITE;
 
        /* retrieve RF rev. no and various other things from EEPROM */
        run_read_eeprom(sc);
@@ -780,25 +777,19 @@
        ic->ic_th = &sc->sc_txtapu.th.wt_ihdr;
 
        usbwifi_attach_finalize(&sc->sc_uw);
-
-       usbwifi_unlock_core(&sc->sc_uw);
-
-
 }
 
 static int
 run_detach(device_t self, int flags)
 {
        struct run_softc *sc = device_private(self);
-
-       usbwifi_set_dying(&sc->sc_uw, true);
-       
-       sc->sc_uw.uw_flags |= RUN_DETACHING;
-
-       usbwifi_detach(self, flags);
+       int err;
+
+       err = usbwifi_detach(self, flags);
+       if (err)
+               return err;
 
        callout_stop(&sc->calib_to);
-
        callout_destroy(&sc->calib_to);
 
        return 0;
@@ -814,6 +805,8 @@
        uint32_t tmp;
        int ntries, error;
 
+       usbwifi_isowned_ic(&sc->sc_uw);
+
        /* RT3071/RT3072 use a different firmware */
        if (sc->mac_ver != 0x2860 &&
            sc->mac_ver != 0x2872 &&
@@ -870,7 +863,7 @@
                return ETIMEDOUT;
        }
 
-       sc->sc_flags |= RUN_FWLOADED;
+       sc->sc_uw.uw_flags |= RUN_FWLOADED;
 
        DPRINTF(("microcode successfully loaded after %d tries\n", ntries));
        return 0;
@@ -943,7 +936,7 @@
     int len)
 {
        int error = 0;
-       if (sc->sc_flags & RUN_USE_BLOCK_WRITE) {
+       if (sc->sc_uw.uw_flags & RUN_USE_BLOCK_WRITE) {
                usb_device_request_t req;
                /*
                 * NOTE: It appears the WRITE_REGION_1 command cannot be
@@ -984,7 +977,7 @@
 {
        int error = 0;
 
-       if (sc->sc_flags & RUN_USE_BLOCK_WRITE) {
+       if (sc->sc_uw.uw_flags & RUN_USE_BLOCK_WRITE) {
                while (count > 0) {
                        int i, delta;
                        uint32_t tmp[16];
@@ -1399,7 +1392,7 @@
 static int
 run_read_eeprom(struct run_softc *sc)
 {
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
        int8_t delta_2ghz, delta_5ghz;
        uint32_t tmp;
        uint16_t val;
@@ -1716,7 +1709,7 @@
        struct run_host_cmd *cmd;
        int s;
 
-       if (sc->sc_flags & RUN_DETACHING)
+       if (usbwifi_isdying(&sc->sc_uw))
                return;
 
        s = splusb();
@@ -1733,6 +1726,10 @@
        splx(s);
 }
 
+/*
+ * A VAP changes state.
+ * This is called with thread context and the 'ic' lock held.
+ */
 static int
 run_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
 {
@@ -1744,7 +1741,6 @@
        uint32_t tmp, sta[3];
        uint8_t wcid;
 
-       usbwifi_lock_core(&sc->sc_uw);
        callout_stop(&sc->calib_to);
 
        ostate = vap->iv_state;
@@ -1825,8 +1821,7 @@
                printf ("RUN UNKNOWN nSTATE: %d\n", nstate);
                break;
        }
-       usbwifi_unlock_core(&sc->sc_uw);
-       
+
        return (*rvap->newstate)(vap, nstate, arg);
 }
 
@@ -1836,7 +1831,7 @@
 // {
 //     struct run_cmd_newstate *cmd = arg;
 //     struct ifnet *ifp = &sc->sc_if;
-//     struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+//     struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
 //     enum ieee80211_state ostate;
 //     struct ieee80211_node *ni;
 //     uint32_t tmp, sta[3];
@@ -1932,7 +1927,7 @@
 static void
 run_updateedca_cb(struct run_softc *sc, void *arg)
 {
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
        int s, aci;
 
        s = splnet();
@@ -1990,7 +1985,7 @@
 run_set_key_cb(struct run_softc *sc, void *arg)
 {
 #ifndef IEEE80211_STA_ONLY
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
 #endif
        struct run_cmd_key *cmd = arg;
        struct ieee80211_key *k = &cmd->key;
@@ -2048,7 +2043,8 @@
                /* set initial packet number in IV+EIV */
                if (k->wk_cipher->ic_cipher == IEEE80211_CIPHER_WEP) {
                        memset(iv, 0, sizeof(iv));
-                       iv[3] = sc->sc_uw.uw_ic.ic_crypto.cs_def_txkey << 6;
+                       iv[3] = usbwifi_ic(&sc->sc_uw)
+                            ->ic_crypto.cs_def_txkey << 6;
                } else {
                        if (k->wk_cipher->ic_cipher == IEEE80211_CIPHER_TKIP) {
                                iv[0] = k->wk_keytsc >> 8;
@@ -2138,9 +2134,9 @@
 {
        uint32_t sta[3];
        int s, error;
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
        
-       usbwifi_lock_core(&sc->sc_uw);
+       usbwifi_lock_ic(&sc->sc_uw);
 
        /* read statistic counters (clear on read) and update AMRR state */
        error = run_read_region_1(sc, RT2860_TX_STA_CNT0, (uint8_t *)sta,
@@ -2166,11 +2162,12 @@
 
        /* XXX amrr not implemented yet? */
        /*
-       ieee80211_amrr_choose(&sc->amrr, sc->sc_uw.uw_ic.ic_bss, &sc->amn);
+       ieee80211_amrr_choose(&sc->amrr, usbwifi_ic(&sc->sc_uw)->ic_bss,
+           &sc->amn);
        */
        splx(s);
 
-skip:  usbwifi_unlock_core(&sc->sc_uw);        
+skip:  usbwifi_unlock_ic(&sc->sc_uw);  
        callout_schedule(&sc->calib_to, hz);
 }
 
@@ -2238,7 +2235,7 @@
 static void
 run_rx_frame(struct run_softc *sc, uint8_t *buf, int dmalen)
 {
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic; 
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
        struct ieee80211_frame *wh;
        struct rt2870_rxd *rxd;
        struct rt2860_rxwi *rxwi;
@@ -2337,7 +2334,7 @@
 static void
 run_rx_loop(struct usbwifi *uw, struct usbwifi_chain *c, uint32_t len)
 {
-       struct run_softc *sc = uw->uw_sc;
+       struct run_softc *sc = usbwifi_softc(uw);
        uint8_t *buf;
        uint32_t dmalen;
        uint16_t rxwisize;
@@ -2345,7 +2342,7 @@
        DPRINTFN(5, ("%s: %s: chain %p len %u\n",
            device_xname(sc->sc_uw.uw_dev), __func__, c, len));
 
-       if (__predict_false(sc->sc_flags & RUN_DETACHING))
+       if (__predict_false(usbwifi_isdying(&sc->sc_uw)))
                return;
 
        rxwisize = sizeof(struct rt2860_rxwi);
@@ -2384,11 +2381,11 @@
 static unsigned
 run_tx_prepare(struct usbwifi *uw, struct usbwifi_chain *chain, uint8_t qid)
 {
-       struct ieee80211com *ic = &uw->uw_ic; 
+       struct ieee80211com *ic = usbwifi_ic(uw);
        struct ieee80211_node *ni = chain->uwc_ni;
        struct run_node *rn = (void *)ni;
        struct ieee80211_frame *wh;
-       struct run_softc *sc = uw->uw_sc;
+       struct run_softc *sc = usbwifi_softc(uw);
 #ifndef RUN_HWCRYPTO
        struct ieee80211_key *k;
 #endif
@@ -2408,6 +2405,7 @@
                k = ieee80211_crypto_encap(ni, m);
                if (k == NULL) {
                        m_freem(m);
+DPRINTF(("%s: failed to encrypt packet\n", __func__));
                        return 0;
                }
                
@@ -2511,7 +2509,7 @@
 run_watchdog(void *arg)
 {
        struct run_softc *sc = arg;
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
 
        DPRINTFN(5, ("%s: %s\n", device_xname(sc->sc_uw.uw_dev), __func__));
 
@@ -3499,15 +3497,15 @@
 
        DPRINTFN(5, ("%s: %s\n",device_xname(sc->sc_uw.uw_dev), __func__));
 
-       usbwifi_lock_core(&sc->sc_uw);
+       usbwifi_lock_ic(&sc->sc_uw);
        run_set_chan(sc, ic->ic_curchan);
-       usbwifi_unlock_core(&sc->sc_uw);
+       usbwifi_unlock_ic(&sc->sc_uw);
 } 
 
 static int
 run_set_chan(struct run_softc *sc, struct ieee80211_channel *c)
 {
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
+       struct ieee80211com *ic = usbwifi_ic(&sc->sc_uw);
        u_int chan, group;
 
        chan = ieee80211_chan2ieee(ic, c);
@@ -3552,7 +3550,7 @@
 static void
 run_updateprot(struct run_softc *sc)
 {
-       struct ieee80211com *ic = &sc->sc_uw.uw_ic;



Home | Main Index | Thread Index | Old Index