Skip to content

Commit

Permalink
wifi: mt76: mt7921: update the channel usage when the regd domain cha…
Browse files Browse the repository at this point in the history
…nged

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>
  • Loading branch information
Ming Yen Hsieh authored and nbd168 committed Sep 30, 2023
1 parent 9bfd669 commit 4a0f839
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
7 changes: 5 additions & 2 deletions eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions mt76.h
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,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,
Expand Down
51 changes: 51 additions & 0 deletions mt7921/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions mt7921/mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down

2 comments on commit 4a0f839

@ywt114
Copy link

@ywt114 ywt114 commented on 4a0f839 Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/home/runner/work/test/test/openwrt/build_dir/target-x86_64_musl/linux-x86_64/mt76-2022-12-22-5b509e80/mt7921/mcu.c:16:52: error: expected ')' before 'bool'
16 | module_param_named(disable_clc, mt7921_disable_clc, bool, 0644);
| ^~~~~
| )
/home/runner/work/test/test/openwrt/build_dir/target-x86_64_musl/linux-x86_64/mt76-2022-12-22-5b509e80/mt7921/mcu.c:17:30: error: expected ')' before string constant
17 | MODULE_PARM_DESC(disable_clc, "disable CLC support");
| ^~~~~~~~~~~~~~~~~~~~~~
| )
make[6]: *** [scripts/Makefile.build:262: /home/runner/work/test/test/openwrt/build_dir/target-x86_64_musl/linux-x86_64/mt76-2022-12-22-5b509e80/mt7921/mcu.o] Error 1
make[5]: *** [scripts/Makefile.build:497: /home/runner/work/test/test/openwrt/build_dir/target-x86_64_musl/linux-x86_64/mt76-2022-12-22-5b509e80/mt7921] Error 2
make[4]: *** [Makefile:1750: /home/runner/work/test/test/openwrt/build_dir/target-x86_64_musl/linux-x86_64/mt76-2022-12-22-5b509e80] Error 2
make[3]: *** [Makefile:585: /home/runner/work/test/test/openwrt/build_dir/target-x86_64_musl/linux-x86_64/mt76-2022-12-22-5b509e80/.built] Error 2
make[4]: Leaving directory '/home/runner/work/test/test/openwrt/build_dir/target-x86_64_musl/linux-x86_64/linux-5.4.257'
make[3]: Leaving directory '/home/runner/work/test/test/openwrt/package/kernel/mt76'
time: package/kernel/mt76/compile#2.20#0.46#2.65
ERROR: package/kernel/mt76 failed to build.

@ywt114
Copy link

@ywt114 ywt114 commented on 4a0f839 Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message indicates that there's a problem on line 16 of the mcu.c file, specifically saying: "expected ')' before 'bool'." This error suggests there's a problem with how the parameter is defined. In this case, it might be related to the module_param_named line where the parameter is declared.Would it be better to modify it as follows?

static bool mt7921_disable_clc;
module_param_named(disable_clc, mt7921_disable_clc, bool, 0644);
MODULE_PARM_DESC(disable_clc, "Disable CLC support (0/1)");

Please sign in to comment.