wifi: rtw89: regd: judge UNII-4 according to BIOS and chip
authorZong-Zhe Yang <kevin_yang@realtek.com>
Mon, 8 May 2023 08:12:10 +0000 (16:12 +0800)
committerKalle Valo <kvalo@kernel.org>
Thu, 11 May 2023 13:19:17 +0000 (16:19 +0300)
For realtek regulatory, there are following two kinds of configurations
to determine whether to allow UNII-4 band, i.e. 5.9GHz channels.

1. default setting according to whether chip support it or not
2. evaluate realtek ACPI DSM with RTW89_ACPI_DSM_FUNC_59G_EN (func. 6)

If (1) is false, we won't try (2) and just disallow UNII-4. Otherwise,
if (2) is not supported or returns a non-specific value, we follow the
default setting either. Besides, this commit aims to add decision logic
in rtw89 regulatory. Actually, driver doesn't register UNII-4 yet. That
will be handled by another commit.

Signed-off-by: Zong-Zhe Yang <kevin_yang@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20230508081211.38760-3-pkshih@realtek.com
drivers/net/wireless/realtek/rtw89/core.c
drivers/net/wireless/realtek/rtw89/core.h
drivers/net/wireless/realtek/rtw89/regd.c
drivers/net/wireless/realtek/rtw89/rtw8851b.c
drivers/net/wireless/realtek/rtw89/rtw8852a.c
drivers/net/wireless/realtek/rtw89/rtw8852b.c
drivers/net/wireless/realtek/rtw89/rtw8852c.c

index 630124f9e025436f93dea391ee32039d56dd2c55..09296e79f07b48907eb91bca8493ddd86bf1481d 100644 (file)
@@ -3850,7 +3850,12 @@ static int rtw89_core_register_hw(struct rtw89_dev *rtwdev)
                return ret;
        }
 
-       hw->wiphy->reg_notifier = rtw89_regd_notifier;
+       ret = rtw89_regd_setup(rtwdev);
+       if (ret) {
+               rtw89_err(rtwdev, "failed to set up regd\n");
+               goto err_free_supported_band;
+       }
+
        hw->wiphy->sar_capa = &rtw89_sar_capa;
 
        ret = ieee80211_register_hw(hw);
