public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] r8152: Add support for setting MAC to system's Auxiliary MAC address
@ 2016-06-01 21:50 Mario Limonciello
  2016-06-01 22:27 ` Andrew Lunn
                   ` (3 more replies)
  0 siblings, 4 replies; 27+ messages in thread
From: Mario Limonciello @ 2016-06-01 21:50 UTC (permalink / raw)
  To: hayeswang
  Cc: LKML, Netdev, Linux USB, pali.rohar, anthony.wong,
	Mario Limonciello

Dell systems with Type-C ports have support for a persistent system
specific MAC address when used with Dell Type-C docks and dongles.
This means a dock plugged into two different systems will show different
(but persistent) MAC addresses.  Dell Type-C docks and dongles use the
r8152 driver.

This information for the system's persistent MAC address is burned in when
the HW is built and avilable under _SB\AMAC in the DSDT at runtime.

More information about the technology is available here:
http://www.dell.com/support/article/us/en/04/SLN301147

Signed-off-by: Mario Limonciello <mario_limonciello@dell.com>
---
 drivers/net/usb/Kconfig |  1 +
 drivers/net/usb/r8152.c | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index cdde590..c320930 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -98,6 +98,7 @@ config USB_RTL8150
 config USB_RTL8152
 	tristate "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters"
 	select MII
+	depends on ACPI
 	help
 	  This option adds support for Realtek RTL8152 based USB 2.0
 	  10/100 Ethernet adapters and RTL8153 based USB 3.0 10/100/1000
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 3f9f6ed..62af3b4 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -26,6 +26,7 @@
 #include <linux/mdio.h>
 #include <linux/usb/cdc.h>
 #include <linux/suspend.h>
+#include <linux/acpi.h>
 
 /* Information for net-next */
 #define NETNEXT_VERSION		"08"
@@ -1030,6 +1031,39 @@ out1:
 	return ret;
 }
 
+static u8 amac_ascii_to_hex(int c)
+{
+	if (c <= 0x39)
+		return (u8)(c - 0x30);
+	else if (c <= 0x46)
+		return (u8)(c - 0x37);
+	return (u8)(c - 0x57);
+}
+
+static void set_auxiliary_addr(struct sockaddr *sa)
+{
+	acpi_status status;
+	acpi_handle handle;
+	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+	union acpi_object *obj;
+	int i;
+	char *ptr;
+
+	acpi_get_handle(NULL, "\\_SB", &handle);
+	status = acpi_evaluate_object(handle, "AMAC", NULL, &buffer);
+	obj = (union acpi_object *)buffer.pointer;
+	if (ACPI_SUCCESS(status) && (obj->string.length == 0x17)) {
+		/* returns _AUXMAC_#AABBCCDDEEFF#
+		 * this pulls out _AUXMAC# from start and # from end
+		 */
+		ptr = obj->string.pointer + 9;
+		pr_info("r8152: Using system auxiliary MAC address");
+		for (i = 0; i < 6; i++, ptr += 2)
+			sa->sa_data[i] = amac_ascii_to_hex(*ptr) << 4 |
+					 amac_ascii_to_hex(*(ptr + 1));
+	}
+}
+
 static int set_ethernet_addr(struct r8152 *tp)
 {
 	struct net_device *dev = tp->netdev;
@@ -1041,6 +1075,9 @@ static int set_ethernet_addr(struct r8152 *tp)
 	else
 		ret = pla_ocp_read(tp, PLA_BACKUP, 8, sa.sa_data);
 
+	/* if system provides auxiliary MAC address */
+	set_auxiliary_addr(&sa);
+
 	if (ret < 0) {
 		netif_err(tp, probe, dev, "Get ether addr fail\n");
 	} else if (!is_valid_ether_addr(sa.sa_data)) {
-- 
2.7.4

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

end of thread, other threads:[~2016-06-03 14:52 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-01 21:50 [PATCH] r8152: Add support for setting MAC to system's Auxiliary MAC address Mario Limonciello
2016-06-01 22:27 ` Andrew Lunn
2016-06-01 22:31   ` Mario_Limonciello
2016-06-01 23:06     ` Greg KH
2016-06-02  1:54       ` Mario_Limonciello
2016-06-01 23:05 ` Greg KH
2016-06-02  2:10   ` Mario_Limonciello
2016-06-02 15:22     ` Greg KH
     [not found]       ` <20160602152244.GA26494-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2016-06-02 15:46         ` Mario_Limonciello-DYMqY+WieiM
2016-06-02 16:09           ` Greg KH
2016-06-02 16:58             ` Mario_Limonciello
2016-06-03  9:23               ` Hayes Wang
     [not found]                 ` <0835B3720019904CB8F7AA43166CEEB2FED973-JIZ+AM9kKNzuvTFwvkocLypo8c9IxeqyAjHCUHv49ws@public.gmane.org>
2016-06-03 14:52                   ` Mario_Limonciello-DYMqY+WieiM
2016-06-02 18:04           ` Bjørn Mork
2016-06-02 18:28             ` Mario_Limonciello
2016-06-02 19:03               ` Pali Rohár
2016-06-02 19:18                 ` Mario_Limonciello
2016-06-02 18:44             ` Pali Rohár
2016-06-02  2:53   ` Mario_Limonciello
2016-06-02  8:11     ` Bjørn Mork
2016-06-02 14:29       ` Mario_Limonciello
2016-06-02  7:27   ` Bjørn Mork
2016-06-02  6:10 ` Hayes Wang
2016-06-02  7:46 ` Pali Rohár
2016-06-02 14:45   ` Mario_Limonciello
2016-06-02 15:01     ` Andrew Lunn
2016-06-02 15:07       ` Mario_Limonciello

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox