• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <linux/module.h>
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/platform_device.h>
5 #include <linux/delay.h>
6 #include <linux/err.h>
7 #include <linux/skbuff.h>
8 
9 #define DHD_STATIC_VERSION_STR "101.10.361.12 (wlan=r892223-20210928-1)"
10 #define STATIC_ERROR_LEVEL (1 << 0)
11 #define STATIC_TRACE_LEVEL (1 << 1)
12 #define STATIC_MSG_LEVEL (1 << 0)
13 uint static_msg_level = STATIC_ERROR_LEVEL | STATIC_MSG_LEVEL;
14 
15 #define DHD_STATIC_MSG(x, args...)                                             \
16     do {                                                                       \
17         if (static_msg_level & STATIC_MSG_LEVEL) {                             \
18             pr_err("[dhd] STATIC-MSG) %s : " x, __func__, ##args);             \
19         }                                                                      \
20     } while (0)
21 #define DHD_STATIC_ERROR(x, args...)                                           \
22     do {                                                                       \
23         if (static_msg_level & STATIC_ERROR_LEVEL) {                           \
24             pr_err("[dhd] STATIC-ERROR) %s : " x, __func__, ##args);           \
25         }                                                                      \
26     } while (0)
27 #define DHD_STATIC_TRACE(x, args...)                                           \
28     do {                                                                       \
29         if (static_msg_level & STATIC_TRACE_LEVEL) {                           \
30             pr_err("[dhd] STATIC-TRACE) %s : " x, __func__, ##args);           \
31         }                                                                      \
32     } while (0)
33 
34 #define BCMDHD_SDIO
35 #define BCMDHD_PCIE
36 #define CONFIG_BCMDHD_VTS := y
37 #define CONFIG_BCMDHD_DEBUG := y
38 
39 #ifndef MAX_NUM_ADAPTERS
40 #define MAX_NUM_ADAPTERS 1
41 #endif
42 
43 enum dhd_prealloc_index {
44     DHD_PREALLOC_PROT = 0,
45 #if defined(BCMDHD_SDIO)
46     DHD_PREALLOC_RXBUF = 1,
47     DHD_PREALLOC_DATABUF = 2,
48 #endif /* BCMDHD_SDIO */
49     DHD_PREALLOC_OSL_BUF = 3,
50     DHD_PREALLOC_SKB_BUF = 4,
51     DHD_PREALLOC_WIPHY_ESCAN0 = 5,
52     DHD_PREALLOC_WIPHY_ESCAN1 = 6,
53     DHD_PREALLOC_DHD_INFO = 7,
54 #if defined(BCMDHD_SDIO) || defined(BCMDHD_USB)
55     DHD_PREALLOC_DHD_WLFC_INFO = 8,
56 #endif /* BCMDHD_SDIO | BCMDHD_USB */
57 #ifdef BCMDHD_PCIE
58     DHD_PREALLOC_IF_FLOW_LKUP = 9,
59 #endif /* BCMDHD_PCIE */
60     DHD_PREALLOC_MEMDUMP_BUF = 10,
61 #if defined(CONFIG_BCMDHD_VTS) || defined(CONFIG_BCMDHD_DEBUG)
62     DHD_PREALLOC_MEMDUMP_RAM = 11,
63 #endif /* CONFIG_BCMDHD_VTS | CONFIG_BCMDHD_DEBUG */
64 #if defined(BCMDHD_SDIO) || defined(BCMDHD_USB)
65     DHD_PREALLOC_DHD_WLFC_HANGER = 12,
66 #endif /* BCMDHD_SDIO | BCMDHD_USB */
67     DHD_PREALLOC_PKTID_MAP = 13,
68     DHD_PREALLOC_PKTID_MAP_IOCTL = 14,
69 #if defined(CONFIG_BCMDHD_VTS) || defined(CONFIG_BCMDHD_DEBUG)
70     DHD_PREALLOC_DHD_LOG_DUMP_BUF = 15,
71     DHD_PREALLOC_DHD_LOG_DUMP_BUF_EX = 16,
72 #endif /* CONFIG_BCMDHD_VTS | CONFIG_BCMDHD_DEBUG */
73     DHD_PREALLOC_DHD_PKTLOG_DUMP_BUF = 17,
74     DHD_PREALLOC_STAT_REPORT_BUF = 18,
75     DHD_PREALLOC_WL_ESCAN = 19,
76     DHD_PREALLOC_FW_VERBOSE_RING = 20,
77     DHD_PREALLOC_FW_EVENT_RING = 21,
78     DHD_PREALLOC_DHD_EVENT_RING = 22,
79 #if defined(BCMDHD_UNUSE_MEM)
80     DHD_PREALLOC_NAN_EVENT_RING = 23,
81 #endif /* BCMDHD_UNUSE_MEM */
82     DHD_PREALLOC_MAX
83 };
84 
85 #define STATIC_BUF_MAX_NUM 20
86 #define STATIC_BUF_SIZE (PAGE_SIZE * 2)
87 
88 #ifndef CUSTOM_LOG_DUMP_BUFSIZE_MB
89 #define CUSTOM_LOG_DUMP_BUFSIZE_MB                                             \
90     4  /* DHD_LOG_DUMP_BUF_SIZE 4 MB static memory in kernel */
91 #endif /* CUSTOM_LOG_DUMP_BUFSIZE_MB */
92 
93 #define DHD_PREALLOC_PROT_SIZE (16 * 1024)
94 #define DHD_PREALLOC_RXBUF_SIZE (24 * 1024)
95 #define DHD_PREALLOC_DATABUF_SIZE (64 * 1024)
96 #define DHD_PREALLOC_OSL_BUF_SIZE (STATIC_BUF_MAX_NUM * STATIC_BUF_SIZE)
97 #define DHD_PREALLOC_WIPHY_ESCAN0_SIZE (64 * 1024)
98 #define DHD_PREALLOC_DHD_INFO_SIZE (34 * 1024)
99 #if defined(CONFIG_BCMDHD_VTS) || defined(CONFIG_BCMDHD_DEBUG)
100 #define DHD_PREALLOC_MEMDUMP_RAM_SIZE (1290 * 1024)
101 #endif /* CONFIG_BCMDHD_VTS | CONFIG_BCMDHD_DEBUG */
102 #define DHD_PREALLOC_DHD_WLFC_HANGER_SIZE (73 * 1024)
103 #if defined(CONFIG_BCMDHD_VTS) || defined(CONFIG_BCMDHD_DEBUG)
104 #define DHD_PREALLOC_DHD_LOG_DUMP_BUF_SIZE                                     \
105     (1024 * 1024 * CUSTOM_LOG_DUMP_BUFSIZE_MB)
106 #define DHD_PREALLOC_DHD_LOG_DUMP_BUF_EX_SIZE (8 * 1024)
107 #endif /* CONFIG_BCMDHD_VTS | CONFIG_BCMDHD_DEBUG */
108 #define DHD_PREALLOC_WL_ESCAN_SIZE (70 * 1024)
109 #ifdef CONFIG_64BIT
110 #define DHD_PREALLOC_IF_FLOW_LKUP_SIZE (20 * 1024 * 2)
111 #else
112 #define DHD_PREALLOC_IF_FLOW_LKUP_SIZE (20 * 1024)
113 #endif
114 #define FW_VERBOSE_RING_SIZE (256 * 1024)
115 #define FW_EVENT_RING_SIZE (64 * 1024)
116 #define DHD_EVENT_RING_SIZE (64 * 1024)
117 #define NAN_EVENT_RING_SIZE (64 * 1024)
118 
119 #if defined(CONFIG_64BIT)
120 #define WLAN_DHD_INFO_BUF_SIZE (24 * 1024)
121 #define WLAN_DHD_WLFC_BUF_SIZE (64 * 1024)
122 #define WLAN_DHD_IF_FLOW_LKUP_SIZE (64 * 1024)
123 #else
124 #define WLAN_DHD_INFO_BUF_SIZE (16 * 1024)
125 #define WLAN_DHD_WLFC_BUF_SIZE (64 * 1024)
126 #define WLAN_DHD_IF_FLOW_LKUP_SIZE (20 * 1024)
127 #endif /* CONFIG_64BIT */
128 #define WLAN_DHD_MEMDUMP_SIZE (800 * 1024)
129 
130 #define DHD_SKB_1PAGE_BUFSIZE (PAGE_SIZE * 1)
131 #define DHD_SKB_2PAGE_BUFSIZE (PAGE_SIZE * 2)
132 #define DHD_SKB_4PAGE_BUFSIZE (PAGE_SIZE * 4)
133 
134 #ifdef BCMDHD_PCIE
135 #define DHD_SKB_1PAGE_BUF_NUM 0
136 #define DHD_SKB_2PAGE_BUF_NUM 192
137 #elif defined(BCMDHD_SDIO)
138 #define DHD_SKB_1PAGE_BUF_NUM 8
139 #define DHD_SKB_2PAGE_BUF_NUM 8
140 #endif /* BCMDHD_PCIE */
141 #define DHD_SKB_4PAGE_BUF_NUM 1
142 
143 /* The number is defined in linux_osl.c
144  * WLAN_SKB_1_2PAGE_BUF_NUM => STATIC_PKT_1_2PAGE_NUM
145  * WLAN_SKB_BUF_NUM => STATIC_PKT_MAX_NUM
146  */
147 #if defined(BCMDHD_SDIO) || defined(BCMDHD_PCIE)
148 #define WLAN_SKB_1_2PAGE_BUF_NUM                                               \
149     ((DHD_SKB_1PAGE_BUF_NUM) + (DHD_SKB_2PAGE_BUF_NUM))
150 #define WLAN_SKB_BUF_NUM ((WLAN_SKB_1_2PAGE_BUF_NUM) + (DHD_SKB_4PAGE_BUF_NUM))
151 #endif
152 
153 void *wlan_static_prot[MAX_NUM_ADAPTERS] = {NULL};
154 void *wlan_static_rxbuf[MAX_NUM_ADAPTERS] = {NULL};
155 void *wlan_static_databuf[MAX_NUM_ADAPTERS] = {NULL};
156 void *wlan_static_osl_buf[MAX_NUM_ADAPTERS] = {NULL};
157 void *wlan_static_scan_buf0[MAX_NUM_ADAPTERS] = {NULL};
158 void *wlan_static_scan_buf1[MAX_NUM_ADAPTERS] = {NULL};
159 void *wlan_static_dhd_info_buf[MAX_NUM_ADAPTERS] = {NULL};
160 void *wlan_static_dhd_wlfc_info_buf[MAX_NUM_ADAPTERS] = {NULL};
161 void *wlan_static_if_flow_lkup[MAX_NUM_ADAPTERS] = {NULL};
162 void *wlan_static_dhd_memdump_ram_buf[MAX_NUM_ADAPTERS] = {NULL};
163 void *wlan_static_dhd_wlfc_hanger_buf[MAX_NUM_ADAPTERS] = {NULL};
164 #if defined(CONFIG_BCMDHD_VTS) || defined(CONFIG_BCMDHD_DEBUG)
165 void *wlan_static_dhd_log_dump_buf[MAX_NUM_ADAPTERS] = {NULL};
166 void *wlan_static_dhd_log_dump_buf_ex[MAX_NUM_ADAPTERS] = {NULL};
167 #endif /* CONFIG_BCMDHD_VTS | CONFIG_BCMDHD_DEBUG */
168 void *wlan_static_wl_escan_info_buf[MAX_NUM_ADAPTERS] = {NULL};
169 void *wlan_static_fw_verbose_ring_buf[MAX_NUM_ADAPTERS] = {NULL};
170 void *wlan_static_fw_event_ring_buf[MAX_NUM_ADAPTERS] = {NULL};
171 void *wlan_static_dhd_event_ring_buf[MAX_NUM_ADAPTERS] = {NULL};
172 void *wlan_static_nan_event_ring_buf[MAX_NUM_ADAPTERS] = {NULL};
173 
174 #if defined(BCMDHD_SDIO) || defined(BCMDHD_PCIE)
175 static struct sk_buff *wlan_static_skb[MAX_NUM_ADAPTERS][WLAN_SKB_BUF_NUM];
176 #endif /* BCMDHD_SDIO | BCMDHD_PCIE */
177 
dhd_wlan_mem_prealloc(uint bus_type,int index,int section,unsigned long size)178 void *dhd_wlan_mem_prealloc(
179 #ifdef BCMDHD_MDRIVER
180     uint bus_type, int index,
181 #endif
182     int section, unsigned long size)
183 {
184 #ifndef BCMDHD_MDRIVER
185     uint bus_type = 0;
186     int index = 0;
187 #endif
188     DHD_STATIC_MSG("bus_type %d, index %d, sectoin %d, size %ld\n", bus_type,
189                    index, section, size);
190 
191     if (section == DHD_PREALLOC_PROT) {
192         return wlan_static_prot[index];
193     }
194 
195 #if defined(BCMDHD_SDIO)
196     if (section == DHD_PREALLOC_RXBUF) {
197         return wlan_static_rxbuf[index];
198     }
199 
200     if (section == DHD_PREALLOC_DATABUF) {
201         return wlan_static_databuf[index];
202     }
203 #endif /* BCMDHD_SDIO */
204 
205 #if defined(BCMDHD_SDIO) || defined(BCMDHD_PCIE)
206     if (section == DHD_PREALLOC_SKB_BUF) {
207         return wlan_static_skb[index];
208     }
209 #endif /* BCMDHD_SDIO | BCMDHD_PCIE */
210 
211     if (section == DHD_PREALLOC_WIPHY_ESCAN0) {
212         return wlan_static_scan_buf0[index];
213     }
214 
215     if (section == DHD_PREALLOC_WIPHY_ESCAN1) {
216         return wlan_static_scan_buf1[index];
217     }
218 
219     if (section == DHD_PREALLOC_OSL_BUF) {
220         if (size > DHD_PREALLOC_OSL_BUF_SIZE) {
221             DHD_STATIC_ERROR("request OSL_BUF(%lu) > %ld\n", size,
222                              DHD_PREALLOC_OSL_BUF_SIZE);
223             return NULL;
224         }
225         return wlan_static_osl_buf[index];
226     }
227 
228     if (section == DHD_PREALLOC_DHD_INFO) {
229         if (size > DHD_PREALLOC_DHD_INFO_SIZE) {
230             DHD_STATIC_ERROR("request DHD_INFO(%lu) > %d\n", size,
231                              DHD_PREALLOC_DHD_INFO_SIZE);
232             return NULL;
233         }
234         return wlan_static_dhd_info_buf[index];
235     }
236 #if defined(BCMDHD_SDIO) || defined(BCMDHD_USB)
237     if (section == DHD_PREALLOC_DHD_WLFC_INFO) {
238         if (size > WLAN_DHD_WLFC_BUF_SIZE) {
239             DHD_STATIC_ERROR("request DHD_WLFC_INFO(%lu) > %d\n", size,
240                              WLAN_DHD_WLFC_BUF_SIZE);
241             return NULL;
242         }
243         return wlan_static_dhd_wlfc_info_buf[index];
244     }
245 #endif /* BCMDHD_SDIO | BCMDHD_USB */
246 #ifdef BCMDHD_PCIE
247     if (section == DHD_PREALLOC_IF_FLOW_LKUP) {
248         if (size > DHD_PREALLOC_IF_FLOW_LKUP_SIZE) {
249             DHD_STATIC_ERROR("request DHD_IF_FLOW_LKUP(%lu) > %d\n", size,
250                              DHD_PREALLOC_IF_FLOW_LKUP_SIZE);
251             return NULL;
252         }
253         return wlan_static_if_flow_lkup[index];
254     }
255 #endif /* BCMDHD_PCIE */
256 #if defined(CONFIG_BCMDHD_VTS) || defined(CONFIG_BCMDHD_DEBUG)
257     if (section == DHD_PREALLOC_MEMDUMP_RAM) {
258         if (size > DHD_PREALLOC_MEMDUMP_RAM_SIZE) {
259             DHD_STATIC_ERROR("request DHD_PREALLOC_MEMDUMP_RAM(%lu) > %d\n",
260                              size, DHD_PREALLOC_MEMDUMP_RAM_SIZE);
261             return NULL;
262         }
263         return wlan_static_dhd_memdump_ram_buf[index];
264     }
265 #endif /* CONFIG_BCMDHD_VTS | CONFIG_BCMDHD_DEBUG */
266 #if defined(BCMDHD_SDIO) || defined(BCMDHD_USB)
267     if (section == DHD_PREALLOC_DHD_WLFC_HANGER) {
268         if (size > DHD_PREALLOC_DHD_WLFC_HANGER_SIZE) {
269             DHD_STATIC_ERROR("request DHD_WLFC_HANGER(%lu) > %d\n", size,
270                              DHD_PREALLOC_DHD_WLFC_HANGER_SIZE);
271             return NULL;
272         }
273         return wlan_static_dhd_wlfc_hanger_buf[index];
274     }
275 #endif /* BCMDHD_SDIO | BCMDHD_USB */
276 #if defined(CONFIG_BCMDHD_VTS) || defined(CONFIG_BCMDHD_DEBUG)
277     if (section == DHD_PREALLOC_DHD_LOG_DUMP_BUF) {
278         if (size > DHD_PREALLOC_DHD_LOG_DUMP_BUF_SIZE) {
279             DHD_STATIC_ERROR(
280                 "request DHD_PREALLOC_DHD_LOG_DUMP_BUF(%lu) > %d\n", size,
281                 DHD_PREALLOC_DHD_LOG_DUMP_BUF_SIZE);
282             return NULL;
283         }
284         return wlan_static_dhd_log_dump_buf[index];
285     }
286     if (section == DHD_PREALLOC_DHD_LOG_DUMP_BUF_EX) {
287         if (size > DHD_PREALLOC_DHD_LOG_DUMP_BUF_EX_SIZE) {
288             DHD_STATIC_ERROR(
289                 "request DHD_PREALLOC_DHD_LOG_DUMP_BUF_EX(%lu) > %d\n", size,
290                 DHD_PREALLOC_DHD_LOG_DUMP_BUF_EX_SIZE);
291             return NULL;
292         }
293         return wlan_static_dhd_log_dump_buf_ex[index];
294     }
295 #endif /* CONFIG_BCMDHD_VTS | CONFIG_BCMDHD_DEBUG */
296     if (section == DHD_PREALLOC_WL_ESCAN) {
297         if (size > DHD_PREALLOC_WL_ESCAN_SIZE) {
298             DHD_STATIC_ERROR("request DHD_PREALLOC_WL_ESCAN(%lu) > %d\n", size,
299                              DHD_PREALLOC_WL_ESCAN_SIZE);
300             return NULL;
301         }
302         return wlan_static_wl_escan_info_buf[index];
303     }
304     if (section == DHD_PREALLOC_FW_VERBOSE_RING) {
305         if (size > FW_VERBOSE_RING_SIZE) {
306             DHD_STATIC_ERROR("request DHD_PREALLOC_FW_VERBOSE_RING(%lu) > %d\n",
307                              size, FW_VERBOSE_RING_SIZE);
308             return NULL;
309         }
310         return wlan_static_fw_verbose_ring_buf[index];
311     }
312     if (section == DHD_PREALLOC_FW_EVENT_RING) {
313         if (size > FW_EVENT_RING_SIZE) {
314             DHD_STATIC_ERROR("request DHD_PREALLOC_FW_EVENT_RING(%lu) > %d\n",
315                              size, FW_EVENT_RING_SIZE);
316             return NULL;
317         }
318         return wlan_static_fw_event_ring_buf[index];
319     }
320     if (section == DHD_PREALLOC_DHD_EVENT_RING) {
321         if (size > DHD_EVENT_RING_SIZE) {
322             DHD_STATIC_ERROR("request DHD_PREALLOC_DHD_EVENT_RING(%lu) > %d\n",
323                              size, DHD_EVENT_RING_SIZE);
324             return NULL;
325         }
326         return wlan_static_dhd_event_ring_buf[index];
327     }
328 #if defined(BCMDHD_UNUSE_MEM)
329     if (section == DHD_PREALLOC_NAN_EVENT_RING) {
330         if (size > NAN_EVENT_RING_SIZE) {
331             DHD_STATIC_ERROR("request DHD_PREALLOC_NAN_EVENT_RING(%lu) > %d\n",
332                              size, NAN_EVENT_RING_SIZE);
333             return NULL;
334         }
335         return wlan_static_nan_event_ring_buf[index];
336     }
337 #endif /* BCMDHD_UNUSE_MEM */
338     if ((section < 0) || (section > DHD_PREALLOC_MAX)) {
339         DHD_STATIC_ERROR("request section id(%d) is out of max index %d\n",
340                          section, DHD_PREALLOC_MAX);
341     }
342 
343     DHD_STATIC_ERROR("failed to alloc section %d, size=%ld\n", section, size);
344 
345     return NULL;
346 }
347 EXPORT_SYMBOL(dhd_wlan_mem_prealloc);
348 
dhd_deinit_wlan_mem(int index)349 static void dhd_deinit_wlan_mem(int index)
350 {
351 #if defined(BCMDHD_SDIO) || defined(BCMDHD_PCIE)
352     int i;
353 #endif /* BCMDHD_SDIO | BCMDHD_PCIE */
354 
355     if (wlan_static_prot[index]) {
356         kfree(wlan_static_prot[index]);
357     }
358 #if defined(BCMDHD_SDIO)
359     if (wlan_static_rxbuf[index]) {
360         kfree(wlan_static_rxbuf[index]);
361     }
362     if (wlan_static_databuf[index]) {
363         kfree(wlan_static_databuf[index]);
364     }
365 #endif /* BCMDHD_SDIO */
366     if (wlan_static_osl_buf[index]) {
367         kfree(wlan_static_osl_buf[index]);
368     }
369     if (wlan_static_scan_buf0[index]) {
370         kfree(wlan_static_scan_buf0[index]);
371     }
372     if (wlan_static_scan_buf1[index]) {
373         kfree(wlan_static_scan_buf1[index]);
374     }
375     if (wlan_static_dhd_info_buf[index]) {
376         kfree(wlan_static_dhd_info_buf[index]);
377     }
378 #if defined(BCMDHD_SDIO) || defined(BCMDHD_USB)
379     if (wlan_static_dhd_wlfc_info_buf[index]) {
380         kfree(wlan_static_dhd_wlfc_info_buf[index]);
381     }
382 #endif /* BCMDHD_SDIO | BCMDHD_USB */
383 #ifdef BCMDHD_PCIE
384     if (wlan_static_if_flow_lkup[index]) {
385         kfree(wlan_static_if_flow_lkup[index]);
386     }
387 #endif /* BCMDHD_PCIE */
388 #if defined(CONFIG_BCMDHD_VTS) || defined(CONFIG_BCMDHD_DEBUG)
389     if (wlan_static_dhd_memdump_ram_buf[index]) {
390         kfree(wlan_static_dhd_memdump_ram_buf[index]);
391     }
392 #endif /* CONFIG_BCMDHD_VTS | CONFIG_BCMDHD_DEBUG */
393 #if defined(BCMDHD_SDIO) || defined(BCMDHD_USB)
394     if (wlan_static_dhd_wlfc_hanger_buf[index]) {
395         kfree(wlan_static_dhd_wlfc_hanger_buf[index]);
396     }
397 #endif /* BCMDHD_SDIO | BCMDHD_USB */
398 #if defined(CONFIG_BCMDHD_VTS) || defined(CONFIG_BCMDHD_DEBUG)
399     if (wlan_static_dhd_log_dump_buf[index]) {
400         kfree(wlan_static_dhd_log_dump_buf[index]);
401     }
402     if (wlan_static_dhd_log_dump_buf_ex[index]) {
403         kfree(wlan_static_dhd_log_dump_buf_ex[index]);
404     }
405 #endif /* CONFIG_BCMDHD_VTS | CONFIG_BCMDHD_DEBUG */
406     if (wlan_static_wl_escan_info_buf[index]) {
407         kfree(wlan_static_wl_escan_info_buf[index]);
408     }
409     if (wlan_static_fw_verbose_ring_buf[index]) {
410         kfree(wlan_static_fw_verbose_ring_buf[index]);
411     }
412     if (wlan_static_fw_event_ring_buf[index]) {
413         kfree(wlan_static_fw_event_ring_buf[index]);
414     }
415     if (wlan_static_dhd_event_ring_buf[index]) {
416         kfree(wlan_static_dhd_event_ring_buf[index]);
417     }
418 #if defined(BCMDHD_UNUSE_MEM)
419     if (wlan_static_nan_event_ring_buf[index]) {
420         kfree(wlan_static_nan_event_ring_buf[index]);
421     }
422 #endif /* BCMDHD_UNUSE_MEM */
423 
424 #if defined(BCMDHD_SDIO) || defined(BCMDHD_PCIE)
425     for (i = 0; i < WLAN_SKB_BUF_NUM; i++) {
426         if (wlan_static_skb[index][i]) {
427             dev_kfree_skb(wlan_static_skb[index][i]);
428         }
429     }
430 #endif /* BCMDHD_SDIO | BCMDHD_PCIE */
431 
432     return;
433 }
434 
dhd_init_wlan_mem(int index)435 static int dhd_init_wlan_mem(int index)
436 {
437 #if defined(BCMDHD_SDIO) || defined(BCMDHD_PCIE)
438     int i;
439 #endif
440     unsigned long size = 0;
441 
442 #if defined(BCMDHD_SDIO) || defined(BCMDHD_PCIE)
443     for (i = 0; i < WLAN_SKB_BUF_NUM; i++) {
444         wlan_static_skb[index][i] = NULL;
445     }
446 
447     for (i = 0; i < DHD_SKB_1PAGE_BUF_NUM; i++) {
448         wlan_static_skb[index][i] = dev_alloc_skb(DHD_SKB_1PAGE_BUFSIZE);
449         if (!wlan_static_skb[index][i]) {
450             goto err_mem_alloc;
451         }
452         size += DHD_SKB_1PAGE_BUFSIZE;
453         DHD_STATIC_TRACE("sectoin %d skb[%d], size=%ld\n", DHD_PREALLOC_SKB_BUF,
454                          i, DHD_SKB_1PAGE_BUFSIZE);
455     }
456 
457     for (i = DHD_SKB_1PAGE_BUF_NUM; i < WLAN_SKB_1_2PAGE_BUF_NUM; i++) {
458         wlan_static_skb[index][i] = dev_alloc_skb(DHD_SKB_2PAGE_BUFSIZE);
459         if (!wlan_static_skb[index][i]) {
460             goto err_mem_alloc;
461         }
462         size += DHD_SKB_2PAGE_BUFSIZE;
463         DHD_STATIC_TRACE("sectoin %d skb[%d], size=%ld\n", DHD_PREALLOC_SKB_BUF,
464                          i, DHD_SKB_2PAGE_BUFSIZE);
465     }
466 #endif /* BCMDHD_SDIO | BCMDHD_PCIE */
467 
468 #if defined(BCMDHD_SDIO)
469     wlan_static_skb[index][i] = dev_alloc_skb(DHD_SKB_4PAGE_BUFSIZE);
470     if (!wlan_static_skb[index][i]) {
471         goto err_mem_alloc;
472     }
473     size += DHD_SKB_4PAGE_BUFSIZE;
474     DHD_STATIC_TRACE("sectoin %d skb[%d], size=%ld\n", DHD_PREALLOC_SKB_BUF, i,
475                      DHD_SKB_4PAGE_BUFSIZE);
476 #endif /* BCMDHD_SDIO */
477 
478     wlan_static_prot[index] = kmalloc(DHD_PREALLOC_PROT_SIZE, GFP_KERNEL);
479     if (!wlan_static_prot[index]) {
480         goto err_mem_alloc;
481     }
482     size += DHD_PREALLOC_PROT_SIZE;
483     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_PROT,
484                      DHD_PREALLOC_PROT_SIZE);
485 
486 #if defined(BCMDHD_SDIO)
487     wlan_static_rxbuf[index] = kmalloc(DHD_PREALLOC_RXBUF_SIZE, GFP_KERNEL);
488     if (!wlan_static_rxbuf[index]) {
489         goto err_mem_alloc;
490     }
491     size += DHD_PREALLOC_RXBUF_SIZE;
492     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_RXBUF,
493                      DHD_PREALLOC_RXBUF_SIZE);
494 
495     wlan_static_databuf[index] = kmalloc(DHD_PREALLOC_DATABUF_SIZE, GFP_KERNEL);
496     if (!wlan_static_databuf[index]) {
497         goto err_mem_alloc;
498     }
499     size += DHD_PREALLOC_DATABUF_SIZE;
500     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_DATABUF,
501                      DHD_PREALLOC_DATABUF_SIZE);
502 #endif /* BCMDHD_SDIO */
503 
504     wlan_static_osl_buf[index] = kmalloc(DHD_PREALLOC_OSL_BUF_SIZE, GFP_KERNEL);
505     if (!wlan_static_osl_buf[index]) {
506         goto err_mem_alloc;
507     }
508     size += DHD_PREALLOC_OSL_BUF_SIZE;
509     DHD_STATIC_TRACE("sectoin %d, size=%ld\n", DHD_PREALLOC_OSL_BUF,
510                      DHD_PREALLOC_OSL_BUF_SIZE);
511 
512     wlan_static_scan_buf0[index] =
513         kmalloc(DHD_PREALLOC_WIPHY_ESCAN0_SIZE, GFP_KERNEL);
514     if (!wlan_static_scan_buf0[index]) {
515         goto err_mem_alloc;
516     }
517     size += DHD_PREALLOC_WIPHY_ESCAN0_SIZE;
518     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_WIPHY_ESCAN0,
519                      DHD_PREALLOC_WIPHY_ESCAN0_SIZE);
520 
521     wlan_static_dhd_info_buf[index] =
522         kmalloc(DHD_PREALLOC_DHD_INFO_SIZE, GFP_KERNEL);
523     if (!wlan_static_dhd_info_buf[index]) {
524         goto err_mem_alloc;
525     }
526     size += DHD_PREALLOC_DHD_INFO_SIZE;
527     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_DHD_INFO,
528                      DHD_PREALLOC_DHD_INFO_SIZE);
529 
530 #if defined(BCMDHD_SDIO) || defined(BCMDHD_USB)
531     wlan_static_dhd_wlfc_info_buf[index] =
532         kmalloc(WLAN_DHD_WLFC_BUF_SIZE, GFP_KERNEL);
533     if (!wlan_static_dhd_wlfc_info_buf[index]) {
534         goto err_mem_alloc;
535     }
536     size += WLAN_DHD_WLFC_BUF_SIZE;
537     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_DHD_WLFC_INFO,
538                      WLAN_DHD_WLFC_BUF_SIZE);
539 #endif /* BCMDHD_SDIO | BCMDHD_USB */
540 
541 #ifdef BCMDHD_PCIE
542     wlan_static_if_flow_lkup[index] =
543         kmalloc(DHD_PREALLOC_IF_FLOW_LKUP_SIZE, GFP_KERNEL);
544     if (!wlan_static_if_flow_lkup[index]) {
545         goto err_mem_alloc;
546     }
547     size += DHD_PREALLOC_IF_FLOW_LKUP_SIZE;
548     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_IF_FLOW_LKUP,
549                      DHD_PREALLOC_IF_FLOW_LKUP_SIZE);
550 #endif /* BCMDHD_PCIE */
551 
552 #if defined(CONFIG_BCMDHD_VTS) || defined(CONFIG_BCMDHD_DEBUG)
553     wlan_static_dhd_memdump_ram_buf[index] =
554         kmalloc(DHD_PREALLOC_MEMDUMP_RAM_SIZE, GFP_KERNEL);
555     if (!wlan_static_dhd_memdump_ram_buf[index]) {
556         goto err_mem_alloc;
557     }
558     size += DHD_PREALLOC_MEMDUMP_RAM_SIZE;
559     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_MEMDUMP_RAM,
560                      DHD_PREALLOC_MEMDUMP_RAM_SIZE);
561 #endif /* CONFIG_BCMDHD_VTS | CONFIG_BCMDHD_DEBUG */
562 
563 #if defined(BCMDHD_SDIO) || defined(BCMDHD_USB)
564     wlan_static_dhd_wlfc_hanger_buf[index] =
565         kmalloc(DHD_PREALLOC_DHD_WLFC_HANGER_SIZE, GFP_KERNEL);
566     if (!wlan_static_dhd_wlfc_hanger_buf[index]) {
567         goto err_mem_alloc;
568     }
569     size += DHD_PREALLOC_DHD_WLFC_HANGER_SIZE;
570     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_DHD_WLFC_HANGER,
571                      DHD_PREALLOC_DHD_WLFC_HANGER_SIZE);
572 #endif /* BCMDHD_SDIO | BCMDHD_USB */
573 
574 #if defined(CONFIG_BCMDHD_VTS) || defined(CONFIG_BCMDHD_DEBUG)
575     wlan_static_dhd_log_dump_buf[index] =
576         kmalloc(DHD_PREALLOC_DHD_LOG_DUMP_BUF_SIZE, GFP_KERNEL);
577     if (!wlan_static_dhd_log_dump_buf[index]) {
578         goto err_mem_alloc;
579     }
580     size += DHD_PREALLOC_DHD_LOG_DUMP_BUF_SIZE;
581     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_DHD_LOG_DUMP_BUF,
582                      DHD_PREALLOC_DHD_LOG_DUMP_BUF_SIZE);
583 
584     wlan_static_dhd_log_dump_buf_ex[index] =
585         kmalloc(DHD_PREALLOC_DHD_LOG_DUMP_BUF_EX_SIZE, GFP_KERNEL);
586     if (!wlan_static_dhd_log_dump_buf_ex[index]) {
587         goto err_mem_alloc;
588     }
589     size += DHD_PREALLOC_DHD_LOG_DUMP_BUF_EX_SIZE;
590     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_DHD_LOG_DUMP_BUF_EX,
591                      DHD_PREALLOC_DHD_LOG_DUMP_BUF_EX_SIZE);
592 #endif /* CONFIG_BCMDHD_VTS | CONFIG_BCMDHD_DEBUG */
593 
594     wlan_static_wl_escan_info_buf[index] =
595         kmalloc(DHD_PREALLOC_WL_ESCAN_SIZE, GFP_KERNEL);
596     if (!wlan_static_wl_escan_info_buf[index]) {
597         goto err_mem_alloc;
598     }
599     size += DHD_PREALLOC_WL_ESCAN_SIZE;
600     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_WL_ESCAN,
601                      DHD_PREALLOC_WL_ESCAN_SIZE);
602 
603     wlan_static_fw_verbose_ring_buf[index] =
604         kmalloc(FW_VERBOSE_RING_SIZE, GFP_KERNEL);
605     if (!wlan_static_fw_verbose_ring_buf[index]) {
606         goto err_mem_alloc;
607     }
608     size += FW_VERBOSE_RING_SIZE;
609     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_FW_VERBOSE_RING,
610                      FW_VERBOSE_RING_SIZE);
611 
612     wlan_static_fw_event_ring_buf[index] =
613         kmalloc(FW_EVENT_RING_SIZE, GFP_KERNEL);
614     if (!wlan_static_fw_event_ring_buf[index]) {
615         goto err_mem_alloc;
616     }
617     size += FW_EVENT_RING_SIZE;
618     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_FW_EVENT_RING,
619                      FW_EVENT_RING_SIZE);
620 
621     wlan_static_dhd_event_ring_buf[index] =
622         kmalloc(DHD_EVENT_RING_SIZE, GFP_KERNEL);
623     if (!wlan_static_dhd_event_ring_buf[index]) {
624         goto err_mem_alloc;
625     }
626     size += DHD_EVENT_RING_SIZE;
627     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_DHD_EVENT_RING,
628                      DHD_EVENT_RING_SIZE);
629 
630 #if defined(BCMDHD_UNUSE_MEM)
631     wlan_static_nan_event_ring_buf[index] =
632         kmalloc(NAN_EVENT_RING_SIZE, GFP_KERNEL);
633     if (!wlan_static_nan_event_ring_buf[index]) {
634         goto err_mem_alloc;
635     }
636     size += NAN_EVENT_RING_SIZE;
637     DHD_STATIC_TRACE("sectoin %d, size=%d\n", DHD_PREALLOC_NAN_EVENT_RING,
638                      NAN_EVENT_RING_SIZE);
639 #endif /* BCMDHD_UNUSE_MEM */
640 
641     DHD_STATIC_MSG("prealloc ok for index %d: %ld(%ldK)\n", index, size,
642                    size / 1024);
643     return 0;
644 
645 err_mem_alloc:
646     DHD_STATIC_ERROR("Failed to allocate memory for index %d\n", index);
647 
648     return -ENOMEM;
649 }
650 
651 #ifdef DHD_STATIC_IN_DRIVER
652 int
653 #else
654 static int __init
655 #endif
dhd_static_buf_init(void)656 dhd_static_buf_init(void)
657 {
658     int i, ret = 0;
659 
660     DHD_STATIC_MSG("%s\n", DHD_STATIC_VERSION_STR);
661 
662     for (i = 0; i < MAX_NUM_ADAPTERS; i++) {
663         ret = dhd_init_wlan_mem(i);
664         if (ret) {
665             break;
666         }
667     }
668 
669     if (ret) {
670         for (i = 0; i < MAX_NUM_ADAPTERS; i++) {
671             dhd_deinit_wlan_mem(i);
672         }
673     }
674 
675     return 0;
676 }
677 
678 #ifdef DHD_STATIC_IN_DRIVER
679 void
680 #else
681 static void __exit
682 #endif
dhd_static_buf_exit(void)683 dhd_static_buf_exit(void)
684 {
685     int i;
686 
687     DHD_STATIC_MSG("Enter\n");
688 
689     for (i = 0; i < MAX_NUM_ADAPTERS; i++) {
690         dhd_deinit_wlan_mem(i);
691     }
692 }
693 
694 #ifndef DHD_STATIC_IN_DRIVER
695 module_init(dhd_static_buf_init);
696 module_exit(dhd_static_buf_exit);
697 #endif
698