wifi: mt76: mt792x: extend MTCL of APCI to version3 for EHT control
authorMing Yen Hsieh <mingyen.hsieh@mediatek.com>
Tue, 4 Mar 2025 11:36:48 +0000 (19:36 +0800)
committerFelix Fietkau <nbd@nbd.name>
Wed, 19 Mar 2025 13:47:04 +0000 (14:47 +0100)
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>
Link: https://patch.msgid.link/20250304113649.867387-5-mingyen.hsieh@mediatek.com
Signed-off-by: Felix Fietkau <nbd@nbd.name>
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 97e9de88a63d86d54841952eee8b979e8c9a0f41..e0359d431eca9696e81963ba322537c651c1f125 100644 (file)
@@ -508,7 +508,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)
 {
@@ -526,9 +526,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
 
index 9317f8ff2070fda56ebcfbd8677ed4aff8ebdcb3..d1aebadd50aac05367cd3ff926979eccd8979d1e 100644 (file)
@@ -4,6 +4,28 @@
 #include <linux/acpi.h>
 #include "mt792x.h"
 
+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",
+};
+
 static int
 mt792x_acpi_read(struct mt792x_dev *dev, u8 *method, u8 **tbl, u32 *len)
 {
@@ -66,13 +88,22 @@ free:
 }
 
 /* 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 +382,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 +413,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;
 
-       cl = sar->countrylist;
        if (!cl)
-               return 0xc;
+               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;
+
+       if (!cl)
+               return MT792X_ACPI_MTCL_INVALID;
 
        for (i = 0; i < ARRAY_SIZE(cc_list_all); i++) {
                col = 7 - i % 8;
@@ -406,4 +465,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);
index 2298983b6342fde6b4cc415317460874bb463abb..e45dcd7fbdb18bd13dfb177061f97a8363585c73 100644 (file)
@@ -15,6 +15,8 @@
 #define MT792x_ACPI_MTGS               "MTGS"
 #define MT792x_ACPI_MTFG               "MTFG"
 
+#define MT792X_ACPI_MTCL_INVALID       0xffffffff
+
 struct mt792x_asar_dyn_limit {
        u8 idx;
        u8 frp[5];
@@ -72,6 +74,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 +113,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;
 };