Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp3130087lkv; Mon, 10 May 2021 08:19:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyu7hpIrp03jMSJTBwY8D+uJQhi5nUPy45gTqeXZsacGlNtc+Y0Ko6WAsFycqrd9LzQ3EFL X-Received: by 2002:a17:906:3949:: with SMTP id g9mr26555069eje.7.1620659984582; Mon, 10 May 2021 08:19:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620659984; cv=none; d=google.com; s=arc-20160816; b=Ch+WoTRY95xCSQwvaM8RAujvK2ZbimyLOOZiePNg4o2gwfvSsBZjtNS2jBtvzJufIr 2bVy7HgYhjNsx9oZjwHSIZYfieoXgR0ZqJZ7YN+aZ5340rSbTbEWGxsi+2lzCTtC6i5h TBlbpUhrtVHO6e2Fqdnxw7fzMzmxhdGXFmvy4NdfrHTxScssL+ttjyn1XVUtpAklNg8G FwKEkMdNTMWmxA6sUts7rbpscOtIh4uuq6OyrShwHy21vqBizzQNZprue79efmw5xLpl s8NFG23S6KjA0Eik7y5s15b9bxFjT06UEAZ7WFILzyy+UvKzzMRqxUdobc5xqpVpHnN/ 4w+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Sc73Q9mXiKzJZVu07rQs/sHwgUFbKRPzyAgQVkkgC/w=; b=u1a+iN7MLJOXHrjrvFoV4DAwJWQscCwErTkLCB+CbYUp+5JRVxHxDi/YDDK4NXlKiv OheWTZWlxz07xsXPLbx5FgCobORncqBnBL14WK9Sa1lGQk+SLdoAbTY+aH8FtbvJk5NR mHAA5XbsWa7ATSKvLxuFAwipzFfhCpRBUUdMpzu6OkgVJ3pPJhldeOUjnjr9GOy5EOW3 XJoLNxDFphjzkhFcmEjg9xU84Shd8B4y4zkaf7yx/BwrqiLDRmM4EGadfJ5jGkFqc0WS y46o/yOdiNbE+lAbKOC3Fp1CE1aiEw+b8Q4j66SI95SgUZNTh4CZAVQnwKxk71imzHnS EZmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j14si15118509ejs.333.2021.05.10.08.19.21; Mon, 10 May 2021 08:19:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232605AbhEJPUN (ORCPT + 99 others); Mon, 10 May 2021 11:20:13 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:58495 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S234302AbhEJPSu (ORCPT ); Mon, 10 May 2021 11:18:50 -0400 X-UUID: 4089e40365ae45598466a19bc2a598f5-20210510 X-UUID: 4089e40365ae45598466a19bc2a598f5-20210510 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1153437198; Mon, 10 May 2021 23:15:00 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 10 May 2021 23:14:58 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 10 May 2021 23:14:58 +0800 From: To: , CC: , , , , , , , , , , , , , , , Subject: [PATCH 4/9] mt76: mt7921: enable deep sleep at runtime Date: Mon, 10 May 2021 23:14:52 +0800 Message-ID: <1620659697-12048-4-git-send-email-sean.wang@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1620659697-12048-1-git-send-email-sean.wang@mediatek.com> References: <1620659697-12048-1-git-send-email-sean.wang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Sean Wang 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 Signed-off-by: Sean Wang --- .../wireless/mediatek/mt76/mt76_connac_mcu.c | 20 +++++++++++++ .../wireless/mediatek/mt76/mt76_connac_mcu.h | 3 ++ .../net/wireless/mediatek/mt76/mt7921/init.c | 6 +++- .../net/wireless/mediatek/mt76/mt7921/main.c | 28 +++++++++++++++++-- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c index 7b8f8e6f431d..542d7d9f1f52 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c @@ -1596,6 +1596,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) { diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h index 01fc9f2c2f4a..3ed2fb5e1389 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h @@ -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, diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/init.c b/drivers/net/wireless/mediatek/mt76/mt7921/init.c index 6947d98287c0..cd68721314fa 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/init.c @@ -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) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c index 39b3e769925e..5dbccbefe047 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c @@ -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) @@ -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, -- 2.25.1