linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <Charles.Hyde@dellteam.com>
To: <oliver@neukum.org>, <rjw@rjwysocki.net>, <lenb@kernel.org>
Cc: <linux-usb@vger.kernel.org>, <linux-acpi@vger.kernel.org>,
	<nic_swsd@realtek.com>, <Mario.Limonciello@dell.com>
Subject: [PATCH 3/3] net: cdc_ncm: Add ACPI MAC address pass through functionality
Date: Fri, 30 Aug 2019 19:38:54 +0000	[thread overview]
Message-ID: <b24465a706744d99a7c1682f05a24784@AUSX13MPS307.AMER.DELL.COM> (raw)

This change adds support to cdc_ncm for ACPI MAC address pass through
functionality that also exists in the Realtek r8152 driver.  This is in
support of Dell's Universal Dock D6000, to give it the same feature
capability as is currently available in Windows and advertized on Dell's
product web site.

Signed-off-by: Charles Hyde <charles.hyde@dellteam.com>
Cc: Mario Limonciello <mario.limonciello@dell.com>
Cc: Oliver Neukum <oliver@neukum.org>
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Cc: Len Brown <lenb@kernel.org>
Cc: linux-usb@vger.kernel.org
Cc: linux-acpi@vger.kernel.org
---
 drivers/net/usb/cdc_ncm.c | 67 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 64 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index 85093579612f..11a04dc2298d 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -52,6 +52,7 @@
 #include <linux/usb/usbnet.h>
 #include <linux/usb/cdc.h>
 #include <linux/usb/cdc_ncm.h>
+#include <acpi/acpi_mac_passthru.h>
 
 #if IS_ENABLED(CONFIG_USB_NET_CDC_MBIM)
 static bool prefer_mbim = true;
@@ -984,11 +985,30 @@ int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_
 	usb_set_intfdata(ctx->control, dev);
 
 	if (ctx->ether_desc) {
-		temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress);
+		struct sockaddr sa;
+
+		temp = cdc_ncm_get_ethernet_address(dev, ctx);
 		if (temp) {
 			dev_dbg(&intf->dev, "failed to get mac address\n");
 			goto error2;
 		}
+
+		/* Check for a Dell Universal Dock D6000 before checking if
+		 * ACPI supports MAC address pass through.
+		 */
+		if (!strstr(dev->udev->product, "D6000"))
+			goto skip_acpi_mapt_in_bind;
+
+		if (get_acpi_mac_passthru(sa.sa_data) != 0)
+			goto skip_acpi_mapt_in_bind;
+
+		if (memcmp(dev->net->dev_addr, sa.sa_data, ETH_ALEN) == 0)
+			goto skip_acpi_mapt_in_bind;
+
+		if (cdc_ncm_set_ethernet_address(dev, &sa) == 0)
+			memcpy(dev->net->dev_addr, sa.sa_data, ETH_ALEN);
+
+skip_acpi_mapt_in_bind:
 		dev_info(&intf->dev, "MAC-Address: %pM\n", dev->net->dev_addr);
 	}
 
@@ -1716,6 +1736,47 @@ static void cdc_ncm_status(struct usbnet *dev, struct urb *urb)
 	}
 }
 
+static int cdc_ncm_resume(struct usb_interface *intf)
+{
+	struct usbnet *dev = usb_get_intfdata(intf);
+	struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
+	int ret;
+
+	ret = usbnet_resume(intf);
+	if (ret != 0)
+		goto error2;
+
+	if (ctx->ether_desc) {
+		struct sockaddr sa;
+
+		if (cdc_ncm_get_ethernet_address(dev, ctx)) {
+			dev_dbg(&intf->dev, "failed to get mac address\n");
+			goto error2;
+		}
+
+		/* Check for a Dell Universal Dock D6000 before checking if
+		 * ACPI supports MAC address pass through.
+		 */
+		if (!strstr(dev->udev->product, "D6000"))
+			goto skip_acpi_mapt_in_resume;
+
+		if (get_acpi_mac_passthru(sa.sa_data) != 0)
+			goto skip_acpi_mapt_in_resume;
+
+		if (memcmp(dev->net->dev_addr, sa.sa_data, ETH_ALEN) == 0)
+			goto skip_acpi_mapt_in_resume;
+
+		if (cdc_ncm_set_ethernet_address(dev, &sa) == 0)
+			memcpy(dev->net->dev_addr, sa.sa_data, ETH_ALEN);
+
+skip_acpi_mapt_in_resume:
+		dev_info(&intf->dev, "MAC-Address: %pM\n", dev->net->dev_addr);
+	}
+
+error2:
+	return ret;
+}
+
 static const struct driver_info cdc_ncm_info = {
 	.description = "CDC NCM",
 	.flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT | FLAG_MULTI_PACKET
@@ -1848,8 +1909,8 @@ static struct usb_driver cdc_ncm_driver = {
 	.probe = usbnet_probe,
 	.disconnect = usbnet_disconnect,
 	.suspend = usbnet_suspend,
-	.resume = usbnet_resume,
-	.reset_resume =	usbnet_resume,
+	.resume = cdc_ncm_resume,
+	.reset_resume =	cdc_ncm_resume,
 	.supports_autosuspend = 1,
 	.disable_hub_initiated_lpm = 1,
 };
-- 
2.20.1

             reply	other threads:[~2019-08-30 19:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-30 19:38 Charles.Hyde [this message]
2019-09-02  9:49 ` [PATCH 3/3] net: cdc_ncm: Add ACPI MAC address pass through functionality Oliver Neukum
2019-09-03 17:50   ` Charles.Hyde
2019-09-03 17:57     ` Mario.Limonciello
2019-09-05 21:01 Charles.Hyde
2019-09-06  2:13 ` Chunfeng Yun
2019-09-06 13:25   ` chip.programmer
2019-09-06  7:59 ` Bjørn Mork
2019-09-06 15:23   ` Dan Williams

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=b24465a706744d99a7c1682f05a24784@AUSX13MPS307.AMER.DELL.COM \
    --to=charles.hyde@dellteam.com \
    --cc=Mario.Limonciello@dell.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nic_swsd@realtek.com \
    --cc=oliver@neukum.org \
    --cc=rjw@rjwysocki.net \
    /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).