OSDN Git Service

wifi: mt76: mt7915: rework mt7915_mcu_set_thermal_throttling
authorHoward Hsu <howard-yh.hsu@mediatek.com>
Wed, 14 Dec 2022 02:28:07 +0000 (10:28 +0800)
committerFelix Fietkau <nbd@nbd.name>
Fri, 3 Feb 2023 13:47:15 +0000 (14:47 +0100)
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>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7915/init.c
drivers/net/wireless/mediatek/mt76/mt7915/main.c
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h

index 11407e1..be435ae 100644 (file)
@@ -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;
 
index 98af032..7589af4 100644 (file)
@@ -63,6 +63,11 @@ int mt7915_run(struct ieee80211_hw *hw)
        if (ret)
                goto out;
 
+       ret = mt7915_mcu_set_thermal_protect(phy);
+
+       if (ret)
+               goto out;
+
        ret = mt76_connac_mcu_set_rts_thresh(&dev->mt76, 0x92b,
                                             phy->mt76->band_idx);
        if (ret)
index 37a3c1f..04d1da1 100644 (file)
@@ -3079,6 +3079,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 {
                struct mt7915_mcu_thermal_ctrl ctrl;
 
@@ -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);
 }
index 6351feb..855779f 100644 (file)
@@ -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,