diff --git a/bes2600/bes_pwr.c b/bes2600/bes_pwr.c index b7b6c2f..620acef 100644 --- a/bes2600/bes_pwr.c +++ b/bes2600/bes_pwr.c @@ -467,6 +467,45 @@ static void bes2600_pwr_device_enter_lp_mode(struct bes2600_common *hw_priv) bes_devel("device enter sleep\n"); } +/* + * Number of consecutive bes2600_pwr_enter_lp_mode timeouts (with zero + * PM_INDICATIONs received) before we conclude the firmware does not + * honor host-driven PSM and switch to a sticky skip path. + */ +#define BES2600_PM_UNSUPPORTED_THRESHOLD 3 + +/* + * Latch pm_unsupported = true and force chip_pm_state = ACTIVE so the + * c6.2 wake-side skip branch covers bes2600_pwr_device_exit_lp_mode. + * Called after BES2600_PM_UNSUPPORTED_THRESHOLD consecutive enter_lp_mode + * timeouts with zero PM_INDICATIONs. + */ +static void bes2600_pwr_latch_pm_unsupported(struct bes2600_common *hw_priv) +{ + bes_warn("PSM not honored (%u timeouts), switching to skip mode\n", + hw_priv->bes_power.pm_consecutive_timeouts); + hw_priv->bes_power.pm_unsupported = true; + atomic_set(&hw_priv->bes_power.chip_pm_state, + BES2600_CHIP_PM_ACTIVE); + + /* + * Hold the MCU wake-flag bit permanently. Without this, every + * sdio_rx_work invocation hits bes2600_gpio_wakeup_mcu(SDIO_RX) + * when gpio_wakup_flags == 0, drives the GPIO high and msleeps + * 10 ms per RX. With ~50 RX/s of beacons + multicast that's + * ~50%% of the bes_sdio workqueue thread blocked in msleep, + * which directly caps RX throughput. Holding the MCU bit makes + * those calls bit-only bookkeeping (gpio_wakeup = (flags == 0) + * stays false, no GPIO toggle, no msleep). The bit is never + * cleared once pm_unsupported is set because + * bes2600_pwr_device_enter_lp_mode is unreachable under the + * early-return. + */ + if (hw_priv->sbus_ops->gpio_wake) + hw_priv->sbus_ops->gpio_wake(hw_priv->sbus_priv, + GPIO_WAKE_FLAG_MCU); +} + static int bes2600_pwr_enter_lp_mode(struct bes2600_common *hw_priv) { int i = 0; @@ -476,6 +515,17 @@ static int bes2600_pwr_enter_lp_mode(struct bes2600_common *hw_priv) char ip_str[20]; unsigned long status = 0; + /* + * Sticky early-return when we've previously concluded the firmware + * doesn't honor PSM. Each attempt would otherwise burn 5s on a + * doomed wait_for_completion_timeout and produce a noisy three-line + * cascade in dmesg every time power_down_work retries (every + * ~10s). The chip stays in active mode, which on this firmware is + * the de-facto state anyway. + */ + if (hw_priv->bes_power.pm_unsupported) + return -EOPNOTSUPP; + /* set interface low power configuration */ bes2600_for_each_vif(hw_priv, priv, i) { #ifdef P2P_MULTIVIF @@ -571,6 +621,9 @@ static int bes2600_pwr_enter_lp_mode(struct bes2600_common *hw_priv) atomic_set(&hw_priv->bes_power.chip_pm_state, BES2600_CHIP_PM_UNKNOWN); timeouts++; + if (++hw_priv->bes_power.pm_consecutive_timeouts + >= BES2600_PM_UNSUPPORTED_THRESHOLD) + bes2600_pwr_latch_pm_unsupported(hw_priv); } } } else { @@ -609,7 +662,8 @@ static int bes2600_pwr_enter_lp_mode(struct bes2600_common *hw_priv) * GPIO stays high and the bit clear here is purely * bookkeeping (so the next gpio_wake doesn't no-op). */ - if (hw_priv->sbus_ops->gpio_sleep) + if (!hw_priv->bes_power.pm_unsupported && + hw_priv->sbus_ops->gpio_sleep) hw_priv->sbus_ops->gpio_sleep(hw_priv->sbus_priv, GPIO_WAKE_FLAG_MCU); ret = -ETIMEDOUT; @@ -932,6 +986,8 @@ void bes2600_pwr_init(struct bes2600_common *hw_priv) mutex_init(&hw_priv->bes_power.pwr_mutex); atomic_set(&hw_priv->bes_power.dev_state, 0); atomic_set(&hw_priv->bes_power.chip_pm_state, BES2600_CHIP_PM_UNKNOWN); + hw_priv->bes_power.pm_unsupported = false; + hw_priv->bes_power.pm_consecutive_timeouts = 0; init_completion(&hw_priv->bes_power.pm_enter_cmpl); sema_init(&hw_priv->bes_power.sync_lock, 1); device_set_wakeup_capable(hw_priv->pdev, true); @@ -1321,6 +1377,18 @@ void bes2600_pwr_notify_ps_changed(struct bes2600_common *hw_priv, u8 psmode) * indication can prime a future wait against a freshly * reinit_completion()'ed state. */ + /* + * Any PM indication, whatever its psmode, proves the firmware is + * actually emitting them. Reset the consecutive-timeout counter + * so a transient stall doesn't permanently disable PSM, and clear + * pm_unsupported if a previous run had latched it. + */ + hw_priv->bes_power.pm_consecutive_timeouts = 0; + if (hw_priv->bes_power.pm_unsupported) { + bes_warn("PM indication arrived after pm_unsupported was set; re-enabling PSM transitions\n"); + hw_priv->bes_power.pm_unsupported = false; + } + if ((psmode & 0x01) != WSM_PSM_ACTIVE) { atomic_set(&hw_priv->bes_power.chip_pm_state, BES2600_CHIP_PM_LP); diff --git a/bes2600/bes_pwr.h b/bes2600/bes_pwr.h index 6bc44ac..92de90b 100644 --- a/bes2600/bes_pwr.h +++ b/bes2600/bes_pwr.h @@ -121,6 +121,15 @@ struct bes2600_pwr_t struct bes2600_pwr_event_t pwr_events[BES2600_DELAY_EVENT_NUM]; atomic_t pm_set_in_process; atomic_t chip_pm_state; + /* + * Sticky flag set after BES2600_PM_UNSUPPORTED_THRESHOLD + * consecutive enter_lp_mode timeouts with zero PM_INDICATIONs + * received from firmware. Indicates this chip's firmware does + * not honor host-driven PSM transitions; further attempts are + * skipped to avoid the 5s timeout cascade. + */ + bool pm_unsupported; + unsigned int pm_consecutive_timeouts; }; #ifdef CONFIG_BES2600_WOWLAN