Bug 253374 - [if_ure] Add support for RTL8153B, RTL8156 and RTL8156B
Summary: [if_ure] Add support for RTL8153B, RTL8156 and RTL8156B
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: usb (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Only Me
Assignee: Hans Petter Selasky
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-09 14:49 UTC by fbbz
Modified: 2021-07-10 19:19 UTC (History)
8 users (show)

See Also:


Attachments
if_ure.c and if_urereg.h patch (53.19 KB, patch)
2021-02-09 14:49 UTC, fbbz
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description fbbz 2021-02-09 14:49:28 UTC
Created attachment 222292 [details]
if_ure.c and if_urereg.h patch

Could you add support for Realtek RTL8153B, RTL8156 and RTL8156B ?

I tried doing it by studying openbsd and linux drivers, but since i'm not a developer, i certainly made some rookie mistakes.
Comment 1 Hans Petter Selasky freebsd_committer 2021-02-09 14:55:42 UTC
jmg@ is currently working on this driver. Please synchronize with him.

--HPS
Comment 2 TOXIC 2021-02-27 13:21:46 UTC
Just wanted to express interest into this. 
I'm way over my head looking at the proposed patch and realy not competent to compile it, but I'm fairly familiar with linux comand line, will get around to learning the freebsd specialties which I find much simpler, so I'm available to test it out on my current opnSense installs running 12.1-RELEASE-p13-HBSD (hardened) with my USB RTL8156B and my ISP's box providing 2.5G ethernet.
Comment 3 Masachika ISHIZUKA 2021-03-01 08:11:00 UTC
RTL8156 will be supported by the cdce driver on 13.0-RELEASE.
You can try on 13.0-BETAs/RCs.
Comment 4 Niels Bakker 2021-04-14 13:19:27 UTC
(In reply to Masachika ISHIZUKA from comment #3)

I haven't compared performance of this patch with what if_cdce delivers, but 13.0-RELEASE's performance is not what I expected.

I have a USB dongle with RTL8156B chipset that easily gets 1.9 Gbps or 2.3 Gbps with iPerf3 when attached to a recent Apple laptop. FreeBSD added a USB quirk for the device to select profile 2. The device then gets 92 Mbps throughput.

If I switch it back to profile 1 using usbconfig -d ugen0.12 set_config 1, it gets roughly 800 Mbps. The switch says the port negotiated to 2.5 Gbps in either case.

Is there a way to achieve closer to linerate performance?
Comment 5 Hans Petter Selasky freebsd_committer 2021-04-14 13:23:59 UTC
Hi,

I think jmg@ is working on something. Last update from him was that the Realtek devices disconnect from USB if stressed too much, and this is a severe problem.

--HPS
Comment 6 sec 2021-04-21 08:52:50 UTC
(In reply to Masachika ISHIZUKA from comment #3)
Hi. Any news about RTL8153B support? About one week ago I tried 13-CURRENT on NanoPi R2S and it wasn't detected :(
Comment 7 Ganbold Tsagaankhuu freebsd_committer 2021-06-03 05:40:44 UTC
(In reply to Hans Petter Selasky from comment #5)
jmg@ said he is not working actively on it.

Hans, can you work on it when you get a chance?

thanks,
Comment 8 Hans Petter Selasky freebsd_committer 2021-06-03 12:19:40 UTC
Yes, I'll have a look at this.
Comment 9 Hans Petter Selasky freebsd_committer 2021-06-04 08:32:31 UTC
If you could upload an update for the if_ure.4 manual page, that would be great!

Submitted to -current with some minor changes. See following commit message.

--HPS
Comment 10 commit-hook freebsd_committer 2021-06-04 08:33:27 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=d4cf41a99b405c73288aea81e3c4580d1de18435

commit d4cf41a99b405c73288aea81e3c4580d1de18435
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2021-06-04 08:28:58 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2021-06-04 08:29:55 +0000

    Add support for RTL8153B, RTL8156 and RTL8156B to if_ure(4).

    Submitted by:   fbbz@synack.eu
    PR:             253374
    MFC after:      1 week
    Sponsored by:   Mellanox Technologies // NVIDIA Networking

 sys/dev/usb/net/if_ure.c    | 965 ++++++++++++++++++++++++++++++++------------
 sys/dev/usb/net/if_urereg.h | 200 ++++++++-
 2 files changed, 890 insertions(+), 275 deletions(-)
Comment 11 Ganbold Tsagaankhuu freebsd_committer 2021-06-04 11:39:01 UTC
It seems NanoPI R2S still has issue with it:

ugen0.2: <Realtek USB 10/100/1000 LAN> at usbus0
ure0 on uhub3
ure0: <Realtek USB 10/100/1000 LAN, class 0/0, rev 3.00/31.00, addr 1> on usbus0

ure0: timeout waiting for chip autoload
ure0: timeout waiting for phy to stabilize
ure0: MAC assigned randomly
ure0: attaching PHYs failed
ure0: unknown version 0x0000

usbconfig:
ugen0.2: <Realtek USB 10/100/1000 LAN> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=ON (72mA)
Comment 12 Ganbold Tsagaankhuu freebsd_committer 2021-06-04 11:59:21 UTC
More debug messages:

ure0: timeout waiting for phy to stabilize
ure0: timeout waiting for OOB control
ure0: timeout waiting for OOB control
ure0: MAC assigned randomly
ure0: attaching PHYs failed
Comment 13 Hans Petter Selasky freebsd_committer 2021-06-04 12:33:04 UTC
Is this a regression issue, or a new one.

What does:

usbconfig -d X.Y dump_device_desc

say?

--HPS
Comment 14 Ganbold Tsagaankhuu freebsd_committer 2021-06-04 12:56:20 UTC
It may not be a regression, but something could be missing for 8153b.

ugen0.2: <Realtek USB 10/100/1000 LAN> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=ON (72mA)

  bLength = 0x0012
  bDescriptorType = 0x0001
  bcdUSB = 0x0300
  bDeviceClass = 0x0000  <Probed by interface class>
  bDeviceSubClass = 0x0000
  bDeviceProtocol = 0x0000
  bMaxPacketSize0 = 0x0009
  idVendor = 0x0bda
  idProduct = 0x8153
  bcdDevice = 0x3100
  iManufacturer = 0x0001  <retrieving string failed>
  iProduct = 0x0002  <retrieving string failed>
  iSerialNumber = 0x0006  <retrieving string failed>
  bNumConfigurations = 0x0002
Comment 15 Hans Petter Selasky freebsd_committer 2021-06-04 13:05:46 UTC
Can you also dump the configuration descriptor, I see there are two configurations there.

usbconfig -d X.Y dump_all_config_desc

--HPS
Comment 16 Ganbold Tsagaankhuu freebsd_committer 2021-06-04 13:08:20 UTC
ugen0.2: <Realtek USB 10/100/1000 LAN> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=ON (72mA)


 Configuration index 0

    bLength = 0x0009
    bDescriptorType = 0x0002
    wTotalLength = 0x0039
    bNumInterfaces = 0x0001
    bConfigurationValue = 0x0001
    iConfiguration = 0x0000  <no string>
    bmAttributes = 0x00a0
    bMaxPower = 0x0024

    Interface 0
      bLength = 0x0009
      bDescriptorType = 0x0004
      bInterfaceNumber = 0x0000
      bAlternateSetting = 0x0000
      bNumEndpoints = 0x0003
      bInterfaceClass = 0x00ff  <Vendor specific>
      bInterfaceSubClass = 0x00ff
      bInterfaceProtocol = 0x0000
      iInterface = 0x0000  <no string>

     Endpoint 0
        bLength = 0x0007
        bDescriptorType = 0x0005
        bEndpointAddress = 0x0081  <IN>
        bmAttributes = 0x0002  <BULK>
        wMaxPacketSize = 0x0400
        bInterval = 0x0000
        bRefresh = 0x0000
        bSynchAddress = 0x0000

      Additional Descriptor

      bLength = 0x06
      bDescriptorType = 0x30
      bDescriptorSubType = 0x03
       RAW dump:
       0x00 | 0x06, 0x30, 0x03, 0x00, 0x00, 0x00


     Endpoint 1
        bLength = 0x0007
        bDescriptorType = 0x0005
        bEndpointAddress = 0x0002  <OUT>
        bmAttributes = 0x0002  <BULK>
        wMaxPacketSize = 0x0400
        bInterval = 0x0000
        bRefresh = 0x0000
        bSynchAddress = 0x0000

      Additional Descriptor

      bLength = 0x06
      bDescriptorType = 0x30
      bDescriptorSubType = 0x03
       RAW dump:
       0x00 | 0x06, 0x30, 0x03, 0x00, 0x00, 0x00


     Endpoint 2
        bLength = 0x0007
        bDescriptorType = 0x0005
        bEndpointAddress = 0x0083  <IN>
        bmAttributes = 0x0003  <INTERRUPT>
        wMaxPacketSize = 0x0002
        bInterval = 0x0008
        bRefresh = 0x0000
        bSynchAddress = 0x0000

      Additional Descriptor

      bLength = 0x06
      bDescriptorType = 0x30
      bDescriptorSubType = 0x00
       RAW dump:
       0x00 | 0x06, 0x30, 0x00, 0x00, 0x02, 0x00
Comment 17 commit-hook freebsd_committer 2021-06-04 13:53:35 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=dab84426a68d43efaede62ccf86ca3ef852f8ae3

commit dab84426a68d43efaede62ccf86ca3ef852f8ae3
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2021-06-04 13:48:15 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2021-06-04 13:51:01 +0000

    Narrow down the probe range for if_ure(4) compatible devices
    to only match the first vendor specific interface, if any.

    PR:             253374
    MFC after:      1 week
    Sponsored by:   Mellanox Technologies // NVIDIA Networking

 sys/dev/usb/net/if_ure.c | 7 ++++---
 sys/dev/usb/usb.h        | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)
Comment 18 Ganbold Tsagaankhuu freebsd_committer 2021-06-04 13:59:59 UTC
root@generic:~ # usbconfig
ugen2.1: <DWCOTG OTG Root HUB> at usbus2, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen0.1: <Synopsys XHCI root HUB> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA)
ugen4.1: <Generic OHCI root HUB> at usbus4, cfg=0 md=HOST spd=FULL (12Mbps) pwr=SAVE (0mA)
ugen3.1: <Generic EHCI root HUB> at usbus3, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen0.2: <Realtek USB 10/100/1000 LAN> at usbus0, cfg=255 md=HOST spd=SUPER (5.0Gbps) pwr=ON (72mA)

and usbconfig -d 0.2 reset makes it attach and work:

root@generic:~ # usbconfig -d 0.2 reset
ure0: at uhub3, port 2, addr 1 (disconnected)
ure0: timeout waiting for phy to stabilize
ure0: timeout waiting for phy to stabilize
ure0: MAC assigned randomly
ure0: attaching PHYs failed
ure0: detached
ure0 on uhub3
ure0: <Realtek USB 10/100/1000 LAN, class 0/0, rev 3.00/31.00, addr 1> on usbus0
root@generic:~ # ure0: MAC assigned randomly
miibus1: <MII bus> on ure0
rgephy2: <RTL8251/8153 1000BASE-T media interface> PHY 0 on miibus1
rgephy2:  none, 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT-FDX, 1000baseT-FDX-master, auto

root@generic:~ #
Comment 19 sec 2021-06-11 14:58:07 UTC
(In reply to Ganbold Tsagaankhuu from comment #18)
Do I need something special for USB support to work? I tried 14-CURRENT with u-boot 2021.04 and only have those visible:
root@generic:~ # usbconfig
ugen2.1: <Generic EHCI root HUB> at usbus2, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen1.1: <DWCOTG OTG Root HUB> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen3.1: <Generic OHCI root HUB> at usbus3, cfg=0 md=HOST spd=FULL (12Mbps) pwr=SAVE (0mA)
root@generic:~ # uname -a
FreeBSD generic 14.0-CURRENT FreeBSD 14.0-CURRENT #0 main-n247271-597cc550e7b: Thu Jun 10 07:44:44 UTC 2021     root@releng1.nyi.freebsd.org:/usr/obj/usr/src/arm64.aarch64/sys/GENERIC  arm64
Comment 20 Hans Petter Selasky freebsd_committer 2021-06-11 15:10:20 UTC
(In reply to sec from comment #19)

You need to plug a USB device. Sometimes a FDT GPIO configuration update is required to make sure your USB port is really connected and has +5V.

--HPS
Comment 21 sec 2021-06-11 15:31:32 UTC
(In reply to Hans Petter Selasky from comment #20)

Hm, so I plugged USB mouse into the other port - it's visible, but still no ure interface :)
Comment 22 sec 2021-06-14 13:35:37 UTC
A little update (thanks Ganbold for help). What I was missing was this line:

fdt_overlays="rk3328-dwc3"

in /boot/loader.conf

Then after boot, errors were the same, so:
usbconfig -d 0.2 reset

did the trick. Setting cpu.freq to 1200 is getting:
dwc0 around 350mbit/s
ue0 around 300mbit/s

which is not bad, but under openwrt it was getting 800-900mbit/s
Comment 23 commit-hook freebsd_committer 2021-07-10 19:19:05 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=47c5e288eee94c67369443d0ed7c2ab21235c924

commit 47c5e288eee94c67369443d0ed7c2ab21235c924
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2021-06-04 13:48:15 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2021-07-10 19:17:29 +0000

    Narrow down the probe range for if_ure(4) compatible devices
    to only match the first vendor specific interface, if any.

    PR:             253374
    Sponsored by:   Mellanox Technologies // NVIDIA Networking

    (cherry picked from commit dab84426a68d43efaede62ccf86ca3ef852f8ae3)

 sys/dev/usb/net/if_ure.c | 7 ++++---
 sys/dev/usb/usb.h        | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)
Comment 24 commit-hook freebsd_committer 2021-07-10 19:19:08 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=77f7133bd55c3f6a73b6428ceaa8c266940a55f3

commit 77f7133bd55c3f6a73b6428ceaa8c266940a55f3
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2021-06-04 08:28:58 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2021-07-10 19:17:26 +0000

    Add support for RTL8153B, RTL8156 and RTL8156B to if_ure(4).

    Submitted by:   fbbz@synack.eu
    PR:             253374
    Sponsored by:   Mellanox Technologies // NVIDIA Networking

    (cherry picked from commit d4cf41a99b405c73288aea81e3c4580d1de18435)

 sys/dev/usb/net/if_ure.c    | 965 ++++++++++++++++++++++++++++++++------------
 sys/dev/usb/net/if_urereg.h | 200 ++++++++-
 2 files changed, 890 insertions(+), 275 deletions(-)