1 /*
2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 /* ****************************************************************************
20 1 头文件包含
21 **************************************************************************** */
22 #include "oal_main.h"
23 #include "oal_mem.h"
24 #include "oal_net.h"
25 #include "oam_ext_if.h"
26 #include "hcc_hmac_if.h"
27
28 #ifdef __cplusplus
29 #if __cplusplus
30 extern "C" {
31 #endif
32 #endif
33
34 /* ****************************************************************************
35 2 全局变量定义
36 **************************************************************************** */
37 /* ****************************************************************************
38 3 函数实现
39 **************************************************************************** */
40 /* ****************************************************************************
41 功能描述 : 根据配置的资源数量初始化资源池配置
42 **************************************************************************** */
oal_main_init_mem_pool_cfg(const hi_u8 vap_num,const hi_u8 user_num)43 static hi_u32 oal_main_init_mem_pool_cfg(const hi_u8 vap_num, const hi_u8 user_num)
44 {
45 const hi_u16 mem_dog_size = OAL_MEM_INFO_SIZE + OAL_DOG_TAG_SIZE;
46 hi_u8 loop;
47
48 /* 本地变量内存池各子池基础使用数量, 驱动加载即使用的数量 */
49 oal_mem_subpool_cfg_stru ast_base_cfg[WLAN_MEM_LOCAL_SUBPOOL_CNT] = {
50 {WLAN_MEM_LOCAL_SIZE1 + mem_dog_size, 22}, {WLAN_MEM_LOCAL_SIZE2 + mem_dog_size, 10},
51 {WLAN_MEM_LOCAL_SIZE3 + mem_dog_size, 3}, {WLAN_MEM_LOCAL_SIZE4 + mem_dog_size, 2},
52 {WLAN_MEM_LOCAL_SIZE5 + mem_dog_size, 3}, {WLAN_MEM_LOCAL_SIZE6 + mem_dog_size, 1}
53 };
54
55 oal_mem_subpool_cfg_stru ast_event_cfg[WLAN_MEM_EVENT_SUBPOOL_CNT];
56 oal_mem_subpool_cfg_stru ast_local_cfg[WLAN_MEM_LOCAL_SUBPOOL_CNT];
57 oal_mem_subpool_cfg_stru ast_mib_cfg[WLAN_MEM_MIB_SUBPOOL_CNT] = {{WLAN_MEM_MIB_SIZE, vap_num}};
58 hi_u8 user_base[] = { 18, 0, 3, 1, 0, 2 }; /* 本地变量内存池各子池:添加用户时使用数量 */
59 hi_u8 vap_base[] = { 15, 20, 2, 5, 0, 0 }; /* 本地变量内存池各子池:添加vap时使用数量 */
60
61 /* 事件池支持单用户场景以及其他两种模式配置 */
62 ast_event_cfg[0].us_size = WLAN_MEM_EVENT_SIZE1 + mem_dog_size;
63 ast_event_cfg[1].us_size = WLAN_MEM_EVENT_SIZE2 + mem_dog_size;
64 ast_event_cfg[0].us_cnt = (user_num == 1) ? WLAN_MEM_EVENT_CNT1 : WLAN_MEM_EVENT_MULTI_USER_CNT1;
65 ast_event_cfg[1].us_cnt = (user_num == 1) ? WLAN_MEM_EVENT_CNT2 : WLAN_MEM_EVENT_MULTI_USER_CNT2;
66
67 hi_u32 ret = oal_mem_set_subpool_config(ast_event_cfg, OAL_MEM_POOL_ID_EVENT, WLAN_MEM_EVENT_SUBPOOL_CNT);
68 if (ret != HI_SUCCESS) {
69 return ret;
70 }
71
72 /* 01:根据支持的用户数量配置本地变量内存池 */
73 for (loop = 0; loop < WLAN_MEM_LOCAL_SUBPOOL_CNT; loop++) {
74 ast_local_cfg[loop].us_size = ast_base_cfg[loop].us_size;
75
76 /* 配置vap的使用量算在基准值里面 */
77 ast_local_cfg[loop].us_cnt = ast_base_cfg[loop].us_cnt + user_num * user_base[loop] + vap_num * vap_base[loop];
78 }
79
80 ret = oal_mem_set_subpool_config(ast_local_cfg, OAL_MEM_POOL_ID_LOCAL, WLAN_MEM_LOCAL_SUBPOOL_CNT);
81 if (ret != HI_SUCCESS) {
82 return ret;
83 }
84
85 /* 02:根据支持的vap数量配置MIB内存池 mib池子池只有一个 配置vap没有mib,数量在vap资源上-1 */
86 ret = oal_mem_set_subpool_config(ast_mib_cfg, OAL_MEM_POOL_ID_MIB, WLAN_MEM_MIB_SUBPOOL_CNT);
87 if (ret != HI_SUCCESS) {
88 return ret;
89 }
90
91 return HI_SUCCESS;
92 }
93
94 /* ****************************************************************************
95 功能描述 : OAL模块初始化总入口,包含OAL模块内部所有特性的初始化。
96 返 回 值 : 初始化返回值,成功或失败原因
97 **************************************************************************** */
oal_main_init(const hi_u8 vap_num,const hi_u8 user_num)98 hi_u32 oal_main_init(const hi_u8 vap_num, const hi_u8 user_num)
99 {
100 /* 保存用户配置的vap 和user资源数 */
101 if ((oal_mem_set_vap_res_num(vap_num, WLAN_SERVICE_VAP_NUM_PER_DEVICE) != HI_SUCCESS) ||
102 (oal_mem_set_user_res_num(user_num, WLAN_ACTIVE_USER_MAX_NUM) != HI_SUCCESS)) {
103 oam_error_log0(0, 0, "oal_main_init: set user/vap failed.");
104 return HI_FAIL;
105 }
106 /* 内存池配置初始化 vap user数量前面已经有校验 */
107 if (oal_main_init_mem_pool_cfg(vap_num, user_num) != HI_SUCCESS) {
108 oam_error_log0(0, 0, "oal_main_init: init mem pool cfg failed.");
109 return HI_FAIL;
110 }
111 /* 内存池初始化 */
112 if (oal_mem_init_pool() != HI_SUCCESS) {
113 oam_error_log0(0, 0, "oal_main_init: oal_mem_init_pool failed.");
114 return HI_FAIL;
115 }
116 printk("oal_main_init SUCCESSFULLY\r\n");
117 return HI_SUCCESS;
118 }
119
120 /* ****************************************************************************
121 功能描述 : OAL模块卸载
122 返 回 值 : 模块卸载返回值,成功或失败原因
123 **************************************************************************** */
oal_main_exit(hi_void)124 hi_void oal_main_exit(hi_void)
125 {
126 hcc_hmac_exit();
127 /* 内存池卸载 */
128 oal_mem_exit();
129
130 printk("oal_main_exit SUCCESSFULLY\r\n");
131 }
132
133 #ifdef __cplusplus
134 #if __cplusplus
135 }
136 #endif
137 #endif
138