On Mon, Jul 15, 2019 at 07:25:45PM +0200, Manuel Bouyer wrote:
> Hello,
> I'm trying to use this wifi USB adapter:
> run0 at uhub7 port 1
> run0: Ralink (0x148f) 802.11 n WLAN (0x5370), rev 2.00/1.01, addr 3
> run0: MAC/BBP RT5390 (rev 0x0502), RF RT5592 (MIMO 1T1R), address 
> e8:4e:e8:4e:af:44
> run0: 11a rates: 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
> run0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> run0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 
> 36Mbps 48Mbps 54Mbps
> 
> (tested on 8.1 and HEAD).
> wpa_supplicant doesn't find any AP (it finds dozens with the internal
> wpi(4)) and wiconfig fails with:
> rochebonne# wiconfig run0 -D
> scanning .............wiconfig: ioctl: Operation now in progress
> 
> (the same command with wpi0 finds 12).
> 
> Is anyone using such an adapter with NetBSD ?

I have:

run0 at uhub4 port 2
run0: Ralink (0x148f) 802.11 n WLAN (0x5370), rev 2.00/1.01, addr 5
run0: MAC/BBP RT5390 (rev 0x0502), RF RT5592 (MIMO 1T1R), address 
3c:33:3c:33:70:96
run0: 11a rates: 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
run0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
run0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 
36Mbps 48Mbps 54Mbps

and it fails to scan as well.

OpenBSD works fine, and there are quite a few differences for this variant
in the driver.

There is at least one inverted condition (selecting the wrong antenna), but
that didn't fix it for me. I tried to bring in other changes but nothing
made it work (and I ran out of time). Latest change I used attached.

Martin
Index: if_run.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/if_run.c,v
retrieving revision 1.32
diff -u -p -r1.32 if_run.c
--- if_run.c    22 Jan 2019 06:47:20 -0000      1.32
+++ if_run.c    15 Jul 2019 17:29:15 -0000
@@ -18,7 +18,7 @@
  */
 
 /*-
- * Ralink Technology RT2700U/RT2800U/RT3000U chipset driver.
+ * Ralink Technology RT2700U/RT2800U/RT3000U/RT3900E chipset driver.
  * http://www.ralinktech.com/
  */
 
