[PATCH 07/10] staging: wfx: add support for set/get ps_timeout

Jerome Pouiller Jerome.Pouiller at silabs.com
Tue May 26 17:18:18 UTC 2020


From: Jérôme Pouiller <jerome.pouiller at silabs.com>

In some advanced usage or debug scenarios, it could interesting to
change the value of ps_timeout or eventually to force use of PS-Poll
frames.

The wext API (used by iwconfig) provide a way to change ps_timeout.
However, this API is obsolete and it seems a little weird to use (it
seems it doesn't apply the changes, so the user have to disable then
re-enable de power save)

On side of nl80211, there is no way to change the ps_timeout.

This patch provides a vendor extension to nl80211 to change the value
of ps_timeout.

Signed-off-by: Jérôme Pouiller <jerome.pouiller at silabs.com>
---
 drivers/staging/wfx/Makefile         |  3 +-
 drivers/staging/wfx/main.c           |  4 +++
 drivers/staging/wfx/nl80211_vendor.c | 49 ++++++++++++++++++++++++++++
 drivers/staging/wfx/nl80211_vendor.h | 44 +++++++++++++++++++++++++
 drivers/staging/wfx/sta.c            |  9 +++--
 drivers/staging/wfx/sta.h            |  2 ++
 drivers/staging/wfx/wfx.h            |  1 +
 7 files changed, 109 insertions(+), 3 deletions(-)
 create mode 100644 drivers/staging/wfx/nl80211_vendor.c
 create mode 100644 drivers/staging/wfx/nl80211_vendor.h

diff --git a/drivers/staging/wfx/Makefile b/drivers/staging/wfx/Makefile
index 0e0cc982ceab2..2d34a02853226 100644
--- a/drivers/staging/wfx/Makefile
+++ b/drivers/staging/wfx/Makefile
@@ -18,7 +18,8 @@ wfx-y := \
 	key.o \
 	main.o \
 	sta.o \
-	debug.o
+	debug.o \
+	nl80211_vendor.o
 wfx-$(CONFIG_SPI) += bus_spi.o
 wfx-$(subst m,y,$(CONFIG_MMC)) += bus_sdio.o
 
diff --git a/drivers/staging/wfx/main.c b/drivers/staging/wfx/main.c
index 6bd96f4763884..11f6bc6fa3394 100644
--- a/drivers/staging/wfx/main.c
+++ b/drivers/staging/wfx/main.c
@@ -34,6 +34,7 @@
 #include "secure_link.h"
 #include "hif_tx_mib.h"
 #include "hif_api_cmd.h"
+#include "nl80211_vendor.h"
 
 #define WFX_PDS_MAX_SIZE 1500
 
@@ -312,6 +313,9 @@ struct wfx_dev *wfx_init_common(struct device *dev,
 				sizeof(struct hif_msg)
 				+ sizeof(struct hif_req_tx)
 				+ 4 /* alignment */ + 8 /* TKIP IV */;
+
+	hw->wiphy->n_vendor_commands = ARRAY_SIZE(wfx_nl80211_vendor_commands);
+	hw->wiphy->vendor_commands = wfx_nl80211_vendor_commands;
 	hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
 				     BIT(NL80211_IFTYPE_ADHOC) |
 				     BIT(NL80211_IFTYPE_AP);
diff --git a/drivers/staging/wfx/nl80211_vendor.c b/drivers/staging/wfx/nl80211_vendor.c
new file mode 100644
index 0000000000000..ec2fd2d73885f
--- /dev/null
+++ b/drivers/staging/wfx/nl80211_vendor.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Extra commands for nl80211 interface.
+ *
+ * Copyright (c) 2020, Silicon Laboratories, Inc.
+ */
+#include "nl80211_vendor.h"
+#include "wfx.h"
+#include "sta.h"
+
+int wfx_nl_ps_timeout(struct wiphy *wiphy, struct wireless_dev *widev,
+		      const void *data, int data_len)
+{
+	int reply_size = nla_total_size(sizeof(u32));
+	struct nlattr *tb[WFX_NL80211_ATTR_MAX];
+	struct ieee80211_vif *vif;
+	struct wfx_vif *wvif;
+	struct sk_buff *msg;
+	int rc, ps_timeout;
+
+	rc = nla_parse(tb, WFX_NL80211_ATTR_MAX - 1, data, data_len,
+		       wfx_nl_policy, NULL);
+	if (rc)
+		return rc;
+	vif = wdev_to_ieee80211_vif(widev);
+	if (!vif)
+		return -ENODEV;
+	wvif = (struct wfx_vif *)vif->drv_priv;
+
+	if (tb[WFX_NL80211_ATTR_PS_TIMEOUT]) {
+		wvif->force_ps_timeout =
+			nla_get_s32(tb[WFX_NL80211_ATTR_PS_TIMEOUT]);
+		wfx_update_pm(wvif);
+	}
+
+	msg = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, reply_size);
+	if (!msg)
+		return -ENOMEM;
+	ps_timeout = wfx_get_ps_timeout(wvif, NULL);
+	rc = nla_put_s32(msg, WFX_NL80211_ATTR_PS_TIMEOUT, ps_timeout);
+	if (rc)
+		goto error;
+	return cfg80211_vendor_cmd_reply(msg);
+
+error:
+	kfree_skb(msg);
+	return rc;
+}
+
diff --git a/drivers/staging/wfx/nl80211_vendor.h b/drivers/staging/wfx/nl80211_vendor.h
new file mode 100644
index 0000000000000..c069330e240a9
--- /dev/null
+++ b/drivers/staging/wfx/nl80211_vendor.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Extra commands for nl80211 interface.
+ *
+ * Copyright (c) 2020, Silicon Laboratories, Inc.
+ */
+#ifndef WFX_NL80211_VENDOR_H
+#define WFX_NL80211_VENDOR_H
+
+#include <net/netlink.h>
+#include <net/cfg80211.h>
+
+#include "hif_api_general.h"
+
+#define WFX_NL80211_ID 0x90fd9f
+
+int wfx_nl_ps_timeout(struct wiphy *wiphy, struct wireless_dev *widev,
+		      const void *data, int data_len);
+
+enum {
+	WFX_NL80211_SUBCMD_PS_TIMEOUT                   = 0x10,
+};
+
+enum {
+	WFX_NL80211_ATTR_PS_TIMEOUT     = 1,
+	WFX_NL80211_ATTR_MAX
+};
+
+static const struct nla_policy wfx_nl_policy[WFX_NL80211_ATTR_MAX] = {
+	[WFX_NL80211_ATTR_PS_TIMEOUT]     = NLA_POLICY_RANGE(NLA_S32, -1, 127),
+};
+
+static const struct wiphy_vendor_command wfx_nl80211_vendor_commands[] = {
+	{
+		.info.vendor_id = WFX_NL80211_ID,
+		.info.subcmd = WFX_NL80211_SUBCMD_PS_TIMEOUT,
+		.flags = WIPHY_VENDOR_CMD_NEED_WDEV,
+		.policy = wfx_nl_policy,
+		.doit = wfx_nl_ps_timeout,
+		.maxattr = WFX_NL80211_ATTR_MAX - 1,
+	},
+};
+
+#endif /* WFX_NL80211_VENDOR_H */
diff --git a/drivers/staging/wfx/sta.c b/drivers/staging/wfx/sta.c
index 12e8a5b638f11..7f0bb8eb78660 100644
--- a/drivers/staging/wfx/sta.c
+++ b/drivers/staging/wfx/sta.c
@@ -217,14 +217,18 @@ int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *enable_ps)
 		// are differents.
 		if (enable_ps)
 			*enable_ps = true;
