1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2019 MediaTek Inc.
4 * Author: Roy Luo <royluo@google.com>
5 * Ryder Lee <ryder.lee@mediatek.com>
8 #include <linux/firmware.h>
14 struct mt7615_patch_hdr
{
22 struct mt7615_fw_trailer
{
32 #define MCU_PATCH_ADDRESS 0x80000
34 #define N9_REGION_NUM 2
35 #define CR4_REGION_NUM 1
39 #define FW_FEATURE_SET_ENCRYPT BIT(0)
40 #define FW_FEATURE_SET_KEY_IDX GENMASK(2, 1)
42 #define DL_MODE_ENCRYPT BIT(0)
43 #define DL_MODE_KEY_IDX GENMASK(2, 1)
44 #define DL_MODE_RESET_SEC_IV BIT(3)
45 #define DL_MODE_WORKING_PDA_CR4 BIT(4)
46 #define DL_MODE_NEED_RSP BIT(31)
48 #define FW_START_OVERRIDE BIT(0)
49 #define FW_START_WORKING_PDA_CR4 BIT(2)
51 static int __mt7615_mcu_msg_send(struct mt7615_dev
*dev
, struct sk_buff
*skb
,
52 int cmd
, int *wait_seq
)
54 struct mt7615_mcu_txd
*mcu_txd
;
55 u8 seq
, q_idx
, pkt_fmt
;
60 seq
= ++dev
->mt76
.mmio
.mcu
.msg_seq
& 0xf;
62 seq
= ++dev
->mt76
.mmio
.mcu
.msg_seq
& 0xf;
64 mcu_txd
= (struct mt7615_mcu_txd
*)skb_push(skb
,
65 sizeof(struct mt7615_mcu_txd
));
66 memset(mcu_txd
, 0, sizeof(struct mt7615_mcu_txd
));
68 if (cmd
!= -MCU_CMD_FW_SCATTER
) {
69 q_idx
= MT_TX_MCU_PORT_RX_Q0
;
70 pkt_fmt
= MT_TX_TYPE_CMD
;
72 q_idx
= MT_TX_MCU_PORT_RX_FWDL
;
73 pkt_fmt
= MT_TX_TYPE_FW
;
78 val
= FIELD_PREP(MT_TXD0_TX_BYTES
, skb
->len
) |
79 FIELD_PREP(MT_TXD0_P_IDX
, MT_TX_PORT_IDX_MCU
) |
80 FIELD_PREP(MT_TXD0_Q_IDX
, q_idx
);
81 txd
[0] = cpu_to_le32(val
);
83 val
= MT_TXD1_LONG_FORMAT
|
84 FIELD_PREP(MT_TXD1_HDR_FORMAT
, MT_HDR_FORMAT_CMD
) |
85 FIELD_PREP(MT_TXD1_PKT_FMT
, pkt_fmt
);
86 txd
[1] = cpu_to_le32(val
);
88 mcu_txd
->len
= cpu_to_le16(skb
->len
- sizeof(mcu_txd
->txd
));
89 mcu_txd
->pq_id
= cpu_to_le16(MCU_PQ_ID(MT_TX_PORT_IDX_MCU
, q_idx
));
90 mcu_txd
->pkt_type
= MCU_PKT_ID
;
94 mcu_txd
->set_query
= MCU_Q_NA
;
97 mcu_txd
->cid
= MCU_CMD_EXT_CID
;
98 mcu_txd
->set_query
= MCU_Q_SET
;
99 mcu_txd
->ext_cid
= cmd
;
100 mcu_txd
->ext_cid_ack
= 1;
102 mcu_txd
->s2d_index
= MCU_S2D_H2N
;
107 if (test_bit(MT76_STATE_MCU_RUNNING
, &dev
->mt76
.state
))
112 return mt76_tx_queue_skb_raw(dev
, qid
, skb
, 0);
116 mt7615_mcu_parse_response(struct mt7615_dev
*dev
, int cmd
,
117 struct sk_buff
*skb
, int seq
)
119 struct mt7615_mcu_rxd
*rxd
= (struct mt7615_mcu_rxd
*)skb
->data
;
126 case -MCU_CMD_PATCH_SEM_CONTROL
:
127 skb_pull(skb
, sizeof(*rxd
) - 4);
130 case MCU_EXT_CMD_GET_TEMP
:
131 skb_pull(skb
, sizeof(*rxd
));
132 ret
= le32_to_cpu(*(__le32
*)skb
->data
);
143 mt7615_mcu_msg_send(struct mt76_dev
*mdev
, int cmd
, const void *data
,
144 int len
, bool wait_resp
)
146 struct mt7615_dev
*dev
= container_of(mdev
, struct mt7615_dev
, mt76
);
147 unsigned long expires
= jiffies
+ 10 * HZ
;
151 skb
= mt7615_mcu_msg_alloc(data
, len
);
155 mutex_lock(&mdev
->mmio
.mcu
.mutex
);
157 ret
= __mt7615_mcu_msg_send(dev
, skb
, cmd
, &seq
);
162 skb
= mt76_mcu_get_response(mdev
, expires
);
164 dev_err(mdev
->dev
, "Message %d (seq %d) timeout\n",
170 ret
= mt7615_mcu_parse_response(dev
, cmd
, skb
, seq
);
176 mutex_unlock(&mdev
->mmio
.mcu
.mutex
);
182 mt7615_mcu_csa_finish(void *priv
, u8
*mac
, struct ieee80211_vif
*vif
)
185 ieee80211_csa_finish(vif
);
189 mt7615_mcu_rx_ext_event(struct mt7615_dev
*dev
, struct sk_buff
*skb
)
191 struct mt7615_mcu_rxd
*rxd
= (struct mt7615_mcu_rxd
*)skb
->data
;
193 switch (rxd
->ext_eid
) {
194 case MCU_EXT_EVENT_RDD_REPORT
:
195 ieee80211_radar_detected(dev
->mt76
.hw
);
198 case MCU_EXT_EVENT_CSA_NOTIFY
:
199 ieee80211_iterate_active_interfaces_atomic(dev
->mt76
.hw
,
200 IEEE80211_IFACE_ITER_RESUME_ALL
,
201 mt7615_mcu_csa_finish
, dev
);
209 mt7615_mcu_rx_unsolicited_event(struct mt7615_dev
*dev
, struct sk_buff
*skb
)
211 struct mt7615_mcu_rxd
*rxd
= (struct mt7615_mcu_rxd
*)skb
->data
;
215 mt7615_mcu_rx_ext_event(dev
, skb
);
223 void mt7615_mcu_rx_event(struct mt7615_dev
*dev
, struct sk_buff
*skb
)
225 struct mt7615_mcu_rxd
*rxd
= (struct mt7615_mcu_rxd
*)skb
->data
;
227 if (rxd
->ext_eid
== MCU_EXT_EVENT_THERMAL_PROTECT
||
228 rxd
->ext_eid
== MCU_EXT_EVENT_FW_LOG_2_HOST
||
229 rxd
->ext_eid
== MCU_EXT_EVENT_ASSERT_DUMP
||
230 rxd
->ext_eid
== MCU_EXT_EVENT_PS_SYNC
||
232 mt7615_mcu_rx_unsolicited_event(dev
, skb
);
234 mt76_mcu_rx_event(&dev
->mt76
, skb
);
237 static int mt7615_mcu_init_download(struct mt7615_dev
*dev
, u32 addr
,
245 .addr
= cpu_to_le32(addr
),
246 .len
= cpu_to_le32(len
),
247 .mode
= cpu_to_le32(mode
),
250 return __mt76_mcu_send_msg(&dev
->mt76
, -MCU_CMD_TARGET_ADDRESS_LEN_REQ
,
251 &req
, sizeof(req
), true);
254 static int mt7615_mcu_send_firmware(struct mt7615_dev
*dev
, const void *data
,
257 int ret
= 0, cur_len
;
260 cur_len
= min_t(int, 4096 - sizeof(struct mt7615_mcu_txd
),
263 ret
= __mt76_mcu_send_msg(&dev
->mt76
, -MCU_CMD_FW_SCATTER
,
264 data
, cur_len
, false);
270 mt76_queue_tx_cleanup(dev
, MT_TXQ_FWDL
, false);
276 static int mt7615_mcu_start_firmware(struct mt7615_dev
*dev
, u32 addr
,
283 .option
= cpu_to_le32(option
),
284 .addr
= cpu_to_le32(addr
),
287 return __mt76_mcu_send_msg(&dev
->mt76
, -MCU_CMD_FW_START_REQ
,
288 &req
, sizeof(req
), true);
291 static int mt7615_mcu_restart(struct mt76_dev
*dev
)
293 return __mt76_mcu_send_msg(dev
, -MCU_CMD_RESTART_DL_REQ
, NULL
,
297 static int mt7615_mcu_patch_sem_ctrl(struct mt7615_dev
*dev
, bool get
)
302 .op
= cpu_to_le32(get
? PATCH_SEM_GET
: PATCH_SEM_RELEASE
),
305 return __mt76_mcu_send_msg(&dev
->mt76
, -MCU_CMD_PATCH_SEM_CONTROL
,
306 &req
, sizeof(req
), true);
309 static int mt7615_mcu_start_patch(struct mt7615_dev
*dev
)
318 return __mt76_mcu_send_msg(&dev
->mt76
, -MCU_CMD_PATCH_FINISH_REQ
,
319 &req
, sizeof(req
), true);
322 static int mt7615_driver_own(struct mt7615_dev
*dev
)
324 mt76_wr(dev
, MT_CFG_LPCR_HOST
, MT_CFG_LPCR_HOST_DRV_OWN
);
325 if (!mt76_poll_msec(dev
, MT_CFG_LPCR_HOST
,
326 MT_CFG_LPCR_HOST_FW_OWN
, 0, 500)) {
327 dev_err(dev
->mt76
.dev
, "Timeout for driver own\n");
334 static int mt7615_load_patch(struct mt7615_dev
*dev
)
336 const struct mt7615_patch_hdr
*hdr
;
337 const struct firmware
*fw
= NULL
;
340 sem
= mt7615_mcu_patch_sem_ctrl(dev
, 1);
344 case PATCH_NOT_DL_SEM_SUCCESS
:
347 dev_err(dev
->mt76
.dev
, "Failed to get patch semaphore\n");
351 ret
= request_firmware(&fw
, MT7615_ROM_PATCH
, dev
->mt76
.dev
);
355 if (!fw
|| !fw
->data
|| fw
->size
< sizeof(*hdr
)) {
356 dev_err(dev
->mt76
.dev
, "Invalid firmware\n");
361 hdr
= (const struct mt7615_patch_hdr
*)(fw
->data
);
363 dev_info(dev
->mt76
.dev
, "HW/SW Version: 0x%x, Build Time: %.16s\n",
364 be32_to_cpu(hdr
->hw_sw_ver
), hdr
->build_date
);
366 len
= fw
->size
- sizeof(*hdr
);
368 ret
= mt7615_mcu_init_download(dev
, MCU_PATCH_ADDRESS
, len
,
371 dev_err(dev
->mt76
.dev
, "Download request failed\n");
375 ret
= mt7615_mcu_send_firmware(dev
, fw
->data
+ sizeof(*hdr
), len
);
377 dev_err(dev
->mt76
.dev
, "Failed to send firmware to device\n");
381 ret
= mt7615_mcu_start_patch(dev
);
383 dev_err(dev
->mt76
.dev
, "Failed to start patch\n");
386 release_firmware(fw
);
388 sem
= mt7615_mcu_patch_sem_ctrl(dev
, 0);
390 case PATCH_REL_SEM_SUCCESS
:
394 dev_err(dev
->mt76
.dev
, "Failed to release patch semaphore\n");
401 static u32
mt7615_mcu_gen_dl_mode(u8 feature_set
, bool is_cr4
)
405 ret
|= (feature_set
& FW_FEATURE_SET_ENCRYPT
) ?
406 (DL_MODE_ENCRYPT
| DL_MODE_RESET_SEC_IV
) : 0;
407 ret
|= FIELD_PREP(DL_MODE_KEY_IDX
,
408 FIELD_GET(FW_FEATURE_SET_KEY_IDX
, feature_set
));
409 ret
|= DL_MODE_NEED_RSP
;
410 ret
|= is_cr4
? DL_MODE_WORKING_PDA_CR4
: 0;
416 mt7615_mcu_send_ram_firmware(struct mt7615_dev
*dev
,
417 const struct mt7615_fw_trailer
*hdr
,
418 const u8
*data
, bool is_cr4
)
420 int n_region
= is_cr4
? CR4_REGION_NUM
: N9_REGION_NUM
;
421 int err
, i
, offset
= 0;
424 for (i
= 0; i
< n_region
; i
++) {
425 mode
= mt7615_mcu_gen_dl_mode(hdr
[i
].feature_set
, is_cr4
);
426 len
= le32_to_cpu(hdr
[i
].len
) + IMG_CRC_LEN
;
427 addr
= le32_to_cpu(hdr
[i
].addr
);
429 err
= mt7615_mcu_init_download(dev
, addr
, len
, mode
);
431 dev_err(dev
->mt76
.dev
, "Download request failed\n");
435 err
= mt7615_mcu_send_firmware(dev
, data
+ offset
, len
);
437 dev_err(dev
->mt76
.dev
, "Failed to send firmware to device\n");
447 static int mt7615_load_ram(struct mt7615_dev
*dev
)
449 const struct mt7615_fw_trailer
*hdr
;
450 const struct firmware
*fw
;
453 ret
= request_firmware(&fw
, MT7615_FIRMWARE_N9
, dev
->mt76
.dev
);
457 if (!fw
|| !fw
->data
|| fw
->size
< N9_REGION_NUM
* sizeof(*hdr
)) {
458 dev_err(dev
->mt76
.dev
, "Invalid firmware\n");
463 hdr
= (const struct mt7615_fw_trailer
*)(fw
->data
+ fw
->size
-
464 N9_REGION_NUM
* sizeof(*hdr
));
466 dev_info(dev
->mt76
.dev
, "N9 Firmware Version: %.10s, Build Time: %.15s\n",
467 hdr
->fw_ver
, hdr
->build_date
);
469 ret
= mt7615_mcu_send_ram_firmware(dev
, hdr
, fw
->data
, false);
473 ret
= mt7615_mcu_start_firmware(dev
, le32_to_cpu(hdr
->addr
),
476 dev_err(dev
->mt76
.dev
, "Failed to start N9 firmware\n");
480 release_firmware(fw
);
482 ret
= request_firmware(&fw
, MT7615_FIRMWARE_CR4
, dev
->mt76
.dev
);
486 if (!fw
|| !fw
->data
|| fw
->size
< CR4_REGION_NUM
* sizeof(*hdr
)) {
487 dev_err(dev
->mt76
.dev
, "Invalid firmware\n");
492 hdr
= (const struct mt7615_fw_trailer
*)(fw
->data
+ fw
->size
-
493 CR4_REGION_NUM
* sizeof(*hdr
));
495 dev_info(dev
->mt76
.dev
, "CR4 Firmware Version: %.10s, Build Time: %.15s\n",
496 hdr
->fw_ver
, hdr
->build_date
);
498 ret
= mt7615_mcu_send_ram_firmware(dev
, hdr
, fw
->data
, true);
502 ret
= mt7615_mcu_start_firmware(dev
, 0, FW_START_WORKING_PDA_CR4
);
504 dev_err(dev
->mt76
.dev
, "Failed to start CR4 firmware\n");
507 release_firmware(fw
);
512 static int mt7615_load_firmware(struct mt7615_dev
*dev
)
517 val
= mt76_get_field(dev
, MT_TOP_MISC2
, MT_TOP_MISC2_FW_STATE
);
519 if (val
!= FW_STATE_FW_DOWNLOAD
) {
520 dev_err(dev
->mt76
.dev
, "Firmware is not ready for download\n");
524 ret
= mt7615_load_patch(dev
);
528 ret
= mt7615_load_ram(dev
);
532 if (!mt76_poll_msec(dev
, MT_TOP_MISC2
, MT_TOP_MISC2_FW_STATE
,
533 FIELD_PREP(MT_TOP_MISC2_FW_STATE
,
534 FW_STATE_CR4_RDY
), 500)) {
535 dev_err(dev
->mt76
.dev
, "Timeout for initializing firmware\n");
539 mt76_queue_tx_cleanup(dev
, MT_TXQ_FWDL
, false);
541 dev_dbg(dev
->mt76
.dev
, "Firmware init done\n");
546 int mt7615_mcu_init(struct mt7615_dev
*dev
)
548 static const struct mt76_mcu_ops mt7615_mcu_ops
= {
549 .mcu_send_msg
= mt7615_mcu_msg_send
,
550 .mcu_restart
= mt7615_mcu_restart
,
554 dev
->mt76
.mcu_ops
= &mt7615_mcu_ops
,
556 ret
= mt7615_driver_own(dev
);
560 ret
= mt7615_load_firmware(dev
);
564 set_bit(MT76_STATE_MCU_RUNNING
, &dev
->mt76
.state
);
569 void mt7615_mcu_exit(struct mt7615_dev
*dev
)
571 __mt76_mcu_restart(&dev
->mt76
);
572 mt76_wr(dev
, MT_CFG_LPCR_HOST
, MT_CFG_LPCR_HOST_FW_OWN
);
573 skb_queue_purge(&dev
->mt76
.mmio
.mcu
.res_q
);
576 int mt7615_mcu_set_eeprom(struct mt7615_dev
*dev
)
582 } __packed req_hdr
= {
584 .len
= __MT_EE_MAX
- MT_EE_NIC_CONF_0
,
586 int ret
, len
= sizeof(req_hdr
) + __MT_EE_MAX
- MT_EE_NIC_CONF_0
;
587 u8
*req
, *eep
= (u8
*)dev
->mt76
.eeprom
.data
;
589 req
= kzalloc(len
, GFP_KERNEL
);
593 memcpy(req
, &req_hdr
, sizeof(req_hdr
));
594 memcpy(req
+ sizeof(req_hdr
), eep
+ MT_EE_NIC_CONF_0
,
595 __MT_EE_MAX
- MT_EE_NIC_CONF_0
);
597 ret
= __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_EFUSE_BUFFER_MODE
,
604 int mt7615_mcu_init_mac(struct mt7615_dev
*dev
)
615 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_MAC_INIT_CTRL
,
616 &req
, sizeof(req
), true);
619 int mt7615_mcu_set_rts_thresh(struct mt7615_dev
*dev
, u32 val
)
630 .len_thresh
= cpu_to_le32(val
),
631 .pkt_thresh
= cpu_to_le32(0x2),
634 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_PROTECT_CTRL
,
635 &req
, sizeof(req
), true);
638 int mt7615_mcu_set_wmm(struct mt7615_dev
*dev
, u8 queue
,
639 const struct ieee80211_tx_queue_params
*params
)
641 #define WMM_AIFS_SET BIT(0)
642 #define WMM_CW_MIN_SET BIT(1)
643 #define WMM_CW_MAX_SET BIT(2)
644 #define WMM_TXOP_SET BIT(3)
645 #define WMM_PARAM_SET (WMM_AIFS_SET | WMM_CW_MIN_SET | \
646 WMM_CW_MAX_SET | WMM_TXOP_SET)
659 .valid
= WMM_PARAM_SET
,
660 .aifs
= params
->aifs
,
662 .cw_max
= cpu_to_le16(10),
663 .txop
= cpu_to_le16(params
->txop
),
667 req
.cw_min
= fls(params
->cw_min
);
669 req
.cw_max
= cpu_to_le16(fls(params
->cw_max
));
671 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_EDCA_UPDATE
,
672 &req
, sizeof(req
), true);
675 int mt7615_mcu_ctrl_pm_state(struct mt7615_dev
*dev
, int enter
)
677 #define ENTER_PM_STATE 1
678 #define EXIT_PM_STATE 2
697 .pm_state
= (enter
) ? ENTER_PM_STATE
: EXIT_PM_STATE
,
701 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_PM_STATE_CTRL
,
702 &req
, sizeof(req
), true);
705 int mt7615_mcu_set_dev_info(struct mt7615_dev
*dev
,
706 struct ieee80211_vif
*vif
, bool enable
)
708 struct mt7615_vif
*mvif
= (struct mt7615_vif
*)vif
->drv_priv
;
722 u8 omac_addr
[ETH_ALEN
];
726 .omac_idx
= mvif
->omac_idx
,
727 .band_idx
= mvif
->band_idx
,
728 .tlv_num
= cpu_to_le16(1),
732 .tag
= cpu_to_le16(DEV_INFO_ACTIVE
),
733 .len
= cpu_to_le16(sizeof(struct req_tlv
)),
735 .band_idx
= mvif
->band_idx
,
739 memcpy(data
.tlv
.omac_addr
, vif
->addr
, ETH_ALEN
);
740 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_DEV_INFO_UPDATE
,
741 &data
, sizeof(data
), true);
745 mt7615_mcu_bss_info_omac_header(struct mt7615_vif
*mvif
, u8
*data
,
748 struct bss_info_omac
*hdr
= (struct bss_info_omac
*)data
;
751 idx
= mvif
->omac_idx
> EXT_BSSID_START
? HW_BSSID_0
: mvif
->omac_idx
;
752 hdr
->tag
= cpu_to_le16(BSS_INFO_OMAC
);
753 hdr
->len
= cpu_to_le16(sizeof(struct bss_info_omac
));
754 hdr
->hw_bss_idx
= idx
;
755 hdr
->omac_idx
= mvif
->omac_idx
;
756 hdr
->band_idx
= mvif
->band_idx
;
757 hdr
->conn_type
= cpu_to_le32(conn_type
);
761 mt7615_mcu_bss_info_basic_header(struct ieee80211_vif
*vif
, u8
*data
,
762 u32 net_type
, u8 tx_wlan_idx
,
765 struct mt7615_vif
*mvif
= (struct mt7615_vif
*)vif
->drv_priv
;
766 struct bss_info_basic
*hdr
= (struct bss_info_basic
*)data
;
768 hdr
->tag
= cpu_to_le16(BSS_INFO_BASIC
);
769 hdr
->len
= cpu_to_le16(sizeof(struct bss_info_basic
));
770 hdr
->network_type
= cpu_to_le32(net_type
);
771 hdr
->active
= enable
;
772 hdr
->bcn_interval
= cpu_to_le16(vif
->bss_conf
.beacon_int
);
773 memcpy(hdr
->bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
774 hdr
->wmm_idx
= mvif
->wmm_idx
;
775 hdr
->dtim_period
= vif
->bss_conf
.dtim_period
;
776 hdr
->bmc_tx_wlan_idx
= tx_wlan_idx
;
780 mt7615_mcu_bss_info_ext_header(struct mt7615_vif
*mvif
, u8
*data
)
782 /* SIFS 20us + 512 byte beacon tranmitted by 1Mbps (3906us) */
783 #define BCN_TX_ESTIMATE_TIME (4096 + 20)
784 struct bss_info_ext_bss
*hdr
= (struct bss_info_ext_bss
*)data
;
785 int ext_bss_idx
, tsf_offset
;
787 ext_bss_idx
= mvif
->omac_idx
- EXT_BSSID_START
;
791 hdr
->tag
= cpu_to_le16(BSS_INFO_EXT_BSS
);
792 hdr
->len
= cpu_to_le16(sizeof(struct bss_info_ext_bss
));
793 tsf_offset
= ext_bss_idx
* BCN_TX_ESTIMATE_TIME
;
794 hdr
->mbss_tsf_offset
= cpu_to_le32(tsf_offset
);
797 int mt7615_mcu_set_bss_info(struct mt7615_dev
*dev
,
798 struct ieee80211_vif
*vif
, int en
)
800 struct mt7615_vif
*mvif
= (struct mt7615_vif
*)vif
->drv_priv
;
808 int len
= sizeof(struct req_hdr
) + sizeof(struct bss_info_basic
);
809 int ret
, i
, features
= BIT(BSS_INFO_BASIC
), ntlv
= 1;
810 u32 conn_type
= 0, net_type
= NETWORK_INFRA
;
811 u8
*buf
, *data
, tx_wlan_idx
= 0;
815 len
+= sizeof(struct bss_info_omac
);
816 features
|= BIT(BSS_INFO_OMAC
);
817 if (mvif
->omac_idx
> EXT_BSSID_START
) {
818 len
+= sizeof(struct bss_info_ext_bss
);
819 features
|= BIT(BSS_INFO_EXT_BSS
);
826 case NL80211_IFTYPE_AP
:
827 case NL80211_IFTYPE_MESH_POINT
:
828 tx_wlan_idx
= mvif
->sta
.wcid
.idx
;
829 conn_type
= CONNECTION_INFRA_AP
;
831 case NL80211_IFTYPE_STATION
: {
832 /* TODO: enable BSS_INFO_UAPSD & BSS_INFO_PM */
834 struct ieee80211_sta
*sta
;
835 struct mt7615_sta
*msta
;
838 sta
= ieee80211_find_sta(vif
, vif
->bss_conf
.bssid
);
844 msta
= (struct mt7615_sta
*)sta
->drv_priv
;
845 tx_wlan_idx
= msta
->wcid
.idx
;
848 conn_type
= CONNECTION_INFRA_STA
;
851 case NL80211_IFTYPE_ADHOC
:
852 conn_type
= CONNECTION_IBSS_ADHOC
;
853 tx_wlan_idx
= mvif
->sta
.wcid
.idx
;
854 net_type
= NETWORK_IBSS
;
861 buf
= kzalloc(len
, GFP_KERNEL
);
865 hdr
= (struct req_hdr
*)buf
;
866 hdr
->bss_idx
= mvif
->idx
;
867 hdr
->tlv_num
= cpu_to_le16(ntlv
);
868 hdr
->is_tlv_append
= 1;
870 data
= buf
+ sizeof(*hdr
);
871 for (i
= 0; i
< BSS_INFO_MAX_NUM
; i
++) {
872 int tag
= ffs(features
& BIT(i
)) - 1;
876 mt7615_mcu_bss_info_omac_header(mvif
, data
,
878 data
+= sizeof(struct bss_info_omac
);
881 mt7615_mcu_bss_info_basic_header(vif
, data
, net_type
,
883 data
+= sizeof(struct bss_info_basic
);
885 case BSS_INFO_EXT_BSS
:
886 mt7615_mcu_bss_info_ext_header(mvif
, data
);
887 data
+= sizeof(struct bss_info_ext_bss
);
894 ret
= __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_BSS_INFO_UPDATE
,
902 mt7615_mcu_add_wtbl_bmc(struct mt7615_dev
*dev
,
903 struct mt7615_vif
*mvif
)
906 struct wtbl_req_hdr hdr
;
907 struct wtbl_generic g_wtbl
;
908 struct wtbl_rx rx_wtbl
;
911 .wlan_idx
= mvif
->sta
.wcid
.idx
,
912 .operation
= WTBL_RESET_AND_SET
,
913 .tlv_num
= cpu_to_le16(2),
916 .tag
= cpu_to_le16(WTBL_GENERIC
),
917 .len
= cpu_to_le16(sizeof(struct wtbl_generic
)),
921 .tag
= cpu_to_le16(WTBL_RX
),
922 .len
= cpu_to_le16(sizeof(struct wtbl_rx
)),
928 eth_broadcast_addr(req
.g_wtbl
.peer_addr
);
930 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_WTBL_UPDATE
,
931 &req
, sizeof(req
), true);
934 int mt7615_mcu_wtbl_bmc(struct mt7615_dev
*dev
,
935 struct ieee80211_vif
*vif
, bool enable
)
937 struct mt7615_vif
*mvif
= (struct mt7615_vif
*)vif
->drv_priv
;
940 struct wtbl_req_hdr req
= {
941 .wlan_idx
= mvif
->sta
.wcid
.idx
,
942 .operation
= WTBL_RESET_AND_SET
,
945 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_WTBL_UPDATE
,
946 &req
, sizeof(req
), true);
949 return mt7615_mcu_add_wtbl_bmc(dev
, mvif
);
952 int mt7615_mcu_add_wtbl(struct mt7615_dev
*dev
, struct ieee80211_vif
*vif
,
953 struct ieee80211_sta
*sta
)
955 struct mt7615_vif
*mvif
= (struct mt7615_vif
*)vif
->drv_priv
;
956 struct mt7615_sta
*msta
= (struct mt7615_sta
*)sta
->drv_priv
;
958 struct wtbl_req_hdr hdr
;
959 struct wtbl_generic g_wtbl
;
960 struct wtbl_rx rx_wtbl
;
963 .wlan_idx
= msta
->wcid
.idx
,
964 .operation
= WTBL_RESET_AND_SET
,
965 .tlv_num
= cpu_to_le16(2),
968 .tag
= cpu_to_le16(WTBL_GENERIC
),
969 .len
= cpu_to_le16(sizeof(struct wtbl_generic
)),
970 .muar_idx
= mvif
->omac_idx
,
972 .partial_aid
= cpu_to_le16(sta
->aid
),
975 .tag
= cpu_to_le16(WTBL_RX
),
976 .len
= cpu_to_le16(sizeof(struct wtbl_rx
)),
977 .rca1
= vif
->type
!= NL80211_IFTYPE_AP
,
982 memcpy(req
.g_wtbl
.peer_addr
, sta
->addr
, ETH_ALEN
);
984 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_WTBL_UPDATE
,
985 &req
, sizeof(req
), true);
988 int mt7615_mcu_del_wtbl(struct mt7615_dev
*dev
,
989 struct ieee80211_sta
*sta
)
991 struct mt7615_sta
*msta
= (struct mt7615_sta
*)sta
->drv_priv
;
992 struct wtbl_req_hdr req
= {
993 .wlan_idx
= msta
->wcid
.idx
,
994 .operation
= WTBL_RESET_AND_SET
,
997 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_WTBL_UPDATE
,
998 &req
, sizeof(req
), true);
1001 int mt7615_mcu_del_wtbl_all(struct mt7615_dev
*dev
)
1003 struct wtbl_req_hdr req
= {
1004 .operation
= WTBL_RESET_ALL
,
1007 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_WTBL_UPDATE
,
1008 &req
, sizeof(req
), true);
1011 int mt7615_mcu_set_sta_rec_bmc(struct mt7615_dev
*dev
,
1012 struct ieee80211_vif
*vif
, bool en
)
1014 struct mt7615_vif
*mvif
= (struct mt7615_vif
*)vif
->drv_priv
;
1016 struct sta_req_hdr hdr
;
1017 struct sta_rec_basic basic
;
1020 .bss_idx
= mvif
->idx
,
1021 .wlan_idx
= mvif
->sta
.wcid
.idx
,
1022 .tlv_num
= cpu_to_le16(1),
1024 .muar_idx
= mvif
->omac_idx
,
1027 .tag
= cpu_to_le16(STA_REC_BASIC
),
1028 .len
= cpu_to_le16(sizeof(struct sta_rec_basic
)),
1029 .conn_type
= cpu_to_le32(CONNECTION_INFRA_BC
),
1032 eth_broadcast_addr(req
.basic
.peer_addr
);
1035 req
.basic
.conn_state
= CONN_STATE_PORT_SECURE
;
1036 req
.basic
.extra_info
= cpu_to_le16(EXTRA_INFO_VER
|
1039 req
.basic
.conn_state
= CONN_STATE_DISCONNECT
;
1040 req
.basic
.extra_info
= cpu_to_le16(EXTRA_INFO_VER
);
1043 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_STA_REC_UPDATE
,
1044 &req
, sizeof(req
), true);
1047 int mt7615_mcu_set_sta_rec(struct mt7615_dev
*dev
, struct ieee80211_vif
*vif
,
1048 struct ieee80211_sta
*sta
, bool en
)
1050 struct mt7615_vif
*mvif
= (struct mt7615_vif
*)vif
->drv_priv
;
1051 struct mt7615_sta
*msta
= (struct mt7615_sta
*)sta
->drv_priv
;
1054 struct sta_req_hdr hdr
;
1055 struct sta_rec_basic basic
;
1058 .bss_idx
= mvif
->idx
,
1059 .wlan_idx
= msta
->wcid
.idx
,
1060 .tlv_num
= cpu_to_le16(1),
1062 .muar_idx
= mvif
->omac_idx
,
1065 .tag
= cpu_to_le16(STA_REC_BASIC
),
1066 .len
= cpu_to_le16(sizeof(struct sta_rec_basic
)),
1068 .aid
= cpu_to_le16(sta
->aid
),
1071 memcpy(req
.basic
.peer_addr
, sta
->addr
, ETH_ALEN
);
1073 switch (vif
->type
) {
1074 case NL80211_IFTYPE_AP
:
1075 case NL80211_IFTYPE_MESH_POINT
:
1076 req
.basic
.conn_type
= cpu_to_le32(CONNECTION_INFRA_STA
);
1078 case NL80211_IFTYPE_STATION
:
1079 req
.basic
.conn_type
= cpu_to_le32(CONNECTION_INFRA_AP
);
1081 case NL80211_IFTYPE_ADHOC
:
1082 req
.basic
.conn_type
= cpu_to_le32(CONNECTION_IBSS_ADHOC
);
1090 req
.basic
.conn_state
= CONN_STATE_PORT_SECURE
;
1091 req
.basic
.extra_info
= cpu_to_le16(EXTRA_INFO_VER
|
1094 req
.basic
.conn_state
= CONN_STATE_DISCONNECT
;
1095 req
.basic
.extra_info
= cpu_to_le16(EXTRA_INFO_VER
);
1098 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_STA_REC_UPDATE
,
1099 &req
, sizeof(req
), true);
1102 int mt7615_mcu_set_bcn(struct mt7615_dev
*dev
, struct ieee80211_vif
*vif
,
1105 struct mt7615_vif
*mvif
= (struct mt7615_vif
*)vif
->drv_priv
;
1106 struct mt76_wcid
*wcid
= &dev
->mt76
.global_wcid
;
1107 struct ieee80211_mutable_offsets offs
;
1114 u8 need_pre_tbtt_int
;
1120 /* bss color change */
1124 .omac_idx
= mvif
->omac_idx
,
1126 .wlan_idx
= wcid
->idx
,
1127 .band_idx
= mvif
->band_idx
,
1129 struct sk_buff
*skb
;
1131 skb
= ieee80211_beacon_get_template(mt76_hw(dev
), vif
, &offs
);
1135 if (skb
->len
> 512 - MT_TXD_SIZE
) {
1136 dev_err(dev
->mt76
.dev
, "Bcn size limit exceed\n");
1141 mt7615_mac_write_txwi(dev
, (__le32
*)(req
.pkt
), skb
, wcid
, NULL
,
1143 memcpy(req
.pkt
+ MT_TXD_SIZE
, skb
->data
, skb
->len
);
1144 req
.pkt_len
= cpu_to_le16(MT_TXD_SIZE
+ skb
->len
);
1145 req
.tim_ie_pos
= cpu_to_le16(MT_TXD_SIZE
+ offs
.tim_offset
);
1146 if (offs
.csa_counter_offs
[0]) {
1149 csa_offs
= MT_TXD_SIZE
+ offs
.csa_counter_offs
[0] - 4;
1150 req
.csa_ie_pos
= cpu_to_le16(csa_offs
);
1151 req
.csa_cnt
= skb
->data
[offs
.csa_counter_offs
[0]];
1155 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_BCN_OFFLOAD
,
1156 &req
, sizeof(req
), true);
1159 int mt7615_mcu_set_tx_power(struct mt7615_dev
*dev
)
1161 int i
, ret
, n_chains
= hweight8(dev
->mt76
.antenna_mask
);
1162 struct cfg80211_chan_def
*chandef
= &dev
->mt76
.chandef
;
1163 int freq
= chandef
->center_freq1
, len
, target_chains
;
1164 u8
*req
, *data
, *eep
= (u8
*)dev
->mt76
.eeprom
.data
;
1165 enum nl80211_band band
= chandef
->chan
->band
;
1166 struct ieee80211_hw
*hw
= mt76_hw(dev
);
1172 } __packed req_hdr
= {
1173 .center_chan
= ieee80211_frequency_to_channel(freq
),
1178 len
= sizeof(req_hdr
) + __MT_EE_MAX
- MT_EE_NIC_CONF_0
;
1179 req
= kzalloc(len
, GFP_KERNEL
);
1183 memcpy(req
, &req_hdr
, sizeof(req_hdr
));
1184 data
= req
+ sizeof(req_hdr
);
1185 memcpy(data
, eep
+ MT_EE_NIC_CONF_0
,
1186 __MT_EE_MAX
- MT_EE_NIC_CONF_0
);
1188 tx_power
= hw
->conf
.power_level
* 2;
1202 tx_power
= max_t(s8
, tx_power
, 0);
1203 dev
->mt76
.txpower_cur
= tx_power
;
1205 target_chains
= mt7615_ext_pa_enabled(dev
, band
) ? 1 : n_chains
;
1206 for (i
= 0; i
< target_chains
; i
++) {
1207 int index
= -MT_EE_NIC_CONF_0
;
1209 ret
= mt7615_eeprom_get_power_index(dev
, chandef
->chan
, i
);
1214 data
[index
] = min_t(u8
, data
[index
], tx_power
);
1217 ret
= __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_SET_TX_POWER_CTRL
,
1225 int mt7615_mcu_rdd_cmd(struct mt7615_dev
*dev
,
1226 enum mt7615_rdd_cmd cmd
, u8 index
,
1238 .rdd_rx_sel
= rx_sel
,
1242 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_SET_RDD_CTRL
,
1243 &req
, sizeof(req
), true);
1246 int mt7615_mcu_rdd_send_pattern(struct mt7615_dev
*dev
)
1257 .pulse_num
= dev
->radar_pattern
.n_pulses
,
1259 u32 start_time
= ktime_to_ms(ktime_get_boottime());
1262 if (dev
->radar_pattern
.n_pulses
> ARRAY_SIZE(req
.pattern
))
1265 /* TODO: add some noise here */
1266 for (i
= 0; i
< dev
->radar_pattern
.n_pulses
; i
++) {
1267 req
.pattern
[i
].width
= dev
->radar_pattern
.width
;
1268 req
.pattern
[i
].power
= dev
->radar_pattern
.power
;
1269 req
.pattern
[i
].start_time
= start_time
+
1270 i
* dev
->radar_pattern
.period
;
1273 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_SET_RDD_PATTERN
,
1274 &req
, sizeof(req
), false);
1277 int mt7615_mcu_set_channel(struct mt7615_dev
*dev
)
1279 struct cfg80211_chan_def
*chandef
= &dev
->mt76
.chandef
;
1280 int freq1
= chandef
->center_freq1
, freq2
= chandef
->center_freq2
;
1289 /* for 80+80 only */
1294 __le32 outband_freq
;
1300 .control_chan
= chandef
->chan
->hw_value
,
1301 .center_chan
= ieee80211_frequency_to_channel(freq1
),
1302 .tx_streams
= (dev
->mt76
.chainmask
>> 8) & 0xf,
1303 .rx_streams_mask
= dev
->mt76
.antenna_mask
,
1304 .center_chan2
= ieee80211_frequency_to_channel(freq2
),
1308 if (dev
->mt76
.hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
)
1309 req
.switch_reason
= CH_SWITCH_SCAN_BYPASS_DPD
;
1310 else if ((chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
) &&
1311 chandef
->chan
->dfs_state
!= NL80211_DFS_AVAILABLE
)
1312 req
.switch_reason
= CH_SWITCH_DFS
;
1314 req
.switch_reason
= CH_SWITCH_NORMAL
;
1316 switch (dev
->mt76
.chandef
.width
) {
1317 case NL80211_CHAN_WIDTH_40
:
1318 req
.bw
= CMD_CBW_40MHZ
;
1320 case NL80211_CHAN_WIDTH_80
:
1321 req
.bw
= CMD_CBW_80MHZ
;
1323 case NL80211_CHAN_WIDTH_80P80
:
1324 req
.bw
= CMD_CBW_8080MHZ
;
1326 case NL80211_CHAN_WIDTH_160
:
1327 req
.bw
= CMD_CBW_160MHZ
;
1329 case NL80211_CHAN_WIDTH_5
:
1330 req
.bw
= CMD_CBW_5MHZ
;
1332 case NL80211_CHAN_WIDTH_10
:
1333 req
.bw
= CMD_CBW_10MHZ
;
1335 case NL80211_CHAN_WIDTH_20_NOHT
:
1336 case NL80211_CHAN_WIDTH_20
:
1338 req
.bw
= CMD_CBW_20MHZ
;
1341 memset(req
.txpower_sku
, 0x3f, 49);
1343 ret
= __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_CHANNEL_SWITCH
,
1344 &req
, sizeof(req
), true);
1348 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_SET_RX_PATH
,
1349 &req
, sizeof(req
), true);
1352 int mt7615_mcu_set_ht_cap(struct mt7615_dev
*dev
, struct ieee80211_vif
*vif
,
1353 struct ieee80211_sta
*sta
)
1355 struct mt7615_sta
*msta
= (struct mt7615_sta
*)sta
->drv_priv
;
1356 struct mt7615_vif
*mvif
= (struct mt7615_vif
*)vif
->drv_priv
;
1357 struct wtbl_req_hdr
*wtbl_hdr
;
1358 struct sta_req_hdr
*sta_hdr
;
1359 struct wtbl_raw
*wtbl_raw
;
1360 struct sta_rec_ht
*sta_ht
;
1361 struct wtbl_ht
*wtbl_ht
;
1362 int buf_len
, ret
, ntlv
= 2;
1366 buf
= kzalloc(MT7615_WTBL_UPDATE_MAX_SIZE
, GFP_KERNEL
);
1370 wtbl_hdr
= (struct wtbl_req_hdr
*)buf
;
1371 wtbl_hdr
->wlan_idx
= msta
->wcid
.idx
;
1372 wtbl_hdr
->operation
= WTBL_SET
;
1373 buf_len
= sizeof(*wtbl_hdr
);
1376 wtbl_ht
= (struct wtbl_ht
*)(buf
+ buf_len
);
1377 wtbl_ht
->tag
= cpu_to_le16(WTBL_HT
);
1378 wtbl_ht
->len
= cpu_to_le16(sizeof(*wtbl_ht
));
1380 wtbl_ht
->ldpc
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_LDPC_CODING
;
1381 wtbl_ht
->af
= sta
->ht_cap
.ampdu_factor
;
1382 wtbl_ht
->mm
= sta
->ht_cap
.ampdu_density
;
1383 buf_len
+= sizeof(*wtbl_ht
);
1385 if (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
)
1386 val
|= MT_WTBL_W5_SHORT_GI_20
;
1387 if (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
)
1388 val
|= MT_WTBL_W5_SHORT_GI_40
;
1391 if (sta
->vht_cap
.vht_supported
) {
1392 struct wtbl_vht
*wtbl_vht
;
1394 wtbl_vht
= (struct wtbl_vht
*)(buf
+ buf_len
);
1395 buf_len
+= sizeof(*wtbl_vht
);
1396 wtbl_vht
->tag
= cpu_to_le16(WTBL_VHT
);
1397 wtbl_vht
->len
= cpu_to_le16(sizeof(*wtbl_vht
));
1398 wtbl_vht
->ldpc
= sta
->vht_cap
.cap
& IEEE80211_VHT_CAP_RXLDPC
;
1402 if (sta
->vht_cap
.cap
& IEEE80211_VHT_CAP_SHORT_GI_80
)
1403 val
|= MT_WTBL_W5_SHORT_GI_80
;
1404 if (sta
->vht_cap
.cap
& IEEE80211_VHT_CAP_SHORT_GI_160
)
1405 val
|= MT_WTBL_W5_SHORT_GI_160
;
1409 if (sta
->smps_mode
== IEEE80211_SMPS_DYNAMIC
) {
1410 struct wtbl_smps
*wtbl_smps
;
1412 wtbl_smps
= (struct wtbl_smps
*)(buf
+ buf_len
);
1413 buf_len
+= sizeof(*wtbl_smps
);
1414 wtbl_smps
->tag
= cpu_to_le16(WTBL_SMPS
);
1415 wtbl_smps
->len
= cpu_to_le16(sizeof(*wtbl_smps
));
1416 wtbl_smps
->smps
= 1;
1421 msk
= MT_WTBL_W5_SHORT_GI_20
| MT_WTBL_W5_SHORT_GI_40
|
1422 MT_WTBL_W5_SHORT_GI_80
| MT_WTBL_W5_SHORT_GI_160
;
1424 wtbl_raw
= (struct wtbl_raw
*)(buf
+ buf_len
);
1425 buf_len
+= sizeof(*wtbl_raw
);
1426 wtbl_raw
->tag
= cpu_to_le16(WTBL_RAW_DATA
);
1427 wtbl_raw
->len
= cpu_to_le16(sizeof(*wtbl_raw
));
1428 wtbl_raw
->wtbl_idx
= 1;
1430 wtbl_raw
->msk
= cpu_to_le32(~msk
);
1431 wtbl_raw
->val
= cpu_to_le32(val
);
1433 wtbl_hdr
->tlv_num
= cpu_to_le16(ntlv
);
1434 ret
= __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_WTBL_UPDATE
,
1435 buf
, buf_len
, true);
1439 memset(buf
, 0, MT7615_WTBL_UPDATE_MAX_SIZE
);
1441 sta_hdr
= (struct sta_req_hdr
*)buf
;
1442 sta_hdr
->bss_idx
= mvif
->idx
;
1443 sta_hdr
->wlan_idx
= msta
->wcid
.idx
;
1444 sta_hdr
->is_tlv_append
= 1;
1445 ntlv
= sta
->vht_cap
.vht_supported
? 2 : 1;
1446 sta_hdr
->tlv_num
= cpu_to_le16(ntlv
);
1447 sta_hdr
->muar_idx
= mvif
->omac_idx
;
1448 buf_len
= sizeof(*sta_hdr
);
1450 sta_ht
= (struct sta_rec_ht
*)(buf
+ buf_len
);
1451 sta_ht
->tag
= cpu_to_le16(STA_REC_HT
);
1452 sta_ht
->len
= cpu_to_le16(sizeof(*sta_ht
));
1453 sta_ht
->ht_cap
= cpu_to_le16(sta
->ht_cap
.cap
);
1454 buf_len
+= sizeof(*sta_ht
);
1456 if (sta
->vht_cap
.vht_supported
) {
1457 struct sta_rec_vht
*sta_vht
;
1459 sta_vht
= (struct sta_rec_vht
*)(buf
+ buf_len
);
1460 buf_len
+= sizeof(*sta_vht
);
1461 sta_vht
->tag
= cpu_to_le16(STA_REC_VHT
);
1462 sta_vht
->len
= cpu_to_le16(sizeof(*sta_vht
));
1463 sta_vht
->vht_cap
= cpu_to_le32(sta
->vht_cap
.cap
);
1464 sta_vht
->vht_rx_mcs_map
= sta
->vht_cap
.vht_mcs
.rx_mcs_map
;
1465 sta_vht
->vht_tx_mcs_map
= sta
->vht_cap
.vht_mcs
.tx_mcs_map
;
1468 ret
= __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_STA_REC_UPDATE
,
1469 buf
, buf_len
, true);
1476 int mt7615_mcu_set_tx_ba(struct mt7615_dev
*dev
,
1477 struct ieee80211_ampdu_params
*params
,
1480 struct mt7615_sta
*msta
= (struct mt7615_sta
*)params
->sta
->drv_priv
;
1481 struct mt7615_vif
*mvif
= msta
->vif
;
1483 struct wtbl_req_hdr hdr
;
1487 .wlan_idx
= msta
->wcid
.idx
,
1488 .operation
= WTBL_SET
,
1489 .tlv_num
= cpu_to_le16(1),
1492 .tag
= cpu_to_le16(WTBL_BA
),
1493 .len
= cpu_to_le16(sizeof(struct wtbl_ba
)),
1495 .ba_type
= MT_BA_TYPE_ORIGINATOR
,
1496 .sn
= add
? cpu_to_le16(params
->ssn
) : 0,
1501 struct sta_req_hdr hdr
;
1502 struct sta_rec_ba ba
;
1505 .bss_idx
= mvif
->idx
,
1506 .wlan_idx
= msta
->wcid
.idx
,
1507 .tlv_num
= cpu_to_le16(1),
1509 .muar_idx
= mvif
->omac_idx
,
1512 .tag
= cpu_to_le16(STA_REC_BA
),
1513 .len
= cpu_to_le16(sizeof(struct sta_rec_ba
)),
1515 .ba_type
= MT_BA_TYPE_ORIGINATOR
,
1516 .amsdu
= params
->amsdu
,
1517 .ba_en
= add
<< params
->tid
,
1518 .ssn
= cpu_to_le16(params
->ssn
),
1519 .winsize
= cpu_to_le16(params
->buf_size
),
1525 u8 idx
, ba_range
[] = { 4, 8, 12, 24, 36, 48, 54, 64 };
1527 for (idx
= 7; idx
> 0; idx
--) {
1528 if (params
->buf_size
>= ba_range
[idx
])
1532 wtbl_req
.ba
.ba_winsize_idx
= idx
;
1535 ret
= __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_WTBL_UPDATE
,
1536 &wtbl_req
, sizeof(wtbl_req
), true);
1540 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_STA_REC_UPDATE
,
1541 &sta_req
, sizeof(sta_req
), true);
1544 int mt7615_mcu_set_rx_ba(struct mt7615_dev
*dev
,
1545 struct ieee80211_ampdu_params
*params
,
1548 struct mt7615_sta
*msta
= (struct mt7615_sta
*)params
->sta
->drv_priv
;
1549 struct mt7615_vif
*mvif
= msta
->vif
;
1551 struct wtbl_req_hdr hdr
;
1555 .wlan_idx
= msta
->wcid
.idx
,
1556 .operation
= WTBL_SET
,
1557 .tlv_num
= cpu_to_le16(1),
1560 .tag
= cpu_to_le16(WTBL_BA
),
1561 .len
= cpu_to_le16(sizeof(struct wtbl_ba
)),
1563 .ba_type
= MT_BA_TYPE_RECIPIENT
,
1564 .rst_ba_tid
= params
->tid
,
1565 .rst_ba_sel
= RST_BA_MAC_TID_MATCH
,
1570 struct sta_req_hdr hdr
;
1571 struct sta_rec_ba ba
;
1574 .bss_idx
= mvif
->idx
,
1575 .wlan_idx
= msta
->wcid
.idx
,
1576 .tlv_num
= cpu_to_le16(1),
1578 .muar_idx
= mvif
->omac_idx
,
1581 .tag
= cpu_to_le16(STA_REC_BA
),
1582 .len
= cpu_to_le16(sizeof(struct sta_rec_ba
)),
1584 .ba_type
= MT_BA_TYPE_RECIPIENT
,
1585 .amsdu
= params
->amsdu
,
1586 .ba_en
= add
<< params
->tid
,
1587 .ssn
= cpu_to_le16(params
->ssn
),
1588 .winsize
= cpu_to_le16(params
->buf_size
),
1593 memcpy(wtbl_req
.ba
.peer_addr
, params
->sta
->addr
, ETH_ALEN
);
1595 ret
= __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_STA_REC_UPDATE
,
1596 &sta_req
, sizeof(sta_req
), true);
1600 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_WTBL_UPDATE
,
1601 &wtbl_req
, sizeof(wtbl_req
), true);
1604 int mt7615_mcu_get_temperature(struct mt7615_dev
*dev
, int index
)
1613 return __mt76_mcu_send_msg(&dev
->mt76
, MCU_EXT_CMD_GET_TEMP
, &req
,