2 * This file contains the major functions in WLAN
3 * driver. It includes init, exit, open, close and main
7 #include <linux/moduleparam.h>
8 #include <linux/delay.h>
9 #include <linux/freezer.h>
10 #include <linux/etherdevice.h>
11 #include <linux/netdevice.h>
12 #include <linux/if_arp.h>
14 #include <net/iw_handler.h>
15 #include <net/ieee80211.h>
24 #define DRIVER_RELEASE_VERSION "321.p0"
25 const char libertas_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
32 /* Module parameters */
33 unsigned int libertas_debug = 0;
34 module_param(libertas_debug, int, 0644);
35 EXPORT_SYMBOL_GPL(libertas_debug);
38 #define WLAN_TX_PWR_DEFAULT 20 /*100mW */
39 #define WLAN_TX_PWR_US_DEFAULT 20 /*100mW */
40 #define WLAN_TX_PWR_JP_DEFAULT 16 /*50mW */
41 #define WLAN_TX_PWR_FR_DEFAULT 20 /*100mW */
42 #define WLAN_TX_PWR_EMEA_DEFAULT 20 /*100mW */
44 /* Format { channel, frequency (MHz), maxtxpower } */
45 /* band: 'B/G', region: USA FCC/Canada IC */
46 static struct chan_freq_power channel_freq_power_US_BG[] = {
47 {1, 2412, WLAN_TX_PWR_US_DEFAULT},
48 {2, 2417, WLAN_TX_PWR_US_DEFAULT},
49 {3, 2422, WLAN_TX_PWR_US_DEFAULT},
50 {4, 2427, WLAN_TX_PWR_US_DEFAULT},
51 {5, 2432, WLAN_TX_PWR_US_DEFAULT},
52 {6, 2437, WLAN_TX_PWR_US_DEFAULT},
53 {7, 2442, WLAN_TX_PWR_US_DEFAULT},
54 {8, 2447, WLAN_TX_PWR_US_DEFAULT},
55 {9, 2452, WLAN_TX_PWR_US_DEFAULT},
56 {10, 2457, WLAN_TX_PWR_US_DEFAULT},
57 {11, 2462, WLAN_TX_PWR_US_DEFAULT}
60 /* band: 'B/G', region: Europe ETSI */
61 static struct chan_freq_power channel_freq_power_EU_BG[] = {
62 {1, 2412, WLAN_TX_PWR_EMEA_DEFAULT},
63 {2, 2417, WLAN_TX_PWR_EMEA_DEFAULT},
64 {3, 2422, WLAN_TX_PWR_EMEA_DEFAULT},
65 {4, 2427, WLAN_TX_PWR_EMEA_DEFAULT},
66 {5, 2432, WLAN_TX_PWR_EMEA_DEFAULT},
67 {6, 2437, WLAN_TX_PWR_EMEA_DEFAULT},
68 {7, 2442, WLAN_TX_PWR_EMEA_DEFAULT},
69 {8, 2447, WLAN_TX_PWR_EMEA_DEFAULT},
70 {9, 2452, WLAN_TX_PWR_EMEA_DEFAULT},
71 {10, 2457, WLAN_TX_PWR_EMEA_DEFAULT},
72 {11, 2462, WLAN_TX_PWR_EMEA_DEFAULT},
73 {12, 2467, WLAN_TX_PWR_EMEA_DEFAULT},
74 {13, 2472, WLAN_TX_PWR_EMEA_DEFAULT}
77 /* band: 'B/G', region: Spain */
78 static struct chan_freq_power channel_freq_power_SPN_BG[] = {
79 {10, 2457, WLAN_TX_PWR_DEFAULT},
80 {11, 2462, WLAN_TX_PWR_DEFAULT}
83 /* band: 'B/G', region: France */
84 static struct chan_freq_power channel_freq_power_FR_BG[] = {
85 {10, 2457, WLAN_TX_PWR_FR_DEFAULT},
86 {11, 2462, WLAN_TX_PWR_FR_DEFAULT},
87 {12, 2467, WLAN_TX_PWR_FR_DEFAULT},
88 {13, 2472, WLAN_TX_PWR_FR_DEFAULT}
91 /* band: 'B/G', region: Japan */
92 static struct chan_freq_power channel_freq_power_JPN_BG[] = {
93 {1, 2412, WLAN_TX_PWR_JP_DEFAULT},
94 {2, 2417, WLAN_TX_PWR_JP_DEFAULT},
95 {3, 2422, WLAN_TX_PWR_JP_DEFAULT},
96 {4, 2427, WLAN_TX_PWR_JP_DEFAULT},
97 {5, 2432, WLAN_TX_PWR_JP_DEFAULT},
98 {6, 2437, WLAN_TX_PWR_JP_DEFAULT},
99 {7, 2442, WLAN_TX_PWR_JP_DEFAULT},
100 {8, 2447, WLAN_TX_PWR_JP_DEFAULT},
101 {9, 2452, WLAN_TX_PWR_JP_DEFAULT},
102 {10, 2457, WLAN_TX_PWR_JP_DEFAULT},
103 {11, 2462, WLAN_TX_PWR_JP_DEFAULT},
104 {12, 2467, WLAN_TX_PWR_JP_DEFAULT},
105 {13, 2472, WLAN_TX_PWR_JP_DEFAULT},
106 {14, 2484, WLAN_TX_PWR_JP_DEFAULT}
110 * the structure for channel, frequency and power
112 struct region_cfp_table {
114 struct chan_freq_power *cfp_BG;
119 * the structure for the mapping between region and CFP
121 static struct region_cfp_table region_cfp_table[] = {
123 channel_freq_power_US_BG,
124 sizeof(channel_freq_power_US_BG) / sizeof(struct chan_freq_power),
127 {0x20, /*CANADA IC */
128 channel_freq_power_US_BG,
129 sizeof(channel_freq_power_US_BG) / sizeof(struct chan_freq_power),
132 {0x30, /*EU*/ channel_freq_power_EU_BG,
133 sizeof(channel_freq_power_EU_BG) / sizeof(struct chan_freq_power),
136 {0x31, /*SPAIN*/ channel_freq_power_SPN_BG,
137 sizeof(channel_freq_power_SPN_BG) / sizeof(struct chan_freq_power),
140 {0x32, /*FRANCE*/ channel_freq_power_FR_BG,
141 sizeof(channel_freq_power_FR_BG) / sizeof(struct chan_freq_power),
144 {0x40, /*JAPAN*/ channel_freq_power_JPN_BG,
145 sizeof(channel_freq_power_JPN_BG) / sizeof(struct chan_freq_power),
148 /*Add new region here */
152 * the rates supported
154 u8 libertas_supported_rates[G_SUPPORTED_RATES] =
155 { 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
159 * the rates supported for ad-hoc G mode
161 u8 libertas_adhoc_rates_g[G_SUPPORTED_RATES] =
162 { 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
166 * the rates supported for ad-hoc B mode
168 u8 libertas_adhoc_rates_b[4] = { 0x82, 0x84, 0x8b, 0x96 };
171 * the table to keep region code
173 u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
174 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
177 * Attributes exported through sysfs
181 * @brief Get function for sysfs attribute libertas_mpp
183 static ssize_t libertas_mpp_get(struct device * dev,
184 struct device_attribute *attr, char * buf) {
185 struct cmd_ds_mesh_access mesh_access;
187 memset(&mesh_access, 0, sizeof(mesh_access));
188 libertas_prepare_and_send_command(to_net_dev(dev)->priv,
190 cmd_act_mesh_get_mpp,
191 cmd_option_waitforrsp, 0, (void *)&mesh_access);
193 return snprintf(buf, 3, "%d\n", mesh_access.data[0]);
197 * @brief Set function for sysfs attribute libertas_mpp
199 static ssize_t libertas_mpp_set(struct device * dev,
200 struct device_attribute *attr, const char * buf, size_t count) {
201 struct cmd_ds_mesh_access mesh_access;
203 memset(&mesh_access, 0, sizeof(mesh_access));
204 sscanf(buf, "%d", &(mesh_access.data[0]));
205 libertas_prepare_and_send_command((to_net_dev(dev))->priv,
207 cmd_act_mesh_set_mpp,
208 cmd_option_waitforrsp, 0, (void *)&mesh_access);
213 * libertas_mpp attribute to be exported per mshX interface
214 * through sysfs (/sys/class/net/mshX/libertas-mpp)
216 static DEVICE_ATTR(libertas_mpp, 0644, libertas_mpp_get,
220 * @brief Check if the device can be open and wait if necessary.
222 * @param dev A pointer to net_device structure
225 * For USB adapter, on some systems the device open handler will be
226 * called before FW ready. Use the following flag check and wait
227 * function to work around the issue.
230 static int pre_open_check(struct net_device *dev)
232 wlan_private *priv = (wlan_private *) dev->priv;
233 wlan_adapter *adapter = priv->adapter;
236 while (!adapter->fw_ready && i < 20) {
238 msleep_interruptible(100);
240 if (!adapter->fw_ready) {
241 lbs_pr_err("firmware not ready\n");
249 * @brief This function opens the device
251 * @param dev A pointer to net_device structure
254 static int wlan_dev_open(struct net_device *dev)
256 wlan_private *priv = (wlan_private *) dev->priv;
257 wlan_adapter *adapter = priv->adapter;
259 lbs_deb_enter(LBS_DEB_NET);
263 if (adapter->connect_status == libertas_connected) {
264 netif_carrier_on(priv->dev);
265 netif_carrier_on(priv->mesh_dev);
267 netif_carrier_off(priv->dev);
268 netif_carrier_off(priv->mesh_dev);
271 lbs_deb_leave(LBS_DEB_NET);
275 * @brief This function opens the mshX interface
277 * @param dev A pointer to net_device structure
280 static int mesh_open(struct net_device *dev)
282 wlan_private *priv = (wlan_private *) dev->priv ;
284 if (pre_open_check(dev) == -1)
286 priv->mesh_open = 1 ;
287 netif_wake_queue(priv->mesh_dev);
288 if (priv->infra_open == 0)
289 return wlan_dev_open(priv->dev) ;
294 * @brief This function opens the ethX interface
296 * @param dev A pointer to net_device structure
299 static int wlan_open(struct net_device *dev)
301 wlan_private *priv = (wlan_private *) dev->priv ;
303 if(pre_open_check(dev) == -1)
305 priv->infra_open = 1 ;
306 netif_wake_queue(priv->dev);
308 return wlan_dev_open(priv->dev) ;
312 static int wlan_dev_close(struct net_device *dev)
314 wlan_private *priv = dev->priv;
316 lbs_deb_enter(LBS_DEB_NET);
318 netif_carrier_off(priv->dev);
321 lbs_deb_leave(LBS_DEB_NET);
326 * @brief This function closes the mshX interface
328 * @param dev A pointer to net_device structure
331 static int mesh_close(struct net_device *dev)
333 wlan_private *priv = (wlan_private *) (dev->priv);
336 netif_stop_queue(priv->mesh_dev);
337 if (priv->infra_open == 0)
338 return wlan_dev_close(dev);
344 * @brief This function closes the ethX interface
346 * @param dev A pointer to net_device structure
349 static int wlan_close(struct net_device *dev)
351 wlan_private *priv = (wlan_private *) dev->priv;
353 netif_stop_queue(dev);
354 priv->infra_open = 0;
355 if (priv->mesh_open == 0)
356 return wlan_dev_close(dev);
362 static int wlan_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
365 wlan_private *priv = dev->priv;
367 lbs_deb_enter(LBS_DEB_NET);
369 if (priv->dnld_sent || priv->adapter->TxLockFlag) {
370 priv->stats.tx_dropped++;
374 netif_stop_queue(priv->dev);
375 netif_stop_queue(priv->mesh_dev);
377 if (libertas_process_tx(priv, skb) == 0)
378 dev->trans_start = jiffies;
380 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
385 * @brief Mark mesh packets and handover them to wlan_hard_start_xmit
388 static int mesh_pre_start_xmit(struct sk_buff *skb, struct net_device *dev)
390 wlan_private *priv = dev->priv;
393 lbs_deb_enter(LBS_DEB_MESH);
397 ret = wlan_hard_start_xmit(skb, priv->dev);
398 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
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)
410 lbs_deb_enter(LBS_DEB_NET);
412 UNSET_MESH_FRAME(skb);
414 ret = wlan_hard_start_xmit(skb, dev);
415 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
419 static void wlan_tx_timeout(struct net_device *dev)
421 wlan_private *priv = (wlan_private *) dev->priv;
423 lbs_deb_enter(LBS_DEB_TX);
425 lbs_pr_err("tx watch dog timeout\n");
427 priv->dnld_sent = DNLD_RES_RECEIVED;
428 dev->trans_start = jiffies;
430 if (priv->adapter->currenttxskb) {
431 if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
432 /* If we are here, we have not received feedback from
433 the previous packet. Assume TX_FAIL and move on. */
434 priv->adapter->eventcause = 0x01000000;
435 libertas_send_tx_feedback(priv);
437 wake_up_interruptible(&priv->mainthread.waitq);
438 } else if (priv->adapter->connect_status == libertas_connected) {
439 netif_wake_queue(priv->dev);
440 netif_wake_queue(priv->mesh_dev);
443 lbs_deb_leave(LBS_DEB_TX);
447 * @brief This function returns the network statistics
449 * @param dev A pointer to wlan_private structure
450 * @return A pointer to net_device_stats structure
452 static struct net_device_stats *wlan_get_stats(struct net_device *dev)
454 wlan_private *priv = (wlan_private *) dev->priv;
459 static int wlan_set_mac_address(struct net_device *dev, void *addr)
462 wlan_private *priv = (wlan_private *) dev->priv;
463 wlan_adapter *adapter = priv->adapter;
464 struct sockaddr *phwaddr = addr;
466 lbs_deb_enter(LBS_DEB_NET);
468 memset(adapter->current_addr, 0, ETH_ALEN);
470 /* dev->dev_addr is 8 bytes */
471 lbs_dbg_hex("dev->dev_addr:", dev->dev_addr, ETH_ALEN);
473 lbs_dbg_hex("addr:", phwaddr->sa_data, ETH_ALEN);
474 memcpy(adapter->current_addr, phwaddr->sa_data, ETH_ALEN);
476 ret = libertas_prepare_and_send_command(priv, cmd_802_11_mac_address,
478 cmd_option_waitforrsp, 0, NULL);
481 lbs_deb_net("set MAC address failed\n");
486 lbs_dbg_hex("adapter->macaddr:", adapter->current_addr, ETH_ALEN);
487 memcpy(dev->dev_addr, adapter->current_addr, ETH_ALEN);
489 memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
492 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
496 static int wlan_copy_multicast_address(wlan_adapter * adapter,
497 struct net_device *dev)
500 struct dev_mc_list *mcptr = dev->mc_list;
502 for (i = 0; i < dev->mc_count; i++) {
503 memcpy(&adapter->multicastlist[i], mcptr->dmi_addr, ETH_ALEN);
511 static void wlan_set_multicast_list(struct net_device *dev)
513 wlan_private *priv = dev->priv;
514 wlan_adapter *adapter = priv->adapter;
517 lbs_deb_enter(LBS_DEB_NET);
519 oldpacketfilter = adapter->currentpacketfilter;
521 if (dev->flags & IFF_PROMISC) {
522 lbs_deb_net("enable promiscuous mode\n");
523 adapter->currentpacketfilter |=
524 cmd_act_mac_promiscuous_enable;
525 adapter->currentpacketfilter &=
526 ~(cmd_act_mac_all_multicast_enable |
527 cmd_act_mac_multicast_enable);
530 adapter->currentpacketfilter &=
531 ~cmd_act_mac_promiscuous_enable;
533 if (dev->flags & IFF_ALLMULTI || dev->mc_count >
534 MRVDRV_MAX_MULTICAST_LIST_SIZE) {
535 lbs_deb_net( "enabling all multicast\n");
536 adapter->currentpacketfilter |=
537 cmd_act_mac_all_multicast_enable;
538 adapter->currentpacketfilter &=
539 ~cmd_act_mac_multicast_enable;
541 adapter->currentpacketfilter &=
542 ~cmd_act_mac_all_multicast_enable;
544 if (!dev->mc_count) {
545 lbs_deb_net("no multicast addresses, "
546 "disabling multicast\n");
547 adapter->currentpacketfilter &=
548 ~cmd_act_mac_multicast_enable;
552 adapter->currentpacketfilter |=
553 cmd_act_mac_multicast_enable;
555 adapter->nr_of_multicastmacaddr =
556 wlan_copy_multicast_address(adapter, dev);
558 lbs_deb_net("multicast addresses: %d\n",
561 for (i = 0; i < dev->mc_count; i++) {
562 lbs_deb_net("Multicast address %d:"
564 adapter->multicastlist[i][0],
565 adapter->multicastlist[i][1],
566 adapter->multicastlist[i][2],
567 adapter->multicastlist[i][3],
568 adapter->multicastlist[i][4],
569 adapter->multicastlist[i][5]);
571 /* send multicast addresses to firmware */
572 libertas_prepare_and_send_command(priv,
573 cmd_mac_multicast_adr,
580 if (adapter->currentpacketfilter != oldpacketfilter) {
581 libertas_set_mac_packet_filter(priv);
584 lbs_deb_leave(LBS_DEB_NET);
588 * @brief This function handles the major jobs in the WLAN driver.
589 * It handles all events generated by firmware, RX data received
590 * from firmware and TX data sent from kernel.
592 * @param data A pointer to wlan_thread structure
595 static int wlan_service_main_thread(void *data)
597 struct wlan_thread *thread = data;
598 wlan_private *priv = thread->priv;
599 wlan_adapter *adapter = priv->adapter;
603 lbs_deb_enter(LBS_DEB_THREAD);
605 wlan_activate_thread(thread);
607 init_waitqueue_entry(&wait, current);
610 lbs_deb_thread( "main-thread 111: intcounter=%d "
611 "currenttxskb=%p dnld_sent=%d\n",
613 adapter->currenttxskb, priv->dnld_sent);
615 add_wait_queue(&thread->waitq, &wait);
616 set_current_state(TASK_INTERRUPTIBLE);
617 spin_lock_irq(&adapter->driver_lock);
618 if ((adapter->psstate == PS_STATE_SLEEP) ||
619 (!adapter->intcounter
620 && (priv->dnld_sent || adapter->cur_cmd ||
621 list_empty(&adapter->cmdpendingq)))) {
623 "main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
624 adapter->connect_status, adapter->intcounter,
625 adapter->psmode, adapter->psstate);
626 spin_unlock_irq(&adapter->driver_lock);
629 spin_unlock_irq(&adapter->driver_lock);
633 "main-thread 222 (waking up): intcounter=%d currenttxskb=%p "
634 "dnld_sent=%d\n", adapter->intcounter,
635 adapter->currenttxskb, priv->dnld_sent);
637 set_current_state(TASK_RUNNING);
638 remove_wait_queue(&thread->waitq, &wait);
641 lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p "
644 adapter->currenttxskb, priv->dnld_sent);
646 if (kthread_should_stop()
647 || adapter->surpriseremoved) {
649 "main-thread: break from main thread: surpriseremoved=0x%x\n",
650 adapter->surpriseremoved);
655 spin_lock_irq(&adapter->driver_lock);
656 if (adapter->intcounter) {
658 adapter->intcounter = 0;
659 int_status = priv->hw_get_int_status(priv, &ireg);
663 "main-thread: reading HOST_INT_STATUS_REG failed\n");
664 spin_unlock_irq(&adapter->driver_lock);
667 adapter->hisregcpy |= ireg;
670 lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p "
673 adapter->currenttxskb, priv->dnld_sent);
675 /* command response? */
676 if (adapter->hisregcpy & his_cmdupldrdy) {
677 lbs_deb_thread("main-thread: cmd response ready\n");
679 adapter->hisregcpy &= ~his_cmdupldrdy;
680 spin_unlock_irq(&adapter->driver_lock);
681 libertas_process_rx_command(priv);
682 spin_lock_irq(&adapter->driver_lock);
686 if (adapter->hisregcpy & his_cardevent) {
687 lbs_deb_thread("main-thread: Card Event Activity\n");
689 adapter->hisregcpy &= ~his_cardevent;
691 if (priv->hw_read_event_cause(priv)) {
693 "main-thread: hw_read_event_cause failed\n");
694 spin_unlock_irq(&adapter->driver_lock);
697 spin_unlock_irq(&adapter->driver_lock);
698 libertas_process_event(priv);
700 spin_unlock_irq(&adapter->driver_lock);
702 /* Check if we need to confirm Sleep Request received previously */
703 if (adapter->psstate == PS_STATE_PRE_SLEEP) {
704 if (!priv->dnld_sent && !adapter->cur_cmd) {
705 if (adapter->connect_status ==
706 libertas_connected) {
708 "main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p "
709 "dnld_sent=%d cur_cmd=%p, confirm now\n",
711 adapter->currenttxskb,
715 libertas_ps_confirm_sleep(priv,
716 (u16) adapter->psmode);
718 /* workaround for firmware sending
719 * deauth/linkloss event immediately
720 * after sleep request, remove this
721 * after firmware fixes it
723 adapter->psstate = PS_STATE_AWAKE;
725 "main-thread: ignore PS_SleepConfirm in non-connected state\n");
730 /* The PS state is changed during processing of Sleep Request
733 if ((priv->adapter->psstate == PS_STATE_SLEEP) ||
734 (priv->adapter->psstate == PS_STATE_PRE_SLEEP))
737 /* Execute the next command */
738 if (!priv->dnld_sent && !priv->adapter->cur_cmd)
739 libertas_execute_next_command(priv);
741 /* Wake-up command waiters which can't sleep in
742 * libertas_prepare_and_send_command
744 if (!adapter->nr_cmd_pending)
745 wake_up_all(&adapter->cmd_pending);
747 libertas_tx_runqueue(priv);
750 del_timer(&adapter->command_timer);
751 adapter->nr_cmd_pending = 0;
752 wake_up_all(&adapter->cmd_pending);
753 wlan_deactivate_thread(thread);
755 lbs_deb_leave(LBS_DEB_THREAD);
760 * @brief This function adds the card. it will probe the
761 * card, allocate the wlan_priv and initialize the device.
763 * @param card A pointer to card
764 * @return A pointer to wlan_private structure
766 wlan_private *libertas_add_card(void *card, struct device *dmdev)
768 struct net_device *dev = NULL;
769 wlan_private *priv = NULL;
771 lbs_deb_enter(LBS_DEB_NET);
773 /* Allocate an Ethernet device and register it */
774 if (!(dev = alloc_etherdev(sizeof(wlan_private)))) {
775 lbs_pr_err("init ethX device failed\n");
780 /* allocate buffer for wlan_adapter */
781 if (!(priv->adapter = kzalloc(sizeof(wlan_adapter), GFP_KERNEL))) {
782 lbs_pr_err("allocate buffer for wlan_adapter failed\n");
789 priv->infra_open = 0;
791 SET_MODULE_OWNER(dev);
793 /* Setup the OS Interface to our functions */
794 dev->open = wlan_open;
795 dev->hard_start_xmit = wlan_pre_start_xmit;
796 dev->stop = wlan_close;
797 dev->do_ioctl = libertas_do_ioctl;
798 dev->set_mac_address = wlan_set_mac_address;
799 dev->tx_timeout = wlan_tx_timeout;
800 dev->get_stats = wlan_get_stats;
801 dev->watchdog_timeo = 5 * HZ;
802 dev->ethtool_ops = &libertas_ethtool_ops;
804 dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def;
806 #define NETIF_F_DYNALLOC 16
807 dev->features |= NETIF_F_DYNALLOC;
808 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
809 dev->set_multicast_list = wlan_set_multicast_list;
811 SET_NETDEV_DEV(dev, dmdev);
813 INIT_LIST_HEAD(&priv->adapter->cmdfreeq);
814 INIT_LIST_HEAD(&priv->adapter->cmdpendingq);
816 spin_lock_init(&priv->adapter->driver_lock);
817 init_waitqueue_head(&priv->adapter->cmd_pending);
818 priv->adapter->nr_cmd_pending = 0;
825 lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv);
828 EXPORT_SYMBOL_GPL(libertas_add_card);
830 int libertas_activate_card(wlan_private *priv, char *fw_name)
832 struct net_device *dev = priv->dev;
835 lbs_deb_enter(LBS_DEB_MAIN);
837 lbs_deb_thread("Starting kthread...\n");
838 priv->mainthread.priv = priv;
839 wlan_create_thread(wlan_service_main_thread,
840 &priv->mainthread, "wlan_main_service");
843 create_singlethread_workqueue("libertas_assoc");
844 INIT_DELAYED_WORK(&priv->assoc_work, libertas_association_worker);
847 * Register the device. Fillup the private data structure with
848 * relevant information from the card and request for the required
851 if (priv->hw_register_dev(priv) < 0) {
852 lbs_pr_err("failed to register WLAN device\n");
853 goto err_registerdev;
857 if (fw_name && libertas_init_fw(priv, fw_name)) {
858 lbs_pr_err("firmware init failed\n");
859 goto err_registerdev;
862 if (register_netdev(dev)) {
863 lbs_pr_err("cannot register ethX device\n");
867 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
869 libertas_debugfs_init_one(priv, dev);
875 priv->hw_unregister_dev(priv);
877 destroy_workqueue(priv->assoc_thread);
878 /* Stop the thread servicing the interrupts */
879 wake_up_interruptible(&priv->mainthread.waitq);
880 wlan_terminate_thread(&priv->mainthread);
882 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
885 EXPORT_SYMBOL_GPL(libertas_activate_card);
889 * @brief This function adds mshX interface
891 * @param priv A pointer to the wlan_private structure
892 * @return 0 if successful, -X otherwise
894 int libertas_add_mesh(wlan_private *priv, struct device *dev)
896 struct net_device *mesh_dev = NULL;
899 lbs_deb_enter(LBS_DEB_MESH);
901 /* Allocate a virtual mesh device */
902 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
903 lbs_deb_mesh("init mshX device failed\n");
907 mesh_dev->priv = priv;
908 priv->mesh_dev = mesh_dev;
910 SET_MODULE_OWNER(mesh_dev);
912 mesh_dev->open = mesh_open;
913 mesh_dev->hard_start_xmit = mesh_pre_start_xmit;
914 mesh_dev->stop = mesh_close;
915 mesh_dev->do_ioctl = libertas_do_ioctl;
916 mesh_dev->get_stats = wlan_get_stats;
917 mesh_dev->ethtool_ops = &libertas_ethtool_ops;
918 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
919 sizeof(priv->dev->dev_addr));
921 SET_NETDEV_DEV(priv->mesh_dev, dev);
924 mesh_dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def;
926 #define NETIF_F_DYNALLOC 16
928 /* Register virtual mesh interface */
929 ret = register_netdev(mesh_dev);
931 lbs_pr_err("cannot register mshX virtual interface\n");
935 ret = device_create_file(&(mesh_dev->dev), &dev_attr_libertas_mpp);
939 /* Everything successful */
945 unregister_netdev(mesh_dev);
948 free_netdev(mesh_dev);
951 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
954 EXPORT_SYMBOL_GPL(libertas_add_mesh);
956 static void wake_pending_cmdnodes(wlan_private *priv)
958 struct cmd_ctrl_node *cmdnode;
961 lbs_deb_enter(LBS_DEB_CMD);
963 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
964 list_for_each_entry(cmdnode, &priv->adapter->cmdpendingq, list) {
965 cmdnode->cmdwaitqwoken = 1;
966 wake_up_interruptible(&cmdnode->cmdwait_q);
968 spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
972 int libertas_remove_card(wlan_private *priv)
974 wlan_adapter *adapter;
975 struct net_device *dev;
976 union iwreq_data wrqu;
978 lbs_deb_enter(LBS_DEB_NET);
983 adapter = priv->adapter;
990 netif_stop_queue(priv->dev);
991 netif_carrier_off(priv->dev);
993 wake_pending_cmdnodes(priv);
995 unregister_netdev(dev);
997 cancel_delayed_work(&priv->assoc_work);
998 destroy_workqueue(priv->assoc_thread);
1000 if (adapter->psmode == wlan802_11powermodemax_psp) {
1001 adapter->psmode = wlan802_11powermodecam;
1002 libertas_ps_wakeup(priv, cmd_option_waitforrsp);
1005 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
1006 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1007 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
1009 adapter->surpriseremoved = 1;
1011 /* Stop the thread servicing the interrupts */
1012 wlan_terminate_thread(&priv->mainthread);
1014 libertas_debugfs_remove_one(priv);
1016 lbs_deb_net("free adapter\n");
1017 libertas_free_adapter(priv);
1019 lbs_deb_net("unregister finish\n");
1025 lbs_deb_leave(LBS_DEB_NET);
1028 EXPORT_SYMBOL_GPL(libertas_remove_card);
1031 void libertas_remove_mesh(wlan_private *priv)
1033 struct net_device *mesh_dev;
1035 lbs_deb_enter(LBS_DEB_NET);
1040 mesh_dev = priv->mesh_dev;
1042 netif_stop_queue(mesh_dev);
1043 netif_carrier_off(priv->mesh_dev);
1045 device_remove_file(&(mesh_dev->dev), &dev_attr_libertas_mpp);
1046 unregister_netdev(mesh_dev);
1048 priv->mesh_dev = NULL ;
1049 free_netdev(mesh_dev);
1052 lbs_deb_leave(LBS_DEB_NET);
1054 EXPORT_SYMBOL_GPL(libertas_remove_mesh);
1057 * @brief This function finds the CFP in
1058 * region_cfp_table based on region and band parameter.
1060 * @param region The region code
1061 * @param band The band
1062 * @param cfp_no A pointer to CFP number
1063 * @return A pointer to CFP
1065 struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band, int *cfp_no)
1069 lbs_deb_enter(LBS_DEB_MAIN);
1071 end = sizeof(region_cfp_table)/sizeof(struct region_cfp_table);
1073 for (i = 0; i < end ; i++) {
1074 lbs_deb_main("region_cfp_table[i].region=%d\n",
1075 region_cfp_table[i].region);
1076 if (region_cfp_table[i].region == region) {
1077 *cfp_no = region_cfp_table[i].cfp_no_BG;
1078 lbs_deb_leave(LBS_DEB_MAIN);
1079 return region_cfp_table[i].cfp_BG;
1083 lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
1087 int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band)
1089 wlan_adapter *adapter = priv->adapter;
1093 struct chan_freq_power *cfp;
1096 lbs_deb_enter(LBS_DEB_MAIN);
1098 memset(adapter->region_channel, 0, sizeof(adapter->region_channel));
1101 cfp = libertas_get_region_cfp_table(region, band, &cfp_no);
1103 adapter->region_channel[i].nrcfp = cfp_no;
1104 adapter->region_channel[i].CFP = cfp;
1106 lbs_deb_main("wrong region code %#x in band B/G\n",
1111 adapter->region_channel[i].valid = 1;
1112 adapter->region_channel[i].region = region;
1113 adapter->region_channel[i].band = band;
1117 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1122 * @brief This function handles the interrupt. it will change PS
1123 * state if applicable. it will wake up main_thread to handle
1124 * the interrupt event as well.
1126 * @param dev A pointer to net_device structure
1129 void libertas_interrupt(struct net_device *dev)
1131 wlan_private *priv = dev->priv;
1133 lbs_deb_enter(LBS_DEB_THREAD);
1135 lbs_deb_thread("libertas_interrupt: intcounter=%d\n",
1136 priv->adapter->intcounter);
1138 priv->adapter->intcounter++;
1140 if (priv->adapter->psstate == PS_STATE_SLEEP) {
1141 priv->adapter->psstate = PS_STATE_AWAKE;
1142 netif_wake_queue(dev);
1143 netif_wake_queue(priv->mesh_dev);
1146 wake_up_interruptible(&priv->mainthread.waitq);
1148 lbs_deb_leave(LBS_DEB_THREAD);
1150 EXPORT_SYMBOL_GPL(libertas_interrupt);
1152 static int libertas_init_module(void)
1154 lbs_deb_enter(LBS_DEB_MAIN);
1155 libertas_debugfs_init();
1156 lbs_deb_leave(LBS_DEB_MAIN);
1160 static void libertas_exit_module(void)
1162 lbs_deb_enter(LBS_DEB_MAIN);
1164 libertas_debugfs_remove();
1166 lbs_deb_leave(LBS_DEB_MAIN);
1169 module_init(libertas_init_module);
1170 module_exit(libertas_exit_module);
1172 MODULE_DESCRIPTION("Libertas WLAN Driver Library");
1173 MODULE_AUTHOR("Marvell International Ltd.");
1174 MODULE_LICENSE("GPL");