Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2663509rdb; Fri, 22 Sep 2023 05:25:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWvMIeCgJTC2fHMylZFPhi9R3eqSVfv3ihvilOzfDmalB5QOkfg7FMD1VHSGZxDl1VPSJa X-Received: by 2002:a17:902:ec81:b0:1c3:6705:bcee with SMTP id x1-20020a170902ec8100b001c36705bceemr10169782plg.57.1695385541597; Fri, 22 Sep 2023 05:25:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695385541; cv=none; d=google.com; s=arc-20160816; b=nqIa9LITVMKekObZ/lO7P1NNmRVKXH8a50vTTuFOOHH0GKJ9oRXzcHAFLHIJ2GApD1 FiLMLrGhT5ObcV9hwp58Ml8B1zjKzH8PKGU4wVUFcEA8BjNmOKnNTZZX4Y6RcCKnf428 vMoWWsdNAtMEu3ZHfexUIZgy8Yrp/9P3ZasiaQuLwCjep9VzSMbiFF/l4U0TAZPQ4OaV 7ZRk8139lqcQgmx/Usn1HGrAB+s2NBPUiOfDKJ5R+V56O2h5yVs49LI6g1XnFzBuPUE7 9Gj/a/wVPak92kpxtExcDpnWGjMUowdH/L4Rf/yfy5+GQnFMUDq/5Q4OuQ4JlxPL4RYW /w/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=81zpRqWrPzh13AAVBRTZXFAMZnmZUZ6MT9IC/NumHYw=; fh=aaBeJ2HmOA2jsIuDSW9KhQ1qhFXkvQ7iPyaAqDoN6Vc=; b=odO1WSl9r7YgpdnftZj160OOxrlIsCT1oBoqWxSVhfjyjO9YL9gdQcQHnVLfBLArNx oRDUYGGDEG+iwLmLrPNnAXXGp4vF/S/XlQOJwpkV+u9pBM826IyDkSr+6Un4g0IB2Uee qO3hxBfW7wZNhbfN/OGxMNRqC4H7UqK8xoqwZuSOHoQ/POcC9RJZJk9yTSHAMgrnPk/2 1hwlsMvsDkPanlgHV5CX1s61MDCPtEMOvrWXT1hcoIGqGxTLb3c4X7yCHqdsKB1G9aUl cLA4LgYzYEyvEfT8QG7zoRzIxGserXFImrsKYDKRhLnjfZVMILgXw/tiamX1fxJCq6m9 UuGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=E5gr45hR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id o7-20020a170902d4c700b001c57c952622si3603519plg.446.2023.09.22.05.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 05:25:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=E5gr45hR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id EA9FB8374698; Fri, 22 Sep 2023 01:52:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232356AbjIVIwO (ORCPT + 99 others); Fri, 22 Sep 2023 04:52:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231814AbjIVIwN (ORCPT ); Fri, 22 Sep 2023 04:52:13 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF4A9A9; Fri, 22 Sep 2023 01:52:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695372727; x=1726908727; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=909qfSZJj9g30Z44iivYF+PQog17rbjHkc3mDJyIeVA=; b=E5gr45hRlzMJEmrraVyRfT/yz9tH4lwuKirPsJ1qB30NsP3+E+0UNmlr 3A4lTKprTlDN1i8uUF8JWnzlnAPRzlDjtX9EuzoUMbD7mttr/2RakgYSa Y2fBfJhLZsKA9VpMJETS8gPoKgD+itlejaGnS4koBLcnrr2uJnL2UH8fZ Ouf1Mr2ylIzqQp3qcJphk5ZGXaMVG+4nW9BJSVO2sEVaRcZoQ2eAMtgo0 PHoIjU2pu5TV/aBMQq+M0ztBhXca0YzS0V1Jvpm1k0MLvxDqWYiRMbrWW S5lYoUKvWHGwJVI/6Lc5IqPQK+qhuNaUgafnBxwiZOoYdmn3yJeXyAvAB w==; X-IronPort-AV: E=McAfee;i="6600,9927,10840"; a="447258904" X-IronPort-AV: E=Sophos;i="6.03,167,1694761200"; d="scan'208";a="447258904" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 01:52:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10840"; a="837654871" X-IronPort-AV: E=Sophos;i="6.03,167,1694761200"; d="scan'208";a="837654871" Received: from rblanarx-mobl.ger.corp.intel.com ([10.252.52.48]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 01:52:00 -0700 Date: Fri, 22 Sep 2023 11:51:54 +0300 (EEST) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Fernando Eckhardt Valle cc: Hans de Goede , Mark Pearson , corbet@lwn.net, hmh@hmh.eng.br, markgross@kernel.org, linux-doc@vger.kernel.org, LKML , ibm-acpi-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org Subject: Re: [PATCH v4] platform/x86: thinkpad_acpi: sysfs interface to auxmac In-Reply-To: <20230921143622.72387-1-fevalle@ipt.br> Message-ID: <946285e6-6064-4084-a1a7-f5ba7dea3e7d@linux.intel.com> References: <20230921143622.72387-1-fevalle@ipt.br> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 22 Sep 2023 01:52:16 -0700 (PDT) On Thu, 21 Sep 2023, Fernando Eckhardt Valle wrote: > Newer Thinkpads have a feature called MAC Address Pass-through. > This patch provides a sysfs interface that userspace can use > to get this auxiliary mac address. > > Signed-off-by: Fernando Eckhardt Valle > --- > Changes in v4: > - strscpy() in all string copies. > Changes in v3: > - Added null terminator to auxmac string when copying auxiliary > mac address value. > Changes in v2: > - Added documentation. > - All handling of the auxmac value is done in the _init function. > --- > .../admin-guide/laptops/thinkpad-acpi.rst | 20 +++++ > drivers/platform/x86/thinkpad_acpi.c | 79 +++++++++++++++++++ > 2 files changed, 99 insertions(+) > > diff --git a/Documentation/admin-guide/laptops/thinkpad-acpi.rst b/Documentation/admin-guide/laptops/thinkpad-acpi.rst > index e27a1c3f6..98d304010 100644 > --- a/Documentation/admin-guide/laptops/thinkpad-acpi.rst > +++ b/Documentation/admin-guide/laptops/thinkpad-acpi.rst > @@ -53,6 +53,7 @@ detailed description): > - Lap mode sensor > - Setting keyboard language > - WWAN Antenna type > + - Auxmac > > A compatibility table by model and feature is maintained on the web > site, http://ibm-acpi.sf.net/. I appreciate any success or failure > @@ -1511,6 +1512,25 @@ Currently 2 antenna types are supported as mentioned below: > The property is read-only. If the platform doesn't have support the sysfs > class is not created. > > +Auxmac > +------ > + > +sysfs: auxmac > + > +Some newer Thinkpads have a feature called MAC Address Pass-through. This > +feature is implemented by the system firmware to provide a system unique MAC, > +that can override a dock or USB ethernet dongle MAC, when connected to a > +network. This property enables user-space to easily determine the MAC address > +if the feature is enabled. > + > +The values of this auxiliary MAC are: > + > + cat /sys/devices/platform/thinkpad_acpi/auxmac > + > +If the feature is disabled, the value will be 'disabled'. > + > +This property is read-only. > + > Adaptive keyboard > ----------------- > > diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c > index d70c89d32..f430cc9ed 100644 > --- a/drivers/platform/x86/thinkpad_acpi.c > +++ b/drivers/platform/x86/thinkpad_acpi.c > @@ -10785,6 +10785,80 @@ static struct ibm_struct dprc_driver_data = { > .name = "dprc", > }; > > +/* > + * Auxmac > + * > + * This auxiliary mac address is enabled in the bios through the > + * MAC Address Pass-through feature. In most cases, there are three > + * possibilities: Internal Mac, Second Mac, and disabled. > + * > + */ > + > +#define AUXMAC_LEN 12 > +#define AUXMAC_START 9 > +#define AUXMAC_STRLEN 22 > +#define AUXMAC_BEGIN_MARKER 8 > +#define AUXMAC_END_MARKER 21 > + > +static char auxmac[AUXMAC_LEN + 1]; > + > +static int auxmac_init(struct ibm_init_struct *iibm) > +{ > + acpi_status status; > + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; > + union acpi_object *obj; > + > + status = acpi_evaluate_object(NULL, "\\MACA", NULL, &buffer); > + > + if (ACPI_FAILURE(status)) > + return -ENODEV; > + > + obj = buffer.pointer; > + > + if (obj->type != ACPI_TYPE_STRING || obj->string.length != AUXMAC_STRLEN) { > + pr_info("Invalid buffer for MAC address pass-through.\n"); > + strscpy(auxmac, "unavailable", AUXMAC_LEN); > + goto auxmacinvalid; > + } > + > + if (obj->string.pointer[AUXMAC_BEGIN_MARKER] != '#' || > + obj->string.pointer[AUXMAC_END_MARKER] != '#') { > + pr_info("Invalid header for MAC address pass-through.\n"); > + strscpy(auxmac, "unavailable", AUXMAC_LEN); > + goto auxmacinvalid; > + } > + > + if (strncmp(obj->string.pointer + AUXMAC_START, "XXXXXXXXXXXX", AUXMAC_LEN) != 0) > + strscpy(auxmac, obj->string.pointer + AUXMAC_START, AUXMAC_LEN + 1); Okay, I wasn't expecting this change as this relies on the nul termination by strscpy() since the original buffer does not have one but the # character there. But I guess it isn't harmful either. > + else > + strscpy(auxmac, "disabled", AUXMAC_START); AUXMAC_START is an offset ??? It should be AUXMAC_LEN. > + > +auxmacinvalid: > + kfree(obj); > + return 0; I only now realized there are two gotos to auxmacinvalid. Therefore, I'd do this instead: free: kfree(obj); return 0; auxmacinvalid: strscpy(auxmac, "unavailable", AUXMAC_LEN); goto free; I'm sorry about my incorrect suggestion the last time. > +} > + > +static struct ibm_struct auxmac_data = { > + .name = "auxmac", > +}; > + > +static ssize_t auxmac_show(struct device *dev, > + struct device_attribute *attr, > + char *buf) > +{ > + return sysfs_emit(buf, "%s\n", auxmac); > +} > +static DEVICE_ATTR_RO(auxmac); > + > +static struct attribute *auxmac_attributes[] = { > + &dev_attr_auxmac.attr, > + NULL > +}; > + > +static const struct attribute_group auxmac_attr_group = { > + .attrs = auxmac_attributes, > +}; > + > /* --------------------------------------------------------------------- */ > > static struct attribute *tpacpi_driver_attributes[] = { > @@ -10843,6 +10917,7 @@ static const struct attribute_group *tpacpi_groups[] = { > &proxsensor_attr_group, > &kbdlang_attr_group, > &dprc_attr_group, > + &auxmac_attr_group, > NULL, > }; > > @@ -11414,6 +11489,10 @@ static struct ibm_init_struct ibms_init[] __initdata = { > .init = tpacpi_dprc_init, > .data = &dprc_driver_data, > }, > + { > + .init = auxmac_init, > + .data = &auxmac_data, > + }, > }; > > static int __init set_ibm_param(const char *val, const struct kernel_param *kp) > -- i.