From: Aaron Ma <aaron.ma@canonical.com>
To: aaron.ma@canonical.com, kuba@kernel.org,
henning.schild@siemens.com, linux-usb@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: davem@davemloft.net, hayeswang@realtek.com, tiwai@suse.de
Subject: [PATCH 1/3 v3] net: usb: r8152: Check used MAC passthrough address
Date: Wed, 5 Jan 2022 23:14:25 +0800 [thread overview]
Message-ID: <20220105151427.8373-1-aaron.ma@canonical.com> (raw)
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.
Currently builtin r8152 on Dock still can't be identified.
First detected r8152 will use the MAC passthrough address.
v2:
Skip builtin PCI MAC address which is share MAC address with
passthrough MAC.
Check thunderbolt based ethernet.
v3:
Add return value.
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 | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index f9877a3e83ac..2483dc421dff 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,19 @@ 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) {
+ ret = -EINVAL;
+ 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
next reply other threads:[~2022-01-05 15:14 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-05 15:14 Aaron Ma [this message]
2022-01-05 15:14 ` [PATCH 2/3] net: usb: r8152: Set probe mode to sync Aaron Ma
2022-01-05 15:33 ` Greg KH
2022-01-05 15:14 ` [PATCH 3/3] net: usb: r8152: remove unused definition Aaron Ma
2022-01-05 15:34 ` Greg KH
2022-01-05 15:31 ` [PATCH 1/3 v3] net: usb: r8152: Check used MAC passthrough address Greg KH
2022-01-05 15:57 ` Henning Schild
2022-01-05 17:30 ` Andrew Lunn
2022-01-05 17:40 ` Henning Schild
2022-01-05 21:49 ` Oliver Neukum
2022-01-05 22:27 ` Andrew Lunn
2022-01-06 2:10 ` Kai-Heng Feng
2022-01-06 13:27 ` Andrew Lunn
2022-01-07 2:01 ` Kai-Heng Feng
2022-01-07 2:31 ` Jakub Kicinski
2022-01-10 3:32 ` Kai-Heng Feng
2022-01-10 16:51 ` Jakub Kicinski
2022-01-11 1:51 ` Kai-Heng Feng
2022-01-11 14:57 ` Limonciello, Mario
2022-01-11 16:26 ` Jakub Kicinski
2022-01-11 16:33 ` Limonciello, Mario
2022-01-11 16:43 ` Jakub Kicinski
2022-01-11 16:54 ` Limonciello, Mario
2022-01-11 17:06 ` Jakub Kicinski
2022-01-11 17:10 ` Limonciello, Mario
2022-01-12 19:21 ` Henning Schild
2022-01-12 19:27 ` Limonciello, Mario
2022-01-13 3:23 ` Aaron Ma
2022-01-27 2:51 ` Aaron Ma
2022-01-27 8:06 ` Hayes Wang
2022-01-27 8:13 ` Aaron Ma
2022-01-27 8:42 ` Hayes Wang
2022-01-27 12:53 ` Andrew Lunn
2022-01-07 13:32 ` Andrew Lunn
2022-01-10 3:39 ` Kai-Heng Feng
2022-01-10 11:39 ` Oliver Neukum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220105151427.8373-1-aaron.ma@canonical.com \
--to=aaron.ma@canonical.com \
--cc=davem@davemloft.net \
--cc=hayeswang@realtek.com \
--cc=henning.schild@siemens.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).