* [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type
@ 2025-03-04 6:28 Mingyen Hsieh
2025-03-04 6:28 ` [PATCH v2 2/6] wifi: mt76: mt7925: add EHT control support based on the CLC data Mingyen Hsieh
` (5 more replies)
0 siblings, 6 replies; 15+ messages in thread
From: Mingyen Hsieh @ 2025-03-04 6:28 UTC (permalink / raw)
To: nbd, lorenzo
Cc: deren.wu, Sean.Wang, Leon.Yen, Michael.Lo, allan.wang,
Eric-SY.Chang, km.lin, Quan.Zhou, Ryder.Lee, Shayne.Chen,
linux-wireless, linux-mediatek, Ming Yen Hsieh
From: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Read the EEPROM to determine the hardware type and uses this to load the
correct CLC data.
Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
---
v2: no change
---
.../net/wireless/mediatek/mt76/mt7925/mcu.c | 61 ++++++++++++++++++-
.../wireless/mediatek/mt76/mt7925/mt7925.h | 3 +
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
index d4fac7c2d0e6..505a6467f147 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
@@ -800,6 +800,54 @@ int mt7925_mcu_uni_rx_ba(struct mt792x_dev *dev,
enable, false);
}
+static int mt7925_mcu_read_eeprom(struct mt792x_dev *dev, u32 offset, u8 *val)
+{
+ struct {
+ u8 rsv[4];
+
+ __le16 tag;
+ __le16 len;
+
+ __le32 addr;
+ __le32 valid;
+ u8 data[MT7925_EEPROM_BLOCK_SIZE];
+ } __packed req = {
+ .tag = cpu_to_le16(1),
+ .len = cpu_to_le16(sizeof(req) - 4),
+ .addr = cpu_to_le32(round_down(offset,
+ MT7925_EEPROM_BLOCK_SIZE)),
+ };
+ struct evt {
+ u8 rsv[4];
+
+ __le16 tag;
+ __le16 len;
+
+ __le32 ver;
+ __le32 addr;
+ __le32 valid;
+ __le32 size;
+ __le32 magic_num;
+ __le32 type;
+ __le32 rsv1[4];
+ u8 data[32];
+ } __packed * res;
+ struct sk_buff *skb;
+ int ret;
+
+ ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_WM_UNI_CMD_QUERY(EFUSE_CTRL),
+ &req, sizeof(req), true, &skb);
+ if (ret)
+ return ret;
+
+ res = (struct evt *)skb->data;
+ *val = res->data[offset % MT7925_EEPROM_BLOCK_SIZE];
+
+ dev_kfree_skb(skb);
+
+ return 0;
+}
+
static int mt7925_load_clc(struct mt792x_dev *dev, const char *fw_name)
{
const struct mt76_connac2_fw_trailer *hdr;
@@ -809,12 +857,19 @@ static int mt7925_load_clc(struct mt792x_dev *dev, const char *fw_name)
struct mt792x_phy *phy = &dev->phy;
const struct firmware *fw;
int ret, i, len, offset = 0;
- u8 *clc_base = NULL;
+ u8 *clc_base = NULL, hw_encap = 0;
if (mt7925_disable_clc ||
mt76_is_usb(&dev->mt76))
return 0;
+ if (mt76_is_mmio(&dev->mt76)) {
+ ret = mt7925_mcu_read_eeprom(dev, MT_EE_HW_TYPE, &hw_encap);
+ if (ret)
+ return ret;
+ hw_encap = u8_get_bits(hw_encap, MT_EE_HW_TYPE_ENCAP);
+ }
+
ret = request_firmware(&fw, fw_name, mdev->dev);
if (ret)
return ret;
@@ -859,6 +914,10 @@ static int mt7925_load_clc(struct mt792x_dev *dev, const char *fw_name)
if (phy->clc[clc->idx])
continue;
+ /* header content sanity */
+ if (u8_get_bits(clc->type, MT_EE_HW_TYPE_ENCAP) != hw_encap)
+ continue;
+
phy->clc[clc->idx] = devm_kmemdup(mdev->dev, clc,
le32_to_cpu(clc->len),
GFP_KERNEL);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
index 3f7187309513..abecaf897159 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
@@ -167,9 +167,12 @@ enum mt7925_eeprom_field {
MT_EE_CHIP_ID = 0x000,
MT_EE_VERSION = 0x002,
MT_EE_MAC_ADDR = 0x004,
+ MT_EE_HW_TYPE = 0xa71,
__MT_EE_MAX = 0x9ff
};
+#define MT_EE_HW_TYPE_ENCAP GENMASK(1, 0)
+
enum {
TXPWR_USER,
TXPWR_EEPROM,
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 2/6] wifi: mt76: mt7925: add EHT control support based on the CLC data 2025-03-04 6:28 [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type Mingyen Hsieh @ 2025-03-04 6:28 ` Mingyen Hsieh 2025-03-04 9:10 ` Ping-Ke Shih 2025-03-04 6:28 ` [PATCH v2 3/6] wifi: mt76: mt7925: update the channel usage when the regd domain changed Mingyen Hsieh ` (4 subsequent siblings) 5 siblings, 1 reply; 15+ messages in thread From: Mingyen Hsieh @ 2025-03-04 6:28 UTC (permalink / raw) To: nbd, lorenzo Cc: deren.wu, Sean.Wang, Leon.Yen, Michael.Lo, allan.wang, Eric-SY.Chang, km.lin, Quan.Zhou, Ryder.Lee, Shayne.Chen, linux-wireless, linux-mediatek, Ming Yen Hsieh From: Ming Yen Hsieh <mingyen.hsieh@mediatek.com> Some countries do not support EHT modulation for now. To prevent violating regulations, the MT7925 chipset should control the EHT capabilities. Therefore, when a regulatory domain change is detected during scanning, the `mt7925_regd_be_ctrl` will process the CLC data to update the EHT capabilities. Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com> --- v2: no change --- .../net/wireless/mediatek/mt76/mt7925/init.c | 38 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7925/main.c | 3 ++ .../net/wireless/mediatek/mt76/mt7925/mcu.c | 10 +++-- .../wireless/mediatek/mt76/mt7925/mt7925.h | 27 +++++++++++-- drivers/net/wireless/mediatek/mt76/mt792x.h | 1 + 5 files changed, 72 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/init.c b/drivers/net/wireless/mediatek/mt76/mt7925/init.c index b40d979f1b65..94d7b762fe40 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/init.c @@ -58,6 +58,44 @@ static int mt7925_thermal_init(struct mt792x_phy *phy) return PTR_ERR_OR_ZERO(hwmon); } +void mt7925_regd_be_ctrl(struct mt792x_dev *dev, u8 *alpha2) +{ + struct mt792x_phy *phy = &dev->phy; + struct mt7925_clc_rule_v2 *rule; + struct mt7925_clc *clc; + bool old = dev->has_eht, new = true; + u8 *pos; + + if (!phy->clc[MT792x_CLC_BE_CTRL]) + goto out; + + clc = (struct mt7925_clc *)phy->clc[MT792x_CLC_BE_CTRL]; + pos = clc->data; + + while (1) { + rule = (struct mt7925_clc_rule_v2 *)pos; + + if (rule->alpha2[0] == alpha2[0] && + rule->alpha2[1] == alpha2[1]) { + new = false; + break; + } + + /* Check the last one */ + if (rule->flag && BIT(0)) + break; + + pos += sizeof(*rule); + } + +out: + if (old == new) + return; + + dev->has_eht = new; + mt7925_set_stream_he_eht_caps(phy); +} + void mt7925_regd_update(struct mt792x_dev *dev) { struct mt76_dev *mdev = &dev->mt76; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c index cefb9068fa72..80aa7f329cf8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c @@ -1449,6 +1449,9 @@ void mt7925_scan_work(struct work_struct *work) if (!is_valid_alpha2(evt->alpha2)) break; + if (memcmp(evt->alpha2, mdev->alpha2, 2)) + mt7925_regd_be_ctrl(phy->dev, evt->alpha2); + if (mdev->alpha2[0] != '0' && mdev->alpha2[1] != '0') break; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c index 505a6467f147..e73320c5d8c0 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c @@ -915,7 +915,9 @@ static int mt7925_load_clc(struct mt792x_dev *dev, const char *fw_name) continue; /* header content sanity */ - if (u8_get_bits(clc->type, MT_EE_HW_TYPE_ENCAP) != hw_encap) + if ((clc->idx == MT792x_CLC_BE_CTRL && + u8_get_bits(clc->t2.type, MT_EE_HW_TYPE_ENCAP) != hw_encap) || + u8_get_bits(clc->t0.type, MT_EE_HW_TYPE_ENCAP) != hw_encap) continue; phy->clc[clc->idx] = devm_kmemdup(mdev->dev, clc, @@ -1024,7 +1026,6 @@ mt7925_mcu_parse_phy_cap(struct mt792x_dev *dev, char *data) mdev->phy.chainmask = mdev->phy.antenna_mask; mdev->phy.cap.has_2ghz = cap->hw_path & BIT(WF0_24G); mdev->phy.cap.has_5ghz = cap->hw_path & BIT(WF0_5G); - dev->has_eht = cap->eht; } static void @@ -3427,7 +3428,7 @@ __mt7925_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, if (!clc) return 0; - pos = clc->data + sizeof(*seg) * clc->nr_seg; + pos = clc->data + sizeof(*seg) * clc->t0.nr_seg; last_pos = clc->data + le32_to_cpu(*(__le32 *)(clc->data + 4)); while (pos < last_pos) { struct mt7925_clc_rule *rule = (struct mt7925_clc_rule *)pos; @@ -3473,6 +3474,9 @@ int mt7925_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, /* submit all clc config */ for (i = 0; i < ARRAY_SIZE(phy->clc); i++) { + if (i == MT792x_CLC_BE_CTRL) + continue; + ret = __mt7925_mcu_set_clc(dev, alpha2, env_cap, phy->clc[i], i); diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h index abecaf897159..e6ca9021f487 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h @@ -137,6 +137,12 @@ enum { MT7925_CLC_MAX_NUM, }; +struct mt7925_clc_rule_v2 { + u32 flag; + u8 alpha2[2]; + u8 rsv[10]; +} __packed; + struct mt7925_clc_rule { u8 alpha2[2]; u8 type[2]; @@ -152,14 +158,26 @@ struct mt7925_clc_segment { u8 rsv2[4]; } __packed; -struct mt7925_clc { - __le32 len; - u8 idx; - u8 ver; +struct mt7925_clc_type0 { u8 nr_country; u8 type; u8 nr_seg; u8 rsv[7]; +} __packed; + +struct mt7925_clc_type2 { + u8 type; + u8 rsv[9]; +} __packed; + +struct mt7925_clc { + __le32 len; + u8 idx; + u8 ver; + union { + struct mt7925_clc_type0 t0; + struct mt7925_clc_type2 t2; + }; u8 data[]; } __packed; @@ -239,6 +257,7 @@ int mt7925_mcu_chip_configv2(struct mt792x_dev *dev, const char *cmd); int mt7925_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif, u8 bit_op, u32 bit_map); +void mt7925_regd_be_ctrl(struct mt792x_dev *dev, u8 *alpha2); void mt7925_regd_update(struct mt792x_dev *dev); int mt7925_mac_init(struct mt792x_dev *dev); int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h index 281df43d9060..85f07f936be5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x.h +++ b/drivers/net/wireless/mediatek/mt76/mt792x.h @@ -71,6 +71,7 @@ struct mt792x_fw_features { enum { MT792x_CLC_POWER, MT792x_CLC_POWER_EXT, + MT792x_CLC_BE_CTRL, MT792x_CLC_MAX_NUM, }; -- 2.34.1 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* RE: [PATCH v2 2/6] wifi: mt76: mt7925: add EHT control support based on the CLC data 2025-03-04 6:28 ` [PATCH v2 2/6] wifi: mt76: mt7925: add EHT control support based on the CLC data Mingyen Hsieh @ 2025-03-04 9:10 ` Ping-Ke Shih 2025-03-04 9:34 ` Mingyen Hsieh (謝明諺) 0 siblings, 1 reply; 15+ messages in thread From: Ping-Ke Shih @ 2025-03-04 9:10 UTC (permalink / raw) To: Mingyen Hsieh, nbd@nbd.name, lorenzo@kernel.org Cc: deren.wu@mediatek.com, Sean.Wang@mediatek.com, Leon.Yen@mediatek.com, Michael.Lo@mediatek.com, allan.wang@mediatek.com, Eric-SY.Chang@mediatek.com, km.lin@mediatek.com, Quan.Zhou@mediatek.com, Ryder.Lee@mediatek.com, Shayne.Chen@mediatek.com, linux-wireless@vger.kernel.org, linux-mediatek@lists.infradead.org Mingyen Hsieh <mingyen.hsieh@mediatek.com> wrote: [...] > > +void mt7925_regd_be_ctrl(struct mt792x_dev *dev, u8 *alpha2) > +{ > + struct mt792x_phy *phy = &dev->phy; > + struct mt7925_clc_rule_v2 *rule; > + struct mt7925_clc *clc; > + bool old = dev->has_eht, new = true; > + u8 *pos; > + > + if (!phy->clc[MT792x_CLC_BE_CTRL]) > + goto out; > + > + clc = (struct mt7925_clc *)phy->clc[MT792x_CLC_BE_CTRL]; > + pos = clc->data; > + > + while (1) { while (1) could lead infinite loop unexpectedly. Adding a checking of clc->len would be safer. > + rule = (struct mt7925_clc_rule_v2 *)pos; > + > + if (rule->alpha2[0] == alpha2[0] && > + rule->alpha2[1] == alpha2[1]) { > + new = false; > + break; > + } > + > + /* Check the last one */ > + if (rule->flag && BIT(0)) > + break; > + > + pos += sizeof(*rule); > + } > + > +out: > + if (old == new) > + return; > + > + dev->has_eht = new; > + mt7925_set_stream_he_eht_caps(phy); > +} > + [...] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 2/6] wifi: mt76: mt7925: add EHT control support based on the CLC data 2025-03-04 9:10 ` Ping-Ke Shih @ 2025-03-04 9:34 ` Mingyen Hsieh (謝明諺) 2025-03-05 1:21 ` Ping-Ke Shih 0 siblings, 1 reply; 15+ messages in thread From: Mingyen Hsieh (謝明諺) @ 2025-03-04 9:34 UTC (permalink / raw) To: nbd@nbd.name, pkshih@realtek.com, lorenzo@kernel.org Cc: Allan Wang (王家偉), Eric-SY Chang (張書源), Deren Wu (武德仁), Ryder Lee, Quan Zhou (周全), Michael Lo (羅璧章), Shayne Chen (陳軒丞), Sean Wang, Leon Yen (顏良儒), KM Lin (林昆民), linux-mediatek@lists.infradead.org, linux-wireless@vger.kernel.org On Tue, 2025-03-04 at 09:10 +0000, Ping-Ke Shih wrote: > > External email : Please do not click links or open attachments until > you have verified the sender or the content. > > > Mingyen Hsieh <mingyen.hsieh@mediatek.com> wrote: > > [...] > > > > > +void mt7925_regd_be_ctrl(struct mt792x_dev *dev, u8 *alpha2) > > +{ > > + struct mt792x_phy *phy = &dev->phy; > > + struct mt7925_clc_rule_v2 *rule; > > + struct mt7925_clc *clc; > > + bool old = dev->has_eht, new = true; > > + u8 *pos; > > + > > + if (!phy->clc[MT792x_CLC_BE_CTRL]) > > + goto out; > > + > > + clc = (struct mt7925_clc *)phy->clc[MT792x_CLC_BE_CTRL]; > > + pos = clc->data; > > + > > + while (1) { > > while (1) could lead infinite loop unexpectedly. > Adding a checking of clc->len would be safer. > > > + rule = (struct mt7925_clc_rule_v2 *)pos; > > + > > + if (rule->alpha2[0] == alpha2[0] && > > + rule->alpha2[1] == alpha2[1]) { > > + new = false; > > + break; > > + } > > + > > + /* Check the last one */ > > + if (rule->flag && BIT(0)) > > + break; > > + Hi Ping-Ke, I designed a flag to prevent the infinite loop. > > + pos += sizeof(*rule); > > + } > > + > > +out: > > + if (old == new) > > + return; > > + > > + dev->has_eht = new; > > + mt7925_set_stream_he_eht_caps(phy); > > +} > > + > > [...] > ^ permalink raw reply [flat|nested] 15+ messages in thread
* RE: [PATCH v2 2/6] wifi: mt76: mt7925: add EHT control support based on the CLC data 2025-03-04 9:34 ` Mingyen Hsieh (謝明諺) @ 2025-03-05 1:21 ` Ping-Ke Shih 2025-03-05 9:32 ` Mingyen Hsieh (謝明諺) 0 siblings, 1 reply; 15+ messages in thread From: Ping-Ke Shih @ 2025-03-05 1:21 UTC (permalink / raw) To: Mingyen Hsieh (謝明諺), nbd@nbd.name, lorenzo@kernel.org Cc: Allan Wang (王家偉), Eric-SY Chang (張書源), Deren Wu (武德仁), Ryder Lee, Quan Zhou (周全), Michael Lo (羅璧章), Shayne Chen (陳軒丞), Sean Wang, Leon Yen (顏良儒), KM Lin (林昆民), linux-mediatek@lists.infradead.org, linux-wireless@vger.kernel.org Mingyen Hsieh (謝明諺) <Mingyen.Hsieh@mediatek.com> wrote: > On Tue, 2025-03-04 at 09:10 +0000, Ping-Ke Shih wrote: > > Mingyen Hsieh <mailto:mingyen.hsieh@mediatek.com> wrote: > > > > [...] > > > > > > > > +void mt7925_regd_be_ctrl(struct mt792x_dev *dev, u8 *alpha2) > > > +{ > > > + struct mt792x_phy *phy = &dev->phy; > > > + struct mt7925_clc_rule_v2 *rule; > > > + struct mt7925_clc *clc; > > > + bool old = dev->has_eht, new = true; > > > + u8 *pos; > > > + > > > + if (!phy->clc[MT792x_CLC_BE_CTRL]) > > > + goto out; > > > + > > > + clc = (struct mt7925_clc *)phy->clc[MT792x_CLC_BE_CTRL]; > > > + pos = clc->data; > > > + > > > + while (1) { > > > > while (1) could lead infinite loop unexpectedly. > > Adding a checking of clc->len would be safer. > > > > > + rule = (struct mt7925_clc_rule_v2 *)pos; > > > + > > > + if (rule->alpha2[0] == alpha2[0] && > > > + rule->alpha2[1] == alpha2[1]) { > > > + new = false; > > > + break; > > > + } > > > + > > > + /* Check the last one */ > > > + if (rule->flag && BIT(0)) > > > + break; > > > + > > Hi Ping-Ke, > > I designed a flag to prevent the infinite loop. I knew. People believe their code is safe, but somehow `while (1)` get unexpected result. An alternative way is to use for-loop with limit range, like clc_end = &clc->data[clc->len]; for (pos = clc->data; pos < clc_end; pos += sizeof(*rule)) Just FYR. > > > > + pos += sizeof(*rule); > > > + } > > > + > > > +out: > > > + if (old == new) > > > + return; > > > + > > > + dev->has_eht = new; > > > + mt7925_set_stream_he_eht_caps(phy); > > > +} > > > + > > > > [...] > > > ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 2/6] wifi: mt76: mt7925: add EHT control support based on the CLC data 2025-03-05 1:21 ` Ping-Ke Shih @ 2025-03-05 9:32 ` Mingyen Hsieh (謝明諺) 2025-03-06 0:41 ` Ping-Ke Shih 0 siblings, 1 reply; 15+ messages in thread From: Mingyen Hsieh (謝明諺) @ 2025-03-05 9:32 UTC (permalink / raw) To: nbd@nbd.name, pkshih@realtek.com, lorenzo@kernel.org Cc: Allan Wang (王家偉), Shayne Chen (陳軒丞), Eric-SY Chang (張書源), Ryder Lee, Quan Zhou (周全), Deren Wu (武德仁), Michael Lo (羅璧章), linux-wireless@vger.kernel.org, Sean Wang, Leon Yen (顏良儒), KM Lin (林昆民), linux-mediatek@lists.infradead.org On Wed, 2025-03-05 at 01:21 +0000, Ping-Ke Shih wrote: > > External email : Please do not click links or open attachments until > you have verified the sender or the content. > > > Mingyen Hsieh (謝明諺) <Mingyen.Hsieh@mediatek.com> wrote: > > On Tue, 2025-03-04 at 09:10 +0000, Ping-Ke Shih wrote: > > > Mingyen Hsieh <mailto:mingyen.hsieh@mediatek.com> wrote: > > > > > > [...] > > > > > > > > > > > +void mt7925_regd_be_ctrl(struct mt792x_dev *dev, u8 *alpha2) > > > > +{ > > > > + struct mt792x_phy *phy = &dev->phy; > > > > + struct mt7925_clc_rule_v2 *rule; > > > > + struct mt7925_clc *clc; > > > > + bool old = dev->has_eht, new = true; > > > > + u8 *pos; > > > > + > > > > + if (!phy->clc[MT792x_CLC_BE_CTRL]) > > > > + goto out; > > > > + > > > > + clc = (struct mt7925_clc *)phy- > > > > >clc[MT792x_CLC_BE_CTRL]; > > > > + pos = clc->data; > > > > + > > > > + while (1) { > > > > > > while (1) could lead infinite loop unexpectedly. > > > Adding a checking of clc->len would be safer. > > > > > > > + rule = (struct mt7925_clc_rule_v2 *)pos; > > > > + > > > > + if (rule->alpha2[0] == alpha2[0] && > > > > + rule->alpha2[1] == alpha2[1]) { > > > > + new = false; > > > > + break; > > > > + } > > > > + > > > > + /* Check the last one */ > > > > + if (rule->flag && BIT(0)) > > > > + break; > > > > + > > > > Hi Ping-Ke, > > > > I designed a flag to prevent the infinite loop. > > I knew. > > People believe their code is safe, but somehow `while (1)` get > unexpected > result. An alternative way is to use for-loop with limit range, like > > clc_end = &clc->data[clc->len]; > > for (pos = clc->data; pos < clc_end; pos += sizeof(*rule)) > > Just FYR. > Ok. I got it. Thanks for the suggestions. Perhaps i will modify it in the next version. > > > > > > + pos += sizeof(*rule); > > > > + } > > > > + > > > > +out: > > > > + if (old == new) > > > > + return; > > > > + > > > > + dev->has_eht = new; > > > > + mt7925_set_stream_he_eht_caps(phy); > > > > +} > > > > + > > > > > > [...] > > > > > ^ permalink raw reply [flat|nested] 15+ messages in thread
* RE: [PATCH v2 2/6] wifi: mt76: mt7925: add EHT control support based on the CLC data 2025-03-05 9:32 ` Mingyen Hsieh (謝明諺) @ 2025-03-06 0:41 ` Ping-Ke Shih 0 siblings, 0 replies; 15+ messages in thread From: Ping-Ke Shih @ 2025-03-06 0:41 UTC (permalink / raw) To: Mingyen Hsieh (謝明諺), nbd@nbd.name, lorenzo@kernel.org Cc: Allan Wang (王家偉), Shayne Chen (陳軒丞), Eric-SY Chang (張書源), Ryder Lee, Quan Zhou (周全), Deren Wu (武德仁), Michael Lo (羅璧章), linux-wireless@vger.kernel.org, Sean Wang, Leon Yen (顏良儒), KM Lin (林昆民), linux-mediatek@lists.infradead.org Mingyen Hsieh (謝明諺) <Mingyen.Hsieh@mediatek.com> wrote: > On Wed, 2025-03-05 at 01:21 +0000, Ping-Ke Shih wrote: > > > > External email : Please do not click links or open attachments until > > you have verified the sender or the content. > > > > > > Mingyen Hsieh (謝明諺) <mailto:Mingyen.Hsieh@mediatek.com> wrote: > > > On Tue, 2025-03-04 at 09:10 +0000, Ping-Ke Shih wrote: > > > > Mingyen Hsieh <mailto:mingyen.hsieh@mediatek.com> wrote: > > > > > > > > [...] > > > > > > > > > > > > > > +void mt7925_regd_be_ctrl(struct mt792x_dev *dev, u8 *alpha2) > > > > > +{ > > > > > + struct mt792x_phy *phy = &dev->phy; > > > > > + struct mt7925_clc_rule_v2 *rule; > > > > > + struct mt7925_clc *clc; > > > > > + bool old = dev->has_eht, new = true; > > > > > + u8 *pos; > > > > > + > > > > > + if (!phy->clc[MT792x_CLC_BE_CTRL]) > > > > > + goto out; > > > > > + > > > > > + clc = (struct mt7925_clc *)phy- > > > > > >clc[MT792x_CLC_BE_CTRL]; > > > > > + pos = clc->data; > > > > > + > > > > > + while (1) { > > > > > > > > while (1) could lead infinite loop unexpectedly. > > > > Adding a checking of clc->len would be safer. > > > > > > > > > + rule = (struct mt7925_clc_rule_v2 *)pos; > > > > > + > > > > > + if (rule->alpha2[0] == alpha2[0] && > > > > > + rule->alpha2[1] == alpha2[1]) { > > > > > + new = false; > > > > > + break; > > > > > + } > > > > > + > > > > > + /* Check the last one */ > > > > > + if (rule->flag && BIT(0)) > > > > > + break; > > > > > + > > > > > > Hi Ping-Ke, > > > > > > I designed a flag to prevent the infinite loop. > > > > I knew. > > > > People believe their code is safe, but somehow `while (1)` get > > unexpected > > result. An alternative way is to use for-loop with limit range, like > > > > clc_end = &clc->data[clc->len]; > > > > for (pos = clc->data; pos < clc_end; pos += sizeof(*rule)) > > > > Just FYR. > > > > Ok. I got it. Thanks for the suggestions. > Perhaps i will modify it in the next version. > Good. :-) By the way, could you check if you replied in plain text mode? From my outlook, it looks like in html mode, but patchwork can recognize it well [1]. [1] https://patchwork.kernel.org/project/linux-wireless/patch/20250304062854.829194-2-mingyen.hsieh@mediatek.com/ > > > > > > > > + pos += sizeof(*rule); > > > > > + } > > > > > + > > > > > +out: > > > > > + if (old == new) > > > > > + return; > > > > > + > > > > > + dev->has_eht = new; > > > > > + mt7925_set_stream_he_eht_caps(phy); > > > > > +} > > > > > + > > > > > > > > [...] > > > > > > > > ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 3/6] wifi: mt76: mt7925: update the channel usage when the regd domain changed 2025-03-04 6:28 [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type Mingyen Hsieh 2025-03-04 6:28 ` [PATCH v2 2/6] wifi: mt76: mt7925: add EHT control support based on the CLC data Mingyen Hsieh @ 2025-03-04 6:28 ` Mingyen Hsieh 2025-03-04 9:13 ` Ping-Ke Shih 2025-03-04 6:28 ` [PATCH v2 4/6] wifi: mt76: mt7925: remove unused acpi function for clc Mingyen Hsieh ` (3 subsequent siblings) 5 siblings, 1 reply; 15+ messages in thread From: Mingyen Hsieh @ 2025-03-04 6:28 UTC (permalink / raw) To: nbd, lorenzo Cc: deren.wu, Sean.Wang, Leon.Yen, Michael.Lo, allan.wang, Eric-SY.Chang, km.lin, Quan.Zhou, Ryder.Lee, Shayne.Chen, linux-wireless, linux-mediatek, Ming Yen Hsieh From: Ming Yen Hsieh <mingyen.hsieh@mediatek.com> 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, mt7925 chipset should update the channel usage based on CLC data. Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com> --- v2: no change --- .../net/wireless/mediatek/mt76/mt7925/init.c | 42 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7925/mcu.c | 7 +++- .../wireless/mediatek/mt76/mt7925/mt7925.h | 3 +- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/init.c b/drivers/net/wireless/mediatek/mt76/mt7925/init.c index 94d7b762fe40..8561ab310f16 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/init.c @@ -96,15 +96,57 @@ void mt7925_regd_be_ctrl(struct mt792x_dev *dev, u8 *alpha2) mt7925_set_stream_he_eht_caps(phy); } +static void +mt7925_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 ieee80211_channel *ch; + int i, cfreq; + + sband = wiphy->bands[NL80211_BAND_5GHZ]; + if (!sband) + return; + + for (i = 0; i < sband->n_channels; i++) { + ch = &sband->channels[i]; + cfreq = ch->center_freq; + + /* UNII-4 */ + if (IS_UNII_INVALID(0, 5845, 5925)) + ch->flags |= IEEE80211_CHAN_DISABLED; + } + + sband = wiphy->bands[NL80211_BAND_6GHZ]; + if (!sband) + return; + + for (i = 0; i < sband->n_channels; i++) { + ch = &sband->channels[i]; + cfreq = ch->center_freq; + + /* 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 mt7925_regd_update(struct mt792x_dev *dev) { struct mt76_dev *mdev = &dev->mt76; struct ieee80211_hw *hw = mdev->hw; + struct wiphy *wiphy = hw->wiphy; if (!dev->regd_change) return; mt7925_mcu_set_clc(dev, mdev->alpha2, dev->country_ie_env); + mt7925_regd_channel_update(wiphy, dev); mt7925_mcu_set_channel_domain(hw->priv); mt7925_set_tx_sar_pwr(hw, NULL); dev->regd_change = false; diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c index e73320c5d8c0..602ac3c31976 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c @@ -859,6 +859,7 @@ static int mt7925_load_clc(struct mt792x_dev *dev, const char *fw_name) int ret, i, len, offset = 0; u8 *clc_base = NULL, hw_encap = 0; + dev->phy.clc_chan_conf = 0xff; if (mt7925_disable_clc || mt76_is_usb(&dev->mt76)) return 0; @@ -3428,6 +3429,7 @@ __mt7925_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, if (!clc) return 0; + req.ver = clc->ver; pos = clc->data + sizeof(*seg) * clc->t0.nr_seg; last_pos = clc->data + le32_to_cpu(*(__le32 *)(clc->data + 4)); while (pos < last_pos) { @@ -3445,6 +3447,7 @@ __mt7925_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, memcpy(req.type, rule->type, 2); req.size = cpu_to_le16(seg->len); + dev->phy.clc_chan_conf = clc->ver == 1 ? 0xff : rule->flag; skb = __mt76_mcu_msg_alloc(&dev->mt76, &req, le16_to_cpu(req.size) + sizeof(req), sizeof(req), GFP_KERNEL); @@ -3460,8 +3463,10 @@ __mt7925_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, valid_cnt++; } - if (!valid_cnt) + if (!valid_cnt) { + dev->phy.clc_chan_conf = 0xff; return -ENOENT; + } return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h index e6ca9021f487..71811734592c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h @@ -147,7 +147,8 @@ struct mt7925_clc_rule { u8 alpha2[2]; u8 type[2]; u8 seg_idx; - u8 rsv[3]; + u8 flag; /* UNII4~8 ctrl flag */ + u8 rsv[2]; } __packed; struct mt7925_clc_segment { -- 2.34.1 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* RE: [PATCH v2 3/6] wifi: mt76: mt7925: update the channel usage when the regd domain changed 2025-03-04 6:28 ` [PATCH v2 3/6] wifi: mt76: mt7925: update the channel usage when the regd domain changed Mingyen Hsieh @ 2025-03-04 9:13 ` Ping-Ke Shih 0 siblings, 0 replies; 15+ messages in thread From: Ping-Ke Shih @ 2025-03-04 9:13 UTC (permalink / raw) To: Mingyen Hsieh, nbd@nbd.name, lorenzo@kernel.org Cc: deren.wu@mediatek.com, Sean.Wang@mediatek.com, Leon.Yen@mediatek.com, Michael.Lo@mediatek.com, allan.wang@mediatek.com, Eric-SY.Chang@mediatek.com, km.lin@mediatek.com, Quan.Zhou@mediatek.com, Ryder.Lee@mediatek.com, Shayne.Chen@mediatek.com, linux-wireless@vger.kernel.org, linux-mediatek@lists.infradead.org Mingyen Hsieh <mingyen.hsieh@mediatek.com> wrote: [...] > +static void > +mt7925_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)) Implicitly using 'cfreq' would be missing something by reviewers. How about adding it as an argument of macro? > + struct ieee80211_supported_band *sband; > + struct mt76_dev *mdev = &dev->mt76; > + struct ieee80211_channel *ch; > + int i, cfreq; > + > + sband = wiphy->bands[NL80211_BAND_5GHZ]; > + if (!sband) > + return; > + > + for (i = 0; i < sband->n_channels; i++) { > + ch = &sband->channels[i]; > + cfreq = ch->center_freq; > + > + /* UNII-4 */ > + if (IS_UNII_INVALID(0, 5845, 5925)) > + ch->flags |= IEEE80211_CHAN_DISABLED; > + } > + > + sband = wiphy->bands[NL80211_BAND_6GHZ]; > + if (!sband) > + return; > + > + for (i = 0; i < sband->n_channels; i++) { > + ch = &sband->channels[i]; > + cfreq = ch->center_freq; > + > + /* 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; > + } > +} > + [...] ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 4/6] wifi: mt76: mt7925: remove unused acpi function for clc 2025-03-04 6:28 [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type Mingyen Hsieh 2025-03-04 6:28 ` [PATCH v2 2/6] wifi: mt76: mt7925: add EHT control support based on the CLC data Mingyen Hsieh 2025-03-04 6:28 ` [PATCH v2 3/6] wifi: mt76: mt7925: update the channel usage when the regd domain changed Mingyen Hsieh @ 2025-03-04 6:28 ` Mingyen Hsieh 2025-03-04 6:28 ` [PATCH v2 5/6] wifi: mt76: mt792x: extend MTCL of APCI to version3 for EHT control Mingyen Hsieh ` (2 subsequent siblings) 5 siblings, 0 replies; 15+ messages in thread From: Mingyen Hsieh @ 2025-03-04 6:28 UTC (permalink / raw) To: nbd, lorenzo Cc: deren.wu, Sean.Wang, Leon.Yen, Michael.Lo, allan.wang, Eric-SY.Chang, km.lin, Quan.Zhou, Ryder.Lee, Shayne.Chen, linux-wireless, linux-mediatek, Ming Yen Hsieh, stable From: Ming Yen Hsieh <mingyen.hsieh@mediatek.com> The code for handling ACPI configuration in CLC was copied from the mt7921 driver but is not utilized in the mt7925 implementation. So removes the unused functionality to clean up the codebase. Cc: stable@vger.kernel.org Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips") Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com> --- v2: no change --- drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c index 602ac3c31976..3fd75216889f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c @@ -3421,7 +3421,6 @@ __mt7925_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, .idx = idx, .env = env_cap, - .acpi_conf = mt792x_acpi_get_flags(&dev->phy), }; int ret, valid_cnt = 0; u8 *pos, *last_pos; -- 2.34.1 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 5/6] wifi: mt76: mt792x: extend MTCL of APCI to version3 for EHT control 2025-03-04 6:28 [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type Mingyen Hsieh ` (2 preceding siblings ...) 2025-03-04 6:28 ` [PATCH v2 4/6] wifi: mt76: mt7925: remove unused acpi function for clc Mingyen Hsieh @ 2025-03-04 6:28 ` Mingyen Hsieh 2025-03-04 6:28 ` [PATCH v2 6/6] wifi: mt76: mt7925: add MTCL support to enhance the reulatory compliance Mingyen Hsieh 2025-03-04 9:06 ` [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type Ping-Ke Shih 5 siblings, 0 replies; 15+ messages in thread From: Mingyen Hsieh @ 2025-03-04 6:28 UTC (permalink / raw) To: nbd, lorenzo Cc: deren.wu, Sean.Wang, Leon.Yen, Michael.Lo, allan.wang, Eric-SY.Chang, km.lin, Quan.Zhou, Ryder.Lee, Shayne.Chen, linux-wireless, linux-mediatek, Ming Yen Hsieh From: Ming Yen Hsieh <mingyen.hsieh@mediatek.com> This patch introduces version 3 of the MTCL table, which provides regulatory information for WiFi 7. It also configured by the platform vender like the version 1 and 2. Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com> --- v2: mt792x_acpi_parse_mtcl_tbl_v3 should return the config of "depends on driver" when bios support mtcl v2 only --- drivers/net/wireless/mediatek/mt76/mt792x.h | 6 +- .../wireless/mediatek/mt76/mt792x_acpi_sar.c | 101 ++++++++++++++---- .../wireless/mediatek/mt76/mt792x_acpi_sar.h | 40 ++++++- 3 files changed, 120 insertions(+), 27 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h index 85f07f936be5..d43e5d93dd85 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x.h +++ b/drivers/net/wireless/mediatek/mt76/mt792x.h @@ -525,7 +525,7 @@ int mt792xe_mcu_fw_pmctrl(struct mt792x_dev *dev); int mt792x_init_acpi_sar(struct mt792x_dev *dev); int mt792x_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default); u8 mt792x_acpi_get_flags(struct mt792x_phy *phy); -u8 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2); +u32 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2); #else static inline int mt792x_init_acpi_sar(struct mt792x_dev *dev) { @@ -543,9 +543,9 @@ static inline u8 mt792x_acpi_get_flags(struct mt792x_phy *phy) return 0; } -static inline u8 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2) +static inline u32 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2) { - return 0xf; + return MT792X_ACPI_MTCL_INVALID; } #endif diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c b/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c index 9317f8ff2070..fac53e62687b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c +++ b/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c @@ -66,13 +66,22 @@ mt792x_acpi_read(struct mt792x_dev *dev, u8 *method, u8 **tbl, u32 *len) } /* MTCL : Country List Table for 6G band */ +/* MTCL : Country List Table for 6G band and 11BE */ static int mt792x_asar_acpi_read_mtcl(struct mt792x_dev *dev, u8 **table, u8 *version) { - int ret; + int len, ret; - *version = ((ret = mt792x_acpi_read(dev, MT792x_ACPI_MTCL, table, NULL)) < 0) - ? 1 : 2; + ret = mt792x_acpi_read(dev, MT792x_ACPI_MTCL, table, &len); + if (ret) + return ret; + + if (len == sizeof(struct mt792x_asar_cl)) + *version = ((struct mt792x_asar_cl *)*table)->version; + else if (len == sizeof(struct mt792x_asar_cl_v3)) + *version = ((struct mt792x_asar_cl_v3 *)*table)->version; + else + return -EINVAL; return ret; } @@ -351,10 +360,24 @@ u8 mt792x_acpi_get_flags(struct mt792x_phy *phy) } EXPORT_SYMBOL_GPL(mt792x_acpi_get_flags); -static u8 +static u32 +mt792x_acpi_get_mtcl_map_v3(int row, int column, struct mt792x_asar_cl_v3 *cl) +{ + u32 config = 0; + u8 mode_be = 0; + + mode_be = (cl->mode_be > 0x02) ? 0 : cl->mode_be; + + if (cl->version > 2 && cl->clbe[row] & BIT(column)) + config |= (mode_be & 0x3) << 4; + + return config; +} + +static u32 mt792x_acpi_get_mtcl_map(int row, int column, struct mt792x_asar_cl *cl) { - u8 config = 0; + u32 config = 0; u8 mode_6g, mode_5g9; mode_6g = (cl->mode_6g > 0x02) ? 0 : cl->mode_6g; @@ -368,30 +391,44 @@ mt792x_acpi_get_mtcl_map(int row, int column, struct mt792x_asar_cl *cl) return config; } -u8 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2) +static u32 +mt792x_acpi_parse_mtcl_tbl_v3(struct mt792x_phy *phy, char *alpha2) { - static const char * const cc_list_all[] = { - "00", "EU", "AR", "AU", "AZ", "BY", "BO", "BR", - "CA", "CL", "CN", "ID", "JP", "MY", "MX", "ME", - "MA", "NZ", "NG", "PH", "RU", "RS", "SG", "KR", - "TW", "TH", "UA", "GB", "US", "VN", "KH", "PY", - }; - static const char * const cc_list_eu[] = { - "AT", "BE", "BG", "CY", "CZ", "HR", "DK", "EE", - "FI", "FR", "DE", "GR", "HU", "IS", "IE", "IT", - "LV", "LI", "LT", "LU", "MT", "NL", "NO", "PL", - "PT", "RO", "SK", "SI", "ES", "SE", "CH", - }; struct mt792x_acpi_sar *sar = phy->acpisar; - struct mt792x_asar_cl *cl; + struct mt792x_asar_cl_v3 *cl = sar->countrylist_v3; int col, row, i; - if (!sar) - return 0xf; + if (sar->ver != 3) + goto out; + + if (!cl) + return MT792X_ACPI_MTCL_INVALID; + + for (i = 0; i < ARRAY_SIZE(cc_list_be); i++) { + col = 7 - i % 8; + row = i / 8; + if (!memcmp(cc_list_be[i], alpha2, 2)) + return mt792x_acpi_get_mtcl_map_v3(row, col, cl); + } + for (i = 0; i < ARRAY_SIZE(cc_list_eu); i++) { + if (!memcmp(cc_list_eu[i], alpha2, 2)) + return mt792x_acpi_get_mtcl_map_v3(3, 7, cl); + } + +out: + /* Depends on driver */ + return 0x20; +} + +static u32 +mt792x_acpi_parse_mtcl_tbl(struct mt792x_phy *phy, char *alpha2) +{ + struct mt792x_acpi_sar *sar = phy->acpisar; + struct mt792x_asar_cl *cl = sar->countrylist; + int col, row, i; - cl = sar->countrylist; if (!cl) - return 0xc; + return MT792X_ACPI_MTCL_INVALID; for (i = 0; i < ARRAY_SIZE(cc_list_all); i++) { col = 7 - i % 8; @@ -406,4 +443,22 @@ u8 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2) return mt792x_acpi_get_mtcl_map(0, 7, cl); } + +u32 mt792x_acpi_get_mtcl_conf(struct mt792x_phy *phy, char *alpha2) +{ + struct mt792x_acpi_sar *sar = phy->acpisar; + u32 config = 0; + + if (!sar) + return MT792X_ACPI_MTCL_INVALID; + + config = mt792x_acpi_parse_mtcl_tbl_v3(phy, alpha2); + + if (config == MT792X_ACPI_MTCL_INVALID) + return MT792X_ACPI_MTCL_INVALID; + + config |= mt792x_acpi_parse_mtcl_tbl(phy, alpha2); + + return config; +} EXPORT_SYMBOL_GPL(mt792x_acpi_get_mtcl_conf); diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.h b/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.h index 2298983b6342..cf15571dcb82 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.h +++ b/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.h @@ -15,6 +15,30 @@ #define MT792x_ACPI_MTGS "MTGS" #define MT792x_ACPI_MTFG "MTFG" +#define MT792X_ACPI_MTCL_INVALID 0xffffffff + +static const char * const cc_list_all[] = { + "00", "EU", "AR", "AU", "AZ", "BY", "BO", "BR", + "CA", "CL", "CN", "ID", "JP", "MY", "MX", "ME", + "MA", "NZ", "NG", "PH", "RU", "RS", "SG", "KR", + "TW", "TH", "UA", "GB", "US", "VN", "KH", "PY", +}; + +static const char * const cc_list_eu[] = { + "AD", "AT", "BE", "BG", "CY", "CZ", "HR", "DK", + "EE", "FI", "FR", "DE", "GR", "HU", "IS", "IE", + "IT", "LV", "LI", "LT", "LU", "MC", "MT", "NL", + "NO", "PL", "PT", "RO", "SK", "SI", "ES", "SE", + "CH", +}; + +static const char * const cc_list_be[] = { + "AR", "BR", "BY", "CL", "IQ", "MX", "OM", "RU", + "RW", "VN", "KR", "UA", "", "", "", "", + "EU", "AT", "CN", "CA", "TW", "NZ", "PH", "UK", + "US", +}; + struct mt792x_asar_dyn_limit { u8 idx; u8 frp[5]; @@ -72,6 +96,17 @@ struct mt792x_asar_geo_v2 { DECLARE_FLEX_ARRAY(struct mt792x_asar_geo_limit_v2, tbl); } __packed; +struct mt792x_asar_cl_v3 { + u8 names[4]; + u8 version; + u8 mode_6g; + u8 cl6g[6]; + u8 mode_5g9; + u8 cl5g9[6]; + u8 mode_be; + u8 clbe[6]; +} __packed; + struct mt792x_asar_cl { u8 names[4]; u8 version; @@ -100,7 +135,10 @@ struct mt792x_acpi_sar { struct mt792x_asar_geo *geo; struct mt792x_asar_geo_v2 *geo_v2; }; - struct mt792x_asar_cl *countrylist; + union { + struct mt792x_asar_cl *countrylist; + struct mt792x_asar_cl_v3 *countrylist_v3; + }; struct mt792x_asar_fg *fg; }; -- 2.34.1 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 6/6] wifi: mt76: mt7925: add MTCL support to enhance the reulatory compliance 2025-03-04 6:28 [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type Mingyen Hsieh ` (3 preceding siblings ...) 2025-03-04 6:28 ` [PATCH v2 5/6] wifi: mt76: mt792x: extend MTCL of APCI to version3 for EHT control Mingyen Hsieh @ 2025-03-04 6:28 ` Mingyen Hsieh 2025-03-04 9:06 ` [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type Ping-Ke Shih 5 siblings, 0 replies; 15+ messages in thread From: Mingyen Hsieh @ 2025-03-04 6:28 UTC (permalink / raw) To: nbd, lorenzo Cc: deren.wu, Sean.Wang, Leon.Yen, Michael.Lo, allan.wang, Eric-SY.Chang, km.lin, Quan.Zhou, Ryder.Lee, Shayne.Chen, linux-wireless, linux-mediatek, Ming Yen Hsieh From: Ming Yen Hsieh <mingyen.hsieh@mediatek.com> Apply the MTCL configuration to improving channel availability and regulatory compliance if MTCL table is supported. Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com> --- v2: no change --- .../net/wireless/mediatek/mt76/mt7925/init.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/init.c b/drivers/net/wireless/mediatek/mt76/mt7925/init.c index 8561ab310f16..1bd30a857be5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/init.c @@ -64,8 +64,15 @@ void mt7925_regd_be_ctrl(struct mt792x_dev *dev, u8 *alpha2) struct mt7925_clc_rule_v2 *rule; struct mt7925_clc *clc; bool old = dev->has_eht, new = true; + u32 mtcl_conf = mt792x_acpi_get_mtcl_conf(&dev->phy, alpha2); u8 *pos; + if (mtcl_conf != MT792X_ACPI_MTCL_INVALID && + (((mtcl_conf >> 4) & 0x3) == 0)) { + new = false; + goto out; + } + if (!phy->clc[MT792x_CLC_BE_CTRL]) goto out; @@ -101,11 +108,21 @@ mt7925_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)) +#define MT7925_UNII_59G_IS_VALID 0x1 +#define MT7925_UNII_6G_IS_VALID 0x1e struct ieee80211_supported_band *sband; struct mt76_dev *mdev = &dev->mt76; struct ieee80211_channel *ch; + u32 mtcl_conf = mt792x_acpi_get_mtcl_conf(&dev->phy, mdev->alpha2); int i, cfreq; + if (mtcl_conf != MT792X_ACPI_MTCL_INVALID) { + if ((mtcl_conf & 0x3) == 0) + dev->phy.clc_chan_conf &= ~MT7925_UNII_59G_IS_VALID; + if (((mtcl_conf >> 2) & 0x3) == 0) + dev->phy.clc_chan_conf &= ~MT7925_UNII_6G_IS_VALID; + } + sband = wiphy->bands[NL80211_BAND_5GHZ]; if (!sband) return; -- 2.34.1 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* RE: [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type 2025-03-04 6:28 [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type Mingyen Hsieh ` (4 preceding siblings ...) 2025-03-04 6:28 ` [PATCH v2 6/6] wifi: mt76: mt7925: add MTCL support to enhance the reulatory compliance Mingyen Hsieh @ 2025-03-04 9:06 ` Ping-Ke Shih 2025-03-04 9:37 ` Mingyen Hsieh (謝明諺) 5 siblings, 1 reply; 15+ messages in thread From: Ping-Ke Shih @ 2025-03-04 9:06 UTC (permalink / raw) To: Mingyen Hsieh, nbd@nbd.name, lorenzo@kernel.org Cc: deren.wu@mediatek.com, Sean.Wang@mediatek.com, Leon.Yen@mediatek.com, Michael.Lo@mediatek.com, allan.wang@mediatek.com, Eric-SY.Chang@mediatek.com, km.lin@mediatek.com, Quan.Zhou@mediatek.com, Ryder.Lee@mediatek.com, Shayne.Chen@mediatek.com, linux-wireless@vger.kernel.org, linux-mediatek@lists.infradead.org Mingyen Hsieh <mingyen.hsieh@mediatek.com> wrote: [...] > + struct evt { > + u8 rsv[4]; > + > + __le16 tag; > + __le16 len; > + > + __le32 ver; > + __le32 addr; > + __le32 valid; > + __le32 size; > + __le32 magic_num; > + __le32 type; > + __le32 rsv1[4]; > + u8 data[32]; > + } __packed * res; nit: no need space between * and res, i.e. "__packed *res". > + struct sk_buff *skb; > + int ret; > + > + ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_WM_UNI_CMD_QUERY(EFUSE_CTRL), > + &req, sizeof(req), true, &skb); > + if (ret) > + return ret; > + > + res = (struct evt *)skb->data; > + *val = res->data[offset % MT7925_EEPROM_BLOCK_SIZE]; > + > + dev_kfree_skb(skb); > + > + return 0; > +} > + > static int mt7925_load_clc(struct mt792x_dev *dev, const char *fw_name) > { > const struct mt76_connac2_fw_trailer *hdr; > @@ -809,12 +857,19 @@ static int mt7925_load_clc(struct mt792x_dev *dev, const char *fw_name) > struct mt792x_phy *phy = &dev->phy; > const struct firmware *fw; > int ret, i, len, offset = 0; > - u8 *clc_base = NULL; > + u8 *clc_base = NULL, hw_encap = 0; not sure if mt76 declare local variables in reverse X'mas tree order? ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type 2025-03-04 9:06 ` [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type Ping-Ke Shih @ 2025-03-04 9:37 ` Mingyen Hsieh (謝明諺) 2025-03-05 1:00 ` Ping-Ke Shih 0 siblings, 1 reply; 15+ messages in thread From: Mingyen Hsieh (謝明諺) @ 2025-03-04 9:37 UTC (permalink / raw) To: nbd@nbd.name, pkshih@realtek.com, lorenzo@kernel.org Cc: Allan Wang (王家偉), Eric-SY Chang (張書源), Deren Wu (武德仁), Ryder Lee, Quan Zhou (周全), Michael Lo (羅璧章), Shayne Chen (陳軒丞), Sean Wang, Leon Yen (顏良儒), KM Lin (林昆民), linux-mediatek@lists.infradead.org, linux-wireless@vger.kernel.org On Tue, 2025-03-04 at 09:06 +0000, Ping-Ke Shih wrote: > > External email : Please do not click links or open attachments until > you have verified the sender or the content. > > > Mingyen Hsieh <mingyen.hsieh@mediatek.com> wrote: > > [...] > > > + struct evt { > > + u8 rsv[4]; > > + > > + __le16 tag; > > + __le16 len; > > + > > + __le32 ver; > > + __le32 addr; > > + __le32 valid; > > + __le32 size; > > + __le32 magic_num; > > + __le32 type; > > + __le32 rsv1[4]; > > + u8 data[32]; > > + } __packed * res; > > nit: no need space between * and res, i.e. "__packed *res". > Hi Ping-Ke, I also think this is better, but this was suggested to me by script/checkpatch.pl. I will send v4 for this. > > + struct sk_buff *skb; > > + int ret; > > + > > + ret = mt76_mcu_send_and_get_msg(&dev->mt76, > > MCU_WM_UNI_CMD_QUERY(EFUSE_CTRL), > > + &req, sizeof(req), true, > > &skb); > > + if (ret) > > + return ret; > > + > > + res = (struct evt *)skb->data; > > + *val = res->data[offset % MT7925_EEPROM_BLOCK_SIZE]; > > + > > + dev_kfree_skb(skb); > > + > > + return 0; > > +} > > + > > static int mt7925_load_clc(struct mt792x_dev *dev, const char > > *fw_name) > > { > > const struct mt76_connac2_fw_trailer *hdr; > > @@ -809,12 +857,19 @@ static int mt7925_load_clc(struct mt792x_dev > > *dev, const char *fw_name) > > struct mt792x_phy *phy = &dev->phy; > > const struct firmware *fw; > > int ret, i, len, offset = 0; > > - u8 *clc_base = NULL; > > + u8 *clc_base = NULL, hw_encap = 0; > > not sure if mt76 declare local variables in reverse X'mas tree order? > > ^ permalink raw reply [flat|nested] 15+ messages in thread
* RE: [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type 2025-03-04 9:37 ` Mingyen Hsieh (謝明諺) @ 2025-03-05 1:00 ` Ping-Ke Shih 0 siblings, 0 replies; 15+ messages in thread From: Ping-Ke Shih @ 2025-03-05 1:00 UTC (permalink / raw) To: Mingyen Hsieh (謝明諺), nbd@nbd.name, lorenzo@kernel.org Cc: Allan Wang (王家偉), Eric-SY Chang (張書源), Deren Wu (武德仁), Ryder Lee, Quan Zhou (周全), Michael Lo (羅璧章), Shayne Chen (陳軒丞), Sean Wang, Leon Yen (顏良儒), KM Lin (林昆民), linux-mediatek@lists.infradead.org, linux-wireless@vger.kernel.org > > > + struct evt { > > > + u8 rsv[4]; > > > + > > > + __le16 tag; > > > + __le16 len; > > > + > > > + __le32 ver; > > > + __le32 addr; > > > + __le32 valid; > > > + __le32 size; > > > + __le32 magic_num; > > > + __le32 type; > > > + __le32 rsv1[4]; > > > + u8 data[32]; > > > + } __packed * res; > > > > nit: no need space between * and res, i.e. "__packed *res". > > > Hi Ping-Ke, > > I also think this is better, but this was suggested to me by > script/checkpatch.pl. > checkpatch says "CHECK:SPACING: spaces preferred around that '*'" for this case, because it treats as a binary operator, so this is a false alarm. By the way, "git grep "__packed \* " drivers/net/wireless/" can see many similar instances I guess they are also suggested by checkpatch. ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2025-03-06 0:42 UTC | newest] Thread overview: 15+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-03-04 6:28 [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type Mingyen Hsieh 2025-03-04 6:28 ` [PATCH v2 2/6] wifi: mt76: mt7925: add EHT control support based on the CLC data Mingyen Hsieh 2025-03-04 9:10 ` Ping-Ke Shih 2025-03-04 9:34 ` Mingyen Hsieh (謝明諺) 2025-03-05 1:21 ` Ping-Ke Shih 2025-03-05 9:32 ` Mingyen Hsieh (謝明諺) 2025-03-06 0:41 ` Ping-Ke Shih 2025-03-04 6:28 ` [PATCH v2 3/6] wifi: mt76: mt7925: update the channel usage when the regd domain changed Mingyen Hsieh 2025-03-04 9:13 ` Ping-Ke Shih 2025-03-04 6:28 ` [PATCH v2 4/6] wifi: mt76: mt7925: remove unused acpi function for clc Mingyen Hsieh 2025-03-04 6:28 ` [PATCH v2 5/6] wifi: mt76: mt792x: extend MTCL of APCI to version3 for EHT control Mingyen Hsieh 2025-03-04 6:28 ` [PATCH v2 6/6] wifi: mt76: mt7925: add MTCL support to enhance the reulatory compliance Mingyen Hsieh 2025-03-04 9:06 ` [PATCH v2 1/6] wifi: mt76: mt7925: load the appropriate CLC data based on hardware type Ping-Ke Shih 2025-03-04 9:37 ` Mingyen Hsieh (謝明諺) 2025-03-05 1:00 ` 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