From patchwork Mon Mar 3 10:58:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13998575 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2088.outbound.protection.outlook.com [40.107.212.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A734E1EF0AA; Mon, 3 Mar 2025 10:59:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999576; cv=fail; b=nodMxnI5x/Lmi++eHUH8sXSQ5cwCZ+IuUO8WeGlKZbTu6uepCIArjTgyL1/SRXGDZM7GDLu2e05pcvqheszRVeE7+4p2mS2OBN7NLoUDkfPUA32F+Fdq5LjbrEwEGV0qqSPuOl14ee0C9qws3mAt/DnI/bfcQUDPp9YWKyM8dXQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999576; c=relaxed/simple; bh=Pxi9DQYAtr8pjkcL49+BcaKCU3FHH2PIwalsjdxC054=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XiGWyPJqTYKwB2iac+6zXbO/qw+8i3IHpu+Jmp/aFgd0+tJr1aaw2poaQk0xhWvl0qDhFn3C6nTd3R+OGosbomi3mrYtFsrD6suYaJDyTePr1P5VoHoewYQnMyrQH54PdLIPPMzN2DkwoKgsGslZ/KyMvBQcmLir1h4euIVrO5g= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=ejT9S99i; arc=fail smtp.client-ip=40.107.212.88 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="ejT9S99i" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ywu1ql4mOFfzCHONrMSpr4YvifuBTArnxOQQOT5/aR5sYsBxSUoQk934RWhabxpnYIOXV3r914LY3w6gZn2sjsRJD1UoPb1/XrtwHDzvfDLN7n9gPTq82kJCYMmc8FHxYW96kY+Nap2WaZ8xyofuZ3Lhn6gzeMUWk7FvNiMqiWbxLr/hJkat7SUEt48VLfl8OCRE4aRLjYa1/v4vBujeWusCtQcRM5UQRrb5d6GNnPFdOGOM4mM/WAs7W6ckpgsLudsWJVJR2rgO4R7MI0YhOa9EuWm0o3fOoR7zWQQXzPJa+LwDTaTDEhN/4AfN7yrFVbDXzk0Un+UXz3TXzROIog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=24ZoBzqCEpp5mLa6zgWZWDHGF69laEr7zcXx0e9VNV8=; b=AC2dygAOP7YUGJuMxrSinKrGjy8P3AMNDd0E4XGjO5cR7isqogOR2xKPbMN83ZzNCWvOM1pt6RN6naZCAP77JvGKTqGXdll7VDO+H6DHLfFWyBgVdGcvE9/lE2cUFCh5tmjpxBB9HBdCfq1y8DHI3CgMbYwbF8VZII36nXCgv7U2cT3daJscxNImnCOIxYGBVPRA78eVovRT+m0JXdGZqmKnbF31jvaRkABGuauB+E0uAxkpg9dZsbjv7AhfKLxc7C+gaFCoUnrfp3jYqk7lOKhZB1y8gbZg6wEzusk9WQdYiXChLLa/wt8lkLGpBjswglO5N8QCIU47mbWYrtju1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=24ZoBzqCEpp5mLa6zgWZWDHGF69laEr7zcXx0e9VNV8=; b=ejT9S99iw3MzboCW3VHc+hDubznC41Y9eK92Ia6kkk/5nRW9PIdR+0beAbNwg6g56aOPr4Uhvnrr/uMbiOL+c8zigFono28NcXoaKmGAcSqRWvx3HxuLZpoKrOxCXhSQaaMmYLf7czbJp4RYmjFHRA1R20mnxKOE4AXpx+0UH1c= Received: from SA9P223CA0028.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::33) by CH3PR12MB8354.namprd12.prod.outlook.com (2603:10b6:610:12f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.25; Mon, 3 Mar 2025 10:59:29 +0000 Received: from SN1PEPF00036F3F.namprd05.prod.outlook.com (2603:10b6:806:26:cafe::c7) by SA9P223CA0028.outlook.office365.com (2603:10b6:806:26::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8489.23 via Frontend Transport; Mon, 3 Mar 2025 10:59:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F3F.mail.protection.outlook.com (10.167.248.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Mon, 3 Mar 2025 10:59:29 +0000 Received: from amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 3 Mar 2025 04:59:25 -0600 From: Akshay Gupta To: , CC: , , , , , , , Akshay Gupta Subject: [PATCH v5 01/11] hwmon/misc: amd-sbi: Move core sbrmi from hwmon to misc Date: Mon, 3 Mar 2025 10:58:52 +0000 Message-ID: <20250303105902.215009-2-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250303105902.215009-1-akshay.gupta@amd.com> References: <20250303105902.215009-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3F:EE_|CH3PR12MB8354:EE_ X-MS-Office365-Filtering-Correlation-Id: caf5cb61-4123-4829-41cd-08dd5a42786a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: 6/p6PXIkZbdY1/l2gNGK5/+Cit+xTGvZ6rUioLZ66SKIkelWWY2CsST+Ng5UTDeuPFEiARpldNSCn0jtOXEtyimBdBNz7NCUz6+/sqrbqy7tQKI32wF/4hSed7+97/hzU0oaHsXqzllBWBKpm9jXMPr7SXvfaIwiruREXf76nrKAzFh/LThSYJn6BpeoXffsywV4YxaS/0t4UUkKXrrYdPvbJrg2YKr8JKIOBO6CooAsJkynrk28oH1hBWLVxcZ2wPxzmpzETDIDb2oIhlYn1ry5W8ww2X+pvaaV+sR4kLcXpEc6MTKx5hao6nYy/ImbXzYuYc+oZm3tOHYeivwBQycgOI1aqiwIeZx1c9jB6c7iv4eevilAifoWf1xOdQPWcXi5mMRYXFJOYdwSGUBdsJTj+bysoKx6xarga0KDLTUscfUi28aWzLPDe0pE1fBiafrJP8Bjy100WvurqQa4LRiAyrQJFziBkh5mvJ6Nbje4iaSz8Rf8RpR7j/b26ChS7mcVvEmd0i9urIxgPcOBz7sAg640Ii5TjkcfFXtVvDEKmcs/fC+oJMZLkLaw8uzbU9fVcwnKzYz8469q+VSPGUJonUEO/LN1G5xrdCtjWuHEwE34TVx4WmC9pTy6M0Ao6N/zHa87EVODX7tc8qjFjcIELSpB+4I+p3V/2NVJVAfDGGZqxMlvNORSjIvtzJX275WLvMDnbKs/alDMSGONcZupeB8cYSNw53JsfWMrpOxwB9Etvv5sCUpHmzO+blEoYQnPNznJaNReCE/dHPpEiviLfuycNKMkrTG4Zo1xQjyvsXdnDvVFPhzmNr6whx1ZfuyhQ3ywsqufxpWZo3un0AyIoNU2rlRXyVZoR5M6RWoE51L5xkVVhi9krRErPxl6ls/aRafVpIi6h1I6LyPAIINNsGiYAg5N38awcmUPDWt9+G7VdlP1FB89HzlfZAzJKun0gR1tnHY4WohvFkFbwbiUFQ+Qg18tq/LtWi/kLiKGpHZ7P1/C7ixN/sB850yrizgXy1c34olMW90/paBSDgCAXg+S0FXqQR7FnYChAmPvwd4drqudiM+rixb6+cWZtLRDgZoB+gvX7I9dn0YBLzjlB9/rb2YHk1CYI8ZEJ/MJKLmnn9AfTAzXB9UD/698q/+Si9QGDGtnS98kK39PaEtG2mmcGQmzKrQxRk2MpPBwDiC24AAYrYa3XTWQb2nHzJFOVt9X7BYBhqMypllSmJqSa5+LsmYczAk4Kc+xLNUM/ICN7xJTaeJvHVNtttAGEmUWbRio3SqIdWAptBqAr5RAzJTzSb1uv14CK8r4auu5uBmqSAaLbEvhTd2TNErgPz1lPiSGeKLeTx2g2z3uVjmgVGFyFZiiC+FrloJEJNykpwJLJ0VOGoczSMt/N6hkmBx8HEvMSDJLe/I4M3kaV4DNjuB5N/nkOGpxXEE2usL0a/fdN0+byfcEUOYb1OcHkFSa8TG6K1/8ZaGmatg4OTIAql9kTr+x+2eRfm3kXkg= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2025 10:59:29.0111 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: caf5cb61-4123-4829-41cd-08dd5a42786a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F3F.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8354 This is done to support other functionality provided by the SBRMI, which does not fit in the hwmon subsystem. Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta Acked-by: Guenter Roeck --- Changes since v4: - Split in 3 new patches as per review comments 1. Bring drivers/hwmon to drivers/misc/amd-sbi 2. Move out the core functionality 3. Move out the hwmon functionality. Changes since v3: Rebase the patch Added Acked-by Changes since v2: Rebase the patch Changes since v1: - File name update - Add hwmon sensor registration in this patch - Update Copyright year drivers/hwmon/Kconfig | 10 ---------- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/amd-sbi/Kconfig | 9 +++++++++ drivers/misc/amd-sbi/Makefile | 2 ++ drivers/{hwmon => misc/amd-sbi}/sbrmi.c | 0 6 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 drivers/misc/amd-sbi/Kconfig create mode 100644 drivers/misc/amd-sbi/Makefile rename drivers/{hwmon => misc/amd-sbi}/sbrmi.c (100%) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 4cbaba15d86e..5b53137f8b89 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1866,16 +1866,6 @@ config SENSORS_SBTSI This driver can also be built as a module. If so, the module will be called sbtsi_temp. -config SENSORS_SBRMI - tristate "Emulated SB-RMI sensor" - depends on I2C - help - If you say yes here you get support for emulated RMI - sensors on AMD SoCs with APML interface connected to a BMC device. - - This driver can also be built as a module. If so, the module will - be called sbrmi. - config SENSORS_SHT15 tristate "Sensiron humidity and temperature sensors. SHT15 and compat." depends on GPIOLIB || COMPILE_TEST diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 56bc72c7ce4a..b2792b9664ba 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -649,4 +649,5 @@ source "drivers/misc/uacce/Kconfig" source "drivers/misc/pvpanic/Kconfig" source "drivers/misc/mchp_pci1xxxx/Kconfig" source "drivers/misc/keba/Kconfig" +source "drivers/misc/amd-sbi/Kconfig" endmenu diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 545aad06d088..fde23b0b4f0e 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -75,3 +75,4 @@ lan966x-pci-objs := lan966x_pci.o lan966x-pci-objs += lan966x_pci.dtbo.o obj-$(CONFIG_MCHP_LAN966X_PCI) += lan966x-pci.o obj-y += keba/ +obj-y += amd-sbi/ diff --git a/drivers/misc/amd-sbi/Kconfig b/drivers/misc/amd-sbi/Kconfig new file mode 100644 index 000000000000..be2d9e495eb7 --- /dev/null +++ b/drivers/misc/amd-sbi/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +config AMD_SBRMI_I2C + tristate "AMD side band RMI support" + depends on I2C + help + Side band RMI over I2C support for AMD out of band management. + + This driver can also be built as a module. If so, the module will + be called sbrmi-i2c. diff --git a/drivers/misc/amd-sbi/Makefile b/drivers/misc/amd-sbi/Makefile new file mode 100644 index 000000000000..304394bf5e59 --- /dev/null +++ b/drivers/misc/amd-sbi/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_AMD_SBRMI_I2C) += sbrmi.o diff --git a/drivers/hwmon/sbrmi.c b/drivers/misc/amd-sbi/sbrmi.c similarity index 100% rename from drivers/hwmon/sbrmi.c rename to drivers/misc/amd-sbi/sbrmi.c From patchwork Mon Mar 3 10:58:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13998576 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2055.outbound.protection.outlook.com [40.107.94.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD9501F417E; Mon, 3 Mar 2025 10:59:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999577; cv=fail; b=mBd6eCxE0wI6LUFB4LN/N/uU5qo7PnprulnOwHwHaIRP41MnpR0swai9iFhIg5gA+9VO6e1jnVAp1vTHiN9Rhyh6U0vlGQ5AlbPM7D+WJfvfU5MGlKQcrgTSqQk8uYHIuoYNTF0NDoEDoI6lXEaNIEYq/+mJMBAG9OAqsv+7ITY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999577; c=relaxed/simple; bh=PIKHWevZDSKouLGTCvfGJfjfIZtcySnJLKiJ8HTFqxE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sr/BiHTZ4F9XXmazvDX5NduQ4KjWGMSh5KuggBSC1p7JOsWusUrSuRzRnox0Tcdp+t+SPzcTYgCusT2fkJLec/mGUC2wmiWCQSapzN3bbFV9qjL5J9S30D9zfaf0112uP1XpiE5DJlGpQfm3WaNyIZnL2MYGuva+geYJ+WhvXkA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=CmhHd50D; arc=fail smtp.client-ip=40.107.94.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="CmhHd50D" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WDOGzgZhZZhf+AG7PVJgWnXmDCZghjefJkf9+vCOwBVq/PKfGwhdVbwd7WnVZlc5yGzRcjPT7p+AliE7MFJ65zFU0uLfK6sZXN1+My44FCHU4qihlP0nXzk86lv2rtZlWADLn00xdi4xUtvmj0Hlw/lwJ0rA/WLODSDvdvfc/q+chjWLLzQVzGkanYDPIWVTaLgLK2VpNndeJyr82tZHINy6k9Xtv1Lf2HS44jt65OomgsygNIWUGXu3osyvGSlHnXBFm1p86AbAVHLEAo3ZJTXTeJojf3hloIh54A26SJBjSLO4Xd6d0mz2OoyuMo9JW+FP5hnOFnZMlcNnJq5ZTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iqTThDyCbhumJVkijYZpjKt0/QLJeLUuLAM7Zyz1BNU=; b=mBb6UN5B/+1FRITJ+jVwOcPebFcXBXV+NgtOt7G5U/tC1Hnbk1DRdDMp/7raB/hwSju9rhZNBA+Lm0vsLqrA+ZMHlsZPuycmCA7VDv8eqojxu7GQDxuwt/YRPVbX/5y3U6WxC0EcnbOZ2h6TUP4VH6FkJ5IAr6oxE5L7WYZx/pWZyGY4ZcYZmVMYZ/qN2yX7gas7qsKc4zK4hKIxkbvDw6QfaZt0RoofcxgGyctNBlbQ6+Cn9q3PNr+W3yHwZ4wnps1G9sh7+KQnW95ogbSQB3rPaRlDpf2y6EqEY2xSy2W5b88MJeJSXC9nKM2xAhX2m0YQsRUZTYvNLcrhFzsVpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iqTThDyCbhumJVkijYZpjKt0/QLJeLUuLAM7Zyz1BNU=; b=CmhHd50D0fxPI53OM6Rg+7vcVtv/DCr8Thwe3HWgRJeJ752ZBEGK+EktExNst6iar2a1sBbYblGUe7Dv3q2w3OcsU+HWRT76CSSMcN5kQpq2/69zLVzcIkdokW3Dj9i/36mElQWSJVsWEx/o7B+0WKZ66LPGt/aazHMoONTfZ5E= Received: from SA9P223CA0016.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::21) by SA3PR12MB9228.namprd12.prod.outlook.com (2603:10b6:806:39c::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.25; Mon, 3 Mar 2025 10:59:33 +0000 Received: from SN1PEPF00036F3F.namprd05.prod.outlook.com (2603:10b6:806:26:cafe::8) by SA9P223CA0016.outlook.office365.com (2603:10b6:806:26::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8489.28 via Frontend Transport; Mon, 3 Mar 2025 10:59:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F3F.mail.protection.outlook.com (10.167.248.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Mon, 3 Mar 2025 10:59:33 +0000 Received: from amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 3 Mar 2025 04:59:29 -0600 From: Akshay Gupta To: , CC: , , , , , , , Akshay Gupta Subject: [PATCH v5 02/11] misc: amd-sbi: Move protocol functionality to core file Date: Mon, 3 Mar 2025 10:58:53 +0000 Message-ID: <20250303105902.215009-3-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250303105902.215009-1-akshay.gupta@amd.com> References: <20250303105902.215009-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3F:EE_|SA3PR12MB9228:EE_ X-MS-Office365-Filtering-Correlation-Id: c50a40ab-966d-47cf-4c2c-08dd5a427add X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: 27rrI9+VrPph6swUlH4B6VpGGlPoClBphkfG79gY3/V/38XSyalvZCeJn10dtK77BV8fzCINS1qNRaYMvr1hb5nxZF7QcroVRCYm3bdbg9IzxqDDY9g9Crup7CmnNzFltWaubOFFRZD33Rw4lClZ005ci0iPaJbIuSVlJ4UKNxMMpeltAp+PGD/6AabKWlBnJjs8cUYIM7YQhj0YkPigI8SfjgfLG7OqLxWtzYEp0uXRb1+MCwN5m1xnyqQi2m3nbCtpDt3QZAybzzuwyPguxZ3tfVcJwMH4Kzfd1+jNGagTVBKHqZPXpNX4UnZfpn7+pPlMCArHZLn61KpGbBaN+vCYcdiPN63kXNpx/ibxChrVKiZBpTRLUtudzGujjWUDKuxW+jbFdZbZ6e3q7J2mffW8KMx1utCSEnQORAhBpYGcmZm6YawX+U9VldypwctlV48utVJ4WfsqPjWmdXxTlqU6eDVaGQbc+cKjgQ6iV8CdUIszoC7t2PIWgTfZ6kw26dlZNIcNHbeNMgw7xPO1A/uHaudoE8klNt0lUZsNgAaftqjtg4pWh19MMgFnLJDv20+iVmZ8l9KeUi/TLFuMyYJjkowgb3oTJhKJnb59lSwReRm1+eMXfVj1nFi/+pNI7S7lQ/udbFzLYrYMZImHDhutoxx+ISSyUtGA2Mnl1kG9gPsBpruNQAiKC6Qho84Yq35Tgff55SdlNv19jh6ScApFECXj6R9nZ/ZWKDNkIQqcoJykSYZWHuasXu4uvh6a7acpWIIIg7JjafYuxAkamanT9punvcQOgEBT2cBJONXM3ETbqcO2g45J5L0tTPl0b2znTeIYCWMgj+kIYS5U/54QCZmdMIKQnsrSHG7hcmJLMQGmWHcIwuNCcos+o0wLDaZwTWZSst2/EVCVxKG6X15Qu1YkqeDoo2HzjxEO9E5/iTZ3yNRXZ1PEpqnG0+mXZplqaM0u0qoJ/hVqUGRUu4o5M4WGw7BqwV0LNL47BUYehAPg8tGRH9aUCZQgxGpRG9nf5Jsu6+cH7vc5+1hbiIyaf3qwLPxTGozUslvADN97oHJPpH2eu0YP5jbvZSv6eCzy4lGNK+DLn/pTnBBx9UNbUe7oLedEbgkNsX4lpfPE4ucca5KGVyWTmiUymPVzYTcV/JX6BZkNhXbs603FCF0HslB7XeBJOKzTDz/nO9Tz+ReQqu72igzh2Z10HFGou7T5Rpkr1iTXdV6+5aN6PT8yUA+qY1WnzNzxKhQ2IdcDifLeOJkDSnnRyM/3Q7GFlRGpTtvq2e/7FAKWKxFQBHcQqay/y5dVHwwyZQsTEe4FB3Wb9Yqjmk+EJ2ba3GfxaZphItfha8CGfWhlPRfIgCvs+72F2TKAAgXVSRWs9UnQE9Ts1RpsRjA+ssRbLVNr3U4JcSI4sLt97LpkVRyJxuHBH9HTpK+MmVWHlIJS9Z5nehKKfFspvzsIogDKDx9Rgdx6eUw0wfk1QEXicVhbTg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2025 10:59:33.1361 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c50a40ab-966d-47cf-4c2c-08dd5a427add X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F3F.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9228 - This is done to utilize the protocol functionality into other domains. - Increase the scalability of the module with different bus(i2c/i3c) Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v4: New patch: Patch split from v4 patch 1/9 - Update Copyright year to 2025 drivers/misc/amd-sbi/Makefile | 3 +- drivers/misc/amd-sbi/rmi-core.c | 113 ++++++++++++++ drivers/misc/amd-sbi/rmi-core.h | 63 ++++++++ drivers/misc/amd-sbi/{sbrmi.c => rmi-i2c.c} | 165 ++------------------ 4 files changed, 187 insertions(+), 157 deletions(-) create mode 100644 drivers/misc/amd-sbi/rmi-core.c create mode 100644 drivers/misc/amd-sbi/rmi-core.h rename drivers/misc/amd-sbi/{sbrmi.c => rmi-i2c.c} (53%) diff --git a/drivers/misc/amd-sbi/Makefile b/drivers/misc/amd-sbi/Makefile index 304394bf5e59..7cd8e0a1aa5d 100644 --- a/drivers/misc/amd-sbi/Makefile +++ b/drivers/misc/amd-sbi/Makefile @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_AMD_SBRMI_I2C) += sbrmi.o +sbrmi-i2c-objs := rmi-i2c.o rmi-core.o +obj-$(CONFIG_AMD_SBRMI_I2C) += sbrmi-i2c.o diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c new file mode 100644 index 000000000000..74456756270c --- /dev/null +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * sbrmi-core.c - file defining SB-RMI protocols compliant + * AMD SoC device. + * + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ +#include +#include +#include +#include +#include "rmi-core.h" + +/* Mask for Status Register bit[1] */ +#define SW_ALERT_MASK 0x2 + +/* Software Interrupt for triggering */ +#define START_CMD 0x80 +#define TRIGGER_MAILBOX 0x01 + +int rmi_mailbox_xfer(struct sbrmi_data *data, + struct sbrmi_mailbox_msg *msg) +{ + int i, ret, retry = 10; + int sw_status; + u8 byte; + + mutex_lock(&data->lock); + + /* Indicate firmware a command is to be serviced */ + ret = i2c_smbus_write_byte_data(data->client, + SBRMI_INBNDMSG7, START_CMD); + if (ret < 0) + goto exit_unlock; + + /* Write the command to SBRMI::InBndMsg_inst0 */ + ret = i2c_smbus_write_byte_data(data->client, + SBRMI_INBNDMSG0, msg->cmd); + if (ret < 0) + goto exit_unlock; + + /* + * For both read and write the initiator (BMC) writes + * Command Data In[31:0] to SBRMI::InBndMsg_inst[4:1] + * SBRMI_x3C(MSB):SBRMI_x39(LSB) + */ + for (i = 0; i < 4; i++) { + byte = (msg->data_in >> i * 8) & 0xff; + ret = i2c_smbus_write_byte_data(data->client, + SBRMI_INBNDMSG1 + i, byte); + if (ret < 0) + goto exit_unlock; + } + + /* + * Write 0x01 to SBRMI::SoftwareInterrupt to notify firmware to + * perform the requested read or write command + */ + ret = i2c_smbus_write_byte_data(data->client, + SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); + if (ret < 0) + goto exit_unlock; + + /* + * Firmware will write SBRMI::Status[SwAlertSts]=1 to generate + * an ALERT (if enabled) to initiator (BMC) to indicate completion + * of the requested command + */ + do { + sw_status = i2c_smbus_read_byte_data(data->client, + SBRMI_STATUS); + if (sw_status < 0) { + ret = sw_status; + goto exit_unlock; + } + if (sw_status & SW_ALERT_MASK) + break; + usleep_range(50, 100); + } while (retry--); + + if (retry < 0) { + dev_err(&data->client->dev, + "Firmware fail to indicate command completion\n"); + ret = -EIO; + goto exit_unlock; + } + + /* + * For a read operation, the initiator (BMC) reads the firmware + * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1] + * {SBRMI_x34(MSB):SBRMI_x31(LSB)}. + */ + if (msg->read) { + for (i = 0; i < 4; i++) { + ret = i2c_smbus_read_byte_data(data->client, + SBRMI_OUTBNDMSG1 + i); + if (ret < 0) + goto exit_unlock; + msg->data_out |= ret << i * 8; + } + } + + /* + * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the + * ALERT to initiator + */ + ret = i2c_smbus_write_byte_data(data->client, SBRMI_STATUS, + sw_status | SW_ALERT_MASK); + +exit_unlock: + mutex_unlock(&data->lock); + return ret; +} diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-core.h new file mode 100644 index 000000000000..8e30a43ec714 --- /dev/null +++ b/drivers/misc/amd-sbi/rmi-core.h @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#ifndef _SBRMI_CORE_H_ +#define _SBRMI_CORE_H_ + +#include +#include +#include + +/* SB-RMI registers */ +enum sbrmi_reg { + SBRMI_CTRL = 0x01, + SBRMI_STATUS, + SBRMI_OUTBNDMSG0 = 0x30, + SBRMI_OUTBNDMSG1, + SBRMI_OUTBNDMSG2, + SBRMI_OUTBNDMSG3, + SBRMI_OUTBNDMSG4, + SBRMI_OUTBNDMSG5, + SBRMI_OUTBNDMSG6, + SBRMI_OUTBNDMSG7, + SBRMI_INBNDMSG0, + SBRMI_INBNDMSG1, + SBRMI_INBNDMSG2, + SBRMI_INBNDMSG3, + SBRMI_INBNDMSG4, + SBRMI_INBNDMSG5, + SBRMI_INBNDMSG6, + SBRMI_INBNDMSG7, + SBRMI_SW_INTERRUPT, +}; + +/* + * SB-RMI supports soft mailbox service request to MP1 (power management + * firmware) through SBRMI inbound/outbound message registers. + * SB-RMI message IDs + */ +enum sbrmi_msg_id { + SBRMI_READ_PKG_PWR_CONSUMPTION = 0x1, + SBRMI_WRITE_PKG_PWR_LIMIT, + SBRMI_READ_PKG_PWR_LIMIT, + SBRMI_READ_PKG_MAX_PWR_LIMIT, +}; + +/* Each client has this additional data */ +struct sbrmi_data { + struct i2c_client *client; + struct mutex lock; + u32 pwr_limit_max; +}; + +struct sbrmi_mailbox_msg { + u8 cmd; + bool read; + u32 data_in; + u32 data_out; +}; + +int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg); +#endif /*_SBRMI_CORE_H_*/ diff --git a/drivers/misc/amd-sbi/sbrmi.c b/drivers/misc/amd-sbi/rmi-i2c.c similarity index 53% rename from drivers/misc/amd-sbi/sbrmi.c rename to drivers/misc/amd-sbi/rmi-i2c.c index d48d8e5460ff..914338a24246 100644 --- a/drivers/misc/amd-sbi/sbrmi.c +++ b/drivers/misc/amd-sbi/rmi-i2c.c @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * sbrmi.c - hwmon driver for a SB-RMI mailbox - * compliant AMD SoC device. + * rmi-i2c.c - Side band RMI over I2C support for AMD out + * of band management * - * Copyright (C) 2020-2021 Advanced Micro Devices, Inc. + * Copyright (C) 2024 Advanced Micro Devices, Inc. */ #include @@ -14,64 +14,10 @@ #include #include #include +#include "rmi-core.h" /* Do not allow setting negative power limit */ #define SBRMI_PWR_MIN 0 -/* Mask for Status Register bit[1] */ -#define SW_ALERT_MASK 0x2 - -/* Software Interrupt for triggering */ -#define START_CMD 0x80 -#define TRIGGER_MAILBOX 0x01 - -/* - * SB-RMI supports soft mailbox service request to MP1 (power management - * firmware) through SBRMI inbound/outbound message registers. - * SB-RMI message IDs - */ -enum sbrmi_msg_id { - SBRMI_READ_PKG_PWR_CONSUMPTION = 0x1, - SBRMI_WRITE_PKG_PWR_LIMIT, - SBRMI_READ_PKG_PWR_LIMIT, - SBRMI_READ_PKG_MAX_PWR_LIMIT, -}; - -/* SB-RMI registers */ -enum sbrmi_reg { - SBRMI_CTRL = 0x01, - SBRMI_STATUS, - SBRMI_OUTBNDMSG0 = 0x30, - SBRMI_OUTBNDMSG1, - SBRMI_OUTBNDMSG2, - SBRMI_OUTBNDMSG3, - SBRMI_OUTBNDMSG4, - SBRMI_OUTBNDMSG5, - SBRMI_OUTBNDMSG6, - SBRMI_OUTBNDMSG7, - SBRMI_INBNDMSG0, - SBRMI_INBNDMSG1, - SBRMI_INBNDMSG2, - SBRMI_INBNDMSG3, - SBRMI_INBNDMSG4, - SBRMI_INBNDMSG5, - SBRMI_INBNDMSG6, - SBRMI_INBNDMSG7, - SBRMI_SW_INTERRUPT, -}; - -/* Each client has this additional data */ -struct sbrmi_data { - struct i2c_client *client; - struct mutex lock; - u32 pwr_limit_max; -}; - -struct sbrmi_mailbox_msg { - u8 cmd; - bool read; - u32 data_in; - u32 data_out; -}; static int sbrmi_enable_alert(struct i2c_client *client) { @@ -94,100 +40,6 @@ static int sbrmi_enable_alert(struct i2c_client *client) return 0; } -static int rmi_mailbox_xfer(struct sbrmi_data *data, - struct sbrmi_mailbox_msg *msg) -{ - int i, ret, retry = 10; - int sw_status; - u8 byte; - - mutex_lock(&data->lock); - - /* Indicate firmware a command is to be serviced */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG7, START_CMD); - if (ret < 0) - goto exit_unlock; - - /* Write the command to SBRMI::InBndMsg_inst0 */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG0, msg->cmd); - if (ret < 0) - goto exit_unlock; - - /* - * For both read and write the initiator (BMC) writes - * Command Data In[31:0] to SBRMI::InBndMsg_inst[4:1] - * SBRMI_x3C(MSB):SBRMI_x39(LSB) - */ - for (i = 0; i < 4; i++) { - byte = (msg->data_in >> i * 8) & 0xff; - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG1 + i, byte); - if (ret < 0) - goto exit_unlock; - } - - /* - * Write 0x01 to SBRMI::SoftwareInterrupt to notify firmware to - * perform the requested read or write command - */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); - if (ret < 0) - goto exit_unlock; - - /* - * Firmware will write SBRMI::Status[SwAlertSts]=1 to generate - * an ALERT (if enabled) to initiator (BMC) to indicate completion - * of the requested command - */ - do { - sw_status = i2c_smbus_read_byte_data(data->client, - SBRMI_STATUS); - if (sw_status < 0) { - ret = sw_status; - goto exit_unlock; - } - if (sw_status & SW_ALERT_MASK) - break; - usleep_range(50, 100); - } while (retry--); - - if (retry < 0) { - dev_err(&data->client->dev, - "Firmware fail to indicate command completion\n"); - ret = -EIO; - goto exit_unlock; - } - - /* - * For a read operation, the initiator (BMC) reads the firmware - * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1] - * {SBRMI_x34(MSB):SBRMI_x31(LSB)}. - */ - if (msg->read) { - for (i = 0; i < 4; i++) { - ret = i2c_smbus_read_byte_data(data->client, - SBRMI_OUTBNDMSG1 + i); - if (ret < 0) - goto exit_unlock; - msg->data_out |= ret << i * 8; - } - } - - /* - * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the - * ALERT to initiator - */ - ret = i2c_smbus_write_byte_data(data->client, SBRMI_STATUS, - sw_status | SW_ALERT_MASK); - -exit_unlock: - mutex_unlock(&data->lock); - return ret; -} - static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { @@ -297,7 +149,7 @@ static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) return ret; } -static int sbrmi_probe(struct i2c_client *client) +static int sbrmi_i2c_probe(struct i2c_client *client) { struct device *dev = &client->dev; struct device *hwmon_dev; @@ -328,7 +180,7 @@ static int sbrmi_probe(struct i2c_client *client) } static const struct i2c_device_id sbrmi_id[] = { - {"sbrmi"}, + {"sbrmi-i2c"}, {} }; MODULE_DEVICE_TABLE(i2c, sbrmi_id); @@ -343,15 +195,16 @@ MODULE_DEVICE_TABLE(of, sbrmi_of_match); static struct i2c_driver sbrmi_driver = { .driver = { - .name = "sbrmi", + .name = "sbrmi-i2c", .of_match_table = of_match_ptr(sbrmi_of_match), }, - .probe = sbrmi_probe, + .probe = sbrmi_i2c_probe, .id_table = sbrmi_id, }; module_i2c_driver(sbrmi_driver); MODULE_AUTHOR("Akshay Gupta "); +MODULE_AUTHOR("Naveen Krishna Chatradhi "); MODULE_DESCRIPTION("Hwmon driver for AMD SB-RMI emulated sensor"); MODULE_LICENSE("GPL"); From patchwork Mon Mar 3 10:58:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13998578 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2065.outbound.protection.outlook.com [40.107.101.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 376991F461F; Mon, 3 Mar 2025 10:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999589; cv=fail; b=MeiZ7hluzx+G1SjoEuA/vQGiNWNhIEPDXhUJ34zo+X+A/TMGu0OU3eWRacD3wXWgT+dY5s+KPgP26MGqwlYEKOGFYUCb2IKqtNvz3pqi4uZPEKzQv1mK7/ugHkrxyOdkRP77g6IOmywTW7fjVjRt73NDDfpyvv/QkPTKWXZgJqc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999589; c=relaxed/simple; bh=/BgLzPf3NsR2HtXkQ/CIFgY5TOZuw7S8eG7lQnuR+Dg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VXkXLVBjUuasf0zDLO/YYi4ch0sDd0E7UUKQUuEEOc0LmP8bKOdp/4PTar9n+dN1E8rbM08hut8PNgjfyKdxDIQmjflMLYtdW9aKjNmTb+YUxTTK6lL2Hi+0w2Hjk45S1f0q03rkZKTEru613rUTZoV600eBM9SoHj2VU8DgzQ8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=OadCObGA; arc=fail smtp.client-ip=40.107.101.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="OadCObGA" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WDhLnt79nsd17lBoOIwZsmorJBZCjIocJITfg6LCqDRBK+LeiGNtE3iFcutQhTn2vSjNA2QJ6iRD3lbCVa+pTHdkXu/AAujhlZXR5kmMoKZ/eeWpCJaxOyWbM3QPDAgqLOlnrsgb1bT7DMrAE52Zo7TGltQBXTJAvzzZdZgjkKx3bZ6vDkCak4OX22x35x6gJlnljsQU6sV0ycOHm9ch7jS+X0e+GsiwynuOvxkoN4Yy3XULWOb6/WcNOyAYgHuwMGRonVF8Su+7gi+PEs7sYYdg5XdWU9V+ABYhwtNR+A/7N7TNCwo4GuTMh6eSFlG6FfjfKfOOy+BnKnDf3aYjrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rGV2tSPqZeCNDPcRLJTMB+34eX/08dEHILSjTXi8aP0=; b=mmLaz4SGAfY+IjDOhI+NH2VkvI/in9qk87PE0dKHCx5lIJDdRPJyzOcMUBI7iWU9GQ6oM6yEKJEl/+2F/8sJeedDw8tpa5Y1rzjYsO5g768dq3e0L7gv5m5fvupmXFz3TQnIaB6rJM1TydQnbfYvA88DIWZz6sWV0Kf4KOXkC7/wcVvPfnV+cdSBH29YdKSy7ttlgFjgPUbOlyL0uuBhePARuKLo9s5MbBlCXUoTsRE5uuLCxKHtSiv4h7KcGylLlK00CWH7t5NcL4kYRP1T2qaPJdzNaZmw8caeGZMo9ZcEnvTDKlIvnhz9S79JNdQRvW6rD86ITctnTtJMUCwJgw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rGV2tSPqZeCNDPcRLJTMB+34eX/08dEHILSjTXi8aP0=; b=OadCObGAAXShuJ6tNXixJYkYuRqCF5w9IELSQ0cw8WH1UVndHqNH37WHWYsHZnzFominH5eS/te7x0gLaQZvXhIaJudfux6INvFYkYwk8sUy6f8Hgq9HakH6771jgyboEEW626UbpMFFI/j38IjsoHL6lp/gG6FQuMOz7PsEslM= Received: from SN6PR08CA0022.namprd08.prod.outlook.com (2603:10b6:805:66::35) by DS0PR12MB8200.namprd12.prod.outlook.com (2603:10b6:8:f5::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.22; Mon, 3 Mar 2025 10:59:37 +0000 Received: from SN1PEPF00036F42.namprd05.prod.outlook.com (2603:10b6:805:66:cafe::62) by SN6PR08CA0022.outlook.office365.com (2603:10b6:805:66::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8489.29 via Frontend Transport; Mon, 3 Mar 2025 10:59:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F42.mail.protection.outlook.com (10.167.248.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Mon, 3 Mar 2025 10:59:36 +0000 Received: from amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 3 Mar 2025 04:59:33 -0600 From: Akshay Gupta To: , CC: , , , , , , , Akshay Gupta Subject: [PATCH v5 03/11] misc: amd-sbi: Move hwmon device sensor as separate entity Date: Mon, 3 Mar 2025 10:58:54 +0000 Message-ID: <20250303105902.215009-4-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250303105902.215009-1-akshay.gupta@amd.com> References: <20250303105902.215009-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F42:EE_|DS0PR12MB8200:EE_ X-MS-Office365-Filtering-Correlation-Id: 8af9e1fb-c101-4b0e-b259-08dd5a427d1c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: OThM+7mF4HuChRuZMieFyVkoeYhTb6hkERvKhlJp1ZutBGyDqcM+JoeVUwiXQRGu0c3c0OadQP9qtooQ+NDmUeL4Vr8zqp6EtLofAmoQjfdV538nSE83QZPfNBw0JOLRUdih7gd5kmwqTAt6I7EOxiQoVmg6kMKZxS4cbhOOQBg8gbBQr9EeOraV13WHDFkzlQniYLKrmC6IpwYHHDWTE+p7MSMtIAddyTqi2vxtzJrPpTBBYyWEDHhIqkHXalCGOb5fgm96WStpvByxjgEl9MwRToWYbcti6X/vQcpS5ujEY+w9Eg6RQC2x66MzjMhnGswuMHr/WkBk5OPNcAmzEaHzOQnoSvUB73IeuFEyfhcLuVim7jf0ZVb0AEI2Eem+HfAtugrcqrQXJLZVlxzGmBxWGK++DKscZO5xnErX/MgX5HDpWB24ym7mj9lEmUXhjDpGNELDh2Au364hPVWVNArn2hXiROu9zi77lgGEWg9E7sgyxklgkPRt7PNftDn3GLnfAlRwb8dcAu3SImVY9K9ewiP4lbwlzFU0zq9R2Dn4cgfbvm6hVI5SIKfhddNzeNnjXdFlPkuwtWNzmSVrkdfuXxVl+BdcAubdzgCAhYfsyJ3EUVxIDtUdfbwdz1EUACs6VByXApJaqVI9kgqtm28dI694VFUPSU7ZdG6Tn2ws4D++YIaSVSWXUPFZE5BmH4PprnR7uR1dHsCAmWN5obNlJBVfnEiPjjc02caKlvo3H/gXaFRzoN0j6Ykd9m3BInc0KCeyU2MMWlWipwW1RZNg/s599yjOQonwtOo/23HY0vnB3ec75Ix88bHRQOTxMHgw9s9EGTfHgboDW1OvRpsaS+pdhi18XqgzfDcrmEmOP1yRGgHab68uKTGz26YuIfMuC3lilqoisowUw80PSk0Vj0AZItSWUyCP/C0hytwGRbvpyGdvD/8qNGD21NQ32kJ9rH8EWO6Uq4ramfu42KiJv5Do4D642VsH+zIZSre/6Q05Erw9NUMqarPyhsD6lF/c7hmPFh2vvLOO4ZkEXg70iN4LHfWKnt01Dp6anVdpzV1s9WsmuI7Yf4DxhDipt686k1YIPDfGJr3rNQuMMFnhWLL7qOlzg9r9s1sMOZ08X+gA3P+/LjMYqjOfSH/0q8cGqXmQSnqNb61TDR4qGe7roWA98gkIj+Ypt8EJmlcqLW1Ku7zRQDJk3x5el+50ljztkWY4YogwPbr2kBA8PrwlLRALgYax4vHmpeVe9qtlfuOyF26AdosTnhgQhcV1TEgW/ySOn+mZb9mrPhCBC09mrYyYQ9E2IqBhqmKF9pT1zsnVBh3KN6XZNtfQR2tdr1OdBpoeejxsMV6AHkIApLJb7qGbx6Iyqs8oPoV6BAD+z/T1Zbulv6i0fx9qn9tq5ktkRclw35bE0b23m/sBxH2wPOgxd4hCqZeEWQRtznfDlt0BKLCIoAwg/UbRS7cdkdQbtRcHbrxTTQicrLB7IlUZWL5XvgPE/CHj33qZ4WI= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2025 10:59:36.8915 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8af9e1fb-c101-4b0e-b259-08dd5a427d1c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F42.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8200 - Move hwmon device sensor to misc as only power is reported through hwmon sensor. Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v4: New patch: Patch split from v4 patch 1/9 - Update Copyright year to 2025 drivers/misc/amd-sbi/Makefile | 2 +- drivers/misc/amd-sbi/rmi-core.h | 1 + drivers/misc/amd-sbi/rmi-hwmon.c | 121 +++++++++++++++++++++++++++++++ drivers/misc/amd-sbi/rmi-i2c.c | 105 +-------------------------- 4 files changed, 125 insertions(+), 104 deletions(-) create mode 100644 drivers/misc/amd-sbi/rmi-hwmon.c diff --git a/drivers/misc/amd-sbi/Makefile b/drivers/misc/amd-sbi/Makefile index 7cd8e0a1aa5d..eac90a7635de 100644 --- a/drivers/misc/amd-sbi/Makefile +++ b/drivers/misc/amd-sbi/Makefile @@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only -sbrmi-i2c-objs := rmi-i2c.o rmi-core.o +sbrmi-i2c-objs := rmi-i2c.o rmi-core.o rmi-hwmon.o obj-$(CONFIG_AMD_SBRMI_I2C) += sbrmi-i2c.o diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-core.h index 8e30a43ec714..27165d3bb20f 100644 --- a/drivers/misc/amd-sbi/rmi-core.h +++ b/drivers/misc/amd-sbi/rmi-core.h @@ -60,4 +60,5 @@ struct sbrmi_mailbox_msg { }; int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg); +int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data); #endif /*_SBRMI_CORE_H_*/ diff --git a/drivers/misc/amd-sbi/rmi-hwmon.c b/drivers/misc/amd-sbi/rmi-hwmon.c new file mode 100644 index 000000000000..720e800db1f0 --- /dev/null +++ b/drivers/misc/amd-sbi/rmi-hwmon.c @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * rmi-hwmon.c - hwmon sensor support for side band RMI + * + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ +#include +#include +#include "rmi-core.h" + +/* Do not allow setting negative power limit */ +#define SBRMI_PWR_MIN 0 + +static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + struct sbrmi_data *data = dev_get_drvdata(dev); + struct sbrmi_mailbox_msg msg = { 0 }; + int ret; + + if (!data) + return -ENODEV; + + if (type != hwmon_power) + return -EINVAL; + + msg.read = true; + switch (attr) { + case hwmon_power_input: + msg.cmd = SBRMI_READ_PKG_PWR_CONSUMPTION; + ret = rmi_mailbox_xfer(data, &msg); + break; + case hwmon_power_cap: + msg.cmd = SBRMI_READ_PKG_PWR_LIMIT; + ret = rmi_mailbox_xfer(data, &msg); + break; + case hwmon_power_cap_max: + msg.data_out = data->pwr_limit_max; + ret = 0; + break; + default: + return -EINVAL; + } + if (ret < 0) + return ret; + /* hwmon power attributes are in microWatt */ + *val = (long)msg.data_out * 1000; + return ret; +} + +static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long val) +{ + struct sbrmi_data *data = dev_get_drvdata(dev); + struct sbrmi_mailbox_msg msg = { 0 }; + + if (!data) + return -ENODEV; + + if (type != hwmon_power && attr != hwmon_power_cap) + return -EINVAL; + /* + * hwmon power attributes are in microWatt + * mailbox read/write is in mWatt + */ + val /= 1000; + + val = clamp_val(val, SBRMI_PWR_MIN, data->pwr_limit_max); + + msg.cmd = SBRMI_WRITE_PKG_PWR_LIMIT; + msg.data_in = val; + msg.read = false; + + return rmi_mailbox_xfer(data, &msg); +} + +static umode_t sbrmi_is_visible(const void *data, + enum hwmon_sensor_types type, + u32 attr, int channel) +{ + switch (type) { + case hwmon_power: + switch (attr) { + case hwmon_power_input: + case hwmon_power_cap_max: + return 0444; + case hwmon_power_cap: + return 0644; + } + break; + default: + break; + } + return 0; +} + +static const struct hwmon_channel_info * const sbrmi_info[] = { + HWMON_CHANNEL_INFO(power, + HWMON_P_INPUT | HWMON_P_CAP | HWMON_P_CAP_MAX), + NULL +}; + +static const struct hwmon_ops sbrmi_hwmon_ops = { + .is_visible = sbrmi_is_visible, + .read = sbrmi_read, + .write = sbrmi_write, +}; + +static const struct hwmon_chip_info sbrmi_chip_info = { + .ops = &sbrmi_hwmon_ops, + .info = sbrmi_info, +}; + +int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data) +{ + struct device *hwmon_dev; + + hwmon_dev = devm_hwmon_device_register_with_info(dev, "sbrmi", data, + &sbrmi_chip_info, NULL); + return PTR_ERR_OR_ZERO(hwmon_dev); +} diff --git a/drivers/misc/amd-sbi/rmi-i2c.c b/drivers/misc/amd-sbi/rmi-i2c.c index 914338a24246..9ad4c8093399 100644 --- a/drivers/misc/amd-sbi/rmi-i2c.c +++ b/drivers/misc/amd-sbi/rmi-i2c.c @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -16,9 +15,6 @@ #include #include "rmi-core.h" -/* Do not allow setting negative power limit */ -#define SBRMI_PWR_MIN 0 - static int sbrmi_enable_alert(struct i2c_client *client) { int ctrl; @@ -40,100 +36,6 @@ static int sbrmi_enable_alert(struct i2c_client *client) return 0; } -static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, - u32 attr, int channel, long *val) -{ - struct sbrmi_data *data = dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg = { 0 }; - int ret; - - if (type != hwmon_power) - return -EINVAL; - - msg.read = true; - switch (attr) { - case hwmon_power_input: - msg.cmd = SBRMI_READ_PKG_PWR_CONSUMPTION; - ret = rmi_mailbox_xfer(data, &msg); - break; - case hwmon_power_cap: - msg.cmd = SBRMI_READ_PKG_PWR_LIMIT; - ret = rmi_mailbox_xfer(data, &msg); - break; - case hwmon_power_cap_max: - msg.data_out = data->pwr_limit_max; - ret = 0; - break; - default: - return -EINVAL; - } - if (ret < 0) - return ret; - /* hwmon power attributes are in microWatt */ - *val = (long)msg.data_out * 1000; - return ret; -} - -static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, - u32 attr, int channel, long val) -{ - struct sbrmi_data *data = dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg = { 0 }; - - if (type != hwmon_power && attr != hwmon_power_cap) - return -EINVAL; - /* - * hwmon power attributes are in microWatt - * mailbox read/write is in mWatt - */ - val /= 1000; - - val = clamp_val(val, SBRMI_PWR_MIN, data->pwr_limit_max); - - msg.cmd = SBRMI_WRITE_PKG_PWR_LIMIT; - msg.data_in = val; - msg.read = false; - - return rmi_mailbox_xfer(data, &msg); -} - -static umode_t sbrmi_is_visible(const void *data, - enum hwmon_sensor_types type, - u32 attr, int channel) -{ - switch (type) { - case hwmon_power: - switch (attr) { - case hwmon_power_input: - case hwmon_power_cap_max: - return 0444; - case hwmon_power_cap: - return 0644; - } - break; - default: - break; - } - return 0; -} - -static const struct hwmon_channel_info * const sbrmi_info[] = { - HWMON_CHANNEL_INFO(power, - HWMON_P_INPUT | HWMON_P_CAP | HWMON_P_CAP_MAX), - NULL -}; - -static const struct hwmon_ops sbrmi_hwmon_ops = { - .is_visible = sbrmi_is_visible, - .read = sbrmi_read, - .write = sbrmi_write, -}; - -static const struct hwmon_chip_info sbrmi_chip_info = { - .ops = &sbrmi_hwmon_ops, - .info = sbrmi_info, -}; - static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) { struct sbrmi_mailbox_msg msg = { 0 }; @@ -152,7 +54,6 @@ static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) static int sbrmi_i2c_probe(struct i2c_client *client) { struct device *dev = &client->dev; - struct device *hwmon_dev; struct sbrmi_data *data; int ret; @@ -173,10 +74,8 @@ static int sbrmi_i2c_probe(struct i2c_client *client) if (ret < 0) return ret; - hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data, - &sbrmi_chip_info, NULL); - - return PTR_ERR_OR_ZERO(hwmon_dev); + dev_set_drvdata(dev, data); + return create_hwmon_sensor_device(dev, data); } static const struct i2c_device_id sbrmi_id[] = { From patchwork Mon Mar 3 10:58:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13998577 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2067.outbound.protection.outlook.com [40.107.100.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B4501F417E; Mon, 3 Mar 2025 10:59:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999586; cv=fail; b=WKbrmTozki3csfqpSHArYzlY8EkcfQgiVyl3nOk5PNa95uZ4vF6wfh23QlU6f2SWCw+mJD+loXxdHTUa9lNOzLuqCVKLA2UYQ7QVq71mFg2twDq56i9Ta+6ZOoc0OOPYTqm0oAnyOd7ml5bw1mwMBP8zwnJgEeXsJyv/pc+021Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999586; c=relaxed/simple; bh=fh+uhEeUGrjJhdvGkAo65eRfKeCy3t5xL7Tvx1TUDk0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EwG/UAYJT4FEyEqF6jI+pzp3FsgS8RBhXK9TjKfeasNud2wWQotVXF7Ov9S6zn16wgL2M47Hzd4qvduL2ev4toFAKrDFnm3Egx9QPHLKaBPql2dcV8z/b1k29IpXJMiLB7VsuRjMcJ0uMS93zz0NX9L6CTvfLJQASmtks9ho2Ek= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=W2RO2UxE; arc=fail smtp.client-ip=40.107.100.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="W2RO2UxE" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MGlfqlEwYqpgyTBndCGj7kBWy8aftgPec8knUvaDJwEDcMhHcFY0jl9IYFLU4dLa34KpyQ2wPYcFAKH4YIkxRcYbmDkNRrjnDzmWQvorYe7Yvbfue/YKYLhRNRFS+i9mKE4pNTFGwefF8duigA0YlkN4qweO5XQCV4Gqk6ojGnNrN51hft8r5BqKryMtV0aS/wwEjdPgS5UZ2i8AWIAsAkQIFzg1HQPAzuHiQ+3outBixpCfisq7D4nApA+nvS8KHQf2V09XlEj142RvYYBOBnH3weKAd3dLXGI3TCaeP3ey3mwpviMiuCalzVBCvB77JkFtG6vRHYh/NnnsqSNtmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fWpAIKJib9evUvF3ZT1qq4ZIooQ7/lcpgzwS9JjO6ec=; b=cpvA2X056IuIxlBcJjMhV6gHR5l3C8VxCuLqNpsutFQNc3w5gE3KEcs+LeOYsD/MuYIuJMqYQlDsyWyz+bA7NgHt+hDQ+woISjb9ZxsMaEYDE/6QvdWlg0pDQlBvPaFpydQW8wqfr5GCzB761WYQnrvQVl65nIADQnWNetgSjWaIIY675PDhrMDbxxLW01h6+UR5KVMC5HeDgcXa7y4+W1OCIJCaP5yQEEpHQH2+gmfj7zJcdngNNChfvzFcNffiXEKqTZP7O037CDEwtOmxhfec6oJUGVoOkxymUmi07PvQwgO/ivi4MJoX8/7m8JM2XDDqDcU9hgdHMGrKcWBB1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fWpAIKJib9evUvF3ZT1qq4ZIooQ7/lcpgzwS9JjO6ec=; b=W2RO2UxErWOFKQTfDN3Y6Yw8KN6CE7XAZ4aKN/HgbCOQMtLp+0LIJBlr0Rlva3p+9yUbW9ZhSgaUVfzWqCQntuJVCdtb867f46URbaVBwf8LE8WKKvsu81TxkZgynM/vrXMC+EEEinJoOIVRtwZqlvyzcQiKPGFwsiP6MhtVjQQ= Received: from SN6PR08CA0030.namprd08.prod.outlook.com (2603:10b6:805:66::43) by BL1PR12MB5708.namprd12.prod.outlook.com (2603:10b6:208:387::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.25; Mon, 3 Mar 2025 10:59:41 +0000 Received: from SN1PEPF00036F42.namprd05.prod.outlook.com (2603:10b6:805:66:cafe::60) by SN6PR08CA0030.outlook.office365.com (2603:10b6:805:66::43) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8489.28 via Frontend Transport; Mon, 3 Mar 2025 10:59:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F42.mail.protection.outlook.com (10.167.248.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Mon, 3 Mar 2025 10:59:40 +0000 Received: from amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 3 Mar 2025 04:59:37 -0600 From: Akshay Gupta To: , CC: , , , , , , , Akshay Gupta Subject: [PATCH v5 04/11] misc: amd-sbi: Use regmap subsystem Date: Mon, 3 Mar 2025 10:58:55 +0000 Message-ID: <20250303105902.215009-5-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250303105902.215009-1-akshay.gupta@amd.com> References: <20250303105902.215009-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F42:EE_|BL1PR12MB5708:EE_ X-MS-Office365-Filtering-Correlation-Id: 26c96758-24db-40c8-7113-08dd5a427f62 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: Lp4WH8NIdNKcfum3GLsyDEye7bTC9WHq28d5bf8FFuvsizOPRLJzNECAj1359gqIaESuSda1ucEw15y+lx+u2m0zZcBbfnKDJEyiYQshYRhhAGob1tlrNYDhcxeLSCnv+PJQFaZ+nX1QGXJJZFFH1e6D6r3U6NQ0KdAYz1WxBTKEZNPpYhS0ehKRgMi8YTDlPxEOyqGO/fTF7FfNhEghdg4yE0vuhoxDh12VWDkvbASK5ick0s0qQRn0ED4+wfmGfjoc7fN+lyKSQUj3GSfB48FHw0b8xK/hSIZTFM3YQ/hOaufdCZjGRJ7zIXaVoP4+x1LKLWTP4cr1gX8IowF5mahOBRSKR+G8yMg0+KS8W+YauKxPH/Do4JipjO0za3A0xWVS8HNWYGi5WnRz9DePo3NAbPmwfgyVIN+ewDHthyxQGHYqUZyPx6KAjbUxPSqzSvStfmKeewy1rCmYUB8oboWP927HQB4fP7a31WE8KxwqZL9MOXgb1nLJo5rsEYUgbIhZfzhepm7cKARkjBfK5UzycGPtxrkezD74sOFaP9JVV4LT8YNYAU9qfwip/R+cbBuRPFvG+ga9tHJ0Fqrg76FnzA7M89EXfExpj5x9LYdS55TcguRWMdDznlfG9btcya9g92zGAO+O+5FGmSTf0MmckQoBjJcjt6jfCPMv3PskjxCsvgQr0vGUFq3jJeIhr/hIvrdqqjEXmnoi+0VZ6PQofTfSnDT6scv6iGUgVeXFxTgSet2wGNPoCP6mYkXOJNSJ+zzITIrsZrr1XG44Plr7NOPRzfzRXwnms3fDwaDSJcxAq+B5jMQr/sZzVasxcNpoL7K4GvrmIiyrO8+4sUUMNeHD3nNB68gQRucfHk0el0B2Z+sTVwL06JFmqFQeqq6Z+dAsMf1mCJV3RJ5OyM1b6fc0lPDdeARnAWIqJcZvoTNxQaQVVG0oyVjyAo/KaTLYkAkw1FDrwOCbVYK+nSy3YcNVe1a1Ati00KvgqV1L/U1BDId2I+Bk+VQmu7apeQOUCWCz2bUTyzIJUrOyTWWsWnTC1/oJgZenER63xR48Obm8B3vRg/hLjknuoBLTPlN2ADqsIc243fyJIx2dIOSeFApXSJz6sEov6tc1ulOj+2qgWXYUC0mP55Nc07xdYsmtP/S46S7QrCAYTuoVHhXatJEiVSJNrhLoNJ3EYVaqMp54ZVrd6JKyMP1vbg7T/6yqv2jj0TMrQCjgxpO5YQZuGd6r1xRUMP0ntgEDfQCeFOsA2fyPK5qnE8DCA4pb+d9sXe6C964bCmicOaCSAMrfuBxpG6NbZ2sZZ9nuJghT9as1fTV2FLufPQyNnjr9/Ba2cDQr7DM0eDWSMg4r+vQjQmKXA5xYEyBy17b4tATwVO+Ew7Xxagl0UHzcee530k1eGSIQqI76GhrEM5HCi0BdKQuis1seaPKizfidC+kDbAYrVUZXMTyeaNAcNoa4COkPSrEVV5XfKxZyMXkD6abTZKcB5rxlFeyjqWNhrzo= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2025 10:59:40.7040 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 26c96758-24db-40c8-7113-08dd5a427f62 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F42.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5708 - regmap subsystem provides multiple benefits over direct smbus APIs - subsystem adds another abstraction layer on top of struct i2c_client to make it easy to read or write registers. - The subsystem can be helpful in following cases - Different types of bus (i2c/i3c), we have plans to support i3c. - Different Register address size (1byte/2byte) Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v4: - Previously patch 2 Changes since v1: - Previously patch 3 - Remove "__packed" from data structure drivers/misc/amd-sbi/rmi-core.c | 29 ++++++++++++----------------- drivers/misc/amd-sbi/rmi-core.h | 3 ++- drivers/misc/amd-sbi/rmi-i2c.c | 25 ++++++++++++++++--------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c index 74456756270c..663ab9176d95 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "rmi-core.h" /* Mask for Status Register bit[1] */ @@ -21,6 +22,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg) { + unsigned int bytes; int i, ret, retry = 10; int sw_status; u8 byte; @@ -28,14 +30,12 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, mutex_lock(&data->lock); /* Indicate firmware a command is to be serviced */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG7, START_CMD); + ret = regmap_write(data->regmap, SBRMI_INBNDMSG7, START_CMD); if (ret < 0) goto exit_unlock; /* Write the command to SBRMI::InBndMsg_inst0 */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG0, msg->cmd); + ret = regmap_write(data->regmap, SBRMI_INBNDMSG0, msg->cmd); if (ret < 0) goto exit_unlock; @@ -46,8 +46,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, */ for (i = 0; i < 4; i++) { byte = (msg->data_in >> i * 8) & 0xff; - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG1 + i, byte); + ret = regmap_write(data->regmap, SBRMI_INBNDMSG1 + i, byte); if (ret < 0) goto exit_unlock; } @@ -56,8 +55,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * Write 0x01 to SBRMI::SoftwareInterrupt to notify firmware to * perform the requested read or write command */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); + ret = regmap_write(data->regmap, SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); if (ret < 0) goto exit_unlock; @@ -67,8 +65,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * of the requested command */ do { - sw_status = i2c_smbus_read_byte_data(data->client, - SBRMI_STATUS); + ret = regmap_read(data->regmap, SBRMI_STATUS, &sw_status); if (sw_status < 0) { ret = sw_status; goto exit_unlock; @@ -79,8 +76,6 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, } while (retry--); if (retry < 0) { - dev_err(&data->client->dev, - "Firmware fail to indicate command completion\n"); ret = -EIO; goto exit_unlock; } @@ -92,11 +87,11 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, */ if (msg->read) { for (i = 0; i < 4; i++) { - ret = i2c_smbus_read_byte_data(data->client, - SBRMI_OUTBNDMSG1 + i); + ret = regmap_read(data->regmap, + SBRMI_OUTBNDMSG1 + i, &bytes); if (ret < 0) goto exit_unlock; - msg->data_out |= ret << i * 8; + msg->data_out |= bytes << i * 8; } } @@ -104,8 +99,8 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the * ALERT to initiator */ - ret = i2c_smbus_write_byte_data(data->client, SBRMI_STATUS, - sw_status | SW_ALERT_MASK); + ret = regmap_write(data->regmap, SBRMI_STATUS, + sw_status | SW_ALERT_MASK); exit_unlock: mutex_unlock(&data->lock); diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-core.h index 27165d3bb20f..bbb6bb1cefde 100644 --- a/drivers/misc/amd-sbi/rmi-core.h +++ b/drivers/misc/amd-sbi/rmi-core.h @@ -9,6 +9,7 @@ #include #include #include +#include /* SB-RMI registers */ enum sbrmi_reg { @@ -47,7 +48,7 @@ enum sbrmi_msg_id { /* Each client has this additional data */ struct sbrmi_data { - struct i2c_client *client; + struct regmap *regmap; struct mutex lock; u32 pwr_limit_max; }; diff --git a/drivers/misc/amd-sbi/rmi-i2c.c b/drivers/misc/amd-sbi/rmi-i2c.c index 9ad4c8093399..7a9801273a4c 100644 --- a/drivers/misc/amd-sbi/rmi-i2c.c +++ b/drivers/misc/amd-sbi/rmi-i2c.c @@ -13,24 +13,24 @@ #include #include #include +#include #include "rmi-core.h" -static int sbrmi_enable_alert(struct i2c_client *client) +static int sbrmi_enable_alert(struct sbrmi_data *data) { - int ctrl; + int ctrl, ret; /* * Enable the SB-RMI Software alert status * by writing 0 to bit 4 of Control register(0x1) */ - ctrl = i2c_smbus_read_byte_data(client, SBRMI_CTRL); - if (ctrl < 0) - return ctrl; + ret = regmap_read(data->regmap, SBRMI_CTRL, &ctrl); + if (ret < 0) + return ret; if (ctrl & 0x10) { ctrl &= ~0x10; - return i2c_smbus_write_byte_data(client, - SBRMI_CTRL, ctrl); + return regmap_write(data->regmap, SBRMI_CTRL, ctrl); } return 0; @@ -55,17 +55,24 @@ static int sbrmi_i2c_probe(struct i2c_client *client) { struct device *dev = &client->dev; struct sbrmi_data *data; + struct regmap_config sbrmi_i2c_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + }; int ret; data = devm_kzalloc(dev, sizeof(struct sbrmi_data), GFP_KERNEL); if (!data) return -ENOMEM; - data->client = client; mutex_init(&data->lock); + data->regmap = devm_regmap_init_i2c(client, &sbrmi_i2c_regmap_config); + if (IS_ERR(data->regmap)) + return PTR_ERR(data->regmap); + /* Enable alert for SB-RMI sequence */ - ret = sbrmi_enable_alert(client); + ret = sbrmi_enable_alert(data); if (ret < 0) return ret; From patchwork Mon Mar 3 10:58:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13998579 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2075.outbound.protection.outlook.com [40.107.237.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B80E01F4630; Mon, 3 Mar 2025 10:59:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999592; cv=fail; b=nlkV+7zGLnk3SrZYEk3QI7cffg5Q5eQleG2FC59cZR8f0M/9zJ34YBK4hA5v64vDVv4DHiqPmJKNnZCxC5DbZb0qYRan01G233i/R9m1+7qXnNAXudgWogWLhM9Z+cMhRcuCCc9r7mDf2V+o5aajPMoeuyWy95ZGdL2AeYUxN1s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999592; c=relaxed/simple; bh=5GtngUwv/pFLVs/5jP4e1YTBT+QZloysFbMq2j+bxzk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gUmN6niLJ0kgzUhHZyy63CwNrH4c5T8DDnteY/RoCXQM9DXQ2YdJQRpA3Vxc2fba4zd9fy7DP28Xv+Ta5k7iM24iH5IYuiy9JKbbJkMr4n0TgmmLcW+mmCGuEOppcDilE1NK9gnen6vm63kPjSagNM8vhWpSLvITdZm76bG49lQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=b0cz2tci; arc=fail smtp.client-ip=40.107.237.75 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="b0cz2tci" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=A3yeuh7s/6HvT9hx02xjskBrNhajO8Jy16RIpwrjJywGPEiRi7a971C2STFvSzsGPADXEsS23QtmIGoOiZxsZtd85KEp//sTxQBrmVCxHvPfIrDEtjvNBmo+u5m1gp6nyNsoNRr1nQmEZuIFGWkupKSuDYQEwl+0MimeC1aoPm79QNYLZ+njcaHIEfmW2Cl3mpnxbttUz6MuPzDWRxdy1q3Tc4eRFCLQwkuTFljoEX/9a4REJdy05BlB5m08odbUzG67/8fB/GeRGLgwn61RISqOmpznpZfQ/9lwcQcjDXFX+hgPeAlouHRhFL65J0VMzQwgzUacg+ghrXxWbLcp3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=g1pRsfusff5dmd7COF46Efmf3bQtvGWyrIdbo/pp59w=; b=QfkJaUefh+eHXqtpfrHq8YewN58O77R9UzgqCWvc6/tKmIW7aDAtLFs11ryfZAUCm/Z9PgSuqZvF4kiz9GBQok22l5yvjZ593kZNuk8g6hTPuPm4iom3FgtSQQdC2RdObEeEKjjE7nyd5VwwfD4TRUC/WLWBkClxfZzypVI33/9bLVZHiE92tiNlFIZQGpQDOj8WHeZTEjX1LP1WbJ7ebMOrMkpm2esTmh6RxtV7hFje1r8Wgpnzt0ungsnMkn4zl+ogRSCAl6DKU01+FYRvm1/8mjN0RTgE47N16oA8KZBcAHEmpJXOHe95vNzGPQ3XFJsiyPnJphFzkHIuiDRVGQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g1pRsfusff5dmd7COF46Efmf3bQtvGWyrIdbo/pp59w=; b=b0cz2tci3c6oUr0wbuUjWlefFvn7R9nnzIVZz7406Wu9I3ztRTtGJYLMVkaBEZ5NveYm1P31vWM8RxdKckPDAgibFCsBHeJsR2gVVwuuu6bqmtIM1B+7Qqo0+Xh4lXIFxA3EkTetpOJfQ+DFDALv2dbV7DmJd4gIZwkiKtCjwHA= Received: from PH8PR07CA0030.namprd07.prod.outlook.com (2603:10b6:510:2cf::16) by DS0PR12MB6389.namprd12.prod.outlook.com (2603:10b6:8:cf::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8466.20; Mon, 3 Mar 2025 10:59:44 +0000 Received: from SN1PEPF00036F3D.namprd05.prod.outlook.com (2603:10b6:510:2cf:cafe::30) by PH8PR07CA0030.outlook.office365.com (2603:10b6:510:2cf::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8489.29 via Frontend Transport; Mon, 3 Mar 2025 10:59:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F3D.mail.protection.outlook.com (10.167.248.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Mon, 3 Mar 2025 10:59:44 +0000 Received: from amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 3 Mar 2025 04:59:40 -0600 From: Akshay Gupta To: , CC: , , , , , , , Akshay Gupta Subject: [PATCH v5 05/11] misc: amd-sbi: Optimize the wait condition for mailbox command completion Date: Mon, 3 Mar 2025 10:58:56 +0000 Message-ID: <20250303105902.215009-6-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250303105902.215009-1-akshay.gupta@amd.com> References: <20250303105902.215009-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3D:EE_|DS0PR12MB6389:EE_ X-MS-Office365-Filtering-Correlation-Id: f3916f5f-6a91-4d1e-8df3-08dd5a428185 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|36860700013; X-Microsoft-Antispam-Message-Info: Kk4LudVBAwxksmWvydYZ7HZdT4PuWaaDKfGTdntyRhIO8qR2+EVWoFIM51fAfsSJ7XGlCxLA8A6WXlQgSh1V2UsZrS/oeWbY/7B93uGK/C1nuOWkFozOUcWEoROBnp4uYNt0PpzjhV6IsCFD+ZCQPs6N9U3tRf8p0dsgW0uIH+kxvD3m9D0uIxXCOE/+/xSHmGWLVKsuhJKBhwGO+sssu7l0XuDedDseiGXFM22cEPdHYjC8MGTGjApzEsiCcZlM6sV63HP3fOJB3Hg9naTrB757qQEoOI91Jnqc+2/mALvyDyiGXCjlnQkpuz/2KCUOOCiNeJ9mftkox1ziiwISgnwtU9r+jKnYMkg4PvOrn2zoBsmWJHC66eMJ9kIDuvL1OmatcsAjTRMDALsPXWGTOEjjN+9Z/ZIzNtX351i4PxKsGqCBbKxa/SrjXMfOVTq36HOeZ3bA5LvunST8wkrLZsqsl1mXNrd5ZrH8V9nsgc2BuGexFP1UyEXZGswdu6VaoFnxtReiFCpDOleW3NwvKpfh7SOAr/xdOOah5HzAqMAEYLOXV/Qkr803jcV0+9f16ZtXXgY6JP6ODDMwf6tNszjZeH9afO6HSQnqKOy//lSnBCIrLviAXZKAmB823MDfnK0xRpRaZvcz2DBbnqAl5RW8JMxbq8v1Gqf2LVJYqAbocUjxOlX5tHr8rj+Grm+1gV+WXoOTZP8IsTw7oY/f8PioYsQ7bNhrEqunItgA5cgUiOXvWlGrs0gdRcXEstCJ0JBgN6WlbNLog0J+4kNPkdb6OHDrZYGTD1QcBZo0YySoH3Pox8X2//pk0iU/MyCk2pZZG4spOxF4m+RVGrEyDc89mo9WBcH47kATiqWerc/aD9+tBZ4Y+lLU8vjCx/1+uByMhAtxCUgY03aT58uKQxYFyvykfdBXwCYfxj0sHDUOeH6UqzB/rM0yIbDAA4xJ8W7U0hIb8TMF7B12A9NL1D6aAaQ9Bdiq7F2GvZrVY3dmFeGT34tXv1aPsvCEifXaC7G8sDXHBsvFRoz/SOyjPiAggQ70+UIV0UvIeR0Rhpn6NvxSD3ApMQ2szBfxDKlkaB+iBKCL/eCzhGy2mH1/2VMhXbE+MwrC55TeLwYkac6NOb9pSu4V/FNOLRj9hYReRHrDdmmNBwCB3kUaQjeYIJytvPQ/8CJ+uvOtbzO7TYY+2LYjvMH/acQbNSvsEnyLAo71OUwTJy6d3LcZD+KPkMQWXffM/pCWE9ftmubrQz7BioENV8UCi0blliuGf0cMM/i27aih497acOjg3bx2AkxOPt/I5xHpx230lWTcwcNOoH4FrmDla2ml2TwDv4FacSLa5iSjRjANfI5tcfApV46YVBWOYfS13+Eb/5G7H15Xo9NHokc84GD6s9D6/kL5fzDmgIdkvgPeAPTAlTJ3zWs09VQqQsLNt6rXKZHcNLO9xRdBGazogtAxyMniASZ+3hqJeN5+iKKwG5mIEMTv7e6b3MsD6TnA6hSAsh/zuKY= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2025 10:59:44.3052 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f3916f5f-6a91-4d1e-8df3-08dd5a428185 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F3D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6389 - optimize the wait condition to indicate command completion by replacing the do while loop with regmap subsystem API regmap_read_poll_timeout() Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v4: - Previously patch 3 Changes since v3: - New patch as per suggestion from Arnd drivers/misc/amd-sbi/rmi-core.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c index 663ab9176d95..1d5e2556ab88 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -23,7 +23,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg) { unsigned int bytes; - int i, ret, retry = 10; + int i, ret; int sw_status; u8 byte; @@ -64,21 +64,10 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * an ALERT (if enabled) to initiator (BMC) to indicate completion * of the requested command */ - do { - ret = regmap_read(data->regmap, SBRMI_STATUS, &sw_status); - if (sw_status < 0) { - ret = sw_status; - goto exit_unlock; - } - if (sw_status & SW_ALERT_MASK) - break; - usleep_range(50, 100); - } while (retry--); - - if (retry < 0) { - ret = -EIO; + ret = regmap_read_poll_timeout(data->regmap, SBRMI_STATUS, sw_status, + sw_status & SW_ALERT_MASK, 500, 2000000); + if (ret) goto exit_unlock; - } /* * For a read operation, the initiator (BMC) reads the firmware From patchwork Mon Mar 3 10:58:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13998581 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2063.outbound.protection.outlook.com [40.107.94.63]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06B6F1F473A; Mon, 3 Mar 2025 10:59:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999596; cv=fail; b=UnbZUMS7k+LDd3ILy+fiJLGV67ro/OM1+T7q5RDY3UWyky7A/laSFwJauYuQ9F+t94QG+uJYJeZa9IgUrTxKURMAyB/n0rGhGp/taFmzXgDRDQULvHK1ioHAN+6Q/KtIB5WtKKuOpq1Hk6n5CkZ1a+dsQUa9NvbCHV2nLGb8JrU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999596; c=relaxed/simple; bh=ZEb8aioKH5rpgZaWvCEtVTwH+74krNXWMEBNVrnuPAY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XjFraHiM/oeM986wgpl0axds99KTiqDCqJgovGidOVDGB+TAYUl8zUfSInEDNYRwDIYcavRPtpzRo7G56Zq113h1GZLLZBJfi0YWplQTRYV3Wb7Lw61jzA3bU19YvpwiSkwR+yrJ2LXkIvNUvWZuy+qKW4m+4q2taD2g3VedqGo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=tlpywUyC; arc=fail smtp.client-ip=40.107.94.63 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="tlpywUyC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=s65E+n/iBK5SpI3r19bh91G/N/PB/xaX+9A1fg8oUss9BnOrNGvvAl6hsFlivTvKwWxns5qhanWk5H93JrCVazd7r16SKK+Y72Hkjl0RT8cUFdMCquSqoLid2//KQ9rNTVeCOJ4Z9io/AKkXIJBuTUo1PoEwtcX0lrLu3YC75InB5ibjPgoxsjvPWJ9prkT8KJ9QMCLJyVwHuFVOqvkXEhYWUq9DAIFSG27lrJYKVC5KnbBCVmAUUEDpsBsDO++uZIfeMaWs5epwbHPIM8RNJklJn2BjMLdPjfSjJ3sw/6spY4a1YMukgoc+QxDw56W48Ydlw2iKZ1dZeGloN+T3UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AFpu8M+oPKWaeK7kDlvv5YCACza9rm706Ex/WzpHtxY=; b=DGhdF7nlom7ejHjQ8pF2eh6irMtsgnka5ODRxxTw3G6WniBRmin5aXQRwUZXU2KSftN/tomUnXKMdvYHzO3wm1YoJBZKxb/XNF9jUlKyw1KksfNb8fBh1gec8I3+6c+0LN2C/4PLglAE3RkX651wjFNUOUJ01dTmsz8Ynzm1Ag32SilZNjy7I1T3A0F9uGrKznK5eBbpYbU9ieO2BHG13M0vjTTTG4JZCKJVMLXmrdkTYQ8q6alFry00fHMAr6nbjJZAMn7o1yl4jNVPt7QpRwtHdRExKA8JC1JpSDo+IW83BOr7ZZWQwJB0Ai8QYi/CeePw5YnJk3ozzAGaujyriw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AFpu8M+oPKWaeK7kDlvv5YCACza9rm706Ex/WzpHtxY=; b=tlpywUyCX1yvSQAkVfEaYTcZ2h3zVbPzmxrpF8HnGNJ2oRWVEGL1PpHlqQjguxVp1LLwKvF8YCaseEqZ+P5WD2W9u10nvugOegK2A5a/VN428G0pPF5LpSK12HqAZKo6/kyOk4nkmVg5bA2UbuSu67iqWdv811QRmi1yIcMg9qs= Received: from PH7P221CA0013.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:32a::9) by CY5PR12MB6203.namprd12.prod.outlook.com (2603:10b6:930:24::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.25; Mon, 3 Mar 2025 10:59:49 +0000 Received: from SN1PEPF00036F3C.namprd05.prod.outlook.com (2603:10b6:510:32a:cafe::f4) by PH7P221CA0013.outlook.office365.com (2603:10b6:510:32a::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8489.27 via Frontend Transport; Mon, 3 Mar 2025 10:59:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F3C.mail.protection.outlook.com (10.167.248.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Mon, 3 Mar 2025 10:59:48 +0000 Received: from amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 3 Mar 2025 04:59:44 -0600 From: Akshay Gupta To: , CC: , , , , , , , Akshay Gupta Subject: [PATCH v5 06/11] misc: amd-sbi: Add support for AMD_SBI IOCTL Date: Mon, 3 Mar 2025 10:58:57 +0000 Message-ID: <20250303105902.215009-7-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250303105902.215009-1-akshay.gupta@amd.com> References: <20250303105902.215009-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3C:EE_|CY5PR12MB6203:EE_ X-MS-Office365-Filtering-Correlation-Id: 85b05823-5431-4b73-2c55-08dd5a4283c3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: wD4r8jGuGEOmX5y1KWs72dkGUTpT9UR52kOK4ZhImtYhqtzMcx7AtI/r+9nYgpTKgycZYaN8/Bt/74jeNlfDtg5MN6RthgfjVtroLltGnPavYY9ycXxjVSXBssTR3/lV6Rf3jf61hPoDAPR2I4uORUpz+3bjxos0fuQ/H2oZbPJ+GUas2MGhJrscJyplh21fVmwK0YrVqa9/9E3GjnNPR3cYomxlpCzwHCOVOiro25ZBn+Cwz0G137VdSyIMAqE8ThF+hCX3S1rUJKi4V05jaQdYXitVaJ+c5eVO0MYenDzicGWksN7vSs+7m5S1mnhC681ri38nu+98etzWeMC66AtXKczBcumcCRNkJzwl9r2SipHZKLSn51kFcRd1hQVZ2b0FY0rMb7aAswyxHoW+r9J54HJSdJmIgAOMfGkY02+12jRHvC25peYOpsqYEABI8OPQVh4UTHKH+rj1xl/MwpEHu+E1nyjl38mL1j/BtVzf/NUs4KmstJeMGtuq2tAvIa3l/SYPdfaDUPOqyo0hwnJpnT0TkdVeO1aN10Y5Kws8+sX4vW/gKe7t07p2v3gD+PY7SLVaKb95nFvPhU1arF/FyylHKddBb+hpCKAsqnfN2OAQ/5uKU6HxYgvayfkNYGLbDSAyyxNZCs7y5H2jJXLzV5VrCxr6z3CLEezV7a/Zk5jvMzi5CVFMHTJFqEkNh27gJeBiiFZKZN3Mc3uujsJLQAgjCQN6GvOFuXsmT7VvhPXoyjpi7JCt+zl0x156am3IoztKHnfBwpMdglx5KNcSHDMxY6IRWI/wpZ7isC4yFhdwtpZCCqGw0ZH0hJruVcVf+JpUARTO0vSynm+KUD0WrbIrswYraIGi5Ve9xs09jnBEDT0f827NLoiQKU3shfUBijti3WN9324sZG8xGfqt2nRLuBHdLu6+KW0psTgV4aG/RMKlNQsqKABrH+LiaqE7ZhcZckGExZeiKbyucr1HnkAzJeGj/nin3wenZnYyzwxODmosTwat2wWAV+ZQdsNEo/9dxOSdM/7/S122TwacAIx7axaxKULP87FpowrFJWQt14R7gg7PgLoY5uJEug0jZOL4Fx6JbIHu8nnD7Y8kEr9suj0Q0rzkaA0QWdl2EMR7trZthfppRYMcrLo8+nQsZxSBqq1lcpZFXNNPJg8gayoJ8L4hy0qW8V7v9AJDaPttpgH9zvqOpNnoaBnFzNlayiG2LXhYwaP/u4eLTeN6jJHKidsA5yj/SrcBYGRnzGHrwCm5domJtOh8CZKMkiqkftsOZo1z5dgQIHBDlsUYCjxcgLWkrzmW92574ykNuo95HanyZ7Lj0LQ4uTq8IJk6sT6PaL2JIxWyapm+yj6Hcp8pQWS/u8tSpyOjhjFFfAcFZ44q7EDQecHR26VgTxsan5W7JvTeSMyzG+TE3AP1V8vJMdkYLO0vmFn7a0MS+OGTDiiBTymbvrsElnw2ytswcUpojx2I4bvim2DUhpe8CWWZLQ1egzPnAE150dE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2025 10:59:48.0488 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 85b05823-5431-4b73-2c55-08dd5a4283c3 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F3C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6203 The present sbrmi module only support reporting power via hwmon. However, AMD data center range of processors support various system management functionality using custom protocols defined in Advanced Platform Management Link (APML) specification. Register a miscdevice, which creates a device /dev/sbrmiX with an IOCTL interface for the user space to invoke the APML Mailbox protocol, which is already defined in sbrmi_mailbox_xfer(). The APML protocols depend on a set of RMI registers. Having an IOCTL as a single entry point will help in providing synchronization among these protocols as multiple transactions on RMI register set may create race condition. Support for other protocols will be added in subsequent patches. Open-sourced and widely used https://github.com/amd/esmi_oob_library will continue to provide user-space programmable API. Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v4: - Address review comment - Address Greg review comments - Not initialize ret - return on error - Previously patch 4 - Fix documentation warning Changes since v3: - Previously patch 3 - Documentation and comments changes Changes since v2: - update the MACROS name as per feedback Changes since v1: - Previously patch 5 - Add IOCTL description in ioctl-number.rst - Split patch as per suggestion. Documentation/misc-devices/index.rst | 1 + .../userspace-api/ioctl/ioctl-number.rst | 2 + drivers/misc/amd-sbi/rmi-core.c | 81 +++++++++++++++++-- drivers/misc/amd-sbi/rmi-core.h | 15 ++-- drivers/misc/amd-sbi/rmi-hwmon.c | 15 ++-- drivers/misc/amd-sbi/rmi-i2c.c | 25 +++++- include/uapi/misc/amd-apml.h | 66 +++++++++++++++ 7 files changed, 178 insertions(+), 27 deletions(-) create mode 100644 include/uapi/misc/amd-apml.h diff --git a/Documentation/misc-devices/index.rst b/Documentation/misc-devices/index.rst index 8c5b226d8313..081e79415e38 100644 --- a/Documentation/misc-devices/index.rst +++ b/Documentation/misc-devices/index.rst @@ -12,6 +12,7 @@ fit into other categories. :maxdepth: 2 ad525x_dpot + amd-sbi apds990x bh1770glc c2port diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst index 6d1465315df3..5692b50b3c6f 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -392,6 +392,8 @@ Code Seq# Include File Comments 0xF8 all arch/x86/include/uapi/asm/amd_hsmp.h AMD HSMP EPYC system management interface driver +0xF9 00-0F uapi/misc/amd-apml.h AMD side band system management interface driver + 0xFD all linux/dm-ioctl.h 0xFE all linux/isst_if.h ==== ===== ======================================================= ================================================================ diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c index 1d5e2556ab88..c39a29d90c27 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -7,7 +7,10 @@ */ #include #include +#include #include +#include +#include #include #include #include "rmi-core.h" @@ -20,7 +23,7 @@ #define TRIGGER_MAILBOX 0x01 int rmi_mailbox_xfer(struct sbrmi_data *data, - struct sbrmi_mailbox_msg *msg) + struct apml_message *msg) { unsigned int bytes; int i, ret; @@ -44,8 +47,8 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * Command Data In[31:0] to SBRMI::InBndMsg_inst[4:1] * SBRMI_x3C(MSB):SBRMI_x39(LSB) */ - for (i = 0; i < 4; i++) { - byte = (msg->data_in >> i * 8) & 0xff; + for (i = 0; i < AMD_SBI_MB_DATA_SIZE; i++) { + byte = msg->data_in.reg_in[i]; ret = regmap_write(data->regmap, SBRMI_INBNDMSG1 + i, byte); if (ret < 0) goto exit_unlock; @@ -74,13 +77,13 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1] * {SBRMI_x34(MSB):SBRMI_x31(LSB)}. */ - if (msg->read) { - for (i = 0; i < 4; i++) { + if (msg->data_in.reg_in[AMD_SBI_RD_FLAG_INDEX]) { + for (i = 0; i < AMD_SBI_MB_DATA_SIZE; i++) { ret = regmap_read(data->regmap, SBRMI_OUTBNDMSG1 + i, &bytes); if (ret < 0) - goto exit_unlock; - msg->data_out |= bytes << i * 8; + break; + msg->data_out.reg_out[i] = bytes; } } @@ -90,8 +93,70 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, */ ret = regmap_write(data->regmap, SBRMI_STATUS, sw_status | SW_ALERT_MASK); - exit_unlock: mutex_unlock(&data->lock); return ret; } + +static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) +{ + int __user *arguser = (int __user *)arg; + struct apml_message msg = { 0 }; + bool read = false; + int ret; + + struct sbrmi_data *data = container_of(fp->private_data, struct sbrmi_data, + sbrmi_misc_dev); + if (!data) + return -ENODEV; + + /* Copy the structure from user */ + if (copy_struct_from_user(&msg, sizeof(msg), arguser, + sizeof(struct apml_message))) + return -EFAULT; + + /* Is this a read/monitor/get request */ + if (msg.data_in.reg_in[AMD_SBI_RD_FLAG_INDEX]) + read = true; + + switch (msg.cmd) { + case 0 ... 0x999: + /* Mailbox protocol */ + ret = rmi_mailbox_xfer(data, &msg); + break; + default: + return -EINVAL; + } + + /* Copy results back to user only for get/monitor commands and firmware failures */ + if ((read && !ret) || ret == -EPROTOTYPE) { + if (copy_to_user(arguser, &msg, sizeof(struct apml_message))) + ret = -EFAULT; + } + return ret; +} + +static const struct file_operations sbrmi_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = sbrmi_ioctl, + .compat_ioctl = sbrmi_ioctl, +}; + +int create_misc_rmi_device(struct sbrmi_data *data, + struct device *dev) +{ + data->sbrmi_misc_dev.name = devm_kasprintf(dev, + GFP_KERNEL, + "sbrmi-%x", + data->dev_static_addr); + data->sbrmi_misc_dev.minor = MISC_DYNAMIC_MINOR; + data->sbrmi_misc_dev.fops = &sbrmi_fops; + data->sbrmi_misc_dev.parent = dev; + data->sbrmi_misc_dev.nodename = devm_kasprintf(dev, + GFP_KERNEL, + "sbrmi-%x", + data->dev_static_addr); + data->sbrmi_misc_dev.mode = 0600; + + return misc_register(&data->sbrmi_misc_dev); +} diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-core.h index bbb6bb1cefde..e3a11575d19e 100644 --- a/drivers/misc/amd-sbi/rmi-core.h +++ b/drivers/misc/amd-sbi/rmi-core.h @@ -6,10 +6,12 @@ #ifndef _SBRMI_CORE_H_ #define _SBRMI_CORE_H_ +#include #include #include #include #include +#include /* SB-RMI registers */ enum sbrmi_reg { @@ -48,18 +50,15 @@ enum sbrmi_msg_id { /* Each client has this additional data */ struct sbrmi_data { + struct miscdevice sbrmi_misc_dev; struct regmap *regmap; + /* Mutex locking */ struct mutex lock; u32 pwr_limit_max; + u8 dev_static_addr; }; -struct sbrmi_mailbox_msg { - u8 cmd; - bool read; - u32 data_in; - u32 data_out; -}; - -int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg); +int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_message *msg); int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data); +int create_misc_rmi_device(struct sbrmi_data *data, struct device *dev); #endif /*_SBRMI_CORE_H_*/ diff --git a/drivers/misc/amd-sbi/rmi-hwmon.c b/drivers/misc/amd-sbi/rmi-hwmon.c index 720e800db1f0..ee0c3b72174c 100644 --- a/drivers/misc/amd-sbi/rmi-hwmon.c +++ b/drivers/misc/amd-sbi/rmi-hwmon.c @@ -6,6 +6,7 @@ */ #include #include +#include #include "rmi-core.h" /* Do not allow setting negative power limit */ @@ -15,7 +16,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { struct sbrmi_data *data = dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg = { 0 }; + struct apml_message msg = { 0 }; int ret; if (!data) @@ -24,7 +25,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, if (type != hwmon_power) return -EINVAL; - msg.read = true; + msg.data_in.reg_in[AMD_SBI_RD_FLAG_INDEX] = 1; switch (attr) { case hwmon_power_input: msg.cmd = SBRMI_READ_PKG_PWR_CONSUMPTION; @@ -35,7 +36,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, ret = rmi_mailbox_xfer(data, &msg); break; case hwmon_power_cap_max: - msg.data_out = data->pwr_limit_max; + msg.data_out.mb_out[AMD_SBI_RD_WR_DATA_INDEX] = data->pwr_limit_max; ret = 0; break; default: @@ -44,7 +45,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, if (ret < 0) return ret; /* hwmon power attributes are in microWatt */ - *val = (long)msg.data_out * 1000; + *val = (long)msg.data_out.mb_out[AMD_SBI_RD_WR_DATA_INDEX] * 1000; return ret; } @@ -52,7 +53,7 @@ static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long val) { struct sbrmi_data *data = dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg = { 0 }; + struct apml_message msg = { 0 }; if (!data) return -ENODEV; @@ -68,8 +69,8 @@ static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, val = clamp_val(val, SBRMI_PWR_MIN, data->pwr_limit_max); msg.cmd = SBRMI_WRITE_PKG_PWR_LIMIT; - msg.data_in = val; - msg.read = false; + msg.data_in.mb_in[AMD_SBI_RD_WR_DATA_INDEX] = val; + msg.data_in.reg_in[AMD_SBI_RD_FLAG_INDEX] = 0; return rmi_mailbox_xfer(data, &msg); } diff --git a/drivers/misc/amd-sbi/rmi-i2c.c b/drivers/misc/amd-sbi/rmi-i2c.c index 7a9801273a4c..919ff7f61225 100644 --- a/drivers/misc/amd-sbi/rmi-i2c.c +++ b/drivers/misc/amd-sbi/rmi-i2c.c @@ -38,15 +38,15 @@ static int sbrmi_enable_alert(struct sbrmi_data *data) static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) { - struct sbrmi_mailbox_msg msg = { 0 }; + struct apml_message msg = { 0 }; int ret; msg.cmd = SBRMI_READ_PKG_MAX_PWR_LIMIT; - msg.read = true; + msg.data_in.reg_in[AMD_SBI_RD_FLAG_INDEX] = 1; ret = rmi_mailbox_xfer(data, &msg); if (ret < 0) return ret; - data->pwr_limit_max = msg.data_out; + data->pwr_limit_max = msg.data_out.mb_out[AMD_SBI_RD_WR_DATA_INDEX]; return ret; } @@ -81,8 +81,24 @@ static int sbrmi_i2c_probe(struct i2c_client *client) if (ret < 0) return ret; + data->dev_static_addr = client->addr; dev_set_drvdata(dev, data); - return create_hwmon_sensor_device(dev, data); + ret = create_hwmon_sensor_device(dev, data); + if (ret < 0) + return ret; + return create_misc_rmi_device(data, dev); +} + +static void sbrmi_i2c_remove(struct i2c_client *client) +{ + struct sbrmi_data *data = dev_get_drvdata(&client->dev); + + misc_deregister(&data->sbrmi_misc_dev); + /* Assign fops and parent of misc dev to NULL */ + data->sbrmi_misc_dev.fops = NULL; + data->sbrmi_misc_dev.parent = NULL; + dev_info(&client->dev, "Removed sbrmi-i2c driver\n"); + return; } static const struct i2c_device_id sbrmi_id[] = { @@ -105,6 +121,7 @@ static struct i2c_driver sbrmi_driver = { .of_match_table = of_match_ptr(sbrmi_of_match), }, .probe = sbrmi_i2c_probe, + .remove = sbrmi_i2c_remove, .id_table = sbrmi_id, }; diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h new file mode 100644 index 000000000000..5721aaa0c6bd --- /dev/null +++ b/include/uapi/misc/amd-apml.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (C) 2021-2024 Advanced Micro Devices, Inc. + */ +#ifndef _AMD_APML_H_ +#define _AMD_APML_H_ + +#include + +/* These are byte indexes into data_in and data_out arrays */ +#define AMD_SBI_RD_WR_DATA_INDEX 0 +#define AMD_SBI_REG_OFF_INDEX 0 +#define AMD_SBI_REG_VAL_INDEX 4 +#define AMD_SBI_RD_FLAG_INDEX 7 + +#define AMD_SBI_MB_DATA_SIZE 4 + +struct apml_message { + /* message ids: + * Mailbox Messages: 0x0 ... 0x999 + */ + __u32 cmd; + + /* + * 8 bit data for reg read, + * 32 bit data in case of mailbox, + */ + union { + __u32 mb_out[2]; + __u8 reg_out[8]; + } data_out; + + /* + * [0]...[3] mailbox 32bit input + * [7] read/write functionality + */ + union { + __u32 mb_in[2]; + __u8 reg_in[8]; + } data_in; +} __attribute__((packed)); + +/* + * AMD sideband interface base IOCTL + */ +#define SB_BASE_IOCTL_NR 0xF9 + +/** + * DOC: SBRMI_IOCTL_CMD + * + * @Parameters + * + * @struct apml_message + * Pointer to the &struct apml_message that will contain the protocol + * information + * + * @Description + * IOCTL command for APML messages using generic _IOWR + * The IOCTL provides userspace access to AMD sideband protocols + * The APML RMI module checks whether the cmd is + * - Mailbox message read/write(0x0~0x999) + * - returning "-EFAULT" if none of the above + */ +#define SBRMI_IOCTL_CMD _IOWR(SB_BASE_IOCTL_NR, 0, struct apml_message) + +#endif /*_AMD_APML_H_*/ From patchwork Mon Mar 3 10:58:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13998580 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2041.outbound.protection.outlook.com [40.107.244.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EF1E1F4E2F; Mon, 3 Mar 2025 10:59:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999596; cv=fail; b=HRSIDtFUg2gJOmoZa04wdzTfusY3CR4CnTs709Z5V3OGsgV/X3VfCgUhCTvnDsJgCufT/7vq6MOfoLjMLlKR5KbTFqBJnTZRgXANVW3d0cPHKwApLO/dyEZcOuO4nvoFQL+d8gistoJlGKff74pnb4YJUZv7TtrSl1UfknoNwwk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999596; c=relaxed/simple; bh=6czvyvz/aVtniO/PdwmvZ4uROFYXiuR7U6rd+M+6+6g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XEIh2wWP4q5deXhKhgn5J9Xem1RUcUn56NaXgx6Gl1+OnpHHcJ2qAjs+hIEncGyjHE91FngaEKIq89SaXvd42x3jj+7zwWONpy0fppZkxqOqjxf+NM9/nf2M905+nySp3ZO00JMOD7uTS7rx+7j6SsQCwxNRq7GFY/bYERrdcqA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=VZrF0NCD; arc=fail smtp.client-ip=40.107.244.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="VZrF0NCD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fWVlDLdl8xsgArS85jwh3uKSQxsxhGtwtQB6rgiilOO5kmU5AB8VE1tR2CslWZsudOqd7s8YJNcXRCvPCAxDlnB0KJ0wvz8Ce5CZXRWPHp43LF3ba/WNXjTpeAOBy52EnovO+3b6xLMnyS1V/D2qlts/sBKdger9w2jeXZstoUon5lx0hNRyH0GFLJmlvKvMDxcMflFPIrMI8aC96XXFU399job2A0G1Br8o+9E/LO9QeGP8zH5AZzWiM4s1Skkp3IVfKwzShFb7O/HPzOs7JP8jdA4FIVJy0iLohkWoM1t3wToSlGO6HRXGIijCrSRg7rCJvxCIEkFDDtWjtOUELQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=si6ylr3W9qfOCdGH6B1BkjXMtHC1yKl6Atu7JYBfS+M=; b=b1a/BHvJaaXZU8rs9yi/U51EYId1j0v/g+6o+huwk3jwq/yueC1ucOyBLFIBAG5f2NxHOYG97S1H9WADfXvmJCfj+1qy6/FuEvX/Mabh5Dhg7elPfvrXZjY8HWfYr8JNwB5dhZZ2p7nQ3JU6BH3MOy8RsRT8FDnFITV1cyThL9huuklYhy1Hpm5fQNLbcfCxLP14Rvy7AIBLSZ7G9TeLVP7YsmViJrEByKi318XZ3Oj0IJS0o+1pUF6TYgpUF4m/E2WEQAcS+Ut6dKCh5LEq1we6ZPhF3vbonZeCdCLyA2vLCVziTMr26ROhROz3JxLlJ8iRZ/BQ4HmUpZ33gTeEig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=si6ylr3W9qfOCdGH6B1BkjXMtHC1yKl6Atu7JYBfS+M=; b=VZrF0NCDWRFhyW90EuFiXzM5qxYcX7Cy+xudB3wXFHAyIggBZDu+f38NuwbFkbCjHnrXQvIRCGCrCukyGdMeFiVGm5PTiNxj4zszWLdRzBVUnJr/zNoZCZnkPQOGuvsz9CHJMm4BPYts7JdmBC4bTfYr7UlqcIndtPL1biN7jyY= Received: from PH7P220CA0015.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:326::20) by MN2PR12MB4095.namprd12.prod.outlook.com (2603:10b6:208:1d1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.25; Mon, 3 Mar 2025 10:59:52 +0000 Received: from SN1PEPF00036F3E.namprd05.prod.outlook.com (2603:10b6:510:326:cafe::43) by PH7P220CA0015.outlook.office365.com (2603:10b6:510:326::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8489.26 via Frontend Transport; Mon, 3 Mar 2025 10:59:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F3E.mail.protection.outlook.com (10.167.248.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Mon, 3 Mar 2025 10:59:51 +0000 Received: from amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 3 Mar 2025 04:59:48 -0600 From: Akshay Gupta To: , CC: , , , , , , , Akshay Gupta Subject: [PATCH v5 07/11] misc: amd-sbi: Add support for mailbox error codes Date: Mon, 3 Mar 2025 10:58:58 +0000 Message-ID: <20250303105902.215009-8-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250303105902.215009-1-akshay.gupta@amd.com> References: <20250303105902.215009-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3E:EE_|MN2PR12MB4095:EE_ X-MS-Office365-Filtering-Correlation-Id: de1b99d7-bb6a-4bcb-aecc-08dd5a4285f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: 4YhP6Q15/YSc7G/CTMJNK6Avy6HRkoEDZX+1AalEKwvFXddDb7TShPfxK1tFXSIgqx9mOXIg2vAWdBPMssEyf5xiwRsRlW2KRhRxNBdncItEBdyZRunat3suBO6apK5+RBooY5c/4Q3fMXomYfphxzYr86IT3+jaFv7yjdN/qyym3Xfvbzu0/993PmZzkImklE/yj9hHZHQuMoJ+XtKUj6Wq3rWUwxVDgndoQ6Zc7DM0EJs7jrzu9dlJ8EhgFdEe/zyj1/LwXxpDdg5ccoaH6pNZRfj8xNRzq24hQdKDC2nH4dQ/dBXqvhQV2na9u83RMo2jZxiPHGrl8WqoL58ggfIr64oSbpiYb6cMG1wdAiX/WjSkbCzK0g5ItP6vLYA5bw0E98iuQNTvmudCu+5m2REuY+MSyFrV+fKdz+gjDna/rB5u7+QEe3M738u0XcjH9LszXKiNWbsBUBLYjKKX1VAjhBDKbnXVy++AUeRXVToi9a1/01CEdcuR638ZCieeP4YA0868VGF36xXgVK9iL1CK48q+7Ag1/NYEut/MqKw6afiWkD4RL5q+tKbg1nXjc+WKEHAI5ABwKnree4Sxxk19+CocI92izUb45R5ZcZZcnzuDCwfleAdzjihNj+MQhMqLpoO1vQf4RZ7MS3b5h6ahAI4t0Rk54q/8dp2+DLm1q8QbWTJS57ETZa3GxxGKTPseWXIjConuWwRtZ6/gv7ER8IZ6BLSV+U7KypNY6qlE9Ta7oQBYNDkTh3QczrCH1VEESABtf8jYAGD7MR2Lz7RvX6bKHSx7BvyNnCF7O8gpREa913iNGJz8p+syqP5jb5q41gMw59z6SEHO7msMiEhwK7sRQsRuhu9ciVr4psn2lfPSy43uvXJlfgxyvCkjMwhAoFRBm9yyiViP1GZdLCDf3Ki87GRkQ127rsCCi90nPxdZ1Xfup8ZTB95Yy2vBds9FTKgAr+Z71H7l1YnivZGXNYUfto3OMdMOR1z6Cq/8EfuuBbDVIZ+sUue7qoBo/TjGSW6EoahTPbRJthTETaU3mDsgzRdvO1/+rsEpbYDmFLDNFGGexhGjwzMp6KgPAjB62sS/qZNCgejttDMn+/dY5SrUo2pzj7UxMVkmrjjWJesppGtwqrsIInh03OIOeP7Zz/BDJSvu/fjPHzu7I4rVKiZU9sWxlcRMLCThU3bKl2t94X+5SpOsoKnrsJYgRbQpYJnICWlvC09P46+gtQumQcjiPb+d8bUsybPbCtim27mYZ+4szNz0vNZBTGZsaffAdGpPzBj48YcRZEK0m5lXQdGLs/YnEPqSfohBzqhGGwPyoCcGils2iqZgQIfeFMrLwBMR9o+dGsrmKv9lmVUxefolOIrERBeECvMRlLMWiOVw5gv1H7lCzYas5vWrI5inhPRLy5MK0rQAK7gaXWQjbNmOLujOq5uF2qq+bDZrpot48Owd3ryryFzRz2bQ/IBkrffaNQwCIaj2y81Pppf/q+HvxqWx5H/iZAtNXnA= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2025 10:59:51.7705 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: de1b99d7-bb6a-4bcb-aecc-08dd5a4285f8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F3E.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4095 APML mailbox protocol returns additional error codes written by SMU firmware in the out-bound register 0x37. These errors include, invalid core, message not supported over platform and others. This additional error codes can be used to provide more details to user space. Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v4: - Previously patch 5 - Fix Documentation warning Changes since v3: - update ioctl comment description Changes since v1: - bifurcated from previous patch 5 drivers/misc/amd-sbi/rmi-core.c | 12 +++++++++++- include/uapi/misc/amd-apml.h | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c index c39a29d90c27..642fe762cf6f 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -25,13 +25,15 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_message *msg) { - unsigned int bytes; + unsigned int bytes, ec; int i, ret; int sw_status; u8 byte; mutex_lock(&data->lock); + msg->fw_ret_code = 0; + /* Indicate firmware a command is to be serviced */ ret = regmap_write(data->regmap, SBRMI_INBNDMSG7, START_CMD); if (ret < 0) @@ -72,6 +74,9 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, if (ret) goto exit_unlock; + ret = regmap_read(data->regmap, SBRMI_OUTBNDMSG7, &ec); + if (ret || ec) + goto exit_clear_alert; /* * For a read operation, the initiator (BMC) reads the firmware * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1] @@ -87,12 +92,17 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, } } +exit_clear_alert: /* * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the * ALERT to initiator */ ret = regmap_write(data->regmap, SBRMI_STATUS, sw_status | SW_ALERT_MASK); + if (ec) { + ret = -EPROTOTYPE; + msg->fw_ret_code = ec; + } exit_unlock: mutex_unlock(&data->lock); return ret; diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h index 5721aaa0c6bd..47a057226300 100644 --- a/include/uapi/misc/amd-apml.h +++ b/include/uapi/misc/amd-apml.h @@ -38,6 +38,10 @@ struct apml_message { __u32 mb_in[2]; __u8 reg_in[8]; } data_in; + /* + * Error code is returned in case of soft mailbox + */ + __u32 fw_ret_code; } __attribute__((packed)); /* @@ -60,6 +64,7 @@ struct apml_message { * The APML RMI module checks whether the cmd is * - Mailbox message read/write(0x0~0x999) * - returning "-EFAULT" if none of the above + * "-EPROTOTYPE" error is returned to provide additional error details */ #define SBRMI_IOCTL_CMD _IOWR(SB_BASE_IOCTL_NR, 0, struct apml_message) From patchwork Mon Mar 3 10:58:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13998582 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2081.outbound.protection.outlook.com [40.107.236.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA6D71F543F; Mon, 3 Mar 2025 11:00:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999603; cv=fail; b=N3Zgc8udVV8rVT68Iqa1MbeqR5uUMC7ELnpUo0Jh8JERqGbn6QCAqH07cTUEQoHIqGKko+39WMR6WDNLqONtAlSy2ttHQZ7jw1Cv0ea2p1D4yoRryORKYowLDZaX5y27RRDENNbeL1v8IcDND9xRNok4+D3o5ShRrdbwuGpDMtA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999603; c=relaxed/simple; bh=sB6An38OMDyB404NMh9FVaYmbgXY4y4VmMg07BTI1+c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y0mSEsJJ6VX1YfQ/iGZ9g/mSHixZ1naNDOyXQNYeV6b2Akq+Moijr1R2H5KQLkzQ+tF0DlXcCqCGw2wVrvVJoDn/azUdS+Q54VUJ40181yVcHiceeB1ok2JxCnbEYrrCy4WTvjctD1RY5tKnI3ud4QDwws/JcU9TUiOAxKdvQQw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=vzsD1VO0; arc=fail smtp.client-ip=40.107.236.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="vzsD1VO0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KGUB4L4uSHiG7zNuHGTz5KMX1UwjwYdynnWbBNtqtxwwuurGr5QztlAtegDG7k4AaRu8Rf2BNa5V0VU0yB4Dn+yizWLx07r74N7FFwe14BYj8++tjqEy9IogEDi7adERcvORJiAQxpAqzdLfqvsugyyDZcLihVy2997/8IvmHBLu1VFnR009oNkYYEABz9ac3nvgCL2AJnIdH+8W9q0zP/suYsEUDa7asXawh3AA/LNcPwD/XsKYJKuyqxOO95rwCHbIvJiSHWf197qx+7meW6kb2hucegflSln748DLWZeipk0a1wvvUn/4g5v63a7Y9fPerRaVMyQFOfbn14LP8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SCTIFzxNOO2ssRJ+aV6RGLBNVh3/1ooq1UKFB+UgyFE=; b=O5mXeeTZ93hJ8IkDM67rUHPXZcNwFrydqhBoJECxrtGAhXrJE+J7yXoDOjUkDP3PJqvTAyCrAGlYKuRLeZppufqGTbZB/b91AyKPryLYBknHqqfE6Kp+URQoT4hZcmYAoKbZg8e0pIha05iOnHos+I9As77bwQngLBOVodDA9a+U6GGccb/sJukqMN2HD6qG/MQex4zYx/JMJx10G/lzyQwcySl2YLZH5NPRfCpmVqBZ3K74pLS9vphoW6QpSJBXm8HA5OetcerbbNkSZbqk5pXyJbcM0h0FCBnPQykBU9f9Pi7eVOyJYNoOMCqVWSky1bIBrXmcwQ12U+XkTjcLLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SCTIFzxNOO2ssRJ+aV6RGLBNVh3/1ooq1UKFB+UgyFE=; b=vzsD1VO0aDorgC6rOqotbev2d4YdHbk8VVhNceG+S09YnQ/3bmsfsZzGpKOnWZ06kjymOTAwXzw6qNHvP7kQBn4tEB0mQTadyAOk0J2nMIhuuFufbDYAuTGuCVpNciGz6DJhdlLkeKjoOiKr4sTyB8h67Ah+lAYkv/BEqp2Vyqk= Received: from SA9P223CA0018.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::23) by DM4PR12MB8521.namprd12.prod.outlook.com (2603:10b6:8:17e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.25; Mon, 3 Mar 2025 10:59:55 +0000 Received: from SN1PEPF00036F3F.namprd05.prod.outlook.com (2603:10b6:806:26:cafe::9a) by SA9P223CA0018.outlook.office365.com (2603:10b6:806:26::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8489.26 via Frontend Transport; Mon, 3 Mar 2025 10:59:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F3F.mail.protection.outlook.com (10.167.248.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Mon, 3 Mar 2025 10:59:55 +0000 Received: from amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 3 Mar 2025 04:59:52 -0600 From: Akshay Gupta To: , CC: , , , , , , , Akshay Gupta Subject: [PATCH v5 08/11] misc: amd-sbi: Add support for CPUID protocol Date: Mon, 3 Mar 2025 10:58:59 +0000 Message-ID: <20250303105902.215009-9-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250303105902.215009-1-akshay.gupta@amd.com> References: <20250303105902.215009-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3F:EE_|DM4PR12MB8521:EE_ X-MS-Office365-Filtering-Correlation-Id: 2f910d6b-662d-4d15-119b-08dd5a428831 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: vMpB9rc6LXvjj1dlEcfqGIojyqetUDCe5BKk2L6kHTE0w4AucJ72+KiVt3wSZKXFP2fr870b3xzw6gRMEWI32LgVNogke7nd6Lvbi051LR9hpLSK/c8PRPfWANhzKcxTKJxKm2LrURozxM1KIh+aCyoEqZf4zJ1hDnvEejtjaII2O8gx+896kEAK0HRh/YTC2Dy656WmxqLxq7haaUEYQ5fVWsUz+vidwfDcv3AKRzvewS2O5AXBTTQUPu7vQZsvhYYu07Gh//sL6EaHar10lAngjxhbWEFn0Db1iO7PoSGAT4G7iK6K3yhblj+SUT/y78hvAMORmIKrhrZpKHlb2mDoehFTYkpTooLkpQnSayOHm1IqVWWh4Gbty4RveCngWC0F9kh58atzg5ppafrOIlYvK3wRJwfjltgXh6jZLmdzoydWDCj98hzPMcNkOcZQY2YrpgUwvREerLuqvx40AfEivYotUdTg+wRPgA3f/ZrJPGopO7s11oaCgq81i54n00roasV5akIiuPPx2itg8yQnLqOrMe+4uN6dl9H2pXI8CYXJUZVKxvpCqZ3LOQRKT3tbeGc9FpOGDDQFzLk4HOeJxTvIqgnpWSJskcesfJg68VtV10GfjXP4v2xzbsQkskztp3x2njod/qhI/iO4Gq91VYQHlTlWckQ5uwcjyJ0Y5c0vom/BL23Spvy01EIon7u2veOgHSq17yapcZ5l+ziz/nIzTnDv0uFW/gbrkXyj1XzHq/x6yfsVFOvp5hXBSsLaLo/iKHWOBCXOMoDLMdbtdYrct1E7pqr1N4qg3128hAQ6ZnBhAxA4Xk2RZ9j2IShxAl8dVJMrKuwowW1vfYFMJTsk3sLeinJTffZ+V8unVfhQ5sLJi8HsR3rTVmX07BX92u17GZ7xFmb0WJbijmB+HGml3dQezVczfk07+dZhjMdDWXd/CgAL9nIQU8985harrHTKPzTb68+eOsIQkhgWpp2MEtRnKD4QD5FyXGhVErXWvtH7BY6xXq6ljw6z23srPm0HZZiv80sPj14VWz9ExHEevP6kufnHcc+Hn+UUaB0FdyVZFgesnLUe66qhJBvCpT9Xg0VSgGQp/r7Hw+95g+bbO3z8vL+FGsfQ380LeGjBifAFNaFp/OSiqhInWsUTFFAWoyCgpc5d0Cs9RZ6xISOVse9UKos+z2uA5jPwNo42xO1Nl6lcCLSWVepvCtQMz5CUFuMEq9/MZF2toZCqTFm1RKn3ZrvbLjABbeaODmfg42SL0yR9BjzokyL8L4VMSNFMOe8QulRa+7Lh+DpBAZATiyGnA0pYOIfC40z40LI9vJ1XVn3L4yh3O9ieJkXWgDAWBHoCt0Ur+Tp9oxYU1kgiJL6hcXkPtxnYDodyf75pI0jrIdt4Q9Hzbwf78s6Zt8A8gYbe/aOx8NgBFA6++B4A/HBdVWLveFHF2A4EOWkn2nLWq9ACf0N+kSF5sOpNCzzu8gINBCtAVO0/ILooFeLlRgVYz4BKVTVXRhI= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2025 10:59:55.4955 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2f910d6b-662d-4d15-119b-08dd5a428831 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F3F.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB8521 - AMD provides custom protocol to read Processor feature capabilities and configuration information through side band. The information is accessed by providing CPUID Function, extended function and thread ID to the protocol. Undefined function returns 0. Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v4: - Previously patch 6 - Address review comments Changes since v3: - Address review comments: - update the #define to inline function - pack the union inside the structure Changes since v2: - update the MACROS name as per feedback Changes since v1: - bifurcated from previous patch 5 drivers/misc/amd-sbi/rmi-core.c | 148 ++++++++++++++++++++++++++++++++ drivers/misc/amd-sbi/rmi-core.h | 5 +- include/uapi/misc/amd-apml.h | 16 ++++ 3 files changed, 168 insertions(+), 1 deletion(-) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c index 642fe762cf6f..6fd6e8e579d5 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -17,11 +17,156 @@ /* Mask for Status Register bit[1] */ #define SW_ALERT_MASK 0x2 +/* Mask to check H/W Alert status bit */ +#define HW_ALERT_MASK 0x80 /* Software Interrupt for triggering */ #define START_CMD 0x80 #define TRIGGER_MAILBOX 0x01 +/* Default message lengths as per APML command protocol */ +/* CPUID */ +#define CPUID_RD_DATA_LEN 0x8 +#define CPUID_WR_DATA_LEN 0x8 +#define CPUID_RD_REG_LEN 0xa +#define CPUID_WR_REG_LEN 0x9 + +/* CPUID MSR Command Ids */ +#define CPUID_MCA_CMD 0x73 +#define RD_CPUID_CMD 0x91 + +/* input for bulk write to CPUID protocol */ +struct cpu_msr_indata { + u8 wr_len; /* const value */ + u8 rd_len; /* const value */ + u8 proto_cmd; /* const value */ + u8 thread; /* thread number */ + union { + u8 reg_offset[4]; /* input value */ + u32 value; + } __packed; + u8 ext; /* extended function */ +}; + +/* output for bulk read from CPUID protocol */ +struct cpu_msr_outdata { + u8 num_bytes; /* number of bytes return */ + u8 status; /* Protocol status code */ + union { + u64 value; + u8 reg_data[8]; + } __packed; +}; + +static inline void prepare_cpuid_input_message(struct cpu_msr_indata *input, + u8 thread_id, u32 func, + u8 ext_func) +{ + input->rd_len = CPUID_RD_DATA_LEN; + input->wr_len = CPUID_WR_DATA_LEN; + input->proto_cmd = RD_CPUID_CMD; + input->thread = thread_id << 1; + input->value = func; + input->ext = ext_func; +} + +static int sbrmi_get_rev(struct sbrmi_data *data) +{ + struct apml_message msg = { 0 }; + int ret; + + msg.data_in.reg_in[AMD_SBI_REG_OFF_INDEX] = SBRMI_REV; + msg.data_in.reg_in[AMD_SBI_RD_FLAG_INDEX] = 1; + ret = regmap_read(data->regmap, + msg.data_in.reg_in[AMD_SBI_REG_OFF_INDEX], + &msg.data_out.mb_out[AMD_SBI_RD_WR_DATA_INDEX]); + if (ret < 0) + return ret; + + data->rev = msg.data_out.reg_out[AMD_SBI_RD_WR_DATA_INDEX]; + return 0; +} + +/* Read CPUID function protocol */ +static int rmi_cpuid_read(struct sbrmi_data *data, + struct apml_message *msg) +{ + struct cpu_msr_indata input = {0}; + struct cpu_msr_outdata output = {0}; + int val = 0; + int ret, hw_status; + u16 thread; + + mutex_lock(&data->lock); + /* cache the rev value to identify if protocol is supported or not */ + if (!data->rev) { + ret = sbrmi_get_rev(data); + if (ret < 0) + goto exit_unlock; + } + /* CPUID protocol for REV 0x10 is not supported*/ + if (data->rev == 0x10) { + ret = -EOPNOTSUPP; + goto exit_unlock; + } + + thread = msg->data_in.reg_in[AMD_SBI_THREAD_LOW_INDEX] | + msg->data_in.reg_in[AMD_SBI_THREAD_HI_INDEX] << 8; + + /* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */ + if (thread > 127) { + thread -= 128; + val = 1; + } + ret = regmap_write(data->regmap, SBRMI_THREAD128CS, val); + if (ret < 0) + goto exit_unlock; + + prepare_cpuid_input_message(&input, thread, + msg->data_in.mb_in[AMD_SBI_RD_WR_DATA_INDEX], + msg->data_in.reg_in[AMD_SBI_EXT_FUNC_INDEX]); + + ret = regmap_bulk_write(data->regmap, CPUID_MCA_CMD, + &input, CPUID_WR_REG_LEN); + if (ret < 0) + goto exit_unlock; + + /* + * For RMI Rev 0x20, new h/w status bit is introduced. which is used + * by firmware to indicate completion of commands (0x71, 0x72, 0x73). + * wait for the status bit to be set by the hardware before + * reading the data out. + */ + ret = regmap_read_poll_timeout(data->regmap, SBRMI_STATUS, hw_status, + hw_status & HW_ALERT_MASK, 500, 2000000); + if (ret) + goto exit_unlock; + + ret = regmap_bulk_read(data->regmap, CPUID_MCA_CMD, + &output, CPUID_RD_REG_LEN); + if (ret < 0) + goto exit_unlock; + + ret = regmap_write(data->regmap, SBRMI_STATUS, + HW_ALERT_MASK); + if (ret < 0) + goto exit_unlock; + + if (output.num_bytes != CPUID_RD_REG_LEN - 1) { + ret = -EMSGSIZE; + goto exit_unlock; + } + if (output.status) { + ret = -EPROTOTYPE; + msg->fw_ret_code = output.status; + goto exit_unlock; + } + msg->data_out.cpu_msr_out = output.value; +exit_unlock: + mutex_unlock(&data->lock); + return ret; +} + int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_message *msg) { @@ -134,6 +279,9 @@ static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) /* Mailbox protocol */ ret = rmi_mailbox_xfer(data, &msg); break; + case APML_CPUID: + ret = rmi_cpuid_read(data, &msg); + break; default: return -EINVAL; } diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-core.h index e3a11575d19e..3f2c1c6b22d4 100644 --- a/drivers/misc/amd-sbi/rmi-core.h +++ b/drivers/misc/amd-sbi/rmi-core.h @@ -15,7 +15,8 @@ /* SB-RMI registers */ enum sbrmi_reg { - SBRMI_CTRL = 0x01, + SBRMI_REV, + SBRMI_CTRL, SBRMI_STATUS, SBRMI_OUTBNDMSG0 = 0x30, SBRMI_OUTBNDMSG1, @@ -34,6 +35,7 @@ enum sbrmi_reg { SBRMI_INBNDMSG6, SBRMI_INBNDMSG7, SBRMI_SW_INTERRUPT, + SBRMI_THREAD128CS = 0x4b, }; /* @@ -56,6 +58,7 @@ struct sbrmi_data { struct mutex lock; u32 pwr_limit_max; u8 dev_static_addr; + u8 rev; }; int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_message *msg); diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h index 47a057226300..847a83770ab0 100644 --- a/include/uapi/misc/amd-apml.h +++ b/include/uapi/misc/amd-apml.h @@ -7,38 +7,53 @@ #include +/* command ID to identify CPUID protocol */ +#define APML_CPUID 0x1000 /* These are byte indexes into data_in and data_out arrays */ #define AMD_SBI_RD_WR_DATA_INDEX 0 #define AMD_SBI_REG_OFF_INDEX 0 #define AMD_SBI_REG_VAL_INDEX 4 #define AMD_SBI_RD_FLAG_INDEX 7 +#define AMD_SBI_THREAD_LOW_INDEX 4 +#define AMD_SBI_THREAD_HI_INDEX 5 +#define AMD_SBI_EXT_FUNC_INDEX 6 #define AMD_SBI_MB_DATA_SIZE 4 struct apml_message { /* message ids: * Mailbox Messages: 0x0 ... 0x999 + * APML_CPUID: 0x1000 */ __u32 cmd; /* * 8 bit data for reg read, * 32 bit data in case of mailbox, + * up to 64 bit in case of cpuid */ union { + __u64 cpu_msr_out; __u32 mb_out[2]; __u8 reg_out[8]; } data_out; /* * [0]...[3] mailbox 32bit input + * cpuid, + * [4][5] cpuid: thread + * [6] cpuid: ext function & read eax/ebx or ecx/edx + * [7:0] -> bits [7:4] -> ext function & + * bit [0] read eax/ebx or ecx/edx * [7] read/write functionality */ union { + __u64 cpu_msr_in; __u32 mb_in[2]; __u8 reg_in[8]; } data_in; /* + * Status code is returned in case of CPUID access * Error code is returned in case of soft mailbox */ __u32 fw_ret_code; @@ -63,6 +78,7 @@ struct apml_message { * The IOCTL provides userspace access to AMD sideband protocols * The APML RMI module checks whether the cmd is * - Mailbox message read/write(0x0~0x999) + * - CPUID read(0x1000) * - returning "-EFAULT" if none of the above * "-EPROTOTYPE" error is returned to provide additional error details */ From patchwork Mon Mar 3 10:59:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13998584 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2069.outbound.protection.outlook.com [40.107.100.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2BB21E991A; Mon, 3 Mar 2025 11:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999613; cv=fail; b=sVrovgBKBtJpaXcyabPzF+UnWmrI1E/1xCUXJqo8bsaNmBmIBWHdbd7kipgisaa7RVRaxxomMU+3aEBZLRgt9CI39j4srFKNIqMgcO25ETVOdmm4JKwWxpVvhcv6uhO0xqh43XWoJ9qLstmfmhuXwNyp1mPn9VeBBQKhu2idec0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999613; c=relaxed/simple; bh=7AYevgm/dk0FY3evDjkmxRve/nPzE3jjDYRHUDalSQo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=G92Bd0fOIJmlwbjtl2uVYrO9ydZvX/i//4asiRxPNVRRPh48l7fV7s/UONN59D/KIm5Z5fUPB8lr8SwQz/ktBrh/9DDelH9Eo5ePbcB/N0Yr/H7dUMMK0q8UKcYdvAlhYAfog0UvL/GpNa/AZiJr12nAT/S70l4hfjaS0yoAHDg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=KxdVfa/0; arc=fail smtp.client-ip=40.107.100.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="KxdVfa/0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mh0wE6B2hPz+CncnzdMwH1u7azP+T7TizMhiqUnIdXyOfALN74hyEbCTVrtu2NshZyolZTTQPMwjLl0itbWxgSFg3di8fSHYgUWC9t/4lfaAwF1A5+RI6sJBMNNnb4g5rEw9canOAb5MkxOMLTyHiV46l6h+w7lamkWQM1vJL+ZP4kq5Jl4jSXu3p/X8/8MzOGfYazT87VY8QDHQnD4MugXZyrnJ+PrfgMJeZ1taGInRARRvxj2DMdR0xMzAhwGJQZ49ltmfXjWTcnV2Z5EpIu4kAHA5Z4sIMdHNBgjnHh2dBCukl0pMSXyer9WnqvfYq0DdLbIarQgAPjqyNNr5sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OGMoeu14lEt8msC9YkjZnWB4zDinMCue4dnI2muRl0g=; b=QhT1zxgtY6q8Hr+/3xjeTgnvIfPbZy2PdWNleIDusV1jt8p+dwz3oIoUUoyaKWoeyrSg0REpyIQ3TXOLFj6gM8ZnN86ZhRlmSbNhtY4F9hg8KLMYnLMkEYIKlOgBsNb2I6W+A3965VvXwGVFvj0izMoAljxqWq4iLFcf45bANnZ00JEmVz4xa5Ay12XiKIAWGcnyCDP/FeeAFQi1w136GQlD3wGYFQX/Lc+l9y+t6T2ZWK02n3mln5QwZjI0OtrJI4IG5AXSgPA5Y9vEY1jXwz219ONNjB8MqyV6CrWHHgiYAJmtEC1znFK6jf3Lefm5nkA4ys+8rtosho7R4lkPbg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OGMoeu14lEt8msC9YkjZnWB4zDinMCue4dnI2muRl0g=; b=KxdVfa/0FxId++72gTPi6moVmpW1s1kcv2KPbxxWvSmvAK/4thJgPuyIzBxnZo3OCEAz/qGl8pkiTTIMUNZ/mtMSdLb+gV4YZnq2en76T8NkNhjV+CcPWx8phOOPGCzbcTbk+VKHdRzCWE8Y2PNcdouGh+A9rJQLk8kMaXOIX8A= Received: from SA1PR05CA0017.namprd05.prod.outlook.com (2603:10b6:806:2d2::20) by SA1PR12MB6847.namprd12.prod.outlook.com (2603:10b6:806:25e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.25; Mon, 3 Mar 2025 11:00:02 +0000 Received: from SN1PEPF00036F40.namprd05.prod.outlook.com (2603:10b6:806:2d2:cafe::7) by SA1PR05CA0017.outlook.office365.com (2603:10b6:806:2d2::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8511.13 via Frontend Transport; Mon, 3 Mar 2025 11:00:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F40.mail.protection.outlook.com (10.167.248.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Mon, 3 Mar 2025 11:00:02 +0000 Received: from amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 3 Mar 2025 04:59:55 -0600 From: Akshay Gupta To: , CC: , , , , , , , Akshay Gupta Subject: [PATCH v5 09/11] misc: amd-sbi: Add support for read MCA register protocol Date: Mon, 3 Mar 2025 10:59:00 +0000 Message-ID: <20250303105902.215009-10-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250303105902.215009-1-akshay.gupta@amd.com> References: <20250303105902.215009-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F40:EE_|SA1PR12MB6847:EE_ X-MS-Office365-Filtering-Correlation-Id: 4744807a-ea41-4a9f-807f-08dd5a428c38 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: yD8EaVLkQp+mzDjiTshh+Jp6gixV3iCFzLHYroC/+h3yKuAa/GMmUzOCzB6ohhivhPiMYU9nC4uBuyeG919jErenSEIQ0l+FpzBda2qybiCt6WaNo24iW5Mow9SfxO+INE0xGQJ/Tuf+jaQ3qNxJTIUgxRu+/ZuCQbHMDpnLQ0IRwRYGb2c3h4Y2PswL3bBCfFWNS91VXFQyaYmksEbKnIGd3i8hUcfh8Hd7j9Ces5qPZzZSyk2HCusW+nZpP5DZ3nuBWGcR0uaO++3FFHhfIyRtaqYSkeJEvYmiwzVuTaPU3LKNKh52tiPm5cZnh4RghPhLmwsXz/vapwrjryKXFSlPWfIPbq7LtCzvA8y9jdPyuM8x+7ywjqBJvpv4H4idLrlENCZ0kKd58dV8aX8ff4LR4WkavVpVMCQl7jHdKop7Xi4UEkawE3s8/3QyNAbBWPt0qC23ryl71AWA5GYLU71xlwu88V0Mfrv7yc8k2PR0MpNvLvvDib3KEwf34bWP4wrPBkPprEd3xmqtW5l8rOX9DpHDnGc6HZrRVZeSt2UU6IVLd0WCM2m0Bn/3PllbhbDIGKZmaqsw4Z0EbPW7D8R7iq4wv3wQTzVzk/z3yU3jS3vvQfDTNL1Kmwhyt3IAYS/WdrPakhqaJ4EgKplbfMwF+R6s6OWGdISzQnqiRkwasMoY0SC4kCchPuXNySFf3SRZz2RAg1DCx1JIeTptdwFIEy4tYut3F3Njo5ywU5VJ56v+tv1xSzRAWRXgBBF/6RouyczNAr2PxxaczS5tNErMAyAAZs1mOpPEVWxribZ8XHlSKa1nSvKoNreBbKPDeqMyVfNAlI97FPfrPx0CAgx9xGA16Ty3RLcwReTHNB02tMFGvpaMXZLT1fx5crwjtr2a69DJmYhFH9sktDVDt5gHq43CuZ1C8/j8lc+tgE2IXOw5dF0vWb4YSq//7R1iiYUa131uQax7DkDy+8rOo3d7HLdAvwScUYCvoA1jg0gSUPyW4E3EKY8FHp9qLW0J7HFK+Pb7bD6cceJgmSgyPTRRK+hMSUYaVRSeAhzfQmYGnjPyASM9upZF7Pfb6/BxosF3yHIzTZuDhduJrKMI1iNAEbgyKc+jt9Mwr1kaRV7D+9eNsZtDM6IBmynnjRgWXceZy7BpznzbxFYOenKPdrKm43pktKSK6Izjr8dXpTW7nEsqQMEwmLjXvG/ubuXjRpkV2iqYVKlQxgbsBcfvkJZZEoQDqvKZ4Vr5ftVp1bM/E2N/3QZUqd7GiLgv3hpyacSgrDhzF7ST1Yd24zy+S19fND+HMuJPJE6SifjzNaaigLJQJSPMz3E+avcPtMOe0gU51ozDbooaEiE/u0wf+Dyq2jHrsvb1t7g9GiLcDg76ttTstUHyigtVWQr63k+oTTdBk+rWagDLdfAi3ryJDqzKAWaB3MEwcfzzsRt12wIPaQRWjpIT7MqZxfFkKQga3gYP22CfeITbkiTrEtsEDI0DRozotfdbEPOCeQqZCMA= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(376014)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2025 11:00:02.2395 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4744807a-ea41-4a9f-807f-08dd5a428c38 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F40.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6847 - AMD provides custom protocol to read Machine Check Architecture(MCA) registers over sideband. The information is accessed for range of MCA registers by passing register address and thread ID to the protocol. MCA register read command using the register address to access Core::X86::Msr::MCG_CAP which determines the number of MCA banks. Access is read-only Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v4: - Previously patch 7 - Address review comment for documentation warning Changes since v3: - Address review comments: - update the #define to inline function - pack the union inside the structure Changes since v2: - update the MACROS name as per feedback Changes since v1: - bifurcated from previous patch 5 drivers/misc/amd-sbi/rmi-core.c | 100 ++++++++++++++++++++++++++++++++ include/uapi/misc/amd-apml.h | 18 ++++-- 2 files changed, 112 insertions(+), 6 deletions(-) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c index 6fd6e8e579d5..662aa90980fc 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -30,10 +30,16 @@ #define CPUID_WR_DATA_LEN 0x8 #define CPUID_RD_REG_LEN 0xa #define CPUID_WR_REG_LEN 0x9 +/* MSR */ +#define MSR_RD_REG_LEN 0xa +#define MSR_WR_REG_LEN 0x8 +#define MSR_RD_DATA_LEN 0x8 +#define MSR_WR_DATA_LEN 0x7 /* CPUID MSR Command Ids */ #define CPUID_MCA_CMD 0x73 #define RD_CPUID_CMD 0x91 +#define RD_MCA_CMD 0x86 /* input for bulk write to CPUID protocol */ struct cpu_msr_indata { @@ -70,6 +76,16 @@ static inline void prepare_cpuid_input_message(struct cpu_msr_indata *input, input->ext = ext_func; } +static inline void prepare_mca_msr_input_message(struct cpu_msr_indata *input, + u8 thread_id, u32 data_in) +{ + input->rd_len = MSR_RD_DATA_LEN; + input->wr_len = MSR_WR_DATA_LEN; + input->proto_cmd = RD_MCA_CMD; + input->thread = thread_id << 1; + input->value = data_in; +} + static int sbrmi_get_rev(struct sbrmi_data *data) { struct apml_message msg = { 0 }; @@ -167,6 +183,86 @@ static int rmi_cpuid_read(struct sbrmi_data *data, return ret; } +/* MCA MSR protocol */ +static int rmi_mca_msr_read(struct sbrmi_data *data, + struct apml_message *msg) +{ + struct cpu_msr_outdata output = {0}; + struct cpu_msr_indata input = {0}; + int ret, val = 0; + int hw_status; + u16 thread; + + mutex_lock(&data->lock); + /* cache the rev value to identify if protocol is supported or not */ + if (!data->rev) { + ret = sbrmi_get_rev(data); + if (ret < 0) + goto exit_unlock; + } + /* MCA MSR protocol for REV 0x10 is not supported*/ + if (data->rev == 0x10) { + ret = -EOPNOTSUPP; + goto exit_unlock; + } + + thread = msg->data_in.reg_in[AMD_SBI_THREAD_LOW_INDEX] | + msg->data_in.reg_in[AMD_SBI_THREAD_HI_INDEX] << 8; + + /* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */ + if (thread > 127) { + thread -= 128; + val = 1; + } + ret = regmap_write(data->regmap, SBRMI_THREAD128CS, val); + if (ret < 0) + goto exit_unlock; + + prepare_mca_msr_input_message(&input, thread, + msg->data_in.mb_in[AMD_SBI_RD_WR_DATA_INDEX]); + + ret = regmap_bulk_write(data->regmap, CPUID_MCA_CMD, + &input, MSR_WR_REG_LEN); + if (ret < 0) + goto exit_unlock; + + /* + * For RMI Rev 0x20, new h/w status bit is introduced. which is used + * by firmware to indicate completion of commands (0x71, 0x72, 0x73). + * wait for the status bit to be set by the hardware before + * reading the data out. + */ + ret = regmap_read_poll_timeout(data->regmap, SBRMI_STATUS, hw_status, + hw_status & HW_ALERT_MASK, 500, 2000000); + if (ret) + goto exit_unlock; + + ret = regmap_bulk_read(data->regmap, CPUID_MCA_CMD, + &output, MSR_RD_REG_LEN); + if (ret < 0) + goto exit_unlock; + + ret = regmap_write(data->regmap, SBRMI_STATUS, + HW_ALERT_MASK); + if (ret < 0) + goto exit_unlock; + + if (output.num_bytes != MSR_RD_REG_LEN - 1) { + ret = -EMSGSIZE; + goto exit_unlock; + } + if (output.status) { + ret = -EPROTOTYPE; + msg->fw_ret_code = output.status; + goto exit_unlock; + } + msg->data_out.cpu_msr_out = output.value; + +exit_unlock: + mutex_unlock(&data->lock); + return ret; +} + int rmi_mailbox_xfer(struct sbrmi_data *data, struct apml_message *msg) { @@ -282,6 +378,10 @@ static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) case APML_CPUID: ret = rmi_cpuid_read(data, &msg); break; + case APML_MCA_MSR: + /* MCAMSR protocol */ + ret = rmi_mca_msr_read(data, &msg); + break; default: return -EINVAL; } diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h index 847a83770ab0..0a841809ca84 100644 --- a/include/uapi/misc/amd-apml.h +++ b/include/uapi/misc/amd-apml.h @@ -7,8 +7,11 @@ #include -/* command ID to identify CPUID protocol */ -#define APML_CPUID 0x1000 +enum apml_protocol { + APML_CPUID = 0x1000, + APML_MCA_MSR, +}; + /* These are byte indexes into data_in and data_out arrays */ #define AMD_SBI_RD_WR_DATA_INDEX 0 #define AMD_SBI_REG_OFF_INDEX 0 @@ -24,13 +27,14 @@ struct apml_message { /* message ids: * Mailbox Messages: 0x0 ... 0x999 * APML_CPUID: 0x1000 + * APML_MCA_MSR: 0x1001 */ __u32 cmd; /* * 8 bit data for reg read, * 32 bit data in case of mailbox, - * up to 64 bit in case of cpuid + * up to 64 bit in case of cpuid and mca msr */ union { __u64 cpu_msr_out; @@ -40,8 +44,9 @@ struct apml_message { /* * [0]...[3] mailbox 32bit input - * cpuid, - * [4][5] cpuid: thread + * cpuid & mca msr, + * [4][5] cpuid & mca msr: thread + * [4] rmi reg wr: value * [6] cpuid: ext function & read eax/ebx or ecx/edx * [7:0] -> bits [7:4] -> ext function & * bit [0] read eax/ebx or ecx/edx @@ -53,7 +58,7 @@ struct apml_message { __u8 reg_in[8]; } data_in; /* - * Status code is returned in case of CPUID access + * Status code is returned in case of CPUID/MCA access * Error code is returned in case of soft mailbox */ __u32 fw_ret_code; @@ -79,6 +84,7 @@ struct apml_message { * The APML RMI module checks whether the cmd is * - Mailbox message read/write(0x0~0x999) * - CPUID read(0x1000) + * - MCAMSR read(0x1001) * - returning "-EFAULT" if none of the above * "-EPROTOTYPE" error is returned to provide additional error details */ From patchwork Mon Mar 3 10:59:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13998583 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2061.outbound.protection.outlook.com [40.107.220.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CE681F3BA2; Mon, 3 Mar 2025 11:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999613; cv=fail; b=IkOCaFepwoTMapHw+nglir8uO8CY5KimyPHZpBoyfzOtPGEKwkOTG8nyyglvWp7oGMjDbjNpSXKmpYT8G5YDIIof+jzraCrjks+X7b2vLf9QXLEFY9+WkK/CmO4gY6Pumt/TaqcDqBeWLzXwfr1UdpivvOaoSJm8EwhAmTWbwm4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999613; c=relaxed/simple; bh=PEdl4eQHD9NfySCtoWbslE9to1LRnSP0Ye0jpNWX08Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lFxxlSM5/0qpEJJBV5KH27tS5dJdFurDmZeG6eIcoS4xn73j2lFyobLG0K/2Bc4osb/UuuE/Cj+t0lwcBy4PHRSENhZcTlJNfWQRUUfYAGqJF7Ng3eC+zhY41f7/KP2U8afuR+80AsKOJ/DamKheXDW2PCrNFe0l87pk0Oe/dG0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=jBvqsmzs; arc=fail smtp.client-ip=40.107.220.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="jBvqsmzs" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=syMxyWGXTeR7+BAK9J/oqKMOkx14u2vqI78YM5varsdv2BeAZpNxCA+VianhZtCFYaXwFBnIf2QjlVJcMdZkVtOHURE0vfzFq0MlFTnGqjTN4sy8KME08U7pta58qeDELwlq5iQmb0Nx8uraTl/hF5ttqpmolssI2RUTnNRGMEjL1P6cIO49A2Pg/XFqpZChtNhZUM9LQ99purk8quUKG2yX0VVglOyibzZJEIgc0zCpOiPlz60+/TOXhNbnu1uRzaKPulfIdXDd3O/JPCNE8q799beVef9hLhN/E/1lpevBfeeO/Qr2tWmYxd73rL9L3NH4CufcG/cpy3WBw1YE0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IpUzbkyvuMxU8l+A/IVX5UEJFfGy5cjiVhgG3qeC+sw=; b=jEdbhOAHIDlE5Jl+dAY0dia2sytWUneIBsqHW4r1l5Cs0fVOp5j5womoc3c/3+P3Co5XQSRCDBmkn+rRTJ5NKDP5Lt+NcQd+Mr2s65NPz0jerTDTXwWzDOLwBIE2z8PZrYEwN2Z9AL6cssUdpJYOAKJI/JpVexLuT76Hot+Zc2WgIUZPL+mRfRXbcfjZS2//tAO44sZCNPJgqlqNcbGH8umIS9nafKsjCFM99LKqykXUlB6ikA/MDW+W5xQGZnOumkXerebvrxEKY9wu6bt/gfIy1KzMpvoZqmp056Kp6DjS0RAl+ZEY2E9zIYC+q7u5/ZBYqDbAsd+UdH2m48bZhA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IpUzbkyvuMxU8l+A/IVX5UEJFfGy5cjiVhgG3qeC+sw=; b=jBvqsmzsr1fo5jlLEZSK5uW21L024HF6M5hWmp/w1uJImPFBCOD5m8Y1L+TEwnxFTsBK5P4RoIL9Ki+1V/P3GBDqmBekSCNg4SR3F+FRtpftmpqPaSELGXLpibcS1FHdH22hbAqIldbj6OomSUpTJSAlbzqec8lhnPSUo+en1CI= Received: from SA1PR05CA0023.namprd05.prod.outlook.com (2603:10b6:806:2d2::17) by MN2PR12MB4078.namprd12.prod.outlook.com (2603:10b6:208:1de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.25; Mon, 3 Mar 2025 11:00:07 +0000 Received: from SN1PEPF00036F40.namprd05.prod.outlook.com (2603:10b6:806:2d2:cafe::81) by SA1PR05CA0023.outlook.office365.com (2603:10b6:806:2d2::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8511.13 via Frontend Transport; Mon, 3 Mar 2025 11:00:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F40.mail.protection.outlook.com (10.167.248.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Mon, 3 Mar 2025 11:00:06 +0000 Received: from amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 3 Mar 2025 04:59:59 -0600 From: Akshay Gupta To: , CC: , , , , , , , Akshay Gupta Subject: [PATCH v5 10/11] misc: amd-sbi: Add support for register xfer Date: Mon, 3 Mar 2025 10:59:01 +0000 Message-ID: <20250303105902.215009-11-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250303105902.215009-1-akshay.gupta@amd.com> References: <20250303105902.215009-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F40:EE_|MN2PR12MB4078:EE_ X-MS-Office365-Filtering-Correlation-Id: 66032be2-14e4-463f-4deb-08dd5a428eee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: ouPU7Pvz+aH0hwhZsSwo6zXencZqvgL0EsCTd/mf0aGQ4eaCBLF9GG9I/qzX6SJm04jFcbDYWnQ629KerJNKQuq1zROgRwx055pqNUNkG2LoIbFPFL37Dx06If1pOxeg/P5mmeCoufaky6BVqEJuyid0m34jyJIjQ3WKJgxROhytYbicIzParw3MNsxza1l2tMQcyi5wWAZPqxkk2fPvF02v6YeuzlKua8O/rFMBt0B9VgprNu2HL7Y77AowTNaFbecDj8PGC4ijFUBR8IyiiS2mAwGi6Kz+9X+epf2pId/jT8UXYq2Uv7bKSl8NH4h2opgX4+XCHfQ2OQSdSUVOJp/suGn0gDxIyAoOKzMzH/EDleZBeFmS99ljYL/VoJ7kajSIRQs472LvVHjUmewQ9p/TDag4BMvZljsgRRJx920+T/uqUXhIi6IFRHOHK+lkCqzZSQ6CUCblVxi6TkYl4Ww+YM/AQ9tV3GJW4KdeoDMWaO95AcnuAKiqihEE9aB6+i9xW2bVcKk/02RhVU6YcAVduT3k6XAaZTLSDwEeQe8udCpj35Tl/8oOE9RmZFLaIp/iD0Ms3ZBeYT3WXH4EXyYhyRYzC/wV6m04mXfIAp/pWdHFkiUUliyJU0PJRnEL06mLO7HgINUo/uyZVEF4jrUlOadnDe9qJOQmlXL8zQRfG+6Kar3S3Fy6i0anX8zKPBjHUEJnXM1l5i4yeg4qyl0mDBqggY0u9IO0GgBXvKCguuNNieya6i6PdKZ2cmp2orrxGJwSH6Ao2gO7niUO6g0riEk0SoX7r8mz9LfT1v0W03k1LPvPsshWsXY1Fui148bObb/qegPBtpu+TaJFf92u5QD16Q6j+UTu1Xho1sLOzXEe/Rhz1FY3NOMbnvmD3fl/BsPtAI+lZ6X6eL/uHuzx4+G3xE3C9LoNoZ+45Yhri1Vf+myurKVQqZ8HQvHUX3p7N4QQLKrzJBEPPg/+6W13VyJDUKYtExzz6eQmPx6T/z1FGN6W4r9YInPXHe1XfuWblVLuEr56KVXk4f3CO3wT9Pg9O0ukt0bhFcShX0yMgeLzfiZq+K1HHMVvLWKsPcZhyLoUJDhXyBQqep5ksERzt3/lqR9UKZ/L/FvpUV+HP74URs2GRBoTF20ury+Gz47PZas3wJe3VxMGdPtbfvznEA7tWwefTv/9iO5yys5vMVB/sNsvLAOcw6gxc/P8pckv9XxifwIGkSTtJntKxwkkfMXy5zfp5KV2XrDFFi3UhRTnlPBIY6z3r2t8QdGK5lNTBVYWt2mOlP4Zeh8vvv0HevQjLHHin/y/YclCFFCBcuZ4r4M0Azn+xmxbsXhI8xJB6RIXJQuwiaehegrfxdQ3pltCiojpcvSPGfuXKzOiPyF1hBFHWHLflijL5jGRw3rerAU7Dstx3koHbeuy951umv+OySluvtSt/vSK/Y0jiyrQAm3wqfJJUpaPxu9Fb2sbCTC3Yh5q1FYY3Xv5Lhd9s63xLL0Sz3kUceYnPho= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2025 11:00:06.7864 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 66032be2-14e4-463f-4deb-08dd5a428eee X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F40.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4078 - Provide user register access over IOCTL. Both register read and write are supported. - APML interface does not provide a synchronization method. By defining, a register access path, we use APML modules and library for all APML transactions. Without having to use external tools such as i2c-tools, which may cause race conditions. Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v4: - Previously patch 8 - Address review comment for documentation warning Changes since v3: - Add ioctl description comment Changes since v2: - update the MACROS name as per feedback Changes since v1: - bifurcated from previous patch 5 drivers/misc/amd-sbi/rmi-core.c | 25 +++++++++++++++++++++++++ include/uapi/misc/amd-apml.h | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c index 662aa90980fc..1c248dcb8ce9 100644 --- a/drivers/misc/amd-sbi/rmi-core.c +++ b/drivers/misc/amd-sbi/rmi-core.c @@ -349,6 +349,27 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, return ret; } +static int rmi_register_xfer(struct sbrmi_data *data, + struct apml_message *msg) +{ + int ret; + + if (WARN_ON(!msg)) + return -EINVAL; + + mutex_lock(&data->lock); + if (msg->data_in.reg_in[AMD_SBI_RD_FLAG_INDEX]) + ret = regmap_read(data->regmap, + msg->data_in.reg_in[AMD_SBI_REG_OFF_INDEX], + &msg->data_out.mb_out[AMD_SBI_RD_WR_DATA_INDEX]); + else + ret = regmap_write(data->regmap, + msg->data_in.reg_in[AMD_SBI_REG_OFF_INDEX], + msg->data_in.reg_in[AMD_SBI_REG_VAL_INDEX]); + mutex_unlock(&data->lock); + return ret; +} + static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) { int __user *arguser = (int __user *)arg; @@ -382,6 +403,10 @@ static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) /* MCAMSR protocol */ ret = rmi_mca_msr_read(data, &msg); break; + case APML_REG: + /* REG R/W */ + ret = rmi_register_xfer(data, &msg); + break; default: return -EINVAL; } diff --git a/include/uapi/misc/amd-apml.h b/include/uapi/misc/amd-apml.h index 0a841809ca84..b18c20f9f809 100644 --- a/include/uapi/misc/amd-apml.h +++ b/include/uapi/misc/amd-apml.h @@ -10,6 +10,7 @@ enum apml_protocol { APML_CPUID = 0x1000, APML_MCA_MSR, + APML_REG, }; /* These are byte indexes into data_in and data_out arrays */ @@ -28,6 +29,7 @@ struct apml_message { * Mailbox Messages: 0x0 ... 0x999 * APML_CPUID: 0x1000 * APML_MCA_MSR: 0x1001 + * APML_REG: 0x1002 */ __u32 cmd; @@ -45,6 +47,7 @@ struct apml_message { /* * [0]...[3] mailbox 32bit input * cpuid & mca msr, + * rmi rd/wr: reg_offset * [4][5] cpuid & mca msr: thread * [4] rmi reg wr: value * [6] cpuid: ext function & read eax/ebx or ecx/edx @@ -85,6 +88,7 @@ struct apml_message { * - Mailbox message read/write(0x0~0x999) * - CPUID read(0x1000) * - MCAMSR read(0x1001) + * - Register read/write(0x1002) * - returning "-EFAULT" if none of the above * "-EPROTOTYPE" error is returned to provide additional error details */ From patchwork Mon Mar 3 10:59:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Akshay" X-Patchwork-Id: 13998585 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2040.outbound.protection.outlook.com [40.107.96.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C1301F63C3; Mon, 3 Mar 2025 11:00:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999618; cv=fail; b=VJgbtnhYEEDndBEsca9/CFXmFPw5XaqaJWUV+waXc4LeJTk3KKTOjXmaBBOjurY8CZNXZaeAKJxwpUIshJpUpDGvzNgng5+cQJ2VFOeJHazLvzbSS2kO7xdGxz/aitLDiUHqpLgY2/lKLrqKAKvI69eUNwhSuRWN5TXUKfTv9mY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740999618; c=relaxed/simple; bh=QwFjzdIGLHuIEjCKotTW/idS8H+wha8bKV+IXQ2lSPA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oFpZQpOl0fcbkUyEYNb05iBh/BldnZfxwjzm0znkTCtTlM5UEffRUPx6fZ4SUXLbd2m0ERmxpdG2zFbRylo+/S9Ew+XkQp0N6ElPDyMRNgtmhTA9FJX5+FP+7zBzEWa9UE0QowznaGRanIG2HfBwtw8h7rXVwIrd+MglRNVx8gw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=oVmDJMQU; arc=fail smtp.client-ip=40.107.96.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="oVmDJMQU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VLJTZysGuTGqG/o/i4CBc3uCibGA9y4cZ3JUw3/+7Sazv4T00m0Q2RgTV3usdqkLQZscrpwNUNOZdcoq6/l2UdJF9cHltcs02z57m723Ru6jE/6NS8loCAfNOuzEw10Sy855XW8EelMAXCB2sqqfgQPC5/5yZ1yZ9j5Hx9HsVzuN0RXH3gNCcu2sHPcUuSwyQO2GAXNhd3sQJiZ26vIt5n8mta5rW+/wVl81Bo1R5iTB6Ir07ThNohoFIbpqGjVLGb5/0gks+M0XKla5nUVtH+LB49aMbiExVYFjP+oF79DhrRy9tK45fduEB8D2ba8TRi0omlj+cookTrSIJNTJLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ehs4H6t56Ucd9PHTttShbnw51gMTfpuRJh+cUERi9lU=; b=h7F4/1z1Kc9EHfpnZx/iW0kXNk0h3t04V0Uom6ll3e1FXVLpq9cXZWGuC2jv9oCE2SwHXxj6frnYAiPJEqkbc98/1YQ/NKHdvkYow7zQmjqjBWlPXfdWWjTlgmZCUf48aphWwj+15xUDpDPoFeWeYWhhQtOXe6W1ye5cKg+6gEkg91wnDTmxQD/qVbzDvDF2yzg3IeacIa8Bb2ydq8BXYU7bM3t2V95DJ8FdaEknMnDNeTqx3/973cZEvtNnFg06c8//hXGXx0VkVRj+aWQonqY6SCu/fX44cu4XNtcN5zyQKbL8xD7wuLwQ+o/irh24axoG8AazItZQF+nOKFEDkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ehs4H6t56Ucd9PHTttShbnw51gMTfpuRJh+cUERi9lU=; b=oVmDJMQUoFirC/qZZssPprkkst/3lghVWHD2TcQHiNcbXdQWkYFBrbte/6SIp5P5exhGbRQ+pgWErTBcaSIDporOctn0Mvtv5WqmXDquvZ4A1sCVu/++W9MBbWvH9kjDhxEfE6d/9l5Xe7xEPuQty8sdsqgXQWEkaValRo5TQp4= Received: from SA1PR05CA0007.namprd05.prod.outlook.com (2603:10b6:806:2d2::9) by PH7PR12MB9128.namprd12.prod.outlook.com (2603:10b6:510:2f7::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.24; Mon, 3 Mar 2025 11:00:11 +0000 Received: from SN1PEPF00036F40.namprd05.prod.outlook.com (2603:10b6:806:2d2:cafe::61) by SA1PR05CA0007.outlook.office365.com (2603:10b6:806:2d2::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8511.12 via Frontend Transport; Mon, 3 Mar 2025 11:00:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F40.mail.protection.outlook.com (10.167.248.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Mon, 3 Mar 2025 11:00:10 +0000 Received: from amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 3 Mar 2025 05:00:04 -0600 From: Akshay Gupta To: , CC: , , , , , , , Akshay Gupta Subject: [PATCH v5 11/11] misc: amd-sbi: Add document for AMD SB IOCTL description Date: Mon, 3 Mar 2025 10:59:02 +0000 Message-ID: <20250303105902.215009-12-akshay.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250303105902.215009-1-akshay.gupta@amd.com> References: <20250303105902.215009-1-akshay.gupta@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F40:EE_|PH7PR12MB9128:EE_ X-MS-Office365-Filtering-Correlation-Id: 6bf55eb2-6151-4628-fcca-08dd5a4290e2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014|13003099007; X-Microsoft-Antispam-Message-Info: TiexCFTykxeKXVUFAGlQiZPa3/fLCXW6Yr7Kf4ITz6t5c5ajGw439iSKSkwmfeIce3F62I/VN/4oSWnqcsaUJ9mhO12KPJqRbIei0w8dNXGmGCKlEEaBmVq7QPMpW77pNnr3Op9x/envHHNQIHH+ou26+3d+hPmxSrIO02dmDjZspIKWoVjDscqd9WtXM0wAGV6PtsVGnRMo4kDC+r+Y0dD3QlUFIpeDRLrCb/bsZ+SbGVAHmddtaK8AlRLTMCW10V3r4CPfVHLgSA8UgWD98QFnPAu5C03l0y1qiW4QLEtAkP3QvpAz1RApMQ2SWVvFWl5XfuSpHwIaI2xLcIiwnZPnmaWojMzmJPyta68QIyccm9swSLtgYmgv3mE46JgB/0pPFonutUD40Y1KurMPmjm/X5bariKhs5ruS+C4Z8VcZMDuiKSN1qJ3518GqdUzyZ+dW8zhlsTiMcJnSygFmFUhaMqzzzu6Es+l8so3rptPkG8/y6C84HPsM/d/Mg/5LXZcNb0SboOwyGvWRlHnkOwWzHVzlVjtcH59eCFWebhUPV2Sf2wKhrb0Ot8a8w5ENaMQhaHzat+eXF4m7Ag9M+yj0By72Spnt3om4lXq9Q3gxrhO7olPSK4z+shQOZKvRD66ov7pgEOPONy6SP0l2QwSaEkIo/Nxw7pW0PkGfbrjavjd47A9q+ViQsYN+zjae6PfNS1mg1JasDCL7yM+/D7SqM5szH4FaMKZ77tma3LFeJjQ7J7GlDhdwiDv0SJ6EobvR/Ka4mfqcrq4+iVWOMF2eKKaYQDvpRghN+IVS1EfiKlvKdPCwdwaNuNNLd4vIlpyBo/obpEMcAPpauW+2D/1cOhjGKoKFhFcGpGiFeJf4ln4sdH1aiew4YArewXZKZqgdkAWtUQPagbLkgs5Li/fKHnhtStIQ6F+r6HJZsW5s9F04e4d8h70nUchfH8FZQFT1NT0GbSHkCBHB7GOo1xVJdwV/jf9lmn4ToqioQR5AEUqUTNp4S0CrRVe2Dmhn9y6nacxsFfAttc6s8Rlt3fnpfthwDmcucSAipsBu5O6OIucEpAfuSDIBwFvPvoElcN6zF9lA2GGBrQy1gxqYdeyuRrqJt4qkPCkdtzeWj/RWkDTpGcWA27thTdGCsnXQtIrmzb6Ndhq5GOcFBUDF+SYPwd46g6Hdb+Z2OspCFt9IZCRrFcEvXTe88aMaieNI036FPkvZYGIuDGUmcRKqG+OTbgg2Yy7eD1NHmy1WS5hJ/xEvZqJr6kqZIXvAeDu9FdOKA91kce+u5KFqhWxgdZQZJbElSlTCmxsgxey1jM2bPKCffgxzxtcoB+Z99F3B+3mem0er4d39qb4117yLrF7rJe7SmwUmhdRm6ibVph6d7xjYClBkB0bkDycmAhIkvCVGuY0kE/eVyS3ox4lvJlPCCG6z7gpD1hxmY1Ruwn0UknNpG/qpfXMtrEA5YuS95wa8y22rHbXOqHKRizoqYAfAnYuaqNdXXtBQHv8Npg= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2025 11:00:10.0677 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6bf55eb2-6151-4628-fcca-08dd5a4290e2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F40.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9128 - This document provides AMD side band IOCTL description defined for APML and its usage. Multiple AMD custom protocols defined for side band system management uses this IOCTL. User space C-APIs are made available by esmi_oob_library [1], which is provided by the E-SMS project [2]. Link: https://github.com/amd/esmi_oob_library [1] Link: https://www.amd.com/en/developer/e-sms.html [2] Reviewed-by: Naveen Krishna Chatradhi Signed-off-by: Akshay Gupta --- Changes since v4: - Previously patch 9 - Update description as per review comment - Address the review comments for documentation warning Changes since v3: - Address the review comments Changes since v2: - update the MACROS name as per feedback Changes since v1: - New patch Documentation/misc-devices/amd-sbi.rst | 87 ++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Documentation/misc-devices/amd-sbi.rst diff --git a/Documentation/misc-devices/amd-sbi.rst b/Documentation/misc-devices/amd-sbi.rst new file mode 100644 index 000000000000..9fbb01b33032 --- /dev/null +++ b/Documentation/misc-devices/amd-sbi.rst @@ -0,0 +1,87 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================= +AMD SIDE BAND interface +======================= + +Some AMD Zen based processors supports system management +functionality via side-band interface (SBI) called +Advanced Platform Management Link (APML). APML is an I2C/I3C +based 2-wire processor target interface. APML is used to +communicate with the Remote Management Interface +(SB Remote Management Interface (SB-RMI) +and SB Temperature Sensor Interface (SB-TSI)). + +More details on the interface can be found in chapter +"5 Advanced Platform Management Link (APML)" of the family/model PPR [1]_. + +.. [1] https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/programmer-references/55898_B1_pub_0_50.zip + + +SBRMI device +============ + +apml_sbrmi driver under the drivers/misc/amd-sbi creates miscdevice +/dev/sbrmi-* to let user space programs run APML mailbox, CPUID, +MCAMSR and register xfer commands. + +Register sets is common across APML protocols. IOCTL is providing synchronization +among protocols as transactions may create race condition. + +$ ls -al /dev/sbrmi-3c +crw------- 1 root root 10, 53 Jul 10 11:13 /dev/sbrmi-3c + +apml_sbrmi driver registers hwmon sensors for monitoring power_cap_max, +current power consumption and managing power_cap. + +Characteristics of the dev node: + * message ids are defined to run differnet xfer protocols: + * Mailbox: 0x0 ... 0x999 + * CPUID: 0x1000 + * MCA_MSR: 0x1001 + * Register xfer: 0x1002 + +Access restrictions: + * Only root user is allowed to open the file. + * APML Mailbox messages and Register xfer access are read-write, + * CPUID and MCA_MSR access is read-only. + +Driver IOCTLs +============= + +.. c:macro:: SBRMI_IOCTL_CMD +.. kernel-doc:: include/uapi/misc/amd-apml.h + :doc: SBRMI_IOCTL_CMD + +User-space usage +================ + +To access side band interface from a C program. +First, user need to include the headers:: + + #include + +Which defines the supported IOCTL and data structure to be passed +from the user space. + +Next thing, open the device file, as follows:: + + int file; + + file = open("/dev/sbrmi-*", O_RDWR); + if (file < 0) { + /* ERROR HANDLING */ + exit(1); + } + +The following IOCTL is defined: + +``#define SB_BASE_IOCTL_NR 0xF9`` +``#define SBRMI_IOCTL_CMD _IOWR(SB_BASE_IOCTL_NR, 0, struct apml_message)`` + + +User space C-APIs are made available by esmi_oob_library, hosted at +[2]_ which is provided by the E-SMS project [3]_. + +.. [2] https://github.com/amd/esmi_oob_library +.. [3] https://www.amd.com/en/developer/e-sms.html