ARM64: DTS: Add rk3399-firefly uart4 device, node as /dev/ttyS1
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rkwifi / bcmdhd / dhd_static_buf.c
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
9 \r
10 #define CONFIG_BROADCOM_WIFI_RESERVED_MEM\r
11 \r
12 #ifdef CONFIG_BROADCOM_WIFI_RESERVED_MEM\r
13 \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
22 \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
29 \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
34 \r
35 #define WLAN_SKB_BUF_NUM        17\r
36 \r
37 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];\r
38 \r
39 struct wlan_mem_prealloc {\r
40         void *mem_ptr;\r
41         unsigned long size;\r
42 };\r
43 \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
51 };\r
52 \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
56 {\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
61         }\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
66         }\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
71         }\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
76         }\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
81         }\r
82         if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM)) {\r
83                 printk("6 %s: out of section %d\n", __FUNCTION__, section);\r
84                 return NULL;\r
85         }\r
86 \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
90                 return NULL;\r
91         }\r
92         printk("8 %s: wlan_mem_array[section].mem_ptr=%p, size=%lu\n",\r
93                 __FUNCTION__, &wlan_mem_array[section], size);\r
94 \r
95         return wlan_mem_array[section].mem_ptr;\r
96 }\r
97 \r
98 EXPORT_SYMBOL(bcmdhd_mem_prealloc);\r
99 \r
100 int bcmdhd_init_wlan_mem(void)
101 {\r
102         int i;\r
103         int j;\r
104 \r
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
108                         goto err_skb_alloc;
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
111         }\r
112 \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
116                         goto err_skb_alloc;
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
119         }\r
120 \r
121         wlan_static_skb[i] = dev_alloc_skb(DHD_SKB_4PAGE_BUFSIZE);\r
122         if (!wlan_static_skb[i])\r
123                 goto err_skb_alloc;
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
126 \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
130 \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
135         }\r
136 \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
142 \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
148 \r
149         printk("%s: WIFI MEM Allocated\n", __FUNCTION__);\r
150         return 0;\r
151 \r
152 err_mem_alloc:\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
156 \r
157         i = WLAN_SKB_BUF_NUM;\r
158 \r
159 err_skb_alloc:\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
163 \r
164         return -ENOMEM;\r
165 }\r
166 #endif /* CONFIG_BROADCOM_WIFI_RESERVED_MEM */\r
167 \r
168 static int __init bcmdhd_wlan_init(void)\r
169 {\r
170         printk("%s()\n", __FUNCTION__);\r
171 \r
172 #ifdef CONFIG_BROADCOM_WIFI_RESERVED_MEM\r
173         bcmdhd_init_wlan_mem();\r
174 #endif\r
175 \r
176         return 0;\r
177 }\r
178 \r
179 __initcall(bcmdhd_wlan_init);\r