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>
26 #define DRIVER_RELEASE_VERSION "320.p0"
27 const char libertas_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
34 /* Module parameters */
35 unsigned int libertas_debug = 0;
36 module_param(libertas_debug, int, 0644);
40 #define WLAN_TX_PWR_DEFAULT 20 /*100mW */
41 #define WLAN_TX_PWR_US_DEFAULT 20 /*100mW */
42 #define WLAN_TX_PWR_JP_DEFAULT 16 /*50mW */
43 #define WLAN_TX_PWR_FR_DEFAULT 20 /*100mW */
44 #define WLAN_TX_PWR_EMEA_DEFAULT 20 /*100mW */
46 /* Format { channel, frequency (MHz), maxtxpower } */
47 /* band: 'B/G', region: USA FCC/Canada IC */
48 static struct chan_freq_power channel_freq_power_US_BG[] = {
49 {1, 2412, WLAN_TX_PWR_US_DEFAULT},
50 {2, 2417, WLAN_TX_PWR_US_DEFAULT},
51 {3, 2422, WLAN_TX_PWR_US_DEFAULT},
52 {4, 2427, WLAN_TX_PWR_US_DEFAULT},
53 {5, 2432, WLAN_TX_PWR_US_DEFAULT},
54 {6, 2437, WLAN_TX_PWR_US_DEFAULT},
55 {7, 2442, WLAN_TX_PWR_US_DEFAULT},
56 {8, 2447, WLAN_TX_PWR_US_DEFAULT},
57 {9, 2452, WLAN_TX_PWR_US_DEFAULT},
58 {10, 2457, WLAN_TX_PWR_US_DEFAULT},
59 {11, 2462, WLAN_TX_PWR_US_DEFAULT}
62 /* band: 'B/G', region: Europe ETSI */
63 static struct chan_freq_power channel_freq_power_EU_BG[] = {
64 {1, 2412, WLAN_TX_PWR_EMEA_DEFAULT},
65 {2, 2417, WLAN_TX_PWR_EMEA_DEFAULT},
66 {3, 2422, WLAN_TX_PWR_EMEA_DEFAULT},
67 {4, 2427, WLAN_TX_PWR_EMEA_DEFAULT},
68 {5, 2432, WLAN_TX_PWR_EMEA_DEFAULT},
69 {6, 2437, WLAN_TX_PWR_EMEA_DEFAULT},
70 {7, 2442, WLAN_TX_PWR_EMEA_DEFAULT},
71 {8, 2447, WLAN_TX_PWR_EMEA_DEFAULT},
72 {9, 2452, WLAN_TX_PWR_EMEA_DEFAULT},
73 {10, 2457, WLAN_TX_PWR_EMEA_DEFAULT},
74 {11, 2462, WLAN_TX_PWR_EMEA_DEFAULT},
75 {12, 2467, WLAN_TX_PWR_EMEA_DEFAULT},
76 {13, 2472, WLAN_TX_PWR_EMEA_DEFAULT}
79 /* band: 'B/G', region: Spain */
80 static struct chan_freq_power channel_freq_power_SPN_BG[] = {
81 {10, 2457, WLAN_TX_PWR_DEFAULT},
82 {11, 2462, WLAN_TX_PWR_DEFAULT}
85 /* band: 'B/G', region: France */
86 static struct chan_freq_power channel_freq_power_FR_BG[] = {
87 {10, 2457, WLAN_TX_PWR_FR_DEFAULT},
88 {11, 2462, WLAN_TX_PWR_FR_DEFAULT},
89 {12, 2467, WLAN_TX_PWR_FR_DEFAULT},
90 {13, 2472, WLAN_TX_PWR_FR_DEFAULT}
93 /* band: 'B/G', region: Japan */
94 static struct chan_freq_power channel_freq_power_JPN_BG[] = {
95 {1, 2412, WLAN_TX_PWR_JP_DEFAULT},
96 {2, 2417, WLAN_TX_PWR_JP_DEFAULT},
97 {3, 2422, WLAN_TX_PWR_JP_DEFAULT},
98 {4, 2427, WLAN_TX_PWR_JP_DEFAULT},
99 {5, 2432, WLAN_TX_PWR_JP_DEFAULT},
100 {6, 2437, WLAN_TX_PWR_JP_DEFAULT},
101 {7, 2442, WLAN_TX_PWR_JP_DEFAULT},
102 {8, 2447, WLAN_TX_PWR_JP_DEFAULT},
103 {9, 2452, WLAN_TX_PWR_JP_DEFAULT},
104 {10, 2457, WLAN_TX_PWR_JP_DEFAULT},
105 {11, 2462, WLAN_TX_PWR_JP_DEFAULT},
106 {12, 2467, WLAN_TX_PWR_JP_DEFAULT},
107 {13, 2472, WLAN_TX_PWR_JP_DEFAULT},
108 {14, 2484, WLAN_TX_PWR_JP_DEFAULT}
112 * the structure for channel, frequency and power
114 struct region_cfp_table {
116 struct chan_freq_power *cfp_BG;
121 * the structure for the mapping between region and CFP
123 static struct region_cfp_table region_cfp_table[] = {
125 channel_freq_power_US_BG,
126 sizeof(channel_freq_power_US_BG) / sizeof(struct chan_freq_power),
129 {0x20, /*CANADA IC */
130 channel_freq_power_US_BG,
131 sizeof(channel_freq_power_US_BG) / sizeof(struct chan_freq_power),
134 {0x30, /*EU*/ channel_freq_power_EU_BG,
135 sizeof(channel_freq_power_EU_BG) / sizeof(struct chan_freq_power),
138 {0x31, /*SPAIN*/ channel_freq_power_SPN_BG,
139 sizeof(channel_freq_power_SPN_BG) / sizeof(struct chan_freq_power),
142 {0x32, /*FRANCE*/ channel_freq_power_FR_BG,
143 sizeof(channel_freq_power_FR_BG) / sizeof(struct chan_freq_power),
146 {0x40, /*JAPAN*/ channel_freq_power_JPN_BG,
147 sizeof(channel_freq_power_JPN_BG) / sizeof(struct chan_freq_power),
150 /*Add new region here */
154 * the rates supported
156 u8 libertas_supported_rates[G_SUPPORTED_RATES] =
157 { 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
161 * the rates supported for ad-hoc G mode
163 u8 libertas_adhoc_rates_g[G_SUPPORTED_RATES] =
164 { 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
168 * the rates supported for ad-hoc B mode
170 u8 libertas_adhoc_rates_b[4] = { 0x82, 0x84, 0x8b, 0x96 };
173 * the table to keep region code
175 u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
176 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
178 static u8 *default_fw_name = "usb8388.bin";
181 * Attributes exported through sysfs
185 * @brief Get function for sysfs attribute libertas_mpp
187 static ssize_t libertas_mpp_get(struct device * dev,
188 struct device_attribute *attr, char * buf) {
189 struct cmd_ds_mesh_access mesh_access;
191 memset(&mesh_access, 0, sizeof(mesh_access));
192 libertas_prepare_and_send_command(to_net_dev(dev)->priv,
194 cmd_act_mesh_get_mpp,
195 cmd_option_waitforrsp, 0, (void *)&mesh_access);
197 return snprintf(buf, 3, "%d\n", mesh_access.data[0]);
201 * @brief Set function for sysfs attribute libertas_mpp
203 static ssize_t libertas_mpp_set(struct device * dev,
204 struct device_attribute *attr, const char * buf, size_t count) {
205 struct cmd_ds_mesh_access mesh_access;
207 memset(&mesh_access, 0, sizeof(mesh_access));
208 sscanf(buf, "%d", &(mesh_access.data[0]));
209 libertas_prepare_and_send_command((to_net_dev(dev))->priv,
211 cmd_act_mesh_set_mpp,
212 cmd_option_waitforrsp, 0, (void *)&mesh_access);
217 * libertas_mpp attribute to be exported per mshX interface
218 * through sysfs (/sys/class/net/mshX/libertas-mpp)
220 static DEVICE_ATTR(libertas_mpp, 0644, libertas_mpp_get,
224 * @brief Check if the device can be open and wait if necessary.
226 * @param dev A pointer to net_device structure
229 * For USB adapter, on some systems the device open handler will be
230 * called before FW ready. Use the following flag check and wait
231 * function to work around the issue.
234 static int pre_open_check(struct net_device *dev)
236 wlan_private *priv = (wlan_private *) dev->priv;
237 wlan_adapter *adapter = priv->adapter;
240 while (!adapter->fw_ready && i < 20) {
242 msleep_interruptible(100);
244 if (!adapter->fw_ready) {
245 lbs_pr_err("firmware not ready\n");
253 * @brief This function opens the device
255 * @param dev A pointer to net_device structure
258 static int wlan_dev_open(struct net_device *dev)
260 wlan_private *priv = (wlan_private *) dev->priv;
261 wlan_adapter *adapter = priv->adapter;
263 lbs_deb_enter(LBS_DEB_NET);
267 if (adapter->connect_status == libertas_connected) {
268 netif_carrier_on(priv->wlan_dev.netdev);
269 netif_carrier_on(priv->mesh_dev);
271 netif_carrier_off(priv->wlan_dev.netdev);
272 netif_carrier_off(priv->mesh_dev);
275 lbs_deb_leave(LBS_DEB_NET);
279 * @brief This function opens the mshX interface
281 * @param dev A pointer to net_device structure
284 static int mesh_open(struct net_device *dev)
286 wlan_private *priv = (wlan_private *) dev->priv ;
288 if (pre_open_check(dev) == -1)
290 priv->mesh_open = 1 ;
291 netif_wake_queue(priv->mesh_dev);
292 if (priv->infra_open == 0)
293 return wlan_dev_open(priv->wlan_dev.netdev) ;
298 * @brief This function opens the ethX interface
300 * @param dev A pointer to net_device structure
303 static int wlan_open(struct net_device *dev)
305 wlan_private *priv = (wlan_private *) dev->priv ;
307 if(pre_open_check(dev) == -1)
309 priv->infra_open = 1 ;
310 netif_wake_queue(priv->wlan_dev.netdev);
312 return wlan_dev_open(priv->wlan_dev.netdev) ;
316 static int wlan_dev_close(struct net_device *dev)
318 wlan_private *priv = dev->priv;
320 lbs_deb_enter(LBS_DEB_NET);
322 netif_carrier_off(priv->wlan_dev.netdev);
323 netif_carrier_off(priv->mesh_dev);
326 lbs_deb_leave(LBS_DEB_NET);
331 * @brief This function closes the mshX interface
333 * @param dev A pointer to net_device structure
336 static int mesh_close(struct net_device *dev)
338 wlan_private *priv = (wlan_private *) (dev->priv);
341 netif_stop_queue(priv->mesh_dev);
342 if (priv->infra_open == 0)
343 return wlan_dev_close( ((wlan_private *) dev->priv)->wlan_dev.netdev) ;
349 * @brief This function closes the ethX interface
351 * @param dev A pointer to net_device structure
354 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;
372 lbs_deb_enter(LBS_DEB_NET);
374 if (priv->wlan_dev.dnld_sent || priv->adapter->TxLockFlag) {
375 priv->stats.tx_dropped++;
379 netif_stop_queue(priv->wlan_dev.netdev);
380 netif_stop_queue(priv->mesh_dev);
382 if (libertas_process_tx(priv, skb) == 0)
383 dev->trans_start = jiffies;
385 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
390 * @brief Mark mesh packets and handover them to wlan_hard_start_xmit
393 static int mesh_pre_start_xmit(struct sk_buff *skb, struct net_device *dev)
395 wlan_private *priv = dev->priv;
398 lbs_deb_enter(LBS_DEB_MESH);
402 ret = wlan_hard_start_xmit(skb, priv->wlan_dev.netdev);
403 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
408 * @brief Mark non-mesh packets and handover them to wlan_hard_start_xmit
411 static int wlan_pre_start_xmit(struct sk_buff *skb, struct net_device *dev)
415 lbs_deb_enter(LBS_DEB_NET);
417 UNSET_MESH_FRAME(skb);
419 ret = wlan_hard_start_xmit(skb, dev);
420 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
424 static void wlan_tx_timeout(struct net_device *dev)
426 wlan_private *priv = (wlan_private *) dev->priv;
428 lbs_deb_enter(LBS_DEB_TX);
430 lbs_pr_err("tx watch dog timeout\n");
432 priv->wlan_dev.dnld_sent = DNLD_RES_RECEIVED;
433 dev->trans_start = jiffies;
435 if (priv->adapter->currenttxskb) {
436 if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
437 /* If we are here, we have not received feedback from
438 the previous packet. Assume TX_FAIL and move on. */
439 priv->adapter->eventcause = 0x01000000;
440 libertas_send_tx_feedback(priv);
442 wake_up_interruptible(&priv->mainthread.waitq);
443 } else if (priv->adapter->connect_status == libertas_connected) {
444 netif_wake_queue(priv->wlan_dev.netdev);
445 netif_wake_queue(priv->mesh_dev);
448 lbs_deb_leave(LBS_DEB_TX);
452 * @brief This function returns the network statistics
454 * @param dev A pointer to wlan_private structure
455 * @return A pointer to net_device_stats structure
457 static struct net_device_stats *wlan_get_stats(struct net_device *dev)
459 wlan_private *priv = (wlan_private *) dev->priv;
464 static int wlan_set_mac_address(struct net_device *dev, void *addr)
467 wlan_private *priv = (wlan_private *) dev->priv;
468 wlan_adapter *adapter = priv->adapter;
469 struct sockaddr *phwaddr = addr;
471 lbs_deb_enter(LBS_DEB_NET);
473 memset(adapter->current_addr, 0, ETH_ALEN);
475 /* dev->dev_addr is 8 bytes */
476 lbs_dbg_hex("dev->dev_addr:", dev->dev_addr, ETH_ALEN);
478 lbs_dbg_hex("addr:", phwaddr->sa_data, ETH_ALEN);
479 memcpy(adapter->current_addr, phwaddr->sa_data, ETH_ALEN);
481 ret = libertas_prepare_and_send_command(priv, cmd_802_11_mac_address,
483 cmd_option_waitforrsp, 0, NULL);
486 lbs_deb_net("set MAC address failed\n");
491 lbs_dbg_hex("adapter->macaddr:", adapter->current_addr, ETH_ALEN);
492 memcpy(dev->dev_addr, adapter->current_addr, ETH_ALEN);
494 memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
497 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
501 static int wlan_copy_multicast_address(wlan_adapter * adapter,
502 struct net_device *dev)
505 struct dev_mc_list *mcptr = dev->mc_list;
507 for (i = 0; i < dev->mc_count; i++) {
508 memcpy(&adapter->multicastlist[i], mcptr->dmi_addr, ETH_ALEN);
516 static void wlan_set_multicast_list(struct net_device *dev)
518 wlan_private *priv = dev->priv;
519 wlan_adapter *adapter = priv->adapter;
522 lbs_deb_enter(LBS_DEB_NET);
524 oldpacketfilter = adapter->currentpacketfilter;
526 if (dev->flags & IFF_PROMISC) {
527 lbs_deb_net("enable promiscuous mode\n");
528 adapter->currentpacketfilter |=
529 cmd_act_mac_promiscuous_enable;
530 adapter->currentpacketfilter &=
531 ~(cmd_act_mac_all_multicast_enable |
532 cmd_act_mac_multicast_enable);
535 adapter->currentpacketfilter &=
536 ~cmd_act_mac_promiscuous_enable;
538 if (dev->flags & IFF_ALLMULTI || dev->mc_count >
539 MRVDRV_MAX_MULTICAST_LIST_SIZE) {
540 lbs_deb_net( "enabling all multicast\n");
541 adapter->currentpacketfilter |=
542 cmd_act_mac_all_multicast_enable;
543 adapter->currentpacketfilter &=
544 ~cmd_act_mac_multicast_enable;
546 adapter->currentpacketfilter &=
547 ~cmd_act_mac_all_multicast_enable;
549 if (!dev->mc_count) {
550 lbs_deb_net("no multicast addresses, "
551 "disabling multicast\n");
552 adapter->currentpacketfilter &=
553 ~cmd_act_mac_multicast_enable;
557 adapter->currentpacketfilter |=
558 cmd_act_mac_multicast_enable;
560 adapter->nr_of_multicastmacaddr =
561 wlan_copy_multicast_address(adapter, dev);
563 lbs_deb_net("multicast addresses: %d\n",
566 for (i = 0; i < dev->mc_count; i++) {
567 lbs_deb_net("Multicast address %d:"
569 adapter->multicastlist[i][0],
570 adapter->multicastlist[i][1],
571 adapter->multicastlist[i][2],
572 adapter->multicastlist[i][3],
573 adapter->multicastlist[i][4],
574 adapter->multicastlist[i][5]);
576 /* send multicast addresses to firmware */
577 libertas_prepare_and_send_command(priv,
578 cmd_mac_multicast_adr,
585 if (adapter->currentpacketfilter != oldpacketfilter) {
586 libertas_set_mac_packet_filter(priv);
589 lbs_deb_leave(LBS_DEB_NET);
593 * @brief This function handles the major jobs in the WLAN driver.
594 * It handles all events generated by firmware, RX data received
595 * from firmware and TX data sent from kernel.
597 * @param data A pointer to wlan_thread structure
600 static int wlan_service_main_thread(void *data)
602 struct wlan_thread *thread = data;
603 wlan_private *priv = thread->priv;
604 wlan_adapter *adapter = priv->adapter;
608 lbs_deb_enter(LBS_DEB_THREAD);
610 wlan_activate_thread(thread);
612 init_waitqueue_entry(&wait, current);
615 lbs_deb_thread( "main-thread 111: intcounter=%d "
616 "currenttxskb=%p dnld_sent=%d\n",
618 adapter->currenttxskb, priv->wlan_dev.dnld_sent);
620 add_wait_queue(&thread->waitq, &wait);
621 set_current_state(TASK_INTERRUPTIBLE);
622 spin_lock_irq(&adapter->driver_lock);
623 if ((adapter->psstate == PS_STATE_SLEEP) ||
624 (!adapter->intcounter
625 && (priv->wlan_dev.dnld_sent || adapter->cur_cmd ||
626 list_empty(&adapter->cmdpendingq)))) {
628 "main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
629 adapter->connect_status, adapter->intcounter,
630 adapter->psmode, adapter->psstate);
631 spin_unlock_irq(&adapter->driver_lock);
634 spin_unlock_irq(&adapter->driver_lock);
638 "main-thread 222 (waking up): intcounter=%d currenttxskb=%p "
639 "dnld_sent=%d\n", adapter->intcounter,
640 adapter->currenttxskb, priv->wlan_dev.dnld_sent);
642 set_current_state(TASK_RUNNING);
643 remove_wait_queue(&thread->waitq, &wait);
646 lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p "
649 adapter->currenttxskb, priv->wlan_dev.dnld_sent);
651 if (kthread_should_stop()
652 || adapter->surpriseremoved) {
654 "main-thread: break from main thread: surpriseremoved=0x%x\n",
655 adapter->surpriseremoved);
660 spin_lock_irq(&adapter->driver_lock);
661 if (adapter->intcounter) {
663 adapter->intcounter = 0;
664 int_status = libertas_sbi_get_int_status(priv, &ireg);
668 "main-thread: reading HOST_INT_STATUS_REG failed\n");
669 spin_unlock_irq(&adapter->driver_lock);
672 adapter->hisregcpy |= ireg;
675 lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p "
678 adapter->currenttxskb, priv->wlan_dev.dnld_sent);
680 /* command response? */
681 if (adapter->hisregcpy & his_cmdupldrdy) {
682 lbs_deb_thread("main-thread: cmd response ready\n");
684 adapter->hisregcpy &= ~his_cmdupldrdy;
685 spin_unlock_irq(&adapter->driver_lock);
686 libertas_process_rx_command(priv);
687 spin_lock_irq(&adapter->driver_lock);
691 if (adapter->hisregcpy & his_cardevent) {
692 lbs_deb_thread("main-thread: Card Event Activity\n");
694 adapter->hisregcpy &= ~his_cardevent;
696 if (libertas_sbi_read_event_cause(priv)) {
698 "main-thread: libertas_sbi_read_event_cause failed\n");
699 spin_unlock_irq(&adapter->driver_lock);
702 spin_unlock_irq(&adapter->driver_lock);
703 libertas_process_event(priv);
705 spin_unlock_irq(&adapter->driver_lock);
707 /* Check if we need to confirm Sleep Request received previously */
708 if (adapter->psstate == PS_STATE_PRE_SLEEP) {
709 if (!priv->wlan_dev.dnld_sent && !adapter->cur_cmd) {
710 if (adapter->connect_status ==
711 libertas_connected) {
713 "main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p "
714 "dnld_sent=%d cur_cmd=%p, confirm now\n",
716 adapter->currenttxskb,
717 priv->wlan_dev.dnld_sent,
720 libertas_ps_confirm_sleep(priv,
721 (u16) adapter->psmode);
723 /* workaround for firmware sending
724 * deauth/linkloss event immediately
725 * after sleep request, remove this
726 * after firmware fixes it
728 adapter->psstate = PS_STATE_AWAKE;
730 "main-thread: ignore PS_SleepConfirm in non-connected state\n");
735 /* The PS state is changed during processing of Sleep Request
738 if ((priv->adapter->psstate == PS_STATE_SLEEP) ||
739 (priv->adapter->psstate == PS_STATE_PRE_SLEEP))
742 /* Execute the next command */
743 if (!priv->wlan_dev.dnld_sent && !priv->adapter->cur_cmd)
744 libertas_execute_next_command(priv);
746 /* Wake-up command waiters which can't sleep in
747 * libertas_prepare_and_send_command
749 if (!adapter->nr_cmd_pending)
750 wake_up_all(&adapter->cmd_pending);
752 libertas_tx_runqueue(priv);
755 del_timer(&adapter->command_timer);
756 adapter->nr_cmd_pending = 0;
757 wake_up_all(&adapter->cmd_pending);
758 wlan_deactivate_thread(thread);
760 lbs_deb_leave(LBS_DEB_THREAD);
765 * @brief This function adds the card. it will probe the
766 * card, allocate the wlan_priv and initialize the device.
768 * @param card A pointer to card
769 * @return A pointer to wlan_private structure
771 wlan_private *wlan_add_card(void *card)
773 struct net_device *dev = NULL;
774 wlan_private *priv = NULL;
776 lbs_deb_enter(LBS_DEB_NET);
778 /* Allocate an Ethernet device and register it */
779 if (!(dev = alloc_etherdev(sizeof(wlan_private)))) {
780 lbs_pr_err("init ethX device failed\n");
785 /* allocate buffer for wlan_adapter */
786 if (!(priv->adapter = kzalloc(sizeof(wlan_adapter), GFP_KERNEL))) {
787 lbs_pr_err("allocate buffer for wlan_adapter failed\n");
791 priv->wlan_dev.netdev = dev;
792 priv->wlan_dev.card = card;
794 priv->infra_open = 0;
796 SET_MODULE_OWNER(dev);
798 /* Setup the OS Interface to our functions */
799 dev->open = wlan_open;
800 dev->hard_start_xmit = wlan_pre_start_xmit;
801 dev->stop = wlan_close;
802 dev->do_ioctl = libertas_do_ioctl;
803 dev->set_mac_address = wlan_set_mac_address;
804 dev->tx_timeout = wlan_tx_timeout;
805 dev->get_stats = wlan_get_stats;
806 dev->watchdog_timeo = 5 * HZ;
807 dev->ethtool_ops = &libertas_ethtool_ops;
809 dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def;
811 #define NETIF_F_DYNALLOC 16
812 dev->features |= NETIF_F_DYNALLOC;
813 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
814 dev->set_multicast_list = wlan_set_multicast_list;
816 INIT_LIST_HEAD(&priv->adapter->cmdfreeq);
817 INIT_LIST_HEAD(&priv->adapter->cmdpendingq);
819 spin_lock_init(&priv->adapter->driver_lock);
820 init_waitqueue_head(&priv->adapter->cmd_pending);
821 priv->adapter->nr_cmd_pending = 0;
827 lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv);
831 int libertas_activate_card(wlan_private *priv)
833 struct net_device *dev = priv->wlan_dev.netdev;
836 lbs_deb_enter(LBS_DEB_MAIN);
838 lbs_deb_thread("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_err("failed to register WLAN device\n");
854 goto err_registerdev;
858 if (libertas_init_fw(priv)) {
859 lbs_pr_err("firmware init failed\n");
860 goto err_registerdev;
863 if (register_netdev(dev)) {
864 lbs_pr_err("cannot register ethX device\n");
868 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
870 libertas_debugfs_init_one(priv, dev);
876 libertas_sbi_unregister_dev(priv);
878 destroy_workqueue(priv->assoc_thread);
879 /* Stop the thread servicing the interrupts */
880 wake_up_interruptible(&priv->mainthread.waitq);
881 wlan_terminate_thread(&priv->mainthread);
882 kfree(priv->adapter);
885 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
890 * @brief This function adds mshX interface
892 * @param priv A pointer to the wlan_private structure
893 * @return 0 if successful, -X otherwise
895 int wlan_add_mesh(wlan_private *priv)
897 struct net_device *mesh_dev = NULL;
900 lbs_deb_enter(LBS_DEB_MESH);
902 /* Allocate a virtual mesh device */
903 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
904 lbs_deb_mesh("init mshX device failed\n");
908 mesh_dev->priv = priv;
909 priv->mesh_dev = mesh_dev;
911 SET_MODULE_OWNER(mesh_dev);
913 mesh_dev->open = mesh_open;
914 mesh_dev->hard_start_xmit = mesh_pre_start_xmit;
915 mesh_dev->stop = mesh_close;
916 mesh_dev->do_ioctl = libertas_do_ioctl;
917 mesh_dev->get_stats = wlan_get_stats;
918 mesh_dev->ethtool_ops = &libertas_ethtool_ops;
919 memcpy(mesh_dev->dev_addr, priv->wlan_dev.netdev->dev_addr,
920 sizeof(priv->wlan_dev.netdev->dev_addr));
923 mesh_dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def;
925 #define NETIF_F_DYNALLOC 16
927 /* Register virtual mesh interface */
928 ret = register_netdev(mesh_dev);
930 lbs_pr_err("cannot register mshX virtual interface\n");
934 ret = device_create_file(&(mesh_dev->dev), &dev_attr_libertas_mpp);
938 /* Everything successful */
944 unregister_netdev(mesh_dev);
947 free_netdev(mesh_dev);
950 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
954 static void wake_pending_cmdnodes(wlan_private *priv)
956 struct cmd_ctrl_node *cmdnode;
959 lbs_deb_enter(LBS_DEB_CMD);
961 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
962 list_for_each_entry(cmdnode, &priv->adapter->cmdpendingq, list) {
963 cmdnode->cmdwaitqwoken = 1;
964 wake_up_interruptible(&cmdnode->cmdwait_q);
966 spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
970 int wlan_remove_card(wlan_private *priv)
972 wlan_adapter *adapter;
973 struct net_device *dev;
974 union iwreq_data wrqu;
976 lbs_deb_enter(LBS_DEB_NET);
981 adapter = priv->adapter;
986 dev = priv->wlan_dev.netdev;
988 netif_stop_queue(priv->wlan_dev.netdev);
989 netif_carrier_off(priv->wlan_dev.netdev);
991 wake_pending_cmdnodes(priv);
993 unregister_netdev(dev);
995 cancel_delayed_work(&priv->assoc_work);
996 destroy_workqueue(priv->assoc_thread);
998 if (adapter->psmode == wlan802_11powermodemax_psp) {
999 adapter->psmode = wlan802_11powermodecam;
1000 libertas_ps_wakeup(priv, cmd_option_waitforrsp);
1003 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
1004 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1005 wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL);
1007 adapter->surpriseremoved = 1;
1009 /* Stop the thread servicing the interrupts */
1010 wlan_terminate_thread(&priv->mainthread);
1012 libertas_debugfs_remove_one(priv);
1014 lbs_deb_net("free adapter\n");
1015 libertas_free_adapter(priv);
1017 lbs_deb_net("unregister finish\n");
1019 priv->wlan_dev.netdev = NULL;
1023 lbs_deb_leave(LBS_DEB_NET);
1027 void wlan_remove_mesh(wlan_private *priv)
1029 struct net_device *mesh_dev;
1031 lbs_deb_enter(LBS_DEB_NET);
1036 mesh_dev = priv->mesh_dev;
1038 netif_stop_queue(mesh_dev);
1039 netif_carrier_off(priv->mesh_dev);
1041 device_remove_file(&(mesh_dev->dev), &dev_attr_libertas_mpp);
1042 unregister_netdev(mesh_dev);
1044 priv->mesh_dev = NULL ;
1045 free_netdev(mesh_dev);
1048 lbs_deb_leave(LBS_DEB_NET);
1052 * @brief This function finds the CFP in
1053 * region_cfp_table based on region and band parameter.
1055 * @param region The region code
1056 * @param band The band
1057 * @param cfp_no A pointer to CFP number
1058 * @return A pointer to CFP
1060 struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band, int *cfp_no)
1064 lbs_deb_enter(LBS_DEB_MAIN);
1066 end = sizeof(region_cfp_table)/sizeof(struct region_cfp_table);
1068 for (i = 0; i < end ; i++) {
1069 lbs_deb_main("region_cfp_table[i].region=%d\n",
1070 region_cfp_table[i].region);
1071 if (region_cfp_table[i].region == region) {
1072 *cfp_no = region_cfp_table[i].cfp_no_BG;
1073 lbs_deb_leave(LBS_DEB_MAIN);
1074 return region_cfp_table[i].cfp_BG;
1078 lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
1082 int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band)
1084 wlan_adapter *adapter = priv->adapter;
1088 struct chan_freq_power *cfp;
1091 lbs_deb_enter(LBS_DEB_MAIN);
1093 memset(adapter->region_channel, 0, sizeof(adapter->region_channel));
1096 cfp = libertas_get_region_cfp_table(region, band, &cfp_no);
1098 adapter->region_channel[i].nrcfp = cfp_no;
1099 adapter->region_channel[i].CFP = cfp;
1101 lbs_deb_main("wrong region code %#x in band B/G\n",
1106 adapter->region_channel[i].valid = 1;
1107 adapter->region_channel[i].region = region;
1108 adapter->region_channel[i].band = band;
1112 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1117 * @brief This function handles the interrupt. it will change PS
1118 * state if applicable. it will wake up main_thread to handle
1119 * the interrupt event as well.
1121 * @param dev A pointer to net_device structure
1124 void libertas_interrupt(struct net_device *dev)
1126 wlan_private *priv = dev->priv;
1128 lbs_deb_enter(LBS_DEB_THREAD);
1130 lbs_deb_thread("libertas_interrupt: intcounter=%d\n",
1131 priv->adapter->intcounter);
1133 priv->adapter->intcounter++;
1135 if (priv->adapter->psstate == PS_STATE_SLEEP) {
1136 priv->adapter->psstate = PS_STATE_AWAKE;
1137 netif_wake_queue(dev);
1138 netif_wake_queue(priv->mesh_dev);
1141 wake_up_interruptible(&priv->mainthread.waitq);
1143 lbs_deb_leave(LBS_DEB_THREAD);
1146 static int wlan_init_module(void)
1150 lbs_deb_enter(LBS_DEB_MAIN);
1152 if (libertas_fw_name == NULL) {
1153 libertas_fw_name = default_fw_name;
1156 libertas_debugfs_init();
1158 if (libertas_sbi_register()) {
1160 libertas_debugfs_remove();
1163 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1167 static void wlan_cleanup_module(void)
1169 lbs_deb_enter(LBS_DEB_MAIN);
1171 libertas_sbi_unregister();
1172 libertas_debugfs_remove();
1174 lbs_deb_leave(LBS_DEB_MAIN);
1177 module_init(wlan_init_module);
1178 module_exit(wlan_cleanup_module);
1180 MODULE_DESCRIPTION("M-WLAN Driver");
1181 MODULE_AUTHOR("Marvell International Ltd.");
1182 MODULE_LICENSE("GPL");