linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jerome Pouiller <Jerome.Pouiller@silabs.com>
To: devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Kalle Valo" <kvalo@codeaurora.org>,
	"David S . Miller" <davem@davemloft.net>,
	"Jérôme Pouiller" <jerome.pouiller@silabs.com>
Subject: [PATCH 07/10] staging: wfx: add support for set/get ps_timeout
Date: Tue, 26 May 2020 19:18:18 +0200	[thread overview]
Message-ID: <20200526171821.934581-8-Jerome.Pouiller@silabs.com> (raw)
In-Reply-To: <20200526171821.934581-1-Jerome.Pouiller@silabs.com>

From: Jérôme Pouiller <jerome.pouiller@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@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


  parent reply	other threads:[~2020-05-26 17:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-26 17:18 [PATCH 00/10] staging: wfx: introduce nl80211 vendor extensions Jerome Pouiller
2020-05-26 17:18 ` [PATCH 01/10] staging: wfx: drop unused variable Jerome Pouiller
2020-05-26 17:18 ` [PATCH 02/10] staging: wfx: do not declare variables inside loops Jerome Pouiller
2020-05-26 17:18 ` [PATCH 03/10] staging: wfx: drop unused function wfx_pending_requeue() Jerome Pouiller
2020-05-26 17:18 ` [PATCH 04/10] staging: wfx: add support for tx_power_loop Jerome Pouiller
2020-05-26 17:18 ` [PATCH 05/10] staging: wfx: retrieve the PS status from the vif Jerome Pouiller
2020-05-26 17:18 ` [PATCH 06/10] staging: wfx: split wfx_get_ps_timeout() from wfx_update_pm() Jerome Pouiller
2020-05-26 17:18 ` Jerome Pouiller [this message]
2020-05-26 17:18 ` [PATCH 08/10] staging: wfx: allow to burn prevent rollback bit Jerome Pouiller
2020-05-26 17:18 ` [PATCH 09/10] staging: wfx: allow to set PTA settings Jerome Pouiller
2020-05-26 17:18 ` [PATCH 10/10] staging: wfx: allow to run nl80211 vendor commands with 'iw' Jerome Pouiller
2020-05-27  8:22 ` [PATCH 00/10] staging: wfx: introduce nl80211 vendor extensions Greg Kroah-Hartman
2020-05-27 12:34 ` Kalle Valo
2020-05-27 13:05   ` Jérôme Pouiller
2020-05-29 15:13     ` Kalle Valo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200526171821.934581-8-Jerome.Pouiller@silabs.com \
    --to=jerome.pouiller@silabs.com \
    --cc=davem@davemloft.net \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).