Skip to contentSkip to conversation

r8169: extend hwmon support

PATCH In review Heiner Kallweit 3 participants 11 messages Jan 6, 2025 – Jan 8, 2025

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

cover r8169: extend hwmon support

This series extends the hwmon support and adds support for the over-temp threshold.

Heiner Kallweit (2):
r8169: prepare for extending hwmon support
r8169: add support for reading over-temp threshold

 drivers/net/ethernet/realtek/r8169_main.c | 30 +++++++++++++++++------
 1 file changed, 23 insertions(+), 7 deletions(-)
Signature · 1 line
2.47.1
author maintainer
#1 lore raw

PATCH 1/2 r8169: prepare for extending hwmon support

This factors out the temperature value calculation and prepares for adding further temperature attributes.

---
 drivers/net/ethernet/realtek/r8169_main.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +17 -6
index 5724f650f..38f915956 100644
@@ -5338,17 +5338,28 @@ static bool rtl_aspm_is_safe(struct rtl8169_private *tp)
 	return false;
 }
 
+static int r8169_hwmon_get_temp(int raw)
+{
+	if (raw >= 512)
+		raw -= 1024;
+
+	return 1000 * raw / 2;
+}
+
 static int r8169_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
 			    u32 attr, int channel, long *val)
 {
 	struct rtl8169_private *tp = dev_get_drvdata(dev);
-	int val_raw;
-
-	val_raw = phy_read_paged(tp->phydev, 0xbd8, 0x12) & 0x3ff;
-	if (val_raw >= 512)
-		val_raw -= 1024;
+	int raw;
 
-	*val = 1000 * val_raw / 2;
+	switch (attr) {
+	case hwmon_temp_input:
+		raw = phy_read_paged(tp->phydev, 0xbd8, 0x12) & 0x3ff;
+		*val = r8169_hwmon_get_temp(raw);
+		break;
+	default:
+		return -EINVAL;
+	}
 
 	return 0;
 }
Signature · 1 line
2.47.1
author maintainer
#3 lore raw

PATCH 2/2 r8169: add support for reading over-temp threshold

In reply to Heiner Kallweit

Add support for reading the over-temp threshold. If the chip temperature exceeds this value, the chip will reduce the speed to 1Gbps (by disabling 2.5G/5G advertisement and triggering a renegotiation).

---
 drivers/net/ethernet/realtek/r8169_main.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ethernet/realtek/r8169_main.c +6 -1
index 38f915956..fd6ff77e8 100644
@@ -5357,6 +5357,11 @@ static int r8169_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
 		raw = phy_read_paged(tp->phydev, 0xbd8, 0x12) & 0x3ff;
 		*val = r8169_hwmon_get_temp(raw);
 		break;
+	case hwmon_temp_max:
+		/* Chip reduces speed to 1G if threshold is exceeded */
+		raw = phy_read_paged(tp->phydev, 0xb54, 0x16) >> 6;
+		*val = r8169_hwmon_get_temp(raw);
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -5370,7 +5375,7 @@ static const struct hwmon_ops r8169_hwmon_ops = {
 };
 
 static const struct hwmon_channel_info * const r8169_hwmon_info[] = {
-	HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
+	HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_MAX),
 	NULL
 };
 
Signature · 1 line
2.47.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH net-next 2/2] r8169: add support for reading over-temp threshold

Quoted 3 lines · Heiner Kallweit

Add support for reading the over-temp threshold. If the chip temperature exceeds this value, the chip will reduce the speed to 1Gbps (by disabling 2.5G/5G advertisement and triggering a renegotiation).

I'm assuming here that the over-temp threshold always exists when the temp_in sensors exists? If so:

Does it reduce the speed in the same way as downshift? Can the user tell it has happened, other than networking is slower?

Andrew

author maintainer
#5 lore raw

Re: [PATCH net-next 2/2] r8169: add support for reading over-temp threshold

Quoted 8 lines · Andrew Lunn
Quoted 3 lines · Heiner Kallweit

Add support for reading the over-temp threshold. If the chip temperature exceeds this value, the chip will reduce the speed to 1Gbps (by disabling 2.5G/5G advertisement and triggering a renegotiation).

I'm assuming here that the over-temp threshold always exists when the temp_in sensors exists? If so:

Right

Quoted 5 lines

Does it reduce the speed in the same way as downshift? Can the user tell it has happened, other than networking is slower?

It internally disables 2.5G/5G advertisement and triggers an autoneg. So you get the usual message on console/dmesg indicating the new speed. This internal action sets a register bit, and it can also trigger an interrupt. So it should be possible to check in the link_change_notify() callback whether an over-temp event occurred. The silent change of the advertisement may also result in the phylib-cached advertisement being out-of-sync. So we would have to re-sync it. But I didn't fully test this yet.

