2.5G USB->Ethernet, kmod-usb-net-rtl8152?

Hello,

Im quite new to this world of openwrt and linux in general.
The past week ive atleast learned how to make my own firmware with imagebuilder and some troubleshooting etc.
Im an IT guy since 20years but always ran windows and a basic homerouter, usually with asuswrt merlin or whatever.

But now i decided its time to enter the dark zone :smiley:

I got myself 2x 2.5Gbit USB->ethernet, both use realtek 8156 drivers from what ive gathered.
I took the chance to see if kmod-usb-net-rtl8152 might work, and im trying to make it work, i just got them today.

  • x86_64 custom firmware with kmod-usb-net-rtl8152 embedded
  • The hardware has 2x 2.0 USB and 2x 3.0 USB
  • Qotom Q570G6 mini-PC hardware

I made my firmware from an imagebuilder (19.07.3 stable x86_64) with the following included:

wireguard luci-app-wireguard vpn-policy-routing luci-app-vpn-policy-routing kmod-usb-net-rtl8152 hostapd ath10k-firmware-qca988x kmod-ath10k dnsmasq-full luci-app-openvpn openvpn-openssl openssl-util wget luci-app-sqm wget luci-ssl luci-app-statistics collectd-mod-wireless collectd-mod-thermal collectd-mod-sensors nano ca-certificates"

I got it all setup, until today when i got these USB>Ethernet devices.

  • On My windows PC connected to my router with the USB->Ethernet connected in both ends, windows says its 2.5Gbit
  • lsusb shows

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 0bda:8156 Realtek Semiconductor Corp.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

  • lsusb -t shows
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 5000M
    |__ Port 1: Dev 2, If 0, Class=Communications, Driver=, 5000M
    |__ Port 1: Dev 2, If 1, Class=CDC Data, Driver=, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M
  • lsmod show a bunch of things, but whats interesting i think(?) is

r8152 45056 0

  • cat /sys/kernel/debug/usb/devices lists