index f697902706acc1369643017c1bfc057543a0b528..cdd8e312cef76afa30e33f850b6b5349d7dbba14 100644 (file)
@@ -3179,6 +3179,7 @@ struct rtw89_chip_info {
        u8 support_chanctx_num;
        u8 support_bands;
        bool support_bw160;
+       bool support_unii4;
        bool support_ul_tb_ctrl;
        bool hw_sec_hdr;
        u8 rf_path_num;
@@ -5044,6 +5045,7 @@ int rtw89_core_release_sta_ba_entry(struct rtw89_dev *rtwdev,
 void rtw89_vif_type_mapping(struct ieee80211_vif *vif, bool assoc);
 int rtw89_chip_info_setup(struct rtw89_dev *rtwdev);
 bool rtw89_ra_report_to_bitrate(struct rtw89_dev *rtwdev, u8 rpt_rate, u16 *bitrate);
+int rtw89_regd_setup(struct rtw89_dev *rtwdev);
 int rtw89_regd_init(struct rtw89_dev *rtwdev,
                    void (*reg_notifier)(struct wiphy *wiphy, struct regulatory_request *request));
 void rtw89_regd_notifier(struct wiphy *wiphy, struct regulatory_request *request);
index 6e5a740b128f027ca4dfeefcaf133e3cad3a6dca..7800ca36bc13383273a7a02f8c0b5ff6c8196414 100644 (file)
@@ -2,6 +2,7 @@
 /* Copyright(c) 2019-2020  Realtek Corporation
  */
 
+#include "acpi.h"
 #include "debug.h"
 #include "ps.h"
 
@@ -282,6 +283,56 @@ do { \
                    __r->txpwr_regd[RTW89_BAND_6G]); \
 } while (0)
 
+static void rtw89_regd_setup_unii4(struct rtw89_dev *rtwdev,
+                                  struct wiphy *wiphy)
+{
+       const struct rtw89_chip_info *chip = rtwdev->chip;
+       bool regd_allow_unii_4 = chip->support_unii4;
+       int ret;
+       u8 val;
+
+       if (!chip->support_unii4)
+               goto bottom;
+
+       ret = rtw89_acpi_evaluate_dsm(rtwdev, RTW89_ACPI_DSM_FUNC_59G_EN, &val);
+       if (ret) {
+               rtw89_debug(rtwdev, RTW89_DBG_REGD,
+                           "acpi: cannot eval unii 4: %d\n", ret);
+               goto bottom;
+       }
+
+       rtw89_debug(rtwdev, RTW89_DBG_REGD,
+                   "acpi: eval if allow unii 4: %d\n", val);
+
+       switch (val) {
+       case 0:
+               regd_allow_unii_4 = false;
+               break;
+       case 1:
+               regd_allow_unii_4 = true;
+               break;
+       default:
+               break;
+       }
+
+bottom:
+       rtw89_debug(rtwdev, RTW89_DBG_REGD, "regd: allow unii 4: %d\n",
+                   regd_allow_unii_4);
+}
+
+int rtw89_regd_setup(struct rtw89_dev *rtwdev)
+{
+       struct wiphy *wiphy = rtwdev->hw->wiphy;
+
+       if (!wiphy)
+               return -EINVAL;
+
+       rtw89_regd_setup_unii4(rtwdev, wiphy);
+
+       wiphy->reg_notifier = rtw89_regd_notifier;
+       return 0;
+}
+
 int rtw89_regd_init(struct rtw89_dev *rtwdev,
                    void (*reg_notifier)(struct wiphy *wiphy,
                                         struct regulatory_request *request))
index b68ebe950c4ef8b8d67a54ae46f92ffdf25e02ef..00cabf92c5a9999ec5f6733eef90a36f7ad16d2a 100644 (file)
@@ -123,6 +123,7 @@ const struct rtw89_chip_info rtw8851b_chip_info = {
        .support_bands          = BIT(NL80211_BAND_2GHZ) |
                                  BIT(NL80211_BAND_5GHZ),
        .support_bw160          = false,
+       .support_unii4          = true,
        .support_ul_tb_ctrl     = true,
        .hw_sec_hdr             = false,
        .rf_path_num            = 1,
index a8a58ff36e95f7bbd4e65752eaa2be4fd41f335c..4e6f3bbdc2d8f0abf0a737ec35b17f16a100d22a 100644 (file)
@@ -2105,6 +2105,7 @@ const struct rtw89_chip_info rtw8852a_chip_info = {
        .support_bands          = BIT(NL80211_BAND_2GHZ) |
                                  BIT(NL80211_BAND_5GHZ),
        .support_bw160          = false,
+       .support_unii4          = false,
        .support_ul_tb_ctrl     = false,
        .hw_sec_hdr             = false,
        .rf_path_num            = 2,
index fa12d4a7f79f97ed0996d3555b28c75747d36f8d..b1a6b985842bed2193c015d6607c6229a01e535a 100644 (file)
@@ -2536,6 +2536,7 @@ const struct rtw89_chip_info rtw8852b_chip_info = {
        .support_bands          = BIT(NL80211_BAND_2GHZ) |
                                  BIT(NL80211_BAND_5GHZ),
        .support_bw160          = false,
+       .support_unii4          = true,
        .support_ul_tb_ctrl     = true,
        .hw_sec_hdr             = false,
        .rf_path_num            = 2,
index d9272bce03256c0da2233caaa1b12343d06710c8..f2e70bda8e480da48c69ac8adae1ea8257873386 100644 (file)
@@ -2836,6 +2836,7 @@ const struct rtw89_chip_info rtw8852c_chip_info = {
                                  BIT(NL80211_BAND_5GHZ) |
                                  BIT(NL80211_BAND_6GHZ),
        .support_bw160          = true,
+       .support_unii4          = true,
        .support_ul_tb_ctrl     = false,
        .hw_sec_hdr             = true,
        .rf_path_num            = 2,