wifi: mt76: mt7921: update the channel usage when the regd domain changed
authorMing Yen Hsieh <mingyen.hsieh@mediatek.com>
Sat, 30 Sep 2023 02:25:09 +0000 (10:25 +0800)
committerFelix Fietkau <nbd@nbd.name>
Sat, 30 Sep 2023 18:17:18 +0000 (20:17 +0200)
The 5.9/6GHz channel license of a certain platform device has been
regulated in various countries. That may be difference with standard
Liunx regulatory domain settings. In this case, when .reg_notifier()
called for regulatory change, mt792x chipset should update the channel
usage based on clc or dts configurations.

Channel would be disabled by following cases.
* clc report the particular UNII-x is disabled.
* dts enabled and the channel is not configured.

Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/eeprom.c
drivers/net/wireless/mediatek/mt76/mt76.h
drivers/net/wireless/mediatek/mt76/mt7921/init.c
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c

index 36564930aef121bdd00c95aadaab2a4cf0cf7382..7725dd6763ef26537edeab919c4ee0475d09f11b 100644 (file)
@@ -188,7 +188,7 @@ static bool mt76_string_prop_find(struct property *prop, const char *str)
        return false;
 }
 
-static struct device_node *
+struct device_node *
 mt76_find_power_limits_node(struct mt76_dev *dev)
 {
        struct device_node *np = dev->dev->of_node;
@@ -227,6 +227,7 @@ mt76_find_power_limits_node(struct mt76_dev *dev)
        of_node_put(np);
        return fallback;
 }
+EXPORT_SYMBOL_GPL(mt76_find_power_limits_node);
 
 static const __be32 *
 mt76_get_of_array(struct device_node *np, char *name, size_t *len, int min)
@@ -241,7 +242,7 @@ mt76_get_of_array(struct device_node *np, char *name, size_t *len, int min)
        return prop->value;
 }
 
-static struct device_node *
+struct device_node *
 mt76_find_channel_node(struct device_node *np, struct ieee80211_channel *chan)
 {
        struct device_node *cur;
@@ -265,6 +266,8 @@ mt76_find_channel_node(struct device_node *np, struct ieee80211_channel *chan)
 
        return NULL;
 }
+EXPORT_SYMBOL_GPL(mt76_find_channel_node);
+
 
 static s8
 mt76_get_txs_delta(struct device_node *np, u8 nss)
index fede40cf86b748c735ec3ea36ec0fe2af329f196..3730c5e7d7026b64f3288ad3f305fde014117114 100644 (file)
@@ -1537,6 +1537,11 @@ mt76_mcu_skb_send_msg(struct mt76_dev *dev, struct sk_buff *skb, int cmd,
 
 void mt76_set_irq_mask(struct mt76_dev *dev, u32 addr, u32 clear, u32 set);
 
+struct device_node *
+mt76_find_power_limits_node(struct mt76_dev *dev);
+struct device_node *
+mt76_find_channel_node(struct device_node *np, struct ieee80211_channel *chan);
+
 s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
                              struct ieee80211_channel *chan,
                              struct mt76_power_limits *dest,
index 534c7bee5ef1a407f0a1709938a12339f5077c99..55baac70860b56d04179ec24446ef62644837545 100644 (file)
@@ -58,6 +58,55 @@ 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, 5850, 5925))
+                       ch->flags |= IEEE80211_CHAN_DISABLED;
+       }
+
+       sband = wiphy->bands[NL80211_BAND_6GHZ];
+       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;
+       }
+}
+
 static void
 mt7921_regd_notifier(struct wiphy *wiphy,
                     struct regulatory_request *request)
@@ -74,6 +123,8 @@ mt7921_regd_notifier(struct wiphy *wiphy,
        mt76_connac_mcu_set_channel_domain(hw->priv);
        mt7921_set_tx_sar_pwr(hw, NULL);
        mt792x_mutex_release(dev);
+
+       mt7921_regd_channel_update(wiphy, dev);
 }
 
 int mt7921_mac_init(struct mt792x_dev *dev)
index 4f66e27aa43aa19ddff5ac629289c3bfa27fd029..63f3d4a5c9aa6e9daafc69fbe049c04b91b766ad 100644 (file)
@@ -1247,6 +1247,7 @@ int __mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2,
                         u8 idx)
 {
 #define CLC_CAP_EVT_EN BIT(0)
+#define CLC_CAP_DTS_EN BIT(1)
        struct sk_buff *skb, *ret_skb = NULL;
        struct {
                u8 ver;
@@ -1274,6 +1275,8 @@ int __mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2,
 
        if (dev->phy.chip_cap & MT792x_CHIP_CAP_CLC_EVT_EN)
                req.cap |= CLC_CAP_EVT_EN;
+       if (mt76_find_power_limits_node(&dev->mt76))
+               req.cap |= CLC_CAP_DTS_EN;
 
        pos = clc->data;
        for (i = 0; i < clc->nr_country; i++) {