All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] net: usb: r8152: Check used MAC passthrough address
@ 2022-01-05 14:23 Aaron Ma
  2022-01-05 14:23 ` [PATCH 2/3] net: usb: r8152: Set probe mode to sync Aaron Ma
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Aaron Ma @ 2022-01-05 14:23 UTC (permalink / raw)
  To: aaron.ma, kuba, henning.schild, linux-usb, netdev, linux-kernel
  Cc: davem, hayeswang, tiwai

When plugin multiple r8152 ethernet dongles to Lenovo Docks
or USB hub, MAC passthrough address from BIOS should be
checked if it had been used to avoid using on other dongles.

Skip builtin PCI MAC address which is share MAC address with
passthrough MAC.
Check thunderbolt based ethernet.

Currently builtin r8152 on Dock still can't be identified.
First detected r8152 will use the MAC passthrough address.

Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
 drivers/net/usb/r8152.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index f9877a3e83ac..91f4b2761f8e 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -25,6 +25,7 @@
 #include <linux/atomic.h>
 #include <linux/acpi.h>
 #include <linux/firmware.h>
+#include <linux/pci.h>
 #include <crypto/hash.h>
 #include <linux/usb/r8152.h>
 
@@ -1605,6 +1606,7 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
 	char *mac_obj_name;
 	acpi_object_type mac_obj_type;
 	int mac_strlen;
+	struct net_device *ndev;
 
 	if (tp->lenovo_macpassthru) {
 		mac_obj_name = "\\MACA";
@@ -1662,6 +1664,18 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
 		ret = -EINVAL;
 		goto amacout;
 	}
+	rcu_read_lock();
+	for_each_netdev_rcu(&init_net, ndev) {
+		if (ndev->dev.parent && dev_is_pci(ndev->dev.parent) &&
+				!pci_is_thunderbolt_attached(to_pci_dev(ndev->dev.parent)))
+			continue;
+		if (strncmp(buf, ndev->dev_addr, 6) == 0) {
+			rcu_read_unlock();
+			goto amacout;
+		}
+	}
+	rcu_read_unlock();
+
 	memcpy(sa->sa_data, buf, 6);
 	netif_info(tp, probe, tp->netdev,
 		   "Using pass-thru MAC addr %pM\n", sa->sa_data);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] net: usb: r8152: Set probe mode to sync
  2022-01-05 14:23 [PATCH 1/3] net: usb: r8152: Check used MAC passthrough address Aaron Ma
@ 2022-01-05 14:23 ` Aaron Ma
  2022-01-05 14:23 ` [PATCH 3/3] net: usb: r8152: remove unused definition Aaron Ma
  2022-01-05 14:48 ` [PATCH 1/3] net: usb: r8152: Check used MAC passthrough address Henning Schild
  2 siblings, 0 replies; 7+ messages in thread
From: Aaron Ma @ 2022-01-05 14:23 UTC (permalink / raw)
  To: aaron.ma, kuba, henning.schild, linux-usb, netdev, linux-kernel
  Cc: davem, hayeswang, tiwai

To avoid the race of get passthrough MAC,
set probe mode to sync to check the used MAC address.

Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
 drivers/net/usb/r8152.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 91f4b2761f8e..3fbce3dbc04d 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -29,6 +29,8 @@
 #include <crypto/hash.h>
 #include <linux/usb/r8152.h>
 
+static struct usb_driver rtl8152_driver;
+
 /* Information for net-next */
 #define NETNEXT_VERSION		"12"
 
