VSF Documented
vsf_wifi_mt76.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_WIFI_MT76_H__
19#define __VSF_WIFI_MT76_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "../../vsf_wifi_cfg.h"
24
25#if VSF_USE_WIFI == ENABLED && VSF_WIFI_USE_MT76 == ENABLED
26
27#include "../../vsf_wifi.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/*============================ MACROS ========================================*/
34
35#define MT76_RX_URB_SIZE 2048
36#define MT76_TX_URB_SIZE 4096
37#define MT76_MCU_RESP_SIZE 2048
38
39#define MT76_EEPROM_SIZE 512
40
41/* USB endpoint indices shared between the chip driver and the USB bus driver. */
42#define MT76_EP_IN_CMD_RESP 1
43
44/* EFUSE control registers */
45#define MT_EFUSE_CTRL 0x0024
46#define MT_EFUSE_CTRL_AOUT 0x0000003F
47#define MT_EFUSE_CTRL_MODE 0x000000C0
48#define MT_EFUSE_CTRL_AIN 0x03FF0000
49#define MT_EFUSE_CTRL_KICK 0x40000000
50#define MT_EFUSE_CTRL_SEL 0x80000000
51
52#define MT_EFUSE_DATA_BASE 0x0028
53#define MT_EFUSE_DATA(_n) (MT_EFUSE_DATA_BASE + ((_n) << 2))
54
55/* MAC address / BSSID registers */
56#define MT_MAC_ADDR_DW0 0x1008
57#define MT_MAC_ADDR_DW1 0x100c
58#define MT_MAC_ADDR_DW1_U2ME_MASK 0x00FF0000
59
60#define MT_MAC_BSSID_DW0 0x1010
61#define MT_MAC_BSSID_DW1 0x1014
62#define MT_MAC_BSSID_DW1_ADDR 0x0000FFFF
63#define MT_MAC_BSSID_DW1_MBSS_MODE 0x00030000
64#define MT_MAC_BSSID_DW1_MBSS_LOCAL_BIT 0x00040000
65#define MT_MAC_BSSID_DW1_MBEACON_N 0x001C0000
66#define MT_MAC_BSSID_DW1_MBEACON_N_SHIFT 18
67
68/* APC BSSID registers: one 64-bit entry per BSS (low 32 + high 16). */
69#define MT_MAC_APC_BSSID_BASE 0x1090
70#define MT_MAC_APC_BSSID_L(_n) (MT_MAC_APC_BSSID_BASE + ((_n) * 8))
71#define MT_MAC_APC_BSSID_H(_n) (MT_MAC_APC_BSSID_BASE + ((_n) * 8 + 4))
72#define MT_MAC_APC_BSSID_H_ADDR 0x0000FFFF
73
74/*============================ TYPES =========================================*/
75
76/* MT76 bus operations.
77 *
78 * MT76 is a register-based chip (extensive cfg_read/cfg_write) plus chip-
79 * specific primitives for FCE writes, device commands, MCU command frames,
80 * TX frame submission and RX URB arming. The first member MUST be
81 * vsf_wifi_reg_bus_t so the generic wifi layer can treat the structure as a
82 * standard register bus; chip-private operations follow the shared part.
83 *
84 * On USB the bus driver maps reg_read/reg_write to ep0 vendor requests and
85 * the private ops to bulk URBs / ep0 control transfers; on other buses (e.g.
86 * SDIO) the same chip driver would use a different bus_ops implementation
87 * that maps to the appropriate host/controller primitives. */
89 /* Generic register-bus interface. reg_read/reg_write are used for the
90 * many 32-bit configuration/register accesses that MT76 performs. */
92
93 /* Write an FCE (Forward Control Engine) DMA register. Used during
94 * firmware upload to set the destination address/length before sending
95 * the firmware payload as an MCU command frame. */
97 uint32_t addr, uint32_t val, vsf_wifi_done_t done);
98
99 /* Issue a device-mode control command (reset, IVB load).
100 * On USB this is an ep0 vendor request. */
102 uint8_t req, uint16_t value, uint16_t index, vsf_wifi_done_t done);
103
104 /* Issue a device-mode class request (patch enable / WMT reset).
105 * On USB this is an ep0 class request with a small data stage. */
107 uint8_t req, uint16_t value, uint16_t index,
108 const uint8_t *data, uint16_t len, vsf_wifi_done_t done);
109
110 /* Send an MCU command frame. On USB this is a bulk OUT transfer on the
111 * INBAND_CMD endpoint. The buffer already contains the TXINFO + CMD
112 * header + payload layout required by the chip. Completion is signalled
113 * when the bulk OUT URB finishes (the caller separately waits for the
114 * CMD_RESP via rx_submit). */
116 const uint8_t *data, uint16_t len, vsf_wifi_done_t done);
117
118 /* Submit a TX 802.11 frame. On USB this is a bulk OUT transfer on one of
119 * the AC endpoints. The buffer already contains TXINFO + TXWI + frame. */
121 const uint8_t *data, uint16_t len, uint8_t queue_idx, vsf_wifi_done_t done);
122
123 /* Start / re-arm a single RX reception. On USB this is a bulk IN URB. */
125 uint8_t *buf, uint16_t len, uint8_t queue_idx);
127
128typedef struct mt76_wifi_priv {
130 void *bus_priv;
131
132 /* RX data/event delivery callback registered by the chip driver. The bus
133 * driver invokes this for every completed bulk IN URB. */
134 void (*on_rx)(vsf_wifi_t *wifi, uint8_t *buf, uint16_t len);
135
136 /* RX packet callback for beacon/probe response frames received on the
137 * packet RX endpoint during scanning. */
139
143
144 /* Hardware capability: chainmask from EEPROM (rx = low nibble, tx = high nibble).
145 * MT7612U is 2T2R -> 0x0202. */
147 /* Cached RX filter value; updated after MAC reset and during scan. */
149
150 /* RX path gain state, read from EEPROM and programmed via CMD_INIT_GAIN_OP
151 * after every channel switch (mirrors Linux mt76x2_read_rx_gain). */
157
158 /* One-time RF calibration flags, matching Linux mt76x2u init. */
160
163
164 /* MCU command response matching.
165 * Some firmware commands (LOAD_CR, SWITCH_CHANNEL_OP) require the host
166 * to drain the CMD_RESP endpoint and wait for EVT_CMD_DONE before the
167 * next command can be issued. */
171
172 /* EEPROM loading context */
178
179 /* async operation context */
182
183 /* firmware upload context */
203
204 /* MAC address programming context */
207
208 /* Hardware init context (mt76x2u_init_hardware steps) */
214
215 /* set_channel context */
218 uint8_t set_channel_bw; /* WIFI_BW_xxx hint */
222 uint8_t set_channel_state; /* top-level state */
223 uint8_t set_channel_substate; /* mac_stop sub-state */
224 uint8_t set_channel_bbp_substate; /* BBP bw sub-state */
225 uint8_t set_channel_post_substate; /* post-switch cal/regs */
227 vsf_wifi_done_t set_channel_done; /* original caller callback */
228 uint8_t last_channel; /* last tuned channel */
229
230 /* connect context */
232
233 /* disconnect context */
235
236 /* hardware crypto install context */
238 /* Multicast/broadcast software-CCMP PN. MT76 firmware overrides the QoS
239 * Control Ack Policy of WIV=0 broadcast frames, so multicast data is
240 * software-encrypted locally using this counter while unicast data uses
241 * the hardware WCID PN. Little-endian, mcast_pn[0] = LSB. */
243#if VSF_KERNEL_CFG_SUPPORT_CALLBACK_TIMER == ENABLED
245 /* one-shot TX status poll for debugging handshake ACK failures */
249#endif
250
251 /* Rate control state: index into __mt76_rate_table, consecutive ACK
252 * counter, and the rate value last programmed into WCID 1 TX info. */
256
257 /* Last received RSSI (from rxwi[12], i.e. rssi[0]). -128 means "not
258 * received yet"; updated for every successfully parsed MPDU. */
260
261 /* Per-interface 802.11 TX sequence number. Previously a file-level
262 * static, which would collide if multiple VIFs/interfaces share this
263 * driver. The lower 4 bits are the fragment number and stay zero. */
265
266 /* buffers */
271
272/*============================ LOGGING HELPERS ===============================*/
273
274#if VSF_WIFI_CFG_CHIP_MT76_LOG_LEVEL >= 1
275# define vsf_wifi_chip_mt76_trace_error(...) vsf_trace_error(__VA_ARGS__)
276#else
277# define vsf_wifi_chip_mt76_trace_error(...) ((void)0)
278#endif
279
280#if VSF_WIFI_CFG_CHIP_MT76_LOG_LEVEL >= 2
281# define vsf_wifi_chip_mt76_trace_info(...) vsf_trace_info(__VA_ARGS__)
282#else
283# define vsf_wifi_chip_mt76_trace_info(...) ((void)0)
284#endif
285
286#if VSF_WIFI_CFG_CHIP_MT76_LOG_LEVEL >= 4
287# define vsf_wifi_chip_mt76_trace_debug(...) vsf_trace_info(__VA_ARGS__)
288#else
289# define vsf_wifi_chip_mt76_trace_debug(...) ((void)0)
290#endif
291
292/*============================ GLOBAL VARIABLES ==============================*/
293
295
296/*============================ PROTOTYPES ====================================*/
297
302
303#ifdef __cplusplus
304}
305#endif
306
307#endif /* VSF_USE_WIFI == ENABLED && VSF_WIFI_USE_MT76 == ENABLED */
308#endif /* __VSF_WIFI_MT76_H__ */
vsf_err_t
Definition __type.h:42
Definition vsf_eda.h:851
struct ieee80211_ext_chansw_ie data
Definition ieee80211.h:80
unsigned short uint16_t
Definition stdint.h:7
unsigned uint32_t
Definition stdint.h:9
unsigned char uint8_t
Definition stdint.h:5
signed char int8_t
Definition stdint.h:4
Definition vsf_wifi_mt76.h:128
vsf_wifi_done_t disconnect_done
Definition vsf_wifi_mt76.h:234
uint8_t state
Definition vsf_wifi_mt76.h:162
uint8_t set_channel_ch_group
Definition vsf_wifi_mt76.h:220
uint32_t fw_poll_mask
Definition vsf_wifi_mt76.h:198
uint32_t fw_patch_mask
Definition vsf_wifi_mt76.h:197
uint8_t set_channel_bw_index
Definition vsf_wifi_mt76.h:219
uint8_t set_channel_substate
Definition vsf_wifi_mt76.h:223
uint8_t rx_buf[MT76_RX_URB_SIZE]
Definition vsf_wifi_mt76.h:267
uint8_t eeprom[MT76_EEPROM_SIZE]
Definition vsf_wifi_mt76.h:142
uint32_t rxfilter
Definition vsf_wifi_mt76.h:148
uint8_t mcu_wait_seq
Definition vsf_wifi_mt76.h:169
uint8_t fw_send_next_state
Definition vsf_wifi_mt76.h:187
uint32_t eeprom_data[4]
Definition vsf_wifi_mt76.h:176
uint16_t pending_cmd
Definition vsf_wifi_mt76.h:181
uint8_t set_channel_post_substate
Definition vsf_wifi_mt76.h:225
bool init_cal_done
Definition vsf_wifi_mt76.h:159
void * bus_priv
Definition vsf_wifi_mt76.h:130
uint8_t mcast_pn[6]
Definition vsf_wifi_mt76.h:242
uint8_t eeprom_step
Definition vsf_wifi_mt76.h:174
uint8_t set_channel_scan
Definition vsf_wifi_mt76.h:217
int8_t rx_rssi_offset[2]
Definition vsf_wifi_mt76.h:155
void(* on_rx)(vsf_wifi_t *wifi, uint8_t *buf, uint16_t len)
Definition vsf_wifi_mt76.h:134
uint8_t xtal_step
Definition vsf_wifi_mt76.h:212
int8_t rx_high_gain[2]
Definition vsf_wifi_mt76.h:154
uint32_t fw_idx
Definition vsf_wifi_mt76.h:188
uint16_t tx_rate_val
Definition vsf_wifi_mt76.h:255
uint8_t fw_rf_step
Definition vsf_wifi_mt76.h:202
uint32_t fw_max_payload
Definition vsf_wifi_mt76.h:195
uint32_t fw_dst_offset
Definition vsf_wifi_mt76.h:194
vsf_wifi_done_t mcu_wait_done
Definition vsf_wifi_mt76.h:170
uint32_t fw_dlm_len
Definition vsf_wifi_mt76.h:190
uint32_t fw_len
Definition vsf_wifi_mt76.h:192
uint32_t fw_pos
Definition vsf_wifi_mt76.h:193
uint8_t init_substate
Definition vsf_wifi_mt76.h:211
uint32_t txstat_ext_val
Definition vsf_wifi_mt76.h:248
uint8_t tx_rate_success_cnt
Definition vsf_wifi_mt76.h:254
uint32_t asic_rev
Definition vsf_wifi_mt76.h:140
vsf_wifi_done_t set_channel_done
Definition vsf_wifi_mt76.h:227
uint16_t init_idx2
Definition vsf_wifi_mt76.h:210
uint8_t set_channel_bw
Definition vsf_wifi_mt76.h:218
vsf_wifi_done_t eeprom_done
Definition vsf_wifi_mt76.h:177
vsf_callback_timer_t fw_timer
Definition vsf_wifi_mt76.h:244
uint8_t set_channel_channel
Definition vsf_wifi_mt76.h:216
vsf_wifi_done_t pending_done
Definition vsf_wifi_mt76.h:180
uint8_t fw_stage
Definition vsf_wifi_mt76.h:185
uint32_t fw_patch_reg
Definition vsf_wifi_mt76.h:196
bool set_channel_is_5g
Definition vsf_wifi_mt76.h:221
uint8_t mac_addr_step
Definition vsf_wifi_mt76.h:205
uint16_t fw_sem_ms
Definition vsf_wifi_mt76.h:200
uint32_t set_channel_saved_rts
Definition vsf_wifi_mt76.h:226
uint8_t fw_rf_unit
Definition vsf_wifi_mt76.h:201
uint16_t fw_poll_ms
Definition vsf_wifi_mt76.h:199
uint16_t xtal_val
Definition vsf_wifi_mt76.h:213
bool mcu_wait_resp
Definition vsf_wifi_mt76.h:168
uint16_t init_idx
Definition vsf_wifi_mt76.h:209
uint8_t mac_addr[6]
Definition vsf_wifi_mt76.h:141
uint32_t rx_mcu_gain
Definition vsf_wifi_mt76.h:152
const uint8_t * fw_data
Definition vsf_wifi_mt76.h:191
uint8_t tx_rate_idx
Definition vsf_wifi_mt76.h:253
uint16_t chainmask
Definition vsf_wifi_mt76.h:146
uint8_t set_channel_state
Definition vsf_wifi_mt76.h:222
vsf_wifi_done_t mac_addr_done
Definition vsf_wifi_mt76.h:206
vsf_callback_timer_t txstat_timer
Definition vsf_wifi_mt76.h:246
uint8_t fw_send_state
Definition vsf_wifi_mt76.h:186
uint8_t fw_state
Definition vsf_wifi_mt76.h:184
uint32_t txstat_val
Definition vsf_wifi_mt76.h:247
int8_t rx_lna_gain
Definition vsf_wifi_mt76.h:153
uint8_t set_channel_bbp_substate
Definition vsf_wifi_mt76.h:224
uint32_t fw_ilm_len
Definition vsf_wifi_mt76.h:189
int8_t last_rssi
Definition vsf_wifi_mt76.h:259
uint8_t last_channel
Definition vsf_wifi_mt76.h:228
vsf_wifi_done_t crypto_done
Definition vsf_wifi_mt76.h:237
uint8_t mcu_seq
Definition vsf_wifi_mt76.h:161
vsf_wifi_t * wifi
Definition vsf_wifi_mt76.h:129
uint32_t eeprom_ctrl
Definition vsf_wifi_mt76.h:175
uint8_t mcu_resp_buf[MT76_MCU_RESP_SIZE]
Definition vsf_wifi_mt76.h:269
uint16_t eeprom_offset
Definition vsf_wifi_mt76.h:173
uint16_t tx_seq
Definition vsf_wifi_mt76.h:264
void(* on_rx_pkt)(vsf_wifi_t *wifi, uint8_t *buf, uint16_t len)
Definition vsf_wifi_mt76.h:138
bool rx_gain_read
Definition vsf_wifi_mt76.h:156
vsf_wifi_done_t connect_done
Definition vsf_wifi_mt76.h:231
uint8_t tx_buf[MT76_TX_URB_SIZE]
Definition vsf_wifi_mt76.h:268
Definition vsf_wifi.h:304
Definition vsf_wifi_mt76.h:88
vsf_err_t(* dev_class_cmd)(vsf_wifi_t *wifi, uint8_t req, uint16_t value, uint16_t index, const uint8_t *data, uint16_t len, vsf_wifi_done_t done)
Definition vsf_wifi_mt76.h:106
vsf_err_t(* fce_write)(vsf_wifi_t *wifi, uint32_t addr, uint32_t val, vsf_wifi_done_t done)
Definition vsf_wifi_mt76.h:96
vsf_err_t(* rx_submit)(vsf_wifi_t *wifi, uint8_t *buf, uint16_t len, uint8_t queue_idx)
Definition vsf_wifi_mt76.h:124
vsf_err_t(* tx_frame)(vsf_wifi_t *wifi, const uint8_t *data, uint16_t len, uint8_t queue_idx, vsf_wifi_done_t done)
Definition vsf_wifi_mt76.h:120
vsf_err_t(* dev_cmd)(vsf_wifi_t *wifi, uint8_t req, uint16_t value, uint16_t index, vsf_wifi_done_t done)
Definition vsf_wifi_mt76.h:101
vsf_wifi_reg_bus_t base
Definition vsf_wifi_mt76.h:91
vsf_err_t(* mcu_cmd)(vsf_wifi_t *wifi, const uint8_t *data, uint16_t len, vsf_wifi_done_t done)
Definition vsf_wifi_mt76.h:115
Definition vsf_wifi.h:214
Definition vsf_wifi_priv.h:57
vk_av_control_value_t value
Definition vsf_audio.h:171
void(* vsf_wifi_done_t)(vsf_wifi_t *wifi, vsf_err_t err)
Definition vsf_wifi.h:123
struct vsf_wifi_mt76_bus_ops_t vsf_wifi_mt76_bus_ops_t
const vsf_wifi_chip_drv_t vsf_wifi_mt76_drv
Definition vsf_wifi_mt76.c:5920
const uint32_t __mt76_main_firmware_size
Definition vsf_wifi_mt76_firmware_data.c:6803
#define MT76_TX_URB_SIZE
Definition vsf_wifi_mt76.h:36
const uint32_t __mt76_rom_patch_firmware_size
Definition vsf_wifi_mt76_firmware_data.c:1673
const uint8_t __mt76_rom_patch_firmware_data[]
Definition vsf_wifi_mt76_firmware_data.c:24
#define MT76_RX_URB_SIZE
Definition vsf_wifi_mt76.h:35
#define MT76_MCU_RESP_SIZE
Definition vsf_wifi_mt76.h:37
struct mt76_wifi_priv mt76_wifi_priv_t
#define MT76_EEPROM_SIZE
Definition vsf_wifi_mt76.h:39
const uint8_t __mt76_main_firmware_data[]
Definition vsf_wifi_mt76_firmware_data.c:1677
Generated from commit: vsfteam/vsf@9e2cb73