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/etherdevice.h>
10 #include <linux/netdevice.h>
11 #include <linux/if_arp.h>
12 #include <linux/kthread.h>
13 #include <linux/kfifo.h>
14 //#include <asm/olpc.h>
16 #include <net/iw_handler.h>
17 #include <net/ieee80211.h>
29 #define DRIVER_RELEASE_VERSION "323.p0"
30 const char lbs_driver_version
[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
37 /* Module parameters */
38 unsigned int lbs_debug
;
39 EXPORT_SYMBOL_GPL(lbs_debug
);
40 module_param_named(libertas_debug
, lbs_debug
, int, 0644);
43 /* This global structure is used to send the confirm_sleep command as
44 * fast as possible down to the firmware. */
45 struct cmd_confirm_sleep confirm_sleep
;
48 #define LBS_TX_PWR_DEFAULT 20 /*100mW */
49 #define LBS_TX_PWR_US_DEFAULT 20 /*100mW */
50 #define LBS_TX_PWR_JP_DEFAULT 16 /*50mW */
51 #define LBS_TX_PWR_FR_DEFAULT 20 /*100mW */
52 #define LBS_TX_PWR_EMEA_DEFAULT 20 /*100mW */
54 /* Format { channel, frequency (MHz), maxtxpower } */
55 /* band: 'B/G', region: USA FCC/Canada IC */
56 static struct chan_freq_power channel_freq_power_US_BG
[] = {
57 {1, 2412, LBS_TX_PWR_US_DEFAULT
},
58 {2, 2417, LBS_TX_PWR_US_DEFAULT
},
59 {3, 2422, LBS_TX_PWR_US_DEFAULT
},
60 {4, 2427, LBS_TX_PWR_US_DEFAULT
},
61 {5, 2432, LBS_TX_PWR_US_DEFAULT
},
62 {6, 2437, LBS_TX_PWR_US_DEFAULT
},
63 {7, 2442, LBS_TX_PWR_US_DEFAULT
},
64 {8, 2447, LBS_TX_PWR_US_DEFAULT
},
65 {9, 2452, LBS_TX_PWR_US_DEFAULT
},
66 {10, 2457, LBS_TX_PWR_US_DEFAULT
},
67 {11, 2462, LBS_TX_PWR_US_DEFAULT
}
70 /* band: 'B/G', region: Europe ETSI */
71 static struct chan_freq_power channel_freq_power_EU_BG
[] = {
72 {1, 2412, LBS_TX_PWR_EMEA_DEFAULT
},
73 {2, 2417, LBS_TX_PWR_EMEA_DEFAULT
},
74 {3, 2422, LBS_TX_PWR_EMEA_DEFAULT
},
75 {4, 2427, LBS_TX_PWR_EMEA_DEFAULT
},
76 {5, 2432, LBS_TX_PWR_EMEA_DEFAULT
},
77 {6, 2437, LBS_TX_PWR_EMEA_DEFAULT
},
78 {7, 2442, LBS_TX_PWR_EMEA_DEFAULT
},
79 {8, 2447, LBS_TX_PWR_EMEA_DEFAULT
},
80 {9, 2452, LBS_TX_PWR_EMEA_DEFAULT
},
81 {10, 2457, LBS_TX_PWR_EMEA_DEFAULT
},
82 {11, 2462, LBS_TX_PWR_EMEA_DEFAULT
},
83 {12, 2467, LBS_TX_PWR_EMEA_DEFAULT
},
84 {13, 2472, LBS_TX_PWR_EMEA_DEFAULT
}
87 /* band: 'B/G', region: Spain */
88 static struct chan_freq_power channel_freq_power_SPN_BG
[] = {
89 {10, 2457, LBS_TX_PWR_DEFAULT
},
90 {11, 2462, LBS_TX_PWR_DEFAULT
}
93 /* band: 'B/G', region: France */
94 static struct chan_freq_power channel_freq_power_FR_BG
[] = {
95 {10, 2457, LBS_TX_PWR_FR_DEFAULT
},
96 {11, 2462, LBS_TX_PWR_FR_DEFAULT
},
97 {12, 2467, LBS_TX_PWR_FR_DEFAULT
},
98 {13, 2472, LBS_TX_PWR_FR_DEFAULT
}
101 /* band: 'B/G', region: Japan */
102 static struct chan_freq_power channel_freq_power_JPN_BG
[] = {
103 {1, 2412, LBS_TX_PWR_JP_DEFAULT
},
104 {2, 2417, LBS_TX_PWR_JP_DEFAULT
},
105 {3, 2422, LBS_TX_PWR_JP_DEFAULT
},
106 {4, 2427, LBS_TX_PWR_JP_DEFAULT
},
107 {5, 2432, LBS_TX_PWR_JP_DEFAULT
},
108 {6, 2437, LBS_TX_PWR_JP_DEFAULT
},
109 {7, 2442, LBS_TX_PWR_JP_DEFAULT
},
110 {8, 2447, LBS_TX_PWR_JP_DEFAULT
},
111 {9, 2452, LBS_TX_PWR_JP_DEFAULT
},
112 {10, 2457, LBS_TX_PWR_JP_DEFAULT
},
113 {11, 2462, LBS_TX_PWR_JP_DEFAULT
},
114 {12, 2467, LBS_TX_PWR_JP_DEFAULT
},
115 {13, 2472, LBS_TX_PWR_JP_DEFAULT
},
116 {14, 2484, LBS_TX_PWR_JP_DEFAULT
}
120 * the structure for channel, frequency and power
122 struct region_cfp_table
{
124 struct chan_freq_power
*cfp_BG
;
129 * the structure for the mapping between region and CFP
131 static struct region_cfp_table region_cfp_table
[] = {
133 channel_freq_power_US_BG
,
134 ARRAY_SIZE(channel_freq_power_US_BG
),
137 {0x20, /*CANADA IC */
138 channel_freq_power_US_BG
,
139 ARRAY_SIZE(channel_freq_power_US_BG
),
142 {0x30, /*EU*/ channel_freq_power_EU_BG
,
143 ARRAY_SIZE(channel_freq_power_EU_BG
),
146 {0x31, /*SPAIN*/ channel_freq_power_SPN_BG
,
147 ARRAY_SIZE(channel_freq_power_SPN_BG
),
150 {0x32, /*FRANCE*/ channel_freq_power_FR_BG
,
151 ARRAY_SIZE(channel_freq_power_FR_BG
),
154 {0x40, /*JAPAN*/ channel_freq_power_JPN_BG
,
155 ARRAY_SIZE(channel_freq_power_JPN_BG
),
158 /*Add new region here */
162 * the table to keep region code
164 u16 lbs_region_code_to_index
[MRVDRV_MAX_REGION_CODE
] =
165 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
168 * 802.11b/g supported bitrates (in 500Kb/s units)
170 u8 lbs_bg_rates
[MAX_RATES
] =
171 { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
175 * FW rate table. FW refers to rates by their index in this table, not by the
176 * rate value itself. Values of 0x00 are
177 * reserved positions.
179 static u8 fw_data_rates
[MAX_RATES
] =
180 { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
181 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
185 * @brief use index to get the data rate
187 * @param idx The index of data rate
188 * @return data rate or 0
190 u32
lbs_fw_index_to_data_rate(u8 idx
)
192 if (idx
>= sizeof(fw_data_rates
))
194 return fw_data_rates
[idx
];
198 * @brief use rate to get the index
200 * @param rate data rate
203 u8
lbs_data_rate_to_fw_index(u32 rate
)
210 for (i
= 0; i
< sizeof(fw_data_rates
); i
++) {
211 if (rate
== fw_data_rates
[i
])
218 * Attributes exported through sysfs
222 * @brief Get function for sysfs attribute anycast_mask
224 static ssize_t
lbs_anycast_get(struct device
*dev
,
225 struct device_attribute
*attr
, char * buf
)
227 struct lbs_private
*priv
= to_net_dev(dev
)->priv
;
228 struct cmd_ds_mesh_access mesh_access
;
231 memset(&mesh_access
, 0, sizeof(mesh_access
));
233 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_GET_ANYCAST
, &mesh_access
);
237 return snprintf(buf
, 12, "0x%X\n", le32_to_cpu(mesh_access
.data
[0]));
241 * @brief Set function for sysfs attribute anycast_mask
243 static ssize_t
lbs_anycast_set(struct device
*dev
,
244 struct device_attribute
*attr
, const char * buf
, size_t count
)
246 struct lbs_private
*priv
= to_net_dev(dev
)->priv
;
247 struct cmd_ds_mesh_access mesh_access
;
251 memset(&mesh_access
, 0, sizeof(mesh_access
));
252 sscanf(buf
, "%x", &datum
);
253 mesh_access
.data
[0] = cpu_to_le32(datum
);
255 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_ANYCAST
, &mesh_access
);
262 static int lbs_add_rtap(struct lbs_private
*priv
);
263 static void lbs_remove_rtap(struct lbs_private
*priv
);
264 static int lbs_add_mesh(struct lbs_private
*priv
);
265 static void lbs_remove_mesh(struct lbs_private
*priv
);
269 * Get function for sysfs attribute rtap
271 static ssize_t
lbs_rtap_get(struct device
*dev
,
272 struct device_attribute
*attr
, char * buf
)
274 struct lbs_private
*priv
= to_net_dev(dev
)->priv
;
275 return snprintf(buf
, 5, "0x%X\n", priv
->monitormode
);
279 * Set function for sysfs attribute rtap
281 static ssize_t
lbs_rtap_set(struct device
*dev
,
282 struct device_attribute
*attr
, const char * buf
, size_t count
)
285 struct lbs_private
*priv
= to_net_dev(dev
)->priv
;
287 sscanf(buf
, "%x", &monitor_mode
);
289 if (priv
->monitormode
== monitor_mode
)
291 if (!priv
->monitormode
) {
292 if (priv
->infra_open
|| priv
->mesh_open
)
294 if (priv
->mode
== IW_MODE_INFRA
)
295 lbs_send_deauthentication(priv
);
296 else if (priv
->mode
== IW_MODE_ADHOC
)
297 lbs_stop_adhoc_network(priv
);
300 priv
->monitormode
= monitor_mode
;
304 if (!priv
->monitormode
)
306 priv
->monitormode
= 0;
307 lbs_remove_rtap(priv
);
309 if (priv
->currenttxskb
) {
310 dev_kfree_skb_any(priv
->currenttxskb
);
311 priv
->currenttxskb
= NULL
;
314 /* Wake queues, command thread, etc. */
315 lbs_host_to_card_done(priv
);
318 lbs_prepare_and_send_command(priv
,
319 CMD_802_11_MONITOR_MODE
, CMD_ACT_SET
,
320 CMD_OPTION_WAITFORRSP
, 0, &priv
->monitormode
);
325 * lbs_rtap attribute to be exported per ethX interface
326 * through sysfs (/sys/class/net/ethX/lbs_rtap)
328 static DEVICE_ATTR(lbs_rtap
, 0644, lbs_rtap_get
, lbs_rtap_set
);
331 * Get function for sysfs attribute mesh
333 static ssize_t
lbs_mesh_get(struct device
*dev
,
334 struct device_attribute
*attr
, char * buf
)
336 struct lbs_private
*priv
= to_net_dev(dev
)->priv
;
337 return snprintf(buf
, 5, "0x%X\n", !!priv
->mesh_dev
);
341 * Set function for sysfs attribute mesh
343 static ssize_t
lbs_mesh_set(struct device
*dev
,
344 struct device_attribute
*attr
, const char * buf
, size_t count
)
346 struct lbs_private
*priv
= to_net_dev(dev
)->priv
;
350 sscanf(buf
, "%x", &enable
);
352 if (enable
== !!priv
->mesh_dev
)
355 ret
= lbs_mesh_config(priv
, enable
, priv
->curbssparams
.channel
);
362 lbs_remove_mesh(priv
);
368 * lbs_mesh attribute to be exported per ethX interface
369 * through sysfs (/sys/class/net/ethX/lbs_mesh)
371 static DEVICE_ATTR(lbs_mesh
, 0644, lbs_mesh_get
, lbs_mesh_set
);
374 * anycast_mask attribute to be exported per mshX interface
375 * through sysfs (/sys/class/net/mshX/anycast_mask)
377 static DEVICE_ATTR(anycast_mask
, 0644, lbs_anycast_get
, lbs_anycast_set
);
379 static struct attribute
*lbs_mesh_sysfs_entries
[] = {
380 &dev_attr_anycast_mask
.attr
,
384 static struct attribute_group lbs_mesh_attr_group
= {
385 .attrs
= lbs_mesh_sysfs_entries
,
389 * @brief This function opens the ethX or mshX interface
391 * @param dev A pointer to net_device structure
392 * @return 0 or -EBUSY if monitor mode active
394 static int lbs_dev_open(struct net_device
*dev
)
396 struct lbs_private
*priv
= (struct lbs_private
*) dev
->priv
;
399 lbs_deb_enter(LBS_DEB_NET
);
401 spin_lock_irq(&priv
->driver_lock
);
403 if (priv
->monitormode
) {
408 if (dev
== priv
->mesh_dev
) {
410 priv
->mesh_connect_status
= LBS_CONNECTED
;
411 netif_carrier_on(dev
);
413 priv
->infra_open
= 1;
415 if (priv
->connect_status
== LBS_CONNECTED
)
416 netif_carrier_on(dev
);
418 netif_carrier_off(dev
);
421 if (!priv
->tx_pending_len
)
422 netif_wake_queue(dev
);
425 spin_unlock_irq(&priv
->driver_lock
);
426 lbs_deb_leave_args(LBS_DEB_NET
, "ret %d", ret
);
431 * @brief This function closes the mshX interface
433 * @param dev A pointer to net_device structure
436 static int lbs_mesh_stop(struct net_device
*dev
)
438 struct lbs_private
*priv
= (struct lbs_private
*) (dev
->priv
);
440 lbs_deb_enter(LBS_DEB_MESH
);
441 spin_lock_irq(&priv
->driver_lock
);
444 priv
->mesh_connect_status
= LBS_DISCONNECTED
;
446 netif_stop_queue(dev
);
447 netif_carrier_off(dev
);
449 spin_unlock_irq(&priv
->driver_lock
);
451 lbs_deb_leave(LBS_DEB_MESH
);
456 * @brief This function closes the ethX interface
458 * @param dev A pointer to net_device structure
461 static int lbs_eth_stop(struct net_device
*dev
)
463 struct lbs_private
*priv
= (struct lbs_private
*) dev
->priv
;
465 lbs_deb_enter(LBS_DEB_NET
);
467 spin_lock_irq(&priv
->driver_lock
);
468 priv
->infra_open
= 0;
469 netif_stop_queue(dev
);
470 spin_unlock_irq(&priv
->driver_lock
);
472 lbs_deb_leave(LBS_DEB_NET
);
476 static void lbs_tx_timeout(struct net_device
*dev
)
478 struct lbs_private
*priv
= (struct lbs_private
*) dev
->priv
;
480 lbs_deb_enter(LBS_DEB_TX
);
482 lbs_pr_err("tx watch dog timeout\n");
484 dev
->trans_start
= jiffies
;
486 if (priv
->currenttxskb
)
487 lbs_send_tx_feedback(priv
, 0);
489 /* XX: Shouldn't we also call into the hw-specific driver
490 to kick it somehow? */
491 lbs_host_to_card_done(priv
);
493 /* More often than not, this actually happens because the
494 firmware has crapped itself -- rather than just a very
495 busy medium. So send a harmless command, and if/when
496 _that_ times out, we'll kick it in the head. */
497 lbs_prepare_and_send_command(priv
, CMD_802_11_RSSI
, 0,
500 lbs_deb_leave(LBS_DEB_TX
);
503 void lbs_host_to_card_done(struct lbs_private
*priv
)
507 lbs_deb_enter(LBS_DEB_THREAD
);
509 spin_lock_irqsave(&priv
->driver_lock
, flags
);
511 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
513 /* Wake main thread if commands are pending */
514 if (!priv
->cur_cmd
|| priv
->tx_pending_len
> 0)
515 wake_up_interruptible(&priv
->waitq
);
517 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
518 lbs_deb_leave(LBS_DEB_THREAD
);
520 EXPORT_SYMBOL_GPL(lbs_host_to_card_done
);
523 * @brief This function returns the network statistics
525 * @param dev A pointer to struct lbs_private structure
526 * @return A pointer to net_device_stats structure
528 static struct net_device_stats
*lbs_get_stats(struct net_device
*dev
)
530 struct lbs_private
*priv
= (struct lbs_private
*) dev
->priv
;
532 lbs_deb_enter(LBS_DEB_NET
);
536 static int lbs_set_mac_address(struct net_device
*dev
, void *addr
)
539 struct lbs_private
*priv
= (struct lbs_private
*) dev
->priv
;
540 struct sockaddr
*phwaddr
= addr
;
541 struct cmd_ds_802_11_mac_address cmd
;
543 lbs_deb_enter(LBS_DEB_NET
);
545 /* In case it was called from the mesh device */
548 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
549 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
550 memcpy(cmd
.macadd
, phwaddr
->sa_data
, ETH_ALEN
);
552 ret
= lbs_cmd_with_response(priv
, CMD_802_11_MAC_ADDRESS
, &cmd
);
554 lbs_deb_net("set MAC address failed\n");
558 memcpy(priv
->current_addr
, phwaddr
->sa_data
, ETH_ALEN
);
559 memcpy(dev
->dev_addr
, phwaddr
->sa_data
, ETH_ALEN
);
561 memcpy(priv
->mesh_dev
->dev_addr
, phwaddr
->sa_data
, ETH_ALEN
);
564 lbs_deb_leave_args(LBS_DEB_NET
, "ret %d", ret
);
568 static int lbs_copy_multicast_address(struct lbs_private
*priv
,
569 struct net_device
*dev
)
572 struct dev_mc_list
*mcptr
= dev
->mc_list
;
574 for (i
= 0; i
< dev
->mc_count
; i
++) {
575 memcpy(&priv
->multicastlist
[i
], mcptr
->dmi_addr
, ETH_ALEN
);
581 static void lbs_set_multicast_list(struct net_device
*dev
)
583 struct lbs_private
*priv
= dev
->priv
;
585 DECLARE_MAC_BUF(mac
);
587 lbs_deb_enter(LBS_DEB_NET
);
589 old_mac_control
= priv
->mac_control
;
591 if (dev
->flags
& IFF_PROMISC
) {
592 lbs_deb_net("enable promiscuous mode\n");
594 CMD_ACT_MAC_PROMISCUOUS_ENABLE
;
596 ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE
|
597 CMD_ACT_MAC_MULTICAST_ENABLE
);
601 ~CMD_ACT_MAC_PROMISCUOUS_ENABLE
;
603 if (dev
->flags
& IFF_ALLMULTI
|| dev
->mc_count
>
604 MRVDRV_MAX_MULTICAST_LIST_SIZE
) {
605 lbs_deb_net( "enabling all multicast\n");
607 CMD_ACT_MAC_ALL_MULTICAST_ENABLE
;
609 ~CMD_ACT_MAC_MULTICAST_ENABLE
;
612 ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE
;
614 if (!dev
->mc_count
) {
615 lbs_deb_net("no multicast addresses, "
616 "disabling multicast\n");
618 ~CMD_ACT_MAC_MULTICAST_ENABLE
;
623 CMD_ACT_MAC_MULTICAST_ENABLE
;
625 priv
->nr_of_multicastmacaddr
=
626 lbs_copy_multicast_address(priv
, dev
);
628 lbs_deb_net("multicast addresses: %d\n",
631 for (i
= 0; i
< dev
->mc_count
; i
++) {
632 lbs_deb_net("Multicast address %d: %s\n",
634 priv
->multicastlist
[i
]));
636 /* send multicast addresses to firmware */
637 lbs_prepare_and_send_command(priv
,
638 CMD_MAC_MULTICAST_ADR
,
645 if (priv
->mac_control
!= old_mac_control
)
646 lbs_set_mac_control(priv
);
648 lbs_deb_leave(LBS_DEB_NET
);
652 * @brief This function handles the major jobs in the LBS driver.
653 * It handles all events generated by firmware, RX data received
654 * from firmware and TX data sent from kernel.
656 * @param data A pointer to lbs_thread structure
659 static int lbs_thread(void *data
)
661 struct net_device
*dev
= data
;
662 struct lbs_private
*priv
= dev
->priv
;
665 lbs_deb_enter(LBS_DEB_THREAD
);
667 init_waitqueue_entry(&wait
, current
);
673 lbs_deb_thread("1: currenttxskb %p, dnld_sent %d\n",
674 priv
->currenttxskb
, priv
->dnld_sent
);
676 add_wait_queue(&priv
->waitq
, &wait
);
677 set_current_state(TASK_INTERRUPTIBLE
);
678 spin_lock_irq(&priv
->driver_lock
);
680 if (kthread_should_stop())
681 shouldsleep
= 0; /* Bye */
682 else if (priv
->surpriseremoved
)
683 shouldsleep
= 1; /* We need to wait until we're _told_ to die */
684 else if (priv
->psstate
== PS_STATE_SLEEP
)
685 shouldsleep
= 1; /* Sleep mode. Nothing we can do till it wakes */
686 else if (priv
->cmd_timed_out
)
687 shouldsleep
= 0; /* Command timed out. Recover */
688 else if (!priv
->fw_ready
)
689 shouldsleep
= 1; /* Firmware not ready. We're waiting for it */
690 else if (priv
->dnld_sent
)
691 shouldsleep
= 1; /* Something is en route to the device already */
692 else if (priv
->tx_pending_len
> 0)
693 shouldsleep
= 0; /* We've a packet to send */
694 else if (priv
->cur_cmd
)
695 shouldsleep
= 1; /* Can't send a command; one already running */
696 else if (!list_empty(&priv
->cmdpendingq
))
697 shouldsleep
= 0; /* We have a command to send */
698 else if (__kfifo_len(priv
->event_fifo
))
699 shouldsleep
= 0; /* We have an event to process */
700 else if (priv
->resp_len
[priv
->resp_idx
])
701 shouldsleep
= 0; /* We have a command response */
703 shouldsleep
= 1; /* No command */
706 lbs_deb_thread("sleeping, connect_status %d, "
707 "ps_mode %d, ps_state %d\n",
708 priv
->connect_status
,
709 priv
->psmode
, priv
->psstate
);
710 spin_unlock_irq(&priv
->driver_lock
);
713 spin_unlock_irq(&priv
->driver_lock
);
715 lbs_deb_thread("2: currenttxskb %p, dnld_send %d\n",
716 priv
->currenttxskb
, priv
->dnld_sent
);
718 set_current_state(TASK_RUNNING
);
719 remove_wait_queue(&priv
->waitq
, &wait
);
721 lbs_deb_thread("3: currenttxskb %p, dnld_sent %d\n",
722 priv
->currenttxskb
, priv
->dnld_sent
);
724 if (kthread_should_stop()) {
725 lbs_deb_thread("break from main thread\n");
729 if (priv
->surpriseremoved
) {
730 lbs_deb_thread("adapter removed; waiting to die...\n");
734 lbs_deb_thread("4: currenttxskb %p, dnld_sent %d\n",
735 priv
->currenttxskb
, priv
->dnld_sent
);
737 /* Process any pending command response */
738 spin_lock_irq(&priv
->driver_lock
);
739 resp_idx
= priv
->resp_idx
;
740 if (priv
->resp_len
[resp_idx
]) {
741 spin_unlock_irq(&priv
->driver_lock
);
742 lbs_process_command_response(priv
,
743 priv
->resp_buf
[resp_idx
],
744 priv
->resp_len
[resp_idx
]);
745 spin_lock_irq(&priv
->driver_lock
);
746 priv
->resp_len
[resp_idx
] = 0;
748 spin_unlock_irq(&priv
->driver_lock
);
750 /* command timeout stuff */
751 if (priv
->cmd_timed_out
&& priv
->cur_cmd
) {
752 struct cmd_ctrl_node
*cmdnode
= priv
->cur_cmd
;
754 if (++priv
->nr_retries
> 10) {
755 lbs_pr_info("Excessive timeouts submitting command %x\n",
756 le16_to_cpu(cmdnode
->cmdbuf
->command
));
757 lbs_complete_command(priv
, cmdnode
, -ETIMEDOUT
);
758 priv
->nr_retries
= 0;
760 if (machine_is_olpc()) {
761 spin_unlock_irq(&priv
->driver_lock
);
762 printk(KERN_CRIT
"Resetting OLPC wireless via EC...\n");
763 olpc_ec_cmd(0x25, NULL
, 0, NULL
, 0);
764 spin_lock_irq(&priv
->driver_lock
);
768 priv
->cur_cmd
= NULL
;
769 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
770 lbs_pr_info("requeueing command %x due to timeout (#%d)\n",
771 le16_to_cpu(cmdnode
->cmdbuf
->command
), priv
->nr_retries
);
773 /* Stick it back at the _top_ of the pending queue
774 for immediate resubmission */
775 list_add(&cmdnode
->list
, &priv
->cmdpendingq
);
778 priv
->cmd_timed_out
= 0;
780 /* Process hardware events, e.g. card removed, link lost */
781 spin_lock_irq(&priv
->driver_lock
);
782 while (__kfifo_len(priv
->event_fifo
)) {
785 __kfifo_get(priv
->event_fifo
, (unsigned char *) &event
,
787 spin_unlock_irq(&priv
->driver_lock
);
788 lbs_process_event(priv
, event
);
789 spin_lock_irq(&priv
->driver_lock
);
791 spin_unlock_irq(&priv
->driver_lock
);
796 /* Check if we need to confirm Sleep Request received previously */
797 if (priv
->psstate
== PS_STATE_PRE_SLEEP
&&
798 !priv
->dnld_sent
&& !priv
->cur_cmd
) {
799 if (priv
->connect_status
== LBS_CONNECTED
) {
800 lbs_deb_thread("pre-sleep, currenttxskb %p, "
801 "dnld_sent %d, cur_cmd %p\n",
802 priv
->currenttxskb
, priv
->dnld_sent
,
805 lbs_ps_confirm_sleep(priv
);
807 /* workaround for firmware sending
808 * deauth/linkloss event immediately
809 * after sleep request; remove this
810 * after firmware fixes it
812 priv
->psstate
= PS_STATE_AWAKE
;
813 lbs_pr_alert("ignore PS_SleepConfirm in "
814 "non-connected state\n");
818 /* The PS state is changed during processing of Sleep Request
821 if ((priv
->psstate
== PS_STATE_SLEEP
) ||
822 (priv
->psstate
== PS_STATE_PRE_SLEEP
))
825 /* Execute the next command */
826 if (!priv
->dnld_sent
&& !priv
->cur_cmd
)
827 lbs_execute_next_command(priv
);
829 /* Wake-up command waiters which can't sleep in
830 * lbs_prepare_and_send_command
832 if (!list_empty(&priv
->cmdpendingq
))
833 wake_up_all(&priv
->cmd_pending
);
835 spin_lock_irq(&priv
->driver_lock
);
836 if (!priv
->dnld_sent
&& priv
->tx_pending_len
> 0) {
837 int ret
= priv
->hw_host_to_card(priv
, MVMS_DAT
,
838 priv
->tx_pending_buf
,
839 priv
->tx_pending_len
);
841 lbs_deb_tx("host_to_card failed %d\n", ret
);
842 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
844 priv
->tx_pending_len
= 0;
845 if (!priv
->currenttxskb
) {
846 /* We can wake the queues immediately if we aren't
847 waiting for TX feedback */
848 if (priv
->connect_status
== LBS_CONNECTED
)
849 netif_wake_queue(priv
->dev
);
850 if (priv
->mesh_dev
&&
851 priv
->mesh_connect_status
== LBS_CONNECTED
)
852 netif_wake_queue(priv
->mesh_dev
);
855 spin_unlock_irq(&priv
->driver_lock
);
858 del_timer(&priv
->command_timer
);
859 wake_up_all(&priv
->cmd_pending
);
861 lbs_deb_leave(LBS_DEB_THREAD
);
865 static int lbs_suspend_callback(struct lbs_private
*priv
, unsigned long dummy
,
866 struct cmd_header
*cmd
)
868 lbs_deb_enter(LBS_DEB_FW
);
870 netif_device_detach(priv
->dev
);
872 netif_device_detach(priv
->mesh_dev
);
875 lbs_deb_leave(LBS_DEB_FW
);
879 int lbs_suspend(struct lbs_private
*priv
)
881 struct cmd_header cmd
;
884 lbs_deb_enter(LBS_DEB_FW
);
886 if (priv
->wol_criteria
== 0xffffffff) {
887 lbs_pr_info("Suspend attempt without configuring wake params!\n");
891 memset(&cmd
, 0, sizeof(cmd
));
893 ret
= __lbs_cmd(priv
, CMD_802_11_HOST_SLEEP_ACTIVATE
, &cmd
,
894 sizeof(cmd
), lbs_suspend_callback
, 0);
896 lbs_pr_info("HOST_SLEEP_ACTIVATE failed: %d\n", ret
);
898 lbs_deb_leave_args(LBS_DEB_FW
, "ret %d", ret
);
901 EXPORT_SYMBOL_GPL(lbs_suspend
);
903 int lbs_resume(struct lbs_private
*priv
)
905 lbs_deb_enter(LBS_DEB_FW
);
909 /* Firmware doesn't seem to give us RX packets any more
910 until we send it some command. Might as well update */
911 lbs_prepare_and_send_command(priv
, CMD_802_11_RSSI
, 0,
914 netif_device_attach(priv
->dev
);
916 netif_device_attach(priv
->mesh_dev
);
918 lbs_deb_leave(LBS_DEB_FW
);
921 EXPORT_SYMBOL_GPL(lbs_resume
);
924 * @brief This function downloads firmware image, gets
925 * HW spec from firmware and set basic parameters to
928 * @param priv A pointer to struct lbs_private structure
931 static int lbs_setup_firmware(struct lbs_private
*priv
)
935 lbs_deb_enter(LBS_DEB_FW
);
938 * Read MAC address from HW
940 memset(priv
->current_addr
, 0xff, ETH_ALEN
);
941 ret
= lbs_update_hw_spec(priv
);
947 lbs_set_mac_control(priv
);
949 ret
= lbs_get_data_rate(priv
);
957 lbs_deb_leave_args(LBS_DEB_FW
, "ret %d", ret
);
962 * This function handles the timeout of command sending.
963 * It will re-send the same command again.
965 static void command_timer_fn(unsigned long data
)
967 struct lbs_private
*priv
= (struct lbs_private
*)data
;
970 lbs_deb_enter(LBS_DEB_CMD
);
971 spin_lock_irqsave(&priv
->driver_lock
, flags
);
973 if (!priv
->cur_cmd
) {
974 lbs_pr_info("Command timer expired; no pending command\n");
978 lbs_pr_info("Command %x timed out\n", le16_to_cpu(priv
->cur_cmd
->cmdbuf
->command
));
980 priv
->cmd_timed_out
= 1;
981 wake_up_interruptible(&priv
->waitq
);
983 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
984 lbs_deb_leave(LBS_DEB_CMD
);
987 static void lbs_sync_channel_worker(struct work_struct
*work
)
989 struct lbs_private
*priv
= container_of(work
, struct lbs_private
,
992 lbs_deb_enter(LBS_DEB_MAIN
);
993 if (lbs_update_channel(priv
))
994 lbs_pr_info("Channel synchronization failed.");
995 lbs_deb_leave(LBS_DEB_MAIN
);
999 static int lbs_init_adapter(struct lbs_private
*priv
)
1004 lbs_deb_enter(LBS_DEB_MAIN
);
1006 /* Allocate buffer to store the BSSID list */
1007 bufsize
= MAX_NETWORK_COUNT
* sizeof(struct bss_descriptor
);
1008 priv
->networks
= kzalloc(bufsize
, GFP_KERNEL
);
1009 if (!priv
->networks
) {
1010 lbs_pr_err("Out of memory allocating beacons\n");
1015 /* Initialize scan result lists */
1016 INIT_LIST_HEAD(&priv
->network_free_list
);
1017 INIT_LIST_HEAD(&priv
->network_list
);
1018 for (i
= 0; i
< MAX_NETWORK_COUNT
; i
++) {
1019 list_add_tail(&priv
->networks
[i
].list
,
1020 &priv
->network_free_list
);
1023 memset(priv
->current_addr
, 0xff, ETH_ALEN
);
1025 priv
->connect_status
= LBS_DISCONNECTED
;
1026 priv
->mesh_connect_status
= LBS_DISCONNECTED
;
1027 priv
->secinfo
.auth_mode
= IW_AUTH_ALG_OPEN_SYSTEM
;
1028 priv
->mode
= IW_MODE_INFRA
;
1029 priv
->curbssparams
.channel
= DEFAULT_AD_HOC_CHANNEL
;
1030 priv
->mac_control
= CMD_ACT_MAC_RX_ON
| CMD_ACT_MAC_TX_ON
;
1031 priv
->radioon
= RADIO_ON
;
1032 priv
->auto_rate
= 1;
1033 priv
->capability
= WLAN_CAPABILITY_SHORT_PREAMBLE
;
1034 priv
->psmode
= LBS802_11POWERMODECAM
;
1035 priv
->psstate
= PS_STATE_FULL_POWER
;
1037 mutex_init(&priv
->lock
);
1039 setup_timer(&priv
->command_timer
, command_timer_fn
,
1040 (unsigned long)priv
);
1042 INIT_LIST_HEAD(&priv
->cmdfreeq
);
1043 INIT_LIST_HEAD(&priv
->cmdpendingq
);
1045 spin_lock_init(&priv
->driver_lock
);
1046 init_waitqueue_head(&priv
->cmd_pending
);
1048 /* Allocate the command buffers */
1049 if (lbs_allocate_cmd_buffer(priv
)) {
1050 lbs_pr_err("Out of memory allocating command buffers\n");
1055 priv
->resp_len
[0] = priv
->resp_len
[1] = 0;
1057 /* Create the event FIFO */
1058 priv
->event_fifo
= kfifo_alloc(sizeof(u32
) * 16, GFP_KERNEL
, NULL
);
1059 if (IS_ERR(priv
->event_fifo
)) {
1060 lbs_pr_err("Out of memory allocating event FIFO buffer\n");
1066 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1071 static void lbs_free_adapter(struct lbs_private
*priv
)
1073 lbs_deb_enter(LBS_DEB_MAIN
);
1075 lbs_free_cmd_buffer(priv
);
1076 if (priv
->event_fifo
)
1077 kfifo_free(priv
->event_fifo
);
1078 del_timer(&priv
->command_timer
);
1079 kfree(priv
->networks
);
1080 priv
->networks
= NULL
;
1082 lbs_deb_leave(LBS_DEB_MAIN
);
1086 * @brief This function adds the card. it will probe the
1087 * card, allocate the lbs_priv and initialize the device.
1089 * @param card A pointer to card
1090 * @return A pointer to struct lbs_private structure
1092 struct lbs_private
*lbs_add_card(void *card
, struct device
*dmdev
)
1094 struct net_device
*dev
= NULL
;
1095 struct lbs_private
*priv
= NULL
;
1097 lbs_deb_enter(LBS_DEB_MAIN
);
1099 /* Allocate an Ethernet device and register it */
1100 dev
= alloc_etherdev(sizeof(struct lbs_private
));
1102 lbs_pr_err("init ethX device failed\n");
1107 if (lbs_init_adapter(priv
)) {
1108 lbs_pr_err("failed to initialize adapter structure.\n");
1109 goto err_init_adapter
;
1114 priv
->mesh_open
= 0;
1115 priv
->infra_open
= 0;
1117 /* Setup the OS Interface to our functions */
1118 dev
->open
= lbs_dev_open
;
1119 dev
->hard_start_xmit
= lbs_hard_start_xmit
;
1120 dev
->stop
= lbs_eth_stop
;
1121 dev
->set_mac_address
= lbs_set_mac_address
;
1122 dev
->tx_timeout
= lbs_tx_timeout
;
1123 dev
->do_ioctl
= lbs_do_ioctl
;
1124 dev
->get_stats
= lbs_get_stats
;
1125 dev
->watchdog_timeo
= 5 * HZ
;
1126 dev
->ethtool_ops
= &lbs_ethtool_ops
;
1128 dev
->wireless_handlers
= (struct iw_handler_def
*)&lbs_handler_def
;
1130 dev
->flags
|= IFF_BROADCAST
| IFF_MULTICAST
;
1131 dev
->set_multicast_list
= lbs_set_multicast_list
;
1133 SET_NETDEV_DEV(dev
, dmdev
);
1135 priv
->rtap_net_dev
= NULL
;
1137 lbs_deb_thread("Starting main thread...\n");
1138 init_waitqueue_head(&priv
->waitq
);
1139 priv
->main_thread
= kthread_run(lbs_thread
, dev
, "lbs_main");
1140 if (IS_ERR(priv
->main_thread
)) {
1141 lbs_deb_thread("Error creating main thread.\n");
1142 goto err_init_adapter
;
1145 priv
->work_thread
= create_singlethread_workqueue("lbs_worker");
1146 INIT_DELAYED_WORK(&priv
->assoc_work
, lbs_association_worker
);
1147 INIT_DELAYED_WORK(&priv
->scan_work
, lbs_scan_worker
);
1148 INIT_WORK(&priv
->sync_channel
, lbs_sync_channel_worker
);
1150 sprintf(priv
->mesh_ssid
, "mesh");
1151 priv
->mesh_ssid_len
= 4;
1153 priv
->wol_criteria
= 0xffffffff;
1154 priv
->wol_gpio
= 0xff;
1159 lbs_free_adapter(priv
);
1164 lbs_deb_leave_args(LBS_DEB_MAIN
, "priv %p", priv
);
1167 EXPORT_SYMBOL_GPL(lbs_add_card
);
1170 int lbs_remove_card(struct lbs_private
*priv
)
1172 struct net_device
*dev
= priv
->dev
;
1173 union iwreq_data wrqu
;
1175 lbs_deb_enter(LBS_DEB_MAIN
);
1177 lbs_remove_mesh(priv
);
1178 lbs_remove_rtap(priv
);
1182 cancel_delayed_work(&priv
->scan_work
);
1183 cancel_delayed_work(&priv
->assoc_work
);
1184 destroy_workqueue(priv
->work_thread
);
1186 if (priv
->psmode
== LBS802_11POWERMODEMAX_PSP
) {
1187 priv
->psmode
= LBS802_11POWERMODECAM
;
1188 lbs_ps_wakeup(priv
, CMD_OPTION_WAITFORRSP
);
1191 memset(wrqu
.ap_addr
.sa_data
, 0xaa, ETH_ALEN
);
1192 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1193 wireless_send_event(priv
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
1195 /* Stop the thread servicing the interrupts */
1196 priv
->surpriseremoved
= 1;
1197 kthread_stop(priv
->main_thread
);
1199 lbs_free_adapter(priv
);
1204 lbs_deb_leave(LBS_DEB_MAIN
);
1207 EXPORT_SYMBOL_GPL(lbs_remove_card
);
1210 int lbs_start_card(struct lbs_private
*priv
)
1212 struct net_device
*dev
= priv
->dev
;
1215 lbs_deb_enter(LBS_DEB_MAIN
);
1217 /* poke the firmware */
1218 ret
= lbs_setup_firmware(priv
);
1225 if (register_netdev(dev
)) {
1226 lbs_pr_err("cannot register ethX device\n");
1229 if (device_create_file(&dev
->dev
, &dev_attr_lbs_rtap
))
1230 lbs_pr_err("cannot register lbs_rtap attribute\n");
1232 lbs_update_channel(priv
);
1234 /* 5.0.16p0 is known to NOT support any mesh */
1235 if (priv
->fwrelease
> 0x05001000) {
1236 /* Enable mesh, if supported, and work out which TLV it uses.
1237 0x100 + 291 is an unofficial value used in 5.110.20.pXX
1238 0x100 + 37 is the official value used in 5.110.21.pXX
1239 but we check them in that order because 20.pXX doesn't
1240 give an error -- it just silently fails. */
1242 /* 5.110.20.pXX firmware will fail the command if the channel
1243 doesn't match the existing channel. But only if the TLV
1244 is correct. If the channel is wrong, _BOTH_ versions will
1245 give an error to 0x100+291, and allow 0x100+37 to succeed.
1246 It's just that 5.110.20.pXX will not have done anything
1249 priv
->mesh_tlv
= 0x100 + 291;
1250 if (lbs_mesh_config(priv
, 1, priv
->curbssparams
.channel
)) {
1251 priv
->mesh_tlv
= 0x100 + 37;
1252 if (lbs_mesh_config(priv
, 1, priv
->curbssparams
.channel
))
1255 if (priv
->mesh_tlv
) {
1258 if (device_create_file(&dev
->dev
, &dev_attr_lbs_mesh
))
1259 lbs_pr_err("cannot register lbs_mesh attribute\n");
1263 lbs_debugfs_init_one(priv
, dev
);
1265 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev
->name
);
1270 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1273 EXPORT_SYMBOL_GPL(lbs_start_card
);
1276 int lbs_stop_card(struct lbs_private
*priv
)
1278 struct net_device
*dev
= priv
->dev
;
1280 struct cmd_ctrl_node
*cmdnode
;
1281 unsigned long flags
;
1283 lbs_deb_enter(LBS_DEB_MAIN
);
1285 netif_stop_queue(priv
->dev
);
1286 netif_carrier_off(priv
->dev
);
1288 lbs_debugfs_remove_one(priv
);
1289 device_remove_file(&dev
->dev
, &dev_attr_lbs_rtap
);
1291 device_remove_file(&dev
->dev
, &dev_attr_lbs_mesh
);
1293 /* Flush pending command nodes */
1294 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1295 list_for_each_entry(cmdnode
, &priv
->cmdpendingq
, list
) {
1296 cmdnode
->result
= -ENOENT
;
1297 cmdnode
->cmdwaitqwoken
= 1;
1298 wake_up_interruptible(&cmdnode
->cmdwait_q
);
1300 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1302 unregister_netdev(dev
);
1304 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1307 EXPORT_SYMBOL_GPL(lbs_stop_card
);
1311 * @brief This function adds mshX interface
1313 * @param priv A pointer to the struct lbs_private structure
1314 * @return 0 if successful, -X otherwise
1316 static int lbs_add_mesh(struct lbs_private
*priv
)
1318 struct net_device
*mesh_dev
= NULL
;
1321 lbs_deb_enter(LBS_DEB_MESH
);
1323 /* Allocate a virtual mesh device */
1324 if (!(mesh_dev
= alloc_netdev(0, "msh%d", ether_setup
))) {
1325 lbs_deb_mesh("init mshX device failed\n");
1329 mesh_dev
->priv
= priv
;
1330 priv
->mesh_dev
= mesh_dev
;
1332 mesh_dev
->open
= lbs_dev_open
;
1333 mesh_dev
->hard_start_xmit
= lbs_hard_start_xmit
;
1334 mesh_dev
->stop
= lbs_mesh_stop
;
1335 mesh_dev
->do_ioctl
= lbs_do_ioctl
;
1336 mesh_dev
->get_stats
= lbs_get_stats
;
1337 mesh_dev
->set_mac_address
= lbs_set_mac_address
;
1338 mesh_dev
->ethtool_ops
= &lbs_ethtool_ops
;
1339 memcpy(mesh_dev
->dev_addr
, priv
->dev
->dev_addr
,
1340 sizeof(priv
->dev
->dev_addr
));
1342 SET_NETDEV_DEV(priv
->mesh_dev
, priv
->dev
->dev
.parent
);
1345 mesh_dev
->wireless_handlers
= (struct iw_handler_def
*)&mesh_handler_def
;
1347 /* Register virtual mesh interface */
1348 ret
= register_netdev(mesh_dev
);
1350 lbs_pr_err("cannot register mshX virtual interface\n");
1354 ret
= sysfs_create_group(&(mesh_dev
->dev
.kobj
), &lbs_mesh_attr_group
);
1356 goto err_unregister
;
1358 /* Everything successful */
1363 unregister_netdev(mesh_dev
);
1366 free_netdev(mesh_dev
);
1369 lbs_deb_leave_args(LBS_DEB_MESH
, "ret %d", ret
);
1373 static void lbs_remove_mesh(struct lbs_private
*priv
)
1375 struct net_device
*mesh_dev
;
1378 mesh_dev
= priv
->mesh_dev
;
1382 lbs_deb_enter(LBS_DEB_MESH
);
1383 netif_stop_queue(mesh_dev
);
1384 netif_carrier_off(priv
->mesh_dev
);
1385 sysfs_remove_group(&(mesh_dev
->dev
.kobj
), &lbs_mesh_attr_group
);
1386 unregister_netdev(mesh_dev
);
1387 priv
->mesh_dev
= NULL
;
1388 free_netdev(mesh_dev
);
1389 lbs_deb_leave(LBS_DEB_MESH
);
1393 * @brief This function finds the CFP in
1394 * region_cfp_table based on region and band parameter.
1396 * @param region The region code
1397 * @param band The band
1398 * @param cfp_no A pointer to CFP number
1399 * @return A pointer to CFP
1401 struct chan_freq_power
*lbs_get_region_cfp_table(u8 region
, int *cfp_no
)
1405 lbs_deb_enter(LBS_DEB_MAIN
);
1407 end
= ARRAY_SIZE(region_cfp_table
);
1409 for (i
= 0; i
< end
; i
++) {
1410 lbs_deb_main("region_cfp_table[i].region=%d\n",
1411 region_cfp_table
[i
].region
);
1412 if (region_cfp_table
[i
].region
== region
) {
1413 *cfp_no
= region_cfp_table
[i
].cfp_no_BG
;
1414 lbs_deb_leave(LBS_DEB_MAIN
);
1415 return region_cfp_table
[i
].cfp_BG
;
1419 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret NULL");
1423 int lbs_set_regiontable(struct lbs_private
*priv
, u8 region
, u8 band
)
1428 struct chan_freq_power
*cfp
;
1431 lbs_deb_enter(LBS_DEB_MAIN
);
1433 memset(priv
->region_channel
, 0, sizeof(priv
->region_channel
));
1435 cfp
= lbs_get_region_cfp_table(region
, &cfp_no
);
1437 priv
->region_channel
[i
].nrcfp
= cfp_no
;
1438 priv
->region_channel
[i
].CFP
= cfp
;
1440 lbs_deb_main("wrong region code %#x in band B/G\n",
1445 priv
->region_channel
[i
].valid
= 1;
1446 priv
->region_channel
[i
].region
= region
;
1447 priv
->region_channel
[i
].band
= band
;
1450 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1454 void lbs_queue_event(struct lbs_private
*priv
, u32 event
)
1456 unsigned long flags
;
1458 lbs_deb_enter(LBS_DEB_THREAD
);
1459 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1461 if (priv
->psstate
== PS_STATE_SLEEP
)
1462 priv
->psstate
= PS_STATE_AWAKE
;
1464 __kfifo_put(priv
->event_fifo
, (unsigned char *) &event
, sizeof(u32
));
1466 wake_up_interruptible(&priv
->waitq
);
1468 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1469 lbs_deb_leave(LBS_DEB_THREAD
);
1471 EXPORT_SYMBOL_GPL(lbs_queue_event
);
1473 void lbs_notify_command_response(struct lbs_private
*priv
, u8 resp_idx
)
1475 lbs_deb_enter(LBS_DEB_THREAD
);
1477 if (priv
->psstate
== PS_STATE_SLEEP
)
1478 priv
->psstate
= PS_STATE_AWAKE
;
1480 /* Swap buffers by flipping the response index */
1481 BUG_ON(resp_idx
> 1);
1482 priv
->resp_idx
= resp_idx
;
1484 wake_up_interruptible(&priv
->waitq
);
1486 lbs_deb_leave(LBS_DEB_THREAD
);
1488 EXPORT_SYMBOL_GPL(lbs_notify_command_response
);
1490 static int __init
lbs_init_module(void)
1492 lbs_deb_enter(LBS_DEB_MAIN
);
1493 memset(&confirm_sleep
, 0, sizeof(confirm_sleep
));
1494 confirm_sleep
.hdr
.command
= cpu_to_le16(CMD_802_11_PS_MODE
);
1495 confirm_sleep
.hdr
.size
= cpu_to_le16(sizeof(confirm_sleep
));
1496 confirm_sleep
.action
= cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED
);
1498 lbs_deb_leave(LBS_DEB_MAIN
);
1502 static void __exit
lbs_exit_module(void)
1504 lbs_deb_enter(LBS_DEB_MAIN
);
1505 lbs_debugfs_remove();
1506 lbs_deb_leave(LBS_DEB_MAIN
);
1510 * rtap interface support fuctions
1513 static int lbs_rtap_open(struct net_device
*dev
)
1515 /* Yes, _stop_ the queue. Because we don't support injection */
1516 lbs_deb_enter(LBS_DEB_MAIN
);
1517 netif_carrier_off(dev
);
1518 netif_stop_queue(dev
);
1519 lbs_deb_leave(LBS_DEB_LEAVE
);
1523 static int lbs_rtap_stop(struct net_device
*dev
)
1525 lbs_deb_enter(LBS_DEB_MAIN
);
1526 lbs_deb_leave(LBS_DEB_MAIN
);
1530 static int lbs_rtap_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1532 netif_stop_queue(dev
);
1533 return NETDEV_TX_BUSY
;
1536 static struct net_device_stats
*lbs_rtap_get_stats(struct net_device
*dev
)
1538 struct lbs_private
*priv
= dev
->priv
;
1539 lbs_deb_enter(LBS_DEB_NET
);
1540 return &priv
->stats
;
1544 static void lbs_remove_rtap(struct lbs_private
*priv
)
1546 lbs_deb_enter(LBS_DEB_MAIN
);
1547 if (priv
->rtap_net_dev
== NULL
)
1549 unregister_netdev(priv
->rtap_net_dev
);
1550 free_netdev(priv
->rtap_net_dev
);
1551 priv
->rtap_net_dev
= NULL
;
1552 lbs_deb_leave(LBS_DEB_MAIN
);
1555 static int lbs_add_rtap(struct lbs_private
*priv
)
1558 struct net_device
*rtap_dev
;
1560 lbs_deb_enter(LBS_DEB_MAIN
);
1561 if (priv
->rtap_net_dev
) {
1566 rtap_dev
= alloc_netdev(0, "rtap%d", ether_setup
);
1567 if (rtap_dev
== NULL
) {
1572 memcpy(rtap_dev
->dev_addr
, priv
->current_addr
, ETH_ALEN
);
1573 rtap_dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
1574 rtap_dev
->open
= lbs_rtap_open
;
1575 rtap_dev
->stop
= lbs_rtap_stop
;
1576 rtap_dev
->get_stats
= lbs_rtap_get_stats
;
1577 rtap_dev
->hard_start_xmit
= lbs_rtap_hard_start_xmit
;
1578 rtap_dev
->set_multicast_list
= lbs_set_multicast_list
;
1579 rtap_dev
->priv
= priv
;
1580 SET_NETDEV_DEV(rtap_dev
, priv
->dev
->dev
.parent
);
1582 ret
= register_netdev(rtap_dev
);
1584 free_netdev(rtap_dev
);
1587 priv
->rtap_net_dev
= rtap_dev
;
1590 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1594 #ifndef CONFIG_IEEE80211
1595 const char *escape_essid(const char *essid
, u8 essid_len
)
1597 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
1598 const char *s
= essid
;
1601 if (ieee80211_is_empty_essid(essid
, essid_len
)) {
1602 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
1606 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
1607 while (essid_len
--) {
1621 module_init(lbs_init_module
);
1622 module_exit(lbs_exit_module
);
1624 MODULE_DESCRIPTION("Libertas WLAN Driver Library");
1625 MODULE_AUTHOR("Marvell International Ltd.");
1626 MODULE_LICENSE("GPL");