mcu.c (ffa1bf97425bd511b105ce769976e20a845a71e9) | mcu.c (67aa27431c7f871962fccdb70ae1f3883691e958) |
---|---|
1// SPDX-License-Identifier: ISC 2/* Copyright (C) 2020 MediaTek Inc. */ 3 4#include <linux/firmware.h> 5#include <linux/fs.h> 6#include "mt7921.h" 7#include "mcu.h" 8#include "mac.h" --- 49 unchanged lines hidden (view full) --- 58 __le32 decomp_blk_sz; 59 u8 reserved[4]; 60 __le32 addr; 61 __le32 len; 62 u8 feature_set; 63 u8 reserved1[15]; 64} __packed; 65 | 1// SPDX-License-Identifier: ISC 2/* Copyright (C) 2020 MediaTek Inc. */ 3 4#include <linux/firmware.h> 5#include <linux/fs.h> 6#include "mt7921.h" 7#include "mcu.h" 8#include "mac.h" --- 49 unchanged lines hidden (view full) --- 58 __le32 decomp_blk_sz; 59 u8 reserved[4]; 60 __le32 addr; 61 __le32 len; 62 u8 feature_set; 63 u8 reserved1[15]; 64} __packed; 65 |
66#define MCU_PATCH_ADDRESS 0x200000 67 | |
68#define MT_STA_BFER BIT(0) 69#define MT_STA_BFEE BIT(1) 70 71#define FW_FEATURE_SET_ENCRYPT BIT(0) 72#define FW_FEATURE_SET_KEY_IDX GENMASK(2, 1) 73#define FW_FEATURE_ENCRY_MODE BIT(4) 74#define FW_FEATURE_OVERRIDE_ADDR BIT(5) 75 --- 8 unchanged lines hidden (view full) --- 84#define FW_START_WORKING_PDA_CR4 BIT(2) 85 86#define PATCH_SEC_TYPE_MASK GENMASK(15, 0) 87#define PATCH_SEC_TYPE_INFO 0x2 88 89#define to_wcid_lo(id) FIELD_GET(GENMASK(7, 0), (u16)id) 90#define to_wcid_hi(id) FIELD_GET(GENMASK(9, 8), (u16)id) 91 | 66#define MT_STA_BFER BIT(0) 67#define MT_STA_BFEE BIT(1) 68 69#define FW_FEATURE_SET_ENCRYPT BIT(0) 70#define FW_FEATURE_SET_KEY_IDX GENMASK(2, 1) 71#define FW_FEATURE_ENCRY_MODE BIT(4) 72#define FW_FEATURE_OVERRIDE_ADDR BIT(5) 73 --- 8 unchanged lines hidden (view full) --- 82#define FW_START_WORKING_PDA_CR4 BIT(2) 83 84#define PATCH_SEC_TYPE_MASK GENMASK(15, 0) 85#define PATCH_SEC_TYPE_INFO 0x2 86 87#define to_wcid_lo(id) FIELD_GET(GENMASK(7, 0), (u16)id) 88#define to_wcid_hi(id) FIELD_GET(GENMASK(9, 8), (u16)id) 89 |
92#define HE_PHY(p, c) u8_get_bits(c, IEEE80211_HE_PHY_##p) 93#define HE_MAC(m, c) u8_get_bits(c, IEEE80211_HE_MAC_##m) 94 | |
95static enum mt7921_cipher_type 96mt7921_mcu_get_cipher(int cipher) 97{ 98 switch (cipher) { 99 case WLAN_CIPHER_SUITE_WEP40: 100 return MT_CIPHER_WEP40; 101 case WLAN_CIPHER_SUITE_WEP104: 102 return MT_CIPHER_WEP104; --- 30 unchanged lines hidden (view full) --- 133 }; 134 135 if (chandef->width >= ARRAY_SIZE(width_to_bw)) 136 return 0; 137 138 return width_to_bw[chandef->width]; 139} 140 | 90static enum mt7921_cipher_type 91mt7921_mcu_get_cipher(int cipher) 92{ 93 switch (cipher) { 94 case WLAN_CIPHER_SUITE_WEP40: 95 return MT_CIPHER_WEP40; 96 case WLAN_CIPHER_SUITE_WEP104: 97 return MT_CIPHER_WEP104; --- 30 unchanged lines hidden (view full) --- 128 }; 129 130 if (chandef->width >= ARRAY_SIZE(width_to_bw)) 131 return 0; 132 133 return width_to_bw[chandef->width]; 134} 135 |
141static const struct ieee80211_sta_he_cap * 142mt7921_get_he_phy_cap(struct mt7921_phy *phy, struct ieee80211_vif *vif) 143{ 144 struct ieee80211_supported_band *sband; 145 enum nl80211_band band; 146 147 band = phy->mt76->chandef.chan->band; 148 sband = phy->mt76->hw->wiphy->bands[band]; 149 150 return ieee80211_get_he_iftype_cap(sband, vif->type); 151} 152 153static u8 154mt7921_get_phy_mode(struct mt7921_dev *dev, struct ieee80211_vif *vif, 155 enum nl80211_band band, struct ieee80211_sta *sta) 156{ 157 struct ieee80211_sta_ht_cap *ht_cap; 158 struct ieee80211_sta_vht_cap *vht_cap; 159 const struct ieee80211_sta_he_cap *he_cap; 160 u8 mode = 0; 161 162 if (sta) { 163 ht_cap = &sta->ht_cap; 164 vht_cap = &sta->vht_cap; 165 he_cap = &sta->he_cap; 166 } else { 167 struct ieee80211_supported_band *sband; 168 struct mt7921_phy *phy = &dev->phy; 169 170 sband = phy->mt76->hw->wiphy->bands[band]; 171 ht_cap = &sband->ht_cap; 172 vht_cap = &sband->vht_cap; 173 he_cap = ieee80211_get_he_iftype_cap(sband, vif->type); 174 } 175 176 if (band == NL80211_BAND_2GHZ) { 177 mode |= PHY_MODE_B | PHY_MODE_G; 178 179 if (ht_cap->ht_supported) 180 mode |= PHY_MODE_GN; 181 182 if (he_cap->has_he) 183 mode |= PHY_MODE_AX_24G; 184 } else if (band == NL80211_BAND_5GHZ) { 185 mode |= PHY_MODE_A; 186 187 if (ht_cap->ht_supported) 188 mode |= PHY_MODE_AN; 189 190 if (vht_cap->vht_supported) 191 mode |= PHY_MODE_AC; 192 193 if (he_cap->has_he) 194 mode |= PHY_MODE_AX_5G; 195 } 196 197 return mode; 198} 199 200static u8 201mt7921_get_phy_mode_v2(struct mt7921_dev *dev, struct ieee80211_vif *vif, 202 enum nl80211_band band, struct ieee80211_sta *sta) 203{ 204 struct ieee80211_sta_ht_cap *ht_cap; 205 struct ieee80211_sta_vht_cap *vht_cap; 206 const struct ieee80211_sta_he_cap *he_cap; 207 u8 mode = 0; 208 209 if (sta) { 210 ht_cap = &sta->ht_cap; 211 vht_cap = &sta->vht_cap; 212 he_cap = &sta->he_cap; 213 } else { 214 struct ieee80211_supported_band *sband; 215 struct mt7921_phy *phy = &dev->phy; 216 217 sband = phy->mt76->hw->wiphy->bands[band]; 218 ht_cap = &sband->ht_cap; 219 vht_cap = &sband->vht_cap; 220 he_cap = ieee80211_get_he_iftype_cap(sband, vif->type); 221 } 222 223 if (band == NL80211_BAND_2GHZ) { 224 mode |= PHY_TYPE_BIT_HR_DSSS | PHY_TYPE_BIT_ERP; 225 226 if (ht_cap->ht_supported) 227 mode |= PHY_TYPE_BIT_HT; 228 229 if (he_cap->has_he) 230 mode |= PHY_TYPE_BIT_HE; 231 } else if (band == NL80211_BAND_5GHZ) { 232 mode |= PHY_TYPE_BIT_OFDM; 233 234 if (ht_cap->ht_supported) 235 mode |= PHY_TYPE_BIT_HT; 236 237 if (vht_cap->vht_supported) 238 mode |= PHY_TYPE_BIT_VHT; 239 240 if (he_cap->has_he) 241 mode |= PHY_TYPE_BIT_HE; 242 } 243 244 return mode; 245} 246 | |
247static int 248mt7921_mcu_parse_eeprom(struct mt76_dev *dev, struct sk_buff *skb) 249{ 250 struct mt7921_mcu_eeprom_info *res; 251 u8 *buf; 252 253 if (!skb) 254 return -EINVAL; --- 24 unchanged lines hidden (view full) --- 279 if (seq != rxd->seq) 280 return -EAGAIN; 281 282 switch (cmd) { 283 case MCU_CMD_PATCH_SEM_CONTROL: 284 skb_pull(skb, sizeof(*rxd) - 4); 285 ret = *skb->data; 286 break; | 136static int 137mt7921_mcu_parse_eeprom(struct mt76_dev *dev, struct sk_buff *skb) 138{ 139 struct mt7921_mcu_eeprom_info *res; 140 u8 *buf; 141 142 if (!skb) 143 return -EINVAL; --- 24 unchanged lines hidden (view full) --- 168 if (seq != rxd->seq) 169 return -EAGAIN; 170 171 switch (cmd) { 172 case MCU_CMD_PATCH_SEM_CONTROL: 173 skb_pull(skb, sizeof(*rxd) - 4); 174 ret = *skb->data; 175 break; |
287 case MCU_EXT_CMD_THERMAL_CTRL: | 176 case MCU_EXT_CMD_GET_TEMP: |
288 skb_pull(skb, sizeof(*rxd) + 4); 289 ret = le32_to_cpu(*(__le32 *)skb->data); 290 break; 291 case MCU_EXT_CMD_EFUSE_ACCESS: 292 ret = mt7921_mcu_parse_eeprom(mdev, skb); 293 break; 294 case MCU_UNI_CMD_DEV_INFO_UPDATE: 295 case MCU_UNI_CMD_BSS_INFO_UPDATE: --- 243 unchanged lines hidden (view full) --- 539 __skb_queue_tail(&phy->scan_event_list, skb); 540 spin_unlock_bh(&dev->mt76.lock); 541 542 ieee80211_queue_delayed_work(mphy->hw, &phy->scan_work, 543 MT7921_HW_SCAN_TIMEOUT); 544} 545 546static void | 177 skb_pull(skb, sizeof(*rxd) + 4); 178 ret = le32_to_cpu(*(__le32 *)skb->data); 179 break; 180 case MCU_EXT_CMD_EFUSE_ACCESS: 181 ret = mt7921_mcu_parse_eeprom(mdev, skb); 182 break; 183 case MCU_UNI_CMD_DEV_INFO_UPDATE: 184 case MCU_UNI_CMD_BSS_INFO_UPDATE: --- 243 unchanged lines hidden (view full) --- 428 __skb_queue_tail(&phy->scan_event_list, skb); 429 spin_unlock_bh(&dev->mt76.lock); 430 431 ieee80211_queue_delayed_work(mphy->hw, &phy->scan_work, 432 MT7921_HW_SCAN_TIMEOUT); 433} 434 435static void |
547mt7921_mcu_beacon_loss_iter(void *priv, u8 *mac, struct ieee80211_vif *vif) 548{ 549 struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv; 550 struct mt7921_beacon_loss_event *event = priv; 551 552 if (mvif->mt76.idx != event->bss_idx) 553 return; 554 555 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)) 556 return; 557 558 ieee80211_beacon_loss(vif); 559} 560 561static void | |
562mt7921_mcu_beacon_loss_event(struct mt7921_dev *dev, struct sk_buff *skb) 563{ | 436mt7921_mcu_beacon_loss_event(struct mt7921_dev *dev, struct sk_buff *skb) 437{ |
564 struct mt7921_beacon_loss_event *event; | 438 struct mt76_connac_beacon_loss_event *event; |
565 struct mt76_phy *mphy; 566 u8 band_idx = 0; /* DBDC support */ 567 568 skb_pull(skb, sizeof(struct mt7921_mcu_rxd)); | 439 struct mt76_phy *mphy; 440 u8 band_idx = 0; /* DBDC support */ 441 442 skb_pull(skb, sizeof(struct mt7921_mcu_rxd)); |
569 event = (struct mt7921_beacon_loss_event *)skb->data; | 443 event = (struct mt76_connac_beacon_loss_event *)skb->data; |
570 if (band_idx && dev->mt76.phy2) 571 mphy = dev->mt76.phy2; 572 else 573 mphy = &dev->mt76.phy; 574 575 ieee80211_iterate_active_interfaces_atomic(mphy->hw, 576 IEEE80211_IFACE_ITER_RESUME_ALL, | 444 if (band_idx && dev->mt76.phy2) 445 mphy = dev->mt76.phy2; 446 else 447 mphy = &dev->mt76.phy; 448 449 ieee80211_iterate_active_interfaces_atomic(mphy->hw, 450 IEEE80211_IFACE_ITER_RESUME_ALL, |
577 mt7921_mcu_beacon_loss_iter, event); | 451 mt76_connac_mcu_beacon_loss_iter, event); |
578} 579 580static void 581mt7921_mcu_bss_event(struct mt7921_dev *dev, struct sk_buff *skb) 582{ 583 struct mt76_phy *mphy = &dev->mt76.phy; | 452} 453 454static void 455mt7921_mcu_bss_event(struct mt7921_dev *dev, struct sk_buff *skb) 456{ 457 struct mt76_phy *mphy = &dev->mt76.phy; |
584 struct mt7921_mcu_bss_event *event; | 458 struct mt76_connac_mcu_bss_event *event; |
585 | 459 |
586 event = (struct mt7921_mcu_bss_event *)(skb->data + 587 sizeof(struct mt7921_mcu_rxd)); | 460 skb_pull(skb, sizeof(struct mt7921_mcu_rxd)); 461 event = (struct mt76_connac_mcu_bss_event *)skb->data; |
588 if (event->is_absent) 589 ieee80211_stop_queues(mphy->hw); 590 else 591 ieee80211_wake_queues(mphy->hw); 592} 593 594static void 595mt7921_mcu_debug_msg_event(struct mt7921_dev *dev, struct sk_buff *skb) --- 65 unchanged lines hidden (view full) --- 661 rxd->eid == MCU_EVENT_SCAN_DONE || 662 rxd->eid == MCU_EVENT_DBG_MSG || 663 !rxd->seq) 664 mt7921_mcu_rx_unsolicited_event(dev, skb); 665 else 666 mt76_mcu_rx_event(&dev->mt76, skb); 667} 668 | 462 if (event->is_absent) 463 ieee80211_stop_queues(mphy->hw); 464 else 465 ieee80211_wake_queues(mphy->hw); 466} 467 468static void 469mt7921_mcu_debug_msg_event(struct mt7921_dev *dev, struct sk_buff *skb) --- 65 unchanged lines hidden (view full) --- 535 rxd->eid == MCU_EVENT_SCAN_DONE || 536 rxd->eid == MCU_EVENT_DBG_MSG || 537 !rxd->seq) 538 mt7921_mcu_rx_unsolicited_event(dev, skb); 539 else 540 mt76_mcu_rx_event(&dev->mt76, skb); 541} 542 |
669static struct sk_buff * 670mt7921_mcu_alloc_sta_req(struct mt7921_dev *dev, struct mt7921_vif *mvif, 671 struct mt7921_sta *msta, int len) 672{ 673 struct sta_req_hdr hdr = { 674 .bss_idx = mvif->mt76.idx, 675 .wlan_idx_lo = msta ? to_wcid_lo(msta->wcid.idx) : 0, 676 .wlan_idx_hi = msta ? to_wcid_hi(msta->wcid.idx) : 0, 677 .muar_idx = msta ? mvif->mt76.omac_idx : 0, 678 .is_tlv_append = 1, 679 }; 680 struct sk_buff *skb; 681 682 skb = mt76_mcu_msg_alloc(&dev->mt76, NULL, len); 683 if (!skb) 684 return ERR_PTR(-ENOMEM); 685 686 skb_put_data(skb, &hdr, sizeof(hdr)); 687 688 return skb; 689} 690 691static struct wtbl_req_hdr * 692mt7921_mcu_alloc_wtbl_req(struct mt7921_dev *dev, struct mt7921_sta *msta, 693 int cmd, void *sta_wtbl, struct sk_buff **skb) 694{ 695 struct tlv *sta_hdr = sta_wtbl; 696 struct wtbl_req_hdr hdr = { 697 .wlan_idx_lo = to_wcid_lo(msta->wcid.idx), 698 .wlan_idx_hi = to_wcid_hi(msta->wcid.idx), 699 .operation = cmd, 700 }; 701 struct sk_buff *nskb = *skb; 702 703 if (!nskb) { 704 nskb = mt76_mcu_msg_alloc(&dev->mt76, NULL, 705 MT7921_WTBL_UPDATE_BA_SIZE); 706 if (!nskb) 707 return ERR_PTR(-ENOMEM); 708 709 *skb = nskb; 710 } 711 712 if (sta_hdr) 713 sta_hdr->len = cpu_to_le16(sizeof(hdr)); 714 715 return skb_put_data(nskb, &hdr, sizeof(hdr)); 716} 717 718static struct tlv * 719mt7921_mcu_add_nested_tlv(struct sk_buff *skb, int tag, int len, 720 void *sta_ntlv, void *sta_wtbl) 721{ 722 struct sta_ntlv_hdr *ntlv_hdr = sta_ntlv; 723 struct tlv *sta_hdr = sta_wtbl; 724 struct tlv *ptlv, tlv = { 725 .tag = cpu_to_le16(tag), 726 .len = cpu_to_le16(len), 727 }; 728 u16 ntlv; 729 730 ptlv = skb_put(skb, len); 731 memcpy(ptlv, &tlv, sizeof(tlv)); 732 733 ntlv = le16_to_cpu(ntlv_hdr->tlv_num); 734 ntlv_hdr->tlv_num = cpu_to_le16(ntlv + 1); 735 736 if (sta_hdr) { 737 u16 size = le16_to_cpu(sta_hdr->len); 738 739 sta_hdr->len = cpu_to_le16(size + len); 740 } 741 742 return ptlv; 743} 744 745static struct tlv * 746mt7921_mcu_add_tlv(struct sk_buff *skb, int tag, int len) 747{ 748 return mt7921_mcu_add_nested_tlv(skb, tag, len, skb->data, NULL); 749} 750 751static void 752mt7921_mcu_uni_bss_he_tlv(struct tlv *tlv, struct ieee80211_vif *vif, 753 struct mt7921_phy *phy) 754{ 755#define DEFAULT_HE_PE_DURATION 4 756#define DEFAULT_HE_DURATION_RTS_THRES 1023 757 const struct ieee80211_sta_he_cap *cap; 758 struct bss_info_uni_he *he; 759 760 cap = mt7921_get_he_phy_cap(phy, vif); 761 762 he = (struct bss_info_uni_he *)tlv; 763 he->he_pe_duration = vif->bss_conf.htc_trig_based_pkt_ext; 764 if (!he->he_pe_duration) 765 he->he_pe_duration = DEFAULT_HE_PE_DURATION; 766 767 he->he_rts_thres = cpu_to_le16(vif->bss_conf.frame_time_rts_th); 768 if (!he->he_rts_thres) 769 he->he_rts_thres = cpu_to_le16(DEFAULT_HE_DURATION_RTS_THRES); 770 771 he->max_nss_mcs[CMD_HE_MCS_BW80] = cap->he_mcs_nss_supp.tx_mcs_80; 772 he->max_nss_mcs[CMD_HE_MCS_BW160] = cap->he_mcs_nss_supp.tx_mcs_160; 773 he->max_nss_mcs[CMD_HE_MCS_BW8080] = cap->he_mcs_nss_supp.tx_mcs_80p80; 774} 775 | |
776/** starec & wtbl **/ 777static int 778mt7921_mcu_sta_key_tlv(struct mt7921_sta *msta, struct sk_buff *skb, 779 struct ieee80211_key_conf *key, enum set_key_cmd cmd) 780{ 781 struct mt7921_sta_key_conf *bip = &msta->bip; 782 struct sta_rec_sec *sec; 783 struct tlv *tlv; 784 u32 len = sizeof(*sec); 785 | 543/** starec & wtbl **/ 544static int 545mt7921_mcu_sta_key_tlv(struct mt7921_sta *msta, struct sk_buff *skb, 546 struct ieee80211_key_conf *key, enum set_key_cmd cmd) 547{ 548 struct mt7921_sta_key_conf *bip = &msta->bip; 549 struct sta_rec_sec *sec; 550 struct tlv *tlv; 551 u32 len = sizeof(*sec); 552 |
786 tlv = mt7921_mcu_add_tlv(skb, STA_REC_KEY_V2, sizeof(*sec)); | 553 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_KEY_V2, sizeof(*sec)); |
787 788 sec = (struct sta_rec_sec *)tlv; 789 sec->add = cmd; 790 791 if (cmd == SET_KEY) { 792 struct sec_key *sec_key; 793 u8 cipher; 794 --- 48 unchanged lines hidden (view full) --- 843} 844 845int mt7921_mcu_add_key(struct mt7921_dev *dev, struct ieee80211_vif *vif, 846 struct mt7921_sta *msta, struct ieee80211_key_conf *key, 847 enum set_key_cmd cmd) 848{ 849 struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv; 850 struct sk_buff *skb; | 554 555 sec = (struct sta_rec_sec *)tlv; 556 sec->add = cmd; 557 558 if (cmd == SET_KEY) { 559 struct sec_key *sec_key; 560 u8 cipher; 561 --- 48 unchanged lines hidden (view full) --- 610} 611 612int mt7921_mcu_add_key(struct mt7921_dev *dev, struct ieee80211_vif *vif, 613 struct mt7921_sta *msta, struct ieee80211_key_conf *key, 614 enum set_key_cmd cmd) 615{ 616 struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv; 617 struct sk_buff *skb; |
851 int len = sizeof(struct sta_req_hdr) + sizeof(struct sta_rec_sec); | |
852 int ret; 853 | 618 int ret; 619 |
854 skb = mt7921_mcu_alloc_sta_req(dev, mvif, msta, len); | 620 skb = mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, 621 &msta->wcid); |
855 if (IS_ERR(skb)) 856 return PTR_ERR(skb); 857 858 ret = mt7921_mcu_sta_key_tlv(msta, skb, key, cmd); 859 if (ret) 860 return ret; 861 862 return mt76_mcu_skb_send_msg(&dev->mt76, skb, 863 MCU_UNI_CMD_STA_REC_UPDATE, true); 864} 865 | 622 if (IS_ERR(skb)) 623 return PTR_ERR(skb); 624 625 ret = mt7921_mcu_sta_key_tlv(msta, skb, key, cmd); 626 if (ret) 627 return ret; 628 629 return mt76_mcu_skb_send_msg(&dev->mt76, skb, 630 MCU_UNI_CMD_STA_REC_UPDATE, true); 631} 632 |
866static void 867mt7921_mcu_sta_ba_tlv(struct sk_buff *skb, 868 struct ieee80211_ampdu_params *params, 869 bool enable, bool tx) | 633int mt7921_mcu_uni_tx_ba(struct mt7921_dev *dev, 634 struct ieee80211_ampdu_params *params, 635 bool enable) |
870{ | 636{ |
871 struct sta_rec_ba *ba; 872 struct tlv *tlv; 873 874 tlv = mt7921_mcu_add_tlv(skb, STA_REC_BA, sizeof(*ba)); 875 876 ba = (struct sta_rec_ba *)tlv; 877 ba->ba_type = tx ? MT_BA_TYPE_ORIGINATOR : MT_BA_TYPE_RECIPIENT, 878 ba->winsize = cpu_to_le16(params->buf_size); 879 ba->ssn = cpu_to_le16(params->ssn); 880 ba->ba_en = enable << params->tid; 881 ba->amsdu = params->amsdu; 882 ba->tid = params->tid; 883} 884 885static void 886mt7921_mcu_wtbl_ba_tlv(struct sk_buff *skb, 887 struct ieee80211_ampdu_params *params, 888 bool enable, bool tx, void *sta_wtbl, 889 void *wtbl_tlv) 890{ 891 struct wtbl_ba *ba; 892 struct tlv *tlv; 893 894 tlv = mt7921_mcu_add_nested_tlv(skb, WTBL_BA, sizeof(*ba), 895 wtbl_tlv, sta_wtbl); 896 897 ba = (struct wtbl_ba *)tlv; 898 ba->tid = params->tid; 899 900 if (tx) { 901 ba->ba_type = MT_BA_TYPE_ORIGINATOR; 902 ba->sn = enable ? cpu_to_le16(params->ssn) : 0; 903 ba->ba_en = enable; 904 } else { 905 memcpy(ba->peer_addr, params->sta->addr, ETH_ALEN); 906 ba->ba_type = MT_BA_TYPE_RECIPIENT; 907 ba->rst_ba_tid = params->tid; 908 ba->rst_ba_sel = RST_BA_MAC_TID_MATCH; 909 ba->rst_ba_sb = 1; 910 } 911 912 if (enable && tx) 913 ba->ba_winsize = cpu_to_le16(params->buf_size); 914} 915 916static int 917mt7921_mcu_sta_ba(struct mt7921_dev *dev, 918 struct ieee80211_ampdu_params *params, 919 bool enable, bool tx, int cmd) 920{ | |
921 struct mt7921_sta *msta = (struct mt7921_sta *)params->sta->drv_priv; | 637 struct mt7921_sta *msta = (struct mt7921_sta *)params->sta->drv_priv; |
922 struct mt7921_vif *mvif = msta->vif; 923 struct wtbl_req_hdr *wtbl_hdr; 924 struct tlv *sta_wtbl; 925 struct sk_buff *skb; 926 int ret; | |
927 | 638 |
928 if (enable && tx && !params->amsdu) | 639 if (enable && !params->amsdu) |
929 msta->wcid.amsdu = false; 930 | 640 msta->wcid.amsdu = false; 641 |
931 skb = mt7921_mcu_alloc_sta_req(dev, mvif, msta, 932 MT7921_STA_UPDATE_MAX_SIZE); 933 if (IS_ERR(skb)) 934 return PTR_ERR(skb); 935 936 sta_wtbl = mt7921_mcu_add_tlv(skb, STA_REC_WTBL, sizeof(struct tlv)); 937 938 wtbl_hdr = mt7921_mcu_alloc_wtbl_req(dev, msta, WTBL_SET, sta_wtbl, 939 &skb); 940 mt7921_mcu_wtbl_ba_tlv(skb, params, enable, tx, sta_wtbl, wtbl_hdr); 941 942 ret = mt76_mcu_skb_send_msg(&dev->mt76, skb, cmd, true); 943 if (ret) 944 return ret; 945 946 skb = mt7921_mcu_alloc_sta_req(dev, mvif, msta, 947 MT7921_STA_UPDATE_MAX_SIZE); 948 if (IS_ERR(skb)) 949 return PTR_ERR(skb); 950 951 mt7921_mcu_sta_ba_tlv(skb, params, enable, tx); 952 953 return mt76_mcu_skb_send_msg(&dev->mt76, skb, cmd, true); | 642 return mt76_connac_mcu_sta_ba(&dev->mt76, &msta->vif->mt76, params, 643 enable, true); |
954} 955 | 644} 645 |
956int mt7921_mcu_uni_tx_ba(struct mt7921_dev *dev, 957 struct ieee80211_ampdu_params *params, 958 bool enable) 959{ 960 return mt7921_mcu_sta_ba(dev, params, enable, true, MCU_UNI_CMD_STA_REC_UPDATE); 961} 962 | |
963int mt7921_mcu_uni_rx_ba(struct mt7921_dev *dev, 964 struct ieee80211_ampdu_params *params, 965 bool enable) 966{ | 646int mt7921_mcu_uni_rx_ba(struct mt7921_dev *dev, 647 struct ieee80211_ampdu_params *params, 648 bool enable) 649{ |
967 return mt7921_mcu_sta_ba(dev, params, enable, false, MCU_UNI_CMD_STA_REC_UPDATE); 968} | 650 struct mt7921_sta *msta = (struct mt7921_sta *)params->sta->drv_priv; |
969 | 651 |
970static void 971mt7921_mcu_wtbl_generic_tlv(struct sk_buff *skb, struct ieee80211_vif *vif, 972 struct ieee80211_sta *sta, void *sta_wtbl, 973 void *wtbl_tlv) 974{ 975 struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv; 976 struct wtbl_generic *generic; 977 struct wtbl_rx *rx; 978 struct tlv *tlv; 979 980 tlv = mt7921_mcu_add_nested_tlv(skb, WTBL_GENERIC, sizeof(*generic), 981 wtbl_tlv, sta_wtbl); 982 983 generic = (struct wtbl_generic *)tlv; 984 985 if (sta) { 986 if (vif->type == NL80211_IFTYPE_STATION) 987 generic->partial_aid = cpu_to_le16(vif->bss_conf.aid); 988 else 989 generic->partial_aid = cpu_to_le16(sta->aid); 990 memcpy(generic->peer_addr, sta->addr, ETH_ALEN); 991 generic->muar_idx = mvif->mt76.omac_idx; 992 generic->qos = sta->wme; 993 } else { 994 /* use BSSID in station mode */ 995 if (vif->type == NL80211_IFTYPE_STATION) 996 memcpy(generic->peer_addr, vif->bss_conf.bssid, 997 ETH_ALEN); 998 else 999 eth_broadcast_addr(generic->peer_addr); 1000 1001 generic->muar_idx = 0xe; 1002 } 1003 1004 tlv = mt7921_mcu_add_nested_tlv(skb, WTBL_RX, sizeof(*rx), 1005 wtbl_tlv, sta_wtbl); 1006 1007 rx = (struct wtbl_rx *)tlv; 1008 rx->rca1 = sta ? vif->type != NL80211_IFTYPE_AP : 1; 1009 rx->rca2 = 1; 1010 rx->rv = 1; | 652 return mt76_connac_mcu_sta_ba(&dev->mt76, &msta->vif->mt76, params, 653 enable, false); |
1011} 1012 | 654} 655 |
1013static void 1014mt7921_mcu_sta_basic_tlv(struct sk_buff *skb, struct ieee80211_vif *vif, 1015 struct ieee80211_sta *sta, bool enable) 1016{ 1017#define EXTRA_INFO_VER BIT(0) 1018#define EXTRA_INFO_NEW BIT(1) 1019 struct sta_rec_basic *basic; 1020 struct tlv *tlv; 1021 int conn_type; 1022 1023 tlv = mt7921_mcu_add_tlv(skb, STA_REC_BASIC, sizeof(*basic)); 1024 1025 basic = (struct sta_rec_basic *)tlv; 1026 basic->extra_info = cpu_to_le16(EXTRA_INFO_VER); 1027 1028 if (enable) { 1029 basic->extra_info |= cpu_to_le16(EXTRA_INFO_NEW); 1030 basic->conn_state = CONN_STATE_PORT_SECURE; 1031 } else { 1032 basic->conn_state = CONN_STATE_DISCONNECT; 1033 } 1034 1035 if (!sta) { 1036 basic->conn_type = cpu_to_le32(CONNECTION_INFRA_BC); 1037 eth_broadcast_addr(basic->peer_addr); 1038 return; 1039 } 1040 1041 switch (vif->type) { 1042 case NL80211_IFTYPE_MESH_POINT: 1043 case NL80211_IFTYPE_AP: 1044 if (vif->p2p) 1045 conn_type = CONNECTION_P2P_GC; 1046 else 1047 conn_type = CONNECTION_INFRA_STA; 1048 basic->conn_type = cpu_to_le32(conn_type); 1049 basic->aid = cpu_to_le16(sta->aid); 1050 break; 1051 case NL80211_IFTYPE_STATION: 1052 if (vif->p2p) 1053 conn_type = CONNECTION_P2P_GO; 1054 else 1055 conn_type = CONNECTION_INFRA_AP; 1056 basic->conn_type = cpu_to_le32(conn_type); 1057 basic->aid = cpu_to_le16(vif->bss_conf.aid); 1058 break; 1059 case NL80211_IFTYPE_ADHOC: 1060 basic->conn_type = cpu_to_le32(CONNECTION_IBSS_ADHOC); 1061 basic->aid = cpu_to_le16(sta->aid); 1062 break; 1063 default: 1064 WARN_ON(1); 1065 break; 1066 } 1067 1068 memcpy(basic->peer_addr, sta->addr, ETH_ALEN); 1069 basic->qos = sta->wme; 1070} 1071 1072static void 1073mt7921_mcu_sta_he_tlv(struct sk_buff *skb, struct ieee80211_sta *sta) 1074{ 1075 struct ieee80211_sta_he_cap *he_cap = &sta->he_cap; 1076 struct ieee80211_he_cap_elem *elem = &he_cap->he_cap_elem; 1077 struct sta_rec_he *he; 1078 struct tlv *tlv; 1079 u32 cap = 0; 1080 1081 tlv = mt7921_mcu_add_tlv(skb, STA_REC_HE, sizeof(*he)); 1082 1083 he = (struct sta_rec_he *)tlv; 1084 1085 if (elem->mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_HTC_HE) 1086 cap |= STA_REC_HE_CAP_HTC; 1087 1088 if (elem->mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR) 1089 cap |= STA_REC_HE_CAP_BSR; 1090 1091 if (elem->mac_cap_info[3] & IEEE80211_HE_MAC_CAP3_OMI_CONTROL) 1092 cap |= STA_REC_HE_CAP_OM; 1093 1094 if (elem->mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_AMDSU_IN_AMPDU) 1095 cap |= STA_REC_HE_CAP_AMSDU_IN_AMPDU; 1096 1097 if (elem->mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR) 1098 cap |= STA_REC_HE_CAP_BQR; 1099 1100 if (elem->phy_cap_info[0] & 1101 (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G | 1102 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G)) 1103 cap |= STA_REC_HE_CAP_BW20_RU242_SUPPORT; 1104 1105 if (elem->phy_cap_info[1] & 1106 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD) 1107 cap |= STA_REC_HE_CAP_LDPC; 1108 1109 if (elem->phy_cap_info[1] & 1110 IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US) 1111 cap |= STA_REC_HE_CAP_SU_PPDU_1LTF_8US_GI; 1112 1113 if (elem->phy_cap_info[2] & 1114 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US) 1115 cap |= STA_REC_HE_CAP_NDP_4LTF_3DOT2MS_GI; 1116 1117 if (elem->phy_cap_info[2] & 1118 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ) 1119 cap |= STA_REC_HE_CAP_LE_EQ_80M_TX_STBC; 1120 1121 if (elem->phy_cap_info[2] & 1122 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ) 1123 cap |= STA_REC_HE_CAP_LE_EQ_80M_RX_STBC; 1124 1125 if (elem->phy_cap_info[6] & 1126 IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE) 1127 cap |= STA_REC_HE_CAP_PARTIAL_BW_EXT_RANGE; 1128 1129 if (elem->phy_cap_info[7] & 1130 IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI) 1131 cap |= STA_REC_HE_CAP_SU_MU_PPDU_4LTF_8US_GI; 1132 1133 if (elem->phy_cap_info[7] & 1134 IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ) 1135 cap |= STA_REC_HE_CAP_GT_80M_TX_STBC; 1136 1137 if (elem->phy_cap_info[7] & 1138 IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ) 1139 cap |= STA_REC_HE_CAP_GT_80M_RX_STBC; 1140 1141 if (elem->phy_cap_info[8] & 1142 IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI) 1143 cap |= STA_REC_HE_CAP_ER_SU_PPDU_4LTF_8US_GI; 1144 1145 if (elem->phy_cap_info[8] & 1146 IEEE80211_HE_PHY_CAP8_HE_ER_SU_1XLTF_AND_08_US_GI) 1147 cap |= STA_REC_HE_CAP_ER_SU_PPDU_1LTF_8US_GI; 1148 1149 if (elem->phy_cap_info[9] & 1150 IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK) 1151 cap |= STA_REC_HE_CAP_TRIG_CQI_FK; 1152 1153 if (elem->phy_cap_info[9] & 1154 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU) 1155 cap |= STA_REC_HE_CAP_TX_1024QAM_UNDER_RU242; 1156 1157 if (elem->phy_cap_info[9] & 1158 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU) 1159 cap |= STA_REC_HE_CAP_RX_1024QAM_UNDER_RU242; 1160 1161 he->he_cap = cpu_to_le32(cap); 1162 1163 switch (sta->bandwidth) { 1164 case IEEE80211_STA_RX_BW_160: 1165 if (elem->phy_cap_info[0] & 1166 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) 1167 he->max_nss_mcs[CMD_HE_MCS_BW8080] = 1168 he_cap->he_mcs_nss_supp.rx_mcs_80p80; 1169 1170 he->max_nss_mcs[CMD_HE_MCS_BW160] = 1171 he_cap->he_mcs_nss_supp.rx_mcs_160; 1172 fallthrough; 1173 default: 1174 he->max_nss_mcs[CMD_HE_MCS_BW80] = 1175 he_cap->he_mcs_nss_supp.rx_mcs_80; 1176 break; 1177 } 1178 1179 he->t_frame_dur = 1180 HE_MAC(CAP1_TF_MAC_PAD_DUR_MASK, elem->mac_cap_info[1]); 1181 he->max_ampdu_exp = 1182 HE_MAC(CAP3_MAX_AMPDU_LEN_EXP_MASK, elem->mac_cap_info[3]); 1183 1184 he->bw_set = 1185 HE_PHY(CAP0_CHANNEL_WIDTH_SET_MASK, elem->phy_cap_info[0]); 1186 he->device_class = 1187 HE_PHY(CAP1_DEVICE_CLASS_A, elem->phy_cap_info[1]); 1188 he->punc_pream_rx = 1189 HE_PHY(CAP1_PREAMBLE_PUNC_RX_MASK, elem->phy_cap_info[1]); 1190 1191 he->dcm_tx_mode = 1192 HE_PHY(CAP3_DCM_MAX_CONST_TX_MASK, elem->phy_cap_info[3]); 1193 he->dcm_tx_max_nss = 1194 HE_PHY(CAP3_DCM_MAX_TX_NSS_2, elem->phy_cap_info[3]); 1195 he->dcm_rx_mode = 1196 HE_PHY(CAP3_DCM_MAX_CONST_RX_MASK, elem->phy_cap_info[3]); 1197 he->dcm_rx_max_nss = 1198 HE_PHY(CAP3_DCM_MAX_RX_NSS_2, elem->phy_cap_info[3]); 1199 he->dcm_rx_max_nss = 1200 HE_PHY(CAP8_DCM_MAX_RU_MASK, elem->phy_cap_info[8]); 1201 1202 he->pkt_ext = 2; 1203} 1204 1205static void 1206mt7921_mcu_sta_uapsd_tlv(struct sk_buff *skb, struct ieee80211_sta *sta, 1207 struct ieee80211_vif *vif) 1208{ 1209 struct sta_rec_uapsd *uapsd; 1210 struct tlv *tlv; 1211 1212 if (vif->type != NL80211_IFTYPE_AP || !sta->wme) 1213 return; 1214 1215 tlv = mt7921_mcu_add_tlv(skb, STA_REC_APPS, sizeof(*uapsd)); 1216 uapsd = (struct sta_rec_uapsd *)tlv; 1217 1218 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) { 1219 uapsd->dac_map |= BIT(3); 1220 uapsd->tac_map |= BIT(3); 1221 } 1222 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) { 1223 uapsd->dac_map |= BIT(2); 1224 uapsd->tac_map |= BIT(2); 1225 } 1226 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) { 1227 uapsd->dac_map |= BIT(1); 1228 uapsd->tac_map |= BIT(1); 1229 } 1230 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) { 1231 uapsd->dac_map |= BIT(0); 1232 uapsd->tac_map |= BIT(0); 1233 } 1234 uapsd->max_sp = sta->max_sp; 1235} 1236 1237static void 1238mt7921_mcu_sta_amsdu_tlv(struct sk_buff *skb, struct ieee80211_sta *sta) 1239{ 1240 struct mt7921_sta *msta = (struct mt7921_sta *)sta->drv_priv; 1241 struct sta_rec_amsdu *amsdu; 1242 struct tlv *tlv; 1243 1244 if (!sta->max_amsdu_len) 1245 return; 1246 1247 tlv = mt7921_mcu_add_tlv(skb, STA_REC_HW_AMSDU, sizeof(*amsdu)); 1248 amsdu = (struct sta_rec_amsdu *)tlv; 1249 amsdu->max_amsdu_num = 8; 1250 amsdu->amsdu_en = true; 1251 amsdu->max_mpdu_size = sta->max_amsdu_len >= 1252 IEEE80211_MAX_MPDU_LEN_VHT_7991; 1253 msta->wcid.amsdu = true; 1254} 1255 1256static bool 1257mt7921_hw_amsdu_supported(struct ieee80211_vif *vif) 1258{ 1259 switch (vif->type) { 1260 case NL80211_IFTYPE_AP: 1261 case NL80211_IFTYPE_STATION: 1262 return true; 1263 default: 1264 return false; 1265 } 1266} 1267 1268static void 1269mt7921_mcu_sta_tlv(struct mt7921_dev *dev, struct sk_buff *skb, 1270 struct ieee80211_sta *sta, struct ieee80211_vif *vif) 1271{ 1272 struct tlv *tlv; 1273 struct sta_rec_state *state; 1274 struct sta_rec_phy *phy; 1275 struct sta_rec_ra_info *ra_info; 1276 struct cfg80211_chan_def *chandef = &dev->mphy.chandef; 1277 enum nl80211_band band = chandef->chan->band; 1278 1279 /* starec ht */ 1280 if (sta->ht_cap.ht_supported) { 1281 struct sta_rec_ht *ht; 1282 1283 tlv = mt7921_mcu_add_tlv(skb, STA_REC_HT, sizeof(*ht)); 1284 ht = (struct sta_rec_ht *)tlv; 1285 ht->ht_cap = cpu_to_le16(sta->ht_cap.cap); 1286 1287 if (mt7921_hw_amsdu_supported(vif)) 1288 mt7921_mcu_sta_amsdu_tlv(skb, sta); 1289 } 1290 1291 /* starec vht */ 1292 if (sta->vht_cap.vht_supported) { 1293 struct sta_rec_vht *vht; 1294 1295 tlv = mt7921_mcu_add_tlv(skb, STA_REC_VHT, sizeof(*vht)); 1296 vht = (struct sta_rec_vht *)tlv; 1297 vht->vht_cap = cpu_to_le32(sta->vht_cap.cap); 1298 vht->vht_rx_mcs_map = sta->vht_cap.vht_mcs.rx_mcs_map; 1299 vht->vht_tx_mcs_map = sta->vht_cap.vht_mcs.tx_mcs_map; 1300 } 1301 1302 /* starec he */ 1303 if (sta->he_cap.has_he) 1304 mt7921_mcu_sta_he_tlv(skb, sta); 1305 1306 /* starec uapsd */ 1307 mt7921_mcu_sta_uapsd_tlv(skb, sta, vif); 1308 1309 tlv = mt7921_mcu_add_tlv(skb, STA_REC_PHY, sizeof(*phy)); 1310 phy = (struct sta_rec_phy *)tlv; 1311 phy->phy_type = mt7921_get_phy_mode_v2(dev, vif, band, sta); 1312 phy->basic_rate = cpu_to_le16((u16)vif->bss_conf.basic_rates); 1313 1314 tlv = mt7921_mcu_add_tlv(skb, STA_REC_RA, sizeof(*ra_info)); 1315 ra_info = (struct sta_rec_ra_info *)tlv; 1316 ra_info->legacy = cpu_to_le16((u16)sta->supp_rates[band]); 1317 1318 if (sta->ht_cap.ht_supported) { 1319 memcpy(ra_info->rx_mcs_bitmask, sta->ht_cap.mcs.rx_mask, 1320 HT_MCS_MASK_NUM); 1321 } 1322 1323 tlv = mt7921_mcu_add_tlv(skb, STA_REC_STATE, sizeof(*state)); 1324 state = (struct sta_rec_state *)tlv; 1325 state->state = 2; 1326 1327 if (sta->vht_cap.vht_supported) { 1328 state->vht_opmode = sta->bandwidth; 1329 state->vht_opmode |= (sta->rx_nss - 1) << 1330 IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT; 1331 } 1332} 1333 1334static void 1335mt7921_mcu_wtbl_smps_tlv(struct sk_buff *skb, struct ieee80211_sta *sta, 1336 void *sta_wtbl, void *wtbl_tlv) 1337{ 1338 struct wtbl_smps *smps; 1339 struct tlv *tlv; 1340 1341 tlv = mt7921_mcu_add_nested_tlv(skb, WTBL_SMPS, sizeof(*smps), 1342 wtbl_tlv, sta_wtbl); 1343 smps = (struct wtbl_smps *)tlv; 1344 1345 if (sta->smps_mode == IEEE80211_SMPS_DYNAMIC) 1346 smps->smps = true; 1347} 1348 1349static void 1350mt7921_mcu_wtbl_ht_tlv(struct sk_buff *skb, struct ieee80211_sta *sta, 1351 void *sta_wtbl, void *wtbl_tlv) 1352{ 1353 struct wtbl_ht *ht = NULL; 1354 struct tlv *tlv; 1355 1356 /* wtbl ht */ 1357 if (sta->ht_cap.ht_supported) { 1358 tlv = mt7921_mcu_add_nested_tlv(skb, WTBL_HT, sizeof(*ht), 1359 wtbl_tlv, sta_wtbl); 1360 ht = (struct wtbl_ht *)tlv; 1361 ht->ldpc = !!(sta->ht_cap.cap & IEEE80211_HT_CAP_LDPC_CODING); 1362 ht->af = sta->ht_cap.ampdu_factor; 1363 ht->mm = sta->ht_cap.ampdu_density; 1364 ht->ht = true; 1365 } 1366 1367 /* wtbl vht */ 1368 if (sta->vht_cap.vht_supported) { 1369 struct wtbl_vht *vht; 1370 u8 af; 1371 1372 tlv = mt7921_mcu_add_nested_tlv(skb, WTBL_VHT, sizeof(*vht), 1373 wtbl_tlv, sta_wtbl); 1374 vht = (struct wtbl_vht *)tlv; 1375 vht->ldpc = !!(sta->vht_cap.cap & IEEE80211_VHT_CAP_RXLDPC); 1376 vht->vht = true; 1377 1378 af = FIELD_GET(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK, 1379 sta->vht_cap.cap); 1380 if (ht) 1381 ht->af = max_t(u8, ht->af, af); 1382 } 1383 1384 mt7921_mcu_wtbl_smps_tlv(skb, sta, sta_wtbl, wtbl_tlv); 1385} 1386 1387static int mt7921_mcu_start_firmware(struct mt7921_dev *dev, u32 addr, 1388 u32 option) 1389{ 1390 struct { 1391 __le32 option; 1392 __le32 addr; 1393 } req = { 1394 .option = cpu_to_le32(option), 1395 .addr = cpu_to_le32(addr), 1396 }; 1397 1398 return mt76_mcu_send_msg(&dev->mt76, MCU_CMD_FW_START_REQ, &req, 1399 sizeof(req), true); 1400} 1401 | |
1402static int mt7921_mcu_restart(struct mt76_dev *dev) 1403{ 1404 struct { 1405 u8 power_mode; 1406 u8 rsv[3]; 1407 } req = { 1408 .power_mode = 1, 1409 }; 1410 1411 return mt76_mcu_send_msg(dev, MCU_CMD_NIC_POWER_CTRL, &req, 1412 sizeof(req), false); 1413} 1414 | 656static int mt7921_mcu_restart(struct mt76_dev *dev) 657{ 658 struct { 659 u8 power_mode; 660 u8 rsv[3]; 661 } req = { 662 .power_mode = 1, 663 }; 664 665 return mt76_mcu_send_msg(dev, MCU_CMD_NIC_POWER_CTRL, &req, 666 sizeof(req), false); 667} 668 |
1415static int mt7921_mcu_patch_sem_ctrl(struct mt7921_dev *dev, bool get) 1416{ 1417 struct { 1418 __le32 op; 1419 } req = { 1420 .op = cpu_to_le32(get ? PATCH_SEM_GET : PATCH_SEM_RELEASE), 1421 }; 1422 1423 return mt76_mcu_send_msg(&dev->mt76, MCU_CMD_PATCH_SEM_CONTROL, &req, 1424 sizeof(req), true); 1425} 1426 1427static int mt7921_mcu_start_patch(struct mt7921_dev *dev) 1428{ 1429 struct { 1430 u8 check_crc; 1431 u8 reserved[3]; 1432 } req = { 1433 .check_crc = 0, 1434 }; 1435 1436 return mt76_mcu_send_msg(&dev->mt76, MCU_CMD_PATCH_FINISH_REQ, &req, 1437 sizeof(req), true); 1438} 1439 | |
1440static int mt7921_driver_own(struct mt7921_dev *dev) 1441{ 1442 u32 reg = mt7921_reg_map_l1(dev, MT_TOP_LPCR_HOST_BAND0); 1443 1444 mt76_wr(dev, reg, MT_TOP_LPCR_HOST_DRV_OWN); 1445 if (!mt76_poll_msec(dev, reg, MT_TOP_LPCR_HOST_FW_OWN, 1446 0, 500)) { 1447 dev_err(dev->mt76.dev, "Timeout for driver own\n"); 1448 return -EIO; 1449 } 1450 1451 return 0; 1452} 1453 | 669static int mt7921_driver_own(struct mt7921_dev *dev) 670{ 671 u32 reg = mt7921_reg_map_l1(dev, MT_TOP_LPCR_HOST_BAND0); 672 673 mt76_wr(dev, reg, MT_TOP_LPCR_HOST_DRV_OWN); 674 if (!mt76_poll_msec(dev, reg, MT_TOP_LPCR_HOST_FW_OWN, 675 0, 500)) { 676 dev_err(dev->mt76.dev, "Timeout for driver own\n"); 677 return -EIO; 678 } 679 680 return 0; 681} 682 |
1454static int mt7921_mcu_init_download(struct mt7921_dev *dev, u32 addr, 1455 u32 len, u32 mode) 1456{ 1457 struct { 1458 __le32 addr; 1459 __le32 len; 1460 __le32 mode; 1461 } req = { 1462 .addr = cpu_to_le32(addr), 1463 .len = cpu_to_le32(len), 1464 .mode = cpu_to_le32(mode), 1465 }; 1466 int attr; 1467 1468 if (req.addr == cpu_to_le32(MCU_PATCH_ADDRESS) || addr == 0x900000) 1469 attr = MCU_CMD_PATCH_START_REQ; 1470 else 1471 attr = MCU_CMD_TARGET_ADDRESS_LEN_REQ; 1472 1473 return mt76_mcu_send_msg(&dev->mt76, attr, &req, sizeof(req), true); 1474} 1475 | |
1476static int mt7921_load_patch(struct mt7921_dev *dev) 1477{ 1478 const struct mt7921_patch_hdr *hdr; 1479 const struct firmware *fw = NULL; 1480 int i, ret, sem; 1481 | 683static int mt7921_load_patch(struct mt7921_dev *dev) 684{ 685 const struct mt7921_patch_hdr *hdr; 686 const struct firmware *fw = NULL; 687 int i, ret, sem; 688 |
1482 sem = mt7921_mcu_patch_sem_ctrl(dev, 1); | 689 sem = mt76_connac_mcu_patch_sem_ctrl(&dev->mt76, true); |
1483 switch (sem) { 1484 case PATCH_IS_DL: 1485 return 0; 1486 case PATCH_NOT_DL_SEM_SUCCESS: 1487 break; 1488 default: 1489 dev_err(dev->mt76.dev, "Failed to get patch semaphore\n"); 1490 return -EAGAIN; --- 26 unchanged lines hidden (view full) --- 1517 ret = -EINVAL; 1518 goto out; 1519 } 1520 1521 addr = be32_to_cpu(sec->info.addr); 1522 len = be32_to_cpu(sec->info.len); 1523 dl = fw->data + be32_to_cpu(sec->offs); 1524 | 690 switch (sem) { 691 case PATCH_IS_DL: 692 return 0; 693 case PATCH_NOT_DL_SEM_SUCCESS: 694 break; 695 default: 696 dev_err(dev->mt76.dev, "Failed to get patch semaphore\n"); 697 return -EAGAIN; --- 26 unchanged lines hidden (view full) --- 724 ret = -EINVAL; 725 goto out; 726 } 727 728 addr = be32_to_cpu(sec->info.addr); 729 len = be32_to_cpu(sec->info.len); 730 dl = fw->data + be32_to_cpu(sec->offs); 731 |
1525 ret = mt7921_mcu_init_download(dev, addr, len, 1526 DL_MODE_NEED_RSP); | 732 ret = mt76_connac_mcu_init_download(&dev->mt76, addr, len, 733 DL_MODE_NEED_RSP); |
1527 if (ret) { 1528 dev_err(dev->mt76.dev, "Download request failed\n"); 1529 goto out; 1530 } 1531 1532 ret = mt76_mcu_send_firmware(&dev->mt76, MCU_CMD_FW_SCATTER, 1533 dl, len); 1534 if (ret) { 1535 dev_err(dev->mt76.dev, "Failed to send patch\n"); 1536 goto out; 1537 } 1538 } 1539 | 734 if (ret) { 735 dev_err(dev->mt76.dev, "Download request failed\n"); 736 goto out; 737 } 738 739 ret = mt76_mcu_send_firmware(&dev->mt76, MCU_CMD_FW_SCATTER, 740 dl, len); 741 if (ret) { 742 dev_err(dev->mt76.dev, "Failed to send patch\n"); 743 goto out; 744 } 745 } 746 |
1540 ret = mt7921_mcu_start_patch(dev); | 747 ret = mt76_connac_mcu_start_patch(&dev->mt76); |
1541 if (ret) 1542 dev_err(dev->mt76.dev, "Failed to start patch\n"); 1543 1544out: | 748 if (ret) 749 dev_err(dev->mt76.dev, "Failed to start patch\n"); 750 751out: |
1545 sem = mt7921_mcu_patch_sem_ctrl(dev, 0); | 752 sem = mt76_connac_mcu_patch_sem_ctrl(&dev->mt76, false); |
1546 switch (sem) { 1547 case PATCH_REL_SEM_SUCCESS: 1548 break; 1549 default: 1550 ret = -EAGAIN; 1551 dev_err(dev->mt76.dev, "Failed to release patch semaphore\n"); 1552 goto out; 1553 } --- 35 unchanged lines hidden (view full) --- 1589 (hdr->n_region - i) * sizeof(*region)); 1590 mode = mt7921_mcu_gen_dl_mode(region->feature_set, is_wa); 1591 len = le32_to_cpu(region->len); 1592 addr = le32_to_cpu(region->addr); 1593 1594 if (region->feature_set & FW_FEATURE_OVERRIDE_ADDR) 1595 override = addr; 1596 | 753 switch (sem) { 754 case PATCH_REL_SEM_SUCCESS: 755 break; 756 default: 757 ret = -EAGAIN; 758 dev_err(dev->mt76.dev, "Failed to release patch semaphore\n"); 759 goto out; 760 } --- 35 unchanged lines hidden (view full) --- 796 (hdr->n_region - i) * sizeof(*region)); 797 mode = mt7921_mcu_gen_dl_mode(region->feature_set, is_wa); 798 len = le32_to_cpu(region->len); 799 addr = le32_to_cpu(region->addr); 800 801 if (region->feature_set & FW_FEATURE_OVERRIDE_ADDR) 802 override = addr; 803 |
1597 err = mt7921_mcu_init_download(dev, addr, len, mode); | 804 err = mt76_connac_mcu_init_download(&dev->mt76, addr, len, 805 mode); |
1598 if (err) { 1599 dev_err(dev->mt76.dev, "Download request failed\n"); 1600 return err; 1601 } 1602 1603 err = mt76_mcu_send_firmware(&dev->mt76, MCU_CMD_FW_SCATTER, 1604 data + offset, len); 1605 if (err) { --- 5 unchanged lines hidden (view full) --- 1611 } 1612 1613 if (override) 1614 option |= FW_START_OVERRIDE; 1615 1616 if (is_wa) 1617 option |= FW_START_WORKING_PDA_CR4; 1618 | 806 if (err) { 807 dev_err(dev->mt76.dev, "Download request failed\n"); 808 return err; 809 } 810 811 err = mt76_mcu_send_firmware(&dev->mt76, MCU_CMD_FW_SCATTER, 812 data + offset, len); 813 if (err) { --- 5 unchanged lines hidden (view full) --- 819 } 820 821 if (override) 822 option |= FW_START_OVERRIDE; 823 824 if (is_wa) 825 option |= FW_START_WORKING_PDA_CR4; 826 |
1619 return mt7921_mcu_start_firmware(dev, override, option); | 827 return mt76_connac_mcu_start_firmware(&dev->mt76, override, option); |
1620} 1621 1622static int mt7921_load_ram(struct mt7921_dev *dev) 1623{ 1624 const struct mt7921_fw_trailer *hdr; 1625 const struct firmware *fw; 1626 int ret; 1627 --- 125 unchanged lines hidden (view full) --- 1753 return; 1754 } 1755 1756 reg = mt7921_reg_map_l1(dev, MT_TOP_LPCR_HOST_BAND0); 1757 mt76_wr(dev, reg, MT_TOP_LPCR_HOST_FW_OWN); 1758 skb_queue_purge(&dev->mt76.mcu.res_q); 1759} 1760 | 828} 829 830static int mt7921_load_ram(struct mt7921_dev *dev) 831{ 832 const struct mt7921_fw_trailer *hdr; 833 const struct firmware *fw; 834 int ret; 835 --- 125 unchanged lines hidden (view full) --- 961 return; 962 } 963 964 reg = mt7921_reg_map_l1(dev, MT_TOP_LPCR_HOST_BAND0); 965 mt76_wr(dev, reg, MT_TOP_LPCR_HOST_FW_OWN); 966 skb_queue_purge(&dev->mt76.mcu.res_q); 967} 968 |
1761int mt7921_mcu_set_mac(struct mt7921_dev *dev, int band, 1762 bool enable, bool hdr_trans) 1763{ 1764 struct { 1765 u8 enable; 1766 u8 band; 1767 u8 rsv[2]; 1768 } __packed req_mac = { 1769 .enable = enable, 1770 .band = band, 1771 }; 1772 1773 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_MAC_INIT_CTRL, 1774 &req_mac, sizeof(req_mac), true); 1775} 1776 1777int mt7921_mcu_set_rts_thresh(struct mt7921_phy *phy, u32 val) 1778{ 1779 struct mt7921_dev *dev = phy->dev; 1780 struct { 1781 u8 prot_idx; 1782 u8 band; 1783 u8 rsv[2]; 1784 __le32 len_thresh; 1785 __le32 pkt_thresh; 1786 } __packed req = { 1787 .prot_idx = 1, 1788 .band = phy != &dev->phy, 1789 .len_thresh = cpu_to_le32(val), 1790 .pkt_thresh = cpu_to_le32(0x2), 1791 }; 1792 1793 return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_PROTECT_CTRL, &req, 1794 sizeof(req), true); 1795} 1796 | |
1797int mt7921_mcu_set_tx(struct mt7921_dev *dev, struct ieee80211_vif *vif) 1798{ 1799#define WMM_AIFS_SET BIT(0) 1800#define WMM_CW_MIN_SET BIT(1) 1801#define WMM_CW_MAX_SET BIT(2) 1802#define WMM_TXOP_SET BIT(3) 1803#define WMM_PARAM_SET GENMASK(3, 0) 1804#define TX_CMD_MODE 1 --- 128 unchanged lines hidden (view full) --- 1933 res = (struct mt7921_mcu_eeprom_info *)skb->data; 1934 buf = dev->mt76.eeprom.data + le32_to_cpu(res->addr); 1935 memcpy(buf, res->data, 16); 1936 dev_kfree_skb(skb); 1937 1938 return 0; 1939} 1940 | 969int mt7921_mcu_set_tx(struct mt7921_dev *dev, struct ieee80211_vif *vif) 970{ 971#define WMM_AIFS_SET BIT(0) 972#define WMM_CW_MIN_SET BIT(1) 973#define WMM_CW_MAX_SET BIT(2) 974#define WMM_TXOP_SET BIT(3) 975#define WMM_PARAM_SET GENMASK(3, 0) 976#define TX_CMD_MODE 1 --- 128 unchanged lines hidden (view full) --- 1105 res = (struct mt7921_mcu_eeprom_info *)skb->data; 1106 buf = dev->mt76.eeprom.data + le32_to_cpu(res->addr); 1107 memcpy(buf, res->data, 16); 1108 dev_kfree_skb(skb); 1109 1110 return 0; 1111} 1112 |
1941int 1942mt7921_mcu_uni_add_dev(struct mt7921_dev *dev, 1943 struct ieee80211_vif *vif, bool enable) 1944{ 1945 struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv; 1946 u8 omac_idx = mvif->mt76.omac_idx; 1947 struct { 1948 struct { 1949 u8 omac_idx; 1950 u8 band_idx; 1951 __le16 pad; 1952 } __packed hdr; 1953 struct req_tlv { 1954 __le16 tag; 1955 __le16 len; 1956 u8 active; 1957 u8 pad; 1958 u8 omac_addr[ETH_ALEN]; 1959 } __packed tlv; 1960 } dev_req = { 1961 .hdr = { 1962 .omac_idx = omac_idx, 1963 .band_idx = mvif->mt76.band_idx, 1964 }, 1965 .tlv = { 1966 .tag = cpu_to_le16(DEV_INFO_ACTIVE), 1967 .len = cpu_to_le16(sizeof(struct req_tlv)), 1968 .active = enable, 1969 }, 1970 }; 1971 struct { 1972 struct { 1973 u8 bss_idx; 1974 u8 pad[3]; 1975 } __packed hdr; 1976 struct mt7921_bss_basic_tlv basic; 1977 } basic_req = { 1978 .hdr = { 1979 .bss_idx = mvif->mt76.idx, 1980 }, 1981 .basic = { 1982 .tag = cpu_to_le16(UNI_BSS_INFO_BASIC), 1983 .len = cpu_to_le16(sizeof(struct mt7921_bss_basic_tlv)), 1984 .omac_idx = omac_idx, 1985 .band_idx = mvif->mt76.band_idx, 1986 .wmm_idx = mvif->mt76.wmm_idx, 1987 .active = enable, 1988 .bmc_tx_wlan_idx = cpu_to_le16(mvif->sta.wcid.idx), 1989 .sta_idx = cpu_to_le16(mvif->sta.wcid.idx), 1990 .conn_state = 1, 1991 }, 1992 }; 1993 int err, idx, cmd, len; 1994 void *data; 1995 1996 switch (vif->type) { 1997 case NL80211_IFTYPE_MESH_POINT: 1998 case NL80211_IFTYPE_AP: 1999 basic_req.basic.conn_type = cpu_to_le32(CONNECTION_INFRA_AP); 2000 break; 2001 case NL80211_IFTYPE_STATION: 2002 basic_req.basic.conn_type = cpu_to_le32(CONNECTION_INFRA_STA); 2003 break; 2004 case NL80211_IFTYPE_ADHOC: 2005 basic_req.basic.conn_type = cpu_to_le32(CONNECTION_IBSS_ADHOC); 2006 break; 2007 default: 2008 WARN_ON(1); 2009 break; 2010 } 2011 2012 idx = omac_idx > EXT_BSSID_START ? HW_BSSID_0 : omac_idx; 2013 basic_req.basic.hw_bss_idx = idx; 2014 2015 memcpy(dev_req.tlv.omac_addr, vif->addr, ETH_ALEN); 2016 2017 cmd = enable ? MCU_UNI_CMD_DEV_INFO_UPDATE : MCU_UNI_CMD_BSS_INFO_UPDATE; 2018 data = enable ? (void *)&dev_req : (void *)&basic_req; 2019 len = enable ? sizeof(dev_req) : sizeof(basic_req); 2020 2021 err = mt76_mcu_send_msg(&dev->mt76, cmd, data, len, true); 2022 if (err < 0) 2023 return err; 2024 2025 cmd = enable ? MCU_UNI_CMD_BSS_INFO_UPDATE : MCU_UNI_CMD_DEV_INFO_UPDATE; 2026 data = enable ? (void *)&basic_req : (void *)&dev_req; 2027 len = enable ? sizeof(basic_req) : sizeof(dev_req); 2028 2029 return mt76_mcu_send_msg(&dev->mt76, cmd, data, len, true); 2030} 2031 2032int 2033mt7921_mcu_uni_add_bss(struct mt7921_phy *phy, struct ieee80211_vif *vif, 2034 bool enable) 2035{ 2036 struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv; 2037 struct cfg80211_chan_def *chandef = &phy->mt76->chandef; 2038 int freq1 = chandef->center_freq1, freq2 = chandef->center_freq2; 2039 struct mt7921_dev *dev = phy->dev; 2040 enum nl80211_band band = chandef->chan->band; 2041 u8 omac_idx = mvif->mt76.omac_idx; 2042 struct { 2043 struct { 2044 u8 bss_idx; 2045 u8 pad[3]; 2046 } __packed hdr; 2047 struct mt7921_bss_basic_tlv basic; 2048 struct mt7921_bss_qos_tlv qos; 2049 } basic_req = { 2050 .hdr = { 2051 .bss_idx = mvif->mt76.idx, 2052 }, 2053 .basic = { 2054 .tag = cpu_to_le16(UNI_BSS_INFO_BASIC), 2055 .len = cpu_to_le16(sizeof(struct mt7921_bss_basic_tlv)), 2056 .bcn_interval = cpu_to_le16(vif->bss_conf.beacon_int), 2057 .dtim_period = vif->bss_conf.dtim_period, 2058 .omac_idx = omac_idx, 2059 .band_idx = mvif->mt76.band_idx, 2060 .wmm_idx = mvif->mt76.wmm_idx, 2061 .active = true, /* keep bss deactivated */ 2062 .phymode = mt7921_get_phy_mode(phy->dev, vif, band, NULL), 2063 }, 2064 .qos = { 2065 .tag = cpu_to_le16(UNI_BSS_INFO_QBSS), 2066 .len = cpu_to_le16(sizeof(struct mt7921_bss_qos_tlv)), 2067 .qos = vif->bss_conf.qos, 2068 }, 2069 }; 2070 2071 struct { 2072 struct { 2073 u8 bss_idx; 2074 u8 pad[3]; 2075 } __packed hdr; 2076 struct bss_info_uni_he he; 2077 } he_req = { 2078 .hdr = { 2079 .bss_idx = mvif->mt76.idx, 2080 }, 2081 .he = { 2082 .tag = cpu_to_le16(UNI_BSS_INFO_HE_BASIC), 2083 .len = cpu_to_le16(sizeof(struct bss_info_uni_he)), 2084 }, 2085 }; 2086 2087 struct { 2088 struct { 2089 u8 bss_idx; 2090 u8 pad[3]; 2091 } __packed hdr; 2092 struct rlm_tlv { 2093 __le16 tag; 2094 __le16 len; 2095 u8 control_channel; 2096 u8 center_chan; 2097 u8 center_chan2; 2098 u8 bw; 2099 u8 tx_streams; 2100 u8 rx_streams; 2101 u8 short_st; 2102 u8 ht_op_info; 2103 u8 sco; 2104 u8 pad[3]; 2105 } __packed rlm; 2106 } __packed rlm_req = { 2107 .hdr = { 2108 .bss_idx = mvif->mt76.idx, 2109 }, 2110 .rlm = { 2111 .tag = cpu_to_le16(UNI_BSS_INFO_RLM), 2112 .len = cpu_to_le16(sizeof(struct rlm_tlv)), 2113 .control_channel = chandef->chan->hw_value, 2114 .center_chan = ieee80211_frequency_to_channel(freq1), 2115 .center_chan2 = ieee80211_frequency_to_channel(freq2), 2116 .tx_streams = hweight8(phy->mt76->antenna_mask), 2117 .rx_streams = phy->mt76->chainmask, 2118 .short_st = true, 2119 }, 2120 }; 2121 int err, conn_type; 2122 u8 idx; 2123 2124 idx = omac_idx > EXT_BSSID_START ? HW_BSSID_0 : omac_idx; 2125 basic_req.basic.hw_bss_idx = idx; 2126 2127 switch (vif->type) { 2128 case NL80211_IFTYPE_MESH_POINT: 2129 case NL80211_IFTYPE_AP: 2130 if (vif->p2p) 2131 conn_type = CONNECTION_P2P_GO; 2132 else 2133 conn_type = CONNECTION_INFRA_AP; 2134 basic_req.basic.conn_type = cpu_to_le32(conn_type); 2135 break; 2136 case NL80211_IFTYPE_STATION: 2137 if (vif->p2p) 2138 conn_type = CONNECTION_P2P_GC; 2139 else 2140 conn_type = CONNECTION_INFRA_STA; 2141 basic_req.basic.conn_type = cpu_to_le32(conn_type); 2142 break; 2143 case NL80211_IFTYPE_ADHOC: 2144 basic_req.basic.conn_type = cpu_to_le32(CONNECTION_IBSS_ADHOC); 2145 break; 2146 default: 2147 WARN_ON(1); 2148 break; 2149 } 2150 2151 memcpy(basic_req.basic.bssid, vif->bss_conf.bssid, ETH_ALEN); 2152 basic_req.basic.bmc_tx_wlan_idx = cpu_to_le16(mvif->sta.wcid.idx); 2153 basic_req.basic.sta_idx = cpu_to_le16(mvif->sta.wcid.idx); 2154 basic_req.basic.conn_state = !enable; 2155 2156 err = mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD_BSS_INFO_UPDATE, 2157 &basic_req, sizeof(basic_req), true); 2158 if (err < 0) 2159 return err; 2160 2161 if (vif->bss_conf.he_support) { 2162 mt7921_mcu_uni_bss_he_tlv((struct tlv *)&he_req.he, vif, phy); 2163 2164 err = mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD_BSS_INFO_UPDATE, 2165 &he_req, sizeof(he_req), true); 2166 if (err < 0) 2167 return err; 2168 } 2169 2170 switch (chandef->width) { 2171 case NL80211_CHAN_WIDTH_40: 2172 rlm_req.rlm.bw = CMD_CBW_40MHZ; 2173 break; 2174 case NL80211_CHAN_WIDTH_80: 2175 rlm_req.rlm.bw = CMD_CBW_80MHZ; 2176 break; 2177 case NL80211_CHAN_WIDTH_80P80: 2178 rlm_req.rlm.bw = CMD_CBW_8080MHZ; 2179 break; 2180 case NL80211_CHAN_WIDTH_160: 2181 rlm_req.rlm.bw = CMD_CBW_160MHZ; 2182 break; 2183 case NL80211_CHAN_WIDTH_5: 2184 rlm_req.rlm.bw = CMD_CBW_5MHZ; 2185 break; 2186 case NL80211_CHAN_WIDTH_10: 2187 rlm_req.rlm.bw = CMD_CBW_10MHZ; 2188 break; 2189 case NL80211_CHAN_WIDTH_20_NOHT: 2190 case NL80211_CHAN_WIDTH_20: 2191 default: 2192 rlm_req.rlm.bw = CMD_CBW_20MHZ; 2193 break; 2194 } 2195 2196 if (rlm_req.rlm.control_channel < rlm_req.rlm.center_chan) 2197 rlm_req.rlm.sco = 1; /* SCA */ 2198 else if (rlm_req.rlm.control_channel > rlm_req.rlm.center_chan) 2199 rlm_req.rlm.sco = 3; /* SCB */ 2200 2201 return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD_BSS_INFO_UPDATE, 2202 &rlm_req, sizeof(rlm_req), true); 2203} 2204 2205static int 2206mt7921_mcu_add_sta_cmd(struct mt7921_dev *dev, struct ieee80211_vif *vif, 2207 struct ieee80211_sta *sta, bool enable, int cmd) 2208{ 2209 struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv; 2210 struct wtbl_req_hdr *wtbl_hdr; 2211 struct mt7921_sta *msta; 2212 struct tlv *sta_wtbl; 2213 struct sk_buff *skb; 2214 2215 msta = sta ? (struct mt7921_sta *)sta->drv_priv : &mvif->sta; 2216 2217 skb = mt7921_mcu_alloc_sta_req(dev, mvif, msta, 2218 MT7921_STA_UPDATE_MAX_SIZE); 2219 if (IS_ERR(skb)) 2220 return PTR_ERR(skb); 2221 2222 mt7921_mcu_sta_basic_tlv(skb, vif, sta, enable); 2223 if (enable && sta) 2224 mt7921_mcu_sta_tlv(dev, skb, sta, vif); 2225 2226 sta_wtbl = mt7921_mcu_add_tlv(skb, STA_REC_WTBL, sizeof(struct tlv)); 2227 2228 wtbl_hdr = mt7921_mcu_alloc_wtbl_req(dev, msta, WTBL_RESET_AND_SET, 2229 sta_wtbl, &skb); 2230 if (enable) { 2231 mt7921_mcu_wtbl_generic_tlv(skb, vif, sta, sta_wtbl, wtbl_hdr); 2232 if (sta) 2233 mt7921_mcu_wtbl_ht_tlv(skb, sta, sta_wtbl, wtbl_hdr); 2234 } 2235 2236 return mt76_mcu_skb_send_msg(&dev->mt76, skb, cmd, true); 2237} 2238 2239int 2240mt7921_mcu_uni_add_sta(struct mt7921_dev *dev, struct ieee80211_vif *vif, 2241 struct ieee80211_sta *sta, bool enable) 2242{ 2243 return mt7921_mcu_add_sta_cmd(dev, vif, sta, enable, 2244 MCU_UNI_CMD_STA_REC_UPDATE); 2245} 2246 2247int mt7921_mcu_set_channel_domain(struct mt7921_phy *phy) 2248{ 2249 struct mt76_phy *mphy = phy->mt76; 2250 struct mt7921_dev *dev = phy->dev; 2251 struct mt7921_mcu_channel_domain { 2252 __le32 country_code; /* regulatory_request.alpha2 */ 2253 u8 bw_2g; /* BW_20_40M 0 2254 * BW_20M 1 2255 * BW_20_40_80M 2 2256 * BW_20_40_80_160M 3 2257 * BW_20_40_80_8080M 4 2258 */ 2259 u8 bw_5g; 2260 __le16 pad; 2261 u8 n_2ch; 2262 u8 n_5ch; 2263 __le16 pad2; 2264 } __packed hdr = { 2265 .bw_2g = 0, 2266 .bw_5g = 3, 2267 .n_2ch = mphy->sband_2g.sband.n_channels, 2268 .n_5ch = mphy->sband_5g.sband.n_channels, 2269 }; 2270 struct mt7921_mcu_chan { 2271 __le16 hw_value; 2272 __le16 pad; 2273 __le32 flags; 2274 } __packed; 2275 int i, n_channels = hdr.n_2ch + hdr.n_5ch; 2276 int len = sizeof(hdr) + n_channels * sizeof(struct mt7921_mcu_chan); 2277 struct sk_buff *skb; 2278 2279 skb = mt76_mcu_msg_alloc(&dev->mt76, NULL, len); 2280 if (!skb) 2281 return -ENOMEM; 2282 2283 skb_put_data(skb, &hdr, sizeof(hdr)); 2284 2285 for (i = 0; i < n_channels; i++) { 2286 struct ieee80211_channel *chan; 2287 struct mt7921_mcu_chan channel; 2288 2289 if (i < hdr.n_2ch) 2290 chan = &mphy->sband_2g.sband.channels[i]; 2291 else 2292 chan = &mphy->sband_5g.sband.channels[i - hdr.n_2ch]; 2293 2294 channel.hw_value = cpu_to_le16(chan->hw_value); 2295 channel.flags = cpu_to_le32(chan->flags); 2296 channel.pad = 0; 2297 2298 skb_put_data(skb, &channel, sizeof(channel)); 2299 } 2300 2301 return mt76_mcu_skb_send_msg(&dev->mt76, skb, MCU_CMD_SET_CHAN_DOMAIN, 2302 false); 2303} 2304 | |
2305#define MT7921_SCAN_CHANNEL_TIME 60 2306int mt7921_mcu_hw_scan(struct mt7921_phy *phy, struct ieee80211_vif *vif, 2307 struct ieee80211_scan_request *scan_req) 2308{ 2309 struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv; 2310 struct cfg80211_scan_request *sreq = &scan_req->req; 2311 int n_ssids = 0, err, i, duration = MT7921_SCAN_CHANNEL_TIME; 2312 int ext_channels_num = max_t(int, sreq->n_channels - 32, 0); --- 607 unchanged lines hidden --- | 1113#define MT7921_SCAN_CHANNEL_TIME 60 1114int mt7921_mcu_hw_scan(struct mt7921_phy *phy, struct ieee80211_vif *vif, 1115 struct ieee80211_scan_request *scan_req) 1116{ 1117 struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv; 1118 struct cfg80211_scan_request *sreq = &scan_req->req; 1119 int n_ssids = 0, err, i, duration = MT7921_SCAN_CHANNEL_TIME; 1120 int ext_channels_num = max_t(int, sreq->n_channels - 32, 0); --- 607 unchanged lines hidden --- |