wifi: ath12k: fix mac pdev frequency range update
authorAditya Kumar Singh <aditya.kumar.singh@oss.qualcomm.com>
Tue, 20 May 2025 04:36:52 +0000 (10:06 +0530)
committerJeff Johnson <jeff.johnson@oss.qualcomm.com>
Wed, 21 May 2025 01:08:38 +0000 (18:08 -0700)
The current implementation of per-pdev frequency range updates assumes that
each pdev supports only a single band. As a result in ath12k_regd_update(),
bands are handled using an if-else structure, which limits updates to only
one of the band per pdev. This assumption does not hold for all chipsets.
For example, the WCN7850 supports multiple bands within a single pdev.

Hence to accommodate such cases, update the logic to account for all band
cases by handling each band in a separate if conditions instead of the
previous if-else structure.

Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.4.1-00199-QCAHKSWPL_SILICONZ-1

Fixes: 13324cecbb2c ("wifi: ath12k: Update frequency range if reg rules changes")
Signed-off-by: Aditya Kumar Singh <aditya.kumar.singh@oss.qualcomm.com>
Reviewed-by: Vasanthakumar Thiagarajan <vasanthakumar.thiagarajan@oss.qualcomm.com>
Link: https://patch.msgid.link/20250520-fix_freq_range_update-v1-1-e061fd147b87@oss.qualcomm.com
Signed-off-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
drivers/net/wireless/ath/ath12k/mac.c
drivers/net/wireless/ath/ath12k/reg.c

