• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: HAL Layer Specifications.
15  */
16 
17 #ifndef __HAL_OPS_COMMON_ROM_H__
18 #define __HAL_OPS_COMMON_ROM_H__
19 
20 /*****************************************************************************
21     1 头文件包含
22 *****************************************************************************/
23 #include "frw_list_rom.h"
24 #include "frw_util_common_rom.h"
25 #include "frw_ext_common_rom.h"
26 #include "oal_types_device_rom.h"
27 #include "wlan_types.h"
28 #include "wlan_types_base_rom.h"
29 #include "wlan_custom_type.h"
30 #include "oal_fsm.h"
31 #include "hal_commom_ops_type_rom.h"
32 #include "hal_common_ops_device_rom.h"
33 
34 #ifdef __cplusplus
35 #if __cplusplus
36 extern "C" {
37 #endif
38 #endif
39 
40 #define INI_SUCC                (0)
41 #define INI_FAILED              (-1)
42 
43 /*****************************************************************************
44     加密相关枚举定义
45 *****************************************************************************/
46 typedef struct {
47     hal_fcs_protect_type_enum_uint8 protect_type;
48     hal_fcs_protect_cnt_enum_uint8  protect_cnt;
49     osal_u16                          protect_coex_pri : 2;     /* btcoex下使用,one pkt发送优先级 */
50     osal_u16                          cfg_one_pkt_tx_vap_index : 4;
51     osal_u16                          cfg_one_pkt_tx_peer_index : 5;
52     osal_u16                          bit_rsv : 5;
53 
54     osal_u32                          tx_mode;
55     osal_u32                          tx_data_rate;
56     osal_u16                          duration;    /* 单位 us */
57     osal_u16                          timeout;
58 
59     osal_u16                          wait_timeout;     /* 软件定时器超时时间 */
60     osal_u8                           rsv[2];      /* 保留2字节对齐 */
61     osal_u8                             protect_frame[24]; // 24 mac_vap_ext hmac_only
62 } hal_one_packet_cfg_stru;
63 
64 typedef struct {
65     hal_fcs_protect_type_enum_uint8 protect_type;
66     osal_u8 vap_id;    /* hal vap id */
67     osal_u8 status;    /* 0:成功 1:接收响应帧失败 2:接收响应帧超时 3:异常结束 */
68     osal_u8 timeout;   /* 最后一次是否发送超时 */
69     osal_u8 tx_cnt;    /* 发送次数 */
70     osal_u8 resv;
71     osal_u16 tx_time;  /* 硬件发送时间 */
72 } hal_one_packet_debug_stru;
73 
74 /*****************************************************************************
75   结构名  : hmac_tx_dscr_queue_header_stru
76   结构说明: 发送描述符队列头的结构体
77 *****************************************************************************/
78 typedef struct {
79     struct osal_list_head                     header;          /* 发送描述符队列头结点 */
80     hal_dscr_queue_status_enum_uint8        queue_status;    /* 发送描述符队列状态 */
81     osal_u8                               ppdu_cnt;     /* 发送描述符队列中元素的个数 */
82     osal_u8                               mpdu_cnt;     /* 发送描述符队列中mpdu总数,聚合场景,多个mpdu组成一个ppdu */
83     osal_u8                               auc_resv[1];   /* 保留2字节对齐 */
84 #ifdef _PRE_WLAN_DFR_STAT
85     osal_u32                              enqueue_total_cnt;   /* 统计周期内入队的数量 */
86 #endif
87 } hal_tx_dscr_queue_header_stru;
88 /*****************************************************************************/
89 /*****************************************************************************/
90 /*                        hh503 产品宏定义、枚举                            */
91 /*****************************************************************************/
92 /*****************************************************************************/
93 /*****************************************************************************
94     2 宏定义
95 *****************************************************************************/
96 #define hal_public_hook_func(_func)     hh503##_func
97 
98 #define HAL_COEX_SW_IRQ_BT BIT0
99 /*****************************************************************************
100   3 枚举
101 *****************************************************************************/
102 /* 算法描述符中RTS开关枚举 */
103 typedef enum {
104     WLAN_PROTECT_MODE_NONE = 0,
105     WLAN_PROTECT_MODE_RTS_CTS = 1,
106     WLAN_PROTECT_MODE_SELF_CTS = 2,
107     WLAN_PROTECT_MODE_BUTT
108 } wlan_protect_mode_enum;
109 typedef osal_u8 wlan_protect_mode_enum_uint8;
110 
111 /*****************************************************************************/
112 /*                        公共宏定义、枚举、结构体                            */
113 /*****************************************************************************/
114 #define hal_pow_lpf_base_idx(_en_band)      (((_en_band) == WLAN_BAND_2G) ? HAL_POW_2G_LPF_BASE_IDX : \
115     HAL_POW_5G_LPF_BASE_IDX)  /* 基准LPF Index */
116 #define hal_pow_dac_base_idx(_en_band)      (((_en_band) == WLAN_BAND_2G) ? HAL_POW_2G_DAC_BASE_IDX : \
117     HAL_POW_5G_DAC_BASE_IDX)  /* 基准DAC Index */
118 
119 /* Bit[22:22]: DPD enable; Bit[21:12]: delt dbb scaling; Bit[11:10]: DAC gain; Bit[9:8]: PA;
120    Bit[7:5]: LPF gain ; Bit[4:4]: UPC gain ; Bit[3:2]: CFR index; Bit[1:0]: dpd_tpc_lv */
121 #define hal_pow_code_comb(_en_dpd_enable, _uc_upc_idx, _uc_pa_idx, _uc_dac_idx, _uc_lpf_idx, \
122     _uc_delta_dbb_scaling, _uc_dpd_tpc_lv, _uc_cfr_index) \
123     ((((osal_u32)(_uc_dpd_tpc_lv) & 0x3) | (((osal_u32)(_uc_cfr_index) & 0x3) << 2) | \
124       (((osal_u32)(_uc_upc_idx) & 0x1) << 4) | (((osal_u32)(_uc_lpf_idx) & 0x7) << 5) | \
125       (((osal_u32)(_uc_pa_idx) & 0x3) << 8) | (((osal_u32)(_uc_dac_idx) & 0x3) << 10) | \
126       (((osal_u32)(_uc_delta_dbb_scaling) & 0x3ff) << 12) | (((osal_u32)(_en_dpd_enable) & 0x1) << 22)) & 0x7fffff)
127 
128 #define hal_ini_pow_code(_en_band)    (hal_pow_code_comb(OSAL_TRUE, HAL_POW_UPC_LOW_START_IDX, HAL_POW_PA_BASE_IDX, \
129     hal_pow_dac_base_idx(_en_band), hal_pow_lpf_base_idx(_en_band), HAL_POW_DELTA_DBB_SCAL_BASE_IDX, \
130     HAL_POW_DPD_TPC_BASE_IDX, HAL_POW_CFR_BASE_IDX))
131 
132 #define hal_pow_fill_tx_four_same_code(_uc_code)    \
133     ((((osal_u32)(_uc_code)) << 24) | (((osal_u32)(_uc_code)) << 16) | \
134      (((osal_u32)(_uc_code)) << 8) | ((osal_u32)(_uc_code)))
135 
136 #define hal_pow_fill_upc_data_reg(_uc_data1, _uc_data2, _uc_data3, _uc_data4)    \
137     (((osal_u32)((_uc_data1)<<(osal_u32)24)) | ((osal_u32)((_uc_data2)<<(osal_u32)16)) | \
138     ((osal_u32)(_uc_data3)<<(osal_u32)8) | (_uc_data4))
139 
140 #define hal_abs(_a)  (((_a) > 0) ? (_a) : (-(_a)))
141 
142 #define hal_pow_find_near_idx(_uc_data1, _uc_data2, _uc_idx1, _uc_idx2, _uc_input)    \
143     ((hal_abs((_uc_data1) - (_uc_input))) > (hal_abs((_uc_data2)-(_uc_input))) ? (_uc_idx2) : (_uc_idx1))
144 
145 #define get_rssi_min(_c_rssi_ant0, _c_rssi_ant1)  \
146     (((_c_rssi_ant0) == OAL_RSSI_INIT_VALUE) ? (_c_rssi_ant1) : \
147      ((_c_rssi_ant1) == OAL_RSSI_INIT_VALUE) ? (_c_rssi_ant0) : \
148      osal_min((_c_rssi_ant0), (_c_rssi_ant1)))
149 
150 #define get_rssi(_c_rssi_dbm, _c_rssi_ant0, _c_rssi_ant1) get_rssi_min(_c_rssi_ant0, _c_rssi_ant1)
151 
152 /* hal device下挂接收描述符控制相关宏定义 */
153 #define get_dev_rx_dscr_q_empty(_pst_hal_dev, _uc_queue_id) \
154     (((alg_rx_dscr_ctl_alg_info_stru *)((_pst_hal_dev)->rx_dscr_ctl.rx_dscr_ctl_alg_info + \
155     (_uc_queue_id)))->rx_dscr_q_empty)
156 #define get_dev_rx_dscr_max_used_cnt(_pst_hal_dev, _uc_queue_id) \
157     (((alg_rx_dscr_ctl_alg_info_stru *)((_pst_hal_dev)->rx_dscr_ctl.rx_dscr_ctl_alg_info + \
158     (_uc_queue_id)))->rx_max_dscr_used_cnt)
159 #define get_dev_rx_dscr_event_cnt(_pst_hal_dev, _uc_queue_id)    \
160     (((alg_rx_dscr_ctl_alg_info_stru *)((_pst_hal_dev)->rx_dscr_ctl.rx_dscr_ctl_alg_info + \
161     (_uc_queue_id)))->rx_event_cnt)
162 #define get_dev_rx_dscr_event_pkts(_pst_hal_dev, _uc_queue_id)   \
163     (((alg_rx_dscr_ctl_alg_info_stru *)((_pst_hal_dev)->rx_dscr_ctl.rx_dscr_ctl_alg_info + \
164     (_uc_queue_id)))->rx_event_pkts_sum)
165 #define get_dev_rx_dscr_avrage_pkts(_pst_hal_dev, _uc_queue_id)  \
166     ((get_dev_rx_dscr_event_pkts(_pst_hal_dev, _uc_queue_id)) / (get_dev_rx_dscr_event_cnt(_pst_hal_dev, _uc_queue_id)))
167 #define get_dev_rx_dscr_avrg_pkts(_pst_hal_dev, _uc_queue_id)    \
168     ((get_dev_rx_dscr_event_cnt(_pst_hal_dev, _uc_queue_id) == 0) ? 0 : \
169     (get_dev_rx_dscr_avrage_pkts(_pst_hal_dev, _uc_queue_id)))
170 #define get_dev_rx_dscr_smooth_dscr_pkts(_pst_hal_dev, _uc_queue_id) \
171     (((alg_rx_dscr_ctl_alg_info_stru *)((_pst_hal_dev)->rx_dscr_ctl.rx_dscr_ctl_alg_info + \
172     (_uc_queue_id)))->rx_dscr_smooth_event_pkts)
173 #define get_dev_rx_dscr_smooth_avr_dscr(_pst_hal_dev, _uc_queue_id) \
174     (((alg_rx_dscr_ctl_alg_info_stru *)((_pst_hal_dev)->rx_dscr_ctl.rx_dscr_ctl_alg_info + \
175     (_uc_queue_id)))->rx_dscr_smooth_avr_dscr)
176 
177 #define get_dev_max(_us_ualue, _us_thres)        \
178     ((_us_ualue) = ((_us_ualue) < (_us_thres)) ? (_us_thres) : (_us_ualue))
179 
180 #define get_dev_rx_dscr_reset_static(_pst_hal_dev, _uc_queue_id) \
181     do { \
182         get_dev_rx_dscr_max_used_cnt(_pst_hal_dev, _uc_queue_id) = 0; \
183         get_dev_rx_dscr_event_cnt(_pst_hal_dev, _uc_queue_id) = 0; \
184         get_dev_rx_dscr_event_pkts(_pst_hal_dev, _uc_queue_id) = 0; \
185     } while (0)
186 #define get_dev_rx_dscr_reset_smooth(_pst_hal_dev, _uc_queue_id) \
187     do { \
188         get_dev_rx_dscr_smooth_avr_dscr(_pst_hal_dev, _uc_queue_id) = 0; \
189         get_dev_rx_dscr_smooth_dscr_pkts(_pst_hal_dev, _uc_queue_id) = 0; \
190     } while (0)
191 /* 获取tpc档位对应的目标功率增益 */
192 #define hal_dev_get_idx_target_pow_gain(_pst_hal_dev, _uc_pow_idx, _en_freq_band) \
193     (((hal_to_dmac_device_stru *)(_pst_hal_dev))->tx_pwr_ctrl.tpc_lvl_vs_gain_ctrl->as_pow_level_table[(_uc_pow_idx)] \
194         [(_en_freq_band)])
195 
196 #define ops_min(a, b)           (((a) < (b)) ? (a) : (b))
197 
198 /* 计算PAPA=5.5时,对应的功率补偿值 单位0.1dBm */
199 /* 根据实验室测试数据,一次拟合得到计算功率偏差公式0.25+0.03*delt_power,推导对应6
200     M&MCS0有如下功率补偿值计算公式,小于-0.5dB时不需要补偿 */
201 #define hal_dev_cfr_get_compsen_by_deltpow(_c_delt_pow) ((osal_u8)(((_c_delt_pow) < -5) ? 0 : \
202     (((3*(_c_delt_pow) + 25) + 5) / 10)))
203 
204 
205 /* 检查是否为11b 1M速率 */
206 #define hal_phy_11b_1m_rate(_a, _b)  (((_a) == WLAN_11B_PHY_PROTOCOL_MODE) && ((_b) == 0))
207 
208 #ifdef _PRE_WLAN_FEATURE_NEGTIVE_DET
209 /* 干扰检测模块PK模式探测阶段枚举 */
210 typedef enum {
211     HAL_ALG_INTF_PKADJ_STAGE_INIT      = 0,     /* 用于统计跑流的初始干扰 */
212     HAL_ALG_INTF_PKADJ_STAGE_TXOP      = 1,
213     HAL_ALG_INTF_PKADJ_STAGE_AIFSN     = 2,
214     HAL_ALG_INTF_PKADJ_STAGE_CW        = 3,
215 
216     HAL_ALG_INTF_PK_STAGE_BUTT
217 } hal_alg_intf_pk_stage_enum;
218 typedef osal_u8 hal_alg_pk_intf_stage_enum_uint8;
219 #endif
220 
221 /*****************************************************************************
222     7.1 基准发送描述符定义
223 *****************************************************************************/
224 typedef struct tag_hal_tx_dscr_stru {
225     struct osal_list_head                 entry;
226     osal_void                         *skb_start_addr;         /* Sub MSDU 0 Skb Address */
227     osal_u16                          original_mpdu_len;       /* mpdu长度 含帧头 */
228     hal_tx_queue_type_enum_uint8        q_num;                   /* 发送队列队列号 */
229     osal_u8                           is_retried         : 1; /* 是不是重传包 */
230     osal_u8                           is_ampdu           : 1; /* 是不是ampdu */
231     osal_u8                           is_rifs            : 1; /* 是不是rifs发送 */
232     osal_u8                           is_first           : 1; /* 标志是否是第一个描述符 */
233     osal_u8                           tid                : 4; /* tid队列 */
234     osal_u8                           data[0];
235 } hal_tx_dscr_stru;
236 
237 /*****************************************************************************
238   7.2 基准接收描述符定义
239 *****************************************************************************/
240 typedef struct tag_hal_rx_dscr_stru {
241     struct osal_list_head         entry;
242     osal_void                 *skb_start_addr;          /* 描述符中保存的netbuf的首地址 */
243     osal_u8                   data[0];
244 } hal_rx_dscr_stru;
245 
246 typedef struct {
247     osal_u32                              mac_hdr_start_addr;
248     osal_void                             *skb_start_addr;
249 } hal_tx_mpdu_address_params_stru;
250 
251 typedef struct {
252     /* tx dscr中算法填写的参数 */
253     hal_tx_phy_mode_one_stru           phy_info;                            /* 第13行(HY TX MODE 1) */
254     hal_tx_ctrl_desc_rate_stru           tx_dsrc[HAL_TX_RATE_MAX_NUM];  /* 第14(PHY TX RATA 1) 19 20 21 行 */
255     hal_tx_txop_tpc_stru                 tpc;                             /* 第24 25 26 27行 */
256     osal_u8                              rts_rate[HAL_TX_RATE_MAX_NUM];
257     osal_u32                             self_cts_protect : 1;
258     osal_u32                             rts_tpc_rank : 2;
259     osal_u32                             res_ : 29;
260 }hal_tx_txop_alg_stru;
261 
262 /*****************************************************************************
263   结构名  : hal_user_pow_info_stru
264   结构说明: HAL模块USER级别功率结构
265 *****************************************************************************/
266 typedef struct {
267     hal_rate_pow_code_gain_table_stru *rate_pow_table; /* EVM功率表单结构体指针 */
268     hal_tx_txop_alg_stru              *txop_param;     /* 用户速率描述符信息结构体 */
269 } hal_user_pow_info_stru;
270 
271 /* Beacon帧发送参数 */
272 typedef struct {
273     uintptr_t               pkt_ptr;  /* 64位OS上用osal_u32会导致pkt_ptr截断 用uintptr_t则不会 */
274     osal_u32                pkt_len;
275     hal_tx_txop_alg_stru   *tx_param;
276     osal_u32                tx_chain_mask;
277 } hal_beacon_tx_params_stru;
278 
279 typedef struct {
280     osal_u16 partial_aid : 9,   /* partial_aid */
281              ax_bss_color : 6,
282              txop_ps_not_allowed : 1;
283     osal_u8  tx_vap_idx : 2,
284              ra_lut_index : 3,
285              peer_ps_chk_disable : 1,
286              lsig_txop : 1,
287              obss_pd_tx_disable : 1;
288     osal_u8 retry_flag_hw_bypass : 1,
289             duration_hw_bypass : 1,
290             timestamp_hw_bypass : 1,
291             tx_pn_hw_bypass : 1,
292             tx_addba_ssn_bypass : 1,
293             long_nav_enable : 1,
294             tx_fcs_gen_err_en : 1,
295             pdet_en : 1;
296 
297     osal_u8 cipher_key_type;      /* 密钥ID/类型 */
298     osal_u8 cipher_protocol_type;
299     osal_u8 cipher_key_id;
300     osal_u8 seq_ctl_hw_bypass : 1,
301             resrv_1 : 7;
302 
303     osal_u8 ftm_protocol_mode : 4,     /* ftm */
304             ftm_bandwidth : 4;
305     osal_u8 ftm_cali_en : 1,
306             is_ftm : 2,
307             ftm_chain : 2,
308             resrv_2 : 3;
309 } hal_tx_mpdu_ctl;
310 
311 /*****************************************************************************
312   结构名  : hal_tx_mpdu_stru
313   结构说明: DMAC模块MPDU发送控制结构
314 *****************************************************************************/
315 typedef struct {
316     /* 从11MAC帧头中获取 针对MPDU */
317     hal_wmm_txop_params_stru              wmm;
318     hal_tx_mpdu_mac_hdr_params_stru       mpdu_mac_hdr;                          /* 第12 17行(PHY TX MODE 2) */
319     hal_tx_mpdu_address_params_stru       mpdu_addr;                             /* 第18行(MAC TX MODE 2) */
320     hal_tx_msdu_address_params            msdu_addr[WLAN_DSCR_SUBTABEL_MAX_NUM]; /* 第24,25...行 */
321     hal_tx_mpdu_ctl                     mpdu_ctl;
322     osal_u16                            mpdu_len;                              /* 发送帧的长度,包括head */
323     osal_u16                            resv;
324 } hal_tx_mpdu_stru;
325 
326 /*****************************************************************************
327   结构名  : hal_rx_dscr_queue_header_stru
328   结构说明: 接收描述符队列头的结构体
329 *****************************************************************************/
330 typedef struct {
331     struct osal_list_head                  header;             /* 发送描述符队列头结点 */
332     osal_u16                              element_cnt;        /* 接收描述符队列中元素的个数 */
333     hal_dscr_queue_status_enum_uint8    queue_status;       /* 接收描述符队列的状态 */
334     osal_u8                               available_cnt;      /* 当前队列中硬件可用描述符个数 */
335 } hal_rx_dscr_queue_header_stru;
336 
337 /*****************************************************************************
338     结构名  : hal_cfg_rts_tx_param_stru
339     结构说明: RTS设置发送参数
340 *****************************************************************************/
341 typedef struct {
342     wlan_legacy_rate_value_enum_uint8   rate[HAL_TX_RATE_MAX_NUM];      /* 发送速率,单位mpbs */
343 
344     /* 协议模式, 取值参见wlan_phy_protocol_enum_uint8 */
345     wlan_phy_protocol_enum_uint8        protocol_mode[HAL_TX_RATE_MAX_NUM];
346     wlan_channel_band_enum_uint8        band;
347     osal_u8                             recv[3];                        /* 保留3字节对齐 */
348 } hal_cfg_rts_tx_param_stru;
349 
350 /*****************************************************************************
351   7.7 对外部保留的设备级接口列表,建议外部不做直接调用,而是调用对应的内联函数
352 *****************************************************************************/
353 typedef osal_void (* p_hal_alg_isr_func)(osal_u8 vap_id, osal_void *p_hal_to_dmac_device);
354 typedef osal_void (* p_hal_gap_isr_func)(osal_u8 vap_id, osal_void *p_hal_to_dmac_device);
355 typedef osal_u32 (*p_tbtt_ap_isr_func)(osal_u8 mac_vap_id);
356 
357 /* 保存硬件上报接收中断信息结构 */
358 typedef struct {
359     struct osal_list_head         dlist_head;
360     osal_u32                 *base_dscr;      /* 本次中断描述符地址 */
361     osal_u16                  dscr_num;        /* 接收到的描述符的个数 */
362     osal_u8                   channel_num;     /* 本次中断时,所在的信道号 */
363     osal_u8                   queue_id;
364 } hal_hw_rx_dscr_info_stru;
365 
366 typedef struct {
367     frw_timeout_stru                 tx_prot_timer;        /* 检测无发送完成中断定时器 */
368     hal_dfr_timer_step_enum_uint8    tx_prot_timer_step;   /* 超时标志,表明第几次超时 */
369     osal_u8                          auc_resv[1];
370     osal_u16                         tx_prot_time;         /* 超时时间 */
371 } hal_dfr_tx_prot_stru;
372 
373 /*****************************************************************************
374   结构名  : hal_phy_pow_param_stru
375   结构说明: PHY 功率相关寄存器参数, 在2.4G/5G频点切换时使用
376 *****************************************************************************/
377 typedef struct {
378     /* 不同帧的tpc code */
379     osal_u32       ack_cts_pow_code[WLAN_OFDM_ACK_CTS_TYPE_BUTT][WLAN_2G_SUB_BAND_NUM + WLAN_5G_SUB_BAND_NUM];
380     osal_u32       aul_2g_dsss_ack_cts_pow_code[WLAN_2G_SUB_BAND_NUM];
381     osal_u32       rts_pow_code[WLAN_2G_SUB_BAND_NUM + WLAN_5G_SUB_BAND_NUM];
382     osal_u32       one_pkt_pow_code[WLAN_2G_SUB_BAND_NUM + WLAN_5G_SUB_BAND_NUM];
383     osal_u32       bar_pow_code[WLAN_2G_SUB_BAND_NUM + WLAN_5G_SUB_BAND_NUM];
384     osal_u32       cfend_pow_code[WLAN_2G_SUB_BAND_NUM + WLAN_5G_SUB_BAND_NUM];
385     osal_u32       vht_report_pow_code[WLAN_5G_SUB_BAND_NUM];
386     /* 读取不同帧格式的速率 */
387     osal_u8        rate_bar;
388     osal_u8        rate_rts;
389     osal_u8        rate_one_pkt;
390     osal_u8        rate_abort_selfcts;
391     osal_u8        rate_ofdm_ack_cts[WLAN_OFDM_ACK_CTS_TYPE_BUTT];
392     osal_u8        rate_cfend;
393     osal_u8        rate_vht_report;
394     osal_u8        resv_2[2];
395 } hal_phy_pow_param_stru;
396 
397 typedef struct {
398     oal_bool_enum_uint8     aen_dyn_cali_chain_comp_flag[WLAN_RF_CHANNEL_NUMS];
399     osal_u8                 tx_chain_sel;
400     osal_u8                 auc_resv[1];
401 } hal_dyn_cali_chain_status_stru;
402 typedef struct hal_dyn_cali_val {
403     osal_u16              aus_cali_en_cnt[WLAN_BAND_BUTT];
404     osal_u16              aus_cali_en_interval[WLAN_BAND_BUTT];      /* 两次动态校准间隔描述符个数  */
405 
406     osal_s32              pdet_val;     /* 上报pdet值 */
407 
408     osal_u8               tpc_code;     /* 上报tpc code */
409     osal_u8               pdet_chain   : 4;     /* 上报pdet的通道 */
410     osal_u8               protocol     : 4;     /* 校准帧的协议模式 wlan_phy_protocol_enum */
411     osal_u8               dscr_tpc;
412     osal_u8               dscr_pdet_en;
413     hal_dyn_cali_chain_status_stru cali_chain_status_info;
414 } hal_dyn_cali_val_stru;
415 
416 typedef struct {
417     frw_timeout_stru             scan_timer;                             /* 扫描定时器用于切换信道 */
418     mac_channel_stru             home_channel;                           /* 记录home channel */
419 
420     osal_u8                    original_mac_addr[WLAN_MAC_ADDR_LEN];     /* 扫描开始前保存原始的MAC地址 */
421     wlan_scan_mode_enum_uint8    scan_mode;                              /* 扫描模式 */
422     osal_u8                    scan_pause_bitmap;                        /* 扫描是否被暂停 */
423 
424     osal_u8                    start_chan_idx;                         /* 扫描起始idx */
425     osal_u8                    scan_chan_idx;                          /* 当前扫描信道索引累加值 */
426     osal_u8                    channel_nums;                           /* 此hal扫描的信道个数 */
427     osal_u8                    scan_ap_num_in_2p4;                     /* 在2.4g上扫到ap的信道个数 */
428 
429     osal_u8                    last_channel_band;                      /* 上一个channel的频段 */
430 
431     /* 记录当前信道的扫描次数,第一次发送广播ssid的probe req帧,后面发送指
432        定ssid的probe req帧 */
433     osal_u8                    curr_channel_scan_count;
434     osal_u8                    max_scan_count_per_channel;             /* 每个信道的扫描次数 */
435 
436     /* 间隔n个信道,切回工作信道工作一段时间 */
437     osal_u8                    scan_channel_interval;
438 
439     /* 扫描在某一信道停留此时间后,扫描结束, ms,必须配置为MAC负载统计周期的整数倍 */
440     osal_u16                   scan_time;
441     osal_u16                   work_time_on_home_channel;  /* 背景扫描时,返回工作信道工作的时间 */
442 
443     osal_u32                   scan_timestamp;                         /* 记录最新一次扫描开始的时间 */
444 
445     osal_u8                    scan_ap_num_in_5p0;                     /* 在5g上扫到ap的信道个数 */
446     osal_u8                    curr_scan_state               : 2; /* 此hal扫描状态 */
447     osal_u8                    scan_curr_chan_find_bss_flag  : 1; /* 本信道是否扫到bss */
448 
449     /* 背景扫描时,扫描完一个信道,判断是否需要切回工作信道工作 */
450     osal_u8                    need_switch_back_home_channel : 1;
451     osal_u8                    working_in_home_chan          : 1; /* 是否工作在工作信道 */
452     osal_u8                    scan_band                     : 2; /* 扫描的频段,支持fast scan使用 */
453     osal_u8                    resv0                         : 1;
454     hal_scan_tx_dscr_dbg_ctl_enum_uint8 tx_dscr_debug_ctl; /* 控制扫描时打印部分tx dscr */
455     osal_u8                    resv1;
456 } hal_scan_params_stru;
457 
458 struct tag_hal_to_dmac_device_stru;
459 
460 typedef osal_void (*p_dmac_scan_one_channel_start_cb)(struct tag_hal_to_dmac_device_stru *hal_device,
461     oal_bool_enum_uint8 is_scan_start);
462 
463 typedef struct {
464     p_dmac_scan_one_channel_start_cb         hmac_scan_one_channel_start;
465 } hal_device_fsm_cb;
466 
467 /* hal device状态机结构体 */
468 typedef struct _hal_device_handle_handler {
469     osal_u8                        cur_state;
470     osal_u8                        prev_state;
471     oal_fsm_stru                   oal_fsm;                    /* 状态机 */
472     osal_u8                        is_fsm_attached;            /* 状态机是否已经注册 */
473     frw_timeout_stru               check_timer;                /* 定时器 */
474     osal_u8                        wait_hw_txq_empty    : 1;   /* 标记是否等待硬件队列为空后关闭mac pa */
475     osal_u8                        mac_pa_switch_en     : 1;
476     osal_u8                        bit_resv             : 6;
477     osal_u8                        pm_vap_id;                  /* 执行休眠唤醒的hal vap id */
478     hal_work_sub_state_uint8     sub_work_state;               /* pm状态,用于双rf下各rf状态同步 */
479 
480     osal_u32                       vap_pm_state_bitmap[HAL_WORK_SUB_STATE_NUM];     /* vap ps state bitmap */
481     hal_device_fsm_cb            hal_device_fsm_cb;
482 } hal_dev_fsm_stru;
483 
484 /* hal device m2s状态机结构体 */
485 typedef struct {
486     oal_fsm_stru                     oal_fsm;          /* 状态机 */
487     osal_u8                        is_fsm_attached;    /* 状态机是否已经注册 */
488     wlan_m2s_type_enum_uint8         m2s_type;         /* 0:软切换 1:硬切换 */
489     wlan_m2s_mode_stru               m2s_mode;         /* m2s业务申请占用bitmap,用户优先级管理 */
490     oal_bool_enum_uint8              command_scan_on;  /* command下优化扫描是否在执行,防止miso时误end */
491     osal_u8                        _rom[4];            /* 4字节储存rom地址 */
492 } hal_m2s_fsm_stru;
493 
494 #ifdef _PRE_WLAN_FEATURE_M2S
495 typedef osal_void (*p_m2s_back_to_mimo_check_cb)(struct tag_hal_to_dmac_device_stru *hal_device);
496 
497 typedef struct {
498     p_m2s_back_to_mimo_check_cb    m2s_back_to_mimo_check;
499 } hal_device_m2s_mgr_cb;
500 
501 typedef struct {
502     /* 处于管理用户时,需要调整action方案 */
503     wlan_m2s_mgr_vap_stru     m2s_blacklist[WLAN_M2S_BLACKLIST_MAX_NUM];
504     osal_u8                     blacklist_bss_index;                       /* 黑名单MAC地址的数组下标 */
505     osal_u8                     blacklist_bss_cnt;                         /* 黑名单用户个数 */
506     osal_u8                     m2s_switch_protect  : 1; /* 是否使能m2s切换保护,针对sta模式 */
507 
508     /* 存在关联ap用户是blacklist none的,需要刷新标记为切换保持miso稳定态 */
509     osal_u8                     delay_swi_miso_hold : 1;
510     osal_u8                     mss_on              : 1; /* 是否使能mss上报和下发功能 */
511     osal_u8                     resv                : 5;
512 
513     /* 最近一次cur rssi mgmt逻辑学习到的合适single_txchain */
514     osal_u8                     rssi_mgmt_single_txchain;
515     hal_device_m2s_mgr_cb     hal_device_m2s_mgr_cb;
516 } hal_device_m2s_mgr_stru;
517 #endif
518 
519 typedef struct {
520     frw_timeout_stru s2m_resume_timer;          /* 切回mimo状态超时等待定时器 */
521 
522     /* siso ap切换回mimo探测时间,防止音乐切歌造成太过频繁 */
523     frw_timeout_stru bt_coex_s2m_siso_ap_timer;
524 
525     hal_coex_m2s_mode_bitmap_stru m2s_mode_bitmap; /* 申请siso切换的业务bitmap,目前是ldac=1 和6slot=2 */
526 
527     /* 申请切换回mimo的业务bitmap,目前是ldac=0 a2dp=0 和6slot=0 3者都满足 */
528     hal_coex_s2m_mode_bitmap_stru s2m_mode_bitmap;
529 
530     /* 需要切回mimo的超时处理函数里面才用此bit来清m2s标记,防止l
531        dac结束时,6slot来了又切siso流程 */
532     hal_coex_s2m_mode_bitmap_stru s2m_wait_bitmap;
533 
534     osal_u8 siso_ap_excute_on : 1; /* siso ap切换siso执行标志 */
535     osal_u8 m2s_6slot         : 1; /* 0: m2s; 1:开m2s */
536     osal_u8 m2s_ldac          : 1;
537     osal_u8 m2s_resv          : 5;
538 } hal_device_btcoex_mgr_stru;
539 
540 typedef struct tag_hal_to_dmac_device_stru {
541     hal_cfg_cap_info_stru  *cfg_cap_info;
542 
543     hal_rx_dscr_queue_header_stru rx_dscr_queue[HAL_RX_QUEUE_NUM];
544     hal_tx_dscr_queue_header_stru tx_dscr_queue[HAL_TX_QUEUE_NUM];
545 
546     osal_u32 rx_machw_dscr_addr[HAL_RX_DSCR_QUEUE_ID_BUTT]; /* 接收硬件队列状态寄存器 */
547 
548     osal_u16 rx_normal_dscr_cnt;
549     osal_u16 rx_small_dscr_cnt;
550     osal_u16 rx_high_dscr_cnt;
551 
552     hal_alg_stat_info_stru hal_alg_stat;  /* 算法使用的统计信息结构体 */
553 
554     /* 0: 关闭常发; 1:保留给RF测试; 2: ampdu聚合帧常发; 3:非聚合帧常发 */
555     osal_u8 al_tx_flag            : 3;
556 
557     /* 0: 关闭常收; 1:保留给RF测试;2: ampdu聚合帧常收; 3:非聚合帧常收 */
558     osal_u8 al_rx_flag            : 3;
559     osal_u8 one_packet_st         : 1; /* 0表示DBC结束 1表示DBAC正在执行 */
560     osal_u8 clear_fifo_st         : 1; /* 0表示无clear fifo状态,1表示clear fifo状态 */
561 
562     osal_u8 al_txrx_ampdu_num     : 7; /* 指示用于常发常收的聚合帧数目 */
563     osal_u8 current_rx_list_index : 1;
564 
565     /* 分两次打印寄存器信息,0:上报soc寄存器的值,1:上报rf寄存器的值, */
566     /* 2:上报MAC寄存器的值,3:补充 ABB_CALI_WL_CTRL 信息,4:上报phy寄存器的值 */
567     osal_u8 reg_info_flag         : 5;
568     osal_u8 sdp_init_flag         : 1; /* 0表示 wifi aware未初始化,1表示 wifi aware已初始化 */
569     osal_u8 rsv                   : 2; /* 已删除, 算法用的是vap中的,当前创建的P2P 是处于CL/GO 模式 */
570 
571     osal_u8 current_chan_number;
572 
573     osal_u32                     al_tx_pkt_len;
574     osal_u32                     rx_normal_mdpu_succ_num;
575     osal_u32                     rx_ampdu_succ_num;
576     osal_u32                     rx_ppdu_fail_num;
577 
578     osal_u8   p2p_hal_vap_idx;         /* 用于P2P 中断产生后指示对应设备的hal vap */
579     osal_u8   sta_hal_vap_idx;         /* 用于STA 中断产生后指示对应设备的hal vap */
580     osal_u8   ap_hal_vap_idx;          /* 用于softAP 中断产生后指示对应设备的hal vap */
581     osal_u8   ax_vap_cnt; /* 记录当前存在ax设备的数目 */
582     osal_u8   resv[2]; // 2字节预留
583 
584     hal_dyn_cali_val_stru dyn_cali_val;
585 
586 #ifdef _PRE_WLAN_FEATURE_DFS
587     hal_dfs_radar_filter_stru dfs_radar_filter;
588 #endif
589 
590     /* hh503重构出来了rf dev,校准参数全部都从rf dev中获取 */
591     /* 功率相关PHY参数 */
592     hal_phy_pow_param_stru          phy_pow_param;
593 
594     /* 字节对齐 */
595     p_hal_alg_isr_func  pa_hal_alg_isr_func_table[HAL_ISR_TYPE_BUTT][HAL_ALG_ISR_NOTIFY_BUTT];
596 
597     osal_s16                     always_rx_rssi;
598 
599     mac_channel_stru           wifi_channel_status;
600 
601     hal_rssi_stru              rssi;
602 
603     osal_s8                    rx_last_rssi; /* 保存上次rssi */
604     osal_u8                      adc_4t01_flag : 1; /* ADC使用4路80M合成为320M */
605     osal_u8                      resv0         : 7;
606     osal_u8                      adc_type : 4,      /* hal_clk_adc_dac_enum */
607                                dac_type : 4;      /* hal_clk_adc_dac_enum */
608 
609     osal_u8                      current_11ax_working : 1, /* 当前hal dev是否有工作的11ax vap */
610                                ampdu_tx_hw          : 1, /* AMPDU TX硬化开关 */
611                                ampdu_partial_resnd  : 1, /* 硬件聚合时,MAC是否做部分帧重传 */
612                                intf_det_invalid     : 1, /* 指示当前的检测结果是否有效 */
613                                dpd_cali_doing       : 1,
614                                dpd_clk_on           : 1,
615 
616                                /* 功率RF寄存器控使能时,固定功率配置不生效 */
617                                pow_rf_reg_ctl_flag  : 1,
618                                m2s_excute_flag      : 1; /* m2s正在执行的标记 */
619 
620     wlan_chan_ratio_stru            chan_ratio;                       /* 信道繁忙度相关统计量 */
621     wlan_scan_chan_stats_stru       chan_result;                      /* 扫描时 一个信道的信道测量记录 */
622 
623     hal_dev_fsm_stru               hal_dev_fsm;                       /* hal device 状态机结构体 */
624     osal_u32                         work_vap_bitmap;                   /* 需要在work状态工作的vap的个数 */
625 
626     hal_m2s_fsm_stru               hal_m2s_fsm;                       /* hal device m2s状态机 */
627 
628     /* hal device上所有vap上用户数总和,方便统计本hal device上用户数 */
629     osal_u8                      assoc_user_nums;
630     osal_u8                      fix_power_level;                    /* 固定功率等级(取值为0, 1, 2, 3) */
631     osal_u8                      control_frm_power_level;            /* 控制帧的功率等级 */
632 
633     osal_void                    *alg_priv;                       /* 算法私有结构体 */
634     hal_scan_params_stru           hal_scan_params;
635 
636     hal_device_tx_pwr_ctrl_stru    tx_pwr_ctrl;
637 
638     frw_timeout_stru                    btcoex_powersave_timer;
639     hal_device_btcoex_sw_preempt_stru   btcoex_sw_preempt;
640 
641     osal_u8                   srb_switch         : 1,
642                               mac_parse_tim      : 1,
643                               fix_sifs_resp_rate : 1, /* 是否限制响应帧速率 */
644                               is_mac_pa_enabled  : 1, /* pa是否使能 */
645                               sideband_flag      : 1, /* 0:表示非边带认证国家,1:表示边带认证国家 */
646                               resv4              : 1,
647                               promis_switch      : 1, /* 混杂模式开关 */
648                               is_temp_protect_pa_off  : 1; /* 过温保护是否关闭PA */
649     osal_u8                   reserve[2];
650 
651     p_tbtt_ap_isr_func                  tbtt_update_beacon_func;
652 
653     alg_rx_dscr_ctl_device_info_stru    rx_dscr_ctl;
654 #ifdef _PRE_WLAN_FEATURE_FTM
655     osal_u64              t1;
656     osal_u64              t4;
657 #endif
658     /* 同频干扰算法 */
659     osal_u32 duty_ratio;          /* 占空比统计 */
660 
661     /* MAC测量信息 */
662     hal_ch_mac_statics_stru  mac_ch_stats;
663     hal_ch_intf_statics_stru intf_statics_stru;
664 
665     hal_device_btcoex_mgr_stru device_btcoex_mgr;
666 
667     osal_u8 twt_session_enable             : 1;
668     osal_u8 psd_enable : 1;
669     osal_u8 resv1 : 6;
670 
671     osal_u8 resv2[2]; /* 2字节resv */
672     oal_bool_enum_uint8 ps_mode_ever; /* 标记干扰检测期间是否进过低功耗 */
673 
674     osal_u8 tx_ba_index_table[MAC_TX_BA_LUT_BMAP_LEN]; /* 发送端BA 软件维护LUT表位图 大小4 */
675     osal_u8 resv3[2]; // 4字节对齐
676     osal_u16 foc_err_cnt;
677     osal_u32 last_trigger_time;
678     osal_s32 cfo_phase_avg;
679     osal_u32 phase_det_cnt;
680     /* ROM化后资源扩展指针 */
681     osal_void             *_rom;
682     osal_u16              tx_time;
683     osal_u8               resv5[2];
684     osal_u32              backoff_done_timestamp;
685     osal_u32              tx_done_timestamp;
686 } hal_to_dmac_device_stru;
687 
688 /* 自动调频的 pps门限 */
689 typedef struct {
690     osal_u32 pps_value_0;
691     osal_u32 pps_value_1;
692     osal_u32 pps_value_2;
693 } hmac_pps_value_stru;
694 
695 /* HAL模块和DMAC模块共用的WLAN RX结构体 */
696 typedef struct {
697     osal_u32                  *base_dscr;      /* 描述符基地址 */
698     hal_to_dmac_device_stru *hal_device;
699     osal_u16                  dscr_num;        /* 接收到的描述符的个数 */
700     osal_u8                   queue_id;        /* 队列同步标识 */
701     osal_u8                   channel_num;
702 } hal_wlan_rx_event_stru;
703 
704 typedef struct {
705     hal_tx_dscr_stru        *base_dscr; /* 发送完成中断硬件所上报的描述符指针 */
706     hal_to_dmac_device_stru *hal_device;
707     osal_u8                dscr_num; /* 硬件一次发送所发出的描述符个数 */
708 
709     osal_s16                pdet_val;
710     osal_u8                 tpc_code;
711 
712     osal_u64              t1;
713     osal_u64              t4;
714     osal_u16              tx_time;
715     oal_bool_enum_uint8      pdet_enable : 1;
716     osal_u8                chain_num       : 1;
717     osal_u8                resv            : 6;
718     osal_u8               resv1[1];
719     osal_u32              backoff_done_timestamp;
720     osal_u32              tx_done_timestamp;
721 } hal_tx_complete_event_stru;
722 
723 typedef struct {
724     hal_error_state_stru            error_state;
725     hal_to_dmac_device_stru        *hal_device;
726 } hal_error_irq_event_stru;
727 
728 typedef struct {
729     hal_to_dmac_device_stru        *hal_device;
730 } hal_common_irq_event_stru;
731 
732 typedef struct {
733     osal_u8 ampdu_enable;
734     osal_u8 mpdu_num;
735 }hal_tx_mpdu_info_mod;
736 
737 typedef struct {
738     wlan_scan_chan_stats_stru      chan_result_total; /* 时间、功率检测结果 */
739     hal_ch_mac_statics_stru        mac_ch_stats_total; /* 发送、接收时间检测结果 */
740 } alg_intf_det_ch_stats_result;
741 
742 typedef struct {
743     osal_u8 vap_id;                               /* 下发扫描请求的vap id */
744     wlan_scan_type_enum_uint8 bss_type; /* 要扫描的bss类型 */
745     wlan_scan_type_enum_uint8 scan_type;          /* 主动/被动 */
746     osal_u8 probe_delay;                          /* 主动扫描发probe request帧之前的等待时间 */
747 
748     osal_u8 scan_func;                            /* DMAC SCANNER 扫描模式 */
749     osal_u8 max_scan_count_per_channel;           /* 每个信道的扫描次数 */
750     osal_u16 scan_time;                           /* 扫描在某一信道停留此时间后,扫描结束, ms,必须是10的整数倍 */
751 
752     wlan_scan_mode_enum_uint8 scan_mode;          /* 扫描模式:前景扫描 or 背景扫描 */
753     osal_u8 channel_nums;                         /* 信道列表中信道的个数 */
754     osal_u8 resv[2];                              /* 对齐 */
755 
756     hal_chan_measure_stru measure_period;          /* 检测周期 */
757     mac_channel_stru channel_list[WLAN_MAX_CHANNEL_NUM];
758 } alg_intf_det_ch_stats_param;
759 /*****************************************************************************
760   4 函数实现
761 *****************************************************************************/
hal_rx_dscr_get_real_addr(osal_u32 * rx_dscr)762 static INLINE__ osal_u32*  hal_rx_dscr_get_real_addr(osal_u32 *rx_dscr)
763 {
764     if (rx_dscr == OAL_PTR_NULL) {
765         return rx_dscr;
766     }
767     return (osal_u32 *)((osal_u8 *)rx_dscr + sizeof(hal_rx_dscr_stru));
768 }
769 
hal_rx_dscr_get_sw_addr(osal_u32 * rx_dscr)770 static INLINE__ osal_u32*  hal_rx_dscr_get_sw_addr(osal_u32 *rx_dscr)
771 {
772     if (rx_dscr == OAL_PTR_NULL) {
773         return rx_dscr;
774     }
775     return (osal_u32 *)((osal_u8 *)rx_dscr - sizeof(hal_rx_dscr_stru));
776 }
777 
778 /*****************************************************************************
779     10.2 对外暴露的配置接口
780 *****************************************************************************/
781 #ifdef __cplusplus
782 #if __cplusplus
783 }
784 #endif
785 #endif
786 
787 #endif
788