2 * This file contains the major functions in WLAN
3 * driver. It includes init, exit, open, close and main
7 #include <linux/delay.h>
8 #include <linux/freezer.h>
9 #include <linux/etherdevice.h>
10 #include <linux/netdevice.h>
11 #include <linux/if_arp.h>
13 #include <net/iw_handler.h>
24 #define DRIVER_RELEASE_VERSION "320.p0"
25 const char libertas_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
31 #define WLAN_TX_PWR_DEFAULT 20 /*100mW */
32 #define WLAN_TX_PWR_US_DEFAULT 20 /*100mW */
33 #define WLAN_TX_PWR_JP_DEFAULT 16 /*50mW */
34 #define WLAN_TX_PWR_FR_DEFAULT 20 /*100mW */
35 #define WLAN_TX_PWR_EMEA_DEFAULT 20 /*100mW */
37 /* Format { channel, frequency (MHz), maxtxpower } */
38 /* band: 'B/G', region: USA FCC/Canada IC */
39 static struct chan_freq_power channel_freq_power_US_BG[] = {
40 {1, 2412, WLAN_TX_PWR_US_DEFAULT},
41 {2, 2417, WLAN_TX_PWR_US_DEFAULT},
42 {3, 2422, WLAN_TX_PWR_US_DEFAULT},
43 {4, 2427, WLAN_TX_PWR_US_DEFAULT},
44 {5, 2432, WLAN_TX_PWR_US_DEFAULT},
45 {6, 2437, WLAN_TX_PWR_US_DEFAULT},
46 {7, 2442, WLAN_TX_PWR_US_DEFAULT},
47 {8, 2447, WLAN_TX_PWR_US_DEFAULT},
48 {9, 2452, WLAN_TX_PWR_US_DEFAULT},
49 {10, 2457, WLAN_TX_PWR_US_DEFAULT},
50 {11, 2462, WLAN_TX_PWR_US_DEFAULT}
53 /* band: 'B/G', region: Europe ETSI */
54 static struct chan_freq_power channel_freq_power_EU_BG[] = {
55 {1, 2412, WLAN_TX_PWR_EMEA_DEFAULT},
56 {2, 2417, WLAN_TX_PWR_EMEA_DEFAULT},
57 {3, 2422, WLAN_TX_PWR_EMEA_DEFAULT},
58 {4, 2427, WLAN_TX_PWR_EMEA_DEFAULT},
59 {5, 2432, WLAN_TX_PWR_EMEA_DEFAULT},
60 {6, 2437, WLAN_TX_PWR_EMEA_DEFAULT},
61 {7, 2442, WLAN_TX_PWR_EMEA_DEFAULT},
62 {8, 2447, WLAN_TX_PWR_EMEA_DEFAULT},
63 {9, 2452, WLAN_TX_PWR_EMEA_DEFAULT},
64 {10, 2457, WLAN_TX_PWR_EMEA_DEFAULT},
65 {11, 2462, WLAN_TX_PWR_EMEA_DEFAULT},
66 {12, 2467, WLAN_TX_PWR_EMEA_DEFAULT},
67 {13, 2472, WLAN_TX_PWR_EMEA_DEFAULT}
70 /* band: 'B/G', region: Spain */
71 static struct chan_freq_power channel_freq_power_SPN_BG[] = {
72 {10, 2457, WLAN_TX_PWR_DEFAULT},
73 {11, 2462, WLAN_TX_PWR_DEFAULT}
76 /* band: 'B/G', region: France */
77 static struct chan_freq_power channel_freq_power_FR_BG[] = {
78 {10, 2457, WLAN_TX_PWR_FR_DEFAULT},
79 {11, 2462, WLAN_TX_PWR_FR_DEFAULT},
80 {12, 2467, WLAN_TX_PWR_FR_DEFAULT},
81 {13, 2472, WLAN_TX_PWR_FR_DEFAULT}
84 /* band: 'B/G', region: Japan */
85 static struct chan_freq_power channel_freq_power_JPN_BG[] = {
86 {1, 2412, WLAN_TX_PWR_JP_DEFAULT},
87 {2, 2417, WLAN_TX_PWR_JP_DEFAULT},
88 {3, 2422, WLAN_TX_PWR_JP_DEFAULT},
89 {4, 2427, WLAN_TX_PWR_JP_DEFAULT},
90 {5, 2432, WLAN_TX_PWR_JP_DEFAULT},
91 {6, 2437, WLAN_TX_PWR_JP_DEFAULT},
92 {7, 2442, WLAN_TX_PWR_JP_DEFAULT},
93 {8, 2447, WLAN_TX_PWR_JP_DEFAULT},
94 {9, 2452, WLAN_TX_PWR_JP_DEFAULT},
95 {10, 2457, WLAN_TX_PWR_JP_DEFAULT},
96 {11, 2462, WLAN_TX_PWR_JP_DEFAULT},
97 {12, 2467, WLAN_TX_PWR_JP_DEFAULT},
98 {13, 2472, WLAN_TX_PWR_JP_DEFAULT},
99 {14, 2484, WLAN_TX_PWR_JP_DEFAULT}
103 * the structure for channel, frequency and power
105 struct region_cfp_table {
107 struct chan_freq_power *cfp_BG;
112 * the structure for the mapping between region and CFP
114 static struct region_cfp_table region_cfp_table[] = {
116 channel_freq_power_US_BG,
117 sizeof(channel_freq_power_US_BG) / sizeof(struct chan_freq_power),
120 {0x20, /*CANADA IC */
121 channel_freq_power_US_BG,
122 sizeof(channel_freq_power_US_BG) / sizeof(struct chan_freq_power),
125 {0x30, /*EU*/ channel_freq_power_EU_BG,
126 sizeof(channel_freq_power_EU_BG) / sizeof(struct chan_freq_power),
129 {0x31, /*SPAIN*/ channel_freq_power_SPN_BG,
130 sizeof(channel_freq_power_SPN_BG) / sizeof(struct chan_freq_power),
133 {0x32, /*FRANCE*/ channel_freq_power_FR_BG,
134 sizeof(channel_freq_power_FR_BG) / sizeof(struct chan_freq_power),
137 {0x40, /*JAPAN*/ channel_freq_power_JPN_BG,
138 sizeof(channel_freq_power_JPN_BG) / sizeof(struct chan_freq_power),
141 /*Add new region here */
145 * the rates supported by the card
147 u8 libertas_wlan_data_rates[WLAN_SUPPORTED_RATES] =
148 { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
149 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
153 * the rates supported
155 u8 libertas_supported_rates[G_SUPPORTED_RATES] =
156 { 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
160 * the rates supported for ad-hoc G mode
162 u8 libertas_adhoc_rates_g[G_SUPPORTED_RATES] =
163 { 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
167 * the rates supported for ad-hoc B mode
169 u8 libertas_adhoc_rates_b[4] = { 0x82, 0x84, 0x8b, 0x96 };
172 static struct net_device *libertas_devs[MAX_DEVS];
173 static int libertas_found = 0;
176 * the table to keep region code
178 u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
179 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
181 static u8 *default_fw_name = "usb8388.bin";
184 * Attributes exported through sysfs
188 * @brief Get function for sysfs attribute libertas_mpp
190 static ssize_t libertas_mpp_get(struct device * dev,
191 struct device_attribute *attr, char * buf) {
192 struct cmd_ds_mesh_access mesh_access;
194 memset(&mesh_access, 0, sizeof(mesh_access));
195 libertas_prepare_and_send_command(to_net_dev(dev)->priv,
197 cmd_act_mesh_get_mpp,
198 cmd_option_waitforrsp, 0, (void *)&mesh_access);
200 return snprintf(buf, 3, "%d\n", mesh_access.data[0]);
204 * @brief Set function for sysfs attribute libertas_mpp
206 static ssize_t libertas_mpp_set(struct device * dev,
207 struct device_attribute *attr, const char * buf, size_t count) {
208 struct cmd_ds_mesh_access mesh_access;
211 memset(&mesh_access, 0, sizeof(mesh_access));
212 sscanf(buf, "%d", &(mesh_access.data[0]));
213 libertas_prepare_and_send_command((to_net_dev(dev))->priv,
215 cmd_act_mesh_set_mpp,
216 cmd_option_waitforrsp, 0, (void *)&mesh_access);
221 * libertas_mpp attribute to be exported per mshX interface
222 * through sysfs (/sys/class/net/mshX/libertas-mpp)
224 static DEVICE_ATTR(libertas_mpp, 0644, libertas_mpp_get,
228 * @brief Check if the device can be open and wait if necessary.
230 * @param dev A pointer to net_device structure
233 * For USB adapter, on some systems the device open handler will be
234 * called before FW ready. Use the following flag check and wait
235 * function to work around the issue.
238 static int pre_open_check(struct net_device *dev) {
239 wlan_private *priv = (wlan_private *) dev->priv;
240 wlan_adapter *adapter = priv->adapter;
243 while (!adapter->fw_ready && i < 20) {
245 msleep_interruptible(100);
247 if (!adapter->fw_ready) {
248 lbs_pr_info("FW not ready, pre_open_check() return failure\n");
257 * @brief This function opens the device
259 * @param dev A pointer to net_device structure
262 static int wlan_dev_open(struct net_device *dev)
264 wlan_private *priv = (wlan_private *) dev->priv;
265 wlan_adapter *adapter = priv->adapter;
272 if (adapter->connect_status == libertas_connected) {
273 netif_carrier_on(priv->wlan_dev.netdev);
275 netif_carrier_off(priv->wlan_dev.netdev);
281 * @brief This function opens the mshX interface
283 * @param dev A pointer to net_device structure
286 static int mesh_open(struct net_device *dev)
288 wlan_private *priv = (wlan_private *) dev->priv ;
290 if(pre_open_check(dev) == -1)
292 priv->mesh_open = 1 ;
293 netif_start_queue(priv->mesh_dev);
294 if (priv->infra_open == 0)
295 return wlan_dev_open(priv->wlan_dev.netdev) ;
300 * @brief This function opens the ethX interface
302 * @param dev A pointer to net_device structure
305 static int wlan_open(struct net_device *dev)
307 wlan_private *priv = (wlan_private *) dev->priv ;
309 if(pre_open_check(dev) == -1)
311 priv->infra_open = 1 ;
312 netif_wake_queue(priv->wlan_dev.netdev);
314 return wlan_dev_open(priv->wlan_dev.netdev) ;
318 static int wlan_dev_close(struct net_device *dev)
320 wlan_private *priv = dev->priv;
324 netif_carrier_off(priv->wlan_dev.netdev);
332 * @brief This function closes the mshX interface
334 * @param dev A pointer to net_device structure
337 static int mesh_close(struct net_device *dev)
339 wlan_private *priv = (wlan_private *) (dev->priv);
342 netif_stop_queue(priv->mesh_dev);
343 if (priv->infra_open == 0)
344 return wlan_dev_close( ((wlan_private *) dev->priv)->wlan_dev.netdev) ;
350 * @brief This function closes the ethX interface
352 * @param dev A pointer to net_device structure
355 static int wlan_close(struct net_device *dev) {
356 wlan_private *priv = (wlan_private *) dev->priv;
358 netif_stop_queue(priv->wlan_dev.netdev);
359 priv->infra_open = 0;
360 if (priv->mesh_open == 0)
361 return wlan_dev_close( ((wlan_private *) dev->priv)->wlan_dev.netdev) ;
367 static int wlan_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
370 wlan_private *priv = dev->priv;
374 if (priv->wlan_dev.dnld_sent || priv->adapter->TxLockFlag) {
375 priv->stats.tx_dropped++;
379 netif_stop_queue(priv->wlan_dev.netdev);
381 if (libertas_process_tx(priv, skb) == 0)
382 dev->trans_start = jiffies;
389 * @brief Mark mesh packets and handover them to wlan_hard_start_xmit
392 static int mesh_pre_start_xmit(struct sk_buff *skb, struct net_device *dev)
394 wlan_private *priv = dev->priv;
399 return wlan_hard_start_xmit(skb, priv->wlan_dev.netdev);
403 * @brief Mark non-mesh packets and handover them to wlan_hard_start_xmit
406 static int wlan_pre_start_xmit(struct sk_buff *skb, struct net_device *dev) {
408 UNSET_MESH_FRAME(skb);
410 return wlan_hard_start_xmit(skb, dev);
413 static void wlan_tx_timeout(struct net_device *dev)
415 wlan_private *priv = (wlan_private *) dev->priv;
419 lbs_pr_err("tx watch dog timeout!\n");
421 priv->wlan_dev.dnld_sent = DNLD_RES_RECEIVED;
422 dev->trans_start = jiffies;
424 if (priv->adapter->currenttxskb) {
425 if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
426 /* If we are here, we have not received feedback from
427 the previous packet. Assume TX_FAIL and move on. */
428 priv->adapter->eventcause = 0x01000000;
429 libertas_send_tx_feedback(priv);
431 wake_up_interruptible(&priv->mainthread.waitq);
432 } else if (priv->adapter->connect_status == libertas_connected)
433 netif_wake_queue(priv->wlan_dev.netdev);
439 * @brief This function returns the network statistics
441 * @param dev A pointer to wlan_private structure
442 * @return A pointer to net_device_stats structure
444 static struct net_device_stats *wlan_get_stats(struct net_device *dev)
446 wlan_private *priv = (wlan_private *) dev->priv;
451 static int wlan_set_mac_address(struct net_device *dev, void *addr)
454 wlan_private *priv = (wlan_private *) dev->priv;
455 wlan_adapter *adapter = priv->adapter;
456 struct sockaddr *phwaddr = addr;
460 memset(adapter->current_addr, 0, ETH_ALEN);
462 /* dev->dev_addr is 8 bytes */
463 lbs_dbg_hex("dev->dev_addr:", dev->dev_addr, ETH_ALEN);
465 lbs_dbg_hex("addr:", phwaddr->sa_data, ETH_ALEN);
466 memcpy(adapter->current_addr, phwaddr->sa_data, ETH_ALEN);
468 ret = libertas_prepare_and_send_command(priv, cmd_802_11_mac_address,
470 cmd_option_waitforrsp, 0, NULL);
473 lbs_pr_debug(1, "set mac address failed.\n");
478 lbs_dbg_hex("adapter->macaddr:", adapter->current_addr, ETH_ALEN);
479 memcpy(dev->dev_addr, adapter->current_addr, ETH_ALEN);
480 memcpy(((wlan_private *) dev->priv)->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
487 static int wlan_copy_multicast_address(wlan_adapter * adapter,
488 struct net_device *dev)
491 struct dev_mc_list *mcptr = dev->mc_list;
493 for (i = 0; i < dev->mc_count; i++) {
494 memcpy(&adapter->multicastlist[i], mcptr->dmi_addr, ETH_ALEN);
502 static void wlan_set_multicast_list(struct net_device *dev)
504 wlan_private *priv = dev->priv;
505 wlan_adapter *adapter = priv->adapter;
510 oldpacketfilter = adapter->currentpacketfilter;
512 if (dev->flags & IFF_PROMISC) {
513 lbs_pr_debug(1, "enable Promiscuous mode\n");
514 adapter->currentpacketfilter |=
515 cmd_act_mac_promiscuous_enable;
516 adapter->currentpacketfilter &=
517 ~(cmd_act_mac_all_multicast_enable |
518 cmd_act_mac_multicast_enable);
521 adapter->currentpacketfilter &=
522 ~cmd_act_mac_promiscuous_enable;
524 if (dev->flags & IFF_ALLMULTI || dev->mc_count >
525 MRVDRV_MAX_MULTICAST_LIST_SIZE) {
526 lbs_pr_debug(1, "Enabling All Multicast!\n");
527 adapter->currentpacketfilter |=
528 cmd_act_mac_all_multicast_enable;
529 adapter->currentpacketfilter &=
530 ~cmd_act_mac_multicast_enable;
532 adapter->currentpacketfilter &=
533 ~cmd_act_mac_all_multicast_enable;
535 if (!dev->mc_count) {
536 lbs_pr_debug(1, "No multicast addresses - "
537 "disabling multicast!\n");
538 adapter->currentpacketfilter &=
539 ~cmd_act_mac_multicast_enable;
543 adapter->currentpacketfilter |=
544 cmd_act_mac_multicast_enable;
546 adapter->nr_of_multicastmacaddr =
547 wlan_copy_multicast_address(adapter, dev);
549 lbs_pr_debug(1, "Multicast addresses: %d\n",
552 for (i = 0; i < dev->mc_count; i++) {
553 lbs_pr_debug(1, "Multicast address %d:"
554 "%x %x %x %x %x %x\n", i,
555 adapter->multicastlist[i][0],
556 adapter->multicastlist[i][1],
557 adapter->multicastlist[i][2],
558 adapter->multicastlist[i][3],
559 adapter->multicastlist[i][4],
560 adapter->multicastlist[i][5]);
562 /* set multicast addresses to firmware */
563 libertas_prepare_and_send_command(priv,
564 cmd_mac_multicast_adr,
571 if (adapter->currentpacketfilter != oldpacketfilter) {
572 libertas_set_mac_packet_filter(priv);
579 * @brief This function hanldes the major job in WLAN driver.
580 * it handles the event generated by firmware, rx data received
581 * from firmware and tx data sent from kernel.
583 * @param data A pointer to wlan_thread structure
586 static int wlan_service_main_thread(void *data)
588 struct wlan_thread *thread = data;
589 wlan_private *priv = thread->priv;
590 wlan_adapter *adapter = priv->adapter;
596 wlan_activate_thread(thread);
598 init_waitqueue_entry(&wait, current);
601 lbs_pr_debug(1, "main-thread 111: intcounter=%d "
602 "currenttxskb=%p dnld_sent=%d\n",
604 adapter->currenttxskb, priv->wlan_dev.dnld_sent);
606 add_wait_queue(&thread->waitq, &wait);
607 set_current_state(TASK_INTERRUPTIBLE);
608 spin_lock_irq(&adapter->driver_lock);
609 if ((adapter->psstate == PS_STATE_SLEEP) ||
610 (!adapter->intcounter
611 && (priv->wlan_dev.dnld_sent || adapter->cur_cmd ||
612 list_empty(&adapter->cmdpendingq)))) {
614 "main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
615 adapter->connect_status, adapter->intcounter,
616 adapter->psmode, adapter->psstate);
617 spin_unlock_irq(&adapter->driver_lock);
620 spin_unlock_irq(&adapter->driver_lock);
624 "main-thread 222 (waking up): intcounter=%d currenttxskb=%p "
625 "dnld_sent=%d\n", adapter->intcounter,
626 adapter->currenttxskb, priv->wlan_dev.dnld_sent);
628 set_current_state(TASK_RUNNING);
629 remove_wait_queue(&thread->waitq, &wait);
632 lbs_pr_debug(1, "main-thread 333: intcounter=%d currenttxskb=%p "
635 adapter->currenttxskb, priv->wlan_dev.dnld_sent);
637 if (kthread_should_stop()
638 || adapter->surpriseremoved) {
640 "main-thread: break from main thread: surpriseremoved=0x%x\n",
641 adapter->surpriseremoved);
646 spin_lock_irq(&adapter->driver_lock);
647 if (adapter->intcounter) {
649 adapter->intcounter = 0;
650 int_status = libertas_sbi_get_int_status(priv, &ireg);
654 "main-thread: reading HOST_INT_STATUS_REG failed\n");
655 spin_unlock_irq(&adapter->driver_lock);
658 adapter->hisregcpy |= ireg;
661 lbs_pr_debug(1, "main-thread 444: intcounter=%d currenttxskb=%p "
664 adapter->currenttxskb, priv->wlan_dev.dnld_sent);
666 /* command response? */
667 if (adapter->hisregcpy & his_cmdupldrdy) {
668 lbs_pr_debug(1, "main-thread: cmd response ready.\n");
670 adapter->hisregcpy &= ~his_cmdupldrdy;
671 spin_unlock_irq(&adapter->driver_lock);
672 libertas_process_rx_command(priv);
673 spin_lock_irq(&adapter->driver_lock);
677 if (adapter->hisregcpy & his_cardevent) {
678 lbs_pr_debug(1, "main-thread: Card Event Activity.\n");
680 adapter->hisregcpy &= ~his_cardevent;
682 if (libertas_sbi_read_event_cause(priv)) {
684 "main-thread: libertas_sbi_read_event_cause failed.\n");
685 spin_unlock_irq(&adapter->driver_lock);
688 spin_unlock_irq(&adapter->driver_lock);
689 libertas_process_event(priv);
691 spin_unlock_irq(&adapter->driver_lock);
693 /* Check if we need to confirm Sleep Request received previously */
694 if (adapter->psstate == PS_STATE_PRE_SLEEP) {
695 if (!priv->wlan_dev.dnld_sent && !adapter->cur_cmd) {
696 if (adapter->connect_status ==
697 libertas_connected) {
699 "main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p "
700 "dnld_sent=%d cur_cmd=%p, confirm now\n",
702 adapter->currenttxskb,
703 priv->wlan_dev.dnld_sent,
706 libertas_ps_confirm_sleep(priv,
707 (u16) adapter->psmode);
709 /* workaround for firmware sending
710 * deauth/linkloss event immediately
711 * after sleep request, remove this
712 * after firmware fixes it
714 adapter->psstate = PS_STATE_AWAKE;
716 "main-thread: ignore PS_SleepConfirm in non-connected state\n");
721 /* The PS state is changed during processing of Sleep Request
724 if ((priv->adapter->psstate == PS_STATE_SLEEP) ||
725 (priv->adapter->psstate == PS_STATE_PRE_SLEEP))
728 /* Execute the next command */
729 if (!priv->wlan_dev.dnld_sent && !priv->adapter->cur_cmd)
730 libertas_execute_next_command(priv);
732 /* Wake-up command waiters which can't sleep in
733 * libertas_prepare_and_send_command
735 if (!adapter->nr_cmd_pending)
736 wake_up_all(&adapter->cmd_pending);
738 libertas_tx_runqueue(priv);
741 del_timer(&adapter->command_timer);
742 adapter->nr_cmd_pending = 0;
743 wake_up_all(&adapter->cmd_pending);
744 wlan_deactivate_thread(thread);
751 * @brief This function adds the card. it will probe the
752 * card, allocate the wlan_priv and initialize the device.
754 * @param card A pointer to card
755 * @return A pointer to wlan_private structure
757 wlan_private *wlan_add_card(void *card)
759 struct net_device *dev = NULL;
760 struct net_device *mesh_dev = NULL;
761 wlan_private *priv = NULL;
765 /* Allocate an Ethernet device and register it */
766 if (!(dev = alloc_etherdev(sizeof(wlan_private)))) {
767 lbs_pr_alert( "Init ethernet device failed!\n");
773 /* allocate buffer for wlan_adapter */
774 if (!(priv->adapter = kmalloc(sizeof(wlan_adapter), GFP_KERNEL))) {
775 lbs_pr_alert( "Allocate buffer for wlan_adapter failed!\n");
779 /* Allocate a virtual mesh device */
780 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
781 lbs_pr_debug(1, "Init ethernet device failed!\n");
785 /* Both intervaces share the priv structure */
786 mesh_dev->priv = priv;
788 /* init wlan_adapter */
789 memset(priv->adapter, 0, sizeof(wlan_adapter));
791 priv->wlan_dev.netdev = dev;
792 priv->wlan_dev.card = card;
794 priv->infra_open = 0;
795 priv->mesh_dev = mesh_dev;
797 SET_MODULE_OWNER(dev);
798 SET_MODULE_OWNER(mesh_dev);
800 /* Setup the OS Interface to our functions */
801 dev->open = wlan_open;
802 dev->hard_start_xmit = wlan_pre_start_xmit;
803 dev->stop = wlan_close;
804 dev->do_ioctl = libertas_do_ioctl;
805 dev->set_mac_address = wlan_set_mac_address;
806 mesh_dev->open = mesh_open;
807 mesh_dev->hard_start_xmit = mesh_pre_start_xmit;
808 mesh_dev->stop = mesh_close;
809 mesh_dev->do_ioctl = libertas_do_ioctl;
810 memcpy(mesh_dev->dev_addr, priv->wlan_dev.netdev->dev_addr,
811 sizeof(priv->wlan_dev.netdev->dev_addr));
813 #define WLAN_WATCHDOG_TIMEOUT (5 * HZ)
815 dev->tx_timeout = wlan_tx_timeout;
816 dev->get_stats = wlan_get_stats;
817 dev->watchdog_timeo = WLAN_WATCHDOG_TIMEOUT;
818 dev->ethtool_ops = &libertas_ethtool_ops;
819 mesh_dev->get_stats = wlan_get_stats;
820 mesh_dev->ethtool_ops = &libertas_ethtool_ops;
823 dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def;
824 mesh_dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def;
826 #define NETIF_F_DYNALLOC 16
827 dev->features |= NETIF_F_DYNALLOC;
828 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
829 dev->set_multicast_list = wlan_set_multicast_list;
831 INIT_LIST_HEAD(&priv->adapter->cmdfreeq);
832 INIT_LIST_HEAD(&priv->adapter->cmdpendingq);
834 spin_lock_init(&priv->adapter->driver_lock);
835 init_waitqueue_head(&priv->adapter->cmd_pending);
836 priv->adapter->nr_cmd_pending = 0;
838 lbs_pr_debug(1, "Starting kthread...\n");
839 priv->mainthread.priv = priv;
840 wlan_create_thread(wlan_service_main_thread,
841 &priv->mainthread, "wlan_main_service");
844 create_singlethread_workqueue("libertas_assoc");
845 INIT_DELAYED_WORK(&priv->assoc_work, libertas_association_worker);
848 * Register the device. Fillup the private data structure with
849 * relevant information from the card and request for the required
852 if (libertas_sbi_register_dev(priv) < 0) {
853 lbs_pr_info("failed to register wlan device!\n");
854 goto err_registerdev;
858 if (libertas_init_fw(priv)) {
859 lbs_pr_debug(1, "Firmware Init failed\n");
860 goto err_registerdev;
863 if (register_netdev(dev)) {
864 lbs_pr_err("Cannot register network device!\n");
868 /* Register virtual mesh interface */
869 if (register_netdev(mesh_dev)) {
870 lbs_pr_info("Cannot register mesh virtual interface!\n");
874 lbs_pr_info("%s: Marvell Wlan 802.11 adapter\n", dev->name);
876 libertas_debugfs_init_one(priv, dev);
878 if (libertas_found == MAX_DEVS)
880 libertas_devs[libertas_found] = dev;
882 if (device_create_file(&(mesh_dev->dev), &dev_attr_libertas_mpp))
883 goto err_create_file;
889 device_remove_file(&(mesh_dev->dev), &dev_attr_libertas_mpp);
891 libertas_sbi_unregister_dev(priv);
893 destroy_workqueue(priv->assoc_thread);
894 /* Stop the thread servicing the interrupts */
895 wake_up_interruptible(&priv->mainthread.waitq);
896 wlan_terminate_thread(&priv->mainthread);
897 kfree(priv->adapter);
900 free_netdev(mesh_dev);
906 static void wake_pending_cmdnodes(wlan_private *priv)
908 struct cmd_ctrl_node *cmdnode;
911 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
912 list_for_each_entry(cmdnode, &priv->adapter->cmdpendingq, list) {
913 cmdnode->cmdwaitqwoken = 1;
914 wake_up_interruptible(&cmdnode->cmdwait_q);
916 spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
920 int wlan_remove_card(void *card)
922 wlan_private *priv = libertas_sbi_get_priv(card);
923 wlan_adapter *adapter;
924 struct net_device *dev;
925 struct net_device *mesh_dev;
926 union iwreq_data wrqu;
936 adapter = priv->adapter;
943 dev = priv->wlan_dev.netdev;
944 mesh_dev = priv->mesh_dev;
946 netif_stop_queue(mesh_dev);
947 netif_stop_queue(priv->wlan_dev.netdev);
948 netif_carrier_off(priv->wlan_dev.netdev);
950 wake_pending_cmdnodes(priv);
952 device_remove_file(&(mesh_dev->dev), &dev_attr_libertas_mpp);
953 unregister_netdev(mesh_dev);
954 unregister_netdev(dev);
956 cancel_delayed_work(&priv->assoc_work);
957 destroy_workqueue(priv->assoc_thread);
959 if (adapter->psmode == wlan802_11powermodemax_psp) {
960 adapter->psmode = wlan802_11powermodecam;
961 libertas_ps_wakeup(priv, cmd_option_waitforrsp);
964 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
965 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
966 wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL);
968 adapter->surpriseremoved = 1;
970 /* Stop the thread servicing the interrupts */
971 wlan_terminate_thread(&priv->mainthread);
973 libertas_debugfs_remove_one(priv);
975 lbs_pr_debug(1, "Free adapter\n");
976 libertas_free_adapter(priv);
978 for (i = 0; i<libertas_found; i++) {
979 if (libertas_devs[i]==priv->wlan_dev.netdev) {
980 libertas_devs[i] = libertas_devs[--libertas_found];
981 libertas_devs[libertas_found] = NULL ;
986 lbs_pr_debug(1, "Unregister finish\n");
988 priv->wlan_dev.netdev = NULL;
989 priv->mesh_dev = NULL ;
990 free_netdev(mesh_dev);
998 * @brief This function finds the CFP in
999 * region_cfp_table based on region and band parameter.
1001 * @param region The region code
1002 * @param band The band
1003 * @param cfp_no A pointer to CFP number
1004 * @return A pointer to CFP
1006 struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band, int *cfp_no)
1012 end = sizeof(region_cfp_table)/sizeof(struct region_cfp_table);
1014 for (i = 0; i < end ; i++) {
1015 lbs_pr_debug(1, "region_cfp_table[i].region=%d\n",
1016 region_cfp_table[i].region);
1017 if (region_cfp_table[i].region == region) {
1018 *cfp_no = region_cfp_table[i].cfp_no_BG;
1020 return region_cfp_table[i].cfp_BG;
1028 int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band)
1030 wlan_adapter *adapter = priv->adapter;
1033 struct chan_freq_power *cfp;
1038 memset(adapter->region_channel, 0, sizeof(adapter->region_channel));
1041 cfp = libertas_get_region_cfp_table(region, band, &cfp_no);
1043 adapter->region_channel[i].nrcfp = cfp_no;
1044 adapter->region_channel[i].CFP = cfp;
1046 lbs_pr_debug(1, "wrong region code %#x in band B-G\n",
1050 adapter->region_channel[i].valid = 1;
1051 adapter->region_channel[i].region = region;
1052 adapter->region_channel[i].band = band;
1060 * @brief This function handles the interrupt. it will change PS
1061 * state if applicable. it will wake up main_thread to handle
1062 * the interrupt event as well.
1064 * @param dev A pointer to net_device structure
1067 void libertas_interrupt(struct net_device *dev)
1069 wlan_private *priv = dev->priv;
1073 lbs_pr_debug(1, "libertas_interrupt: intcounter=%d\n",
1074 priv->adapter->intcounter);
1076 priv->adapter->intcounter++;
1078 if (priv->adapter->psstate == PS_STATE_SLEEP) {
1079 priv->adapter->psstate = PS_STATE_AWAKE;
1080 netif_wake_queue(dev);
1083 wake_up_interruptible(&priv->mainthread.waitq);
1088 static int wlan_init_module(void)
1094 if (libertas_fw_name == NULL) {
1095 libertas_fw_name = default_fw_name;
1098 libertas_debugfs_init();
1100 if (libertas_sbi_register()) {
1102 libertas_debugfs_remove();
1111 static void wlan_cleanup_module(void)
1117 for (i = 0; i<libertas_found; i++) {
1118 wlan_private *priv = libertas_devs[i]->priv;
1122 libertas_sbi_unregister();
1123 libertas_debugfs_remove();
1128 module_init(wlan_init_module);
1129 module_exit(wlan_cleanup_module);
1131 MODULE_DESCRIPTION("M-WLAN Driver");
1132 MODULE_AUTHOR("Marvell International Ltd.");
1133 MODULE_LICENSE("GPL");