T:  Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=5000 MxCh= 0
D:  Ver= 3.20 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 9 #Cfgs=  3
P:  Vendor=0bda ProdID=8156 Rev=30.00
S:  Manufacturer=Realtek
S:  Product=USB 10/100/1G/2.5G LAN
S:  SerialNumber=000000001
C:  #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=512mA
I:  If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=00 Driver=
E:  Ad=81(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=83(I) Atr=03(Int.) MxPS=   2 Ivl=128ms
C:* #Ifs= 2 Cfg#= 2 Atr=a0 MxPwr=512mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=0d Prot=00 Driver=(none)
E:  Ad=83(I) Atr=03(Int.) MxPS=  16 Ivl=16ms
I:* If#= 1 Alt= 0 #EPs= 0 Cls=0a(data ) Sub=00 Prot=01 Driver=(none)
I:  If#= 1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=01 Driver=(none)
E:  Ad=81(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
C:  #Ifs= 2 Cfg#= 3 Atr=a0 MxPwr=512mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=06 Prot=00 Driver=
E:  Ad=83(I) Atr=03(Int.) MxPS=  16 Ivl=16ms
I:  If#= 1 Alt= 0 #EPs= 0 Cls=0a(data ) Sub=00 Prot=00 Driver=
I:  If#= 1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=
E:  Ad=81(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
  • It finds the devices as "Realtek 10/100/1G/2.5G LAN"
  • dmesg | grep usb shows
[    0.921204] usbcore: registered new interface driver usbfs
[    0.921216] usbcore: registered new interface driver hub
[    0.932458] usbcore: registered new device driver usb
[    2.130045] usbcore: registered new interface driver usb-storage
[    3.313509] usbcore: registered new interface driver usbhid
[    3.313510] usbhid: USB HID core driver
[    3.475833] usb 2-1: new SuperSpeed USB device number 2 using xhci_hcd
[    9.794723] usbcore: registered new interface driver r8152

Im not sure how to proceed? Any help would be most helpful, remember im a linux newbie, but can use google i guess.

EDIT: Sorry i guess i didnt really ask a question.
The problem is that the adapter doesnt show up in ifconfig -a for example, i cant choose it, openwrt doesnt find it

Thank you all

With what? What exactly is the issue?

Sorry i guess i didnt really ask a question.
The problem is that the adapter doesnt show up in ifconfig -a for example, i cant choose it, openwrt doesnt find it

This, currently active, configuration has a CDC NCM class function. You could try installing the kmod-usb-net-cdc-ncm package.

There are also 2 alternative configurations:

  • 1" has a vendor specific function. This needs a vendor specific driver. I don't believe the 8152 driver supports this device, and I don't know of any other option.
  • "3" has a CDC Ethernet function, which should work with the kmod-usb-net-cdc-ether package

You can switch configuraitons temporarily by writing to the bConfiguration sysfs attribute of the device. Something like

echo 3 >/sys/bus/usb/devices/x-y/bConfigurationValue

with proper values for x-y.

1 Like

Check that you have kmod-usb-net installed.

Ok, so something definately happened anyway, if its in the right direction i dont know, but id like to think so.
After installing kmod-usb-net-cdc-ncm package, i got a new message when plugging in the adapter:

kmodloader: done loading kernel modules from /etc/modules.d/*
cdc_ncm 2-1:2.0: MAC-Address: xxxxxxxxxxx
cdc_ncm 2-1:2.0: setting rx_max = 16384
cdc_ncm 2-1:2.0: setting tx_max = 16384
cdc_ncm 2-1:2.0 usb0: register 'cdc_ncm' at usb-0000:00:14.0-1, CDC NCM. <MAC-ADRESS>
cdc_ncm 2-1:2.0 usb0: 2500 mbit/s downlink 2500 mbit/s uplink
device usb0 entered promiscuous mode
usbcore: registered new interface driver cdc_ncm
cdc_ncm 2-1:2.0: network connection: connected
kmodloader: done loading kernel modules from /etc/modules.d/*

Then it spammed indefinately until i unplugged it:
cmc_ncm 2-1:2.0 usb0: network connection: connected
cmc_ncm 2-1:2.0 usb0:2500 mbit/s downlink 2500 mbit/s uplink
cmc_ncm 2-1:2.0 usb0: network connection: connected
cmc_ncm 2-1:2.0 usb0:2500 mbit/s downlink 2500 mbit/s uplink

Im not sure how to find x_y, im not savvy enough on this

edit: i wrote before checking the /sys/bus/usb/devices folder..
i get permission denied though so i guess i must somehow get permission

Ye it is installed

Well, that looks good, doesn't it?

I can't explain why you see these messages over and over again. The driver will print them when it receives a USB_CDC_NOTIFY_SPEED_CHANGE or USB_CDC_NOTIFY_NETWORK_CONNECTION notification from the device. If they are repeated then the device are sending them repeatedly. Maybe it is waiting for the link to go up? Did you try to configure the interface? Or maybe the link is actually flapping? Do you have any management of the other end?

It looks better for sure, but yeah it still doesnt work, it spams it 50times a second, and if i disconnect it spams disconnected 50times a second.

I think the link is flapping yeah. But we are on to something!
I am curious what would happend if i didnt get permission denied on temporarily changing the bConfiguration, my gut says mode "1" might work. When i download the linux drivers from realtek website they are called 8152.. But im not sure how to get permission to change that.
I tried some chmod commands but im new to this, probably did it wrong

EDIT: So it seems like the spam begins when i assign it to an interface in openwrt, before that its not spamming, hmmmmmmmmmmmmmm

EDIT 2: I receive DHCP on it lol, but i cant go anywhere

lsmod -v

Bus 002 Device 003: ID 0bda:8156 Realtek Semiconductor Corp.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               3.20
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         9
  idVendor           0x0bda Realtek Semiconductor Corp.
  idProduct          0x8156
  bcdDevice           30.00
  iManufacturer           1 Realtek
  iProduct                2 USB 10/100/1G/2.5G LAN
  iSerial                 6 000000001
  bNumConfigurations      3
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           57
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              128mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0002  1x 2 bytes
        bInterval              11
        bMaxBurst               0
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          104
    bNumInterfaces          2
    bConfigurationValue     2
    iConfiguration          0
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              128mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass     13
      bInterfaceProtocol      0
      iInterface              5 CDC Communications Control
      CDC Header:
        bcdCDC               1.10
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1
      CDC Ethernet:
        iMacAddress                      3 00E04CAB6A9C
        bmEthernetStatistics    0x0031500f
        wMaxSegmentSize               1518
        wNumberMCFilters            0x8000
        bNumberPowerFilters              0
      CDC NCM:
        bcdNcmVersion        1.00
        bmNetworkCapabilities 0x2b
          8-byte ntb input size
          max datagram size
          net address
          packet filter
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval               8
        bMaxBurst               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      1
      iInterface              0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      1
      iInterface              4 Ethernet Data
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           98
    bNumInterfaces          2
    bConfigurationValue     3
    iConfiguration          0
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              128mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      6 Ethernet Networking
      bInterfaceProtocol      0
      iInterface              5 CDC Communications Control
      CDC Header:
        bcdCDC               1.10
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1
      CDC Ethernet:
        iMacAddress                      3 00E04CAB6A9C
        bmEthernetStatistics    0x0031500f
        wMaxSegmentSize               1518
        wNumberMCFilters            0x8000
        bNumberPowerFilters              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval               8
        bMaxBurst               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0
      iInterface              0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0
      iInterface              4 Ethernet Data
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3
Binary Object Store Descriptor:
  bLength                 5
  bDescriptorType        15
  wTotalLength           22
  bNumDeviceCaps          2
  USB 2.0 Extension Device Capability:
    bLength                 7
    bDescriptorType        16
    bDevCapabilityType      2
    bmAttributes   0x00000002
      Link Power Management (LPM) Supported
  SuperSpeed USB Device Capability:
    bLength                10
    bDescriptorType        16
    bDevCapabilityType      3
    bmAttributes         0x02
      Latency Tolerance Messages (LTM) Supported
    wSpeedsSupported   0x000e
      Device can operate at Full Speed (12Mbps)
      Device can operate at High Speed (480Mbps)
      Device can operate at SuperSpeed (5Gbps)
    bFunctionalitySupport   2
      Lowest fully-functional device speed is High Speed (480Mbps)
    bU1DevExitLat          10 micro seconds
    bU2DevExitLat        2047 micro seconds
Device Status:     0x001c
  (Bus Powered)
  U1 Enabled
  U2 Enabled
  Latency Tolerance Messaging (LTM) Enabled

So it says its bConfigurationValue "1"

And "2" and "3" further down. These are three alternatives presented by the device. Only one can be active. lsusb isn't great at showing you which one this is. It has some additional descriptors, showing you stuff like properly configured mac address etc, but it lacks info on active configurations and altsettings. The cat /sys/kernel/debug/usb/devices you posted earlier is better when it comes to this. It indicates the active settings by an asterisk.

You can also look up the active configuration for all your usb devices by doing e.g

grep . /sys/bus/usb/devices/*/bConfigurationValue

Most will only have one, so the value will be "1". You can therefore most likely identify your ethernet device by the one having "2". Writing 3 to to it will change the configuration to the one with CDC Ethernet. You need to be root to do this, but I assume you are since this is OpenWrt.

EDIT: but if you are having link issues, then this obviously won't make any difference. Just hide them by not being so verbose about the notifications.

Ok i see..
So what can i do about permission denied when trying to change the bConfigurationValue?
I got a reply on this thats interesting also: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1832472

Anyone can give me their 2cents? More and more ppl getting these 2.5G usb nics

Please post the command you are running with resulting error, and the output of
grep . /sys/bus/usb/devices/*/bConfigurationValue

But this is most likely completely unrelated to the main issue, so I'm not sure it's worth spending a lot of time on until we understand if there are real link problems or not.

Try debugging the link. look at the link partner. Switch to another port and/or device in the other end.

Install ethtool and run it to see the negotiated values. Maybe try locking to different speeds.

Verify that the USB device works on a Windows host (if you have one) when connected to the same link partner with the same cable.

Thx for staying with me :stuck_out_tongue: i will look at this when i have time, tomorrow i think, its late now.
Thx again

Do you think usb-modeswitch is relevant in this case?
Or maybe kmod-usb-net-rndis ?

Not really. It is capable of swithcing USB configurations, but will not be able to do anything you can't do using sysfs. And you'd have to configure it for this device yourself.

No, there isn't any such function here. Only vendor specifc, NCM and ECM

The only driver that would make a difference is a vendor specific one with support for this device. I assume that's the preferred device mode, based on it being cfg #1 and how RTL8152/RTL8153 devices behave.

Yeah i assume so, ive been looking at how to go about creating a firmware with make, make menuconfig etc.
Im still new but i got it working.
The thing i dont know is, how do i add a custom driver, such as these realtek drivers that are on their website.
Modify kernel config i think i have to learn.

https://www.realtek.com/en/component/zoo/category/network-interface-controllers-10-100-1000m-gigabit-ethernet-usb-3-0-software

Looking in the kernel on v19.07.3 , rtl8152 is outdated and the driver for rtl8156 is not included.
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/net/usb/r8152.c?h=linux-4.14.y&id=v4.14.180
I gave it a try to update the driver, by coping the vendor driver r8152.c compatibility.h to the kernel in /drivers/net/usb/ , from there I got the diff patch
https://github.com/mj22226/openwrt/commit/3f05cd7b54a7b8c8b2b13601e5e71468f8fd56d6.patch
After applying the patch and compiled I got the updated kmod-usb-net-rtl8152 for x86_64 v19.07.3
https://github.com/mj22226/openwrt/blob/v19-07-3/64/packages/kmod-usb-net-rtl8152_4.14.180-1_x86_64.ipk
I don't have a rtl8156 adapters to test , but works with the regular rtl8152.

1 Like