Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp85871lqb; Thu, 23 May 2024 11:28:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1RvZ59Tr5bq2afqemgZkGQmdwfbWAFPr9QXXJJRsbki5ZQ237IbNHyTnFwgUljWa5oyQvPKC1QtrRGPV4EGeH5/Vmcyc/LYeNHi9Fgw== X-Google-Smtp-Source: AGHT+IFpC64RoFogpfJmHfSKC5MOa70OsoT/fflBKxzTJGGJysyXQPK8r7lU5NQ3FSw5g3eSeFEa X-Received: by 2002:a17:902:d50b:b0:1e4:2859:e59b with SMTP id d9443c01a7336-1f339f5fb15mr43155765ad.28.1716488910309; Thu, 23 May 2024 11:28:30 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f2f0067b80si5319085ad.621.2024.05.23.11.28.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 11:28:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187875-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=e9bwMbo8; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-187875-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187875-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C10552823D2 for ; Thu, 23 May 2024 18:28:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C205C84D08; Thu, 23 May 2024 18:27:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="e9bwMbo8" Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2060.outbound.protection.outlook.com [40.107.94.60]) (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 D2ED883CC8; Thu, 23 May 2024 18:27:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.60 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716488841; cv=fail; b=VowdkMemTZg93FYOOFvid0jn8r5vm+riq5BrZ5REQN2kH1DY0Y+bp05YvPpba0qbdg61wbF1Ni7ARrUoofGIUUatqMg1Lo+nNXFGrb18m4IZvAA1scqm2pkPLXdpQ5mwhLvi9yZ9aaLRFuXVZN3/352/4cu5kjvYKvThHfRePDo= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716488841; c=relaxed/simple; bh=wS3+mE2h5wAiqHNbd5F0/aPcPHQiIWNi1aQuBqT3Qf4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=i9zKitCVnat4xnpcbaJ1/ef3WVYZlfsvW5B+J0ZP7rBDrantQbG5r2pwZak0gXquzNRBHYVEbf0ze+m39a1GiXWaKrdfkx4tJozxyj2GiBtACkoo0FaWH7ZW82+bLoQWqcW6Md5+cYrsn94T18cSLzWJuRxIU3U2LtWBgL5FogM= 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=e9bwMbo8; arc=fail smtp.client-ip=40.107.94.60 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=Cfjno8kNge2FVbgJYiNZNhXiZqpDRvQJPezQ62W76NVnzZYQVDJkdTQ16S4iZjM6Jjf16GjkJvqlabXJinh1FyMVlotIHJJu/OPfwqbfsh9u5UCIDGXrLZYwqfxjbLc3Ohf5u6IiRrP/Uh/2Z2gTmkiZe5zWhcVTtLYPvabjgsf0roU/520qnjKJJduZEdsdC8WnFAaTVNN3vEOUon7qNTLbYVxI+dQa+p9fl/U2WsFyQznbD/8tFHrUgENg3EblhyxJCujhJb6o4okyjq/iXmEk9PbmuwIklb7WEmtWLnxd4DrimYmf7k+Y4dfpXUO350lQpNQaZt+hFPg3pAFpzw== 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=jj/+7k7go6xrVhHdzhoCtB16C6b241CBx9n9cd7OnnU7FXv98wZDN9kwm6QIY0YL4ccS9FbLe3IC/KEZfF+DH3TTvDU5hE1tdCtQJaZeM2Qm59QQS/HfrC+da7kVihk4fzBeJmP4gAVqCExaQfYpJxY1tKE4jE8eFiLz8bQkwQAXGvLRnJDpf6JjRH4KULCMtT+rTtLtk432gutlZFrHVSy8agMPS0jk42vL/PsHO+nqhjIDSXuXnjbZgJAaRqwH+LNJ+4Tj8Hqo3iH7w8U66vwt9D4/gyGjbQtqddXpi8AqRiu70cF3QGNRiy1ArdOLedtxDIo5ukrZSiBFsvt/LQ== 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 (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=e9bwMbo83G8VUAqlpM/7ZPOq4EtbvucpR9M6MWLQdn7Rj0OtMi4cgV9Q313TzTj4JJMVxEQHfPoC+QXCREvYDwrqtfWLvMFsXKGca4ODO3djua3r15fzj+igaWdhlDlPhgd09q9Yp8mDpUvnTFynXpr3msx8IvFEdnyBbcZM29c= Received: from DS7PR03CA0261.namprd03.prod.outlook.com (2603:10b6:5:3b3::26) by DM4PR12MB6037.namprd12.prod.outlook.com (2603:10b6:8:b0::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.19; Thu, 23 May 2024 18:27:15 +0000 Received: from CH3PEPF00000011.namprd21.prod.outlook.com (2603:10b6:5:3b3:cafe::bd) by DS7PR03CA0261.outlook.office365.com (2603:10b6:5:3b3::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.18 via Frontend Transport; Thu, 23 May 2024 18:27:15 +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 CH3PEPF00000011.mail.protection.outlook.com (10.167.244.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.0 via Frontend Transport; Thu, 23 May 2024 18:27:15 +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, 23 May 2024 13:27:10 -0500 From: Yazen Ghannam Date: Thu, 23 May 2024 13:26:56 -0500 Subject: [PATCH v3 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: <20240523-fix-smn-bad-read-v3-5-aa44c622de39@amd.com> References: <20240523-fix-smn-bad-read-v3-0-aa44c622de39@amd.com> In-Reply-To: <20240523-fix-smn-bad-read-v3-0-aa44c622de39@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: CH3PEPF00000011:EE_|DM4PR12MB6037:EE_ X-MS-Office365-Filtering-Correlation-Id: acf9d69c-106d-4c9e-8ccc-08dc7b55f8af X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|82310400017|36860700004|376005; X-Microsoft-Antispam-Message-Info: =?utf-8?B?V0ZMYkIxUm5pd0dLYjlGejhBd3RNSlJuckNCRXdLK2FVazdvQ1M1clZLcit3?= =?utf-8?B?Y2NkNGhkcWdkWTdPVmt6TS9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;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(1800799015)(82310400017)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 18:27:15.3833 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: acf9d69c-106d-4c9e-8ccc-08dc7b55f8af 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: CH3PEPF00000011.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6037 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