From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH 5/7] netdev: disable power save if required
Date: Thu, 15 Jun 2023 12:24:13 -0700 [thread overview]
Message-ID: <20230615192415.1718516-5-prestwoj@gmail.com> (raw)
In-Reply-To: <20230615192415.1718516-1-prestwoj@gmail.com>
Disable power save if the wiphy indicates its needed. Do this
before issuing GET_LINK so the netdev doesn't signal its up until
power save is disabled.
---
src/netdev.c | 80 +++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 66 insertions(+), 14 deletions(-)
diff --git a/src/netdev.c b/src/netdev.c
index 4ee17f3b..1b44944e 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -6212,6 +6212,65 @@ error:
return NULL;
}
+static void netdev_get_link(uint32_t ifindex)
+{
+ struct ifinfomsg *rtmmsg;
+ size_t bufsize;
+
+ /* Query interface flags */
+ bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg));
+ rtmmsg = l_malloc(bufsize);
+ memset(rtmmsg, 0, bufsize);
+
+ rtmmsg->ifi_family = AF_UNSPEC;
+ rtmmsg->ifi_index = ifindex;
+
+ l_netlink_send(rtnl, RTM_GETLINK, 0, rtmmsg, bufsize,
+ netdev_getlink_cb, NULL, NULL);
+
+ l_free(rtmmsg);
+}
+
+static void netdev_disable_ps_cb(struct l_genl_msg *msg, void *user_data)
+{
+ int err = l_genl_msg_get_error(msg);
+ uint32_t ifindex = L_PTR_TO_UINT(user_data);
+
+ /* Can't do anything about it but inform the user */
+ if (err < 0) {
+ l_error("Failed to disable power save for ifindex %u (%s: %d)",
+ ifindex, strerror(-err), err);
+ return;
+ }
+
+ l_debug("Disabled power save for ifindex %u", ifindex);
+}
+
+static void netdev_disable_ps_destroy(void *user_data)
+{
+ uint32_t ifindex = L_PTR_TO_UINT(user_data);
+
+ netdev_get_link(ifindex);
+}
+
+static bool netdev_disable_power_save(uint32_t ifindex)
+{
+ struct l_genl_msg *msg = l_genl_msg_new(NL80211_CMD_SET_POWER_SAVE);
+ uint32_t disabled = NL80211_PS_DISABLED;
+
+ l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
+ l_genl_msg_append_attr(msg, NL80211_ATTR_PS_STATE, 4, &disabled);
+
+ if (!l_genl_family_send(nl80211, msg, netdev_disable_ps_cb,
+ L_UINT_TO_PTR(ifindex),
+ netdev_disable_ps_destroy)) {
+ l_error("Failed to send SET_POWER_SAVE (-EIO)");
+ return false;
+ }
+
+ return true;
+}
+
struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
const uint8_t *set_mac)
{
@@ -6223,8 +6282,6 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
uint32_t wiphy_id;
struct netdev *netdev;
struct wiphy *wiphy = NULL;
- struct ifinfomsg *rtmmsg;
- size_t bufsize;
struct l_io *pae_io = NULL;
if (nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
@@ -6283,20 +6340,15 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
l_debug("Created interface %s[%d %" PRIx64 "]", netdev->name,
netdev->index, netdev->wdev_id);
- /* Query interface flags */
- bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg));
- rtmmsg = l_malloc(bufsize);
- memset(rtmmsg, 0, bufsize);
-
- rtmmsg->ifi_family = AF_UNSPEC;
- rtmmsg->ifi_index = ifindex;
-
- l_netlink_send(rtnl, RTM_GETLINK, 0, rtmmsg, bufsize,
- netdev_getlink_cb, NULL, NULL);
+ netdev_setup_interface(netdev);
- l_free(rtmmsg);
+ if (wiphy_disable_power_save(wiphy)) {
+ /* Wait to issue GET_LINK until PS is disabled */
+ if (netdev_disable_power_save(ifindex))
+ return netdev;
+ }
- netdev_setup_interface(netdev);
+ netdev_get_link(ifindex);
return netdev;
}
--
2.25.1
next prev parent reply other threads:[~2023-06-15 19:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-15 19:24 [PATCH 1/7] wiphy: store driver flags directly in wiphy object James Prestwood
2023-06-15 19:24 ` [PATCH 2/7] wiphy: allow for user-defined driver flags James Prestwood
2023-06-18 19:03 ` Denis Kenzior
2023-06-15 19:24 ` [PATCH 3/7] doc: document [DriverFlags] group settings James Prestwood
2023-06-15 19:24 ` [PATCH 4/7] wiphy: add [DriverFlags].PowerSaveDisable flag James Prestwood
2023-06-18 19:07 ` Denis Kenzior
2023-06-19 14:49 ` James Prestwood
2023-06-15 19:24 ` James Prestwood [this message]
2023-06-18 19:11 ` [PATCH 5/7] netdev: disable power save if required Denis Kenzior
2023-06-19 14:54 ` James Prestwood
2023-06-15 19:24 ` [PATCH 6/7] wiphy: print driver flags on startup James Prestwood
2023-06-15 19:24 ` [PATCH 7/7] doc: Document [DriverFlags].PowerSaveDisable James Prestwood
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=20230615192415.1718516-5-prestwoj@gmail.com \
--to=prestwoj@gmail.com \
--cc=iwd@lists.linux.dev \
/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