This patch only allows to read the over-temp threshold set as power-on default or by the boot loader. It doesn't change the existing behavior.

Quoted 1 line

Andrew

Heiner

#6 lore raw

Re: [PATCH net-next 2/2] r8169: add support for reading over-temp threshold

Quoted 11 lines
Quoted 3 lines

Does it reduce the speed in the same way as downshift? Can the user tell it has happened, other than networking is slower?

It internally disables 2.5G/5G advertisement and triggers an autoneg. So you get the usual message on console/dmesg indicating the new speed. This internal action sets a register bit, and it can also trigger an interrupt. So it should be possible to check in the link_change_notify() callback whether an over-temp event occurred. The silent change of the advertisement may also result in the phylib-cached advertisement being out-of-sync. So we would have to re-sync it. But I didn't fully test this yet.

Quoted 2 lines

This patch only allows to read the over-temp threshold set as power-on default or by the boot loader. It doesn't change the existing behavior.

Thanks for the details. So it does seem to be different to downshift, where generally advertised link modes in the registers is not changed, and the speed indicated in BMSR generally does not indicate the downshifted speed, you need vendor registers to get the actual speed. But downshift happens at link up, not latter when the device starts to overheat.

Does it restore advertisement to 2.5G/5G when it cools down? There is an interesting policy decision here. Do you want 1s downtime very so often as it speeds up and slows down, or should it keep at the slower speed until the user kicks it back up to the higher speed?

Andrew

author maintainer
#7 lore raw

Re: [PATCH net-next 2/2] r8169: add support for reading over-temp threshold

Quoted 21 lines · Andrew Lunn
Quoted 11 lines
Quoted 3 lines

Does it reduce the speed in the same way as downshift? Can the user tell it has happened, other than networking is slower?

It internally disables 2.5G/5G advertisement and triggers an autoneg. So you get the usual message on console/dmesg indicating the new speed. This internal action sets a register bit, and it can also trigger an interrupt. So it should be possible to check in the link_change_notify() callback whether an over-temp event occurred. The silent change of the advertisement may also result in the phylib-cached advertisement being out-of-sync. So we would have to re-sync it. But I didn't fully test this yet.

Quoted 2 lines

This patch only allows to read the over-temp threshold set as power-on default or by the boot loader. It doesn't change the existing behavior.

Thanks for the details. So it does seem to be different to downshift, where generally advertised link modes in the registers is not changed, and the speed indicated in BMSR generally does not indicate the downshifted speed, you need vendor registers to get the actual speed. But downshift happens at link up, not latter when the device starts to overheat.

Quoted 5 lines

Does it restore advertisement to 2.5G/5G when it cools down? There is an interesting policy decision here. Do you want 1s downtime very so often as it speeds up and slows down, or should it keep at the slower speed until the user kicks it back up to the higher speed?

I will do more testing and provide an update.

Quoted 2 lines

Andrew

Heiner

maintainer
#8 lore raw

Re: [PATCH net-next 2/2] r8169: add support for reading over-temp threshold

In reply to Heiner Kallweit
Quoted 3 lines · On Mon, 6 Jan 2025 19:05:13 +0100 Heiner Kallweit wrote:

Add support for reading the over-temp threshold. If the chip temperature exceeds this value, the chip will reduce the speed to 1Gbps (by disabling 2.5G/5G advertisement and triggering a renegotiation).

If there is a v2 -- please make sure hwmon folks are CCed. Looks like get_maintainers doesn't flag it, but since we're charting a new territory for networking a broader audience may be quite useful.

author maintainer
#9 lore raw

Re: [PATCH net-next 2/2] r8169: add support for reading over-temp threshold

Quoted 8 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 6 Jan 2025 19:05:13 +0100 Heiner Kallweit wrote:

Add support for reading the over-temp threshold. If the chip temperature exceeds this value, the chip will reduce the speed to 1Gbps (by disabling 2.5G/5G advertisement and triggering a renegotiation).

If there is a v2 -- please make sure hwmon folks are CCed. Looks like get_maintainers doesn't flag it, but since we're charting a new territory for networking a broader audience may be quite useful.

OK. No v2 is planned, but there may be follow-up patches.

author maintainer
#10 lore raw
In reply to Heiner Kallweit
Quoted 10 lines · Heiner Kallweit

This series extends the hwmon support and adds support for the over-temp threshold.

Heiner Kallweit (2):
r8169: prepare for extending hwmon support
r8169: add support for reading over-temp threshold

 drivers/net/ethernet/realtek/r8169_main.c | 30 +++++++++++++++++------
 1 file changed, 23 insertions(+), 7 deletions(-)

These patches are superseded. The temperature sensor is also available in the standalone version of the integrated PHY, so I'll move the hwmon support to the Realtek PHY driver.