diff --git a/drivers/net/wireless/ath/ath12k/core.c b/drivers/net/wireless/ath/ath12k/core.c index cd58ab9c2322..d47cf17ed430 100644 --- a/drivers/net/wireless/ath/ath12k/core.c +++ b/drivers/net/wireless/ath/ath12k/core.c @@ -1473,6 +1473,7 @@ static void ath12k_core_pre_reconfigure_recovery(struct ath12k_base *ab) complete(&ar->vdev_setup_done); complete(&ar->vdev_delete_done); complete(&ar->bss_survey_done); + complete(&ar->regd_update_completed); wake_up(&ar->dp.tx_empty_waitq); idr_for_each(&ar->txmgmt_idr, @@ -1512,6 +1513,9 @@ static void ath12k_update_11d(struct work_struct *work) ar = pdev->ar; memcpy(&ar->alpha2, &arg.alpha2, 2); + + reinit_completion(&ar->regd_update_completed); + ret = ath12k_wmi_send_set_current_country_cmd(ar, &arg); if (ret) ath12k_warn(ar->ab, diff --git a/drivers/net/wireless/ath/ath12k/core.h b/drivers/net/wireless/ath/ath12k/core.h index 46fc14dce4c7..cf10c62d4751 100644 --- a/drivers/net/wireless/ath/ath12k/core.h +++ b/drivers/net/wireless/ath/ath12k/core.h @@ -811,6 +811,7 @@ struct ath12k { enum ath12k_11d_state state_11d; u8 alpha2[REG_ALPHA2_LEN]; bool regdom_set_by_user; + struct completion regd_update_completed; struct completion fw_stats_complete; struct completion fw_stats_done; diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c index b9c8854786b4..3c9c9066d320 100644 --- a/drivers/net/wireless/ath/ath12k/mac.c +++ b/drivers/net/wireless/ath/ath12k/mac.c @@ -11381,6 +11381,7 @@ ath12k_mac_op_reconfig_complete(struct ieee80211_hw *hw, struct wmi_set_current_country_arg arg = {}; memcpy(&arg.alpha2, ar->alpha2, 2); + reinit_completion(&ar->regd_update_completed); ath12k_wmi_send_set_current_country_cmd(ar, &arg); } @@ -12680,6 +12681,16 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah) goto err_cleanup_if_combs; } + /* Boot-time regulatory updates have already been processed. + * Mark them as complete now, because after registration, + * cfg80211 will notify us again if there are any pending hints. + * We need to wait for those hints to be processed, so it's + * important to mark the boot-time updates as complete before + * proceeding with registration. + */ + for_each_ar(ah, ar, i) + complete(&ar->regd_update_completed); + ret = ieee80211_register_hw(hw); if (ret) { ath12k_err(ab, "ieee80211 registration failed: %d\n", ret); @@ -12707,6 +12718,9 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah) memcpy(¤t_cc.alpha2, ab->new_alpha2, 2); memcpy(&ar->alpha2, ab->new_alpha2, 2); + + reinit_completion(&ar->regd_update_completed); + ret = ath12k_wmi_send_set_current_country_cmd(ar, ¤t_cc); if (ret) ath12k_warn(ar->ab, @@ -12779,6 +12793,7 @@ static void ath12k_mac_setup(struct ath12k *ar) init_completion(&ar->scan.on_channel); init_completion(&ar->mlo_setup_done); init_completion(&ar->completed_11d_scan); + init_completion(&ar->regd_update_completed); INIT_DELAYED_WORK(&ar->scan.timeout, ath12k_scan_timeout_work); wiphy_work_init(&ar->scan.vdev_clean_wk, ath12k_scan_vdev_clean_work); diff --git a/drivers/net/wireless/ath/ath12k/reg.c b/drivers/net/wireless/ath/ath12k/reg.c index 7c997c9dad4d..96254d6fc675 100644 --- a/drivers/net/wireless/ath/ath12k/reg.c +++ b/drivers/net/wireless/ath/ath12k/reg.c @@ -102,6 +102,8 @@ ath12k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request) /* Send the reg change request to all the radios */ for_each_ar(ah, ar, i) { + reinit_completion(&ar->regd_update_completed); + if (ar->ab->hw_params->current_cc_support) { memcpy(¤t_arg.alpha2, request->alpha2, 2); memcpy(&ar->alpha2, ¤t_arg.alpha2, 2); @@ -273,9 +275,19 @@ int ath12k_regd_update(struct ath12k *ar, bool init) struct ieee80211_regdomain *regd, *regd_copy = NULL; int ret, regd_len, pdev_id; struct ath12k_base *ab; + long time_left; ab = ar->ab; + time_left = wait_for_completion_timeout(&ar->regd_update_completed, + ATH12K_REG_UPDATE_TIMEOUT_HZ); + if (time_left == 0) { + ath12k_warn(ab, "Timeout while waiting for regulatory update"); + /* Even though timeout has occurred, still continue since at least boot + * time data would be there to process + */ + } + supported_bands = ar->pdev->cap.supported_bands; reg_cap = &ab->hal_reg_cap[ar->pdev_idx]; diff --git a/drivers/net/wireless/ath/ath12k/reg.h b/drivers/net/wireless/ath/ath12k/reg.h index 0aeba06182c5..da5128b8c97f 100644 --- a/drivers/net/wireless/ath/ath12k/reg.h +++ b/drivers/net/wireless/ath/ath12k/reg.h @@ -13,6 +13,8 @@ struct ath12k_base; struct ath12k; +#define ATH12K_REG_UPDATE_TIMEOUT_HZ (3 * HZ) + #define ATH12K_2GHZ_MAX_FREQUENCY 2495 #define ATH12K_5GHZ_MAX_FREQUENCY 5920 diff --git a/drivers/net/wireless/ath/ath12k/wmi.c b/drivers/net/wireless/ath/ath12k/wmi.c index 1b82fe0e5099..b38f22118d73 100644 --- a/drivers/net/wireless/ath/ath12k/wmi.c +++ b/drivers/net/wireless/ath/ath12k/wmi.c @@ -6684,7 +6684,8 @@ static void ath12k_wmi_htc_tx_complete(struct ath12k_base *ab, static int ath12k_reg_chan_list_event(struct ath12k_base *ab, struct sk_buff *skb) { struct ath12k_reg_info *reg_info; - u8 pdev_idx; + struct ath12k *ar = NULL; + u8 pdev_idx = 255; int ret; reg_info = kzalloc(sizeof(*reg_info), GFP_ATOMIC); @@ -6739,7 +6740,7 @@ static int ath12k_reg_chan_list_event(struct ath12k_base *ab, struct sk_buff *sk kfree(reg_info); if (ret == ATH12K_REG_STATUS_VALID) - return ret; + goto out; fallback: /* Fallback to older reg (by sending previous country setting @@ -6753,6 +6754,18 @@ static int ath12k_reg_chan_list_event(struct ath12k_base *ab, struct sk_buff *sk WARN_ON(1); out: + /* In some error cases, even a valid pdev_idx might not be available */ + if (pdev_idx != 255) + ar = ab->pdevs[pdev_idx].ar; + + /* During the boot-time update, 'ar' might not be allocated, + * so the completion cannot be marked at that point. + * This boot-time update is handled in ath12k_mac_hw_register() + * before registering the hardware. + */ + if (ar) + complete(&ar->regd_update_completed); + return ret; }