1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2020 MediaTek Inc. */
4 #include "mt76_connac_mcu.h"
6 int mt76_connac_mcu_start_firmware(struct mt76_dev *dev, u32 addr, u32 option)
12 .option = cpu_to_le32(option),
13 .addr = cpu_to_le32(addr),
16 return mt76_mcu_send_msg(dev, MCU_CMD(FW_START_REQ), &req,
19 EXPORT_SYMBOL_GPL(mt76_connac_mcu_start_firmware);
21 int mt76_connac_mcu_patch_sem_ctrl(struct mt76_dev *dev, bool get)
23 u32 op = get ? PATCH_SEM_GET : PATCH_SEM_RELEASE;
27 .op = cpu_to_le32(op),
30 return mt76_mcu_send_msg(dev, MCU_CMD(PATCH_SEM_CONTROL),
31 &req, sizeof(req), true);
33 EXPORT_SYMBOL_GPL(mt76_connac_mcu_patch_sem_ctrl);
35 int mt76_connac_mcu_start_patch(struct mt76_dev *dev)
44 return mt76_mcu_send_msg(dev, MCU_CMD(PATCH_FINISH_REQ),
45 &req, sizeof(req), true);
47 EXPORT_SYMBOL_GPL(mt76_connac_mcu_start_patch);
49 #define MCU_PATCH_ADDRESS 0x200000
51 int mt76_connac_mcu_init_download(struct mt76_dev *dev, u32 addr, u32 len,
59 .addr = cpu_to_le32(addr),
60 .len = cpu_to_le32(len),
61 .mode = cpu_to_le32(mode),
65 if ((!is_connac_v1(dev) && addr == MCU_PATCH_ADDRESS) ||
66 (is_mt7921(dev) && addr == 0x900000))
67 cmd = MCU_CMD(PATCH_START_REQ);
69 cmd = MCU_CMD(TARGET_ADDRESS_LEN_REQ);
71 return mt76_mcu_send_msg(dev, cmd, &req, sizeof(req), true);
73 EXPORT_SYMBOL_GPL(mt76_connac_mcu_init_download);
75 int mt76_connac_mcu_set_channel_domain(struct mt76_phy *phy)
77 int len, i, n_max_channels, n_2ch = 0, n_5ch = 0, n_6ch = 0;
78 struct mt76_connac_mcu_channel_domain {
79 u8 alpha2[4]; /* regulatory_request.alpha2 */
80 u8 bw_2g; /* BW_20_40M 0
95 .bw_5g = 3, /* BW_20_40_80_160M */
98 struct mt76_connac_mcu_chan {
103 struct mt76_dev *dev = phy->dev;
104 struct ieee80211_channel *chan;
107 n_max_channels = phy->sband_2g.sband.n_channels +
108 phy->sband_5g.sband.n_channels +
109 phy->sband_6g.sband.n_channels;
110 len = sizeof(hdr) + n_max_channels * sizeof(channel);
112 skb = mt76_mcu_msg_alloc(dev, NULL, len);
116 skb_reserve(skb, sizeof(hdr));
118 for (i = 0; i < phy->sband_2g.sband.n_channels; i++) {
119 chan = &phy->sband_2g.sband.channels[i];
120 if (chan->flags & IEEE80211_CHAN_DISABLED)
123 channel.hw_value = cpu_to_le16(chan->hw_value);
124 channel.flags = cpu_to_le32(chan->flags);
127 skb_put_data(skb, &channel, sizeof(channel));
130 for (i = 0; i < phy->sband_5g.sband.n_channels; i++) {
131 chan = &phy->sband_5g.sband.channels[i];
132 if (chan->flags & IEEE80211_CHAN_DISABLED)
135 channel.hw_value = cpu_to_le16(chan->hw_value);
136 channel.flags = cpu_to_le32(chan->flags);
139 skb_put_data(skb, &channel, sizeof(channel));
142 for (i = 0; i < phy->sband_6g.sband.n_channels; i++) {
143 chan = &phy->sband_6g.sband.channels[i];
144 if (chan->flags & IEEE80211_CHAN_DISABLED)
147 channel.hw_value = cpu_to_le16(chan->hw_value);
148 channel.flags = cpu_to_le32(chan->flags);
151 skb_put_data(skb, &channel, sizeof(channel));
155 BUILD_BUG_ON(sizeof(dev->alpha2) > sizeof(hdr.alpha2));
156 memcpy(hdr.alpha2, dev->alpha2, sizeof(dev->alpha2));
161 memcpy(__skb_push(skb, sizeof(hdr)), &hdr, sizeof(hdr));
163 return mt76_mcu_skb_send_msg(dev, skb, MCU_CE_CMD(SET_CHAN_DOMAIN),
166 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_channel_domain);
168 int mt76_connac_mcu_set_mac_enable(struct mt76_dev *dev, int band, bool enable,
175 } __packed req_mac = {
180 return mt76_mcu_send_msg(dev, MCU_EXT_CMD(MAC_INIT_CTRL), &req_mac,
181 sizeof(req_mac), true);
183 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_mac_enable);
185 int mt76_connac_mcu_set_vif_ps(struct mt76_dev *dev, struct ieee80211_vif *vif)
187 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
190 u8 ps_state; /* 0: device awake
191 * 1: static power save
192 * 2: dynamic power saving
195 .bss_idx = mvif->idx,
196 .ps_state = vif->bss_conf.ps ? 2 : 0,
199 if (vif->type != NL80211_IFTYPE_STATION)
202 return mt76_mcu_send_msg(dev, MCU_CE_CMD(SET_PS_PROFILE),
203 &req, sizeof(req), false);
205 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_vif_ps);
207 int mt76_connac_mcu_set_rts_thresh(struct mt76_dev *dev, u32 val, u8 band)
218 .len_thresh = cpu_to_le32(val),
219 .pkt_thresh = cpu_to_le32(0x2),
222 return mt76_mcu_send_msg(dev, MCU_EXT_CMD(PROTECT_CTRL), &req,
225 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_rts_thresh);
227 void mt76_connac_mcu_beacon_loss_iter(void *priv, u8 *mac,
228 struct ieee80211_vif *vif)
230 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
231 struct mt76_connac_beacon_loss_event *event = priv;
233 if (mvif->idx != event->bss_idx)
236 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
239 ieee80211_beacon_loss(vif);
241 EXPORT_SYMBOL_GPL(mt76_connac_mcu_beacon_loss_iter);
244 mt76_connac_mcu_add_nested_tlv(struct sk_buff *skb, int tag, int len,
245 void *sta_ntlv, void *sta_wtbl)
247 struct sta_ntlv_hdr *ntlv_hdr = sta_ntlv;
248 struct tlv *sta_hdr = sta_wtbl;
249 struct tlv *ptlv, tlv = {
250 .tag = cpu_to_le16(tag),
251 .len = cpu_to_le16(len),
255 ptlv = skb_put(skb, len);
256 memcpy(ptlv, &tlv, sizeof(tlv));
258 ntlv = le16_to_cpu(ntlv_hdr->tlv_num);
259 ntlv_hdr->tlv_num = cpu_to_le16(ntlv + 1);
262 le16_add_cpu(&sta_hdr->len, len);
266 EXPORT_SYMBOL_GPL(mt76_connac_mcu_add_nested_tlv);
269 __mt76_connac_mcu_alloc_sta_req(struct mt76_dev *dev, struct mt76_vif *mvif,
270 struct mt76_wcid *wcid, int len)
272 struct sta_req_hdr hdr = {
273 .bss_idx = mvif->idx,
274 .muar_idx = wcid ? mvif->omac_idx : 0,
279 mt76_connac_mcu_get_wlan_idx(dev, wcid, &hdr.wlan_idx_lo,
281 skb = mt76_mcu_msg_alloc(dev, NULL, len);
283 return ERR_PTR(-ENOMEM);
285 skb_put_data(skb, &hdr, sizeof(hdr));
289 EXPORT_SYMBOL_GPL(__mt76_connac_mcu_alloc_sta_req);
291 struct wtbl_req_hdr *
292 mt76_connac_mcu_alloc_wtbl_req(struct mt76_dev *dev, struct mt76_wcid *wcid,
293 int cmd, void *sta_wtbl, struct sk_buff **skb)
295 struct tlv *sta_hdr = sta_wtbl;
296 struct wtbl_req_hdr hdr = {
299 struct sk_buff *nskb = *skb;
301 mt76_connac_mcu_get_wlan_idx(dev, wcid, &hdr.wlan_idx_lo,
304 nskb = mt76_mcu_msg_alloc(dev, NULL,
305 MT76_CONNAC_WTBL_UPDATE_MAX_SIZE);
307 return ERR_PTR(-ENOMEM);
313 le16_add_cpu(&sta_hdr->len, sizeof(hdr));
315 return skb_put_data(nskb, &hdr, sizeof(hdr));
317 EXPORT_SYMBOL_GPL(mt76_connac_mcu_alloc_wtbl_req);
319 void mt76_connac_mcu_bss_omac_tlv(struct sk_buff *skb,
320 struct ieee80211_vif *vif)
322 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
323 u8 omac_idx = mvif->omac_idx;
324 struct bss_info_omac *omac;
329 case NL80211_IFTYPE_MONITOR:
330 case NL80211_IFTYPE_MESH_POINT:
331 case NL80211_IFTYPE_AP:
333 type = CONNECTION_P2P_GO;
335 type = CONNECTION_INFRA_AP;
337 case NL80211_IFTYPE_STATION:
339 type = CONNECTION_P2P_GC;
341 type = CONNECTION_INFRA_STA;
343 case NL80211_IFTYPE_ADHOC:
344 type = CONNECTION_IBSS_ADHOC;
351 tlv = mt76_connac_mcu_add_tlv(skb, BSS_INFO_OMAC, sizeof(*omac));
353 omac = (struct bss_info_omac *)tlv;
354 omac->conn_type = cpu_to_le32(type);
355 omac->omac_idx = mvif->omac_idx;
356 omac->band_idx = mvif->band_idx;
357 omac->hw_bss_idx = omac_idx > EXT_BSSID_START ? HW_BSSID_0 : omac_idx;
359 EXPORT_SYMBOL_GPL(mt76_connac_mcu_bss_omac_tlv);
361 void mt76_connac_mcu_sta_basic_tlv(struct sk_buff *skb,
362 struct ieee80211_vif *vif,
363 struct ieee80211_sta *sta,
364 bool enable, bool newly)
366 struct sta_rec_basic *basic;
370 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_BASIC, sizeof(*basic));
372 basic = (struct sta_rec_basic *)tlv;
373 basic->extra_info = cpu_to_le16(EXTRA_INFO_VER);
377 basic->extra_info |= cpu_to_le16(EXTRA_INFO_NEW);
378 basic->conn_state = CONN_STATE_PORT_SECURE;
380 basic->conn_state = CONN_STATE_DISCONNECT;
384 basic->conn_type = cpu_to_le32(CONNECTION_INFRA_BC);
385 eth_broadcast_addr(basic->peer_addr);
390 case NL80211_IFTYPE_MESH_POINT:
391 case NL80211_IFTYPE_AP:
393 conn_type = CONNECTION_P2P_GC;
395 conn_type = CONNECTION_INFRA_STA;
396 basic->conn_type = cpu_to_le32(conn_type);
397 basic->aid = cpu_to_le16(sta->aid);
399 case NL80211_IFTYPE_STATION:
401 conn_type = CONNECTION_P2P_GO;
403 conn_type = CONNECTION_INFRA_AP;
404 basic->conn_type = cpu_to_le32(conn_type);
405 basic->aid = cpu_to_le16(vif->bss_conf.aid);
407 case NL80211_IFTYPE_ADHOC:
408 basic->conn_type = cpu_to_le32(CONNECTION_IBSS_ADHOC);
409 basic->aid = cpu_to_le16(sta->aid);
416 memcpy(basic->peer_addr, sta->addr, ETH_ALEN);
417 basic->qos = sta->wme;
419 EXPORT_SYMBOL_GPL(mt76_connac_mcu_sta_basic_tlv);
421 void mt76_connac_mcu_sta_uapsd(struct sk_buff *skb, struct ieee80211_vif *vif,
422 struct ieee80211_sta *sta)
424 struct sta_rec_uapsd *uapsd;
427 if (vif->type != NL80211_IFTYPE_AP || !sta->wme)
430 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_APPS, sizeof(*uapsd));
431 uapsd = (struct sta_rec_uapsd *)tlv;
433 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) {
434 uapsd->dac_map |= BIT(3);
435 uapsd->tac_map |= BIT(3);
437 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) {
438 uapsd->dac_map |= BIT(2);
439 uapsd->tac_map |= BIT(2);
441 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) {
442 uapsd->dac_map |= BIT(1);
443 uapsd->tac_map |= BIT(1);
445 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) {
446 uapsd->dac_map |= BIT(0);
447 uapsd->tac_map |= BIT(0);
449 uapsd->max_sp = sta->max_sp;
451 EXPORT_SYMBOL_GPL(mt76_connac_mcu_sta_uapsd);
453 void mt76_connac_mcu_wtbl_hdr_trans_tlv(struct sk_buff *skb,
454 struct ieee80211_vif *vif,
455 struct mt76_wcid *wcid,
456 void *sta_wtbl, void *wtbl_tlv)
458 struct wtbl_hdr_trans *htr;
461 tlv = mt76_connac_mcu_add_nested_tlv(skb, WTBL_HDR_TRANS,
464 htr = (struct wtbl_hdr_trans *)tlv;
465 htr->no_rx_trans = true;
467 if (vif->type == NL80211_IFTYPE_STATION)
475 htr->no_rx_trans = !test_bit(MT_WCID_FLAG_HDR_TRANS, &wcid->flags);
476 if (test_bit(MT_WCID_FLAG_4ADDR, &wcid->flags)) {
481 EXPORT_SYMBOL_GPL(mt76_connac_mcu_wtbl_hdr_trans_tlv);
483 int mt76_connac_mcu_sta_update_hdr_trans(struct mt76_dev *dev,
484 struct ieee80211_vif *vif,
485 struct mt76_wcid *wcid, int cmd)
487 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
488 struct wtbl_req_hdr *wtbl_hdr;
489 struct tlv *sta_wtbl;
492 skb = mt76_connac_mcu_alloc_sta_req(dev, mvif, wcid);
496 sta_wtbl = mt76_connac_mcu_add_tlv(skb, STA_REC_WTBL,
499 wtbl_hdr = mt76_connac_mcu_alloc_wtbl_req(dev, wcid, WTBL_SET,
501 if (IS_ERR(wtbl_hdr))
502 return PTR_ERR(wtbl_hdr);
504 mt76_connac_mcu_wtbl_hdr_trans_tlv(skb, vif, wcid, sta_wtbl, wtbl_hdr);
506 return mt76_mcu_skb_send_msg(dev, skb, cmd, true);
508 EXPORT_SYMBOL_GPL(mt76_connac_mcu_sta_update_hdr_trans);
510 int mt76_connac_mcu_wtbl_update_hdr_trans(struct mt76_dev *dev,
511 struct ieee80211_vif *vif,
512 struct ieee80211_sta *sta)
514 struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
515 struct wtbl_req_hdr *wtbl_hdr;
516 struct sk_buff *skb = NULL;
518 wtbl_hdr = mt76_connac_mcu_alloc_wtbl_req(dev, wcid, WTBL_SET, NULL,
520 if (IS_ERR(wtbl_hdr))
521 return PTR_ERR(wtbl_hdr);
523 mt76_connac_mcu_wtbl_hdr_trans_tlv(skb, vif, wcid, NULL, wtbl_hdr);
525 return mt76_mcu_skb_send_msg(dev, skb, MCU_EXT_CMD(WTBL_UPDATE), true);
527 EXPORT_SYMBOL_GPL(mt76_connac_mcu_wtbl_update_hdr_trans);
529 void mt76_connac_mcu_wtbl_generic_tlv(struct mt76_dev *dev,
531 struct ieee80211_vif *vif,
532 struct ieee80211_sta *sta,
533 void *sta_wtbl, void *wtbl_tlv)
535 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
536 struct wtbl_generic *generic;
538 struct wtbl_spe *spe;
541 tlv = mt76_connac_mcu_add_nested_tlv(skb, WTBL_GENERIC,
545 generic = (struct wtbl_generic *)tlv;
548 if (vif->type == NL80211_IFTYPE_STATION)
549 generic->partial_aid = cpu_to_le16(vif->bss_conf.aid);
551 generic->partial_aid = cpu_to_le16(sta->aid);
552 memcpy(generic->peer_addr, sta->addr, ETH_ALEN);
553 generic->muar_idx = mvif->omac_idx;
554 generic->qos = sta->wme;
556 if (!is_connac_v1(dev) && vif->type == NL80211_IFTYPE_STATION)
557 memcpy(generic->peer_addr, vif->bss_conf.bssid,
560 eth_broadcast_addr(generic->peer_addr);
562 generic->muar_idx = 0xe;
565 tlv = mt76_connac_mcu_add_nested_tlv(skb, WTBL_RX, sizeof(*rx),
568 rx = (struct wtbl_rx *)tlv;
569 rx->rca1 = sta ? vif->type != NL80211_IFTYPE_AP : 1;
573 if (!is_connac_v1(dev))
576 tlv = mt76_connac_mcu_add_nested_tlv(skb, WTBL_SPE, sizeof(*spe),
578 spe = (struct wtbl_spe *)tlv;
581 EXPORT_SYMBOL_GPL(mt76_connac_mcu_wtbl_generic_tlv);
584 mt76_connac_mcu_sta_amsdu_tlv(struct sk_buff *skb, struct ieee80211_sta *sta,
585 struct ieee80211_vif *vif)
587 struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
588 struct sta_rec_amsdu *amsdu;
591 if (vif->type != NL80211_IFTYPE_AP &&
592 vif->type != NL80211_IFTYPE_STATION)
595 if (!sta->max_amsdu_len)
598 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HW_AMSDU, sizeof(*amsdu));
599 amsdu = (struct sta_rec_amsdu *)tlv;
600 amsdu->max_amsdu_num = 8;
601 amsdu->amsdu_en = true;
602 amsdu->max_mpdu_size = sta->max_amsdu_len >=
603 IEEE80211_MAX_MPDU_LEN_VHT_7991;
608 #define HE_PHY(p, c) u8_get_bits(c, IEEE80211_HE_PHY_##p)
609 #define HE_MAC(m, c) u8_get_bits(c, IEEE80211_HE_MAC_##m)
611 mt76_connac_mcu_sta_he_tlv(struct sk_buff *skb, struct ieee80211_sta *sta)
613 struct ieee80211_sta_he_cap *he_cap = &sta->deflink.he_cap;
614 struct ieee80211_he_cap_elem *elem = &he_cap->he_cap_elem;
615 struct sta_rec_he *he;
619 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HE, sizeof(*he));
621 he = (struct sta_rec_he *)tlv;
623 if (elem->mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_HTC_HE)
624 cap |= STA_REC_HE_CAP_HTC;
626 if (elem->mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
627 cap |= STA_REC_HE_CAP_BSR;
629 if (elem->mac_cap_info[3] & IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
630 cap |= STA_REC_HE_CAP_OM;
632 if (elem->mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU)
633 cap |= STA_REC_HE_CAP_AMSDU_IN_AMPDU;
635 if (elem->mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
636 cap |= STA_REC_HE_CAP_BQR;
638 if (elem->phy_cap_info[0] &
639 (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G |
640 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G))
641 cap |= STA_REC_HE_CAP_BW20_RU242_SUPPORT;
643 if (elem->phy_cap_info[1] &
644 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD)
645 cap |= STA_REC_HE_CAP_LDPC;
647 if (elem->phy_cap_info[1] &
648 IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US)
649 cap |= STA_REC_HE_CAP_SU_PPDU_1LTF_8US_GI;
651 if (elem->phy_cap_info[2] &
652 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US)
653 cap |= STA_REC_HE_CAP_NDP_4LTF_3DOT2MS_GI;
655 if (elem->phy_cap_info[2] &
656 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ)
657 cap |= STA_REC_HE_CAP_LE_EQ_80M_TX_STBC;
659 if (elem->phy_cap_info[2] &
660 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ)
661 cap |= STA_REC_HE_CAP_LE_EQ_80M_RX_STBC;
663 if (elem->phy_cap_info[6] &
664 IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE)
665 cap |= STA_REC_HE_CAP_PARTIAL_BW_EXT_RANGE;
667 if (elem->phy_cap_info[7] &
668 IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI)
669 cap |= STA_REC_HE_CAP_SU_MU_PPDU_4LTF_8US_GI;
671 if (elem->phy_cap_info[7] &
672 IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ)
673 cap |= STA_REC_HE_CAP_GT_80M_TX_STBC;
675 if (elem->phy_cap_info[7] &
676 IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ)
677 cap |= STA_REC_HE_CAP_GT_80M_RX_STBC;
679 if (elem->phy_cap_info[8] &
680 IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI)
681 cap |= STA_REC_HE_CAP_ER_SU_PPDU_4LTF_8US_GI;
683 if (elem->phy_cap_info[8] &
684 IEEE80211_HE_PHY_CAP8_HE_ER_SU_1XLTF_AND_08_US_GI)
685 cap |= STA_REC_HE_CAP_ER_SU_PPDU_1LTF_8US_GI;
687 if (elem->phy_cap_info[9] &
688 IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK)
689 cap |= STA_REC_HE_CAP_TRIG_CQI_FK;
691 if (elem->phy_cap_info[9] &
692 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU)
693 cap |= STA_REC_HE_CAP_TX_1024QAM_UNDER_RU242;
695 if (elem->phy_cap_info[9] &
696 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU)
697 cap |= STA_REC_HE_CAP_RX_1024QAM_UNDER_RU242;
699 he->he_cap = cpu_to_le32(cap);
701 switch (sta->deflink.bandwidth) {
702 case IEEE80211_STA_RX_BW_160:
703 if (elem->phy_cap_info[0] &
704 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)
705 he->max_nss_mcs[CMD_HE_MCS_BW8080] =
706 he_cap->he_mcs_nss_supp.rx_mcs_80p80;
708 he->max_nss_mcs[CMD_HE_MCS_BW160] =
709 he_cap->he_mcs_nss_supp.rx_mcs_160;
712 he->max_nss_mcs[CMD_HE_MCS_BW80] =
713 he_cap->he_mcs_nss_supp.rx_mcs_80;
718 HE_MAC(CAP1_TF_MAC_PAD_DUR_MASK, elem->mac_cap_info[1]);
720 HE_MAC(CAP3_MAX_AMPDU_LEN_EXP_MASK, elem->mac_cap_info[3]);
723 HE_PHY(CAP0_CHANNEL_WIDTH_SET_MASK, elem->phy_cap_info[0]);
725 HE_PHY(CAP1_DEVICE_CLASS_A, elem->phy_cap_info[1]);
727 HE_PHY(CAP1_PREAMBLE_PUNC_RX_MASK, elem->phy_cap_info[1]);
730 HE_PHY(CAP3_DCM_MAX_CONST_TX_MASK, elem->phy_cap_info[3]);
732 HE_PHY(CAP3_DCM_MAX_TX_NSS_2, elem->phy_cap_info[3]);
734 HE_PHY(CAP3_DCM_MAX_CONST_RX_MASK, elem->phy_cap_info[3]);
736 HE_PHY(CAP3_DCM_MAX_RX_NSS_2, elem->phy_cap_info[3]);
738 HE_PHY(CAP8_DCM_MAX_RU_MASK, elem->phy_cap_info[8]);
744 mt76_connac_get_phy_mode_v2(struct mt76_phy *mphy, struct ieee80211_vif *vif,
745 enum nl80211_band band, struct ieee80211_sta *sta)
747 struct ieee80211_sta_ht_cap *ht_cap;
748 struct ieee80211_sta_vht_cap *vht_cap;
749 const struct ieee80211_sta_he_cap *he_cap;
753 ht_cap = &sta->deflink.ht_cap;
754 vht_cap = &sta->deflink.vht_cap;
755 he_cap = &sta->deflink.he_cap;
757 struct ieee80211_supported_band *sband;
759 sband = mphy->hw->wiphy->bands[band];
760 ht_cap = &sband->ht_cap;
761 vht_cap = &sband->vht_cap;
762 he_cap = ieee80211_get_he_iftype_cap(sband, vif->type);
765 if (band == NL80211_BAND_2GHZ) {
766 mode |= PHY_TYPE_BIT_HR_DSSS | PHY_TYPE_BIT_ERP;
768 if (ht_cap->ht_supported)
769 mode |= PHY_TYPE_BIT_HT;
771 if (he_cap && he_cap->has_he)
772 mode |= PHY_TYPE_BIT_HE;
773 } else if (band == NL80211_BAND_5GHZ || band == NL80211_BAND_6GHZ) {
774 mode |= PHY_TYPE_BIT_OFDM;
776 if (ht_cap->ht_supported)
777 mode |= PHY_TYPE_BIT_HT;
779 if (vht_cap->vht_supported)
780 mode |= PHY_TYPE_BIT_VHT;
782 if (he_cap && he_cap->has_he)
783 mode |= PHY_TYPE_BIT_HE;
789 void mt76_connac_mcu_sta_tlv(struct mt76_phy *mphy, struct sk_buff *skb,
790 struct ieee80211_sta *sta,
791 struct ieee80211_vif *vif,
792 u8 rcpi, u8 sta_state)
794 struct cfg80211_chan_def *chandef = &mphy->chandef;
795 enum nl80211_band band = chandef->chan->band;
796 struct mt76_dev *dev = mphy->dev;
797 struct sta_rec_ra_info *ra_info;
798 struct sta_rec_state *state;
799 struct sta_rec_phy *phy;
804 if (sta->deflink.ht_cap.ht_supported) {
805 struct sta_rec_ht *ht;
807 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HT, sizeof(*ht));
808 ht = (struct sta_rec_ht *)tlv;
809 ht->ht_cap = cpu_to_le16(sta->deflink.ht_cap.cap);
813 if (sta->deflink.vht_cap.vht_supported) {
814 struct sta_rec_vht *vht;
817 len = is_mt7921(dev) ? sizeof(*vht) : sizeof(*vht) - 4;
818 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_VHT, len);
819 vht = (struct sta_rec_vht *)tlv;
820 vht->vht_cap = cpu_to_le32(sta->deflink.vht_cap.cap);
821 vht->vht_rx_mcs_map = sta->deflink.vht_cap.vht_mcs.rx_mcs_map;
822 vht->vht_tx_mcs_map = sta->deflink.vht_cap.vht_mcs.tx_mcs_map;
826 mt76_connac_mcu_sta_uapsd(skb, vif, sta);
831 if (sta->deflink.ht_cap.ht_supported || sta->deflink.he_cap.has_he)
832 mt76_connac_mcu_sta_amsdu_tlv(skb, sta, vif);
835 if (sta->deflink.he_cap.has_he) {
836 mt76_connac_mcu_sta_he_tlv(skb, sta);
837 if (band == NL80211_BAND_6GHZ &&
838 sta_state == MT76_STA_INFO_STATE_ASSOC) {
839 struct sta_rec_he_6g_capa *he_6g_capa;
841 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HE_6G,
842 sizeof(*he_6g_capa));
843 he_6g_capa = (struct sta_rec_he_6g_capa *)tlv;
844 he_6g_capa->capa = sta->deflink.he_6ghz_capa.capa;
848 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_PHY, sizeof(*phy));
849 phy = (struct sta_rec_phy *)tlv;
850 phy->phy_type = mt76_connac_get_phy_mode_v2(mphy, vif, band, sta);
851 phy->basic_rate = cpu_to_le16((u16)vif->bss_conf.basic_rates);
853 phy->ampdu = FIELD_PREP(IEEE80211_HT_AMPDU_PARM_FACTOR,
854 sta->deflink.ht_cap.ampdu_factor) |
855 FIELD_PREP(IEEE80211_HT_AMPDU_PARM_DENSITY,
856 sta->deflink.ht_cap.ampdu_density);
858 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_RA, sizeof(*ra_info));
859 ra_info = (struct sta_rec_ra_info *)tlv;
861 supp_rates = sta->deflink.supp_rates[band];
862 if (band == NL80211_BAND_2GHZ)
863 supp_rates = FIELD_PREP(RA_LEGACY_OFDM, supp_rates >> 4) |
864 FIELD_PREP(RA_LEGACY_CCK, supp_rates & 0xf);
866 supp_rates = FIELD_PREP(RA_LEGACY_OFDM, supp_rates);
868 ra_info->legacy = cpu_to_le16(supp_rates);
870 if (sta->deflink.ht_cap.ht_supported)
871 memcpy(ra_info->rx_mcs_bitmask,
872 sta->deflink.ht_cap.mcs.rx_mask,
875 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_STATE, sizeof(*state));
876 state = (struct sta_rec_state *)tlv;
877 state->state = sta_state;
879 if (sta->deflink.vht_cap.vht_supported) {
880 state->vht_opmode = sta->deflink.bandwidth;
881 state->vht_opmode |= (sta->deflink.rx_nss - 1) <<
882 IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
885 EXPORT_SYMBOL_GPL(mt76_connac_mcu_sta_tlv);
887 void mt76_connac_mcu_wtbl_smps_tlv(struct sk_buff *skb,
888 struct ieee80211_sta *sta,
889 void *sta_wtbl, void *wtbl_tlv)
891 struct wtbl_smps *smps;
894 tlv = mt76_connac_mcu_add_nested_tlv(skb, WTBL_SMPS, sizeof(*smps),
896 smps = (struct wtbl_smps *)tlv;
897 smps->smps = (sta->smps_mode == IEEE80211_SMPS_DYNAMIC);
899 EXPORT_SYMBOL_GPL(mt76_connac_mcu_wtbl_smps_tlv);
901 void mt76_connac_mcu_wtbl_ht_tlv(struct mt76_dev *dev, struct sk_buff *skb,
902 struct ieee80211_sta *sta, void *sta_wtbl,
903 void *wtbl_tlv, bool ht_ldpc, bool vht_ldpc)
905 struct wtbl_ht *ht = NULL;
909 if (sta->deflink.ht_cap.ht_supported || sta->deflink.he_6ghz_capa.capa) {
910 tlv = mt76_connac_mcu_add_nested_tlv(skb, WTBL_HT, sizeof(*ht),
912 ht = (struct wtbl_ht *)tlv;
913 ht->ldpc = ht_ldpc &&
914 !!(sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_LDPC_CODING);
916 if (sta->deflink.ht_cap.ht_supported) {
917 ht->af = sta->deflink.ht_cap.ampdu_factor;
918 ht->mm = sta->deflink.ht_cap.ampdu_density;
920 ht->af = le16_get_bits(sta->deflink.he_6ghz_capa.capa,
921 IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP);
922 ht->mm = le16_get_bits(sta->deflink.he_6ghz_capa.capa,
923 IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START);
929 if (sta->deflink.vht_cap.vht_supported || sta->deflink.he_6ghz_capa.capa) {
930 struct wtbl_vht *vht;
933 tlv = mt76_connac_mcu_add_nested_tlv(skb, WTBL_VHT,
934 sizeof(*vht), wtbl_tlv,
936 vht = (struct wtbl_vht *)tlv;
937 vht->ldpc = vht_ldpc &&
938 !!(sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_RXLDPC);
941 af = FIELD_GET(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK,
942 sta->deflink.vht_cap.cap);
944 ht->af = max(ht->af, af);
947 mt76_connac_mcu_wtbl_smps_tlv(skb, sta, sta_wtbl, wtbl_tlv);
949 if (is_connac_v1(dev) && sta->deflink.ht_cap.ht_supported) {
951 u32 msk = MT_WTBL_W5_SHORT_GI_20 | MT_WTBL_W5_SHORT_GI_40 |
952 MT_WTBL_W5_SHORT_GI_80 | MT_WTBL_W5_SHORT_GI_160;
953 struct wtbl_raw *raw;
955 tlv = mt76_connac_mcu_add_nested_tlv(skb, WTBL_RAW_DATA,
956 sizeof(*raw), wtbl_tlv,
959 if (sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SGI_20)
960 flags |= MT_WTBL_W5_SHORT_GI_20;
961 if (sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SGI_40)
962 flags |= MT_WTBL_W5_SHORT_GI_40;
964 if (sta->deflink.vht_cap.vht_supported) {
965 if (sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80)
966 flags |= MT_WTBL_W5_SHORT_GI_80;
967 if (sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_160)
968 flags |= MT_WTBL_W5_SHORT_GI_160;
970 raw = (struct wtbl_raw *)tlv;
971 raw->val = cpu_to_le32(flags);
972 raw->msk = cpu_to_le32(~msk);
977 EXPORT_SYMBOL_GPL(mt76_connac_mcu_wtbl_ht_tlv);
979 int mt76_connac_mcu_sta_cmd(struct mt76_phy *phy,
980 struct mt76_sta_cmd_info *info)
982 struct mt76_vif *mvif = (struct mt76_vif *)info->vif->drv_priv;
983 struct mt76_dev *dev = phy->dev;
984 struct wtbl_req_hdr *wtbl_hdr;
985 struct tlv *sta_wtbl;
988 skb = mt76_connac_mcu_alloc_sta_req(dev, mvif, info->wcid);
992 if (info->sta || !info->offload_fw)
993 mt76_connac_mcu_sta_basic_tlv(skb, info->vif, info->sta,
994 info->enable, info->newly);
995 if (info->sta && info->enable)
996 mt76_connac_mcu_sta_tlv(phy, skb, info->sta,
997 info->vif, info->rcpi,
1000 sta_wtbl = mt76_connac_mcu_add_tlv(skb, STA_REC_WTBL,
1001 sizeof(struct tlv));
1003 wtbl_hdr = mt76_connac_mcu_alloc_wtbl_req(dev, info->wcid,
1006 if (IS_ERR(wtbl_hdr))
1007 return PTR_ERR(wtbl_hdr);
1010 mt76_connac_mcu_wtbl_generic_tlv(dev, skb, info->vif,
1011 info->sta, sta_wtbl,
1013 mt76_connac_mcu_wtbl_hdr_trans_tlv(skb, info->vif, info->wcid,
1014 sta_wtbl, wtbl_hdr);
1016 mt76_connac_mcu_wtbl_ht_tlv(dev, skb, info->sta,
1021 return mt76_mcu_skb_send_msg(dev, skb, info->cmd, true);
1023 EXPORT_SYMBOL_GPL(mt76_connac_mcu_sta_cmd);
1025 void mt76_connac_mcu_wtbl_ba_tlv(struct mt76_dev *dev, struct sk_buff *skb,
1026 struct ieee80211_ampdu_params *params,
1027 bool enable, bool tx, void *sta_wtbl,
1033 tlv = mt76_connac_mcu_add_nested_tlv(skb, WTBL_BA, sizeof(*ba),
1034 wtbl_tlv, sta_wtbl);
1036 ba = (struct wtbl_ba *)tlv;
1037 ba->tid = params->tid;
1040 ba->ba_type = MT_BA_TYPE_ORIGINATOR;
1041 ba->sn = enable ? cpu_to_le16(params->ssn) : 0;
1042 ba->ba_winsize = enable ? cpu_to_le16(params->buf_size) : 0;
1045 memcpy(ba->peer_addr, params->sta->addr, ETH_ALEN);
1046 ba->ba_type = MT_BA_TYPE_RECIPIENT;
1047 ba->rst_ba_tid = params->tid;
1048 ba->rst_ba_sel = RST_BA_MAC_TID_MATCH;
1052 if (!is_connac_v1(dev)) {
1053 ba->ba_winsize = enable ? cpu_to_le16(params->buf_size) : 0;
1058 static const u8 ba_range[] = { 4, 8, 12, 24, 36, 48, 54, 64 };
1061 for (i = 7; i > 0; i--) {
1062 if (params->buf_size >= ba_range[i])
1065 ba->ba_winsize_idx = i;
1068 EXPORT_SYMBOL_GPL(mt76_connac_mcu_wtbl_ba_tlv);
1070 int mt76_connac_mcu_uni_add_dev(struct mt76_phy *phy,
1071 struct ieee80211_vif *vif,
1072 struct mt76_wcid *wcid,
1075 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
1076 struct mt76_dev *dev = phy->dev;
1088 u8 omac_addr[ETH_ALEN];
1092 .omac_idx = mvif->omac_idx,
1093 .band_idx = mvif->band_idx,
1096 .tag = cpu_to_le16(DEV_INFO_ACTIVE),
1097 .len = cpu_to_le16(sizeof(struct req_tlv)),
1106 struct mt76_connac_bss_basic_tlv basic;
1109 .bss_idx = mvif->idx,
1112 .tag = cpu_to_le16(UNI_BSS_INFO_BASIC),
1113 .len = cpu_to_le16(sizeof(struct mt76_connac_bss_basic_tlv)),
1114 .omac_idx = mvif->omac_idx,
1115 .band_idx = mvif->band_idx,
1116 .wmm_idx = mvif->wmm_idx,
1118 .bmc_tx_wlan_idx = cpu_to_le16(wcid->idx),
1119 .sta_idx = cpu_to_le16(wcid->idx),
1123 int err, idx, cmd, len;
1126 switch (vif->type) {
1127 case NL80211_IFTYPE_MESH_POINT:
1128 case NL80211_IFTYPE_MONITOR:
1129 case NL80211_IFTYPE_AP:
1130 basic_req.basic.conn_type = cpu_to_le32(CONNECTION_INFRA_AP);
1132 case NL80211_IFTYPE_STATION:
1133 basic_req.basic.conn_type = cpu_to_le32(CONNECTION_INFRA_STA);
1135 case NL80211_IFTYPE_ADHOC:
1136 basic_req.basic.conn_type = cpu_to_le32(CONNECTION_IBSS_ADHOC);
1143 idx = mvif->omac_idx > EXT_BSSID_START ? HW_BSSID_0 : mvif->omac_idx;
1144 basic_req.basic.hw_bss_idx = idx;
1146 memcpy(dev_req.tlv.omac_addr, vif->addr, ETH_ALEN);
1148 cmd = enable ? MCU_UNI_CMD(DEV_INFO_UPDATE) : MCU_UNI_CMD(BSS_INFO_UPDATE);
1149 data = enable ? (void *)&dev_req : (void *)&basic_req;
1150 len = enable ? sizeof(dev_req) : sizeof(basic_req);
1152 err = mt76_mcu_send_msg(dev, cmd, data, len, true);
1156 cmd = enable ? MCU_UNI_CMD(BSS_INFO_UPDATE) : MCU_UNI_CMD(DEV_INFO_UPDATE);
1157 data = enable ? (void *)&basic_req : (void *)&dev_req;
1158 len = enable ? sizeof(basic_req) : sizeof(dev_req);
1160 return mt76_mcu_send_msg(dev, cmd, data, len, true);
1162 EXPORT_SYMBOL_GPL(mt76_connac_mcu_uni_add_dev);
1164 void mt76_connac_mcu_sta_ba_tlv(struct sk_buff *skb,
1165 struct ieee80211_ampdu_params *params,
1166 bool enable, bool tx)
1168 struct sta_rec_ba *ba;
1171 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_BA, sizeof(*ba));
1173 ba = (struct sta_rec_ba *)tlv;
1174 ba->ba_type = tx ? MT_BA_TYPE_ORIGINATOR : MT_BA_TYPE_RECIPIENT;
1175 ba->winsize = cpu_to_le16(params->buf_size);
1176 ba->ssn = cpu_to_le16(params->ssn);
1177 ba->ba_en = enable << params->tid;
1178 ba->amsdu = params->amsdu;
1179 ba->tid = params->tid;
1181 EXPORT_SYMBOL_GPL(mt76_connac_mcu_sta_ba_tlv);
1183 int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif *mvif,
1184 struct ieee80211_ampdu_params *params,
1185 int cmd, bool enable, bool tx)
1187 struct mt76_wcid *wcid = (struct mt76_wcid *)params->sta->drv_priv;
1188 struct wtbl_req_hdr *wtbl_hdr;
1189 struct tlv *sta_wtbl;
1190 struct sk_buff *skb;
1193 skb = mt76_connac_mcu_alloc_sta_req(dev, mvif, wcid);
1195 return PTR_ERR(skb);
1197 sta_wtbl = mt76_connac_mcu_add_tlv(skb, STA_REC_WTBL,
1198 sizeof(struct tlv));
1200 wtbl_hdr = mt76_connac_mcu_alloc_wtbl_req(dev, wcid, WTBL_SET,
1202 if (IS_ERR(wtbl_hdr))
1203 return PTR_ERR(wtbl_hdr);
1205 mt76_connac_mcu_wtbl_ba_tlv(dev, skb, params, enable, tx, sta_wtbl,
1208 ret = mt76_mcu_skb_send_msg(dev, skb, cmd, true);
1212 skb = mt76_connac_mcu_alloc_sta_req(dev, mvif, wcid);
1214 return PTR_ERR(skb);
1216 mt76_connac_mcu_sta_ba_tlv(skb, params, enable, tx);
1218 return mt76_mcu_skb_send_msg(dev, skb, cmd, true);
1220 EXPORT_SYMBOL_GPL(mt76_connac_mcu_sta_ba);
1222 u8 mt76_connac_get_phy_mode(struct mt76_phy *phy, struct ieee80211_vif *vif,
1223 enum nl80211_band band, struct ieee80211_sta *sta)
1225 struct mt76_dev *dev = phy->dev;
1226 const struct ieee80211_sta_he_cap *he_cap;
1227 struct ieee80211_sta_vht_cap *vht_cap;
1228 struct ieee80211_sta_ht_cap *ht_cap;
1231 if (is_connac_v1(dev))
1235 ht_cap = &sta->deflink.ht_cap;
1236 vht_cap = &sta->deflink.vht_cap;
1237 he_cap = &sta->deflink.he_cap;
1239 struct ieee80211_supported_band *sband;
1241 sband = phy->hw->wiphy->bands[band];
1242 ht_cap = &sband->ht_cap;
1243 vht_cap = &sband->vht_cap;
1244 he_cap = ieee80211_get_he_iftype_cap(sband, vif->type);
1247 if (band == NL80211_BAND_2GHZ) {
1248 mode |= PHY_MODE_B | PHY_MODE_G;
1250 if (ht_cap->ht_supported)
1251 mode |= PHY_MODE_GN;
1253 if (he_cap && he_cap->has_he)
1254 mode |= PHY_MODE_AX_24G;
1255 } else if (band == NL80211_BAND_5GHZ) {
1258 if (ht_cap->ht_supported)
1259 mode |= PHY_MODE_AN;
1261 if (vht_cap->vht_supported)
1262 mode |= PHY_MODE_AC;
1264 if (he_cap && he_cap->has_he)
1265 mode |= PHY_MODE_AX_5G;
1266 } else if (band == NL80211_BAND_6GHZ) {
1267 mode |= PHY_MODE_A | PHY_MODE_AN |
1268 PHY_MODE_AC | PHY_MODE_AX_5G;
1273 EXPORT_SYMBOL_GPL(mt76_connac_get_phy_mode);
1275 const struct ieee80211_sta_he_cap *
1276 mt76_connac_get_he_phy_cap(struct mt76_phy *phy, struct ieee80211_vif *vif)
1278 enum nl80211_band band = phy->chandef.chan->band;
1279 struct ieee80211_supported_band *sband;
1281 sband = phy->hw->wiphy->bands[band];
1283 return ieee80211_get_he_iftype_cap(sband, vif->type);
1285 EXPORT_SYMBOL_GPL(mt76_connac_get_he_phy_cap);
1287 #define DEFAULT_HE_PE_DURATION 4
1288 #define DEFAULT_HE_DURATION_RTS_THRES 1023
1290 mt76_connac_mcu_uni_bss_he_tlv(struct mt76_phy *phy, struct ieee80211_vif *vif,
1293 const struct ieee80211_sta_he_cap *cap;
1294 struct bss_info_uni_he *he;
1296 cap = mt76_connac_get_he_phy_cap(phy, vif);
1298 he = (struct bss_info_uni_he *)tlv;
1299 he->he_pe_duration = vif->bss_conf.htc_trig_based_pkt_ext;
1300 if (!he->he_pe_duration)
1301 he->he_pe_duration = DEFAULT_HE_PE_DURATION;
1303 he->he_rts_thres = cpu_to_le16(vif->bss_conf.frame_time_rts_th);
1304 if (!he->he_rts_thres)
1305 he->he_rts_thres = cpu_to_le16(DEFAULT_HE_DURATION_RTS_THRES);
1307 he->max_nss_mcs[CMD_HE_MCS_BW80] = cap->he_mcs_nss_supp.tx_mcs_80;
1308 he->max_nss_mcs[CMD_HE_MCS_BW160] = cap->he_mcs_nss_supp.tx_mcs_160;
1309 he->max_nss_mcs[CMD_HE_MCS_BW8080] = cap->he_mcs_nss_supp.tx_mcs_80p80;
1312 int mt76_connac_mcu_uni_add_bss(struct mt76_phy *phy,
1313 struct ieee80211_vif *vif,
1314 struct mt76_wcid *wcid,
1317 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
1318 struct cfg80211_chan_def *chandef = &phy->chandef;
1319 int freq1 = chandef->center_freq1, freq2 = chandef->center_freq2;
1320 enum nl80211_band band = chandef->chan->band;
1321 struct mt76_dev *mdev = phy->dev;
1327 struct mt76_connac_bss_basic_tlv basic;
1328 struct mt76_connac_bss_qos_tlv qos;
1331 .bss_idx = mvif->idx,
1334 .tag = cpu_to_le16(UNI_BSS_INFO_BASIC),
1335 .len = cpu_to_le16(sizeof(struct mt76_connac_bss_basic_tlv)),
1336 .bcn_interval = cpu_to_le16(vif->bss_conf.beacon_int),
1337 .dtim_period = vif->bss_conf.dtim_period,
1338 .omac_idx = mvif->omac_idx,
1339 .band_idx = mvif->band_idx,
1340 .wmm_idx = mvif->wmm_idx,
1341 .active = true, /* keep bss deactivated */
1342 .phymode = mt76_connac_get_phy_mode(phy, vif, band, NULL),
1345 .tag = cpu_to_le16(UNI_BSS_INFO_QBSS),
1346 .len = cpu_to_le16(sizeof(struct mt76_connac_bss_qos_tlv)),
1347 .qos = vif->bss_conf.qos,
1370 } __packed rlm_req = {
1372 .bss_idx = mvif->idx,
1375 .tag = cpu_to_le16(UNI_BSS_INFO_RLM),
1376 .len = cpu_to_le16(sizeof(struct rlm_tlv)),
1377 .control_channel = chandef->chan->hw_value,
1378 .center_chan = ieee80211_frequency_to_channel(freq1),
1379 .center_chan2 = ieee80211_frequency_to_channel(freq2),
1380 .tx_streams = hweight8(phy->antenna_mask),
1381 .ht_op_info = 4, /* set HT 40M allowed */
1382 .rx_streams = phy->chainmask,
1390 idx = mvif->omac_idx > EXT_BSSID_START ? HW_BSSID_0 : mvif->omac_idx;
1391 basic_req.basic.hw_bss_idx = idx;
1392 if (band == NL80211_BAND_6GHZ)
1393 basic_req.basic.phymode_ext = PHY_MODE_AX_6G;
1395 basic_phy = mt76_connac_get_phy_mode_v2(phy, vif, band, NULL);
1396 basic_req.basic.nonht_basic_phy = cpu_to_le16(basic_phy);
1398 switch (vif->type) {
1399 case NL80211_IFTYPE_MESH_POINT:
1400 case NL80211_IFTYPE_AP:
1402 conn_type = CONNECTION_P2P_GO;
1404 conn_type = CONNECTION_INFRA_AP;
1405 basic_req.basic.conn_type = cpu_to_le32(conn_type);
1407 case NL80211_IFTYPE_STATION:
1409 conn_type = CONNECTION_P2P_GC;
1411 conn_type = CONNECTION_INFRA_STA;
1412 basic_req.basic.conn_type = cpu_to_le32(conn_type);
1414 case NL80211_IFTYPE_ADHOC:
1415 basic_req.basic.conn_type = cpu_to_le32(CONNECTION_IBSS_ADHOC);
1422 memcpy(basic_req.basic.bssid, vif->bss_conf.bssid, ETH_ALEN);
1423 basic_req.basic.bmc_tx_wlan_idx = cpu_to_le16(wcid->idx);
1424 basic_req.basic.sta_idx = cpu_to_le16(wcid->idx);
1425 basic_req.basic.conn_state = !enable;
1427 err = mt76_mcu_send_msg(mdev, MCU_UNI_CMD(BSS_INFO_UPDATE), &basic_req,
1428 sizeof(basic_req), true);
1432 if (vif->bss_conf.he_support) {
1438 struct bss_info_uni_he he;
1439 struct bss_info_uni_bss_color bss_color;
1442 .bss_idx = mvif->idx,
1445 .tag = cpu_to_le16(UNI_BSS_INFO_HE_BASIC),
1446 .len = cpu_to_le16(sizeof(struct bss_info_uni_he)),
1449 .tag = cpu_to_le16(UNI_BSS_INFO_BSS_COLOR),
1450 .len = cpu_to_le16(sizeof(struct bss_info_uni_bss_color)),
1457 he_req.bss_color.enable =
1458 vif->bss_conf.he_bss_color.enabled;
1459 he_req.bss_color.bss_color =
1460 vif->bss_conf.he_bss_color.color;
1463 mt76_connac_mcu_uni_bss_he_tlv(phy, vif,
1464 (struct tlv *)&he_req.he);
1465 err = mt76_mcu_send_msg(mdev, MCU_UNI_CMD(BSS_INFO_UPDATE),
1466 &he_req, sizeof(he_req), true);
1471 switch (chandef->width) {
1472 case NL80211_CHAN_WIDTH_40:
1473 rlm_req.rlm.bw = CMD_CBW_40MHZ;
1475 case NL80211_CHAN_WIDTH_80:
1476 rlm_req.rlm.bw = CMD_CBW_80MHZ;
1478 case NL80211_CHAN_WIDTH_80P80:
1479 rlm_req.rlm.bw = CMD_CBW_8080MHZ;
1481 case NL80211_CHAN_WIDTH_160:
1482 rlm_req.rlm.bw = CMD_CBW_160MHZ;
1484 case NL80211_CHAN_WIDTH_5:
1485 rlm_req.rlm.bw = CMD_CBW_5MHZ;
1487 case NL80211_CHAN_WIDTH_10:
1488 rlm_req.rlm.bw = CMD_CBW_10MHZ;
1490 case NL80211_CHAN_WIDTH_20_NOHT:
1491 case NL80211_CHAN_WIDTH_20:
1493 rlm_req.rlm.bw = CMD_CBW_20MHZ;
1494 rlm_req.rlm.ht_op_info = 0;
1498 if (rlm_req.rlm.control_channel < rlm_req.rlm.center_chan)
1499 rlm_req.rlm.sco = 1; /* SCA */
1500 else if (rlm_req.rlm.control_channel > rlm_req.rlm.center_chan)
1501 rlm_req.rlm.sco = 3; /* SCB */
1503 return mt76_mcu_send_msg(mdev, MCU_UNI_CMD(BSS_INFO_UPDATE), &rlm_req,
1504 sizeof(rlm_req), true);
1506 EXPORT_SYMBOL_GPL(mt76_connac_mcu_uni_add_bss);
1508 #define MT76_CONNAC_SCAN_CHANNEL_TIME 60
1509 int mt76_connac_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif,
1510 struct ieee80211_scan_request *scan_req)
1512 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
1513 struct cfg80211_scan_request *sreq = &scan_req->req;
1514 int n_ssids = 0, err, i, duration;
1515 int ext_channels_num = max_t(int, sreq->n_channels - 32, 0);
1516 struct ieee80211_channel **scan_list = sreq->channels;
1517 struct mt76_dev *mdev = phy->dev;
1518 struct mt76_connac_mcu_scan_channel *chan;
1519 struct mt76_connac_hw_scan_req *req;
1520 struct sk_buff *skb;
1522 skb = mt76_mcu_msg_alloc(mdev, NULL, sizeof(*req));
1526 set_bit(MT76_HW_SCANNING, &phy->state);
1527 mvif->scan_seq_num = (mvif->scan_seq_num + 1) & 0x7f;
1529 req = (struct mt76_connac_hw_scan_req *)skb_put(skb, sizeof(*req));
1531 req->seq_num = mvif->scan_seq_num | mvif->band_idx << 7;
1532 req->bss_idx = mvif->idx;
1533 req->scan_type = sreq->n_ssids ? 1 : 0;
1534 req->probe_req_num = sreq->n_ssids ? 2 : 0;
1537 for (i = 0; i < sreq->n_ssids; i++) {
1538 if (!sreq->ssids[i].ssid_len)
1541 req->ssids[i].ssid_len = cpu_to_le32(sreq->ssids[i].ssid_len);
1542 memcpy(req->ssids[i].ssid, sreq->ssids[i].ssid,
1543 sreq->ssids[i].ssid_len);
1546 req->ssid_type = n_ssids ? BIT(2) : BIT(0);
1547 req->ssid_type_ext = n_ssids ? BIT(0) : 0;
1548 req->ssids_num = n_ssids;
1550 duration = is_mt7921(phy->dev) ? 0 : MT76_CONNAC_SCAN_CHANNEL_TIME;
1551 /* increase channel time for passive scan */
1554 req->timeout_value = cpu_to_le16(sreq->n_channels * duration);
1555 req->channel_min_dwell_time = cpu_to_le16(duration);
1556 req->channel_dwell_time = cpu_to_le16(duration);
1558 req->channels_num = min_t(u8, sreq->n_channels, 32);
1559 req->ext_channels_num = min_t(u8, ext_channels_num, 32);
1560 for (i = 0; i < req->channels_num + req->ext_channels_num; i++) {
1562 chan = &req->ext_channels[i - 32];
1564 chan = &req->channels[i];
1566 switch (scan_list[i]->band) {
1567 case NL80211_BAND_2GHZ:
1570 case NL80211_BAND_6GHZ:
1577 chan->channel_num = scan_list[i]->hw_value;
1579 req->channel_type = sreq->n_channels ? 4 : 0;
1581 if (sreq->ie_len > 0) {
1582 memcpy(req->ies, sreq->ie, sreq->ie_len);
1583 req->ies_len = cpu_to_le16(sreq->ie_len);
1586 if (is_mt7921(phy->dev))
1587 req->scan_func |= SCAN_FUNC_SPLIT_SCAN;
1589 memcpy(req->bssid, sreq->bssid, ETH_ALEN);
1590 if (sreq->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
1591 get_random_mask_addr(req->random_mac, sreq->mac_addr,
1592 sreq->mac_addr_mask);
1593 req->scan_func |= SCAN_FUNC_RANDOM_MAC;
1596 err = mt76_mcu_skb_send_msg(mdev, skb, MCU_CE_CMD(START_HW_SCAN),
1599 clear_bit(MT76_HW_SCANNING, &phy->state);
1603 EXPORT_SYMBOL_GPL(mt76_connac_mcu_hw_scan);
1605 int mt76_connac_mcu_cancel_hw_scan(struct mt76_phy *phy,
1606 struct ieee80211_vif *vif)
1608 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
1614 .seq_num = mvif->scan_seq_num,
1617 if (test_and_clear_bit(MT76_HW_SCANNING, &phy->state)) {
1618 struct cfg80211_scan_info info = {
1622 ieee80211_scan_completed(phy->hw, &info);
1625 return mt76_mcu_send_msg(phy->dev, MCU_CE_CMD(CANCEL_HW_SCAN),
1626 &req, sizeof(req), false);
1628 EXPORT_SYMBOL_GPL(mt76_connac_mcu_cancel_hw_scan);
1630 int mt76_connac_mcu_sched_scan_req(struct mt76_phy *phy,
1631 struct ieee80211_vif *vif,
1632 struct cfg80211_sched_scan_request *sreq)
1634 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
1635 struct ieee80211_channel **scan_list = sreq->channels;
1636 struct mt76_connac_mcu_scan_channel *chan;
1637 struct mt76_connac_sched_scan_req *req;
1638 struct mt76_dev *mdev = phy->dev;
1639 struct cfg80211_match_set *match;
1640 struct cfg80211_ssid *ssid;
1641 struct sk_buff *skb;
1644 skb = mt76_mcu_msg_alloc(mdev, NULL, sizeof(*req) + sreq->ie_len);
1648 mvif->scan_seq_num = (mvif->scan_seq_num + 1) & 0x7f;
1650 req = (struct mt76_connac_sched_scan_req *)skb_put(skb, sizeof(*req));
1652 req->seq_num = mvif->scan_seq_num | mvif->band_idx << 7;
1654 if (sreq->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
1655 u8 *addr = is_mt7663(phy->dev) ? req->mt7663.random_mac
1656 : req->mt7921.random_mac;
1659 get_random_mask_addr(addr, sreq->mac_addr,
1660 sreq->mac_addr_mask);
1662 if (is_mt7921(phy->dev)) {
1663 req->mt7921.bss_idx = mvif->idx;
1664 req->mt7921.delay = cpu_to_le32(sreq->delay);
1667 req->ssids_num = sreq->n_ssids;
1668 for (i = 0; i < req->ssids_num; i++) {
1669 ssid = &sreq->ssids[i];
1670 memcpy(req->ssids[i].ssid, ssid->ssid, ssid->ssid_len);
1671 req->ssids[i].ssid_len = cpu_to_le32(ssid->ssid_len);
1674 req->match_num = sreq->n_match_sets;
1675 for (i = 0; i < req->match_num; i++) {
1676 match = &sreq->match_sets[i];
1677 memcpy(req->match[i].ssid, match->ssid.ssid,
1678 match->ssid.ssid_len);
1679 req->match[i].rssi_th = cpu_to_le32(match->rssi_thold);
1680 req->match[i].ssid_len = match->ssid.ssid_len;
1683 req->channel_type = sreq->n_channels ? 4 : 0;
1684 req->channels_num = min_t(u8, sreq->n_channels, 64);
1685 for (i = 0; i < req->channels_num; i++) {
1686 chan = &req->channels[i];
1688 switch (scan_list[i]->band) {
1689 case NL80211_BAND_2GHZ:
1692 case NL80211_BAND_6GHZ:
1699 chan->channel_num = scan_list[i]->hw_value;
1702 req->intervals_num = sreq->n_scan_plans;
1703 for (i = 0; i < req->intervals_num; i++)
1704 req->intervals[i] = cpu_to_le16(sreq->scan_plans[i].interval);
1706 if (sreq->ie_len > 0) {
1707 req->ie_len = cpu_to_le16(sreq->ie_len);
1708 memcpy(skb_put(skb, sreq->ie_len), sreq->ie, sreq->ie_len);
1711 return mt76_mcu_skb_send_msg(mdev, skb, MCU_CE_CMD(SCHED_SCAN_REQ),
1714 EXPORT_SYMBOL_GPL(mt76_connac_mcu_sched_scan_req);
1716 int mt76_connac_mcu_sched_scan_enable(struct mt76_phy *phy,
1717 struct ieee80211_vif *vif,
1721 u8 active; /* 0: enabled 1: disabled */
1728 set_bit(MT76_HW_SCHED_SCANNING, &phy->state);
1730 clear_bit(MT76_HW_SCHED_SCANNING, &phy->state);
1732 return mt76_mcu_send_msg(phy->dev, MCU_CE_CMD(SCHED_SCAN_ENABLE),
1733 &req, sizeof(req), false);
1735 EXPORT_SYMBOL_GPL(mt76_connac_mcu_sched_scan_enable);
1737 int mt76_connac_mcu_chip_config(struct mt76_dev *dev)
1739 struct mt76_connac_config req = {
1743 memcpy(req.data, "assert", 7);
1745 return mt76_mcu_send_msg(dev, MCU_CE_CMD(CHIP_CONFIG),
1746 &req, sizeof(req), false);
1748 EXPORT_SYMBOL_GPL(mt76_connac_mcu_chip_config);
1750 int mt76_connac_mcu_set_deep_sleep(struct mt76_dev *dev, bool enable)
1752 struct mt76_connac_config req = {
1756 snprintf(req.data, sizeof(req.data), "KeepFullPwr %d", !enable);
1758 return mt76_mcu_send_msg(dev, MCU_CE_CMD(CHIP_CONFIG),
1759 &req, sizeof(req), false);
1761 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_deep_sleep);
1763 int mt76_connac_sta_state_dp(struct mt76_dev *dev,
1764 enum ieee80211_sta_state old_state,
1765 enum ieee80211_sta_state new_state)
1767 if ((old_state == IEEE80211_STA_ASSOC &&
1768 new_state == IEEE80211_STA_AUTHORIZED) ||
1769 (old_state == IEEE80211_STA_NONE &&
1770 new_state == IEEE80211_STA_NOTEXIST))
1771 mt76_connac_mcu_set_deep_sleep(dev, true);
1773 if ((old_state == IEEE80211_STA_NOTEXIST &&
1774 new_state == IEEE80211_STA_NONE) ||
1775 (old_state == IEEE80211_STA_AUTHORIZED &&
1776 new_state == IEEE80211_STA_ASSOC))
1777 mt76_connac_mcu_set_deep_sleep(dev, false);
1781 EXPORT_SYMBOL_GPL(mt76_connac_sta_state_dp);
1783 void mt76_connac_mcu_coredump_event(struct mt76_dev *dev, struct sk_buff *skb,
1784 struct mt76_connac_coredump *coredump)
1786 spin_lock_bh(&dev->lock);
1787 __skb_queue_tail(&coredump->msg_list, skb);
1788 spin_unlock_bh(&dev->lock);
1790 coredump->last_activity = jiffies;
1792 queue_delayed_work(dev->wq, &coredump->work,
1793 MT76_CONNAC_COREDUMP_TIMEOUT);
1795 EXPORT_SYMBOL_GPL(mt76_connac_mcu_coredump_event);
1797 static void mt76_connac_mcu_parse_tx_resource(struct mt76_dev *dev,
1798 struct sk_buff *skb)
1800 struct mt76_sdio *sdio = &dev->sdio;
1801 struct mt76_connac_tx_resource {
1803 __le32 pse_data_quota;
1804 __le32 pse_mcu_quota;
1805 __le32 ple_data_quota;
1806 __le32 ple_mcu_quota;
1807 __le16 pse_page_size;
1808 __le16 ple_page_size;
1811 } __packed * tx_res;
1813 tx_res = (struct mt76_connac_tx_resource *)skb->data;
1814 sdio->sched.pse_data_quota = le32_to_cpu(tx_res->pse_data_quota);
1815 sdio->sched.pse_mcu_quota = le32_to_cpu(tx_res->pse_mcu_quota);
1816 sdio->sched.ple_data_quota = le32_to_cpu(tx_res->ple_data_quota);
1817 sdio->sched.pse_page_size = le16_to_cpu(tx_res->pse_page_size);
1818 sdio->sched.deficit = tx_res->pp_padding;
1821 static void mt76_connac_mcu_parse_phy_cap(struct mt76_dev *dev,
1822 struct sk_buff *skb)
1824 struct mt76_connac_phy_cap {
1844 cap = (struct mt76_connac_phy_cap *)skb->data;
1846 dev->phy.antenna_mask = BIT(cap->nss) - 1;
1847 dev->phy.chainmask = dev->phy.antenna_mask;
1848 dev->phy.cap.has_2ghz = cap->hw_path & BIT(WF0_24G);
1849 dev->phy.cap.has_5ghz = cap->hw_path & BIT(WF0_5G);
1852 int mt76_connac_mcu_get_nic_capability(struct mt76_phy *phy)
1854 struct mt76_connac_cap_hdr {
1858 struct sk_buff *skb;
1861 ret = mt76_mcu_send_and_get_msg(phy->dev, MCU_CE_CMD(GET_NIC_CAPAB),
1862 NULL, 0, true, &skb);
1866 hdr = (struct mt76_connac_cap_hdr *)skb->data;
1867 if (skb->len < sizeof(*hdr)) {
1872 skb_pull(skb, sizeof(*hdr));
1874 for (i = 0; i < le16_to_cpu(hdr->n_element); i++) {
1878 } __packed * tlv = (struct tlv_hdr *)skb->data;
1881 if (skb->len < sizeof(*tlv))
1884 skb_pull(skb, sizeof(*tlv));
1886 len = le32_to_cpu(tlv->len);
1890 switch (le32_to_cpu(tlv->type)) {
1892 phy->cap.has_6ghz = skb->data[0];
1894 case MT_NIC_CAP_MAC_ADDR:
1895 memcpy(phy->macaddr, (void *)skb->data, ETH_ALEN);
1897 case MT_NIC_CAP_PHY:
1898 mt76_connac_mcu_parse_phy_cap(phy->dev, skb);
1900 case MT_NIC_CAP_TX_RESOURCE:
1901 if (mt76_is_sdio(phy->dev))
1902 mt76_connac_mcu_parse_tx_resource(phy->dev,
1915 EXPORT_SYMBOL_GPL(mt76_connac_mcu_get_nic_capability);
1918 mt76_connac_mcu_build_sku(struct mt76_dev *dev, s8 *sku,
1919 struct mt76_power_limits *limits,
1920 enum nl80211_band band)
1922 int max_power = is_mt7921(dev) ? 127 : 63;
1923 int i, offset = sizeof(limits->cck);
1925 memset(sku, max_power, MT_SKU_POWER_LIMIT);
1927 if (band == NL80211_BAND_2GHZ) {
1929 memcpy(sku, limits->cck, sizeof(limits->cck));
1933 memcpy(&sku[offset], limits->ofdm, sizeof(limits->ofdm));
1934 offset += sizeof(limits->ofdm);
1937 for (i = 0; i < 2; i++) {
1938 memcpy(&sku[offset], limits->mcs[i], 8);
1941 sku[offset++] = limits->mcs[0][0];
1944 for (i = 0; i < ARRAY_SIZE(limits->mcs); i++) {
1945 memcpy(&sku[offset], limits->mcs[i],
1946 ARRAY_SIZE(limits->mcs[i]));
1950 if (!is_mt7921(dev))
1954 for (i = 0; i < ARRAY_SIZE(limits->ru); i++) {
1955 memcpy(&sku[offset], limits->ru[i], ARRAY_SIZE(limits->ru[i]));
1956 offset += ARRAY_SIZE(limits->ru[i]);
1960 static s8 mt76_connac_get_ch_power(struct mt76_phy *phy,
1961 struct ieee80211_channel *chan,
1964 struct mt76_dev *dev = phy->dev;
1965 struct ieee80211_supported_band *sband;
1968 switch (chan->band) {
1969 case NL80211_BAND_2GHZ:
1970 sband = &phy->sband_2g.sband;
1972 case NL80211_BAND_5GHZ:
1973 sband = &phy->sband_5g.sband;
1975 case NL80211_BAND_6GHZ:
1976 sband = &phy->sband_6g.sband;
1979 return target_power;
1982 for (i = 0; i < sband->n_channels; i++) {
1983 struct ieee80211_channel *ch = &sband->channels[i];
1985 if (ch->hw_value == chan->hw_value) {
1986 if (!(ch->flags & IEEE80211_CHAN_DISABLED)) {
1987 int power = 2 * ch->max_reg_power;
1989 if (is_mt7663(dev) && (power > 63 || power < -64))
1991 target_power = min_t(s8, power, target_power);
1997 return target_power;
2001 mt76_connac_mcu_rate_txpower_band(struct mt76_phy *phy,
2002 enum nl80211_band band)
2004 struct mt76_dev *dev = phy->dev;
2005 int sku_len, batch_len = is_mt7921(dev) ? 8 : 16;
2006 static const u8 chan_list_2ghz[] = {
2007 1, 2, 3, 4, 5, 6, 7,
2008 8, 9, 10, 11, 12, 13, 14
2010 static const u8 chan_list_5ghz[] = {
2011 36, 38, 40, 42, 44, 46, 48,
2012 50, 52, 54, 56, 58, 60, 62,
2013 64, 100, 102, 104, 106, 108, 110,
2014 112, 114, 116, 118, 120, 122, 124,
2015 126, 128, 132, 134, 136, 138, 140,
2016 142, 144, 149, 151, 153, 155, 157,
2019 static const u8 chan_list_6ghz[] = {
2020 1, 3, 5, 7, 9, 11, 13,
2021 15, 17, 19, 21, 23, 25, 27,
2022 29, 33, 35, 37, 39, 41, 43,
2023 45, 47, 49, 51, 53, 55, 57,
2024 59, 61, 65, 67, 69, 71, 73,
2025 75, 77, 79, 81, 83, 85, 87,
2026 89, 91, 93, 97, 99, 101, 103,
2027 105, 107, 109, 111, 113, 115, 117,
2028 119, 121, 123, 125, 129, 131, 133,
2029 135, 137, 139, 141, 143, 145, 147,
2030 149, 151, 153, 155, 157, 161, 163,
2031 165, 167, 169, 171, 173, 175, 177,
2032 179, 181, 183, 185, 187, 189, 193,
2033 195, 197, 199, 201, 203, 205, 207,
2034 209, 211, 213, 215, 217, 219, 221,
2037 int i, n_chan, batch_size, idx = 0, tx_power, last_ch;
2038 struct mt76_connac_sku_tlv sku_tlbv;
2039 struct mt76_power_limits limits;
2042 sku_len = is_mt7921(dev) ? sizeof(sku_tlbv) : sizeof(sku_tlbv) - 92;
2043 tx_power = 2 * phy->hw->conf.power_level;
2047 if (band == NL80211_BAND_2GHZ) {
2048 n_chan = ARRAY_SIZE(chan_list_2ghz);
2049 ch_list = chan_list_2ghz;
2050 } else if (band == NL80211_BAND_6GHZ) {
2051 n_chan = ARRAY_SIZE(chan_list_6ghz);
2052 ch_list = chan_list_6ghz;
2054 n_chan = ARRAY_SIZE(chan_list_5ghz);
2055 ch_list = chan_list_5ghz;
2057 batch_size = DIV_ROUND_UP(n_chan, batch_len);
2059 if (phy->cap.has_6ghz)
2060 last_ch = chan_list_6ghz[ARRAY_SIZE(chan_list_6ghz) - 1];
2061 else if (phy->cap.has_5ghz)
2062 last_ch = chan_list_5ghz[ARRAY_SIZE(chan_list_5ghz) - 1];
2064 last_ch = chan_list_2ghz[ARRAY_SIZE(chan_list_2ghz) - 1];
2066 for (i = 0; i < batch_size; i++) {
2067 struct mt76_connac_tx_power_limit_tlv tx_power_tlv = {};
2068 int j, err, msg_len, num_ch;
2069 struct sk_buff *skb;
2071 num_ch = i == batch_size - 1 ? n_chan % batch_len : batch_len;
2072 msg_len = sizeof(tx_power_tlv) + num_ch * sizeof(sku_tlbv);
2073 skb = mt76_mcu_msg_alloc(dev, NULL, msg_len);
2077 skb_reserve(skb, sizeof(tx_power_tlv));
2079 BUILD_BUG_ON(sizeof(dev->alpha2) > sizeof(tx_power_tlv.alpha2));
2080 memcpy(tx_power_tlv.alpha2, dev->alpha2, sizeof(dev->alpha2));
2081 tx_power_tlv.n_chan = num_ch;
2084 case NL80211_BAND_2GHZ:
2085 tx_power_tlv.band = 1;
2087 case NL80211_BAND_6GHZ:
2088 tx_power_tlv.band = 3;
2091 tx_power_tlv.band = 2;
2095 for (j = 0; j < num_ch; j++, idx++) {
2096 struct ieee80211_channel chan = {
2097 .hw_value = ch_list[idx],
2100 s8 reg_power, sar_power;
2102 reg_power = mt76_connac_get_ch_power(phy, &chan,
2104 sar_power = mt76_get_sar_power(phy, &chan, reg_power);
2106 mt76_get_rate_power_limits(phy, &chan, &limits,
2109 tx_power_tlv.last_msg = ch_list[idx] == last_ch;
2110 sku_tlbv.channel = ch_list[idx];
2112 mt76_connac_mcu_build_sku(dev, sku_tlbv.pwr_limit,
2114 skb_put_data(skb, &sku_tlbv, sku_len);
2116 __skb_push(skb, sizeof(tx_power_tlv));
2117 memcpy(skb->data, &tx_power_tlv, sizeof(tx_power_tlv));
2119 err = mt76_mcu_skb_send_msg(dev, skb,
2120 MCU_CE_CMD(SET_RATE_TX_POWER),
2129 int mt76_connac_mcu_set_rate_txpower(struct mt76_phy *phy)
2133 if (phy->cap.has_2ghz) {
2134 err = mt76_connac_mcu_rate_txpower_band(phy,
2139 if (phy->cap.has_5ghz) {
2140 err = mt76_connac_mcu_rate_txpower_band(phy,
2145 if (phy->cap.has_6ghz) {
2146 err = mt76_connac_mcu_rate_txpower_band(phy,
2154 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_rate_txpower);
2156 int mt76_connac_mcu_update_arp_filter(struct mt76_dev *dev,
2157 struct mt76_vif *vif,
2158 struct ieee80211_bss_conf *info)
2160 struct sk_buff *skb;
2161 int i, len = min_t(int, info->arp_addr_cnt,
2162 IEEE80211_BSS_ARP_ADDR_LIST_LEN);
2168 struct mt76_connac_arpns_tlv arp;
2171 .bss_idx = vif->idx,
2174 .tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ARP),
2175 .len = cpu_to_le16(sizeof(struct mt76_connac_arpns_tlv)),
2177 .mode = 2, /* update */
2182 skb = mt76_mcu_msg_alloc(dev, NULL,
2183 sizeof(req_hdr) + len * sizeof(__be32));
2187 skb_put_data(skb, &req_hdr, sizeof(req_hdr));
2188 for (i = 0; i < len; i++)
2189 skb_put_data(skb, &info->arp_addr_list[i], sizeof(__be32));
2191 return mt76_mcu_skb_send_msg(dev, skb, MCU_UNI_CMD(OFFLOAD), true);
2193 EXPORT_SYMBOL_GPL(mt76_connac_mcu_update_arp_filter);
2195 int mt76_connac_mcu_set_p2p_oppps(struct ieee80211_hw *hw,
2196 struct ieee80211_vif *vif)
2198 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
2199 int ct_window = vif->bss_conf.p2p_noa_attr.oppps_ctwindow;
2200 struct mt76_phy *phy = hw->priv;
2206 .ct_win = cpu_to_le32(ct_window),
2207 .bss_idx = mvif->idx,
2210 return mt76_mcu_send_msg(phy->dev, MCU_CE_CMD(SET_P2P_OPPPS),
2211 &req, sizeof(req), false);
2213 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_p2p_oppps);
2217 const struct wiphy_wowlan_support mt76_connac_wowlan_support = {
2218 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
2219 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | WIPHY_WOWLAN_NET_DETECT,
2221 .pattern_min_len = 1,
2222 .pattern_max_len = MT76_CONNAC_WOW_PATTEN_MAX_LEN,
2223 .max_nd_match_sets = 10,
2225 EXPORT_SYMBOL_GPL(mt76_connac_wowlan_support);
2228 mt76_connac_mcu_key_iter(struct ieee80211_hw *hw,
2229 struct ieee80211_vif *vif,
2230 struct ieee80211_sta *sta,
2231 struct ieee80211_key_conf *key,
2234 struct mt76_connac_gtk_rekey_tlv *gtk_tlv = data;
2237 if (key->cipher != WLAN_CIPHER_SUITE_AES_CMAC &&
2238 key->cipher != WLAN_CIPHER_SUITE_CCMP &&
2239 key->cipher != WLAN_CIPHER_SUITE_TKIP)
2242 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
2247 /* we are assuming here to have a single pairwise key */
2248 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
2249 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
2250 gtk_tlv->proto = cpu_to_le32(NL80211_WPA_VERSION_1);
2252 gtk_tlv->proto = cpu_to_le32(NL80211_WPA_VERSION_2);
2254 gtk_tlv->pairwise_cipher = cpu_to_le32(cipher);
2255 gtk_tlv->keyid = key->keyidx;
2257 gtk_tlv->group_cipher = cpu_to_le32(cipher);
2261 int mt76_connac_mcu_update_gtk_rekey(struct ieee80211_hw *hw,
2262 struct ieee80211_vif *vif,
2263 struct cfg80211_gtk_rekey_data *key)
2265 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
2266 struct mt76_connac_gtk_rekey_tlv *gtk_tlv;
2267 struct mt76_phy *phy = hw->priv;
2268 struct sk_buff *skb;
2273 .bss_idx = mvif->idx,
2276 skb = mt76_mcu_msg_alloc(phy->dev, NULL,
2277 sizeof(hdr) + sizeof(*gtk_tlv));
2281 skb_put_data(skb, &hdr, sizeof(hdr));
2282 gtk_tlv = (struct mt76_connac_gtk_rekey_tlv *)skb_put(skb,
2284 gtk_tlv->tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_GTK_REKEY);
2285 gtk_tlv->len = cpu_to_le16(sizeof(*gtk_tlv));
2286 gtk_tlv->rekey_mode = 2;
2287 gtk_tlv->option = 1;
2290 ieee80211_iter_keys_rcu(hw, vif, mt76_connac_mcu_key_iter, gtk_tlv);
2293 memcpy(gtk_tlv->kek, key->kek, NL80211_KEK_LEN);
2294 memcpy(gtk_tlv->kck, key->kck, NL80211_KCK_LEN);
2295 memcpy(gtk_tlv->replay_ctr, key->replay_ctr, NL80211_REPLAY_CTR_LEN);
2297 return mt76_mcu_skb_send_msg(phy->dev, skb,
2298 MCU_UNI_CMD(OFFLOAD), true);
2300 EXPORT_SYMBOL_GPL(mt76_connac_mcu_update_gtk_rekey);
2303 mt76_connac_mcu_set_arp_filter(struct mt76_dev *dev, struct ieee80211_vif *vif,
2306 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
2312 struct mt76_connac_arpns_tlv arpns;
2315 .bss_idx = mvif->idx,
2318 .tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ARP),
2319 .len = cpu_to_le16(sizeof(struct mt76_connac_arpns_tlv)),
2324 return mt76_mcu_send_msg(dev, MCU_UNI_CMD(OFFLOAD), &req,
2329 mt76_connac_mcu_set_gtk_rekey(struct mt76_dev *dev, struct ieee80211_vif *vif,
2332 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
2338 struct mt76_connac_gtk_rekey_tlv gtk_tlv;
2341 .bss_idx = mvif->idx,
2344 .tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_GTK_REKEY),
2345 .len = cpu_to_le16(sizeof(struct mt76_connac_gtk_rekey_tlv)),
2346 .rekey_mode = !suspend,
2350 return mt76_mcu_send_msg(dev, MCU_UNI_CMD(OFFLOAD), &req,
2355 mt76_connac_mcu_set_suspend_mode(struct mt76_dev *dev,
2356 struct ieee80211_vif *vif,
2357 bool enable, u8 mdtim,
2360 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
2366 struct mt76_connac_suspend_tlv suspend_tlv;
2369 .bss_idx = mvif->idx,
2372 .tag = cpu_to_le16(UNI_SUSPEND_MODE_SETTING),
2373 .len = cpu_to_le16(sizeof(struct mt76_connac_suspend_tlv)),
2376 .wow_suspend = wow_suspend,
2380 return mt76_mcu_send_msg(dev, MCU_UNI_CMD(SUSPEND), &req,
2385 mt76_connac_mcu_set_wow_pattern(struct mt76_dev *dev,
2386 struct ieee80211_vif *vif,
2387 u8 index, bool enable,
2388 struct cfg80211_pkt_pattern *pattern)
2390 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
2391 struct mt76_connac_wow_pattern_tlv *ptlv;
2392 struct sk_buff *skb;
2397 .bss_idx = mvif->idx,
2400 skb = mt76_mcu_msg_alloc(dev, NULL, sizeof(hdr) + sizeof(*ptlv));
2404 skb_put_data(skb, &hdr, sizeof(hdr));
2405 ptlv = (struct mt76_connac_wow_pattern_tlv *)skb_put(skb, sizeof(*ptlv));
2406 ptlv->tag = cpu_to_le16(UNI_SUSPEND_WOW_PATTERN);
2407 ptlv->len = cpu_to_le16(sizeof(*ptlv));
2408 ptlv->data_len = pattern->pattern_len;
2409 ptlv->enable = enable;
2410 ptlv->index = index;
2412 memcpy(ptlv->pattern, pattern->pattern, pattern->pattern_len);
2413 memcpy(ptlv->mask, pattern->mask, DIV_ROUND_UP(pattern->pattern_len, 8));
2415 return mt76_mcu_skb_send_msg(dev, skb, MCU_UNI_CMD(SUSPEND), true);
2419 mt76_connac_mcu_set_wow_ctrl(struct mt76_phy *phy, struct ieee80211_vif *vif,
2420 bool suspend, struct cfg80211_wowlan *wowlan)
2422 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
2423 struct mt76_dev *dev = phy->dev;
2429 struct mt76_connac_wow_ctrl_tlv wow_ctrl_tlv;
2430 struct mt76_connac_wow_gpio_param_tlv gpio_tlv;
2433 .bss_idx = mvif->idx,
2436 .tag = cpu_to_le16(UNI_SUSPEND_WOW_CTRL),
2437 .len = cpu_to_le16(sizeof(struct mt76_connac_wow_ctrl_tlv)),
2438 .cmd = suspend ? 1 : 2,
2441 .tag = cpu_to_le16(UNI_SUSPEND_WOW_GPIO_PARAM),
2442 .len = cpu_to_le16(sizeof(struct mt76_connac_wow_gpio_param_tlv)),
2443 .gpio_pin = 0xff, /* follow fw about GPIO pin */
2447 if (wowlan->magic_pkt)
2448 req.wow_ctrl_tlv.trigger |= UNI_WOW_DETECT_TYPE_MAGIC;
2449 if (wowlan->disconnect)
2450 req.wow_ctrl_tlv.trigger |= (UNI_WOW_DETECT_TYPE_DISCONNECT |
2451 UNI_WOW_DETECT_TYPE_BCN_LOST);
2452 if (wowlan->nd_config) {
2453 mt76_connac_mcu_sched_scan_req(phy, vif, wowlan->nd_config);
2454 req.wow_ctrl_tlv.trigger |= UNI_WOW_DETECT_TYPE_SCH_SCAN_HIT;
2455 mt76_connac_mcu_sched_scan_enable(phy, vif, suspend);
2457 if (wowlan->n_patterns)
2458 req.wow_ctrl_tlv.trigger |= UNI_WOW_DETECT_TYPE_BITMAP;
2460 if (mt76_is_mmio(dev))
2461 req.wow_ctrl_tlv.wakeup_hif = WOW_PCIE;
2462 else if (mt76_is_usb(dev))
2463 req.wow_ctrl_tlv.wakeup_hif = WOW_USB;
2464 else if (mt76_is_sdio(dev))
2465 req.wow_ctrl_tlv.wakeup_hif = WOW_GPIO;
2467 return mt76_mcu_send_msg(dev, MCU_UNI_CMD(SUSPEND), &req,
2471 int mt76_connac_mcu_set_hif_suspend(struct mt76_dev *dev, bool suspend)
2475 u8 hif_type; /* 0x0: HIF_SDIO
2481 struct hif_suspend_tlv {
2485 } __packed hif_suspend;
2488 .tag = cpu_to_le16(0), /* 0: UNI_HIF_CTRL_BASIC */
2489 .len = cpu_to_le16(sizeof(struct hif_suspend_tlv)),
2494 if (mt76_is_mmio(dev))
2495 req.hdr.hif_type = 2;
2496 else if (mt76_is_usb(dev))
2497 req.hdr.hif_type = 1;
2498 else if (mt76_is_sdio(dev))
2499 req.hdr.hif_type = 0;
2501 return mt76_mcu_send_msg(dev, MCU_UNI_CMD(HIF_CTRL), &req,
2504 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_hif_suspend);
2506 void mt76_connac_mcu_set_suspend_iter(void *priv, u8 *mac,
2507 struct ieee80211_vif *vif)
2509 struct mt76_phy *phy = priv;
2510 bool suspend = !test_bit(MT76_STATE_RUNNING, &phy->state);
2511 struct ieee80211_hw *hw = phy->hw;
2512 struct cfg80211_wowlan *wowlan = hw->wiphy->wowlan_config;
2515 mt76_connac_mcu_set_gtk_rekey(phy->dev, vif, suspend);
2516 mt76_connac_mcu_set_arp_filter(phy->dev, vif, suspend);
2518 mt76_connac_mcu_set_suspend_mode(phy->dev, vif, suspend, 1, true);
2520 for (i = 0; i < wowlan->n_patterns; i++)
2521 mt76_connac_mcu_set_wow_pattern(phy->dev, vif, i, suspend,
2522 &wowlan->patterns[i]);
2523 mt76_connac_mcu_set_wow_ctrl(phy, vif, suspend, wowlan);
2525 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_suspend_iter);
2526 #endif /* CONFIG_PM */
2528 u32 mt76_connac_mcu_reg_rr(struct mt76_dev *dev, u32 offset)
2534 .addr = cpu_to_le32(offset),
2537 return mt76_mcu_send_msg(dev, MCU_CE_QUERY(REG_READ), &req,
2540 EXPORT_SYMBOL_GPL(mt76_connac_mcu_reg_rr);
2542 void mt76_connac_mcu_reg_wr(struct mt76_dev *dev, u32 offset, u32 val)
2548 .addr = cpu_to_le32(offset),
2549 .val = cpu_to_le32(val),
2552 mt76_mcu_send_msg(dev, MCU_CE_CMD(REG_WRITE), &req,
2553 sizeof(req), false);
2555 EXPORT_SYMBOL_GPL(mt76_connac_mcu_reg_wr);
2558 mt76_connac_mcu_sta_key_tlv(struct mt76_connac_sta_key_conf *sta_key_conf,
2559 struct sk_buff *skb,
2560 struct ieee80211_key_conf *key,
2561 enum set_key_cmd cmd)
2563 struct sta_rec_sec *sec;
2564 u32 len = sizeof(*sec);
2567 tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_KEY_V2, sizeof(*sec));
2568 sec = (struct sta_rec_sec *)tlv;
2571 if (cmd == SET_KEY) {
2572 struct sec_key *sec_key;
2575 cipher = mt76_connac_mcu_get_cipher(key->cipher);
2576 if (cipher == MCU_CIPHER_NONE)
2579 sec_key = &sec->key[0];
2580 sec_key->cipher_len = sizeof(*sec_key);
2582 if (cipher == MCU_CIPHER_BIP_CMAC_128) {
2583 sec_key->cipher_id = MCU_CIPHER_AES_CCMP;
2584 sec_key->key_id = sta_key_conf->keyidx;
2585 sec_key->key_len = 16;
2586 memcpy(sec_key->key, sta_key_conf->key, 16);
2588 sec_key = &sec->key[1];
2589 sec_key->cipher_id = MCU_CIPHER_BIP_CMAC_128;
2590 sec_key->cipher_len = sizeof(*sec_key);
2591 sec_key->key_len = 16;
2592 memcpy(sec_key->key, key->key, 16);
2595 sec_key->cipher_id = cipher;
2596 sec_key->key_id = key->keyidx;
2597 sec_key->key_len = key->keylen;
2598 memcpy(sec_key->key, key->key, key->keylen);
2600 if (cipher == MCU_CIPHER_TKIP) {
2601 /* Rx/Tx MIC keys are swapped */
2602 memcpy(sec_key->key + 16, key->key + 24, 8);
2603 memcpy(sec_key->key + 24, key->key + 16, 8);
2606 /* store key_conf for BIP batch update */
2607 if (cipher == MCU_CIPHER_AES_CCMP) {
2608 memcpy(sta_key_conf->key, key->key, key->keylen);
2609 sta_key_conf->keyidx = key->keyidx;
2612 len -= sizeof(*sec_key);
2616 len -= sizeof(sec->key);
2619 sec->len = cpu_to_le16(len);
2624 int mt76_connac_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
2625 struct mt76_connac_sta_key_conf *sta_key_conf,
2626 struct ieee80211_key_conf *key, int mcu_cmd,
2627 struct mt76_wcid *wcid, enum set_key_cmd cmd)
2629 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
2630 struct sk_buff *skb;
2633 skb = mt76_connac_mcu_alloc_sta_req(dev, mvif, wcid);
2635 return PTR_ERR(skb);
2637 ret = mt76_connac_mcu_sta_key_tlv(sta_key_conf, skb, key, cmd);
2641 return mt76_mcu_skb_send_msg(dev, skb, mcu_cmd, true);
2643 EXPORT_SYMBOL_GPL(mt76_connac_mcu_add_key);
2645 /* SIFS 20us + 512 byte beacon tranmitted by 1Mbps (3906us) */
2646 #define BCN_TX_ESTIMATE_TIME (4096 + 20)
2647 void mt76_connac_mcu_bss_ext_tlv(struct sk_buff *skb, struct mt76_vif *mvif)
2649 struct bss_info_ext_bss *ext;
2650 int ext_bss_idx, tsf_offset;
2653 ext_bss_idx = mvif->omac_idx - EXT_BSSID_START;
2654 if (ext_bss_idx < 0)
2657 tlv = mt76_connac_mcu_add_tlv(skb, BSS_INFO_EXT_BSS, sizeof(*ext));
2659 ext = (struct bss_info_ext_bss *)tlv;
2660 tsf_offset = ext_bss_idx * BCN_TX_ESTIMATE_TIME;
2661 ext->mbss_tsf_offset = cpu_to_le32(tsf_offset);
2663 EXPORT_SYMBOL_GPL(mt76_connac_mcu_bss_ext_tlv);
2665 int mt76_connac_mcu_bss_basic_tlv(struct sk_buff *skb,
2666 struct ieee80211_vif *vif,
2667 struct ieee80211_sta *sta,
2668 struct mt76_phy *phy, u16 wlan_idx,
2671 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
2672 u32 type = vif->p2p ? NETWORK_P2P : NETWORK_INFRA;
2673 struct bss_info_basic *bss;
2676 tlv = mt76_connac_mcu_add_tlv(skb, BSS_INFO_BASIC, sizeof(*bss));
2677 bss = (struct bss_info_basic *)tlv;
2679 switch (vif->type) {
2680 case NL80211_IFTYPE_MESH_POINT:
2681 case NL80211_IFTYPE_MONITOR:
2683 case NL80211_IFTYPE_AP:
2684 if (ieee80211_hw_check(phy->hw, SUPPORTS_MULTI_BSSID)) {
2685 u8 bssid_id = vif->bss_conf.bssid_indicator;
2686 struct wiphy *wiphy = phy->hw->wiphy;
2688 if (bssid_id > ilog2(wiphy->mbssid_max_interfaces))
2691 bss->non_tx_bssid = vif->bss_conf.bssid_index;
2692 bss->max_bssid = bssid_id;
2695 case NL80211_IFTYPE_STATION:
2699 sta = ieee80211_find_sta(vif,
2700 vif->bss_conf.bssid);
2701 /* TODO: enable BSS_INFO_UAPSD & BSS_INFO_PM */
2703 struct mt76_wcid *wcid;
2705 wcid = (struct mt76_wcid *)sta->drv_priv;
2706 wlan_idx = wcid->idx;
2711 case NL80211_IFTYPE_ADHOC:
2712 type = NETWORK_IBSS;
2719 bss->network_type = cpu_to_le32(type);
2720 bss->bmc_wcid_lo = to_wcid_lo(wlan_idx);
2721 bss->bmc_wcid_hi = to_wcid_hi(wlan_idx);
2722 bss->wmm_idx = mvif->wmm_idx;
2723 bss->active = enable;
2724 bss->cipher = mvif->cipher;
2726 if (vif->type != NL80211_IFTYPE_MONITOR) {
2727 struct cfg80211_chan_def *chandef = &phy->chandef;
2729 memcpy(bss->bssid, vif->bss_conf.bssid, ETH_ALEN);
2730 bss->bcn_interval = cpu_to_le16(vif->bss_conf.beacon_int);
2731 bss->dtim_period = vif->bss_conf.dtim_period;
2732 bss->phy_mode = mt76_connac_get_phy_mode(phy, vif,
2733 chandef->chan->band, NULL);
2735 memcpy(bss->bssid, phy->macaddr, ETH_ALEN);
2740 EXPORT_SYMBOL_GPL(mt76_connac_mcu_bss_basic_tlv);
2742 #define ENTER_PM_STATE 1
2743 #define EXIT_PM_STATE 2
2744 int mt76_connac_mcu_set_pm(struct mt76_dev *dev, int band, int enter)
2752 __le16 bcn_interval;
2765 .pm_state = enter ? ENTER_PM_STATE : EXIT_PM_STATE,
2769 return mt76_mcu_send_msg(dev, MCU_EXT_CMD(PM_STATE_CTRL), &req,
2772 EXPORT_SYMBOL_GPL(mt76_connac_mcu_set_pm);
2774 int mt76_connac_mcu_restart(struct mt76_dev *dev)
2783 return mt76_mcu_send_msg(dev, MCU_CMD(NIC_POWER_CTRL), &req,
2784 sizeof(req), false);
2786 EXPORT_SYMBOL_GPL(mt76_connac_mcu_restart);
2788 int mt76_connac_mcu_rdd_cmd(struct mt76_dev *dev, int cmd, u8 index,
2800 .rdd_rx_sel = rx_sel,
2804 return mt76_mcu_send_msg(dev, MCU_EXT_CMD(SET_RDD_CTRL), &req,
2807 EXPORT_SYMBOL_GPL(mt76_connac_mcu_rdd_cmd);
2809 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo@kernel.org>");
2810 MODULE_LICENSE("Dual BSD/GPL");