| 1 | #include <net/mac80211.h> |
| 2 | #include <net/rtnetlink.h> |
| 3 | |
| 4 | #include "ieee80211_i.h" |
| 5 | #include "mesh.h" |
| 6 | #include "driver-ops.h" |
| 7 | #include "led.h" |
| 8 | |
| 9 | int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) |
| 10 | { |
| 11 | struct ieee80211_local *local = hw_to_local(hw); |
| 12 | struct ieee80211_sub_if_data *sdata; |
| 13 | struct sta_info *sta; |
| 14 | |
| 15 | if (!local->open_count) |
| 16 | goto suspend; |
| 17 | |
| 18 | ieee80211_scan_cancel(local); |
| 19 | |
| 20 | ieee80211_dfs_cac_cancel(local); |
| 21 | |
| 22 | ieee80211_roc_purge(local, NULL); |
| 23 | |
| 24 | ieee80211_del_virtual_monitor(local); |
| 25 | |
| 26 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { |
| 27 | mutex_lock(&local->sta_mtx); |
| 28 | list_for_each_entry(sta, &local->sta_list, list) { |
| 29 | set_sta_flag(sta, WLAN_STA_BLOCK_BA); |
| 30 | ieee80211_sta_tear_down_BA_sessions( |
| 31 | sta, AGG_STOP_LOCAL_REQUEST); |
| 32 | } |
| 33 | mutex_unlock(&local->sta_mtx); |
| 34 | } |
| 35 | |
| 36 | ieee80211_stop_queues_by_reason(hw, |
| 37 | IEEE80211_MAX_QUEUE_MAP, |
| 38 | IEEE80211_QUEUE_STOP_REASON_SUSPEND); |
| 39 | |
| 40 | /* flush out all packets */ |
| 41 | synchronize_net(); |
| 42 | |
| 43 | ieee80211_flush_queues(local, NULL); |
| 44 | |
| 45 | local->quiescing = true; |
| 46 | /* make quiescing visible to timers everywhere */ |
| 47 | mb(); |
| 48 | |
| 49 | flush_workqueue(local->workqueue); |
| 50 | |
| 51 | /* Don't try to run timers while suspended. */ |
| 52 | del_timer_sync(&local->sta_cleanup); |
| 53 | |
| 54 | /* |
| 55 | * Note that this particular timer doesn't need to be |
| 56 | * restarted at resume. |
| 57 | */ |
| 58 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 59 | del_timer_sync(&local->dynamic_ps_timer); |
| 60 | |
| 61 | local->wowlan = wowlan && local->open_count; |
| 62 | if (local->wowlan) { |
| 63 | int err = drv_suspend(local, wowlan); |
| 64 | if (err < 0) { |
| 65 | local->quiescing = false; |
| 66 | local->wowlan = false; |
| 67 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { |
| 68 | mutex_lock(&local->sta_mtx); |
| 69 | list_for_each_entry(sta, |
| 70 | &local->sta_list, list) { |
| 71 | clear_sta_flag(sta, WLAN_STA_BLOCK_BA); |
| 72 | } |
| 73 | mutex_unlock(&local->sta_mtx); |
| 74 | } |
| 75 | ieee80211_wake_queues_by_reason(hw, |
| 76 | IEEE80211_MAX_QUEUE_MAP, |
| 77 | IEEE80211_QUEUE_STOP_REASON_SUSPEND); |
| 78 | return err; |
| 79 | } else if (err > 0) { |
| 80 | WARN_ON(err != 1); |
| 81 | return err; |
| 82 | } else { |
| 83 | goto suspend; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /* tear down aggregation sessions and remove STAs */ |
| 88 | mutex_lock(&local->sta_mtx); |
| 89 | list_for_each_entry(sta, &local->sta_list, list) { |
| 90 | if (sta->uploaded) { |
| 91 | enum ieee80211_sta_state state; |
| 92 | |
| 93 | state = sta->sta_state; |
| 94 | for (; state > IEEE80211_STA_NOTEXIST; state--) |
| 95 | WARN_ON(drv_sta_state(local, sta->sdata, sta, |
| 96 | state, state - 1)); |
| 97 | } |
| 98 | } |
| 99 | mutex_unlock(&local->sta_mtx); |
| 100 | |
| 101 | /* remove all interfaces that were created in the driver */ |
| 102 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 103 | if (!ieee80211_sdata_running(sdata)) |
| 104 | continue; |
| 105 | switch (sdata->vif.type) { |
| 106 | case NL80211_IFTYPE_AP_VLAN: |
| 107 | case NL80211_IFTYPE_MONITOR: |
| 108 | continue; |
| 109 | case NL80211_IFTYPE_STATION: |
| 110 | ieee80211_mgd_quiesce(sdata); |
| 111 | break; |
| 112 | default: |
| 113 | break; |
| 114 | } |
| 115 | |
| 116 | drv_remove_interface(local, sdata); |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * We disconnected on all interfaces before suspend, all channel |
| 121 | * contexts should be released. |
| 122 | */ |
| 123 | WARN_ON(!list_empty(&local->chanctx_list)); |
| 124 | |
| 125 | /* stop hardware - this must stop RX */ |
| 126 | if (local->open_count) |
| 127 | ieee80211_stop_device(local); |
| 128 | |
| 129 | suspend: |
| 130 | local->suspended = true; |
| 131 | /* need suspended to be visible before quiescing is false */ |
| 132 | barrier(); |
| 133 | local->quiescing = false; |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * __ieee80211_resume() is a static inline which just calls |
| 140 | * ieee80211_reconfig(), which is also needed for hardware |
| 141 | * hang/firmware failure/etc. recovery. |
| 142 | */ |
| 143 | |
| 144 | void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif, |
| 145 | struct cfg80211_wowlan_wakeup *wakeup, |
| 146 | gfp_t gfp) |
| 147 | { |
| 148 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 149 | |
| 150 | cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp); |
| 151 | } |
| 152 | EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup); |