Skip to contentSkip to conversation

some wireless suspend thoughts

PATCH Johannes Berg 3 participants 6 messages May 15, 2009 – May 18, 2009

Subsystems (3)
lore
Share & tools
lore

Johannes Berg

author maintainer
#0 lore raw

* kick pci driver suspend/resume out of ath9k and keep the device in low power while unused
* make mac80211 send nullfunc for suspend/resume
* make cfg80211 always call suspend/resume

This is quite hackish. It works for me, but my AP disassocs me anyway because it probes every 5 seconds and if you don't respond ... however, due to the nullfunc at resume time we notice very very quickly since it sends a deauth as a response to that.

The ->shutdown hook in cfg80211 is a little odd.

To implement WoW on top of this, we need to refactor the cfg80211 hooks and probably actually pass the information to ->stop after all, I think? I can't think of a good way to do this.

johannes

---
 drivers/net/wireless/ath/ath9k/ath9k.h |    2 
 drivers/net/wireless/ath/ath9k/main.c  |    6 ++
 drivers/net/wireless/ath/ath9k/pci.c   |   74 +++++++++++++--------------------
 net/mac80211/ieee80211_i.h             |    2 
 net/mac80211/pm.c                      |   11 ++++
 net/mac80211/util.c                    |    8 +++
 net/wireless/core.c                    |    2 
 net/wireless/core.h                    |    1 
 net/wireless/sysfs.c                   |   27 ++++++++++--
 9 files changed, 87 insertions(+), 46 deletions(-)
