Add get/set ethernet address functions and ACPI MAC address pass through functionality to cdc_ncm driver
Subsystems (6)
v3 cover Add get/set ethernet address functions and ACPI MAC address pass through functionality to cdc_ncm driver
In recent testing of a Dell Universal Dock D6000, I found that MAC address pass through is not supported in the Linux drivers. However, this same device is supported in Windows 10 (Pro) on my personal computer, in as much as I was able to tell Windows to assign a new MAC address of my choosing, and I saw through wireshark the new MAC address was pushed out to the device. Afterward, Windows reported a new IP address and I was able to view web pages.
This series of patches give support to cdc_ncm USB based Ethernet controllers for programming a MAC address to the device, and also to retrieve the device's MAC address. This patch series further adds ACPI MAC address pass through support specifically for the cdc_ncm driver, and generally for any other driver that may need or want it, in furtherance of Dell's enterprise IT policy efforts. It was this latter that I initially found lacking when testing a D6000 with a Dell laptop, and then I found ifconfig was unable to set a MAC address into the device. These patches bring a similar level of functionality to cdc_ncm driver as is available with the Realtek r8152 driver, and is available with Windows.
The cdc_ncm driver limits the ACPI MAC address pass through support to only the Dell Universal Dock D6000, so no other cdc_ncm device will be impacted.
Today's v3 patch series includes a function named get_ethernet_addr() which replaces two instances where the same code snippet was located in teh previous patch series. I also created a post reset function to set the MAC address, if there exists an ACPI MAC address pass through (MAPT) method. Oliver Neukum had requested a post reset function for this purpose.
Charles Hyde (3):
net: cdc_ncm: add get/set ethernet address functions
ACPI: move ACPI functionality out of r8152 driver
net: cdc_ncm: Add ACPI MAC address pass through functionality
drivers/acpi/Makefile | 1 + drivers/acpi/acpi_mac_passthru.c | 63 +++++++++++++ drivers/net/usb/cdc_ncm.c | 148 ++++++++++++++++++++++++++++--- drivers/net/usb/r8152.c | 44 +-------- include/acpi/acpi_mac_passthru.h | 27 ++++++ 5 files changed, 232 insertions(+), 51 deletions(-) create mode 100644 drivers/acpi/acpi_mac_passthru.c create mode 100644 include/acpi/acpi_mac_passthru.h
Signature · 1 line
2.20.1
PATCH v3 1/3 net: cdc_ncm: add get/set ethernet address functions
This patch adds support for pushing a MAC address out to USB based ethernet controllers driven by cdc_ncm. With this change, ifconfig can now set the device's MAC address. For example, the Dell Universal Dock D6000 is driven by cdc_ncm. The D6000 can now have its MAC address set by ifconfig, as it can be done in Windows. This was tested with a D6000 using ifconfig on an x86 based chromebook, where iproute2 is not available.
--- drivers/net/usb/cdc_ncm.c | 74 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-)
drivers/net/usb/cdc_ncm.c +73 -1
@@ -750,6 +750,78 @@ int cdc_ncm_change_mtu(struct net_device *net, int new_mtu) }EXPORT_SYMBOL_GPL (cdc_ncm_change_mtu); +/* Provide method to get MAC address from the USB device's ethernet controller. +* If the device supports CDC_GET_ADDRESS, we should receive just six bytes. +* Otherwise, use the prior method by asking for the descriptor. +*/ +static int cdc_ncm_get_ethernet_address (struct usbnet *dev, +struct cdc_ncm_ctx *ctx) +{ +int ret; +char *buf; + + buf =kmalloc (ETH_ALEN ,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + + ret =usbnet_read_cmd (dev,USB_CDC_GET_NET_ADDRESS , +USB_DIR_IN |USB_TYPE_CLASS + |USB_RECIP_INTERFACE ,0 , +USB_REQ_SET_ADDRESS , buf,ETH_ALEN ); +if (ret ==ETH_ALEN ) { +memcpy (dev->net->dev_addr, buf,ETH_ALEN ); + ret =0 ;/* success */ + }else { + ret =usbnet_get_ethernet_addr (dev, + ctx->ether_desc->iMACAddress); + } +kfree (buf); +return ret; +} + +/* Provide method to push MAC address to the USB device's ethernet controller. +* If the device does not support CDC_SET_ADDRESS, there is no harm and we +* proceed as before. +*/ +static int cdc_ncm_set_ethernet_address (struct usbnet *dev, +struct sockaddr *addr) +{ +int ret; +char *buf; + + buf =kmalloc (ETH_ALEN ,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +memcpy (buf, addr->sa_data,ETH_ALEN ); + ret =usbnet_write_cmd (dev,USB_CDC_SET_NET_ADDRESS , +USB_DIR_OUT |USB_TYPE_CLASS + |USB_RECIP_INTERFACE ,0 , +USB_REQ_SET_ADDRESS , buf,ETH_ALEN ); +if (ret ==ETH_ALEN ) + ret =0 ;/* success */ +else if (ret <0 ) +dev_dbg (&dev->udev->dev,"bad MAC address put, %d\n" , ret); + +kfree (buf); +return ret; +} + +/* Provide method to push MAC address to the USB device's ethernet controller. +*/ +int cdc_ncm_set_mac_addr (struct net_device *net,void *p) +{ +struct usbnet *dev =netdev_priv (net); + +/* Try to push the MAC address out to the device. Ignore any errors, +* to be compatible with prior versions of this source. +*/ +cdc_ncm_set_ethernet_address (dev, (struct sockaddr *)p); + +return eth_mac_addr (net, p); +} +EXPORT_SYMBOL_GPL (cdc_ncm_set_mac_addr); +static const struct net_device_ops cdc_ncm_netdev_ops = { .ndo_open = usbnet_open, .ndo_stop = usbnet_stop,
@@ -757,7 +829,7 @@ static const struct net_device_ops cdc_ncm_netdev_ops = { .ndo_tx_timeout = usbnet_tx_timeout, .ndo_get_stats64 = usbnet_get_stats64, .ndo_change_mtu = cdc_ncm_change_mtu, - .ndo_set_mac_address = eth_mac_addr, + .ndo_set_mac_address = cdc_ncm_set_mac_addr, .ndo_validate_addr = eth_validate_addr, };
Signature · 1 line
2.20.1
PATCH v3 2/3 ACPI: move ACPI functionality out of r8152 driver
In reply to Charles HydeThis change moves ACPI functionality out of the Realtek r8152 driver to its own source and header file, making it available to other drivers as needed now and into the future. At the time this ACPI snippet was introduced in 2016, only the Realtek driver made use of it in support of Dell's enterprise IT policy efforts. There comes now a need for this same support in a different driver, also in support of Dell's enterprise IT policy efforts.
--- drivers/acpi/Makefile | 1 + drivers/acpi/acpi_mac_passthru.c | 63 ++++++++++++++++++++++++++++++++ drivers/net/usb/r8152.c | 44 ++-------------------- include/acpi/acpi_mac_passthru.h | 27 ++++++++++++++ 4 files changed, 95 insertions(+), 40 deletions(-) create mode 100644 drivers/acpi/acpi_mac_passthru.c create mode 100644 include/acpi/acpi_mac_passthru.h
drivers/acpi/Makefile +1 -0
@@ -66,6 +66,7 @@ acpi-$(CONFIG_ACPI_WATCHDOG) += acpi_watchdog.o acpi-$(CONFIG_ACPI_ADXL) += acpi_adxl.o # These are (potentially) separate modules +acpi-y += acpi_mac_passthru.o # IPMI may be used by other drivers, so it has to initialise before them obj-$(CONFIG_ACPI_IPMI) += acpi_ipmi.o
drivers/acpi/acpi_mac_passthru.c new file +63 -0
63 lines not on this page · raw message
drivers/net/usb/r8152.c +4 -40
71 lines not on this page · raw message
include/acpi/acpi_mac_passthru.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* acpi_mac_passthru.h - ACPI MAC address pass through driver +* +* Copyright (c) 2019 Dell Technology. All rights reserved. +* +* Search for MAC Address Pass Through information, and return the MAC address +* found. This is set through enterprise policy settings, and expected to be +* read by ethernet drivers that have software programmable MAC addresses. +* Failure to find the needed information results in -ENODEV. +*/ + +#include <linux/module.h> +#include <linux/acpi.h> + +#ifdef CONFIG_ACPI + +int get_acpi_mac_passthru (char *macAddress); + +#else + +static inline int get_acpi_mac_passthru (char *macAddress) +{ +return -ENODEV ; +} + +#endif
Signature · 1 line
2.20.1
PATCH v3 3/3 net: cdc_ncm: Add ACPI MAC address pass through functionality
In reply to Charles HydeThis 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.
Today's v3 patch series includes a function named get_ethernet_addr() which replaces two instances where the same code snippet was located in teh previous patch series. I also created a post reset function to set the MAC address, if there exists an ACPI MAC address pass through (MAPT) method. Oliver Neukum had requested a post reset function for this purpose.
--- drivers/net/usb/cdc_ncm.c | 74 +++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 10 deletions(-)
drivers/net/usb/cdc_ncm.c +64 -10
@@ -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;
@@ -833,6 +834,45 @@ static const struct net_device_ops cdc_ncm_netdev_ops = { .ndo_validate_addr = eth_validate_addr, }; +static int get_ethernet_addr (struct usb_interface *intf) +{ +struct sockaddr sa; +struct usbnet *dev =usb_get_intfdata (intf); +struct cdc_ncm_ctx *ctx; +int ret =0 ; + +if (!dev) +return 0 ; + + ctx = (struct cdc_ncm_ctx *)dev->data[0 ]; +if (!ctx->ether_desc) +return 0 ; + + ret =cdc_ncm_get_ethernet_address (dev, ctx); +if (ret) { +dev_dbg (&intf->dev,"failed to get mac address\n" ); +return ret; + } + +/* Check for a Dell Universal Dock D6000 before checking if ACPI +* supports MAC address pass through. +*/ +if (strstr (dev->udev->product,"D6000" )) { + sa.sa_family = dev->net->type; +if (get_acpi_mac_passthru (sa.sa_data)) { +if (!memcmp (dev->net->dev_addr, sa.sa_data, +ETH_ALEN )) { +if (!cdc_ncm_set_ethernet_address (dev, &sa)) +memcpy (dev->net->dev_addr, sa.sa_data, +ETH_ALEN ); + } + } + } +dev_info (&intf->dev,"MAC-Address: %pM\n" , dev->net->dev_addr); + +return 0 ; +} +int cdc_ncm_bind_common (struct usbnet *dev,struct usb_interface *intf,u8 data_altsetting,int drvflags) {struct cdc_ncm_ctx *ctx;
@@ -983,14 +1023,8 @@ int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_usb_set_intfdata (ctx->data, dev);usb_set_intfdata (ctx->control, dev); -if (ctx->ether_desc) { - temp =usbnet_get_ethernet_addr (dev, ctx->ether_desc->iMACAddress); -if (temp) { -dev_dbg (&intf->dev,"failed to get mac address\n" ); - goto error2; - } -dev_info (&intf->dev,"MAC-Address: %pM\n" , dev->net->dev_addr); - } +if (get_ethernet_addr (intf)) + goto error2;/* finish setting up the device specific data */ cdc_ncm_setup (dev);
@@ -1716,6 +1750,25 @@ static void cdc_ncm_status(struct usbnet *dev, struct urb *urb) } } +static int cdc_ncm_resume (struct usb_interface *intf) +{ +int ret; + + ret =usbnet_resume (intf); +if (ret ==0 ) +get_ethernet_addr (intf); + +return ret; +} + +static int cdc_ncm_post_reset (struct usb_interface *intf) +{ +/* reset the MAC address in case of policy change */ +get_ethernet_addr (intf); + +return 0 ; +} +static const struct driver_info cdc_ncm_info = { .description ="CDC NCM" , .flags =FLAG_POINTTOPOINT |FLAG_NO_SETINT |FLAG_MULTI_PACKET
@@ -1848,8 +1901,9 @@ 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, + .post_reset = cdc_ncm_post_reset, .supports_autosuspend = 1, .disable_hub_initiated_lpm = 1, };
Signature · 1 line
2.20.1
Re: [PATCH v3 3/3] net: cdc_ncm: Add ACPI MAC address pass through functionality
Quoted 55 lines · Charles Hyde
This change adds support to
cdc_ncmfor 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.Today's v3 patch series includes a function named
get_ethernet_addr()which replaces two instances where the same code snippet was located in teh previous patch series. I also created a post reset function to set the MAC address, if there exists an ACPI MAC address pass through (MAPT) method. Oliver Neukum had requested a post reset function for this purpose.Signed-off-by Charles Hyde <[email protected]>Cc Mario Limonciello <[email protected]>Cc Oliver Neukum <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>--- drivers/net/usb/cdc_ncm.c | 74 +++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 10 deletions(-)drivers/net/usb/cdc_ncm.c +15
-0@@ -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;@@ -833,6 +834,45 @@ static const struct net_device_ops cdc_ncm_netdev_ops = { .ndo_validate_addr = eth_validate_addr, }; +static int get_ethernet_addr (struct usb_interface *intf) +{ +struct sockaddr sa; +struct usbnet *dev =usb_get_intfdata (intf); +struct cdc_ncm_ctx *ctx; +int ret =0 ; + +if (!dev) +return 0 ; + + ctx = (struct cdc_ncm_ctx *)dev->data[0 ]; +if (!ctx->ether_desc) +return 0 ; +
drivers/net/usb/cdc_ncm.c static const struct net_device_ops cdc_ncm_netdev_ops = { · line 860
Quoted 10 lines
drivers/net/usb/cdc_ncm.c +10
-0+ ret =cdc_ncm_get_ethernet_address (dev, ctx); +if (ret) { +dev_dbg (&intf->dev,"failed to get mac address\n" ); +return ret; + } + +/* Check for a Dell Universal Dock D6000 before checking if ACPI +* supports MAC address pass through. +*/ +if (strstr (dev->udev->product,"D6000" )) {
As other people have pointed out, that's funny.
No, this is explicitly what the USB vendor/product ids are for, don't try to make up something that will be guaranteed to not work correctly...
drivers/net/usb/cdc_ncm.c static const struct net_device_ops cdc_ncm_netdev_ops = { · line 871
Quoted 11 lines
drivers/net/usb/cdc_ncm.c +11
-0+ sa.sa_family = dev->net->type; +if (get_acpi_mac_passthru (sa.sa_data)) { +if (!memcmp (dev->net->dev_addr, sa.sa_data, +ETH_ALEN )) { +if (!cdc_ncm_set_ethernet_address (dev, &sa)) +memcpy (dev->net->dev_addr, sa.sa_data, +ETH_ALEN ); + } + } + } +dev_info (&intf->dev,"MAC-Address: %pM\n" , dev->net->dev_addr);
If a driver is working properly, it should not spit out any kernel log messages. Make this dev_dbg() if you need it for your own debugging logic.
thanks,
greg k-h