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: header file of hmac_alg_notify.c.
15 * Create: 2020-7-5
16 */
17
18 #ifndef __HMAC_ALG_NOTIFY_H__
19 #define __HMAC_ALG_NOTIFY_H__
20
21 /*****************************************************************************
22 1 其他头文件包含
23 *****************************************************************************/
24 #include "hmac_alg_if.h"
25 #include "dmac_ext_if_hcm.h"
26 #include "hmac_main.h"
27 #include "hmac_vap.h"
28 #ifdef _PRE_WLAN_FEATURE_SMPS
29 #include "hmac_smps.h"
30 #endif
31 #include "hmac_thruput_test.h"
32 #ifdef __cplusplus
33 #if __cplusplus
34 extern "C" {
35 #endif
36 #endif
37
38 /*****************************************************************************
39 2 宏定义
40 *****************************************************************************/
41 /*****************************************************************************
42 7 STRUCT定义
43 *****************************************************************************/
44 /*****************************************************************************
45 4 全局变量声明
46 *****************************************************************************/
47 /*****************************************************************************
48 10 函数声明
49 *****************************************************************************/
50 osal_u32 hmac_alg_cfg_channel_notify(hmac_vap_stru *hmac_vap, mac_alg_channel_bw_chg_type_uint8 type);
51
52 osal_u32 hmac_alg_cfg_btcoex_state_notify(hal_to_dmac_device_stru *hal_device, hmac_alg_bt_aggr_time_uint8 type);
53
54 osal_u32 hmac_alg_add_assoc_user_notify(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user);
55 osal_u32 hmac_alg_del_assoc_user_notify(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user);
56 osal_u32 hmac_alg_rx_mgmt_notify(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
57 oal_netbuf_stru *buf);
58 osal_u32 hmac_alg_rx_cntl_notify(const hmac_vap_stru *hmac_vap, const hmac_user_stru *hmac_user,
59 const oal_netbuf_stru *buf);
60
61 osal_void *hmac_alg_get_algorithm_main(osal_void);
62 osal_u32 hmac_scan_param_sync(const mac_scan_req_stru *scan_req_params);
63 osal_u32 hmac_alg_scan_ch_complete_notify(osal_void *param);
64 #ifdef _PRE_WLAN_FEATURE_ANTI_INTERF
65 osal_u32 hmac_alg_anti_intf_switch(hal_to_dmac_device_stru *hal_device, oal_bool_enum_uint8 alg_enable);
66 #endif
67 osal_u32 hmac_alg_anti_intf_tbtt_handler(hmac_vap_stru *hmac_vap, hal_to_dmac_device_stru *hal_device);
68
69 #ifdef _PRE_WLAN_FEATURE_DBAC
70 osal_s32 hmac_alg_dbac_pause(hmac_vap_stru *hmac_vap);
71 osal_s32 hmac_alg_dbac_send_disassoc(hmac_vap_stru *hmac_vap, osal_u8 is_send);
72 osal_s32 hmac_alg_dbac_resume(hal_to_dmac_device_stru *hal_device, oal_bool_enum_uint8 is_resume_channel);
73 oal_bool_enum_uint8 hmac_alg_dbac_is_pause(hal_to_dmac_device_stru *hal_device);
74 osal_s32 hmac_alg_update_dbac_fcs_config(hmac_vap_stru *hmac_vap);
75 #endif
76 osal_void hmac_alg_vap_up_hmac_to_dmac(hmac_vap_stru *mac_vap);
77
78 /*****************************************************************************
79 函 数 名 : hmac_alg_tx_schedule_notify
80 功能描述 : 调用挂接到TX COMPLETE流程上的算法钩子
81 *****************************************************************************/
hmac_alg_tx_schedule_notify(const hal_to_dmac_device_stru * hal_device,osal_u8 ac_num,mac_tid_schedule_output_stru * sch_output)82 static INLINE__ osal_u32 hmac_alg_tx_schedule_notify(const hal_to_dmac_device_stru *hal_device, osal_u8 ac_num,
83 mac_tid_schedule_output_stru *sch_output)
84 {
85 hmac_alg_stru *alg_stru = OSAL_NULL;
86 if (osal_unlikely(hal_device == OSAL_NULL || sch_output == OSAL_NULL)) {
87 return OAL_ERR_CODE_PTR_NULL;
88 }
89 alg_stru = (hmac_alg_stru *)hmac_alg_get_algorithm_main();
90 if (osal_unlikely(alg_stru->tx_schedule_func == OSAL_NULL)) {
91 return OAL_ERR_CODE_PTR_NULL;
92 }
93
94 if (ac_num >= HAL_TX_QUEUE_NUM) {
95 return OAL_FAIL;
96 }
97
98 return alg_stru->tx_schedule_func(hal_device, ac_num, sch_output);
99 }
100 /*****************************************************************************
101 函 数 名 : hmac_alg_tx_schedule_timer_notify
102 功能描述 : 通知调度算法更新调度灌包timer
103 *****************************************************************************/
hmac_alg_tx_schedule_timer_notify(const hal_to_dmac_device_stru * hal_device)104 static INLINE__ osal_u32 hmac_alg_tx_schedule_timer_notify(const hal_to_dmac_device_stru *hal_device)
105 {
106 hmac_alg_stru *alg_stru = OSAL_NULL;
107 if (osal_unlikely(hal_device == OSAL_NULL)) {
108 return OAL_ERR_CODE_PTR_NULL;
109 }
110 alg_stru = (hmac_alg_stru *)hmac_alg_get_algorithm_main();
111 if (osal_unlikely(alg_stru->tx_schedule_timer_func == OSAL_NULL)) {
112 return OAL_ERR_CODE_PTR_NULL;
113 }
114
115 return alg_stru->tx_schedule_timer_func(hal_device);
116 }
117 /*****************************************************************************
118 函 数 名 : hmac_alg_user_info_update_notify
119 功能描述 : 更新user info 时回调算法
120 *****************************************************************************/
hmac_alg_user_info_update_notify(const hal_to_dmac_device_stru * hal_device,hmac_user_stru * hmac_user,mac_tid_schedule_output_stru schedule_ouput,osal_u8 device_mpdu_full)121 static INLINE__ osal_u32 hmac_alg_user_info_update_notify(const hal_to_dmac_device_stru *hal_device,
122 hmac_user_stru *hmac_user, mac_tid_schedule_output_stru schedule_ouput, osal_u8 device_mpdu_full)
123 {
124 hmac_alg_stru *alg_stru = OSAL_NULL;
125 if (osal_unlikely(hal_device == OSAL_NULL || hmac_user == OSAL_NULL)) {
126 return OAL_ERR_CODE_PTR_NULL;
127 }
128 alg_stru = (hmac_alg_stru *)hmac_alg_get_algorithm_main();
129 if (osal_unlikely(alg_stru->tid_update_func == OSAL_NULL)) {
130 return OAL_ERR_CODE_PTR_NULL;
131 }
132
133 return alg_stru->user_info_update_func(hal_device, hmac_user, schedule_ouput, device_mpdu_full);
134 }
135 /*****************************************************************************
136 函 数 名 : hmac_alg_tid_update_notify
137 功能描述 : 更新TID队列时回调算法
138 *****************************************************************************/
hmac_alg_tid_update_notify(hmac_tid_stru * tid,osal_u8 in_mpdu_num)139 static INLINE__ osal_u32 hmac_alg_tid_update_notify(hmac_tid_stru *tid, osal_u8 in_mpdu_num)
140 {
141 hmac_alg_stru *alg_stru = OSAL_NULL;
142 if (osal_unlikely(tid == OSAL_NULL)) {
143 return OAL_ERR_CODE_PTR_NULL;
144 }
145 alg_stru = (hmac_alg_stru *)hmac_alg_get_algorithm_main();
146 if (osal_unlikely(alg_stru->tid_update_func == OSAL_NULL)) {
147 return OAL_ERR_CODE_PTR_NULL;
148 }
149
150 return alg_stru->tid_update_func(tid, in_mpdu_num);
151 }
152
153 #ifdef _PRE_WLAN_FEATURE_SMPS
154 /*****************************************************************************
155 函 数 名 : hmac_tx_check_mimo_rate
156 功能描述 : 更新发送描述符中的"phy tx mode 1"
157 *****************************************************************************/
hmac_tx_check_mimo_rate(osal_u8 protocol_mode,const hal_tx_txop_alg_stru * txop_alg,osal_u8 data_idx)158 static INLINE__ oal_bool_enum_uint8 hmac_tx_check_mimo_rate(osal_u8 protocol_mode, const hal_tx_txop_alg_stru *txop_alg,
159 osal_u8 data_idx)
160 {
161 oal_bool_enum_uint8 mimo_rate = OSAL_FALSE;
162 osal_u8 daterate = WLAN_HT_MCS_BUTT;
163 if (protocol_mode == WLAN_HT_PHY_PROTOCOL_MODE) {
164 daterate = hal_txop_alg_get_tx_dscr(txop_alg)[data_idx].nss_rate.ht_rate.ht_mcs;
165 if ((daterate >= WLAN_HT_MCS8) && (daterate < WLAN_HT_MCS_BUTT)) {
166 mimo_rate = OSAL_TRUE;
167 }
168 } else if (protocol_mode == WLAN_VHT_PHY_PROTOCOL_MODE) {
169 daterate = hal_txop_alg_get_tx_dscr(txop_alg)[data_idx].nss_rate.vht_nss_mcs.vht_mcs;
170 if (daterate > WLAN_SINGLE_NSS) {
171 mimo_rate = OSAL_TRUE;
172 }
173 } else {
174 /* 暂时不做处理 */
175 }
176
177 return mimo_rate;
178 }
179
180 /*****************************************************************************
181 函 数 名 : hmac_tx_update_smps_txop_alg
182 功能描述 : 更新发送描述符中的"phy tx mode 1"
183 *****************************************************************************/
hmac_tx_update_smps_txop_alg(hmac_vap_stru * hmac_vap,const hmac_user_stru * hmac_user,hal_tx_txop_alg_stru * txop_alg)184 static INLINE__ osal_void hmac_tx_update_smps_txop_alg(hmac_vap_stru *hmac_vap, const hmac_user_stru *hmac_user,
185 hal_tx_txop_alg_stru *txop_alg)
186 {
187 osal_u8 smps = 0;
188 osal_u8 protocol_mode = 0;
189 osal_u8 mimo_rate = 0;
190 osal_u8 index = 0;
191 hal_cfg_rts_tx_param_stru hal_rts_tx_param;
192
193 smps = hmac_user_get_smps_mode(hmac_vap, hmac_user);
194
195 if (smps >= WLAN_MIB_MIMO_POWER_SAVE_MIMO) {
196 return;
197 }
198
199 if (hmac_vap->vap_mode != WLAN_VAP_MODE_BSS_AP) {
200 return;
201 }
202
203 for (index = 0; index < HAL_TX_RATE_MAX_NUM; index++) {
204 protocol_mode = hal_txop_alg_get_tx_dscr(txop_alg)[index].protocol_mode;
205 mimo_rate = hmac_tx_check_mimo_rate(protocol_mode, txop_alg, index);
206
207 if (mimo_rate == OSAL_FALSE) {
208 continue;
209 }
210
211 if (smps == WLAN_MIB_MIMO_POWER_SAVE_DYNAMIC) {
212 hal_txop_alg_get_tx_dscr(txop_alg)[index].rts_cts_protect_mode = OSAL_TRUE;
213
214 /* 设置RTS速率对应的频带 */
215 hal_rts_tx_param.band = hmac_vap->channel.band;
216
217 /* RTS[0~2]设为24Mbps */
218 hal_rts_tx_param.protocol_mode[0] = WLAN_LEGACY_OFDM_PHY_PROTOCOL_MODE;
219 hal_rts_tx_param.rate[0] = WLAN_LEGACY_OFDM_24M_BPS;
220 hal_rts_tx_param.protocol_mode[1] = WLAN_LEGACY_OFDM_PHY_PROTOCOL_MODE;
221 hal_rts_tx_param.rate[1] = WLAN_LEGACY_OFDM_24M_BPS;
222 hal_rts_tx_param.protocol_mode[2] = WLAN_LEGACY_OFDM_PHY_PROTOCOL_MODE;
223 hal_rts_tx_param.rate[2] = WLAN_LEGACY_OFDM_24M_BPS;
224
225 /* 2G的RTS[3]设为1Mbps */
226 if (hal_rts_tx_param.band == WLAN_BAND_2G) {
227 hal_rts_tx_param.protocol_mode[3] = WLAN_11B_PHY_PROTOCOL_MODE;
228 hal_rts_tx_param.rate[3] = WLAN_LONG_11B_1M_BPS;
229 }
230 /* 5G的RTS[3]设为24Mbps */
231 else {
232 hal_rts_tx_param.protocol_mode[3] = WLAN_LEGACY_OFDM_PHY_PROTOCOL_MODE;
233 hal_rts_tx_param.rate[3] = WLAN_LEGACY_OFDM_24M_BPS;
234 }
235
236 } else if (smps == WLAN_MIB_MIMO_POWER_SAVE_STATIC) {
237 hal_txop_alg_get_tx_dscr(txop_alg)[index].nss_rate.ht_rate.ht_mcs = WLAN_HT_MCS0;
238 }
239 }
240 }
241 #endif
242
243 /*****************************************************************************
244 函 数 名 : hmac_alg_rx_notify
245 功能描述 : 调用挂接到RX流程上的算法钩子
246 *****************************************************************************/
hmac_alg_rx_notify(hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user,oal_netbuf_stru * buf,hal_rx_statistic_stru * rx_stats)247 static INLINE__ osal_void hmac_alg_rx_notify(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user, oal_netbuf_stru *buf,
248 hal_rx_statistic_stru *rx_stats)
249 {
250 hmac_alg_stru *alg_stru;
251 osal_u32 index;
252 if (osal_unlikely((hmac_vap == OSAL_NULL) || (hmac_user == OSAL_NULL) ||
253 (buf == OSAL_NULL) || (rx_stats == OSAL_NULL))) {
254 return;
255 }
256 alg_stru = (hmac_alg_stru *)hmac_alg_get_algorithm_main();
257
258 /* 检查是否有算法注册 */
259 if (osal_unlikely(alg_stru->alg_bitmap == 0)) {
260 return;
261 }
262
263 if (hmac_is_thruput_enable(THRUPUT_ALG_BYPASS)) {
264 return;
265 }
266
267 /* 调用钩子函数 */
268 for (index = HMAC_ALG_RX_START; index < HMAC_ALG_RX_NOTIFY_BUTT; index++) {
269 if (alg_stru->pa_rx_notify_func[index] != OSAL_NULL) {
270 alg_stru->pa_rx_notify_func[index](hmac_vap, hmac_user, buf, rx_stats);
271 }
272 }
273
274 return;
275 }
276
277 /*****************************************************************************
278 函 数 名 : hmac_alg_vap_up_notify
279 功能描述 : vap up时调用算法钩子
280 *****************************************************************************/
hmac_alg_vap_up_notify(hmac_vap_stru * hmac_vap)281 static INLINE__ osal_u32 hmac_alg_vap_up_notify(hmac_vap_stru *hmac_vap)
282 {
283 hmac_alg_stru *alg_stru;
284 osal_u32 index;
285 if (osal_unlikely(hmac_vap == OSAL_NULL)) {
286 return OAL_ERR_CODE_PTR_NULL;
287 }
288 hmac_alg_vap_up_hmac_to_dmac(hmac_vap);
289 alg_stru = (hmac_alg_stru *)hmac_alg_get_algorithm_main();
290
291 /* 检查是否有算法注册 */
292 if (alg_stru->alg_bitmap == 0) {
293 return OAL_SUCC;
294 }
295
296 /* 调用钩子函数 */
297 for (index = HMAC_ALG_VAP_UP_START; index < HMAC_ALG_VAP_UP_BUTT; index++) {
298 if (alg_stru->pa_alg_vap_up_notify_func[index] != OSAL_NULL) {
299 alg_stru->pa_alg_vap_up_notify_func[index](hmac_vap);
300 }
301 }
302
303 return OAL_SUCC;
304 }
305
306 /*****************************************************************************
307 函 数 名 : hmac_alg_vap_down_notify
308 功能描述 : vap down时调用算法钩子
309 *****************************************************************************/
hmac_alg_vap_down_notify(hmac_vap_stru * hmac_vap)310 static INLINE__ osal_u32 hmac_alg_vap_down_notify(hmac_vap_stru *hmac_vap)
311 {
312 hmac_alg_stru *alg_stru;
313 osal_u32 index;
314
315 if (osal_unlikely(hmac_vap == OSAL_NULL)) {
316 return OAL_ERR_CODE_PTR_NULL;
317 }
318 alg_stru = (hmac_alg_stru *)hmac_alg_get_algorithm_main();
319
320 /* 检查是否有算法注册 */
321 if (alg_stru->alg_bitmap == 0) {
322 return OAL_SUCC;
323 }
324
325 /* 调用钩子函数 */
326 for (index = HMAC_ALG_VAP_DOWN_START; index < HMAC_ALG_VAP_DOWN_BUTT; index++) {
327 if (alg_stru->pa_alg_vap_down_notify_func[index] != OSAL_NULL) {
328 alg_stru->pa_alg_vap_down_notify_func[index](hmac_vap);
329 }
330 }
331
332 return OAL_SUCC;
333 }
334
335 /*****************************************************************************
336 功能描述 : 算法参数同步通知,入参由调用者保证有效性
337 *****************************************************************************/
hmac_alg_para_sync_notify(alg_param_sync_stru * para)338 static INLINE__ osal_u32 hmac_alg_para_sync_notify(alg_param_sync_stru *para)
339 {
340 osal_u32 index;
341 hmac_alg_stru *alg_stru = (hmac_alg_stru *)hmac_alg_get_algorithm_main();
342
343 /* 检查是否有算法注册 */
344 if (alg_stru->alg_bitmap == 0) {
345 return OAL_SUCC;
346 }
347 if (osal_unlikely(para == OSAL_NULL)) {
348 return OAL_FAIL;
349 }
350
351 /* 调用钩子函数 */
352 for (index = 0; index < ALG_PARAM_SYNC_NOTIFY_BUTT; index++) {
353 if (alg_stru->alg_para_sync_notify_func[index] != OSAL_NULL) {
354 alg_stru->alg_para_sync_notify_func[index](para);
355 }
356 }
357
358 return OAL_SUCC;
359 }
360
361 /*****************************************************************************
362 功能描述 : 算法参数同步通知,入参由调用者保证有效性
363 *****************************************************************************/
hmac_alg_para_cfg_notify(hmac_vap_stru * hmac_vap,frw_msg * msg)364 static INLINE__ osal_u32 hmac_alg_para_cfg_notify(hmac_vap_stru *hmac_vap, frw_msg *msg)
365 {
366 osal_u32 index;
367 frw_msg alg_msg = {0};
368 hmac_alg_stru *alg_stru = (hmac_alg_stru *)hmac_alg_get_algorithm_main();
369
370 /* 检查是否有算法注册 */
371 if (alg_stru->alg_bitmap == 0) {
372 return OAL_SUCC;
373 }
374 if (osal_unlikely((hmac_vap == OSAL_NULL) || (msg == OSAL_NULL))) {
375 return OAL_FAIL;
376 }
377 cfg_msg_init(msg->data, msg->data_len, msg->rsp, msg->rsp_buf_len, &alg_msg);
378
379 /* 调用钩子函数 */
380 for (index = 0; index < ALG_PARAM_CFG_NOTIFY_BUTT; index++) {
381 if (alg_stru->alg_para_cfg_notify_func[index] != OSAL_NULL) {
382 alg_stru->alg_para_cfg_notify_func[index](hmac_vap, &alg_msg);
383 }
384 }
385
386 return OAL_SUCC;
387 }
388
389 /*****************************************************************************
390 功能描述 : bfee report帧速率或用户距离信息改变通知tpc算法更新功率,入参由调用者保证有效性
391 *****************************************************************************/
hmac_bfee_report_pow_adjust_notify(hal_to_dmac_device_stru * hal_device)392 static INLINE__ osal_u32 hmac_bfee_report_pow_adjust_notify(hal_to_dmac_device_stru *hal_device)
393 {
394 hmac_alg_stru *alg_stru = (hmac_alg_stru *)hmac_alg_get_algorithm_main();
395
396 /* 检查是否有算法注册 */
397 if (alg_stru->alg_bitmap == 0) {
398 return OAL_SUCC;
399 }
400 if (osal_unlikely(hal_device == OSAL_NULL)) {
401 return OAL_FAIL;
402 }
403
404 /* 检查钩子函数是否注册 */
405 if (alg_stru->bfee_report_pow_adjust_notify != OSAL_NULL) {
406 alg_stru->bfee_report_pow_adjust_notify(hal_device);
407 return OAL_FAIL;
408 }
409
410 return OAL_SUCC;
411 }
412
413 /*****************************************************************************
414 功能描述 : 功率表更新通知TPC更新参数,入参由调用者保证有效性
415 *****************************************************************************/
hmac_alg_pow_table_refresh_notify(hmac_vap_stru * hmac_vap)416 static INLINE__ osal_u32 hmac_alg_pow_table_refresh_notify(hmac_vap_stru *hmac_vap)
417 {
418 hmac_alg_stru *alg_stru = (hmac_alg_stru *)hmac_alg_get_algorithm_main();
419
420 /* 检查是否有算法注册 */
421 if (alg_stru->alg_bitmap == 0) {
422 return OAL_SUCC;
423 }
424 if (osal_unlikely(hmac_vap == OSAL_NULL)) {
425 return OAL_FAIL;
426 }
427
428 /* 检查钩子函数是否注册 */
429 if (alg_stru->alg_pow_table_refresh_notify_func != OSAL_NULL) {
430 alg_stru->alg_pow_table_refresh_notify_func(hmac_vap);
431 return OAL_FAIL;
432 }
433
434 return OAL_SUCC;
435 }
436
437 /*****************************************************************************
438 功能描述 : cb更新 通知tpc算法更新cb->rssi_level,入参由调用者保证有效性
439 *****************************************************************************/
hmac_alg_update_rssi_level_notify(hmac_vap_stru * hmac_vap,mac_tx_ctl_stru * cb,hmac_user_stru * hmac_user)440 static INLINE__ osal_u32 hmac_alg_update_rssi_level_notify(hmac_vap_stru *hmac_vap, mac_tx_ctl_stru *cb,
441 hmac_user_stru *hmac_user)
442 {
443 hmac_alg_stru *alg_stru = (hmac_alg_stru *)hmac_alg_get_algorithm_main();
444
445 /* 检查是否有算法注册 */
446 if (alg_stru->alg_bitmap == 0) {
447 return OAL_SUCC;
448 }
449 if (osal_unlikely((hmac_vap == OSAL_NULL) || (cb == OSAL_NULL))) {
450 return OAL_FAIL;
451 }
452
453 /* 检查钩子函数是否注册 */
454 if (alg_stru->alg_update_cb_rssi_level_notify_func != OSAL_NULL) {
455 alg_stru->alg_update_cb_rssi_level_notify_func(hmac_vap, cb, hmac_user);
456 return OAL_SUCC;
457 }
458
459 return OAL_FAIL;
460 }
461 #ifdef __cplusplus
462 #if __cplusplus
463 }
464 #endif
465 #endif
466
467 #endif /* end of hmac_alg_notify.h */
468