Commit 08523a2a authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: mt7615: add mt7615_pm_wake utility routine

Introduce mt7615_pm_wake utility routine to wake the device from
runtime low-power state (lower-power state is currently supported by
offload firmware for pcie devices).
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent a86f1d01
...@@ -291,6 +291,7 @@ enum { ...@@ -291,6 +291,7 @@ enum {
MT76_STATE_POWER_OFF, MT76_STATE_POWER_OFF,
MT76_STATE_SUSPEND, MT76_STATE_SUSPEND,
MT76_STATE_ROC, MT76_STATE_ROC,
MT76_STATE_PM,
}; };
struct mt76_hw_cap { struct mt76_hw_cap {
......
...@@ -435,6 +435,9 @@ void mt7615_init_device(struct mt7615_dev *dev) ...@@ -435,6 +435,9 @@ void mt7615_init_device(struct mt7615_dev *dev)
dev->phy.dev = dev; dev->phy.dev = dev;
dev->phy.mt76 = &dev->mt76.phy; dev->phy.mt76 = &dev->mt76.phy;
dev->mt76.phy.priv = &dev->phy; dev->mt76.phy.priv = &dev->phy;
INIT_WORK(&dev->pm.wake_work, mt7615_pm_wake_work);
init_completion(&dev->pm.wake_cmpl);
INIT_DELAYED_WORK(&dev->phy.mac_work, mt7615_mac_work); INIT_DELAYED_WORK(&dev->phy.mac_work, mt7615_mac_work);
INIT_DELAYED_WORK(&dev->phy.scan_work, mt7615_scan_work); INIT_DELAYED_WORK(&dev->phy.scan_work, mt7615_scan_work);
skb_queue_head_init(&dev->phy.scan_event_list); skb_queue_head_init(&dev->phy.scan_event_list);
......
...@@ -1808,6 +1808,48 @@ mt7615_mac_update_mib_stats(struct mt7615_phy *phy) ...@@ -1808,6 +1808,48 @@ mt7615_mac_update_mib_stats(struct mt7615_phy *phy)
} }
} }
void mt7615_pm_wake_work(struct work_struct *work)
{
struct mt7615_dev *dev;
struct mt76_phy *mphy;
dev = (struct mt7615_dev *)container_of(work, struct mt7615_dev,
pm.wake_work);
mphy = dev->phy.mt76;
if (mt7615_driver_own(dev))
dev_err(mphy->dev->dev, "failed to wake device\n");
complete_all(&dev->pm.wake_cmpl);
}
int mt7615_pm_wake(struct mt7615_dev *dev)
{
struct mt76_phy *mphy = dev->phy.mt76;
if (!mt7615_firmware_offload(dev))
return 0;
if (!mt76_is_mmio(mphy->dev))
return 0;
if (!test_bit(MT76_STATE_PM, &mphy->state))
return 0;
if (test_bit(MT76_HW_SCANNING, &mphy->state) ||
test_bit(MT76_HW_SCHED_SCANNING, &mphy->state))
return 0;
if (queue_work(dev->mt76.wq, &dev->pm.wake_work))
reinit_completion(&dev->pm.wake_cmpl);
if (!wait_for_completion_timeout(&dev->pm.wake_cmpl, 3 * HZ))
return -ETIMEDOUT;
return 0;
}
EXPORT_SYMBOL_GPL(mt7615_pm_wake);
void mt7615_mac_work(struct work_struct *work) void mt7615_mac_work(struct work_struct *work)
{ {
struct mt7615_phy *phy; struct mt7615_phy *phy;
......
...@@ -74,6 +74,8 @@ static void mt7615_stop(struct ieee80211_hw *hw) ...@@ -74,6 +74,8 @@ static void mt7615_stop(struct ieee80211_hw *hw)
del_timer_sync(&phy->roc_timer); del_timer_sync(&phy->roc_timer);
cancel_work_sync(&phy->roc_work); cancel_work_sync(&phy->roc_work);
cancel_work_sync(&dev->pm.wake_work);
mutex_lock(&dev->mt76.mutex); mutex_lock(&dev->mt76.mutex);
mt76_testmode_reset(&dev->mt76, true); mt76_testmode_reset(&dev->mt76, true);
......
...@@ -1889,28 +1889,36 @@ static void mt7622_trigger_hif_int(struct mt7615_dev *dev, bool en) ...@@ -1889,28 +1889,36 @@ static void mt7622_trigger_hif_int(struct mt7615_dev *dev, bool en)
int mt7615_driver_own(struct mt7615_dev *dev) int mt7615_driver_own(struct mt7615_dev *dev)
{ {
struct mt76_phy *mphy = &dev->mt76.phy;
struct mt76_dev *mdev = &dev->mt76; struct mt76_dev *mdev = &dev->mt76;
int err = 0;
u32 addr; u32 addr;
mt7622_trigger_hif_int(dev, true);
addr = is_mt7663(mdev) ? MT_PCIE_DOORBELL_PUSH : MT_CFG_LPCR_HOST; addr = is_mt7663(mdev) ? MT_PCIE_DOORBELL_PUSH : MT_CFG_LPCR_HOST;
mt76_wr(dev, addr, MT_CFG_LPCR_HOST_DRV_OWN); mt76_wr(dev, addr, MT_CFG_LPCR_HOST_DRV_OWN);
mt7622_trigger_hif_int(dev, true);
addr = is_mt7663(mdev) ? MT_CONN_HIF_ON_LPCTL : MT_CFG_LPCR_HOST; addr = is_mt7663(mdev) ? MT_CONN_HIF_ON_LPCTL : MT_CFG_LPCR_HOST;
if (!mt76_poll_msec(dev, addr, MT_CFG_LPCR_HOST_FW_OWN, 0, 3000)) { if (!mt76_poll_msec(dev, addr, MT_CFG_LPCR_HOST_FW_OWN, 0, 3000)) {
dev_err(dev->mt76.dev, "Timeout for driver own\n"); dev_err(dev->mt76.dev, "Timeout for driver own\n");
return -EIO; err = -EIO;
goto out;
} }
clear_bit(MT76_STATE_PM, &mphy->state);
out:
mt7622_trigger_hif_int(dev, false); mt7622_trigger_hif_int(dev, false);
return 0; return err;
} }
EXPORT_SYMBOL_GPL(mt7615_driver_own); EXPORT_SYMBOL_GPL(mt7615_driver_own);
int mt7615_firmware_own(struct mt7615_dev *dev) int mt7615_firmware_own(struct mt7615_dev *dev)
{ {
struct mt76_phy *mphy = &dev->mt76.phy;
int err = 0;
u32 addr; u32 addr;
addr = is_mt7663(&dev->mt76) ? MT_CONN_HIF_ON_LPCTL : MT_CFG_LPCR_HOST; addr = is_mt7663(&dev->mt76) ? MT_CONN_HIF_ON_LPCTL : MT_CFG_LPCR_HOST;
...@@ -1922,11 +1930,16 @@ int mt7615_firmware_own(struct mt7615_dev *dev) ...@@ -1922,11 +1930,16 @@ int mt7615_firmware_own(struct mt7615_dev *dev)
!mt76_poll_msec(dev, addr, MT_CFG_LPCR_HOST_FW_OWN, !mt76_poll_msec(dev, addr, MT_CFG_LPCR_HOST_FW_OWN,
MT_CFG_LPCR_HOST_FW_OWN, 300)) { MT_CFG_LPCR_HOST_FW_OWN, 300)) {
dev_err(dev->mt76.dev, "Timeout for firmware own\n"); dev_err(dev->mt76.dev, "Timeout for firmware own\n");
return -EIO; err = -EIO;
goto out;
} }
set_bit(MT76_STATE_PM, &mphy->state);
out:
mt7622_trigger_hif_int(dev, false); mt7622_trigger_hif_int(dev, false);
return 0; return err;
} }
EXPORT_SYMBOL_GPL(mt7615_firmware_own); EXPORT_SYMBOL_GPL(mt7615_firmware_own);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#ifndef __MT7615_H #ifndef __MT7615_H
#define __MT7615_H #define __MT7615_H
#include <linux/completion.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/ktime.h> #include <linux/ktime.h>
#include <linux/regmap.h> #include <linux/regmap.h>
...@@ -296,6 +297,11 @@ struct mt7615_dev { ...@@ -296,6 +297,11 @@ struct mt7615_dev {
s8 last_wb_rssi; s8 last_wb_rssi;
} test; } test;
#endif #endif
struct {
struct work_struct wake_work;
struct completion wake_cmpl;
} pm;
}; };
enum tx_pkt_queue_idx { enum tx_pkt_queue_idx {
...@@ -425,6 +431,8 @@ bool mt7615_wait_for_mcu_init(struct mt7615_dev *dev); ...@@ -425,6 +431,8 @@ bool mt7615_wait_for_mcu_init(struct mt7615_dev *dev);
void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta, void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta,
struct ieee80211_tx_rate *probe_rate, struct ieee80211_tx_rate *probe_rate,
struct ieee80211_tx_rate *rates); struct ieee80211_tx_rate *rates);
void mt7615_pm_wake_work(struct work_struct *work);
int mt7615_pm_wake(struct mt7615_dev *dev);
int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev); int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev);
int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd); int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd);
int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue, int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment