linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] wifi: mt76: mt7915: rework thermal protection
@ 2022-12-06  1:29 Howard Hsu
  2022-12-06  1:29 ` [PATCH 1/3] wifi: mt76: mt7915: rework mt7915_thermal_set_cur_throttle_state() Howard Hsu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Howard Hsu @ 2022-12-06  1:29 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: Lorenzo Bianconi, Ryder Lee, Shayne Chen, Evelyn Tsai,
	linux-wireless, linux-mediatek, Howard Hsu

*** BLURB HERE ***

Howard Hsu (3):
  wifi: mt76: mt7915: rework mt7915_thermal_set_cur_throttle_state()
  wifi: mt76: mt7915: call mt7915_mcu_set_thermal_throttling() only
    after init_work
  wifi: mt76: mt7915: rework mt7915_mcu_set_thermal_throttling()

 .../net/wireless/mediatek/mt76/mt7915/init.c  | 21 ++++++++++---------
 .../net/wireless/mediatek/mt76/mt7915/main.c  |  5 +++++
 .../net/wireless/mediatek/mt76/mt7915/mcu.c   | 17 ++++++++-------
 3 files changed, 26 insertions(+), 17 deletions(-)

-- 
2.18.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] wifi: mt76: mt7915: rework mt7915_thermal_set_cur_throttle_state()
  2022-12-06  1:29 [PATCH 0/3] wifi: mt76: mt7915: rework thermal protection Howard Hsu
@ 2022-12-06  1:29 ` Howard Hsu
  2022-12-06  1:29 ` [PATCH 2/3] wifi: mt76: mt7915: call mt7915_mcu_set_thermal_throttling() only after init_work Howard Hsu
  2022-12-06  1:29 ` [PATCH 3/3] wifi: mt76: mt7915: rework mt7915_mcu_set_thermal_throttling() Howard Hsu
  2 siblings, 0 replies; 4+ messages in thread
From: Howard Hsu @ 2022-12-06  1:29 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: Lorenzo Bianconi, Ryder Lee, Shayne Chen, Evelyn Tsai,
	linux-wireless, linux-mediatek, Howard Hsu, Ryder Lee

This patch includes 3 changes:
1. The maximum throttle state can be set to 100 to fix the problem that maximum tx
cyle can only be set to 99.
2. Throttle state do not need to be different from the previous state.
This will make it is impossible for users to just change the
trigger/restore temp but not the throttle state.
3. Add dev_err so that it is easier to see invalid setting while looking at dmesg.

Fixes: 9fee8f3736eb ("mt76: mt7915e: Fix degraded performance after temporary overheat")
Co-developed-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Howard Hsu <howard-yh.hsu@mediatek.com>
---
 .../net/wireless/mediatek/mt76/mt7915/init.c   | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/init.c b/drivers/net/wireless/mediatek/mt76/mt7915/init.c