index c485a7266eefef6677f1b8b6d630f6ae1b154dc5..81ff32d2ce5afce582b78c17fbdf5082e4394798 100644 (file)
@@ -11361,8 +11361,20 @@ void ath12k_mac_update_freq_range(struct ath12k *ar,
        if (!(freq_low && freq_high))
                return;
 
-       ar->freq_range.start_freq = MHZ_TO_KHZ(freq_low);
-       ar->freq_range.end_freq = MHZ_TO_KHZ(freq_high);
+       if (ar->freq_range.start_freq || ar->freq_range.end_freq) {
+               ar->freq_range.start_freq = min(ar->freq_range.start_freq,
+                                               MHZ_TO_KHZ(freq_low));
+               ar->freq_range.end_freq = max(ar->freq_range.end_freq,
+                                             MHZ_TO_KHZ(freq_high));
+       } else {
+               ar->freq_range.start_freq = MHZ_TO_KHZ(freq_low);
+               ar->freq_range.end_freq = MHZ_TO_KHZ(freq_high);
+       }
+
+       ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
+                  "mac pdev %u freq limit updated. New range %u->%u MHz\n",
+                  ar->pdev->pdev_id, KHZ_TO_MHZ(ar->freq_range.start_freq),
+                  KHZ_TO_MHZ(ar->freq_range.end_freq));
 }
 
 static void ath12k_mac_update_ch_list(struct ath12k *ar,
index 19d14486e0caaeaaa2e53c238cd7f3a05ed477ee..2134e72e0812b2a0bdc537ace456ef7af1db0726 100644 (file)
@@ -265,8 +265,8 @@ static void ath12k_copy_regd(struct ieee80211_regdomain *regd_orig,
 
 int ath12k_regd_update(struct ath12k *ar, bool init)
 {
-       u32 phy_id, freq_low = 0, freq_high = 0, supported_bands, band;
        struct ath12k_wmi_hal_reg_capabilities_ext_arg *reg_cap;
+       u32 phy_id, freq_low, freq_high, supported_bands;
        struct ath12k_hw *ah = ath12k_ar_to_ah(ar);
        struct ieee80211_hw *hw = ah->hw;
        struct ieee80211_regdomain *regd, *regd_copy = NULL;
@@ -276,45 +276,45 @@ int ath12k_regd_update(struct ath12k *ar, bool init)
        ab = ar->ab;
 
        supported_bands = ar->pdev->cap.supported_bands;
-       if (supported_bands & WMI_HOST_WLAN_2GHZ_CAP) {
-               band = NL80211_BAND_2GHZ;
-       } else if (supported_bands & WMI_HOST_WLAN_5GHZ_CAP && !ar->supports_6ghz) {
-               band = NL80211_BAND_5GHZ;
-       } else if (supported_bands & WMI_HOST_WLAN_5GHZ_CAP && ar->supports_6ghz) {
-               band = NL80211_BAND_6GHZ;
-       } else {
-               /* This condition is not expected.
-                */
-               WARN_ON(1);
-               ret = -EINVAL;
-               goto err;
-       }
-
        reg_cap = &ab->hal_reg_cap[ar->pdev_idx];
 
-       if (ab->hw_params->single_pdev_only && !ar->supports_6ghz) {
-               phy_id = ar->pdev->cap.band[band].phy_id;
-               reg_cap = &ab->hal_reg_cap[phy_id];
-       }
-
        /* Possible that due to reg change, current limits for supported
-        * frequency changed. Update that
+        * frequency changed. Update it. As a first step, reset the
+        * previous values and then compute and set the new values.
         */
+       ar->freq_range.start_freq = 0;
+       ar->freq_range.end_freq = 0;
+
        if (supported_bands & WMI_HOST_WLAN_2GHZ_CAP) {
+               if (ab->hw_params->single_pdev_only) {
+                       phy_id = ar->pdev->cap.band[WMI_HOST_WLAN_2GHZ_CAP].phy_id;
+                       reg_cap = &ab->hal_reg_cap[phy_id];
+               }
+
                freq_low = max(reg_cap->low_2ghz_chan, ab->reg_freq_2ghz.start_freq);
                freq_high = min(reg_cap->high_2ghz_chan, ab->reg_freq_2ghz.end_freq);
-       } else if (supported_bands & WMI_HOST_WLAN_5GHZ_CAP && !ar->supports_6ghz) {
+
+               ath12k_mac_update_freq_range(ar, freq_low, freq_high);
+       }
+
+       if (supported_bands & WMI_HOST_WLAN_5GHZ_CAP && !ar->supports_6ghz) {
+               if (ab->hw_params->single_pdev_only) {
+                       phy_id = ar->pdev->cap.band[WMI_HOST_WLAN_5GHZ_CAP].phy_id;
+                       reg_cap = &ab->hal_reg_cap[phy_id];
+               }
+
                freq_low = max(reg_cap->low_5ghz_chan, ab->reg_freq_5ghz.start_freq);
                freq_high = min(reg_cap->high_5ghz_chan, ab->reg_freq_5ghz.end_freq);
-       } else if (supported_bands & WMI_HOST_WLAN_5GHZ_CAP && ar->supports_6ghz) {
-               freq_low = max(reg_cap->low_5ghz_chan, ab->reg_freq_6ghz.start_freq);
-               freq_high = min(reg_cap->high_5ghz_chan, ab->reg_freq_6ghz.end_freq);
+
+               ath12k_mac_update_freq_range(ar, freq_low, freq_high);
        }
 
-       ath12k_mac_update_freq_range(ar, freq_low, freq_high);
+       if (supported_bands & WMI_HOST_WLAN_5GHZ_CAP && ar->supports_6ghz) {
+               freq_low = max(reg_cap->low_5ghz_chan, ab->reg_freq_6ghz.start_freq);
+               freq_high = min(reg_cap->high_5ghz_chan, ab->reg_freq_6ghz.end_freq);
 
-       ath12k_dbg(ab, ATH12K_DBG_REG, "pdev %u reg updated freq limits %u->%u MHz\n",
-                  ar->pdev->pdev_id, freq_low, freq_high);
+               ath12k_mac_update_freq_range(ar, freq_low, freq_high);
+       }
 
        /* If one of the radios within ah has already updated the regd for
         * the wiphy, then avoid setting regd again