net: cdc_ncm: Add ACPI MAC address pass through functionality
Subsystems (5)
PATCH 3/3 net: cdc_ncm: Add ACPI MAC address pass through functionality
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.
--- 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
Quoted 53 lines · On Thu, 2019-09-05 at 21:01 +0000, [email protected] wrote:
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.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 +20
-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 ; + + ret =cdc_ncm_get_ethernet_address (dev, ctx); +if (ret) { +dev_dbg (&intf->dev,"failed to get mac address\n" ); +return ret; + }
drivers/net/usb/cdc_ncm.c static const struct net_device_ops cdc_ncm_netdev_ops = { · line 865
Quoted 10 lines
drivers/net/usb/cdc_ncm.c +10
-0+ +/* 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))
How about use one if-statement instead of these three if-statement?
Quoted 68 lines
drivers/net/usb/cdc_ncm.c +34
-10+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, };
Quoted 8 lines
Quoted 6 lines
+ 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))How about use one if-statement instead of these three if-statement?
While using a single compound if statement is possible, my experience is that using multiple if statements will make the code easier to debug and maintain by others who come after me. What is possible to do with code is not necessarily what should be done.
drivers/net/usb/cdc_ncm.c static const struct net_device_ops cdc_ncm_netdev_ops = { · line 860
Quoted 1 line · <[email protected]> writes:
drivers/net/usb/cdc_ncm.c +1
-0+if (strstr (dev->udev->product,"D6000" )) {
Huh? Can you please test that on all USB devices ever made?
Bjørn
Quoted 5 lines · Bjørn Mork
drivers/net/usb/cdc_ncm.c static const struct net_device_ops cdc_ncm_netdev_ops = { · line 860
Quoted 1 line · <[email protected]> writes:
drivers/net/usb/cdc_ncm.c +1
-0+if (strstr (dev->udev->product,"D6000" )) {Huh? Can you please test that on all USB devices ever made?
Yeah. Can't VID/PID be used as the filter here instead?
Dan