[PATCH] wilc1000: Allow setting power_save before driver is initialized

Subsystems: microchip wilc1000 wifi driver, the rest

STALE1760d

4 messages, 2 authors, 2021-12-16 · open the first message on its own page

[PATCH] wilc1000: Allow setting power_save before driver is initialized

From: David Mosberger-Tang <hidden>
Date: 2021-12-12 01:21:22

Without this patch, trying to use:

	iw dev wlan0 set power_save on

before the driver is initialized results in an EIO error.  It is more
useful to simply remember the desired setting and establish it when
the driver is initialized.

Signed-off-by: David Mosberger-Tang <redacted>
---
 drivers/net/wireless/microchip/wilc1000/cfg80211.c | 3 ---
 drivers/net/wireless/microchip/wilc1000/hif.c      | 8 ++++++++
 drivers/net/wireless/microchip/wilc1000/netdev.c   | 3 ++-
 3 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/microchip/wilc1000/cfg80211.c b/drivers/net/wireless/microchip/wilc1000/cfg80211.c
index dc4bfe7be378..01d607fa2ded 100644
--- a/drivers/net/wireless/microchip/wilc1000/cfg80211.c
+++ b/drivers/net/wireless/microchip/wilc1000/cfg80211.c
@@ -1280,9 +1280,6 @@ static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
 	struct wilc_vif *vif = netdev_priv(dev);
 	struct wilc_priv *priv = &vif->priv;
 
-	if (!priv->hif_drv)
-		return -EIO;
-
 	wilc_set_power_mgmt(vif, enabled, timeout);
 
 	return 0;
diff --git a/drivers/net/wireless/microchip/wilc1000/hif.c b/drivers/net/wireless/microchip/wilc1000/hif.c
index 29a42bc47017..66fd77c816f7 100644
--- a/drivers/net/wireless/microchip/wilc1000/hif.c
+++ b/drivers/net/wireless/microchip/wilc1000/hif.c
@@ -1934,6 +1934,14 @@ int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
 	int result;
 	s8 power_mode;
 
+	if (!wilc->initialized) {
+		/* Simply remember the desired setting for now; will be
+		 * established by wilc_init_fw_config().
+		 */
+		wilc->power_save_mode = enabled;
+		return 0;
+	}
+
 	if (enabled)
 		power_mode = WILC_FW_MIN_FAST_PS;
 	else
