mac80211: add suspend/resume callbacks
PATCH 1/2 mac80211: add suspend/resume callbacks
This patch introduces suspend and resume callbacks to mac80211, allowing mac80211 to quiesce its state (bringing down interfaces, removing keys, etc) in preparation for suspend. The driver is responsible for calling ieee80211_notify_mac with the appropriate option from its suspend/resume hook.
--- include/net/mac80211.h | 41 +++++++++++++++++ net/mac80211/Makefile | 2 + net/mac80211/pm.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 0 deletions(-) create mode 100644 net/mac80211/pm.c
include/net/mac80211.h +41 -0
@@ -1873,6 +1873,47 @@ void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, const u8 *ra,struct ieee80211_sta *ieee80211_find_sta (struct ieee80211_hw *hw,const u8 *addr); +#ifdef CONFIG_PM +void __ieee80211_suspend (struct ieee80211_hw *); +void __ieee80211_resume (struct ieee80211_hw *); +#endif +/** +* ieee80211_suspend - prepare for platform suspend +* +* Call this function from the low level driver from the bus suspend +* function to prepare for suspend to ram or disk. The function will +* quiesce active interfaces and save state for resume. +* +* This function must not be called with any locks held as it may +* call back into the driver. +* +* @hw: pointer as obtained from ieee80211_alloc_hw() +*/ +static inline void ieee80211_suspend (struct ieee80211_hw *hw) +{ +#ifdef CONFIG_PM +__ieee80211_suspend (hw); +#endif +} + +/** +* ieee80211_resume - resume operation from sleep +* +* Call this function from the low level driver from the bus resume +* function to resume from ram or disk. This will reactivate interfaces +* and reprogram the hardware to continue normal operation. +* +* This function must not be called with any locks held as it may +* call back into the driver. +* +* @hw: pointer as obtained from ieee80211_alloc_hw() +*/ +static inline void ieee80211_resume (struct ieee80211_hw *hw) +{ +#ifdef CONFIG_PM +__ieee80211_resume (hw); +#endif +}/* Rate control API */
net/mac80211/Makefile +2 -0
@@ -37,6 +37,8 @@ mac80211-$(CONFIG_MAC80211_MESH) += \ mesh_plink.o \ mesh_hwmp.o +mac80211-$(CONFIG_PM) += pm.o + # objects for PID algorithm rc80211_pid-y := rc80211_pid_algo.o rc80211_pid-$(CONFIG_MAC80211_DEBUGFS) += rc80211_pid_debugfs.o
net/mac80211/pm.c new file +116 -0
116 lines not on this page · raw message
Signature · 1 line
1.5.4.2.182.gb3092
Johannes Berg
maintainerQuoted 5 lines · Bob Copeland
This patch introduces suspend and resume callbacks to mac80211, allowing mac80211 to quiesce its state (bringing down interfaces, removing keys, etc) in preparation for suspend. The driver is responsible for calling
ieee80211_notify_macwith the appropriate option from its suspend/resume hook.
Thanks! Looks pretty good already, a few comments:
Quoted 4 lines
net/mac80211/pm.c new file +4
-0+void __ieee80211_suspend (struct ieee80211_hw *hw) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct ieee80211_sub_if_data *sdata;
net/mac80211/pm.c line 20
Quoted 10 lines
net/mac80211/pm.c new file +10
-0+struct ieee80211_if_init_conf conf; +struct sta_info *sta; + +printk (KERN_DEBUG "mac80211: suspending\n" ); + +rtnl_lock (); + +flush_workqueue (local->hw.workqueue); + +/* disable aggregation and notify that STAs are going away */
I think this should run through interfaces twice, in the first run to remove keys, then remove stas and then in the second run remove the interfaces, because otherwise you may be having keys left when the sta for which the key was has been removed.
net/mac80211/pm.c line 38
Quoted 3 lines
net/mac80211/pm.c new file +3
-0+/* remove all interfaces */ +list_for_each_entry (sdata, &local->interfaces, list) { +ieee80211_disable_keys (sdata);
This needs to take care that the interface is actually up and not a monitor/ap-vlan interface (those we don't tell the driver about)
net/mac80211/pm.c line 82
Quoted 9 lines
net/mac80211/pm.c new file +9
-0+/* add interfaces */ +list_for_each_entry (sdata, &local->interfaces, list) { + + conf.vif = &sdata->vif; + conf.type = sdata->vif.type; + conf.mac_addr = sdata->dev->dev_addr; + res = local->ops->add_interface (hw, &conf); + +ieee80211_enable_keys (sdata);
Similarly here, make sure the interface is actually up and re-enable the keys only after adding the stas back.
net/mac80211/pm.c line 107
Quoted 7 lines
net/mac80211/pm.c new file +7
-0+/* setup RTS and frag thresholds */ +if (local->ops->set_rts_threshold) + local->ops->set_rts_threshold (hw, local->rts_threshold); + +if (local->ops->set_frag_threshold) + local->ops->set_frag_threshold (hw, + local->fragmentation_threshold);
Heh, I didn't even think of those.
What were you thinking of when you said something is missing? I can't think of anything right now. And what warnings do you get?
Resume definitely needs to defer to schedule_work(), I think, but that's a trivial change.
johannes
On Sun, Nov 23, 2008 at 10:19:13AM +0100, Johannes Berg wrote:
Great, thanks for the feedback!
Quoted 6 lines
net/mac80211/pm.c line 20
Quoted 1 line
net/mac80211/pm.c new file +1
-0+/* disable aggregation and notify that STAs are going away */ I think this should run through interfaces twice, in the first run to remove keys, then remove stas and then in the second run remove the interfaces, because otherwise you may be having keys left when the sta for which the key was has been removed.
Ok, that makes sense.
Quoted 9 lines
net/mac80211/pm.c line 107
Quoted 7 lines
net/mac80211/pm.c new file +7
-0+/* setup RTS and frag thresholds */ +if (local->ops->set_rts_threshold) + local->ops->set_rts_threshold (hw, local->rts_threshold); + +if (local->ops->set_frag_threshold) + local->ops->set_frag_threshold (hw, + local->fragmentation_threshold);Heh, I didn't even think of those.
They were in your original email on the website. I'm not making up too much, yet :)
Quoted 2 lines
What were you thinking of when you said something is missing? I can't think of anything right now. And what warnings do you get?
conf_tx was the last callback from your email that I hadn't yet worked in.
Predictably, I got the netif_running() warning on ieee80211_enable_keys, so hopefully the reordering and checking first will take care of that.
Quoted 2 lines
Resume definitely needs to defer to
schedule_work(), I think, but that's a trivial change.
Yeah that shouldn't be a problem.
Signature · 1 line
Bob Copeland %% www.bobcopeland.com
On Sun, 23 Nov 2008 10:19:13 +0100, Johannes Berg wrote
Quoted 4 lines
I think this should run through interfaces twice, in the first run to remove keys, then remove stas and then in the second run remove the interfaces, because otherwise you may be having keys left when the sta for which the key was has been removed.
Is this what you had in mind? (now on top of your cfg80211 patch, btw it called ->suspend() in the resume hook)
I tested this with ath5k, it works in the sense that device suspends and resumes without any hangs or errors.
However, netif_running(sdata->dev) seems to randomly be false for wlan0 on the resume side so the interface doesn't always come up. I haven't had time to track that down but it's not consistent.
Quoted 1 line
From
ec2f9fb1db1f98caf28e90f9838a42f0508a3a80Mon Sep 17 00:00:00 2001
From: Bob Copeland <[email protected]>
Date: Mon, 27 Oct 2008 09:17:46 -0400
Subject: [PATCH] mac80211: add suspend/resume callbacks
This patch introduces suspend and resume callbacks to mac80211, allowing mac80211 to quiesce its state (bringing down interfaces, removing keys, etc) in preparation for suspend. cfg80211 will call the suspend hook before the device suspend, and resume hook after the device resume.
--- net/mac80211/Makefile | 2 + net/mac80211/cfg.c | 18 +++++++ net/mac80211/pm.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++ net/mac80211/pm.h | 9 ++++ 4 files changed, 154 insertions(+), 0 deletions(-) create mode 100644 net/mac80211/pm.c create mode 100644 net/mac80211/pm.h
net/mac80211/Makefile +2 -0
@@ -37,6 +37,8 @@ mac80211-$(CONFIG_MAC80211_MESH) += \ mesh_plink.o \ mesh_hwmp.o +mac80211-$(CONFIG_PM) += pm.o + # objects for PID algorithm rc80211_pid-y := rc80211_pid_algo.o rc80211_pid-$(CONFIG_MAC80211_DEBUGFS) += rc80211_pid_debugfs.o
net/mac80211/cfg.c +18 -0
@@ -16,6 +16,7 @@#include "cfg.h" #include "rate.h" #include "mesh.h" +#include "pm.h" static bool nl80211_type_check (enum nl80211_iftype type) {
@@ -1107,6 +1108,21 @@ static int ieee80211_set_channel(struct wiphy *wiphy,return ieee80211_hw_config (local,IEEE80211_CONF_CHANGE_CHANNEL ); } +#ifdef CONFIG_PM +static int ieee80211_suspend (struct wiphy *wiphy) +{ +return __ieee80211_suspend (wiphy_priv (wiphy)); +} + +static int ieee80211_resume (struct wiphy *wiphy) +{ +return __ieee80211_resume (wiphy_priv (wiphy)); +} +#else +#define ieee80211_suspend NULL +#define ieee80211_resume NULL +#endif +struct cfg80211_ops mac80211_config_ops = { .add_virtual_intf = ieee80211_add_iface, .del_virtual_intf = ieee80211_del_iface,
@@ -1135,4 +1151,6 @@ struct cfg80211_ops mac80211_config_ops = { .change_bss = ieee80211_change_bss, .set_txq_params = ieee80211_set_txq_params, .set_channel = ieee80211_set_channel, + .suspend = ieee80211_suspend, + .resume = ieee80211_resume, };
net/mac80211/pm.c new file +125 -0
125 lines not on this page · raw message
net/mac80211/pm.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef __MAC80211_PM_H +#define __MAC80211_PM_H + +#ifdef CONFIG_PM +int __ieee80211_suspend (struct ieee80211_hw *hw); +int __ieee80211_resume (struct ieee80211_hw *hw); +#endif + +#endif
Signature · 4 lines
1.6.0.4 -- Bob Copeland %% www.bobcopeland.com
Johannes Berg
maintainerQuoted 8 lines · Bob Copeland
On Sun, 23 Nov 2008 10:19:13 +0100, Johannes Berg wrote
Quoted 4 lines
I think this should run through interfaces twice, in the first run to remove keys, then remove stas and then in the second run remove the interfaces, because otherwise you may be having keys left when the sta for which the key was has been removed.
Is this what you had in mind? (now on top of your cfg80211 patch, btw it called ->suspend() in the resume hook)
Can you adopt that patch too?
Quoted 6 lines
I tested this with ath5k, it works in the sense that device suspends and resumes without any hangs or errors.
However,
netif_running(sdata->dev)seems to randomly be false for wlan0 on the resume side so the interface doesn't always come up. I haven't had time to track that down but it's not consistent.
I think it's just a bug below?
Quoted 21 lines
net/mac80211/pm.c new file +21
-0+int __ieee80211_suspend (struct ieee80211_hw *hw) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct ieee80211_sub_if_data *sdata; +struct ieee80211_if_init_conf conf; +struct sta_info *sta; + +printk (KERN_DEBUG "mac80211: suspending\n" ); + +flush_workqueue (local->hw.workqueue); + +/* disable keys */ +list_for_each_entry (sdata, &local->interfaces, list) +ieee80211_disable_keys (sdata); + +/* remove STAs */ +list_for_each_entry (sta, &local->sta_list, list) { + +/* disable aggregation */ +ieee80211_sta_tear_down_BA_sessions (sdata, sta->sta.addr); +
net/mac80211/pm.c line 38
Quoted 10 lines
net/mac80211/pm.c new file +10
-0+if (local->ops->sta_notify) { +if (sdata->vif.type ==NL80211_IFTYPE_AP_VLAN ) + sdata =container_of (sdata->bss, + struct ieee80211_sub_if_data, + u.ap); + + local->ops->sta_notify (hw, &sdata->vif, +STA_NOTIFY_REMOVE , &sta->sta); + } + }
That looks pretty good.
net/mac80211/pm.c line 45
Quoted 6 lines
net/mac80211/pm.c new file +6
-0+/* remove all interfaces */ +list_for_each_entry (sdata, &local->interfaces, list) { + +if (sdata->vif.type ==NL80211_IFTYPE_AP_VLAN && + sdata->vif.type ==NL80211_IFTYPE_MONITOR && +netif_running (sdata->dev)) {
But shouldn't that be != _AP_VLAN && != _MONITOR && running?
net/mac80211/pm.c line 83
Quoted 6 lines
net/mac80211/pm.c new file +6
-0+/* add interfaces */ +list_for_each_entry (sdata, &local->interfaces, list) { + +if (sdata->vif.type !=NL80211_IFTYPE_AP_VLAN && + sdata->vif.type !=NL80211_IFTYPE_MONITOR && +netif_running (sdata->dev)) {
Like here
net/mac80211/pm.h line 7
Quoted 13 lines
net/mac80211/pm.h new file +7
-0@@ -0,0 +1,9 @@ +#ifndef __MAC80211_PM_H +#define __MAC80211_PM_H + +#ifdef CONFIG_PM +int __ieee80211_suspend (struct ieee80211_hw *hw); +int __ieee80211_resume (struct ieee80211_hw *hw); +#endif
I'd just add those to ieee80211_i.h, and I don't think you really need to protect them with #ifdef CONFIG_PM
johannes
On Tue, 09 Dec 2008 16:59:06 +0100, Johannes Berg wrote
Quoted 4 lines
Quoted 2 lines
Is this what you had in mind? (now on top of your cfg80211 patch, btw it called ->suspend() in the resume hook)
Can you adopt that patch too?
Yeah, I already have it in my tree, I just didn't repost it because my webmail sucks.
Quoted 8 lines
net/mac80211/pm.c line 45
Quoted 6 lines
net/mac80211/pm.c new file +6
-0+/* remove all interfaces */ +list_for_each_entry (sdata, &local->interfaces, list) { + +if (sdata->vif.type ==NL80211_IFTYPE_AP_VLAN && + sdata->vif.type ==NL80211_IFTYPE_MONITOR && +netif_running (sdata->dev)) {But shouldn't that be !=
_AP_VLAN&& !=_MONITOR&& running?
Oops, of course it should; that if() started life as continue. But that would just mean a missed call to remove_interface()... in the driver, which for ath5k just clears the mac, so I don't know why it would affect the running state of the interface.
Quoted 2 lines
I'd just add those to
ieee80211_i.h, and I don't think you really need to protect them with #ifdefCONFIG_PM
Will do, thanks for the review.
Signature · 1 line
Bob Copeland %% www.bobcopeland.com
Johannes Berg
maintainerQuoted 10 lines · Bob Copeland
Quoted 5 lines
net/mac80211/pm.c line 45
Quoted 3 lines
net/mac80211/pm.c new file +3
-0+if (sdata->vif.type ==NL80211_IFTYPE_AP_VLAN && + sdata->vif.type ==NL80211_IFTYPE_MONITOR && +netif_running (sdata->dev)) {But shouldn't that be !=
_AP_VLAN&& !=_MONITOR&& running?Oops, of course it should; that
if()started life as continue. But that would just mean a missed call toremove_interface()... in the driver, which for ath5k just clears the mac, so I don't know why it would affect the running state of the interface.
Ok, no, it shouldn't affect the running state.
johannes