wifi: mt76: mt7925: fix suspend regression
cover wifi: mt76: mt7925: fix suspend regression
Suspend to RAM with the mt7925 running is broken since 6.12.31 due to having ac3af695c4b0 without its dependencies. This brings them in as well.
Jan
Quan Zhou (3):
wifi: mt76: mt7925: fix the unfinished command of regd_notifier before
suspend
wifi: mt76: mt7925: fix CLC command timeout when suspend/resume
wifi: mt76: mt7925: add handler to hif suspend/resume event
.../net/wireless/mediatek/mt76/mt7615/main.c | 4 +- .../net/wireless/mediatek/mt76/mt7615/pci.c | 6 +-- .../net/wireless/mediatek/mt76/mt7615/sdio.c | 4 +- .../net/wireless/mediatek/mt76/mt7615/usb.c | 4 +- .../wireless/mediatek/mt76/mt76_connac_mcu.c | 4 +- .../wireless/mediatek/mt76/mt76_connac_mcu.h | 3 +- .../net/wireless/mediatek/mt76/mt7921/pci.c | 6 +-- .../net/wireless/mediatek/mt76/mt7921/sdio.c | 6 +-- .../net/wireless/mediatek/mt76/mt7921/usb.c | 4 +- .../net/wireless/mediatek/mt76/mt7925/init.c | 24 +++++++-- .../net/wireless/mediatek/mt76/mt7925/mcu.c | 49 ++++++++++++++++++- .../wireless/mediatek/mt76/mt7925/mt7925.h | 21 ++++++++ .../net/wireless/mediatek/mt76/mt7925/pci.c | 33 ++++++++++--- .../net/wireless/mediatek/mt76/mt7925/usb.c | 20 ++++++-- drivers/net/wireless/mediatek/mt76/mt792x.h | 2 + 15 files changed, 154 insertions(+), 36 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/3 wifi: mt76: mt7925: fix the unfinished command of regd_notifier before suspend
From: Quan Zhou <[email protected]>
[ Upstream commit 1b97fc8443aea01922560de9f24a6383e6eb6ae8 ]
Before entering suspend, we need to ensure that all MCU command are completed. In some cases, such as with regd_notifier, there is a chance that CLC commands, will be executed before suspend.
--- drivers/net/wireless/mediatek/mt76/mt7925/init.c | 4 ++++ drivers/net/wireless/mediatek/mt76/mt7925/pci.c | 3 +++ 2 files changed, 7 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7925/init.c +4 -0
@@ -81,11 +81,14 @@ mt7925_regd_notifier(struct wiphy *wiphy, mdev->region = req->dfs_region; dev->country_ie_env = req->country_ie_env; + dev->regd_in_progress = true;mt792x_mutex_acquire (dev);mt7925_mcu_set_clc (dev, req->alpha2, req->country_ie_env);mt7925_mcu_set_channel_domain (hw->priv);mt7925_set_tx_sar_pwr (hw,NULL );mt792x_mutex_release (dev); + dev->regd_in_progress = false; +wake_up (&dev->wait); }static void mt7925_mac_init_basic_rates (struct mt792x_dev *dev)
@@ -235,6 +238,7 @@ int mt7925_register_device(struct mt792x_dev *dev)spin_lock_init (&dev->pm.wake.lock);mutex_init (&dev->pm.mutex);init_waitqueue_head (&dev->pm.wait); +init_waitqueue_head (&dev->wait);spin_lock_init (&dev->pm.txq_lock);INIT_DELAYED_WORK (&dev->mphy.mac_work, mt792x_mac_work);INIT_DELAYED_WORK (&dev->phy.scan_work, mt7925_scan_work);
drivers/net/wireless/mediatek/mt76/mt7925/pci.c +3 -0
@@ -455,6 +455,9 @@ static int mt7925_pci_suspend(struct device *device)if (err <0 ) goto restore_suspend; +wait_event_timeout (dev->wait, + !dev->regd_in_progress,5 *HZ ); +/* always enable deep sleep during suspend to reduce * power consumption */
Signature · 1 line
2.51.0
PATCH 2/3 wifi: mt76: mt7925: fix CLC command timeout when suspend/resume
In reply to Jan KiszkaFrom: Quan Zhou <[email protected]>
[ Upstream commit a0f721b8d986b62b4de316444f2b2e356d17e3b5 ]
When enter suspend/resume while in a connected state, the upper layer will trigger disconnection before entering suspend, and at the same time, it will trigger regd_notifier() and update CLC, causing the CLC event to not be received due to suspend, resulting in a command timeout.
Therefore, the update of CLC is postponed until resume, to ensure data consistency and avoid the occurrence of command timeout.
--- .../net/wireless/mediatek/mt76/mt7925/init.c | 20 ++++++++++++++++--- .../wireless/mediatek/mt76/mt7925/mt7925.h | 1 + .../net/wireless/mediatek/mt76/mt7925/pci.c | 3 +++ 3 files changed, 21 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/init.c +17 -3
@@ -59,6 +59,18 @@ static int mt7925_thermal_init(struct mt792x_phy *phy) mt7925_hwmon_groups);return PTR_ERR_OR_ZERO (hwmon); } + +void mt7925_regd_update (struct mt792x_dev *dev) +{ +struct mt76_dev *mdev = &dev->mt76; +struct ieee80211_hw *hw = mdev->hw; + +mt7925_mcu_set_clc (dev, mdev->alpha2, dev->country_ie_env); +mt7925_mcu_set_channel_domain (hw->priv); +mt7925_set_tx_sar_pwr (hw,NULL ); +} +EXPORT_SYMBOL_GPL (mt7925_regd_update); +static void mt7925_regd_notifier (struct wiphy *wiphy,struct regulatory_request *req)
@@ -66,6 +78,7 @@ mt7925_regd_notifier(struct wiphy *wiphy,struct ieee80211_hw *hw =wiphy_to_ieee80211_hw (wiphy);struct mt792x_dev *dev =mt792x_hw_dev (hw);struct mt76_dev *mdev = &dev->mt76; +struct mt76_connac_pm *pm = &dev->pm;/* allow world regdom at the first boot only */ if (!memcmp(req->alpha2, "00", 2) &&
@@ -81,11 +94,12 @@ mt7925_regd_notifier(struct wiphy *wiphy, mdev->region = req->dfs_region; dev->country_ie_env = req->country_ie_env; +if (pm->suspended) +return ; + dev->regd_in_progress = true;mt792x_mutex_acquire (dev); -mt7925_mcu_set_clc (dev, req->alpha2, req->country_ie_env); -mt7925_mcu_set_channel_domain (hw->priv); -mt7925_set_tx_sar_pwr (hw,NULL ); +mt7925_regd_update (dev);mt792x_mutex_release (dev); dev->regd_in_progress = false;wake_up (&dev->wait);
drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +1 -0
@@ -218,6 +218,7 @@ int mt7925_mcu_chip_config(struct mt792x_dev *dev, const char *cmd);int mt7925_mcu_set_rxfilter (struct mt792x_dev *dev,u32 fif,u8 bit_op,u32 bit_map); +void mt7925_regd_update (struct mt792x_dev *dev);int mt7925_mac_init (struct mt792x_dev *dev);int mt7925_mac_sta_add (struct mt76_dev *mdev,struct ieee80211_vif *vif,struct ieee80211_sta *sta);
drivers/net/wireless/mediatek/mt76/mt7925/pci.c +3 -0
@@ -554,11 +554,14 @@ static int mt7925_pci_resume(struct device *device)local_bh_enable (); err =mt76_connac_mcu_set_hif_suspend (mdev, false); +if (err <0 ) + goto failed;/* restore previous ds setting */ if (!pm->ds_enable)mt7925_mcu_set_deep_sleep (dev, false); +mt7925_regd_update (dev); failed: pm->suspended = false;
Signature · 1 line
2.51.0
PATCH 3/3 wifi: mt76: mt7925: add handler to hif suspend/resume event
In reply to Jan KiszkaFrom: Quan Zhou <[email protected]>
[ Upstream commit 8f6571ad470feb242dcef36e53f7cf1bba03780f ]
When the system suspend or resume, the WiFi driver sends an hif_ctrl command to the firmware and waits for an event. Due to changes in the event format reported by the chip, the current mt7925's driver does not account for these changes, resulting in command timeout. Add flow to handle hif_ctrl event to avoid command timeout. We also exented API mt76_connac_mcu_set_hif_suspend for connac3 this time.
--- .../net/wireless/mediatek/mt76/mt7615/main.c | 4 +- .../net/wireless/mediatek/mt76/mt7615/pci.c | 6 +-- .../net/wireless/mediatek/mt76/mt7615/sdio.c | 4 +- .../net/wireless/mediatek/mt76/mt7615/usb.c | 4 +- .../wireless/mediatek/mt76/mt76_connac_mcu.c | 4 +- .../wireless/mediatek/mt76/mt76_connac_mcu.h | 3 +- .../net/wireless/mediatek/mt76/mt7921/pci.c | 6 +-- .../net/wireless/mediatek/mt76/mt7921/sdio.c | 6 +-- .../net/wireless/mediatek/mt76/mt7921/usb.c | 4 +- .../net/wireless/mediatek/mt76/mt7925/mcu.c | 49 ++++++++++++++++++- .../wireless/mediatek/mt76/mt7925/mt7925.h | 20 ++++++++ .../net/wireless/mediatek/mt76/mt7925/pci.c | 29 ++++++++--- .../net/wireless/mediatek/mt76/mt7925/usb.c | 20 ++++++-- drivers/net/wireless/mediatek/mt76/mt792x.h | 2 + 14 files changed, 127 insertions(+), 34 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/main.c +2 -2
@@ -1249,7 +1249,7 @@ static int mt7615_suspend(struct ieee80211_hw *hw, phy->mt76);if (!mt7615_dev_running (dev)) - err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, true); + err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, true, true);mt7615_mutex_release (dev);
@@ -1271,7 +1271,7 @@ static int mt7615_resume(struct ieee80211_hw *hw)if (!running) {int err; - err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, false); + err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, false, true);if (err <0 ) {mt7615_mutex_release (dev);return err;
drivers/net/wireless/mediatek/mt76/mt7615/pci.c +3 -3
@@ -83,7 +83,7 @@ static int mt7615_pci_suspend(struct pci_dev *pdev, pm_message_t state) hif_suspend = !test_bit (MT76_STATE_SUSPEND , &dev->mphy.state) &&mt7615_firmware_offload (dev);if (hif_suspend) { - err =mt76_connac_mcu_set_hif_suspend (mdev, true); + err =mt76_connac_mcu_set_hif_suspend (mdev, true, true);if (err)return err; }
@@ -131,7 +131,7 @@ static int mt7615_pci_suspend(struct pci_dev *pdev, pm_message_t state) }napi_enable (&mdev->tx_napi);if (hif_suspend) -mt76_connac_mcu_set_hif_suspend (mdev, false); +mt76_connac_mcu_set_hif_suspend (mdev, false, true);return err; }
@@ -175,7 +175,7 @@ static int mt7615_pci_resume(struct pci_dev *pdev)if (!test_bit (MT76_STATE_SUSPEND , &dev->mphy.state) &&mt7615_firmware_offload (dev)) - err =mt76_connac_mcu_set_hif_suspend (mdev, false); + err =mt76_connac_mcu_set_hif_suspend (mdev, false, true);return err; }
drivers/net/wireless/mediatek/mt76/mt7615/sdio.c +2 -2
@@ -191,7 +191,7 @@ static int mt7663s_suspend(struct device *dev) mt7615_firmware_offload(mdev)) {int err; - err =mt76_connac_mcu_set_hif_suspend (&mdev->mt76, true); + err =mt76_connac_mcu_set_hif_suspend (&mdev->mt76, true, true);if (err <0 )return err; }
@@ -230,7 +230,7 @@ static int mt7663s_resume(struct device *dev)if (!test_bit (MT76_STATE_SUSPEND , &mdev->mphy.state) &&mt7615_firmware_offload (mdev)) - err =mt76_connac_mcu_set_hif_suspend (&mdev->mt76, false); + err =mt76_connac_mcu_set_hif_suspend (&mdev->mt76, false, true);return err; }
drivers/net/wireless/mediatek/mt76/mt7615/usb.c +2 -2
@@ -225,7 +225,7 @@ static int mt7663u_suspend(struct usb_interface *intf, pm_message_t state) mt7615_firmware_offload(dev)) {int err; - err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, true); + err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, true, true);if (err <0 )return err; }
@@ -253,7 +253,7 @@ static int mt7663u_resume(struct usb_interface *intf)if (!test_bit (MT76_STATE_SUSPEND , &dev->mphy.state) &&mt7615_firmware_offload (dev)) - err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, false); + err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, false, true);return err; }
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +2 -2
@@ -2527,7 +2527,7 @@ mt76_connac_mcu_set_wow_ctrl(struct mt76_phy *phy, struct ieee80211_vif *vif, }EXPORT_SYMBOL_GPL (mt76_connac_mcu_set_wow_ctrl); -int mt76_connac_mcu_set_hif_suspend (struct mt76_dev *dev,bool suspend) +int mt76_connac_mcu_set_hif_suspend (struct mt76_dev *dev,bool suspend,bool wait_resp) { struct { struct {
@@ -2559,7 +2559,7 @@ int mt76_connac_mcu_set_hif_suspend(struct mt76_dev *dev, bool suspend) req.hdr.hif_type =0 ;return mt76_mcu_send_msg (dev,MCU_UNI_CMD (HIF_CTRL ), &req, -sizeof (req), true); +sizeof (req), wait_resp); }EXPORT_SYMBOL_GPL (mt76_connac_mcu_set_hif_suspend);
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +2 -1
@@ -1049,6 +1049,7 @@ enum {/* unified event table */ enum {MCU_UNI_EVENT_RESULT =0x01 , +MCU_UNI_EVENT_HIF_CTRL =0x03 ,MCU_UNI_EVENT_FW_LOG_2_HOST =0x04 ,MCU_UNI_EVENT_ACCESS_REG =0x6 ,MCU_UNI_EVENT_IE_COUNTDOWN =0x09 ,
@@ -1989,7 +1990,7 @@ int mt76_connac_mcu_set_suspend_mode(struct mt76_dev *dev,struct ieee80211_vif *vif, bool enable, u8 mdtim, bool wow_suspend); -int mt76_connac_mcu_set_hif_suspend (struct mt76_dev *dev,bool suspend); +int mt76_connac_mcu_set_hif_suspend (struct mt76_dev *dev,bool suspend,bool wait_resp);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,
drivers/net/wireless/mediatek/mt76/mt7921/pci.c +3 -3
@@ -435,7 +435,7 @@ static int mt7921_pci_suspend(struct device *device)if (err <0 ) goto restore_suspend; - err =mt76_connac_mcu_set_hif_suspend (mdev, true); + err =mt76_connac_mcu_set_hif_suspend (mdev, true, true);if (err) goto restore_suspend;
@@ -481,7 +481,7 @@ static int mt7921_pci_suspend(struct device *device)if (!pm->ds_enable)mt76_connac_mcu_set_deep_sleep (&dev->mt76, false); -mt76_connac_mcu_set_hif_suspend (mdev, false); +mt76_connac_mcu_set_hif_suspend (mdev, false, true); restore_suspend: pm->suspended = false;
@@ -532,7 +532,7 @@ static int mt7921_pci_resume(struct device *device)if (!pm->ds_enable)mt76_connac_mcu_set_deep_sleep (&dev->mt76, false); - err =mt76_connac_mcu_set_hif_suspend (mdev, false); + err =mt76_connac_mcu_set_hif_suspend (mdev, false, true);if (err <0 ) goto failed;
drivers/net/wireless/mediatek/mt76/mt7921/sdio.c +3 -3
@@ -240,7 +240,7 @@ static int mt7921s_suspend(struct device *__dev) mt76s_txqs_empty(&dev->mt76), 5 * HZ);/* It is supposed that SDIO bus is idle at the point */ - err =mt76_connac_mcu_set_hif_suspend (mdev, true); + err =mt76_connac_mcu_set_hif_suspend (mdev, true, true);if (err) goto restore_worker;
@@ -258,7 +258,7 @@ static int mt7921s_suspend(struct device *__dev) restore_txrx_worker:mt76_worker_enable (&mdev->sdio.net_worker);mt76_worker_enable (&mdev->sdio.txrx_worker); -mt76_connac_mcu_set_hif_suspend (mdev, false); +mt76_connac_mcu_set_hif_suspend (mdev, false, true); restore_worker:mt76_worker_enable (&mdev->tx_worker);
@@ -302,7 +302,7 @@ static int mt7921s_resume(struct device *__dev)if (!pm->ds_enable)mt76_connac_mcu_set_deep_sleep (mdev, false); - err =mt76_connac_mcu_set_hif_suspend (mdev, false); + err =mt76_connac_mcu_set_hif_suspend (mdev, false, true); failed: pm->suspended = false;
drivers/net/wireless/mediatek/mt76/mt7921/usb.c +2 -2
@@ -263,7 +263,7 @@ static int mt7921u_suspend(struct usb_interface *intf, pm_message_t state) pm->suspended = true;flush_work (&dev->reset_work); - err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, true); + err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, true, true);if (err) goto failed;
@@ -313,7 +313,7 @@ static int mt7921u_resume(struct usb_interface *intf)if (err <0 ) goto failed; - err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, false); + err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, false, true); failed: pm->suspended = false;
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +48 -1
67 lines not on this page · raw message
drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +20 -0
@@ -27,6 +27,26 @@#define MCU_UNI_EVENT_ROC 0x27 +#define HIF_TRAFFIC_IDLE 0x2 + +enum { +UNI_EVENT_HIF_CTRL_BASIC =0 , +UNI_EVENT_HIF_CTRL_TAG_NUM +}; + +struct mt7925_mcu_hif_ctrl_basic_tlv { +__le16 tag; +__le16 len; +u8 cid; +u8 pad[3 ]; +u32 status; +u8 hif_type; +u8 hif_tx_traffic_status; +u8 hif_rx_traffic_status; +u8 hifsuspend; +u8 rsv[4 ]; +} __packed; +enum {UNI_ROC_ACQUIRE ,UNI_ROC_ABORT ,
drivers/net/wireless/mediatek/mt76/mt7925/pci.c +21 -8
@@ -442,9 +442,10 @@ static int mt7925_pci_suspend(struct device *device)struct mt76_dev *mdev =pci_get_drvdata (pdev); struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);struct mt76_connac_pm *pm = &dev->pm; -int i, err; +int i, err, ret; pm->suspended = true; + dev->hif_resumed = false;flush_work (&dev->reset_work);cancel_delayed_work_sync (&pm->ps_work);cancel_work_sync (&pm->wake_work);
@@ -463,9 +464,13 @@ static int mt7925_pci_suspend(struct device *device)*/ mt7925_mcu_set_deep_sleep (dev, true); - err =mt76_connac_mcu_set_hif_suspend (mdev, true); -if (err) +mt76_connac_mcu_set_hif_suspend (mdev, true, false); + ret =wait_event_timeout (dev->wait, + dev->hif_idle,3 *HZ ); +if (!ret) { + err = -ETIMEDOUT ; goto restore_suspend; + }napi_disable (&mdev->tx_napi);mt76_worker_disable (&mdev->tx_worker);
@@ -506,8 +511,11 @@ static int mt7925_pci_suspend(struct device *device)if (!pm->ds_enable)mt7925_mcu_set_deep_sleep (dev, false); -mt76_connac_mcu_set_hif_suspend (mdev, false); - +mt76_connac_mcu_set_hif_suspend (mdev, false, false); + ret =wait_event_timeout (dev->wait, + dev->hif_resumed,3 *HZ ); +if (!ret) + err = -ETIMEDOUT ; restore_suspend: pm->suspended = false;
@@ -523,8 +531,9 @@ static int mt7925_pci_resume(struct device *device)struct mt76_dev *mdev =pci_get_drvdata (pdev); struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);struct mt76_connac_pm *pm = &dev->pm; -int i, err; +int i, err, ret; + dev->hif_idle = false; err =mt792x_mcu_drv_pmctrl (dev);if (err <0 ) goto failed;
@@ -553,9 +562,13 @@ static int mt7925_pci_resume(struct device *device)napi_schedule (&mdev->tx_napi);local_bh_enable (); - err =mt76_connac_mcu_set_hif_suspend (mdev, false); -if (err <0 ) +mt76_connac_mcu_set_hif_suspend (mdev, false, false); + ret =wait_event_timeout (dev->wait, + dev->hif_resumed,3 *HZ ); +if (!ret) { + err = -ETIMEDOUT ; goto failed; + }/* restore previous ds setting */ if (!pm->ds_enable)
drivers/net/wireless/mediatek/mt76/mt7925/usb.c +15 -5
@@ -246,14 +246,19 @@ static int mt7925u_suspend(struct usb_interface *intf, pm_message_t state) {struct mt792x_dev *dev =usb_get_intfdata (intf);struct mt76_connac_pm *pm = &dev->pm; -int err; +int err, ret; pm->suspended = true; + dev->hif_resumed = false;flush_work (&dev->reset_work); - err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, true); -if (err) +mt76_connac_mcu_set_hif_suspend (&dev->mt76, true, false); + ret =wait_event_timeout (dev->wait, + dev->hif_idle,3 *HZ ); +if (!ret) { + err = -ETIMEDOUT ; goto failed; + }mt76u_stop_rx (&dev->mt76);mt76u_stop_tx (&dev->mt76);
@@ -274,8 +279,9 @@ static int mt7925u_resume(struct usb_interface *intf)struct mt792x_dev *dev =usb_get_intfdata (intf);struct mt76_connac_pm *pm = &dev->pm;bool reinit = true; -int err, i; +int err, i, ret; + dev->hif_idle = false;for (i =0 ; i <10 ; i++) {u32 val =mt76_rr (dev,MT_WF_SW_DEF_CR_USB_MCU_EVENT );
@@ -301,7 +307,11 @@ static int mt7925u_resume(struct usb_interface *intf)if (err <0 ) goto failed; - err =mt76_connac_mcu_set_hif_suspend (&dev->mt76, false); +mt76_connac_mcu_set_hif_suspend (&dev->mt76, false, false); + ret =wait_event_timeout (dev->wait, + dev->hif_resumed,3 *HZ ); +if (!ret) + err = -ETIMEDOUT ; failed: pm->suspended = false;
drivers/net/wireless/mediatek/mt76/mt792x.h +2 -0
@@ -216,6 +216,8 @@ struct mt792x_dev { bool has_eht:1; bool regd_in_progress:1; bool aspm_supported:1; + bool hif_idle:1; + bool hif_resumed:1;wait_queue_head_t wait;struct work_struct init_work;
Signature · 1 line
2.51.0