1 // SPDX-License-Identifier: BSD-3-Clause-Clear 2 /* Copyright (C) 2023 MediaTek Inc. */ 3 4 #include <linux/module.h> 5 #include <linux/firmware.h> 6 #include <linux/slab.h> 7 8 #include "mt792x.h" 9 #include "dma.h" 10 11 static const struct ieee80211_iface_limit if_limits[] = { 12 { 13 .max = MT792x_MAX_INTERFACES, 14 .types = BIT(NL80211_IFTYPE_STATION) 15 }, 16 { 17 .max = 1, 18 .types = BIT(NL80211_IFTYPE_AP) 19 } 20 }; 21 22 static const struct ieee80211_iface_combination if_comb[] = { 23 { 24 .limits = if_limits, 25 .n_limits = ARRAY_SIZE(if_limits), 26 .max_interfaces = MT792x_MAX_INTERFACES, 27 .num_different_channels = 1, 28 .beacon_int_infra_match = true, 29 }, 30 }; 31 32 static const struct ieee80211_iface_limit if_limits_chanctx_mcc[] = { 33 { 34 .max = 2, 35 .types = BIT(NL80211_IFTYPE_STATION) | 36 BIT(NL80211_IFTYPE_P2P_CLIENT) 37 }, 38 { 39 .max = 1, 40 .types = BIT(NL80211_IFTYPE_P2P_GO) 41 }, 42 { 43 .max = 1, 44 .types = BIT(NL80211_IFTYPE_P2P_DEVICE) 45 } 46 }; 47 48 static const struct ieee80211_iface_limit if_limits_chanctx_scc[] = { 49 { 50 .max = 2, 51 .types = BIT(NL80211_IFTYPE_STATION) | 52 BIT(NL80211_IFTYPE_P2P_CLIENT) 53 }, 54 { 55 .max = 1, 56 .types = BIT(NL80211_IFTYPE_AP) 57 }, 58 { 59 .max = 1, 60 .types = BIT(NL80211_IFTYPE_P2P_DEVICE) 61 } 62 }; 63 64 static const struct ieee80211_iface_limit if_limits_nan_mcc[] = { 65 { 66 .max = 2, 67 .types = BIT(NL80211_IFTYPE_STATION), 68 }, 69 { 70 .max = 1, 71 .types = BIT(NL80211_IFTYPE_NAN), 72 }, 73 { 74 .max = 2, 75 .types = BIT(NL80211_IFTYPE_NAN_DATA), 76 }, 77 }; 78 79 static const struct ieee80211_iface_limit if_limits_nan_scc[] = { 80 { 81 .max = 2, 82 .types = BIT(NL80211_IFTYPE_STATION), 83 }, 84 { 85 .max = 1, 86 .types = BIT(NL80211_IFTYPE_NAN), 87 }, 88 { 89 .max = 2, 90 .types = BIT(NL80211_IFTYPE_NAN_DATA), 91 }, 92 { 93 .max = 1, 94 .types = BIT(NL80211_IFTYPE_AP), 95 }, 96 }; 97 98 static const struct ieee80211_iface_combination if_comb_chanctx_base[] = { 99 { 100 .limits = if_limits_chanctx_mcc, 101 .n_limits = ARRAY_SIZE(if_limits_chanctx_mcc), 102 .max_interfaces = 3, 103 .num_different_channels = 2, 104 .beacon_int_infra_match = false, 105 }, 106 { 107 .limits = if_limits_chanctx_scc, 108 .n_limits = ARRAY_SIZE(if_limits_chanctx_scc), 109 .max_interfaces = 3, 110 .num_different_channels = 1, 111 .beacon_int_infra_match = false, 112 } 113 }; 114 115 static const struct ieee80211_iface_combination if_comb_chanctx_nan[] = { 116 { 117 .limits = if_limits_nan_mcc, 118 .n_limits = ARRAY_SIZE(if_limits_nan_mcc), 119 .max_interfaces = MT792x_MAX_INTERFACES, 120 .num_different_channels = 2, 121 .beacon_int_infra_match = false, 122 }, 123 { 124 .limits = if_limits_nan_scc, 125 .n_limits = ARRAY_SIZE(if_limits_nan_scc), 126 .max_interfaces = MT792x_MAX_INTERFACES, 127 .num_different_channels = 1, 128 .beacon_int_infra_match = false, 129 }, 130 }; 131 132 static int mt792x_setup_iface_combinations(struct mt792x_dev *dev, 133 struct wiphy *wiphy) 134 { 135 const bool cnm = !!(dev->fw_features & MT792x_FW_CAP_CNM); 136 const bool nan = !!(dev->fw_features & MT792x_FW_CAP_NAN); 137 const int n_base = ARRAY_SIZE(if_comb_chanctx_base); 138 const int n_nan = ARRAY_SIZE(if_comb_chanctx_nan); 139 struct ieee80211_iface_combination *comb; 140 141 if (!cnm) { 142 dev->iface_combinations = if_comb; 143 dev->n_iface_combinations = ARRAY_SIZE(if_comb); 144 return 0; 145 } 146 147 /* CNM enabled, NAN optional */ 148 if (!nan) { 149 dev->iface_combinations = if_comb_chanctx_base; 150 dev->n_iface_combinations = ARRAY_SIZE(if_comb_chanctx_base); 151 return 0; 152 } 153 154 /* CNM + NAN: dynamically build base + nan list */ 155 comb = devm_kcalloc(&wiphy->dev, n_base + n_nan, sizeof(*comb), 156 GFP_KERNEL); 157 if (!comb) 158 return -ENOMEM; 159 160 memcpy(comb, if_comb_chanctx_base, sizeof(if_comb_chanctx_base)); 161 memcpy(comb + n_base, if_comb_chanctx_nan, sizeof(if_comb_chanctx_nan)); 162 163 dev->iface_combinations = comb; 164 dev->n_iface_combinations = n_base + n_nan; 165 166 return 0; 167 } 168 169 void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, 170 struct sk_buff *skb) 171 { 172 struct mt792x_dev *dev = mt792x_hw_dev(hw); 173 struct mt76_phy *mphy = hw->priv; 174 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 175 struct ieee80211_vif *vif = info->control.vif; 176 struct mt76_wcid *wcid = &dev->mt76.global_wcid; 177 u8 link_id; 178 int qid; 179 180 if (control->sta) { 181 struct mt792x_link_sta *mlink; 182 struct mt792x_sta *sta; 183 link_id = u32_get_bits(info->control.flags, 184 IEEE80211_TX_CTRL_MLO_LINK); 185 sta = (struct mt792x_sta *)control->sta->drv_priv; 186 mlink = mt792x_sta_to_link(sta, link_id); 187 wcid = &mlink->wcid; 188 } 189 190 if (vif && !control->sta) { 191 struct mt792x_vif *mvif; 192 193 mvif = (struct mt792x_vif *)vif->drv_priv; 194 wcid = &mvif->sta.deflink.wcid; 195 } 196 197 if (vif && control->sta && ieee80211_vif_is_mld(vif) && 198 !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) { 199 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 200 struct ieee80211_link_sta *link_sta; 201 struct ieee80211_bss_conf *conf; 202 203 link_id = wcid->link_id; 204 rcu_read_lock(); 205 conf = rcu_dereference(vif->link_conf[link_id]); 206 memcpy(hdr->addr2, conf->addr, ETH_ALEN); 207 208 link_sta = rcu_dereference(control->sta->link[link_id]); 209 memcpy(hdr->addr1, link_sta->addr, ETH_ALEN); 210 211 if (vif->type == NL80211_IFTYPE_STATION) 212 memcpy(hdr->addr3, conf->bssid, ETH_ALEN); 213 rcu_read_unlock(); 214 } 215 216 if (mt76_connac_pm_ref(mphy, &dev->pm)) { 217 mt76_tx(mphy, control->sta, wcid, skb); 218 mt76_connac_pm_unref(mphy, &dev->pm); 219 return; 220 } 221 222 qid = skb_get_queue_mapping(skb); 223 if (qid >= MT_TXQ_PSD) { 224 qid = IEEE80211_AC_BE; 225 skb_set_queue_mapping(skb, qid); 226 } 227 228 mt76_connac_pm_queue_skb(hw, &dev->pm, wcid, skb); 229 } 230 EXPORT_SYMBOL_GPL(mt792x_tx); 231 232 void mt792x_stop(struct ieee80211_hw *hw, bool suspend) 233 { 234 struct mt792x_dev *dev = mt792x_hw_dev(hw); 235 struct mt792x_phy *phy = mt792x_hw_phy(hw); 236 237 cancel_delayed_work_sync(&phy->mt76->mac_work); 238 239 cancel_delayed_work_sync(&dev->pm.ps_work); 240 cancel_work_sync(&dev->pm.wake_work); 241 cancel_work_sync(&dev->reset_work); 242 mt76_connac_free_pending_tx_skbs(&dev->pm, NULL); 243 244 if (is_connac2(&dev->mt76)) { 245 mt792x_mutex_acquire(dev); 246 mt76_connac_mcu_set_mac_enable(&dev->mt76, 0, false, false); 247 mt792x_mutex_release(dev); 248 } 249 250 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state); 251 } 252 EXPORT_SYMBOL_GPL(mt792x_stop); 253 254 void mt792x_mac_link_bss_remove(struct mt792x_dev *dev, 255 struct mt792x_bss_conf *mconf, 256 struct mt792x_link_sta *mlink) 257 { 258 struct ieee80211_vif *vif = container_of((void *)mconf->vif, 259 struct ieee80211_vif, drv_priv); 260 struct ieee80211_bss_conf *link_conf; 261 int idx = mlink->wcid.idx; 262 263 link_conf = mt792x_vif_to_bss_conf(vif, mconf->link_id); 264 265 mt76_connac_free_pending_tx_skbs(&dev->pm, &mlink->wcid); 266 mt76_connac_mcu_uni_add_dev(&dev->mphy, link_conf, &mconf->mt76, 267 &mlink->wcid, false); 268 269 rcu_assign_pointer(dev->mt76.wcid[idx], NULL); 270 271 dev->mt76.vif_mask &= ~BIT_ULL(mconf->mt76.idx); 272 mconf->vif->phy->omac_mask &= ~BIT_ULL(mconf->mt76.omac_idx); 273 274 spin_lock_bh(&dev->mt76.sta_poll_lock); 275 if (!list_empty(&mlink->wcid.poll_list)) 276 list_del_init(&mlink->wcid.poll_list); 277 spin_unlock_bh(&dev->mt76.sta_poll_lock); 278 279 mt76_wcid_cleanup(&dev->mt76, &mlink->wcid); 280 } 281 EXPORT_SYMBOL_GPL(mt792x_mac_link_bss_remove); 282 283 void mt792x_remove_interface(struct ieee80211_hw *hw, 284 struct ieee80211_vif *vif) 285 { 286 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 287 struct mt792x_dev *dev = mt792x_hw_dev(hw); 288 struct mt792x_bss_conf *mconf; 289 290 mt792x_mutex_acquire(dev); 291 292 mconf = mt792x_link_conf_to_mconf(&vif->bss_conf); 293 mt792x_mac_link_bss_remove(dev, mconf, &mvif->sta.deflink); 294 295 mt792x_mutex_release(dev); 296 } 297 EXPORT_SYMBOL_GPL(mt792x_remove_interface); 298 299 int mt792x_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 300 unsigned int link_id, u16 queue, 301 const struct ieee80211_tx_queue_params *params) 302 { 303 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 304 305 /* no need to update right away, we'll get BSS_CHANGED_QOS */ 306 queue = mt76_connac_lmac_mapping(queue); 307 mvif->bss_conf.queue_params[queue] = *params; 308 309 return 0; 310 } 311 EXPORT_SYMBOL_GPL(mt792x_conf_tx); 312 313 int mt792x_get_stats(struct ieee80211_hw *hw, 314 struct ieee80211_low_level_stats *stats) 315 { 316 struct mt792x_phy *phy = mt792x_hw_phy(hw); 317 struct mt76_mib_stats *mib = &phy->mib; 318 319 mt792x_mutex_acquire(phy->dev); 320 321 stats->dot11RTSSuccessCount = mib->rts_cnt; 322 stats->dot11RTSFailureCount = mib->rts_retries_cnt; 323 stats->dot11FCSErrorCount = mib->fcs_err_cnt; 324 stats->dot11ACKFailureCount = mib->ack_fail_cnt; 325 326 mt792x_mutex_release(phy->dev); 327 328 return 0; 329 } 330 EXPORT_SYMBOL_GPL(mt792x_get_stats); 331 332 u64 mt792x_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 333 { 334 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 335 struct mt792x_dev *dev = mt792x_hw_dev(hw); 336 u8 omac_idx = mvif->bss_conf.mt76.omac_idx; 337 union { 338 u64 t64; 339 u32 t32[2]; 340 } tsf; 341 u16 n; 342 343 mt792x_mutex_acquire(dev); 344 345 n = omac_idx > HW_BSSID_MAX ? HW_BSSID_0 : omac_idx; 346 /* TSF software read */ 347 mt76_set(dev, MT_LPON_TCR(0, n), MT_LPON_TCR_SW_MODE); 348 tsf.t32[0] = mt76_rr(dev, MT_LPON_UTTR0(0)); 349 tsf.t32[1] = mt76_rr(dev, MT_LPON_UTTR1(0)); 350 351 mt792x_mutex_release(dev); 352 353 return tsf.t64; 354 } 355 EXPORT_SYMBOL_GPL(mt792x_get_tsf); 356 357 void mt792x_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 358 u64 timestamp) 359 { 360 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 361 struct mt792x_dev *dev = mt792x_hw_dev(hw); 362 u8 omac_idx = mvif->bss_conf.mt76.omac_idx; 363 union { 364 u64 t64; 365 u32 t32[2]; 366 } tsf = { .t64 = timestamp, }; 367 u16 n; 368 369 mt792x_mutex_acquire(dev); 370 371 n = omac_idx > HW_BSSID_MAX ? HW_BSSID_0 : omac_idx; 372 mt76_wr(dev, MT_LPON_UTTR0(0), tsf.t32[0]); 373 mt76_wr(dev, MT_LPON_UTTR1(0), tsf.t32[1]); 374 /* TSF software overwrite */ 375 mt76_set(dev, MT_LPON_TCR(0, n), MT_LPON_TCR_SW_WRITE); 376 377 mt792x_mutex_release(dev); 378 } 379 EXPORT_SYMBOL_GPL(mt792x_set_tsf); 380 381 void mt792x_tx_worker(struct mt76_worker *w) 382 { 383 struct mt792x_dev *dev = container_of(w, struct mt792x_dev, 384 mt76.tx_worker); 385 386 if (!mt76_connac_pm_ref(&dev->mphy, &dev->pm)) { 387 queue_work(dev->mt76.wq, &dev->pm.wake_work); 388 return; 389 } 390 391 mt76_txq_schedule_all(&dev->mphy); 392 mt76_connac_pm_unref(&dev->mphy, &dev->pm); 393 } 394 EXPORT_SYMBOL_GPL(mt792x_tx_worker); 395 396 void mt792x_roc_timer(struct timer_list *timer) 397 { 398 struct mt792x_phy *phy = timer_container_of(phy, timer, roc_timer); 399 400 ieee80211_queue_work(phy->mt76->hw, &phy->roc_work); 401 } 402 EXPORT_SYMBOL_GPL(mt792x_roc_timer); 403 404 void mt792x_csa_timer(struct timer_list *timer) 405 { 406 struct mt792x_vif *mvif = timer_container_of(mvif, timer, csa_timer); 407 408 ieee80211_queue_work(mvif->phy->mt76->hw, &mvif->csa_work); 409 } 410 EXPORT_SYMBOL_GPL(mt792x_csa_timer); 411 412 void mt792x_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 413 u32 queues, bool drop) 414 { 415 struct mt792x_dev *dev = mt792x_hw_dev(hw); 416 417 wait_event_timeout(dev->mt76.tx_wait, 418 !mt76_has_tx_pending(&dev->mphy), HZ / 2); 419 } 420 EXPORT_SYMBOL_GPL(mt792x_flush); 421 422 int mt792x_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 423 unsigned int link_id, int *dbm) 424 { 425 struct mt76_power_limits limits = {}; 426 struct ieee80211_bss_conf *link_conf; 427 struct ieee80211_channel *chan; 428 struct mt792x_bss_conf *mconf; 429 struct mt792x_vif *mvif; 430 struct mt76_phy *phy; 431 s8 max_power; 432 433 if (!vif) 434 return mt76_get_txpower(hw, vif, link_id, dbm); 435 436 mvif = (struct mt792x_vif *)vif->drv_priv; 437 phy = mvif->phy->mt76; 438 439 mt792x_mutex_acquire(mvif->phy->dev); 440 441 link_conf = mt792x_vif_to_bss_conf(vif, link_id); 442 mconf = link_conf ? mt792x_link_conf_to_mconf(link_conf) : NULL; 443 if (mconf && mconf->mt76.ctx && mconf->mt76.ctx->def.chan) 444 chan = mconf->mt76.ctx->def.chan; 445 else 446 /* Fall back to the current PHY chandef if the requested link 447 * does not have a valid channel context. 448 */ 449 chan = phy->chandef.chan; 450 451 mt792x_mutex_release(mvif->phy->dev); 452 453 if (!chan) 454 return -EINVAL; 455 456 max_power = mt76_connac_get_rate_power_limit(phy, chan, &limits); 457 *dbm = DIV_ROUND_UP(max_power, 2); 458 459 return 0; 460 } 461 EXPORT_SYMBOL_GPL(mt792x_get_txpower); 462 463 int mt792x_assign_vif_chanctx(struct ieee80211_hw *hw, 464 struct ieee80211_vif *vif, 465 struct ieee80211_bss_conf *link_conf, 466 struct ieee80211_chanctx_conf *ctx) 467 { 468 struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv; 469 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 470 struct mt792x_dev *dev = mt792x_hw_dev(hw); 471 472 mutex_lock(&dev->mt76.mutex); 473 mvif->bss_conf.mt76.ctx = ctx; 474 mctx->bss_conf = &mvif->bss_conf; 475 mt76_phy_chandef_set(&dev->mphy, &ctx->def); 476 mutex_unlock(&dev->mt76.mutex); 477 478 return 0; 479 } 480 EXPORT_SYMBOL_GPL(mt792x_assign_vif_chanctx); 481 482 void mt792x_unassign_vif_chanctx(struct ieee80211_hw *hw, 483 struct ieee80211_vif *vif, 484 struct ieee80211_bss_conf *link_conf, 485 struct ieee80211_chanctx_conf *ctx) 486 { 487 struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv; 488 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 489 struct mt792x_dev *dev = mt792x_hw_dev(hw); 490 491 mutex_lock(&dev->mt76.mutex); 492 mctx->bss_conf = NULL; 493 mvif->bss_conf.mt76.ctx = NULL; 494 mutex_unlock(&dev->mt76.mutex); 495 496 if (vif->bss_conf.csa_active) { 497 timer_delete_sync(&mvif->csa_timer); 498 cancel_work_sync(&mvif->csa_work); 499 } 500 } 501 EXPORT_SYMBOL_GPL(mt792x_unassign_vif_chanctx); 502 503 void mt792x_set_wakeup(struct ieee80211_hw *hw, bool enabled) 504 { 505 struct mt792x_dev *dev = mt792x_hw_dev(hw); 506 struct mt76_dev *mdev = &dev->mt76; 507 508 device_set_wakeup_enable(mdev->dev, enabled); 509 } 510 EXPORT_SYMBOL_GPL(mt792x_set_wakeup); 511 512 static const char mt792x_gstrings_stats[][ETH_GSTRING_LEN] = { 513 /* tx counters */ 514 "tx_ampdu_cnt", 515 "tx_mpdu_attempts", 516 "tx_mpdu_success", 517 "tx_pkt_ebf_cnt", 518 "tx_pkt_ibf_cnt", 519 "tx_ampdu_len:0-1", 520 "tx_ampdu_len:2-10", 521 "tx_ampdu_len:11-19", 522 "tx_ampdu_len:20-28", 523 "tx_ampdu_len:29-37", 524 "tx_ampdu_len:38-46", 525 "tx_ampdu_len:47-55", 526 "tx_ampdu_len:56-79", 527 "tx_ampdu_len:80-103", 528 "tx_ampdu_len:104-127", 529 "tx_ampdu_len:128-151", 530 "tx_ampdu_len:152-175", 531 "tx_ampdu_len:176-199", 532 "tx_ampdu_len:200-223", 533 "tx_ampdu_len:224-247", 534 "ba_miss_count", 535 "tx_beamformer_ppdu_iBF", 536 "tx_beamformer_ppdu_eBF", 537 "tx_beamformer_rx_feedback_all", 538 "tx_beamformer_rx_feedback_he", 539 "tx_beamformer_rx_feedback_vht", 540 "tx_beamformer_rx_feedback_ht", 541 "tx_msdu_pack_1", 542 "tx_msdu_pack_2", 543 "tx_msdu_pack_3", 544 "tx_msdu_pack_4", 545 "tx_msdu_pack_5", 546 "tx_msdu_pack_6", 547 "tx_msdu_pack_7", 548 "tx_msdu_pack_8", 549 /* rx counters */ 550 "rx_mpdu_cnt", 551 "rx_ampdu_cnt", 552 "rx_ampdu_bytes_cnt", 553 "rx_ba_cnt", 554 /* per vif counters */ 555 "v_tx_mode_cck", 556 "v_tx_mode_ofdm", 557 "v_tx_mode_ht", 558 "v_tx_mode_ht_gf", 559 "v_tx_mode_vht", 560 "v_tx_mode_he_su", 561 "v_tx_mode_he_ext_su", 562 "v_tx_mode_he_tb", 563 "v_tx_mode_he_mu", 564 "v_tx_mode_eht_su", 565 "v_tx_mode_eht_trig", 566 "v_tx_mode_eht_mu", 567 "v_tx_bw_20", 568 "v_tx_bw_40", 569 "v_tx_bw_80", 570 "v_tx_bw_160", 571 "v_tx_bw_320", 572 "v_tx_mcs_0", 573 "v_tx_mcs_1", 574 "v_tx_mcs_2", 575 "v_tx_mcs_3", 576 "v_tx_mcs_4", 577 "v_tx_mcs_5", 578 "v_tx_mcs_6", 579 "v_tx_mcs_7", 580 "v_tx_mcs_8", 581 "v_tx_mcs_9", 582 "v_tx_mcs_10", 583 "v_tx_mcs_11", 584 "v_tx_mcs_12", 585 "v_tx_mcs_13", 586 "v_tx_nss_1", 587 "v_tx_nss_2", 588 "v_tx_nss_3", 589 "v_tx_nss_4", 590 }; 591 592 void mt792x_get_et_strings(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 593 u32 sset, u8 *data) 594 { 595 if (sset != ETH_SS_STATS) 596 return; 597 598 memcpy(data, mt792x_gstrings_stats, sizeof(mt792x_gstrings_stats)); 599 600 data += sizeof(mt792x_gstrings_stats); 601 page_pool_ethtool_stats_get_strings(data); 602 } 603 EXPORT_SYMBOL_GPL(mt792x_get_et_strings); 604 605 int mt792x_get_et_sset_count(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 606 int sset) 607 { 608 if (sset != ETH_SS_STATS) 609 return 0; 610 611 return ARRAY_SIZE(mt792x_gstrings_stats) + 612 page_pool_ethtool_stats_get_count(); 613 } 614 EXPORT_SYMBOL_GPL(mt792x_get_et_sset_count); 615 616 static void 617 mt792x_ethtool_worker(void *wi_data, struct ieee80211_sta *sta) 618 { 619 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; 620 struct mt76_ethtool_worker_info *wi = wi_data; 621 622 if (msta->vif->bss_conf.mt76.idx != wi->idx) 623 return; 624 625 mt76_ethtool_worker(wi, &msta->deflink.wcid.stats, true); 626 } 627 628 void mt792x_get_et_stats(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 629 struct ethtool_stats *stats, u64 *data) 630 { 631 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; 632 int stats_size = ARRAY_SIZE(mt792x_gstrings_stats); 633 struct mt792x_phy *phy = mt792x_hw_phy(hw); 634 struct mt792x_dev *dev = phy->dev; 635 struct mt76_mib_stats *mib = &phy->mib; 636 struct mt76_ethtool_worker_info wi = { 637 .data = data, 638 .idx = mvif->bss_conf.mt76.idx, 639 }; 640 int i, ei = 0; 641 642 mt792x_mutex_acquire(dev); 643 644 mt792x_mac_update_mib_stats(phy); 645 646 data[ei++] = mib->tx_ampdu_cnt; 647 data[ei++] = mib->tx_mpdu_attempts_cnt; 648 data[ei++] = mib->tx_mpdu_success_cnt; 649 data[ei++] = mib->tx_pkt_ebf_cnt; 650 data[ei++] = mib->tx_pkt_ibf_cnt; 651 652 /* Tx ampdu stat */ 653 for (i = 0; i < 15; i++) 654 data[ei++] = phy->mt76->aggr_stats[i]; 655 656 data[ei++] = phy->mib.ba_miss_cnt; 657 658 /* Tx Beamformer monitor */ 659 data[ei++] = mib->tx_bf_ibf_ppdu_cnt; 660 data[ei++] = mib->tx_bf_ebf_ppdu_cnt; 661 662 /* Tx Beamformer Rx feedback monitor */ 663 data[ei++] = mib->tx_bf_rx_fb_all_cnt; 664 data[ei++] = mib->tx_bf_rx_fb_he_cnt; 665 data[ei++] = mib->tx_bf_rx_fb_vht_cnt; 666 data[ei++] = mib->tx_bf_rx_fb_ht_cnt; 667 668 /* Tx amsdu info (pack-count histogram) */ 669 for (i = 0; i < ARRAY_SIZE(mib->tx_amsdu); i++) 670 data[ei++] = mib->tx_amsdu[i]; 671 672 /* rx counters */ 673 data[ei++] = mib->rx_mpdu_cnt; 674 data[ei++] = mib->rx_ampdu_cnt; 675 data[ei++] = mib->rx_ampdu_bytes_cnt; 676 data[ei++] = mib->rx_ba_cnt; 677 678 /* Add values for all stations owned by this vif */ 679 wi.initial_stat_idx = ei; 680 ieee80211_iterate_stations_atomic(hw, mt792x_ethtool_worker, &wi); 681 682 mt792x_mutex_release(dev); 683 684 if (!wi.sta_count) 685 return; 686 687 ei += wi.worker_stat_count; 688 689 mt76_ethtool_page_pool_stats(&dev->mt76, &data[ei], &ei); 690 stats_size += page_pool_ethtool_stats_get_count(); 691 692 if (ei != stats_size) 693 dev_err(dev->mt76.dev, "ei: %d SSTATS_LEN: %d", ei, 694 stats_size); 695 } 696 EXPORT_SYMBOL_GPL(mt792x_get_et_stats); 697 698 void mt792x_sta_statistics(struct ieee80211_hw *hw, 699 struct ieee80211_vif *vif, 700 struct ieee80211_sta *sta, 701 struct station_info *sinfo) 702 { 703 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; 704 struct rate_info *txrate = &msta->deflink.wcid.rate; 705 706 if (!txrate->legacy && !txrate->flags) 707 return; 708 709 if (txrate->legacy) { 710 sinfo->txrate.legacy = txrate->legacy; 711 } else { 712 sinfo->txrate.mcs = txrate->mcs; 713 sinfo->txrate.nss = txrate->nss; 714 sinfo->txrate.bw = txrate->bw; 715 sinfo->txrate.he_gi = txrate->he_gi; 716 sinfo->txrate.he_dcm = txrate->he_dcm; 717 sinfo->txrate.he_ru_alloc = txrate->he_ru_alloc; 718 } 719 sinfo->tx_failed = msta->deflink.wcid.stats.tx_failed; 720 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED); 721 722 sinfo->tx_retries = msta->deflink.wcid.stats.tx_retries; 723 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES); 724 725 sinfo->txrate.flags = txrate->flags; 726 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); 727 728 sinfo->ack_signal = (s8)msta->deflink.ack_signal; 729 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL); 730 731 sinfo->avg_ack_signal = -(s8)ewma_avg_signal_read(&msta->deflink.avg_ack_signal); 732 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG); 733 } 734 EXPORT_SYMBOL_GPL(mt792x_sta_statistics); 735 736 void mt792x_set_coverage_class(struct ieee80211_hw *hw, int radio_idx, 737 s16 coverage_class) 738 { 739 struct mt792x_phy *phy = mt792x_hw_phy(hw); 740 struct mt792x_dev *dev = phy->dev; 741 742 mt792x_mutex_acquire(dev); 743 744 phy->coverage_class = max_t(s16, coverage_class, 0); 745 mt792x_mac_set_timeing(phy); 746 747 mt792x_mutex_release(dev); 748 } 749 EXPORT_SYMBOL_GPL(mt792x_set_coverage_class); 750 751 int mt792x_init_wiphy(struct ieee80211_hw *hw) 752 { 753 struct mt792x_phy *phy = mt792x_hw_phy(hw); 754 struct mt792x_dev *dev = phy->dev; 755 struct wiphy *wiphy = hw->wiphy; 756 int err; 757 758 hw->queues = 4; 759 if (dev->has_eht) { 760 hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_EHT; 761 hw->max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_EHT; 762 } else { 763 hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_HE; 764 hw->max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_HE; 765 } 766 hw->netdev_features = NETIF_F_RXCSUM; 767 768 hw->radiotap_timestamp.units_pos = 769 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US; 770 771 phy->slottime = 9; 772 773 hw->sta_data_size = sizeof(struct mt792x_sta); 774 hw->vif_data_size = sizeof(struct mt792x_vif); 775 hw->chanctx_data_size = sizeof(struct mt792x_chanctx); 776 777 if (dev->fw_features & MT792x_FW_CAP_CNM) 778 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; 779 else 780 wiphy->flags &= ~WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; 781 782 err = mt792x_setup_iface_combinations(dev, wiphy); 783 if (err) 784 return err; 785 786 wiphy->iface_combinations = dev->iface_combinations; 787 wiphy->n_iface_combinations = dev->n_iface_combinations; 788 wiphy->flags &= ~(WIPHY_FLAG_IBSS_RSN | WIPHY_FLAG_4ADDR_AP | 789 WIPHY_FLAG_4ADDR_STATION); 790 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 791 BIT(NL80211_IFTYPE_AP) | 792 BIT(NL80211_IFTYPE_P2P_CLIENT) | 793 BIT(NL80211_IFTYPE_P2P_GO) | 794 BIT(NL80211_IFTYPE_P2P_DEVICE); 795 796 if ((dev->fw_features & MT792x_FW_CAP_CNM) && 797 (dev->fw_features & MT792x_FW_CAP_NAN)) { 798 wiphy->interface_modes |= BIT(NL80211_IFTYPE_NAN) | 799 BIT(NL80211_IFTYPE_NAN_DATA); 800 wiphy->nan_supported_bands = BIT(NL80211_BAND_2GHZ) | 801 BIT(NL80211_BAND_5GHZ); 802 wiphy->nan_capa.flags = WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC | 803 WIPHY_NAN_FLAGS_USERSPACE_DE; 804 wiphy->nan_capa.op_mode = NAN_OP_MODE_PHY_MODE_MASK; 805 wiphy->nan_capa.n_antennas = 0x22; 806 wiphy->nan_capa.max_channel_switch_time = 12; 807 wiphy->nan_capa.dev_capabilities = NAN_DEV_CAPA_EXT_KEY_ID_SUPPORTED; 808 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SECURE_NAN); 809 } 810 811 wiphy->max_scan_ie_len = MT76_CONNAC_SCAN_IE_LEN; 812 wiphy->max_scan_ssids = 4; 813 wiphy->max_sched_scan_plan_interval = 814 MT76_CONNAC_MAX_TIME_SCHED_SCAN_INTERVAL; 815 wiphy->max_sched_scan_ie_len = IEEE80211_MAX_DATA_LEN; 816 wiphy->max_sched_scan_ssids = MT76_CONNAC_MAX_SCHED_SCAN_SSID; 817 wiphy->max_match_sets = MT76_CONNAC_MAX_SCAN_MATCH; 818 wiphy->max_sched_scan_reqs = 1; 819 wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH | 820 WIPHY_FLAG_SPLIT_SCAN_6GHZ; 821 822 wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | 823 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; 824 phy->mt76->no_active_monitor = true; 825 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SET_SCAN_DWELL); 826 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_LEGACY); 827 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_HT); 828 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_VHT); 829 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_HE); 830 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT); 831 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0); 832 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS); 833 834 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); 835 ieee80211_hw_set(hw, HAS_RATE_CONTROL); 836 ieee80211_hw_set(hw, SUPPORTS_TX_ENCAP_OFFLOAD); 837 ieee80211_hw_set(hw, SUPPORTS_RX_DECAP_OFFLOAD); 838 if (is_mt7927(&dev->mt76)) 839 ieee80211_hw_set(hw, NO_VIRTUAL_MONITOR); 840 else 841 ieee80211_hw_set(hw, WANT_MONITOR_VIF); 842 ieee80211_hw_set(hw, SUPPORTS_PS); 843 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 844 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW); 845 ieee80211_hw_set(hw, CONNECTION_MONITOR); 846 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); 847 ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID); 848 849 ieee80211_hw_set(hw, CHANCTX_STA_CSA); 850 851 852 if (dev->pm.enable) 853 ieee80211_hw_set(hw, CONNECTION_MONITOR); 854 855 hw->max_tx_fragments = 4; 856 857 return 0; 858 } 859 EXPORT_SYMBOL_GPL(mt792x_init_wiphy); 860 861 static int 862 mt792x_get_offload_capability(struct device *dev, const char *fw_wm) 863 { 864 const struct mt76_connac2_fw_trailer *hdr; 865 struct mt792x_realease_info *rel_info; 866 const struct firmware *fw; 867 int ret, i, offset = 0; 868 const u8 *data, *end; 869 u8 offload_caps = 0; 870 871 ret = request_firmware(&fw, fw_wm, dev); 872 if (ret) 873 return ret; 874 875 if (!fw || !fw->data || fw->size < sizeof(*hdr)) { 876 dev_err(dev, "Invalid firmware\n"); 877 goto out; 878 } 879 880 data = fw->data; 881 hdr = (const void *)(fw->data + fw->size - sizeof(*hdr)); 882 883 for (i = 0; i < hdr->n_region; i++) { 884 const struct mt76_connac2_fw_region *region; 885 886 region = (const void *)((const u8 *)hdr - 887 (hdr->n_region - i) * sizeof(*region)); 888 offset += le32_to_cpu(region->len); 889 } 890 891 data += offset + 16; 892 rel_info = (struct mt792x_realease_info *)data; 893 data += sizeof(*rel_info); 894 end = data + le16_to_cpu(rel_info->len); 895 896 while (data < end) { 897 rel_info = (struct mt792x_realease_info *)data; 898 data += sizeof(*rel_info); 899 900 if (rel_info->tag == MT792x_FW_TAG_FEATURE) { 901 struct mt792x_fw_features *features; 902 903 features = (struct mt792x_fw_features *)data; 904 offload_caps = features->data; 905 break; 906 } 907 908 data += le16_to_cpu(rel_info->len) + rel_info->pad_len; 909 } 910 911 out: 912 release_firmware(fw); 913 914 return offload_caps; 915 } 916 917 static bool mt792x_needs_cnm_runtime(const void *drv_data) 918 { 919 const char *fw_wm = drv_data; 920 921 return fw_wm && !strcmp(fw_wm, MT7927_FIRMWARE_WM); 922 } 923 924 struct ieee80211_ops * 925 mt792x_get_mac80211_ops(struct device *dev, 926 const struct ieee80211_ops *mac80211_ops, 927 void *drv_data, u8 *fw_features) 928 { 929 struct ieee80211_ops *ops; 930 int ret; 931 932 ops = devm_kmemdup(dev, mac80211_ops, sizeof(struct ieee80211_ops), 933 GFP_KERNEL); 934 if (!ops) 935 return NULL; 936 937 ret = mt792x_get_offload_capability(dev, drv_data); 938 if (ret < 0) { 939 dev_warn(dev, "failed to read firmware offload caps: %d\n", ret); 940 *fw_features = 0; 941 } else { 942 *fw_features = ret; 943 } 944 945 if (mt792x_needs_cnm_runtime(drv_data)) 946 *fw_features |= MT792x_FW_CAP_CNM; 947 948 if (!(*fw_features & MT792x_FW_CAP_CNM)) { 949 ops->remain_on_channel = NULL; 950 ops->cancel_remain_on_channel = NULL; 951 ops->add_chanctx = ieee80211_emulate_add_chanctx; 952 ops->remove_chanctx = ieee80211_emulate_remove_chanctx; 953 ops->change_chanctx = ieee80211_emulate_change_chanctx; 954 ops->switch_vif_chanctx = ieee80211_emulate_switch_vif_chanctx; 955 ops->assign_vif_chanctx = NULL; 956 ops->unassign_vif_chanctx = NULL; 957 ops->mgd_prepare_tx = NULL; 958 ops->mgd_complete_tx = NULL; 959 } 960 return ops; 961 } 962 EXPORT_SYMBOL_GPL(mt792x_get_mac80211_ops); 963 964 int mt792x_init_wcid(struct mt792x_dev *dev) 965 { 966 int idx; 967 968 /* Beacon and mgmt frames should occupy wcid 0 */ 969 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT792x_WTBL_STA - 1); 970 if (idx) 971 return -ENOSPC; 972 973 dev->mt76.global_wcid.idx = idx; 974 dev->mt76.global_wcid.hw_key_idx = -1; 975 dev->mt76.global_wcid.tx_info |= MT_WCID_TX_INFO_SET; 976 rcu_assign_pointer(dev->mt76.wcid[idx], &dev->mt76.global_wcid); 977 978 return 0; 979 } 980 EXPORT_SYMBOL_GPL(mt792x_init_wcid); 981 982 int mt792x_mcu_drv_pmctrl(struct mt792x_dev *dev) 983 { 984 struct mt76_phy *mphy = &dev->mt76.phy; 985 struct mt76_connac_pm *pm = &dev->pm; 986 int err = 0; 987 988 mutex_lock(&pm->mutex); 989 990 if (!test_bit(MT76_STATE_PM, &mphy->state)) 991 goto out; 992 993 err = __mt792x_mcu_drv_pmctrl(dev); 994 out: 995 mutex_unlock(&pm->mutex); 996 997 if (err) 998 mt792x_reset(&dev->mt76); 999 1000 return err; 1001 } 1002 EXPORT_SYMBOL_GPL(mt792x_mcu_drv_pmctrl); 1003 1004 int mt792x_mcu_fw_pmctrl(struct mt792x_dev *dev) 1005 { 1006 struct mt76_phy *mphy = &dev->mt76.phy; 1007 struct mt76_connac_pm *pm = &dev->pm; 1008 int err = 0; 1009 1010 mutex_lock(&pm->mutex); 1011 1012 if (mt76_connac_skip_fw_pmctrl(mphy, pm)) 1013 goto out; 1014 1015 err = __mt792x_mcu_fw_pmctrl(dev); 1016 out: 1017 mutex_unlock(&pm->mutex); 1018 1019 if (err) 1020 mt792x_reset(&dev->mt76); 1021 1022 return err; 1023 } 1024 EXPORT_SYMBOL_GPL(mt792x_mcu_fw_pmctrl); 1025 1026 int __mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev) 1027 { 1028 int i, err = 0; 1029 1030 for (i = 0; i < MT792x_DRV_OWN_RETRY_COUNT; i++) { 1031 mt76_wr(dev, MT_CONN_ON_LPCTL, PCIE_LPCR_HOST_CLR_OWN); 1032 1033 if (dev->aspm_supported) 1034 usleep_range(2000, 3000); 1035 1036 if (mt76_poll_msec_tick(dev, MT_CONN_ON_LPCTL, 1037 PCIE_LPCR_HOST_OWN_SYNC, 0, 50, 1)) 1038 break; 1039 } 1040 1041 if (i == MT792x_DRV_OWN_RETRY_COUNT) { 1042 dev_err(dev->mt76.dev, "driver own failed\n"); 1043 err = -EIO; 1044 } 1045 1046 return err; 1047 } 1048 EXPORT_SYMBOL_GPL(__mt792xe_mcu_drv_pmctrl); 1049 1050 int mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev) 1051 { 1052 struct mt76_phy *mphy = &dev->mt76.phy; 1053 struct mt76_connac_pm *pm = &dev->pm; 1054 int err; 1055 1056 err = __mt792xe_mcu_drv_pmctrl(dev); 1057 if (err < 0) 1058 goto out; 1059 1060 mt792x_wpdma_reinit_cond(dev); 1061 clear_bit(MT76_STATE_PM, &mphy->state); 1062 1063 pm->stats.last_wake_event = jiffies; 1064 pm->stats.doze_time += pm->stats.last_wake_event - 1065 pm->stats.last_doze_event; 1066 out: 1067 return err; 1068 } 1069 EXPORT_SYMBOL_GPL(mt792xe_mcu_drv_pmctrl); 1070 1071 int mt792xe_mcu_fw_pmctrl(struct mt792x_dev *dev) 1072 { 1073 struct mt76_phy *mphy = &dev->mt76.phy; 1074 struct mt76_connac_pm *pm = &dev->pm; 1075 int i; 1076 1077 for (i = 0; i < MT792x_DRV_OWN_RETRY_COUNT; i++) { 1078 mt76_wr(dev, MT_CONN_ON_LPCTL, PCIE_LPCR_HOST_SET_OWN); 1079 if (mt76_poll_msec_tick(dev, MT_CONN_ON_LPCTL, 1080 PCIE_LPCR_HOST_OWN_SYNC, 4, 50, 1)) 1081 break; 1082 } 1083 1084 if (i == MT792x_DRV_OWN_RETRY_COUNT) { 1085 dev_err(dev->mt76.dev, "firmware own failed\n"); 1086 clear_bit(MT76_STATE_PM, &mphy->state); 1087 return -EIO; 1088 } 1089 1090 pm->stats.last_doze_event = jiffies; 1091 pm->stats.awake_time += pm->stats.last_doze_event - 1092 pm->stats.last_wake_event; 1093 1094 return 0; 1095 } 1096 EXPORT_SYMBOL_GPL(mt792xe_mcu_fw_pmctrl); 1097 1098 int mt792x_load_firmware(struct mt792x_dev *dev) 1099 { 1100 int ret; 1101 1102 mt76_connac_mcu_restart(&dev->mt76); 1103 1104 if (!mt76_poll_msec(dev, MT_CONN_ON_MISC, MT_TOP_MISC_FW_STATE, 1105 MT_TOP_MISC2_FW_PWR_ON, 1000)) 1106 dev_warn(dev->mt76.dev, 1107 "MCU is not ready for firmware download\n"); 1108 1109 if (is_mt7928(&dev->mt76)) { 1110 dev_info(dev->mt76.dev, "Loading CB firmware patch: %s\n", 1111 mt792x_cb_patch_name(dev)); 1112 ret = mt76_connac3_load_cb_patch(&dev->mt76, mt792x_cb_patch_name(dev)); 1113 if (ret) 1114 return ret; 1115 } 1116 1117 dev_info(dev->mt76.dev, "Loading firmware patch: %s\n", mt792x_patch_name(dev)); 1118 ret = mt76_connac2_load_patch(&dev->mt76, mt792x_patch_name(dev)); 1119 if (ret) 1120 return ret; 1121 1122 if (mt76_is_sdio(&dev->mt76)) { 1123 /* activate again */ 1124 ret = __mt792x_mcu_fw_pmctrl(dev); 1125 if (!ret) 1126 ret = __mt792x_mcu_drv_pmctrl(dev); 1127 } 1128 1129 if (is_mt7928(&dev->mt76)) { 1130 ret = mt76_connac3_load_phy_ram(&dev->mt76, mt792x_phy_ram_name(dev)); 1131 if (ret) 1132 return ret; 1133 } 1134 1135 ret = mt76_connac2_load_ram(&dev->mt76, mt792x_ram_name(dev), NULL); 1136 if (ret) 1137 return ret; 1138 1139 if (!mt76_poll_msec(dev, MT_CONN_ON_MISC, MT_TOP_MISC2_FW_N9_RDY, 1140 MT_TOP_MISC2_FW_N9_RDY, 1500)) { 1141 dev_err(dev->mt76.dev, "Timeout for initializing firmware\n"); 1142 1143 return -EIO; 1144 } 1145 1146 #ifdef CONFIG_PM 1147 dev->mt76.hw->wiphy->wowlan = &mt76_connac_wowlan_support; 1148 #endif /* CONFIG_PM */ 1149 1150 dev_dbg(dev->mt76.dev, "Firmware init done\n"); 1151 1152 return 0; 1153 } 1154 EXPORT_SYMBOL_GPL(mt792x_load_firmware); 1155 1156 void mt792x_config_mac_addr_list(struct mt792x_dev *dev) 1157 { 1158 struct ieee80211_hw *hw = mt76_hw(dev); 1159 struct wiphy *wiphy = hw->wiphy; 1160 int i; 1161 1162 for (i = 0; i < ARRAY_SIZE(dev->macaddr_list); i++) { 1163 u8 *addr = dev->macaddr_list[i].addr; 1164 1165 memcpy(addr, dev->mphy.macaddr, ETH_ALEN); 1166 1167 if (!i) 1168 continue; 1169 1170 addr[0] |= BIT(1); 1171 addr[0] ^= ((i - 1) << 2); 1172 } 1173 wiphy->addresses = dev->macaddr_list; 1174 wiphy->n_addresses = ARRAY_SIZE(dev->macaddr_list); 1175 } 1176 EXPORT_SYMBOL_GPL(mt792x_config_mac_addr_list); 1177 1178 MODULE_DESCRIPTION("MediaTek MT792x core driver"); 1179 MODULE_LICENSE("Dual BSD/GPL"); 1180 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo@kernel.org>"); 1181