1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Platform Dependent file for usage of Preallocted Memory
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Portions of this code are copyright (c) 2021 Cypress Semiconductor Corporation
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 1999-2017, Broadcom Corporation
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Unless you and Broadcom execute a separate written software license
9*4882a593Smuzhiyun * agreement governing use of this software, this software is licensed to you
10*4882a593Smuzhiyun * under the terms of the GNU General Public License version 2 (the "GPL"),
11*4882a593Smuzhiyun * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12*4882a593Smuzhiyun * following added to such license:
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * As a special exception, the copyright holders of this software give you
15*4882a593Smuzhiyun * permission to link this software with independent modules, and to copy and
16*4882a593Smuzhiyun * distribute the resulting executable under terms of your choice, provided that
17*4882a593Smuzhiyun * you also meet, for each linked independent module, the terms and conditions of
18*4882a593Smuzhiyun * the license of that module. An independent module is a module which is not
19*4882a593Smuzhiyun * derived from this software. The special exception does not apply to any
20*4882a593Smuzhiyun * modifications of the software.
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * Notwithstanding the above, under no circumstances may you combine this
23*4882a593Smuzhiyun * software in any way with any other Broadcom software provided under a license
24*4882a593Smuzhiyun * other than the GPL, without Broadcom's express prior written consent.
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun * <<Broadcom-WL-IPTag/Open:>>
27*4882a593Smuzhiyun *
28*4882a593Smuzhiyun * $Id: dhd_custom_memprealloc.c 695148 2017-04-19 04:15:17Z $
29*4882a593Smuzhiyun */
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #include <linux/device.h>
32*4882a593Smuzhiyun #include <linux/slab.h>
33*4882a593Smuzhiyun #include <linux/miscdevice.h>
34*4882a593Smuzhiyun #include <linux/sched.h>
35*4882a593Smuzhiyun #include <linux/module.h>
36*4882a593Smuzhiyun #include <linux/fs.h>
37*4882a593Smuzhiyun #include <linux/list.h>
38*4882a593Smuzhiyun #include <linux/io.h>
39*4882a593Smuzhiyun #include <linux/workqueue.h>
40*4882a593Smuzhiyun #include <linux/unistd.h>
41*4882a593Smuzhiyun #include <linux/bug.h>
42*4882a593Smuzhiyun #include <linux/skbuff.h>
43*4882a593Smuzhiyun #include <linux/init.h>
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun #ifdef CONFIG_BROADCOM_WIFI_RESERVED_MEM
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun #define WLAN_STATIC_SCAN_BUF0 5
48*4882a593Smuzhiyun #define WLAN_STATIC_SCAN_BUF1 6
49*4882a593Smuzhiyun #define WLAN_STATIC_DHD_INFO_BUF 7
50*4882a593Smuzhiyun #define WLAN_STATIC_DHD_WLFC_BUF 8
51*4882a593Smuzhiyun #define WLAN_STATIC_DHD_IF_FLOW_LKUP 9
52*4882a593Smuzhiyun #define WLAN_STATIC_DHD_MEMDUMP_RAM 11
53*4882a593Smuzhiyun #define WLAN_STATIC_DHD_WLFC_HANGER 12
54*4882a593Smuzhiyun #define WLAN_STATIC_DHD_PKTID_MAP 13
55*4882a593Smuzhiyun #define WLAN_STATIC_DHD_PKTID_IOCTL_MAP 14
56*4882a593Smuzhiyun #define WLAN_STATIC_DHD_LOG_DUMP_BUF 15
57*4882a593Smuzhiyun #define WLAN_STATIC_DHD_LOG_DUMP_BUF_EX 16
58*4882a593Smuzhiyun #define WLAN_STATIC_DHD_PKTLOG_DUMP_BUF 17
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun #define WLAN_SCAN_BUF_SIZE (64 * 1024)
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun #if defined(CONFIG_64BIT)
63*4882a593Smuzhiyun #define WLAN_DHD_INFO_BUF_SIZE (32 * 1024)
64*4882a593Smuzhiyun #define WLAN_DHD_WLFC_BUF_SIZE (64 * 1024)
65*4882a593Smuzhiyun #define WLAN_DHD_IF_FLOW_LKUP_SIZE (64 * 1024)
66*4882a593Smuzhiyun #else
67*4882a593Smuzhiyun #define WLAN_DHD_INFO_BUF_SIZE (32 * 1024)
68*4882a593Smuzhiyun #define WLAN_DHD_WLFC_BUF_SIZE (16 * 1024)
69*4882a593Smuzhiyun #define WLAN_DHD_IF_FLOW_LKUP_SIZE (20 * 1024)
70*4882a593Smuzhiyun #endif /* CONFIG_64BIT */
71*4882a593Smuzhiyun /* Have 2MB ramsize to accomodate future chips */
72*4882a593Smuzhiyun #define WLAN_DHD_MEMDUMP_SIZE (2048 * 1024)
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun #define PREALLOC_WLAN_SEC_NUM 4
75*4882a593Smuzhiyun #define PREALLOC_WLAN_BUF_NUM 160
76*4882a593Smuzhiyun #define PREALLOC_WLAN_SECTION_HEADER 24
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun #ifdef CONFIG_BCMDHD_PCIE
79*4882a593Smuzhiyun #define DHD_SKB_1PAGE_BUFSIZE (PAGE_SIZE*1)
80*4882a593Smuzhiyun #define DHD_SKB_2PAGE_BUFSIZE (PAGE_SIZE*2)
81*4882a593Smuzhiyun #define DHD_SKB_4PAGE_BUFSIZE (PAGE_SIZE*4)
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun #define WLAN_SECTION_SIZE_0 (PREALLOC_WLAN_BUF_NUM * 128)
84*4882a593Smuzhiyun #define WLAN_SECTION_SIZE_1 0
85*4882a593Smuzhiyun #define WLAN_SECTION_SIZE_2 0
86*4882a593Smuzhiyun #define WLAN_SECTION_SIZE_3 (PREALLOC_WLAN_BUF_NUM * 1024)
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun #define DHD_SKB_1PAGE_BUF_NUM 0
89*4882a593Smuzhiyun #define DHD_SKB_2PAGE_BUF_NUM 128
90*4882a593Smuzhiyun #define DHD_SKB_4PAGE_BUF_NUM 0
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun #else
93*4882a593Smuzhiyun #define DHD_SKB_HDRSIZE 336
94*4882a593Smuzhiyun #define DHD_SKB_1PAGE_BUFSIZE ((PAGE_SIZE*1)-DHD_SKB_HDRSIZE)
95*4882a593Smuzhiyun #define DHD_SKB_2PAGE_BUFSIZE ((PAGE_SIZE*2)-DHD_SKB_HDRSIZE)
96*4882a593Smuzhiyun #define DHD_SKB_4PAGE_BUFSIZE ((PAGE_SIZE*4)-DHD_SKB_HDRSIZE)
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun #define WLAN_SECTION_SIZE_0 (PREALLOC_WLAN_BUF_NUM * 128)
99*4882a593Smuzhiyun #define WLAN_SECTION_SIZE_1 (PREALLOC_WLAN_BUF_NUM * 128)
100*4882a593Smuzhiyun #define WLAN_SECTION_SIZE_2 (PREALLOC_WLAN_BUF_NUM * 512)
101*4882a593Smuzhiyun #define WLAN_SECTION_SIZE_3 (PREALLOC_WLAN_BUF_NUM * 1024)
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun #define DHD_SKB_1PAGE_BUF_NUM 8
104*4882a593Smuzhiyun #define DHD_SKB_2PAGE_BUF_NUM 8
105*4882a593Smuzhiyun #define DHD_SKB_4PAGE_BUF_NUM 1
106*4882a593Smuzhiyun #endif /* CONFIG_BCMDHD_PCIE */
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun #define WLAN_SKB_1_2PAGE_BUF_NUM ((DHD_SKB_1PAGE_BUF_NUM) + \
109*4882a593Smuzhiyun (DHD_SKB_2PAGE_BUF_NUM))
110*4882a593Smuzhiyun #define WLAN_SKB_BUF_NUM ((WLAN_SKB_1_2PAGE_BUF_NUM) + \
111*4882a593Smuzhiyun (DHD_SKB_4PAGE_BUF_NUM))
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun #define WLAN_MAX_PKTID_ITEMS (8192)
114*4882a593Smuzhiyun #define WLAN_DHD_PKTID_MAP_HDR_SIZE (20 + 4*(WLAN_MAX_PKTID_ITEMS + 1))
115*4882a593Smuzhiyun #define WLAN_DHD_PKTID_MAP_ITEM_SIZE (32)
116*4882a593Smuzhiyun #define WLAN_DHD_PKTID_MAP_SIZE ((WLAN_DHD_PKTID_MAP_HDR_SIZE) + \
117*4882a593Smuzhiyun ((WLAN_MAX_PKTID_ITEMS+1) * WLAN_DHD_PKTID_MAP_ITEM_SIZE))
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun #define WLAN_MAX_PKTID_IOCTL_ITEMS (32)
120*4882a593Smuzhiyun #define WLAN_DHD_PKTID_IOCTL_MAP_HDR_SIZE (20 + 4*(WLAN_MAX_PKTID_IOCTL_ITEMS + 1))
121*4882a593Smuzhiyun #define WLAN_DHD_PKTID_IOCTL_MAP_ITEM_SIZE (32)
122*4882a593Smuzhiyun #define WLAN_DHD_PKTID_IOCTL_MAP_SIZE ((WLAN_DHD_PKTID_IOCTL_MAP_HDR_SIZE) + \
123*4882a593Smuzhiyun ((WLAN_MAX_PKTID_IOCTL_ITEMS+1) * WLAN_DHD_PKTID_IOCTL_MAP_ITEM_SIZE))
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun #define DHD_LOG_DUMP_BUF_SIZE (1024 * 1024 * 4)
126*4882a593Smuzhiyun #define DHD_LOG_DUMP_BUF_EX_SIZE (1024 * 1024 * 4)
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun #define DHD_PKTLOG_DUMP_BUF_SIZE (64 * 1024)
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun #define WLAN_DHD_WLFC_HANGER_MAXITEMS 3072
131*4882a593Smuzhiyun #define WLAN_DHD_WLFC_HANGER_ITEM_SIZE 32
132*4882a593Smuzhiyun #define WLAN_DHD_WLFC_HANGER_SIZE ((WLAN_DHD_WLFC_HANGER_ITEM_SIZE) + \
133*4882a593Smuzhiyun ((WLAN_DHD_WLFC_HANGER_MAXITEMS) * (WLAN_DHD_WLFC_HANGER_ITEM_SIZE)))
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun struct wlan_mem_prealloc {
138*4882a593Smuzhiyun void *mem_ptr;
139*4882a593Smuzhiyun unsigned long size;
140*4882a593Smuzhiyun };
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun static struct wlan_mem_prealloc wlan_mem_array[PREALLOC_WLAN_SEC_NUM] = {
143*4882a593Smuzhiyun {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
144*4882a593Smuzhiyun {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
145*4882a593Smuzhiyun {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
146*4882a593Smuzhiyun {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)}
147*4882a593Smuzhiyun };
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun static void *wlan_static_scan_buf0 = NULL;
150*4882a593Smuzhiyun static void *wlan_static_scan_buf1 = NULL;
151*4882a593Smuzhiyun static void *wlan_static_dhd_info_buf = NULL;
152*4882a593Smuzhiyun static void *wlan_static_dhd_wlfc_buf = NULL;
153*4882a593Smuzhiyun static void *wlan_static_if_flow_lkup = NULL;
154*4882a593Smuzhiyun static void *wlan_static_dhd_memdump_ram = NULL;
155*4882a593Smuzhiyun static void *wlan_static_dhd_wlfc_hanger = NULL;
156*4882a593Smuzhiyun static void *wlan_static_dhd_pktid_map = NULL;
157*4882a593Smuzhiyun static void *wlan_static_dhd_pktid_ioctl_map = NULL;
158*4882a593Smuzhiyun static void *wlan_static_dhd_log_dump_buf = NULL;
159*4882a593Smuzhiyun static void *wlan_static_dhd_log_dump_buf_ex = NULL;
160*4882a593Smuzhiyun static void *wlan_static_dhd_pktlog_dump_buf = NULL;
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun void
dhd_wlan_mem_prealloc(int section,unsigned long size)163*4882a593Smuzhiyun *dhd_wlan_mem_prealloc(int section, unsigned long size)
164*4882a593Smuzhiyun {
165*4882a593Smuzhiyun if (section == PREALLOC_WLAN_SEC_NUM) {
166*4882a593Smuzhiyun return wlan_static_skb;
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun if (section == WLAN_STATIC_SCAN_BUF0) {
170*4882a593Smuzhiyun return wlan_static_scan_buf0;
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun if (section == WLAN_STATIC_SCAN_BUF1) {
174*4882a593Smuzhiyun return wlan_static_scan_buf1;
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun if (section == WLAN_STATIC_DHD_INFO_BUF) {
178*4882a593Smuzhiyun if (size > WLAN_DHD_INFO_BUF_SIZE) {
179*4882a593Smuzhiyun pr_err("request DHD_INFO size(%lu) is bigger than"
180*4882a593Smuzhiyun " static size(%d).\n", size,
181*4882a593Smuzhiyun WLAN_DHD_INFO_BUF_SIZE);
182*4882a593Smuzhiyun return NULL;
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun return wlan_static_dhd_info_buf;
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun if (section == WLAN_STATIC_DHD_WLFC_BUF) {
188*4882a593Smuzhiyun if (size > WLAN_DHD_WLFC_BUF_SIZE) {
189*4882a593Smuzhiyun pr_err("request DHD_WLFC size(%lu) is bigger than"
190*4882a593Smuzhiyun " static size(%d).\n",
191*4882a593Smuzhiyun size, WLAN_DHD_WLFC_BUF_SIZE);
192*4882a593Smuzhiyun return NULL;
193*4882a593Smuzhiyun }
194*4882a593Smuzhiyun return wlan_static_dhd_wlfc_buf;
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun if (section == WLAN_STATIC_DHD_WLFC_HANGER) {
198*4882a593Smuzhiyun if (size > WLAN_DHD_WLFC_HANGER_SIZE) {
199*4882a593Smuzhiyun pr_err("request DHD_WLFC_HANGER size(%lu) is bigger than"
200*4882a593Smuzhiyun " static size(%d).\n",
201*4882a593Smuzhiyun size, WLAN_DHD_WLFC_HANGER_SIZE);
202*4882a593Smuzhiyun return NULL;
203*4882a593Smuzhiyun }
204*4882a593Smuzhiyun return wlan_static_dhd_wlfc_hanger;
205*4882a593Smuzhiyun }
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun if (section == WLAN_STATIC_DHD_IF_FLOW_LKUP) {
208*4882a593Smuzhiyun if (size > WLAN_DHD_IF_FLOW_LKUP_SIZE) {
209*4882a593Smuzhiyun pr_err("request DHD_WLFC size(%lu) is bigger than"
210*4882a593Smuzhiyun " static size(%d).\n",
211*4882a593Smuzhiyun size, WLAN_DHD_WLFC_BUF_SIZE);
212*4882a593Smuzhiyun return NULL;
213*4882a593Smuzhiyun }
214*4882a593Smuzhiyun return wlan_static_if_flow_lkup;
215*4882a593Smuzhiyun }
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun if (section == WLAN_STATIC_DHD_MEMDUMP_RAM) {
218*4882a593Smuzhiyun if (size > WLAN_DHD_MEMDUMP_SIZE) {
219*4882a593Smuzhiyun pr_err("request DHD_MEMDUMP_RAM size(%lu) is bigger"
220*4882a593Smuzhiyun " than static size(%d).\n",
221*4882a593Smuzhiyun size, WLAN_DHD_MEMDUMP_SIZE);
222*4882a593Smuzhiyun return NULL;
223*4882a593Smuzhiyun }
224*4882a593Smuzhiyun return wlan_static_dhd_memdump_ram;
225*4882a593Smuzhiyun }
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun if (section == WLAN_STATIC_DHD_PKTID_MAP) {
228*4882a593Smuzhiyun if (size > WLAN_DHD_PKTID_MAP_SIZE) {
229*4882a593Smuzhiyun pr_err("request DHD_PKTID_MAP size(%lu) is bigger than"
230*4882a593Smuzhiyun " static size(%d).\n",
231*4882a593Smuzhiyun size, WLAN_DHD_PKTID_MAP_SIZE);
232*4882a593Smuzhiyun return NULL;
233*4882a593Smuzhiyun }
234*4882a593Smuzhiyun return wlan_static_dhd_pktid_map;
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun if (section == WLAN_STATIC_DHD_PKTID_IOCTL_MAP) {
238*4882a593Smuzhiyun if (size > WLAN_DHD_PKTID_IOCTL_MAP_SIZE) {
239*4882a593Smuzhiyun pr_err("request DHD_PKTID_IOCTL_MAP size(%lu) is bigger than"
240*4882a593Smuzhiyun " static size(%d).\n",
241*4882a593Smuzhiyun size, WLAN_DHD_PKTID_IOCTL_MAP_SIZE);
242*4882a593Smuzhiyun return NULL;
243*4882a593Smuzhiyun }
244*4882a593Smuzhiyun return wlan_static_dhd_pktid_ioctl_map;
245*4882a593Smuzhiyun }
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun if (section == WLAN_STATIC_DHD_LOG_DUMP_BUF) {
248*4882a593Smuzhiyun if (size > DHD_LOG_DUMP_BUF_SIZE) {
249*4882a593Smuzhiyun pr_err("request DHD_LOG_DUMP_BUF size(%lu) is bigger then"
250*4882a593Smuzhiyun " static size(%d).\n",
251*4882a593Smuzhiyun size, DHD_LOG_DUMP_BUF_SIZE);
252*4882a593Smuzhiyun return NULL;
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun return wlan_static_dhd_log_dump_buf;
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun if (section == WLAN_STATIC_DHD_LOG_DUMP_BUF_EX) {
258*4882a593Smuzhiyun if (size > DHD_LOG_DUMP_BUF_EX_SIZE) {
259*4882a593Smuzhiyun pr_err("request DHD_LOG_DUMP_BUF_EX size(%lu) is bigger then"
260*4882a593Smuzhiyun " static size(%d).\n",
261*4882a593Smuzhiyun size, DHD_LOG_DUMP_BUF_EX_SIZE);
262*4882a593Smuzhiyun return NULL;
263*4882a593Smuzhiyun }
264*4882a593Smuzhiyun return wlan_static_dhd_log_dump_buf_ex;
265*4882a593Smuzhiyun }
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun if (section == WLAN_STATIC_DHD_PKTLOG_DUMP_BUF) {
268*4882a593Smuzhiyun if (size > DHD_PKTLOG_DUMP_BUF_SIZE) {
269*4882a593Smuzhiyun pr_err("request DHD_PKTLOG_DUMP_BUF size(%lu) is bigger then"
270*4882a593Smuzhiyun " static size(%d).\n",
271*4882a593Smuzhiyun size, DHD_PKTLOG_DUMP_BUF_SIZE);
272*4882a593Smuzhiyun return NULL;
273*4882a593Smuzhiyun }
274*4882a593Smuzhiyun return wlan_static_dhd_pktlog_dump_buf;
275*4882a593Smuzhiyun }
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun if ((section < 0) || (section >= PREALLOC_WLAN_SEC_NUM)) {
278*4882a593Smuzhiyun return NULL;
279*4882a593Smuzhiyun }
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun if (wlan_mem_array[section].size < size) {
282*4882a593Smuzhiyun return NULL;
283*4882a593Smuzhiyun }
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun return wlan_mem_array[section].mem_ptr;
286*4882a593Smuzhiyun }
287*4882a593Smuzhiyun EXPORT_SYMBOL(dhd_wlan_mem_prealloc);
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun int
dhd_init_wlan_mem(void)290*4882a593Smuzhiyun dhd_init_wlan_mem(void)
291*4882a593Smuzhiyun {
292*4882a593Smuzhiyun int i;
293*4882a593Smuzhiyun int j;
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun #if !defined(CONFIG_BCMDHD_PCIE)
296*4882a593Smuzhiyun for (i = 0; i < DHD_SKB_1PAGE_BUF_NUM; i++) {
297*4882a593Smuzhiyun wlan_static_skb[i] = __dev_alloc_skb(DHD_SKB_1PAGE_BUFSIZE, GFP_KERNEL);
298*4882a593Smuzhiyun if (!wlan_static_skb[i]) {
299*4882a593Smuzhiyun goto err_skb_alloc;
300*4882a593Smuzhiyun }
301*4882a593Smuzhiyun }
302*4882a593Smuzhiyun #endif /* !CONFIG_BCMDHD_PCIE */
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun for (i = DHD_SKB_1PAGE_BUF_NUM; i < WLAN_SKB_1_2PAGE_BUF_NUM; i++) {
305*4882a593Smuzhiyun wlan_static_skb[i] = __dev_alloc_skb(DHD_SKB_2PAGE_BUFSIZE, GFP_KERNEL);
306*4882a593Smuzhiyun if (!wlan_static_skb[i]) {
307*4882a593Smuzhiyun goto err_skb_alloc;
308*4882a593Smuzhiyun }
309*4882a593Smuzhiyun }
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun #if !defined(CONFIG_BCMDHD_PCIE)
312*4882a593Smuzhiyun wlan_static_skb[i] = __dev_alloc_skb(DHD_SKB_4PAGE_BUFSIZE, GFP_KERNEL);
313*4882a593Smuzhiyun if (!wlan_static_skb[i]) {
314*4882a593Smuzhiyun goto err_skb_alloc;
315*4882a593Smuzhiyun }
316*4882a593Smuzhiyun #endif /* !CONFIG_BCMDHD_PCIE */
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun for (i = 0; i < PREALLOC_WLAN_SEC_NUM; i++) {
319*4882a593Smuzhiyun if (wlan_mem_array[i].size > 0) {
320*4882a593Smuzhiyun wlan_mem_array[i].mem_ptr =
321*4882a593Smuzhiyun kmalloc(wlan_mem_array[i].size, GFP_KERNEL);
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun if (!wlan_mem_array[i].mem_ptr) {
324*4882a593Smuzhiyun goto err_mem_alloc;
325*4882a593Smuzhiyun }
326*4882a593Smuzhiyun }
327*4882a593Smuzhiyun }
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun wlan_static_scan_buf0 = kmalloc(WLAN_SCAN_BUF_SIZE, GFP_KERNEL);
330*4882a593Smuzhiyun if (!wlan_static_scan_buf0) {
331*4882a593Smuzhiyun pr_err("Failed to alloc wlan_static_scan_buf0\n");
332*4882a593Smuzhiyun goto err_mem_alloc;
333*4882a593Smuzhiyun }
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun wlan_static_scan_buf1 = kmalloc(WLAN_SCAN_BUF_SIZE, GFP_KERNEL);
336*4882a593Smuzhiyun if (!wlan_static_scan_buf1) {
337*4882a593Smuzhiyun pr_err("Failed to alloc wlan_static_scan_buf1\n");
338*4882a593Smuzhiyun goto err_mem_alloc;
339*4882a593Smuzhiyun }
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun wlan_static_dhd_log_dump_buf = kmalloc(DHD_LOG_DUMP_BUF_SIZE, GFP_KERNEL);
342*4882a593Smuzhiyun if (!wlan_static_dhd_log_dump_buf) {
343*4882a593Smuzhiyun pr_err("Failed to alloc wlan_static_dhd_log_dump_buf\n");
344*4882a593Smuzhiyun goto err_mem_alloc;
345*4882a593Smuzhiyun }
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun wlan_static_dhd_log_dump_buf_ex = kmalloc(DHD_LOG_DUMP_BUF_EX_SIZE, GFP_KERNEL);
348*4882a593Smuzhiyun if (!wlan_static_dhd_log_dump_buf_ex) {
349*4882a593Smuzhiyun pr_err("Failed to alloc wlan_static_dhd_log_dump_buf_ex\n");
350*4882a593Smuzhiyun goto err_mem_alloc;
351*4882a593Smuzhiyun }
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun wlan_static_dhd_info_buf = kmalloc(WLAN_DHD_INFO_BUF_SIZE, GFP_KERNEL);
354*4882a593Smuzhiyun if (!wlan_static_dhd_info_buf) {
355*4882a593Smuzhiyun pr_err("Failed to alloc wlan_static_dhd_info_buf\n");
356*4882a593Smuzhiyun goto err_mem_alloc;
357*4882a593Smuzhiyun }
358*4882a593Smuzhiyun
359*4882a593Smuzhiyun #ifdef CONFIG_BCMDHD_PCIE
360*4882a593Smuzhiyun wlan_static_if_flow_lkup = kmalloc(WLAN_DHD_IF_FLOW_LKUP_SIZE,
361*4882a593Smuzhiyun GFP_KERNEL);
362*4882a593Smuzhiyun if (!wlan_static_if_flow_lkup) {
363*4882a593Smuzhiyun pr_err("Failed to alloc wlan_static_if_flow_lkup\n");
364*4882a593Smuzhiyun goto err_mem_alloc;
365*4882a593Smuzhiyun }
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun #ifdef CONFIG_BCMDHD_PREALLOC_PKTIDMAP
368*4882a593Smuzhiyun wlan_static_dhd_pktid_map = kmalloc(WLAN_DHD_PKTID_MAP_SIZE,
369*4882a593Smuzhiyun GFP_KERNEL);
370*4882a593Smuzhiyun if (!wlan_static_dhd_pktid_map) {
371*4882a593Smuzhiyun pr_err("Failed to alloc wlan_static_dhd_pktid_map\n");
372*4882a593Smuzhiyun goto err_mem_alloc;
373*4882a593Smuzhiyun }
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun wlan_static_dhd_pktid_ioctl_map = kmalloc(WLAN_DHD_PKTID_IOCTL_MAP_SIZE,
376*4882a593Smuzhiyun GFP_KERNEL);
377*4882a593Smuzhiyun if (!wlan_static_dhd_pktid_ioctl_map) {
378*4882a593Smuzhiyun pr_err("Failed to alloc wlan_static_dhd_pktid_ioctl_map\n");
379*4882a593Smuzhiyun goto err_mem_alloc;
380*4882a593Smuzhiyun }
381*4882a593Smuzhiyun #endif /* CONFIG_BCMDHD_PREALLOC_PKTIDMAP */
382*4882a593Smuzhiyun #else
383*4882a593Smuzhiyun wlan_static_dhd_wlfc_buf = kmalloc(WLAN_DHD_WLFC_BUF_SIZE,
384*4882a593Smuzhiyun GFP_KERNEL);
385*4882a593Smuzhiyun if (!wlan_static_dhd_wlfc_buf) {
386*4882a593Smuzhiyun pr_err("Failed to alloc wlan_static_dhd_wlfc_buf\n");
387*4882a593Smuzhiyun goto err_mem_alloc;
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun wlan_static_dhd_wlfc_hanger = kmalloc(WLAN_DHD_WLFC_HANGER_SIZE,
391*4882a593Smuzhiyun GFP_KERNEL);
392*4882a593Smuzhiyun if (!wlan_static_dhd_wlfc_hanger) {
393*4882a593Smuzhiyun pr_err("Failed to alloc wlan_static_dhd_wlfc_hanger\n");
394*4882a593Smuzhiyun goto err_mem_alloc;
395*4882a593Smuzhiyun }
396*4882a593Smuzhiyun #endif /* CONFIG_BCMDHD_PCIE */
397*4882a593Smuzhiyun
398*4882a593Smuzhiyun #ifdef CONFIG_BCMDHD_PREALLOC_MEMDUMP
399*4882a593Smuzhiyun wlan_static_dhd_memdump_ram = kmalloc(WLAN_DHD_MEMDUMP_SIZE, GFP_KERNEL);
400*4882a593Smuzhiyun if (!wlan_static_dhd_memdump_ram) {
401*4882a593Smuzhiyun pr_err("Failed to alloc wlan_static_dhd_memdump_ram\n");
402*4882a593Smuzhiyun goto err_mem_alloc;
403*4882a593Smuzhiyun }
404*4882a593Smuzhiyun #endif /* CONFIG_BCMDHD_PREALLOC_MEMDUMP */
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun wlan_static_dhd_pktlog_dump_buf = kmalloc(DHD_PKTLOG_DUMP_BUF_SIZE, GFP_KERNEL);
407*4882a593Smuzhiyun if (!wlan_static_dhd_pktlog_dump_buf) {
408*4882a593Smuzhiyun pr_err("Failed to alloc wlan_static_dhd_pktlog_dump_buf\n");
409*4882a593Smuzhiyun goto err_mem_alloc;
410*4882a593Smuzhiyun }
411*4882a593Smuzhiyun
412*4882a593Smuzhiyun pr_err("%s: WIFI MEM Allocated\n", __FUNCTION__);
413*4882a593Smuzhiyun return 0;
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun err_mem_alloc:
416*4882a593Smuzhiyun #ifdef CONFIG_BCMDHD_PREALLOC_MEMDUMP
417*4882a593Smuzhiyun if (wlan_static_dhd_memdump_ram) {
418*4882a593Smuzhiyun kfree(wlan_static_dhd_memdump_ram);
419*4882a593Smuzhiyun }
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun #endif /* CONFIG_BCMDHD_PREALLOC_MEMDUMP */
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun #ifdef CONFIG_BCMDHD_PCIE
424*4882a593Smuzhiyun if (wlan_static_if_flow_lkup) {
425*4882a593Smuzhiyun kfree(wlan_static_if_flow_lkup);
426*4882a593Smuzhiyun }
427*4882a593Smuzhiyun
428*4882a593Smuzhiyun #ifdef CONFIG_BCMDHD_PREALLOC_PKTIDMAP
429*4882a593Smuzhiyun if (wlan_static_dhd_pktid_map) {
430*4882a593Smuzhiyun kfree(wlan_static_dhd_pktid_map);
431*4882a593Smuzhiyun }
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun if (wlan_static_dhd_pktid_ioctl_map) {
434*4882a593Smuzhiyun kfree(wlan_static_dhd_pktid_ioctl_map);
435*4882a593Smuzhiyun }
436*4882a593Smuzhiyun #endif /* CONFIG_BCMDHD_PREALLOC_PKTIDMAP */
437*4882a593Smuzhiyun #else
438*4882a593Smuzhiyun if (wlan_static_dhd_wlfc_buf) {
439*4882a593Smuzhiyun kfree(wlan_static_dhd_wlfc_buf);
440*4882a593Smuzhiyun }
441*4882a593Smuzhiyun
442*4882a593Smuzhiyun if (wlan_static_dhd_wlfc_hanger) {
443*4882a593Smuzhiyun kfree(wlan_static_dhd_wlfc_hanger);
444*4882a593Smuzhiyun }
445*4882a593Smuzhiyun #endif /* CONFIG_BCMDHD_PCIE */
446*4882a593Smuzhiyun if (wlan_static_dhd_info_buf) {
447*4882a593Smuzhiyun kfree(wlan_static_dhd_info_buf);
448*4882a593Smuzhiyun }
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun if (wlan_static_dhd_log_dump_buf) {
451*4882a593Smuzhiyun kfree(wlan_static_dhd_log_dump_buf);
452*4882a593Smuzhiyun }
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun if (wlan_static_dhd_log_dump_buf_ex) {
455*4882a593Smuzhiyun kfree(wlan_static_dhd_log_dump_buf_ex);
456*4882a593Smuzhiyun }
457*4882a593Smuzhiyun
458*4882a593Smuzhiyun if (wlan_static_scan_buf1) {
459*4882a593Smuzhiyun kfree(wlan_static_scan_buf1);
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun if (wlan_static_scan_buf0) {
463*4882a593Smuzhiyun kfree(wlan_static_scan_buf0);
464*4882a593Smuzhiyun }
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun if (wlan_static_dhd_pktlog_dump_buf) {
467*4882a593Smuzhiyun kfree(wlan_static_dhd_pktlog_dump_buf);
468*4882a593Smuzhiyun }
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun pr_err("Failed to mem_alloc for WLAN\n");
471*4882a593Smuzhiyun
472*4882a593Smuzhiyun for (j = 0; j < i; j++) {
473*4882a593Smuzhiyun kfree(wlan_mem_array[j].mem_ptr);
474*4882a593Smuzhiyun }
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun i = WLAN_SKB_BUF_NUM;
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun err_skb_alloc:
479*4882a593Smuzhiyun pr_err("Failed to skb_alloc for WLAN\n");
480*4882a593Smuzhiyun for (j = 0; j < i; j++) {
481*4882a593Smuzhiyun dev_kfree_skb(wlan_static_skb[j]);
482*4882a593Smuzhiyun }
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun return -ENOMEM;
485*4882a593Smuzhiyun }
486*4882a593Smuzhiyun EXPORT_SYMBOL(dhd_init_wlan_mem);
487*4882a593Smuzhiyun
488*4882a593Smuzhiyun void
dhd_exit_wlan_mem(void)489*4882a593Smuzhiyun dhd_exit_wlan_mem(void)
490*4882a593Smuzhiyun {
491*4882a593Smuzhiyun int i = 0;
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun #ifdef CONFIG_BCMDHD_PREALLOC_MEMDUMP
494*4882a593Smuzhiyun if (wlan_static_dhd_memdump_ram) {
495*4882a593Smuzhiyun kfree(wlan_static_dhd_memdump_ram);
496*4882a593Smuzhiyun }
497*4882a593Smuzhiyun
498*4882a593Smuzhiyun #endif /* CONFIG_BCMDHD_PREALLOC_MEMDUMP */
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun #ifdef CONFIG_BCMDHD_PCIE
501*4882a593Smuzhiyun if (wlan_static_if_flow_lkup) {
502*4882a593Smuzhiyun kfree(wlan_static_if_flow_lkup);
503*4882a593Smuzhiyun }
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun #ifdef CONFIG_BCMDHD_PREALLOC_PKTIDMAP
506*4882a593Smuzhiyun if (wlan_static_dhd_pktid_map) {
507*4882a593Smuzhiyun kfree(wlan_static_dhd_pktid_map);
508*4882a593Smuzhiyun }
509*4882a593Smuzhiyun
510*4882a593Smuzhiyun if (wlan_static_dhd_pktid_ioctl_map) {
511*4882a593Smuzhiyun kfree(wlan_static_dhd_pktid_ioctl_map);
512*4882a593Smuzhiyun }
513*4882a593Smuzhiyun #endif /* CONFIG_BCMDHD_PREALLOC_PKTIDMAP */
514*4882a593Smuzhiyun #else
515*4882a593Smuzhiyun if (wlan_static_dhd_wlfc_buf) {
516*4882a593Smuzhiyun kfree(wlan_static_dhd_wlfc_buf);
517*4882a593Smuzhiyun }
518*4882a593Smuzhiyun
519*4882a593Smuzhiyun if (wlan_static_dhd_wlfc_hanger) {
520*4882a593Smuzhiyun kfree(wlan_static_dhd_wlfc_hanger);
521*4882a593Smuzhiyun }
522*4882a593Smuzhiyun #endif /* CONFIG_BCMDHD_PCIE */
523*4882a593Smuzhiyun if (wlan_static_dhd_info_buf) {
524*4882a593Smuzhiyun kfree(wlan_static_dhd_info_buf);
525*4882a593Smuzhiyun }
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun if (wlan_static_dhd_log_dump_buf) {
528*4882a593Smuzhiyun kfree(wlan_static_dhd_log_dump_buf);
529*4882a593Smuzhiyun }
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun if (wlan_static_dhd_log_dump_buf_ex) {
532*4882a593Smuzhiyun kfree(wlan_static_dhd_log_dump_buf_ex);
533*4882a593Smuzhiyun }
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun if (wlan_static_scan_buf1) {
536*4882a593Smuzhiyun kfree(wlan_static_scan_buf1);
537*4882a593Smuzhiyun }
538*4882a593Smuzhiyun
539*4882a593Smuzhiyun if (wlan_static_scan_buf0) {
540*4882a593Smuzhiyun kfree(wlan_static_scan_buf0);
541*4882a593Smuzhiyun }
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun if (wlan_static_dhd_pktlog_dump_buf) {
544*4882a593Smuzhiyun kfree(wlan_static_dhd_pktlog_dump_buf);
545*4882a593Smuzhiyun }
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun pr_err("Failed to mem_alloc for WLAN\n");
548*4882a593Smuzhiyun
549*4882a593Smuzhiyun for (i = 0; i < PREALLOC_WLAN_SEC_NUM; i++) {
550*4882a593Smuzhiyun if (wlan_mem_array[i].mem_ptr) {
551*4882a593Smuzhiyun kfree(wlan_mem_array[i].mem_ptr);
552*4882a593Smuzhiyun }
553*4882a593Smuzhiyun }
554*4882a593Smuzhiyun
555*4882a593Smuzhiyun pr_err("Failed to skb_alloc for WLAN\n");
556*4882a593Smuzhiyun for (i = 0; i < WLAN_SKB_BUF_NUM; i++) {
557*4882a593Smuzhiyun dev_kfree_skb(wlan_static_skb[i]);
558*4882a593Smuzhiyun }
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun return;
561*4882a593Smuzhiyun }
562*4882a593Smuzhiyun EXPORT_SYMBOL(dhd_exit_wlan_mem);
563*4882a593Smuzhiyun #endif /* CONFIG_BROADCOM_WIFI_RESERVED_MEM */
564