Source-Changes-HG archive

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

[src-draft/trunk]: src Merge in Martin's changes.



details:   https://anonhg.NetBSD.org/src-all/rev/9db37d73126c
branches:  trunk
changeset: 1027130:9db37d73126c
user:      Nathanial Sloss <nat%netbsd.org@localhost>
date:      Thu Nov 18 08:39:49 2021 +1100

description:
Merge in Martin's changes.

diffstat:

 sys/dev/usb/if_run.c    |  1248 ++++++++++++++++++----------------------------
 sys/dev/usb/if_runvar.h |    19 +-
 2 files changed, 508 insertions(+), 759 deletions(-)

diffs (truncated from 2130 to 300 lines):

diff -r 9b79dc8cc430 -r 9db37d73126c sys/dev/usb/if_run.c
--- a/sys/dev/usb/if_run.c      Sun Nov 07 13:19:20 2021 +1100
+++ b/sys/dev/usb/if_run.c      Thu Nov 18 08:39:49 2021 +1100
@@ -65,10 +65,11 @@
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
-#include <dev/usb/usbdivar.h>
 #include <dev/usb/usbdi_util.h>
 #include <dev/usb/usbdevs.h>
 
+#include <dev/usb/usbwifi.h>
+
 #include <dev/ic/rt2860reg.h>          /* shared with ral(4) */
 #include <dev/usb/if_runvar.h>
 
@@ -333,15 +334,10 @@
 static int             run_match(device_t, cfdata_t, void *);
 static void            run_attach(device_t, device_t, void *);
 static int             run_detach(device_t, int);
-static int             run_activate(device_t, enum devact);
 
 CFATTACH_DECL_NEW(run, sizeof(struct run_softc),
-       run_match, run_attach, run_detach, run_activate);
-
-static int             run_alloc_rx_ring(struct run_softc *);
-static void            run_free_rx_ring(struct run_softc *);
-static int             run_alloc_tx_ring(struct run_softc *, int);
-static void            run_free_tx_ring(struct run_softc *, int);
+       run_match, run_attach, run_detach, usbwifi_activate);
+
 static int             run_load_microcode(struct run_softc *);
 static int             run_reset(struct run_softc *);
 static int             run_read(struct run_softc *, uint16_t, uint32_t *);
@@ -373,15 +369,14 @@
 static void            run_get_txpower(struct run_softc *);
 static int             run_read_eeprom(struct run_softc *);
 static struct ieee80211_node *
-                       run_node_alloc(struct ieee80211_node_table *);
-static int             run_media_change(struct ifnet *);
-static void            run_next_scan(void *);
+                       run_node_alloc(struct ieee80211vap *, const uint8_t *);
+static int             run_media_change(struct ifnet *); 
 static void            run_task(void *);
 static void            run_do_async(struct run_softc *,
                            void (*)(struct run_softc *, void *), void *, int);
