aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/libertas/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/libertas/main.c')
-rw-r--r--drivers/net/wireless/libertas/main.c673
1 files changed, 294 insertions, 379 deletions
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index b9b25ce65919..ec9be0c51c69 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -4,6 +4,7 @@
4 * thread etc.. 4 * thread etc..
5 */ 5 */
6 6
7#include <linux/moduleparam.h>
7#include <linux/delay.h> 8#include <linux/delay.h>
8#include <linux/freezer.h> 9#include <linux/freezer.h>
9#include <linux/etherdevice.h> 10#include <linux/etherdevice.h>
@@ -11,26 +12,28 @@
11#include <linux/if_arp.h> 12#include <linux/if_arp.h>
12 13
13#include <net/iw_handler.h> 14#include <net/iw_handler.h>
15#include <net/ieee80211.h>
14 16
15#include "host.h" 17#include "host.h"
16#include "sbi.h"
17#include "decl.h" 18#include "decl.h"
18#include "dev.h" 19#include "dev.h"
19#include "fw.h"
20#include "wext.h" 20#include "wext.h"
21#include "debugfs.h" 21#include "debugfs.h"
22#include "assoc.h" 22#include "assoc.h"
23 23
24#define DRIVER_RELEASE_VERSION "320.p0" 24#define DRIVER_RELEASE_VERSION "322.p0"
25const char libertas_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION 25const char libertas_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
26#ifdef DEBUG 26#ifdef DEBUG
27 "-dbg" 27 "-dbg"
28#endif 28#endif
29 ""; 29 "";
30 30
31#ifdef ENABLE_PM 31
32static struct pm_dev *wlan_pm_dev = NULL; 32/* Module parameters */
33#endif 33unsigned int libertas_debug = 0;
34module_param(libertas_debug, int, 0644);
35EXPORT_SYMBOL_GPL(libertas_debug);
36
34 37
35#define WLAN_TX_PWR_DEFAULT 20 /*100mW */ 38#define WLAN_TX_PWR_DEFAULT 20 /*100mW */
36#define WLAN_TX_PWR_US_DEFAULT 20 /*100mW */ 39#define WLAN_TX_PWR_US_DEFAULT 20 /*100mW */
@@ -146,14 +149,6 @@ static struct region_cfp_table region_cfp_table[] = {
146}; 149};
147 150
148/** 151/**
149 * the rates supported by the card
150 */
151u8 libertas_wlan_data_rates[WLAN_SUPPORTED_RATES] =
152 { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
153 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
154};
155
156/**
157 * the rates supported 152 * the rates supported
158 */ 153 */
159u8 libertas_supported_rates[G_SUPPORTED_RATES] = 154u8 libertas_supported_rates[G_SUPPORTED_RATES] =
@@ -173,23 +168,11 @@ u8 libertas_adhoc_rates_g[G_SUPPORTED_RATES] =
173u8 libertas_adhoc_rates_b[4] = { 0x82, 0x84, 0x8b, 0x96 }; 168u8 libertas_adhoc_rates_b[4] = { 0x82, 0x84, 0x8b, 0x96 };
174 169
175/** 170/**
176 * the global variable of a pointer to wlan_private
177 * structure variable
178 */
179static wlan_private *wlanpriv = NULL;
180
181#define MAX_DEVS 5
182static struct net_device *libertas_devs[MAX_DEVS];
183static int libertas_found = 0;
184
185/**
186 * the table to keep region code 171 * the table to keep region code
187 */ 172 */
188u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE] = 173u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
189 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 }; 174 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
190 175
191static u8 *default_fw_name = "usb8388.bin";
192
193/** 176/**
194 * Attributes exported through sysfs 177 * Attributes exported through sysfs
195 */ 178 */
@@ -207,7 +190,7 @@ static ssize_t libertas_mpp_get(struct device * dev,
207 cmd_act_mesh_get_mpp, 190 cmd_act_mesh_get_mpp,
208 cmd_option_waitforrsp, 0, (void *)&mesh_access); 191 cmd_option_waitforrsp, 0, (void *)&mesh_access);
209 192
210 return snprintf(buf, 3, "%d\n", mesh_access.data[0]); 193 return snprintf(buf, 3, "%d\n", le32_to_cpu(mesh_access.data[0]));
211} 194}
212 195
213/** 196/**
@@ -216,10 +199,12 @@ static ssize_t libertas_mpp_get(struct device * dev,
216static ssize_t libertas_mpp_set(struct device * dev, 199static ssize_t libertas_mpp_set(struct device * dev,
217 struct device_attribute *attr, const char * buf, size_t count) { 200 struct device_attribute *attr, const char * buf, size_t count) {
218 struct cmd_ds_mesh_access mesh_access; 201 struct cmd_ds_mesh_access mesh_access;
219 202 uint32_t datum;
220 203
221 memset(&mesh_access, 0, sizeof(mesh_access)); 204 memset(&mesh_access, 0, sizeof(mesh_access));
222 sscanf(buf, "%d", &(mesh_access.data[0])); 205 sscanf(buf, "%d", &datum);
206 mesh_access.data[0] = cpu_to_le32(datum);
207
223 libertas_prepare_and_send_command((to_net_dev(dev))->priv, 208 libertas_prepare_and_send_command((to_net_dev(dev))->priv,
224 cmd_mesh_access, 209 cmd_mesh_access,
225 cmd_act_mesh_set_mpp, 210 cmd_act_mesh_set_mpp,
@@ -231,8 +216,7 @@ static ssize_t libertas_mpp_set(struct device * dev,
231 * libertas_mpp attribute to be exported per mshX interface 216 * libertas_mpp attribute to be exported per mshX interface
232 * through sysfs (/sys/class/net/mshX/libertas-mpp) 217 * through sysfs (/sys/class/net/mshX/libertas-mpp)
233 */ 218 */
234static DEVICE_ATTR(libertas_mpp, 0644, libertas_mpp_get, 219static DEVICE_ATTR(libertas_mpp, 0644, libertas_mpp_get, libertas_mpp_set );
235 libertas_mpp_set );
236 220
237/** 221/**
238 * @brief Check if the device can be open and wait if necessary. 222 * @brief Check if the device can be open and wait if necessary.
@@ -245,7 +229,8 @@ static DEVICE_ATTR(libertas_mpp, 0644, libertas_mpp_get,
245 * function to work around the issue. 229 * function to work around the issue.
246 * 230 *
247 */ 231 */
248static int pre_open_check(struct net_device *dev) { 232static int pre_open_check(struct net_device *dev)
233{
249 wlan_private *priv = (wlan_private *) dev->priv; 234 wlan_private *priv = (wlan_private *) dev->priv;
250 wlan_adapter *adapter = priv->adapter; 235 wlan_adapter *adapter = priv->adapter;
251 int i = 0; 236 int i = 0;
@@ -255,8 +240,7 @@ static int pre_open_check(struct net_device *dev) {
255 msleep_interruptible(100); 240 msleep_interruptible(100);
256 } 241 }
257 if (!adapter->fw_ready) { 242 if (!adapter->fw_ready) {
258 lbs_pr_info("FW not ready, pre_open_check() return failure\n"); 243 lbs_pr_err("firmware not ready\n");
259 LEAVE();
260 return -1; 244 return -1;
261 } 245 }
262 246
@@ -274,17 +258,19 @@ static int wlan_dev_open(struct net_device *dev)
274 wlan_private *priv = (wlan_private *) dev->priv; 258 wlan_private *priv = (wlan_private *) dev->priv;
275 wlan_adapter *adapter = priv->adapter; 259 wlan_adapter *adapter = priv->adapter;
276 260
277 ENTER(); 261 lbs_deb_enter(LBS_DEB_NET);
278
279 262
280 priv->open = 1; 263 priv->open = 1;
281 264
282 if (adapter->connect_status == libertas_connected) { 265 if (adapter->connect_status == libertas_connected) {
283 netif_carrier_on(priv->wlan_dev.netdev); 266 netif_carrier_on(priv->dev);
284 } else 267 netif_carrier_on(priv->mesh_dev);
285 netif_carrier_off(priv->wlan_dev.netdev); 268 } else {
269 netif_carrier_off(priv->dev);
270 netif_carrier_off(priv->mesh_dev);
271 }
286 272
287 LEAVE(); 273 lbs_deb_leave(LBS_DEB_NET);
288 return 0; 274 return 0;
289} 275}
290/** 276/**
@@ -297,12 +283,12 @@ static int mesh_open(struct net_device *dev)
297{ 283{
298 wlan_private *priv = (wlan_private *) dev->priv ; 284 wlan_private *priv = (wlan_private *) dev->priv ;
299 285
300 if(pre_open_check(dev) == -1) 286 if (pre_open_check(dev) == -1)
301 return -1; 287 return -1;
302 priv->mesh_open = 1 ; 288 priv->mesh_open = 1 ;
303 netif_start_queue(priv->mesh_dev); 289 netif_wake_queue(priv->mesh_dev);
304 if (priv->infra_open == 0) 290 if (priv->infra_open == 0)
305 return wlan_dev_open(priv->wlan_dev.netdev) ; 291 return wlan_dev_open(priv->dev) ;
306 return 0; 292 return 0;
307} 293}
308 294
@@ -319,9 +305,9 @@ static int wlan_open(struct net_device *dev)
319 if(pre_open_check(dev) == -1) 305 if(pre_open_check(dev) == -1)
320 return -1; 306 return -1;
321 priv->infra_open = 1 ; 307 priv->infra_open = 1 ;
322 netif_wake_queue(priv->wlan_dev.netdev); 308 netif_wake_queue(priv->dev);
323 if (priv->open == 0) 309 if (priv->open == 0)
324 return wlan_dev_open(priv->wlan_dev.netdev) ; 310 return wlan_dev_open(priv->dev) ;
325 return 0; 311 return 0;
326} 312}
327 313
@@ -329,12 +315,12 @@ static int wlan_dev_close(struct net_device *dev)
329{ 315{
330 wlan_private *priv = dev->priv; 316 wlan_private *priv = dev->priv;
331 317
332 ENTER(); 318 lbs_deb_enter(LBS_DEB_NET);
333 319
334 netif_carrier_off(priv->wlan_dev.netdev); 320 netif_carrier_off(priv->dev);
335 priv->open = 0; 321 priv->open = 0;
336 322
337 LEAVE(); 323 lbs_deb_leave(LBS_DEB_NET);
338 return 0; 324 return 0;
339} 325}
340 326
@@ -351,7 +337,7 @@ static int mesh_close(struct net_device *dev)
351 priv->mesh_open = 0; 337 priv->mesh_open = 0;
352 netif_stop_queue(priv->mesh_dev); 338 netif_stop_queue(priv->mesh_dev);
353 if (priv->infra_open == 0) 339 if (priv->infra_open == 0)
354 return wlan_dev_close( ((wlan_private *) dev->priv)->wlan_dev.netdev) ; 340 return wlan_dev_close(dev);
355 else 341 else
356 return 0; 342 return 0;
357} 343}
@@ -362,147 +348,38 @@ static int mesh_close(struct net_device *dev)
362 * @param dev A pointer to net_device structure 348 * @param dev A pointer to net_device structure
363 * @return 0 349 * @return 0
364 */ 350 */
365static int wlan_close(struct net_device *dev) { 351static int wlan_close(struct net_device *dev)
352{
366 wlan_private *priv = (wlan_private *) dev->priv; 353 wlan_private *priv = (wlan_private *) dev->priv;
367 354
368 netif_stop_queue(priv->wlan_dev.netdev); 355 netif_stop_queue(dev);
369 priv->infra_open = 0; 356 priv->infra_open = 0;
370 if (priv->mesh_open == 0) 357 if (priv->mesh_open == 0)
371 return wlan_dev_close( ((wlan_private *) dev->priv)->wlan_dev.netdev) ; 358 return wlan_dev_close(dev);
372 else 359 else
373 return 0; 360 return 0;
374} 361}
375 362
376 363
377#ifdef ENABLE_PM
378
379/**
380 * @brief This function is a callback function. it is called by
381 * kernel to enter or exit power saving mode.
382 *
383 * @param pmdev A pointer to pm_dev
384 * @param pmreq pm_request_t
385 * @param pmdata A pointer to pmdata
386 * @return 0 or -1
387 */
388static int wlan_pm_callback(struct pm_dev *pmdev, pm_request_t pmreq,
389 void *pmdata)
390{
391 wlan_private *priv = wlanpriv;
392 wlan_adapter *adapter = priv->adapter;
393 struct net_device *dev = priv->wlan_dev.netdev;
394
395 lbs_pr_debug(1, "WPRM_PM_CALLBACK: pmreq = %d.\n", pmreq);
396
397 switch (pmreq) {
398 case PM_SUSPEND:
399 lbs_pr_debug(1, "WPRM_PM_CALLBACK: enter PM_SUSPEND.\n");
400
401 /* in associated mode */
402 if (adapter->connect_status == libertas_connected) {
403 if ((adapter->psstate != PS_STATE_SLEEP)
404 ) {
405 lbs_pr_debug(1,
406 "wlan_pm_callback: can't enter sleep mode\n");
407 return -1;
408 } else {
409
410 /*
411 * Detach the network interface
412 * if the network is running
413 */
414 if (netif_running(dev)) {
415 netif_device_detach(dev);
416 lbs_pr_debug(1,
417 "netif_device_detach().\n");
418 }
419 libertas_sbi_suspend(priv);
420 }
421 break;
422 }
423
424 /* in non associated mode */
425
426 /*
427 * Detach the network interface
428 * if the network is running
429 */
430 if (netif_running(dev))
431 netif_device_detach(dev);
432
433 /*
434 * Storing and restoring of the regs be taken care
435 * at the driver rest will be done at wlan driver
436 * this makes driver independent of the card
437 */
438
439 libertas_sbi_suspend(priv);
440
441 break;
442
443 case PM_RESUME:
444 /* in associated mode */
445 if (adapter->connect_status == libertas_connected) {
446 {
447 /*
448 * Bring the inteface up first
449 * This case should not happen still ...
450 */
451 libertas_sbi_resume(priv);
452
453 /*
454 * Attach the network interface
455 * if the network is running
456 */
457 if (netif_running(dev)) {
458 netif_device_attach(dev);
459 lbs_pr_debug(1,
460 "after netif_device_attach().\n");
461 }
462 lbs_pr_debug(1,
463 "After netif attach, in associated mode.\n");
464 }
465 break;
466 }
467
468 /* in non associated mode */
469
470 /*
471 * Bring the inteface up first
472 * This case should not happen still ...
473 */
474
475 libertas_sbi_resume(priv);
476
477 if (netif_running(dev))
478 netif_device_attach(dev);
479
480 lbs_pr_debug(1, "after netif attach, in NON associated mode.\n");
481 break;
482 }
483
484 return 0;
485}
486#endif /* ENABLE_PM */
487
488static int wlan_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) 364static int wlan_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
489{ 365{
490 int ret = 0; 366 int ret = 0;
491 wlan_private *priv = dev->priv; 367 wlan_private *priv = dev->priv;
492 368
493 ENTER(); 369 lbs_deb_enter(LBS_DEB_NET);
494 370
495 if (priv->wlan_dev.dnld_sent || priv->adapter->TxLockFlag) { 371 if (priv->dnld_sent || priv->adapter->TxLockFlag) {
496 priv->stats.tx_dropped++; 372 priv->stats.tx_dropped++;
497 goto done; 373 goto done;
498 } 374 }
499 375
500 netif_stop_queue(priv->wlan_dev.netdev); 376 netif_stop_queue(priv->dev);
377 netif_stop_queue(priv->mesh_dev);
501 378
502 if (libertas_process_tx(priv, skb) == 0) 379 if (libertas_process_tx(priv, skb) == 0)
503 dev->trans_start = jiffies; 380 dev->trans_start = jiffies;
504done: 381done:
505 LEAVE(); 382 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
506 return ret; 383 return ret;
507} 384}
508 385
@@ -513,33 +390,43 @@ done:
513static int mesh_pre_start_xmit(struct sk_buff *skb, struct net_device *dev) 390static int mesh_pre_start_xmit(struct sk_buff *skb, struct net_device *dev)
514{ 391{
515 wlan_private *priv = dev->priv; 392 wlan_private *priv = dev->priv;
516 ENTER(); 393 int ret;
394
395 lbs_deb_enter(LBS_DEB_MESH);
396
517 SET_MESH_FRAME(skb); 397 SET_MESH_FRAME(skb);
518 LEAVE();
519 398
520 return wlan_hard_start_xmit(skb, priv->wlan_dev.netdev); 399 ret = wlan_hard_start_xmit(skb, priv->dev);
400 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
401 return ret;
521} 402}
522 403
523/** 404/**
524 * @brief Mark non-mesh packets and handover them to wlan_hard_start_xmit 405 * @brief Mark non-mesh packets and handover them to wlan_hard_start_xmit
525 * 406 *
526 */ 407 */
527static int wlan_pre_start_xmit(struct sk_buff *skb, struct net_device *dev) { 408static int wlan_pre_start_xmit(struct sk_buff *skb, struct net_device *dev)
528 ENTER(); 409{
410 int ret;
411
412 lbs_deb_enter(LBS_DEB_NET);
413
529 UNSET_MESH_FRAME(skb); 414 UNSET_MESH_FRAME(skb);
530 LEAVE(); 415
531 return wlan_hard_start_xmit(skb, dev); 416 ret = wlan_hard_start_xmit(skb, dev);
417 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
418 return ret;
532} 419}
533 420
534static void wlan_tx_timeout(struct net_device *dev) 421static void wlan_tx_timeout(struct net_device *dev)
535{ 422{
536 wlan_private *priv = (wlan_private *) dev->priv; 423 wlan_private *priv = (wlan_private *) dev->priv;
537 424
538 ENTER(); 425 lbs_deb_enter(LBS_DEB_TX);
539 426
540 lbs_pr_err("tx watch dog timeout!\n"); 427 lbs_pr_err("tx watch dog timeout\n");
541 428
542 priv->wlan_dev.dnld_sent = DNLD_RES_RECEIVED; 429 priv->dnld_sent = DNLD_RES_RECEIVED;
543 dev->trans_start = jiffies; 430 dev->trans_start = jiffies;
544 431
545 if (priv->adapter->currenttxskb) { 432 if (priv->adapter->currenttxskb) {
@@ -550,10 +437,12 @@ static void wlan_tx_timeout(struct net_device *dev)
550 libertas_send_tx_feedback(priv); 437 libertas_send_tx_feedback(priv);
551 } else 438 } else
552 wake_up_interruptible(&priv->mainthread.waitq); 439 wake_up_interruptible(&priv->mainthread.waitq);
553 } else if (priv->adapter->connect_status == libertas_connected) 440 } else if (priv->adapter->connect_status == libertas_connected) {
554 netif_wake_queue(priv->wlan_dev.netdev); 441 netif_wake_queue(priv->dev);
442 netif_wake_queue(priv->mesh_dev);
443 }
555 444
556 LEAVE(); 445 lbs_deb_leave(LBS_DEB_TX);
557} 446}
558 447
559/** 448/**
@@ -576,7 +465,10 @@ static int wlan_set_mac_address(struct net_device *dev, void *addr)
576 wlan_adapter *adapter = priv->adapter; 465 wlan_adapter *adapter = priv->adapter;
577 struct sockaddr *phwaddr = addr; 466 struct sockaddr *phwaddr = addr;
578 467
579 ENTER(); 468 lbs_deb_enter(LBS_DEB_NET);
469
470 /* In case it was called from the mesh device */
471 dev = priv->dev ;
580 472
581 memset(adapter->current_addr, 0, ETH_ALEN); 473 memset(adapter->current_addr, 0, ETH_ALEN);
582 474
@@ -591,17 +483,18 @@ static int wlan_set_mac_address(struct net_device *dev, void *addr)
591 cmd_option_waitforrsp, 0, NULL); 483 cmd_option_waitforrsp, 0, NULL);
592 484
593 if (ret) { 485 if (ret) {
594 lbs_pr_debug(1, "set mac address failed.\n"); 486 lbs_deb_net("set MAC address failed\n");
595 ret = -1; 487 ret = -1;
596 goto done; 488 goto done;
597 } 489 }
598 490
599 lbs_dbg_hex("adapter->macaddr:", adapter->current_addr, ETH_ALEN); 491 lbs_dbg_hex("adapter->macaddr:", adapter->current_addr, ETH_ALEN);
600 memcpy(dev->dev_addr, adapter->current_addr, ETH_ALEN); 492 memcpy(dev->dev_addr, adapter->current_addr, ETH_ALEN);
601 memcpy(((wlan_private *) dev->priv)->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN); 493 if (priv->mesh_dev)
494 memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
602 495
603done: 496done:
604 LEAVE(); 497 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
605 return ret; 498 return ret;
606} 499}
607 500
@@ -626,12 +519,12 @@ static void wlan_set_multicast_list(struct net_device *dev)
626 wlan_adapter *adapter = priv->adapter; 519 wlan_adapter *adapter = priv->adapter;
627 int oldpacketfilter; 520 int oldpacketfilter;
628 521
629 ENTER(); 522 lbs_deb_enter(LBS_DEB_NET);
630 523
631 oldpacketfilter = adapter->currentpacketfilter; 524 oldpacketfilter = adapter->currentpacketfilter;
632 525
633 if (dev->flags & IFF_PROMISC) { 526 if (dev->flags & IFF_PROMISC) {
634 lbs_pr_debug(1, "enable Promiscuous mode\n"); 527 lbs_deb_net("enable promiscuous mode\n");
635 adapter->currentpacketfilter |= 528 adapter->currentpacketfilter |=
636 cmd_act_mac_promiscuous_enable; 529 cmd_act_mac_promiscuous_enable;
637 adapter->currentpacketfilter &= 530 adapter->currentpacketfilter &=
@@ -644,7 +537,7 @@ static void wlan_set_multicast_list(struct net_device *dev)
644 537
645 if (dev->flags & IFF_ALLMULTI || dev->mc_count > 538 if (dev->flags & IFF_ALLMULTI || dev->mc_count >
646 MRVDRV_MAX_MULTICAST_LIST_SIZE) { 539 MRVDRV_MAX_MULTICAST_LIST_SIZE) {
647 lbs_pr_debug(1, "Enabling All Multicast!\n"); 540 lbs_deb_net( "enabling all multicast\n");
648 adapter->currentpacketfilter |= 541 adapter->currentpacketfilter |=
649 cmd_act_mac_all_multicast_enable; 542 cmd_act_mac_all_multicast_enable;
650 adapter->currentpacketfilter &= 543 adapter->currentpacketfilter &=
@@ -654,8 +547,8 @@ static void wlan_set_multicast_list(struct net_device *dev)
654 ~cmd_act_mac_all_multicast_enable; 547 ~cmd_act_mac_all_multicast_enable;
655 548
656 if (!dev->mc_count) { 549 if (!dev->mc_count) {
657 lbs_pr_debug(1, "No multicast addresses - " 550 lbs_deb_net("no multicast addresses, "
658 "disabling multicast!\n"); 551 "disabling multicast\n");
659 adapter->currentpacketfilter &= 552 adapter->currentpacketfilter &=
660 ~cmd_act_mac_multicast_enable; 553 ~cmd_act_mac_multicast_enable;
661 } else { 554 } else {
@@ -667,12 +560,12 @@ static void wlan_set_multicast_list(struct net_device *dev)
667 adapter->nr_of_multicastmacaddr = 560 adapter->nr_of_multicastmacaddr =
668 wlan_copy_multicast_address(adapter, dev); 561 wlan_copy_multicast_address(adapter, dev);
669 562
670 lbs_pr_debug(1, "Multicast addresses: %d\n", 563 lbs_deb_net("multicast addresses: %d\n",
671 dev->mc_count); 564 dev->mc_count);
672 565
673 for (i = 0; i < dev->mc_count; i++) { 566 for (i = 0; i < dev->mc_count; i++) {
674 lbs_pr_debug(1, "Multicast address %d:" 567 lbs_deb_net("Multicast address %d:"
675 "%x %x %x %x %x %x\n", i, 568 MAC_FMT "\n", i,
676 adapter->multicastlist[i][0], 569 adapter->multicastlist[i][0],
677 adapter->multicastlist[i][1], 570 adapter->multicastlist[i][1],
678 adapter->multicastlist[i][2], 571 adapter->multicastlist[i][2],
@@ -680,7 +573,7 @@ static void wlan_set_multicast_list(struct net_device *dev)
680 adapter->multicastlist[i][4], 573 adapter->multicastlist[i][4],
681 adapter->multicastlist[i][5]); 574 adapter->multicastlist[i][5]);
682 } 575 }
683 /* set multicast addresses to firmware */ 576 /* send multicast addresses to firmware */
684 libertas_prepare_and_send_command(priv, 577 libertas_prepare_and_send_command(priv,
685 cmd_mac_multicast_adr, 578 cmd_mac_multicast_adr,
686 cmd_act_set, 0, 0, 579 cmd_act_set, 0, 0,
@@ -693,13 +586,13 @@ static void wlan_set_multicast_list(struct net_device *dev)
693 libertas_set_mac_packet_filter(priv); 586 libertas_set_mac_packet_filter(priv);
694 } 587 }
695 588
696 LEAVE(); 589 lbs_deb_leave(LBS_DEB_NET);
697} 590}
698 591
699/** 592/**
700 * @brief This function hanldes the major job in WLAN driver. 593 * @brief This function handles the major jobs in the WLAN driver.
701 * it handles the event generated by firmware, rx data received 594 * It handles all events generated by firmware, RX data received
702 * from firmware and tx data sent from kernel. 595 * from firmware and TX data sent from kernel.
703 * 596 *
704 * @param data A pointer to wlan_thread structure 597 * @param data A pointer to wlan_thread structure
705 * @return 0 598 * @return 0
@@ -712,26 +605,26 @@ static int wlan_service_main_thread(void *data)
712 wait_queue_t wait; 605 wait_queue_t wait;
713 u8 ireg = 0; 606 u8 ireg = 0;
714 607
715 ENTER(); 608 lbs_deb_enter(LBS_DEB_THREAD);
716 609
717 wlan_activate_thread(thread); 610 wlan_activate_thread(thread);
718 611
719 init_waitqueue_entry(&wait, current); 612 init_waitqueue_entry(&wait, current);
720 613
721 for (;;) { 614 for (;;) {
722 lbs_pr_debug(1, "main-thread 111: intcounter=%d " 615 lbs_deb_thread( "main-thread 111: intcounter=%d "
723 "currenttxskb=%p dnld_sent=%d\n", 616 "currenttxskb=%p dnld_sent=%d\n",
724 adapter->intcounter, 617 adapter->intcounter,
725 adapter->currenttxskb, priv->wlan_dev.dnld_sent); 618 adapter->currenttxskb, priv->dnld_sent);
726 619
727 add_wait_queue(&thread->waitq, &wait); 620 add_wait_queue(&thread->waitq, &wait);
728 set_current_state(TASK_INTERRUPTIBLE); 621 set_current_state(TASK_INTERRUPTIBLE);
729 spin_lock_irq(&adapter->driver_lock); 622 spin_lock_irq(&adapter->driver_lock);
730 if ((adapter->psstate == PS_STATE_SLEEP) || 623 if ((adapter->psstate == PS_STATE_SLEEP) ||
731 (!adapter->intcounter 624 (!adapter->intcounter
732 && (priv->wlan_dev.dnld_sent || adapter->cur_cmd || 625 && (priv->dnld_sent || adapter->cur_cmd ||
733 list_empty(&adapter->cmdpendingq)))) { 626 list_empty(&adapter->cmdpendingq)))) {
734 lbs_pr_debug(1, 627 lbs_deb_thread(
735 "main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n", 628 "main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
736 adapter->connect_status, adapter->intcounter, 629 adapter->connect_status, adapter->intcounter,
737 adapter->psmode, adapter->psstate); 630 adapter->psmode, adapter->psstate);
@@ -741,23 +634,23 @@ static int wlan_service_main_thread(void *data)
741 spin_unlock_irq(&adapter->driver_lock); 634 spin_unlock_irq(&adapter->driver_lock);
742 635
743 636
744 lbs_pr_debug(1, 637 lbs_deb_thread(
745 "main-thread 222 (waking up): intcounter=%d currenttxskb=%p " 638 "main-thread 222 (waking up): intcounter=%d currenttxskb=%p "
746 "dnld_sent=%d\n", adapter->intcounter, 639 "dnld_sent=%d\n", adapter->intcounter,
747 adapter->currenttxskb, priv->wlan_dev.dnld_sent); 640 adapter->currenttxskb, priv->dnld_sent);
748 641
749 set_current_state(TASK_RUNNING); 642 set_current_state(TASK_RUNNING);
750 remove_wait_queue(&thread->waitq, &wait); 643 remove_wait_queue(&thread->waitq, &wait);
751 try_to_freeze(); 644 try_to_freeze();
752 645
753 lbs_pr_debug(1, "main-thread 333: intcounter=%d currenttxskb=%p " 646 lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p "
754 "dnld_sent=%d\n", 647 "dnld_sent=%d\n",
755 adapter->intcounter, 648 adapter->intcounter,
756 adapter->currenttxskb, priv->wlan_dev.dnld_sent); 649 adapter->currenttxskb, priv->dnld_sent);
757 650
758 if (kthread_should_stop() 651 if (kthread_should_stop()
759 || adapter->surpriseremoved) { 652 || adapter->surpriseremoved) {
760 lbs_pr_debug(1, 653 lbs_deb_thread(
761 "main-thread: break from main thread: surpriseremoved=0x%x\n", 654 "main-thread: break from main thread: surpriseremoved=0x%x\n",
762 adapter->surpriseremoved); 655 adapter->surpriseremoved);
763 break; 656 break;
@@ -768,10 +661,10 @@ static int wlan_service_main_thread(void *data)
768 if (adapter->intcounter) { 661 if (adapter->intcounter) {
769 u8 int_status; 662 u8 int_status;
770 adapter->intcounter = 0; 663 adapter->intcounter = 0;
771 int_status = libertas_sbi_get_int_status(priv, &ireg); 664 int_status = priv->hw_get_int_status(priv, &ireg);
772 665
773 if (int_status) { 666 if (int_status) {
774 lbs_pr_debug(1, 667 lbs_deb_thread(
775 "main-thread: reading HOST_INT_STATUS_REG failed\n"); 668 "main-thread: reading HOST_INT_STATUS_REG failed\n");
776 spin_unlock_irq(&adapter->driver_lock); 669 spin_unlock_irq(&adapter->driver_lock);
777 continue; 670 continue;
@@ -779,14 +672,14 @@ static int wlan_service_main_thread(void *data)
779 adapter->hisregcpy |= ireg; 672 adapter->hisregcpy |= ireg;
780 } 673 }
781 674
782 lbs_pr_debug(1, "main-thread 444: intcounter=%d currenttxskb=%p " 675 lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p "
783 "dnld_sent=%d\n", 676 "dnld_sent=%d\n",
784 adapter->intcounter, 677 adapter->intcounter,
785 adapter->currenttxskb, priv->wlan_dev.dnld_sent); 678 adapter->currenttxskb, priv->dnld_sent);
786 679
787 /* command response? */ 680 /* command response? */
788 if (adapter->hisregcpy & his_cmdupldrdy) { 681 if (adapter->hisregcpy & his_cmdupldrdy) {
789 lbs_pr_debug(1, "main-thread: cmd response ready.\n"); 682 lbs_deb_thread("main-thread: cmd response ready\n");
790 683
791 adapter->hisregcpy &= ~his_cmdupldrdy; 684 adapter->hisregcpy &= ~his_cmdupldrdy;
792 spin_unlock_irq(&adapter->driver_lock); 685 spin_unlock_irq(&adapter->driver_lock);
@@ -796,13 +689,13 @@ static int wlan_service_main_thread(void *data)
796 689
797 /* Any Card Event */ 690 /* Any Card Event */
798 if (adapter->hisregcpy & his_cardevent) { 691 if (adapter->hisregcpy & his_cardevent) {
799 lbs_pr_debug(1, "main-thread: Card Event Activity.\n"); 692 lbs_deb_thread("main-thread: Card Event Activity\n");
800 693
801 adapter->hisregcpy &= ~his_cardevent; 694 adapter->hisregcpy &= ~his_cardevent;
802 695
803 if (libertas_sbi_read_event_cause(priv)) { 696 if (priv->hw_read_event_cause(priv)) {
804 lbs_pr_alert( 697 lbs_pr_alert(
805 "main-thread: libertas_sbi_read_event_cause failed.\n"); 698 "main-thread: hw_read_event_cause failed\n");
806 spin_unlock_irq(&adapter->driver_lock); 699 spin_unlock_irq(&adapter->driver_lock);
807 continue; 700 continue;
808 } 701 }
@@ -813,15 +706,15 @@ static int wlan_service_main_thread(void *data)
813 706
814 /* Check if we need to confirm Sleep Request received previously */ 707 /* Check if we need to confirm Sleep Request received previously */
815 if (adapter->psstate == PS_STATE_PRE_SLEEP) { 708 if (adapter->psstate == PS_STATE_PRE_SLEEP) {
816 if (!priv->wlan_dev.dnld_sent && !adapter->cur_cmd) { 709 if (!priv->dnld_sent && !adapter->cur_cmd) {
817 if (adapter->connect_status == 710 if (adapter->connect_status ==
818 libertas_connected) { 711 libertas_connected) {
819 lbs_pr_debug(1, 712 lbs_deb_thread(
820 "main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p " 713 "main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p "
821 "dnld_sent=%d cur_cmd=%p, confirm now\n", 714 "dnld_sent=%d cur_cmd=%p, confirm now\n",
822 adapter->intcounter, 715 adapter->intcounter,
823 adapter->currenttxskb, 716 adapter->currenttxskb,
824 priv->wlan_dev.dnld_sent, 717 priv->dnld_sent,
825 adapter->cur_cmd); 718 adapter->cur_cmd);
826 719
827 libertas_ps_confirm_sleep(priv, 720 libertas_ps_confirm_sleep(priv,
@@ -847,7 +740,7 @@ static int wlan_service_main_thread(void *data)
847 continue; 740 continue;
848 741
849 /* Execute the next command */ 742 /* Execute the next command */
850 if (!priv->wlan_dev.dnld_sent && !priv->adapter->cur_cmd) 743 if (!priv->dnld_sent && !priv->adapter->cur_cmd)
851 libertas_execute_next_command(priv); 744 libertas_execute_next_command(priv);
852 745
853 /* Wake-up command waiters which can't sleep in 746 /* Wake-up command waiters which can't sleep in
@@ -864,7 +757,7 @@ static int wlan_service_main_thread(void *data)
864 wake_up_all(&adapter->cmd_pending); 757 wake_up_all(&adapter->cmd_pending);
865 wlan_deactivate_thread(thread); 758 wlan_deactivate_thread(thread);
866 759
867 LEAVE(); 760 lbs_deb_leave(LBS_DEB_THREAD);
868 return 0; 761 return 0;
869} 762}
870 763
@@ -875,49 +768,32 @@ static int wlan_service_main_thread(void *data)
875 * @param card A pointer to card 768 * @param card A pointer to card
876 * @return A pointer to wlan_private structure 769 * @return A pointer to wlan_private structure
877 */ 770 */
878wlan_private *wlan_add_card(void *card) 771wlan_private *libertas_add_card(void *card, struct device *dmdev)
879{ 772{
880 struct net_device *dev = NULL; 773 struct net_device *dev = NULL;
881 struct net_device *mesh_dev = NULL;
882 wlan_private *priv = NULL; 774 wlan_private *priv = NULL;
883 775
884 ENTER(); 776 lbs_deb_enter(LBS_DEB_NET);
885 777
886 /* Allocate an Ethernet device and register it */ 778 /* Allocate an Ethernet device and register it */
887 if (!(dev = alloc_etherdev(sizeof(wlan_private)))) { 779 if (!(dev = alloc_etherdev(sizeof(wlan_private)))) {
888 lbs_pr_alert( "Init ethernet device failed!\n"); 780 lbs_pr_err("init ethX device failed\n");
889 return NULL; 781 return NULL;
890 } 782 }
891
892 priv = dev->priv; 783 priv = dev->priv;
893 784
894 /* allocate buffer for wlan_adapter */ 785 /* allocate buffer for wlan_adapter */
895 if (!(priv->adapter = kmalloc(sizeof(wlan_adapter), GFP_KERNEL))) { 786 if (!(priv->adapter = kzalloc(sizeof(wlan_adapter), GFP_KERNEL))) {
896 lbs_pr_alert( "Allocate buffer for wlan_adapter failed!\n"); 787 lbs_pr_err("allocate buffer for wlan_adapter failed\n");
897 goto err_kmalloc; 788 goto err_kzalloc;
898 } 789 }
899 790
900 /* Allocate a virtual mesh device */ 791 priv->dev = dev;
901 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) { 792 priv->card = card;
902 lbs_pr_debug(1, "Init ethernet device failed!\n");
903 return NULL;
904 }
905
906 /* Both intervaces share the priv structure */
907 mesh_dev->priv = priv;
908
909 /* init wlan_adapter */
910 memset(priv->adapter, 0, sizeof(wlan_adapter));
911
912 priv->wlan_dev.netdev = dev;
913 priv->wlan_dev.card = card;
914 priv->mesh_open = 0; 793 priv->mesh_open = 0;
915 priv->infra_open = 0; 794 priv->infra_open = 0;
916 priv->mesh_dev = mesh_dev;
917 wlanpriv = priv;
918 795
919 SET_MODULE_OWNER(dev); 796 SET_MODULE_OWNER(dev);
920 SET_MODULE_OWNER(mesh_dev);
921 797
922 /* Setup the OS Interface to our functions */ 798 /* Setup the OS Interface to our functions */
923 dev->open = wlan_open; 799 dev->open = wlan_open;
@@ -925,116 +801,171 @@ wlan_private *wlan_add_card(void *card)
925 dev->stop = wlan_close; 801 dev->stop = wlan_close;
926 dev->do_ioctl = libertas_do_ioctl; 802 dev->do_ioctl = libertas_do_ioctl;
927 dev->set_mac_address = wlan_set_mac_address; 803 dev->set_mac_address = wlan_set_mac_address;
928 mesh_dev->open = mesh_open;
929 mesh_dev->hard_start_xmit = mesh_pre_start_xmit;
930 mesh_dev->stop = mesh_close;
931 mesh_dev->do_ioctl = libertas_do_ioctl;
932 memcpy(mesh_dev->dev_addr, wlanpriv->wlan_dev.netdev->dev_addr,
933 sizeof(wlanpriv->wlan_dev.netdev->dev_addr));
934
935#define WLAN_WATCHDOG_TIMEOUT (5 * HZ)
936
937 dev->tx_timeout = wlan_tx_timeout; 804 dev->tx_timeout = wlan_tx_timeout;
938 dev->get_stats = wlan_get_stats; 805 dev->get_stats = wlan_get_stats;
939 dev->watchdog_timeo = WLAN_WATCHDOG_TIMEOUT; 806 dev->watchdog_timeo = 5 * HZ;
940 dev->ethtool_ops = &libertas_ethtool_ops; 807 dev->ethtool_ops = &libertas_ethtool_ops;
941 mesh_dev->get_stats = wlan_get_stats;
942 mesh_dev->ethtool_ops = &libertas_ethtool_ops;
943
944#ifdef WIRELESS_EXT 808#ifdef WIRELESS_EXT
945 dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def; 809 dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def;
946 mesh_dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def;
947#endif 810#endif
948#define NETIF_F_DYNALLOC 16 811#define NETIF_F_DYNALLOC 16
949 dev->features |= NETIF_F_DYNALLOC; 812 dev->features |= NETIF_F_DYNALLOC;
950 dev->flags |= IFF_BROADCAST | IFF_MULTICAST; 813 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
951 dev->set_multicast_list = wlan_set_multicast_list; 814 dev->set_multicast_list = wlan_set_multicast_list;
952 815
816 SET_NETDEV_DEV(dev, dmdev);
817
953 INIT_LIST_HEAD(&priv->adapter->cmdfreeq); 818 INIT_LIST_HEAD(&priv->adapter->cmdfreeq);
954 INIT_LIST_HEAD(&priv->adapter->cmdpendingq); 819 INIT_LIST_HEAD(&priv->adapter->cmdpendingq);
955 820
956 spin_lock_init(&priv->adapter->driver_lock); 821 spin_lock_init(&priv->adapter->driver_lock);
957 init_waitqueue_head(&priv->adapter->cmd_pending); 822 init_waitqueue_head(&priv->adapter->cmd_pending);
958 priv->adapter->nr_cmd_pending = 0; 823 priv->adapter->nr_cmd_pending = 0;
824 goto done;
959 825
960 lbs_pr_debug(1, "Starting kthread...\n"); 826err_kzalloc:
827 free_netdev(dev);
828 priv = NULL;
829done:
830 lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv);
831 return priv;
832}
833EXPORT_SYMBOL_GPL(libertas_add_card);
834
835int libertas_activate_card(wlan_private *priv, char *fw_name)
836{
837 struct net_device *dev = priv->dev;
838 int ret = -1;
839
840 lbs_deb_enter(LBS_DEB_MAIN);
841
842 lbs_deb_thread("Starting kthread...\n");
961 priv->mainthread.priv = priv; 843 priv->mainthread.priv = priv;
962 wlan_create_thread(wlan_service_main_thread, 844 wlan_create_thread(wlan_service_main_thread,
963 &priv->mainthread, "wlan_main_service"); 845 &priv->mainthread, "wlan_main_service");
964 846
965 priv->assoc_thread = 847 priv->assoc_thread =
966 create_singlethread_workqueue("libertas_assoc"); 848 create_singlethread_workqueue("libertas_assoc");
967 INIT_DELAYED_WORK(&priv->assoc_work, wlan_association_worker); 849 INIT_DELAYED_WORK(&priv->assoc_work, libertas_association_worker);
968 850
969 /* 851 /*
970 * Register the device. Fillup the private data structure with 852 * Register the device. Fillup the private data structure with
971 * relevant information from the card and request for the required 853 * relevant information from the card and request for the required
972 * IRQ. 854 * IRQ.
973 */ 855 */
974 if (libertas_sbi_register_dev(priv) < 0) { 856 if (priv->hw_register_dev(priv) < 0) {
975 lbs_pr_info("failed to register wlan device!\n"); 857 lbs_pr_err("failed to register WLAN device\n");
976 goto err_registerdev; 858 goto err_registerdev;
977 } 859 }
978 860
979 /* init FW and HW */ 861 /* init FW and HW */
980 if (libertas_init_fw(priv)) { 862 if (fw_name && libertas_init_fw(priv, fw_name)) {
981 lbs_pr_debug(1, "Firmware Init failed\n"); 863 lbs_pr_err("firmware init failed\n");
982 goto err_registerdev; 864 goto err_registerdev;
983 } 865 }
984 866
985 if (register_netdev(dev)) { 867 if (register_netdev(dev)) {
986 lbs_pr_err("Cannot register network device!\n"); 868 lbs_pr_err("cannot register ethX device\n");
987 goto err_init_fw; 869 goto err_init_fw;
988 } 870 }
989 871
990 /* Register virtual mesh interface */ 872 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
991 if (register_netdev(mesh_dev)) {
992 lbs_pr_info("Cannot register mesh virtual interface!\n");
993 goto err_init_fw;
994 }
995
996 lbs_pr_info("%s: Marvell Wlan 802.11 adapter ", dev->name);
997 873
998 libertas_debugfs_init_one(priv, dev); 874 libertas_debugfs_init_one(priv, dev);
999 875
1000 if (libertas_found == MAX_DEVS) 876 ret = 0;
1001 goto err_init_fw; 877 goto done;
1002 libertas_devs[libertas_found] = dev;
1003 libertas_found++;
1004#ifdef ENABLE_PM
1005 if (!(wlan_pm_dev = pm_register(PM_UNKNOWN_DEV, 0, wlan_pm_callback)))
1006 lbs_pr_alert( "failed to register PM callback\n");
1007#endif
1008 if (device_create_file(&(mesh_dev->dev), &dev_attr_libertas_mpp))
1009 goto err_create_file;
1010 878
1011 LEAVE();
1012 return priv;
1013
1014err_create_file:
1015 device_remove_file(&(mesh_dev->dev), &dev_attr_libertas_mpp);
1016err_init_fw: 879err_init_fw:
1017 libertas_sbi_unregister_dev(priv); 880 priv->hw_unregister_dev(priv);
1018err_registerdev: 881err_registerdev:
1019 destroy_workqueue(priv->assoc_thread); 882 destroy_workqueue(priv->assoc_thread);
1020 /* Stop the thread servicing the interrupts */ 883 /* Stop the thread servicing the interrupts */
1021 wake_up_interruptible(&priv->mainthread.waitq); 884 wake_up_interruptible(&priv->mainthread.waitq);
1022 wlan_terminate_thread(&priv->mainthread); 885 wlan_terminate_thread(&priv->mainthread);
1023 kfree(priv->adapter); 886done:
1024err_kmalloc: 887 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
1025 free_netdev(dev); 888 return ret;
889}
890EXPORT_SYMBOL_GPL(libertas_activate_card);
891
892
893/**
894 * @brief This function adds mshX interface
895 *
896 * @param priv A pointer to the wlan_private structure
897 * @return 0 if successful, -X otherwise
898 */
899int libertas_add_mesh(wlan_private *priv, struct device *dev)
900{
901 struct net_device *mesh_dev = NULL;
902 int ret = 0;
903
904 lbs_deb_enter(LBS_DEB_MESH);
905
906 /* Allocate a virtual mesh device */
907 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
908 lbs_deb_mesh("init mshX device failed\n");
909 ret = -ENOMEM;
910 goto done;
911 }
912 mesh_dev->priv = priv;
913 priv->mesh_dev = mesh_dev;
914
915 SET_MODULE_OWNER(mesh_dev);
916
917 mesh_dev->open = mesh_open;
918 mesh_dev->hard_start_xmit = mesh_pre_start_xmit;
919 mesh_dev->stop = mesh_close;
920 mesh_dev->do_ioctl = libertas_do_ioctl;
921 mesh_dev->get_stats = wlan_get_stats;
922 mesh_dev->set_mac_address = wlan_set_mac_address;
923 mesh_dev->ethtool_ops = &libertas_ethtool_ops;
924 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
925 sizeof(priv->dev->dev_addr));
926
927 SET_NETDEV_DEV(priv->mesh_dev, dev);
928
929#ifdef WIRELESS_EXT
930 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
931#endif
932#define NETIF_F_DYNALLOC 16
933
934 /* Register virtual mesh interface */
935 ret = register_netdev(mesh_dev);
936 if (ret) {
937 lbs_pr_err("cannot register mshX virtual interface\n");
938 goto err_free;
939 }
940
941 ret = device_create_file(&(mesh_dev->dev), &dev_attr_libertas_mpp);
942 if (ret)
943 goto err_unregister;
944
945 /* Everything successful */
946 ret = 0;
947 goto done;
948
949
950err_unregister:
951 unregister_netdev(mesh_dev);
952
953err_free:
1026 free_netdev(mesh_dev); 954 free_netdev(mesh_dev);
1027 wlanpriv = NULL;
1028 955
1029 LEAVE(); 956done:
1030 return NULL; 957 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
958 return ret;
1031} 959}
960EXPORT_SYMBOL_GPL(libertas_add_mesh);
1032 961
1033static void wake_pending_cmdnodes(wlan_private *priv) 962static void wake_pending_cmdnodes(wlan_private *priv)
1034{ 963{
1035 struct cmd_ctrl_node *cmdnode; 964 struct cmd_ctrl_node *cmdnode;
1036 unsigned long flags; 965 unsigned long flags;
1037 966
967 lbs_deb_enter(LBS_DEB_CMD);
968
1038 spin_lock_irqsave(&priv->adapter->driver_lock, flags); 969 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
1039 list_for_each_entry(cmdnode, &priv->adapter->cmdpendingq, list) { 970 list_for_each_entry(cmdnode, &priv->adapter->cmdpendingq, list) {
1040 cmdnode->cmdwaitqwoken = 1; 971 cmdnode->cmdwaitqwoken = 1;
@@ -1044,40 +975,29 @@ static void wake_pending_cmdnodes(wlan_private *priv)
1044} 975}
1045 976
1046 977
1047int wlan_remove_card(void *card) 978int libertas_remove_card(wlan_private *priv)
1048{ 979{
1049 wlan_private *priv = libertas_sbi_get_priv(card);
1050 wlan_adapter *adapter; 980 wlan_adapter *adapter;
1051 struct net_device *dev; 981 struct net_device *dev;
1052 struct net_device *mesh_dev;
1053 union iwreq_data wrqu; 982 union iwreq_data wrqu;
1054 int i;
1055 983
1056 ENTER(); 984 lbs_deb_enter(LBS_DEB_NET);
1057 985
1058 if (!priv) { 986 if (!priv)
1059 LEAVE(); 987 goto out;
1060 return 0;
1061 }
1062 988
1063 adapter = priv->adapter; 989 adapter = priv->adapter;
1064 990
1065 if (!adapter) { 991 if (!adapter)
1066 LEAVE(); 992 goto out;
1067 return 0;
1068 }
1069 993
1070 dev = priv->wlan_dev.netdev; 994 dev = priv->dev;
1071 mesh_dev = priv->mesh_dev;
1072 995
1073 netif_stop_queue(mesh_dev); 996 netif_stop_queue(priv->dev);
1074 netif_stop_queue(priv->wlan_dev.netdev); 997 netif_carrier_off(priv->dev);
1075 netif_carrier_off(priv->wlan_dev.netdev);
1076 998
1077 wake_pending_cmdnodes(priv); 999 wake_pending_cmdnodes(priv);
1078 1000
1079 device_remove_file(&(mesh_dev->dev), &dev_attr_libertas_mpp);
1080 unregister_netdev(mesh_dev);
1081 unregister_netdev(dev); 1001 unregister_netdev(dev);
1082 1002
1083 cancel_delayed_work(&priv->assoc_work); 1003 cancel_delayed_work(&priv->assoc_work);
@@ -1090,11 +1010,7 @@ int wlan_remove_card(void *card)
1090 1010
1091 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN); 1011 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
1092 wrqu.ap_addr.sa_family = ARPHRD_ETHER; 1012 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1093 wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL); 1013 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
1094
1095#ifdef ENABLE_PM
1096 pm_unregister(wlan_pm_dev);
1097#endif
1098 1014
1099 adapter->surpriseremoved = 1; 1015 adapter->surpriseremoved = 1;
1100 1016
@@ -1103,28 +1019,45 @@ int wlan_remove_card(void *card)
1103 1019
1104 libertas_debugfs_remove_one(priv); 1020 libertas_debugfs_remove_one(priv);
1105 1021
1106 lbs_pr_debug(1, "Free adapter\n"); 1022 lbs_deb_net("free adapter\n");
1107 libertas_free_adapter(priv); 1023 libertas_free_adapter(priv);
1108 1024
1109 for (i = 0; i<libertas_found; i++) { 1025 lbs_deb_net("unregister finish\n");
1110 if (libertas_devs[i]==priv->wlan_dev.netdev) {
1111 libertas_devs[i] = libertas_devs[--libertas_found];
1112 libertas_devs[libertas_found] = NULL ;
1113 break ;
1114 }
1115 }
1116 1026
1117 lbs_pr_debug(1, "Unregister finish\n"); 1027 priv->dev = NULL;
1028 free_netdev(dev);
1029
1030out:
1031 lbs_deb_leave(LBS_DEB_NET);
1032 return 0;
1033}
1034EXPORT_SYMBOL_GPL(libertas_remove_card);
1035
1036
1037void libertas_remove_mesh(wlan_private *priv)
1038{
1039 struct net_device *mesh_dev;
1040
1041 lbs_deb_enter(LBS_DEB_NET);
1042
1043 if (!priv)
1044 goto out;
1045
1046 mesh_dev = priv->mesh_dev;
1047
1048 netif_stop_queue(mesh_dev);
1049 netif_carrier_off(priv->mesh_dev);
1050
1051 device_remove_file(&(mesh_dev->dev), &dev_attr_libertas_mpp);
1052 unregister_netdev(mesh_dev);
1118 1053
1119 priv->wlan_dev.netdev = NULL;
1120 priv->mesh_dev = NULL ; 1054 priv->mesh_dev = NULL ;
1121 free_netdev(mesh_dev); 1055 free_netdev(mesh_dev);
1122 free_netdev(dev);
1123 wlanpriv = NULL;
1124 1056
1125 LEAVE(); 1057out:
1126 return 0; 1058 lbs_deb_leave(LBS_DEB_NET);
1127} 1059}
1060EXPORT_SYMBOL_GPL(libertas_remove_mesh);
1128 1061
1129/** 1062/**
1130 * @brief This function finds the CFP in 1063 * @brief This function finds the CFP in
@@ -1139,33 +1072,34 @@ struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band, int *c
1139{ 1072{
1140 int i, end; 1073 int i, end;
1141 1074
1142 ENTER(); 1075 lbs_deb_enter(LBS_DEB_MAIN);
1143 1076
1144 end = sizeof(region_cfp_table)/sizeof(struct region_cfp_table); 1077 end = sizeof(region_cfp_table)/sizeof(struct region_cfp_table);
1145 1078
1146 for (i = 0; i < end ; i++) { 1079 for (i = 0; i < end ; i++) {
1147 lbs_pr_debug(1, "region_cfp_table[i].region=%d\n", 1080 lbs_deb_main("region_cfp_table[i].region=%d\n",
1148 region_cfp_table[i].region); 1081 region_cfp_table[i].region);
1149 if (region_cfp_table[i].region == region) { 1082 if (region_cfp_table[i].region == region) {
1150 *cfp_no = region_cfp_table[i].cfp_no_BG; 1083 *cfp_no = region_cfp_table[i].cfp_no_BG;
1151 LEAVE(); 1084 lbs_deb_leave(LBS_DEB_MAIN);
1152 return region_cfp_table[i].cfp_BG; 1085 return region_cfp_table[i].cfp_BG;
1153 } 1086 }
1154 } 1087 }
1155 1088
1156 LEAVE(); 1089 lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
1157 return NULL; 1090 return NULL;
1158} 1091}
1159 1092
1160int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band) 1093int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band)
1161{ 1094{
1162 wlan_adapter *adapter = priv->adapter; 1095 wlan_adapter *adapter = priv->adapter;
1096 int ret = 0;
1163 int i = 0; 1097 int i = 0;
1164 1098
1165 struct chan_freq_power *cfp; 1099 struct chan_freq_power *cfp;
1166 int cfp_no; 1100 int cfp_no;
1167 1101
1168 ENTER(); 1102 lbs_deb_enter(LBS_DEB_MAIN);
1169 1103
1170 memset(adapter->region_channel, 0, sizeof(adapter->region_channel)); 1104 memset(adapter->region_channel, 0, sizeof(adapter->region_channel));
1171 1105
@@ -1175,17 +1109,19 @@ int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band)
1175 adapter->region_channel[i].nrcfp = cfp_no; 1109 adapter->region_channel[i].nrcfp = cfp_no;
1176 adapter->region_channel[i].CFP = cfp; 1110 adapter->region_channel[i].CFP = cfp;
1177 } else { 1111 } else {
1178 lbs_pr_debug(1, "wrong region code %#x in band B-G\n", 1112 lbs_deb_main("wrong region code %#x in band B/G\n",
1179 region); 1113 region);
1180 return -1; 1114 ret = -1;
1115 goto out;
1181 } 1116 }
1182 adapter->region_channel[i].valid = 1; 1117 adapter->region_channel[i].valid = 1;
1183 adapter->region_channel[i].region = region; 1118 adapter->region_channel[i].region = region;
1184 adapter->region_channel[i].band = band; 1119 adapter->region_channel[i].band = band;
1185 i++; 1120 i++;
1186 } 1121 }
1187 LEAVE(); 1122out:
1188 return 0; 1123 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1124 return ret;
1189} 1125}
1190 1126
1191/** 1127/**
@@ -1200,9 +1136,9 @@ void libertas_interrupt(struct net_device *dev)
1200{ 1136{
1201 wlan_private *priv = dev->priv; 1137 wlan_private *priv = dev->priv;
1202 1138
1203 ENTER(); 1139 lbs_deb_enter(LBS_DEB_THREAD);
1204 1140
1205 lbs_pr_debug(1, "libertas_interrupt: intcounter=%d\n", 1141 lbs_deb_thread("libertas_interrupt: intcounter=%d\n",
1206 priv->adapter->intcounter); 1142 priv->adapter->intcounter);
1207 1143
1208 priv->adapter->intcounter++; 1144 priv->adapter->intcounter++;
@@ -1210,56 +1146,35 @@ void libertas_interrupt(struct net_device *dev)
1210 if (priv->adapter->psstate == PS_STATE_SLEEP) { 1146 if (priv->adapter->psstate == PS_STATE_SLEEP) {
1211 priv->adapter->psstate = PS_STATE_AWAKE; 1147 priv->adapter->psstate = PS_STATE_AWAKE;
1212 netif_wake_queue(dev); 1148 netif_wake_queue(dev);
1149 netif_wake_queue(priv->mesh_dev);
1213 } 1150 }
1214 1151
1215 wake_up_interruptible(&priv->mainthread.waitq); 1152 wake_up_interruptible(&priv->mainthread.waitq);
1216 1153
1217 LEAVE(); 1154 lbs_deb_leave(LBS_DEB_THREAD);
1218} 1155}
1156EXPORT_SYMBOL_GPL(libertas_interrupt);
1219 1157
1220static int wlan_init_module(void) 1158static int libertas_init_module(void)
1221{ 1159{
1222 int ret = 0; 1160 lbs_deb_enter(LBS_DEB_MAIN);
1223
1224 ENTER();
1225
1226 if (libertas_fw_name == NULL) {
1227 libertas_fw_name = default_fw_name;
1228 }
1229
1230 libertas_debugfs_init(); 1161 libertas_debugfs_init();
1231 1162 lbs_deb_leave(LBS_DEB_MAIN);
1232 if (libertas_sbi_register()) { 1163 return 0;
1233 ret = -1;
1234 libertas_debugfs_remove();
1235 goto done;
1236 }
1237
1238done:
1239 LEAVE();
1240 return ret;
1241} 1164}
1242 1165
1243static void wlan_cleanup_module(void) 1166static void libertas_exit_module(void)
1244{ 1167{
1245 int i; 1168 lbs_deb_enter(LBS_DEB_MAIN);
1246
1247 ENTER();
1248
1249 for (i = 0; i<libertas_found; i++) {
1250 wlan_private *priv = libertas_devs[i]->priv;
1251 reset_device(priv);
1252 }
1253 1169
1254 libertas_sbi_unregister();
1255 libertas_debugfs_remove(); 1170 libertas_debugfs_remove();
1256 1171
1257 LEAVE(); 1172 lbs_deb_leave(LBS_DEB_MAIN);
1258} 1173}
1259 1174
1260module_init(wlan_init_module); 1175module_init(libertas_init_module);
1261module_exit(wlan_cleanup_module); 1176module_exit(libertas_exit_module);
1262 1177
1263MODULE_DESCRIPTION("M-WLAN Driver"); 1178MODULE_DESCRIPTION("Libertas WLAN Driver Library");
1264MODULE_AUTHOR("Marvell International Ltd."); 1179MODULE_AUTHOR("Marvell International Ltd.");
1265MODULE_LICENSE("GPL"); 1180MODULE_LICENSE("GPL");