From: Yazen Ghannam <yazen.ghannam@amd.com>
To: Guenter Roeck <linux@roeck-us.net>, <x86@kernel.org>,
Yazen Ghannam <yazen.ghannam@amd.com>
Cc: Mario Limonciello <mario.limonciello@amd.com>,
<linux-edac@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-hwmon@vger.kernel.org>
Subject: [PATCH v3 5/8] hwmon: (k10temp) Define helper function to read CCD temp
Date: Thu, 23 May 2024 13:26:56 -0500 [thread overview]
Message-ID: <20240523-fix-smn-bad-read-v3-5-aa44c622de39@amd.com> (raw)
In-Reply-To: <20240523-fix-smn-bad-read-v3-0-aa44c622de39@amd.com>
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 <yazen.ghannam@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Acked-by: Guenter Roeck <linux@roeck-us.net>
---
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
next prev parent reply other threads:[~2024-05-23 18:27 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-23 18:26 [PATCH v3 0/8] Enhance AMD SMN Error Checking Yazen Ghannam
2024-05-23 18:26 ` [PATCH v3 1/8] EDAC/amd64: Remove unused register accesses Yazen Ghannam
2024-06-05 8:51 ` Borislav Petkov
2024-05-23 18:26 ` [PATCH v3 2/8] EDAC/amd64: Check return value of amd_smn_read() Yazen Ghannam
2024-05-25 13:22 ` Markus Elfring
2024-06-05 9:47 ` Borislav Petkov
2024-05-23 18:26 ` [PATCH v3 3/8] hwmon: (k10temp) " Yazen Ghannam
2024-05-25 13:32 ` Markus Elfring
2024-06-05 12:20 ` Borislav Petkov
2024-06-05 13:41 ` Yazen Ghannam
2024-06-05 16:12 ` Borislav Petkov
2024-06-05 16:30 ` Yazen Ghannam
2024-06-05 16:45 ` Borislav Petkov
2024-06-05 17:41 ` Yazen Ghannam
2024-05-23 18:26 ` [PATCH v3 4/8] x86/amd_nb: Enhance SMN access error checking Yazen Ghannam
2024-05-25 13:55 ` Markus Elfring
2024-05-23 18:26 ` Yazen Ghannam [this message]
2024-05-23 18:26 ` [PATCH v3 6/8] hwmon: (k10temp) Reduce k10temp_get_ccd_support() parameters Yazen Ghannam
2024-05-25 14:43 ` Markus Elfring
2024-05-23 18:26 ` [PATCH v3 7/8] hwmon: (k10temp) Remove unused HAVE_TDIE() macro Yazen Ghannam
2024-05-23 19:31 ` Guenter Roeck
2024-05-25 15:00 ` Markus Elfring
2024-05-23 18:26 ` [PATCH v3 8/8] hwmon: (k10temp) Rename _data variable Yazen Ghannam
2024-05-23 19:32 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240523-fix-smn-bad-read-v3-5-aa44c622de39@amd.com \
--to=yazen.ghannam@amd.com \
--cc=linux-edac@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mario.limonciello@amd.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox