diff mbox series

[wpan-next,v2,02/27] net: mac802154: Ensure proper channel selection at probe time

Message ID 20220112173312.764660-3-miquel.raynal@bootlin.com (mailing list archive)
State Superseded
Headers show
Series IEEE 802.15.4 scan support | expand

Commit Message

Miquel Raynal Jan. 12, 2022, 5:32 p.m. UTC
Right now device drivers are encouraged to just set the ->current_page
and ->current_channel to indicate about the current state of the
hardware but this is far from ideal given the fact that we might want to
configure a few things internally, such as the symbol duration.

Call the ieee802154_change_channel() helper from the code section
registering the hardware to ensure proper channel selection and
configuration both on the device side and the core side.

This change somehow "fixes" the hwsim driver which advertises using page
0 channel 13, but does not actually update its own internal pib
structure to reflect that configuration.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 net/mac802154/cfg.c          | 3 +--
 net/mac802154/ieee802154_i.h | 1 +
 net/mac802154/main.c         | 8 ++++++++
 3 files changed, 10 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
index 870e442bbff0..6969f1330ccd 100644
--- a/net/mac802154/cfg.c
+++ b/net/mac802154/cfg.c
@@ -102,8 +102,7 @@  ieee802154_del_iface(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev)
 	return 0;
 }
 
-static int
-ieee802154_change_channel(struct wpan_phy *wpan_phy, u8 page, u8 channel)
+int ieee802154_change_channel(struct wpan_phy *wpan_phy, u8 page, u8 channel)
 {
 	struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
 	int ret;
diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h
index 702560acc8ce..8a7f4c83c5b6 100644
--- a/net/mac802154/ieee802154_i.h
+++ b/net/mac802154/ieee802154_i.h
@@ -127,6 +127,7 @@  ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
 netdev_tx_t
 ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
 enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer);
+int ieee802154_change_channel(struct wpan_phy *wpan_phy, u8 page, u8 channel);
 
 /* MIB callbacks */
 void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan);
diff --git a/net/mac802154/main.c b/net/mac802154/main.c
index 520cedc594e1..12ab1545e871 100644
--- a/net/mac802154/main.c
+++ b/net/mac802154/main.c
@@ -157,6 +157,14 @@  int ieee802154_register_hw(struct ieee802154_hw *hw)
 
 	ieee802154_setup_wpan_phy_pib(local->phy);
 
+	/* Ensure proper channel selection */
+	rtnl_lock();
+	rc = ieee802154_change_channel(local->phy, local->phy->current_page,
+				       local->phy->current_channel);
+	rtnl_unlock();
+	if (rc)
+		goto out_wq;
+
 	if (!(hw->flags & IEEE802154_HW_CSMA_PARAMS)) {
 		local->phy->supported.min_csma_backoffs = 4;
 		local->phy->supported.max_csma_backoffs = 4;