wifi: mt76: mt7921: support 5.9/6GHz channel config in acpi
authorRong Yan <rong.yan@mediatek.com>
Sun, 1 Oct 2023 15:02:05 +0000 (23:02 +0800)
committerFelix Fietkau <nbd@nbd.name>
Thu, 7 Dec 2023 17:50:19 +0000 (18:50 +0100)
The mtcl table, configured by platform vendor, provides regulatory
information for 5.9/6 GHz channels. mt792x should work on
corresponding channels supported by mtcl. This patch would parse
the settings in mtcl table and apply the result into chip side.

Signed-off-by: Rong Yan <rong.yan@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/mt7921/mcu.c
drivers/net/wireless/mediatek/mt76/mt792x.h
drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c
drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.h

index 63f3d4a5c9aa6e9daafc69fbe049c04b91b766ad..94fc3eb4023488c2dc8e203d0c436778eb4c9028 100644 (file)
@@ -1260,12 +1260,14 @@ int __mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2,
                u8 alpha2[2];
                u8 type[2];
                u8 env_6g;
-               u8 rsvd[63];
+               u8 mtcl_conf;
+               u8 rsvd[62];
        } __packed req = {
                .idx = idx,
                .env = env_cap,
                .env_6g = dev->phy.power_type,
                .acpi_conf = mt792x_acpi_get_flags(&dev->phy),
+               .mtcl_conf = mt792x_acpi_get_mtcl_conf(&dev->phy, alpha2),
        };
        int ret, valid_cnt = 0;
        u8 i, *pos;
index 36fae736dd19251b0f48986551a68af123fe292c..3c897b34aaa79662b72c935a6b0b7b69ca621231 100644 (file)
@@ -382,6 +382,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);
 #else
 static inline int mt792x_init_acpi_sar(struct mt792x_dev *dev)
 {
@@ -398,6 +399,11 @@ 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)
+{
+       return 0xf;
+}
 #endif
 
 #endif /* __MT7925_H */
index 303c0f5c9c662ca04436245deae4f7605aa5b681..e7afea87e82e2b42c41bdea32b6015679909222d 100644 (file)
@@ -348,3 +348,56 @@ u8 mt792x_acpi_get_flags(struct mt792x_phy *phy)
        return flags;
 }
 EXPORT_SYMBOL_GPL(mt792x_acpi_get_flags);
+
+static u8
+mt792x_acpi_get_mtcl_map(int row, int column, struct mt792x_asar_cl *cl)
+{
+       u8 config = 0;
+
+       if (cl->cl6g[row] & BIT(column))
+               config |= (cl->mode_6g & 0x3) << 2;
+       if (cl->version > 1 && cl->cl5g9[row] & BIT(column))
+               config |= (cl->mode_5g9 & 0x3);
+
+       return config;
+}
+
+u8 mt792x_acpi_get_mtcl_conf(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", "MT", "SK", "SI", "ES", "CH",
+       };
+       struct mt792x_acpi_sar *sar = phy->acpisar;
+       struct mt792x_asar_cl *cl;
+       int col, row, i;
+
+       if (!sar)
+               return 0xf;
+
+       cl = sar->countrylist;
+       if (!cl)
+               return 0xc;
+
+       for (i = 0; i < ARRAY_SIZE(cc_list_all); i++) {
+               col = 7 - i % 8;
+               row = i / 8;
+               if (!memcmp(cc_list_all[i], alpha2, 2))
+                       return mt792x_acpi_get_mtcl_map(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(0, 6, cl);
+
+       return mt792x_acpi_get_mtcl_map(0, 7, cl);
+}
+EXPORT_SYMBOL_GPL(mt792x_acpi_get_mtcl_conf);
index d6d332e863ba9c9836e44875a3c5f9333fa56a0e..2298983b6342fde6b4cc415317460874bb463abb 100644 (file)
@@ -77,6 +77,8 @@ struct mt792x_asar_cl {
        u8 version;
        u8 mode_6g;
        u8 cl6g[6];
+       u8 mode_5g9;
+       u8 cl5g9[6];
 } __packed;
 
 struct mt792x_asar_fg {