[][MAC80211][MT76][Rework Thermal Protection]
[Description]
Fix thermal protection bugs.
[Release-log]
N/A
Change-Id: I3ec0295572893c14c662a172349110e4129d1ce3
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/6923892
diff --git a/autobuild_mac80211_release/package/kernel/mt76/patches/0002-wifi-mt76-mt7915-rework-mt7915_mcu_set_thermal_throt.patch b/autobuild_mac80211_release/package/kernel/mt76/patches/0002-wifi-mt76-mt7915-rework-mt7915_mcu_set_thermal_throt.patch
new file mode 100644
index 0000000..618a14e
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mt76/patches/0002-wifi-mt76-mt7915-rework-mt7915_mcu_set_thermal_throt.patch
@@ -0,0 +1,151 @@
+From 906bad79c7beb43c81a80fdb97898ebb977e527a Mon Sep 17 00:00:00 2001
+From: Howard Hsu <howard-yh.hsu@mediatek.com>
+Date: Mon, 5 Dec 2022 14:09:18 +0800
+Subject: [PATCH 2/4] wifi: mt76: mt7915: rework
+ mt7915_mcu_set_thermal_throttling
+
+This patch includes 2 changes:
+1. Firmware expects to disable thermal protect first before
+reconfiguring.
+2. Separate setting thermal_protect and setting thermal_tx_duty into
+different functions. These two firmware commands do not need to send
+together.
+
+Fixes: 34b877d972be ("mt76: mt7915: add thermal cooling device support")
+Reviewed-by: Ryder Lee <ryder.lee@mediatek.com>
+Signed-off-by: Howard Hsu <howard-yh.hsu@mediatek.com>
+---
+ mt7915/init.c | 3 ---
+ mt7915/main.c | 5 +++++
+ mt7915/mcu.c | 54 ++++++++++++++++++++++++++++---------------------
+ mt7915/mt7915.h | 1 +
+ 4 files changed, 37 insertions(+), 26 deletions(-)
+
+diff --git a/mt7915/init.c b/mt7915/init.c
+index a03d0b3b..df3a35d5 100644
+--- a/mt7915/init.c
++++ b/mt7915/init.c
+@@ -134,9 +134,6 @@ mt7915_thermal_set_cur_throttle_state(struct thermal_cooling_device *cdev,
+ if (state > MT7915_CDEV_THROTTLE_MAX)
+ return -EINVAL;
+
+- if (phy->throttle_temp[0] > phy->throttle_temp[1])
+- return 0;
+-
+ if (state == phy->cdev_state)
+ return 0;
+
+diff --git a/mt7915/main.c b/mt7915/main.c
+index 98af032e..7589af4b 100644
+--- a/mt7915/main.c
++++ b/mt7915/main.c
+@@ -60,6 +60,11 @@ int mt7915_run(struct ieee80211_hw *hw)
+ ret = mt7915_mcu_set_thermal_throttling(phy,
+ MT7915_THERMAL_THROTTLE_MAX);
+
++ if (ret)
++ goto out;
++
++ ret = mt7915_mcu_set_thermal_protect(phy);
++
+ if (ret)
+ goto out;
+
+diff --git a/mt7915/mcu.c b/mt7915/mcu.c
+index 35441dcb..7c14a189 100644
+--- a/mt7915/mcu.c
++++ b/mt7915/mcu.c
+@@ -3077,6 +3077,29 @@ int mt7915_mcu_get_temperature(struct mt7915_phy *phy)
+ }
+
+ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state)
++{
++ struct mt7915_dev *dev = phy->dev;
++ struct mt7915_mcu_thermal_ctrl req = {
++ .band_idx = phy->mt76->band_idx,
++ .ctrl_id = THERMAL_PROTECT_DUTY_CONFIG,
++ };
++ int level, ret;
++
++ /* set duty cycle and level */
++ for (level = 0; level < 4; level++) {
++ req.duty.duty_level = level;
++ req.duty.duty_cycle = state;
++ state /= 2;
++
++ ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT),
++ &req, sizeof(req), false);
++ if (ret)
++ return ret;
++ }
++ return 0;
++}
++
++int mt7915_mcu_set_thermal_protect(struct mt7915_phy *phy)
+ {
+ struct mt7915_dev *dev = phy->dev;
+ struct {
+@@ -3089,29 +3112,18 @@ 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;
+-
+- if (!state) {
+- req.ctrl.ctrl_id = THERMAL_PROTECT_DISABLE;
+- goto out;
+- }
+-
+- /* set duty cycle and level */
+- for (level = 0; level < 4; level++) {
+- int ret;
++ int ret;
+
+- req.ctrl.ctrl_id = THERMAL_PROTECT_DUTY_CONFIG;
+- req.ctrl.duty.duty_level = level;
+- req.ctrl.duty.duty_cycle = state;
+- state /= 2;
++ req.ctrl.ctrl_id = THERMAL_PROTECT_DISABLE;
++ ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT),
++ &req, sizeof(req.ctrl), false);
+
+- ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT),
+- &req, sizeof(req.ctrl), false);
+- if (ret)
+- return ret;
+- }
++ if (ret)
++ return ret;
+
+ /* set high-temperature trigger threshold */
+ req.ctrl.ctrl_id = THERMAL_PROTECT_ENABLE;
+@@ -3120,10 +3132,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;
+-
+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT),
+ &req, sizeof(req), false);
+ }
+diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
+index 6351feba..855779f8 100644
+--- a/mt7915/mt7915.h
++++ b/mt7915/mt7915.h
+@@ -543,6 +543,7 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy);
+ int mt7915_mcu_get_chan_mib_info(struct mt7915_phy *phy, bool chan_switch);
+ int mt7915_mcu_get_temperature(struct mt7915_phy *phy);
+ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state);
++int mt7915_mcu_set_thermal_protect(struct mt7915_phy *phy);
+ int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta, struct rate_info *rate);
+ int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy,
+--
+2.18.0
+