diff --git a/drivers/net/wireless/microchip/wilc1000/netdev.c b/drivers/net/wireless/microchip/wilc1000/netdev.c
index 4712cd7dff9f..082bed26a981 100644
--- a/drivers/net/wireless/microchip/wilc1000/netdev.c
+++ b/drivers/net/wireless/microchip/wilc1000/netdev.c
@@ -244,6 +244,7 @@ static int wilc1000_firmware_download(struct net_device *dev)
 static int wilc_init_fw_config(struct net_device *dev, struct wilc_vif *vif)
 {
 	struct wilc_priv *priv = &vif->priv;
+	struct wilc *wilc = vif->wilc;
 	struct host_if_drv *hif_drv;
 	u8 b;
 	u16 hw;
@@ -305,7 +306,7 @@ static int wilc_init_fw_config(struct net_device *dev, struct wilc_vif *vif)
 	if (!wilc_wlan_cfg_set(vif, 0, WID_QOS_ENABLE, &b, 1, 0, 0))
 		goto fail;
 
-	b = WILC_FW_NO_POWERSAVE;
+	b = wilc->power_save_mode ? WILC_FW_MIN_FAST_PS : WILC_FW_NO_POWERSAVE;
 	if (!wilc_wlan_cfg_set(vif, 0, WID_POWER_MANAGEMENT, &b, 1, 0, 0))
 		goto fail;
 
-- 
2.25.1

Re: [PATCH] wilc1000: Allow setting power_save before driver is initialized

From: David Mosberger-Tang <hidden>
Date: 2021-12-12 21:22:00

Unfortunately, this patch doesn't seem to be sufficient.  From what I
can tell, if power-save mode is turned on before a station is
associated with an access-point, there is no actual power savings.  If
I issue the command after the station is associated, it works perfectly
fine.

Ajay, does this make sense to you?

Best regards,

  --david

On Sun, 2021-12-12 at 01:18 +0000, David Mosberger-Tang wrote:
quoted hunk
Without this patch, trying to use:

	iw dev wlan0 set power_save on

before the driver is initialized results in an EIO error.  It is more
useful to simply remember the desired setting and establish it when
the driver is initialized.

Signed-off-by: David Mosberger-Tang <redacted>
---
 drivers/net/wireless/microchip/wilc1000/cfg80211.c | 3 ---
 drivers/net/wireless/microchip/wilc1000/hif.c      | 8 ++++++++
 drivers/net/wireless/microchip/wilc1000/netdev.c   | 3 ++-
 3 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/microchip/wilc1000/cfg80211.c b/drivers/net/wireless/microchip/wilc1000/cfg80211.c
index dc4bfe7be378..01d607fa2ded 100644
--- a/drivers/net/wireless/microchip/wilc1000/cfg80211.c
+++ b/drivers/net/wireless/microchip/wilc1000/cfg80211.c
@@ -1280,9 +1280,6 @@ static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
 	struct wilc_vif *vif = netdev_priv(dev);
 	struct wilc_priv *priv = &vif->priv;
 
-	if (!priv->hif_drv)
-		return -EIO;
-
 	wilc_set_power_mgmt(vif, enabled, timeout);
 
 	return 0;
diff --git a/drivers/net/wireless/microchip/wilc1000/hif.c b/drivers/net/wireless/microchip/wilc1000/hif.c
index 29a42bc47017..66fd77c816f7 100644
--- a/drivers/net/wireless/microchip/wilc1000/hif.c
+++ b/drivers/net/wireless/microchip/wilc1000/hif.c
@@ -1934,6 +1934,14 @@ int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
 	int result;
 	s8 power_mode;
 
+	if (!wilc->initialized) {
+		/* Simply remember the desired setting for now; will be
+		 * established by wilc_init_fw_config().
+		 */
+		wilc->power_save_mode = enabled;
+		return 0;
+	}
+
 	if (enabled)
 		power_mode = WILC_FW_MIN_FAST_PS;
 	else
diff --git a/drivers/net/wireless/microchip/wilc1000/netdev.c b/drivers/net/wireless/microchip/wilc1000/netdev.c
index 4712cd7dff9f..082bed26a981 100644
--- a/drivers/net/wireless/microchip/wilc1000/netdev.c
+++ b/drivers/net/wireless/microchip/wilc1000/netdev.c
@@ -244,6 +244,7 @@ static int wilc1000_firmware_download(struct net_device *dev)
 static int wilc_init_fw_config(struct net_device *dev, struct wilc_vif *vif)
 {
 	struct wilc_priv *priv = &vif->priv;
+	struct wilc *wilc = vif->wilc;
 	struct host_if_drv *hif_drv;
 	u8 b;
 	u16 hw;
@@ -305,7 +306,7 @@ static int wilc_init_fw_config(struct net_device *dev, struct wilc_vif *vif)
 	if (!wilc_wlan_cfg_set(vif, 0, WID_QOS_ENABLE, &b, 1, 0, 0))
 		goto fail;
 
-	b = WILC_FW_NO_POWERSAVE;
+	b = wilc->power_save_mode ? WILC_FW_MIN_FAST_PS : WILC_FW_NO_POWERSAVE;
 	if (!wilc_wlan_cfg_set(vif, 0, WID_POWER_MANAGEMENT, &b, 1, 0, 0))
 		goto fail;
 

Re: [PATCH] wilc1000: Allow setting power_save before driver is initialized

From: <Ajay.Kathat@microchip.com>
Date: 2021-12-15 13:01:42

On 13/12/21 02:50, David Mosberger-Tang wrote:
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Unfortunately, this patch doesn't seem to be sufficient.  From what I
can tell, if power-save mode is turned on before a station is
associated with an access-point, there is no actual power savings.  If
I issue the command after the station is associated, it works perfectly
fine.

Ajay, does this make sense to you?

I think the patch has no effect because wilc_init_fw_config() gets 
called before wilc_set_power_mgmt().

Also, you had mentioned that to enable the PSM(power-save mode), the 
toggling of PS mode is required that means the previous set_power_mgmt() 
was successful. I believe ".set_power_mgmt" cfg80211_ops doesn't get 
called when there is no change from the previous state.

Power-save mode is allowed to be enabled irrespective of station 
association state. Before association, the power consumption should be 
less with PSM enabled compared to PSM disabled. The WLAN automatic power 
save delivery gets enabled after the association with AP.

To check the power measurement before association,  test without 
wpa_supplicant.


Steps:
- load the module
- ifconfig wlan0 up
- iw dev wlan0 set power_save off (check the pwr measurement after PS 
mode disabled)
- iw dev wlan0 set power_save on (check the pwr measurement after PS 
mode enable)


Regards,
Ajay

Re: [PATCH] wilc1000: Allow setting power_save before driver is initialized

From: David Mosberger-Tang <hidden>
Date: 2021-12-16 05:38:02

On Wed, 2021-12-15 at 13:01 +0000, Ajay.Kathat@microchip.com wrote:
On 13/12/21 02:50, David Mosberger-Tang wrote:
quoted
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Unfortunately, this patch doesn't seem to be sufficient.  From what I
can tell, if power-save mode is turned on before a station is
associated with an access-point, there is no actual power savings.  If
I issue the command after the station is associated, it works perfectly
fine.

Ajay, does this make sense to you?
  <snip>
Power-save mode is allowed to be enabled irrespective of station 
association state. Before association, the power consumption should be 
less with PSM enabled compared to PSM disabled. The WLAN automatic power 
save delivery gets enabled after the association with AP.

To check the power measurement before association,  test without 
wpa_supplicant.


Steps:
- load the module
- ifconfig wlan0 up
- iw dev wlan0 set power_save off (check the pwr measurement after PS 
mode disabled)
- iw dev wlan0 set power_save on (check the pwr measurement after PS 
mode enable)
It appears wpa_supplicant consistently renders PSM ineffective:

                                (current draw, 1 min avg):
------------------------------  --------------------------
- base case (no module loaded): 16.8 mA
- module loaded & PSM on      : 16.8 mA
- wpa_supplicant started      : 19.6 mA
- PSM on                      : 19.6 mA (no change)
- PSM off                     : 19.6 mA (no change)
- PSM on                      : 15.4 mA

What's strange is when I try this sequence a couple of times in a row,
the device gets into a state where after starting wpa_supplicant, no
amount of PSM on/off commands will get it to enter power-savings mode
any more.  When in that state, only removing wilc1000-spi.ko and adding
it back gets it out of that state.  A power-cycle does not.  Very
confusing.

  --david

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help