From patchwork Fri Aug 30 19:37:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles.Hyde@dellteam.com X-Patchwork-Id: 11124465 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 631A214DE for ; Fri, 30 Aug 2019 19:37:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 383EC23430 for ; Fri, 30 Aug 2019 19:37:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=dellteam.com header.i=@dellteam.com header.b="pjcL+i8R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728258AbfH3ThJ (ORCPT ); Fri, 30 Aug 2019 15:37:09 -0400 Received: from mx0a-00154904.pphosted.com ([148.163.133.20]:26112 "EHLO mx0a-00154904.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727888AbfH3ThJ (ORCPT ); Fri, 30 Aug 2019 15:37:09 -0400 Received: from pps.filterd (m0170392.ppops.net [127.0.0.1]) by mx0a-00154904.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x7UJYoOn020120; Fri, 30 Aug 2019 15:37:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dellteam.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=smtpout1; bh=SG7/ZrIxFNnyczseg+qZx3HwfoDHJQCk+Vr/FKcBrIs=; b=pjcL+i8RxwOWE5Uubj5zBI7luK0SE5ug6bks0efm7wvCjzc2aYsCyO7BzYY//egbZmto q7Vvy1wOXBYiEXeY7hflvkQoB1NMNU0C/bHtzSgu99gvg472tr209xFHFrdYCFdR96OK ZEe2dJylRWUwiY4yZ62YD/KhPTOZiOOWZqrqbnu3wyE/Pdq75Va0WxzxsiOJ6meZ7BxP Q0HwB01ODCUhvYTS4+YGZW5GRIt6pckdfej24UgQMbp3b3kw8NkaR62sPtWQXxN2bynG Esym+0oDdWlml3hRByjs/uNt4rVnHqw7XTjsfqWoHH+3w/IlHttl4x1Bx+ynXuOTOQ/C Zg== Received: from mx0a-00154901.pphosted.com (mx0a-00154901.pphosted.com [67.231.149.39]) by mx0a-00154904.pphosted.com with ESMTP id 2uk2r5vmgf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 30 Aug 2019 15:37:08 -0400 Received: from pps.filterd (m0134746.ppops.net [127.0.0.1]) by mx0a-00154901.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x7UJX18c021191; Fri, 30 Aug 2019 15:37:08 -0400 Received: from ausxipps306.us.dell.com (AUSXIPPS306.us.dell.com [143.166.148.156]) by mx0a-00154901.pphosted.com with ESMTP id 2upx0ujq1n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 Aug 2019 15:37:08 -0400 X-LoopCount0: from 10.166.132.131 X-PREM-Routing: D-Outbound X-IronPort-AV: E=Sophos;i="5.60,349,1549951200"; d="scan'208";a="368171689" From: To: , , CC: , , , Subject: [PATCH 1/3] net: cdc_ncm: add get/set ethernet address functions Thread-Topic: [PATCH 1/3] net: cdc_ncm: add get/set ethernet address functions Thread-Index: AQHVX2pN6giiJ6/FU06nVjUMk0ut4w== Date: Fri, 30 Aug 2019 19:37:05 +0000 Message-ID: <5cee0eb405f2492b8086d8684f1c75ca@AUSX13MPS307.AMER.DELL.COM> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.177.90.68] MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.70,1.0.8 definitions=2019-08-30_07:2019-08-29,2019-08-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 bulkscore=0 malwarescore=0 suspectscore=0 lowpriorityscore=0 adultscore=0 impostorscore=0 spamscore=0 clxscore=1015 phishscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1908300184 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 clxscore=1015 impostorscore=0 bulkscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1908300184 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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. Signed-off-by: Charles Hyde Cc: Mario Limonciello Cc: Oliver Neukum Cc: linux-usb@vger.kernel.org --- drivers/net/usb/cdc_ncm.c | 74 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c index 50c05d0f44cb..85093579612f 100644 --- a/drivers/net/usb/cdc_ncm.c +++ b/drivers/net/usb/cdc_ncm.c @@ -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, }; From patchwork Fri Aug 30 19:38:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles.Hyde@dellteam.com X-Patchwork-Id: 11124471 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28CD513B1 for ; Fri, 30 Aug 2019 19:38:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0689E23430 for ; Fri, 30 Aug 2019 19:38:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=dellteam.com header.i=@dellteam.com header.b="uAn6WqtT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728086AbfH3TiQ (ORCPT ); Fri, 30 Aug 2019 15:38:16 -0400 Received: from mx0b-00154904.pphosted.com ([148.163.137.20]:23674 "EHLO mx0b-00154904.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727246AbfH3TiQ (ORCPT ); Fri, 30 Aug 2019 15:38:16 -0400 Received: from pps.filterd (m0170396.ppops.net [127.0.0.1]) by mx0b-00154904.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x7UJYnM5011547; Fri, 30 Aug 2019 15:38:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dellteam.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=smtpout1; bh=oCR3uKLh7OJgs1eCBjb4l8GF+Hdcyevl5fSZCEHPJlE=; b=uAn6WqtTReyYyLn7rg8nLNZ3oZlPl3qphlVskj0SJSEFS/0lROaWb8XVgmZj96DHy90g bc4GD6HGcCvM1SfEVskWN0qJvYFNzat00EJKqiKhS1+4YJNcYGIxkA+uTBri+imGXVAJ LKuKwvJI3PF2z7zIoUk1hBfOGbYmw58wcxlHH9E5fCml+fk1wCgj3wSAt0u6LKGMw9WG NriSmJVs1zT1QIGpUYNQ4AFeSpcGoYYBqhwh4ppCMZDyr+LNFIeCKhF1PINt9xRZ8qgQ Z4S3IvOG2xz6zQuzYagwJ7JvIUtXCVaXdV1MB957/fd2sJlSdk8Ps9D68TYyieKACfvj 8Q== Received: from mx0a-00154901.pphosted.com (mx0a-00154901.pphosted.com [67.231.149.39]) by mx0b-00154904.pphosted.com with ESMTP id 2uk2xjcygh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 30 Aug 2019 15:38:13 -0400 Received: from pps.filterd (m0142699.ppops.net [127.0.0.1]) by mx0a-00154901.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x7UJbhec098149; Fri, 30 Aug 2019 15:38:13 -0400 Received: from ausxippc101.us.dell.com (ausxippc101.us.dell.com [143.166.85.207]) by mx0a-00154901.pphosted.com with ESMTP id 2uq6k5k6ds-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 Aug 2019 15:38:12 -0400 X-LoopCount0: from 10.166.132.132 X-PREM-Routing: D-Outbound X-IronPort-AV: E=Sophos;i="5.60,346,1549951200"; d="scan'208";a="1292047321" From: To: , , CC: , , , Subject: [PATCH 2/3] ACPI: move ACPI functionality out of r8152 driver Thread-Topic: [PATCH 2/3] ACPI: move ACPI functionality out of r8152 driver Thread-Index: AQHVX2p0618F58/JikuMcbZqKJSvFA== Date: Fri, 30 Aug 2019 19:38:10 +0000 Message-ID: <1763d249345445ada4240eeeb522fc14@AUSX13MPS307.AMER.DELL.COM> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.177.90.68] MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.70,1.0.8 definitions=2019-08-30_07:2019-08-29,2019-08-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 spamscore=0 malwarescore=0 adultscore=0 clxscore=1015 suspectscore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1908300185 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 adultscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 spamscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1908300184 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This 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. Signed-off-by: Charles Hyde Cc: Mario Limonciello Cc: Realtek linux nic maintainers Cc: Rafael J. Wysocki Cc: Len Brown Cc: linux-usb@vger.kernel.org Cc: linux-acpi@vger.kernel.org --- drivers/acpi/Makefile | 1 + drivers/acpi/acpi_mac_passthru.c | 63 ++++++++++++++++++++++++++++++++ drivers/net/usb/r8152.c | 44 ++-------------------- include/acpi/acpi_mac_passthru.h | 29 +++++++++++++++ 4 files changed, 97 insertions(+), 40 deletions(-) create mode 100644 drivers/acpi/acpi_mac_passthru.c create mode 100644 include/acpi/acpi_mac_passthru.h diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 5d361e4e3405..6bc2748f0e00 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -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 diff --git a/drivers/acpi/acpi_mac_passthru.c b/drivers/acpi/acpi_mac_passthru.c new file mode 100644 index 000000000000..37d7e2388c0b --- /dev/null +++ b/drivers/acpi/acpi_mac_passthru.c @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * acpi_mac_passthru.c - 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 +#include +#include +#include +#include + +ACPI_MODULE_NAME("mapt"); + +MODULE_AUTHOR("Charles Hyde"); +MODULE_DESCRIPTION("ACPI MAPT Driver"); +MODULE_LICENSE("GPL"); + +int get_acpi_mac_passthru(char *macAddress) +{ + acpi_status status; + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *obj; + int ret = -EINVAL; + unsigned char buf[6]; + + /* returns _AUXMAC_#AABBCCDDEEFF# */ + status = acpi_evaluate_object(NULL, "\\_SB.AMAC", NULL, &buffer); + obj = (union acpi_object *)buffer.pointer; + if (!ACPI_SUCCESS(status)) + return -ENODEV; + if (obj->type != ACPI_TYPE_BUFFER || obj->string.length != 0x17) { + acpi_info("Invalid buffer for pass-thru MAC addr: (%d, %d)\n", + obj->type, obj->string.length); + goto amacout; + } + if (strncmp(obj->string.pointer, "_AUXMAC_#", 9) != 0 || + strncmp(obj->string.pointer + 0x15, "#", 1) != 0) { + acpi_info("Invalid header when reading pass-thru MAC addr\n"); + goto amacout; + } + ret = hex2bin(buf, obj->string.pointer + 9, 6); + if (!(ret == 0 && is_valid_ether_addr(buf))) { + acpi_info("Invalid MAC for pass-thru MAC addr: %d, %pM\n", + ret, buf); + ret = -EINVAL; + goto amacout; + } + memcpy(macAddress, buf, 6); + acpi_info("Pass-thru MAC addr %pM\n", macAddress); + +amacout: + kfree(obj); + return ret; + +} +EXPORT_SYMBOL_GPL(get_acpi_mac_passthru); diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index eee0f5007ee3..5336c96006cf 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -23,6 +23,7 @@ #include #include #include +#include /* Information for net-next */ #define NETNEXT_VERSION "09" @@ -1178,12 +1179,7 @@ static int rtl8152_set_mac_address(struct net_device *netdev, void *p) */ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa) { - acpi_status status; - struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; - union acpi_object *obj; - int ret = -EINVAL; u32 ocp_data; - unsigned char buf[6]; /* test for -AD variant of RTL8153 */ ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); @@ -1204,39 +1200,7 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa) return -ENODEV; } } - - /* returns _AUXMAC_#AABBCCDDEEFF# */ - status = acpi_evaluate_object(NULL, "\\_SB.AMAC", NULL, &buffer); - obj = (union acpi_object *)buffer.pointer; - if (!ACPI_SUCCESS(status)) - return -ENODEV; - if (obj->type != ACPI_TYPE_BUFFER || obj->string.length != 0x17) { - netif_warn(tp, probe, tp->netdev, - "Invalid buffer for pass-thru MAC addr: (%d, %d)\n", - obj->type, obj->string.length); - goto amacout; - } - if (strncmp(obj->string.pointer, "_AUXMAC_#", 9) != 0 || - strncmp(obj->string.pointer + 0x15, "#", 1) != 0) { - netif_warn(tp, probe, tp->netdev, - "Invalid header when reading pass-thru MAC addr\n"); - goto amacout; - } - ret = hex2bin(buf, obj->string.pointer + 9, 6); - if (!(ret == 0 && is_valid_ether_addr(buf))) { - netif_warn(tp, probe, tp->netdev, - "Invalid MAC for pass-thru MAC addr: %d, %pM\n", - ret, buf); - ret = -EINVAL; - goto amacout; - } - memcpy(sa->sa_data, buf, 6); - netif_info(tp, probe, tp->netdev, - "Using pass-thru MAC addr %pM\n", sa->sa_data); - -amacout: - kfree(obj); - return ret; + return get_acpi_mac_passthru(sa->sa_data); } static int determine_ethernet_addr(struct r8152 *tp, struct sockaddr *sa) @@ -4312,10 +4276,10 @@ static int rtl8152_post_reset(struct usb_interface *intf) if (!tp) return 0; - /* reset the MAC adddress in case of policy change */ + /* reset the MAC address in case of policy change */ if (determine_ethernet_addr(tp, &sa) >= 0) { rtnl_lock(); - dev_set_mac_address (tp->netdev, &sa, NULL); + dev_set_mac_address(tp->netdev, &sa, NULL); rtnl_unlock(); } diff --git a/include/acpi/acpi_mac_passthru.h b/include/acpi/acpi_mac_passthru.h new file mode 100644 index 000000000000..9da3d5b399ac --- /dev/null +++ b/include/acpi/acpi_mac_passthru.h @@ -0,0 +1,29 @@ +/* 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 +#include +//#include +//#include + +#ifdef CONFIG_ACPI + +int get_acpi_mac_passthru(char *macAddress); + +#else + +static inline int get_acpi_mac_passthru(char *macAddress) +{ + return -ENODEV; +} + +#endif From patchwork Fri Aug 30 19:38:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles.Hyde@dellteam.com X-Patchwork-Id: 11124475 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60B6718B7 for ; Fri, 30 Aug 2019 19:38:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3EAF923431 for ; Fri, 30 Aug 2019 19:38:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=dellteam.com header.i=@dellteam.com header.b="s6XPNWvM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728107AbfH3Ti6 (ORCPT ); Fri, 30 Aug 2019 15:38:58 -0400 Received: from mx0b-00154904.pphosted.com ([148.163.137.20]:37112 "EHLO mx0b-00154904.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727246AbfH3Ti6 (ORCPT ); Fri, 30 Aug 2019 15:38:58 -0400 Received: from pps.filterd (m0170396.ppops.net [127.0.0.1]) by mx0b-00154904.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x7UJYttx011662; Fri, 30 Aug 2019 15:38:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dellteam.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=smtpout1; bh=44wTjuXSWMXNrwjFUFwYXstyHmykGsnhGtwggTvTdew=; b=s6XPNWvMcNQRT/oIaPDEEBApTKsWhkkkITSG3SJLMIRtO8VU13/ecXdr13kzM7dheUqw t/BkAz+GKsJvNVviJ2tGZIq2PUwng04Po2kpNMISA7EVwyHsFydBZ+eyPifSoLRxoQfb lX0vuny05bJ60JozjkM3PonenN+awy7ZSYsMNJM1duD5/OLTdYLkYf6U/4GtQbUTO3AG fGJ5sLNT40gzwnHNUsXlc1jmSwNuxU5lrET+aOZTNkLloWgx4QQb8g5nx/lhxqqV7u+O a37nNGniybJlgT/TZTyV4iyN54RyoTnnNjLnmFLotI3RN39l6Xsgjy0ZuRGhUKou8n8P eA== Received: from mx0b-00154901.pphosted.com (mx0b-00154901.pphosted.com [67.231.157.37]) by mx0b-00154904.pphosted.com with ESMTP id 2uk2xjcyjx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 30 Aug 2019 15:38:56 -0400 Received: from pps.filterd (m0089483.ppops.net [127.0.0.1]) by mx0b-00154901.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x7UJbhaS076744; Fri, 30 Aug 2019 15:38:56 -0400 Received: from ausxippc110.us.dell.com (AUSXIPPC110.us.dell.com [143.166.85.200]) by mx0b-00154901.pphosted.com with ESMTP id 2up6pcxvh1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 Aug 2019 15:38:56 -0400 X-LoopCount0: from 10.166.132.128 X-PREM-Routing: D-Outbound X-IronPort-AV: E=Sophos;i="5.60,349,1549951200"; d="scan'208";a="850370706" From: To: , , CC: , , , Subject: [PATCH 3/3] net: cdc_ncm: Add ACPI MAC address pass through functionality Thread-Topic: [PATCH 3/3] net: cdc_ncm: Add ACPI MAC address pass through functionality Thread-Index: AQHVX2qOXZfzpNrp7kuN2ddtBmn+Zg== Date: Fri, 30 Aug 2019 19:38:54 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.177.90.68] MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.70,1.0.8 definitions=2019-08-30_07:2019-08-29,2019-08-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 impostorscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 phishscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 adultscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1908300185 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 adultscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 spamscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1908300184 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 Cc: Mario Limonciello Cc: Oliver Neukum Cc: Rafael J. Wysocki Cc: Len Brown 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 #include #include +#include #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, };