index c810c31fbd6e..abeecf15f1c8 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/init.c
@@ -131,14 +131,17 @@ mt7915_thermal_set_cur_throttle_state(struct thermal_cooling_device *cdev,
 	u8 throttling = MT7915_THERMAL_THROTTLE_MAX - state;
 	int ret;
 
-	if (state > MT7915_CDEV_THROTTLE_MAX)
+	if (state > MT7915_THERMAL_THROTTLE_MAX) {
+		dev_err(phy->dev->mt76.dev,
+			"please specify a valid throttling state\n");
 		return -EINVAL;
+	}
 
-	if (phy->throttle_temp[0] > phy->throttle_temp[1])
-		return 0;
-
-	if (state == phy->cdev_state)
-		return 0;
+	if (phy->throttle_temp[0] > phy->throttle_temp[1]) {
+		dev_err(phy->dev->mt76.dev,
+			"temp1_crit shall not be greater than temp1_max\n");
+		return -EINVAL;
+	}
 
 	/*
 	 * cooling_device convention: 0 = no cooling, more = more cooling
@@ -164,7 +167,7 @@ static void mt7915_unregister_thermal(struct mt7915_phy *phy)
 	struct wiphy *wiphy = phy->mt76->hw->wiphy;
 
 	if (!phy->cdev)
-	    return;
+		return;
 
 	sysfs_remove_link(&wiphy->dev.kobj, "cooling_device");
 	thermal_cooling_device_unregister(phy->cdev);
@@ -1101,7 +1104,6 @@ static void mt7915_stop_hardware(struct mt7915_dev *dev)
 		mt7986_wmac_disable(dev);
 }
 
-
 int mt7915_register_device(struct mt7915_dev *dev)
 {
 	struct ieee80211_hw *hw = mt76_hw(dev);
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] wifi: mt76: mt7915: call mt7915_mcu_set_thermal_throttling() only after init_work
  2022-12-06  1:29 [PATCH 0/3] wifi: mt76: mt7915: rework thermal protection Howard Hsu
  2022-12-06  1:29 ` [PATCH 1/3] wifi: mt76: mt7915: rework mt7915_thermal_set_cur_throttle_state() Howard Hsu
@ 2022-12-06  1:29 ` Howard Hsu
  2022-12-06  1:29 ` [PATCH 3/3] wifi: mt76: mt7915: rework mt7915_mcu_set_thermal_throttling() Howard Hsu
  2 siblings, 0 replies; 4+ messages in thread
From: Howard Hsu @ 2022-12-06  1:29 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: Lorenzo Bianconi, Ryder Lee, Shayne Chen, Evelyn Tsai,
	linux-wireless, linux-mediatek, Howard Hsu

Enable thermal management by default shall not be executed during mcu
init. This causes thermal configuration being reset to the firmware
default settings.

Fixes: c67df0d3130a ("mt76: mt7915e: Enable thermal management by default")
Signed-off-by: Howard Hsu <howard-yh.hsu@mediatek.com>
---
 drivers/net/wireless/mediatek/mt76/mt7915/init.c | 3 +--
 drivers/net/wireless/mediatek/mt76/mt7915/main.c | 5 +++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/init.c b/drivers/net/wireless/mediatek/mt76/mt7915/init.c
index abeecf15f1c8..8f4561eed5db 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/init.c
@@ -204,8 +204,7 @@ static int mt7915_thermal_init(struct mt7915_phy *phy)
 	phy->throttle_temp[0] = 110;
 	phy->throttle_temp[1] = 120;
 
-	return mt7915_mcu_set_thermal_throttling(phy,
-						 MT7915_THERMAL_THROTTLE_MAX);
+	return 0;
 }
 
 static void mt7915_led_set_config(struct led_classdev *led_cdev,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
index 0511d6a505b0..fc87216e40b1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
@@ -57,6 +57,11 @@ int mt7915_run(struct ieee80211_hw *hw)
 		mt7915_mac_enable_nf(dev, phy->mt76->band_idx);
 	}
 
+	ret = mt7915_mcu_set_thermal_throttling(phy, MT7915_THERMAL_THROTTLE_MAX);
+
+	if (ret)
+		goto out;
+
 	ret = mt76_connac_mcu_set_rts_thresh(&dev->mt76, 0x92b,
 					     phy->mt76->band_idx);
 	if (ret)
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] wifi: mt76: mt7915: rework mt7915_mcu_set_thermal_throttling()
  2022-12-06  1:29 [PATCH 0/3] wifi: mt76: mt7915: rework thermal protection Howard Hsu
  2022-12-06  1:29 ` [PATCH 1/3] wifi: mt76: mt7915: rework mt7915_thermal_set_cur_throttle_state() Howard Hsu
  2022-12-06  1:29 ` [PATCH 2/3] wifi: mt76: mt7915: call mt7915_mcu_set_thermal_throttling() only after init_work Howard Hsu
@ 2022-12-06  1:29 ` Howard Hsu
  2 siblings, 0 replies; 4+ messages in thread
From: Howard Hsu @ 2022-12-06  1:29 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: Lorenzo Bianconi, Ryder Lee, Shayne Chen, Evelyn Tsai,
	linux-wireless, linux-mediatek, Howard Hsu

Firmware expects to disable thermal protect first before reconfiguring.

Fixes: afab0e8202ff ("mt76: mt7915: add thermal cooling device support")
Signed-off-by: Howard Hsu <howard-yh.hsu@mediatek.com>
---
 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
index b2652de082ba..e1b6d644cc14 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
@@ -3070,18 +3070,22 @@ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state)
 	} __packed req = {
 		.ctrl = {
 			.band_idx = phy->mt76->band_idx,
+			.type.protect_type = 1,
+			.type.trigger_type = 1,
 		},
 	};
-	int level;
+	int level, ret;
 
-	if (!state) {
-		req.ctrl.ctrl_id = THERMAL_PROTECT_DISABLE;
-		goto out;
-	}
+	req.ctrl.ctrl_id = THERMAL_PROTECT_DISABLE;
+
+	ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT),
+				&req, sizeof(req.ctrl), false);
+
+	if (ret || !state)
+		return ret;
 
 	/* set duty cycle and level */
 	for (level = 0; level < 4; level++) {
-		int ret;
 
 		req.ctrl.ctrl_id = THERMAL_PROTECT_DUTY_CONFIG;
 		req.ctrl.duty.duty_level = level;
@@ -3101,7 +3105,6 @@ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state)
 	req.trigger_temp = cpu_to_le32(phy->throttle_temp[1]);
 	req.sustain_time = cpu_to_le16(10);
 
-out:
 	req.ctrl.type.protect_type = 1;
 	req.ctrl.type.trigger_type = 1;
 
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-06  1:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06  1:29 [PATCH 0/3] wifi: mt76: mt7915: rework thermal protection Howard Hsu
2022-12-06  1:29 ` [PATCH 1/3] wifi: mt76: mt7915: rework mt7915_thermal_set_cur_throttle_state() Howard Hsu
2022-12-06  1:29 ` [PATCH 2/3] wifi: mt76: mt7915: call mt7915_mcu_set_thermal_throttling() only after init_work Howard Hsu
2022-12-06  1:29 ` [PATCH 3/3] wifi: mt76: mt7915: rework mt7915_mcu_set_thermal_throttling() Howard Hsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).