dhd_custom_memprealloc.c 16 KB

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