| 1 |
// SPDX-License-Identifier: BSD-3-Clause-Clear |
| 2 |
/* |
| 3 |
* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. |
| 4 |
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <net/mac80211.h> |
| 8 |
#include <net/cfg80211.h> |
| 9 |
#include <linux/etherdevice.h> |
| 10 |
|
| 11 |
#include "mac.h" |
| 12 |
#include "core.h" |
| 13 |
#include "debug.h" |
| 14 |
#include "wmi.h" |
| 15 |
#include "hw.h" |
| 16 |
#include "dp_tx.h" |
| 17 |
#include "dp_rx.h" |
| 18 |
#include "testmode.h" |
| 19 |
#include "peer.h" |
| 20 |
#include "debugfs.h" |
| 21 |
#include "hif.h" |
| 22 |
#include "wow.h" |
| 23 |
#include "debugfs_sta.h" |
| 24 |
#include "dp.h" |
| 25 |
#include "dp_cmn.h" |
| 26 |
|
| 27 |
#define CHAN2G(_channel, _freq, _flags) { \ |
| 28 |
.band = NL80211_BAND_2GHZ, \ |
| 29 |
.hw_value = (_channel), \ |
| 30 |
.center_freq = (_freq), \ |
| 31 |
.flags = (_flags), \ |
| 32 |
.max_antenna_gain = 0, \ |
| 33 |
.max_power = 30, \ |
| 34 |
} |
| 35 |
|
| 36 |
#define CHAN5G(_channel, _freq, _flags) { \ |
| 37 |
.band = NL80211_BAND_5GHZ, \ |
| 38 |
.hw_value = (_channel), \ |
| 39 |
.center_freq = (_freq), \ |
| 40 |
.flags = (_flags), \ |
| 41 |
.max_antenna_gain = 0, \ |
| 42 |
.max_power = 30, \ |
| 43 |
} |
| 44 |
|
| 45 |
#define CHAN6G(_channel, _freq, _flags) { \ |
| 46 |
.band = NL80211_BAND_6GHZ, \ |
| 47 |
.hw_value = (_channel), \ |
| 48 |
.center_freq = (_freq), \ |
| 49 |
.flags = (_flags), \ |
| 50 |
.max_antenna_gain = 0, \ |
| 51 |
.max_power = 30, \ |
| 52 |
} |
| 53 |
|
| 54 |
static const struct ieee80211_channel ath12k_2ghz_channels[] = { |
| 55 |
CHAN2G(1, 2412, 0), |
| 56 |
CHAN2G(2, 2417, 0), |
| 57 |
CHAN2G(3, 2422, 0), |
| 58 |
CHAN2G(4, 2427, 0), |
| 59 |
CHAN2G(5, 2432, 0), |
| 60 |
CHAN2G(6, 2437, 0), |
| 61 |
CHAN2G(7, 2442, 0), |
| 62 |
CHAN2G(8, 2447, 0), |
| 63 |
CHAN2G(9, 2452, 0), |
| 64 |
CHAN2G(10, 2457, 0), |
| 65 |
CHAN2G(11, 2462, 0), |
| 66 |
CHAN2G(12, 2467, 0), |
| 67 |
CHAN2G(13, 2472, 0), |
| 68 |
CHAN2G(14, 2484, 0), |
| 69 |
}; |
| 70 |
|
| 71 |
static const struct ieee80211_channel ath12k_5ghz_channels[] = { |
| 72 |
CHAN5G(36, 5180, 0), |
| 73 |
CHAN5G(40, 5200, 0), |
| 74 |
CHAN5G(44, 5220, 0), |
| 75 |
CHAN5G(48, 5240, 0), |
| 76 |
CHAN5G(52, 5260, 0), |
| 77 |
CHAN5G(56, 5280, 0), |
| 78 |
CHAN5G(60, 5300, 0), |
| 79 |
CHAN5G(64, 5320, 0), |
| 80 |
CHAN5G(100, 5500, 0), |
| 81 |
CHAN5G(104, 5520, 0), |
| 82 |
CHAN5G(108, 5540, 0), |
| 83 |
CHAN5G(112, 5560, 0), |
| 84 |
CHAN5G(116, 5580, 0), |
| 85 |
CHAN5G(120, 5600, 0), |
| 86 |
CHAN5G(124, 5620, 0), |
| 87 |
CHAN5G(128, 5640, 0), |
| 88 |
CHAN5G(132, 5660, 0), |
| 89 |
CHAN5G(136, 5680, 0), |
| 90 |
CHAN5G(140, 5700, 0), |
| 91 |
CHAN5G(144, 5720, 0), |
| 92 |
CHAN5G(149, 5745, 0), |
| 93 |
CHAN5G(153, 5765, 0), |
| 94 |
CHAN5G(157, 5785, 0), |
| 95 |
CHAN5G(161, 5805, 0), |
| 96 |
CHAN5G(165, 5825, 0), |
| 97 |
CHAN5G(169, 5845, 0), |
| 98 |
CHAN5G(173, 5865, 0), |
| 99 |
}; |
| 100 |
|
| 101 |
static const struct ieee80211_channel ath12k_6ghz_channels[] = { |
| 102 |
/* Operating Class 136 */ |
| 103 |
CHAN6G(2, 5935, 0), |
| 104 |
|
| 105 |
/* Operating Classes 131-135 */ |
| 106 |
CHAN6G(1, 5955, 0), |
| 107 |
CHAN6G(5, 5975, 0), |
| 108 |
CHAN6G(9, 5995, 0), |
| 109 |
CHAN6G(13, 6015, 0), |
| 110 |
CHAN6G(17, 6035, 0), |
| 111 |
CHAN6G(21, 6055, 0), |
| 112 |
CHAN6G(25, 6075, 0), |
| 113 |
CHAN6G(29, 6095, 0), |
| 114 |
CHAN6G(33, 6115, 0), |
| 115 |
CHAN6G(37, 6135, 0), |
| 116 |
CHAN6G(41, 6155, 0), |
| 117 |
CHAN6G(45, 6175, 0), |
| 118 |
CHAN6G(49, 6195, 0), |
| 119 |
CHAN6G(53, 6215, 0), |
| 120 |
CHAN6G(57, 6235, 0), |
| 121 |
CHAN6G(61, 6255, 0), |
| 122 |
CHAN6G(65, 6275, 0), |
| 123 |
CHAN6G(69, 6295, 0), |
| 124 |
CHAN6G(73, 6315, 0), |
| 125 |
CHAN6G(77, 6335, 0), |
| 126 |
CHAN6G(81, 6355, 0), |
| 127 |
CHAN6G(85, 6375, 0), |
| 128 |
CHAN6G(89, 6395, 0), |
| 129 |
CHAN6G(93, 6415, 0), |
| 130 |
CHAN6G(97, 6435, 0), |
| 131 |
CHAN6G(101, 6455, 0), |
| 132 |
CHAN6G(105, 6475, 0), |
| 133 |
CHAN6G(109, 6495, 0), |
| 134 |
CHAN6G(113, 6515, 0), |
| 135 |
CHAN6G(117, 6535, 0), |
| 136 |
CHAN6G(121, 6555, 0), |
| 137 |
CHAN6G(125, 6575, 0), |
| 138 |
CHAN6G(129, 6595, 0), |
| 139 |
CHAN6G(133, 6615, 0), |
| 140 |
CHAN6G(137, 6635, 0), |
| 141 |
CHAN6G(141, 6655, 0), |
| 142 |
CHAN6G(145, 6675, 0), |
| 143 |
CHAN6G(149, 6695, 0), |
| 144 |
CHAN6G(153, 6715, 0), |
| 145 |
CHAN6G(157, 6735, 0), |
| 146 |
CHAN6G(161, 6755, 0), |
| 147 |
CHAN6G(165, 6775, 0), |
| 148 |
CHAN6G(169, 6795, 0), |
| 149 |
CHAN6G(173, 6815, 0), |
| 150 |
CHAN6G(177, 6835, 0), |
| 151 |
CHAN6G(181, 6855, 0), |
| 152 |
CHAN6G(185, 6875, 0), |
| 153 |
CHAN6G(189, 6895, 0), |
| 154 |
CHAN6G(193, 6915, 0), |
| 155 |
CHAN6G(197, 6935, 0), |
| 156 |
CHAN6G(201, 6955, 0), |
| 157 |
CHAN6G(205, 6975, 0), |
| 158 |
CHAN6G(209, 6995, 0), |
| 159 |
CHAN6G(213, 7015, 0), |
| 160 |
CHAN6G(217, 7035, 0), |
| 161 |
CHAN6G(221, 7055, 0), |
| 162 |
CHAN6G(225, 7075, 0), |
| 163 |
CHAN6G(229, 7095, 0), |
| 164 |
CHAN6G(233, 7115, 0), |
| 165 |
}; |
| 166 |
|
| 167 |
#define ATH12K_MAC_RATE_A_M(bps, code) \ |
| 168 |
{ .bitrate = (bps), .hw_value = (code),\ |
| 169 |
.flags = IEEE80211_RATE_MANDATORY_A } |
| 170 |
|
| 171 |
#define ATH12K_MAC_RATE_B(bps, code, code_short) \ |
| 172 |
{ .bitrate = (bps), .hw_value = (code), .hw_value_short = (code_short),\ |
| 173 |
.flags = IEEE80211_RATE_SHORT_PREAMBLE } |
| 174 |
|
| 175 |
static struct ieee80211_rate ath12k_legacy_rates[] = { |
| 176 |
{ .bitrate = 10, |
| 177 |
.hw_value = ATH12K_HW_RATE_CCK_LP_1M }, |
| 178 |
ATH12K_MAC_RATE_B(20, ATH12K_HW_RATE_CCK_LP_2M, |
| 179 |
ATH12K_HW_RATE_CCK_SP_2M), |
| 180 |
ATH12K_MAC_RATE_B(55, ATH12K_HW_RATE_CCK_LP_5_5M, |
| 181 |
ATH12K_HW_RATE_CCK_SP_5_5M), |
| 182 |
ATH12K_MAC_RATE_B(110, ATH12K_HW_RATE_CCK_LP_11M, |
| 183 |
ATH12K_HW_RATE_CCK_SP_11M), |
| 184 |
ATH12K_MAC_RATE_A_M(60, ATH12K_HW_RATE_OFDM_6M), |
| 185 |
ATH12K_MAC_RATE_A_M(90, ATH12K_HW_RATE_OFDM_9M), |
| 186 |
ATH12K_MAC_RATE_A_M(120, ATH12K_HW_RATE_OFDM_12M), |
| 187 |
ATH12K_MAC_RATE_A_M(180, ATH12K_HW_RATE_OFDM_18M), |
| 188 |
ATH12K_MAC_RATE_A_M(240, ATH12K_HW_RATE_OFDM_24M), |
| 189 |
ATH12K_MAC_RATE_A_M(360, ATH12K_HW_RATE_OFDM_36M), |
| 190 |
ATH12K_MAC_RATE_A_M(480, ATH12K_HW_RATE_OFDM_48M), |
| 191 |
ATH12K_MAC_RATE_A_M(540, ATH12K_HW_RATE_OFDM_54M), |
| 192 |
}; |
| 193 |
|
| 194 |
static const int |
| 195 |
ath12k_phymodes[NUM_NL80211_BANDS][ATH12K_CHAN_WIDTH_NUM] = { |
| 196 |
[NL80211_BAND_2GHZ] = { |
| 197 |
[NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, |
| 198 |
[NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, |
| 199 |
[NL80211_CHAN_WIDTH_20_NOHT] = MODE_11BE_EHT20_2G, |
| 200 |
[NL80211_CHAN_WIDTH_20] = MODE_11BE_EHT20_2G, |
| 201 |
[NL80211_CHAN_WIDTH_40] = MODE_11BE_EHT40_2G, |
| 202 |
[NL80211_CHAN_WIDTH_80] = MODE_UNKNOWN, |
| 203 |
[NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN, |
| 204 |
[NL80211_CHAN_WIDTH_160] = MODE_UNKNOWN, |
| 205 |
[NL80211_CHAN_WIDTH_320] = MODE_UNKNOWN, |
| 206 |
}, |
| 207 |
[NL80211_BAND_5GHZ] = { |
| 208 |
[NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, |
| 209 |
[NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, |
| 210 |
[NL80211_CHAN_WIDTH_20_NOHT] = MODE_11BE_EHT20, |
| 211 |
[NL80211_CHAN_WIDTH_20] = MODE_11BE_EHT20, |
| 212 |
[NL80211_CHAN_WIDTH_40] = MODE_11BE_EHT40, |
| 213 |
[NL80211_CHAN_WIDTH_80] = MODE_11BE_EHT80, |
| 214 |
[NL80211_CHAN_WIDTH_160] = MODE_11BE_EHT160, |
| 215 |
[NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN, |
| 216 |
[NL80211_CHAN_WIDTH_320] = MODE_11BE_EHT320, |
| 217 |
}, |
| 218 |
[NL80211_BAND_6GHZ] = { |
| 219 |
[NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, |
| 220 |
[NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, |
| 221 |
[NL80211_CHAN_WIDTH_20_NOHT] = MODE_11BE_EHT20, |
| 222 |
[NL80211_CHAN_WIDTH_20] = MODE_11BE_EHT20, |
| 223 |
[NL80211_CHAN_WIDTH_40] = MODE_11BE_EHT40, |
| 224 |
[NL80211_CHAN_WIDTH_80] = MODE_11BE_EHT80, |
| 225 |
[NL80211_CHAN_WIDTH_160] = MODE_11BE_EHT160, |
| 226 |
[NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN, |
| 227 |
[NL80211_CHAN_WIDTH_320] = MODE_11BE_EHT320, |
| 228 |
}, |
| 229 |
|
| 230 |
}; |
| 231 |
|
| 232 |
const struct htt_rx_ring_tlv_filter ath12k_mac_mon_status_filter_default = { |
| 233 |
.rx_filter = HTT_RX_FILTER_TLV_FLAGS_MPDU_START | |
| 234 |
HTT_RX_FILTER_TLV_FLAGS_PPDU_END | |
| 235 |
HTT_RX_FILTER_TLV_FLAGS_PPDU_END_STATUS_DONE | |
| 236 |
HTT_RX_FILTER_TLV_FLAGS_PPDU_START_USER_INFO, |
| 237 |
.pkt_filter_flags0 = HTT_RX_FP_MGMT_FILTER_FLAGS0, |
| 238 |
.pkt_filter_flags1 = HTT_RX_FP_MGMT_FILTER_FLAGS1, |
| 239 |
.pkt_filter_flags2 = HTT_RX_FP_CTRL_FILTER_FLASG2, |
| 240 |
.pkt_filter_flags3 = HTT_RX_FP_DATA_FILTER_FLASG3 | |
| 241 |
HTT_RX_FP_CTRL_FILTER_FLASG3 |
| 242 |
}; |
| 243 |
|
| 244 |
#define ATH12K_MAC_FIRST_OFDM_RATE_IDX 4 |
| 245 |
#define ath12k_g_rates ath12k_legacy_rates |
| 246 |
#define ath12k_g_rates_size (ARRAY_SIZE(ath12k_legacy_rates)) |
| 247 |
#define ath12k_a_rates (ath12k_legacy_rates + 4) |
| 248 |
#define ath12k_a_rates_size (ARRAY_SIZE(ath12k_legacy_rates) - 4) |
| 249 |
|
| 250 |
#define ATH12K_MAC_SCAN_TIMEOUT_MSECS 200 /* in msecs */ |
| 251 |
|
| 252 |
static const u32 ath12k_smps_map[] = { |
| 253 |
[WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC, |
| 254 |
[WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC, |
| 255 |
[WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE, |
| 256 |
[WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE, |
| 257 |
}; |
| 258 |
|
| 259 |
static int ath12k_start_vdev_delay(struct ath12k *ar, |
| 260 |
struct ath12k_link_vif *arvif); |
| 261 |
static void ath12k_mac_stop(struct ath12k *ar); |
| 262 |
static int ath12k_mac_vdev_create(struct ath12k *ar, struct ath12k_link_vif *arvif); |
| 263 |
static int ath12k_mac_vdev_delete(struct ath12k *ar, struct ath12k_link_vif *arvif); |
| 264 |
|
| 265 |
static const char *ath12k_mac_phymode_str(enum wmi_phy_mode mode) |
| 266 |
{ |
| 267 |
switch (mode) { |
| 268 |
case MODE_11A: |
| 269 |
return "11a"; |
| 270 |
case MODE_11G: |
| 271 |
return "11g"; |
| 272 |
case MODE_11B: |
| 273 |
return "11b"; |
| 274 |
case MODE_11GONLY: |
| 275 |
return "11gonly"; |
| 276 |
case MODE_11NA_HT20: |
| 277 |
return "11na-ht20"; |
| 278 |
case MODE_11NG_HT20: |
| 279 |
return "11ng-ht20"; |
| 280 |
case MODE_11NA_HT40: |
| 281 |
return "11na-ht40"; |
| 282 |
case MODE_11NG_HT40: |
| 283 |
return "11ng-ht40"; |
| 284 |
case MODE_11AC_VHT20: |
| 285 |
return "11ac-vht20"; |
| 286 |
case MODE_11AC_VHT40: |
| 287 |
return "11ac-vht40"; |
| 288 |
case MODE_11AC_VHT80: |
| 289 |
return "11ac-vht80"; |
| 290 |
case MODE_11AC_VHT160: |
| 291 |
return "11ac-vht160"; |
| 292 |
case MODE_11AC_VHT80_80: |
| 293 |
return "11ac-vht80+80"; |
| 294 |
case MODE_11AC_VHT20_2G: |
| 295 |
return "11ac-vht20-2g"; |
| 296 |
case MODE_11AC_VHT40_2G: |
| 297 |
return "11ac-vht40-2g"; |
| 298 |
case MODE_11AC_VHT80_2G: |
| 299 |
return "11ac-vht80-2g"; |
| 300 |
case MODE_11AX_HE20: |
| 301 |
return "11ax-he20"; |
| 302 |
case MODE_11AX_HE40: |
| 303 |
return "11ax-he40"; |
| 304 |
case MODE_11AX_HE80: |
| 305 |
return "11ax-he80"; |
| 306 |
case MODE_11AX_HE80_80: |
| 307 |
return "11ax-he80+80"; |
| 308 |
case MODE_11AX_HE160: |
| 309 |
return "11ax-he160"; |
| 310 |
case MODE_11AX_HE20_2G: |
| 311 |
return "11ax-he20-2g"; |
| 312 |
case MODE_11AX_HE40_2G: |
| 313 |
return "11ax-he40-2g"; |
| 314 |
case MODE_11AX_HE80_2G: |
| 315 |
return "11ax-he80-2g"; |
| 316 |
case MODE_11BE_EHT20: |
| 317 |
return "11be-eht20"; |
| 318 |
case MODE_11BE_EHT40: |
| 319 |
return "11be-eht40"; |
| 320 |
case MODE_11BE_EHT80: |
| 321 |
return "11be-eht80"; |
| 322 |
case MODE_11BE_EHT80_80: |
| 323 |
return "11be-eht80+80"; |
| 324 |
case MODE_11BE_EHT160: |
| 325 |
return "11be-eht160"; |
| 326 |
case MODE_11BE_EHT160_160: |
| 327 |
return "11be-eht160+160"; |
| 328 |
case MODE_11BE_EHT320: |
| 329 |
return "11be-eht320"; |
| 330 |
case MODE_11BE_EHT20_2G: |
| 331 |
return "11be-eht20-2g"; |
| 332 |
case MODE_11BE_EHT40_2G: |
| 333 |
return "11be-eht40-2g"; |
| 334 |
case MODE_UNKNOWN: |
| 335 |
/* skip */ |
| 336 |
break; |
| 337 |
|
| 338 |
/* no default handler to allow compiler to check that the |
| 339 |
* enum is fully handled |
| 340 |
*/ |
| 341 |
} |
| 342 |
|
| 343 |
return "<unknown>"; |
| 344 |
} |
| 345 |
|
| 346 |
u16 ath12k_mac_he_convert_tones_to_ru_tones(u16 tones) |
| 347 |
{ |
| 348 |
switch (tones) { |
| 349 |
case 26: |
| 350 |
return RU_26; |
| 351 |
case 52: |
| 352 |
return RU_52; |
| 353 |
case 106: |
| 354 |
return RU_106; |
| 355 |
case 242: |
| 356 |
return RU_242; |
| 357 |
case 484: |
| 358 |
return RU_484; |
| 359 |
case 996: |
| 360 |
return RU_996; |
| 361 |
case (996 * 2): |
| 362 |
return RU_2X996; |
| 363 |
default: |
| 364 |
return RU_26; |
| 365 |
} |
| 366 |
} |
| 367 |
EXPORT_SYMBOL(ath12k_mac_he_convert_tones_to_ru_tones); |
| 368 |
|
| 369 |
enum nl80211_eht_gi ath12k_mac_eht_gi_to_nl80211_eht_gi(u8 sgi) |
| 370 |
{ |
| 371 |
switch (sgi) { |
| 372 |
case RX_MSDU_START_SGI_0_8_US: |
| 373 |
return NL80211_RATE_INFO_EHT_GI_0_8; |
| 374 |
case RX_MSDU_START_SGI_1_6_US: |
| 375 |
return NL80211_RATE_INFO_EHT_GI_1_6; |
| 376 |
case RX_MSDU_START_SGI_3_2_US: |
| 377 |
return NL80211_RATE_INFO_EHT_GI_3_2; |
| 378 |
default: |
| 379 |
return NL80211_RATE_INFO_EHT_GI_0_8; |
| 380 |
} |
| 381 |
} |
| 382 |
EXPORT_SYMBOL(ath12k_mac_eht_gi_to_nl80211_eht_gi); |
| 383 |
|
| 384 |
enum nl80211_eht_ru_alloc ath12k_mac_eht_ru_tones_to_nl80211_eht_ru_alloc(u16 ru_tones) |
| 385 |
{ |
| 386 |
switch (ru_tones) { |
| 387 |
case 26: |
| 388 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_26; |
| 389 |
case 52: |
| 390 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_52; |
| 391 |
case (52 + 26): |
| 392 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_52P26; |
| 393 |
case 106: |
| 394 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_106; |
| 395 |
case (106 + 26): |
| 396 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_106P26; |
| 397 |
case 242: |
| 398 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_242; |
| 399 |
case 484: |
| 400 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_484; |
| 401 |
case (484 + 242): |
| 402 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_484P242; |
| 403 |
case 996: |
| 404 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_996; |
| 405 |
case (996 + 484): |
| 406 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_996P484; |
| 407 |
case (996 + 484 + 242): |
| 408 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242; |
| 409 |
case (2 * 996): |
| 410 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_2x996; |
| 411 |
case (2 * 996 + 484): |
| 412 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484; |
| 413 |
case (3 * 996): |
| 414 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_3x996; |
| 415 |
case (3 * 996 + 484): |
| 416 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484; |
| 417 |
case (4 * 996): |
| 418 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_4x996; |
| 419 |
default: |
| 420 |
return NL80211_RATE_INFO_EHT_RU_ALLOC_26; |
| 421 |
} |
| 422 |
} |
| 423 |
EXPORT_SYMBOL(ath12k_mac_eht_ru_tones_to_nl80211_eht_ru_alloc); |
| 424 |
|
| 425 |
enum rate_info_bw |
| 426 |
ath12k_mac_bw_to_mac80211_bw(enum ath12k_supported_bw bw) |
| 427 |
{ |
| 428 |
u8 ret = RATE_INFO_BW_20; |
| 429 |
|
| 430 |
switch (bw) { |
| 431 |
case ATH12K_BW_20: |
| 432 |
ret = RATE_INFO_BW_20; |
| 433 |
break; |
| 434 |
case ATH12K_BW_40: |
| 435 |
ret = RATE_INFO_BW_40; |
| 436 |
break; |
| 437 |
case ATH12K_BW_80: |
| 438 |
ret = RATE_INFO_BW_80; |
| 439 |
break; |
| 440 |
case ATH12K_BW_160: |
| 441 |
ret = RATE_INFO_BW_160; |
| 442 |
break; |
| 443 |
case ATH12K_BW_320: |
| 444 |
ret = RATE_INFO_BW_320; |
| 445 |
break; |
| 446 |
} |
| 447 |
|
| 448 |
return ret; |
| 449 |
} |
| 450 |
EXPORT_SYMBOL(ath12k_mac_bw_to_mac80211_bw); |
| 451 |
|
| 452 |
enum ath12k_supported_bw ath12k_mac_mac80211_bw_to_ath12k_bw(enum rate_info_bw bw) |
| 453 |
{ |
| 454 |
switch (bw) { |
| 455 |
case RATE_INFO_BW_20: |
| 456 |
return ATH12K_BW_20; |
| 457 |
case RATE_INFO_BW_40: |
| 458 |
return ATH12K_BW_40; |
| 459 |
case RATE_INFO_BW_80: |
| 460 |
return ATH12K_BW_80; |
| 461 |
case RATE_INFO_BW_160: |
| 462 |
return ATH12K_BW_160; |
| 463 |
case RATE_INFO_BW_320: |
| 464 |
return ATH12K_BW_320; |
| 465 |
default: |
| 466 |
return ATH12K_BW_20; |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
int ath12k_mac_hw_ratecode_to_legacy_rate(u8 hw_rc, u8 preamble, u8 *rateidx, |
| 471 |
u16 *rate) |
| 472 |
{ |
| 473 |
/* As default, it is OFDM rates */ |
| 474 |
int i = ATH12K_MAC_FIRST_OFDM_RATE_IDX; |
| 475 |
int max_rates_idx = ath12k_g_rates_size; |
| 476 |
|
| 477 |
if (preamble == WMI_RATE_PREAMBLE_CCK) { |
| 478 |
hw_rc &= ~ATH12K_HW_RATECODE_CCK_SHORT_PREAM_MASK; |
| 479 |
i = 0; |
| 480 |
max_rates_idx = ATH12K_MAC_FIRST_OFDM_RATE_IDX; |
| 481 |
} |
| 482 |
|
| 483 |
while (i < max_rates_idx) { |
| 484 |
if (hw_rc == ath12k_legacy_rates[i].hw_value) { |
| 485 |
*rateidx = i; |
| 486 |
*rate = ath12k_legacy_rates[i].bitrate; |
| 487 |
return 0; |
| 488 |
} |
| 489 |
i++; |
| 490 |
} |
| 491 |
|
| 492 |
return -EINVAL; |
| 493 |
} |
| 494 |
EXPORT_SYMBOL(ath12k_mac_hw_ratecode_to_legacy_rate); |
| 495 |
|
| 496 |
u8 ath12k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband, |
| 497 |
u32 bitrate) |
| 498 |
{ |
| 499 |
int i; |
| 500 |
|
| 501 |
for (i = 0; i < sband->n_bitrates; i++) |
| 502 |
if (sband->bitrates[i].bitrate == bitrate) |
| 503 |
return i; |
| 504 |
|
| 505 |
return 0; |
| 506 |
} |
| 507 |
|
| 508 |
static u32 |
| 509 |
ath12k_mac_max_ht_nss(const u8 *ht_mcs_mask) |
| 510 |
{ |
| 511 |
int nss; |
| 512 |
|
| 513 |
for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--) |
| 514 |
if (ht_mcs_mask[nss]) |
| 515 |
return nss + 1; |
| 516 |
|
| 517 |
return 1; |
| 518 |
} |
| 519 |
|
| 520 |
static u32 |
| 521 |
ath12k_mac_max_vht_nss(const u16 *vht_mcs_mask) |
| 522 |
{ |
| 523 |
int nss; |
| 524 |
|
| 525 |
for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--) |
| 526 |
if (vht_mcs_mask[nss]) |
| 527 |
return nss + 1; |
| 528 |
|
| 529 |
return 1; |
| 530 |
} |
| 531 |
|
| 532 |
static u32 |
| 533 |
ath12k_mac_max_he_nss(const u16 he_mcs_mask[NL80211_HE_NSS_MAX]) |
| 534 |
{ |
| 535 |
int nss; |
| 536 |
|
| 537 |
for (nss = NL80211_HE_NSS_MAX - 1; nss >= 0; nss--) |
| 538 |
if (he_mcs_mask[nss]) |
| 539 |
return nss + 1; |
| 540 |
|
| 541 |
return 1; |
| 542 |
} |
| 543 |
|
| 544 |
static u32 |
| 545 |
ath12k_mac_max_eht_nss(const u16 eht_mcs_mask[NL80211_EHT_NSS_MAX]) |
| 546 |
{ |
| 547 |
int nss; |
| 548 |
|
| 549 |
for (nss = NL80211_EHT_NSS_MAX - 1; nss >= 0; nss--) |
| 550 |
if (eht_mcs_mask[nss]) |
| 551 |
return nss + 1; |
| 552 |
|
| 553 |
return 1; |
| 554 |
} |
| 555 |
|
| 556 |
static u32 |
| 557 |
ath12k_mac_max_eht_mcs_nss(const u8 *eht_mcs, int eht_mcs_set_size) |
| 558 |
{ |
| 559 |
int i; |
| 560 |
u8 nss = 0; |
| 561 |
|
| 562 |
for (i = 0; i < eht_mcs_set_size; i++) |
| 563 |
nss = max(nss, u8_get_bits(eht_mcs[i], IEEE80211_EHT_MCS_NSS_RX)); |
| 564 |
|
| 565 |
return nss; |
| 566 |
} |
| 567 |
|
| 568 |
static u8 ath12k_parse_mpdudensity(u8 mpdudensity) |
| 569 |
{ |
| 570 |
/* From IEEE Std 802.11-2020 defined values for "Minimum MPDU Start Spacing": |
| 571 |
* 0 for no restriction |
| 572 |
* 1 for 1/4 us |
| 573 |
* 2 for 1/2 us |
| 574 |
* 3 for 1 us |
| 575 |
* 4 for 2 us |
| 576 |
* 5 for 4 us |
| 577 |
* 6 for 8 us |
| 578 |
* 7 for 16 us |
| 579 |
*/ |
| 580 |
switch (mpdudensity) { |
| 581 |
case 0: |
| 582 |
return 0; |
| 583 |
case 1: |
| 584 |
case 2: |
| 585 |
case 3: |
| 586 |
/* Our lower layer calculations limit our precision to |
| 587 |
* 1 microsecond |
| 588 |
*/ |
| 589 |
return 1; |
| 590 |
case 4: |
| 591 |
return 2; |
| 592 |
case 5: |
| 593 |
return 4; |
| 594 |
case 6: |
| 595 |
return 8; |
| 596 |
case 7: |
| 597 |
return 16; |
| 598 |
default: |
| 599 |
return 0; |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
static int ath12k_mac_vif_link_chan(struct ieee80211_vif *vif, u8 link_id, |
| 604 |
struct cfg80211_chan_def *def) |
| 605 |
{ |
| 606 |
struct ieee80211_bss_conf *link_conf; |
| 607 |
struct ieee80211_chanctx_conf *conf; |
| 608 |
|
| 609 |
rcu_read_lock(); |
| 610 |
link_conf = rcu_dereference(vif->link_conf[link_id]); |
| 611 |
|
| 612 |
if (!link_conf) { |
| 613 |
rcu_read_unlock(); |
| 614 |
return -ENOLINK; |
| 615 |
} |
| 616 |
|
| 617 |
conf = rcu_dereference(link_conf->chanctx_conf); |
| 618 |
if (!conf) { |
| 619 |
rcu_read_unlock(); |
| 620 |
return -ENOENT; |
| 621 |
} |
| 622 |
*def = conf->def; |
| 623 |
rcu_read_unlock(); |
| 624 |
|
| 625 |
return 0; |
| 626 |
} |
| 627 |
|
| 628 |
static struct ath12k_link_vif * |
| 629 |
ath12k_mac_get_tx_arvif(struct ath12k_link_vif *arvif, |
| 630 |
struct ieee80211_bss_conf *link_conf) |
| 631 |
{ |
| 632 |
struct ieee80211_bss_conf *tx_bss_conf; |
| 633 |
struct ath12k *ar = arvif->ar; |
| 634 |
struct ath12k_vif *tx_ahvif; |
| 635 |
|
| 636 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 637 |
|
| 638 |
tx_bss_conf = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, |
| 639 |
link_conf->tx_bss_conf); |
| 640 |
if (tx_bss_conf) { |
| 641 |
tx_ahvif = ath12k_vif_to_ahvif(tx_bss_conf->vif); |
| 642 |
return wiphy_dereference(tx_ahvif->ah->hw->wiphy, |
| 643 |
tx_ahvif->link[tx_bss_conf->link_id]); |
| 644 |
} |
| 645 |
|
| 646 |
return NULL; |
| 647 |
} |
| 648 |
|
| 649 |
static const u8 *ath12k_mac_get_tx_bssid(struct ath12k_link_vif *arvif) |
| 650 |
{ |
| 651 |
struct ieee80211_bss_conf *link_conf; |
| 652 |
struct ath12k_link_vif *tx_arvif; |
| 653 |
struct ath12k *ar = arvif->ar; |
| 654 |
|
| 655 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 656 |
|
| 657 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 658 |
if (!link_conf) { |
| 659 |
ath12k_warn(ar->ab, |
| 660 |
"unable to access bss link conf for link %u required to retrieve transmitting link conf\n", |
| 661 |
arvif->link_id); |
| 662 |
return NULL; |
| 663 |
} |
| 664 |
if (link_conf->vif->type == NL80211_IFTYPE_STATION) { |
| 665 |
if (link_conf->nontransmitted) |
| 666 |
return link_conf->transmitter_bssid; |
| 667 |
} else { |
| 668 |
tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf); |
| 669 |
if (tx_arvif) |
| 670 |
return tx_arvif->bssid; |
| 671 |
} |
| 672 |
|
| 673 |
return NULL; |
| 674 |
} |
| 675 |
|
| 676 |
struct ieee80211_bss_conf * |
| 677 |
ath12k_mac_get_link_bss_conf(struct ath12k_link_vif *arvif) |
| 678 |
{ |
| 679 |
struct ieee80211_vif *vif = arvif->ahvif->vif; |
| 680 |
struct ieee80211_bss_conf *link_conf; |
| 681 |
struct ath12k *ar = arvif->ar; |
| 682 |
|
| 683 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 684 |
|
| 685 |
if (arvif->link_id >= IEEE80211_MLD_MAX_NUM_LINKS) |
| 686 |
return NULL; |
| 687 |
|
| 688 |
link_conf = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, |
| 689 |
vif->link_conf[arvif->link_id]); |
| 690 |
|
| 691 |
return link_conf; |
| 692 |
} |
| 693 |
|
| 694 |
static struct ieee80211_link_sta *ath12k_mac_get_link_sta(struct ath12k_link_sta *arsta) |
| 695 |
{ |
| 696 |
struct ath12k_sta *ahsta = arsta->ahsta; |
| 697 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(ahsta); |
| 698 |
struct ieee80211_link_sta *link_sta; |
| 699 |
|
| 700 |
lockdep_assert_wiphy(ahsta->ahvif->ah->hw->wiphy); |
| 701 |
|
| 702 |
if (arsta->link_id >= IEEE80211_MLD_MAX_NUM_LINKS) |
| 703 |
return NULL; |
| 704 |
|
| 705 |
link_sta = wiphy_dereference(ahsta->ahvif->ah->hw->wiphy, |
| 706 |
sta->link[arsta->link_id]); |
| 707 |
|
| 708 |
return link_sta; |
| 709 |
} |
| 710 |
|
| 711 |
static bool ath12k_mac_bitrate_is_cck(int bitrate) |
| 712 |
{ |
| 713 |
switch (bitrate) { |
| 714 |
case 10: |
| 715 |
case 20: |
| 716 |
case 55: |
| 717 |
case 110: |
| 718 |
return true; |
| 719 |
} |
| 720 |
|
| 721 |
return false; |
| 722 |
} |
| 723 |
|
| 724 |
u8 ath12k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband, |
| 725 |
u8 hw_rate, bool cck) |
| 726 |
{ |
| 727 |
const struct ieee80211_rate *rate; |
| 728 |
int i; |
| 729 |
|
| 730 |
for (i = 0; i < sband->n_bitrates; i++) { |
| 731 |
rate = &sband->bitrates[i]; |
| 732 |
|
| 733 |
if (ath12k_mac_bitrate_is_cck(rate->bitrate) != cck) |
| 734 |
continue; |
| 735 |
|
| 736 |
/* To handle 802.11a PPDU type */ |
| 737 |
if ((!cck) && (rate->hw_value == hw_rate) && |
| 738 |
(rate->flags & IEEE80211_RATE_MANDATORY_A)) |
| 739 |
return i; |
| 740 |
/* To handle 802.11b short PPDU type */ |
| 741 |
else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE && |
| 742 |
rate->hw_value_short == hw_rate) |
| 743 |
return i; |
| 744 |
/* To handle 802.11b long PPDU type */ |
| 745 |
else if (rate->hw_value == hw_rate) |
| 746 |
return i; |
| 747 |
} |
| 748 |
|
| 749 |
return 0; |
| 750 |
} |
| 751 |
|
| 752 |
static u8 ath12k_mac_bitrate_to_rate(int bitrate) |
| 753 |
{ |
| 754 |
return DIV_ROUND_UP(bitrate, 5) | |
| 755 |
(ath12k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0); |
| 756 |
} |
| 757 |
|
| 758 |
static void ath12k_get_arvif_iter(void *data, u8 *mac, |
| 759 |
struct ieee80211_vif *vif) |
| 760 |
{ |
| 761 |
struct ath12k_vif_iter *arvif_iter = data; |
| 762 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 763 |
unsigned long links_map = ahvif->links_map; |
| 764 |
struct ath12k_link_vif *arvif; |
| 765 |
u8 link_id; |
| 766 |
|
| 767 |
for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 768 |
arvif = rcu_dereference(ahvif->link[link_id]); |
| 769 |
|
| 770 |
if (WARN_ON(!arvif)) |
| 771 |
continue; |
| 772 |
|
| 773 |
if (!arvif->is_created) |
| 774 |
continue; |
| 775 |
|
| 776 |
if (arvif->vdev_id == arvif_iter->vdev_id && |
| 777 |
arvif->ar == arvif_iter->ar) { |
| 778 |
arvif_iter->arvif = arvif; |
| 779 |
break; |
| 780 |
} |
| 781 |
} |
| 782 |
} |
| 783 |
|
| 784 |
struct ath12k_link_vif *ath12k_mac_get_arvif(struct ath12k *ar, u32 vdev_id) |
| 785 |
{ |
| 786 |
struct ath12k_vif_iter arvif_iter = {}; |
| 787 |
u32 flags; |
| 788 |
|
| 789 |
/* To use the arvif returned, caller must have held rcu read lock. |
| 790 |
*/ |
| 791 |
WARN_ON(!rcu_read_lock_any_held()); |
| 792 |
arvif_iter.vdev_id = vdev_id; |
| 793 |
arvif_iter.ar = ar; |
| 794 |
|
| 795 |
flags = IEEE80211_IFACE_ITER_RESUME_ALL; |
| 796 |
ieee80211_iterate_active_interfaces_atomic(ath12k_ar_to_hw(ar), |
| 797 |
flags, |
| 798 |
ath12k_get_arvif_iter, |
| 799 |
&arvif_iter); |
| 800 |
if (!arvif_iter.arvif) { |
| 801 |
ath12k_warn(ar->ab, "No VIF found for vdev %d\n", vdev_id); |
| 802 |
return NULL; |
| 803 |
} |
| 804 |
|
| 805 |
return arvif_iter.arvif; |
| 806 |
} |
| 807 |
|
| 808 |
struct ath12k_link_vif *ath12k_mac_get_arvif_by_vdev_id(struct ath12k_base *ab, |
| 809 |
u32 vdev_id) |
| 810 |
{ |
| 811 |
int i; |
| 812 |
struct ath12k_pdev *pdev; |
| 813 |
struct ath12k_link_vif *arvif; |
| 814 |
|
| 815 |
for (i = 0; i < ab->num_radios; i++) { |
| 816 |
pdev = rcu_dereference(ab->pdevs_active[i]); |
| 817 |
if (pdev && pdev->ar && |
| 818 |
(pdev->ar->allocated_vdev_map & (1LL << vdev_id))) { |
| 819 |
arvif = ath12k_mac_get_arvif(pdev->ar, vdev_id); |
| 820 |
if (arvif) |
| 821 |
return arvif; |
| 822 |
} |
| 823 |
} |
| 824 |
|
| 825 |
return NULL; |
| 826 |
} |
| 827 |
|
| 828 |
struct ath12k *ath12k_mac_get_ar_by_vdev_id(struct ath12k_base *ab, u32 vdev_id) |
| 829 |
{ |
| 830 |
int i; |
| 831 |
struct ath12k_pdev *pdev; |
| 832 |
|
| 833 |
for (i = 0; i < ab->num_radios; i++) { |
| 834 |
pdev = rcu_dereference(ab->pdevs_active[i]); |
| 835 |
if (pdev && pdev->ar) { |
| 836 |
if (pdev->ar->allocated_vdev_map & (1LL << vdev_id)) |
| 837 |
return pdev->ar; |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
return NULL; |
| 842 |
} |
| 843 |
|
| 844 |
struct ath12k *ath12k_mac_get_ar_by_pdev_id(struct ath12k_base *ab, u32 pdev_id) |
| 845 |
{ |
| 846 |
int i; |
| 847 |
struct ath12k_pdev *pdev; |
| 848 |
|
| 849 |
if (ab->hw_params->single_pdev_only) { |
| 850 |
pdev = rcu_dereference(ab->pdevs_active[0]); |
| 851 |
return pdev ? pdev->ar : NULL; |
| 852 |
} |
| 853 |
|
| 854 |
if (WARN_ON(pdev_id > ab->num_radios)) |
| 855 |
return NULL; |
| 856 |
|
| 857 |
for (i = 0; i < ab->num_radios; i++) { |
| 858 |
if (ab->fw_mode == ATH12K_FIRMWARE_MODE_FTM) |
| 859 |
pdev = &ab->pdevs[i]; |
| 860 |
else |
| 861 |
pdev = rcu_dereference(ab->pdevs_active[i]); |
| 862 |
|
| 863 |
if (pdev && pdev->pdev_id == pdev_id) |
| 864 |
return (pdev->ar ? pdev->ar : NULL); |
| 865 |
} |
| 866 |
|
| 867 |
return NULL; |
| 868 |
} |
| 869 |
|
| 870 |
static bool ath12k_mac_is_ml_arvif(struct ath12k_link_vif *arvif) |
| 871 |
{ |
| 872 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 873 |
|
| 874 |
lockdep_assert_wiphy(ahvif->ah->hw->wiphy); |
| 875 |
|
| 876 |
if (ahvif->vif->valid_links & BIT(arvif->link_id)) |
| 877 |
return true; |
| 878 |
|
| 879 |
return false; |
| 880 |
} |
| 881 |
|
| 882 |
static struct ath12k *ath12k_mac_get_ar_by_chan(struct ieee80211_hw *hw, |
| 883 |
struct ieee80211_channel *channel) |
| 884 |
{ |
| 885 |
struct ath12k_hw *ah = hw->priv; |
| 886 |
struct ath12k *ar; |
| 887 |
int i; |
| 888 |
|
| 889 |
ar = ah->radio; |
| 890 |
|
| 891 |
if (ah->num_radio == 1) |
| 892 |
return ar; |
| 893 |
|
| 894 |
for_each_ar(ah, ar, i) { |
| 895 |
if (channel->center_freq >= KHZ_TO_MHZ(ar->freq_range.start_freq) && |
| 896 |
channel->center_freq <= KHZ_TO_MHZ(ar->freq_range.end_freq)) |
| 897 |
return ar; |
| 898 |
} |
| 899 |
return NULL; |
| 900 |
} |
| 901 |
|
| 902 |
static struct ath12k *ath12k_get_ar_by_ctx(struct ieee80211_hw *hw, |
| 903 |
struct ieee80211_chanctx_conf *ctx) |
| 904 |
{ |
| 905 |
if (!ctx) |
| 906 |
return NULL; |
| 907 |
|
| 908 |
return ath12k_mac_get_ar_by_chan(hw, ctx->def.chan); |
| 909 |
} |
| 910 |
|
| 911 |
struct ath12k *ath12k_get_ar_by_vif(struct ieee80211_hw *hw, |
| 912 |
struct ieee80211_vif *vif, |
| 913 |
u8 link_id) |
| 914 |
{ |
| 915 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 916 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 917 |
struct ath12k_link_vif *arvif; |
| 918 |
|
| 919 |
lockdep_assert_wiphy(hw->wiphy); |
| 920 |
|
| 921 |
/* If there is one pdev within ah, then we return |
| 922 |
* ar directly. |
| 923 |
*/ |
| 924 |
if (ah->num_radio == 1) |
| 925 |
return ah->radio; |
| 926 |
|
| 927 |
if (!(ahvif->links_map & BIT(link_id))) |
| 928 |
return NULL; |
| 929 |
|
| 930 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 931 |
if (arvif && arvif->is_created) |
| 932 |
return arvif->ar; |
| 933 |
|
| 934 |
return NULL; |
| 935 |
} |
| 936 |
|
| 937 |
void ath12k_mac_get_any_chanctx_conf_iter(struct ieee80211_hw *hw, |
| 938 |
struct ieee80211_chanctx_conf *conf, |
| 939 |
void *data) |
| 940 |
{ |
| 941 |
struct ath12k_mac_get_any_chanctx_conf_arg *arg = data; |
| 942 |
struct ath12k *ctx_ar = ath12k_get_ar_by_ctx(hw, conf); |
| 943 |
|
| 944 |
if (ctx_ar == arg->ar) |
| 945 |
arg->chanctx_conf = conf; |
| 946 |
} |
| 947 |
|
| 948 |
static struct ath12k_link_vif *ath12k_mac_get_vif_up(struct ath12k *ar) |
| 949 |
{ |
| 950 |
struct ath12k_link_vif *arvif; |
| 951 |
|
| 952 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 953 |
|
| 954 |
list_for_each_entry(arvif, &ar->arvifs, list) { |
| 955 |
if (arvif->is_up) |
| 956 |
return arvif; |
| 957 |
} |
| 958 |
|
| 959 |
return NULL; |
| 960 |
} |
| 961 |
|
| 962 |
static bool ath12k_mac_band_match(enum nl80211_band band1, enum WMI_HOST_WLAN_BAND band2) |
| 963 |
{ |
| 964 |
switch (band1) { |
| 965 |
case NL80211_BAND_2GHZ: |
| 966 |
if (band2 & WMI_HOST_WLAN_2GHZ_CAP) |
| 967 |
return true; |
| 968 |
break; |
| 969 |
case NL80211_BAND_5GHZ: |
| 970 |
case NL80211_BAND_6GHZ: |
| 971 |
if (band2 & WMI_HOST_WLAN_5GHZ_CAP) |
| 972 |
return true; |
| 973 |
break; |
| 974 |
default: |
| 975 |
return false; |
| 976 |
} |
| 977 |
|
| 978 |
return false; |
| 979 |
} |
| 980 |
|
| 981 |
static u8 ath12k_mac_get_target_pdev_id_from_vif(struct ath12k_link_vif *arvif) |
| 982 |
{ |
| 983 |
struct ath12k *ar = arvif->ar; |
| 984 |
struct ath12k_base *ab = ar->ab; |
| 985 |
struct ieee80211_vif *vif = arvif->ahvif->vif; |
| 986 |
struct cfg80211_chan_def def; |
| 987 |
enum nl80211_band band; |
| 988 |
u8 pdev_id = ab->fw_pdev[0].pdev_id; |
| 989 |
int i; |
| 990 |
|
| 991 |
if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
| 992 |
return pdev_id; |
| 993 |
|
| 994 |
band = def.chan->band; |
| 995 |
|
| 996 |
for (i = 0; i < ab->fw_pdev_count; i++) { |
| 997 |
if (ath12k_mac_band_match(band, ab->fw_pdev[i].supported_bands)) |
| 998 |
return ab->fw_pdev[i].pdev_id; |
| 999 |
} |
| 1000 |
|
| 1001 |
return pdev_id; |
| 1002 |
} |
| 1003 |
|
| 1004 |
u8 ath12k_mac_get_target_pdev_id(struct ath12k *ar) |
| 1005 |
{ |
| 1006 |
struct ath12k_link_vif *arvif; |
| 1007 |
struct ath12k_base *ab = ar->ab; |
| 1008 |
|
| 1009 |
if (!ab->hw_params->single_pdev_only) |
| 1010 |
return ar->pdev->pdev_id; |
| 1011 |
|
| 1012 |
arvif = ath12k_mac_get_vif_up(ar); |
| 1013 |
|
| 1014 |
/* fw_pdev array has pdev ids derived from phy capability |
| 1015 |
* service ready event (pdev_and_hw_link_ids). |
| 1016 |
* If no vif is active, return default first index. |
| 1017 |
*/ |
| 1018 |
if (!arvif) |
| 1019 |
return ar->ab->fw_pdev[0].pdev_id; |
| 1020 |
|
| 1021 |
/* If active vif is found, return the pdev id matching chandef band */ |
| 1022 |
return ath12k_mac_get_target_pdev_id_from_vif(arvif); |
| 1023 |
} |
| 1024 |
|
| 1025 |
static void ath12k_pdev_caps_update(struct ath12k *ar) |
| 1026 |
{ |
| 1027 |
struct ath12k_base *ab = ar->ab; |
| 1028 |
|
| 1029 |
ar->max_tx_power = ab->target_caps.hw_max_tx_power; |
| 1030 |
|
| 1031 |
/* FIXME: Set min_tx_power to ab->target_caps.hw_min_tx_power. |
| 1032 |
* But since the received value in svcrdy is same as hw_max_tx_power, |
| 1033 |
* we can set ar->min_tx_power to 0 currently until |
| 1034 |
* this is fixed in firmware |
| 1035 |
*/ |
| 1036 |
ar->min_tx_power = 0; |
| 1037 |
|
| 1038 |
ar->txpower_limit_2g = ar->max_tx_power; |
| 1039 |
ar->txpower_limit_5g = ar->max_tx_power; |
| 1040 |
ar->txpower_scale = WMI_HOST_TP_SCALE_MAX; |
| 1041 |
} |
| 1042 |
|
| 1043 |
static int ath12k_mac_txpower_recalc(struct ath12k *ar) |
| 1044 |
{ |
| 1045 |
struct ath12k_pdev *pdev = ar->pdev; |
| 1046 |
struct ath12k_link_vif *arvif; |
| 1047 |
int ret, txpower = -1; |
| 1048 |
u32 param; |
| 1049 |
|
| 1050 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 1051 |
|
| 1052 |
list_for_each_entry(arvif, &ar->arvifs, list) { |
| 1053 |
if (arvif->txpower <= 0) |
| 1054 |
continue; |
| 1055 |
|
| 1056 |
if (txpower == -1) |
| 1057 |
txpower = arvif->txpower; |
| 1058 |
else |
| 1059 |
txpower = min(txpower, arvif->txpower); |
| 1060 |
} |
| 1061 |
|
| 1062 |
if (txpower == -1) |
| 1063 |
return 0; |
| 1064 |
|
| 1065 |
/* txpwr is set as 2 units per dBm in FW*/ |
| 1066 |
txpower = min_t(u32, max_t(u32, ar->min_tx_power, txpower), |
| 1067 |
ar->max_tx_power) * 2; |
| 1068 |
|
| 1069 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower to set in hw %d\n", |
| 1070 |
txpower / 2); |
| 1071 |
|
| 1072 |
if ((pdev->cap.supported_bands & WMI_HOST_WLAN_2GHZ_CAP) && |
| 1073 |
ar->txpower_limit_2g != txpower) { |
| 1074 |
param = WMI_PDEV_PARAM_TXPOWER_LIMIT2G; |
| 1075 |
ret = ath12k_wmi_pdev_set_param(ar, param, |
| 1076 |
txpower, ar->pdev->pdev_id); |
| 1077 |
if (ret) |
| 1078 |
goto fail; |
| 1079 |
ar->txpower_limit_2g = txpower; |
| 1080 |
} |
| 1081 |
|
| 1082 |
if ((pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP) && |
| 1083 |
ar->txpower_limit_5g != txpower) { |
| 1084 |
param = WMI_PDEV_PARAM_TXPOWER_LIMIT5G; |
| 1085 |
ret = ath12k_wmi_pdev_set_param(ar, param, |
| 1086 |
txpower, ar->pdev->pdev_id); |
| 1087 |
if (ret) |
| 1088 |
goto fail; |
| 1089 |
ar->txpower_limit_5g = txpower; |
| 1090 |
} |
| 1091 |
|
| 1092 |
return 0; |
| 1093 |
|
| 1094 |
fail: |
| 1095 |
ath12k_warn(ar->ab, "failed to recalc txpower limit %d using pdev param %d: %d\n", |
| 1096 |
txpower / 2, param, ret); |
| 1097 |
return ret; |
| 1098 |
} |
| 1099 |
|
| 1100 |
static int ath12k_recalc_rtscts_prot(struct ath12k_link_vif *arvif) |
| 1101 |
{ |
| 1102 |
struct ath12k *ar = arvif->ar; |
| 1103 |
u32 vdev_param, rts_cts; |
| 1104 |
int ret; |
| 1105 |
|
| 1106 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 1107 |
|
| 1108 |
vdev_param = WMI_VDEV_PARAM_ENABLE_RTSCTS; |
| 1109 |
|
| 1110 |
/* Enable RTS/CTS protection for sw retries (when legacy stations |
| 1111 |
* are in BSS) or by default only for second rate series. |
| 1112 |
* TODO: Check if we need to enable CTS 2 Self in any case |
| 1113 |
*/ |
| 1114 |
rts_cts = WMI_USE_RTS_CTS; |
| 1115 |
|
| 1116 |
if (arvif->num_legacy_stations > 0) |
| 1117 |
rts_cts |= WMI_RTSCTS_ACROSS_SW_RETRIES << 4; |
| 1118 |
else |
| 1119 |
rts_cts |= WMI_RTSCTS_FOR_SECOND_RATESERIES << 4; |
| 1120 |
|
| 1121 |
/* Need not send duplicate param value to firmware */ |
| 1122 |
if (arvif->rtscts_prot_mode == rts_cts) |
| 1123 |
return 0; |
| 1124 |
|
| 1125 |
arvif->rtscts_prot_mode = rts_cts; |
| 1126 |
|
| 1127 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n", |
| 1128 |
arvif->vdev_id, rts_cts); |
| 1129 |
|
| 1130 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 1131 |
vdev_param, rts_cts); |
| 1132 |
if (ret) |
| 1133 |
ath12k_warn(ar->ab, "failed to recalculate rts/cts prot for vdev %d: %d\n", |
| 1134 |
arvif->vdev_id, ret); |
| 1135 |
|
| 1136 |
return ret; |
| 1137 |
} |
| 1138 |
|
| 1139 |
static int ath12k_mac_set_kickout(struct ath12k_link_vif *arvif) |
| 1140 |
{ |
| 1141 |
struct ath12k *ar = arvif->ar; |
| 1142 |
u32 param; |
| 1143 |
int ret; |
| 1144 |
|
| 1145 |
ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_STA_KICKOUT_TH, |
| 1146 |
ATH12K_KICKOUT_THRESHOLD, |
| 1147 |
ar->pdev->pdev_id); |
| 1148 |
if (ret) { |
| 1149 |
ath12k_warn(ar->ab, "failed to set kickout threshold on vdev %i: %d\n", |
| 1150 |
arvif->vdev_id, ret); |
| 1151 |
return ret; |
| 1152 |
} |
| 1153 |
|
| 1154 |
param = WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS; |
| 1155 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, |
| 1156 |
ATH12K_KEEPALIVE_MIN_IDLE); |
| 1157 |
if (ret) { |
| 1158 |
ath12k_warn(ar->ab, "failed to set keepalive minimum idle time on vdev %i: %d\n", |
| 1159 |
arvif->vdev_id, ret); |
| 1160 |
return ret; |
| 1161 |
} |
| 1162 |
|
| 1163 |
param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS; |
| 1164 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, |
| 1165 |
ATH12K_KEEPALIVE_MAX_IDLE); |
| 1166 |
if (ret) { |
| 1167 |
ath12k_warn(ar->ab, "failed to set keepalive maximum idle time on vdev %i: %d\n", |
| 1168 |
arvif->vdev_id, ret); |
| 1169 |
return ret; |
| 1170 |
} |
| 1171 |
|
| 1172 |
param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS; |
| 1173 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, |
| 1174 |
ATH12K_KEEPALIVE_MAX_UNRESPONSIVE); |
| 1175 |
if (ret) { |
| 1176 |
ath12k_warn(ar->ab, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n", |
| 1177 |
arvif->vdev_id, ret); |
| 1178 |
return ret; |
| 1179 |
} |
| 1180 |
|
| 1181 |
return 0; |
| 1182 |
} |
| 1183 |
|
| 1184 |
static void ath12k_mac_link_sta_rhash_cleanup(void *data, struct ieee80211_sta *sta) |
| 1185 |
{ |
| 1186 |
u8 link_id; |
| 1187 |
unsigned long links_map; |
| 1188 |
struct ath12k_sta *ahsta; |
| 1189 |
struct ath12k *ar = data; |
| 1190 |
struct ath12k_link_sta *arsta; |
| 1191 |
struct ath12k_link_vif *arvif; |
| 1192 |
struct ath12k_base *ab = ar->ab; |
| 1193 |
|
| 1194 |
ahsta = ath12k_sta_to_ahsta(sta); |
| 1195 |
links_map = ahsta->links_map; |
| 1196 |
|
| 1197 |
rcu_read_lock(); |
| 1198 |
for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 1199 |
arsta = rcu_dereference(ahsta->link[link_id]); |
| 1200 |
if (!arsta) |
| 1201 |
continue; |
| 1202 |
arvif = arsta->arvif; |
| 1203 |
if (!(arvif->ar == ar)) |
| 1204 |
continue; |
| 1205 |
|
| 1206 |
spin_lock_bh(&ab->base_lock); |
| 1207 |
ath12k_link_sta_rhash_delete(ab, arsta); |
| 1208 |
spin_unlock_bh(&ab->base_lock); |
| 1209 |
} |
| 1210 |
rcu_read_unlock(); |
| 1211 |
} |
| 1212 |
|
| 1213 |
void ath12k_mac_peer_cleanup_all(struct ath12k *ar) |
| 1214 |
{ |
| 1215 |
struct ath12k_dp_link_peer *peer, *tmp; |
| 1216 |
struct ath12k_base *ab = ar->ab; |
| 1217 |
struct ath12k_dp *dp = ath12k_ab_to_dp(ab); |
| 1218 |
struct ath12k_link_vif *arvif, *tmp_vif; |
| 1219 |
struct ath12k_dp_hw *dp_hw = &ar->ah->dp_hw; |
| 1220 |
struct ath12k_dp_peer *dp_peer = NULL; |
| 1221 |
u16 peerid_index; |
| 1222 |
struct list_head peers; |
| 1223 |
|
| 1224 |
INIT_LIST_HEAD(&peers); |
| 1225 |
|
| 1226 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 1227 |
|
| 1228 |
spin_lock_bh(&dp->dp_lock); |
| 1229 |
list_for_each_entry_safe(peer, tmp, &dp->peers, list) { |
| 1230 |
/* Skip Rx TID cleanup for self peer */ |
| 1231 |
if (peer->sta && peer->dp_peer) |
| 1232 |
ath12k_dp_rx_peer_tid_cleanup(ar, peer); |
| 1233 |
|
| 1234 |
/* cleanup dp peer */ |
| 1235 |
spin_lock_bh(&dp_hw->peer_lock); |
| 1236 |
dp_peer = peer->dp_peer; |
| 1237 |
peerid_index = ath12k_dp_peer_get_peerid_index(dp, peer->peer_id); |
| 1238 |
rcu_assign_pointer(dp_peer->link_peers[peer->link_id], NULL); |
| 1239 |
rcu_assign_pointer(dp_hw->dp_peers[peerid_index], NULL); |
| 1240 |
spin_unlock_bh(&dp_hw->peer_lock); |
| 1241 |
|
| 1242 |
ath12k_dp_link_peer_rhash_delete(dp, peer); |
| 1243 |
|
| 1244 |
list_move(&peer->list, &peers); |
| 1245 |
} |
| 1246 |
spin_unlock_bh(&dp->dp_lock); |
| 1247 |
|
| 1248 |
synchronize_rcu(); |
| 1249 |
|
| 1250 |
list_for_each_entry_safe(peer, tmp, &peers, list) { |
| 1251 |
ath12k_dp_link_peer_free(peer); |
| 1252 |
} |
| 1253 |
|
| 1254 |
ar->num_peers = 0; |
| 1255 |
ar->num_stations = 0; |
| 1256 |
|
| 1257 |
/* Cleanup rhash table maintained for arsta by iterating over sta */ |
| 1258 |
ieee80211_iterate_stations_mtx(ar->ah->hw, ath12k_mac_link_sta_rhash_cleanup, |
| 1259 |
ar); |
| 1260 |
|
| 1261 |
/* Delete all the self dp_peers on asserted radio */ |
| 1262 |
list_for_each_entry_safe_reverse(arvif, tmp_vif, &ar->arvifs, list) { |
| 1263 |
if ((arvif->ahvif->vdev_type == WMI_VDEV_TYPE_AP) && |
| 1264 |
(arvif->link_id < IEEE80211_MLD_MAX_NUM_LINKS)) { |
| 1265 |
ath12k_dp_peer_delete(dp_hw, arvif->bssid, NULL); |
| 1266 |
arvif->num_stations = 0; |
| 1267 |
} |
| 1268 |
} |
| 1269 |
} |
| 1270 |
|
| 1271 |
void ath12k_mac_dp_peer_cleanup(struct ath12k_hw *ah) |
| 1272 |
{ |
| 1273 |
struct list_head peers; |
| 1274 |
struct ath12k_dp_peer *dp_peer, *tmp; |
| 1275 |
struct ath12k_dp_hw *dp_hw = &ah->dp_hw; |
| 1276 |
|
| 1277 |
INIT_LIST_HEAD(&peers); |
| 1278 |
|
| 1279 |
spin_lock_bh(&dp_hw->peer_lock); |
| 1280 |
list_for_each_entry_safe(dp_peer, tmp, &dp_hw->dp_peers_list, list) { |
| 1281 |
if (dp_peer->is_mlo) { |
| 1282 |
rcu_assign_pointer(dp_hw->dp_peers[dp_peer->peer_id], NULL); |
| 1283 |
clear_bit(dp_peer->peer_id, ah->free_ml_peer_id_map); |
| 1284 |
} |
| 1285 |
|
| 1286 |
list_move(&dp_peer->list, &peers); |
| 1287 |
} |
| 1288 |
|
| 1289 |
spin_unlock_bh(&dp_hw->peer_lock); |
| 1290 |
|
| 1291 |
synchronize_rcu(); |
| 1292 |
|
| 1293 |
list_for_each_entry_safe(dp_peer, tmp, &peers, list) { |
| 1294 |
list_del(&dp_peer->list); |
| 1295 |
kfree(dp_peer); |
| 1296 |
} |
| 1297 |
} |
| 1298 |
|
| 1299 |
static int ath12k_mac_vdev_setup_sync(struct ath12k *ar) |
| 1300 |
{ |
| 1301 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 1302 |
|
| 1303 |
if (test_bit(ATH12K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags)) |
| 1304 |
return -ESHUTDOWN; |
| 1305 |
|
| 1306 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "vdev setup timeout %d\n", |
| 1307 |
ATH12K_VDEV_SETUP_TIMEOUT_HZ); |
| 1308 |
|
| 1309 |
if (!wait_for_completion_timeout(&ar->vdev_setup_done, |
| 1310 |
ATH12K_VDEV_SETUP_TIMEOUT_HZ)) |
| 1311 |
return -ETIMEDOUT; |
| 1312 |
|
| 1313 |
return ar->last_wmi_vdev_start_status ? -EINVAL : 0; |
| 1314 |
} |
| 1315 |
|
| 1316 |
static int ath12k_monitor_vdev_up(struct ath12k *ar, int vdev_id) |
| 1317 |
{ |
| 1318 |
struct ath12k_wmi_vdev_up_params params = {}; |
| 1319 |
int ret; |
| 1320 |
|
| 1321 |
params.vdev_id = vdev_id; |
| 1322 |
params.bssid = ar->mac_addr; |
| 1323 |
ret = ath12k_wmi_vdev_up(ar, ¶ms); |
| 1324 |
if (ret) { |
| 1325 |
ath12k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n", |
| 1326 |
vdev_id, ret); |
| 1327 |
return ret; |
| 1328 |
} |
| 1329 |
|
| 1330 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i started\n", |
| 1331 |
vdev_id); |
| 1332 |
return 0; |
| 1333 |
} |
| 1334 |
|
| 1335 |
static int ath12k_mac_monitor_vdev_start(struct ath12k *ar, int vdev_id, |
| 1336 |
struct cfg80211_chan_def *chandef) |
| 1337 |
{ |
| 1338 |
struct ieee80211_channel *channel; |
| 1339 |
struct wmi_vdev_start_req_arg arg = {}; |
| 1340 |
struct ath12k_wmi_vdev_up_params params = {}; |
| 1341 |
int ret; |
| 1342 |
|
| 1343 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 1344 |
|
| 1345 |
channel = chandef->chan; |
| 1346 |
arg.vdev_id = vdev_id; |
| 1347 |
arg.freq = channel->center_freq; |
| 1348 |
arg.band_center_freq1 = chandef->center_freq1; |
| 1349 |
arg.band_center_freq2 = chandef->center_freq2; |
| 1350 |
arg.mode = ath12k_phymodes[chandef->chan->band][chandef->width]; |
| 1351 |
arg.chan_radar = !!(channel->flags & IEEE80211_CHAN_RADAR); |
| 1352 |
|
| 1353 |
arg.min_power = 0; |
| 1354 |
arg.max_power = channel->max_power; |
| 1355 |
arg.max_reg_power = channel->max_reg_power; |
| 1356 |
arg.max_antenna_gain = channel->max_antenna_gain; |
| 1357 |
|
| 1358 |
arg.pref_tx_streams = ar->num_tx_chains; |
| 1359 |
arg.pref_rx_streams = ar->num_rx_chains; |
| 1360 |
arg.punct_bitmap = 0xFFFFFFFF; |
| 1361 |
|
| 1362 |
arg.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR); |
| 1363 |
|
| 1364 |
reinit_completion(&ar->vdev_setup_done); |
| 1365 |
reinit_completion(&ar->vdev_delete_done); |
| 1366 |
|
| 1367 |
ret = ath12k_wmi_vdev_start(ar, &arg, false); |
| 1368 |
if (ret) { |
| 1369 |
ath12k_warn(ar->ab, "failed to request monitor vdev %i start: %d\n", |
| 1370 |
vdev_id, ret); |
| 1371 |
return ret; |
| 1372 |
} |
| 1373 |
|
| 1374 |
ret = ath12k_mac_vdev_setup_sync(ar); |
| 1375 |
if (ret) { |
| 1376 |
ath12k_warn(ar->ab, "failed to synchronize setup for monitor vdev %i start: %d\n", |
| 1377 |
vdev_id, ret); |
| 1378 |
return ret; |
| 1379 |
} |
| 1380 |
|
| 1381 |
params.vdev_id = vdev_id; |
| 1382 |
params.bssid = ar->mac_addr; |
| 1383 |
ret = ath12k_wmi_vdev_up(ar, ¶ms); |
| 1384 |
if (ret) { |
| 1385 |
ath12k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n", |
| 1386 |
vdev_id, ret); |
| 1387 |
goto vdev_stop; |
| 1388 |
} |
| 1389 |
|
| 1390 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i started\n", |
| 1391 |
vdev_id); |
| 1392 |
return 0; |
| 1393 |
|
| 1394 |
vdev_stop: |
| 1395 |
ret = ath12k_wmi_vdev_stop(ar, vdev_id); |
| 1396 |
if (ret) |
| 1397 |
ath12k_warn(ar->ab, "failed to stop monitor vdev %i after start failure: %d\n", |
| 1398 |
vdev_id, ret); |
| 1399 |
return ret; |
| 1400 |
} |
| 1401 |
|
| 1402 |
static int ath12k_mac_monitor_vdev_stop(struct ath12k *ar) |
| 1403 |
{ |
| 1404 |
int ret; |
| 1405 |
|
| 1406 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 1407 |
|
| 1408 |
reinit_completion(&ar->vdev_setup_done); |
| 1409 |
|
| 1410 |
ret = ath12k_wmi_vdev_stop(ar, ar->monitor_vdev_id); |
| 1411 |
if (ret) |
| 1412 |
ath12k_warn(ar->ab, "failed to request monitor vdev %i stop: %d\n", |
| 1413 |
ar->monitor_vdev_id, ret); |
| 1414 |
|
| 1415 |
ret = ath12k_mac_vdev_setup_sync(ar); |
| 1416 |
if (ret) |
| 1417 |
ath12k_warn(ar->ab, "failed to synchronize monitor vdev %i stop: %d\n", |
| 1418 |
ar->monitor_vdev_id, ret); |
| 1419 |
|
| 1420 |
ret = ath12k_wmi_vdev_down(ar, ar->monitor_vdev_id); |
| 1421 |
if (ret) |
| 1422 |
ath12k_warn(ar->ab, "failed to put down monitor vdev %i: %d\n", |
| 1423 |
ar->monitor_vdev_id, ret); |
| 1424 |
|
| 1425 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i stopped\n", |
| 1426 |
ar->monitor_vdev_id); |
| 1427 |
return ret; |
| 1428 |
} |
| 1429 |
|
| 1430 |
static int ath12k_mac_monitor_vdev_delete(struct ath12k *ar) |
| 1431 |
{ |
| 1432 |
int ret; |
| 1433 |
unsigned long time_left; |
| 1434 |
|
| 1435 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 1436 |
|
| 1437 |
if (!ar->monitor_vdev_created) |
| 1438 |
return 0; |
| 1439 |
|
| 1440 |
reinit_completion(&ar->vdev_delete_done); |
| 1441 |
|
| 1442 |
ret = ath12k_wmi_vdev_delete(ar, ar->monitor_vdev_id); |
| 1443 |
if (ret) { |
| 1444 |
ath12k_warn(ar->ab, "failed to request wmi monitor vdev %i removal: %d\n", |
| 1445 |
ar->monitor_vdev_id, ret); |
| 1446 |
return ret; |
| 1447 |
} |
| 1448 |
|
| 1449 |
time_left = wait_for_completion_timeout(&ar->vdev_delete_done, |
| 1450 |
ATH12K_VDEV_DELETE_TIMEOUT_HZ); |
| 1451 |
if (time_left == 0) { |
| 1452 |
ath12k_warn(ar->ab, "Timeout in receiving vdev delete response\n"); |
| 1453 |
} else { |
| 1454 |
ar->allocated_vdev_map &= ~(1LL << ar->monitor_vdev_id); |
| 1455 |
ar->ab->free_vdev_map |= 1LL << (ar->monitor_vdev_id); |
| 1456 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %d deleted\n", |
| 1457 |
ar->monitor_vdev_id); |
| 1458 |
ar->num_created_vdevs--; |
| 1459 |
ar->monitor_vdev_id = -1; |
| 1460 |
ar->monitor_vdev_created = false; |
| 1461 |
} |
| 1462 |
|
| 1463 |
return ret; |
| 1464 |
} |
| 1465 |
|
| 1466 |
static int ath12k_mac_monitor_start(struct ath12k *ar) |
| 1467 |
{ |
| 1468 |
struct ath12k_mac_get_any_chanctx_conf_arg arg; |
| 1469 |
int ret; |
| 1470 |
|
| 1471 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 1472 |
|
| 1473 |
if (ar->monitor_started) |
| 1474 |
return 0; |
| 1475 |
|
| 1476 |
arg.ar = ar; |
| 1477 |
arg.chanctx_conf = NULL; |
| 1478 |
ieee80211_iter_chan_contexts_atomic(ath12k_ar_to_hw(ar), |
| 1479 |
ath12k_mac_get_any_chanctx_conf_iter, |
| 1480 |
&arg); |
| 1481 |
if (!arg.chanctx_conf) |
| 1482 |
return 0; |
| 1483 |
|
| 1484 |
ret = ath12k_mac_monitor_vdev_start(ar, ar->monitor_vdev_id, |
| 1485 |
&arg.chanctx_conf->def); |
| 1486 |
if (ret) { |
| 1487 |
ath12k_warn(ar->ab, "failed to start monitor vdev: %d\n", ret); |
| 1488 |
return ret; |
| 1489 |
} |
| 1490 |
|
| 1491 |
ret = ath12k_dp_tx_htt_monitor_mode_ring_config(ar, false); |
| 1492 |
if (ret) { |
| 1493 |
ath12k_warn(ar->ab, "fail to set monitor filter: %d\n", ret); |
| 1494 |
return ret; |
| 1495 |
} |
| 1496 |
|
| 1497 |
ar->monitor_started = true; |
| 1498 |
ar->num_started_vdevs++; |
| 1499 |
|
| 1500 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor started\n"); |
| 1501 |
|
| 1502 |
return 0; |
| 1503 |
} |
| 1504 |
|
| 1505 |
static int ath12k_mac_monitor_stop(struct ath12k *ar) |
| 1506 |
{ |
| 1507 |
int ret; |
| 1508 |
|
| 1509 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 1510 |
|
| 1511 |
if (!ar->monitor_started) |
| 1512 |
return 0; |
| 1513 |
|
| 1514 |
ret = ath12k_mac_monitor_vdev_stop(ar); |
| 1515 |
if (ret) { |
| 1516 |
ath12k_warn(ar->ab, "failed to stop monitor vdev: %d\n", ret); |
| 1517 |
return ret; |
| 1518 |
} |
| 1519 |
|
| 1520 |
ar->monitor_started = false; |
| 1521 |
ar->num_started_vdevs--; |
| 1522 |
ret = ath12k_dp_tx_htt_monitor_mode_ring_config(ar, true); |
| 1523 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor stopped ret %d\n", ret); |
| 1524 |
return ret; |
| 1525 |
} |
| 1526 |
|
| 1527 |
int ath12k_mac_vdev_stop(struct ath12k_link_vif *arvif) |
| 1528 |
{ |
| 1529 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 1530 |
struct ath12k *ar = arvif->ar; |
| 1531 |
int ret; |
| 1532 |
|
| 1533 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 1534 |
|
| 1535 |
reinit_completion(&ar->vdev_setup_done); |
| 1536 |
|
| 1537 |
ret = ath12k_wmi_vdev_stop(ar, arvif->vdev_id); |
| 1538 |
if (ret) { |
| 1539 |
ath12k_warn(ar->ab, "failed to stop WMI vdev %i: %d\n", |
| 1540 |
arvif->vdev_id, ret); |
| 1541 |
goto err; |
| 1542 |
} |
| 1543 |
|
| 1544 |
ret = ath12k_mac_vdev_setup_sync(ar); |
| 1545 |
if (ret) { |
| 1546 |
ath12k_warn(ar->ab, "failed to synchronize setup for vdev %i: %d\n", |
| 1547 |
arvif->vdev_id, ret); |
| 1548 |
goto err; |
| 1549 |
} |
| 1550 |
|
| 1551 |
WARN_ON(ar->num_started_vdevs == 0); |
| 1552 |
|
| 1553 |
ar->num_started_vdevs--; |
| 1554 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "vdev %pM stopped, vdev_id %d\n", |
| 1555 |
ahvif->vif->addr, arvif->vdev_id); |
| 1556 |
|
| 1557 |
if (test_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags)) { |
| 1558 |
clear_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags); |
| 1559 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "CAC Stopped for vdev %d\n", |
| 1560 |
arvif->vdev_id); |
| 1561 |
} |
| 1562 |
|
| 1563 |
return 0; |
| 1564 |
err: |
| 1565 |
return ret; |
| 1566 |
} |
| 1567 |
|
| 1568 |
int ath12k_mac_op_config(struct ieee80211_hw *hw, int radio_idx, u32 changed) |
| 1569 |
{ |
| 1570 |
return 0; |
| 1571 |
} |
| 1572 |
EXPORT_SYMBOL(ath12k_mac_op_config); |
| 1573 |
|
| 1574 |
static int ath12k_mac_setup_bcn_p2p_ie(struct ath12k_link_vif *arvif, |
| 1575 |
struct sk_buff *bcn) |
| 1576 |
{ |
| 1577 |
struct ath12k *ar = arvif->ar; |
| 1578 |
struct ieee80211_mgmt *mgmt; |
| 1579 |
const u8 *p2p_ie; |
| 1580 |
int ret; |
| 1581 |
|
| 1582 |
mgmt = (void *)bcn->data; |
| 1583 |
p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, |
| 1584 |
mgmt->u.beacon.variable, |
| 1585 |
bcn->len - (mgmt->u.beacon.variable - |
| 1586 |
bcn->data)); |
| 1587 |
if (!p2p_ie) { |
| 1588 |
ath12k_warn(ar->ab, "no P2P ie found in beacon\n"); |
| 1589 |
return -ENOENT; |
| 1590 |
} |
| 1591 |
|
| 1592 |
ret = ath12k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie); |
| 1593 |
if (ret) { |
| 1594 |
ath12k_warn(ar->ab, "failed to submit P2P GO bcn ie for vdev %i: %d\n", |
| 1595 |
arvif->vdev_id, ret); |
| 1596 |
return ret; |
| 1597 |
} |
| 1598 |
|
| 1599 |
return 0; |
| 1600 |
} |
| 1601 |
|
| 1602 |
static int ath12k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui, |
| 1603 |
u8 oui_type, size_t ie_offset) |
| 1604 |
{ |
| 1605 |
const u8 *next, *end; |
| 1606 |
size_t len; |
| 1607 |
u8 *ie; |
| 1608 |
|
| 1609 |
if (WARN_ON(skb->len < ie_offset)) |
| 1610 |
return -EINVAL; |
| 1611 |
|
| 1612 |
ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, |
| 1613 |
skb->data + ie_offset, |
| 1614 |
skb->len - ie_offset); |
| 1615 |
if (!ie) |
| 1616 |
return -ENOENT; |
| 1617 |
|
| 1618 |
len = ie[1] + 2; |
| 1619 |
end = skb->data + skb->len; |
| 1620 |
next = ie + len; |
| 1621 |
|
| 1622 |
if (WARN_ON(next > end)) |
| 1623 |
return -EINVAL; |
| 1624 |
|
| 1625 |
memmove(ie, next, end - next); |
| 1626 |
skb_trim(skb, skb->len - len); |
| 1627 |
|
| 1628 |
return 0; |
| 1629 |
} |
| 1630 |
|
| 1631 |
static void ath12k_mac_set_arvif_ies(struct ath12k_link_vif *arvif, |
| 1632 |
struct ath12k_link_vif *tx_arvif, |
| 1633 |
struct sk_buff *bcn, |
| 1634 |
u8 bssid_index, bool *nontx_profile_found) |
| 1635 |
{ |
| 1636 |
struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)bcn->data; |
| 1637 |
const struct element *elem, *nontx, *index, *nie, *ext_cap_ie; |
| 1638 |
const u8 *start, *tail; |
| 1639 |
u16 rem_len; |
| 1640 |
u8 i; |
| 1641 |
|
| 1642 |
start = bcn->data + ieee80211_get_hdrlen_from_skb(bcn) + sizeof(mgmt->u.beacon); |
| 1643 |
tail = skb_tail_pointer(bcn); |
| 1644 |
rem_len = tail - start; |
| 1645 |
|
| 1646 |
arvif->rsnie_present = false; |
| 1647 |
arvif->wpaie_present = false; |
| 1648 |
|
| 1649 |
if (cfg80211_find_ie(WLAN_EID_RSN, start, rem_len)) |
| 1650 |
arvif->rsnie_present = true; |
| 1651 |
if (cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, WLAN_OUI_TYPE_MICROSOFT_WPA, |
| 1652 |
start, rem_len)) |
| 1653 |
arvif->wpaie_present = true; |
| 1654 |
|
| 1655 |
ext_cap_ie = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, start, rem_len); |
| 1656 |
if (ext_cap_ie && ext_cap_ie->datalen >= 11 && |
| 1657 |
(ext_cap_ie->data[10] & WLAN_EXT_CAPA11_BCN_PROTECT)) |
| 1658 |
tx_arvif->beacon_prot = true; |
| 1659 |
|
| 1660 |
/* Return from here for the transmitted profile */ |
| 1661 |
if (!bssid_index) |
| 1662 |
return; |
| 1663 |
|
| 1664 |
/* Initial rsnie_present for the nontransmitted profile is set to be same as that |
| 1665 |
* of the transmitted profile. It will be changed if security configurations are |
| 1666 |
* different. |
| 1667 |
*/ |
| 1668 |
*nontx_profile_found = false; |
| 1669 |
for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, start, rem_len) { |
| 1670 |
/* Fixed minimum MBSSID element length with at least one |
| 1671 |
* nontransmitted BSSID profile is 12 bytes as given below; |
| 1672 |
* 1 (max BSSID indicator) + |
| 1673 |
* 2 (Nontransmitted BSSID profile: Subelement ID + length) + |
| 1674 |
* 4 (Nontransmitted BSSID Capabilities: tag + length + info) |
| 1675 |
* 2 (Nontransmitted BSSID SSID: tag + length) |
| 1676 |
* 3 (Nontransmitted BSSID Index: tag + length + BSSID index |
| 1677 |
*/ |
| 1678 |
if (elem->datalen < 12 || elem->data[0] < 1) |
| 1679 |
continue; /* Max BSSID indicator must be >=1 */ |
| 1680 |
|
| 1681 |
for_each_element(nontx, elem->data + 1, elem->datalen - 1) { |
| 1682 |
start = nontx->data; |
| 1683 |
|
| 1684 |
if (nontx->id != 0 || nontx->datalen < 4) |
| 1685 |
continue; /* Invalid nontransmitted profile */ |
| 1686 |
|
| 1687 |
if (nontx->data[0] != WLAN_EID_NON_TX_BSSID_CAP || |
| 1688 |
nontx->data[1] != 2) { |
| 1689 |
continue; /* Missing nontransmitted BSS capabilities */ |
| 1690 |
} |
| 1691 |
|
| 1692 |
if (nontx->data[4] != WLAN_EID_SSID) |
| 1693 |
continue; /* Missing SSID for nontransmitted BSS */ |
| 1694 |
|
| 1695 |
index = cfg80211_find_elem(WLAN_EID_MULTI_BSSID_IDX, |
| 1696 |
start, nontx->datalen); |
| 1697 |
if (!index || index->datalen < 1 || index->data[0] == 0) |
| 1698 |
continue; /* Invalid MBSSID Index element */ |
| 1699 |
|
| 1700 |
if (index->data[0] == bssid_index) { |
| 1701 |
*nontx_profile_found = true; |
| 1702 |
|
| 1703 |
/* Check if nontx BSS has beacon protection enabled */ |
| 1704 |
if (!tx_arvif->beacon_prot) { |
| 1705 |
ext_cap_ie = |
| 1706 |
cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, |
| 1707 |
nontx->data, |
| 1708 |
nontx->datalen); |
| 1709 |
if (ext_cap_ie && ext_cap_ie->datalen >= 11 && |
| 1710 |
(ext_cap_ie->data[10] & |
| 1711 |
WLAN_EXT_CAPA11_BCN_PROTECT)) |
| 1712 |
tx_arvif->beacon_prot = true; |
| 1713 |
} |
| 1714 |
|
| 1715 |
if (cfg80211_find_ie(WLAN_EID_RSN, |
| 1716 |
nontx->data, |
| 1717 |
nontx->datalen)) { |
| 1718 |
arvif->rsnie_present = true; |
| 1719 |
return; |
| 1720 |
} else if (!arvif->rsnie_present) { |
| 1721 |
return; /* Both tx and nontx BSS are open */ |
| 1722 |
} |
| 1723 |
|
| 1724 |
nie = cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE, |
| 1725 |
nontx->data, |
| 1726 |
nontx->datalen); |
| 1727 |
if (!nie || nie->datalen < 2) |
| 1728 |
return; /* Invalid non-inheritance element */ |
| 1729 |
|
| 1730 |
for (i = 1; i < nie->datalen - 1; i++) { |
| 1731 |
if (nie->data[i] == WLAN_EID_RSN) { |
| 1732 |
arvif->rsnie_present = false; |
| 1733 |
break; |
| 1734 |
} |
| 1735 |
} |
| 1736 |
|
| 1737 |
return; |
| 1738 |
} |
| 1739 |
} |
| 1740 |
} |
| 1741 |
} |
| 1742 |
|
| 1743 |
static int ath12k_mac_setup_bcn_tmpl_ema(struct ath12k_link_vif *arvif, |
| 1744 |
struct ath12k_link_vif *tx_arvif, |
| 1745 |
u8 bssid_index) |
| 1746 |
{ |
| 1747 |
struct ath12k_wmi_bcn_tmpl_ema_arg ema_args; |
| 1748 |
struct ieee80211_ema_beacons *beacons; |
| 1749 |
bool nontx_profile_found = false; |
| 1750 |
int ret = 0; |
| 1751 |
u8 i; |
| 1752 |
|
| 1753 |
beacons = ieee80211_beacon_get_template_ema_list(ath12k_ar_to_hw(tx_arvif->ar), |
| 1754 |
tx_arvif->ahvif->vif, |
| 1755 |
tx_arvif->link_id); |
| 1756 |
if (!beacons || !beacons->cnt) { |
| 1757 |
ath12k_warn(arvif->ar->ab, |
| 1758 |
"failed to get ema beacon templates from mac80211\n"); |
| 1759 |
return -EPERM; |
| 1760 |
} |
| 1761 |
|
| 1762 |
if (tx_arvif == arvif) |
| 1763 |
ath12k_mac_set_arvif_ies(arvif, tx_arvif, beacons->bcn[0].skb, 0, NULL); |
| 1764 |
|
| 1765 |
for (i = 0; i < beacons->cnt; i++) { |
| 1766 |
if (tx_arvif != arvif && !nontx_profile_found) |
| 1767 |
ath12k_mac_set_arvif_ies(arvif, tx_arvif, beacons->bcn[i].skb, |
| 1768 |
bssid_index, |
| 1769 |
&nontx_profile_found); |
| 1770 |
|
| 1771 |
ema_args.bcn_cnt = beacons->cnt; |
| 1772 |
ema_args.bcn_index = i; |
| 1773 |
ret = ath12k_wmi_bcn_tmpl(tx_arvif, &beacons->bcn[i].offs, |
| 1774 |
beacons->bcn[i].skb, &ema_args); |
| 1775 |
if (ret) { |
| 1776 |
ath12k_warn(tx_arvif->ar->ab, |
| 1777 |
"failed to set ema beacon template id %i error %d\n", |
| 1778 |
i, ret); |
| 1779 |
break; |
| 1780 |
} |
| 1781 |
} |
| 1782 |
|
| 1783 |
if (tx_arvif != arvif && !nontx_profile_found) |
| 1784 |
ath12k_warn(arvif->ar->ab, |
| 1785 |
"nontransmitted bssid index %u not found in beacon template\n", |
| 1786 |
bssid_index); |
| 1787 |
|
| 1788 |
ieee80211_beacon_free_ema_list(beacons); |
| 1789 |
return ret; |
| 1790 |
} |
| 1791 |
|
| 1792 |
static int ath12k_mac_setup_bcn_tmpl(struct ath12k_link_vif *arvif) |
| 1793 |
{ |
| 1794 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 1795 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); |
| 1796 |
struct ieee80211_bss_conf *link_conf; |
| 1797 |
struct ath12k_link_vif *tx_arvif; |
| 1798 |
struct ath12k *ar = arvif->ar; |
| 1799 |
struct ath12k_base *ab = ar->ab; |
| 1800 |
struct ieee80211_mutable_offsets offs = {}; |
| 1801 |
bool nontx_profile_found = false; |
| 1802 |
struct sk_buff *bcn; |
| 1803 |
int ret; |
| 1804 |
|
| 1805 |
if (ahvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 1806 |
return 0; |
| 1807 |
|
| 1808 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 1809 |
if (!link_conf) { |
| 1810 |
ath12k_warn(ar->ab, "unable to access bss link conf to set bcn tmpl for vif %pM link %u\n", |
| 1811 |
vif->addr, arvif->link_id); |
| 1812 |
return -ENOLINK; |
| 1813 |
} |
| 1814 |
|
| 1815 |
tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf); |
| 1816 |
if (tx_arvif) { |
| 1817 |
if (tx_arvif != arvif && arvif->is_up) |
| 1818 |
return 0; |
| 1819 |
|
| 1820 |
if (link_conf->ema_ap) |
| 1821 |
return ath12k_mac_setup_bcn_tmpl_ema(arvif, tx_arvif, |
| 1822 |
link_conf->bssid_index); |
| 1823 |
} else { |
| 1824 |
tx_arvif = arvif; |
| 1825 |
} |
| 1826 |
|
| 1827 |
bcn = ieee80211_beacon_get_template(ath12k_ar_to_hw(tx_arvif->ar), |
| 1828 |
tx_arvif->ahvif->vif, |
| 1829 |
&offs, tx_arvif->link_id); |
| 1830 |
if (!bcn) { |
| 1831 |
ath12k_warn(ab, "failed to get beacon template from mac80211\n"); |
| 1832 |
return -EPERM; |
| 1833 |
} |
| 1834 |
|
| 1835 |
if (tx_arvif == arvif) { |
| 1836 |
ath12k_mac_set_arvif_ies(arvif, tx_arvif, bcn, 0, NULL); |
| 1837 |
} else { |
| 1838 |
ath12k_mac_set_arvif_ies(arvif, tx_arvif, bcn, |
| 1839 |
link_conf->bssid_index, |
| 1840 |
&nontx_profile_found); |
| 1841 |
if (!nontx_profile_found) |
| 1842 |
ath12k_warn(ab, |
| 1843 |
"nontransmitted profile not found in beacon template\n"); |
| 1844 |
} |
| 1845 |
|
| 1846 |
if (ahvif->vif->type == NL80211_IFTYPE_AP && ahvif->vif->p2p) { |
| 1847 |
ret = ath12k_mac_setup_bcn_p2p_ie(arvif, bcn); |
| 1848 |
if (ret) { |
| 1849 |
ath12k_warn(ab, "failed to setup P2P GO bcn ie: %d\n", |
| 1850 |
ret); |
| 1851 |
goto free_bcn_skb; |
| 1852 |
} |
| 1853 |
|
| 1854 |
/* P2P IE is inserted by firmware automatically (as |
| 1855 |
* configured above) so remove it from the base beacon |
| 1856 |
* template to avoid duplicate P2P IEs in beacon frames. |
| 1857 |
*/ |
| 1858 |
ret = ath12k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, |
| 1859 |
WLAN_OUI_TYPE_WFA_P2P, |
| 1860 |
offsetof(struct ieee80211_mgmt, |
| 1861 |
u.beacon.variable)); |
| 1862 |
if (ret) { |
| 1863 |
ath12k_warn(ab, "failed to remove P2P vendor ie: %d\n", |
| 1864 |
ret); |
| 1865 |
goto free_bcn_skb; |
| 1866 |
} |
| 1867 |
} |
| 1868 |
|
| 1869 |
ret = ath12k_wmi_bcn_tmpl(arvif, &offs, bcn, NULL); |
| 1870 |
|
| 1871 |
if (ret) |
| 1872 |
ath12k_warn(ab, "failed to submit beacon template command: %d\n", |
| 1873 |
ret); |
| 1874 |
|
| 1875 |
free_bcn_skb: |
| 1876 |
kfree_skb(bcn); |
| 1877 |
return ret; |
| 1878 |
} |
| 1879 |
|
| 1880 |
static void ath12k_control_beaconing(struct ath12k_link_vif *arvif, |
| 1881 |
struct ieee80211_bss_conf *info) |
| 1882 |
{ |
| 1883 |
struct ath12k_wmi_vdev_up_params params = {}; |
| 1884 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 1885 |
struct ath12k *ar = arvif->ar; |
| 1886 |
int ret; |
| 1887 |
|
| 1888 |
lockdep_assert_wiphy(ath12k_ar_to_hw(arvif->ar)->wiphy); |
| 1889 |
|
| 1890 |
if (!info->enable_beacon) { |
| 1891 |
ret = ath12k_wmi_vdev_down(ar, arvif->vdev_id); |
| 1892 |
if (ret) |
| 1893 |
ath12k_warn(ar->ab, "failed to down vdev_id %i: %d\n", |
| 1894 |
arvif->vdev_id, ret); |
| 1895 |
|
| 1896 |
arvif->is_up = false; |
| 1897 |
return; |
| 1898 |
} |
| 1899 |
|
| 1900 |
/* Install the beacon template to the FW */ |
| 1901 |
ret = ath12k_mac_setup_bcn_tmpl(arvif); |
| 1902 |
if (ret) { |
| 1903 |
ath12k_warn(ar->ab, "failed to update bcn tmpl during vdev up: %d\n", |
| 1904 |
ret); |
| 1905 |
return; |
| 1906 |
} |
| 1907 |
|
| 1908 |
ahvif->aid = 0; |
| 1909 |
|
| 1910 |
ether_addr_copy(arvif->bssid, info->addr); |
| 1911 |
|
| 1912 |
params.vdev_id = arvif->vdev_id; |
| 1913 |
params.aid = ahvif->aid; |
| 1914 |
params.bssid = arvif->bssid; |
| 1915 |
params.tx_bssid = ath12k_mac_get_tx_bssid(arvif); |
| 1916 |
if (params.tx_bssid) { |
| 1917 |
params.nontx_profile_idx = info->bssid_index; |
| 1918 |
params.nontx_profile_cnt = 1 << info->bssid_indicator; |
| 1919 |
} |
| 1920 |
ret = ath12k_wmi_vdev_up(arvif->ar, ¶ms); |
| 1921 |
if (ret) { |
| 1922 |
ath12k_warn(ar->ab, "failed to bring up vdev %d: %i\n", |
| 1923 |
arvif->vdev_id, ret); |
| 1924 |
return; |
| 1925 |
} |
| 1926 |
|
| 1927 |
arvif->is_up = true; |
| 1928 |
|
| 1929 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id); |
| 1930 |
} |
| 1931 |
|
| 1932 |
static void ath12k_mac_handle_beacon_iter(void *data, u8 *mac, |
| 1933 |
struct ieee80211_vif *vif) |
| 1934 |
{ |
| 1935 |
struct sk_buff *skb = data; |
| 1936 |
struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 1937 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 1938 |
struct ath12k_link_vif *arvif = &ahvif->deflink; |
| 1939 |
|
| 1940 |
if (vif->type != NL80211_IFTYPE_STATION || !arvif->is_created) |
| 1941 |
return; |
| 1942 |
|
| 1943 |
if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid)) |
| 1944 |
return; |
| 1945 |
|
| 1946 |
cancel_delayed_work(&arvif->connection_loss_work); |
| 1947 |
} |
| 1948 |
|
| 1949 |
void ath12k_mac_handle_beacon(struct ath12k *ar, struct sk_buff *skb) |
| 1950 |
{ |
| 1951 |
ieee80211_iterate_active_interfaces_atomic(ath12k_ar_to_hw(ar), |
| 1952 |
IEEE80211_IFACE_ITER_NORMAL, |
| 1953 |
ath12k_mac_handle_beacon_iter, |
| 1954 |
skb); |
| 1955 |
} |
| 1956 |
|
| 1957 |
void ath12k_mac_handle_beacon_miss(struct ath12k *ar, |
| 1958 |
struct ath12k_link_vif *arvif) |
| 1959 |
{ |
| 1960 |
struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
| 1961 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 1962 |
|
| 1963 |
if (!(arvif->is_created && arvif->is_up)) |
| 1964 |
return; |
| 1965 |
|
| 1966 |
ieee80211_beacon_loss(vif); |
| 1967 |
|
| 1968 |
/* Firmware doesn't report beacon loss events repeatedly. If AP probe |
| 1969 |
* (done by mac80211) succeeds but beacons do not resume then it |
| 1970 |
* doesn't make sense to continue operation. Queue connection loss work |
| 1971 |
* which can be cancelled when beacon is received. |
| 1972 |
*/ |
| 1973 |
ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work, |
| 1974 |
ATH12K_CONNECTION_LOSS_HZ); |
| 1975 |
} |
| 1976 |
|
| 1977 |
static void ath12k_mac_vif_sta_connection_loss_work(struct work_struct *work) |
| 1978 |
{ |
| 1979 |
struct ath12k_link_vif *arvif = container_of(work, struct ath12k_link_vif, |
| 1980 |
connection_loss_work.work); |
| 1981 |
struct ieee80211_vif *vif = arvif->ahvif->vif; |
| 1982 |
|
| 1983 |
if (!arvif->is_up) |
| 1984 |
return; |
| 1985 |
|
| 1986 |
ieee80211_connection_loss(vif); |
| 1987 |
} |
| 1988 |
|
| 1989 |
static void ath12k_peer_assoc_h_basic(struct ath12k *ar, |
| 1990 |
struct ath12k_link_vif *arvif, |
| 1991 |
struct ath12k_link_sta *arsta, |
| 1992 |
struct ath12k_wmi_peer_assoc_arg *arg) |
| 1993 |
{ |
| 1994 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 1995 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 1996 |
struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
| 1997 |
struct ieee80211_bss_conf *bss_conf; |
| 1998 |
u32 aid; |
| 1999 |
|
| 2000 |
lockdep_assert_wiphy(hw->wiphy); |
| 2001 |
|
| 2002 |
if (vif->type == NL80211_IFTYPE_STATION) |
| 2003 |
aid = vif->cfg.aid; |
| 2004 |
else |
| 2005 |
aid = sta->aid; |
| 2006 |
|
| 2007 |
ether_addr_copy(arg->peer_mac, arsta->addr); |
| 2008 |
arg->vdev_id = arvif->vdev_id; |
| 2009 |
arg->peer_associd = aid; |
| 2010 |
arg->auth_flag = true; |
| 2011 |
/* TODO: STA WAR in ath10k for listen interval required? */ |
| 2012 |
arg->peer_listen_intval = hw->conf.listen_interval; |
| 2013 |
arg->peer_nss = 1; |
| 2014 |
|
| 2015 |
bss_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 2016 |
if (!bss_conf) { |
| 2017 |
ath12k_warn(ar->ab, "unable to access bss link conf in peer assoc for vif %pM link %u\n", |
| 2018 |
vif->addr, arvif->link_id); |
| 2019 |
return; |
| 2020 |
} |
| 2021 |
|
| 2022 |
arg->peer_caps = bss_conf->assoc_capability; |
| 2023 |
} |
| 2024 |
|
| 2025 |
static void ath12k_peer_assoc_h_crypto(struct ath12k *ar, |
| 2026 |
struct ath12k_link_vif *arvif, |
| 2027 |
struct ath12k_link_sta *arsta, |
| 2028 |
struct ath12k_wmi_peer_assoc_arg *arg) |
| 2029 |
{ |
| 2030 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 2031 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 2032 |
struct ieee80211_bss_conf *info; |
| 2033 |
struct cfg80211_chan_def def; |
| 2034 |
struct cfg80211_bss *bss; |
| 2035 |
struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
| 2036 |
const u8 *rsnie = NULL; |
| 2037 |
const u8 *wpaie = NULL; |
| 2038 |
|
| 2039 |
lockdep_assert_wiphy(hw->wiphy); |
| 2040 |
|
| 2041 |
info = ath12k_mac_get_link_bss_conf(arvif); |
| 2042 |
if (!info) { |
| 2043 |
ath12k_warn(ar->ab, "unable to access bss link conf for peer assoc crypto for vif %pM link %u\n", |
| 2044 |
vif->addr, arvif->link_id); |
| 2045 |
return; |
| 2046 |
} |
| 2047 |
|
| 2048 |
if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
| 2049 |
return; |
| 2050 |
|
| 2051 |
bss = cfg80211_get_bss(hw->wiphy, def.chan, info->bssid, NULL, 0, |
| 2052 |
IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY); |
| 2053 |
|
| 2054 |
if (arvif->rsnie_present || arvif->wpaie_present) { |
| 2055 |
arg->need_ptk_4_way = true; |
| 2056 |
if (arvif->wpaie_present) |
| 2057 |
arg->need_gtk_2_way = true; |
| 2058 |
} else if (bss) { |
| 2059 |
const struct cfg80211_bss_ies *ies; |
| 2060 |
|
| 2061 |
rcu_read_lock(); |
| 2062 |
rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN); |
| 2063 |
|
| 2064 |
ies = rcu_dereference(bss->ies); |
| 2065 |
|
| 2066 |
wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, |
| 2067 |
WLAN_OUI_TYPE_MICROSOFT_WPA, |
| 2068 |
ies->data, |
| 2069 |
ies->len); |
| 2070 |
rcu_read_unlock(); |
| 2071 |
cfg80211_put_bss(hw->wiphy, bss); |
| 2072 |
} |
| 2073 |
|
| 2074 |
/* FIXME: base on RSN IE/WPA IE is a correct idea? */ |
| 2075 |
if (rsnie || wpaie) { |
| 2076 |
ath12k_dbg(ar->ab, ATH12K_DBG_WMI, |
| 2077 |
"%s: rsn ie found\n", __func__); |
| 2078 |
arg->need_ptk_4_way = true; |
| 2079 |
} |
| 2080 |
|
| 2081 |
if (wpaie) { |
| 2082 |
ath12k_dbg(ar->ab, ATH12K_DBG_WMI, |
| 2083 |
"%s: wpa ie found\n", __func__); |
| 2084 |
arg->need_gtk_2_way = true; |
| 2085 |
} |
| 2086 |
|
| 2087 |
if (sta->mfp) { |
| 2088 |
/* TODO: Need to check if FW supports PMF? */ |
| 2089 |
arg->is_pmf_enabled = true; |
| 2090 |
} |
| 2091 |
|
| 2092 |
/* TODO: safe_mode_enabled (bypass 4-way handshake) flag req? */ |
| 2093 |
} |
| 2094 |
|
| 2095 |
static void ath12k_peer_assoc_h_rates(struct ath12k *ar, |
| 2096 |
struct ath12k_link_vif *arvif, |
| 2097 |
struct ath12k_link_sta *arsta, |
| 2098 |
struct ath12k_wmi_peer_assoc_arg *arg) |
| 2099 |
{ |
| 2100 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 2101 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 2102 |
struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; |
| 2103 |
struct ieee80211_link_sta *link_sta; |
| 2104 |
struct cfg80211_chan_def def; |
| 2105 |
const struct ieee80211_supported_band *sband; |
| 2106 |
const struct ieee80211_rate *rates; |
| 2107 |
struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
| 2108 |
enum nl80211_band band; |
| 2109 |
u32 ratemask; |
| 2110 |
u8 rate; |
| 2111 |
int i; |
| 2112 |
|
| 2113 |
lockdep_assert_wiphy(hw->wiphy); |
| 2114 |
|
| 2115 |
if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
| 2116 |
return; |
| 2117 |
|
| 2118 |
link_sta = ath12k_mac_get_link_sta(arsta); |
| 2119 |
if (!link_sta) { |
| 2120 |
ath12k_warn(ar->ab, "unable to access link sta in peer assoc rates for sta %pM link %u\n", |
| 2121 |
sta->addr, arsta->link_id); |
| 2122 |
return; |
| 2123 |
} |
| 2124 |
|
| 2125 |
band = def.chan->band; |
| 2126 |
sband = hw->wiphy->bands[band]; |
| 2127 |
ratemask = link_sta->supp_rates[band]; |
| 2128 |
ratemask &= arvif->bitrate_mask.control[band].legacy; |
| 2129 |
rates = sband->bitrates; |
| 2130 |
|
| 2131 |
rateset->num_rates = 0; |
| 2132 |
|
| 2133 |
for (i = 0; i < 32; i++, ratemask >>= 1, rates++) { |
| 2134 |
if (!(ratemask & 1)) |
| 2135 |
continue; |
| 2136 |
|
| 2137 |
rate = ath12k_mac_bitrate_to_rate(rates->bitrate); |
| 2138 |
rateset->rates[rateset->num_rates] = rate; |
| 2139 |
rateset->num_rates++; |
| 2140 |
} |
| 2141 |
} |
| 2142 |
|
| 2143 |
static bool |
| 2144 |
ath12k_peer_assoc_h_ht_masked(const u8 *ht_mcs_mask) |
| 2145 |
{ |
| 2146 |
int nss; |
| 2147 |
|
| 2148 |
for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++) |
| 2149 |
if (ht_mcs_mask[nss]) |
| 2150 |
return false; |
| 2151 |
|
| 2152 |
return true; |
| 2153 |
} |
| 2154 |
|
| 2155 |
static bool |
| 2156 |
ath12k_peer_assoc_h_vht_masked(const u16 *vht_mcs_mask) |
| 2157 |
{ |
| 2158 |
int nss; |
| 2159 |
|
| 2160 |
for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) |
| 2161 |
if (vht_mcs_mask[nss]) |
| 2162 |
return false; |
| 2163 |
|
| 2164 |
return true; |
| 2165 |
} |
| 2166 |
|
| 2167 |
static void ath12k_peer_assoc_h_ht(struct ath12k *ar, |
| 2168 |
struct ath12k_link_vif *arvif, |
| 2169 |
struct ath12k_link_sta *arsta, |
| 2170 |
struct ath12k_wmi_peer_assoc_arg *arg) |
| 2171 |
{ |
| 2172 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 2173 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 2174 |
const struct ieee80211_sta_ht_cap *ht_cap; |
| 2175 |
struct ieee80211_link_sta *link_sta; |
| 2176 |
struct cfg80211_chan_def def; |
| 2177 |
enum nl80211_band band; |
| 2178 |
const u8 *ht_mcs_mask; |
| 2179 |
int i, n; |
| 2180 |
u8 max_nss; |
| 2181 |
u32 stbc; |
| 2182 |
|
| 2183 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 2184 |
|
| 2185 |
if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
| 2186 |
return; |
| 2187 |
|
| 2188 |
link_sta = ath12k_mac_get_link_sta(arsta); |
| 2189 |
if (!link_sta) { |
| 2190 |
ath12k_warn(ar->ab, "unable to access link sta in peer assoc ht for sta %pM link %u\n", |
| 2191 |
sta->addr, arsta->link_id); |
| 2192 |
return; |
| 2193 |
} |
| 2194 |
|
| 2195 |
ht_cap = &link_sta->ht_cap; |
| 2196 |
if (!ht_cap->ht_supported) |
| 2197 |
return; |
| 2198 |
|
| 2199 |
band = def.chan->band; |
| 2200 |
ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; |
| 2201 |
|
| 2202 |
if (ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) |
| 2203 |
return; |
| 2204 |
|
| 2205 |
arg->ht_flag = true; |
| 2206 |
|
| 2207 |
arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 2208 |
ht_cap->ampdu_factor)) - 1; |
| 2209 |
|
| 2210 |
arg->peer_mpdu_density = |
| 2211 |
ath12k_parse_mpdudensity(ht_cap->ampdu_density); |
| 2212 |
|
| 2213 |
arg->peer_ht_caps = ht_cap->cap; |
| 2214 |
arg->peer_rate_caps |= WMI_HOST_RC_HT_FLAG; |
| 2215 |
|
| 2216 |
if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) |
| 2217 |
arg->ldpc_flag = true; |
| 2218 |
|
| 2219 |
if (link_sta->bandwidth >= IEEE80211_STA_RX_BW_40) { |
| 2220 |
arg->bw_40 = true; |
| 2221 |
arg->peer_rate_caps |= WMI_HOST_RC_CW40_FLAG; |
| 2222 |
} |
| 2223 |
|
| 2224 |
/* As firmware handles these two flags (IEEE80211_HT_CAP_SGI_20 |
| 2225 |
* and IEEE80211_HT_CAP_SGI_40) for enabling SGI, reset both |
| 2226 |
* flags if guard interval is to force Long GI |
| 2227 |
*/ |
| 2228 |
if (arvif->bitrate_mask.control[band].gi == NL80211_TXRATE_FORCE_LGI) { |
| 2229 |
arg->peer_ht_caps &= ~(IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40); |
| 2230 |
} else { |
| 2231 |
/* Enable SGI flag if either SGI_20 or SGI_40 is supported */ |
| 2232 |
if (ht_cap->cap & (IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40)) |
| 2233 |
arg->peer_rate_caps |= WMI_HOST_RC_SGI_FLAG; |
| 2234 |
} |
| 2235 |
|
| 2236 |
if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) { |
| 2237 |
arg->peer_rate_caps |= WMI_HOST_RC_TX_STBC_FLAG; |
| 2238 |
arg->stbc_flag = true; |
| 2239 |
} |
| 2240 |
|
| 2241 |
if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) { |
| 2242 |
stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC; |
| 2243 |
stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 2244 |
stbc = stbc << WMI_HOST_RC_RX_STBC_FLAG_S; |
| 2245 |
arg->peer_rate_caps |= stbc; |
| 2246 |
arg->stbc_flag = true; |
| 2247 |
} |
| 2248 |
|
| 2249 |
if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2]) |
| 2250 |
arg->peer_rate_caps |= WMI_HOST_RC_TS_FLAG; |
| 2251 |
else if (ht_cap->mcs.rx_mask[1]) |
| 2252 |
arg->peer_rate_caps |= WMI_HOST_RC_DS_FLAG; |
| 2253 |
|
| 2254 |
for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++) |
| 2255 |
if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) && |
| 2256 |
(ht_mcs_mask[i / 8] & BIT(i % 8))) { |
| 2257 |
max_nss = (i / 8) + 1; |
| 2258 |
arg->peer_ht_rates.rates[n++] = i; |
| 2259 |
} |
| 2260 |
|
| 2261 |
/* This is a workaround for HT-enabled STAs which break the spec |
| 2262 |
* and have no HT capabilities RX mask (no HT RX MCS map). |
| 2263 |
* |
| 2264 |
* As per spec, in section 20.3.5 Modulation and coding scheme (MCS), |
| 2265 |
* MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. |
| 2266 |
* |
| 2267 |
* Firmware asserts if such situation occurs. |
| 2268 |
*/ |
| 2269 |
if (n == 0) { |
| 2270 |
arg->peer_ht_rates.num_rates = 8; |
| 2271 |
for (i = 0; i < arg->peer_ht_rates.num_rates; i++) |
| 2272 |
arg->peer_ht_rates.rates[i] = i; |
| 2273 |
} else { |
| 2274 |
arg->peer_ht_rates.num_rates = n; |
| 2275 |
arg->peer_nss = min(link_sta->rx_nss, max_nss); |
| 2276 |
} |
| 2277 |
|
| 2278 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n", |
| 2279 |
arg->peer_mac, |
| 2280 |
arg->peer_ht_rates.num_rates, |
| 2281 |
arg->peer_nss); |
| 2282 |
} |
| 2283 |
|
| 2284 |
static int ath12k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss) |
| 2285 |
{ |
| 2286 |
switch ((mcs_map >> (2 * nss)) & 0x3) { |
| 2287 |
case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1; |
| 2288 |
case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1; |
| 2289 |
case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1; |
| 2290 |
} |
| 2291 |
return 0; |
| 2292 |
} |
| 2293 |
|
| 2294 |
static u16 |
| 2295 |
ath12k_peer_assoc_h_vht_limit(u16 tx_mcs_set, |
| 2296 |
const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX]) |
| 2297 |
{ |
| 2298 |
int idx_limit; |
| 2299 |
int nss; |
| 2300 |
u16 mcs_map; |
| 2301 |
u16 mcs; |
| 2302 |
|
| 2303 |
for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 2304 |
mcs_map = ath12k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) & |
| 2305 |
vht_mcs_limit[nss]; |
| 2306 |
|
| 2307 |
if (mcs_map) |
| 2308 |
idx_limit = fls(mcs_map) - 1; |
| 2309 |
else |
| 2310 |
idx_limit = -1; |
| 2311 |
|
| 2312 |
switch (idx_limit) { |
| 2313 |
case 0: |
| 2314 |
case 1: |
| 2315 |
case 2: |
| 2316 |
case 3: |
| 2317 |
case 4: |
| 2318 |
case 5: |
| 2319 |
case 6: |
| 2320 |
case 7: |
| 2321 |
mcs = IEEE80211_VHT_MCS_SUPPORT_0_7; |
| 2322 |
break; |
| 2323 |
case 8: |
| 2324 |
mcs = IEEE80211_VHT_MCS_SUPPORT_0_8; |
| 2325 |
break; |
| 2326 |
case 9: |
| 2327 |
mcs = IEEE80211_VHT_MCS_SUPPORT_0_9; |
| 2328 |
break; |
| 2329 |
default: |
| 2330 |
WARN_ON(1); |
| 2331 |
fallthrough; |
| 2332 |
case -1: |
| 2333 |
mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 2334 |
break; |
| 2335 |
} |
| 2336 |
|
| 2337 |
tx_mcs_set &= ~(0x3 << (nss * 2)); |
| 2338 |
tx_mcs_set |= mcs << (nss * 2); |
| 2339 |
} |
| 2340 |
|
| 2341 |
return tx_mcs_set; |
| 2342 |
} |
| 2343 |
|
| 2344 |
static u8 ath12k_get_nss_160mhz(struct ath12k *ar, |
| 2345 |
u8 max_nss) |
| 2346 |
{ |
| 2347 |
u8 nss_ratio_info = ar->pdev->cap.nss_ratio_info; |
| 2348 |
u8 max_sup_nss = 0; |
| 2349 |
|
| 2350 |
switch (nss_ratio_info) { |
| 2351 |
case WMI_NSS_RATIO_1BY2_NSS: |
| 2352 |
max_sup_nss = max_nss >> 1; |
| 2353 |
break; |
| 2354 |
case WMI_NSS_RATIO_3BY4_NSS: |
| 2355 |
ath12k_warn(ar->ab, "WMI_NSS_RATIO_3BY4_NSS not supported\n"); |
| 2356 |
break; |
| 2357 |
case WMI_NSS_RATIO_1_NSS: |
| 2358 |
max_sup_nss = max_nss; |
| 2359 |
break; |
| 2360 |
case WMI_NSS_RATIO_2_NSS: |
| 2361 |
ath12k_warn(ar->ab, "WMI_NSS_RATIO_2_NSS not supported\n"); |
| 2362 |
break; |
| 2363 |
default: |
| 2364 |
ath12k_warn(ar->ab, "invalid nss ratio received from fw: %d\n", |
| 2365 |
nss_ratio_info); |
| 2366 |
break; |
| 2367 |
} |
| 2368 |
|
| 2369 |
return max_sup_nss; |
| 2370 |
} |
| 2371 |
|
| 2372 |
static void ath12k_peer_assoc_h_vht(struct ath12k *ar, |
| 2373 |
struct ath12k_link_vif *arvif, |
| 2374 |
struct ath12k_link_sta *arsta, |
| 2375 |
struct ath12k_wmi_peer_assoc_arg *arg) |
| 2376 |
{ |
| 2377 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 2378 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 2379 |
const struct ieee80211_sta_vht_cap *vht_cap; |
| 2380 |
struct ieee80211_link_sta *link_sta; |
| 2381 |
struct cfg80211_chan_def def; |
| 2382 |
enum nl80211_band band; |
| 2383 |
u16 *vht_mcs_mask; |
| 2384 |
u8 ampdu_factor; |
| 2385 |
u8 max_nss, vht_mcs; |
| 2386 |
int i, vht_nss, nss_idx; |
| 2387 |
bool user_rate_valid = true; |
| 2388 |
u32 rx_nss, tx_nss, nss_160; |
| 2389 |
|
| 2390 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 2391 |
|
| 2392 |
if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
| 2393 |
return; |
| 2394 |
|
| 2395 |
link_sta = ath12k_mac_get_link_sta(arsta); |
| 2396 |
if (!link_sta) { |
| 2397 |
ath12k_warn(ar->ab, "unable to access link sta in peer assoc vht for sta %pM link %u\n", |
| 2398 |
sta->addr, arsta->link_id); |
| 2399 |
return; |
| 2400 |
} |
| 2401 |
|
| 2402 |
vht_cap = &link_sta->vht_cap; |
| 2403 |
if (!vht_cap->vht_supported) |
| 2404 |
return; |
| 2405 |
|
| 2406 |
band = def.chan->band; |
| 2407 |
vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; |
| 2408 |
|
| 2409 |
if (ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) |
| 2410 |
return; |
| 2411 |
|
| 2412 |
arg->vht_flag = true; |
| 2413 |
|
| 2414 |
/* TODO: similar flags required? */ |
| 2415 |
arg->vht_capable = true; |
| 2416 |
|
| 2417 |
if (def.chan->band == NL80211_BAND_2GHZ) |
| 2418 |
arg->vht_ng_flag = true; |
| 2419 |
|
| 2420 |
arg->peer_vht_caps = vht_cap->cap; |
| 2421 |
|
| 2422 |
ampdu_factor = (vht_cap->cap & |
| 2423 |
IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >> |
| 2424 |
IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 2425 |
|
| 2426 |
/* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to |
| 2427 |
* zero in VHT IE. Using it would result in degraded throughput. |
| 2428 |
* arg->peer_max_mpdu at this point contains HT max_mpdu so keep |
| 2429 |
* it if VHT max_mpdu is smaller. |
| 2430 |
*/ |
| 2431 |
arg->peer_max_mpdu = max(arg->peer_max_mpdu, |
| 2432 |
(1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 2433 |
ampdu_factor)) - 1); |
| 2434 |
|
| 2435 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 2436 |
arg->bw_80 = true; |
| 2437 |
|
| 2438 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) |
| 2439 |
arg->bw_160 = true; |
| 2440 |
|
| 2441 |
vht_nss = ath12k_mac_max_vht_nss(vht_mcs_mask); |
| 2442 |
|
| 2443 |
if (vht_nss > link_sta->rx_nss) { |
| 2444 |
user_rate_valid = false; |
| 2445 |
for (nss_idx = link_sta->rx_nss - 1; nss_idx >= 0; nss_idx--) { |
| 2446 |
if (vht_mcs_mask[nss_idx]) { |
| 2447 |
user_rate_valid = true; |
| 2448 |
break; |
| 2449 |
} |
| 2450 |
} |
| 2451 |
} |
| 2452 |
|
| 2453 |
if (!user_rate_valid) { |
| 2454 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 2455 |
"Setting vht range MCS value to peer supported nss:%d for peer %pM\n", |
| 2456 |
link_sta->rx_nss, arsta->addr); |
| 2457 |
vht_mcs_mask[link_sta->rx_nss - 1] = vht_mcs_mask[vht_nss - 1]; |
| 2458 |
} |
| 2459 |
|
| 2460 |
/* Calculate peer NSS capability from VHT capabilities if STA |
| 2461 |
* supports VHT. |
| 2462 |
*/ |
| 2463 |
for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 2464 |
vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >> |
| 2465 |
(2 * i) & 3; |
| 2466 |
|
| 2467 |
if (vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED && |
| 2468 |
vht_mcs_mask[i]) |
| 2469 |
max_nss = i + 1; |
| 2470 |
} |
| 2471 |
arg->peer_nss = min(link_sta->rx_nss, max_nss); |
| 2472 |
arg->rx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.rx_highest); |
| 2473 |
arg->rx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); |
| 2474 |
arg->rx_mcs_set = ath12k_peer_assoc_h_vht_limit(arg->rx_mcs_set, vht_mcs_mask); |
| 2475 |
|
| 2476 |
arg->tx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.tx_highest); |
| 2477 |
arg->tx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map); |
| 2478 |
|
| 2479 |
/* In QCN9274 platform, VHT MCS rate 10 and 11 is enabled by default. |
| 2480 |
* VHT MCS rate 10 and 11 is not supported in 11ac standard. |
| 2481 |
* so explicitly disable the VHT MCS rate 10 and 11 in 11ac mode. |
| 2482 |
*/ |
| 2483 |
arg->tx_mcs_set &= ~IEEE80211_VHT_MCS_SUPPORT_0_11_MASK; |
| 2484 |
arg->tx_mcs_set |= IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11; |
| 2485 |
|
| 2486 |
if ((arg->tx_mcs_set & IEEE80211_VHT_MCS_NOT_SUPPORTED) == |
| 2487 |
IEEE80211_VHT_MCS_NOT_SUPPORTED) |
| 2488 |
arg->peer_vht_caps &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 2489 |
|
| 2490 |
/* TODO: Check */ |
| 2491 |
arg->tx_max_mcs_nss = 0xFF; |
| 2492 |
|
| 2493 |
if (arg->peer_phymode == MODE_11AC_VHT160) { |
| 2494 |
tx_nss = ath12k_get_nss_160mhz(ar, max_nss); |
| 2495 |
rx_nss = min(arg->peer_nss, tx_nss); |
| 2496 |
arg->peer_bw_rxnss_override = ATH12K_BW_NSS_MAP_ENABLE; |
| 2497 |
|
| 2498 |
if (!rx_nss) { |
| 2499 |
ath12k_warn(ar->ab, "invalid max_nss\n"); |
| 2500 |
return; |
| 2501 |
} |
| 2502 |
|
| 2503 |
nss_160 = u32_encode_bits(rx_nss - 1, ATH12K_PEER_RX_NSS_160MHZ); |
| 2504 |
arg->peer_bw_rxnss_override |= nss_160; |
| 2505 |
} |
| 2506 |
|
| 2507 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 2508 |
"mac vht peer %pM max_mpdu %d flags 0x%x nss_override 0x%x\n", |
| 2509 |
arsta->addr, arg->peer_max_mpdu, arg->peer_flags, |
| 2510 |
arg->peer_bw_rxnss_override); |
| 2511 |
} |
| 2512 |
|
| 2513 |
static int ath12k_mac_get_max_he_mcs_map(u16 mcs_map, int nss) |
| 2514 |
{ |
| 2515 |
switch ((mcs_map >> (2 * nss)) & 0x3) { |
| 2516 |
case IEEE80211_HE_MCS_SUPPORT_0_7: return BIT(8) - 1; |
| 2517 |
case IEEE80211_HE_MCS_SUPPORT_0_9: return BIT(10) - 1; |
| 2518 |
case IEEE80211_HE_MCS_SUPPORT_0_11: return BIT(12) - 1; |
| 2519 |
} |
| 2520 |
return 0; |
| 2521 |
} |
| 2522 |
|
| 2523 |
static u16 ath12k_peer_assoc_h_he_limit(u16 tx_mcs_set, |
| 2524 |
const u16 *he_mcs_limit) |
| 2525 |
{ |
| 2526 |
int idx_limit; |
| 2527 |
int nss; |
| 2528 |
u16 mcs_map; |
| 2529 |
u16 mcs; |
| 2530 |
|
| 2531 |
for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) { |
| 2532 |
mcs_map = ath12k_mac_get_max_he_mcs_map(tx_mcs_set, nss) & |
| 2533 |
he_mcs_limit[nss]; |
| 2534 |
|
| 2535 |
if (mcs_map) |
| 2536 |
idx_limit = fls(mcs_map) - 1; |
| 2537 |
else |
| 2538 |
idx_limit = -1; |
| 2539 |
|
| 2540 |
switch (idx_limit) { |
| 2541 |
case 0 ... 7: |
| 2542 |
mcs = IEEE80211_HE_MCS_SUPPORT_0_7; |
| 2543 |
break; |
| 2544 |
case 8: |
| 2545 |
case 9: |
| 2546 |
mcs = IEEE80211_HE_MCS_SUPPORT_0_9; |
| 2547 |
break; |
| 2548 |
case 10: |
| 2549 |
case 11: |
| 2550 |
mcs = IEEE80211_HE_MCS_SUPPORT_0_11; |
| 2551 |
break; |
| 2552 |
default: |
| 2553 |
WARN_ON(1); |
| 2554 |
fallthrough; |
| 2555 |
case -1: |
| 2556 |
mcs = IEEE80211_HE_MCS_NOT_SUPPORTED; |
| 2557 |
break; |
| 2558 |
} |
| 2559 |
|
| 2560 |
tx_mcs_set &= ~(0x3 << (nss * 2)); |
| 2561 |
tx_mcs_set |= mcs << (nss * 2); |
| 2562 |
} |
| 2563 |
|
| 2564 |
return tx_mcs_set; |
| 2565 |
} |
| 2566 |
|
| 2567 |
static bool |
| 2568 |
ath12k_peer_assoc_h_he_masked(const u16 he_mcs_mask[NL80211_HE_NSS_MAX]) |
| 2569 |
{ |
| 2570 |
int nss; |
| 2571 |
|
| 2572 |
for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) |
| 2573 |
if (he_mcs_mask[nss]) |
| 2574 |
return false; |
| 2575 |
|
| 2576 |
return true; |
| 2577 |
} |
| 2578 |
|
| 2579 |
static void ath12k_peer_assoc_h_he(struct ath12k *ar, |
| 2580 |
struct ath12k_link_vif *arvif, |
| 2581 |
struct ath12k_link_sta *arsta, |
| 2582 |
struct ath12k_wmi_peer_assoc_arg *arg) |
| 2583 |
{ |
| 2584 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 2585 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 2586 |
const struct ieee80211_sta_he_cap *he_cap; |
| 2587 |
struct ieee80211_bss_conf *link_conf; |
| 2588 |
struct ieee80211_link_sta *link_sta; |
| 2589 |
struct cfg80211_chan_def def; |
| 2590 |
int i; |
| 2591 |
u8 ampdu_factor, max_nss; |
| 2592 |
u8 rx_mcs_80 = IEEE80211_HE_MCS_NOT_SUPPORTED; |
| 2593 |
u8 rx_mcs_160 = IEEE80211_HE_MCS_NOT_SUPPORTED; |
| 2594 |
u16 mcs_160_map, mcs_80_map; |
| 2595 |
u8 link_id = arvif->link_id; |
| 2596 |
bool support_160; |
| 2597 |
enum nl80211_band band; |
| 2598 |
u16 *he_mcs_mask; |
| 2599 |
u8 he_mcs; |
| 2600 |
u16 he_tx_mcs = 0, v = 0; |
| 2601 |
int he_nss, nss_idx; |
| 2602 |
bool user_rate_valid = true; |
| 2603 |
u32 rx_nss, tx_nss, nss_160; |
| 2604 |
|
| 2605 |
if (WARN_ON(ath12k_mac_vif_link_chan(vif, link_id, &def))) |
| 2606 |
return; |
| 2607 |
|
| 2608 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 2609 |
if (!link_conf) { |
| 2610 |
ath12k_warn(ar->ab, "unable to access bss link conf in peer assoc he for vif %pM link %u", |
| 2611 |
vif->addr, link_id); |
| 2612 |
return; |
| 2613 |
} |
| 2614 |
|
| 2615 |
link_sta = ath12k_mac_get_link_sta(arsta); |
| 2616 |
if (!link_sta) { |
| 2617 |
ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n", |
| 2618 |
sta->addr, arsta->link_id); |
| 2619 |
return; |
| 2620 |
} |
| 2621 |
|
| 2622 |
he_cap = &link_sta->he_cap; |
| 2623 |
if (!he_cap->has_he) |
| 2624 |
return; |
| 2625 |
|
| 2626 |
band = def.chan->band; |
| 2627 |
he_mcs_mask = arvif->bitrate_mask.control[band].he_mcs; |
| 2628 |
|
| 2629 |
if (ath12k_peer_assoc_h_he_masked(he_mcs_mask)) |
| 2630 |
return; |
| 2631 |
|
| 2632 |
arg->he_flag = true; |
| 2633 |
|
| 2634 |
support_160 = !!(he_cap->he_cap_elem.phy_cap_info[0] & |
| 2635 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G); |
| 2636 |
|
| 2637 |
/* Supported HE-MCS and NSS Set of peer he_cap is intersection with self he_cp */ |
| 2638 |
mcs_160_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160); |
| 2639 |
mcs_80_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80); |
| 2640 |
|
| 2641 |
if (support_160) { |
| 2642 |
for (i = 7; i >= 0; i--) { |
| 2643 |
u8 mcs_160 = (mcs_160_map >> (2 * i)) & 3; |
| 2644 |
|
| 2645 |
if (mcs_160 != IEEE80211_HE_MCS_NOT_SUPPORTED) { |
| 2646 |
rx_mcs_160 = i + 1; |
| 2647 |
break; |
| 2648 |
} |
| 2649 |
} |
| 2650 |
} |
| 2651 |
|
| 2652 |
for (i = 7; i >= 0; i--) { |
| 2653 |
u8 mcs_80 = (mcs_80_map >> (2 * i)) & 3; |
| 2654 |
|
| 2655 |
if (mcs_80 != IEEE80211_HE_MCS_NOT_SUPPORTED) { |
| 2656 |
rx_mcs_80 = i + 1; |
| 2657 |
break; |
| 2658 |
} |
| 2659 |
} |
| 2660 |
|
| 2661 |
if (support_160) |
| 2662 |
max_nss = min(rx_mcs_80, rx_mcs_160); |
| 2663 |
else |
| 2664 |
max_nss = rx_mcs_80; |
| 2665 |
|
| 2666 |
arg->peer_nss = min(link_sta->rx_nss, max_nss); |
| 2667 |
|
| 2668 |
memcpy(&arg->peer_he_cap_macinfo, he_cap->he_cap_elem.mac_cap_info, |
| 2669 |
sizeof(he_cap->he_cap_elem.mac_cap_info)); |
| 2670 |
memcpy(&arg->peer_he_cap_phyinfo, he_cap->he_cap_elem.phy_cap_info, |
| 2671 |
sizeof(he_cap->he_cap_elem.phy_cap_info)); |
| 2672 |
arg->peer_he_ops = link_conf->he_oper.params; |
| 2673 |
|
| 2674 |
/* the top most byte is used to indicate BSS color info */ |
| 2675 |
arg->peer_he_ops &= 0xffffff; |
| 2676 |
|
| 2677 |
/* As per section 26.6.1 IEEE Std 802.11ax‐2022, if the Max AMPDU |
| 2678 |
* Exponent Extension in HE cap is zero, use the arg->peer_max_mpdu |
| 2679 |
* as calculated while parsing VHT caps(if VHT caps is present) |
| 2680 |
* or HT caps (if VHT caps is not present). |
| 2681 |
* |
| 2682 |
* For non-zero value of Max AMPDU Exponent Extension in HE MAC caps, |
| 2683 |
* if a HE STA sends VHT cap and HE cap IE in assoc request then, use |
| 2684 |
* MAX_AMPDU_LEN_FACTOR as 20 to calculate max_ampdu length. |
| 2685 |
* If a HE STA that does not send VHT cap, but HE and HT cap in assoc |
| 2686 |
* request, then use MAX_AMPDU_LEN_FACTOR as 16 to calculate max_ampdu |
| 2687 |
* length. |
| 2688 |
*/ |
| 2689 |
ampdu_factor = u8_get_bits(he_cap->he_cap_elem.mac_cap_info[3], |
| 2690 |
IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK); |
| 2691 |
|
| 2692 |
if (ampdu_factor) { |
| 2693 |
if (link_sta->vht_cap.vht_supported) |
| 2694 |
arg->peer_max_mpdu = (1 << (IEEE80211_HE_VHT_MAX_AMPDU_FACTOR + |
| 2695 |
ampdu_factor)) - 1; |
| 2696 |
else if (link_sta->ht_cap.ht_supported) |
| 2697 |
arg->peer_max_mpdu = (1 << (IEEE80211_HE_HT_MAX_AMPDU_FACTOR + |
| 2698 |
ampdu_factor)) - 1; |
| 2699 |
} |
| 2700 |
|
| 2701 |
if (he_cap->he_cap_elem.phy_cap_info[6] & |
| 2702 |
IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { |
| 2703 |
int bit = 7; |
| 2704 |
int nss, ru; |
| 2705 |
|
| 2706 |
arg->peer_ppet.numss_m1 = he_cap->ppe_thres[0] & |
| 2707 |
IEEE80211_PPE_THRES_NSS_MASK; |
| 2708 |
arg->peer_ppet.ru_bit_mask = |
| 2709 |
(he_cap->ppe_thres[0] & |
| 2710 |
IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >> |
| 2711 |
IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS; |
| 2712 |
|
| 2713 |
for (nss = 0; nss <= arg->peer_ppet.numss_m1; nss++) { |
| 2714 |
for (ru = 0; ru < 4; ru++) { |
| 2715 |
u32 val = 0; |
| 2716 |
int i; |
| 2717 |
|
| 2718 |
if ((arg->peer_ppet.ru_bit_mask & BIT(ru)) == 0) |
| 2719 |
continue; |
| 2720 |
for (i = 0; i < 6; i++) { |
| 2721 |
val >>= 1; |
| 2722 |
val |= ((he_cap->ppe_thres[bit / 8] >> |
| 2723 |
(bit % 8)) & 0x1) << 5; |
| 2724 |
bit++; |
| 2725 |
} |
| 2726 |
arg->peer_ppet.ppet16_ppet8_ru3_ru0[nss] |= |
| 2727 |
val << (ru * 6); |
| 2728 |
} |
| 2729 |
} |
| 2730 |
} |
| 2731 |
|
| 2732 |
if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_RES) |
| 2733 |
arg->twt_responder = true; |
| 2734 |
if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_REQ) |
| 2735 |
arg->twt_requester = true; |
| 2736 |
|
| 2737 |
he_nss = ath12k_mac_max_he_nss(he_mcs_mask); |
| 2738 |
|
| 2739 |
if (he_nss > link_sta->rx_nss) { |
| 2740 |
user_rate_valid = false; |
| 2741 |
for (nss_idx = link_sta->rx_nss - 1; nss_idx >= 0; nss_idx--) { |
| 2742 |
if (he_mcs_mask[nss_idx]) { |
| 2743 |
user_rate_valid = true; |
| 2744 |
break; |
| 2745 |
} |
| 2746 |
} |
| 2747 |
} |
| 2748 |
|
| 2749 |
if (!user_rate_valid) { |
| 2750 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 2751 |
"Setting he range MCS value to peer supported nss:%d for peer %pM\n", |
| 2752 |
link_sta->rx_nss, arsta->addr); |
| 2753 |
he_mcs_mask[link_sta->rx_nss - 1] = he_mcs_mask[he_nss - 1]; |
| 2754 |
} |
| 2755 |
|
| 2756 |
switch (link_sta->bandwidth) { |
| 2757 |
case IEEE80211_STA_RX_BW_160: |
| 2758 |
v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160); |
| 2759 |
v = ath12k_peer_assoc_h_he_limit(v, he_mcs_mask); |
| 2760 |
arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v; |
| 2761 |
|
| 2762 |
v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_160); |
| 2763 |
arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v; |
| 2764 |
|
| 2765 |
arg->peer_he_mcs_count++; |
| 2766 |
if (!he_tx_mcs) |
| 2767 |
he_tx_mcs = v; |
| 2768 |
fallthrough; |
| 2769 |
|
| 2770 |
default: |
| 2771 |
v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80); |
| 2772 |
v = ath12k_peer_assoc_h_he_limit(v, he_mcs_mask); |
| 2773 |
arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v; |
| 2774 |
|
| 2775 |
v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80); |
| 2776 |
arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v; |
| 2777 |
|
| 2778 |
arg->peer_he_mcs_count++; |
| 2779 |
if (!he_tx_mcs) |
| 2780 |
he_tx_mcs = v; |
| 2781 |
break; |
| 2782 |
} |
| 2783 |
|
| 2784 |
/* Calculate peer NSS capability from HE capabilities if STA |
| 2785 |
* supports HE. |
| 2786 |
*/ |
| 2787 |
for (i = 0, max_nss = 0, he_mcs = 0; i < NL80211_HE_NSS_MAX; i++) { |
| 2788 |
he_mcs = he_tx_mcs >> (2 * i) & 3; |
| 2789 |
|
| 2790 |
/* In case of fixed rates, MCS Range in he_tx_mcs might have |
| 2791 |
* unsupported range, with he_mcs_mask set, so check either of them |
| 2792 |
* to find nss. |
| 2793 |
*/ |
| 2794 |
if (he_mcs != IEEE80211_HE_MCS_NOT_SUPPORTED || |
| 2795 |
he_mcs_mask[i]) |
| 2796 |
max_nss = i + 1; |
| 2797 |
} |
| 2798 |
|
| 2799 |
max_nss = min(max_nss, ar->num_tx_chains); |
| 2800 |
arg->peer_nss = min(link_sta->rx_nss, max_nss); |
| 2801 |
|
| 2802 |
if (arg->peer_phymode == MODE_11AX_HE160) { |
| 2803 |
tx_nss = ath12k_get_nss_160mhz(ar, ar->num_tx_chains); |
| 2804 |
rx_nss = min(arg->peer_nss, tx_nss); |
| 2805 |
|
| 2806 |
arg->peer_nss = min(link_sta->rx_nss, ar->num_rx_chains); |
| 2807 |
arg->peer_bw_rxnss_override = ATH12K_BW_NSS_MAP_ENABLE; |
| 2808 |
|
| 2809 |
if (!rx_nss) { |
| 2810 |
ath12k_warn(ar->ab, "invalid max_nss\n"); |
| 2811 |
return; |
| 2812 |
} |
| 2813 |
|
| 2814 |
nss_160 = u32_encode_bits(rx_nss - 1, ATH12K_PEER_RX_NSS_160MHZ); |
| 2815 |
arg->peer_bw_rxnss_override |= nss_160; |
| 2816 |
} |
| 2817 |
|
| 2818 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 2819 |
"mac he peer %pM nss %d mcs cnt %d nss_override 0x%x\n", |
| 2820 |
arsta->addr, arg->peer_nss, |
| 2821 |
arg->peer_he_mcs_count, |
| 2822 |
arg->peer_bw_rxnss_override); |
| 2823 |
} |
| 2824 |
|
| 2825 |
static void ath12k_peer_assoc_h_he_6ghz(struct ath12k *ar, |
| 2826 |
struct ath12k_link_vif *arvif, |
| 2827 |
struct ath12k_link_sta *arsta, |
| 2828 |
struct ath12k_wmi_peer_assoc_arg *arg) |
| 2829 |
{ |
| 2830 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 2831 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 2832 |
const struct ieee80211_sta_he_cap *he_cap; |
| 2833 |
struct ieee80211_link_sta *link_sta; |
| 2834 |
struct cfg80211_chan_def def; |
| 2835 |
enum nl80211_band band; |
| 2836 |
u8 ampdu_factor, mpdu_density; |
| 2837 |
|
| 2838 |
if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
| 2839 |
return; |
| 2840 |
|
| 2841 |
band = def.chan->band; |
| 2842 |
|
| 2843 |
link_sta = ath12k_mac_get_link_sta(arsta); |
| 2844 |
if (!link_sta) { |
| 2845 |
ath12k_warn(ar->ab, "unable to access link sta in peer assoc he 6ghz for sta %pM link %u\n", |
| 2846 |
sta->addr, arsta->link_id); |
| 2847 |
return; |
| 2848 |
} |
| 2849 |
|
| 2850 |
he_cap = &link_sta->he_cap; |
| 2851 |
|
| 2852 |
if (!arg->he_flag || band != NL80211_BAND_6GHZ || !link_sta->he_6ghz_capa.capa) |
| 2853 |
return; |
| 2854 |
|
| 2855 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 2856 |
arg->bw_40 = true; |
| 2857 |
|
| 2858 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 2859 |
arg->bw_80 = true; |
| 2860 |
|
| 2861 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) |
| 2862 |
arg->bw_160 = true; |
| 2863 |
|
| 2864 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_320) |
| 2865 |
arg->bw_320 = true; |
| 2866 |
|
| 2867 |
arg->peer_he_caps_6ghz = le16_to_cpu(link_sta->he_6ghz_capa.capa); |
| 2868 |
|
| 2869 |
mpdu_density = u32_get_bits(arg->peer_he_caps_6ghz, |
| 2870 |
IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START); |
| 2871 |
arg->peer_mpdu_density = ath12k_parse_mpdudensity(mpdu_density); |
| 2872 |
|
| 2873 |
/* From IEEE Std 802.11ax-2021 - Section 10.12.2: An HE STA shall be capable of |
| 2874 |
* receiving A-MPDU where the A-MPDU pre-EOF padding length is up to the value |
| 2875 |
* indicated by the Maximum A-MPDU Length Exponent Extension field in the HE |
| 2876 |
* Capabilities element and the Maximum A-MPDU Length Exponent field in HE 6 GHz |
| 2877 |
* Band Capabilities element in the 6 GHz band. |
| 2878 |
* |
| 2879 |
* Here, we are extracting the Max A-MPDU Exponent Extension from HE caps and |
| 2880 |
* factor is the Maximum A-MPDU Length Exponent from HE 6 GHZ Band capability. |
| 2881 |
*/ |
| 2882 |
ampdu_factor = u8_get_bits(he_cap->he_cap_elem.mac_cap_info[3], |
| 2883 |
IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK) + |
| 2884 |
u32_get_bits(arg->peer_he_caps_6ghz, |
| 2885 |
IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP); |
| 2886 |
|
| 2887 |
arg->peer_max_mpdu = (1u << (IEEE80211_HE_6GHZ_MAX_AMPDU_FACTOR + |
| 2888 |
ampdu_factor)) - 1; |
| 2889 |
} |
| 2890 |
|
| 2891 |
static int ath12k_get_smps_from_capa(const struct ieee80211_sta_ht_cap *ht_cap, |
| 2892 |
const struct ieee80211_he_6ghz_capa *he_6ghz_capa, |
| 2893 |
int *smps) |
| 2894 |
{ |
| 2895 |
if (ht_cap->ht_supported) |
| 2896 |
*smps = u16_get_bits(ht_cap->cap, IEEE80211_HT_CAP_SM_PS); |
| 2897 |
else |
| 2898 |
*smps = le16_get_bits(he_6ghz_capa->capa, |
| 2899 |
IEEE80211_HE_6GHZ_CAP_SM_PS); |
| 2900 |
|
| 2901 |
if (*smps >= ARRAY_SIZE(ath12k_smps_map)) |
| 2902 |
return -EINVAL; |
| 2903 |
|
| 2904 |
return 0; |
| 2905 |
} |
| 2906 |
|
| 2907 |
static void ath12k_peer_assoc_h_smps(struct ath12k_link_sta *arsta, |
| 2908 |
struct ath12k_wmi_peer_assoc_arg *arg) |
| 2909 |
{ |
| 2910 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 2911 |
const struct ieee80211_he_6ghz_capa *he_6ghz_capa; |
| 2912 |
struct ath12k_link_vif *arvif = arsta->arvif; |
| 2913 |
const struct ieee80211_sta_ht_cap *ht_cap; |
| 2914 |
struct ieee80211_link_sta *link_sta; |
| 2915 |
struct ath12k *ar = arvif->ar; |
| 2916 |
int smps; |
| 2917 |
|
| 2918 |
link_sta = ath12k_mac_get_link_sta(arsta); |
| 2919 |
if (!link_sta) { |
| 2920 |
ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n", |
| 2921 |
sta->addr, arsta->link_id); |
| 2922 |
return; |
| 2923 |
} |
| 2924 |
|
| 2925 |
he_6ghz_capa = &link_sta->he_6ghz_capa; |
| 2926 |
ht_cap = &link_sta->ht_cap; |
| 2927 |
|
| 2928 |
if (!ht_cap->ht_supported && !he_6ghz_capa->capa) |
| 2929 |
return; |
| 2930 |
|
| 2931 |
if (ath12k_get_smps_from_capa(ht_cap, he_6ghz_capa, &smps)) |
| 2932 |
return; |
| 2933 |
|
| 2934 |
switch (smps) { |
| 2935 |
case WLAN_HT_CAP_SM_PS_STATIC: |
| 2936 |
arg->static_mimops_flag = true; |
| 2937 |
break; |
| 2938 |
case WLAN_HT_CAP_SM_PS_DYNAMIC: |
| 2939 |
arg->dynamic_mimops_flag = true; |
| 2940 |
break; |
| 2941 |
case WLAN_HT_CAP_SM_PS_DISABLED: |
| 2942 |
arg->spatial_mux_flag = true; |
| 2943 |
break; |
| 2944 |
default: |
| 2945 |
break; |
| 2946 |
} |
| 2947 |
} |
| 2948 |
|
| 2949 |
static void ath12k_peer_assoc_h_qos(struct ath12k *ar, |
| 2950 |
struct ath12k_link_vif *arvif, |
| 2951 |
struct ath12k_link_sta *arsta, |
| 2952 |
struct ath12k_wmi_peer_assoc_arg *arg) |
| 2953 |
{ |
| 2954 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 2955 |
|
| 2956 |
switch (arvif->ahvif->vdev_type) { |
| 2957 |
case WMI_VDEV_TYPE_AP: |
| 2958 |
if (sta->wme) { |
| 2959 |
/* TODO: Check WME vs QoS */ |
| 2960 |
arg->is_wme_set = true; |
| 2961 |
arg->qos_flag = true; |
| 2962 |
} |
| 2963 |
|
| 2964 |
if (sta->wme && sta->uapsd_queues) { |
| 2965 |
/* TODO: Check WME vs QoS */ |
| 2966 |
arg->is_wme_set = true; |
| 2967 |
arg->apsd_flag = true; |
| 2968 |
arg->peer_rate_caps |= WMI_HOST_RC_UAPSD_FLAG; |
| 2969 |
} |
| 2970 |
break; |
| 2971 |
case WMI_VDEV_TYPE_STA: |
| 2972 |
if (sta->wme) { |
| 2973 |
arg->is_wme_set = true; |
| 2974 |
arg->qos_flag = true; |
| 2975 |
} |
| 2976 |
break; |
| 2977 |
default: |
| 2978 |
break; |
| 2979 |
} |
| 2980 |
|
| 2981 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac peer %pM qos %d\n", |
| 2982 |
arsta->addr, arg->qos_flag); |
| 2983 |
} |
| 2984 |
|
| 2985 |
static int ath12k_peer_assoc_qos_ap(struct ath12k *ar, |
| 2986 |
struct ath12k_link_vif *arvif, |
| 2987 |
struct ath12k_link_sta *arsta) |
| 2988 |
{ |
| 2989 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 2990 |
struct ath12k_wmi_ap_ps_arg arg; |
| 2991 |
u32 max_sp; |
| 2992 |
u32 uapsd; |
| 2993 |
int ret; |
| 2994 |
|
| 2995 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 2996 |
|
| 2997 |
arg.vdev_id = arvif->vdev_id; |
| 2998 |
|
| 2999 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n", |
| 3000 |
sta->uapsd_queues, sta->max_sp); |
| 3001 |
|
| 3002 |
uapsd = 0; |
| 3003 |
if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 3004 |
uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | |
| 3005 |
WMI_AP_PS_UAPSD_AC3_TRIGGER_EN; |
| 3006 |
if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 3007 |
uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | |
| 3008 |
WMI_AP_PS_UAPSD_AC2_TRIGGER_EN; |
| 3009 |
if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 3010 |
uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | |
| 3011 |
WMI_AP_PS_UAPSD_AC1_TRIGGER_EN; |
| 3012 |
if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 3013 |
uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | |
| 3014 |
WMI_AP_PS_UAPSD_AC0_TRIGGER_EN; |
| 3015 |
|
| 3016 |
max_sp = 0; |
| 3017 |
if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP) |
| 3018 |
max_sp = sta->max_sp; |
| 3019 |
|
| 3020 |
arg.param = WMI_AP_PS_PEER_PARAM_UAPSD; |
| 3021 |
arg.value = uapsd; |
| 3022 |
ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg); |
| 3023 |
if (ret) |
| 3024 |
goto err; |
| 3025 |
|
| 3026 |
arg.param = WMI_AP_PS_PEER_PARAM_MAX_SP; |
| 3027 |
arg.value = max_sp; |
| 3028 |
ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg); |
| 3029 |
if (ret) |
| 3030 |
goto err; |
| 3031 |
|
| 3032 |
/* TODO: revisit during testing */ |
| 3033 |
arg.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE; |
| 3034 |
arg.value = DISABLE_SIFS_RESPONSE_TRIGGER; |
| 3035 |
ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg); |
| 3036 |
if (ret) |
| 3037 |
goto err; |
| 3038 |
|
| 3039 |
arg.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD; |
| 3040 |
arg.value = DISABLE_SIFS_RESPONSE_TRIGGER; |
| 3041 |
ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg); |
| 3042 |
if (ret) |
| 3043 |
goto err; |
| 3044 |
|
| 3045 |
return 0; |
| 3046 |
|
| 3047 |
err: |
| 3048 |
ath12k_warn(ar->ab, "failed to set ap ps peer param %d for vdev %i: %d\n", |
| 3049 |
arg.param, arvif->vdev_id, ret); |
| 3050 |
return ret; |
| 3051 |
} |
| 3052 |
|
| 3053 |
static bool ath12k_mac_sta_has_ofdm_only(struct ieee80211_link_sta *sta) |
| 3054 |
{ |
| 3055 |
return sta->supp_rates[NL80211_BAND_2GHZ] >> |
| 3056 |
ATH12K_MAC_FIRST_OFDM_RATE_IDX; |
| 3057 |
} |
| 3058 |
|
| 3059 |
static enum wmi_phy_mode ath12k_mac_get_phymode_vht(struct ath12k *ar, |
| 3060 |
struct ieee80211_link_sta *link_sta) |
| 3061 |
{ |
| 3062 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) { |
| 3063 |
if (link_sta->vht_cap.cap & (IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ | |
| 3064 |
IEEE80211_VHT_CAP_EXT_NSS_BW_MASK)) |
| 3065 |
return MODE_11AC_VHT160; |
| 3066 |
|
| 3067 |
/* Allow STA to connect even if it does not explicitly advertise 160 MHz |
| 3068 |
* support |
| 3069 |
*/ |
| 3070 |
return MODE_11AC_VHT160; |
| 3071 |
} |
| 3072 |
|
| 3073 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 3074 |
return MODE_11AC_VHT80; |
| 3075 |
|
| 3076 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 3077 |
return MODE_11AC_VHT40; |
| 3078 |
|
| 3079 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 3080 |
return MODE_11AC_VHT20; |
| 3081 |
|
| 3082 |
return MODE_UNKNOWN; |
| 3083 |
} |
| 3084 |
|
| 3085 |
static enum wmi_phy_mode ath12k_mac_get_phymode_he(struct ath12k *ar, |
| 3086 |
struct ieee80211_link_sta *link_sta) |
| 3087 |
{ |
| 3088 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) { |
| 3089 |
if (link_sta->he_cap.he_cap_elem.phy_cap_info[0] & |
| 3090 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) |
| 3091 |
return MODE_11AX_HE160; |
| 3092 |
|
| 3093 |
return MODE_UNKNOWN; |
| 3094 |
} |
| 3095 |
|
| 3096 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 3097 |
return MODE_11AX_HE80; |
| 3098 |
|
| 3099 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 3100 |
return MODE_11AX_HE40; |
| 3101 |
|
| 3102 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 3103 |
return MODE_11AX_HE20; |
| 3104 |
|
| 3105 |
return MODE_UNKNOWN; |
| 3106 |
} |
| 3107 |
|
| 3108 |
static enum wmi_phy_mode ath12k_mac_get_phymode_eht(struct ath12k *ar, |
| 3109 |
struct ieee80211_link_sta *link_sta) |
| 3110 |
{ |
| 3111 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_320) |
| 3112 |
if (link_sta->eht_cap.eht_cap_elem.phy_cap_info[0] & |
| 3113 |
IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ) |
| 3114 |
return MODE_11BE_EHT320; |
| 3115 |
|
| 3116 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) { |
| 3117 |
if (link_sta->he_cap.he_cap_elem.phy_cap_info[0] & |
| 3118 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) |
| 3119 |
return MODE_11BE_EHT160; |
| 3120 |
|
| 3121 |
ath12k_warn(ar->ab, "invalid EHT PHY capability info for 160 Mhz: %d\n", |
| 3122 |
link_sta->he_cap.he_cap_elem.phy_cap_info[0]); |
| 3123 |
|
| 3124 |
return MODE_UNKNOWN; |
| 3125 |
} |
| 3126 |
|
| 3127 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 3128 |
return MODE_11BE_EHT80; |
| 3129 |
|
| 3130 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 3131 |
return MODE_11BE_EHT40; |
| 3132 |
|
| 3133 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 3134 |
return MODE_11BE_EHT20; |
| 3135 |
|
| 3136 |
return MODE_UNKNOWN; |
| 3137 |
} |
| 3138 |
|
| 3139 |
static bool |
| 3140 |
ath12k_peer_assoc_h_eht_masked(const u16 eht_mcs_mask[NL80211_EHT_NSS_MAX]) |
| 3141 |
{ |
| 3142 |
int nss; |
| 3143 |
|
| 3144 |
for (nss = 0; nss < NL80211_EHT_NSS_MAX; nss++) |
| 3145 |
if (eht_mcs_mask[nss]) |
| 3146 |
return false; |
| 3147 |
|
| 3148 |
return true; |
| 3149 |
} |
| 3150 |
|
| 3151 |
static void ath12k_peer_assoc_h_phymode(struct ath12k *ar, |
| 3152 |
struct ath12k_link_vif *arvif, |
| 3153 |
struct ath12k_link_sta *arsta, |
| 3154 |
struct ath12k_wmi_peer_assoc_arg *arg) |
| 3155 |
{ |
| 3156 |
struct ieee80211_link_sta *link_sta; |
| 3157 |
struct cfg80211_chan_def def; |
| 3158 |
enum nl80211_band band; |
| 3159 |
const u8 *ht_mcs_mask; |
| 3160 |
const u16 *vht_mcs_mask; |
| 3161 |
const u16 *he_mcs_mask; |
| 3162 |
const u16 *eht_mcs_mask; |
| 3163 |
enum wmi_phy_mode phymode = MODE_UNKNOWN; |
| 3164 |
|
| 3165 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 3166 |
|
| 3167 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 3168 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 3169 |
|
| 3170 |
if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
| 3171 |
return; |
| 3172 |
|
| 3173 |
band = def.chan->band; |
| 3174 |
ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; |
| 3175 |
vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; |
| 3176 |
he_mcs_mask = arvif->bitrate_mask.control[band].he_mcs; |
| 3177 |
eht_mcs_mask = arvif->bitrate_mask.control[band].eht_mcs; |
| 3178 |
|
| 3179 |
link_sta = ath12k_mac_get_link_sta(arsta); |
| 3180 |
if (!link_sta) { |
| 3181 |
ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n", |
| 3182 |
sta->addr, arsta->link_id); |
| 3183 |
return; |
| 3184 |
} |
| 3185 |
|
| 3186 |
switch (band) { |
| 3187 |
case NL80211_BAND_2GHZ: |
| 3188 |
if (link_sta->eht_cap.has_eht && |
| 3189 |
!ath12k_peer_assoc_h_eht_masked(eht_mcs_mask)) { |
| 3190 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 3191 |
phymode = MODE_11BE_EHT40_2G; |
| 3192 |
else |
| 3193 |
phymode = MODE_11BE_EHT20_2G; |
| 3194 |
} else if (link_sta->he_cap.has_he && |
| 3195 |
!ath12k_peer_assoc_h_he_masked(he_mcs_mask)) { |
| 3196 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 3197 |
phymode = MODE_11AX_HE80_2G; |
| 3198 |
else if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 3199 |
phymode = MODE_11AX_HE40_2G; |
| 3200 |
else |
| 3201 |
phymode = MODE_11AX_HE20_2G; |
| 3202 |
} else if (link_sta->vht_cap.vht_supported && |
| 3203 |
!ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) { |
| 3204 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 3205 |
phymode = MODE_11AC_VHT40; |
| 3206 |
else |
| 3207 |
phymode = MODE_11AC_VHT20; |
| 3208 |
} else if (link_sta->ht_cap.ht_supported && |
| 3209 |
!ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) { |
| 3210 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 3211 |
phymode = MODE_11NG_HT40; |
| 3212 |
else |
| 3213 |
phymode = MODE_11NG_HT20; |
| 3214 |
} else if (ath12k_mac_sta_has_ofdm_only(link_sta)) { |
| 3215 |
phymode = MODE_11G; |
| 3216 |
} else { |
| 3217 |
phymode = MODE_11B; |
| 3218 |
} |
| 3219 |
break; |
| 3220 |
case NL80211_BAND_5GHZ: |
| 3221 |
case NL80211_BAND_6GHZ: |
| 3222 |
/* Check EHT first */ |
| 3223 |
if (link_sta->eht_cap.has_eht) { |
| 3224 |
phymode = ath12k_mac_get_phymode_eht(ar, link_sta); |
| 3225 |
} else if (link_sta->he_cap.has_he && |
| 3226 |
!ath12k_peer_assoc_h_he_masked(he_mcs_mask)) { |
| 3227 |
phymode = ath12k_mac_get_phymode_he(ar, link_sta); |
| 3228 |
} else if (link_sta->vht_cap.vht_supported && |
| 3229 |
!ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) { |
| 3230 |
phymode = ath12k_mac_get_phymode_vht(ar, link_sta); |
| 3231 |
} else if (link_sta->ht_cap.ht_supported && |
| 3232 |
!ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) { |
| 3233 |
if (link_sta->bandwidth >= IEEE80211_STA_RX_BW_40) |
| 3234 |
phymode = MODE_11NA_HT40; |
| 3235 |
else |
| 3236 |
phymode = MODE_11NA_HT20; |
| 3237 |
} else { |
| 3238 |
phymode = MODE_11A; |
| 3239 |
} |
| 3240 |
break; |
| 3241 |
default: |
| 3242 |
break; |
| 3243 |
} |
| 3244 |
|
| 3245 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac peer %pM phymode %s\n", |
| 3246 |
arsta->addr, ath12k_mac_phymode_str(phymode)); |
| 3247 |
|
| 3248 |
arg->peer_phymode = phymode; |
| 3249 |
WARN_ON(phymode == MODE_UNKNOWN); |
| 3250 |
} |
| 3251 |
|
| 3252 |
#define ATH12K_EHT_MCS_7_ENABLED 0x00FF |
| 3253 |
#define ATH12K_EHT_MCS_9_ENABLED 0x0300 |
| 3254 |
#define ATH12K_EHT_MCS_11_ENABLED 0x0C00 |
| 3255 |
#define ATH12K_EHT_MCS_13_ENABLED 0x3000 |
| 3256 |
|
| 3257 |
static void ath12k_mac_set_eht_mcs(u8 rx_tx_mcs7, u8 rx_tx_mcs9, |
| 3258 |
u8 rx_tx_mcs11, u8 rx_tx_mcs13, |
| 3259 |
u32 *rx_mcs, u32 *tx_mcs, |
| 3260 |
const u16 eht_mcs_limit[NL80211_EHT_NSS_MAX]) |
| 3261 |
{ |
| 3262 |
int nss; |
| 3263 |
u8 mcs_7 = 0, mcs_9 = 0, mcs_11 = 0, mcs_13 = 0; |
| 3264 |
u8 peer_mcs_7, peer_mcs_9, peer_mcs_11, peer_mcs_13; |
| 3265 |
|
| 3266 |
for (nss = 0; nss < NL80211_EHT_NSS_MAX; nss++) { |
| 3267 |
if (eht_mcs_limit[nss] & ATH12K_EHT_MCS_7_ENABLED) |
| 3268 |
mcs_7++; |
| 3269 |
if (eht_mcs_limit[nss] & ATH12K_EHT_MCS_9_ENABLED) |
| 3270 |
mcs_9++; |
| 3271 |
if (eht_mcs_limit[nss] & ATH12K_EHT_MCS_11_ENABLED) |
| 3272 |
mcs_11++; |
| 3273 |
if (eht_mcs_limit[nss] & ATH12K_EHT_MCS_13_ENABLED) |
| 3274 |
mcs_13++; |
| 3275 |
} |
| 3276 |
|
| 3277 |
peer_mcs_7 = u8_get_bits(rx_tx_mcs7, IEEE80211_EHT_MCS_NSS_RX); |
| 3278 |
peer_mcs_9 = u8_get_bits(rx_tx_mcs9, IEEE80211_EHT_MCS_NSS_RX); |
| 3279 |
peer_mcs_11 = u8_get_bits(rx_tx_mcs11, IEEE80211_EHT_MCS_NSS_RX); |
| 3280 |
peer_mcs_13 = u8_get_bits(rx_tx_mcs13, IEEE80211_EHT_MCS_NSS_RX); |
| 3281 |
|
| 3282 |
*rx_mcs = u32_encode_bits(min(peer_mcs_7, mcs_7), WMI_EHT_MCS_NSS_0_7) | |
| 3283 |
u32_encode_bits(min(peer_mcs_9, mcs_9), WMI_EHT_MCS_NSS_8_9) | |
| 3284 |
u32_encode_bits(min(peer_mcs_11, mcs_11), WMI_EHT_MCS_NSS_10_11) | |
| 3285 |
u32_encode_bits(min(peer_mcs_13, mcs_13), WMI_EHT_MCS_NSS_12_13); |
| 3286 |
|
| 3287 |
peer_mcs_7 = u8_get_bits(rx_tx_mcs7, IEEE80211_EHT_MCS_NSS_TX); |
| 3288 |
peer_mcs_9 = u8_get_bits(rx_tx_mcs9, IEEE80211_EHT_MCS_NSS_TX); |
| 3289 |
peer_mcs_11 = u8_get_bits(rx_tx_mcs11, IEEE80211_EHT_MCS_NSS_TX); |
| 3290 |
peer_mcs_13 = u8_get_bits(rx_tx_mcs13, IEEE80211_EHT_MCS_NSS_TX); |
| 3291 |
|
| 3292 |
*tx_mcs = u32_encode_bits(min(peer_mcs_7, mcs_7), WMI_EHT_MCS_NSS_0_7) | |
| 3293 |
u32_encode_bits(min(peer_mcs_9, mcs_9), WMI_EHT_MCS_NSS_8_9) | |
| 3294 |
u32_encode_bits(min(peer_mcs_11, mcs_11), WMI_EHT_MCS_NSS_10_11) | |
| 3295 |
u32_encode_bits(min(peer_mcs_13, mcs_13), WMI_EHT_MCS_NSS_12_13); |
| 3296 |
} |
| 3297 |
|
| 3298 |
static void ath12k_mac_set_eht_ppe_threshold(const u8 *ppe_thres, |
| 3299 |
struct ath12k_wmi_ppe_threshold_arg *ppet) |
| 3300 |
{ |
| 3301 |
u32 bit_pos = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE, val; |
| 3302 |
u8 nss, ru, i; |
| 3303 |
u8 ppet_bit_len_per_ru = IEEE80211_EHT_PPE_THRES_INFO_PPET_SIZE * 2; |
| 3304 |
|
| 3305 |
ppet->numss_m1 = u8_get_bits(ppe_thres[0], IEEE80211_EHT_PPE_THRES_NSS_MASK); |
| 3306 |
ppet->ru_bit_mask = u16_get_bits(get_unaligned_le16(ppe_thres), |
| 3307 |
IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); |
| 3308 |
|
| 3309 |
for (nss = 0; nss <= ppet->numss_m1; nss++) { |
| 3310 |
for (ru = 0; |
| 3311 |
ru < hweight16(IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); |
| 3312 |
ru++) { |
| 3313 |
if ((ppet->ru_bit_mask & BIT(ru)) == 0) |
| 3314 |
continue; |
| 3315 |
|
| 3316 |
val = 0; |
| 3317 |
for (i = 0; i < ppet_bit_len_per_ru; i++) { |
| 3318 |
val |= (((ppe_thres[bit_pos / 8] >> |
| 3319 |
(bit_pos % 8)) & 0x1) << i); |
| 3320 |
bit_pos++; |
| 3321 |
} |
| 3322 |
ppet->ppet16_ppet8_ru3_ru0[nss] |= |
| 3323 |
(val << (ru * ppet_bit_len_per_ru)); |
| 3324 |
} |
| 3325 |
} |
| 3326 |
} |
| 3327 |
|
| 3328 |
static void ath12k_peer_assoc_h_eht(struct ath12k *ar, |
| 3329 |
struct ath12k_link_vif *arvif, |
| 3330 |
struct ath12k_link_sta *arsta, |
| 3331 |
struct ath12k_wmi_peer_assoc_arg *arg) |
| 3332 |
{ |
| 3333 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 3334 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 3335 |
const struct ieee80211_eht_mcs_nss_supp *own_eht_mcs_nss_supp; |
| 3336 |
const struct ieee80211_eht_mcs_nss_supp_20mhz_only *bw_20; |
| 3337 |
const struct ieee80211_sta_eht_cap *eht_cap, *own_eht_cap; |
| 3338 |
const struct ieee80211_sband_iftype_data *iftd; |
| 3339 |
const struct ieee80211_eht_mcs_nss_supp_bw *bw; |
| 3340 |
const struct ieee80211_sta_he_cap *he_cap; |
| 3341 |
struct ieee80211_link_sta *link_sta; |
| 3342 |
struct ieee80211_bss_conf *link_conf; |
| 3343 |
struct cfg80211_chan_def def; |
| 3344 |
bool user_rate_valid = true; |
| 3345 |
enum nl80211_band band; |
| 3346 |
int eht_nss, nss_idx; |
| 3347 |
u32 *rx_mcs, *tx_mcs; |
| 3348 |
u16 *eht_mcs_mask; |
| 3349 |
u8 max_nss = 0; |
| 3350 |
|
| 3351 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 3352 |
|
| 3353 |
link_sta = ath12k_mac_get_link_sta(arsta); |
| 3354 |
if (!link_sta) { |
| 3355 |
ath12k_warn(ar->ab, "unable to access link sta in peer assoc eht for sta %pM link %u\n", |
| 3356 |
sta->addr, arsta->link_id); |
| 3357 |
return; |
| 3358 |
} |
| 3359 |
|
| 3360 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 3361 |
if (!link_conf) { |
| 3362 |
ath12k_warn(ar->ab, "unable to access link_conf in peer assoc eht set\n"); |
| 3363 |
return; |
| 3364 |
} |
| 3365 |
|
| 3366 |
eht_cap = &link_sta->eht_cap; |
| 3367 |
he_cap = &link_sta->he_cap; |
| 3368 |
if (!he_cap->has_he || !eht_cap->has_eht) |
| 3369 |
return; |
| 3370 |
|
| 3371 |
if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
| 3372 |
return; |
| 3373 |
|
| 3374 |
band = def.chan->band; |
| 3375 |
eht_mcs_mask = arvif->bitrate_mask.control[band].eht_mcs; |
| 3376 |
|
| 3377 |
iftd = ieee80211_get_sband_iftype_data(&ar->mac.sbands[band], vif->type); |
| 3378 |
if (!iftd) { |
| 3379 |
ath12k_warn(ar->ab, |
| 3380 |
"unable to access iftype_data in struct ieee80211_supported_band\n"); |
| 3381 |
return; |
| 3382 |
} |
| 3383 |
|
| 3384 |
own_eht_cap = &iftd->eht_cap; |
| 3385 |
own_eht_mcs_nss_supp = &own_eht_cap->eht_mcs_nss_supp; |
| 3386 |
|
| 3387 |
arg->eht_flag = true; |
| 3388 |
|
| 3389 |
if ((eht_cap->eht_cap_elem.phy_cap_info[5] & |
| 3390 |
IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) && |
| 3391 |
eht_cap->eht_ppe_thres[0] != 0) |
| 3392 |
ath12k_mac_set_eht_ppe_threshold(eht_cap->eht_ppe_thres, |
| 3393 |
&arg->peer_eht_ppet); |
| 3394 |
|
| 3395 |
memcpy(arg->peer_eht_cap_mac, eht_cap->eht_cap_elem.mac_cap_info, |
| 3396 |
sizeof(eht_cap->eht_cap_elem.mac_cap_info)); |
| 3397 |
memcpy(arg->peer_eht_cap_phy, eht_cap->eht_cap_elem.phy_cap_info, |
| 3398 |
sizeof(eht_cap->eht_cap_elem.phy_cap_info)); |
| 3399 |
|
| 3400 |
rx_mcs = arg->peer_eht_rx_mcs_set; |
| 3401 |
tx_mcs = arg->peer_eht_tx_mcs_set; |
| 3402 |
|
| 3403 |
eht_nss = ath12k_mac_max_eht_mcs_nss((void *)own_eht_mcs_nss_supp, |
| 3404 |
sizeof(*own_eht_mcs_nss_supp)); |
| 3405 |
if (eht_nss > link_sta->rx_nss) { |
| 3406 |
user_rate_valid = false; |
| 3407 |
for (nss_idx = (link_sta->rx_nss - 1); nss_idx >= 0; nss_idx--) { |
| 3408 |
if (eht_mcs_mask[nss_idx]) { |
| 3409 |
user_rate_valid = true; |
| 3410 |
break; |
| 3411 |
} |
| 3412 |
} |
| 3413 |
} |
| 3414 |
|
| 3415 |
if (!user_rate_valid) { |
| 3416 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 3417 |
"Setting eht range MCS value to peer supported nss %d for peer %pM\n", |
| 3418 |
link_sta->rx_nss, arsta->addr); |
| 3419 |
eht_mcs_mask[link_sta->rx_nss - 1] = eht_mcs_mask[eht_nss - 1]; |
| 3420 |
} |
| 3421 |
|
| 3422 |
bw_20 = &eht_cap->eht_mcs_nss_supp.only_20mhz; |
| 3423 |
bw = &eht_cap->eht_mcs_nss_supp.bw._80; |
| 3424 |
|
| 3425 |
switch (link_sta->bandwidth) { |
| 3426 |
case IEEE80211_STA_RX_BW_320: |
| 3427 |
bw = &eht_cap->eht_mcs_nss_supp.bw._320; |
| 3428 |
ath12k_mac_set_eht_mcs(bw->rx_tx_mcs9_max_nss, |
| 3429 |
bw->rx_tx_mcs9_max_nss, |
| 3430 |
bw->rx_tx_mcs11_max_nss, |
| 3431 |
bw->rx_tx_mcs13_max_nss, |
| 3432 |
&rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_320], |
| 3433 |
&tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_320], |
| 3434 |
eht_mcs_mask); |
| 3435 |
arg->peer_eht_mcs_count++; |
| 3436 |
fallthrough; |
| 3437 |
case IEEE80211_STA_RX_BW_160: |
| 3438 |
bw = &eht_cap->eht_mcs_nss_supp.bw._160; |
| 3439 |
ath12k_mac_set_eht_mcs(bw->rx_tx_mcs9_max_nss, |
| 3440 |
bw->rx_tx_mcs9_max_nss, |
| 3441 |
bw->rx_tx_mcs11_max_nss, |
| 3442 |
bw->rx_tx_mcs13_max_nss, |
| 3443 |
&rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_160], |
| 3444 |
&tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_160], |
| 3445 |
eht_mcs_mask); |
| 3446 |
arg->peer_eht_mcs_count++; |
| 3447 |
fallthrough; |
| 3448 |
default: |
| 3449 |
if ((vif->type == NL80211_IFTYPE_AP || |
| 3450 |
vif->type == NL80211_IFTYPE_MESH_POINT) && |
| 3451 |
!(link_sta->he_cap.he_cap_elem.phy_cap_info[0] & |
| 3452 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK_ALL)) { |
| 3453 |
bw_20 = &eht_cap->eht_mcs_nss_supp.only_20mhz; |
| 3454 |
|
| 3455 |
ath12k_mac_set_eht_mcs(bw_20->rx_tx_mcs7_max_nss, |
| 3456 |
bw_20->rx_tx_mcs9_max_nss, |
| 3457 |
bw_20->rx_tx_mcs11_max_nss, |
| 3458 |
bw_20->rx_tx_mcs13_max_nss, |
| 3459 |
&rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80], |
| 3460 |
&tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80], |
| 3461 |
eht_mcs_mask); |
| 3462 |
} else { |
| 3463 |
bw = &eht_cap->eht_mcs_nss_supp.bw._80; |
| 3464 |
ath12k_mac_set_eht_mcs(bw->rx_tx_mcs9_max_nss, |
| 3465 |
bw->rx_tx_mcs9_max_nss, |
| 3466 |
bw->rx_tx_mcs11_max_nss, |
| 3467 |
bw->rx_tx_mcs13_max_nss, |
| 3468 |
&rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80], |
| 3469 |
&tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80], |
| 3470 |
eht_mcs_mask); |
| 3471 |
} |
| 3472 |
|
| 3473 |
arg->peer_eht_mcs_count++; |
| 3474 |
break; |
| 3475 |
} |
| 3476 |
|
| 3477 |
arg->punct_bitmap = ~arvif->punct_bitmap; |
| 3478 |
arg->eht_disable_mcs15 = link_conf->eht_disable_mcs15; |
| 3479 |
|
| 3480 |
if ((vif->type == NL80211_IFTYPE_AP || |
| 3481 |
vif->type == NL80211_IFTYPE_MESH_POINT) && |
| 3482 |
!(link_sta->he_cap.he_cap_elem.phy_cap_info[0] & |
| 3483 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK_ALL)) { |
| 3484 |
if (bw_20->rx_tx_mcs13_max_nss) |
| 3485 |
max_nss = max(max_nss, u8_get_bits(bw_20->rx_tx_mcs13_max_nss, |
| 3486 |
IEEE80211_EHT_MCS_NSS_RX)); |
| 3487 |
if (bw_20->rx_tx_mcs11_max_nss) |
| 3488 |
max_nss = max(max_nss, u8_get_bits(bw_20->rx_tx_mcs11_max_nss, |
| 3489 |
IEEE80211_EHT_MCS_NSS_RX)); |
| 3490 |
if (bw_20->rx_tx_mcs9_max_nss) |
| 3491 |
max_nss = max(max_nss, u8_get_bits(bw_20->rx_tx_mcs9_max_nss, |
| 3492 |
IEEE80211_EHT_MCS_NSS_RX)); |
| 3493 |
if (bw_20->rx_tx_mcs7_max_nss) |
| 3494 |
max_nss = max(max_nss, u8_get_bits(bw_20->rx_tx_mcs7_max_nss, |
| 3495 |
IEEE80211_EHT_MCS_NSS_RX)); |
| 3496 |
} else { |
| 3497 |
if (bw->rx_tx_mcs13_max_nss) |
| 3498 |
max_nss = max(max_nss, u8_get_bits(bw->rx_tx_mcs13_max_nss, |
| 3499 |
IEEE80211_EHT_MCS_NSS_RX)); |
| 3500 |
if (bw->rx_tx_mcs11_max_nss) |
| 3501 |
max_nss = max(max_nss, u8_get_bits(bw->rx_tx_mcs11_max_nss, |
| 3502 |
IEEE80211_EHT_MCS_NSS_RX)); |
| 3503 |
if (bw->rx_tx_mcs9_max_nss) |
| 3504 |
max_nss = max(max_nss, u8_get_bits(bw->rx_tx_mcs9_max_nss, |
| 3505 |
IEEE80211_EHT_MCS_NSS_RX)); |
| 3506 |
} |
| 3507 |
|
| 3508 |
max_nss = min(max_nss, (uint8_t)eht_nss); |
| 3509 |
|
| 3510 |
arg->peer_nss = min(link_sta->rx_nss, max_nss); |
| 3511 |
|
| 3512 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 3513 |
"mac eht peer %pM nss %d mcs cnt %d ru_punct_bitmap 0x%x\n", |
| 3514 |
arsta->addr, arg->peer_nss, arg->peer_eht_mcs_count, |
| 3515 |
arg->punct_bitmap); |
| 3516 |
} |
| 3517 |
|
| 3518 |
static void ath12k_peer_assoc_h_mlo(struct ath12k_link_sta *arsta, |
| 3519 |
struct ath12k_wmi_peer_assoc_arg *arg) |
| 3520 |
{ |
| 3521 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 3522 |
struct peer_assoc_mlo_params *ml = &arg->ml; |
| 3523 |
struct ath12k_sta *ahsta = arsta->ahsta; |
| 3524 |
struct ath12k_link_sta *arsta_p; |
| 3525 |
struct ath12k_link_vif *arvif; |
| 3526 |
unsigned long links; |
| 3527 |
u8 link_id; |
| 3528 |
int i; |
| 3529 |
|
| 3530 |
if (!sta->mlo || ahsta->ml_peer_id == ATH12K_MLO_PEER_ID_INVALID) |
| 3531 |
return; |
| 3532 |
|
| 3533 |
ml->enabled = true; |
| 3534 |
ml->assoc_link = arsta->is_assoc_link; |
| 3535 |
|
| 3536 |
/* For now considering the primary umac based on assoc link */ |
| 3537 |
ml->primary_umac = arsta->is_assoc_link; |
| 3538 |
ml->peer_id_valid = true; |
| 3539 |
ml->logical_link_idx_valid = true; |
| 3540 |
|
| 3541 |
ether_addr_copy(ml->mld_addr, sta->addr); |
| 3542 |
ml->logical_link_idx = arsta->link_idx; |
| 3543 |
ml->ml_peer_id = ahsta->ml_peer_id; |
| 3544 |
ml->ieee_link_id = arsta->link_id; |
| 3545 |
ml->num_partner_links = 0; |
| 3546 |
ml->eml_cap = sta->eml_cap; |
| 3547 |
links = ahsta->links_map; |
| 3548 |
|
| 3549 |
rcu_read_lock(); |
| 3550 |
|
| 3551 |
i = 0; |
| 3552 |
|
| 3553 |
for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 3554 |
if (i >= ATH12K_WMI_MLO_MAX_LINKS) |
| 3555 |
break; |
| 3556 |
|
| 3557 |
arsta_p = rcu_dereference(ahsta->link[link_id]); |
| 3558 |
arvif = rcu_dereference(ahsta->ahvif->link[link_id]); |
| 3559 |
|
| 3560 |
if (arsta_p == arsta) |
| 3561 |
continue; |
| 3562 |
|
| 3563 |
if (!arvif->is_started) |
| 3564 |
continue; |
| 3565 |
|
| 3566 |
ml->partner_info[i].vdev_id = arvif->vdev_id; |
| 3567 |
ml->partner_info[i].hw_link_id = arvif->ar->pdev->hw_link_id; |
| 3568 |
ml->partner_info[i].assoc_link = arsta_p->is_assoc_link; |
| 3569 |
ml->partner_info[i].primary_umac = arsta_p->is_assoc_link; |
| 3570 |
ml->partner_info[i].logical_link_idx_valid = true; |
| 3571 |
ml->partner_info[i].logical_link_idx = arsta_p->link_idx; |
| 3572 |
ml->num_partner_links++; |
| 3573 |
|
| 3574 |
i++; |
| 3575 |
} |
| 3576 |
|
| 3577 |
rcu_read_unlock(); |
| 3578 |
} |
| 3579 |
|
| 3580 |
static void ath12k_peer_assoc_prepare(struct ath12k *ar, |
| 3581 |
struct ath12k_link_vif *arvif, |
| 3582 |
struct ath12k_link_sta *arsta, |
| 3583 |
struct ath12k_wmi_peer_assoc_arg *arg, |
| 3584 |
bool reassoc) |
| 3585 |
{ |
| 3586 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 3587 |
|
| 3588 |
memset(arg, 0, sizeof(*arg)); |
| 3589 |
|
| 3590 |
reinit_completion(&ar->peer_assoc_done); |
| 3591 |
|
| 3592 |
arg->peer_new_assoc = !reassoc; |
| 3593 |
ath12k_peer_assoc_h_basic(ar, arvif, arsta, arg); |
| 3594 |
ath12k_peer_assoc_h_crypto(ar, arvif, arsta, arg); |
| 3595 |
ath12k_peer_assoc_h_rates(ar, arvif, arsta, arg); |
| 3596 |
ath12k_peer_assoc_h_ht(ar, arvif, arsta, arg); |
| 3597 |
ath12k_peer_assoc_h_vht(ar, arvif, arsta, arg); |
| 3598 |
ath12k_peer_assoc_h_he(ar, arvif, arsta, arg); |
| 3599 |
ath12k_peer_assoc_h_he_6ghz(ar, arvif, arsta, arg); |
| 3600 |
ath12k_peer_assoc_h_eht(ar, arvif, arsta, arg); |
| 3601 |
ath12k_peer_assoc_h_qos(ar, arvif, arsta, arg); |
| 3602 |
ath12k_peer_assoc_h_phymode(ar, arvif, arsta, arg); |
| 3603 |
ath12k_peer_assoc_h_smps(arsta, arg); |
| 3604 |
ath12k_peer_assoc_h_mlo(arsta, arg); |
| 3605 |
|
| 3606 |
arsta->peer_nss = arg->peer_nss; |
| 3607 |
/* TODO: amsdu_disable req? */ |
| 3608 |
} |
| 3609 |
|
| 3610 |
static int ath12k_setup_peer_smps(struct ath12k *ar, struct ath12k_link_vif *arvif, |
| 3611 |
const u8 *addr, |
| 3612 |
const struct ieee80211_sta_ht_cap *ht_cap, |
| 3613 |
const struct ieee80211_he_6ghz_capa *he_6ghz_capa) |
| 3614 |
{ |
| 3615 |
int smps, ret = 0; |
| 3616 |
|
| 3617 |
if (!ht_cap->ht_supported && !he_6ghz_capa) |
| 3618 |
return 0; |
| 3619 |
|
| 3620 |
ret = ath12k_get_smps_from_capa(ht_cap, he_6ghz_capa, &smps); |
| 3621 |
if (ret < 0) |
| 3622 |
return ret; |
| 3623 |
|
| 3624 |
return ath12k_wmi_set_peer_param(ar, addr, arvif->vdev_id, |
| 3625 |
WMI_PEER_MIMO_PS_STATE, |
| 3626 |
ath12k_smps_map[smps]); |
| 3627 |
} |
| 3628 |
|
| 3629 |
static int ath12k_mac_set_he_txbf_conf(struct ath12k_link_vif *arvif) |
| 3630 |
{ |
| 3631 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 3632 |
struct ath12k *ar = arvif->ar; |
| 3633 |
u32 param = WMI_VDEV_PARAM_SET_HEMU_MODE; |
| 3634 |
u32 value = 0; |
| 3635 |
int ret; |
| 3636 |
struct ieee80211_bss_conf *link_conf; |
| 3637 |
|
| 3638 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 3639 |
if (!link_conf) { |
| 3640 |
ath12k_warn(ar->ab, "unable to access bss link conf in txbf conf\n"); |
| 3641 |
return -EINVAL; |
| 3642 |
} |
| 3643 |
|
| 3644 |
if (!link_conf->he_support) |
| 3645 |
return 0; |
| 3646 |
|
| 3647 |
if (link_conf->he_su_beamformer) { |
| 3648 |
value |= u32_encode_bits(HE_SU_BFER_ENABLE, HE_MODE_SU_TX_BFER); |
| 3649 |
if (link_conf->he_mu_beamformer && |
| 3650 |
ahvif->vdev_type == WMI_VDEV_TYPE_AP) |
| 3651 |
value |= u32_encode_bits(HE_MU_BFER_ENABLE, HE_MODE_MU_TX_BFER); |
| 3652 |
} |
| 3653 |
|
| 3654 |
if (ahvif->vif->type != NL80211_IFTYPE_MESH_POINT) { |
| 3655 |
value |= u32_encode_bits(HE_DL_MUOFDMA_ENABLE, HE_MODE_DL_OFDMA) | |
| 3656 |
u32_encode_bits(HE_UL_MUOFDMA_ENABLE, HE_MODE_UL_OFDMA); |
| 3657 |
|
| 3658 |
if (link_conf->he_full_ul_mumimo) |
| 3659 |
value |= u32_encode_bits(HE_UL_MUMIMO_ENABLE, HE_MODE_UL_MUMIMO); |
| 3660 |
|
| 3661 |
if (link_conf->he_su_beamformee) |
| 3662 |
value |= u32_encode_bits(HE_SU_BFEE_ENABLE, HE_MODE_SU_TX_BFEE); |
| 3663 |
} |
| 3664 |
|
| 3665 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, value); |
| 3666 |
if (ret) { |
| 3667 |
ath12k_warn(ar->ab, "failed to set vdev %d HE MU mode: %d\n", |
| 3668 |
arvif->vdev_id, ret); |
| 3669 |
return ret; |
| 3670 |
} |
| 3671 |
|
| 3672 |
param = WMI_VDEV_PARAM_SET_HE_SOUNDING_MODE; |
| 3673 |
value = u32_encode_bits(HE_VHT_SOUNDING_MODE_ENABLE, HE_VHT_SOUNDING_MODE) | |
| 3674 |
u32_encode_bits(HE_TRIG_NONTRIG_SOUNDING_MODE_ENABLE, |
| 3675 |
HE_TRIG_NONTRIG_SOUNDING_MODE); |
| 3676 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 3677 |
param, value); |
| 3678 |
if (ret) { |
| 3679 |
ath12k_warn(ar->ab, "failed to set vdev %d sounding mode: %d\n", |
| 3680 |
arvif->vdev_id, ret); |
| 3681 |
return ret; |
| 3682 |
} |
| 3683 |
|
| 3684 |
return 0; |
| 3685 |
} |
| 3686 |
|
| 3687 |
static int ath12k_mac_vif_recalc_sta_he_txbf(struct ath12k *ar, |
| 3688 |
struct ath12k_link_vif *arvif, |
| 3689 |
struct ieee80211_sta_he_cap *he_cap, |
| 3690 |
int *hemode) |
| 3691 |
{ |
| 3692 |
struct ieee80211_vif *vif = arvif->ahvif->vif; |
| 3693 |
struct ieee80211_he_cap_elem he_cap_elem = {}; |
| 3694 |
struct ieee80211_sta_he_cap *cap_band; |
| 3695 |
struct cfg80211_chan_def def; |
| 3696 |
u8 link_id = arvif->link_id; |
| 3697 |
struct ieee80211_bss_conf *link_conf; |
| 3698 |
|
| 3699 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 3700 |
if (!link_conf) { |
| 3701 |
ath12k_warn(ar->ab, "unable to access bss link conf in recalc txbf conf\n"); |
| 3702 |
return -EINVAL; |
| 3703 |
} |
| 3704 |
|
| 3705 |
if (!link_conf->he_support) |
| 3706 |
return 0; |
| 3707 |
|
| 3708 |
if (vif->type != NL80211_IFTYPE_STATION) |
| 3709 |
return -EINVAL; |
| 3710 |
|
| 3711 |
if (WARN_ON(ath12k_mac_vif_link_chan(vif, link_id, &def))) |
| 3712 |
return -EINVAL; |
| 3713 |
|
| 3714 |
if (def.chan->band == NL80211_BAND_2GHZ) |
| 3715 |
cap_band = &ar->mac.iftype[NL80211_BAND_2GHZ][vif->type].he_cap; |
| 3716 |
else |
| 3717 |
cap_band = &ar->mac.iftype[NL80211_BAND_5GHZ][vif->type].he_cap; |
| 3718 |
|
| 3719 |
memcpy(&he_cap_elem, &cap_band->he_cap_elem, sizeof(he_cap_elem)); |
| 3720 |
|
| 3721 |
*hemode = 0; |
| 3722 |
if (HECAP_PHY_SUBFME_GET(he_cap_elem.phy_cap_info)) { |
| 3723 |
if (HECAP_PHY_SUBFMR_GET(he_cap->he_cap_elem.phy_cap_info)) |
| 3724 |
*hemode |= u32_encode_bits(HE_SU_BFEE_ENABLE, HE_MODE_SU_TX_BFEE); |
| 3725 |
if (HECAP_PHY_MUBFMR_GET(he_cap->he_cap_elem.phy_cap_info)) |
| 3726 |
*hemode |= u32_encode_bits(HE_MU_BFEE_ENABLE, HE_MODE_MU_TX_BFEE); |
| 3727 |
} |
| 3728 |
|
| 3729 |
if (vif->type != NL80211_IFTYPE_MESH_POINT) { |
| 3730 |
*hemode |= u32_encode_bits(HE_DL_MUOFDMA_ENABLE, HE_MODE_DL_OFDMA) | |
| 3731 |
u32_encode_bits(HE_UL_MUOFDMA_ENABLE, HE_MODE_UL_OFDMA); |
| 3732 |
|
| 3733 |
if (HECAP_PHY_ULMUMIMO_GET(he_cap_elem.phy_cap_info)) |
| 3734 |
if (HECAP_PHY_ULMUMIMO_GET(he_cap->he_cap_elem.phy_cap_info)) |
| 3735 |
*hemode |= u32_encode_bits(HE_UL_MUMIMO_ENABLE, |
| 3736 |
HE_MODE_UL_MUMIMO); |
| 3737 |
|
| 3738 |
if (u32_get_bits(*hemode, HE_MODE_MU_TX_BFEE)) |
| 3739 |
*hemode |= u32_encode_bits(HE_SU_BFEE_ENABLE, HE_MODE_SU_TX_BFEE); |
| 3740 |
|
| 3741 |
if (u32_get_bits(*hemode, HE_MODE_MU_TX_BFER)) |
| 3742 |
*hemode |= u32_encode_bits(HE_SU_BFER_ENABLE, HE_MODE_SU_TX_BFER); |
| 3743 |
} |
| 3744 |
|
| 3745 |
return 0; |
| 3746 |
} |
| 3747 |
|
| 3748 |
static int ath12k_mac_set_eht_txbf_conf(struct ath12k_link_vif *arvif) |
| 3749 |
{ |
| 3750 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 3751 |
struct ath12k *ar = arvif->ar; |
| 3752 |
u32 param = WMI_VDEV_PARAM_SET_EHT_MU_MODE; |
| 3753 |
u32 value = 0; |
| 3754 |
int ret; |
| 3755 |
struct ieee80211_bss_conf *link_conf; |
| 3756 |
|
| 3757 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 3758 |
if (!link_conf) { |
| 3759 |
ath12k_warn(ar->ab, "unable to access bss link conf in eht txbf conf\n"); |
| 3760 |
return -ENOENT; |
| 3761 |
} |
| 3762 |
|
| 3763 |
if (!link_conf->eht_support) |
| 3764 |
return 0; |
| 3765 |
|
| 3766 |
if (link_conf->eht_su_beamformer) { |
| 3767 |
value |= u32_encode_bits(EHT_SU_BFER_ENABLE, EHT_MODE_SU_TX_BFER); |
| 3768 |
if (link_conf->eht_mu_beamformer && |
| 3769 |
ahvif->vdev_type == WMI_VDEV_TYPE_AP) |
| 3770 |
value |= u32_encode_bits(EHT_MU_BFER_ENABLE, |
| 3771 |
EHT_MODE_MU_TX_BFER) | |
| 3772 |
u32_encode_bits(EHT_DL_MUOFDMA_ENABLE, |
| 3773 |
EHT_MODE_DL_OFDMA_MUMIMO) | |
| 3774 |
u32_encode_bits(EHT_UL_MUOFDMA_ENABLE, |
| 3775 |
EHT_MODE_UL_OFDMA_MUMIMO); |
| 3776 |
} |
| 3777 |
|
| 3778 |
if (ahvif->vif->type != NL80211_IFTYPE_MESH_POINT) { |
| 3779 |
value |= u32_encode_bits(EHT_DL_MUOFDMA_ENABLE, EHT_MODE_DL_OFDMA) | |
| 3780 |
u32_encode_bits(EHT_UL_MUOFDMA_ENABLE, EHT_MODE_UL_OFDMA); |
| 3781 |
|
| 3782 |
if (link_conf->eht_80mhz_full_bw_ul_mumimo) |
| 3783 |
value |= u32_encode_bits(EHT_UL_MUMIMO_ENABLE, EHT_MODE_MUMIMO); |
| 3784 |
|
| 3785 |
if (link_conf->eht_su_beamformee) |
| 3786 |
value |= u32_encode_bits(EHT_SU_BFEE_ENABLE, |
| 3787 |
EHT_MODE_SU_TX_BFEE); |
| 3788 |
} |
| 3789 |
|
| 3790 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, value); |
| 3791 |
if (ret) { |
| 3792 |
ath12k_warn(ar->ab, "failed to set vdev %d EHT MU mode: %d\n", |
| 3793 |
arvif->vdev_id, ret); |
| 3794 |
return ret; |
| 3795 |
} |
| 3796 |
|
| 3797 |
return 0; |
| 3798 |
} |
| 3799 |
|
| 3800 |
static u32 ath12k_mac_ieee80211_sta_bw_to_wmi(struct ath12k *ar, |
| 3801 |
struct ieee80211_link_sta *link_sta) |
| 3802 |
{ |
| 3803 |
u32 bw; |
| 3804 |
|
| 3805 |
switch (link_sta->bandwidth) { |
| 3806 |
case IEEE80211_STA_RX_BW_20: |
| 3807 |
bw = WMI_PEER_CHWIDTH_20MHZ; |
| 3808 |
break; |
| 3809 |
case IEEE80211_STA_RX_BW_40: |
| 3810 |
bw = WMI_PEER_CHWIDTH_40MHZ; |
| 3811 |
break; |
| 3812 |
case IEEE80211_STA_RX_BW_80: |
| 3813 |
bw = WMI_PEER_CHWIDTH_80MHZ; |
| 3814 |
break; |
| 3815 |
case IEEE80211_STA_RX_BW_160: |
| 3816 |
bw = WMI_PEER_CHWIDTH_160MHZ; |
| 3817 |
break; |
| 3818 |
case IEEE80211_STA_RX_BW_320: |
| 3819 |
bw = WMI_PEER_CHWIDTH_320MHZ; |
| 3820 |
break; |
| 3821 |
default: |
| 3822 |
ath12k_warn(ar->ab, "Invalid bandwidth %d for link station %pM\n", |
| 3823 |
link_sta->bandwidth, link_sta->addr); |
| 3824 |
bw = WMI_PEER_CHWIDTH_20MHZ; |
| 3825 |
break; |
| 3826 |
} |
| 3827 |
|
| 3828 |
return bw; |
| 3829 |
} |
| 3830 |
|
| 3831 |
static void ath12k_bss_assoc(struct ath12k *ar, |
| 3832 |
struct ath12k_link_vif *arvif, |
| 3833 |
struct ieee80211_bss_conf *bss_conf) |
| 3834 |
{ |
| 3835 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 3836 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); |
| 3837 |
struct ath12k_wmi_vdev_up_params params = {}; |
| 3838 |
struct ieee80211_link_sta *link_sta; |
| 3839 |
u8 link_id = bss_conf->link_id; |
| 3840 |
struct ath12k_link_sta *arsta; |
| 3841 |
struct ieee80211_sta *ap_sta; |
| 3842 |
struct ath12k_sta *ahsta; |
| 3843 |
struct ath12k_dp_link_peer *peer; |
| 3844 |
bool is_auth = false; |
| 3845 |
u32 hemode = 0; |
| 3846 |
int ret; |
| 3847 |
struct ath12k_dp *dp = ath12k_ab_to_dp(ar->ab); |
| 3848 |
|
| 3849 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 3850 |
|
| 3851 |
struct ath12k_wmi_peer_assoc_arg *peer_arg __free(kfree) = |
| 3852 |
kzalloc_obj(*peer_arg); |
| 3853 |
if (!peer_arg) |
| 3854 |
return; |
| 3855 |
|
| 3856 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 3857 |
"mac vdev %i link id %u assoc bssid %pM aid %d\n", |
| 3858 |
arvif->vdev_id, link_id, arvif->bssid, ahvif->aid); |
| 3859 |
|
| 3860 |
rcu_read_lock(); |
| 3861 |
|
| 3862 |
/* During ML connection, cfg.ap_addr has the MLD address. For |
| 3863 |
* non-ML connection, it has the BSSID. |
| 3864 |
*/ |
| 3865 |
ap_sta = ieee80211_find_sta(vif, vif->cfg.ap_addr); |
| 3866 |
if (!ap_sta) { |
| 3867 |
ath12k_warn(ar->ab, "failed to find station entry for bss %pM vdev %i\n", |
| 3868 |
vif->cfg.ap_addr, arvif->vdev_id); |
| 3869 |
rcu_read_unlock(); |
| 3870 |
return; |
| 3871 |
} |
| 3872 |
|
| 3873 |
ahsta = ath12k_sta_to_ahsta(ap_sta); |
| 3874 |
|
| 3875 |
arsta = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, |
| 3876 |
ahsta->link[link_id]); |
| 3877 |
if (WARN_ON(!arsta)) { |
| 3878 |
rcu_read_unlock(); |
| 3879 |
return; |
| 3880 |
} |
| 3881 |
|
| 3882 |
link_sta = ath12k_mac_get_link_sta(arsta); |
| 3883 |
if (WARN_ON(!link_sta)) { |
| 3884 |
rcu_read_unlock(); |
| 3885 |
return; |
| 3886 |
} |
| 3887 |
|
| 3888 |
ath12k_peer_assoc_prepare(ar, arvif, arsta, peer_arg, false); |
| 3889 |
|
| 3890 |
/* link_sta->he_cap must be protected by rcu_read_lock */ |
| 3891 |
ret = ath12k_mac_vif_recalc_sta_he_txbf(ar, arvif, &link_sta->he_cap, &hemode); |
| 3892 |
if (ret) { |
| 3893 |
ath12k_warn(ar->ab, "failed to recalc he txbf for vdev %i on bss %pM: %d\n", |
| 3894 |
arvif->vdev_id, bss_conf->bssid, ret); |
| 3895 |
rcu_read_unlock(); |
| 3896 |
return; |
| 3897 |
} |
| 3898 |
|
| 3899 |
rcu_read_unlock(); |
| 3900 |
|
| 3901 |
/* keep this before ath12k_wmi_send_peer_assoc_cmd() */ |
| 3902 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 3903 |
WMI_VDEV_PARAM_SET_HEMU_MODE, hemode); |
| 3904 |
if (ret) { |
| 3905 |
ath12k_warn(ar->ab, "failed to submit vdev param txbf 0x%x: %d\n", |
| 3906 |
hemode, ret); |
| 3907 |
return; |
| 3908 |
} |
| 3909 |
|
| 3910 |
peer_arg->is_assoc = true; |
| 3911 |
ret = ath12k_wmi_send_peer_assoc_cmd(ar, peer_arg); |
| 3912 |
if (ret) { |
| 3913 |
ath12k_warn(ar->ab, "failed to run peer assoc for %pM vdev %i: %d\n", |
| 3914 |
bss_conf->bssid, arvif->vdev_id, ret); |
| 3915 |
return; |
| 3916 |
} |
| 3917 |
|
| 3918 |
if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) { |
| 3919 |
ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", |
| 3920 |
bss_conf->bssid, arvif->vdev_id); |
| 3921 |
return; |
| 3922 |
} |
| 3923 |
|
| 3924 |
ret = ath12k_setup_peer_smps(ar, arvif, bss_conf->bssid, |
| 3925 |
&link_sta->ht_cap, &link_sta->he_6ghz_capa); |
| 3926 |
if (ret) { |
| 3927 |
ath12k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n", |
| 3928 |
arvif->vdev_id, ret); |
| 3929 |
return; |
| 3930 |
} |
| 3931 |
|
| 3932 |
WARN_ON(arvif->is_up); |
| 3933 |
|
| 3934 |
ahvif->aid = vif->cfg.aid; |
| 3935 |
ether_addr_copy(arvif->bssid, bss_conf->bssid); |
| 3936 |
|
| 3937 |
params.vdev_id = arvif->vdev_id; |
| 3938 |
params.aid = ahvif->aid; |
| 3939 |
params.bssid = arvif->bssid; |
| 3940 |
params.tx_bssid = ath12k_mac_get_tx_bssid(arvif); |
| 3941 |
if (params.tx_bssid) { |
| 3942 |
params.nontx_profile_idx = bss_conf->bssid_index; |
| 3943 |
params.nontx_profile_cnt = 1 << bss_conf->bssid_indicator; |
| 3944 |
} |
| 3945 |
ret = ath12k_wmi_vdev_up(ar, ¶ms); |
| 3946 |
if (ret) { |
| 3947 |
ath12k_warn(ar->ab, "failed to set vdev %d up: %d\n", |
| 3948 |
arvif->vdev_id, ret); |
| 3949 |
return; |
| 3950 |
} |
| 3951 |
|
| 3952 |
arvif->is_up = true; |
| 3953 |
arvif->rekey_data.enable_offload = false; |
| 3954 |
|
| 3955 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 3956 |
"mac vdev %d up (associated) bssid %pM aid %d\n", |
| 3957 |
arvif->vdev_id, bss_conf->bssid, vif->cfg.aid); |
| 3958 |
|
| 3959 |
spin_lock_bh(&dp->dp_lock); |
| 3960 |
|
| 3961 |
peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id, |
| 3962 |
arvif->bssid); |
| 3963 |
if (peer && peer->is_authorized) |
| 3964 |
is_auth = true; |
| 3965 |
|
| 3966 |
spin_unlock_bh(&dp->dp_lock); |
| 3967 |
|
| 3968 |
/* Authorize BSS Peer */ |
| 3969 |
if (is_auth) { |
| 3970 |
ret = ath12k_wmi_set_peer_param(ar, arvif->bssid, |
| 3971 |
arvif->vdev_id, |
| 3972 |
WMI_PEER_AUTHORIZE, |
| 3973 |
1); |
| 3974 |
if (ret) |
| 3975 |
ath12k_warn(ar->ab, "Unable to authorize BSS peer: %d\n", ret); |
| 3976 |
} |
| 3977 |
|
| 3978 |
ret = ath12k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id, |
| 3979 |
&bss_conf->he_obss_pd); |
| 3980 |
if (ret) |
| 3981 |
ath12k_warn(ar->ab, "failed to set vdev %i OBSS PD parameters: %d\n", |
| 3982 |
arvif->vdev_id, ret); |
| 3983 |
|
| 3984 |
if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map) && |
| 3985 |
ahvif->vdev_type == WMI_VDEV_TYPE_STA && |
| 3986 |
ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) |
| 3987 |
ath12k_mac_11d_scan_stop_all(ar->ab); |
| 3988 |
} |
| 3989 |
|
| 3990 |
static void ath12k_bss_disassoc(struct ath12k *ar, |
| 3991 |
struct ath12k_link_vif *arvif) |
| 3992 |
{ |
| 3993 |
int ret; |
| 3994 |
|
| 3995 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 3996 |
|
| 3997 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n", |
| 3998 |
arvif->vdev_id, arvif->bssid); |
| 3999 |
|
| 4000 |
ret = ath12k_wmi_vdev_down(ar, arvif->vdev_id); |
| 4001 |
if (ret) |
| 4002 |
ath12k_warn(ar->ab, "failed to down vdev %i: %d\n", |
| 4003 |
arvif->vdev_id, ret); |
| 4004 |
|
| 4005 |
arvif->is_up = false; |
| 4006 |
|
| 4007 |
memset(&arvif->rekey_data, 0, sizeof(arvif->rekey_data)); |
| 4008 |
|
| 4009 |
cancel_delayed_work(&arvif->connection_loss_work); |
| 4010 |
} |
| 4011 |
|
| 4012 |
static u32 ath12k_mac_get_rate_hw_value(int bitrate) |
| 4013 |
{ |
| 4014 |
u32 preamble; |
| 4015 |
u16 hw_value; |
| 4016 |
int rate; |
| 4017 |
size_t i; |
| 4018 |
|
| 4019 |
if (ath12k_mac_bitrate_is_cck(bitrate)) |
| 4020 |
preamble = WMI_RATE_PREAMBLE_CCK; |
| 4021 |
else |
| 4022 |
preamble = WMI_RATE_PREAMBLE_OFDM; |
| 4023 |
|
| 4024 |
for (i = 0; i < ARRAY_SIZE(ath12k_legacy_rates); i++) { |
| 4025 |
if (ath12k_legacy_rates[i].bitrate != bitrate) |
| 4026 |
continue; |
| 4027 |
|
| 4028 |
hw_value = ath12k_legacy_rates[i].hw_value; |
| 4029 |
rate = ATH12K_HW_RATE_CODE(hw_value, 0, preamble); |
| 4030 |
|
| 4031 |
return rate; |
| 4032 |
} |
| 4033 |
|
| 4034 |
return -EINVAL; |
| 4035 |
} |
| 4036 |
|
| 4037 |
static void ath12k_recalculate_mgmt_rate(struct ath12k *ar, |
| 4038 |
struct ath12k_link_vif *arvif, |
| 4039 |
struct cfg80211_chan_def *def) |
| 4040 |
{ |
| 4041 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 4042 |
struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
| 4043 |
const struct ieee80211_supported_band *sband; |
| 4044 |
struct ieee80211_bss_conf *bss_conf; |
| 4045 |
u8 basic_rate_idx; |
| 4046 |
int hw_rate_code; |
| 4047 |
u32 vdev_param; |
| 4048 |
u16 bitrate; |
| 4049 |
int ret; |
| 4050 |
|
| 4051 |
lockdep_assert_wiphy(hw->wiphy); |
| 4052 |
|
| 4053 |
bss_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 4054 |
if (!bss_conf) { |
| 4055 |
ath12k_warn(ar->ab, "unable to access bss link conf in mgmt rate calc for vif %pM link %u\n", |
| 4056 |
vif->addr, arvif->link_id); |
| 4057 |
return; |
| 4058 |
} |
| 4059 |
|
| 4060 |
sband = hw->wiphy->bands[def->chan->band]; |
| 4061 |
if (bss_conf->basic_rates) |
| 4062 |
basic_rate_idx = __ffs(bss_conf->basic_rates); |
| 4063 |
else |
| 4064 |
basic_rate_idx = 0; |
| 4065 |
bitrate = sband->bitrates[basic_rate_idx].bitrate; |
| 4066 |
|
| 4067 |
hw_rate_code = ath12k_mac_get_rate_hw_value(bitrate); |
| 4068 |
if (hw_rate_code < 0) { |
| 4069 |
ath12k_warn(ar->ab, "bitrate not supported %d\n", bitrate); |
| 4070 |
return; |
| 4071 |
} |
| 4072 |
|
| 4073 |
vdev_param = WMI_VDEV_PARAM_MGMT_RATE; |
| 4074 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param, |
| 4075 |
hw_rate_code); |
| 4076 |
if (ret) |
| 4077 |
ath12k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret); |
| 4078 |
|
| 4079 |
vdev_param = WMI_VDEV_PARAM_BEACON_RATE; |
| 4080 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param, |
| 4081 |
hw_rate_code); |
| 4082 |
if (ret) |
| 4083 |
ath12k_warn(ar->ab, "failed to set beacon tx rate %d\n", ret); |
| 4084 |
} |
| 4085 |
|
| 4086 |
static void ath12k_mac_bcn_tx_event(struct ath12k_link_vif *arvif) |
| 4087 |
{ |
| 4088 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 4089 |
struct ieee80211_bss_conf *link_conf; |
| 4090 |
|
| 4091 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 4092 |
if (!link_conf) { |
| 4093 |
ath12k_warn(arvif->ar->ab, "failed to get link conf for vdev %u\n", |
| 4094 |
arvif->vdev_id); |
| 4095 |
return; |
| 4096 |
} |
| 4097 |
|
| 4098 |
if (link_conf->color_change_active) { |
| 4099 |
if (ieee80211_beacon_cntdwn_is_complete(vif, arvif->link_id)) { |
| 4100 |
ieee80211_color_change_finish(vif, arvif->link_id); |
| 4101 |
return; |
| 4102 |
} |
| 4103 |
|
| 4104 |
ieee80211_beacon_update_cntdwn(vif, arvif->link_id); |
| 4105 |
ath12k_mac_setup_bcn_tmpl(arvif); |
| 4106 |
} |
| 4107 |
} |
| 4108 |
|
| 4109 |
static void ath12k_mac_bcn_tx_work(struct wiphy *wiphy, struct wiphy_work *work) |
| 4110 |
{ |
| 4111 |
struct ath12k_link_vif *arvif = container_of(work, struct ath12k_link_vif, |
| 4112 |
bcn_tx_work); |
| 4113 |
|
| 4114 |
lockdep_assert_wiphy(wiphy); |
| 4115 |
ath12k_mac_bcn_tx_event(arvif); |
| 4116 |
} |
| 4117 |
|
| 4118 |
static void ath12k_mac_init_arvif(struct ath12k_vif *ahvif, |
| 4119 |
struct ath12k_link_vif *arvif, int link_id) |
| 4120 |
{ |
| 4121 |
struct ath12k_hw *ah = ahvif->ah; |
| 4122 |
u8 _link_id; |
| 4123 |
int i; |
| 4124 |
|
| 4125 |
lockdep_assert_wiphy(ah->hw->wiphy); |
| 4126 |
|
| 4127 |
if (WARN_ON(!arvif)) |
| 4128 |
return; |
| 4129 |
|
| 4130 |
if (WARN_ON(link_id >= ATH12K_NUM_MAX_LINKS)) |
| 4131 |
return; |
| 4132 |
|
| 4133 |
if (link_id < 0) |
| 4134 |
_link_id = 0; |
| 4135 |
else |
| 4136 |
_link_id = link_id; |
| 4137 |
|
| 4138 |
arvif->ahvif = ahvif; |
| 4139 |
arvif->link_id = _link_id; |
| 4140 |
|
| 4141 |
/* Protects the datapath stats update on a per link basis */ |
| 4142 |
spin_lock_init(&arvif->link_stats_lock); |
| 4143 |
|
| 4144 |
INIT_LIST_HEAD(&arvif->list); |
| 4145 |
INIT_DELAYED_WORK(&arvif->connection_loss_work, |
| 4146 |
ath12k_mac_vif_sta_connection_loss_work); |
| 4147 |
wiphy_work_init(&arvif->bcn_tx_work, ath12k_mac_bcn_tx_work); |
| 4148 |
|
| 4149 |
arvif->num_stations = 0; |
| 4150 |
|
| 4151 |
for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) { |
| 4152 |
arvif->bitrate_mask.control[i].legacy = 0xffffffff; |
| 4153 |
arvif->bitrate_mask.control[i].gi = NL80211_TXRATE_DEFAULT_GI; |
| 4154 |
memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff, |
| 4155 |
sizeof(arvif->bitrate_mask.control[i].ht_mcs)); |
| 4156 |
memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff, |
| 4157 |
sizeof(arvif->bitrate_mask.control[i].vht_mcs)); |
| 4158 |
memset(arvif->bitrate_mask.control[i].he_mcs, 0xff, |
| 4159 |
sizeof(arvif->bitrate_mask.control[i].he_mcs)); |
| 4160 |
memset(arvif->bitrate_mask.control[i].eht_mcs, 0xff, |
| 4161 |
sizeof(arvif->bitrate_mask.control[i].eht_mcs)); |
| 4162 |
} |
| 4163 |
|
| 4164 |
/* Handle MLO related assignments */ |
| 4165 |
if (link_id >= 0) { |
| 4166 |
rcu_assign_pointer(ahvif->link[arvif->link_id], arvif); |
| 4167 |
ahvif->links_map |= BIT(_link_id); |
| 4168 |
} |
| 4169 |
|
| 4170 |
ath12k_generic_dbg(ATH12K_DBG_MAC, |
| 4171 |
"mac init link arvif (link_id %d%s) for vif %pM. links_map 0x%x", |
| 4172 |
_link_id, (link_id < 0) ? " deflink" : "", ahvif->vif->addr, |
| 4173 |
ahvif->links_map); |
| 4174 |
} |
| 4175 |
|
| 4176 |
static void ath12k_mac_remove_link_interface(struct ieee80211_hw *hw, |
| 4177 |
struct ath12k_link_vif *arvif) |
| 4178 |
{ |
| 4179 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 4180 |
struct ath12k_hw *ah = hw->priv; |
| 4181 |
struct ath12k *ar = arvif->ar; |
| 4182 |
int ret; |
| 4183 |
|
| 4184 |
lockdep_assert_wiphy(ah->hw->wiphy); |
| 4185 |
|
| 4186 |
cancel_delayed_work_sync(&arvif->connection_loss_work); |
| 4187 |
wiphy_work_cancel(ath12k_ar_to_hw(ar)->wiphy, &arvif->bcn_tx_work); |
| 4188 |
|
| 4189 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac remove link interface (vdev %d link id %d)", |
| 4190 |
arvif->vdev_id, arvif->link_id); |
| 4191 |
|
| 4192 |
if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map) && |
| 4193 |
ahvif->vdev_type == WMI_VDEV_TYPE_STA && |
| 4194 |
ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) |
| 4195 |
ath12k_mac_11d_scan_stop(ar); |
| 4196 |
|
| 4197 |
if (ahvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 4198 |
ret = ath12k_peer_delete(ar, arvif->vdev_id, arvif->bssid); |
| 4199 |
if (ret) |
| 4200 |
ath12k_warn(ar->ab, "failed to submit AP self-peer removal on vdev %d link id %d: %d", |
| 4201 |
arvif->vdev_id, arvif->link_id, ret); |
| 4202 |
|
| 4203 |
if (arvif->link_id < IEEE80211_MLD_MAX_NUM_LINKS) |
| 4204 |
ath12k_dp_peer_delete(&ah->dp_hw, arvif->bssid, NULL); |
| 4205 |
} |
| 4206 |
ath12k_mac_vdev_delete(ar, arvif); |
| 4207 |
} |
| 4208 |
|
| 4209 |
static struct ath12k_link_vif *ath12k_mac_assign_link_vif(struct ath12k_hw *ah, |
| 4210 |
struct ieee80211_vif *vif, |
| 4211 |
u8 link_id) |
| 4212 |
{ |
| 4213 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 4214 |
struct ath12k_link_vif *arvif; |
| 4215 |
|
| 4216 |
lockdep_assert_wiphy(ah->hw->wiphy); |
| 4217 |
|
| 4218 |
arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); |
| 4219 |
if (arvif) |
| 4220 |
return arvif; |
| 4221 |
|
| 4222 |
/* If this is the first link arvif being created for an ML VIF |
| 4223 |
* use the preallocated deflink memory except for scan arvifs |
| 4224 |
*/ |
| 4225 |
if (!ahvif->links_map && link_id < ATH12K_FIRST_SCAN_LINK) { |
| 4226 |
arvif = &ahvif->deflink; |
| 4227 |
|
| 4228 |
if (vif->type == NL80211_IFTYPE_STATION) |
| 4229 |
arvif->is_sta_assoc_link = true; |
| 4230 |
} else { |
| 4231 |
arvif = kzalloc_obj(*arvif); |
| 4232 |
if (!arvif) |
| 4233 |
return NULL; |
| 4234 |
} |
| 4235 |
|
| 4236 |
ath12k_mac_init_arvif(ahvif, arvif, link_id); |
| 4237 |
|
| 4238 |
return arvif; |
| 4239 |
} |
| 4240 |
|
| 4241 |
static void ath12k_mac_unassign_link_vif(struct ath12k_link_vif *arvif) |
| 4242 |
{ |
| 4243 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 4244 |
struct ath12k_hw *ah = ahvif->ah; |
| 4245 |
|
| 4246 |
lockdep_assert_wiphy(ah->hw->wiphy); |
| 4247 |
|
| 4248 |
rcu_assign_pointer(ahvif->link[arvif->link_id], NULL); |
| 4249 |
synchronize_rcu(); |
| 4250 |
ahvif->links_map &= ~BIT(arvif->link_id); |
| 4251 |
|
| 4252 |
if (arvif != &ahvif->deflink) |
| 4253 |
kfree(arvif); |
| 4254 |
else |
| 4255 |
memset(arvif, 0, sizeof(*arvif)); |
| 4256 |
} |
| 4257 |
|
| 4258 |
int |
| 4259 |
ath12k_mac_op_change_vif_links(struct ieee80211_hw *hw, |
| 4260 |
struct ieee80211_vif *vif, |
| 4261 |
u16 old_links, u16 new_links, |
| 4262 |
struct ieee80211_bss_conf *ol[IEEE80211_MLD_MAX_NUM_LINKS]) |
| 4263 |
{ |
| 4264 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 4265 |
unsigned long to_remove = old_links & ~new_links; |
| 4266 |
unsigned long to_add = ~old_links & new_links; |
| 4267 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 4268 |
struct ath12k_link_vif *arvif; |
| 4269 |
u8 link_id; |
| 4270 |
|
| 4271 |
lockdep_assert_wiphy(hw->wiphy); |
| 4272 |
|
| 4273 |
ath12k_generic_dbg(ATH12K_DBG_MAC, |
| 4274 |
"mac vif link changed for MLD %pM old_links 0x%x new_links 0x%x\n", |
| 4275 |
vif->addr, old_links, new_links); |
| 4276 |
|
| 4277 |
for_each_set_bit(link_id, &to_add, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 4278 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 4279 |
/* mac80211 wants to add link but driver already has the |
| 4280 |
* link. This should not happen ideally. |
| 4281 |
*/ |
| 4282 |
if (WARN_ON(arvif)) |
| 4283 |
return -EINVAL; |
| 4284 |
|
| 4285 |
arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); |
| 4286 |
if (WARN_ON(!arvif)) |
| 4287 |
return -EINVAL; |
| 4288 |
} |
| 4289 |
|
| 4290 |
for_each_set_bit(link_id, &to_remove, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 4291 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 4292 |
if (WARN_ON(!arvif)) |
| 4293 |
return -EINVAL; |
| 4294 |
|
| 4295 |
if (!arvif->is_created) { |
| 4296 |
ath12k_mac_unassign_link_vif(arvif); |
| 4297 |
continue; |
| 4298 |
} |
| 4299 |
|
| 4300 |
if (WARN_ON(!arvif->ar)) |
| 4301 |
return -EINVAL; |
| 4302 |
|
| 4303 |
ath12k_mac_remove_link_interface(hw, arvif); |
| 4304 |
ath12k_mac_unassign_link_vif(arvif); |
| 4305 |
} |
| 4306 |
|
| 4307 |
return 0; |
| 4308 |
} |
| 4309 |
EXPORT_SYMBOL(ath12k_mac_op_change_vif_links); |
| 4310 |
|
| 4311 |
static int ath12k_mac_fils_discovery(struct ath12k_link_vif *arvif, |
| 4312 |
struct ieee80211_bss_conf *info) |
| 4313 |
{ |
| 4314 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 4315 |
struct ath12k *ar = arvif->ar; |
| 4316 |
struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
| 4317 |
struct sk_buff *tmpl; |
| 4318 |
int ret; |
| 4319 |
u32 interval; |
| 4320 |
bool unsol_bcast_probe_resp_enabled = false; |
| 4321 |
|
| 4322 |
if (info->fils_discovery.max_interval) { |
| 4323 |
interval = info->fils_discovery.max_interval; |
| 4324 |
|
| 4325 |
tmpl = ieee80211_get_fils_discovery_tmpl(hw, vif); |
| 4326 |
if (tmpl) |
| 4327 |
ret = ath12k_wmi_fils_discovery_tmpl(ar, arvif->vdev_id, |
| 4328 |
tmpl); |
| 4329 |
} else if (info->unsol_bcast_probe_resp_interval) { |
| 4330 |
unsol_bcast_probe_resp_enabled = 1; |
| 4331 |
interval = info->unsol_bcast_probe_resp_interval; |
| 4332 |
|
| 4333 |
tmpl = ieee80211_get_unsol_bcast_probe_resp_tmpl(hw, vif); |
| 4334 |
if (tmpl) |
| 4335 |
ret = ath12k_wmi_probe_resp_tmpl(ar, arvif->vdev_id, |
| 4336 |
tmpl); |
| 4337 |
} else { /* Disable */ |
| 4338 |
return ath12k_wmi_fils_discovery(ar, arvif->vdev_id, 0, false); |
| 4339 |
} |
| 4340 |
|
| 4341 |
if (!tmpl) { |
| 4342 |
ath12k_warn(ar->ab, |
| 4343 |
"mac vdev %i failed to retrieve %s template\n", |
| 4344 |
arvif->vdev_id, (unsol_bcast_probe_resp_enabled ? |
| 4345 |
"unsolicited broadcast probe response" : |
| 4346 |
"FILS discovery")); |
| 4347 |
return -EPERM; |
| 4348 |
} |
| 4349 |
kfree_skb(tmpl); |
| 4350 |
|
| 4351 |
if (!ret) |
| 4352 |
ret = ath12k_wmi_fils_discovery(ar, arvif->vdev_id, interval, |
| 4353 |
unsol_bcast_probe_resp_enabled); |
| 4354 |
|
| 4355 |
return ret; |
| 4356 |
} |
| 4357 |
|
| 4358 |
void ath12k_mac_op_vif_cfg_changed(struct ieee80211_hw *hw, |
| 4359 |
struct ieee80211_vif *vif, |
| 4360 |
u64 changed) |
| 4361 |
{ |
| 4362 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 4363 |
unsigned long links = ahvif->links_map; |
| 4364 |
struct ieee80211_bss_conf *info; |
| 4365 |
struct ath12k_link_vif *arvif; |
| 4366 |
struct ieee80211_sta *sta; |
| 4367 |
struct ath12k_sta *ahsta; |
| 4368 |
struct ath12k *ar; |
| 4369 |
u8 link_id; |
| 4370 |
|
| 4371 |
lockdep_assert_wiphy(hw->wiphy); |
| 4372 |
|
| 4373 |
if (changed & BSS_CHANGED_SSID && vif->type == NL80211_IFTYPE_AP) { |
| 4374 |
ahvif->u.ap.ssid_len = vif->cfg.ssid_len; |
| 4375 |
if (vif->cfg.ssid_len) |
| 4376 |
memcpy(ahvif->u.ap.ssid, vif->cfg.ssid, vif->cfg.ssid_len); |
| 4377 |
} |
| 4378 |
|
| 4379 |
if (changed & BSS_CHANGED_ASSOC) { |
| 4380 |
if (vif->cfg.assoc) { |
| 4381 |
/* only in station mode we can get here, so it's safe |
| 4382 |
* to use ap_addr |
| 4383 |
*/ |
| 4384 |
rcu_read_lock(); |
| 4385 |
sta = ieee80211_find_sta(vif, vif->cfg.ap_addr); |
| 4386 |
if (!sta) { |
| 4387 |
rcu_read_unlock(); |
| 4388 |
WARN_ONCE(1, "failed to find sta with addr %pM\n", |
| 4389 |
vif->cfg.ap_addr); |
| 4390 |
return; |
| 4391 |
} |
| 4392 |
|
| 4393 |
ahsta = ath12k_sta_to_ahsta(sta); |
| 4394 |
arvif = wiphy_dereference(hw->wiphy, |
| 4395 |
ahvif->link[ahsta->assoc_link_id]); |
| 4396 |
rcu_read_unlock(); |
| 4397 |
|
| 4398 |
ar = arvif->ar; |
| 4399 |
/* there is no reason for which an assoc link's |
| 4400 |
* bss info does not exist |
| 4401 |
*/ |
| 4402 |
info = ath12k_mac_get_link_bss_conf(arvif); |
| 4403 |
ath12k_bss_assoc(ar, arvif, info); |
| 4404 |
|
| 4405 |
/* exclude assoc link as it is done above */ |
| 4406 |
links &= ~BIT(ahsta->assoc_link_id); |
| 4407 |
} |
| 4408 |
|
| 4409 |
for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 4410 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 4411 |
if (!arvif || !arvif->ar) |
| 4412 |
continue; |
| 4413 |
|
| 4414 |
ar = arvif->ar; |
| 4415 |
|
| 4416 |
if (vif->cfg.assoc) { |
| 4417 |
info = ath12k_mac_get_link_bss_conf(arvif); |
| 4418 |
if (!info) |
| 4419 |
continue; |
| 4420 |
|
| 4421 |
ath12k_bss_assoc(ar, arvif, info); |
| 4422 |
} else { |
| 4423 |
ath12k_bss_disassoc(ar, arvif); |
| 4424 |
} |
| 4425 |
} |
| 4426 |
} |
| 4427 |
} |
| 4428 |
EXPORT_SYMBOL(ath12k_mac_op_vif_cfg_changed); |
| 4429 |
|
| 4430 |
static void ath12k_mac_vif_setup_ps(struct ath12k_link_vif *arvif) |
| 4431 |
{ |
| 4432 |
struct ath12k *ar = arvif->ar; |
| 4433 |
struct ieee80211_vif *vif = arvif->ahvif->vif; |
| 4434 |
struct ieee80211_conf *conf = &ath12k_ar_to_hw(ar)->conf; |
| 4435 |
enum wmi_sta_powersave_param param; |
| 4436 |
struct ieee80211_bss_conf *info; |
| 4437 |
enum wmi_sta_ps_mode psmode; |
| 4438 |
int ret; |
| 4439 |
int timeout; |
| 4440 |
bool enable_ps; |
| 4441 |
|
| 4442 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 4443 |
|
| 4444 |
if (vif->type != NL80211_IFTYPE_STATION) |
| 4445 |
return; |
| 4446 |
|
| 4447 |
enable_ps = arvif->ahvif->ps; |
| 4448 |
if (enable_ps) { |
| 4449 |
psmode = WMI_STA_PS_MODE_ENABLED; |
| 4450 |
param = WMI_STA_PS_PARAM_INACTIVITY_TIME; |
| 4451 |
|
| 4452 |
timeout = conf->dynamic_ps_timeout; |
| 4453 |
if (timeout == 0) { |
| 4454 |
info = ath12k_mac_get_link_bss_conf(arvif); |
| 4455 |
if (!info) { |
| 4456 |
ath12k_warn(ar->ab, "unable to access bss link conf in setup ps for vif %pM link %u\n", |
| 4457 |
vif->addr, arvif->link_id); |
| 4458 |
return; |
| 4459 |
} |
| 4460 |
|
| 4461 |
/* firmware doesn't like 0 */ |
| 4462 |
timeout = ieee80211_tu_to_usec(info->beacon_int) / 1000; |
| 4463 |
} |
| 4464 |
|
| 4465 |
ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, |
| 4466 |
timeout); |
| 4467 |
if (ret) { |
| 4468 |
ath12k_warn(ar->ab, "failed to set inactivity time for vdev %d: %i\n", |
| 4469 |
arvif->vdev_id, ret); |
| 4470 |
return; |
| 4471 |
} |
| 4472 |
} else { |
| 4473 |
psmode = WMI_STA_PS_MODE_DISABLED; |
| 4474 |
} |
| 4475 |
|
| 4476 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d psmode %s\n", |
| 4477 |
arvif->vdev_id, psmode ? "enable" : "disable"); |
| 4478 |
|
| 4479 |
ret = ath12k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, psmode); |
| 4480 |
if (ret) |
| 4481 |
ath12k_warn(ar->ab, "failed to set sta power save mode %d for vdev %d: %d\n", |
| 4482 |
psmode, arvif->vdev_id, ret); |
| 4483 |
} |
| 4484 |
|
| 4485 |
static bool ath12k_mac_supports_tpc(struct ath12k *ar, struct ath12k_vif *ahvif, |
| 4486 |
const struct cfg80211_chan_def *chandef) |
| 4487 |
{ |
| 4488 |
return ath12k_wmi_supports_6ghz_cc_ext(ar) && |
| 4489 |
test_bit(WMI_TLV_SERVICE_EXT_TPC_REG_SUPPORT, ar->ab->wmi_ab.svc_map) && |
| 4490 |
(ahvif->vdev_type == WMI_VDEV_TYPE_STA || |
| 4491 |
ahvif->vdev_type == WMI_VDEV_TYPE_AP) && |
| 4492 |
ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE && |
| 4493 |
chandef->chan && |
| 4494 |
chandef->chan->band == NL80211_BAND_6GHZ; |
| 4495 |
} |
| 4496 |
|
| 4497 |
static void ath12k_wmi_vdev_params_up(struct ath12k *ar, |
| 4498 |
struct ath12k_link_vif *arvif, |
| 4499 |
struct ath12k_link_vif *tx_arvif, |
| 4500 |
struct ieee80211_bss_conf *info, u16 aid) |
| 4501 |
{ |
| 4502 |
struct ath12k_wmi_vdev_up_params params = { |
| 4503 |
.vdev_id = arvif->vdev_id, |
| 4504 |
.aid = aid, |
| 4505 |
.bssid = arvif->bssid |
| 4506 |
}; |
| 4507 |
int ret; |
| 4508 |
|
| 4509 |
if (tx_arvif) { |
| 4510 |
params.tx_bssid = tx_arvif->bssid; |
| 4511 |
params.nontx_profile_idx = info->bssid_index; |
| 4512 |
params.nontx_profile_cnt = 1 << info->bssid_indicator; |
| 4513 |
} |
| 4514 |
|
| 4515 |
ret = ath12k_wmi_vdev_up(arvif->ar, ¶ms); |
| 4516 |
if (ret) |
| 4517 |
ath12k_warn(ar->ab, "failed to bring vdev up %d: %d\n", |
| 4518 |
arvif->vdev_id, ret); |
| 4519 |
} |
| 4520 |
|
| 4521 |
static int ath12k_mac_config_obss_pd(struct ath12k_link_vif *arvif, |
| 4522 |
const struct ieee80211_he_obss_pd *he_obss_pd) |
| 4523 |
{ |
| 4524 |
struct ath12k_wmi_obss_pd_arg obss_pd_arg = {}; |
| 4525 |
u32 srg_bitmap[2], non_srg_bitmap[2]; |
| 4526 |
struct ath12k *ar = arvif->ar; |
| 4527 |
u32 param_id, pdev_id; |
| 4528 |
u32 param_val; |
| 4529 |
int ret; |
| 4530 |
|
| 4531 |
if (ar->ab->hw_params->single_pdev_only) |
| 4532 |
pdev_id = ath12k_mac_get_target_pdev_id_from_vif(arvif); |
| 4533 |
else |
| 4534 |
pdev_id = ar->pdev->pdev_id; |
| 4535 |
|
| 4536 |
/* Set and enable SRG/non-SRG OBSS PD threshold */ |
| 4537 |
param_id = WMI_PDEV_PARAM_SET_CMD_OBSS_PD_THRESHOLD; |
| 4538 |
if (ar->monitor_started || !he_obss_pd->enable) { |
| 4539 |
ret = ath12k_wmi_pdev_set_param(ar, param_id, 0, pdev_id); |
| 4540 |
if (ret) |
| 4541 |
ath12k_warn(ar->ab, |
| 4542 |
"failed to set OBSS PD threshold for pdev %u: %d\n", |
| 4543 |
pdev_id, ret); |
| 4544 |
return ret; |
| 4545 |
} |
| 4546 |
|
| 4547 |
/* |
| 4548 |
* This service flag indicates firmware support for SRG/SRP-based |
| 4549 |
* spatial reuse. It also specifies whether OBSS PD threshold values |
| 4550 |
* should be interpreted as dB (offset) or dBm (absolute) units. |
| 4551 |
*/ |
| 4552 |
obss_pd_arg.srp_support = test_bit(WMI_TLV_SERVICE_SRG_SRP_SPATIAL_REUSE_SUPPORT, |
| 4553 |
ar->ab->wmi_ab.svc_map); |
| 4554 |
|
| 4555 |
if (!(he_obss_pd->sr_ctrl & |
| 4556 |
IEEE80211_HE_SPR_NON_SRG_OBSS_PD_SR_DISALLOWED)) { |
| 4557 |
if (he_obss_pd->sr_ctrl & IEEE80211_HE_SPR_NON_SRG_OFFSET_PRESENT) |
| 4558 |
obss_pd_arg.non_srg_th = ATH12K_OBSS_PD_MAX_THRESHOLD + |
| 4559 |
he_obss_pd->non_srg_max_offset; |
| 4560 |
else |
| 4561 |
obss_pd_arg.non_srg_th = ATH12K_OBSS_PD_NON_SRG_MAX_THRESHOLD; |
| 4562 |
|
| 4563 |
if (!obss_pd_arg.srp_support) |
| 4564 |
obss_pd_arg.non_srg_th -= ATH12K_DEFAULT_NOISE_FLOOR; |
| 4565 |
|
| 4566 |
obss_pd_arg.non_srg_enabled = true; |
| 4567 |
} |
| 4568 |
|
| 4569 |
if (he_obss_pd->sr_ctrl & IEEE80211_HE_SPR_SRG_INFORMATION_PRESENT) { |
| 4570 |
obss_pd_arg.srg_th = ATH12K_OBSS_PD_MAX_THRESHOLD + |
| 4571 |
he_obss_pd->max_offset; |
| 4572 |
obss_pd_arg.srg_enabled = true; |
| 4573 |
} |
| 4574 |
|
| 4575 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 4576 |
"pdev %u OBSS PD sr_ctrl 0x%x srg_th %d dBm non_srg_th %d dBm\n", |
| 4577 |
pdev_id, he_obss_pd->sr_ctrl, |
| 4578 |
obss_pd_arg.srg_th, obss_pd_arg.non_srg_th); |
| 4579 |
|
| 4580 |
param_val = ath12k_wmi_build_obss_pd(&obss_pd_arg); |
| 4581 |
ret = ath12k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id); |
| 4582 |
if (ret) { |
| 4583 |
ath12k_warn(ar->ab, |
| 4584 |
"failed to set OBSS PD threshold for pdev %u: %d\n", |
| 4585 |
pdev_id, ret); |
| 4586 |
return ret; |
| 4587 |
} |
| 4588 |
|
| 4589 |
/* Enable OBSS PD for all access category */ |
| 4590 |
param_id = WMI_PDEV_PARAM_SET_CMD_OBSS_PD_PER_AC; |
| 4591 |
param_val = 0xf; |
| 4592 |
ret = ath12k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id); |
| 4593 |
if (ret) { |
| 4594 |
ath12k_warn(ar->ab, |
| 4595 |
"failed to set OBSS PD per ac for pdev %u: %d\n", |
| 4596 |
pdev_id, ret); |
| 4597 |
return ret; |
| 4598 |
} |
| 4599 |
|
| 4600 |
/* Set SR prohibit */ |
| 4601 |
param_id = WMI_PDEV_PARAM_ENABLE_SR_PROHIBIT; |
| 4602 |
param_val = !!(he_obss_pd->sr_ctrl & |
| 4603 |
IEEE80211_HE_SPR_HESIGA_SR_VAL15_ALLOWED); |
| 4604 |
ret = ath12k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id); |
| 4605 |
if (ret) { |
| 4606 |
ath12k_warn(ar->ab, "failed to set SR prohibit for pdev %u: %d\n", |
| 4607 |
pdev_id, ret); |
| 4608 |
return ret; |
| 4609 |
} |
| 4610 |
|
| 4611 |
if (!obss_pd_arg.srp_support) |
| 4612 |
return 0; |
| 4613 |
|
| 4614 |
memcpy(srg_bitmap, he_obss_pd->bss_color_bitmap, sizeof(srg_bitmap)); |
| 4615 |
/* Set SRG BSS color bitmap */ |
| 4616 |
ret = ath12k_wmi_pdev_set_srg_bss_color_bitmap(ar, pdev_id, srg_bitmap); |
| 4617 |
if (ret) { |
| 4618 |
ath12k_warn(ar->ab, |
| 4619 |
"failed to set SRG bss color bitmap for pdev %u: %d\n", |
| 4620 |
pdev_id, ret); |
| 4621 |
return ret; |
| 4622 |
} |
| 4623 |
|
| 4624 |
/* Enable BSS colors for SRG */ |
| 4625 |
ret = ath12k_wmi_pdev_srg_obss_color_enable_bitmap(ar, pdev_id, srg_bitmap); |
| 4626 |
if (ret) { |
| 4627 |
ath12k_warn(ar->ab, |
| 4628 |
"failed to enable SRG bss color bitmap pdev %u: %d\n", |
| 4629 |
pdev_id, ret); |
| 4630 |
return ret; |
| 4631 |
} |
| 4632 |
|
| 4633 |
memcpy(srg_bitmap, he_obss_pd->partial_bssid_bitmap, sizeof(srg_bitmap)); |
| 4634 |
/* Set SRG partial bssid bitmap */ |
| 4635 |
ret = ath12k_wmi_pdev_set_srg_partial_bssid_bitmap(ar, pdev_id, srg_bitmap); |
| 4636 |
if (ret) { |
| 4637 |
ath12k_warn(ar->ab, |
| 4638 |
"failed to set SRG partial bssid bitmap for pdev %u: %d\n", |
| 4639 |
pdev_id, ret); |
| 4640 |
return ret; |
| 4641 |
} |
| 4642 |
|
| 4643 |
/* Enable partial bssid mask for SRG */ |
| 4644 |
ret = ath12k_wmi_pdev_srg_obss_bssid_enable_bitmap(ar, pdev_id, srg_bitmap); |
| 4645 |
if (ret) { |
| 4646 |
ath12k_warn(ar->ab, |
| 4647 |
"failed to enable SRG bssid bitmap pdev %u: %d\n", |
| 4648 |
pdev_id, ret); |
| 4649 |
return ret; |
| 4650 |
} |
| 4651 |
|
| 4652 |
/* |
| 4653 |
* No explicit non-SRG bitmap from mac80211; enable all colors/bssids |
| 4654 |
* as non-SRG candidates. Actual SRG members are filtered by SRG bitmaps. |
| 4655 |
*/ |
| 4656 |
memset(non_srg_bitmap, 0xff, sizeof(non_srg_bitmap)); |
| 4657 |
|
| 4658 |
/* Enable BSS colors for non-SRG */ |
| 4659 |
ret = ath12k_wmi_pdev_non_srg_obss_color_enable_bitmap(ar, pdev_id, |
| 4660 |
non_srg_bitmap); |
| 4661 |
if (ret) { |
| 4662 |
ath12k_warn(ar->ab, |
| 4663 |
"failed to enable non SRG color bitmap pdev %u: %d\n", |
| 4664 |
pdev_id, ret); |
| 4665 |
return ret; |
| 4666 |
} |
| 4667 |
|
| 4668 |
/* Enable partial bssid mask for non-SRG */ |
| 4669 |
ret = ath12k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(ar, pdev_id, |
| 4670 |
non_srg_bitmap); |
| 4671 |
if (ret) { |
| 4672 |
ath12k_warn(ar->ab, |
| 4673 |
"failed to enable non SRG bssid bitmap pdev %u: %d\n", |
| 4674 |
pdev_id, ret); |
| 4675 |
return ret; |
| 4676 |
} |
| 4677 |
|
| 4678 |
return 0; |
| 4679 |
} |
| 4680 |
|
| 4681 |
static void ath12k_mac_bss_info_changed(struct ath12k *ar, |
| 4682 |
struct ath12k_link_vif *arvif, |
| 4683 |
struct ieee80211_bss_conf *info, |
| 4684 |
u64 changed) |
| 4685 |
{ |
| 4686 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 4687 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); |
| 4688 |
struct ieee80211_vif_cfg *vif_cfg = &vif->cfg; |
| 4689 |
struct ath12k_link_vif *tx_arvif; |
| 4690 |
struct cfg80211_chan_def def; |
| 4691 |
u32 param_id, param_value; |
| 4692 |
enum nl80211_band band; |
| 4693 |
u32 vdev_param; |
| 4694 |
int mcast_rate; |
| 4695 |
u32 preamble; |
| 4696 |
u16 hw_value; |
| 4697 |
u16 bitrate; |
| 4698 |
u8 rateidx; |
| 4699 |
u32 rate; |
| 4700 |
int ret; |
| 4701 |
|
| 4702 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 4703 |
|
| 4704 |
if (changed & BSS_CHANGED_BEACON_INT) { |
| 4705 |
arvif->beacon_interval = info->beacon_int; |
| 4706 |
|
| 4707 |
param_id = WMI_VDEV_PARAM_BEACON_INTERVAL; |
| 4708 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 4709 |
param_id, |
| 4710 |
arvif->beacon_interval); |
| 4711 |
if (ret) |
| 4712 |
ath12k_warn(ar->ab, "Failed to set beacon interval for VDEV: %d\n", |
| 4713 |
arvif->vdev_id); |
| 4714 |
else |
| 4715 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 4716 |
"Beacon interval: %d set for VDEV: %d\n", |
| 4717 |
arvif->beacon_interval, arvif->vdev_id); |
| 4718 |
} |
| 4719 |
|
| 4720 |
if (changed & BSS_CHANGED_BEACON) { |
| 4721 |
param_id = WMI_PDEV_PARAM_BEACON_TX_MODE; |
| 4722 |
param_value = WMI_BEACON_BURST_MODE; |
| 4723 |
ret = ath12k_wmi_pdev_set_param(ar, param_id, |
| 4724 |
param_value, ar->pdev->pdev_id); |
| 4725 |
if (ret) |
| 4726 |
ath12k_warn(ar->ab, "Failed to set beacon mode for VDEV: %d\n", |
| 4727 |
arvif->vdev_id); |
| 4728 |
else |
| 4729 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 4730 |
"Set burst beacon mode for VDEV: %d\n", |
| 4731 |
arvif->vdev_id); |
| 4732 |
|
| 4733 |
/* In MBSSID case, need to install transmitting VIF's template first */ |
| 4734 |
|
| 4735 |
ret = ath12k_mac_setup_bcn_tmpl(arvif); |
| 4736 |
if (ret) |
| 4737 |
ath12k_warn(ar->ab, "failed to update bcn template: %d\n", |
| 4738 |
ret); |
| 4739 |
|
| 4740 |
if (!arvif->is_csa_in_progress) |
| 4741 |
goto skip_vdev_up; |
| 4742 |
|
| 4743 |
tx_arvif = ath12k_mac_get_tx_arvif(arvif, info); |
| 4744 |
if (tx_arvif && arvif != tx_arvif && tx_arvif->is_csa_in_progress) |
| 4745 |
/* skip non tx vif's */ |
| 4746 |
goto skip_vdev_up; |
| 4747 |
|
| 4748 |
ath12k_wmi_vdev_params_up(ar, arvif, tx_arvif, info, ahvif->aid); |
| 4749 |
|
| 4750 |
arvif->is_csa_in_progress = false; |
| 4751 |
|
| 4752 |
if (tx_arvif && arvif == tx_arvif) { |
| 4753 |
struct ath12k_link_vif *arvif_itr; |
| 4754 |
|
| 4755 |
list_for_each_entry(arvif_itr, &ar->arvifs, list) { |
| 4756 |
if (!arvif_itr->is_csa_in_progress) |
| 4757 |
continue; |
| 4758 |
|
| 4759 |
ath12k_wmi_vdev_params_up(ar, arvif, tx_arvif, |
| 4760 |
info, ahvif->aid); |
| 4761 |
arvif_itr->is_csa_in_progress = false; |
| 4762 |
} |
| 4763 |
} |
| 4764 |
} |
| 4765 |
|
| 4766 |
skip_vdev_up: |
| 4767 |
|
| 4768 |
if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) { |
| 4769 |
arvif->dtim_period = info->dtim_period; |
| 4770 |
|
| 4771 |
param_id = WMI_VDEV_PARAM_DTIM_PERIOD; |
| 4772 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 4773 |
param_id, |
| 4774 |
arvif->dtim_period); |
| 4775 |
|
| 4776 |
if (ret) |
| 4777 |
ath12k_warn(ar->ab, "Failed to set dtim period for VDEV %d: %i\n", |
| 4778 |
arvif->vdev_id, ret); |
| 4779 |
else |
| 4780 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 4781 |
"DTIM period: %d set for VDEV: %d\n", |
| 4782 |
arvif->dtim_period, arvif->vdev_id); |
| 4783 |
} |
| 4784 |
|
| 4785 |
if (changed & BSS_CHANGED_SSID && |
| 4786 |
vif->type == NL80211_IFTYPE_AP) { |
| 4787 |
ahvif->u.ap.ssid_len = vif->cfg.ssid_len; |
| 4788 |
if (vif->cfg.ssid_len) |
| 4789 |
memcpy(ahvif->u.ap.ssid, vif->cfg.ssid, vif->cfg.ssid_len); |
| 4790 |
ahvif->u.ap.hidden_ssid = info->hidden_ssid; |
| 4791 |
} |
| 4792 |
|
| 4793 |
if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) |
| 4794 |
ether_addr_copy(arvif->bssid, info->bssid); |
| 4795 |
|
| 4796 |
if (changed & BSS_CHANGED_BEACON_ENABLED) { |
| 4797 |
if (info->enable_beacon) { |
| 4798 |
ret = ath12k_mac_set_he_txbf_conf(arvif); |
| 4799 |
if (ret) |
| 4800 |
ath12k_warn(ar->ab, |
| 4801 |
"failed to set HE TXBF config for vdev: %d\n", |
| 4802 |
arvif->vdev_id); |
| 4803 |
|
| 4804 |
ret = ath12k_mac_set_eht_txbf_conf(arvif); |
| 4805 |
if (ret) |
| 4806 |
ath12k_warn(ar->ab, |
| 4807 |
"failed to set EHT TXBF config for vdev: %d\n", |
| 4808 |
arvif->vdev_id); |
| 4809 |
} |
| 4810 |
ath12k_control_beaconing(arvif, info); |
| 4811 |
|
| 4812 |
if (arvif->is_up && info->he_support && |
| 4813 |
info->he_oper.params) { |
| 4814 |
/* TODO: Extend to support 1024 BA Bitmap size */ |
| 4815 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 4816 |
WMI_VDEV_PARAM_BA_MODE, |
| 4817 |
WMI_BA_MODE_BUFFER_SIZE_256); |
| 4818 |
if (ret) |
| 4819 |
ath12k_warn(ar->ab, |
| 4820 |
"failed to set BA BUFFER SIZE 256 for vdev: %d\n", |
| 4821 |
arvif->vdev_id); |
| 4822 |
|
| 4823 |
param_id = WMI_VDEV_PARAM_HEOPS_0_31; |
| 4824 |
param_value = info->he_oper.params; |
| 4825 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 4826 |
param_id, param_value); |
| 4827 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 4828 |
"he oper param: %x set for VDEV: %d\n", |
| 4829 |
param_value, arvif->vdev_id); |
| 4830 |
|
| 4831 |
if (ret) |
| 4832 |
ath12k_warn(ar->ab, "Failed to set he oper params %x for VDEV %d: %i\n", |
| 4833 |
param_value, arvif->vdev_id, ret); |
| 4834 |
} |
| 4835 |
} |
| 4836 |
|
| 4837 |
if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 4838 |
u32 cts_prot; |
| 4839 |
|
| 4840 |
cts_prot = !!(info->use_cts_prot); |
| 4841 |
param_id = WMI_VDEV_PARAM_PROTECTION_MODE; |
| 4842 |
|
| 4843 |
if (arvif->is_started) { |
| 4844 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 4845 |
param_id, cts_prot); |
| 4846 |
if (ret) |
| 4847 |
ath12k_warn(ar->ab, "Failed to set CTS prot for VDEV: %d\n", |
| 4848 |
arvif->vdev_id); |
| 4849 |
else |
| 4850 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "Set CTS prot: %d for VDEV: %d\n", |
| 4851 |
cts_prot, arvif->vdev_id); |
| 4852 |
} else { |
| 4853 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "defer protection mode setup, vdev is not ready yet\n"); |
| 4854 |
} |
| 4855 |
} |
| 4856 |
|
| 4857 |
if (changed & BSS_CHANGED_ERP_SLOT) { |
| 4858 |
u32 slottime; |
| 4859 |
|
| 4860 |
if (info->use_short_slot) |
| 4861 |
slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ |
| 4862 |
|
| 4863 |
else |
| 4864 |
slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ |
| 4865 |
|
| 4866 |
param_id = WMI_VDEV_PARAM_SLOT_TIME; |
| 4867 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 4868 |
param_id, slottime); |
| 4869 |
if (ret) |
| 4870 |
ath12k_warn(ar->ab, "Failed to set erp slot for VDEV: %d\n", |
| 4871 |
arvif->vdev_id); |
| 4872 |
else |
| 4873 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 4874 |
"Set slottime: %d for VDEV: %d\n", |
| 4875 |
slottime, arvif->vdev_id); |
| 4876 |
} |
| 4877 |
|
| 4878 |
if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 4879 |
u32 preamble; |
| 4880 |
|
| 4881 |
if (info->use_short_preamble) |
| 4882 |
preamble = WMI_VDEV_PREAMBLE_SHORT; |
| 4883 |
else |
| 4884 |
preamble = WMI_VDEV_PREAMBLE_LONG; |
| 4885 |
|
| 4886 |
param_id = WMI_VDEV_PARAM_PREAMBLE; |
| 4887 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 4888 |
param_id, preamble); |
| 4889 |
if (ret) |
| 4890 |
ath12k_warn(ar->ab, "Failed to set preamble for VDEV: %d\n", |
| 4891 |
arvif->vdev_id); |
| 4892 |
else |
| 4893 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 4894 |
"Set preamble: %d for VDEV: %d\n", |
| 4895 |
preamble, arvif->vdev_id); |
| 4896 |
} |
| 4897 |
|
| 4898 |
if (changed & BSS_CHANGED_ASSOC) { |
| 4899 |
if (vif->cfg.assoc) |
| 4900 |
ath12k_bss_assoc(ar, arvif, info); |
| 4901 |
else |
| 4902 |
ath12k_bss_disassoc(ar, arvif); |
| 4903 |
} |
| 4904 |
|
| 4905 |
if (changed & BSS_CHANGED_TXPOWER) { |
| 4906 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev_id %i txpower %d\n", |
| 4907 |
arvif->vdev_id, info->txpower); |
| 4908 |
|
| 4909 |
arvif->txpower = info->txpower; |
| 4910 |
ath12k_mac_txpower_recalc(ar); |
| 4911 |
} |
| 4912 |
|
| 4913 |
if (changed & BSS_CHANGED_MCAST_RATE && |
| 4914 |
!ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)) { |
| 4915 |
band = def.chan->band; |
| 4916 |
mcast_rate = info->mcast_rate[band]; |
| 4917 |
|
| 4918 |
if (mcast_rate > 0) { |
| 4919 |
rateidx = mcast_rate - 1; |
| 4920 |
} else { |
| 4921 |
if (info->basic_rates) |
| 4922 |
rateidx = __ffs(info->basic_rates); |
| 4923 |
else |
| 4924 |
rateidx = 0; |
| 4925 |
} |
| 4926 |
|
| 4927 |
if (ar->pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP) |
| 4928 |
rateidx += ATH12K_MAC_FIRST_OFDM_RATE_IDX; |
| 4929 |
|
| 4930 |
bitrate = ath12k_legacy_rates[rateidx].bitrate; |
| 4931 |
hw_value = ath12k_legacy_rates[rateidx].hw_value; |
| 4932 |
|
| 4933 |
if (ath12k_mac_bitrate_is_cck(bitrate)) |
| 4934 |
preamble = WMI_RATE_PREAMBLE_CCK; |
| 4935 |
else |
| 4936 |
preamble = WMI_RATE_PREAMBLE_OFDM; |
| 4937 |
|
| 4938 |
rate = ATH12K_HW_RATE_CODE(hw_value, 0, preamble); |
| 4939 |
|
| 4940 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 4941 |
"mac vdev %d mcast_rate %x\n", |
| 4942 |
arvif->vdev_id, rate); |
| 4943 |
|
| 4944 |
vdev_param = WMI_VDEV_PARAM_MCAST_DATA_RATE; |
| 4945 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 4946 |
vdev_param, rate); |
| 4947 |
if (ret) |
| 4948 |
ath12k_warn(ar->ab, |
| 4949 |
"failed to set mcast rate on vdev %i: %d\n", |
| 4950 |
arvif->vdev_id, ret); |
| 4951 |
|
| 4952 |
vdev_param = WMI_VDEV_PARAM_BCAST_DATA_RATE; |
| 4953 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 4954 |
vdev_param, rate); |
| 4955 |
if (ret) |
| 4956 |
ath12k_warn(ar->ab, |
| 4957 |
"failed to set bcast rate on vdev %i: %d\n", |
| 4958 |
arvif->vdev_id, ret); |
| 4959 |
} |
| 4960 |
|
| 4961 |
if (changed & BSS_CHANGED_BASIC_RATES && |
| 4962 |
!ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)) |
| 4963 |
ath12k_recalculate_mgmt_rate(ar, arvif, &def); |
| 4964 |
|
| 4965 |
if (changed & BSS_CHANGED_TWT) { |
| 4966 |
if (info->twt_requester || info->twt_responder) |
| 4967 |
ath12k_wmi_send_twt_enable_cmd(ar, ar->pdev->pdev_id); |
| 4968 |
else |
| 4969 |
ath12k_wmi_send_twt_disable_cmd(ar, ar->pdev->pdev_id); |
| 4970 |
} |
| 4971 |
|
| 4972 |
if (changed & BSS_CHANGED_HE_OBSS_PD) { |
| 4973 |
if (vif->type == NL80211_IFTYPE_AP) |
| 4974 |
ath12k_mac_config_obss_pd(arvif, &info->he_obss_pd); |
| 4975 |
else |
| 4976 |
ath12k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id, |
| 4977 |
&info->he_obss_pd); |
| 4978 |
} |
| 4979 |
|
| 4980 |
if (changed & BSS_CHANGED_HE_BSS_COLOR) { |
| 4981 |
if (vif->type == NL80211_IFTYPE_AP) { |
| 4982 |
ret = ath12k_wmi_obss_color_cfg_cmd(ar, |
| 4983 |
arvif->vdev_id, |
| 4984 |
info->he_bss_color.color, |
| 4985 |
ATH12K_BSS_COLOR_AP_PERIODS, |
| 4986 |
info->he_bss_color.enabled); |
| 4987 |
if (ret) |
| 4988 |
ath12k_warn(ar->ab, "failed to set bss color collision on vdev %u: %d\n", |
| 4989 |
arvif->vdev_id, ret); |
| 4990 |
|
| 4991 |
param_id = WMI_VDEV_PARAM_BSS_COLOR; |
| 4992 |
if (info->he_bss_color.enabled) |
| 4993 |
param_value = info->he_bss_color.color << |
| 4994 |
IEEE80211_HE_OPERATION_BSS_COLOR_OFFSET; |
| 4995 |
else |
| 4996 |
param_value = IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED; |
| 4997 |
|
| 4998 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 4999 |
param_id, |
| 5000 |
param_value); |
| 5001 |
if (ret) |
| 5002 |
ath12k_warn(ar->ab, "failed to set bss color param on vdev %u: %d\n", |
| 5003 |
arvif->vdev_id, ret); |
| 5004 |
else |
| 5005 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "bss color param 0x%x set on vdev %u\n", |
| 5006 |
param_value, arvif->vdev_id); |
| 5007 |
} else if (vif->type == NL80211_IFTYPE_STATION) { |
| 5008 |
ret = ath12k_wmi_send_bss_color_change_enable_cmd(ar, |
| 5009 |
arvif->vdev_id, |
| 5010 |
1); |
| 5011 |
if (ret) |
| 5012 |
ath12k_warn(ar->ab, "failed to enable bss color change on vdev %i: %d\n", |
| 5013 |
arvif->vdev_id, ret); |
| 5014 |
ret = ath12k_wmi_obss_color_cfg_cmd(ar, |
| 5015 |
arvif->vdev_id, |
| 5016 |
0, |
| 5017 |
ATH12K_BSS_COLOR_STA_PERIODS, |
| 5018 |
1); |
| 5019 |
if (ret) |
| 5020 |
ath12k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n", |
| 5021 |
arvif->vdev_id, ret); |
| 5022 |
} |
| 5023 |
} |
| 5024 |
|
| 5025 |
ath12k_mac_fils_discovery(arvif, info); |
| 5026 |
|
| 5027 |
if (changed & BSS_CHANGED_PS && |
| 5028 |
ar->ab->hw_params->supports_sta_ps) { |
| 5029 |
ahvif->ps = vif_cfg->ps; |
| 5030 |
ath12k_mac_vif_setup_ps(arvif); |
| 5031 |
} |
| 5032 |
} |
| 5033 |
|
| 5034 |
static struct ath12k_vif_cache *ath12k_ahvif_get_link_cache(struct ath12k_vif *ahvif, |
| 5035 |
u8 link_id) |
| 5036 |
{ |
| 5037 |
if (!ahvif->cache[link_id]) { |
| 5038 |
ahvif->cache[link_id] = kzalloc_obj(*ahvif->cache[0]); |
| 5039 |
if (ahvif->cache[link_id]) |
| 5040 |
INIT_LIST_HEAD(&ahvif->cache[link_id]->key_conf.list); |
| 5041 |
} |
| 5042 |
|
| 5043 |
return ahvif->cache[link_id]; |
| 5044 |
} |
| 5045 |
|
| 5046 |
static void ath12k_ahvif_put_link_key_cache(struct ath12k_vif_cache *cache) |
| 5047 |
{ |
| 5048 |
struct ath12k_key_conf *key_conf, *tmp; |
| 5049 |
|
| 5050 |
if (!cache || list_empty(&cache->key_conf.list)) |
| 5051 |
return; |
| 5052 |
list_for_each_entry_safe(key_conf, tmp, &cache->key_conf.list, list) { |
| 5053 |
list_del(&key_conf->list); |
| 5054 |
kfree(key_conf); |
| 5055 |
} |
| 5056 |
} |
| 5057 |
|
| 5058 |
static void ath12k_ahvif_put_link_cache(struct ath12k_vif *ahvif, u8 link_id) |
| 5059 |
{ |
| 5060 |
if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) |
| 5061 |
return; |
| 5062 |
|
| 5063 |
ath12k_ahvif_put_link_key_cache(ahvif->cache[link_id]); |
| 5064 |
kfree(ahvif->cache[link_id]); |
| 5065 |
ahvif->cache[link_id] = NULL; |
| 5066 |
} |
| 5067 |
|
| 5068 |
void ath12k_mac_op_link_info_changed(struct ieee80211_hw *hw, |
| 5069 |
struct ieee80211_vif *vif, |
| 5070 |
struct ieee80211_bss_conf *info, |
| 5071 |
u64 changed) |
| 5072 |
{ |
| 5073 |
struct ath12k *ar; |
| 5074 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 5075 |
struct ath12k_vif_cache *cache; |
| 5076 |
struct ath12k_link_vif *arvif; |
| 5077 |
u8 link_id = info->link_id; |
| 5078 |
|
| 5079 |
lockdep_assert_wiphy(hw->wiphy); |
| 5080 |
|
| 5081 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 5082 |
|
| 5083 |
/* if the vdev is not created on a certain radio, |
| 5084 |
* cache the info to be updated later on vdev creation |
| 5085 |
*/ |
| 5086 |
|
| 5087 |
if (!arvif || !arvif->is_created) { |
| 5088 |
cache = ath12k_ahvif_get_link_cache(ahvif, link_id); |
| 5089 |
if (!cache) |
| 5090 |
return; |
| 5091 |
|
| 5092 |
cache->bss_conf_changed |= changed; |
| 5093 |
|
| 5094 |
return; |
| 5095 |
} |
| 5096 |
|
| 5097 |
ar = arvif->ar; |
| 5098 |
|
| 5099 |
ath12k_mac_bss_info_changed(ar, arvif, info, changed); |
| 5100 |
} |
| 5101 |
EXPORT_SYMBOL(ath12k_mac_op_link_info_changed); |
| 5102 |
|
| 5103 |
static struct ath12k* |
| 5104 |
ath12k_mac_select_scan_device(struct ieee80211_hw *hw, |
| 5105 |
struct ieee80211_vif *vif, |
| 5106 |
u32 center_freq) |
| 5107 |
{ |
| 5108 |
struct ath12k_hw *ah = hw->priv; |
| 5109 |
enum nl80211_band band; |
| 5110 |
struct ath12k *ar; |
| 5111 |
int i; |
| 5112 |
|
| 5113 |
if (ah->num_radio == 1) |
| 5114 |
return ah->radio; |
| 5115 |
|
| 5116 |
/* Currently mac80211 supports splitting scan requests into |
| 5117 |
* multiple scan requests per band. |
| 5118 |
* Loop through first channel and determine the scan radio |
| 5119 |
* TODO: There could be 5 GHz low/high channels in that case |
| 5120 |
* split the hw request and perform multiple scans |
| 5121 |
*/ |
| 5122 |
|
| 5123 |
if (center_freq < ATH12K_MIN_5GHZ_FREQ) |
| 5124 |
band = NL80211_BAND_2GHZ; |
| 5125 |
else if (center_freq < ATH12K_MIN_6GHZ_FREQ) |
| 5126 |
band = NL80211_BAND_5GHZ; |
| 5127 |
else |
| 5128 |
band = NL80211_BAND_6GHZ; |
| 5129 |
|
| 5130 |
for_each_ar(ah, ar, i) { |
| 5131 |
if (ar->mac.sbands[band].channels && |
| 5132 |
center_freq >= KHZ_TO_MHZ(ar->freq_range.start_freq) && |
| 5133 |
center_freq <= KHZ_TO_MHZ(ar->freq_range.end_freq)) |
| 5134 |
return ar; |
| 5135 |
} |
| 5136 |
|
| 5137 |
return NULL; |
| 5138 |
} |
| 5139 |
|
| 5140 |
void __ath12k_mac_scan_finish(struct ath12k *ar) |
| 5141 |
{ |
| 5142 |
struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
| 5143 |
|
| 5144 |
lockdep_assert_held(&ar->data_lock); |
| 5145 |
|
| 5146 |
switch (ar->scan.state) { |
| 5147 |
case ATH12K_SCAN_IDLE: |
| 5148 |
break; |
| 5149 |
case ATH12K_SCAN_RUNNING: |
| 5150 |
case ATH12K_SCAN_ABORTING: |
| 5151 |
if (ar->scan.is_roc && ar->scan.roc_notify) |
| 5152 |
ieee80211_remain_on_channel_expired(hw); |
| 5153 |
fallthrough; |
| 5154 |
case ATH12K_SCAN_STARTING: |
| 5155 |
cancel_delayed_work(&ar->scan.timeout); |
| 5156 |
complete_all(&ar->scan.completed); |
| 5157 |
wiphy_work_queue(ar->ah->hw->wiphy, &ar->scan.vdev_clean_wk); |
| 5158 |
break; |
| 5159 |
} |
| 5160 |
} |
| 5161 |
|
| 5162 |
void ath12k_mac_scan_finish(struct ath12k *ar) |
| 5163 |
{ |
| 5164 |
spin_lock_bh(&ar->data_lock); |
| 5165 |
__ath12k_mac_scan_finish(ar); |
| 5166 |
spin_unlock_bh(&ar->data_lock); |
| 5167 |
} |
| 5168 |
|
| 5169 |
static int ath12k_scan_stop(struct ath12k *ar) |
| 5170 |
{ |
| 5171 |
struct ath12k_wmi_scan_cancel_arg arg = { |
| 5172 |
.req_type = WLAN_SCAN_CANCEL_SINGLE, |
| 5173 |
.scan_id = ATH12K_SCAN_ID, |
| 5174 |
}; |
| 5175 |
int ret; |
| 5176 |
|
| 5177 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 5178 |
|
| 5179 |
/* TODO: Fill other STOP Params */ |
| 5180 |
arg.pdev_id = ar->pdev->pdev_id; |
| 5181 |
|
| 5182 |
ret = ath12k_wmi_send_scan_stop_cmd(ar, &arg); |
| 5183 |
if (ret) { |
| 5184 |
ath12k_warn(ar->ab, "failed to stop wmi scan: %d\n", ret); |
| 5185 |
goto out; |
| 5186 |
} |
| 5187 |
|
| 5188 |
ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ); |
| 5189 |
if (ret == 0) { |
| 5190 |
ath12k_warn(ar->ab, |
| 5191 |
"failed to receive scan abort comple: timed out\n"); |
| 5192 |
ret = -ETIMEDOUT; |
| 5193 |
} else if (ret > 0) { |
| 5194 |
ret = 0; |
| 5195 |
} |
| 5196 |
|
| 5197 |
out: |
| 5198 |
/* Scan state should be updated in scan completion worker but in |
| 5199 |
* case firmware fails to deliver the event (for whatever reason) |
| 5200 |
* it is desired to clean up scan state anyway. Firmware may have |
| 5201 |
* just dropped the scan completion event delivery due to transport |
| 5202 |
* pipe being overflown with data and/or it can recover on its own |
| 5203 |
* before next scan request is submitted. |
| 5204 |
*/ |
| 5205 |
spin_lock_bh(&ar->data_lock); |
| 5206 |
if (ret) |
| 5207 |
__ath12k_mac_scan_finish(ar); |
| 5208 |
spin_unlock_bh(&ar->data_lock); |
| 5209 |
|
| 5210 |
return ret; |
| 5211 |
} |
| 5212 |
|
| 5213 |
static void ath12k_scan_abort(struct ath12k *ar) |
| 5214 |
{ |
| 5215 |
int ret; |
| 5216 |
|
| 5217 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 5218 |
|
| 5219 |
spin_lock_bh(&ar->data_lock); |
| 5220 |
|
| 5221 |
switch (ar->scan.state) { |
| 5222 |
case ATH12K_SCAN_IDLE: |
| 5223 |
/* This can happen if timeout worker kicked in and called |
| 5224 |
* abortion while scan completion was being processed. |
| 5225 |
*/ |
| 5226 |
break; |
| 5227 |
case ATH12K_SCAN_STARTING: |
| 5228 |
case ATH12K_SCAN_ABORTING: |
| 5229 |
ath12k_warn(ar->ab, "refusing scan abortion due to invalid scan state: %d\n", |
| 5230 |
ar->scan.state); |
| 5231 |
break; |
| 5232 |
case ATH12K_SCAN_RUNNING: |
| 5233 |
ar->scan.state = ATH12K_SCAN_ABORTING; |
| 5234 |
spin_unlock_bh(&ar->data_lock); |
| 5235 |
|
| 5236 |
ret = ath12k_scan_stop(ar); |
| 5237 |
if (ret) |
| 5238 |
ath12k_warn(ar->ab, "failed to abort scan: %d\n", ret); |
| 5239 |
|
| 5240 |
spin_lock_bh(&ar->data_lock); |
| 5241 |
break; |
| 5242 |
} |
| 5243 |
|
| 5244 |
spin_unlock_bh(&ar->data_lock); |
| 5245 |
} |
| 5246 |
|
| 5247 |
static void ath12k_scan_timeout_work(struct work_struct *work) |
| 5248 |
{ |
| 5249 |
struct ath12k *ar = container_of(work, struct ath12k, |
| 5250 |
scan.timeout.work); |
| 5251 |
|
| 5252 |
wiphy_lock(ath12k_ar_to_hw(ar)->wiphy); |
| 5253 |
ath12k_scan_abort(ar); |
| 5254 |
wiphy_unlock(ath12k_ar_to_hw(ar)->wiphy); |
| 5255 |
} |
| 5256 |
|
| 5257 |
static void ath12k_mac_scan_send_complete(struct ath12k *ar, |
| 5258 |
struct cfg80211_scan_info *info) |
| 5259 |
{ |
| 5260 |
struct ath12k_hw *ah = ar->ah; |
| 5261 |
struct ath12k *partner_ar; |
| 5262 |
int i; |
| 5263 |
|
| 5264 |
lockdep_assert_wiphy(ah->hw->wiphy); |
| 5265 |
|
| 5266 |
for_each_ar(ah, partner_ar, i) |
| 5267 |
if (partner_ar != ar && |
| 5268 |
partner_ar->scan.state == ATH12K_SCAN_RUNNING) |
| 5269 |
return; |
| 5270 |
|
| 5271 |
ieee80211_scan_completed(ah->hw, info); |
| 5272 |
} |
| 5273 |
|
| 5274 |
static void ath12k_scan_vdev_clean_work(struct wiphy *wiphy, struct wiphy_work *work) |
| 5275 |
{ |
| 5276 |
struct ath12k *ar = container_of(work, struct ath12k, |
| 5277 |
scan.vdev_clean_wk); |
| 5278 |
struct ath12k_hw *ah = ar->ah; |
| 5279 |
struct ath12k_link_vif *arvif; |
| 5280 |
|
| 5281 |
lockdep_assert_wiphy(wiphy); |
| 5282 |
|
| 5283 |
arvif = ar->scan.arvif; |
| 5284 |
|
| 5285 |
/* The scan vdev has already been deleted. This can occur when a |
| 5286 |
* new scan request is made on the same vif with a different |
| 5287 |
* frequency, causing the scan arvif to move from one radio to |
| 5288 |
* another. Or, scan was abrupted and via remove interface, the |
| 5289 |
* arvif is already deleted. Alternatively, if the scan vdev is not |
| 5290 |
* being used as an actual vdev, then do not delete it. |
| 5291 |
*/ |
| 5292 |
if (!arvif || arvif->is_started) |
| 5293 |
goto work_complete; |
| 5294 |
|
| 5295 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac clean scan vdev (link id %u)", |
| 5296 |
arvif->link_id); |
| 5297 |
|
| 5298 |
ath12k_mac_remove_link_interface(ah->hw, arvif); |
| 5299 |
ath12k_mac_unassign_link_vif(arvif); |
| 5300 |
|
| 5301 |
work_complete: |
| 5302 |
spin_lock_bh(&ar->data_lock); |
| 5303 |
ar->scan.arvif = NULL; |
| 5304 |
if (!ar->scan.is_roc) { |
| 5305 |
struct cfg80211_scan_info info = { |
| 5306 |
.aborted = ((ar->scan.state == |
| 5307 |
ATH12K_SCAN_ABORTING) || |
| 5308 |
(ar->scan.state == |
| 5309 |
ATH12K_SCAN_STARTING)), |
| 5310 |
}; |
| 5311 |
|
| 5312 |
ath12k_mac_scan_send_complete(ar, &info); |
| 5313 |
} |
| 5314 |
|
| 5315 |
ar->scan.state = ATH12K_SCAN_IDLE; |
| 5316 |
ar->scan_channel = NULL; |
| 5317 |
ar->scan.roc_freq = 0; |
| 5318 |
spin_unlock_bh(&ar->data_lock); |
| 5319 |
} |
| 5320 |
|
| 5321 |
static int ath12k_start_scan(struct ath12k *ar, |
| 5322 |
struct ath12k_wmi_scan_req_arg *arg) |
| 5323 |
{ |
| 5324 |
int ret; |
| 5325 |
|
| 5326 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 5327 |
|
| 5328 |
ret = ath12k_wmi_send_scan_start_cmd(ar, arg); |
| 5329 |
if (ret) |
| 5330 |
return ret; |
| 5331 |
|
| 5332 |
ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ); |
| 5333 |
if (ret == 0) { |
| 5334 |
ret = ath12k_scan_stop(ar); |
| 5335 |
if (ret) |
| 5336 |
ath12k_warn(ar->ab, "failed to stop scan: %d\n", ret); |
| 5337 |
|
| 5338 |
return -ETIMEDOUT; |
| 5339 |
} |
| 5340 |
|
| 5341 |
/* If we failed to start the scan, return error code at |
| 5342 |
* this point. This is probably due to some issue in the |
| 5343 |
* firmware, but no need to wedge the driver due to that... |
| 5344 |
*/ |
| 5345 |
spin_lock_bh(&ar->data_lock); |
| 5346 |
if (ar->scan.state == ATH12K_SCAN_IDLE) { |
| 5347 |
spin_unlock_bh(&ar->data_lock); |
| 5348 |
return -EINVAL; |
| 5349 |
} |
| 5350 |
spin_unlock_bh(&ar->data_lock); |
| 5351 |
|
| 5352 |
return 0; |
| 5353 |
} |
| 5354 |
|
| 5355 |
int ath12k_mac_get_fw_stats(struct ath12k *ar, |
| 5356 |
struct ath12k_fw_stats_req_params *param) |
| 5357 |
{ |
| 5358 |
struct ath12k_base *ab = ar->ab; |
| 5359 |
struct ath12k_hw *ah = ath12k_ar_to_ah(ar); |
| 5360 |
unsigned long time_left; |
| 5361 |
int ret; |
| 5362 |
|
| 5363 |
guard(mutex)(&ah->hw_mutex); |
| 5364 |
|
| 5365 |
if (ah->state != ATH12K_HW_STATE_ON) |
| 5366 |
return -ENETDOWN; |
| 5367 |
|
| 5368 |
reinit_completion(&ar->fw_stats_complete); |
| 5369 |
reinit_completion(&ar->fw_stats_done); |
| 5370 |
|
| 5371 |
ret = ath12k_wmi_send_stats_request_cmd(ar, param->stats_id, |
| 5372 |
param->vdev_id, param->pdev_id); |
| 5373 |
if (ret) { |
| 5374 |
ath12k_warn(ab, "failed to request fw stats: %d\n", ret); |
| 5375 |
return ret; |
| 5376 |
} |
| 5377 |
|
| 5378 |
ath12k_dbg(ab, ATH12K_DBG_WMI, |
| 5379 |
"get fw stat pdev id %d vdev id %d stats id 0x%x\n", |
| 5380 |
param->pdev_id, param->vdev_id, param->stats_id); |
| 5381 |
|
| 5382 |
time_left = wait_for_completion_timeout(&ar->fw_stats_complete, 1 * HZ); |
| 5383 |
if (!time_left) { |
| 5384 |
ath12k_warn(ab, "time out while waiting for get fw stats\n"); |
| 5385 |
return -ETIMEDOUT; |
| 5386 |
} |
| 5387 |
|
| 5388 |
/* Firmware sends WMI_UPDATE_STATS_EVENTID back-to-back |
| 5389 |
* when stats data buffer limit is reached. fw_stats_complete |
| 5390 |
* is completed once host receives first event from firmware, but |
| 5391 |
* still there could be more events following. Below is to wait |
| 5392 |
* until firmware completes sending all the events. |
| 5393 |
*/ |
| 5394 |
time_left = wait_for_completion_timeout(&ar->fw_stats_done, 3 * HZ); |
| 5395 |
if (!time_left) { |
| 5396 |
ath12k_warn(ab, "time out while waiting for fw stats done\n"); |
| 5397 |
return -ETIMEDOUT; |
| 5398 |
} |
| 5399 |
|
| 5400 |
return 0; |
| 5401 |
} |
| 5402 |
|
| 5403 |
int ath12k_mac_op_get_txpower(struct ieee80211_hw *hw, |
| 5404 |
struct ieee80211_vif *vif, |
| 5405 |
unsigned int link_id, |
| 5406 |
int *dbm) |
| 5407 |
{ |
| 5408 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 5409 |
struct ath12k_fw_stats_req_params params = {}; |
| 5410 |
struct ath12k_fw_stats_pdev *pdev; |
| 5411 |
struct ath12k_hw *ah = hw->priv; |
| 5412 |
struct ath12k_link_vif *arvif; |
| 5413 |
struct ath12k_base *ab; |
| 5414 |
struct ath12k *ar; |
| 5415 |
int ret; |
| 5416 |
|
| 5417 |
/* Final Tx power is minimum of Target Power, CTL power, Regulatory |
| 5418 |
* Power, PSD EIRP Power. We just know the Regulatory power from the |
| 5419 |
* regulatory rules obtained. FW knows all these power and sets the min |
| 5420 |
* of these. Hence, we request the FW pdev stats in which FW reports |
| 5421 |
* the minimum of all vdev's channel Tx power. |
| 5422 |
*/ |
| 5423 |
lockdep_assert_wiphy(hw->wiphy); |
| 5424 |
|
| 5425 |
arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); |
| 5426 |
if (!arvif || !arvif->ar) |
| 5427 |
return -EINVAL; |
| 5428 |
|
| 5429 |
ar = arvif->ar; |
| 5430 |
ab = ar->ab; |
| 5431 |
if (ah->state != ATH12K_HW_STATE_ON) |
| 5432 |
goto err_fallback; |
| 5433 |
|
| 5434 |
if (test_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags)) |
| 5435 |
return -EAGAIN; |
| 5436 |
|
| 5437 |
/* Limit the requests to Firmware for fetching the tx power */ |
| 5438 |
if (ar->chan_tx_pwr != ATH12K_PDEV_TX_POWER_INVALID && |
| 5439 |
time_before(jiffies, |
| 5440 |
msecs_to_jiffies(ATH12K_PDEV_TX_POWER_REFRESH_TIME_MSECS) + |
| 5441 |
ar->last_tx_power_update)) |
| 5442 |
goto send_tx_power; |
| 5443 |
|
| 5444 |
params.pdev_id = ath12k_mac_get_target_pdev_id(ar); |
| 5445 |
params.vdev_id = arvif->vdev_id; |
| 5446 |
params.stats_id = WMI_REQUEST_PDEV_STAT; |
| 5447 |
ret = ath12k_mac_get_fw_stats(ar, ¶ms); |
| 5448 |
if (ret) { |
| 5449 |
ath12k_warn(ab, "failed to request fw pdev stats: %d\n", ret); |
| 5450 |
goto err_fallback; |
| 5451 |
} |
| 5452 |
|
| 5453 |
spin_lock_bh(&ar->data_lock); |
| 5454 |
pdev = list_first_entry_or_null(&ar->fw_stats.pdevs, |
| 5455 |
struct ath12k_fw_stats_pdev, list); |
| 5456 |
if (!pdev) { |
| 5457 |
spin_unlock_bh(&ar->data_lock); |
| 5458 |
goto err_fallback; |
| 5459 |
} |
| 5460 |
|
| 5461 |
/* tx power reported by firmware is in units of 0.5 dBm */ |
| 5462 |
ar->chan_tx_pwr = pdev->chan_tx_power / 2; |
| 5463 |
spin_unlock_bh(&ar->data_lock); |
| 5464 |
ar->last_tx_power_update = jiffies; |
| 5465 |
ath12k_fw_stats_reset(ar); |
| 5466 |
|
| 5467 |
send_tx_power: |
| 5468 |
*dbm = ar->chan_tx_pwr; |
| 5469 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower fetched from firmware %d dBm\n", |
| 5470 |
*dbm); |
| 5471 |
return 0; |
| 5472 |
|
| 5473 |
err_fallback: |
| 5474 |
/* We didn't get txpower from FW. Hence, relying on vif->bss_conf.txpower */ |
| 5475 |
*dbm = vif->bss_conf.txpower; |
| 5476 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower from firmware NaN, reported %d dBm\n", |
| 5477 |
*dbm); |
| 5478 |
return 0; |
| 5479 |
} |
| 5480 |
EXPORT_SYMBOL(ath12k_mac_op_get_txpower); |
| 5481 |
|
| 5482 |
static u8 |
| 5483 |
ath12k_mac_find_link_id_by_ar(struct ath12k_vif *ahvif, struct ath12k *ar) |
| 5484 |
{ |
| 5485 |
struct ath12k_link_vif *arvif; |
| 5486 |
struct ath12k_hw *ah = ahvif->ah; |
| 5487 |
unsigned long links = ahvif->links_map; |
| 5488 |
unsigned long scan_links_map; |
| 5489 |
u8 link_id; |
| 5490 |
|
| 5491 |
lockdep_assert_wiphy(ah->hw->wiphy); |
| 5492 |
|
| 5493 |
for_each_set_bit(link_id, &links, ATH12K_NUM_MAX_LINKS) { |
| 5494 |
arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); |
| 5495 |
|
| 5496 |
if (!arvif || !arvif->is_created) |
| 5497 |
continue; |
| 5498 |
|
| 5499 |
if (ar == arvif->ar) |
| 5500 |
return link_id; |
| 5501 |
} |
| 5502 |
|
| 5503 |
/* input ar is not assigned to any of the links of ML VIF, use next |
| 5504 |
* available scan link for scan vdev creation. There are cases where |
| 5505 |
* single scan req needs to be split in driver and initiate separate |
| 5506 |
* scan requests to firmware based on device. |
| 5507 |
*/ |
| 5508 |
|
| 5509 |
/* Unset all non-scan links (0-14) of scan_links_map so that ffs() will |
| 5510 |
* choose an available link among scan links (i.e link id >= 15) |
| 5511 |
*/ |
| 5512 |
scan_links_map = ~ahvif->links_map & ATH12K_SCAN_LINKS_MASK; |
| 5513 |
if (scan_links_map) |
| 5514 |
return __ffs(scan_links_map); |
| 5515 |
|
| 5516 |
return ATH12K_FIRST_SCAN_LINK; |
| 5517 |
} |
| 5518 |
|
| 5519 |
static int ath12k_mac_initiate_hw_scan(struct ieee80211_hw *hw, |
| 5520 |
struct ieee80211_vif *vif, |
| 5521 |
struct ieee80211_scan_request *hw_req, |
| 5522 |
int n_channels, |
| 5523 |
struct ieee80211_channel **chan_list, |
| 5524 |
struct ath12k *ar) |
| 5525 |
{ |
| 5526 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 5527 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 5528 |
struct ath12k_link_vif *arvif; |
| 5529 |
struct cfg80211_scan_request *req = &hw_req->req; |
| 5530 |
struct ath12k_wmi_scan_req_arg *arg = NULL; |
| 5531 |
u8 link_id; |
| 5532 |
int ret; |
| 5533 |
int i; |
| 5534 |
bool create = true; |
| 5535 |
|
| 5536 |
lockdep_assert_wiphy(hw->wiphy); |
| 5537 |
|
| 5538 |
arvif = &ahvif->deflink; |
| 5539 |
|
| 5540 |
/* check if any of the links of ML VIF is already started on |
| 5541 |
* radio(ar) corresponding to given scan frequency and use it, |
| 5542 |
* if not use scan link (link id >= 15) for scan purpose. |
| 5543 |
*/ |
| 5544 |
link_id = ath12k_mac_find_link_id_by_ar(ahvif, ar); |
| 5545 |
/* All scan links are occupied. ideally this shouldn't happen as |
| 5546 |
* mac80211 won't schedule scan for same band until ongoing scan is |
| 5547 |
* completed, don't try to exceed max links just in case if it happens. |
| 5548 |
*/ |
| 5549 |
if (link_id >= ATH12K_NUM_MAX_LINKS) |
| 5550 |
return -EBUSY; |
| 5551 |
|
| 5552 |
arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); |
| 5553 |
|
| 5554 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac link ID %d selected for scan", |
| 5555 |
arvif->link_id); |
| 5556 |
|
| 5557 |
/* If the vif is already assigned to a specific vdev of an ar, |
| 5558 |
* check whether its already started, vdev which is started |
| 5559 |
* are not allowed to switch to a new radio. |
| 5560 |
* If the vdev is not started, but was earlier created on a |
| 5561 |
* different ar, delete that vdev and create a new one. We don't |
| 5562 |
* delete at the scan stop as an optimization to avoid redundant |
| 5563 |
* delete-create vdev's for the same ar, in case the request is |
| 5564 |
* always on the same band for the vif |
| 5565 |
*/ |
| 5566 |
if (arvif->is_created) { |
| 5567 |
if (WARN_ON(!arvif->ar)) |
| 5568 |
return -EINVAL; |
| 5569 |
|
| 5570 |
if (ar != arvif->ar && arvif->is_started) |
| 5571 |
return -EINVAL; |
| 5572 |
|
| 5573 |
if (ar != arvif->ar) { |
| 5574 |
ath12k_mac_remove_link_interface(hw, arvif); |
| 5575 |
ath12k_mac_unassign_link_vif(arvif); |
| 5576 |
} else { |
| 5577 |
create = false; |
| 5578 |
} |
| 5579 |
} |
| 5580 |
|
| 5581 |
if (create) { |
| 5582 |
/* Previous arvif would've been cleared in radio switch block |
| 5583 |
* above, assign arvif again for create. |
| 5584 |
*/ |
| 5585 |
arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); |
| 5586 |
|
| 5587 |
ret = ath12k_mac_vdev_create(ar, arvif); |
| 5588 |
if (ret) { |
| 5589 |
ath12k_warn(ar->ab, "unable to create scan vdev %d\n", ret); |
| 5590 |
ath12k_mac_unassign_link_vif(arvif); |
| 5591 |
return ret; |
| 5592 |
} |
| 5593 |
} |
| 5594 |
|
| 5595 |
spin_lock_bh(&ar->data_lock); |
| 5596 |
switch (ar->scan.state) { |
| 5597 |
case ATH12K_SCAN_IDLE: |
| 5598 |
reinit_completion(&ar->scan.started); |
| 5599 |
reinit_completion(&ar->scan.completed); |
| 5600 |
ar->scan.state = ATH12K_SCAN_STARTING; |
| 5601 |
ar->scan.is_roc = false; |
| 5602 |
ar->scan.arvif = arvif; |
| 5603 |
ret = 0; |
| 5604 |
break; |
| 5605 |
case ATH12K_SCAN_STARTING: |
| 5606 |
case ATH12K_SCAN_RUNNING: |
| 5607 |
case ATH12K_SCAN_ABORTING: |
| 5608 |
ret = -EBUSY; |
| 5609 |
break; |
| 5610 |
} |
| 5611 |
spin_unlock_bh(&ar->data_lock); |
| 5612 |
|
| 5613 |
if (ret) |
| 5614 |
goto exit; |
| 5615 |
|
| 5616 |
arg = kzalloc_obj(*arg); |
| 5617 |
if (!arg) { |
| 5618 |
ret = -ENOMEM; |
| 5619 |
goto exit; |
| 5620 |
} |
| 5621 |
|
| 5622 |
ath12k_wmi_start_scan_init(ar, arg); |
| 5623 |
arg->vdev_id = arvif->vdev_id; |
| 5624 |
arg->scan_id = ATH12K_SCAN_ID; |
| 5625 |
|
| 5626 |
if (req->ie_len) { |
| 5627 |
arg->extraie.ptr = kmemdup(req->ie, req->ie_len, GFP_KERNEL); |
| 5628 |
if (!arg->extraie.ptr) { |
| 5629 |
ret = -ENOMEM; |
| 5630 |
goto exit; |
| 5631 |
} |
| 5632 |
arg->extraie.len = req->ie_len; |
| 5633 |
} |
| 5634 |
|
| 5635 |
if (req->n_ssids) { |
| 5636 |
arg->num_ssids = req->n_ssids; |
| 5637 |
for (i = 0; i < arg->num_ssids; i++) |
| 5638 |
arg->ssid[i] = req->ssids[i]; |
| 5639 |
} else { |
| 5640 |
arg->scan_f_passive = 1; |
| 5641 |
} |
| 5642 |
|
| 5643 |
if (n_channels) { |
| 5644 |
arg->num_chan = n_channels; |
| 5645 |
arg->chan_list = kcalloc(arg->num_chan, sizeof(*arg->chan_list), |
| 5646 |
GFP_KERNEL); |
| 5647 |
if (!arg->chan_list) { |
| 5648 |
ret = -ENOMEM; |
| 5649 |
goto exit; |
| 5650 |
} |
| 5651 |
|
| 5652 |
for (i = 0; i < arg->num_chan; i++) |
| 5653 |
arg->chan_list[i] = chan_list[i]->center_freq; |
| 5654 |
} |
| 5655 |
|
| 5656 |
ret = ath12k_start_scan(ar, arg); |
| 5657 |
if (ret) { |
| 5658 |
if (ret == -EBUSY) |
| 5659 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 5660 |
"scan engine is busy 11d state %d\n", ar->state_11d); |
| 5661 |
else |
| 5662 |
ath12k_warn(ar->ab, "failed to start hw scan: %d\n", ret); |
| 5663 |
|
| 5664 |
spin_lock_bh(&ar->data_lock); |
| 5665 |
ar->scan.state = ATH12K_SCAN_IDLE; |
| 5666 |
spin_unlock_bh(&ar->data_lock); |
| 5667 |
goto exit; |
| 5668 |
} |
| 5669 |
|
| 5670 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac scan started"); |
| 5671 |
|
| 5672 |
/* Add a margin to account for event/command processing */ |
| 5673 |
ieee80211_queue_delayed_work(ath12k_ar_to_hw(ar), &ar->scan.timeout, |
| 5674 |
msecs_to_jiffies(arg->max_scan_time + |
| 5675 |
ATH12K_MAC_SCAN_TIMEOUT_MSECS)); |
| 5676 |
|
| 5677 |
exit: |
| 5678 |
if (arg) { |
| 5679 |
kfree(arg->chan_list); |
| 5680 |
kfree(arg->extraie.ptr); |
| 5681 |
kfree(arg); |
| 5682 |
} |
| 5683 |
|
| 5684 |
if (ar->state_11d == ATH12K_11D_PREPARING && |
| 5685 |
ahvif->vdev_type == WMI_VDEV_TYPE_STA && |
| 5686 |
ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) |
| 5687 |
ath12k_mac_11d_scan_start(ar, arvif->vdev_id); |
| 5688 |
|
| 5689 |
return ret; |
| 5690 |
} |
| 5691 |
|
| 5692 |
int ath12k_mac_op_hw_scan(struct ieee80211_hw *hw, |
| 5693 |
struct ieee80211_vif *vif, |
| 5694 |
struct ieee80211_scan_request *hw_req) |
| 5695 |
{ |
| 5696 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 5697 |
struct ieee80211_channel **chan_list, *chan; |
| 5698 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 5699 |
unsigned long links_map, link_id; |
| 5700 |
struct ath12k_link_vif *arvif; |
| 5701 |
struct ath12k *ar, *scan_ar; |
| 5702 |
int i, j, ret = 0; |
| 5703 |
|
| 5704 |
lockdep_assert_wiphy(hw->wiphy); |
| 5705 |
|
| 5706 |
chan_list = kzalloc_objs(*chan_list, hw_req->req.n_channels); |
| 5707 |
if (!chan_list) |
| 5708 |
return -ENOMEM; |
| 5709 |
|
| 5710 |
/* There could be channels that belong to multiple underlying radio |
| 5711 |
* in same scan request as mac80211 sees it as single band. In that |
| 5712 |
* case split the hw_req based on frequency range and schedule scans to |
| 5713 |
* corresponding radio. |
| 5714 |
*/ |
| 5715 |
for_each_ar(ah, ar, i) { |
| 5716 |
int n_chans = 0; |
| 5717 |
|
| 5718 |
for (j = 0; j < hw_req->req.n_channels; j++) { |
| 5719 |
chan = hw_req->req.channels[j]; |
| 5720 |
scan_ar = ath12k_mac_select_scan_device(hw, vif, |
| 5721 |
chan->center_freq); |
| 5722 |
if (!scan_ar) { |
| 5723 |
ath12k_hw_warn(ah, "unable to select scan device for freq %d\n", |
| 5724 |
chan->center_freq); |
| 5725 |
ret = -EINVAL; |
| 5726 |
goto abort; |
| 5727 |
} |
| 5728 |
if (ar != scan_ar) |
| 5729 |
continue; |
| 5730 |
|
| 5731 |
chan_list[n_chans++] = chan; |
| 5732 |
} |
| 5733 |
if (n_chans) { |
| 5734 |
ret = ath12k_mac_initiate_hw_scan(hw, vif, hw_req, n_chans, |
| 5735 |
chan_list, ar); |
| 5736 |
if (ret) |
| 5737 |
goto abort; |
| 5738 |
} |
| 5739 |
} |
| 5740 |
abort: |
| 5741 |
/* If any of the parallel scans initiated fails, abort all and |
| 5742 |
* remove the scan interfaces created. Return complete scan |
| 5743 |
* failure as mac80211 assumes this as single scan request. |
| 5744 |
*/ |
| 5745 |
if (ret) { |
| 5746 |
ath12k_hw_warn(ah, "Scan failed %d , cleanup all scan vdevs\n", ret); |
| 5747 |
links_map = ahvif->links_map; |
| 5748 |
for_each_set_bit(link_id, &links_map, ATH12K_NUM_MAX_LINKS) { |
| 5749 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 5750 |
if (!arvif) |
| 5751 |
continue; |
| 5752 |
|
| 5753 |
ar = arvif->ar; |
| 5754 |
if (ar->scan.arvif == arvif) { |
| 5755 |
wiphy_work_cancel(hw->wiphy, &ar->scan.vdev_clean_wk); |
| 5756 |
spin_lock_bh(&ar->data_lock); |
| 5757 |
ar->scan.arvif = NULL; |
| 5758 |
ar->scan.state = ATH12K_SCAN_IDLE; |
| 5759 |
ar->scan_channel = NULL; |
| 5760 |
ar->scan.roc_freq = 0; |
| 5761 |
spin_unlock_bh(&ar->data_lock); |
| 5762 |
} |
| 5763 |
if (link_id >= ATH12K_FIRST_SCAN_LINK) { |
| 5764 |
ath12k_mac_remove_link_interface(hw, arvif); |
| 5765 |
ath12k_mac_unassign_link_vif(arvif); |
| 5766 |
} |
| 5767 |
} |
| 5768 |
} |
| 5769 |
kfree(chan_list); |
| 5770 |
return ret; |
| 5771 |
} |
| 5772 |
EXPORT_SYMBOL(ath12k_mac_op_hw_scan); |
| 5773 |
|
| 5774 |
void ath12k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw, |
| 5775 |
struct ieee80211_vif *vif) |
| 5776 |
{ |
| 5777 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 5778 |
unsigned long link_id, links_map = ahvif->links_map; |
| 5779 |
struct ath12k_link_vif *arvif; |
| 5780 |
struct ath12k *ar; |
| 5781 |
|
| 5782 |
lockdep_assert_wiphy(hw->wiphy); |
| 5783 |
|
| 5784 |
for_each_set_bit(link_id, &links_map, ATH12K_NUM_MAX_LINKS) { |
| 5785 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 5786 |
if (!arvif || !arvif->is_created || |
| 5787 |
arvif->ar->scan.arvif != arvif) |
| 5788 |
continue; |
| 5789 |
|
| 5790 |
ar = arvif->ar; |
| 5791 |
|
| 5792 |
ath12k_scan_abort(ar); |
| 5793 |
|
| 5794 |
cancel_delayed_work_sync(&ar->scan.timeout); |
| 5795 |
} |
| 5796 |
} |
| 5797 |
EXPORT_SYMBOL(ath12k_mac_op_cancel_hw_scan); |
| 5798 |
|
| 5799 |
static int ath12k_install_key(struct ath12k_link_vif *arvif, |
| 5800 |
struct ieee80211_key_conf *key, |
| 5801 |
enum set_key_cmd cmd, |
| 5802 |
const u8 *macaddr, u32 flags) |
| 5803 |
{ |
| 5804 |
int ret; |
| 5805 |
struct ath12k *ar = arvif->ar; |
| 5806 |
struct wmi_vdev_install_key_arg arg = { |
| 5807 |
.vdev_id = arvif->vdev_id, |
| 5808 |
.key_idx = key->keyidx, |
| 5809 |
.key_len = key->keylen, |
| 5810 |
.key_data = key->key, |
| 5811 |
.key_flags = flags, |
| 5812 |
.ieee80211_key_cipher = key->cipher, |
| 5813 |
.macaddr = macaddr, |
| 5814 |
}; |
| 5815 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 5816 |
|
| 5817 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 5818 |
|
| 5819 |
if (test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags)) |
| 5820 |
return 0; |
| 5821 |
|
| 5822 |
if (cmd == DISABLE_KEY) { |
| 5823 |
/* TODO: Check if FW expects value other than NONE for del */ |
| 5824 |
/* arg.key_cipher = WMI_CIPHER_NONE; */ |
| 5825 |
arg.key_len = 0; |
| 5826 |
arg.key_data = NULL; |
| 5827 |
goto check_order; |
| 5828 |
} |
| 5829 |
|
| 5830 |
switch (key->cipher) { |
| 5831 |
case WLAN_CIPHER_SUITE_CCMP: |
| 5832 |
case WLAN_CIPHER_SUITE_CCMP_256: |
| 5833 |
arg.key_cipher = WMI_CIPHER_AES_CCM; |
| 5834 |
key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; |
| 5835 |
break; |
| 5836 |
case WLAN_CIPHER_SUITE_TKIP: |
| 5837 |
arg.key_cipher = WMI_CIPHER_TKIP; |
| 5838 |
arg.key_txmic_len = 8; |
| 5839 |
arg.key_rxmic_len = 8; |
| 5840 |
break; |
| 5841 |
case WLAN_CIPHER_SUITE_GCMP: |
| 5842 |
case WLAN_CIPHER_SUITE_GCMP_256: |
| 5843 |
arg.key_cipher = WMI_CIPHER_AES_GCM; |
| 5844 |
key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; |
| 5845 |
break; |
| 5846 |
case WLAN_CIPHER_SUITE_AES_CMAC: |
| 5847 |
arg.key_cipher = WMI_CIPHER_AES_CMAC; |
| 5848 |
break; |
| 5849 |
case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 5850 |
case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 5851 |
arg.key_cipher = WMI_CIPHER_AES_GMAC; |
| 5852 |
break; |
| 5853 |
case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
| 5854 |
arg.key_cipher = WMI_CIPHER_AES_CMAC; |
| 5855 |
break; |
| 5856 |
default: |
| 5857 |
ath12k_warn(ar->ab, "cipher %d is not supported\n", key->cipher); |
| 5858 |
return -EOPNOTSUPP; |
| 5859 |
} |
| 5860 |
|
| 5861 |
if (test_bit(ATH12K_FLAG_RAW_MODE, &ar->ab->dev_flags)) |
| 5862 |
key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV | |
| 5863 |
IEEE80211_KEY_FLAG_RESERVE_TAILROOM; |
| 5864 |
|
| 5865 |
check_order: |
| 5866 |
if (ahvif->vdev_type == WMI_VDEV_TYPE_STA && |
| 5867 |
arg.key_flags == WMI_KEY_GROUP) { |
| 5868 |
if (cmd == SET_KEY) { |
| 5869 |
if (arvif->pairwise_key_done) { |
| 5870 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 5871 |
"vdev %u pairwise key done, go install group key\n", |
| 5872 |
arg.vdev_id); |
| 5873 |
goto install; |
| 5874 |
} else { |
| 5875 |
/* WCN7850 firmware requires pairwise key to be installed |
| 5876 |
* before group key. In case group key comes first, cache |
| 5877 |
* it and return. Will revisit it once pairwise key gets |
| 5878 |
* installed. |
| 5879 |
*/ |
| 5880 |
arvif->group_key = arg; |
| 5881 |
arvif->group_key_valid = true; |
| 5882 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 5883 |
"vdev %u group key before pairwise key, cache and skip\n", |
| 5884 |
arg.vdev_id); |
| 5885 |
|
| 5886 |
ret = 0; |
| 5887 |
goto out; |
| 5888 |
} |
| 5889 |
} else { |
| 5890 |
arvif->group_key_valid = false; |
| 5891 |
} |
| 5892 |
} |
| 5893 |
|
| 5894 |
install: |
| 5895 |
reinit_completion(&ar->install_key_done); |
| 5896 |
|
| 5897 |
ret = ath12k_wmi_vdev_install_key(arvif->ar, &arg); |
| 5898 |
if (ret) |
| 5899 |
return ret; |
| 5900 |
|
| 5901 |
if (!wait_for_completion_timeout(&ar->install_key_done, 1 * HZ)) |
| 5902 |
return -ETIMEDOUT; |
| 5903 |
|
| 5904 |
if (ether_addr_equal(arg.macaddr, arvif->bssid)) |
| 5905 |
ahvif->dp_vif.key_cipher = arg.ieee80211_key_cipher; |
| 5906 |
|
| 5907 |
if (ar->install_key_status) { |
| 5908 |
ret = -EINVAL; |
| 5909 |
goto out; |
| 5910 |
} |
| 5911 |
|
| 5912 |
if (ahvif->vdev_type == WMI_VDEV_TYPE_STA && |
| 5913 |
arg.key_flags == WMI_KEY_PAIRWISE) { |
| 5914 |
if (cmd == SET_KEY) { |
| 5915 |
arvif->pairwise_key_done = true; |
| 5916 |
if (arvif->group_key_valid) { |
| 5917 |
/* Install cached GTK */ |
| 5918 |
arvif->group_key_valid = false; |
| 5919 |
arg = arvif->group_key; |
| 5920 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 5921 |
"vdev %u pairwise key done, group key ready, go install\n", |
| 5922 |
arg.vdev_id); |
| 5923 |
goto install; |
| 5924 |
} |
| 5925 |
} else { |
| 5926 |
arvif->pairwise_key_done = false; |
| 5927 |
} |
| 5928 |
} |
| 5929 |
|
| 5930 |
out: |
| 5931 |
if (ret) { |
| 5932 |
/* In case of failure userspace may not do DISABLE_KEY |
| 5933 |
* but triggers re-connection directly, so manually reset |
| 5934 |
* status here. |
| 5935 |
*/ |
| 5936 |
arvif->group_key_valid = false; |
| 5937 |
arvif->pairwise_key_done = false; |
| 5938 |
} |
| 5939 |
|
| 5940 |
return ret; |
| 5941 |
} |
| 5942 |
|
| 5943 |
static int ath12k_clear_peer_keys(struct ath12k_link_vif *arvif, |
| 5944 |
const u8 *addr) |
| 5945 |
{ |
| 5946 |
struct ath12k *ar = arvif->ar; |
| 5947 |
struct ath12k_base *ab = ar->ab; |
| 5948 |
struct ath12k_dp_link_peer *peer; |
| 5949 |
int first_errno = 0; |
| 5950 |
int ret; |
| 5951 |
int i, len; |
| 5952 |
u32 flags = 0; |
| 5953 |
struct ath12k_dp *dp = ath12k_ab_to_dp(ab); |
| 5954 |
struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1] = {}; |
| 5955 |
|
| 5956 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 5957 |
|
| 5958 |
spin_lock_bh(&dp->dp_lock); |
| 5959 |
peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id, addr); |
| 5960 |
if (!peer || !peer->dp_peer) { |
| 5961 |
spin_unlock_bh(&dp->dp_lock); |
| 5962 |
return -ENOENT; |
| 5963 |
} |
| 5964 |
|
| 5965 |
len = ARRAY_SIZE(peer->dp_peer->keys); |
| 5966 |
for (i = 0; i < len; i++) { |
| 5967 |
if (!peer->dp_peer->keys[i]) |
| 5968 |
continue; |
| 5969 |
|
| 5970 |
keys[i] = peer->dp_peer->keys[i]; |
| 5971 |
peer->dp_peer->keys[i] = NULL; |
| 5972 |
} |
| 5973 |
|
| 5974 |
spin_unlock_bh(&dp->dp_lock); |
| 5975 |
|
| 5976 |
for (i = 0; i < len; i++) { |
| 5977 |
if (!keys[i]) |
| 5978 |
continue; |
| 5979 |
|
| 5980 |
/* key flags are not required to delete the key */ |
| 5981 |
ret = ath12k_install_key(arvif, keys[i], |
| 5982 |
DISABLE_KEY, addr, flags); |
| 5983 |
if (ret < 0 && first_errno == 0) |
| 5984 |
first_errno = ret; |
| 5985 |
|
| 5986 |
if (ret < 0) |
| 5987 |
ath12k_warn(ab, "failed to remove peer key %d: %d\n", |
| 5988 |
i, ret); |
| 5989 |
} |
| 5990 |
|
| 5991 |
return first_errno; |
| 5992 |
} |
| 5993 |
|
| 5994 |
static int ath12k_mac_set_key(struct ath12k *ar, enum set_key_cmd cmd, |
| 5995 |
struct ath12k_link_vif *arvif, |
| 5996 |
struct ath12k_link_sta *arsta, |
| 5997 |
struct ieee80211_key_conf *key) |
| 5998 |
{ |
| 5999 |
struct ieee80211_sta *sta = NULL; |
| 6000 |
struct ath12k_base *ab = ar->ab; |
| 6001 |
struct ath12k_dp_link_peer *peer; |
| 6002 |
struct ath12k_sta *ahsta; |
| 6003 |
const u8 *peer_addr; |
| 6004 |
int ret; |
| 6005 |
u32 flags = 0; |
| 6006 |
struct ath12k_dp *dp = ath12k_ab_to_dp(ab); |
| 6007 |
|
| 6008 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 6009 |
|
| 6010 |
if (arsta) |
| 6011 |
sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 6012 |
|
| 6013 |
if (test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ab->dev_flags)) |
| 6014 |
return 1; |
| 6015 |
|
| 6016 |
if (sta) |
| 6017 |
peer_addr = arsta->addr; |
| 6018 |
else |
| 6019 |
peer_addr = arvif->bssid; |
| 6020 |
|
| 6021 |
key->hw_key_idx = key->keyidx; |
| 6022 |
|
| 6023 |
/* the peer should not disappear in mid-way (unless FW goes awry) since |
| 6024 |
* we already hold wiphy lock. we just make sure its there now. |
| 6025 |
*/ |
| 6026 |
spin_lock_bh(&dp->dp_lock); |
| 6027 |
peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id, |
| 6028 |
peer_addr); |
| 6029 |
if (!peer || !peer->dp_peer) { |
| 6030 |
spin_unlock_bh(&dp->dp_lock); |
| 6031 |
|
| 6032 |
if (cmd == SET_KEY) { |
| 6033 |
ath12k_warn(ab, "cannot install key for non-existent peer %pM\n", |
| 6034 |
peer_addr); |
| 6035 |
return -EOPNOTSUPP; |
| 6036 |
} |
| 6037 |
|
| 6038 |
/* if the peer doesn't exist there is no key to disable |
| 6039 |
* anymore |
| 6040 |
*/ |
| 6041 |
return 0; |
| 6042 |
} |
| 6043 |
|
| 6044 |
spin_unlock_bh(&dp->dp_lock); |
| 6045 |
|
| 6046 |
if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 6047 |
flags = WMI_KEY_PAIRWISE; |
| 6048 |
else |
| 6049 |
flags = WMI_KEY_GROUP; |
| 6050 |
|
| 6051 |
ret = ath12k_install_key(arvif, key, cmd, peer_addr, flags); |
| 6052 |
if (ret) { |
| 6053 |
ath12k_warn(ab, "ath12k_install_key failed (%d)\n", ret); |
| 6054 |
return ret; |
| 6055 |
} |
| 6056 |
|
| 6057 |
ret = ath12k_dp_rx_peer_pn_replay_config(arvif, peer_addr, cmd, key); |
| 6058 |
if (ret) { |
| 6059 |
ath12k_warn(ab, "failed to offload PN replay detection %d\n", ret); |
| 6060 |
return ret; |
| 6061 |
} |
| 6062 |
|
| 6063 |
spin_lock_bh(&dp->dp_lock); |
| 6064 |
peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id, |
| 6065 |
peer_addr); |
| 6066 |
if (peer && peer->dp_peer && cmd == SET_KEY) { |
| 6067 |
peer->dp_peer->keys[key->keyidx] = key; |
| 6068 |
if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { |
| 6069 |
peer->dp_peer->ucast_keyidx = key->keyidx; |
| 6070 |
peer->dp_peer->sec_type = |
| 6071 |
ath12k_dp_tx_get_encrypt_type(key->cipher); |
| 6072 |
} else { |
| 6073 |
peer->dp_peer->mcast_keyidx = key->keyidx; |
| 6074 |
peer->dp_peer->sec_type_grp = |
| 6075 |
ath12k_dp_tx_get_encrypt_type(key->cipher); |
| 6076 |
} |
| 6077 |
} else if (peer && peer->dp_peer && cmd == DISABLE_KEY) { |
| 6078 |
peer->dp_peer->keys[key->keyidx] = NULL; |
| 6079 |
if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 6080 |
peer->dp_peer->ucast_keyidx = 0; |
| 6081 |
else |
| 6082 |
peer->dp_peer->mcast_keyidx = 0; |
| 6083 |
} else if (!peer) |
| 6084 |
/* impossible unless FW goes crazy */ |
| 6085 |
ath12k_warn(ab, "peer %pM disappeared!\n", peer_addr); |
| 6086 |
|
| 6087 |
if (sta) { |
| 6088 |
ahsta = ath12k_sta_to_ahsta(sta); |
| 6089 |
|
| 6090 |
switch (key->cipher) { |
| 6091 |
case WLAN_CIPHER_SUITE_TKIP: |
| 6092 |
case WLAN_CIPHER_SUITE_CCMP: |
| 6093 |
case WLAN_CIPHER_SUITE_CCMP_256: |
| 6094 |
case WLAN_CIPHER_SUITE_GCMP: |
| 6095 |
case WLAN_CIPHER_SUITE_GCMP_256: |
| 6096 |
if (cmd == SET_KEY) |
| 6097 |
ahsta->pn_type = HAL_PN_TYPE_WPA; |
| 6098 |
else |
| 6099 |
ahsta->pn_type = HAL_PN_TYPE_NONE; |
| 6100 |
break; |
| 6101 |
default: |
| 6102 |
ahsta->pn_type = HAL_PN_TYPE_NONE; |
| 6103 |
break; |
| 6104 |
} |
| 6105 |
} |
| 6106 |
|
| 6107 |
spin_unlock_bh(&dp->dp_lock); |
| 6108 |
|
| 6109 |
return 0; |
| 6110 |
} |
| 6111 |
|
| 6112 |
static int ath12k_mac_update_key_cache(struct ath12k_vif_cache *cache, |
| 6113 |
enum set_key_cmd cmd, |
| 6114 |
struct ieee80211_sta *sta, |
| 6115 |
struct ieee80211_key_conf *key) |
| 6116 |
{ |
| 6117 |
struct ath12k_key_conf *key_conf, *tmp; |
| 6118 |
|
| 6119 |
list_for_each_entry_safe(key_conf, tmp, &cache->key_conf.list, list) { |
| 6120 |
if (key_conf->key != key) |
| 6121 |
continue; |
| 6122 |
|
| 6123 |
/* If SET key entry is already present in cache, nothing to do, |
| 6124 |
* just return |
| 6125 |
*/ |
| 6126 |
if (cmd == SET_KEY) |
| 6127 |
return 0; |
| 6128 |
|
| 6129 |
/* DEL key for an old SET key which driver hasn't flushed yet. |
| 6130 |
*/ |
| 6131 |
list_del(&key_conf->list); |
| 6132 |
kfree(key_conf); |
| 6133 |
} |
| 6134 |
|
| 6135 |
if (cmd == SET_KEY) { |
| 6136 |
key_conf = kzalloc_obj(*key_conf); |
| 6137 |
|
| 6138 |
if (!key_conf) |
| 6139 |
return -ENOMEM; |
| 6140 |
|
| 6141 |
key_conf->cmd = cmd; |
| 6142 |
key_conf->sta = sta; |
| 6143 |
key_conf->key = key; |
| 6144 |
list_add_tail(&key_conf->list, |
| 6145 |
&cache->key_conf.list); |
| 6146 |
} |
| 6147 |
|
| 6148 |
return 0; |
| 6149 |
} |
| 6150 |
|
| 6151 |
int ath12k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 6152 |
struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 6153 |
struct ieee80211_key_conf *key) |
| 6154 |
{ |
| 6155 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 6156 |
struct ath12k_link_vif *arvif; |
| 6157 |
struct ath12k_link_sta *arsta = NULL; |
| 6158 |
struct ath12k_vif_cache *cache; |
| 6159 |
struct ath12k_sta *ahsta; |
| 6160 |
unsigned long links; |
| 6161 |
u8 link_id; |
| 6162 |
int ret; |
| 6163 |
|
| 6164 |
lockdep_assert_wiphy(hw->wiphy); |
| 6165 |
|
| 6166 |
/* IGTK needs to be done in host software */ |
| 6167 |
if (key->keyidx == 4 || key->keyidx == 5) |
| 6168 |
return 1; |
| 6169 |
|
| 6170 |
if (key->keyidx > WMI_MAX_KEY_INDEX) |
| 6171 |
return -ENOSPC; |
| 6172 |
|
| 6173 |
if (sta) { |
| 6174 |
ahsta = ath12k_sta_to_ahsta(sta); |
| 6175 |
|
| 6176 |
/* For an ML STA Pairwise key is same for all associated link Stations, |
| 6177 |
* hence do set key for all link STAs which are active. |
| 6178 |
*/ |
| 6179 |
if (sta->mlo) { |
| 6180 |
links = ahsta->links_map; |
| 6181 |
for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 6182 |
arvif = wiphy_dereference(hw->wiphy, |
| 6183 |
ahvif->link[link_id]); |
| 6184 |
arsta = wiphy_dereference(hw->wiphy, |
| 6185 |
ahsta->link[link_id]); |
| 6186 |
|
| 6187 |
if (WARN_ON(!arvif || !arsta)) |
| 6188 |
/* arvif and arsta are expected to be valid when |
| 6189 |
* STA is present. |
| 6190 |
*/ |
| 6191 |
continue; |
| 6192 |
|
| 6193 |
ret = ath12k_mac_set_key(arvif->ar, cmd, arvif, |
| 6194 |
arsta, key); |
| 6195 |
if (ret) |
| 6196 |
break; |
| 6197 |
} |
| 6198 |
|
| 6199 |
return 0; |
| 6200 |
} |
| 6201 |
|
| 6202 |
arsta = &ahsta->deflink; |
| 6203 |
arvif = arsta->arvif; |
| 6204 |
if (WARN_ON(!arvif)) |
| 6205 |
return -EINVAL; |
| 6206 |
|
| 6207 |
ret = ath12k_mac_set_key(arvif->ar, cmd, arvif, arsta, key); |
| 6208 |
if (ret) |
| 6209 |
return ret; |
| 6210 |
|
| 6211 |
return 0; |
| 6212 |
} |
| 6213 |
|
| 6214 |
if (key->link_id >= 0 && key->link_id < IEEE80211_MLD_MAX_NUM_LINKS) { |
| 6215 |
link_id = key->link_id; |
| 6216 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 6217 |
} else { |
| 6218 |
link_id = 0; |
| 6219 |
arvif = &ahvif->deflink; |
| 6220 |
} |
| 6221 |
|
| 6222 |
if (!arvif || !arvif->is_created) { |
| 6223 |
cache = ath12k_ahvif_get_link_cache(ahvif, link_id); |
| 6224 |
if (!cache) |
| 6225 |
return -ENOSPC; |
| 6226 |
|
| 6227 |
ret = ath12k_mac_update_key_cache(cache, cmd, sta, key); |
| 6228 |
if (ret) |
| 6229 |
return ret; |
| 6230 |
|
| 6231 |
return 0; |
| 6232 |
} |
| 6233 |
|
| 6234 |
ret = ath12k_mac_set_key(arvif->ar, cmd, arvif, NULL, key); |
| 6235 |
if (ret) |
| 6236 |
return ret; |
| 6237 |
|
| 6238 |
return 0; |
| 6239 |
} |
| 6240 |
EXPORT_SYMBOL(ath12k_mac_op_set_key); |
| 6241 |
|
| 6242 |
static int |
| 6243 |
ath12k_mac_bitrate_mask_num_vht_rates(struct ath12k *ar, |
| 6244 |
enum nl80211_band band, |
| 6245 |
const struct cfg80211_bitrate_mask *mask) |
| 6246 |
{ |
| 6247 |
int num_rates = 0; |
| 6248 |
int i; |
| 6249 |
|
| 6250 |
for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) |
| 6251 |
num_rates += hweight16(mask->control[band].vht_mcs[i]); |
| 6252 |
|
| 6253 |
return num_rates; |
| 6254 |
} |
| 6255 |
|
| 6256 |
static int |
| 6257 |
ath12k_mac_bitrate_mask_num_he_rates(struct ath12k *ar, |
| 6258 |
enum nl80211_band band, |
| 6259 |
const struct cfg80211_bitrate_mask *mask) |
| 6260 |
{ |
| 6261 |
int num_rates = 0; |
| 6262 |
int i; |
| 6263 |
|
| 6264 |
for (i = 0; i < ARRAY_SIZE(mask->control[band].he_mcs); i++) |
| 6265 |
num_rates += hweight16(mask->control[band].he_mcs[i]); |
| 6266 |
|
| 6267 |
return num_rates; |
| 6268 |
} |
| 6269 |
|
| 6270 |
static int |
| 6271 |
ath12k_mac_bitrate_mask_num_eht_rates(struct ath12k *ar, |
| 6272 |
enum nl80211_band band, |
| 6273 |
const struct cfg80211_bitrate_mask *mask) |
| 6274 |
{ |
| 6275 |
int num_rates = 0; |
| 6276 |
int i; |
| 6277 |
|
| 6278 |
for (i = 0; i < ARRAY_SIZE(mask->control[band].eht_mcs); i++) |
| 6279 |
num_rates += hweight16(mask->control[band].eht_mcs[i]); |
| 6280 |
|
| 6281 |
return num_rates; |
| 6282 |
} |
| 6283 |
|
| 6284 |
static int |
| 6285 |
ath12k_mac_set_peer_vht_fixed_rate(struct ath12k_link_vif *arvif, |
| 6286 |
struct ath12k_link_sta *arsta, |
| 6287 |
const struct cfg80211_bitrate_mask *mask, |
| 6288 |
enum nl80211_band band) |
| 6289 |
{ |
| 6290 |
struct ath12k *ar = arvif->ar; |
| 6291 |
u8 vht_rate, nss; |
| 6292 |
u32 rate_code; |
| 6293 |
int ret, i; |
| 6294 |
|
| 6295 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 6296 |
|
| 6297 |
nss = 0; |
| 6298 |
|
| 6299 |
for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { |
| 6300 |
if (hweight16(mask->control[band].vht_mcs[i]) == 1) { |
| 6301 |
nss = i + 1; |
| 6302 |
vht_rate = ffs(mask->control[band].vht_mcs[i]) - 1; |
| 6303 |
} |
| 6304 |
} |
| 6305 |
|
| 6306 |
if (!nss) { |
| 6307 |
ath12k_warn(ar->ab, "No single VHT Fixed rate found to set for %pM", |
| 6308 |
arsta->addr); |
| 6309 |
return -EINVAL; |
| 6310 |
} |
| 6311 |
|
| 6312 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 6313 |
"Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates", |
| 6314 |
arsta->addr); |
| 6315 |
|
| 6316 |
rate_code = ATH12K_HW_RATE_CODE(vht_rate, nss - 1, |
| 6317 |
WMI_RATE_PREAMBLE_VHT); |
| 6318 |
ret = ath12k_wmi_set_peer_param(ar, arsta->addr, |
| 6319 |
arvif->vdev_id, |
| 6320 |
WMI_PEER_PARAM_FIXED_RATE, |
| 6321 |
rate_code); |
| 6322 |
if (ret) |
| 6323 |
ath12k_warn(ar->ab, |
| 6324 |
"failed to update STA %pM Fixed Rate %d: %d\n", |
| 6325 |
arsta->addr, rate_code, ret); |
| 6326 |
|
| 6327 |
return ret; |
| 6328 |
} |
| 6329 |
|
| 6330 |
static int |
| 6331 |
ath12k_mac_set_peer_he_fixed_rate(struct ath12k_link_vif *arvif, |
| 6332 |
struct ath12k_link_sta *arsta, |
| 6333 |
const struct cfg80211_bitrate_mask *mask, |
| 6334 |
enum nl80211_band band) |
| 6335 |
{ |
| 6336 |
struct ath12k *ar = arvif->ar; |
| 6337 |
u8 he_rate, nss; |
| 6338 |
u32 rate_code; |
| 6339 |
int ret, i; |
| 6340 |
struct ath12k_sta *ahsta = arsta->ahsta; |
| 6341 |
struct ieee80211_sta *sta; |
| 6342 |
|
| 6343 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 6344 |
|
| 6345 |
sta = ath12k_ahsta_to_sta(ahsta); |
| 6346 |
nss = 0; |
| 6347 |
|
| 6348 |
for (i = 0; i < ARRAY_SIZE(mask->control[band].he_mcs); i++) { |
| 6349 |
if (hweight16(mask->control[band].he_mcs[i]) == 1) { |
| 6350 |
nss = i + 1; |
| 6351 |
he_rate = ffs(mask->control[band].he_mcs[i]) - 1; |
| 6352 |
} |
| 6353 |
} |
| 6354 |
|
| 6355 |
if (!nss) { |
| 6356 |
ath12k_warn(ar->ab, "No single HE Fixed rate found to set for %pM", |
| 6357 |
arsta->addr); |
| 6358 |
return -EINVAL; |
| 6359 |
} |
| 6360 |
|
| 6361 |
/* Avoid updating invalid nss as fixed rate*/ |
| 6362 |
if (nss > sta->deflink.rx_nss) |
| 6363 |
return -EINVAL; |
| 6364 |
|
| 6365 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 6366 |
"Setting Fixed HE Rate for peer %pM. Device will not switch to any other selected rates", |
| 6367 |
arsta->addr); |
| 6368 |
|
| 6369 |
rate_code = ATH12K_HW_RATE_CODE(he_rate, nss - 1, |
| 6370 |
WMI_RATE_PREAMBLE_HE); |
| 6371 |
|
| 6372 |
ret = ath12k_wmi_set_peer_param(ar, arsta->addr, |
| 6373 |
arvif->vdev_id, |
| 6374 |
WMI_PEER_PARAM_FIXED_RATE, |
| 6375 |
rate_code); |
| 6376 |
if (ret) |
| 6377 |
ath12k_warn(ar->ab, |
| 6378 |
"failed to update STA %pM Fixed Rate %d: %d\n", |
| 6379 |
arsta->addr, rate_code, ret); |
| 6380 |
|
| 6381 |
return ret; |
| 6382 |
} |
| 6383 |
|
| 6384 |
static int |
| 6385 |
ath12k_mac_set_peer_eht_fixed_rate(struct ath12k_link_vif *arvif, |
| 6386 |
struct ath12k_link_sta *arsta, |
| 6387 |
const struct cfg80211_bitrate_mask *mask, |
| 6388 |
enum nl80211_band band) |
| 6389 |
{ |
| 6390 |
struct ath12k_sta *ahsta = arsta->ahsta; |
| 6391 |
struct ath12k *ar = arvif->ar; |
| 6392 |
struct ieee80211_sta *sta; |
| 6393 |
struct ieee80211_link_sta *link_sta; |
| 6394 |
u8 eht_rate, nss = 0; |
| 6395 |
u32 rate_code; |
| 6396 |
int ret, i; |
| 6397 |
|
| 6398 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 6399 |
|
| 6400 |
sta = ath12k_ahsta_to_sta(ahsta); |
| 6401 |
|
| 6402 |
for (i = 0; i < ARRAY_SIZE(mask->control[band].eht_mcs); i++) { |
| 6403 |
if (hweight16(mask->control[band].eht_mcs[i]) == 1) { |
| 6404 |
nss = i + 1; |
| 6405 |
eht_rate = ffs(mask->control[band].eht_mcs[i]) - 1; |
| 6406 |
} |
| 6407 |
} |
| 6408 |
|
| 6409 |
if (!nss) { |
| 6410 |
ath12k_warn(ar->ab, "No single EHT Fixed rate found to set for %pM\n", |
| 6411 |
arsta->addr); |
| 6412 |
return -EINVAL; |
| 6413 |
} |
| 6414 |
|
| 6415 |
/* Avoid updating invalid nss as fixed rate*/ |
| 6416 |
link_sta = ath12k_mac_get_link_sta(arsta); |
| 6417 |
if (!link_sta || nss > link_sta->rx_nss) { |
| 6418 |
ath12k_warn(ar->ab, |
| 6419 |
"unable to access link sta for sta %pM link %u or fixed nss of %u is not supported by sta\n", |
| 6420 |
sta->addr, arsta->link_id, nss); |
| 6421 |
return -EINVAL; |
| 6422 |
} |
| 6423 |
|
| 6424 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 6425 |
"Setting Fixed EHT Rate for peer %pM. Device will not switch to any other selected rates\n", |
| 6426 |
arsta->addr); |
| 6427 |
|
| 6428 |
rate_code = ATH12K_HW_RATE_CODE(eht_rate, nss - 1, |
| 6429 |
WMI_RATE_PREAMBLE_EHT); |
| 6430 |
|
| 6431 |
ret = ath12k_wmi_set_peer_param(ar, arsta->addr, |
| 6432 |
arvif->vdev_id, |
| 6433 |
WMI_PEER_PARAM_FIXED_RATE, |
| 6434 |
rate_code); |
| 6435 |
if (ret) |
| 6436 |
ath12k_warn(ar->ab, |
| 6437 |
"failed to update STA %pM Fixed Rate %d: %d\n", |
| 6438 |
arsta->addr, rate_code, ret); |
| 6439 |
|
| 6440 |
return ret; |
| 6441 |
} |
| 6442 |
|
| 6443 |
static int ath12k_mac_station_assoc(struct ath12k *ar, |
| 6444 |
struct ath12k_link_vif *arvif, |
| 6445 |
struct ath12k_link_sta *arsta, |
| 6446 |
bool reassoc) |
| 6447 |
{ |
| 6448 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 6449 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 6450 |
struct ieee80211_link_sta *link_sta; |
| 6451 |
int ret; |
| 6452 |
struct cfg80211_chan_def def; |
| 6453 |
enum nl80211_band band; |
| 6454 |
struct cfg80211_bitrate_mask *mask; |
| 6455 |
u8 num_vht_rates, num_he_rates, num_eht_rates; |
| 6456 |
u8 link_id = arvif->link_id; |
| 6457 |
|
| 6458 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 6459 |
|
| 6460 |
if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
| 6461 |
return -EPERM; |
| 6462 |
|
| 6463 |
if (WARN_ON(!rcu_access_pointer(sta->link[link_id]))) |
| 6464 |
return -EINVAL; |
| 6465 |
|
| 6466 |
band = def.chan->band; |
| 6467 |
mask = &arvif->bitrate_mask; |
| 6468 |
|
| 6469 |
struct ath12k_wmi_peer_assoc_arg *peer_arg __free(kfree) = |
| 6470 |
kzalloc_obj(*peer_arg); |
| 6471 |
if (!peer_arg) |
| 6472 |
return -ENOMEM; |
| 6473 |
|
| 6474 |
ath12k_peer_assoc_prepare(ar, arvif, arsta, peer_arg, reassoc); |
| 6475 |
|
| 6476 |
if (peer_arg->peer_nss < 1) { |
| 6477 |
ath12k_warn(ar->ab, |
| 6478 |
"invalid peer NSS %d\n", peer_arg->peer_nss); |
| 6479 |
return -EINVAL; |
| 6480 |
} |
| 6481 |
|
| 6482 |
peer_arg->is_assoc = true; |
| 6483 |
ret = ath12k_wmi_send_peer_assoc_cmd(ar, peer_arg); |
| 6484 |
if (ret) { |
| 6485 |
ath12k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n", |
| 6486 |
arsta->addr, arvif->vdev_id, ret); |
| 6487 |
return ret; |
| 6488 |
} |
| 6489 |
|
| 6490 |
if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) { |
| 6491 |
ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", |
| 6492 |
arsta->addr, arvif->vdev_id); |
| 6493 |
return -ETIMEDOUT; |
| 6494 |
} |
| 6495 |
|
| 6496 |
num_vht_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, mask); |
| 6497 |
num_he_rates = ath12k_mac_bitrate_mask_num_he_rates(ar, band, mask); |
| 6498 |
num_eht_rates = ath12k_mac_bitrate_mask_num_eht_rates(ar, band, mask); |
| 6499 |
|
| 6500 |
/* If single VHT/HE/EHT rate is configured (by set_bitrate_mask()), |
| 6501 |
* peer_assoc will disable VHT/HE/EHT. This is now enabled by a peer |
| 6502 |
* specific fixed param. |
| 6503 |
* Note that all other rates and NSS will be disabled for this peer. |
| 6504 |
*/ |
| 6505 |
link_sta = ath12k_mac_get_link_sta(arsta); |
| 6506 |
if (!link_sta) { |
| 6507 |
ath12k_warn(ar->ab, "unable to access link sta in station assoc\n"); |
| 6508 |
return -EINVAL; |
| 6509 |
} |
| 6510 |
|
| 6511 |
spin_lock_bh(&ar->data_lock); |
| 6512 |
arsta->bw = ath12k_mac_ieee80211_sta_bw_to_wmi(ar, link_sta); |
| 6513 |
arsta->bw_prev = link_sta->bandwidth; |
| 6514 |
spin_unlock_bh(&ar->data_lock); |
| 6515 |
|
| 6516 |
if (link_sta->vht_cap.vht_supported && num_vht_rates == 1) { |
| 6517 |
ret = ath12k_mac_set_peer_vht_fixed_rate(arvif, arsta, mask, band); |
| 6518 |
} else if (link_sta->he_cap.has_he && num_he_rates == 1) { |
| 6519 |
ret = ath12k_mac_set_peer_he_fixed_rate(arvif, arsta, mask, band); |
| 6520 |
if (ret) |
| 6521 |
return ret; |
| 6522 |
} else if (link_sta->eht_cap.has_eht && num_eht_rates == 1) { |
| 6523 |
ret = ath12k_mac_set_peer_eht_fixed_rate(arvif, arsta, mask, band); |
| 6524 |
if (ret) |
| 6525 |
return ret; |
| 6526 |
} |
| 6527 |
|
| 6528 |
/* Re-assoc is run only to update supported rates for given station. It |
| 6529 |
* doesn't make much sense to reconfigure the peer completely. |
| 6530 |
*/ |
| 6531 |
if (reassoc) |
| 6532 |
return 0; |
| 6533 |
|
| 6534 |
ret = ath12k_setup_peer_smps(ar, arvif, arsta->addr, |
| 6535 |
&link_sta->ht_cap, &link_sta->he_6ghz_capa); |
| 6536 |
if (ret) { |
| 6537 |
ath12k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n", |
| 6538 |
arvif->vdev_id, ret); |
| 6539 |
return ret; |
| 6540 |
} |
| 6541 |
|
| 6542 |
if (!sta->wme) { |
| 6543 |
arvif->num_legacy_stations++; |
| 6544 |
ret = ath12k_recalc_rtscts_prot(arvif); |
| 6545 |
if (ret) |
| 6546 |
return ret; |
| 6547 |
} |
| 6548 |
|
| 6549 |
if (sta->wme && sta->uapsd_queues) { |
| 6550 |
ret = ath12k_peer_assoc_qos_ap(ar, arvif, arsta); |
| 6551 |
if (ret) { |
| 6552 |
ath12k_warn(ar->ab, "failed to set qos params for STA %pM for vdev %i: %d\n", |
| 6553 |
arsta->addr, arvif->vdev_id, ret); |
| 6554 |
return ret; |
| 6555 |
} |
| 6556 |
} |
| 6557 |
|
| 6558 |
return 0; |
| 6559 |
} |
| 6560 |
|
| 6561 |
static int ath12k_mac_station_disassoc(struct ath12k *ar, |
| 6562 |
struct ath12k_link_vif *arvif, |
| 6563 |
struct ath12k_link_sta *arsta) |
| 6564 |
{ |
| 6565 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 6566 |
|
| 6567 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 6568 |
|
| 6569 |
if (!sta->wme) { |
| 6570 |
arvif->num_legacy_stations--; |
| 6571 |
return ath12k_recalc_rtscts_prot(arvif); |
| 6572 |
} |
| 6573 |
|
| 6574 |
return 0; |
| 6575 |
} |
| 6576 |
|
| 6577 |
static void ath12k_sta_rc_update_wk(struct wiphy *wiphy, struct wiphy_work *wk) |
| 6578 |
{ |
| 6579 |
struct ieee80211_link_sta *link_sta; |
| 6580 |
struct ath12k *ar; |
| 6581 |
struct ath12k_link_vif *arvif; |
| 6582 |
struct ieee80211_sta *sta; |
| 6583 |
struct cfg80211_chan_def def; |
| 6584 |
enum nl80211_band band; |
| 6585 |
const u8 *ht_mcs_mask; |
| 6586 |
const u16 *vht_mcs_mask; |
| 6587 |
const u16 *he_mcs_mask; |
| 6588 |
const u16 *eht_mcs_mask; |
| 6589 |
u32 changed, bw, nss, mac_nss, smps, bw_prev; |
| 6590 |
int err, num_vht_rates, num_he_rates, num_eht_rates; |
| 6591 |
const struct cfg80211_bitrate_mask *mask; |
| 6592 |
enum wmi_phy_mode peer_phymode; |
| 6593 |
struct ath12k_link_sta *arsta; |
| 6594 |
struct ieee80211_vif *vif; |
| 6595 |
|
| 6596 |
lockdep_assert_wiphy(wiphy); |
| 6597 |
|
| 6598 |
arsta = container_of(wk, struct ath12k_link_sta, update_wk); |
| 6599 |
sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 6600 |
arvif = arsta->arvif; |
| 6601 |
vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 6602 |
ar = arvif->ar; |
| 6603 |
|
| 6604 |
if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
| 6605 |
return; |
| 6606 |
|
| 6607 |
band = def.chan->band; |
| 6608 |
ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; |
| 6609 |
vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; |
| 6610 |
he_mcs_mask = arvif->bitrate_mask.control[band].he_mcs; |
| 6611 |
eht_mcs_mask = arvif->bitrate_mask.control[band].eht_mcs; |
| 6612 |
|
| 6613 |
spin_lock_bh(&ar->data_lock); |
| 6614 |
|
| 6615 |
changed = arsta->changed; |
| 6616 |
arsta->changed = 0; |
| 6617 |
|
| 6618 |
bw = arsta->bw; |
| 6619 |
bw_prev = arsta->bw_prev; |
| 6620 |
nss = arsta->nss; |
| 6621 |
smps = arsta->smps; |
| 6622 |
|
| 6623 |
spin_unlock_bh(&ar->data_lock); |
| 6624 |
|
| 6625 |
nss = max_t(u32, 1, nss); |
| 6626 |
mac_nss = max3(ath12k_mac_max_ht_nss(ht_mcs_mask), |
| 6627 |
ath12k_mac_max_vht_nss(vht_mcs_mask), |
| 6628 |
ath12k_mac_max_he_nss(he_mcs_mask)); |
| 6629 |
mac_nss = max(mac_nss, ath12k_mac_max_eht_nss(eht_mcs_mask)); |
| 6630 |
nss = min(nss, mac_nss); |
| 6631 |
|
| 6632 |
struct ath12k_wmi_peer_assoc_arg *peer_arg __free(kfree) = |
| 6633 |
kzalloc_obj(*peer_arg); |
| 6634 |
if (!peer_arg) |
| 6635 |
return; |
| 6636 |
|
| 6637 |
if (changed & IEEE80211_RC_BW_CHANGED) { |
| 6638 |
ath12k_peer_assoc_h_phymode(ar, arvif, arsta, peer_arg); |
| 6639 |
peer_phymode = peer_arg->peer_phymode; |
| 6640 |
|
| 6641 |
if (bw > bw_prev) { |
| 6642 |
/* Phymode shows maximum supported channel width, if we |
| 6643 |
* upgrade bandwidth then due to sanity check of firmware, |
| 6644 |
* we have to send WMI_PEER_PHYMODE followed by |
| 6645 |
* WMI_PEER_CHWIDTH |
| 6646 |
*/ |
| 6647 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac bandwidth upgrade for sta %pM new %d old %d\n", |
| 6648 |
arsta->addr, bw, bw_prev); |
| 6649 |
err = ath12k_wmi_set_peer_param(ar, arsta->addr, |
| 6650 |
arvif->vdev_id, WMI_PEER_PHYMODE, |
| 6651 |
peer_phymode); |
| 6652 |
if (err) { |
| 6653 |
ath12k_warn(ar->ab, "failed to update STA %pM to peer phymode %d: %d\n", |
| 6654 |
arsta->addr, peer_phymode, err); |
| 6655 |
return; |
| 6656 |
} |
| 6657 |
err = ath12k_wmi_set_peer_param(ar, arsta->addr, |
| 6658 |
arvif->vdev_id, WMI_PEER_CHWIDTH, |
| 6659 |
bw); |
| 6660 |
if (err) |
| 6661 |
ath12k_warn(ar->ab, "failed to update STA %pM to peer bandwidth %d: %d\n", |
| 6662 |
arsta->addr, bw, err); |
| 6663 |
} else { |
| 6664 |
/* When we downgrade bandwidth this will conflict with phymode |
| 6665 |
* and cause to trigger firmware crash. In this case we send |
| 6666 |
* WMI_PEER_CHWIDTH followed by WMI_PEER_PHYMODE |
| 6667 |
*/ |
| 6668 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac bandwidth downgrade for sta %pM new %d old %d\n", |
| 6669 |
arsta->addr, bw, bw_prev); |
| 6670 |
err = ath12k_wmi_set_peer_param(ar, arsta->addr, |
| 6671 |
arvif->vdev_id, WMI_PEER_CHWIDTH, |
| 6672 |
bw); |
| 6673 |
if (err) { |
| 6674 |
ath12k_warn(ar->ab, "failed to update STA %pM peer to bandwidth %d: %d\n", |
| 6675 |
arsta->addr, bw, err); |
| 6676 |
return; |
| 6677 |
} |
| 6678 |
err = ath12k_wmi_set_peer_param(ar, arsta->addr, |
| 6679 |
arvif->vdev_id, WMI_PEER_PHYMODE, |
| 6680 |
peer_phymode); |
| 6681 |
if (err) |
| 6682 |
ath12k_warn(ar->ab, "failed to update STA %pM to peer phymode %d: %d\n", |
| 6683 |
arsta->addr, peer_phymode, err); |
| 6684 |
} |
| 6685 |
} |
| 6686 |
|
| 6687 |
if (changed & IEEE80211_RC_NSS_CHANGED) { |
| 6688 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac update sta %pM nss %d\n", |
| 6689 |
arsta->addr, nss); |
| 6690 |
|
| 6691 |
err = ath12k_wmi_set_peer_param(ar, arsta->addr, arvif->vdev_id, |
| 6692 |
WMI_PEER_NSS, nss); |
| 6693 |
if (err) |
| 6694 |
ath12k_warn(ar->ab, "failed to update STA %pM nss %d: %d\n", |
| 6695 |
arsta->addr, nss, err); |
| 6696 |
} |
| 6697 |
|
| 6698 |
if (changed & IEEE80211_RC_SMPS_CHANGED) { |
| 6699 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac update sta %pM smps %d\n", |
| 6700 |
arsta->addr, smps); |
| 6701 |
|
| 6702 |
err = ath12k_wmi_set_peer_param(ar, arsta->addr, arvif->vdev_id, |
| 6703 |
WMI_PEER_MIMO_PS_STATE, smps); |
| 6704 |
if (err) |
| 6705 |
ath12k_warn(ar->ab, "failed to update STA %pM smps %d: %d\n", |
| 6706 |
arsta->addr, smps, err); |
| 6707 |
} |
| 6708 |
|
| 6709 |
if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) { |
| 6710 |
mask = &arvif->bitrate_mask; |
| 6711 |
num_vht_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, |
| 6712 |
mask); |
| 6713 |
num_he_rates = ath12k_mac_bitrate_mask_num_he_rates(ar, band, |
| 6714 |
mask); |
| 6715 |
num_eht_rates = ath12k_mac_bitrate_mask_num_eht_rates(ar, band, |
| 6716 |
mask); |
| 6717 |
|
| 6718 |
/* Peer_assoc_prepare will reject vht rates in |
| 6719 |
* bitrate_mask if its not available in range format and |
| 6720 |
* sets vht tx_rateset as unsupported. So multiple VHT MCS |
| 6721 |
* setting(eg. MCS 4,5,6) per peer is not supported here. |
| 6722 |
* But, Single rate in VHT mask can be set as per-peer |
| 6723 |
* fixed rate. But even if any HT rates are configured in |
| 6724 |
* the bitrate mask, device will not switch to those rates |
| 6725 |
* when per-peer Fixed rate is set. |
| 6726 |
* TODO: Check RATEMASK_CMDID to support auto rates selection |
| 6727 |
* across HT/VHT and for multiple VHT MCS support. |
| 6728 |
*/ |
| 6729 |
link_sta = ath12k_mac_get_link_sta(arsta); |
| 6730 |
if (!link_sta) { |
| 6731 |
ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n", |
| 6732 |
sta->addr, arsta->link_id); |
| 6733 |
return; |
| 6734 |
} |
| 6735 |
|
| 6736 |
if (link_sta->vht_cap.vht_supported && num_vht_rates == 1) { |
| 6737 |
ath12k_mac_set_peer_vht_fixed_rate(arvif, arsta, mask, |
| 6738 |
band); |
| 6739 |
} else if (link_sta->he_cap.has_he && num_he_rates == 1) { |
| 6740 |
ath12k_mac_set_peer_he_fixed_rate(arvif, arsta, mask, band); |
| 6741 |
} else if (link_sta->eht_cap.has_eht && num_eht_rates == 1) { |
| 6742 |
err = ath12k_mac_set_peer_eht_fixed_rate(arvif, arsta, |
| 6743 |
mask, band); |
| 6744 |
if (err) { |
| 6745 |
ath12k_warn(ar->ab, |
| 6746 |
"failed to set peer EHT fixed rate for STA %pM ret %d\n", |
| 6747 |
arsta->addr, err); |
| 6748 |
return; |
| 6749 |
} |
| 6750 |
} else { |
| 6751 |
/* If the peer is non-VHT/HE/EHT or no fixed VHT/HE/EHT |
| 6752 |
* rate is provided in the new bitrate mask we set the |
| 6753 |
* other rates using peer_assoc command. Also clear |
| 6754 |
* the peer fixed rate settings as it has higher proprity |
| 6755 |
* than peer assoc |
| 6756 |
*/ |
| 6757 |
err = ath12k_wmi_set_peer_param(ar, arsta->addr, |
| 6758 |
arvif->vdev_id, |
| 6759 |
WMI_PEER_PARAM_FIXED_RATE, |
| 6760 |
WMI_FIXED_RATE_NONE); |
| 6761 |
if (err) |
| 6762 |
ath12k_warn(ar->ab, |
| 6763 |
"failed to disable peer fixed rate for STA %pM ret %d\n", |
| 6764 |
arsta->addr, err); |
| 6765 |
|
| 6766 |
ath12k_peer_assoc_prepare(ar, arvif, arsta, |
| 6767 |
peer_arg, true); |
| 6768 |
|
| 6769 |
peer_arg->is_assoc = false; |
| 6770 |
err = ath12k_wmi_send_peer_assoc_cmd(ar, peer_arg); |
| 6771 |
if (err) |
| 6772 |
ath12k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n", |
| 6773 |
arsta->addr, arvif->vdev_id, err); |
| 6774 |
|
| 6775 |
if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) |
| 6776 |
ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", |
| 6777 |
arsta->addr, arvif->vdev_id); |
| 6778 |
} |
| 6779 |
} |
| 6780 |
} |
| 6781 |
|
| 6782 |
static void ath12k_mac_free_unassign_link_sta(struct ath12k_hw *ah, |
| 6783 |
struct ath12k_sta *ahsta, |
| 6784 |
u8 link_id) |
| 6785 |
{ |
| 6786 |
struct ath12k_link_sta *arsta; |
| 6787 |
|
| 6788 |
lockdep_assert_wiphy(ah->hw->wiphy); |
| 6789 |
|
| 6790 |
if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) |
| 6791 |
return; |
| 6792 |
|
| 6793 |
arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]); |
| 6794 |
if (WARN_ON(!arsta)) |
| 6795 |
return; |
| 6796 |
|
| 6797 |
ahsta->links_map &= ~BIT(link_id); |
| 6798 |
rcu_assign_pointer(ahsta->link[link_id], NULL); |
| 6799 |
synchronize_rcu(); |
| 6800 |
|
| 6801 |
if (arsta == &ahsta->deflink) { |
| 6802 |
arsta->link_id = ATH12K_INVALID_LINK_ID; |
| 6803 |
arsta->ahsta = NULL; |
| 6804 |
arsta->arvif = NULL; |
| 6805 |
return; |
| 6806 |
} |
| 6807 |
|
| 6808 |
kfree(arsta); |
| 6809 |
} |
| 6810 |
|
| 6811 |
static int ath12k_mac_inc_num_stations(struct ath12k_link_vif *arvif, |
| 6812 |
struct ath12k_link_sta *arsta) |
| 6813 |
{ |
| 6814 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 6815 |
struct ath12k *ar = arvif->ar; |
| 6816 |
|
| 6817 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 6818 |
|
| 6819 |
if (arvif->ahvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) |
| 6820 |
return 0; |
| 6821 |
|
| 6822 |
if (ar->num_stations >= ar->max_num_stations) |
| 6823 |
return -ENOBUFS; |
| 6824 |
|
| 6825 |
ar->num_stations++; |
| 6826 |
arvif->num_stations++; |
| 6827 |
|
| 6828 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 6829 |
"mac station %pM connected to vdev %u num_stations %u\n", |
| 6830 |
arsta->addr, arvif->vdev_id, arvif->num_stations); |
| 6831 |
|
| 6832 |
return 0; |
| 6833 |
} |
| 6834 |
|
| 6835 |
static void ath12k_mac_dec_num_stations(struct ath12k_link_vif *arvif, |
| 6836 |
struct ath12k_link_sta *arsta) |
| 6837 |
{ |
| 6838 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 6839 |
struct ath12k *ar = arvif->ar; |
| 6840 |
|
| 6841 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 6842 |
|
| 6843 |
if (arvif->ahvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) |
| 6844 |
return; |
| 6845 |
|
| 6846 |
ar->num_stations--; |
| 6847 |
|
| 6848 |
if (arvif->num_stations) { |
| 6849 |
arvif->num_stations--; |
| 6850 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 6851 |
"mac station %pM disconnected from vdev %u num_stations %u\n", |
| 6852 |
arsta->addr, arvif->vdev_id, arvif->num_stations); |
| 6853 |
} else { |
| 6854 |
ath12k_warn(ar->ab, |
| 6855 |
"mac station %pM disconnect for vdev %u without any connected station\n", |
| 6856 |
arsta->addr, arvif->vdev_id); |
| 6857 |
} |
| 6858 |
} |
| 6859 |
|
| 6860 |
static void ath12k_mac_station_post_remove(struct ath12k *ar, |
| 6861 |
struct ath12k_link_vif *arvif, |
| 6862 |
struct ath12k_link_sta *arsta) |
| 6863 |
{ |
| 6864 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 6865 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 6866 |
struct ath12k_dp_link_peer *peer; |
| 6867 |
struct ath12k_dp *dp = ath12k_ab_to_dp(ar->ab); |
| 6868 |
|
| 6869 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 6870 |
|
| 6871 |
ath12k_mac_dec_num_stations(arvif, arsta); |
| 6872 |
|
| 6873 |
spin_lock_bh(&dp->dp_lock); |
| 6874 |
|
| 6875 |
peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id, |
| 6876 |
arsta->addr); |
| 6877 |
if (peer && peer->sta == sta) { |
| 6878 |
ath12k_warn(ar->ab, "Found peer entry %pM n vdev %i after it was supposedly removed\n", |
| 6879 |
vif->addr, arvif->vdev_id); |
| 6880 |
peer->sta = NULL; |
| 6881 |
|
| 6882 |
ath12k_dp_link_peer_free(peer); |
| 6883 |
ar->num_peers--; |
| 6884 |
} |
| 6885 |
|
| 6886 |
spin_unlock_bh(&dp->dp_lock); |
| 6887 |
} |
| 6888 |
|
| 6889 |
static int ath12k_mac_station_unauthorize(struct ath12k *ar, |
| 6890 |
struct ath12k_link_vif *arvif, |
| 6891 |
struct ath12k_link_sta *arsta) |
| 6892 |
{ |
| 6893 |
struct ath12k_dp_link_peer *peer; |
| 6894 |
int ret; |
| 6895 |
struct ath12k_dp *dp = ath12k_ab_to_dp(ar->ab); |
| 6896 |
|
| 6897 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 6898 |
|
| 6899 |
spin_lock_bh(&dp->dp_lock); |
| 6900 |
|
| 6901 |
peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id, |
| 6902 |
arsta->addr); |
| 6903 |
if (peer) |
| 6904 |
peer->is_authorized = false; |
| 6905 |
|
| 6906 |
spin_unlock_bh(&dp->dp_lock); |
| 6907 |
|
| 6908 |
/* Driver must clear the keys during the state change from |
| 6909 |
* IEEE80211_STA_AUTHORIZED to IEEE80211_STA_ASSOC, since after |
| 6910 |
* returning from here, mac80211 is going to delete the keys |
| 6911 |
* in __sta_info_destroy_part2(). This will ensure that the driver does |
| 6912 |
* not retain stale key references after mac80211 deletes the keys. |
| 6913 |
*/ |
| 6914 |
ret = ath12k_clear_peer_keys(arvif, arsta->addr); |
| 6915 |
if (ret) { |
| 6916 |
ath12k_warn(ar->ab, "failed to clear all peer keys for vdev %i: %d\n", |
| 6917 |
arvif->vdev_id, ret); |
| 6918 |
return ret; |
| 6919 |
} |
| 6920 |
|
| 6921 |
return 0; |
| 6922 |
} |
| 6923 |
|
| 6924 |
static int ath12k_mac_station_authorize(struct ath12k *ar, |
| 6925 |
struct ath12k_link_vif *arvif, |
| 6926 |
struct ath12k_link_sta *arsta) |
| 6927 |
{ |
| 6928 |
struct ath12k_dp_link_peer *peer; |
| 6929 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 6930 |
int ret; |
| 6931 |
struct ath12k_dp *dp = ath12k_ab_to_dp(ar->ab); |
| 6932 |
|
| 6933 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 6934 |
|
| 6935 |
spin_lock_bh(&dp->dp_lock); |
| 6936 |
|
| 6937 |
peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id, |
| 6938 |
arsta->addr); |
| 6939 |
if (peer) |
| 6940 |
peer->is_authorized = true; |
| 6941 |
|
| 6942 |
spin_unlock_bh(&dp->dp_lock); |
| 6943 |
|
| 6944 |
if (vif->type == NL80211_IFTYPE_STATION && arvif->is_up) { |
| 6945 |
ret = ath12k_wmi_set_peer_param(ar, arsta->addr, |
| 6946 |
arvif->vdev_id, |
| 6947 |
WMI_PEER_AUTHORIZE, |
| 6948 |
1); |
| 6949 |
if (ret) { |
| 6950 |
ath12k_warn(ar->ab, "Unable to authorize peer %pM vdev %d: %d\n", |
| 6951 |
arsta->addr, arvif->vdev_id, ret); |
| 6952 |
return ret; |
| 6953 |
} |
| 6954 |
} |
| 6955 |
|
| 6956 |
return 0; |
| 6957 |
} |
| 6958 |
|
| 6959 |
static int ath12k_mac_station_remove(struct ath12k *ar, |
| 6960 |
struct ath12k_link_vif *arvif, |
| 6961 |
struct ath12k_link_sta *arsta) |
| 6962 |
{ |
| 6963 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 6964 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 6965 |
int ret = 0; |
| 6966 |
struct ath12k_link_sta *temp_arsta; |
| 6967 |
|
| 6968 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 6969 |
|
| 6970 |
wiphy_work_cancel(ar->ah->hw->wiphy, &arsta->update_wk); |
| 6971 |
|
| 6972 |
if (ahvif->vdev_type == WMI_VDEV_TYPE_STA) { |
| 6973 |
ath12k_bss_disassoc(ar, arvif); |
| 6974 |
ret = ath12k_mac_vdev_stop(arvif); |
| 6975 |
if (ret) |
| 6976 |
ath12k_warn(ar->ab, "failed to stop vdev %i: %d\n", |
| 6977 |
arvif->vdev_id, ret); |
| 6978 |
} |
| 6979 |
|
| 6980 |
if (sta->mlo) |
| 6981 |
return ret; |
| 6982 |
|
| 6983 |
ath12k_dp_peer_cleanup(ar, arvif->vdev_id, arsta->addr); |
| 6984 |
|
| 6985 |
ret = ath12k_peer_delete(ar, arvif->vdev_id, arsta->addr); |
| 6986 |
if (ret) |
| 6987 |
ath12k_warn(ar->ab, "Failed to delete peer: %pM for VDEV: %d\n", |
| 6988 |
arsta->addr, arvif->vdev_id); |
| 6989 |
else |
| 6990 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "Removed peer: %pM for VDEV: %d\n", |
| 6991 |
arsta->addr, arvif->vdev_id); |
| 6992 |
|
| 6993 |
ath12k_mac_station_post_remove(ar, arvif, arsta); |
| 6994 |
|
| 6995 |
spin_lock_bh(&ar->ab->base_lock); |
| 6996 |
|
| 6997 |
/* To handle roaming and split phy scenario */ |
| 6998 |
temp_arsta = ath12k_link_sta_find_by_addr(ar->ab, arsta->addr); |
| 6999 |
if (temp_arsta && temp_arsta->arvif->ar == ar) |
| 7000 |
ath12k_link_sta_rhash_delete(ar->ab, arsta); |
| 7001 |
|
| 7002 |
spin_unlock_bh(&ar->ab->base_lock); |
| 7003 |
|
| 7004 |
if (sta->valid_links) |
| 7005 |
ath12k_mac_free_unassign_link_sta(ahvif->ah, |
| 7006 |
arsta->ahsta, arsta->link_id); |
| 7007 |
|
| 7008 |
return ret; |
| 7009 |
} |
| 7010 |
|
| 7011 |
static int ath12k_mac_station_add(struct ath12k *ar, |
| 7012 |
struct ath12k_link_vif *arvif, |
| 7013 |
struct ath12k_link_sta *arsta) |
| 7014 |
{ |
| 7015 |
struct ath12k_base *ab = ar->ab; |
| 7016 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 7017 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
| 7018 |
struct ath12k_wmi_peer_create_arg peer_param = {}; |
| 7019 |
int ret; |
| 7020 |
struct ath12k_link_sta *temp_arsta; |
| 7021 |
|
| 7022 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 7023 |
|
| 7024 |
ret = ath12k_mac_inc_num_stations(arvif, arsta); |
| 7025 |
if (ret) { |
| 7026 |
ath12k_warn(ab, "refusing to associate station: too many connected already (%d)\n", |
| 7027 |
ar->max_num_stations); |
| 7028 |
goto exit; |
| 7029 |
} |
| 7030 |
|
| 7031 |
spin_lock_bh(&ab->base_lock); |
| 7032 |
|
| 7033 |
/* |
| 7034 |
* In case of Split PHY and roaming scenario, pdev idx |
| 7035 |
* might differ but both the pdev will share same rhash |
| 7036 |
* table. In that case update the rhash table if link_sta is |
| 7037 |
* already present |
| 7038 |
*/ |
| 7039 |
temp_arsta = ath12k_link_sta_find_by_addr(ab, arsta->addr); |
| 7040 |
if (temp_arsta && temp_arsta->arvif->ar != ar) |
| 7041 |
ath12k_link_sta_rhash_delete(ab, temp_arsta); |
| 7042 |
|
| 7043 |
ret = ath12k_link_sta_rhash_add(ab, arsta); |
| 7044 |
spin_unlock_bh(&ab->base_lock); |
| 7045 |
if (ret) { |
| 7046 |
ath12k_warn(ab, "Failed to add arsta: %pM to hash table, ret: %d", |
| 7047 |
arsta->addr, ret); |
| 7048 |
goto dec_num_station; |
| 7049 |
} |
| 7050 |
|
| 7051 |
peer_param.vdev_id = arvif->vdev_id; |
| 7052 |
peer_param.peer_addr = arsta->addr; |
| 7053 |
peer_param.peer_type = WMI_PEER_TYPE_DEFAULT; |
| 7054 |
peer_param.ml_enabled = sta->mlo; |
| 7055 |
|
| 7056 |
ret = ath12k_peer_create(ar, arvif, sta, &peer_param); |
| 7057 |
if (ret) { |
| 7058 |
ath12k_warn(ab, "Failed to add peer: %pM for VDEV: %d\n", |
| 7059 |
arsta->addr, arvif->vdev_id); |
| 7060 |
goto free_peer; |
| 7061 |
} |
| 7062 |
|
| 7063 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "Added peer: %pM for VDEV: %d\n", |
| 7064 |
arsta->addr, arvif->vdev_id); |
| 7065 |
|
| 7066 |
if (ieee80211_vif_is_mesh(vif)) { |
| 7067 |
ret = ath12k_wmi_set_peer_param(ar, arsta->addr, |
| 7068 |
arvif->vdev_id, |
| 7069 |
WMI_PEER_USE_4ADDR, 1); |
| 7070 |
if (ret) { |
| 7071 |
ath12k_warn(ab, "failed to STA %pM 4addr capability: %d\n", |
| 7072 |
arsta->addr, ret); |
| 7073 |
goto free_peer; |
| 7074 |
} |
| 7075 |
} |
| 7076 |
|
| 7077 |
ret = ath12k_dp_peer_setup(ar, arvif->vdev_id, arsta->addr); |
| 7078 |
if (ret) { |
| 7079 |
ath12k_warn(ab, "failed to setup dp for peer %pM on vdev %i (%d)\n", |
| 7080 |
arsta->addr, arvif->vdev_id, ret); |
| 7081 |
goto free_peer; |
| 7082 |
} |
| 7083 |
|
| 7084 |
if (ab->hw_params->vdev_start_delay && |
| 7085 |
!arvif->is_started && |
| 7086 |
arvif->ahvif->vdev_type != WMI_VDEV_TYPE_AP) { |
| 7087 |
ret = ath12k_start_vdev_delay(ar, arvif); |
| 7088 |
if (ret) { |
| 7089 |
ath12k_warn(ab, "failed to delay vdev start: %d\n", ret); |
| 7090 |
goto free_peer; |
| 7091 |
} |
| 7092 |
} |
| 7093 |
|
| 7094 |
return 0; |
| 7095 |
|
| 7096 |
free_peer: |
| 7097 |
ath12k_peer_delete(ar, arvif->vdev_id, arsta->addr); |
| 7098 |
spin_lock_bh(&ab->base_lock); |
| 7099 |
ath12k_link_sta_rhash_delete(ab, arsta); |
| 7100 |
spin_unlock_bh(&ab->base_lock); |
| 7101 |
dec_num_station: |
| 7102 |
ath12k_mac_dec_num_stations(arvif, arsta); |
| 7103 |
exit: |
| 7104 |
return ret; |
| 7105 |
} |
| 7106 |
|
| 7107 |
static int ath12k_mac_assign_link_sta(struct ath12k_hw *ah, |
| 7108 |
struct ath12k_sta *ahsta, |
| 7109 |
struct ath12k_link_sta *arsta, |
| 7110 |
struct ath12k_vif *ahvif, |
| 7111 |
u8 link_id) |
| 7112 |
{ |
| 7113 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(ahsta); |
| 7114 |
struct ieee80211_link_sta *link_sta; |
| 7115 |
struct ath12k_link_vif *arvif; |
| 7116 |
|
| 7117 |
lockdep_assert_wiphy(ah->hw->wiphy); |
| 7118 |
|
| 7119 |
if (!arsta || link_id >= IEEE80211_MLD_MAX_NUM_LINKS) |
| 7120 |
return -EINVAL; |
| 7121 |
|
| 7122 |
arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); |
| 7123 |
if (!arvif) |
| 7124 |
return -EINVAL; |
| 7125 |
|
| 7126 |
memset(arsta, 0, sizeof(*arsta)); |
| 7127 |
|
| 7128 |
link_sta = wiphy_dereference(ah->hw->wiphy, sta->link[link_id]); |
| 7129 |
if (!link_sta) |
| 7130 |
return -EINVAL; |
| 7131 |
|
| 7132 |
ether_addr_copy(arsta->addr, link_sta->addr); |
| 7133 |
|
| 7134 |
/* logical index of the link sta in order of creation */ |
| 7135 |
arsta->link_idx = ahsta->num_peer++; |
| 7136 |
|
| 7137 |
arsta->link_id = link_id; |
| 7138 |
ahsta->links_map |= BIT(arsta->link_id); |
| 7139 |
arsta->arvif = arvif; |
| 7140 |
arsta->ahsta = ahsta; |
| 7141 |
ahsta->ahvif = ahvif; |
| 7142 |
|
| 7143 |
wiphy_work_init(&arsta->update_wk, ath12k_sta_rc_update_wk); |
| 7144 |
|
| 7145 |
rcu_assign_pointer(ahsta->link[link_id], arsta); |
| 7146 |
|
| 7147 |
return 0; |
| 7148 |
} |
| 7149 |
|
| 7150 |
static void ath12k_mac_ml_station_remove(struct ath12k_vif *ahvif, |
| 7151 |
struct ath12k_sta *ahsta) |
| 7152 |
{ |
| 7153 |
struct ieee80211_sta *sta = ath12k_ahsta_to_sta(ahsta); |
| 7154 |
struct ath12k_hw *ah = ahvif->ah; |
| 7155 |
struct ath12k_link_vif *arvif; |
| 7156 |
struct ath12k_link_sta *arsta; |
| 7157 |
unsigned long links; |
| 7158 |
struct ath12k *ar; |
| 7159 |
u8 link_id; |
| 7160 |
|
| 7161 |
lockdep_assert_wiphy(ah->hw->wiphy); |
| 7162 |
|
| 7163 |
ath12k_peer_mlo_link_peers_delete(ahvif, ahsta); |
| 7164 |
|
| 7165 |
/* validate link station removal and clear arsta links */ |
| 7166 |
links = ahsta->links_map; |
| 7167 |
for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 7168 |
arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); |
| 7169 |
arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]); |
| 7170 |
if (!arvif || !arsta) |
| 7171 |
continue; |
| 7172 |
|
| 7173 |
ar = arvif->ar; |
| 7174 |
|
| 7175 |
ath12k_mac_station_post_remove(ar, arvif, arsta); |
| 7176 |
|
| 7177 |
spin_lock_bh(&ar->ab->base_lock); |
| 7178 |
ath12k_link_sta_rhash_delete(ar->ab, arsta); |
| 7179 |
spin_unlock_bh(&ar->ab->base_lock); |
| 7180 |
|
| 7181 |
ath12k_mac_free_unassign_link_sta(ah, ahsta, link_id); |
| 7182 |
} |
| 7183 |
|
| 7184 |
if (sta->mlo) { |
| 7185 |
clear_bit(ahsta->ml_peer_id, ah->free_ml_peer_id_map); |
| 7186 |
ahsta->ml_peer_id = ATH12K_MLO_PEER_ID_INVALID; |
| 7187 |
} |
| 7188 |
} |
| 7189 |
|
| 7190 |
static int ath12k_mac_handle_link_sta_state(struct ieee80211_hw *hw, |
| 7191 |
struct ath12k_link_vif *arvif, |
| 7192 |
struct ath12k_link_sta *arsta, |
| 7193 |
enum ieee80211_sta_state old_state, |
| 7194 |
enum ieee80211_sta_state new_state) |
| 7195 |
{ |
| 7196 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 7197 |
struct ieee80211_bss_conf *link_conf; |
| 7198 |
struct ath12k *ar = arvif->ar; |
| 7199 |
struct ath12k_reg_info *reg_info; |
| 7200 |
struct ath12k_base *ab = ar->ab; |
| 7201 |
int ret = 0; |
| 7202 |
|
| 7203 |
lockdep_assert_wiphy(hw->wiphy); |
| 7204 |
|
| 7205 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "mac handle link %u sta %pM state %d -> %d\n", |
| 7206 |
arsta->link_id, arsta->addr, old_state, new_state); |
| 7207 |
|
| 7208 |
/* IEEE80211_STA_NONE -> IEEE80211_STA_NOTEXIST: Remove the station |
| 7209 |
* from driver |
| 7210 |
*/ |
| 7211 |
if ((old_state == IEEE80211_STA_NONE && |
| 7212 |
new_state == IEEE80211_STA_NOTEXIST)) { |
| 7213 |
ret = ath12k_mac_station_remove(ar, arvif, arsta); |
| 7214 |
if (ret) { |
| 7215 |
ath12k_warn(ab, "Failed to remove station: %pM for VDEV: %d\n", |
| 7216 |
arsta->addr, arvif->vdev_id); |
| 7217 |
goto exit; |
| 7218 |
} |
| 7219 |
} |
| 7220 |
|
| 7221 |
/* IEEE80211_STA_NOTEXIST -> IEEE80211_STA_NONE: Add new station to driver */ |
| 7222 |
if (old_state == IEEE80211_STA_NOTEXIST && |
| 7223 |
new_state == IEEE80211_STA_NONE) { |
| 7224 |
ret = ath12k_mac_station_add(ar, arvif, arsta); |
| 7225 |
if (ret) |
| 7226 |
ath12k_warn(ab, "Failed to add station: %pM for VDEV: %d\n", |
| 7227 |
arsta->addr, arvif->vdev_id); |
| 7228 |
|
| 7229 |
/* IEEE80211_STA_AUTH -> IEEE80211_STA_ASSOC: Send station assoc command for |
| 7230 |
* peer associated to AP/Mesh/ADHOC vif type. |
| 7231 |
*/ |
| 7232 |
} else if (old_state == IEEE80211_STA_AUTH && |
| 7233 |
new_state == IEEE80211_STA_ASSOC && |
| 7234 |
(vif->type == NL80211_IFTYPE_AP || |
| 7235 |
vif->type == NL80211_IFTYPE_MESH_POINT || |
| 7236 |
vif->type == NL80211_IFTYPE_ADHOC)) { |
| 7237 |
ret = ath12k_mac_station_assoc(ar, arvif, arsta, false); |
| 7238 |
if (ret) |
| 7239 |
ath12k_warn(ab, "Failed to associate station: %pM\n", |
| 7240 |
arsta->addr); |
| 7241 |
|
| 7242 |
/* IEEE80211_STA_ASSOC -> IEEE80211_STA_AUTHORIZED: set peer status as |
| 7243 |
* authorized |
| 7244 |
*/ |
| 7245 |
} else if (old_state == IEEE80211_STA_ASSOC && |
| 7246 |
new_state == IEEE80211_STA_AUTHORIZED) { |
| 7247 |
ret = ath12k_mac_station_authorize(ar, arvif, arsta); |
| 7248 |
if (ret) { |
| 7249 |
ath12k_warn(ab, "Failed to authorize station: %pM\n", |
| 7250 |
arsta->addr); |
| 7251 |
goto exit; |
| 7252 |
} |
| 7253 |
|
| 7254 |
if (ath12k_wmi_supports_6ghz_cc_ext(ar) && |
| 7255 |
arvif->ahvif->vdev_type == WMI_VDEV_TYPE_STA) { |
| 7256 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 7257 |
reg_info = ab->reg_info[ar->pdev_idx]; |
| 7258 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "connection done, update reg rules\n"); |
| 7259 |
ath12k_hw_to_ah(hw)->regd_updated = false; |
| 7260 |
ath12k_reg_handle_chan_list(ab, reg_info, arvif->ahvif->vdev_type, |
| 7261 |
link_conf->power_type); |
| 7262 |
} |
| 7263 |
|
| 7264 |
/* IEEE80211_STA_AUTHORIZED -> IEEE80211_STA_ASSOC: station may be in removal, |
| 7265 |
* deauthorize it. |
| 7266 |
*/ |
| 7267 |
} else if (old_state == IEEE80211_STA_AUTHORIZED && |
| 7268 |
new_state == IEEE80211_STA_ASSOC) { |
| 7269 |
ath12k_mac_station_unauthorize(ar, arvif, arsta); |
| 7270 |
|
| 7271 |
/* IEEE80211_STA_ASSOC -> IEEE80211_STA_AUTH: disassoc peer connected to |
| 7272 |
* AP/mesh/ADHOC vif type. |
| 7273 |
*/ |
| 7274 |
} else if (old_state == IEEE80211_STA_ASSOC && |
| 7275 |
new_state == IEEE80211_STA_AUTH && |
| 7276 |
(vif->type == NL80211_IFTYPE_AP || |
| 7277 |
vif->type == NL80211_IFTYPE_MESH_POINT || |
| 7278 |
vif->type == NL80211_IFTYPE_ADHOC)) { |
| 7279 |
ret = ath12k_mac_station_disassoc(ar, arvif, arsta); |
| 7280 |
if (ret) |
| 7281 |
ath12k_warn(ab, "Failed to disassociate station: %pM\n", |
| 7282 |
arsta->addr); |
| 7283 |
} |
| 7284 |
|
| 7285 |
exit: |
| 7286 |
return ret; |
| 7287 |
} |
| 7288 |
|
| 7289 |
static bool ath12k_mac_is_freq_on_mac(struct ath12k_hw_mode_freq_range_arg *freq_range, |
| 7290 |
u32 freq, u8 mac_id) |
| 7291 |
{ |
| 7292 |
return (freq >= freq_range[mac_id].low_2ghz_freq && |
| 7293 |
freq <= freq_range[mac_id].high_2ghz_freq) || |
| 7294 |
(freq >= freq_range[mac_id].low_5ghz_freq && |
| 7295 |
freq <= freq_range[mac_id].high_5ghz_freq); |
| 7296 |
} |
| 7297 |
|
| 7298 |
static bool |
| 7299 |
ath12k_mac_2_freq_same_mac_in_freq_range(struct ath12k_base *ab, |
| 7300 |
struct ath12k_hw_mode_freq_range_arg *freq_range, |
| 7301 |
u32 freq_link1, u32 freq_link2) |
| 7302 |
{ |
| 7303 |
u8 i; |
| 7304 |
|
| 7305 |
for (i = 0; i < MAX_RADIOS; i++) { |
| 7306 |
if (ath12k_mac_is_freq_on_mac(freq_range, freq_link1, i) && |
| 7307 |
ath12k_mac_is_freq_on_mac(freq_range, freq_link2, i)) |
| 7308 |
return true; |
| 7309 |
} |
| 7310 |
|
| 7311 |
return false; |
| 7312 |
} |
| 7313 |
|
| 7314 |
static bool ath12k_mac_is_hw_dbs_capable(struct ath12k_base *ab) |
| 7315 |
{ |
| 7316 |
return test_bit(WMI_TLV_SERVICE_DUAL_BAND_SIMULTANEOUS_SUPPORT, |
| 7317 |
ab->wmi_ab.svc_map) && |
| 7318 |
ab->wmi_ab.hw_mode_info.support_dbs; |
| 7319 |
} |
| 7320 |
|
| 7321 |
static bool ath12k_mac_2_freq_same_mac_in_dbs(struct ath12k_base *ab, |
| 7322 |
u32 freq_link1, u32 freq_link2) |
| 7323 |
{ |
| 7324 |
struct ath12k_hw_mode_freq_range_arg *freq_range; |
| 7325 |
|
| 7326 |
if (!ath12k_mac_is_hw_dbs_capable(ab)) |
| 7327 |
return true; |
| 7328 |
|
| 7329 |
freq_range = ab->wmi_ab.hw_mode_info.freq_range_caps[ATH12K_HW_MODE_DBS]; |
| 7330 |
return ath12k_mac_2_freq_same_mac_in_freq_range(ab, freq_range, |
| 7331 |
freq_link1, freq_link2); |
| 7332 |
} |
| 7333 |
|
| 7334 |
static bool ath12k_mac_is_hw_sbs_capable(struct ath12k_base *ab) |
| 7335 |
{ |
| 7336 |
return test_bit(WMI_TLV_SERVICE_DUAL_BAND_SIMULTANEOUS_SUPPORT, |
| 7337 |
ab->wmi_ab.svc_map) && |
| 7338 |
ab->wmi_ab.hw_mode_info.support_sbs; |
| 7339 |
} |
| 7340 |
|
| 7341 |
static bool ath12k_mac_2_freq_same_mac_in_sbs(struct ath12k_base *ab, |
| 7342 |
u32 freq_link1, u32 freq_link2) |
| 7343 |
{ |
| 7344 |
struct ath12k_hw_mode_info *info = &ab->wmi_ab.hw_mode_info; |
| 7345 |
struct ath12k_hw_mode_freq_range_arg *sbs_uppr_share; |
| 7346 |
struct ath12k_hw_mode_freq_range_arg *sbs_low_share; |
| 7347 |
struct ath12k_hw_mode_freq_range_arg *sbs_range; |
| 7348 |
|
| 7349 |
if (!ath12k_mac_is_hw_sbs_capable(ab)) |
| 7350 |
return true; |
| 7351 |
|
| 7352 |
if (ab->wmi_ab.sbs_lower_band_end_freq) { |
| 7353 |
sbs_uppr_share = info->freq_range_caps[ATH12K_HW_MODE_SBS_UPPER_SHARE]; |
| 7354 |
sbs_low_share = info->freq_range_caps[ATH12K_HW_MODE_SBS_LOWER_SHARE]; |
| 7355 |
|
| 7356 |
return ath12k_mac_2_freq_same_mac_in_freq_range(ab, sbs_low_share, |
| 7357 |
freq_link1, freq_link2) || |
| 7358 |
ath12k_mac_2_freq_same_mac_in_freq_range(ab, sbs_uppr_share, |
| 7359 |
freq_link1, freq_link2); |
| 7360 |
} |
| 7361 |
|
| 7362 |
sbs_range = info->freq_range_caps[ATH12K_HW_MODE_SBS]; |
| 7363 |
return ath12k_mac_2_freq_same_mac_in_freq_range(ab, sbs_range, |
| 7364 |
freq_link1, freq_link2); |
| 7365 |
} |
| 7366 |
|
| 7367 |
static bool ath12k_mac_freqs_on_same_mac(struct ath12k_base *ab, |
| 7368 |
u32 freq_link1, u32 freq_link2) |
| 7369 |
{ |
| 7370 |
return ath12k_mac_2_freq_same_mac_in_dbs(ab, freq_link1, freq_link2) && |
| 7371 |
ath12k_mac_2_freq_same_mac_in_sbs(ab, freq_link1, freq_link2); |
| 7372 |
} |
| 7373 |
|
| 7374 |
static int ath12k_mac_mlo_sta_set_link_active(struct ath12k_base *ab, |
| 7375 |
enum wmi_mlo_link_force_reason reason, |
| 7376 |
enum wmi_mlo_link_force_mode mode, |
| 7377 |
u8 *mlo_vdev_id_lst, |
| 7378 |
u8 num_mlo_vdev, |
| 7379 |
u8 *mlo_inactive_vdev_lst, |
| 7380 |
u8 num_mlo_inactive_vdev) |
| 7381 |
{ |
| 7382 |
struct wmi_mlo_link_set_active_arg param = {}; |
| 7383 |
u32 entry_idx, entry_offset, vdev_idx; |
| 7384 |
u8 vdev_id; |
| 7385 |
|
| 7386 |
param.reason = reason; |
| 7387 |
param.force_mode = mode; |
| 7388 |
|
| 7389 |
for (vdev_idx = 0; vdev_idx < num_mlo_vdev; vdev_idx++) { |
| 7390 |
vdev_id = mlo_vdev_id_lst[vdev_idx]; |
| 7391 |
entry_idx = vdev_id / 32; |
| 7392 |
entry_offset = vdev_id % 32; |
| 7393 |
if (entry_idx >= WMI_MLO_LINK_NUM_SZ) { |
| 7394 |
ath12k_warn(ab, "Invalid entry_idx %d num_mlo_vdev %d vdev %d", |
| 7395 |
entry_idx, num_mlo_vdev, vdev_id); |
| 7396 |
return -EINVAL; |
| 7397 |
} |
| 7398 |
param.vdev_bitmap[entry_idx] |= 1 << entry_offset; |
| 7399 |
/* update entry number if entry index changed */ |
| 7400 |
if (param.num_vdev_bitmap < entry_idx + 1) |
| 7401 |
param.num_vdev_bitmap = entry_idx + 1; |
| 7402 |
} |
| 7403 |
|
| 7404 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 7405 |
"num_vdev_bitmap %d vdev_bitmap[0] = 0x%x, vdev_bitmap[1] = 0x%x", |
| 7406 |
param.num_vdev_bitmap, param.vdev_bitmap[0], param.vdev_bitmap[1]); |
| 7407 |
|
| 7408 |
if (mode == WMI_MLO_LINK_FORCE_MODE_ACTIVE_INACTIVE) { |
| 7409 |
for (vdev_idx = 0; vdev_idx < num_mlo_inactive_vdev; vdev_idx++) { |
| 7410 |
vdev_id = mlo_inactive_vdev_lst[vdev_idx]; |
| 7411 |
entry_idx = vdev_id / 32; |
| 7412 |
entry_offset = vdev_id % 32; |
| 7413 |
if (entry_idx >= WMI_MLO_LINK_NUM_SZ) { |
| 7414 |
ath12k_warn(ab, "Invalid entry_idx %d num_mlo_vdev %d vdev %d", |
| 7415 |
entry_idx, num_mlo_inactive_vdev, vdev_id); |
| 7416 |
return -EINVAL; |
| 7417 |
} |
| 7418 |
param.inactive_vdev_bitmap[entry_idx] |= 1 << entry_offset; |
| 7419 |
/* update entry number if entry index changed */ |
| 7420 |
if (param.num_inactive_vdev_bitmap < entry_idx + 1) |
| 7421 |
param.num_inactive_vdev_bitmap = entry_idx + 1; |
| 7422 |
} |
| 7423 |
|
| 7424 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 7425 |
"num_vdev_bitmap %d inactive_vdev_bitmap[0] = 0x%x, inactive_vdev_bitmap[1] = 0x%x", |
| 7426 |
param.num_inactive_vdev_bitmap, |
| 7427 |
param.inactive_vdev_bitmap[0], |
| 7428 |
param.inactive_vdev_bitmap[1]); |
| 7429 |
} |
| 7430 |
|
| 7431 |
if (mode == WMI_MLO_LINK_FORCE_MODE_ACTIVE_LINK_NUM || |
| 7432 |
mode == WMI_MLO_LINK_FORCE_MODE_INACTIVE_LINK_NUM) { |
| 7433 |
param.num_link_entry = 1; |
| 7434 |
param.link_num[0].num_of_link = num_mlo_vdev - 1; |
| 7435 |
} |
| 7436 |
|
| 7437 |
return ath12k_wmi_send_mlo_link_set_active_cmd(ab, ¶m); |
| 7438 |
} |
| 7439 |
|
| 7440 |
static int ath12k_mac_mlo_sta_update_link_active(struct ath12k_base *ab, |
| 7441 |
struct ieee80211_hw *hw, |
| 7442 |
struct ath12k_vif *ahvif) |
| 7443 |
{ |
| 7444 |
u8 mlo_vdev_id_lst[IEEE80211_MLD_MAX_NUM_LINKS] = {}; |
| 7445 |
u32 mlo_freq_list[IEEE80211_MLD_MAX_NUM_LINKS] = {}; |
| 7446 |
unsigned long links = ahvif->links_map; |
| 7447 |
enum wmi_mlo_link_force_reason reason; |
| 7448 |
struct ieee80211_chanctx_conf *conf; |
| 7449 |
enum wmi_mlo_link_force_mode mode; |
| 7450 |
struct ieee80211_bss_conf *info; |
| 7451 |
struct ath12k_link_vif *arvif; |
| 7452 |
u8 num_mlo_vdev = 0; |
| 7453 |
u8 link_id; |
| 7454 |
|
| 7455 |
for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 7456 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 7457 |
/* make sure vdev is created on this device */ |
| 7458 |
if (!arvif || !arvif->is_created || arvif->ar->ab != ab) |
| 7459 |
continue; |
| 7460 |
|
| 7461 |
info = ath12k_mac_get_link_bss_conf(arvif); |
| 7462 |
conf = wiphy_dereference(hw->wiphy, info->chanctx_conf); |
| 7463 |
mlo_freq_list[num_mlo_vdev] = conf->def.chan->center_freq; |
| 7464 |
|
| 7465 |
mlo_vdev_id_lst[num_mlo_vdev] = arvif->vdev_id; |
| 7466 |
num_mlo_vdev++; |
| 7467 |
} |
| 7468 |
|
| 7469 |
/* It is not allowed to activate more links than a single device |
| 7470 |
* supported. Something goes wrong if we reach here. |
| 7471 |
*/ |
| 7472 |
if (num_mlo_vdev > ATH12K_NUM_MAX_ACTIVE_LINKS_PER_DEVICE) { |
| 7473 |
WARN_ON_ONCE(1); |
| 7474 |
return -EINVAL; |
| 7475 |
} |
| 7476 |
|
| 7477 |
/* if 2 links are established and both link channels fall on the |
| 7478 |
* same hardware MAC, send command to firmware to deactivate one |
| 7479 |
* of them. |
| 7480 |
*/ |
| 7481 |
if (num_mlo_vdev == 2 && |
| 7482 |
ath12k_mac_freqs_on_same_mac(ab, mlo_freq_list[0], |
| 7483 |
mlo_freq_list[1])) { |
| 7484 |
mode = WMI_MLO_LINK_FORCE_MODE_INACTIVE_LINK_NUM; |
| 7485 |
reason = WMI_MLO_LINK_FORCE_REASON_NEW_CONNECT; |
| 7486 |
return ath12k_mac_mlo_sta_set_link_active(ab, reason, mode, |
| 7487 |
mlo_vdev_id_lst, num_mlo_vdev, |
| 7488 |
NULL, 0); |
| 7489 |
} |
| 7490 |
|
| 7491 |
return 0; |
| 7492 |
} |
| 7493 |
|
| 7494 |
static bool ath12k_mac_are_sbs_chan(struct ath12k_base *ab, u32 freq_1, u32 freq_2) |
| 7495 |
{ |
| 7496 |
if (!ath12k_mac_is_hw_sbs_capable(ab)) |
| 7497 |
return false; |
| 7498 |
|
| 7499 |
if (ath12k_is_2ghz_channel_freq(freq_1) || |
| 7500 |
ath12k_is_2ghz_channel_freq(freq_2)) |
| 7501 |
return false; |
| 7502 |
|
| 7503 |
return !ath12k_mac_2_freq_same_mac_in_sbs(ab, freq_1, freq_2); |
| 7504 |
} |
| 7505 |
|
| 7506 |
static bool ath12k_mac_are_dbs_chan(struct ath12k_base *ab, u32 freq_1, u32 freq_2) |
| 7507 |
{ |
| 7508 |
if (!ath12k_mac_is_hw_dbs_capable(ab)) |
| 7509 |
return false; |
| 7510 |
|
| 7511 |
return !ath12k_mac_2_freq_same_mac_in_dbs(ab, freq_1, freq_2); |
| 7512 |
} |
| 7513 |
|
| 7514 |
static int ath12k_mac_select_links(struct ath12k_base *ab, |
| 7515 |
struct ieee80211_vif *vif, |
| 7516 |
struct ieee80211_hw *hw, |
| 7517 |
u16 *selected_links) |
| 7518 |
{ |
| 7519 |
unsigned long useful_links = ieee80211_vif_usable_links(vif); |
| 7520 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 7521 |
u8 num_useful_links = hweight_long(useful_links); |
| 7522 |
struct ieee80211_chanctx_conf *chanctx; |
| 7523 |
struct ath12k_link_vif *assoc_arvif; |
| 7524 |
u32 assoc_link_freq, partner_freq; |
| 7525 |
u16 sbs_links = 0, dbs_links = 0; |
| 7526 |
struct ieee80211_bss_conf *info; |
| 7527 |
struct ieee80211_channel *chan; |
| 7528 |
struct ieee80211_sta *sta; |
| 7529 |
struct ath12k_sta *ahsta; |
| 7530 |
u8 link_id; |
| 7531 |
|
| 7532 |
/* activate all useful links if less than max supported */ |
| 7533 |
if (num_useful_links <= ATH12K_NUM_MAX_ACTIVE_LINKS_PER_DEVICE) { |
| 7534 |
*selected_links = useful_links; |
| 7535 |
return 0; |
| 7536 |
} |
| 7537 |
|
| 7538 |
/* only in station mode we can get here, so it's safe |
| 7539 |
* to use ap_addr |
| 7540 |
*/ |
| 7541 |
rcu_read_lock(); |
| 7542 |
sta = ieee80211_find_sta(vif, vif->cfg.ap_addr); |
| 7543 |
if (!sta) { |
| 7544 |
rcu_read_unlock(); |
| 7545 |
ath12k_warn(ab, "failed to find sta with addr %pM\n", vif->cfg.ap_addr); |
| 7546 |
return -EINVAL; |
| 7547 |
} |
| 7548 |
|
| 7549 |
ahsta = ath12k_sta_to_ahsta(sta); |
| 7550 |
assoc_arvif = wiphy_dereference(hw->wiphy, ahvif->link[ahsta->assoc_link_id]); |
| 7551 |
info = ath12k_mac_get_link_bss_conf(assoc_arvif); |
| 7552 |
chanctx = rcu_dereference(info->chanctx_conf); |
| 7553 |
assoc_link_freq = chanctx->def.chan->center_freq; |
| 7554 |
rcu_read_unlock(); |
| 7555 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "assoc link %u freq %u\n", |
| 7556 |
assoc_arvif->link_id, assoc_link_freq); |
| 7557 |
|
| 7558 |
/* assoc link is already activated and has to be kept active, |
| 7559 |
* only need to select a partner link from others. |
| 7560 |
*/ |
| 7561 |
useful_links &= ~BIT(assoc_arvif->link_id); |
| 7562 |
for_each_set_bit(link_id, &useful_links, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 7563 |
info = wiphy_dereference(hw->wiphy, vif->link_conf[link_id]); |
| 7564 |
if (!info) { |
| 7565 |
ath12k_warn(ab, "failed to get link info for link: %u\n", |
| 7566 |
link_id); |
| 7567 |
return -ENOLINK; |
| 7568 |
} |
| 7569 |
|
| 7570 |
chan = info->chanreq.oper.chan; |
| 7571 |
if (!chan) { |
| 7572 |
ath12k_warn(ab, "failed to get chan for link: %u\n", link_id); |
| 7573 |
return -EINVAL; |
| 7574 |
} |
| 7575 |
|
| 7576 |
partner_freq = chan->center_freq; |
| 7577 |
if (ath12k_mac_are_sbs_chan(ab, assoc_link_freq, partner_freq)) { |
| 7578 |
sbs_links |= BIT(link_id); |
| 7579 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "new SBS link %u freq %u\n", |
| 7580 |
link_id, partner_freq); |
| 7581 |
continue; |
| 7582 |
} |
| 7583 |
|
| 7584 |
if (ath12k_mac_are_dbs_chan(ab, assoc_link_freq, partner_freq)) { |
| 7585 |
dbs_links |= BIT(link_id); |
| 7586 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "new DBS link %u freq %u\n", |
| 7587 |
link_id, partner_freq); |
| 7588 |
continue; |
| 7589 |
} |
| 7590 |
|
| 7591 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "non DBS/SBS link %u freq %u\n", |
| 7592 |
link_id, partner_freq); |
| 7593 |
} |
| 7594 |
|
| 7595 |
/* choose the first candidate no matter how many is in the list */ |
| 7596 |
if (sbs_links) |
| 7597 |
link_id = __ffs(sbs_links); |
| 7598 |
else if (dbs_links) |
| 7599 |
link_id = __ffs(dbs_links); |
| 7600 |
else |
| 7601 |
link_id = ffs(useful_links) - 1; |
| 7602 |
|
| 7603 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "select partner link %u\n", link_id); |
| 7604 |
|
| 7605 |
*selected_links = BIT(assoc_arvif->link_id) | BIT(link_id); |
| 7606 |
|
| 7607 |
return 0; |
| 7608 |
} |
| 7609 |
|
| 7610 |
int ath12k_mac_op_sta_state(struct ieee80211_hw *hw, |
| 7611 |
struct ieee80211_vif *vif, |
| 7612 |
struct ieee80211_sta *sta, |
| 7613 |
enum ieee80211_sta_state old_state, |
| 7614 |
enum ieee80211_sta_state new_state) |
| 7615 |
{ |
| 7616 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 7617 |
struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
| 7618 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 7619 |
struct ath12k_base *prev_ab = NULL, *ab; |
| 7620 |
struct ath12k_link_vif *arvif; |
| 7621 |
struct ath12k_link_sta *arsta; |
| 7622 |
unsigned long valid_links; |
| 7623 |
u16 selected_links = 0; |
| 7624 |
u8 link_id = 0, i; |
| 7625 |
struct ath12k *ar; |
| 7626 |
int ret = -EINVAL; |
| 7627 |
struct ath12k_dp_peer_create_params dp_params = {}; |
| 7628 |
|
| 7629 |
lockdep_assert_wiphy(hw->wiphy); |
| 7630 |
|
| 7631 |
if (ieee80211_vif_is_mld(vif) && sta->valid_links) { |
| 7632 |
WARN_ON(!sta->mlo && hweight16(sta->valid_links) != 1); |
| 7633 |
link_id = ffs(sta->valid_links) - 1; |
| 7634 |
} |
| 7635 |
|
| 7636 |
/* IEEE80211_STA_NOTEXIST -> IEEE80211_STA_NONE: |
| 7637 |
* New station add received. If this is a ML station then |
| 7638 |
* ahsta->links_map will be zero and sta->valid_links will be 1. |
| 7639 |
* Assign default link to the first link sta. |
| 7640 |
*/ |
| 7641 |
if (old_state == IEEE80211_STA_NOTEXIST && |
| 7642 |
new_state == IEEE80211_STA_NONE) { |
| 7643 |
memset(ahsta, 0, sizeof(*ahsta)); |
| 7644 |
|
| 7645 |
arsta = &ahsta->deflink; |
| 7646 |
|
| 7647 |
/* ML sta */ |
| 7648 |
if (sta->mlo && !ahsta->links_map && |
| 7649 |
(hweight16(sta->valid_links) == 1)) { |
| 7650 |
ahsta->ml_peer_id = ath12k_peer_ml_alloc(ah); |
| 7651 |
if (ahsta->ml_peer_id == ATH12K_MLO_PEER_ID_INVALID) { |
| 7652 |
ath12k_hw_warn(ah, "unable to allocate ML peer id for sta %pM", |
| 7653 |
sta->addr); |
| 7654 |
goto exit; |
| 7655 |
} |
| 7656 |
|
| 7657 |
dp_params.is_mlo = true; |
| 7658 |
dp_params.peer_id = ahsta->ml_peer_id | ATH12K_PEER_ML_ID_VALID; |
| 7659 |
} |
| 7660 |
|
| 7661 |
dp_params.sta = sta; |
| 7662 |
|
| 7663 |
if (vif->type == NL80211_IFTYPE_AP) |
| 7664 |
dp_params.ucast_ra_only = true; |
| 7665 |
|
| 7666 |
ret = ath12k_dp_peer_create(&ah->dp_hw, sta->addr, &dp_params); |
| 7667 |
if (ret) { |
| 7668 |
ath12k_hw_warn(ah, "unable to create ath12k_dp_peer for sta %pM, ret: %d", |
| 7669 |
sta->addr, ret); |
| 7670 |
|
| 7671 |
goto ml_peer_id_clear; |
| 7672 |
} |
| 7673 |
|
| 7674 |
ret = ath12k_mac_assign_link_sta(ah, ahsta, arsta, ahvif, |
| 7675 |
link_id); |
| 7676 |
if (ret) { |
| 7677 |
ath12k_hw_warn(ah, "unable assign link %d for sta %pM", |
| 7678 |
link_id, sta->addr); |
| 7679 |
goto peer_delete; |
| 7680 |
} |
| 7681 |
|
| 7682 |
/* above arsta will get memset, hence do this after assign |
| 7683 |
* link sta |
| 7684 |
*/ |
| 7685 |
if (sta->mlo) { |
| 7686 |
/* For station mode, arvif->is_sta_assoc_link has been set when |
| 7687 |
* vdev starts. Make sure the arvif/arsta pair have same setting |
| 7688 |
*/ |
| 7689 |
if (vif->type == NL80211_IFTYPE_STATION && |
| 7690 |
!arsta->arvif->is_sta_assoc_link) { |
| 7691 |
ath12k_hw_warn(ah, "failed to verify assoc link setting with link id %u\n", |
| 7692 |
link_id); |
| 7693 |
ret = -EINVAL; |
| 7694 |
goto exit; |
| 7695 |
} |
| 7696 |
|
| 7697 |
arsta->is_assoc_link = true; |
| 7698 |
ahsta->assoc_link_id = link_id; |
| 7699 |
} |
| 7700 |
} |
| 7701 |
|
| 7702 |
/* In the ML station scenario, activate all partner links once the |
| 7703 |
* client is transitioning to the associated state. |
| 7704 |
* |
| 7705 |
* FIXME: Ideally, this activation should occur when the client |
| 7706 |
* transitions to the authorized state. However, there are some |
| 7707 |
* issues with handling this in the firmware. Until the firmware |
| 7708 |
* can manage it properly, activate the links when the client is |
| 7709 |
* about to move to the associated state. |
| 7710 |
*/ |
| 7711 |
if (ieee80211_vif_is_mld(vif) && vif->type == NL80211_IFTYPE_STATION && |
| 7712 |
old_state == IEEE80211_STA_AUTH && new_state == IEEE80211_STA_ASSOC) { |
| 7713 |
/* TODO: for now only do link selection for single device |
| 7714 |
* MLO case. Other cases would be handled in the future. |
| 7715 |
*/ |
| 7716 |
ab = ah->radio[0].ab; |
| 7717 |
if (ab->ag->num_devices == 1) { |
| 7718 |
ret = ath12k_mac_select_links(ab, vif, hw, &selected_links); |
| 7719 |
if (ret) { |
| 7720 |
ath12k_warn(ab, |
| 7721 |
"failed to get selected links: %d\n", ret); |
| 7722 |
goto exit; |
| 7723 |
} |
| 7724 |
} else { |
| 7725 |
selected_links = ieee80211_vif_usable_links(vif); |
| 7726 |
} |
| 7727 |
|
| 7728 |
ieee80211_set_active_links(vif, selected_links); |
| 7729 |
} |
| 7730 |
|
| 7731 |
/* Handle all the other state transitions in generic way */ |
| 7732 |
valid_links = ahsta->links_map; |
| 7733 |
for_each_set_bit(link_id, &valid_links, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 7734 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 7735 |
arsta = wiphy_dereference(hw->wiphy, ahsta->link[link_id]); |
| 7736 |
/* some assumptions went wrong! */ |
| 7737 |
if (WARN_ON(!arvif || !arsta)) |
| 7738 |
continue; |
| 7739 |
|
| 7740 |
/* vdev might be in deleted */ |
| 7741 |
if (WARN_ON(!arvif->ar)) |
| 7742 |
continue; |
| 7743 |
|
| 7744 |
ret = ath12k_mac_handle_link_sta_state(hw, arvif, arsta, |
| 7745 |
old_state, new_state); |
| 7746 |
if (ret) { |
| 7747 |
ath12k_hw_warn(ah, "unable to move link sta %d of sta %pM from state %d to %d", |
| 7748 |
link_id, arsta->addr, old_state, new_state); |
| 7749 |
|
| 7750 |
if (old_state == IEEE80211_STA_NOTEXIST && |
| 7751 |
new_state == IEEE80211_STA_NONE) |
| 7752 |
goto peer_delete; |
| 7753 |
else |
| 7754 |
goto exit; |
| 7755 |
} |
| 7756 |
} |
| 7757 |
|
| 7758 |
if (ieee80211_vif_is_mld(vif) && vif->type == NL80211_IFTYPE_STATION && |
| 7759 |
old_state == IEEE80211_STA_ASSOC && new_state == IEEE80211_STA_AUTHORIZED) { |
| 7760 |
for_each_ar(ah, ar, i) { |
| 7761 |
ab = ar->ab; |
| 7762 |
if (prev_ab == ab) |
| 7763 |
continue; |
| 7764 |
|
| 7765 |
ret = ath12k_mac_mlo_sta_update_link_active(ab, hw, ahvif); |
| 7766 |
if (ret) { |
| 7767 |
ath12k_warn(ab, |
| 7768 |
"failed to update link active state on connect %d\n", |
| 7769 |
ret); |
| 7770 |
goto exit; |
| 7771 |
} |
| 7772 |
|
| 7773 |
prev_ab = ab; |
| 7774 |
} |
| 7775 |
} |
| 7776 |
/* IEEE80211_STA_NONE -> IEEE80211_STA_NOTEXIST: |
| 7777 |
* Remove the station from driver (handle ML sta here since that |
| 7778 |
* needs special handling. Normal sta will be handled in generic |
| 7779 |
* handler below |
| 7780 |
*/ |
| 7781 |
if (old_state == IEEE80211_STA_NONE && |
| 7782 |
new_state == IEEE80211_STA_NOTEXIST) { |
| 7783 |
if (sta->mlo) |
| 7784 |
ath12k_mac_ml_station_remove(ahvif, ahsta); |
| 7785 |
|
| 7786 |
ath12k_dp_peer_delete(&ah->dp_hw, sta->addr, sta); |
| 7787 |
} |
| 7788 |
|
| 7789 |
ret = 0; |
| 7790 |
goto exit; |
| 7791 |
|
| 7792 |
peer_delete: |
| 7793 |
ath12k_dp_peer_delete(&ah->dp_hw, sta->addr, sta); |
| 7794 |
ml_peer_id_clear: |
| 7795 |
if (sta->mlo) { |
| 7796 |
clear_bit(ahsta->ml_peer_id, ah->free_ml_peer_id_map); |
| 7797 |
ahsta->ml_peer_id = ATH12K_MLO_PEER_ID_INVALID; |
| 7798 |
} |
| 7799 |
exit: |
| 7800 |
/* update the state if everything went well */ |
| 7801 |
if (!ret) |
| 7802 |
ahsta->state = new_state; |
| 7803 |
|
| 7804 |
return ret; |
| 7805 |
} |
| 7806 |
EXPORT_SYMBOL(ath12k_mac_op_sta_state); |
| 7807 |
|
| 7808 |
int ath12k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw, |
| 7809 |
struct ieee80211_vif *vif, |
| 7810 |
struct ieee80211_sta *sta) |
| 7811 |
{ |
| 7812 |
struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
| 7813 |
struct ath12k *ar; |
| 7814 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 7815 |
struct ath12k_link_vif *arvif; |
| 7816 |
struct ath12k_link_sta *arsta; |
| 7817 |
u8 link_id; |
| 7818 |
int ret; |
| 7819 |
s16 txpwr; |
| 7820 |
|
| 7821 |
lockdep_assert_wiphy(hw->wiphy); |
| 7822 |
|
| 7823 |
/* TODO: use link id from mac80211 once that's implemented */ |
| 7824 |
link_id = 0; |
| 7825 |
|
| 7826 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 7827 |
arsta = wiphy_dereference(hw->wiphy, ahsta->link[link_id]); |
| 7828 |
|
| 7829 |
if (sta->deflink.txpwr.type == NL80211_TX_POWER_AUTOMATIC) { |
| 7830 |
txpwr = 0; |
| 7831 |
} else { |
| 7832 |
txpwr = sta->deflink.txpwr.power; |
| 7833 |
if (!txpwr) { |
| 7834 |
ret = -EINVAL; |
| 7835 |
goto out; |
| 7836 |
} |
| 7837 |
} |
| 7838 |
|
| 7839 |
if (txpwr > ATH12K_TX_POWER_MAX_VAL || txpwr < ATH12K_TX_POWER_MIN_VAL) { |
| 7840 |
ret = -EINVAL; |
| 7841 |
goto out; |
| 7842 |
} |
| 7843 |
|
| 7844 |
ar = arvif->ar; |
| 7845 |
|
| 7846 |
ret = ath12k_wmi_set_peer_param(ar, arsta->addr, arvif->vdev_id, |
| 7847 |
WMI_PEER_USE_FIXED_PWR, txpwr); |
| 7848 |
if (ret) { |
| 7849 |
ath12k_warn(ar->ab, "failed to set tx power for station ret: %d\n", |
| 7850 |
ret); |
| 7851 |
goto out; |
| 7852 |
} |
| 7853 |
|
| 7854 |
out: |
| 7855 |
return ret; |
| 7856 |
} |
| 7857 |
EXPORT_SYMBOL(ath12k_mac_op_sta_set_txpwr); |
| 7858 |
|
| 7859 |
void ath12k_mac_op_link_sta_rc_update(struct ieee80211_hw *hw, |
| 7860 |
struct ieee80211_vif *vif, |
| 7861 |
struct ieee80211_link_sta *link_sta, |
| 7862 |
u32 changed) |
| 7863 |
{ |
| 7864 |
struct ieee80211_sta *sta = link_sta->sta; |
| 7865 |
struct ath12k *ar; |
| 7866 |
struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
| 7867 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 7868 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 7869 |
struct ath12k_link_sta *arsta; |
| 7870 |
struct ath12k_link_vif *arvif; |
| 7871 |
struct ath12k_dp_link_peer *peer; |
| 7872 |
u32 bw, smps; |
| 7873 |
struct ath12k_dp *dp; |
| 7874 |
|
| 7875 |
rcu_read_lock(); |
| 7876 |
arvif = rcu_dereference(ahvif->link[link_sta->link_id]); |
| 7877 |
if (!arvif) { |
| 7878 |
ath12k_hw_warn(ah, "mac sta rc update failed to fetch link vif on link id %u for peer %pM\n", |
| 7879 |
link_sta->link_id, sta->addr); |
| 7880 |
rcu_read_unlock(); |
| 7881 |
return; |
| 7882 |
} |
| 7883 |
|
| 7884 |
ar = arvif->ar; |
| 7885 |
dp = ath12k_ab_to_dp(ar->ab); |
| 7886 |
|
| 7887 |
arsta = rcu_dereference(ahsta->link[link_sta->link_id]); |
| 7888 |
if (!arsta) { |
| 7889 |
rcu_read_unlock(); |
| 7890 |
ath12k_warn(ar->ab, "mac sta rc update failed to fetch link sta on link id %u for peer %pM\n", |
| 7891 |
link_sta->link_id, sta->addr); |
| 7892 |
return; |
| 7893 |
} |
| 7894 |
spin_lock_bh(&dp->dp_lock); |
| 7895 |
|
| 7896 |
peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id, |
| 7897 |
arsta->addr); |
| 7898 |
if (!peer) { |
| 7899 |
spin_unlock_bh(&dp->dp_lock); |
| 7900 |
rcu_read_unlock(); |
| 7901 |
ath12k_warn(ar->ab, "mac sta rc update failed to find peer %pM on vdev %i\n", |
| 7902 |
arsta->addr, arvif->vdev_id); |
| 7903 |
return; |
| 7904 |
} |
| 7905 |
|
| 7906 |
spin_unlock_bh(&dp->dp_lock); |
| 7907 |
|
| 7908 |
if (arsta->link_id >= IEEE80211_MLD_MAX_NUM_LINKS) { |
| 7909 |
rcu_read_unlock(); |
| 7910 |
return; |
| 7911 |
} |
| 7912 |
|
| 7913 |
link_sta = rcu_dereference(sta->link[arsta->link_id]); |
| 7914 |
if (!link_sta) { |
| 7915 |
rcu_read_unlock(); |
| 7916 |
ath12k_warn(ar->ab, "unable to access link sta in rc update for sta %pM link %u\n", |
| 7917 |
sta->addr, arsta->link_id); |
| 7918 |
return; |
| 7919 |
} |
| 7920 |
|
| 7921 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 7922 |
"mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", |
| 7923 |
arsta->addr, changed, link_sta->bandwidth, link_sta->rx_nss, |
| 7924 |
link_sta->smps_mode); |
| 7925 |
|
| 7926 |
spin_lock_bh(&ar->data_lock); |
| 7927 |
|
| 7928 |
if (changed & IEEE80211_RC_BW_CHANGED) { |
| 7929 |
bw = ath12k_mac_ieee80211_sta_bw_to_wmi(ar, link_sta); |
| 7930 |
arsta->bw_prev = arsta->bw; |
| 7931 |
arsta->bw = bw; |
| 7932 |
} |
| 7933 |
|
| 7934 |
if (changed & IEEE80211_RC_NSS_CHANGED) |
| 7935 |
arsta->nss = link_sta->rx_nss; |
| 7936 |
|
| 7937 |
if (changed & IEEE80211_RC_SMPS_CHANGED) { |
| 7938 |
smps = WMI_PEER_SMPS_PS_NONE; |
| 7939 |
|
| 7940 |
switch (link_sta->smps_mode) { |
| 7941 |
case IEEE80211_SMPS_AUTOMATIC: |
| 7942 |
case IEEE80211_SMPS_OFF: |
| 7943 |
smps = WMI_PEER_SMPS_PS_NONE; |
| 7944 |
break; |
| 7945 |
case IEEE80211_SMPS_STATIC: |
| 7946 |
smps = WMI_PEER_SMPS_STATIC; |
| 7947 |
break; |
| 7948 |
case IEEE80211_SMPS_DYNAMIC: |
| 7949 |
smps = WMI_PEER_SMPS_DYNAMIC; |
| 7950 |
break; |
| 7951 |
default: |
| 7952 |
ath12k_warn(ar->ab, "Invalid smps %d in sta rc update for %pM link %u\n", |
| 7953 |
link_sta->smps_mode, arsta->addr, link_sta->link_id); |
| 7954 |
smps = WMI_PEER_SMPS_PS_NONE; |
| 7955 |
break; |
| 7956 |
} |
| 7957 |
|
| 7958 |
arsta->smps = smps; |
| 7959 |
} |
| 7960 |
|
| 7961 |
arsta->changed |= changed; |
| 7962 |
|
| 7963 |
spin_unlock_bh(&ar->data_lock); |
| 7964 |
|
| 7965 |
wiphy_work_queue(hw->wiphy, &arsta->update_wk); |
| 7966 |
|
| 7967 |
rcu_read_unlock(); |
| 7968 |
} |
| 7969 |
EXPORT_SYMBOL(ath12k_mac_op_link_sta_rc_update); |
| 7970 |
|
| 7971 |
static struct ath12k_link_sta *ath12k_mac_alloc_assign_link_sta(struct ath12k_hw *ah, |
| 7972 |
struct ath12k_sta *ahsta, |
| 7973 |
struct ath12k_vif *ahvif, |
| 7974 |
u8 link_id) |
| 7975 |
{ |
| 7976 |
struct ath12k_link_sta *arsta; |
| 7977 |
int ret; |
| 7978 |
|
| 7979 |
lockdep_assert_wiphy(ah->hw->wiphy); |
| 7980 |
|
| 7981 |
if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) |
| 7982 |
return NULL; |
| 7983 |
|
| 7984 |
arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]); |
| 7985 |
if (arsta) |
| 7986 |
return NULL; |
| 7987 |
|
| 7988 |
arsta = kmalloc_obj(*arsta); |
| 7989 |
if (!arsta) |
| 7990 |
return NULL; |
| 7991 |
|
| 7992 |
ret = ath12k_mac_assign_link_sta(ah, ahsta, arsta, ahvif, link_id); |
| 7993 |
if (ret) { |
| 7994 |
kfree(arsta); |
| 7995 |
return NULL; |
| 7996 |
} |
| 7997 |
|
| 7998 |
return arsta; |
| 7999 |
} |
| 8000 |
|
| 8001 |
int ath12k_mac_op_change_sta_links(struct ieee80211_hw *hw, |
| 8002 |
struct ieee80211_vif *vif, |
| 8003 |
struct ieee80211_sta *sta, |
| 8004 |
u16 old_links, u16 new_links) |
| 8005 |
{ |
| 8006 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 8007 |
struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
| 8008 |
struct ath12k_hw *ah = hw->priv; |
| 8009 |
struct ath12k_link_vif *arvif; |
| 8010 |
struct ath12k_link_sta *arsta; |
| 8011 |
unsigned long valid_links; |
| 8012 |
struct ath12k *ar; |
| 8013 |
u8 link_id; |
| 8014 |
int ret; |
| 8015 |
|
| 8016 |
lockdep_assert_wiphy(hw->wiphy); |
| 8017 |
|
| 8018 |
if (!sta->valid_links) |
| 8019 |
return -EINVAL; |
| 8020 |
|
| 8021 |
/* Firmware does not support removal of one of link stas. All sta |
| 8022 |
* would be removed during ML STA delete in sta_state(), hence link |
| 8023 |
* sta removal is not handled here. |
| 8024 |
*/ |
| 8025 |
if (new_links < old_links) |
| 8026 |
return 0; |
| 8027 |
|
| 8028 |
if (ahsta->ml_peer_id == ATH12K_MLO_PEER_ID_INVALID) { |
| 8029 |
ath12k_hw_warn(ah, "unable to add link for ml sta %pM", sta->addr); |
| 8030 |
return -EINVAL; |
| 8031 |
} |
| 8032 |
|
| 8033 |
/* this op is expected only after initial sta insertion with default link */ |
| 8034 |
if (WARN_ON(ahsta->links_map == 0)) |
| 8035 |
return -EINVAL; |
| 8036 |
|
| 8037 |
valid_links = new_links; |
| 8038 |
for_each_set_bit(link_id, &valid_links, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 8039 |
if (ahsta->links_map & BIT(link_id)) |
| 8040 |
continue; |
| 8041 |
|
| 8042 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 8043 |
arsta = ath12k_mac_alloc_assign_link_sta(ah, ahsta, ahvif, link_id); |
| 8044 |
|
| 8045 |
if (!arvif || !arsta) { |
| 8046 |
ath12k_hw_warn(ah, "Failed to alloc/assign link sta"); |
| 8047 |
continue; |
| 8048 |
} |
| 8049 |
|
| 8050 |
ar = arvif->ar; |
| 8051 |
if (!ar) |
| 8052 |
continue; |
| 8053 |
|
| 8054 |
ret = ath12k_mac_station_add(ar, arvif, arsta); |
| 8055 |
if (ret) { |
| 8056 |
ath12k_warn(ar->ab, "Failed to add station: %pM for VDEV: %d\n", |
| 8057 |
arsta->addr, arvif->vdev_id); |
| 8058 |
ath12k_mac_free_unassign_link_sta(ah, ahsta, link_id); |
| 8059 |
return ret; |
| 8060 |
} |
| 8061 |
} |
| 8062 |
|
| 8063 |
return 0; |
| 8064 |
} |
| 8065 |
EXPORT_SYMBOL(ath12k_mac_op_change_sta_links); |
| 8066 |
|
| 8067 |
bool ath12k_mac_op_can_activate_links(struct ieee80211_hw *hw, |
| 8068 |
struct ieee80211_vif *vif, |
| 8069 |
u16 active_links) |
| 8070 |
{ |
| 8071 |
/* TODO: Handle recovery case */ |
| 8072 |
|
| 8073 |
return true; |
| 8074 |
} |
| 8075 |
EXPORT_SYMBOL(ath12k_mac_op_can_activate_links); |
| 8076 |
|
| 8077 |
static int ath12k_conf_tx_uapsd(struct ath12k_link_vif *arvif, |
| 8078 |
u16 ac, bool enable) |
| 8079 |
{ |
| 8080 |
struct ath12k *ar = arvif->ar; |
| 8081 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 8082 |
u32 value; |
| 8083 |
int ret; |
| 8084 |
|
| 8085 |
if (ahvif->vdev_type != WMI_VDEV_TYPE_STA) |
| 8086 |
return 0; |
| 8087 |
|
| 8088 |
switch (ac) { |
| 8089 |
case IEEE80211_AC_VO: |
| 8090 |
value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | |
| 8091 |
WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; |
| 8092 |
break; |
| 8093 |
case IEEE80211_AC_VI: |
| 8094 |
value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | |
| 8095 |
WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; |
| 8096 |
break; |
| 8097 |
case IEEE80211_AC_BE: |
| 8098 |
value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | |
| 8099 |
WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; |
| 8100 |
break; |
| 8101 |
case IEEE80211_AC_BK: |
| 8102 |
value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | |
| 8103 |
WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; |
| 8104 |
break; |
| 8105 |
} |
| 8106 |
|
| 8107 |
if (enable) |
| 8108 |
ahvif->u.sta.uapsd |= value; |
| 8109 |
else |
| 8110 |
ahvif->u.sta.uapsd &= ~value; |
| 8111 |
|
| 8112 |
ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 8113 |
WMI_STA_PS_PARAM_UAPSD, |
| 8114 |
ahvif->u.sta.uapsd); |
| 8115 |
if (ret) { |
| 8116 |
ath12k_warn(ar->ab, "could not set uapsd params %d\n", ret); |
| 8117 |
goto exit; |
| 8118 |
} |
| 8119 |
|
| 8120 |
if (ahvif->u.sta.uapsd) |
| 8121 |
value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; |
| 8122 |
else |
| 8123 |
value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; |
| 8124 |
|
| 8125 |
ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 8126 |
WMI_STA_PS_PARAM_RX_WAKE_POLICY, |
| 8127 |
value); |
| 8128 |
if (ret) |
| 8129 |
ath12k_warn(ar->ab, "could not set rx wake param %d\n", ret); |
| 8130 |
|
| 8131 |
exit: |
| 8132 |
return ret; |
| 8133 |
} |
| 8134 |
|
| 8135 |
static int ath12k_mac_conf_tx(struct ath12k_link_vif *arvif, u16 ac, |
| 8136 |
const struct ieee80211_tx_queue_params *params) |
| 8137 |
{ |
| 8138 |
struct wmi_wmm_params_arg *p = NULL; |
| 8139 |
struct ath12k *ar = arvif->ar; |
| 8140 |
struct ath12k_base *ab = ar->ab; |
| 8141 |
int ret; |
| 8142 |
|
| 8143 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 8144 |
|
| 8145 |
switch (ac) { |
| 8146 |
case IEEE80211_AC_VO: |
| 8147 |
p = &arvif->wmm_params.ac_vo; |
| 8148 |
break; |
| 8149 |
case IEEE80211_AC_VI: |
| 8150 |
p = &arvif->wmm_params.ac_vi; |
| 8151 |
break; |
| 8152 |
case IEEE80211_AC_BE: |
| 8153 |
p = &arvif->wmm_params.ac_be; |
| 8154 |
break; |
| 8155 |
case IEEE80211_AC_BK: |
| 8156 |
p = &arvif->wmm_params.ac_bk; |
| 8157 |
break; |
| 8158 |
} |
| 8159 |
|
| 8160 |
if (WARN_ON(!p)) { |
| 8161 |
ret = -EINVAL; |
| 8162 |
goto exit; |
| 8163 |
} |
| 8164 |
|
| 8165 |
p->cwmin = params->cw_min; |
| 8166 |
p->cwmax = params->cw_max; |
| 8167 |
p->aifs = params->aifs; |
| 8168 |
p->txop = params->txop; |
| 8169 |
|
| 8170 |
ret = ath12k_wmi_send_wmm_update_cmd(ar, arvif->vdev_id, |
| 8171 |
&arvif->wmm_params); |
| 8172 |
if (ret) { |
| 8173 |
ath12k_warn(ab, "pdev idx %d failed to set wmm params: %d\n", |
| 8174 |
ar->pdev_idx, ret); |
| 8175 |
goto exit; |
| 8176 |
} |
| 8177 |
|
| 8178 |
ret = ath12k_conf_tx_uapsd(arvif, ac, params->uapsd); |
| 8179 |
if (ret) |
| 8180 |
ath12k_warn(ab, "pdev idx %d failed to set sta uapsd: %d\n", |
| 8181 |
ar->pdev_idx, ret); |
| 8182 |
|
| 8183 |
exit: |
| 8184 |
return ret; |
| 8185 |
} |
| 8186 |
|
| 8187 |
int ath12k_mac_op_conf_tx(struct ieee80211_hw *hw, |
| 8188 |
struct ieee80211_vif *vif, |
| 8189 |
unsigned int link_id, u16 ac, |
| 8190 |
const struct ieee80211_tx_queue_params *params) |
| 8191 |
{ |
| 8192 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 8193 |
struct ath12k_link_vif *arvif; |
| 8194 |
struct ath12k_vif_cache *cache; |
| 8195 |
int ret; |
| 8196 |
|
| 8197 |
lockdep_assert_wiphy(hw->wiphy); |
| 8198 |
|
| 8199 |
if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) |
| 8200 |
return -EINVAL; |
| 8201 |
|
| 8202 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 8203 |
if (!arvif || !arvif->is_created) { |
| 8204 |
cache = ath12k_ahvif_get_link_cache(ahvif, link_id); |
| 8205 |
if (!cache) |
| 8206 |
return -ENOSPC; |
| 8207 |
|
| 8208 |
cache->tx_conf.changed = true; |
| 8209 |
cache->tx_conf.ac = ac; |
| 8210 |
cache->tx_conf.tx_queue_params = *params; |
| 8211 |
|
| 8212 |
return 0; |
| 8213 |
} |
| 8214 |
|
| 8215 |
ret = ath12k_mac_conf_tx(arvif, ac, params); |
| 8216 |
|
| 8217 |
return ret; |
| 8218 |
} |
| 8219 |
EXPORT_SYMBOL(ath12k_mac_op_conf_tx); |
| 8220 |
|
| 8221 |
static struct ieee80211_sta_ht_cap |
| 8222 |
ath12k_create_ht_cap(struct ath12k *ar, u32 ar_ht_cap, u32 rate_cap_rx_chainmask) |
| 8223 |
{ |
| 8224 |
int i; |
| 8225 |
struct ieee80211_sta_ht_cap ht_cap = {}; |
| 8226 |
u32 ar_vht_cap = ar->pdev->cap.vht_cap; |
| 8227 |
|
| 8228 |
if (!(ar_ht_cap & WMI_HT_CAP_ENABLED)) |
| 8229 |
return ht_cap; |
| 8230 |
|
| 8231 |
ht_cap.ht_supported = 1; |
| 8232 |
ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 8233 |
ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; |
| 8234 |
ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 8235 |
ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; |
| 8236 |
ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 8237 |
|
| 8238 |
if (ar_ht_cap & WMI_HT_CAP_HT20_SGI) |
| 8239 |
ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
| 8240 |
|
| 8241 |
if (ar_ht_cap & WMI_HT_CAP_HT40_SGI) |
| 8242 |
ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
| 8243 |
|
| 8244 |
if (ar_ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) { |
| 8245 |
u32 smps; |
| 8246 |
|
| 8247 |
smps = WLAN_HT_CAP_SM_PS_DYNAMIC; |
| 8248 |
smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 8249 |
|
| 8250 |
ht_cap.cap |= smps; |
| 8251 |
} |
| 8252 |
|
| 8253 |
if (ar_ht_cap & WMI_HT_CAP_TX_STBC) |
| 8254 |
ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; |
| 8255 |
|
| 8256 |
if (ar_ht_cap & WMI_HT_CAP_RX_STBC) { |
| 8257 |
u32 stbc; |
| 8258 |
|
| 8259 |
stbc = ar_ht_cap; |
| 8260 |
stbc &= WMI_HT_CAP_RX_STBC; |
| 8261 |
stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; |
| 8262 |
stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 8263 |
stbc &= IEEE80211_HT_CAP_RX_STBC; |
| 8264 |
|
| 8265 |
ht_cap.cap |= stbc; |
| 8266 |
} |
| 8267 |
|
| 8268 |
if (ar_ht_cap & WMI_HT_CAP_RX_LDPC) |
| 8269 |
ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; |
| 8270 |
|
| 8271 |
if (ar_ht_cap & WMI_HT_CAP_L_SIG_TXOP_PROT) |
| 8272 |
ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; |
| 8273 |
|
| 8274 |
if (ar_vht_cap & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) |
| 8275 |
ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; |
| 8276 |
|
| 8277 |
for (i = 0; i < ar->num_rx_chains; i++) { |
| 8278 |
if (rate_cap_rx_chainmask & BIT(i)) |
| 8279 |
ht_cap.mcs.rx_mask[i] = 0xFF; |
| 8280 |
} |
| 8281 |
|
| 8282 |
ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; |
| 8283 |
|
| 8284 |
return ht_cap; |
| 8285 |
} |
| 8286 |
|
| 8287 |
static int ath12k_mac_set_txbf_conf(struct ath12k_link_vif *arvif) |
| 8288 |
{ |
| 8289 |
u32 value = 0; |
| 8290 |
struct ath12k *ar = arvif->ar; |
| 8291 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 8292 |
int nsts; |
| 8293 |
int sound_dim; |
| 8294 |
u32 vht_cap = ar->pdev->cap.vht_cap; |
| 8295 |
u32 vdev_param = WMI_VDEV_PARAM_TXBF; |
| 8296 |
|
| 8297 |
if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) { |
| 8298 |
nsts = vht_cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; |
| 8299 |
nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; |
| 8300 |
value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET); |
| 8301 |
} |
| 8302 |
|
| 8303 |
if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) { |
| 8304 |
sound_dim = vht_cap & |
| 8305 |
IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; |
| 8306 |
sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; |
| 8307 |
if (sound_dim > (ar->num_tx_chains - 1)) |
| 8308 |
sound_dim = ar->num_tx_chains - 1; |
| 8309 |
value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET); |
| 8310 |
} |
| 8311 |
|
| 8312 |
if (!value) |
| 8313 |
return 0; |
| 8314 |
|
| 8315 |
if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) { |
| 8316 |
value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; |
| 8317 |
|
| 8318 |
if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) && |
| 8319 |
ahvif->vdev_type == WMI_VDEV_TYPE_AP) |
| 8320 |
value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER; |
| 8321 |
} |
| 8322 |
|
| 8323 |
if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) { |
| 8324 |
value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; |
| 8325 |
|
| 8326 |
if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) && |
| 8327 |
ahvif->vdev_type == WMI_VDEV_TYPE_STA) |
| 8328 |
value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE; |
| 8329 |
} |
| 8330 |
|
| 8331 |
return ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 8332 |
vdev_param, value); |
| 8333 |
} |
| 8334 |
|
| 8335 |
static void ath12k_set_vht_txbf_cap(struct ath12k *ar, u32 *vht_cap) |
| 8336 |
{ |
| 8337 |
bool subfer, subfee; |
| 8338 |
int sound_dim = 0; |
| 8339 |
|
| 8340 |
subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)); |
| 8341 |
subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)); |
| 8342 |
|
| 8343 |
if (ar->num_tx_chains < 2) { |
| 8344 |
*vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE); |
| 8345 |
subfer = false; |
| 8346 |
} |
| 8347 |
|
| 8348 |
/* If SU Beaformer is not set, then disable MU Beamformer Capability */ |
| 8349 |
if (!subfer) |
| 8350 |
*vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE); |
| 8351 |
|
| 8352 |
/* If SU Beaformee is not set, then disable MU Beamformee Capability */ |
| 8353 |
if (!subfee) |
| 8354 |
*vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); |
| 8355 |
|
| 8356 |
sound_dim = u32_get_bits(*vht_cap, |
| 8357 |
IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); |
| 8358 |
*vht_cap = u32_replace_bits(*vht_cap, 0, |
| 8359 |
IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); |
| 8360 |
|
| 8361 |
/* TODO: Need to check invalid STS and Sound_dim values set by FW? */ |
| 8362 |
|
| 8363 |
/* Enable Sounding Dimension Field only if SU BF is enabled */ |
| 8364 |
if (subfer) { |
| 8365 |
if (sound_dim > (ar->num_tx_chains - 1)) |
| 8366 |
sound_dim = ar->num_tx_chains - 1; |
| 8367 |
|
| 8368 |
*vht_cap = u32_replace_bits(*vht_cap, sound_dim, |
| 8369 |
IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); |
| 8370 |
} |
| 8371 |
|
| 8372 |
/* Use the STS advertised by FW unless SU Beamformee is not supported*/ |
| 8373 |
if (!subfee) |
| 8374 |
*vht_cap &= ~(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK); |
| 8375 |
} |
| 8376 |
|
| 8377 |
static struct ieee80211_sta_vht_cap |
| 8378 |
ath12k_create_vht_cap(struct ath12k *ar, u32 rate_cap_tx_chainmask, |
| 8379 |
u32 rate_cap_rx_chainmask) |
| 8380 |
{ |
| 8381 |
struct ieee80211_sta_vht_cap vht_cap = {}; |
| 8382 |
u16 txmcs_map, rxmcs_map; |
| 8383 |
int i; |
| 8384 |
|
| 8385 |
vht_cap.vht_supported = 1; |
| 8386 |
vht_cap.cap = ar->pdev->cap.vht_cap; |
| 8387 |
|
| 8388 |
ath12k_set_vht_txbf_cap(ar, &vht_cap.cap); |
| 8389 |
|
| 8390 |
/* 80P80 is not supported */ |
| 8391 |
vht_cap.cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; |
| 8392 |
|
| 8393 |
rxmcs_map = 0; |
| 8394 |
txmcs_map = 0; |
| 8395 |
for (i = 0; i < 8; i++) { |
| 8396 |
if (i < ar->num_tx_chains && rate_cap_tx_chainmask & BIT(i)) |
| 8397 |
txmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); |
| 8398 |
else |
| 8399 |
txmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); |
| 8400 |
|
| 8401 |
if (i < ar->num_rx_chains && rate_cap_rx_chainmask & BIT(i)) |
| 8402 |
rxmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); |
| 8403 |
else |
| 8404 |
rxmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); |
| 8405 |
} |
| 8406 |
|
| 8407 |
if (rate_cap_tx_chainmask <= 1) |
| 8408 |
vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC; |
| 8409 |
|
| 8410 |
vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_map); |
| 8411 |
vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_map); |
| 8412 |
|
| 8413 |
/* Check if the HW supports 1:1 NSS ratio and reset |
| 8414 |
* EXT NSS BW Support field to 0 to indicate 1:1 ratio |
| 8415 |
*/ |
| 8416 |
if (ar->pdev->cap.nss_ratio_info == WMI_NSS_RATIO_1_NSS) |
| 8417 |
vht_cap.cap &= ~IEEE80211_VHT_CAP_EXT_NSS_BW_MASK; |
| 8418 |
|
| 8419 |
return vht_cap; |
| 8420 |
} |
| 8421 |
|
| 8422 |
static void ath12k_mac_setup_ht_vht_cap(struct ath12k *ar, |
| 8423 |
struct ath12k_pdev_cap *cap, |
| 8424 |
u32 *ht_cap_info) |
| 8425 |
{ |
| 8426 |
struct ieee80211_supported_band *band; |
| 8427 |
u32 rate_cap_tx_chainmask; |
| 8428 |
u32 rate_cap_rx_chainmask; |
| 8429 |
u32 ht_cap; |
| 8430 |
|
| 8431 |
rate_cap_tx_chainmask = ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift; |
| 8432 |
rate_cap_rx_chainmask = ar->cfg_rx_chainmask >> cap->rx_chain_mask_shift; |
| 8433 |
|
| 8434 |
if (cap->supported_bands & WMI_HOST_WLAN_2GHZ_CAP) { |
| 8435 |
band = &ar->mac.sbands[NL80211_BAND_2GHZ]; |
| 8436 |
ht_cap = cap->band[NL80211_BAND_2GHZ].ht_cap_info; |
| 8437 |
if (ht_cap_info) |
| 8438 |
*ht_cap_info = ht_cap; |
| 8439 |
band->ht_cap = ath12k_create_ht_cap(ar, ht_cap, |
| 8440 |
rate_cap_rx_chainmask); |
| 8441 |
} |
| 8442 |
|
| 8443 |
if (cap->supported_bands & WMI_HOST_WLAN_5GHZ_CAP && |
| 8444 |
(ar->ab->hw_params->single_pdev_only || |
| 8445 |
!ar->supports_6ghz)) { |
| 8446 |
band = &ar->mac.sbands[NL80211_BAND_5GHZ]; |
| 8447 |
ht_cap = cap->band[NL80211_BAND_5GHZ].ht_cap_info; |
| 8448 |
if (ht_cap_info) |
| 8449 |
*ht_cap_info = ht_cap; |
| 8450 |
band->ht_cap = ath12k_create_ht_cap(ar, ht_cap, |
| 8451 |
rate_cap_rx_chainmask); |
| 8452 |
band->vht_cap = ath12k_create_vht_cap(ar, rate_cap_tx_chainmask, |
| 8453 |
rate_cap_rx_chainmask); |
| 8454 |
} |
| 8455 |
} |
| 8456 |
|
| 8457 |
static int ath12k_check_chain_mask(struct ath12k *ar, u32 ant, bool is_tx_ant) |
| 8458 |
{ |
| 8459 |
/* TODO: Check the request chainmask against the supported |
| 8460 |
* chainmask table which is advertised in extented_service_ready event |
| 8461 |
*/ |
| 8462 |
|
| 8463 |
return 0; |
| 8464 |
} |
| 8465 |
|
| 8466 |
static void ath12k_gen_ppe_thresh(struct ath12k_wmi_ppe_threshold_arg *fw_ppet, |
| 8467 |
u8 *he_ppet) |
| 8468 |
{ |
| 8469 |
int nss, ru; |
| 8470 |
u8 bit = 7; |
| 8471 |
|
| 8472 |
he_ppet[0] = fw_ppet->numss_m1 & IEEE80211_PPE_THRES_NSS_MASK; |
| 8473 |
he_ppet[0] |= (fw_ppet->ru_bit_mask << |
| 8474 |
IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS) & |
| 8475 |
IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK; |
| 8476 |
for (nss = 0; nss <= fw_ppet->numss_m1; nss++) { |
| 8477 |
for (ru = 0; ru < 4; ru++) { |
| 8478 |
u8 val; |
| 8479 |
int i; |
| 8480 |
|
| 8481 |
if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0) |
| 8482 |
continue; |
| 8483 |
val = (fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> (ru * 6)) & |
| 8484 |
0x3f; |
| 8485 |
val = ((val >> 3) & 0x7) | ((val & 0x7) << 3); |
| 8486 |
for (i = 5; i >= 0; i--) { |
| 8487 |
he_ppet[bit / 8] |= |
| 8488 |
((val >> i) & 0x1) << ((bit % 8)); |
| 8489 |
bit++; |
| 8490 |
} |
| 8491 |
} |
| 8492 |
} |
| 8493 |
} |
| 8494 |
|
| 8495 |
static void |
| 8496 |
ath12k_mac_filter_he_cap_mesh(struct ieee80211_he_cap_elem *he_cap_elem) |
| 8497 |
{ |
| 8498 |
u8 m; |
| 8499 |
|
| 8500 |
m = IEEE80211_HE_MAC_CAP0_TWT_RES | |
| 8501 |
IEEE80211_HE_MAC_CAP0_TWT_REQ; |
| 8502 |
he_cap_elem->mac_cap_info[0] &= ~m; |
| 8503 |
|
| 8504 |
m = IEEE80211_HE_MAC_CAP2_TRS | |
| 8505 |
IEEE80211_HE_MAC_CAP2_BCAST_TWT | |
| 8506 |
IEEE80211_HE_MAC_CAP2_MU_CASCADING; |
| 8507 |
he_cap_elem->mac_cap_info[2] &= ~m; |
| 8508 |
|
| 8509 |
m = IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED | |
| 8510 |
IEEE80211_HE_MAC_CAP2_BCAST_TWT | |
| 8511 |
IEEE80211_HE_MAC_CAP2_MU_CASCADING; |
| 8512 |
he_cap_elem->mac_cap_info[3] &= ~m; |
| 8513 |
|
| 8514 |
m = IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG | |
| 8515 |
IEEE80211_HE_MAC_CAP4_BQR; |
| 8516 |
he_cap_elem->mac_cap_info[4] &= ~m; |
| 8517 |
|
| 8518 |
m = IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECTIVE_TRANSMISSION | |
| 8519 |
IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU | |
| 8520 |
IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING | |
| 8521 |
IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX; |
| 8522 |
he_cap_elem->mac_cap_info[5] &= ~m; |
| 8523 |
|
| 8524 |
m = IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | |
| 8525 |
IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO; |
| 8526 |
he_cap_elem->phy_cap_info[2] &= ~m; |
| 8527 |
|
| 8528 |
m = IEEE80211_HE_PHY_CAP3_RX_PARTIAL_BW_SU_IN_20MHZ_MU | |
| 8529 |
IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK | |
| 8530 |
IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK; |
| 8531 |
he_cap_elem->phy_cap_info[3] &= ~m; |
| 8532 |
|
| 8533 |
m = IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER; |
| 8534 |
he_cap_elem->phy_cap_info[4] &= ~m; |
| 8535 |
|
| 8536 |
m = IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK; |
| 8537 |
he_cap_elem->phy_cap_info[5] &= ~m; |
| 8538 |
|
| 8539 |
m = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU | |
| 8540 |
IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB | |
| 8541 |
IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB | |
| 8542 |
IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO; |
| 8543 |
he_cap_elem->phy_cap_info[6] &= ~m; |
| 8544 |
|
| 8545 |
m = IEEE80211_HE_PHY_CAP7_PSR_BASED_SR | |
| 8546 |
IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP | |
| 8547 |
IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ | |
| 8548 |
IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ; |
| 8549 |
he_cap_elem->phy_cap_info[7] &= ~m; |
| 8550 |
|
| 8551 |
m = IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI | |
| 8552 |
IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G | |
| 8553 |
IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU | |
| 8554 |
IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU; |
| 8555 |
he_cap_elem->phy_cap_info[8] &= ~m; |
| 8556 |
|
| 8557 |
m = IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM | |
| 8558 |
IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK | |
| 8559 |
IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU | |
| 8560 |
IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU | |
| 8561 |
IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB | |
| 8562 |
IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB; |
| 8563 |
he_cap_elem->phy_cap_info[9] &= ~m; |
| 8564 |
} |
| 8565 |
|
| 8566 |
static __le16 ath12k_mac_setup_he_6ghz_cap(struct ath12k_pdev_cap *pcap, |
| 8567 |
struct ath12k_band_cap *bcap) |
| 8568 |
{ |
| 8569 |
u8 val; |
| 8570 |
|
| 8571 |
bcap->he_6ghz_capa = IEEE80211_HT_MPDU_DENSITY_NONE; |
| 8572 |
if (bcap->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) |
| 8573 |
bcap->he_6ghz_capa |= |
| 8574 |
u32_encode_bits(WLAN_HT_CAP_SM_PS_DYNAMIC, |
| 8575 |
IEEE80211_HE_6GHZ_CAP_SM_PS); |
| 8576 |
else |
| 8577 |
bcap->he_6ghz_capa |= |
| 8578 |
u32_encode_bits(WLAN_HT_CAP_SM_PS_DISABLED, |
| 8579 |
IEEE80211_HE_6GHZ_CAP_SM_PS); |
| 8580 |
val = u32_get_bits(pcap->vht_cap, |
| 8581 |
IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK); |
| 8582 |
bcap->he_6ghz_capa |= |
| 8583 |
u32_encode_bits(val, IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP); |
| 8584 |
val = u32_get_bits(pcap->vht_cap, |
| 8585 |
IEEE80211_VHT_CAP_MAX_MPDU_MASK); |
| 8586 |
bcap->he_6ghz_capa |= |
| 8587 |
u32_encode_bits(val, IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN); |
| 8588 |
if (pcap->vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN) |
| 8589 |
bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS; |
| 8590 |
if (pcap->vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN) |
| 8591 |
bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS; |
| 8592 |
|
| 8593 |
return cpu_to_le16(bcap->he_6ghz_capa); |
| 8594 |
} |
| 8595 |
|
| 8596 |
static void ath12k_mac_set_hemcsmap(struct ath12k *ar, |
| 8597 |
struct ath12k_pdev_cap *cap, |
| 8598 |
struct ieee80211_sta_he_cap *he_cap) |
| 8599 |
{ |
| 8600 |
struct ieee80211_he_mcs_nss_supp *mcs_nss = &he_cap->he_mcs_nss_supp; |
| 8601 |
u8 maxtxnss_160 = ath12k_get_nss_160mhz(ar, ar->num_tx_chains); |
| 8602 |
u8 maxrxnss_160 = ath12k_get_nss_160mhz(ar, ar->num_rx_chains); |
| 8603 |
u16 txmcs_map_160 = 0, rxmcs_map_160 = 0; |
| 8604 |
u16 txmcs_map = 0, rxmcs_map = 0; |
| 8605 |
u32 i; |
| 8606 |
|
| 8607 |
for (i = 0; i < 8; i++) { |
| 8608 |
if (i < ar->num_tx_chains && |
| 8609 |
(ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift) & BIT(i)) |
| 8610 |
txmcs_map |= IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2); |
| 8611 |
else |
| 8612 |
txmcs_map |= IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2); |
| 8613 |
|
| 8614 |
if (i < ar->num_rx_chains && |
| 8615 |
(ar->cfg_rx_chainmask >> cap->tx_chain_mask_shift) & BIT(i)) |
| 8616 |
rxmcs_map |= IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2); |
| 8617 |
else |
| 8618 |
rxmcs_map |= IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2); |
| 8619 |
|
| 8620 |
if (i < maxtxnss_160 && |
| 8621 |
(ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift) & BIT(i)) |
| 8622 |
txmcs_map_160 |= IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2); |
| 8623 |
else |
| 8624 |
txmcs_map_160 |= IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2); |
| 8625 |
|
| 8626 |
if (i < maxrxnss_160 && |
| 8627 |
(ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift) & BIT(i)) |
| 8628 |
rxmcs_map_160 |= IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2); |
| 8629 |
else |
| 8630 |
rxmcs_map_160 |= IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2); |
| 8631 |
} |
| 8632 |
|
| 8633 |
mcs_nss->rx_mcs_80 = cpu_to_le16(rxmcs_map & 0xffff); |
| 8634 |
mcs_nss->tx_mcs_80 = cpu_to_le16(txmcs_map & 0xffff); |
| 8635 |
mcs_nss->rx_mcs_160 = cpu_to_le16(rxmcs_map_160 & 0xffff); |
| 8636 |
mcs_nss->tx_mcs_160 = cpu_to_le16(txmcs_map_160 & 0xffff); |
| 8637 |
} |
| 8638 |
|
| 8639 |
static void ath12k_mac_copy_he_cap(struct ath12k *ar, |
| 8640 |
struct ath12k_band_cap *band_cap, |
| 8641 |
int iftype, u8 num_tx_chains, |
| 8642 |
struct ieee80211_sta_he_cap *he_cap) |
| 8643 |
{ |
| 8644 |
struct ieee80211_he_cap_elem *he_cap_elem = &he_cap->he_cap_elem; |
| 8645 |
|
| 8646 |
he_cap->has_he = true; |
| 8647 |
memcpy(he_cap_elem->mac_cap_info, band_cap->he_cap_info, |
| 8648 |
sizeof(he_cap_elem->mac_cap_info)); |
| 8649 |
memcpy(he_cap_elem->phy_cap_info, band_cap->he_cap_phy_info, |
| 8650 |
sizeof(he_cap_elem->phy_cap_info)); |
| 8651 |
|
| 8652 |
he_cap_elem->mac_cap_info[1] &= |
| 8653 |
IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK; |
| 8654 |
he_cap_elem->phy_cap_info[0] &= |
| 8655 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G | |
| 8656 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | |
| 8657 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G; |
| 8658 |
/* 80PLUS80 is not supported */ |
| 8659 |
he_cap_elem->phy_cap_info[0] &= |
| 8660 |
~IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G; |
| 8661 |
he_cap_elem->phy_cap_info[5] &= |
| 8662 |
~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK; |
| 8663 |
he_cap_elem->phy_cap_info[5] |= num_tx_chains - 1; |
| 8664 |
|
| 8665 |
switch (iftype) { |
| 8666 |
case NL80211_IFTYPE_AP: |
| 8667 |
he_cap_elem->mac_cap_info[2] &= |
| 8668 |
~IEEE80211_HE_MAC_CAP2_BCAST_TWT; |
| 8669 |
he_cap_elem->phy_cap_info[3] &= |
| 8670 |
~IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK; |
| 8671 |
he_cap_elem->phy_cap_info[9] |= |
| 8672 |
IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU; |
| 8673 |
break; |
| 8674 |
case NL80211_IFTYPE_STATION: |
| 8675 |
he_cap_elem->mac_cap_info[0] &= ~IEEE80211_HE_MAC_CAP0_TWT_RES; |
| 8676 |
he_cap_elem->mac_cap_info[0] |= IEEE80211_HE_MAC_CAP0_TWT_REQ; |
| 8677 |
he_cap_elem->phy_cap_info[9] |= |
| 8678 |
IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU; |
| 8679 |
break; |
| 8680 |
case NL80211_IFTYPE_MESH_POINT: |
| 8681 |
ath12k_mac_filter_he_cap_mesh(he_cap_elem); |
| 8682 |
break; |
| 8683 |
} |
| 8684 |
|
| 8685 |
ath12k_mac_set_hemcsmap(ar, &ar->pdev->cap, he_cap); |
| 8686 |
memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres)); |
| 8687 |
if (he_cap_elem->phy_cap_info[6] & |
| 8688 |
IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) |
| 8689 |
ath12k_gen_ppe_thresh(&band_cap->he_ppet, he_cap->ppe_thres); |
| 8690 |
} |
| 8691 |
|
| 8692 |
static void |
| 8693 |
ath12k_mac_copy_eht_mcs_nss(struct ath12k_band_cap *band_cap, |
| 8694 |
struct ieee80211_eht_mcs_nss_supp *mcs_nss, |
| 8695 |
const struct ieee80211_he_cap_elem *he_cap, |
| 8696 |
const struct ieee80211_eht_cap_elem_fixed *eht_cap) |
| 8697 |
{ |
| 8698 |
if ((he_cap->phy_cap_info[0] & |
| 8699 |
(IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G | |
| 8700 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | |
| 8701 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | |
| 8702 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)) == 0) |
| 8703 |
memcpy(&mcs_nss->only_20mhz, &band_cap->eht_mcs_20_only, |
| 8704 |
sizeof(struct ieee80211_eht_mcs_nss_supp_20mhz_only)); |
| 8705 |
|
| 8706 |
if (he_cap->phy_cap_info[0] & |
| 8707 |
(IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G | |
| 8708 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G)) |
| 8709 |
memcpy(&mcs_nss->bw._80, &band_cap->eht_mcs_80, |
| 8710 |
sizeof(struct ieee80211_eht_mcs_nss_supp_bw)); |
| 8711 |
|
| 8712 |
if (he_cap->phy_cap_info[0] & |
| 8713 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) |
| 8714 |
memcpy(&mcs_nss->bw._160, &band_cap->eht_mcs_160, |
| 8715 |
sizeof(struct ieee80211_eht_mcs_nss_supp_bw)); |
| 8716 |
|
| 8717 |
if (eht_cap->phy_cap_info[0] & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ) |
| 8718 |
memcpy(&mcs_nss->bw._320, &band_cap->eht_mcs_320, |
| 8719 |
sizeof(struct ieee80211_eht_mcs_nss_supp_bw)); |
| 8720 |
} |
| 8721 |
|
| 8722 |
static void ath12k_mac_copy_eht_ppe_thresh(struct ath12k_wmi_ppe_threshold_arg *fw_ppet, |
| 8723 |
struct ieee80211_sta_eht_cap *cap) |
| 8724 |
{ |
| 8725 |
u16 bit = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE; |
| 8726 |
u8 i, nss, ru, ppet_bit_len_per_ru = IEEE80211_EHT_PPE_THRES_INFO_PPET_SIZE * 2; |
| 8727 |
|
| 8728 |
u8p_replace_bits(&cap->eht_ppe_thres[0], fw_ppet->numss_m1, |
| 8729 |
IEEE80211_EHT_PPE_THRES_NSS_MASK); |
| 8730 |
|
| 8731 |
u16p_replace_bits((u16 *)&cap->eht_ppe_thres[0], fw_ppet->ru_bit_mask, |
| 8732 |
IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); |
| 8733 |
|
| 8734 |
for (nss = 0; nss <= fw_ppet->numss_m1; nss++) { |
| 8735 |
for (ru = 0; |
| 8736 |
ru < hweight16(IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); |
| 8737 |
ru++) { |
| 8738 |
u32 val = 0; |
| 8739 |
|
| 8740 |
if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0) |
| 8741 |
continue; |
| 8742 |
|
| 8743 |
u32p_replace_bits(&val, fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> |
| 8744 |
(ru * ppet_bit_len_per_ru), |
| 8745 |
GENMASK(ppet_bit_len_per_ru - 1, 0)); |
| 8746 |
|
| 8747 |
for (i = 0; i < ppet_bit_len_per_ru; i++) { |
| 8748 |
cap->eht_ppe_thres[bit / 8] |= |
| 8749 |
(((val >> i) & 0x1) << ((bit % 8))); |
| 8750 |
bit++; |
| 8751 |
} |
| 8752 |
} |
| 8753 |
} |
| 8754 |
} |
| 8755 |
|
| 8756 |
static void |
| 8757 |
ath12k_mac_filter_eht_cap_mesh(struct ieee80211_eht_cap_elem_fixed |
| 8758 |
*eht_cap_elem) |
| 8759 |
{ |
| 8760 |
u8 m; |
| 8761 |
|
| 8762 |
m = IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS; |
| 8763 |
eht_cap_elem->mac_cap_info[0] &= ~m; |
| 8764 |
|
| 8765 |
m = IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO; |
| 8766 |
eht_cap_elem->phy_cap_info[0] &= ~m; |
| 8767 |
|
| 8768 |
m = IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK | |
| 8769 |
IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK | |
| 8770 |
IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK | |
| 8771 |
IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK; |
| 8772 |
eht_cap_elem->phy_cap_info[3] &= ~m; |
| 8773 |
|
| 8774 |
m = IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO | |
| 8775 |
IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP | |
| 8776 |
IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP | |
| 8777 |
IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI; |
| 8778 |
eht_cap_elem->phy_cap_info[4] &= ~m; |
| 8779 |
|
| 8780 |
m = IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK | |
| 8781 |
IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP | |
| 8782 |
IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP | |
| 8783 |
IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK; |
| 8784 |
eht_cap_elem->phy_cap_info[5] &= ~m; |
| 8785 |
|
| 8786 |
m = IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK; |
| 8787 |
eht_cap_elem->phy_cap_info[6] &= ~m; |
| 8788 |
|
| 8789 |
m = IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ | |
| 8790 |
IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ | |
| 8791 |
IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ | |
| 8792 |
IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | |
| 8793 |
IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ | |
| 8794 |
IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ; |
| 8795 |
eht_cap_elem->phy_cap_info[7] &= ~m; |
| 8796 |
} |
| 8797 |
|
| 8798 |
static void ath12k_mac_copy_eht_cap(struct ath12k *ar, |
| 8799 |
struct ath12k_band_cap *band_cap, |
| 8800 |
struct ieee80211_he_cap_elem *he_cap_elem, |
| 8801 |
int iftype, |
| 8802 |
struct ieee80211_sta_eht_cap *eht_cap) |
| 8803 |
{ |
| 8804 |
struct ieee80211_eht_cap_elem_fixed *eht_cap_elem = &eht_cap->eht_cap_elem; |
| 8805 |
|
| 8806 |
memset(eht_cap, 0, sizeof(struct ieee80211_sta_eht_cap)); |
| 8807 |
|
| 8808 |
if (!(test_bit(WMI_TLV_SERVICE_11BE, ar->ab->wmi_ab.svc_map)) || |
| 8809 |
ath12k_acpi_get_disable_11be(ar->ab)) |
| 8810 |
return; |
| 8811 |
|
| 8812 |
eht_cap->has_eht = true; |
| 8813 |
memcpy(eht_cap_elem->mac_cap_info, band_cap->eht_cap_mac_info, |
| 8814 |
sizeof(eht_cap_elem->mac_cap_info)); |
| 8815 |
memcpy(eht_cap_elem->phy_cap_info, band_cap->eht_cap_phy_info, |
| 8816 |
sizeof(eht_cap_elem->phy_cap_info)); |
| 8817 |
|
| 8818 |
switch (iftype) { |
| 8819 |
case NL80211_IFTYPE_AP: |
| 8820 |
eht_cap_elem->phy_cap_info[0] &= |
| 8821 |
~IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ; |
| 8822 |
eht_cap_elem->phy_cap_info[4] &= |
| 8823 |
~IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO; |
| 8824 |
eht_cap_elem->phy_cap_info[5] &= |
| 8825 |
~IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP; |
| 8826 |
break; |
| 8827 |
case NL80211_IFTYPE_STATION: |
| 8828 |
eht_cap_elem->phy_cap_info[7] &= |
| 8829 |
~(IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ | |
| 8830 |
IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ | |
| 8831 |
IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ); |
| 8832 |
eht_cap_elem->phy_cap_info[7] &= |
| 8833 |
~(IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | |
| 8834 |
IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ | |
| 8835 |
IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ); |
| 8836 |
break; |
| 8837 |
case NL80211_IFTYPE_MESH_POINT: |
| 8838 |
ath12k_mac_filter_eht_cap_mesh(eht_cap_elem); |
| 8839 |
break; |
| 8840 |
default: |
| 8841 |
break; |
| 8842 |
} |
| 8843 |
|
| 8844 |
ath12k_mac_copy_eht_mcs_nss(band_cap, &eht_cap->eht_mcs_nss_supp, |
| 8845 |
he_cap_elem, eht_cap_elem); |
| 8846 |
|
| 8847 |
if (eht_cap_elem->phy_cap_info[5] & |
| 8848 |
IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) |
| 8849 |
ath12k_mac_copy_eht_ppe_thresh(&band_cap->eht_ppet, eht_cap); |
| 8850 |
} |
| 8851 |
|
| 8852 |
static int ath12k_mac_copy_sband_iftype_data(struct ath12k *ar, |
| 8853 |
struct ath12k_pdev_cap *cap, |
| 8854 |
struct ieee80211_sband_iftype_data *data, |
| 8855 |
int band) |
| 8856 |
{ |
| 8857 |
struct ath12k_band_cap *band_cap = &cap->band[band]; |
| 8858 |
int i, idx = 0; |
| 8859 |
|
| 8860 |
for (i = 0; i < NUM_NL80211_IFTYPES; i++) { |
| 8861 |
struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap; |
| 8862 |
|
| 8863 |
switch (i) { |
| 8864 |
case NL80211_IFTYPE_STATION: |
| 8865 |
case NL80211_IFTYPE_AP: |
| 8866 |
case NL80211_IFTYPE_MESH_POINT: |
| 8867 |
break; |
| 8868 |
|
| 8869 |
default: |
| 8870 |
continue; |
| 8871 |
} |
| 8872 |
|
| 8873 |
data[idx].types_mask = BIT(i); |
| 8874 |
|
| 8875 |
ath12k_mac_copy_he_cap(ar, band_cap, i, ar->num_tx_chains, he_cap); |
| 8876 |
if (band == NL80211_BAND_6GHZ) { |
| 8877 |
data[idx].he_6ghz_capa.capa = |
| 8878 |
ath12k_mac_setup_he_6ghz_cap(cap, band_cap); |
| 8879 |
} |
| 8880 |
ath12k_mac_copy_eht_cap(ar, band_cap, &he_cap->he_cap_elem, i, |
| 8881 |
&data[idx].eht_cap); |
| 8882 |
idx++; |
| 8883 |
} |
| 8884 |
|
| 8885 |
return idx; |
| 8886 |
} |
| 8887 |
|
| 8888 |
static void ath12k_mac_setup_sband_iftype_data(struct ath12k *ar, |
| 8889 |
struct ath12k_pdev_cap *cap) |
| 8890 |
{ |
| 8891 |
struct ieee80211_supported_band *sband; |
| 8892 |
enum nl80211_band band; |
| 8893 |
int count; |
| 8894 |
|
| 8895 |
if (cap->supported_bands & WMI_HOST_WLAN_2GHZ_CAP) { |
| 8896 |
band = NL80211_BAND_2GHZ; |
| 8897 |
count = ath12k_mac_copy_sband_iftype_data(ar, cap, |
| 8898 |
ar->mac.iftype[band], |
| 8899 |
band); |
| 8900 |
sband = &ar->mac.sbands[band]; |
| 8901 |
_ieee80211_set_sband_iftype_data(sband, ar->mac.iftype[band], |
| 8902 |
count); |
| 8903 |
} |
| 8904 |
|
| 8905 |
if (cap->supported_bands & WMI_HOST_WLAN_5GHZ_CAP) { |
| 8906 |
band = NL80211_BAND_5GHZ; |
| 8907 |
count = ath12k_mac_copy_sband_iftype_data(ar, cap, |
| 8908 |
ar->mac.iftype[band], |
| 8909 |
band); |
| 8910 |
sband = &ar->mac.sbands[band]; |
| 8911 |
_ieee80211_set_sband_iftype_data(sband, ar->mac.iftype[band], |
| 8912 |
count); |
| 8913 |
} |
| 8914 |
|
| 8915 |
if (cap->supported_bands & WMI_HOST_WLAN_5GHZ_CAP && |
| 8916 |
ar->supports_6ghz) { |
| 8917 |
band = NL80211_BAND_6GHZ; |
| 8918 |
count = ath12k_mac_copy_sband_iftype_data(ar, cap, |
| 8919 |
ar->mac.iftype[band], |
| 8920 |
band); |
| 8921 |
sband = &ar->mac.sbands[band]; |
| 8922 |
_ieee80211_set_sband_iftype_data(sband, ar->mac.iftype[band], |
| 8923 |
count); |
| 8924 |
} |
| 8925 |
} |
| 8926 |
|
| 8927 |
static int __ath12k_set_antenna(struct ath12k *ar, u32 tx_ant, u32 rx_ant) |
| 8928 |
{ |
| 8929 |
struct ath12k_hw *ah = ath12k_ar_to_ah(ar); |
| 8930 |
int ret; |
| 8931 |
|
| 8932 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 8933 |
|
| 8934 |
if (ath12k_check_chain_mask(ar, tx_ant, true)) |
| 8935 |
return -EINVAL; |
| 8936 |
|
| 8937 |
if (ath12k_check_chain_mask(ar, rx_ant, false)) |
| 8938 |
return -EINVAL; |
| 8939 |
|
| 8940 |
/* Since we advertised the max cap of all radios combined during wiphy |
| 8941 |
* registration, ensure we don't set the antenna config higher than the |
| 8942 |
* limits |
| 8943 |
*/ |
| 8944 |
tx_ant = min_t(u32, tx_ant, ar->pdev->cap.tx_chain_mask); |
| 8945 |
rx_ant = min_t(u32, rx_ant, ar->pdev->cap.rx_chain_mask); |
| 8946 |
|
| 8947 |
ar->cfg_tx_chainmask = tx_ant; |
| 8948 |
ar->cfg_rx_chainmask = rx_ant; |
| 8949 |
|
| 8950 |
if (ah->state != ATH12K_HW_STATE_ON && |
| 8951 |
ah->state != ATH12K_HW_STATE_RESTARTED) |
| 8952 |
return 0; |
| 8953 |
|
| 8954 |
ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_TX_CHAIN_MASK, |
| 8955 |
tx_ant, ar->pdev->pdev_id); |
| 8956 |
if (ret) { |
| 8957 |
ath12k_warn(ar->ab, "failed to set tx-chainmask: %d, req 0x%x\n", |
| 8958 |
ret, tx_ant); |
| 8959 |
return ret; |
| 8960 |
} |
| 8961 |
|
| 8962 |
ar->num_tx_chains = hweight32(tx_ant); |
| 8963 |
|
| 8964 |
ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RX_CHAIN_MASK, |
| 8965 |
rx_ant, ar->pdev->pdev_id); |
| 8966 |
if (ret) { |
| 8967 |
ath12k_warn(ar->ab, "failed to set rx-chainmask: %d, req 0x%x\n", |
| 8968 |
ret, rx_ant); |
| 8969 |
return ret; |
| 8970 |
} |
| 8971 |
|
| 8972 |
ar->num_rx_chains = hweight32(rx_ant); |
| 8973 |
|
| 8974 |
/* Reload HT/VHT/HE capability */ |
| 8975 |
ath12k_mac_setup_ht_vht_cap(ar, &ar->pdev->cap, NULL); |
| 8976 |
ath12k_mac_setup_sband_iftype_data(ar, &ar->pdev->cap); |
| 8977 |
|
| 8978 |
return 0; |
| 8979 |
} |
| 8980 |
|
| 8981 |
static void ath12k_mgmt_over_wmi_tx_drop(struct ath12k *ar, struct sk_buff *skb) |
| 8982 |
{ |
| 8983 |
int num_mgmt; |
| 8984 |
|
| 8985 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 8986 |
|
| 8987 |
ieee80211_free_txskb(ath12k_ar_to_hw(ar), skb); |
| 8988 |
|
| 8989 |
num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx); |
| 8990 |
|
| 8991 |
if (num_mgmt < 0) |
| 8992 |
WARN_ON_ONCE(1); |
| 8993 |
|
| 8994 |
if (!num_mgmt) |
| 8995 |
wake_up(&ar->txmgmt_empty_waitq); |
| 8996 |
} |
| 8997 |
|
| 8998 |
static void ath12k_mac_tx_mgmt_free(struct ath12k *ar, int buf_id) |
| 8999 |
{ |
| 9000 |
struct sk_buff *msdu; |
| 9001 |
struct ieee80211_tx_info *info; |
| 9002 |
|
| 9003 |
spin_lock_bh(&ar->txmgmt_idr_lock); |
| 9004 |
msdu = idr_remove(&ar->txmgmt_idr, buf_id); |
| 9005 |
spin_unlock_bh(&ar->txmgmt_idr_lock); |
| 9006 |
|
| 9007 |
if (!msdu) |
| 9008 |
return; |
| 9009 |
|
| 9010 |
dma_unmap_single(ar->ab->dev, ATH12K_SKB_CB(msdu)->paddr, msdu->len, |
| 9011 |
DMA_TO_DEVICE); |
| 9012 |
|
| 9013 |
info = IEEE80211_SKB_CB(msdu); |
| 9014 |
memset(&info->status, 0, sizeof(info->status)); |
| 9015 |
|
| 9016 |
ath12k_mgmt_over_wmi_tx_drop(ar, msdu); |
| 9017 |
} |
| 9018 |
|
| 9019 |
int ath12k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx) |
| 9020 |
{ |
| 9021 |
struct ath12k *ar = ctx; |
| 9022 |
|
| 9023 |
ath12k_mac_tx_mgmt_free(ar, buf_id); |
| 9024 |
|
| 9025 |
return 0; |
| 9026 |
} |
| 9027 |
|
| 9028 |
static int ath12k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx) |
| 9029 |
{ |
| 9030 |
struct ieee80211_vif *vif = ctx; |
| 9031 |
struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb); |
| 9032 |
struct ath12k *ar = skb_cb->ar; |
| 9033 |
|
| 9034 |
if (skb_cb->vif == vif) |
| 9035 |
ath12k_mac_tx_mgmt_free(ar, buf_id); |
| 9036 |
|
| 9037 |
return 0; |
| 9038 |
} |
| 9039 |
|
| 9040 |
static int ath12k_mac_mgmt_tx_wmi(struct ath12k *ar, struct ath12k_link_vif *arvif, |
| 9041 |
struct sk_buff *skb) |
| 9042 |
{ |
| 9043 |
struct ath12k_base *ab = ar->ab; |
| 9044 |
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 9045 |
struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb); |
| 9046 |
struct ieee80211_tx_info *info; |
| 9047 |
enum hal_encrypt_type enctype; |
| 9048 |
unsigned int mic_len; |
| 9049 |
dma_addr_t paddr; |
| 9050 |
int buf_id; |
| 9051 |
int ret; |
| 9052 |
|
| 9053 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 9054 |
|
| 9055 |
skb_cb->ar = ar; |
| 9056 |
spin_lock_bh(&ar->txmgmt_idr_lock); |
| 9057 |
buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0, |
| 9058 |
ATH12K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC); |
| 9059 |
spin_unlock_bh(&ar->txmgmt_idr_lock); |
| 9060 |
if (buf_id < 0) |
| 9061 |
return -ENOSPC; |
| 9062 |
|
| 9063 |
info = IEEE80211_SKB_CB(skb); |
| 9064 |
if ((skb_cb->flags & ATH12K_SKB_CIPHER_SET) && |
| 9065 |
!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) { |
| 9066 |
if ((ieee80211_is_action(hdr->frame_control) || |
| 9067 |
ieee80211_is_deauth(hdr->frame_control) || |
| 9068 |
ieee80211_is_disassoc(hdr->frame_control)) && |
| 9069 |
ieee80211_has_protected(hdr->frame_control)) { |
| 9070 |
enctype = ath12k_dp_tx_get_encrypt_type(skb_cb->cipher); |
| 9071 |
mic_len = ath12k_dp_rx_crypto_mic_len(ab->dp, enctype); |
| 9072 |
skb_put(skb, mic_len); |
| 9073 |
} |
| 9074 |
} |
| 9075 |
|
| 9076 |
paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE); |
| 9077 |
if (dma_mapping_error(ab->dev, paddr)) { |
| 9078 |
ath12k_warn(ab, "failed to DMA map mgmt Tx buffer\n"); |
| 9079 |
ret = -EIO; |
| 9080 |
goto err_free_idr; |
| 9081 |
} |
| 9082 |
|
| 9083 |
skb_cb->paddr = paddr; |
| 9084 |
|
| 9085 |
ret = ath12k_wmi_mgmt_send(arvif, buf_id, skb); |
| 9086 |
if (ret) { |
| 9087 |
ath12k_warn(ar->ab, "failed to send mgmt frame: %d\n", ret); |
| 9088 |
goto err_unmap_buf; |
| 9089 |
} |
| 9090 |
|
| 9091 |
return 0; |
| 9092 |
|
| 9093 |
err_unmap_buf: |
| 9094 |
dma_unmap_single(ab->dev, skb_cb->paddr, |
| 9095 |
skb->len, DMA_TO_DEVICE); |
| 9096 |
err_free_idr: |
| 9097 |
spin_lock_bh(&ar->txmgmt_idr_lock); |
| 9098 |
idr_remove(&ar->txmgmt_idr, buf_id); |
| 9099 |
spin_unlock_bh(&ar->txmgmt_idr_lock); |
| 9100 |
|
| 9101 |
return ret; |
| 9102 |
} |
| 9103 |
|
| 9104 |
static void ath12k_mgmt_over_wmi_tx_purge(struct ath12k *ar) |
| 9105 |
{ |
| 9106 |
struct sk_buff *skb; |
| 9107 |
|
| 9108 |
while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) |
| 9109 |
ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
| 9110 |
} |
| 9111 |
|
| 9112 |
static int ath12k_mac_mgmt_action_frame_fill_elem_data(struct ath12k_link_vif *arvif, |
| 9113 |
struct sk_buff *skb) |
| 9114 |
{ |
| 9115 |
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 9116 |
u8 category, *buf, iv_len, action_code, dialog_token; |
| 9117 |
struct ieee80211_bss_conf *link_conf; |
| 9118 |
struct ieee80211_chanctx_conf *conf; |
| 9119 |
int cur_tx_power, max_tx_power; |
| 9120 |
struct ath12k *ar = arvif->ar; |
| 9121 |
struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
| 9122 |
struct wiphy *wiphy = hw->wiphy; |
| 9123 |
struct ath12k_skb_cb *skb_cb; |
| 9124 |
struct ieee80211_mgmt *mgmt; |
| 9125 |
unsigned int remaining_len; |
| 9126 |
bool has_protected; |
| 9127 |
|
| 9128 |
lockdep_assert_wiphy(wiphy); |
| 9129 |
|
| 9130 |
/* make sure category field is present */ |
| 9131 |
if (skb->len < IEEE80211_MIN_ACTION_SIZE) |
| 9132 |
return -EINVAL; |
| 9133 |
|
| 9134 |
remaining_len = skb->len - IEEE80211_MIN_ACTION_SIZE; |
| 9135 |
has_protected = ieee80211_has_protected(hdr->frame_control); |
| 9136 |
|
| 9137 |
/* In case of SW crypto and hdr protected (PMF), packet will already be encrypted, |
| 9138 |
* we can't put in data in this case |
| 9139 |
*/ |
| 9140 |
if (test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags) && |
| 9141 |
has_protected) |
| 9142 |
return 0; |
| 9143 |
|
| 9144 |
mgmt = (struct ieee80211_mgmt *)hdr; |
| 9145 |
buf = (u8 *)&mgmt->u.action; |
| 9146 |
|
| 9147 |
/* FCTL_PROTECTED frame might have extra space added for HDR_LEN. Offset that |
| 9148 |
* many bytes if it is there |
| 9149 |
*/ |
| 9150 |
if (has_protected) { |
| 9151 |
skb_cb = ATH12K_SKB_CB(skb); |
| 9152 |
|
| 9153 |
switch (skb_cb->cipher) { |
| 9154 |
/* Cipher suite having flag %IEEE80211_KEY_FLAG_GENERATE_IV_MGMT set in |
| 9155 |
* key needs to be processed. See ath12k_install_key() |
| 9156 |
*/ |
| 9157 |
case WLAN_CIPHER_SUITE_CCMP: |
| 9158 |
case WLAN_CIPHER_SUITE_CCMP_256: |
| 9159 |
case WLAN_CIPHER_SUITE_GCMP: |
| 9160 |
case WLAN_CIPHER_SUITE_GCMP_256: |
| 9161 |
iv_len = IEEE80211_CCMP_HDR_LEN; |
| 9162 |
break; |
| 9163 |
case WLAN_CIPHER_SUITE_TKIP: |
| 9164 |
iv_len = 0; |
| 9165 |
break; |
| 9166 |
default: |
| 9167 |
return -EINVAL; |
| 9168 |
} |
| 9169 |
|
| 9170 |
if (remaining_len < iv_len) |
| 9171 |
return -EINVAL; |
| 9172 |
|
| 9173 |
buf += iv_len; |
| 9174 |
remaining_len -= iv_len; |
| 9175 |
} |
| 9176 |
|
| 9177 |
category = *buf++; |
| 9178 |
/* category code is already taken care in %IEEE80211_MIN_ACTION_SIZE hence |
| 9179 |
* no need to adjust remaining_len |
| 9180 |
*/ |
| 9181 |
|
| 9182 |
switch (category) { |
| 9183 |
case WLAN_CATEGORY_RADIO_MEASUREMENT: |
| 9184 |
/* need action code and dialog token */ |
| 9185 |
if (remaining_len < 2) |
| 9186 |
return -EINVAL; |
| 9187 |
|
| 9188 |
/* Packet Format: |
| 9189 |
* Action Code | Dialog Token | Variable Len (based on Action Code) |
| 9190 |
*/ |
| 9191 |
action_code = *buf++; |
| 9192 |
dialog_token = *buf++; |
| 9193 |
remaining_len -= 2; |
| 9194 |
|
| 9195 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 9196 |
if (!link_conf) { |
| 9197 |
ath12k_warn(ar->ab, |
| 9198 |
"failed to get bss link conf for vdev %d in RM handling\n", |
| 9199 |
arvif->vdev_id); |
| 9200 |
return -EINVAL; |
| 9201 |
} |
| 9202 |
|
| 9203 |
conf = wiphy_dereference(wiphy, link_conf->chanctx_conf); |
| 9204 |
if (!conf) |
| 9205 |
return -ENOENT; |
| 9206 |
|
| 9207 |
cur_tx_power = link_conf->txpower; |
| 9208 |
max_tx_power = min(conf->def.chan->max_reg_power, |
| 9209 |
(int)ar->max_tx_power / 2); |
| 9210 |
|
| 9211 |
ath12k_mac_op_get_txpower(hw, arvif->ahvif->vif, arvif->link_id, |
| 9212 |
&cur_tx_power); |
| 9213 |
|
| 9214 |
switch (action_code) { |
| 9215 |
case WLAN_RM_ACTION_LINK_MEASUREMENT_REQUEST: |
| 9216 |
/* need variable fields to be present in len */ |
| 9217 |
if (remaining_len < 2) |
| 9218 |
return -EINVAL; |
| 9219 |
|
| 9220 |
/* Variable length format as defined in IEEE 802.11-2024, |
| 9221 |
* Figure 9-1187-Link Measurement Request frame Action field |
| 9222 |
* format. |
| 9223 |
* Transmit Power | Max Tx Power |
| 9224 |
* We fill both of these. |
| 9225 |
*/ |
| 9226 |
*buf++ = cur_tx_power; |
| 9227 |
*buf = max_tx_power; |
| 9228 |
|
| 9229 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 9230 |
"RRM: Link Measurement Req dialog_token %u cur_tx_power %d max_tx_power %d\n", |
| 9231 |
dialog_token, cur_tx_power, max_tx_power); |
| 9232 |
break; |
| 9233 |
case WLAN_RM_ACTION_LINK_MEASUREMENT_REPORT: |
| 9234 |
/* need variable fields to be present in len */ |
| 9235 |
if (remaining_len < 3) |
| 9236 |
return -EINVAL; |
| 9237 |
|
| 9238 |
/* Variable length format as defined in IEEE 802.11-2024, |
| 9239 |
* Figure 9-1188-Link Measurement Report frame Action field format |
| 9240 |
* TPC Report | Variable Fields |
| 9241 |
* |
| 9242 |
* TPC Report Format: |
| 9243 |
* Element ID | Len | Tx Power | Link Margin |
| 9244 |
* |
| 9245 |
* We fill Tx power in the TPC Report (2nd index) |
| 9246 |
*/ |
| 9247 |
buf[2] = cur_tx_power; |
| 9248 |
|
| 9249 |
/* TODO: At present, Link margin data is not present so can't |
| 9250 |
* really fill it now. Once it is available, it can be added |
| 9251 |
* here |
| 9252 |
*/ |
| 9253 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 9254 |
"RRM: Link Measurement Report dialog_token %u cur_tx_power %d\n", |
| 9255 |
dialog_token, cur_tx_power); |
| 9256 |
break; |
| 9257 |
default: |
| 9258 |
return -EINVAL; |
| 9259 |
} |
| 9260 |
break; |
| 9261 |
default: |
| 9262 |
/* nothing to fill */ |
| 9263 |
return 0; |
| 9264 |
} |
| 9265 |
|
| 9266 |
return 0; |
| 9267 |
} |
| 9268 |
|
| 9269 |
static int ath12k_mac_mgmt_frame_fill_elem_data(struct ath12k_link_vif *arvif, |
| 9270 |
struct sk_buff *skb) |
| 9271 |
{ |
| 9272 |
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 9273 |
|
| 9274 |
if (!ieee80211_is_action(hdr->frame_control)) |
| 9275 |
return 0; |
| 9276 |
|
| 9277 |
return ath12k_mac_mgmt_action_frame_fill_elem_data(arvif, skb); |
| 9278 |
} |
| 9279 |
|
| 9280 |
static void ath12k_mgmt_over_wmi_tx_work(struct wiphy *wiphy, struct wiphy_work *work) |
| 9281 |
{ |
| 9282 |
struct ath12k *ar = container_of(work, struct ath12k, wmi_mgmt_tx_work); |
| 9283 |
struct ath12k_hw *ah = ar->ah; |
| 9284 |
struct ath12k_skb_cb *skb_cb; |
| 9285 |
struct ath12k_vif *ahvif; |
| 9286 |
struct ath12k_link_vif *arvif; |
| 9287 |
struct sk_buff *skb; |
| 9288 |
int ret; |
| 9289 |
|
| 9290 |
lockdep_assert_wiphy(wiphy); |
| 9291 |
|
| 9292 |
while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) { |
| 9293 |
skb_cb = ATH12K_SKB_CB(skb); |
| 9294 |
if (!skb_cb->vif) { |
| 9295 |
ath12k_warn(ar->ab, "no vif found for mgmt frame\n"); |
| 9296 |
ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
| 9297 |
continue; |
| 9298 |
} |
| 9299 |
|
| 9300 |
ahvif = ath12k_vif_to_ahvif(skb_cb->vif); |
| 9301 |
if (!(ahvif->links_map & BIT(skb_cb->link_id))) { |
| 9302 |
ath12k_warn(ar->ab, |
| 9303 |
"invalid linkid %u in mgmt over wmi tx with linkmap 0x%x\n", |
| 9304 |
skb_cb->link_id, ahvif->links_map); |
| 9305 |
ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
| 9306 |
continue; |
| 9307 |
} |
| 9308 |
|
| 9309 |
arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[skb_cb->link_id]); |
| 9310 |
if (ar->allocated_vdev_map & (1LL << arvif->vdev_id)) { |
| 9311 |
/* Fill in the data which is required to be filled by the driver |
| 9312 |
* For example: Max Tx power in Link Measurement Request/Report |
| 9313 |
*/ |
| 9314 |
ret = ath12k_mac_mgmt_frame_fill_elem_data(arvif, skb); |
| 9315 |
if (ret) { |
| 9316 |
/* If we couldn't fill the data due to any reason, |
| 9317 |
* let's not discard transmitting the packet. |
| 9318 |
* For example: Software crypto and PMF case |
| 9319 |
*/ |
| 9320 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 9321 |
"Failed to fill the required data for the mgmt packet err %d\n", |
| 9322 |
ret); |
| 9323 |
} |
| 9324 |
|
| 9325 |
ret = ath12k_mac_mgmt_tx_wmi(ar, arvif, skb); |
| 9326 |
if (ret) { |
| 9327 |
ath12k_warn(ar->ab, "failed to tx mgmt frame, vdev_id %d :%d\n", |
| 9328 |
arvif->vdev_id, ret); |
| 9329 |
ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
| 9330 |
} |
| 9331 |
} else { |
| 9332 |
ath12k_warn(ar->ab, |
| 9333 |
"dropping mgmt frame for vdev %d link %u is_started %d\n", |
| 9334 |
arvif->vdev_id, |
| 9335 |
skb_cb->link_id, |
| 9336 |
arvif->is_started); |
| 9337 |
ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
| 9338 |
} |
| 9339 |
} |
| 9340 |
} |
| 9341 |
|
| 9342 |
int ath12k_mac_mgmt_tx(struct ath12k *ar, struct sk_buff *skb, |
| 9343 |
bool is_prb_rsp) |
| 9344 |
{ |
| 9345 |
struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue; |
| 9346 |
|
| 9347 |
if (test_bit(ATH12K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags)) |
| 9348 |
return -ESHUTDOWN; |
| 9349 |
|
| 9350 |
/* Drop probe response packets when the pending management tx |
| 9351 |
* count has reached a certain threshold, so as to prioritize |
| 9352 |
* other mgmt packets like auth and assoc to be sent on time |
| 9353 |
* for establishing successful connections. |
| 9354 |
*/ |
| 9355 |
if (is_prb_rsp && |
| 9356 |
atomic_read(&ar->num_pending_mgmt_tx) > ATH12K_PRB_RSP_DROP_THRESHOLD) { |
| 9357 |
ath12k_warn(ar->ab, |
| 9358 |
"dropping probe response as pending queue is almost full\n"); |
| 9359 |
return -ENOSPC; |
| 9360 |
} |
| 9361 |
|
| 9362 |
if (skb_queue_len_lockless(q) >= ATH12K_TX_MGMT_NUM_PENDING_MAX) { |
| 9363 |
ath12k_warn(ar->ab, "mgmt tx queue is full\n"); |
| 9364 |
return -ENOSPC; |
| 9365 |
} |
| 9366 |
|
| 9367 |
skb_queue_tail(q, skb); |
| 9368 |
atomic_inc(&ar->num_pending_mgmt_tx); |
| 9369 |
wiphy_work_queue(ath12k_ar_to_hw(ar)->wiphy, &ar->wmi_mgmt_tx_work); |
| 9370 |
|
| 9371 |
return 0; |
| 9372 |
} |
| 9373 |
EXPORT_SYMBOL(ath12k_mac_mgmt_tx); |
| 9374 |
|
| 9375 |
void ath12k_mac_add_p2p_noa_ie(struct ath12k *ar, |
| 9376 |
struct ieee80211_vif *vif, |
| 9377 |
struct sk_buff *skb, |
| 9378 |
bool is_prb_rsp) |
| 9379 |
{ |
| 9380 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 9381 |
|
| 9382 |
if (likely(!is_prb_rsp)) |
| 9383 |
return; |
| 9384 |
|
| 9385 |
spin_lock_bh(&ar->data_lock); |
| 9386 |
|
| 9387 |
if (ahvif->u.ap.noa_data && |
| 9388 |
!pskb_expand_head(skb, 0, ahvif->u.ap.noa_len, |
| 9389 |
GFP_ATOMIC)) |
| 9390 |
skb_put_data(skb, ahvif->u.ap.noa_data, |
| 9391 |
ahvif->u.ap.noa_len); |
| 9392 |
|
| 9393 |
spin_unlock_bh(&ar->data_lock); |
| 9394 |
} |
| 9395 |
EXPORT_SYMBOL(ath12k_mac_add_p2p_noa_ie); |
| 9396 |
|
| 9397 |
/* Note: called under rcu_read_lock() */ |
| 9398 |
void ath12k_mlo_mcast_update_tx_link_address(struct ieee80211_vif *vif, |
| 9399 |
u8 link_id, struct sk_buff *skb, |
| 9400 |
u32 info_flags) |
| 9401 |
{ |
| 9402 |
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 9403 |
struct ieee80211_bss_conf *bss_conf; |
| 9404 |
|
| 9405 |
if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP) |
| 9406 |
return; |
| 9407 |
|
| 9408 |
bss_conf = rcu_dereference(vif->link_conf[link_id]); |
| 9409 |
if (bss_conf) |
| 9410 |
ether_addr_copy(hdr->addr2, bss_conf->addr); |
| 9411 |
} |
| 9412 |
EXPORT_SYMBOL(ath12k_mlo_mcast_update_tx_link_address); |
| 9413 |
|
| 9414 |
/* Note: called under rcu_read_lock() */ |
| 9415 |
u8 ath12k_mac_get_tx_link(struct ieee80211_sta *sta, struct ieee80211_vif *vif, |
| 9416 |
u8 link, struct sk_buff *skb, u32 info_flags) |
| 9417 |
{ |
| 9418 |
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 9419 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 9420 |
struct ieee80211_link_sta *link_sta; |
| 9421 |
struct ieee80211_bss_conf *bss_conf; |
| 9422 |
struct ath12k_sta *ahsta; |
| 9423 |
|
| 9424 |
/* Use the link id passed or the default vif link */ |
| 9425 |
if (!sta) { |
| 9426 |
if (link != IEEE80211_LINK_UNSPECIFIED) |
| 9427 |
return link; |
| 9428 |
|
| 9429 |
return ahvif->deflink.link_id; |
| 9430 |
} |
| 9431 |
|
| 9432 |
ahsta = ath12k_sta_to_ahsta(sta); |
| 9433 |
|
| 9434 |
/* Below translation ensures we pass proper A2 & A3 for non ML clients. |
| 9435 |
* Also it assumes for now support only for MLO AP in this path |
| 9436 |
*/ |
| 9437 |
if (!sta->mlo) { |
| 9438 |
link = ahsta->deflink.link_id; |
| 9439 |
|
| 9440 |
if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP) |
| 9441 |
return link; |
| 9442 |
|
| 9443 |
bss_conf = rcu_dereference(vif->link_conf[link]); |
| 9444 |
if (bss_conf) { |
| 9445 |
ether_addr_copy(hdr->addr2, bss_conf->addr); |
| 9446 |
if (!ieee80211_has_tods(hdr->frame_control) && |
| 9447 |
!ieee80211_has_fromds(hdr->frame_control)) |
| 9448 |
ether_addr_copy(hdr->addr3, bss_conf->addr); |
| 9449 |
} |
| 9450 |
|
| 9451 |
return link; |
| 9452 |
} |
| 9453 |
|
| 9454 |
/* enqueue eth enacap & data frames on primary link, FW does link |
| 9455 |
* selection and address translation. |
| 9456 |
*/ |
| 9457 |
if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP || |
| 9458 |
ieee80211_is_data(hdr->frame_control)) |
| 9459 |
return ahsta->assoc_link_id; |
| 9460 |
|
| 9461 |
/* 802.11 frame cases */ |
| 9462 |
if (link == IEEE80211_LINK_UNSPECIFIED) |
| 9463 |
link = ahsta->deflink.link_id; |
| 9464 |
|
| 9465 |
if (!ieee80211_is_mgmt(hdr->frame_control)) |
| 9466 |
return link; |
| 9467 |
|
| 9468 |
/* Perform address conversion for ML STA Tx */ |
| 9469 |
bss_conf = rcu_dereference(vif->link_conf[link]); |
| 9470 |
link_sta = rcu_dereference(sta->link[link]); |
| 9471 |
|
| 9472 |
if (bss_conf && link_sta) { |
| 9473 |
ether_addr_copy(hdr->addr1, link_sta->addr); |
| 9474 |
ether_addr_copy(hdr->addr2, bss_conf->addr); |
| 9475 |
|
| 9476 |
if (vif->type == NL80211_IFTYPE_STATION && bss_conf->bssid) |
| 9477 |
ether_addr_copy(hdr->addr3, bss_conf->bssid); |
| 9478 |
else if (vif->type == NL80211_IFTYPE_AP) |
| 9479 |
ether_addr_copy(hdr->addr3, bss_conf->addr); |
| 9480 |
|
| 9481 |
return link; |
| 9482 |
} |
| 9483 |
|
| 9484 |
if (bss_conf) { |
| 9485 |
/* In certain cases where a ML sta associated and added subset of |
| 9486 |
* links on which the ML AP is active, but now sends some frame |
| 9487 |
* (ex. Probe request) on a different link which is active in our |
| 9488 |
* MLD but was not added during previous association, we can |
| 9489 |
* still honor the Tx to that ML STA via the requested link. |
| 9490 |
* The control would reach here in such case only when that link |
| 9491 |
* address is same as the MLD address or in worst case clients |
| 9492 |
* used MLD address at TA wrongly which would have helped |
| 9493 |
* identify the ML sta object and pass it here. |
| 9494 |
* If the link address of that STA is different from MLD address, |
| 9495 |
* then the sta object would be NULL and control won't reach |
| 9496 |
* here but return at the start of the function itself with !sta |
| 9497 |
* check. Also this would not need any translation at hdr->addr1 |
| 9498 |
* from MLD to link address since the RA is the MLD address |
| 9499 |
* (same as that link address ideally) already. |
| 9500 |
*/ |
| 9501 |
ether_addr_copy(hdr->addr2, bss_conf->addr); |
| 9502 |
|
| 9503 |
if (vif->type == NL80211_IFTYPE_STATION && bss_conf->bssid) |
| 9504 |
ether_addr_copy(hdr->addr3, bss_conf->bssid); |
| 9505 |
else if (vif->type == NL80211_IFTYPE_AP) |
| 9506 |
ether_addr_copy(hdr->addr3, bss_conf->addr); |
| 9507 |
} |
| 9508 |
|
| 9509 |
return link; |
| 9510 |
} |
| 9511 |
EXPORT_SYMBOL(ath12k_mac_get_tx_link); |
| 9512 |
|
| 9513 |
void ath12k_mac_drain_tx(struct ath12k *ar) |
| 9514 |
{ |
| 9515 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 9516 |
|
| 9517 |
/* make sure rcu-protected mac80211 tx path itself is drained */ |
| 9518 |
synchronize_net(); |
| 9519 |
|
| 9520 |
wiphy_work_cancel(ath12k_ar_to_hw(ar)->wiphy, &ar->wmi_mgmt_tx_work); |
| 9521 |
ath12k_mgmt_over_wmi_tx_purge(ar); |
| 9522 |
} |
| 9523 |
|
| 9524 |
static int ath12k_mac_config_mon_status_default(struct ath12k *ar, bool enable) |
| 9525 |
{ |
| 9526 |
struct htt_rx_ring_tlv_filter tlv_filter = {}; |
| 9527 |
struct ath12k_base *ab = ar->ab; |
| 9528 |
u32 ring_id, i; |
| 9529 |
int ret = 0; |
| 9530 |
|
| 9531 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 9532 |
|
| 9533 |
if (!ab->hw_params->rxdma1_enable) |
| 9534 |
return ret; |
| 9535 |
|
| 9536 |
if (enable) { |
| 9537 |
tlv_filter = ath12k_mac_mon_status_filter_default; |
| 9538 |
|
| 9539 |
if (ath12k_debugfs_rx_filter(ar)) |
| 9540 |
tlv_filter.rx_filter = ath12k_debugfs_rx_filter(ar); |
| 9541 |
} else { |
| 9542 |
tlv_filter.rxmon_disable = true; |
| 9543 |
} |
| 9544 |
|
| 9545 |
for (i = 0; i < ab->hw_params->num_rxdma_per_pdev; i++) { |
| 9546 |
ring_id = ar->dp.rxdma_mon_dst_ring[i].ring_id; |
| 9547 |
ret = ath12k_dp_tx_htt_rx_filter_setup(ab, ring_id, |
| 9548 |
ar->dp.mac_id + i, |
| 9549 |
HAL_RXDMA_MONITOR_DST, |
| 9550 |
DP_RXDMA_REFILL_RING_SIZE, |
| 9551 |
&tlv_filter); |
| 9552 |
if (ret) { |
| 9553 |
ath12k_err(ab, |
| 9554 |
"failed to setup filter for monitor buf %d\n", |
| 9555 |
ret); |
| 9556 |
} |
| 9557 |
} |
| 9558 |
|
| 9559 |
return ret; |
| 9560 |
} |
| 9561 |
|
| 9562 |
static int ath12k_mac_start(struct ath12k *ar) |
| 9563 |
{ |
| 9564 |
struct ath12k_hw *ah = ar->ah; |
| 9565 |
struct ath12k_base *ab = ar->ab; |
| 9566 |
struct ath12k_pdev *pdev = ar->pdev; |
| 9567 |
int ret; |
| 9568 |
|
| 9569 |
lockdep_assert_held(&ah->hw_mutex); |
| 9570 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 9571 |
|
| 9572 |
ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, |
| 9573 |
1, pdev->pdev_id); |
| 9574 |
|
| 9575 |
if (ret) { |
| 9576 |
ath12k_err(ab, "failed to enable PMF QOS: %d\n", ret); |
| 9577 |
goto err; |
| 9578 |
} |
| 9579 |
|
| 9580 |
ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 1, |
| 9581 |
pdev->pdev_id); |
| 9582 |
if (ret) { |
| 9583 |
ath12k_err(ab, "failed to enable dynamic bw: %d\n", ret); |
| 9584 |
goto err; |
| 9585 |
} |
| 9586 |
|
| 9587 |
ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_ARP_AC_OVERRIDE, |
| 9588 |
0, pdev->pdev_id); |
| 9589 |
if (ret) { |
| 9590 |
ath12k_err(ab, "failed to set ac override for ARP: %d\n", |
| 9591 |
ret); |
| 9592 |
goto err; |
| 9593 |
} |
| 9594 |
|
| 9595 |
ret = ath12k_wmi_send_dfs_phyerr_offload_enable_cmd(ar, pdev->pdev_id); |
| 9596 |
if (ret) { |
| 9597 |
ath12k_err(ab, "failed to offload radar detection: %d\n", |
| 9598 |
ret); |
| 9599 |
goto err; |
| 9600 |
} |
| 9601 |
|
| 9602 |
ret = ath12k_dp_tx_htt_h2t_ppdu_stats_req(ar, |
| 9603 |
HTT_PPDU_STATS_TAG_DEFAULT); |
| 9604 |
if (ret) { |
| 9605 |
ath12k_err(ab, "failed to req ppdu stats: %d\n", ret); |
| 9606 |
goto err; |
| 9607 |
} |
| 9608 |
|
| 9609 |
ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_MESH_MCAST_ENABLE, |
| 9610 |
1, pdev->pdev_id); |
| 9611 |
|
| 9612 |
if (ret) { |
| 9613 |
ath12k_err(ab, "failed to enable MESH MCAST ENABLE: (%d\n", ret); |
| 9614 |
goto err; |
| 9615 |
} |
| 9616 |
|
| 9617 |
__ath12k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask); |
| 9618 |
|
| 9619 |
/* TODO: Do we need to enable ANI? */ |
| 9620 |
|
| 9621 |
ret = ath12k_reg_update_chan_list(ar, false); |
| 9622 |
|
| 9623 |
/* The ar state alone can be turned off for non supported country |
| 9624 |
* without returning the error value. As we need to update the channel |
| 9625 |
* for the next ar. |
| 9626 |
*/ |
| 9627 |
if (ret) { |
| 9628 |
if (ret == -EINVAL) |
| 9629 |
ret = 0; |
| 9630 |
goto err; |
| 9631 |
} |
| 9632 |
|
| 9633 |
ar->num_started_vdevs = 0; |
| 9634 |
ar->num_created_vdevs = 0; |
| 9635 |
ar->num_peers = 0; |
| 9636 |
ar->allocated_vdev_map = 0; |
| 9637 |
ar->chan_tx_pwr = ATH12K_PDEV_TX_POWER_INVALID; |
| 9638 |
|
| 9639 |
/* Configure monitor status ring with default rx_filter to get rx status |
| 9640 |
* such as rssi, rx_duration. |
| 9641 |
*/ |
| 9642 |
ret = ath12k_mac_config_mon_status_default(ar, true); |
| 9643 |
if (ret && (ret != -EOPNOTSUPP)) { |
| 9644 |
ath12k_err(ab, "failed to configure monitor status ring with default rx_filter: (%d)\n", |
| 9645 |
ret); |
| 9646 |
goto err; |
| 9647 |
} |
| 9648 |
|
| 9649 |
if (ret == -EOPNOTSUPP) |
| 9650 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 9651 |
"monitor status config is not yet supported"); |
| 9652 |
|
| 9653 |
/* Configure the hash seed for hash based reo dest ring selection */ |
| 9654 |
ath12k_wmi_pdev_lro_cfg(ar, ar->pdev->pdev_id); |
| 9655 |
|
| 9656 |
/* allow device to enter IMPS */ |
| 9657 |
if (ab->hw_params->idle_ps) { |
| 9658 |
ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_IDLE_PS_CONFIG, |
| 9659 |
1, pdev->pdev_id); |
| 9660 |
if (ret) { |
| 9661 |
ath12k_err(ab, "failed to enable idle ps: %d\n", ret); |
| 9662 |
goto err; |
| 9663 |
} |
| 9664 |
} |
| 9665 |
|
| 9666 |
rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx], |
| 9667 |
&ab->pdevs[ar->pdev_idx]); |
| 9668 |
|
| 9669 |
return 0; |
| 9670 |
err: |
| 9671 |
|
| 9672 |
return ret; |
| 9673 |
} |
| 9674 |
|
| 9675 |
static void ath12k_drain_tx(struct ath12k_hw *ah) |
| 9676 |
{ |
| 9677 |
struct ath12k *ar; |
| 9678 |
int i; |
| 9679 |
|
| 9680 |
lockdep_assert_wiphy(ah->hw->wiphy); |
| 9681 |
|
| 9682 |
for_each_ar(ah, ar, i) |
| 9683 |
ath12k_mac_drain_tx(ar); |
| 9684 |
} |
| 9685 |
|
| 9686 |
int ath12k_mac_op_start(struct ieee80211_hw *hw) |
| 9687 |
{ |
| 9688 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 9689 |
struct ath12k *ar; |
| 9690 |
int ret, i; |
| 9691 |
|
| 9692 |
if (ath12k_ftm_mode) |
| 9693 |
return -EPERM; |
| 9694 |
|
| 9695 |
lockdep_assert_wiphy(hw->wiphy); |
| 9696 |
|
| 9697 |
ath12k_drain_tx(ah); |
| 9698 |
|
| 9699 |
guard(mutex)(&ah->hw_mutex); |
| 9700 |
|
| 9701 |
switch (ah->state) { |
| 9702 |
case ATH12K_HW_STATE_OFF: |
| 9703 |
ah->state = ATH12K_HW_STATE_ON; |
| 9704 |
break; |
| 9705 |
case ATH12K_HW_STATE_RESTARTING: |
| 9706 |
ah->state = ATH12K_HW_STATE_RESTARTED; |
| 9707 |
break; |
| 9708 |
case ATH12K_HW_STATE_RESTARTED: |
| 9709 |
case ATH12K_HW_STATE_WEDGED: |
| 9710 |
case ATH12K_HW_STATE_ON: |
| 9711 |
case ATH12K_HW_STATE_TM: |
| 9712 |
ah->state = ATH12K_HW_STATE_OFF; |
| 9713 |
|
| 9714 |
WARN_ON(1); |
| 9715 |
return -EINVAL; |
| 9716 |
} |
| 9717 |
|
| 9718 |
for_each_ar(ah, ar, i) { |
| 9719 |
ret = ath12k_mac_start(ar); |
| 9720 |
if (ret) { |
| 9721 |
ah->state = ATH12K_HW_STATE_OFF; |
| 9722 |
|
| 9723 |
ath12k_err(ar->ab, "fail to start mac operations in pdev idx %d ret %d\n", |
| 9724 |
ar->pdev_idx, ret); |
| 9725 |
goto fail_start; |
| 9726 |
} |
| 9727 |
} |
| 9728 |
|
| 9729 |
return 0; |
| 9730 |
|
| 9731 |
fail_start: |
| 9732 |
for (; i > 0; i--) { |
| 9733 |
ar = ath12k_ah_to_ar(ah, i - 1); |
| 9734 |
ath12k_mac_stop(ar); |
| 9735 |
} |
| 9736 |
|
| 9737 |
return ret; |
| 9738 |
} |
| 9739 |
EXPORT_SYMBOL(ath12k_mac_op_start); |
| 9740 |
|
| 9741 |
int ath12k_mac_rfkill_config(struct ath12k *ar) |
| 9742 |
{ |
| 9743 |
struct ath12k_base *ab = ar->ab; |
| 9744 |
u32 param; |
| 9745 |
int ret; |
| 9746 |
|
| 9747 |
if (ab->hw_params->rfkill_pin == 0) |
| 9748 |
return -EOPNOTSUPP; |
| 9749 |
|
| 9750 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 9751 |
"mac rfkill_pin %d rfkill_cfg %d rfkill_on_level %d", |
| 9752 |
ab->hw_params->rfkill_pin, ab->hw_params->rfkill_cfg, |
| 9753 |
ab->hw_params->rfkill_on_level); |
| 9754 |
|
| 9755 |
param = u32_encode_bits(ab->hw_params->rfkill_on_level, |
| 9756 |
WMI_RFKILL_CFG_RADIO_LEVEL) | |
| 9757 |
u32_encode_bits(ab->hw_params->rfkill_pin, |
| 9758 |
WMI_RFKILL_CFG_GPIO_PIN_NUM) | |
| 9759 |
u32_encode_bits(ab->hw_params->rfkill_cfg, |
| 9760 |
WMI_RFKILL_CFG_PIN_AS_GPIO); |
| 9761 |
|
| 9762 |
ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_HW_RFKILL_CONFIG, |
| 9763 |
param, ar->pdev->pdev_id); |
| 9764 |
if (ret) { |
| 9765 |
ath12k_warn(ab, |
| 9766 |
"failed to set rfkill config 0x%x: %d\n", |
| 9767 |
param, ret); |
| 9768 |
return ret; |
| 9769 |
} |
| 9770 |
|
| 9771 |
return 0; |
| 9772 |
} |
| 9773 |
|
| 9774 |
int ath12k_mac_rfkill_enable_radio(struct ath12k *ar, bool enable) |
| 9775 |
{ |
| 9776 |
enum wmi_rfkill_enable_radio param; |
| 9777 |
int ret; |
| 9778 |
|
| 9779 |
if (enable) |
| 9780 |
param = WMI_RFKILL_ENABLE_RADIO_ON; |
| 9781 |
else |
| 9782 |
param = WMI_RFKILL_ENABLE_RADIO_OFF; |
| 9783 |
|
| 9784 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac %d rfkill enable %d", |
| 9785 |
ar->pdev_idx, param); |
| 9786 |
|
| 9787 |
ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RFKILL_ENABLE, |
| 9788 |
param, ar->pdev->pdev_id); |
| 9789 |
if (ret) { |
| 9790 |
ath12k_warn(ar->ab, "failed to set rfkill enable param %d: %d\n", |
| 9791 |
param, ret); |
| 9792 |
return ret; |
| 9793 |
} |
| 9794 |
|
| 9795 |
return 0; |
| 9796 |
} |
| 9797 |
|
| 9798 |
static void ath12k_mac_stop(struct ath12k *ar) |
| 9799 |
{ |
| 9800 |
struct ath12k_pdev_dp *dp_pdev = &ar->dp; |
| 9801 |
struct ath12k_hw *ah = ar->ah; |
| 9802 |
struct htt_ppdu_stats_info *ppdu_stats, *tmp; |
| 9803 |
struct ath12k_wmi_scan_chan_list_arg *arg; |
| 9804 |
int ret; |
| 9805 |
|
| 9806 |
lockdep_assert_held(&ah->hw_mutex); |
| 9807 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 9808 |
|
| 9809 |
ret = ath12k_mac_config_mon_status_default(ar, false); |
| 9810 |
if (ret && (ret != -EOPNOTSUPP)) |
| 9811 |
ath12k_err(ar->ab, "failed to clear rx_filter for monitor status ring: (%d)\n", |
| 9812 |
ret); |
| 9813 |
|
| 9814 |
clear_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags); |
| 9815 |
|
| 9816 |
cancel_delayed_work_sync(&ar->scan.timeout); |
| 9817 |
wiphy_work_cancel(ath12k_ar_to_hw(ar)->wiphy, &ar->scan.vdev_clean_wk); |
| 9818 |
cancel_work_sync(&ar->regd_channel_update_work); |
| 9819 |
cancel_work_sync(&ar->regd_update_work); |
| 9820 |
cancel_work_sync(&ar->ab->rfkill_work); |
| 9821 |
cancel_work_sync(&ar->ab->update_11d_work); |
| 9822 |
ar->state_11d = ATH12K_11D_IDLE; |
| 9823 |
complete(&ar->completed_11d_scan); |
| 9824 |
|
| 9825 |
spin_lock_bh(&dp_pdev->ppdu_list_lock); |
| 9826 |
list_for_each_entry_safe(ppdu_stats, tmp, &dp_pdev->ppdu_stats_info, list) { |
| 9827 |
list_del(&ppdu_stats->list); |
| 9828 |
kfree(ppdu_stats); |
| 9829 |
} |
| 9830 |
spin_unlock_bh(&dp_pdev->ppdu_list_lock); |
| 9831 |
|
| 9832 |
spin_lock_bh(&ar->data_lock); |
| 9833 |
while ((arg = list_first_entry_or_null(&ar->regd_channel_update_queue, |
| 9834 |
struct ath12k_wmi_scan_chan_list_arg, |
| 9835 |
list))) { |
| 9836 |
list_del(&arg->list); |
| 9837 |
kfree(arg); |
| 9838 |
} |
| 9839 |
spin_unlock_bh(&ar->data_lock); |
| 9840 |
|
| 9841 |
rcu_assign_pointer(ar->ab->pdevs_active[ar->pdev_idx], NULL); |
| 9842 |
|
| 9843 |
synchronize_rcu(); |
| 9844 |
|
| 9845 |
atomic_set(&ar->num_pending_mgmt_tx, 0); |
| 9846 |
} |
| 9847 |
|
| 9848 |
void ath12k_mac_op_stop(struct ieee80211_hw *hw, bool suspend) |
| 9849 |
{ |
| 9850 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 9851 |
struct ath12k *ar; |
| 9852 |
int i; |
| 9853 |
|
| 9854 |
lockdep_assert_wiphy(hw->wiphy); |
| 9855 |
|
| 9856 |
ath12k_drain_tx(ah); |
| 9857 |
|
| 9858 |
mutex_lock(&ah->hw_mutex); |
| 9859 |
|
| 9860 |
ah->state = ATH12K_HW_STATE_OFF; |
| 9861 |
|
| 9862 |
for_each_ar(ah, ar, i) |
| 9863 |
ath12k_mac_stop(ar); |
| 9864 |
|
| 9865 |
mutex_unlock(&ah->hw_mutex); |
| 9866 |
} |
| 9867 |
EXPORT_SYMBOL(ath12k_mac_op_stop); |
| 9868 |
|
| 9869 |
static u8 |
| 9870 |
ath12k_mac_get_vdev_stats_id(struct ath12k_link_vif *arvif) |
| 9871 |
{ |
| 9872 |
struct ath12k_base *ab = arvif->ar->ab; |
| 9873 |
u8 vdev_stats_id = 0; |
| 9874 |
|
| 9875 |
do { |
| 9876 |
if (ab->free_vdev_stats_id_map & (1LL << vdev_stats_id)) { |
| 9877 |
vdev_stats_id++; |
| 9878 |
if (vdev_stats_id >= ATH12K_MAX_VDEV_STATS_ID) { |
| 9879 |
vdev_stats_id = ATH12K_INVAL_VDEV_STATS_ID; |
| 9880 |
break; |
| 9881 |
} |
| 9882 |
} else { |
| 9883 |
ab->free_vdev_stats_id_map |= (1LL << vdev_stats_id); |
| 9884 |
break; |
| 9885 |
} |
| 9886 |
} while (vdev_stats_id); |
| 9887 |
|
| 9888 |
arvif->vdev_stats_id = vdev_stats_id; |
| 9889 |
return vdev_stats_id; |
| 9890 |
} |
| 9891 |
|
| 9892 |
static int ath12k_mac_setup_vdev_params_mbssid(struct ath12k_link_vif *arvif, |
| 9893 |
u32 *flags, u32 *tx_vdev_id) |
| 9894 |
{ |
| 9895 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 9896 |
struct ieee80211_bss_conf *link_conf; |
| 9897 |
struct ath12k *ar = arvif->ar; |
| 9898 |
struct ath12k_link_vif *tx_arvif; |
| 9899 |
|
| 9900 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 9901 |
if (!link_conf) { |
| 9902 |
ath12k_warn(ar->ab, "unable to access bss link conf in set mbssid params for vif %pM link %u\n", |
| 9903 |
ahvif->vif->addr, arvif->link_id); |
| 9904 |
return -ENOLINK; |
| 9905 |
} |
| 9906 |
|
| 9907 |
tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf); |
| 9908 |
if (!tx_arvif) |
| 9909 |
return 0; |
| 9910 |
|
| 9911 |
if (link_conf->nontransmitted) { |
| 9912 |
if (ath12k_ar_to_hw(ar)->wiphy != |
| 9913 |
ath12k_ar_to_hw(tx_arvif->ar)->wiphy) |
| 9914 |
return -EINVAL; |
| 9915 |
|
| 9916 |
*flags = WMI_VDEV_MBSSID_FLAGS_NON_TRANSMIT_AP; |
| 9917 |
*tx_vdev_id = tx_arvif->vdev_id; |
| 9918 |
} else if (tx_arvif == arvif) { |
| 9919 |
*flags = WMI_VDEV_MBSSID_FLAGS_TRANSMIT_AP; |
| 9920 |
} else { |
| 9921 |
return -EINVAL; |
| 9922 |
} |
| 9923 |
|
| 9924 |
if (link_conf->ema_ap) |
| 9925 |
*flags |= WMI_VDEV_MBSSID_FLAGS_EMA_MODE; |
| 9926 |
|
| 9927 |
return 0; |
| 9928 |
} |
| 9929 |
|
| 9930 |
static int ath12k_mac_setup_vdev_create_arg(struct ath12k_link_vif *arvif, |
| 9931 |
struct ath12k_wmi_vdev_create_arg *arg) |
| 9932 |
{ |
| 9933 |
struct ath12k *ar = arvif->ar; |
| 9934 |
struct ath12k_pdev *pdev = ar->pdev; |
| 9935 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 9936 |
int ret; |
| 9937 |
|
| 9938 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 9939 |
|
| 9940 |
arg->if_id = arvif->vdev_id; |
| 9941 |
arg->type = ahvif->vdev_type; |
| 9942 |
arg->subtype = ahvif->vdev_subtype; |
| 9943 |
arg->pdev_id = pdev->pdev_id; |
| 9944 |
|
| 9945 |
arg->mbssid_flags = WMI_VDEV_MBSSID_FLAGS_NON_MBSSID_AP; |
| 9946 |
arg->mbssid_tx_vdev_id = 0; |
| 9947 |
if (!test_bit(WMI_TLV_SERVICE_MBSS_PARAM_IN_VDEV_START_SUPPORT, |
| 9948 |
ar->ab->wmi_ab.svc_map)) { |
| 9949 |
ret = ath12k_mac_setup_vdev_params_mbssid(arvif, |
| 9950 |
&arg->mbssid_flags, |
| 9951 |
&arg->mbssid_tx_vdev_id); |
| 9952 |
if (ret) |
| 9953 |
return ret; |
| 9954 |
} |
| 9955 |
|
| 9956 |
if (pdev->cap.supported_bands & WMI_HOST_WLAN_2GHZ_CAP) { |
| 9957 |
arg->chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains; |
| 9958 |
arg->chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains; |
| 9959 |
} |
| 9960 |
if (pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP) { |
| 9961 |
arg->chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains; |
| 9962 |
arg->chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains; |
| 9963 |
} |
| 9964 |
if (pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP && |
| 9965 |
ar->supports_6ghz) { |
| 9966 |
arg->chains[NL80211_BAND_6GHZ].tx = ar->num_tx_chains; |
| 9967 |
arg->chains[NL80211_BAND_6GHZ].rx = ar->num_rx_chains; |
| 9968 |
} |
| 9969 |
|
| 9970 |
arg->if_stats_id = ath12k_mac_get_vdev_stats_id(arvif); |
| 9971 |
|
| 9972 |
if (ath12k_mac_is_ml_arvif(arvif)) { |
| 9973 |
if (hweight16(ahvif->vif->valid_links) > ATH12K_WMI_MLO_MAX_LINKS) { |
| 9974 |
ath12k_warn(ar->ab, "too many MLO links during setting up vdev: %d", |
| 9975 |
ahvif->vif->valid_links); |
| 9976 |
return -EINVAL; |
| 9977 |
} |
| 9978 |
|
| 9979 |
ether_addr_copy(arg->mld_addr, ahvif->vif->addr); |
| 9980 |
} |
| 9981 |
|
| 9982 |
return 0; |
| 9983 |
} |
| 9984 |
|
| 9985 |
static void ath12k_mac_update_vif_offload(struct ath12k_link_vif *arvif) |
| 9986 |
{ |
| 9987 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 9988 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); |
| 9989 |
struct ath12k *ar = arvif->ar; |
| 9990 |
struct ath12k_base *ab = ar->ab; |
| 9991 |
u32 param_id, param_value; |
| 9992 |
int ret; |
| 9993 |
|
| 9994 |
param_id = WMI_VDEV_PARAM_TX_ENCAP_TYPE; |
| 9995 |
if (vif->type != NL80211_IFTYPE_STATION && |
| 9996 |
vif->type != NL80211_IFTYPE_AP) |
| 9997 |
vif->offload_flags &= ~(IEEE80211_OFFLOAD_ENCAP_ENABLED | |
| 9998 |
IEEE80211_OFFLOAD_DECAP_ENABLED); |
| 9999 |
|
| 10000 |
if (vif->offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED) |
| 10001 |
ahvif->dp_vif.tx_encap_type = ATH12K_HW_TXRX_ETHERNET; |
| 10002 |
else if (test_bit(ATH12K_FLAG_RAW_MODE, &ab->dev_flags)) |
| 10003 |
ahvif->dp_vif.tx_encap_type = ATH12K_HW_TXRX_RAW; |
| 10004 |
else |
| 10005 |
ahvif->dp_vif.tx_encap_type = ATH12K_HW_TXRX_NATIVE_WIFI; |
| 10006 |
|
| 10007 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 10008 |
param_id, ahvif->dp_vif.tx_encap_type); |
| 10009 |
if (ret) { |
| 10010 |
ath12k_warn(ab, "failed to set vdev %d tx encap mode: %d\n", |
| 10011 |
arvif->vdev_id, ret); |
| 10012 |
vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED; |
| 10013 |
} |
| 10014 |
|
| 10015 |
param_id = WMI_VDEV_PARAM_RX_DECAP_TYPE; |
| 10016 |
if (vif->offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED) |
| 10017 |
param_value = ATH12K_HW_TXRX_ETHERNET; |
| 10018 |
else if (test_bit(ATH12K_FLAG_RAW_MODE, &ab->dev_flags)) |
| 10019 |
param_value = ATH12K_HW_TXRX_RAW; |
| 10020 |
else |
| 10021 |
param_value = ATH12K_HW_TXRX_NATIVE_WIFI; |
| 10022 |
|
| 10023 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 10024 |
param_id, param_value); |
| 10025 |
if (ret) { |
| 10026 |
ath12k_warn(ab, "failed to set vdev %d rx decap mode: %d\n", |
| 10027 |
arvif->vdev_id, ret); |
| 10028 |
vif->offload_flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED; |
| 10029 |
} |
| 10030 |
} |
| 10031 |
|
| 10032 |
void ath12k_mac_op_update_vif_offload(struct ieee80211_hw *hw, |
| 10033 |
struct ieee80211_vif *vif) |
| 10034 |
{ |
| 10035 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 10036 |
struct ath12k_link_vif *arvif; |
| 10037 |
unsigned long links; |
| 10038 |
int link_id; |
| 10039 |
|
| 10040 |
lockdep_assert_wiphy(hw->wiphy); |
| 10041 |
|
| 10042 |
if (vif->valid_links) { |
| 10043 |
links = vif->valid_links; |
| 10044 |
for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 10045 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 10046 |
if (!(arvif && arvif->ar)) |
| 10047 |
continue; |
| 10048 |
|
| 10049 |
ath12k_mac_update_vif_offload(arvif); |
| 10050 |
} |
| 10051 |
|
| 10052 |
return; |
| 10053 |
} |
| 10054 |
|
| 10055 |
ath12k_mac_update_vif_offload(&ahvif->deflink); |
| 10056 |
} |
| 10057 |
EXPORT_SYMBOL(ath12k_mac_op_update_vif_offload); |
| 10058 |
|
| 10059 |
static bool ath12k_mac_vif_ap_active_any(struct ath12k_base *ab) |
| 10060 |
{ |
| 10061 |
struct ath12k *ar; |
| 10062 |
struct ath12k_pdev *pdev; |
| 10063 |
struct ath12k_link_vif *arvif; |
| 10064 |
int i; |
| 10065 |
|
| 10066 |
for (i = 0; i < ab->num_radios; i++) { |
| 10067 |
pdev = &ab->pdevs[i]; |
| 10068 |
ar = pdev->ar; |
| 10069 |
list_for_each_entry(arvif, &ar->arvifs, list) { |
| 10070 |
if (arvif->is_up && |
| 10071 |
arvif->ahvif->vdev_type == WMI_VDEV_TYPE_AP) |
| 10072 |
return true; |
| 10073 |
} |
| 10074 |
} |
| 10075 |
return false; |
| 10076 |
} |
| 10077 |
|
| 10078 |
void ath12k_mac_11d_scan_start(struct ath12k *ar, u32 vdev_id) |
| 10079 |
{ |
| 10080 |
struct wmi_11d_scan_start_arg arg; |
| 10081 |
int ret; |
| 10082 |
|
| 10083 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 10084 |
|
| 10085 |
if (ar->regdom_set_by_user) |
| 10086 |
goto fin; |
| 10087 |
|
| 10088 |
if (ar->vdev_id_11d_scan != ATH12K_11D_INVALID_VDEV_ID) |
| 10089 |
goto fin; |
| 10090 |
|
| 10091 |
if (!test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map)) |
| 10092 |
goto fin; |
| 10093 |
|
| 10094 |
if (ath12k_mac_vif_ap_active_any(ar->ab)) |
| 10095 |
goto fin; |
| 10096 |
|
| 10097 |
arg.vdev_id = vdev_id; |
| 10098 |
arg.start_interval_msec = 0; |
| 10099 |
arg.scan_period_msec = ATH12K_SCAN_11D_INTERVAL; |
| 10100 |
|
| 10101 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 10102 |
"mac start 11d scan for vdev %d\n", vdev_id); |
| 10103 |
|
| 10104 |
ret = ath12k_wmi_send_11d_scan_start_cmd(ar, &arg); |
| 10105 |
if (ret) { |
| 10106 |
ath12k_warn(ar->ab, "failed to start 11d scan vdev %d ret: %d\n", |
| 10107 |
vdev_id, ret); |
| 10108 |
} else { |
| 10109 |
ar->vdev_id_11d_scan = vdev_id; |
| 10110 |
if (ar->state_11d == ATH12K_11D_PREPARING) |
| 10111 |
ar->state_11d = ATH12K_11D_RUNNING; |
| 10112 |
} |
| 10113 |
|
| 10114 |
fin: |
| 10115 |
if (ar->state_11d == ATH12K_11D_PREPARING) { |
| 10116 |
ar->state_11d = ATH12K_11D_IDLE; |
| 10117 |
complete(&ar->completed_11d_scan); |
| 10118 |
} |
| 10119 |
} |
| 10120 |
|
| 10121 |
void ath12k_mac_11d_scan_stop(struct ath12k *ar) |
| 10122 |
{ |
| 10123 |
int ret; |
| 10124 |
u32 vdev_id; |
| 10125 |
|
| 10126 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 10127 |
|
| 10128 |
if (!test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map)) |
| 10129 |
return; |
| 10130 |
|
| 10131 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac stop 11d for vdev %d\n", |
| 10132 |
ar->vdev_id_11d_scan); |
| 10133 |
|
| 10134 |
if (ar->state_11d == ATH12K_11D_PREPARING) { |
| 10135 |
ar->state_11d = ATH12K_11D_IDLE; |
| 10136 |
complete(&ar->completed_11d_scan); |
| 10137 |
} |
| 10138 |
|
| 10139 |
if (ar->vdev_id_11d_scan != ATH12K_11D_INVALID_VDEV_ID) { |
| 10140 |
vdev_id = ar->vdev_id_11d_scan; |
| 10141 |
|
| 10142 |
ret = ath12k_wmi_send_11d_scan_stop_cmd(ar, vdev_id); |
| 10143 |
if (ret) { |
| 10144 |
ath12k_warn(ar->ab, |
| 10145 |
"failed to stopt 11d scan vdev %d ret: %d\n", |
| 10146 |
vdev_id, ret); |
| 10147 |
} else { |
| 10148 |
ar->vdev_id_11d_scan = ATH12K_11D_INVALID_VDEV_ID; |
| 10149 |
ar->state_11d = ATH12K_11D_IDLE; |
| 10150 |
complete(&ar->completed_11d_scan); |
| 10151 |
} |
| 10152 |
} |
| 10153 |
} |
| 10154 |
|
| 10155 |
void ath12k_mac_11d_scan_stop_all(struct ath12k_base *ab) |
| 10156 |
{ |
| 10157 |
struct ath12k *ar; |
| 10158 |
struct ath12k_pdev *pdev; |
| 10159 |
int i; |
| 10160 |
|
| 10161 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "mac stop soc 11d scan\n"); |
| 10162 |
|
| 10163 |
for (i = 0; i < ab->num_radios; i++) { |
| 10164 |
pdev = &ab->pdevs[i]; |
| 10165 |
ar = pdev->ar; |
| 10166 |
|
| 10167 |
ath12k_mac_11d_scan_stop(ar); |
| 10168 |
} |
| 10169 |
} |
| 10170 |
|
| 10171 |
static void ath12k_mac_determine_vdev_type(struct ieee80211_vif *vif, |
| 10172 |
struct ath12k_vif *ahvif) |
| 10173 |
{ |
| 10174 |
ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE; |
| 10175 |
|
| 10176 |
switch (vif->type) { |
| 10177 |
case NL80211_IFTYPE_UNSPECIFIED: |
| 10178 |
case NL80211_IFTYPE_STATION: |
| 10179 |
ahvif->vdev_type = WMI_VDEV_TYPE_STA; |
| 10180 |
|
| 10181 |
if (vif->p2p) |
| 10182 |
ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT; |
| 10183 |
|
| 10184 |
break; |
| 10185 |
case NL80211_IFTYPE_MESH_POINT: |
| 10186 |
ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_MESH_11S; |
| 10187 |
fallthrough; |
| 10188 |
case NL80211_IFTYPE_AP: |
| 10189 |
ahvif->vdev_type = WMI_VDEV_TYPE_AP; |
| 10190 |
|
| 10191 |
if (vif->p2p) |
| 10192 |
ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO; |
| 10193 |
|
| 10194 |
break; |
| 10195 |
case NL80211_IFTYPE_MONITOR: |
| 10196 |
ahvif->vdev_type = WMI_VDEV_TYPE_MONITOR; |
| 10197 |
break; |
| 10198 |
case NL80211_IFTYPE_P2P_DEVICE: |
| 10199 |
ahvif->vdev_type = WMI_VDEV_TYPE_STA; |
| 10200 |
ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE; |
| 10201 |
break; |
| 10202 |
default: |
| 10203 |
WARN_ON(1); |
| 10204 |
break; |
| 10205 |
} |
| 10206 |
} |
| 10207 |
|
| 10208 |
int ath12k_mac_vdev_create(struct ath12k *ar, struct ath12k_link_vif *arvif) |
| 10209 |
{ |
| 10210 |
struct ath12k_hw *ah = ar->ah; |
| 10211 |
struct ath12k_base *ab = ar->ab; |
| 10212 |
struct ieee80211_hw *hw = ah->hw; |
| 10213 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 10214 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); |
| 10215 |
struct ath12k_wmi_vdev_create_arg vdev_arg = {}; |
| 10216 |
struct ath12k_wmi_peer_create_arg peer_param = {}; |
| 10217 |
struct ieee80211_bss_conf *link_conf = NULL; |
| 10218 |
u32 param_id, param_value; |
| 10219 |
u16 nss; |
| 10220 |
int i; |
| 10221 |
int ret, vdev_id; |
| 10222 |
u8 link_id; |
| 10223 |
struct ath12k_dp_link_vif *dp_link_vif = NULL; |
| 10224 |
struct ath12k_dp_peer_create_params params = {}; |
| 10225 |
bool dp_peer_created = false; |
| 10226 |
|
| 10227 |
lockdep_assert_wiphy(hw->wiphy); |
| 10228 |
|
| 10229 |
/* In NO_VIRTUAL_MONITOR, its necessary to restrict only one monitor |
| 10230 |
* interface in each radio |
| 10231 |
*/ |
| 10232 |
if (vif->type == NL80211_IFTYPE_MONITOR && ar->monitor_vdev_created) |
| 10233 |
return -EINVAL; |
| 10234 |
|
| 10235 |
if (ar->num_created_vdevs >= TARGET_NUM_VDEVS(ab)) { |
| 10236 |
ath12k_warn(ab, "failed to create vdev, reached max vdev limit %d\n", |
| 10237 |
TARGET_NUM_VDEVS(ab)); |
| 10238 |
return -ENOSPC; |
| 10239 |
} |
| 10240 |
|
| 10241 |
link_id = arvif->link_id; |
| 10242 |
|
| 10243 |
if (link_id < IEEE80211_MLD_MAX_NUM_LINKS) { |
| 10244 |
link_conf = wiphy_dereference(hw->wiphy, vif->link_conf[link_id]); |
| 10245 |
if (!link_conf) { |
| 10246 |
ath12k_warn(ar->ab, "unable to access bss link conf in vdev create for vif %pM link %u\n", |
| 10247 |
vif->addr, arvif->link_id); |
| 10248 |
return -ENOLINK; |
| 10249 |
} |
| 10250 |
} |
| 10251 |
|
| 10252 |
if (link_conf) |
| 10253 |
memcpy(arvif->bssid, link_conf->addr, ETH_ALEN); |
| 10254 |
else |
| 10255 |
memcpy(arvif->bssid, vif->addr, ETH_ALEN); |
| 10256 |
|
| 10257 |
arvif->ar = ar; |
| 10258 |
vdev_id = __ffs64(ab->free_vdev_map); |
| 10259 |
arvif->vdev_id = vdev_id; |
| 10260 |
if (vif->type == NL80211_IFTYPE_MONITOR) |
| 10261 |
ar->monitor_vdev_id = vdev_id; |
| 10262 |
|
| 10263 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev create id %d type %d subtype %d map %llx\n", |
| 10264 |
arvif->vdev_id, ahvif->vdev_type, ahvif->vdev_subtype, |
| 10265 |
ab->free_vdev_map); |
| 10266 |
|
| 10267 |
vif->cab_queue = arvif->vdev_id % (ATH12K_HW_MAX_QUEUES - 1); |
| 10268 |
for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++) |
| 10269 |
vif->hw_queue[i] = i % (ATH12K_HW_MAX_QUEUES - 1); |
| 10270 |
|
| 10271 |
ret = ath12k_mac_setup_vdev_create_arg(arvif, &vdev_arg); |
| 10272 |
if (ret) { |
| 10273 |
ath12k_warn(ab, "failed to create vdev parameters %d: %d\n", |
| 10274 |
arvif->vdev_id, ret); |
| 10275 |
goto err; |
| 10276 |
} |
| 10277 |
|
| 10278 |
ret = ath12k_wmi_vdev_create(ar, arvif->bssid, &vdev_arg); |
| 10279 |
if (ret) { |
| 10280 |
ath12k_warn(ab, "failed to create WMI vdev %d: %d\n", |
| 10281 |
arvif->vdev_id, ret); |
| 10282 |
return ret; |
| 10283 |
} |
| 10284 |
|
| 10285 |
ar->num_created_vdevs++; |
| 10286 |
arvif->is_created = true; |
| 10287 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM created, vdev_id %d\n", |
| 10288 |
vif->addr, arvif->vdev_id); |
| 10289 |
ar->allocated_vdev_map |= 1LL << arvif->vdev_id; |
| 10290 |
ab->free_vdev_map &= ~(1LL << arvif->vdev_id); |
| 10291 |
|
| 10292 |
spin_lock_bh(&ar->data_lock); |
| 10293 |
list_add(&arvif->list, &ar->arvifs); |
| 10294 |
spin_unlock_bh(&ar->data_lock); |
| 10295 |
|
| 10296 |
ath12k_mac_update_vif_offload(arvif); |
| 10297 |
|
| 10298 |
nss = hweight32(ar->cfg_tx_chainmask) ? : 1; |
| 10299 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 10300 |
WMI_VDEV_PARAM_NSS, nss); |
| 10301 |
if (ret) { |
| 10302 |
ath12k_warn(ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n", |
| 10303 |
arvif->vdev_id, ar->cfg_tx_chainmask, nss, ret); |
| 10304 |
goto err_vdev_del; |
| 10305 |
} |
| 10306 |
|
| 10307 |
dp_link_vif = ath12k_dp_vif_to_dp_link_vif(&ahvif->dp_vif, arvif->link_id); |
| 10308 |
|
| 10309 |
dp_link_vif->vdev_id = arvif->vdev_id; |
| 10310 |
dp_link_vif->lmac_id = ar->lmac_id; |
| 10311 |
dp_link_vif->pdev_idx = ar->pdev_idx; |
| 10312 |
|
| 10313 |
switch (ahvif->vdev_type) { |
| 10314 |
case WMI_VDEV_TYPE_AP: |
| 10315 |
params.ucast_ra_only = true; |
| 10316 |
|
| 10317 |
if (arvif->link_id < IEEE80211_MLD_MAX_NUM_LINKS) { |
| 10318 |
ret = ath12k_dp_peer_create(&ah->dp_hw, arvif->bssid, ¶ms); |
| 10319 |
if (ret) { |
| 10320 |
ath12k_warn(ab, "failed to vdev %d create dp_peer for AP: %d\n", |
| 10321 |
arvif->vdev_id, ret); |
| 10322 |
goto err_vdev_del; |
| 10323 |
} |
| 10324 |
dp_peer_created = true; |
| 10325 |
} |
| 10326 |
|
| 10327 |
peer_param.vdev_id = arvif->vdev_id; |
| 10328 |
peer_param.peer_addr = arvif->bssid; |
| 10329 |
peer_param.peer_type = WMI_PEER_TYPE_DEFAULT; |
| 10330 |
ret = ath12k_peer_create(ar, arvif, NULL, &peer_param); |
| 10331 |
if (ret) { |
| 10332 |
ath12k_warn(ab, "failed to vdev %d create peer for AP: %d\n", |
| 10333 |
arvif->vdev_id, ret); |
| 10334 |
goto err_dp_peer_del; |
| 10335 |
} |
| 10336 |
|
| 10337 |
ret = ath12k_mac_set_kickout(arvif); |
| 10338 |
if (ret) { |
| 10339 |
ath12k_warn(ar->ab, "failed to set vdev %i kickout parameters: %d\n", |
| 10340 |
arvif->vdev_id, ret); |
| 10341 |
goto err_peer_del; |
| 10342 |
} |
| 10343 |
ath12k_mac_11d_scan_stop_all(ar->ab); |
| 10344 |
break; |
| 10345 |
case WMI_VDEV_TYPE_STA: |
| 10346 |
param_id = WMI_STA_PS_PARAM_RX_WAKE_POLICY; |
| 10347 |
param_value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; |
| 10348 |
ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 10349 |
param_id, param_value); |
| 10350 |
if (ret) { |
| 10351 |
ath12k_warn(ar->ab, "failed to set vdev %d RX wake policy: %d\n", |
| 10352 |
arvif->vdev_id, ret); |
| 10353 |
goto err_peer_del; |
| 10354 |
} |
| 10355 |
|
| 10356 |
param_id = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD; |
| 10357 |
param_value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS; |
| 10358 |
ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 10359 |
param_id, param_value); |
| 10360 |
if (ret) { |
| 10361 |
ath12k_warn(ar->ab, "failed to set vdev %d TX wake threshold: %d\n", |
| 10362 |
arvif->vdev_id, ret); |
| 10363 |
goto err_peer_del; |
| 10364 |
} |
| 10365 |
|
| 10366 |
param_id = WMI_STA_PS_PARAM_PSPOLL_COUNT; |
| 10367 |
param_value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX; |
| 10368 |
ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 10369 |
param_id, param_value); |
| 10370 |
if (ret) { |
| 10371 |
ath12k_warn(ar->ab, "failed to set vdev %d pspoll count: %d\n", |
| 10372 |
arvif->vdev_id, ret); |
| 10373 |
goto err_peer_del; |
| 10374 |
} |
| 10375 |
|
| 10376 |
ret = ath12k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, false); |
| 10377 |
if (ret) { |
| 10378 |
ath12k_warn(ar->ab, "failed to disable vdev %d ps mode: %d\n", |
| 10379 |
arvif->vdev_id, ret); |
| 10380 |
goto err_peer_del; |
| 10381 |
} |
| 10382 |
|
| 10383 |
if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ab->wmi_ab.svc_map) && |
| 10384 |
ahvif->vdev_type == WMI_VDEV_TYPE_STA && |
| 10385 |
ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) { |
| 10386 |
reinit_completion(&ar->completed_11d_scan); |
| 10387 |
ar->state_11d = ATH12K_11D_PREPARING; |
| 10388 |
} |
| 10389 |
break; |
| 10390 |
case WMI_VDEV_TYPE_MONITOR: |
| 10391 |
ar->monitor_vdev_created = true; |
| 10392 |
break; |
| 10393 |
default: |
| 10394 |
break; |
| 10395 |
} |
| 10396 |
|
| 10397 |
if (link_conf) |
| 10398 |
arvif->txpower = link_conf->txpower; |
| 10399 |
else |
| 10400 |
arvif->txpower = NL80211_TX_POWER_AUTOMATIC; |
| 10401 |
|
| 10402 |
ret = ath12k_mac_txpower_recalc(ar); |
| 10403 |
if (ret) |
| 10404 |
goto err_peer_del; |
| 10405 |
|
| 10406 |
param_id = WMI_VDEV_PARAM_RTS_THRESHOLD; |
| 10407 |
param_value = hw->wiphy->rts_threshold; |
| 10408 |
ar->rts_threshold = param_value; |
| 10409 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 10410 |
param_id, param_value); |
| 10411 |
if (ret) { |
| 10412 |
ath12k_warn(ar->ab, "failed to set rts threshold for vdev %d: %d\n", |
| 10413 |
arvif->vdev_id, ret); |
| 10414 |
} |
| 10415 |
|
| 10416 |
ath12k_dp_vdev_tx_attach(ar, arvif); |
| 10417 |
|
| 10418 |
return ret; |
| 10419 |
|
| 10420 |
err_peer_del: |
| 10421 |
if (ahvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 10422 |
reinit_completion(&ar->peer_delete_done); |
| 10423 |
|
| 10424 |
ret = ath12k_wmi_send_peer_delete_cmd(ar, arvif->bssid, |
| 10425 |
arvif->vdev_id); |
| 10426 |
if (ret) { |
| 10427 |
ath12k_warn(ar->ab, "failed to delete peer vdev_id %d addr %pM\n", |
| 10428 |
arvif->vdev_id, arvif->bssid); |
| 10429 |
goto err; |
| 10430 |
} |
| 10431 |
|
| 10432 |
ret = ath12k_wait_for_peer_delete_done(ar, arvif->vdev_id, |
| 10433 |
arvif->bssid); |
| 10434 |
if (ret) |
| 10435 |
goto err_vdev_del; |
| 10436 |
|
| 10437 |
ar->num_peers--; |
| 10438 |
} |
| 10439 |
|
| 10440 |
err_dp_peer_del: |
| 10441 |
if (dp_peer_created) |
| 10442 |
ath12k_dp_peer_delete(&ah->dp_hw, arvif->bssid, NULL); |
| 10443 |
|
| 10444 |
err_vdev_del: |
| 10445 |
if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { |
| 10446 |
ar->monitor_vdev_id = -1; |
| 10447 |
ar->monitor_vdev_created = false; |
| 10448 |
} |
| 10449 |
|
| 10450 |
ath12k_wmi_vdev_delete(ar, arvif->vdev_id); |
| 10451 |
ar->num_created_vdevs--; |
| 10452 |
arvif->is_created = false; |
| 10453 |
arvif->ar = NULL; |
| 10454 |
ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id); |
| 10455 |
ab->free_vdev_map |= 1LL << arvif->vdev_id; |
| 10456 |
ab->free_vdev_stats_id_map &= ~(1LL << arvif->vdev_stats_id); |
| 10457 |
spin_lock_bh(&ar->data_lock); |
| 10458 |
list_del(&arvif->list); |
| 10459 |
spin_unlock_bh(&ar->data_lock); |
| 10460 |
|
| 10461 |
err: |
| 10462 |
arvif->ar = NULL; |
| 10463 |
return ret; |
| 10464 |
} |
| 10465 |
|
| 10466 |
static void ath12k_mac_vif_flush_key_cache(struct ath12k_link_vif *arvif) |
| 10467 |
{ |
| 10468 |
struct ath12k_key_conf *key_conf, *tmp; |
| 10469 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 10470 |
struct ath12k_hw *ah = ahvif->ah; |
| 10471 |
struct ath12k_sta *ahsta; |
| 10472 |
struct ath12k_link_sta *arsta; |
| 10473 |
struct ath12k_vif_cache *cache = ahvif->cache[arvif->link_id]; |
| 10474 |
int ret; |
| 10475 |
|
| 10476 |
lockdep_assert_wiphy(ah->hw->wiphy); |
| 10477 |
|
| 10478 |
list_for_each_entry_safe(key_conf, tmp, &cache->key_conf.list, list) { |
| 10479 |
arsta = NULL; |
| 10480 |
if (key_conf->sta) { |
| 10481 |
ahsta = ath12k_sta_to_ahsta(key_conf->sta); |
| 10482 |
arsta = wiphy_dereference(ah->hw->wiphy, |
| 10483 |
ahsta->link[arvif->link_id]); |
| 10484 |
if (!arsta) |
| 10485 |
goto free_cache; |
| 10486 |
} |
| 10487 |
|
| 10488 |
ret = ath12k_mac_set_key(arvif->ar, key_conf->cmd, |
| 10489 |
arvif, arsta, |
| 10490 |
key_conf->key); |
| 10491 |
if (ret) |
| 10492 |
ath12k_warn(arvif->ar->ab, "unable to apply set key param to vdev %d ret %d\n", |
| 10493 |
arvif->vdev_id, ret); |
| 10494 |
free_cache: |
| 10495 |
list_del(&key_conf->list); |
| 10496 |
kfree(key_conf); |
| 10497 |
} |
| 10498 |
} |
| 10499 |
|
| 10500 |
static void ath12k_mac_vif_cache_flush(struct ath12k *ar, struct ath12k_link_vif *arvif) |
| 10501 |
{ |
| 10502 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 10503 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); |
| 10504 |
struct ath12k_vif_cache *cache = ahvif->cache[arvif->link_id]; |
| 10505 |
struct ath12k_base *ab = ar->ab; |
| 10506 |
struct ieee80211_bss_conf *link_conf; |
| 10507 |
|
| 10508 |
int ret; |
| 10509 |
|
| 10510 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 10511 |
|
| 10512 |
if (!cache) |
| 10513 |
return; |
| 10514 |
|
| 10515 |
if (cache->tx_conf.changed) { |
| 10516 |
ret = ath12k_mac_conf_tx(arvif, cache->tx_conf.ac, |
| 10517 |
&cache->tx_conf.tx_queue_params); |
| 10518 |
if (ret) |
| 10519 |
ath12k_warn(ab, |
| 10520 |
"unable to apply tx config parameters to vdev %d\n", |
| 10521 |
ret); |
| 10522 |
} |
| 10523 |
|
| 10524 |
if (cache->bss_conf_changed) { |
| 10525 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 10526 |
if (!link_conf) { |
| 10527 |
ath12k_warn(ar->ab, "unable to access bss link conf in cache flush for vif %pM link %u\n", |
| 10528 |
vif->addr, arvif->link_id); |
| 10529 |
return; |
| 10530 |
} |
| 10531 |
ath12k_mac_bss_info_changed(ar, arvif, link_conf, |
| 10532 |
cache->bss_conf_changed); |
| 10533 |
} |
| 10534 |
|
| 10535 |
if (!list_empty(&cache->key_conf.list)) |
| 10536 |
ath12k_mac_vif_flush_key_cache(arvif); |
| 10537 |
|
| 10538 |
ath12k_ahvif_put_link_cache(ahvif, arvif->link_id); |
| 10539 |
} |
| 10540 |
|
| 10541 |
static struct ath12k *ath12k_mac_assign_vif_to_vdev(struct ieee80211_hw *hw, |
| 10542 |
struct ath12k_link_vif *arvif, |
| 10543 |
struct ieee80211_chanctx_conf *ctx) |
| 10544 |
{ |
| 10545 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 10546 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); |
| 10547 |
struct ath12k_link_vif *scan_arvif; |
| 10548 |
struct ath12k_hw *ah = hw->priv; |
| 10549 |
struct ath12k *ar; |
| 10550 |
struct ath12k_base *ab; |
| 10551 |
u8 link_id = arvif->link_id, scan_link_id; |
| 10552 |
unsigned long scan_link_map; |
| 10553 |
int ret; |
| 10554 |
|
| 10555 |
lockdep_assert_wiphy(hw->wiphy); |
| 10556 |
|
| 10557 |
if (ah->num_radio == 1) |
| 10558 |
ar = ah->radio; |
| 10559 |
else if (ctx) |
| 10560 |
ar = ath12k_get_ar_by_ctx(hw, ctx); |
| 10561 |
else |
| 10562 |
return NULL; |
| 10563 |
|
| 10564 |
if (!ar) |
| 10565 |
return NULL; |
| 10566 |
|
| 10567 |
/* cleanup the scan vdev if we are done scan on that ar |
| 10568 |
* and now we want to create for actual usage. |
| 10569 |
*/ |
| 10570 |
if (ieee80211_vif_is_mld(vif)) { |
| 10571 |
scan_link_map = ahvif->links_map & ATH12K_SCAN_LINKS_MASK; |
| 10572 |
for_each_set_bit(scan_link_id, &scan_link_map, ATH12K_NUM_MAX_LINKS) { |
| 10573 |
scan_arvif = wiphy_dereference(hw->wiphy, |
| 10574 |
ahvif->link[scan_link_id]); |
| 10575 |
if (scan_arvif && scan_arvif->ar == ar) { |
| 10576 |
ar->scan.arvif = NULL; |
| 10577 |
ath12k_mac_remove_link_interface(hw, scan_arvif); |
| 10578 |
ath12k_mac_unassign_link_vif(scan_arvif); |
| 10579 |
break; |
| 10580 |
} |
| 10581 |
} |
| 10582 |
} |
| 10583 |
|
| 10584 |
if (arvif->ar) { |
| 10585 |
/* This is not expected really */ |
| 10586 |
if (WARN_ON(!arvif->is_created)) { |
| 10587 |
arvif->ar = NULL; |
| 10588 |
return NULL; |
| 10589 |
} |
| 10590 |
|
| 10591 |
if (ah->num_radio == 1) |
| 10592 |
return arvif->ar; |
| 10593 |
|
| 10594 |
/* This can happen as scan vdev gets created during multiple scans |
| 10595 |
* across different radios before a vdev is brought up in |
| 10596 |
* a certain radio. |
| 10597 |
*/ |
| 10598 |
if (ar != arvif->ar) { |
| 10599 |
if (WARN_ON(arvif->is_started)) |
| 10600 |
return NULL; |
| 10601 |
|
| 10602 |
ath12k_mac_remove_link_interface(hw, arvif); |
| 10603 |
ath12k_mac_unassign_link_vif(arvif); |
| 10604 |
} |
| 10605 |
} |
| 10606 |
|
| 10607 |
ab = ar->ab; |
| 10608 |
|
| 10609 |
/* Assign arvif again here since previous radio switch block |
| 10610 |
* would've unassigned and cleared it. |
| 10611 |
*/ |
| 10612 |
arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); |
| 10613 |
if (vif->type == NL80211_IFTYPE_AP && |
| 10614 |
ar->num_peers > (ar->max_num_peers - 1)) { |
| 10615 |
ath12k_warn(ab, "failed to create vdev due to insufficient peer entry resource in firmware\n"); |
| 10616 |
goto unlock; |
| 10617 |
} |
| 10618 |
|
| 10619 |
if (arvif->is_created) |
| 10620 |
goto flush; |
| 10621 |
|
| 10622 |
ret = ath12k_mac_vdev_create(ar, arvif); |
| 10623 |
if (ret) { |
| 10624 |
ath12k_warn(ab, "failed to create vdev %pM ret %d", vif->addr, ret); |
| 10625 |
goto unlock; |
| 10626 |
} |
| 10627 |
|
| 10628 |
flush: |
| 10629 |
/* If the vdev is created during channel assign and not during |
| 10630 |
* add_interface(), Apply any parameters for the vdev which were received |
| 10631 |
* after add_interface, corresponding to this vif. |
| 10632 |
*/ |
| 10633 |
ath12k_mac_vif_cache_flush(ar, arvif); |
| 10634 |
unlock: |
| 10635 |
return arvif->ar; |
| 10636 |
} |
| 10637 |
|
| 10638 |
int ath12k_mac_op_add_interface(struct ieee80211_hw *hw, |
| 10639 |
struct ieee80211_vif *vif) |
| 10640 |
{ |
| 10641 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 10642 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 10643 |
struct ath12k_reg_info *reg_info; |
| 10644 |
struct ath12k_link_vif *arvif; |
| 10645 |
struct ath12k_base *ab; |
| 10646 |
struct ath12k *ar; |
| 10647 |
int i; |
| 10648 |
|
| 10649 |
lockdep_assert_wiphy(hw->wiphy); |
| 10650 |
|
| 10651 |
memset(ahvif, 0, sizeof(*ahvif)); |
| 10652 |
|
| 10653 |
ahvif->ah = ah; |
| 10654 |
ahvif->vif = vif; |
| 10655 |
arvif = &ahvif->deflink; |
| 10656 |
|
| 10657 |
ath12k_mac_init_arvif(ahvif, arvif, -1); |
| 10658 |
|
| 10659 |
/* Allocate Default Queue now and reassign during actual vdev create */ |
| 10660 |
vif->cab_queue = ATH12K_HW_DEFAULT_QUEUE; |
| 10661 |
for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++) |
| 10662 |
vif->hw_queue[i] = ATH12K_HW_DEFAULT_QUEUE; |
| 10663 |
|
| 10664 |
vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; |
| 10665 |
|
| 10666 |
ath12k_mac_determine_vdev_type(vif, ahvif); |
| 10667 |
|
| 10668 |
for_each_ar(ah, ar, i) { |
| 10669 |
if (!ath12k_wmi_supports_6ghz_cc_ext(ar)) |
| 10670 |
continue; |
| 10671 |
|
| 10672 |
ab = ar->ab; |
| 10673 |
reg_info = ab->reg_info[ar->pdev_idx]; |
| 10674 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "interface added to change reg rules\n"); |
| 10675 |
ah->regd_updated = false; |
| 10676 |
ath12k_reg_handle_chan_list(ab, reg_info, ahvif->vdev_type, |
| 10677 |
IEEE80211_REG_UNSET_AP); |
| 10678 |
break; |
| 10679 |
} |
| 10680 |
|
| 10681 |
/* Defer vdev creation until assign_chanctx or hw_scan is initiated as driver |
| 10682 |
* will not know if this interface is an ML vif at this point. |
| 10683 |
*/ |
| 10684 |
return 0; |
| 10685 |
} |
| 10686 |
EXPORT_SYMBOL(ath12k_mac_op_add_interface); |
| 10687 |
|
| 10688 |
static void ath12k_mac_vif_unref(struct ath12k_dp *dp, struct ieee80211_vif *vif) |
| 10689 |
{ |
| 10690 |
struct ath12k_tx_desc_info *tx_desc_info; |
| 10691 |
struct ath12k_skb_cb *skb_cb; |
| 10692 |
struct sk_buff *skb; |
| 10693 |
int i; |
| 10694 |
|
| 10695 |
for (i = 0; i < ATH12K_HW_MAX_QUEUES; i++) { |
| 10696 |
spin_lock_bh(&dp->tx_desc_lock[i]); |
| 10697 |
|
| 10698 |
list_for_each_entry(tx_desc_info, &dp->tx_desc_used_list[i], |
| 10699 |
list) { |
| 10700 |
skb = tx_desc_info->skb; |
| 10701 |
if (!skb) |
| 10702 |
continue; |
| 10703 |
|
| 10704 |
skb_cb = ATH12K_SKB_CB(skb); |
| 10705 |
if (skb_cb->vif == vif) |
| 10706 |
skb_cb->vif = NULL; |
| 10707 |
} |
| 10708 |
|
| 10709 |
spin_unlock_bh(&dp->tx_desc_lock[i]); |
| 10710 |
} |
| 10711 |
} |
| 10712 |
|
| 10713 |
static int ath12k_mac_vdev_delete(struct ath12k *ar, struct ath12k_link_vif *arvif) |
| 10714 |
{ |
| 10715 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 10716 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); |
| 10717 |
struct ath12k_dp_link_vif *dp_link_vif; |
| 10718 |
struct ath12k_base *ab = ar->ab; |
| 10719 |
unsigned long time_left; |
| 10720 |
int ret; |
| 10721 |
|
| 10722 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 10723 |
|
| 10724 |
reinit_completion(&ar->vdev_delete_done); |
| 10725 |
|
| 10726 |
ret = ath12k_wmi_vdev_delete(ar, arvif->vdev_id); |
| 10727 |
if (ret) { |
| 10728 |
ath12k_warn(ab, "failed to delete WMI vdev %d: %d\n", |
| 10729 |
arvif->vdev_id, ret); |
| 10730 |
goto err_vdev_del; |
| 10731 |
} |
| 10732 |
|
| 10733 |
time_left = wait_for_completion_timeout(&ar->vdev_delete_done, |
| 10734 |
ATH12K_VDEV_DELETE_TIMEOUT_HZ); |
| 10735 |
if (time_left == 0) { |
| 10736 |
ath12k_warn(ab, "Timeout in receiving vdev delete response\n"); |
| 10737 |
goto err_vdev_del; |
| 10738 |
} |
| 10739 |
|
| 10740 |
ab->free_vdev_map |= 1LL << arvif->vdev_id; |
| 10741 |
ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id); |
| 10742 |
ar->num_created_vdevs--; |
| 10743 |
|
| 10744 |
if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { |
| 10745 |
ar->monitor_vdev_id = -1; |
| 10746 |
ar->monitor_vdev_created = false; |
| 10747 |
} |
| 10748 |
|
| 10749 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM deleted, vdev_id %d\n", |
| 10750 |
vif->addr, arvif->vdev_id); |
| 10751 |
|
| 10752 |
err_vdev_del: |
| 10753 |
spin_lock_bh(&ar->data_lock); |
| 10754 |
list_del(&arvif->list); |
| 10755 |
spin_unlock_bh(&ar->data_lock); |
| 10756 |
|
| 10757 |
ath12k_peer_cleanup(ar, arvif->vdev_id); |
| 10758 |
ath12k_ahvif_put_link_cache(ahvif, arvif->link_id); |
| 10759 |
|
| 10760 |
idr_for_each(&ar->txmgmt_idr, |
| 10761 |
ath12k_mac_vif_txmgmt_idr_remove, vif); |
| 10762 |
|
| 10763 |
ath12k_mac_vif_unref(ath12k_ab_to_dp(ab), vif); |
| 10764 |
|
| 10765 |
dp_link_vif = ath12k_dp_vif_to_dp_link_vif(&ahvif->dp_vif, arvif->link_id); |
| 10766 |
ath12k_dp_tx_put_bank_profile(ath12k_ab_to_dp(ab), dp_link_vif->bank_id); |
| 10767 |
|
| 10768 |
/* Recalc txpower for remaining vdev */ |
| 10769 |
ath12k_mac_txpower_recalc(ar); |
| 10770 |
|
| 10771 |
/* TODO: recal traffic pause state based on the available vdevs */ |
| 10772 |
arvif->is_created = false; |
| 10773 |
arvif->ar = NULL; |
| 10774 |
|
| 10775 |
return ret; |
| 10776 |
} |
| 10777 |
|
| 10778 |
void ath12k_mac_op_remove_interface(struct ieee80211_hw *hw, |
| 10779 |
struct ieee80211_vif *vif) |
| 10780 |
{ |
| 10781 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 10782 |
struct ath12k_link_vif *arvif; |
| 10783 |
struct ath12k *ar; |
| 10784 |
u8 link_id; |
| 10785 |
|
| 10786 |
lockdep_assert_wiphy(hw->wiphy); |
| 10787 |
|
| 10788 |
for (link_id = 0; link_id < ATH12K_NUM_MAX_LINKS; link_id++) { |
| 10789 |
/* if we cached some config but never received assign chanctx, |
| 10790 |
* free the allocated cache. |
| 10791 |
*/ |
| 10792 |
ath12k_ahvif_put_link_cache(ahvif, link_id); |
| 10793 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 10794 |
if (!arvif || !arvif->is_created) |
| 10795 |
continue; |
| 10796 |
|
| 10797 |
ar = arvif->ar; |
| 10798 |
|
| 10799 |
/* Scan abortion is in progress since before this, cancel_hw_scan() |
| 10800 |
* is expected to be executed. Since link is anyways going to be removed |
| 10801 |
* now, just cancel the worker and send the scan aborted to user space |
| 10802 |
*/ |
| 10803 |
if (ar->scan.arvif == arvif) { |
| 10804 |
wiphy_work_cancel(hw->wiphy, &ar->scan.vdev_clean_wk); |
| 10805 |
|
| 10806 |
spin_lock_bh(&ar->data_lock); |
| 10807 |
ar->scan.arvif = NULL; |
| 10808 |
if (!ar->scan.is_roc) { |
| 10809 |
struct cfg80211_scan_info info = { |
| 10810 |
.aborted = true, |
| 10811 |
}; |
| 10812 |
|
| 10813 |
ath12k_mac_scan_send_complete(ar, &info); |
| 10814 |
} |
| 10815 |
|
| 10816 |
ar->scan.state = ATH12K_SCAN_IDLE; |
| 10817 |
ar->scan_channel = NULL; |
| 10818 |
ar->scan.roc_freq = 0; |
| 10819 |
spin_unlock_bh(&ar->data_lock); |
| 10820 |
} |
| 10821 |
|
| 10822 |
ath12k_mac_remove_link_interface(hw, arvif); |
| 10823 |
ath12k_mac_unassign_link_vif(arvif); |
| 10824 |
} |
| 10825 |
} |
| 10826 |
EXPORT_SYMBOL(ath12k_mac_op_remove_interface); |
| 10827 |
|
| 10828 |
/* FIXME: Has to be verified. */ |
| 10829 |
#define SUPPORTED_FILTERS \ |
| 10830 |
(FIF_ALLMULTI | \ |
| 10831 |
FIF_CONTROL | \ |
| 10832 |
FIF_PSPOLL | \ |
| 10833 |
FIF_OTHER_BSS | \ |
| 10834 |
FIF_BCN_PRBRESP_PROMISC | \ |
| 10835 |
FIF_PROBE_REQ | \ |
| 10836 |
FIF_FCSFAIL) |
| 10837 |
|
| 10838 |
void ath12k_mac_op_configure_filter(struct ieee80211_hw *hw, |
| 10839 |
unsigned int changed_flags, |
| 10840 |
unsigned int *total_flags, |
| 10841 |
u64 multicast) |
| 10842 |
{ |
| 10843 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 10844 |
struct ath12k *ar; |
| 10845 |
|
| 10846 |
lockdep_assert_wiphy(hw->wiphy); |
| 10847 |
|
| 10848 |
ar = ath12k_ah_to_ar(ah, 0); |
| 10849 |
|
| 10850 |
*total_flags &= SUPPORTED_FILTERS; |
| 10851 |
ar->filter_flags = *total_flags; |
| 10852 |
} |
| 10853 |
EXPORT_SYMBOL(ath12k_mac_op_configure_filter); |
| 10854 |
|
| 10855 |
int ath12k_mac_op_get_antenna(struct ieee80211_hw *hw, int radio_idx, |
| 10856 |
u32 *tx_ant, u32 *rx_ant) |
| 10857 |
{ |
| 10858 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 10859 |
int antennas_rx = 0, antennas_tx = 0; |
| 10860 |
struct ath12k *ar; |
| 10861 |
int i; |
| 10862 |
|
| 10863 |
lockdep_assert_wiphy(hw->wiphy); |
| 10864 |
|
| 10865 |
for_each_ar(ah, ar, i) { |
| 10866 |
antennas_rx = max_t(u32, antennas_rx, ar->cfg_rx_chainmask); |
| 10867 |
antennas_tx = max_t(u32, antennas_tx, ar->cfg_tx_chainmask); |
| 10868 |
} |
| 10869 |
|
| 10870 |
*tx_ant = antennas_tx; |
| 10871 |
*rx_ant = antennas_rx; |
| 10872 |
|
| 10873 |
return 0; |
| 10874 |
} |
| 10875 |
EXPORT_SYMBOL(ath12k_mac_op_get_antenna); |
| 10876 |
|
| 10877 |
int ath12k_mac_op_set_antenna(struct ieee80211_hw *hw, int radio_idx, |
| 10878 |
u32 tx_ant, u32 rx_ant) |
| 10879 |
{ |
| 10880 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 10881 |
struct ath12k *ar; |
| 10882 |
int ret = 0; |
| 10883 |
int i; |
| 10884 |
|
| 10885 |
lockdep_assert_wiphy(hw->wiphy); |
| 10886 |
|
| 10887 |
for_each_ar(ah, ar, i) { |
| 10888 |
ret = __ath12k_set_antenna(ar, tx_ant, rx_ant); |
| 10889 |
if (ret) |
| 10890 |
break; |
| 10891 |
} |
| 10892 |
|
| 10893 |
return ret; |
| 10894 |
} |
| 10895 |
EXPORT_SYMBOL(ath12k_mac_op_set_antenna); |
| 10896 |
|
| 10897 |
static int ath12k_mac_ampdu_action(struct ieee80211_hw *hw, |
| 10898 |
struct ieee80211_vif *vif, |
| 10899 |
struct ieee80211_ampdu_params *params, |
| 10900 |
u8 link_id) |
| 10901 |
{ |
| 10902 |
struct ath12k *ar; |
| 10903 |
int ret = -EINVAL; |
| 10904 |
|
| 10905 |
lockdep_assert_wiphy(hw->wiphy); |
| 10906 |
|
| 10907 |
ar = ath12k_get_ar_by_vif(hw, vif, link_id); |
| 10908 |
if (!ar) |
| 10909 |
return -EINVAL; |
| 10910 |
|
| 10911 |
switch (params->action) { |
| 10912 |
case IEEE80211_AMPDU_RX_START: |
| 10913 |
ret = ath12k_dp_rx_ampdu_start(ar, params, link_id); |
| 10914 |
break; |
| 10915 |
case IEEE80211_AMPDU_RX_STOP: |
| 10916 |
ret = ath12k_dp_rx_ampdu_stop(ar, params, link_id); |
| 10917 |
break; |
| 10918 |
case IEEE80211_AMPDU_TX_START: |
| 10919 |
case IEEE80211_AMPDU_TX_STOP_CONT: |
| 10920 |
case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 10921 |
case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
| 10922 |
case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 10923 |
/* Tx A-MPDU aggregation offloaded to hw/fw so deny mac80211 |
| 10924 |
* Tx aggregation requests. |
| 10925 |
*/ |
| 10926 |
ret = -EOPNOTSUPP; |
| 10927 |
break; |
| 10928 |
} |
| 10929 |
|
| 10930 |
if (ret) |
| 10931 |
ath12k_warn(ar->ab, "unable to perform ampdu action %d for vif %pM link %u ret %d\n", |
| 10932 |
params->action, vif->addr, link_id, ret); |
| 10933 |
|
| 10934 |
return ret; |
| 10935 |
} |
| 10936 |
|
| 10937 |
int ath12k_mac_op_ampdu_action(struct ieee80211_hw *hw, |
| 10938 |
struct ieee80211_vif *vif, |
| 10939 |
struct ieee80211_ampdu_params *params) |
| 10940 |
{ |
| 10941 |
struct ieee80211_sta *sta = params->sta; |
| 10942 |
struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
| 10943 |
unsigned long links_map = ahsta->links_map; |
| 10944 |
int ret = -EINVAL; |
| 10945 |
u8 link_id; |
| 10946 |
|
| 10947 |
lockdep_assert_wiphy(hw->wiphy); |
| 10948 |
|
| 10949 |
if (WARN_ON(!links_map)) |
| 10950 |
return ret; |
| 10951 |
|
| 10952 |
for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 10953 |
ret = ath12k_mac_ampdu_action(hw, vif, params, link_id); |
| 10954 |
if (ret) |
| 10955 |
return ret; |
| 10956 |
} |
| 10957 |
|
| 10958 |
return 0; |
| 10959 |
} |
| 10960 |
EXPORT_SYMBOL(ath12k_mac_op_ampdu_action); |
| 10961 |
|
| 10962 |
int ath12k_mac_op_add_chanctx(struct ieee80211_hw *hw, |
| 10963 |
struct ieee80211_chanctx_conf *ctx) |
| 10964 |
{ |
| 10965 |
struct ath12k *ar; |
| 10966 |
struct ath12k_base *ab; |
| 10967 |
|
| 10968 |
lockdep_assert_wiphy(hw->wiphy); |
| 10969 |
|
| 10970 |
ar = ath12k_get_ar_by_ctx(hw, ctx); |
| 10971 |
if (!ar) |
| 10972 |
return -EINVAL; |
| 10973 |
|
| 10974 |
ab = ar->ab; |
| 10975 |
|
| 10976 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 10977 |
"mac chanctx add freq %u width %d ptr %p\n", |
| 10978 |
ctx->def.chan->center_freq, ctx->def.width, ctx); |
| 10979 |
|
| 10980 |
spin_lock_bh(&ar->data_lock); |
| 10981 |
/* TODO: In case of multiple channel context, populate rx_channel from |
| 10982 |
* Rx PPDU desc information. |
| 10983 |
*/ |
| 10984 |
ar->rx_channel = ctx->def.chan; |
| 10985 |
spin_unlock_bh(&ar->data_lock); |
| 10986 |
ar->chan_tx_pwr = ATH12K_PDEV_TX_POWER_INVALID; |
| 10987 |
|
| 10988 |
return 0; |
| 10989 |
} |
| 10990 |
EXPORT_SYMBOL(ath12k_mac_op_add_chanctx); |
| 10991 |
|
| 10992 |
void ath12k_mac_op_remove_chanctx(struct ieee80211_hw *hw, |
| 10993 |
struct ieee80211_chanctx_conf *ctx) |
| 10994 |
{ |
| 10995 |
struct ath12k *ar; |
| 10996 |
struct ath12k_base *ab; |
| 10997 |
|
| 10998 |
lockdep_assert_wiphy(hw->wiphy); |
| 10999 |
|
| 11000 |
ar = ath12k_get_ar_by_ctx(hw, ctx); |
| 11001 |
if (!ar) |
| 11002 |
return; |
| 11003 |
|
| 11004 |
ab = ar->ab; |
| 11005 |
|
| 11006 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 11007 |
"mac chanctx remove freq %u width %d ptr %p\n", |
| 11008 |
ctx->def.chan->center_freq, ctx->def.width, ctx); |
| 11009 |
|
| 11010 |
spin_lock_bh(&ar->data_lock); |
| 11011 |
/* TODO: In case of there is one more channel context left, populate |
| 11012 |
* rx_channel with the channel of that remaining channel context. |
| 11013 |
*/ |
| 11014 |
ar->rx_channel = NULL; |
| 11015 |
spin_unlock_bh(&ar->data_lock); |
| 11016 |
ar->chan_tx_pwr = ATH12K_PDEV_TX_POWER_INVALID; |
| 11017 |
} |
| 11018 |
EXPORT_SYMBOL(ath12k_mac_op_remove_chanctx); |
| 11019 |
|
| 11020 |
static enum wmi_phy_mode |
| 11021 |
ath12k_mac_check_down_grade_phy_mode(struct ath12k *ar, |
| 11022 |
enum wmi_phy_mode mode, |
| 11023 |
enum nl80211_band band, |
| 11024 |
enum nl80211_iftype type) |
| 11025 |
{ |
| 11026 |
struct ieee80211_sta_eht_cap *eht_cap = NULL; |
| 11027 |
enum wmi_phy_mode down_mode; |
| 11028 |
int n = ar->mac.sbands[band].n_iftype_data; |
| 11029 |
int i; |
| 11030 |
struct ieee80211_sband_iftype_data *data; |
| 11031 |
|
| 11032 |
if (mode < MODE_11BE_EHT20) |
| 11033 |
return mode; |
| 11034 |
|
| 11035 |
data = ar->mac.iftype[band]; |
| 11036 |
for (i = 0; i < n; i++) { |
| 11037 |
if (data[i].types_mask & BIT(type)) { |
| 11038 |
eht_cap = &data[i].eht_cap; |
| 11039 |
break; |
| 11040 |
} |
| 11041 |
} |
| 11042 |
|
| 11043 |
if (eht_cap && eht_cap->has_eht) |
| 11044 |
return mode; |
| 11045 |
|
| 11046 |
switch (mode) { |
| 11047 |
case MODE_11BE_EHT20: |
| 11048 |
down_mode = MODE_11AX_HE20; |
| 11049 |
break; |
| 11050 |
case MODE_11BE_EHT40: |
| 11051 |
down_mode = MODE_11AX_HE40; |
| 11052 |
break; |
| 11053 |
case MODE_11BE_EHT80: |
| 11054 |
down_mode = MODE_11AX_HE80; |
| 11055 |
break; |
| 11056 |
case MODE_11BE_EHT80_80: |
| 11057 |
down_mode = MODE_11AX_HE80_80; |
| 11058 |
break; |
| 11059 |
case MODE_11BE_EHT160: |
| 11060 |
case MODE_11BE_EHT160_160: |
| 11061 |
case MODE_11BE_EHT320: |
| 11062 |
down_mode = MODE_11AX_HE160; |
| 11063 |
break; |
| 11064 |
case MODE_11BE_EHT20_2G: |
| 11065 |
down_mode = MODE_11AX_HE20_2G; |
| 11066 |
break; |
| 11067 |
case MODE_11BE_EHT40_2G: |
| 11068 |
down_mode = MODE_11AX_HE40_2G; |
| 11069 |
break; |
| 11070 |
default: |
| 11071 |
down_mode = mode; |
| 11072 |
break; |
| 11073 |
} |
| 11074 |
|
| 11075 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 11076 |
"mac vdev start phymode %s downgrade to %s\n", |
| 11077 |
ath12k_mac_phymode_str(mode), |
| 11078 |
ath12k_mac_phymode_str(down_mode)); |
| 11079 |
|
| 11080 |
return down_mode; |
| 11081 |
} |
| 11082 |
|
| 11083 |
static void |
| 11084 |
ath12k_mac_mlo_get_vdev_args(struct ath12k_link_vif *arvif, |
| 11085 |
struct wmi_ml_arg *ml_arg) |
| 11086 |
{ |
| 11087 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 11088 |
struct wmi_ml_partner_info *partner_info; |
| 11089 |
struct ieee80211_bss_conf *link_conf; |
| 11090 |
struct ath12k_link_vif *arvif_p; |
| 11091 |
unsigned long links; |
| 11092 |
u8 link_id; |
| 11093 |
|
| 11094 |
lockdep_assert_wiphy(ahvif->ah->hw->wiphy); |
| 11095 |
|
| 11096 |
if (!ath12k_mac_is_ml_arvif(arvif)) |
| 11097 |
return; |
| 11098 |
|
| 11099 |
if (hweight16(ahvif->vif->valid_links) > ATH12K_WMI_MLO_MAX_LINKS) |
| 11100 |
return; |
| 11101 |
|
| 11102 |
ml_arg->enabled = true; |
| 11103 |
|
| 11104 |
/* Driver always add a new link via VDEV START, FW takes |
| 11105 |
* care of internally adding this link to existing |
| 11106 |
* link vdevs which are advertised as partners below |
| 11107 |
*/ |
| 11108 |
ml_arg->link_add = true; |
| 11109 |
|
| 11110 |
ml_arg->assoc_link = arvif->is_sta_assoc_link; |
| 11111 |
|
| 11112 |
partner_info = ml_arg->partner_info; |
| 11113 |
|
| 11114 |
links = ahvif->links_map; |
| 11115 |
for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 11116 |
arvif_p = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]); |
| 11117 |
|
| 11118 |
if (WARN_ON(!arvif_p)) |
| 11119 |
continue; |
| 11120 |
|
| 11121 |
if (arvif == arvif_p) |
| 11122 |
continue; |
| 11123 |
|
| 11124 |
if (!arvif_p->is_created) |
| 11125 |
continue; |
| 11126 |
|
| 11127 |
link_conf = wiphy_dereference(ahvif->ah->hw->wiphy, |
| 11128 |
ahvif->vif->link_conf[arvif_p->link_id]); |
| 11129 |
|
| 11130 |
if (!link_conf) |
| 11131 |
continue; |
| 11132 |
|
| 11133 |
partner_info->vdev_id = arvif_p->vdev_id; |
| 11134 |
partner_info->hw_link_id = arvif_p->ar->pdev->hw_link_id; |
| 11135 |
ether_addr_copy(partner_info->addr, link_conf->addr); |
| 11136 |
ml_arg->num_partner_links++; |
| 11137 |
partner_info++; |
| 11138 |
} |
| 11139 |
} |
| 11140 |
|
| 11141 |
static int |
| 11142 |
ath12k_mac_vdev_start_restart(struct ath12k_link_vif *arvif, |
| 11143 |
struct ieee80211_chanctx_conf *ctx, |
| 11144 |
bool restart) |
| 11145 |
{ |
| 11146 |
struct ath12k *ar = arvif->ar; |
| 11147 |
struct ath12k_base *ab = ar->ab; |
| 11148 |
struct wmi_vdev_start_req_arg arg = {}; |
| 11149 |
const struct cfg80211_chan_def *chandef = &ctx->def; |
| 11150 |
struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
| 11151 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 11152 |
struct ieee80211_bss_conf *link_conf; |
| 11153 |
unsigned int dfs_cac_time; |
| 11154 |
int ret; |
| 11155 |
|
| 11156 |
lockdep_assert_wiphy(hw->wiphy); |
| 11157 |
|
| 11158 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 11159 |
if (!link_conf) { |
| 11160 |
ath12k_warn(ar->ab, "unable to access bss link conf in vdev start for vif %pM link %u\n", |
| 11161 |
ahvif->vif->addr, arvif->link_id); |
| 11162 |
return -ENOLINK; |
| 11163 |
} |
| 11164 |
|
| 11165 |
reinit_completion(&ar->vdev_setup_done); |
| 11166 |
|
| 11167 |
arg.vdev_id = arvif->vdev_id; |
| 11168 |
arg.dtim_period = arvif->dtim_period; |
| 11169 |
arg.bcn_intval = arvif->beacon_interval; |
| 11170 |
arg.punct_bitmap = ~arvif->punct_bitmap; |
| 11171 |
|
| 11172 |
arg.freq = chandef->chan->center_freq; |
| 11173 |
arg.band_center_freq1 = chandef->center_freq1; |
| 11174 |
arg.band_center_freq2 = chandef->center_freq2; |
| 11175 |
arg.mode = ath12k_phymodes[chandef->chan->band][chandef->width]; |
| 11176 |
|
| 11177 |
arg.mode = ath12k_mac_check_down_grade_phy_mode(ar, arg.mode, |
| 11178 |
chandef->chan->band, |
| 11179 |
ahvif->vif->type); |
| 11180 |
arg.min_power = 0; |
| 11181 |
arg.max_power = chandef->chan->max_power; |
| 11182 |
arg.max_reg_power = chandef->chan->max_reg_power; |
| 11183 |
arg.max_antenna_gain = chandef->chan->max_antenna_gain; |
| 11184 |
|
| 11185 |
arg.pref_tx_streams = ar->num_tx_chains; |
| 11186 |
arg.pref_rx_streams = ar->num_rx_chains; |
| 11187 |
|
| 11188 |
arg.mbssid_flags = WMI_VDEV_MBSSID_FLAGS_NON_MBSSID_AP; |
| 11189 |
arg.mbssid_tx_vdev_id = 0; |
| 11190 |
if (test_bit(WMI_TLV_SERVICE_MBSS_PARAM_IN_VDEV_START_SUPPORT, |
| 11191 |
ar->ab->wmi_ab.svc_map)) { |
| 11192 |
ret = ath12k_mac_setup_vdev_params_mbssid(arvif, |
| 11193 |
&arg.mbssid_flags, |
| 11194 |
&arg.mbssid_tx_vdev_id); |
| 11195 |
if (ret) |
| 11196 |
return ret; |
| 11197 |
} |
| 11198 |
|
| 11199 |
if (ahvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 11200 |
arg.ssid = ahvif->u.ap.ssid; |
| 11201 |
arg.ssid_len = ahvif->u.ap.ssid_len; |
| 11202 |
arg.hidden_ssid = ahvif->u.ap.hidden_ssid; |
| 11203 |
|
| 11204 |
/* For now allow DFS for AP mode */ |
| 11205 |
arg.chan_radar = !!(chandef->chan->flags & IEEE80211_CHAN_RADAR); |
| 11206 |
|
| 11207 |
arg.freq2_radar = ctx->radar_enabled; |
| 11208 |
|
| 11209 |
arg.passive = arg.chan_radar; |
| 11210 |
|
| 11211 |
spin_lock_bh(&ab->base_lock); |
| 11212 |
arg.regdomain = ar->ab->dfs_region; |
| 11213 |
spin_unlock_bh(&ab->base_lock); |
| 11214 |
|
| 11215 |
/* TODO: Notify if secondary 80Mhz also needs radar detection */ |
| 11216 |
} |
| 11217 |
|
| 11218 |
arg.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR); |
| 11219 |
|
| 11220 |
if (!restart) |
| 11221 |
ath12k_mac_mlo_get_vdev_args(arvif, &arg.ml); |
| 11222 |
|
| 11223 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 11224 |
"mac vdev %d start center_freq %d phymode %s punct_bitmap 0x%x\n", |
| 11225 |
arg.vdev_id, arg.freq, |
| 11226 |
ath12k_mac_phymode_str(arg.mode), arg.punct_bitmap); |
| 11227 |
|
| 11228 |
ret = ath12k_wmi_vdev_start(ar, &arg, restart); |
| 11229 |
if (ret) { |
| 11230 |
ath12k_warn(ar->ab, "failed to %s WMI vdev %i\n", |
| 11231 |
restart ? "restart" : "start", arg.vdev_id); |
| 11232 |
return ret; |
| 11233 |
} |
| 11234 |
|
| 11235 |
ret = ath12k_mac_vdev_setup_sync(ar); |
| 11236 |
if (ret) { |
| 11237 |
ath12k_warn(ab, "failed to synchronize setup for vdev %i %s: %d\n", |
| 11238 |
arg.vdev_id, restart ? "restart" : "start", ret); |
| 11239 |
return ret; |
| 11240 |
} |
| 11241 |
|
| 11242 |
/* TODO: For now we only set TPC power here. However when |
| 11243 |
* channel changes, say CSA, it should be updated again. |
| 11244 |
*/ |
| 11245 |
if (ath12k_mac_supports_tpc(ar, ahvif, chandef)) { |
| 11246 |
ath12k_mac_fill_reg_tpc_info(ar, arvif, ctx); |
| 11247 |
ath12k_wmi_send_vdev_set_tpc_power(ar, arvif->vdev_id, |
| 11248 |
&arvif->reg_tpc_info); |
| 11249 |
} |
| 11250 |
|
| 11251 |
ar->num_started_vdevs++; |
| 11252 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM started, vdev_id %d\n", |
| 11253 |
ahvif->vif->addr, arvif->vdev_id); |
| 11254 |
|
| 11255 |
/* Enable CAC Running Flag in the driver by checking all sub-channel's DFS |
| 11256 |
* state as NL80211_DFS_USABLE which indicates CAC needs to be |
| 11257 |
* done before channel usage. This flag is used to drop rx packets. |
| 11258 |
* during CAC. |
| 11259 |
*/ |
| 11260 |
/* TODO: Set the flag for other interface types as required */ |
| 11261 |
if (arvif->ahvif->vdev_type == WMI_VDEV_TYPE_AP && ctx->radar_enabled && |
| 11262 |
cfg80211_chandef_dfs_usable(hw->wiphy, chandef)) { |
| 11263 |
set_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags); |
| 11264 |
dfs_cac_time = cfg80211_chandef_dfs_cac_time(hw->wiphy, chandef); |
| 11265 |
|
| 11266 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 11267 |
"CAC started dfs_cac_time %u center_freq %d center_freq1 %d for vdev %d\n", |
| 11268 |
dfs_cac_time, arg.freq, arg.band_center_freq1, arg.vdev_id); |
| 11269 |
} |
| 11270 |
|
| 11271 |
ret = ath12k_mac_set_txbf_conf(arvif); |
| 11272 |
if (ret) |
| 11273 |
ath12k_warn(ab, "failed to set txbf conf for vdev %d: %d\n", |
| 11274 |
arvif->vdev_id, ret); |
| 11275 |
|
| 11276 |
return 0; |
| 11277 |
} |
| 11278 |
|
| 11279 |
static int ath12k_mac_vdev_start(struct ath12k_link_vif *arvif, |
| 11280 |
struct ieee80211_chanctx_conf *ctx) |
| 11281 |
{ |
| 11282 |
return ath12k_mac_vdev_start_restart(arvif, ctx, false); |
| 11283 |
} |
| 11284 |
|
| 11285 |
static int ath12k_mac_vdev_restart(struct ath12k_link_vif *arvif, |
| 11286 |
struct ieee80211_chanctx_conf *ctx) |
| 11287 |
{ |
| 11288 |
return ath12k_mac_vdev_start_restart(arvif, ctx, true); |
| 11289 |
} |
| 11290 |
|
| 11291 |
struct ath12k_mac_change_chanctx_arg { |
| 11292 |
struct ieee80211_chanctx_conf *ctx; |
| 11293 |
struct ieee80211_vif_chanctx_switch *vifs; |
| 11294 |
int n_vifs; |
| 11295 |
int next_vif; |
| 11296 |
struct ath12k *ar; |
| 11297 |
}; |
| 11298 |
|
| 11299 |
static void |
| 11300 |
ath12k_mac_change_chanctx_cnt_iter(void *data, u8 *mac, |
| 11301 |
struct ieee80211_vif *vif) |
| 11302 |
{ |
| 11303 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 11304 |
struct ath12k_mac_change_chanctx_arg *arg = data; |
| 11305 |
struct ieee80211_bss_conf *link_conf; |
| 11306 |
struct ath12k_link_vif *arvif; |
| 11307 |
unsigned long links_map; |
| 11308 |
u8 link_id; |
| 11309 |
|
| 11310 |
lockdep_assert_wiphy(ahvif->ah->hw->wiphy); |
| 11311 |
|
| 11312 |
links_map = ahvif->links_map; |
| 11313 |
for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 11314 |
arvif = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]); |
| 11315 |
if (WARN_ON(!arvif)) |
| 11316 |
continue; |
| 11317 |
|
| 11318 |
if (!arvif->is_created || arvif->ar != arg->ar) |
| 11319 |
continue; |
| 11320 |
|
| 11321 |
link_conf = wiphy_dereference(ahvif->ah->hw->wiphy, |
| 11322 |
vif->link_conf[link_id]); |
| 11323 |
if (WARN_ON(!link_conf)) |
| 11324 |
continue; |
| 11325 |
|
| 11326 |
if (rcu_access_pointer(link_conf->chanctx_conf) != arg->ctx) |
| 11327 |
continue; |
| 11328 |
|
| 11329 |
arg->n_vifs++; |
| 11330 |
} |
| 11331 |
} |
| 11332 |
|
| 11333 |
static void |
| 11334 |
ath12k_mac_change_chanctx_fill_iter(void *data, u8 *mac, |
| 11335 |
struct ieee80211_vif *vif) |
| 11336 |
{ |
| 11337 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 11338 |
struct ath12k_mac_change_chanctx_arg *arg = data; |
| 11339 |
struct ieee80211_bss_conf *link_conf; |
| 11340 |
struct ieee80211_chanctx_conf *ctx; |
| 11341 |
struct ath12k_link_vif *arvif; |
| 11342 |
unsigned long links_map; |
| 11343 |
u8 link_id; |
| 11344 |
|
| 11345 |
lockdep_assert_wiphy(ahvif->ah->hw->wiphy); |
| 11346 |
|
| 11347 |
links_map = ahvif->links_map; |
| 11348 |
for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 11349 |
arvif = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]); |
| 11350 |
if (WARN_ON(!arvif)) |
| 11351 |
continue; |
| 11352 |
|
| 11353 |
if (!arvif->is_created || arvif->ar != arg->ar) |
| 11354 |
continue; |
| 11355 |
|
| 11356 |
link_conf = wiphy_dereference(ahvif->ah->hw->wiphy, |
| 11357 |
vif->link_conf[arvif->link_id]); |
| 11358 |
if (WARN_ON(!link_conf)) |
| 11359 |
continue; |
| 11360 |
|
| 11361 |
ctx = rcu_access_pointer(link_conf->chanctx_conf); |
| 11362 |
if (ctx != arg->ctx) |
| 11363 |
continue; |
| 11364 |
|
| 11365 |
if (WARN_ON(arg->next_vif == arg->n_vifs)) |
| 11366 |
return; |
| 11367 |
|
| 11368 |
arg->vifs[arg->next_vif].vif = vif; |
| 11369 |
arg->vifs[arg->next_vif].old_ctx = ctx; |
| 11370 |
arg->vifs[arg->next_vif].new_ctx = ctx; |
| 11371 |
arg->vifs[arg->next_vif].link_conf = link_conf; |
| 11372 |
arg->next_vif++; |
| 11373 |
} |
| 11374 |
} |
| 11375 |
|
| 11376 |
static u32 ath12k_mac_nlwidth_to_wmiwidth(enum nl80211_chan_width width) |
| 11377 |
{ |
| 11378 |
switch (width) { |
| 11379 |
case NL80211_CHAN_WIDTH_20: |
| 11380 |
return WMI_CHAN_WIDTH_20; |
| 11381 |
case NL80211_CHAN_WIDTH_40: |
| 11382 |
return WMI_CHAN_WIDTH_40; |
| 11383 |
case NL80211_CHAN_WIDTH_80: |
| 11384 |
return WMI_CHAN_WIDTH_80; |
| 11385 |
case NL80211_CHAN_WIDTH_160: |
| 11386 |
return WMI_CHAN_WIDTH_160; |
| 11387 |
case NL80211_CHAN_WIDTH_80P80: |
| 11388 |
return WMI_CHAN_WIDTH_80P80; |
| 11389 |
case NL80211_CHAN_WIDTH_5: |
| 11390 |
return WMI_CHAN_WIDTH_5; |
| 11391 |
case NL80211_CHAN_WIDTH_10: |
| 11392 |
return WMI_CHAN_WIDTH_10; |
| 11393 |
case NL80211_CHAN_WIDTH_320: |
| 11394 |
return WMI_CHAN_WIDTH_320; |
| 11395 |
default: |
| 11396 |
WARN_ON(1); |
| 11397 |
return WMI_CHAN_WIDTH_20; |
| 11398 |
} |
| 11399 |
} |
| 11400 |
|
| 11401 |
static int ath12k_mac_update_peer_puncturing_width(struct ath12k *ar, |
| 11402 |
struct ath12k_link_vif *arvif, |
| 11403 |
struct cfg80211_chan_def def) |
| 11404 |
{ |
| 11405 |
u32 param_id, param_value; |
| 11406 |
int ret; |
| 11407 |
|
| 11408 |
if (arvif->ahvif->vdev_type != WMI_VDEV_TYPE_STA) |
| 11409 |
return 0; |
| 11410 |
|
| 11411 |
param_id = WMI_PEER_CHWIDTH_PUNCTURE_20MHZ_BITMAP; |
| 11412 |
param_value = ath12k_mac_nlwidth_to_wmiwidth(def.width) | |
| 11413 |
u32_encode_bits((~def.punctured), |
| 11414 |
WMI_PEER_PUNCTURE_BITMAP); |
| 11415 |
|
| 11416 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 11417 |
"punctured bitmap %02x width %d vdev %d\n", |
| 11418 |
def.punctured, def.width, arvif->vdev_id); |
| 11419 |
|
| 11420 |
ret = ath12k_wmi_set_peer_param(ar, arvif->bssid, |
| 11421 |
arvif->vdev_id, param_id, |
| 11422 |
param_value); |
| 11423 |
|
| 11424 |
return ret; |
| 11425 |
} |
| 11426 |
|
| 11427 |
static void |
| 11428 |
ath12k_mac_update_vif_chan(struct ath12k *ar, |
| 11429 |
struct ieee80211_vif_chanctx_switch *vifs, |
| 11430 |
int n_vifs) |
| 11431 |
{ |
| 11432 |
struct ath12k_wmi_vdev_up_params params = {}; |
| 11433 |
struct ieee80211_bss_conf *link_conf; |
| 11434 |
struct ath12k_base *ab = ar->ab; |
| 11435 |
struct ath12k_link_vif *arvif; |
| 11436 |
struct ieee80211_vif *vif; |
| 11437 |
struct ath12k_vif *ahvif; |
| 11438 |
u8 link_id; |
| 11439 |
int ret; |
| 11440 |
int i; |
| 11441 |
bool monitor_vif = false; |
| 11442 |
|
| 11443 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 11444 |
|
| 11445 |
for (i = 0; i < n_vifs; i++) { |
| 11446 |
vif = vifs[i].vif; |
| 11447 |
ahvif = ath12k_vif_to_ahvif(vif); |
| 11448 |
link_conf = vifs[i].link_conf; |
| 11449 |
link_id = link_conf->link_id; |
| 11450 |
arvif = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, |
| 11451 |
ahvif->link[link_id]); |
| 11452 |
|
| 11453 |
if (vif->type == NL80211_IFTYPE_MONITOR) { |
| 11454 |
monitor_vif = true; |
| 11455 |
continue; |
| 11456 |
} |
| 11457 |
|
| 11458 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 11459 |
"mac chanctx switch vdev_id %i freq %u->%u width %d->%d\n", |
| 11460 |
arvif->vdev_id, |
| 11461 |
vifs[i].old_ctx->def.chan->center_freq, |
| 11462 |
vifs[i].new_ctx->def.chan->center_freq, |
| 11463 |
vifs[i].old_ctx->def.width, |
| 11464 |
vifs[i].new_ctx->def.width); |
| 11465 |
|
| 11466 |
if (WARN_ON(!arvif->is_started)) |
| 11467 |
continue; |
| 11468 |
|
| 11469 |
arvif->punct_bitmap = vifs[i].new_ctx->def.punctured; |
| 11470 |
|
| 11471 |
/* Firmware expect vdev_restart only if vdev is up. |
| 11472 |
* If vdev is down then it expect vdev_stop->vdev_start. |
| 11473 |
*/ |
| 11474 |
if (arvif->is_up) { |
| 11475 |
ret = ath12k_mac_vdev_restart(arvif, vifs[i].new_ctx); |
| 11476 |
if (ret) { |
| 11477 |
ath12k_warn(ab, "failed to restart vdev %d: %d\n", |
| 11478 |
arvif->vdev_id, ret); |
| 11479 |
continue; |
| 11480 |
} |
| 11481 |
} else { |
| 11482 |
ret = ath12k_mac_vdev_stop(arvif); |
| 11483 |
if (ret) { |
| 11484 |
ath12k_warn(ab, "failed to stop vdev %d: %d\n", |
| 11485 |
arvif->vdev_id, ret); |
| 11486 |
continue; |
| 11487 |
} |
| 11488 |
|
| 11489 |
ret = ath12k_mac_vdev_start(arvif, vifs[i].new_ctx); |
| 11490 |
if (ret) |
| 11491 |
ath12k_warn(ab, "failed to start vdev %d: %d\n", |
| 11492 |
arvif->vdev_id, ret); |
| 11493 |
continue; |
| 11494 |
} |
| 11495 |
|
| 11496 |
ret = ath12k_mac_update_peer_puncturing_width(arvif->ar, arvif, |
| 11497 |
vifs[i].new_ctx->def); |
| 11498 |
if (ret) { |
| 11499 |
ath12k_warn(ar->ab, |
| 11500 |
"failed to update puncturing bitmap %02x and width %d: %d\n", |
| 11501 |
vifs[i].new_ctx->def.punctured, |
| 11502 |
vifs[i].new_ctx->def.width, ret); |
| 11503 |
continue; |
| 11504 |
} |
| 11505 |
|
| 11506 |
/* Defer VDEV bring-up during CSA to avoid installing stale |
| 11507 |
* beacon templates. The beacon content is updated only |
| 11508 |
* after CSA finalize, so we mark CSA in progress and skip |
| 11509 |
* VDEV_UP for now. It will be handled later in |
| 11510 |
* bss_info_changed(). |
| 11511 |
*/ |
| 11512 |
if (link_conf->csa_active && |
| 11513 |
arvif->ahvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 11514 |
arvif->is_csa_in_progress = true; |
| 11515 |
continue; |
| 11516 |
} |
| 11517 |
|
| 11518 |
ret = ath12k_mac_setup_bcn_tmpl(arvif); |
| 11519 |
if (ret) |
| 11520 |
ath12k_warn(ab, "failed to update bcn tmpl during csa: %d\n", |
| 11521 |
ret); |
| 11522 |
|
| 11523 |
memset(¶ms, 0, sizeof(params)); |
| 11524 |
params.vdev_id = arvif->vdev_id; |
| 11525 |
params.aid = ahvif->aid; |
| 11526 |
params.bssid = arvif->bssid; |
| 11527 |
params.tx_bssid = ath12k_mac_get_tx_bssid(arvif); |
| 11528 |
if (params.tx_bssid) { |
| 11529 |
params.nontx_profile_idx = link_conf->bssid_index; |
| 11530 |
params.nontx_profile_cnt = 1 << link_conf->bssid_indicator; |
| 11531 |
} |
| 11532 |
ret = ath12k_wmi_vdev_up(arvif->ar, ¶ms); |
| 11533 |
if (ret) { |
| 11534 |
ath12k_warn(ab, "failed to bring vdev up %d: %d\n", |
| 11535 |
arvif->vdev_id, ret); |
| 11536 |
continue; |
| 11537 |
} |
| 11538 |
} |
| 11539 |
|
| 11540 |
/* Restart the internal monitor vdev on new channel */ |
| 11541 |
if (!monitor_vif && ar->monitor_vdev_created) { |
| 11542 |
if (!ath12k_mac_monitor_stop(ar)) |
| 11543 |
ath12k_mac_monitor_start(ar); |
| 11544 |
} |
| 11545 |
} |
| 11546 |
|
| 11547 |
static void |
| 11548 |
ath12k_mac_update_active_vif_chan(struct ath12k *ar, |
| 11549 |
struct ieee80211_chanctx_conf *ctx) |
| 11550 |
{ |
| 11551 |
struct ath12k_mac_change_chanctx_arg arg = { .ctx = ctx, .ar = ar }; |
| 11552 |
struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
| 11553 |
|
| 11554 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 11555 |
|
| 11556 |
ieee80211_iterate_active_interfaces_atomic(hw, |
| 11557 |
IEEE80211_IFACE_ITER_NORMAL, |
| 11558 |
ath12k_mac_change_chanctx_cnt_iter, |
| 11559 |
&arg); |
| 11560 |
if (arg.n_vifs == 0) |
| 11561 |
return; |
| 11562 |
|
| 11563 |
arg.vifs = kzalloc_objs(arg.vifs[0], arg.n_vifs); |
| 11564 |
if (!arg.vifs) |
| 11565 |
return; |
| 11566 |
|
| 11567 |
ieee80211_iterate_active_interfaces_atomic(hw, |
| 11568 |
IEEE80211_IFACE_ITER_NORMAL, |
| 11569 |
ath12k_mac_change_chanctx_fill_iter, |
| 11570 |
&arg); |
| 11571 |
|
| 11572 |
ath12k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs); |
| 11573 |
|
| 11574 |
kfree(arg.vifs); |
| 11575 |
} |
| 11576 |
|
| 11577 |
void ath12k_mac_op_change_chanctx(struct ieee80211_hw *hw, |
| 11578 |
struct ieee80211_chanctx_conf *ctx, |
| 11579 |
u32 changed) |
| 11580 |
{ |
| 11581 |
struct ath12k *ar; |
| 11582 |
struct ath12k_base *ab; |
| 11583 |
|
| 11584 |
lockdep_assert_wiphy(hw->wiphy); |
| 11585 |
|
| 11586 |
ar = ath12k_get_ar_by_ctx(hw, ctx); |
| 11587 |
if (!ar) |
| 11588 |
return; |
| 11589 |
|
| 11590 |
ab = ar->ab; |
| 11591 |
|
| 11592 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 11593 |
"mac chanctx change freq %u width %d ptr %p changed %x\n", |
| 11594 |
ctx->def.chan->center_freq, ctx->def.width, ctx, changed); |
| 11595 |
|
| 11596 |
/* This shouldn't really happen because channel switching should use |
| 11597 |
* switch_vif_chanctx(). |
| 11598 |
*/ |
| 11599 |
if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL)) |
| 11600 |
return; |
| 11601 |
|
| 11602 |
if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH || |
| 11603 |
changed & IEEE80211_CHANCTX_CHANGE_RADAR || |
| 11604 |
changed & IEEE80211_CHANCTX_CHANGE_PUNCTURING) |
| 11605 |
ath12k_mac_update_active_vif_chan(ar, ctx); |
| 11606 |
|
| 11607 |
/* TODO: Recalc radar detection */ |
| 11608 |
} |
| 11609 |
EXPORT_SYMBOL(ath12k_mac_op_change_chanctx); |
| 11610 |
|
| 11611 |
static int ath12k_start_vdev_delay(struct ath12k *ar, |
| 11612 |
struct ath12k_link_vif *arvif) |
| 11613 |
{ |
| 11614 |
struct ath12k_base *ab = ar->ab; |
| 11615 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 11616 |
struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
| 11617 |
struct ieee80211_chanctx_conf *chanctx; |
| 11618 |
struct ieee80211_bss_conf *link_conf; |
| 11619 |
int ret; |
| 11620 |
|
| 11621 |
if (WARN_ON(arvif->is_started)) |
| 11622 |
return -EBUSY; |
| 11623 |
|
| 11624 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 11625 |
if (!link_conf) { |
| 11626 |
ath12k_warn(ab, "failed to get link conf for vdev %u\n", arvif->vdev_id); |
| 11627 |
return -EINVAL; |
| 11628 |
} |
| 11629 |
|
| 11630 |
chanctx = wiphy_dereference(ath12k_ar_to_hw(arvif->ar)->wiphy, |
| 11631 |
link_conf->chanctx_conf); |
| 11632 |
ret = ath12k_mac_vdev_start(arvif, chanctx); |
| 11633 |
if (ret) { |
| 11634 |
ath12k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n", |
| 11635 |
arvif->vdev_id, vif->addr, |
| 11636 |
chanctx->def.chan->center_freq, ret); |
| 11637 |
return ret; |
| 11638 |
} |
| 11639 |
|
| 11640 |
if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { |
| 11641 |
ret = ath12k_monitor_vdev_up(ar, arvif->vdev_id); |
| 11642 |
if (ret) { |
| 11643 |
ath12k_warn(ab, "failed put monitor up: %d\n", ret); |
| 11644 |
return ret; |
| 11645 |
} |
| 11646 |
} |
| 11647 |
|
| 11648 |
arvif->is_started = true; |
| 11649 |
|
| 11650 |
/* TODO: Setup ps and cts/rts protection */ |
| 11651 |
return 0; |
| 11652 |
} |
| 11653 |
|
| 11654 |
static u8 ath12k_mac_get_num_pwr_levels(struct cfg80211_chan_def *chan_def) |
| 11655 |
{ |
| 11656 |
if (chan_def->chan->flags & IEEE80211_CHAN_PSD) { |
| 11657 |
switch (chan_def->width) { |
| 11658 |
case NL80211_CHAN_WIDTH_20: |
| 11659 |
return 1; |
| 11660 |
case NL80211_CHAN_WIDTH_40: |
| 11661 |
return 2; |
| 11662 |
case NL80211_CHAN_WIDTH_80: |
| 11663 |
return 4; |
| 11664 |
case NL80211_CHAN_WIDTH_160: |
| 11665 |
return 8; |
| 11666 |
case NL80211_CHAN_WIDTH_320: |
| 11667 |
return 16; |
| 11668 |
default: |
| 11669 |
return 1; |
| 11670 |
} |
| 11671 |
} else { |
| 11672 |
switch (chan_def->width) { |
| 11673 |
case NL80211_CHAN_WIDTH_20: |
| 11674 |
return 1; |
| 11675 |
case NL80211_CHAN_WIDTH_40: |
| 11676 |
return 2; |
| 11677 |
case NL80211_CHAN_WIDTH_80: |
| 11678 |
return 3; |
| 11679 |
case NL80211_CHAN_WIDTH_160: |
| 11680 |
return 4; |
| 11681 |
case NL80211_CHAN_WIDTH_320: |
| 11682 |
return 5; |
| 11683 |
default: |
| 11684 |
return 1; |
| 11685 |
} |
| 11686 |
} |
| 11687 |
} |
| 11688 |
|
| 11689 |
static u16 ath12k_mac_get_6ghz_start_frequency(struct cfg80211_chan_def *chan_def) |
| 11690 |
{ |
| 11691 |
u16 diff_seq; |
| 11692 |
|
| 11693 |
/* It is to get the lowest channel number's center frequency of the chan. |
| 11694 |
* For example, |
| 11695 |
* bandwidth=40 MHz, center frequency is 5965, lowest channel is 1 |
| 11696 |
* with center frequency 5955, its diff is 5965 - 5955 = 10. |
| 11697 |
* bandwidth=80 MHz, center frequency is 5985, lowest channel is 1 |
| 11698 |
* with center frequency 5955, its diff is 5985 - 5955 = 30. |
| 11699 |
* bandwidth=160 MHz, center frequency is 6025, lowest channel is 1 |
| 11700 |
* with center frequency 5955, its diff is 6025 - 5955 = 70. |
| 11701 |
* bandwidth=320 MHz, center frequency is 6105, lowest channel is 1 |
| 11702 |
* with center frequency 5955, its diff is 6105 - 5955 = 70. |
| 11703 |
*/ |
| 11704 |
switch (chan_def->width) { |
| 11705 |
case NL80211_CHAN_WIDTH_320: |
| 11706 |
diff_seq = 150; |
| 11707 |
break; |
| 11708 |
case NL80211_CHAN_WIDTH_160: |
| 11709 |
diff_seq = 70; |
| 11710 |
break; |
| 11711 |
case NL80211_CHAN_WIDTH_80: |
| 11712 |
diff_seq = 30; |
| 11713 |
break; |
| 11714 |
case NL80211_CHAN_WIDTH_40: |
| 11715 |
diff_seq = 10; |
| 11716 |
break; |
| 11717 |
default: |
| 11718 |
diff_seq = 0; |
| 11719 |
} |
| 11720 |
|
| 11721 |
return chan_def->center_freq1 - diff_seq; |
| 11722 |
} |
| 11723 |
|
| 11724 |
static u16 ath12k_mac_get_seg_freq(struct cfg80211_chan_def *chan_def, |
| 11725 |
u16 start_seq, u8 seq) |
| 11726 |
{ |
| 11727 |
u16 seg_seq; |
| 11728 |
|
| 11729 |
/* It is to get the center frequency of the specific bandwidth. |
| 11730 |
* start_seq means the lowest channel number's center frequency. |
| 11731 |
* seq 0/1/2/3 means 20 MHz/40 MHz/80 MHz/160 MHz. |
| 11732 |
* For example, |
| 11733 |
* lowest channel is 1, its center frequency 5955, |
| 11734 |
* center frequency is 5955 when bandwidth=20 MHz, its diff is 5955 - 5955 = 0. |
| 11735 |
* lowest channel is 1, its center frequency 5955, |
| 11736 |
* center frequency is 5965 when bandwidth=40 MHz, its diff is 5965 - 5955 = 10. |
| 11737 |
* lowest channel is 1, its center frequency 5955, |
| 11738 |
* center frequency is 5985 when bandwidth=80 MHz, its diff is 5985 - 5955 = 30. |
| 11739 |
* lowest channel is 1, its center frequency 5955, |
| 11740 |
* center frequency is 6025 when bandwidth=160 MHz, its diff is 6025 - 5955 = 70. |
| 11741 |
*/ |
| 11742 |
seg_seq = 10 * (BIT(seq) - 1); |
| 11743 |
return seg_seq + start_seq; |
| 11744 |
} |
| 11745 |
|
| 11746 |
static void ath12k_mac_get_psd_channel(struct ath12k *ar, |
| 11747 |
u16 step_freq, |
| 11748 |
u16 *start_freq, |
| 11749 |
u16 *center_freq, |
| 11750 |
u8 i, |
| 11751 |
struct ieee80211_channel **temp_chan, |
| 11752 |
s8 *tx_power) |
| 11753 |
{ |
| 11754 |
/* It is to get the center frequency for each 20 MHz. |
| 11755 |
* For example, if the chan is 160 MHz and center frequency is 6025, |
| 11756 |
* then it include 8 channels, they are 1/5/9/13/17/21/25/29, |
| 11757 |
* channel number 1's center frequency is 5955, it is parameter start_freq. |
| 11758 |
* parameter i is the step of the 8 channels. i is 0~7 for the 8 channels. |
| 11759 |
* the channel 1/5/9/13/17/21/25/29 maps i=0/1/2/3/4/5/6/7, |
| 11760 |
* and maps its center frequency is 5955/5975/5995/6015/6035/6055/6075/6095, |
| 11761 |
* the gap is 20 for each channel, parameter step_freq means the gap. |
| 11762 |
* after get the center frequency of each channel, it is easy to find the |
| 11763 |
* struct ieee80211_channel of it and get the max_reg_power. |
| 11764 |
*/ |
| 11765 |
*center_freq = *start_freq + i * step_freq; |
| 11766 |
*temp_chan = ieee80211_get_channel(ar->ah->hw->wiphy, *center_freq); |
| 11767 |
*tx_power = (*temp_chan)->max_reg_power; |
| 11768 |
} |
| 11769 |
|
| 11770 |
static void ath12k_mac_get_eirp_power(struct ath12k *ar, |
| 11771 |
u16 *start_freq, |
| 11772 |
u16 *center_freq, |
| 11773 |
u8 i, |
| 11774 |
struct ieee80211_channel **temp_chan, |
| 11775 |
struct cfg80211_chan_def *def, |
| 11776 |
s8 *tx_power) |
| 11777 |
{ |
| 11778 |
/* It is to get the center frequency for 20 MHz/40 MHz/80 MHz/ |
| 11779 |
* 160 MHz bandwidth, and then plus 10 to the center frequency, |
| 11780 |
* it is the center frequency of a channel number. |
| 11781 |
* For example, when configured channel number is 1. |
| 11782 |
* center frequency is 5965 when bandwidth=40 MHz, after plus 10, it is 5975, |
| 11783 |
* then it is channel number 5. |
| 11784 |
* center frequency is 5985 when bandwidth=80 MHz, after plus 10, it is 5995, |
| 11785 |
* then it is channel number 9. |
| 11786 |
* center frequency is 6025 when bandwidth=160 MHz, after plus 10, it is 6035, |
| 11787 |
* then it is channel number 17. |
| 11788 |
* after get the center frequency of each channel, it is easy to find the |
| 11789 |
* struct ieee80211_channel of it and get the max_reg_power. |
| 11790 |
*/ |
| 11791 |
*center_freq = ath12k_mac_get_seg_freq(def, *start_freq, i); |
| 11792 |
|
| 11793 |
/* For the 20 MHz, its center frequency is same with same channel */ |
| 11794 |
if (i != 0) |
| 11795 |
*center_freq += 10; |
| 11796 |
|
| 11797 |
*temp_chan = ieee80211_get_channel(ar->ah->hw->wiphy, *center_freq); |
| 11798 |
*tx_power = (*temp_chan)->max_reg_power; |
| 11799 |
} |
| 11800 |
|
| 11801 |
void ath12k_mac_fill_reg_tpc_info(struct ath12k *ar, |
| 11802 |
struct ath12k_link_vif *arvif, |
| 11803 |
struct ieee80211_chanctx_conf *ctx) |
| 11804 |
{ |
| 11805 |
struct ath12k_base *ab = ar->ab; |
| 11806 |
struct ath12k_reg_tpc_power_info *reg_tpc_info = &arvif->reg_tpc_info; |
| 11807 |
struct ieee80211_bss_conf *bss_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 11808 |
struct ieee80211_channel *chan, *temp_chan; |
| 11809 |
u8 pwr_lvl_idx, num_pwr_levels, pwr_reduction; |
| 11810 |
bool is_psd_power = false, is_tpe_present = false; |
| 11811 |
s8 max_tx_power[ATH12K_NUM_PWR_LEVELS], psd_power, tx_power; |
| 11812 |
s8 eirp_power = 0; |
| 11813 |
struct ath12k_vif *ahvif = arvif->ahvif; |
| 11814 |
u16 start_freq, center_freq; |
| 11815 |
u8 reg_6ghz_power_mode; |
| 11816 |
|
| 11817 |
chan = ctx->def.chan; |
| 11818 |
start_freq = ath12k_mac_get_6ghz_start_frequency(&ctx->def); |
| 11819 |
pwr_reduction = bss_conf->pwr_reduction; |
| 11820 |
|
| 11821 |
if (arvif->reg_tpc_info.num_pwr_levels) { |
| 11822 |
is_tpe_present = true; |
| 11823 |
num_pwr_levels = arvif->reg_tpc_info.num_pwr_levels; |
| 11824 |
} else { |
| 11825 |
num_pwr_levels = ath12k_mac_get_num_pwr_levels(&ctx->def); |
| 11826 |
} |
| 11827 |
|
| 11828 |
for (pwr_lvl_idx = 0; pwr_lvl_idx < num_pwr_levels; pwr_lvl_idx++) { |
| 11829 |
/* STA received TPE IE*/ |
| 11830 |
if (is_tpe_present) { |
| 11831 |
/* local power is PSD power*/ |
| 11832 |
if (chan->flags & IEEE80211_CHAN_PSD) { |
| 11833 |
/* Connecting AP is psd power */ |
| 11834 |
if (reg_tpc_info->is_psd_power) { |
| 11835 |
is_psd_power = true; |
| 11836 |
ath12k_mac_get_psd_channel(ar, 20, |
| 11837 |
&start_freq, |
| 11838 |
¢er_freq, |
| 11839 |
pwr_lvl_idx, |
| 11840 |
&temp_chan, |
| 11841 |
&tx_power); |
| 11842 |
psd_power = temp_chan->psd; |
| 11843 |
eirp_power = tx_power; |
| 11844 |
max_tx_power[pwr_lvl_idx] = |
| 11845 |
min_t(s8, |
| 11846 |
psd_power, |
| 11847 |
reg_tpc_info->tpe[pwr_lvl_idx]); |
| 11848 |
/* Connecting AP is not psd power */ |
| 11849 |
} else { |
| 11850 |
ath12k_mac_get_eirp_power(ar, |
| 11851 |
&start_freq, |
| 11852 |
¢er_freq, |
| 11853 |
pwr_lvl_idx, |
| 11854 |
&temp_chan, |
| 11855 |
&ctx->def, |
| 11856 |
&tx_power); |
| 11857 |
psd_power = temp_chan->psd; |
| 11858 |
/* convert psd power to EIRP power based |
| 11859 |
* on channel width |
| 11860 |
*/ |
| 11861 |
tx_power = |
| 11862 |
min_t(s8, tx_power, |
| 11863 |
psd_power + 13 + pwr_lvl_idx * 3); |
| 11864 |
max_tx_power[pwr_lvl_idx] = |
| 11865 |
min_t(s8, |
| 11866 |
tx_power, |
| 11867 |
reg_tpc_info->tpe[pwr_lvl_idx]); |
| 11868 |
} |
| 11869 |
/* local power is not PSD power */ |
| 11870 |
} else { |
| 11871 |
/* Connecting AP is psd power */ |
| 11872 |
if (reg_tpc_info->is_psd_power) { |
| 11873 |
is_psd_power = true; |
| 11874 |
ath12k_mac_get_psd_channel(ar, 20, |
| 11875 |
&start_freq, |
| 11876 |
¢er_freq, |
| 11877 |
pwr_lvl_idx, |
| 11878 |
&temp_chan, |
| 11879 |
&tx_power); |
| 11880 |
eirp_power = tx_power; |
| 11881 |
max_tx_power[pwr_lvl_idx] = |
| 11882 |
reg_tpc_info->tpe[pwr_lvl_idx]; |
| 11883 |
/* Connecting AP is not psd power */ |
| 11884 |
} else { |
| 11885 |
ath12k_mac_get_eirp_power(ar, |
| 11886 |
&start_freq, |
| 11887 |
¢er_freq, |
| 11888 |
pwr_lvl_idx, |
| 11889 |
&temp_chan, |
| 11890 |
&ctx->def, |
| 11891 |
&tx_power); |
| 11892 |
max_tx_power[pwr_lvl_idx] = |
| 11893 |
min_t(s8, |
| 11894 |
tx_power, |
| 11895 |
reg_tpc_info->tpe[pwr_lvl_idx]); |
| 11896 |
} |
| 11897 |
} |
| 11898 |
/* STA not received TPE IE */ |
| 11899 |
} else { |
| 11900 |
/* local power is PSD power*/ |
| 11901 |
if (chan->flags & IEEE80211_CHAN_PSD) { |
| 11902 |
is_psd_power = true; |
| 11903 |
ath12k_mac_get_psd_channel(ar, 20, |
| 11904 |
&start_freq, |
| 11905 |
¢er_freq, |
| 11906 |
pwr_lvl_idx, |
| 11907 |
&temp_chan, |
| 11908 |
&tx_power); |
| 11909 |
psd_power = temp_chan->psd; |
| 11910 |
eirp_power = tx_power; |
| 11911 |
max_tx_power[pwr_lvl_idx] = psd_power; |
| 11912 |
} else { |
| 11913 |
ath12k_mac_get_eirp_power(ar, |
| 11914 |
&start_freq, |
| 11915 |
¢er_freq, |
| 11916 |
pwr_lvl_idx, |
| 11917 |
&temp_chan, |
| 11918 |
&ctx->def, |
| 11919 |
&tx_power); |
| 11920 |
max_tx_power[pwr_lvl_idx] = tx_power; |
| 11921 |
} |
| 11922 |
} |
| 11923 |
|
| 11924 |
if (is_psd_power) { |
| 11925 |
/* If AP local power constraint is present */ |
| 11926 |
if (pwr_reduction) |
| 11927 |
eirp_power = eirp_power - pwr_reduction; |
| 11928 |
|
| 11929 |
/* If firmware updated max tx power is non zero, then take |
| 11930 |
* the min of firmware updated ap tx power |
| 11931 |
* and max power derived from above mentioned parameters. |
| 11932 |
*/ |
| 11933 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 11934 |
"eirp power : %d firmware report power : %d\n", |
| 11935 |
eirp_power, ar->max_allowed_tx_power); |
| 11936 |
/* Firmware reports lower max_allowed_tx_power during vdev |
| 11937 |
* start response. In case of 6 GHz, firmware is not aware |
| 11938 |
* of EIRP power unless driver sets EIRP power through WMI |
| 11939 |
* TPC command. So radio which does not support idle power |
| 11940 |
* save can set maximum calculated EIRP power directly to |
| 11941 |
* firmware through TPC command without min comparison with |
| 11942 |
* vdev start response's max_allowed_tx_power. |
| 11943 |
*/ |
| 11944 |
if (ar->max_allowed_tx_power && ab->hw_params->idle_ps) |
| 11945 |
eirp_power = min_t(s8, |
| 11946 |
eirp_power, |
| 11947 |
ar->max_allowed_tx_power); |
| 11948 |
} else { |
| 11949 |
/* If AP local power constraint is present */ |
| 11950 |
if (pwr_reduction) |
| 11951 |
max_tx_power[pwr_lvl_idx] = |
| 11952 |
max_tx_power[pwr_lvl_idx] - pwr_reduction; |
| 11953 |
/* If firmware updated max tx power is non zero, then take |
| 11954 |
* the min of firmware updated ap tx power |
| 11955 |
* and max power derived from above mentioned parameters. |
| 11956 |
*/ |
| 11957 |
if (ar->max_allowed_tx_power && ab->hw_params->idle_ps) |
| 11958 |
max_tx_power[pwr_lvl_idx] = |
| 11959 |
min_t(s8, |
| 11960 |
max_tx_power[pwr_lvl_idx], |
| 11961 |
ar->max_allowed_tx_power); |
| 11962 |
} |
| 11963 |
reg_tpc_info->chan_power_info[pwr_lvl_idx].chan_cfreq = center_freq; |
| 11964 |
reg_tpc_info->chan_power_info[pwr_lvl_idx].tx_power = |
| 11965 |
max_tx_power[pwr_lvl_idx]; |
| 11966 |
} |
| 11967 |
|
| 11968 |
reg_tpc_info->num_pwr_levels = num_pwr_levels; |
| 11969 |
reg_tpc_info->is_psd_power = is_psd_power; |
| 11970 |
reg_tpc_info->eirp_power = eirp_power; |
| 11971 |
if (ahvif->vdev_type == WMI_VDEV_TYPE_STA) |
| 11972 |
reg_6ghz_power_mode = bss_conf->power_type; |
| 11973 |
else |
| 11974 |
/* For now, LPI is the only supported AP power mode */ |
| 11975 |
reg_6ghz_power_mode = IEEE80211_REG_LPI_AP; |
| 11976 |
|
| 11977 |
reg_tpc_info->ap_power_type = |
| 11978 |
ath12k_reg_ap_pwr_convert(reg_6ghz_power_mode); |
| 11979 |
} |
| 11980 |
|
| 11981 |
static void ath12k_mac_parse_tx_pwr_env(struct ath12k *ar, |
| 11982 |
struct ath12k_link_vif *arvif) |
| 11983 |
{ |
| 11984 |
struct ieee80211_bss_conf *bss_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 11985 |
struct ath12k_reg_tpc_power_info *tpc_info = &arvif->reg_tpc_info; |
| 11986 |
struct ieee80211_parsed_tpe_eirp *local_non_psd, *reg_non_psd; |
| 11987 |
struct ieee80211_parsed_tpe_psd *local_psd, *reg_psd; |
| 11988 |
struct ieee80211_parsed_tpe *tpe = &bss_conf->tpe; |
| 11989 |
enum wmi_reg_6g_client_type client_type; |
| 11990 |
struct ath12k_reg_info *reg_info; |
| 11991 |
struct ath12k_base *ab = ar->ab; |
| 11992 |
bool psd_valid, non_psd_valid; |
| 11993 |
int i; |
| 11994 |
|
| 11995 |
reg_info = ab->reg_info[ar->pdev_idx]; |
| 11996 |
client_type = reg_info->client_type; |
| 11997 |
|
| 11998 |
local_psd = &tpe->psd_local[client_type]; |
| 11999 |
reg_psd = &tpe->psd_reg_client[client_type]; |
| 12000 |
local_non_psd = &tpe->max_local[client_type]; |
| 12001 |
reg_non_psd = &tpe->max_reg_client[client_type]; |
| 12002 |
|
| 12003 |
psd_valid = local_psd->valid | reg_psd->valid; |
| 12004 |
non_psd_valid = local_non_psd->valid | reg_non_psd->valid; |
| 12005 |
|
| 12006 |
if (!psd_valid && !non_psd_valid) { |
| 12007 |
ath12k_warn(ab, |
| 12008 |
"no transmit power envelope match client power type %d\n", |
| 12009 |
client_type); |
| 12010 |
return; |
| 12011 |
} |
| 12012 |
|
| 12013 |
if (psd_valid) { |
| 12014 |
tpc_info->is_psd_power = true; |
| 12015 |
|
| 12016 |
tpc_info->num_pwr_levels = max(local_psd->count, |
| 12017 |
reg_psd->count); |
| 12018 |
tpc_info->num_pwr_levels = |
| 12019 |
min3(tpc_info->num_pwr_levels, |
| 12020 |
IEEE80211_TPE_PSD_ENTRIES_320MHZ, |
| 12021 |
ATH12K_NUM_PWR_LEVELS); |
| 12022 |
|
| 12023 |
for (i = 0; i < tpc_info->num_pwr_levels; i++) { |
| 12024 |
tpc_info->tpe[i] = min(local_psd->power[i], |
| 12025 |
reg_psd->power[i]) / 2; |
| 12026 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 12027 |
"TPE PSD power[%d] : %d\n", |
| 12028 |
i, tpc_info->tpe[i]); |
| 12029 |
} |
| 12030 |
} else { |
| 12031 |
tpc_info->is_psd_power = false; |
| 12032 |
tpc_info->eirp_power = 0; |
| 12033 |
|
| 12034 |
tpc_info->num_pwr_levels = max(local_non_psd->count, |
| 12035 |
reg_non_psd->count); |
| 12036 |
tpc_info->num_pwr_levels = |
| 12037 |
min3(tpc_info->num_pwr_levels, |
| 12038 |
IEEE80211_TPE_EIRP_ENTRIES_320MHZ, |
| 12039 |
ATH12K_NUM_PWR_LEVELS); |
| 12040 |
|
| 12041 |
for (i = 0; i < tpc_info->num_pwr_levels; i++) { |
| 12042 |
tpc_info->tpe[i] = min(local_non_psd->power[i], |
| 12043 |
reg_non_psd->power[i]) / 2; |
| 12044 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 12045 |
"non PSD power[%d] : %d\n", |
| 12046 |
i, tpc_info->tpe[i]); |
| 12047 |
} |
| 12048 |
} |
| 12049 |
} |
| 12050 |
|
| 12051 |
int |
| 12052 |
ath12k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 12053 |
struct ieee80211_vif *vif, |
| 12054 |
struct ieee80211_bss_conf *link_conf, |
| 12055 |
struct ieee80211_chanctx_conf *ctx) |
| 12056 |
{ |
| 12057 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 12058 |
struct ath12k *ar; |
| 12059 |
struct ath12k_base *ab; |
| 12060 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 12061 |
u8 link_id = link_conf->link_id; |
| 12062 |
struct ath12k_link_vif *arvif; |
| 12063 |
int ret; |
| 12064 |
|
| 12065 |
lockdep_assert_wiphy(hw->wiphy); |
| 12066 |
|
| 12067 |
/* For multi radio wiphy, the vdev was not created during add_interface |
| 12068 |
* create now since we have a channel ctx now to assign to a specific ar/fw |
| 12069 |
*/ |
| 12070 |
arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); |
| 12071 |
if (!arvif) { |
| 12072 |
WARN_ON(1); |
| 12073 |
return -ENOMEM; |
| 12074 |
} |
| 12075 |
|
| 12076 |
ar = ath12k_mac_assign_vif_to_vdev(hw, arvif, ctx); |
| 12077 |
if (!ar) { |
| 12078 |
ath12k_hw_warn(ah, "failed to assign chanctx for vif %pM link id %u link vif is already started", |
| 12079 |
vif->addr, link_id); |
| 12080 |
return -EINVAL; |
| 12081 |
} |
| 12082 |
|
| 12083 |
ab = ar->ab; |
| 12084 |
|
| 12085 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 12086 |
"mac chanctx assign ptr %p vdev_id %i\n", |
| 12087 |
ctx, arvif->vdev_id); |
| 12088 |
|
| 12089 |
if (ath12k_wmi_supports_6ghz_cc_ext(ar) && |
| 12090 |
ctx->def.chan->band == NL80211_BAND_6GHZ && |
| 12091 |
ahvif->vdev_type == WMI_VDEV_TYPE_STA) |
| 12092 |
ath12k_mac_parse_tx_pwr_env(ar, arvif); |
| 12093 |
|
| 12094 |
arvif->punct_bitmap = ctx->def.punctured; |
| 12095 |
|
| 12096 |
/* for some targets bss peer must be created before vdev_start */ |
| 12097 |
if (ab->hw_params->vdev_start_delay && |
| 12098 |
ahvif->vdev_type != WMI_VDEV_TYPE_AP && |
| 12099 |
ahvif->vdev_type != WMI_VDEV_TYPE_MONITOR && |
| 12100 |
!ath12k_dp_link_peer_exist_by_vdev_id(ath12k_ab_to_dp(ab), arvif->vdev_id)) { |
| 12101 |
ret = 0; |
| 12102 |
goto out; |
| 12103 |
} |
| 12104 |
|
| 12105 |
if (WARN_ON(arvif->is_started)) { |
| 12106 |
ret = -EBUSY; |
| 12107 |
goto out; |
| 12108 |
} |
| 12109 |
|
| 12110 |
if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { |
| 12111 |
ret = ath12k_mac_monitor_start(ar); |
| 12112 |
if (ret) { |
| 12113 |
ath12k_mac_monitor_vdev_delete(ar); |
| 12114 |
goto out; |
| 12115 |
} |
| 12116 |
|
| 12117 |
arvif->is_started = true; |
| 12118 |
goto out; |
| 12119 |
} |
| 12120 |
|
| 12121 |
ret = ath12k_mac_vdev_start(arvif, ctx); |
| 12122 |
if (ret) { |
| 12123 |
ath12k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n", |
| 12124 |
arvif->vdev_id, vif->addr, |
| 12125 |
ctx->def.chan->center_freq, ret); |
| 12126 |
goto out; |
| 12127 |
} |
| 12128 |
|
| 12129 |
arvif->is_started = true; |
| 12130 |
|
| 12131 |
/* TODO: Setup ps and cts/rts protection */ |
| 12132 |
|
| 12133 |
out: |
| 12134 |
return ret; |
| 12135 |
} |
| 12136 |
EXPORT_SYMBOL(ath12k_mac_op_assign_vif_chanctx); |
| 12137 |
|
| 12138 |
void |
| 12139 |
ath12k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 12140 |
struct ieee80211_vif *vif, |
| 12141 |
struct ieee80211_bss_conf *link_conf, |
| 12142 |
struct ieee80211_chanctx_conf *ctx) |
| 12143 |
{ |
| 12144 |
struct ath12k *ar; |
| 12145 |
struct ath12k_base *ab; |
| 12146 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 12147 |
struct ath12k_link_vif *arvif; |
| 12148 |
u8 link_id = link_conf->link_id; |
| 12149 |
int ret; |
| 12150 |
|
| 12151 |
lockdep_assert_wiphy(hw->wiphy); |
| 12152 |
|
| 12153 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 12154 |
|
| 12155 |
/* The vif is expected to be attached to an ar's VDEV. |
| 12156 |
* We leave the vif/vdev in this function as is |
| 12157 |
* and not delete the vdev symmetric to assign_vif_chanctx() |
| 12158 |
* the VDEV will be deleted and unassigned either during |
| 12159 |
* remove_interface() or when there is a change in channel |
| 12160 |
* that moves the vif to a new ar |
| 12161 |
*/ |
| 12162 |
if (!arvif || !arvif->is_created) |
| 12163 |
return; |
| 12164 |
|
| 12165 |
ar = arvif->ar; |
| 12166 |
ab = ar->ab; |
| 12167 |
|
| 12168 |
ath12k_dbg(ab, ATH12K_DBG_MAC, |
| 12169 |
"mac chanctx unassign ptr %p vdev_id %i\n", |
| 12170 |
ctx, arvif->vdev_id); |
| 12171 |
|
| 12172 |
WARN_ON(!arvif->is_started); |
| 12173 |
|
| 12174 |
if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { |
| 12175 |
ret = ath12k_mac_monitor_stop(ar); |
| 12176 |
if (ret) |
| 12177 |
return; |
| 12178 |
|
| 12179 |
arvif->is_started = false; |
| 12180 |
} |
| 12181 |
|
| 12182 |
if (ahvif->vdev_type != WMI_VDEV_TYPE_STA && |
| 12183 |
ahvif->vdev_type != WMI_VDEV_TYPE_MONITOR) { |
| 12184 |
ath12k_bss_disassoc(ar, arvif); |
| 12185 |
ret = ath12k_mac_vdev_stop(arvif); |
| 12186 |
if (ret) |
| 12187 |
ath12k_warn(ab, "failed to stop vdev %i: %d\n", |
| 12188 |
arvif->vdev_id, ret); |
| 12189 |
} |
| 12190 |
arvif->is_started = false; |
| 12191 |
|
| 12192 |
if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ab->wmi_ab.svc_map) && |
| 12193 |
ahvif->vdev_type == WMI_VDEV_TYPE_STA && |
| 12194 |
ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE && |
| 12195 |
ar->state_11d != ATH12K_11D_PREPARING) { |
| 12196 |
reinit_completion(&ar->completed_11d_scan); |
| 12197 |
ar->state_11d = ATH12K_11D_PREPARING; |
| 12198 |
} |
| 12199 |
|
| 12200 |
if (ar->scan.arvif == arvif && ar->scan.state == ATH12K_SCAN_RUNNING) { |
| 12201 |
ath12k_scan_abort(ar); |
| 12202 |
ar->scan.arvif = NULL; |
| 12203 |
} |
| 12204 |
} |
| 12205 |
EXPORT_SYMBOL(ath12k_mac_op_unassign_vif_chanctx); |
| 12206 |
|
| 12207 |
int |
| 12208 |
ath12k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw, |
| 12209 |
struct ieee80211_vif_chanctx_switch *vifs, |
| 12210 |
int n_vifs, |
| 12211 |
enum ieee80211_chanctx_switch_mode mode) |
| 12212 |
{ |
| 12213 |
struct ath12k *ar; |
| 12214 |
|
| 12215 |
lockdep_assert_wiphy(hw->wiphy); |
| 12216 |
|
| 12217 |
ar = ath12k_get_ar_by_ctx(hw, vifs->old_ctx); |
| 12218 |
if (!ar) |
| 12219 |
return -EINVAL; |
| 12220 |
|
| 12221 |
/* Switching channels across radio is not allowed */ |
| 12222 |
if (ar != ath12k_get_ar_by_ctx(hw, vifs->new_ctx)) |
| 12223 |
return -EINVAL; |
| 12224 |
|
| 12225 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 12226 |
"mac chanctx switch n_vifs %d mode %d\n", |
| 12227 |
n_vifs, mode); |
| 12228 |
ath12k_mac_update_vif_chan(ar, vifs, n_vifs); |
| 12229 |
|
| 12230 |
return 0; |
| 12231 |
} |
| 12232 |
EXPORT_SYMBOL(ath12k_mac_op_switch_vif_chanctx); |
| 12233 |
|
| 12234 |
static int |
| 12235 |
ath12k_set_vdev_param_to_all_vifs(struct ath12k *ar, int param, u32 value) |
| 12236 |
{ |
| 12237 |
struct ath12k_link_vif *arvif; |
| 12238 |
int ret = 0; |
| 12239 |
|
| 12240 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 12241 |
|
| 12242 |
list_for_each_entry(arvif, &ar->arvifs, list) { |
| 12243 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "setting mac vdev %d param %d value %d\n", |
| 12244 |
param, arvif->vdev_id, value); |
| 12245 |
|
| 12246 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 12247 |
param, value); |
| 12248 |
if (ret) { |
| 12249 |
ath12k_warn(ar->ab, "failed to set param %d for vdev %d: %d\n", |
| 12250 |
param, arvif->vdev_id, ret); |
| 12251 |
break; |
| 12252 |
} |
| 12253 |
} |
| 12254 |
|
| 12255 |
return ret; |
| 12256 |
} |
| 12257 |
|
| 12258 |
/* mac80211 stores device specific RTS/Fragmentation threshold value, |
| 12259 |
* this is set interface specific to firmware from ath12k driver |
| 12260 |
*/ |
| 12261 |
int ath12k_mac_op_set_rts_threshold(struct ieee80211_hw *hw, |
| 12262 |
int radio_idx, u32 value) |
| 12263 |
{ |
| 12264 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 12265 |
struct wiphy *wiphy = hw->wiphy; |
| 12266 |
struct ath12k *ar; |
| 12267 |
int param_id = WMI_VDEV_PARAM_RTS_THRESHOLD; |
| 12268 |
int ret = 0, ret_err, i; |
| 12269 |
|
| 12270 |
lockdep_assert_wiphy(hw->wiphy); |
| 12271 |
|
| 12272 |
if (radio_idx >= wiphy->n_radio || radio_idx < -1) |
| 12273 |
return -EINVAL; |
| 12274 |
|
| 12275 |
if (radio_idx != -1) { |
| 12276 |
/* Update RTS threshold in specified radio */ |
| 12277 |
ar = ath12k_ah_to_ar(ah, radio_idx); |
| 12278 |
ret = ath12k_set_vdev_param_to_all_vifs(ar, param_id, value); |
| 12279 |
if (ret) { |
| 12280 |
ath12k_warn(ar->ab, |
| 12281 |
"failed to set RTS config for all vdevs of pdev %d", |
| 12282 |
ar->pdev->pdev_id); |
| 12283 |
return ret; |
| 12284 |
} |
| 12285 |
|
| 12286 |
ar->rts_threshold = value; |
| 12287 |
return 0; |
| 12288 |
} |
| 12289 |
|
| 12290 |
/* Radio_index passed is -1, so set RTS threshold for all radios. */ |
| 12291 |
for_each_ar(ah, ar, i) { |
| 12292 |
ret = ath12k_set_vdev_param_to_all_vifs(ar, param_id, value); |
| 12293 |
if (ret) { |
| 12294 |
ath12k_warn(ar->ab, "failed to set RTS config for all vdevs of pdev %d", |
| 12295 |
ar->pdev->pdev_id); |
| 12296 |
break; |
| 12297 |
} |
| 12298 |
} |
| 12299 |
if (!ret) { |
| 12300 |
/* Setting new RTS threshold for vdevs of all radios passed, so update |
| 12301 |
* the RTS threshold value for all radios |
| 12302 |
*/ |
| 12303 |
for_each_ar(ah, ar, i) |
| 12304 |
ar->rts_threshold = value; |
| 12305 |
return 0; |
| 12306 |
} |
| 12307 |
|
| 12308 |
/* RTS threshold config failed, revert to the previous RTS threshold */ |
| 12309 |
for (i = i - 1; i >= 0; i--) { |
| 12310 |
ar = ath12k_ah_to_ar(ah, i); |
| 12311 |
ret_err = ath12k_set_vdev_param_to_all_vifs(ar, param_id, |
| 12312 |
ar->rts_threshold); |
| 12313 |
if (ret_err) |
| 12314 |
ath12k_warn(ar->ab, |
| 12315 |
"failed to restore RTS threshold for all vdevs of pdev %d", |
| 12316 |
ar->pdev->pdev_id); |
| 12317 |
} |
| 12318 |
|
| 12319 |
return ret; |
| 12320 |
} |
| 12321 |
EXPORT_SYMBOL(ath12k_mac_op_set_rts_threshold); |
| 12322 |
|
| 12323 |
int ath12k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, |
| 12324 |
int radio_idx, u32 value) |
| 12325 |
{ |
| 12326 |
/* Even though there's a WMI vdev param for fragmentation threshold no |
| 12327 |
* known firmware actually implements it. Moreover it is not possible to |
| 12328 |
* rely frame fragmentation to mac80211 because firmware clears the |
| 12329 |
* "more fragments" bit in frame control making it impossible for remote |
| 12330 |
* devices to reassemble frames. |
| 12331 |
* |
| 12332 |
* Hence implement a dummy callback just to say fragmentation isn't |
| 12333 |
* supported. This effectively prevents mac80211 from doing frame |
| 12334 |
* fragmentation in software. |
| 12335 |
*/ |
| 12336 |
|
| 12337 |
lockdep_assert_wiphy(hw->wiphy); |
| 12338 |
|
| 12339 |
return -EOPNOTSUPP; |
| 12340 |
} |
| 12341 |
EXPORT_SYMBOL(ath12k_mac_op_set_frag_threshold); |
| 12342 |
|
| 12343 |
static int ath12k_mac_flush(struct ath12k *ar) |
| 12344 |
{ |
| 12345 |
long time_left; |
| 12346 |
int ret = 0; |
| 12347 |
|
| 12348 |
time_left = wait_event_timeout(ar->dp.tx_empty_waitq, |
| 12349 |
(atomic_read(&ar->dp.num_tx_pending) == 0), |
| 12350 |
ATH12K_FLUSH_TIMEOUT); |
| 12351 |
if (time_left == 0) { |
| 12352 |
ath12k_warn(ar->ab, |
| 12353 |
"failed to flush transmit queue, data pkts pending %d\n", |
| 12354 |
atomic_read(&ar->dp.num_tx_pending)); |
| 12355 |
ret = -ETIMEDOUT; |
| 12356 |
} |
| 12357 |
|
| 12358 |
time_left = wait_event_timeout(ar->txmgmt_empty_waitq, |
| 12359 |
(atomic_read(&ar->num_pending_mgmt_tx) == 0), |
| 12360 |
ATH12K_FLUSH_TIMEOUT); |
| 12361 |
if (time_left == 0) { |
| 12362 |
ath12k_warn(ar->ab, |
| 12363 |
"failed to flush mgmt transmit queue, mgmt pkts pending %d\n", |
| 12364 |
atomic_read(&ar->num_pending_mgmt_tx)); |
| 12365 |
ret = -ETIMEDOUT; |
| 12366 |
} |
| 12367 |
|
| 12368 |
return ret; |
| 12369 |
} |
| 12370 |
|
| 12371 |
int ath12k_mac_wait_tx_complete(struct ath12k *ar) |
| 12372 |
{ |
| 12373 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 12374 |
|
| 12375 |
ath12k_mac_drain_tx(ar); |
| 12376 |
return ath12k_mac_flush(ar); |
| 12377 |
} |
| 12378 |
|
| 12379 |
void ath12k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 12380 |
u32 queues, bool drop) |
| 12381 |
{ |
| 12382 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 12383 |
struct ath12k_link_vif *arvif; |
| 12384 |
struct ath12k_vif *ahvif; |
| 12385 |
unsigned long links; |
| 12386 |
struct ath12k *ar; |
| 12387 |
u8 link_id; |
| 12388 |
int i; |
| 12389 |
|
| 12390 |
lockdep_assert_wiphy(hw->wiphy); |
| 12391 |
|
| 12392 |
if (drop) |
| 12393 |
return; |
| 12394 |
|
| 12395 |
for_each_ar(ah, ar, i) |
| 12396 |
wiphy_work_flush(hw->wiphy, &ar->wmi_mgmt_tx_work); |
| 12397 |
|
| 12398 |
/* vif can be NULL when flush() is considered for hw */ |
| 12399 |
if (!vif) { |
| 12400 |
for_each_ar(ah, ar, i) |
| 12401 |
ath12k_mac_flush(ar); |
| 12402 |
return; |
| 12403 |
} |
| 12404 |
|
| 12405 |
ahvif = ath12k_vif_to_ahvif(vif); |
| 12406 |
links = ahvif->links_map; |
| 12407 |
for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 12408 |
arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
| 12409 |
if (!(arvif && arvif->ar)) |
| 12410 |
continue; |
| 12411 |
|
| 12412 |
ath12k_mac_flush(arvif->ar); |
| 12413 |
} |
| 12414 |
} |
| 12415 |
EXPORT_SYMBOL(ath12k_mac_op_flush); |
| 12416 |
|
| 12417 |
static int |
| 12418 |
ath12k_mac_bitrate_mask_num_ht_rates(struct ath12k *ar, |
| 12419 |
enum nl80211_band band, |
| 12420 |
const struct cfg80211_bitrate_mask *mask) |
| 12421 |
{ |
| 12422 |
int num_rates = 0; |
| 12423 |
int i; |
| 12424 |
|
| 12425 |
for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) |
| 12426 |
num_rates += hweight16(mask->control[band].ht_mcs[i]); |
| 12427 |
|
| 12428 |
return num_rates; |
| 12429 |
} |
| 12430 |
|
| 12431 |
static bool |
| 12432 |
ath12k_mac_has_single_legacy_rate(struct ath12k *ar, |
| 12433 |
enum nl80211_band band, |
| 12434 |
const struct cfg80211_bitrate_mask *mask) |
| 12435 |
{ |
| 12436 |
int num_rates = 0; |
| 12437 |
|
| 12438 |
num_rates = hweight32(mask->control[band].legacy); |
| 12439 |
|
| 12440 |
if (ath12k_mac_bitrate_mask_num_ht_rates(ar, band, mask)) |
| 12441 |
return false; |
| 12442 |
|
| 12443 |
if (ath12k_mac_bitrate_mask_num_vht_rates(ar, band, mask)) |
| 12444 |
return false; |
| 12445 |
|
| 12446 |
if (ath12k_mac_bitrate_mask_num_he_rates(ar, band, mask)) |
| 12447 |
return false; |
| 12448 |
|
| 12449 |
if (ath12k_mac_bitrate_mask_num_eht_rates(ar, band, mask)) |
| 12450 |
return false; |
| 12451 |
|
| 12452 |
return num_rates == 1; |
| 12453 |
} |
| 12454 |
|
| 12455 |
static __le16 |
| 12456 |
ath12k_mac_get_tx_mcs_map(const struct ieee80211_sta_he_cap *he_cap) |
| 12457 |
{ |
| 12458 |
if (he_cap->he_cap_elem.phy_cap_info[0] & |
| 12459 |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) |
| 12460 |
return he_cap->he_mcs_nss_supp.tx_mcs_160; |
| 12461 |
|
| 12462 |
return he_cap->he_mcs_nss_supp.tx_mcs_80; |
| 12463 |
} |
| 12464 |
|
| 12465 |
static bool |
| 12466 |
ath12k_mac_bitrate_mask_get_single_nss(struct ath12k *ar, |
| 12467 |
struct ieee80211_vif *vif, |
| 12468 |
enum nl80211_band band, |
| 12469 |
const struct cfg80211_bitrate_mask *mask, |
| 12470 |
int *nss) |
| 12471 |
{ |
| 12472 |
struct ieee80211_supported_band *sband = &ar->mac.sbands[band]; |
| 12473 |
u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 12474 |
const struct ieee80211_sband_iftype_data *data; |
| 12475 |
const struct ieee80211_sta_he_cap *he_cap; |
| 12476 |
u16 he_mcs_map = 0; |
| 12477 |
u16 eht_mcs_map = 0; |
| 12478 |
u8 ht_nss_mask = 0; |
| 12479 |
u8 vht_nss_mask = 0; |
| 12480 |
u8 he_nss_mask = 0; |
| 12481 |
u8 eht_nss_mask = 0; |
| 12482 |
u8 mcs_nss_len; |
| 12483 |
int i; |
| 12484 |
|
| 12485 |
/* No need to consider legacy here. Basic rates are always present |
| 12486 |
* in bitrate mask |
| 12487 |
*/ |
| 12488 |
|
| 12489 |
for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) { |
| 12490 |
if (mask->control[band].ht_mcs[i] == 0) |
| 12491 |
continue; |
| 12492 |
else if (mask->control[band].ht_mcs[i] == |
| 12493 |
sband->ht_cap.mcs.rx_mask[i]) |
| 12494 |
ht_nss_mask |= BIT(i); |
| 12495 |
else |
| 12496 |
return false; |
| 12497 |
} |
| 12498 |
|
| 12499 |
for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { |
| 12500 |
if (mask->control[band].vht_mcs[i] == 0) |
| 12501 |
continue; |
| 12502 |
else if (mask->control[band].vht_mcs[i] == |
| 12503 |
ath12k_mac_get_max_vht_mcs_map(vht_mcs_map, i)) |
| 12504 |
vht_nss_mask |= BIT(i); |
| 12505 |
else |
| 12506 |
return false; |
| 12507 |
} |
| 12508 |
|
| 12509 |
he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif); |
| 12510 |
if (!he_cap) |
| 12511 |
return false; |
| 12512 |
|
| 12513 |
he_mcs_map = le16_to_cpu(ath12k_mac_get_tx_mcs_map(he_cap)); |
| 12514 |
|
| 12515 |
for (i = 0; i < ARRAY_SIZE(mask->control[band].he_mcs); i++) { |
| 12516 |
if (mask->control[band].he_mcs[i] == 0) |
| 12517 |
continue; |
| 12518 |
|
| 12519 |
if (mask->control[band].he_mcs[i] == |
| 12520 |
ath12k_mac_get_max_he_mcs_map(he_mcs_map, i)) |
| 12521 |
he_nss_mask |= BIT(i); |
| 12522 |
else |
| 12523 |
return false; |
| 12524 |
} |
| 12525 |
|
| 12526 |
data = ieee80211_get_sband_iftype_data(sband, vif->type); |
| 12527 |
|
| 12528 |
mcs_nss_len = ieee80211_eht_mcs_nss_size(&data->he_cap.he_cap_elem, |
| 12529 |
&data->eht_cap.eht_cap_elem, |
| 12530 |
false); |
| 12531 |
if (mcs_nss_len == 4) { |
| 12532 |
/* 20 MHz only STA case */ |
| 12533 |
const struct ieee80211_eht_mcs_nss_supp_20mhz_only *eht_mcs_nss = |
| 12534 |
&data->eht_cap.eht_mcs_nss_supp.only_20mhz; |
| 12535 |
if (eht_mcs_nss->rx_tx_mcs13_max_nss) |
| 12536 |
eht_mcs_map = 0x1fff; |
| 12537 |
else if (eht_mcs_nss->rx_tx_mcs11_max_nss) |
| 12538 |
eht_mcs_map = 0x07ff; |
| 12539 |
else if (eht_mcs_nss->rx_tx_mcs9_max_nss) |
| 12540 |
eht_mcs_map = 0x01ff; |
| 12541 |
else |
| 12542 |
eht_mcs_map = 0x007f; |
| 12543 |
} else { |
| 12544 |
const struct ieee80211_eht_mcs_nss_supp_bw *eht_mcs_nss; |
| 12545 |
|
| 12546 |
switch (mcs_nss_len) { |
| 12547 |
case 9: |
| 12548 |
eht_mcs_nss = &data->eht_cap.eht_mcs_nss_supp.bw._320; |
| 12549 |
break; |
| 12550 |
case 6: |
| 12551 |
eht_mcs_nss = &data->eht_cap.eht_mcs_nss_supp.bw._160; |
| 12552 |
break; |
| 12553 |
case 3: |
| 12554 |
eht_mcs_nss = &data->eht_cap.eht_mcs_nss_supp.bw._80; |
| 12555 |
break; |
| 12556 |
default: |
| 12557 |
return false; |
| 12558 |
} |
| 12559 |
|
| 12560 |
if (eht_mcs_nss->rx_tx_mcs13_max_nss) |
| 12561 |
eht_mcs_map = 0x1fff; |
| 12562 |
else if (eht_mcs_nss->rx_tx_mcs11_max_nss) |
| 12563 |
eht_mcs_map = 0x7ff; |
| 12564 |
else |
| 12565 |
eht_mcs_map = 0x1ff; |
| 12566 |
} |
| 12567 |
|
| 12568 |
for (i = 0; i < ARRAY_SIZE(mask->control[band].eht_mcs); i++) { |
| 12569 |
if (mask->control[band].eht_mcs[i] == 0) |
| 12570 |
continue; |
| 12571 |
|
| 12572 |
if (mask->control[band].eht_mcs[i] < eht_mcs_map) |
| 12573 |
eht_nss_mask |= BIT(i); |
| 12574 |
else |
| 12575 |
return false; |
| 12576 |
} |
| 12577 |
|
| 12578 |
if (ht_nss_mask != vht_nss_mask || ht_nss_mask != he_nss_mask || |
| 12579 |
ht_nss_mask != eht_nss_mask) |
| 12580 |
return false; |
| 12581 |
|
| 12582 |
if (ht_nss_mask == 0) |
| 12583 |
return false; |
| 12584 |
|
| 12585 |
if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask) |
| 12586 |
return false; |
| 12587 |
|
| 12588 |
*nss = fls(ht_nss_mask); |
| 12589 |
|
| 12590 |
return true; |
| 12591 |
} |
| 12592 |
|
| 12593 |
static int |
| 12594 |
ath12k_mac_get_single_legacy_rate(struct ath12k *ar, |
| 12595 |
enum nl80211_band band, |
| 12596 |
const struct cfg80211_bitrate_mask *mask, |
| 12597 |
u32 *rate, u8 *nss) |
| 12598 |
{ |
| 12599 |
int rate_idx; |
| 12600 |
u16 bitrate; |
| 12601 |
u8 preamble; |
| 12602 |
u8 hw_rate; |
| 12603 |
|
| 12604 |
if (hweight32(mask->control[band].legacy) != 1) |
| 12605 |
return -EINVAL; |
| 12606 |
|
| 12607 |
rate_idx = ffs(mask->control[band].legacy) - 1; |
| 12608 |
|
| 12609 |
if (band == NL80211_BAND_5GHZ || band == NL80211_BAND_6GHZ) |
| 12610 |
rate_idx += ATH12K_MAC_FIRST_OFDM_RATE_IDX; |
| 12611 |
|
| 12612 |
hw_rate = ath12k_legacy_rates[rate_idx].hw_value; |
| 12613 |
bitrate = ath12k_legacy_rates[rate_idx].bitrate; |
| 12614 |
|
| 12615 |
if (ath12k_mac_bitrate_is_cck(bitrate)) |
| 12616 |
preamble = WMI_RATE_PREAMBLE_CCK; |
| 12617 |
else |
| 12618 |
preamble = WMI_RATE_PREAMBLE_OFDM; |
| 12619 |
|
| 12620 |
*nss = 1; |
| 12621 |
*rate = ATH12K_HW_RATE_CODE(hw_rate, 0, preamble); |
| 12622 |
|
| 12623 |
return 0; |
| 12624 |
} |
| 12625 |
|
| 12626 |
static int |
| 12627 |
ath12k_mac_set_fixed_rate_gi_ltf(struct ath12k_link_vif *arvif, u8 gi, u8 ltf, |
| 12628 |
u32 param) |
| 12629 |
{ |
| 12630 |
struct ath12k *ar = arvif->ar; |
| 12631 |
int ret; |
| 12632 |
|
| 12633 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 12634 |
|
| 12635 |
/* 0.8 = 0, 1.6 = 2 and 3.2 = 3. */ |
| 12636 |
if (gi && gi != 0xFF) |
| 12637 |
gi += 1; |
| 12638 |
|
| 12639 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 12640 |
WMI_VDEV_PARAM_SGI, gi); |
| 12641 |
if (ret) { |
| 12642 |
ath12k_warn(ar->ab, "failed to set GI:%d, error:%d\n", |
| 12643 |
gi, ret); |
| 12644 |
return ret; |
| 12645 |
} |
| 12646 |
|
| 12647 |
if (param == WMI_VDEV_PARAM_HE_LTF) { |
| 12648 |
/* HE values start from 1 */ |
| 12649 |
if (ltf != 0xFF) |
| 12650 |
ltf += 1; |
| 12651 |
} else { |
| 12652 |
/* EHT values start from 5 */ |
| 12653 |
if (ltf != 0xFF) |
| 12654 |
ltf += 4; |
| 12655 |
} |
| 12656 |
|
| 12657 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 12658 |
param, ltf); |
| 12659 |
if (ret) { |
| 12660 |
ath12k_warn(ar->ab, "failed to set LTF:%d, error:%d\n", |
| 12661 |
ltf, ret); |
| 12662 |
return ret; |
| 12663 |
} |
| 12664 |
return 0; |
| 12665 |
} |
| 12666 |
|
| 12667 |
static int |
| 12668 |
ath12k_mac_set_auto_rate_gi_ltf(struct ath12k_link_vif *arvif, u16 gi, u8 ltf) |
| 12669 |
{ |
| 12670 |
struct ath12k *ar = arvif->ar; |
| 12671 |
int ret; |
| 12672 |
u32 ar_gi_ltf; |
| 12673 |
|
| 12674 |
if (gi != 0xFF) { |
| 12675 |
switch (gi) { |
| 12676 |
case ATH12K_RATE_INFO_GI_0_8: |
| 12677 |
gi = WMI_AUTORATE_800NS_GI; |
| 12678 |
break; |
| 12679 |
case ATH12K_RATE_INFO_GI_1_6: |
| 12680 |
gi = WMI_AUTORATE_1600NS_GI; |
| 12681 |
break; |
| 12682 |
case ATH12K_RATE_INFO_GI_3_2: |
| 12683 |
gi = WMI_AUTORATE_3200NS_GI; |
| 12684 |
break; |
| 12685 |
default: |
| 12686 |
ath12k_warn(ar->ab, "Invalid GI\n"); |
| 12687 |
return -EINVAL; |
| 12688 |
} |
| 12689 |
} |
| 12690 |
|
| 12691 |
if (ltf != 0xFF) { |
| 12692 |
switch (ltf) { |
| 12693 |
case ATH12K_RATE_INFO_1XLTF: |
| 12694 |
ltf = WMI_AUTORATE_LTF_1X; |
| 12695 |
break; |
| 12696 |
case ATH12K_RATE_INFO_2XLTF: |
| 12697 |
ltf = WMI_AUTORATE_LTF_2X; |
| 12698 |
break; |
| 12699 |
case ATH12K_RATE_INFO_4XLTF: |
| 12700 |
ltf = WMI_AUTORATE_LTF_4X; |
| 12701 |
break; |
| 12702 |
default: |
| 12703 |
ath12k_warn(ar->ab, "Invalid LTF\n"); |
| 12704 |
return -EINVAL; |
| 12705 |
} |
| 12706 |
} |
| 12707 |
|
| 12708 |
ar_gi_ltf = gi | ltf; |
| 12709 |
|
| 12710 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 12711 |
WMI_VDEV_PARAM_AUTORATE_MISC_CFG, |
| 12712 |
ar_gi_ltf); |
| 12713 |
if (ret) { |
| 12714 |
ath12k_warn(ar->ab, |
| 12715 |
"failed to set autorate GI:%u, LTF:%u params, error:%d\n", |
| 12716 |
gi, ltf, ret); |
| 12717 |
return ret; |
| 12718 |
} |
| 12719 |
|
| 12720 |
return 0; |
| 12721 |
} |
| 12722 |
|
| 12723 |
static u32 ath12k_mac_nlgi_to_wmigi(enum nl80211_txrate_gi gi) |
| 12724 |
{ |
| 12725 |
switch (gi) { |
| 12726 |
case NL80211_TXRATE_DEFAULT_GI: |
| 12727 |
return WMI_GI_400_NS; |
| 12728 |
case NL80211_TXRATE_FORCE_LGI: |
| 12729 |
return WMI_GI_800_NS; |
| 12730 |
default: |
| 12731 |
return WMI_GI_400_NS; |
| 12732 |
} |
| 12733 |
} |
| 12734 |
|
| 12735 |
static int ath12k_mac_set_rate_params(struct ath12k_link_vif *arvif, |
| 12736 |
u32 rate, u8 nss, u8 sgi, u8 ldpc, |
| 12737 |
u8 he_gi, u8 he_ltf, bool he_fixed_rate, |
| 12738 |
u8 eht_gi, u8 eht_ltf, |
| 12739 |
bool eht_fixed_rate) |
| 12740 |
{ |
| 12741 |
struct ieee80211_bss_conf *link_conf; |
| 12742 |
struct ath12k *ar = arvif->ar; |
| 12743 |
bool he_support, eht_support, gi_ltf_set = false; |
| 12744 |
u32 vdev_param; |
| 12745 |
u32 param_value; |
| 12746 |
int ret; |
| 12747 |
|
| 12748 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 12749 |
|
| 12750 |
link_conf = ath12k_mac_get_link_bss_conf(arvif); |
| 12751 |
if (!link_conf) |
| 12752 |
return -EINVAL; |
| 12753 |
|
| 12754 |
he_support = link_conf->he_support; |
| 12755 |
eht_support = link_conf->eht_support; |
| 12756 |
|
| 12757 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 12758 |
"mac set rate params vdev %i rate 0x%02x nss 0x%02x sgi 0x%02x ldpc 0x%02x\n", |
| 12759 |
arvif->vdev_id, rate, nss, sgi, ldpc); |
| 12760 |
|
| 12761 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 12762 |
"he_gi 0x%02x he_ltf 0x%02x he_fixed_rate %d\n", he_gi, |
| 12763 |
he_ltf, he_fixed_rate); |
| 12764 |
|
| 12765 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 12766 |
"eht_gi 0x%02x eht_ltf 0x%02x eht_fixed_rate %d\n", |
| 12767 |
eht_gi, eht_ltf, eht_fixed_rate); |
| 12768 |
|
| 12769 |
if (!he_support && !eht_support) { |
| 12770 |
vdev_param = WMI_VDEV_PARAM_FIXED_RATE; |
| 12771 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 12772 |
vdev_param, rate); |
| 12773 |
if (ret) { |
| 12774 |
ath12k_warn(ar->ab, "failed to set fixed rate param 0x%02x: %d\n", |
| 12775 |
rate, ret); |
| 12776 |
return ret; |
| 12777 |
} |
| 12778 |
} |
| 12779 |
|
| 12780 |
vdev_param = WMI_VDEV_PARAM_NSS; |
| 12781 |
|
| 12782 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 12783 |
vdev_param, nss); |
| 12784 |
if (ret) { |
| 12785 |
ath12k_warn(ar->ab, "failed to set nss param %d: %d\n", |
| 12786 |
nss, ret); |
| 12787 |
return ret; |
| 12788 |
} |
| 12789 |
|
| 12790 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 12791 |
WMI_VDEV_PARAM_LDPC, ldpc); |
| 12792 |
if (ret) { |
| 12793 |
ath12k_warn(ar->ab, "failed to set ldpc param %d: %d\n", |
| 12794 |
ldpc, ret); |
| 12795 |
return ret; |
| 12796 |
} |
| 12797 |
|
| 12798 |
if (eht_support) { |
| 12799 |
if (eht_fixed_rate) |
| 12800 |
ret = ath12k_mac_set_fixed_rate_gi_ltf(arvif, eht_gi, eht_ltf, |
| 12801 |
WMI_VDEV_PARAM_EHT_LTF); |
| 12802 |
else |
| 12803 |
ret = ath12k_mac_set_auto_rate_gi_ltf(arvif, eht_gi, eht_ltf); |
| 12804 |
|
| 12805 |
if (ret) { |
| 12806 |
ath12k_warn(ar->ab, |
| 12807 |
"failed to set EHT LTF/GI params %d/%d: %d\n", |
| 12808 |
eht_gi, eht_ltf, ret); |
| 12809 |
return ret; |
| 12810 |
} |
| 12811 |
gi_ltf_set = true; |
| 12812 |
} |
| 12813 |
|
| 12814 |
if (he_support) { |
| 12815 |
if (he_fixed_rate) |
| 12816 |
ret = ath12k_mac_set_fixed_rate_gi_ltf(arvif, he_gi, he_ltf, |
| 12817 |
WMI_VDEV_PARAM_HE_LTF); |
| 12818 |
else |
| 12819 |
ret = ath12k_mac_set_auto_rate_gi_ltf(arvif, he_gi, he_ltf); |
| 12820 |
if (ret) |
| 12821 |
return ret; |
| 12822 |
gi_ltf_set = true; |
| 12823 |
} |
| 12824 |
|
| 12825 |
if (!gi_ltf_set) { |
| 12826 |
vdev_param = WMI_VDEV_PARAM_SGI; |
| 12827 |
param_value = ath12k_mac_nlgi_to_wmigi(sgi); |
| 12828 |
ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
| 12829 |
vdev_param, param_value); |
| 12830 |
if (ret) { |
| 12831 |
ath12k_warn(ar->ab, "failed to set sgi param %d: %d\n", |
| 12832 |
sgi, ret); |
| 12833 |
return ret; |
| 12834 |
} |
| 12835 |
} |
| 12836 |
|
| 12837 |
return 0; |
| 12838 |
} |
| 12839 |
|
| 12840 |
static bool |
| 12841 |
ath12k_mac_vht_mcs_range_present(struct ath12k *ar, |
| 12842 |
enum nl80211_band band, |
| 12843 |
const struct cfg80211_bitrate_mask *mask) |
| 12844 |
{ |
| 12845 |
int i; |
| 12846 |
u16 vht_mcs; |
| 12847 |
|
| 12848 |
for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 12849 |
vht_mcs = mask->control[band].vht_mcs[i]; |
| 12850 |
|
| 12851 |
switch (vht_mcs) { |
| 12852 |
case 0: |
| 12853 |
case BIT(8) - 1: |
| 12854 |
case BIT(9) - 1: |
| 12855 |
case BIT(10) - 1: |
| 12856 |
break; |
| 12857 |
default: |
| 12858 |
return false; |
| 12859 |
} |
| 12860 |
} |
| 12861 |
|
| 12862 |
return true; |
| 12863 |
} |
| 12864 |
|
| 12865 |
static bool |
| 12866 |
ath12k_mac_he_mcs_range_present(struct ath12k *ar, |
| 12867 |
enum nl80211_band band, |
| 12868 |
const struct cfg80211_bitrate_mask *mask) |
| 12869 |
{ |
| 12870 |
int i; |
| 12871 |
u16 he_mcs; |
| 12872 |
|
| 12873 |
for (i = 0; i < NL80211_HE_NSS_MAX; i++) { |
| 12874 |
he_mcs = mask->control[band].he_mcs[i]; |
| 12875 |
|
| 12876 |
switch (he_mcs) { |
| 12877 |
case 0: |
| 12878 |
case BIT(8) - 1: |
| 12879 |
case BIT(10) - 1: |
| 12880 |
case BIT(12) - 1: |
| 12881 |
break; |
| 12882 |
default: |
| 12883 |
return false; |
| 12884 |
} |
| 12885 |
} |
| 12886 |
|
| 12887 |
return true; |
| 12888 |
} |
| 12889 |
|
| 12890 |
static bool |
| 12891 |
ath12k_mac_eht_mcs_range_present(struct ath12k *ar, |
| 12892 |
enum nl80211_band band, |
| 12893 |
const struct cfg80211_bitrate_mask *mask) |
| 12894 |
{ |
| 12895 |
u16 eht_mcs; |
| 12896 |
int i; |
| 12897 |
|
| 12898 |
for (i = 0; i < NL80211_EHT_NSS_MAX; i++) { |
| 12899 |
eht_mcs = mask->control[band].eht_mcs[i]; |
| 12900 |
|
| 12901 |
switch (eht_mcs) { |
| 12902 |
case 0: |
| 12903 |
case BIT(8) - 1: |
| 12904 |
case BIT(10) - 1: |
| 12905 |
case BIT(12) - 1: |
| 12906 |
case BIT(14) - 1: |
| 12907 |
break; |
| 12908 |
case BIT(15) - 1: |
| 12909 |
case BIT(16) - 1: |
| 12910 |
case BIT(16) - BIT(14) - 1: |
| 12911 |
if (i != 0) |
| 12912 |
return false; |
| 12913 |
break; |
| 12914 |
default: |
| 12915 |
return false; |
| 12916 |
} |
| 12917 |
} |
| 12918 |
|
| 12919 |
return true; |
| 12920 |
} |
| 12921 |
|
| 12922 |
static void ath12k_mac_set_bitrate_mask_iter(void *data, |
| 12923 |
struct ieee80211_sta *sta) |
| 12924 |
{ |
| 12925 |
struct ath12k_link_vif *arvif = data; |
| 12926 |
struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
| 12927 |
struct ath12k_link_sta *arsta; |
| 12928 |
struct ath12k *ar = arvif->ar; |
| 12929 |
|
| 12930 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 12931 |
|
| 12932 |
arsta = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, |
| 12933 |
ahsta->link[arvif->link_id]); |
| 12934 |
if (!arsta || arsta->arvif != arvif) |
| 12935 |
return; |
| 12936 |
|
| 12937 |
spin_lock_bh(&ar->data_lock); |
| 12938 |
arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED; |
| 12939 |
spin_unlock_bh(&ar->data_lock); |
| 12940 |
|
| 12941 |
wiphy_work_queue(ath12k_ar_to_hw(ar)->wiphy, &arsta->update_wk); |
| 12942 |
} |
| 12943 |
|
| 12944 |
static void ath12k_mac_disable_peer_fixed_rate(void *data, |
| 12945 |
struct ieee80211_sta *sta) |
| 12946 |
{ |
| 12947 |
struct ath12k_link_vif *arvif = data; |
| 12948 |
struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
| 12949 |
struct ath12k_link_sta *arsta; |
| 12950 |
struct ath12k *ar = arvif->ar; |
| 12951 |
int ret; |
| 12952 |
|
| 12953 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 12954 |
|
| 12955 |
arsta = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, |
| 12956 |
ahsta->link[arvif->link_id]); |
| 12957 |
|
| 12958 |
if (!arsta || arsta->arvif != arvif) |
| 12959 |
return; |
| 12960 |
|
| 12961 |
ret = ath12k_wmi_set_peer_param(ar, arsta->addr, |
| 12962 |
arvif->vdev_id, |
| 12963 |
WMI_PEER_PARAM_FIXED_RATE, |
| 12964 |
WMI_FIXED_RATE_NONE); |
| 12965 |
if (ret) |
| 12966 |
ath12k_warn(ar->ab, |
| 12967 |
"failed to disable peer fixed rate for STA %pM ret %d\n", |
| 12968 |
arsta->addr, ret); |
| 12969 |
} |
| 12970 |
|
| 12971 |
static bool |
| 12972 |
ath12k_mac_validate_fixed_rate_settings(struct ath12k *ar, enum nl80211_band band, |
| 12973 |
const struct cfg80211_bitrate_mask *mask, |
| 12974 |
unsigned int link_id) |
| 12975 |
{ |
| 12976 |
bool eht_fixed_rate = false, he_fixed_rate = false, vht_fixed_rate = false; |
| 12977 |
const u16 *vht_mcs_mask, *he_mcs_mask, *eht_mcs_mask; |
| 12978 |
struct ieee80211_link_sta *link_sta; |
| 12979 |
struct ath12k_dp_link_peer *peer, *tmp; |
| 12980 |
u8 vht_nss, he_nss, eht_nss; |
| 12981 |
int ret = true; |
| 12982 |
struct ath12k_base *ab = ar->ab; |
| 12983 |
struct ath12k_dp *dp = ath12k_ab_to_dp(ab); |
| 12984 |
|
| 12985 |
vht_mcs_mask = mask->control[band].vht_mcs; |
| 12986 |
he_mcs_mask = mask->control[band].he_mcs; |
| 12987 |
eht_mcs_mask = mask->control[band].eht_mcs; |
| 12988 |
|
| 12989 |
if (ath12k_mac_bitrate_mask_num_vht_rates(ar, band, mask) == 1) |
| 12990 |
vht_fixed_rate = true; |
| 12991 |
|
| 12992 |
if (ath12k_mac_bitrate_mask_num_he_rates(ar, band, mask) == 1) |
| 12993 |
he_fixed_rate = true; |
| 12994 |
|
| 12995 |
if (ath12k_mac_bitrate_mask_num_eht_rates(ar, band, mask) == 1) |
| 12996 |
eht_fixed_rate = true; |
| 12997 |
|
| 12998 |
if (!vht_fixed_rate && !he_fixed_rate && !eht_fixed_rate) |
| 12999 |
return true; |
| 13000 |
|
| 13001 |
vht_nss = ath12k_mac_max_vht_nss(vht_mcs_mask); |
| 13002 |
he_nss = ath12k_mac_max_he_nss(he_mcs_mask); |
| 13003 |
eht_nss = ath12k_mac_max_eht_nss(eht_mcs_mask); |
| 13004 |
|
| 13005 |
rcu_read_lock(); |
| 13006 |
spin_lock_bh(&dp->dp_lock); |
| 13007 |
list_for_each_entry_safe(peer, tmp, &dp->peers, list) { |
| 13008 |
if (peer->sta) { |
| 13009 |
link_sta = rcu_dereference(peer->sta->link[link_id]); |
| 13010 |
if (!link_sta) { |
| 13011 |
ret = false; |
| 13012 |
goto exit; |
| 13013 |
} |
| 13014 |
|
| 13015 |
if (vht_fixed_rate && (!link_sta->vht_cap.vht_supported || |
| 13016 |
link_sta->rx_nss < vht_nss)) { |
| 13017 |
ret = false; |
| 13018 |
goto exit; |
| 13019 |
} |
| 13020 |
if (he_fixed_rate && (!link_sta->he_cap.has_he || |
| 13021 |
link_sta->rx_nss < he_nss)) { |
| 13022 |
ret = false; |
| 13023 |
goto exit; |
| 13024 |
} |
| 13025 |
if (eht_fixed_rate && (!link_sta->eht_cap.has_eht || |
| 13026 |
link_sta->rx_nss < eht_nss)) { |
| 13027 |
ret = false; |
| 13028 |
goto exit; |
| 13029 |
} |
| 13030 |
} |
| 13031 |
} |
| 13032 |
exit: |
| 13033 |
spin_unlock_bh(&dp->dp_lock); |
| 13034 |
rcu_read_unlock(); |
| 13035 |
return ret; |
| 13036 |
} |
| 13037 |
|
| 13038 |
int |
| 13039 |
ath12k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw, |
| 13040 |
struct ieee80211_vif *vif, |
| 13041 |
const struct cfg80211_bitrate_mask *mask) |
| 13042 |
{ |
| 13043 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 13044 |
struct ath12k_link_vif *arvif; |
| 13045 |
struct cfg80211_chan_def def; |
| 13046 |
struct ath12k *ar; |
| 13047 |
enum nl80211_band band; |
| 13048 |
const u8 *ht_mcs_mask; |
| 13049 |
const u16 *vht_mcs_mask; |
| 13050 |
const u16 *he_mcs_mask; |
| 13051 |
const u16 *eht_mcs_mask; |
| 13052 |
u8 he_ltf = 0; |
| 13053 |
u8 he_gi = 0; |
| 13054 |
u8 eht_ltf = 0, eht_gi = 0; |
| 13055 |
u32 rate; |
| 13056 |
u8 nss, mac_nss; |
| 13057 |
u8 sgi; |
| 13058 |
u8 ldpc; |
| 13059 |
int single_nss; |
| 13060 |
int ret; |
| 13061 |
int num_rates; |
| 13062 |
bool he_fixed_rate = false; |
| 13063 |
bool eht_fixed_rate = false; |
| 13064 |
|
| 13065 |
lockdep_assert_wiphy(hw->wiphy); |
| 13066 |
|
| 13067 |
arvif = &ahvif->deflink; |
| 13068 |
|
| 13069 |
ar = arvif->ar; |
| 13070 |
if (ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)) { |
| 13071 |
ret = -EPERM; |
| 13072 |
goto out; |
| 13073 |
} |
| 13074 |
|
| 13075 |
band = def.chan->band; |
| 13076 |
ht_mcs_mask = mask->control[band].ht_mcs; |
| 13077 |
vht_mcs_mask = mask->control[band].vht_mcs; |
| 13078 |
he_mcs_mask = mask->control[band].he_mcs; |
| 13079 |
eht_mcs_mask = mask->control[band].eht_mcs; |
| 13080 |
ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC); |
| 13081 |
|
| 13082 |
sgi = mask->control[band].gi; |
| 13083 |
if (sgi == NL80211_TXRATE_FORCE_SGI) { |
| 13084 |
ret = -EINVAL; |
| 13085 |
goto out; |
| 13086 |
} |
| 13087 |
|
| 13088 |
he_gi = mask->control[band].he_gi; |
| 13089 |
he_ltf = mask->control[band].he_ltf; |
| 13090 |
|
| 13091 |
eht_gi = mask->control[band].eht_gi; |
| 13092 |
eht_ltf = mask->control[band].eht_ltf; |
| 13093 |
|
| 13094 |
/* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it |
| 13095 |
* requires passing at least one of used basic rates along with them. |
| 13096 |
* Fixed rate setting across different preambles(legacy, HT, VHT) is |
| 13097 |
* not supported by the FW. Hence use of FIXED_RATE vdev param is not |
| 13098 |
* suitable for setting single HT/VHT rates. |
| 13099 |
* But, there could be a single basic rate passed from userspace which |
| 13100 |
* can be done through the FIXED_RATE param. |
| 13101 |
*/ |
| 13102 |
if (ath12k_mac_has_single_legacy_rate(ar, band, mask)) { |
| 13103 |
ret = ath12k_mac_get_single_legacy_rate(ar, band, mask, &rate, |
| 13104 |
&nss); |
| 13105 |
if (ret) { |
| 13106 |
ath12k_warn(ar->ab, "failed to get single legacy rate for vdev %i: %d\n", |
| 13107 |
arvif->vdev_id, ret); |
| 13108 |
goto out; |
| 13109 |
} |
| 13110 |
|
| 13111 |
ieee80211_iterate_stations_mtx(hw, |
| 13112 |
ath12k_mac_disable_peer_fixed_rate, |
| 13113 |
arvif); |
| 13114 |
} else if (ath12k_mac_bitrate_mask_get_single_nss(ar, vif, band, mask, |
| 13115 |
&single_nss)) { |
| 13116 |
rate = WMI_FIXED_RATE_NONE; |
| 13117 |
nss = single_nss; |
| 13118 |
arvif->bitrate_mask = *mask; |
| 13119 |
|
| 13120 |
ieee80211_iterate_stations_atomic(hw, |
| 13121 |
ath12k_mac_set_bitrate_mask_iter, |
| 13122 |
arvif); |
| 13123 |
} else { |
| 13124 |
rate = WMI_FIXED_RATE_NONE; |
| 13125 |
|
| 13126 |
if (!ath12k_mac_validate_fixed_rate_settings(ar, band, |
| 13127 |
mask, arvif->link_id)) |
| 13128 |
ath12k_warn(ar->ab, |
| 13129 |
"failed to update fixed rate settings due to mcs/nss incompatibility\n"); |
| 13130 |
|
| 13131 |
mac_nss = max(max3(ath12k_mac_max_ht_nss(ht_mcs_mask), |
| 13132 |
ath12k_mac_max_vht_nss(vht_mcs_mask), |
| 13133 |
ath12k_mac_max_he_nss(he_mcs_mask)), |
| 13134 |
ath12k_mac_max_eht_nss(eht_mcs_mask)); |
| 13135 |
nss = min_t(u32, ar->num_tx_chains, mac_nss); |
| 13136 |
|
| 13137 |
/* If multiple rates across different preambles are given |
| 13138 |
* we can reconfigure this info with all peers using PEER_ASSOC |
| 13139 |
* command with the below exception cases. |
| 13140 |
* - Single VHT Rate : peer_assoc command accommodates only MCS |
| 13141 |
* range values i.e 0-7, 0-8, 0-9 for VHT. Though mac80211 |
| 13142 |
* mandates passing basic rates along with HT/VHT rates, FW |
| 13143 |
* doesn't allow switching from VHT to Legacy. Hence instead of |
| 13144 |
* setting legacy and VHT rates using RATEMASK_CMD vdev cmd, |
| 13145 |
* we could set this VHT rate as peer fixed rate param, which |
| 13146 |
* will override FIXED rate and FW rate control algorithm. |
| 13147 |
* If single VHT rate is passed along with HT rates, we select |
| 13148 |
* the VHT rate as fixed rate for vht peers. |
| 13149 |
* - Multiple VHT Rates : When Multiple VHT rates are given,this |
| 13150 |
* can be set using RATEMASK CMD which uses FW rate-ctl alg. |
| 13151 |
* TODO: Setting multiple VHT MCS and replacing peer_assoc with |
| 13152 |
* RATEMASK_CMDID can cover all use cases of setting rates |
| 13153 |
* across multiple preambles and rates within same type. |
| 13154 |
* But requires more validation of the command at this point. |
| 13155 |
*/ |
| 13156 |
|
| 13157 |
num_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, |
| 13158 |
mask); |
| 13159 |
|
| 13160 |
if (!ath12k_mac_vht_mcs_range_present(ar, band, mask) && |
| 13161 |
num_rates > 1) { |
| 13162 |
/* TODO: Handle multiple VHT MCS values setting using |
| 13163 |
* RATEMASK CMD |
| 13164 |
*/ |
| 13165 |
ath12k_warn(ar->ab, |
| 13166 |
"Setting more than one MCS Value in bitrate mask not supported\n"); |
| 13167 |
ret = -EINVAL; |
| 13168 |
goto out; |
| 13169 |
} |
| 13170 |
|
| 13171 |
num_rates = ath12k_mac_bitrate_mask_num_he_rates(ar, band, mask); |
| 13172 |
if (num_rates == 1) |
| 13173 |
he_fixed_rate = true; |
| 13174 |
|
| 13175 |
if (!ath12k_mac_he_mcs_range_present(ar, band, mask) && |
| 13176 |
num_rates > 1) { |
| 13177 |
ath12k_warn(ar->ab, |
| 13178 |
"Setting more than one HE MCS Value in bitrate mask not supported\n"); |
| 13179 |
ret = -EINVAL; |
| 13180 |
goto out; |
| 13181 |
} |
| 13182 |
|
| 13183 |
num_rates = ath12k_mac_bitrate_mask_num_eht_rates(ar, band, |
| 13184 |
mask); |
| 13185 |
if (num_rates == 1) |
| 13186 |
eht_fixed_rate = true; |
| 13187 |
|
| 13188 |
if (!ath12k_mac_eht_mcs_range_present(ar, band, mask) && |
| 13189 |
num_rates > 1) { |
| 13190 |
ath12k_warn(ar->ab, |
| 13191 |
"Setting more than one EHT MCS Value in bitrate mask not supported\n"); |
| 13192 |
ret = -EINVAL; |
| 13193 |
goto out; |
| 13194 |
} |
| 13195 |
|
| 13196 |
ieee80211_iterate_stations_mtx(hw, |
| 13197 |
ath12k_mac_disable_peer_fixed_rate, |
| 13198 |
arvif); |
| 13199 |
|
| 13200 |
arvif->bitrate_mask = *mask; |
| 13201 |
ieee80211_iterate_stations_mtx(hw, |
| 13202 |
ath12k_mac_set_bitrate_mask_iter, |
| 13203 |
arvif); |
| 13204 |
} |
| 13205 |
|
| 13206 |
ret = ath12k_mac_set_rate_params(arvif, rate, nss, sgi, ldpc, he_gi, |
| 13207 |
he_ltf, he_fixed_rate, eht_gi, eht_ltf, |
| 13208 |
eht_fixed_rate); |
| 13209 |
if (ret) { |
| 13210 |
ath12k_warn(ar->ab, "failed to set rate params on vdev %i: %d\n", |
| 13211 |
arvif->vdev_id, ret); |
| 13212 |
} |
| 13213 |
|
| 13214 |
out: |
| 13215 |
return ret; |
| 13216 |
} |
| 13217 |
EXPORT_SYMBOL(ath12k_mac_op_set_bitrate_mask); |
| 13218 |
|
| 13219 |
void |
| 13220 |
ath12k_mac_op_reconfig_complete(struct ieee80211_hw *hw, |
| 13221 |
enum ieee80211_reconfig_type reconfig_type) |
| 13222 |
{ |
| 13223 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 13224 |
struct ath12k *ar; |
| 13225 |
struct ath12k_base *ab; |
| 13226 |
struct ath12k_vif *ahvif; |
| 13227 |
struct ath12k_link_vif *arvif; |
| 13228 |
int recovery_count, i; |
| 13229 |
|
| 13230 |
lockdep_assert_wiphy(hw->wiphy); |
| 13231 |
|
| 13232 |
if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART) |
| 13233 |
return; |
| 13234 |
|
| 13235 |
guard(mutex)(&ah->hw_mutex); |
| 13236 |
|
| 13237 |
if (ah->state != ATH12K_HW_STATE_RESTARTED) |
| 13238 |
return; |
| 13239 |
|
| 13240 |
ah->state = ATH12K_HW_STATE_ON; |
| 13241 |
ieee80211_wake_queues(hw); |
| 13242 |
|
| 13243 |
for_each_ar(ah, ar, i) { |
| 13244 |
ab = ar->ab; |
| 13245 |
|
| 13246 |
ath12k_warn(ar->ab, "pdev %d successfully recovered\n", |
| 13247 |
ar->pdev->pdev_id); |
| 13248 |
|
| 13249 |
if (ar->ab->hw_params->current_cc_support && |
| 13250 |
ar->alpha2[0] != 0 && ar->alpha2[1] != 0) { |
| 13251 |
struct wmi_set_current_country_arg arg = {}; |
| 13252 |
|
| 13253 |
memcpy(&arg.alpha2, ar->alpha2, 2); |
| 13254 |
reinit_completion(&ar->regd_update_completed); |
| 13255 |
ath12k_wmi_send_set_current_country_cmd(ar, &arg); |
| 13256 |
} |
| 13257 |
|
| 13258 |
if (ab->is_reset) { |
| 13259 |
recovery_count = atomic_inc_return(&ab->recovery_count); |
| 13260 |
|
| 13261 |
ath12k_dbg(ab, ATH12K_DBG_BOOT, "recovery count %d\n", |
| 13262 |
recovery_count); |
| 13263 |
|
| 13264 |
/* When there are multiple radios in an SOC, |
| 13265 |
* the recovery has to be done for each radio |
| 13266 |
*/ |
| 13267 |
if (recovery_count == ab->num_radios) { |
| 13268 |
atomic_dec(&ab->reset_count); |
| 13269 |
complete(&ab->reset_complete); |
| 13270 |
ab->is_reset = false; |
| 13271 |
atomic_set(&ab->fail_cont_count, 0); |
| 13272 |
ath12k_dbg(ab, ATH12K_DBG_BOOT, "reset success\n"); |
| 13273 |
} |
| 13274 |
} |
| 13275 |
|
| 13276 |
list_for_each_entry(arvif, &ar->arvifs, list) { |
| 13277 |
ahvif = arvif->ahvif; |
| 13278 |
ath12k_dbg(ab, ATH12K_DBG_BOOT, |
| 13279 |
"reconfig cipher %d up %d vdev type %d\n", |
| 13280 |
ahvif->dp_vif.key_cipher, |
| 13281 |
arvif->is_up, |
| 13282 |
ahvif->vdev_type); |
| 13283 |
|
| 13284 |
/* After trigger disconnect, then upper layer will |
| 13285 |
* trigger connect again, then the PN number of |
| 13286 |
* upper layer will be reset to keep up with AP |
| 13287 |
* side, hence PN number mismatch will not happen. |
| 13288 |
*/ |
| 13289 |
if (arvif->is_up && |
| 13290 |
ahvif->vdev_type == WMI_VDEV_TYPE_STA && |
| 13291 |
ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) { |
| 13292 |
ieee80211_hw_restart_disconnect(ahvif->vif); |
| 13293 |
|
| 13294 |
ath12k_dbg(ab, ATH12K_DBG_BOOT, |
| 13295 |
"restart disconnect\n"); |
| 13296 |
} |
| 13297 |
} |
| 13298 |
} |
| 13299 |
} |
| 13300 |
EXPORT_SYMBOL(ath12k_mac_op_reconfig_complete); |
| 13301 |
|
| 13302 |
static void |
| 13303 |
ath12k_mac_update_bss_chan_survey(struct ath12k *ar, |
| 13304 |
struct ieee80211_channel *channel) |
| 13305 |
{ |
| 13306 |
int ret; |
| 13307 |
enum wmi_bss_chan_info_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ; |
| 13308 |
|
| 13309 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 13310 |
|
| 13311 |
if (!test_bit(WMI_TLV_SERVICE_BSS_CHANNEL_INFO_64, ar->ab->wmi_ab.svc_map) || |
| 13312 |
ar->rx_channel != channel) |
| 13313 |
return; |
| 13314 |
|
| 13315 |
if (ar->scan.state != ATH12K_SCAN_IDLE) { |
| 13316 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 13317 |
"ignoring bss chan info req while scanning..\n"); |
| 13318 |
return; |
| 13319 |
} |
| 13320 |
|
| 13321 |
reinit_completion(&ar->bss_survey_done); |
| 13322 |
|
| 13323 |
ret = ath12k_wmi_pdev_bss_chan_info_request(ar, type); |
| 13324 |
if (ret) { |
| 13325 |
ath12k_warn(ar->ab, "failed to send pdev bss chan info request\n"); |
| 13326 |
return; |
| 13327 |
} |
| 13328 |
|
| 13329 |
ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ); |
| 13330 |
if (ret == 0) |
| 13331 |
ath12k_warn(ar->ab, "bss channel survey timed out\n"); |
| 13332 |
} |
| 13333 |
|
| 13334 |
int ath12k_mac_op_get_survey(struct ieee80211_hw *hw, int idx, |
| 13335 |
struct survey_info *survey) |
| 13336 |
{ |
| 13337 |
struct ath12k *ar; |
| 13338 |
struct ieee80211_supported_band *sband; |
| 13339 |
struct survey_info *ar_survey; |
| 13340 |
|
| 13341 |
lockdep_assert_wiphy(hw->wiphy); |
| 13342 |
|
| 13343 |
if (idx >= ATH12K_NUM_CHANS) |
| 13344 |
return -ENOENT; |
| 13345 |
|
| 13346 |
sband = hw->wiphy->bands[NL80211_BAND_2GHZ]; |
| 13347 |
if (sband && idx >= sband->n_channels) { |
| 13348 |
idx -= sband->n_channels; |
| 13349 |
sband = NULL; |
| 13350 |
} |
| 13351 |
|
| 13352 |
if (!sband) |
| 13353 |
sband = hw->wiphy->bands[NL80211_BAND_5GHZ]; |
| 13354 |
if (sband && idx >= sband->n_channels) { |
| 13355 |
idx -= sband->n_channels; |
| 13356 |
sband = NULL; |
| 13357 |
} |
| 13358 |
|
| 13359 |
if (!sband) |
| 13360 |
sband = hw->wiphy->bands[NL80211_BAND_6GHZ]; |
| 13361 |
|
| 13362 |
if (!sband || idx >= sband->n_channels) |
| 13363 |
return -ENOENT; |
| 13364 |
|
| 13365 |
ar = ath12k_mac_get_ar_by_chan(hw, &sband->channels[idx]); |
| 13366 |
if (!ar) { |
| 13367 |
if (sband->channels[idx].flags & IEEE80211_CHAN_DISABLED) { |
| 13368 |
memset(survey, 0, sizeof(*survey)); |
| 13369 |
return 0; |
| 13370 |
} |
| 13371 |
return -ENOENT; |
| 13372 |
} |
| 13373 |
|
| 13374 |
ar_survey = &ar->survey[idx]; |
| 13375 |
|
| 13376 |
ath12k_mac_update_bss_chan_survey(ar, &sband->channels[idx]); |
| 13377 |
|
| 13378 |
spin_lock_bh(&ar->data_lock); |
| 13379 |
memcpy(survey, ar_survey, sizeof(*survey)); |
| 13380 |
spin_unlock_bh(&ar->data_lock); |
| 13381 |
|
| 13382 |
survey->channel = &sband->channels[idx]; |
| 13383 |
|
| 13384 |
if (ar->rx_channel == survey->channel) |
| 13385 |
survey->filled |= SURVEY_INFO_IN_USE; |
| 13386 |
|
| 13387 |
return 0; |
| 13388 |
} |
| 13389 |
EXPORT_SYMBOL(ath12k_mac_op_get_survey); |
| 13390 |
|
| 13391 |
static void ath12k_mac_put_chain_rssi(struct station_info *sinfo, |
| 13392 |
struct ath12k_link_sta *arsta) |
| 13393 |
{ |
| 13394 |
s8 rssi; |
| 13395 |
int i; |
| 13396 |
|
| 13397 |
for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) { |
| 13398 |
sinfo->chains &= ~BIT(i); |
| 13399 |
rssi = arsta->chain_signal[i]; |
| 13400 |
|
| 13401 |
if (rssi != ATH12K_DEFAULT_NOISE_FLOOR && |
| 13402 |
rssi != ATH12K_INVALID_RSSI_FULL && |
| 13403 |
rssi != ATH12K_INVALID_RSSI_EMPTY && |
| 13404 |
rssi != 0) { |
| 13405 |
sinfo->chain_signal[i] = rssi; |
| 13406 |
sinfo->chains |= BIT(i); |
| 13407 |
sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL); |
| 13408 |
} |
| 13409 |
} |
| 13410 |
} |
| 13411 |
|
| 13412 |
void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw, |
| 13413 |
struct ieee80211_vif *vif, |
| 13414 |
struct ieee80211_sta *sta, |
| 13415 |
struct station_info *sinfo) |
| 13416 |
{ |
| 13417 |
struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
| 13418 |
struct ath12k_dp_link_peer_rate_info rate_info = {}; |
| 13419 |
struct ath12k_fw_stats_req_params params = {}; |
| 13420 |
struct ath12k_dp_link_peer *peer; |
| 13421 |
struct ath12k_link_sta *arsta; |
| 13422 |
s8 signal, noise_floor; |
| 13423 |
struct ath12k_dp *dp; |
| 13424 |
struct ath12k *ar; |
| 13425 |
bool db2dbm; |
| 13426 |
|
| 13427 |
lockdep_assert_wiphy(hw->wiphy); |
| 13428 |
|
| 13429 |
arsta = &ahsta->deflink; |
| 13430 |
ar = ath12k_get_ar_by_vif(hw, vif, arsta->link_id); |
| 13431 |
if (!ar) |
| 13432 |
return; |
| 13433 |
|
| 13434 |
dp = ath12k_ab_to_dp(ar->ab); |
| 13435 |
ath12k_dp_link_peer_get_sta_rate_info_stats(dp, arsta->addr, &rate_info); |
| 13436 |
|
| 13437 |
db2dbm = test_bit(WMI_TLV_SERVICE_HW_DB2DBM_CONVERSION_SUPPORT, |
| 13438 |
ar->ab->wmi_ab.svc_map); |
| 13439 |
|
| 13440 |
sinfo->rx_duration = rate_info.rx_duration; |
| 13441 |
sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION); |
| 13442 |
|
| 13443 |
sinfo->tx_duration = rate_info.tx_duration; |
| 13444 |
sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION); |
| 13445 |
|
| 13446 |
if (rate_info.txrate.legacy || rate_info.txrate.nss) { |
| 13447 |
if (rate_info.txrate.legacy) { |
| 13448 |
sinfo->txrate.legacy = rate_info.txrate.legacy; |
| 13449 |
} else { |
| 13450 |
sinfo->txrate.mcs = rate_info.txrate.mcs; |
| 13451 |
sinfo->txrate.nss = rate_info.txrate.nss; |
| 13452 |
sinfo->txrate.bw = rate_info.txrate.bw; |
| 13453 |
sinfo->txrate.he_gi = rate_info.txrate.he_gi; |
| 13454 |
sinfo->txrate.he_dcm = rate_info.txrate.he_dcm; |
| 13455 |
sinfo->txrate.he_ru_alloc = rate_info.txrate.he_ru_alloc; |
| 13456 |
sinfo->txrate.eht_gi = rate_info.txrate.eht_gi; |
| 13457 |
sinfo->txrate.eht_ru_alloc = rate_info.txrate.eht_ru_alloc; |
| 13458 |
} |
| 13459 |
sinfo->txrate.flags = rate_info.txrate.flags; |
| 13460 |
sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); |
| 13461 |
} |
| 13462 |
|
| 13463 |
/* TODO: Use real NF instead of default one. */ |
| 13464 |
signal = rate_info.rssi_comb; |
| 13465 |
|
| 13466 |
params.pdev_id = ath12k_mac_get_target_pdev_id(ar); |
| 13467 |
params.vdev_id = 0; |
| 13468 |
params.stats_id = WMI_REQUEST_VDEV_STAT; |
| 13469 |
|
| 13470 |
if (!signal && |
| 13471 |
ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA && |
| 13472 |
!(ath12k_mac_get_fw_stats(ar, ¶ms))) { |
| 13473 |
signal = arsta->rssi_beacon; |
| 13474 |
ath12k_fw_stats_reset(ar); |
| 13475 |
} |
| 13476 |
|
| 13477 |
params.stats_id = WMI_REQUEST_RSSI_PER_CHAIN_STAT; |
| 13478 |
if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) && |
| 13479 |
ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA && |
| 13480 |
!(ath12k_mac_get_fw_stats(ar, ¶ms))) { |
| 13481 |
ath12k_mac_put_chain_rssi(sinfo, arsta); |
| 13482 |
ath12k_fw_stats_reset(ar); |
| 13483 |
} |
| 13484 |
|
| 13485 |
spin_lock_bh(&ar->data_lock); |
| 13486 |
noise_floor = ath12k_pdev_get_noise_floor(ar); |
| 13487 |
spin_unlock_bh(&ar->data_lock); |
| 13488 |
|
| 13489 |
if (signal) { |
| 13490 |
sinfo->signal = db2dbm ? signal : signal + noise_floor; |
| 13491 |
sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL); |
| 13492 |
} |
| 13493 |
|
| 13494 |
sinfo->signal_avg = rate_info.signal_avg; |
| 13495 |
|
| 13496 |
if (!db2dbm) |
| 13497 |
sinfo->signal_avg += noise_floor; |
| 13498 |
|
| 13499 |
sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); |
| 13500 |
|
| 13501 |
spin_lock_bh(&dp->dp_lock); |
| 13502 |
peer = ath12k_dp_link_peer_find_by_addr(dp, arsta->addr); |
| 13503 |
if (!peer) { |
| 13504 |
spin_unlock_bh(&dp->dp_lock); |
| 13505 |
return; |
| 13506 |
} |
| 13507 |
|
| 13508 |
sinfo->tx_retries = peer->tx_retry_count; |
| 13509 |
sinfo->tx_failed = peer->tx_retry_failed; |
| 13510 |
sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES); |
| 13511 |
sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED); |
| 13512 |
|
| 13513 |
spin_unlock_bh(&dp->dp_lock); |
| 13514 |
} |
| 13515 |
EXPORT_SYMBOL(ath12k_mac_op_sta_statistics); |
| 13516 |
|
| 13517 |
void ath12k_mac_op_link_sta_statistics(struct ieee80211_hw *hw, |
| 13518 |
struct ieee80211_vif *vif, |
| 13519 |
struct ieee80211_link_sta *link_sta, |
| 13520 |
struct link_station_info *link_sinfo) |
| 13521 |
{ |
| 13522 |
struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(link_sta->sta); |
| 13523 |
struct ath12k_fw_stats_req_params params = {}; |
| 13524 |
struct ath12k_dp_link_peer *peer; |
| 13525 |
struct ath12k_link_sta *arsta; |
| 13526 |
struct ath12k *ar; |
| 13527 |
s8 signal; |
| 13528 |
bool db2dbm; |
| 13529 |
|
| 13530 |
lockdep_assert_wiphy(hw->wiphy); |
| 13531 |
|
| 13532 |
arsta = wiphy_dereference(hw->wiphy, ahsta->link[link_sta->link_id]); |
| 13533 |
|
| 13534 |
if (!arsta) |
| 13535 |
return; |
| 13536 |
|
| 13537 |
ar = ath12k_get_ar_by_vif(hw, vif, arsta->link_id); |
| 13538 |
if (!ar) |
| 13539 |
return; |
| 13540 |
|
| 13541 |
db2dbm = test_bit(WMI_TLV_SERVICE_HW_DB2DBM_CONVERSION_SUPPORT, |
| 13542 |
ar->ab->wmi_ab.svc_map); |
| 13543 |
|
| 13544 |
spin_lock_bh(&ar->ab->dp->dp_lock); |
| 13545 |
peer = ath12k_dp_link_peer_find_by_addr(ar->ab->dp, arsta->addr); |
| 13546 |
if (!peer) { |
| 13547 |
spin_unlock_bh(&ar->ab->dp->dp_lock); |
| 13548 |
return; |
| 13549 |
} |
| 13550 |
|
| 13551 |
link_sinfo->rx_duration = peer->rx_duration; |
| 13552 |
link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION); |
| 13553 |
|
| 13554 |
link_sinfo->tx_duration = peer->tx_duration; |
| 13555 |
link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION); |
| 13556 |
|
| 13557 |
if (peer->txrate.legacy || peer->txrate.nss) { |
| 13558 |
if (peer->txrate.legacy) { |
| 13559 |
link_sinfo->txrate.legacy = peer->txrate.legacy; |
| 13560 |
} else { |
| 13561 |
link_sinfo->txrate.mcs = peer->txrate.mcs; |
| 13562 |
link_sinfo->txrate.nss = peer->txrate.nss; |
| 13563 |
link_sinfo->txrate.bw = peer->txrate.bw; |
| 13564 |
link_sinfo->txrate.he_gi = peer->txrate.he_gi; |
| 13565 |
link_sinfo->txrate.he_dcm = peer->txrate.he_dcm; |
| 13566 |
link_sinfo->txrate.he_ru_alloc = |
| 13567 |
peer->txrate.he_ru_alloc; |
| 13568 |
link_sinfo->txrate.eht_gi = peer->txrate.eht_gi; |
| 13569 |
link_sinfo->txrate.eht_ru_alloc = |
| 13570 |
peer->txrate.eht_ru_alloc; |
| 13571 |
} |
| 13572 |
link_sinfo->txrate.flags = peer->txrate.flags; |
| 13573 |
link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); |
| 13574 |
} |
| 13575 |
|
| 13576 |
link_sinfo->signal_avg = ewma_avg_rssi_read(&peer->avg_rssi); |
| 13577 |
|
| 13578 |
if (!db2dbm) |
| 13579 |
link_sinfo->signal_avg += ATH12K_DEFAULT_NOISE_FLOOR; |
| 13580 |
|
| 13581 |
link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); |
| 13582 |
|
| 13583 |
link_sinfo->tx_retries = peer->tx_retry_count; |
| 13584 |
link_sinfo->tx_failed = peer->tx_retry_failed; |
| 13585 |
link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES); |
| 13586 |
link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED); |
| 13587 |
|
| 13588 |
/* TODO: Use real NF instead of default one. */ |
| 13589 |
signal = peer->rssi_comb; |
| 13590 |
|
| 13591 |
spin_unlock_bh(&ar->ab->dp->dp_lock); |
| 13592 |
|
| 13593 |
if (!signal && ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA) { |
| 13594 |
params.pdev_id = ath12k_mac_get_target_pdev_id(ar); |
| 13595 |
params.vdev_id = 0; |
| 13596 |
params.stats_id = WMI_REQUEST_VDEV_STAT; |
| 13597 |
|
| 13598 |
if (!ath12k_mac_get_fw_stats(ar, ¶ms)) { |
| 13599 |
signal = arsta->rssi_beacon; |
| 13600 |
ath12k_fw_stats_reset(ar); |
| 13601 |
} |
| 13602 |
} |
| 13603 |
|
| 13604 |
if (signal) { |
| 13605 |
link_sinfo->signal = |
| 13606 |
db2dbm ? signal : signal + ATH12K_DEFAULT_NOISE_FLOOR; |
| 13607 |
link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL); |
| 13608 |
} |
| 13609 |
} |
| 13610 |
EXPORT_SYMBOL(ath12k_mac_op_link_sta_statistics); |
| 13611 |
|
| 13612 |
int ath12k_mac_op_cancel_remain_on_channel(struct ieee80211_hw *hw, |
| 13613 |
struct ieee80211_vif *vif) |
| 13614 |
{ |
| 13615 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 13616 |
struct ath12k *ar; |
| 13617 |
|
| 13618 |
ar = ath12k_ah_to_ar(ah, 0); |
| 13619 |
|
| 13620 |
lockdep_assert_wiphy(hw->wiphy); |
| 13621 |
|
| 13622 |
spin_lock_bh(&ar->data_lock); |
| 13623 |
ar->scan.roc_notify = false; |
| 13624 |
spin_unlock_bh(&ar->data_lock); |
| 13625 |
|
| 13626 |
ath12k_scan_abort(ar); |
| 13627 |
|
| 13628 |
cancel_delayed_work_sync(&ar->scan.timeout); |
| 13629 |
wiphy_work_flush(hw->wiphy, &ar->scan.vdev_clean_wk); |
| 13630 |
|
| 13631 |
return 0; |
| 13632 |
} |
| 13633 |
EXPORT_SYMBOL(ath12k_mac_op_cancel_remain_on_channel); |
| 13634 |
|
| 13635 |
int ath12k_mac_op_remain_on_channel(struct ieee80211_hw *hw, |
| 13636 |
struct ieee80211_vif *vif, |
| 13637 |
struct ieee80211_channel *chan, |
| 13638 |
int duration, |
| 13639 |
enum ieee80211_roc_type type) |
| 13640 |
{ |
| 13641 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 13642 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 13643 |
struct ath12k_link_vif *arvif; |
| 13644 |
struct ath12k *ar; |
| 13645 |
u32 scan_time_msec; |
| 13646 |
bool create = true; |
| 13647 |
u8 link_id; |
| 13648 |
int ret; |
| 13649 |
|
| 13650 |
lockdep_assert_wiphy(hw->wiphy); |
| 13651 |
|
| 13652 |
ar = ath12k_mac_select_scan_device(hw, vif, chan->center_freq); |
| 13653 |
if (!ar) |
| 13654 |
return -EINVAL; |
| 13655 |
|
| 13656 |
/* check if any of the links of ML VIF is already started on |
| 13657 |
* radio(ar) corresponding to given scan frequency and use it, |
| 13658 |
* if not use deflink(link 0) for scan purpose. |
| 13659 |
*/ |
| 13660 |
|
| 13661 |
link_id = ath12k_mac_find_link_id_by_ar(ahvif, ar); |
| 13662 |
arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); |
| 13663 |
/* If the vif is already assigned to a specific vdev of an ar, |
| 13664 |
* check whether its already started, vdev which is started |
| 13665 |
* are not allowed to switch to a new radio. |
| 13666 |
* If the vdev is not started, but was earlier created on a |
| 13667 |
* different ar, delete that vdev and create a new one. We don't |
| 13668 |
* delete at the scan stop as an optimization to avoid redundant |
| 13669 |
* delete-create vdev's for the same ar, in case the request is |
| 13670 |
* always on the same band for the vif |
| 13671 |
*/ |
| 13672 |
if (arvif->is_created) { |
| 13673 |
if (WARN_ON(!arvif->ar)) |
| 13674 |
return -EINVAL; |
| 13675 |
|
| 13676 |
if (ar != arvif->ar && arvif->is_started) |
| 13677 |
return -EBUSY; |
| 13678 |
|
| 13679 |
if (ar != arvif->ar) { |
| 13680 |
ath12k_mac_remove_link_interface(hw, arvif); |
| 13681 |
ath12k_mac_unassign_link_vif(arvif); |
| 13682 |
} else { |
| 13683 |
create = false; |
| 13684 |
} |
| 13685 |
} |
| 13686 |
|
| 13687 |
if (create) { |
| 13688 |
arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); |
| 13689 |
|
| 13690 |
ret = ath12k_mac_vdev_create(ar, arvif); |
| 13691 |
if (ret) { |
| 13692 |
ath12k_warn(ar->ab, "unable to create scan vdev for roc: %d\n", |
| 13693 |
ret); |
| 13694 |
ath12k_mac_unassign_link_vif(arvif); |
| 13695 |
return ret; |
| 13696 |
} |
| 13697 |
} |
| 13698 |
|
| 13699 |
spin_lock_bh(&ar->data_lock); |
| 13700 |
|
| 13701 |
switch (ar->scan.state) { |
| 13702 |
case ATH12K_SCAN_IDLE: |
| 13703 |
reinit_completion(&ar->scan.started); |
| 13704 |
reinit_completion(&ar->scan.completed); |
| 13705 |
reinit_completion(&ar->scan.on_channel); |
| 13706 |
ar->scan.state = ATH12K_SCAN_STARTING; |
| 13707 |
ar->scan.is_roc = true; |
| 13708 |
ar->scan.arvif = arvif; |
| 13709 |
ar->scan.roc_freq = chan->center_freq; |
| 13710 |
ar->scan.roc_notify = true; |
| 13711 |
ret = 0; |
| 13712 |
break; |
| 13713 |
case ATH12K_SCAN_STARTING: |
| 13714 |
case ATH12K_SCAN_RUNNING: |
| 13715 |
case ATH12K_SCAN_ABORTING: |
| 13716 |
ret = -EBUSY; |
| 13717 |
break; |
| 13718 |
} |
| 13719 |
|
| 13720 |
spin_unlock_bh(&ar->data_lock); |
| 13721 |
|
| 13722 |
if (ret) |
| 13723 |
return ret; |
| 13724 |
|
| 13725 |
scan_time_msec = hw->wiphy->max_remain_on_channel_duration * 2; |
| 13726 |
|
| 13727 |
struct ath12k_wmi_scan_req_arg *arg __free(kfree) = |
| 13728 |
kzalloc_obj(*arg); |
| 13729 |
if (!arg) |
| 13730 |
return -ENOMEM; |
| 13731 |
|
| 13732 |
ath12k_wmi_start_scan_init(ar, arg); |
| 13733 |
arg->num_chan = 1; |
| 13734 |
|
| 13735 |
u32 *chan_list __free(kfree) = kcalloc(arg->num_chan, sizeof(*chan_list), |
| 13736 |
GFP_KERNEL); |
| 13737 |
if (!chan_list) |
| 13738 |
return -ENOMEM; |
| 13739 |
|
| 13740 |
arg->chan_list = chan_list; |
| 13741 |
arg->vdev_id = arvif->vdev_id; |
| 13742 |
arg->scan_id = ATH12K_SCAN_ID; |
| 13743 |
arg->chan_list[0] = chan->center_freq; |
| 13744 |
arg->dwell_time_active = scan_time_msec; |
| 13745 |
arg->dwell_time_passive = scan_time_msec; |
| 13746 |
arg->max_scan_time = scan_time_msec; |
| 13747 |
arg->scan_f_passive = 1; |
| 13748 |
arg->burst_duration = duration; |
| 13749 |
|
| 13750 |
ret = ath12k_start_scan(ar, arg); |
| 13751 |
if (ret) { |
| 13752 |
ath12k_warn(ar->ab, "failed to start roc scan: %d\n", ret); |
| 13753 |
|
| 13754 |
spin_lock_bh(&ar->data_lock); |
| 13755 |
ar->scan.state = ATH12K_SCAN_IDLE; |
| 13756 |
spin_unlock_bh(&ar->data_lock); |
| 13757 |
return ret; |
| 13758 |
} |
| 13759 |
|
| 13760 |
ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ); |
| 13761 |
if (ret == 0) { |
| 13762 |
ath12k_warn(ar->ab, "failed to switch to channel for roc scan\n"); |
| 13763 |
ret = ath12k_scan_stop(ar); |
| 13764 |
if (ret) |
| 13765 |
ath12k_warn(ar->ab, "failed to stop scan: %d\n", ret); |
| 13766 |
return -ETIMEDOUT; |
| 13767 |
} |
| 13768 |
|
| 13769 |
ieee80211_queue_delayed_work(hw, &ar->scan.timeout, |
| 13770 |
msecs_to_jiffies(duration)); |
| 13771 |
|
| 13772 |
return 0; |
| 13773 |
} |
| 13774 |
EXPORT_SYMBOL(ath12k_mac_op_remain_on_channel); |
| 13775 |
|
| 13776 |
void ath12k_mac_op_set_rekey_data(struct ieee80211_hw *hw, |
| 13777 |
struct ieee80211_vif *vif, |
| 13778 |
struct cfg80211_gtk_rekey_data *data) |
| 13779 |
{ |
| 13780 |
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
| 13781 |
struct ath12k_rekey_data *rekey_data; |
| 13782 |
struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
| 13783 |
struct ath12k *ar = ath12k_ah_to_ar(ah, 0); |
| 13784 |
struct ath12k_link_vif *arvif; |
| 13785 |
|
| 13786 |
lockdep_assert_wiphy(hw->wiphy); |
| 13787 |
|
| 13788 |
arvif = &ahvif->deflink; |
| 13789 |
rekey_data = &arvif->rekey_data; |
| 13790 |
|
| 13791 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac set rekey data vdev %d\n", |
| 13792 |
arvif->vdev_id); |
| 13793 |
|
| 13794 |
memcpy(rekey_data->kck, data->kck, NL80211_KCK_LEN); |
| 13795 |
memcpy(rekey_data->kek, data->kek, NL80211_KEK_LEN); |
| 13796 |
|
| 13797 |
/* The supplicant works on big-endian, the firmware expects it on |
| 13798 |
* little endian. |
| 13799 |
*/ |
| 13800 |
rekey_data->replay_ctr = get_unaligned_be64(data->replay_ctr); |
| 13801 |
|
| 13802 |
arvif->rekey_data.enable_offload = true; |
| 13803 |
|
| 13804 |
ath12k_dbg_dump(ar->ab, ATH12K_DBG_MAC, "kck", NULL, |
| 13805 |
rekey_data->kck, NL80211_KCK_LEN); |
| 13806 |
ath12k_dbg_dump(ar->ab, ATH12K_DBG_MAC, "kek", NULL, |
| 13807 |
rekey_data->kck, NL80211_KEK_LEN); |
| 13808 |
ath12k_dbg_dump(ar->ab, ATH12K_DBG_MAC, "replay ctr", NULL, |
| 13809 |
&rekey_data->replay_ctr, sizeof(rekey_data->replay_ctr)); |
| 13810 |
} |
| 13811 |
EXPORT_SYMBOL(ath12k_mac_op_set_rekey_data); |
| 13812 |
|
| 13813 |
void ath12k_mac_update_freq_range(struct ath12k *ar, |
| 13814 |
u32 freq_low, u32 freq_high) |
| 13815 |
{ |
| 13816 |
if (!(freq_low && freq_high)) |
| 13817 |
return; |
| 13818 |
|
| 13819 |
if (ar->freq_range.start_freq || ar->freq_range.end_freq) { |
| 13820 |
ar->freq_range.start_freq = min(ar->freq_range.start_freq, |
| 13821 |
MHZ_TO_KHZ(freq_low)); |
| 13822 |
ar->freq_range.end_freq = max(ar->freq_range.end_freq, |
| 13823 |
MHZ_TO_KHZ(freq_high)); |
| 13824 |
} else { |
| 13825 |
ar->freq_range.start_freq = MHZ_TO_KHZ(freq_low); |
| 13826 |
ar->freq_range.end_freq = MHZ_TO_KHZ(freq_high); |
| 13827 |
} |
| 13828 |
|
| 13829 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
| 13830 |
"mac pdev %u freq limit updated. New range %u->%u MHz\n", |
| 13831 |
ar->pdev->pdev_id, KHZ_TO_MHZ(ar->freq_range.start_freq), |
| 13832 |
KHZ_TO_MHZ(ar->freq_range.end_freq)); |
| 13833 |
} |
| 13834 |
|
| 13835 |
static void ath12k_mac_update_ch_list(struct ath12k *ar, |
| 13836 |
struct ieee80211_supported_band *band, |
| 13837 |
u32 freq_low, u32 freq_high) |
| 13838 |
{ |
| 13839 |
int i; |
| 13840 |
|
| 13841 |
if (!(freq_low && freq_high)) |
| 13842 |
return; |
| 13843 |
|
| 13844 |
for (i = 0; i < band->n_channels; i++) { |
| 13845 |
if (band->channels[i].center_freq < freq_low || |
| 13846 |
band->channels[i].center_freq > freq_high) |
| 13847 |
band->channels[i].flags |= IEEE80211_CHAN_DISABLED; |
| 13848 |
} |
| 13849 |
} |
| 13850 |
|
| 13851 |
static u32 ath12k_get_phy_id(struct ath12k *ar, u32 band) |
| 13852 |
{ |
| 13853 |
struct ath12k_pdev *pdev = ar->pdev; |
| 13854 |
struct ath12k_pdev_cap *pdev_cap = &pdev->cap; |
| 13855 |
|
| 13856 |
if (band == WMI_HOST_WLAN_2GHZ_CAP) |
| 13857 |
return pdev_cap->band[NL80211_BAND_2GHZ].phy_id; |
| 13858 |
|
| 13859 |
if (band == WMI_HOST_WLAN_5GHZ_CAP) |
| 13860 |
return pdev_cap->band[NL80211_BAND_5GHZ].phy_id; |
| 13861 |
|
| 13862 |
ath12k_warn(ar->ab, "unsupported phy cap:%d\n", band); |
| 13863 |
|
| 13864 |
return 0; |
| 13865 |
} |
| 13866 |
|
| 13867 |
static int ath12k_mac_update_band(struct ath12k *ar, |
| 13868 |
struct ieee80211_supported_band *orig_band, |
| 13869 |
struct ieee80211_supported_band *new_band) |
| 13870 |
{ |
| 13871 |
int i; |
| 13872 |
|
| 13873 |
if (!orig_band || !new_band) |
| 13874 |
return -EINVAL; |
| 13875 |
|
| 13876 |
if (orig_band->band != new_band->band) |
| 13877 |
return -EINVAL; |
| 13878 |
|
| 13879 |
for (i = 0; i < new_band->n_channels; i++) { |
| 13880 |
if (new_band->channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 13881 |
continue; |
| 13882 |
/* An enabled channel in new_band should not be already enabled |
| 13883 |
* in the orig_band |
| 13884 |
*/ |
| 13885 |
if (WARN_ON(!(orig_band->channels[i].flags & |
| 13886 |
IEEE80211_CHAN_DISABLED))) |
| 13887 |
return -EINVAL; |
| 13888 |
orig_band->channels[i].flags &= ~IEEE80211_CHAN_DISABLED; |
| 13889 |
} |
| 13890 |
return 0; |
| 13891 |
} |
| 13892 |
|
| 13893 |
static int ath12k_mac_setup_channels_rates(struct ath12k *ar, |
| 13894 |
u32 supported_bands, |
| 13895 |
struct ieee80211_supported_band *bands[]) |
| 13896 |
{ |
| 13897 |
struct ieee80211_supported_band *band; |
| 13898 |
struct ath12k_wmi_hal_reg_capabilities_ext_arg *reg_cap; |
| 13899 |
struct ath12k_base *ab = ar->ab; |
| 13900 |
u32 phy_id, freq_low, freq_high; |
| 13901 |
struct ath12k_hw *ah = ar->ah; |
| 13902 |
void *channels; |
| 13903 |
int ret; |
| 13904 |
|
| 13905 |
BUILD_BUG_ON((ARRAY_SIZE(ath12k_2ghz_channels) + |
| 13906 |
ARRAY_SIZE(ath12k_5ghz_channels) + |
| 13907 |
ARRAY_SIZE(ath12k_6ghz_channels)) != |
| 13908 |
ATH12K_NUM_CHANS); |
| 13909 |
|
| 13910 |
reg_cap = &ab->hal_reg_cap[ar->pdev_idx]; |
| 13911 |
|
| 13912 |
if (supported_bands & WMI_HOST_WLAN_2GHZ_CAP) { |
| 13913 |
channels = kmemdup(ath12k_2ghz_channels, |
| 13914 |
sizeof(ath12k_2ghz_channels), |
| 13915 |
GFP_KERNEL); |
| 13916 |
if (!channels) |
| 13917 |
return -ENOMEM; |
| 13918 |
|
| 13919 |
band = &ar->mac.sbands[NL80211_BAND_2GHZ]; |
| 13920 |
band->band = NL80211_BAND_2GHZ; |
| 13921 |
band->n_channels = ARRAY_SIZE(ath12k_2ghz_channels); |
| 13922 |
band->channels = channels; |
| 13923 |
band->n_bitrates = ath12k_g_rates_size; |
| 13924 |
band->bitrates = ath12k_g_rates; |
| 13925 |
|
| 13926 |
if (ab->hw_params->single_pdev_only) { |
| 13927 |
phy_id = ath12k_get_phy_id(ar, WMI_HOST_WLAN_2GHZ_CAP); |
| 13928 |
reg_cap = &ab->hal_reg_cap[phy_id]; |
| 13929 |
} |
| 13930 |
|
| 13931 |
freq_low = max(reg_cap->low_2ghz_chan, |
| 13932 |
ab->reg_freq_2ghz.start_freq); |
| 13933 |
freq_high = min(reg_cap->high_2ghz_chan, |
| 13934 |
ab->reg_freq_2ghz.end_freq); |
| 13935 |
|
| 13936 |
ath12k_mac_update_ch_list(ar, band, |
| 13937 |
reg_cap->low_2ghz_chan, |
| 13938 |
reg_cap->high_2ghz_chan); |
| 13939 |
|
| 13940 |
ath12k_mac_update_freq_range(ar, freq_low, freq_high); |
| 13941 |
|
| 13942 |
if (!bands[NL80211_BAND_2GHZ]) { |
| 13943 |
bands[NL80211_BAND_2GHZ] = band; |
| 13944 |
} else { |
| 13945 |
/* Split mac in same band under same wiphy */ |
| 13946 |
ret = ath12k_mac_update_band(ar, bands[NL80211_BAND_2GHZ], band); |
| 13947 |
if (ret) { |
| 13948 |
kfree(channels); |
| 13949 |
band->channels = NULL; |
| 13950 |
return ret; |
| 13951 |
} |
| 13952 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac pdev %u identified as 2 GHz split mac with start freq %d end freq %d", |
| 13953 |
ar->pdev->pdev_id, |
| 13954 |
KHZ_TO_MHZ(ar->freq_range.start_freq), |
| 13955 |
KHZ_TO_MHZ(ar->freq_range.end_freq)); |
| 13956 |
} |
| 13957 |
} |
| 13958 |
|
| 13959 |
if (supported_bands & WMI_HOST_WLAN_5GHZ_CAP) { |
| 13960 |
if (reg_cap->high_5ghz_chan >= ATH12K_MIN_6GHZ_FREQ) { |
| 13961 |
channels = kmemdup(ath12k_6ghz_channels, |
| 13962 |
sizeof(ath12k_6ghz_channels), GFP_KERNEL); |
| 13963 |
if (!channels) { |
| 13964 |
kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); |
| 13965 |
return -ENOMEM; |
| 13966 |
} |
| 13967 |
|
| 13968 |
ar->supports_6ghz = true; |
| 13969 |
band = &ar->mac.sbands[NL80211_BAND_6GHZ]; |
| 13970 |
band->band = NL80211_BAND_6GHZ; |
| 13971 |
band->n_channels = ARRAY_SIZE(ath12k_6ghz_channels); |
| 13972 |
band->channels = channels; |
| 13973 |
band->n_bitrates = ath12k_a_rates_size; |
| 13974 |
band->bitrates = ath12k_a_rates; |
| 13975 |
|
| 13976 |
freq_low = max(reg_cap->low_5ghz_chan, |
| 13977 |
ab->reg_freq_6ghz.start_freq); |
| 13978 |
freq_high = min(reg_cap->high_5ghz_chan, |
| 13979 |
ab->reg_freq_6ghz.end_freq); |
| 13980 |
|
| 13981 |
ath12k_mac_update_ch_list(ar, band, |
| 13982 |
reg_cap->low_5ghz_chan, |
| 13983 |
reg_cap->high_5ghz_chan); |
| 13984 |
|
| 13985 |
ath12k_mac_update_freq_range(ar, freq_low, freq_high); |
| 13986 |
ah->use_6ghz_regd = true; |
| 13987 |
|
| 13988 |
if (!bands[NL80211_BAND_6GHZ]) { |
| 13989 |
bands[NL80211_BAND_6GHZ] = band; |
| 13990 |
} else { |
| 13991 |
/* Split mac in same band under same wiphy */ |
| 13992 |
ret = ath12k_mac_update_band(ar, |
| 13993 |
bands[NL80211_BAND_6GHZ], |
| 13994 |
band); |
| 13995 |
if (ret) { |
| 13996 |
kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); |
| 13997 |
ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL; |
| 13998 |
kfree(channels); |
| 13999 |
band->channels = NULL; |
| 14000 |
return ret; |
| 14001 |
} |
| 14002 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac pdev %u identified as 6 GHz split mac with start freq %d end freq %d", |
| 14003 |
ar->pdev->pdev_id, |
| 14004 |
KHZ_TO_MHZ(ar->freq_range.start_freq), |
| 14005 |
KHZ_TO_MHZ(ar->freq_range.end_freq)); |
| 14006 |
} |
| 14007 |
} |
| 14008 |
|
| 14009 |
if (reg_cap->low_5ghz_chan < ATH12K_MIN_6GHZ_FREQ) { |
| 14010 |
channels = kmemdup(ath12k_5ghz_channels, |
| 14011 |
sizeof(ath12k_5ghz_channels), |
| 14012 |
GFP_KERNEL); |
| 14013 |
if (!channels) { |
| 14014 |
kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); |
| 14015 |
kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); |
| 14016 |
return -ENOMEM; |
| 14017 |
} |
| 14018 |
|
| 14019 |
band = &ar->mac.sbands[NL80211_BAND_5GHZ]; |
| 14020 |
band->band = NL80211_BAND_5GHZ; |
| 14021 |
band->n_channels = ARRAY_SIZE(ath12k_5ghz_channels); |
| 14022 |
band->channels = channels; |
| 14023 |
band->n_bitrates = ath12k_a_rates_size; |
| 14024 |
band->bitrates = ath12k_a_rates; |
| 14025 |
|
| 14026 |
if (ab->hw_params->single_pdev_only) { |
| 14027 |
phy_id = ath12k_get_phy_id(ar, WMI_HOST_WLAN_5GHZ_CAP); |
| 14028 |
reg_cap = &ab->hal_reg_cap[phy_id]; |
| 14029 |
} |
| 14030 |
|
| 14031 |
freq_low = max(reg_cap->low_5ghz_chan, |
| 14032 |
ab->reg_freq_5ghz.start_freq); |
| 14033 |
freq_high = min(reg_cap->high_5ghz_chan, |
| 14034 |
ab->reg_freq_5ghz.end_freq); |
| 14035 |
|
| 14036 |
ath12k_mac_update_ch_list(ar, band, |
| 14037 |
reg_cap->low_5ghz_chan, |
| 14038 |
reg_cap->high_5ghz_chan); |
| 14039 |
|
| 14040 |
ath12k_mac_update_freq_range(ar, freq_low, freq_high); |
| 14041 |
|
| 14042 |
if (!bands[NL80211_BAND_5GHZ]) { |
| 14043 |
bands[NL80211_BAND_5GHZ] = band; |
| 14044 |
} else { |
| 14045 |
/* Split mac in same band under same wiphy */ |
| 14046 |
ret = ath12k_mac_update_band(ar, |
| 14047 |
bands[NL80211_BAND_5GHZ], |
| 14048 |
band); |
| 14049 |
if (ret) { |
| 14050 |
kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); |
| 14051 |
ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL; |
| 14052 |
kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); |
| 14053 |
ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL; |
| 14054 |
kfree(channels); |
| 14055 |
band->channels = NULL; |
| 14056 |
return ret; |
| 14057 |
} |
| 14058 |
ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac pdev %u identified as 5 GHz split mac with start freq %d end freq %d", |
| 14059 |
ar->pdev->pdev_id, |
| 14060 |
KHZ_TO_MHZ(ar->freq_range.start_freq), |
| 14061 |
KHZ_TO_MHZ(ar->freq_range.end_freq)); |
| 14062 |
} |
| 14063 |
} |
| 14064 |
} |
| 14065 |
|
| 14066 |
return 0; |
| 14067 |
} |
| 14068 |
|
| 14069 |
static u16 ath12k_mac_get_ifmodes(struct ath12k_hw *ah) |
| 14070 |
{ |
| 14071 |
struct ath12k *ar; |
| 14072 |
int i; |
| 14073 |
u16 interface_modes = U16_MAX; |
| 14074 |
|
| 14075 |
for_each_ar(ah, ar, i) |
| 14076 |
interface_modes &= ar->ab->hw_params->interface_modes; |
| 14077 |
|
| 14078 |
return interface_modes == U16_MAX ? 0 : interface_modes; |
| 14079 |
} |
| 14080 |
|
| 14081 |
static bool ath12k_mac_is_iface_mode_enable(struct ath12k_hw *ah, |
| 14082 |
enum nl80211_iftype type) |
| 14083 |
{ |
| 14084 |
struct ath12k *ar; |
| 14085 |
int i; |
| 14086 |
u16 interface_modes, mode = 0; |
| 14087 |
bool is_enable = false; |
| 14088 |
|
| 14089 |
if (type == NL80211_IFTYPE_MESH_POINT) { |
| 14090 |
if (IS_ENABLED(CONFIG_MAC80211_MESH)) |
| 14091 |
mode = BIT(type); |
| 14092 |
} else { |
| 14093 |
mode = BIT(type); |
| 14094 |
} |
| 14095 |
|
| 14096 |
for_each_ar(ah, ar, i) { |
| 14097 |
interface_modes = ar->ab->hw_params->interface_modes; |
| 14098 |
if (interface_modes & mode) { |
| 14099 |
is_enable = true; |
| 14100 |
break; |
| 14101 |
} |
| 14102 |
} |
| 14103 |
|
| 14104 |
return is_enable; |
| 14105 |
} |
| 14106 |
|
| 14107 |
static int |
| 14108 |
ath12k_mac_setup_radio_iface_comb(struct ath12k *ar, |
| 14109 |
struct ieee80211_iface_combination *comb) |
| 14110 |
{ |
| 14111 |
u16 interface_modes = ar->ab->hw_params->interface_modes; |
| 14112 |
struct ieee80211_iface_limit *limits; |
| 14113 |
int n_limits, max_interfaces; |
| 14114 |
bool ap, mesh, p2p; |
| 14115 |
|
| 14116 |
ap = interface_modes & BIT(NL80211_IFTYPE_AP); |
| 14117 |
p2p = interface_modes & BIT(NL80211_IFTYPE_P2P_DEVICE); |
| 14118 |
|
| 14119 |
mesh = IS_ENABLED(CONFIG_MAC80211_MESH) && |
| 14120 |
(interface_modes & BIT(NL80211_IFTYPE_MESH_POINT)); |
| 14121 |
|
| 14122 |
if ((ap || mesh) && !p2p) { |
| 14123 |
n_limits = 2; |
| 14124 |
max_interfaces = 16; |
| 14125 |
} else if (p2p) { |
| 14126 |
n_limits = 3; |
| 14127 |
if (ap || mesh) |
| 14128 |
max_interfaces = 16; |
| 14129 |
else |
| 14130 |
max_interfaces = 3; |
| 14131 |
} else { |
| 14132 |
n_limits = 1; |
| 14133 |
max_interfaces = 1; |
| 14134 |
} |
| 14135 |
|
| 14136 |
limits = kzalloc_objs(*limits, n_limits); |
| 14137 |
if (!limits) |
| 14138 |
return -ENOMEM; |
| 14139 |
|
| 14140 |
limits[0].max = 1; |
| 14141 |
limits[0].types |= BIT(NL80211_IFTYPE_STATION); |
| 14142 |
|
| 14143 |
if (ap || mesh || p2p) |
| 14144 |
limits[1].max = max_interfaces; |
| 14145 |
|
| 14146 |
if (ap) |
| 14147 |
limits[1].types |= BIT(NL80211_IFTYPE_AP); |
| 14148 |
|
| 14149 |
if (mesh) |
| 14150 |
limits[1].types |= BIT(NL80211_IFTYPE_MESH_POINT); |
| 14151 |
|
| 14152 |
if (p2p) { |
| 14153 |
limits[1].types |= BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 14154 |
BIT(NL80211_IFTYPE_P2P_GO); |
| 14155 |
limits[2].max = 1; |
| 14156 |
limits[2].types |= BIT(NL80211_IFTYPE_P2P_DEVICE); |
| 14157 |
} |
| 14158 |
|
| 14159 |
comb[0].limits = limits; |
| 14160 |
comb[0].n_limits = n_limits; |
| 14161 |
comb[0].max_interfaces = max_interfaces; |
| 14162 |
comb[0].beacon_int_infra_match = true; |
| 14163 |
comb[0].beacon_int_min_gcd = 100; |
| 14164 |
|
| 14165 |
comb[0].num_different_channels = 1; |
| 14166 |
comb[0].radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
| 14167 |
BIT(NL80211_CHAN_WIDTH_20) | |
| 14168 |
BIT(NL80211_CHAN_WIDTH_40) | |
| 14169 |
BIT(NL80211_CHAN_WIDTH_80) | |
| 14170 |
BIT(NL80211_CHAN_WIDTH_160); |
| 14171 |
|
| 14172 |
return 0; |
| 14173 |
} |
| 14174 |
|
| 14175 |
static int |
| 14176 |
ath12k_mac_setup_global_iface_comb(struct ath12k_hw *ah, |
| 14177 |
struct wiphy_radio *radio, |
| 14178 |
u8 n_radio, |
| 14179 |
struct ieee80211_iface_combination *comb) |
| 14180 |
{ |
| 14181 |
const struct ieee80211_iface_combination *iter_comb; |
| 14182 |
struct ieee80211_iface_limit *limits; |
| 14183 |
int i, j, n_limits; |
| 14184 |
bool ap, mesh, p2p; |
| 14185 |
|
| 14186 |
if (!n_radio) |
| 14187 |
return 0; |
| 14188 |
|
| 14189 |
ap = ath12k_mac_is_iface_mode_enable(ah, NL80211_IFTYPE_AP); |
| 14190 |
p2p = ath12k_mac_is_iface_mode_enable(ah, NL80211_IFTYPE_P2P_DEVICE); |
| 14191 |
mesh = ath12k_mac_is_iface_mode_enable(ah, NL80211_IFTYPE_MESH_POINT); |
| 14192 |
|
| 14193 |
if ((ap || mesh) && !p2p) |
| 14194 |
n_limits = 2; |
| 14195 |
else if (p2p) |
| 14196 |
n_limits = 3; |
| 14197 |
else |
| 14198 |
n_limits = 1; |
| 14199 |
|
| 14200 |
limits = kzalloc_objs(*limits, n_limits); |
| 14201 |
if (!limits) |
| 14202 |
return -ENOMEM; |
| 14203 |
|
| 14204 |
for (i = 0; i < n_radio; i++) { |
| 14205 |
iter_comb = radio[i].iface_combinations; |
| 14206 |
for (j = 0; j < iter_comb->n_limits && j < n_limits; j++) { |
| 14207 |
limits[j].types |= iter_comb->limits[j].types; |
| 14208 |
limits[j].max += iter_comb->limits[j].max; |
| 14209 |
} |
| 14210 |
|
| 14211 |
comb->max_interfaces += iter_comb->max_interfaces; |
| 14212 |
comb->num_different_channels += iter_comb->num_different_channels; |
| 14213 |
comb->radar_detect_widths |= iter_comb->radar_detect_widths; |
| 14214 |
} |
| 14215 |
|
| 14216 |
comb->limits = limits; |
| 14217 |
comb->n_limits = n_limits; |
| 14218 |
comb->beacon_int_infra_match = true; |
| 14219 |
comb->beacon_int_min_gcd = 100; |
| 14220 |
|
| 14221 |
return 0; |
| 14222 |
} |
| 14223 |
|
| 14224 |
static |
| 14225 |
void ath12k_mac_cleanup_iface_comb(const struct ieee80211_iface_combination *iface_comb) |
| 14226 |
{ |
| 14227 |
kfree(iface_comb[0].limits); |
| 14228 |
kfree(iface_comb); |
| 14229 |
} |
| 14230 |
|
| 14231 |
static void ath12k_mac_cleanup_iface_combinations(struct ath12k_hw *ah) |
| 14232 |
{ |
| 14233 |
struct wiphy *wiphy = ah->hw->wiphy; |
| 14234 |
const struct wiphy_radio *radio; |
| 14235 |
int i; |
| 14236 |
|
| 14237 |
if (wiphy->n_radio > 0) { |
| 14238 |
radio = wiphy->radio; |
| 14239 |
for (i = 0; i < wiphy->n_radio; i++) |
| 14240 |
ath12k_mac_cleanup_iface_comb(radio[i].iface_combinations); |
| 14241 |
|
| 14242 |
kfree(wiphy->radio); |
| 14243 |
} |
| 14244 |
|
| 14245 |
ath12k_mac_cleanup_iface_comb(wiphy->iface_combinations); |
| 14246 |
} |
| 14247 |
|
| 14248 |
static int ath12k_mac_setup_iface_combinations(struct ath12k_hw *ah) |
| 14249 |
{ |
| 14250 |
struct ieee80211_iface_combination *combinations, *comb; |
| 14251 |
struct wiphy *wiphy = ah->hw->wiphy; |
| 14252 |
struct wiphy_radio *radio; |
| 14253 |
int n_combinations = 1; |
| 14254 |
struct ath12k *ar; |
| 14255 |
int i, ret; |
| 14256 |
|
| 14257 |
if (ah->num_radio == 1) { |
| 14258 |
ar = &ah->radio[0]; |
| 14259 |
|
| 14260 |
if (ar->ab->hw_params->single_pdev_only) |
| 14261 |
n_combinations = 2; |
| 14262 |
|
| 14263 |
combinations = kzalloc_objs(*combinations, n_combinations); |
| 14264 |
if (!combinations) |
| 14265 |
return -ENOMEM; |
| 14266 |
|
| 14267 |
ret = ath12k_mac_setup_radio_iface_comb(ar, combinations); |
| 14268 |
if (ret) { |
| 14269 |
ath12k_hw_warn(ah, "failed to setup radio interface combinations for one radio: %d", |
| 14270 |
ret); |
| 14271 |
goto err_free_combinations; |
| 14272 |
} |
| 14273 |
|
| 14274 |
if (ar->ab->hw_params->single_pdev_only) { |
| 14275 |
comb = combinations + 1; |
| 14276 |
memcpy(comb, combinations, sizeof(*comb)); |
| 14277 |
comb->num_different_channels = 2; |
| 14278 |
comb->radar_detect_widths = 0; |
| 14279 |
} |
| 14280 |
|
| 14281 |
goto out; |
| 14282 |
} |
| 14283 |
|
| 14284 |
combinations = kzalloc_objs(*combinations, n_combinations); |
| 14285 |
if (!combinations) |
| 14286 |
return -ENOMEM; |
| 14287 |
|
| 14288 |
/* there are multiple radios */ |
| 14289 |
|
| 14290 |
radio = kzalloc_objs(*radio, ah->num_radio); |
| 14291 |
if (!radio) { |
| 14292 |
ret = -ENOMEM; |
| 14293 |
goto err_free_combinations; |
| 14294 |
} |
| 14295 |
|
| 14296 |
for_each_ar(ah, ar, i) { |
| 14297 |
comb = kzalloc_obj(*comb); |
| 14298 |
if (!comb) { |
| 14299 |
ret = -ENOMEM; |
| 14300 |
goto err_free_radios; |
| 14301 |
} |
| 14302 |
|
| 14303 |
ret = ath12k_mac_setup_radio_iface_comb(ar, comb); |
| 14304 |
if (ret) { |
| 14305 |
ath12k_hw_warn(ah, "failed to setup radio interface combinations for radio %d: %d", |
| 14306 |
i, ret); |
| 14307 |
kfree(comb); |
| 14308 |
goto err_free_radios; |
| 14309 |
} |
| 14310 |
|
| 14311 |
radio[i].freq_range = &ar->freq_range; |
| 14312 |
radio[i].n_freq_range = 1; |
| 14313 |
|
| 14314 |
radio[i].iface_combinations = comb; |
| 14315 |
radio[i].n_iface_combinations = 1; |
| 14316 |
} |
| 14317 |
|
| 14318 |
ret = ath12k_mac_setup_global_iface_comb(ah, radio, ah->num_radio, combinations); |
| 14319 |
if (ret) { |
| 14320 |
ath12k_hw_warn(ah, "failed to setup global interface combinations: %d", |
| 14321 |
ret); |
| 14322 |
goto err_free_all_radios; |
| 14323 |
} |
| 14324 |
|
| 14325 |
wiphy->radio = radio; |
| 14326 |
wiphy->n_radio = ah->num_radio; |
| 14327 |
|
| 14328 |
out: |
| 14329 |
wiphy->iface_combinations = combinations; |
| 14330 |
wiphy->n_iface_combinations = n_combinations; |
| 14331 |
|
| 14332 |
return 0; |
| 14333 |
|
| 14334 |
err_free_all_radios: |
| 14335 |
i = ah->num_radio; |
| 14336 |
|
| 14337 |
err_free_radios: |
| 14338 |
while (i--) |
| 14339 |
ath12k_mac_cleanup_iface_comb(radio[i].iface_combinations); |
| 14340 |
|
| 14341 |
kfree(radio); |
| 14342 |
|
| 14343 |
err_free_combinations: |
| 14344 |
kfree(combinations); |
| 14345 |
|
| 14346 |
return ret; |
| 14347 |
} |
| 14348 |
|
| 14349 |
static const u8 ath12k_if_types_ext_capa[] = { |
| 14350 |
[0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, |
| 14351 |
[2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, |
| 14352 |
[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, |
| 14353 |
}; |
| 14354 |
|
| 14355 |
static const u8 ath12k_if_types_ext_capa_sta[] = { |
| 14356 |
[0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, |
| 14357 |
[2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, |
| 14358 |
[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, |
| 14359 |
[9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT, |
| 14360 |
}; |
| 14361 |
|
| 14362 |
static const u8 ath12k_if_types_ext_capa_ap[] = { |
| 14363 |
[0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, |
| 14364 |
[2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, |
| 14365 |
[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, |
| 14366 |
[9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT, |
| 14367 |
[10] = WLAN_EXT_CAPA11_EMA_SUPPORT, |
| 14368 |
}; |
| 14369 |
|
| 14370 |
static struct wiphy_iftype_ext_capab ath12k_iftypes_ext_capa[] = { |
| 14371 |
{ |
| 14372 |
.extended_capabilities = ath12k_if_types_ext_capa, |
| 14373 |
.extended_capabilities_mask = ath12k_if_types_ext_capa, |
| 14374 |
.extended_capabilities_len = sizeof(ath12k_if_types_ext_capa), |
| 14375 |
}, { |
| 14376 |
.iftype = NL80211_IFTYPE_STATION, |
| 14377 |
.extended_capabilities = ath12k_if_types_ext_capa_sta, |
| 14378 |
.extended_capabilities_mask = ath12k_if_types_ext_capa_sta, |
| 14379 |
.extended_capabilities_len = |
| 14380 |
sizeof(ath12k_if_types_ext_capa_sta), |
| 14381 |
}, { |
| 14382 |
.iftype = NL80211_IFTYPE_AP, |
| 14383 |
.extended_capabilities = ath12k_if_types_ext_capa_ap, |
| 14384 |
.extended_capabilities_mask = ath12k_if_types_ext_capa_ap, |
| 14385 |
.extended_capabilities_len = |
| 14386 |
sizeof(ath12k_if_types_ext_capa_ap), |
| 14387 |
.eml_capabilities = 0, |
| 14388 |
.mld_capa_and_ops = 0, |
| 14389 |
}, |
| 14390 |
}; |
| 14391 |
|
| 14392 |
static void ath12k_mac_cleanup_unregister(struct ath12k *ar) |
| 14393 |
{ |
| 14394 |
idr_for_each(&ar->txmgmt_idr, ath12k_mac_tx_mgmt_pending_free, ar); |
| 14395 |
idr_destroy(&ar->txmgmt_idr); |
| 14396 |
|
| 14397 |
kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); |
| 14398 |
kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); |
| 14399 |
kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); |
| 14400 |
} |
| 14401 |
|
| 14402 |
static void ath12k_mac_hw_unregister(struct ath12k_hw *ah) |
| 14403 |
{ |
| 14404 |
struct ieee80211_hw *hw = ah->hw; |
| 14405 |
struct ath12k *ar; |
| 14406 |
int i; |
| 14407 |
|
| 14408 |
for_each_ar(ah, ar, i) { |
| 14409 |
cancel_work_sync(&ar->regd_channel_update_work); |
| 14410 |
cancel_work_sync(&ar->regd_update_work); |
| 14411 |
ath12k_debugfs_unregister(ar); |
| 14412 |
ath12k_fw_stats_reset(ar); |
| 14413 |
} |
| 14414 |
|
| 14415 |
ieee80211_unregister_hw(hw); |
| 14416 |
|
| 14417 |
for_each_ar(ah, ar, i) |
| 14418 |
ath12k_mac_cleanup_unregister(ar); |
| 14419 |
|
| 14420 |
ath12k_mac_cleanup_iface_combinations(ah); |
| 14421 |
|
| 14422 |
SET_IEEE80211_DEV(hw, NULL); |
| 14423 |
} |
| 14424 |
|
| 14425 |
static int ath12k_mac_setup_register(struct ath12k *ar, |
| 14426 |
u32 *ht_cap, |
| 14427 |
struct ieee80211_supported_band *bands[]) |
| 14428 |
{ |
| 14429 |
struct ath12k_pdev_cap *cap = &ar->pdev->cap; |
| 14430 |
int ret; |
| 14431 |
|
| 14432 |
init_waitqueue_head(&ar->txmgmt_empty_waitq); |
| 14433 |
idr_init(&ar->txmgmt_idr); |
| 14434 |
spin_lock_init(&ar->txmgmt_idr_lock); |
| 14435 |
|
| 14436 |
ath12k_pdev_caps_update(ar); |
| 14437 |
|
| 14438 |
ret = ath12k_mac_setup_channels_rates(ar, |
| 14439 |
cap->supported_bands, |
| 14440 |
bands); |
| 14441 |
if (ret) |
| 14442 |
return ret; |
| 14443 |
|
| 14444 |
ath12k_mac_setup_ht_vht_cap(ar, cap, ht_cap); |
| 14445 |
ath12k_mac_setup_sband_iftype_data(ar, cap); |
| 14446 |
|
| 14447 |
ar->max_num_stations = ath12k_core_get_max_station_per_radio(ar->ab); |
| 14448 |
ar->max_num_peers = ath12k_core_get_max_peers_per_radio(ar->ab); |
| 14449 |
|
| 14450 |
ar->rssi_info.min_nf_dbm = ATH12K_DEFAULT_NOISE_FLOOR; |
| 14451 |
ar->rssi_info.temp_offset = 0; |
| 14452 |
ar->rssi_info.noise_floor = ar->rssi_info.min_nf_dbm + ar->rssi_info.temp_offset; |
| 14453 |
|
| 14454 |
return 0; |
| 14455 |
} |
| 14456 |
|
| 14457 |
static int ath12k_mac_hw_register(struct ath12k_hw *ah) |
| 14458 |
{ |
| 14459 |
struct ieee80211_hw *hw = ah->hw; |
| 14460 |
struct wiphy *wiphy = hw->wiphy; |
| 14461 |
struct ath12k *ar = ath12k_ah_to_ar(ah, 0); |
| 14462 |
struct ath12k_base *ab = ar->ab; |
| 14463 |
struct ath12k_pdev *pdev; |
| 14464 |
struct ath12k_pdev_cap *cap; |
| 14465 |
static const u32 cipher_suites[] = { |
| 14466 |
WLAN_CIPHER_SUITE_TKIP, |
| 14467 |
WLAN_CIPHER_SUITE_CCMP, |
| 14468 |
WLAN_CIPHER_SUITE_AES_CMAC, |
| 14469 |
WLAN_CIPHER_SUITE_BIP_CMAC_256, |
| 14470 |
WLAN_CIPHER_SUITE_BIP_GMAC_128, |
| 14471 |
WLAN_CIPHER_SUITE_BIP_GMAC_256, |
| 14472 |
WLAN_CIPHER_SUITE_GCMP, |
| 14473 |
WLAN_CIPHER_SUITE_GCMP_256, |
| 14474 |
WLAN_CIPHER_SUITE_CCMP_256, |
| 14475 |
}; |
| 14476 |
int ret, i, j; |
| 14477 |
u32 ht_cap = U32_MAX, antennas_rx = 0, antennas_tx = 0; |
| 14478 |
bool is_6ghz = false, is_raw_mode = false, is_monitor_disable = false; |
| 14479 |
u8 *mac_addr = NULL; |
| 14480 |
u8 mbssid_max_interfaces = 0; |
| 14481 |
|
| 14482 |
wiphy->max_ap_assoc_sta = 0; |
| 14483 |
|
| 14484 |
for_each_ar(ah, ar, i) { |
| 14485 |
u32 ht_cap_info = 0; |
| 14486 |
|
| 14487 |
pdev = ar->pdev; |
| 14488 |
if (ar->ab->pdevs_macaddr_valid) { |
| 14489 |
ether_addr_copy(ar->mac_addr, pdev->mac_addr); |
| 14490 |
} else { |
| 14491 |
ether_addr_copy(ar->mac_addr, ar->ab->mac_addr); |
| 14492 |
ar->mac_addr[4] += ar->pdev_idx; |
| 14493 |
} |
| 14494 |
|
| 14495 |
ret = ath12k_mac_setup_register(ar, &ht_cap_info, hw->wiphy->bands); |
| 14496 |
if (ret) |
| 14497 |
goto err_cleanup_unregister; |
| 14498 |
|
| 14499 |
/* 6 GHz does not support HT Cap, hence do not consider it */ |
| 14500 |
if (!ar->supports_6ghz) |
| 14501 |
ht_cap &= ht_cap_info; |
| 14502 |
|
| 14503 |
wiphy->max_ap_assoc_sta += ar->max_num_stations; |
| 14504 |
|
| 14505 |
/* Advertise the max antenna support of all radios, driver can handle |
| 14506 |
* per pdev specific antenna setting based on pdev cap when antenna |
| 14507 |
* changes are made |
| 14508 |
*/ |
| 14509 |
cap = &pdev->cap; |
| 14510 |
|
| 14511 |
antennas_rx = max_t(u32, antennas_rx, cap->rx_chain_mask); |
| 14512 |
antennas_tx = max_t(u32, antennas_tx, cap->tx_chain_mask); |
| 14513 |
|
| 14514 |
if (ar->supports_6ghz) |
| 14515 |
is_6ghz = true; |
| 14516 |
|
| 14517 |
if (test_bit(ATH12K_FLAG_RAW_MODE, &ar->ab->dev_flags)) |
| 14518 |
is_raw_mode = true; |
| 14519 |
|
| 14520 |
if (!ar->ab->hw_params->supports_monitor) |
| 14521 |
is_monitor_disable = true; |
| 14522 |
|
| 14523 |
if (i == 0) |
| 14524 |
mac_addr = ar->mac_addr; |
| 14525 |
else |
| 14526 |
mac_addr = ab->mac_addr; |
| 14527 |
|
| 14528 |
mbssid_max_interfaces += TARGET_NUM_VDEVS(ar->ab); |
| 14529 |
} |
| 14530 |
|
| 14531 |
wiphy->available_antennas_rx = antennas_rx; |
| 14532 |
wiphy->available_antennas_tx = antennas_tx; |
| 14533 |
|
| 14534 |
SET_IEEE80211_PERM_ADDR(hw, mac_addr); |
| 14535 |
SET_IEEE80211_DEV(hw, ab->dev); |
| 14536 |
|
| 14537 |
ret = ath12k_mac_setup_iface_combinations(ah); |
| 14538 |
if (ret) { |
| 14539 |
ath12k_err(ab, "failed to setup interface combinations: %d\n", ret); |
| 14540 |
goto err_complete_cleanup_unregister; |
| 14541 |
} |
| 14542 |
|
| 14543 |
wiphy->interface_modes = ath12k_mac_get_ifmodes(ah); |
| 14544 |
|
| 14545 |
if (ah->num_radio == 1 && |
| 14546 |
wiphy->bands[NL80211_BAND_2GHZ] && |
| 14547 |
wiphy->bands[NL80211_BAND_5GHZ] && |
| 14548 |
wiphy->bands[NL80211_BAND_6GHZ]) |
| 14549 |
ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); |
| 14550 |
|
| 14551 |
ieee80211_hw_set(hw, SIGNAL_DBM); |
| 14552 |
ieee80211_hw_set(hw, SUPPORTS_PS); |
| 14553 |
ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); |
| 14554 |
ieee80211_hw_set(hw, MFP_CAPABLE); |
| 14555 |
ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); |
| 14556 |
ieee80211_hw_set(hw, HAS_RATE_CONTROL); |
| 14557 |
ieee80211_hw_set(hw, AP_LINK_PS); |
| 14558 |
ieee80211_hw_set(hw, SPECTRUM_MGMT); |
| 14559 |
ieee80211_hw_set(hw, CONNECTION_MONITOR); |
| 14560 |
ieee80211_hw_set(hw, SUPPORTS_PER_STA_GTK); |
| 14561 |
ieee80211_hw_set(hw, CHANCTX_STA_CSA); |
| 14562 |
ieee80211_hw_set(hw, QUEUE_CONTROL); |
| 14563 |
ieee80211_hw_set(hw, SUPPORTS_TX_FRAG); |
| 14564 |
ieee80211_hw_set(hw, REPORTS_LOW_ACK); |
| 14565 |
ieee80211_hw_set(hw, NO_VIRTUAL_MONITOR); |
| 14566 |
|
| 14567 |
if (test_bit(WMI_TLV_SERVICE_ETH_OFFLOAD, ar->wmi->wmi_ab->svc_map)) { |
| 14568 |
ieee80211_hw_set(hw, SUPPORTS_TX_ENCAP_OFFLOAD); |
| 14569 |
ieee80211_hw_set(hw, SUPPORTS_RX_DECAP_OFFLOAD); |
| 14570 |
} |
| 14571 |
|
| 14572 |
if (cap->nss_ratio_enabled) |
| 14573 |
ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW); |
| 14574 |
|
| 14575 |
if ((ht_cap & WMI_HT_CAP_ENABLED) || is_6ghz) { |
| 14576 |
ieee80211_hw_set(hw, AMPDU_AGGREGATION); |
| 14577 |
ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW); |
| 14578 |
ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); |
| 14579 |
ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); |
| 14580 |
ieee80211_hw_set(hw, USES_RSS); |
| 14581 |
} |
| 14582 |
|
| 14583 |
wiphy->features |= NL80211_FEATURE_STATIC_SMPS; |
| 14584 |
wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
| 14585 |
|
| 14586 |
/* TODO: Check if HT capability advertised from firmware is different |
| 14587 |
* for each band for a dual band capable radio. It will be tricky to |
| 14588 |
* handle it when the ht capability different for each band. |
| 14589 |
*/ |
| 14590 |
if (ht_cap & WMI_HT_CAP_DYNAMIC_SMPS || |
| 14591 |
(is_6ghz && ab->hw_params->supports_dynamic_smps_6ghz)) |
| 14592 |
wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS; |
| 14593 |
|
| 14594 |
wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; |
| 14595 |
wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; |
| 14596 |
|
| 14597 |
hw->max_listen_interval = ATH12K_MAX_HW_LISTEN_INTERVAL; |
| 14598 |
|
| 14599 |
wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
| 14600 |
wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
| 14601 |
wiphy->max_remain_on_channel_duration = 5000; |
| 14602 |
|
| 14603 |
wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
| 14604 |
wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | |
| 14605 |
NL80211_FEATURE_AP_SCAN; |
| 14606 |
|
| 14607 |
wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION; |
| 14608 |
|
| 14609 |
/* MLO is not yet supported so disable Wireless Extensions for now |
| 14610 |
* to make sure ath12k users don't use it. This flag can be removed |
| 14611 |
* once WIPHY_FLAG_SUPPORTS_MLO is enabled. |
| 14612 |
*/ |
| 14613 |
wiphy->flags |= WIPHY_FLAG_DISABLE_WEXT; |
| 14614 |
|
| 14615 |
/* Copy over MLO related capabilities received from |
| 14616 |
* WMI_SERVICE_READY_EXT2_EVENT if single_chip_mlo_supp is set. |
| 14617 |
*/ |
| 14618 |
if (ab->ag->mlo_capable) { |
| 14619 |
ath12k_iftypes_ext_capa[2].eml_capabilities = cap->eml_cap; |
| 14620 |
ath12k_iftypes_ext_capa[2].mld_capa_and_ops = cap->mld_cap; |
| 14621 |
wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO; |
| 14622 |
|
| 14623 |
ieee80211_hw_set(hw, MLO_MCAST_MULTI_LINK_TX); |
| 14624 |
} |
| 14625 |
|
| 14626 |
hw->queues = ATH12K_HW_MAX_QUEUES; |
| 14627 |
wiphy->tx_queue_len = ATH12K_QUEUE_LEN; |
| 14628 |
hw->offchannel_tx_hw_queue = ATH12K_HW_MAX_QUEUES - 1; |
| 14629 |
hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_EHT; |
| 14630 |
|
| 14631 |
hw->vif_data_size = sizeof(struct ath12k_vif); |
| 14632 |
hw->sta_data_size = sizeof(struct ath12k_sta); |
| 14633 |
hw->extra_tx_headroom = ab->hw_params->iova_mask; |
| 14634 |
|
| 14635 |
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); |
| 14636 |
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STA_TX_PWR); |
| 14637 |
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT); |
| 14638 |
if (test_bit(WMI_TLV_SERVICE_BSS_COLOR_OFFLOAD, |
| 14639 |
ab->wmi_ab.svc_map)) { |
| 14640 |
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BSS_COLOR); |
| 14641 |
ieee80211_hw_set(hw, DETECTS_COLOR_COLLISION); |
| 14642 |
} |
| 14643 |
|
| 14644 |
wiphy->cipher_suites = cipher_suites; |
| 14645 |
wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); |
| 14646 |
|
| 14647 |
wiphy->iftype_ext_capab = ath12k_iftypes_ext_capa; |
| 14648 |
wiphy->num_iftype_ext_capab = ARRAY_SIZE(ath12k_iftypes_ext_capa); |
| 14649 |
|
| 14650 |
wiphy->mbssid_max_interfaces = mbssid_max_interfaces; |
| 14651 |
wiphy->ema_max_profile_periodicity = TARGET_EMA_MAX_PROFILE_PERIOD; |
| 14652 |
ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); |
| 14653 |
|
| 14654 |
if (is_6ghz) { |
| 14655 |
wiphy_ext_feature_set(wiphy, |
| 14656 |
NL80211_EXT_FEATURE_FILS_DISCOVERY); |
| 14657 |
wiphy_ext_feature_set(wiphy, |
| 14658 |
NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP); |
| 14659 |
} |
| 14660 |
|
| 14661 |
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_PUNCT); |
| 14662 |
if (test_bit(WMI_TLV_SERVICE_BEACON_PROTECTION_SUPPORT, ab->wmi_ab.svc_map)) |
| 14663 |
wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_BEACON_PROTECTION); |
| 14664 |
|
| 14665 |
ath12k_reg_init(hw); |
| 14666 |
|
| 14667 |
if (!is_raw_mode) { |
| 14668 |
hw->netdev_features = NETIF_F_HW_CSUM; |
| 14669 |
ieee80211_hw_set(hw, SW_CRYPTO_CONTROL); |
| 14670 |
ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); |
| 14671 |
} |
| 14672 |
|
| 14673 |
if (test_bit(WMI_TLV_SERVICE_NLO, ar->wmi->wmi_ab->svc_map)) { |
| 14674 |
wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS; |
| 14675 |
wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS; |
| 14676 |
wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH; |
| 14677 |
wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS; |
| 14678 |
wiphy->max_sched_scan_plan_interval = |
| 14679 |
WMI_PNO_MAX_SCHED_SCAN_PLAN_INT; |
| 14680 |
wiphy->max_sched_scan_plan_iterations = |
| 14681 |
WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS; |
| 14682 |
wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 14683 |
} |
| 14684 |
|
| 14685 |
ret = ath12k_wow_init(ar); |
| 14686 |
if (ret) { |
| 14687 |
ath12k_warn(ar->ab, "failed to init wow: %d\n", ret); |
| 14688 |
goto err_cleanup_if_combs; |
| 14689 |
} |
| 14690 |
|
| 14691 |
/* Boot-time regulatory updates have already been processed. |
| 14692 |
* Mark them as complete now, because after registration, |
| 14693 |
* cfg80211 will notify us again if there are any pending hints. |
| 14694 |
* We need to wait for those hints to be processed, so it's |
| 14695 |
* important to mark the boot-time updates as complete before |
| 14696 |
* proceeding with registration. |
| 14697 |
*/ |
| 14698 |
for_each_ar(ah, ar, i) |
| 14699 |
complete_all(&ar->regd_update_completed); |
| 14700 |
|
| 14701 |
ret = ieee80211_register_hw(hw); |
| 14702 |
if (ret) { |
| 14703 |
ath12k_err(ab, "ieee80211 registration failed: %d\n", ret); |
| 14704 |
goto err_cleanup_if_combs; |
| 14705 |
} |
| 14706 |
|
| 14707 |
if (is_monitor_disable) |
| 14708 |
/* There's a race between calling ieee80211_register_hw() |
| 14709 |
* and here where the monitor mode is enabled for a little |
| 14710 |
* while. But that time is so short and in practice it doesn't make |
| 14711 |
* a difference in real life. |
| 14712 |
*/ |
| 14713 |
wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MONITOR); |
| 14714 |
|
| 14715 |
for_each_ar(ah, ar, i) { |
| 14716 |
/* Apply the regd received during initialization */ |
| 14717 |
ret = ath12k_regd_update(ar, true); |
| 14718 |
if (ret) { |
| 14719 |
ath12k_err(ar->ab, "ath12k regd update failed: %d\n", ret); |
| 14720 |
goto err_unregister_hw; |
| 14721 |
} |
| 14722 |
|
| 14723 |
if (ar->ab->hw_params->current_cc_support && ab->new_alpha2[0]) { |
| 14724 |
struct wmi_set_current_country_arg current_cc = {}; |
| 14725 |
|
| 14726 |
memcpy(¤t_cc.alpha2, ab->new_alpha2, 2); |
| 14727 |
memcpy(&ar->alpha2, ab->new_alpha2, 2); |
| 14728 |
|
| 14729 |
reinit_completion(&ar->regd_update_completed); |
| 14730 |
|
| 14731 |
ret = ath12k_wmi_send_set_current_country_cmd(ar, ¤t_cc); |
| 14732 |
if (ret) |
| 14733 |
ath12k_warn(ar->ab, |
| 14734 |
"failed set cc code for mac register: %d\n", |
| 14735 |
ret); |
| 14736 |
} |
| 14737 |
|
| 14738 |
ath12k_fw_stats_init(ar); |
| 14739 |
ath12k_debugfs_register(ar); |
| 14740 |
} |
| 14741 |
|
| 14742 |
return 0; |
| 14743 |
|
| 14744 |
err_unregister_hw: |
| 14745 |
for_each_ar(ah, ar, i) |
| 14746 |
ath12k_debugfs_unregister(ar); |
| 14747 |
|
| 14748 |
ieee80211_unregister_hw(hw); |
| 14749 |
|
| 14750 |
err_cleanup_if_combs: |
| 14751 |
ath12k_mac_cleanup_iface_combinations(ah); |
| 14752 |
|
| 14753 |
err_complete_cleanup_unregister: |
| 14754 |
i = ah->num_radio; |
| 14755 |
|
| 14756 |
err_cleanup_unregister: |
| 14757 |
for (j = 0; j < i; j++) { |
| 14758 |
ar = ath12k_ah_to_ar(ah, j); |
| 14759 |
ath12k_mac_cleanup_unregister(ar); |
| 14760 |
} |
| 14761 |
|
| 14762 |
SET_IEEE80211_DEV(hw, NULL); |
| 14763 |
|
| 14764 |
return ret; |
| 14765 |
} |
| 14766 |
|
| 14767 |
static void ath12k_mac_setup(struct ath12k *ar) |
| 14768 |
{ |
| 14769 |
struct ath12k_base *ab = ar->ab; |
| 14770 |
struct ath12k_pdev *pdev = ar->pdev; |
| 14771 |
u8 pdev_idx = ar->pdev_idx; |
| 14772 |
|
| 14773 |
ar->lmac_id = ath12k_hw_get_mac_from_pdev_id(ab->hw_params, pdev_idx); |
| 14774 |
|
| 14775 |
ar->wmi = &ab->wmi_ab.wmi[pdev_idx]; |
| 14776 |
/* FIXME: wmi[0] is already initialized during attach, |
| 14777 |
* Should we do this again? |
| 14778 |
*/ |
| 14779 |
ath12k_wmi_pdev_attach(ab, pdev_idx); |
| 14780 |
|
| 14781 |
ar->cfg_tx_chainmask = pdev->cap.tx_chain_mask; |
| 14782 |
ar->cfg_rx_chainmask = pdev->cap.rx_chain_mask; |
| 14783 |
ar->num_tx_chains = hweight32(pdev->cap.tx_chain_mask); |
| 14784 |
ar->num_rx_chains = hweight32(pdev->cap.rx_chain_mask); |
| 14785 |
ar->scan.arvif = NULL; |
| 14786 |
ar->vdev_id_11d_scan = ATH12K_11D_INVALID_VDEV_ID; |
| 14787 |
|
| 14788 |
spin_lock_init(&ar->data_lock); |
| 14789 |
spin_lock_init(&ar->dp.ppdu_list_lock); |
| 14790 |
INIT_LIST_HEAD(&ar->arvifs); |
| 14791 |
INIT_LIST_HEAD(&ar->dp.ppdu_stats_info); |
| 14792 |
|
| 14793 |
init_completion(&ar->vdev_setup_done); |
| 14794 |
init_completion(&ar->vdev_delete_done); |
| 14795 |
init_completion(&ar->peer_assoc_done); |
| 14796 |
init_completion(&ar->peer_delete_done); |
| 14797 |
init_completion(&ar->install_key_done); |
| 14798 |
init_completion(&ar->bss_survey_done); |
| 14799 |
init_completion(&ar->scan.started); |
| 14800 |
init_completion(&ar->scan.completed); |
| 14801 |
init_completion(&ar->scan.on_channel); |
| 14802 |
init_completion(&ar->mlo_setup_done); |
| 14803 |
init_completion(&ar->completed_11d_scan); |
| 14804 |
init_completion(&ar->regd_update_completed); |
| 14805 |
|
| 14806 |
INIT_DELAYED_WORK(&ar->scan.timeout, ath12k_scan_timeout_work); |
| 14807 |
wiphy_work_init(&ar->scan.vdev_clean_wk, ath12k_scan_vdev_clean_work); |
| 14808 |
INIT_WORK(&ar->regd_channel_update_work, ath12k_regd_update_chan_list_work); |
| 14809 |
INIT_LIST_HEAD(&ar->regd_channel_update_queue); |
| 14810 |
INIT_WORK(&ar->regd_update_work, ath12k_regd_update_work); |
| 14811 |
|
| 14812 |
wiphy_work_init(&ar->wmi_mgmt_tx_work, ath12k_mgmt_over_wmi_tx_work); |
| 14813 |
skb_queue_head_init(&ar->wmi_mgmt_tx_queue); |
| 14814 |
|
| 14815 |
ar->monitor_vdev_id = -1; |
| 14816 |
ar->monitor_vdev_created = false; |
| 14817 |
ar->monitor_started = false; |
| 14818 |
} |
| 14819 |
|
| 14820 |
static int __ath12k_mac_mlo_setup(struct ath12k *ar) |
| 14821 |
{ |
| 14822 |
u8 num_link = 0, partner_link_id[ATH12K_GROUP_MAX_RADIO] = {}; |
| 14823 |
struct ath12k_base *partner_ab, *ab = ar->ab; |
| 14824 |
struct ath12k_hw_group *ag = ab->ag; |
| 14825 |
struct wmi_mlo_setup_arg mlo = {}; |
| 14826 |
struct ath12k_pdev *pdev; |
| 14827 |
unsigned long time_left; |
| 14828 |
int i, j, ret; |
| 14829 |
|
| 14830 |
lockdep_assert_held(&ag->mutex); |
| 14831 |
|
| 14832 |
reinit_completion(&ar->mlo_setup_done); |
| 14833 |
|
| 14834 |
for (i = 0; i < ag->num_devices; i++) { |
| 14835 |
partner_ab = ag->ab[i]; |
| 14836 |
|
| 14837 |
for (j = 0; j < partner_ab->num_radios; j++) { |
| 14838 |
pdev = &partner_ab->pdevs[j]; |
| 14839 |
|
| 14840 |
/* Avoid the self link */ |
| 14841 |
if (ar == pdev->ar) |
| 14842 |
continue; |
| 14843 |
|
| 14844 |
partner_link_id[num_link] = pdev->hw_link_id; |
| 14845 |
num_link++; |
| 14846 |
|
| 14847 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "device %d pdev %d hw_link_id %d num_link %d\n", |
| 14848 |
i, j, pdev->hw_link_id, num_link); |
| 14849 |
} |
| 14850 |
} |
| 14851 |
|
| 14852 |
if (num_link == 0) |
| 14853 |
return 0; |
| 14854 |
|
| 14855 |
mlo.group_id = cpu_to_le32(ag->id); |
| 14856 |
mlo.partner_link_id = partner_link_id; |
| 14857 |
mlo.num_partner_links = num_link; |
| 14858 |
ar->mlo_setup_status = 0; |
| 14859 |
|
| 14860 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "group id %d num_link %d\n", ag->id, num_link); |
| 14861 |
|
| 14862 |
ret = ath12k_wmi_mlo_setup(ar, &mlo); |
| 14863 |
if (ret) { |
| 14864 |
ath12k_err(ab, "failed to send setup MLO WMI command for pdev %d: %d\n", |
| 14865 |
ar->pdev_idx, ret); |
| 14866 |
return ret; |
| 14867 |
} |
| 14868 |
|
| 14869 |
time_left = wait_for_completion_timeout(&ar->mlo_setup_done, |
| 14870 |
WMI_MLO_CMD_TIMEOUT_HZ); |
| 14871 |
|
| 14872 |
if (!time_left || ar->mlo_setup_status) |
| 14873 |
return ar->mlo_setup_status ? : -ETIMEDOUT; |
| 14874 |
|
| 14875 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "mlo setup done for pdev %d\n", ar->pdev_idx); |
| 14876 |
|
| 14877 |
return 0; |
| 14878 |
} |
| 14879 |
|
| 14880 |
static int __ath12k_mac_mlo_teardown(struct ath12k *ar) |
| 14881 |
{ |
| 14882 |
struct ath12k_base *ab = ar->ab; |
| 14883 |
int ret; |
| 14884 |
u8 num_link; |
| 14885 |
|
| 14886 |
if (test_bit(ATH12K_FLAG_RECOVERY, &ab->dev_flags)) |
| 14887 |
return 0; |
| 14888 |
|
| 14889 |
num_link = ath12k_get_num_partner_link(ar); |
| 14890 |
|
| 14891 |
if (num_link == 0) |
| 14892 |
return 0; |
| 14893 |
|
| 14894 |
ret = ath12k_wmi_mlo_teardown(ar); |
| 14895 |
if (ret) { |
| 14896 |
ath12k_warn(ab, "failed to send MLO teardown WMI command for pdev %d: %d\n", |
| 14897 |
ar->pdev_idx, ret); |
| 14898 |
return ret; |
| 14899 |
} |
| 14900 |
|
| 14901 |
ath12k_dbg(ab, ATH12K_DBG_MAC, "mlo teardown for pdev %d\n", ar->pdev_idx); |
| 14902 |
|
| 14903 |
return 0; |
| 14904 |
} |
| 14905 |
|
| 14906 |
int ath12k_mac_mlo_setup(struct ath12k_hw_group *ag) |
| 14907 |
{ |
| 14908 |
struct ath12k_hw *ah; |
| 14909 |
struct ath12k *ar; |
| 14910 |
int ret; |
| 14911 |
int i, j; |
| 14912 |
|
| 14913 |
for (i = 0; i < ag->num_hw; i++) { |
| 14914 |
ah = ag->ah[i]; |
| 14915 |
if (!ah) |
| 14916 |
continue; |
| 14917 |
|
| 14918 |
for_each_ar(ah, ar, j) { |
| 14919 |
ar = &ah->radio[j]; |
| 14920 |
ret = __ath12k_mac_mlo_setup(ar); |
| 14921 |
if (ret) { |
| 14922 |
ath12k_err(ar->ab, "failed to setup MLO: %d\n", ret); |
| 14923 |
goto err_setup; |
| 14924 |
} |
| 14925 |
} |
| 14926 |
} |
| 14927 |
|
| 14928 |
return 0; |
| 14929 |
|
| 14930 |
err_setup: |
| 14931 |
for (i = i - 1; i >= 0; i--) { |
| 14932 |
ah = ag->ah[i]; |
| 14933 |
if (!ah) |
| 14934 |
continue; |
| 14935 |
|
| 14936 |
for (j = j - 1; j >= 0; j--) { |
| 14937 |
ar = &ah->radio[j]; |
| 14938 |
if (!ar) |
| 14939 |
continue; |
| 14940 |
|
| 14941 |
__ath12k_mac_mlo_teardown(ar); |
| 14942 |
} |
| 14943 |
} |
| 14944 |
|
| 14945 |
return ret; |
| 14946 |
} |
| 14947 |
|
| 14948 |
void ath12k_mac_mlo_teardown(struct ath12k_hw_group *ag) |
| 14949 |
{ |
| 14950 |
struct ath12k_hw *ah; |
| 14951 |
struct ath12k *ar; |
| 14952 |
int ret, i, j; |
| 14953 |
|
| 14954 |
for (i = 0; i < ag->num_hw; i++) { |
| 14955 |
ah = ag->ah[i]; |
| 14956 |
if (!ah) |
| 14957 |
continue; |
| 14958 |
|
| 14959 |
for_each_ar(ah, ar, j) { |
| 14960 |
ar = &ah->radio[j]; |
| 14961 |
ret = __ath12k_mac_mlo_teardown(ar); |
| 14962 |
if (ret) { |
| 14963 |
ath12k_err(ar->ab, "failed to teardown MLO: %d\n", ret); |
| 14964 |
break; |
| 14965 |
} |
| 14966 |
} |
| 14967 |
} |
| 14968 |
} |
| 14969 |
|
| 14970 |
int ath12k_mac_register(struct ath12k_hw_group *ag) |
| 14971 |
{ |
| 14972 |
struct ath12k_hw *ah; |
| 14973 |
int i; |
| 14974 |
int ret; |
| 14975 |
|
| 14976 |
for (i = 0; i < ag->num_hw; i++) { |
| 14977 |
ah = ath12k_ag_to_ah(ag, i); |
| 14978 |
|
| 14979 |
ret = ath12k_mac_hw_register(ah); |
| 14980 |
if (ret) |
| 14981 |
goto err; |
| 14982 |
} |
| 14983 |
|
| 14984 |
return 0; |
| 14985 |
|
| 14986 |
err: |
| 14987 |
for (i = i - 1; i >= 0; i--) { |
| 14988 |
ah = ath12k_ag_to_ah(ag, i); |
| 14989 |
if (!ah) |
| 14990 |
continue; |
| 14991 |
|
| 14992 |
ath12k_mac_hw_unregister(ah); |
| 14993 |
} |
| 14994 |
|
| 14995 |
return ret; |
| 14996 |
} |
| 14997 |
|
| 14998 |
void ath12k_mac_unregister(struct ath12k_hw_group *ag) |
| 14999 |
{ |
| 15000 |
struct ath12k_hw *ah; |
| 15001 |
int i; |
| 15002 |
|
| 15003 |
for (i = ag->num_hw - 1; i >= 0; i--) { |
| 15004 |
ah = ath12k_ag_to_ah(ag, i); |
| 15005 |
if (!ah) |
| 15006 |
continue; |
| 15007 |
|
| 15008 |
ath12k_mac_hw_unregister(ah); |
| 15009 |
} |
| 15010 |
} |
| 15011 |
|
| 15012 |
static void ath12k_mac_hw_destroy(struct ath12k_hw *ah) |
| 15013 |
{ |
| 15014 |
ieee80211_free_hw(ah->hw); |
| 15015 |
} |
| 15016 |
|
| 15017 |
static struct ath12k_hw *ath12k_mac_hw_allocate(struct ath12k_hw_group *ag, |
| 15018 |
struct ath12k_pdev_map *pdev_map, |
| 15019 |
u8 num_pdev_map) |
| 15020 |
{ |
| 15021 |
struct ieee80211_hw *hw; |
| 15022 |
struct ath12k *ar; |
| 15023 |
struct ath12k_base *ab; |
| 15024 |
struct ath12k_pdev *pdev; |
| 15025 |
struct ath12k_hw *ah; |
| 15026 |
int i; |
| 15027 |
u8 pdev_idx; |
| 15028 |
|
| 15029 |
hw = ieee80211_alloc_hw(struct_size(ah, radio, num_pdev_map), |
| 15030 |
pdev_map->ab->ath12k_ops); |
| 15031 |
if (!hw) |
| 15032 |
return NULL; |
| 15033 |
|
| 15034 |
ah = ath12k_hw_to_ah(hw); |
| 15035 |
ah->hw = hw; |
| 15036 |
ah->num_radio = num_pdev_map; |
| 15037 |
|
| 15038 |
mutex_init(&ah->hw_mutex); |
| 15039 |
|
| 15040 |
spin_lock_init(&ah->dp_hw.peer_lock); |
| 15041 |
INIT_LIST_HEAD(&ah->dp_hw.dp_peers_list); |
| 15042 |
|
| 15043 |
for (i = 0; i < num_pdev_map; i++) { |
| 15044 |
ab = pdev_map[i].ab; |
| 15045 |
pdev_idx = pdev_map[i].pdev_idx; |
| 15046 |
pdev = &ab->pdevs[pdev_idx]; |
| 15047 |
|
| 15048 |
ar = ath12k_ah_to_ar(ah, i); |
| 15049 |
ar->ah = ah; |
| 15050 |
ar->ab = ab; |
| 15051 |
ar->hw_link_id = pdev->hw_link_id; |
| 15052 |
ar->pdev = pdev; |
| 15053 |
ar->pdev_idx = pdev_idx; |
| 15054 |
pdev->ar = ar; |
| 15055 |
|
| 15056 |
ag->hw_links[ar->hw_link_id].device_id = ab->device_id; |
| 15057 |
ag->hw_links[ar->hw_link_id].pdev_idx = pdev_idx; |
| 15058 |
|
| 15059 |
ath12k_mac_setup(ar); |
| 15060 |
ath12k_dp_pdev_pre_alloc(ar); |
| 15061 |
} |
| 15062 |
|
| 15063 |
return ah; |
| 15064 |
} |
| 15065 |
|
| 15066 |
void ath12k_mac_destroy(struct ath12k_hw_group *ag) |
| 15067 |
{ |
| 15068 |
struct ath12k_pdev *pdev; |
| 15069 |
struct ath12k_base *ab = ag->ab[0]; |
| 15070 |
int i, j; |
| 15071 |
struct ath12k_hw *ah; |
| 15072 |
|
| 15073 |
for (i = 0; i < ag->num_devices; i++) { |
| 15074 |
ab = ag->ab[i]; |
| 15075 |
if (!ab) |
| 15076 |
continue; |
| 15077 |
|
| 15078 |
for (j = 0; j < ab->num_radios; j++) { |
| 15079 |
pdev = &ab->pdevs[j]; |
| 15080 |
if (!pdev->ar) |
| 15081 |
continue; |
| 15082 |
pdev->ar = NULL; |
| 15083 |
} |
| 15084 |
} |
| 15085 |
|
| 15086 |
for (i = 0; i < ag->num_hw; i++) { |
| 15087 |
ah = ath12k_ag_to_ah(ag, i); |
| 15088 |
if (!ah) |
| 15089 |
continue; |
| 15090 |
|
| 15091 |
ath12k_mac_hw_destroy(ah); |
| 15092 |
ath12k_ag_set_ah(ag, i, NULL); |
| 15093 |
} |
| 15094 |
} |
| 15095 |
|
| 15096 |
static void ath12k_mac_set_device_defaults(struct ath12k_base *ab) |
| 15097 |
{ |
| 15098 |
int total_vdev; |
| 15099 |
|
| 15100 |
/* Initialize channel counters frequency value in hertz */ |
| 15101 |
ab->cc_freq_hz = 320000; |
| 15102 |
total_vdev = ab->num_radios * TARGET_NUM_VDEVS(ab); |
| 15103 |
ab->free_vdev_map = (1LL << total_vdev) - 1; |
| 15104 |
} |
| 15105 |
|
| 15106 |
int ath12k_mac_allocate(struct ath12k_hw_group *ag) |
| 15107 |
{ |
| 15108 |
struct ath12k_pdev_map pdev_map[ATH12K_GROUP_MAX_RADIO]; |
| 15109 |
int mac_id, device_id, total_radio, num_hw; |
| 15110 |
struct ath12k_base *ab; |
| 15111 |
struct ath12k_hw *ah; |
| 15112 |
int ret, i, j; |
| 15113 |
u8 radio_per_hw; |
| 15114 |
|
| 15115 |
total_radio = 0; |
| 15116 |
for (i = 0; i < ag->num_devices; i++) { |
| 15117 |
ab = ag->ab[i]; |
| 15118 |
if (!ab) |
| 15119 |
continue; |
| 15120 |
|
| 15121 |
ath12k_debugfs_pdev_create(ab); |
| 15122 |
ath12k_mac_set_device_defaults(ab); |
| 15123 |
total_radio += ab->num_radios; |
| 15124 |
} |
| 15125 |
|
| 15126 |
if (!total_radio) |
| 15127 |
return -EINVAL; |
| 15128 |
|
| 15129 |
if (WARN_ON(total_radio > ATH12K_GROUP_MAX_RADIO)) |
| 15130 |
return -ENOSPC; |
| 15131 |
|
| 15132 |
/* All pdev get combined and register as single wiphy based on |
| 15133 |
* hardware group which participate in multi-link operation else |
| 15134 |
* each pdev get register separately. |
| 15135 |
*/ |
| 15136 |
if (ag->mlo_capable) |
| 15137 |
radio_per_hw = total_radio; |
| 15138 |
else |
| 15139 |
radio_per_hw = 1; |
| 15140 |
|
| 15141 |
num_hw = total_radio / radio_per_hw; |
| 15142 |
|
| 15143 |
ag->num_hw = 0; |
| 15144 |
device_id = 0; |
| 15145 |
mac_id = 0; |
| 15146 |
for (i = 0; i < num_hw; i++) { |
| 15147 |
for (j = 0; j < radio_per_hw; j++) { |
| 15148 |
if (device_id >= ag->num_devices || !ag->ab[device_id]) { |
| 15149 |
ret = -ENOSPC; |
| 15150 |
goto err; |
| 15151 |
} |
| 15152 |
|
| 15153 |
ab = ag->ab[device_id]; |
| 15154 |
pdev_map[j].ab = ab; |
| 15155 |
pdev_map[j].pdev_idx = mac_id; |
| 15156 |
mac_id++; |
| 15157 |
|
| 15158 |
/* If mac_id falls beyond the current device MACs then |
| 15159 |
* move to next device |
| 15160 |
*/ |
| 15161 |
if (mac_id >= ab->num_radios) { |
| 15162 |
mac_id = 0; |
| 15163 |
device_id++; |
| 15164 |
} |
| 15165 |
} |
| 15166 |
|
| 15167 |
ab = pdev_map->ab; |
| 15168 |
|
| 15169 |
ah = ath12k_mac_hw_allocate(ag, pdev_map, radio_per_hw); |
| 15170 |
if (!ah) { |
| 15171 |
ath12k_warn(ab, "failed to allocate mac80211 hw device for hw_idx %d\n", |
| 15172 |
i); |
| 15173 |
ret = -ENOMEM; |
| 15174 |
goto err; |
| 15175 |
} |
| 15176 |
|
| 15177 |
ah->dev = ab->dev; |
| 15178 |
|
| 15179 |
ag->ah[i] = ah; |
| 15180 |
ag->num_hw++; |
| 15181 |
} |
| 15182 |
|
| 15183 |
return 0; |
| 15184 |
|
| 15185 |
err: |
| 15186 |
for (i = i - 1; i >= 0; i--) { |
| 15187 |
ah = ath12k_ag_to_ah(ag, i); |
| 15188 |
if (!ah) |
| 15189 |
continue; |
| 15190 |
|
| 15191 |
ath12k_mac_hw_destroy(ah); |
| 15192 |
ath12k_ag_set_ah(ag, i, NULL); |
| 15193 |
} |
| 15194 |
|
| 15195 |
return ret; |
| 15196 |
} |
| 15197 |
|
| 15198 |
int ath12k_mac_vif_set_keepalive(struct ath12k_link_vif *arvif, |
| 15199 |
enum wmi_sta_keepalive_method method, |
| 15200 |
u32 interval) |
| 15201 |
{ |
| 15202 |
struct wmi_sta_keepalive_arg arg = {}; |
| 15203 |
struct ath12k *ar = arvif->ar; |
| 15204 |
int ret; |
| 15205 |
|
| 15206 |
lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
| 15207 |
|
| 15208 |
if (arvif->ahvif->vdev_type != WMI_VDEV_TYPE_STA) |
| 15209 |
return 0; |
| 15210 |
|
| 15211 |
if (!test_bit(WMI_TLV_SERVICE_STA_KEEP_ALIVE, ar->ab->wmi_ab.svc_map)) |
| 15212 |
return 0; |
| 15213 |
|
| 15214 |
arg.vdev_id = arvif->vdev_id; |
| 15215 |
arg.enabled = 1; |
| 15216 |
arg.method = method; |
| 15217 |
arg.interval = interval; |
| 15218 |
|
| 15219 |
ret = ath12k_wmi_sta_keepalive(ar, &arg); |
| 15220 |
if (ret) { |
| 15221 |
ath12k_warn(ar->ab, "failed to set keepalive on vdev %i: %d\n", |
| 15222 |
arvif->vdev_id, ret); |
| 15223 |
return ret; |
| 15224 |
} |
| 15225 |
|
| 15226 |
return 0; |
| 15227 |
} |