From patchwork Tue May 16 20:24:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yazen Ghannam X-Patchwork-Id: 13243844 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12949C7EE2C for ; Tue, 16 May 2023 20:25:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230447AbjEPUYu (ORCPT ); Tue, 16 May 2023 16:24:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbjEPUYt (ORCPT ); Tue, 16 May 2023 16:24:49 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2046.outbound.protection.outlook.com [40.107.243.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 200311717; Tue, 16 May 2023 13:24:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B7BXCUXy5wmBPr3HXhuf+rx62SjAb9bvyD6jO04dBaxgVXyps44DQL4KSzLjGCIvAXt2e19Z4mkMeBhKVnJ5gN1CnuiPmd0xklvcqrmrxt44nT52qrszfy6xHnu00Mxat7aLYVGylTmdrXIUEbRSnxABA7wiRCKFRJH/F+NW95+qDME840kKyjOqu7OraTzJ7tSeJ8svcMgZKZb+m84EAfla/Bp1++Aw9MPA3Megh5PKtb9jIGP2ypMK1FSSjehyGhjcRVBs1gnIdpUJ0HQs84FfhAJKgJneSQ4gbgxK3ad6xcya1oRSvtCBUbtc0Yd7kVMLEFHAx5S2ELn2VECMzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=kkEwh9HfAWv7u9CsXT/BePK4o1Goki4vrlncZTzHYmM=; b=aMs4LiFm6znKLi278+pgoMe/jbQZRkXaO2f/EIVO5VM5lIrk0LqPjeuYCpiug+PbhBO1l8oDIy8Nj6uXztQuvSjeejThINJm5k93mzTOe6MceTIlB7/Npbulzhxkim6uBv79CECM+iIzc0UGYXQsX1FOAoR6A6A78jtACh8VxnSyy9+Bik+T+DoRGQBOvdBDT012Tyj9aJ9tqX5yEfuzEarZ8B7QZA/pbm7w1Y1jH1MXB3vEO4s247xOi3EaEmA1Gf5rapaaAt5QrvdHlXPvplfTVesiZfn1bMlvZdrLqliqcOHlxSoHNmJRLx3iiKQtM06N5RkkD0kkIgQvMX8+UA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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 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=kkEwh9HfAWv7u9CsXT/BePK4o1Goki4vrlncZTzHYmM=; b=0EgbkKcsA+Nx/C09ct78SrpGg2Aa23j+et9F4IFP3Q3w248KbSyS3dKDUMLuoXJHA6GZ98qfVhDEg7cnADIUinHf1vifRMqx8x5RUSWY8WQbm87OPndKqpHSKTKBGYyrsytjtfnHa1VqkRuPszl0sUyUgvJ/2jQHr2FrOqHnY1g= Received: from BN7PR06CA0047.namprd06.prod.outlook.com (2603:10b6:408:34::24) by CO6PR12MB5458.namprd12.prod.outlook.com (2603:10b6:5:35b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33; Tue, 16 May 2023 20:24:46 +0000 Received: from BN8NAM11FT036.eop-nam11.prod.protection.outlook.com (2603:10b6:408:34:cafe::a5) by BN7PR06CA0047.outlook.office365.com (2603:10b6:408:34::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33 via Frontend Transport; Tue, 16 May 2023 20:24:45 +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 BN8NAM11FT036.mail.protection.outlook.com (10.13.177.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.15 via Frontend Transport; Tue, 16 May 2023 20:24:45 +0000 Received: from quartz-7b1chost.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.2375.34; Tue, 16 May 2023 15:24:44 -0500 From: Yazen Ghannam To: CC: , , , , , , , , , , , , Yazen Ghannam Subject: [PATCH 1/6] EDAC/amd64: Remove unused register accesses Date: Tue, 16 May 2023 15:24:25 -0500 Message-ID: <20230516202430.4157216-2-yazen.ghannam@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230516202430.4157216-1-yazen.ghannam@amd.com> References: <20230516202430.4157216-1-yazen.ghannam@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BN8NAM11FT036:EE_|CO6PR12MB5458:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f7341db-1685-43c8-216f-08db564b96f9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LQM+uTdMTQeFALC6X1WjROUCqJsxRvT7dTiuK/GF3VwOo0wgSXaxI6xj1edXCxInSEAb3zsQI7AeqIq6vfbED9wHsZGoKP0AWG9bNQuYrnaMc3KniSACRIjv+y1L0Dn0vX6zJH62L68fbQIFxCJ3H1//peEjJUm1B9+wH2rltg8I6jzexD7Wom5H1GmfNZQh79gnauimjvFq/AB6uG2OcZVYATob3nLydeUBxBE1EQwYzWguCB7W1d9XQDR+LUC1lagvsBA4pyROdm0kIbq81cMKMgMtQO5CoPxvXQvME82AcwPL9SHNSNV2F1LSEHZULO1OcCDXKRv1/9J9Q4mVMO5WIgIKwdQQpk9pMnN9QrDg7lKzCj3LHoo1S04f8c/AtbH8Q1g7FeWNwB5LE5eEMlmbDBtQqqGZPDV6dPhZDiJtwbONUssvzQC3aDYqKWx6+CTcPzKIHeyzMOpQvxg4i4i4Y3F/kxOLc7rZTLHYILKEepObv6B6QVNFiEz5FoXrfSGcgk2D+UPyKkyIodciIKrLp34iePMExVx4hAkljjU7tTY2YkFlh1mhj7UlJ3W8J2+OAfDbVPME+qOIdNbWY38EgOB4EFD5+4cTaIadExFeTXvQ/hOpwcT4vQVubLDHeBAm6xFlzNtf+ZVl6lxh1yPIqNjP9GI1Q8GSrWZ/of9yiP1CNr/MT6nrY5v1VRDCAVN2OcG/Rs1ZMThdLYg9knFBB98UCAVnqsKwS2oPtFXEcV6CfURM4jowaVRxgR92QWZ8TRYdAEw8ut5LWMs9vA== 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:(13230028)(4636009)(376002)(396003)(136003)(346002)(39860400002)(451199021)(46966006)(36840700001)(40470700004)(316002)(8676002)(8936002)(4326008)(6916009)(70206006)(5660300002)(86362001)(82310400005)(7416002)(70586007)(356005)(54906003)(81166007)(44832011)(82740400003)(2906002)(41300700001)(478600001)(6666004)(7696005)(36756003)(1076003)(36860700001)(26005)(336012)(426003)(16526019)(40460700003)(186003)(83380400001)(47076005)(40480700001)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2023 20:24:45.8033 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f7341db-1685-43c8-216f-08db564b96f9 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: BN8NAM11FT036.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5458 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org A number of UMC registers are read only for the purpose of debug printing. They are not used in any calculations. Nor do they have any specific debug value. Remove these register accesses. Signed-off-by: Yazen Ghannam Cc: stable@vger.kernel.org --- drivers/edac/amd64_edac.c | 17 +---------------- drivers/edac/amd64_edac.h | 4 ---- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c index de3ea2c1807d..fda6537c80be 100644 --- a/drivers/edac/amd64_edac.c +++ b/drivers/edac/amd64_edac.c @@ -19,7 +19,6 @@ static inline u32 get_umc_reg(struct amd64_pvt *pvt, u32 reg) return reg; switch (reg) { - case UMCCH_ADDR_CFG: return UMCCH_ADDR_CFG_DDR5; case UMCCH_ADDR_MASK_SEC: return UMCCH_ADDR_MASK_SEC_DDR5; case UMCCH_DIMM_CFG: return UMCCH_DIMM_CFG_DDR5; } @@ -1528,7 +1527,7 @@ static void umc_debug_display_dimm_sizes(struct amd64_pvt *pvt, u8 ctrl) static void umc_dump_misc_regs(struct amd64_pvt *pvt) { struct amd64_umc *umc; - u32 i, tmp, umc_base; + u32 i, umc_base; for_each_umc(i) { umc_base = get_umc_base(i); @@ -1538,12 +1537,6 @@ static void umc_dump_misc_regs(struct amd64_pvt *pvt) edac_dbg(1, "UMC%d UMC cfg: 0x%x\n", i, umc->umc_cfg); edac_dbg(1, "UMC%d SDP ctrl: 0x%x\n", i, umc->sdp_ctrl); edac_dbg(1, "UMC%d ECC ctrl: 0x%x\n", i, umc->ecc_ctrl); - - amd_smn_read(pvt->mc_node_id, umc_base + UMCCH_ECC_BAD_SYMBOL, &tmp); - edac_dbg(1, "UMC%d ECC bad symbol: 0x%x\n", i, tmp); - - amd_smn_read(pvt->mc_node_id, umc_base + UMCCH_UMC_CAP, &tmp); - edac_dbg(1, "UMC%d UMC cap: 0x%x\n", i, tmp); edac_dbg(1, "UMC%d UMC cap high: 0x%x\n", i, umc->umc_cap_hi); edac_dbg(1, "UMC%d ECC capable: %s, ChipKill ECC capable: %s\n", @@ -1556,14 +1549,6 @@ static void umc_dump_misc_regs(struct amd64_pvt *pvt) edac_dbg(1, "UMC%d x16 DIMMs present: %s\n", i, (umc->dimm_cfg & BIT(7)) ? "yes" : "no"); - if (umc->dram_type == MEM_LRDDR4 || umc->dram_type == MEM_LRDDR5) { - amd_smn_read(pvt->mc_node_id, - umc_base + get_umc_reg(pvt, UMCCH_ADDR_CFG), - &tmp); - edac_dbg(1, "UMC%d LRDIMM %dx rank multiply\n", - i, 1 << ((tmp >> 4) & 0x3)); - } - umc_debug_display_dimm_sizes(pvt, i); } } diff --git a/drivers/edac/amd64_edac.h b/drivers/edac/amd64_edac.h index 0bde0db76f7a..a6cd42731e30 100644 --- a/drivers/edac/amd64_edac.h +++ b/drivers/edac/amd64_edac.h @@ -255,15 +255,11 @@ #define UMCCH_ADDR_MASK 0x20 #define UMCCH_ADDR_MASK_SEC 0x28 #define UMCCH_ADDR_MASK_SEC_DDR5 0x30 -#define UMCCH_ADDR_CFG 0x30 -#define UMCCH_ADDR_CFG_DDR5 0x40 #define UMCCH_DIMM_CFG 0x80 #define UMCCH_DIMM_CFG_DDR5 0x90 #define UMCCH_UMC_CFG 0x100 #define UMCCH_SDP_CTRL 0x104 #define UMCCH_ECC_CTRL 0x14C -#define UMCCH_ECC_BAD_SYMBOL 0xD90 -#define UMCCH_UMC_CAP 0xDF0 #define UMCCH_UMC_CAP_HI 0xDF4 /* UMC CH bitfields */ From patchwork Tue May 16 20:24:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yazen Ghannam X-Patchwork-Id: 13243845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0601BC7EE2F for ; Tue, 16 May 2023 20:25:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229709AbjEPUZI (ORCPT ); Tue, 16 May 2023 16:25:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230461AbjEPUYv (ORCPT ); Tue, 16 May 2023 16:24:51 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2062.outbound.protection.outlook.com [40.107.237.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 194A91BC; Tue, 16 May 2023 13:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a8lEMmJSpf5qIMZi+zT/rEgO+U3tghueoW3r+TQZBKEUcl/X/FEOQzNzB1zV4wgvD/2d0yrX8v2ZjaV1QEfD5brQJOYe1uuYnBpWYvc4gR9pZ/FMz7n7lGc38Fhsxf5DomtDvCZXiHLVBp+LKb1V0AHgS8AmV6xfBp92HkeYOgDqNEIuhC3mTi+FHmcf9FciS4Zu3dZfKYv3/ewtiYPhNurLRuUgd1klkSA7CJ6F7PImKhjkZT6V5LjZKq6AqdltbOY6sKuUofJAO3/ysGs1A+jB4BGovXFYlO7wLysHyMQ0IHlH5wIzewzZCKCt9+sSTazQoa4UTIg8P5ie/cR7Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=/3ym0DmPkjFkl9juXZIPH/rDRNBtBIuyF5FT0t8j+YE=; b=CAAfqEQIQDQiD90gd79F5j1wj8D3LHTpRV/Xy9kx+PfBTjqZlbES+mBnJZ056Roxc71qtWmQSLoeYwnmveXIeiHo4RG8iMDbVGat7alNX2pPxVO1r31QhMjwBojz+kScRNdS8uSH+fmVHDUXV9Ipjr+Xzq3kx8lunWyk/spHSsUW/XNswVs3Ux8XwFVwVFkrZe3HSwBM3whn+DR2PxTm9b/4Wdtknsl2lwRTE/RVKGJl6UpAoiYVtTAoiuJV7KT14o8Up+081LnC7wyvAa4/7bULirfVEm12MfvnsRpXzZdxzgw285ok5Eawh3ItpYT9VtuBjLmngNcyEFxtmfisfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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 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=/3ym0DmPkjFkl9juXZIPH/rDRNBtBIuyF5FT0t8j+YE=; b=rSZ3uCa992akAYtthXW2SP8b2ri8e2gLZ5J+AfLHAQEynA5E5ODhOO8Jactnyxp6bp4KQLdrV2OZB/JrU+oZp33CUgE2aNUbenBq6X7+4Yd8Oh0s0brCHsHvVPbXfDwHLD0M7SCZDErqSC7aBCw6oUkob98yipZWZHSE+2a8Elg= Received: from BN9PR03CA0404.namprd03.prod.outlook.com (2603:10b6:408:111::19) by CY8PR12MB7562.namprd12.prod.outlook.com (2603:10b6:930:95::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33; Tue, 16 May 2023 20:24:47 +0000 Received: from BN8NAM11FT098.eop-nam11.prod.protection.outlook.com (2603:10b6:408:111:cafe::fb) by BN9PR03CA0404.outlook.office365.com (2603:10b6:408:111::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33 via Frontend Transport; Tue, 16 May 2023 20:24:47 +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 BN8NAM11FT098.mail.protection.outlook.com (10.13.177.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.17 via Frontend Transport; Tue, 16 May 2023 20:24:46 +0000 Received: from quartz-7b1chost.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.2375.34; Tue, 16 May 2023 15:24:45 -0500 From: Yazen Ghannam To: CC: , , , , , , , , , , , , Yazen Ghannam Subject: [PATCH 2/6] EDAC/amd64: Check return value of amd_smn_read() Date: Tue, 16 May 2023 15:24:26 -0500 Message-ID: <20230516202430.4157216-3-yazen.ghannam@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230516202430.4157216-1-yazen.ghannam@amd.com> References: <20230516202430.4157216-1-yazen.ghannam@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BN8NAM11FT098:EE_|CY8PR12MB7562:EE_ X-MS-Office365-Filtering-Correlation-Id: 28325957-217f-41df-ca19-08db564b97a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YRQWov9CdR1b+A9e5fKNECuQkRLMZxFDnixEl0Qc4IOo+q2tVsrH1qg+UO4H/SA/lzvx2KhdSgvfk+MRAjgIOHgbIDUoHY+9u8GPGleMnjkTR5rKU0bR20r8vo0KcatQ5hwfaSzli5+DU/dyBj0CI36oxb0TKnz4fg1/SIz3EIULQ4O6MxuK3jEb7NmP1s+inr0wJ5+wW7H4mzFHnSHE6h+weDfgBuFlRKDsXTnbKtxDyZfx9anjtMwBr5nsjA2tSwJfVnyYO2/0vkJ8/HzaXwX6hxKeP6VlaQBrL2bMFseGuDB9m3+GmASnNkUOs3pdBrHz6zdoctlcJQI/059aSHGMxvp0XcW9x9O4MaTdhNAjc3kaAfX1LGy5L4EdsuXGxwmGv0EEbgTI3Sk6eKGf++LADDsYCJlL6EmTrYAfplFcc1nuH2XINEt74j8/McrV3l3Kbp4v8VC7jThNvNtzfD+r9PkCVUbelxHhuNIs4UdqdbmYISip92HzQH48pRswYGch8ds4Cn0e6LmnMpgu30FUlLWXmS6De/Lk5jaPbMKXRgdiK3iUkqzF74uRG5EjFMNh/w5VcqB6ERhHKG88eXjxgNPrNWy6YSK7kL2nq0rKTvT6njDfCZHCSclbCPDOMyXNKeaUTz+lkT7kNE3noK/25SsQZPUFimDI/zjCWlMH+5L0xjplENYAbMFQA9Ds2S0PZGipCR4ZdtbmoCB5SEqvjFw30mxGXB3xoVKI1/SAtVsawXk7nmPbWr9va8sVLEvIjvR7ETp/CXaWwNVhug== 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:(13230028)(4636009)(346002)(136003)(376002)(39860400002)(396003)(451199021)(40470700004)(36840700001)(46966006)(40460700003)(6916009)(4326008)(70206006)(70586007)(478600001)(316002)(54906003)(86362001)(36756003)(7696005)(47076005)(83380400001)(16526019)(1076003)(186003)(426003)(2616005)(26005)(36860700001)(336012)(2906002)(8676002)(8936002)(41300700001)(5660300002)(44832011)(7416002)(6666004)(40480700001)(82310400005)(81166007)(82740400003)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2023 20:24:46.9283 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 28325957-217f-41df-ca19-08db564b97a4 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: BN8NAM11FT098.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7562 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Check the return value of amd_smn_read() before saving a value. This ensures invalid values aren't saved. The struct umc instance is initialized to 0 during memory allocation. Therefore, a bad read will keep the value as 0 providing the expected Read-as-Zero behavior. Furthermore, the __must_check attribute will be added to amd_smn_read(). Therefore, this change is required to avoid compile-time warnings. Signed-off-by: Yazen Ghannam Cc: stable@vger.kernel.org --- drivers/edac/amd64_edac.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c index fda6537c80be..e9aa54e42edc 100644 --- a/drivers/edac/amd64_edac.c +++ b/drivers/edac/amd64_edac.c @@ -1626,6 +1626,7 @@ static void umc_read_base_mask(struct amd64_pvt *pvt) u32 *base, *base_sec; u32 *mask, *mask_sec; int cs, umc; + u32 tmp; for_each_umc(umc) { umc_base_reg = get_umc_base(umc) + UMCCH_BASE_ADDR; @@ -1638,13 +1639,17 @@ static void umc_read_base_mask(struct amd64_pvt *pvt) base_reg = umc_base_reg + (cs * 4); base_reg_sec = umc_base_reg_sec + (cs * 4); - if (!amd_smn_read(pvt->mc_node_id, base_reg, base)) + if (!amd_smn_read(pvt->mc_node_id, base_reg, &tmp)) { + *base = tmp; edac_dbg(0, " DCSB%d[%d]=0x%08x reg: 0x%x\n", umc, cs, *base, base_reg); + } - if (!amd_smn_read(pvt->mc_node_id, base_reg_sec, base_sec)) + if (!amd_smn_read(pvt->mc_node_id, base_reg_sec, &tmp)) { + *base_sec = tmp; edac_dbg(0, " DCSB_SEC%d[%d]=0x%08x reg: 0x%x\n", umc, cs, *base_sec, base_reg_sec); + } } umc_mask_reg = get_umc_base(umc) + UMCCH_ADDR_MASK; @@ -1657,13 +1662,17 @@ static void umc_read_base_mask(struct amd64_pvt *pvt) mask_reg = umc_mask_reg + (cs * 4); mask_reg_sec = umc_mask_reg_sec + (cs * 4); - if (!amd_smn_read(pvt->mc_node_id, mask_reg, mask)) + if (!amd_smn_read(pvt->mc_node_id, mask_reg, &tmp)) { + *mask = tmp; edac_dbg(0, " DCSM%d[%d]=0x%08x reg: 0x%x\n", umc, cs, *mask, mask_reg); + } - if (!amd_smn_read(pvt->mc_node_id, mask_reg_sec, mask_sec)) + if (!amd_smn_read(pvt->mc_node_id, mask_reg_sec, &tmp)) { + *mask_sec = tmp; edac_dbg(0, " DCSM_SEC%d[%d]=0x%08x reg: 0x%x\n", umc, cs, *mask_sec, mask_reg_sec); + } } } } @@ -3074,7 +3083,7 @@ static void umc_read_mc_regs(struct amd64_pvt *pvt) { u8 nid = pvt->mc_node_id; struct amd64_umc *umc; - u32 i, umc_base; + u32 i, tmp, umc_base; /* Read registers from each UMC */ for_each_umc(i) { @@ -3082,11 +3091,20 @@ static void umc_read_mc_regs(struct amd64_pvt *pvt) umc_base = get_umc_base(i); umc = &pvt->umc[i]; - amd_smn_read(nid, umc_base + get_umc_reg(pvt, UMCCH_DIMM_CFG), &umc->dimm_cfg); - amd_smn_read(nid, umc_base + UMCCH_UMC_CFG, &umc->umc_cfg); - amd_smn_read(nid, umc_base + UMCCH_SDP_CTRL, &umc->sdp_ctrl); - amd_smn_read(nid, umc_base + UMCCH_ECC_CTRL, &umc->ecc_ctrl); - amd_smn_read(nid, umc_base + UMCCH_UMC_CAP_HI, &umc->umc_cap_hi); + if (!amd_smn_read(nid, umc_base + get_umc_reg(pvt, UMCCH_DIMM_CFG), &tmp)) + umc->dimm_cfg = tmp; + + if (!amd_smn_read(nid, umc_base + UMCCH_UMC_CFG, &tmp)) + umc->umc_cfg = tmp; + + if (!amd_smn_read(nid, umc_base + UMCCH_SDP_CTRL, &tmp)) + umc->sdp_ctrl = tmp; + + if (!amd_smn_read(nid, umc_base + UMCCH_ECC_CTRL, &tmp)) + umc->ecc_ctrl = tmp; + + if (!amd_smn_read(nid, umc_base + UMCCH_UMC_CAP_HI, &tmp)) + umc->umc_cap_hi = tmp; } } From patchwork Tue May 16 20:24:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yazen Ghannam X-Patchwork-Id: 13243848 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65D6FC7EE33 for ; Tue, 16 May 2023 20:25:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230483AbjEPUZI (ORCPT ); Tue, 16 May 2023 16:25:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230470AbjEPUYv (ORCPT ); Tue, 16 May 2023 16:24:51 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2056.outbound.protection.outlook.com [40.107.243.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF99397; Tue, 16 May 2023 13:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DZxzENCwMuGmXL7Irdx0TiZS9J7x96Pdrf+DrcEA3XMdxH5u5NwuLWz1TkR5gDZf9ywbG9JJb4g+a6xc/aB8rZO74hQpU3UCdYHIdmzWG9IYS09F/LPCILXF96o0PCsz9CIt9w3CeB5CXnwFioesGSbpIum3uTa3dwtL5nAd1RjmV/3s2/2bKaVVu2dHWFE+3diYSdgarMojqm9lVSMWTtInOQVtAcKZc2LFtPAdLzR9i521BV6FSDbuVILey6R9J8EAToYlfGJD1xzcZHV148JNcww+LiZItIqjcMRZsjht/XvWQYzdSs7G/K2tqyxT/YuLlv+dZIPt82aUJRfw2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=J03kh9KQTcEyJIqijy8cUhLGif8AiK3cLVTK3VIx5t0=; b=Ch+uOlSX0YKRmZje93uKhy6ZY5zsi/oWn68Gi7sAIfnK34UKur6olOmqhAaB5xooo/RQT+U70iJ56P1HOqUSKsR36ADGmcP5IopdluczNQ2C5t+VMJVfS1pTAAHiqL9+1z/LfaAiiiYSJ27aGyH0oa3EZhdMQM6n+ABVn2cgEHm0p4bETeHBOiCUwp8ujIxxIN9w9lgwD6CMn2M2AfGCeS/91aMijNSFaEtFkOJbJYQH5lQn/Ve7hHbwzoAxQc5nWjQ2KZn3Jecpp/LGszCndWpbbTahgtQSyBLyybocbYeSdmOvANMdTRXh1nqHWT+0e23oQLmDhgvSeagz58vWzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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 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=J03kh9KQTcEyJIqijy8cUhLGif8AiK3cLVTK3VIx5t0=; b=1u3lH8hNZzdWMrD21qkyZnq7z9LYcdbYojw1Jcm+G3/oEW5M+y/YjWTqQ7L/rjcdni72Tnzc+lnqpNoDUl7o7XelCv0cFRPK3O3xnkumt+E+69Kx7Y26rEHNu2pP1k5+8o1Sgq0XgnGVmXcAdB5dpsCFHQqHfrHW5zKPbg2xmqw= Received: from BN7PR06CA0072.namprd06.prod.outlook.com (2603:10b6:408:34::49) by CH0PR12MB5059.namprd12.prod.outlook.com (2603:10b6:610:e2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33; Tue, 16 May 2023 20:24:48 +0000 Received: from BN8NAM11FT108.eop-nam11.prod.protection.outlook.com (2603:10b6:408:34:cafe::a9) by BN7PR06CA0072.outlook.office365.com (2603:10b6:408:34::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33 via Frontend Transport; Tue, 16 May 2023 20:24: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 BN8NAM11FT108.mail.protection.outlook.com (10.13.176.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.17 via Frontend Transport; Tue, 16 May 2023 20:24:48 +0000 Received: from quartz-7b1chost.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.2375.34; Tue, 16 May 2023 15:24:46 -0500 From: Yazen Ghannam To: CC: , , , , , , , , , , , , Yazen Ghannam Subject: [PATCH 3/6] hwmon: (k10temp) Check return value of amd_smn_read() Date: Tue, 16 May 2023 15:24:27 -0500 Message-ID: <20230516202430.4157216-4-yazen.ghannam@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230516202430.4157216-1-yazen.ghannam@amd.com> References: <20230516202430.4157216-1-yazen.ghannam@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BN8NAM11FT108:EE_|CH0PR12MB5059:EE_ X-MS-Office365-Filtering-Correlation-Id: 89feed6a-01aa-481d-b4f0-08db564b986a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8yxSqmumN/gNECtDNfn1lUY/AcHyud4jT6FH8O9AqMao4ivs3hUwcYad/23JMrvuBMApUx1ywbO419AbctlWnq9WqQGm3FWsD5pJd9YFwCsM5QT4tyP/0dsmo4fboeF89Cu61u2rfzig46hjoC58HzktlkrZshhHUYHzAf4UkpYq5vRV/CTnICVWGtmc8hxroSeGMSe+AZlPeIYizZGrLu3TM2IhBufEBHqPJ6k3De5Rcg5uTBraqldK4YbTAJ+MvND3EJQstC0M4r6PxyK96oLDw1o4bS7xrXOF6HR/C3tSJqt3o4QmEndLo+4VlxAOya0EZ0IEcfN+liEddJ9FYDbYCTZSeAs6BfEI/lNvvjSwuLdSXBOinsspvbruD1yNtizI53TtXlaK+OS6nmbAq9CUgHvd5KUpU8LqAHxV85mhuOS2igevnkDA1DRDx7DG+HaamFLkpkAB6LozYQh0eGljiBciE6RGAfEr4PCn/QrWKorZTaoCECnymJlxTC8mQZlpY7zoraX1tbxw1iyKm0bv9ZHUzeEXR75/XVU55bLN0JauWUIN9mSh8Cbn2xShC+BjE5Cy3gmTdHINgTp5LFLlChVE6hZ7JPBxe7lHjJBsx4tmc8+OnUSAsBfNSzGo6UfKk7/Di+w9/fIIYfMQB+rr6LflI31HkSP9Pn4FwSOYRAU0hAAm3XK8V6bwKjHwWpXu3MCpyQOE2DD+I9tfdaW6BNuiFzFxM8J9X7KaybeXIz5LcFkFmCX/An0XGFMGtHR8ZnfkvEdeDj8Bvv1GGQ== 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:(13230028)(4636009)(39860400002)(376002)(396003)(346002)(136003)(451199021)(46966006)(40470700004)(36840700001)(44832011)(2906002)(36860700001)(16526019)(83380400001)(7416002)(54906003)(8936002)(1076003)(26005)(186003)(47076005)(478600001)(2616005)(336012)(426003)(8676002)(5660300002)(316002)(40460700003)(81166007)(82310400005)(86362001)(356005)(41300700001)(40480700001)(82740400003)(36756003)(70206006)(6666004)(70586007)(6916009)(4326008)(7696005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2023 20:24:48.2410 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 89feed6a-01aa-481d-b4f0-08db564b986a 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: BN8NAM11FT108.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5059 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Check the return value of amd_smn_read() before saving a value. This ensures invalid values aren't saved or used. There are three cases here with slightly different behavior. 1) read_tempreg_nb_zen(): This is a function pointer which does not include a return code. In this case, set the register value to 0 on failure. This enforces Read-as-Zero behavior. 2) k10temp_read_temp(): This function does have return codes, so return -EINVAL on a failed register read. Continued operation is not necessary, since there is no valid data from the register. Furthermore, if the register value was set to 0, then the following operation would underflow. 3) k10temp_get_ccd_support(): This function reads the same register from multiple CCD instances in a loop. And a bitmask is formed if a specific bit is set in each register instance. The loop should continue on a failed register read, skipping the bit check. Furthermore, the __must_check attribute will be added to amd_smn_read(). Therefore, this change is required to avoid compile-time warnings. Signed-off-by: Yazen Ghannam Cc: stable@vger.kernel.org --- drivers/hwmon/k10temp.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c index 7b177b9fbb09..6ea1fa62b7c1 100644 --- a/drivers/hwmon/k10temp.c +++ b/drivers/hwmon/k10temp.c @@ -145,8 +145,9 @@ static void read_tempreg_nb_f15(struct pci_dev *pdev, u32 *regval) static void read_tempreg_nb_zen(struct pci_dev *pdev, u32 *regval) { - amd_smn_read(amd_pci_dev_to_node_id(pdev), - ZEN_REPORTED_TEMP_CTRL_BASE, regval); + if (amd_smn_read(amd_pci_dev_to_node_id(pdev), + ZEN_REPORTED_TEMP_CTRL_BASE, regval)) + *regval = 0; } static long get_raw_temp(struct k10temp_data *data) @@ -213,9 +214,11 @@ static int k10temp_read_temp(struct device *dev, u32 attr, int channel, *val = 0; break; case 2 ... 13: /* Tccd{1-12} */ - amd_smn_read(amd_pci_dev_to_node_id(data->pdev), - ZEN_CCD_TEMP(data->ccd_offset, channel - 2), - ®val); + if (amd_smn_read(amd_pci_dev_to_node_id(data->pdev), + ZEN_CCD_TEMP(data->ccd_offset, channel - 2), + ®val)) + return -EINVAL; + *val = (regval & ZEN_CCD_TEMP_MASK) * 125 - 49000; break; default: @@ -373,8 +376,10 @@ static void k10temp_get_ccd_support(struct pci_dev *pdev, int i; for (i = 0; i < limit; i++) { - amd_smn_read(amd_pci_dev_to_node_id(pdev), - ZEN_CCD_TEMP(data->ccd_offset, i), ®val); + if (amd_smn_read(amd_pci_dev_to_node_id(pdev), + ZEN_CCD_TEMP(data->ccd_offset, i), ®val)) + continue; + if (regval & ZEN_CCD_TEMP_VALID) data->show_temp |= BIT(TCCD_BIT(i)); } From patchwork Tue May 16 20:24:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yazen Ghannam X-Patchwork-Id: 13243847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A798BC7EE31 for ; Tue, 16 May 2023 20:25:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230498AbjEPUZJ (ORCPT ); Tue, 16 May 2023 16:25:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230513AbjEPUY5 (ORCPT ); Tue, 16 May 2023 16:24:57 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2071.outbound.protection.outlook.com [40.107.93.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 698D01BC; Tue, 16 May 2023 13:24:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D6FvlB2gZP0qak6Gj/hdfj1Mws5mDBkSJz1EdUzV+3eTS672ZmNdTyJURXB4Tqa8vbcu2bZ4rnsE8LcBBGUMXGAU3a0QPiTuGZ0PftNlT2OhawtlUp1zpmmJBjwMx778Okbm6k+czsuuHyx+ijY304KV1d8iFStlWdT5y0QDRif0cZlvsvK1fV3/sgs5YnQKorFrXqJBFDXfUjqFSSpm86NuU04WXuEXUEPdhu+10lDdiw9ELdiUwm+VnFxVR2TX+fSRXXkJ9IySR3PrIKHr+ZVCNUq2+kCgiBV6dfSegUg2FG3vvLsg901GfQutlDGYjkT6xwsHRopn72HGmDp9Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=aexl6TLvJ/4QZ7zfoc/S19jZVCUFyKnSkpg5FHlRV/s=; b=Djd16SJyO3c602TgEP7DMcDeKHPlIjaWhkv39j0d7QdlrSsLVwBKmHQPrAQUw96h5H5aZw03IZG6v5i6JpbziUGOHdww/NqGClGp/fckcT1iRzfb9FPK2AOo25iepU4fwSYaEh32B5/BR7ipP63rXPuEtPWeTaGJ5FW3ztJnz7O+lBLNvPLfMQ/x8HR2d4pbaXYmaFcFWA5r1g7Y9T49kRTkjcuCP3y44lPIdk78Ji1+c18yyOlVZP/JxRl8i4EoD7W7LvBtcY+pUkF5RcBmVN4MRhzrvIc4GuA8AoJBMJG0vQ++54C7m2pGLBrNQLKCX72bPhvuFIG3wv7J+mpuUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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 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=aexl6TLvJ/4QZ7zfoc/S19jZVCUFyKnSkpg5FHlRV/s=; b=oVHGw7gfGT9qYbcXCLFvZdtuxZkchWAmikIkoQuKgDHDVsNiEx9q8t0KH1noSkIiLM9pXXq30c8cYzAdlo0xVxid+6Fgn9uaOhdb8varAr/Mm7T5gS2ePZI0KNiASiDH+tR5lIT2wtxVNIf1y0ruOY6vlnkv0n2Fwq0aj57x4+Q= Received: from BN6PR17CA0028.namprd17.prod.outlook.com (2603:10b6:405:75::17) by DM4PR12MB6253.namprd12.prod.outlook.com (2603:10b6:8:a6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33; Tue, 16 May 2023 20:24:54 +0000 Received: from BN8NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:405:75:cafe::a4) by BN6PR17CA0028.outlook.office365.com (2603:10b6:405:75::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33 via Frontend Transport; Tue, 16 May 2023 20:24:54 +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 BN8NAM11FT054.mail.protection.outlook.com (10.13.177.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.15 via Frontend Transport; Tue, 16 May 2023 20:24:53 +0000 Received: from quartz-7b1chost.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.2375.34; Tue, 16 May 2023 15:24:48 -0500 From: Yazen Ghannam To: CC: , , , , , , , , , , , , Yazen Ghannam Subject: [PATCH 4/6] x86/amd_nb: Enhance SMN access error checking Date: Tue, 16 May 2023 15:24:28 -0500 Message-ID: <20230516202430.4157216-5-yazen.ghannam@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230516202430.4157216-1-yazen.ghannam@amd.com> References: <20230516202430.4157216-1-yazen.ghannam@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BN8NAM11FT054:EE_|DM4PR12MB6253:EE_ X-MS-Office365-Filtering-Correlation-Id: 5791c221-8708-44cb-b7ac-08db564b9bd2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gX4egV8B8NT36U0Do0L4iR/MYa/EvWw//z64yXqauTHf6i39O5DnQ4jkTq0ukUB0W5p6YAlcpjqTKo99KT/RQXRXOiF8n5lzDVnj4QeMrKvdF97FzdyPsocgFHZqnOxJD4CsBJbLo97aznaKBfq/s1RBrbJ4wPZ6XaFH1iUHn4vxwTvAcQfQbzxxX6N6IiEJYlk+a3SXy7VJSnJNcx4vQWAX87JPjpz0dp1AppF/B7PxZOPA7z5PVbvrV2t/e4jcJx2UXEMT/Ezm2L1TDykTQTPRGRQC0PDofInoSpFOmk8BZpWheIvYXbb/ccxrML/V8XplHY55NVinKGRcmlJa9l9VmyZBGxDfJ6pyTB/0zJkoOm8oMUHnTYHGNeQOj/gGeGTSY1gnqwm7O7TP/c7xSttvU+zuF6A4iqxbBIaDw1tXhptuRuRwmMmCwCstvBPR0JJgbIPDhTGLrXyqfrYrVxztwY9PyuT3/V9X57HFmzJAXWdLHX6f/4zng8wtsUtU+nEjuy9WZKfJ7NjvxBoBT4l1Q15jUJ7N1xGNtU78dzLRG2dYw3L/XuBwSbxPh6pm9YH8+dF4H7RM0PVLDrIFaYd+viqSZRZnrbytQdbhX2zV8hMPIlPbAo/J2sFXq217RLKdzD/jMc8JyUnsnasAbp9XB4M+MKoLWjOHSoKdM+6Din65ZGU1SR39YLpkP/FW/mj8uZ18zJt7dgPv0HlecpiLJZspfzKZaonEQa3Tp/+nyFh06YTEAFh9UezA3AxDEKOsEQ0UbKC5cC8TcqJZmQ== 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:(13230028)(4636009)(39860400002)(136003)(346002)(376002)(396003)(451199021)(40470700004)(36840700001)(46966006)(5660300002)(8936002)(8676002)(86362001)(44832011)(7416002)(426003)(336012)(2616005)(83380400001)(47076005)(36860700001)(82310400005)(81166007)(82740400003)(1076003)(356005)(26005)(186003)(16526019)(40460700003)(478600001)(7696005)(6666004)(40480700001)(41300700001)(316002)(70206006)(70586007)(54906003)(36756003)(6916009)(4326008)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2023 20:24:53.9402 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5791c221-8708-44cb-b7ac-08db564b9bd2 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: BN8NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6253 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org AMD Zen-based systems use a System Management Network (SMN) that provides access to implementation-specific registers. SMN accesses are done indirectly through an index/data pair in PCI config space. The PCI config access may fail and return an error code. This would prevent the "read" value from being updated, and it would give an indication to the caller that the read or write operation failed. However for reads, the PCI config access may succeed, but the return value may be invalid. This is in similar fashion to PCI bad reads, i.e. return all bits set. Most systems will return 0 for SMN addresses that are not accessible. This is in line with AMD convention that unavailable registers are Read-as-Zero/Writes-Ignored. However, some systems will return a "PCI Error Response" instead. This value, along with an error code of 0 from the PCI config access, will confuse callers of the amd_smn_read() function. Check for this condition and set a proper error code for SMN reads. Furthermore, require error checking for callers of amd_smn_read() and amd_smn_write(). This is needed because many error conditions cannot be checked by these functions. Also, drop the extern keyword as it's not needed. And remove a warning that will not be trigger in many cases. Fixes: ddfe43cdc0da ("x86/amd_nb: Add SMN and Indirect Data Fabric access for AMD Fam17h") Signed-off-by: Yazen Ghannam Cc: stable@vger.kernel.org --- arch/x86/include/asm/amd_nb.h | 4 +-- arch/x86/kernel/amd_nb.c | 46 ++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/amd_nb.h b/arch/x86/include/asm/amd_nb.h index ed0eaf65c437..e6fe405aa567 100644 --- a/arch/x86/include/asm/amd_nb.h +++ b/arch/x86/include/asm/amd_nb.h @@ -21,8 +21,8 @@ extern int amd_numa_init(void); extern int amd_get_subcaches(int); extern int amd_set_subcaches(int, unsigned long); -extern int amd_smn_read(u16 node, u32 address, u32 *value); -extern int amd_smn_write(u16 node, u32 address, u32 value); +int __must_check amd_smn_read(u16 node, u32 address, u32 *value); +int __must_check amd_smn_write(u16 node, u32 address, u32 value); struct amd_l3_cache { unsigned indices; diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c index 7e331e8f3692..c37754354cd8 100644 --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -157,6 +157,38 @@ static struct pci_dev *next_northbridge(struct pci_dev *dev, return dev; } +/* + * SMN accesses may fail in ways that are difficult to detect here in the called + * functions smn_read() and smn_write(). Therefore, callers of these functions + * must do their own checking based on what behavior they expect. + * + * For SMN reads, the returned SMN value may be zero if the register is + * Read-as-Zero . Or it may be a "PCI Error Response", e.g. all 0xFFs. The "PCI + * Error Response" can be checked here, and a proper error code can be returned. + * But the Read-as-Zero response cannot be verified here. A value of 0 may be + * correct in some cases, so callers must check that this correct is for the + * register/fields they need. + * + * For SMN writes, success can be determined through a "write and read back" + * procedure. However, this is not robust when done here. + * + * Possible issues: + * 1) Bits that are "Write-1-to-Clear". In this case, the read value should + * *not* match the write value. + * 2) Bits that are "Read-as-Zero"/"Writes-Ignored". This information cannot be + * known here. + * 3) Bits that are "Reserved / Set to 1". Ditto above. + * + * Callers of amd_smn_write() should do the "write and read back" check themselves, + * if needed. + * + * For #1, they can see if their target bits got cleared. + * + * For #2 and #3, they can check if their target bits got set as intended. + * + * This matches what is done for rdmsr/wrmsr. As long as there's no #GP, then + * the operation is considered a success, and the caller does their own checking. + */ static int __amd_smn_rw(u16 node, u32 address, u32 *value, bool write) { struct pci_dev *root; @@ -179,9 +211,6 @@ static int __amd_smn_rw(u16 node, u32 address, u32 *value, bool write) err = (write ? pci_write_config_dword(root, 0x64, *value) : pci_read_config_dword(root, 0x64, value)); - if (err) - pr_warn("Error %s SMN address 0x%x.\n", - (write ? "writing to" : "reading from"), address); out_unlock: mutex_unlock(&smn_mutex); @@ -190,13 +219,18 @@ static int __amd_smn_rw(u16 node, u32 address, u32 *value, bool write) return err; } -int amd_smn_read(u16 node, u32 address, u32 *value) +int __must_check amd_smn_read(u16 node, u32 address, u32 *value) { - return __amd_smn_rw(node, address, value, false); + int err = __amd_smn_rw(node, address, value, false); + + if (PCI_POSSIBLE_ERROR(*value)) + err = -ENODEV; + + return err; } EXPORT_SYMBOL_GPL(amd_smn_read); -int amd_smn_write(u16 node, u32 address, u32 value) +int __must_check amd_smn_write(u16 node, u32 address, u32 value) { return __amd_smn_rw(node, address, &value, true); } From patchwork Tue May 16 20:24:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yazen Ghannam X-Patchwork-Id: 13243846 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F45AC7EE39 for ; Tue, 16 May 2023 20:25:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229736AbjEPUZK (ORCPT ); Tue, 16 May 2023 16:25:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231148AbjEPUZB (ORCPT ); Tue, 16 May 2023 16:25:01 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2049.outbound.protection.outlook.com [40.107.92.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC6E497; Tue, 16 May 2023 13:25:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZjLHuNs0E4UZtKDXokZLt1SUSKwlY8a+OWvH4zcM0kHQMiVFTSUN+hIRT2ogFTXdGQewsaaqLzYW6769+jQYzjg4fKZU40Q8RAD3+gjTgn8P8u2Sy0CIIzN/bwHbHOqqgbNZAAvc0bkN6S7zhNUz9FmwVyaWoIS6hXTWcaEG3aR5nKbItQvzSzEzSiMZKsuIbiJsuM5Ly2U24BTvLXYg3Z9PygdGth7VaccmX9OxanBJ6TfUqZo7KbmHy7/+MkQ8SG0skzGmBd/BHzAFGG9TDQveQd2Nhkt7JLxXhZYW0ryhafoORkTrDIQucDRP1K6Q8QXtFof5T17Wgn+j7niGIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=Aji6vNroVQExDKpw5+gxvl+fZyGHaciz4uIiFsFbM+w=; b=FBZDbz5yhoHp9ey8o7w9cw3k65+YqehVv5eK9bcTKBjudQkLu0ctmHc6YgB5+dUjtkHwDMuXFIw0waT3vDbRIuSubBiAmOsEHCwqLgggH6SGi0ANXoX55NfV4ovJDNLxqF977lvc0yFP96ax4EEQYOk867j/8dixQGSTNugbSlFxwyzLJ2BjT31ur86oN329FetpIJz+FyrwNFM5FD4QdQ41oAICLxluBqIKTJUgCzgT6RYfo3mydKarsv01zGxgrg5BME9/gaD8vXgTd/D+v9CUSU5221tBXPPgxvJyCEAe0nsQm7X673mBKJJNu9HQ5E2kEE4rLY/5dorb4EBFyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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 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=Aji6vNroVQExDKpw5+gxvl+fZyGHaciz4uIiFsFbM+w=; b=EtMNEX+n6Rx0g5rhxyDXEZN8A7o6RGQHYfCdLT6xZYV4NU5/X8tDm4+YAV7UvsvSQejZYgN6uHgW8nZSbXJUk8d/XcrEJjafXRCvq/iyOsGYI1hiRruYVJogbOjwx5C4S45bboYW33CnlQAp9hGYf+Jti6UzUbbuwBlKCkTjoRs= Received: from BN6PR17CA0028.namprd17.prod.outlook.com (2603:10b6:405:75::17) by PH7PR12MB6788.namprd12.prod.outlook.com (2603:10b6:510:1ae::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33; Tue, 16 May 2023 20:24:55 +0000 Received: from BN8NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:405:75:cafe::a4) by BN6PR17CA0028.outlook.office365.com (2603:10b6:405:75::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33 via Frontend Transport; Tue, 16 May 2023 20:24:54 +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 BN8NAM11FT054.mail.protection.outlook.com (10.13.177.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.15 via Frontend Transport; Tue, 16 May 2023 20:24:54 +0000 Received: from quartz-7b1chost.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.2375.34; Tue, 16 May 2023 15:24:49 -0500 From: Yazen Ghannam To: CC: , , , , , , , , , , , , Yazen Ghannam Subject: [PATCH 5/6] hwmon: (k10temp) Define helper function to read CCD temp Date: Tue, 16 May 2023 15:24:29 -0500 Message-ID: <20230516202430.4157216-6-yazen.ghannam@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230516202430.4157216-1-yazen.ghannam@amd.com> References: <20230516202430.4157216-1-yazen.ghannam@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BN8NAM11FT054:EE_|PH7PR12MB6788:EE_ X-MS-Office365-Filtering-Correlation-Id: fc937b06-58b2-4076-da8b-08db564b9c17 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: esrzDOQGD2tL0y8i+wrTgv3k5X9vhyZ47ILDwriMkpxf4IB1oZi/oYU3WHNCsruk2CtJsy6c7A+bxuSEOy1qtQlKFHRFutTbA75FOM02RVV4IZnPxP/du0GM8Mn1xdvFVoU9/CwG2NGUthNdJOjuK8E65uhyZIKnRAvUNopwgf8z4HCukJZXE+R5Abp4li+4Y9xrgQzQypkYUXr+EUhnGhgFy5dmgDqnsJLqindIoXhodDhkg1BwgIRppZbMrwBF8UWP/5rNSq/r6KmhIbtpAJJknxqL9T9vTqukXjDcSTNg20AitZU3iMGUtfBtuI42Ku9dB7amzARzPIhEb0sS8HBaknKjc5K2DRPkMuMwo8BOOfjC5PKLKDEB4Z0Cp1K/bQiTcRwjHCgNdRuwdJ9edyIwEUpZM2zJyWWUsfGYVMFb2x19RLjt637081HSnWkU3Mh430aP956J+r0ckcjrqscCsmDPGiWDWIsJszOBtD76sE7RwviFi0F6uYzp+V3k9jaxJNifaiK4YGVj+FrAsQdDu7sBbvq5n5zg806dAUH1sf6m9a9GKUbxeypZo2iAuZHAivrGRXC2cZMBnJ2IIk8Y5AniY6hR3DMJmeE82Q7utzv0qOX1VbuTm6uKvQXunqJEs5cLLJVQFdBQR+5KbxaYmnWvetrdG9gNS1/c2KN8G394b1CUvytgRJIGvfQn4YdyvuChBfWmnWKNYFIijTBCaQR4lVnqJGFx9FUpSSORup+gkQdU8v1EgtHqSWif/kcaN9VQa2BUmjB/31jgww== 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:(13230028)(4636009)(136003)(39860400002)(346002)(376002)(396003)(451199021)(40470700004)(46966006)(36840700001)(40460700003)(7416002)(5660300002)(44832011)(8936002)(47076005)(36860700001)(83380400001)(36756003)(2906002)(16526019)(186003)(2616005)(356005)(336012)(82740400003)(81166007)(426003)(86362001)(82310400005)(8676002)(40480700001)(26005)(1076003)(41300700001)(6666004)(316002)(6916009)(4326008)(70586007)(70206006)(7696005)(478600001)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2023 20:24:54.4089 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc937b06-58b2-4076-da8b-08db564b9c17 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: BN8NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6788 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org The CCD temperature register is read in two places. These reads are done using an AMD SMN access, and a number of parameters are needed for the operation. Move the SMN access and parameter gathering into a helper function in order to simply the code flow. This also has a benefit of centralizing the hardware register access in a single place in case fixes or special decoding is required. Signed-off-by: Yazen Ghannam --- drivers/hwmon/k10temp.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c index 6ea1fa62b7c1..06af1fe38af7 100644 --- a/drivers/hwmon/k10temp.c +++ b/drivers/hwmon/k10temp.c @@ -150,6 +150,18 @@ static void read_tempreg_nb_zen(struct pci_dev *pdev, u32 *regval) *regval = 0; } +static int read_ccd_temp_reg(struct k10temp_data *data, int ccd, u32 *regval) +{ + u16 node_id = amd_pci_dev_to_node_id(data->pdev); + u32 tmp; + + if (amd_smn_read(node_id, ZEN_CCD_TEMP(data->ccd_offset, ccd), &tmp)) + return -EINVAL; + + *regval = tmp; + return 0; +} + static long get_raw_temp(struct k10temp_data *data) { u32 regval; @@ -214,9 +226,7 @@ static int k10temp_read_temp(struct device *dev, u32 attr, int channel, *val = 0; break; case 2 ... 13: /* Tccd{1-12} */ - if (amd_smn_read(amd_pci_dev_to_node_id(data->pdev), - ZEN_CCD_TEMP(data->ccd_offset, channel - 2), - ®val)) + if (read_ccd_temp_reg(data, channel - 2, ®val)) return -EINVAL; *val = (regval & ZEN_CCD_TEMP_MASK) * 125 - 49000; @@ -376,8 +386,7 @@ static void k10temp_get_ccd_support(struct pci_dev *pdev, int i; for (i = 0; i < limit; i++) { - if (amd_smn_read(amd_pci_dev_to_node_id(pdev), - ZEN_CCD_TEMP(data->ccd_offset, i), ®val)) + if (read_ccd_temp_reg(data, i, ®val)) continue; if (regval & ZEN_CCD_TEMP_VALID) From patchwork Tue May 16 20:24:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yazen Ghannam X-Patchwork-Id: 13243849 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FA20C7EE24 for ; Tue, 16 May 2023 20:25:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231200AbjEPUZL (ORCPT ); Tue, 16 May 2023 16:25:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231154AbjEPUZC (ORCPT ); Tue, 16 May 2023 16:25:02 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2042.outbound.protection.outlook.com [40.107.244.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F0FF132; Tue, 16 May 2023 13:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O7kunu7eQukSFf2suKLEuuDy06BWYv28Oh80C2YgC8HryyxkgVX2OEL79yWoTXejg/PJedZEL+D3Jv9NHexkUFPY6D6gmwqMv28dIhypWCMiQt7IV7pmDaZWSW5skRXcqBRrpD7ppNYKzlbIarqaKjGju3SlPssm8IXZyCBMxSO42i0SBBv83bW9BLtkJ4SAe8ArFpkiNCHQ+28GN99T9VpsyYHHgL/Ar3HQMWg2trhg+3GRmh6q42Xceb1xRmhZZS2N5Y5qIZkqUXKPEzLbRz5xAhFMgCI5IPL5iGR/5KeuX6E4ufyz1zPahzqZ26EbrnRJGXI7QzjDNl6yjx+Zvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=upqSgRjvn3kgYne4u2rmiqfVXMmajGzToqGyHGD3JE4=; b=ij+ePoE2R1zU32Pk6OxBJ8yK3qTdbtSiSxNFHiN5egbCZkeT4AeRQ91mxe3fb7m4eJgs1dwyXID0MC5eNbosrPQ9xgrlN63KnryAkGUhirSnU/Q3+WA+IA3tAWTuMkv1msdCvX/gX5CieArl7M/SPrh7z5ZkeEksu4IbiWaHdZ0v5MO/7QXrFk5/8j02OHh8h0vAb5x4h2p+jnjO4euV2W07x+2wks2BfYPOO7PDt6assjkrwidpmp0gFuLQYIN2v98zFrGstiRVGKMu1F+DysJLq5cPu1qA+X7Uxvi39DY+EOYF34KxMNda6NtR7BeY73uGHPhR03T8cqsxueniIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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 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=upqSgRjvn3kgYne4u2rmiqfVXMmajGzToqGyHGD3JE4=; b=W5vdo0ysY/07aHTncVJMcpEjJy7zzwqtYm6DuFynqlu2QqpsPFqZFgxJxWR0mTQQuqgXAhaFxkCZkT9k30HG0ITlxV4SPbwPD8x0RwYl2N/hB/lmN+geALMdNJZub//NDSKmK31zd743xKqHaYtIu1288haPf+3XrOh3NUZrh7Y= Received: from BN6PR17CA0046.namprd17.prod.outlook.com (2603:10b6:405:75::35) by PH0PR12MB7011.namprd12.prod.outlook.com (2603:10b6:510:21c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33; Tue, 16 May 2023 20:24:56 +0000 Received: from BN8NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:405:75:cafe::ad) by BN6PR17CA0046.outlook.office365.com (2603:10b6:405:75::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33 via Frontend Transport; Tue, 16 May 2023 20:24: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 BN8NAM11FT054.mail.protection.outlook.com (10.13.177.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.15 via Frontend Transport; Tue, 16 May 2023 20:24:55 +0000 Received: from quartz-7b1chost.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.2375.34; Tue, 16 May 2023 15:24:51 -0500 From: Yazen Ghannam To: CC: , , , , , , , , , , , , Yazen Ghannam Subject: [PATCH 6/6] hwmon: (k10temp) Reduce k10temp_get_ccd_support() parameters Date: Tue, 16 May 2023 15:24:30 -0500 Message-ID: <20230516202430.4157216-7-yazen.ghannam@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230516202430.4157216-1-yazen.ghannam@amd.com> References: <20230516202430.4157216-1-yazen.ghannam@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BN8NAM11FT054:EE_|PH0PR12MB7011:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d542207-6bd2-4fe9-0be6-08db564b9cae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3Q00+mEaaWNMa0Jkoky6j49pr/oCmL50EvJkg3lQ0Hf8MdS+zw8wheKF3iIBVxZifgyANnruXyGSM2bgjjqL7qNu33oJxN3mSDKR3tLaSyJyVQRYXVD/bjS8paJjzZy9njNIGZKJ/oQ1wrFhQMj4CgIQ/TY9ZkxNx83vm/kmJi4wZzATnXA6FVVPPnmTT+ba2kIMU/bSKCtsTwNuSAzzbAdFCyoOH3QvAXhBU1mXC/S1xPbso+mlW1H1KWeVpB1YEmBroH3z40/n5LHkKlDxDE2YwnkByBQV1UkhI7yEdqskf04dFVVv3EXVKq6Mbd46fvj2pkO0+UUrmsnTNdfEjJkhZVtnLNUWnSFnexetwr9Q/wpr5B18Txk/hNtHkUbgBIJxzpgeqEZw0sJra4qZo04O0IlSmnjwaNsMNDU1P4ccYxtYsX6A8pW4bW5nPv/Q6OHvR6hGrGrMJv9SW8Z0I5wGayk5+oSTzdZvKAZzg2xymD/cPjYSnFV1/tvxmPQYof1WXqeAltvj/L10lYlRmYNeyPwX95fJ+BX1dOV/QUTf3/cu4Kr4B0EeQdp2lXTTWg9ifhQMHO1sCmAJn8wL5eZqAiOw0YdwaFpIHJhYEc4g7izRRdFOmBLWaEOXvZ7q8F0o9HnoR6OyMYMK8CLRUdakOoU9Am6/+kTwN9/qkI02za7GGnildtdzvuDSZHK6v4BYsV4zEotNCH7CxEBHPS/ItDV3BwXOeONXLnhJmNsvwxI4rv35DHo0S6VslpmCAgnGAa8CT/2qHEGmOugVSA== 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:(13230028)(4636009)(376002)(136003)(396003)(39860400002)(346002)(451199021)(46966006)(36840700001)(40470700004)(82740400003)(83380400001)(478600001)(54906003)(70586007)(70206006)(6666004)(7696005)(41300700001)(6916009)(36756003)(86362001)(40460700003)(4326008)(316002)(82310400005)(40480700001)(36860700001)(1076003)(336012)(47076005)(2616005)(426003)(356005)(81166007)(186003)(5660300002)(2906002)(44832011)(7416002)(8676002)(8936002)(26005)(16526019)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2023 20:24:55.3932 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5d542207-6bd2-4fe9-0be6-08db564b9cae 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: BN8NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7011 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Currently, k10temp_get_ccd_support() takes as input "pdev" and "data". However, "pdev" is already included in "data". Furthermore, the "pdev" parameter is no longer used in k10temp_get_ccd_support(), since its use was moved into read_ccd_temp_reg(). Drop the "pdev" input parameter as it is no longer needed. No functional change is intended. Signed-off-by: Yazen Ghannam Acked-by: Guenter Roeck --- drivers/hwmon/k10temp.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c index 06af1fe38af7..873dbe0f5806 100644 --- a/drivers/hwmon/k10temp.c +++ b/drivers/hwmon/k10temp.c @@ -379,8 +379,7 @@ static const struct hwmon_chip_info k10temp_chip_info = { .info = k10temp_info, }; -static void k10temp_get_ccd_support(struct pci_dev *pdev, - struct k10temp_data *data, int limit) +static void k10temp_get_ccd_support(struct k10temp_data *data, int limit) { u32 regval; int i; @@ -435,18 +434,18 @@ static int k10temp_probe(struct pci_dev *pdev, const struct pci_device_id *id) case 0x11: /* Zen APU */ case 0x18: /* Zen+ APU */ data->ccd_offset = 0x154; - k10temp_get_ccd_support(pdev, data, 4); + k10temp_get_ccd_support(data, 4); break; case 0x31: /* Zen2 Threadripper */ case 0x60: /* Renoir */ case 0x68: /* Lucienne */ case 0x71: /* Zen2 */ data->ccd_offset = 0x154; - k10temp_get_ccd_support(pdev, data, 8); + k10temp_get_ccd_support(data, 8); break; case 0xa0 ... 0xaf: data->ccd_offset = 0x300; - k10temp_get_ccd_support(pdev, data, 8); + k10temp_get_ccd_support(data, 8); break; } } else if (boot_cpu_data.x86 == 0x19) { @@ -459,21 +458,21 @@ static int k10temp_probe(struct pci_dev *pdev, const struct pci_device_id *id) case 0x21: /* Zen3 Ryzen Desktop */ case 0x50 ... 0x5f: /* Green Sardine */ data->ccd_offset = 0x154; - k10temp_get_ccd_support(pdev, data, 8); + k10temp_get_ccd_support(data, 8); break; case 0x40 ... 0x4f: /* Yellow Carp */ data->ccd_offset = 0x300; - k10temp_get_ccd_support(pdev, data, 8); + k10temp_get_ccd_support(data, 8); break; case 0x60 ... 0x6f: case 0x70 ... 0x7f: data->ccd_offset = 0x308; - k10temp_get_ccd_support(pdev, data, 8); + k10temp_get_ccd_support(data, 8); break; case 0x10 ... 0x1f: case 0xa0 ... 0xaf: data->ccd_offset = 0x300; - k10temp_get_ccd_support(pdev, data, 12); + k10temp_get_ccd_support(data, 12); break; } } else {