* [PATCH] wifi: mt76: mt7925: add rfkill_poll for hardware rfkill
@ 2025-05-05 7:37 Allan Wang
2025-05-05 9:32 ` Ping-Ke Shih
0 siblings, 1 reply; 2+ messages in thread
From: Allan Wang @ 2025-05-05 7:37 UTC (permalink / raw)
To: nbd, lorenzo
Cc: deren.wu, mingyen.hsieh, Sean.Wang, Soul.Huang, Leon.Yen,
Michael.Lo, Eric-SY.Chang, km.lin, robin.chiu, ch.yeh, posh.sun,
Quan.Zhou, Ryder.Lee, Shayne.Chen, linux-wireless, linux-mediatek,
Allan Wang
Add mac80211 rfkill_poll ops to monitor hardware rfkill state
and state change will be updated.
Signed-off-by: Allan Wang <allan.wang@mediatek.com>
---
.../wireless/mediatek/mt76/mt76_connac_mcu.h | 1 +
.../net/wireless/mediatek/mt76/mt7925/main.c | 16 ++++++++
.../net/wireless/mediatek/mt76/mt7925/mcu.c | 39 +++++++++++++++++++
.../wireless/mediatek/mt76/mt7925/mt7925.h | 1 +
.../net/wireless/mediatek/mt76/mt7925/pci.c | 4 ++
5 files changed, 61 insertions(+)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
index 478cd1886736..e195d69f61f6 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
@@ -1298,6 +1298,7 @@ enum {
MCU_UNI_CMD_PER_STA_INFO = 0x6d,
MCU_UNI_CMD_ALL_STA_INFO = 0x6e,
MCU_UNI_CMD_ASSERT_DUMP = 0x6f,
+ MCU_UNI_CMD_RADIO_STATUS = 0x80,
MCU_UNI_CMD_SDO = 0x88,
};
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
index 83f93f9e002c..65bf9aef2b5e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -334,6 +334,9 @@ int __mt7925_start(struct mt792x_phy *phy)
ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
MT792x_WATCHDOG_TIME);
+ if (phy->chip_cap & MT792x_CHIP_CAP_WF_RF_PIN_CTRL_EVT_EN)
+ wiphy_rfkill_start_polling(mphy->hw->wiphy);
+
return 0;
}
EXPORT_SYMBOL_GPL(__mt7925_start);
@@ -2205,6 +2208,18 @@ static void mt7925_unassign_vif_chanctx(struct ieee80211_hw *hw,
mutex_unlock(&dev->mt76.mutex);
}
+static void mt7925_rfkill_poll(struct ieee80211_hw *hw)
+{
+ struct mt792x_phy *phy = mt792x_hw_phy(hw);
+ int ret = 0;
+
+ mt792x_mutex_acquire(phy->dev);
+ ret = mt7925_mcu_wf_rf_pin_ctrl(phy);
+ mt792x_mutex_release(phy->dev);
+
+ wiphy_rfkill_set_hw_state(hw->wiphy, ret ? false : true);
+}
+
const struct ieee80211_ops mt7925_ops = {
.tx = mt792x_tx,
.start = mt7925_start,
@@ -2265,6 +2280,7 @@ const struct ieee80211_ops mt7925_ops = {
.link_info_changed = mt7925_link_info_changed,
.change_vif_links = mt7925_change_vif_links,
.change_sta_links = mt7925_change_sta_links,
+ .rfkill_poll = mt7925_rfkill_poll,
};
EXPORT_SYMBOL_GPL(mt7925_ops);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
index 286f602623c0..31fa092d2c8c 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
@@ -3633,6 +3633,45 @@ int mt7925_mcu_set_rate_txpower(struct mt76_phy *phy)
return 0;
}
+int mt7925_mcu_wf_rf_pin_ctrl(struct mt792x_phy *phy)
+{
+#define UNI_CMD_RADIO_STATUS_GET 0
+ struct mt792x_dev *dev = phy->dev;
+ struct sk_buff *skb;
+ int ret;
+
+ struct {
+ __le16 tag;
+ __le16 len;
+ u8 rsv[4];
+ } __packed req = {
+ .tag = UNI_CMD_RADIO_STATUS_GET,
+ .len = cpu_to_le16(sizeof(req)),
+ };
+
+ struct mt7925_radio_status_event {
+ __le16 tag;
+ __le16 len;
+
+ u8 data;
+ u8 rsv[3];
+ } __packed * status;
+
+ ret = mt76_mcu_send_and_get_msg(&dev->mt76,
+ MCU_UNI_CMD(RADIO_STATUS),
+ &req, sizeof(req), true, &skb);
+ if (ret)
+ return ret;
+
+ skb_pull(skb, sizeof(struct tlv));
+ status = (struct mt7925_radio_status_event *)skb->data;
+ ret = (int)status->data;
+
+ dev_kfree_skb(skb);
+
+ return ret;
+}
+
int mt7925_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif,
u8 bit_op, u32 bit_map)
{
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
index 4e50f2597ccd..283a40badd28 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
@@ -365,5 +365,6 @@ int mt7925_mcu_wtbl_update_hdr_trans(struct mt792x_dev *dev,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
int link_id);
+int mt7925_mcu_wf_rf_pin_ctrl(struct mt792x_phy *phy);
#endif
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/pci.c b/drivers/net/wireless/mediatek/mt76/mt7925/pci.c
index c7b5dc1dbb34..b997cd8bf8d0 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/pci.c
@@ -31,6 +31,10 @@ static void mt7925e_unregister_device(struct mt792x_dev *dev)
{
int i;
struct mt76_connac_pm *pm = &dev->pm;
+ struct ieee80211_hw *hw = mt76_hw(dev);
+
+ if (dev->phy.chip_cap & MT792x_CHIP_CAP_WF_RF_PIN_CTRL_EVT_EN)
+ wiphy_rfkill_stop_polling(hw->wiphy);
cancel_work_sync(&dev->init_work);
mt76_unregister_device(&dev->mt76);
--
2.45.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: [PATCH] wifi: mt76: mt7925: add rfkill_poll for hardware rfkill
2025-05-05 7:37 [PATCH] wifi: mt76: mt7925: add rfkill_poll for hardware rfkill Allan Wang
@ 2025-05-05 9:32 ` Ping-Ke Shih
0 siblings, 0 replies; 2+ messages in thread
From: Ping-Ke Shih @ 2025-05-05 9:32 UTC (permalink / raw)
To: Allan Wang, nbd@nbd.name, lorenzo@kernel.org
Cc: deren.wu@mediatek.com, mingyen.hsieh@mediatek.com,
Sean.Wang@mediatek.com, Soul.Huang@mediatek.com,
Leon.Yen@mediatek.com, Michael.Lo@mediatek.com,
Eric-SY.Chang@mediatek.com, km.lin@mediatek.com,
robin.chiu@mediatek.com, ch.yeh@mediatek.com,
posh.sun@mediatek.com, Quan.Zhou@mediatek.com,
Ryder.Lee@mediatek.com, Shayne.Chen@mediatek.com,
linux-wireless@vger.kernel.org,
linux-mediatek@lists.infradead.org
Allan Wang <allan.wang@mediatek.com> wrote:
[...]
> @@ -2205,6 +2208,18 @@ static void mt7925_unassign_vif_chanctx(struct ieee80211_hw *hw,
> mutex_unlock(&dev->mt76.mutex);
> }
>
> +static void mt7925_rfkill_poll(struct ieee80211_hw *hw)
> +{
> + struct mt792x_phy *phy = mt792x_hw_phy(hw);
> + int ret = 0;
no need initializer.
> +
> + mt792x_mutex_acquire(phy->dev);
> + ret = mt7925_mcu_wf_rf_pin_ctrl(phy);
> + mt792x_mutex_release(phy->dev);
> +
> + wiphy_rfkill_set_hw_state(hw->wiphy, ret ? false : true);
wiphy_rfkill_set_hw_state(hw->wiphy, ret == 0);
or
wiphy_rfkill_set_hw_state(hw->wiphy, !ret);
> +}
> +
> const struct ieee80211_ops mt7925_ops = {
> .tx = mt792x_tx,
> .start = mt7925_start,
> @@ -2265,6 +2280,7 @@ const struct ieee80211_ops mt7925_ops = {
> .link_info_changed = mt7925_link_info_changed,
> .change_vif_links = mt7925_change_vif_links,
> .change_sta_links = mt7925_change_sta_links,
> + .rfkill_poll = mt7925_rfkill_poll,
> };
> EXPORT_SYMBOL_GPL(mt7925_ops);
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
> b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
> index 286f602623c0..31fa092d2c8c 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
> @@ -3633,6 +3633,45 @@ int mt7925_mcu_set_rate_txpower(struct mt76_phy *phy)
> return 0;
> }
>
> +int mt7925_mcu_wf_rf_pin_ctrl(struct mt792x_phy *phy)
> +{
> +#define UNI_CMD_RADIO_STATUS_GET 0
> + struct mt792x_dev *dev = phy->dev;
> + struct sk_buff *skb;
> + int ret;
> +
Should avoid empty line in declarations?
> + struct {
> + __le16 tag;
> + __le16 len;
> + u8 rsv[4];
> + } __packed req = {
> + .tag = UNI_CMD_RADIO_STATUS_GET,
> + .len = cpu_to_le16(sizeof(req)),
> + };
> +
> + struct mt7925_radio_status_event {
> + __le16 tag;
> + __le16 len;
> +
> + u8 data;
> + u8 rsv[3];
> + } __packed * status;
I remember this should be "__packed *status", but checkpatch reports
false-alarm.
> +
> + ret = mt76_mcu_send_and_get_msg(&dev->mt76,
> + MCU_UNI_CMD(RADIO_STATUS),
> + &req, sizeof(req), true, &skb);
> + if (ret)
> + return ret;
> +
> + skb_pull(skb, sizeof(struct tlv));
> + status = (struct mt7925_radio_status_event *)skb->data;
> + ret = (int)status->data;
I feel int casting is unnecessary.
> +
> + dev_kfree_skb(skb);
> +
> + return ret;
> +}
> +
> int mt7925_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif,
> u8 bit_op, u32 bit_map)
> {
[...]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-05-05 9:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-05 7:37 [PATCH] wifi: mt76: mt7925: add rfkill_poll for hardware rfkill Allan Wang
2025-05-05 9:32 ` Ping-Ke Shih
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).