1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2023 MediaTek Inc. */
5 #include <linux/firmware.h>
10 #define MT_STA_BFER BIT(0)
11 #define MT_STA_BFEE BIT(1)
13 static bool mt7925_disable_clc
;
14 module_param_named(disable_clc
, mt7925_disable_clc
, bool, 0644);
15 MODULE_PARM_DESC(disable_clc
, "disable CLC support");
17 int mt7925_mcu_parse_response(struct mt76_dev
*mdev
, int cmd
,
18 struct sk_buff
*skb
, int seq
)
20 int mcu_cmd
= FIELD_GET(__MCU_CMD_FIELD_ID
, cmd
);
21 struct mt7925_mcu_rxd
*rxd
;
25 dev_err(mdev
->dev
, "Message %08x (seq %d) timeout\n", cmd
, seq
);
31 rxd
= (struct mt7925_mcu_rxd
*)skb
->data
;
35 if (cmd
== MCU_CMD(PATCH_SEM_CONTROL
) ||
36 cmd
== MCU_CMD(PATCH_FINISH_REQ
)) {
37 skb_pull(skb
, sizeof(*rxd
) - 4);
39 } else if (cmd
== MCU_UNI_CMD(DEV_INFO_UPDATE
) ||
40 cmd
== MCU_UNI_CMD(BSS_INFO_UPDATE
) ||
41 cmd
== MCU_UNI_CMD(STA_REC_UPDATE
) ||
42 cmd
== MCU_UNI_CMD(HIF_CTRL
) ||
43 cmd
== MCU_UNI_CMD(OFFLOAD
) ||
44 cmd
== MCU_UNI_CMD(SUSPEND
)) {
45 struct mt7925_mcu_uni_event
*event
;
47 skb_pull(skb
, sizeof(*rxd
));
48 event
= (struct mt7925_mcu_uni_event
*)skb
->data
;
49 ret
= le32_to_cpu(event
->status
);
50 /* skip invalid event */
51 if (mcu_cmd
!= event
->cid
)
54 skb_pull(skb
, sizeof(*rxd
));
59 EXPORT_SYMBOL_GPL(mt7925_mcu_parse_response
);
61 int mt7925_mcu_regval(struct mt792x_dev
*dev
, u32 regidx
, u32
*val
, bool set
)
63 #define MT_RF_REG_HDR GENMASK(31, 24)
64 #define MT_RF_REG_ANT GENMASK(23, 16)
65 #define RF_REG_PREFIX 0x99
69 struct uni_cmd_access_reg_basic
{
75 struct uni_cmd_access_rf_reg_basic
{
84 } __packed
* res
, req
;
88 if (u32_get_bits(regidx
, MT_RF_REG_HDR
) == RF_REG_PREFIX
) {
89 req
.rf_reg
.tag
= cpu_to_le16(UNI_CMD_ACCESS_RF_REG_BASIC
);
90 req
.rf_reg
.len
= cpu_to_le16(sizeof(req
.rf_reg
));
91 req
.rf_reg
.ant
= cpu_to_le16(u32_get_bits(regidx
, MT_RF_REG_ANT
));
92 req
.rf_reg
.idx
= cpu_to_le32(regidx
);
93 req
.rf_reg
.data
= set
? cpu_to_le32(*val
) : 0;
95 req
.reg
.tag
= cpu_to_le16(UNI_CMD_ACCESS_REG_BASIC
);
96 req
.reg
.len
= cpu_to_le16(sizeof(req
.reg
));
97 req
.reg
.idx
= cpu_to_le32(regidx
);
98 req
.reg
.data
= set
? cpu_to_le32(*val
) : 0;
102 return mt76_mcu_send_msg(&dev
->mt76
, MCU_WM_UNI_CMD(REG_ACCESS
),
103 &req
, sizeof(req
), true);
105 ret
= mt76_mcu_send_and_get_msg(&dev
->mt76
,
106 MCU_WM_UNI_CMD_QUERY(REG_ACCESS
),
107 &req
, sizeof(req
), true, &skb
);
111 res
= (void *)skb
->data
;
112 if (u32_get_bits(regidx
, MT_RF_REG_HDR
) == RF_REG_PREFIX
)
113 *val
= le32_to_cpu(res
->rf_reg
.data
);
115 *val
= le32_to_cpu(res
->reg
.data
);
121 EXPORT_SYMBOL_GPL(mt7925_mcu_regval
);
123 int mt7925_mcu_update_arp_filter(struct mt76_dev
*dev
,
124 struct ieee80211_bss_conf
*link_conf
)
126 struct ieee80211_vif
*mvif
= container_of((void *)link_conf
->vif
,
127 struct ieee80211_vif
,
129 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(link_conf
);
131 int i
, len
= min_t(int, mvif
->cfg
.arp_addr_cnt
,
132 IEEE80211_BSS_ARP_ADDR_LIST_LEN
);
138 struct mt7925_arpns_tlv arp
;
141 .bss_idx
= mconf
->mt76
.idx
,
144 .tag
= cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ARP
),
145 .len
= cpu_to_le16(sizeof(req
) - 4 + len
* 2 * sizeof(__be32
)),
151 skb
= mt76_mcu_msg_alloc(dev
, NULL
, sizeof(req
) + len
* 2 * sizeof(__be32
));
155 skb_put_data(skb
, &req
, sizeof(req
));
156 for (i
= 0; i
< len
; i
++) {
157 skb_put_data(skb
, &mvif
->cfg
.arp_addr_list
[i
], sizeof(__be32
));
158 skb_put_zero(skb
, sizeof(__be32
));
161 return mt76_mcu_skb_send_msg(dev
, skb
, MCU_UNI_CMD(OFFLOAD
), true);
166 mt7925_connac_mcu_set_wow_ctrl(struct mt76_phy
*phy
, struct ieee80211_vif
*vif
,
167 bool suspend
, struct cfg80211_wowlan
*wowlan
)
169 struct mt76_vif
*mvif
= (struct mt76_vif
*)vif
->drv_priv
;
170 struct mt76_dev
*dev
= phy
->dev
;
176 struct mt76_connac_wow_ctrl_tlv wow_ctrl_tlv
;
177 struct mt76_connac_wow_gpio_param_tlv gpio_tlv
;
180 .bss_idx
= mvif
->idx
,
183 .tag
= cpu_to_le16(UNI_SUSPEND_WOW_CTRL
),
184 .len
= cpu_to_le16(sizeof(struct mt76_connac_wow_ctrl_tlv
)),
185 .cmd
= suspend
? 1 : 2,
188 .tag
= cpu_to_le16(UNI_SUSPEND_WOW_GPIO_PARAM
),
189 .len
= cpu_to_le16(sizeof(struct mt76_connac_wow_gpio_param_tlv
)),
190 .gpio_pin
= 0xff, /* follow fw about GPIO pin */
194 if (wowlan
->magic_pkt
)
195 req
.wow_ctrl_tlv
.trigger
|= UNI_WOW_DETECT_TYPE_MAGIC
;
196 if (wowlan
->disconnect
)
197 req
.wow_ctrl_tlv
.trigger
|= (UNI_WOW_DETECT_TYPE_DISCONNECT
|
198 UNI_WOW_DETECT_TYPE_BCN_LOST
);
199 if (wowlan
->nd_config
) {
200 mt7925_mcu_sched_scan_req(phy
, vif
, wowlan
->nd_config
);
201 req
.wow_ctrl_tlv
.trigger
|= UNI_WOW_DETECT_TYPE_SCH_SCAN_HIT
;
202 mt7925_mcu_sched_scan_enable(phy
, vif
, suspend
);
204 if (wowlan
->n_patterns
)
205 req
.wow_ctrl_tlv
.trigger
|= UNI_WOW_DETECT_TYPE_BITMAP
;
207 if (mt76_is_mmio(dev
))
208 req
.wow_ctrl_tlv
.wakeup_hif
= WOW_PCIE
;
209 else if (mt76_is_usb(dev
))
210 req
.wow_ctrl_tlv
.wakeup_hif
= WOW_USB
;
211 else if (mt76_is_sdio(dev
))
212 req
.wow_ctrl_tlv
.wakeup_hif
= WOW_GPIO
;
214 return mt76_mcu_send_msg(dev
, MCU_UNI_CMD(SUSPEND
), &req
,
219 mt7925_mcu_set_wow_pattern(struct mt76_dev
*dev
,
220 struct ieee80211_vif
*vif
,
221 u8 index
, bool enable
,
222 struct cfg80211_pkt_pattern
*pattern
)
224 struct mt76_vif
*mvif
= (struct mt76_vif
*)vif
->drv_priv
;
225 struct mt7925_wow_pattern_tlv
*tlv
;
231 .bss_idx
= mvif
->idx
,
234 skb
= mt76_mcu_msg_alloc(dev
, NULL
, sizeof(hdr
) + sizeof(*tlv
));
238 skb_put_data(skb
, &hdr
, sizeof(hdr
));
239 tlv
= (struct mt7925_wow_pattern_tlv
*)skb_put(skb
, sizeof(*tlv
));
240 tlv
->tag
= cpu_to_le16(UNI_SUSPEND_WOW_PATTERN
);
241 tlv
->len
= cpu_to_le16(sizeof(*tlv
));
243 tlv
->data_len
= pattern
->pattern_len
;
244 tlv
->enable
= enable
;
248 memcpy(tlv
->pattern
, pattern
->pattern
, pattern
->pattern_len
);
249 memcpy(tlv
->mask
, pattern
->mask
, DIV_ROUND_UP(pattern
->pattern_len
, 8));
251 return mt76_mcu_skb_send_msg(dev
, skb
, MCU_UNI_CMD(SUSPEND
), true);
254 void mt7925_mcu_set_suspend_iter(void *priv
, u8
*mac
,
255 struct ieee80211_vif
*vif
)
257 struct mt76_phy
*phy
= priv
;
258 bool suspend
= !test_bit(MT76_STATE_RUNNING
, &phy
->state
);
259 struct ieee80211_hw
*hw
= phy
->hw
;
260 struct cfg80211_wowlan
*wowlan
= hw
->wiphy
->wowlan_config
;
263 mt76_connac_mcu_set_gtk_rekey(phy
->dev
, vif
, suspend
);
265 mt76_connac_mcu_set_suspend_mode(phy
->dev
, vif
, suspend
, 1, true);
267 for (i
= 0; i
< wowlan
->n_patterns
; i
++)
268 mt7925_mcu_set_wow_pattern(phy
->dev
, vif
, i
, suspend
,
269 &wowlan
->patterns
[i
]);
270 mt7925_connac_mcu_set_wow_ctrl(phy
, vif
, suspend
, wowlan
);
273 #endif /* CONFIG_PM */
276 mt7925_mcu_connection_loss_iter(void *priv
, u8
*mac
,
277 struct ieee80211_vif
*vif
)
279 struct mt76_vif
*mvif
= (struct mt76_vif
*)vif
->drv_priv
;
280 struct mt7925_uni_beacon_loss_event
*event
= priv
;
282 if (mvif
->idx
!= event
->hdr
.bss_idx
)
285 if (!(vif
->driver_flags
& IEEE80211_VIF_BEACON_FILTER
) ||
286 vif
->type
!= NL80211_IFTYPE_STATION
)
289 ieee80211_connection_loss(vif
);
293 mt7925_mcu_connection_loss_event(struct mt792x_dev
*dev
, struct sk_buff
*skb
)
295 struct mt7925_uni_beacon_loss_event
*event
;
296 struct mt76_phy
*mphy
= &dev
->mt76
.phy
;
298 skb_pull(skb
, sizeof(struct mt7925_mcu_rxd
));
299 event
= (struct mt7925_uni_beacon_loss_event
*)skb
->data
;
301 ieee80211_iterate_active_interfaces_atomic(mphy
->hw
,
302 IEEE80211_IFACE_ITER_RESUME_ALL
,
303 mt7925_mcu_connection_loss_iter
, event
);
307 mt7925_mcu_roc_iter(void *priv
, u8
*mac
, struct ieee80211_vif
*vif
)
309 struct mt76_vif
*mvif
= (struct mt76_vif
*)vif
->drv_priv
;
310 struct mt7925_roc_grant_tlv
*grant
= priv
;
312 if (ieee80211_vif_is_mld(vif
) && vif
->type
== NL80211_IFTYPE_STATION
)
315 if (mvif
->idx
!= grant
->bss_idx
)
318 mvif
->band_idx
= grant
->dbdcband
;
321 static void mt7925_mcu_roc_handle_grant(struct mt792x_dev
*dev
,
324 struct ieee80211_hw
*hw
= dev
->mt76
.hw
;
325 struct mt7925_roc_grant_tlv
*grant
;
328 grant
= (struct mt7925_roc_grant_tlv
*)tlv
;
330 /* should never happen */
331 WARN_ON_ONCE((le16_to_cpu(grant
->tag
) != UNI_EVENT_ROC_GRANT
));
333 if (grant
->reqtype
== MT7925_ROC_REQ_ROC
)
334 ieee80211_ready_on_channel(hw
);
335 else if (grant
->reqtype
== MT7925_ROC_REQ_JOIN
)
336 ieee80211_iterate_active_interfaces_atomic(hw
,
337 IEEE80211_IFACE_ITER_RESUME_ALL
,
338 mt7925_mcu_roc_iter
, grant
);
339 dev
->phy
.roc_grant
= true;
340 wake_up(&dev
->phy
.roc_wait
);
341 duration
= le32_to_cpu(grant
->max_interval
);
342 mod_timer(&dev
->phy
.roc_timer
,
343 jiffies
+ msecs_to_jiffies(duration
));
347 mt7925_mcu_uni_roc_event(struct mt792x_dev
*dev
, struct sk_buff
*skb
)
352 skb_pull(skb
, sizeof(struct mt7925_mcu_rxd
) + 4);
354 while (i
< skb
->len
) {
355 tlv
= (struct tlv
*)(skb
->data
+ i
);
357 switch (le16_to_cpu(tlv
->tag
)) {
358 case UNI_EVENT_ROC_GRANT
:
359 mt7925_mcu_roc_handle_grant(dev
, tlv
);
361 case UNI_EVENT_ROC_GRANT_SUB_LINK
:
365 i
+= le16_to_cpu(tlv
->len
);
370 mt7925_mcu_scan_event(struct mt792x_dev
*dev
, struct sk_buff
*skb
)
372 struct mt76_phy
*mphy
= &dev
->mt76
.phy
;
373 struct mt792x_phy
*phy
= mphy
->priv
;
375 spin_lock_bh(&dev
->mt76
.lock
);
376 __skb_queue_tail(&phy
->scan_event_list
, skb
);
377 spin_unlock_bh(&dev
->mt76
.lock
);
379 ieee80211_queue_delayed_work(mphy
->hw
, &phy
->scan_work
,
380 MT792x_HW_SCAN_TIMEOUT
);
384 mt7925_mcu_tx_done_event(struct mt792x_dev
*dev
, struct sk_buff
*skb
)
386 #define UNI_EVENT_TX_DONE_MSG 0
387 #define UNI_EVENT_TX_DONE_RAW 1
388 struct mt7925_mcu_txs_event
{
396 skb_pull(skb
, sizeof(struct mt7925_mcu_rxd
) + 4);
397 tlv
= (struct tlv
*)skb
->data
;
400 while (tlv_len
> 0 && le16_to_cpu(tlv
->len
) <= tlv_len
) {
401 switch (le16_to_cpu(tlv
->tag
)) {
402 case UNI_EVENT_TX_DONE_RAW
:
403 txs
= (struct mt7925_mcu_txs_event
*)tlv
->data
;
404 mt7925_mac_add_txs(dev
, txs
->data
);
409 tlv_len
-= le16_to_cpu(tlv
->len
);
410 tlv
= (struct tlv
*)((char *)(tlv
) + le16_to_cpu(tlv
->len
));
415 mt7925_mcu_uni_debug_msg_event(struct mt792x_dev
*dev
, struct sk_buff
*skb
)
417 struct mt7925_uni_debug_msg
{
441 skb_pull(skb
, sizeof(struct mt7925_mcu_rxd
) + 4);
442 hdr
= (struct mt7925_uni_debug_msg
*)skb
->data
;
444 if (hdr
->id
== 0x28) {
445 skb_pull(skb
, offsetof(struct mt7925_uni_debug_msg
, id
));
446 wiphy_info(mt76_hw(dev
)->wiphy
, "%.*s", skb
->len
, skb
->data
);
448 } else if (hdr
->id
!= 0xa8) {
452 if (hdr
->type
== 0) { /* idx log */
453 int i
, ret
, len
= PAGE_SIZE
- 1, nr_val
;
454 struct page
*page
= dev_alloc_pages(get_order(len
));
461 buf
= page_address(page
);
464 nr_val
= (le16_to_cpu(hdr
->len
) - sizeof(*hdr
)) / 4;
465 val
= (__le32
*)hdr
->idx
.data
;
466 for (i
= 0; i
< nr_val
&& len
> 0; i
++) {
467 ret
= snprintf(cur
, len
, "0x%x,", le32_to_cpu(val
[i
]));
475 wiphy_info(mt76_hw(dev
)->wiphy
, "idx: 0x%X,%d,%s",
476 le32_to_cpu(hdr
->idx
.idx
), nr_val
, buf
);
478 } else if (hdr
->type
== 2) { /* str log */
479 wiphy_info(mt76_hw(dev
)->wiphy
, "%.*s", hdr
->txt
.len
, hdr
->txt
.data
);
484 mt7925_mcu_uni_rx_unsolicited_event(struct mt792x_dev
*dev
,
487 struct mt7925_mcu_rxd
*rxd
;
489 rxd
= (struct mt7925_mcu_rxd
*)skb
->data
;
492 case MCU_UNI_EVENT_FW_LOG_2_HOST
:
493 mt7925_mcu_uni_debug_msg_event(dev
, skb
);
495 case MCU_UNI_EVENT_ROC
:
496 mt7925_mcu_uni_roc_event(dev
, skb
);
498 case MCU_UNI_EVENT_SCAN_DONE
:
499 mt7925_mcu_scan_event(dev
, skb
);
501 case MCU_UNI_EVENT_TX_DONE
:
502 mt7925_mcu_tx_done_event(dev
, skb
);
504 case MCU_UNI_EVENT_BSS_BEACON_LOSS
:
505 mt7925_mcu_connection_loss_event(dev
, skb
);
507 case MCU_UNI_EVENT_COREDUMP
:
508 dev
->fw_assert
= true;
509 mt76_connac_mcu_coredump_event(&dev
->mt76
, skb
, &dev
->coredump
);
517 void mt7925_mcu_rx_event(struct mt792x_dev
*dev
, struct sk_buff
*skb
)
519 struct mt7925_mcu_rxd
*rxd
= (struct mt7925_mcu_rxd
*)skb
->data
;
521 if (skb_linearize(skb
))
524 if (rxd
->option
& MCU_UNI_CMD_UNSOLICITED_EVENT
) {
525 mt7925_mcu_uni_rx_unsolicited_event(dev
, skb
);
529 mt76_mcu_rx_event(&dev
->mt76
, skb
);
533 mt7925_mcu_sta_ba(struct mt76_dev
*dev
, struct mt76_vif
*mvif
,
534 struct ieee80211_ampdu_params
*params
,
535 bool enable
, bool tx
)
537 struct mt76_wcid
*wcid
= (struct mt76_wcid
*)params
->sta
->drv_priv
;
538 struct sta_rec_ba_uni
*ba
;
543 len
= sizeof(struct sta_req_hdr
) + sizeof(*ba
);
544 skb
= __mt76_connac_mcu_alloc_sta_req(dev
, mvif
, wcid
,
549 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_BA
, sizeof(*ba
));
551 ba
= (struct sta_rec_ba_uni
*)tlv
;
552 ba
->ba_type
= tx
? MT_BA_TYPE_ORIGINATOR
: MT_BA_TYPE_RECIPIENT
;
553 ba
->winsize
= cpu_to_le16(params
->buf_size
);
554 ba
->ssn
= cpu_to_le16(params
->ssn
);
555 ba
->ba_en
= enable
<< params
->tid
;
556 ba
->amsdu
= params
->amsdu
;
557 ba
->tid
= params
->tid
;
559 return mt76_mcu_skb_send_msg(dev
, skb
,
560 MCU_UNI_CMD(STA_REC_UPDATE
), true);
563 /** starec & wtbl **/
564 int mt7925_mcu_uni_tx_ba(struct mt792x_dev
*dev
,
565 struct ieee80211_ampdu_params
*params
,
568 struct mt792x_sta
*msta
= (struct mt792x_sta
*)params
->sta
->drv_priv
;
569 struct mt792x_vif
*mvif
= msta
->vif
;
571 if (enable
&& !params
->amsdu
)
572 msta
->deflink
.wcid
.amsdu
= false;
574 return mt7925_mcu_sta_ba(&dev
->mt76
, &mvif
->bss_conf
.mt76
, params
,
578 int mt7925_mcu_uni_rx_ba(struct mt792x_dev
*dev
,
579 struct ieee80211_ampdu_params
*params
,
582 struct mt792x_sta
*msta
= (struct mt792x_sta
*)params
->sta
->drv_priv
;
583 struct mt792x_vif
*mvif
= msta
->vif
;
585 return mt7925_mcu_sta_ba(&dev
->mt76
, &mvif
->bss_conf
.mt76
, params
,
589 static int mt7925_load_clc(struct mt792x_dev
*dev
, const char *fw_name
)
591 const struct mt76_connac2_fw_trailer
*hdr
;
592 const struct mt76_connac2_fw_region
*region
;
593 const struct mt7925_clc
*clc
;
594 struct mt76_dev
*mdev
= &dev
->mt76
;
595 struct mt792x_phy
*phy
= &dev
->phy
;
596 const struct firmware
*fw
;
597 int ret
, i
, len
, offset
= 0;
600 if (mt7925_disable_clc
||
601 mt76_is_usb(&dev
->mt76
))
604 ret
= request_firmware(&fw
, fw_name
, mdev
->dev
);
608 if (!fw
|| !fw
->data
|| fw
->size
< sizeof(*hdr
)) {
609 dev_err(mdev
->dev
, "Invalid firmware\n");
614 hdr
= (const void *)(fw
->data
+ fw
->size
- sizeof(*hdr
));
615 for (i
= 0; i
< hdr
->n_region
; i
++) {
616 region
= (const void *)((const u8
*)hdr
-
617 (hdr
->n_region
- i
) * sizeof(*region
));
618 len
= le32_to_cpu(region
->len
);
620 /* check if we have valid buffer size */
621 if (offset
+ len
> fw
->size
) {
622 dev_err(mdev
->dev
, "Invalid firmware region\n");
627 if ((region
->feature_set
& FW_FEATURE_NON_DL
) &&
628 region
->type
== FW_TYPE_CLC
) {
629 clc_base
= (u8
*)(fw
->data
+ offset
);
638 for (offset
= 0; offset
< len
; offset
+= le32_to_cpu(clc
->len
)) {
639 clc
= (const struct mt7925_clc
*)(clc_base
+ offset
);
641 if (clc
->idx
> ARRAY_SIZE(phy
->clc
))
644 /* do not init buf again if chip reset triggered */
645 if (phy
->clc
[clc
->idx
])
648 phy
->clc
[clc
->idx
] = devm_kmemdup(mdev
->dev
, clc
,
649 le32_to_cpu(clc
->len
),
652 if (!phy
->clc
[clc
->idx
]) {
658 ret
= mt7925_mcu_set_clc(dev
, "00", ENVIRON_INDOOR
);
660 release_firmware(fw
);
665 int mt7925_mcu_fw_log_2_host(struct mt792x_dev
*dev
, u8 ctrl
)
676 .tag
= cpu_to_le16(UNI_WSYS_CONFIG_FW_LOG_CTRL
),
677 .len
= cpu_to_le16(sizeof(req
) - 4),
682 ret
= mt76_mcu_send_and_get_msg(&dev
->mt76
, MCU_UNI_CMD(WSYS_CONFIG
),
683 &req
, sizeof(req
), false, NULL
);
687 int mt7925_mcu_get_temperature(struct mt792x_phy
*phy
)
696 .tag
= cpu_to_le16(0x0),
697 .len
= cpu_to_le16(sizeof(req
) - 4),
699 struct mt7925_thermal_evt
{
703 struct mt792x_dev
*dev
= phy
->dev
;
704 int temperature
, ret
;
707 ret
= mt76_mcu_send_and_get_msg(&dev
->mt76
,
708 MCU_WM_UNI_CMD_QUERY(THERMAL
),
709 &req
, sizeof(req
), true, &skb
);
713 skb_pull(skb
, 4 + sizeof(struct tlv
));
714 evt
= (struct mt7925_thermal_evt
*)skb
->data
;
716 temperature
= le32_to_cpu(evt
->temperature
);
724 mt7925_mcu_parse_phy_cap(struct mt792x_dev
*dev
, char *data
)
726 struct mt76_phy
*mphy
= &dev
->mt76
.phy
;
727 struct mt76_dev
*mdev
= mphy
->dev
;
728 struct mt7925_mcu_phy_cap
{
748 cap
= (struct mt7925_mcu_phy_cap
*)data
;
750 mdev
->phy
.antenna_mask
= BIT(cap
->nss
) - 1;
751 mdev
->phy
.chainmask
= mdev
->phy
.antenna_mask
;
752 mdev
->phy
.cap
.has_2ghz
= cap
->hw_path
& BIT(WF0_24G
);
753 mdev
->phy
.cap
.has_5ghz
= cap
->hw_path
& BIT(WF0_5G
);
754 dev
->has_eht
= cap
->eht
;
758 mt7925_mcu_parse_eml_cap(struct mt792x_dev
*dev
, char *data
)
760 struct mt7925_mcu_eml_cap
{
766 cap
= (struct mt7925_mcu_eml_cap
*)data
;
768 dev
->phy
.eml_cap
= le16_to_cpu(cap
->eml_cap
);
772 mt7925_mcu_get_nic_capability(struct mt792x_dev
*dev
)
774 struct mt76_phy
*mphy
= &dev
->mt76
.phy
;
781 .tag
= cpu_to_le16(UNI_CHIP_CONFIG_NIC_CAPA
),
782 .len
= cpu_to_le16(sizeof(req
) - 4),
784 struct mt76_connac_cap_hdr
{
791 ret
= mt76_mcu_send_and_get_msg(&dev
->mt76
, MCU_UNI_CMD(CHIP_CONFIG
),
792 &req
, sizeof(req
), true, &skb
);
796 hdr
= (struct mt76_connac_cap_hdr
*)skb
->data
;
797 if (skb
->len
< sizeof(*hdr
)) {
802 skb_pull(skb
, sizeof(*hdr
));
804 for (i
= 0; i
< le16_to_cpu(hdr
->n_element
); i
++) {
805 struct tlv
*tlv
= (struct tlv
*)skb
->data
;
808 if (skb
->len
< sizeof(*tlv
))
811 len
= le16_to_cpu(tlv
->len
);
815 switch (le16_to_cpu(tlv
->tag
)) {
817 mphy
->cap
.has_6ghz
= !!tlv
->data
[0];
819 case MT_NIC_CAP_MAC_ADDR
:
820 memcpy(mphy
->macaddr
, (void *)tlv
->data
, ETH_ALEN
);
823 mt7925_mcu_parse_phy_cap(dev
, tlv
->data
);
825 case MT_NIC_CAP_CHIP_CAP
:
826 memcpy(&dev
->phy
.chip_cap
, (void *)skb
->data
, sizeof(u64
));
828 case MT_NIC_CAP_EML_CAP
:
829 mt7925_mcu_parse_eml_cap(dev
, tlv
->data
);
841 int mt7925_mcu_chip_config(struct mt792x_dev
*dev
, const char *cmd
)
843 u16 len
= strlen(cmd
) + 1;
848 struct mt76_connac_config config
;
850 .tag
= cpu_to_le16(UNI_CHIP_CONFIG_CHIP_CFG
),
851 .len
= cpu_to_le16(sizeof(req
) - 4),
855 .data_size
= cpu_to_le16(len
),
859 memcpy(req
.config
.data
, cmd
, len
);
861 return mt76_mcu_send_msg(&dev
->mt76
, MCU_UNI_CMD(CHIP_CONFIG
),
862 &req
, sizeof(req
), false);
865 int mt7925_mcu_set_deep_sleep(struct mt792x_dev
*dev
, bool enable
)
869 snprintf(cmd
, sizeof(cmd
), "KeepFullPwr %d", !enable
);
871 return mt7925_mcu_chip_config(dev
, cmd
);
873 EXPORT_SYMBOL_GPL(mt7925_mcu_set_deep_sleep
);
875 int mt7925_run_firmware(struct mt792x_dev
*dev
)
879 err
= mt792x_load_firmware(dev
);
883 err
= mt7925_mcu_get_nic_capability(dev
);
887 set_bit(MT76_STATE_MCU_RUNNING
, &dev
->mphy
.state
);
888 err
= mt7925_load_clc(dev
, mt792x_ram_name(dev
));
892 return mt7925_mcu_fw_log_2_host(dev
, 1);
894 EXPORT_SYMBOL_GPL(mt7925_run_firmware
);
897 mt7925_mcu_sta_hdr_trans_tlv(struct sk_buff
*skb
,
898 struct ieee80211_vif
*vif
,
899 struct ieee80211_link_sta
*link_sta
)
901 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
902 struct sta_rec_hdr_trans
*hdr_trans
;
903 struct mt76_wcid
*wcid
;
906 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_HDR_TRANS
, sizeof(*hdr_trans
));
907 hdr_trans
= (struct sta_rec_hdr_trans
*)tlv
;
908 hdr_trans
->dis_rx_hdr_tran
= true;
910 if (vif
->type
== NL80211_IFTYPE_STATION
)
911 hdr_trans
->to_ds
= true;
913 hdr_trans
->from_ds
= true;
916 struct mt792x_sta
*msta
= (struct mt792x_sta
*)link_sta
->sta
->drv_priv
;
917 struct mt792x_link_sta
*mlink
;
919 mlink
= mt792x_sta_to_link(msta
, link_sta
->link_id
);
922 wcid
= &mvif
->sta
.deflink
.wcid
;
928 hdr_trans
->dis_rx_hdr_tran
= !test_bit(MT_WCID_FLAG_HDR_TRANS
, &wcid
->flags
);
929 if (test_bit(MT_WCID_FLAG_4ADDR
, &wcid
->flags
)) {
930 hdr_trans
->to_ds
= true;
931 hdr_trans
->from_ds
= true;
935 int mt7925_mcu_wtbl_update_hdr_trans(struct mt792x_dev
*dev
,
936 struct ieee80211_vif
*vif
,
937 struct ieee80211_sta
*sta
,
940 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
941 struct ieee80211_link_sta
*link_sta
= sta
? &sta
->deflink
: NULL
;
942 struct mt792x_link_sta
*mlink
;
943 struct mt792x_bss_conf
*mconf
;
944 struct mt792x_sta
*msta
;
947 msta
= sta
? (struct mt792x_sta
*)sta
->drv_priv
: &mvif
->sta
;
949 mlink
= mt792x_sta_to_link(msta
, link_id
);
950 link_sta
= mt792x_sta_to_link_sta(vif
, sta
, link_id
);
951 mconf
= mt792x_vif_to_link(mvif
, link_id
);
953 skb
= __mt76_connac_mcu_alloc_sta_req(&dev
->mt76
, &mconf
->mt76
,
955 MT7925_STA_UPDATE_MAX_SIZE
);
959 /* starec hdr trans */
960 mt7925_mcu_sta_hdr_trans_tlv(skb
, vif
, link_sta
);
961 return mt76_mcu_skb_send_msg(&dev
->mt76
, skb
,
962 MCU_WMWA_UNI_CMD(STA_REC_UPDATE
), true);
965 int mt7925_mcu_set_tx(struct mt792x_dev
*dev
,
966 struct ieee80211_bss_conf
*bss_conf
)
968 #define MCU_EDCA_AC_PARAM 0
969 #define WMM_AIFS_SET BIT(0)
970 #define WMM_CW_MIN_SET BIT(1)
971 #define WMM_CW_MAX_SET BIT(2)
972 #define WMM_TXOP_SET BIT(3)
973 #define WMM_PARAM_SET (WMM_AIFS_SET | WMM_CW_MIN_SET | \
974 WMM_CW_MAX_SET | WMM_TXOP_SET)
975 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(bss_conf
);
980 .bss_idx
= mconf
->mt76
.idx
,
983 int len
= sizeof(hdr
) + IEEE80211_NUM_ACS
* sizeof(struct edca
);
986 skb
= mt76_mcu_msg_alloc(&dev
->mt76
, NULL
, len
);
990 skb_put_data(skb
, &hdr
, sizeof(hdr
));
992 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
993 struct ieee80211_tx_queue_params
*q
= &mconf
->queue_params
[ac
];
997 tlv
= mt76_connac_mcu_add_tlv(skb
, MCU_EDCA_AC_PARAM
, sizeof(*e
));
999 e
= (struct edca
*)tlv
;
1000 e
->set
= WMM_PARAM_SET
;
1003 e
->txop
= cpu_to_le16(q
->txop
);
1006 e
->cw_min
= fls(q
->cw_min
);
1011 e
->cw_max
= fls(q
->cw_max
);
1016 return mt76_mcu_skb_send_msg(&dev
->mt76
, skb
,
1017 MCU_UNI_CMD(EDCA_UPDATE
), true);
1021 mt7925_mcu_sta_key_tlv(struct mt76_wcid
*wcid
,
1022 struct mt76_connac_sta_key_conf
*sta_key_conf
,
1023 struct sk_buff
*skb
,
1024 struct ieee80211_key_conf
*key
,
1025 enum set_key_cmd cmd
,
1026 struct mt792x_sta
*msta
)
1028 struct mt792x_vif
*mvif
= msta
->vif
;
1029 struct mt792x_bss_conf
*mconf
= mt792x_vif_to_link(mvif
, wcid
->link_id
);
1030 struct sta_rec_sec_uni
*sec
;
1031 struct ieee80211_sta
*sta
;
1032 struct ieee80211_vif
*vif
;
1035 sta
= msta
== &mvif
->sta
?
1037 container_of((void *)msta
, struct ieee80211_sta
, drv_priv
);
1038 vif
= container_of((void *)mvif
, struct ieee80211_vif
, drv_priv
);
1040 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_KEY_V3
, sizeof(*sec
));
1041 sec
= (struct sta_rec_sec_uni
*)tlv
;
1042 sec
->bss_idx
= mconf
->mt76
.idx
;
1043 sec
->is_authenticator
= 0;
1044 sec
->mgmt_prot
= 1; /* only used in MLO mode */
1045 sec
->wlan_idx
= (u8
)wcid
->idx
;
1048 struct ieee80211_link_sta
*link_sta
;
1052 link_sta
= mt792x_sta_to_link_sta(vif
, sta
, wcid
->link_id
);
1055 memcpy(sec
->peer_addr
, link_sta
->addr
, ETH_ALEN
);
1057 struct ieee80211_bss_conf
*link_conf
;
1059 link_conf
= mt792x_vif_to_bss_conf(vif
, wcid
->link_id
);
1062 memcpy(sec
->peer_addr
, link_conf
->bssid
, ETH_ALEN
);
1065 if (cmd
== SET_KEY
) {
1069 cipher
= mt7925_mcu_get_cipher(key
->cipher
);
1070 if (cipher
== CONNAC3_CIPHER_NONE
)
1073 if (cipher
== CONNAC3_CIPHER_BIP_CMAC_128
) {
1074 sec
->cipher_id
= CONNAC3_CIPHER_BIP_CMAC_128
;
1075 sec
->key_id
= sta_key_conf
->keyidx
;
1077 memcpy(sec
->key
, sta_key_conf
->key
, 16);
1078 memcpy(sec
->key
+ 16, key
->key
, 16);
1080 sec
->cipher_id
= cipher
;
1081 sec
->key_id
= key
->keyidx
;
1082 sec
->key_len
= key
->keylen
;
1083 memcpy(sec
->key
, key
->key
, key
->keylen
);
1085 if (cipher
== CONNAC3_CIPHER_TKIP
) {
1086 /* Rx/Tx MIC keys are swapped */
1087 memcpy(sec
->key
+ 16, key
->key
+ 24, 8);
1088 memcpy(sec
->key
+ 24, key
->key
+ 16, 8);
1091 /* store key_conf for BIP batch update */
1092 if (cipher
== CONNAC3_CIPHER_AES_CCMP
) {
1093 memcpy(sta_key_conf
->key
, key
->key
, key
->keylen
);
1094 sta_key_conf
->keyidx
= key
->keyidx
;
1104 int mt7925_mcu_add_key(struct mt76_dev
*dev
, struct ieee80211_vif
*vif
,
1105 struct mt76_connac_sta_key_conf
*sta_key_conf
,
1106 struct ieee80211_key_conf
*key
, int mcu_cmd
,
1107 struct mt76_wcid
*wcid
, enum set_key_cmd cmd
,
1108 struct mt792x_sta
*msta
)
1110 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1111 struct mt792x_bss_conf
*mconf
= mt792x_vif_to_link(mvif
, wcid
->link_id
);
1112 struct sk_buff
*skb
;
1115 skb
= __mt76_connac_mcu_alloc_sta_req(dev
, &mconf
->mt76
, wcid
,
1116 MT7925_STA_UPDATE_MAX_SIZE
);
1118 return PTR_ERR(skb
);
1120 ret
= mt7925_mcu_sta_key_tlv(wcid
, sta_key_conf
, skb
, key
, cmd
, msta
);
1124 return mt76_mcu_skb_send_msg(dev
, skb
, mcu_cmd
, true);
1127 int mt7925_mcu_set_mlo_roc(struct mt792x_bss_conf
*mconf
, u16 sel_links
,
1128 int duration
, u8 token_id
)
1130 struct mt792x_vif
*mvif
= mconf
->vif
;
1131 struct ieee80211_vif
*vif
= container_of((void *)mvif
,
1132 struct ieee80211_vif
, drv_priv
);
1133 struct ieee80211_bss_conf
*link_conf
;
1134 struct ieee80211_channel
*chan
;
1135 const u8 ch_band
[] = {
1136 [NL80211_BAND_2GHZ
] = 1,
1137 [NL80211_BAND_5GHZ
] = 2,
1138 [NL80211_BAND_6GHZ
] = 3,
1140 enum mt7925_roc_req type
;
1141 int center_ch
, i
= 0;
1142 bool is_AG_band
= false;
1147 struct mt792x_bss_conf
*mconf
;
1148 struct ieee80211_channel
*chan
;
1155 struct roc_acquire_tlv roc
[2];
1158 if (!mconf
|| hweight16(vif
->valid_links
) < 2 ||
1159 hweight16(sel_links
) != 2)
1162 for (i
= 0; i
< ARRAY_SIZE(links
); i
++) {
1163 links
[i
].id
= i
? __ffs(~BIT(mconf
->link_id
) & sel_links
) :
1165 link_conf
= mt792x_vif_to_bss_conf(vif
, links
[i
].id
);
1166 if (WARN_ON_ONCE(!link_conf
))
1169 links
[i
].chan
= link_conf
->chanreq
.oper
.chan
;
1170 if (WARN_ON_ONCE(!links
[i
].chan
))
1173 links
[i
].mconf
= mt792x_vif_to_link(mvif
, links
[i
].id
);
1174 links
[i
].tag
= links
[i
].id
== mconf
->link_id
?
1175 UNI_ROC_ACQUIRE
: UNI_ROC_SUB_LINK
;
1177 is_AG_band
|= links
[i
].chan
->band
== NL80211_BAND_2GHZ
;
1180 if (vif
->cfg
.eml_cap
& IEEE80211_EML_CAP_EMLSR_SUPP
)
1181 type
= is_AG_band
? MT7925_ROC_REQ_MLSR_AG
:
1182 MT7925_ROC_REQ_MLSR_AA
;
1184 type
= MT7925_ROC_REQ_JOIN
;
1186 for (i
= 0; i
< ARRAY_SIZE(links
) && i
< hweight16(vif
->active_links
); i
++) {
1187 if (WARN_ON_ONCE(!links
[i
].mconf
|| !links
[i
].chan
))
1190 chan
= links
[i
].chan
;
1191 center_ch
= ieee80211_frequency_to_channel(chan
->center_freq
);
1192 req
.roc
[i
].len
= cpu_to_le16(sizeof(struct roc_acquire_tlv
));
1193 req
.roc
[i
].tag
= cpu_to_le16(links
[i
].tag
);
1194 req
.roc
[i
].tokenid
= token_id
;
1195 req
.roc
[i
].reqtype
= type
;
1196 req
.roc
[i
].maxinterval
= cpu_to_le32(duration
);
1197 req
.roc
[i
].bss_idx
= links
[i
].mconf
->mt76
.idx
;
1198 req
.roc
[i
].control_channel
= chan
->hw_value
;
1199 req
.roc
[i
].bw
= CMD_CBW_20MHZ
;
1200 req
.roc
[i
].bw_from_ap
= CMD_CBW_20MHZ
;
1201 req
.roc
[i
].center_chan
= center_ch
;
1202 req
.roc
[i
].center_chan_from_ap
= center_ch
;
1204 /* STR : 0xfe indicates BAND_ALL with enabling DBDC
1205 * EMLSR : 0xff indicates (BAND_AUTO) without DBDC
1207 req
.roc
[i
].dbdcband
= type
== MT7925_ROC_REQ_JOIN
? 0xfe : 0xff;
1209 if (chan
->hw_value
< center_ch
)
1210 req
.roc
[i
].sco
= 1; /* SCA */
1211 else if (chan
->hw_value
> center_ch
)
1212 req
.roc
[i
].sco
= 3; /* SCB */
1214 req
.roc
[i
].band
= ch_band
[chan
->band
];
1217 return mt76_mcu_send_msg(&mvif
->phy
->dev
->mt76
, MCU_UNI_CMD(ROC
),
1218 &req
, sizeof(req
), false);
1221 int mt7925_mcu_set_roc(struct mt792x_phy
*phy
, struct mt792x_bss_conf
*mconf
,
1222 struct ieee80211_channel
*chan
, int duration
,
1223 enum mt7925_roc_req type
, u8 token_id
)
1225 int center_ch
= ieee80211_frequency_to_channel(chan
->center_freq
);
1226 struct mt792x_dev
*dev
= phy
->dev
;
1231 struct roc_acquire_tlv roc
;
1234 .tag
= cpu_to_le16(UNI_ROC_ACQUIRE
),
1235 .len
= cpu_to_le16(sizeof(struct roc_acquire_tlv
)),
1236 .tokenid
= token_id
,
1238 .maxinterval
= cpu_to_le32(duration
),
1239 .bss_idx
= mconf
->mt76
.idx
,
1240 .control_channel
= chan
->hw_value
,
1241 .bw
= CMD_CBW_20MHZ
,
1242 .bw_from_ap
= CMD_CBW_20MHZ
,
1243 .center_chan
= center_ch
,
1244 .center_chan_from_ap
= center_ch
,
1245 .dbdcband
= 0xff, /* auto */
1249 if (chan
->hw_value
< center_ch
)
1250 req
.roc
.sco
= 1; /* SCA */
1251 else if (chan
->hw_value
> center_ch
)
1252 req
.roc
.sco
= 3; /* SCB */
1254 switch (chan
->band
) {
1255 case NL80211_BAND_6GHZ
:
1258 case NL80211_BAND_5GHZ
:
1266 return mt76_mcu_send_msg(&dev
->mt76
, MCU_UNI_CMD(ROC
),
1267 &req
, sizeof(req
), false);
1270 int mt7925_mcu_abort_roc(struct mt792x_phy
*phy
, struct mt792x_bss_conf
*mconf
,
1273 struct mt792x_dev
*dev
= phy
->dev
;
1278 struct roc_abort_tlv
{
1288 .tag
= cpu_to_le16(UNI_ROC_ABORT
),
1289 .len
= cpu_to_le16(sizeof(struct roc_abort_tlv
)),
1290 .tokenid
= token_id
,
1291 .bss_idx
= mconf
->mt76
.idx
,
1292 .dbdcband
= 0xff, /* auto*/
1296 return mt76_mcu_send_msg(&dev
->mt76
, MCU_UNI_CMD(ROC
),
1297 &req
, sizeof(req
), false);
1300 int mt7925_mcu_set_eeprom(struct mt792x_dev
*dev
)
1311 .tag
= cpu_to_le16(UNI_EFUSE_BUFFER_MODE
),
1312 .len
= cpu_to_le16(sizeof(req
) - 4),
1313 .buffer_mode
= EE_MODE_EFUSE
,
1314 .format
= EE_FORMAT_WHOLE
1317 return mt76_mcu_send_and_get_msg(&dev
->mt76
, MCU_UNI_CMD(EFUSE_CTRL
),
1318 &req
, sizeof(req
), false, NULL
);
1320 EXPORT_SYMBOL_GPL(mt7925_mcu_set_eeprom
);
1322 int mt7925_mcu_uni_bss_ps(struct mt792x_dev
*dev
,
1323 struct ieee80211_bss_conf
*link_conf
)
1325 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(link_conf
);
1334 u8 ps_state
; /* 0: device awake
1335 * 1: static power save
1336 * 2: dynamic power saving
1337 * 3: enter TWT power saving
1338 * 4: leave TWT power saving
1342 } __packed ps_req
= {
1344 .bss_idx
= mconf
->mt76
.idx
,
1347 .tag
= cpu_to_le16(UNI_BSS_INFO_PS
),
1348 .len
= cpu_to_le16(sizeof(struct ps_tlv
)),
1349 .ps_state
= link_conf
->vif
->cfg
.ps
? 2 : 0,
1353 if (link_conf
->vif
->type
!= NL80211_IFTYPE_STATION
)
1356 return mt76_mcu_send_msg(&dev
->mt76
, MCU_UNI_CMD(BSS_INFO_UPDATE
),
1357 &ps_req
, sizeof(ps_req
), true);
1361 mt7925_mcu_uni_bss_bcnft(struct mt792x_dev
*dev
,
1362 struct ieee80211_bss_conf
*link_conf
, bool enable
)
1364 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(link_conf
);
1373 __le16 bcn_interval
;
1375 u8 bmc_delivered_ac
;
1376 u8 bmc_triggered_ac
;
1379 } __packed bcnft_req
= {
1381 .bss_idx
= mconf
->mt76
.idx
,
1384 .tag
= cpu_to_le16(UNI_BSS_INFO_BCNFT
),
1385 .len
= cpu_to_le16(sizeof(struct bcnft_tlv
)),
1386 .bcn_interval
= cpu_to_le16(link_conf
->beacon_int
),
1387 .dtim_period
= link_conf
->dtim_period
,
1391 if (link_conf
->vif
->type
!= NL80211_IFTYPE_STATION
)
1394 return mt76_mcu_send_msg(&dev
->mt76
, MCU_UNI_CMD(BSS_INFO_UPDATE
),
1395 &bcnft_req
, sizeof(bcnft_req
), true);
1399 mt7925_mcu_set_bss_pm(struct mt792x_dev
*dev
,
1400 struct ieee80211_bss_conf
*link_conf
,
1403 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(link_conf
);
1412 __le16 bcn_interval
;
1414 u8 bmc_delivered_ac
;
1415 u8 bmc_triggered_ac
;
1420 .bss_idx
= mconf
->mt76
.idx
,
1423 .tag
= cpu_to_le16(UNI_BSS_INFO_BCNFT
),
1424 .len
= cpu_to_le16(sizeof(struct bcnft_tlv
)),
1425 .dtim_period
= link_conf
->dtim_period
,
1426 .bcn_interval
= cpu_to_le16(link_conf
->beacon_int
),
1440 .bss_idx
= mconf
->mt76
.idx
,
1443 .tag
= cpu_to_le16(UNI_BSS_INFO_PM_DISABLE
),
1444 .len
= cpu_to_le16(sizeof(struct pm_disable
))
1449 err
= mt76_mcu_send_msg(&dev
->mt76
, MCU_UNI_CMD(BSS_INFO_UPDATE
),
1450 &req1
, sizeof(req1
), false);
1451 if (err
< 0 || !enable
)
1454 return mt76_mcu_send_msg(&dev
->mt76
, MCU_UNI_CMD(BSS_INFO_UPDATE
),
1455 &req
, sizeof(req
), false);
1459 mt7925_mcu_sta_he_tlv(struct sk_buff
*skb
, struct ieee80211_link_sta
*link_sta
)
1461 if (!link_sta
->he_cap
.has_he
)
1464 mt76_connac_mcu_sta_he_tlv_v2(skb
, link_sta
->sta
);
1468 mt7925_mcu_sta_he_6g_tlv(struct sk_buff
*skb
,
1469 struct ieee80211_link_sta
*link_sta
)
1471 struct sta_rec_he_6g_capa
*he_6g
;
1474 if (!link_sta
->he_6ghz_capa
.capa
)
1477 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_HE_6G
, sizeof(*he_6g
));
1479 he_6g
= (struct sta_rec_he_6g_capa
*)tlv
;
1480 he_6g
->capa
= link_sta
->he_6ghz_capa
.capa
;
1484 mt7925_mcu_sta_eht_tlv(struct sk_buff
*skb
, struct ieee80211_link_sta
*link_sta
)
1486 struct ieee80211_eht_mcs_nss_supp
*mcs_map
;
1487 struct ieee80211_eht_cap_elem_fixed
*elem
;
1488 struct sta_rec_eht
*eht
;
1491 if (!link_sta
->eht_cap
.has_eht
)
1494 mcs_map
= &link_sta
->eht_cap
.eht_mcs_nss_supp
;
1495 elem
= &link_sta
->eht_cap
.eht_cap_elem
;
1497 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_EHT
, sizeof(*eht
));
1499 eht
= (struct sta_rec_eht
*)tlv
;
1500 eht
->tid_bitmap
= 0xff;
1501 eht
->mac_cap
= cpu_to_le16(*(u16
*)elem
->mac_cap_info
);
1502 eht
->phy_cap
= cpu_to_le64(*(u64
*)elem
->phy_cap_info
);
1503 eht
->phy_cap_ext
= cpu_to_le64(elem
->phy_cap_info
[8]);
1505 if (link_sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
1506 memcpy(eht
->mcs_map_bw20
, &mcs_map
->only_20mhz
, sizeof(eht
->mcs_map_bw20
));
1507 memcpy(eht
->mcs_map_bw80
, &mcs_map
->bw
._80
, sizeof(eht
->mcs_map_bw80
));
1508 memcpy(eht
->mcs_map_bw160
, &mcs_map
->bw
._160
, sizeof(eht
->mcs_map_bw160
));
1512 mt7925_mcu_sta_ht_tlv(struct sk_buff
*skb
, struct ieee80211_link_sta
*link_sta
)
1514 struct sta_rec_ht
*ht
;
1517 if (!link_sta
->ht_cap
.ht_supported
)
1520 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_HT
, sizeof(*ht
));
1522 ht
= (struct sta_rec_ht
*)tlv
;
1523 ht
->ht_cap
= cpu_to_le16(link_sta
->ht_cap
.cap
);
1527 mt7925_mcu_sta_vht_tlv(struct sk_buff
*skb
, struct ieee80211_link_sta
*link_sta
)
1529 struct sta_rec_vht
*vht
;
1532 /* For 6G band, this tlv is necessary to let hw work normally */
1533 if (!link_sta
->he_6ghz_capa
.capa
&& !link_sta
->vht_cap
.vht_supported
)
1536 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_VHT
, sizeof(*vht
));
1538 vht
= (struct sta_rec_vht
*)tlv
;
1539 vht
->vht_cap
= cpu_to_le32(link_sta
->vht_cap
.cap
);
1540 vht
->vht_rx_mcs_map
= link_sta
->vht_cap
.vht_mcs
.rx_mcs_map
;
1541 vht
->vht_tx_mcs_map
= link_sta
->vht_cap
.vht_mcs
.tx_mcs_map
;
1545 mt7925_mcu_sta_amsdu_tlv(struct sk_buff
*skb
,
1546 struct ieee80211_vif
*vif
,
1547 struct ieee80211_link_sta
*link_sta
)
1549 struct mt792x_sta
*msta
= (struct mt792x_sta
*)link_sta
->sta
->drv_priv
;
1550 struct mt792x_link_sta
*mlink
;
1551 struct sta_rec_amsdu
*amsdu
;
1554 if (vif
->type
!= NL80211_IFTYPE_STATION
&&
1555 vif
->type
!= NL80211_IFTYPE_AP
)
1558 if (!link_sta
->agg
.max_amsdu_len
)
1561 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_HW_AMSDU
, sizeof(*amsdu
));
1562 amsdu
= (struct sta_rec_amsdu
*)tlv
;
1563 amsdu
->max_amsdu_num
= 8;
1564 amsdu
->amsdu_en
= true;
1566 mlink
= mt792x_sta_to_link(msta
, link_sta
->link_id
);
1567 mlink
->wcid
.amsdu
= true;
1569 switch (link_sta
->agg
.max_amsdu_len
) {
1570 case IEEE80211_MAX_MPDU_LEN_VHT_11454
:
1571 amsdu
->max_mpdu_size
=
1572 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454
;
1574 case IEEE80211_MAX_MPDU_LEN_HT_7935
:
1575 case IEEE80211_MAX_MPDU_LEN_VHT_7991
:
1576 amsdu
->max_mpdu_size
= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991
;
1579 amsdu
->max_mpdu_size
= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895
;
1585 mt7925_mcu_sta_phy_tlv(struct sk_buff
*skb
,
1586 struct ieee80211_vif
*vif
,
1587 struct ieee80211_link_sta
*link_sta
)
1589 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1590 struct ieee80211_bss_conf
*link_conf
;
1591 struct cfg80211_chan_def
*chandef
;
1592 struct mt792x_bss_conf
*mconf
;
1593 struct sta_rec_phy
*phy
;
1597 link_conf
= mt792x_vif_to_bss_conf(vif
, link_sta
->link_id
);
1598 mconf
= mt792x_vif_to_link(mvif
, link_sta
->link_id
);
1599 chandef
= mconf
->mt76
.ctx
? &mconf
->mt76
.ctx
->def
:
1600 &link_conf
->chanreq
.oper
;
1602 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_PHY
, sizeof(*phy
));
1603 phy
= (struct sta_rec_phy
*)tlv
;
1604 phy
->phy_type
= mt76_connac_get_phy_mode_v2(mvif
->phy
->mt76
, vif
,
1605 chandef
->chan
->band
,
1607 phy
->basic_rate
= cpu_to_le16((u16
)link_conf
->basic_rates
);
1608 if (link_sta
->ht_cap
.ht_supported
) {
1609 af
= link_sta
->ht_cap
.ampdu_factor
;
1610 mm
= link_sta
->ht_cap
.ampdu_density
;
1613 if (link_sta
->vht_cap
.vht_supported
) {
1614 u8 vht_af
= FIELD_GET(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
,
1615 link_sta
->vht_cap
.cap
);
1617 af
= max_t(u8
, af
, vht_af
);
1620 if (link_sta
->he_6ghz_capa
.capa
) {
1621 af
= le16_get_bits(link_sta
->he_6ghz_capa
.capa
,
1622 IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP
);
1623 mm
= le16_get_bits(link_sta
->he_6ghz_capa
.capa
,
1624 IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START
);
1627 phy
->ampdu
= FIELD_PREP(IEEE80211_HT_AMPDU_PARM_FACTOR
, af
) |
1628 FIELD_PREP(IEEE80211_HT_AMPDU_PARM_DENSITY
, mm
);
1629 phy
->max_ampdu_len
= af
;
1633 mt7925_mcu_sta_state_v2_tlv(struct mt76_phy
*mphy
, struct sk_buff
*skb
,
1634 struct ieee80211_link_sta
*link_sta
,
1635 struct ieee80211_vif
*vif
,
1636 u8 rcpi
, u8 sta_state
)
1638 struct sta_rec_state_v2
{
1650 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_STATE
, sizeof(*state
));
1651 state
= (struct sta_rec_state_v2
*)tlv
;
1652 state
->state
= sta_state
;
1654 if (link_sta
->vht_cap
.vht_supported
) {
1655 state
->vht_opmode
= link_sta
->bandwidth
;
1656 state
->vht_opmode
|= link_sta
->rx_nss
<<
1657 IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT
;
1662 mt7925_mcu_sta_rate_ctrl_tlv(struct sk_buff
*skb
,
1663 struct ieee80211_vif
*vif
,
1664 struct ieee80211_link_sta
*link_sta
)
1666 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1667 struct ieee80211_bss_conf
*link_conf
;
1668 struct cfg80211_chan_def
*chandef
;
1669 struct sta_rec_ra_info
*ra_info
;
1670 struct mt792x_bss_conf
*mconf
;
1671 enum nl80211_band band
;
1675 link_conf
= mt792x_vif_to_bss_conf(vif
, link_sta
->link_id
);
1676 mconf
= mt792x_vif_to_link(mvif
, link_sta
->link_id
);
1677 chandef
= mconf
->mt76
.ctx
? &mconf
->mt76
.ctx
->def
:
1678 &link_conf
->chanreq
.oper
;
1679 band
= chandef
->chan
->band
;
1681 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_RA
, sizeof(*ra_info
));
1682 ra_info
= (struct sta_rec_ra_info
*)tlv
;
1684 supp_rates
= link_sta
->supp_rates
[band
];
1685 if (band
== NL80211_BAND_2GHZ
)
1686 supp_rates
= FIELD_PREP(RA_LEGACY_OFDM
, supp_rates
>> 4) |
1687 FIELD_PREP(RA_LEGACY_CCK
, supp_rates
& 0xf);
1689 supp_rates
= FIELD_PREP(RA_LEGACY_OFDM
, supp_rates
);
1691 ra_info
->legacy
= cpu_to_le16(supp_rates
);
1693 if (link_sta
->ht_cap
.ht_supported
)
1694 memcpy(ra_info
->rx_mcs_bitmask
,
1695 link_sta
->ht_cap
.mcs
.rx_mask
,
1700 mt7925_mcu_sta_eht_mld_tlv(struct sk_buff
*skb
,
1701 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
)
1703 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1704 struct wiphy
*wiphy
= mvif
->phy
->mt76
->hw
->wiphy
;
1705 const struct wiphy_iftype_ext_capab
*ext_capa
;
1706 struct sta_rec_eht_mld
*eht_mld
;
1710 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_EHT_MLD
, sizeof(*eht_mld
));
1711 eht_mld
= (struct sta_rec_eht_mld
*)tlv
;
1712 eht_mld
->mld_type
= 0xff;
1714 if (!ieee80211_vif_is_mld(vif
))
1717 ext_capa
= cfg80211_get_iftype_ext_capa(wiphy
,
1718 ieee80211_vif_type_p2p(vif
));
1722 eml_cap
= (vif
->cfg
.eml_cap
& (IEEE80211_EML_CAP_EMLSR_SUPP
|
1723 IEEE80211_EML_CAP_TRANSITION_TIMEOUT
)) |
1724 (ext_capa
->eml_capabilities
& (IEEE80211_EML_CAP_EMLSR_PADDING_DELAY
|
1725 IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY
));
1727 if (eml_cap
& IEEE80211_EML_CAP_EMLSR_SUPP
) {
1728 eht_mld
->eml_cap
[0] = u16_get_bits(eml_cap
, GENMASK(7, 0));
1729 eht_mld
->eml_cap
[1] = u16_get_bits(eml_cap
, GENMASK(15, 8));
1731 eht_mld
->str_cap
[0] = BIT(1);
1736 mt7925_mcu_sta_mld_tlv(struct sk_buff
*skb
,
1737 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
)
1739 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1740 struct mt792x_sta
*msta
= (struct mt792x_sta
*)sta
->drv_priv
;
1741 unsigned long valid
= mvif
->valid_links
;
1742 struct mt792x_bss_conf
*mconf
;
1743 struct mt792x_link_sta
*mlink
;
1744 struct sta_rec_mld
*mld
;
1748 tlv
= mt76_connac_mcu_add_tlv(skb
, STA_REC_MLD
, sizeof(*mld
));
1749 mld
= (struct sta_rec_mld
*)tlv
;
1750 memcpy(mld
->mac_addr
, sta
->addr
, ETH_ALEN
);
1751 mld
->primary_id
= cpu_to_le16(msta
->deflink
.wcid
.idx
);
1752 mld
->wlan_id
= cpu_to_le16(msta
->deflink
.wcid
.idx
);
1753 mld
->link_num
= min_t(u8
, hweight16(mvif
->valid_links
), 2);
1755 for_each_set_bit(i
, &valid
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1756 if (cnt
== mld
->link_num
)
1759 mconf
= mt792x_vif_to_link(mvif
, i
);
1760 mlink
= mt792x_sta_to_link(msta
, i
);
1761 mld
->link
[cnt
].wlan_id
= cpu_to_le16(mlink
->wcid
.idx
);
1762 mld
->link
[cnt
++].bss_idx
= mconf
->mt76
.idx
;
1764 if (mlink
!= &msta
->deflink
)
1765 mld
->secondary_id
= cpu_to_le16(mlink
->wcid
.idx
);
1770 mt7925_mcu_sta_cmd(struct mt76_phy
*phy
,
1771 struct mt76_sta_cmd_info
*info
)
1773 struct mt76_vif
*mvif
= (struct mt76_vif
*)info
->vif
->drv_priv
;
1774 struct mt76_dev
*dev
= phy
->dev
;
1775 struct sk_buff
*skb
;
1778 skb
= __mt76_connac_mcu_alloc_sta_req(dev
, mvif
, info
->wcid
,
1779 MT7925_STA_UPDATE_MAX_SIZE
);
1781 return PTR_ERR(skb
);
1783 conn_state
= info
->enable
? CONN_STATE_PORT_SECURE
:
1784 CONN_STATE_DISCONNECT
;
1786 mt76_connac_mcu_sta_basic_tlv(dev
, skb
, info
->vif
,
1788 conn_state
, info
->newly
);
1789 if (info
->link_sta
&& info
->enable
) {
1790 mt7925_mcu_sta_phy_tlv(skb
, info
->vif
, info
->link_sta
);
1791 mt7925_mcu_sta_ht_tlv(skb
, info
->link_sta
);
1792 mt7925_mcu_sta_vht_tlv(skb
, info
->link_sta
);
1793 mt76_connac_mcu_sta_uapsd(skb
, info
->vif
, info
->link_sta
->sta
);
1794 mt7925_mcu_sta_amsdu_tlv(skb
, info
->vif
, info
->link_sta
);
1795 mt7925_mcu_sta_he_tlv(skb
, info
->link_sta
);
1796 mt7925_mcu_sta_he_6g_tlv(skb
, info
->link_sta
);
1797 mt7925_mcu_sta_eht_tlv(skb
, info
->link_sta
);
1798 mt7925_mcu_sta_rate_ctrl_tlv(skb
, info
->vif
,
1800 mt7925_mcu_sta_state_v2_tlv(phy
, skb
, info
->link_sta
,
1801 info
->vif
, info
->rcpi
,
1803 mt7925_mcu_sta_mld_tlv(skb
, info
->vif
, info
->link_sta
->sta
);
1807 mt7925_mcu_sta_hdr_trans_tlv(skb
, info
->vif
, info
->link_sta
);
1809 return mt76_mcu_skb_send_msg(dev
, skb
, info
->cmd
, true);
1813 mt7925_mcu_sta_remove_tlv(struct sk_buff
*skb
)
1815 struct sta_rec_remove
*rem
;
1818 tlv
= mt76_connac_mcu_add_tlv(skb
, 0x25, sizeof(*rem
));
1819 rem
= (struct sta_rec_remove
*)tlv
;
1824 mt7925_mcu_mlo_sta_cmd(struct mt76_phy
*phy
,
1825 struct mt76_sta_cmd_info
*info
)
1827 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)info
->vif
->drv_priv
;
1828 struct mt76_dev
*dev
= phy
->dev
;
1829 struct mt792x_bss_conf
*mconf
;
1830 struct sk_buff
*skb
;
1832 mconf
= mt792x_vif_to_link(mvif
, info
->wcid
->link_id
);
1834 skb
= __mt76_connac_mcu_alloc_sta_req(dev
, &mconf
->mt76
, info
->wcid
,
1835 MT7925_STA_UPDATE_MAX_SIZE
);
1837 return PTR_ERR(skb
);
1840 mt76_connac_mcu_sta_basic_tlv(dev
, skb
, info
->vif
,
1842 info
->enable
, info
->newly
);
1844 if (info
->enable
&& info
->link_sta
) {
1845 mt7925_mcu_sta_phy_tlv(skb
, info
->vif
, info
->link_sta
);
1846 mt7925_mcu_sta_ht_tlv(skb
, info
->link_sta
);
1847 mt7925_mcu_sta_vht_tlv(skb
, info
->link_sta
);
1848 mt76_connac_mcu_sta_uapsd(skb
, info
->vif
, info
->link_sta
->sta
);
1849 mt7925_mcu_sta_amsdu_tlv(skb
, info
->vif
, info
->link_sta
);
1850 mt7925_mcu_sta_he_tlv(skb
, info
->link_sta
);
1851 mt7925_mcu_sta_he_6g_tlv(skb
, info
->link_sta
);
1852 mt7925_mcu_sta_eht_tlv(skb
, info
->link_sta
);
1853 mt7925_mcu_sta_rate_ctrl_tlv(skb
, info
->vif
,
1855 mt7925_mcu_sta_state_v2_tlv(phy
, skb
, info
->link_sta
,
1856 info
->vif
, info
->rcpi
,
1859 if (info
->state
!= MT76_STA_INFO_STATE_NONE
) {
1860 mt7925_mcu_sta_mld_tlv(skb
, info
->vif
, info
->link_sta
->sta
);
1861 mt7925_mcu_sta_eht_mld_tlv(skb
, info
->vif
, info
->link_sta
->sta
);
1864 mt7925_mcu_sta_hdr_trans_tlv(skb
, info
->vif
, info
->link_sta
);
1867 if (!info
->enable
) {
1868 mt7925_mcu_sta_remove_tlv(skb
);
1869 mt76_connac_mcu_add_tlv(skb
, STA_REC_MLD_OFF
,
1870 sizeof(struct tlv
));
1873 return mt76_mcu_skb_send_msg(dev
, skb
, info
->cmd
, true);
1876 int mt7925_mcu_sta_update(struct mt792x_dev
*dev
,
1877 struct ieee80211_link_sta
*link_sta
,
1878 struct ieee80211_vif
*vif
, bool enable
,
1879 enum mt76_sta_info_state state
)
1881 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1882 int rssi
= -ewma_rssi_read(&mvif
->bss_conf
.rssi
);
1883 struct mt76_sta_cmd_info info
= {
1884 .link_sta
= link_sta
,
1887 .cmd
= MCU_UNI_CMD(STA_REC_UPDATE
),
1890 .rcpi
= to_rcpi(rssi
),
1892 struct mt792x_sta
*msta
;
1893 struct mt792x_link_sta
*mlink
;
1897 msta
= (struct mt792x_sta
*)link_sta
->sta
->drv_priv
;
1898 mlink
= mt792x_sta_to_link(msta
, link_sta
->link_id
);
1900 info
.wcid
= link_sta
? &mlink
->wcid
: &mvif
->sta
.deflink
.wcid
;
1901 info
.newly
= link_sta
? state
!= MT76_STA_INFO_STATE_ASSOC
: true;
1903 if (ieee80211_vif_is_mld(vif
))
1904 err
= mt7925_mcu_mlo_sta_cmd(&dev
->mphy
, &info
);
1906 err
= mt7925_mcu_sta_cmd(&dev
->mphy
, &info
);
1911 int mt7925_mcu_set_beacon_filter(struct mt792x_dev
*dev
,
1912 struct ieee80211_vif
*vif
,
1915 #define MT7925_FIF_BIT_CLR BIT(1)
1916 #define MT7925_FIF_BIT_SET BIT(0)
1917 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1918 unsigned long valid
= ieee80211_vif_is_mld(vif
) ?
1919 mvif
->valid_links
: BIT(0);
1920 struct ieee80211_bss_conf
*bss_conf
;
1925 for_each_set_bit(i
, &valid
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1926 bss_conf
= mt792x_vif_to_bss_conf(vif
, i
);
1927 err
= mt7925_mcu_uni_bss_bcnft(dev
, bss_conf
, true);
1932 return mt7925_mcu_set_rxfilter(dev
, 0,
1934 MT_WF_RFCR_DROP_OTHER_BEACON
);
1937 for_each_set_bit(i
, &valid
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1938 bss_conf
= mt792x_vif_to_bss_conf(vif
, i
);
1939 err
= mt7925_mcu_set_bss_pm(dev
, bss_conf
, false);
1944 return mt7925_mcu_set_rxfilter(dev
, 0,
1946 MT_WF_RFCR_DROP_OTHER_BEACON
);
1949 int mt7925_get_txpwr_info(struct mt792x_dev
*dev
, u8 band_idx
, struct mt7925_txpwr
*txpwr
)
1951 #define TX_POWER_SHOW_INFO 0x7
1952 #define TXPOWER_ALL_RATE_POWER_INFO 0x2
1953 struct mt7925_txpwr_event
*event
;
1954 struct mt7925_txpwr_req req
= {
1955 .tag
= cpu_to_le16(TX_POWER_SHOW_INFO
),
1956 .len
= cpu_to_le16(sizeof(req
) - 4),
1957 .catg
= TXPOWER_ALL_RATE_POWER_INFO
,
1958 .band_idx
= band_idx
,
1960 struct sk_buff
*skb
;
1963 ret
= mt76_mcu_send_and_get_msg(&dev
->mt76
, MCU_UNI_CMD(TXPOWER
),
1964 &req
, sizeof(req
), true, &skb
);
1968 event
= (struct mt7925_txpwr_event
*)skb
->data
;
1969 memcpy(txpwr
, &event
->txpwr
, sizeof(event
->txpwr
));
1976 int mt7925_mcu_set_sniffer(struct mt792x_dev
*dev
, struct ieee80211_vif
*vif
,
1979 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1986 struct sniffer_enable_tlv
{
1994 .band_idx
= mvif
->bss_conf
.mt76
.band_idx
,
1997 .tag
= cpu_to_le16(UNI_SNIFFER_ENABLE
),
1998 .len
= cpu_to_le16(sizeof(struct sniffer_enable_tlv
)),
2003 mt76_mcu_send_msg(&dev
->mt76
, MCU_UNI_CMD(SNIFFER
), &req
, sizeof(req
), true);
2005 return mt76_mcu_send_msg(&dev
->mt76
, MCU_UNI_CMD(SNIFFER
), &req
, sizeof(req
),
2009 int mt7925_mcu_config_sniffer(struct mt792x_vif
*vif
,
2010 struct ieee80211_chanctx_conf
*ctx
)
2012 struct mt76_phy
*mphy
= vif
->phy
->mt76
;
2013 struct cfg80211_chan_def
*chandef
= ctx
? &ctx
->def
: &mphy
->chandef
;
2014 int freq1
= chandef
->center_freq1
, freq2
= chandef
->center_freq2
;
2016 static const u8 ch_band
[] = {
2017 [NL80211_BAND_2GHZ
] = 1,
2018 [NL80211_BAND_5GHZ
] = 2,
2019 [NL80211_BAND_6GHZ
] = 3,
2021 static const u8 ch_width
[] = {
2022 [NL80211_CHAN_WIDTH_20_NOHT
] = 0,
2023 [NL80211_CHAN_WIDTH_20
] = 0,
2024 [NL80211_CHAN_WIDTH_40
] = 0,
2025 [NL80211_CHAN_WIDTH_80
] = 1,
2026 [NL80211_CHAN_WIDTH_160
] = 2,
2027 [NL80211_CHAN_WIDTH_80P80
] = 3,
2028 [NL80211_CHAN_WIDTH_5
] = 4,
2029 [NL80211_CHAN_WIDTH_10
] = 5,
2030 [NL80211_CHAN_WIDTH_320
] = 6,
2053 .band_idx
= vif
->bss_conf
.mt76
.band_idx
,
2056 .tag
= cpu_to_le16(UNI_SNIFFER_CONFIG
),
2057 .len
= cpu_to_le16(sizeof(req
.tlv
)),
2058 .control_ch
= chandef
->chan
->hw_value
,
2059 .center_ch
= ieee80211_frequency_to_channel(freq1
),
2064 if (chandef
->chan
->band
< ARRAY_SIZE(ch_band
))
2065 req
.tlv
.ch_band
= ch_band
[chandef
->chan
->band
];
2066 if (chandef
->width
< ARRAY_SIZE(ch_width
))
2067 req
.tlv
.bw
= ch_width
[chandef
->width
];
2070 req
.tlv
.center_ch2
= ieee80211_frequency_to_channel(freq2
);
2072 if (req
.tlv
.control_ch
< req
.tlv
.center_ch
)
2073 req
.tlv
.sco
= 1; /* SCA */
2074 else if (req
.tlv
.control_ch
> req
.tlv
.center_ch
)
2075 req
.tlv
.sco
= 3; /* SCB */
2077 return mt76_mcu_send_msg(mphy
->dev
, MCU_UNI_CMD(SNIFFER
),
2078 &req
, sizeof(req
), true);
2082 mt7925_mcu_uni_add_beacon_offload(struct mt792x_dev
*dev
,
2083 struct ieee80211_hw
*hw
,
2084 struct ieee80211_vif
*vif
,
2087 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
2088 struct ieee80211_mutable_offsets offs
;
2094 struct bcn_content_tlv
{
2100 /* 0: disable beacon offload
2101 * 1: enable beacon offload
2102 * 2: update probe respond offload
2105 /* 0: legacy format (TXD + payload)
2106 * 1: only cap field IE
2111 } __packed beacon_tlv
;
2114 .bss_idx
= mvif
->bss_conf
.mt76
.idx
,
2117 .tag
= cpu_to_le16(UNI_BSS_INFO_BCN_CONTENT
),
2118 .len
= cpu_to_le16(sizeof(struct bcn_content_tlv
)),
2123 struct sk_buff
*skb
;
2126 /* support enable/update process only
2127 * disable flow would be handled in bss stop handler automatically
2132 skb
= ieee80211_beacon_get_template(mt76_hw(dev
), vif
, &offs
, 0);
2136 cap_offs
= offsetof(struct ieee80211_mgmt
, u
.beacon
.capab_info
);
2137 if (!skb_pull(skb
, cap_offs
)) {
2138 dev_err(dev
->mt76
.dev
, "beacon format err\n");
2143 if (skb
->len
> 512) {
2144 dev_err(dev
->mt76
.dev
, "beacon size limit exceed\n");
2149 memcpy(req
.beacon_tlv
.pkt
, skb
->data
, skb
->len
);
2150 req
.beacon_tlv
.pkt_len
= cpu_to_le16(skb
->len
);
2151 offs
.tim_offset
-= cap_offs
;
2152 req
.beacon_tlv
.tim_ie_pos
= cpu_to_le16(offs
.tim_offset
);
2154 if (offs
.cntdwn_counter_offs
[0]) {
2157 csa_offs
= offs
.cntdwn_counter_offs
[0] - cap_offs
- 4;
2158 req
.beacon_tlv
.csa_ie_pos
= cpu_to_le16(csa_offs
);
2162 return mt76_mcu_send_msg(&dev
->mt76
, MCU_UNI_CMD(BSS_INFO_UPDATE
),
2163 &req
, sizeof(req
), true);
2167 void mt7925_mcu_bss_rlm_tlv(struct sk_buff
*skb
, struct mt76_phy
*phy
,
2168 struct ieee80211_bss_conf
*link_conf
,
2169 struct ieee80211_chanctx_conf
*ctx
)
2171 struct cfg80211_chan_def
*chandef
= ctx
? &ctx
->def
:
2172 &link_conf
->chanreq
.oper
;
2173 int freq1
= chandef
->center_freq1
, freq2
= chandef
->center_freq2
;
2174 enum nl80211_band band
= chandef
->chan
->band
;
2175 struct bss_rlm_tlv
*req
;
2178 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_BSS_INFO_RLM
, sizeof(*req
));
2179 req
= (struct bss_rlm_tlv
*)tlv
;
2180 req
->control_channel
= chandef
->chan
->hw_value
;
2181 req
->center_chan
= ieee80211_frequency_to_channel(freq1
);
2182 req
->center_chan2
= ieee80211_frequency_to_channel(freq2
);
2183 req
->tx_streams
= hweight8(phy
->antenna_mask
);
2184 req
->ht_op_info
= 4; /* set HT 40M allowed */
2185 req
->rx_streams
= hweight8(phy
->antenna_mask
);
2188 switch (chandef
->width
) {
2189 case NL80211_CHAN_WIDTH_40
:
2190 req
->bw
= CMD_CBW_40MHZ
;
2192 case NL80211_CHAN_WIDTH_80
:
2193 req
->bw
= CMD_CBW_80MHZ
;
2195 case NL80211_CHAN_WIDTH_80P80
:
2196 req
->bw
= CMD_CBW_8080MHZ
;
2198 case NL80211_CHAN_WIDTH_160
:
2199 req
->bw
= CMD_CBW_160MHZ
;
2201 case NL80211_CHAN_WIDTH_5
:
2202 req
->bw
= CMD_CBW_5MHZ
;
2204 case NL80211_CHAN_WIDTH_10
:
2205 req
->bw
= CMD_CBW_10MHZ
;
2207 case NL80211_CHAN_WIDTH_20_NOHT
:
2208 case NL80211_CHAN_WIDTH_20
:
2210 req
->bw
= CMD_CBW_20MHZ
;
2211 req
->ht_op_info
= 0;
2215 if (req
->control_channel
< req
->center_chan
)
2216 req
->sco
= 1; /* SCA */
2217 else if (req
->control_channel
> req
->center_chan
)
2218 req
->sco
= 3; /* SCB */
2221 static struct sk_buff
*
2222 __mt7925_mcu_alloc_bss_req(struct mt76_dev
*dev
, struct mt76_vif
*mvif
, int len
)
2224 struct bss_req_hdr hdr
= {
2225 .bss_idx
= mvif
->idx
,
2227 struct sk_buff
*skb
;
2229 skb
= mt76_mcu_msg_alloc(dev
, NULL
, len
);
2231 return ERR_PTR(-ENOMEM
);
2233 skb_put_data(skb
, &hdr
, sizeof(hdr
));
2238 int mt7925_mcu_set_chctx(struct mt76_phy
*phy
, struct mt76_vif
*mvif
,
2239 struct ieee80211_bss_conf
*link_conf
,
2240 struct ieee80211_chanctx_conf
*ctx
)
2242 struct sk_buff
*skb
;
2244 skb
= __mt7925_mcu_alloc_bss_req(phy
->dev
, mvif
,
2245 MT7925_BSS_UPDATE_MAX_SIZE
);
2247 return PTR_ERR(skb
);
2249 mt7925_mcu_bss_rlm_tlv(skb
, phy
, link_conf
, ctx
);
2251 return mt76_mcu_skb_send_msg(phy
->dev
, skb
,
2252 MCU_UNI_CMD(BSS_INFO_UPDATE
), true);
2256 mt7925_get_phy_mode_ext(struct mt76_phy
*phy
, struct ieee80211_vif
*vif
,
2257 enum nl80211_band band
,
2258 struct ieee80211_link_sta
*link_sta
)
2260 struct ieee80211_he_6ghz_capa
*he_6ghz_capa
;
2261 const struct ieee80211_sta_eht_cap
*eht_cap
;
2266 he_6ghz_capa
= &link_sta
->he_6ghz_capa
;
2267 eht_cap
= &link_sta
->eht_cap
;
2269 struct ieee80211_supported_band
*sband
;
2271 sband
= phy
->hw
->wiphy
->bands
[band
];
2272 capa
= ieee80211_get_he_6ghz_capa(sband
, vif
->type
);
2273 he_6ghz_capa
= (struct ieee80211_he_6ghz_capa
*)&capa
;
2275 eht_cap
= ieee80211_get_eht_iftype_cap(sband
, vif
->type
);
2279 case NL80211_BAND_2GHZ
:
2280 if (eht_cap
&& eht_cap
->has_eht
)
2281 mode
|= PHY_MODE_BE_24G
;
2283 case NL80211_BAND_5GHZ
:
2284 if (eht_cap
&& eht_cap
->has_eht
)
2285 mode
|= PHY_MODE_BE_5G
;
2287 case NL80211_BAND_6GHZ
:
2288 if (he_6ghz_capa
&& he_6ghz_capa
->capa
)
2289 mode
|= PHY_MODE_AX_6G
;
2291 if (eht_cap
&& eht_cap
->has_eht
)
2292 mode
|= PHY_MODE_BE_6G
;
2302 mt7925_mcu_bss_basic_tlv(struct sk_buff
*skb
,
2303 struct ieee80211_bss_conf
*link_conf
,
2304 struct ieee80211_link_sta
*link_sta
,
2305 struct ieee80211_chanctx_conf
*ctx
,
2306 struct mt76_phy
*phy
, u16 wlan_idx
,
2309 struct ieee80211_vif
*vif
= link_conf
->vif
;
2310 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(link_conf
);
2311 struct cfg80211_chan_def
*chandef
= ctx
? &ctx
->def
:
2312 &link_conf
->chanreq
.oper
;
2313 enum nl80211_band band
= chandef
->chan
->band
;
2314 struct mt76_connac_bss_basic_tlv
*basic_req
;
2315 struct mt792x_link_sta
*mlink
;
2320 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_BSS_INFO_BASIC
, sizeof(*basic_req
));
2321 basic_req
= (struct mt76_connac_bss_basic_tlv
*)tlv
;
2323 idx
= mconf
->mt76
.omac_idx
> EXT_BSSID_START
? HW_BSSID_0
:
2324 mconf
->mt76
.omac_idx
;
2325 basic_req
->hw_bss_idx
= idx
;
2327 basic_req
->phymode_ext
= mt7925_get_phy_mode_ext(phy
, vif
, band
,
2330 if (band
== NL80211_BAND_2GHZ
)
2331 basic_req
->nonht_basic_phy
= cpu_to_le16(PHY_TYPE_ERP_INDEX
);
2333 basic_req
->nonht_basic_phy
= cpu_to_le16(PHY_TYPE_OFDM_INDEX
);
2335 memcpy(basic_req
->bssid
, link_conf
->bssid
, ETH_ALEN
);
2336 basic_req
->phymode
= mt76_connac_get_phy_mode(phy
, vif
, band
, link_sta
);
2337 basic_req
->bcn_interval
= cpu_to_le16(link_conf
->beacon_int
);
2338 basic_req
->dtim_period
= link_conf
->dtim_period
;
2339 basic_req
->bmc_tx_wlan_idx
= cpu_to_le16(wlan_idx
);
2340 basic_req
->link_idx
= mconf
->mt76
.idx
;
2343 struct mt792x_sta
*msta
;
2345 msta
= (struct mt792x_sta
*)link_sta
->sta
->drv_priv
;
2346 mlink
= mt792x_sta_to_link(msta
, link_sta
->link_id
);
2349 mlink
= &mconf
->vif
->sta
.deflink
;
2352 basic_req
->sta_idx
= cpu_to_le16(mlink
->wcid
.idx
);
2353 basic_req
->omac_idx
= mconf
->mt76
.omac_idx
;
2354 basic_req
->band_idx
= mconf
->mt76
.band_idx
;
2355 basic_req
->wmm_idx
= mconf
->mt76
.wmm_idx
;
2356 basic_req
->conn_state
= !enable
;
2358 switch (vif
->type
) {
2359 case NL80211_IFTYPE_MESH_POINT
:
2360 case NL80211_IFTYPE_AP
:
2362 conn_type
= CONNECTION_P2P_GO
;
2364 conn_type
= CONNECTION_INFRA_AP
;
2365 basic_req
->conn_type
= cpu_to_le32(conn_type
);
2366 basic_req
->active
= enable
;
2368 case NL80211_IFTYPE_STATION
:
2370 conn_type
= CONNECTION_P2P_GC
;
2372 conn_type
= CONNECTION_INFRA_STA
;
2373 basic_req
->conn_type
= cpu_to_le32(conn_type
);
2374 basic_req
->active
= true;
2376 case NL80211_IFTYPE_ADHOC
:
2377 basic_req
->conn_type
= cpu_to_le32(CONNECTION_IBSS_ADHOC
);
2378 basic_req
->active
= true;
2387 mt7925_mcu_bss_sec_tlv(struct sk_buff
*skb
,
2388 struct ieee80211_bss_conf
*link_conf
)
2390 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(link_conf
);
2391 struct mt76_vif
*mvif
= &mconf
->mt76
;
2392 struct bss_sec_tlv
{
2402 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_BSS_INFO_SEC
, sizeof(*sec
));
2403 sec
= (struct bss_sec_tlv
*)tlv
;
2405 switch (mvif
->cipher
) {
2406 case CONNAC3_CIPHER_GCMP_256
:
2407 case CONNAC3_CIPHER_GCMP
:
2408 sec
->mode
= MODE_WPA3_SAE
;
2411 case CONNAC3_CIPHER_AES_CCMP
:
2412 sec
->mode
= MODE_WPA2_PSK
;
2415 case CONNAC3_CIPHER_TKIP
:
2416 sec
->mode
= MODE_WPA2_PSK
;
2419 case CONNAC3_CIPHER_WEP104
:
2420 case CONNAC3_CIPHER_WEP40
:
2421 sec
->mode
= MODE_SHARED
;
2425 sec
->mode
= MODE_OPEN
;
2430 sec
->cipher
= mvif
->cipher
;
2434 mt7925_mcu_bss_bmc_tlv(struct sk_buff
*skb
, struct mt792x_phy
*phy
,
2435 struct ieee80211_chanctx_conf
*ctx
,
2436 struct ieee80211_bss_conf
*link_conf
)
2438 struct cfg80211_chan_def
*chandef
= ctx
? &ctx
->def
:
2439 &link_conf
->chanreq
.oper
;
2440 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(link_conf
);
2441 enum nl80211_band band
= chandef
->chan
->band
;
2442 struct mt76_vif
*mvif
= &mconf
->mt76
;
2443 struct bss_rate_tlv
*bmc
;
2445 u8 idx
= mvif
->mcast_rates_idx
?
2446 mvif
->mcast_rates_idx
: mvif
->basic_rates_idx
;
2448 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_BSS_INFO_RATE
, sizeof(*bmc
));
2450 bmc
= (struct bss_rate_tlv
*)tlv
;
2452 if (band
== NL80211_BAND_2GHZ
)
2453 bmc
->basic_rate
= cpu_to_le16(HR_DSSS_ERP_BASIC_RATE
);
2455 bmc
->basic_rate
= cpu_to_le16(OFDM_BASIC_RATE
);
2457 bmc
->short_preamble
= (band
== NL80211_BAND_2GHZ
);
2458 bmc
->bc_fixed_rate
= idx
;
2459 bmc
->mc_fixed_rate
= idx
;
2463 mt7925_mcu_bss_mld_tlv(struct sk_buff
*skb
,
2464 struct ieee80211_bss_conf
*link_conf
)
2466 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(link_conf
);
2467 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)link_conf
->vif
->drv_priv
;
2468 struct bss_mld_tlv
*mld
;
2472 is_mld
= ieee80211_vif_is_mld(link_conf
->vif
) ||
2473 (hweight16(mvif
->valid_links
) > 1);
2475 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_BSS_INFO_MLD
, sizeof(*mld
));
2476 mld
= (struct bss_mld_tlv
*)tlv
;
2478 mld
->link_id
= is_mld
? link_conf
->link_id
: 0xff;
2479 /* apply the index of the primary link */
2480 mld
->group_mld_id
= is_mld
? mvif
->bss_conf
.mt76
.idx
: 0xff;
2481 mld
->own_mld_id
= mconf
->mt76
.idx
+ 32;
2482 mld
->remap_idx
= 0xff;
2483 mld
->eml_enable
= !!(link_conf
->vif
->cfg
.eml_cap
&
2484 IEEE80211_EML_CAP_EMLSR_SUPP
);
2486 memcpy(mld
->mac_addr
, link_conf
->addr
, ETH_ALEN
);
2490 mt7925_mcu_bss_qos_tlv(struct sk_buff
*skb
, struct ieee80211_bss_conf
*link_conf
)
2492 struct mt76_connac_bss_qos_tlv
*qos
;
2495 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_BSS_INFO_QBSS
, sizeof(*qos
));
2496 qos
= (struct mt76_connac_bss_qos_tlv
*)tlv
;
2497 qos
->qos
= link_conf
->qos
;
2501 mt7925_mcu_bss_he_tlv(struct sk_buff
*skb
, struct ieee80211_bss_conf
*link_conf
,
2502 struct mt792x_phy
*phy
)
2504 #define DEFAULT_HE_PE_DURATION 4
2505 #define DEFAULT_HE_DURATION_RTS_THRES 1023
2506 const struct ieee80211_sta_he_cap
*cap
;
2507 struct bss_info_uni_he
*he
;
2510 cap
= mt76_connac_get_he_phy_cap(phy
->mt76
, link_conf
->vif
);
2512 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_BSS_INFO_HE_BASIC
, sizeof(*he
));
2514 he
= (struct bss_info_uni_he
*)tlv
;
2515 he
->he_pe_duration
= link_conf
->htc_trig_based_pkt_ext
;
2516 if (!he
->he_pe_duration
)
2517 he
->he_pe_duration
= DEFAULT_HE_PE_DURATION
;
2519 he
->he_rts_thres
= cpu_to_le16(link_conf
->frame_time_rts_th
);
2520 if (!he
->he_rts_thres
)
2521 he
->he_rts_thres
= cpu_to_le16(DEFAULT_HE_DURATION_RTS_THRES
);
2523 he
->max_nss_mcs
[CMD_HE_MCS_BW80
] = cap
->he_mcs_nss_supp
.tx_mcs_80
;
2524 he
->max_nss_mcs
[CMD_HE_MCS_BW160
] = cap
->he_mcs_nss_supp
.tx_mcs_160
;
2525 he
->max_nss_mcs
[CMD_HE_MCS_BW8080
] = cap
->he_mcs_nss_supp
.tx_mcs_80p80
;
2529 mt7925_mcu_bss_color_tlv(struct sk_buff
*skb
, struct ieee80211_bss_conf
*link_conf
,
2532 struct bss_info_uni_bss_color
*color
;
2535 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_BSS_INFO_BSS_COLOR
, sizeof(*color
));
2536 color
= (struct bss_info_uni_bss_color
*)tlv
;
2538 color
->enable
= enable
?
2539 link_conf
->he_bss_color
.enabled
: 0;
2540 color
->bss_color
= enable
?
2541 link_conf
->he_bss_color
.color
: 0;
2545 mt7925_mcu_bss_ifs_tlv(struct sk_buff
*skb
,
2546 struct ieee80211_bss_conf
*link_conf
)
2548 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)link_conf
->vif
->drv_priv
;
2549 struct mt792x_phy
*phy
= mvif
->phy
;
2550 struct bss_ifs_time_tlv
*ifs_time
;
2553 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_BSS_INFO_IFS_TIME
, sizeof(*ifs_time
));
2554 ifs_time
= (struct bss_ifs_time_tlv
*)tlv
;
2555 ifs_time
->slot_valid
= true;
2556 ifs_time
->slot_time
= cpu_to_le16(phy
->slottime
);
2559 int mt7925_mcu_set_timing(struct mt792x_phy
*phy
,
2560 struct ieee80211_bss_conf
*link_conf
)
2562 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(link_conf
);
2563 struct mt792x_dev
*dev
= phy
->dev
;
2564 struct sk_buff
*skb
;
2566 skb
= __mt7925_mcu_alloc_bss_req(&dev
->mt76
, &mconf
->mt76
,
2567 MT7925_BSS_UPDATE_MAX_SIZE
);
2569 return PTR_ERR(skb
);
2571 mt7925_mcu_bss_ifs_tlv(skb
, link_conf
);
2573 return mt76_mcu_skb_send_msg(&dev
->mt76
, skb
,
2574 MCU_UNI_CMD(BSS_INFO_UPDATE
), true);
2577 int mt7925_mcu_add_bss_info(struct mt792x_phy
*phy
,
2578 struct ieee80211_chanctx_conf
*ctx
,
2579 struct ieee80211_bss_conf
*link_conf
,
2580 struct ieee80211_link_sta
*link_sta
,
2583 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)link_conf
->vif
->drv_priv
;
2584 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(link_conf
);
2585 struct mt792x_dev
*dev
= phy
->dev
;
2586 struct mt792x_link_sta
*mlink_bc
;
2587 struct sk_buff
*skb
;
2589 skb
= __mt7925_mcu_alloc_bss_req(&dev
->mt76
, &mconf
->mt76
,
2590 MT7925_BSS_UPDATE_MAX_SIZE
);
2592 return PTR_ERR(skb
);
2594 mlink_bc
= mt792x_sta_to_link(&mvif
->sta
, mconf
->link_id
);
2596 /* bss_basic must be first */
2597 mt7925_mcu_bss_basic_tlv(skb
, link_conf
, link_sta
, ctx
, phy
->mt76
,
2598 mlink_bc
->wcid
.idx
, enable
);
2599 mt7925_mcu_bss_sec_tlv(skb
, link_conf
);
2600 mt7925_mcu_bss_bmc_tlv(skb
, phy
, ctx
, link_conf
);
2601 mt7925_mcu_bss_qos_tlv(skb
, link_conf
);
2602 mt7925_mcu_bss_mld_tlv(skb
, link_conf
);
2603 mt7925_mcu_bss_ifs_tlv(skb
, link_conf
);
2605 if (link_conf
->he_support
) {
2606 mt7925_mcu_bss_he_tlv(skb
, link_conf
, phy
);
2607 mt7925_mcu_bss_color_tlv(skb
, link_conf
, enable
);
2611 mt7925_mcu_bss_rlm_tlv(skb
, phy
->mt76
, link_conf
, ctx
);
2613 return mt76_mcu_skb_send_msg(&dev
->mt76
, skb
,
2614 MCU_UNI_CMD(BSS_INFO_UPDATE
), true);
2617 int mt7925_mcu_set_dbdc(struct mt76_phy
*phy
)
2619 struct mt76_dev
*mdev
= phy
->dev
;
2621 struct mbmc_conf_tlv
*conf
;
2622 struct mbmc_set_req
*hdr
;
2623 struct sk_buff
*skb
;
2627 max_len
= sizeof(*hdr
) + sizeof(*conf
);
2628 skb
= mt76_mcu_msg_alloc(mdev
, NULL
, max_len
);
2632 hdr
= (struct mbmc_set_req
*)skb_put(skb
, sizeof(*hdr
));
2634 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_MBMC_SETTING
, sizeof(*conf
));
2635 conf
= (struct mbmc_conf_tlv
*)tlv
;
2638 conf
->band
= 0; /* unused */
2640 err
= mt76_mcu_skb_send_msg(mdev
, skb
, MCU_UNI_CMD(SET_DBDC_PARMS
),
2646 #define MT76_CONNAC_SCAN_CHANNEL_TIME 60
2648 int mt7925_mcu_hw_scan(struct mt76_phy
*phy
, struct ieee80211_vif
*vif
,
2649 struct ieee80211_scan_request
*scan_req
)
2651 struct mt76_vif
*mvif
= (struct mt76_vif
*)vif
->drv_priv
;
2652 struct cfg80211_scan_request
*sreq
= &scan_req
->req
;
2653 int n_ssids
= 0, err
, i
, duration
;
2654 struct ieee80211_channel
**scan_list
= sreq
->channels
;
2655 struct mt76_dev
*mdev
= phy
->dev
;
2656 struct mt76_connac_mcu_scan_channel
*chan
;
2657 struct sk_buff
*skb
;
2659 struct scan_hdr_tlv
*hdr
;
2660 struct scan_req_tlv
*req
;
2661 struct scan_ssid_tlv
*ssid
;
2662 struct scan_bssid_tlv
*bssid
;
2663 struct scan_chan_info_tlv
*chan_info
;
2664 struct scan_ie_tlv
*ie
;
2665 struct scan_misc_tlv
*misc
;
2669 max_len
= sizeof(*hdr
) + sizeof(*req
) + sizeof(*ssid
) +
2670 sizeof(*bssid
) + sizeof(*chan_info
) +
2671 sizeof(*misc
) + sizeof(*ie
);
2673 skb
= mt76_mcu_msg_alloc(mdev
, NULL
, max_len
);
2677 set_bit(MT76_HW_SCANNING
, &phy
->state
);
2678 mvif
->scan_seq_num
= (mvif
->scan_seq_num
+ 1) & 0x7f;
2680 hdr
= (struct scan_hdr_tlv
*)skb_put(skb
, sizeof(*hdr
));
2681 hdr
->seq_num
= mvif
->scan_seq_num
| mvif
->band_idx
<< 7;
2682 hdr
->bss_idx
= mvif
->idx
;
2684 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_SCAN_REQ
, sizeof(*req
));
2685 req
= (struct scan_req_tlv
*)tlv
;
2686 req
->scan_type
= sreq
->n_ssids
? 1 : 0;
2687 req
->probe_req_num
= sreq
->n_ssids
? 2 : 0;
2689 duration
= MT76_CONNAC_SCAN_CHANNEL_TIME
;
2690 /* increase channel time for passive scan */
2693 req
->timeout_value
= cpu_to_le16(sreq
->n_channels
* duration
);
2694 req
->channel_min_dwell_time
= cpu_to_le16(duration
);
2695 req
->channel_dwell_time
= cpu_to_le16(duration
);
2697 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_SCAN_SSID
, sizeof(*ssid
));
2698 ssid
= (struct scan_ssid_tlv
*)tlv
;
2699 for (i
= 0; i
< sreq
->n_ssids
; i
++) {
2700 if (!sreq
->ssids
[i
].ssid_len
)
2703 ssid
->ssids
[i
].ssid_len
= cpu_to_le32(sreq
->ssids
[i
].ssid_len
);
2704 memcpy(ssid
->ssids
[i
].ssid
, sreq
->ssids
[i
].ssid
,
2705 sreq
->ssids
[i
].ssid_len
);
2708 ssid
->ssid_type
= n_ssids
? BIT(2) : BIT(0);
2709 ssid
->ssids_num
= n_ssids
;
2711 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_SCAN_BSSID
, sizeof(*bssid
));
2712 bssid
= (struct scan_bssid_tlv
*)tlv
;
2714 memcpy(bssid
->bssid
, sreq
->bssid
, ETH_ALEN
);
2716 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_SCAN_CHANNEL
, sizeof(*chan_info
));
2717 chan_info
= (struct scan_chan_info_tlv
*)tlv
;
2718 chan_info
->channels_num
= min_t(u8
, sreq
->n_channels
,
2719 ARRAY_SIZE(chan_info
->channels
));
2720 for (i
= 0; i
< chan_info
->channels_num
; i
++) {
2721 chan
= &chan_info
->channels
[i
];
2723 switch (scan_list
[i
]->band
) {
2724 case NL80211_BAND_2GHZ
:
2727 case NL80211_BAND_6GHZ
:
2734 chan
->channel_num
= scan_list
[i
]->hw_value
;
2736 chan_info
->channel_type
= sreq
->n_channels
? 4 : 0;
2738 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_SCAN_IE
, sizeof(*ie
));
2739 ie
= (struct scan_ie_tlv
*)tlv
;
2740 if (sreq
->ie_len
> 0) {
2741 memcpy(ie
->ies
, sreq
->ie
, sreq
->ie_len
);
2742 ie
->ies_len
= cpu_to_le16(sreq
->ie_len
);
2745 req
->scan_func
|= SCAN_FUNC_SPLIT_SCAN
;
2747 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_SCAN_MISC
, sizeof(*misc
));
2748 misc
= (struct scan_misc_tlv
*)tlv
;
2749 if (sreq
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
2750 get_random_mask_addr(misc
->random_mac
, sreq
->mac_addr
,
2751 sreq
->mac_addr_mask
);
2752 req
->scan_func
|= SCAN_FUNC_RANDOM_MAC
;
2755 err
= mt76_mcu_skb_send_msg(mdev
, skb
, MCU_UNI_CMD(SCAN_REQ
),
2758 clear_bit(MT76_HW_SCANNING
, &phy
->state
);
2762 EXPORT_SYMBOL_GPL(mt7925_mcu_hw_scan
);
2764 int mt7925_mcu_sched_scan_req(struct mt76_phy
*phy
,
2765 struct ieee80211_vif
*vif
,
2766 struct cfg80211_sched_scan_request
*sreq
)
2768 struct mt76_vif
*mvif
= (struct mt76_vif
*)vif
->drv_priv
;
2769 struct ieee80211_channel
**scan_list
= sreq
->channels
;
2770 struct mt76_connac_mcu_scan_channel
*chan
;
2771 struct mt76_dev
*mdev
= phy
->dev
;
2772 struct cfg80211_match_set
*cfg_match
;
2773 struct cfg80211_ssid
*cfg_ssid
;
2775 struct scan_hdr_tlv
*hdr
;
2776 struct scan_sched_req
*req
;
2777 struct scan_ssid_tlv
*ssid
;
2778 struct scan_chan_info_tlv
*chan_info
;
2779 struct scan_ie_tlv
*ie
;
2780 struct scan_sched_ssid_match_sets
*match
;
2781 struct sk_buff
*skb
;
2785 max_len
= sizeof(*hdr
) + sizeof(*req
) + sizeof(*ssid
) +
2786 sizeof(*chan_info
) + sizeof(*ie
) +
2789 skb
= mt76_mcu_msg_alloc(mdev
, NULL
, max_len
);
2793 mvif
->scan_seq_num
= (mvif
->scan_seq_num
+ 1) & 0x7f;
2795 hdr
= (struct scan_hdr_tlv
*)skb_put(skb
, sizeof(*hdr
));
2796 hdr
->seq_num
= mvif
->scan_seq_num
| mvif
->band_idx
<< 7;
2797 hdr
->bss_idx
= mvif
->idx
;
2799 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_SCAN_SCHED_REQ
, sizeof(*req
));
2800 req
= (struct scan_sched_req
*)tlv
;
2803 if (sreq
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
)
2804 req
->scan_func
|= SCAN_FUNC_RANDOM_MAC
;
2806 req
->intervals_num
= sreq
->n_scan_plans
;
2807 for (i
= 0; i
< req
->intervals_num
; i
++)
2808 req
->intervals
[i
] = cpu_to_le16(sreq
->scan_plans
[i
].interval
);
2810 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_SCAN_SSID
, sizeof(*ssid
));
2811 ssid
= (struct scan_ssid_tlv
*)tlv
;
2813 ssid
->ssids_num
= sreq
->n_ssids
;
2814 ssid
->ssid_type
= BIT(2);
2815 for (i
= 0; i
< ssid
->ssids_num
; i
++) {
2816 cfg_ssid
= &sreq
->ssids
[i
];
2817 memcpy(ssid
->ssids
[i
].ssid
, cfg_ssid
->ssid
, cfg_ssid
->ssid_len
);
2818 ssid
->ssids
[i
].ssid_len
= cpu_to_le32(cfg_ssid
->ssid_len
);
2821 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_SCAN_SSID_MATCH_SETS
, sizeof(*match
));
2822 match
= (struct scan_sched_ssid_match_sets
*)tlv
;
2823 match
->match_num
= sreq
->n_match_sets
;
2824 for (i
= 0; i
< match
->match_num
; i
++) {
2825 cfg_match
= &sreq
->match_sets
[i
];
2826 memcpy(match
->match
[i
].ssid
, cfg_match
->ssid
.ssid
,
2827 cfg_match
->ssid
.ssid_len
);
2828 match
->match
[i
].rssi_th
= cpu_to_le32(cfg_match
->rssi_thold
);
2829 match
->match
[i
].ssid_len
= cfg_match
->ssid
.ssid_len
;
2832 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_SCAN_CHANNEL
, sizeof(*chan_info
));
2833 chan_info
= (struct scan_chan_info_tlv
*)tlv
;
2834 chan_info
->channels_num
= min_t(u8
, sreq
->n_channels
,
2835 ARRAY_SIZE(chan_info
->channels
));
2836 for (i
= 0; i
< chan_info
->channels_num
; i
++) {
2837 chan
= &chan_info
->channels
[i
];
2839 switch (scan_list
[i
]->band
) {
2840 case NL80211_BAND_2GHZ
:
2843 case NL80211_BAND_6GHZ
:
2850 chan
->channel_num
= scan_list
[i
]->hw_value
;
2852 chan_info
->channel_type
= sreq
->n_channels
? 4 : 0;
2854 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_SCAN_IE
, sizeof(*ie
));
2855 ie
= (struct scan_ie_tlv
*)tlv
;
2856 if (sreq
->ie_len
> 0) {
2857 memcpy(ie
->ies
, sreq
->ie
, sreq
->ie_len
);
2858 ie
->ies_len
= cpu_to_le16(sreq
->ie_len
);
2861 return mt76_mcu_skb_send_msg(mdev
, skb
, MCU_UNI_CMD(SCAN_REQ
),
2864 EXPORT_SYMBOL_GPL(mt7925_mcu_sched_scan_req
);
2867 mt7925_mcu_sched_scan_enable(struct mt76_phy
*phy
,
2868 struct ieee80211_vif
*vif
,
2871 struct mt76_dev
*mdev
= phy
->dev
;
2872 struct scan_sched_enable
*req
;
2873 struct scan_hdr_tlv
*hdr
;
2874 struct sk_buff
*skb
;
2878 max_len
= sizeof(*hdr
) + sizeof(*req
);
2880 skb
= mt76_mcu_msg_alloc(mdev
, NULL
, max_len
);
2884 hdr
= (struct scan_hdr_tlv
*)skb_put(skb
, sizeof(*hdr
));
2888 tlv
= mt76_connac_mcu_add_tlv(skb
, UNI_SCAN_SCHED_ENABLE
, sizeof(*req
));
2889 req
= (struct scan_sched_enable
*)tlv
;
2890 req
->active
= !enable
;
2893 set_bit(MT76_HW_SCHED_SCANNING
, &phy
->state
);
2895 clear_bit(MT76_HW_SCHED_SCANNING
, &phy
->state
);
2897 return mt76_mcu_skb_send_msg(mdev
, skb
, MCU_UNI_CMD(SCAN_REQ
),
2901 int mt7925_mcu_cancel_hw_scan(struct mt76_phy
*phy
,
2902 struct ieee80211_vif
*vif
)
2904 struct mt76_vif
*mvif
= (struct mt76_vif
*)vif
->drv_priv
;
2911 struct scan_cancel_tlv
{
2919 .seq_num
= mvif
->scan_seq_num
,
2920 .bss_idx
= mvif
->idx
,
2923 .tag
= cpu_to_le16(UNI_SCAN_CANCEL
),
2924 .len
= cpu_to_le16(sizeof(struct scan_cancel_tlv
)),
2928 if (test_and_clear_bit(MT76_HW_SCANNING
, &phy
->state
)) {
2929 struct cfg80211_scan_info info
= {
2933 ieee80211_scan_completed(phy
->hw
, &info
);
2936 return mt76_mcu_send_msg(phy
->dev
, MCU_UNI_CMD(SCAN_REQ
),
2937 &req
, sizeof(req
), false);
2939 EXPORT_SYMBOL_GPL(mt7925_mcu_cancel_hw_scan
);
2941 int mt7925_mcu_set_channel_domain(struct mt76_phy
*phy
)
2943 int len
, i
, n_max_channels
, n_2ch
= 0, n_5ch
= 0, n_6ch
= 0;
2946 u8 alpha2
[4]; /* regulatory_request.alpha2 */
2947 u8 bw_2g
; /* BW_20_40M 0
2950 * BW_20_40_80_160M 3
2951 * BW_20_40_80_8080M 4
2968 .bw_5g
= 3, /* BW_20_40_80_160M */
2972 .tag
= cpu_to_le16(2),
2975 struct mt76_connac_mcu_chan
{
2980 struct mt76_dev
*dev
= phy
->dev
;
2981 struct ieee80211_channel
*chan
;
2982 struct sk_buff
*skb
;
2984 n_max_channels
= phy
->sband_2g
.sband
.n_channels
+
2985 phy
->sband_5g
.sband
.n_channels
+
2986 phy
->sband_6g
.sband
.n_channels
;
2987 len
= sizeof(req
) + n_max_channels
* sizeof(channel
);
2989 skb
= mt76_mcu_msg_alloc(dev
, NULL
, len
);
2993 skb_reserve(skb
, sizeof(req
));
2995 for (i
= 0; i
< phy
->sband_2g
.sband
.n_channels
; i
++) {
2996 chan
= &phy
->sband_2g
.sband
.channels
[i
];
2997 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3000 channel
.hw_value
= cpu_to_le16(chan
->hw_value
);
3001 channel
.flags
= cpu_to_le32(chan
->flags
);
3004 skb_put_data(skb
, &channel
, sizeof(channel
));
3007 for (i
= 0; i
< phy
->sband_5g
.sband
.n_channels
; i
++) {
3008 chan
= &phy
->sband_5g
.sband
.channels
[i
];
3009 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3012 channel
.hw_value
= cpu_to_le16(chan
->hw_value
);
3013 channel
.flags
= cpu_to_le32(chan
->flags
);
3016 skb_put_data(skb
, &channel
, sizeof(channel
));
3019 for (i
= 0; i
< phy
->sband_6g
.sband
.n_channels
; i
++) {
3020 chan
= &phy
->sband_6g
.sband
.channels
[i
];
3021 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3024 channel
.hw_value
= cpu_to_le16(chan
->hw_value
);
3025 channel
.flags
= cpu_to_le32(chan
->flags
);
3028 skb_put_data(skb
, &channel
, sizeof(channel
));
3032 BUILD_BUG_ON(sizeof(dev
->alpha2
) > sizeof(req
.hdr
.alpha2
));
3033 memcpy(req
.hdr
.alpha2
, dev
->alpha2
, sizeof(dev
->alpha2
));
3034 req
.n_ch
.n_2ch
= n_2ch
;
3035 req
.n_ch
.n_5ch
= n_5ch
;
3036 req
.n_ch
.n_6ch
= n_6ch
;
3037 len
= sizeof(struct n_chan
) + (n_2ch
+ n_5ch
+ n_6ch
) * sizeof(channel
);
3038 req
.n_ch
.len
= cpu_to_le16(len
);
3039 memcpy(__skb_push(skb
, sizeof(req
)), &req
, sizeof(req
));
3041 return mt76_mcu_skb_send_msg(dev
, skb
, MCU_UNI_CMD(SET_DOMAIN_INFO
),
3044 EXPORT_SYMBOL_GPL(mt7925_mcu_set_channel_domain
);
3047 __mt7925_mcu_set_clc(struct mt792x_dev
*dev
, u8
*alpha2
,
3048 enum environment_cap env_cap
,
3049 struct mt7925_clc
*clc
, u8 idx
)
3051 struct mt7925_clc_segment
*seg
;
3052 struct sk_buff
*skb
;
3069 .tag
= cpu_to_le16(0x3),
3070 .len
= cpu_to_le16(sizeof(req
) - 4),
3074 .acpi_conf
= mt792x_acpi_get_flags(&dev
->phy
),
3076 int ret
, valid_cnt
= 0;
3082 pos
= clc
->data
+ sizeof(*seg
) * clc
->nr_seg
;
3083 for (i
= 0; i
< clc
->nr_country
; i
++) {
3084 struct mt7925_clc_rule
*rule
= (struct mt7925_clc_rule
*)pos
;
3086 pos
+= sizeof(*rule
);
3087 if (rule
->alpha2
[0] != alpha2
[0] ||
3088 rule
->alpha2
[1] != alpha2
[1])
3091 seg
= (struct mt7925_clc_segment
*)clc
->data
3092 + rule
->seg_idx
- 1;
3094 memcpy(req
.alpha2
, rule
->alpha2
, 2);
3095 memcpy(req
.type
, rule
->type
, 2);
3097 req
.size
= cpu_to_le16(seg
->len
);
3098 skb
= __mt76_mcu_msg_alloc(&dev
->mt76
, &req
,
3099 le16_to_cpu(req
.size
) + sizeof(req
),
3100 sizeof(req
), GFP_KERNEL
);
3103 skb_put_data(skb
, clc
->data
+ seg
->offset
, seg
->len
);
3105 ret
= mt76_mcu_skb_send_msg(&dev
->mt76
, skb
,
3106 MCU_UNI_CMD(SET_POWER_LIMIT
),
3119 int mt7925_mcu_set_clc(struct mt792x_dev
*dev
, u8
*alpha2
,
3120 enum environment_cap env_cap
)
3122 struct mt792x_phy
*phy
= (struct mt792x_phy
*)&dev
->phy
;
3125 /* submit all clc config */
3126 for (i
= 0; i
< ARRAY_SIZE(phy
->clc
); i
++) {
3127 ret
= __mt7925_mcu_set_clc(dev
, alpha2
, env_cap
,
3130 /* If no country found, set "00" as default */
3132 ret
= __mt7925_mcu_set_clc(dev
, "00",
3141 int mt7925_mcu_fill_message(struct mt76_dev
*mdev
, struct sk_buff
*skb
,
3142 int cmd
, int *wait_seq
)
3144 int txd_len
, mcu_cmd
= FIELD_GET(__MCU_CMD_FIELD_ID
, cmd
);
3145 struct mt76_connac2_mcu_uni_txd
*uni_txd
;
3146 struct mt76_connac2_mcu_txd
*mcu_txd
;
3151 /* TODO: make dynamic based on msg type */
3152 mdev
->mcu
.timeout
= 20 * HZ
;
3154 seq
= ++mdev
->mcu
.msg_seq
& 0xf;
3156 seq
= ++mdev
->mcu
.msg_seq
& 0xf;
3158 if (cmd
== MCU_CMD(FW_SCATTER
))
3161 txd_len
= cmd
& __MCU_CMD_FIELD_UNI
? sizeof(*uni_txd
) : sizeof(*mcu_txd
);
3162 txd
= (__le32
*)skb_push(skb
, txd_len
);
3164 val
= FIELD_PREP(MT_TXD0_TX_BYTES
, skb
->len
) |
3165 FIELD_PREP(MT_TXD0_PKT_FMT
, MT_TX_TYPE_CMD
) |
3166 FIELD_PREP(MT_TXD0_Q_IDX
, MT_TX_MCU_PORT_RX_Q0
);
3167 txd
[0] = cpu_to_le32(val
);
3169 val
= FIELD_PREP(MT_TXD1_HDR_FORMAT
, MT_HDR_FORMAT_CMD
);
3170 txd
[1] = cpu_to_le32(val
);
3172 if (cmd
& __MCU_CMD_FIELD_UNI
) {
3173 uni_txd
= (struct mt76_connac2_mcu_uni_txd
*)txd
;
3174 uni_txd
->len
= cpu_to_le16(skb
->len
- sizeof(uni_txd
->txd
));
3175 uni_txd
->cid
= cpu_to_le16(mcu_cmd
);
3176 uni_txd
->s2d_index
= MCU_S2D_H2N
;
3177 uni_txd
->pkt_type
= MCU_PKT_ID
;
3180 if (cmd
& __MCU_CMD_FIELD_QUERY
)
3181 uni_txd
->option
= MCU_CMD_UNI_QUERY_ACK
;
3183 uni_txd
->option
= MCU_CMD_UNI_EXT_ACK
;
3188 mcu_txd
= (struct mt76_connac2_mcu_txd
*)txd
;
3189 mcu_txd
->len
= cpu_to_le16(skb
->len
- sizeof(mcu_txd
->txd
));
3190 mcu_txd
->pq_id
= cpu_to_le16(MCU_PQ_ID(MT_TX_PORT_IDX_MCU
,
3191 MT_TX_MCU_PORT_RX_Q0
));
3192 mcu_txd
->pkt_type
= MCU_PKT_ID
;
3194 mcu_txd
->cid
= mcu_cmd
;
3195 mcu_txd
->ext_cid
= FIELD_GET(__MCU_CMD_FIELD_EXT_ID
, cmd
);
3197 if (mcu_txd
->ext_cid
|| (cmd
& __MCU_CMD_FIELD_CE
)) {
3198 if (cmd
& __MCU_CMD_FIELD_QUERY
)
3199 mcu_txd
->set_query
= MCU_Q_QUERY
;
3201 mcu_txd
->set_query
= MCU_Q_SET
;
3202 mcu_txd
->ext_cid_ack
= !!mcu_txd
->ext_cid
;
3204 mcu_txd
->set_query
= MCU_Q_NA
;
3207 if (cmd
& __MCU_CMD_FIELD_WA
)
3208 mcu_txd
->s2d_index
= MCU_S2D_H2C
;
3210 mcu_txd
->s2d_index
= MCU_S2D_H2N
;
3218 EXPORT_SYMBOL_GPL(mt7925_mcu_fill_message
);
3220 int mt7925_mcu_set_rts_thresh(struct mt792x_phy
*phy
, u32 val
)
3231 .band_idx
= phy
->mt76
->band_idx
,
3232 .tag
= cpu_to_le16(UNI_BAND_CONFIG_RTS_THRESHOLD
),
3233 .len
= cpu_to_le16(sizeof(req
) - 4),
3234 .len_thresh
= cpu_to_le32(val
),
3235 .pkt_thresh
= cpu_to_le32(0x2),
3238 return mt76_mcu_send_msg(&phy
->dev
->mt76
, MCU_UNI_CMD(BAND_CONFIG
),
3239 &req
, sizeof(req
), true);
3242 int mt7925_mcu_set_radio_en(struct mt792x_phy
*phy
, bool enable
)
3253 .band_idx
= phy
->mt76
->band_idx
,
3254 .tag
= cpu_to_le16(UNI_BAND_CONFIG_RADIO_ENABLE
),
3255 .len
= cpu_to_le16(sizeof(req
) - 4),
3259 return mt76_mcu_send_msg(&phy
->dev
->mt76
, MCU_UNI_CMD(BAND_CONFIG
),
3260 &req
, sizeof(req
), true);
3264 mt7925_mcu_build_sku(struct mt76_dev
*dev
, s8
*sku
,
3265 struct mt76_power_limits
*limits
,
3266 enum nl80211_band band
)
3268 int i
, offset
= sizeof(limits
->cck
);
3270 memset(sku
, 127, MT_CONNAC3_SKU_POWER_LIMIT
);
3272 if (band
== NL80211_BAND_2GHZ
) {
3274 memcpy(sku
, limits
->cck
, sizeof(limits
->cck
));
3278 memcpy(&sku
[offset
], limits
->ofdm
, sizeof(limits
->ofdm
));
3279 offset
+= (sizeof(limits
->ofdm
) * 5);
3282 for (i
= 0; i
< 2; i
++) {
3283 memcpy(&sku
[offset
], limits
->mcs
[i
], 8);
3286 sku
[offset
++] = limits
->mcs
[0][0];
3289 for (i
= 0; i
< ARRAY_SIZE(limits
->mcs
); i
++) {
3290 memcpy(&sku
[offset
], limits
->mcs
[i
],
3291 ARRAY_SIZE(limits
->mcs
[i
]));
3296 for (i
= 0; i
< ARRAY_SIZE(limits
->ru
); i
++) {
3297 memcpy(&sku
[offset
], limits
->ru
[i
], ARRAY_SIZE(limits
->ru
[i
]));
3298 offset
+= ARRAY_SIZE(limits
->ru
[i
]);
3302 for (i
= 0; i
< ARRAY_SIZE(limits
->eht
); i
++) {
3303 memcpy(&sku
[offset
], limits
->eht
[i
], ARRAY_SIZE(limits
->eht
[i
]));
3304 offset
+= ARRAY_SIZE(limits
->eht
[i
]);
3309 mt7925_mcu_rate_txpower_band(struct mt76_phy
*phy
,
3310 enum nl80211_band band
)
3312 int tx_power
, n_chan
, last_ch
, err
= 0, idx
= 0;
3313 int i
, sku_len
, batch_size
, batch_len
= 3;
3314 struct mt76_dev
*dev
= phy
->dev
;
3315 static const u8 chan_list_2ghz
[] = {
3316 1, 2, 3, 4, 5, 6, 7,
3317 8, 9, 10, 11, 12, 13, 14
3319 static const u8 chan_list_5ghz
[] = {
3320 36, 38, 40, 42, 44, 46, 48,
3321 50, 52, 54, 56, 58, 60, 62,
3322 64, 100, 102, 104, 106, 108, 110,
3323 112, 114, 116, 118, 120, 122, 124,
3324 126, 128, 132, 134, 136, 138, 140,
3325 142, 144, 149, 151, 153, 155, 157,
3328 static const u8 chan_list_6ghz
[] = {
3329 1, 3, 5, 7, 9, 11, 13,
3330 15, 17, 19, 21, 23, 25, 27,
3331 29, 33, 35, 37, 39, 41, 43,
3332 45, 47, 49, 51, 53, 55, 57,
3333 59, 61, 65, 67, 69, 71, 73,
3334 75, 77, 79, 81, 83, 85, 87,
3335 89, 91, 93, 97, 99, 101, 103,
3336 105, 107, 109, 111, 113, 115, 117,
3337 119, 121, 123, 125, 129, 131, 133,
3338 135, 137, 139, 141, 143, 145, 147,
3339 149, 151, 153, 155, 157, 161, 163,
3340 165, 167, 169, 171, 173, 175, 177,
3341 179, 181, 183, 185, 187, 189, 193,
3342 195, 197, 199, 201, 203, 205, 207,
3343 209, 211, 213, 215, 217, 219, 221,
3346 struct mt76_power_limits
*limits
;
3347 struct mt7925_sku_tlv
*sku_tlbv
;
3350 sku_len
= sizeof(*sku_tlbv
);
3351 tx_power
= 2 * phy
->hw
->conf
.power_level
;
3355 if (band
== NL80211_BAND_2GHZ
) {
3356 n_chan
= ARRAY_SIZE(chan_list_2ghz
);
3357 ch_list
= chan_list_2ghz
;
3358 last_ch
= chan_list_2ghz
[ARRAY_SIZE(chan_list_2ghz
) - 1];
3359 } else if (band
== NL80211_BAND_6GHZ
) {
3360 n_chan
= ARRAY_SIZE(chan_list_6ghz
);
3361 ch_list
= chan_list_6ghz
;
3362 last_ch
= chan_list_6ghz
[ARRAY_SIZE(chan_list_6ghz
) - 1];
3364 n_chan
= ARRAY_SIZE(chan_list_5ghz
);
3365 ch_list
= chan_list_5ghz
;
3366 last_ch
= chan_list_5ghz
[ARRAY_SIZE(chan_list_5ghz
) - 1];
3368 batch_size
= DIV_ROUND_UP(n_chan
, batch_len
);
3370 limits
= devm_kmalloc(dev
->dev
, sizeof(*limits
), GFP_KERNEL
);
3374 sku_tlbv
= devm_kmalloc(dev
->dev
, sku_len
, GFP_KERNEL
);
3376 devm_kfree(dev
->dev
, limits
);
3380 for (i
= 0; i
< batch_size
; i
++) {
3381 struct mt7925_tx_power_limit_tlv
*tx_power_tlv
;
3382 int j
, msg_len
, num_ch
;
3383 struct sk_buff
*skb
;
3385 num_ch
= i
== batch_size
- 1 ? n_chan
% batch_len
: batch_len
;
3386 msg_len
= sizeof(*tx_power_tlv
) + num_ch
* sku_len
;
3387 skb
= mt76_mcu_msg_alloc(dev
, NULL
, msg_len
);
3393 tx_power_tlv
= (struct mt7925_tx_power_limit_tlv
*)
3394 skb_put(skb
, sizeof(*tx_power_tlv
));
3396 BUILD_BUG_ON(sizeof(dev
->alpha2
) > sizeof(tx_power_tlv
->alpha2
));
3397 memcpy(tx_power_tlv
->alpha2
, dev
->alpha2
, sizeof(dev
->alpha2
));
3398 tx_power_tlv
->n_chan
= num_ch
;
3399 tx_power_tlv
->tag
= cpu_to_le16(0x1);
3400 tx_power_tlv
->len
= cpu_to_le16(sizeof(*tx_power_tlv
));
3403 case NL80211_BAND_2GHZ
:
3404 tx_power_tlv
->band
= 1;
3406 case NL80211_BAND_6GHZ
:
3407 tx_power_tlv
->band
= 3;
3410 tx_power_tlv
->band
= 2;
3414 for (j
= 0; j
< num_ch
; j
++, idx
++) {
3415 struct ieee80211_channel chan
= {
3416 .hw_value
= ch_list
[idx
],
3419 s8 reg_power
, sar_power
;
3421 reg_power
= mt76_connac_get_ch_power(phy
, &chan
,
3423 sar_power
= mt76_get_sar_power(phy
, &chan
, reg_power
);
3425 mt76_get_rate_power_limits(phy
, &chan
, limits
,
3428 tx_power_tlv
->last_msg
= ch_list
[idx
] == last_ch
;
3429 sku_tlbv
->channel
= ch_list
[idx
];
3431 mt7925_mcu_build_sku(dev
, sku_tlbv
->pwr_limit
,
3433 skb_put_data(skb
, sku_tlbv
, sku_len
);
3435 err
= mt76_mcu_skb_send_msg(dev
, skb
,
3436 MCU_UNI_CMD(SET_POWER_LIMIT
),
3443 devm_kfree(dev
->dev
, sku_tlbv
);
3444 devm_kfree(dev
->dev
, limits
);
3448 int mt7925_mcu_set_rate_txpower(struct mt76_phy
*phy
)
3452 if (phy
->cap
.has_2ghz
) {
3453 err
= mt7925_mcu_rate_txpower_band(phy
,
3459 if (phy
->cap
.has_5ghz
) {
3460 err
= mt7925_mcu_rate_txpower_band(phy
,
3466 if (phy
->cap
.has_6ghz
) {
3467 err
= mt7925_mcu_rate_txpower_band(phy
,
3476 int mt7925_mcu_set_rxfilter(struct mt792x_dev
*dev
, u32 fif
,
3477 u8 bit_op
, u32 bit_map
)
3479 struct mt792x_phy
*phy
= &dev
->phy
;
3489 __le32 bit_map
; /* bit_* for bitmap update */
3493 .band_idx
= phy
->mt76
->band_idx
,
3494 .tag
= cpu_to_le16(UNI_BAND_CONFIG_SET_MAC80211_RX_FILTER
),
3495 .len
= cpu_to_le16(sizeof(req
) - 4),
3497 .mode
= fif
? 0 : 1,
3498 .fif
= cpu_to_le32(fif
),
3499 .bit_map
= cpu_to_le32(bit_map
),
3503 return mt76_mcu_send_msg(&phy
->dev
->mt76
, MCU_UNI_CMD(BAND_CONFIG
),
3504 &req
, sizeof(req
), true);