Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3987991pxb; Tue, 25 Jan 2022 00:47:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+1wC/Q/eKzXfXB3EV9+OEKczlmmpjvGE7rM0rFdh9OpJPy4lB9Odm6tVcFCA7ES3MPGTF X-Received: by 2002:a17:902:ecd2:b0:14b:2fb9:7225 with SMTP id a18-20020a170902ecd200b0014b2fb97225mr13321668plh.46.1643100439645; Tue, 25 Jan 2022 00:47:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643100439; cv=none; d=google.com; s=arc-20160816; b=MCm/ZBGAND5NnLzIEEcINp1xd07/gqkGNtJTACp4DfopaLXPVUXcazKDqPlCtDBLNc sOHD+JiKVo4TZcKVa7vH925jvt3uFUawesrlY6cprzWmRqdB4gS3pJDtwgDu3An5HHrZ PDo4HJBS+J5gPWfGxRfK9cmrJ9eF1TqTkaT6T+x3QUvjYu3bvmfwQNVCE7HMzCImBHCZ usS6VrO0rePGKIIn15I0At9CEMhCoPuvNHx3EKRXmvFDLK9V20EjBgu9DovfIky/iFqs NFPtBDTV7Ui09hX6Q7Dk+z2F/Jx75h85aDq/2MlXH8LtMjK+frveSYS1qR6seMq3zHPs mT6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=q+psO80QgAcQ7S/RNthxNYrhw/GdU0DWqBu0gazK9G0=; b=PsUzCS0ZhB7F6TyE9ok7yu4/dc78A27K69+zGU3Rr6YwDIb29zBEU5bl85sdocxOAz qzOm4mNnjWG5EX4G2xYH17k/O+K/GWWsp+ScWrH2F1yarJrCIfR9vw5t4jf2BOAcjgNc P69MT7Fp3k5G2mguKKzx+A1deuu413MEfwBZit+dPfrjRLcrc+oWG7UmsFNecB0Na903 2X7sfQ0PRwM0Rp1dedljXEMtbMkUGGRRiTOB1bxQU8a5rPkj75eRUCBf5BvLNpUKXl9i HSMtm5F5kFy7rp9mqzVDNZtx/MrSkKMngS+ONOkJ/+pGIV/M/8c7vNWxd+9mooCoCqMl CENw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=krq09NW1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n193si12911060pfd.121.2022.01.25.00.47.08; Tue, 25 Jan 2022 00:47:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=krq09NW1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1319144AbiAYDIB (ORCPT + 99 others); Mon, 24 Jan 2022 22:08:01 -0500 Received: from mga17.intel.com ([192.55.52.151]:60177 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S3420300AbiAYCXu (ORCPT ); Mon, 24 Jan 2022 21:23:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643077430; x=1674613430; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Wi7YgSoegjpyU0XA1btyBrAIx4jskMfW08fhaWOcJVs=; b=krq09NW1dNNUVqylIGoF5Kz87dgHbSwiWlpYF8a5cA0gyksrf59283c4 eIpAw7v77eQ1D3lFXyVooaGVI6FyHKSYdPRiQkWnzDC3jgHo18eeYGw6B OO12OopUWO3xu7Km9ONBJ/ck1dqV/U4Je4pzEzMx5pNoYzOzrjHRjIROF Rs8vPOoTmNHmF3unseV7vSXrFidWpJVTGExeCYgdzgV4fLn8iE3eY49oe arJHRbCUoo3gqrVmJTbmL6Ob5UUxVEL8ueA/8JOmTllOuIIbIvT0aC9NR kOOHuwxhJED90hNh34qdfDe+kh2WXqJcRra4ysQYkIyJNgkRj9nOHSjIv w==; X-IronPort-AV: E=McAfee;i="6200,9189,10237"; a="226860221" X-IronPort-AV: E=Sophos;i="5.88,313,1635231600"; d="scan'208";a="226860221" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2022 17:14:52 -0800 X-IronPort-AV: E=Sophos;i="5.88,313,1635231600"; d="scan'208";a="532265894" Received: from kerguder-mobl.ger.corp.intel.com (HELO localhost) ([10.249.158.133]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2022 17:14:44 -0800 From: Iwona Winiarska To: linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, Greg Kroah-Hartman Cc: devicetree@vger.kernel.org, linux-aspeed@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Rob Herring , Joel Stanley , Andrew Jeffery , Jean Delvare , Guenter Roeck , Arnd Bergmann , Olof Johansson , Jonathan Corbet , Borislav Petkov , Pierre-Louis Bossart , Tony Luck , Andy Shevchenko , Dan Williams , Randy Dunlap , Zev Weiss , David Muller , Dave Hansen , Billy Tsai , Iwona Winiarska Subject: [PATCH v6 07/13] peci: Add sysfs interface for PECI bus Date: Tue, 25 Jan 2022 02:10:58 +0100 Message-Id: <20220125011104.2480133-8-iwona.winiarska@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220125011104.2480133-1-iwona.winiarska@intel.com> References: <20220125011104.2480133-1-iwona.winiarska@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org PECI devices may not be discoverable at the time when PECI controller is being added (e.g. BMC can boot up when the Host system is still in S5). Since we currently don't have the capabilities to figure out the Host system state inside the PECI subsystem itself, we have to rely on userspace to do it for us. In the future, PECI subsystem may be expanded with mechanisms that allow us to avoid depending on userspace interaction (e.g. CPU presence could be detected using GPIO, and the information on whether it's discoverable could be obtained over IPMI). Unfortunately, those methods may ultimately not be available (support will vary from platform to platform), which means that we still need platform independent method triggered by userspace. Signed-off-by: Iwona Winiarska --- Documentation/ABI/testing/sysfs-bus-peci | 16 +++++ drivers/peci/Makefile | 2 +- drivers/peci/core.c | 3 +- drivers/peci/device.c | 1 + drivers/peci/internal.h | 5 ++ drivers/peci/sysfs.c | 82 ++++++++++++++++++++++++ 6 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-peci create mode 100644 drivers/peci/sysfs.c diff --git a/Documentation/ABI/testing/sysfs-bus-peci b/Documentation/ABI/testing/sysfs-bus-peci new file mode 100644 index 000000000000..56c2b2216bbd --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-peci @@ -0,0 +1,16 @@ +What: /sys/bus/peci/rescan +Date: July 2021 +KernelVersion: 5.15 +Contact: Iwona Winiarska +Description: + Writing a non-zero value to this attribute will + initiate scan for PECI devices on all PECI controllers + in the system. + +What: /sys/bus/peci/devices/-/remove +Date: July 2021 +KernelVersion: 5.15 +Contact: Iwona Winiarska +Description: + Writing a non-zero value to this attribute will + remove the PECI device and any of its children. diff --git a/drivers/peci/Makefile b/drivers/peci/Makefile index c5f9d3fe21bb..917f689e147a 100644 --- a/drivers/peci/Makefile +++ b/drivers/peci/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only # Core functionality -peci-y := core.o request.o device.o +peci-y := core.o request.o device.o sysfs.o obj-$(CONFIG_PECI) += peci.o # Hardware specific bus drivers diff --git a/drivers/peci/core.c b/drivers/peci/core.c index c3361e6e043a..e993615cf521 100644 --- a/drivers/peci/core.c +++ b/drivers/peci/core.c @@ -29,7 +29,7 @@ struct device_type peci_controller_type = { .release = peci_controller_dev_release, }; -static int peci_controller_scan_devices(struct peci_controller *controller) +int peci_controller_scan_devices(struct peci_controller *controller) { int ret; u8 addr; @@ -162,6 +162,7 @@ EXPORT_SYMBOL_NS_GPL(devm_peci_controller_add, PECI); struct bus_type peci_bus_type = { .name = "peci", + .bus_groups = peci_bus_groups, }; static int __init peci_init(void) diff --git a/drivers/peci/device.c b/drivers/peci/device.c index 2b3a2d893aaf..d10ed1cfcd48 100644 --- a/drivers/peci/device.c +++ b/drivers/peci/device.c @@ -116,5 +116,6 @@ static void peci_device_release(struct device *dev) } struct device_type peci_device_type = { + .groups = peci_device_groups, .release = peci_device_release, }; diff --git a/drivers/peci/internal.h b/drivers/peci/internal.h index 57d11a902c5d..978e12c8e1d3 100644 --- a/drivers/peci/internal.h +++ b/drivers/peci/internal.h @@ -8,6 +8,7 @@ #include struct peci_controller; +struct attribute_group; struct peci_device; struct peci_request; @@ -19,12 +20,16 @@ struct peci_request *peci_request_alloc(struct peci_device *device, u8 tx_len, u void peci_request_free(struct peci_request *req); extern struct device_type peci_device_type; +extern const struct attribute_group *peci_device_groups[]; int peci_device_create(struct peci_controller *controller, u8 addr); void peci_device_destroy(struct peci_device *device); extern struct bus_type peci_bus_type; +extern const struct attribute_group *peci_bus_groups[]; extern struct device_type peci_controller_type; +int peci_controller_scan_devices(struct peci_controller *controller); + #endif /* __PECI_INTERNAL_H */ diff --git a/drivers/peci/sysfs.c b/drivers/peci/sysfs.c new file mode 100644 index 000000000000..db9ef05776e3 --- /dev/null +++ b/drivers/peci/sysfs.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (c) 2021 Intel Corporation + +#include +#include +#include + +#include "internal.h" + +static int rescan_controller(struct device *dev, void *data) +{ + if (dev->type != &peci_controller_type) + return 0; + + return peci_controller_scan_devices(to_peci_controller(dev)); +} + +static ssize_t rescan_store(struct bus_type *bus, const char *buf, size_t count) +{ + bool res; + int ret; + + ret = kstrtobool(buf, &res); + if (ret) + return ret; + + if (!res) + return count; + + ret = bus_for_each_dev(&peci_bus_type, NULL, NULL, rescan_controller); + if (ret) + return ret; + + return count; +} +static BUS_ATTR_WO(rescan); + +static struct attribute *peci_bus_attrs[] = { + &bus_attr_rescan.attr, + NULL +}; + +static const struct attribute_group peci_bus_group = { + .attrs = peci_bus_attrs, +}; + +const struct attribute_group *peci_bus_groups[] = { + &peci_bus_group, + NULL +}; + +static ssize_t remove_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct peci_device *device = to_peci_device(dev); + bool res; + int ret; + + ret = kstrtobool(buf, &res); + if (ret) + return ret; + + if (res && device_remove_file_self(dev, attr)) + peci_device_destroy(device); + + return count; +} +static DEVICE_ATTR_IGNORE_LOCKDEP(remove, 0200, NULL, remove_store); + +static struct attribute *peci_device_attrs[] = { + &dev_attr_remove.attr, + NULL +}; + +static const struct attribute_group peci_device_group = { + .attrs = peci_device_attrs, +}; + +const struct attribute_group *peci_device_groups[] = { + &peci_device_group, + NULL +}; -- 2.31.1