@@ -9545,6 +9547,9 @@ static int rtl8152_probe(struct usb_interface *intf,
 	struct r8152 *tp;
 	struct net_device *netdev;
 	int ret;
+	struct device_driver *rtl8152_drv = &rtl8152_driver.drvwrap.driver;
+
+	rtl8152_drv->probe_type = PROBE_FORCE_SYNCHRONOUS;
 
 	if (version == RTL_VER_UNKNOWN)
 		return -ENODEV;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] net: usb: r8152: remove unused definition
  2022-01-05 14:23 [PATCH 1/3] net: usb: r8152: Check used MAC passthrough address Aaron Ma
  2022-01-05 14:23 ` [PATCH 2/3] net: usb: r8152: Set probe mode to sync Aaron Ma
@ 2022-01-05 14:23 ` Aaron Ma
  2022-01-05 14:51   ` Henning Schild
  2022-01-05 14:52   ` Greg KH
  2022-01-05 14:48 ` [PATCH 1/3] net: usb: r8152: Check used MAC passthrough address Henning Schild
  2 siblings, 2 replies; 7+ messages in thread
From: Aaron Ma @ 2022-01-05 14:23 UTC (permalink / raw)
  To: aaron.ma, kuba, henning.schild, linux-usb, netdev, linux-kernel
  Cc: davem, hayeswang, tiwai

Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
 drivers/net/usb/r8152.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 3fbce3dbc04d..be2a6a2c2445 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -773,9 +773,6 @@ enum rtl8152_flags {
 	RX_EPROTO,
 };
 
-#define DEVICE_ID_THINKPAD_THUNDERBOLT3_DOCK_GEN2	0x3082
-#define DEVICE_ID_THINKPAD_USB_C_DOCK_GEN2		0xa387
-
 struct tally_counter {
 	__le64	tx_packets;
 	__le64	rx_packets;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] net: usb: r8152: Check used MAC passthrough address
  2022-01-05 14:23 [PATCH 1/3] net: usb: r8152: Check used MAC passthrough address Aaron Ma
  2022-01-05 14:23 ` [PATCH 2/3] net: usb: r8152: Set probe mode to sync Aaron Ma
  2022-01-05 14:23 ` [PATCH 3/3] net: usb: r8152: remove unused definition Aaron Ma
@ 2022-01-05 14:48 ` Henning Schild
  2 siblings, 0 replies; 7+ messages in thread
From: Henning Schild @ 2022-01-05 14:48 UTC (permalink / raw)
  To: Aaron Ma; +Cc: kuba, linux-usb, netdev, linux-kernel, davem, hayeswang, tiwai

No cover letter?

I think p1 and 2 should be squashed.

Am Wed,  5 Jan 2022 22:23:49 +0800
schrieb Aaron Ma <aaron.ma@canonical.com>:

> When plugin multiple r8152 ethernet dongles to Lenovo Docks
> or USB hub, MAC passthrough address from BIOS should be
> checked if it had been used to avoid using on other dongles.
> 
> Skip builtin PCI MAC address which is share MAC address with
> passthrough MAC.
> Check thunderbolt based ethernet.
> 
> Currently builtin r8152 on Dock still can't be identified.
> First detected r8152 will use the MAC passthrough address.
> 
> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
> ---
>  drivers/net/usb/r8152.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index f9877a3e83ac..91f4b2761f8e 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
> @@ -25,6 +25,7 @@
>  #include <linux/atomic.h>
>  #include <linux/acpi.h>
>  #include <linux/firmware.h>
> +#include <linux/pci.h>
>  #include <crypto/hash.h>
>  #include <linux/usb/r8152.h>
>  
> @@ -1605,6 +1606,7 @@ static int vendor_mac_passthru_addr_read(struct
> r8152 *tp, struct sockaddr *sa) char *mac_obj_name;
>  	acpi_object_type mac_obj_type;
>  	int mac_strlen;
> +	struct net_device *ndev;

reverse xmas tree

>  
>  	if (tp->lenovo_macpassthru) {
>  		mac_obj_name = "\\MACA";
> @@ -1662,6 +1664,18 @@ static int
> vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
> ret = -EINVAL; goto amacout;
>  	}
> +	rcu_read_lock();
> +	for_each_netdev_rcu(&init_net, ndev) {
> +		if (ndev->dev.parent && dev_is_pci(ndev->dev.parent)
> &&
> +
> !pci_is_thunderbolt_attached(to_pci_dev(ndev->dev.parent)))
> +			continue;
> +		if (strncmp(buf, ndev->dev_addr, 6) == 0) {
> +			rcu_read_unlock();

ret = -EBUSY; or anything but 0, otherwise you get a random MAC from a
calling stack.

Henning

> +			goto amacout;
> +		}
> +	}
> +	rcu_read_unlock();
> +
>  	memcpy(sa->sa_data, buf, 6);
>  	netif_info(tp, probe, tp->netdev,
>  		   "Using pass-thru MAC addr %pM\n", sa->sa_data);


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] net: usb: r8152: remove unused definition
  2022-01-05 14:23 ` [PATCH 3/3] net: usb: r8152: remove unused definition Aaron Ma
@ 2022-01-05 14:51   ` Henning Schild
  2022-01-05 15:06     ` Greg KH
  2022-01-05 14:52   ` Greg KH
  1 sibling, 1 reply; 7+ messages in thread