net/mac80211/ieee80211_i.h +2 -0
@@ -630,6 +630,8 @@ struct ieee80211_local {
 	 */
 	bool quiescing;
 
+	bool ps_before_suspend;
+
 	int tx_headroom; /* required headroom for hardware/radiotap */
 
 	/* Tasklet and skb queue to process calls from IRQ mode. All frames
net/mac80211/pm.c +11 -0
@@ -16,6 +16,17 @@ int __ieee80211_suspend(struct ieee80211
 
 	ieee80211_scan_cancel(local);
 
+	local->ps_before_suspend = !!(local->hw.conf.flags & IEEE80211_CONF_PS);
+	local->hw.conf.flags &= ~IEEE80211_CONF_PS;
+	ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
+
+	del_timer_sync(&local->dynamic_ps_timer);
+	cancel_work_sync(&local->dynamic_ps_enable_work);
+
+	list_for_each_entry(sdata, &local->interfaces, list)
+		if (sdata->vif.type == NL80211_IFTYPE_STATION)
+			ieee80211_send_nullfunc(local, sdata, 1);
+
 	ieee80211_stop_queues_by_reason(hw,
 			IEEE80211_QUEUE_STOP_REASON_SUSPEND);
 
net/mac80211/util.c +8 -0
@@ -1042,6 +1042,9 @@ int ieee80211_reconfig(struct ieee80211_
 	 */
 	local->suspended = false;
 
+	if (from_suspend && local->ps_before_suspend)
+		local->hw.conf.flags |= IEEE80211_CONF_PS;
+
 	/* restart hardware */
 	if (local->open_count) {
 		res = drv_start(local);
@@ -1144,6 +1147,11 @@ int ieee80211_reconfig(struct ieee80211_
 		return 0;
 
 #ifdef CONFIG_PM
+	if (!local->ps_before_suspend)
+		list_for_each_entry(sdata, &local->interfaces, list)
+			if (sdata->vif.type == NL80211_IFTYPE_STATION)
+				ieee80211_send_nullfunc(local, sdata, 0);
+
 	local->suspended = false;
 
 	list_for_each_entry(sdata, &local->interfaces, list) {
net/wireless/sysfs.c +24 -3
@@ -55,7 +55,7 @@ static int wiphy_uevent(struct device *d
 }
 #endif
 
-static int wiphy_suspend(struct device *dev, pm_message_t state)
+static int wiphy_suspend(struct device *dev)
 {
 	struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
 	int ret = 0;
@@ -90,6 +90,28 @@ static int wiphy_resume(struct device *d
 	return ret;
 }
 
+/* XXX: for WoW, .poweroff and .suspend need to be different */
+static struct dev_pm_ops cfg80211_pm_ops = {
+	.suspend = wiphy_suspend,
+	.resume = wiphy_resume,
+	.freeze = wiphy_suspend,
+	.thaw = wiphy_resume,
+	.poweroff = wiphy_suspend,
+	.restore = wiphy_resume,
+};
+
+static void wiphy_shutdown(struct device *dev)
+{
+	wiphy_suspend(dev);
+}
+
+/*
+ * XXX: This shouldn't be necessary?!
+ */
+struct device_driver wiphy_driver = {
+	.shutdown = wiphy_shutdown,
+};
+
 struct class ieee80211_class = {
 	.name = "ieee80211",
 	.owner = THIS_MODULE,
@@ -98,8 +120,7 @@ struct class ieee80211_class = {
 #ifdef CONFIG_HOTPLUG
 	.dev_uevent = wiphy_uevent,
 #endif
-	.suspend = wiphy_suspend,
-	.resume = wiphy_resume,
+	.pm = &cfg80211_pm_ops,
 };
 
 int wiphy_sysfs_init(void)
drivers/net/wireless/ath/ath9k/pci.c +31 -43

99 lines not on this page · raw message

net/wireless/core.c +2 -0
@@ -271,6 +271,8 @@ struct wiphy *wiphy_new(struct cfg80211_
 
 	device_initialize(&drv->wiphy.dev);
 	drv->wiphy.dev.class = &ieee80211_class;
+	/* only for ->shutdown hook */
+	drv->wiphy.dev.driver = &wiphy_driver;
 	drv->wiphy.dev.platform_data = drv;
 
 	/*
net/wireless/core.h +1 -0
@@ -154,5 +154,6 @@ int cfg80211_leave_ibss(struct cfg80211_
 /* internal helpers */
 int cfg80211_validate_key_settings(struct key_params *params, int key_idx,
 				   const u8 *mac_addr);
+extern struct device_driver wiphy_driver;
 
 #endif /* __NET_WIRELESS_CORE_H */
drivers/net/wireless/ath/ath9k/ath9k.h +2 -0
@@ -516,6 +516,8 @@ struct ath_rfkill {
 #define SC_OP_TSF_RESET         BIT(15)
 
 struct ath_bus_ops {
+	int		(*start)(struct ath_softc *sc);
+	void		(*stop)(struct ath_softc *sc);
 	void		(*read_cachesize)(struct ath_softc *sc, int *csz);
 	void		(*cleanup)(struct ath_softc *sc);
 	bool		(*eeprom_read)(struct ath_hw *ah, u32 off, u16 *data);
drivers/net/wireless/ath/ath9k/main.c +6 -0
@@ -1901,6 +1901,10 @@ static int ath9k_start(struct ieee80211_
 	DPRINTF(sc, ATH_DBG_CONFIG, "Starting driver with "
 		"initial channel: %d MHz\n", curchan->center_freq);
 
+	r = sc->bus_ops->start(sc);
+	if (r)
+		return r;
+
 	mutex_lock(&sc->mutex);
 
 	if (ath9k_wiphy_started(sc)) {
@@ -2105,6 +2109,8 @@ static void ath9k_stop(struct ieee80211_
 
 	mutex_unlock(&sc->mutex);
 
+	sc->bus_ops->stop(sc);
+
 	DPRINTF(sc, ATH_DBG_CONFIG, "Driver halt\n");
 }
 
#1 lore raw
Quoted 2 lines · Johannes Berg

 * kick pci driver suspend/resume out of ath9k and keep the device in low power while unused

This is nice.

Quoted 8 lines

 * make mac80211 send nullfunc for suspend/resume
 * make cfg80211 always call suspend/resume

This is quite hackish. It works for me, but my AP disassocs me anyway because it probes every 5 seconds and if you don't respond ... however, due to the nullfunc at resume time we notice very very quickly since it sends a deauth as a response to that.

Quoted 5 lines

The ->shutdown hook in cfg80211 is a little odd.

To implement WoW on top of this, we need to refactor the cfg80211 hooks and probably actually pass the information to ->stop after all, I think? I can't think of a good way to do this.

Well that's for sure with this patch. Let me take a crack at it.

net/mac80211/pm.c  2009-05-15 15:17:09.891708511 +0200 int __ieee80211_suspend(struct ieee80211 · line 20

Quoted 8 lines
net/mac80211/pm.c  2009-05-15 15:17:09.891708511 +0200 renamed from net/mac80211/pm.c     2009-05-15 15:17:08.851827827 +0200 +2 -0
@@ -16,6 +16,17 @@ int __ieee80211_suspend(struct ieee80211
 
        ieee80211_scan_cancel(local);
 
+       local->ps_before_suspend = !!(local->hw.conf.flags & IEEE80211_CONF_PS);
+       local->hw.conf.flags &= ~IEEE80211_CONF_PS;

Why clear it? Wasn't the goal to go to PS mode during suspend? Also if we're already in PS mode no point in calling hw_config.

I take it we don't want to go to PS mode when we don't have WoW enabled then, because as you noted you're going to disassoc pretty quickly otherwise, unless your AP has long idle detection times. PS mode requires you to be able to be up at least every DTIM it would seem better to just disassoc unless wow is enabled.

Quoted 14 lines
drivers/net/wireless/ath/ath9k/main.c      2009-05-15 15:47:15.051830998 +0200 renamed from drivers/net/wireless/ath/ath9k/main.c 2009-05-15 15:44:19.261837573 +0200 +0 -0
@@ -1901,6 +1901,10 @@ static int ath9k_start(struct ieee80211_

       DPRINTF(sc, ATH_DBG_CONFIG, "Starting driver with " "initial channel: %d MHz\n", curchan->center_freq);

+       r = sc->bus_ops->start(sc);
+       if (r)
+               return r;
+
       mutex_lock(&sc->mutex);

       if (ath9k_wiphy_started(sc)) {

drivers/net/wireless/ath/ath9k/main.c      2009-05-15 15:47:15.051830998 +0200 static void ath9k_stop(struct ieee80211_ · line 2115

Quoted 7 lines
drivers/net/wireless/ath/ath9k/main.c      2009-05-15 15:47:15.051830998 +0200 renamed from drivers/net/wireless/ath/ath9k/main.c 2009-05-15 15:44:19.261837573 +0200 +2 -0
@@ -2105,6 +2109,8 @@ static void ath9k_stop(struct ieee80211_
 
        mutex_unlock(&sc->mutex);
 
+       sc->bus_ops->stop(sc);
+
        DPRINTF(sc, ATH_DBG_CONFIG, "Driver halt\n");
  }

We need to consider ahb as well but that's a quick fix.

Luis

#2 lore raw
Quoted 15 lines · Luis R. Rodriguez
Quoted 2 lines · Johannes Berg

 * kick pci driver suspend/resume out of ath9k and keep the device in low power while unused

This is nice.

Quoted 8 lines

 * make mac80211 send nullfunc for suspend/resume
 * make cfg80211 always call suspend/resume

This is quite hackish. It works for me, but my AP disassocs me anyway because it probes every 5 seconds and if you don't respond ... however, due to the nullfunc at resume time we notice very very quickly since it sends a deauth as a response to that.

Quoted 7 lines
Quoted 5 lines

The ->shutdown hook in cfg80211 is a little odd.

To implement WoW on top of this, we need to refactor the cfg80211 hooks and probably actually pass the information to ->stop after all, I think? I can't think of a good way to do this.

Well that's for sure with this patch. Let me take a crack at it.

I noticed you nuked pci_save_state() and pci_restore_state(), that saves PCI config space so seems required, so we'll have to still inform drv_stop of the suspend case -- and not sure that is worth it. What we save here is more control in mac80211 / cfg80211 but the things we need to added makes me wonder if its worth it in this case.

Luis

author maintainer
#3 lore raw
In reply to Luis R. Rodriguez
Quoted 12 lines · Luis R. Rodriguez

net/mac80211/pm.c 2009-05-15 15:17:09.891708511 +0200 int __ieee80211_suspend(struct ieee80211 · line 20

Quoted 8 lines
net/mac80211/pm.c 2009-05-15 15:17:09.891708511 +0200 renamed from net/mac80211/pm.c 2009-05-15 15:17:08.851827827 +0200 +2 -0
@@ -16,6 +16,17 @@ int __ieee80211_suspend(struct ieee80211
 
       ieee80211_scan_cancel(local);
 
+       local->ps_before_suspend = !!(local->hw.conf.flags & IEEE80211_CONF_PS);
+       local->hw.conf.flags &= ~IEEE80211_CONF_PS;

Why clear it? Wasn't the goal to go to PS mode during suspend? Also if we're already in PS mode no point in calling hw_config.

Quoted 5 lines

I take it we don't want to go to PS mode when we don't have WoW enabled then, because as you noted you're going to disassoc pretty quickly otherwise, unless your AP has long idle detection times. PS mode requires you to be able to be up at least every DTIM it would seem better to just disassoc unless wow is enabled.

Yes, I don't really know why I did that, I think I only did because I wanted to be able to control what the AP thought by sending that nullfunc frame in mac80211. We probably should do the reverse and enable CONF_PS if supported and not active yet, and only if not supported send the nullfunc frame 'manually'.

But note that for the AP we are in PS anyway since I send the nullfunc frame.

Quoted 1 line

We need to consider ahb as well but that's a quick fix.

Yes, of course. Like I said -- a hack.

Quoted 3 lines

I noticed you nuked pci_save_state() and pci_restore_state(), that saves PCI config space so seems required, so we'll have to still inform drv_stop of the suspend case -- and not sure that is worth it.

Yeah I wasn't sure about that myself. I suspect moving
* pci cache line adjustment,
* pci latency timer thing,
* and pci_set_master
into ->start would be sufficient instead of using save_state/restore_state.

Quoted 2 lines

What we save here is more control in mac80211 / cfg80211 but the things we need to added makes me wonder if its worth it in this case.

Yeah, not sure really. I was just playing with the code mostly tbh. I thought it was nice that I didn't need code in two places in the driver, only in ->start/->stop rather than the PCI resume hooks too.

Also, because I decided to use ->shutdown in cfg80211 so we could in theory have WoW while the machine is off... of course, that doesn't really work since wpa_supplicant will long have been killed thereby deconfiguring the interface and userspace will have taken the interface down itself. Of course, the immediate reason I added a shutdown hook was that quirk with my platform where the wireless card would have woken up for writing the hibernate image, but then never told the AP it's going to PS again because the machine just turns off after that...

johannes

#4 lore raw
In reply to Johannes Berg
Quoted 9 lines · Johannes Berg

* kick pci driver suspend/resume out of ath9k and keep the device in low power while unused
* make mac80211 send nullfunc for suspend/resume
* make cfg80211 always call suspend/resume

This is quite hackish. It works for me, but my AP disassocs me anyway because it probes every 5 seconds and if you don't respond ... however, due to the nullfunc at resume time we notice very very quickly since it sends a deauth as a response to that.

To me trying to maintain association during suspend sounds wrong. What do we gain from that?

In my opinion it's better to disassociate during suspend and let user space reassociate during resume. That way no need to do any special hacks and functionality is the same with all APs.

I'm sure I'm missing a lot here, but this is my first impression.

Signature · 1 line
Kalle Valo
author maintainer
#5 lore raw
Quoted 8 lines · Kalle Valo

To me trying to maintain association during suspend sounds wrong. What do we gain from that?

In my opinion it's better to disassociate during suspend and let user space reassociate during resume. That way no need to do any special hacks and functionality is the same with all APs.

I'm sure I'm missing a lot here, but this is my first impression.

It seems it could be possible to just suspend for very little time, in which case you might care. Also, this actually helped for the case where we don't manage to maintain association because then we send a nullfunc frame and get a deauth very very quickly at resume.

johannes