Commit | Line | Data |
---|---|---|
c5c77ba1 JK |
1 | #include "wilc_wfi_cfgoperations.h" |
2 | #include "linux_wlan_common.h" | |
3 | #include "wilc_wlan_if.h" | |
4 | #include "wilc_wlan.h" | |
c5c77ba1 JK |
5 | |
6 | #include <linux/slab.h> | |
7 | #include <linux/sched.h> | |
8 | #include <linux/delay.h> | |
9 | #include <linux/workqueue.h> | |
10 | #include <linux/interrupt.h> | |
11 | #include <linux/irq.h> | |
f1a99830 | 12 | #include <linux/gpio.h> |
c5c77ba1 JK |
13 | |
14 | #include <linux/kthread.h> | |
15 | #include <linux/firmware.h> | |
16 | #include <linux/delay.h> | |
17 | ||
18 | #include <linux/init.h> | |
19 | #include <linux/netdevice.h> | |
c5c77ba1 | 20 | #include <linux/inetdevice.h> |
c5c77ba1 JK |
21 | #include <linux/etherdevice.h> |
22 | #include <linux/module.h> | |
23 | #include <linux/kernel.h> | |
24 | #include <linux/skbuff.h> | |
25 | ||
26 | #include <linux/version.h> | |
27 | #include <linux/semaphore.h> | |
28 | ||
29 | #ifdef WILC_SDIO | |
30 | #include "linux_wlan_sdio.h" | |
31 | #else | |
32 | #include "linux_wlan_spi.h" | |
33 | #endif | |
34 | ||
c5c77ba1 JK |
35 | #if defined(CUSTOMER_PLATFORM) |
36 | /* | |
37 | TODO : Write power control functions as customer platform. | |
38 | */ | |
39 | #else | |
40 | ||
41 | #define _linux_wlan_device_power_on() {} | |
42 | #define _linux_wlan_device_power_off() {} | |
43 | ||
44 | #define _linux_wlan_device_detection() {} | |
45 | #define _linux_wlan_device_removal() {} | |
46 | #endif | |
47 | ||
72ed4dc7 | 48 | extern bool g_obtainingIP; |
72ed4dc7 | 49 | extern u16 Set_machw_change_vir_if(bool bValue); |
c5c77ba1 | 50 | extern void resolve_disconnect_aberration(void *drvHandler); |
63d03e47 | 51 | extern u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN]; |
f61c5aff | 52 | void wilc1000_wlan_deinit(struct wilc *nic); |
da711eb6 | 53 | extern struct timer_list hDuringIpTimer; |
c5c77ba1 JK |
54 | |
55 | static int linux_wlan_device_power(int on_off) | |
56 | { | |
57 | PRINT_D(INIT_DBG, "linux_wlan_device_power.. (%d)\n", on_off); | |
58 | ||
59 | if (on_off) { | |
60 | _linux_wlan_device_power_on(); | |
61 | } else { | |
62 | _linux_wlan_device_power_off(); | |
63 | } | |
64 | ||
65 | return 0; | |
66 | } | |
67 | ||
68 | static int linux_wlan_device_detection(int on_off) | |
69 | { | |
70 | PRINT_D(INIT_DBG, "linux_wlan_device_detection.. (%d)\n", on_off); | |
71 | ||
72 | #ifdef WILC_SDIO | |
73 | if (on_off) { | |
74 | _linux_wlan_device_detection(); | |
75 | } else { | |
76 | _linux_wlan_device_removal(); | |
77 | } | |
78 | #endif | |
79 | ||
80 | return 0; | |
81 | } | |
82 | ||
c5c77ba1 JK |
83 | static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr); |
84 | ||
85 | static struct notifier_block g_dev_notifier = { | |
86 | .notifier_call = dev_state_ev_handler | |
87 | }; | |
c5c77ba1 | 88 | |
c5c77ba1 JK |
89 | #define IRQ_WAIT 1 |
90 | #define IRQ_NO_WAIT 0 | |
91 | /* | |
92 | * to sync between mac_close and module exit. | |
93 | * don't initialize or de-initialize from init/deinitlocks | |
94 | * to be initialized from module wilc_netdev_init and | |
95 | * deinitialized from mdoule_exit | |
96 | */ | |
97 | static struct semaphore close_exit_sync; | |
c5c77ba1 | 98 | |
f61c5aff TC |
99 | static int wlan_deinit_locks(struct wilc *nic); |
100 | static void wlan_deinitialize_threads(struct wilc *nic); | |
fbc2fe16 CL |
101 | extern void WILC_WFI_monitor_rx(u8 *buff, u32 size); |
102 | extern void WILC_WFI_p2p_rx(struct net_device *dev, u8 *buff, u32 size); | |
c5c77ba1 | 103 | |
c5c77ba1 | 104 | static void linux_wlan_tx_complete(void *priv, int status); |
c5c77ba1 JK |
105 | static int mac_init_fn(struct net_device *ndev); |
106 | int mac_xmit(struct sk_buff *skb, struct net_device *dev); | |
107 | int mac_open(struct net_device *ndev); | |
108 | int mac_close(struct net_device *ndev); | |
109 | static struct net_device_stats *mac_stats(struct net_device *dev); | |
110 | static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd); | |
111 | static void wilc_set_multicast_list(struct net_device *dev); | |
112 | ||
c5c77ba1 JK |
113 | /* |
114 | * for now - in frmw_to_linux there should be private data to be passed to it | |
115 | * and this data should be pointer to net device | |
116 | */ | |
f61c5aff | 117 | struct wilc *g_linux_wlan; |
72ed4dc7 | 118 | bool bEnablePS = true; |
c5c77ba1 | 119 | |
c5c77ba1 JK |
120 | static const struct net_device_ops wilc_netdev_ops = { |
121 | .ndo_init = mac_init_fn, | |
122 | .ndo_open = mac_open, | |
123 | .ndo_stop = mac_close, | |
124 | .ndo_start_xmit = mac_xmit, | |
125 | .ndo_do_ioctl = mac_ioctl, | |
126 | .ndo_get_stats = mac_stats, | |
127 | .ndo_set_rx_mode = wilc_set_multicast_list, | |
128 | ||
129 | }; | |
c5c77ba1 | 130 | |
c5c77ba1 JK |
131 | static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr) |
132 | { | |
133 | struct in_ifaddr *dev_iface = (struct in_ifaddr *)ptr; | |
2726887c | 134 | struct wilc_priv *priv; |
441dc609 | 135 | struct host_if_drv *pstrWFIDrv; |
c5c77ba1 | 136 | struct net_device *dev; |
63d03e47 | 137 | u8 *pIP_Add_buff; |
c5c77ba1 | 138 | perInterface_wlan_t *nic; |
63d03e47 | 139 | u8 null_ip[4] = {0}; |
c5c77ba1 JK |
140 | char wlan_dev_name[5] = "wlan0"; |
141 | ||
142 | if (dev_iface == NULL || dev_iface->ifa_dev == NULL || dev_iface->ifa_dev->dev == NULL) { | |
143 | PRINT_D(GENERIC_DBG, "dev_iface = NULL\n"); | |
144 | return NOTIFY_DONE; | |
145 | } | |
146 | ||
147 | if ((memcmp(dev_iface->ifa_label, "wlan0", 5)) && (memcmp(dev_iface->ifa_label, "p2p0", 4))) { | |
148 | PRINT_D(GENERIC_DBG, "Interface is neither WLAN0 nor P2P0\n"); | |
149 | return NOTIFY_DONE; | |
150 | } | |
151 | ||
152 | dev = (struct net_device *)dev_iface->ifa_dev->dev; | |
153 | if (dev->ieee80211_ptr == NULL || dev->ieee80211_ptr->wiphy == NULL) { | |
154 | PRINT_D(GENERIC_DBG, "No Wireless registerd\n"); | |
155 | return NOTIFY_DONE; | |
156 | } | |
157 | priv = wiphy_priv(dev->ieee80211_ptr->wiphy); | |
158 | if (priv == NULL) { | |
159 | PRINT_D(GENERIC_DBG, "No Wireless Priv\n"); | |
160 | return NOTIFY_DONE; | |
161 | } | |
441dc609 | 162 | pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv; |
c5c77ba1 JK |
163 | nic = netdev_priv(dev); |
164 | if (nic == NULL || pstrWFIDrv == NULL) { | |
165 | PRINT_D(GENERIC_DBG, "No Wireless Priv\n"); | |
166 | return NOTIFY_DONE; | |
167 | } | |
168 | ||
169 | PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler +++\n"); /* tony */ | |
170 | ||
171 | switch (event) { | |
172 | case NETDEV_UP: | |
173 | PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_UP %p\n", dev); /* tony */ | |
174 | ||
175 | PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n"); | |
176 | ||
c5c77ba1 JK |
177 | /*If we are in station mode or client mode*/ |
178 | if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) { | |
179 | pstrWFIDrv->IFC_UP = 1; | |
72ed4dc7 | 180 | g_obtainingIP = false; |
8972d0fe | 181 | del_timer(&hDuringIpTimer); |
c5c77ba1 JK |
182 | PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n"); |
183 | } | |
184 | ||
5a66bf20 | 185 | if (bEnablePS) |
218dc407 | 186 | host_int_set_power_mgmt(pstrWFIDrv, 1, 0); |
c5c77ba1 JK |
187 | |
188 | PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label); | |
189 | ||
190 | pIP_Add_buff = (char *) (&(dev_iface->ifa_address)); | |
17aacd43 | 191 | 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]); |
218dc407 | 192 | host_int_setup_ipaddress(pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx); |
c5c77ba1 JK |
193 | |
194 | break; | |
195 | ||
196 | case NETDEV_DOWN: | |
197 | PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev); /* tony */ | |
198 | ||
199 | PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Released ===============\n\n"); | |
200 | if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) { | |
201 | pstrWFIDrv->IFC_UP = 0; | |
72ed4dc7 | 202 | g_obtainingIP = false; |
c5c77ba1 JK |
203 | } |
204 | ||
205 | if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0) | |
218dc407 | 206 | host_int_set_power_mgmt(pstrWFIDrv, 0, 0); |
c5c77ba1 JK |
207 | |
208 | resolve_disconnect_aberration(pstrWFIDrv); | |
209 | ||
c5c77ba1 JK |
210 | PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label); |
211 | ||
212 | pIP_Add_buff = null_ip; | |
17aacd43 | 213 | 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]); |
c5c77ba1 | 214 | |
218dc407 | 215 | host_int_setup_ipaddress(pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx); |
c5c77ba1 JK |
216 | |
217 | break; | |
218 | ||
219 | default: | |
220 | PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler event=default\n"); /* tony */ | |
221 | PRINT_INFO(GENERIC_DBG, "[%s] unknown dev event: %lu\n", dev_iface->ifa_label, event); | |
222 | ||
223 | break; | |
224 | } | |
225 | ||
226 | return NOTIFY_DONE; | |
227 | ||
228 | } | |
c5c77ba1 | 229 | |
c5c77ba1 JK |
230 | #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) |
231 | static irqreturn_t isr_uh_routine(int irq, void *user_data) | |
232 | { | |
c5c77ba1 JK |
233 | PRINT_D(INT_DBG, "Interrupt received UH\n"); |
234 | ||
235 | /*While mac is closing cacncel the handling of any interrupts received*/ | |
236 | if (g_linux_wlan->close) { | |
237 | PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n"); | |
c5c77ba1 | 238 | return IRQ_HANDLED; |
c5c77ba1 | 239 | } |
c5c77ba1 | 240 | return IRQ_WAKE_THREAD; |
c5c77ba1 JK |
241 | } |
242 | #endif | |
243 | ||
c5c77ba1 JK |
244 | irqreturn_t isr_bh_routine(int irq, void *userdata) |
245 | { | |
f61c5aff | 246 | struct wilc *nic; |
8dfaafd6 | 247 | |
f61c5aff | 248 | nic = (struct wilc *)userdata; |
c5c77ba1 JK |
249 | |
250 | /*While mac is closing cacncel the handling of any interrupts received*/ | |
251 | if (g_linux_wlan->close) { | |
252 | PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n"); | |
c5c77ba1 | 253 | return IRQ_HANDLED; |
c5c77ba1 JK |
254 | } |
255 | ||
c5c77ba1 | 256 | PRINT_D(INT_DBG, "Interrupt received BH\n"); |
46ca80cd | 257 | wilc_handle_isr(); |
c5c77ba1 | 258 | |
c5c77ba1 | 259 | return IRQ_HANDLED; |
c5c77ba1 | 260 | } |
c5c77ba1 | 261 | |
c5c77ba1 | 262 | #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) |
f61c5aff | 263 | static int init_irq(struct wilc *p_nic) |
c5c77ba1 JK |
264 | { |
265 | int ret = 0; | |
f61c5aff | 266 | struct wilc *nic = p_nic; |
c5c77ba1 JK |
267 | |
268 | /*initialize GPIO and register IRQ num*/ | |
269 | /*GPIO request*/ | |
270 | if ((gpio_request(GPIO_NUM, "WILC_INTR") == 0) && | |
271 | (gpio_direction_input(GPIO_NUM) == 0)) { | |
272 | #if defined(CUSTOMER_PLATFORM) | |
273 | /* | |
274 | TODO : save the registerd irq number to the private wilc context in kernel. | |
275 | * | |
276 | * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM); | |
277 | */ | |
c5c77ba1 JK |
278 | #else |
279 | nic->dev_irq_num = gpio_to_irq(GPIO_NUM); | |
280 | #endif | |
281 | } else { | |
282 | ret = -1; | |
283 | PRINT_ER("could not obtain gpio for WILC_INTR\n"); | |
284 | } | |
285 | ||
c5c77ba1 JK |
286 | if ((ret != -1) && (request_threaded_irq(nic->dev_irq_num, isr_uh_routine, isr_bh_routine, |
287 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/ | |
288 | "WILC_IRQ", nic)) < 0) { | |
289 | ||
c5c77ba1 JK |
290 | PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM); |
291 | ret = -1; | |
292 | } else { | |
293 | ||
294 | PRINT_D(INIT_DBG, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n", | |
295 | nic->dev_irq_num, GPIO_NUM); | |
296 | } | |
297 | ||
298 | return ret; | |
299 | } | |
300 | #endif | |
301 | ||
f61c5aff | 302 | static void deinit_irq(struct wilc *nic) |
c5c77ba1 JK |
303 | { |
304 | #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) | |
305 | /* Deintialize IRQ */ | |
306 | if (&nic->dev_irq_num != 0) { | |
307 | free_irq(nic->dev_irq_num, g_linux_wlan); | |
308 | ||
309 | gpio_free(GPIO_NUM); | |
310 | } | |
311 | #endif | |
312 | } | |
313 | ||
c5c77ba1 JK |
314 | /* |
315 | * OS functions | |
316 | */ | |
ef2b784c | 317 | void linux_wlan_dbg(u8 *buff) |
c5c77ba1 JK |
318 | { |
319 | PRINT_D(INIT_DBG, "%d\n", *buff); | |
320 | } | |
321 | ||
b002e20d | 322 | int linux_wlan_lock_timeout(void *vp, u32 timeout) |
c5c77ba1 JK |
323 | { |
324 | int error = -1; | |
8dfaafd6 | 325 | |
c5c77ba1 | 326 | PRINT_D(LOCK_DBG, "Locking %p\n", vp); |
78174ada | 327 | if (vp != NULL) |
c5c77ba1 | 328 | error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout)); |
78174ada | 329 | else |
c5c77ba1 | 330 | PRINT_ER("Failed, mutex is NULL\n"); |
c5c77ba1 JK |
331 | return error; |
332 | } | |
333 | ||
4417d3da | 334 | void linux_wlan_mac_indicate(int flag) |
c5c77ba1 JK |
335 | { |
336 | /*I have to do it that way becuase there is no mean to encapsulate device pointer | |
337 | * as a parameter | |
338 | */ | |
f61c5aff | 339 | struct wilc *pd = g_linux_wlan; |
c5c77ba1 JK |
340 | int status; |
341 | ||
342 | if (flag == WILC_MAC_INDICATE_STATUS) { | |
894de36b | 343 | wilc_wlan_cfg_get_val(WID_STATUS, (unsigned char *)&status, 4); |
c5c77ba1 JK |
344 | if (pd->mac_status == WILC_MAC_STATUS_INIT) { |
345 | pd->mac_status = status; | |
8990d856 | 346 | up(&pd->sync_event); |
c5c77ba1 JK |
347 | } else { |
348 | pd->mac_status = status; | |
349 | } | |
350 | ||
351 | if (pd->mac_status == WILC_MAC_STATUS_CONNECT) { /* Connect */ | |
c5c77ba1 JK |
352 | } |
353 | ||
354 | } else if (flag == WILC_MAC_INDICATE_SCAN) { | |
355 | PRINT_D(GENERIC_DBG, "Scanning ...\n"); | |
356 | ||
357 | } | |
358 | ||
359 | } | |
360 | ||
51e825f7 | 361 | struct net_device *GetIfHandler(u8 *pMacHeader) |
c5c77ba1 | 362 | { |
51e825f7 | 363 | u8 *Bssid, *Bssid1; |
c5c77ba1 JK |
364 | int i = 0; |
365 | ||
366 | Bssid = pMacHeader + 10; | |
367 | Bssid1 = pMacHeader + 4; | |
368 | ||
8259a53e | 369 | for (i = 0; i < g_linux_wlan->vif_num; i++) |
7201cd2c TC |
370 | if (!memcmp(Bssid1, g_linux_wlan->vif[i].bssid, ETH_ALEN) || |
371 | !memcmp(Bssid, g_linux_wlan->vif[i].bssid, ETH_ALEN)) | |
817f3fb9 | 372 | return g_linux_wlan->vif[i].ndev; |
8259a53e | 373 | |
c5c77ba1 | 374 | PRINT_INFO(INIT_DBG, "Invalide handle\n"); |
fc4b95d6 | 375 | for (i = 0; i < 25; i++) |
c5c77ba1 | 376 | PRINT_D(INIT_DBG, "%02x ", pMacHeader[i]); |
c5c77ba1 JK |
377 | Bssid = pMacHeader + 18; |
378 | Bssid1 = pMacHeader + 12; | |
8259a53e | 379 | for (i = 0; i < g_linux_wlan->vif_num; i++) |
7201cd2c TC |
380 | if (!memcmp(Bssid1, g_linux_wlan->vif[i].bssid, ETH_ALEN) || |
381 | !memcmp(Bssid, g_linux_wlan->vif[i].bssid, ETH_ALEN)) | |
817f3fb9 | 382 | return g_linux_wlan->vif[i].ndev; |
8259a53e | 383 | |
c5c77ba1 JK |
384 | PRINT_INFO(INIT_DBG, "\n"); |
385 | return NULL; | |
386 | } | |
387 | ||
51e825f7 | 388 | int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID) |
c5c77ba1 JK |
389 | { |
390 | int i = 0; | |
391 | int ret = -1; | |
392 | ||
8259a53e | 393 | for (i = 0; i < g_linux_wlan->vif_num; i++) |
817f3fb9 | 394 | if (g_linux_wlan->vif[i].ndev == wilc_netdev) { |
7201cd2c | 395 | memcpy(g_linux_wlan->vif[i].bssid, pBSSID, 6); |
c5c77ba1 JK |
396 | ret = 0; |
397 | break; | |
398 | } | |
8259a53e | 399 | |
c5c77ba1 JK |
400 | return ret; |
401 | } | |
402 | ||
c5c77ba1 JK |
403 | /*Function to get number of connected interfaces*/ |
404 | int linux_wlan_get_num_conn_ifcs(void) | |
405 | { | |
51e825f7 CL |
406 | u8 i = 0; |
407 | u8 null_bssid[6] = {0}; | |
408 | u8 ret_val = 0; | |
c5c77ba1 | 409 | |
8259a53e | 410 | for (i = 0; i < g_linux_wlan->vif_num; i++) |
7201cd2c | 411 | if (memcmp(g_linux_wlan->vif[i].bssid, null_bssid, 6)) |
c5c77ba1 | 412 | ret_val++; |
8259a53e | 413 | |
c5c77ba1 JK |
414 | return ret_val; |
415 | } | |
416 | ||
c5c77ba1 JK |
417 | #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS |
418 | ||
419 | static int linux_wlan_txq_task(void *vp) | |
420 | { | |
421 | int ret, txq_count; | |
422 | ||
423 | #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS | |
424 | #define TX_BACKOFF_WEIGHT_INCR_STEP (1) | |
425 | #define TX_BACKOFF_WEIGHT_DECR_STEP (1) | |
426 | #define TX_BACKOFF_WEIGHT_MAX (7) | |
427 | #define TX_BACKOFF_WEIGHT_MIN (0) | |
428 | #define TX_BACKOFF_WEIGHT_UNIT_MS (10) | |
429 | int backoff_weight = TX_BACKOFF_WEIGHT_MIN; | |
c5c77ba1 JK |
430 | #endif |
431 | ||
432 | /* inform wilc1000_wlan_init that TXQ task is started. */ | |
8990d856 | 433 | up(&g_linux_wlan->txq_thread_started); |
c5c77ba1 JK |
434 | while (1) { |
435 | ||
436 | PRINT_D(TX_DBG, "txq_task Taking a nap :)\n"); | |
8990d856 | 437 | down(&g_linux_wlan->txq_event); |
c5c77ba1 JK |
438 | /* wait_for_completion(&pd->txq_event); */ |
439 | PRINT_D(TX_DBG, "txq_task Who waked me up :$\n"); | |
440 | ||
441 | if (g_linux_wlan->close) { | |
442 | /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */ | |
8990d856 | 443 | up(&g_linux_wlan->txq_thread_started); |
c5c77ba1 JK |
444 | |
445 | while (!kthread_should_stop()) | |
446 | schedule(); | |
447 | ||
448 | PRINT_D(TX_DBG, "TX thread stopped\n"); | |
449 | break; | |
450 | } | |
451 | PRINT_D(TX_DBG, "txq_task handle the sending packet and let me go to sleep.\n"); | |
452 | #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS | |
f590c4ce | 453 | ret = wilc_wlan_handle_txq(&txq_count); |
c5c77ba1 JK |
454 | #else |
455 | do { | |
f590c4ce | 456 | ret = wilc_wlan_handle_txq(&txq_count); |
c5c77ba1 JK |
457 | if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD /* && netif_queue_stopped(pd->wilc_netdev)*/) { |
458 | PRINT_D(TX_DBG, "Waking up queue\n"); | |
459 | /* netif_wake_queue(pd->wilc_netdev); */ | |
817f3fb9 TC |
460 | if (netif_queue_stopped(g_linux_wlan->vif[0].ndev)) |
461 | netif_wake_queue(g_linux_wlan->vif[0].ndev); | |
462 | if (netif_queue_stopped(g_linux_wlan->vif[1].ndev)) | |
463 | netif_wake_queue(g_linux_wlan->vif[1].ndev); | |
c5c77ba1 JK |
464 | } |
465 | ||
466 | if (ret == WILC_TX_ERR_NO_BUF) { /* failed to allocate buffers in chip. */ | |
c5c77ba1 JK |
467 | do { |
468 | /* Back off from sending packets for some time. */ | |
469 | /* schedule_timeout will allow RX task to run and free buffers.*/ | |
470 | /* set_current_state(TASK_UNINTERRUPTIBLE); */ | |
471 | /* timeout = schedule_timeout(timeout); */ | |
472 | msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight); | |
473 | } while (/*timeout*/ 0); | |
474 | backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP; | |
fc4b95d6 | 475 | if (backoff_weight > TX_BACKOFF_WEIGHT_MAX) |
c5c77ba1 | 476 | backoff_weight = TX_BACKOFF_WEIGHT_MAX; |
c5c77ba1 JK |
477 | } else { |
478 | if (backoff_weight > TX_BACKOFF_WEIGHT_MIN) { | |
479 | backoff_weight -= TX_BACKOFF_WEIGHT_DECR_STEP; | |
fc4b95d6 | 480 | if (backoff_weight < TX_BACKOFF_WEIGHT_MIN) |
c5c77ba1 | 481 | backoff_weight = TX_BACKOFF_WEIGHT_MIN; |
c5c77ba1 JK |
482 | } |
483 | } | |
484 | /*TODO: drop packets after a certain time/number of retry count. */ | |
485 | } while (ret == WILC_TX_ERR_NO_BUF && !g_linux_wlan->close); /* retry sending packets if no more buffers in chip. */ | |
486 | #endif | |
487 | } | |
488 | return 0; | |
489 | } | |
490 | ||
c0cadaa4 | 491 | void linux_wlan_rx_complete(void) |
c5c77ba1 JK |
492 | { |
493 | PRINT_D(RX_DBG, "RX completed\n"); | |
494 | } | |
495 | ||
496 | int linux_wlan_get_firmware(perInterface_wlan_t *p_nic) | |
497 | { | |
498 | ||
499 | perInterface_wlan_t *nic = p_nic; | |
500 | int ret = 0; | |
501 | const struct firmware *wilc_firmware; | |
502 | char *firmware; | |
503 | ||
c5c77ba1 JK |
504 | if (nic->iftype == AP_MODE) |
505 | firmware = AP_FIRMWARE; | |
506 | else if (nic->iftype == STATION_MODE) | |
507 | firmware = STA_FIRMWARE; | |
508 | ||
c5c77ba1 JK |
509 | else { |
510 | PRINT_D(INIT_DBG, "Get P2P_CONCURRENCY_FIRMWARE\n"); | |
511 | firmware = P2P_CONCURRENCY_FIRMWARE; | |
512 | } | |
513 | ||
c5c77ba1 JK |
514 | if (nic == NULL) { |
515 | PRINT_ER("NIC is NULL\n"); | |
516 | goto _fail_; | |
517 | } | |
518 | ||
519 | if (&nic->wilc_netdev->dev == NULL) { | |
520 | PRINT_ER("&nic->wilc_netdev->dev is NULL\n"); | |
521 | goto _fail_; | |
522 | } | |
523 | ||
c5c77ba1 JK |
524 | /* the firmare should be located in /lib/firmware in |
525 | * root file system with the name specified above */ | |
526 | ||
527 | #ifdef WILC_SDIO | |
528 | if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_sdio_func->dev) != 0) { | |
529 | PRINT_ER("%s - firmare not available\n", firmware); | |
530 | ret = -1; | |
531 | goto _fail_; | |
532 | } | |
533 | #else | |
534 | if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_spidev->dev) != 0) { | |
535 | PRINT_ER("%s - firmare not available\n", firmware); | |
536 | ret = -1; | |
537 | goto _fail_; | |
538 | } | |
539 | #endif | |
8b8ad7bc | 540 | g_linux_wlan->firmware = wilc_firmware; |
c5c77ba1 JK |
541 | |
542 | _fail_: | |
543 | ||
544 | return ret; | |
545 | ||
546 | } | |
547 | ||
c5c77ba1 JK |
548 | static int linux_wlan_start_firmware(perInterface_wlan_t *nic) |
549 | { | |
550 | ||
c5c77ba1 JK |
551 | int ret = 0; |
552 | /* start firmware */ | |
553 | PRINT_D(INIT_DBG, "Starting Firmware ...\n"); | |
e42563bb | 554 | ret = wilc_wlan_start(); |
c5c77ba1 JK |
555 | if (ret < 0) { |
556 | PRINT_ER("Failed to start Firmware\n"); | |
557 | goto _fail_; | |
558 | } | |
559 | ||
560 | /* wait for mac ready */ | |
561 | PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n"); | |
562 | ret = linux_wlan_lock_timeout(&g_linux_wlan->sync_event, 5000); | |
563 | if (ret) { | |
c5c77ba1 JK |
564 | PRINT_D(INIT_DBG, "Firmware start timed out"); |
565 | goto _fail_; | |
566 | } | |
567 | /* | |
568 | * TODO: Driver shouoldn't wait forever for firmware to get started - | |
569 | * in case of timeout this should be handled properly | |
570 | */ | |
571 | PRINT_D(INIT_DBG, "Firmware successfully started\n"); | |
572 | ||
573 | _fail_: | |
574 | return ret; | |
575 | } | |
f61c5aff | 576 | static int linux_wlan_firmware_download(struct wilc *p_nic) |
c5c77ba1 JK |
577 | { |
578 | ||
579 | int ret = 0; | |
580 | ||
8b8ad7bc | 581 | if (!g_linux_wlan->firmware) { |
c5c77ba1 JK |
582 | PRINT_ER("Firmware buffer is NULL\n"); |
583 | ret = -ENOBUFS; | |
584 | goto _FAIL_; | |
585 | } | |
586 | /** | |
587 | * do the firmware download | |
588 | **/ | |
589 | PRINT_D(INIT_DBG, "Downloading Firmware ...\n"); | |
8b8ad7bc TC |
590 | ret = wilc_wlan_firmware_download(g_linux_wlan->firmware->data, |
591 | g_linux_wlan->firmware->size); | |
fc4b95d6 | 592 | if (ret < 0) |
c5c77ba1 | 593 | goto _FAIL_; |
c5c77ba1 JK |
594 | |
595 | /* Freeing FW buffer */ | |
596 | PRINT_D(INIT_DBG, "Freeing FW buffer ...\n"); | |
597 | PRINT_D(INIT_DBG, "Releasing firmware\n"); | |
8b8ad7bc | 598 | release_firmware(g_linux_wlan->firmware); |
c5c77ba1 | 599 | |
17aacd43 | 600 | PRINT_D(INIT_DBG, "Download Succeeded\n"); |
c5c77ba1 JK |
601 | |
602 | _FAIL_: | |
603 | return ret; | |
604 | } | |
605 | ||
c5c77ba1 | 606 | /* startup configuration - could be changed later using iconfig*/ |
f61c5aff | 607 | static int linux_wlan_init_test_config(struct net_device *dev, struct wilc *p_nic) |
c5c77ba1 JK |
608 | { |
609 | ||
610 | unsigned char c_val[64]; | |
c5c77ba1 | 611 | unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff}; |
c5c77ba1 | 612 | |
2726887c | 613 | struct wilc_priv *priv; |
441dc609 | 614 | struct host_if_drv *pstrWFIDrv; |
c5c77ba1 JK |
615 | |
616 | PRINT_D(TX_DBG, "Start configuring Firmware\n"); | |
c5c77ba1 JK |
617 | get_random_bytes(&mac_add[5], 1); |
618 | get_random_bytes(&mac_add[4], 1); | |
c5c77ba1 | 619 | priv = wiphy_priv(dev->ieee80211_ptr->wiphy); |
441dc609 | 620 | pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv; |
8a14330f | 621 | PRINT_D(INIT_DBG, "Host = %p\n", pstrWFIDrv); |
c5c77ba1 JK |
622 | |
623 | 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 | 624 | wilc_get_chipid(0); |
c5c77ba1 | 625 | |
e5d57e91 | 626 | *(int *)c_val = 1; |
c5c77ba1 | 627 | |
1028e5a4 | 628 | if (!wilc_wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0)) |
c5c77ba1 JK |
629 | goto _fail_; |
630 | ||
631 | /*to tell fw that we are going to use PC test - WILC specific*/ | |
632 | c_val[0] = 0; | |
1028e5a4 | 633 | if (!wilc_wlan_cfg_set(0, WID_PC_TEST_MODE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
634 | goto _fail_; |
635 | ||
636 | c_val[0] = INFRASTRUCTURE; | |
1028e5a4 | 637 | if (!wilc_wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
638 | goto _fail_; |
639 | ||
c3ca6372 | 640 | /* c_val[0] = RATE_AUTO; */ |
c5c77ba1 | 641 | c_val[0] = RATE_AUTO; |
1028e5a4 | 642 | if (!wilc_wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
643 | goto _fail_; |
644 | ||
645 | c_val[0] = G_MIXED_11B_2_MODE; | |
1028e5a4 | 646 | if (!wilc_wlan_cfg_set(0, WID_11G_OPERATING_MODE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
647 | goto _fail_; |
648 | ||
649 | c_val[0] = 1; | |
1028e5a4 | 650 | if (!wilc_wlan_cfg_set(0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0)) |
c5c77ba1 JK |
651 | goto _fail_; |
652 | ||
653 | c_val[0] = G_SHORT_PREAMBLE; | |
1028e5a4 | 654 | if (!wilc_wlan_cfg_set(0, WID_PREAMBLE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
655 | goto _fail_; |
656 | ||
657 | c_val[0] = AUTO_PROT; | |
1028e5a4 | 658 | if (!wilc_wlan_cfg_set(0, WID_11N_PROT_MECH, c_val, 1, 0, 0)) |
c5c77ba1 JK |
659 | goto _fail_; |
660 | ||
c5c77ba1 | 661 | c_val[0] = ACTIVE_SCAN; |
1028e5a4 | 662 | if (!wilc_wlan_cfg_set(0, WID_SCAN_TYPE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
663 | goto _fail_; |
664 | ||
665 | c_val[0] = SITE_SURVEY_OFF; | |
1028e5a4 | 666 | if (!wilc_wlan_cfg_set(0, WID_SITE_SURVEY, c_val, 1, 0, 0)) |
c5c77ba1 JK |
667 | goto _fail_; |
668 | ||
669 | *((int *)c_val) = 0xffff; /* Never use RTS-CTS */ | |
1028e5a4 | 670 | if (!wilc_wlan_cfg_set(0, WID_RTS_THRESHOLD, c_val, 2, 0, 0)) |
c5c77ba1 JK |
671 | goto _fail_; |
672 | ||
673 | *((int *)c_val) = 2346; | |
1028e5a4 | 674 | if (!wilc_wlan_cfg_set(0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0)) |
c5c77ba1 JK |
675 | goto _fail_; |
676 | ||
677 | /* SSID */ | |
678 | /* -------------------------------------------------------------- */ | |
679 | /* Configuration : String with length less than 32 bytes */ | |
680 | /* Values to set : Any string with length less than 32 bytes */ | |
681 | /* ( In BSS Station Set SSID to "" (null string) */ | |
682 | /* to enable Broadcast SSID suppport ) */ | |
683 | /* -------------------------------------------------------------- */ | |
c5c77ba1 | 684 | c_val[0] = 0; |
1028e5a4 | 685 | if (!wilc_wlan_cfg_set(0, WID_BCAST_SSID, c_val, 1, 0, 0)) |
c5c77ba1 JK |
686 | goto _fail_; |
687 | ||
688 | c_val[0] = 1; | |
1028e5a4 | 689 | if (!wilc_wlan_cfg_set(0, WID_QOS_ENABLE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
690 | goto _fail_; |
691 | ||
692 | c_val[0] = NO_POWERSAVE; | |
1028e5a4 | 693 | if (!wilc_wlan_cfg_set(0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0)) |
c5c77ba1 JK |
694 | goto _fail_; |
695 | ||
696 | c_val[0] = NO_ENCRYPT; /* NO_ENCRYPT, 0x79 */ | |
1028e5a4 | 697 | if (!wilc_wlan_cfg_set(0, WID_11I_MODE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
698 | goto _fail_; |
699 | ||
700 | c_val[0] = OPEN_SYSTEM; | |
1028e5a4 | 701 | if (!wilc_wlan_cfg_set(0, WID_AUTH_TYPE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
702 | goto _fail_; |
703 | ||
704 | /* WEP/802 11I Configuration */ | |
705 | /* ------------------------------------------------------------------ */ | |
706 | /* Configuration : WEP Key */ | |
707 | /* Values (0x) : 5 byte for WEP40 and 13 bytes for WEP104 */ | |
708 | /* In case more than 5 bytes are passed on for WEP 40 */ | |
709 | /* only first 5 bytes will be used as the key */ | |
710 | /* ------------------------------------------------------------------ */ | |
711 | ||
712 | strcpy(c_val, "123456790abcdef1234567890"); | |
1028e5a4 | 713 | if (!wilc_wlan_cfg_set(0, WID_WEP_KEY_VALUE, c_val, (strlen(c_val) + 1), 0, 0)) |
c5c77ba1 JK |
714 | goto _fail_; |
715 | ||
716 | /* WEP/802 11I Configuration */ | |
717 | /* ------------------------------------------------------------------ */ | |
718 | /* Configuration : AES/TKIP WPA/RSNA Pre-Shared Key */ | |
719 | /* Values to set : Any string with length greater than equal to 8 bytes */ | |
720 | /* and less than 64 bytes */ | |
721 | /* ------------------------------------------------------------------ */ | |
722 | strcpy(c_val, "12345678"); | |
1028e5a4 | 723 | if (!wilc_wlan_cfg_set(0, WID_11I_PSK, c_val, (strlen(c_val)), 0, 0)) |
c5c77ba1 JK |
724 | goto _fail_; |
725 | ||
726 | /* IEEE802.1X Key Configuration */ | |
727 | /* ------------------------------------------------------------------ */ | |
728 | /* Configuration : Radius Server Access Secret Key */ | |
729 | /* Values to set : Any string with length greater than equal to 8 bytes */ | |
730 | /* and less than 65 bytes */ | |
731 | /* ------------------------------------------------------------------ */ | |
732 | strcpy(c_val, "password"); | |
1028e5a4 | 733 | if (!wilc_wlan_cfg_set(0, WID_1X_KEY, c_val, (strlen(c_val) + 1), 0, 0)) |
c5c77ba1 JK |
734 | goto _fail_; |
735 | ||
736 | /* IEEE802.1X Server Address Configuration */ | |
737 | /* ------------------------------------------------------------------ */ | |
738 | /* Configuration : Radius Server IP Address */ | |
739 | /* Values to set : Any valid IP Address */ | |
740 | /* ------------------------------------------------------------------ */ | |
741 | c_val[0] = 192; | |
742 | c_val[1] = 168; | |
743 | c_val[2] = 1; | |
744 | c_val[3] = 112; | |
1028e5a4 | 745 | if (!wilc_wlan_cfg_set(0, WID_1X_SERV_ADDR, c_val, 4, 0, 0)) |
c5c77ba1 JK |
746 | goto _fail_; |
747 | ||
748 | c_val[0] = 3; | |
1028e5a4 | 749 | if (!wilc_wlan_cfg_set(0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0)) |
c5c77ba1 JK |
750 | goto _fail_; |
751 | ||
752 | c_val[0] = 3; | |
1028e5a4 | 753 | if (!wilc_wlan_cfg_set(0, WID_DTIM_PERIOD, c_val, 1, 0, 0)) |
c5c77ba1 JK |
754 | goto _fail_; |
755 | ||
756 | c_val[0] = NORMAL_ACK; | |
1028e5a4 | 757 | if (!wilc_wlan_cfg_set(0, WID_ACK_POLICY, c_val, 1, 0, 0)) |
c5c77ba1 JK |
758 | goto _fail_; |
759 | ||
760 | c_val[0] = 0; | |
1028e5a4 | 761 | if (!wilc_wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, 0, 0)) |
c5c77ba1 JK |
762 | goto _fail_; |
763 | ||
764 | c_val[0] = 48; | |
1028e5a4 | 765 | if (!wilc_wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, 0)) |
c5c77ba1 JK |
766 | goto _fail_; |
767 | ||
768 | c_val[0] = 28; | |
1028e5a4 | 769 | if (!wilc_wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, 0)) |
c5c77ba1 JK |
770 | goto _fail_; |
771 | ||
772 | /* Beacon Interval */ | |
773 | /* -------------------------------------------------------------------- */ | |
774 | /* Configuration : Sets the beacon interval value */ | |
775 | /* Values to set : Any 16-bit value */ | |
776 | /* -------------------------------------------------------------------- */ | |
777 | ||
778 | *((int *)c_val) = 100; | |
1028e5a4 | 779 | if (!wilc_wlan_cfg_set(0, WID_BEACON_INTERVAL, c_val, 2, 0, 0)) |
c5c77ba1 JK |
780 | goto _fail_; |
781 | ||
782 | c_val[0] = REKEY_DISABLE; | |
1028e5a4 | 783 | if (!wilc_wlan_cfg_set(0, WID_REKEY_POLICY, c_val, 1, 0, 0)) |
c5c77ba1 JK |
784 | goto _fail_; |
785 | ||
786 | /* Rekey Time (s) (Used only when the Rekey policy is 2 or 4) */ | |
787 | /* -------------------------------------------------------------------- */ | |
788 | /* Configuration : Sets the Rekey Time (s) */ | |
789 | /* Values to set : 32-bit value */ | |
790 | /* -------------------------------------------------------------------- */ | |
791 | *((int *)c_val) = 84600; | |
1028e5a4 | 792 | if (!wilc_wlan_cfg_set(0, WID_REKEY_PERIOD, c_val, 4, 0, 0)) |
c5c77ba1 JK |
793 | goto _fail_; |
794 | ||
795 | /* Rekey Packet Count (in 1000s; used when Rekey Policy is 3) */ | |
796 | /* -------------------------------------------------------------------- */ | |
797 | /* Configuration : Sets Rekey Group Packet count */ | |
798 | /* Values to set : 32-bit Value */ | |
799 | /* -------------------------------------------------------------------- */ | |
800 | *((int *)c_val) = 500; | |
1028e5a4 | 801 | if (!wilc_wlan_cfg_set(0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, 0)) |
c5c77ba1 JK |
802 | goto _fail_; |
803 | ||
804 | c_val[0] = 1; | |
1028e5a4 | 805 | if (!wilc_wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, 0)) |
c5c77ba1 JK |
806 | goto _fail_; |
807 | ||
808 | c_val[0] = G_SELF_CTS_PROT; | |
1028e5a4 | 809 | if (!wilc_wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
810 | goto _fail_; |
811 | ||
812 | c_val[0] = 1; /* Enable N */ | |
1028e5a4 | 813 | if (!wilc_wlan_cfg_set(0, WID_11N_ENABLE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
814 | goto _fail_; |
815 | ||
816 | c_val[0] = HT_MIXED_MODE; | |
1028e5a4 | 817 | if (!wilc_wlan_cfg_set(0, WID_11N_OPERATING_MODE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
818 | goto _fail_; |
819 | ||
820 | c_val[0] = 1; /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */ | |
1028e5a4 | 821 | if (!wilc_wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
822 | goto _fail_; |
823 | ||
824 | memcpy(c_val, mac_add, 6); | |
825 | ||
1028e5a4 | 826 | if (!wilc_wlan_cfg_set(0, WID_MAC_ADDR, c_val, 6, 0, 0)) |
c5c77ba1 JK |
827 | goto _fail_; |
828 | ||
829 | /** | |
830 | * AP only | |
831 | **/ | |
832 | c_val[0] = DETECT_PROTECT_REPORT; | |
1028e5a4 | 833 | if (!wilc_wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, 0, 0)) |
c5c77ba1 JK |
834 | goto _fail_; |
835 | ||
836 | c_val[0] = RTS_CTS_NONHT_PROT; | |
1028e5a4 | 837 | if (!wilc_wlan_cfg_set(0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
838 | goto _fail_; |
839 | ||
840 | c_val[0] = 0; | |
1028e5a4 | 841 | if (!wilc_wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
842 | goto _fail_; |
843 | ||
844 | c_val[0] = MIMO_MODE; | |
1028e5a4 | 845 | if (!wilc_wlan_cfg_set(0, WID_11N_SMPS_MODE, c_val, 1, 0, 0)) |
c5c77ba1 JK |
846 | goto _fail_; |
847 | ||
848 | c_val[0] = 7; | |
1028e5a4 | 849 | if (!wilc_wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, 0)) |
c5c77ba1 JK |
850 | goto _fail_; |
851 | ||
852 | c_val[0] = 1; /* Enable N with immediate block ack. */ | |
1028e5a4 | 853 | if (!wilc_wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, 1)) |
c5c77ba1 JK |
854 | goto _fail_; |
855 | ||
856 | return 0; | |
857 | ||
858 | _fail_: | |
859 | return -1; | |
860 | } | |
861 | ||
c5c77ba1 | 862 | /**************************/ |
f61c5aff | 863 | void wilc1000_wlan_deinit(struct wilc *nic) |
c5c77ba1 | 864 | { |
080f11bb | 865 | if (g_linux_wlan->initialized) { |
c5c77ba1 JK |
866 | printk("Deinitializing wilc1000 ...\n"); |
867 | ||
868 | if (nic == NULL) { | |
869 | PRINT_ER("nic is NULL\n"); | |
870 | return; | |
871 | } | |
872 | ||
873 | #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31) | |
874 | /* johnny : remove */ | |
875 | PRINT_D(INIT_DBG, "skip wilc_bus_set_default_speed\n"); | |
876 | #else | |
877 | wilc_bus_set_default_speed(); | |
878 | #endif | |
879 | ||
880 | PRINT_D(INIT_DBG, "Disabling IRQ\n"); | |
d59177cb | 881 | #ifdef WILC_SDIO |
5e150b52 | 882 | mutex_lock(&g_linux_wlan->hif_cs); |
c5c77ba1 | 883 | disable_sdio_interrupt(); |
5e150b52 | 884 | mutex_unlock(&g_linux_wlan->hif_cs); |
d59177cb | 885 | #endif |
fc4b95d6 | 886 | if (&g_linux_wlan->txq_event != NULL) |
8990d856 | 887 | up(&g_linux_wlan->txq_event); |
c5c77ba1 | 888 | |
c5c77ba1 JK |
889 | PRINT_D(INIT_DBG, "Deinitializing Threads\n"); |
890 | wlan_deinitialize_threads(nic); | |
891 | ||
892 | PRINT_D(INIT_DBG, "Deinitializing IRQ\n"); | |
893 | deinit_irq(g_linux_wlan); | |
894 | ||
8cec741e | 895 | wilc_wlan_stop(); |
c5c77ba1 JK |
896 | |
897 | PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n"); | |
a17e2ec1 | 898 | wilc_wlan_cleanup(); |
c5c77ba1 JK |
899 | #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) |
900 | #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31) | |
901 | PRINT_D(INIT_DBG, "Disabling IRQ 2\n"); | |
902 | ||
5e150b52 | 903 | mutex_lock(&g_linux_wlan->hif_cs); |
c5c77ba1 | 904 | disable_sdio_interrupt(); |
5e150b52 | 905 | mutex_unlock(&g_linux_wlan->hif_cs); |
c5c77ba1 JK |
906 | #endif |
907 | #endif | |
908 | ||
909 | /*De-Initialize locks*/ | |
910 | PRINT_D(INIT_DBG, "Deinitializing Locks\n"); | |
911 | wlan_deinit_locks(g_linux_wlan); | |
912 | ||
913 | /* announce that wilc1000 is not initialized */ | |
080f11bb | 914 | g_linux_wlan->initialized = false; |
c5c77ba1 JK |
915 | |
916 | PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n"); | |
917 | ||
918 | } else { | |
919 | PRINT_D(INIT_DBG, "wilc1000 is not initialized\n"); | |
920 | } | |
c5c77ba1 JK |
921 | } |
922 | ||
38afb390 | 923 | int wlan_init_locks(struct net_device *dev) |
c5c77ba1 | 924 | { |
38afb390 GL |
925 | perInterface_wlan_t *nic; |
926 | struct wilc *wl; | |
927 | ||
928 | nic = netdev_priv(dev); | |
929 | wl = nic->wilc; | |
c5c77ba1 JK |
930 | |
931 | PRINT_D(INIT_DBG, "Initializing Locks ...\n"); | |
932 | ||
38afb390 GL |
933 | mutex_init(&wl->hif_cs); |
934 | mutex_init(&wl->rxq_cs); | |
c5c77ba1 | 935 | |
38afb390 GL |
936 | spin_lock_init(&wl->txq_spinlock); |
937 | sema_init(&wl->txq_add_to_head_cs, 1); | |
c5c77ba1 | 938 | |
38afb390 | 939 | sema_init(&wl->txq_event, 0); |
c5c77ba1 | 940 | |
38afb390 GL |
941 | sema_init(&wl->cfg_event, 0); |
942 | sema_init(&wl->sync_event, 0); | |
c5c77ba1 | 943 | |
38afb390 | 944 | sema_init(&wl->txq_thread_started, 0); |
c5c77ba1 | 945 | |
c5c77ba1 JK |
946 | return 0; |
947 | } | |
948 | ||
f61c5aff | 949 | static int wlan_deinit_locks(struct wilc *nic) |
c5c77ba1 JK |
950 | { |
951 | PRINT_D(INIT_DBG, "De-Initializing Locks\n"); | |
952 | ||
953 | if (&g_linux_wlan->hif_cs != NULL) | |
19a33489 | 954 | mutex_destroy(&g_linux_wlan->hif_cs); |
c5c77ba1 JK |
955 | |
956 | if (&g_linux_wlan->rxq_cs != NULL) | |
19a33489 | 957 | mutex_destroy(&g_linux_wlan->rxq_cs); |
c5c77ba1 | 958 | |
c5c77ba1 JK |
959 | return 0; |
960 | } | |
f61c5aff | 961 | void linux_to_wlan(wilc_wlan_inp_t *nwi, struct wilc *nic) |
c5c77ba1 JK |
962 | { |
963 | ||
964 | PRINT_D(INIT_DBG, "Linux to Wlan services ...\n"); | |
965 | ||
c5c77ba1 | 966 | nwi->os_context.os_private = (void *)nic; |
c5c77ba1 | 967 | |
c5c77ba1 JK |
968 | #ifdef WILC_SDIO |
969 | nwi->io_func.io_type = HIF_SDIO; | |
970 | nwi->io_func.io_init = linux_sdio_init; | |
971 | nwi->io_func.io_deinit = linux_sdio_deinit; | |
972 | nwi->io_func.u.sdio.sdio_cmd52 = linux_sdio_cmd52; | |
973 | nwi->io_func.u.sdio.sdio_cmd53 = linux_sdio_cmd53; | |
974 | nwi->io_func.u.sdio.sdio_set_max_speed = linux_sdio_set_max_speed; | |
975 | nwi->io_func.u.sdio.sdio_set_default_speed = linux_sdio_set_default_speed; | |
976 | #else | |
977 | nwi->io_func.io_type = HIF_SPI; | |
978 | nwi->io_func.io_init = linux_spi_init; | |
979 | nwi->io_func.io_deinit = linux_spi_deinit; | |
980 | nwi->io_func.u.spi.spi_tx = linux_spi_write; | |
981 | nwi->io_func.u.spi.spi_rx = linux_spi_read; | |
982 | nwi->io_func.u.spi.spi_trx = linux_spi_write_read; | |
983 | nwi->io_func.u.spi.spi_max_speed = linux_spi_set_max_speed; | |
984 | #endif | |
c5c77ba1 JK |
985 | } |
986 | ||
987 | int wlan_initialize_threads(perInterface_wlan_t *nic) | |
988 | { | |
989 | ||
990 | int ret = 0; | |
8dfaafd6 | 991 | |
c5c77ba1 JK |
992 | PRINT_D(INIT_DBG, "Initializing Threads ...\n"); |
993 | ||
c5c77ba1 JK |
994 | /* create tx task */ |
995 | PRINT_D(INIT_DBG, "Creating kthread for transmission\n"); | |
996 | g_linux_wlan->txq_thread = kthread_run(linux_wlan_txq_task, (void *)g_linux_wlan, "K_TXQ_TASK"); | |
0e04f3f3 | 997 | if (g_linux_wlan->txq_thread == NULL) { |
c5c77ba1 JK |
998 | PRINT_ER("couldn't create TXQ thread\n"); |
999 | ret = -ENOBUFS; | |
1000 | goto _fail_2; | |
1001 | } | |
c5c77ba1 | 1002 | /* wait for TXQ task to start. */ |
8990d856 | 1003 | down(&g_linux_wlan->txq_thread_started); |
c5c77ba1 JK |
1004 | |
1005 | return 0; | |
1006 | ||
1007 | _fail_2: | |
1008 | /*De-Initialize 2nd thread*/ | |
1009 | g_linux_wlan->close = 1; | |
c5c77ba1 | 1010 | |
c5c77ba1 JK |
1011 | g_linux_wlan->close = 0; |
1012 | return ret; | |
1013 | } | |
1014 | ||
f61c5aff | 1015 | static void wlan_deinitialize_threads(struct wilc *nic) |
c5c77ba1 JK |
1016 | { |
1017 | ||
1018 | g_linux_wlan->close = 1; | |
1019 | PRINT_D(INIT_DBG, "Deinitializing Threads\n"); | |
c5c77ba1 | 1020 | |
c5c77ba1 | 1021 | if (&g_linux_wlan->txq_event != NULL) |
8990d856 | 1022 | up(&g_linux_wlan->txq_event); |
c5c77ba1 | 1023 | |
c5c77ba1 JK |
1024 | if (g_linux_wlan->txq_thread != NULL) { |
1025 | kthread_stop(g_linux_wlan->txq_thread); | |
1026 | g_linux_wlan->txq_thread = NULL; | |
1027 | } | |
c5c77ba1 JK |
1028 | } |
1029 | ||
c5c77ba1 JK |
1030 | int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic) |
1031 | { | |
1032 | wilc_wlan_inp_t nwi; | |
c5c77ba1 JK |
1033 | perInterface_wlan_t *nic = p_nic; |
1034 | int ret = 0; | |
0fa683b6 | 1035 | struct wilc *wl = nic->wilc; |
c5c77ba1 | 1036 | |
0fa683b6 GL |
1037 | if (!wl->initialized) { |
1038 | wl->mac_status = WILC_MAC_STATUS_INIT; | |
1039 | wl->close = 0; | |
c5c77ba1 | 1040 | |
38afb390 | 1041 | wlan_init_locks(dev); |
c5c77ba1 | 1042 | |
0fa683b6 | 1043 | linux_to_wlan(&nwi, wl); |
c5c77ba1 | 1044 | |
c9d4834d | 1045 | ret = wilc_wlan_init(&nwi); |
c5c77ba1 JK |
1046 | if (ret < 0) { |
1047 | PRINT_ER("Initializing WILC_Wlan FAILED\n"); | |
1048 | ret = -EIO; | |
1049 | goto _fail_locks_; | |
1050 | } | |
c5c77ba1 | 1051 | |
c5c77ba1 | 1052 | #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO) |
0fa683b6 | 1053 | if (init_irq(wl)) { |
c5c77ba1 JK |
1054 | PRINT_ER("couldn't initialize IRQ\n"); |
1055 | ret = -EIO; | |
b46d6882 | 1056 | goto _fail_locks_; |
c5c77ba1 JK |
1057 | } |
1058 | #endif | |
1059 | ||
b46d6882 TC |
1060 | ret = wlan_initialize_threads(nic); |
1061 | if (ret < 0) { | |
1062 | PRINT_ER("Initializing Threads FAILED\n"); | |
1063 | ret = -EIO; | |
1064 | goto _fail_wilc_wlan_; | |
1065 | } | |
1066 | ||
c5c77ba1 JK |
1067 | #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) |
1068 | if (enable_sdio_interrupt()) { | |
1069 | PRINT_ER("couldn't initialize IRQ\n"); | |
1070 | ret = -EIO; | |
1071 | goto _fail_irq_init_; | |
1072 | } | |
1073 | #endif | |
1074 | ||
1075 | if (linux_wlan_get_firmware(nic)) { | |
17aacd43 | 1076 | PRINT_ER("Can't get firmware\n"); |
c5c77ba1 JK |
1077 | ret = -EIO; |
1078 | goto _fail_irq_enable_; | |
1079 | } | |
1080 | ||
c5c77ba1 | 1081 | /*Download firmware*/ |
0fa683b6 | 1082 | ret = linux_wlan_firmware_download(wl); |
c5c77ba1 JK |
1083 | if (ret < 0) { |
1084 | PRINT_ER("Failed to download firmware\n"); | |
1085 | ret = -EIO; | |
1086 | goto _fail_irq_enable_; | |
1087 | } | |
1088 | ||
1089 | /* Start firmware*/ | |
1090 | ret = linux_wlan_start_firmware(nic); | |
1091 | if (ret < 0) { | |
1092 | PRINT_ER("Failed to start firmware\n"); | |
1093 | ret = -EIO; | |
1094 | goto _fail_irq_enable_; | |
1095 | } | |
1096 | ||
1097 | wilc_bus_set_max_speed(); | |
1098 | ||
07056a85 | 1099 | if (wilc_wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) { |
c5c77ba1 JK |
1100 | int size; |
1101 | char Firmware_ver[20]; | |
8dfaafd6 | 1102 | |
894de36b | 1103 | size = wilc_wlan_cfg_get_val( |
c5c77ba1 JK |
1104 | WID_FIRMWARE_VERSION, |
1105 | Firmware_ver, sizeof(Firmware_ver)); | |
1106 | Firmware_ver[size] = '\0'; | |
1107 | PRINT_D(INIT_DBG, "***** Firmware Ver = %s *******\n", Firmware_ver); | |
1108 | } | |
1109 | /* Initialize firmware with default configuration */ | |
0fa683b6 | 1110 | ret = linux_wlan_init_test_config(dev, wl); |
c5c77ba1 JK |
1111 | |
1112 | if (ret < 0) { | |
1113 | PRINT_ER("Failed to configure firmware\n"); | |
1114 | ret = -EIO; | |
1115 | goto _fail_fw_start_; | |
1116 | } | |
1117 | ||
0fa683b6 | 1118 | wl->initialized = true; |
c5c77ba1 JK |
1119 | return 0; /*success*/ |
1120 | ||
c5c77ba1 | 1121 | _fail_fw_start_: |
8cec741e | 1122 | wilc_wlan_stop(); |
c5c77ba1 JK |
1123 | |
1124 | _fail_irq_enable_: | |
1125 | #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) | |
1126 | disable_sdio_interrupt(); | |
c5c77ba1 | 1127 | _fail_irq_init_: |
7a8fd841 | 1128 | #endif |
c5c77ba1 | 1129 | #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO) |
0fa683b6 | 1130 | deinit_irq(wl); |
c5c77ba1 JK |
1131 | |
1132 | #endif | |
0fa683b6 | 1133 | wlan_deinitialize_threads(wl); |
c5c77ba1 | 1134 | _fail_wilc_wlan_: |
a17e2ec1 | 1135 | wilc_wlan_cleanup(); |
c5c77ba1 | 1136 | _fail_locks_: |
0fa683b6 | 1137 | wlan_deinit_locks(wl); |
c5c77ba1 JK |
1138 | PRINT_ER("WLAN Iinitialization FAILED\n"); |
1139 | } else { | |
1140 | PRINT_D(INIT_DBG, "wilc1000 already initialized\n"); | |
1141 | } | |
1142 | return ret; | |
1143 | } | |
1144 | ||
c5c77ba1 JK |
1145 | /* |
1146 | * - this function will be called automatically by OS when module inserted. | |
1147 | */ | |
1148 | ||
c5c77ba1 JK |
1149 | int mac_init_fn(struct net_device *ndev) |
1150 | { | |
1151 | ||
1152 | /*Why we do this !!!*/ | |
1153 | netif_start_queue(ndev); /* ma */ | |
1154 | netif_stop_queue(ndev); /* ma */ | |
1155 | ||
1156 | return 0; | |
1157 | } | |
c5c77ba1 | 1158 | |
c5c77ba1 | 1159 | /* This fn is called, when this device is setup using ifconfig */ |
c5c77ba1 JK |
1160 | int mac_open(struct net_device *ndev) |
1161 | { | |
1162 | perInterface_wlan_t *nic; | |
1163 | ||
c5c77ba1 JK |
1164 | /*No need for setting mac address here anymore,*/ |
1165 | /*Just set it in init_test_config()*/ | |
1166 | unsigned char mac_add[ETH_ALEN] = {0}; | |
c5c77ba1 JK |
1167 | int ret = 0; |
1168 | int i = 0; | |
2726887c | 1169 | struct wilc_priv *priv; |
c5c77ba1 | 1170 | |
7d05652c CG |
1171 | #ifdef WILC_SPI |
1172 | if (!g_linux_wlan || !g_linux_wlan->wilc_spidev) { | |
1173 | netdev_err(ndev, "wilc1000: SPI device not ready\n"); | |
1174 | return -ENODEV; | |
1175 | } | |
1176 | #endif | |
c5c77ba1 JK |
1177 | nic = netdev_priv(ndev); |
1178 | priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy); | |
1179 | PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev); | |
1180 | ||
dd4b6a83 | 1181 | ret = wilc_init_host_int(ndev); |
c5c77ba1 JK |
1182 | if (ret < 0) { |
1183 | PRINT_ER("Failed to initialize host interface\n"); | |
1184 | ||
1185 | return ret; | |
1186 | } | |
c5c77ba1 JK |
1187 | |
1188 | /*initialize platform*/ | |
1189 | PRINT_D(INIT_DBG, "*** re-init ***\n"); | |
1190 | ret = wilc1000_wlan_init(ndev, nic); | |
1191 | if (ret < 0) { | |
1192 | PRINT_ER("Failed to initialize wilc1000\n"); | |
a9a16823 | 1193 | wilc_deinit_host_int(ndev); |
c5c77ba1 JK |
1194 | return ret; |
1195 | } | |
1196 | ||
72ed4dc7 | 1197 | Set_machw_change_vir_if(false); |
c5c77ba1 | 1198 | |
21175ef7 | 1199 | host_int_get_MacAddress(priv->hWILCWFIDrv, mac_add); |
310a28fd | 1200 | PRINT_D(INIT_DBG, "Mac address: %pM\n", mac_add); |
c5c77ba1 JK |
1201 | |
1202 | /* loop through the NUM of supported devices and set the MAC address */ | |
c1b30f6a | 1203 | for (i = 0; i < g_linux_wlan->vif_num; i++) { |
817f3fb9 | 1204 | if (ndev == g_linux_wlan->vif[i].ndev) { |
7e7fa470 | 1205 | memcpy(g_linux_wlan->vif[i].src_addr, mac_add, ETH_ALEN); |
3134a578 | 1206 | g_linux_wlan->vif[i].hif_drv = priv->hWILCWFIDrv; |
c5c77ba1 JK |
1207 | break; |
1208 | } | |
1209 | } | |
1210 | ||
1211 | /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/ | |
7e7fa470 | 1212 | memcpy(ndev->dev_addr, g_linux_wlan->vif[i].src_addr, ETH_ALEN); |
c5c77ba1 JK |
1213 | |
1214 | if (!is_valid_ether_addr(ndev->dev_addr)) { | |
1215 | PRINT_ER("Error: Wrong MAC address\n"); | |
1216 | ret = -EINVAL; | |
1217 | goto _err_; | |
1218 | } | |
1219 | ||
8e0735c5 CL |
1220 | wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev->ieee80211_ptr, |
1221 | nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg); | |
1222 | wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev->ieee80211_ptr, | |
1223 | nic->g_struct_frame_reg[1].frame_type, nic->g_struct_frame_reg[1].reg); | |
c5c77ba1 JK |
1224 | netif_wake_queue(ndev); |
1225 | g_linux_wlan->open_ifcs++; | |
1226 | nic->mac_opened = 1; | |
1227 | return 0; | |
1228 | ||
1229 | _err_: | |
a9a16823 | 1230 | wilc_deinit_host_int(ndev); |
c5c77ba1 JK |
1231 | wilc1000_wlan_deinit(g_linux_wlan); |
1232 | return ret; | |
1233 | } | |
c5c77ba1 JK |
1234 | |
1235 | struct net_device_stats *mac_stats(struct net_device *dev) | |
1236 | { | |
1237 | perInterface_wlan_t *nic = netdev_priv(dev); | |
1238 | ||
c5c77ba1 JK |
1239 | return &nic->netstats; |
1240 | } | |
1241 | ||
1242 | /* Setup the multicast filter */ | |
c5c77ba1 JK |
1243 | static void wilc_set_multicast_list(struct net_device *dev) |
1244 | { | |
1245 | ||
1246 | struct netdev_hw_addr *ha; | |
2726887c | 1247 | struct wilc_priv *priv; |
441dc609 | 1248 | struct host_if_drv *pstrWFIDrv; |
c5c77ba1 | 1249 | int i = 0; |
8dfaafd6 | 1250 | |
c5c77ba1 | 1251 | priv = wiphy_priv(dev->ieee80211_ptr->wiphy); |
441dc609 | 1252 | pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv; |
c5c77ba1 | 1253 | |
c5c77ba1 JK |
1254 | if (!dev) |
1255 | return; | |
1256 | ||
17aacd43 | 1257 | PRINT_D(INIT_DBG, "Setting Multicast List with count = %d.\n", dev->mc.count); |
c5c77ba1 JK |
1258 | |
1259 | if (dev->flags & IFF_PROMISC) { | |
1260 | /* Normally, we should configure the chip to retrive all packets | |
1261 | * but we don't wanna support this right now */ | |
1262 | /* TODO: add promiscuous mode support */ | |
17aacd43 | 1263 | PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets\n"); |
c5c77ba1 JK |
1264 | return; |
1265 | } | |
1266 | ||
1267 | /* If there's more addresses than we handle, get all multicast | |
1268 | * packets and sort them out in software. */ | |
1269 | if ((dev->flags & IFF_ALLMULTI) || (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) { | |
1270 | PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n"); | |
1271 | /* get all multicast packets */ | |
218dc407 | 1272 | host_int_setup_multicast_filter(pstrWFIDrv, false, 0); |
c5c77ba1 JK |
1273 | return; |
1274 | } | |
1275 | ||
1276 | /* No multicast? Just get our own stuff */ | |
1277 | if ((dev->mc.count) == 0) { | |
1278 | PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n"); | |
218dc407 | 1279 | host_int_setup_multicast_filter(pstrWFIDrv, true, 0); |
c5c77ba1 JK |
1280 | return; |
1281 | } | |
1282 | ||
1283 | /* Store all of the multicast addresses in the hardware filter */ | |
1284 | netdev_for_each_mc_addr(ha, dev) | |
1285 | { | |
d00d2ba3 | 1286 | memcpy(gau8MulticastMacAddrList[i], ha->addr, ETH_ALEN); |
c5c77ba1 JK |
1287 | PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i, |
1288 | gau8MulticastMacAddrList[i][0], gau8MulticastMacAddrList[i][1], gau8MulticastMacAddrList[i][2], gau8MulticastMacAddrList[i][3], gau8MulticastMacAddrList[i][4], gau8MulticastMacAddrList[i][5]); | |
1289 | i++; | |
1290 | } | |
1291 | ||
218dc407 | 1292 | host_int_setup_multicast_filter(pstrWFIDrv, true, (dev->mc.count)); |
c5c77ba1 JK |
1293 | |
1294 | return; | |
1295 | ||
1296 | } | |
1297 | ||
c5c77ba1 JK |
1298 | static void linux_wlan_tx_complete(void *priv, int status) |
1299 | { | |
1300 | ||
1301 | struct tx_complete_data *pv_data = (struct tx_complete_data *)priv; | |
8dfaafd6 | 1302 | |
78174ada | 1303 | if (status == 1) |
c5c77ba1 | 1304 | PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb); |
78174ada | 1305 | else |
c5c77ba1 | 1306 | PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb); |
c5c77ba1 JK |
1307 | /* Free the SK Buffer, its work is done */ |
1308 | dev_kfree_skb(pv_data->skb); | |
a18dd630 | 1309 | kfree(pv_data); |
c5c77ba1 JK |
1310 | } |
1311 | ||
1312 | int mac_xmit(struct sk_buff *skb, struct net_device *ndev) | |
1313 | { | |
1314 | perInterface_wlan_t *nic; | |
1315 | struct tx_complete_data *tx_data = NULL; | |
1316 | int QueueCount; | |
1317 | char *pu8UdpBuffer; | |
1318 | struct iphdr *ih; | |
1319 | struct ethhdr *eth_h; | |
8dfaafd6 | 1320 | |
c5c77ba1 JK |
1321 | nic = netdev_priv(ndev); |
1322 | ||
c5c77ba1 JK |
1323 | PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n"); |
1324 | ||
1325 | /* Stop the network interface queue */ | |
1326 | if (skb->dev != ndev) { | |
1327 | PRINT_ER("Packet not destined to this device\n"); | |
1328 | return 0; | |
1329 | } | |
1330 | ||
d5df3797 | 1331 | tx_data = kmalloc(sizeof(struct tx_complete_data), GFP_ATOMIC); |
c5c77ba1 JK |
1332 | if (tx_data == NULL) { |
1333 | PRINT_ER("Failed to allocate memory for tx_data structure\n"); | |
1334 | dev_kfree_skb(skb); | |
1335 | netif_wake_queue(ndev); | |
1336 | return 0; | |
1337 | } | |
1338 | ||
1339 | tx_data->buff = skb->data; | |
1340 | tx_data->size = skb->len; | |
1341 | tx_data->skb = skb; | |
1342 | ||
1343 | eth_h = (struct ethhdr *)(skb->data); | |
fc4b95d6 | 1344 | if (eth_h->h_proto == 0x8e88) |
c5c77ba1 | 1345 | PRINT_D(INIT_DBG, "EAPOL transmitted\n"); |
c5c77ba1 JK |
1346 | |
1347 | /*get source and dest ip addresses*/ | |
1348 | ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr)); | |
1349 | ||
1350 | pu8UdpBuffer = (char *)ih + sizeof(struct iphdr); | |
fc4b95d6 | 1351 | if ((pu8UdpBuffer[1] == 68 && pu8UdpBuffer[3] == 67) || (pu8UdpBuffer[1] == 67 && pu8UdpBuffer[3] == 68)) |
c5c77ba1 JK |
1352 | PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer[248], pu8UdpBuffer[249], pu8UdpBuffer[250]); |
1353 | ||
c5c77ba1 JK |
1354 | PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb); |
1355 | ||
1356 | /* Send packet to MAC HW - for now the tx_complete function will be just status | |
1357 | * indicator. still not sure if I need to suspend host transmission till the tx_complete | |
1358 | * function called or not? | |
1359 | * allocated buffer will be freed in tx_complete function. | |
1360 | */ | |
1361 | PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n"); | |
1362 | nic->netstats.tx_packets++; | |
1363 | nic->netstats.tx_bytes += tx_data->size; | |
7201cd2c | 1364 | tx_data->pBssid = g_linux_wlan->vif[nic->u8IfIdx].bssid; |
8fc84a6f GL |
1365 | QueueCount = wilc_wlan_txq_add_net_pkt((void *)tx_data, tx_data->buff, |
1366 | tx_data->size, | |
1367 | linux_wlan_tx_complete); | |
c5c77ba1 | 1368 | |
c5c77ba1 | 1369 | if (QueueCount > FLOW_CONTROL_UPPER_THRESHOLD) { |
817f3fb9 TC |
1370 | netif_stop_queue(g_linux_wlan->vif[0].ndev); |
1371 | netif_stop_queue(g_linux_wlan->vif[1].ndev); | |
c5c77ba1 JK |
1372 | } |
1373 | ||
1374 | return 0; | |
1375 | } | |
1376 | ||
c5c77ba1 JK |
1377 | int mac_close(struct net_device *ndev) |
1378 | { | |
2726887c | 1379 | struct wilc_priv *priv; |
c5c77ba1 | 1380 | perInterface_wlan_t *nic; |
441dc609 | 1381 | struct host_if_drv *pstrWFIDrv; |
c5c77ba1 JK |
1382 | |
1383 | nic = netdev_priv(ndev); | |
1384 | ||
1385 | if ((nic == NULL) || (nic->wilc_netdev == NULL) || (nic->wilc_netdev->ieee80211_ptr == NULL) || (nic->wilc_netdev->ieee80211_ptr->wiphy == NULL)) { | |
1386 | PRINT_ER("nic = NULL\n"); | |
1387 | return 0; | |
1388 | } | |
1389 | ||
1390 | priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy); | |
1391 | ||
1392 | if (priv == NULL) { | |
1393 | PRINT_ER("priv = NULL\n"); | |
1394 | return 0; | |
1395 | } | |
1396 | ||
441dc609 | 1397 | pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv; |
c5c77ba1 | 1398 | |
c5c77ba1 JK |
1399 | PRINT_D(GENERIC_DBG, "Mac close\n"); |
1400 | ||
1401 | if (g_linux_wlan == NULL) { | |
1402 | PRINT_ER("g_linux_wlan = NULL\n"); | |
1403 | return 0; | |
1404 | } | |
1405 | ||
1406 | if (pstrWFIDrv == NULL) { | |
1407 | PRINT_ER("pstrWFIDrv = NULL\n"); | |
1408 | return 0; | |
1409 | } | |
1410 | ||
1411 | if ((g_linux_wlan->open_ifcs) > 0) { | |
1412 | g_linux_wlan->open_ifcs--; | |
1413 | } else { | |
1414 | PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n"); | |
1415 | return 0; | |
1416 | } | |
1417 | ||
1418 | if (nic->wilc_netdev != NULL) { | |
1419 | /* Stop the network interface queue */ | |
1420 | netif_stop_queue(nic->wilc_netdev); | |
1421 | ||
a9a16823 | 1422 | wilc_deinit_host_int(nic->wilc_netdev); |
c5c77ba1 JK |
1423 | } |
1424 | ||
1425 | if (g_linux_wlan->open_ifcs == 0) { | |
1426 | PRINT_D(GENERIC_DBG, "Deinitializing wilc1000\n"); | |
1427 | g_linux_wlan->close = 1; | |
1428 | wilc1000_wlan_deinit(g_linux_wlan); | |
c5c77ba1 | 1429 | WILC_WFI_deinit_mon_interface(); |
c5c77ba1 JK |
1430 | } |
1431 | ||
8990d856 | 1432 | up(&close_exit_sync); |
c5c77ba1 JK |
1433 | nic->mac_opened = 0; |
1434 | ||
1435 | return 0; | |
1436 | } | |
1437 | ||
c5c77ba1 JK |
1438 | int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) |
1439 | { | |
1440 | ||
63d03e47 | 1441 | u8 *buff = NULL; |
ca356ada | 1442 | s8 rssi; |
4e4467fd | 1443 | u32 size = 0, length = 0; |
c5c77ba1 | 1444 | perInterface_wlan_t *nic; |
2726887c | 1445 | struct wilc_priv *priv; |
e6e12661 | 1446 | s32 s32Error = 0; |
c5c77ba1 | 1447 | |
c5c77ba1 | 1448 | /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */ |
c5c77ba1 JK |
1449 | nic = netdev_priv(ndev); |
1450 | ||
080f11bb | 1451 | if (!g_linux_wlan->initialized) |
c5c77ba1 JK |
1452 | return 0; |
1453 | ||
c5c77ba1 | 1454 | switch (cmd) { |
c5c77ba1 JK |
1455 | |
1456 | /* ]] 2013-06-24 */ | |
1457 | case SIOCSIWPRIV: | |
1458 | { | |
1459 | struct iwreq *wrq = (struct iwreq *) req; /* added by tony */ | |
1460 | ||
1461 | size = wrq->u.data.length; | |
1462 | ||
1463 | if (size && wrq->u.data.pointer) { | |
c5c77ba1 | 1464 | |
4a01f1c3 | 1465 | buff = memdup_user(wrq->u.data.pointer, wrq->u.data.length); |
360e27a9 SM |
1466 | if (IS_ERR(buff)) |
1467 | return PTR_ERR(buff); | |
c5c77ba1 JK |
1468 | |
1469 | if (strncasecmp(buff, "RSSI", length) == 0) { | |
c5c77ba1 JK |
1470 | priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy); |
1471 | s32Error = host_int_get_rssi(priv->hWILCWFIDrv, &(rssi)); | |
1472 | if (s32Error) | |
1473 | PRINT_ER("Failed to send get rssi param's message queue "); | |
c5c77ba1 JK |
1474 | PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi); |
1475 | ||
1476 | /*Rounding up the rssi negative value*/ | |
1477 | rssi += 5; | |
1478 | ||
1479 | snprintf(buff, size, "rssi %d", rssi); | |
1480 | ||
1481 | if (copy_to_user(wrq->u.data.pointer, buff, size)) { | |
60cb1e20 | 1482 | PRINT_ER("%s: failed to copy data to user buffer\n", __func__); |
c5c77ba1 JK |
1483 | s32Error = -EFAULT; |
1484 | goto done; | |
1485 | } | |
1486 | } | |
1487 | } | |
1488 | } | |
1489 | break; | |
1490 | ||
1491 | default: | |
1492 | { | |
1493 | PRINT_INFO(GENERIC_DBG, "Command - %d - has been received\n", cmd); | |
1494 | s32Error = -EOPNOTSUPP; | |
1495 | goto done; | |
1496 | } | |
1497 | } | |
1498 | ||
1499 | done: | |
1500 | ||
642ac6c0 | 1501 | kfree(buff); |
c5c77ba1 JK |
1502 | |
1503 | return s32Error; | |
1504 | } | |
1505 | ||
fbc2fe16 | 1506 | void frmw_to_linux(u8 *buff, u32 size, u32 pkt_offset) |
c5c77ba1 JK |
1507 | { |
1508 | ||
1509 | unsigned int frame_len = 0; | |
1510 | int stats; | |
1511 | unsigned char *buff_to_send = NULL; | |
1512 | struct sk_buff *skb; | |
c5c77ba1 JK |
1513 | struct net_device *wilc_netdev; |
1514 | perInterface_wlan_t *nic; | |
1515 | ||
1516 | wilc_netdev = GetIfHandler(buff); | |
1517 | if (wilc_netdev == NULL) | |
1518 | return; | |
1519 | ||
1520 | buff += pkt_offset; | |
1521 | nic = netdev_priv(wilc_netdev); | |
1522 | ||
1523 | if (size > 0) { | |
1524 | ||
1525 | frame_len = size; | |
1526 | buff_to_send = buff; | |
1527 | ||
c5c77ba1 JK |
1528 | /* Need to send the packet up to the host, allocate a skb buffer */ |
1529 | skb = dev_alloc_skb(frame_len); | |
1530 | if (skb == NULL) { | |
1531 | PRINT_ER("Low memory - packet droped\n"); | |
1532 | return; | |
1533 | } | |
1534 | ||
fc4b95d6 | 1535 | if (g_linux_wlan == NULL || wilc_netdev == NULL) |
c5c77ba1 | 1536 | PRINT_ER("wilc_netdev in g_linux_wlan is NULL"); |
c5c77ba1 JK |
1537 | skb->dev = wilc_netdev; |
1538 | ||
fc4b95d6 | 1539 | if (skb->dev == NULL) |
c5c77ba1 | 1540 | PRINT_ER("skb->dev is NULL\n"); |
c5c77ba1 JK |
1541 | |
1542 | /* | |
1543 | * for(i=0;i<40;i++) | |
1544 | * { | |
1545 | * if(i<frame_len) | |
1546 | * WILC_PRINTF("buff_to_send[%d]=%2x\n",i,buff_to_send[i]); | |
1547 | * | |
1548 | * }*/ | |
1549 | ||
1550 | /* skb_put(skb, frame_len); */ | |
1551 | memcpy(skb_put(skb, frame_len), buff_to_send, frame_len); | |
1552 | ||
1553 | /* WILC_PRINTF("After MEM_CPY\n"); */ | |
1554 | ||
1555 | /* nic = netdev_priv(wilc_netdev); */ | |
1556 | ||
c5c77ba1 | 1557 | skb->protocol = eth_type_trans(skb, wilc_netdev); |
c5c77ba1 JK |
1558 | /* Send the packet to the stack by giving it to the bridge */ |
1559 | nic->netstats.rx_packets++; | |
1560 | nic->netstats.rx_bytes += frame_len; | |
1561 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
1562 | stats = netif_rx(skb); | |
1563 | PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats); | |
1564 | } | |
c5c77ba1 JK |
1565 | } |
1566 | ||
fbc2fe16 | 1567 | void WILC_WFI_mgmt_rx(u8 *buff, u32 size) |
c5c77ba1 JK |
1568 | { |
1569 | int i = 0; | |
1570 | perInterface_wlan_t *nic; | |
1571 | ||
c5c77ba1 JK |
1572 | /*Pass the frame on the monitor interface, if any.*/ |
1573 | /*Otherwise, pass it on p2p0 netdev, if registered on it*/ | |
c1b30f6a | 1574 | for (i = 0; i < g_linux_wlan->vif_num; i++) { |
817f3fb9 | 1575 | nic = netdev_priv(g_linux_wlan->vif[i].ndev); |
c5c77ba1 JK |
1576 | if (nic->monitor_flag) { |
1577 | WILC_WFI_monitor_rx(buff, size); | |
1578 | return; | |
1579 | } | |
1580 | } | |
1581 | ||
817f3fb9 | 1582 | nic = netdev_priv(g_linux_wlan->vif[1].ndev); /* p2p0 */ |
c5c77ba1 | 1583 | if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) || |
fc4b95d6 | 1584 | (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg)) |
817f3fb9 | 1585 | WILC_WFI_p2p_rx(g_linux_wlan->vif[1].ndev, buff, size); |
c5c77ba1 JK |
1586 | } |
1587 | ||
4875c499 TC |
1588 | void wl_wlan_cleanup(void) |
1589 | { | |
1590 | int i = 0; | |
1591 | perInterface_wlan_t *nic[NUM_CONCURRENT_IFC]; | |
1592 | ||
1593 | if (g_linux_wlan && | |
1594 | (g_linux_wlan->vif[0].ndev || g_linux_wlan->vif[1].ndev)) { | |
1595 | unregister_inetaddr_notifier(&g_dev_notifier); | |
1596 | ||
1597 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) | |
1598 | nic[i] = netdev_priv(g_linux_wlan->vif[i].ndev); | |
1599 | } | |
1600 | ||
8b8ad7bc TC |
1601 | if (g_linux_wlan && g_linux_wlan->firmware) |
1602 | release_firmware(g_linux_wlan->firmware); | |
4875c499 TC |
1603 | |
1604 | if (g_linux_wlan && | |
1605 | (g_linux_wlan->vif[0].ndev || g_linux_wlan->vif[1].ndev)) { | |
1606 | linux_wlan_lock_timeout(&close_exit_sync, 12 * 1000); | |
1607 | ||
1608 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) | |
1609 | if (g_linux_wlan->vif[i].ndev) | |
1610 | if (nic[i]->mac_opened) | |
1611 | mac_close(g_linux_wlan->vif[i].ndev); | |
1612 | ||
1613 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) { | |
1614 | unregister_netdev(g_linux_wlan->vif[i].ndev); | |
1615 | wilc_free_wiphy(g_linux_wlan->vif[i].ndev); | |
1616 | free_netdev(g_linux_wlan->vif[i].ndev); | |
1617 | } | |
1618 | } | |
1619 | ||
1620 | kfree(g_linux_wlan); | |
1621 | ||
1622 | #if defined(WILC_DEBUGFS) | |
1623 | wilc_debugfs_remove(); | |
1624 | #endif | |
1625 | linux_wlan_device_detection(0); | |
1626 | linux_wlan_device_power(0); | |
1627 | } | |
1628 | ||
12ba5416 | 1629 | int wilc_netdev_init(struct wilc **wilc) |
c5c77ba1 | 1630 | { |
c5c77ba1 JK |
1631 | int i; |
1632 | perInterface_wlan_t *nic; | |
1633 | struct net_device *ndev; | |
1634 | ||
642768ee | 1635 | sema_init(&close_exit_sync, 0); |
c5c77ba1 JK |
1636 | |
1637 | /*create the common structure*/ | |
f61c5aff | 1638 | g_linux_wlan = kzalloc(sizeof(*g_linux_wlan), GFP_KERNEL); |
ac61ef86 CL |
1639 | if (!g_linux_wlan) |
1640 | return -ENOMEM; | |
c5c77ba1 | 1641 | |
12ba5416 TC |
1642 | *wilc = g_linux_wlan; |
1643 | ||
c5c77ba1 | 1644 | register_inetaddr_notifier(&g_dev_notifier); |
c5c77ba1 JK |
1645 | |
1646 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) { | |
1647 | /*allocate first ethernet device with perinterface_wlan_t as its private data*/ | |
1648 | ndev = alloc_etherdev(sizeof(perInterface_wlan_t)); | |
1649 | if (!ndev) { | |
1650 | PRINT_ER("Failed to allocate ethernet dev\n"); | |
1651 | return -1; | |
1652 | } | |
1653 | ||
1654 | nic = netdev_priv(ndev); | |
1655 | memset(nic, 0, sizeof(perInterface_wlan_t)); | |
1656 | ||
1657 | /*Name the Devices*/ | |
1658 | if (i == 0) { | |
1659 | #if defined(NM73131) /* tony, 2012-09-20 */ | |
1660 | strcpy(ndev->name, "wilc_eth%d"); | |
1661 | #elif defined(PLAT_CLM9722) /* rachel */ | |
1662 | strcpy(ndev->name, "eth%d"); | |
1663 | #else /* PANDA_BOARD, PLAT_ALLWINNER_A10, PLAT_ALLWINNER_A20, PLAT_ALLWINNER_A31, PLAT_AML8726_M3 or PLAT_WMS8304 */ | |
1664 | strcpy(ndev->name, "wlan%d"); | |
1665 | #endif | |
1666 | } else | |
1667 | strcpy(ndev->name, "p2p%d"); | |
1668 | ||
c1b30f6a | 1669 | nic->u8IfIdx = g_linux_wlan->vif_num; |
c5c77ba1 | 1670 | nic->wilc_netdev = ndev; |
38b3001d | 1671 | nic->wilc = *wilc; |
817f3fb9 | 1672 | g_linux_wlan->vif[g_linux_wlan->vif_num].ndev = ndev; |
c1b30f6a | 1673 | g_linux_wlan->vif_num++; |
e5af0561 | 1674 | ndev->netdev_ops = &wilc_netdev_ops; |
c5c77ba1 | 1675 | |
c5c77ba1 JK |
1676 | { |
1677 | struct wireless_dev *wdev; | |
1678 | /*Register WiFi*/ | |
8459fd54 | 1679 | wdev = wilc_create_wiphy(ndev); |
c5c77ba1 JK |
1680 | |
1681 | #ifdef WILC_SDIO | |
1682 | /* set netdev, tony */ | |
1683 | SET_NETDEV_DEV(ndev, &local_sdio_func->dev); | |
1684 | #endif | |
1685 | ||
1686 | if (wdev == NULL) { | |
1687 | PRINT_ER("Can't register WILC Wiphy\n"); | |
1688 | return -1; | |
1689 | } | |
1690 | ||
1691 | /*linking the wireless_dev structure with the netdevice*/ | |
1692 | nic->wilc_netdev->ieee80211_ptr = wdev; | |
1693 | nic->wilc_netdev->ml_priv = nic; | |
1694 | wdev->netdev = nic->wilc_netdev; | |
1695 | nic->netstats.rx_packets = 0; | |
1696 | nic->netstats.tx_packets = 0; | |
1697 | nic->netstats.rx_bytes = 0; | |
1698 | nic->netstats.tx_bytes = 0; | |
1699 | ||
1700 | } | |
c5c77ba1 | 1701 | |
c5c77ba1 JK |
1702 | if (register_netdev(ndev)) { |
1703 | PRINT_ER("Device couldn't be registered - %s\n", ndev->name); | |
1704 | return -1; /* ERROR */ | |
1705 | } | |
1706 | ||
1707 | nic->iftype = STATION_MODE; | |
1708 | nic->mac_opened = 0; | |
1709 | ||
1710 | } | |
1711 | ||
1712 | #ifndef WILC_SDIO | |
1713 | if (!linux_spi_init(&g_linux_wlan->wilc_spidev)) { | |
17aacd43 | 1714 | PRINT_ER("Can't initialize SPI\n"); |
c5c77ba1 JK |
1715 | return -1; /* ERROR */ |
1716 | } | |
1717 | g_linux_wlan->wilc_spidev = wilc_spi_dev; | |
1718 | #else | |
1719 | g_linux_wlan->wilc_sdio_func = local_sdio_func; | |
1720 | #endif | |
1721 | ||
1722 | return 0; | |
1723 | } | |
1724 | ||
c5c77ba1 JK |
1725 | /*The 1st function called after module inserted*/ |
1726 | static int __init init_wilc_driver(void) | |
1727 | { | |
33694632 | 1728 | #if defined(WILC_DEBUGFS) |
c5c77ba1 JK |
1729 | if (wilc_debugfs_init() < 0) { |
1730 | PRINT_D(GENERIC_DBG, "fail to create debugfs for wilc driver\n"); | |
1731 | return -1; | |
1732 | } | |
1733 | #endif | |
1734 | ||
1735 | printk("IN INIT FUNCTION\n"); | |
691f1a2f | 1736 | printk("*** WILC1000 driver VERSION=[10.2] FW_VER=[10.2] ***\n"); |
c5c77ba1 JK |
1737 | |
1738 | linux_wlan_device_power(1); | |
1739 | msleep(100); | |
1740 | linux_wlan_device_detection(1); | |
1741 | ||
1742 | #ifdef WILC_SDIO | |
1743 | { | |
1744 | int ret; | |
1745 | ||
1746 | ret = sdio_register_driver(&wilc_bus); | |
fc4b95d6 | 1747 | if (ret < 0) |
c5c77ba1 | 1748 | PRINT_D(INIT_DBG, "init_wilc_driver: Failed register sdio driver\n"); |
c5c77ba1 JK |
1749 | |
1750 | return ret; | |
1751 | } | |
1752 | #else | |
1753 | PRINT_D(INIT_DBG, "Initializing netdev\n"); | |
fc4b95d6 | 1754 | if (wilc_netdev_init()) |
c5c77ba1 | 1755 | PRINT_ER("Couldn't initialize netdev\n"); |
c5c77ba1 JK |
1756 | return 0; |
1757 | #endif | |
1758 | } | |
1759 | late_initcall(init_wilc_driver); | |
1760 | ||
1761 | static void __exit exit_wilc_driver(void) | |
1762 | { | |
c2eda352 CL |
1763 | #ifndef WILC_SDIO |
1764 | PRINT_D(INIT_DBG, "SPI unregsiter...\n"); | |
1765 | spi_unregister_driver(&wilc_bus); | |
1766 | #else | |
1767 | PRINT_D(INIT_DBG, "SDIO unregsiter...\n"); | |
1768 | sdio_unregister_driver(&wilc_bus); | |
1769 | #endif | |
c5c77ba1 JK |
1770 | } |
1771 | module_exit(exit_wilc_driver); | |
1772 | ||
1773 | MODULE_LICENSE("GPL"); |