diff mbox series

net: usb: r8152: Add MAC passthrough support for RTL8153BL

Message ID 20220127100109.12979-1-aaron.ma@canonical.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: usb: r8152: Add MAC passthrough support for RTL8153BL | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning CHECK: Alignment should match open parenthesis WARNING: line length of 85 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Aaron Ma Jan. 27, 2022, 10:01 a.m. UTC
RTL8153-BL is used in Lenovo Thunderbolt4 dock.
Add the support of MAC passthrough.
This is ported from Realtek Outbox driver r8152.53.56-2.15.0.

There are 2 kinds of rules for MAC passthrough of Lenovo products,
1st USB vendor ID belongs to Lenovo, 2nd the chip of RTL8153-BL
is dedicated for Lenovo. Check the ocp data first then set ACPI object
names.

Suggested-by: Hayes Wang <hayeswang@realtek.com>
Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
 drivers/net/usb/r8152.c | 44 ++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 20 deletions(-)

Comments

Greg Kroah-Hartman Jan. 27, 2022, 10:10 a.m. UTC | #1
On Thu, Jan 27, 2022 at 06:01:09PM +0800, Aaron Ma wrote:
> RTL8153-BL is used in Lenovo Thunderbolt4 dock.
> Add the support of MAC passthrough.
> This is ported from Realtek Outbox driver r8152.53.56-2.15.0.
> 
> There are 2 kinds of rules for MAC passthrough of Lenovo products,
> 1st USB vendor ID belongs to Lenovo, 2nd the chip of RTL8153-BL
> is dedicated for Lenovo. Check the ocp data first then set ACPI object
> names.
> 
> Suggested-by: Hayes Wang <hayeswang@realtek.com>
> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
> ---
>  drivers/net/usb/r8152.c | 44 ++++++++++++++++++++++-------------------
>  1 file changed, 24 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index ee41088c5251..df997b330ee4 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
> @@ -718,6 +718,7 @@ enum spd_duplex {
>  #define AD_MASK			0xfee0
>  #define BND_MASK		0x0004
>  #define BD_MASK			0x0001
> +#define BL_MASK                 BIT(3)

No tab?  :(
Aaron Ma Jan. 27, 2022, 10:14 a.m. UTC | #2
On 1/27/22 18:10, Greg KH wrote:
>> +#define BL_MASK                 BIT(3)
> No tab?:(
> 

My bad, vim paste.
Allow me to fix it v2.

Aaron
Hayes Wang Jan. 27, 2022, 11:07 a.m. UTC | #3
Aaron Ma <aaron.ma@canonical.com>
> Sent: Thursday, January 27, 2022 6:01 PM
[...]
> @@ -1606,31 +1607,34 @@ static int vendor_mac_passthru_addr_read(struct
> r8152 *tp, struct sockaddr *sa)
>  	acpi_object_type mac_obj_type;
>  	int mac_strlen;
> 
> +	/* test for -AD variant of RTL8153 */
> +	ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0);
> +	if ((ocp_data & AD_MASK) == 0x1000) {
> +		/* test for MAC address pass-through bit */
> +		ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, EFUSE);
> +		if ((ocp_data & PASS_THRU_MASK) != 1) {
> +			netif_dbg(tp, probe, tp->netdev,
> +					"No efuse for RTL8153-AD MAC pass through\n");
> +			return -ENODEV;
> +		}
> +	} else {
> +		ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1);
> +		if (tp->version == RTL_VER_09 && (ocp_data & BL_MASK)) {
> +			/* test for RTL8153BL for Lenovo */
> +			tp->lenovo_macpassthru = 1;
> +		} else if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK)
> == 0) {
> +			/* test for RTL8153-BND and RTL8153-BD */
> +			netif_dbg(tp, probe, tp->netdev,
> +					"Invalid variant for MAC pass through\n");
> +			return -ENODEV;

I think the devices with the VID/PID of Lenovo, such as 0x17EF/0x3082 and 0x17EF/0xA387,
would always return -ENODEV here. Is it what you want?


Best Regards,
Hayes


> +		}
> +	}
> +
>  	if (tp->lenovo_macpassthru) {
>  		mac_obj_name = "\\MACA";
>  		mac_obj_type = ACPI_TYPE_STRING;
>  		mac_strlen = 0x16;
>  	} else {
> -		/* test for -AD variant of RTL8153 */
> -		ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0);
> -		if ((ocp_data & AD_MASK) == 0x1000) {
> -			/* test for MAC address pass-through bit */
> -			ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, EFUSE);
> -			if ((ocp_data & PASS_THRU_MASK) != 1) {
> -				netif_dbg(tp, probe, tp->netdev,
> -						"No efuse for RTL8153-AD MAC pass through\n");
> -				return -ENODEV;
> -			}
> -		} else {
> -			/* test for RTL8153-BND and RTL8153-BD */
> -			ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1);
> -			if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK)
> == 0) {
> -				netif_dbg(tp, probe, tp->netdev,
> -						"Invalid variant for MAC pass through\n");
> -				return -ENODEV;
> -			}
> -		}
> -
>  		mac_obj_name = "\\_SB.AMAC";
>  		mac_obj_type = ACPI_TYPE_BUFFER;
>  		mac_strlen = 0x17;
> --
> 2.32.0
Andrew Lunn Jan. 27, 2022, 2:19 p.m. UTC | #4
On Thu, Jan 27, 2022 at 06:01:09PM +0800, Aaron Ma wrote:
> RTL8153-BL is used in Lenovo Thunderbolt4 dock.
> Add the support of MAC passthrough.
> This is ported from Realtek Outbox driver r8152.53.56-2.15.0.
> 
> There are 2 kinds of rules for MAC passthrough of Lenovo products,
> 1st USB vendor ID belongs to Lenovo, 2nd the chip of RTL8153-BL
> is dedicated for Lenovo. Check the ocp data first then set ACPI object
> names.
> 
> Suggested-by: Hayes Wang <hayeswang@realtek.com>
> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
> ---
>  drivers/net/usb/r8152.c | 44 ++++++++++++++++++++++-------------------
>  1 file changed, 24 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index ee41088c5251..df997b330ee4 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
> @@ -718,6 +718,7 @@ enum spd_duplex {
>  #define AD_MASK			0xfee0
>  #define BND_MASK		0x0004
>  #define BD_MASK			0x0001
> +#define BL_MASK                 BIT(3)

Just to be sure, this is defined by Realtek? This is not just Lenovo
just misusing a reserved bit?

     Andrew
Aaron Ma Jan. 28, 2022, 4:19 a.m. UTC | #5
On 1/27/22 22:19, Andrew Lunn wrote:
> On Thu, Jan 27, 2022 at 06:01:09PM +0800, Aaron Ma wrote:
>> RTL8153-BL is used in Lenovo Thunderbolt4 dock.
>> Add the support of MAC passthrough.
>> This is ported from Realtek Outbox driver r8152.53.56-2.15.0.
>>
>> There are 2 kinds of rules for MAC passthrough of Lenovo products,
>> 1st USB vendor ID belongs to Lenovo, 2nd the chip of RTL8153-BL
>> is dedicated for Lenovo. Check the ocp data first then set ACPI object
>> names.
>>
>> Suggested-by: Hayes Wang <hayeswang@realtek.com>
>> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
>> ---
>>   drivers/net/usb/r8152.c | 44 ++++++++++++++++++++++-------------------
>>   1 file changed, 24 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
>> index ee41088c5251..df997b330ee4 100644
>> --- a/drivers/net/usb/r8152.c
>> +++ b/drivers/net/usb/r8152.c
>> @@ -718,6 +718,7 @@ enum spd_duplex {
>>   #define AD_MASK			0xfee0
>>   #define BND_MASK		0x0004
>>   #define BD_MASK			0x0001
>> +#define BL_MASK                 BIT(3)
> 
> Just to be sure, this is defined by Realtek? This is not just Lenovo
> just misusing a reserved bit?
> 

 From what I know, It's defined by Realtek to identify customized product.
It shouldn't be misusing.
Also it's used by Realtek outbox driver.

Aaron

>       Andrew
Aaron Ma Jan. 28, 2022, 4:20 a.m. UTC | #6
On 1/27/22 19:07, Hayes Wang wrote:
> I think the devices with the VID/PID of Lenovo, such as 0x17EF/0x3082 and 0x17EF/0xA387,
> would always return -ENODEV here. Is it what you want?
> 

This was a mistake.
Try to fix it in V3.

Thanks,
Aaron

> 
> Best Regards,
> Hayes
diff mbox series

Patch

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index ee41088c5251..df997b330ee4 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -718,6 +718,7 @@  enum spd_duplex {
 #define AD_MASK			0xfee0
 #define BND_MASK		0x0004
 #define BD_MASK			0x0001
+#define BL_MASK                 BIT(3)
 #define EFUSE			0xcfdb
 #define PASS_THRU_MASK		0x1
 
@@ -1606,31 +1607,34 @@  static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
 	acpi_object_type mac_obj_type;
 	int mac_strlen;
 
+	/* test for -AD variant of RTL8153 */
+	ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0);
+	if ((ocp_data & AD_MASK) == 0x1000) {
+		/* test for MAC address pass-through bit */
+		ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, EFUSE);
+		if ((ocp_data & PASS_THRU_MASK) != 1) {
+			netif_dbg(tp, probe, tp->netdev,
+					"No efuse for RTL8153-AD MAC pass through\n");
+			return -ENODEV;
+		}
+	} else {
+		ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1);
+		if (tp->version == RTL_VER_09 && (ocp_data & BL_MASK)) {
+			/* test for RTL8153BL for Lenovo */
+			tp->lenovo_macpassthru = 1;
+		} else if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK) == 0) {
+			/* test for RTL8153-BND and RTL8153-BD */
+			netif_dbg(tp, probe, tp->netdev,
+					"Invalid variant for MAC pass through\n");
+			return -ENODEV;
+		}
+	}
+
 	if (tp->lenovo_macpassthru) {
 		mac_obj_name = "\\MACA";
 		mac_obj_type = ACPI_TYPE_STRING;
 		mac_strlen = 0x16;
 	} else {
-		/* test for -AD variant of RTL8153 */
-		ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0);
-		if ((ocp_data & AD_MASK) == 0x1000) {
-			/* test for MAC address pass-through bit */
-			ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, EFUSE);
-			if ((ocp_data & PASS_THRU_MASK) != 1) {
-				netif_dbg(tp, probe, tp->netdev,
-						"No efuse for RTL8153-AD MAC pass through\n");
-				return -ENODEV;
-			}
-		} else {
-			/* test for RTL8153-BND and RTL8153-BD */
-			ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1);
-			if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK) == 0) {
-				netif_dbg(tp, probe, tp->netdev,
-						"Invalid variant for MAC pass through\n");
-				return -ENODEV;
-			}
-		}
-
 		mac_obj_name = "\\_SB.AMAC";
 		mac_obj_type = ACPI_TYPE_BUFFER;
 		mac_strlen = 0x17;