Skip to content

Commit

Permalink
mt76: mt7921: enable deep sleep at runtime
Browse files Browse the repository at this point in the history
Enable the deep sleep mode with that firmware is able to trap into
the doze state at runtime to reduce the power consumption further.

The deep sleep mode is not allowed in the STA state transition with
the firmware to have the fast connection experience as we've done in
the full power mode

Reviewed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
  • Loading branch information
moore-bros authored and nbd168 committed May 13, 2021
1 parent 8ab8c77 commit a747b0b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
20 changes: 20 additions & 0 deletions mt76_connac_mcu.c
Expand Up @@ -1598,6 +1598,26 @@ int mt76_connac_mcu_set_deep_sleep(struct mt76_dev *dev, bool enable)
}
EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_deep_sleep);

int mt76_connac_sta_state_dp(struct mt76_dev *dev,
enum ieee80211_sta_state old_state,
enum ieee80211_sta_state new_state)
{
if ((old_state == IEEE80211_STA_ASSOC &&
new_state == IEEE80211_STA_AUTHORIZED) ||
(old_state == IEEE80211_STA_NONE &&
new_state == IEEE80211_STA_NOTEXIST))
mt76_connac_mcu_set_deep_sleep(dev, true);

if ((old_state == IEEE80211_STA_NOTEXIST &&
new_state == IEEE80211_STA_NONE) ||
(old_state == IEEE80211_STA_AUTHORIZED &&
new_state == IEEE80211_STA_ASSOC))
mt76_connac_mcu_set_deep_sleep(dev, false);

return 0;
}
EXPORT_SYMBOL_GPL(mt76_connac_sta_state_dp);

void mt76_connac_mcu_coredump_event(struct mt76_dev *dev, struct sk_buff *skb,
struct mt76_connac_coredump *coredump)
{
Expand Down
3 changes: 3 additions & 0 deletions mt76_connac_mcu.h
Expand Up @@ -1032,6 +1032,9 @@ int mt76_connac_mcu_update_gtk_rekey(struct ieee80211_hw *hw,
int mt76_connac_mcu_set_hif_suspend(struct mt76_dev *dev, bool suspend);
void mt76_connac_mcu_set_suspend_iter(void *priv, u8 *mac,
struct ieee80211_vif *vif);
int mt76_connac_sta_state_dp(struct mt76_dev *dev,
enum ieee80211_sta_state old_state,
enum ieee80211_sta_state new_state);
int mt76_connac_mcu_chip_config(struct mt76_dev *dev);
int mt76_connac_mcu_set_deep_sleep(struct mt76_dev *dev, bool enable);
void mt76_connac_mcu_coredump_event(struct mt76_dev *dev, struct sk_buff *skb,
Expand Down
6 changes: 5 additions & 1 deletion mt7921/init.c
Expand Up @@ -250,7 +250,11 @@ int mt7921_register_device(struct mt7921_dev *dev)
if (ret)
return ret;

return mt7921_init_debugfs(dev);
ret = mt7921_init_debugfs(dev);
if (ret)
return ret;

return mt76_connac_mcu_set_deep_sleep(&dev->mt76, dev->pm.enable);
}

void mt7921_unregister_device(struct mt7921_dev *dev)
Expand Down
28 changes: 26 additions & 2 deletions mt7921/main.c
Expand Up @@ -848,6 +848,31 @@ mt7921_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
IEEE80211_STA_NOTEXIST);
}

static int mt7921_sta_state(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
enum ieee80211_sta_state old_state,
enum ieee80211_sta_state new_state)
{
struct mt7921_dev *dev = mt7921_hw_dev(hw);

if (dev->pm.enable) {
mt7921_mutex_acquire(dev);
mt76_connac_sta_state_dp(&dev->mt76, old_state, new_state);
mt7921_mutex_release(dev);
}

if (old_state == IEEE80211_STA_AUTH &&
new_state == IEEE80211_STA_ASSOC) {
return mt7921_sta_add(hw, vif, sta);
} else if (old_state == IEEE80211_STA_ASSOC &&
new_state == IEEE80211_STA_AUTH) {
return mt7921_sta_remove(hw, vif, sta);
}

return 0;
}

static int
mt7921_get_stats(struct ieee80211_hw *hw,
struct ieee80211_low_level_stats *stats)
Expand Down Expand Up @@ -1191,8 +1216,7 @@ const struct ieee80211_ops mt7921_ops = {
.conf_tx = mt7921_conf_tx,
.configure_filter = mt7921_configure_filter,
.bss_info_changed = mt7921_bss_info_changed,
.sta_add = mt7921_sta_add,
.sta_remove = mt7921_sta_remove,
.sta_state = mt7921_sta_state,
.sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
.set_key = mt7921_set_key,
.sta_set_decap_offload = mt7921_sta_set_decap_offload,
Expand Down

0 comments on commit a747b0b

Please sign in to comment.