1 #include <linux/module.h>
\r
2 #include <linux/kernel.h>
\r
3 #include <linux/init.h>
\r
4 #include <linux/platform_device.h>
\r
5 #include <linux/delay.h>
\r
6 #include <linux/err.h>
\r
7 #include <linux/skbuff.h>
\r
8 #include <linux/wlan_plat.h>
\r
10 #define CONFIG_BROADCOM_WIFI_RESERVED_MEM
\r
12 #ifdef CONFIG_BROADCOM_WIFI_RESERVED_MEM
\r
14 #define WLAN_STATIC_PKT_BUF 4
\r
15 #define WLAN_STATIC_SCAN_BUF0 5
\r
16 #define WLAN_STATIC_SCAN_BUF1 6
\r
17 #define WLAN_STATIC_DHD_INFO 7
\r
18 #define WLAN_STATIC_DHD_WLFC_INFO 8
\r
19 #define PREALLOC_WLAN_SEC_NUM 6
\r
20 #define PREALLOC_WLAN_BUF_NUM 160
\r
21 #define PREALLOC_WLAN_SECTION_HEADER 24
\r
23 #define WLAN_SECTION_SIZE_0 (PREALLOC_WLAN_BUF_NUM * 128)
\r
24 #define WLAN_SECTION_SIZE_1 (PREALLOC_WLAN_BUF_NUM * 128)
\r
25 #define WLAN_SECTION_SIZE_2 (PREALLOC_WLAN_BUF_NUM * 512)
\r
26 #define WLAN_SECTION_SIZE_3 (PREALLOC_WLAN_BUF_NUM * 1024)
\r
27 #define WLAN_SECTION_SIZE_7 (PREALLOC_WLAN_BUF_NUM * 128)
\r
28 #define WLAN_SECTION_SIZE_8 (PREALLOC_WLAN_BUF_NUM * 512)
\r
30 #define DHD_SKB_HDRSIZE 336
\r
31 #define DHD_SKB_1PAGE_BUFSIZE ((PAGE_SIZE*1)-DHD_SKB_HDRSIZE)
\r
32 #define DHD_SKB_2PAGE_BUFSIZE ((PAGE_SIZE*2)-DHD_SKB_HDRSIZE)
\r
33 #define DHD_SKB_4PAGE_BUFSIZE ((PAGE_SIZE*4)-DHD_SKB_HDRSIZE)
\r
35 #define WLAN_SKB_BUF_NUM 17
\r
37 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];
\r
39 struct wlan_mem_prealloc {
\r
44 static struct wlan_mem_prealloc wlan_mem_array[PREALLOC_WLAN_SEC_NUM] = {
\r
45 {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
\r
46 {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
\r
47 {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
\r
48 {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)},
\r
49 {NULL, (WLAN_SECTION_SIZE_7 + PREALLOC_WLAN_SECTION_HEADER)},
\r
50 {NULL, (WLAN_SECTION_SIZE_8 + PREALLOC_WLAN_SECTION_HEADER)}
\r
53 void *wlan_static_scan_buf0;
\r
54 void *wlan_static_scan_buf1;
\r
55 void *bcmdhd_mem_prealloc(int section, unsigned long size)
\r
57 if (section == WLAN_STATIC_PKT_BUF) {
\r
58 printk("1 %s: section=%d, wlan_static_skb=%p\n",
\r
59 __FUNCTION__, section, wlan_static_skb);
\r
60 return wlan_static_skb;
\r
62 if (section == WLAN_STATIC_SCAN_BUF0) {
\r
63 printk("2 %s: section=%d, wlan_static_scan_buf0=%p\n",
\r
64 __FUNCTION__, section, wlan_static_scan_buf0);
\r
65 return wlan_static_scan_buf0;
\r
67 if (section == WLAN_STATIC_SCAN_BUF1) {
\r
68 printk("3 %s: section=%d, wlan_static_scan_buf1=%p\n",
\r
69 __FUNCTION__, section, wlan_static_scan_buf1);
\r
70 return wlan_static_scan_buf1;
\r
72 if (section == WLAN_STATIC_DHD_INFO) {
\r
73 printk("4 %s: section=%d, wlan_mem_array[4]=%p\n",
\r
74 __FUNCTION__, section, wlan_mem_array[4].mem_ptr);
\r
75 return wlan_mem_array[4].mem_ptr;
\r
77 if (section == WLAN_STATIC_DHD_WLFC_INFO) {
\r
78 printk("5 %s: section=%d, wlan_mem_array[5]=%p\n",
\r
79 __FUNCTION__, section, wlan_mem_array[5].mem_ptr);
\r
80 return wlan_mem_array[5].mem_ptr;
\r
82 if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM)) {
\r
83 printk("6 %s: out of section %d\n", __FUNCTION__, section);
\r
87 if (wlan_mem_array[section].size < size) {
\r
88 printk("7 %s: wlan_mem_array[section].size=%lu, size=%lu\n",
\r
89 __FUNCTION__, wlan_mem_array[section].size, size);
\r
92 printk("8 %s: wlan_mem_array[section].mem_ptr=%p, size=%lu\n",
\r
93 __FUNCTION__, &wlan_mem_array[section], size);
\r
95 return wlan_mem_array[section].mem_ptr;
\r
98 EXPORT_SYMBOL(bcmdhd_mem_prealloc);
\r
100 int bcmdhd_init_wlan_mem(void)
105 for (i=0; i<8; i++) {
\r
106 wlan_static_skb[i] = dev_alloc_skb(DHD_SKB_1PAGE_BUFSIZE);
\r
107 if (!wlan_static_skb[i])
\r
109 printk("1 %s: wlan_static_skb[%d]=%p, size=%lu\n",
\r
110 __FUNCTION__, i, wlan_static_skb[i], DHD_SKB_1PAGE_BUFSIZE);
\r
113 for (; i<16; i++) {
\r
114 wlan_static_skb[i] = dev_alloc_skb(DHD_SKB_2PAGE_BUFSIZE);
\r
115 if (!wlan_static_skb[i])
\r
117 printk("2 %s: wlan_static_skb[%d]=%p, size=%lu\n",
\r
118 __FUNCTION__, i, wlan_static_skb[i], DHD_SKB_2PAGE_BUFSIZE);
\r
121 wlan_static_skb[i] = dev_alloc_skb(DHD_SKB_4PAGE_BUFSIZE);
\r
122 if (!wlan_static_skb[i])
\r
124 printk("3 %s: wlan_static_skb[%d]=%p, size=%lu\n",
\r
125 __FUNCTION__, i, wlan_static_skb[i], DHD_SKB_4PAGE_BUFSIZE);
\r
127 for (i=0; i<PREALLOC_WLAN_SEC_NUM; i++) {
\r
128 wlan_mem_array[i].mem_ptr =
\r
129 kmalloc(wlan_mem_array[i].size, GFP_KERNEL);
\r
131 if (!wlan_mem_array[i].mem_ptr)
\r
132 goto err_mem_alloc;
\r
133 printk("4 %s: wlan_mem_array[%d]=%p, size=%lu\n",
\r
134 __FUNCTION__, i, wlan_static_skb[i], wlan_mem_array[i].size);
\r
137 wlan_static_scan_buf0 = kmalloc (65536, GFP_KERNEL);
\r
138 if (!wlan_static_scan_buf0)
139 goto err_mem_alloc;
\r
140 printk("5 %s: wlan_static_scan_buf0=%p, size=%d\n",
\r
141 __FUNCTION__, wlan_static_scan_buf0, 65536);
\r
143 wlan_static_scan_buf1 = kmalloc (65536, GFP_KERNEL);
\r
144 if (!wlan_static_scan_buf1)
145 goto err_mem_alloc;
\r
146 printk("6 %s: wlan_static_scan_buf1=%p, size=%d\n",
\r
147 __FUNCTION__, wlan_static_scan_buf1, 65536);
\r
149 printk("%s: WIFI MEM Allocated\n", __FUNCTION__);
\r
153 pr_err("Failed to mem_alloc for WLAN\n");
\r
154 for (j=0; j<i; j++)
\r
155 kfree(wlan_mem_array[j].mem_ptr);
\r
157 i = WLAN_SKB_BUF_NUM;
\r
160 pr_err("Failed to skb_alloc for WLAN\n");
\r
161 for (j=0; j<i; j++)
\r
162 dev_kfree_skb(wlan_static_skb[j]);
\r
166 #endif /* CONFIG_BROADCOM_WIFI_RESERVED_MEM */
\r
168 static int __init bcmdhd_wlan_init(void)
\r
170 printk("%s()\n", __FUNCTION__);
\r
172 #ifdef CONFIG_BROADCOM_WIFI_RESERVED_MEM
\r
173 bcmdhd_init_wlan_mem();
\r
179 __initcall(bcmdhd_wlan_init);
\r