Commit | Line | Data |
---|---|---|
c5c77ba1 JK |
1 | #include "wilc_wfi_cfgoperations.h" |
2 | #include "linux_wlan_common.h" | |
3 | #include "wilc_wlan_if.h" | |
4 | #include "wilc_wlan.h" | |
5 | #ifdef USE_WIRELESS | |
6 | #include "wilc_wfi_cfgoperations.h" | |
7 | #endif | |
8 | ||
9 | #include "linux_wlan_common.h" | |
10 | ||
11 | #include <linux/slab.h> | |
12 | #include <linux/sched.h> | |
13 | #include <linux/delay.h> | |
14 | #include <linux/workqueue.h> | |
15 | #include <linux/interrupt.h> | |
16 | #include <linux/irq.h> | |
f1a99830 | 17 | #include <linux/gpio.h> |
c5c77ba1 JK |
18 | |
19 | #include <linux/kthread.h> | |
20 | #include <linux/firmware.h> | |
21 | #include <linux/delay.h> | |
22 | ||
23 | #include <linux/init.h> | |
24 | #include <linux/netdevice.h> | |
25 | #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP | |
26 | #include <linux/inetdevice.h> | |
27 | #endif | |
28 | #include <linux/etherdevice.h> | |
29 | #include <linux/module.h> | |
30 | #include <linux/kernel.h> | |
31 | #include <linux/skbuff.h> | |
32 | ||
33 | #include <linux/version.h> | |
34 | #include <linux/semaphore.h> | |
35 | ||
36 | #ifdef WILC_SDIO | |
37 | #include "linux_wlan_sdio.h" | |
38 | #else | |
39 | #include "linux_wlan_spi.h" | |
40 | #endif | |
41 | ||
42 | #ifdef WILC_FULLY_HOSTING_AP | |
43 | #include "wilc_host_ap.h" | |
44 | #endif | |
45 | ||
46 | #ifdef STATIC_MACADDRESS /* brandy_0724 [[ */ | |
47 | #include <linux/vmalloc.h> | |
48 | #include <linux/fs.h> | |
49 | struct task_struct *wilc_mac_thread; | |
50 | unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xb2}; | |
51 | #endif /* brandy_0724 ]] */ | |
52 | ||
53 | #if defined(CUSTOMER_PLATFORM) | |
54 | /* | |
55 | TODO : Write power control functions as customer platform. | |
56 | */ | |
57 | #else | |
58 | ||
59 | #define _linux_wlan_device_power_on() {} | |
60 | #define _linux_wlan_device_power_off() {} | |
61 | ||
62 | #define _linux_wlan_device_detection() {} | |
63 | #define _linux_wlan_device_removal() {} | |
64 | #endif | |
65 | ||
66 | #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP | |
72ed4dc7 | 67 | extern bool g_obtainingIP; |
c5c77ba1 | 68 | #endif |
72ed4dc7 | 69 | extern u16 Set_machw_change_vir_if(bool bValue); |
c5c77ba1 | 70 | extern void resolve_disconnect_aberration(void *drvHandler); |
63d03e47 | 71 | extern u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN]; |
c5c77ba1 JK |
72 | void wilc1000_wlan_deinit(linux_wlan_t *nic); |
73 | #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP | |
74 | extern WILC_TimerHandle hDuringIpTimer; | |
75 | #endif | |
76 | ||
77 | static int linux_wlan_device_power(int on_off) | |
78 | { | |
79 | PRINT_D(INIT_DBG, "linux_wlan_device_power.. (%d)\n", on_off); | |
80 | ||
81 | if (on_off) { | |
82 | _linux_wlan_device_power_on(); | |
83 | } else { | |
84 | _linux_wlan_device_power_off(); | |
85 | } | |
86 | ||
87 | return 0; | |
88 | } | |
89 | ||
90 | static int linux_wlan_device_detection(int on_off) | |
91 | { | |
92 | PRINT_D(INIT_DBG, "linux_wlan_device_detection.. (%d)\n", on_off); | |
93 | ||
94 | #ifdef WILC_SDIO | |
95 | if (on_off) { | |
96 | _linux_wlan_device_detection(); | |
97 | } else { | |
98 | _linux_wlan_device_removal(); | |
99 | } | |
100 | #endif | |
101 | ||
102 | return 0; | |
103 | } | |
104 | ||
105 | ||
106 | #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP | |
107 | static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr); | |
108 | ||
109 | static struct notifier_block g_dev_notifier = { | |
110 | .notifier_call = dev_state_ev_handler | |
111 | }; | |
112 | #endif | |
113 | ||
114 | #define wilc_wlan_deinit(nic) { if (&g_linux_wlan->oup != NULL) \ | |
115 | if (g_linux_wlan->oup.wlan_cleanup != NULL) \ | |
116 | g_linux_wlan->oup.wlan_cleanup(); } | |
117 | ||
118 | ||
119 | #ifndef STA_FIRMWARE | |
120 | #define STA_FIRMWARE "wifi_firmware.bin" | |
121 | #endif | |
122 | ||
123 | #ifndef AP_FIRMWARE | |
124 | #define AP_FIRMWARE "wifi_firmware_ap.bin" | |
125 | #endif | |
126 | ||
127 | #ifndef P2P_CONCURRENCY_FIRMWARE | |
128 | #define P2P_CONCURRENCY_FIRMWARE "wifi_firmware_p2p_concurrency.bin" | |
129 | #endif | |
130 | ||
131 | ||
132 | ||
133 | typedef struct android_wifi_priv_cmd { | |
134 | char *buf; | |
135 | int used_len; | |
136 | int total_len; | |
137 | } android_wifi_priv_cmd; | |
138 | ||
139 | ||
140 | #define IRQ_WAIT 1 | |
141 | #define IRQ_NO_WAIT 0 | |
142 | /* | |
143 | * to sync between mac_close and module exit. | |
144 | * don't initialize or de-initialize from init/deinitlocks | |
145 | * to be initialized from module wilc_netdev_init and | |
146 | * deinitialized from mdoule_exit | |
147 | */ | |
148 | static struct semaphore close_exit_sync; | |
149 | unsigned int int_rcvdU; | |
150 | unsigned int int_rcvdB; | |
151 | unsigned int int_clrd; | |
152 | ||
153 | static int wlan_deinit_locks(linux_wlan_t *nic); | |
154 | static void wlan_deinitialize_threads(linux_wlan_t *nic); | |
155 | static void linux_wlan_lock(void *vp); | |
156 | void linux_wlan_unlock(void *vp); | |
157 | extern void WILC_WFI_monitor_rx(uint8_t *buff, uint32_t size); | |
158 | extern void WILC_WFI_p2p_rx(struct net_device *dev, uint8_t *buff, uint32_t size); | |
159 | ||
160 | ||
161 | static void *internal_alloc(uint32_t size, uint32_t flag); | |
162 | static void linux_wlan_tx_complete(void *priv, int status); | |
163 | void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset); | |
164 | static int mac_init_fn(struct net_device *ndev); | |
165 | int mac_xmit(struct sk_buff *skb, struct net_device *dev); | |
166 | int mac_open(struct net_device *ndev); | |
167 | int mac_close(struct net_device *ndev); | |
168 | static struct net_device_stats *mac_stats(struct net_device *dev); | |
169 | static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd); | |
170 | static void wilc_set_multicast_list(struct net_device *dev); | |
171 | ||
172 | ||
173 | ||
174 | /* | |
175 | * for now - in frmw_to_linux there should be private data to be passed to it | |
176 | * and this data should be pointer to net device | |
177 | */ | |
178 | linux_wlan_t *g_linux_wlan; | |
179 | wilc_wlan_oup_t *gpstrWlanOps; | |
72ed4dc7 | 180 | bool bEnablePS = true; |
c5c77ba1 | 181 | |
c5c77ba1 JK |
182 | static const struct net_device_ops wilc_netdev_ops = { |
183 | .ndo_init = mac_init_fn, | |
184 | .ndo_open = mac_open, | |
185 | .ndo_stop = mac_close, | |
186 | .ndo_start_xmit = mac_xmit, | |
187 | .ndo_do_ioctl = mac_ioctl, | |
188 | .ndo_get_stats = mac_stats, | |
189 | .ndo_set_rx_mode = wilc_set_multicast_list, | |
190 | ||
191 | }; | |
c5c77ba1 | 192 | |
c5c77ba1 JK |
193 | #ifdef DEBUG_MODE |
194 | ||
195 | extern volatile int timeNo; | |
196 | ||
197 | #define DEGUG_BUFFER_LENGTH 1000 | |
198 | volatile int WatchDogdebuggerCounter; | |
199 | char DebugBuffer[DEGUG_BUFFER_LENGTH + 20] = {0}; | |
200 | static char *ps8current = DebugBuffer; | |
201 | ||
202 | ||
203 | ||
204 | void printk_later(const char *format, ...) | |
205 | { | |
206 | va_list args; | |
207 | va_start (args, format); | |
208 | ps8current += vsprintf (ps8current, format, args); | |
209 | va_end (args); | |
210 | if ((ps8current - DebugBuffer) > DEGUG_BUFFER_LENGTH) { | |
211 | ps8current = DebugBuffer; | |
212 | } | |
213 | ||
214 | } | |
215 | ||
216 | ||
217 | void dump_logs() | |
218 | { | |
219 | if (DebugBuffer[0]) { | |
220 | DebugBuffer[DEGUG_BUFFER_LENGTH] = 0; | |
221 | PRINT_INFO(GENERIC_DBG, "early printed\n"); | |
222 | PRINT_D(GENERIC_DBG, ps8current + 1); | |
223 | ps8current[1] = 0; | |
224 | PRINT_INFO(GENERIC_DBG, "latest printed\n"); | |
225 | PRINT_D(GENERIC_DBG, DebugBuffer); | |
226 | DebugBuffer[0] = 0; | |
227 | ps8current = DebugBuffer; | |
228 | } | |
229 | } | |
230 | ||
231 | void Reset_WatchDogdebugger() | |
232 | { | |
233 | WatchDogdebuggerCounter = 0; | |
234 | } | |
235 | ||
236 | static int DebuggingThreadTask(void *vp) | |
237 | { | |
238 | while (1) { | |
239 | while (!WatchDogdebuggerCounter) { | |
240 | PRINT_D(GENERIC_DBG, "Debug Thread Running %d\n", timeNo); | |
241 | WatchDogdebuggerCounter = 1; | |
242 | msleep(10000); | |
243 | } | |
244 | dump_logs(); | |
245 | WatchDogdebuggerCounter = 0; | |
246 | } | |
247 | } | |
248 | ||
249 | ||
250 | #endif | |
251 | ||
252 | ||
253 | #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP | |
254 | static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr) | |
255 | { | |
256 | struct in_ifaddr *dev_iface = (struct in_ifaddr *)ptr; | |
257 | struct WILC_WFI_priv *priv; | |
258 | tstrWILC_WFIDrv *pstrWFIDrv; | |
259 | struct net_device *dev; | |
63d03e47 | 260 | u8 *pIP_Add_buff; |
c5c77ba1 | 261 | perInterface_wlan_t *nic; |
63d03e47 | 262 | u8 null_ip[4] = {0}; |
c5c77ba1 JK |
263 | char wlan_dev_name[5] = "wlan0"; |
264 | ||
265 | if (dev_iface == NULL || dev_iface->ifa_dev == NULL || dev_iface->ifa_dev->dev == NULL) { | |
266 | PRINT_D(GENERIC_DBG, "dev_iface = NULL\n"); | |
267 | return NOTIFY_DONE; | |
268 | } | |
269 | ||
270 | if ((memcmp(dev_iface->ifa_label, "wlan0", 5)) && (memcmp(dev_iface->ifa_label, "p2p0", 4))) { | |
271 | PRINT_D(GENERIC_DBG, "Interface is neither WLAN0 nor P2P0\n"); | |
272 | return NOTIFY_DONE; | |
273 | } | |
274 | ||
275 | dev = (struct net_device *)dev_iface->ifa_dev->dev; | |
276 | if (dev->ieee80211_ptr == NULL || dev->ieee80211_ptr->wiphy == NULL) { | |
277 | PRINT_D(GENERIC_DBG, "No Wireless registerd\n"); | |
278 | return NOTIFY_DONE; | |
279 | } | |
280 | priv = wiphy_priv(dev->ieee80211_ptr->wiphy); | |
281 | if (priv == NULL) { | |
282 | PRINT_D(GENERIC_DBG, "No Wireless Priv\n"); | |
283 | return NOTIFY_DONE; | |
284 | } | |
285 | pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv; | |
286 | nic = netdev_priv(dev); | |
287 | if (nic == NULL || pstrWFIDrv == NULL) { | |
288 | PRINT_D(GENERIC_DBG, "No Wireless Priv\n"); | |
289 | return NOTIFY_DONE; | |
290 | } | |
291 | ||
292 | PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler +++\n"); /* tony */ | |
293 | ||
294 | switch (event) { | |
295 | case NETDEV_UP: | |
296 | PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_UP %p\n", dev); /* tony */ | |
297 | ||
298 | PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n"); | |
299 | ||
300 | ||
301 | /*If we are in station mode or client mode*/ | |
302 | if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) { | |
303 | pstrWFIDrv->IFC_UP = 1; | |
72ed4dc7 | 304 | g_obtainingIP = false; |
b1413b60 | 305 | WILC_TimerStop(&hDuringIpTimer, NULL); |
c5c77ba1 JK |
306 | PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n"); |
307 | } | |
308 | ||
309 | ||
310 | ||
5a66bf20 | 311 | if (bEnablePS) |
c5c77ba1 JK |
312 | host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 1, 0); |
313 | ||
314 | PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label); | |
315 | ||
316 | pIP_Add_buff = (char *) (&(dev_iface->ifa_address)); | |
317 | PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d \n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]); | |
21175ef7 | 318 | host_int_setup_ipaddress((WILC_WFIDrvHandle)pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx); |
c5c77ba1 JK |
319 | |
320 | break; | |
321 | ||
322 | case NETDEV_DOWN: | |
323 | PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev); /* tony */ | |
324 | ||
325 | PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Released ===============\n\n"); | |
326 | if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) { | |
327 | pstrWFIDrv->IFC_UP = 0; | |
72ed4dc7 | 328 | g_obtainingIP = false; |
c5c77ba1 JK |
329 | } |
330 | ||
331 | if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0) | |
332 | host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 0, 0); | |
333 | ||
334 | resolve_disconnect_aberration(pstrWFIDrv); | |
335 | ||
336 | ||
337 | PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label); | |
338 | ||
339 | pIP_Add_buff = null_ip; | |
340 | PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d \n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]); | |
341 | ||
21175ef7 | 342 | host_int_setup_ipaddress((WILC_WFIDrvHandle)pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx); |
c5c77ba1 JK |
343 | |
344 | break; | |
345 | ||
346 | default: | |
347 | PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler event=default\n"); /* tony */ | |
348 | PRINT_INFO(GENERIC_DBG, "[%s] unknown dev event: %lu\n", dev_iface->ifa_label, event); | |
349 | ||
350 | break; | |
351 | } | |
352 | ||
353 | return NOTIFY_DONE; | |
354 | ||
355 | } | |
356 | #endif | |
357 | ||
358 | /* | |
359 | * Interrupt initialization and handling functions | |
360 | */ | |
361 | ||
362 | void linux_wlan_enable_irq(void) | |
363 | { | |
364 | ||
365 | #if (RX_BH_TYPE != RX_BH_THREADED_IRQ) | |
366 | #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) | |
367 | PRINT_D(INT_DBG, "Enabling IRQ ...\n"); | |
368 | enable_irq(g_linux_wlan->dev_irq_num); | |
369 | #endif | |
370 | #endif | |
371 | } | |
372 | ||
373 | void linux_wlan_disable_irq(int wait) | |
374 | { | |
375 | #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) | |
376 | if (wait) { | |
377 | PRINT_D(INT_DBG, "Disabling IRQ ...\n"); | |
378 | disable_irq(g_linux_wlan->dev_irq_num); | |
379 | } else { | |
380 | PRINT_D(INT_DBG, "Disabling IRQ ...\n"); | |
381 | disable_irq_nosync(g_linux_wlan->dev_irq_num); | |
382 | } | |
383 | #endif | |
384 | } | |
385 | ||
386 | #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) | |
387 | static irqreturn_t isr_uh_routine(int irq, void *user_data) | |
388 | { | |
389 | ||
390 | ||
391 | int_rcvdU++; | |
392 | #if (RX_BH_TYPE != RX_BH_THREADED_IRQ) | |
393 | linux_wlan_disable_irq(IRQ_NO_WAIT); | |
394 | #endif | |
395 | PRINT_D(INT_DBG, "Interrupt received UH\n"); | |
396 | ||
397 | /*While mac is closing cacncel the handling of any interrupts received*/ | |
398 | if (g_linux_wlan->close) { | |
399 | PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n"); | |
400 | #if (RX_BH_TYPE == RX_BH_THREADED_IRQ) | |
401 | return IRQ_HANDLED; | |
402 | #else | |
403 | return IRQ_NONE; | |
404 | #endif | |
405 | ||
406 | } | |
407 | #if (RX_BH_TYPE == RX_BH_WORK_QUEUE) | |
408 | schedule_work(&g_linux_wlan->rx_work_queue); | |
409 | return IRQ_HANDLED; | |
410 | #elif (RX_BH_TYPE == RX_BH_KTHREAD) | |
411 | linux_wlan_unlock(&g_linux_wlan->rx_sem); | |
412 | return IRQ_HANDLED; | |
413 | #elif (RX_BH_TYPE == RX_BH_THREADED_IRQ) | |
414 | return IRQ_WAKE_THREAD; | |
415 | #endif | |
416 | ||
417 | } | |
418 | #endif | |
419 | ||
420 | #if (RX_BH_TYPE == RX_BH_WORK_QUEUE || RX_BH_TYPE == RX_BH_THREADED_IRQ) | |
421 | ||
422 | #if (RX_BH_TYPE == RX_BH_THREADED_IRQ) | |
423 | irqreturn_t isr_bh_routine(int irq, void *userdata) | |
424 | { | |
425 | linux_wlan_t *nic; | |
426 | nic = (linux_wlan_t *)userdata; | |
427 | #else | |
428 | static void isr_bh_routine(struct work_struct *work) | |
429 | { | |
430 | perInterface_wlan_t *nic; | |
431 | nic = (perInterface_wlan_t *)container_of(work, linux_wlan_t, rx_work_queue); | |
432 | #endif | |
433 | ||
434 | /*While mac is closing cacncel the handling of any interrupts received*/ | |
435 | if (g_linux_wlan->close) { | |
436 | PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n"); | |
437 | #if (RX_BH_TYPE == RX_BH_THREADED_IRQ) | |
438 | return IRQ_HANDLED; | |
439 | #else | |
440 | return; | |
441 | #endif | |
442 | ||
443 | ||
444 | ||
445 | } | |
446 | ||
447 | int_rcvdB++; | |
448 | PRINT_D(INT_DBG, "Interrupt received BH\n"); | |
449 | if (g_linux_wlan->oup.wlan_handle_rx_isr != 0) { | |
450 | g_linux_wlan->oup.wlan_handle_rx_isr(); | |
451 | } else { | |
452 | PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n"); | |
453 | } | |
454 | ||
455 | ||
456 | #if (RX_BH_TYPE == RX_BH_THREADED_IRQ) | |
457 | return IRQ_HANDLED; | |
458 | #endif | |
459 | } | |
460 | #elif (RX_BH_TYPE == RX_BH_KTHREAD) | |
461 | static int isr_bh_routine(void *vp) | |
462 | { | |
463 | linux_wlan_t *nic; | |
464 | ||
465 | nic = (linux_wlan_t *)vp; | |
466 | ||
467 | while (1) { | |
468 | linux_wlan_lock(&nic->rx_sem); | |
469 | if (g_linux_wlan->close) { | |
470 | ||
471 | while (!kthread_should_stop()) | |
472 | schedule(); | |
473 | ||
474 | break; | |
475 | } | |
476 | int_rcvdB++; | |
477 | PRINT_D(INT_DBG, "Interrupt received BH\n"); | |
478 | if (g_linux_wlan->oup.wlan_handle_rx_isr != 0) { | |
479 | g_linux_wlan->oup.wlan_handle_rx_isr(); | |
480 | } else { | |
481 | PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n"); | |
482 | } | |
483 | } | |
484 | ||
485 | return 0; | |
486 | } | |
487 | #endif | |
488 | ||
489 | ||
490 | #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) | |
491 | static int init_irq(linux_wlan_t *p_nic) | |
492 | { | |
493 | int ret = 0; | |
494 | linux_wlan_t *nic = p_nic; | |
495 | ||
496 | /*initialize GPIO and register IRQ num*/ | |
497 | /*GPIO request*/ | |
498 | if ((gpio_request(GPIO_NUM, "WILC_INTR") == 0) && | |
499 | (gpio_direction_input(GPIO_NUM) == 0)) { | |
500 | #if defined(CUSTOMER_PLATFORM) | |
501 | /* | |
502 | TODO : save the registerd irq number to the private wilc context in kernel. | |
503 | * | |
504 | * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM); | |
505 | */ | |
506 | #elif defined (NM73131_0_BOARD) | |
507 | nic->dev_irq_num = IRQ_WILC1000; | |
508 | #elif defined (PANDA_BOARD) | |
509 | gpio_export(GPIO_NUM, 1); | |
510 | nic->dev_irq_num = OMAP_GPIO_IRQ(GPIO_NUM); | |
511 | irq_set_irq_type(nic->dev_irq_num, IRQ_TYPE_LEVEL_LOW); | |
512 | #else | |
513 | nic->dev_irq_num = gpio_to_irq(GPIO_NUM); | |
514 | #endif | |
515 | } else { | |
516 | ret = -1; | |
517 | PRINT_ER("could not obtain gpio for WILC_INTR\n"); | |
518 | } | |
519 | ||
520 | ||
521 | #if (RX_BH_TYPE == RX_BH_THREADED_IRQ) | |
522 | if ((ret != -1) && (request_threaded_irq(nic->dev_irq_num, isr_uh_routine, isr_bh_routine, | |
523 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/ | |
524 | "WILC_IRQ", nic)) < 0) { | |
525 | ||
526 | #else | |
527 | /*Request IRQ*/ | |
528 | if ((ret != -1) && (request_irq(nic->dev_irq_num, isr_uh_routine, | |
529 | IRQF_TRIGGER_LOW, "WILC_IRQ", nic) < 0)) { | |
530 | ||
531 | #endif | |
532 | PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM); | |
533 | ret = -1; | |
534 | } else { | |
535 | ||
536 | PRINT_D(INIT_DBG, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n", | |
537 | nic->dev_irq_num, GPIO_NUM); | |
538 | } | |
539 | ||
540 | return ret; | |
541 | } | |
542 | #endif | |
543 | ||
544 | static void deinit_irq(linux_wlan_t *nic) | |
545 | { | |
546 | #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) | |
547 | /* Deintialize IRQ */ | |
548 | if (&nic->dev_irq_num != 0) { | |
549 | free_irq(nic->dev_irq_num, g_linux_wlan); | |
550 | ||
551 | gpio_free(GPIO_NUM); | |
552 | } | |
553 | #endif | |
554 | } | |
555 | ||
556 | ||
557 | /* | |
558 | * OS functions | |
559 | */ | |
560 | static void linux_wlan_msleep(uint32_t msc) | |
561 | { | |
562 | if (msc <= 4000000) { | |
4e4467fd | 563 | u32 u32Temp = msc * 1000; |
c5c77ba1 | 564 | usleep_range(u32Temp, u32Temp); |
c5c77ba1 JK |
565 | } else { |
566 | msleep(msc); | |
567 | } | |
568 | } | |
569 | ||
570 | static void linux_wlan_atomic_msleep(uint32_t msc) | |
571 | { | |
572 | mdelay(msc); | |
573 | } | |
574 | static void linux_wlan_dbg(uint8_t *buff) | |
575 | { | |
576 | PRINT_D(INIT_DBG, "%d\n", *buff); | |
577 | } | |
578 | ||
579 | static void *linux_wlan_malloc_atomic(uint32_t sz) | |
580 | { | |
581 | char *pntr = NULL; | |
30ef5c8b | 582 | pntr = kmalloc(sz, GFP_ATOMIC); |
c5c77ba1 JK |
583 | PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", sz, pntr); |
584 | return (void *)pntr; | |
585 | ||
586 | } | |
587 | static void *linux_wlan_malloc(uint32_t sz) | |
588 | { | |
589 | char *pntr = NULL; | |
30ef5c8b | 590 | pntr = kmalloc(sz, GFP_KERNEL); |
c5c77ba1 JK |
591 | PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", sz, pntr); |
592 | return (void *)pntr; | |
593 | } | |
594 | ||
595 | void linux_wlan_free(void *vp) | |
596 | { | |
597 | if (vp != NULL) { | |
598 | PRINT_D(MEM_DBG, "Freeing %p\n", vp); | |
599 | kfree(vp); | |
600 | } | |
601 | } | |
602 | ||
603 | ||
604 | static void *internal_alloc(uint32_t size, uint32_t flag) | |
605 | { | |
606 | char *pntr = NULL; | |
30ef5c8b | 607 | pntr = kmalloc(size, flag); |
c5c77ba1 JK |
608 | PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", size, pntr); |
609 | return (void *)pntr; | |
610 | } | |
611 | ||
612 | ||
613 | static void linux_wlan_init_lock(char *lockName, void *plock, int count) | |
614 | { | |
615 | sema_init((struct semaphore *)plock, count); | |
616 | PRINT_D(LOCK_DBG, "Initializing [%s][%p]\n", lockName, plock); | |
617 | ||
618 | } | |
619 | ||
620 | static void linux_wlan_deinit_lock(void *plock) | |
621 | { | |
622 | /* mutex_destroy((struct mutex*)plock); */ | |
623 | } | |
624 | ||
625 | static void linux_wlan_lock(void *vp) | |
626 | { | |
627 | PRINT_D(LOCK_DBG, "Locking %p\n", vp); | |
628 | if (vp != NULL) { | |
629 | while (down_interruptible((struct semaphore *) vp)) | |
630 | ; | |
631 | } else { | |
632 | PRINT_ER("Failed, mutex is NULL\n"); | |
633 | } | |
634 | } | |
635 | ||
4e4467fd | 636 | static int linux_wlan_lock_timeout(void *vp, u32 timeout) |
c5c77ba1 JK |
637 | { |
638 | int error = -1; | |
639 | PRINT_D(LOCK_DBG, "Locking %p\n", vp); | |
640 | if (vp != NULL) { | |
641 | error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout)); | |
642 | } else { | |
643 | PRINT_ER("Failed, mutex is NULL\n"); | |
644 | } | |
645 | return error; | |
646 | } | |
647 | ||
648 | void linux_wlan_unlock(void *vp) | |
649 | { | |
650 | PRINT_D(LOCK_DBG, "Unlocking %p\n", vp); | |
651 | if (vp != NULL) { | |
652 | up((struct semaphore *)vp); | |
653 | } else { | |
654 | PRINT_ER("Failed, mutex is NULL\n"); | |
655 | } | |
656 | } | |
657 | ||
658 | ||
659 | static void linux_wlan_init_mutex(char *lockName, void *plock, int count) | |
660 | { | |
661 | mutex_init((struct mutex *)plock); | |
662 | PRINT_D(LOCK_DBG, "Initializing mutex [%s][%p]\n", lockName, plock); | |
663 | ||
664 | } | |
665 | ||
666 | static void linux_wlan_deinit_mutex(void *plock) | |
667 | { | |
668 | mutex_destroy((struct mutex *)plock); | |
669 | } | |
670 | ||
671 | static void linux_wlan_lock_mutex(void *vp) | |
672 | { | |
673 | PRINT_D(LOCK_DBG, "Locking mutex %p\n", vp); | |
674 | if (vp != NULL) { | |
675 | /* | |
676 | * if(mutex_is_locked((struct mutex*)vp)) | |
677 | * { | |
678 | * //PRINT_ER("Mutex already locked - %p \n",vp); | |
679 | * } | |
680 | */ | |
681 | mutex_lock((struct mutex *)vp); | |
682 | ||
683 | } else { | |
684 | PRINT_ER("Failed, mutex is NULL\n"); | |
685 | } | |
686 | } | |
687 | ||
688 | static void linux_wlan_unlock_mutex(void *vp) | |
689 | { | |
690 | PRINT_D(LOCK_DBG, "Unlocking mutex %p\n", vp); | |
691 | if (vp != NULL) { | |
692 | ||
693 | if (mutex_is_locked((struct mutex *)vp)) { | |
694 | mutex_unlock((struct mutex *)vp); | |
695 | } else { | |
696 | /* PRINT_ER("Mutex already unlocked - %p\n",vp); */ | |
697 | } | |
698 | ||
699 | } else { | |
700 | PRINT_ER("Failed, mutex is NULL\n"); | |
701 | } | |
702 | } | |
703 | ||
704 | ||
705 | /*Added by Amr - BugID_4720*/ | |
706 | static void linux_wlan_init_spin_lock(char *lockName, void *plock, int count) | |
707 | { | |
708 | spin_lock_init((spinlock_t *)plock); | |
709 | PRINT_D(SPIN_DEBUG, "Initializing mutex [%s][%p]\n", lockName, plock); | |
710 | ||
711 | } | |
712 | ||
713 | static void linux_wlan_deinit_spin_lock(void *plock) | |
714 | { | |
715 | ||
716 | } | |
717 | static void linux_wlan_spin_lock(void *vp, unsigned long *flags) | |
718 | { | |
719 | unsigned long lflags; | |
720 | PRINT_D(SPIN_DEBUG, "Lock spin %p\n", vp); | |
721 | if (vp != NULL) { | |
722 | spin_lock_irqsave((spinlock_t *)vp, lflags); | |
723 | *flags = lflags; | |
724 | } else { | |
725 | PRINT_ER("Failed, spin lock is NULL\n"); | |
726 | } | |
727 | } | |
728 | static void linux_wlan_spin_unlock(void *vp, unsigned long *flags) | |
729 | { | |
730 | unsigned long lflags = *flags; | |
731 | PRINT_D(SPIN_DEBUG, "Unlock spin %p\n", vp); | |
732 | if (vp != NULL) { | |
733 | spin_unlock_irqrestore((spinlock_t *)vp, lflags); | |
734 | *flags = lflags; | |
735 | } else { | |
736 | PRINT_ER("Failed, spin lock is NULL\n"); | |
737 | } | |
738 | } | |
739 | ||
740 | static void linux_wlan_mac_indicate(int flag) | |
741 | { | |
742 | /*I have to do it that way becuase there is no mean to encapsulate device pointer | |
743 | * as a parameter | |
744 | */ | |
745 | linux_wlan_t *pd = g_linux_wlan; | |
746 | int status; | |
747 | ||
748 | if (flag == WILC_MAC_INDICATE_STATUS) { | |
749 | pd->oup.wlan_cfg_get_value(WID_STATUS, (unsigned char *)&status, 4); | |
750 | if (pd->mac_status == WILC_MAC_STATUS_INIT) { | |
751 | pd->mac_status = status; | |
752 | linux_wlan_unlock(&pd->sync_event); | |
753 | } else { | |
754 | pd->mac_status = status; | |
755 | } | |
756 | ||
757 | if (pd->mac_status == WILC_MAC_STATUS_CONNECT) { /* Connect */ | |
c5c77ba1 JK |
758 | } |
759 | ||
760 | } else if (flag == WILC_MAC_INDICATE_SCAN) { | |
761 | PRINT_D(GENERIC_DBG, "Scanning ...\n"); | |
762 | ||
763 | } | |
764 | ||
765 | } | |
766 | ||
767 | struct net_device *GetIfHandler(uint8_t *pMacHeader) | |
768 | { | |
769 | uint8_t *Bssid, *Bssid1; | |
770 | int i = 0; | |
771 | ||
772 | Bssid = pMacHeader + 10; | |
773 | Bssid1 = pMacHeader + 4; | |
774 | ||
775 | for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) { | |
776 | if (!memcmp(Bssid1, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN) || | |
777 | !memcmp(Bssid, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN)) { | |
778 | return g_linux_wlan->strInterfaceInfo[i].wilc_netdev; | |
779 | } | |
780 | } | |
781 | PRINT_INFO(INIT_DBG, "Invalide handle\n"); | |
782 | for (i = 0; i < 25; i++) { | |
783 | PRINT_D(INIT_DBG, "%02x ", pMacHeader[i]); | |
784 | } | |
785 | Bssid = pMacHeader + 18; | |
786 | Bssid1 = pMacHeader + 12; | |
787 | for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) { | |
788 | if (!memcmp(Bssid1, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN) || | |
789 | !memcmp(Bssid, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN)) { | |
790 | PRINT_D(INIT_DBG, "Ctx [%p]\n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev); | |
791 | return g_linux_wlan->strInterfaceInfo[i].wilc_netdev; | |
792 | } | |
793 | } | |
794 | PRINT_INFO(INIT_DBG, "\n"); | |
795 | return NULL; | |
796 | } | |
797 | ||
798 | int linux_wlan_set_bssid(struct net_device *wilc_netdev, uint8_t *pBSSID) | |
799 | { | |
800 | int i = 0; | |
801 | int ret = -1; | |
802 | ||
803 | PRINT_D(INIT_DBG, "set bssid on[%p]\n", wilc_netdev); | |
804 | for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) { | |
805 | if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev == wilc_netdev) { | |
806 | PRINT_D(INIT_DBG, "set bssid [%x][%x][%x]\n", pBSSID[0], pBSSID[1], pBSSID[2]); | |
807 | memcpy(g_linux_wlan->strInterfaceInfo[i].aBSSID, pBSSID, 6); | |
808 | ret = 0; | |
809 | break; | |
810 | } | |
811 | } | |
812 | return ret; | |
813 | } | |
814 | ||
815 | /*BugID_5213*/ | |
816 | /*Function to get number of connected interfaces*/ | |
817 | int linux_wlan_get_num_conn_ifcs(void) | |
818 | { | |
819 | uint8_t i = 0; | |
820 | uint8_t null_bssid[6] = {0}; | |
821 | uint8_t ret_val = 0; | |
822 | ||
823 | for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) { | |
824 | if (memcmp(g_linux_wlan->strInterfaceInfo[i].aBSSID, null_bssid, 6)) { | |
825 | ret_val++; | |
826 | } | |
827 | } | |
828 | return ret_val; | |
829 | } | |
830 | ||
831 | static int linux_wlan_rxq_task(void *vp) | |
832 | { | |
833 | ||
834 | /* inform wilc1000_wlan_init that RXQ task is started. */ | |
835 | linux_wlan_unlock(&g_linux_wlan->rxq_thread_started); | |
836 | while (1) { | |
837 | linux_wlan_lock(&g_linux_wlan->rxq_event); | |
838 | /* wait_for_completion(&g_linux_wlan->rxq_event); */ | |
839 | ||
840 | if (g_linux_wlan->close) { | |
841 | /*Unlock the mutex in the mac_close function to indicate the exiting of the RX thread */ | |
842 | linux_wlan_unlock(&g_linux_wlan->rxq_thread_started); | |
843 | ||
844 | while (!kthread_should_stop()) | |
845 | schedule(); | |
846 | ||
847 | PRINT_D(RX_DBG, " RX thread stopped\n"); | |
848 | break; | |
849 | } | |
850 | PRINT_D(RX_DBG, "Calling wlan_handle_rx_que()\n"); | |
851 | ||
852 | g_linux_wlan->oup.wlan_handle_rx_que(); | |
853 | } | |
854 | return 0; | |
855 | } | |
856 | ||
857 | #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS | |
858 | ||
859 | static int linux_wlan_txq_task(void *vp) | |
860 | { | |
861 | int ret, txq_count; | |
862 | ||
863 | #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS | |
864 | #define TX_BACKOFF_WEIGHT_INCR_STEP (1) | |
865 | #define TX_BACKOFF_WEIGHT_DECR_STEP (1) | |
866 | #define TX_BACKOFF_WEIGHT_MAX (7) | |
867 | #define TX_BACKOFF_WEIGHT_MIN (0) | |
868 | #define TX_BACKOFF_WEIGHT_UNIT_MS (10) | |
869 | int backoff_weight = TX_BACKOFF_WEIGHT_MIN; | |
c5c77ba1 JK |
870 | #endif |
871 | ||
872 | /* inform wilc1000_wlan_init that TXQ task is started. */ | |
873 | linux_wlan_unlock(&g_linux_wlan->txq_thread_started); | |
874 | while (1) { | |
875 | ||
876 | PRINT_D(TX_DBG, "txq_task Taking a nap :)\n"); | |
877 | linux_wlan_lock(&g_linux_wlan->txq_event); | |
878 | /* wait_for_completion(&pd->txq_event); */ | |
879 | PRINT_D(TX_DBG, "txq_task Who waked me up :$\n"); | |
880 | ||
881 | if (g_linux_wlan->close) { | |
882 | /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */ | |
883 | linux_wlan_unlock(&g_linux_wlan->txq_thread_started); | |
884 | ||
885 | while (!kthread_should_stop()) | |
886 | schedule(); | |
887 | ||
888 | PRINT_D(TX_DBG, "TX thread stopped\n"); | |
889 | break; | |
890 | } | |
891 | PRINT_D(TX_DBG, "txq_task handle the sending packet and let me go to sleep.\n"); | |
892 | #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS | |
893 | g_linux_wlan->oup.wlan_handle_tx_que(); | |
894 | #else | |
895 | do { | |
896 | ret = g_linux_wlan->oup.wlan_handle_tx_que(&txq_count); | |
897 | if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD /* && netif_queue_stopped(pd->wilc_netdev)*/) { | |
898 | PRINT_D(TX_DBG, "Waking up queue\n"); | |
899 | /* netif_wake_queue(pd->wilc_netdev); */ | |
900 | if (netif_queue_stopped(g_linux_wlan->strInterfaceInfo[0].wilc_netdev)) | |
901 | netif_wake_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev); | |
902 | if (netif_queue_stopped(g_linux_wlan->strInterfaceInfo[1].wilc_netdev)) | |
903 | netif_wake_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev); | |
904 | } | |
905 | ||
906 | if (ret == WILC_TX_ERR_NO_BUF) { /* failed to allocate buffers in chip. */ | |
c5c77ba1 JK |
907 | do { |
908 | /* Back off from sending packets for some time. */ | |
909 | /* schedule_timeout will allow RX task to run and free buffers.*/ | |
910 | /* set_current_state(TASK_UNINTERRUPTIBLE); */ | |
911 | /* timeout = schedule_timeout(timeout); */ | |
912 | msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight); | |
913 | } while (/*timeout*/ 0); | |
914 | backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP; | |
915 | if (backoff_weight > TX_BACKOFF_WEIGHT_MAX) { | |
916 | backoff_weight = TX_BACKOFF_WEIGHT_MAX; | |
917 | } | |
918 | } else { | |
919 | if (backoff_weight > TX_BACKOFF_WEIGHT_MIN) { | |
920 | backoff_weight -= TX_BACKOFF_WEIGHT_DECR_STEP; | |
921 | if (backoff_weight < TX_BACKOFF_WEIGHT_MIN) { | |
922 | backoff_weight = TX_BACKOFF_WEIGHT_MIN; | |
923 | } | |
924 | } | |
925 | } | |
926 | /*TODO: drop packets after a certain time/number of retry count. */ | |
927 | } while (ret == WILC_TX_ERR_NO_BUF && !g_linux_wlan->close); /* retry sending packets if no more buffers in chip. */ | |
928 | #endif | |
929 | } | |
930 | return 0; | |
931 | } | |
932 | ||
933 | static void linux_wlan_rx_complete(void) | |
934 | { | |
935 | PRINT_D(RX_DBG, "RX completed\n"); | |
936 | } | |
937 | ||
938 | int linux_wlan_get_firmware(perInterface_wlan_t *p_nic) | |
939 | { | |
940 | ||
941 | perInterface_wlan_t *nic = p_nic; | |
942 | int ret = 0; | |
943 | const struct firmware *wilc_firmware; | |
944 | char *firmware; | |
945 | ||
946 | ||
947 | if (nic->iftype == AP_MODE) | |
948 | firmware = AP_FIRMWARE; | |
949 | else if (nic->iftype == STATION_MODE) | |
950 | firmware = STA_FIRMWARE; | |
951 | ||
952 | /*BugID_5137*/ | |
953 | else { | |
954 | PRINT_D(INIT_DBG, "Get P2P_CONCURRENCY_FIRMWARE\n"); | |
955 | firmware = P2P_CONCURRENCY_FIRMWARE; | |
956 | } | |
957 | ||
958 | ||
959 | ||
960 | if (nic == NULL) { | |
961 | PRINT_ER("NIC is NULL\n"); | |
962 | goto _fail_; | |
963 | } | |
964 | ||
965 | if (&nic->wilc_netdev->dev == NULL) { | |
966 | PRINT_ER("&nic->wilc_netdev->dev is NULL\n"); | |
967 | goto _fail_; | |
968 | } | |
969 | ||
970 | ||
971 | /* the firmare should be located in /lib/firmware in | |
972 | * root file system with the name specified above */ | |
973 | ||
974 | #ifdef WILC_SDIO | |
975 | if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_sdio_func->dev) != 0) { | |
976 | PRINT_ER("%s - firmare not available\n", firmware); | |
977 | ret = -1; | |
978 | goto _fail_; | |
979 | } | |
980 | #else | |
981 | if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_spidev->dev) != 0) { | |
982 | PRINT_ER("%s - firmare not available\n", firmware); | |
983 | ret = -1; | |
984 | goto _fail_; | |
985 | } | |
986 | #endif | |
987 | g_linux_wlan->wilc_firmware = wilc_firmware; /* Bug 4703 */ | |
988 | ||
989 | _fail_: | |
990 | ||
991 | return ret; | |
992 | ||
993 | } | |
994 | ||
995 | #ifdef COMPLEMENT_BOOT | |
996 | int repeat_power_cycle(perInterface_wlan_t *nic); | |
997 | #endif | |
998 | ||
999 | static int linux_wlan_start_firmware(perInterface_wlan_t *nic) | |
1000 | { | |
1001 | ||
c5c77ba1 JK |
1002 | int ret = 0; |
1003 | /* start firmware */ | |
1004 | PRINT_D(INIT_DBG, "Starting Firmware ...\n"); | |
1005 | ret = g_linux_wlan->oup.wlan_start(); | |
1006 | if (ret < 0) { | |
1007 | PRINT_ER("Failed to start Firmware\n"); | |
1008 | goto _fail_; | |
1009 | } | |
1010 | ||
1011 | /* wait for mac ready */ | |
1012 | PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n"); | |
1013 | ret = linux_wlan_lock_timeout(&g_linux_wlan->sync_event, 5000); | |
1014 | if (ret) { | |
1015 | #ifdef COMPLEMENT_BOOT | |
7a8fd841 | 1016 | static int timeout = 5; |
c5c77ba1 JK |
1017 | |
1018 | if (timeout--) { | |
1019 | PRINT_D(INIT_DBG, "repeat power cycle[%d]", timeout); | |
1020 | ret = repeat_power_cycle(nic); | |
1021 | } else { | |
1022 | timeout = 5; | |
1023 | ret = -1; | |
1024 | goto _fail_; | |
1025 | } | |
1026 | #endif | |
1027 | PRINT_D(INIT_DBG, "Firmware start timed out"); | |
1028 | goto _fail_; | |
1029 | } | |
1030 | /* | |
1031 | * TODO: Driver shouoldn't wait forever for firmware to get started - | |
1032 | * in case of timeout this should be handled properly | |
1033 | */ | |
1034 | PRINT_D(INIT_DBG, "Firmware successfully started\n"); | |
1035 | ||
1036 | _fail_: | |
1037 | return ret; | |
1038 | } | |
1039 | static int linux_wlan_firmware_download(linux_wlan_t *p_nic) | |
1040 | { | |
1041 | ||
1042 | int ret = 0; | |
1043 | ||
1044 | if (g_linux_wlan->wilc_firmware == NULL) { | |
1045 | PRINT_ER("Firmware buffer is NULL\n"); | |
1046 | ret = -ENOBUFS; | |
1047 | goto _FAIL_; | |
1048 | } | |
1049 | /** | |
1050 | * do the firmware download | |
1051 | **/ | |
1052 | PRINT_D(INIT_DBG, "Downloading Firmware ...\n"); | |
1053 | ret = g_linux_wlan->oup.wlan_firmware_download(g_linux_wlan->wilc_firmware->data, g_linux_wlan->wilc_firmware->size); | |
1054 | if (ret < 0) { | |
1055 | goto _FAIL_; | |
1056 | } | |
1057 | ||
1058 | /* Freeing FW buffer */ | |
1059 | PRINT_D(INIT_DBG, "Freeing FW buffer ...\n"); | |
1060 | PRINT_D(INIT_DBG, "Releasing firmware\n"); | |
1061 | release_firmware(g_linux_wlan->wilc_firmware); | |
1062 | g_linux_wlan->wilc_firmware = NULL; | |
1063 | ||
1064 | PRINT_D(INIT_DBG, "Download Succeeded \n"); | |
1065 | ||
1066 | _FAIL_: | |
1067 | return ret; | |
1068 | } | |
1069 | ||
1070 | ||
1071 | /* startup configuration - could be changed later using iconfig*/ | |
1072 | static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_nic) | |
1073 | { | |
1074 | ||
1075 | unsigned char c_val[64]; | |
1076 | #ifndef STATIC_MACADDRESS | |
1077 | unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff}; | |
1078 | #endif | |
c5c77ba1 JK |
1079 | |
1080 | /*BugID_5077*/ | |
1081 | struct WILC_WFI_priv *priv; | |
1082 | tstrWILC_WFIDrv *pstrWFIDrv; | |
1083 | ||
1084 | PRINT_D(TX_DBG, "Start configuring Firmware\n"); | |
1085 | #ifndef STATIC_MACADDRESS | |
1086 | get_random_bytes(&mac_add[5], 1); | |
1087 | get_random_bytes(&mac_add[4], 1); | |
1088 | #endif | |
1089 | priv = wiphy_priv(dev->ieee80211_ptr->wiphy); | |
1090 | pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv; | |
8a14330f | 1091 | PRINT_D(INIT_DBG, "Host = %p\n", pstrWFIDrv); |
c5c77ba1 JK |
1092 | |
1093 | PRINT_D(INIT_DBG, "MAC address is : %02x-%02x-%02x-%02x-%02x-%02x\n", mac_add[0], mac_add[1], mac_add[2], mac_add[3], mac_add[4], mac_add[5]); | |
21175ef7 | 1094 | wilc_get_chipid(0); |
c5c77ba1 JK |
1095 | |
1096 | ||
1097 | if (g_linux_wlan->oup.wlan_cfg_set == NULL) { | |
1098 | PRINT_D(INIT_DBG, "Null p[ointer\n"); | |
1099 | goto _fail_; | |
1100 | } | |
1101 | ||
4e4467fd | 1102 | *(int *)c_val = (u32)pstrWFIDrv; |
c5c77ba1 JK |
1103 | |
1104 | if (!g_linux_wlan->oup.wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0)) | |
1105 | goto _fail_; | |
1106 | ||
1107 | /*to tell fw that we are going to use PC test - WILC specific*/ | |
1108 | c_val[0] = 0; | |
1109 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_PC_TEST_MODE, c_val, 1, 0, 0)) | |
1110 | goto _fail_; | |
1111 | ||
1112 | c_val[0] = INFRASTRUCTURE; | |
1113 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0)) | |
1114 | goto _fail_; | |
1115 | ||
1116 | ||
1117 | /* c_val[0] = RATE_AUTO; / * bug 4275: Enable autorate and limit it to 24Mbps * / */ | |
1118 | c_val[0] = RATE_AUTO; | |
1119 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0)) | |
1120 | goto _fail_; | |
1121 | ||
1122 | c_val[0] = G_MIXED_11B_2_MODE; | |
1123 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11G_OPERATING_MODE, c_val, 1, 0, 0)) | |
1124 | goto _fail_; | |
1125 | ||
1126 | c_val[0] = 1; | |
1127 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0)) | |
1128 | goto _fail_; | |
1129 | ||
1130 | c_val[0] = G_SHORT_PREAMBLE; | |
1131 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_PREAMBLE, c_val, 1, 0, 0)) | |
1132 | goto _fail_; | |
1133 | ||
1134 | c_val[0] = AUTO_PROT; | |
1135 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_PROT_MECH, c_val, 1, 0, 0)) | |
1136 | goto _fail_; | |
1137 | ||
1138 | #ifdef SWITCH_LOG_TERMINAL | |
1139 | c_val[0] = AUTO_PROT; | |
1140 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_LOGTerminal_Switch, c_val, 1, 0, 0)) | |
1141 | goto _fail_; | |
1142 | #endif | |
1143 | ||
1144 | c_val[0] = ACTIVE_SCAN; | |
1145 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SCAN_TYPE, c_val, 1, 0, 0)) | |
1146 | goto _fail_; | |
1147 | ||
1148 | c_val[0] = SITE_SURVEY_OFF; | |
1149 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SITE_SURVEY, c_val, 1, 0, 0)) | |
1150 | goto _fail_; | |
1151 | ||
1152 | *((int *)c_val) = 0xffff; /* Never use RTS-CTS */ | |
1153 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_RTS_THRESHOLD, c_val, 2, 0, 0)) | |
1154 | goto _fail_; | |
1155 | ||
1156 | *((int *)c_val) = 2346; | |
1157 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0)) | |
1158 | goto _fail_; | |
1159 | ||
1160 | /* SSID */ | |
1161 | /* -------------------------------------------------------------- */ | |
1162 | /* Configuration : String with length less than 32 bytes */ | |
1163 | /* Values to set : Any string with length less than 32 bytes */ | |
1164 | /* ( In BSS Station Set SSID to "" (null string) */ | |
1165 | /* to enable Broadcast SSID suppport ) */ | |
1166 | /* -------------------------------------------------------------- */ | |
1167 | #ifndef USE_WIRELESS | |
1168 | strcpy(c_val, "nwifi"); | |
1169 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SSID, c_val, (strlen(c_val) + 1), 0, 0)) | |
1170 | goto _fail_; | |
1171 | #endif | |
1172 | ||
1173 | c_val[0] = 0; | |
1174 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BCAST_SSID, c_val, 1, 0, 0)) | |
1175 | goto _fail_; | |
1176 | ||
1177 | c_val[0] = 1; | |
1178 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_QOS_ENABLE, c_val, 1, 0, 0)) | |
1179 | goto _fail_; | |
1180 | ||
1181 | c_val[0] = NO_POWERSAVE; | |
1182 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0)) | |
1183 | goto _fail_; | |
1184 | ||
1185 | c_val[0] = NO_ENCRYPT; /* NO_ENCRYPT, 0x79 */ | |
1186 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11I_MODE, c_val, 1, 0, 0)) | |
1187 | goto _fail_; | |
1188 | ||
1189 | c_val[0] = OPEN_SYSTEM; | |
1190 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_AUTH_TYPE, c_val, 1, 0, 0)) | |
1191 | goto _fail_; | |
1192 | ||
1193 | /* WEP/802 11I Configuration */ | |
1194 | /* ------------------------------------------------------------------ */ | |
1195 | /* Configuration : WEP Key */ | |
1196 | /* Values (0x) : 5 byte for WEP40 and 13 bytes for WEP104 */ | |
1197 | /* In case more than 5 bytes are passed on for WEP 40 */ | |
1198 | /* only first 5 bytes will be used as the key */ | |
1199 | /* ------------------------------------------------------------------ */ | |
1200 | ||
1201 | strcpy(c_val, "123456790abcdef1234567890"); | |
1202 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_WEP_KEY_VALUE, c_val, (strlen(c_val) + 1), 0, 0)) | |
1203 | goto _fail_; | |
1204 | ||
1205 | /* WEP/802 11I Configuration */ | |
1206 | /* ------------------------------------------------------------------ */ | |
1207 | /* Configuration : AES/TKIP WPA/RSNA Pre-Shared Key */ | |
1208 | /* Values to set : Any string with length greater than equal to 8 bytes */ | |
1209 | /* and less than 64 bytes */ | |
1210 | /* ------------------------------------------------------------------ */ | |
1211 | strcpy(c_val, "12345678"); | |
1212 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11I_PSK, c_val, (strlen(c_val)), 0, 0)) | |
1213 | goto _fail_; | |
1214 | ||
1215 | /* IEEE802.1X Key Configuration */ | |
1216 | /* ------------------------------------------------------------------ */ | |
1217 | /* Configuration : Radius Server Access Secret Key */ | |
1218 | /* Values to set : Any string with length greater than equal to 8 bytes */ | |
1219 | /* and less than 65 bytes */ | |
1220 | /* ------------------------------------------------------------------ */ | |
1221 | strcpy(c_val, "password"); | |
1222 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_1X_KEY, c_val, (strlen(c_val) + 1), 0, 0)) | |
1223 | goto _fail_; | |
1224 | ||
1225 | /* IEEE802.1X Server Address Configuration */ | |
1226 | /* ------------------------------------------------------------------ */ | |
1227 | /* Configuration : Radius Server IP Address */ | |
1228 | /* Values to set : Any valid IP Address */ | |
1229 | /* ------------------------------------------------------------------ */ | |
1230 | c_val[0] = 192; | |
1231 | c_val[1] = 168; | |
1232 | c_val[2] = 1; | |
1233 | c_val[3] = 112; | |
1234 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_1X_SERV_ADDR, c_val, 4, 0, 0)) | |
1235 | goto _fail_; | |
1236 | ||
1237 | c_val[0] = 3; | |
1238 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0)) | |
1239 | goto _fail_; | |
1240 | ||
1241 | c_val[0] = 3; | |
1242 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_DTIM_PERIOD, c_val, 1, 0, 0)) | |
1243 | goto _fail_; | |
1244 | ||
1245 | c_val[0] = NORMAL_ACK; | |
1246 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_ACK_POLICY, c_val, 1, 0, 0)) | |
1247 | goto _fail_; | |
1248 | ||
1249 | c_val[0] = 0; | |
1250 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, 0, 0)) | |
1251 | goto _fail_; | |
1252 | ||
1253 | c_val[0] = 48; | |
1254 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, 0)) | |
1255 | goto _fail_; | |
1256 | ||
1257 | c_val[0] = 28; | |
1258 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, 0)) | |
1259 | goto _fail_; | |
1260 | ||
1261 | /* Beacon Interval */ | |
1262 | /* -------------------------------------------------------------------- */ | |
1263 | /* Configuration : Sets the beacon interval value */ | |
1264 | /* Values to set : Any 16-bit value */ | |
1265 | /* -------------------------------------------------------------------- */ | |
1266 | ||
1267 | *((int *)c_val) = 100; | |
1268 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BEACON_INTERVAL, c_val, 2, 0, 0)) | |
1269 | goto _fail_; | |
1270 | ||
1271 | c_val[0] = REKEY_DISABLE; | |
1272 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_POLICY, c_val, 1, 0, 0)) | |
1273 | goto _fail_; | |
1274 | ||
1275 | /* Rekey Time (s) (Used only when the Rekey policy is 2 or 4) */ | |
1276 | /* -------------------------------------------------------------------- */ | |
1277 | /* Configuration : Sets the Rekey Time (s) */ | |
1278 | /* Values to set : 32-bit value */ | |
1279 | /* -------------------------------------------------------------------- */ | |
1280 | *((int *)c_val) = 84600; | |
1281 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_PERIOD, c_val, 4, 0, 0)) | |
1282 | goto _fail_; | |
1283 | ||
1284 | /* Rekey Packet Count (in 1000s; used when Rekey Policy is 3) */ | |
1285 | /* -------------------------------------------------------------------- */ | |
1286 | /* Configuration : Sets Rekey Group Packet count */ | |
1287 | /* Values to set : 32-bit Value */ | |
1288 | /* -------------------------------------------------------------------- */ | |
1289 | *((int *)c_val) = 500; | |
1290 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, 0)) | |
1291 | goto _fail_; | |
1292 | ||
1293 | c_val[0] = 1; | |
1294 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, 0)) | |
1295 | goto _fail_; | |
1296 | ||
1297 | c_val[0] = G_SELF_CTS_PROT; | |
1298 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0)) | |
1299 | goto _fail_; | |
1300 | ||
1301 | c_val[0] = 1; /* Enable N */ | |
1302 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_ENABLE, c_val, 1, 0, 0)) | |
1303 | goto _fail_; | |
1304 | ||
1305 | c_val[0] = HT_MIXED_MODE; | |
1306 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_OPERATING_MODE, c_val, 1, 0, 0)) | |
1307 | goto _fail_; | |
1308 | ||
1309 | c_val[0] = 1; /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */ | |
1310 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, 0)) | |
1311 | goto _fail_; | |
1312 | ||
1313 | memcpy(c_val, mac_add, 6); | |
1314 | ||
1315 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_MAC_ADDR, c_val, 6, 0, 0)) | |
1316 | goto _fail_; | |
1317 | ||
1318 | /** | |
1319 | * AP only | |
1320 | **/ | |
1321 | c_val[0] = DETECT_PROTECT_REPORT; | |
1322 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, 0, 0)) | |
1323 | goto _fail_; | |
1324 | ||
1325 | c_val[0] = RTS_CTS_NONHT_PROT; | |
1326 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0)) | |
1327 | goto _fail_; | |
1328 | ||
1329 | c_val[0] = 0; | |
1330 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, 0)) | |
1331 | goto _fail_; | |
1332 | ||
1333 | c_val[0] = MIMO_MODE; | |
1334 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_SMPS_MODE, c_val, 1, 0, 0)) | |
1335 | goto _fail_; | |
1336 | ||
1337 | c_val[0] = 7; | |
1338 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, 0)) | |
1339 | goto _fail_; | |
1340 | ||
1341 | c_val[0] = 1; /* Enable N with immediate block ack. */ | |
4e4467fd | 1342 | if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, (u32)pstrWFIDrv)) |
c5c77ba1 JK |
1343 | goto _fail_; |
1344 | ||
1345 | return 0; | |
1346 | ||
1347 | _fail_: | |
1348 | return -1; | |
1349 | } | |
1350 | ||
1351 | ||
1352 | /**************************/ | |
1353 | void wilc1000_wlan_deinit(linux_wlan_t *nic) | |
1354 | { | |
1355 | ||
1356 | if (g_linux_wlan->wilc1000_initialized) { | |
1357 | ||
1358 | printk("Deinitializing wilc1000 ...\n"); | |
1359 | ||
1360 | if (nic == NULL) { | |
1361 | PRINT_ER("nic is NULL\n"); | |
1362 | return; | |
1363 | } | |
1364 | ||
1365 | #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31) | |
1366 | /* johnny : remove */ | |
1367 | PRINT_D(INIT_DBG, "skip wilc_bus_set_default_speed\n"); | |
1368 | #else | |
1369 | wilc_bus_set_default_speed(); | |
1370 | #endif | |
1371 | ||
1372 | PRINT_D(INIT_DBG, "Disabling IRQ\n"); | |
1373 | #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO) | |
1374 | linux_wlan_disable_irq(IRQ_WAIT); | |
1375 | #else | |
1376 | #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31) | |
1377 | ||
1378 | #else | |
1379 | linux_wlan_lock_mutex((void *)&g_linux_wlan->hif_cs); | |
1380 | disable_sdio_interrupt(); | |
1381 | linux_wlan_unlock_mutex((void *)&g_linux_wlan->hif_cs); | |
1382 | #endif | |
1383 | #endif | |
1384 | ||
1385 | ||
1386 | /* not sure if the following unlocks are needed or not*/ | |
1387 | if (&g_linux_wlan->rxq_event != NULL) { | |
1388 | linux_wlan_unlock(&g_linux_wlan->rxq_event); | |
1389 | } | |
1390 | ||
1391 | if (&g_linux_wlan->txq_event != NULL) { | |
1392 | linux_wlan_unlock(&g_linux_wlan->txq_event); | |
1393 | } | |
1394 | ||
1395 | ||
1396 | #if (RX_BH_TYPE == RX_BH_WORK_QUEUE) | |
1397 | /*Removing the work struct from the linux kernel workqueue*/ | |
1398 | if (&g_linux_wlan->rx_work_queue != NULL) | |
1399 | flush_work(&g_linux_wlan->rx_work_queue); | |
1400 | ||
1401 | #elif (RX_BH_TYPE == RX_BH_KTHREAD) | |
1402 | /* if(&nic->rx_sem != NULL) */ | |
1403 | /* linux_wlan_unlock(&nic->rx_sem); */ | |
1404 | #endif | |
1405 | ||
1406 | PRINT_D(INIT_DBG, "Deinitializing Threads\n"); | |
1407 | wlan_deinitialize_threads(nic); | |
1408 | ||
1409 | PRINT_D(INIT_DBG, "Deinitializing IRQ\n"); | |
1410 | deinit_irq(g_linux_wlan); | |
1411 | ||
1412 | ||
1413 | if (&g_linux_wlan->oup != NULL) { | |
1414 | if (g_linux_wlan->oup.wlan_stop != NULL) | |
1415 | g_linux_wlan->oup.wlan_stop(); | |
1416 | } | |
1417 | ||
1418 | PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n"); | |
1419 | wilc_wlan_deinit(nic); | |
1420 | #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) | |
1421 | #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31) | |
1422 | PRINT_D(INIT_DBG, "Disabling IRQ 2\n"); | |
1423 | ||
1424 | linux_wlan_lock_mutex((void *)&g_linux_wlan->hif_cs); | |
1425 | disable_sdio_interrupt(); | |
1426 | linux_wlan_unlock_mutex((void *)&g_linux_wlan->hif_cs); | |
1427 | #endif | |
1428 | #endif | |
1429 | ||
1430 | /*De-Initialize locks*/ | |
1431 | PRINT_D(INIT_DBG, "Deinitializing Locks\n"); | |
1432 | wlan_deinit_locks(g_linux_wlan); | |
1433 | ||
1434 | /* announce that wilc1000 is not initialized */ | |
1435 | g_linux_wlan->wilc1000_initialized = 0; | |
1436 | ||
1437 | PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n"); | |
1438 | ||
1439 | } else { | |
1440 | PRINT_D(INIT_DBG, "wilc1000 is not initialized\n"); | |
1441 | } | |
1442 | return; | |
1443 | } | |
1444 | ||
1445 | int wlan_init_locks(linux_wlan_t *p_nic) | |
1446 | { | |
1447 | ||
1448 | PRINT_D(INIT_DBG, "Initializing Locks ...\n"); | |
1449 | ||
1450 | /*initialize mutexes*/ | |
1451 | linux_wlan_init_mutex("hif_lock/hif_cs", &g_linux_wlan->hif_cs, 1); | |
1452 | linux_wlan_init_mutex("rxq_lock/rxq_cs", &g_linux_wlan->rxq_cs, 1); | |
1453 | linux_wlan_init_mutex("txq_lock/txq_cs", &g_linux_wlan->txq_cs, 1); | |
1454 | ||
1455 | /*Added by Amr - BugID_4720*/ | |
1456 | linux_wlan_init_spin_lock("txq_spin_lock/txq_cs", &g_linux_wlan->txq_spinlock, 1); | |
1457 | ||
1458 | /*Added by Amr - BugID_4720*/ | |
1459 | linux_wlan_init_lock("txq_add_to_head_lock/txq_cs", &g_linux_wlan->txq_add_to_head_cs, 1); | |
1460 | ||
1461 | linux_wlan_init_lock("txq_wait/txq_event", &g_linux_wlan->txq_event, 0); | |
1462 | linux_wlan_init_lock("rxq_wait/rxq_event", &g_linux_wlan->rxq_event, 0); | |
1463 | ||
1464 | linux_wlan_init_lock("cfg_wait/cfg_event", &g_linux_wlan->cfg_event, 0); | |
1465 | linux_wlan_init_lock("sync_event", &g_linux_wlan->sync_event, 0); | |
1466 | ||
1467 | linux_wlan_init_lock("rxq_lock/rxq_started", &g_linux_wlan->rxq_thread_started, 0); | |
1468 | linux_wlan_init_lock("rxq_lock/txq_started", &g_linux_wlan->txq_thread_started, 0); | |
1469 | ||
1470 | #if (RX_BH_TYPE == RX_BH_KTHREAD) | |
1471 | linux_wlan_init_lock("BH_SEM", &g_linux_wlan->rx_sem, 0); | |
1472 | #endif | |
1473 | ||
1474 | return 0; | |
1475 | } | |
1476 | ||
1477 | static int wlan_deinit_locks(linux_wlan_t *nic) | |
1478 | { | |
1479 | PRINT_D(INIT_DBG, "De-Initializing Locks\n"); | |
1480 | ||
1481 | if (&g_linux_wlan->hif_cs != NULL) | |
1482 | linux_wlan_deinit_mutex(&g_linux_wlan->hif_cs); | |
1483 | ||
1484 | if (&g_linux_wlan->rxq_cs != NULL) | |
1485 | linux_wlan_deinit_mutex(&g_linux_wlan->rxq_cs); | |
1486 | ||
1487 | if (&g_linux_wlan->txq_cs != NULL) | |
1488 | linux_wlan_deinit_mutex(&g_linux_wlan->txq_cs); | |
1489 | ||
1490 | /*Added by Amr - BugID_4720*/ | |
1491 | if (&g_linux_wlan->txq_spinlock != NULL) | |
1492 | linux_wlan_deinit_spin_lock(&g_linux_wlan->txq_spinlock); | |
1493 | ||
1494 | if (&g_linux_wlan->rxq_event != NULL) | |
1495 | linux_wlan_deinit_lock(&g_linux_wlan->rxq_event); | |
1496 | ||
1497 | if (&g_linux_wlan->txq_event != NULL) | |
1498 | linux_wlan_deinit_lock(&g_linux_wlan->txq_event); | |
1499 | ||
1500 | /*Added by Amr - BugID_4720*/ | |
1501 | if (&g_linux_wlan->txq_add_to_head_cs != NULL) | |
1502 | linux_wlan_deinit_lock(&g_linux_wlan->txq_add_to_head_cs); | |
1503 | ||
1504 | if (&g_linux_wlan->rxq_thread_started != NULL) | |
1505 | linux_wlan_deinit_lock(&g_linux_wlan->rxq_thread_started); | |
1506 | ||
1507 | if (&g_linux_wlan->txq_thread_started != NULL) | |
1508 | linux_wlan_deinit_lock(&g_linux_wlan->txq_thread_started); | |
1509 | ||
1510 | if (&g_linux_wlan->cfg_event != NULL) | |
1511 | linux_wlan_deinit_lock(&g_linux_wlan->cfg_event); | |
1512 | ||
1513 | if (&g_linux_wlan->sync_event != NULL) | |
1514 | linux_wlan_deinit_lock(&g_linux_wlan->sync_event); | |
1515 | ||
1516 | return 0; | |
1517 | } | |
1518 | void linux_to_wlan(wilc_wlan_inp_t *nwi, linux_wlan_t *nic) | |
1519 | { | |
1520 | ||
1521 | PRINT_D(INIT_DBG, "Linux to Wlan services ...\n"); | |
1522 | ||
1523 | nwi->os_context.hif_critical_section = (void *)&g_linux_wlan->hif_cs; | |
1524 | nwi->os_context.os_private = (void *)nic; | |
1525 | nwi->os_context.tx_buffer_size = LINUX_TX_SIZE; | |
1526 | nwi->os_context.txq_critical_section = (void *)&g_linux_wlan->txq_cs; | |
1527 | ||
1528 | /*Added by Amr - BugID_4720*/ | |
1529 | nwi->os_context.txq_add_to_head_critical_section = (void *)&g_linux_wlan->txq_add_to_head_cs; | |
1530 | ||
1531 | /*Added by Amr - BugID_4720*/ | |
1532 | nwi->os_context.txq_spin_lock = (void *)&g_linux_wlan->txq_spinlock; | |
1533 | ||
1534 | nwi->os_context.txq_wait_event = (void *)&g_linux_wlan->txq_event; | |
1535 | ||
1536 | #if defined (MEMORY_STATIC) | |
1537 | nwi->os_context.rx_buffer_size = LINUX_RX_SIZE; | |
1538 | #endif | |
1539 | nwi->os_context.rxq_critical_section = (void *)&g_linux_wlan->rxq_cs; | |
1540 | nwi->os_context.rxq_wait_event = (void *)&g_linux_wlan->rxq_event; | |
1541 | nwi->os_context.cfg_wait_event = (void *)&g_linux_wlan->cfg_event; | |
1542 | ||
1543 | nwi->os_func.os_sleep = linux_wlan_msleep; | |
1544 | nwi->os_func.os_atomic_sleep = linux_wlan_atomic_msleep; | |
1545 | nwi->os_func.os_debug = linux_wlan_dbg; | |
1546 | nwi->os_func.os_malloc = linux_wlan_malloc; | |
1547 | nwi->os_func.os_malloc_atomic = linux_wlan_malloc_atomic; | |
1548 | nwi->os_func.os_free = linux_wlan_free; | |
1549 | nwi->os_func.os_lock = linux_wlan_lock; | |
1550 | nwi->os_func.os_unlock = linux_wlan_unlock; | |
1551 | nwi->os_func.os_wait = linux_wlan_lock_timeout; | |
1552 | nwi->os_func.os_signal = linux_wlan_unlock; | |
1553 | nwi->os_func.os_enter_cs = linux_wlan_lock_mutex; | |
1554 | nwi->os_func.os_leave_cs = linux_wlan_unlock_mutex; | |
1555 | ||
1556 | /*Added by Amr - BugID_4720*/ | |
1557 | nwi->os_func.os_spin_lock = linux_wlan_spin_lock; | |
1558 | nwi->os_func.os_spin_unlock = linux_wlan_spin_unlock; | |
1559 | ||
1560 | #ifdef WILC_SDIO | |
1561 | nwi->io_func.io_type = HIF_SDIO; | |
1562 | nwi->io_func.io_init = linux_sdio_init; | |
1563 | nwi->io_func.io_deinit = linux_sdio_deinit; | |
1564 | nwi->io_func.u.sdio.sdio_cmd52 = linux_sdio_cmd52; | |
1565 | nwi->io_func.u.sdio.sdio_cmd53 = linux_sdio_cmd53; | |
1566 | nwi->io_func.u.sdio.sdio_set_max_speed = linux_sdio_set_max_speed; | |
1567 | nwi->io_func.u.sdio.sdio_set_default_speed = linux_sdio_set_default_speed; | |
1568 | #else | |
1569 | nwi->io_func.io_type = HIF_SPI; | |
1570 | nwi->io_func.io_init = linux_spi_init; | |
1571 | nwi->io_func.io_deinit = linux_spi_deinit; | |
1572 | nwi->io_func.u.spi.spi_tx = linux_spi_write; | |
1573 | nwi->io_func.u.spi.spi_rx = linux_spi_read; | |
1574 | nwi->io_func.u.spi.spi_trx = linux_spi_write_read; | |
1575 | nwi->io_func.u.spi.spi_max_speed = linux_spi_set_max_speed; | |
1576 | #endif | |
1577 | ||
1578 | /*for now - to be revised*/ | |
1579 | #ifdef WILC_FULLY_HOSTING_AP | |
1580 | /* incase of Fully hosted AP, all non cfg pkts are processed here*/ | |
1581 | nwi->net_func.rx_indicate = WILC_Process_rx_frame; | |
1582 | #else | |
1583 | nwi->net_func.rx_indicate = frmw_to_linux; | |
1584 | #endif | |
1585 | nwi->net_func.rx_complete = linux_wlan_rx_complete; | |
1586 | nwi->indicate_func.mac_indicate = linux_wlan_mac_indicate; | |
1587 | } | |
1588 | ||
1589 | int wlan_initialize_threads(perInterface_wlan_t *nic) | |
1590 | { | |
1591 | ||
1592 | int ret = 0; | |
1593 | PRINT_D(INIT_DBG, "Initializing Threads ...\n"); | |
1594 | ||
1595 | #if (RX_BH_TYPE == RX_BH_WORK_QUEUE) | |
1596 | /*Initialize rx work queue task*/ | |
1597 | INIT_WORK(&g_linux_wlan->rx_work_queue, isr_bh_routine); | |
1598 | #elif (RX_BH_TYPE == RX_BH_KTHREAD) | |
1599 | PRINT_D(INIT_DBG, "Creating kthread for Rxq BH\n"); | |
1600 | g_linux_wlan->rx_bh_thread = kthread_run(isr_bh_routine, (void *)g_linux_wlan, "K_RXQ_BH"); | |
1601 | if (g_linux_wlan->rx_bh_thread == 0) { | |
1602 | PRINT_ER("couldn't create RX BH thread\n"); | |
1603 | ret = -ENOBUFS; | |
1604 | goto _fail_; | |
1605 | } | |
1606 | #endif | |
1607 | ||
1608 | #ifndef TCP_ENHANCEMENTS | |
1609 | /* create rx task */ | |
1610 | PRINT_D(INIT_DBG, "Creating kthread for reception\n"); | |
1611 | g_linux_wlan->rxq_thread = kthread_run(linux_wlan_rxq_task, (void *)g_linux_wlan, "K_RXQ_TASK"); | |
1612 | if (g_linux_wlan->rxq_thread == 0) { | |
1613 | PRINT_ER("couldn't create RXQ thread\n"); | |
1614 | ret = -ENOBUFS; | |
1615 | goto _fail_1; | |
1616 | } | |
1617 | ||
1618 | /* wait for RXQ task to start. */ | |
1619 | linux_wlan_lock(&g_linux_wlan->rxq_thread_started); | |
1620 | ||
1621 | #endif | |
1622 | ||
1623 | /* create tx task */ | |
1624 | PRINT_D(INIT_DBG, "Creating kthread for transmission\n"); | |
1625 | g_linux_wlan->txq_thread = kthread_run(linux_wlan_txq_task, (void *)g_linux_wlan, "K_TXQ_TASK"); | |
1626 | if (g_linux_wlan->txq_thread == 0) { | |
1627 | PRINT_ER("couldn't create TXQ thread\n"); | |
1628 | ret = -ENOBUFS; | |
1629 | goto _fail_2; | |
1630 | } | |
1631 | #ifdef DEBUG_MODE | |
1632 | PRINT_D(INIT_DBG, "Creating kthread for Debugging\n"); | |
1633 | g_linux_wlan->txq_thread = kthread_run(DebuggingThreadTask, (void *)g_linux_wlan, "DebugThread"); | |
1634 | if (g_linux_wlan->txq_thread == 0) { | |
1635 | PRINT_ER("couldn't create TXQ thread\n"); | |
1636 | ret = -ENOBUFS; | |
1637 | goto _fail_2; | |
1638 | } | |
1639 | #endif | |
1640 | /* wait for TXQ task to start. */ | |
1641 | linux_wlan_lock(&g_linux_wlan->txq_thread_started); | |
1642 | ||
1643 | return 0; | |
1644 | ||
1645 | _fail_2: | |
1646 | /*De-Initialize 2nd thread*/ | |
1647 | g_linux_wlan->close = 1; | |
1648 | linux_wlan_unlock(&g_linux_wlan->rxq_event); | |
1649 | kthread_stop(g_linux_wlan->rxq_thread); | |
1650 | ||
7a8fd841 | 1651 | #ifndef TCP_ENHANCEMENTS |
c5c77ba1 | 1652 | _fail_1: |
7a8fd841 | 1653 | #endif |
c5c77ba1 JK |
1654 | #if (RX_BH_TYPE == RX_BH_KTHREAD) |
1655 | /*De-Initialize 1st thread*/ | |
1656 | g_linux_wlan->close = 1; | |
1657 | linux_wlan_unlock(&g_linux_wlan->rx_sem); | |
1658 | kthread_stop(g_linux_wlan->rx_bh_thread); | |
1659 | _fail_: | |
1660 | #endif | |
1661 | g_linux_wlan->close = 0; | |
1662 | return ret; | |
1663 | } | |
1664 | ||
1665 | static void wlan_deinitialize_threads(linux_wlan_t *nic) | |
1666 | { | |
1667 | ||
1668 | g_linux_wlan->close = 1; | |
1669 | PRINT_D(INIT_DBG, "Deinitializing Threads\n"); | |
1670 | if (&g_linux_wlan->rxq_event != NULL) | |
1671 | linux_wlan_unlock(&g_linux_wlan->rxq_event); | |
1672 | ||
1673 | ||
1674 | if (g_linux_wlan->rxq_thread != NULL) { | |
1675 | kthread_stop(g_linux_wlan->rxq_thread); | |
1676 | g_linux_wlan->rxq_thread = NULL; | |
1677 | } | |
1678 | ||
1679 | ||
1680 | if (&g_linux_wlan->txq_event != NULL) | |
1681 | linux_wlan_unlock(&g_linux_wlan->txq_event); | |
1682 | ||
1683 | ||
1684 | if (g_linux_wlan->txq_thread != NULL) { | |
1685 | kthread_stop(g_linux_wlan->txq_thread); | |
1686 | g_linux_wlan->txq_thread = NULL; | |
1687 | } | |
1688 | ||
1689 | #if (RX_BH_TYPE == RX_BH_KTHREAD) | |
1690 | if (&g_linux_wlan->rx_sem != NULL) | |
1691 | linux_wlan_unlock(&g_linux_wlan->rx_sem); | |
1692 | ||
1693 | if (g_linux_wlan->rx_bh_thread != NULL) { | |
1694 | kthread_stop(g_linux_wlan->rx_bh_thread); | |
1695 | g_linux_wlan->rx_bh_thread = NULL; | |
1696 | } | |
1697 | #endif | |
1698 | } | |
1699 | ||
1700 | #ifdef STATIC_MACADDRESS | |
1701 | const char *path_string[] = { | |
1702 | "/etc/wlan", | |
1703 | "/data/wlan", | |
1704 | }; | |
1705 | ||
1706 | static int linux_wlan_read_mac_addr(void *vp) | |
1707 | { | |
1708 | int ret = 0; | |
1709 | struct file *fp = (struct file *)-ENOENT; | |
1710 | mm_segment_t old_fs; | |
1711 | loff_t pos = 0; | |
1712 | int index; | |
0feae200 | 1713 | int array_size = ARRAY_SIZE(path_string); |
c5c77ba1 JK |
1714 | |
1715 | /* change to KERNEL_DS address limit */ | |
1716 | old_fs = get_fs(); | |
1717 | set_fs(KERNEL_DS); | |
1718 | ||
1719 | for (index = 0; index < array_size; index++) { | |
1720 | fp = filp_open(path_string[index], O_WRONLY, 0640); | |
1721 | if (!fp) { | |
1722 | ret = -1; | |
1723 | goto exit; | |
1724 | } | |
1725 | ||
1726 | /*No such file or directory */ | |
1727 | if (IS_ERR(fp) || !fp->f_op) { | |
1728 | get_random_bytes(&mac_add[3], 3); | |
1729 | /* open file to write */ | |
1730 | fp = filp_open(path_string[index], O_WRONLY | O_CREAT, 0640); | |
1731 | ||
1732 | if (!fp || IS_ERR(fp)) { | |
1733 | ret = -1; | |
1734 | continue; | |
1735 | } else { | |
1736 | /* write buf to file */ | |
1737 | fp->f_op->write(fp, mac_add, 6, &pos); | |
1738 | break; | |
1739 | } | |
1740 | } else { | |
1741 | /* read file to buf */ | |
1742 | fp->f_op->read(fp, mac_add, 6, &pos); | |
1743 | break; | |
1744 | } | |
1745 | } | |
1746 | ||
1747 | if (index == array_size) { | |
1748 | PRINT_ER("random MAC\n"); | |
1749 | } | |
1750 | ||
1751 | exit: | |
1752 | if (fp && !IS_ERR(fp)) { | |
1753 | filp_close(fp, NULL); | |
1754 | } | |
1755 | ||
1756 | set_fs(old_fs); | |
1757 | ||
1758 | return ret; | |
1759 | } | |
1760 | #endif | |
1761 | ||
1762 | #ifdef COMPLEMENT_BOOT | |
1763 | ||
1764 | extern volatile int probe; | |
1765 | extern uint8_t core_11b_ready(void); | |
1766 | ||
1767 | #define READY_CHECK_THRESHOLD 30 | |
1768 | extern void wilc_wlan_global_reset(void); | |
1769 | uint8_t wilc1000_prepare_11b_core(wilc_wlan_inp_t *nwi, wilc_wlan_oup_t *nwo, linux_wlan_t *nic) | |
1770 | { | |
1771 | uint8_t trials = 0; | |
1772 | while ((core_11b_ready() && (READY_CHECK_THRESHOLD > (trials++)))) { | |
1773 | PRINT_D(INIT_DBG, "11b core not ready yet: %u\n", trials); | |
1774 | wilc_wlan_deinit(nic); | |
1775 | wilc_wlan_global_reset(); | |
1776 | sdio_unregister_driver(&wilc_bus); | |
1777 | ||
1778 | linux_wlan_device_detection(0); | |
1779 | ||
1780 | mdelay(100); | |
1781 | ||
1782 | linux_wlan_device_detection(1); | |
1783 | ||
1784 | sdio_register_driver(&wilc_bus); | |
1785 | ||
1786 | while (!probe) { | |
1787 | msleep(100); | |
1788 | } | |
1789 | probe = 0; | |
1790 | g_linux_wlan->wilc_sdio_func = local_sdio_func; | |
1791 | linux_to_wlan(nwi, nic); | |
1792 | wilc_wlan_init(nwi, nwo); | |
1793 | } | |
1794 | ||
1795 | if (READY_CHECK_THRESHOLD <= trials) | |
1796 | return 1; | |
1797 | else | |
1798 | return 0; | |
1799 | ||
1800 | } | |
1801 | ||
1802 | int repeat_power_cycle(perInterface_wlan_t *nic) | |
1803 | { | |
1804 | int ret = 0; | |
1805 | wilc_wlan_inp_t nwi; | |
1806 | wilc_wlan_oup_t nwo; | |
1807 | sdio_unregister_driver(&wilc_bus); | |
1808 | ||
1809 | linux_wlan_device_detection(0); | |
1810 | linux_wlan_device_power(0); | |
1811 | msleep(100); | |
1812 | linux_wlan_device_power(1); | |
1813 | msleep(80); | |
1814 | linux_wlan_device_detection(1); | |
1815 | msleep(20); | |
1816 | ||
1817 | sdio_register_driver(&wilc_bus); | |
1818 | ||
1819 | /* msleep(1000); */ | |
1820 | while (!probe) { | |
1821 | msleep(100); | |
1822 | } | |
1823 | probe = 0; | |
1824 | g_linux_wlan->wilc_sdio_func = local_sdio_func; | |
1825 | linux_to_wlan(&nwi, g_linux_wlan); | |
1826 | ret = wilc_wlan_init(&nwi, &nwo); | |
1827 | ||
1828 | g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT; | |
1829 | #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) | |
1830 | enable_sdio_interrupt(); | |
1831 | #endif | |
1832 | ||
1833 | if (linux_wlan_get_firmware(nic)) { | |
1834 | PRINT_ER("Can't get firmware \n"); | |
1835 | ret = -1; | |
1836 | goto __fail__; | |
1837 | } | |
1838 | ||
1839 | /*Download firmware*/ | |
1840 | ret = linux_wlan_firmware_download(g_linux_wlan); | |
1841 | if (ret < 0) { | |
1842 | PRINT_ER("Failed to download firmware\n"); | |
1843 | goto __fail__; | |
1844 | } | |
1845 | /* Start firmware*/ | |
1846 | ret = linux_wlan_start_firmware(nic); | |
1847 | if (ret < 0) { | |
1848 | PRINT_ER("Failed to start firmware\n"); | |
1849 | } | |
1850 | __fail__: | |
1851 | return ret; | |
1852 | } | |
1853 | #endif | |
1854 | ||
1855 | int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic) | |
1856 | { | |
1857 | wilc_wlan_inp_t nwi; | |
1858 | wilc_wlan_oup_t nwo; | |
1859 | perInterface_wlan_t *nic = p_nic; | |
1860 | int ret = 0; | |
1861 | ||
1862 | if (!g_linux_wlan->wilc1000_initialized) { | |
1863 | g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT; | |
1864 | g_linux_wlan->close = 0; | |
1865 | g_linux_wlan->wilc1000_initialized = 0; | |
1866 | ||
1867 | wlan_init_locks(g_linux_wlan); | |
1868 | ||
1869 | #ifdef STATIC_MACADDRESS | |
1870 | wilc_mac_thread = kthread_run(linux_wlan_read_mac_addr, NULL, "wilc_mac_thread"); | |
1871 | if (wilc_mac_thread < 0) { | |
1872 | PRINT_ER("couldn't create Mac addr thread\n"); | |
1873 | } | |
1874 | #endif | |
1875 | ||
1876 | linux_to_wlan(&nwi, g_linux_wlan); | |
1877 | ||
1878 | ret = wilc_wlan_init(&nwi, &nwo); | |
1879 | if (ret < 0) { | |
1880 | PRINT_ER("Initializing WILC_Wlan FAILED\n"); | |
1881 | ret = -EIO; | |
1882 | goto _fail_locks_; | |
1883 | } | |
1884 | memcpy(&g_linux_wlan->oup, &nwo, sizeof(wilc_wlan_oup_t)); | |
1885 | ||
1886 | /*Save the oup structre into global pointer*/ | |
1887 | gpstrWlanOps = &g_linux_wlan->oup; | |
1888 | ||
1889 | ||
1890 | ret = wlan_initialize_threads(nic); | |
1891 | if (ret < 0) { | |
1892 | PRINT_ER("Initializing Threads FAILED\n"); | |
1893 | ret = -EIO; | |
1894 | goto _fail_wilc_wlan_; | |
1895 | } | |
1896 | ||
1897 | #if (defined WILC_SDIO) && (defined COMPLEMENT_BOOT) | |
1898 | if (wilc1000_prepare_11b_core(&nwi, &nwo, g_linux_wlan)) { | |
1899 | PRINT_ER("11b Core is not ready\n"); | |
1900 | ret = -EIO; | |
1901 | goto _fail_threads_; | |
1902 | } | |
1903 | #endif | |
1904 | ||
1905 | #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO) | |
1906 | if (init_irq(g_linux_wlan)) { | |
1907 | PRINT_ER("couldn't initialize IRQ\n"); | |
1908 | ret = -EIO; | |
1909 | goto _fail_threads_; | |
1910 | } | |
1911 | #endif | |
1912 | ||
1913 | #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) | |
1914 | if (enable_sdio_interrupt()) { | |
1915 | PRINT_ER("couldn't initialize IRQ\n"); | |
1916 | ret = -EIO; | |
1917 | goto _fail_irq_init_; | |
1918 | } | |
1919 | #endif | |
1920 | ||
1921 | if (linux_wlan_get_firmware(nic)) { | |
1922 | PRINT_ER("Can't get firmware \n"); | |
1923 | ret = -EIO; | |
1924 | goto _fail_irq_enable_; | |
1925 | } | |
1926 | ||
1927 | ||
1928 | /*Download firmware*/ | |
1929 | ret = linux_wlan_firmware_download(g_linux_wlan); | |
1930 | if (ret < 0) { | |
1931 | PRINT_ER("Failed to download firmware\n"); | |
1932 | ret = -EIO; | |
1933 | goto _fail_irq_enable_; | |
1934 | } | |
1935 | ||
1936 | /* Start firmware*/ | |
1937 | ret = linux_wlan_start_firmware(nic); | |
1938 | if (ret < 0) { | |
1939 | PRINT_ER("Failed to start firmware\n"); | |
1940 | ret = -EIO; | |
1941 | goto _fail_irq_enable_; | |
1942 | } | |
1943 | ||
1944 | wilc_bus_set_max_speed(); | |
1945 | ||
1946 | if (g_linux_wlan->oup.wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) { | |
1947 | int size; | |
1948 | char Firmware_ver[20]; | |
1949 | size = g_linux_wlan->oup.wlan_cfg_get_value( | |
1950 | WID_FIRMWARE_VERSION, | |
1951 | Firmware_ver, sizeof(Firmware_ver)); | |
1952 | Firmware_ver[size] = '\0'; | |
1953 | PRINT_D(INIT_DBG, "***** Firmware Ver = %s *******\n", Firmware_ver); | |
1954 | } | |
1955 | /* Initialize firmware with default configuration */ | |
1956 | ret = linux_wlan_init_test_config(dev, g_linux_wlan); | |
1957 | ||
1958 | if (ret < 0) { | |
1959 | PRINT_ER("Failed to configure firmware\n"); | |
1960 | ret = -EIO; | |
1961 | goto _fail_fw_start_; | |
1962 | } | |
1963 | ||
1964 | g_linux_wlan->wilc1000_initialized = 1; | |
1965 | return 0; /*success*/ | |
1966 | ||
1967 | ||
1968 | _fail_fw_start_: | |
1969 | if (&g_linux_wlan->oup != NULL) { | |
1970 | if (g_linux_wlan->oup.wlan_stop != NULL) | |
1971 | g_linux_wlan->oup.wlan_stop(); | |
1972 | } | |
1973 | ||
1974 | _fail_irq_enable_: | |
1975 | #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) | |
1976 | disable_sdio_interrupt(); | |
c5c77ba1 | 1977 | _fail_irq_init_: |
7a8fd841 | 1978 | #endif |
c5c77ba1 JK |
1979 | #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO) |
1980 | deinit_irq(g_linux_wlan); | |
1981 | ||
1982 | #endif | |
1983 | _fail_threads_: | |
1984 | wlan_deinitialize_threads(g_linux_wlan); | |
1985 | _fail_wilc_wlan_: | |
1986 | wilc_wlan_deinit(g_linux_wlan); | |
1987 | _fail_locks_: | |
1988 | wlan_deinit_locks(g_linux_wlan); | |
1989 | PRINT_ER("WLAN Iinitialization FAILED\n"); | |
1990 | } else { | |
1991 | PRINT_D(INIT_DBG, "wilc1000 already initialized\n"); | |
1992 | } | |
1993 | return ret; | |
1994 | } | |
1995 | ||
1996 | ||
1997 | /* | |
1998 | * - this function will be called automatically by OS when module inserted. | |
1999 | */ | |
2000 | ||
2001 | #if !defined (NM73131_0_BOARD) | |
2002 | int mac_init_fn(struct net_device *ndev) | |
2003 | { | |
2004 | ||
2005 | /*Why we do this !!!*/ | |
2006 | netif_start_queue(ndev); /* ma */ | |
2007 | netif_stop_queue(ndev); /* ma */ | |
2008 | ||
2009 | return 0; | |
2010 | } | |
2011 | #else | |
2012 | int mac_init_fn(struct net_device *ndev) | |
2013 | { | |
2014 | ||
2015 | unsigned char mac_add[] = {0x00, 0x50, 0xc2, 0x5e, 0x10, 0x00}; | |
2016 | /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/ | |
2017 | memcpy(ndev->dev_addr, mac_add, 6); | |
2018 | ||
2019 | if (!is_valid_ether_addr(ndev->dev_addr)) { | |
2020 | PRINT_ER("Error: Wrong MAC address\n"); | |
2021 | return -EINVAL; | |
2022 | } | |
2023 | ||
2024 | return 0; | |
2025 | } | |
2026 | #endif | |
2027 | ||
2028 | ||
2029 | void WILC_WFI_frame_register(struct wiphy *wiphy, struct net_device *dev, | |
2030 | u16 frame_type, bool reg); | |
2031 | ||
2032 | /* This fn is called, when this device is setup using ifconfig */ | |
2033 | #if !defined (NM73131_0_BOARD) | |
2034 | int mac_open(struct net_device *ndev) | |
2035 | { | |
2036 | perInterface_wlan_t *nic; | |
2037 | ||
2038 | /*BugID_5213*/ | |
2039 | /*No need for setting mac address here anymore,*/ | |
2040 | /*Just set it in init_test_config()*/ | |
2041 | unsigned char mac_add[ETH_ALEN] = {0}; | |
c5c77ba1 JK |
2042 | int ret = 0; |
2043 | int i = 0; | |
2044 | struct WILC_WFI_priv *priv; | |
2045 | ||
2046 | nic = netdev_priv(ndev); | |
2047 | priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy); | |
2048 | PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev); | |
2049 | ||
2050 | #ifdef USE_WIRELESS | |
2051 | ret = WILC_WFI_InitHostInt(ndev); | |
2052 | if (ret < 0) { | |
2053 | PRINT_ER("Failed to initialize host interface\n"); | |
2054 | ||
2055 | return ret; | |
2056 | } | |
2057 | #endif | |
2058 | ||
2059 | /*initialize platform*/ | |
2060 | PRINT_D(INIT_DBG, "*** re-init ***\n"); | |
2061 | ret = wilc1000_wlan_init(ndev, nic); | |
2062 | if (ret < 0) { | |
2063 | PRINT_ER("Failed to initialize wilc1000\n"); | |
2064 | WILC_WFI_DeInitHostInt(ndev); | |
2065 | return ret; | |
2066 | } | |
2067 | ||
72ed4dc7 | 2068 | Set_machw_change_vir_if(false); |
c5c77ba1 | 2069 | |
21175ef7 | 2070 | host_int_get_MacAddress(priv->hWILCWFIDrv, mac_add); |
c5c77ba1 JK |
2071 | PRINT_D(INIT_DBG, "Mac address: %x:%x:%x:%x:%x:%x\n", mac_add[0], mac_add[1], mac_add[2], |
2072 | mac_add[3], mac_add[4], mac_add[5]); | |
2073 | ||
2074 | /* loop through the NUM of supported devices and set the MAC address */ | |
2075 | for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) { | |
2076 | if (ndev == g_linux_wlan->strInterfaceInfo[i].wilc_netdev) { | |
2077 | memcpy(g_linux_wlan->strInterfaceInfo[i].aSrcAddress, mac_add, ETH_ALEN); | |
4e4467fd | 2078 | g_linux_wlan->strInterfaceInfo[i].drvHandler = (u32)priv->hWILCWFIDrv; |
c5c77ba1 JK |
2079 | break; |
2080 | } | |
2081 | } | |
2082 | ||
2083 | /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/ | |
2084 | memcpy(ndev->dev_addr, g_linux_wlan->strInterfaceInfo[i].aSrcAddress, ETH_ALEN); | |
2085 | ||
2086 | if (!is_valid_ether_addr(ndev->dev_addr)) { | |
2087 | PRINT_ER("Error: Wrong MAC address\n"); | |
2088 | ret = -EINVAL; | |
2089 | goto _err_; | |
2090 | } | |
2091 | ||
2092 | ||
2093 | WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev, | |
2094 | nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg); | |
2095 | WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev, | |
2096 | nic->g_struct_frame_reg[1].frame_type, nic->g_struct_frame_reg[1].reg); | |
2097 | netif_wake_queue(ndev); | |
2098 | g_linux_wlan->open_ifcs++; | |
2099 | nic->mac_opened = 1; | |
2100 | return 0; | |
2101 | ||
2102 | _err_: | |
2103 | WILC_WFI_DeInitHostInt(ndev); | |
2104 | wilc1000_wlan_deinit(g_linux_wlan); | |
2105 | return ret; | |
2106 | } | |
2107 | #else | |
2108 | int mac_open(struct net_device *ndev) | |
2109 | { | |
2110 | ||
2111 | linux_wlan_t *nic; | |
2112 | nic = netdev_priv(ndev); | |
2113 | ||
2114 | /*initialize platform*/ | |
2115 | if (wilc1000_wlan_init(nic)) { | |
2116 | PRINT_ER("Failed to initialize platform\n"); | |
2117 | return 1; | |
2118 | } | |
2119 | /* Start the network interface queue for this device */ | |
2120 | PRINT_D(INIT_DBG, "Starting netifQ\n"); | |
2121 | netif_start_queue(ndev); | |
2122 | /* linux_wlan_lock(&close_exit_sync); */ | |
2123 | return 0; | |
2124 | } | |
2125 | #endif | |
2126 | ||
2127 | struct net_device_stats *mac_stats(struct net_device *dev) | |
2128 | { | |
2129 | perInterface_wlan_t *nic = netdev_priv(dev); | |
2130 | ||
2131 | ||
2132 | return &nic->netstats; | |
2133 | } | |
2134 | ||
2135 | /* Setup the multicast filter */ | |
c5c77ba1 JK |
2136 | static void wilc_set_multicast_list(struct net_device *dev) |
2137 | { | |
2138 | ||
2139 | struct netdev_hw_addr *ha; | |
2140 | struct WILC_WFI_priv *priv; | |
2141 | tstrWILC_WFIDrv *pstrWFIDrv; | |
2142 | int i = 0; | |
2143 | priv = wiphy_priv(dev->ieee80211_ptr->wiphy); | |
2144 | pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv; | |
2145 | ||
2146 | ||
2147 | if (!dev) | |
2148 | return; | |
2149 | ||
2150 | PRINT_D(INIT_DBG, "Setting Multicast List with count = %d. \n", dev->mc.count); | |
2151 | ||
2152 | if (dev->flags & IFF_PROMISC) { | |
2153 | /* Normally, we should configure the chip to retrive all packets | |
2154 | * but we don't wanna support this right now */ | |
2155 | /* TODO: add promiscuous mode support */ | |
2156 | PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets \n"); | |
2157 | return; | |
2158 | } | |
2159 | ||
2160 | /* If there's more addresses than we handle, get all multicast | |
2161 | * packets and sort them out in software. */ | |
2162 | if ((dev->flags & IFF_ALLMULTI) || (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) { | |
2163 | PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n"); | |
2164 | /* get all multicast packets */ | |
72ed4dc7 | 2165 | host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, false, 0); |
c5c77ba1 JK |
2166 | return; |
2167 | } | |
2168 | ||
2169 | /* No multicast? Just get our own stuff */ | |
2170 | if ((dev->mc.count) == 0) { | |
2171 | PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n"); | |
72ed4dc7 | 2172 | host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, true, 0); |
c5c77ba1 JK |
2173 | return; |
2174 | } | |
2175 | ||
2176 | /* Store all of the multicast addresses in the hardware filter */ | |
2177 | netdev_for_each_mc_addr(ha, dev) | |
2178 | { | |
2179 | WILC_memcpy(gau8MulticastMacAddrList[i], ha->addr, ETH_ALEN); | |
2180 | PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i, | |
2181 | gau8MulticastMacAddrList[i][0], gau8MulticastMacAddrList[i][1], gau8MulticastMacAddrList[i][2], gau8MulticastMacAddrList[i][3], gau8MulticastMacAddrList[i][4], gau8MulticastMacAddrList[i][5]); | |
2182 | i++; | |
2183 | } | |
2184 | ||
72ed4dc7 | 2185 | host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, true, (dev->mc.count)); |
c5c77ba1 JK |
2186 | |
2187 | return; | |
2188 | ||
2189 | } | |
2190 | ||
c5c77ba1 JK |
2191 | static void linux_wlan_tx_complete(void *priv, int status) |
2192 | { | |
2193 | ||
2194 | struct tx_complete_data *pv_data = (struct tx_complete_data *)priv; | |
2195 | if (status == 1) { | |
2196 | PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb); | |
2197 | } else { | |
2198 | PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb); | |
2199 | } | |
2200 | /* Free the SK Buffer, its work is done */ | |
2201 | dev_kfree_skb(pv_data->skb); | |
2202 | linux_wlan_free(pv_data); | |
2203 | } | |
2204 | ||
2205 | int mac_xmit(struct sk_buff *skb, struct net_device *ndev) | |
2206 | { | |
2207 | perInterface_wlan_t *nic; | |
2208 | struct tx_complete_data *tx_data = NULL; | |
2209 | int QueueCount; | |
2210 | char *pu8UdpBuffer; | |
2211 | struct iphdr *ih; | |
2212 | struct ethhdr *eth_h; | |
2213 | nic = netdev_priv(ndev); | |
2214 | ||
2215 | PRINT_D(INT_DBG, "\n========\n IntUH: %d - IntBH: %d - IntCld: %d \n========\n", int_rcvdU, int_rcvdB, int_clrd); | |
2216 | PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n"); | |
2217 | ||
2218 | /* Stop the network interface queue */ | |
2219 | if (skb->dev != ndev) { | |
2220 | PRINT_ER("Packet not destined to this device\n"); | |
2221 | return 0; | |
2222 | } | |
2223 | ||
2224 | tx_data = (struct tx_complete_data *)internal_alloc(sizeof(struct tx_complete_data), GFP_ATOMIC); | |
2225 | if (tx_data == NULL) { | |
2226 | PRINT_ER("Failed to allocate memory for tx_data structure\n"); | |
2227 | dev_kfree_skb(skb); | |
2228 | netif_wake_queue(ndev); | |
2229 | return 0; | |
2230 | } | |
2231 | ||
2232 | tx_data->buff = skb->data; | |
2233 | tx_data->size = skb->len; | |
2234 | tx_data->skb = skb; | |
2235 | ||
2236 | eth_h = (struct ethhdr *)(skb->data); | |
2237 | if (eth_h->h_proto == 0x8e88) { | |
2238 | PRINT_D(INIT_DBG, "EAPOL transmitted\n"); | |
2239 | } | |
2240 | ||
2241 | /*get source and dest ip addresses*/ | |
2242 | ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr)); | |
2243 | ||
2244 | pu8UdpBuffer = (char *)ih + sizeof(struct iphdr); | |
2245 | if ((pu8UdpBuffer[1] == 68 && pu8UdpBuffer[3] == 67) || (pu8UdpBuffer[1] == 67 && pu8UdpBuffer[3] == 68)) { | |
2246 | PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer[248], pu8UdpBuffer[249], pu8UdpBuffer[250]); | |
2247 | ||
2248 | } | |
2249 | PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb); | |
2250 | ||
2251 | /* Send packet to MAC HW - for now the tx_complete function will be just status | |
2252 | * indicator. still not sure if I need to suspend host transmission till the tx_complete | |
2253 | * function called or not? | |
2254 | * allocated buffer will be freed in tx_complete function. | |
2255 | */ | |
2256 | PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n"); | |
2257 | nic->netstats.tx_packets++; | |
2258 | nic->netstats.tx_bytes += tx_data->size; | |
2259 | tx_data->pBssid = g_linux_wlan->strInterfaceInfo[nic->u8IfIdx].aBSSID; | |
2260 | #ifndef WILC_FULLY_HOSTING_AP | |
2261 | QueueCount = g_linux_wlan->oup.wlan_add_to_tx_que((void *)tx_data, | |
2262 | tx_data->buff, | |
2263 | tx_data->size, | |
2264 | linux_wlan_tx_complete); | |
2265 | #else | |
2266 | QueueCount = WILC_Xmit_data((void *)tx_data, HOST_TO_WLAN); | |
2267 | #endif /* WILC_FULLY_HOSTING_AP */ | |
2268 | ||
2269 | ||
2270 | if (QueueCount > FLOW_CONTROL_UPPER_THRESHOLD) { | |
2271 | netif_stop_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev); | |
2272 | netif_stop_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev); | |
2273 | } | |
2274 | ||
2275 | return 0; | |
2276 | } | |
2277 | ||
2278 | ||
2279 | int mac_close(struct net_device *ndev) | |
2280 | { | |
2281 | struct WILC_WFI_priv *priv; | |
2282 | perInterface_wlan_t *nic; | |
2283 | tstrWILC_WFIDrv *pstrWFIDrv; | |
2284 | ||
2285 | nic = netdev_priv(ndev); | |
2286 | ||
2287 | if ((nic == NULL) || (nic->wilc_netdev == NULL) || (nic->wilc_netdev->ieee80211_ptr == NULL) || (nic->wilc_netdev->ieee80211_ptr->wiphy == NULL)) { | |
2288 | PRINT_ER("nic = NULL\n"); | |
2289 | return 0; | |
2290 | } | |
2291 | ||
2292 | priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy); | |
2293 | ||
2294 | if (priv == NULL) { | |
2295 | PRINT_ER("priv = NULL\n"); | |
2296 | return 0; | |
2297 | } | |
2298 | ||
2299 | pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv; | |
2300 | ||
2301 | ||
2302 | ||
2303 | PRINT_D(GENERIC_DBG, "Mac close\n"); | |
2304 | ||
2305 | if (g_linux_wlan == NULL) { | |
2306 | PRINT_ER("g_linux_wlan = NULL\n"); | |
2307 | return 0; | |
2308 | } | |
2309 | ||
2310 | if (pstrWFIDrv == NULL) { | |
2311 | PRINT_ER("pstrWFIDrv = NULL\n"); | |
2312 | return 0; | |
2313 | } | |
2314 | ||
2315 | if ((g_linux_wlan->open_ifcs) > 0) { | |
2316 | g_linux_wlan->open_ifcs--; | |
2317 | } else { | |
2318 | PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n"); | |
2319 | return 0; | |
2320 | } | |
2321 | ||
2322 | if (nic->wilc_netdev != NULL) { | |
2323 | /* Stop the network interface queue */ | |
2324 | netif_stop_queue(nic->wilc_netdev); | |
2325 | ||
2326 | #ifdef USE_WIRELESS | |
2327 | WILC_WFI_DeInitHostInt(nic->wilc_netdev); | |
2328 | #endif | |
2329 | } | |
2330 | ||
2331 | if (g_linux_wlan->open_ifcs == 0) { | |
2332 | PRINT_D(GENERIC_DBG, "Deinitializing wilc1000\n"); | |
2333 | g_linux_wlan->close = 1; | |
2334 | wilc1000_wlan_deinit(g_linux_wlan); | |
2335 | #ifdef USE_WIRELESS | |
2336 | #ifdef WILC_AP_EXTERNAL_MLME | |
2337 | WILC_WFI_deinit_mon_interface(); | |
2338 | #endif | |
2339 | #endif | |
2340 | } | |
2341 | ||
2342 | linux_wlan_unlock(&close_exit_sync); | |
2343 | nic->mac_opened = 0; | |
2344 | ||
2345 | return 0; | |
2346 | } | |
2347 | ||
2348 | ||
2349 | int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) | |
2350 | { | |
2351 | ||
63d03e47 | 2352 | u8 *buff = NULL; |
ca356ada | 2353 | s8 rssi; |
4e4467fd | 2354 | u32 size = 0, length = 0; |
c5c77ba1 JK |
2355 | perInterface_wlan_t *nic; |
2356 | struct WILC_WFI_priv *priv; | |
fb4ec9ca | 2357 | s32 s32Error = WILC_SUCCESS; |
c5c77ba1 JK |
2358 | |
2359 | ||
2360 | ||
2361 | /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */ | |
2362 | #ifdef USE_WIRELESS | |
2363 | nic = netdev_priv(ndev); | |
2364 | ||
2365 | if (!g_linux_wlan->wilc1000_initialized) | |
2366 | return 0; | |
2367 | ||
2368 | #endif | |
2369 | ||
2370 | switch (cmd) { | |
c5c77ba1 JK |
2371 | |
2372 | /* ]] 2013-06-24 */ | |
2373 | case SIOCSIWPRIV: | |
2374 | { | |
2375 | struct iwreq *wrq = (struct iwreq *) req; /* added by tony */ | |
2376 | ||
2377 | size = wrq->u.data.length; | |
2378 | ||
2379 | if (size && wrq->u.data.pointer) { | |
c5c77ba1 | 2380 | |
4a01f1c3 HPGE |
2381 | buff = memdup_user(wrq->u.data.pointer, wrq->u.data.length); |
2382 | if (IS_ERR(buff)) { | |
2383 | s32Error = PTR_ERR(buff); | |
c5c77ba1 JK |
2384 | goto done; |
2385 | } | |
2386 | ||
2387 | if (strncasecmp(buff, "RSSI", length) == 0) { | |
2388 | ||
2389 | #ifdef USE_WIRELESS | |
2390 | priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy); | |
2391 | s32Error = host_int_get_rssi(priv->hWILCWFIDrv, &(rssi)); | |
2392 | if (s32Error) | |
2393 | PRINT_ER("Failed to send get rssi param's message queue "); | |
2394 | #endif | |
2395 | PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi); | |
2396 | ||
2397 | /*Rounding up the rssi negative value*/ | |
2398 | rssi += 5; | |
2399 | ||
2400 | snprintf(buff, size, "rssi %d", rssi); | |
2401 | ||
2402 | if (copy_to_user(wrq->u.data.pointer, buff, size)) { | |
60cb1e20 | 2403 | PRINT_ER("%s: failed to copy data to user buffer\n", __func__); |
c5c77ba1 JK |
2404 | s32Error = -EFAULT; |
2405 | goto done; | |
2406 | } | |
2407 | } | |
2408 | } | |
2409 | } | |
2410 | break; | |
2411 | ||
2412 | default: | |
2413 | { | |
2414 | PRINT_INFO(GENERIC_DBG, "Command - %d - has been received\n", cmd); | |
2415 | s32Error = -EOPNOTSUPP; | |
2416 | goto done; | |
2417 | } | |
2418 | } | |
2419 | ||
2420 | done: | |
2421 | ||
2422 | if (buff != NULL) { | |
2423 | kfree(buff); | |
2424 | } | |
2425 | ||
2426 | return s32Error; | |
2427 | } | |
2428 | ||
2429 | void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset) | |
2430 | { | |
2431 | ||
2432 | unsigned int frame_len = 0; | |
2433 | int stats; | |
2434 | unsigned char *buff_to_send = NULL; | |
2435 | struct sk_buff *skb; | |
7a8fd841 | 2436 | #ifndef TCP_ENHANCEMENTS |
c5c77ba1 JK |
2437 | char *pu8UdpBuffer; |
2438 | struct iphdr *ih; | |
7a8fd841 | 2439 | #endif |
c5c77ba1 JK |
2440 | struct net_device *wilc_netdev; |
2441 | perInterface_wlan_t *nic; | |
2442 | ||
2443 | wilc_netdev = GetIfHandler(buff); | |
2444 | if (wilc_netdev == NULL) | |
2445 | return; | |
2446 | ||
2447 | buff += pkt_offset; | |
2448 | nic = netdev_priv(wilc_netdev); | |
2449 | ||
2450 | if (size > 0) { | |
2451 | ||
2452 | frame_len = size; | |
2453 | buff_to_send = buff; | |
2454 | ||
2455 | ||
2456 | /* Need to send the packet up to the host, allocate a skb buffer */ | |
2457 | skb = dev_alloc_skb(frame_len); | |
2458 | if (skb == NULL) { | |
2459 | PRINT_ER("Low memory - packet droped\n"); | |
2460 | return; | |
2461 | } | |
2462 | ||
2463 | skb_reserve(skb, (unsigned int)skb->data & 0x3); | |
2464 | ||
2465 | if (g_linux_wlan == NULL || wilc_netdev == NULL) { | |
2466 | PRINT_ER("wilc_netdev in g_linux_wlan is NULL"); | |
2467 | } | |
2468 | skb->dev = wilc_netdev; | |
2469 | ||
2470 | if (skb->dev == NULL) { | |
2471 | PRINT_ER("skb->dev is NULL\n"); | |
2472 | } | |
2473 | ||
2474 | /* | |
2475 | * for(i=0;i<40;i++) | |
2476 | * { | |
2477 | * if(i<frame_len) | |
2478 | * WILC_PRINTF("buff_to_send[%d]=%2x\n",i,buff_to_send[i]); | |
2479 | * | |
2480 | * }*/ | |
2481 | ||
2482 | /* skb_put(skb, frame_len); */ | |
2483 | memcpy(skb_put(skb, frame_len), buff_to_send, frame_len); | |
2484 | ||
2485 | /* WILC_PRINTF("After MEM_CPY\n"); */ | |
2486 | ||
2487 | /* nic = netdev_priv(wilc_netdev); */ | |
2488 | ||
2489 | #ifdef USE_WIRELESS | |
2490 | /* if(nic->monitor_flag) | |
2491 | * { | |
2492 | * WILC_WFI_monitor_rx(nic->wilc_netdev,skb); | |
2493 | * return; | |
2494 | * }*/ | |
2495 | #endif | |
2496 | skb->protocol = eth_type_trans(skb, wilc_netdev); | |
2497 | #ifndef TCP_ENHANCEMENTS | |
2498 | /*get source and dest ip addresses*/ | |
2499 | ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr)); | |
2500 | ||
2501 | pu8UdpBuffer = (char *)ih + sizeof(struct iphdr); | |
2502 | if (buff_to_send[35] == 67 && buff_to_send[37] == 68) { | |
2503 | PRINT_D(RX_DBG, "DHCP Message received\n"); | |
2504 | } | |
2505 | if (buff_to_send[12] == 0x88 && buff_to_send[13] == 0x8e) | |
2506 | PRINT_D(GENERIC_DBG, "eapol received\n"); | |
2507 | #endif | |
2508 | /* Send the packet to the stack by giving it to the bridge */ | |
2509 | nic->netstats.rx_packets++; | |
2510 | nic->netstats.rx_bytes += frame_len; | |
2511 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
2512 | stats = netif_rx(skb); | |
2513 | PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats); | |
2514 | } | |
2515 | #ifndef TCP_ENHANCEMENTS | |
2516 | else { | |
2517 | PRINT_ER("Discard sending packet with len = %d\n", size); | |
2518 | } | |
2519 | #endif | |
2520 | } | |
2521 | ||
2522 | void WILC_WFI_mgmt_rx(uint8_t *buff, uint32_t size) | |
2523 | { | |
2524 | int i = 0; | |
2525 | perInterface_wlan_t *nic; | |
2526 | ||
2527 | /*BugID_5450*/ | |
2528 | /*Pass the frame on the monitor interface, if any.*/ | |
2529 | /*Otherwise, pass it on p2p0 netdev, if registered on it*/ | |
2530 | for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) { | |
2531 | nic = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev); | |
2532 | if (nic->monitor_flag) { | |
2533 | WILC_WFI_monitor_rx(buff, size); | |
2534 | return; | |
2535 | } | |
2536 | } | |
2537 | ||
2538 | #ifdef WILC_P2P | |
2539 | nic = netdev_priv(g_linux_wlan->strInterfaceInfo[1].wilc_netdev); /* p2p0 */ | |
2540 | if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) || | |
2541 | (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg)) { | |
2542 | WILC_WFI_p2p_rx(g_linux_wlan->strInterfaceInfo[1].wilc_netdev, buff, size); | |
2543 | } | |
2544 | #endif | |
2545 | } | |
2546 | ||
2547 | int wilc_netdev_init(void) | |
2548 | { | |
2549 | ||
2550 | int i; | |
2551 | perInterface_wlan_t *nic; | |
2552 | struct net_device *ndev; | |
2553 | ||
2554 | linux_wlan_init_lock("close_exit_sync", &close_exit_sync, 0); | |
2555 | ||
2556 | /*create the common structure*/ | |
2557 | g_linux_wlan = (linux_wlan_t *)WILC_MALLOC(sizeof(linux_wlan_t)); | |
2558 | memset(g_linux_wlan, 0, sizeof(linux_wlan_t)); | |
2559 | ||
2560 | /*Reset interrupt count debug*/ | |
2561 | int_rcvdU = 0; | |
2562 | int_rcvdB = 0; | |
2563 | int_clrd = 0; | |
2564 | #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP | |
2565 | register_inetaddr_notifier(&g_dev_notifier); | |
2566 | #endif | |
2567 | ||
2568 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) { | |
2569 | /*allocate first ethernet device with perinterface_wlan_t as its private data*/ | |
2570 | ndev = alloc_etherdev(sizeof(perInterface_wlan_t)); | |
2571 | if (!ndev) { | |
2572 | PRINT_ER("Failed to allocate ethernet dev\n"); | |
2573 | return -1; | |
2574 | } | |
2575 | ||
2576 | nic = netdev_priv(ndev); | |
2577 | memset(nic, 0, sizeof(perInterface_wlan_t)); | |
2578 | ||
2579 | /*Name the Devices*/ | |
2580 | if (i == 0) { | |
2581 | #if defined(NM73131) /* tony, 2012-09-20 */ | |
2582 | strcpy(ndev->name, "wilc_eth%d"); | |
2583 | #elif defined(PLAT_CLM9722) /* rachel */ | |
2584 | strcpy(ndev->name, "eth%d"); | |
2585 | #else /* PANDA_BOARD, PLAT_ALLWINNER_A10, PLAT_ALLWINNER_A20, PLAT_ALLWINNER_A31, PLAT_AML8726_M3 or PLAT_WMS8304 */ | |
2586 | strcpy(ndev->name, "wlan%d"); | |
2587 | #endif | |
2588 | } else | |
2589 | strcpy(ndev->name, "p2p%d"); | |
2590 | ||
2591 | nic->u8IfIdx = g_linux_wlan->u8NoIfcs; | |
2592 | nic->wilc_netdev = ndev; | |
2593 | g_linux_wlan->strInterfaceInfo[g_linux_wlan->u8NoIfcs].wilc_netdev = ndev; | |
2594 | g_linux_wlan->u8NoIfcs++; | |
e5af0561 | 2595 | ndev->netdev_ops = &wilc_netdev_ops; |
c5c77ba1 JK |
2596 | |
2597 | #ifdef USE_WIRELESS | |
2598 | { | |
2599 | struct wireless_dev *wdev; | |
2600 | /*Register WiFi*/ | |
2601 | wdev = WILC_WFI_WiphyRegister(ndev); | |
2602 | ||
2603 | #ifdef WILC_SDIO | |
2604 | /* set netdev, tony */ | |
2605 | SET_NETDEV_DEV(ndev, &local_sdio_func->dev); | |
2606 | #endif | |
2607 | ||
2608 | if (wdev == NULL) { | |
2609 | PRINT_ER("Can't register WILC Wiphy\n"); | |
2610 | return -1; | |
2611 | } | |
2612 | ||
2613 | /*linking the wireless_dev structure with the netdevice*/ | |
2614 | nic->wilc_netdev->ieee80211_ptr = wdev; | |
2615 | nic->wilc_netdev->ml_priv = nic; | |
2616 | wdev->netdev = nic->wilc_netdev; | |
2617 | nic->netstats.rx_packets = 0; | |
2618 | nic->netstats.tx_packets = 0; | |
2619 | nic->netstats.rx_bytes = 0; | |
2620 | nic->netstats.tx_bytes = 0; | |
2621 | ||
2622 | } | |
2623 | #endif | |
2624 | ||
2625 | ||
2626 | if (register_netdev(ndev)) { | |
2627 | PRINT_ER("Device couldn't be registered - %s\n", ndev->name); | |
2628 | return -1; /* ERROR */ | |
2629 | } | |
2630 | ||
2631 | nic->iftype = STATION_MODE; | |
2632 | nic->mac_opened = 0; | |
2633 | ||
2634 | } | |
2635 | ||
2636 | #ifndef WILC_SDIO | |
2637 | if (!linux_spi_init(&g_linux_wlan->wilc_spidev)) { | |
2638 | PRINT_ER("Can't initialize SPI \n"); | |
2639 | return -1; /* ERROR */ | |
2640 | } | |
2641 | g_linux_wlan->wilc_spidev = wilc_spi_dev; | |
2642 | #else | |
2643 | g_linux_wlan->wilc_sdio_func = local_sdio_func; | |
2644 | #endif | |
2645 | ||
2646 | return 0; | |
2647 | } | |
2648 | ||
2649 | ||
2650 | /*The 1st function called after module inserted*/ | |
2651 | static int __init init_wilc_driver(void) | |
2652 | { | |
2653 | ||
2654 | ||
2655 | #if defined (WILC_DEBUGFS) | |
2656 | if (wilc_debugfs_init() < 0) { | |
2657 | PRINT_D(GENERIC_DBG, "fail to create debugfs for wilc driver\n"); | |
2658 | return -1; | |
2659 | } | |
2660 | #endif | |
2661 | ||
2662 | printk("IN INIT FUNCTION\n"); | |
691f1a2f | 2663 | printk("*** WILC1000 driver VERSION=[10.2] FW_VER=[10.2] ***\n"); |
c5c77ba1 JK |
2664 | |
2665 | linux_wlan_device_power(1); | |
2666 | msleep(100); | |
2667 | linux_wlan_device_detection(1); | |
2668 | ||
2669 | #ifdef WILC_SDIO | |
2670 | { | |
2671 | int ret; | |
2672 | ||
2673 | ret = sdio_register_driver(&wilc_bus); | |
2674 | if (ret < 0) { | |
2675 | PRINT_D(INIT_DBG, "init_wilc_driver: Failed register sdio driver\n"); | |
2676 | } | |
2677 | ||
2678 | return ret; | |
2679 | } | |
2680 | #else | |
2681 | PRINT_D(INIT_DBG, "Initializing netdev\n"); | |
2682 | if (wilc_netdev_init()) { | |
2683 | PRINT_ER("Couldn't initialize netdev\n"); | |
2684 | } | |
2685 | return 0; | |
2686 | #endif | |
2687 | } | |
2688 | late_initcall(init_wilc_driver); | |
2689 | ||
2690 | static void __exit exit_wilc_driver(void) | |
2691 | { | |
2692 | int i = 0; | |
842f1d71 | 2693 | perInterface_wlan_t *nic[NUM_CONCURRENT_IFC] = {NULL,}; |
c5c77ba1 JK |
2694 | #define CLOSE_TIMEOUT (12 * 1000) |
2695 | ||
2696 | if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL) | |
2697 | || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) { | |
2698 | #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP | |
2699 | unregister_inetaddr_notifier(&g_dev_notifier); | |
2700 | #endif | |
2701 | ||
2702 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) { | |
2703 | nic[i] = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev); | |
2704 | } | |
2705 | } | |
2706 | ||
2707 | ||
2708 | if ((g_linux_wlan != NULL) && g_linux_wlan->wilc_firmware != NULL) { | |
2709 | release_firmware(g_linux_wlan->wilc_firmware); | |
2710 | g_linux_wlan->wilc_firmware = NULL; | |
2711 | } | |
2712 | ||
2713 | ||
2714 | if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL) | |
2715 | || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) { | |
2716 | PRINT_D(INIT_DBG, "Waiting for mac_close ....\n"); | |
2717 | ||
2718 | if (linux_wlan_lock_timeout(&close_exit_sync, CLOSE_TIMEOUT) < 0) | |
2719 | PRINT_D(INIT_DBG, "Closed TimedOUT\n"); | |
2720 | else | |
2721 | PRINT_D(INIT_DBG, "mac_closed\n"); | |
2722 | ||
2723 | ||
2724 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) { | |
2725 | /* close all opened interfaces */ | |
2726 | if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev != NULL) { | |
2727 | if (nic[i]->mac_opened) { | |
2728 | mac_close(g_linux_wlan->strInterfaceInfo[i].wilc_netdev); | |
2729 | } | |
2730 | } | |
2731 | } | |
2732 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) { | |
2733 | PRINT_D(INIT_DBG, "Unregistering netdev %p \n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev); | |
2734 | unregister_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev); | |
2735 | #ifdef USE_WIRELESS | |
2736 | PRINT_D(INIT_DBG, "Freeing Wiphy...\n"); | |
2737 | WILC_WFI_WiphyFree(g_linux_wlan->strInterfaceInfo[i].wilc_netdev); | |
2738 | #endif | |
2739 | PRINT_D(INIT_DBG, "Freeing netdev...\n"); | |
2740 | free_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev); | |
2741 | } | |
2742 | } | |
2743 | ||
2744 | ||
2745 | #ifdef USE_WIRELESS | |
2746 | #ifdef WILC_AP_EXTERNAL_MLME | |
2747 | /* Bug 4600 : WILC_WFI_deinit_mon_interface was already called at mac_close */ | |
2748 | /* WILC_WFI_deinit_mon_interface(); */ | |
2749 | #endif | |
2750 | #endif | |
2751 | ||
2752 | /* if(g_linux_wlan->open_ifcs==0) */ | |
2753 | { | |
2754 | #ifndef WILC_SDIO | |
2755 | PRINT_D(INIT_DBG, "SPI unregsiter...\n"); | |
2756 | spi_unregister_driver(&wilc_bus); | |
2757 | #else | |
2758 | PRINT_D(INIT_DBG, "SDIO unregsiter...\n"); | |
2759 | sdio_unregister_driver(&wilc_bus); | |
2760 | #endif | |
2761 | ||
2762 | linux_wlan_deinit_lock(&close_exit_sync); | |
2763 | if (g_linux_wlan != NULL) { | |
2764 | WILC_FREE(g_linux_wlan); | |
2765 | g_linux_wlan = NULL; | |
2766 | } | |
2767 | printk("Module_exit Done.\n"); | |
2768 | ||
2769 | #if defined (WILC_DEBUGFS) | |
2770 | wilc_debugfs_remove(); | |
2771 | #endif | |
2772 | ||
2773 | linux_wlan_device_detection(0); | |
2774 | linux_wlan_device_power(0); | |
2775 | } | |
2776 | } | |
2777 | module_exit(exit_wilc_driver); | |
2778 | ||
2779 | MODULE_LICENSE("GPL"); |