2 * Copyright (c) 2014,2016 Qualcomm Atheros, Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 int wil_can_suspend(struct wil6210_priv *wil, bool is_runtime)
22 struct wireless_dev *wdev = wil->wdev;
24 wil_dbg_pm(wil, "%s(%s)\n", __func__,
25 is_runtime ? "runtime" : "system");
27 if (!netif_running(wil_to_ndev(wil))) {
28 /* can always sleep when down */
29 wil_dbg_pm(wil, "Interface is down\n");
32 if (test_bit(wil_status_resetting, wil->status)) {
33 wil_dbg_pm(wil, "Delay suspend when resetting\n");
37 if (wil->recovery_state != fw_recovery_idle) {
38 wil_dbg_pm(wil, "Delay suspend during recovery\n");
43 /* interface is running */
44 switch (wdev->iftype) {
45 case NL80211_IFTYPE_MONITOR:
46 case NL80211_IFTYPE_STATION:
47 case NL80211_IFTYPE_P2P_CLIENT:
48 if (test_bit(wil_status_fwconnecting, wil->status)) {
49 wil_dbg_pm(wil, "Delay suspend when connecting\n");
54 /* AP-like interface - can't suspend */
56 wil_dbg_pm(wil, "AP-like interface\n");
62 wil_dbg_pm(wil, "%s(%s) => %s (%d)\n", __func__,
63 is_runtime ? "runtime" : "system", rc ? "No" : "Yes", rc);
68 int wil_suspend(struct wil6210_priv *wil, bool is_runtime)
71 struct net_device *ndev = wil_to_ndev(wil);
73 wil_dbg_pm(wil, "%s(%s)\n", __func__,
74 is_runtime ? "runtime" : "system");
76 /* if netif up, hardware is alive, shut it down */
77 if (ndev->flags & IFF_UP) {
80 wil_err(wil, "wil_down : %d\n", rc);
85 if (wil->platform_ops.suspend)
86 rc = wil->platform_ops.suspend(wil->platform_handle);
89 wil_dbg_pm(wil, "%s(%s) => %d\n", __func__,
90 is_runtime ? "runtime" : "system", rc);
94 int wil_resume(struct wil6210_priv *wil, bool is_runtime)
97 struct net_device *ndev = wil_to_ndev(wil);
99 wil_dbg_pm(wil, "%s(%s)\n", __func__,
100 is_runtime ? "runtime" : "system");
102 if (wil->platform_ops.resume) {
103 rc = wil->platform_ops.resume(wil->platform_handle);
105 wil_err(wil, "platform_ops.resume : %d\n", rc);
110 /* if netif up, bring hardware up
111 * During open(), IFF_UP set after actual device method
112 * invocation. This prevent recursive call to wil_up()
114 if (ndev->flags & IFF_UP)
118 wil_dbg_pm(wil, "%s(%s) => %d\n", __func__,
119 is_runtime ? "runtime" : "system", rc);