int wil_resume(struct wil6210_priv *wil, bool is_runtime, bool keep_radio_on) { int rc = 0; wil_dbg_pm(wil, "resume: %s\n", is_runtime ? "runtime" : "system"); if (wil->platform_ops.resume) { rc = wil->platform_ops.resume(wil->platform_handle, keep_radio_on); if (rc) { wil_err(wil, "platform_ops.resume : %d\n", rc); goto out; } } if (keep_radio_on) rc = wil_resume_keep_radio_on(wil); else rc = wil_resume_radio_off(wil); out: wil_dbg_pm(wil, "resume: %s => %d\n", is_runtime ? "runtime" : "system", rc); return rc; }
static bool wil_can_suspend_vif(struct wil6210_priv *wil, struct wil6210_vif *vif, bool is_runtime) { struct wireless_dev *wdev = vif_to_wdev(vif); switch (wdev->iftype) { case NL80211_IFTYPE_MONITOR: wil_dbg_pm(wil, "Sniffer\n"); return false; /* for STA-like interface, don't runtime suspend */ case NL80211_IFTYPE_STATION: case NL80211_IFTYPE_P2P_CLIENT: if (test_bit(wil_vif_fwconnecting, vif->status)) { wil_dbg_pm(wil, "Delay suspend when connecting\n"); return false; } if (is_runtime) { wil_dbg_pm(wil, "STA-like interface\n"); return false; } break; /* AP-like interface - can't suspend */ default: wil_dbg_pm(wil, "AP-like interface\n"); return false; } return true; }
static int wil_suspend_radio_off(struct wil6210_priv *wil) { int rc = 0; bool active_ifaces; wil_dbg_pm(wil, "suspend radio off\n"); rc = down_write_trylock(&wil->mem_lock); if (!rc) { wil_err(wil, "device is busy. down_write_trylock failed, returned (0x%x)\n", rc); wil->suspend_stats.rejected_by_host++; return -EBUSY; } set_bit(wil_status_suspending, wil->status); up_write(&wil->mem_lock); /* if netif up, hardware is alive, shut it down */ mutex_lock(&wil->vif_mutex); active_ifaces = wil_has_active_ifaces(wil, true, false); mutex_unlock(&wil->vif_mutex); if (active_ifaces) { rc = wil_down(wil); if (rc) { wil_err(wil, "wil_down : %d\n", rc); wil->suspend_stats.r_off.failed_suspends++; goto out; } } /* Disable PCIe IRQ to prevent sporadic IRQs when PCIe is suspending */ wil_dbg_pm(wil, "Disabling PCIe IRQ before suspending\n"); wil_disable_irq(wil); if (wil->platform_ops.suspend) { rc = wil->platform_ops.suspend(wil->platform_handle, false); if (rc) { wil_enable_irq(wil); wil->suspend_stats.r_off.failed_suspends++; goto out; } } set_bit(wil_status_suspended, wil->status); out: clear_bit(wil_status_suspending, wil->status); wil_dbg_pm(wil, "suspend radio off: %d\n", rc); return rc; }
static int wil_suspend_radio_off(struct wil6210_priv *wil) { int rc = 0; bool active_ifaces; wil_dbg_pm(wil, "suspend radio off\n"); set_bit(wil_status_suspending, wil->status); if (test_bit(wil_status_collecting_dumps, wil->status)) { /* Device collects crash dump, cancel the suspend */ wil_dbg_pm(wil, "reject suspend while collecting crash dump\n"); clear_bit(wil_status_suspending, wil->status); wil->suspend_stats.rejected_by_host++; return -EBUSY; } /* if netif up, hardware is alive, shut it down */ mutex_lock(&wil->vif_mutex); active_ifaces = wil_has_active_ifaces(wil, true, false); mutex_unlock(&wil->vif_mutex); if (active_ifaces) { rc = wil_down(wil); if (rc) { wil_err(wil, "wil_down : %d\n", rc); wil->suspend_stats.r_off.failed_suspends++; goto out; } } /* Disable PCIe IRQ to prevent sporadic IRQs when PCIe is suspending */ wil_dbg_pm(wil, "Disabling PCIe IRQ before suspending\n"); wil_disable_irq(wil); if (wil->platform_ops.suspend) { rc = wil->platform_ops.suspend(wil->platform_handle, false); if (rc) { wil_enable_irq(wil); wil->suspend_stats.r_off.failed_suspends++; goto out; } } set_bit(wil_status_suspended, wil->status); out: clear_bit(wil_status_suspending, wil->status); wil_dbg_pm(wil, "suspend radio off: %d\n", rc); return rc; }
static int wil6210_suspend(struct device *dev, bool is_runtime) { int rc = 0; struct pci_dev *pdev = to_pci_dev(dev); struct wil6210_priv *wil = pci_get_drvdata(pdev); wil_dbg_pm(wil, "%s(%s)\n", __func__, is_runtime ? "runtime" : "system"); rc = wil_can_suspend(wil, is_runtime); if (rc) goto out; rc = wil_suspend(wil, is_runtime); if (rc) goto out; /* TODO: how do I bring card in low power state? */ /* disable bus mastering */ pci_clear_master(pdev); /* PCI will call pci_save_state(pdev) and pci_prepare_to_sleep(pdev) */ out: return rc; }
int wil_suspend(struct wil6210_priv *wil, bool is_runtime, bool keep_radio_on) { int rc = 0; wil_dbg_pm(wil, "suspend: %s\n", is_runtime ? "runtime" : "system"); if (test_bit(wil_status_suspended, wil->status)) { wil_dbg_pm(wil, "trying to suspend while suspended\n"); return 0; } if (!keep_radio_on) rc = wil_suspend_radio_off(wil); else rc = wil_suspend_keep_radio_on(wil); wil_dbg_pm(wil, "suspend: %s => %d\n", is_runtime ? "runtime" : "system", rc); return rc; }
static int wil6210_pm_notify(struct notifier_block *notify_block, unsigned long mode, void *unused) { struct wil6210_priv *wil = container_of( notify_block, struct wil6210_priv, pm_notify); int rc = 0; enum wil_platform_event evt; wil_dbg_pm(wil, "%s: mode (%ld)\n", __func__, mode); switch (mode) { case PM_HIBERNATION_PREPARE: case PM_SUSPEND_PREPARE: case PM_RESTORE_PREPARE: rc = wil_can_suspend(wil, false); if (rc) break; evt = WIL_PLATFORM_EVT_PRE_SUSPEND; if (wil->platform_ops.notify) rc = wil->platform_ops.notify(wil->platform_handle, evt); break; case PM_POST_SUSPEND: case PM_POST_HIBERNATION: case PM_POST_RESTORE: evt = WIL_PLATFORM_EVT_POST_SUSPEND; if (wil->platform_ops.notify) rc = wil->platform_ops.notify(wil->platform_handle, evt); break; default: wil_dbg_pm(wil, "unhandled notify mode %ld\n", mode); break; } wil_dbg_pm(wil, "notification mode %ld: rc (%d)\n", mode, rc); return rc; }
static int wil6210_resume(struct device *dev, bool is_runtime) { int rc = 0; struct pci_dev *pdev = to_pci_dev(dev); struct wil6210_priv *wil = pci_get_drvdata(pdev); wil_dbg_pm(wil, "%s(%s)\n", __func__, is_runtime ? "runtime" : "system"); /* allow master */ pci_set_master(pdev); rc = wil_resume(wil, is_runtime); if (rc) pci_clear_master(pdev); return rc; }
static int wil_resume_radio_off(struct wil6210_priv *wil) { int rc = 0; struct net_device *ndev = wil_to_ndev(wil); wil_dbg_pm(wil, "Enabling PCIe IRQ\n"); wil_enable_irq(wil); /* if netif up, bring hardware up * During open(), IFF_UP set after actual device method * invocation. This prevent recursive call to wil_up() * wil_status_suspended will be cleared in wil_reset */ if (ndev->flags & IFF_UP) rc = wil_up(wil); else clear_bit(wil_status_suspended, wil->status); return rc; }
static int wil_resume_radio_off(struct wil6210_priv *wil) { int rc = 0; bool active_ifaces; wil_dbg_pm(wil, "Enabling PCIe IRQ\n"); wil_enable_irq(wil); /* if any netif up, bring hardware up * During open(), IFF_UP set after actual device method * invocation. This prevent recursive call to wil_up() * wil_status_suspended will be cleared in wil_reset */ mutex_lock(&wil->vif_mutex); active_ifaces = wil_has_active_ifaces(wil, true, false); mutex_unlock(&wil->vif_mutex); if (active_ifaces) rc = wil_up(wil); else clear_bit(wil_status_suspended, wil->status); return rc; }
int wil_can_suspend(struct wil6210_priv *wil, bool is_runtime) { int rc = 0, i; bool wmi_only = test_bit(WMI_FW_CAPABILITY_WMI_ONLY, wil->fw_capabilities); bool active_ifaces; wil_dbg_pm(wil, "can_suspend: %s\n", is_runtime ? "runtime" : "system"); if (wmi_only || debug_fw) { wil_dbg_pm(wil, "Deny any suspend - %s mode\n", wmi_only ? "wmi_only" : "debug_fw"); rc = -EBUSY; goto out; } if (is_runtime && !wil->platform_ops.suspend) { rc = -EBUSY; goto out; } mutex_lock(&wil->vif_mutex); active_ifaces = wil_has_active_ifaces(wil, true, false); mutex_unlock(&wil->vif_mutex); if (!active_ifaces) { /* can always sleep when down */ wil_dbg_pm(wil, "Interface is down\n"); goto out; } if (test_bit(wil_status_resetting, wil->status)) { wil_dbg_pm(wil, "Delay suspend when resetting\n"); rc = -EBUSY; goto out; } if (wil->recovery_state != fw_recovery_idle) { wil_dbg_pm(wil, "Delay suspend during recovery\n"); rc = -EBUSY; goto out; } /* interface is running */ mutex_lock(&wil->vif_mutex); for (i = 0; i < GET_MAX_VIFS(wil); i++) { struct wil6210_vif *vif = wil->vifs[i]; if (!vif) continue; if (!wil_can_suspend_vif(wil, vif, is_runtime)) { rc = -EBUSY; mutex_unlock(&wil->vif_mutex); goto out; } } mutex_unlock(&wil->vif_mutex); out: wil_dbg_pm(wil, "can_suspend: %s => %s (%d)\n", is_runtime ? "runtime" : "system", rc ? "No" : "Yes", rc); if (rc) wil->suspend_stats.rejected_by_host++; return rc; }
static int wil_suspend_keep_radio_on(struct wil6210_priv *wil) { int rc = 0; unsigned long data_comp_to; wil_dbg_pm(wil, "suspend keep radio on\n"); /* Prevent handling of new tx and wmi commands */ rc = down_write_trylock(&wil->mem_lock); if (!rc) { wil_err(wil, "device is busy. down_write_trylock failed, returned (0x%x)\n", rc); wil->suspend_stats.rejected_by_host++; return -EBUSY; } set_bit(wil_status_suspending, wil->status); up_write(&wil->mem_lock); wil_pm_stop_all_net_queues(wil); if (!wil_is_tx_idle(wil)) { wil_dbg_pm(wil, "Pending TX data, reject suspend\n"); wil->suspend_stats.rejected_by_host++; goto reject_suspend; } if (!wil->txrx_ops.is_rx_idle(wil)) { wil_dbg_pm(wil, "Pending RX data, reject suspend\n"); wil->suspend_stats.rejected_by_host++; goto reject_suspend; } if (!wil_is_wmi_idle(wil)) { wil_dbg_pm(wil, "Pending WMI events, reject suspend\n"); wil->suspend_stats.rejected_by_host++; goto reject_suspend; } /* Send WMI suspend request to the device */ rc = wmi_suspend(wil); if (rc) { wil_dbg_pm(wil, "wmi_suspend failed, reject suspend (%d)\n", rc); goto reject_suspend; } /* Wait for completion of the pending RX packets */ data_comp_to = jiffies + msecs_to_jiffies(WIL_DATA_COMPLETION_TO_MS); if (test_bit(wil_status_napi_en, wil->status)) { while (!wil->txrx_ops.is_rx_idle(wil)) { if (time_after(jiffies, data_comp_to)) { if (wil->txrx_ops.is_rx_idle(wil)) break; wil_err(wil, "TO waiting for idle RX, suspend failed\n"); wil->suspend_stats.r_on.failed_suspends++; goto resume_after_fail; } wil_dbg_ratelimited(wil, "rx vring is not empty -> NAPI\n"); napi_synchronize(&wil->napi_rx); msleep(20); } } /* In case of pending WMI events, reject the suspend * and resume the device. * This can happen if the device sent the WMI events before * approving the suspend. */ if (!wil_is_wmi_idle(wil)) { wil_err(wil, "suspend failed due to pending WMI events\n"); wil->suspend_stats.r_on.failed_suspends++; goto resume_after_fail; } wil_mask_irq(wil); /* Disable device reset on PERST */ wil_s(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD); if (wil->platform_ops.suspend) { rc = wil->platform_ops.suspend(wil->platform_handle, true); if (rc) { wil_err(wil, "platform device failed to suspend (%d)\n", rc); wil->suspend_stats.r_on.failed_suspends++; wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD); wil_unmask_irq(wil); goto resume_after_fail; } } /* Save the current bus request to return to the same in resume */ wil->bus_request_kbps_pre_suspend = wil->bus_request_kbps; wil6210_bus_request(wil, 0); set_bit(wil_status_suspended, wil->status); clear_bit(wil_status_suspending, wil->status); return rc; resume_after_fail: set_bit(wil_status_resuming, wil->status); clear_bit(wil_status_suspending, wil->status); rc = wmi_resume(wil); /* if resume succeeded, reject the suspend */ if (!rc) { rc = -EBUSY; wil_pm_wake_connected_net_queues(wil); } return rc; reject_suspend: clear_bit(wil_status_suspending, wil->status); wil_pm_wake_connected_net_queues(wil); return -EBUSY; }
int wil_can_suspend(struct wil6210_priv *wil, bool is_runtime) { int rc = 0; struct wireless_dev *wdev = wil->wdev; struct net_device *ndev = wil_to_ndev(wil); bool wmi_only = test_bit(WMI_FW_CAPABILITY_WMI_ONLY, wil->fw_capabilities); wil_dbg_pm(wil, "can_suspend: %s\n", is_runtime ? "runtime" : "system"); if (wmi_only || debug_fw) { wil_dbg_pm(wil, "Deny any suspend - %s mode\n", wmi_only ? "wmi_only" : "debug_fw"); rc = -EBUSY; goto out; } if (is_runtime && !wil->platform_ops.suspend) { rc = -EBUSY; goto out; } if (!(ndev->flags & IFF_UP)) { /* can always sleep when down */ wil_dbg_pm(wil, "Interface is down\n"); goto out; } if (test_bit(wil_status_resetting, wil->status)) { wil_dbg_pm(wil, "Delay suspend when resetting\n"); rc = -EBUSY; goto out; } if (wil->recovery_state != fw_recovery_idle) { wil_dbg_pm(wil, "Delay suspend during recovery\n"); rc = -EBUSY; goto out; } /* interface is running */ switch (wdev->iftype) { case NL80211_IFTYPE_MONITOR: wil_dbg_pm(wil, "Sniffer\n"); rc = -EBUSY; goto out; /* for STA-like interface, don't runtime suspend */ case NL80211_IFTYPE_STATION: case NL80211_IFTYPE_P2P_CLIENT: if (test_bit(wil_status_fwconnecting, wil->status)) { wil_dbg_pm(wil, "Delay suspend when connecting\n"); rc = -EBUSY; goto out; } /* Runtime pm not supported in case the interface is up */ if (is_runtime) { wil_dbg_pm(wil, "STA-like interface\n"); rc = -EBUSY; goto out; } break; /* AP-like interface - can't suspend */ default: wil_dbg_pm(wil, "AP-like interface\n"); rc = -EBUSY; break; } out: wil_dbg_pm(wil, "can_suspend: %s => %s (%d)\n", is_runtime ? "runtime" : "system", rc ? "No" : "Yes", rc); if (rc) wil->suspend_stats.rejected_by_host++; return rc; }