wifi: rtw89: regd: judge 6 GHz according to chip and BIOS
authorZong-Zhe Yang <kevin_yang@realtek.com>
Fri, 2 Jun 2023 15:05:50 +0000 (23:05 +0800)
committerKalle Valo <kvalo@kernel.org>
Thu, 8 Jun 2023 15:58:51 +0000 (18:58 +0300)
We allow platform to disable 6 GHz on chips, which supports 6 GHz, through
BIOS. Driver will evaluate Realtek acpi DSM with RTW89_ACPI_DSM_FUNC_6G_DIS
(function 3) to get whether 6 GHz should be disabled.

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/20230602150556.36777-3-pkshih@realtek.com
drivers/net/wireless/realtek/rtw89/regd.c

index 377a7a1c560b732b406d3f25130d16a38f27e532..43e589c023af87afb0209fe55ed539f454aad886 100644 (file)
@@ -330,6 +330,55 @@ bottom:
        sband->n_channels -= 3;
 }
 
+static void rtw89_regd_setup_6ghz(struct rtw89_dev *rtwdev, struct wiphy *wiphy)
+{
+       const struct rtw89_chip_info *chip = rtwdev->chip;
+       bool chip_support_6ghz = chip->support_bands & BIT(NL80211_BAND_6GHZ);
+       bool regd_allow_6ghz = chip_support_6ghz;
+       struct ieee80211_supported_band *sband;
+       int ret;
+       u8 val;
+
+       if (!chip_support_6ghz)
+               goto bottom;
+
+       ret = rtw89_acpi_evaluate_dsm(rtwdev, RTW89_ACPI_DSM_FUNC_6G_DIS, &val);
+       if (ret) {
+               rtw89_debug(rtwdev, RTW89_DBG_REGD,
+                           "acpi: cannot eval 6ghz: %d\n", ret);
+               goto bottom;
+       }
+
+       rtw89_debug(rtwdev, RTW89_DBG_REGD,
+                   "acpi: eval if disallow 6ghz: %d\n", val);
+
+       switch (val) {
+       case 0:
+               regd_allow_6ghz = true;
+               break;
+       case 1:
+               regd_allow_6ghz = false;
+               break;
+       default:
+               break;
+       }
+
+bottom:
+       rtw89_debug(rtwdev, RTW89_DBG_REGD, "regd: allow 6ghz: %d\n",
+                   regd_allow_6ghz);
+
+       if (regd_allow_6ghz)
+               return;
+
+       sband = wiphy->bands[NL80211_BAND_6GHZ];
+       if (!sband)
+               return;
+
+       wiphy->bands[NL80211_BAND_6GHZ] = NULL;
+       kfree(sband->iftype_data);
+       kfree(sband);
+}
+
 int rtw89_regd_setup(struct rtw89_dev *rtwdev)
 {
        struct wiphy *wiphy = rtwdev->hw->wiphy;
@@ -338,6 +387,7 @@ int rtw89_regd_setup(struct rtw89_dev *rtwdev)
                return -EINVAL;
 
        rtw89_regd_setup_unii4(rtwdev, wiphy);
+       rtw89_regd_setup_6ghz(rtwdev, wiphy);
 
        wiphy->reg_notifier = rtw89_regd_notifier;
        return 0;