@@ -69,10 +69,12 @@ __KERNEL_RCSID(0, "$NetBSD: if_run.c,v 1
 #include <dev/ic/rt2860reg.h>          /* shared with ral(4) */
 #include <dev/usb/if_runvar.h>
 
+#define        RUN_DEBUG
+
 #ifdef RUN_DEBUG
 #define DPRINTF(x)     do { if (run_debug) printf x; } while (0)
 #define DPRINTFN(n, x) do { if (run_debug >= (n)) printf x; } while (0)
-int run_debug = 0;
+int run_debug = 255;
 #else
 #define DPRINTF(x)
 #define DPRINTFN(n, x)
@@ -850,6 +852,11 @@ run_alloc_tx_ring(struct run_softc *sc, 
 {
        struct run_tx_ring *txq = &sc->txq[qid];
        int i, error;
+       uint16_t txwisize;
+
+       txwisize = sizeof(struct rt2860_txwi);
+       if (sc->mac_ver == 0x5592)
+               txwisize += sizeof(uint32_t);
 
        txq->cur = txq->queued = 0;
 
@@ -870,8 +877,7 @@ run_alloc_tx_ring(struct run_softc *sc, 
 
                data->buf = usbd_get_buffer(data->xfer);
                /* zeroize the TXD + TXWI part */
-               memset(data->buf, 0, sizeof(struct rt2870_txd) +
-                   sizeof(struct rt2860_txwi));
+               memset(data->buf, 0, sizeof(struct rt2870_txd) + txwisize);
        }
        if (error != 0)
 fail:          run_free_tx_ring(sc, qid);
@@ -942,7 +948,9 @@ run_load_microcode(struct run_softc *sc)
                return error;
 
        usbd_delay_ms(sc->sc_udev, 10);
+       run_write(sc, RT2860_H2M_BBPAGENT, 0);
        run_write(sc, RT2860_H2M_MAILBOX, 0);
+       run_write(sc, RT2860_H2M_INTSRC, 0);
        if ((error = run_mcu_cmd(sc, RT2860_MCU_CMD_RFRESET, 0)) != 0)
                return error;
 
@@ -1468,7 +1476,7 @@ run_read_eeprom(struct run_softc *sc)
        if (sc->mac_ver >= 0x3070) {
                run_read(sc, RT3070_EFUSE_CTRL, &tmp);
                DPRINTF(("EFUSE_CTRL=0x%08x\n", tmp));
-               if (tmp & RT3070_SEL_EFUSE)
+               if (tmp & RT3070_SEL_EFUSE || sc->mac_ver == 0x3593)
                        sc->sc_srom_read = run_efuse_read_2;
        }
 
@@ -1526,7 +1534,10 @@ run_read_eeprom(struct run_softc *sc)
            sc->leds, sc->led[0], sc->led[1], sc->led[2]));
 
        /* read RF information */
-       run_srom_read(sc, RT2860_EEPROM_ANTENNA, &val);
+       if (sc->mac_ver == 0x5390 || sc->mac_ver == 0x5392)
+               run_srom_read(sc, 0x00, &val);
+       else
+               run_srom_read(sc, RT2860_EEPROM_ANTENNA, &val);
        if (val == 0xffff) {
                DPRINTF(("invalid EEPROM antenna info, using default\n"));
                if (sc->mac_ver == 0x3572) {
@@ -1546,13 +1557,19 @@ run_read_eeprom(struct run_softc *sc)
                        sc->nrxchains = 2;
                }
        } else {
-               sc->rf_rev = (val >> 8) & 0xf;
+               if (sc->mac_ver == 0x5390 || sc->mac_ver == 0x5392) {
+                       sc->rf_rev = val;
+                       run_srom_read(sc, RT2860_EEPROM_ANTENNA, &val);
+               } else {
+                       sc->rf_rev = (val >> 8) & 0xf;
+               }
                sc->ntxchains = (val >> 4) & 0xf;
                sc->nrxchains = val & 0xf;
        }
        DPRINTF(("EEPROM RF rev=0x%02x chains=%dT%dR\n",
            sc->rf_rev, sc->ntxchains, sc->nrxchains));
 
+       /* check if RF supports automatic Tx access gain control */
        run_srom_read(sc, RT2860_EEPROM_CONFIG, &val);
        DPRINTF(("EEPROM CFG 0x%04x\n", val));
        /* check if driver should patch the DAC issue */
@@ -2342,6 +2359,13 @@ run_rxeof(struct usbd_xfer *xfer, void *
        uint8_t *buf;
        uint32_t dmalen;
        int xferlen;
+       uint16_t rxwisize;
+
+       rxwisize = sizeof(struct rt2860_rxwi);
+       if (sc->mac_ver == 0x5592)
+                rxwisize += sizeof(uint64_t);
+        else if (sc->mac_ver == 0x3593)
+                rxwisize += sizeof(uint32_t);
 
        if (__predict_false(sc->sc_flags & RUN_DETACHING))
                return;
@@ -2356,8 +2380,8 @@ run_rxeof(struct usbd_xfer *xfer, void *
        }
        usbd_get_xfer_status(xfer, NULL, NULL, &xferlen, NULL);
 
-       if (__predict_false(xferlen < (int)(sizeof(uint32_t) +
-           sizeof(struct rt2860_rxwi) + sizeof(struct rt2870_rxd)))) {
+       if (__predict_false(xferlen < (int)(sizeof(uint32_t) + rxwisize +
+           sizeof(struct rt2870_rxd)))) {
                DPRINTF(("xfer too short %d\n", xferlen));
                goto skip;
        }
@@ -2481,6 +2505,7 @@ run_tx(struct run_softc *sc, struct mbuf
        txwisize = (sc->mac_ver == 0x5592) ?
            sizeof(*txwi) + sizeof(uint32_t) : sizeof(*txwi);
        xferlen = txwisize + m->m_pkthdr.len;
+
        /* roundup to 32-bit alignment */
        xferlen = (xferlen + 3) & ~3;
 
@@ -3581,7 +3606,7 @@ run_set_rx_antenna(struct run_softc *sc,
        if (sc->rf_rev == RT5390_RF_5370) {
                run_bbp_read(sc, 152, &bbp152);
                bbp152 &= ~0x80;
-               if (aux)
+               if (!aux)
                        bbp152 |= 0x80;
                run_bbp_write(sc, 152, bbp152);
        } else {
@@ -3915,7 +3940,8 @@ run_bbp_init(struct run_softc *sc)
        if (sc->mac_ver == 0x2860 && sc->mac_rev != 0x0101)
                run_bbp_write(sc, 84, 0x19);
 
-       if (sc->mac_ver >= 0x3070) {
+       if (sc->mac_ver >= 0x3070 && (sc->mac_ver != 0x3593 &&
+           sc->mac_ver != 0x5592)) {
                run_bbp_write(sc, 79, 0x13);
                run_bbp_write(sc, 80, 0x05);
                run_bbp_write(sc, 81, 0x33);

Reply via email to