]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: mt76: mt7921: refactor regulatory domain handling to regd.[ch]
authorJB Tsai <jb.tsai@mediatek.com>
Tue, 3 Mar 2026 05:36:33 +0000 (13:36 +0800)
committerFelix Fietkau <nbd@nbd.name>
Tue, 9 Jun 2026 10:20:43 +0000 (10:20 +0000)
Move regd logic to regd.c and regd.h files

Co-developed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: JB Tsai <jb.tsai@mediatek.com>
Link: https://patch.msgid.link/20260303053637.465465-1-jb.tsai@mediatek.com
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7921/Makefile
drivers/net/wireless/mediatek/mt76/mt7921/init.c
drivers/net/wireless/mediatek/mt76/mt7921/main.c
drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
drivers/net/wireless/mediatek/mt76/mt7921/pci.c
drivers/net/wireless/mediatek/mt76/mt7921/regd.c [new file with mode: 0644]
drivers/net/wireless/mediatek/mt76/mt7921/regd.h [new file with mode: 0644]

index 2ad3c1cc3779878986068ff9c0071ed867819eb7..3ef7c9c453869c16ebe496cd1c6c42ee1dcbaf4e 100644 (file)
@@ -5,7 +5,7 @@ obj-$(CONFIG_MT7921E) += mt7921e.o
 obj-$(CONFIG_MT7921S) += mt7921s.o
 obj-$(CONFIG_MT7921U) += mt7921u.o
 
-mt7921-common-y := mac.o mcu.o main.o init.o debugfs.o
+mt7921-common-y := mac.o mcu.o regd.o main.o init.o debugfs.o
 mt7921-common-$(CONFIG_NL80211_TESTMODE) += testmode.o
 mt7921e-y := pci.o pci_mac.o pci_mcu.o
 mt7921s-y := sdio.o sdio_mac.o sdio_mcu.o
index 8e779070219187d1c0dc65e3b143b1fe3b0c95e1..49be2fa4e3fa178e03764fb03c627413b8967c86 100644 (file)
@@ -9,6 +9,7 @@
 #include "mt7921.h"
 #include "../mt76_connac2_mac.h"
 #include "mcu.h"
+#include "regd.h"
 
 static ssize_t mt7921_thermal_temp_show(struct device *dev,
                                        struct device_attribute *attr,
@@ -60,103 +61,6 @@ static int mt7921_thermal_init(struct mt792x_phy *phy)
        return PTR_ERR_OR_ZERO(hwmon);
 }
 