From: Henning Schild @ 2022-01-05 14:51 UTC (permalink / raw)
  To: Aaron Ma; +Cc: kuba, linux-usb, netdev, linux-kernel, davem, hayeswang, tiwai

Am Wed,  5 Jan 2022 22:23:51 +0800
schrieb Aaron Ma <aaron.ma@canonical.com>:

Maybe add a 
Fixes: f77b83b5bbab ("net: usb: r8152: Add MAC passthrough support for more Lenovo Docks")

> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
> ---
>  drivers/net/usb/r8152.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index 3fbce3dbc04d..be2a6a2c2445 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
> @@ -773,9 +773,6 @@ enum rtl8152_flags {
>  	RX_EPROTO,
>  };
>  
> -#define DEVICE_ID_THINKPAD_THUNDERBOLT3_DOCK_GEN2	0x3082
> -#define DEVICE_ID_THINKPAD_USB_C_DOCK_GEN2		0xa387
> -
>  struct tally_counter {
>  	__le64	tx_packets;
>  	__le64	rx_packets;


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] net: usb: r8152: remove unused definition
  2022-01-05 14:23 ` [PATCH 3/3] net: usb: r8152: remove unused definition Aaron Ma
  2022-01-05 14:51   ` Henning Schild
@ 2022-01-05 14:52   ` Greg KH
  1 sibling, 0 replies; 7+ messages in thread
From: Greg KH @ 2022-01-05 14:52 UTC (permalink / raw)
  To: Aaron Ma
  Cc: kuba, henning.schild, linux-usb, netdev, linux-kernel, davem,
	hayeswang, tiwai

On Wed, Jan 05, 2022 at 10:23:51PM +0800, Aaron Ma wrote:
> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
> ---
>  drivers/net/usb/r8152.c | 3 ---
>  1 file changed, 3 deletions(-)

I know I do not take patches without any changelog text in it, maybe
other maintainers are more lax :)

Please fix.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] net: usb: r8152: remove unused definition
  2022-01-05 14:51   ` Henning Schild
@ 2022-01-05 15:06     ` Greg KH
  0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2022-01-05 15:06 UTC (permalink / raw)
  To: Henning Schild
  Cc: Aaron Ma, kuba, linux-usb, netdev, linux-kernel, davem, hayeswang, tiwai

On Wed, Jan 05, 2022 at 03:51:06PM +0100, Henning Schild wrote:
> Am Wed,  5 Jan 2022 22:23:51 +0800
> schrieb Aaron Ma <aaron.ma@canonical.com>:
> 
> Maybe add a 
> Fixes: f77b83b5bbab ("net: usb: r8152: Add MAC passthrough support for more Lenovo Docks")

How can removing an unused #define fix anything?


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-01-05 15:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-05 14:23 [PATCH 1/3] net: usb: r8152: Check used MAC passthrough address Aaron Ma
2022-01-05 14:23 ` [PATCH 2/3] net: usb: r8152: Set probe mode to sync Aaron Ma
2022-01-05 14:23 ` [PATCH 3/3] net: usb: r8152: remove unused definition Aaron Ma
2022-01-05 14:51   ` Henning Schild
2022-01-05 15:06     ` Greg KH
2022-01-05 14:52   ` Greg KH
2022-01-05 14:48 ` [PATCH 1/3] net: usb: r8152: Check used MAC passthrough address Henning Schild

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.