Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp491903lqt; Thu, 6 Jun 2024 09:18:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVqWnJn1Mxq8nkYDPwiERV5sil8TDdsRM6f1Yjso79FcxveMh/92kFsyWiz+I+W80W+FGSWGa2JgkwXYZf44YSvsHHMg35lJT+hQ4O52Q== X-Google-Smtp-Source: AGHT+IFtybcfHCsrP/zF8QTau2bBSv3CprxBoTTMCmQHaxCxkJlJRG0PtQT8JpJE3h9LPHi6EYkB X-Received: by 2002:a05:6214:5d8b:b0:6af:f898:71f1 with SMTP id 6a1803df08f44-6b0595d2f49mr2378326d6.21.1717690700333; Thu, 06 Jun 2024 09:18:20 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6b04f967df9si17708636d6.280.2024.06.06.09.18.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 09:18:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204673-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=dXRFRNAq; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-204673-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204673-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DCA181C25FB6 for ; Thu, 6 Jun 2024 16:18:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31E6419B5AA; Thu, 6 Jun 2024 16:13:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="dXRFRNAq" Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2081.outbound.protection.outlook.com [40.107.92.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 589D219B3DB; Thu, 6 Jun 2024 16:13:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.81 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717690411; cv=fail; b=U5hfbOpYLcaZ6quRAjxgpUm7gS9zxe/hJpwbDQqx79AsCguqRNG+veT2qaN1Xu6mj9zbiAyoqJNfI4e+Qn7sGRbho6AmMAa5WwW9FrahulHU0l+nYPCDGD5LMO0RRAk78FRFbIe1aHQa/LYBB4JTKdPYcfe1/a4jSZlauXCXe/Q= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717690411; c=relaxed/simple; bh=wS3+mE2h5wAiqHNbd5F0/aPcPHQiIWNi1aQuBqT3Qf4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=pP6m2oVS6+vxBFeIihKZPxZLegKjUs1iIZVapJWPgdByOFrqqbQrIPn3ILoRlSwbg73qbGHjTV0EF8P58bJ8tWvFfCk/lpuXrndI9q3q09ISXeLpPFhSITiktEy7mHPnMYsHdf+cSIEZxnbnlvaKJgUqfEnQ4UhCWAVLRccv4WU= 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=dXRFRNAq; arc=fail smtp.client-ip=40.107.92.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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bB+f99TuKqWxqLYoovwCtNdmW9T4IRZIUju/DrYJ+KUubaAfYUFiEHmh8/3lgzsZviCykD8F5PxkS1nglf9zHQyzIm1bDQrL86GcEvSa1i7TCs+PywtL/AOCWjfQ5FMF+sagj3T2k1dvcP9/O6XVj0IL6/L5B2kus5oO+W3/R9ALsMNWP/wa1dbtABPlY0pXzRL/jk+KtV9HXrb16GF7QOAxZYaDS7V9SkCZoYWxPhaVtbMFevsSPQ5rH7jyivu/6LS+8zrbqk6A6JNaVq2uXnprC87k8ijF7MDDNesA8KhVCWJnjkBX1/s4aOblqKJILYDrDPl6LgMV1gH3f4GGDw== 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=QSVWdwBYxEnXSQDb11DLW1FrriGwziZwr5kWDaJdBUU=; b=DyaStnTPp4ll++mehWt0Z7tTgPoYUiKW3zeNhq2bPhe9/mRs4JEr/4Crc6cZnz35wjZrvywvOyWKAOLiSsT3VRVZyqc8TSlA5sOBliN6hVNuLVqfzEt7qocX+9jPfz28wkGPv/X0mahtJrEDV7e+xfdKKhC7C+oCg6xnvbMJsoJbaWL/RnxIy0OYoPH5XuW6CU7RV7D2ayDjwBOe3DBo6RRBsFs0Kv0aKzmYSF23xTlxmQ4ddXMBBxtFWsmJeNsdeUxKpwgq5WFiNrKNuOKf7Mv2pZUMtoTLTi0bWbt4XfykU8in+jZ32es7RdaIBVTMdOcADRub9QqB2awGCxNqqw== 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=QSVWdwBYxEnXSQDb11DLW1FrriGwziZwr5kWDaJdBUU=; b=dXRFRNAqC+VtpMgSqUun6o41B9p5+7v2VAnMVyVf8odHqbmAWqGh53Gc3qxH0rjhmTxPXPmZIIiLGW0JD9iX7vgym5ZyTOXkfN+RsoJDE57P9WzfSb8aPuzezp/g4E0dW9Si+KwHojfXctMD+B113gkJyZuOKM0/7b18g1D51/c= Received: from CH0PR04CA0112.namprd04.prod.outlook.com (2603:10b6:610:75::27) by CY5PR12MB9053.namprd12.prod.outlook.com (2603:10b6:930:37::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.17; Thu, 6 Jun 2024 16:13:23 +0000 Received: from CH2PEPF00000146.namprd02.prod.outlook.com (2603:10b6:610:75:cafe::2e) by CH0PR04CA0112.outlook.office365.com (2603:10b6:610:75::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.21 via Frontend Transport; Thu, 6 Jun 2024 16:13:23 +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 CH2PEPF00000146.mail.protection.outlook.com (10.167.244.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Thu, 6 Jun 2024 16:13:23 +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.2507.35; Thu, 6 Jun 2024 11:13:21 -0500 From: Yazen Ghannam Date: Thu, 6 Jun 2024 11:12:58 -0500 Subject: [PATCH v4 5/8] hwmon: (k10temp) Define helper function to read CCD temp Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-ID: <20240606-fix-smn-bad-read-v4-5-ffde21931c3f@amd.com> References: <20240606-fix-smn-bad-read-v4-0-ffde21931c3f@amd.com> In-Reply-To: <20240606-fix-smn-bad-read-v4-0-ffde21931c3f@amd.com> To: Guenter Roeck , , Yazen Ghannam CC: Mario Limonciello , , , , X-Mailer: b4 0.13.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: CH2PEPF00000146:EE_|CY5PR12MB9053:EE_ X-MS-Office365-Filtering-Correlation-Id: e3c0f5d4-4619-45f6-18d8-08dc864396e5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|82310400017|376005|36860700004; X-Microsoft-Antispam-Message-Info: =?utf-8?B?TWtYZlZldXRmWTFHbnFocVAyNFhRam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QXI2MXVGYWNKdk12cHgvODM5bnk1TzhVak13SWUwbzMzV2dlNC94c2t3?= =?utf-8?B?ZmdsQllHa0d0MTJvSm81YWY0MEdtRDQ2ckIwWWFLd1RoZlE9PQ==?= 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:(13230031)(1800799015)(82310400017)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2024 16:13:23.1357 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e3c0f5d4-4619-45f6-18d8-08dc864396e5 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: CH2PEPF00000146.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB9053 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 Reviewed-by: Mario Limonciello Acked-by: Guenter Roeck --- drivers/hwmon/k10temp.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c index 6cad35e7f182..315c52de6e54 100644 --- a/drivers/hwmon/k10temp.c +++ b/drivers/hwmon/k10temp.c @@ -158,6 +158,13 @@ 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); + + return amd_smn_read(node_id, ZEN_CCD_TEMP(data->ccd_offset, ccd), regval); +} + static long get_raw_temp(struct k10temp_data *data) { u32 regval; @@ -223,9 +230,7 @@ static int k10temp_read_temp(struct device *dev, u32 attr, int channel, *val = 0; break; case 2 ... 13: /* Tccd{1-12} */ - ret = amd_smn_read(amd_pci_dev_to_node_id(data->pdev), - ZEN_CCD_TEMP(data->ccd_offset, channel - 2), - ®val); + ret = read_ccd_temp_reg(data, channel - 2, ®val); if (ret) return ret; @@ -397,8 +402,7 @@ static void k10temp_get_ccd_support(struct pci_dev *pdev, * the register value. And this will incorrectly pass the TEMP_VALID * bit check. */ - 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) -- 2.34.1