-		if (wvif->bss_not_support_ps_poll)
+		if (wvif->force_ps_timeout > -1)
+			return wvif->force_ps_timeout;
+		else if (wvif->bss_not_support_ps_poll)
 			return 30;
 		else
 			return 0;
 	}
 	if (enable_ps)
 		*enable_ps = wvif->vif->bss_conf.ps;
-	if (wvif->vif->bss_conf.assoc && wvif->vif->bss_conf.ps)
+	if (wvif->force_ps_timeout > -1)
+		return wvif->force_ps_timeout;
+	else if (wvif->vif->bss_conf.assoc && wvif->vif->bss_conf.ps)
 		return conf->dynamic_ps_timeout;
 	else
 		return -1;
@@ -788,6 +792,7 @@ int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
 	wvif->vif = vif;
 	wvif->wdev = wdev;
 
+	wvif->force_ps_timeout = -1;
 	wvif->link_id_map = 1; // link-id 0 is reserved for multicast
 	INIT_WORK(&wvif->update_tim_work, wfx_update_tim_work);
 	INIT_DELAYED_WORK(&wvif->beacon_loss_work, wfx_beacon_loss_work);
diff --git a/drivers/staging/wfx/sta.h b/drivers/staging/wfx/sta.h
index 8a20ad9ae017e..8220d31184c8c 100644
--- a/drivers/staging/wfx/sta.h
+++ b/drivers/staging/wfx/sta.h
@@ -69,9 +69,11 @@ void wfx_cooling_timeout_work(struct work_struct *work);
 void wfx_suspend_hot_dev(struct wfx_dev *wdev, enum sta_notify_cmd cmd);
 void wfx_suspend_resume_mc(struct wfx_vif *wvif, enum sta_notify_cmd cmd);
 void wfx_event_report_rssi(struct wfx_vif *wvif, u8 raw_rcpi_rssi);
+int wfx_update_pm(struct wfx_vif *wvif);
 
 // Other Helpers
 void wfx_reset(struct wfx_vif *wvif);
+int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *force_ps);
 u32 wfx_rate_mask_to_hw(struct wfx_dev *wdev, u32 rates);
 
 #endif /* WFX_STA_H */
diff --git a/drivers/staging/wfx/wfx.h b/drivers/staging/wfx/wfx.h
index 73e216733ce4f..ef68aa4086e01 100644
--- a/drivers/staging/wfx/wfx.h
+++ b/drivers/staging/wfx/wfx.h
@@ -92,6 +92,7 @@ struct wfx_vif {
 	bool			scan_abort;
 	struct ieee80211_scan_request *scan_req;
 
+	int			force_ps_timeout;
 	bool			bss_not_support_ps_poll;
 	struct work_struct	update_pm_work;
 	struct completion	set_pm_mode_complete;
-- 
2.26.2



More information about the devel mailing list