-static int             run_newstate(struct ieee80211com *,
+static int             run_newstate(struct ieee80211vap *,
                            enum ieee80211_state, int);
-static void            run_newstate_cb(struct run_softc *, void *);
+/* static void         run_newstate_cb(struct run_softc *, void *); */
 static int             run_updateedca(struct ieee80211com *);
 static void            run_updateedca_cb(struct run_softc *, void *);
 #ifdef RUN_HWCRYPTO
@@ -396,15 +391,15 @@
 static void            run_calibrate_cb(struct run_softc *, void *);
 static void            run_newassoc(struct ieee80211_node *, int);
 static void            run_rx_frame(struct run_softc *, uint8_t *, int);
-static void            run_rxeof(struct usbd_xfer *, void *,
-                           usbd_status);
-static void            run_txeof(struct usbd_xfer *, void *,
-                           usbd_status);
-static int             run_tx(struct run_softc *, struct mbuf *,
-                           struct ieee80211_node *);
-static void            run_start(struct ifnet *);
-static void            run_watchdog(struct ifnet *);
-static int             run_ioctl(struct ifnet *, u_long, void *);
+static void            run_rx_loop(struct usbwifi *, struct usbwifi_chain *, 
+                                   uint32_t);
+/* static void         run_txeof(struct usbd_xfer *, void *,
+                           usbd_status); */
+static unsigned        run_tx_prepare(struct usbwifi *, struct usbwifi_chain *, 
+                                   uint8_t);
+/* static void         run_start(struct ifnet *); */
+static void            run_watchdog(void *);
+/* static int          run_ioctl(struct ifnet *, u_long, void *); */
 static void            run_select_chan_group(struct run_softc *, int);
 static void            run_iq_calib(struct run_softc *, u_int);
 static void            run_set_agc(struct run_softc *, uint8_t);
@@ -418,14 +413,14 @@
 static int             run_set_chan(struct run_softc *,
                            struct ieee80211_channel *);
 static void            run_updateprot(struct run_softc *);
-static void            run_enable_tsf_sync(struct run_softc *);
+static void            run_enable_tsf_sync(struct ieee80211vap *);
 static void            run_enable_mrr(struct run_softc *);
 static void            run_set_txpreamble(struct run_softc *);
 static void            run_set_basicrates(struct run_softc *);
 static void            run_set_leds(struct run_softc *, uint16_t);
 static void            run_set_bssid(struct run_softc *, const uint8_t *);
 static void            run_set_macaddr(struct run_softc *, const uint8_t *);
-static void            run_updateslot(struct ifnet *);
+static void            run_updateslot(struct ieee80211com *);
 static void            run_updateslot_cb(struct run_softc *, void *);
 static int8_t          run_rssi2dbm(struct run_softc *, uint8_t, uint8_t);
 static void            run_rt5390_bbp_init(struct run_softc *);
@@ -440,11 +435,23 @@
 static void            run_rt5390_rf_setup(struct run_softc *);
 static int             run_txrx_enable(struct run_softc *);
 static int                     run_adjust_freq_offset(struct run_softc *);
-static int             run_init(struct ifnet *);
-static void            run_stop(struct ifnet *, int);
+static int             run_init(struct usbwifi *);
+static void            run_stop(struct usbwifi *);
 #ifndef IEEE80211_STA_ONLY
-static int             run_setup_beacon(struct run_softc *);
+static int             run_setup_beacon(struct ieee80211vap *);
 #endif
+static void    run_get_radiocaps(struct ieee80211com *, int , int *,
+                       struct ieee80211_channel []);
+static struct ieee80211vap *   run_vap_create(struct ieee80211com *,
+                                   const char [IFNAMSIZ],int,
+                                   enum ieee80211_opmode, int,
+                                   const uint8_t [IEEE80211_ADDR_LEN],
+                                   const uint8_t [IEEE80211_ADDR_LEN]);
+static void    run_vap_delete(struct ieee80211vap *);
+static void    run_scan_start(struct ieee80211com *);
+static void    run_scan_end(struct ieee80211com *);
+static void    run_set_channel(struct ieee80211com *);
+       
 
 static const struct {
        uint32_t reg;
@@ -531,6 +538,18 @@
        RT5592_CHAN_5GHZ
 };
 
+struct run_vap {
+       struct ieee80211vap vap;
+       int (*newstate)(struct ieee80211vap *, enum ieee80211_state, int);
+};
+
+static const struct usbwifi_ops run_ops = {
+       .uwo_rx_loop = run_rx_loop,
+       .uwo_tx_prepare = run_tx_prepare,
+       .uwo_init = run_init,
+       .uwo_stop = run_stop,
+};
+
 static int
 firmware_load(const char *dname, const char *iname, uint8_t **ucodep,
     size_t *sizep)
@@ -566,35 +585,52 @@
 {
        struct run_softc *sc = device_private(self);
        struct usb_attach_arg *uaa = aux;
-       struct ieee80211com *ic = &sc->sc_ic;
-       struct ifnet *ifp = &sc->sc_if;
+       struct ieee80211com *ic = &sc->sc_uw.uw_ic;
        usb_interface_descriptor_t *id;
        usb_endpoint_descriptor_t *ed;
        char *devinfop;
        int i, nrx, ntx, ntries, error;
        uint32_t ver;
+       uint8_t rxq, txq[RUN_MAXEPOUT];
 
        aprint_naive("\n");
        aprint_normal("\n");
-
-       sc->sc_dev = self;
-       sc->sc_udev = uaa->uaa_device;
-
-       devinfop = usbd_devinfo_alloc(sc->sc_udev, 0);
-       aprint_normal_dev(sc->sc_dev, "%s\n", devinfop);
+       
+       ic->ic_softc = sc;
+
+       sc->sc_uw.uw_sc = sc;
+       sc->sc_uw.uw_dev = self;
+       sc->sc_uw.uw_udev = uaa->uaa_device;
+       sc->sc_uw.uw_ops = &run_ops;
+       sc->sc_uw.uw_rx_xfer_flags = USBD_SHORT_XFER_OK;
+       sc->sc_uw.uw_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
+       sc->sc_uw.uw_rx_bufsz = RUN_MAX_RXSZ;
+       sc->sc_uw.uw_tx_bufsz = RUN_MAX_TXSZ;
+       sc->sc_uw.uw_rx_list_cnt = RUN_RX_RING_COUNT;
+       sc->sc_uw.uw_tx_list_cnt = RUN_TX_RING_COUNT;
+
+       sc->sc_sendq.ifq_maxlen = ifqmaxlen;
+       IFQ_LOCK_INIT(&sc->sc_sendq);
+
+       devinfop = usbd_devinfo_alloc(sc->sc_uw.uw_udev, 0);
+       aprint_normal_dev(self, "%s\n", devinfop);
        usbd_devinfo_free(devinfop);
 
-       error = usbd_set_config_no(sc->sc_udev, 1, 0);
+       usbwifi_attach(&sc->sc_uw, "rundet");
+
+       usbwifi_lock_core(&sc->sc_uw);
+
+       error = usbd_set_config_no(sc->sc_uw.uw_udev, 1, 0);
        if (error != 0) {
-               aprint_error_dev(sc->sc_dev, "failed to set configuration"
+               aprint_error_dev(self, "failed to set configuration"
                    ", err=%s\n", usbd_errstr(error));
                return;
        }
 
        /* get the first interface handle */
-       error = usbd_device2interface_handle(sc->sc_udev, 0, &sc->sc_iface);
+       error = usbd_device2interface_handle(sc->sc_uw.uw_udev, 0, &sc->sc_uw.uw_iface);
        if (error != 0) {
-               aprint_error_dev(sc->sc_dev,
+               aprint_error_dev(self,
                    "could not get interface handle\n");
                return;
        }
@@ -606,31 +642,38 @@
         * seem to have only 4 TX bulk endpoints (Fukaumi Naoki).
         */
        nrx = ntx = 0;
-       id = usbd_get_interface_descriptor(sc->sc_iface);
+       id = usbd_get_interface_descriptor(sc->sc_uw.uw_iface);
        for (i = 0; i < id->bNumEndpoints; i++) {
-               ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
+               ed = usbd_interface2endpoint_descriptor(sc->sc_uw.uw_iface, i);
                if (ed == NULL || UE_GET_XFERTYPE(ed->bmAttributes) != UE_BULK)
                        continue;
 
                if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN) {
-                       sc->rxq.pipe_no = ed->bEndpointAddress;
+                       rxq = ed->bEndpointAddress;
                        nrx++;
                } else if (ntx < RUN_MAXEPOUT) {
-                       sc->txq[ntx].pipe_no = ed->bEndpointAddress;
+                       txq[ntx] = ed->bEndpointAddress;
                        ntx++;
                }
        }
        /* make sure we've got them all */
        if (nrx < 1 || ntx < RUN_MAXEPOUT) {
-               aprint_error_dev(sc->sc_dev, "missing endpoint\n");
+               aprint_error_dev(self, "missing endpoint\n");
                return;
        }
+       
+       memcpy(&sc->sc_uw.uw_ed[0], txq, sizeof(txq[0])*ntx);
+       memcpy(&sc->sc_uw.uw_ed[ntx], &rxq, sizeof(rxq)*nrx);
 
        usb_init_task(&sc->sc_task, run_task, sc, 0);
+       /*
        callout_init(&sc->scan_to, 0);
        callout_setfunc(&sc->scan_to, run_next_scan, sc);
+       */
        callout_init(&sc->calib_to, 0);
        callout_setfunc(&sc->calib_to, run_calibrate_to, sc);
+       callout_init(&sc->sc_watchdog_to, CALLOUT_MPSAFE);
+       callout_setfunc(&sc->sc_watchdog_to, run_watchdog, sc);
 
        sc->amrr.amrr_min_success_threshold =  1;
        sc->amrr.amrr_max_success_threshold = 10;
@@ -644,7 +687,7 @@
                DELAY(10);
        }
        if (ntries == 100) {
-               aprint_error_dev(sc->sc_dev,
+               aprint_error_dev(self,
                    "timeout waiting for NIC to initialize\n");
                return;
        }
@@ -667,19 +710,23 @@
        /* retrieve RF rev. no and various other things from EEPROM */
        run_read_eeprom(sc);
 
-       aprint_verbose_dev(sc->sc_dev,
+       aprint_verbose_dev(self,
            "MAC/BBP RT%04X (rev 0x%04X), RF %s (MIMO %dT%dR), address %s\n",
            sc->mac_ver, sc->mac_rev, run_get_rf(sc->rf_rev), sc->ntxchains,
-           sc->nrxchains, ether_sprintf(ic->ic_myaddr));
-
-       ic->ic_ifp = ifp;
+           sc->nrxchains, ether_sprintf(ic->ic_macaddr));
+
+       ic->ic_name = device_xname(self);
+
+       ic->ic_txstream = sc->ntxchains;
+       ic->ic_rxstream = sc->nrxchains;
+
        ic->ic_phytype = IEEE80211_T_OFDM;      /* not only, but not used */
        ic->ic_opmode = IEEE80211_M_STA;        /* default to BSS mode */
-       ic->ic_state = IEEE80211_S_INIT;
 
        /* set device capabilities */
        ic->ic_caps =
-           IEEE80211_C_MONITOR |       /* monitor mode supported */
+            IEEE80211_C_STA |
+            IEEE80211_C_MONITOR |      /* monitor mode supported */
 #ifndef IEEE80211_STA_ONLY
            IEEE80211_C_IBSS |          /* IBSS mode supported */
            IEEE80211_C_HOSTAP |        /* HostAP mode supported */
@@ -694,49 +741,16 @@
 #endif
            IEEE80211_C_WME |           /* WME */
            IEEE80211_C_WPA;            /* WPA/RSN */
-
-       if (sc->rf_rev == RT2860_RF_2750 ||
-           sc->rf_rev == RT2860_RF_2850 ||
-           sc->rf_rev == RT3070_RF_3052 ||
-           sc->rf_rev == RT3070_RF_3053 ||
-           sc->rf_rev == RT5592_RF_5592) {



Home | Main Index | Thread Index | Old Index