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