Lines Matching +full:country +full:- +full:code

1 // SPDX-License-Identifier: BSD-3-Clause-Clear
3 * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
11 #define ATH12K_2GHZ_CH01_11 REG_RULE(2412 - 10, 2462 + 10, 40, 0, 20, 0)
12 #define ATH12K_5GHZ_5150_5350 REG_RULE(5150 - 10, 5350 + 10, 80, 0, 30,\
14 #define ATH12K_5GHZ_5725_5850 REG_RULE(5725 - 10, 5850 + 10, 80, 0, 30,\
35 regd = rcu_dereference_rtnl(hw->wiphy->regd); in ath12k_regdom_changes()
43 return memcmp(regd->alpha2, alpha2, 2) != 0; in ath12k_regdom_changes()
55 ath12k_dbg(ar->ab, ATH12K_DBG_REG, in ath12k_reg_notifier()
63 if (!(request->initiator == NL80211_REGDOM_SET_BY_USER && in ath12k_reg_notifier()
64 request->user_reg_hint_type == NL80211_USER_REG_HINT_USER)) { in ath12k_reg_notifier()
65 ath12k_warn(ar->ab, "Unexpected Regulatory event for this wiphy\n"); in ath12k_reg_notifier()
70 ath12k_dbg(ar->ab, ATH12K_DBG_REG, in ath12k_reg_notifier()
71 "Country Setting is not allowed\n"); in ath12k_reg_notifier()
75 if (!ath12k_regdom_changes(hw, request->alpha2)) { in ath12k_reg_notifier()
76 ath12k_dbg(ar->ab, ATH12K_DBG_REG, "Country is already set\n"); in ath12k_reg_notifier()
80 /* Set the country code to the firmware and wait for in ath12k_reg_notifier()
85 memcpy(&arg.cc_info.alpha2, request->alpha2, 2); in ath12k_reg_notifier()
89 ah->regd_updated = false; in ath12k_reg_notifier()
95 ath12k_warn(ar->ab, in ath12k_reg_notifier()
96 "INIT Country code set to fw failed : %d\n", ret); in ath12k_reg_notifier()
111 bands = hw->wiphy->bands; in ath12k_reg_update_chan_list()
113 if (!(ar->mac.sbands[band].channels && bands[band])) in ath12k_reg_update_chan_list()
116 for (i = 0; i < bands[band]->n_channels; i++) { in ath12k_reg_update_chan_list()
117 if (bands[band]->channels[i].flags & in ath12k_reg_update_chan_list()
126 return -EINVAL; in ath12k_reg_update_chan_list()
131 return -ENOMEM; in ath12k_reg_update_chan_list()
133 arg->pdev_id = ar->pdev->pdev_id; in ath12k_reg_update_chan_list()
134 arg->nallchans = num_channels; in ath12k_reg_update_chan_list()
136 ch = arg->channel; in ath12k_reg_update_chan_list()
139 if (!(ar->mac.sbands[band].channels && bands[band])) in ath12k_reg_update_chan_list()
142 for (i = 0; i < bands[band]->n_channels; i++) { in ath12k_reg_update_chan_list()
143 channel = &bands[band]->channels[i]; in ath12k_reg_update_chan_list()
145 if (channel->flags & IEEE80211_CHAN_DISABLED) in ath12k_reg_update_chan_list()
149 ch->allow_ht = true; in ath12k_reg_update_chan_list()
150 ch->allow_vht = true; in ath12k_reg_update_chan_list()
151 ch->allow_he = true; in ath12k_reg_update_chan_list()
153 ch->dfs_set = in ath12k_reg_update_chan_list()
154 !!(channel->flags & IEEE80211_CHAN_RADAR); in ath12k_reg_update_chan_list()
155 ch->is_chan_passive = !!(channel->flags & in ath12k_reg_update_chan_list()
157 ch->is_chan_passive |= ch->dfs_set; in ath12k_reg_update_chan_list()
158 ch->mhz = channel->center_freq; in ath12k_reg_update_chan_list()
159 ch->cfreq1 = channel->center_freq; in ath12k_reg_update_chan_list()
160 ch->minpower = 0; in ath12k_reg_update_chan_list()
161 ch->maxpower = channel->max_power * 2; in ath12k_reg_update_chan_list()
162 ch->maxregpower = channel->max_reg_power * 2; in ath12k_reg_update_chan_list()
163 ch->antennamax = channel->max_antenna_gain * 2; in ath12k_reg_update_chan_list()
166 if (channel->band == NL80211_BAND_2GHZ) in ath12k_reg_update_chan_list()
167 ch->phy_mode = MODE_11G; in ath12k_reg_update_chan_list()
169 ch->phy_mode = MODE_11A; in ath12k_reg_update_chan_list()
171 if (channel->band == NL80211_BAND_6GHZ && in ath12k_reg_update_chan_list()
173 ch->psc_channel = true; in ath12k_reg_update_chan_list()
175 ath12k_dbg(ar->ab, ATH12K_DBG_WMI, in ath12k_reg_update_chan_list()
177 i, arg->nallchans, in ath12k_reg_update_chan_list()
178 ch->mhz, ch->maxpower, ch->maxregpower, in ath12k_reg_update_chan_list()
179 ch->antennamax, ch->phy_mode); in ath12k_reg_update_chan_list()
202 for (i = 0; i < regd_orig->n_reg_rules; i++) in ath12k_copy_regd()
203 memcpy(&regd_copy->reg_rules[i], &regd_orig->reg_rules[i], in ath12k_copy_regd()
210 struct ieee80211_hw *hw = ah->hw; in ath12k_regd_update()
216 ab = ar->ab; in ath12k_regd_update()
221 if (ah->regd_updated) in ath12k_regd_update()
234 if (ah->use_6ghz_regd && !ar->supports_6ghz) in ath12k_regd_update()
237 pdev_id = ar->pdev_idx; in ath12k_regd_update()
239 spin_lock_bh(&ab->base_lock); in ath12k_regd_update()
247 if (ab->default_regd[pdev_id]) { in ath12k_regd_update()
248 regd = ab->default_regd[pdev_id]; in ath12k_regd_update()
255 regd = ab->new_regd[pdev_id]; in ath12k_regd_update()
259 ret = -EINVAL; in ath12k_regd_update()
260 spin_unlock_bh(&ab->base_lock); in ath12k_regd_update()
264 regd_len = sizeof(*regd) + (regd->n_reg_rules * in ath12k_regd_update()
271 spin_unlock_bh(&ab->base_lock); in ath12k_regd_update()
274 ret = -ENOMEM; in ath12k_regd_update()
279 wiphy_lock(hw->wiphy); in ath12k_regd_update()
280 ret = regulatory_set_wiphy_regd_sync(hw->wiphy, regd_copy); in ath12k_regd_update()
281 wiphy_unlock(hw->wiphy); in ath12k_regd_update()
289 if (ah->state != ATH12K_HW_STATE_ON) in ath12k_regd_update()
292 ah->regd_updated = true; in ath12k_regd_update()
294 * since we check for ah->regd_updated and allow here only once. in ath12k_regd_update()
297 ab = ar->ab; in ath12k_regd_update()
375 start_freq1 = rule1->freq_range.start_freq_khz; in ath12k_reg_can_intersect()
376 start_freq2 = rule2->freq_range.start_freq_khz; in ath12k_reg_can_intersect()
378 end_freq1 = rule1->freq_range.end_freq_khz; in ath12k_reg_can_intersect()
379 end_freq2 = rule2->freq_range.end_freq_khz; in ath12k_reg_can_intersect()
404 start_freq1 = rule1->freq_range.start_freq_khz; in ath12k_reg_intersect_rules()
405 start_freq2 = rule2->freq_range.start_freq_khz; in ath12k_reg_intersect_rules()
407 end_freq1 = rule1->freq_range.end_freq_khz; in ath12k_reg_intersect_rules()
408 end_freq2 = rule2->freq_range.end_freq_khz; in ath12k_reg_intersect_rules()
410 new_rule->freq_range.start_freq_khz = max_t(u32, start_freq1, in ath12k_reg_intersect_rules()
412 new_rule->freq_range.end_freq_khz = min_t(u32, end_freq1, end_freq2); in ath12k_reg_intersect_rules()
414 freq_diff = new_rule->freq_range.end_freq_khz - in ath12k_reg_intersect_rules()
415 new_rule->freq_range.start_freq_khz; in ath12k_reg_intersect_rules()
416 max_bw = min_t(u32, rule1->freq_range.max_bandwidth_khz, in ath12k_reg_intersect_rules()
417 rule2->freq_range.max_bandwidth_khz); in ath12k_reg_intersect_rules()
418 new_rule->freq_range.max_bandwidth_khz = min_t(u32, max_bw, freq_diff); in ath12k_reg_intersect_rules()
420 new_rule->power_rule.max_antenna_gain = in ath12k_reg_intersect_rules()
421 min_t(u32, rule1->power_rule.max_antenna_gain, in ath12k_reg_intersect_rules()
422 rule2->power_rule.max_antenna_gain); in ath12k_reg_intersect_rules()
424 new_rule->power_rule.max_eirp = min_t(u32, rule1->power_rule.max_eirp, in ath12k_reg_intersect_rules()
425 rule2->power_rule.max_eirp); in ath12k_reg_intersect_rules()
428 new_rule->flags = rule1->flags | rule2->flags; in ath12k_reg_intersect_rules()
431 new_rule->dfs_cac_ms = max_t(u32, rule1->dfs_cac_ms, in ath12k_reg_intersect_rules()
432 rule2->dfs_cac_ms); in ath12k_reg_intersect_rules()
444 num_old_regd_rules = default_regd->n_reg_rules; in ath12k_regd_intersect()
445 num_curr_regd_rules = curr_regd->n_reg_rules; in ath12k_regd_intersect()
450 old_rule = default_regd->reg_rules + i; in ath12k_regd_intersect()
452 curr_rule = curr_regd->reg_rules + j; in ath12k_regd_intersect()
469 /* We set the new country and dfs region directly and only trim in ath12k_regd_intersect()
473 new_regd->n_reg_rules = num_new_regd_rules; in ath12k_regd_intersect()
474 memcpy(new_regd->alpha2, curr_regd->alpha2, sizeof(new_regd->alpha2)); in ath12k_regd_intersect()
475 new_regd->dfs_region = curr_regd->dfs_region; in ath12k_regd_intersect()
476 new_rule = new_regd->reg_rules; in ath12k_regd_intersect()
479 old_rule = default_regd->reg_rules + i; in ath12k_regd_intersect()
481 curr_rule = curr_regd->reg_rules + j; in ath12k_regd_intersect()
511 bw = end_freq - start_freq; in ath12k_reg_adjust_bw()
529 reg_rule->freq_range.start_freq_khz = MHZ_TO_KHZ(start_freq); in ath12k_reg_update_rule()
530 reg_rule->freq_range.end_freq_khz = MHZ_TO_KHZ(end_freq); in ath12k_reg_update_rule()
531 reg_rule->freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw); in ath12k_reg_update_rule()
532 reg_rule->power_rule.max_antenna_gain = DBI_TO_MBI(ant_gain); in ath12k_reg_update_rule()
533 reg_rule->power_rule.max_eirp = DBM_TO_MBM(reg_pwr); in ath12k_reg_update_rule()
534 reg_rule->flags = reg_flags; in ath12k_reg_update_rule()
549 bw = ath12k_reg_adjust_bw(reg_rule->start_freq, in ath12k_reg_update_weather_radar_band()
552 ath12k_reg_update_rule(regd->reg_rules + i, reg_rule->start_freq, in ath12k_reg_update_weather_radar_band()
554 reg_rule->ant_gain, reg_rule->reg_power, in ath12k_reg_update_weather_radar_band()
558 "\t%d. (%d - %d @ %d) (%d, %d) (%d ms) (FLAGS %d)\n", in ath12k_reg_update_weather_radar_band()
559 i + 1, reg_rule->start_freq, ETSI_WEATHER_RADAR_BAND_LOW, in ath12k_reg_update_weather_radar_band()
560 bw, reg_rule->ant_gain, reg_rule->reg_power, in ath12k_reg_update_weather_radar_band()
561 regd->reg_rules[i].dfs_cac_ms, in ath12k_reg_update_weather_radar_band()
564 if (reg_rule->end_freq > ETSI_WEATHER_RADAR_BAND_HIGH) in ath12k_reg_update_weather_radar_band()
567 end_freq = reg_rule->end_freq; in ath12k_reg_update_weather_radar_band()
574 ath12k_reg_update_rule(regd->reg_rules + i, in ath12k_reg_update_weather_radar_band()
576 reg_rule->ant_gain, reg_rule->reg_power, in ath12k_reg_update_weather_radar_band()
579 regd->reg_rules[i].dfs_cac_ms = ETSI_WEATHER_RADAR_BAND_CAC_TIMEOUT; in ath12k_reg_update_weather_radar_band()
582 "\t%d. (%d - %d @ %d) (%d, %d) (%d ms) (FLAGS %d)\n", in ath12k_reg_update_weather_radar_band()
584 bw, reg_rule->ant_gain, reg_rule->reg_power, in ath12k_reg_update_weather_radar_band()
585 regd->reg_rules[i].dfs_cac_ms, in ath12k_reg_update_weather_radar_band()
588 if (end_freq == reg_rule->end_freq) { in ath12k_reg_update_weather_radar_band()
589 regd->n_reg_rules--; in ath12k_reg_update_weather_radar_band()
595 reg_rule->end_freq, max_bw); in ath12k_reg_update_weather_radar_band()
599 ath12k_reg_update_rule(regd->reg_rules + i, ETSI_WEATHER_RADAR_BAND_HIGH, in ath12k_reg_update_weather_radar_band()
600 reg_rule->end_freq, bw, in ath12k_reg_update_weather_radar_band()
601 reg_rule->ant_gain, reg_rule->reg_power, in ath12k_reg_update_weather_radar_band()
605 "\t%d. (%d - %d @ %d) (%d, %d) (%d ms) (FLAGS %d)\n", in ath12k_reg_update_weather_radar_band()
606 i + 1, ETSI_WEATHER_RADAR_BAND_HIGH, reg_rule->end_freq, in ath12k_reg_update_weather_radar_band()
607 bw, reg_rule->ant_gain, reg_rule->reg_power, in ath12k_reg_update_weather_radar_band()
608 regd->reg_rules[i].dfs_cac_ms, in ath12k_reg_update_weather_radar_band()
626 num_rules = reg_info->num_5g_reg_rules + reg_info->num_2g_reg_rules; in ath12k_reg_build_regd()
632 if (reg_info->is_ext_reg_event) in ath12k_reg_build_regd()
633 num_rules += reg_info->num_6g_reg_rules_ap[WMI_REG_INDOOR_AP]; in ath12k_reg_build_regd()
639 if (reg_info->dfs_region == ATH12K_DFS_REG_ETSI) in ath12k_reg_build_regd()
648 memcpy(tmp_regd->alpha2, reg_info->alpha2, REG_ALPHA2_LEN + 1); in ath12k_reg_build_regd()
649 memcpy(alpha2, reg_info->alpha2, REG_ALPHA2_LEN + 1); in ath12k_reg_build_regd()
651 tmp_regd->dfs_region = ath12k_map_fw_dfs_region(reg_info->dfs_region); in ath12k_reg_build_regd()
655 alpha2, ath12k_reg_get_regdom_str(tmp_regd->dfs_region), in ath12k_reg_build_regd()
656 reg_info->dfs_region, num_rules); in ath12k_reg_build_regd()
661 if (reg_info->num_2g_reg_rules && in ath12k_reg_build_regd()
662 (i < reg_info->num_2g_reg_rules)) { in ath12k_reg_build_regd()
663 reg_rule = reg_info->reg_rules_2g_ptr + i; in ath12k_reg_build_regd()
664 max_bw = min_t(u16, reg_rule->max_bw, in ath12k_reg_build_regd()
665 reg_info->max_bw_2g); in ath12k_reg_build_regd()
667 } else if (reg_info->num_5g_reg_rules && in ath12k_reg_build_regd()
668 (j < reg_info->num_5g_reg_rules)) { in ath12k_reg_build_regd()
669 reg_rule = reg_info->reg_rules_5g_ptr + j++; in ath12k_reg_build_regd()
670 max_bw = min_t(u16, reg_rule->max_bw, in ath12k_reg_build_regd()
671 reg_info->max_bw_5g); in ath12k_reg_build_regd()
680 } else if (reg_info->is_ext_reg_event && in ath12k_reg_build_regd()
681 reg_info->num_6g_reg_rules_ap[WMI_REG_INDOOR_AP] && in ath12k_reg_build_regd()
682 (k < reg_info->num_6g_reg_rules_ap[WMI_REG_INDOOR_AP])) { in ath12k_reg_build_regd()
683 reg_rule = reg_info->reg_rules_6g_ap_ptr[WMI_REG_INDOOR_AP] + k++; in ath12k_reg_build_regd()
684 max_bw = min_t(u16, reg_rule->max_bw, in ath12k_reg_build_regd()
685 reg_info->max_bw_6g_ap[WMI_REG_INDOOR_AP]); in ath12k_reg_build_regd()
691 flags |= ath12k_map_fw_reg_flags(reg_rule->flags); in ath12k_reg_build_regd()
692 flags |= ath12k_map_fw_phy_flags(reg_info->phybitmap); in ath12k_reg_build_regd()
694 ath12k_reg_update_rule(tmp_regd->reg_rules + i, in ath12k_reg_build_regd()
695 reg_rule->start_freq, in ath12k_reg_build_regd()
696 reg_rule->end_freq, max_bw, in ath12k_reg_build_regd()
697 reg_rule->ant_gain, reg_rule->reg_power, in ath12k_reg_build_regd()
706 reg_info->dfs_region == ATH12K_DFS_REG_ETSI && in ath12k_reg_build_regd()
707 (reg_rule->end_freq > ETSI_WEATHER_RADAR_BAND_LOW && in ath12k_reg_build_regd()
708 reg_rule->start_freq < ETSI_WEATHER_RADAR_BAND_HIGH)){ in ath12k_reg_build_regd()
715 if (reg_info->is_ext_reg_event) { in ath12k_reg_build_regd()
716 ath12k_dbg(ab, ATH12K_DBG_REG, "\t%d. (%d - %d @ %d) (%d, %d) (%d ms) (FLAGS %d) (%d, %d)\n", in ath12k_reg_build_regd()
717 i + 1, reg_rule->start_freq, reg_rule->end_freq, in ath12k_reg_build_regd()
718 max_bw, reg_rule->ant_gain, reg_rule->reg_power, in ath12k_reg_build_regd()
719 tmp_regd->reg_rules[i].dfs_cac_ms, in ath12k_reg_build_regd()
720 flags, reg_rule->psd_flag, reg_rule->psd_eirp); in ath12k_reg_build_regd()
723 "\t%d. (%d - %d @ %d) (%d, %d) (%d ms) (FLAGS %d)\n", in ath12k_reg_build_regd()
724 i + 1, reg_rule->start_freq, reg_rule->end_freq, in ath12k_reg_build_regd()
725 max_bw, reg_rule->ant_gain, reg_rule->reg_power, in ath12k_reg_build_regd()
726 tmp_regd->reg_rules[i].dfs_cac_ms, in ath12k_reg_build_regd()
731 tmp_regd->n_reg_rules = i; in ath12k_reg_build_regd()
734 default_regd = ab->default_regd[reg_info->phy_id]; in ath12k_reg_build_regd()
764 * the prev or default country code to the firmware. in ath12k_regd_update_work()
772 hw->wiphy->regulatory_flags = REGULATORY_WIPHY_SELF_MANAGED; in ath12k_reg_init()
773 hw->wiphy->reg_notifier = ath12k_reg_notifier; in ath12k_reg_init()
780 for (i = 0; i < ab->hw_params->max_radios; i++) { in ath12k_reg_free()
781 kfree(ab->default_regd[i]); in ath12k_reg_free()
782 kfree(ab->new_regd[i]); in ath12k_reg_free()