]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: rtw89: enable dynamic antenna gain based on country
authorKuan-Chung Chen <damon.chen@realtek.com>
Thu, 6 Mar 2025 02:11:42 +0000 (10:11 +0800)
committerPing-Ke Shih <pkshih@realtek.com>
Thu, 13 Mar 2025 00:44:25 +0000 (08:44 +0800)
The dynamic antenna gain (DAG) considers the country, meaning DAG can
be activated only when countries and regulatory domains allow it.

Signed-off-by: Kuan-Chung Chen <damon.chen@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Link: https://patch.msgid.link/20250306021144.12854-4-pkshih@realtek.com
drivers/net/wireless/realtek/rtw89/core.h
drivers/net/wireless/realtek/rtw89/phy.c
drivers/net/wireless/realtek/rtw89/regd.c

index 074c865e6d03f721a34d246a052fdd77b4c9754e..b8f46207141e7adcdc73289f164b06b2f7d46a71 100644 (file)
@@ -4666,6 +4666,7 @@ enum rtw89_ant_gain_domain_type {
 struct rtw89_ant_gain_info {
        s8 offset[RTW89_ANT_GAIN_CHAIN_NUM][RTW89_ANT_GAIN_SUBBAND_NR];
        u32 regd_enabled;
+       bool block_country;
 };
 
 struct rtw89_6ghz_span {
index abc2a7e989eb8ab84893c09ec4dc5034ef807c8f..bd736417f46779d601ab17905e208d0e84d16622 100644 (file)
@@ -2044,7 +2044,7 @@ static s8 rtw89_phy_ant_gain_offset(struct rtw89_dev *rtwdev, u8 band, u32 cente
        if (!chip->support_ant_gain)
                return 0;
 
-       if (!(ant_gain->regd_enabled & BIT(regd)))
+       if (ant_gain->block_country || !(ant_gain->regd_enabled & BIT(regd)))
                return 0;
 
        offset_patha = rtw89_phy_ant_gain_query(rtwdev, RF_PATH_A, center_freq);
@@ -2057,10 +2057,14 @@ s16 rtw89_phy_ant_gain_pwr_offset(struct rtw89_dev *rtwdev,
                                  const struct rtw89_chan *chan)
 {
        struct rtw89_ant_gain_info *ant_gain = &rtwdev->ant_gain;
+       const struct rtw89_chip_info *chip = rtwdev->chip;
        u8 regd = rtw89_regd_get(rtwdev, chan->band_type);
        s8 offset_patha, offset_pathb;
 
-       if (!(ant_gain->regd_enabled & BIT(regd)))
+       if (!chip->support_ant_gain)
+               return 0;
+
+       if (ant_gain->block_country || !(ant_gain->regd_enabled & BIT(regd)))
                return 0;
 
        offset_patha = rtw89_phy_ant_gain_query(rtwdev, RF_PATH_A, chan->freq);
@@ -2079,7 +2083,8 @@ int rtw89_print_ant_gain(struct rtw89_dev *rtwdev, char *buf, size_t bufsz,
        char *p = buf, *end = buf + bufsz;
        s8 offset_patha, offset_pathb;
 
-       if (!chip->support_ant_gain || !(ant_gain->regd_enabled & BIT(regd))) {
+       if (!(chip->support_ant_gain && (ant_gain->regd_enabled & BIT(regd))) ||
+           ant_gain->block_country) {
                p += scnprintf(p, end - p, "no DAG is applied\n");
                goto out;
        }
index d31403f9009ee9431ca667d5ffd6c2fab3304355..655323a796082b9008d0a067ba4c265393a5cfd1 100644 (file)
@@ -733,6 +733,19 @@ static void rtw89_regd_apply_policy_tas(struct rtw89_dev *rtwdev)
        tas->block_regd = !test_bit(RTW89_REGD_FUNC_TAS, regd->func_bitmap);
 }
 
+static void rtw89_regd_apply_policy_ant_gain(struct rtw89_dev *rtwdev)
+{
+       struct rtw89_regulatory_info *regulatory = &rtwdev->regulatory;
+       struct rtw89_ant_gain_info *ant_gain = &rtwdev->ant_gain;
+       const struct rtw89_chip_info *chip = rtwdev->chip;
+       const struct rtw89_regd *regd = regulatory->regd;
+
+       if (!chip->support_ant_gain)
+               return;
+
+       ant_gain->block_country = !test_bit(RTW89_REGD_FUNC_DAG, regd->func_bitmap);
+}
+
 static void rtw89_regd_notifier_apply(struct rtw89_dev *rtwdev,
                                      struct wiphy *wiphy,
                                      struct regulatory_request *request)
@@ -751,6 +764,7 @@ static void rtw89_regd_notifier_apply(struct rtw89_dev *rtwdev,
        rtw89_regd_apply_policy_unii4(rtwdev, wiphy);
        rtw89_regd_apply_policy_6ghz(rtwdev, wiphy);
        rtw89_regd_apply_policy_tas(rtwdev);
+       rtw89_regd_apply_policy_ant_gain(rtwdev);
 }
 
 static