USB Driver loading Issue

I am having problems with my wifi usb adapters during startup. From what I can see in the dmesg output, the wifi adapter loads before the drivers load, causing the adapter to be stuck in a state with no associated driver.

dmesg | grep usb
[    0.054179] usbcore: registered new interface driver usbfs
[    0.054199] usbcore: registered new interface driver hub
[    0.054222] usbcore: registered new device driver usb
[    0.548216] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 6.06
[    0.548227] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.548235] usb usb1: Product: xHCI Host Controller
[    0.548241] usb usb1: Manufacturer: Linux 6.6.110 xhci-hcd
[    0.548247] usb usb1: SerialNumber: 0000:01:00.0
[    0.548788] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 6.06
[    0.548799] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.548807] usb usb2: Product: xHCI Host Controller
[    0.548813] usb usb2: Manufacturer: Linux 6.6.110 xhci-hcd
[    0.548819] usb usb2: SerialNumber: 0000:01:00.0
[    0.549705] usbcore: registered new interface driver uas
[    0.549743] usbcore: registered new interface driver usb-storage
[    2.055095] usb 1-1: new high-speed USB device number 2 using xhci_hcd
[    2.237755] usb 1-1: New USB device found, idVendor=2109, idProduct=3431, bcdDevice= 4.21
[    2.245960] usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[    2.253092] usb 1-1: Product: USB2.0 Hub
[    2.585097] usb 1-1.1: new high-speed USB device number 3 using xhci_hcd
[    2.736071] usb 1-1.1: New USB device found, idVendor=0e8d, idProduct=2870, bcdDevice= 0.01
[    2.744436] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    2.751749] usb 1-1.1: Product: Љ
[    2.755149] usb 1-1.1: Manufacturer: Љ
[    2.758977] usb 1-1.1: SerialNumber: Љ
[    2.764618] usb-storage 1-1.1:1.0: USB Mass Storage device detected
[    2.771128] scsi host0: usb-storage 1-1.1:1.0
[    7.904818] usbcore: registered new interface driver mt76x2u
[    8.003062] usbcore: registered new interface driver lan78xx
[    8.012399] usbcore: registered new interface driver usbhid
[    8.018001] usbhid: USB HID core driver
[    8.050237] usbcore: registered new interface driver brcmfmac

... unplug 

[  111.282220] usb 1-1.1: USB disconnect, device number 3

... plugin

[  163.253665] usb 1-1.1: new high-speed USB device number 4 using xhci_hcd
[  163.384648] usb 1-1.1: New USB device found, idVendor=0e8d, idProduct=2870, bcdDevice= 0.01
[  163.393026] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  163.400384] usb 1-1.1: Product: Љ
[  163.403819] usb 1-1.1: Manufacturer: Љ
[  163.407672] usb 1-1.1: SerialNumber: Љ
[  163.413664] usb-storage 1-1.1:1.0: USB Mass Storage device detected
[  163.420436] scsi host0: usb-storage 1-1.1:1.0
[  163.668159] usb 1-1.1: USB disconnect, device number 4
[  164.433961] usb 2-1: new SuperSpeed USB device number 2 using xhci_hcd
[  164.465629] usb 2-1: New USB device found, idVendor=0e8d, idProduct=7612, bcdDevice= 1.00
[  164.473837] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  164.480975] usb 2-1: Product: 802.11ac WLAN
[  164.485169] usb 2-1: Manufacturer: MediaTek Inc.
[  164.489784] usb 2-1: SerialNumber: 000000000
[  164.654480] usb 2-1: reset SuperSpeed USB device number 2 using xhci_hcd

Im using a Raspberry Pi with a MediaTek Wifi Adapter MT7612U.

Ive tested the MT adapter on my laptop and it worked without issues. Once Loaded, the radio shows up in LUCI and I'm able to scan and connected to WiFi.

Ive tried following the steps in 3g/4g USB dongle not showing up - #10 by bmork. The idea was to try and get the adapter to reload once the drivers are available.

{
        "messages" : [ ],
        "devices" : {
                "0e8d:2870": {
                        "*": {
                                "t_vendor": 3727,
                                "t_product": [ 30226 ],
                                "mode": "StandardEject",
                                "msg": [ ],
                        }
                }
        }

}

