Skip to content

Commit 09382d8

Browse files
Ming Yen Hsiehnbd168
authored andcommitted
wifi: mt76: mt7921: update the channel usage when the regd domain changed
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 <[email protected]> Co-developed-by: Deren Wu <[email protected]> Signed-off-by: Deren Wu <[email protected]> Signed-off-by: Felix Fietkau <[email protected]>
1 parent 4fc8df5 commit 09382d8

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

drivers/net/wireless/mediatek/mt76/eeprom.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static bool mt76_string_prop_find(struct property *prop, const char *str)
188188
return false;
189189
}
190190

191-
static struct device_node *
191+
struct device_node *
192192
mt76_find_power_limits_node(struct mt76_dev *dev)
193193
{
194194
struct device_node *np = dev->dev->of_node;
@@ -227,6 +227,7 @@ mt76_find_power_limits_node(struct mt76_dev *dev)
227227
of_node_put(np);
228228
return fallback;
229229
}
230+
EXPORT_SYMBOL_GPL(mt76_find_power_limits_node);
230231

231232
static const __be32 *
232233
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)
241242
return prop->value;
242243
}
243244

244-
static struct device_node *
245+
struct device_node *
245246
mt76_find_channel_node(struct device_node *np, struct ieee80211_channel *chan)
246247
{
247248
struct device_node *cur;
@@ -265,6 +266,8 @@ mt76_find_channel_node(struct device_node *np, struct ieee80211_channel *chan)
265266

266267
return NULL;
267268
}
269+
EXPORT_SYMBOL_GPL(mt76_find_channel_node);
270+
268271

269272
static s8
270273
mt76_get_txs_delta(struct device_node *np, u8 nss)

drivers/net/wireless/mediatek/mt76/mt76.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,11 @@ mt76_mcu_skb_send_msg(struct mt76_dev *dev, struct sk_buff *skb, int cmd,
15371537

15381538
void mt76_set_irq_mask(struct mt76_dev *dev, u32 addr, u32 clear, u32 set);
15391539

1540+
struct device_node *
1541+
mt76_find_power_limits_node(struct mt76_dev *dev);
1542+
struct device_node *
1543+
mt76_find_channel_node(struct device_node *np, struct ieee80211_channel *chan);
1544+
15401545
s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
15411546
struct ieee80211_channel *chan,
15421547
struct mt76_power_limits *dest,

drivers/net/wireless/mediatek/mt76/mt7921/init.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,55 @@ static int mt7921_thermal_init(struct mt792x_phy *phy)
5858
return PTR_ERR_OR_ZERO(hwmon);
5959
}
6060

61+
static void
62+
mt7921_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev)
63+
{
64+
#define IS_UNII_INVALID(idx, sfreq, efreq) \
65+
(!(dev->phy.clc_chan_conf & BIT(idx)) && (cfreq) >= (sfreq) && (cfreq) <= (efreq))
66+
struct ieee80211_supported_band *sband;
67+
struct mt76_dev *mdev = &dev->mt76;
68+
struct device_node *np, *band_np;
69+
struct ieee80211_channel *ch;
70+
int i, cfreq;
71+
72+
np = mt76_find_power_limits_node(mdev);
73+
74+
sband = wiphy->bands[NL80211_BAND_5GHZ];
75+
band_np = np ? of_get_child_by_name(np, "txpower-5g") : NULL;
76+
for (i = 0; i < sband->n_channels; i++) {
77+
ch = &sband->channels[i];
78+
cfreq = ch->center_freq;
79+
80+
if (np && (!band_np || !mt76_find_channel_node(band_np, ch))) {
81+
ch->flags |= IEEE80211_CHAN_DISABLED;
82+
continue;
83+
}
84+
85+
/* UNII-4 */
86+
if (IS_UNII_INVALID(0, 5850, 5925))
87+
ch->flags |= IEEE80211_CHAN_DISABLED;
88+
}
89+
90+
sband = wiphy->bands[NL80211_BAND_6GHZ];
91+
band_np = np ? of_get_child_by_name(np, "txpower-6g") : NULL;
92+
for (i = 0; i < sband->n_channels; i++) {
93+
ch = &sband->channels[i];
94+
cfreq = ch->center_freq;
95+
96+
if (np && (!band_np || !mt76_find_channel_node(band_np, ch))) {
97+
ch->flags |= IEEE80211_CHAN_DISABLED;
98+
continue;
99+
}
100+
101+
/* UNII-5/6/7/8 */
102+
if (IS_UNII_INVALID(1, 5925, 6425) ||
103+
IS_UNII_INVALID(2, 6425, 6525) ||
104+
IS_UNII_INVALID(3, 6525, 6875) ||
105+
IS_UNII_INVALID(4, 6875, 7125))
106+
ch->flags |= IEEE80211_CHAN_DISABLED;
107+
}
108+
}
109+
61110
static void
62111
mt7921_regd_notifier(struct wiphy *wiphy,
63112
struct regulatory_request *request)
@@ -74,6 +123,8 @@ mt7921_regd_notifier(struct wiphy *wiphy,
74123
mt76_connac_mcu_set_channel_domain(hw->priv);
75124
mt7921_set_tx_sar_pwr(hw, NULL);
76125
mt792x_mutex_release(dev);
126+
127+
mt7921_regd_channel_update(wiphy, dev);
77128
}
78129

79130
int mt7921_mac_init(struct mt792x_dev *dev)

drivers/net/wireless/mediatek/mt76/mt7921/mcu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,7 @@ int __mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2,
12471247
u8 idx)
12481248
{
12491249
#define CLC_CAP_EVT_EN BIT(0)
1250+
#define CLC_CAP_DTS_EN BIT(1)
12501251
struct sk_buff *skb, *ret_skb = NULL;
12511252
struct {
12521253
u8 ver;
@@ -1274,6 +1275,8 @@ int __mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2,
12741275

12751276
if (dev->phy.chip_cap & MT792x_CHIP_CAP_CLC_EVT_EN)
12761277
req.cap |= CLC_CAP_EVT_EN;
1278+
if (mt76_find_power_limits_node(&dev->mt76))
1279+
req.cap |= CLC_CAP_DTS_EN;
12771280

12781281
pos = clc->data;
12791282
for (i = 0; i < clc->nr_country; i++) {

0 commit comments

Comments
 (0)