[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220728191851.30402-1-oneukum@suse.com>
Date: Thu, 28 Jul 2022 21:18:51 +0200
From: Oliver Neukum <oneukum@...e.com>
To: hayeswang@...ltek.com, netdev@...r.kernel.org
Cc: Oliver Neukum <oneukum@...e.com>
Subject: [RFC] r8152: pass through needs to be singular
If multiple devices are connected only one of them
is allowed to get the pass through MAC
Signed-off-by: Oliver Neukum <oneukum@...e.com>
---
drivers/net/usb/r8152.c | 38 ++++++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 0f6efaabaa32..15f695398284 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -1193,6 +1193,9 @@ static unsigned int agg_buf_sz = 16384;
#define RTL_LIMITED_TSO_SIZE (size_to_mtu(agg_buf_sz) - sizeof(struct tx_desc))
+static struct r8152 *holder_of_pass_through = NULL;
+static DEFINE_MUTEX(pass_through_lock);
+
static
int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
{
@@ -1587,8 +1590,19 @@ static int __rtl8152_set_mac_address(struct net_device *netdev, void *p,
return ret;
}
+static void give_up_pass_through(struct r8152 *tp)
+{
+ mutex_lock(&pass_through_lock);
+ if (tp == holder_of_pass_through)
+ holder_of_pass_through = NULL;
+ mutex_unlock(&pass_through_lock);
+}
+
static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
{
+ struct r8152 *tp = netdev_priv(netdev);
+
+ give_up_pass_through(tp);
return __rtl8152_set_mac_address(netdev, p, false);
}
@@ -1608,6 +1622,12 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
acpi_object_type mac_obj_type;
int mac_strlen;
+ mutex_lock(&pass_through_lock);
+
+ if (!holder_of_pass_through) {
+ ret = -EBUSY;
+ goto failout;
+ }
if (tp->lenovo_macpassthru) {
mac_obj_name = "\\MACA";
mac_obj_type = ACPI_TYPE_STRING;
@@ -1621,7 +1641,8 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
if ((ocp_data & PASS_THRU_MASK) != 1) {
netif_dbg(tp, probe, tp->netdev,
"No efuse for RTL8153-AD MAC pass through\n");
- return -ENODEV;
+ ret = -ENODEV;
+ goto failout;
}
} else {
/* test for RTL8153-BND and RTL8153-BD */
@@ -1629,7 +1650,8 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
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;
+ ret = -ENODEV;
+ goto failout;
}
}
@@ -1641,8 +1663,10 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
/* returns _AUXMAC_#AABBCCDDEEFF# */
status = acpi_evaluate_object(NULL, mac_obj_name, NULL, &buffer);
obj = (union acpi_object *)buffer.pointer;
- if (!ACPI_SUCCESS(status))
- return -ENODEV;
+ if (!ACPI_SUCCESS(status)) {
+ ret = -ENODEV;
+ goto failout;
+ }
if (obj->type != mac_obj_type || obj->string.length != mac_strlen) {
netif_warn(tp, probe, tp->netdev,
"Invalid buffer for pass-thru MAC addr: (%d, %d)\n",
@@ -1670,6 +1694,10 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
amacout:
kfree(obj);
+failout:
+ if (!ret)
+ holder_of_pass_through = tp;
+ mutex_unlock(&pass_through_lock);
return ret;
}
@@ -8287,6 +8315,7 @@ static int rtl8152_pre_reset(struct usb_interface *intf)
tp->rtl_ops.disable(tp);
mutex_unlock(&tp->control);
}
+ give_up_pass_through(tp);
return 0;
}
@@ -9802,6 +9831,7 @@ static void rtl8152_disconnect(struct usb_interface *intf)
cancel_delayed_work_sync(&tp->hw_phy_work);
if (tp->rtl_ops.unload)
tp->rtl_ops.unload(tp);
+ give_up_pass_through(tp);
rtl8152_release_firmware(tp);
free_netdev(tp->netdev);
}
--
2.35.3
Powered by blists - more mailing lists