The usb adapter shows up when using -l

root@OpenWrt:~# usbmode -l
Found device: 0e8d:2870 (Manufacturer: "?", Product: "?", Serial: "?")

but running -s doesnt bring the adapter out of its uninitialized state.

logs

dmesg | grep usb
[    0.054179] usbcore: registered new interface driver usbfs
[    0.054199] usbcore: registered new interface driver hub
[    0.054222] usbcore: registered new device driver usb
[    0.548216] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 6.06
[    0.548227] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.548235] usb usb1: Product: xHCI Host Controller
[    0.548241] usb usb1: Manufacturer: Linux 6.6.110 xhci-hcd
[    0.548247] usb usb1: SerialNumber: 0000:01:00.0
[    0.548788] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 6.06
[    0.548799] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.548807] usb usb2: Product: xHCI Host Controller
[    0.548813] usb usb2: Manufacturer: Linux 6.6.110 xhci-hcd
[    0.548819] usb usb2: SerialNumber: 0000:01:00.0
[    0.549705] usbcore: registered new interface driver uas
[    0.549743] usbcore: registered new interface driver usb-storage
[    2.055095] usb 1-1: new high-speed USB device number 2 using xhci_hcd
[    2.237755] usb 1-1: New USB device found, idVendor=2109, idProduct=3431, bcdDevice= 4.21
[    2.245960] usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[    2.253092] usb 1-1: Product: USB2.0 Hub
[    2.585097] usb 1-1.1: new high-speed USB device number 3 using xhci_hcd
[    2.736071] usb 1-1.1: New USB device found, idVendor=0e8d, idProduct=2870, bcdDevice= 0.01
[    2.744436] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    2.751749] usb 1-1.1: Product: Љ
[    2.755149] usb 1-1.1: Manufacturer: Љ
[    2.758977] usb 1-1.1: SerialNumber: Љ
[    2.764618] usb-storage 1-1.1:1.0: USB Mass Storage device detected
[    2.771128] scsi host0: usb-storage 1-1.1:1.0
[    7.904818] usbcore: registered new interface driver mt76x2u
[    8.003062] usbcore: registered new interface driver lan78xx
[    8.012399] usbcore: registered new interface driver usbhid
[    8.018001] usbhid: USB HID core driver
[    8.050237] usbcore: registered new interface driver brcmfmac

... unplug 

[  111.282220] usb 1-1.1: USB disconnect, device number 3

... plugin

[  163.253665] usb 1-1.1: new high-speed USB device number 4 using xhci_hcd
[  163.384648] usb 1-1.1: New USB device found, idVendor=0e8d, idProduct=2870, bcdDevice= 0.01
[  163.393026] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  163.400384] usb 1-1.1: Product: Љ
[  163.403819] usb 1-1.1: Manufacturer: Љ
[  163.407672] usb 1-1.1: SerialNumber: Љ
[  163.413664] usb-storage 1-1.1:1.0: USB Mass Storage device detected
[  163.420436] scsi host0: usb-storage 1-1.1:1.0
[  163.668159] usb 1-1.1: USB disconnect, device number 4
[  164.433961] usb 2-1: new SuperSpeed USB device number 2 using xhci_hcd
[  164.465629] usb 2-1: New USB device found, idVendor=0e8d, idProduct=7612, bcdDevice= 1.00
[  164.473837] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  164.480975] usb 2-1: Product: 802.11ac WLAN
[  164.485169] usb 2-1: Manufacturer: MediaTek Inc.
[  164.489784] usb 2-1: SerialNumber: 000000000
[  164.654480] usb 2-1: reset SuperSpeed USB device number 2 using xhci_hcd

Uninitialized state:

cat /sys/kernel/debug/usb/devices
T:  Bus=01 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#=  3 Spd=480  MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=0e8d ProdID=2870 Rev= 0.01
S:  Manufacturer=Љ
S:  Product=Љ
S:  SerialNumber=Љ
C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=160mA
I:* If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=(none)
E:  Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux 6.6.110 xhci-hcd xHCI Host Controller
Bus 001 Device 002: ID 2109:3431  USB2.0 Hub
Bus 001 Device 003: ID 0e8d:2870 Љ Љ
Bus 002 Device 001: ID 1d6b:0003 Linux 6.6.110 xhci-hcd xHCI Host Controller