-static void
-mt7921_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev)
-{
-#define IS_UNII_INVALID(idx, sfreq, efreq) \
-       (!(dev->phy.clc_chan_conf & BIT(idx)) && (cfreq) >= (sfreq) && (cfreq) <= (efreq))
-       struct ieee80211_supported_band *sband;
-       struct mt76_dev *mdev = &dev->mt76;
-       struct device_node *np, *band_np;
-       struct ieee80211_channel *ch;
-       int i, cfreq;
-
-       np = mt76_find_power_limits_node(mdev);
-
-       sband = wiphy->bands[NL80211_BAND_5GHZ];
-       band_np = np ? of_get_child_by_name(np, "txpower-5g") : NULL;
-       for (i = 0; i < sband->n_channels; i++) {
-               ch = &sband->channels[i];
-               cfreq = ch->center_freq;
-
-               if (np && (!band_np || !mt76_find_channel_node(band_np, ch))) {
-                       ch->flags |= IEEE80211_CHAN_DISABLED;
-                       continue;
-               }
-
-               /* UNII-4 */
-               if (IS_UNII_INVALID(0, 5845, 5925))
-                       ch->flags |= IEEE80211_CHAN_DISABLED;
-       }
-
-       sband = wiphy->bands[NL80211_BAND_6GHZ];
-       if (!sband)
-               return;
-
-       band_np = np ? of_get_child_by_name(np, "txpower-6g") : NULL;
-       for (i = 0; i < sband->n_channels; i++) {
-               ch = &sband->channels[i];
-               cfreq = ch->center_freq;
-
-               if (np && (!band_np || !mt76_find_channel_node(band_np, ch))) {
-                       ch->flags |= IEEE80211_CHAN_DISABLED;
-                       continue;
-               }
-
-               /* UNII-5/6/7/8 */
-               if (IS_UNII_INVALID(1, 5925, 6425) ||
-                   IS_UNII_INVALID(2, 6425, 6525) ||
-                   IS_UNII_INVALID(3, 6525, 6875) ||
-                   IS_UNII_INVALID(4, 6875, 7125))
-                       ch->flags |= IEEE80211_CHAN_DISABLED;
-       }
-}
-
-void mt7921_regd_update(struct mt792x_dev *dev)
-{
-       struct mt76_dev *mdev = &dev->mt76;
-       struct ieee80211_hw *hw = mdev->hw;
-       struct wiphy *wiphy = hw->wiphy;
-
-       mt7921_mcu_set_clc(dev, mdev->alpha2, dev->country_ie_env);
-       mt7921_regd_channel_update(wiphy, dev);
-       mt76_connac_mcu_set_channel_domain(hw->priv);
-       mt7921_set_tx_sar_pwr(hw, NULL);
-}
-EXPORT_SYMBOL_GPL(mt7921_regd_update);
-
-static void
-mt7921_regd_notifier(struct wiphy *wiphy,
-                    struct regulatory_request *request)
-{
-       struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
-       struct mt792x_dev *dev = mt792x_hw_dev(hw);
-       struct mt76_connac_pm *pm = &dev->pm;
-
-       memcpy(dev->mt76.alpha2, request->alpha2, sizeof(dev->mt76.alpha2));
-       dev->mt76.region = request->dfs_region;
-       dev->country_ie_env = request->country_ie_env;
-
-       if (request->initiator == NL80211_REGDOM_SET_BY_USER) {
-               if (dev->mt76.alpha2[0] == '0' && dev->mt76.alpha2[1] == '0')
-                       wiphy->regulatory_flags &= ~REGULATORY_COUNTRY_IE_IGNORE;
-               else
-                       wiphy->regulatory_flags |= REGULATORY_COUNTRY_IE_IGNORE;
-       }
-
-       if (pm->suspended)
-               return;
-
-       dev->regd_in_progress = true;
-
-       mt792x_mutex_acquire(dev);
-       mt7921_regd_update(dev);
-       mt792x_mutex_release(dev);
-
-       dev->regd_in_progress = false;
-       wake_up(&dev->wait);
-}
-
 int mt7921_mac_init(struct mt792x_dev *dev)
 {
        int i;
index 6ffccc023728033b789ed455cb96cc41bbd544f7..4ac26391a721782eab67b66bb773a7ee97c3d8ca 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/module.h>
 #include <net/ipv6.h>
 #include "mt7921.h"
+#include "regd.h"
 #include "mcu.h"
 
 static int
index 64f60c4fc60c886864e83e5f9bafc9ecb11d5573..fb8654b7c5e7e713abbb989e3fee15dc93c20e2a 100644 (file)
@@ -260,7 +260,6 @@ mt7921_l1_rmw(struct mt792x_dev *dev, u32 addr, u32 mask, u32 val)
 #define mt7921_l1_set(dev, addr, val)  mt7921_l1_rmw(dev, addr, 0, val)
 #define mt7921_l1_clear(dev, addr, val)        mt7921_l1_rmw(dev, addr, val, 0)
 
-void mt7921_regd_update(struct mt792x_dev *dev);
 int mt7921_mac_init(struct mt792x_dev *dev);
 bool mt7921_mac_wtbl_update(struct mt792x_dev *dev, int idx, u32 mask);
 int mt7921_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
index 49a37185f0564ec69cd46e93ffecc8128d925461..7ac0ca07278d46dd50a1ccec86640a785741c5a7 100644 (file)
@@ -12,6 +12,7 @@
 #include "../mt76_connac2_mac.h"
 #include "../dma.h"
 #include "mcu.h"
+#include "regd.h"
 
 static const struct pci_device_id mt7921_pci_device_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_MEDIATEK, 0x7961),
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/regd.c b/drivers/net/wireless/mediatek/mt76/mt7921/regd.c
new file mode 100644 (file)
index 0000000..51dbbad
--- /dev/null
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: BSD-3-Clause-Clear
+/* Copyright (C) 2025 MediaTek Inc. */
+
+#include <linux/of.h>
+#include "mt7921.h"
+#include "regd.h"
+#include "mcu.h"
+
+static void
+mt7921_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev)
+{
+#define IS_UNII_INVALID(idx, sfreq, efreq) \
+       (!(dev->phy.clc_chan_conf & BIT(idx)) && (cfreq) >= (sfreq) && (cfreq) <= (efreq))
+       struct ieee80211_supported_band *sband;
+       struct mt76_dev *mdev = &dev->mt76;
+       struct device_node *np, *band_np;
+       struct ieee80211_channel *ch;
+       int i, cfreq;
+
+       np = mt76_find_power_limits_node(mdev);
+
+       sband = wiphy->bands[NL80211_BAND_5GHZ];
+       band_np = np ? of_get_child_by_name(np, "txpower-5g") : NULL;
+       for (i = 0; i < sband->n_channels; i++) {
+               ch = &sband->channels[i];
+               cfreq = ch->center_freq;
+
+               if (np && (!band_np || !mt76_find_channel_node(band_np, ch))) {
+                       ch->flags |= IEEE80211_CHAN_DISABLED;
+                       continue;
+               }
+
+               /* UNII-4 */
+               if (IS_UNII_INVALID(0, 5845, 5925))
+                       ch->flags |= IEEE80211_CHAN_DISABLED;
+       }
+
+       sband = wiphy->bands[NL80211_BAND_6GHZ];
+       if (!sband)
+               return;
+
+       band_np = np ? of_get_child_by_name(np, "txpower-6g") : NULL;
+       for (i = 0; i < sband->n_channels; i++) {
+               ch = &sband->channels[i];
+               cfreq = ch->center_freq;
+
+               if (np && (!band_np || !mt76_find_channel_node(band_np, ch))) {
+                       ch->flags |= IEEE80211_CHAN_DISABLED;
+                       continue;
+               }
+
+               /* UNII-5/6/7/8 */
+               if (IS_UNII_INVALID(1, 5925, 6425) ||
+                   IS_UNII_INVALID(2, 6425, 6525) ||
+                   IS_UNII_INVALID(3, 6525, 6875) ||
+                   IS_UNII_INVALID(4, 6875, 7125))
+                       ch->flags |= IEEE80211_CHAN_DISABLED;
+       }
+}
+
+void mt7921_regd_update(struct mt792x_dev *dev)
+{
+       struct mt76_dev *mdev = &dev->mt76;
+       struct ieee80211_hw *hw = mdev->hw;
+       struct wiphy *wiphy = hw->wiphy;
+
+       mt7921_mcu_set_clc(dev, mdev->alpha2, dev->country_ie_env);
+       mt7921_regd_channel_update(wiphy, dev);
+       mt76_connac_mcu_set_channel_domain(hw->priv);
+       mt7921_set_tx_sar_pwr(hw, NULL);
+}
+EXPORT_SYMBOL_GPL(mt7921_regd_update);
+
+void mt7921_regd_notifier(struct wiphy *wiphy,
+                         struct regulatory_request *request)
+{
+       struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
+       struct mt792x_dev *dev = mt792x_hw_dev(hw);
+       struct mt76_connac_pm *pm = &dev->pm;
+
+       memcpy(dev->mt76.alpha2, request->alpha2, sizeof(dev->mt76.alpha2));
+       dev->mt76.region = request->dfs_region;
+       dev->country_ie_env = request->country_ie_env;
+
+       if (request->initiator == NL80211_REGDOM_SET_BY_USER) {
+               if (dev->mt76.alpha2[0] == '0' && dev->mt76.alpha2[1] == '0')
+                       wiphy->regulatory_flags &= ~REGULATORY_COUNTRY_IE_IGNORE;
+               else
+                       wiphy->regulatory_flags |= REGULATORY_COUNTRY_IE_IGNORE;
+       }
+
+       if (pm->suspended)
+               return;
+
+       dev->regd_in_progress = true;
+
+       mt792x_mutex_acquire(dev);
+       mt7921_regd_update(dev);
+       mt792x_mutex_release(dev);
+
+       dev->regd_in_progress = false;
+       wake_up(&dev->wait);
+}
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/regd.h b/drivers/net/wireless/mediatek/mt76/mt7921/regd.h
new file mode 100644 (file)
index 0000000..2907b78
--- /dev/null
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: BSD-3-Clause-Clear */
+/* Copyright (C) 2025 MediaTek Inc. */
+
+#ifndef __MT7921_REGD_H
+#define __MT7921_REGD_H
+
+struct mt792x_dev;
+struct wiphy;
+struct regulatory_request;
+
+void mt7921_regd_update(struct mt792x_dev *dev);
+void mt7921_regd_notifier(struct wiphy *wiphy,
+                         struct regulatory_request *request);
+
+#endif