From patchwork Fri Aug 23 22:28:24 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: 11112439 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 9863E1399 for ; Fri, 23 Aug 2019 22:28:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 630C82166E for ; Fri, 23 Aug 2019 22:28:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=dellteam.com header.i=@dellteam.com header.b="jJe9mrBK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406250AbfHWW2c (ORCPT ); Fri, 23 Aug 2019 18:28:32 -0400 Received: from mx0b-00154904.pphosted.com ([148.163.137.20]:58216 "EHLO mx0b-00154904.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727370AbfHWW21 (ORCPT ); Fri, 23 Aug 2019 18:28:27 -0400 Received: from pps.filterd (m0170395.ppops.net [127.0.0.1]) by mx0b-00154904.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x7NMJWWW031775; Fri, 23 Aug 2019 18:28:26 -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=+DSeAv18ky6dsAVbGLZZBh5nxsQn5QSjOtdXZONH7kQ=; b=jJe9mrBK24KLRvtqtw8b5ObvhnDFYykCNXzFf9UHnu2jHaq9ew0xqIVy5XNJFAr4GkYC fSH2melRj/eU4mlb18LI6GO5MzA59iB85IsObCqiW5UUBGDLbfhFkunWUlyZQY1NKZUU mOQSsXhpM4RaWBtmKy6upeJ3jcYDd4Jpb3QN/NOMiV0XH/mECKe9zzwSGv3sYsFX1pje btWoeX3uXDVghxfyCV3GqvIuo6WxSKTvNIsOt6VpTVrA+G9nqXj5ci3BhDFIE5ilRGYj 7cvFxPoX5ZKKqJzktV8yw7c2kBIUaDk9gS2XMmDubVCm3uDXSu8CtstSv+18iXvWlxMg BA== Received: from mx0b-00154901.pphosted.com (mx0b-00154901.pphosted.com [67.231.157.37]) by mx0b-00154904.pphosted.com with ESMTP id 2ujfchad9u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Aug 2019 18:28:26 -0400 Received: from pps.filterd (m0144102.ppops.net [127.0.0.1]) by mx0b-00154901.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x7NMMp9L096938; Fri, 23 Aug 2019 18:28:26 -0400 Received: from ausxippc110.us.dell.com (AUSXIPPC110.us.dell.com [143.166.85.200]) by mx0b-00154901.pphosted.com with ESMTP id 2ujm4b3x60-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2019 18:28:26 -0400 X-LoopCount0: from 10.166.132.129 X-PREM-Routing: D-Outbound X-IronPort-AV: E=Sophos;i="5.60,349,1549951200"; d="scan'208";a="847527142" From: To: CC: , , , Subject: [RFC 2/3] ACPI: move ACPI functionality out of r8152 driver Thread-Topic: [RFC 2/3] ACPI: move ACPI functionality out of r8152 driver Thread-Index: AQHVWgITZZ4dwXs8CES9WUAD0zcVmA== Date: Fri, 23 Aug 2019 22:28:24 +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.49.166] MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-08-23_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908230211 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908230211 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: linux-usb@vger.kernel.org Cc: linux-acpi@vger.kernel.org --- drivers/net/usb/r8152.c | 44 +++-------------------- include/acpi/acpi_mac_passthru.h | 16 +++++++++ lib/Makefile | 3 +- lib/acpi_mac_passthru.c | 61 ++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 41 deletions(-) create mode 100644 include/acpi/acpi_mac_passthru.h create mode 100644 lib/acpi_mac_passthru.c diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 0cc03a9ff545..b1dba3400b74 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" @@ -1175,12 +1176,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); @@ -1201,39 +1197,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(&tp->intf->dev, sa); } static int determine_ethernet_addr(struct r8152 *tp, struct sockaddr *sa) @@ -4309,10 +4273,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..fb2b114c2765 --- /dev/null +++ b/include/acpi/acpi_mac_passthru.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2019 Dell Technology. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + */ + +#include +#include +#include +#include + +int get_acpi_mac_passthru(struct device *dev, struct sockaddr *sa); + diff --git a/lib/Makefile b/lib/Makefile index 29c02a924973..a902bec0ac65 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -35,7 +35,8 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ flex_proportions.o ratelimit.o show_mem.o \ is_single_threaded.o plist.o decompress.o kobject_uevent.o \ earlycpio.o seq_buf.o siphash.o dec_and_lock.o \ - nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o + nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o \ + acpi_mac_passthru.o lib-$(CONFIG_PRINTK) += dump_stack.o lib-$(CONFIG_MMU) += ioremap.o diff --git a/lib/acpi_mac_passthru.c b/lib/acpi_mac_passthru.c new file mode 100644 index 000000000000..832596433592 --- /dev/null +++ b/lib/acpi_mac_passthru.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2019 Dell Technology. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + */ + +#include +#include + +int get_acpi_mac_passthru(struct device *dev, struct sockaddr *sa) +{ +#ifdef CONFIG_ACPI + 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) { + dev_warn(dev, + "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) { + dev_warn(dev, + "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))) { + dev_warn(dev, + "Invalid MAC for pass-thru MAC addr: %d, %pM\n", + ret, buf); + ret = -EINVAL; + goto amacout; + } + memcpy(sa->sa_data, buf, 6); + dev_info(dev, "Pass-thru MAC addr %pM\n", sa->sa_data); + +amacout: + kfree(obj); + return ret; + +#else /* !CONFIG_ACPI */ + (void)dev; + (void)sa; + + return -ENODEV; +#endif +} +EXPORT_SYMBOL_GPL(get_acpi_mac_passthru);