Initialized state:

cat /sys/kernel/debug/usb/devices
T:  Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=5000 MxCh= 0
D:  Ver= 3.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 9 #Cfgs=  1
P:  Vendor=0e8d ProdID=7612 Rev= 1.00
S:  Manufacturer=MediaTek Inc.
S:  Product=802.11ac WLAN
S:  SerialNumber=000000000
C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=800mA
I:* If#= 0 Alt= 0 #EPs= 8 Cls=ff(vend.) Sub=ff Prot=ff Driver=mt76x2u
E:  Ad=84(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=85(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=08(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=04(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=05(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=06(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=07(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=09(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux 6.6.110 xhci-hcd xHCI Host Controller
Bus 001 Device 002: ID 2109:3431  USB2.0 Hub
Bus 002 Device 001: ID 1d6b:0003 Linux 6.6.110 xhci-hcd xHCI Host Controller
Bus 002 Device 002: ID 0e8d:7612 MediaTek Inc. 802.11ac WLAN

Don't know if this is the reason it doesn't work, but is that a typo?

bjorn@miraculix:~$ printf "%04x\n" 3727
0e8f

Looking closer, this is more likely the problem:

                "0e8d:2870": {
                        "*": {

Your config isn't valid json. Tip: Pipe it to jq . or similar to validate

Thanks for the reply!

Don't know if this is the reason it doesn't work, but is that a typo?

Good catch. That was a typo.

Your config isn't valid json

I've validated the json using jq.

It doesn't appear to have changed anything.

root@OpenWrt:~# usbmode -v -l -c fix.json
Found device: 0e8d:2870 (Manufacturer: "?", Product: "?", Serial: "?")
root@OpenWrt:~# usbmode -v -s -c fix.json
root@OpenWrt:~# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux 6.6.110 xhci-hcd xHCI Host Controller
Bus 001 Device 002: ID 2109:3431  USB2.0 Hub
Bus 001 Device 003: ID 0e8d:2870 Љ Љ
Bus 002 Device 001: ID 1d6b:0003 Linux 6.6.110 xhci-hcd xHCI Host Controller
root@OpenWrt:~#

checking dmesg, I cant see any new logs. There might be another issue with my config which is causing it to silently fail.

root@OpenWrt:~# cat fix.json
{
  "messages": [],
  "devices": {
    "0e8d:2870": {
      "*": {
        "t_vendor": 3725,
        "t_product": [
          30226
        ],
        "mode": "StandardEject",
        "msg": []
      }
    }
  }
}

Is there some other logs i should be checking to see if its working?

Yes, I see you're correct. I was confused by the weird structure and indentation, but I see that it matches the examples on https://openwrt.org/docs/guide-user/network/wan/wwan/usb-modeswitching so I assume it's correct.

Still don't understand what that config is trying to express. But that's not your problem. Obviously been too long time since I looked at usbmode :slight_smile:

It might be that usbmode is the wrong idea to fix this problem. I don't really understand usbmode either :slight_smile:

I could maybe change the driver loading order to try and get the MT drivers to load before the usb device connects, but I've not messed around with /etc/modules.d before and wouldn't know what I'm doing. Maybe I don't understand the actual reason why the wifi adapter is getting stuck in the uninitialized state. All very confusing.

Have you verified that "StandardEject" works with this device? Is that what the usb-modeswitch application does on your laptop, or is the laptop running som odd non-Linux OS? If not from usb-modeswitch , then where does this config come from?

I see that you have the usb-storage driver and it binds to the device as it should. Does it register a disk device you can try to "eject"? If so, then install the eject package and run it on the disk/cdrom device. This is to verify that "StandardEject" is correct. If the eject tool doesn't work, then "StandardEject" won't either.

Trying to align these parts of the unitialized state:

So we see that usb-storage binds to that device and interface, but there still is no driver bound. Only explanation I can come up with is that usbmode is running as it should, unbinding the driver and sending its eject message. If so, then the message must be ignored by the device.

But why would it work when you unplug/replug the device? Can't explain

I would remove modeswitch and try usbreset.
If that works then simple hotplug script should be able to do the job.