Skip to contentSkip to conversation

net: usb: r8152: Add in new Devices that are supported for Mac-Passthru

PATCH Superseded David Ober 2 participants 2 messages May 13, 2022 – May 14, 2022

Subsystems (4)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

David Ober

author
#0 lore raw

PATCH v4 1/1 net: usb: r8152: Add in new Devices that are supported for Mac-Passthru

Lenovo Thunderbolt 4 Dock, and other Lenovo USB Docks are using the original Realtek USB ethernet Vendor and Product IDs
If the Network device is Realtek verify that it is on a Lenovo USB hub before enabling the passthru feature

This also adds in the device IDs for the Lenovo USB Dongle and one other USB-C dock

V2 fix formating of code
V3 remove Generic define for Device ID 0x8153 and change it to use value V4 rearrange defines and case statement to put them in better order

---
 drivers/net/usb/r8152.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/usb/r8152.c +10 -0
index c2da3438387c..d8f2d4b85db4 100644
@@ -771,7 +771,9 @@ enum rtl8152_flags {
 };
 
 #define DEVICE_ID_THINKPAD_THUNDERBOLT3_DOCK_GEN2	0x3082
+#define DEVICE_ID_THINKPAD_USB_C_DONGLE			0x720c
 #define DEVICE_ID_THINKPAD_USB_C_DOCK_GEN2		0xa387
+#define DEVICE_ID_THINKPAD_USB_C_DOCK_GEN3		0x3062
 
 struct tally_counter {
 	__le64	tx_packets;
@@ -9646,6 +9648,14 @@ static int rtl8152_probe(struct usb_interface *intf,
 		switch (le16_to_cpu(udev->descriptor.idProduct)) {
 		case DEVICE_ID_THINKPAD_THUNDERBOLT3_DOCK_GEN2:
 		case DEVICE_ID_THINKPAD_USB_C_DOCK_GEN2:
+		case DEVICE_ID_THINKPAD_USB_C_DOCK_GEN3:
+		case DEVICE_ID_THINKPAD_USB_C_DONGLE:
+			tp->lenovo_macpassthru = 1;
+		}
+	} else if ((le16_to_cpu(udev->descriptor.idVendor) == VENDOR_ID_REALTEK) &&
+		   (le16_to_cpu(udev->parent->descriptor.idVendor) == VENDOR_ID_LENOVO)) {
+		switch (le16_to_cpu(udev->descriptor.idProduct)) {
+		case 0x8153:
 			tp->lenovo_macpassthru = 1;
 		}
 	}
Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 32 lines · On Fri, 13 May 2022 08:49:06 -0400 David Ober wrote:

Lenovo Thunderbolt 4 Dock, and other Lenovo USB Docks are using the original Realtek USB ethernet Vendor and Product IDs
If the Network device is Realtek verify that it is on a Lenovo USB hub before enabling the passthru feature

This also adds in the device IDs for the Lenovo USB Dongle and one other USB-C dock

V2 fix formating of code
V3 remove Generic define for Device ID 0x8153 and change it to use value V4 rearrange defines and case statement to put them in better order

---
 drivers/net/usb/r8152.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/usb/r8152.c +2 -0
index c2da3438387c..d8f2d4b85db4 100644
@@ -771,7 +771,9 @@ enum rtl8152_flags {
 };
 
 #define DEVICE_ID_THINKPAD_THUNDERBOLT3_DOCK_GEN2	0x3082
+#define DEVICE_ID_THINKPAD_USB_C_DONGLE			0x720c
 #define DEVICE_ID_THINKPAD_USB_C_DOCK_GEN2		0xa387
+#define DEVICE_ID_THINKPAD_USB_C_DOCK_GEN3		0x3062
 
 struct tally_counter {
 	__le64	tx_packets;

drivers/net/usb/r8152.c static int rtl8152_probe(struct usb_interface *intf, · line 9656

Quoted 9 lines
drivers/net/usb/r8152.c +6 -0
@@ -9646,6 +9648,14 @@ static int rtl8152_probe(struct usb_interface *intf,
 		switch (le16_to_cpu(udev->descriptor.idProduct)) {
 		case DEVICE_ID_THINKPAD_THUNDERBOLT3_DOCK_GEN2:
 		case DEVICE_ID_THINKPAD_USB_C_DOCK_GEN2:
+		case DEVICE_ID_THINKPAD_USB_C_DOCK_GEN3:
+		case DEVICE_ID_THINKPAD_USB_C_DONGLE:
+			tp->lenovo_macpassthru = 1;
+		}
+	} else if ((le16_to_cpu(udev->descriptor.idVendor) == VENDOR_ID_REALTEK) &&
+		   (le16_to_cpu(udev->parent->descriptor.idVendor) == VENDOR_ID_LENOVO)) {

The parenthesis around the condition are unnecessary. If the compiler does not warn it's okay to skip parenthesis. checkpatch should warn about this. We assume kernel developers know the C operator precedence.

I think you should factor these checks out to a separate helper tho. Create a helper like:

static bool rtl8152_needs_lenovo_macpassthru(dev)

that can use local variables to avoid the tediously long and repeated le16_to_cpu(...) lines. Then just assign:

	tp->lenovo_macpassthru = rtl8152_needs_lenovo_macpassthru(dev);

Please CC Bjørn Mork <[email protected]> since he commented on the previous version. I'd personally also love to see this solved in user space... but have no clear idea how.

Quoted 5 lines
drivers/net/usb/r8152.c +2 -0
+		switch (le16_to_cpu(udev->descriptor.idProduct)) {
+		case 0x8153:
 			tp->lenovo_macpassthru = 1;
 		}
 	}