1 // SPDX-License-Identifier: BSD-3-Clause-Clear 2 /* 3 * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. 4 * Copyright (c) 2021-2025 Qualcomm Innovation Center, Inc. All rights reserved. 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 25 #define CHAN2G(_channel, _freq, _flags) { \ 26 .band = NL80211_BAND_2GHZ, \ 27 .hw_value = (_channel), \ 28 .center_freq = (_freq), \ 29 .flags = (_flags), \ 30 .max_antenna_gain = 0, \ 31 .max_power = 30, \ 32 } 33 34 #define CHAN5G(_channel, _freq, _flags) { \ 35 .band = NL80211_BAND_5GHZ, \ 36 .hw_value = (_channel), \ 37 .center_freq = (_freq), \ 38 .flags = (_flags), \ 39 .max_antenna_gain = 0, \ 40 .max_power = 30, \ 41 } 42 43 #define CHAN6G(_channel, _freq, _flags) { \ 44 .band = NL80211_BAND_6GHZ, \ 45 .hw_value = (_channel), \ 46 .center_freq = (_freq), \ 47 .flags = (_flags), \ 48 .max_antenna_gain = 0, \ 49 .max_power = 30, \ 50 } 51 52 static const struct ieee80211_channel ath12k_2ghz_channels[] = { 53 CHAN2G(1, 2412, 0), 54 CHAN2G(2, 2417, 0), 55 CHAN2G(3, 2422, 0), 56 CHAN2G(4, 2427, 0), 57 CHAN2G(5, 2432, 0), 58 CHAN2G(6, 2437, 0), 59 CHAN2G(7, 2442, 0), 60 CHAN2G(8, 2447, 0), 61 CHAN2G(9, 2452, 0), 62 CHAN2G(10, 2457, 0), 63 CHAN2G(11, 2462, 0), 64 CHAN2G(12, 2467, 0), 65 CHAN2G(13, 2472, 0), 66 CHAN2G(14, 2484, 0), 67 }; 68 69 static const struct ieee80211_channel ath12k_5ghz_channels[] = { 70 CHAN5G(36, 5180, 0), 71 CHAN5G(40, 5200, 0), 72 CHAN5G(44, 5220, 0), 73 CHAN5G(48, 5240, 0), 74 CHAN5G(52, 5260, 0), 75 CHAN5G(56, 5280, 0), 76 CHAN5G(60, 5300, 0), 77 CHAN5G(64, 5320, 0), 78 CHAN5G(100, 5500, 0), 79 CHAN5G(104, 5520, 0), 80 CHAN5G(108, 5540, 0), 81 CHAN5G(112, 5560, 0), 82 CHAN5G(116, 5580, 0), 83 CHAN5G(120, 5600, 0), 84 CHAN5G(124, 5620, 0), 85 CHAN5G(128, 5640, 0), 86 CHAN5G(132, 5660, 0), 87 CHAN5G(136, 5680, 0), 88 CHAN5G(140, 5700, 0), 89 CHAN5G(144, 5720, 0), 90 CHAN5G(149, 5745, 0), 91 CHAN5G(153, 5765, 0), 92 CHAN5G(157, 5785, 0), 93 CHAN5G(161, 5805, 0), 94 CHAN5G(165, 5825, 0), 95 CHAN5G(169, 5845, 0), 96 CHAN5G(173, 5865, 0), 97 }; 98 99 static const struct ieee80211_channel ath12k_6ghz_channels[] = { 100 /* Operating Class 136 */ 101 CHAN6G(2, 5935, 0), 102 103 /* Operating Classes 131-135 */ 104 CHAN6G(1, 5955, 0), 105 CHAN6G(5, 5975, 0), 106 CHAN6G(9, 5995, 0), 107 CHAN6G(13, 6015, 0), 108 CHAN6G(17, 6035, 0), 109 CHAN6G(21, 6055, 0), 110 CHAN6G(25, 6075, 0), 111 CHAN6G(29, 6095, 0), 112 CHAN6G(33, 6115, 0), 113 CHAN6G(37, 6135, 0), 114 CHAN6G(41, 6155, 0), 115 CHAN6G(45, 6175, 0), 116 CHAN6G(49, 6195, 0), 117 CHAN6G(53, 6215, 0), 118 CHAN6G(57, 6235, 0), 119 CHAN6G(61, 6255, 0), 120 CHAN6G(65, 6275, 0), 121 CHAN6G(69, 6295, 0), 122 CHAN6G(73, 6315, 0), 123 CHAN6G(77, 6335, 0), 124 CHAN6G(81, 6355, 0), 125 CHAN6G(85, 6375, 0), 126 CHAN6G(89, 6395, 0), 127 CHAN6G(93, 6415, 0), 128 CHAN6G(97, 6435, 0), 129 CHAN6G(101, 6455, 0), 130 CHAN6G(105, 6475, 0), 131 CHAN6G(109, 6495, 0), 132 CHAN6G(113, 6515, 0), 133 CHAN6G(117, 6535, 0), 134 CHAN6G(121, 6555, 0), 135 CHAN6G(125, 6575, 0), 136 CHAN6G(129, 6595, 0), 137 CHAN6G(133, 6615, 0), 138 CHAN6G(137, 6635, 0), 139 CHAN6G(141, 6655, 0), 140 CHAN6G(145, 6675, 0), 141 CHAN6G(149, 6695, 0), 142 CHAN6G(153, 6715, 0), 143 CHAN6G(157, 6735, 0), 144 CHAN6G(161, 6755, 0), 145 CHAN6G(165, 6775, 0), 146 CHAN6G(169, 6795, 0), 147 CHAN6G(173, 6815, 0), 148 CHAN6G(177, 6835, 0), 149 CHAN6G(181, 6855, 0), 150 CHAN6G(185, 6875, 0), 151 CHAN6G(189, 6895, 0), 152 CHAN6G(193, 6915, 0), 153 CHAN6G(197, 6935, 0), 154 CHAN6G(201, 6955, 0), 155 CHAN6G(205, 6975, 0), 156 CHAN6G(209, 6995, 0), 157 CHAN6G(213, 7015, 0), 158 CHAN6G(217, 7035, 0), 159 CHAN6G(221, 7055, 0), 160 CHAN6G(225, 7075, 0), 161 CHAN6G(229, 7095, 0), 162 CHAN6G(233, 7115, 0), 163 }; 164 165 static struct ieee80211_rate ath12k_legacy_rates[] = { 166 { .bitrate = 10, 167 .hw_value = ATH12K_HW_RATE_CCK_LP_1M }, 168 { .bitrate = 20, 169 .hw_value = ATH12K_HW_RATE_CCK_LP_2M, 170 .hw_value_short = ATH12K_HW_RATE_CCK_SP_2M, 171 .flags = IEEE80211_RATE_SHORT_PREAMBLE }, 172 { .bitrate = 55, 173 .hw_value = ATH12K_HW_RATE_CCK_LP_5_5M, 174 .hw_value_short = ATH12K_HW_RATE_CCK_SP_5_5M, 175 .flags = IEEE80211_RATE_SHORT_PREAMBLE }, 176 { .bitrate = 110, 177 .hw_value = ATH12K_HW_RATE_CCK_LP_11M, 178 .hw_value_short = ATH12K_HW_RATE_CCK_SP_11M, 179 .flags = IEEE80211_RATE_SHORT_PREAMBLE }, 180 181 { .bitrate = 60, .hw_value = ATH12K_HW_RATE_OFDM_6M }, 182 { .bitrate = 90, .hw_value = ATH12K_HW_RATE_OFDM_9M }, 183 { .bitrate = 120, .hw_value = ATH12K_HW_RATE_OFDM_12M }, 184 { .bitrate = 180, .hw_value = ATH12K_HW_RATE_OFDM_18M }, 185 { .bitrate = 240, .hw_value = ATH12K_HW_RATE_OFDM_24M }, 186 { .bitrate = 360, .hw_value = ATH12K_HW_RATE_OFDM_36M }, 187 { .bitrate = 480, .hw_value = ATH12K_HW_RATE_OFDM_48M }, 188 { .bitrate = 540, .hw_value = ATH12K_HW_RATE_OFDM_54M }, 189 }; 190 191 static const int 192 ath12k_phymodes[NUM_NL80211_BANDS][ATH12K_CHAN_WIDTH_NUM] = { 193 [NL80211_BAND_2GHZ] = { 194 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, 195 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, 196 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11BE_EHT20_2G, 197 [NL80211_CHAN_WIDTH_20] = MODE_11BE_EHT20_2G, 198 [NL80211_CHAN_WIDTH_40] = MODE_11BE_EHT40_2G, 199 [NL80211_CHAN_WIDTH_80] = MODE_UNKNOWN, 200 [NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN, 201 [NL80211_CHAN_WIDTH_160] = MODE_UNKNOWN, 202 [NL80211_CHAN_WIDTH_320] = MODE_UNKNOWN, 203 }, 204 [NL80211_BAND_5GHZ] = { 205 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, 206 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, 207 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11BE_EHT20, 208 [NL80211_CHAN_WIDTH_20] = MODE_11BE_EHT20, 209 [NL80211_CHAN_WIDTH_40] = MODE_11BE_EHT40, 210 [NL80211_CHAN_WIDTH_80] = MODE_11BE_EHT80, 211 [NL80211_CHAN_WIDTH_160] = MODE_11BE_EHT160, 212 [NL80211_CHAN_WIDTH_80P80] = MODE_11BE_EHT80_80, 213 [NL80211_CHAN_WIDTH_320] = MODE_11BE_EHT320, 214 }, 215 [NL80211_BAND_6GHZ] = { 216 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, 217 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, 218 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11BE_EHT20, 219 [NL80211_CHAN_WIDTH_20] = MODE_11BE_EHT20, 220 [NL80211_CHAN_WIDTH_40] = MODE_11BE_EHT40, 221 [NL80211_CHAN_WIDTH_80] = MODE_11BE_EHT80, 222 [NL80211_CHAN_WIDTH_160] = MODE_11BE_EHT160, 223 [NL80211_CHAN_WIDTH_80P80] = MODE_11BE_EHT80_80, 224 [NL80211_CHAN_WIDTH_320] = MODE_11BE_EHT320, 225 }, 226 227 }; 228 229 const struct htt_rx_ring_tlv_filter ath12k_mac_mon_status_filter_default = { 230 .rx_filter = HTT_RX_FILTER_TLV_FLAGS_MPDU_START | 231 HTT_RX_FILTER_TLV_FLAGS_PPDU_END | 232 HTT_RX_FILTER_TLV_FLAGS_PPDU_END_STATUS_DONE | 233 HTT_RX_FILTER_TLV_FLAGS_PPDU_START_USER_INFO, 234 .pkt_filter_flags0 = HTT_RX_FP_MGMT_FILTER_FLAGS0, 235 .pkt_filter_flags1 = HTT_RX_FP_MGMT_FILTER_FLAGS1, 236 .pkt_filter_flags2 = HTT_RX_FP_CTRL_FILTER_FLASG2, 237 .pkt_filter_flags3 = HTT_RX_FP_DATA_FILTER_FLASG3 | 238 HTT_RX_FP_CTRL_FILTER_FLASG3 239 }; 240 241 #define ATH12K_MAC_FIRST_OFDM_RATE_IDX 4 242 #define ath12k_g_rates ath12k_legacy_rates 243 #define ath12k_g_rates_size (ARRAY_SIZE(ath12k_legacy_rates)) 244 #define ath12k_a_rates (ath12k_legacy_rates + 4) 245 #define ath12k_a_rates_size (ARRAY_SIZE(ath12k_legacy_rates) - 4) 246 247 #define ATH12K_MAC_SCAN_TIMEOUT_MSECS 200 /* in msecs */ 248 249 static const u32 ath12k_smps_map[] = { 250 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC, 251 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC, 252 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE, 253 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE, 254 }; 255 256 static int ath12k_start_vdev_delay(struct ath12k *ar, 257 struct ath12k_link_vif *arvif); 258 static void ath12k_mac_stop(struct ath12k *ar); 259 static int ath12k_mac_vdev_create(struct ath12k *ar, struct ath12k_link_vif *arvif); 260 static int ath12k_mac_vdev_delete(struct ath12k *ar, struct ath12k_link_vif *arvif); 261 262 static const char *ath12k_mac_phymode_str(enum wmi_phy_mode mode) 263 { 264 switch (mode) { 265 case MODE_11A: 266 return "11a"; 267 case MODE_11G: 268 return "11g"; 269 case MODE_11B: 270 return "11b"; 271 case MODE_11GONLY: 272 return "11gonly"; 273 case MODE_11NA_HT20: 274 return "11na-ht20"; 275 case MODE_11NG_HT20: 276 return "11ng-ht20"; 277 case MODE_11NA_HT40: 278 return "11na-ht40"; 279 case MODE_11NG_HT40: 280 return "11ng-ht40"; 281 case MODE_11AC_VHT20: 282 return "11ac-vht20"; 283 case MODE_11AC_VHT40: 284 return "11ac-vht40"; 285 case MODE_11AC_VHT80: 286 return "11ac-vht80"; 287 case MODE_11AC_VHT160: 288 return "11ac-vht160"; 289 case MODE_11AC_VHT80_80: 290 return "11ac-vht80+80"; 291 case MODE_11AC_VHT20_2G: 292 return "11ac-vht20-2g"; 293 case MODE_11AC_VHT40_2G: 294 return "11ac-vht40-2g"; 295 case MODE_11AC_VHT80_2G: 296 return "11ac-vht80-2g"; 297 case MODE_11AX_HE20: 298 return "11ax-he20"; 299 case MODE_11AX_HE40: 300 return "11ax-he40"; 301 case MODE_11AX_HE80: 302 return "11ax-he80"; 303 case MODE_11AX_HE80_80: 304 return "11ax-he80+80"; 305 case MODE_11AX_HE160: 306 return "11ax-he160"; 307 case MODE_11AX_HE20_2G: 308 return "11ax-he20-2g"; 309 case MODE_11AX_HE40_2G: 310 return "11ax-he40-2g"; 311 case MODE_11AX_HE80_2G: 312 return "11ax-he80-2g"; 313 case MODE_11BE_EHT20: 314 return "11be-eht20"; 315 case MODE_11BE_EHT40: 316 return "11be-eht40"; 317 case MODE_11BE_EHT80: 318 return "11be-eht80"; 319 case MODE_11BE_EHT80_80: 320 return "11be-eht80+80"; 321 case MODE_11BE_EHT160: 322 return "11be-eht160"; 323 case MODE_11BE_EHT160_160: 324 return "11be-eht160+160"; 325 case MODE_11BE_EHT320: 326 return "11be-eht320"; 327 case MODE_11BE_EHT20_2G: 328 return "11be-eht20-2g"; 329 case MODE_11BE_EHT40_2G: 330 return "11be-eht40-2g"; 331 case MODE_UNKNOWN: 332 /* skip */ 333 break; 334 335 /* no default handler to allow compiler to check that the 336 * enum is fully handled 337 */ 338 } 339 340 return "<unknown>"; 341 } 342 343 u16 ath12k_mac_he_convert_tones_to_ru_tones(u16 tones) 344 { 345 switch (tones) { 346 case 26: 347 return RU_26; 348 case 52: 349 return RU_52; 350 case 106: 351 return RU_106; 352 case 242: 353 return RU_242; 354 case 484: 355 return RU_484; 356 case 996: 357 return RU_996; 358 case (996 * 2): 359 return RU_2X996; 360 default: 361 return RU_26; 362 } 363 } 364 365 enum nl80211_eht_gi ath12k_mac_eht_gi_to_nl80211_eht_gi(u8 sgi) 366 { 367 switch (sgi) { 368 case RX_MSDU_START_SGI_0_8_US: 369 return NL80211_RATE_INFO_EHT_GI_0_8; 370 case RX_MSDU_START_SGI_1_6_US: 371 return NL80211_RATE_INFO_EHT_GI_1_6; 372 case RX_MSDU_START_SGI_3_2_US: 373 return NL80211_RATE_INFO_EHT_GI_3_2; 374 default: 375 return NL80211_RATE_INFO_EHT_GI_0_8; 376 } 377 } 378 379 enum nl80211_eht_ru_alloc ath12k_mac_eht_ru_tones_to_nl80211_eht_ru_alloc(u16 ru_tones) 380 { 381 switch (ru_tones) { 382 case 26: 383 return NL80211_RATE_INFO_EHT_RU_ALLOC_26; 384 case 52: 385 return NL80211_RATE_INFO_EHT_RU_ALLOC_52; 386 case (52 + 26): 387 return NL80211_RATE_INFO_EHT_RU_ALLOC_52P26; 388 case 106: 389 return NL80211_RATE_INFO_EHT_RU_ALLOC_106; 390 case (106 + 26): 391 return NL80211_RATE_INFO_EHT_RU_ALLOC_106P26; 392 case 242: 393 return NL80211_RATE_INFO_EHT_RU_ALLOC_242; 394 case 484: 395 return NL80211_RATE_INFO_EHT_RU_ALLOC_484; 396 case (484 + 242): 397 return NL80211_RATE_INFO_EHT_RU_ALLOC_484P242; 398 case 996: 399 return NL80211_RATE_INFO_EHT_RU_ALLOC_996; 400 case (996 + 484): 401 return NL80211_RATE_INFO_EHT_RU_ALLOC_996P484; 402 case (996 + 484 + 242): 403 return NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242; 404 case (2 * 996): 405 return NL80211_RATE_INFO_EHT_RU_ALLOC_2x996; 406 case (2 * 996 + 484): 407 return NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484; 408 case (3 * 996): 409 return NL80211_RATE_INFO_EHT_RU_ALLOC_3x996; 410 case (3 * 996 + 484): 411 return NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484; 412 case (4 * 996): 413 return NL80211_RATE_INFO_EHT_RU_ALLOC_4x996; 414 default: 415 return NL80211_RATE_INFO_EHT_RU_ALLOC_26; 416 } 417 } 418 419 enum rate_info_bw 420 ath12k_mac_bw_to_mac80211_bw(enum ath12k_supported_bw bw) 421 { 422 u8 ret = RATE_INFO_BW_20; 423 424 switch (bw) { 425 case ATH12K_BW_20: 426 ret = RATE_INFO_BW_20; 427 break; 428 case ATH12K_BW_40: 429 ret = RATE_INFO_BW_40; 430 break; 431 case ATH12K_BW_80: 432 ret = RATE_INFO_BW_80; 433 break; 434 case ATH12K_BW_160: 435 ret = RATE_INFO_BW_160; 436 break; 437 case ATH12K_BW_320: 438 ret = RATE_INFO_BW_320; 439 break; 440 } 441 442 return ret; 443 } 444 445 enum ath12k_supported_bw ath12k_mac_mac80211_bw_to_ath12k_bw(enum rate_info_bw bw) 446 { 447 switch (bw) { 448 case RATE_INFO_BW_20: 449 return ATH12K_BW_20; 450 case RATE_INFO_BW_40: 451 return ATH12K_BW_40; 452 case RATE_INFO_BW_80: 453 return ATH12K_BW_80; 454 case RATE_INFO_BW_160: 455 return ATH12K_BW_160; 456 case RATE_INFO_BW_320: 457 return ATH12K_BW_320; 458 default: 459 return ATH12K_BW_20; 460 } 461 } 462 463 int ath12k_mac_hw_ratecode_to_legacy_rate(u8 hw_rc, u8 preamble, u8 *rateidx, 464 u16 *rate) 465 { 466 /* As default, it is OFDM rates */ 467 int i = ATH12K_MAC_FIRST_OFDM_RATE_IDX; 468 int max_rates_idx = ath12k_g_rates_size; 469 470 if (preamble == WMI_RATE_PREAMBLE_CCK) { 471 hw_rc &= ~ATH12K_HW_RATECODE_CCK_SHORT_PREAM_MASK; 472 i = 0; 473 max_rates_idx = ATH12K_MAC_FIRST_OFDM_RATE_IDX; 474 } 475 476 while (i < max_rates_idx) { 477 if (hw_rc == ath12k_legacy_rates[i].hw_value) { 478 *rateidx = i; 479 *rate = ath12k_legacy_rates[i].bitrate; 480 return 0; 481 } 482 i++; 483 } 484 485 return -EINVAL; 486 } 487 488 u8 ath12k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband, 489 u32 bitrate) 490 { 491 int i; 492 493 for (i = 0; i < sband->n_bitrates; i++) 494 if (sband->bitrates[i].bitrate == bitrate) 495 return i; 496 497 return 0; 498 } 499 500 static u32 501 ath12k_mac_max_ht_nss(const u8 *ht_mcs_mask) 502 { 503 int nss; 504 505 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--) 506 if (ht_mcs_mask[nss]) 507 return nss + 1; 508 509 return 1; 510 } 511 512 static u32 513 ath12k_mac_max_vht_nss(const u16 *vht_mcs_mask) 514 { 515 int nss; 516 517 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--) 518 if (vht_mcs_mask[nss]) 519 return nss + 1; 520 521 return 1; 522 } 523 524 static u8 ath12k_parse_mpdudensity(u8 mpdudensity) 525 { 526 /* From IEEE Std 802.11-2020 defined values for "Minimum MPDU Start Spacing": 527 * 0 for no restriction 528 * 1 for 1/4 us 529 * 2 for 1/2 us 530 * 3 for 1 us 531 * 4 for 2 us 532 * 5 for 4 us 533 * 6 for 8 us 534 * 7 for 16 us 535 */ 536 switch (mpdudensity) { 537 case 0: 538 return 0; 539 case 1: 540 case 2: 541 case 3: 542 /* Our lower layer calculations limit our precision to 543 * 1 microsecond 544 */ 545 return 1; 546 case 4: 547 return 2; 548 case 5: 549 return 4; 550 case 6: 551 return 8; 552 case 7: 553 return 16; 554 default: 555 return 0; 556 } 557 } 558 559 static int ath12k_mac_vif_link_chan(struct ieee80211_vif *vif, u8 link_id, 560 struct cfg80211_chan_def *def) 561 { 562 struct ieee80211_bss_conf *link_conf; 563 struct ieee80211_chanctx_conf *conf; 564 565 rcu_read_lock(); 566 link_conf = rcu_dereference(vif->link_conf[link_id]); 567 568 if (!link_conf) { 569 rcu_read_unlock(); 570 return -ENOLINK; 571 } 572 573 conf = rcu_dereference(link_conf->chanctx_conf); 574 if (!conf) { 575 rcu_read_unlock(); 576 return -ENOENT; 577 } 578 *def = conf->def; 579 rcu_read_unlock(); 580 581 return 0; 582 } 583 584 static struct ath12k_link_vif * 585 ath12k_mac_get_tx_arvif(struct ath12k_link_vif *arvif, 586 struct ieee80211_bss_conf *link_conf) 587 { 588 struct ieee80211_bss_conf *tx_bss_conf; 589 struct ath12k *ar = arvif->ar; 590 struct ath12k_vif *tx_ahvif; 591 592 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 593 594 tx_bss_conf = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, 595 link_conf->tx_bss_conf); 596 if (tx_bss_conf) { 597 tx_ahvif = ath12k_vif_to_ahvif(tx_bss_conf->vif); 598 return wiphy_dereference(tx_ahvif->ah->hw->wiphy, 599 tx_ahvif->link[tx_bss_conf->link_id]); 600 } 601 602 return NULL; 603 } 604 605 struct ieee80211_bss_conf * 606 ath12k_mac_get_link_bss_conf(struct ath12k_link_vif *arvif) 607 { 608 struct ieee80211_vif *vif = arvif->ahvif->vif; 609 struct ieee80211_bss_conf *link_conf; 610 struct ath12k *ar = arvif->ar; 611 612 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 613 614 if (arvif->link_id >= IEEE80211_MLD_MAX_NUM_LINKS) 615 return NULL; 616 617 link_conf = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, 618 vif->link_conf[arvif->link_id]); 619 620 return link_conf; 621 } 622 623 static struct ieee80211_link_sta *ath12k_mac_get_link_sta(struct ath12k_link_sta *arsta) 624 { 625 struct ath12k_sta *ahsta = arsta->ahsta; 626 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(ahsta); 627 struct ieee80211_link_sta *link_sta; 628 629 lockdep_assert_wiphy(ahsta->ahvif->ah->hw->wiphy); 630 631 if (arsta->link_id >= IEEE80211_MLD_MAX_NUM_LINKS) 632 return NULL; 633 634 link_sta = wiphy_dereference(ahsta->ahvif->ah->hw->wiphy, 635 sta->link[arsta->link_id]); 636 637 return link_sta; 638 } 639 640 static bool ath12k_mac_bitrate_is_cck(int bitrate) 641 { 642 switch (bitrate) { 643 case 10: 644 case 20: 645 case 55: 646 case 110: 647 return true; 648 } 649 650 return false; 651 } 652 653 u8 ath12k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband, 654 u8 hw_rate, bool cck) 655 { 656 const struct ieee80211_rate *rate; 657 int i; 658 659 for (i = 0; i < sband->n_bitrates; i++) { 660 rate = &sband->bitrates[i]; 661 662 if (ath12k_mac_bitrate_is_cck(rate->bitrate) != cck) 663 continue; 664 665 if (rate->hw_value == hw_rate) 666 return i; 667 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE && 668 rate->hw_value_short == hw_rate) 669 return i; 670 } 671 672 return 0; 673 } 674 675 static u8 ath12k_mac_bitrate_to_rate(int bitrate) 676 { 677 return DIV_ROUND_UP(bitrate, 5) | 678 (ath12k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0); 679 } 680 681 static void ath12k_get_arvif_iter(void *data, u8 *mac, 682 struct ieee80211_vif *vif) 683 { 684 struct ath12k_vif_iter *arvif_iter = data; 685 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 686 unsigned long links_map = ahvif->links_map; 687 struct ath12k_link_vif *arvif; 688 u8 link_id; 689 690 for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { 691 arvif = rcu_dereference(ahvif->link[link_id]); 692 693 if (WARN_ON(!arvif)) 694 continue; 695 696 if (arvif->vdev_id == arvif_iter->vdev_id && 697 arvif->ar == arvif_iter->ar) { 698 arvif_iter->arvif = arvif; 699 break; 700 } 701 } 702 } 703 704 struct ath12k_link_vif *ath12k_mac_get_arvif(struct ath12k *ar, u32 vdev_id) 705 { 706 struct ath12k_vif_iter arvif_iter = {}; 707 u32 flags; 708 709 /* To use the arvif returned, caller must have held rcu read lock. 710 */ 711 WARN_ON(!rcu_read_lock_any_held()); 712 arvif_iter.vdev_id = vdev_id; 713 arvif_iter.ar = ar; 714 715 flags = IEEE80211_IFACE_ITER_RESUME_ALL; 716 ieee80211_iterate_active_interfaces_atomic(ath12k_ar_to_hw(ar), 717 flags, 718 ath12k_get_arvif_iter, 719 &arvif_iter); 720 if (!arvif_iter.arvif) { 721 ath12k_warn(ar->ab, "No VIF found for vdev %d\n", vdev_id); 722 return NULL; 723 } 724 725 return arvif_iter.arvif; 726 } 727 728 struct ath12k_link_vif *ath12k_mac_get_arvif_by_vdev_id(struct ath12k_base *ab, 729 u32 vdev_id) 730 { 731 int i; 732 struct ath12k_pdev *pdev; 733 struct ath12k_link_vif *arvif; 734 735 for (i = 0; i < ab->num_radios; i++) { 736 pdev = rcu_dereference(ab->pdevs_active[i]); 737 if (pdev && pdev->ar && 738 (pdev->ar->allocated_vdev_map & (1LL << vdev_id))) { 739 arvif = ath12k_mac_get_arvif(pdev->ar, vdev_id); 740 if (arvif) 741 return arvif; 742 } 743 } 744 745 return NULL; 746 } 747 748 struct ath12k *ath12k_mac_get_ar_by_vdev_id(struct ath12k_base *ab, u32 vdev_id) 749 { 750 int i; 751 struct ath12k_pdev *pdev; 752 753 for (i = 0; i < ab->num_radios; i++) { 754 pdev = rcu_dereference(ab->pdevs_active[i]); 755 if (pdev && pdev->ar) { 756 if (pdev->ar->allocated_vdev_map & (1LL << vdev_id)) 757 return pdev->ar; 758 } 759 } 760 761 return NULL; 762 } 763 764 struct ath12k *ath12k_mac_get_ar_by_pdev_id(struct ath12k_base *ab, u32 pdev_id) 765 { 766 int i; 767 struct ath12k_pdev *pdev; 768 769 if (ab->hw_params->single_pdev_only) { 770 pdev = rcu_dereference(ab->pdevs_active[0]); 771 return pdev ? pdev->ar : NULL; 772 } 773 774 if (WARN_ON(pdev_id > ab->num_radios)) 775 return NULL; 776 777 for (i = 0; i < ab->num_radios; i++) { 778 if (ab->fw_mode == ATH12K_FIRMWARE_MODE_FTM) 779 pdev = &ab->pdevs[i]; 780 else 781 pdev = rcu_dereference(ab->pdevs_active[i]); 782 783 if (pdev && pdev->pdev_id == pdev_id) 784 return (pdev->ar ? pdev->ar : NULL); 785 } 786 787 return NULL; 788 } 789 790 static bool ath12k_mac_is_ml_arvif(struct ath12k_link_vif *arvif) 791 { 792 struct ath12k_vif *ahvif = arvif->ahvif; 793 794 lockdep_assert_wiphy(ahvif->ah->hw->wiphy); 795 796 if (ahvif->vif->valid_links & BIT(arvif->link_id)) 797 return true; 798 799 return false; 800 } 801 802 static struct ath12k *ath12k_mac_get_ar_by_chan(struct ieee80211_hw *hw, 803 struct ieee80211_channel *channel) 804 { 805 struct ath12k_hw *ah = hw->priv; 806 struct ath12k *ar; 807 int i; 808 809 ar = ah->radio; 810 811 if (ah->num_radio == 1) 812 return ar; 813 814 for_each_ar(ah, ar, i) { 815 if (channel->center_freq >= KHZ_TO_MHZ(ar->freq_range.start_freq) && 816 channel->center_freq <= KHZ_TO_MHZ(ar->freq_range.end_freq)) 817 return ar; 818 } 819 return NULL; 820 } 821 822 static struct ath12k *ath12k_get_ar_by_ctx(struct ieee80211_hw *hw, 823 struct ieee80211_chanctx_conf *ctx) 824 { 825 if (!ctx) 826 return NULL; 827 828 return ath12k_mac_get_ar_by_chan(hw, ctx->def.chan); 829 } 830 831 struct ath12k *ath12k_get_ar_by_vif(struct ieee80211_hw *hw, 832 struct ieee80211_vif *vif, 833 u8 link_id) 834 { 835 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 836 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 837 struct ath12k_link_vif *arvif; 838 839 lockdep_assert_wiphy(hw->wiphy); 840 841 /* If there is one pdev within ah, then we return 842 * ar directly. 843 */ 844 if (ah->num_radio == 1) 845 return ah->radio; 846 847 if (!(ahvif->links_map & BIT(link_id))) 848 return NULL; 849 850 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 851 if (arvif && arvif->is_created) 852 return arvif->ar; 853 854 return NULL; 855 } 856 857 void ath12k_mac_get_any_chanctx_conf_iter(struct ieee80211_hw *hw, 858 struct ieee80211_chanctx_conf *conf, 859 void *data) 860 { 861 struct ath12k_mac_get_any_chanctx_conf_arg *arg = data; 862 struct ath12k *ctx_ar = ath12k_get_ar_by_ctx(hw, conf); 863 864 if (ctx_ar == arg->ar) 865 arg->chanctx_conf = conf; 866 } 867 868 static struct ath12k_link_vif *ath12k_mac_get_vif_up(struct ath12k *ar) 869 { 870 struct ath12k_link_vif *arvif; 871 872 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 873 874 list_for_each_entry(arvif, &ar->arvifs, list) { 875 if (arvif->is_up) 876 return arvif; 877 } 878 879 return NULL; 880 } 881 882 static bool ath12k_mac_band_match(enum nl80211_band band1, enum WMI_HOST_WLAN_BAND band2) 883 { 884 switch (band1) { 885 case NL80211_BAND_2GHZ: 886 if (band2 & WMI_HOST_WLAN_2GHZ_CAP) 887 return true; 888 break; 889 case NL80211_BAND_5GHZ: 890 case NL80211_BAND_6GHZ: 891 if (band2 & WMI_HOST_WLAN_5GHZ_CAP) 892 return true; 893 break; 894 default: 895 return false; 896 } 897 898 return false; 899 } 900 901 static u8 ath12k_mac_get_target_pdev_id_from_vif(struct ath12k_link_vif *arvif) 902 { 903 struct ath12k *ar = arvif->ar; 904 struct ath12k_base *ab = ar->ab; 905 struct ieee80211_vif *vif = arvif->ahvif->vif; 906 struct cfg80211_chan_def def; 907 enum nl80211_band band; 908 u8 pdev_id = ab->fw_pdev[0].pdev_id; 909 int i; 910 911 if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) 912 return pdev_id; 913 914 band = def.chan->band; 915 916 for (i = 0; i < ab->fw_pdev_count; i++) { 917 if (ath12k_mac_band_match(band, ab->fw_pdev[i].supported_bands)) 918 return ab->fw_pdev[i].pdev_id; 919 } 920 921 return pdev_id; 922 } 923 924 u8 ath12k_mac_get_target_pdev_id(struct ath12k *ar) 925 { 926 struct ath12k_link_vif *arvif; 927 struct ath12k_base *ab = ar->ab; 928 929 if (!ab->hw_params->single_pdev_only) 930 return ar->pdev->pdev_id; 931 932 arvif = ath12k_mac_get_vif_up(ar); 933 934 /* fw_pdev array has pdev ids derived from phy capability 935 * service ready event (pdev_and_hw_link_ids). 936 * If no vif is active, return default first index. 937 */ 938 if (!arvif) 939 return ar->ab->fw_pdev[0].pdev_id; 940 941 /* If active vif is found, return the pdev id matching chandef band */ 942 return ath12k_mac_get_target_pdev_id_from_vif(arvif); 943 } 944 945 static void ath12k_pdev_caps_update(struct ath12k *ar) 946 { 947 struct ath12k_base *ab = ar->ab; 948 949 ar->max_tx_power = ab->target_caps.hw_max_tx_power; 950 951 /* FIXME: Set min_tx_power to ab->target_caps.hw_min_tx_power. 952 * But since the received value in svcrdy is same as hw_max_tx_power, 953 * we can set ar->min_tx_power to 0 currently until 954 * this is fixed in firmware 955 */ 956 ar->min_tx_power = 0; 957 958 ar->txpower_limit_2g = ar->max_tx_power; 959 ar->txpower_limit_5g = ar->max_tx_power; 960 ar->txpower_scale = WMI_HOST_TP_SCALE_MAX; 961 } 962 963 static int ath12k_mac_txpower_recalc(struct ath12k *ar) 964 { 965 struct ath12k_pdev *pdev = ar->pdev; 966 struct ath12k_link_vif *arvif; 967 int ret, txpower = -1; 968 u32 param; 969 970 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 971 972 list_for_each_entry(arvif, &ar->arvifs, list) { 973 if (arvif->txpower <= 0) 974 continue; 975 976 if (txpower == -1) 977 txpower = arvif->txpower; 978 else 979 txpower = min(txpower, arvif->txpower); 980 } 981 982 if (txpower == -1) 983 return 0; 984 985 /* txpwr is set as 2 units per dBm in FW*/ 986 txpower = min_t(u32, max_t(u32, ar->min_tx_power, txpower), 987 ar->max_tx_power) * 2; 988 989 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower to set in hw %d\n", 990 txpower / 2); 991 992 if ((pdev->cap.supported_bands & WMI_HOST_WLAN_2GHZ_CAP) && 993 ar->txpower_limit_2g != txpower) { 994 param = WMI_PDEV_PARAM_TXPOWER_LIMIT2G; 995 ret = ath12k_wmi_pdev_set_param(ar, param, 996 txpower, ar->pdev->pdev_id); 997 if (ret) 998 goto fail; 999 ar->txpower_limit_2g = txpower; 1000 } 1001 1002 if ((pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP) && 1003 ar->txpower_limit_5g != txpower) { 1004 param = WMI_PDEV_PARAM_TXPOWER_LIMIT5G; 1005 ret = ath12k_wmi_pdev_set_param(ar, param, 1006 txpower, ar->pdev->pdev_id); 1007 if (ret) 1008 goto fail; 1009 ar->txpower_limit_5g = txpower; 1010 } 1011 1012 return 0; 1013 1014 fail: 1015 ath12k_warn(ar->ab, "failed to recalc txpower limit %d using pdev param %d: %d\n", 1016 txpower / 2, param, ret); 1017 return ret; 1018 } 1019 1020 static int ath12k_recalc_rtscts_prot(struct ath12k_link_vif *arvif) 1021 { 1022 struct ath12k *ar = arvif->ar; 1023 u32 vdev_param, rts_cts; 1024 int ret; 1025 1026 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 1027 1028 vdev_param = WMI_VDEV_PARAM_ENABLE_RTSCTS; 1029 1030 /* Enable RTS/CTS protection for sw retries (when legacy stations 1031 * are in BSS) or by default only for second rate series. 1032 * TODO: Check if we need to enable CTS 2 Self in any case 1033 */ 1034 rts_cts = WMI_USE_RTS_CTS; 1035 1036 if (arvif->num_legacy_stations > 0) 1037 rts_cts |= WMI_RTSCTS_ACROSS_SW_RETRIES << 4; 1038 else 1039 rts_cts |= WMI_RTSCTS_FOR_SECOND_RATESERIES << 4; 1040 1041 /* Need not send duplicate param value to firmware */ 1042 if (arvif->rtscts_prot_mode == rts_cts) 1043 return 0; 1044 1045 arvif->rtscts_prot_mode = rts_cts; 1046 1047 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n", 1048 arvif->vdev_id, rts_cts); 1049 1050 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 1051 vdev_param, rts_cts); 1052 if (ret) 1053 ath12k_warn(ar->ab, "failed to recalculate rts/cts prot for vdev %d: %d\n", 1054 arvif->vdev_id, ret); 1055 1056 return ret; 1057 } 1058 1059 static int ath12k_mac_set_kickout(struct ath12k_link_vif *arvif) 1060 { 1061 struct ath12k *ar = arvif->ar; 1062 u32 param; 1063 int ret; 1064 1065 ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_STA_KICKOUT_TH, 1066 ATH12K_KICKOUT_THRESHOLD, 1067 ar->pdev->pdev_id); 1068 if (ret) { 1069 ath12k_warn(ar->ab, "failed to set kickout threshold on vdev %i: %d\n", 1070 arvif->vdev_id, ret); 1071 return ret; 1072 } 1073 1074 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS; 1075 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, 1076 ATH12K_KEEPALIVE_MIN_IDLE); 1077 if (ret) { 1078 ath12k_warn(ar->ab, "failed to set keepalive minimum idle time on vdev %i: %d\n", 1079 arvif->vdev_id, ret); 1080 return ret; 1081 } 1082 1083 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS; 1084 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, 1085 ATH12K_KEEPALIVE_MAX_IDLE); 1086 if (ret) { 1087 ath12k_warn(ar->ab, "failed to set keepalive maximum idle time on vdev %i: %d\n", 1088 arvif->vdev_id, ret); 1089 return ret; 1090 } 1091 1092 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS; 1093 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, 1094 ATH12K_KEEPALIVE_MAX_UNRESPONSIVE); 1095 if (ret) { 1096 ath12k_warn(ar->ab, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n", 1097 arvif->vdev_id, ret); 1098 return ret; 1099 } 1100 1101 return 0; 1102 } 1103 1104 void ath12k_mac_peer_cleanup_all(struct ath12k *ar) 1105 { 1106 struct ath12k_peer *peer, *tmp; 1107 struct ath12k_base *ab = ar->ab; 1108 1109 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 1110 1111 spin_lock_bh(&ab->base_lock); 1112 list_for_each_entry_safe(peer, tmp, &ab->peers, list) { 1113 /* Skip Rx TID cleanup for self peer */ 1114 if (peer->sta) 1115 ath12k_dp_rx_peer_tid_cleanup(ar, peer); 1116 1117 list_del(&peer->list); 1118 kfree(peer); 1119 } 1120 spin_unlock_bh(&ab->base_lock); 1121 1122 ar->num_peers = 0; 1123 ar->num_stations = 0; 1124 } 1125 1126 static int ath12k_mac_vdev_setup_sync(struct ath12k *ar) 1127 { 1128 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 1129 1130 if (test_bit(ATH12K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags)) 1131 return -ESHUTDOWN; 1132 1133 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "vdev setup timeout %d\n", 1134 ATH12K_VDEV_SETUP_TIMEOUT_HZ); 1135 1136 if (!wait_for_completion_timeout(&ar->vdev_setup_done, 1137 ATH12K_VDEV_SETUP_TIMEOUT_HZ)) 1138 return -ETIMEDOUT; 1139 1140 return ar->last_wmi_vdev_start_status ? -EINVAL : 0; 1141 } 1142 1143 static int ath12k_monitor_vdev_up(struct ath12k *ar, int vdev_id) 1144 { 1145 struct ath12k_wmi_vdev_up_params params = {}; 1146 int ret; 1147 1148 params.vdev_id = vdev_id; 1149 params.bssid = ar->mac_addr; 1150 ret = ath12k_wmi_vdev_up(ar, ¶ms); 1151 if (ret) { 1152 ath12k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n", 1153 vdev_id, ret); 1154 return ret; 1155 } 1156 1157 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i started\n", 1158 vdev_id); 1159 return 0; 1160 } 1161 1162 static int ath12k_mac_monitor_vdev_start(struct ath12k *ar, int vdev_id, 1163 struct cfg80211_chan_def *chandef) 1164 { 1165 struct ieee80211_channel *channel; 1166 struct wmi_vdev_start_req_arg arg = {}; 1167 struct ath12k_wmi_vdev_up_params params = {}; 1168 int ret; 1169 1170 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 1171 1172 channel = chandef->chan; 1173 arg.vdev_id = vdev_id; 1174 arg.freq = channel->center_freq; 1175 arg.band_center_freq1 = chandef->center_freq1; 1176 arg.band_center_freq2 = chandef->center_freq2; 1177 arg.mode = ath12k_phymodes[chandef->chan->band][chandef->width]; 1178 arg.chan_radar = !!(channel->flags & IEEE80211_CHAN_RADAR); 1179 1180 arg.min_power = 0; 1181 arg.max_power = channel->max_power; 1182 arg.max_reg_power = channel->max_reg_power; 1183 arg.max_antenna_gain = channel->max_antenna_gain; 1184 1185 arg.pref_tx_streams = ar->num_tx_chains; 1186 arg.pref_rx_streams = ar->num_rx_chains; 1187 arg.punct_bitmap = 0xFFFFFFFF; 1188 1189 arg.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR); 1190 1191 reinit_completion(&ar->vdev_setup_done); 1192 reinit_completion(&ar->vdev_delete_done); 1193 1194 ret = ath12k_wmi_vdev_start(ar, &arg, false); 1195 if (ret) { 1196 ath12k_warn(ar->ab, "failed to request monitor vdev %i start: %d\n", 1197 vdev_id, ret); 1198 return ret; 1199 } 1200 1201 ret = ath12k_mac_vdev_setup_sync(ar); 1202 if (ret) { 1203 ath12k_warn(ar->ab, "failed to synchronize setup for monitor vdev %i start: %d\n", 1204 vdev_id, ret); 1205 return ret; 1206 } 1207 1208 params.vdev_id = vdev_id; 1209 params.bssid = ar->mac_addr; 1210 ret = ath12k_wmi_vdev_up(ar, ¶ms); 1211 if (ret) { 1212 ath12k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n", 1213 vdev_id, ret); 1214 goto vdev_stop; 1215 } 1216 1217 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i started\n", 1218 vdev_id); 1219 return 0; 1220 1221 vdev_stop: 1222 ret = ath12k_wmi_vdev_stop(ar, vdev_id); 1223 if (ret) 1224 ath12k_warn(ar->ab, "failed to stop monitor vdev %i after start failure: %d\n", 1225 vdev_id, ret); 1226 return ret; 1227 } 1228 1229 static int ath12k_mac_monitor_vdev_stop(struct ath12k *ar) 1230 { 1231 int ret; 1232 1233 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 1234 1235 reinit_completion(&ar->vdev_setup_done); 1236 1237 ret = ath12k_wmi_vdev_stop(ar, ar->monitor_vdev_id); 1238 if (ret) 1239 ath12k_warn(ar->ab, "failed to request monitor vdev %i stop: %d\n", 1240 ar->monitor_vdev_id, ret); 1241 1242 ret = ath12k_mac_vdev_setup_sync(ar); 1243 if (ret) 1244 ath12k_warn(ar->ab, "failed to synchronize monitor vdev %i stop: %d\n", 1245 ar->monitor_vdev_id, ret); 1246 1247 ret = ath12k_wmi_vdev_down(ar, ar->monitor_vdev_id); 1248 if (ret) 1249 ath12k_warn(ar->ab, "failed to put down monitor vdev %i: %d\n", 1250 ar->monitor_vdev_id, ret); 1251 1252 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i stopped\n", 1253 ar->monitor_vdev_id); 1254 return ret; 1255 } 1256 1257 static int ath12k_mac_monitor_vdev_delete(struct ath12k *ar) 1258 { 1259 int ret; 1260 unsigned long time_left; 1261 1262 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 1263 1264 if (!ar->monitor_vdev_created) 1265 return 0; 1266 1267 reinit_completion(&ar->vdev_delete_done); 1268 1269 ret = ath12k_wmi_vdev_delete(ar, ar->monitor_vdev_id); 1270 if (ret) { 1271 ath12k_warn(ar->ab, "failed to request wmi monitor vdev %i removal: %d\n", 1272 ar->monitor_vdev_id, ret); 1273 return ret; 1274 } 1275 1276 time_left = wait_for_completion_timeout(&ar->vdev_delete_done, 1277 ATH12K_VDEV_DELETE_TIMEOUT_HZ); 1278 if (time_left == 0) { 1279 ath12k_warn(ar->ab, "Timeout in receiving vdev delete response\n"); 1280 } else { 1281 ar->allocated_vdev_map &= ~(1LL << ar->monitor_vdev_id); 1282 ar->ab->free_vdev_map |= 1LL << (ar->monitor_vdev_id); 1283 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %d deleted\n", 1284 ar->monitor_vdev_id); 1285 ar->num_created_vdevs--; 1286 ar->monitor_vdev_id = -1; 1287 ar->monitor_vdev_created = false; 1288 } 1289 1290 return ret; 1291 } 1292 1293 static int ath12k_mac_monitor_start(struct ath12k *ar) 1294 { 1295 struct ath12k_mac_get_any_chanctx_conf_arg arg; 1296 int ret; 1297 1298 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 1299 1300 if (ar->monitor_started) 1301 return 0; 1302 1303 arg.ar = ar; 1304 arg.chanctx_conf = NULL; 1305 ieee80211_iter_chan_contexts_atomic(ath12k_ar_to_hw(ar), 1306 ath12k_mac_get_any_chanctx_conf_iter, 1307 &arg); 1308 if (!arg.chanctx_conf) 1309 return 0; 1310 1311 ret = ath12k_mac_monitor_vdev_start(ar, ar->monitor_vdev_id, 1312 &arg.chanctx_conf->def); 1313 if (ret) { 1314 ath12k_warn(ar->ab, "failed to start monitor vdev: %d\n", ret); 1315 return ret; 1316 } 1317 1318 ret = ath12k_dp_tx_htt_monitor_mode_ring_config(ar, false); 1319 if (ret) { 1320 ath12k_warn(ar->ab, "fail to set monitor filter: %d\n", ret); 1321 return ret; 1322 } 1323 1324 ar->monitor_started = true; 1325 ar->num_started_vdevs++; 1326 1327 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor started\n"); 1328 1329 return 0; 1330 } 1331 1332 static int ath12k_mac_monitor_stop(struct ath12k *ar) 1333 { 1334 int ret; 1335 1336 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 1337 1338 if (!ar->monitor_started) 1339 return 0; 1340 1341 ret = ath12k_mac_monitor_vdev_stop(ar); 1342 if (ret) { 1343 ath12k_warn(ar->ab, "failed to stop monitor vdev: %d\n", ret); 1344 return ret; 1345 } 1346 1347 ar->monitor_started = false; 1348 ar->num_started_vdevs--; 1349 ret = ath12k_dp_tx_htt_monitor_mode_ring_config(ar, true); 1350 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor stopped ret %d\n", ret); 1351 return ret; 1352 } 1353 1354 int ath12k_mac_vdev_stop(struct ath12k_link_vif *arvif) 1355 { 1356 struct ath12k_vif *ahvif = arvif->ahvif; 1357 struct ath12k *ar = arvif->ar; 1358 int ret; 1359 1360 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 1361 1362 reinit_completion(&ar->vdev_setup_done); 1363 1364 ret = ath12k_wmi_vdev_stop(ar, arvif->vdev_id); 1365 if (ret) { 1366 ath12k_warn(ar->ab, "failed to stop WMI vdev %i: %d\n", 1367 arvif->vdev_id, ret); 1368 goto err; 1369 } 1370 1371 ret = ath12k_mac_vdev_setup_sync(ar); 1372 if (ret) { 1373 ath12k_warn(ar->ab, "failed to synchronize setup for vdev %i: %d\n", 1374 arvif->vdev_id, ret); 1375 goto err; 1376 } 1377 1378 WARN_ON(ar->num_started_vdevs == 0); 1379 1380 ar->num_started_vdevs--; 1381 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "vdev %pM stopped, vdev_id %d\n", 1382 ahvif->vif->addr, arvif->vdev_id); 1383 1384 if (test_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags)) { 1385 clear_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags); 1386 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "CAC Stopped for vdev %d\n", 1387 arvif->vdev_id); 1388 } 1389 1390 return 0; 1391 err: 1392 return ret; 1393 } 1394 1395 static int ath12k_mac_op_config(struct ieee80211_hw *hw, u32 changed) 1396 { 1397 return 0; 1398 } 1399 1400 static int ath12k_mac_setup_bcn_p2p_ie(struct ath12k_link_vif *arvif, 1401 struct sk_buff *bcn) 1402 { 1403 struct ath12k *ar = arvif->ar; 1404 struct ieee80211_mgmt *mgmt; 1405 const u8 *p2p_ie; 1406 int ret; 1407 1408 mgmt = (void *)bcn->data; 1409 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, 1410 mgmt->u.beacon.variable, 1411 bcn->len - (mgmt->u.beacon.variable - 1412 bcn->data)); 1413 if (!p2p_ie) { 1414 ath12k_warn(ar->ab, "no P2P ie found in beacon\n"); 1415 return -ENOENT; 1416 } 1417 1418 ret = ath12k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie); 1419 if (ret) { 1420 ath12k_warn(ar->ab, "failed to submit P2P GO bcn ie for vdev %i: %d\n", 1421 arvif->vdev_id, ret); 1422 return ret; 1423 } 1424 1425 return 0; 1426 } 1427 1428 static int ath12k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui, 1429 u8 oui_type, size_t ie_offset) 1430 { 1431 const u8 *next, *end; 1432 size_t len; 1433 u8 *ie; 1434 1435 if (WARN_ON(skb->len < ie_offset)) 1436 return -EINVAL; 1437 1438 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, 1439 skb->data + ie_offset, 1440 skb->len - ie_offset); 1441 if (!ie) 1442 return -ENOENT; 1443 1444 len = ie[1] + 2; 1445 end = skb->data + skb->len; 1446 next = ie + len; 1447 1448 if (WARN_ON(next > end)) 1449 return -EINVAL; 1450 1451 memmove(ie, next, end - next); 1452 skb_trim(skb, skb->len - len); 1453 1454 return 0; 1455 } 1456 1457 static void ath12k_mac_set_arvif_ies(struct ath12k_link_vif *arvif, struct sk_buff *bcn, 1458 u8 bssid_index, bool *nontx_profile_found) 1459 { 1460 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)bcn->data; 1461 const struct element *elem, *nontx, *index, *nie; 1462 const u8 *start, *tail; 1463 u16 rem_len; 1464 u8 i; 1465 1466 start = bcn->data + ieee80211_get_hdrlen_from_skb(bcn) + sizeof(mgmt->u.beacon); 1467 tail = skb_tail_pointer(bcn); 1468 rem_len = tail - start; 1469 1470 arvif->rsnie_present = false; 1471 arvif->wpaie_present = false; 1472 1473 if (cfg80211_find_ie(WLAN_EID_RSN, start, rem_len)) 1474 arvif->rsnie_present = true; 1475 if (cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, WLAN_OUI_TYPE_MICROSOFT_WPA, 1476 start, rem_len)) 1477 arvif->wpaie_present = true; 1478 1479 /* Return from here for the transmitted profile */ 1480 if (!bssid_index) 1481 return; 1482 1483 /* Initial rsnie_present for the nontransmitted profile is set to be same as that 1484 * of the transmitted profile. It will be changed if security configurations are 1485 * different. 1486 */ 1487 *nontx_profile_found = false; 1488 for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, start, rem_len) { 1489 /* Fixed minimum MBSSID element length with at least one 1490 * nontransmitted BSSID profile is 12 bytes as given below; 1491 * 1 (max BSSID indicator) + 1492 * 2 (Nontransmitted BSSID profile: Subelement ID + length) + 1493 * 4 (Nontransmitted BSSID Capabilities: tag + length + info) 1494 * 2 (Nontransmitted BSSID SSID: tag + length) 1495 * 3 (Nontransmitted BSSID Index: tag + length + BSSID index 1496 */ 1497 if (elem->datalen < 12 || elem->data[0] < 1) 1498 continue; /* Max BSSID indicator must be >=1 */ 1499 1500 for_each_element(nontx, elem->data + 1, elem->datalen - 1) { 1501 start = nontx->data; 1502 1503 if (nontx->id != 0 || nontx->datalen < 4) 1504 continue; /* Invalid nontransmitted profile */ 1505 1506 if (nontx->data[0] != WLAN_EID_NON_TX_BSSID_CAP || 1507 nontx->data[1] != 2) { 1508 continue; /* Missing nontransmitted BSS capabilities */ 1509 } 1510 1511 if (nontx->data[4] != WLAN_EID_SSID) 1512 continue; /* Missing SSID for nontransmitted BSS */ 1513 1514 index = cfg80211_find_elem(WLAN_EID_MULTI_BSSID_IDX, 1515 start, nontx->datalen); 1516 if (!index || index->datalen < 1 || index->data[0] == 0) 1517 continue; /* Invalid MBSSID Index element */ 1518 1519 if (index->data[0] == bssid_index) { 1520 *nontx_profile_found = true; 1521 if (cfg80211_find_ie(WLAN_EID_RSN, 1522 nontx->data, 1523 nontx->datalen)) { 1524 arvif->rsnie_present = true; 1525 return; 1526 } else if (!arvif->rsnie_present) { 1527 return; /* Both tx and nontx BSS are open */ 1528 } 1529 1530 nie = cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE, 1531 nontx->data, 1532 nontx->datalen); 1533 if (!nie || nie->datalen < 2) 1534 return; /* Invalid non-inheritance element */ 1535 1536 for (i = 1; i < nie->datalen - 1; i++) { 1537 if (nie->data[i] == WLAN_EID_RSN) { 1538 arvif->rsnie_present = false; 1539 break; 1540 } 1541 } 1542 1543 return; 1544 } 1545 } 1546 } 1547 } 1548 1549 static int ath12k_mac_setup_bcn_tmpl_ema(struct ath12k_link_vif *arvif, 1550 struct ath12k_link_vif *tx_arvif, 1551 u8 bssid_index) 1552 { 1553 struct ath12k_wmi_bcn_tmpl_ema_arg ema_args; 1554 struct ieee80211_ema_beacons *beacons; 1555 bool nontx_profile_found = false; 1556 int ret = 0; 1557 u8 i; 1558 1559 beacons = ieee80211_beacon_get_template_ema_list(ath12k_ar_to_hw(tx_arvif->ar), 1560 tx_arvif->ahvif->vif, 1561 tx_arvif->link_id); 1562 if (!beacons || !beacons->cnt) { 1563 ath12k_warn(arvif->ar->ab, 1564 "failed to get ema beacon templates from mac80211\n"); 1565 return -EPERM; 1566 } 1567 1568 if (tx_arvif == arvif) 1569 ath12k_mac_set_arvif_ies(arvif, beacons->bcn[0].skb, 0, NULL); 1570 1571 for (i = 0; i < beacons->cnt; i++) { 1572 if (tx_arvif != arvif && !nontx_profile_found) 1573 ath12k_mac_set_arvif_ies(arvif, beacons->bcn[i].skb, 1574 bssid_index, 1575 &nontx_profile_found); 1576 1577 ema_args.bcn_cnt = beacons->cnt; 1578 ema_args.bcn_index = i; 1579 ret = ath12k_wmi_bcn_tmpl(tx_arvif, &beacons->bcn[i].offs, 1580 beacons->bcn[i].skb, &ema_args); 1581 if (ret) { 1582 ath12k_warn(tx_arvif->ar->ab, 1583 "failed to set ema beacon template id %i error %d\n", 1584 i, ret); 1585 break; 1586 } 1587 } 1588 1589 if (tx_arvif != arvif && !nontx_profile_found) 1590 ath12k_warn(arvif->ar->ab, 1591 "nontransmitted bssid index %u not found in beacon template\n", 1592 bssid_index); 1593 1594 ieee80211_beacon_free_ema_list(beacons); 1595 return ret; 1596 } 1597 1598 static int ath12k_mac_setup_bcn_tmpl(struct ath12k_link_vif *arvif) 1599 { 1600 struct ath12k_vif *ahvif = arvif->ahvif; 1601 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); 1602 struct ieee80211_bss_conf *link_conf; 1603 struct ath12k_link_vif *tx_arvif; 1604 struct ath12k *ar = arvif->ar; 1605 struct ath12k_base *ab = ar->ab; 1606 struct ieee80211_mutable_offsets offs = {}; 1607 bool nontx_profile_found = false; 1608 struct sk_buff *bcn; 1609 int ret; 1610 1611 if (ahvif->vdev_type != WMI_VDEV_TYPE_AP) 1612 return 0; 1613 1614 link_conf = ath12k_mac_get_link_bss_conf(arvif); 1615 if (!link_conf) { 1616 ath12k_warn(ar->ab, "unable to access bss link conf to set bcn tmpl for vif %pM link %u\n", 1617 vif->addr, arvif->link_id); 1618 return -ENOLINK; 1619 } 1620 1621 tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf); 1622 if (tx_arvif) { 1623 if (tx_arvif != arvif && arvif->is_up) 1624 return 0; 1625 1626 if (link_conf->ema_ap) 1627 return ath12k_mac_setup_bcn_tmpl_ema(arvif, tx_arvif, 1628 link_conf->bssid_index); 1629 } else { 1630 tx_arvif = arvif; 1631 } 1632 1633 bcn = ieee80211_beacon_get_template(ath12k_ar_to_hw(tx_arvif->ar), 1634 tx_arvif->ahvif->vif, 1635 &offs, tx_arvif->link_id); 1636 if (!bcn) { 1637 ath12k_warn(ab, "failed to get beacon template from mac80211\n"); 1638 return -EPERM; 1639 } 1640 1641 if (tx_arvif == arvif) { 1642 ath12k_mac_set_arvif_ies(arvif, bcn, 0, NULL); 1643 } else { 1644 ath12k_mac_set_arvif_ies(arvif, bcn, 1645 link_conf->bssid_index, 1646 &nontx_profile_found); 1647 if (!nontx_profile_found) 1648 ath12k_warn(ab, 1649 "nontransmitted profile not found in beacon template\n"); 1650 } 1651 1652 if (ahvif->vif->type == NL80211_IFTYPE_AP && ahvif->vif->p2p) { 1653 ret = ath12k_mac_setup_bcn_p2p_ie(arvif, bcn); 1654 if (ret) { 1655 ath12k_warn(ab, "failed to setup P2P GO bcn ie: %d\n", 1656 ret); 1657 goto free_bcn_skb; 1658 } 1659 1660 /* P2P IE is inserted by firmware automatically (as 1661 * configured above) so remove it from the base beacon 1662 * template to avoid duplicate P2P IEs in beacon frames. 1663 */ 1664 ret = ath12k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, 1665 WLAN_OUI_TYPE_WFA_P2P, 1666 offsetof(struct ieee80211_mgmt, 1667 u.beacon.variable)); 1668 if (ret) { 1669 ath12k_warn(ab, "failed to remove P2P vendor ie: %d\n", 1670 ret); 1671 goto free_bcn_skb; 1672 } 1673 } 1674 1675 ret = ath12k_wmi_bcn_tmpl(arvif, &offs, bcn, NULL); 1676 1677 if (ret) 1678 ath12k_warn(ab, "failed to submit beacon template command: %d\n", 1679 ret); 1680 1681 free_bcn_skb: 1682 kfree_skb(bcn); 1683 return ret; 1684 } 1685 1686 static void ath12k_control_beaconing(struct ath12k_link_vif *arvif, 1687 struct ieee80211_bss_conf *info) 1688 { 1689 struct ath12k_wmi_vdev_up_params params = {}; 1690 struct ath12k_vif *ahvif = arvif->ahvif; 1691 struct ieee80211_bss_conf *link_conf; 1692 struct ath12k_link_vif *tx_arvif; 1693 struct ath12k *ar = arvif->ar; 1694 int ret; 1695 1696 lockdep_assert_wiphy(ath12k_ar_to_hw(arvif->ar)->wiphy); 1697 1698 if (!info->enable_beacon) { 1699 ret = ath12k_wmi_vdev_down(ar, arvif->vdev_id); 1700 if (ret) 1701 ath12k_warn(ar->ab, "failed to down vdev_id %i: %d\n", 1702 arvif->vdev_id, ret); 1703 1704 arvif->is_up = false; 1705 return; 1706 } 1707 1708 /* Install the beacon template to the FW */ 1709 ret = ath12k_mac_setup_bcn_tmpl(arvif); 1710 if (ret) { 1711 ath12k_warn(ar->ab, "failed to update bcn tmpl during vdev up: %d\n", 1712 ret); 1713 return; 1714 } 1715 1716 ahvif->aid = 0; 1717 1718 ether_addr_copy(arvif->bssid, info->addr); 1719 1720 params.vdev_id = arvif->vdev_id; 1721 params.aid = ahvif->aid; 1722 params.bssid = arvif->bssid; 1723 1724 link_conf = ath12k_mac_get_link_bss_conf(arvif); 1725 if (!link_conf) { 1726 ath12k_warn(ar->ab, 1727 "unable to access bss link conf for link %u required to retrieve transmitting link conf\n", 1728 arvif->link_id); 1729 return; 1730 } 1731 1732 tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf); 1733 if (tx_arvif) { 1734 params.tx_bssid = tx_arvif->bssid; 1735 params.nontx_profile_idx = info->bssid_index; 1736 params.nontx_profile_cnt = 1 << info->bssid_indicator; 1737 } 1738 ret = ath12k_wmi_vdev_up(arvif->ar, ¶ms); 1739 if (ret) { 1740 ath12k_warn(ar->ab, "failed to bring up vdev %d: %i\n", 1741 arvif->vdev_id, ret); 1742 return; 1743 } 1744 1745 arvif->is_up = true; 1746 1747 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id); 1748 } 1749 1750 static void ath12k_mac_handle_beacon_iter(void *data, u8 *mac, 1751 struct ieee80211_vif *vif) 1752 { 1753 struct sk_buff *skb = data; 1754 struct ieee80211_mgmt *mgmt = (void *)skb->data; 1755 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 1756 struct ath12k_link_vif *arvif = &ahvif->deflink; 1757 1758 if (vif->type != NL80211_IFTYPE_STATION) 1759 return; 1760 1761 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid)) 1762 return; 1763 1764 cancel_delayed_work(&arvif->connection_loss_work); 1765 } 1766 1767 void ath12k_mac_handle_beacon(struct ath12k *ar, struct sk_buff *skb) 1768 { 1769 ieee80211_iterate_active_interfaces_atomic(ath12k_ar_to_hw(ar), 1770 IEEE80211_IFACE_ITER_NORMAL, 1771 ath12k_mac_handle_beacon_iter, 1772 skb); 1773 } 1774 1775 static void ath12k_mac_handle_beacon_miss_iter(void *data, u8 *mac, 1776 struct ieee80211_vif *vif) 1777 { 1778 u32 *vdev_id = data; 1779 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 1780 struct ath12k_link_vif *arvif = &ahvif->deflink; 1781 struct ath12k *ar = arvif->ar; 1782 struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); 1783 1784 if (arvif->vdev_id != *vdev_id) 1785 return; 1786 1787 if (!arvif->is_up) 1788 return; 1789 1790 ieee80211_beacon_loss(vif); 1791 1792 /* Firmware doesn't report beacon loss events repeatedly. If AP probe 1793 * (done by mac80211) succeeds but beacons do not resume then it 1794 * doesn't make sense to continue operation. Queue connection loss work 1795 * which can be cancelled when beacon is received. 1796 */ 1797 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work, 1798 ATH12K_CONNECTION_LOSS_HZ); 1799 } 1800 1801 void ath12k_mac_handle_beacon_miss(struct ath12k *ar, u32 vdev_id) 1802 { 1803 ieee80211_iterate_active_interfaces_atomic(ath12k_ar_to_hw(ar), 1804 IEEE80211_IFACE_ITER_NORMAL, 1805 ath12k_mac_handle_beacon_miss_iter, 1806 &vdev_id); 1807 } 1808 1809 static void ath12k_mac_vif_sta_connection_loss_work(struct work_struct *work) 1810 { 1811 struct ath12k_link_vif *arvif = container_of(work, struct ath12k_link_vif, 1812 connection_loss_work.work); 1813 struct ieee80211_vif *vif = arvif->ahvif->vif; 1814 1815 if (!arvif->is_up) 1816 return; 1817 1818 ieee80211_connection_loss(vif); 1819 } 1820 1821 static void ath12k_peer_assoc_h_basic(struct ath12k *ar, 1822 struct ath12k_link_vif *arvif, 1823 struct ath12k_link_sta *arsta, 1824 struct ath12k_wmi_peer_assoc_arg *arg) 1825 { 1826 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 1827 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 1828 struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); 1829 struct ieee80211_bss_conf *bss_conf; 1830 u32 aid; 1831 1832 lockdep_assert_wiphy(hw->wiphy); 1833 1834 if (vif->type == NL80211_IFTYPE_STATION) 1835 aid = vif->cfg.aid; 1836 else 1837 aid = sta->aid; 1838 1839 ether_addr_copy(arg->peer_mac, arsta->addr); 1840 arg->vdev_id = arvif->vdev_id; 1841 arg->peer_associd = aid; 1842 arg->auth_flag = true; 1843 /* TODO: STA WAR in ath10k for listen interval required? */ 1844 arg->peer_listen_intval = hw->conf.listen_interval; 1845 arg->peer_nss = 1; 1846 1847 bss_conf = ath12k_mac_get_link_bss_conf(arvif); 1848 if (!bss_conf) { 1849 ath12k_warn(ar->ab, "unable to access bss link conf in peer assoc for vif %pM link %u\n", 1850 vif->addr, arvif->link_id); 1851 return; 1852 } 1853 1854 arg->peer_caps = bss_conf->assoc_capability; 1855 } 1856 1857 static void ath12k_peer_assoc_h_crypto(struct ath12k *ar, 1858 struct ath12k_link_vif *arvif, 1859 struct ath12k_link_sta *arsta, 1860 struct ath12k_wmi_peer_assoc_arg *arg) 1861 { 1862 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 1863 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 1864 struct ieee80211_bss_conf *info; 1865 struct cfg80211_chan_def def; 1866 struct cfg80211_bss *bss; 1867 struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); 1868 const u8 *rsnie = NULL; 1869 const u8 *wpaie = NULL; 1870 1871 lockdep_assert_wiphy(hw->wiphy); 1872 1873 info = ath12k_mac_get_link_bss_conf(arvif); 1874 if (!info) { 1875 ath12k_warn(ar->ab, "unable to access bss link conf for peer assoc crypto for vif %pM link %u\n", 1876 vif->addr, arvif->link_id); 1877 return; 1878 } 1879 1880 if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) 1881 return; 1882 1883 bss = cfg80211_get_bss(hw->wiphy, def.chan, info->bssid, NULL, 0, 1884 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY); 1885 1886 if (arvif->rsnie_present || arvif->wpaie_present) { 1887 arg->need_ptk_4_way = true; 1888 if (arvif->wpaie_present) 1889 arg->need_gtk_2_way = true; 1890 } else if (bss) { 1891 const struct cfg80211_bss_ies *ies; 1892 1893 rcu_read_lock(); 1894 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN); 1895 1896 ies = rcu_dereference(bss->ies); 1897 1898 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, 1899 WLAN_OUI_TYPE_MICROSOFT_WPA, 1900 ies->data, 1901 ies->len); 1902 rcu_read_unlock(); 1903 cfg80211_put_bss(hw->wiphy, bss); 1904 } 1905 1906 /* FIXME: base on RSN IE/WPA IE is a correct idea? */ 1907 if (rsnie || wpaie) { 1908 ath12k_dbg(ar->ab, ATH12K_DBG_WMI, 1909 "%s: rsn ie found\n", __func__); 1910 arg->need_ptk_4_way = true; 1911 } 1912 1913 if (wpaie) { 1914 ath12k_dbg(ar->ab, ATH12K_DBG_WMI, 1915 "%s: wpa ie found\n", __func__); 1916 arg->need_gtk_2_way = true; 1917 } 1918 1919 if (sta->mfp) { 1920 /* TODO: Need to check if FW supports PMF? */ 1921 arg->is_pmf_enabled = true; 1922 } 1923 1924 /* TODO: safe_mode_enabled (bypass 4-way handshake) flag req? */ 1925 } 1926 1927 static void ath12k_peer_assoc_h_rates(struct ath12k *ar, 1928 struct ath12k_link_vif *arvif, 1929 struct ath12k_link_sta *arsta, 1930 struct ath12k_wmi_peer_assoc_arg *arg) 1931 { 1932 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 1933 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 1934 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; 1935 struct ieee80211_link_sta *link_sta; 1936 struct cfg80211_chan_def def; 1937 const struct ieee80211_supported_band *sband; 1938 const struct ieee80211_rate *rates; 1939 struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); 1940 enum nl80211_band band; 1941 u32 ratemask; 1942 u8 rate; 1943 int i; 1944 1945 lockdep_assert_wiphy(hw->wiphy); 1946 1947 if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) 1948 return; 1949 1950 link_sta = ath12k_mac_get_link_sta(arsta); 1951 if (!link_sta) { 1952 ath12k_warn(ar->ab, "unable to access link sta in peer assoc rates for sta %pM link %u\n", 1953 sta->addr, arsta->link_id); 1954 return; 1955 } 1956 1957 band = def.chan->band; 1958 sband = hw->wiphy->bands[band]; 1959 ratemask = link_sta->supp_rates[band]; 1960 ratemask &= arvif->bitrate_mask.control[band].legacy; 1961 rates = sband->bitrates; 1962 1963 rateset->num_rates = 0; 1964 1965 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) { 1966 if (!(ratemask & 1)) 1967 continue; 1968 1969 rate = ath12k_mac_bitrate_to_rate(rates->bitrate); 1970 rateset->rates[rateset->num_rates] = rate; 1971 rateset->num_rates++; 1972 } 1973 } 1974 1975 static bool 1976 ath12k_peer_assoc_h_ht_masked(const u8 *ht_mcs_mask) 1977 { 1978 int nss; 1979 1980 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++) 1981 if (ht_mcs_mask[nss]) 1982 return false; 1983 1984 return true; 1985 } 1986 1987 static bool 1988 ath12k_peer_assoc_h_vht_masked(const u16 *vht_mcs_mask) 1989 { 1990 int nss; 1991 1992 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) 1993 if (vht_mcs_mask[nss]) 1994 return false; 1995 1996 return true; 1997 } 1998 1999 static void ath12k_peer_assoc_h_ht(struct ath12k *ar, 2000 struct ath12k_link_vif *arvif, 2001 struct ath12k_link_sta *arsta, 2002 struct ath12k_wmi_peer_assoc_arg *arg) 2003 { 2004 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 2005 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 2006 const struct ieee80211_sta_ht_cap *ht_cap; 2007 struct ieee80211_link_sta *link_sta; 2008 struct cfg80211_chan_def def; 2009 enum nl80211_band band; 2010 const u8 *ht_mcs_mask; 2011 int i, n; 2012 u8 max_nss; 2013 u32 stbc; 2014 2015 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 2016 2017 if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) 2018 return; 2019 2020 link_sta = ath12k_mac_get_link_sta(arsta); 2021 if (!link_sta) { 2022 ath12k_warn(ar->ab, "unable to access link sta in peer assoc ht for sta %pM link %u\n", 2023 sta->addr, arsta->link_id); 2024 return; 2025 } 2026 2027 ht_cap = &link_sta->ht_cap; 2028 if (!ht_cap->ht_supported) 2029 return; 2030 2031 band = def.chan->band; 2032 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; 2033 2034 if (ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) 2035 return; 2036 2037 arg->ht_flag = true; 2038 2039 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + 2040 ht_cap->ampdu_factor)) - 1; 2041 2042 arg->peer_mpdu_density = 2043 ath12k_parse_mpdudensity(ht_cap->ampdu_density); 2044 2045 arg->peer_ht_caps = ht_cap->cap; 2046 arg->peer_rate_caps |= WMI_HOST_RC_HT_FLAG; 2047 2048 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) 2049 arg->ldpc_flag = true; 2050 2051 if (link_sta->bandwidth >= IEEE80211_STA_RX_BW_40) { 2052 arg->bw_40 = true; 2053 arg->peer_rate_caps |= WMI_HOST_RC_CW40_FLAG; 2054 } 2055 2056 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) { 2057 if (ht_cap->cap & (IEEE80211_HT_CAP_SGI_20 | 2058 IEEE80211_HT_CAP_SGI_40)) 2059 arg->peer_rate_caps |= WMI_HOST_RC_SGI_FLAG; 2060 } 2061 2062 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) { 2063 arg->peer_rate_caps |= WMI_HOST_RC_TX_STBC_FLAG; 2064 arg->stbc_flag = true; 2065 } 2066 2067 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) { 2068 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC; 2069 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT; 2070 stbc = stbc << WMI_HOST_RC_RX_STBC_FLAG_S; 2071 arg->peer_rate_caps |= stbc; 2072 arg->stbc_flag = true; 2073 } 2074 2075 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2]) 2076 arg->peer_rate_caps |= WMI_HOST_RC_TS_FLAG; 2077 else if (ht_cap->mcs.rx_mask[1]) 2078 arg->peer_rate_caps |= WMI_HOST_RC_DS_FLAG; 2079 2080 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++) 2081 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) && 2082 (ht_mcs_mask[i / 8] & BIT(i % 8))) { 2083 max_nss = (i / 8) + 1; 2084 arg->peer_ht_rates.rates[n++] = i; 2085 } 2086 2087 /* This is a workaround for HT-enabled STAs which break the spec 2088 * and have no HT capabilities RX mask (no HT RX MCS map). 2089 * 2090 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS), 2091 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. 2092 * 2093 * Firmware asserts if such situation occurs. 2094 */ 2095 if (n == 0) { 2096 arg->peer_ht_rates.num_rates = 8; 2097 for (i = 0; i < arg->peer_ht_rates.num_rates; i++) 2098 arg->peer_ht_rates.rates[i] = i; 2099 } else { 2100 arg->peer_ht_rates.num_rates = n; 2101 arg->peer_nss = min(link_sta->rx_nss, max_nss); 2102 } 2103 2104 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n", 2105 arg->peer_mac, 2106 arg->peer_ht_rates.num_rates, 2107 arg->peer_nss); 2108 } 2109 2110 static int ath12k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss) 2111 { 2112 switch ((mcs_map >> (2 * nss)) & 0x3) { 2113 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1; 2114 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1; 2115 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1; 2116 } 2117 return 0; 2118 } 2119 2120 static u16 2121 ath12k_peer_assoc_h_vht_limit(u16 tx_mcs_set, 2122 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX]) 2123 { 2124 int idx_limit; 2125 int nss; 2126 u16 mcs_map; 2127 u16 mcs; 2128 2129 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { 2130 mcs_map = ath12k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) & 2131 vht_mcs_limit[nss]; 2132 2133 if (mcs_map) 2134 idx_limit = fls(mcs_map) - 1; 2135 else 2136 idx_limit = -1; 2137 2138 switch (idx_limit) { 2139 case 0: 2140 case 1: 2141 case 2: 2142 case 3: 2143 case 4: 2144 case 5: 2145 case 6: 2146 case 7: 2147 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7; 2148 break; 2149 case 8: 2150 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8; 2151 break; 2152 case 9: 2153 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9; 2154 break; 2155 default: 2156 WARN_ON(1); 2157 fallthrough; 2158 case -1: 2159 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED; 2160 break; 2161 } 2162 2163 tx_mcs_set &= ~(0x3 << (nss * 2)); 2164 tx_mcs_set |= mcs << (nss * 2); 2165 } 2166 2167 return tx_mcs_set; 2168 } 2169 2170 static void ath12k_peer_assoc_h_vht(struct ath12k *ar, 2171 struct ath12k_link_vif *arvif, 2172 struct ath12k_link_sta *arsta, 2173 struct ath12k_wmi_peer_assoc_arg *arg) 2174 { 2175 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 2176 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 2177 const struct ieee80211_sta_vht_cap *vht_cap; 2178 struct ieee80211_link_sta *link_sta; 2179 struct cfg80211_chan_def def; 2180 enum nl80211_band band; 2181 const u16 *vht_mcs_mask; 2182 u16 tx_mcs_map; 2183 u8 ampdu_factor; 2184 u8 max_nss, vht_mcs; 2185 int i; 2186 2187 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 2188 2189 if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) 2190 return; 2191 2192 link_sta = ath12k_mac_get_link_sta(arsta); 2193 if (!link_sta) { 2194 ath12k_warn(ar->ab, "unable to access link sta in peer assoc vht for sta %pM link %u\n", 2195 sta->addr, arsta->link_id); 2196 return; 2197 } 2198 2199 vht_cap = &link_sta->vht_cap; 2200 if (!vht_cap->vht_supported) 2201 return; 2202 2203 band = def.chan->band; 2204 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; 2205 2206 if (ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) 2207 return; 2208 2209 arg->vht_flag = true; 2210 2211 /* TODO: similar flags required? */ 2212 arg->vht_capable = true; 2213 2214 if (def.chan->band == NL80211_BAND_2GHZ) 2215 arg->vht_ng_flag = true; 2216 2217 arg->peer_vht_caps = vht_cap->cap; 2218 2219 ampdu_factor = (vht_cap->cap & 2220 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >> 2221 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; 2222 2223 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to 2224 * zero in VHT IE. Using it would result in degraded throughput. 2225 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep 2226 * it if VHT max_mpdu is smaller. 2227 */ 2228 arg->peer_max_mpdu = max(arg->peer_max_mpdu, 2229 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + 2230 ampdu_factor)) - 1); 2231 2232 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) 2233 arg->bw_80 = true; 2234 2235 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) 2236 arg->bw_160 = true; 2237 2238 /* Calculate peer NSS capability from VHT capabilities if STA 2239 * supports VHT. 2240 */ 2241 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) { 2242 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >> 2243 (2 * i) & 3; 2244 2245 if (vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED && 2246 vht_mcs_mask[i]) 2247 max_nss = i + 1; 2248 } 2249 arg->peer_nss = min(link_sta->rx_nss, max_nss); 2250 arg->rx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.rx_highest); 2251 arg->rx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); 2252 arg->tx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.tx_highest); 2253 2254 tx_mcs_map = __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map); 2255 arg->tx_mcs_set = ath12k_peer_assoc_h_vht_limit(tx_mcs_map, vht_mcs_mask); 2256 2257 /* In QCN9274 platform, VHT MCS rate 10 and 11 is enabled by default. 2258 * VHT MCS rate 10 and 11 is not supported in 11ac standard. 2259 * so explicitly disable the VHT MCS rate 10 and 11 in 11ac mode. 2260 */ 2261 arg->tx_mcs_set &= ~IEEE80211_VHT_MCS_SUPPORT_0_11_MASK; 2262 arg->tx_mcs_set |= IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11; 2263 2264 if ((arg->tx_mcs_set & IEEE80211_VHT_MCS_NOT_SUPPORTED) == 2265 IEEE80211_VHT_MCS_NOT_SUPPORTED) 2266 arg->peer_vht_caps &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; 2267 2268 /* TODO: Check */ 2269 arg->tx_max_mcs_nss = 0xFF; 2270 2271 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n", 2272 arsta->addr, arg->peer_max_mpdu, arg->peer_flags); 2273 2274 /* TODO: rxnss_override */ 2275 } 2276 2277 static void ath12k_peer_assoc_h_he(struct ath12k *ar, 2278 struct ath12k_link_vif *arvif, 2279 struct ath12k_link_sta *arsta, 2280 struct ath12k_wmi_peer_assoc_arg *arg) 2281 { 2282 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 2283 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 2284 const struct ieee80211_sta_he_cap *he_cap; 2285 struct ieee80211_bss_conf *link_conf; 2286 struct ieee80211_link_sta *link_sta; 2287 int i; 2288 u8 ampdu_factor, max_nss; 2289 u8 rx_mcs_80 = IEEE80211_HE_MCS_NOT_SUPPORTED; 2290 u8 rx_mcs_160 = IEEE80211_HE_MCS_NOT_SUPPORTED; 2291 u16 mcs_160_map, mcs_80_map; 2292 bool support_160; 2293 u16 v; 2294 2295 link_conf = ath12k_mac_get_link_bss_conf(arvif); 2296 if (!link_conf) { 2297 ath12k_warn(ar->ab, "unable to access bss link conf in peer assoc he for vif %pM link %u", 2298 vif->addr, arvif->link_id); 2299 return; 2300 } 2301 2302 link_sta = ath12k_mac_get_link_sta(arsta); 2303 if (!link_sta) { 2304 ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n", 2305 sta->addr, arsta->link_id); 2306 return; 2307 } 2308 2309 he_cap = &link_sta->he_cap; 2310 if (!he_cap->has_he) 2311 return; 2312 2313 arg->he_flag = true; 2314 2315 support_160 = !!(he_cap->he_cap_elem.phy_cap_info[0] & 2316 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G); 2317 2318 /* Supported HE-MCS and NSS Set of peer he_cap is intersection with self he_cp */ 2319 mcs_160_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160); 2320 mcs_80_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80); 2321 2322 if (support_160) { 2323 for (i = 7; i >= 0; i--) { 2324 u8 mcs_160 = (mcs_160_map >> (2 * i)) & 3; 2325 2326 if (mcs_160 != IEEE80211_HE_MCS_NOT_SUPPORTED) { 2327 rx_mcs_160 = i + 1; 2328 break; 2329 } 2330 } 2331 } 2332 2333 for (i = 7; i >= 0; i--) { 2334 u8 mcs_80 = (mcs_80_map >> (2 * i)) & 3; 2335 2336 if (mcs_80 != IEEE80211_HE_MCS_NOT_SUPPORTED) { 2337 rx_mcs_80 = i + 1; 2338 break; 2339 } 2340 } 2341 2342 if (support_160) 2343 max_nss = min(rx_mcs_80, rx_mcs_160); 2344 else 2345 max_nss = rx_mcs_80; 2346 2347 arg->peer_nss = min(link_sta->rx_nss, max_nss); 2348 2349 memcpy(&arg->peer_he_cap_macinfo, he_cap->he_cap_elem.mac_cap_info, 2350 sizeof(he_cap->he_cap_elem.mac_cap_info)); 2351 memcpy(&arg->peer_he_cap_phyinfo, he_cap->he_cap_elem.phy_cap_info, 2352 sizeof(he_cap->he_cap_elem.phy_cap_info)); 2353 arg->peer_he_ops = link_conf->he_oper.params; 2354 2355 /* the top most byte is used to indicate BSS color info */ 2356 arg->peer_he_ops &= 0xffffff; 2357 2358 /* As per section 26.6.1 IEEE Std 802.11ax‐2022, if the Max AMPDU 2359 * Exponent Extension in HE cap is zero, use the arg->peer_max_mpdu 2360 * as calculated while parsing VHT caps(if VHT caps is present) 2361 * or HT caps (if VHT caps is not present). 2362 * 2363 * For non-zero value of Max AMPDU Exponent Extension in HE MAC caps, 2364 * if a HE STA sends VHT cap and HE cap IE in assoc request then, use 2365 * MAX_AMPDU_LEN_FACTOR as 20 to calculate max_ampdu length. 2366 * If a HE STA that does not send VHT cap, but HE and HT cap in assoc 2367 * request, then use MAX_AMPDU_LEN_FACTOR as 16 to calculate max_ampdu 2368 * length. 2369 */ 2370 ampdu_factor = u8_get_bits(he_cap->he_cap_elem.mac_cap_info[3], 2371 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK); 2372 2373 if (ampdu_factor) { 2374 if (link_sta->vht_cap.vht_supported) 2375 arg->peer_max_mpdu = (1 << (IEEE80211_HE_VHT_MAX_AMPDU_FACTOR + 2376 ampdu_factor)) - 1; 2377 else if (link_sta->ht_cap.ht_supported) 2378 arg->peer_max_mpdu = (1 << (IEEE80211_HE_HT_MAX_AMPDU_FACTOR + 2379 ampdu_factor)) - 1; 2380 } 2381 2382 if (he_cap->he_cap_elem.phy_cap_info[6] & 2383 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 2384 int bit = 7; 2385 int nss, ru; 2386 2387 arg->peer_ppet.numss_m1 = he_cap->ppe_thres[0] & 2388 IEEE80211_PPE_THRES_NSS_MASK; 2389 arg->peer_ppet.ru_bit_mask = 2390 (he_cap->ppe_thres[0] & 2391 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >> 2392 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS; 2393 2394 for (nss = 0; nss <= arg->peer_ppet.numss_m1; nss++) { 2395 for (ru = 0; ru < 4; ru++) { 2396 u32 val = 0; 2397 int i; 2398 2399 if ((arg->peer_ppet.ru_bit_mask & BIT(ru)) == 0) 2400 continue; 2401 for (i = 0; i < 6; i++) { 2402 val >>= 1; 2403 val |= ((he_cap->ppe_thres[bit / 8] >> 2404 (bit % 8)) & 0x1) << 5; 2405 bit++; 2406 } 2407 arg->peer_ppet.ppet16_ppet8_ru3_ru0[nss] |= 2408 val << (ru * 6); 2409 } 2410 } 2411 } 2412 2413 if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_RES) 2414 arg->twt_responder = true; 2415 if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_REQ) 2416 arg->twt_requester = true; 2417 2418 switch (link_sta->bandwidth) { 2419 case IEEE80211_STA_RX_BW_160: 2420 if (he_cap->he_cap_elem.phy_cap_info[0] & 2421 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) { 2422 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80p80); 2423 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v; 2424 2425 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80p80); 2426 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v; 2427 2428 arg->peer_he_mcs_count++; 2429 } 2430 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160); 2431 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v; 2432 2433 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_160); 2434 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v; 2435 2436 arg->peer_he_mcs_count++; 2437 fallthrough; 2438 2439 default: 2440 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80); 2441 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v; 2442 2443 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80); 2444 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v; 2445 2446 arg->peer_he_mcs_count++; 2447 break; 2448 } 2449 } 2450 2451 static void ath12k_peer_assoc_h_he_6ghz(struct ath12k *ar, 2452 struct ath12k_link_vif *arvif, 2453 struct ath12k_link_sta *arsta, 2454 struct ath12k_wmi_peer_assoc_arg *arg) 2455 { 2456 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 2457 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 2458 const struct ieee80211_sta_he_cap *he_cap; 2459 struct ieee80211_link_sta *link_sta; 2460 struct cfg80211_chan_def def; 2461 enum nl80211_band band; 2462 u8 ampdu_factor, mpdu_density; 2463 2464 if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) 2465 return; 2466 2467 band = def.chan->band; 2468 2469 link_sta = ath12k_mac_get_link_sta(arsta); 2470 if (!link_sta) { 2471 ath12k_warn(ar->ab, "unable to access link sta in peer assoc he 6ghz for sta %pM link %u\n", 2472 sta->addr, arsta->link_id); 2473 return; 2474 } 2475 2476 he_cap = &link_sta->he_cap; 2477 2478 if (!arg->he_flag || band != NL80211_BAND_6GHZ || !link_sta->he_6ghz_capa.capa) 2479 return; 2480 2481 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) 2482 arg->bw_40 = true; 2483 2484 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) 2485 arg->bw_80 = true; 2486 2487 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) 2488 arg->bw_160 = true; 2489 2490 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_320) 2491 arg->bw_320 = true; 2492 2493 arg->peer_he_caps_6ghz = le16_to_cpu(link_sta->he_6ghz_capa.capa); 2494 2495 mpdu_density = u32_get_bits(arg->peer_he_caps_6ghz, 2496 IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START); 2497 arg->peer_mpdu_density = ath12k_parse_mpdudensity(mpdu_density); 2498 2499 /* From IEEE Std 802.11ax-2021 - Section 10.12.2: An HE STA shall be capable of 2500 * receiving A-MPDU where the A-MPDU pre-EOF padding length is up to the value 2501 * indicated by the Maximum A-MPDU Length Exponent Extension field in the HE 2502 * Capabilities element and the Maximum A-MPDU Length Exponent field in HE 6 GHz 2503 * Band Capabilities element in the 6 GHz band. 2504 * 2505 * Here, we are extracting the Max A-MPDU Exponent Extension from HE caps and 2506 * factor is the Maximum A-MPDU Length Exponent from HE 6 GHZ Band capability. 2507 */ 2508 ampdu_factor = u8_get_bits(he_cap->he_cap_elem.mac_cap_info[3], 2509 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK) + 2510 u32_get_bits(arg->peer_he_caps_6ghz, 2511 IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP); 2512 2513 arg->peer_max_mpdu = (1u << (IEEE80211_HE_6GHZ_MAX_AMPDU_FACTOR + 2514 ampdu_factor)) - 1; 2515 } 2516 2517 static int ath12k_get_smps_from_capa(const struct ieee80211_sta_ht_cap *ht_cap, 2518 const struct ieee80211_he_6ghz_capa *he_6ghz_capa, 2519 int *smps) 2520 { 2521 if (ht_cap->ht_supported) 2522 *smps = u16_get_bits(ht_cap->cap, IEEE80211_HT_CAP_SM_PS); 2523 else 2524 *smps = le16_get_bits(he_6ghz_capa->capa, 2525 IEEE80211_HE_6GHZ_CAP_SM_PS); 2526 2527 if (*smps >= ARRAY_SIZE(ath12k_smps_map)) 2528 return -EINVAL; 2529 2530 return 0; 2531 } 2532 2533 static void ath12k_peer_assoc_h_smps(struct ath12k_link_sta *arsta, 2534 struct ath12k_wmi_peer_assoc_arg *arg) 2535 { 2536 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 2537 const struct ieee80211_he_6ghz_capa *he_6ghz_capa; 2538 struct ath12k_link_vif *arvif = arsta->arvif; 2539 const struct ieee80211_sta_ht_cap *ht_cap; 2540 struct ieee80211_link_sta *link_sta; 2541 struct ath12k *ar = arvif->ar; 2542 int smps; 2543 2544 link_sta = ath12k_mac_get_link_sta(arsta); 2545 if (!link_sta) { 2546 ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n", 2547 sta->addr, arsta->link_id); 2548 return; 2549 } 2550 2551 he_6ghz_capa = &link_sta->he_6ghz_capa; 2552 ht_cap = &link_sta->ht_cap; 2553 2554 if (!ht_cap->ht_supported && !he_6ghz_capa->capa) 2555 return; 2556 2557 if (ath12k_get_smps_from_capa(ht_cap, he_6ghz_capa, &smps)) 2558 return; 2559 2560 switch (smps) { 2561 case WLAN_HT_CAP_SM_PS_STATIC: 2562 arg->static_mimops_flag = true; 2563 break; 2564 case WLAN_HT_CAP_SM_PS_DYNAMIC: 2565 arg->dynamic_mimops_flag = true; 2566 break; 2567 case WLAN_HT_CAP_SM_PS_DISABLED: 2568 arg->spatial_mux_flag = true; 2569 break; 2570 default: 2571 break; 2572 } 2573 } 2574 2575 static void ath12k_peer_assoc_h_qos(struct ath12k *ar, 2576 struct ath12k_link_vif *arvif, 2577 struct ath12k_link_sta *arsta, 2578 struct ath12k_wmi_peer_assoc_arg *arg) 2579 { 2580 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 2581 2582 switch (arvif->ahvif->vdev_type) { 2583 case WMI_VDEV_TYPE_AP: 2584 if (sta->wme) { 2585 /* TODO: Check WME vs QoS */ 2586 arg->is_wme_set = true; 2587 arg->qos_flag = true; 2588 } 2589 2590 if (sta->wme && sta->uapsd_queues) { 2591 /* TODO: Check WME vs QoS */ 2592 arg->is_wme_set = true; 2593 arg->apsd_flag = true; 2594 arg->peer_rate_caps |= WMI_HOST_RC_UAPSD_FLAG; 2595 } 2596 break; 2597 case WMI_VDEV_TYPE_STA: 2598 if (sta->wme) { 2599 arg->is_wme_set = true; 2600 arg->qos_flag = true; 2601 } 2602 break; 2603 default: 2604 break; 2605 } 2606 2607 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac peer %pM qos %d\n", 2608 arsta->addr, arg->qos_flag); 2609 } 2610 2611 static int ath12k_peer_assoc_qos_ap(struct ath12k *ar, 2612 struct ath12k_link_vif *arvif, 2613 struct ath12k_link_sta *arsta) 2614 { 2615 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 2616 struct ath12k_wmi_ap_ps_arg arg; 2617 u32 max_sp; 2618 u32 uapsd; 2619 int ret; 2620 2621 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 2622 2623 arg.vdev_id = arvif->vdev_id; 2624 2625 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n", 2626 sta->uapsd_queues, sta->max_sp); 2627 2628 uapsd = 0; 2629 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) 2630 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | 2631 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN; 2632 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) 2633 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | 2634 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN; 2635 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) 2636 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | 2637 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN; 2638 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) 2639 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | 2640 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN; 2641 2642 max_sp = 0; 2643 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP) 2644 max_sp = sta->max_sp; 2645 2646 arg.param = WMI_AP_PS_PEER_PARAM_UAPSD; 2647 arg.value = uapsd; 2648 ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg); 2649 if (ret) 2650 goto err; 2651 2652 arg.param = WMI_AP_PS_PEER_PARAM_MAX_SP; 2653 arg.value = max_sp; 2654 ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg); 2655 if (ret) 2656 goto err; 2657 2658 /* TODO: revisit during testing */ 2659 arg.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE; 2660 arg.value = DISABLE_SIFS_RESPONSE_TRIGGER; 2661 ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg); 2662 if (ret) 2663 goto err; 2664 2665 arg.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD; 2666 arg.value = DISABLE_SIFS_RESPONSE_TRIGGER; 2667 ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg); 2668 if (ret) 2669 goto err; 2670 2671 return 0; 2672 2673 err: 2674 ath12k_warn(ar->ab, "failed to set ap ps peer param %d for vdev %i: %d\n", 2675 arg.param, arvif->vdev_id, ret); 2676 return ret; 2677 } 2678 2679 static bool ath12k_mac_sta_has_ofdm_only(struct ieee80211_link_sta *sta) 2680 { 2681 return sta->supp_rates[NL80211_BAND_2GHZ] >> 2682 ATH12K_MAC_FIRST_OFDM_RATE_IDX; 2683 } 2684 2685 static enum wmi_phy_mode ath12k_mac_get_phymode_vht(struct ath12k *ar, 2686 struct ieee80211_link_sta *link_sta) 2687 { 2688 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) { 2689 switch (link_sta->vht_cap.cap & 2690 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) { 2691 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ: 2692 return MODE_11AC_VHT160; 2693 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ: 2694 return MODE_11AC_VHT80_80; 2695 default: 2696 /* not sure if this is a valid case? */ 2697 return MODE_11AC_VHT160; 2698 } 2699 } 2700 2701 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) 2702 return MODE_11AC_VHT80; 2703 2704 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) 2705 return MODE_11AC_VHT40; 2706 2707 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20) 2708 return MODE_11AC_VHT20; 2709 2710 return MODE_UNKNOWN; 2711 } 2712 2713 static enum wmi_phy_mode ath12k_mac_get_phymode_he(struct ath12k *ar, 2714 struct ieee80211_link_sta *link_sta) 2715 { 2716 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) { 2717 if (link_sta->he_cap.he_cap_elem.phy_cap_info[0] & 2718 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) 2719 return MODE_11AX_HE160; 2720 else if (link_sta->he_cap.he_cap_elem.phy_cap_info[0] & 2721 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) 2722 return MODE_11AX_HE80_80; 2723 /* not sure if this is a valid case? */ 2724 return MODE_11AX_HE160; 2725 } 2726 2727 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) 2728 return MODE_11AX_HE80; 2729 2730 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) 2731 return MODE_11AX_HE40; 2732 2733 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20) 2734 return MODE_11AX_HE20; 2735 2736 return MODE_UNKNOWN; 2737 } 2738 2739 static enum wmi_phy_mode ath12k_mac_get_phymode_eht(struct ath12k *ar, 2740 struct ieee80211_link_sta *link_sta) 2741 { 2742 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_320) 2743 if (link_sta->eht_cap.eht_cap_elem.phy_cap_info[0] & 2744 IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ) 2745 return MODE_11BE_EHT320; 2746 2747 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) { 2748 if (link_sta->he_cap.he_cap_elem.phy_cap_info[0] & 2749 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) 2750 return MODE_11BE_EHT160; 2751 2752 if (link_sta->he_cap.he_cap_elem.phy_cap_info[0] & 2753 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) 2754 return MODE_11BE_EHT80_80; 2755 2756 ath12k_warn(ar->ab, "invalid EHT PHY capability info for 160 Mhz: %d\n", 2757 link_sta->he_cap.he_cap_elem.phy_cap_info[0]); 2758 2759 return MODE_11BE_EHT160; 2760 } 2761 2762 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) 2763 return MODE_11BE_EHT80; 2764 2765 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) 2766 return MODE_11BE_EHT40; 2767 2768 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20) 2769 return MODE_11BE_EHT20; 2770 2771 return MODE_UNKNOWN; 2772 } 2773 2774 static void ath12k_peer_assoc_h_phymode(struct ath12k *ar, 2775 struct ath12k_link_vif *arvif, 2776 struct ath12k_link_sta *arsta, 2777 struct ath12k_wmi_peer_assoc_arg *arg) 2778 { 2779 struct ieee80211_link_sta *link_sta; 2780 struct cfg80211_chan_def def; 2781 enum nl80211_band band; 2782 const u8 *ht_mcs_mask; 2783 const u16 *vht_mcs_mask; 2784 enum wmi_phy_mode phymode = MODE_UNKNOWN; 2785 2786 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 2787 2788 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 2789 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 2790 2791 if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) 2792 return; 2793 2794 band = def.chan->band; 2795 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; 2796 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; 2797 2798 link_sta = ath12k_mac_get_link_sta(arsta); 2799 if (!link_sta) { 2800 ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n", 2801 sta->addr, arsta->link_id); 2802 return; 2803 } 2804 2805 switch (band) { 2806 case NL80211_BAND_2GHZ: 2807 if (link_sta->eht_cap.has_eht) { 2808 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) 2809 phymode = MODE_11BE_EHT40_2G; 2810 else 2811 phymode = MODE_11BE_EHT20_2G; 2812 } else if (link_sta->he_cap.has_he) { 2813 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) 2814 phymode = MODE_11AX_HE80_2G; 2815 else if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) 2816 phymode = MODE_11AX_HE40_2G; 2817 else 2818 phymode = MODE_11AX_HE20_2G; 2819 } else if (link_sta->vht_cap.vht_supported && 2820 !ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) { 2821 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) 2822 phymode = MODE_11AC_VHT40; 2823 else 2824 phymode = MODE_11AC_VHT20; 2825 } else if (link_sta->ht_cap.ht_supported && 2826 !ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) { 2827 if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) 2828 phymode = MODE_11NG_HT40; 2829 else 2830 phymode = MODE_11NG_HT20; 2831 } else if (ath12k_mac_sta_has_ofdm_only(link_sta)) { 2832 phymode = MODE_11G; 2833 } else { 2834 phymode = MODE_11B; 2835 } 2836 break; 2837 case NL80211_BAND_5GHZ: 2838 case NL80211_BAND_6GHZ: 2839 /* Check EHT first */ 2840 if (link_sta->eht_cap.has_eht) { 2841 phymode = ath12k_mac_get_phymode_eht(ar, link_sta); 2842 } else if (link_sta->he_cap.has_he) { 2843 phymode = ath12k_mac_get_phymode_he(ar, link_sta); 2844 } else if (link_sta->vht_cap.vht_supported && 2845 !ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) { 2846 phymode = ath12k_mac_get_phymode_vht(ar, link_sta); 2847 } else if (link_sta->ht_cap.ht_supported && 2848 !ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) { 2849 if (link_sta->bandwidth >= IEEE80211_STA_RX_BW_40) 2850 phymode = MODE_11NA_HT40; 2851 else 2852 phymode = MODE_11NA_HT20; 2853 } else { 2854 phymode = MODE_11A; 2855 } 2856 break; 2857 default: 2858 break; 2859 } 2860 2861 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac peer %pM phymode %s\n", 2862 arsta->addr, ath12k_mac_phymode_str(phymode)); 2863 2864 arg->peer_phymode = phymode; 2865 WARN_ON(phymode == MODE_UNKNOWN); 2866 } 2867 2868 static void ath12k_mac_set_eht_mcs(u8 rx_tx_mcs7, u8 rx_tx_mcs9, 2869 u8 rx_tx_mcs11, u8 rx_tx_mcs13, 2870 u32 *rx_mcs, u32 *tx_mcs) 2871 { 2872 *rx_mcs = 0; 2873 u32p_replace_bits(rx_mcs, 2874 u8_get_bits(rx_tx_mcs7, IEEE80211_EHT_MCS_NSS_RX), 2875 WMI_EHT_MCS_NSS_0_7); 2876 u32p_replace_bits(rx_mcs, 2877 u8_get_bits(rx_tx_mcs9, IEEE80211_EHT_MCS_NSS_RX), 2878 WMI_EHT_MCS_NSS_8_9); 2879 u32p_replace_bits(rx_mcs, 2880 u8_get_bits(rx_tx_mcs11, IEEE80211_EHT_MCS_NSS_RX), 2881 WMI_EHT_MCS_NSS_10_11); 2882 u32p_replace_bits(rx_mcs, 2883 u8_get_bits(rx_tx_mcs13, IEEE80211_EHT_MCS_NSS_RX), 2884 WMI_EHT_MCS_NSS_12_13); 2885 2886 *tx_mcs = 0; 2887 u32p_replace_bits(tx_mcs, 2888 u8_get_bits(rx_tx_mcs7, IEEE80211_EHT_MCS_NSS_TX), 2889 WMI_EHT_MCS_NSS_0_7); 2890 u32p_replace_bits(tx_mcs, 2891 u8_get_bits(rx_tx_mcs9, IEEE80211_EHT_MCS_NSS_TX), 2892 WMI_EHT_MCS_NSS_8_9); 2893 u32p_replace_bits(tx_mcs, 2894 u8_get_bits(rx_tx_mcs11, IEEE80211_EHT_MCS_NSS_TX), 2895 WMI_EHT_MCS_NSS_10_11); 2896 u32p_replace_bits(tx_mcs, 2897 u8_get_bits(rx_tx_mcs13, IEEE80211_EHT_MCS_NSS_TX), 2898 WMI_EHT_MCS_NSS_12_13); 2899 } 2900 2901 static void ath12k_mac_set_eht_ppe_threshold(const u8 *ppe_thres, 2902 struct ath12k_wmi_ppe_threshold_arg *ppet) 2903 { 2904 u32 bit_pos = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE, val; 2905 u8 nss, ru, i; 2906 u8 ppet_bit_len_per_ru = IEEE80211_EHT_PPE_THRES_INFO_PPET_SIZE * 2; 2907 2908 ppet->numss_m1 = u8_get_bits(ppe_thres[0], IEEE80211_EHT_PPE_THRES_NSS_MASK); 2909 ppet->ru_bit_mask = u16_get_bits(get_unaligned_le16(ppe_thres), 2910 IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); 2911 2912 for (nss = 0; nss <= ppet->numss_m1; nss++) { 2913 for (ru = 0; 2914 ru < hweight16(IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); 2915 ru++) { 2916 if ((ppet->ru_bit_mask & BIT(ru)) == 0) 2917 continue; 2918 2919 val = 0; 2920 for (i = 0; i < ppet_bit_len_per_ru; i++) { 2921 val |= (((ppe_thres[bit_pos / 8] >> 2922 (bit_pos % 8)) & 0x1) << i); 2923 bit_pos++; 2924 } 2925 ppet->ppet16_ppet8_ru3_ru0[nss] |= 2926 (val << (ru * ppet_bit_len_per_ru)); 2927 } 2928 } 2929 } 2930 2931 static void ath12k_peer_assoc_h_eht(struct ath12k *ar, 2932 struct ath12k_link_vif *arvif, 2933 struct ath12k_link_sta *arsta, 2934 struct ath12k_wmi_peer_assoc_arg *arg) 2935 { 2936 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 2937 const struct ieee80211_eht_mcs_nss_supp_20mhz_only *bw_20; 2938 const struct ieee80211_eht_mcs_nss_supp_bw *bw; 2939 const struct ieee80211_sta_eht_cap *eht_cap; 2940 const struct ieee80211_sta_he_cap *he_cap; 2941 struct ieee80211_link_sta *link_sta; 2942 struct ieee80211_bss_conf *link_conf; 2943 u32 *rx_mcs, *tx_mcs; 2944 2945 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 2946 2947 link_sta = ath12k_mac_get_link_sta(arsta); 2948 if (!link_sta) { 2949 ath12k_warn(ar->ab, "unable to access link sta in peer assoc eht for sta %pM link %u\n", 2950 sta->addr, arsta->link_id); 2951 return; 2952 } 2953 2954 link_conf = ath12k_mac_get_link_bss_conf(arvif); 2955 if (!link_conf) { 2956 ath12k_warn(ar->ab, "unable to access link_conf in peer assoc eht set\n"); 2957 return; 2958 } 2959 2960 eht_cap = &link_sta->eht_cap; 2961 he_cap = &link_sta->he_cap; 2962 if (!he_cap->has_he || !eht_cap->has_eht) 2963 return; 2964 2965 arg->eht_flag = true; 2966 2967 if ((eht_cap->eht_cap_elem.phy_cap_info[5] & 2968 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) && 2969 eht_cap->eht_ppe_thres[0] != 0) 2970 ath12k_mac_set_eht_ppe_threshold(eht_cap->eht_ppe_thres, 2971 &arg->peer_eht_ppet); 2972 2973 memcpy(arg->peer_eht_cap_mac, eht_cap->eht_cap_elem.mac_cap_info, 2974 sizeof(eht_cap->eht_cap_elem.mac_cap_info)); 2975 memcpy(arg->peer_eht_cap_phy, eht_cap->eht_cap_elem.phy_cap_info, 2976 sizeof(eht_cap->eht_cap_elem.phy_cap_info)); 2977 2978 rx_mcs = arg->peer_eht_rx_mcs_set; 2979 tx_mcs = arg->peer_eht_tx_mcs_set; 2980 2981 switch (link_sta->bandwidth) { 2982 case IEEE80211_STA_RX_BW_320: 2983 bw = &eht_cap->eht_mcs_nss_supp.bw._320; 2984 ath12k_mac_set_eht_mcs(bw->rx_tx_mcs9_max_nss, 2985 bw->rx_tx_mcs9_max_nss, 2986 bw->rx_tx_mcs11_max_nss, 2987 bw->rx_tx_mcs13_max_nss, 2988 &rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_320], 2989 &tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_320]); 2990 arg->peer_eht_mcs_count++; 2991 fallthrough; 2992 case IEEE80211_STA_RX_BW_160: 2993 bw = &eht_cap->eht_mcs_nss_supp.bw._160; 2994 ath12k_mac_set_eht_mcs(bw->rx_tx_mcs9_max_nss, 2995 bw->rx_tx_mcs9_max_nss, 2996 bw->rx_tx_mcs11_max_nss, 2997 bw->rx_tx_mcs13_max_nss, 2998 &rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_160], 2999 &tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_160]); 3000 arg->peer_eht_mcs_count++; 3001 fallthrough; 3002 default: 3003 if ((he_cap->he_cap_elem.phy_cap_info[0] & 3004 (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G | 3005 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | 3006 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | 3007 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)) == 0) { 3008 bw_20 = &eht_cap->eht_mcs_nss_supp.only_20mhz; 3009 3010 ath12k_mac_set_eht_mcs(bw_20->rx_tx_mcs7_max_nss, 3011 bw_20->rx_tx_mcs9_max_nss, 3012 bw_20->rx_tx_mcs11_max_nss, 3013 bw_20->rx_tx_mcs13_max_nss, 3014 &rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80], 3015 &tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80]); 3016 } else { 3017 bw = &eht_cap->eht_mcs_nss_supp.bw._80; 3018 ath12k_mac_set_eht_mcs(bw->rx_tx_mcs9_max_nss, 3019 bw->rx_tx_mcs9_max_nss, 3020 bw->rx_tx_mcs11_max_nss, 3021 bw->rx_tx_mcs13_max_nss, 3022 &rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80], 3023 &tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80]); 3024 } 3025 3026 arg->peer_eht_mcs_count++; 3027 break; 3028 } 3029 3030 arg->punct_bitmap = ~arvif->punct_bitmap; 3031 arg->eht_disable_mcs15 = link_conf->eht_disable_mcs15; 3032 } 3033 3034 static void ath12k_peer_assoc_h_mlo(struct ath12k_link_sta *arsta, 3035 struct ath12k_wmi_peer_assoc_arg *arg) 3036 { 3037 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 3038 struct peer_assoc_mlo_params *ml = &arg->ml; 3039 struct ath12k_sta *ahsta = arsta->ahsta; 3040 struct ath12k_link_sta *arsta_p; 3041 struct ath12k_link_vif *arvif; 3042 unsigned long links; 3043 u8 link_id; 3044 int i; 3045 3046 if (!sta->mlo || ahsta->ml_peer_id == ATH12K_MLO_PEER_ID_INVALID) 3047 return; 3048 3049 ml->enabled = true; 3050 ml->assoc_link = arsta->is_assoc_link; 3051 3052 /* For now considering the primary umac based on assoc link */ 3053 ml->primary_umac = arsta->is_assoc_link; 3054 ml->peer_id_valid = true; 3055 ml->logical_link_idx_valid = true; 3056 3057 ether_addr_copy(ml->mld_addr, sta->addr); 3058 ml->logical_link_idx = arsta->link_idx; 3059 ml->ml_peer_id = ahsta->ml_peer_id; 3060 ml->ieee_link_id = arsta->link_id; 3061 ml->num_partner_links = 0; 3062 ml->eml_cap = sta->eml_cap; 3063 links = ahsta->links_map; 3064 3065 rcu_read_lock(); 3066 3067 i = 0; 3068 3069 for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { 3070 if (i >= ATH12K_WMI_MLO_MAX_LINKS) 3071 break; 3072 3073 arsta_p = rcu_dereference(ahsta->link[link_id]); 3074 arvif = rcu_dereference(ahsta->ahvif->link[link_id]); 3075 3076 if (arsta_p == arsta) 3077 continue; 3078 3079 if (!arvif->is_started) 3080 continue; 3081 3082 ml->partner_info[i].vdev_id = arvif->vdev_id; 3083 ml->partner_info[i].hw_link_id = arvif->ar->pdev->hw_link_id; 3084 ml->partner_info[i].assoc_link = arsta_p->is_assoc_link; 3085 ml->partner_info[i].primary_umac = arsta_p->is_assoc_link; 3086 ml->partner_info[i].logical_link_idx_valid = true; 3087 ml->partner_info[i].logical_link_idx = arsta_p->link_idx; 3088 ml->num_partner_links++; 3089 3090 i++; 3091 } 3092 3093 rcu_read_unlock(); 3094 } 3095 3096 static void ath12k_peer_assoc_prepare(struct ath12k *ar, 3097 struct ath12k_link_vif *arvif, 3098 struct ath12k_link_sta *arsta, 3099 struct ath12k_wmi_peer_assoc_arg *arg, 3100 bool reassoc) 3101 { 3102 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 3103 3104 memset(arg, 0, sizeof(*arg)); 3105 3106 reinit_completion(&ar->peer_assoc_done); 3107 3108 arg->peer_new_assoc = !reassoc; 3109 ath12k_peer_assoc_h_basic(ar, arvif, arsta, arg); 3110 ath12k_peer_assoc_h_crypto(ar, arvif, arsta, arg); 3111 ath12k_peer_assoc_h_rates(ar, arvif, arsta, arg); 3112 ath12k_peer_assoc_h_ht(ar, arvif, arsta, arg); 3113 ath12k_peer_assoc_h_vht(ar, arvif, arsta, arg); 3114 ath12k_peer_assoc_h_he(ar, arvif, arsta, arg); 3115 ath12k_peer_assoc_h_he_6ghz(ar, arvif, arsta, arg); 3116 ath12k_peer_assoc_h_eht(ar, arvif, arsta, arg); 3117 ath12k_peer_assoc_h_qos(ar, arvif, arsta, arg); 3118 ath12k_peer_assoc_h_phymode(ar, arvif, arsta, arg); 3119 ath12k_peer_assoc_h_smps(arsta, arg); 3120 ath12k_peer_assoc_h_mlo(arsta, arg); 3121 3122 arsta->peer_nss = arg->peer_nss; 3123 /* TODO: amsdu_disable req? */ 3124 } 3125 3126 static int ath12k_setup_peer_smps(struct ath12k *ar, struct ath12k_link_vif *arvif, 3127 const u8 *addr, 3128 const struct ieee80211_sta_ht_cap *ht_cap, 3129 const struct ieee80211_he_6ghz_capa *he_6ghz_capa) 3130 { 3131 int smps, ret = 0; 3132 3133 if (!ht_cap->ht_supported && !he_6ghz_capa) 3134 return 0; 3135 3136 ret = ath12k_get_smps_from_capa(ht_cap, he_6ghz_capa, &smps); 3137 if (ret < 0) 3138 return ret; 3139 3140 return ath12k_wmi_set_peer_param(ar, addr, arvif->vdev_id, 3141 WMI_PEER_MIMO_PS_STATE, 3142 ath12k_smps_map[smps]); 3143 } 3144 3145 static u32 ath12k_mac_ieee80211_sta_bw_to_wmi(struct ath12k *ar, 3146 struct ieee80211_link_sta *link_sta) 3147 { 3148 u32 bw; 3149 3150 switch (link_sta->bandwidth) { 3151 case IEEE80211_STA_RX_BW_20: 3152 bw = WMI_PEER_CHWIDTH_20MHZ; 3153 break; 3154 case IEEE80211_STA_RX_BW_40: 3155 bw = WMI_PEER_CHWIDTH_40MHZ; 3156 break; 3157 case IEEE80211_STA_RX_BW_80: 3158 bw = WMI_PEER_CHWIDTH_80MHZ; 3159 break; 3160 case IEEE80211_STA_RX_BW_160: 3161 bw = WMI_PEER_CHWIDTH_160MHZ; 3162 break; 3163 case IEEE80211_STA_RX_BW_320: 3164 bw = WMI_PEER_CHWIDTH_320MHZ; 3165 break; 3166 default: 3167 ath12k_warn(ar->ab, "Invalid bandwidth %d for link station %pM\n", 3168 link_sta->bandwidth, link_sta->addr); 3169 bw = WMI_PEER_CHWIDTH_20MHZ; 3170 break; 3171 } 3172 3173 return bw; 3174 } 3175 3176 static void ath12k_bss_assoc(struct ath12k *ar, 3177 struct ath12k_link_vif *arvif, 3178 struct ieee80211_bss_conf *bss_conf) 3179 { 3180 struct ath12k_vif *ahvif = arvif->ahvif; 3181 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); 3182 struct ath12k_wmi_vdev_up_params params = {}; 3183 struct ieee80211_link_sta *link_sta; 3184 u8 link_id = bss_conf->link_id; 3185 struct ath12k_link_sta *arsta; 3186 struct ieee80211_sta *ap_sta; 3187 struct ath12k_sta *ahsta; 3188 struct ath12k_peer *peer; 3189 bool is_auth = false; 3190 int ret; 3191 3192 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 3193 3194 struct ath12k_wmi_peer_assoc_arg *peer_arg __free(kfree) = 3195 kzalloc(sizeof(*peer_arg), GFP_KERNEL); 3196 if (!peer_arg) 3197 return; 3198 3199 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 3200 "mac vdev %i link id %u assoc bssid %pM aid %d\n", 3201 arvif->vdev_id, link_id, arvif->bssid, ahvif->aid); 3202 3203 rcu_read_lock(); 3204 3205 /* During ML connection, cfg.ap_addr has the MLD address. For 3206 * non-ML connection, it has the BSSID. 3207 */ 3208 ap_sta = ieee80211_find_sta(vif, vif->cfg.ap_addr); 3209 if (!ap_sta) { 3210 ath12k_warn(ar->ab, "failed to find station entry for bss %pM vdev %i\n", 3211 vif->cfg.ap_addr, arvif->vdev_id); 3212 rcu_read_unlock(); 3213 return; 3214 } 3215 3216 ahsta = ath12k_sta_to_ahsta(ap_sta); 3217 3218 arsta = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, 3219 ahsta->link[link_id]); 3220 if (WARN_ON(!arsta)) { 3221 rcu_read_unlock(); 3222 return; 3223 } 3224 3225 link_sta = ath12k_mac_get_link_sta(arsta); 3226 if (WARN_ON(!link_sta)) { 3227 rcu_read_unlock(); 3228 return; 3229 } 3230 3231 ath12k_peer_assoc_prepare(ar, arvif, arsta, peer_arg, false); 3232 3233 rcu_read_unlock(); 3234 3235 ret = ath12k_wmi_send_peer_assoc_cmd(ar, peer_arg); 3236 if (ret) { 3237 ath12k_warn(ar->ab, "failed to run peer assoc for %pM vdev %i: %d\n", 3238 bss_conf->bssid, arvif->vdev_id, ret); 3239 return; 3240 } 3241 3242 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) { 3243 ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", 3244 bss_conf->bssid, arvif->vdev_id); 3245 return; 3246 } 3247 3248 ret = ath12k_setup_peer_smps(ar, arvif, bss_conf->bssid, 3249 &link_sta->ht_cap, &link_sta->he_6ghz_capa); 3250 if (ret) { 3251 ath12k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n", 3252 arvif->vdev_id, ret); 3253 return; 3254 } 3255 3256 WARN_ON(arvif->is_up); 3257 3258 ahvif->aid = vif->cfg.aid; 3259 ether_addr_copy(arvif->bssid, bss_conf->bssid); 3260 3261 params.vdev_id = arvif->vdev_id; 3262 params.aid = ahvif->aid; 3263 params.bssid = arvif->bssid; 3264 ret = ath12k_wmi_vdev_up(ar, ¶ms); 3265 if (ret) { 3266 ath12k_warn(ar->ab, "failed to set vdev %d up: %d\n", 3267 arvif->vdev_id, ret); 3268 return; 3269 } 3270 3271 arvif->is_up = true; 3272 arvif->rekey_data.enable_offload = false; 3273 3274 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 3275 "mac vdev %d up (associated) bssid %pM aid %d\n", 3276 arvif->vdev_id, bss_conf->bssid, vif->cfg.aid); 3277 3278 spin_lock_bh(&ar->ab->base_lock); 3279 3280 peer = ath12k_peer_find(ar->ab, arvif->vdev_id, arvif->bssid); 3281 if (peer && peer->is_authorized) 3282 is_auth = true; 3283 3284 spin_unlock_bh(&ar->ab->base_lock); 3285 3286 /* Authorize BSS Peer */ 3287 if (is_auth) { 3288 ret = ath12k_wmi_set_peer_param(ar, arvif->bssid, 3289 arvif->vdev_id, 3290 WMI_PEER_AUTHORIZE, 3291 1); 3292 if (ret) 3293 ath12k_warn(ar->ab, "Unable to authorize BSS peer: %d\n", ret); 3294 } 3295 3296 ret = ath12k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id, 3297 &bss_conf->he_obss_pd); 3298 if (ret) 3299 ath12k_warn(ar->ab, "failed to set vdev %i OBSS PD parameters: %d\n", 3300 arvif->vdev_id, ret); 3301 3302 if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map) && 3303 ahvif->vdev_type == WMI_VDEV_TYPE_STA && 3304 ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) 3305 ath12k_mac_11d_scan_stop_all(ar->ab); 3306 } 3307 3308 static void ath12k_bss_disassoc(struct ath12k *ar, 3309 struct ath12k_link_vif *arvif) 3310 { 3311 int ret; 3312 3313 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 3314 3315 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n", 3316 arvif->vdev_id, arvif->bssid); 3317 3318 ret = ath12k_wmi_vdev_down(ar, arvif->vdev_id); 3319 if (ret) 3320 ath12k_warn(ar->ab, "failed to down vdev %i: %d\n", 3321 arvif->vdev_id, ret); 3322 3323 arvif->is_up = false; 3324 3325 memset(&arvif->rekey_data, 0, sizeof(arvif->rekey_data)); 3326 3327 cancel_delayed_work(&arvif->connection_loss_work); 3328 } 3329 3330 static u32 ath12k_mac_get_rate_hw_value(int bitrate) 3331 { 3332 u32 preamble; 3333 u16 hw_value; 3334 int rate; 3335 size_t i; 3336 3337 if (ath12k_mac_bitrate_is_cck(bitrate)) 3338 preamble = WMI_RATE_PREAMBLE_CCK; 3339 else 3340 preamble = WMI_RATE_PREAMBLE_OFDM; 3341 3342 for (i = 0; i < ARRAY_SIZE(ath12k_legacy_rates); i++) { 3343 if (ath12k_legacy_rates[i].bitrate != bitrate) 3344 continue; 3345 3346 hw_value = ath12k_legacy_rates[i].hw_value; 3347 rate = ATH12K_HW_RATE_CODE(hw_value, 0, preamble); 3348 3349 return rate; 3350 } 3351 3352 return -EINVAL; 3353 } 3354 3355 static void ath12k_recalculate_mgmt_rate(struct ath12k *ar, 3356 struct ath12k_link_vif *arvif, 3357 struct cfg80211_chan_def *def) 3358 { 3359 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 3360 struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); 3361 const struct ieee80211_supported_band *sband; 3362 struct ieee80211_bss_conf *bss_conf; 3363 u8 basic_rate_idx; 3364 int hw_rate_code; 3365 u32 vdev_param; 3366 u16 bitrate; 3367 int ret; 3368 3369 lockdep_assert_wiphy(hw->wiphy); 3370 3371 bss_conf = ath12k_mac_get_link_bss_conf(arvif); 3372 if (!bss_conf) { 3373 ath12k_warn(ar->ab, "unable to access bss link conf in mgmt rate calc for vif %pM link %u\n", 3374 vif->addr, arvif->link_id); 3375 return; 3376 } 3377 3378 sband = hw->wiphy->bands[def->chan->band]; 3379 if (bss_conf->basic_rates) 3380 basic_rate_idx = __ffs(bss_conf->basic_rates); 3381 else 3382 basic_rate_idx = 0; 3383 bitrate = sband->bitrates[basic_rate_idx].bitrate; 3384 3385 hw_rate_code = ath12k_mac_get_rate_hw_value(bitrate); 3386 if (hw_rate_code < 0) { 3387 ath12k_warn(ar->ab, "bitrate not supported %d\n", bitrate); 3388 return; 3389 } 3390 3391 vdev_param = WMI_VDEV_PARAM_MGMT_RATE; 3392 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param, 3393 hw_rate_code); 3394 if (ret) 3395 ath12k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret); 3396 3397 vdev_param = WMI_VDEV_PARAM_BEACON_RATE; 3398 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param, 3399 hw_rate_code); 3400 if (ret) 3401 ath12k_warn(ar->ab, "failed to set beacon tx rate %d\n", ret); 3402 } 3403 3404 static void ath12k_mac_init_arvif(struct ath12k_vif *ahvif, 3405 struct ath12k_link_vif *arvif, int link_id) 3406 { 3407 struct ath12k_hw *ah = ahvif->ah; 3408 u8 _link_id; 3409 int i; 3410 3411 lockdep_assert_wiphy(ah->hw->wiphy); 3412 3413 if (WARN_ON(!arvif)) 3414 return; 3415 3416 if (WARN_ON(link_id >= ATH12K_NUM_MAX_LINKS)) 3417 return; 3418 3419 if (link_id < 0) 3420 _link_id = 0; 3421 else 3422 _link_id = link_id; 3423 3424 arvif->ahvif = ahvif; 3425 arvif->link_id = _link_id; 3426 3427 /* Protects the datapath stats update on a per link basis */ 3428 spin_lock_init(&arvif->link_stats_lock); 3429 3430 INIT_LIST_HEAD(&arvif->list); 3431 INIT_DELAYED_WORK(&arvif->connection_loss_work, 3432 ath12k_mac_vif_sta_connection_loss_work); 3433 3434 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) { 3435 arvif->bitrate_mask.control[i].legacy = 0xffffffff; 3436 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff, 3437 sizeof(arvif->bitrate_mask.control[i].ht_mcs)); 3438 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff, 3439 sizeof(arvif->bitrate_mask.control[i].vht_mcs)); 3440 } 3441 3442 /* Handle MLO related assignments */ 3443 if (link_id >= 0) { 3444 rcu_assign_pointer(ahvif->link[arvif->link_id], arvif); 3445 ahvif->links_map |= BIT(_link_id); 3446 } 3447 3448 ath12k_generic_dbg(ATH12K_DBG_MAC, 3449 "mac init link arvif (link_id %d%s) for vif %pM. links_map 0x%x", 3450 _link_id, (link_id < 0) ? " deflink" : "", ahvif->vif->addr, 3451 ahvif->links_map); 3452 } 3453 3454 static void ath12k_mac_remove_link_interface(struct ieee80211_hw *hw, 3455 struct ath12k_link_vif *arvif) 3456 { 3457 struct ath12k_vif *ahvif = arvif->ahvif; 3458 struct ath12k_hw *ah = hw->priv; 3459 struct ath12k *ar = arvif->ar; 3460 int ret; 3461 3462 lockdep_assert_wiphy(ah->hw->wiphy); 3463 3464 cancel_delayed_work_sync(&arvif->connection_loss_work); 3465 3466 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac remove link interface (vdev %d link id %d)", 3467 arvif->vdev_id, arvif->link_id); 3468 3469 if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map) && 3470 ahvif->vdev_type == WMI_VDEV_TYPE_STA && 3471 ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) 3472 ath12k_mac_11d_scan_stop(ar); 3473 3474 if (ahvif->vdev_type == WMI_VDEV_TYPE_AP) { 3475 ret = ath12k_peer_delete(ar, arvif->vdev_id, arvif->bssid); 3476 if (ret) 3477 ath12k_warn(ar->ab, "failed to submit AP self-peer removal on vdev %d link id %d: %d", 3478 arvif->vdev_id, arvif->link_id, ret); 3479 } 3480 ath12k_mac_vdev_delete(ar, arvif); 3481 } 3482 3483 static struct ath12k_link_vif *ath12k_mac_assign_link_vif(struct ath12k_hw *ah, 3484 struct ieee80211_vif *vif, 3485 u8 link_id) 3486 { 3487 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 3488 struct ath12k_link_vif *arvif; 3489 3490 lockdep_assert_wiphy(ah->hw->wiphy); 3491 3492 arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); 3493 if (arvif) 3494 return arvif; 3495 3496 /* If this is the first link arvif being created for an ML VIF 3497 * use the preallocated deflink memory except for scan arvifs 3498 */ 3499 if (!ahvif->links_map && link_id != ATH12K_DEFAULT_SCAN_LINK) { 3500 arvif = &ahvif->deflink; 3501 3502 if (vif->type == NL80211_IFTYPE_STATION) 3503 arvif->is_sta_assoc_link = true; 3504 } else { 3505 arvif = kzalloc(sizeof(*arvif), GFP_KERNEL); 3506 if (!arvif) 3507 return NULL; 3508 } 3509 3510 ath12k_mac_init_arvif(ahvif, arvif, link_id); 3511 3512 return arvif; 3513 } 3514 3515 static void ath12k_mac_unassign_link_vif(struct ath12k_link_vif *arvif) 3516 { 3517 struct ath12k_vif *ahvif = arvif->ahvif; 3518 struct ath12k_hw *ah = ahvif->ah; 3519 3520 lockdep_assert_wiphy(ah->hw->wiphy); 3521 3522 rcu_assign_pointer(ahvif->link[arvif->link_id], NULL); 3523 synchronize_rcu(); 3524 ahvif->links_map &= ~BIT(arvif->link_id); 3525 3526 if (arvif != &ahvif->deflink) 3527 kfree(arvif); 3528 else 3529 memset(arvif, 0, sizeof(*arvif)); 3530 } 3531 3532 static int 3533 ath12k_mac_op_change_vif_links(struct ieee80211_hw *hw, 3534 struct ieee80211_vif *vif, 3535 u16 old_links, u16 new_links, 3536 struct ieee80211_bss_conf *ol[IEEE80211_MLD_MAX_NUM_LINKS]) 3537 { 3538 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 3539 unsigned long to_remove = old_links & ~new_links; 3540 unsigned long to_add = ~old_links & new_links; 3541 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 3542 struct ath12k_link_vif *arvif; 3543 u8 link_id; 3544 3545 lockdep_assert_wiphy(hw->wiphy); 3546 3547 ath12k_generic_dbg(ATH12K_DBG_MAC, 3548 "mac vif link changed for MLD %pM old_links 0x%x new_links 0x%x\n", 3549 vif->addr, old_links, new_links); 3550 3551 for_each_set_bit(link_id, &to_add, IEEE80211_MLD_MAX_NUM_LINKS) { 3552 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 3553 /* mac80211 wants to add link but driver already has the 3554 * link. This should not happen ideally. 3555 */ 3556 if (WARN_ON(arvif)) 3557 return -EINVAL; 3558 3559 arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); 3560 if (WARN_ON(!arvif)) 3561 return -EINVAL; 3562 } 3563 3564 for_each_set_bit(link_id, &to_remove, IEEE80211_MLD_MAX_NUM_LINKS) { 3565 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 3566 if (WARN_ON(!arvif)) 3567 return -EINVAL; 3568 3569 if (!arvif->is_created) 3570 continue; 3571 3572 if (WARN_ON(!arvif->ar)) 3573 return -EINVAL; 3574 3575 ath12k_mac_remove_link_interface(hw, arvif); 3576 ath12k_mac_unassign_link_vif(arvif); 3577 } 3578 3579 return 0; 3580 } 3581 3582 static int ath12k_mac_fils_discovery(struct ath12k_link_vif *arvif, 3583 struct ieee80211_bss_conf *info) 3584 { 3585 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 3586 struct ath12k *ar = arvif->ar; 3587 struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); 3588 struct sk_buff *tmpl; 3589 int ret; 3590 u32 interval; 3591 bool unsol_bcast_probe_resp_enabled = false; 3592 3593 if (info->fils_discovery.max_interval) { 3594 interval = info->fils_discovery.max_interval; 3595 3596 tmpl = ieee80211_get_fils_discovery_tmpl(hw, vif); 3597 if (tmpl) 3598 ret = ath12k_wmi_fils_discovery_tmpl(ar, arvif->vdev_id, 3599 tmpl); 3600 } else if (info->unsol_bcast_probe_resp_interval) { 3601 unsol_bcast_probe_resp_enabled = 1; 3602 interval = info->unsol_bcast_probe_resp_interval; 3603 3604 tmpl = ieee80211_get_unsol_bcast_probe_resp_tmpl(hw, vif); 3605 if (tmpl) 3606 ret = ath12k_wmi_probe_resp_tmpl(ar, arvif->vdev_id, 3607 tmpl); 3608 } else { /* Disable */ 3609 return ath12k_wmi_fils_discovery(ar, arvif->vdev_id, 0, false); 3610 } 3611 3612 if (!tmpl) { 3613 ath12k_warn(ar->ab, 3614 "mac vdev %i failed to retrieve %s template\n", 3615 arvif->vdev_id, (unsol_bcast_probe_resp_enabled ? 3616 "unsolicited broadcast probe response" : 3617 "FILS discovery")); 3618 return -EPERM; 3619 } 3620 kfree_skb(tmpl); 3621 3622 if (!ret) 3623 ret = ath12k_wmi_fils_discovery(ar, arvif->vdev_id, interval, 3624 unsol_bcast_probe_resp_enabled); 3625 3626 return ret; 3627 } 3628 3629 static void ath12k_mac_op_vif_cfg_changed(struct ieee80211_hw *hw, 3630 struct ieee80211_vif *vif, 3631 u64 changed) 3632 { 3633 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 3634 unsigned long links = ahvif->links_map; 3635 struct ieee80211_bss_conf *info; 3636 struct ath12k_link_vif *arvif; 3637 struct ieee80211_sta *sta; 3638 struct ath12k_sta *ahsta; 3639 struct ath12k *ar; 3640 u8 link_id; 3641 3642 lockdep_assert_wiphy(hw->wiphy); 3643 3644 if (changed & BSS_CHANGED_SSID && vif->type == NL80211_IFTYPE_AP) { 3645 ahvif->u.ap.ssid_len = vif->cfg.ssid_len; 3646 if (vif->cfg.ssid_len) 3647 memcpy(ahvif->u.ap.ssid, vif->cfg.ssid, vif->cfg.ssid_len); 3648 } 3649 3650 if (changed & BSS_CHANGED_ASSOC) { 3651 if (vif->cfg.assoc) { 3652 /* only in station mode we can get here, so it's safe 3653 * to use ap_addr 3654 */ 3655 rcu_read_lock(); 3656 sta = ieee80211_find_sta(vif, vif->cfg.ap_addr); 3657 if (!sta) { 3658 rcu_read_unlock(); 3659 WARN_ONCE(1, "failed to find sta with addr %pM\n", 3660 vif->cfg.ap_addr); 3661 return; 3662 } 3663 3664 ahsta = ath12k_sta_to_ahsta(sta); 3665 arvif = wiphy_dereference(hw->wiphy, 3666 ahvif->link[ahsta->assoc_link_id]); 3667 rcu_read_unlock(); 3668 3669 ar = arvif->ar; 3670 /* there is no reason for which an assoc link's 3671 * bss info does not exist 3672 */ 3673 info = ath12k_mac_get_link_bss_conf(arvif); 3674 ath12k_bss_assoc(ar, arvif, info); 3675 3676 /* exclude assoc link as it is done above */ 3677 links &= ~BIT(ahsta->assoc_link_id); 3678 } 3679 3680 for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { 3681 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 3682 if (!arvif || !arvif->ar) 3683 continue; 3684 3685 ar = arvif->ar; 3686 3687 if (vif->cfg.assoc) { 3688 info = ath12k_mac_get_link_bss_conf(arvif); 3689 if (!info) 3690 continue; 3691 3692 ath12k_bss_assoc(ar, arvif, info); 3693 } else { 3694 ath12k_bss_disassoc(ar, arvif); 3695 } 3696 } 3697 } 3698 } 3699 3700 static void ath12k_mac_vif_setup_ps(struct ath12k_link_vif *arvif) 3701 { 3702 struct ath12k *ar = arvif->ar; 3703 struct ieee80211_vif *vif = arvif->ahvif->vif; 3704 struct ieee80211_conf *conf = &ath12k_ar_to_hw(ar)->conf; 3705 enum wmi_sta_powersave_param param; 3706 struct ieee80211_bss_conf *info; 3707 enum wmi_sta_ps_mode psmode; 3708 int ret; 3709 int timeout; 3710 bool enable_ps; 3711 3712 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 3713 3714 if (vif->type != NL80211_IFTYPE_STATION) 3715 return; 3716 3717 enable_ps = arvif->ahvif->ps; 3718 if (enable_ps) { 3719 psmode = WMI_STA_PS_MODE_ENABLED; 3720 param = WMI_STA_PS_PARAM_INACTIVITY_TIME; 3721 3722 timeout = conf->dynamic_ps_timeout; 3723 if (timeout == 0) { 3724 info = ath12k_mac_get_link_bss_conf(arvif); 3725 if (!info) { 3726 ath12k_warn(ar->ab, "unable to access bss link conf in setup ps for vif %pM link %u\n", 3727 vif->addr, arvif->link_id); 3728 return; 3729 } 3730 3731 /* firmware doesn't like 0 */ 3732 timeout = ieee80211_tu_to_usec(info->beacon_int) / 1000; 3733 } 3734 3735 ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, 3736 timeout); 3737 if (ret) { 3738 ath12k_warn(ar->ab, "failed to set inactivity time for vdev %d: %i\n", 3739 arvif->vdev_id, ret); 3740 return; 3741 } 3742 } else { 3743 psmode = WMI_STA_PS_MODE_DISABLED; 3744 } 3745 3746 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d psmode %s\n", 3747 arvif->vdev_id, psmode ? "enable" : "disable"); 3748 3749 ret = ath12k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, psmode); 3750 if (ret) 3751 ath12k_warn(ar->ab, "failed to set sta power save mode %d for vdev %d: %d\n", 3752 psmode, arvif->vdev_id, ret); 3753 } 3754 3755 static bool ath12k_mac_supports_station_tpc(struct ath12k *ar, 3756 struct ath12k_vif *ahvif, 3757 const struct cfg80211_chan_def *chandef) 3758 { 3759 return ath12k_wmi_supports_6ghz_cc_ext(ar) && 3760 test_bit(WMI_TLV_SERVICE_EXT_TPC_REG_SUPPORT, ar->ab->wmi_ab.svc_map) && 3761 ahvif->vdev_type == WMI_VDEV_TYPE_STA && 3762 ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE && 3763 chandef->chan && 3764 chandef->chan->band == NL80211_BAND_6GHZ; 3765 } 3766 3767 static void ath12k_mac_bss_info_changed(struct ath12k *ar, 3768 struct ath12k_link_vif *arvif, 3769 struct ieee80211_bss_conf *info, 3770 u64 changed) 3771 { 3772 struct ath12k_vif *ahvif = arvif->ahvif; 3773 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); 3774 struct ieee80211_vif_cfg *vif_cfg = &vif->cfg; 3775 struct cfg80211_chan_def def; 3776 u32 param_id, param_value; 3777 enum nl80211_band band; 3778 u32 vdev_param; 3779 int mcast_rate; 3780 u32 preamble; 3781 u16 hw_value; 3782 u16 bitrate; 3783 int ret; 3784 u8 rateidx; 3785 u32 rate; 3786 3787 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 3788 3789 if (changed & BSS_CHANGED_BEACON_INT) { 3790 arvif->beacon_interval = info->beacon_int; 3791 3792 param_id = WMI_VDEV_PARAM_BEACON_INTERVAL; 3793 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 3794 param_id, 3795 arvif->beacon_interval); 3796 if (ret) 3797 ath12k_warn(ar->ab, "Failed to set beacon interval for VDEV: %d\n", 3798 arvif->vdev_id); 3799 else 3800 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 3801 "Beacon interval: %d set for VDEV: %d\n", 3802 arvif->beacon_interval, arvif->vdev_id); 3803 } 3804 3805 if (changed & BSS_CHANGED_BEACON) { 3806 param_id = WMI_PDEV_PARAM_BEACON_TX_MODE; 3807 param_value = WMI_BEACON_BURST_MODE; 3808 ret = ath12k_wmi_pdev_set_param(ar, param_id, 3809 param_value, ar->pdev->pdev_id); 3810 if (ret) 3811 ath12k_warn(ar->ab, "Failed to set beacon mode for VDEV: %d\n", 3812 arvif->vdev_id); 3813 else 3814 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 3815 "Set burst beacon mode for VDEV: %d\n", 3816 arvif->vdev_id); 3817 3818 ret = ath12k_mac_setup_bcn_tmpl(arvif); 3819 if (ret) 3820 ath12k_warn(ar->ab, "failed to update bcn template: %d\n", 3821 ret); 3822 } 3823 3824 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) { 3825 arvif->dtim_period = info->dtim_period; 3826 3827 param_id = WMI_VDEV_PARAM_DTIM_PERIOD; 3828 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 3829 param_id, 3830 arvif->dtim_period); 3831 3832 if (ret) 3833 ath12k_warn(ar->ab, "Failed to set dtim period for VDEV %d: %i\n", 3834 arvif->vdev_id, ret); 3835 else 3836 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 3837 "DTIM period: %d set for VDEV: %d\n", 3838 arvif->dtim_period, arvif->vdev_id); 3839 } 3840 3841 if (changed & BSS_CHANGED_SSID && 3842 vif->type == NL80211_IFTYPE_AP) { 3843 ahvif->u.ap.ssid_len = vif->cfg.ssid_len; 3844 if (vif->cfg.ssid_len) 3845 memcpy(ahvif->u.ap.ssid, vif->cfg.ssid, vif->cfg.ssid_len); 3846 ahvif->u.ap.hidden_ssid = info->hidden_ssid; 3847 } 3848 3849 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) 3850 ether_addr_copy(arvif->bssid, info->bssid); 3851 3852 if (changed & BSS_CHANGED_BEACON_ENABLED) { 3853 ath12k_control_beaconing(arvif, info); 3854 3855 if (arvif->is_up && info->he_support && 3856 info->he_oper.params) { 3857 /* TODO: Extend to support 1024 BA Bitmap size */ 3858 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 3859 WMI_VDEV_PARAM_BA_MODE, 3860 WMI_BA_MODE_BUFFER_SIZE_256); 3861 if (ret) 3862 ath12k_warn(ar->ab, 3863 "failed to set BA BUFFER SIZE 256 for vdev: %d\n", 3864 arvif->vdev_id); 3865 3866 param_id = WMI_VDEV_PARAM_HEOPS_0_31; 3867 param_value = info->he_oper.params; 3868 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 3869 param_id, param_value); 3870 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 3871 "he oper param: %x set for VDEV: %d\n", 3872 param_value, arvif->vdev_id); 3873 3874 if (ret) 3875 ath12k_warn(ar->ab, "Failed to set he oper params %x for VDEV %d: %i\n", 3876 param_value, arvif->vdev_id, ret); 3877 } 3878 } 3879 3880 if (changed & BSS_CHANGED_ERP_CTS_PROT) { 3881 u32 cts_prot; 3882 3883 cts_prot = !!(info->use_cts_prot); 3884 param_id = WMI_VDEV_PARAM_PROTECTION_MODE; 3885 3886 if (arvif->is_started) { 3887 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 3888 param_id, cts_prot); 3889 if (ret) 3890 ath12k_warn(ar->ab, "Failed to set CTS prot for VDEV: %d\n", 3891 arvif->vdev_id); 3892 else 3893 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "Set CTS prot: %d for VDEV: %d\n", 3894 cts_prot, arvif->vdev_id); 3895 } else { 3896 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "defer protection mode setup, vdev is not ready yet\n"); 3897 } 3898 } 3899 3900 if (changed & BSS_CHANGED_ERP_SLOT) { 3901 u32 slottime; 3902 3903 if (info->use_short_slot) 3904 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ 3905 3906 else 3907 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ 3908 3909 param_id = WMI_VDEV_PARAM_SLOT_TIME; 3910 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 3911 param_id, slottime); 3912 if (ret) 3913 ath12k_warn(ar->ab, "Failed to set erp slot for VDEV: %d\n", 3914 arvif->vdev_id); 3915 else 3916 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 3917 "Set slottime: %d for VDEV: %d\n", 3918 slottime, arvif->vdev_id); 3919 } 3920 3921 if (changed & BSS_CHANGED_ERP_PREAMBLE) { 3922 u32 preamble; 3923 3924 if (info->use_short_preamble) 3925 preamble = WMI_VDEV_PREAMBLE_SHORT; 3926 else 3927 preamble = WMI_VDEV_PREAMBLE_LONG; 3928 3929 param_id = WMI_VDEV_PARAM_PREAMBLE; 3930 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 3931 param_id, preamble); 3932 if (ret) 3933 ath12k_warn(ar->ab, "Failed to set preamble for VDEV: %d\n", 3934 arvif->vdev_id); 3935 else 3936 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 3937 "Set preamble: %d for VDEV: %d\n", 3938 preamble, arvif->vdev_id); 3939 } 3940 3941 if (changed & BSS_CHANGED_ASSOC) { 3942 if (vif->cfg.assoc) 3943 ath12k_bss_assoc(ar, arvif, info); 3944 else 3945 ath12k_bss_disassoc(ar, arvif); 3946 } 3947 3948 if (changed & BSS_CHANGED_TXPOWER) { 3949 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev_id %i txpower %d\n", 3950 arvif->vdev_id, info->txpower); 3951 3952 arvif->txpower = info->txpower; 3953 ath12k_mac_txpower_recalc(ar); 3954 } 3955 3956 if (changed & BSS_CHANGED_MCAST_RATE && 3957 !ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)) { 3958 band = def.chan->band; 3959 mcast_rate = info->mcast_rate[band]; 3960 3961 if (mcast_rate > 0) { 3962 rateidx = mcast_rate - 1; 3963 } else { 3964 if (info->basic_rates) 3965 rateidx = __ffs(info->basic_rates); 3966 else 3967 rateidx = 0; 3968 } 3969 3970 if (ar->pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP) 3971 rateidx += ATH12K_MAC_FIRST_OFDM_RATE_IDX; 3972 3973 bitrate = ath12k_legacy_rates[rateidx].bitrate; 3974 hw_value = ath12k_legacy_rates[rateidx].hw_value; 3975 3976 if (ath12k_mac_bitrate_is_cck(bitrate)) 3977 preamble = WMI_RATE_PREAMBLE_CCK; 3978 else 3979 preamble = WMI_RATE_PREAMBLE_OFDM; 3980 3981 rate = ATH12K_HW_RATE_CODE(hw_value, 0, preamble); 3982 3983 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 3984 "mac vdev %d mcast_rate %x\n", 3985 arvif->vdev_id, rate); 3986 3987 vdev_param = WMI_VDEV_PARAM_MCAST_DATA_RATE; 3988 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 3989 vdev_param, rate); 3990 if (ret) 3991 ath12k_warn(ar->ab, 3992 "failed to set mcast rate on vdev %i: %d\n", 3993 arvif->vdev_id, ret); 3994 3995 vdev_param = WMI_VDEV_PARAM_BCAST_DATA_RATE; 3996 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 3997 vdev_param, rate); 3998 if (ret) 3999 ath12k_warn(ar->ab, 4000 "failed to set bcast rate on vdev %i: %d\n", 4001 arvif->vdev_id, ret); 4002 } 4003 4004 if (changed & BSS_CHANGED_BASIC_RATES && 4005 !ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)) 4006 ath12k_recalculate_mgmt_rate(ar, arvif, &def); 4007 4008 if (changed & BSS_CHANGED_TWT) { 4009 if (info->twt_requester || info->twt_responder) 4010 ath12k_wmi_send_twt_enable_cmd(ar, ar->pdev->pdev_id); 4011 else 4012 ath12k_wmi_send_twt_disable_cmd(ar, ar->pdev->pdev_id); 4013 } 4014 4015 if (changed & BSS_CHANGED_HE_OBSS_PD) 4016 ath12k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id, 4017 &info->he_obss_pd); 4018 4019 if (changed & BSS_CHANGED_HE_BSS_COLOR) { 4020 if (vif->type == NL80211_IFTYPE_AP) { 4021 ret = ath12k_wmi_obss_color_cfg_cmd(ar, 4022 arvif->vdev_id, 4023 info->he_bss_color.color, 4024 ATH12K_BSS_COLOR_AP_PERIODS, 4025 info->he_bss_color.enabled); 4026 if (ret) 4027 ath12k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n", 4028 arvif->vdev_id, ret); 4029 } else if (vif->type == NL80211_IFTYPE_STATION) { 4030 ret = ath12k_wmi_send_bss_color_change_enable_cmd(ar, 4031 arvif->vdev_id, 4032 1); 4033 if (ret) 4034 ath12k_warn(ar->ab, "failed to enable bss color change on vdev %i: %d\n", 4035 arvif->vdev_id, ret); 4036 ret = ath12k_wmi_obss_color_cfg_cmd(ar, 4037 arvif->vdev_id, 4038 0, 4039 ATH12K_BSS_COLOR_STA_PERIODS, 4040 1); 4041 if (ret) 4042 ath12k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n", 4043 arvif->vdev_id, ret); 4044 } 4045 } 4046 4047 ath12k_mac_fils_discovery(arvif, info); 4048 4049 if (changed & BSS_CHANGED_PS && 4050 ar->ab->hw_params->supports_sta_ps) { 4051 ahvif->ps = vif_cfg->ps; 4052 ath12k_mac_vif_setup_ps(arvif); 4053 } 4054 } 4055 4056 static struct ath12k_vif_cache *ath12k_ahvif_get_link_cache(struct ath12k_vif *ahvif, 4057 u8 link_id) 4058 { 4059 if (!ahvif->cache[link_id]) { 4060 ahvif->cache[link_id] = kzalloc(sizeof(*ahvif->cache[0]), GFP_KERNEL); 4061 if (ahvif->cache[link_id]) 4062 INIT_LIST_HEAD(&ahvif->cache[link_id]->key_conf.list); 4063 } 4064 4065 return ahvif->cache[link_id]; 4066 } 4067 4068 static void ath12k_ahvif_put_link_key_cache(struct ath12k_vif_cache *cache) 4069 { 4070 struct ath12k_key_conf *key_conf, *tmp; 4071 4072 if (!cache || list_empty(&cache->key_conf.list)) 4073 return; 4074 list_for_each_entry_safe(key_conf, tmp, &cache->key_conf.list, list) { 4075 list_del(&key_conf->list); 4076 kfree(key_conf); 4077 } 4078 } 4079 4080 static void ath12k_ahvif_put_link_cache(struct ath12k_vif *ahvif, u8 link_id) 4081 { 4082 if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) 4083 return; 4084 4085 ath12k_ahvif_put_link_key_cache(ahvif->cache[link_id]); 4086 kfree(ahvif->cache[link_id]); 4087 ahvif->cache[link_id] = NULL; 4088 } 4089 4090 static void ath12k_mac_op_link_info_changed(struct ieee80211_hw *hw, 4091 struct ieee80211_vif *vif, 4092 struct ieee80211_bss_conf *info, 4093 u64 changed) 4094 { 4095 struct ath12k *ar; 4096 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 4097 struct ath12k_vif_cache *cache; 4098 struct ath12k_link_vif *arvif; 4099 u8 link_id = info->link_id; 4100 4101 lockdep_assert_wiphy(hw->wiphy); 4102 4103 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 4104 4105 /* if the vdev is not created on a certain radio, 4106 * cache the info to be updated later on vdev creation 4107 */ 4108 4109 if (!arvif || !arvif->is_created) { 4110 cache = ath12k_ahvif_get_link_cache(ahvif, link_id); 4111 if (!cache) 4112 return; 4113 4114 cache->bss_conf_changed |= changed; 4115 4116 return; 4117 } 4118 4119 ar = arvif->ar; 4120 4121 ath12k_mac_bss_info_changed(ar, arvif, info, changed); 4122 } 4123 4124 static struct ath12k* 4125 ath12k_mac_select_scan_device(struct ieee80211_hw *hw, 4126 struct ieee80211_vif *vif, 4127 u32 center_freq) 4128 { 4129 struct ath12k_hw *ah = hw->priv; 4130 enum nl80211_band band; 4131 struct ath12k *ar; 4132 int i; 4133 4134 if (ah->num_radio == 1) 4135 return ah->radio; 4136 4137 /* Currently mac80211 supports splitting scan requests into 4138 * multiple scan requests per band. 4139 * Loop through first channel and determine the scan radio 4140 * TODO: There could be 5 GHz low/high channels in that case 4141 * split the hw request and perform multiple scans 4142 */ 4143 4144 if (center_freq < ATH12K_MIN_5GHZ_FREQ) 4145 band = NL80211_BAND_2GHZ; 4146 else if (center_freq < ATH12K_MIN_6GHZ_FREQ) 4147 band = NL80211_BAND_5GHZ; 4148 else 4149 band = NL80211_BAND_6GHZ; 4150 4151 for_each_ar(ah, ar, i) { 4152 /* TODO 5 GHz low high split changes */ 4153 if (ar->mac.sbands[band].channels) 4154 return ar; 4155 } 4156 4157 return NULL; 4158 } 4159 4160 void __ath12k_mac_scan_finish(struct ath12k *ar) 4161 { 4162 struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); 4163 4164 lockdep_assert_held(&ar->data_lock); 4165 4166 switch (ar->scan.state) { 4167 case ATH12K_SCAN_IDLE: 4168 break; 4169 case ATH12K_SCAN_RUNNING: 4170 case ATH12K_SCAN_ABORTING: 4171 if (ar->scan.is_roc && ar->scan.roc_notify) 4172 ieee80211_remain_on_channel_expired(hw); 4173 fallthrough; 4174 case ATH12K_SCAN_STARTING: 4175 cancel_delayed_work(&ar->scan.timeout); 4176 complete_all(&ar->scan.completed); 4177 wiphy_work_queue(ar->ah->hw->wiphy, &ar->scan.vdev_clean_wk); 4178 break; 4179 } 4180 } 4181 4182 void ath12k_mac_scan_finish(struct ath12k *ar) 4183 { 4184 spin_lock_bh(&ar->data_lock); 4185 __ath12k_mac_scan_finish(ar); 4186 spin_unlock_bh(&ar->data_lock); 4187 } 4188 4189 static int ath12k_scan_stop(struct ath12k *ar) 4190 { 4191 struct ath12k_wmi_scan_cancel_arg arg = { 4192 .req_type = WLAN_SCAN_CANCEL_SINGLE, 4193 .scan_id = ATH12K_SCAN_ID, 4194 }; 4195 int ret; 4196 4197 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 4198 4199 /* TODO: Fill other STOP Params */ 4200 arg.pdev_id = ar->pdev->pdev_id; 4201 4202 ret = ath12k_wmi_send_scan_stop_cmd(ar, &arg); 4203 if (ret) { 4204 ath12k_warn(ar->ab, "failed to stop wmi scan: %d\n", ret); 4205 goto out; 4206 } 4207 4208 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ); 4209 if (ret == 0) { 4210 ath12k_warn(ar->ab, 4211 "failed to receive scan abort comple: timed out\n"); 4212 ret = -ETIMEDOUT; 4213 } else if (ret > 0) { 4214 ret = 0; 4215 } 4216 4217 out: 4218 /* Scan state should be updated in scan completion worker but in 4219 * case firmware fails to deliver the event (for whatever reason) 4220 * it is desired to clean up scan state anyway. Firmware may have 4221 * just dropped the scan completion event delivery due to transport 4222 * pipe being overflown with data and/or it can recover on its own 4223 * before next scan request is submitted. 4224 */ 4225 spin_lock_bh(&ar->data_lock); 4226 if (ret) 4227 __ath12k_mac_scan_finish(ar); 4228 spin_unlock_bh(&ar->data_lock); 4229 4230 return ret; 4231 } 4232 4233 static void ath12k_scan_abort(struct ath12k *ar) 4234 { 4235 int ret; 4236 4237 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 4238 4239 spin_lock_bh(&ar->data_lock); 4240 4241 switch (ar->scan.state) { 4242 case ATH12K_SCAN_IDLE: 4243 /* This can happen if timeout worker kicked in and called 4244 * abortion while scan completion was being processed. 4245 */ 4246 break; 4247 case ATH12K_SCAN_STARTING: 4248 case ATH12K_SCAN_ABORTING: 4249 ath12k_warn(ar->ab, "refusing scan abortion due to invalid scan state: %d\n", 4250 ar->scan.state); 4251 break; 4252 case ATH12K_SCAN_RUNNING: 4253 ar->scan.state = ATH12K_SCAN_ABORTING; 4254 spin_unlock_bh(&ar->data_lock); 4255 4256 ret = ath12k_scan_stop(ar); 4257 if (ret) 4258 ath12k_warn(ar->ab, "failed to abort scan: %d\n", ret); 4259 4260 spin_lock_bh(&ar->data_lock); 4261 break; 4262 } 4263 4264 spin_unlock_bh(&ar->data_lock); 4265 } 4266 4267 static void ath12k_scan_timeout_work(struct work_struct *work) 4268 { 4269 struct ath12k *ar = container_of(work, struct ath12k, 4270 scan.timeout.work); 4271 4272 wiphy_lock(ath12k_ar_to_hw(ar)->wiphy); 4273 ath12k_scan_abort(ar); 4274 wiphy_unlock(ath12k_ar_to_hw(ar)->wiphy); 4275 } 4276 4277 static void ath12k_scan_vdev_clean_work(struct wiphy *wiphy, struct wiphy_work *work) 4278 { 4279 struct ath12k *ar = container_of(work, struct ath12k, 4280 scan.vdev_clean_wk); 4281 struct ath12k_hw *ah = ar->ah; 4282 struct ath12k_link_vif *arvif; 4283 4284 lockdep_assert_wiphy(wiphy); 4285 4286 arvif = ar->scan.arvif; 4287 4288 /* The scan vdev has already been deleted. This can occur when a 4289 * new scan request is made on the same vif with a different 4290 * frequency, causing the scan arvif to move from one radio to 4291 * another. Or, scan was abrupted and via remove interface, the 4292 * arvif is already deleted. Alternatively, if the scan vdev is not 4293 * being used as an actual vdev, then do not delete it. 4294 */ 4295 if (!arvif || arvif->is_started) 4296 goto work_complete; 4297 4298 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac clean scan vdev (link id %u)", 4299 arvif->link_id); 4300 4301 ath12k_mac_remove_link_interface(ah->hw, arvif); 4302 ath12k_mac_unassign_link_vif(arvif); 4303 4304 work_complete: 4305 spin_lock_bh(&ar->data_lock); 4306 ar->scan.arvif = NULL; 4307 if (!ar->scan.is_roc) { 4308 struct cfg80211_scan_info info = { 4309 .aborted = ((ar->scan.state == 4310 ATH12K_SCAN_ABORTING) || 4311 (ar->scan.state == 4312 ATH12K_SCAN_STARTING)), 4313 }; 4314 4315 ieee80211_scan_completed(ar->ah->hw, &info); 4316 } 4317 4318 ar->scan.state = ATH12K_SCAN_IDLE; 4319 ar->scan_channel = NULL; 4320 ar->scan.roc_freq = 0; 4321 spin_unlock_bh(&ar->data_lock); 4322 } 4323 4324 static int ath12k_start_scan(struct ath12k *ar, 4325 struct ath12k_wmi_scan_req_arg *arg) 4326 { 4327 int ret; 4328 4329 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 4330 4331 ret = ath12k_wmi_send_scan_start_cmd(ar, arg); 4332 if (ret) 4333 return ret; 4334 4335 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ); 4336 if (ret == 0) { 4337 ret = ath12k_scan_stop(ar); 4338 if (ret) 4339 ath12k_warn(ar->ab, "failed to stop scan: %d\n", ret); 4340 4341 return -ETIMEDOUT; 4342 } 4343 4344 /* If we failed to start the scan, return error code at 4345 * this point. This is probably due to some issue in the 4346 * firmware, but no need to wedge the driver due to that... 4347 */ 4348 spin_lock_bh(&ar->data_lock); 4349 if (ar->scan.state == ATH12K_SCAN_IDLE) { 4350 spin_unlock_bh(&ar->data_lock); 4351 return -EINVAL; 4352 } 4353 spin_unlock_bh(&ar->data_lock); 4354 4355 return 0; 4356 } 4357 4358 int ath12k_mac_get_fw_stats(struct ath12k *ar, 4359 struct ath12k_fw_stats_req_params *param) 4360 { 4361 struct ath12k_base *ab = ar->ab; 4362 struct ath12k_hw *ah = ath12k_ar_to_ah(ar); 4363 unsigned long timeout, time_left; 4364 int ret; 4365 4366 guard(mutex)(&ah->hw_mutex); 4367 4368 if (ah->state != ATH12K_HW_STATE_ON) 4369 return -ENETDOWN; 4370 4371 /* FW stats can get split when exceeding the stats data buffer limit. 4372 * In that case, since there is no end marking for the back-to-back 4373 * received 'update stats' event, we keep a 3 seconds timeout in case, 4374 * fw_stats_done is not marked yet 4375 */ 4376 timeout = jiffies + msecs_to_jiffies(3 * 1000); 4377 ath12k_fw_stats_reset(ar); 4378 4379 reinit_completion(&ar->fw_stats_complete); 4380 4381 ret = ath12k_wmi_send_stats_request_cmd(ar, param->stats_id, 4382 param->vdev_id, param->pdev_id); 4383 4384 if (ret) { 4385 ath12k_warn(ab, "failed to request fw stats: %d\n", ret); 4386 return ret; 4387 } 4388 4389 ath12k_dbg(ab, ATH12K_DBG_WMI, 4390 "get fw stat pdev id %d vdev id %d stats id 0x%x\n", 4391 param->pdev_id, param->vdev_id, param->stats_id); 4392 4393 time_left = wait_for_completion_timeout(&ar->fw_stats_complete, 1 * HZ); 4394 4395 if (!time_left) { 4396 ath12k_warn(ab, "time out while waiting for get fw stats\n"); 4397 return -ETIMEDOUT; 4398 } 4399 4400 /* Firmware sends WMI_UPDATE_STATS_EVENTID back-to-back 4401 * when stats data buffer limit is reached. fw_stats_complete 4402 * is completed once host receives first event from firmware, but 4403 * still end might not be marked in the TLV. 4404 * Below loop is to confirm that firmware completed sending all the event 4405 * and fw_stats_done is marked true when end is marked in the TLV. 4406 */ 4407 for (;;) { 4408 if (time_after(jiffies, timeout)) 4409 break; 4410 spin_lock_bh(&ar->data_lock); 4411 if (ar->fw_stats.fw_stats_done) { 4412 spin_unlock_bh(&ar->data_lock); 4413 break; 4414 } 4415 spin_unlock_bh(&ar->data_lock); 4416 } 4417 return 0; 4418 } 4419 4420 static int ath12k_mac_op_get_txpower(struct ieee80211_hw *hw, 4421 struct ieee80211_vif *vif, 4422 unsigned int link_id, 4423 int *dbm) 4424 { 4425 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 4426 struct ath12k_fw_stats_req_params params = {}; 4427 struct ath12k_fw_stats_pdev *pdev; 4428 struct ath12k_hw *ah = hw->priv; 4429 struct ath12k_link_vif *arvif; 4430 struct ath12k_base *ab; 4431 struct ath12k *ar; 4432 int ret; 4433 4434 /* Final Tx power is minimum of Target Power, CTL power, Regulatory 4435 * Power, PSD EIRP Power. We just know the Regulatory power from the 4436 * regulatory rules obtained. FW knows all these power and sets the min 4437 * of these. Hence, we request the FW pdev stats in which FW reports 4438 * the minimum of all vdev's channel Tx power. 4439 */ 4440 lockdep_assert_wiphy(hw->wiphy); 4441 4442 arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); 4443 if (!arvif || !arvif->ar) 4444 return -EINVAL; 4445 4446 ar = arvif->ar; 4447 ab = ar->ab; 4448 if (ah->state != ATH12K_HW_STATE_ON) 4449 goto err_fallback; 4450 4451 if (test_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags)) 4452 return -EAGAIN; 4453 4454 /* Limit the requests to Firmware for fetching the tx power */ 4455 if (ar->chan_tx_pwr != ATH12K_PDEV_TX_POWER_INVALID && 4456 time_before(jiffies, 4457 msecs_to_jiffies(ATH12K_PDEV_TX_POWER_REFRESH_TIME_MSECS) + 4458 ar->last_tx_power_update)) 4459 goto send_tx_power; 4460 4461 params.pdev_id = ar->pdev->pdev_id; 4462 params.vdev_id = arvif->vdev_id; 4463 params.stats_id = WMI_REQUEST_PDEV_STAT; 4464 ret = ath12k_mac_get_fw_stats(ar, ¶ms); 4465 if (ret) { 4466 ath12k_warn(ab, "failed to request fw pdev stats: %d\n", ret); 4467 goto err_fallback; 4468 } 4469 4470 spin_lock_bh(&ar->data_lock); 4471 pdev = list_first_entry_or_null(&ar->fw_stats.pdevs, 4472 struct ath12k_fw_stats_pdev, list); 4473 if (!pdev) { 4474 spin_unlock_bh(&ar->data_lock); 4475 goto err_fallback; 4476 } 4477 4478 /* tx power reported by firmware is in units of 0.5 dBm */ 4479 ar->chan_tx_pwr = pdev->chan_tx_power / 2; 4480 spin_unlock_bh(&ar->data_lock); 4481 ar->last_tx_power_update = jiffies; 4482 4483 send_tx_power: 4484 *dbm = ar->chan_tx_pwr; 4485 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower fetched from firmware %d dBm\n", 4486 *dbm); 4487 return 0; 4488 4489 err_fallback: 4490 /* We didn't get txpower from FW. Hence, relying on vif->bss_conf.txpower */ 4491 *dbm = vif->bss_conf.txpower; 4492 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower from firmware NaN, reported %d dBm\n", 4493 *dbm); 4494 return 0; 4495 } 4496 4497 static u8 4498 ath12k_mac_find_link_id_by_ar(struct ath12k_vif *ahvif, struct ath12k *ar) 4499 { 4500 struct ath12k_link_vif *arvif; 4501 struct ath12k_hw *ah = ahvif->ah; 4502 unsigned long links = ahvif->links_map; 4503 u8 link_id; 4504 4505 lockdep_assert_wiphy(ah->hw->wiphy); 4506 4507 for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { 4508 arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); 4509 4510 if (!arvif || !arvif->is_created) 4511 continue; 4512 4513 if (ar == arvif->ar) 4514 return link_id; 4515 } 4516 4517 /* input ar is not assigned to any of the links of ML VIF, use scan 4518 * link (15) for scan vdev creation. 4519 */ 4520 return ATH12K_DEFAULT_SCAN_LINK; 4521 } 4522 4523 static int ath12k_mac_op_hw_scan(struct ieee80211_hw *hw, 4524 struct ieee80211_vif *vif, 4525 struct ieee80211_scan_request *hw_req) 4526 { 4527 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 4528 struct ath12k *ar; 4529 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 4530 struct ath12k_link_vif *arvif; 4531 struct cfg80211_scan_request *req = &hw_req->req; 4532 struct ath12k_wmi_scan_req_arg *arg = NULL; 4533 u8 link_id; 4534 int ret; 4535 int i; 4536 bool create = true; 4537 4538 lockdep_assert_wiphy(hw->wiphy); 4539 4540 arvif = &ahvif->deflink; 4541 4542 /* Since the targeted scan device could depend on the frequency 4543 * requested in the hw_req, select the corresponding radio 4544 */ 4545 ar = ath12k_mac_select_scan_device(hw, vif, hw_req->req.channels[0]->center_freq); 4546 if (!ar) 4547 return -EINVAL; 4548 4549 /* check if any of the links of ML VIF is already started on 4550 * radio(ar) corresponding to given scan frequency and use it, 4551 * if not use scan link (link 15) for scan purpose. 4552 */ 4553 link_id = ath12k_mac_find_link_id_by_ar(ahvif, ar); 4554 arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); 4555 4556 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac link ID %d selected for scan", 4557 arvif->link_id); 4558 4559 /* If the vif is already assigned to a specific vdev of an ar, 4560 * check whether its already started, vdev which is started 4561 * are not allowed to switch to a new radio. 4562 * If the vdev is not started, but was earlier created on a 4563 * different ar, delete that vdev and create a new one. We don't 4564 * delete at the scan stop as an optimization to avoid redundant 4565 * delete-create vdev's for the same ar, in case the request is 4566 * always on the same band for the vif 4567 */ 4568 if (arvif->is_created) { 4569 if (WARN_ON(!arvif->ar)) 4570 return -EINVAL; 4571 4572 if (ar != arvif->ar && arvif->is_started) 4573 return -EINVAL; 4574 4575 if (ar != arvif->ar) { 4576 ath12k_mac_remove_link_interface(hw, arvif); 4577 ath12k_mac_unassign_link_vif(arvif); 4578 } else { 4579 create = false; 4580 } 4581 } 4582 4583 if (create) { 4584 /* Previous arvif would've been cleared in radio switch block 4585 * above, assign arvif again for create. 4586 */ 4587 arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); 4588 4589 ret = ath12k_mac_vdev_create(ar, arvif); 4590 if (ret) { 4591 ath12k_warn(ar->ab, "unable to create scan vdev %d\n", ret); 4592 return -EINVAL; 4593 } 4594 } 4595 4596 spin_lock_bh(&ar->data_lock); 4597 switch (ar->scan.state) { 4598 case ATH12K_SCAN_IDLE: 4599 reinit_completion(&ar->scan.started); 4600 reinit_completion(&ar->scan.completed); 4601 ar->scan.state = ATH12K_SCAN_STARTING; 4602 ar->scan.is_roc = false; 4603 ar->scan.arvif = arvif; 4604 ret = 0; 4605 break; 4606 case ATH12K_SCAN_STARTING: 4607 case ATH12K_SCAN_RUNNING: 4608 case ATH12K_SCAN_ABORTING: 4609 ret = -EBUSY; 4610 break; 4611 } 4612 spin_unlock_bh(&ar->data_lock); 4613 4614 if (ret) 4615 goto exit; 4616 4617 arg = kzalloc(sizeof(*arg), GFP_KERNEL); 4618 if (!arg) { 4619 ret = -ENOMEM; 4620 goto exit; 4621 } 4622 4623 ath12k_wmi_start_scan_init(ar, arg); 4624 arg->vdev_id = arvif->vdev_id; 4625 arg->scan_id = ATH12K_SCAN_ID; 4626 4627 if (req->ie_len) { 4628 arg->extraie.ptr = kmemdup(req->ie, req->ie_len, GFP_KERNEL); 4629 if (!arg->extraie.ptr) { 4630 ret = -ENOMEM; 4631 goto exit; 4632 } 4633 arg->extraie.len = req->ie_len; 4634 } 4635 4636 if (req->n_ssids) { 4637 arg->num_ssids = req->n_ssids; 4638 for (i = 0; i < arg->num_ssids; i++) 4639 arg->ssid[i] = req->ssids[i]; 4640 } else { 4641 arg->scan_f_passive = 1; 4642 } 4643 4644 if (req->n_channels) { 4645 arg->num_chan = req->n_channels; 4646 arg->chan_list = kcalloc(arg->num_chan, sizeof(*arg->chan_list), 4647 GFP_KERNEL); 4648 if (!arg->chan_list) { 4649 ret = -ENOMEM; 4650 goto exit; 4651 } 4652 4653 for (i = 0; i < arg->num_chan; i++) 4654 arg->chan_list[i] = req->channels[i]->center_freq; 4655 } 4656 4657 ret = ath12k_start_scan(ar, arg); 4658 if (ret) { 4659 if (ret == -EBUSY) 4660 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 4661 "scan engine is busy 11d state %d\n", ar->state_11d); 4662 else 4663 ath12k_warn(ar->ab, "failed to start hw scan: %d\n", ret); 4664 4665 spin_lock_bh(&ar->data_lock); 4666 ar->scan.state = ATH12K_SCAN_IDLE; 4667 spin_unlock_bh(&ar->data_lock); 4668 goto exit; 4669 } 4670 4671 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac scan started"); 4672 4673 /* As per cfg80211/mac80211 scan design, it allows only one 4674 * scan at a time. Hence last_scan link id is used for 4675 * tracking the link id on which the scan is been done on 4676 * this vif. 4677 */ 4678 ahvif->last_scan_link = arvif->link_id; 4679 4680 /* Add a margin to account for event/command processing */ 4681 ieee80211_queue_delayed_work(ath12k_ar_to_hw(ar), &ar->scan.timeout, 4682 msecs_to_jiffies(arg->max_scan_time + 4683 ATH12K_MAC_SCAN_TIMEOUT_MSECS)); 4684 4685 exit: 4686 if (arg) { 4687 kfree(arg->chan_list); 4688 kfree(arg->extraie.ptr); 4689 kfree(arg); 4690 } 4691 4692 if (ar->state_11d == ATH12K_11D_PREPARING && 4693 ahvif->vdev_type == WMI_VDEV_TYPE_STA && 4694 ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) 4695 ath12k_mac_11d_scan_start(ar, arvif->vdev_id); 4696 4697 return ret; 4698 } 4699 4700 static void ath12k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw, 4701 struct ieee80211_vif *vif) 4702 { 4703 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 4704 u16 link_id = ahvif->last_scan_link; 4705 struct ath12k_link_vif *arvif; 4706 struct ath12k *ar; 4707 4708 lockdep_assert_wiphy(hw->wiphy); 4709 4710 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 4711 if (!arvif || arvif->is_started) 4712 return; 4713 4714 ar = arvif->ar; 4715 4716 ath12k_scan_abort(ar); 4717 4718 cancel_delayed_work_sync(&ar->scan.timeout); 4719 } 4720 4721 static int ath12k_install_key(struct ath12k_link_vif *arvif, 4722 struct ieee80211_key_conf *key, 4723 enum set_key_cmd cmd, 4724 const u8 *macaddr, u32 flags) 4725 { 4726 int ret; 4727 struct ath12k *ar = arvif->ar; 4728 struct wmi_vdev_install_key_arg arg = { 4729 .vdev_id = arvif->vdev_id, 4730 .key_idx = key->keyidx, 4731 .key_len = key->keylen, 4732 .key_data = key->key, 4733 .key_flags = flags, 4734 .macaddr = macaddr, 4735 }; 4736 struct ath12k_vif *ahvif = arvif->ahvif; 4737 4738 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 4739 4740 reinit_completion(&ar->install_key_done); 4741 4742 if (test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags)) 4743 return 0; 4744 4745 if (cmd == DISABLE_KEY) { 4746 /* TODO: Check if FW expects value other than NONE for del */ 4747 /* arg.key_cipher = WMI_CIPHER_NONE; */ 4748 arg.key_len = 0; 4749 arg.key_data = NULL; 4750 goto install; 4751 } 4752 4753 switch (key->cipher) { 4754 case WLAN_CIPHER_SUITE_CCMP: 4755 case WLAN_CIPHER_SUITE_CCMP_256: 4756 arg.key_cipher = WMI_CIPHER_AES_CCM; 4757 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; 4758 break; 4759 case WLAN_CIPHER_SUITE_TKIP: 4760 arg.key_cipher = WMI_CIPHER_TKIP; 4761 arg.key_txmic_len = 8; 4762 arg.key_rxmic_len = 8; 4763 break; 4764 case WLAN_CIPHER_SUITE_GCMP: 4765 case WLAN_CIPHER_SUITE_GCMP_256: 4766 arg.key_cipher = WMI_CIPHER_AES_GCM; 4767 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; 4768 break; 4769 default: 4770 ath12k_warn(ar->ab, "cipher %d is not supported\n", key->cipher); 4771 return -EOPNOTSUPP; 4772 } 4773 4774 if (test_bit(ATH12K_FLAG_RAW_MODE, &ar->ab->dev_flags)) 4775 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV | 4776 IEEE80211_KEY_FLAG_RESERVE_TAILROOM; 4777 4778 install: 4779 ret = ath12k_wmi_vdev_install_key(arvif->ar, &arg); 4780 4781 if (ret) 4782 return ret; 4783 4784 if (!wait_for_completion_timeout(&ar->install_key_done, 1 * HZ)) 4785 return -ETIMEDOUT; 4786 4787 if (ether_addr_equal(macaddr, arvif->bssid)) 4788 ahvif->key_cipher = key->cipher; 4789 4790 return ar->install_key_status ? -EINVAL : 0; 4791 } 4792 4793 static int ath12k_clear_peer_keys(struct ath12k_link_vif *arvif, 4794 const u8 *addr) 4795 { 4796 struct ath12k *ar = arvif->ar; 4797 struct ath12k_base *ab = ar->ab; 4798 struct ath12k_peer *peer; 4799 int first_errno = 0; 4800 int ret; 4801 int i; 4802 u32 flags = 0; 4803 4804 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 4805 4806 spin_lock_bh(&ab->base_lock); 4807 peer = ath12k_peer_find(ab, arvif->vdev_id, addr); 4808 spin_unlock_bh(&ab->base_lock); 4809 4810 if (!peer) 4811 return -ENOENT; 4812 4813 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { 4814 if (!peer->keys[i]) 4815 continue; 4816 4817 /* key flags are not required to delete the key */ 4818 ret = ath12k_install_key(arvif, peer->keys[i], 4819 DISABLE_KEY, addr, flags); 4820 if (ret < 0 && first_errno == 0) 4821 first_errno = ret; 4822 4823 if (ret < 0) 4824 ath12k_warn(ab, "failed to remove peer key %d: %d\n", 4825 i, ret); 4826 4827 spin_lock_bh(&ab->base_lock); 4828 peer->keys[i] = NULL; 4829 spin_unlock_bh(&ab->base_lock); 4830 } 4831 4832 return first_errno; 4833 } 4834 4835 static int ath12k_mac_set_key(struct ath12k *ar, enum set_key_cmd cmd, 4836 struct ath12k_link_vif *arvif, 4837 struct ath12k_link_sta *arsta, 4838 struct ieee80211_key_conf *key) 4839 { 4840 struct ieee80211_sta *sta = NULL; 4841 struct ath12k_base *ab = ar->ab; 4842 struct ath12k_peer *peer; 4843 struct ath12k_sta *ahsta; 4844 const u8 *peer_addr; 4845 int ret; 4846 u32 flags = 0; 4847 4848 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 4849 4850 if (arsta) 4851 sta = ath12k_ahsta_to_sta(arsta->ahsta); 4852 4853 if (test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ab->dev_flags)) 4854 return 1; 4855 4856 if (sta) 4857 peer_addr = arsta->addr; 4858 else 4859 peer_addr = arvif->bssid; 4860 4861 key->hw_key_idx = key->keyidx; 4862 4863 /* the peer should not disappear in mid-way (unless FW goes awry) since 4864 * we already hold wiphy lock. we just make sure its there now. 4865 */ 4866 spin_lock_bh(&ab->base_lock); 4867 peer = ath12k_peer_find(ab, arvif->vdev_id, peer_addr); 4868 spin_unlock_bh(&ab->base_lock); 4869 4870 if (!peer) { 4871 if (cmd == SET_KEY) { 4872 ath12k_warn(ab, "cannot install key for non-existent peer %pM\n", 4873 peer_addr); 4874 return -EOPNOTSUPP; 4875 } 4876 4877 /* if the peer doesn't exist there is no key to disable 4878 * anymore 4879 */ 4880 return 0; 4881 } 4882 4883 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) 4884 flags |= WMI_KEY_PAIRWISE; 4885 else 4886 flags |= WMI_KEY_GROUP; 4887 4888 ret = ath12k_install_key(arvif, key, cmd, peer_addr, flags); 4889 if (ret) { 4890 ath12k_warn(ab, "ath12k_install_key failed (%d)\n", ret); 4891 return ret; 4892 } 4893 4894 ret = ath12k_dp_rx_peer_pn_replay_config(arvif, peer_addr, cmd, key); 4895 if (ret) { 4896 ath12k_warn(ab, "failed to offload PN replay detection %d\n", ret); 4897 return ret; 4898 } 4899 4900 spin_lock_bh(&ab->base_lock); 4901 peer = ath12k_peer_find(ab, arvif->vdev_id, peer_addr); 4902 if (peer && cmd == SET_KEY) { 4903 peer->keys[key->keyidx] = key; 4904 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { 4905 peer->ucast_keyidx = key->keyidx; 4906 peer->sec_type = ath12k_dp_tx_get_encrypt_type(key->cipher); 4907 } else { 4908 peer->mcast_keyidx = key->keyidx; 4909 peer->sec_type_grp = ath12k_dp_tx_get_encrypt_type(key->cipher); 4910 } 4911 } else if (peer && cmd == DISABLE_KEY) { 4912 peer->keys[key->keyidx] = NULL; 4913 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) 4914 peer->ucast_keyidx = 0; 4915 else 4916 peer->mcast_keyidx = 0; 4917 } else if (!peer) 4918 /* impossible unless FW goes crazy */ 4919 ath12k_warn(ab, "peer %pM disappeared!\n", peer_addr); 4920 4921 if (sta) { 4922 ahsta = ath12k_sta_to_ahsta(sta); 4923 4924 switch (key->cipher) { 4925 case WLAN_CIPHER_SUITE_TKIP: 4926 case WLAN_CIPHER_SUITE_CCMP: 4927 case WLAN_CIPHER_SUITE_CCMP_256: 4928 case WLAN_CIPHER_SUITE_GCMP: 4929 case WLAN_CIPHER_SUITE_GCMP_256: 4930 if (cmd == SET_KEY) 4931 ahsta->pn_type = HAL_PN_TYPE_WPA; 4932 else 4933 ahsta->pn_type = HAL_PN_TYPE_NONE; 4934 break; 4935 default: 4936 ahsta->pn_type = HAL_PN_TYPE_NONE; 4937 break; 4938 } 4939 } 4940 4941 spin_unlock_bh(&ab->base_lock); 4942 4943 return 0; 4944 } 4945 4946 static int ath12k_mac_update_key_cache(struct ath12k_vif_cache *cache, 4947 enum set_key_cmd cmd, 4948 struct ieee80211_sta *sta, 4949 struct ieee80211_key_conf *key) 4950 { 4951 struct ath12k_key_conf *key_conf, *tmp; 4952 4953 list_for_each_entry_safe(key_conf, tmp, &cache->key_conf.list, list) { 4954 if (key_conf->key != key) 4955 continue; 4956 4957 /* If SET key entry is already present in cache, nothing to do, 4958 * just return 4959 */ 4960 if (cmd == SET_KEY) 4961 return 0; 4962 4963 /* DEL key for an old SET key which driver hasn't flushed yet. 4964 */ 4965 list_del(&key_conf->list); 4966 kfree(key_conf); 4967 } 4968 4969 if (cmd == SET_KEY) { 4970 key_conf = kzalloc(sizeof(*key_conf), GFP_KERNEL); 4971 4972 if (!key_conf) 4973 return -ENOMEM; 4974 4975 key_conf->cmd = cmd; 4976 key_conf->sta = sta; 4977 key_conf->key = key; 4978 list_add_tail(&key_conf->list, 4979 &cache->key_conf.list); 4980 } 4981 4982 return 0; 4983 } 4984 4985 static int ath12k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 4986 struct ieee80211_vif *vif, struct ieee80211_sta *sta, 4987 struct ieee80211_key_conf *key) 4988 { 4989 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 4990 struct ath12k_link_vif *arvif; 4991 struct ath12k_link_sta *arsta = NULL; 4992 struct ath12k_vif_cache *cache; 4993 struct ath12k_sta *ahsta; 4994 unsigned long links; 4995 u8 link_id; 4996 int ret; 4997 4998 lockdep_assert_wiphy(hw->wiphy); 4999 5000 /* BIP needs to be done in software */ 5001 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || 5002 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || 5003 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 || 5004 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256) { 5005 return 1; 5006 } 5007 5008 if (key->keyidx > WMI_MAX_KEY_INDEX) 5009 return -ENOSPC; 5010 5011 if (sta) { 5012 ahsta = ath12k_sta_to_ahsta(sta); 5013 5014 /* For an ML STA Pairwise key is same for all associated link Stations, 5015 * hence do set key for all link STAs which are active. 5016 */ 5017 if (sta->mlo) { 5018 links = ahsta->links_map; 5019 for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { 5020 arvif = wiphy_dereference(hw->wiphy, 5021 ahvif->link[link_id]); 5022 arsta = wiphy_dereference(hw->wiphy, 5023 ahsta->link[link_id]); 5024 5025 if (WARN_ON(!arvif || !arsta)) 5026 /* arvif and arsta are expected to be valid when 5027 * STA is present. 5028 */ 5029 continue; 5030 5031 ret = ath12k_mac_set_key(arvif->ar, cmd, arvif, 5032 arsta, key); 5033 if (ret) 5034 break; 5035 } 5036 5037 return 0; 5038 } 5039 5040 arsta = &ahsta->deflink; 5041 arvif = arsta->arvif; 5042 if (WARN_ON(!arvif)) 5043 return -EINVAL; 5044 5045 ret = ath12k_mac_set_key(arvif->ar, cmd, arvif, arsta, key); 5046 if (ret) 5047 return ret; 5048 5049 return 0; 5050 } 5051 5052 if (key->link_id >= 0 && key->link_id < IEEE80211_MLD_MAX_NUM_LINKS) { 5053 link_id = key->link_id; 5054 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 5055 } else { 5056 link_id = 0; 5057 arvif = &ahvif->deflink; 5058 } 5059 5060 if (!arvif || !arvif->is_created) { 5061 cache = ath12k_ahvif_get_link_cache(ahvif, link_id); 5062 if (!cache) 5063 return -ENOSPC; 5064 5065 ret = ath12k_mac_update_key_cache(cache, cmd, sta, key); 5066 if (ret) 5067 return ret; 5068 5069 return 0; 5070 } 5071 5072 ret = ath12k_mac_set_key(arvif->ar, cmd, arvif, NULL, key); 5073 if (ret) 5074 return ret; 5075 5076 return 0; 5077 } 5078 5079 static int 5080 ath12k_mac_bitrate_mask_num_vht_rates(struct ath12k *ar, 5081 enum nl80211_band band, 5082 const struct cfg80211_bitrate_mask *mask) 5083 { 5084 int num_rates = 0; 5085 int i; 5086 5087 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) 5088 num_rates += hweight16(mask->control[band].vht_mcs[i]); 5089 5090 return num_rates; 5091 } 5092 5093 static int 5094 ath12k_mac_set_peer_vht_fixed_rate(struct ath12k_link_vif *arvif, 5095 struct ath12k_link_sta *arsta, 5096 const struct cfg80211_bitrate_mask *mask, 5097 enum nl80211_band band) 5098 { 5099 struct ath12k *ar = arvif->ar; 5100 u8 vht_rate, nss; 5101 u32 rate_code; 5102 int ret, i; 5103 5104 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 5105 5106 nss = 0; 5107 5108 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { 5109 if (hweight16(mask->control[band].vht_mcs[i]) == 1) { 5110 nss = i + 1; 5111 vht_rate = ffs(mask->control[band].vht_mcs[i]) - 1; 5112 } 5113 } 5114 5115 if (!nss) { 5116 ath12k_warn(ar->ab, "No single VHT Fixed rate found to set for %pM", 5117 arsta->addr); 5118 return -EINVAL; 5119 } 5120 5121 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 5122 "Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates", 5123 arsta->addr); 5124 5125 rate_code = ATH12K_HW_RATE_CODE(vht_rate, nss - 1, 5126 WMI_RATE_PREAMBLE_VHT); 5127 ret = ath12k_wmi_set_peer_param(ar, arsta->addr, 5128 arvif->vdev_id, 5129 WMI_PEER_PARAM_FIXED_RATE, 5130 rate_code); 5131 if (ret) 5132 ath12k_warn(ar->ab, 5133 "failed to update STA %pM Fixed Rate %d: %d\n", 5134 arsta->addr, rate_code, ret); 5135 5136 return ret; 5137 } 5138 5139 static int ath12k_mac_station_assoc(struct ath12k *ar, 5140 struct ath12k_link_vif *arvif, 5141 struct ath12k_link_sta *arsta, 5142 bool reassoc) 5143 { 5144 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 5145 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 5146 struct ieee80211_link_sta *link_sta; 5147 int ret; 5148 struct cfg80211_chan_def def; 5149 enum nl80211_band band; 5150 struct cfg80211_bitrate_mask *mask; 5151 u8 num_vht_rates; 5152 u8 link_id = arvif->link_id; 5153 5154 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 5155 5156 if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) 5157 return -EPERM; 5158 5159 if (WARN_ON(!rcu_access_pointer(sta->link[link_id]))) 5160 return -EINVAL; 5161 5162 band = def.chan->band; 5163 mask = &arvif->bitrate_mask; 5164 5165 struct ath12k_wmi_peer_assoc_arg *peer_arg __free(kfree) = 5166 kzalloc(sizeof(*peer_arg), GFP_KERNEL); 5167 if (!peer_arg) 5168 return -ENOMEM; 5169 5170 ath12k_peer_assoc_prepare(ar, arvif, arsta, peer_arg, reassoc); 5171 5172 if (peer_arg->peer_nss < 1) { 5173 ath12k_warn(ar->ab, 5174 "invalid peer NSS %d\n", peer_arg->peer_nss); 5175 return -EINVAL; 5176 } 5177 ret = ath12k_wmi_send_peer_assoc_cmd(ar, peer_arg); 5178 if (ret) { 5179 ath12k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n", 5180 arsta->addr, arvif->vdev_id, ret); 5181 return ret; 5182 } 5183 5184 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) { 5185 ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", 5186 arsta->addr, arvif->vdev_id); 5187 return -ETIMEDOUT; 5188 } 5189 5190 num_vht_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, mask); 5191 5192 /* If single VHT rate is configured (by set_bitrate_mask()), 5193 * peer_assoc will disable VHT. This is now enabled by a peer specific 5194 * fixed param. 5195 * Note that all other rates and NSS will be disabled for this peer. 5196 */ 5197 link_sta = ath12k_mac_get_link_sta(arsta); 5198 if (!link_sta) { 5199 ath12k_warn(ar->ab, "unable to access link sta in station assoc\n"); 5200 return -EINVAL; 5201 } 5202 5203 spin_lock_bh(&ar->data_lock); 5204 arsta->bw = ath12k_mac_ieee80211_sta_bw_to_wmi(ar, link_sta); 5205 arsta->bw_prev = link_sta->bandwidth; 5206 spin_unlock_bh(&ar->data_lock); 5207 5208 if (link_sta->vht_cap.vht_supported && num_vht_rates == 1) { 5209 ret = ath12k_mac_set_peer_vht_fixed_rate(arvif, arsta, mask, 5210 band); 5211 if (ret) 5212 return ret; 5213 } 5214 5215 /* Re-assoc is run only to update supported rates for given station. It 5216 * doesn't make much sense to reconfigure the peer completely. 5217 */ 5218 if (reassoc) 5219 return 0; 5220 5221 ret = ath12k_setup_peer_smps(ar, arvif, arsta->addr, 5222 &link_sta->ht_cap, &link_sta->he_6ghz_capa); 5223 if (ret) { 5224 ath12k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n", 5225 arvif->vdev_id, ret); 5226 return ret; 5227 } 5228 5229 if (!sta->wme) { 5230 arvif->num_legacy_stations++; 5231 ret = ath12k_recalc_rtscts_prot(arvif); 5232 if (ret) 5233 return ret; 5234 } 5235 5236 if (sta->wme && sta->uapsd_queues) { 5237 ret = ath12k_peer_assoc_qos_ap(ar, arvif, arsta); 5238 if (ret) { 5239 ath12k_warn(ar->ab, "failed to set qos params for STA %pM for vdev %i: %d\n", 5240 arsta->addr, arvif->vdev_id, ret); 5241 return ret; 5242 } 5243 } 5244 5245 return 0; 5246 } 5247 5248 static int ath12k_mac_station_disassoc(struct ath12k *ar, 5249 struct ath12k_link_vif *arvif, 5250 struct ath12k_link_sta *arsta) 5251 { 5252 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 5253 5254 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 5255 5256 if (!sta->wme) { 5257 arvif->num_legacy_stations--; 5258 return ath12k_recalc_rtscts_prot(arvif); 5259 } 5260 5261 return 0; 5262 } 5263 5264 static void ath12k_sta_rc_update_wk(struct wiphy *wiphy, struct wiphy_work *wk) 5265 { 5266 struct ieee80211_link_sta *link_sta; 5267 struct ath12k *ar; 5268 struct ath12k_link_vif *arvif; 5269 struct ieee80211_sta *sta; 5270 struct cfg80211_chan_def def; 5271 enum nl80211_band band; 5272 const u8 *ht_mcs_mask; 5273 const u16 *vht_mcs_mask; 5274 u32 changed, bw, nss, smps, bw_prev; 5275 int err, num_vht_rates; 5276 const struct cfg80211_bitrate_mask *mask; 5277 enum wmi_phy_mode peer_phymode; 5278 struct ath12k_link_sta *arsta; 5279 struct ieee80211_vif *vif; 5280 5281 lockdep_assert_wiphy(wiphy); 5282 5283 arsta = container_of(wk, struct ath12k_link_sta, update_wk); 5284 sta = ath12k_ahsta_to_sta(arsta->ahsta); 5285 arvif = arsta->arvif; 5286 vif = ath12k_ahvif_to_vif(arvif->ahvif); 5287 ar = arvif->ar; 5288 5289 if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) 5290 return; 5291 5292 band = def.chan->band; 5293 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; 5294 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; 5295 5296 spin_lock_bh(&ar->data_lock); 5297 5298 changed = arsta->changed; 5299 arsta->changed = 0; 5300 5301 bw = arsta->bw; 5302 bw_prev = arsta->bw_prev; 5303 nss = arsta->nss; 5304 smps = arsta->smps; 5305 5306 spin_unlock_bh(&ar->data_lock); 5307 5308 nss = max_t(u32, 1, nss); 5309 nss = min(nss, max(ath12k_mac_max_ht_nss(ht_mcs_mask), 5310 ath12k_mac_max_vht_nss(vht_mcs_mask))); 5311 5312 struct ath12k_wmi_peer_assoc_arg *peer_arg __free(kfree) = 5313 kzalloc(sizeof(*peer_arg), GFP_KERNEL); 5314 if (!peer_arg) 5315 return; 5316 5317 if (changed & IEEE80211_RC_BW_CHANGED) { 5318 ath12k_peer_assoc_h_phymode(ar, arvif, arsta, peer_arg); 5319 peer_phymode = peer_arg->peer_phymode; 5320 5321 if (bw > bw_prev) { 5322 /* Phymode shows maximum supported channel width, if we 5323 * upgrade bandwidth then due to sanity check of firmware, 5324 * we have to send WMI_PEER_PHYMODE followed by 5325 * WMI_PEER_CHWIDTH 5326 */ 5327 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac bandwidth upgrade for sta %pM new %d old %d\n", 5328 arsta->addr, bw, bw_prev); 5329 err = ath12k_wmi_set_peer_param(ar, arsta->addr, 5330 arvif->vdev_id, WMI_PEER_PHYMODE, 5331 peer_phymode); 5332 if (err) { 5333 ath12k_warn(ar->ab, "failed to update STA %pM to peer phymode %d: %d\n", 5334 arsta->addr, peer_phymode, err); 5335 return; 5336 } 5337 err = ath12k_wmi_set_peer_param(ar, arsta->addr, 5338 arvif->vdev_id, WMI_PEER_CHWIDTH, 5339 bw); 5340 if (err) 5341 ath12k_warn(ar->ab, "failed to update STA %pM to peer bandwidth %d: %d\n", 5342 arsta->addr, bw, err); 5343 } else { 5344 /* When we downgrade bandwidth this will conflict with phymode 5345 * and cause to trigger firmware crash. In this case we send 5346 * WMI_PEER_CHWIDTH followed by WMI_PEER_PHYMODE 5347 */ 5348 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac bandwidth downgrade for sta %pM new %d old %d\n", 5349 arsta->addr, bw, bw_prev); 5350 err = ath12k_wmi_set_peer_param(ar, arsta->addr, 5351 arvif->vdev_id, WMI_PEER_CHWIDTH, 5352 bw); 5353 if (err) { 5354 ath12k_warn(ar->ab, "failed to update STA %pM peer to bandwidth %d: %d\n", 5355 arsta->addr, bw, err); 5356 return; 5357 } 5358 err = ath12k_wmi_set_peer_param(ar, arsta->addr, 5359 arvif->vdev_id, WMI_PEER_PHYMODE, 5360 peer_phymode); 5361 if (err) 5362 ath12k_warn(ar->ab, "failed to update STA %pM to peer phymode %d: %d\n", 5363 arsta->addr, peer_phymode, err); 5364 } 5365 } 5366 5367 if (changed & IEEE80211_RC_NSS_CHANGED) { 5368 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac update sta %pM nss %d\n", 5369 arsta->addr, nss); 5370 5371 err = ath12k_wmi_set_peer_param(ar, arsta->addr, arvif->vdev_id, 5372 WMI_PEER_NSS, nss); 5373 if (err) 5374 ath12k_warn(ar->ab, "failed to update STA %pM nss %d: %d\n", 5375 arsta->addr, nss, err); 5376 } 5377 5378 if (changed & IEEE80211_RC_SMPS_CHANGED) { 5379 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac update sta %pM smps %d\n", 5380 arsta->addr, smps); 5381 5382 err = ath12k_wmi_set_peer_param(ar, arsta->addr, arvif->vdev_id, 5383 WMI_PEER_MIMO_PS_STATE, smps); 5384 if (err) 5385 ath12k_warn(ar->ab, "failed to update STA %pM smps %d: %d\n", 5386 arsta->addr, smps, err); 5387 } 5388 5389 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) { 5390 mask = &arvif->bitrate_mask; 5391 num_vht_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, 5392 mask); 5393 5394 /* Peer_assoc_prepare will reject vht rates in 5395 * bitrate_mask if its not available in range format and 5396 * sets vht tx_rateset as unsupported. So multiple VHT MCS 5397 * setting(eg. MCS 4,5,6) per peer is not supported here. 5398 * But, Single rate in VHT mask can be set as per-peer 5399 * fixed rate. But even if any HT rates are configured in 5400 * the bitrate mask, device will not switch to those rates 5401 * when per-peer Fixed rate is set. 5402 * TODO: Check RATEMASK_CMDID to support auto rates selection 5403 * across HT/VHT and for multiple VHT MCS support. 5404 */ 5405 link_sta = ath12k_mac_get_link_sta(arsta); 5406 if (!link_sta) { 5407 ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n", 5408 sta->addr, arsta->link_id); 5409 return; 5410 } 5411 5412 if (link_sta->vht_cap.vht_supported && num_vht_rates == 1) { 5413 ath12k_mac_set_peer_vht_fixed_rate(arvif, arsta, mask, 5414 band); 5415 } else { 5416 /* If the peer is non-VHT or no fixed VHT rate 5417 * is provided in the new bitrate mask we set the 5418 * other rates using peer_assoc command. 5419 */ 5420 ath12k_peer_assoc_prepare(ar, arvif, arsta, 5421 peer_arg, true); 5422 5423 err = ath12k_wmi_send_peer_assoc_cmd(ar, peer_arg); 5424 if (err) 5425 ath12k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n", 5426 arsta->addr, arvif->vdev_id, err); 5427 5428 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) 5429 ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", 5430 arsta->addr, arvif->vdev_id); 5431 } 5432 } 5433 } 5434 5435 static void ath12k_mac_free_unassign_link_sta(struct ath12k_hw *ah, 5436 struct ath12k_sta *ahsta, 5437 u8 link_id) 5438 { 5439 struct ath12k_link_sta *arsta; 5440 5441 lockdep_assert_wiphy(ah->hw->wiphy); 5442 5443 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) 5444 return; 5445 5446 arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]); 5447 if (WARN_ON(!arsta)) 5448 return; 5449 5450 ahsta->links_map &= ~BIT(link_id); 5451 rcu_assign_pointer(ahsta->link[link_id], NULL); 5452 synchronize_rcu(); 5453 5454 if (arsta == &ahsta->deflink) { 5455 arsta->link_id = ATH12K_INVALID_LINK_ID; 5456 arsta->ahsta = NULL; 5457 arsta->arvif = NULL; 5458 return; 5459 } 5460 5461 kfree(arsta); 5462 } 5463 5464 static int ath12k_mac_inc_num_stations(struct ath12k_link_vif *arvif, 5465 struct ath12k_link_sta *arsta) 5466 { 5467 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 5468 struct ath12k *ar = arvif->ar; 5469 5470 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 5471 5472 if (arvif->ahvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) 5473 return 0; 5474 5475 if (ar->num_stations >= ar->max_num_stations) 5476 return -ENOBUFS; 5477 5478 ar->num_stations++; 5479 5480 return 0; 5481 } 5482 5483 static void ath12k_mac_dec_num_stations(struct ath12k_link_vif *arvif, 5484 struct ath12k_link_sta *arsta) 5485 { 5486 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 5487 struct ath12k *ar = arvif->ar; 5488 5489 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 5490 5491 if (arvif->ahvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) 5492 return; 5493 5494 ar->num_stations--; 5495 } 5496 5497 static void ath12k_mac_station_post_remove(struct ath12k *ar, 5498 struct ath12k_link_vif *arvif, 5499 struct ath12k_link_sta *arsta) 5500 { 5501 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 5502 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 5503 struct ath12k_peer *peer; 5504 5505 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 5506 5507 ath12k_mac_dec_num_stations(arvif, arsta); 5508 5509 spin_lock_bh(&ar->ab->base_lock); 5510 5511 peer = ath12k_peer_find(ar->ab, arvif->vdev_id, arsta->addr); 5512 if (peer && peer->sta == sta) { 5513 ath12k_warn(ar->ab, "Found peer entry %pM n vdev %i after it was supposedly removed\n", 5514 vif->addr, arvif->vdev_id); 5515 peer->sta = NULL; 5516 list_del(&peer->list); 5517 kfree(peer); 5518 ar->num_peers--; 5519 } 5520 5521 spin_unlock_bh(&ar->ab->base_lock); 5522 5523 kfree(arsta->rx_stats); 5524 arsta->rx_stats = NULL; 5525 } 5526 5527 static int ath12k_mac_station_unauthorize(struct ath12k *ar, 5528 struct ath12k_link_vif *arvif, 5529 struct ath12k_link_sta *arsta) 5530 { 5531 struct ath12k_peer *peer; 5532 int ret; 5533 5534 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 5535 5536 spin_lock_bh(&ar->ab->base_lock); 5537 5538 peer = ath12k_peer_find(ar->ab, arvif->vdev_id, arsta->addr); 5539 if (peer) 5540 peer->is_authorized = false; 5541 5542 spin_unlock_bh(&ar->ab->base_lock); 5543 5544 /* Driver must clear the keys during the state change from 5545 * IEEE80211_STA_AUTHORIZED to IEEE80211_STA_ASSOC, since after 5546 * returning from here, mac80211 is going to delete the keys 5547 * in __sta_info_destroy_part2(). This will ensure that the driver does 5548 * not retain stale key references after mac80211 deletes the keys. 5549 */ 5550 ret = ath12k_clear_peer_keys(arvif, arsta->addr); 5551 if (ret) { 5552 ath12k_warn(ar->ab, "failed to clear all peer keys for vdev %i: %d\n", 5553 arvif->vdev_id, ret); 5554 return ret; 5555 } 5556 5557 return 0; 5558 } 5559 5560 static int ath12k_mac_station_authorize(struct ath12k *ar, 5561 struct ath12k_link_vif *arvif, 5562 struct ath12k_link_sta *arsta) 5563 { 5564 struct ath12k_peer *peer; 5565 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 5566 int ret; 5567 5568 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 5569 5570 spin_lock_bh(&ar->ab->base_lock); 5571 5572 peer = ath12k_peer_find(ar->ab, arvif->vdev_id, arsta->addr); 5573 if (peer) 5574 peer->is_authorized = true; 5575 5576 spin_unlock_bh(&ar->ab->base_lock); 5577 5578 if (vif->type == NL80211_IFTYPE_STATION && arvif->is_up) { 5579 ret = ath12k_wmi_set_peer_param(ar, arsta->addr, 5580 arvif->vdev_id, 5581 WMI_PEER_AUTHORIZE, 5582 1); 5583 if (ret) { 5584 ath12k_warn(ar->ab, "Unable to authorize peer %pM vdev %d: %d\n", 5585 arsta->addr, arvif->vdev_id, ret); 5586 return ret; 5587 } 5588 } 5589 5590 return 0; 5591 } 5592 5593 static int ath12k_mac_station_remove(struct ath12k *ar, 5594 struct ath12k_link_vif *arvif, 5595 struct ath12k_link_sta *arsta) 5596 { 5597 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 5598 struct ath12k_vif *ahvif = arvif->ahvif; 5599 int ret = 0; 5600 5601 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 5602 5603 wiphy_work_cancel(ar->ah->hw->wiphy, &arsta->update_wk); 5604 5605 if (ahvif->vdev_type == WMI_VDEV_TYPE_STA) { 5606 ath12k_bss_disassoc(ar, arvif); 5607 ret = ath12k_mac_vdev_stop(arvif); 5608 if (ret) 5609 ath12k_warn(ar->ab, "failed to stop vdev %i: %d\n", 5610 arvif->vdev_id, ret); 5611 } 5612 5613 if (sta->mlo) 5614 return ret; 5615 5616 ath12k_dp_peer_cleanup(ar, arvif->vdev_id, arsta->addr); 5617 5618 ret = ath12k_peer_delete(ar, arvif->vdev_id, arsta->addr); 5619 if (ret) 5620 ath12k_warn(ar->ab, "Failed to delete peer: %pM for VDEV: %d\n", 5621 arsta->addr, arvif->vdev_id); 5622 else 5623 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "Removed peer: %pM for VDEV: %d\n", 5624 arsta->addr, arvif->vdev_id); 5625 5626 ath12k_mac_station_post_remove(ar, arvif, arsta); 5627 5628 if (sta->valid_links) 5629 ath12k_mac_free_unassign_link_sta(ahvif->ah, 5630 arsta->ahsta, arsta->link_id); 5631 5632 return ret; 5633 } 5634 5635 static int ath12k_mac_station_add(struct ath12k *ar, 5636 struct ath12k_link_vif *arvif, 5637 struct ath12k_link_sta *arsta) 5638 { 5639 struct ath12k_base *ab = ar->ab; 5640 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 5641 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); 5642 struct ath12k_wmi_peer_create_arg peer_param = {0}; 5643 int ret; 5644 5645 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 5646 5647 ret = ath12k_mac_inc_num_stations(arvif, arsta); 5648 if (ret) { 5649 ath12k_warn(ab, "refusing to associate station: too many connected already (%d)\n", 5650 ar->max_num_stations); 5651 goto exit; 5652 } 5653 5654 if (ath12k_debugfs_is_extd_rx_stats_enabled(ar) && !arsta->rx_stats) { 5655 arsta->rx_stats = kzalloc(sizeof(*arsta->rx_stats), GFP_KERNEL); 5656 if (!arsta->rx_stats) { 5657 ret = -ENOMEM; 5658 goto dec_num_station; 5659 } 5660 } 5661 5662 peer_param.vdev_id = arvif->vdev_id; 5663 peer_param.peer_addr = arsta->addr; 5664 peer_param.peer_type = WMI_PEER_TYPE_DEFAULT; 5665 peer_param.ml_enabled = sta->mlo; 5666 5667 ret = ath12k_peer_create(ar, arvif, sta, &peer_param); 5668 if (ret) { 5669 ath12k_warn(ab, "Failed to add peer: %pM for VDEV: %d\n", 5670 arsta->addr, arvif->vdev_id); 5671 goto free_peer; 5672 } 5673 5674 ath12k_dbg(ab, ATH12K_DBG_MAC, "Added peer: %pM for VDEV: %d\n", 5675 arsta->addr, arvif->vdev_id); 5676 5677 if (ieee80211_vif_is_mesh(vif)) { 5678 ret = ath12k_wmi_set_peer_param(ar, arsta->addr, 5679 arvif->vdev_id, 5680 WMI_PEER_USE_4ADDR, 1); 5681 if (ret) { 5682 ath12k_warn(ab, "failed to STA %pM 4addr capability: %d\n", 5683 arsta->addr, ret); 5684 goto free_peer; 5685 } 5686 } 5687 5688 ret = ath12k_dp_peer_setup(ar, arvif->vdev_id, arsta->addr); 5689 if (ret) { 5690 ath12k_warn(ab, "failed to setup dp for peer %pM on vdev %i (%d)\n", 5691 arsta->addr, arvif->vdev_id, ret); 5692 goto free_peer; 5693 } 5694 5695 if (ab->hw_params->vdev_start_delay && 5696 !arvif->is_started && 5697 arvif->ahvif->vdev_type != WMI_VDEV_TYPE_AP) { 5698 ret = ath12k_start_vdev_delay(ar, arvif); 5699 if (ret) { 5700 ath12k_warn(ab, "failed to delay vdev start: %d\n", ret); 5701 goto free_peer; 5702 } 5703 } 5704 5705 ewma_avg_rssi_init(&arsta->avg_rssi); 5706 return 0; 5707 5708 free_peer: 5709 ath12k_peer_delete(ar, arvif->vdev_id, arsta->addr); 5710 kfree(arsta->rx_stats); 5711 arsta->rx_stats = NULL; 5712 dec_num_station: 5713 ath12k_mac_dec_num_stations(arvif, arsta); 5714 exit: 5715 return ret; 5716 } 5717 5718 static int ath12k_mac_assign_link_sta(struct ath12k_hw *ah, 5719 struct ath12k_sta *ahsta, 5720 struct ath12k_link_sta *arsta, 5721 struct ath12k_vif *ahvif, 5722 u8 link_id) 5723 { 5724 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(ahsta); 5725 struct ieee80211_link_sta *link_sta; 5726 struct ath12k_link_vif *arvif; 5727 5728 lockdep_assert_wiphy(ah->hw->wiphy); 5729 5730 if (!arsta || link_id >= IEEE80211_MLD_MAX_NUM_LINKS) 5731 return -EINVAL; 5732 5733 arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); 5734 if (!arvif) 5735 return -EINVAL; 5736 5737 memset(arsta, 0, sizeof(*arsta)); 5738 5739 link_sta = wiphy_dereference(ah->hw->wiphy, sta->link[link_id]); 5740 if (!link_sta) 5741 return -EINVAL; 5742 5743 ether_addr_copy(arsta->addr, link_sta->addr); 5744 5745 /* logical index of the link sta in order of creation */ 5746 arsta->link_idx = ahsta->num_peer++; 5747 5748 arsta->link_id = link_id; 5749 ahsta->links_map |= BIT(arsta->link_id); 5750 arsta->arvif = arvif; 5751 arsta->ahsta = ahsta; 5752 ahsta->ahvif = ahvif; 5753 5754 wiphy_work_init(&arsta->update_wk, ath12k_sta_rc_update_wk); 5755 5756 rcu_assign_pointer(ahsta->link[link_id], arsta); 5757 5758 return 0; 5759 } 5760 5761 static void ath12k_mac_ml_station_remove(struct ath12k_vif *ahvif, 5762 struct ath12k_sta *ahsta) 5763 { 5764 struct ieee80211_sta *sta = ath12k_ahsta_to_sta(ahsta); 5765 struct ath12k_hw *ah = ahvif->ah; 5766 struct ath12k_link_vif *arvif; 5767 struct ath12k_link_sta *arsta; 5768 unsigned long links; 5769 struct ath12k *ar; 5770 u8 link_id; 5771 5772 lockdep_assert_wiphy(ah->hw->wiphy); 5773 5774 ath12k_peer_mlo_link_peers_delete(ahvif, ahsta); 5775 5776 /* validate link station removal and clear arsta links */ 5777 links = ahsta->links_map; 5778 for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { 5779 arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); 5780 arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]); 5781 if (!arvif || !arsta) 5782 continue; 5783 5784 ar = arvif->ar; 5785 5786 ath12k_mac_station_post_remove(ar, arvif, arsta); 5787 5788 ath12k_mac_free_unassign_link_sta(ah, ahsta, link_id); 5789 } 5790 5791 ath12k_peer_ml_delete(ah, sta); 5792 } 5793 5794 static int ath12k_mac_handle_link_sta_state(struct ieee80211_hw *hw, 5795 struct ath12k_link_vif *arvif, 5796 struct ath12k_link_sta *arsta, 5797 enum ieee80211_sta_state old_state, 5798 enum ieee80211_sta_state new_state) 5799 { 5800 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 5801 struct ieee80211_bss_conf *link_conf; 5802 struct ath12k *ar = arvif->ar; 5803 struct ath12k_reg_info *reg_info; 5804 struct ath12k_base *ab = ar->ab; 5805 int ret = 0; 5806 5807 lockdep_assert_wiphy(hw->wiphy); 5808 5809 ath12k_dbg(ab, ATH12K_DBG_MAC, "mac handle link %u sta %pM state %d -> %d\n", 5810 arsta->link_id, arsta->addr, old_state, new_state); 5811 5812 /* IEEE80211_STA_NONE -> IEEE80211_STA_NOTEXIST: Remove the station 5813 * from driver 5814 */ 5815 if ((old_state == IEEE80211_STA_NONE && 5816 new_state == IEEE80211_STA_NOTEXIST)) { 5817 ret = ath12k_mac_station_remove(ar, arvif, arsta); 5818 if (ret) { 5819 ath12k_warn(ab, "Failed to remove station: %pM for VDEV: %d\n", 5820 arsta->addr, arvif->vdev_id); 5821 goto exit; 5822 } 5823 } 5824 5825 /* IEEE80211_STA_NOTEXIST -> IEEE80211_STA_NONE: Add new station to driver */ 5826 if (old_state == IEEE80211_STA_NOTEXIST && 5827 new_state == IEEE80211_STA_NONE) { 5828 ret = ath12k_mac_station_add(ar, arvif, arsta); 5829 if (ret) 5830 ath12k_warn(ab, "Failed to add station: %pM for VDEV: %d\n", 5831 arsta->addr, arvif->vdev_id); 5832 5833 /* IEEE80211_STA_AUTH -> IEEE80211_STA_ASSOC: Send station assoc command for 5834 * peer associated to AP/Mesh/ADHOC vif type. 5835 */ 5836 } else if (old_state == IEEE80211_STA_AUTH && 5837 new_state == IEEE80211_STA_ASSOC && 5838 (vif->type == NL80211_IFTYPE_AP || 5839 vif->type == NL80211_IFTYPE_MESH_POINT || 5840 vif->type == NL80211_IFTYPE_ADHOC)) { 5841 ret = ath12k_mac_station_assoc(ar, arvif, arsta, false); 5842 if (ret) 5843 ath12k_warn(ab, "Failed to associate station: %pM\n", 5844 arsta->addr); 5845 5846 /* IEEE80211_STA_ASSOC -> IEEE80211_STA_AUTHORIZED: set peer status as 5847 * authorized 5848 */ 5849 } else if (old_state == IEEE80211_STA_ASSOC && 5850 new_state == IEEE80211_STA_AUTHORIZED) { 5851 ret = ath12k_mac_station_authorize(ar, arvif, arsta); 5852 if (ret) { 5853 ath12k_warn(ab, "Failed to authorize station: %pM\n", 5854 arsta->addr); 5855 goto exit; 5856 } 5857 5858 if (ath12k_wmi_supports_6ghz_cc_ext(ar) && 5859 arvif->ahvif->vdev_type == WMI_VDEV_TYPE_STA) { 5860 link_conf = ath12k_mac_get_link_bss_conf(arvif); 5861 reg_info = ab->reg_info[ar->pdev_idx]; 5862 ath12k_dbg(ab, ATH12K_DBG_MAC, "connection done, update reg rules\n"); 5863 ath12k_hw_to_ah(hw)->regd_updated = false; 5864 ath12k_reg_handle_chan_list(ab, reg_info, arvif->ahvif->vdev_type, 5865 link_conf->power_type); 5866 } 5867 5868 /* IEEE80211_STA_AUTHORIZED -> IEEE80211_STA_ASSOC: station may be in removal, 5869 * deauthorize it. 5870 */ 5871 } else if (old_state == IEEE80211_STA_AUTHORIZED && 5872 new_state == IEEE80211_STA_ASSOC) { 5873 ath12k_mac_station_unauthorize(ar, arvif, arsta); 5874 5875 /* IEEE80211_STA_ASSOC -> IEEE80211_STA_AUTH: disassoc peer connected to 5876 * AP/mesh/ADHOC vif type. 5877 */ 5878 } else if (old_state == IEEE80211_STA_ASSOC && 5879 new_state == IEEE80211_STA_AUTH && 5880 (vif->type == NL80211_IFTYPE_AP || 5881 vif->type == NL80211_IFTYPE_MESH_POINT || 5882 vif->type == NL80211_IFTYPE_ADHOC)) { 5883 ret = ath12k_mac_station_disassoc(ar, arvif, arsta); 5884 if (ret) 5885 ath12k_warn(ab, "Failed to disassociate station: %pM\n", 5886 arsta->addr); 5887 } 5888 5889 exit: 5890 return ret; 5891 } 5892 5893 static int ath12k_mac_op_sta_state(struct ieee80211_hw *hw, 5894 struct ieee80211_vif *vif, 5895 struct ieee80211_sta *sta, 5896 enum ieee80211_sta_state old_state, 5897 enum ieee80211_sta_state new_state) 5898 { 5899 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 5900 struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); 5901 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 5902 struct ath12k_link_vif *arvif; 5903 struct ath12k_link_sta *arsta; 5904 unsigned long valid_links; 5905 u8 link_id = 0; 5906 int ret; 5907 5908 lockdep_assert_wiphy(hw->wiphy); 5909 5910 if (ieee80211_vif_is_mld(vif) && sta->valid_links) { 5911 WARN_ON(!sta->mlo && hweight16(sta->valid_links) != 1); 5912 link_id = ffs(sta->valid_links) - 1; 5913 } 5914 5915 /* IEEE80211_STA_NOTEXIST -> IEEE80211_STA_NONE: 5916 * New station add received. If this is a ML station then 5917 * ahsta->links_map will be zero and sta->valid_links will be 1. 5918 * Assign default link to the first link sta. 5919 */ 5920 if (old_state == IEEE80211_STA_NOTEXIST && 5921 new_state == IEEE80211_STA_NONE) { 5922 memset(ahsta, 0, sizeof(*ahsta)); 5923 5924 arsta = &ahsta->deflink; 5925 5926 /* ML sta */ 5927 if (sta->mlo && !ahsta->links_map && 5928 (hweight16(sta->valid_links) == 1)) { 5929 ret = ath12k_peer_ml_create(ah, sta); 5930 if (ret) { 5931 ath12k_hw_warn(ah, "unable to create ML peer for sta %pM", 5932 sta->addr); 5933 goto exit; 5934 } 5935 } 5936 5937 ret = ath12k_mac_assign_link_sta(ah, ahsta, arsta, ahvif, 5938 link_id); 5939 if (ret) { 5940 ath12k_hw_warn(ah, "unable assign link %d for sta %pM", 5941 link_id, sta->addr); 5942 goto exit; 5943 } 5944 5945 /* above arsta will get memset, hence do this after assign 5946 * link sta 5947 */ 5948 if (sta->mlo) { 5949 /* For station mode, arvif->is_sta_assoc_link has been set when 5950 * vdev starts. Make sure the arvif/arsta pair have same setting 5951 */ 5952 if (vif->type == NL80211_IFTYPE_STATION && 5953 !arsta->arvif->is_sta_assoc_link) { 5954 ath12k_hw_warn(ah, "failed to verify assoc link setting with link id %u\n", 5955 link_id); 5956 ret = -EINVAL; 5957 goto exit; 5958 } 5959 5960 arsta->is_assoc_link = true; 5961 ahsta->assoc_link_id = link_id; 5962 } 5963 } 5964 5965 /* In the ML station scenario, activate all partner links once the 5966 * client is transitioning to the associated state. 5967 * 5968 * FIXME: Ideally, this activation should occur when the client 5969 * transitions to the authorized state. However, there are some 5970 * issues with handling this in the firmware. Until the firmware 5971 * can manage it properly, activate the links when the client is 5972 * about to move to the associated state. 5973 */ 5974 if (ieee80211_vif_is_mld(vif) && vif->type == NL80211_IFTYPE_STATION && 5975 old_state == IEEE80211_STA_AUTH && new_state == IEEE80211_STA_ASSOC) 5976 ieee80211_set_active_links(vif, ieee80211_vif_usable_links(vif)); 5977 5978 /* Handle all the other state transitions in generic way */ 5979 valid_links = ahsta->links_map; 5980 for_each_set_bit(link_id, &valid_links, IEEE80211_MLD_MAX_NUM_LINKS) { 5981 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 5982 arsta = wiphy_dereference(hw->wiphy, ahsta->link[link_id]); 5983 /* some assumptions went wrong! */ 5984 if (WARN_ON(!arvif || !arsta)) 5985 continue; 5986 5987 /* vdev might be in deleted */ 5988 if (WARN_ON(!arvif->ar)) 5989 continue; 5990 5991 ret = ath12k_mac_handle_link_sta_state(hw, arvif, arsta, 5992 old_state, new_state); 5993 if (ret) { 5994 ath12k_hw_warn(ah, "unable to move link sta %d of sta %pM from state %d to %d", 5995 link_id, arsta->addr, old_state, new_state); 5996 goto exit; 5997 } 5998 } 5999 6000 /* IEEE80211_STA_NONE -> IEEE80211_STA_NOTEXIST: 6001 * Remove the station from driver (handle ML sta here since that 6002 * needs special handling. Normal sta will be handled in generic 6003 * handler below 6004 */ 6005 if (old_state == IEEE80211_STA_NONE && 6006 new_state == IEEE80211_STA_NOTEXIST && sta->mlo) 6007 ath12k_mac_ml_station_remove(ahvif, ahsta); 6008 6009 ret = 0; 6010 6011 exit: 6012 /* update the state if everything went well */ 6013 if (!ret) 6014 ahsta->state = new_state; 6015 6016 return ret; 6017 } 6018 6019 static int ath12k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw, 6020 struct ieee80211_vif *vif, 6021 struct ieee80211_sta *sta) 6022 { 6023 struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); 6024 struct ath12k *ar; 6025 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 6026 struct ath12k_link_vif *arvif; 6027 struct ath12k_link_sta *arsta; 6028 u8 link_id; 6029 int ret; 6030 s16 txpwr; 6031 6032 lockdep_assert_wiphy(hw->wiphy); 6033 6034 /* TODO: use link id from mac80211 once that's implemented */ 6035 link_id = 0; 6036 6037 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 6038 arsta = wiphy_dereference(hw->wiphy, ahsta->link[link_id]); 6039 6040 if (sta->deflink.txpwr.type == NL80211_TX_POWER_AUTOMATIC) { 6041 txpwr = 0; 6042 } else { 6043 txpwr = sta->deflink.txpwr.power; 6044 if (!txpwr) { 6045 ret = -EINVAL; 6046 goto out; 6047 } 6048 } 6049 6050 if (txpwr > ATH12K_TX_POWER_MAX_VAL || txpwr < ATH12K_TX_POWER_MIN_VAL) { 6051 ret = -EINVAL; 6052 goto out; 6053 } 6054 6055 ar = arvif->ar; 6056 6057 ret = ath12k_wmi_set_peer_param(ar, arsta->addr, arvif->vdev_id, 6058 WMI_PEER_USE_FIXED_PWR, txpwr); 6059 if (ret) { 6060 ath12k_warn(ar->ab, "failed to set tx power for station ret: %d\n", 6061 ret); 6062 goto out; 6063 } 6064 6065 out: 6066 return ret; 6067 } 6068 6069 static void ath12k_mac_op_link_sta_rc_update(struct ieee80211_hw *hw, 6070 struct ieee80211_vif *vif, 6071 struct ieee80211_link_sta *link_sta, 6072 u32 changed) 6073 { 6074 struct ieee80211_sta *sta = link_sta->sta; 6075 struct ath12k *ar; 6076 struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); 6077 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 6078 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 6079 struct ath12k_link_sta *arsta; 6080 struct ath12k_link_vif *arvif; 6081 struct ath12k_peer *peer; 6082 u32 bw, smps; 6083 6084 rcu_read_lock(); 6085 arvif = rcu_dereference(ahvif->link[link_sta->link_id]); 6086 if (!arvif) { 6087 ath12k_hw_warn(ah, "mac sta rc update failed to fetch link vif on link id %u for peer %pM\n", 6088 link_sta->link_id, sta->addr); 6089 rcu_read_unlock(); 6090 return; 6091 } 6092 6093 ar = arvif->ar; 6094 6095 arsta = rcu_dereference(ahsta->link[link_sta->link_id]); 6096 if (!arsta) { 6097 rcu_read_unlock(); 6098 ath12k_warn(ar->ab, "mac sta rc update failed to fetch link sta on link id %u for peer %pM\n", 6099 link_sta->link_id, sta->addr); 6100 return; 6101 } 6102 spin_lock_bh(&ar->ab->base_lock); 6103 6104 peer = ath12k_peer_find(ar->ab, arvif->vdev_id, arsta->addr); 6105 if (!peer) { 6106 spin_unlock_bh(&ar->ab->base_lock); 6107 rcu_read_unlock(); 6108 ath12k_warn(ar->ab, "mac sta rc update failed to find peer %pM on vdev %i\n", 6109 arsta->addr, arvif->vdev_id); 6110 return; 6111 } 6112 6113 spin_unlock_bh(&ar->ab->base_lock); 6114 6115 if (arsta->link_id >= IEEE80211_MLD_MAX_NUM_LINKS) { 6116 rcu_read_unlock(); 6117 return; 6118 } 6119 6120 link_sta = rcu_dereference(sta->link[arsta->link_id]); 6121 if (!link_sta) { 6122 rcu_read_unlock(); 6123 ath12k_warn(ar->ab, "unable to access link sta in rc update for sta %pM link %u\n", 6124 sta->addr, arsta->link_id); 6125 return; 6126 } 6127 6128 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 6129 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", 6130 arsta->addr, changed, link_sta->bandwidth, link_sta->rx_nss, 6131 link_sta->smps_mode); 6132 6133 spin_lock_bh(&ar->data_lock); 6134 6135 if (changed & IEEE80211_RC_BW_CHANGED) { 6136 bw = ath12k_mac_ieee80211_sta_bw_to_wmi(ar, link_sta); 6137 arsta->bw_prev = arsta->bw; 6138 arsta->bw = bw; 6139 } 6140 6141 if (changed & IEEE80211_RC_NSS_CHANGED) 6142 arsta->nss = link_sta->rx_nss; 6143 6144 if (changed & IEEE80211_RC_SMPS_CHANGED) { 6145 smps = WMI_PEER_SMPS_PS_NONE; 6146 6147 switch (link_sta->smps_mode) { 6148 case IEEE80211_SMPS_AUTOMATIC: 6149 case IEEE80211_SMPS_OFF: 6150 smps = WMI_PEER_SMPS_PS_NONE; 6151 break; 6152 case IEEE80211_SMPS_STATIC: 6153 smps = WMI_PEER_SMPS_STATIC; 6154 break; 6155 case IEEE80211_SMPS_DYNAMIC: 6156 smps = WMI_PEER_SMPS_DYNAMIC; 6157 break; 6158 default: 6159 ath12k_warn(ar->ab, "Invalid smps %d in sta rc update for %pM link %u\n", 6160 link_sta->smps_mode, arsta->addr, link_sta->link_id); 6161 smps = WMI_PEER_SMPS_PS_NONE; 6162 break; 6163 } 6164 6165 arsta->smps = smps; 6166 } 6167 6168 arsta->changed |= changed; 6169 6170 spin_unlock_bh(&ar->data_lock); 6171 6172 wiphy_work_queue(hw->wiphy, &arsta->update_wk); 6173 6174 rcu_read_unlock(); 6175 } 6176 6177 static struct ath12k_link_sta *ath12k_mac_alloc_assign_link_sta(struct ath12k_hw *ah, 6178 struct ath12k_sta *ahsta, 6179 struct ath12k_vif *ahvif, 6180 u8 link_id) 6181 { 6182 struct ath12k_link_sta *arsta; 6183 int ret; 6184 6185 lockdep_assert_wiphy(ah->hw->wiphy); 6186 6187 if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) 6188 return NULL; 6189 6190 arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]); 6191 if (arsta) 6192 return NULL; 6193 6194 arsta = kmalloc(sizeof(*arsta), GFP_KERNEL); 6195 if (!arsta) 6196 return NULL; 6197 6198 ret = ath12k_mac_assign_link_sta(ah, ahsta, arsta, ahvif, link_id); 6199 if (ret) { 6200 kfree(arsta); 6201 return NULL; 6202 } 6203 6204 return arsta; 6205 } 6206 6207 static int ath12k_mac_op_change_sta_links(struct ieee80211_hw *hw, 6208 struct ieee80211_vif *vif, 6209 struct ieee80211_sta *sta, 6210 u16 old_links, u16 new_links) 6211 { 6212 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 6213 struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); 6214 struct ath12k_hw *ah = hw->priv; 6215 struct ath12k_link_vif *arvif; 6216 struct ath12k_link_sta *arsta; 6217 unsigned long valid_links; 6218 struct ath12k *ar; 6219 u8 link_id; 6220 int ret; 6221 6222 lockdep_assert_wiphy(hw->wiphy); 6223 6224 if (!sta->valid_links) 6225 return -EINVAL; 6226 6227 /* Firmware does not support removal of one of link stas. All sta 6228 * would be removed during ML STA delete in sta_state(), hence link 6229 * sta removal is not handled here. 6230 */ 6231 if (new_links < old_links) 6232 return 0; 6233 6234 if (ahsta->ml_peer_id == ATH12K_MLO_PEER_ID_INVALID) { 6235 ath12k_hw_warn(ah, "unable to add link for ml sta %pM", sta->addr); 6236 return -EINVAL; 6237 } 6238 6239 /* this op is expected only after initial sta insertion with default link */ 6240 if (WARN_ON(ahsta->links_map == 0)) 6241 return -EINVAL; 6242 6243 valid_links = new_links; 6244 for_each_set_bit(link_id, &valid_links, IEEE80211_MLD_MAX_NUM_LINKS) { 6245 if (ahsta->links_map & BIT(link_id)) 6246 continue; 6247 6248 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 6249 arsta = ath12k_mac_alloc_assign_link_sta(ah, ahsta, ahvif, link_id); 6250 6251 if (!arvif || !arsta) { 6252 ath12k_hw_warn(ah, "Failed to alloc/assign link sta"); 6253 continue; 6254 } 6255 6256 ar = arvif->ar; 6257 if (!ar) 6258 continue; 6259 6260 ret = ath12k_mac_station_add(ar, arvif, arsta); 6261 if (ret) { 6262 ath12k_warn(ar->ab, "Failed to add station: %pM for VDEV: %d\n", 6263 arsta->addr, arvif->vdev_id); 6264 ath12k_mac_free_unassign_link_sta(ah, ahsta, link_id); 6265 return ret; 6266 } 6267 } 6268 6269 return 0; 6270 } 6271 6272 static bool ath12k_mac_op_can_activate_links(struct ieee80211_hw *hw, 6273 struct ieee80211_vif *vif, 6274 u16 active_links) 6275 { 6276 /* TODO: Handle recovery case */ 6277 6278 return true; 6279 } 6280 6281 static int ath12k_conf_tx_uapsd(struct ath12k_link_vif *arvif, 6282 u16 ac, bool enable) 6283 { 6284 struct ath12k *ar = arvif->ar; 6285 struct ath12k_vif *ahvif = arvif->ahvif; 6286 u32 value; 6287 int ret; 6288 6289 if (ahvif->vdev_type != WMI_VDEV_TYPE_STA) 6290 return 0; 6291 6292 switch (ac) { 6293 case IEEE80211_AC_VO: 6294 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | 6295 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; 6296 break; 6297 case IEEE80211_AC_VI: 6298 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | 6299 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; 6300 break; 6301 case IEEE80211_AC_BE: 6302 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | 6303 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; 6304 break; 6305 case IEEE80211_AC_BK: 6306 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | 6307 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; 6308 break; 6309 } 6310 6311 if (enable) 6312 ahvif->u.sta.uapsd |= value; 6313 else 6314 ahvif->u.sta.uapsd &= ~value; 6315 6316 ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, 6317 WMI_STA_PS_PARAM_UAPSD, 6318 ahvif->u.sta.uapsd); 6319 if (ret) { 6320 ath12k_warn(ar->ab, "could not set uapsd params %d\n", ret); 6321 goto exit; 6322 } 6323 6324 if (ahvif->u.sta.uapsd) 6325 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; 6326 else 6327 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; 6328 6329 ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, 6330 WMI_STA_PS_PARAM_RX_WAKE_POLICY, 6331 value); 6332 if (ret) 6333 ath12k_warn(ar->ab, "could not set rx wake param %d\n", ret); 6334 6335 exit: 6336 return ret; 6337 } 6338 6339 static int ath12k_mac_conf_tx(struct ath12k_link_vif *arvif, u16 ac, 6340 const struct ieee80211_tx_queue_params *params) 6341 { 6342 struct wmi_wmm_params_arg *p = NULL; 6343 struct ath12k *ar = arvif->ar; 6344 struct ath12k_base *ab = ar->ab; 6345 int ret; 6346 6347 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 6348 6349 switch (ac) { 6350 case IEEE80211_AC_VO: 6351 p = &arvif->wmm_params.ac_vo; 6352 break; 6353 case IEEE80211_AC_VI: 6354 p = &arvif->wmm_params.ac_vi; 6355 break; 6356 case IEEE80211_AC_BE: 6357 p = &arvif->wmm_params.ac_be; 6358 break; 6359 case IEEE80211_AC_BK: 6360 p = &arvif->wmm_params.ac_bk; 6361 break; 6362 } 6363 6364 if (WARN_ON(!p)) { 6365 ret = -EINVAL; 6366 goto exit; 6367 } 6368 6369 p->cwmin = params->cw_min; 6370 p->cwmax = params->cw_max; 6371 p->aifs = params->aifs; 6372 p->txop = params->txop; 6373 6374 ret = ath12k_wmi_send_wmm_update_cmd(ar, arvif->vdev_id, 6375 &arvif->wmm_params); 6376 if (ret) { 6377 ath12k_warn(ab, "pdev idx %d failed to set wmm params: %d\n", 6378 ar->pdev_idx, ret); 6379 goto exit; 6380 } 6381 6382 ret = ath12k_conf_tx_uapsd(arvif, ac, params->uapsd); 6383 if (ret) 6384 ath12k_warn(ab, "pdev idx %d failed to set sta uapsd: %d\n", 6385 ar->pdev_idx, ret); 6386 6387 exit: 6388 return ret; 6389 } 6390 6391 static int ath12k_mac_op_conf_tx(struct ieee80211_hw *hw, 6392 struct ieee80211_vif *vif, 6393 unsigned int link_id, u16 ac, 6394 const struct ieee80211_tx_queue_params *params) 6395 { 6396 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 6397 struct ath12k_link_vif *arvif; 6398 struct ath12k_vif_cache *cache; 6399 int ret; 6400 6401 lockdep_assert_wiphy(hw->wiphy); 6402 6403 if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) 6404 return -EINVAL; 6405 6406 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 6407 if (!arvif || !arvif->is_created) { 6408 cache = ath12k_ahvif_get_link_cache(ahvif, link_id); 6409 if (!cache) 6410 return -ENOSPC; 6411 6412 cache->tx_conf.changed = true; 6413 cache->tx_conf.ac = ac; 6414 cache->tx_conf.tx_queue_params = *params; 6415 6416 return 0; 6417 } 6418 6419 ret = ath12k_mac_conf_tx(arvif, ac, params); 6420 6421 return ret; 6422 } 6423 6424 static struct ieee80211_sta_ht_cap 6425 ath12k_create_ht_cap(struct ath12k *ar, u32 ar_ht_cap, u32 rate_cap_rx_chainmask) 6426 { 6427 int i; 6428 struct ieee80211_sta_ht_cap ht_cap = {0}; 6429 u32 ar_vht_cap = ar->pdev->cap.vht_cap; 6430 6431 if (!(ar_ht_cap & WMI_HT_CAP_ENABLED)) 6432 return ht_cap; 6433 6434 ht_cap.ht_supported = 1; 6435 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; 6436 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; 6437 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; 6438 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; 6439 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT; 6440 6441 if (ar_ht_cap & WMI_HT_CAP_HT20_SGI) 6442 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; 6443 6444 if (ar_ht_cap & WMI_HT_CAP_HT40_SGI) 6445 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; 6446 6447 if (ar_ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) { 6448 u32 smps; 6449 6450 smps = WLAN_HT_CAP_SM_PS_DYNAMIC; 6451 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; 6452 6453 ht_cap.cap |= smps; 6454 } 6455 6456 if (ar_ht_cap & WMI_HT_CAP_TX_STBC) 6457 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; 6458 6459 if (ar_ht_cap & WMI_HT_CAP_RX_STBC) { 6460 u32 stbc; 6461 6462 stbc = ar_ht_cap; 6463 stbc &= WMI_HT_CAP_RX_STBC; 6464 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; 6465 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; 6466 stbc &= IEEE80211_HT_CAP_RX_STBC; 6467 6468 ht_cap.cap |= stbc; 6469 } 6470 6471 if (ar_ht_cap & WMI_HT_CAP_RX_LDPC) 6472 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; 6473 6474 if (ar_ht_cap & WMI_HT_CAP_L_SIG_TXOP_PROT) 6475 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; 6476 6477 if (ar_vht_cap & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) 6478 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; 6479 6480 for (i = 0; i < ar->num_rx_chains; i++) { 6481 if (rate_cap_rx_chainmask & BIT(i)) 6482 ht_cap.mcs.rx_mask[i] = 0xFF; 6483 } 6484 6485 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; 6486 6487 return ht_cap; 6488 } 6489 6490 static int ath12k_mac_set_txbf_conf(struct ath12k_link_vif *arvif) 6491 { 6492 u32 value = 0; 6493 struct ath12k *ar = arvif->ar; 6494 struct ath12k_vif *ahvif = arvif->ahvif; 6495 int nsts; 6496 int sound_dim; 6497 u32 vht_cap = ar->pdev->cap.vht_cap; 6498 u32 vdev_param = WMI_VDEV_PARAM_TXBF; 6499 6500 if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) { 6501 nsts = vht_cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; 6502 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; 6503 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET); 6504 } 6505 6506 if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) { 6507 sound_dim = vht_cap & 6508 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; 6509 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; 6510 if (sound_dim > (ar->num_tx_chains - 1)) 6511 sound_dim = ar->num_tx_chains - 1; 6512 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET); 6513 } 6514 6515 if (!value) 6516 return 0; 6517 6518 if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) { 6519 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; 6520 6521 if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) && 6522 ahvif->vdev_type == WMI_VDEV_TYPE_AP) 6523 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER; 6524 } 6525 6526 if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) { 6527 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; 6528 6529 if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) && 6530 ahvif->vdev_type == WMI_VDEV_TYPE_STA) 6531 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE; 6532 } 6533 6534 return ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 6535 vdev_param, value); 6536 } 6537 6538 static void ath12k_set_vht_txbf_cap(struct ath12k *ar, u32 *vht_cap) 6539 { 6540 bool subfer, subfee; 6541 int sound_dim = 0; 6542 6543 subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)); 6544 subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)); 6545 6546 if (ar->num_tx_chains < 2) { 6547 *vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE); 6548 subfer = false; 6549 } 6550 6551 /* If SU Beaformer is not set, then disable MU Beamformer Capability */ 6552 if (!subfer) 6553 *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE); 6554 6555 /* If SU Beaformee is not set, then disable MU Beamformee Capability */ 6556 if (!subfee) 6557 *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); 6558 6559 sound_dim = u32_get_bits(*vht_cap, 6560 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); 6561 *vht_cap = u32_replace_bits(*vht_cap, 0, 6562 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); 6563 6564 /* TODO: Need to check invalid STS and Sound_dim values set by FW? */ 6565 6566 /* Enable Sounding Dimension Field only if SU BF is enabled */ 6567 if (subfer) { 6568 if (sound_dim > (ar->num_tx_chains - 1)) 6569 sound_dim = ar->num_tx_chains - 1; 6570 6571 *vht_cap = u32_replace_bits(*vht_cap, sound_dim, 6572 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); 6573 } 6574 6575 /* Use the STS advertised by FW unless SU Beamformee is not supported*/ 6576 if (!subfee) 6577 *vht_cap &= ~(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK); 6578 } 6579 6580 static struct ieee80211_sta_vht_cap 6581 ath12k_create_vht_cap(struct ath12k *ar, u32 rate_cap_tx_chainmask, 6582 u32 rate_cap_rx_chainmask) 6583 { 6584 struct ieee80211_sta_vht_cap vht_cap = {0}; 6585 u16 txmcs_map, rxmcs_map; 6586 int i; 6587 6588 vht_cap.vht_supported = 1; 6589 vht_cap.cap = ar->pdev->cap.vht_cap; 6590 6591 ath12k_set_vht_txbf_cap(ar, &vht_cap.cap); 6592 6593 /* TODO: Enable back VHT160 mode once association issues are fixed */ 6594 /* Disabling VHT160 and VHT80+80 modes */ 6595 vht_cap.cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; 6596 vht_cap.cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160; 6597 6598 rxmcs_map = 0; 6599 txmcs_map = 0; 6600 for (i = 0; i < 8; i++) { 6601 if (i < ar->num_tx_chains && rate_cap_tx_chainmask & BIT(i)) 6602 txmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); 6603 else 6604 txmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); 6605 6606 if (i < ar->num_rx_chains && rate_cap_rx_chainmask & BIT(i)) 6607 rxmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); 6608 else 6609 rxmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); 6610 } 6611 6612 if (rate_cap_tx_chainmask <= 1) 6613 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC; 6614 6615 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_map); 6616 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_map); 6617 6618 return vht_cap; 6619 } 6620 6621 static void ath12k_mac_setup_ht_vht_cap(struct ath12k *ar, 6622 struct ath12k_pdev_cap *cap, 6623 u32 *ht_cap_info) 6624 { 6625 struct ieee80211_supported_band *band; 6626 u32 rate_cap_tx_chainmask; 6627 u32 rate_cap_rx_chainmask; 6628 u32 ht_cap; 6629 6630 rate_cap_tx_chainmask = ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift; 6631 rate_cap_rx_chainmask = ar->cfg_rx_chainmask >> cap->rx_chain_mask_shift; 6632 6633 if (cap->supported_bands & WMI_HOST_WLAN_2GHZ_CAP) { 6634 band = &ar->mac.sbands[NL80211_BAND_2GHZ]; 6635 ht_cap = cap->band[NL80211_BAND_2GHZ].ht_cap_info; 6636 if (ht_cap_info) 6637 *ht_cap_info = ht_cap; 6638 band->ht_cap = ath12k_create_ht_cap(ar, ht_cap, 6639 rate_cap_rx_chainmask); 6640 } 6641 6642 if (cap->supported_bands & WMI_HOST_WLAN_5GHZ_CAP && 6643 (ar->ab->hw_params->single_pdev_only || 6644 !ar->supports_6ghz)) { 6645 band = &ar->mac.sbands[NL80211_BAND_5GHZ]; 6646 ht_cap = cap->band[NL80211_BAND_5GHZ].ht_cap_info; 6647 if (ht_cap_info) 6648 *ht_cap_info = ht_cap; 6649 band->ht_cap = ath12k_create_ht_cap(ar, ht_cap, 6650 rate_cap_rx_chainmask); 6651 band->vht_cap = ath12k_create_vht_cap(ar, rate_cap_tx_chainmask, 6652 rate_cap_rx_chainmask); 6653 } 6654 } 6655 6656 static int ath12k_check_chain_mask(struct ath12k *ar, u32 ant, bool is_tx_ant) 6657 { 6658 /* TODO: Check the request chainmask against the supported 6659 * chainmask table which is advertised in extented_service_ready event 6660 */ 6661 6662 return 0; 6663 } 6664 6665 static void ath12k_gen_ppe_thresh(struct ath12k_wmi_ppe_threshold_arg *fw_ppet, 6666 u8 *he_ppet) 6667 { 6668 int nss, ru; 6669 u8 bit = 7; 6670 6671 he_ppet[0] = fw_ppet->numss_m1 & IEEE80211_PPE_THRES_NSS_MASK; 6672 he_ppet[0] |= (fw_ppet->ru_bit_mask << 6673 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS) & 6674 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK; 6675 for (nss = 0; nss <= fw_ppet->numss_m1; nss++) { 6676 for (ru = 0; ru < 4; ru++) { 6677 u8 val; 6678 int i; 6679 6680 if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0) 6681 continue; 6682 val = (fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> (ru * 6)) & 6683 0x3f; 6684 val = ((val >> 3) & 0x7) | ((val & 0x7) << 3); 6685 for (i = 5; i >= 0; i--) { 6686 he_ppet[bit / 8] |= 6687 ((val >> i) & 0x1) << ((bit % 8)); 6688 bit++; 6689 } 6690 } 6691 } 6692 } 6693 6694 static void 6695 ath12k_mac_filter_he_cap_mesh(struct ieee80211_he_cap_elem *he_cap_elem) 6696 { 6697 u8 m; 6698 6699 m = IEEE80211_HE_MAC_CAP0_TWT_RES | 6700 IEEE80211_HE_MAC_CAP0_TWT_REQ; 6701 he_cap_elem->mac_cap_info[0] &= ~m; 6702 6703 m = IEEE80211_HE_MAC_CAP2_TRS | 6704 IEEE80211_HE_MAC_CAP2_BCAST_TWT | 6705 IEEE80211_HE_MAC_CAP2_MU_CASCADING; 6706 he_cap_elem->mac_cap_info[2] &= ~m; 6707 6708 m = IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED | 6709 IEEE80211_HE_MAC_CAP2_BCAST_TWT | 6710 IEEE80211_HE_MAC_CAP2_MU_CASCADING; 6711 he_cap_elem->mac_cap_info[3] &= ~m; 6712 6713 m = IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG | 6714 IEEE80211_HE_MAC_CAP4_BQR; 6715 he_cap_elem->mac_cap_info[4] &= ~m; 6716 6717 m = IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECTIVE_TRANSMISSION | 6718 IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU | 6719 IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING | 6720 IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX; 6721 he_cap_elem->mac_cap_info[5] &= ~m; 6722 6723 m = IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | 6724 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO; 6725 he_cap_elem->phy_cap_info[2] &= ~m; 6726 6727 m = IEEE80211_HE_PHY_CAP3_RX_PARTIAL_BW_SU_IN_20MHZ_MU | 6728 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK | 6729 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK; 6730 he_cap_elem->phy_cap_info[3] &= ~m; 6731 6732 m = IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER; 6733 he_cap_elem->phy_cap_info[4] &= ~m; 6734 6735 m = IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK; 6736 he_cap_elem->phy_cap_info[5] &= ~m; 6737 6738 m = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU | 6739 IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB | 6740 IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB | 6741 IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO; 6742 he_cap_elem->phy_cap_info[6] &= ~m; 6743 6744 m = IEEE80211_HE_PHY_CAP7_PSR_BASED_SR | 6745 IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP | 6746 IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ | 6747 IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ; 6748 he_cap_elem->phy_cap_info[7] &= ~m; 6749 6750 m = IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI | 6751 IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G | 6752 IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU | 6753 IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU; 6754 he_cap_elem->phy_cap_info[8] &= ~m; 6755 6756 m = IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM | 6757 IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK | 6758 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU | 6759 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU | 6760 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB | 6761 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB; 6762 he_cap_elem->phy_cap_info[9] &= ~m; 6763 } 6764 6765 static __le16 ath12k_mac_setup_he_6ghz_cap(struct ath12k_pdev_cap *pcap, 6766 struct ath12k_band_cap *bcap) 6767 { 6768 u8 val; 6769 6770 bcap->he_6ghz_capa = IEEE80211_HT_MPDU_DENSITY_NONE; 6771 if (bcap->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) 6772 bcap->he_6ghz_capa |= 6773 u32_encode_bits(WLAN_HT_CAP_SM_PS_DYNAMIC, 6774 IEEE80211_HE_6GHZ_CAP_SM_PS); 6775 else 6776 bcap->he_6ghz_capa |= 6777 u32_encode_bits(WLAN_HT_CAP_SM_PS_DISABLED, 6778 IEEE80211_HE_6GHZ_CAP_SM_PS); 6779 val = u32_get_bits(pcap->vht_cap, 6780 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK); 6781 bcap->he_6ghz_capa |= 6782 u32_encode_bits(val, IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP); 6783 val = u32_get_bits(pcap->vht_cap, 6784 IEEE80211_VHT_CAP_MAX_MPDU_MASK); 6785 bcap->he_6ghz_capa |= 6786 u32_encode_bits(val, IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN); 6787 if (pcap->vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN) 6788 bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS; 6789 if (pcap->vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN) 6790 bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS; 6791 6792 return cpu_to_le16(bcap->he_6ghz_capa); 6793 } 6794 6795 static void ath12k_mac_copy_he_cap(struct ath12k_band_cap *band_cap, 6796 int iftype, u8 num_tx_chains, 6797 struct ieee80211_sta_he_cap *he_cap) 6798 { 6799 struct ieee80211_he_cap_elem *he_cap_elem = &he_cap->he_cap_elem; 6800 struct ieee80211_he_mcs_nss_supp *mcs_nss = &he_cap->he_mcs_nss_supp; 6801 6802 he_cap->has_he = true; 6803 memcpy(he_cap_elem->mac_cap_info, band_cap->he_cap_info, 6804 sizeof(he_cap_elem->mac_cap_info)); 6805 memcpy(he_cap_elem->phy_cap_info, band_cap->he_cap_phy_info, 6806 sizeof(he_cap_elem->phy_cap_info)); 6807 6808 he_cap_elem->mac_cap_info[1] &= 6809 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK; 6810 6811 he_cap_elem->phy_cap_info[5] &= 6812 ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK; 6813 he_cap_elem->phy_cap_info[5] &= 6814 ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK; 6815 he_cap_elem->phy_cap_info[5] |= num_tx_chains - 1; 6816 6817 switch (iftype) { 6818 case NL80211_IFTYPE_AP: 6819 he_cap_elem->mac_cap_info[2] &= 6820 ~IEEE80211_HE_MAC_CAP2_BCAST_TWT; 6821 he_cap_elem->phy_cap_info[3] &= 6822 ~IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK; 6823 he_cap_elem->phy_cap_info[9] |= 6824 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU; 6825 break; 6826 case NL80211_IFTYPE_STATION: 6827 he_cap_elem->mac_cap_info[0] &= ~IEEE80211_HE_MAC_CAP0_TWT_RES; 6828 he_cap_elem->mac_cap_info[0] |= IEEE80211_HE_MAC_CAP0_TWT_REQ; 6829 he_cap_elem->phy_cap_info[9] |= 6830 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU; 6831 break; 6832 case NL80211_IFTYPE_MESH_POINT: 6833 ath12k_mac_filter_he_cap_mesh(he_cap_elem); 6834 break; 6835 } 6836 6837 mcs_nss->rx_mcs_80 = cpu_to_le16(band_cap->he_mcs & 0xffff); 6838 mcs_nss->tx_mcs_80 = cpu_to_le16(band_cap->he_mcs & 0xffff); 6839 mcs_nss->rx_mcs_160 = cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); 6840 mcs_nss->tx_mcs_160 = cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); 6841 mcs_nss->rx_mcs_80p80 = cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); 6842 mcs_nss->tx_mcs_80p80 = cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); 6843 6844 memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres)); 6845 if (he_cap_elem->phy_cap_info[6] & 6846 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) 6847 ath12k_gen_ppe_thresh(&band_cap->he_ppet, he_cap->ppe_thres); 6848 } 6849 6850 static void 6851 ath12k_mac_copy_eht_mcs_nss(struct ath12k_band_cap *band_cap, 6852 struct ieee80211_eht_mcs_nss_supp *mcs_nss, 6853 const struct ieee80211_he_cap_elem *he_cap, 6854 const struct ieee80211_eht_cap_elem_fixed *eht_cap) 6855 { 6856 if ((he_cap->phy_cap_info[0] & 6857 (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G | 6858 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | 6859 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | 6860 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)) == 0) 6861 memcpy(&mcs_nss->only_20mhz, &band_cap->eht_mcs_20_only, 6862 sizeof(struct ieee80211_eht_mcs_nss_supp_20mhz_only)); 6863 6864 if (he_cap->phy_cap_info[0] & 6865 (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G | 6866 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G)) 6867 memcpy(&mcs_nss->bw._80, &band_cap->eht_mcs_80, 6868 sizeof(struct ieee80211_eht_mcs_nss_supp_bw)); 6869 6870 if (he_cap->phy_cap_info[0] & 6871 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) 6872 memcpy(&mcs_nss->bw._160, &band_cap->eht_mcs_160, 6873 sizeof(struct ieee80211_eht_mcs_nss_supp_bw)); 6874 6875 if (eht_cap->phy_cap_info[0] & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ) 6876 memcpy(&mcs_nss->bw._320, &band_cap->eht_mcs_320, 6877 sizeof(struct ieee80211_eht_mcs_nss_supp_bw)); 6878 } 6879 6880 static void ath12k_mac_copy_eht_ppe_thresh(struct ath12k_wmi_ppe_threshold_arg *fw_ppet, 6881 struct ieee80211_sta_eht_cap *cap) 6882 { 6883 u16 bit = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE; 6884 u8 i, nss, ru, ppet_bit_len_per_ru = IEEE80211_EHT_PPE_THRES_INFO_PPET_SIZE * 2; 6885 6886 u8p_replace_bits(&cap->eht_ppe_thres[0], fw_ppet->numss_m1, 6887 IEEE80211_EHT_PPE_THRES_NSS_MASK); 6888 6889 u16p_replace_bits((u16 *)&cap->eht_ppe_thres[0], fw_ppet->ru_bit_mask, 6890 IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); 6891 6892 for (nss = 0; nss <= fw_ppet->numss_m1; nss++) { 6893 for (ru = 0; 6894 ru < hweight16(IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); 6895 ru++) { 6896 u32 val = 0; 6897 6898 if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0) 6899 continue; 6900 6901 u32p_replace_bits(&val, fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> 6902 (ru * ppet_bit_len_per_ru), 6903 GENMASK(ppet_bit_len_per_ru - 1, 0)); 6904 6905 for (i = 0; i < ppet_bit_len_per_ru; i++) { 6906 cap->eht_ppe_thres[bit / 8] |= 6907 (((val >> i) & 0x1) << ((bit % 8))); 6908 bit++; 6909 } 6910 } 6911 } 6912 } 6913 6914 static void 6915 ath12k_mac_filter_eht_cap_mesh(struct ieee80211_eht_cap_elem_fixed 6916 *eht_cap_elem) 6917 { 6918 u8 m; 6919 6920 m = IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS; 6921 eht_cap_elem->mac_cap_info[0] &= ~m; 6922 6923 m = IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO; 6924 eht_cap_elem->phy_cap_info[0] &= ~m; 6925 6926 m = IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK | 6927 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK | 6928 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK | 6929 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK; 6930 eht_cap_elem->phy_cap_info[3] &= ~m; 6931 6932 m = IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO | 6933 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP | 6934 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP | 6935 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI; 6936 eht_cap_elem->phy_cap_info[4] &= ~m; 6937 6938 m = IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK | 6939 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP | 6940 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP | 6941 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK; 6942 eht_cap_elem->phy_cap_info[5] &= ~m; 6943 6944 m = IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK; 6945 eht_cap_elem->phy_cap_info[6] &= ~m; 6946 6947 m = IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ | 6948 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ | 6949 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ | 6950 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | 6951 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ | 6952 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ; 6953 eht_cap_elem->phy_cap_info[7] &= ~m; 6954 } 6955 6956 static void ath12k_mac_copy_eht_cap(struct ath12k *ar, 6957 struct ath12k_band_cap *band_cap, 6958 struct ieee80211_he_cap_elem *he_cap_elem, 6959 int iftype, 6960 struct ieee80211_sta_eht_cap *eht_cap) 6961 { 6962 struct ieee80211_eht_cap_elem_fixed *eht_cap_elem = &eht_cap->eht_cap_elem; 6963 6964 memset(eht_cap, 0, sizeof(struct ieee80211_sta_eht_cap)); 6965 6966 if (!(test_bit(WMI_TLV_SERVICE_11BE, ar->ab->wmi_ab.svc_map)) || 6967 ath12k_acpi_get_disable_11be(ar->ab)) 6968 return; 6969 6970 eht_cap->has_eht = true; 6971 memcpy(eht_cap_elem->mac_cap_info, band_cap->eht_cap_mac_info, 6972 sizeof(eht_cap_elem->mac_cap_info)); 6973 memcpy(eht_cap_elem->phy_cap_info, band_cap->eht_cap_phy_info, 6974 sizeof(eht_cap_elem->phy_cap_info)); 6975 6976 switch (iftype) { 6977 case NL80211_IFTYPE_AP: 6978 eht_cap_elem->phy_cap_info[0] &= 6979 ~IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ; 6980 eht_cap_elem->phy_cap_info[4] &= 6981 ~IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO; 6982 eht_cap_elem->phy_cap_info[5] &= 6983 ~IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP; 6984 break; 6985 case NL80211_IFTYPE_STATION: 6986 eht_cap_elem->phy_cap_info[7] &= 6987 ~(IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ | 6988 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ | 6989 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ); 6990 eht_cap_elem->phy_cap_info[7] &= 6991 ~(IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | 6992 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ | 6993 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ); 6994 break; 6995 case NL80211_IFTYPE_MESH_POINT: 6996 ath12k_mac_filter_eht_cap_mesh(eht_cap_elem); 6997 break; 6998 default: 6999 break; 7000 } 7001 7002 ath12k_mac_copy_eht_mcs_nss(band_cap, &eht_cap->eht_mcs_nss_supp, 7003 he_cap_elem, eht_cap_elem); 7004 7005 if (eht_cap_elem->phy_cap_info[5] & 7006 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) 7007 ath12k_mac_copy_eht_ppe_thresh(&band_cap->eht_ppet, eht_cap); 7008 } 7009 7010 static int ath12k_mac_copy_sband_iftype_data(struct ath12k *ar, 7011 struct ath12k_pdev_cap *cap, 7012 struct ieee80211_sband_iftype_data *data, 7013 int band) 7014 { 7015 struct ath12k_band_cap *band_cap = &cap->band[band]; 7016 int i, idx = 0; 7017 7018 for (i = 0; i < NUM_NL80211_IFTYPES; i++) { 7019 struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap; 7020 7021 switch (i) { 7022 case NL80211_IFTYPE_STATION: 7023 case NL80211_IFTYPE_AP: 7024 case NL80211_IFTYPE_MESH_POINT: 7025 break; 7026 7027 default: 7028 continue; 7029 } 7030 7031 data[idx].types_mask = BIT(i); 7032 7033 ath12k_mac_copy_he_cap(band_cap, i, ar->num_tx_chains, he_cap); 7034 if (band == NL80211_BAND_6GHZ) { 7035 data[idx].he_6ghz_capa.capa = 7036 ath12k_mac_setup_he_6ghz_cap(cap, band_cap); 7037 } 7038 ath12k_mac_copy_eht_cap(ar, band_cap, &he_cap->he_cap_elem, i, 7039 &data[idx].eht_cap); 7040 idx++; 7041 } 7042 7043 return idx; 7044 } 7045 7046 static void ath12k_mac_setup_sband_iftype_data(struct ath12k *ar, 7047 struct ath12k_pdev_cap *cap) 7048 { 7049 struct ieee80211_supported_band *sband; 7050 enum nl80211_band band; 7051 int count; 7052 7053 if (cap->supported_bands & WMI_HOST_WLAN_2GHZ_CAP) { 7054 band = NL80211_BAND_2GHZ; 7055 count = ath12k_mac_copy_sband_iftype_data(ar, cap, 7056 ar->mac.iftype[band], 7057 band); 7058 sband = &ar->mac.sbands[band]; 7059 _ieee80211_set_sband_iftype_data(sband, ar->mac.iftype[band], 7060 count); 7061 } 7062 7063 if (cap->supported_bands & WMI_HOST_WLAN_5GHZ_CAP) { 7064 band = NL80211_BAND_5GHZ; 7065 count = ath12k_mac_copy_sband_iftype_data(ar, cap, 7066 ar->mac.iftype[band], 7067 band); 7068 sband = &ar->mac.sbands[band]; 7069 _ieee80211_set_sband_iftype_data(sband, ar->mac.iftype[band], 7070 count); 7071 } 7072 7073 if (cap->supported_bands & WMI_HOST_WLAN_5GHZ_CAP && 7074 ar->supports_6ghz) { 7075 band = NL80211_BAND_6GHZ; 7076 count = ath12k_mac_copy_sband_iftype_data(ar, cap, 7077 ar->mac.iftype[band], 7078 band); 7079 sband = &ar->mac.sbands[band]; 7080 _ieee80211_set_sband_iftype_data(sband, ar->mac.iftype[band], 7081 count); 7082 } 7083 } 7084 7085 static int __ath12k_set_antenna(struct ath12k *ar, u32 tx_ant, u32 rx_ant) 7086 { 7087 struct ath12k_hw *ah = ath12k_ar_to_ah(ar); 7088 int ret; 7089 7090 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 7091 7092 if (ath12k_check_chain_mask(ar, tx_ant, true)) 7093 return -EINVAL; 7094 7095 if (ath12k_check_chain_mask(ar, rx_ant, false)) 7096 return -EINVAL; 7097 7098 /* Since we advertised the max cap of all radios combined during wiphy 7099 * registration, ensure we don't set the antenna config higher than the 7100 * limits 7101 */ 7102 tx_ant = min_t(u32, tx_ant, ar->pdev->cap.tx_chain_mask); 7103 rx_ant = min_t(u32, rx_ant, ar->pdev->cap.rx_chain_mask); 7104 7105 ar->cfg_tx_chainmask = tx_ant; 7106 ar->cfg_rx_chainmask = rx_ant; 7107 7108 if (ah->state != ATH12K_HW_STATE_ON && 7109 ah->state != ATH12K_HW_STATE_RESTARTED) 7110 return 0; 7111 7112 ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_TX_CHAIN_MASK, 7113 tx_ant, ar->pdev->pdev_id); 7114 if (ret) { 7115 ath12k_warn(ar->ab, "failed to set tx-chainmask: %d, req 0x%x\n", 7116 ret, tx_ant); 7117 return ret; 7118 } 7119 7120 ar->num_tx_chains = hweight32(tx_ant); 7121 7122 ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RX_CHAIN_MASK, 7123 rx_ant, ar->pdev->pdev_id); 7124 if (ret) { 7125 ath12k_warn(ar->ab, "failed to set rx-chainmask: %d, req 0x%x\n", 7126 ret, rx_ant); 7127 return ret; 7128 } 7129 7130 ar->num_rx_chains = hweight32(rx_ant); 7131 7132 /* Reload HT/VHT/HE capability */ 7133 ath12k_mac_setup_ht_vht_cap(ar, &ar->pdev->cap, NULL); 7134 ath12k_mac_setup_sband_iftype_data(ar, &ar->pdev->cap); 7135 7136 return 0; 7137 } 7138 7139 static void ath12k_mgmt_over_wmi_tx_drop(struct ath12k *ar, struct sk_buff *skb) 7140 { 7141 int num_mgmt; 7142 7143 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 7144 7145 ieee80211_free_txskb(ath12k_ar_to_hw(ar), skb); 7146 7147 num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx); 7148 7149 if (num_mgmt < 0) 7150 WARN_ON_ONCE(1); 7151 7152 if (!num_mgmt) 7153 wake_up(&ar->txmgmt_empty_waitq); 7154 } 7155 7156 int ath12k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx) 7157 { 7158 struct sk_buff *msdu = skb; 7159 struct ieee80211_tx_info *info; 7160 struct ath12k *ar = ctx; 7161 struct ath12k_base *ab = ar->ab; 7162 7163 spin_lock_bh(&ar->txmgmt_idr_lock); 7164 idr_remove(&ar->txmgmt_idr, buf_id); 7165 spin_unlock_bh(&ar->txmgmt_idr_lock); 7166 dma_unmap_single(ab->dev, ATH12K_SKB_CB(msdu)->paddr, msdu->len, 7167 DMA_TO_DEVICE); 7168 7169 info = IEEE80211_SKB_CB(msdu); 7170 memset(&info->status, 0, sizeof(info->status)); 7171 7172 ath12k_mgmt_over_wmi_tx_drop(ar, skb); 7173 7174 return 0; 7175 } 7176 7177 static int ath12k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx) 7178 { 7179 struct ieee80211_vif *vif = ctx; 7180 struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb); 7181 struct sk_buff *msdu = skb; 7182 struct ath12k *ar = skb_cb->ar; 7183 struct ath12k_base *ab = ar->ab; 7184 7185 if (skb_cb->vif == vif) { 7186 spin_lock_bh(&ar->txmgmt_idr_lock); 7187 idr_remove(&ar->txmgmt_idr, buf_id); 7188 spin_unlock_bh(&ar->txmgmt_idr_lock); 7189 dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, 7190 DMA_TO_DEVICE); 7191 } 7192 7193 return 0; 7194 } 7195 7196 static int ath12k_mac_mgmt_tx_wmi(struct ath12k *ar, struct ath12k_link_vif *arvif, 7197 struct sk_buff *skb) 7198 { 7199 struct ath12k_base *ab = ar->ab; 7200 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 7201 struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb); 7202 struct ieee80211_tx_info *info; 7203 enum hal_encrypt_type enctype; 7204 unsigned int mic_len; 7205 dma_addr_t paddr; 7206 int buf_id; 7207 int ret; 7208 7209 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 7210 7211 skb_cb->ar = ar; 7212 spin_lock_bh(&ar->txmgmt_idr_lock); 7213 buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0, 7214 ATH12K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC); 7215 spin_unlock_bh(&ar->txmgmt_idr_lock); 7216 if (buf_id < 0) 7217 return -ENOSPC; 7218 7219 info = IEEE80211_SKB_CB(skb); 7220 if ((skb_cb->flags & ATH12K_SKB_CIPHER_SET) && 7221 !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) { 7222 if ((ieee80211_is_action(hdr->frame_control) || 7223 ieee80211_is_deauth(hdr->frame_control) || 7224 ieee80211_is_disassoc(hdr->frame_control)) && 7225 ieee80211_has_protected(hdr->frame_control)) { 7226 enctype = ath12k_dp_tx_get_encrypt_type(skb_cb->cipher); 7227 mic_len = ath12k_dp_rx_crypto_mic_len(ar, enctype); 7228 skb_put(skb, mic_len); 7229 } 7230 } 7231 7232 paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE); 7233 if (dma_mapping_error(ab->dev, paddr)) { 7234 ath12k_warn(ab, "failed to DMA map mgmt Tx buffer\n"); 7235 ret = -EIO; 7236 goto err_free_idr; 7237 } 7238 7239 skb_cb->paddr = paddr; 7240 7241 ret = ath12k_wmi_mgmt_send(ar, arvif->vdev_id, buf_id, skb); 7242 if (ret) { 7243 ath12k_warn(ar->ab, "failed to send mgmt frame: %d\n", ret); 7244 goto err_unmap_buf; 7245 } 7246 7247 return 0; 7248 7249 err_unmap_buf: 7250 dma_unmap_single(ab->dev, skb_cb->paddr, 7251 skb->len, DMA_TO_DEVICE); 7252 err_free_idr: 7253 spin_lock_bh(&ar->txmgmt_idr_lock); 7254 idr_remove(&ar->txmgmt_idr, buf_id); 7255 spin_unlock_bh(&ar->txmgmt_idr_lock); 7256 7257 return ret; 7258 } 7259 7260 static void ath12k_mgmt_over_wmi_tx_purge(struct ath12k *ar) 7261 { 7262 struct sk_buff *skb; 7263 7264 while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) 7265 ath12k_mgmt_over_wmi_tx_drop(ar, skb); 7266 } 7267 7268 static void ath12k_mgmt_over_wmi_tx_work(struct wiphy *wiphy, struct wiphy_work *work) 7269 { 7270 struct ath12k *ar = container_of(work, struct ath12k, wmi_mgmt_tx_work); 7271 struct ath12k_hw *ah = ar->ah; 7272 struct ath12k_skb_cb *skb_cb; 7273 struct ath12k_vif *ahvif; 7274 struct ath12k_link_vif *arvif; 7275 struct sk_buff *skb; 7276 int ret; 7277 7278 lockdep_assert_wiphy(wiphy); 7279 7280 while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) { 7281 skb_cb = ATH12K_SKB_CB(skb); 7282 if (!skb_cb->vif) { 7283 ath12k_warn(ar->ab, "no vif found for mgmt frame\n"); 7284 ath12k_mgmt_over_wmi_tx_drop(ar, skb); 7285 continue; 7286 } 7287 7288 ahvif = ath12k_vif_to_ahvif(skb_cb->vif); 7289 if (!(ahvif->links_map & BIT(skb_cb->link_id))) { 7290 ath12k_warn(ar->ab, 7291 "invalid linkid %u in mgmt over wmi tx with linkmap 0x%x\n", 7292 skb_cb->link_id, ahvif->links_map); 7293 ath12k_mgmt_over_wmi_tx_drop(ar, skb); 7294 continue; 7295 } 7296 7297 arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[skb_cb->link_id]); 7298 if (ar->allocated_vdev_map & (1LL << arvif->vdev_id)) { 7299 ret = ath12k_mac_mgmt_tx_wmi(ar, arvif, skb); 7300 if (ret) { 7301 ath12k_warn(ar->ab, "failed to tx mgmt frame, vdev_id %d :%d\n", 7302 arvif->vdev_id, ret); 7303 ath12k_mgmt_over_wmi_tx_drop(ar, skb); 7304 } 7305 } else { 7306 ath12k_warn(ar->ab, 7307 "dropping mgmt frame for vdev %d link %u is_started %d\n", 7308 arvif->vdev_id, 7309 skb_cb->link_id, 7310 arvif->is_started); 7311 ath12k_mgmt_over_wmi_tx_drop(ar, skb); 7312 } 7313 } 7314 } 7315 7316 static int ath12k_mac_mgmt_tx(struct ath12k *ar, struct sk_buff *skb, 7317 bool is_prb_rsp) 7318 { 7319 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue; 7320 7321 if (test_bit(ATH12K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags)) 7322 return -ESHUTDOWN; 7323 7324 /* Drop probe response packets when the pending management tx 7325 * count has reached a certain threshold, so as to prioritize 7326 * other mgmt packets like auth and assoc to be sent on time 7327 * for establishing successful connections. 7328 */ 7329 if (is_prb_rsp && 7330 atomic_read(&ar->num_pending_mgmt_tx) > ATH12K_PRB_RSP_DROP_THRESHOLD) { 7331 ath12k_warn(ar->ab, 7332 "dropping probe response as pending queue is almost full\n"); 7333 return -ENOSPC; 7334 } 7335 7336 if (skb_queue_len_lockless(q) >= ATH12K_TX_MGMT_NUM_PENDING_MAX) { 7337 ath12k_warn(ar->ab, "mgmt tx queue is full\n"); 7338 return -ENOSPC; 7339 } 7340 7341 skb_queue_tail(q, skb); 7342 atomic_inc(&ar->num_pending_mgmt_tx); 7343 wiphy_work_queue(ath12k_ar_to_hw(ar)->wiphy, &ar->wmi_mgmt_tx_work); 7344 7345 return 0; 7346 } 7347 7348 static void ath12k_mac_add_p2p_noa_ie(struct ath12k *ar, 7349 struct ieee80211_vif *vif, 7350 struct sk_buff *skb, 7351 bool is_prb_rsp) 7352 { 7353 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 7354 7355 if (likely(!is_prb_rsp)) 7356 return; 7357 7358 spin_lock_bh(&ar->data_lock); 7359 7360 if (ahvif->u.ap.noa_data && 7361 !pskb_expand_head(skb, 0, ahvif->u.ap.noa_len, 7362 GFP_ATOMIC)) 7363 skb_put_data(skb, ahvif->u.ap.noa_data, 7364 ahvif->u.ap.noa_len); 7365 7366 spin_unlock_bh(&ar->data_lock); 7367 } 7368 7369 /* Note: called under rcu_read_lock() */ 7370 static void ath12k_mlo_mcast_update_tx_link_address(struct ieee80211_vif *vif, 7371 u8 link_id, struct sk_buff *skb, 7372 u32 info_flags) 7373 { 7374 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 7375 struct ieee80211_bss_conf *bss_conf; 7376 7377 if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP) 7378 return; 7379 7380 bss_conf = rcu_dereference(vif->link_conf[link_id]); 7381 if (bss_conf) 7382 ether_addr_copy(hdr->addr2, bss_conf->addr); 7383 } 7384 7385 /* Note: called under rcu_read_lock() */ 7386 static u8 ath12k_mac_get_tx_link(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 7387 u8 link, struct sk_buff *skb, u32 info_flags) 7388 { 7389 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 7390 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 7391 struct ieee80211_link_sta *link_sta; 7392 struct ieee80211_bss_conf *bss_conf; 7393 struct ath12k_sta *ahsta; 7394 7395 /* Use the link id passed or the default vif link */ 7396 if (!sta) { 7397 if (link != IEEE80211_LINK_UNSPECIFIED) 7398 return link; 7399 7400 return ahvif->deflink.link_id; 7401 } 7402 7403 ahsta = ath12k_sta_to_ahsta(sta); 7404 7405 /* Below translation ensures we pass proper A2 & A3 for non ML clients. 7406 * Also it assumes for now support only for MLO AP in this path 7407 */ 7408 if (!sta->mlo) { 7409 link = ahsta->deflink.link_id; 7410 7411 if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP) 7412 return link; 7413 7414 bss_conf = rcu_dereference(vif->link_conf[link]); 7415 if (bss_conf) { 7416 ether_addr_copy(hdr->addr2, bss_conf->addr); 7417 if (!ieee80211_has_tods(hdr->frame_control) && 7418 !ieee80211_has_fromds(hdr->frame_control)) 7419 ether_addr_copy(hdr->addr3, bss_conf->addr); 7420 } 7421 7422 return link; 7423 } 7424 7425 /* enqueue eth enacap & data frames on primary link, FW does link 7426 * selection and address translation. 7427 */ 7428 if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP || 7429 ieee80211_is_data(hdr->frame_control)) 7430 return ahsta->assoc_link_id; 7431 7432 /* 802.11 frame cases */ 7433 if (link == IEEE80211_LINK_UNSPECIFIED) 7434 link = ahsta->deflink.link_id; 7435 7436 if (!ieee80211_is_mgmt(hdr->frame_control)) 7437 return link; 7438 7439 /* Perform address conversion for ML STA Tx */ 7440 bss_conf = rcu_dereference(vif->link_conf[link]); 7441 link_sta = rcu_dereference(sta->link[link]); 7442 7443 if (bss_conf && link_sta) { 7444 ether_addr_copy(hdr->addr1, link_sta->addr); 7445 ether_addr_copy(hdr->addr2, bss_conf->addr); 7446 7447 if (vif->type == NL80211_IFTYPE_STATION && bss_conf->bssid) 7448 ether_addr_copy(hdr->addr3, bss_conf->bssid); 7449 else if (vif->type == NL80211_IFTYPE_AP) 7450 ether_addr_copy(hdr->addr3, bss_conf->addr); 7451 7452 return link; 7453 } 7454 7455 if (bss_conf) { 7456 /* In certain cases where a ML sta associated and added subset of 7457 * links on which the ML AP is active, but now sends some frame 7458 * (ex. Probe request) on a different link which is active in our 7459 * MLD but was not added during previous association, we can 7460 * still honor the Tx to that ML STA via the requested link. 7461 * The control would reach here in such case only when that link 7462 * address is same as the MLD address or in worst case clients 7463 * used MLD address at TA wrongly which would have helped 7464 * identify the ML sta object and pass it here. 7465 * If the link address of that STA is different from MLD address, 7466 * then the sta object would be NULL and control won't reach 7467 * here but return at the start of the function itself with !sta 7468 * check. Also this would not need any translation at hdr->addr1 7469 * from MLD to link address since the RA is the MLD address 7470 * (same as that link address ideally) already. 7471 */ 7472 ether_addr_copy(hdr->addr2, bss_conf->addr); 7473 7474 if (vif->type == NL80211_IFTYPE_STATION && bss_conf->bssid) 7475 ether_addr_copy(hdr->addr3, bss_conf->bssid); 7476 else if (vif->type == NL80211_IFTYPE_AP) 7477 ether_addr_copy(hdr->addr3, bss_conf->addr); 7478 } 7479 7480 return link; 7481 } 7482 7483 /* Note: called under rcu_read_lock() */ 7484 static void ath12k_mac_op_tx(struct ieee80211_hw *hw, 7485 struct ieee80211_tx_control *control, 7486 struct sk_buff *skb) 7487 { 7488 struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb); 7489 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 7490 struct ieee80211_vif *vif = info->control.vif; 7491 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 7492 struct ath12k_link_vif *arvif = &ahvif->deflink; 7493 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 7494 struct ieee80211_key_conf *key = info->control.hw_key; 7495 struct ieee80211_sta *sta = control->sta; 7496 struct ath12k_link_vif *tmp_arvif; 7497 u32 info_flags = info->flags; 7498 struct sk_buff *msdu_copied; 7499 struct ath12k *ar, *tmp_ar; 7500 struct ath12k_peer *peer; 7501 unsigned long links_map; 7502 bool is_mcast = false; 7503 bool is_dvlan = false; 7504 struct ethhdr *eth; 7505 bool is_prb_rsp; 7506 u16 mcbc_gsn; 7507 u8 link_id; 7508 int ret; 7509 7510 if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { 7511 ieee80211_free_txskb(hw, skb); 7512 return; 7513 } 7514 7515 link_id = u32_get_bits(info->control.flags, IEEE80211_TX_CTRL_MLO_LINK); 7516 memset(skb_cb, 0, sizeof(*skb_cb)); 7517 skb_cb->vif = vif; 7518 7519 if (key) { 7520 skb_cb->cipher = key->cipher; 7521 skb_cb->flags |= ATH12K_SKB_CIPHER_SET; 7522 } 7523 7524 /* handle only for MLO case, use deflink for non MLO case */ 7525 if (ieee80211_vif_is_mld(vif)) { 7526 link_id = ath12k_mac_get_tx_link(sta, vif, link_id, skb, info_flags); 7527 if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) { 7528 ieee80211_free_txskb(hw, skb); 7529 return; 7530 } 7531 } else { 7532 link_id = 0; 7533 } 7534 7535 arvif = rcu_dereference(ahvif->link[link_id]); 7536 if (!arvif || !arvif->ar) { 7537 ath12k_warn(ahvif->ah, "failed to find arvif link id %u for frame transmission", 7538 link_id); 7539 ieee80211_free_txskb(hw, skb); 7540 return; 7541 } 7542 7543 ar = arvif->ar; 7544 skb_cb->link_id = link_id; 7545 is_prb_rsp = ieee80211_is_probe_resp(hdr->frame_control); 7546 7547 if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP) { 7548 eth = (struct ethhdr *)skb->data; 7549 is_mcast = is_multicast_ether_addr(eth->h_dest); 7550 7551 skb_cb->flags |= ATH12K_SKB_HW_80211_ENCAP; 7552 } else if (ieee80211_is_mgmt(hdr->frame_control)) { 7553 ret = ath12k_mac_mgmt_tx(ar, skb, is_prb_rsp); 7554 if (ret) { 7555 ath12k_warn(ar->ab, "failed to queue management frame %d\n", 7556 ret); 7557 ieee80211_free_txskb(hw, skb); 7558 } 7559 return; 7560 } 7561 7562 if (!(info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) 7563 is_mcast = is_multicast_ether_addr(hdr->addr1); 7564 7565 /* This is case only for P2P_GO */ 7566 if (vif->type == NL80211_IFTYPE_AP && vif->p2p) 7567 ath12k_mac_add_p2p_noa_ie(ar, vif, skb, is_prb_rsp); 7568 7569 /* Checking if it is a DVLAN frame */ 7570 if (!test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags) && 7571 !(skb_cb->flags & ATH12K_SKB_HW_80211_ENCAP) && 7572 !(skb_cb->flags & ATH12K_SKB_CIPHER_SET) && 7573 ieee80211_has_protected(hdr->frame_control)) 7574 is_dvlan = true; 7575 7576 if (!vif->valid_links || !is_mcast || is_dvlan || 7577 test_bit(ATH12K_FLAG_RAW_MODE, &ar->ab->dev_flags)) { 7578 ret = ath12k_dp_tx(ar, arvif, skb, false, 0, is_mcast); 7579 if (unlikely(ret)) { 7580 ath12k_warn(ar->ab, "failed to transmit frame %d\n", ret); 7581 ieee80211_free_txskb(ar->ah->hw, skb); 7582 return; 7583 } 7584 } else { 7585 mcbc_gsn = atomic_inc_return(&ahvif->mcbc_gsn) & 0xfff; 7586 7587 links_map = ahvif->links_map; 7588 for_each_set_bit(link_id, &links_map, 7589 IEEE80211_MLD_MAX_NUM_LINKS) { 7590 tmp_arvif = rcu_dereference(ahvif->link[link_id]); 7591 if (!tmp_arvif || !tmp_arvif->is_up) 7592 continue; 7593 7594 tmp_ar = tmp_arvif->ar; 7595 msdu_copied = skb_copy(skb, GFP_ATOMIC); 7596 if (!msdu_copied) { 7597 ath12k_err(ar->ab, 7598 "skb copy failure link_id 0x%X vdevid 0x%X\n", 7599 link_id, tmp_arvif->vdev_id); 7600 continue; 7601 } 7602 7603 ath12k_mlo_mcast_update_tx_link_address(vif, link_id, 7604 msdu_copied, 7605 info_flags); 7606 7607 skb_cb = ATH12K_SKB_CB(msdu_copied); 7608 skb_cb->link_id = link_id; 7609 7610 /* For open mode, skip peer find logic */ 7611 if (unlikely(!ahvif->key_cipher)) 7612 goto skip_peer_find; 7613 7614 spin_lock_bh(&tmp_ar->ab->base_lock); 7615 peer = ath12k_peer_find_by_addr(tmp_ar->ab, tmp_arvif->bssid); 7616 if (!peer) { 7617 spin_unlock_bh(&tmp_ar->ab->base_lock); 7618 ath12k_warn(tmp_ar->ab, 7619 "failed to find peer for vdev_id 0x%X addr %pM link_map 0x%X\n", 7620 tmp_arvif->vdev_id, tmp_arvif->bssid, 7621 ahvif->links_map); 7622 dev_kfree_skb_any(msdu_copied); 7623 continue; 7624 } 7625 7626 key = peer->keys[peer->mcast_keyidx]; 7627 if (key) { 7628 skb_cb->cipher = key->cipher; 7629 skb_cb->flags |= ATH12K_SKB_CIPHER_SET; 7630 7631 hdr = (struct ieee80211_hdr *)msdu_copied->data; 7632 if (!ieee80211_has_protected(hdr->frame_control)) 7633 hdr->frame_control |= 7634 cpu_to_le16(IEEE80211_FCTL_PROTECTED); 7635 } 7636 spin_unlock_bh(&tmp_ar->ab->base_lock); 7637 7638 skip_peer_find: 7639 ret = ath12k_dp_tx(tmp_ar, tmp_arvif, 7640 msdu_copied, true, mcbc_gsn, is_mcast); 7641 if (unlikely(ret)) { 7642 if (ret == -ENOMEM) { 7643 /* Drops are expected during heavy multicast 7644 * frame flood. Print with debug log 7645 * level to avoid lot of console prints 7646 */ 7647 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 7648 "failed to transmit frame %d\n", 7649 ret); 7650 } else { 7651 ath12k_warn(ar->ab, 7652 "failed to transmit frame %d\n", 7653 ret); 7654 } 7655 7656 dev_kfree_skb_any(msdu_copied); 7657 } 7658 } 7659 ieee80211_free_txskb(ar->ah->hw, skb); 7660 } 7661 } 7662 7663 void ath12k_mac_drain_tx(struct ath12k *ar) 7664 { 7665 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 7666 7667 /* make sure rcu-protected mac80211 tx path itself is drained */ 7668 synchronize_net(); 7669 7670 wiphy_work_cancel(ath12k_ar_to_hw(ar)->wiphy, &ar->wmi_mgmt_tx_work); 7671 ath12k_mgmt_over_wmi_tx_purge(ar); 7672 } 7673 7674 static int ath12k_mac_config_mon_status_default(struct ath12k *ar, bool enable) 7675 { 7676 struct htt_rx_ring_tlv_filter tlv_filter = {}; 7677 struct ath12k_base *ab = ar->ab; 7678 u32 ring_id, i; 7679 int ret = 0; 7680 7681 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 7682 7683 if (!ab->hw_params->rxdma1_enable) 7684 return ret; 7685 7686 if (enable) { 7687 tlv_filter = ath12k_mac_mon_status_filter_default; 7688 7689 if (ath12k_debugfs_rx_filter(ar)) 7690 tlv_filter.rx_filter = ath12k_debugfs_rx_filter(ar); 7691 } else { 7692 tlv_filter.rxmon_disable = true; 7693 } 7694 7695 for (i = 0; i < ab->hw_params->num_rxdma_per_pdev; i++) { 7696 ring_id = ar->dp.rxdma_mon_dst_ring[i].ring_id; 7697 ret = ath12k_dp_tx_htt_rx_filter_setup(ab, ring_id, 7698 ar->dp.mac_id + i, 7699 HAL_RXDMA_MONITOR_DST, 7700 DP_RXDMA_REFILL_RING_SIZE, 7701 &tlv_filter); 7702 if (ret) { 7703 ath12k_err(ab, 7704 "failed to setup filter for monitor buf %d\n", 7705 ret); 7706 } 7707 } 7708 7709 return ret; 7710 } 7711 7712 static int ath12k_mac_start(struct ath12k *ar) 7713 { 7714 struct ath12k_hw *ah = ar->ah; 7715 struct ath12k_base *ab = ar->ab; 7716 struct ath12k_pdev *pdev = ar->pdev; 7717 int ret; 7718 7719 lockdep_assert_held(&ah->hw_mutex); 7720 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 7721 7722 ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, 7723 1, pdev->pdev_id); 7724 7725 if (ret) { 7726 ath12k_err(ab, "failed to enable PMF QOS: %d\n", ret); 7727 goto err; 7728 } 7729 7730 ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 1, 7731 pdev->pdev_id); 7732 if (ret) { 7733 ath12k_err(ab, "failed to enable dynamic bw: %d\n", ret); 7734 goto err; 7735 } 7736 7737 ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_ARP_AC_OVERRIDE, 7738 0, pdev->pdev_id); 7739 if (ret) { 7740 ath12k_err(ab, "failed to set ac override for ARP: %d\n", 7741 ret); 7742 goto err; 7743 } 7744 7745 ret = ath12k_wmi_send_dfs_phyerr_offload_enable_cmd(ar, pdev->pdev_id); 7746 if (ret) { 7747 ath12k_err(ab, "failed to offload radar detection: %d\n", 7748 ret); 7749 goto err; 7750 } 7751 7752 ret = ath12k_dp_tx_htt_h2t_ppdu_stats_req(ar, 7753 HTT_PPDU_STATS_TAG_DEFAULT); 7754 if (ret) { 7755 ath12k_err(ab, "failed to req ppdu stats: %d\n", ret); 7756 goto err; 7757 } 7758 7759 ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_MESH_MCAST_ENABLE, 7760 1, pdev->pdev_id); 7761 7762 if (ret) { 7763 ath12k_err(ab, "failed to enable MESH MCAST ENABLE: (%d\n", ret); 7764 goto err; 7765 } 7766 7767 __ath12k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask); 7768 7769 /* TODO: Do we need to enable ANI? */ 7770 7771 ath12k_reg_update_chan_list(ar, false); 7772 7773 ar->num_started_vdevs = 0; 7774 ar->num_created_vdevs = 0; 7775 ar->num_peers = 0; 7776 ar->allocated_vdev_map = 0; 7777 ar->chan_tx_pwr = ATH12K_PDEV_TX_POWER_INVALID; 7778 7779 /* Configure monitor status ring with default rx_filter to get rx status 7780 * such as rssi, rx_duration. 7781 */ 7782 ret = ath12k_mac_config_mon_status_default(ar, true); 7783 if (ret && (ret != -EOPNOTSUPP)) { 7784 ath12k_err(ab, "failed to configure monitor status ring with default rx_filter: (%d)\n", 7785 ret); 7786 goto err; 7787 } 7788 7789 if (ret == -EOPNOTSUPP) 7790 ath12k_dbg(ab, ATH12K_DBG_MAC, 7791 "monitor status config is not yet supported"); 7792 7793 /* Configure the hash seed for hash based reo dest ring selection */ 7794 ath12k_wmi_pdev_lro_cfg(ar, ar->pdev->pdev_id); 7795 7796 /* allow device to enter IMPS */ 7797 if (ab->hw_params->idle_ps) { 7798 ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_IDLE_PS_CONFIG, 7799 1, pdev->pdev_id); 7800 if (ret) { 7801 ath12k_err(ab, "failed to enable idle ps: %d\n", ret); 7802 goto err; 7803 } 7804 } 7805 7806 rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx], 7807 &ab->pdevs[ar->pdev_idx]); 7808 7809 return 0; 7810 err: 7811 7812 return ret; 7813 } 7814 7815 static void ath12k_drain_tx(struct ath12k_hw *ah) 7816 { 7817 struct ath12k *ar = ah->radio; 7818 int i; 7819 7820 if (ath12k_ftm_mode) { 7821 ath12k_err(ar->ab, "fail to start mac operations in ftm mode\n"); 7822 return; 7823 } 7824 7825 lockdep_assert_wiphy(ah->hw->wiphy); 7826 7827 for_each_ar(ah, ar, i) 7828 ath12k_mac_drain_tx(ar); 7829 } 7830 7831 static int ath12k_mac_op_start(struct ieee80211_hw *hw) 7832 { 7833 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 7834 struct ath12k *ar; 7835 int ret, i; 7836 7837 lockdep_assert_wiphy(hw->wiphy); 7838 7839 ath12k_drain_tx(ah); 7840 7841 guard(mutex)(&ah->hw_mutex); 7842 7843 switch (ah->state) { 7844 case ATH12K_HW_STATE_OFF: 7845 ah->state = ATH12K_HW_STATE_ON; 7846 break; 7847 case ATH12K_HW_STATE_RESTARTING: 7848 ah->state = ATH12K_HW_STATE_RESTARTED; 7849 break; 7850 case ATH12K_HW_STATE_RESTARTED: 7851 case ATH12K_HW_STATE_WEDGED: 7852 case ATH12K_HW_STATE_ON: 7853 case ATH12K_HW_STATE_TM: 7854 ah->state = ATH12K_HW_STATE_OFF; 7855 7856 WARN_ON(1); 7857 return -EINVAL; 7858 } 7859 7860 for_each_ar(ah, ar, i) { 7861 ret = ath12k_mac_start(ar); 7862 if (ret) { 7863 ah->state = ATH12K_HW_STATE_OFF; 7864 7865 ath12k_err(ar->ab, "fail to start mac operations in pdev idx %d ret %d\n", 7866 ar->pdev_idx, ret); 7867 goto fail_start; 7868 } 7869 } 7870 7871 return 0; 7872 7873 fail_start: 7874 for (; i > 0; i--) { 7875 ar = ath12k_ah_to_ar(ah, i - 1); 7876 ath12k_mac_stop(ar); 7877 } 7878 7879 return ret; 7880 } 7881 7882 int ath12k_mac_rfkill_config(struct ath12k *ar) 7883 { 7884 struct ath12k_base *ab = ar->ab; 7885 u32 param; 7886 int ret; 7887 7888 if (ab->hw_params->rfkill_pin == 0) 7889 return -EOPNOTSUPP; 7890 7891 ath12k_dbg(ab, ATH12K_DBG_MAC, 7892 "mac rfkill_pin %d rfkill_cfg %d rfkill_on_level %d", 7893 ab->hw_params->rfkill_pin, ab->hw_params->rfkill_cfg, 7894 ab->hw_params->rfkill_on_level); 7895 7896 param = u32_encode_bits(ab->hw_params->rfkill_on_level, 7897 WMI_RFKILL_CFG_RADIO_LEVEL) | 7898 u32_encode_bits(ab->hw_params->rfkill_pin, 7899 WMI_RFKILL_CFG_GPIO_PIN_NUM) | 7900 u32_encode_bits(ab->hw_params->rfkill_cfg, 7901 WMI_RFKILL_CFG_PIN_AS_GPIO); 7902 7903 ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_HW_RFKILL_CONFIG, 7904 param, ar->pdev->pdev_id); 7905 if (ret) { 7906 ath12k_warn(ab, 7907 "failed to set rfkill config 0x%x: %d\n", 7908 param, ret); 7909 return ret; 7910 } 7911 7912 return 0; 7913 } 7914 7915 int ath12k_mac_rfkill_enable_radio(struct ath12k *ar, bool enable) 7916 { 7917 enum wmi_rfkill_enable_radio param; 7918 int ret; 7919 7920 if (enable) 7921 param = WMI_RFKILL_ENABLE_RADIO_ON; 7922 else 7923 param = WMI_RFKILL_ENABLE_RADIO_OFF; 7924 7925 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac %d rfkill enable %d", 7926 ar->pdev_idx, param); 7927 7928 ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RFKILL_ENABLE, 7929 param, ar->pdev->pdev_id); 7930 if (ret) { 7931 ath12k_warn(ar->ab, "failed to set rfkill enable param %d: %d\n", 7932 param, ret); 7933 return ret; 7934 } 7935 7936 return 0; 7937 } 7938 7939 static void ath12k_mac_stop(struct ath12k *ar) 7940 { 7941 struct ath12k_hw *ah = ar->ah; 7942 struct htt_ppdu_stats_info *ppdu_stats, *tmp; 7943 int ret; 7944 7945 lockdep_assert_held(&ah->hw_mutex); 7946 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 7947 7948 ret = ath12k_mac_config_mon_status_default(ar, false); 7949 if (ret && (ret != -EOPNOTSUPP)) 7950 ath12k_err(ar->ab, "failed to clear rx_filter for monitor status ring: (%d)\n", 7951 ret); 7952 7953 clear_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags); 7954 7955 cancel_delayed_work_sync(&ar->scan.timeout); 7956 wiphy_work_cancel(ath12k_ar_to_hw(ar)->wiphy, &ar->scan.vdev_clean_wk); 7957 cancel_work_sync(&ar->regd_update_work); 7958 cancel_work_sync(&ar->ab->rfkill_work); 7959 cancel_work_sync(&ar->ab->update_11d_work); 7960 ar->state_11d = ATH12K_11D_IDLE; 7961 complete(&ar->completed_11d_scan); 7962 7963 spin_lock_bh(&ar->data_lock); 7964 list_for_each_entry_safe(ppdu_stats, tmp, &ar->ppdu_stats_info, list) { 7965 list_del(&ppdu_stats->list); 7966 kfree(ppdu_stats); 7967 } 7968 spin_unlock_bh(&ar->data_lock); 7969 7970 rcu_assign_pointer(ar->ab->pdevs_active[ar->pdev_idx], NULL); 7971 7972 synchronize_rcu(); 7973 7974 atomic_set(&ar->num_pending_mgmt_tx, 0); 7975 } 7976 7977 static void ath12k_mac_op_stop(struct ieee80211_hw *hw, bool suspend) 7978 { 7979 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 7980 struct ath12k *ar; 7981 int i; 7982 7983 lockdep_assert_wiphy(hw->wiphy); 7984 7985 ath12k_drain_tx(ah); 7986 7987 mutex_lock(&ah->hw_mutex); 7988 7989 ah->state = ATH12K_HW_STATE_OFF; 7990 7991 for_each_ar(ah, ar, i) 7992 ath12k_mac_stop(ar); 7993 7994 mutex_unlock(&ah->hw_mutex); 7995 } 7996 7997 static u8 7998 ath12k_mac_get_vdev_stats_id(struct ath12k_link_vif *arvif) 7999 { 8000 struct ath12k_base *ab = arvif->ar->ab; 8001 u8 vdev_stats_id = 0; 8002 8003 do { 8004 if (ab->free_vdev_stats_id_map & (1LL << vdev_stats_id)) { 8005 vdev_stats_id++; 8006 if (vdev_stats_id >= ATH12K_MAX_VDEV_STATS_ID) { 8007 vdev_stats_id = ATH12K_INVAL_VDEV_STATS_ID; 8008 break; 8009 } 8010 } else { 8011 ab->free_vdev_stats_id_map |= (1LL << vdev_stats_id); 8012 break; 8013 } 8014 } while (vdev_stats_id); 8015 8016 arvif->vdev_stats_id = vdev_stats_id; 8017 return vdev_stats_id; 8018 } 8019 8020 static int ath12k_mac_setup_vdev_params_mbssid(struct ath12k_link_vif *arvif, 8021 u32 *flags, u32 *tx_vdev_id) 8022 { 8023 struct ath12k_vif *ahvif = arvif->ahvif; 8024 struct ieee80211_bss_conf *link_conf; 8025 struct ath12k *ar = arvif->ar; 8026 struct ath12k_link_vif *tx_arvif; 8027 8028 link_conf = ath12k_mac_get_link_bss_conf(arvif); 8029 if (!link_conf) { 8030 ath12k_warn(ar->ab, "unable to access bss link conf in set mbssid params for vif %pM link %u\n", 8031 ahvif->vif->addr, arvif->link_id); 8032 return -ENOLINK; 8033 } 8034 8035 tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf); 8036 if (!tx_arvif) 8037 return 0; 8038 8039 if (link_conf->nontransmitted) { 8040 if (ath12k_ar_to_hw(ar)->wiphy != 8041 ath12k_ar_to_hw(tx_arvif->ar)->wiphy) 8042 return -EINVAL; 8043 8044 *flags = WMI_VDEV_MBSSID_FLAGS_NON_TRANSMIT_AP; 8045 *tx_vdev_id = tx_arvif->vdev_id; 8046 } else if (tx_arvif == arvif) { 8047 *flags = WMI_VDEV_MBSSID_FLAGS_TRANSMIT_AP; 8048 } else { 8049 return -EINVAL; 8050 } 8051 8052 if (link_conf->ema_ap) 8053 *flags |= WMI_VDEV_MBSSID_FLAGS_EMA_MODE; 8054 8055 return 0; 8056 } 8057 8058 static int ath12k_mac_setup_vdev_create_arg(struct ath12k_link_vif *arvif, 8059 struct ath12k_wmi_vdev_create_arg *arg) 8060 { 8061 struct ath12k *ar = arvif->ar; 8062 struct ath12k_pdev *pdev = ar->pdev; 8063 struct ath12k_vif *ahvif = arvif->ahvif; 8064 int ret; 8065 8066 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 8067 8068 arg->if_id = arvif->vdev_id; 8069 arg->type = ahvif->vdev_type; 8070 arg->subtype = ahvif->vdev_subtype; 8071 arg->pdev_id = pdev->pdev_id; 8072 8073 arg->mbssid_flags = WMI_VDEV_MBSSID_FLAGS_NON_MBSSID_AP; 8074 arg->mbssid_tx_vdev_id = 0; 8075 if (!test_bit(WMI_TLV_SERVICE_MBSS_PARAM_IN_VDEV_START_SUPPORT, 8076 ar->ab->wmi_ab.svc_map)) { 8077 ret = ath12k_mac_setup_vdev_params_mbssid(arvif, 8078 &arg->mbssid_flags, 8079 &arg->mbssid_tx_vdev_id); 8080 if (ret) 8081 return ret; 8082 } 8083 8084 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2GHZ_CAP) { 8085 arg->chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains; 8086 arg->chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains; 8087 } 8088 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP) { 8089 arg->chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains; 8090 arg->chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains; 8091 } 8092 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP && 8093 ar->supports_6ghz) { 8094 arg->chains[NL80211_BAND_6GHZ].tx = ar->num_tx_chains; 8095 arg->chains[NL80211_BAND_6GHZ].rx = ar->num_rx_chains; 8096 } 8097 8098 arg->if_stats_id = ath12k_mac_get_vdev_stats_id(arvif); 8099 8100 if (ath12k_mac_is_ml_arvif(arvif)) { 8101 if (hweight16(ahvif->vif->valid_links) > ATH12K_WMI_MLO_MAX_LINKS) { 8102 ath12k_warn(ar->ab, "too many MLO links during setting up vdev: %d", 8103 ahvif->vif->valid_links); 8104 return -EINVAL; 8105 } 8106 8107 ether_addr_copy(arg->mld_addr, ahvif->vif->addr); 8108 } 8109 8110 return 0; 8111 } 8112 8113 static u32 8114 ath12k_mac_prepare_he_mode(struct ath12k_pdev *pdev, u32 viftype) 8115 { 8116 struct ath12k_pdev_cap *pdev_cap = &pdev->cap; 8117 struct ath12k_band_cap *cap_band = NULL; 8118 u32 *hecap_phy_ptr = NULL; 8119 u32 hemode; 8120 8121 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2GHZ_CAP) 8122 cap_band = &pdev_cap->band[NL80211_BAND_2GHZ]; 8123 else 8124 cap_band = &pdev_cap->band[NL80211_BAND_5GHZ]; 8125 8126 hecap_phy_ptr = &cap_band->he_cap_phy_info[0]; 8127 8128 hemode = u32_encode_bits(HE_SU_BFEE_ENABLE, HE_MODE_SU_TX_BFEE) | 8129 u32_encode_bits(HECAP_PHY_SUBFMR_GET(hecap_phy_ptr), 8130 HE_MODE_SU_TX_BFER) | 8131 u32_encode_bits(HECAP_PHY_ULMUMIMO_GET(hecap_phy_ptr), 8132 HE_MODE_UL_MUMIMO); 8133 8134 /* TODO: WDS and other modes */ 8135 if (viftype == NL80211_IFTYPE_AP) { 8136 hemode |= u32_encode_bits(HECAP_PHY_MUBFMR_GET(hecap_phy_ptr), 8137 HE_MODE_MU_TX_BFER) | 8138 u32_encode_bits(HE_DL_MUOFDMA_ENABLE, HE_MODE_DL_OFDMA) | 8139 u32_encode_bits(HE_UL_MUOFDMA_ENABLE, HE_MODE_UL_OFDMA); 8140 } else { 8141 hemode |= u32_encode_bits(HE_MU_BFEE_ENABLE, HE_MODE_MU_TX_BFEE); 8142 } 8143 8144 return hemode; 8145 } 8146 8147 static int ath12k_set_he_mu_sounding_mode(struct ath12k *ar, 8148 struct ath12k_link_vif *arvif) 8149 { 8150 u32 param_id, param_value; 8151 struct ath12k_base *ab = ar->ab; 8152 struct ath12k_vif *ahvif = arvif->ahvif; 8153 int ret; 8154 8155 param_id = WMI_VDEV_PARAM_SET_HEMU_MODE; 8156 param_value = ath12k_mac_prepare_he_mode(ar->pdev, ahvif->vif->type); 8157 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 8158 param_id, param_value); 8159 if (ret) { 8160 ath12k_warn(ab, "failed to set vdev %d HE MU mode: %d param_value %x\n", 8161 arvif->vdev_id, ret, param_value); 8162 return ret; 8163 } 8164 param_id = WMI_VDEV_PARAM_SET_HE_SOUNDING_MODE; 8165 param_value = 8166 u32_encode_bits(HE_VHT_SOUNDING_MODE_ENABLE, HE_VHT_SOUNDING_MODE) | 8167 u32_encode_bits(HE_TRIG_NONTRIG_SOUNDING_MODE_ENABLE, 8168 HE_TRIG_NONTRIG_SOUNDING_MODE); 8169 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 8170 param_id, param_value); 8171 if (ret) { 8172 ath12k_warn(ab, "failed to set vdev %d HE MU mode: %d\n", 8173 arvif->vdev_id, ret); 8174 return ret; 8175 } 8176 return ret; 8177 } 8178 8179 static void ath12k_mac_update_vif_offload(struct ath12k_link_vif *arvif) 8180 { 8181 struct ath12k_vif *ahvif = arvif->ahvif; 8182 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); 8183 struct ath12k *ar = arvif->ar; 8184 struct ath12k_base *ab = ar->ab; 8185 u32 param_id, param_value; 8186 int ret; 8187 8188 param_id = WMI_VDEV_PARAM_TX_ENCAP_TYPE; 8189 if (vif->type != NL80211_IFTYPE_STATION && 8190 vif->type != NL80211_IFTYPE_AP) 8191 vif->offload_flags &= ~(IEEE80211_OFFLOAD_ENCAP_ENABLED | 8192 IEEE80211_OFFLOAD_DECAP_ENABLED); 8193 8194 if (vif->offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED) 8195 ahvif->tx_encap_type = ATH12K_HW_TXRX_ETHERNET; 8196 else if (test_bit(ATH12K_FLAG_RAW_MODE, &ab->dev_flags)) 8197 ahvif->tx_encap_type = ATH12K_HW_TXRX_RAW; 8198 else 8199 ahvif->tx_encap_type = ATH12K_HW_TXRX_NATIVE_WIFI; 8200 8201 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 8202 param_id, ahvif->tx_encap_type); 8203 if (ret) { 8204 ath12k_warn(ab, "failed to set vdev %d tx encap mode: %d\n", 8205 arvif->vdev_id, ret); 8206 vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED; 8207 } 8208 8209 param_id = WMI_VDEV_PARAM_RX_DECAP_TYPE; 8210 if (vif->offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED) 8211 param_value = ATH12K_HW_TXRX_ETHERNET; 8212 else if (test_bit(ATH12K_FLAG_RAW_MODE, &ab->dev_flags)) 8213 param_value = ATH12K_HW_TXRX_RAW; 8214 else 8215 param_value = ATH12K_HW_TXRX_NATIVE_WIFI; 8216 8217 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 8218 param_id, param_value); 8219 if (ret) { 8220 ath12k_warn(ab, "failed to set vdev %d rx decap mode: %d\n", 8221 arvif->vdev_id, ret); 8222 vif->offload_flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED; 8223 } 8224 } 8225 8226 static void ath12k_mac_op_update_vif_offload(struct ieee80211_hw *hw, 8227 struct ieee80211_vif *vif) 8228 { 8229 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 8230 struct ath12k_link_vif *arvif; 8231 unsigned long links; 8232 int link_id; 8233 8234 lockdep_assert_wiphy(hw->wiphy); 8235 8236 if (vif->valid_links) { 8237 links = vif->valid_links; 8238 for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { 8239 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 8240 if (!(arvif && arvif->ar)) 8241 continue; 8242 8243 ath12k_mac_update_vif_offload(arvif); 8244 } 8245 8246 return; 8247 } 8248 8249 ath12k_mac_update_vif_offload(&ahvif->deflink); 8250 } 8251 8252 static bool ath12k_mac_vif_ap_active_any(struct ath12k_base *ab) 8253 { 8254 struct ath12k *ar; 8255 struct ath12k_pdev *pdev; 8256 struct ath12k_link_vif *arvif; 8257 int i; 8258 8259 for (i = 0; i < ab->num_radios; i++) { 8260 pdev = &ab->pdevs[i]; 8261 ar = pdev->ar; 8262 list_for_each_entry(arvif, &ar->arvifs, list) { 8263 if (arvif->is_up && 8264 arvif->ahvif->vdev_type == WMI_VDEV_TYPE_AP) 8265 return true; 8266 } 8267 } 8268 return false; 8269 } 8270 8271 void ath12k_mac_11d_scan_start(struct ath12k *ar, u32 vdev_id) 8272 { 8273 struct wmi_11d_scan_start_arg arg; 8274 int ret; 8275 8276 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 8277 8278 if (ar->regdom_set_by_user) 8279 goto fin; 8280 8281 if (ar->vdev_id_11d_scan != ATH12K_11D_INVALID_VDEV_ID) 8282 goto fin; 8283 8284 if (!test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map)) 8285 goto fin; 8286 8287 if (ath12k_mac_vif_ap_active_any(ar->ab)) 8288 goto fin; 8289 8290 arg.vdev_id = vdev_id; 8291 arg.start_interval_msec = 0; 8292 arg.scan_period_msec = ATH12K_SCAN_11D_INTERVAL; 8293 8294 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 8295 "mac start 11d scan for vdev %d\n", vdev_id); 8296 8297 ret = ath12k_wmi_send_11d_scan_start_cmd(ar, &arg); 8298 if (ret) { 8299 ath12k_warn(ar->ab, "failed to start 11d scan vdev %d ret: %d\n", 8300 vdev_id, ret); 8301 } else { 8302 ar->vdev_id_11d_scan = vdev_id; 8303 if (ar->state_11d == ATH12K_11D_PREPARING) 8304 ar->state_11d = ATH12K_11D_RUNNING; 8305 } 8306 8307 fin: 8308 if (ar->state_11d == ATH12K_11D_PREPARING) { 8309 ar->state_11d = ATH12K_11D_IDLE; 8310 complete(&ar->completed_11d_scan); 8311 } 8312 } 8313 8314 void ath12k_mac_11d_scan_stop(struct ath12k *ar) 8315 { 8316 int ret; 8317 u32 vdev_id; 8318 8319 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 8320 8321 if (!test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map)) 8322 return; 8323 8324 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac stop 11d for vdev %d\n", 8325 ar->vdev_id_11d_scan); 8326 8327 if (ar->state_11d == ATH12K_11D_PREPARING) { 8328 ar->state_11d = ATH12K_11D_IDLE; 8329 complete(&ar->completed_11d_scan); 8330 } 8331 8332 if (ar->vdev_id_11d_scan != ATH12K_11D_INVALID_VDEV_ID) { 8333 vdev_id = ar->vdev_id_11d_scan; 8334 8335 ret = ath12k_wmi_send_11d_scan_stop_cmd(ar, vdev_id); 8336 if (ret) { 8337 ath12k_warn(ar->ab, 8338 "failed to stopt 11d scan vdev %d ret: %d\n", 8339 vdev_id, ret); 8340 } else { 8341 ar->vdev_id_11d_scan = ATH12K_11D_INVALID_VDEV_ID; 8342 ar->state_11d = ATH12K_11D_IDLE; 8343 complete(&ar->completed_11d_scan); 8344 } 8345 } 8346 } 8347 8348 void ath12k_mac_11d_scan_stop_all(struct ath12k_base *ab) 8349 { 8350 struct ath12k *ar; 8351 struct ath12k_pdev *pdev; 8352 int i; 8353 8354 ath12k_dbg(ab, ATH12K_DBG_MAC, "mac stop soc 11d scan\n"); 8355 8356 for (i = 0; i < ab->num_radios; i++) { 8357 pdev = &ab->pdevs[i]; 8358 ar = pdev->ar; 8359 8360 ath12k_mac_11d_scan_stop(ar); 8361 } 8362 } 8363 8364 static void ath12k_mac_determine_vdev_type(struct ieee80211_vif *vif, 8365 struct ath12k_vif *ahvif) 8366 { 8367 ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE; 8368 8369 switch (vif->type) { 8370 case NL80211_IFTYPE_UNSPECIFIED: 8371 case NL80211_IFTYPE_STATION: 8372 ahvif->vdev_type = WMI_VDEV_TYPE_STA; 8373 8374 if (vif->p2p) 8375 ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT; 8376 8377 break; 8378 case NL80211_IFTYPE_MESH_POINT: 8379 ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_MESH_11S; 8380 fallthrough; 8381 case NL80211_IFTYPE_AP: 8382 ahvif->vdev_type = WMI_VDEV_TYPE_AP; 8383 8384 if (vif->p2p) 8385 ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO; 8386 8387 break; 8388 case NL80211_IFTYPE_MONITOR: 8389 ahvif->vdev_type = WMI_VDEV_TYPE_MONITOR; 8390 break; 8391 case NL80211_IFTYPE_P2P_DEVICE: 8392 ahvif->vdev_type = WMI_VDEV_TYPE_STA; 8393 ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE; 8394 break; 8395 default: 8396 WARN_ON(1); 8397 break; 8398 } 8399 } 8400 8401 int ath12k_mac_vdev_create(struct ath12k *ar, struct ath12k_link_vif *arvif) 8402 { 8403 struct ath12k_hw *ah = ar->ah; 8404 struct ath12k_base *ab = ar->ab; 8405 struct ieee80211_hw *hw = ah->hw; 8406 struct ath12k_vif *ahvif = arvif->ahvif; 8407 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); 8408 struct ath12k_wmi_vdev_create_arg vdev_arg = {0}; 8409 struct ath12k_wmi_peer_create_arg peer_param = {0}; 8410 struct ieee80211_bss_conf *link_conf = NULL; 8411 u32 param_id, param_value; 8412 u16 nss; 8413 int i; 8414 int ret, vdev_id; 8415 u8 link_id; 8416 8417 lockdep_assert_wiphy(hw->wiphy); 8418 8419 /* In NO_VIRTUAL_MONITOR, its necessary to restrict only one monitor 8420 * interface in each radio 8421 */ 8422 if (vif->type == NL80211_IFTYPE_MONITOR && ar->monitor_vdev_created) 8423 return -EINVAL; 8424 8425 link_id = arvif->link_id; 8426 8427 if (link_id < IEEE80211_MLD_MAX_NUM_LINKS) { 8428 link_conf = wiphy_dereference(hw->wiphy, vif->link_conf[link_id]); 8429 if (!link_conf) { 8430 ath12k_warn(ar->ab, "unable to access bss link conf in vdev create for vif %pM link %u\n", 8431 vif->addr, arvif->link_id); 8432 return -ENOLINK; 8433 } 8434 } 8435 8436 if (link_conf) 8437 memcpy(arvif->bssid, link_conf->addr, ETH_ALEN); 8438 else 8439 memcpy(arvif->bssid, vif->addr, ETH_ALEN); 8440 8441 arvif->ar = ar; 8442 vdev_id = __ffs64(ab->free_vdev_map); 8443 arvif->vdev_id = vdev_id; 8444 if (vif->type == NL80211_IFTYPE_MONITOR) 8445 ar->monitor_vdev_id = vdev_id; 8446 8447 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev create id %d type %d subtype %d map %llx\n", 8448 arvif->vdev_id, ahvif->vdev_type, ahvif->vdev_subtype, 8449 ab->free_vdev_map); 8450 8451 vif->cab_queue = arvif->vdev_id % (ATH12K_HW_MAX_QUEUES - 1); 8452 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++) 8453 vif->hw_queue[i] = i % (ATH12K_HW_MAX_QUEUES - 1); 8454 8455 ret = ath12k_mac_setup_vdev_create_arg(arvif, &vdev_arg); 8456 if (ret) { 8457 ath12k_warn(ab, "failed to create vdev parameters %d: %d\n", 8458 arvif->vdev_id, ret); 8459 goto err; 8460 } 8461 8462 ret = ath12k_wmi_vdev_create(ar, arvif->bssid, &vdev_arg); 8463 if (ret) { 8464 ath12k_warn(ab, "failed to create WMI vdev %d: %d\n", 8465 arvif->vdev_id, ret); 8466 return ret; 8467 } 8468 8469 ar->num_created_vdevs++; 8470 arvif->is_created = true; 8471 ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM created, vdev_id %d\n", 8472 vif->addr, arvif->vdev_id); 8473 ar->allocated_vdev_map |= 1LL << arvif->vdev_id; 8474 ab->free_vdev_map &= ~(1LL << arvif->vdev_id); 8475 8476 spin_lock_bh(&ar->data_lock); 8477 list_add(&arvif->list, &ar->arvifs); 8478 spin_unlock_bh(&ar->data_lock); 8479 8480 ath12k_mac_update_vif_offload(arvif); 8481 8482 nss = hweight32(ar->cfg_tx_chainmask) ? : 1; 8483 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 8484 WMI_VDEV_PARAM_NSS, nss); 8485 if (ret) { 8486 ath12k_warn(ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n", 8487 arvif->vdev_id, ar->cfg_tx_chainmask, nss, ret); 8488 goto err_vdev_del; 8489 } 8490 8491 switch (ahvif->vdev_type) { 8492 case WMI_VDEV_TYPE_AP: 8493 peer_param.vdev_id = arvif->vdev_id; 8494 peer_param.peer_addr = arvif->bssid; 8495 peer_param.peer_type = WMI_PEER_TYPE_DEFAULT; 8496 ret = ath12k_peer_create(ar, arvif, NULL, &peer_param); 8497 if (ret) { 8498 ath12k_warn(ab, "failed to vdev %d create peer for AP: %d\n", 8499 arvif->vdev_id, ret); 8500 goto err_vdev_del; 8501 } 8502 8503 ret = ath12k_mac_set_kickout(arvif); 8504 if (ret) { 8505 ath12k_warn(ar->ab, "failed to set vdev %i kickout parameters: %d\n", 8506 arvif->vdev_id, ret); 8507 goto err_peer_del; 8508 } 8509 ath12k_mac_11d_scan_stop_all(ar->ab); 8510 break; 8511 case WMI_VDEV_TYPE_STA: 8512 param_id = WMI_STA_PS_PARAM_RX_WAKE_POLICY; 8513 param_value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; 8514 ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, 8515 param_id, param_value); 8516 if (ret) { 8517 ath12k_warn(ar->ab, "failed to set vdev %d RX wake policy: %d\n", 8518 arvif->vdev_id, ret); 8519 goto err_peer_del; 8520 } 8521 8522 param_id = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD; 8523 param_value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS; 8524 ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, 8525 param_id, param_value); 8526 if (ret) { 8527 ath12k_warn(ar->ab, "failed to set vdev %d TX wake threshold: %d\n", 8528 arvif->vdev_id, ret); 8529 goto err_peer_del; 8530 } 8531 8532 param_id = WMI_STA_PS_PARAM_PSPOLL_COUNT; 8533 param_value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX; 8534 ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, 8535 param_id, param_value); 8536 if (ret) { 8537 ath12k_warn(ar->ab, "failed to set vdev %d pspoll count: %d\n", 8538 arvif->vdev_id, ret); 8539 goto err_peer_del; 8540 } 8541 8542 ret = ath12k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, false); 8543 if (ret) { 8544 ath12k_warn(ar->ab, "failed to disable vdev %d ps mode: %d\n", 8545 arvif->vdev_id, ret); 8546 goto err_peer_del; 8547 } 8548 8549 if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ab->wmi_ab.svc_map) && 8550 ahvif->vdev_type == WMI_VDEV_TYPE_STA && 8551 ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) { 8552 reinit_completion(&ar->completed_11d_scan); 8553 ar->state_11d = ATH12K_11D_PREPARING; 8554 } 8555 break; 8556 case WMI_VDEV_TYPE_MONITOR: 8557 ar->monitor_vdev_created = true; 8558 break; 8559 default: 8560 break; 8561 } 8562 8563 if (link_conf) 8564 arvif->txpower = link_conf->txpower; 8565 else 8566 arvif->txpower = NL80211_TX_POWER_AUTOMATIC; 8567 8568 ret = ath12k_mac_txpower_recalc(ar); 8569 if (ret) 8570 goto err_peer_del; 8571 8572 param_id = WMI_VDEV_PARAM_RTS_THRESHOLD; 8573 param_value = hw->wiphy->rts_threshold; 8574 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 8575 param_id, param_value); 8576 if (ret) { 8577 ath12k_warn(ar->ab, "failed to set rts threshold for vdev %d: %d\n", 8578 arvif->vdev_id, ret); 8579 } 8580 8581 ath12k_dp_vdev_tx_attach(ar, arvif); 8582 8583 return ret; 8584 8585 err_peer_del: 8586 if (ahvif->vdev_type == WMI_VDEV_TYPE_AP) { 8587 reinit_completion(&ar->peer_delete_done); 8588 8589 ret = ath12k_wmi_send_peer_delete_cmd(ar, arvif->bssid, 8590 arvif->vdev_id); 8591 if (ret) { 8592 ath12k_warn(ar->ab, "failed to delete peer vdev_id %d addr %pM\n", 8593 arvif->vdev_id, arvif->bssid); 8594 goto err; 8595 } 8596 8597 ret = ath12k_wait_for_peer_delete_done(ar, arvif->vdev_id, 8598 arvif->bssid); 8599 if (ret) 8600 goto err_vdev_del; 8601 8602 ar->num_peers--; 8603 } 8604 8605 err_vdev_del: 8606 if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { 8607 ar->monitor_vdev_id = -1; 8608 ar->monitor_vdev_created = false; 8609 } 8610 8611 ath12k_wmi_vdev_delete(ar, arvif->vdev_id); 8612 ar->num_created_vdevs--; 8613 arvif->is_created = false; 8614 arvif->ar = NULL; 8615 ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id); 8616 ab->free_vdev_map |= 1LL << arvif->vdev_id; 8617 ab->free_vdev_stats_id_map &= ~(1LL << arvif->vdev_stats_id); 8618 spin_lock_bh(&ar->data_lock); 8619 list_del(&arvif->list); 8620 spin_unlock_bh(&ar->data_lock); 8621 8622 err: 8623 arvif->ar = NULL; 8624 return ret; 8625 } 8626 8627 static void ath12k_mac_vif_flush_key_cache(struct ath12k_link_vif *arvif) 8628 { 8629 struct ath12k_key_conf *key_conf, *tmp; 8630 struct ath12k_vif *ahvif = arvif->ahvif; 8631 struct ath12k_hw *ah = ahvif->ah; 8632 struct ath12k_sta *ahsta; 8633 struct ath12k_link_sta *arsta; 8634 struct ath12k_vif_cache *cache = ahvif->cache[arvif->link_id]; 8635 int ret; 8636 8637 lockdep_assert_wiphy(ah->hw->wiphy); 8638 8639 list_for_each_entry_safe(key_conf, tmp, &cache->key_conf.list, list) { 8640 arsta = NULL; 8641 if (key_conf->sta) { 8642 ahsta = ath12k_sta_to_ahsta(key_conf->sta); 8643 arsta = wiphy_dereference(ah->hw->wiphy, 8644 ahsta->link[arvif->link_id]); 8645 if (!arsta) 8646 goto free_cache; 8647 } 8648 8649 ret = ath12k_mac_set_key(arvif->ar, key_conf->cmd, 8650 arvif, arsta, 8651 key_conf->key); 8652 if (ret) 8653 ath12k_warn(arvif->ar->ab, "unable to apply set key param to vdev %d ret %d\n", 8654 arvif->vdev_id, ret); 8655 free_cache: 8656 list_del(&key_conf->list); 8657 kfree(key_conf); 8658 } 8659 } 8660 8661 static void ath12k_mac_vif_cache_flush(struct ath12k *ar, struct ath12k_link_vif *arvif) 8662 { 8663 struct ath12k_vif *ahvif = arvif->ahvif; 8664 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); 8665 struct ath12k_vif_cache *cache = ahvif->cache[arvif->link_id]; 8666 struct ath12k_base *ab = ar->ab; 8667 struct ieee80211_bss_conf *link_conf; 8668 8669 int ret; 8670 8671 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 8672 8673 if (!cache) 8674 return; 8675 8676 if (cache->tx_conf.changed) { 8677 ret = ath12k_mac_conf_tx(arvif, cache->tx_conf.ac, 8678 &cache->tx_conf.tx_queue_params); 8679 if (ret) 8680 ath12k_warn(ab, 8681 "unable to apply tx config parameters to vdev %d\n", 8682 ret); 8683 } 8684 8685 if (cache->bss_conf_changed) { 8686 link_conf = ath12k_mac_get_link_bss_conf(arvif); 8687 if (!link_conf) { 8688 ath12k_warn(ar->ab, "unable to access bss link conf in cache flush for vif %pM link %u\n", 8689 vif->addr, arvif->link_id); 8690 return; 8691 } 8692 ath12k_mac_bss_info_changed(ar, arvif, link_conf, 8693 cache->bss_conf_changed); 8694 } 8695 8696 if (!list_empty(&cache->key_conf.list)) 8697 ath12k_mac_vif_flush_key_cache(arvif); 8698 8699 ath12k_ahvif_put_link_cache(ahvif, arvif->link_id); 8700 } 8701 8702 static struct ath12k *ath12k_mac_assign_vif_to_vdev(struct ieee80211_hw *hw, 8703 struct ath12k_link_vif *arvif, 8704 struct ieee80211_chanctx_conf *ctx) 8705 { 8706 struct ath12k_vif *ahvif = arvif->ahvif; 8707 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); 8708 struct ath12k_link_vif *scan_arvif; 8709 struct ath12k_hw *ah = hw->priv; 8710 struct ath12k *ar; 8711 struct ath12k_base *ab; 8712 u8 link_id = arvif->link_id; 8713 int ret; 8714 8715 lockdep_assert_wiphy(hw->wiphy); 8716 8717 if (ah->num_radio == 1) 8718 ar = ah->radio; 8719 else if (ctx) 8720 ar = ath12k_get_ar_by_ctx(hw, ctx); 8721 else 8722 return NULL; 8723 8724 if (!ar) 8725 return NULL; 8726 8727 /* cleanup the scan vdev if we are done scan on that ar 8728 * and now we want to create for actual usage. 8729 */ 8730 if (ieee80211_vif_is_mld(vif)) { 8731 scan_arvif = wiphy_dereference(hw->wiphy, 8732 ahvif->link[ATH12K_DEFAULT_SCAN_LINK]); 8733 if (scan_arvif && scan_arvif->ar == ar) { 8734 ar->scan.arvif = NULL; 8735 ath12k_mac_remove_link_interface(hw, scan_arvif); 8736 ath12k_mac_unassign_link_vif(scan_arvif); 8737 } 8738 } 8739 8740 if (arvif->ar) { 8741 /* This is not expected really */ 8742 if (WARN_ON(!arvif->is_created)) { 8743 arvif->ar = NULL; 8744 return NULL; 8745 } 8746 8747 if (ah->num_radio == 1) 8748 return arvif->ar; 8749 8750 /* This can happen as scan vdev gets created during multiple scans 8751 * across different radios before a vdev is brought up in 8752 * a certain radio. 8753 */ 8754 if (ar != arvif->ar) { 8755 if (WARN_ON(arvif->is_started)) 8756 return NULL; 8757 8758 ath12k_mac_remove_link_interface(hw, arvif); 8759 ath12k_mac_unassign_link_vif(arvif); 8760 } 8761 } 8762 8763 ab = ar->ab; 8764 8765 /* Assign arvif again here since previous radio switch block 8766 * would've unassigned and cleared it. 8767 */ 8768 arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); 8769 if (vif->type == NL80211_IFTYPE_AP && 8770 ar->num_peers > (ar->max_num_peers - 1)) { 8771 ath12k_warn(ab, "failed to create vdev due to insufficient peer entry resource in firmware\n"); 8772 goto unlock; 8773 } 8774 8775 if (arvif->is_created) 8776 goto flush; 8777 8778 if (ar->num_created_vdevs > (TARGET_NUM_VDEVS - 1)) { 8779 ath12k_warn(ab, "failed to create vdev, reached max vdev limit %d\n", 8780 TARGET_NUM_VDEVS); 8781 goto unlock; 8782 } 8783 8784 ret = ath12k_mac_vdev_create(ar, arvif); 8785 if (ret) { 8786 ath12k_warn(ab, "failed to create vdev %pM ret %d", vif->addr, ret); 8787 goto unlock; 8788 } 8789 8790 flush: 8791 /* If the vdev is created during channel assign and not during 8792 * add_interface(), Apply any parameters for the vdev which were received 8793 * after add_interface, corresponding to this vif. 8794 */ 8795 ath12k_mac_vif_cache_flush(ar, arvif); 8796 unlock: 8797 return arvif->ar; 8798 } 8799 8800 static int ath12k_mac_op_add_interface(struct ieee80211_hw *hw, 8801 struct ieee80211_vif *vif) 8802 { 8803 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 8804 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 8805 struct ath12k_reg_info *reg_info; 8806 struct ath12k_link_vif *arvif; 8807 struct ath12k_base *ab; 8808 struct ath12k *ar; 8809 int i; 8810 8811 lockdep_assert_wiphy(hw->wiphy); 8812 8813 memset(ahvif, 0, sizeof(*ahvif)); 8814 8815 ahvif->ah = ah; 8816 ahvif->vif = vif; 8817 arvif = &ahvif->deflink; 8818 8819 ath12k_mac_init_arvif(ahvif, arvif, -1); 8820 8821 /* Allocate Default Queue now and reassign during actual vdev create */ 8822 vif->cab_queue = ATH12K_HW_DEFAULT_QUEUE; 8823 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++) 8824 vif->hw_queue[i] = ATH12K_HW_DEFAULT_QUEUE; 8825 8826 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; 8827 8828 ath12k_mac_determine_vdev_type(vif, ahvif); 8829 8830 for_each_ar(ah, ar, i) { 8831 if (!ath12k_wmi_supports_6ghz_cc_ext(ar)) 8832 continue; 8833 8834 ab = ar->ab; 8835 reg_info = ab->reg_info[ar->pdev_idx]; 8836 ath12k_dbg(ab, ATH12K_DBG_MAC, "interface added to change reg rules\n"); 8837 ah->regd_updated = false; 8838 ath12k_reg_handle_chan_list(ab, reg_info, ahvif->vdev_type, 8839 IEEE80211_REG_UNSET_AP); 8840 break; 8841 } 8842 8843 /* Defer vdev creation until assign_chanctx or hw_scan is initiated as driver 8844 * will not know if this interface is an ML vif at this point. 8845 */ 8846 return 0; 8847 } 8848 8849 static void ath12k_mac_vif_unref(struct ath12k_dp *dp, struct ieee80211_vif *vif) 8850 { 8851 struct ath12k_tx_desc_info *tx_desc_info; 8852 struct ath12k_skb_cb *skb_cb; 8853 struct sk_buff *skb; 8854 int i; 8855 8856 for (i = 0; i < ATH12K_HW_MAX_QUEUES; i++) { 8857 spin_lock_bh(&dp->tx_desc_lock[i]); 8858 8859 list_for_each_entry(tx_desc_info, &dp->tx_desc_used_list[i], 8860 list) { 8861 skb = tx_desc_info->skb; 8862 if (!skb) 8863 continue; 8864 8865 skb_cb = ATH12K_SKB_CB(skb); 8866 if (skb_cb->vif == vif) 8867 skb_cb->vif = NULL; 8868 } 8869 8870 spin_unlock_bh(&dp->tx_desc_lock[i]); 8871 } 8872 } 8873 8874 static int ath12k_mac_vdev_delete(struct ath12k *ar, struct ath12k_link_vif *arvif) 8875 { 8876 struct ath12k_vif *ahvif = arvif->ahvif; 8877 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); 8878 struct ath12k_base *ab = ar->ab; 8879 unsigned long time_left; 8880 int ret; 8881 8882 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 8883 8884 reinit_completion(&ar->vdev_delete_done); 8885 8886 ret = ath12k_wmi_vdev_delete(ar, arvif->vdev_id); 8887 if (ret) { 8888 ath12k_warn(ab, "failed to delete WMI vdev %d: %d\n", 8889 arvif->vdev_id, ret); 8890 goto err_vdev_del; 8891 } 8892 8893 time_left = wait_for_completion_timeout(&ar->vdev_delete_done, 8894 ATH12K_VDEV_DELETE_TIMEOUT_HZ); 8895 if (time_left == 0) { 8896 ath12k_warn(ab, "Timeout in receiving vdev delete response\n"); 8897 goto err_vdev_del; 8898 } 8899 8900 ab->free_vdev_map |= 1LL << arvif->vdev_id; 8901 ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id); 8902 ar->num_created_vdevs--; 8903 8904 if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { 8905 ar->monitor_vdev_id = -1; 8906 ar->monitor_vdev_created = false; 8907 } 8908 8909 ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM deleted, vdev_id %d\n", 8910 vif->addr, arvif->vdev_id); 8911 8912 err_vdev_del: 8913 spin_lock_bh(&ar->data_lock); 8914 list_del(&arvif->list); 8915 spin_unlock_bh(&ar->data_lock); 8916 8917 ath12k_peer_cleanup(ar, arvif->vdev_id); 8918 ath12k_ahvif_put_link_cache(ahvif, arvif->link_id); 8919 8920 idr_for_each(&ar->txmgmt_idr, 8921 ath12k_mac_vif_txmgmt_idr_remove, vif); 8922 8923 ath12k_mac_vif_unref(&ab->dp, vif); 8924 ath12k_dp_tx_put_bank_profile(&ab->dp, arvif->bank_id); 8925 8926 /* Recalc txpower for remaining vdev */ 8927 ath12k_mac_txpower_recalc(ar); 8928 8929 /* TODO: recal traffic pause state based on the available vdevs */ 8930 arvif->is_created = false; 8931 arvif->ar = NULL; 8932 8933 return ret; 8934 } 8935 8936 static void ath12k_mac_op_remove_interface(struct ieee80211_hw *hw, 8937 struct ieee80211_vif *vif) 8938 { 8939 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 8940 struct ath12k_link_vif *arvif; 8941 struct ath12k *ar; 8942 u8 link_id; 8943 8944 lockdep_assert_wiphy(hw->wiphy); 8945 8946 for (link_id = 0; link_id < ATH12K_NUM_MAX_LINKS; link_id++) { 8947 /* if we cached some config but never received assign chanctx, 8948 * free the allocated cache. 8949 */ 8950 ath12k_ahvif_put_link_cache(ahvif, link_id); 8951 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 8952 if (!arvif || !arvif->is_created) 8953 continue; 8954 8955 ar = arvif->ar; 8956 8957 /* Scan abortion is in progress since before this, cancel_hw_scan() 8958 * is expected to be executed. Since link is anyways going to be removed 8959 * now, just cancel the worker and send the scan aborted to user space 8960 */ 8961 if (ar->scan.arvif == arvif) { 8962 wiphy_work_cancel(hw->wiphy, &ar->scan.vdev_clean_wk); 8963 8964 spin_lock_bh(&ar->data_lock); 8965 ar->scan.arvif = NULL; 8966 if (!ar->scan.is_roc) { 8967 struct cfg80211_scan_info info = { 8968 .aborted = true, 8969 }; 8970 8971 ieee80211_scan_completed(ar->ah->hw, &info); 8972 } 8973 8974 ar->scan.state = ATH12K_SCAN_IDLE; 8975 ar->scan_channel = NULL; 8976 ar->scan.roc_freq = 0; 8977 spin_unlock_bh(&ar->data_lock); 8978 } 8979 8980 ath12k_mac_remove_link_interface(hw, arvif); 8981 ath12k_mac_unassign_link_vif(arvif); 8982 } 8983 } 8984 8985 /* FIXME: Has to be verified. */ 8986 #define SUPPORTED_FILTERS \ 8987 (FIF_ALLMULTI | \ 8988 FIF_CONTROL | \ 8989 FIF_PSPOLL | \ 8990 FIF_OTHER_BSS | \ 8991 FIF_BCN_PRBRESP_PROMISC | \ 8992 FIF_PROBE_REQ | \ 8993 FIF_FCSFAIL) 8994 8995 static void ath12k_mac_op_configure_filter(struct ieee80211_hw *hw, 8996 unsigned int changed_flags, 8997 unsigned int *total_flags, 8998 u64 multicast) 8999 { 9000 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 9001 struct ath12k *ar; 9002 9003 lockdep_assert_wiphy(hw->wiphy); 9004 9005 ar = ath12k_ah_to_ar(ah, 0); 9006 9007 *total_flags &= SUPPORTED_FILTERS; 9008 ar->filter_flags = *total_flags; 9009 } 9010 9011 static int ath12k_mac_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) 9012 { 9013 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 9014 int antennas_rx = 0, antennas_tx = 0; 9015 struct ath12k *ar; 9016 int i; 9017 9018 lockdep_assert_wiphy(hw->wiphy); 9019 9020 for_each_ar(ah, ar, i) { 9021 antennas_rx = max_t(u32, antennas_rx, ar->cfg_rx_chainmask); 9022 antennas_tx = max_t(u32, antennas_tx, ar->cfg_tx_chainmask); 9023 } 9024 9025 *tx_ant = antennas_tx; 9026 *rx_ant = antennas_rx; 9027 9028 return 0; 9029 } 9030 9031 static int ath12k_mac_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) 9032 { 9033 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 9034 struct ath12k *ar; 9035 int ret = 0; 9036 int i; 9037 9038 lockdep_assert_wiphy(hw->wiphy); 9039 9040 for_each_ar(ah, ar, i) { 9041 ret = __ath12k_set_antenna(ar, tx_ant, rx_ant); 9042 if (ret) 9043 break; 9044 } 9045 9046 return ret; 9047 } 9048 9049 static int ath12k_mac_ampdu_action(struct ieee80211_hw *hw, 9050 struct ieee80211_vif *vif, 9051 struct ieee80211_ampdu_params *params, 9052 u8 link_id) 9053 { 9054 struct ath12k *ar; 9055 int ret = -EINVAL; 9056 9057 lockdep_assert_wiphy(hw->wiphy); 9058 9059 ar = ath12k_get_ar_by_vif(hw, vif, link_id); 9060 if (!ar) 9061 return -EINVAL; 9062 9063 switch (params->action) { 9064 case IEEE80211_AMPDU_RX_START: 9065 ret = ath12k_dp_rx_ampdu_start(ar, params, link_id); 9066 break; 9067 case IEEE80211_AMPDU_RX_STOP: 9068 ret = ath12k_dp_rx_ampdu_stop(ar, params, link_id); 9069 break; 9070 case IEEE80211_AMPDU_TX_START: 9071 case IEEE80211_AMPDU_TX_STOP_CONT: 9072 case IEEE80211_AMPDU_TX_STOP_FLUSH: 9073 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 9074 case IEEE80211_AMPDU_TX_OPERATIONAL: 9075 /* Tx A-MPDU aggregation offloaded to hw/fw so deny mac80211 9076 * Tx aggregation requests. 9077 */ 9078 ret = -EOPNOTSUPP; 9079 break; 9080 } 9081 9082 if (ret) 9083 ath12k_warn(ar->ab, "unable to perform ampdu action %d for vif %pM link %u ret %d\n", 9084 params->action, vif->addr, link_id, ret); 9085 9086 return ret; 9087 } 9088 9089 static int ath12k_mac_op_ampdu_action(struct ieee80211_hw *hw, 9090 struct ieee80211_vif *vif, 9091 struct ieee80211_ampdu_params *params) 9092 { 9093 struct ieee80211_sta *sta = params->sta; 9094 struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); 9095 unsigned long links_map = ahsta->links_map; 9096 int ret = -EINVAL; 9097 u8 link_id; 9098 9099 lockdep_assert_wiphy(hw->wiphy); 9100 9101 if (WARN_ON(!links_map)) 9102 return ret; 9103 9104 for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { 9105 ret = ath12k_mac_ampdu_action(hw, vif, params, link_id); 9106 if (ret) 9107 return ret; 9108 } 9109 9110 return 0; 9111 } 9112 9113 static int ath12k_mac_op_add_chanctx(struct ieee80211_hw *hw, 9114 struct ieee80211_chanctx_conf *ctx) 9115 { 9116 struct ath12k *ar; 9117 struct ath12k_base *ab; 9118 9119 lockdep_assert_wiphy(hw->wiphy); 9120 9121 ar = ath12k_get_ar_by_ctx(hw, ctx); 9122 if (!ar) 9123 return -EINVAL; 9124 9125 ab = ar->ab; 9126 9127 ath12k_dbg(ab, ATH12K_DBG_MAC, 9128 "mac chanctx add freq %u width %d ptr %p\n", 9129 ctx->def.chan->center_freq, ctx->def.width, ctx); 9130 9131 spin_lock_bh(&ar->data_lock); 9132 /* TODO: In case of multiple channel context, populate rx_channel from 9133 * Rx PPDU desc information. 9134 */ 9135 ar->rx_channel = ctx->def.chan; 9136 spin_unlock_bh(&ar->data_lock); 9137 ar->chan_tx_pwr = ATH12K_PDEV_TX_POWER_INVALID; 9138 9139 return 0; 9140 } 9141 9142 static void ath12k_mac_op_remove_chanctx(struct ieee80211_hw *hw, 9143 struct ieee80211_chanctx_conf *ctx) 9144 { 9145 struct ath12k *ar; 9146 struct ath12k_base *ab; 9147 9148 lockdep_assert_wiphy(hw->wiphy); 9149 9150 ar = ath12k_get_ar_by_ctx(hw, ctx); 9151 if (!ar) 9152 return; 9153 9154 ab = ar->ab; 9155 9156 ath12k_dbg(ab, ATH12K_DBG_MAC, 9157 "mac chanctx remove freq %u width %d ptr %p\n", 9158 ctx->def.chan->center_freq, ctx->def.width, ctx); 9159 9160 spin_lock_bh(&ar->data_lock); 9161 /* TODO: In case of there is one more channel context left, populate 9162 * rx_channel with the channel of that remaining channel context. 9163 */ 9164 ar->rx_channel = NULL; 9165 spin_unlock_bh(&ar->data_lock); 9166 ar->chan_tx_pwr = ATH12K_PDEV_TX_POWER_INVALID; 9167 } 9168 9169 static enum wmi_phy_mode 9170 ath12k_mac_check_down_grade_phy_mode(struct ath12k *ar, 9171 enum wmi_phy_mode mode, 9172 enum nl80211_band band, 9173 enum nl80211_iftype type) 9174 { 9175 struct ieee80211_sta_eht_cap *eht_cap = NULL; 9176 enum wmi_phy_mode down_mode; 9177 int n = ar->mac.sbands[band].n_iftype_data; 9178 int i; 9179 struct ieee80211_sband_iftype_data *data; 9180 9181 if (mode < MODE_11BE_EHT20) 9182 return mode; 9183 9184 data = ar->mac.iftype[band]; 9185 for (i = 0; i < n; i++) { 9186 if (data[i].types_mask & BIT(type)) { 9187 eht_cap = &data[i].eht_cap; 9188 break; 9189 } 9190 } 9191 9192 if (eht_cap && eht_cap->has_eht) 9193 return mode; 9194 9195 switch (mode) { 9196 case MODE_11BE_EHT20: 9197 down_mode = MODE_11AX_HE20; 9198 break; 9199 case MODE_11BE_EHT40: 9200 down_mode = MODE_11AX_HE40; 9201 break; 9202 case MODE_11BE_EHT80: 9203 down_mode = MODE_11AX_HE80; 9204 break; 9205 case MODE_11BE_EHT80_80: 9206 down_mode = MODE_11AX_HE80_80; 9207 break; 9208 case MODE_11BE_EHT160: 9209 case MODE_11BE_EHT160_160: 9210 case MODE_11BE_EHT320: 9211 down_mode = MODE_11AX_HE160; 9212 break; 9213 case MODE_11BE_EHT20_2G: 9214 down_mode = MODE_11AX_HE20_2G; 9215 break; 9216 case MODE_11BE_EHT40_2G: 9217 down_mode = MODE_11AX_HE40_2G; 9218 break; 9219 default: 9220 down_mode = mode; 9221 break; 9222 } 9223 9224 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 9225 "mac vdev start phymode %s downgrade to %s\n", 9226 ath12k_mac_phymode_str(mode), 9227 ath12k_mac_phymode_str(down_mode)); 9228 9229 return down_mode; 9230 } 9231 9232 static void 9233 ath12k_mac_mlo_get_vdev_args(struct ath12k_link_vif *arvif, 9234 struct wmi_ml_arg *ml_arg) 9235 { 9236 struct ath12k_vif *ahvif = arvif->ahvif; 9237 struct wmi_ml_partner_info *partner_info; 9238 struct ieee80211_bss_conf *link_conf; 9239 struct ath12k_link_vif *arvif_p; 9240 unsigned long links; 9241 u8 link_id; 9242 9243 lockdep_assert_wiphy(ahvif->ah->hw->wiphy); 9244 9245 if (!ath12k_mac_is_ml_arvif(arvif)) 9246 return; 9247 9248 if (hweight16(ahvif->vif->valid_links) > ATH12K_WMI_MLO_MAX_LINKS) 9249 return; 9250 9251 ml_arg->enabled = true; 9252 9253 /* Driver always add a new link via VDEV START, FW takes 9254 * care of internally adding this link to existing 9255 * link vdevs which are advertised as partners below 9256 */ 9257 ml_arg->link_add = true; 9258 9259 ml_arg->assoc_link = arvif->is_sta_assoc_link; 9260 9261 partner_info = ml_arg->partner_info; 9262 9263 links = ahvif->links_map; 9264 for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { 9265 arvif_p = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]); 9266 9267 if (WARN_ON(!arvif_p)) 9268 continue; 9269 9270 if (arvif == arvif_p) 9271 continue; 9272 9273 if (!arvif_p->is_created) 9274 continue; 9275 9276 link_conf = wiphy_dereference(ahvif->ah->hw->wiphy, 9277 ahvif->vif->link_conf[arvif_p->link_id]); 9278 9279 if (!link_conf) 9280 continue; 9281 9282 partner_info->vdev_id = arvif_p->vdev_id; 9283 partner_info->hw_link_id = arvif_p->ar->pdev->hw_link_id; 9284 ether_addr_copy(partner_info->addr, link_conf->addr); 9285 ml_arg->num_partner_links++; 9286 partner_info++; 9287 } 9288 } 9289 9290 static int 9291 ath12k_mac_vdev_start_restart(struct ath12k_link_vif *arvif, 9292 struct ieee80211_chanctx_conf *ctx, 9293 bool restart) 9294 { 9295 struct ath12k *ar = arvif->ar; 9296 struct ath12k_base *ab = ar->ab; 9297 struct wmi_vdev_start_req_arg arg = {}; 9298 const struct cfg80211_chan_def *chandef = &ctx->def; 9299 struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); 9300 struct ath12k_vif *ahvif = arvif->ahvif; 9301 struct ieee80211_bss_conf *link_conf; 9302 unsigned int dfs_cac_time; 9303 int ret; 9304 9305 lockdep_assert_wiphy(hw->wiphy); 9306 9307 link_conf = ath12k_mac_get_link_bss_conf(arvif); 9308 if (!link_conf) { 9309 ath12k_warn(ar->ab, "unable to access bss link conf in vdev start for vif %pM link %u\n", 9310 ahvif->vif->addr, arvif->link_id); 9311 return -ENOLINK; 9312 } 9313 9314 reinit_completion(&ar->vdev_setup_done); 9315 9316 arg.vdev_id = arvif->vdev_id; 9317 arg.dtim_period = arvif->dtim_period; 9318 arg.bcn_intval = arvif->beacon_interval; 9319 arg.punct_bitmap = ~arvif->punct_bitmap; 9320 9321 arg.freq = chandef->chan->center_freq; 9322 arg.band_center_freq1 = chandef->center_freq1; 9323 arg.band_center_freq2 = chandef->center_freq2; 9324 arg.mode = ath12k_phymodes[chandef->chan->band][chandef->width]; 9325 9326 arg.mode = ath12k_mac_check_down_grade_phy_mode(ar, arg.mode, 9327 chandef->chan->band, 9328 ahvif->vif->type); 9329 arg.min_power = 0; 9330 arg.max_power = chandef->chan->max_power; 9331 arg.max_reg_power = chandef->chan->max_reg_power; 9332 arg.max_antenna_gain = chandef->chan->max_antenna_gain; 9333 9334 arg.pref_tx_streams = ar->num_tx_chains; 9335 arg.pref_rx_streams = ar->num_rx_chains; 9336 9337 arg.mbssid_flags = WMI_VDEV_MBSSID_FLAGS_NON_MBSSID_AP; 9338 arg.mbssid_tx_vdev_id = 0; 9339 if (test_bit(WMI_TLV_SERVICE_MBSS_PARAM_IN_VDEV_START_SUPPORT, 9340 ar->ab->wmi_ab.svc_map)) { 9341 ret = ath12k_mac_setup_vdev_params_mbssid(arvif, 9342 &arg.mbssid_flags, 9343 &arg.mbssid_tx_vdev_id); 9344 if (ret) 9345 return ret; 9346 } 9347 9348 if (ahvif->vdev_type == WMI_VDEV_TYPE_AP) { 9349 arg.ssid = ahvif->u.ap.ssid; 9350 arg.ssid_len = ahvif->u.ap.ssid_len; 9351 arg.hidden_ssid = ahvif->u.ap.hidden_ssid; 9352 9353 /* For now allow DFS for AP mode */ 9354 arg.chan_radar = !!(chandef->chan->flags & IEEE80211_CHAN_RADAR); 9355 9356 arg.freq2_radar = ctx->radar_enabled; 9357 9358 arg.passive = arg.chan_radar; 9359 9360 spin_lock_bh(&ab->base_lock); 9361 arg.regdomain = ar->ab->dfs_region; 9362 spin_unlock_bh(&ab->base_lock); 9363 9364 /* TODO: Notify if secondary 80Mhz also needs radar detection */ 9365 if (link_conf->he_support) { 9366 ret = ath12k_set_he_mu_sounding_mode(ar, arvif); 9367 if (ret) { 9368 ath12k_warn(ar->ab, "failed to set he mode vdev %i\n", 9369 arg.vdev_id); 9370 return ret; 9371 } 9372 } 9373 } 9374 9375 arg.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR); 9376 9377 if (!restart) 9378 ath12k_mac_mlo_get_vdev_args(arvif, &arg.ml); 9379 9380 ath12k_dbg(ab, ATH12K_DBG_MAC, 9381 "mac vdev %d start center_freq %d phymode %s punct_bitmap 0x%x\n", 9382 arg.vdev_id, arg.freq, 9383 ath12k_mac_phymode_str(arg.mode), arg.punct_bitmap); 9384 9385 ret = ath12k_wmi_vdev_start(ar, &arg, restart); 9386 if (ret) { 9387 ath12k_warn(ar->ab, "failed to %s WMI vdev %i\n", 9388 restart ? "restart" : "start", arg.vdev_id); 9389 return ret; 9390 } 9391 9392 ret = ath12k_mac_vdev_setup_sync(ar); 9393 if (ret) { 9394 ath12k_warn(ab, "failed to synchronize setup for vdev %i %s: %d\n", 9395 arg.vdev_id, restart ? "restart" : "start", ret); 9396 return ret; 9397 } 9398 9399 /* TODO: For now we only set TPC power here. However when 9400 * channel changes, say CSA, it should be updated again. 9401 */ 9402 if (ath12k_mac_supports_station_tpc(ar, ahvif, chandef)) { 9403 ath12k_mac_fill_reg_tpc_info(ar, arvif, ctx); 9404 ath12k_wmi_send_vdev_set_tpc_power(ar, arvif->vdev_id, 9405 &arvif->reg_tpc_info); 9406 } 9407 9408 ar->num_started_vdevs++; 9409 ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM started, vdev_id %d\n", 9410 ahvif->vif->addr, arvif->vdev_id); 9411 9412 /* Enable CAC Running Flag in the driver by checking all sub-channel's DFS 9413 * state as NL80211_DFS_USABLE which indicates CAC needs to be 9414 * done before channel usage. This flag is used to drop rx packets. 9415 * during CAC. 9416 */ 9417 /* TODO: Set the flag for other interface types as required */ 9418 if (arvif->ahvif->vdev_type == WMI_VDEV_TYPE_AP && ctx->radar_enabled && 9419 cfg80211_chandef_dfs_usable(hw->wiphy, chandef)) { 9420 set_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags); 9421 dfs_cac_time = cfg80211_chandef_dfs_cac_time(hw->wiphy, chandef); 9422 9423 ath12k_dbg(ab, ATH12K_DBG_MAC, 9424 "CAC started dfs_cac_time %u center_freq %d center_freq1 %d for vdev %d\n", 9425 dfs_cac_time, arg.freq, arg.band_center_freq1, arg.vdev_id); 9426 } 9427 9428 ret = ath12k_mac_set_txbf_conf(arvif); 9429 if (ret) 9430 ath12k_warn(ab, "failed to set txbf conf for vdev %d: %d\n", 9431 arvif->vdev_id, ret); 9432 9433 return 0; 9434 } 9435 9436 static int ath12k_mac_vdev_start(struct ath12k_link_vif *arvif, 9437 struct ieee80211_chanctx_conf *ctx) 9438 { 9439 return ath12k_mac_vdev_start_restart(arvif, ctx, false); 9440 } 9441 9442 static int ath12k_mac_vdev_restart(struct ath12k_link_vif *arvif, 9443 struct ieee80211_chanctx_conf *ctx) 9444 { 9445 return ath12k_mac_vdev_start_restart(arvif, ctx, true); 9446 } 9447 9448 struct ath12k_mac_change_chanctx_arg { 9449 struct ieee80211_chanctx_conf *ctx; 9450 struct ieee80211_vif_chanctx_switch *vifs; 9451 int n_vifs; 9452 int next_vif; 9453 struct ath12k *ar; 9454 }; 9455 9456 static void 9457 ath12k_mac_change_chanctx_cnt_iter(void *data, u8 *mac, 9458 struct ieee80211_vif *vif) 9459 { 9460 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 9461 struct ath12k_mac_change_chanctx_arg *arg = data; 9462 struct ieee80211_bss_conf *link_conf; 9463 struct ath12k_link_vif *arvif; 9464 unsigned long links_map; 9465 u8 link_id; 9466 9467 lockdep_assert_wiphy(ahvif->ah->hw->wiphy); 9468 9469 links_map = ahvif->links_map; 9470 for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { 9471 arvif = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]); 9472 if (WARN_ON(!arvif)) 9473 continue; 9474 9475 if (arvif->ar != arg->ar) 9476 continue; 9477 9478 link_conf = wiphy_dereference(ahvif->ah->hw->wiphy, 9479 vif->link_conf[link_id]); 9480 if (WARN_ON(!link_conf)) 9481 continue; 9482 9483 if (rcu_access_pointer(link_conf->chanctx_conf) != arg->ctx) 9484 continue; 9485 9486 arg->n_vifs++; 9487 } 9488 } 9489 9490 static void 9491 ath12k_mac_change_chanctx_fill_iter(void *data, u8 *mac, 9492 struct ieee80211_vif *vif) 9493 { 9494 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 9495 struct ath12k_mac_change_chanctx_arg *arg = data; 9496 struct ieee80211_bss_conf *link_conf; 9497 struct ieee80211_chanctx_conf *ctx; 9498 struct ath12k_link_vif *arvif; 9499 unsigned long links_map; 9500 u8 link_id; 9501 9502 lockdep_assert_wiphy(ahvif->ah->hw->wiphy); 9503 9504 links_map = ahvif->links_map; 9505 for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { 9506 arvif = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]); 9507 if (WARN_ON(!arvif)) 9508 continue; 9509 9510 if (arvif->ar != arg->ar) 9511 continue; 9512 9513 link_conf = wiphy_dereference(ahvif->ah->hw->wiphy, 9514 vif->link_conf[arvif->link_id]); 9515 if (WARN_ON(!link_conf)) 9516 continue; 9517 9518 ctx = rcu_access_pointer(link_conf->chanctx_conf); 9519 if (ctx != arg->ctx) 9520 continue; 9521 9522 if (WARN_ON(arg->next_vif == arg->n_vifs)) 9523 return; 9524 9525 arg->vifs[arg->next_vif].vif = vif; 9526 arg->vifs[arg->next_vif].old_ctx = ctx; 9527 arg->vifs[arg->next_vif].new_ctx = ctx; 9528 arg->vifs[arg->next_vif].link_conf = link_conf; 9529 arg->next_vif++; 9530 } 9531 } 9532 9533 static u32 ath12k_mac_nlwidth_to_wmiwidth(enum nl80211_chan_width width) 9534 { 9535 switch (width) { 9536 case NL80211_CHAN_WIDTH_20: 9537 return WMI_CHAN_WIDTH_20; 9538 case NL80211_CHAN_WIDTH_40: 9539 return WMI_CHAN_WIDTH_40; 9540 case NL80211_CHAN_WIDTH_80: 9541 return WMI_CHAN_WIDTH_80; 9542 case NL80211_CHAN_WIDTH_160: 9543 return WMI_CHAN_WIDTH_160; 9544 case NL80211_CHAN_WIDTH_80P80: 9545 return WMI_CHAN_WIDTH_80P80; 9546 case NL80211_CHAN_WIDTH_5: 9547 return WMI_CHAN_WIDTH_5; 9548 case NL80211_CHAN_WIDTH_10: 9549 return WMI_CHAN_WIDTH_10; 9550 case NL80211_CHAN_WIDTH_320: 9551 return WMI_CHAN_WIDTH_320; 9552 default: 9553 WARN_ON(1); 9554 return WMI_CHAN_WIDTH_20; 9555 } 9556 } 9557 9558 static int ath12k_mac_update_peer_puncturing_width(struct ath12k *ar, 9559 struct ath12k_link_vif *arvif, 9560 struct cfg80211_chan_def def) 9561 { 9562 u32 param_id, param_value; 9563 int ret; 9564 9565 if (arvif->ahvif->vdev_type != WMI_VDEV_TYPE_STA) 9566 return 0; 9567 9568 param_id = WMI_PEER_CHWIDTH_PUNCTURE_20MHZ_BITMAP; 9569 param_value = ath12k_mac_nlwidth_to_wmiwidth(def.width) | 9570 u32_encode_bits((~def.punctured), 9571 WMI_PEER_PUNCTURE_BITMAP); 9572 9573 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 9574 "punctured bitmap %02x width %d vdev %d\n", 9575 def.punctured, def.width, arvif->vdev_id); 9576 9577 ret = ath12k_wmi_set_peer_param(ar, arvif->bssid, 9578 arvif->vdev_id, param_id, 9579 param_value); 9580 9581 return ret; 9582 } 9583 9584 static void 9585 ath12k_mac_update_vif_chan(struct ath12k *ar, 9586 struct ieee80211_vif_chanctx_switch *vifs, 9587 int n_vifs) 9588 { 9589 struct ath12k_wmi_vdev_up_params params = {}; 9590 struct ath12k_link_vif *arvif, *tx_arvif; 9591 struct ieee80211_bss_conf *link_conf; 9592 struct ath12k_base *ab = ar->ab; 9593 struct ieee80211_vif *vif; 9594 struct ath12k_vif *ahvif; 9595 u8 link_id; 9596 int ret; 9597 int i; 9598 bool monitor_vif = false; 9599 9600 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 9601 9602 for (i = 0; i < n_vifs; i++) { 9603 vif = vifs[i].vif; 9604 ahvif = ath12k_vif_to_ahvif(vif); 9605 link_conf = vifs[i].link_conf; 9606 link_id = link_conf->link_id; 9607 arvif = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, 9608 ahvif->link[link_id]); 9609 9610 if (vif->type == NL80211_IFTYPE_MONITOR) { 9611 monitor_vif = true; 9612 continue; 9613 } 9614 9615 ath12k_dbg(ab, ATH12K_DBG_MAC, 9616 "mac chanctx switch vdev_id %i freq %u->%u width %d->%d\n", 9617 arvif->vdev_id, 9618 vifs[i].old_ctx->def.chan->center_freq, 9619 vifs[i].new_ctx->def.chan->center_freq, 9620 vifs[i].old_ctx->def.width, 9621 vifs[i].new_ctx->def.width); 9622 9623 if (WARN_ON(!arvif->is_started)) 9624 continue; 9625 9626 arvif->punct_bitmap = vifs[i].new_ctx->def.punctured; 9627 9628 /* Firmware expect vdev_restart only if vdev is up. 9629 * If vdev is down then it expect vdev_stop->vdev_start. 9630 */ 9631 if (arvif->is_up) { 9632 ret = ath12k_mac_vdev_restart(arvif, vifs[i].new_ctx); 9633 if (ret) { 9634 ath12k_warn(ab, "failed to restart vdev %d: %d\n", 9635 arvif->vdev_id, ret); 9636 continue; 9637 } 9638 } else { 9639 ret = ath12k_mac_vdev_stop(arvif); 9640 if (ret) { 9641 ath12k_warn(ab, "failed to stop vdev %d: %d\n", 9642 arvif->vdev_id, ret); 9643 continue; 9644 } 9645 9646 ret = ath12k_mac_vdev_start(arvif, vifs[i].new_ctx); 9647 if (ret) 9648 ath12k_warn(ab, "failed to start vdev %d: %d\n", 9649 arvif->vdev_id, ret); 9650 continue; 9651 } 9652 9653 ret = ath12k_mac_setup_bcn_tmpl(arvif); 9654 if (ret) 9655 ath12k_warn(ab, "failed to update bcn tmpl during csa: %d\n", 9656 ret); 9657 9658 memset(¶ms, 0, sizeof(params)); 9659 params.vdev_id = arvif->vdev_id; 9660 params.aid = ahvif->aid; 9661 params.bssid = arvif->bssid; 9662 9663 tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf); 9664 if (tx_arvif) { 9665 params.tx_bssid = tx_arvif->bssid; 9666 params.nontx_profile_idx = link_conf->bssid_index; 9667 params.nontx_profile_cnt = 1 << link_conf->bssid_indicator; 9668 } 9669 ret = ath12k_wmi_vdev_up(arvif->ar, ¶ms); 9670 if (ret) { 9671 ath12k_warn(ab, "failed to bring vdev up %d: %d\n", 9672 arvif->vdev_id, ret); 9673 continue; 9674 } 9675 9676 ret = ath12k_mac_update_peer_puncturing_width(arvif->ar, arvif, 9677 vifs[i].new_ctx->def); 9678 if (ret) { 9679 ath12k_warn(ar->ab, 9680 "failed to update puncturing bitmap %02x and width %d: %d\n", 9681 vifs[i].new_ctx->def.punctured, 9682 vifs[i].new_ctx->def.width, ret); 9683 continue; 9684 } 9685 } 9686 9687 /* Restart the internal monitor vdev on new channel */ 9688 if (!monitor_vif && ar->monitor_vdev_created) { 9689 if (!ath12k_mac_monitor_stop(ar)) 9690 ath12k_mac_monitor_start(ar); 9691 } 9692 } 9693 9694 static void 9695 ath12k_mac_update_active_vif_chan(struct ath12k *ar, 9696 struct ieee80211_chanctx_conf *ctx) 9697 { 9698 struct ath12k_mac_change_chanctx_arg arg = { .ctx = ctx, .ar = ar }; 9699 struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); 9700 9701 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 9702 9703 ieee80211_iterate_active_interfaces_atomic(hw, 9704 IEEE80211_IFACE_ITER_NORMAL, 9705 ath12k_mac_change_chanctx_cnt_iter, 9706 &arg); 9707 if (arg.n_vifs == 0) 9708 return; 9709 9710 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]), GFP_KERNEL); 9711 if (!arg.vifs) 9712 return; 9713 9714 ieee80211_iterate_active_interfaces_atomic(hw, 9715 IEEE80211_IFACE_ITER_NORMAL, 9716 ath12k_mac_change_chanctx_fill_iter, 9717 &arg); 9718 9719 ath12k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs); 9720 9721 kfree(arg.vifs); 9722 } 9723 9724 static void ath12k_mac_op_change_chanctx(struct ieee80211_hw *hw, 9725 struct ieee80211_chanctx_conf *ctx, 9726 u32 changed) 9727 { 9728 struct ath12k *ar; 9729 struct ath12k_base *ab; 9730 9731 lockdep_assert_wiphy(hw->wiphy); 9732 9733 ar = ath12k_get_ar_by_ctx(hw, ctx); 9734 if (!ar) 9735 return; 9736 9737 ab = ar->ab; 9738 9739 ath12k_dbg(ab, ATH12K_DBG_MAC, 9740 "mac chanctx change freq %u width %d ptr %p changed %x\n", 9741 ctx->def.chan->center_freq, ctx->def.width, ctx, changed); 9742 9743 /* This shouldn't really happen because channel switching should use 9744 * switch_vif_chanctx(). 9745 */ 9746 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL)) 9747 return; 9748 9749 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH || 9750 changed & IEEE80211_CHANCTX_CHANGE_RADAR || 9751 changed & IEEE80211_CHANCTX_CHANGE_PUNCTURING) 9752 ath12k_mac_update_active_vif_chan(ar, ctx); 9753 9754 /* TODO: Recalc radar detection */ 9755 } 9756 9757 static int ath12k_start_vdev_delay(struct ath12k *ar, 9758 struct ath12k_link_vif *arvif) 9759 { 9760 struct ath12k_base *ab = ar->ab; 9761 struct ath12k_vif *ahvif = arvif->ahvif; 9762 struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); 9763 struct ieee80211_chanctx_conf *chanctx; 9764 struct ieee80211_bss_conf *link_conf; 9765 int ret; 9766 9767 if (WARN_ON(arvif->is_started)) 9768 return -EBUSY; 9769 9770 link_conf = ath12k_mac_get_link_bss_conf(arvif); 9771 if (!link_conf) { 9772 ath12k_warn(ab, "failed to get link conf for vdev %u\n", arvif->vdev_id); 9773 return -EINVAL; 9774 } 9775 9776 chanctx = wiphy_dereference(ath12k_ar_to_hw(arvif->ar)->wiphy, 9777 link_conf->chanctx_conf); 9778 ret = ath12k_mac_vdev_start(arvif, chanctx); 9779 if (ret) { 9780 ath12k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n", 9781 arvif->vdev_id, vif->addr, 9782 chanctx->def.chan->center_freq, ret); 9783 return ret; 9784 } 9785 9786 if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { 9787 ret = ath12k_monitor_vdev_up(ar, arvif->vdev_id); 9788 if (ret) { 9789 ath12k_warn(ab, "failed put monitor up: %d\n", ret); 9790 return ret; 9791 } 9792 } 9793 9794 arvif->is_started = true; 9795 9796 /* TODO: Setup ps and cts/rts protection */ 9797 return 0; 9798 } 9799 9800 static u8 ath12k_mac_get_num_pwr_levels(struct cfg80211_chan_def *chan_def) 9801 { 9802 if (chan_def->chan->flags & IEEE80211_CHAN_PSD) { 9803 switch (chan_def->width) { 9804 case NL80211_CHAN_WIDTH_20: 9805 return 1; 9806 case NL80211_CHAN_WIDTH_40: 9807 return 2; 9808 case NL80211_CHAN_WIDTH_80: 9809 return 4; 9810 case NL80211_CHAN_WIDTH_160: 9811 return 8; 9812 case NL80211_CHAN_WIDTH_320: 9813 return 16; 9814 default: 9815 return 1; 9816 } 9817 } else { 9818 switch (chan_def->width) { 9819 case NL80211_CHAN_WIDTH_20: 9820 return 1; 9821 case NL80211_CHAN_WIDTH_40: 9822 return 2; 9823 case NL80211_CHAN_WIDTH_80: 9824 return 3; 9825 case NL80211_CHAN_WIDTH_160: 9826 return 4; 9827 case NL80211_CHAN_WIDTH_320: 9828 return 5; 9829 default: 9830 return 1; 9831 } 9832 } 9833 } 9834 9835 static u16 ath12k_mac_get_6ghz_start_frequency(struct cfg80211_chan_def *chan_def) 9836 { 9837 u16 diff_seq; 9838 9839 /* It is to get the lowest channel number's center frequency of the chan. 9840 * For example, 9841 * bandwidth=40 MHz, center frequency is 5965, lowest channel is 1 9842 * with center frequency 5955, its diff is 5965 - 5955 = 10. 9843 * bandwidth=80 MHz, center frequency is 5985, lowest channel is 1 9844 * with center frequency 5955, its diff is 5985 - 5955 = 30. 9845 * bandwidth=160 MHz, center frequency is 6025, lowest channel is 1 9846 * with center frequency 5955, its diff is 6025 - 5955 = 70. 9847 * bandwidth=320 MHz, center frequency is 6105, lowest channel is 1 9848 * with center frequency 5955, its diff is 6105 - 5955 = 70. 9849 */ 9850 switch (chan_def->width) { 9851 case NL80211_CHAN_WIDTH_320: 9852 diff_seq = 150; 9853 break; 9854 case NL80211_CHAN_WIDTH_160: 9855 diff_seq = 70; 9856 break; 9857 case NL80211_CHAN_WIDTH_80: 9858 diff_seq = 30; 9859 break; 9860 case NL80211_CHAN_WIDTH_40: 9861 diff_seq = 10; 9862 break; 9863 default: 9864 diff_seq = 0; 9865 } 9866 9867 return chan_def->center_freq1 - diff_seq; 9868 } 9869 9870 static u16 ath12k_mac_get_seg_freq(struct cfg80211_chan_def *chan_def, 9871 u16 start_seq, u8 seq) 9872 { 9873 u16 seg_seq; 9874 9875 /* It is to get the center frequency of the specific bandwidth. 9876 * start_seq means the lowest channel number's center frequency. 9877 * seq 0/1/2/3 means 20 MHz/40 MHz/80 MHz/160 MHz. 9878 * For example, 9879 * lowest channel is 1, its center frequency 5955, 9880 * center frequency is 5955 when bandwidth=20 MHz, its diff is 5955 - 5955 = 0. 9881 * lowest channel is 1, its center frequency 5955, 9882 * center frequency is 5965 when bandwidth=40 MHz, its diff is 5965 - 5955 = 10. 9883 * lowest channel is 1, its center frequency 5955, 9884 * center frequency is 5985 when bandwidth=80 MHz, its diff is 5985 - 5955 = 30. 9885 * lowest channel is 1, its center frequency 5955, 9886 * center frequency is 6025 when bandwidth=160 MHz, its diff is 6025 - 5955 = 70. 9887 */ 9888 seg_seq = 10 * (BIT(seq) - 1); 9889 return seg_seq + start_seq; 9890 } 9891 9892 static void ath12k_mac_get_psd_channel(struct ath12k *ar, 9893 u16 step_freq, 9894 u16 *start_freq, 9895 u16 *center_freq, 9896 u8 i, 9897 struct ieee80211_channel **temp_chan, 9898 s8 *tx_power) 9899 { 9900 /* It is to get the center frequency for each 20 MHz. 9901 * For example, if the chan is 160 MHz and center frequency is 6025, 9902 * then it include 8 channels, they are 1/5/9/13/17/21/25/29, 9903 * channel number 1's center frequency is 5955, it is parameter start_freq. 9904 * parameter i is the step of the 8 channels. i is 0~7 for the 8 channels. 9905 * the channel 1/5/9/13/17/21/25/29 maps i=0/1/2/3/4/5/6/7, 9906 * and maps its center frequency is 5955/5975/5995/6015/6035/6055/6075/6095, 9907 * the gap is 20 for each channel, parameter step_freq means the gap. 9908 * after get the center frequency of each channel, it is easy to find the 9909 * struct ieee80211_channel of it and get the max_reg_power. 9910 */ 9911 *center_freq = *start_freq + i * step_freq; 9912 *temp_chan = ieee80211_get_channel(ar->ah->hw->wiphy, *center_freq); 9913 *tx_power = (*temp_chan)->max_reg_power; 9914 } 9915 9916 static void ath12k_mac_get_eirp_power(struct ath12k *ar, 9917 u16 *start_freq, 9918 u16 *center_freq, 9919 u8 i, 9920 struct ieee80211_channel **temp_chan, 9921 struct cfg80211_chan_def *def, 9922 s8 *tx_power) 9923 { 9924 /* It is to get the center frequency for 20 MHz/40 MHz/80 MHz/ 9925 * 160 MHz bandwidth, and then plus 10 to the center frequency, 9926 * it is the center frequency of a channel number. 9927 * For example, when configured channel number is 1. 9928 * center frequency is 5965 when bandwidth=40 MHz, after plus 10, it is 5975, 9929 * then it is channel number 5. 9930 * center frequency is 5985 when bandwidth=80 MHz, after plus 10, it is 5995, 9931 * then it is channel number 9. 9932 * center frequency is 6025 when bandwidth=160 MHz, after plus 10, it is 6035, 9933 * then it is channel number 17. 9934 * after get the center frequency of each channel, it is easy to find the 9935 * struct ieee80211_channel of it and get the max_reg_power. 9936 */ 9937 *center_freq = ath12k_mac_get_seg_freq(def, *start_freq, i); 9938 9939 /* For the 20 MHz, its center frequency is same with same channel */ 9940 if (i != 0) 9941 *center_freq += 10; 9942 9943 *temp_chan = ieee80211_get_channel(ar->ah->hw->wiphy, *center_freq); 9944 *tx_power = (*temp_chan)->max_reg_power; 9945 } 9946 9947 void ath12k_mac_fill_reg_tpc_info(struct ath12k *ar, 9948 struct ath12k_link_vif *arvif, 9949 struct ieee80211_chanctx_conf *ctx) 9950 { 9951 struct ath12k_base *ab = ar->ab; 9952 struct ath12k_reg_tpc_power_info *reg_tpc_info = &arvif->reg_tpc_info; 9953 struct ieee80211_bss_conf *bss_conf = ath12k_mac_get_link_bss_conf(arvif); 9954 struct ieee80211_channel *chan, *temp_chan; 9955 u8 pwr_lvl_idx, num_pwr_levels, pwr_reduction; 9956 bool is_psd_power = false, is_tpe_present = false; 9957 s8 max_tx_power[ATH12K_NUM_PWR_LEVELS], 9958 psd_power, tx_power, eirp_power; 9959 u16 start_freq, center_freq; 9960 9961 chan = ctx->def.chan; 9962 start_freq = ath12k_mac_get_6ghz_start_frequency(&ctx->def); 9963 pwr_reduction = bss_conf->pwr_reduction; 9964 9965 if (arvif->reg_tpc_info.num_pwr_levels) { 9966 is_tpe_present = true; 9967 num_pwr_levels = arvif->reg_tpc_info.num_pwr_levels; 9968 } else { 9969 num_pwr_levels = ath12k_mac_get_num_pwr_levels(&ctx->def); 9970 } 9971 9972 for (pwr_lvl_idx = 0; pwr_lvl_idx < num_pwr_levels; pwr_lvl_idx++) { 9973 /* STA received TPE IE*/ 9974 if (is_tpe_present) { 9975 /* local power is PSD power*/ 9976 if (chan->flags & IEEE80211_CHAN_PSD) { 9977 /* Connecting AP is psd power */ 9978 if (reg_tpc_info->is_psd_power) { 9979 is_psd_power = true; 9980 ath12k_mac_get_psd_channel(ar, 20, 9981 &start_freq, 9982 ¢er_freq, 9983 pwr_lvl_idx, 9984 &temp_chan, 9985 &tx_power); 9986 psd_power = temp_chan->psd; 9987 eirp_power = tx_power; 9988 max_tx_power[pwr_lvl_idx] = 9989 min_t(s8, 9990 psd_power, 9991 reg_tpc_info->tpe[pwr_lvl_idx]); 9992 /* Connecting AP is not psd power */ 9993 } else { 9994 ath12k_mac_get_eirp_power(ar, 9995 &start_freq, 9996 ¢er_freq, 9997 pwr_lvl_idx, 9998 &temp_chan, 9999 &ctx->def, 10000 &tx_power); 10001 psd_power = temp_chan->psd; 10002 /* convert psd power to EIRP power based 10003 * on channel width 10004 */ 10005 tx_power = 10006 min_t(s8, tx_power, 10007 psd_power + 13 + pwr_lvl_idx * 3); 10008 max_tx_power[pwr_lvl_idx] = 10009 min_t(s8, 10010 tx_power, 10011 reg_tpc_info->tpe[pwr_lvl_idx]); 10012 } 10013 /* local power is not PSD power */ 10014 } else { 10015 /* Connecting AP is psd power */ 10016 if (reg_tpc_info->is_psd_power) { 10017 is_psd_power = true; 10018 ath12k_mac_get_psd_channel(ar, 20, 10019 &start_freq, 10020 ¢er_freq, 10021 pwr_lvl_idx, 10022 &temp_chan, 10023 &tx_power); 10024 eirp_power = tx_power; 10025 max_tx_power[pwr_lvl_idx] = 10026 reg_tpc_info->tpe[pwr_lvl_idx]; 10027 /* Connecting AP is not psd power */ 10028 } else { 10029 ath12k_mac_get_eirp_power(ar, 10030 &start_freq, 10031 ¢er_freq, 10032 pwr_lvl_idx, 10033 &temp_chan, 10034 &ctx->def, 10035 &tx_power); 10036 max_tx_power[pwr_lvl_idx] = 10037 min_t(s8, 10038 tx_power, 10039 reg_tpc_info->tpe[pwr_lvl_idx]); 10040 } 10041 } 10042 /* STA not received TPE IE */ 10043 } else { 10044 /* local power is PSD power*/ 10045 if (chan->flags & IEEE80211_CHAN_PSD) { 10046 is_psd_power = true; 10047 ath12k_mac_get_psd_channel(ar, 20, 10048 &start_freq, 10049 ¢er_freq, 10050 pwr_lvl_idx, 10051 &temp_chan, 10052 &tx_power); 10053 psd_power = temp_chan->psd; 10054 eirp_power = tx_power; 10055 max_tx_power[pwr_lvl_idx] = psd_power; 10056 } else { 10057 ath12k_mac_get_eirp_power(ar, 10058 &start_freq, 10059 ¢er_freq, 10060 pwr_lvl_idx, 10061 &temp_chan, 10062 &ctx->def, 10063 &tx_power); 10064 max_tx_power[pwr_lvl_idx] = tx_power; 10065 } 10066 } 10067 10068 if (is_psd_power) { 10069 /* If AP local power constraint is present */ 10070 if (pwr_reduction) 10071 eirp_power = eirp_power - pwr_reduction; 10072 10073 /* If firmware updated max tx power is non zero, then take 10074 * the min of firmware updated ap tx power 10075 * and max power derived from above mentioned parameters. 10076 */ 10077 ath12k_dbg(ab, ATH12K_DBG_MAC, 10078 "eirp power : %d firmware report power : %d\n", 10079 eirp_power, ar->max_allowed_tx_power); 10080 /* Firmware reports lower max_allowed_tx_power during vdev 10081 * start response. In case of 6 GHz, firmware is not aware 10082 * of EIRP power unless driver sets EIRP power through WMI 10083 * TPC command. So radio which does not support idle power 10084 * save can set maximum calculated EIRP power directly to 10085 * firmware through TPC command without min comparison with 10086 * vdev start response's max_allowed_tx_power. 10087 */ 10088 if (ar->max_allowed_tx_power && ab->hw_params->idle_ps) 10089 eirp_power = min_t(s8, 10090 eirp_power, 10091 ar->max_allowed_tx_power); 10092 } else { 10093 /* If AP local power constraint is present */ 10094 if (pwr_reduction) 10095 max_tx_power[pwr_lvl_idx] = 10096 max_tx_power[pwr_lvl_idx] - pwr_reduction; 10097 /* If firmware updated max tx power is non zero, then take 10098 * the min of firmware updated ap tx power 10099 * and max power derived from above mentioned parameters. 10100 */ 10101 if (ar->max_allowed_tx_power && ab->hw_params->idle_ps) 10102 max_tx_power[pwr_lvl_idx] = 10103 min_t(s8, 10104 max_tx_power[pwr_lvl_idx], 10105 ar->max_allowed_tx_power); 10106 } 10107 reg_tpc_info->chan_power_info[pwr_lvl_idx].chan_cfreq = center_freq; 10108 reg_tpc_info->chan_power_info[pwr_lvl_idx].tx_power = 10109 max_tx_power[pwr_lvl_idx]; 10110 } 10111 10112 reg_tpc_info->num_pwr_levels = num_pwr_levels; 10113 reg_tpc_info->is_psd_power = is_psd_power; 10114 reg_tpc_info->eirp_power = eirp_power; 10115 reg_tpc_info->ap_power_type = 10116 ath12k_reg_ap_pwr_convert(bss_conf->power_type); 10117 } 10118 10119 static void ath12k_mac_parse_tx_pwr_env(struct ath12k *ar, 10120 struct ath12k_link_vif *arvif) 10121 { 10122 struct ieee80211_bss_conf *bss_conf = ath12k_mac_get_link_bss_conf(arvif); 10123 struct ath12k_reg_tpc_power_info *tpc_info = &arvif->reg_tpc_info; 10124 struct ieee80211_parsed_tpe_eirp *local_non_psd, *reg_non_psd; 10125 struct ieee80211_parsed_tpe_psd *local_psd, *reg_psd; 10126 struct ieee80211_parsed_tpe *tpe = &bss_conf->tpe; 10127 enum wmi_reg_6g_client_type client_type; 10128 struct ath12k_reg_info *reg_info; 10129 struct ath12k_base *ab = ar->ab; 10130 bool psd_valid, non_psd_valid; 10131 int i; 10132 10133 reg_info = ab->reg_info[ar->pdev_idx]; 10134 client_type = reg_info->client_type; 10135 10136 local_psd = &tpe->psd_local[client_type]; 10137 reg_psd = &tpe->psd_reg_client[client_type]; 10138 local_non_psd = &tpe->max_local[client_type]; 10139 reg_non_psd = &tpe->max_reg_client[client_type]; 10140 10141 psd_valid = local_psd->valid | reg_psd->valid; 10142 non_psd_valid = local_non_psd->valid | reg_non_psd->valid; 10143 10144 if (!psd_valid && !non_psd_valid) { 10145 ath12k_warn(ab, 10146 "no transmit power envelope match client power type %d\n", 10147 client_type); 10148 return; 10149 }; 10150 10151 if (psd_valid) { 10152 tpc_info->is_psd_power = true; 10153 10154 tpc_info->num_pwr_levels = max(local_psd->count, 10155 reg_psd->count); 10156 if (tpc_info->num_pwr_levels > ATH12K_NUM_PWR_LEVELS) 10157 tpc_info->num_pwr_levels = ATH12K_NUM_PWR_LEVELS; 10158 10159 for (i = 0; i < tpc_info->num_pwr_levels; i++) { 10160 tpc_info->tpe[i] = min(local_psd->power[i], 10161 reg_psd->power[i]) / 2; 10162 ath12k_dbg(ab, ATH12K_DBG_MAC, 10163 "TPE PSD power[%d] : %d\n", 10164 i, tpc_info->tpe[i]); 10165 } 10166 } else { 10167 tpc_info->is_psd_power = false; 10168 tpc_info->eirp_power = 0; 10169 10170 tpc_info->num_pwr_levels = max(local_non_psd->count, 10171 reg_non_psd->count); 10172 if (tpc_info->num_pwr_levels > ATH12K_NUM_PWR_LEVELS) 10173 tpc_info->num_pwr_levels = ATH12K_NUM_PWR_LEVELS; 10174 10175 for (i = 0; i < tpc_info->num_pwr_levels; i++) { 10176 tpc_info->tpe[i] = min(local_non_psd->power[i], 10177 reg_non_psd->power[i]) / 2; 10178 ath12k_dbg(ab, ATH12K_DBG_MAC, 10179 "non PSD power[%d] : %d\n", 10180 i, tpc_info->tpe[i]); 10181 } 10182 } 10183 } 10184 10185 static int 10186 ath12k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, 10187 struct ieee80211_vif *vif, 10188 struct ieee80211_bss_conf *link_conf, 10189 struct ieee80211_chanctx_conf *ctx) 10190 { 10191 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 10192 struct ath12k *ar; 10193 struct ath12k_base *ab; 10194 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 10195 u8 link_id = link_conf->link_id; 10196 struct ath12k_link_vif *arvif; 10197 int ret; 10198 10199 lockdep_assert_wiphy(hw->wiphy); 10200 10201 /* For multi radio wiphy, the vdev was not created during add_interface 10202 * create now since we have a channel ctx now to assign to a specific ar/fw 10203 */ 10204 arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); 10205 if (!arvif) { 10206 WARN_ON(1); 10207 return -ENOMEM; 10208 } 10209 10210 ar = ath12k_mac_assign_vif_to_vdev(hw, arvif, ctx); 10211 if (!ar) { 10212 ath12k_hw_warn(ah, "failed to assign chanctx for vif %pM link id %u link vif is already started", 10213 vif->addr, link_id); 10214 return -EINVAL; 10215 } 10216 10217 ab = ar->ab; 10218 10219 ath12k_dbg(ab, ATH12K_DBG_MAC, 10220 "mac chanctx assign ptr %p vdev_id %i\n", 10221 ctx, arvif->vdev_id); 10222 10223 if (ath12k_wmi_supports_6ghz_cc_ext(ar) && 10224 ctx->def.chan->band == NL80211_BAND_6GHZ && 10225 ahvif->vdev_type == WMI_VDEV_TYPE_STA) 10226 ath12k_mac_parse_tx_pwr_env(ar, arvif); 10227 10228 arvif->punct_bitmap = ctx->def.punctured; 10229 10230 /* for some targets bss peer must be created before vdev_start */ 10231 if (ab->hw_params->vdev_start_delay && 10232 ahvif->vdev_type != WMI_VDEV_TYPE_AP && 10233 ahvif->vdev_type != WMI_VDEV_TYPE_MONITOR && 10234 !ath12k_peer_exist_by_vdev_id(ab, arvif->vdev_id)) { 10235 ret = 0; 10236 goto out; 10237 } 10238 10239 if (WARN_ON(arvif->is_started)) { 10240 ret = -EBUSY; 10241 goto out; 10242 } 10243 10244 if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { 10245 ret = ath12k_mac_monitor_start(ar); 10246 if (ret) { 10247 ath12k_mac_monitor_vdev_delete(ar); 10248 goto out; 10249 } 10250 10251 arvif->is_started = true; 10252 goto out; 10253 } 10254 10255 ret = ath12k_mac_vdev_start(arvif, ctx); 10256 if (ret) { 10257 ath12k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n", 10258 arvif->vdev_id, vif->addr, 10259 ctx->def.chan->center_freq, ret); 10260 goto out; 10261 } 10262 10263 arvif->is_started = true; 10264 10265 /* TODO: Setup ps and cts/rts protection */ 10266 10267 out: 10268 return ret; 10269 } 10270 10271 static void 10272 ath12k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw, 10273 struct ieee80211_vif *vif, 10274 struct ieee80211_bss_conf *link_conf, 10275 struct ieee80211_chanctx_conf *ctx) 10276 { 10277 struct ath12k *ar; 10278 struct ath12k_base *ab; 10279 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 10280 struct ath12k_link_vif *arvif; 10281 u8 link_id = link_conf->link_id; 10282 int ret; 10283 10284 lockdep_assert_wiphy(hw->wiphy); 10285 10286 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 10287 10288 /* The vif is expected to be attached to an ar's VDEV. 10289 * We leave the vif/vdev in this function as is 10290 * and not delete the vdev symmetric to assign_vif_chanctx() 10291 * the VDEV will be deleted and unassigned either during 10292 * remove_interface() or when there is a change in channel 10293 * that moves the vif to a new ar 10294 */ 10295 if (!arvif || !arvif->is_created) 10296 return; 10297 10298 ar = arvif->ar; 10299 ab = ar->ab; 10300 10301 ath12k_dbg(ab, ATH12K_DBG_MAC, 10302 "mac chanctx unassign ptr %p vdev_id %i\n", 10303 ctx, arvif->vdev_id); 10304 10305 WARN_ON(!arvif->is_started); 10306 10307 if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { 10308 ret = ath12k_mac_monitor_stop(ar); 10309 if (ret) 10310 return; 10311 10312 arvif->is_started = false; 10313 } 10314 10315 if (ahvif->vdev_type != WMI_VDEV_TYPE_STA && 10316 ahvif->vdev_type != WMI_VDEV_TYPE_MONITOR) { 10317 ath12k_bss_disassoc(ar, arvif); 10318 ret = ath12k_mac_vdev_stop(arvif); 10319 if (ret) 10320 ath12k_warn(ab, "failed to stop vdev %i: %d\n", 10321 arvif->vdev_id, ret); 10322 } 10323 arvif->is_started = false; 10324 10325 if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ab->wmi_ab.svc_map) && 10326 ahvif->vdev_type == WMI_VDEV_TYPE_STA && 10327 ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE && 10328 ar->state_11d != ATH12K_11D_PREPARING) { 10329 reinit_completion(&ar->completed_11d_scan); 10330 ar->state_11d = ATH12K_11D_PREPARING; 10331 } 10332 10333 if (ar->scan.arvif == arvif && ar->scan.state == ATH12K_SCAN_RUNNING) { 10334 ath12k_scan_abort(ar); 10335 ar->scan.arvif = NULL; 10336 } 10337 } 10338 10339 static int 10340 ath12k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw, 10341 struct ieee80211_vif_chanctx_switch *vifs, 10342 int n_vifs, 10343 enum ieee80211_chanctx_switch_mode mode) 10344 { 10345 struct ath12k *ar; 10346 10347 lockdep_assert_wiphy(hw->wiphy); 10348 10349 ar = ath12k_get_ar_by_ctx(hw, vifs->old_ctx); 10350 if (!ar) 10351 return -EINVAL; 10352 10353 /* Switching channels across radio is not allowed */ 10354 if (ar != ath12k_get_ar_by_ctx(hw, vifs->new_ctx)) 10355 return -EINVAL; 10356 10357 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 10358 "mac chanctx switch n_vifs %d mode %d\n", 10359 n_vifs, mode); 10360 ath12k_mac_update_vif_chan(ar, vifs, n_vifs); 10361 10362 return 0; 10363 } 10364 10365 static int 10366 ath12k_set_vdev_param_to_all_vifs(struct ath12k *ar, int param, u32 value) 10367 { 10368 struct ath12k_link_vif *arvif; 10369 int ret = 0; 10370 10371 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 10372 10373 list_for_each_entry(arvif, &ar->arvifs, list) { 10374 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "setting mac vdev %d param %d value %d\n", 10375 param, arvif->vdev_id, value); 10376 10377 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 10378 param, value); 10379 if (ret) { 10380 ath12k_warn(ar->ab, "failed to set param %d for vdev %d: %d\n", 10381 param, arvif->vdev_id, ret); 10382 break; 10383 } 10384 } 10385 10386 return ret; 10387 } 10388 10389 /* mac80211 stores device specific RTS/Fragmentation threshold value, 10390 * this is set interface specific to firmware from ath12k driver 10391 */ 10392 static int ath12k_mac_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 10393 { 10394 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 10395 struct ath12k *ar; 10396 int param_id = WMI_VDEV_PARAM_RTS_THRESHOLD, ret = 0, i; 10397 10398 lockdep_assert_wiphy(hw->wiphy); 10399 10400 /* Currently we set the rts threshold value to all the vifs across 10401 * all radios of the single wiphy. 10402 * TODO Once support for vif specific RTS threshold in mac80211 is 10403 * available, ath12k can make use of it. 10404 */ 10405 for_each_ar(ah, ar, i) { 10406 ret = ath12k_set_vdev_param_to_all_vifs(ar, param_id, value); 10407 if (ret) { 10408 ath12k_warn(ar->ab, "failed to set RTS config for all vdevs of pdev %d", 10409 ar->pdev->pdev_id); 10410 break; 10411 } 10412 } 10413 10414 return ret; 10415 } 10416 10417 static int ath12k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) 10418 { 10419 /* Even though there's a WMI vdev param for fragmentation threshold no 10420 * known firmware actually implements it. Moreover it is not possible to 10421 * rely frame fragmentation to mac80211 because firmware clears the 10422 * "more fragments" bit in frame control making it impossible for remote 10423 * devices to reassemble frames. 10424 * 10425 * Hence implement a dummy callback just to say fragmentation isn't 10426 * supported. This effectively prevents mac80211 from doing frame 10427 * fragmentation in software. 10428 */ 10429 10430 lockdep_assert_wiphy(hw->wiphy); 10431 10432 return -EOPNOTSUPP; 10433 } 10434 10435 static int ath12k_mac_flush(struct ath12k *ar) 10436 { 10437 long time_left; 10438 int ret = 0; 10439 10440 time_left = wait_event_timeout(ar->dp.tx_empty_waitq, 10441 (atomic_read(&ar->dp.num_tx_pending) == 0), 10442 ATH12K_FLUSH_TIMEOUT); 10443 if (time_left == 0) { 10444 ath12k_warn(ar->ab, 10445 "failed to flush transmit queue, data pkts pending %d\n", 10446 atomic_read(&ar->dp.num_tx_pending)); 10447 ret = -ETIMEDOUT; 10448 } 10449 10450 time_left = wait_event_timeout(ar->txmgmt_empty_waitq, 10451 (atomic_read(&ar->num_pending_mgmt_tx) == 0), 10452 ATH12K_FLUSH_TIMEOUT); 10453 if (time_left == 0) { 10454 ath12k_warn(ar->ab, 10455 "failed to flush mgmt transmit queue, mgmt pkts pending %d\n", 10456 atomic_read(&ar->num_pending_mgmt_tx)); 10457 ret = -ETIMEDOUT; 10458 } 10459 10460 return ret; 10461 } 10462 10463 int ath12k_mac_wait_tx_complete(struct ath12k *ar) 10464 { 10465 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 10466 10467 ath12k_mac_drain_tx(ar); 10468 return ath12k_mac_flush(ar); 10469 } 10470 10471 static void ath12k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 10472 u32 queues, bool drop) 10473 { 10474 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 10475 struct ath12k_link_vif *arvif; 10476 struct ath12k_vif *ahvif; 10477 unsigned long links; 10478 struct ath12k *ar; 10479 u8 link_id; 10480 int i; 10481 10482 lockdep_assert_wiphy(hw->wiphy); 10483 10484 if (drop) 10485 return; 10486 10487 /* vif can be NULL when flush() is considered for hw */ 10488 if (!vif) { 10489 for_each_ar(ah, ar, i) 10490 ath12k_mac_flush(ar); 10491 return; 10492 } 10493 10494 for_each_ar(ah, ar, i) 10495 wiphy_work_flush(hw->wiphy, &ar->wmi_mgmt_tx_work); 10496 10497 ahvif = ath12k_vif_to_ahvif(vif); 10498 links = ahvif->links_map; 10499 for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { 10500 arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); 10501 if (!(arvif && arvif->ar)) 10502 continue; 10503 10504 ath12k_mac_flush(arvif->ar); 10505 } 10506 } 10507 10508 static int 10509 ath12k_mac_bitrate_mask_num_ht_rates(struct ath12k *ar, 10510 enum nl80211_band band, 10511 const struct cfg80211_bitrate_mask *mask) 10512 { 10513 int num_rates = 0; 10514 int i; 10515 10516 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) 10517 num_rates += hweight16(mask->control[band].ht_mcs[i]); 10518 10519 return num_rates; 10520 } 10521 10522 static bool 10523 ath12k_mac_has_single_legacy_rate(struct ath12k *ar, 10524 enum nl80211_band band, 10525 const struct cfg80211_bitrate_mask *mask) 10526 { 10527 int num_rates = 0; 10528 10529 num_rates = hweight32(mask->control[band].legacy); 10530 10531 if (ath12k_mac_bitrate_mask_num_ht_rates(ar, band, mask)) 10532 return false; 10533 10534 if (ath12k_mac_bitrate_mask_num_vht_rates(ar, band, mask)) 10535 return false; 10536 10537 return num_rates == 1; 10538 } 10539 10540 static bool 10541 ath12k_mac_bitrate_mask_get_single_nss(struct ath12k *ar, 10542 enum nl80211_band band, 10543 const struct cfg80211_bitrate_mask *mask, 10544 int *nss) 10545 { 10546 struct ieee80211_supported_band *sband = &ar->mac.sbands[band]; 10547 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 10548 u8 ht_nss_mask = 0; 10549 u8 vht_nss_mask = 0; 10550 int i; 10551 10552 /* No need to consider legacy here. Basic rates are always present 10553 * in bitrate mask 10554 */ 10555 10556 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) { 10557 if (mask->control[band].ht_mcs[i] == 0) 10558 continue; 10559 else if (mask->control[band].ht_mcs[i] == 10560 sband->ht_cap.mcs.rx_mask[i]) 10561 ht_nss_mask |= BIT(i); 10562 else 10563 return false; 10564 } 10565 10566 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { 10567 if (mask->control[band].vht_mcs[i] == 0) 10568 continue; 10569 else if (mask->control[band].vht_mcs[i] == 10570 ath12k_mac_get_max_vht_mcs_map(vht_mcs_map, i)) 10571 vht_nss_mask |= BIT(i); 10572 else 10573 return false; 10574 } 10575 10576 if (ht_nss_mask != vht_nss_mask) 10577 return false; 10578 10579 if (ht_nss_mask == 0) 10580 return false; 10581 10582 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask) 10583 return false; 10584 10585 *nss = fls(ht_nss_mask); 10586 10587 return true; 10588 } 10589 10590 static int 10591 ath12k_mac_get_single_legacy_rate(struct ath12k *ar, 10592 enum nl80211_band band, 10593 const struct cfg80211_bitrate_mask *mask, 10594 u32 *rate, u8 *nss) 10595 { 10596 int rate_idx; 10597 u16 bitrate; 10598 u8 preamble; 10599 u8 hw_rate; 10600 10601 if (hweight32(mask->control[band].legacy) != 1) 10602 return -EINVAL; 10603 10604 rate_idx = ffs(mask->control[band].legacy) - 1; 10605 10606 if (band == NL80211_BAND_5GHZ || band == NL80211_BAND_6GHZ) 10607 rate_idx += ATH12K_MAC_FIRST_OFDM_RATE_IDX; 10608 10609 hw_rate = ath12k_legacy_rates[rate_idx].hw_value; 10610 bitrate = ath12k_legacy_rates[rate_idx].bitrate; 10611 10612 if (ath12k_mac_bitrate_is_cck(bitrate)) 10613 preamble = WMI_RATE_PREAMBLE_CCK; 10614 else 10615 preamble = WMI_RATE_PREAMBLE_OFDM; 10616 10617 *nss = 1; 10618 *rate = ATH12K_HW_RATE_CODE(hw_rate, 0, preamble); 10619 10620 return 0; 10621 } 10622 10623 static int ath12k_mac_set_fixed_rate_params(struct ath12k_link_vif *arvif, 10624 u32 rate, u8 nss, u8 sgi, u8 ldpc) 10625 { 10626 struct ath12k *ar = arvif->ar; 10627 u32 vdev_param; 10628 int ret; 10629 10630 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 10631 10632 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02x nss %u sgi %u\n", 10633 arvif->vdev_id, rate, nss, sgi); 10634 10635 vdev_param = WMI_VDEV_PARAM_FIXED_RATE; 10636 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 10637 vdev_param, rate); 10638 if (ret) { 10639 ath12k_warn(ar->ab, "failed to set fixed rate param 0x%02x: %d\n", 10640 rate, ret); 10641 return ret; 10642 } 10643 10644 vdev_param = WMI_VDEV_PARAM_NSS; 10645 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 10646 vdev_param, nss); 10647 if (ret) { 10648 ath12k_warn(ar->ab, "failed to set nss param %d: %d\n", 10649 nss, ret); 10650 return ret; 10651 } 10652 10653 vdev_param = WMI_VDEV_PARAM_SGI; 10654 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 10655 vdev_param, sgi); 10656 if (ret) { 10657 ath12k_warn(ar->ab, "failed to set sgi param %d: %d\n", 10658 sgi, ret); 10659 return ret; 10660 } 10661 10662 vdev_param = WMI_VDEV_PARAM_LDPC; 10663 ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, 10664 vdev_param, ldpc); 10665 if (ret) { 10666 ath12k_warn(ar->ab, "failed to set ldpc param %d: %d\n", 10667 ldpc, ret); 10668 return ret; 10669 } 10670 10671 return 0; 10672 } 10673 10674 static bool 10675 ath12k_mac_vht_mcs_range_present(struct ath12k *ar, 10676 enum nl80211_band band, 10677 const struct cfg80211_bitrate_mask *mask) 10678 { 10679 int i; 10680 u16 vht_mcs; 10681 10682 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 10683 vht_mcs = mask->control[band].vht_mcs[i]; 10684 10685 switch (vht_mcs) { 10686 case 0: 10687 case BIT(8) - 1: 10688 case BIT(9) - 1: 10689 case BIT(10) - 1: 10690 break; 10691 default: 10692 return false; 10693 } 10694 } 10695 10696 return true; 10697 } 10698 10699 static void ath12k_mac_set_bitrate_mask_iter(void *data, 10700 struct ieee80211_sta *sta) 10701 { 10702 struct ath12k_link_vif *arvif = data; 10703 struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); 10704 struct ath12k_link_sta *arsta; 10705 struct ath12k *ar = arvif->ar; 10706 10707 arsta = rcu_dereference(ahsta->link[arvif->link_id]); 10708 if (!arsta || arsta->arvif != arvif) 10709 return; 10710 10711 spin_lock_bh(&ar->data_lock); 10712 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED; 10713 spin_unlock_bh(&ar->data_lock); 10714 10715 wiphy_work_queue(ath12k_ar_to_hw(ar)->wiphy, &arsta->update_wk); 10716 } 10717 10718 static void ath12k_mac_disable_peer_fixed_rate(void *data, 10719 struct ieee80211_sta *sta) 10720 { 10721 struct ath12k_link_vif *arvif = data; 10722 struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); 10723 struct ath12k_link_sta *arsta; 10724 struct ath12k *ar = arvif->ar; 10725 int ret; 10726 10727 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 10728 10729 arsta = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, 10730 ahsta->link[arvif->link_id]); 10731 10732 if (!arsta || arsta->arvif != arvif) 10733 return; 10734 10735 ret = ath12k_wmi_set_peer_param(ar, arsta->addr, 10736 arvif->vdev_id, 10737 WMI_PEER_PARAM_FIXED_RATE, 10738 WMI_FIXED_RATE_NONE); 10739 if (ret) 10740 ath12k_warn(ar->ab, 10741 "failed to disable peer fixed rate for STA %pM ret %d\n", 10742 arsta->addr, ret); 10743 } 10744 10745 static int 10746 ath12k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw, 10747 struct ieee80211_vif *vif, 10748 const struct cfg80211_bitrate_mask *mask) 10749 { 10750 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 10751 struct ath12k_link_vif *arvif; 10752 struct cfg80211_chan_def def; 10753 struct ath12k *ar; 10754 enum nl80211_band band; 10755 const u8 *ht_mcs_mask; 10756 const u16 *vht_mcs_mask; 10757 u32 rate; 10758 u8 nss; 10759 u8 sgi; 10760 u8 ldpc; 10761 int single_nss; 10762 int ret; 10763 int num_rates; 10764 10765 lockdep_assert_wiphy(hw->wiphy); 10766 10767 arvif = &ahvif->deflink; 10768 10769 ar = arvif->ar; 10770 if (ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)) { 10771 ret = -EPERM; 10772 goto out; 10773 } 10774 10775 band = def.chan->band; 10776 ht_mcs_mask = mask->control[band].ht_mcs; 10777 vht_mcs_mask = mask->control[band].vht_mcs; 10778 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC); 10779 10780 sgi = mask->control[band].gi; 10781 if (sgi == NL80211_TXRATE_FORCE_LGI) { 10782 ret = -EINVAL; 10783 goto out; 10784 } 10785 10786 /* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it 10787 * requires passing at least one of used basic rates along with them. 10788 * Fixed rate setting across different preambles(legacy, HT, VHT) is 10789 * not supported by the FW. Hence use of FIXED_RATE vdev param is not 10790 * suitable for setting single HT/VHT rates. 10791 * But, there could be a single basic rate passed from userspace which 10792 * can be done through the FIXED_RATE param. 10793 */ 10794 if (ath12k_mac_has_single_legacy_rate(ar, band, mask)) { 10795 ret = ath12k_mac_get_single_legacy_rate(ar, band, mask, &rate, 10796 &nss); 10797 if (ret) { 10798 ath12k_warn(ar->ab, "failed to get single legacy rate for vdev %i: %d\n", 10799 arvif->vdev_id, ret); 10800 goto out; 10801 } 10802 ieee80211_iterate_stations_mtx(hw, 10803 ath12k_mac_disable_peer_fixed_rate, 10804 arvif); 10805 } else if (ath12k_mac_bitrate_mask_get_single_nss(ar, band, mask, 10806 &single_nss)) { 10807 rate = WMI_FIXED_RATE_NONE; 10808 nss = single_nss; 10809 } else { 10810 rate = WMI_FIXED_RATE_NONE; 10811 nss = min_t(u32, ar->num_tx_chains, 10812 max(ath12k_mac_max_ht_nss(ht_mcs_mask), 10813 ath12k_mac_max_vht_nss(vht_mcs_mask))); 10814 10815 /* If multiple rates across different preambles are given 10816 * we can reconfigure this info with all peers using PEER_ASSOC 10817 * command with the below exception cases. 10818 * - Single VHT Rate : peer_assoc command accommodates only MCS 10819 * range values i.e 0-7, 0-8, 0-9 for VHT. Though mac80211 10820 * mandates passing basic rates along with HT/VHT rates, FW 10821 * doesn't allow switching from VHT to Legacy. Hence instead of 10822 * setting legacy and VHT rates using RATEMASK_CMD vdev cmd, 10823 * we could set this VHT rate as peer fixed rate param, which 10824 * will override FIXED rate and FW rate control algorithm. 10825 * If single VHT rate is passed along with HT rates, we select 10826 * the VHT rate as fixed rate for vht peers. 10827 * - Multiple VHT Rates : When Multiple VHT rates are given,this 10828 * can be set using RATEMASK CMD which uses FW rate-ctl alg. 10829 * TODO: Setting multiple VHT MCS and replacing peer_assoc with 10830 * RATEMASK_CMDID can cover all use cases of setting rates 10831 * across multiple preambles and rates within same type. 10832 * But requires more validation of the command at this point. 10833 */ 10834 10835 num_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, 10836 mask); 10837 10838 if (!ath12k_mac_vht_mcs_range_present(ar, band, mask) && 10839 num_rates > 1) { 10840 /* TODO: Handle multiple VHT MCS values setting using 10841 * RATEMASK CMD 10842 */ 10843 ath12k_warn(ar->ab, 10844 "Setting more than one MCS Value in bitrate mask not supported\n"); 10845 return -EINVAL; 10846 } 10847 10848 ieee80211_iterate_stations_mtx(hw, 10849 ath12k_mac_disable_peer_fixed_rate, 10850 arvif); 10851 10852 arvif->bitrate_mask = *mask; 10853 ieee80211_iterate_stations_mtx(hw, 10854 ath12k_mac_set_bitrate_mask_iter, 10855 arvif); 10856 } 10857 10858 ret = ath12k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc); 10859 if (ret) { 10860 ath12k_warn(ar->ab, "failed to set fixed rate params on vdev %i: %d\n", 10861 arvif->vdev_id, ret); 10862 } 10863 10864 out: 10865 return ret; 10866 } 10867 10868 static void 10869 ath12k_mac_op_reconfig_complete(struct ieee80211_hw *hw, 10870 enum ieee80211_reconfig_type reconfig_type) 10871 { 10872 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 10873 struct ath12k *ar; 10874 struct ath12k_base *ab; 10875 struct ath12k_vif *ahvif; 10876 struct ath12k_link_vif *arvif; 10877 int recovery_count, i; 10878 10879 lockdep_assert_wiphy(hw->wiphy); 10880 10881 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART) 10882 return; 10883 10884 guard(mutex)(&ah->hw_mutex); 10885 10886 if (ah->state != ATH12K_HW_STATE_RESTARTED) 10887 return; 10888 10889 ah->state = ATH12K_HW_STATE_ON; 10890 ieee80211_wake_queues(hw); 10891 10892 for_each_ar(ah, ar, i) { 10893 ab = ar->ab; 10894 10895 ath12k_warn(ar->ab, "pdev %d successfully recovered\n", 10896 ar->pdev->pdev_id); 10897 10898 if (ar->ab->hw_params->current_cc_support && 10899 ar->alpha2[0] != 0 && ar->alpha2[1] != 0) { 10900 struct wmi_set_current_country_arg arg = {}; 10901 10902 memcpy(&arg.alpha2, ar->alpha2, 2); 10903 ath12k_wmi_send_set_current_country_cmd(ar, &arg); 10904 } 10905 10906 if (ab->is_reset) { 10907 recovery_count = atomic_inc_return(&ab->recovery_count); 10908 10909 ath12k_dbg(ab, ATH12K_DBG_BOOT, "recovery count %d\n", 10910 recovery_count); 10911 10912 /* When there are multiple radios in an SOC, 10913 * the recovery has to be done for each radio 10914 */ 10915 if (recovery_count == ab->num_radios) { 10916 atomic_dec(&ab->reset_count); 10917 complete(&ab->reset_complete); 10918 ab->is_reset = false; 10919 atomic_set(&ab->fail_cont_count, 0); 10920 ath12k_dbg(ab, ATH12K_DBG_BOOT, "reset success\n"); 10921 } 10922 } 10923 10924 list_for_each_entry(arvif, &ar->arvifs, list) { 10925 ahvif = arvif->ahvif; 10926 ath12k_dbg(ab, ATH12K_DBG_BOOT, 10927 "reconfig cipher %d up %d vdev type %d\n", 10928 ahvif->key_cipher, 10929 arvif->is_up, 10930 ahvif->vdev_type); 10931 10932 /* After trigger disconnect, then upper layer will 10933 * trigger connect again, then the PN number of 10934 * upper layer will be reset to keep up with AP 10935 * side, hence PN number mismatch will not happen. 10936 */ 10937 if (arvif->is_up && 10938 ahvif->vdev_type == WMI_VDEV_TYPE_STA && 10939 ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) { 10940 ieee80211_hw_restart_disconnect(ahvif->vif); 10941 10942 ath12k_dbg(ab, ATH12K_DBG_BOOT, 10943 "restart disconnect\n"); 10944 } 10945 } 10946 } 10947 } 10948 10949 static void 10950 ath12k_mac_update_bss_chan_survey(struct ath12k *ar, 10951 struct ieee80211_channel *channel) 10952 { 10953 int ret; 10954 enum wmi_bss_chan_info_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ; 10955 10956 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 10957 10958 if (!test_bit(WMI_TLV_SERVICE_BSS_CHANNEL_INFO_64, ar->ab->wmi_ab.svc_map) || 10959 ar->rx_channel != channel) 10960 return; 10961 10962 if (ar->scan.state != ATH12K_SCAN_IDLE) { 10963 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 10964 "ignoring bss chan info req while scanning..\n"); 10965 return; 10966 } 10967 10968 reinit_completion(&ar->bss_survey_done); 10969 10970 ret = ath12k_wmi_pdev_bss_chan_info_request(ar, type); 10971 if (ret) { 10972 ath12k_warn(ar->ab, "failed to send pdev bss chan info request\n"); 10973 return; 10974 } 10975 10976 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ); 10977 if (ret == 0) 10978 ath12k_warn(ar->ab, "bss channel survey timed out\n"); 10979 } 10980 10981 static int ath12k_mac_op_get_survey(struct ieee80211_hw *hw, int idx, 10982 struct survey_info *survey) 10983 { 10984 struct ath12k *ar; 10985 struct ieee80211_supported_band *sband; 10986 struct survey_info *ar_survey; 10987 10988 lockdep_assert_wiphy(hw->wiphy); 10989 10990 if (idx >= ATH12K_NUM_CHANS) 10991 return -ENOENT; 10992 10993 sband = hw->wiphy->bands[NL80211_BAND_2GHZ]; 10994 if (sband && idx >= sband->n_channels) { 10995 idx -= sband->n_channels; 10996 sband = NULL; 10997 } 10998 10999 if (!sband) 11000 sband = hw->wiphy->bands[NL80211_BAND_5GHZ]; 11001 if (sband && idx >= sband->n_channels) { 11002 idx -= sband->n_channels; 11003 sband = NULL; 11004 } 11005 11006 if (!sband) 11007 sband = hw->wiphy->bands[NL80211_BAND_6GHZ]; 11008 11009 if (!sband || idx >= sband->n_channels) 11010 return -ENOENT; 11011 11012 ar = ath12k_mac_get_ar_by_chan(hw, &sband->channels[idx]); 11013 if (!ar) { 11014 if (sband->channels[idx].flags & IEEE80211_CHAN_DISABLED) { 11015 memset(survey, 0, sizeof(*survey)); 11016 return 0; 11017 } 11018 return -ENOENT; 11019 } 11020 11021 ar_survey = &ar->survey[idx]; 11022 11023 ath12k_mac_update_bss_chan_survey(ar, &sband->channels[idx]); 11024 11025 spin_lock_bh(&ar->data_lock); 11026 memcpy(survey, ar_survey, sizeof(*survey)); 11027 spin_unlock_bh(&ar->data_lock); 11028 11029 survey->channel = &sband->channels[idx]; 11030 11031 if (ar->rx_channel == survey->channel) 11032 survey->filled |= SURVEY_INFO_IN_USE; 11033 11034 return 0; 11035 } 11036 11037 static void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw, 11038 struct ieee80211_vif *vif, 11039 struct ieee80211_sta *sta, 11040 struct station_info *sinfo) 11041 { 11042 struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); 11043 struct ath12k_fw_stats_req_params params = {}; 11044 struct ath12k_link_sta *arsta; 11045 struct ath12k *ar; 11046 s8 signal; 11047 bool db2dbm; 11048 11049 lockdep_assert_wiphy(hw->wiphy); 11050 11051 arsta = &ahsta->deflink; 11052 ar = ath12k_get_ar_by_vif(hw, vif, arsta->link_id); 11053 if (!ar) 11054 return; 11055 11056 db2dbm = test_bit(WMI_TLV_SERVICE_HW_DB2DBM_CONVERSION_SUPPORT, 11057 ar->ab->wmi_ab.svc_map); 11058 11059 sinfo->rx_duration = arsta->rx_duration; 11060 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION); 11061 11062 sinfo->tx_duration = arsta->tx_duration; 11063 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION); 11064 11065 if (arsta->txrate.legacy || arsta->txrate.nss) { 11066 if (arsta->txrate.legacy) { 11067 sinfo->txrate.legacy = arsta->txrate.legacy; 11068 } else { 11069 sinfo->txrate.mcs = arsta->txrate.mcs; 11070 sinfo->txrate.nss = arsta->txrate.nss; 11071 sinfo->txrate.bw = arsta->txrate.bw; 11072 sinfo->txrate.he_gi = arsta->txrate.he_gi; 11073 sinfo->txrate.he_dcm = arsta->txrate.he_dcm; 11074 sinfo->txrate.he_ru_alloc = arsta->txrate.he_ru_alloc; 11075 sinfo->txrate.eht_gi = arsta->txrate.eht_gi; 11076 sinfo->txrate.eht_ru_alloc = arsta->txrate.eht_ru_alloc; 11077 } 11078 sinfo->txrate.flags = arsta->txrate.flags; 11079 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); 11080 } 11081 11082 /* TODO: Use real NF instead of default one. */ 11083 signal = arsta->rssi_comb; 11084 11085 params.pdev_id = ar->pdev->pdev_id; 11086 params.vdev_id = 0; 11087 params.stats_id = WMI_REQUEST_VDEV_STAT; 11088 11089 if (!signal && 11090 ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA && 11091 !(ath12k_mac_get_fw_stats(ar, ¶ms))) 11092 signal = arsta->rssi_beacon; 11093 11094 if (signal) { 11095 sinfo->signal = db2dbm ? signal : signal + ATH12K_DEFAULT_NOISE_FLOOR; 11096 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL); 11097 } 11098 11099 sinfo->signal_avg = ewma_avg_rssi_read(&arsta->avg_rssi); 11100 11101 if (!db2dbm) 11102 sinfo->signal_avg += ATH12K_DEFAULT_NOISE_FLOOR; 11103 11104 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); 11105 } 11106 11107 static int ath12k_mac_op_cancel_remain_on_channel(struct ieee80211_hw *hw, 11108 struct ieee80211_vif *vif) 11109 { 11110 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 11111 struct ath12k *ar; 11112 11113 ar = ath12k_ah_to_ar(ah, 0); 11114 11115 lockdep_assert_wiphy(hw->wiphy); 11116 11117 spin_lock_bh(&ar->data_lock); 11118 ar->scan.roc_notify = false; 11119 spin_unlock_bh(&ar->data_lock); 11120 11121 ath12k_scan_abort(ar); 11122 11123 cancel_delayed_work_sync(&ar->scan.timeout); 11124 wiphy_work_cancel(hw->wiphy, &ar->scan.vdev_clean_wk); 11125 11126 return 0; 11127 } 11128 11129 static int ath12k_mac_op_remain_on_channel(struct ieee80211_hw *hw, 11130 struct ieee80211_vif *vif, 11131 struct ieee80211_channel *chan, 11132 int duration, 11133 enum ieee80211_roc_type type) 11134 { 11135 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 11136 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 11137 struct ath12k_link_vif *arvif; 11138 struct ath12k *ar; 11139 u32 scan_time_msec; 11140 bool create = true; 11141 u8 link_id; 11142 int ret; 11143 11144 lockdep_assert_wiphy(hw->wiphy); 11145 11146 ar = ath12k_mac_select_scan_device(hw, vif, chan->center_freq); 11147 if (!ar) 11148 return -EINVAL; 11149 11150 /* check if any of the links of ML VIF is already started on 11151 * radio(ar) corresponding to given scan frequency and use it, 11152 * if not use deflink(link 0) for scan purpose. 11153 */ 11154 11155 link_id = ath12k_mac_find_link_id_by_ar(ahvif, ar); 11156 arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); 11157 /* If the vif is already assigned to a specific vdev of an ar, 11158 * check whether its already started, vdev which is started 11159 * are not allowed to switch to a new radio. 11160 * If the vdev is not started, but was earlier created on a 11161 * different ar, delete that vdev and create a new one. We don't 11162 * delete at the scan stop as an optimization to avoid redundant 11163 * delete-create vdev's for the same ar, in case the request is 11164 * always on the same band for the vif 11165 */ 11166 if (arvif->is_created) { 11167 if (WARN_ON(!arvif->ar)) 11168 return -EINVAL; 11169 11170 if (ar != arvif->ar && arvif->is_started) 11171 return -EBUSY; 11172 11173 if (ar != arvif->ar) { 11174 ath12k_mac_remove_link_interface(hw, arvif); 11175 ath12k_mac_unassign_link_vif(arvif); 11176 } else { 11177 create = false; 11178 } 11179 } 11180 11181 if (create) { 11182 arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); 11183 11184 ret = ath12k_mac_vdev_create(ar, arvif); 11185 if (ret) { 11186 ath12k_warn(ar->ab, "unable to create scan vdev for roc: %d\n", 11187 ret); 11188 return ret; 11189 } 11190 } 11191 11192 spin_lock_bh(&ar->data_lock); 11193 11194 switch (ar->scan.state) { 11195 case ATH12K_SCAN_IDLE: 11196 reinit_completion(&ar->scan.started); 11197 reinit_completion(&ar->scan.completed); 11198 reinit_completion(&ar->scan.on_channel); 11199 ar->scan.state = ATH12K_SCAN_STARTING; 11200 ar->scan.is_roc = true; 11201 ar->scan.arvif = arvif; 11202 ar->scan.roc_freq = chan->center_freq; 11203 ar->scan.roc_notify = true; 11204 ret = 0; 11205 break; 11206 case ATH12K_SCAN_STARTING: 11207 case ATH12K_SCAN_RUNNING: 11208 case ATH12K_SCAN_ABORTING: 11209 ret = -EBUSY; 11210 break; 11211 } 11212 11213 spin_unlock_bh(&ar->data_lock); 11214 11215 if (ret) 11216 return ret; 11217 11218 scan_time_msec = hw->wiphy->max_remain_on_channel_duration * 2; 11219 11220 struct ath12k_wmi_scan_req_arg *arg __free(kfree) = 11221 kzalloc(sizeof(*arg), GFP_KERNEL); 11222 if (!arg) 11223 return -ENOMEM; 11224 11225 ath12k_wmi_start_scan_init(ar, arg); 11226 arg->num_chan = 1; 11227 11228 u32 *chan_list __free(kfree) = kcalloc(arg->num_chan, sizeof(*chan_list), 11229 GFP_KERNEL); 11230 if (!chan_list) 11231 return -ENOMEM; 11232 11233 arg->chan_list = chan_list; 11234 arg->vdev_id = arvif->vdev_id; 11235 arg->scan_id = ATH12K_SCAN_ID; 11236 arg->chan_list[0] = chan->center_freq; 11237 arg->dwell_time_active = scan_time_msec; 11238 arg->dwell_time_passive = scan_time_msec; 11239 arg->max_scan_time = scan_time_msec; 11240 arg->scan_f_passive = 1; 11241 arg->burst_duration = duration; 11242 11243 ret = ath12k_start_scan(ar, arg); 11244 if (ret) { 11245 ath12k_warn(ar->ab, "failed to start roc scan: %d\n", ret); 11246 11247 spin_lock_bh(&ar->data_lock); 11248 ar->scan.state = ATH12K_SCAN_IDLE; 11249 spin_unlock_bh(&ar->data_lock); 11250 return ret; 11251 } 11252 11253 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ); 11254 if (ret == 0) { 11255 ath12k_warn(ar->ab, "failed to switch to channel for roc scan\n"); 11256 ret = ath12k_scan_stop(ar); 11257 if (ret) 11258 ath12k_warn(ar->ab, "failed to stop scan: %d\n", ret); 11259 return -ETIMEDOUT; 11260 } 11261 11262 ieee80211_queue_delayed_work(hw, &ar->scan.timeout, 11263 msecs_to_jiffies(duration)); 11264 11265 return 0; 11266 } 11267 11268 static void ath12k_mac_op_set_rekey_data(struct ieee80211_hw *hw, 11269 struct ieee80211_vif *vif, 11270 struct cfg80211_gtk_rekey_data *data) 11271 { 11272 struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); 11273 struct ath12k_rekey_data *rekey_data; 11274 struct ath12k_hw *ah = ath12k_hw_to_ah(hw); 11275 struct ath12k *ar = ath12k_ah_to_ar(ah, 0); 11276 struct ath12k_link_vif *arvif; 11277 11278 lockdep_assert_wiphy(hw->wiphy); 11279 11280 arvif = &ahvif->deflink; 11281 rekey_data = &arvif->rekey_data; 11282 11283 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac set rekey data vdev %d\n", 11284 arvif->vdev_id); 11285 11286 memcpy(rekey_data->kck, data->kck, NL80211_KCK_LEN); 11287 memcpy(rekey_data->kek, data->kek, NL80211_KEK_LEN); 11288 11289 /* The supplicant works on big-endian, the firmware expects it on 11290 * little endian. 11291 */ 11292 rekey_data->replay_ctr = get_unaligned_be64(data->replay_ctr); 11293 11294 arvif->rekey_data.enable_offload = true; 11295 11296 ath12k_dbg_dump(ar->ab, ATH12K_DBG_MAC, "kck", NULL, 11297 rekey_data->kck, NL80211_KCK_LEN); 11298 ath12k_dbg_dump(ar->ab, ATH12K_DBG_MAC, "kek", NULL, 11299 rekey_data->kck, NL80211_KEK_LEN); 11300 ath12k_dbg_dump(ar->ab, ATH12K_DBG_MAC, "replay ctr", NULL, 11301 &rekey_data->replay_ctr, sizeof(rekey_data->replay_ctr)); 11302 } 11303 11304 static const struct ieee80211_ops ath12k_ops = { 11305 .tx = ath12k_mac_op_tx, 11306 .wake_tx_queue = ieee80211_handle_wake_tx_queue, 11307 .start = ath12k_mac_op_start, 11308 .stop = ath12k_mac_op_stop, 11309 .reconfig_complete = ath12k_mac_op_reconfig_complete, 11310 .add_interface = ath12k_mac_op_add_interface, 11311 .remove_interface = ath12k_mac_op_remove_interface, 11312 .update_vif_offload = ath12k_mac_op_update_vif_offload, 11313 .config = ath12k_mac_op_config, 11314 .link_info_changed = ath12k_mac_op_link_info_changed, 11315 .vif_cfg_changed = ath12k_mac_op_vif_cfg_changed, 11316 .change_vif_links = ath12k_mac_op_change_vif_links, 11317 .configure_filter = ath12k_mac_op_configure_filter, 11318 .hw_scan = ath12k_mac_op_hw_scan, 11319 .cancel_hw_scan = ath12k_mac_op_cancel_hw_scan, 11320 .set_key = ath12k_mac_op_set_key, 11321 .set_rekey_data = ath12k_mac_op_set_rekey_data, 11322 .sta_state = ath12k_mac_op_sta_state, 11323 .sta_set_txpwr = ath12k_mac_op_sta_set_txpwr, 11324 .link_sta_rc_update = ath12k_mac_op_link_sta_rc_update, 11325 .conf_tx = ath12k_mac_op_conf_tx, 11326 .set_antenna = ath12k_mac_op_set_antenna, 11327 .get_antenna = ath12k_mac_op_get_antenna, 11328 .ampdu_action = ath12k_mac_op_ampdu_action, 11329 .add_chanctx = ath12k_mac_op_add_chanctx, 11330 .remove_chanctx = ath12k_mac_op_remove_chanctx, 11331 .change_chanctx = ath12k_mac_op_change_chanctx, 11332 .assign_vif_chanctx = ath12k_mac_op_assign_vif_chanctx, 11333 .unassign_vif_chanctx = ath12k_mac_op_unassign_vif_chanctx, 11334 .switch_vif_chanctx = ath12k_mac_op_switch_vif_chanctx, 11335 .get_txpower = ath12k_mac_op_get_txpower, 11336 .set_rts_threshold = ath12k_mac_op_set_rts_threshold, 11337 .set_frag_threshold = ath12k_mac_op_set_frag_threshold, 11338 .set_bitrate_mask = ath12k_mac_op_set_bitrate_mask, 11339 .get_survey = ath12k_mac_op_get_survey, 11340 .flush = ath12k_mac_op_flush, 11341 .sta_statistics = ath12k_mac_op_sta_statistics, 11342 .remain_on_channel = ath12k_mac_op_remain_on_channel, 11343 .cancel_remain_on_channel = ath12k_mac_op_cancel_remain_on_channel, 11344 .change_sta_links = ath12k_mac_op_change_sta_links, 11345 .can_activate_links = ath12k_mac_op_can_activate_links, 11346 #ifdef CONFIG_PM 11347 .suspend = ath12k_wow_op_suspend, 11348 .resume = ath12k_wow_op_resume, 11349 .set_wakeup = ath12k_wow_op_set_wakeup, 11350 #endif 11351 #ifdef CONFIG_ATH12K_DEBUGFS 11352 .vif_add_debugfs = ath12k_debugfs_op_vif_add, 11353 #endif 11354 CFG80211_TESTMODE_CMD(ath12k_tm_cmd) 11355 #ifdef CONFIG_ATH12K_DEBUGFS 11356 .link_sta_add_debugfs = ath12k_debugfs_link_sta_op_add, 11357 #endif 11358 }; 11359 11360 void ath12k_mac_update_freq_range(struct ath12k *ar, 11361 u32 freq_low, u32 freq_high) 11362 { 11363 if (!(freq_low && freq_high)) 11364 return; 11365 11366 if (ar->freq_range.start_freq || ar->freq_range.end_freq) { 11367 ar->freq_range.start_freq = min(ar->freq_range.start_freq, 11368 MHZ_TO_KHZ(freq_low)); 11369 ar->freq_range.end_freq = max(ar->freq_range.end_freq, 11370 MHZ_TO_KHZ(freq_high)); 11371 } else { 11372 ar->freq_range.start_freq = MHZ_TO_KHZ(freq_low); 11373 ar->freq_range.end_freq = MHZ_TO_KHZ(freq_high); 11374 } 11375 11376 ath12k_dbg(ar->ab, ATH12K_DBG_MAC, 11377 "mac pdev %u freq limit updated. New range %u->%u MHz\n", 11378 ar->pdev->pdev_id, KHZ_TO_MHZ(ar->freq_range.start_freq), 11379 KHZ_TO_MHZ(ar->freq_range.end_freq)); 11380 } 11381 11382 static void ath12k_mac_update_ch_list(struct ath12k *ar, 11383 struct ieee80211_supported_band *band, 11384 u32 freq_low, u32 freq_high) 11385 { 11386 int i; 11387 11388 if (!(freq_low && freq_high)) 11389 return; 11390 11391 for (i = 0; i < band->n_channels; i++) { 11392 if (band->channels[i].center_freq < freq_low || 11393 band->channels[i].center_freq > freq_high) 11394 band->channels[i].flags |= IEEE80211_CHAN_DISABLED; 11395 } 11396 } 11397 11398 static u32 ath12k_get_phy_id(struct ath12k *ar, u32 band) 11399 { 11400 struct ath12k_pdev *pdev = ar->pdev; 11401 struct ath12k_pdev_cap *pdev_cap = &pdev->cap; 11402 11403 if (band == WMI_HOST_WLAN_2GHZ_CAP) 11404 return pdev_cap->band[NL80211_BAND_2GHZ].phy_id; 11405 11406 if (band == WMI_HOST_WLAN_5GHZ_CAP) 11407 return pdev_cap->band[NL80211_BAND_5GHZ].phy_id; 11408 11409 ath12k_warn(ar->ab, "unsupported phy cap:%d\n", band); 11410 11411 return 0; 11412 } 11413 11414 static int ath12k_mac_setup_channels_rates(struct ath12k *ar, 11415 u32 supported_bands, 11416 struct ieee80211_supported_band *bands[]) 11417 { 11418 struct ieee80211_supported_band *band; 11419 struct ath12k_wmi_hal_reg_capabilities_ext_arg *reg_cap; 11420 struct ath12k_base *ab = ar->ab; 11421 u32 phy_id, freq_low, freq_high; 11422 struct ath12k_hw *ah = ar->ah; 11423 void *channels; 11424 11425 BUILD_BUG_ON((ARRAY_SIZE(ath12k_2ghz_channels) + 11426 ARRAY_SIZE(ath12k_5ghz_channels) + 11427 ARRAY_SIZE(ath12k_6ghz_channels)) != 11428 ATH12K_NUM_CHANS); 11429 11430 reg_cap = &ab->hal_reg_cap[ar->pdev_idx]; 11431 11432 if (supported_bands & WMI_HOST_WLAN_2GHZ_CAP) { 11433 channels = kmemdup(ath12k_2ghz_channels, 11434 sizeof(ath12k_2ghz_channels), 11435 GFP_KERNEL); 11436 if (!channels) 11437 return -ENOMEM; 11438 11439 band = &ar->mac.sbands[NL80211_BAND_2GHZ]; 11440 band->band = NL80211_BAND_2GHZ; 11441 band->n_channels = ARRAY_SIZE(ath12k_2ghz_channels); 11442 band->channels = channels; 11443 band->n_bitrates = ath12k_g_rates_size; 11444 band->bitrates = ath12k_g_rates; 11445 bands[NL80211_BAND_2GHZ] = band; 11446 11447 if (ab->hw_params->single_pdev_only) { 11448 phy_id = ath12k_get_phy_id(ar, WMI_HOST_WLAN_2GHZ_CAP); 11449 reg_cap = &ab->hal_reg_cap[phy_id]; 11450 } 11451 11452 freq_low = max(reg_cap->low_2ghz_chan, 11453 ab->reg_freq_2ghz.start_freq); 11454 freq_high = min(reg_cap->high_2ghz_chan, 11455 ab->reg_freq_2ghz.end_freq); 11456 11457 ath12k_mac_update_ch_list(ar, band, 11458 reg_cap->low_2ghz_chan, 11459 reg_cap->high_2ghz_chan); 11460 11461 ath12k_mac_update_freq_range(ar, freq_low, freq_high); 11462 } 11463 11464 if (supported_bands & WMI_HOST_WLAN_5GHZ_CAP) { 11465 if (reg_cap->high_5ghz_chan >= ATH12K_MIN_6GHZ_FREQ) { 11466 channels = kmemdup(ath12k_6ghz_channels, 11467 sizeof(ath12k_6ghz_channels), GFP_KERNEL); 11468 if (!channels) { 11469 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); 11470 return -ENOMEM; 11471 } 11472 11473 ar->supports_6ghz = true; 11474 band = &ar->mac.sbands[NL80211_BAND_6GHZ]; 11475 band->band = NL80211_BAND_6GHZ; 11476 band->n_channels = ARRAY_SIZE(ath12k_6ghz_channels); 11477 band->channels = channels; 11478 band->n_bitrates = ath12k_a_rates_size; 11479 band->bitrates = ath12k_a_rates; 11480 bands[NL80211_BAND_6GHZ] = band; 11481 11482 freq_low = max(reg_cap->low_5ghz_chan, 11483 ab->reg_freq_6ghz.start_freq); 11484 freq_high = min(reg_cap->high_5ghz_chan, 11485 ab->reg_freq_6ghz.end_freq); 11486 11487 ath12k_mac_update_ch_list(ar, band, 11488 reg_cap->low_5ghz_chan, 11489 reg_cap->high_5ghz_chan); 11490 11491 ath12k_mac_update_freq_range(ar, freq_low, freq_high); 11492 ah->use_6ghz_regd = true; 11493 } 11494 11495 if (reg_cap->low_5ghz_chan < ATH12K_MIN_6GHZ_FREQ) { 11496 channels = kmemdup(ath12k_5ghz_channels, 11497 sizeof(ath12k_5ghz_channels), 11498 GFP_KERNEL); 11499 if (!channels) { 11500 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); 11501 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); 11502 return -ENOMEM; 11503 } 11504 11505 band = &ar->mac.sbands[NL80211_BAND_5GHZ]; 11506 band->band = NL80211_BAND_5GHZ; 11507 band->n_channels = ARRAY_SIZE(ath12k_5ghz_channels); 11508 band->channels = channels; 11509 band->n_bitrates = ath12k_a_rates_size; 11510 band->bitrates = ath12k_a_rates; 11511 bands[NL80211_BAND_5GHZ] = band; 11512 11513 if (ab->hw_params->single_pdev_only) { 11514 phy_id = ath12k_get_phy_id(ar, WMI_HOST_WLAN_5GHZ_CAP); 11515 reg_cap = &ab->hal_reg_cap[phy_id]; 11516 } 11517 11518 freq_low = max(reg_cap->low_5ghz_chan, 11519 ab->reg_freq_5ghz.start_freq); 11520 freq_high = min(reg_cap->high_5ghz_chan, 11521 ab->reg_freq_5ghz.end_freq); 11522 11523 ath12k_mac_update_ch_list(ar, band, 11524 reg_cap->low_5ghz_chan, 11525 reg_cap->high_5ghz_chan); 11526 11527 ath12k_mac_update_freq_range(ar, freq_low, freq_high); 11528 } 11529 } 11530 11531 return 0; 11532 } 11533 11534 static u16 ath12k_mac_get_ifmodes(struct ath12k_hw *ah) 11535 { 11536 struct ath12k *ar; 11537 int i; 11538 u16 interface_modes = U16_MAX; 11539 11540 for_each_ar(ah, ar, i) 11541 interface_modes &= ar->ab->hw_params->interface_modes; 11542 11543 return interface_modes == U16_MAX ? 0 : interface_modes; 11544 } 11545 11546 static bool ath12k_mac_is_iface_mode_enable(struct ath12k_hw *ah, 11547 enum nl80211_iftype type) 11548 { 11549 struct ath12k *ar; 11550 int i; 11551 u16 interface_modes, mode = 0; 11552 bool is_enable = false; 11553 11554 if (type == NL80211_IFTYPE_MESH_POINT) { 11555 if (IS_ENABLED(CONFIG_MAC80211_MESH)) 11556 mode = BIT(type); 11557 } else { 11558 mode = BIT(type); 11559 } 11560 11561 for_each_ar(ah, ar, i) { 11562 interface_modes = ar->ab->hw_params->interface_modes; 11563 if (interface_modes & mode) { 11564 is_enable = true; 11565 break; 11566 } 11567 } 11568 11569 return is_enable; 11570 } 11571 11572 static int 11573 ath12k_mac_setup_radio_iface_comb(struct ath12k *ar, 11574 struct ieee80211_iface_combination *comb) 11575 { 11576 u16 interface_modes = ar->ab->hw_params->interface_modes; 11577 struct ieee80211_iface_limit *limits; 11578 int n_limits, max_interfaces; 11579 bool ap, mesh, p2p; 11580 11581 ap = interface_modes & BIT(NL80211_IFTYPE_AP); 11582 p2p = interface_modes & BIT(NL80211_IFTYPE_P2P_DEVICE); 11583 11584 mesh = IS_ENABLED(CONFIG_MAC80211_MESH) && 11585 (interface_modes & BIT(NL80211_IFTYPE_MESH_POINT)); 11586 11587 if ((ap || mesh) && !p2p) { 11588 n_limits = 2; 11589 max_interfaces = 16; 11590 } else if (p2p) { 11591 n_limits = 3; 11592 if (ap || mesh) 11593 max_interfaces = 16; 11594 else 11595 max_interfaces = 3; 11596 } else { 11597 n_limits = 1; 11598 max_interfaces = 1; 11599 } 11600 11601 limits = kcalloc(n_limits, sizeof(*limits), GFP_KERNEL); 11602 if (!limits) 11603 return -ENOMEM; 11604 11605 limits[0].max = 1; 11606 limits[0].types |= BIT(NL80211_IFTYPE_STATION); 11607 11608 if (ap || mesh || p2p) 11609 limits[1].max = max_interfaces; 11610 11611 if (ap) 11612 limits[1].types |= BIT(NL80211_IFTYPE_AP); 11613 11614 if (mesh) 11615 limits[1].types |= BIT(NL80211_IFTYPE_MESH_POINT); 11616 11617 if (p2p) { 11618 limits[1].types |= BIT(NL80211_IFTYPE_P2P_CLIENT) | 11619 BIT(NL80211_IFTYPE_P2P_GO); 11620 limits[2].max = 1; 11621 limits[2].types |= BIT(NL80211_IFTYPE_P2P_DEVICE); 11622 } 11623 11624 comb[0].limits = limits; 11625 comb[0].n_limits = n_limits; 11626 comb[0].max_interfaces = max_interfaces; 11627 comb[0].beacon_int_infra_match = true; 11628 comb[0].beacon_int_min_gcd = 100; 11629 11630 if (ar->ab->hw_params->single_pdev_only) { 11631 comb[0].num_different_channels = 2; 11632 } else { 11633 comb[0].num_different_channels = 1; 11634 comb[0].radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 11635 BIT(NL80211_CHAN_WIDTH_20) | 11636 BIT(NL80211_CHAN_WIDTH_40) | 11637 BIT(NL80211_CHAN_WIDTH_80); 11638 } 11639 11640 return 0; 11641 } 11642 11643 static int 11644 ath12k_mac_setup_global_iface_comb(struct ath12k_hw *ah, 11645 struct wiphy_radio *radio, 11646 u8 n_radio, 11647 struct ieee80211_iface_combination *comb) 11648 { 11649 const struct ieee80211_iface_combination *iter_comb; 11650 struct ieee80211_iface_limit *limits; 11651 int i, j, n_limits; 11652 bool ap, mesh, p2p; 11653 11654 if (!n_radio) 11655 return 0; 11656 11657 ap = ath12k_mac_is_iface_mode_enable(ah, NL80211_IFTYPE_AP); 11658 p2p = ath12k_mac_is_iface_mode_enable(ah, NL80211_IFTYPE_P2P_DEVICE); 11659 mesh = ath12k_mac_is_iface_mode_enable(ah, NL80211_IFTYPE_MESH_POINT); 11660 11661 if ((ap || mesh) && !p2p) 11662 n_limits = 2; 11663 else if (p2p) 11664 n_limits = 3; 11665 else 11666 n_limits = 1; 11667 11668 limits = kcalloc(n_limits, sizeof(*limits), GFP_KERNEL); 11669 if (!limits) 11670 return -ENOMEM; 11671 11672 for (i = 0; i < n_radio; i++) { 11673 iter_comb = radio[i].iface_combinations; 11674 for (j = 0; j < iter_comb->n_limits && j < n_limits; j++) { 11675 limits[j].types |= iter_comb->limits[j].types; 11676 limits[j].max += iter_comb->limits[j].max; 11677 } 11678 11679 comb->max_interfaces += iter_comb->max_interfaces; 11680 comb->num_different_channels += iter_comb->num_different_channels; 11681 comb->radar_detect_widths |= iter_comb->radar_detect_widths; 11682 } 11683 11684 comb->limits = limits; 11685 comb->n_limits = n_limits; 11686 comb->beacon_int_infra_match = true; 11687 comb->beacon_int_min_gcd = 100; 11688 11689 return 0; 11690 } 11691 11692 static 11693 void ath12k_mac_cleanup_iface_comb(const struct ieee80211_iface_combination *iface_comb) 11694 { 11695 kfree(iface_comb[0].limits); 11696 kfree(iface_comb); 11697 } 11698 11699 static void ath12k_mac_cleanup_iface_combinations(struct ath12k_hw *ah) 11700 { 11701 struct wiphy *wiphy = ah->hw->wiphy; 11702 const struct wiphy_radio *radio; 11703 int i; 11704 11705 if (wiphy->n_radio > 0) { 11706 radio = wiphy->radio; 11707 for (i = 0; i < wiphy->n_radio; i++) 11708 ath12k_mac_cleanup_iface_comb(radio[i].iface_combinations); 11709 11710 kfree(wiphy->radio); 11711 } 11712 11713 ath12k_mac_cleanup_iface_comb(wiphy->iface_combinations); 11714 } 11715 11716 static int ath12k_mac_setup_iface_combinations(struct ath12k_hw *ah) 11717 { 11718 struct ieee80211_iface_combination *combinations, *comb; 11719 struct wiphy *wiphy = ah->hw->wiphy; 11720 struct wiphy_radio *radio; 11721 struct ath12k *ar; 11722 int i, ret; 11723 11724 combinations = kzalloc(sizeof(*combinations), GFP_KERNEL); 11725 if (!combinations) 11726 return -ENOMEM; 11727 11728 if (ah->num_radio == 1) { 11729 ret = ath12k_mac_setup_radio_iface_comb(&ah->radio[0], 11730 combinations); 11731 if (ret) { 11732 ath12k_hw_warn(ah, "failed to setup radio interface combinations for one radio: %d", 11733 ret); 11734 goto err_free_combinations; 11735 } 11736 11737 goto out; 11738 } 11739 11740 /* there are multiple radios */ 11741 11742 radio = kcalloc(ah->num_radio, sizeof(*radio), GFP_KERNEL); 11743 if (!radio) { 11744 ret = -ENOMEM; 11745 goto err_free_combinations; 11746 } 11747 11748 for_each_ar(ah, ar, i) { 11749 comb = kzalloc(sizeof(*comb), GFP_KERNEL); 11750 if (!comb) { 11751 ret = -ENOMEM; 11752 goto err_free_radios; 11753 } 11754 11755 ret = ath12k_mac_setup_radio_iface_comb(ar, comb); 11756 if (ret) { 11757 ath12k_hw_warn(ah, "failed to setup radio interface combinations for radio %d: %d", 11758 i, ret); 11759 kfree(comb); 11760 goto err_free_radios; 11761 } 11762 11763 radio[i].freq_range = &ar->freq_range; 11764 radio[i].n_freq_range = 1; 11765 11766 radio[i].iface_combinations = comb; 11767 radio[i].n_iface_combinations = 1; 11768 } 11769 11770 ret = ath12k_mac_setup_global_iface_comb(ah, radio, ah->num_radio, combinations); 11771 if (ret) { 11772 ath12k_hw_warn(ah, "failed to setup global interface combinations: %d", 11773 ret); 11774 goto err_free_all_radios; 11775 } 11776 11777 wiphy->radio = radio; 11778 wiphy->n_radio = ah->num_radio; 11779 11780 out: 11781 wiphy->iface_combinations = combinations; 11782 wiphy->n_iface_combinations = 1; 11783 11784 return 0; 11785 11786 err_free_all_radios: 11787 i = ah->num_radio; 11788 11789 err_free_radios: 11790 while (i--) 11791 ath12k_mac_cleanup_iface_comb(radio[i].iface_combinations); 11792 11793 kfree(radio); 11794 11795 err_free_combinations: 11796 kfree(combinations); 11797 11798 return ret; 11799 } 11800 11801 static const u8 ath12k_if_types_ext_capa[] = { 11802 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, 11803 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, 11804 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, 11805 }; 11806 11807 static const u8 ath12k_if_types_ext_capa_sta[] = { 11808 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, 11809 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, 11810 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, 11811 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT, 11812 }; 11813 11814 static const u8 ath12k_if_types_ext_capa_ap[] = { 11815 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, 11816 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, 11817 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, 11818 [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT, 11819 [10] = WLAN_EXT_CAPA11_EMA_SUPPORT, 11820 }; 11821 11822 static struct wiphy_iftype_ext_capab ath12k_iftypes_ext_capa[] = { 11823 { 11824 .extended_capabilities = ath12k_if_types_ext_capa, 11825 .extended_capabilities_mask = ath12k_if_types_ext_capa, 11826 .extended_capabilities_len = sizeof(ath12k_if_types_ext_capa), 11827 }, { 11828 .iftype = NL80211_IFTYPE_STATION, 11829 .extended_capabilities = ath12k_if_types_ext_capa_sta, 11830 .extended_capabilities_mask = ath12k_if_types_ext_capa_sta, 11831 .extended_capabilities_len = 11832 sizeof(ath12k_if_types_ext_capa_sta), 11833 }, { 11834 .iftype = NL80211_IFTYPE_AP, 11835 .extended_capabilities = ath12k_if_types_ext_capa_ap, 11836 .extended_capabilities_mask = ath12k_if_types_ext_capa_ap, 11837 .extended_capabilities_len = 11838 sizeof(ath12k_if_types_ext_capa_ap), 11839 .eml_capabilities = 0, 11840 .mld_capa_and_ops = 0, 11841 }, 11842 }; 11843 11844 static void ath12k_mac_cleanup_unregister(struct ath12k *ar) 11845 { 11846 idr_for_each(&ar->txmgmt_idr, ath12k_mac_tx_mgmt_pending_free, ar); 11847 idr_destroy(&ar->txmgmt_idr); 11848 11849 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); 11850 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); 11851 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); 11852 } 11853 11854 static void ath12k_mac_hw_unregister(struct ath12k_hw *ah) 11855 { 11856 struct ieee80211_hw *hw = ah->hw; 11857 struct ath12k *ar; 11858 int i; 11859 11860 for_each_ar(ah, ar, i) { 11861 cancel_work_sync(&ar->regd_update_work); 11862 ath12k_debugfs_unregister(ar); 11863 ath12k_fw_stats_reset(ar); 11864 } 11865 11866 ieee80211_unregister_hw(hw); 11867 11868 for_each_ar(ah, ar, i) 11869 ath12k_mac_cleanup_unregister(ar); 11870 11871 ath12k_mac_cleanup_iface_combinations(ah); 11872 11873 SET_IEEE80211_DEV(hw, NULL); 11874 } 11875 11876 static int ath12k_mac_setup_register(struct ath12k *ar, 11877 u32 *ht_cap, 11878 struct ieee80211_supported_band *bands[]) 11879 { 11880 struct ath12k_pdev_cap *cap = &ar->pdev->cap; 11881 int ret; 11882 11883 init_waitqueue_head(&ar->txmgmt_empty_waitq); 11884 idr_init(&ar->txmgmt_idr); 11885 spin_lock_init(&ar->txmgmt_idr_lock); 11886 11887 ath12k_pdev_caps_update(ar); 11888 11889 ret = ath12k_mac_setup_channels_rates(ar, 11890 cap->supported_bands, 11891 bands); 11892 if (ret) 11893 return ret; 11894 11895 ath12k_mac_setup_ht_vht_cap(ar, cap, ht_cap); 11896 ath12k_mac_setup_sband_iftype_data(ar, cap); 11897 11898 ar->max_num_stations = ath12k_core_get_max_station_per_radio(ar->ab); 11899 ar->max_num_peers = ath12k_core_get_max_peers_per_radio(ar->ab); 11900 11901 return 0; 11902 } 11903 11904 static int ath12k_mac_hw_register(struct ath12k_hw *ah) 11905 { 11906 struct ieee80211_hw *hw = ah->hw; 11907 struct wiphy *wiphy = hw->wiphy; 11908 struct ath12k *ar = ath12k_ah_to_ar(ah, 0); 11909 struct ath12k_base *ab = ar->ab; 11910 struct ath12k_pdev *pdev; 11911 struct ath12k_pdev_cap *cap; 11912 static const u32 cipher_suites[] = { 11913 WLAN_CIPHER_SUITE_TKIP, 11914 WLAN_CIPHER_SUITE_CCMP, 11915 WLAN_CIPHER_SUITE_AES_CMAC, 11916 WLAN_CIPHER_SUITE_BIP_CMAC_256, 11917 WLAN_CIPHER_SUITE_BIP_GMAC_128, 11918 WLAN_CIPHER_SUITE_BIP_GMAC_256, 11919 WLAN_CIPHER_SUITE_GCMP, 11920 WLAN_CIPHER_SUITE_GCMP_256, 11921 WLAN_CIPHER_SUITE_CCMP_256, 11922 }; 11923 int ret, i, j; 11924 u32 ht_cap = U32_MAX, antennas_rx = 0, antennas_tx = 0; 11925 bool is_6ghz = false, is_raw_mode = false, is_monitor_disable = false; 11926 u8 *mac_addr = NULL; 11927 u8 mbssid_max_interfaces = 0; 11928 11929 wiphy->max_ap_assoc_sta = 0; 11930 11931 for_each_ar(ah, ar, i) { 11932 u32 ht_cap_info = 0; 11933 11934 pdev = ar->pdev; 11935 if (ar->ab->pdevs_macaddr_valid) { 11936 ether_addr_copy(ar->mac_addr, pdev->mac_addr); 11937 } else { 11938 ether_addr_copy(ar->mac_addr, ar->ab->mac_addr); 11939 ar->mac_addr[4] += ar->pdev_idx; 11940 } 11941 11942 ret = ath12k_mac_setup_register(ar, &ht_cap_info, hw->wiphy->bands); 11943 if (ret) 11944 goto err_cleanup_unregister; 11945 11946 /* 6 GHz does not support HT Cap, hence do not consider it */ 11947 if (!ar->supports_6ghz) 11948 ht_cap &= ht_cap_info; 11949 11950 wiphy->max_ap_assoc_sta += ar->max_num_stations; 11951 11952 /* Advertise the max antenna support of all radios, driver can handle 11953 * per pdev specific antenna setting based on pdev cap when antenna 11954 * changes are made 11955 */ 11956 cap = &pdev->cap; 11957 11958 antennas_rx = max_t(u32, antennas_rx, cap->rx_chain_mask); 11959 antennas_tx = max_t(u32, antennas_tx, cap->tx_chain_mask); 11960 11961 if (ar->supports_6ghz) 11962 is_6ghz = true; 11963 11964 if (test_bit(ATH12K_FLAG_RAW_MODE, &ar->ab->dev_flags)) 11965 is_raw_mode = true; 11966 11967 if (!ar->ab->hw_params->supports_monitor) 11968 is_monitor_disable = true; 11969 11970 if (i == 0) 11971 mac_addr = ar->mac_addr; 11972 else 11973 mac_addr = ab->mac_addr; 11974 11975 mbssid_max_interfaces += TARGET_NUM_VDEVS; 11976 } 11977 11978 wiphy->available_antennas_rx = antennas_rx; 11979 wiphy->available_antennas_tx = antennas_tx; 11980 11981 SET_IEEE80211_PERM_ADDR(hw, mac_addr); 11982 SET_IEEE80211_DEV(hw, ab->dev); 11983 11984 ret = ath12k_mac_setup_iface_combinations(ah); 11985 if (ret) { 11986 ath12k_err(ab, "failed to setup interface combinations: %d\n", ret); 11987 goto err_complete_cleanup_unregister; 11988 } 11989 11990 wiphy->interface_modes = ath12k_mac_get_ifmodes(ah); 11991 11992 if (ah->num_radio == 1 && 11993 wiphy->bands[NL80211_BAND_2GHZ] && 11994 wiphy->bands[NL80211_BAND_5GHZ] && 11995 wiphy->bands[NL80211_BAND_6GHZ]) 11996 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); 11997 11998 ieee80211_hw_set(hw, SIGNAL_DBM); 11999 ieee80211_hw_set(hw, SUPPORTS_PS); 12000 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 12001 ieee80211_hw_set(hw, MFP_CAPABLE); 12002 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); 12003 ieee80211_hw_set(hw, HAS_RATE_CONTROL); 12004 ieee80211_hw_set(hw, AP_LINK_PS); 12005 ieee80211_hw_set(hw, SPECTRUM_MGMT); 12006 ieee80211_hw_set(hw, CONNECTION_MONITOR); 12007 ieee80211_hw_set(hw, SUPPORTS_PER_STA_GTK); 12008 ieee80211_hw_set(hw, CHANCTX_STA_CSA); 12009 ieee80211_hw_set(hw, QUEUE_CONTROL); 12010 ieee80211_hw_set(hw, SUPPORTS_TX_FRAG); 12011 ieee80211_hw_set(hw, REPORTS_LOW_ACK); 12012 ieee80211_hw_set(hw, NO_VIRTUAL_MONITOR); 12013 12014 if ((ht_cap & WMI_HT_CAP_ENABLED) || is_6ghz) { 12015 ieee80211_hw_set(hw, AMPDU_AGGREGATION); 12016 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW); 12017 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); 12018 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); 12019 ieee80211_hw_set(hw, USES_RSS); 12020 } 12021 12022 wiphy->features |= NL80211_FEATURE_STATIC_SMPS; 12023 wiphy->flags |= WIPHY_FLAG_IBSS_RSN; 12024 12025 /* TODO: Check if HT capability advertised from firmware is different 12026 * for each band for a dual band capable radio. It will be tricky to 12027 * handle it when the ht capability different for each band. 12028 */ 12029 if (ht_cap & WMI_HT_CAP_DYNAMIC_SMPS || 12030 (is_6ghz && ab->hw_params->supports_dynamic_smps_6ghz)) 12031 wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS; 12032 12033 wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; 12034 wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; 12035 12036 hw->max_listen_interval = ATH12K_MAX_HW_LISTEN_INTERVAL; 12037 12038 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; 12039 wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; 12040 wiphy->max_remain_on_channel_duration = 5000; 12041 12042 wiphy->flags |= WIPHY_FLAG_AP_UAPSD; 12043 wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | 12044 NL80211_FEATURE_AP_SCAN; 12045 12046 /* MLO is not yet supported so disable Wireless Extensions for now 12047 * to make sure ath12k users don't use it. This flag can be removed 12048 * once WIPHY_FLAG_SUPPORTS_MLO is enabled. 12049 */ 12050 wiphy->flags |= WIPHY_FLAG_DISABLE_WEXT; 12051 12052 /* Copy over MLO related capabilities received from 12053 * WMI_SERVICE_READY_EXT2_EVENT if single_chip_mlo_supp is set. 12054 */ 12055 if (ab->ag->mlo_capable) { 12056 ath12k_iftypes_ext_capa[2].eml_capabilities = cap->eml_cap; 12057 ath12k_iftypes_ext_capa[2].mld_capa_and_ops = cap->mld_cap; 12058 wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO; 12059 12060 ieee80211_hw_set(hw, MLO_MCAST_MULTI_LINK_TX); 12061 } 12062 12063 hw->queues = ATH12K_HW_MAX_QUEUES; 12064 wiphy->tx_queue_len = ATH12K_QUEUE_LEN; 12065 hw->offchannel_tx_hw_queue = ATH12K_HW_MAX_QUEUES - 1; 12066 hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_EHT; 12067 12068 hw->vif_data_size = sizeof(struct ath12k_vif); 12069 hw->sta_data_size = sizeof(struct ath12k_sta); 12070 hw->extra_tx_headroom = ab->hw_params->iova_mask; 12071 12072 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); 12073 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STA_TX_PWR); 12074 12075 wiphy->cipher_suites = cipher_suites; 12076 wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); 12077 12078 wiphy->iftype_ext_capab = ath12k_iftypes_ext_capa; 12079 wiphy->num_iftype_ext_capab = ARRAY_SIZE(ath12k_iftypes_ext_capa); 12080 12081 wiphy->mbssid_max_interfaces = mbssid_max_interfaces; 12082 wiphy->ema_max_profile_periodicity = TARGET_EMA_MAX_PROFILE_PERIOD; 12083 12084 if (is_6ghz) { 12085 wiphy_ext_feature_set(wiphy, 12086 NL80211_EXT_FEATURE_FILS_DISCOVERY); 12087 wiphy_ext_feature_set(wiphy, 12088 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP); 12089 } 12090 12091 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_PUNCT); 12092 12093 ath12k_reg_init(hw); 12094 12095 if (!is_raw_mode) { 12096 hw->netdev_features = NETIF_F_HW_CSUM; 12097 ieee80211_hw_set(hw, SW_CRYPTO_CONTROL); 12098 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); 12099 } 12100 12101 if (test_bit(WMI_TLV_SERVICE_NLO, ar->wmi->wmi_ab->svc_map)) { 12102 wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS; 12103 wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS; 12104 wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH; 12105 wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS; 12106 wiphy->max_sched_scan_plan_interval = 12107 WMI_PNO_MAX_SCHED_SCAN_PLAN_INT; 12108 wiphy->max_sched_scan_plan_iterations = 12109 WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS; 12110 wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 12111 } 12112 12113 ret = ath12k_wow_init(ar); 12114 if (ret) { 12115 ath12k_warn(ar->ab, "failed to init wow: %d\n", ret); 12116 goto err_cleanup_if_combs; 12117 } 12118 12119 ret = ieee80211_register_hw(hw); 12120 if (ret) { 12121 ath12k_err(ab, "ieee80211 registration failed: %d\n", ret); 12122 goto err_cleanup_if_combs; 12123 } 12124 12125 if (is_monitor_disable) 12126 /* There's a race between calling ieee80211_register_hw() 12127 * and here where the monitor mode is enabled for a little 12128 * while. But that time is so short and in practise it make 12129 * a difference in real life. 12130 */ 12131 wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MONITOR); 12132 12133 for_each_ar(ah, ar, i) { 12134 /* Apply the regd received during initialization */ 12135 ret = ath12k_regd_update(ar, true); 12136 if (ret) { 12137 ath12k_err(ar->ab, "ath12k regd update failed: %d\n", ret); 12138 goto err_unregister_hw; 12139 } 12140 12141 if (ar->ab->hw_params->current_cc_support && ab->new_alpha2[0]) { 12142 struct wmi_set_current_country_arg current_cc = {}; 12143 12144 memcpy(¤t_cc.alpha2, ab->new_alpha2, 2); 12145 memcpy(&ar->alpha2, ab->new_alpha2, 2); 12146 ret = ath12k_wmi_send_set_current_country_cmd(ar, ¤t_cc); 12147 if (ret) 12148 ath12k_warn(ar->ab, 12149 "failed set cc code for mac register: %d\n", 12150 ret); 12151 } 12152 12153 ath12k_fw_stats_init(ar); 12154 ath12k_debugfs_register(ar); 12155 } 12156 12157 return 0; 12158 12159 err_unregister_hw: 12160 for_each_ar(ah, ar, i) 12161 ath12k_debugfs_unregister(ar); 12162 12163 ieee80211_unregister_hw(hw); 12164 12165 err_cleanup_if_combs: 12166 ath12k_mac_cleanup_iface_combinations(ah); 12167 12168 err_complete_cleanup_unregister: 12169 i = ah->num_radio; 12170 12171 err_cleanup_unregister: 12172 for (j = 0; j < i; j++) { 12173 ar = ath12k_ah_to_ar(ah, j); 12174 ath12k_mac_cleanup_unregister(ar); 12175 } 12176 12177 SET_IEEE80211_DEV(hw, NULL); 12178 12179 return ret; 12180 } 12181 12182 static void ath12k_mac_setup(struct ath12k *ar) 12183 { 12184 struct ath12k_base *ab = ar->ab; 12185 struct ath12k_pdev *pdev = ar->pdev; 12186 u8 pdev_idx = ar->pdev_idx; 12187 12188 ar->lmac_id = ath12k_hw_get_mac_from_pdev_id(ab->hw_params, pdev_idx); 12189 12190 ar->wmi = &ab->wmi_ab.wmi[pdev_idx]; 12191 /* FIXME: wmi[0] is already initialized during attach, 12192 * Should we do this again? 12193 */ 12194 ath12k_wmi_pdev_attach(ab, pdev_idx); 12195 12196 ar->cfg_tx_chainmask = pdev->cap.tx_chain_mask; 12197 ar->cfg_rx_chainmask = pdev->cap.rx_chain_mask; 12198 ar->num_tx_chains = hweight32(pdev->cap.tx_chain_mask); 12199 ar->num_rx_chains = hweight32(pdev->cap.rx_chain_mask); 12200 ar->scan.arvif = NULL; 12201 ar->vdev_id_11d_scan = ATH12K_11D_INVALID_VDEV_ID; 12202 12203 spin_lock_init(&ar->data_lock); 12204 INIT_LIST_HEAD(&ar->arvifs); 12205 INIT_LIST_HEAD(&ar->ppdu_stats_info); 12206 12207 init_completion(&ar->vdev_setup_done); 12208 init_completion(&ar->vdev_delete_done); 12209 init_completion(&ar->peer_assoc_done); 12210 init_completion(&ar->peer_delete_done); 12211 init_completion(&ar->install_key_done); 12212 init_completion(&ar->bss_survey_done); 12213 init_completion(&ar->scan.started); 12214 init_completion(&ar->scan.completed); 12215 init_completion(&ar->scan.on_channel); 12216 init_completion(&ar->mlo_setup_done); 12217 init_completion(&ar->completed_11d_scan); 12218 12219 INIT_DELAYED_WORK(&ar->scan.timeout, ath12k_scan_timeout_work); 12220 wiphy_work_init(&ar->scan.vdev_clean_wk, ath12k_scan_vdev_clean_work); 12221 INIT_WORK(&ar->regd_update_work, ath12k_regd_update_work); 12222 12223 wiphy_work_init(&ar->wmi_mgmt_tx_work, ath12k_mgmt_over_wmi_tx_work); 12224 skb_queue_head_init(&ar->wmi_mgmt_tx_queue); 12225 12226 ar->monitor_vdev_id = -1; 12227 ar->monitor_vdev_created = false; 12228 ar->monitor_started = false; 12229 } 12230 12231 static int __ath12k_mac_mlo_setup(struct ath12k *ar) 12232 { 12233 u8 num_link = 0, partner_link_id[ATH12K_GROUP_MAX_RADIO] = {}; 12234 struct ath12k_base *partner_ab, *ab = ar->ab; 12235 struct ath12k_hw_group *ag = ab->ag; 12236 struct wmi_mlo_setup_arg mlo = {}; 12237 struct ath12k_pdev *pdev; 12238 unsigned long time_left; 12239 int i, j, ret; 12240 12241 lockdep_assert_held(&ag->mutex); 12242 12243 reinit_completion(&ar->mlo_setup_done); 12244 12245 for (i = 0; i < ag->num_devices; i++) { 12246 partner_ab = ag->ab[i]; 12247 12248 for (j = 0; j < partner_ab->num_radios; j++) { 12249 pdev = &partner_ab->pdevs[j]; 12250 12251 /* Avoid the self link */ 12252 if (ar == pdev->ar) 12253 continue; 12254 12255 partner_link_id[num_link] = pdev->hw_link_id; 12256 num_link++; 12257 12258 ath12k_dbg(ab, ATH12K_DBG_MAC, "device %d pdev %d hw_link_id %d num_link %d\n", 12259 i, j, pdev->hw_link_id, num_link); 12260 } 12261 } 12262 12263 if (num_link == 0) 12264 return 0; 12265 12266 mlo.group_id = cpu_to_le32(ag->id); 12267 mlo.partner_link_id = partner_link_id; 12268 mlo.num_partner_links = num_link; 12269 ar->mlo_setup_status = 0; 12270 12271 ath12k_dbg(ab, ATH12K_DBG_MAC, "group id %d num_link %d\n", ag->id, num_link); 12272 12273 ret = ath12k_wmi_mlo_setup(ar, &mlo); 12274 if (ret) { 12275 ath12k_err(ab, "failed to send setup MLO WMI command for pdev %d: %d\n", 12276 ar->pdev_idx, ret); 12277 return ret; 12278 } 12279 12280 time_left = wait_for_completion_timeout(&ar->mlo_setup_done, 12281 WMI_MLO_CMD_TIMEOUT_HZ); 12282 12283 if (!time_left || ar->mlo_setup_status) 12284 return ar->mlo_setup_status ? : -ETIMEDOUT; 12285 12286 ath12k_dbg(ab, ATH12K_DBG_MAC, "mlo setup done for pdev %d\n", ar->pdev_idx); 12287 12288 return 0; 12289 } 12290 12291 static int __ath12k_mac_mlo_teardown(struct ath12k *ar) 12292 { 12293 struct ath12k_base *ab = ar->ab; 12294 int ret; 12295 u8 num_link; 12296 12297 if (test_bit(ATH12K_FLAG_RECOVERY, &ab->dev_flags)) 12298 return 0; 12299 12300 num_link = ath12k_get_num_partner_link(ar); 12301 12302 if (num_link == 0) 12303 return 0; 12304 12305 ret = ath12k_wmi_mlo_teardown(ar); 12306 if (ret) { 12307 ath12k_warn(ab, "failed to send MLO teardown WMI command for pdev %d: %d\n", 12308 ar->pdev_idx, ret); 12309 return ret; 12310 } 12311 12312 ath12k_dbg(ab, ATH12K_DBG_MAC, "mlo teardown for pdev %d\n", ar->pdev_idx); 12313 12314 return 0; 12315 } 12316 12317 int ath12k_mac_mlo_setup(struct ath12k_hw_group *ag) 12318 { 12319 struct ath12k_hw *ah; 12320 struct ath12k *ar; 12321 int ret; 12322 int i, j; 12323 12324 for (i = 0; i < ag->num_hw; i++) { 12325 ah = ag->ah[i]; 12326 if (!ah) 12327 continue; 12328 12329 for_each_ar(ah, ar, j) { 12330 ar = &ah->radio[j]; 12331 ret = __ath12k_mac_mlo_setup(ar); 12332 if (ret) { 12333 ath12k_err(ar->ab, "failed to setup MLO: %d\n", ret); 12334 goto err_setup; 12335 } 12336 } 12337 } 12338 12339 return 0; 12340 12341 err_setup: 12342 for (i = i - 1; i >= 0; i--) { 12343 ah = ag->ah[i]; 12344 if (!ah) 12345 continue; 12346 12347 for (j = j - 1; j >= 0; j--) { 12348 ar = &ah->radio[j]; 12349 if (!ar) 12350 continue; 12351 12352 __ath12k_mac_mlo_teardown(ar); 12353 } 12354 } 12355 12356 return ret; 12357 } 12358 12359 void ath12k_mac_mlo_teardown(struct ath12k_hw_group *ag) 12360 { 12361 struct ath12k_hw *ah; 12362 struct ath12k *ar; 12363 int ret, i, j; 12364 12365 for (i = 0; i < ag->num_hw; i++) { 12366 ah = ag->ah[i]; 12367 if (!ah) 12368 continue; 12369 12370 for_each_ar(ah, ar, j) { 12371 ar = &ah->radio[j]; 12372 ret = __ath12k_mac_mlo_teardown(ar); 12373 if (ret) { 12374 ath12k_err(ar->ab, "failed to teardown MLO: %d\n", ret); 12375 break; 12376 } 12377 } 12378 } 12379 } 12380 12381 int ath12k_mac_register(struct ath12k_hw_group *ag) 12382 { 12383 struct ath12k_hw *ah; 12384 int i; 12385 int ret; 12386 12387 for (i = 0; i < ag->num_hw; i++) { 12388 ah = ath12k_ag_to_ah(ag, i); 12389 12390 ret = ath12k_mac_hw_register(ah); 12391 if (ret) 12392 goto err; 12393 } 12394 12395 return 0; 12396 12397 err: 12398 for (i = i - 1; i >= 0; i--) { 12399 ah = ath12k_ag_to_ah(ag, i); 12400 if (!ah) 12401 continue; 12402 12403 ath12k_mac_hw_unregister(ah); 12404 } 12405 12406 return ret; 12407 } 12408 12409 void ath12k_mac_unregister(struct ath12k_hw_group *ag) 12410 { 12411 struct ath12k_hw *ah; 12412 int i; 12413 12414 for (i = ag->num_hw - 1; i >= 0; i--) { 12415 ah = ath12k_ag_to_ah(ag, i); 12416 if (!ah) 12417 continue; 12418 12419 ath12k_mac_hw_unregister(ah); 12420 } 12421 } 12422 12423 static void ath12k_mac_hw_destroy(struct ath12k_hw *ah) 12424 { 12425 ieee80211_free_hw(ah->hw); 12426 } 12427 12428 static struct ath12k_hw *ath12k_mac_hw_allocate(struct ath12k_hw_group *ag, 12429 struct ath12k_pdev_map *pdev_map, 12430 u8 num_pdev_map) 12431 { 12432 struct ieee80211_hw *hw; 12433 struct ath12k *ar; 12434 struct ath12k_base *ab; 12435 struct ath12k_pdev *pdev; 12436 struct ath12k_hw *ah; 12437 int i; 12438 u8 pdev_idx; 12439 12440 hw = ieee80211_alloc_hw(struct_size(ah, radio, num_pdev_map), 12441 &ath12k_ops); 12442 if (!hw) 12443 return NULL; 12444 12445 ah = ath12k_hw_to_ah(hw); 12446 ah->hw = hw; 12447 ah->num_radio = num_pdev_map; 12448 12449 mutex_init(&ah->hw_mutex); 12450 INIT_LIST_HEAD(&ah->ml_peers); 12451 12452 for (i = 0; i < num_pdev_map; i++) { 12453 ab = pdev_map[i].ab; 12454 pdev_idx = pdev_map[i].pdev_idx; 12455 pdev = &ab->pdevs[pdev_idx]; 12456 12457 ar = ath12k_ah_to_ar(ah, i); 12458 ar->ah = ah; 12459 ar->ab = ab; 12460 ar->hw_link_id = pdev->hw_link_id; 12461 ar->pdev = pdev; 12462 ar->pdev_idx = pdev_idx; 12463 pdev->ar = ar; 12464 12465 ag->hw_links[ar->hw_link_id].device_id = ab->device_id; 12466 ag->hw_links[ar->hw_link_id].pdev_idx = pdev_idx; 12467 12468 ath12k_mac_setup(ar); 12469 ath12k_dp_pdev_pre_alloc(ar); 12470 } 12471 12472 return ah; 12473 } 12474 12475 void ath12k_mac_destroy(struct ath12k_hw_group *ag) 12476 { 12477 struct ath12k_pdev *pdev; 12478 struct ath12k_base *ab = ag->ab[0]; 12479 int i, j; 12480 struct ath12k_hw *ah; 12481 12482 for (i = 0; i < ag->num_devices; i++) { 12483 ab = ag->ab[i]; 12484 if (!ab) 12485 continue; 12486 12487 for (j = 0; j < ab->num_radios; j++) { 12488 pdev = &ab->pdevs[j]; 12489 if (!pdev->ar) 12490 continue; 12491 pdev->ar = NULL; 12492 } 12493 } 12494 12495 for (i = 0; i < ag->num_hw; i++) { 12496 ah = ath12k_ag_to_ah(ag, i); 12497 if (!ah) 12498 continue; 12499 12500 ath12k_mac_hw_destroy(ah); 12501 ath12k_ag_set_ah(ag, i, NULL); 12502 } 12503 } 12504 12505 static void ath12k_mac_set_device_defaults(struct ath12k_base *ab) 12506 { 12507 /* Initialize channel counters frequency value in hertz */ 12508 ab->cc_freq_hz = 320000; 12509 ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS)) - 1; 12510 } 12511 12512 int ath12k_mac_allocate(struct ath12k_hw_group *ag) 12513 { 12514 struct ath12k_pdev_map pdev_map[ATH12K_GROUP_MAX_RADIO]; 12515 int mac_id, device_id, total_radio, num_hw; 12516 struct ath12k_base *ab; 12517 struct ath12k_hw *ah; 12518 int ret, i, j; 12519 u8 radio_per_hw; 12520 12521 total_radio = 0; 12522 for (i = 0; i < ag->num_devices; i++) { 12523 ab = ag->ab[i]; 12524 if (!ab) 12525 continue; 12526 12527 ath12k_debugfs_pdev_create(ab); 12528 ath12k_mac_set_device_defaults(ab); 12529 total_radio += ab->num_radios; 12530 } 12531 12532 if (!total_radio) 12533 return -EINVAL; 12534 12535 if (WARN_ON(total_radio > ATH12K_GROUP_MAX_RADIO)) 12536 return -ENOSPC; 12537 12538 /* All pdev get combined and register as single wiphy based on 12539 * hardware group which participate in multi-link operation else 12540 * each pdev get register separately. 12541 */ 12542 if (ag->mlo_capable) 12543 radio_per_hw = total_radio; 12544 else 12545 radio_per_hw = 1; 12546 12547 num_hw = total_radio / radio_per_hw; 12548 12549 ag->num_hw = 0; 12550 device_id = 0; 12551 mac_id = 0; 12552 for (i = 0; i < num_hw; i++) { 12553 for (j = 0; j < radio_per_hw; j++) { 12554 if (device_id >= ag->num_devices || !ag->ab[device_id]) { 12555 ret = -ENOSPC; 12556 goto err; 12557 } 12558 12559 ab = ag->ab[device_id]; 12560 pdev_map[j].ab = ab; 12561 pdev_map[j].pdev_idx = mac_id; 12562 mac_id++; 12563 12564 /* If mac_id falls beyond the current device MACs then 12565 * move to next device 12566 */ 12567 if (mac_id >= ab->num_radios) { 12568 mac_id = 0; 12569 device_id++; 12570 } 12571 } 12572 12573 ab = pdev_map->ab; 12574 12575 ah = ath12k_mac_hw_allocate(ag, pdev_map, radio_per_hw); 12576 if (!ah) { 12577 ath12k_warn(ab, "failed to allocate mac80211 hw device for hw_idx %d\n", 12578 i); 12579 ret = -ENOMEM; 12580 goto err; 12581 } 12582 12583 ah->dev = ab->dev; 12584 12585 ag->ah[i] = ah; 12586 ag->num_hw++; 12587 } 12588 12589 return 0; 12590 12591 err: 12592 for (i = i - 1; i >= 0; i--) { 12593 ah = ath12k_ag_to_ah(ag, i); 12594 if (!ah) 12595 continue; 12596 12597 ath12k_mac_hw_destroy(ah); 12598 ath12k_ag_set_ah(ag, i, NULL); 12599 } 12600 12601 return ret; 12602 } 12603 12604 int ath12k_mac_vif_set_keepalive(struct ath12k_link_vif *arvif, 12605 enum wmi_sta_keepalive_method method, 12606 u32 interval) 12607 { 12608 struct wmi_sta_keepalive_arg arg = {}; 12609 struct ath12k *ar = arvif->ar; 12610 int ret; 12611 12612 lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); 12613 12614 if (arvif->ahvif->vdev_type != WMI_VDEV_TYPE_STA) 12615 return 0; 12616 12617 if (!test_bit(WMI_TLV_SERVICE_STA_KEEP_ALIVE, ar->ab->wmi_ab.svc_map)) 12618 return 0; 12619 12620 arg.vdev_id = arvif->vdev_id; 12621 arg.enabled = 1; 12622 arg.method = method; 12623 arg.interval = interval; 12624 12625 ret = ath12k_wmi_sta_keepalive(ar, &arg); 12626 if (ret) { 12627 ath12k_warn(ar->ab, "failed to set keepalive on vdev %i: %d\n", 12628 arvif->vdev_id, ret); 12629 return ret; 12630 } 12631 12632 return 0; 12633 } 12634