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>
18 #include <net/iw_handler.h>
19 #include <net/ieee80211.h>
31 #define DRIVER_RELEASE_VERSION "323.p0"
32 const char lbs_driver_version
[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
39 /* Module parameters */
40 unsigned int lbs_debug
;
41 EXPORT_SYMBOL_GPL(lbs_debug
);
42 module_param_named(libertas_debug
, lbs_debug
, int, 0644);
45 /* This global structure is used to send the confirm_sleep command as
46 * fast as possible down to the firmware. */
47 struct cmd_confirm_sleep confirm_sleep
;
50 #define LBS_TX_PWR_DEFAULT 20 /*100mW */
51 #define LBS_TX_PWR_US_DEFAULT 20 /*100mW */
52 #define LBS_TX_PWR_JP_DEFAULT 16 /*50mW */
53 #define LBS_TX_PWR_FR_DEFAULT 20 /*100mW */
54 #define LBS_TX_PWR_EMEA_DEFAULT 20 /*100mW */
56 /* Format { channel, frequency (MHz), maxtxpower } */
57 /* band: 'B/G', region: USA FCC/Canada IC */
58 static struct chan_freq_power channel_freq_power_US_BG
[] = {
59 {1, 2412, LBS_TX_PWR_US_DEFAULT
},
60 {2, 2417, LBS_TX_PWR_US_DEFAULT
},
61 {3, 2422, LBS_TX_PWR_US_DEFAULT
},
62 {4, 2427, LBS_TX_PWR_US_DEFAULT
},
63 {5, 2432, LBS_TX_PWR_US_DEFAULT
},
64 {6, 2437, LBS_TX_PWR_US_DEFAULT
},
65 {7, 2442, LBS_TX_PWR_US_DEFAULT
},
66 {8, 2447, LBS_TX_PWR_US_DEFAULT
},
67 {9, 2452, LBS_TX_PWR_US_DEFAULT
},
68 {10, 2457, LBS_TX_PWR_US_DEFAULT
},
69 {11, 2462, LBS_TX_PWR_US_DEFAULT
}
72 /* band: 'B/G', region: Europe ETSI */
73 static struct chan_freq_power channel_freq_power_EU_BG
[] = {
74 {1, 2412, LBS_TX_PWR_EMEA_DEFAULT
},
75 {2, 2417, LBS_TX_PWR_EMEA_DEFAULT
},
76 {3, 2422, LBS_TX_PWR_EMEA_DEFAULT
},
77 {4, 2427, LBS_TX_PWR_EMEA_DEFAULT
},
78 {5, 2432, LBS_TX_PWR_EMEA_DEFAULT
},
79 {6, 2437, LBS_TX_PWR_EMEA_DEFAULT
},
80 {7, 2442, LBS_TX_PWR_EMEA_DEFAULT
},
81 {8, 2447, LBS_TX_PWR_EMEA_DEFAULT
},
82 {9, 2452, LBS_TX_PWR_EMEA_DEFAULT
},
83 {10, 2457, LBS_TX_PWR_EMEA_DEFAULT
},
84 {11, 2462, LBS_TX_PWR_EMEA_DEFAULT
},
85 {12, 2467, LBS_TX_PWR_EMEA_DEFAULT
},
86 {13, 2472, LBS_TX_PWR_EMEA_DEFAULT
}
89 /* band: 'B/G', region: Spain */
90 static struct chan_freq_power channel_freq_power_SPN_BG
[] = {
91 {10, 2457, LBS_TX_PWR_DEFAULT
},
92 {11, 2462, LBS_TX_PWR_DEFAULT
}
95 /* band: 'B/G', region: France */
96 static struct chan_freq_power channel_freq_power_FR_BG
[] = {
97 {10, 2457, LBS_TX_PWR_FR_DEFAULT
},
98 {11, 2462, LBS_TX_PWR_FR_DEFAULT
},
99 {12, 2467, LBS_TX_PWR_FR_DEFAULT
},
100 {13, 2472, LBS_TX_PWR_FR_DEFAULT
}
103 /* band: 'B/G', region: Japan */
104 static struct chan_freq_power channel_freq_power_JPN_BG
[] = {
105 {1, 2412, LBS_TX_PWR_JP_DEFAULT
},
106 {2, 2417, LBS_TX_PWR_JP_DEFAULT
},
107 {3, 2422, LBS_TX_PWR_JP_DEFAULT
},
108 {4, 2427, LBS_TX_PWR_JP_DEFAULT
},
109 {5, 2432, LBS_TX_PWR_JP_DEFAULT
},
110 {6, 2437, LBS_TX_PWR_JP_DEFAULT
},
111 {7, 2442, LBS_TX_PWR_JP_DEFAULT
},
112 {8, 2447, LBS_TX_PWR_JP_DEFAULT
},
113 {9, 2452, LBS_TX_PWR_JP_DEFAULT
},
114 {10, 2457, LBS_TX_PWR_JP_DEFAULT
},
115 {11, 2462, LBS_TX_PWR_JP_DEFAULT
},
116 {12, 2467, LBS_TX_PWR_JP_DEFAULT
},
117 {13, 2472, LBS_TX_PWR_JP_DEFAULT
},
118 {14, 2484, LBS_TX_PWR_JP_DEFAULT
}
122 * the structure for channel, frequency and power
124 struct region_cfp_table
{
126 struct chan_freq_power
*cfp_BG
;
131 * the structure for the mapping between region and CFP
133 static struct region_cfp_table region_cfp_table
[] = {
135 channel_freq_power_US_BG
,
136 ARRAY_SIZE(channel_freq_power_US_BG
),
139 {0x20, /*CANADA IC */
140 channel_freq_power_US_BG
,
141 ARRAY_SIZE(channel_freq_power_US_BG
),
144 {0x30, /*EU*/ channel_freq_power_EU_BG
,
145 ARRAY_SIZE(channel_freq_power_EU_BG
),
148 {0x31, /*SPAIN*/ channel_freq_power_SPN_BG
,
149 ARRAY_SIZE(channel_freq_power_SPN_BG
),
152 {0x32, /*FRANCE*/ channel_freq_power_FR_BG
,
153 ARRAY_SIZE(channel_freq_power_FR_BG
),
156 {0x40, /*JAPAN*/ channel_freq_power_JPN_BG
,
157 ARRAY_SIZE(channel_freq_power_JPN_BG
),
160 /*Add new region here */
164 * the table to keep region code
166 u16 lbs_region_code_to_index
[MRVDRV_MAX_REGION_CODE
] =
167 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
170 * 802.11b/g supported bitrates (in 500Kb/s units)
172 u8 lbs_bg_rates
[MAX_RATES
] =
173 { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
177 * FW rate table. FW refers to rates by their index in this table, not by the
178 * rate value itself. Values of 0x00 are
179 * reserved positions.
181 static u8 fw_data_rates
[MAX_RATES
] =
182 { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
183 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
187 * @brief use index to get the data rate
189 * @param idx The index of data rate
190 * @return data rate or 0
192 u32
lbs_fw_index_to_data_rate(u8 idx
)
194 if (idx
>= sizeof(fw_data_rates
))
196 return fw_data_rates
[idx
];
200 * @brief use rate to get the index
202 * @param rate data rate
205 u8
lbs_data_rate_to_fw_index(u32 rate
)
212 for (i
= 0; i
< sizeof(fw_data_rates
); i
++) {
213 if (rate
== fw_data_rates
[i
])
220 * Attributes exported through sysfs
224 * @brief Get function for sysfs attribute anycast_mask
226 static ssize_t
lbs_anycast_get(struct device
*dev
,
227 struct device_attribute
*attr
, char * buf
)
229 struct lbs_private
*priv
= to_net_dev(dev
)->priv
;
230 struct cmd_ds_mesh_access mesh_access
;
233 memset(&mesh_access
, 0, sizeof(mesh_access
));
235 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_GET_ANYCAST
, &mesh_access
);
239 return snprintf(buf
, 12, "0x%X\n", le32_to_cpu(mesh_access
.data
[0]));
243 * @brief Set function for sysfs attribute anycast_mask
245 static ssize_t
lbs_anycast_set(struct device
*dev
,
246 struct device_attribute
*attr
, const char * buf
, size_t count
)
248 struct lbs_private
*priv
= to_net_dev(dev
)->priv
;
249 struct cmd_ds_mesh_access mesh_access
;
253 memset(&mesh_access
, 0, sizeof(mesh_access
));
254 sscanf(buf
, "%x", &datum
);
255 mesh_access
.data
[0] = cpu_to_le32(datum
);
257 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_ANYCAST
, &mesh_access
);
264 static int lbs_add_rtap(struct lbs_private
*priv
);
265 static void lbs_remove_rtap(struct lbs_private
*priv
);
266 static int lbs_add_mesh(struct lbs_private
*priv
);
267 static void lbs_remove_mesh(struct lbs_private
*priv
);
271 * Get function for sysfs attribute rtap
273 static ssize_t
lbs_rtap_get(struct device
*dev
,
274 struct device_attribute
*attr
, char * buf
)
276 struct lbs_private
*priv
= to_net_dev(dev
)->priv
;
277 return snprintf(buf
, 5, "0x%X\n", priv
->monitormode
);
281 * Set function for sysfs attribute rtap
283 static ssize_t
lbs_rtap_set(struct device
*dev
,
284 struct device_attribute
*attr
, const char * buf
, size_t count
)
287 struct lbs_private
*priv
= to_net_dev(dev
)->priv
;
289 sscanf(buf
, "%x", &monitor_mode
);
291 if (priv
->monitormode
== monitor_mode
)
293 if (!priv
->monitormode
) {
294 if (priv
->infra_open
|| priv
->mesh_open
)
296 if (priv
->mode
== IW_MODE_INFRA
)
297 lbs_send_deauthentication(priv
);
298 else if (priv
->mode
== IW_MODE_ADHOC
)
299 lbs_stop_adhoc_network(priv
);
302 priv
->monitormode
= monitor_mode
;
306 if (!priv
->monitormode
)
308 priv
->monitormode
= 0;
309 lbs_remove_rtap(priv
);
311 if (priv
->currenttxskb
) {
312 dev_kfree_skb_any(priv
->currenttxskb
);
313 priv
->currenttxskb
= NULL
;
316 /* Wake queues, command thread, etc. */
317 lbs_host_to_card_done(priv
);
320 lbs_prepare_and_send_command(priv
,
321 CMD_802_11_MONITOR_MODE
, CMD_ACT_SET
,
322 CMD_OPTION_WAITFORRSP
, 0, &priv
->monitormode
);
327 * lbs_rtap attribute to be exported per ethX interface
328 * through sysfs (/sys/class/net/ethX/lbs_rtap)
330 static DEVICE_ATTR(lbs_rtap
, 0644, lbs_rtap_get
, lbs_rtap_set
);
333 * Get function for sysfs attribute mesh
335 static ssize_t
lbs_mesh_get(struct device
*dev
,
336 struct device_attribute
*attr
, char * buf
)
338 struct lbs_private
*priv
= to_net_dev(dev
)->priv
;
339 return snprintf(buf
, 5, "0x%X\n", !!priv
->mesh_dev
);
343 * Set function for sysfs attribute mesh
345 static ssize_t
lbs_mesh_set(struct device
*dev
,
346 struct device_attribute
*attr
, const char * buf
, size_t count
)
348 struct lbs_private
*priv
= to_net_dev(dev
)->priv
;
352 sscanf(buf
, "%x", &enable
);
354 if (enable
== !!priv
->mesh_dev
)
357 ret
= lbs_mesh_config(priv
, enable
, priv
->curbssparams
.channel
);
364 lbs_remove_mesh(priv
);
370 * lbs_mesh attribute to be exported per ethX interface
371 * through sysfs (/sys/class/net/ethX/lbs_mesh)
373 static DEVICE_ATTR(lbs_mesh
, 0644, lbs_mesh_get
, lbs_mesh_set
);
376 * anycast_mask attribute to be exported per mshX interface
377 * through sysfs (/sys/class/net/mshX/anycast_mask)
379 static DEVICE_ATTR(anycast_mask
, 0644, lbs_anycast_get
, lbs_anycast_set
);
381 static struct attribute
*lbs_mesh_sysfs_entries
[] = {
382 &dev_attr_anycast_mask
.attr
,
386 static struct attribute_group lbs_mesh_attr_group
= {
387 .attrs
= lbs_mesh_sysfs_entries
,
391 * @brief This function opens the ethX or mshX interface
393 * @param dev A pointer to net_device structure
394 * @return 0 or -EBUSY if monitor mode active
396 static int lbs_dev_open(struct net_device
*dev
)
398 struct lbs_private
*priv
= (struct lbs_private
*) dev
->priv
;
401 lbs_deb_enter(LBS_DEB_NET
);
403 spin_lock_irq(&priv
->driver_lock
);
405 if (priv
->monitormode
) {
410 if (dev
== priv
->mesh_dev
) {
412 priv
->mesh_connect_status
= LBS_CONNECTED
;
413 netif_carrier_on(dev
);
415 priv
->infra_open
= 1;
417 if (priv
->connect_status
== LBS_CONNECTED
)
418 netif_carrier_on(dev
);
420 netif_carrier_off(dev
);
423 if (!priv
->tx_pending_len
)
424 netif_wake_queue(dev
);
427 spin_unlock_irq(&priv
->driver_lock
);
428 lbs_deb_leave_args(LBS_DEB_NET
, "ret %d", ret
);
433 * @brief This function closes the mshX interface
435 * @param dev A pointer to net_device structure
438 static int lbs_mesh_stop(struct net_device
*dev
)
440 struct lbs_private
*priv
= (struct lbs_private
*) (dev
->priv
);
442 lbs_deb_enter(LBS_DEB_MESH
);
443 spin_lock_irq(&priv
->driver_lock
);
446 priv
->mesh_connect_status
= LBS_DISCONNECTED
;
448 netif_stop_queue(dev
);
449 netif_carrier_off(dev
);
451 spin_unlock_irq(&priv
->driver_lock
);
453 lbs_deb_leave(LBS_DEB_MESH
);
458 * @brief This function closes the ethX interface
460 * @param dev A pointer to net_device structure
463 static int lbs_eth_stop(struct net_device
*dev
)
465 struct lbs_private
*priv
= (struct lbs_private
*) dev
->priv
;
467 lbs_deb_enter(LBS_DEB_NET
);
469 spin_lock_irq(&priv
->driver_lock
);
470 priv
->infra_open
= 0;
471 netif_stop_queue(dev
);
472 spin_unlock_irq(&priv
->driver_lock
);
474 lbs_deb_leave(LBS_DEB_NET
);
478 static void lbs_tx_timeout(struct net_device
*dev
)
480 struct lbs_private
*priv
= (struct lbs_private
*) dev
->priv
;
482 lbs_deb_enter(LBS_DEB_TX
);
484 lbs_pr_err("tx watch dog timeout\n");
486 dev
->trans_start
= jiffies
;
488 if (priv
->currenttxskb
)
489 lbs_send_tx_feedback(priv
, 0);
491 /* XX: Shouldn't we also call into the hw-specific driver
492 to kick it somehow? */
493 lbs_host_to_card_done(priv
);
495 /* More often than not, this actually happens because the
496 firmware has crapped itself -- rather than just a very
497 busy medium. So send a harmless command, and if/when
498 _that_ times out, we'll kick it in the head. */
499 lbs_prepare_and_send_command(priv
, CMD_802_11_RSSI
, 0,
502 lbs_deb_leave(LBS_DEB_TX
);
505 void lbs_host_to_card_done(struct lbs_private
*priv
)
509 lbs_deb_enter(LBS_DEB_THREAD
);
511 spin_lock_irqsave(&priv
->driver_lock
, flags
);
513 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
515 /* Wake main thread if commands are pending */
516 if (!priv
->cur_cmd
|| priv
->tx_pending_len
> 0)
517 wake_up_interruptible(&priv
->waitq
);
519 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
520 lbs_deb_leave(LBS_DEB_THREAD
);
522 EXPORT_SYMBOL_GPL(lbs_host_to_card_done
);
525 * @brief This function returns the network statistics
527 * @param dev A pointer to struct lbs_private structure
528 * @return A pointer to net_device_stats structure
530 static struct net_device_stats
*lbs_get_stats(struct net_device
*dev
)
532 struct lbs_private
*priv
= (struct lbs_private
*) dev
->priv
;
534 lbs_deb_enter(LBS_DEB_NET
);
538 static int lbs_set_mac_address(struct net_device
*dev
, void *addr
)
541 struct lbs_private
*priv
= (struct lbs_private
*) dev
->priv
;
542 struct sockaddr
*phwaddr
= addr
;
543 struct cmd_ds_802_11_mac_address cmd
;
545 lbs_deb_enter(LBS_DEB_NET
);
547 /* In case it was called from the mesh device */
550 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
551 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
552 memcpy(cmd
.macadd
, phwaddr
->sa_data
, ETH_ALEN
);
554 ret
= lbs_cmd_with_response(priv
, CMD_802_11_MAC_ADDRESS
, &cmd
);
556 lbs_deb_net("set MAC address failed\n");
560 memcpy(priv
->current_addr
, phwaddr
->sa_data
, ETH_ALEN
);
561 memcpy(dev
->dev_addr
, phwaddr
->sa_data
, ETH_ALEN
);
563 memcpy(priv
->mesh_dev
->dev_addr
, phwaddr
->sa_data
, ETH_ALEN
);
566 lbs_deb_leave_args(LBS_DEB_NET
, "ret %d", ret
);
570 static int lbs_copy_multicast_address(struct lbs_private
*priv
,
571 struct net_device
*dev
)
574 struct dev_mc_list
*mcptr
= dev
->mc_list
;
576 for (i
= 0; i
< dev
->mc_count
; i
++) {
577 memcpy(&priv
->multicastlist
[i
], mcptr
->dmi_addr
, ETH_ALEN
);
583 static void lbs_set_multicast_list(struct net_device
*dev
)
585 struct lbs_private
*priv
= dev
->priv
;
587 DECLARE_MAC_BUF(mac
);
589 lbs_deb_enter(LBS_DEB_NET
);
591 old_mac_control
= priv
->mac_control
;
593 if (dev
->flags
& IFF_PROMISC
) {
594 lbs_deb_net("enable promiscuous mode\n");
596 CMD_ACT_MAC_PROMISCUOUS_ENABLE
;
598 ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE
|
599 CMD_ACT_MAC_MULTICAST_ENABLE
);
603 ~CMD_ACT_MAC_PROMISCUOUS_ENABLE
;
605 if (dev
->flags
& IFF_ALLMULTI
|| dev
->mc_count
>
606 MRVDRV_MAX_MULTICAST_LIST_SIZE
) {
607 lbs_deb_net( "enabling all multicast\n");
609 CMD_ACT_MAC_ALL_MULTICAST_ENABLE
;
611 ~CMD_ACT_MAC_MULTICAST_ENABLE
;
614 ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE
;
616 if (!dev
->mc_count
) {
617 lbs_deb_net("no multicast addresses, "
618 "disabling multicast\n");
620 ~CMD_ACT_MAC_MULTICAST_ENABLE
;
625 CMD_ACT_MAC_MULTICAST_ENABLE
;
627 priv
->nr_of_multicastmacaddr
=
628 lbs_copy_multicast_address(priv
, dev
);
630 lbs_deb_net("multicast addresses: %d\n",
633 for (i
= 0; i
< dev
->mc_count
; i
++) {
634 lbs_deb_net("Multicast address %d: %s\n",
636 priv
->multicastlist
[i
]));
638 /* send multicast addresses to firmware */
639 lbs_prepare_and_send_command(priv
,
640 CMD_MAC_MULTICAST_ADR
,
647 if (priv
->mac_control
!= old_mac_control
)
648 lbs_set_mac_control(priv
);
650 lbs_deb_leave(LBS_DEB_NET
);
654 * @brief This function handles the major jobs in the LBS driver.
655 * It handles all events generated by firmware, RX data received
656 * from firmware and TX data sent from kernel.
658 * @param data A pointer to lbs_thread structure
661 static int lbs_thread(void *data
)
663 struct net_device
*dev
= data
;
664 struct lbs_private
*priv
= dev
->priv
;
667 lbs_deb_enter(LBS_DEB_THREAD
);
669 init_waitqueue_entry(&wait
, current
);
675 lbs_deb_thread("1: currenttxskb %p, dnld_sent %d\n",
676 priv
->currenttxskb
, priv
->dnld_sent
);
678 add_wait_queue(&priv
->waitq
, &wait
);
679 set_current_state(TASK_INTERRUPTIBLE
);
680 spin_lock_irq(&priv
->driver_lock
);
682 if (kthread_should_stop())
683 shouldsleep
= 0; /* Bye */
684 else if (priv
->surpriseremoved
)
685 shouldsleep
= 1; /* We need to wait until we're _told_ to die */
686 else if (priv
->psstate
== PS_STATE_SLEEP
)
687 shouldsleep
= 1; /* Sleep mode. Nothing we can do till it wakes */
688 else if (priv
->cmd_timed_out
)
689 shouldsleep
= 0; /* Command timed out. Recover */
690 else if (!priv
->fw_ready
)
691 shouldsleep
= 1; /* Firmware not ready. We're waiting for it */
692 else if (priv
->dnld_sent
)
693 shouldsleep
= 1; /* Something is en route to the device already */
694 else if (priv
->tx_pending_len
> 0)
695 shouldsleep
= 0; /* We've a packet to send */
696 else if (priv
->cur_cmd
)
697 shouldsleep
= 1; /* Can't send a command; one already running */
698 else if (!list_empty(&priv
->cmdpendingq
))
699 shouldsleep
= 0; /* We have a command to send */
700 else if (__kfifo_len(priv
->event_fifo
))
701 shouldsleep
= 0; /* We have an event to process */
702 else if (priv
->resp_len
[priv
->resp_idx
])
703 shouldsleep
= 0; /* We have a command response */
705 shouldsleep
= 1; /* No command */
708 lbs_deb_thread("sleeping, connect_status %d, "
709 "ps_mode %d, ps_state %d\n",
710 priv
->connect_status
,
711 priv
->psmode
, priv
->psstate
);
712 spin_unlock_irq(&priv
->driver_lock
);
715 spin_unlock_irq(&priv
->driver_lock
);
717 lbs_deb_thread("2: currenttxskb %p, dnld_send %d\n",
718 priv
->currenttxskb
, priv
->dnld_sent
);
720 set_current_state(TASK_RUNNING
);
721 remove_wait_queue(&priv
->waitq
, &wait
);
723 lbs_deb_thread("3: currenttxskb %p, dnld_sent %d\n",
724 priv
->currenttxskb
, priv
->dnld_sent
);
726 if (kthread_should_stop()) {
727 lbs_deb_thread("break from main thread\n");
731 if (priv
->surpriseremoved
) {
732 lbs_deb_thread("adapter removed; waiting to die...\n");
736 lbs_deb_thread("4: currenttxskb %p, dnld_sent %d\n",
737 priv
->currenttxskb
, priv
->dnld_sent
);
739 /* Process any pending command response */
740 spin_lock_irq(&priv
->driver_lock
);
741 resp_idx
= priv
->resp_idx
;
742 if (priv
->resp_len
[resp_idx
]) {
743 spin_unlock_irq(&priv
->driver_lock
);
744 lbs_process_command_response(priv
,
745 priv
->resp_buf
[resp_idx
],
746 priv
->resp_len
[resp_idx
]);
747 spin_lock_irq(&priv
->driver_lock
);
748 priv
->resp_len
[resp_idx
] = 0;
750 spin_unlock_irq(&priv
->driver_lock
);
752 /* command timeout stuff */
753 if (priv
->cmd_timed_out
&& priv
->cur_cmd
) {
754 struct cmd_ctrl_node
*cmdnode
= priv
->cur_cmd
;
756 if (++priv
->nr_retries
> 10) {
757 lbs_pr_info("Excessive timeouts submitting command %x\n",
758 le16_to_cpu(cmdnode
->cmdbuf
->command
));
759 lbs_complete_command(priv
, cmdnode
, -ETIMEDOUT
);
760 priv
->nr_retries
= 0;
762 if (machine_is_olpc()) {
763 spin_unlock_irq(&priv
->driver_lock
);
764 printk(KERN_CRIT
"Resetting OLPC wireless via EC...\n");
765 olpc_ec_cmd(0x25, NULL
, 0, NULL
, 0);
766 spin_lock_irq(&priv
->driver_lock
);
770 priv
->cur_cmd
= NULL
;
771 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
772 lbs_pr_info("requeueing command %x due to timeout (#%d)\n",
773 le16_to_cpu(cmdnode
->cmdbuf
->command
), priv
->nr_retries
);
775 /* Stick it back at the _top_ of the pending queue
776 for immediate resubmission */
777 list_add(&cmdnode
->list
, &priv
->cmdpendingq
);
780 priv
->cmd_timed_out
= 0;
782 /* Process hardware events, e.g. card removed, link lost */
783 spin_lock_irq(&priv
->driver_lock
);
784 while (__kfifo_len(priv
->event_fifo
)) {
787 __kfifo_get(priv
->event_fifo
, (unsigned char *) &event
,
789 spin_unlock_irq(&priv
->driver_lock
);
790 lbs_process_event(priv
, event
);
791 spin_lock_irq(&priv
->driver_lock
);
793 spin_unlock_irq(&priv
->driver_lock
);
798 /* Check if we need to confirm Sleep Request received previously */
799 if (priv
->psstate
== PS_STATE_PRE_SLEEP
&&
800 !priv
->dnld_sent
&& !priv
->cur_cmd
) {
801 if (priv
->connect_status
== LBS_CONNECTED
) {
802 lbs_deb_thread("pre-sleep, currenttxskb %p, "
803 "dnld_sent %d, cur_cmd %p\n",
804 priv
->currenttxskb
, priv
->dnld_sent
,
807 lbs_ps_confirm_sleep(priv
);
809 /* workaround for firmware sending
810 * deauth/linkloss event immediately
811 * after sleep request; remove this
812 * after firmware fixes it
814 priv
->psstate
= PS_STATE_AWAKE
;
815 lbs_pr_alert("ignore PS_SleepConfirm in "
816 "non-connected state\n");
820 /* The PS state is changed during processing of Sleep Request
823 if ((priv
->psstate
== PS_STATE_SLEEP
) ||
824 (priv
->psstate
== PS_STATE_PRE_SLEEP
))
827 /* Execute the next command */
828 if (!priv
->dnld_sent
&& !priv
->cur_cmd
)
829 lbs_execute_next_command(priv
);
831 /* Wake-up command waiters which can't sleep in
832 * lbs_prepare_and_send_command
834 if (!list_empty(&priv
->cmdpendingq
))
835 wake_up_all(&priv
->cmd_pending
);
837 spin_lock_irq(&priv
->driver_lock
);
838 if (!priv
->dnld_sent
&& priv
->tx_pending_len
> 0) {
839 int ret
= priv
->hw_host_to_card(priv
, MVMS_DAT
,
840 priv
->tx_pending_buf
,
841 priv
->tx_pending_len
);
843 lbs_deb_tx("host_to_card failed %d\n", ret
);
844 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
846 priv
->tx_pending_len
= 0;
847 if (!priv
->currenttxskb
) {
848 /* We can wake the queues immediately if we aren't
849 waiting for TX feedback */
850 if (priv
->connect_status
== LBS_CONNECTED
)
851 netif_wake_queue(priv
->dev
);
852 if (priv
->mesh_dev
&&
853 priv
->mesh_connect_status
== LBS_CONNECTED
)
854 netif_wake_queue(priv
->mesh_dev
);
857 spin_unlock_irq(&priv
->driver_lock
);
860 del_timer(&priv
->command_timer
);
861 wake_up_all(&priv
->cmd_pending
);
863 lbs_deb_leave(LBS_DEB_THREAD
);
867 static int lbs_suspend_callback(struct lbs_private
*priv
, unsigned long dummy
,
868 struct cmd_header
*cmd
)
870 lbs_deb_enter(LBS_DEB_FW
);
872 netif_device_detach(priv
->dev
);
874 netif_device_detach(priv
->mesh_dev
);
877 lbs_deb_leave(LBS_DEB_FW
);
881 int lbs_suspend(struct lbs_private
*priv
)
883 struct cmd_header cmd
;
886 lbs_deb_enter(LBS_DEB_FW
);
888 if (priv
->wol_criteria
== 0xffffffff) {
889 lbs_pr_info("Suspend attempt without configuring wake params!\n");
893 memset(&cmd
, 0, sizeof(cmd
));
895 ret
= __lbs_cmd(priv
, CMD_802_11_HOST_SLEEP_ACTIVATE
, &cmd
,
896 sizeof(cmd
), lbs_suspend_callback
, 0);
898 lbs_pr_info("HOST_SLEEP_ACTIVATE failed: %d\n", ret
);
900 lbs_deb_leave_args(LBS_DEB_FW
, "ret %d", ret
);
903 EXPORT_SYMBOL_GPL(lbs_suspend
);
905 int lbs_resume(struct lbs_private
*priv
)
907 lbs_deb_enter(LBS_DEB_FW
);
911 /* Firmware doesn't seem to give us RX packets any more
912 until we send it some command. Might as well update */
913 lbs_prepare_and_send_command(priv
, CMD_802_11_RSSI
, 0,
916 netif_device_attach(priv
->dev
);
918 netif_device_attach(priv
->mesh_dev
);
920 lbs_deb_leave(LBS_DEB_FW
);
923 EXPORT_SYMBOL_GPL(lbs_resume
);
926 * @brief This function downloads firmware image, gets
927 * HW spec from firmware and set basic parameters to
930 * @param priv A pointer to struct lbs_private structure
933 static int lbs_setup_firmware(struct lbs_private
*priv
)
937 lbs_deb_enter(LBS_DEB_FW
);
940 * Read MAC address from HW
942 memset(priv
->current_addr
, 0xff, ETH_ALEN
);
943 ret
= lbs_update_hw_spec(priv
);
949 lbs_set_mac_control(priv
);
951 ret
= lbs_get_data_rate(priv
);
959 lbs_deb_leave_args(LBS_DEB_FW
, "ret %d", ret
);
964 * This function handles the timeout of command sending.
965 * It will re-send the same command again.
967 static void command_timer_fn(unsigned long data
)
969 struct lbs_private
*priv
= (struct lbs_private
*)data
;
972 lbs_deb_enter(LBS_DEB_CMD
);
973 spin_lock_irqsave(&priv
->driver_lock
, flags
);
975 if (!priv
->cur_cmd
) {
976 lbs_pr_info("Command timer expired; no pending command\n");
980 lbs_pr_info("Command %x timed out\n", le16_to_cpu(priv
->cur_cmd
->cmdbuf
->command
));
982 priv
->cmd_timed_out
= 1;
983 wake_up_interruptible(&priv
->waitq
);
985 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
986 lbs_deb_leave(LBS_DEB_CMD
);
989 static void lbs_sync_channel_worker(struct work_struct
*work
)
991 struct lbs_private
*priv
= container_of(work
, struct lbs_private
,
994 lbs_deb_enter(LBS_DEB_MAIN
);
995 if (lbs_update_channel(priv
))
996 lbs_pr_info("Channel synchronization failed.");
997 lbs_deb_leave(LBS_DEB_MAIN
);
1001 static int lbs_init_adapter(struct lbs_private
*priv
)
1006 lbs_deb_enter(LBS_DEB_MAIN
);
1008 /* Allocate buffer to store the BSSID list */
1009 bufsize
= MAX_NETWORK_COUNT
* sizeof(struct bss_descriptor
);
1010 priv
->networks
= kzalloc(bufsize
, GFP_KERNEL
);
1011 if (!priv
->networks
) {
1012 lbs_pr_err("Out of memory allocating beacons\n");
1017 /* Initialize scan result lists */
1018 INIT_LIST_HEAD(&priv
->network_free_list
);
1019 INIT_LIST_HEAD(&priv
->network_list
);
1020 for (i
= 0; i
< MAX_NETWORK_COUNT
; i
++) {
1021 list_add_tail(&priv
->networks
[i
].list
,
1022 &priv
->network_free_list
);
1025 memset(priv
->current_addr
, 0xff, ETH_ALEN
);
1027 priv
->connect_status
= LBS_DISCONNECTED
;
1028 priv
->mesh_connect_status
= LBS_DISCONNECTED
;
1029 priv
->secinfo
.auth_mode
= IW_AUTH_ALG_OPEN_SYSTEM
;
1030 priv
->mode
= IW_MODE_INFRA
;
1031 priv
->curbssparams
.channel
= DEFAULT_AD_HOC_CHANNEL
;
1032 priv
->mac_control
= CMD_ACT_MAC_RX_ON
| CMD_ACT_MAC_TX_ON
;
1033 priv
->radioon
= RADIO_ON
;
1034 priv
->auto_rate
= 1;
1035 priv
->capability
= WLAN_CAPABILITY_SHORT_PREAMBLE
;
1036 priv
->psmode
= LBS802_11POWERMODECAM
;
1037 priv
->psstate
= PS_STATE_FULL_POWER
;
1039 mutex_init(&priv
->lock
);
1041 setup_timer(&priv
->command_timer
, command_timer_fn
,
1042 (unsigned long)priv
);
1044 INIT_LIST_HEAD(&priv
->cmdfreeq
);
1045 INIT_LIST_HEAD(&priv
->cmdpendingq
);
1047 spin_lock_init(&priv
->driver_lock
);
1048 init_waitqueue_head(&priv
->cmd_pending
);
1050 /* Allocate the command buffers */
1051 if (lbs_allocate_cmd_buffer(priv
)) {
1052 lbs_pr_err("Out of memory allocating command buffers\n");
1057 priv
->resp_len
[0] = priv
->resp_len
[1] = 0;
1059 /* Create the event FIFO */
1060 priv
->event_fifo
= kfifo_alloc(sizeof(u32
) * 16, GFP_KERNEL
, NULL
);
1061 if (IS_ERR(priv
->event_fifo
)) {
1062 lbs_pr_err("Out of memory allocating event FIFO buffer\n");
1068 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1073 static void lbs_free_adapter(struct lbs_private
*priv
)
1075 lbs_deb_enter(LBS_DEB_MAIN
);
1077 lbs_free_cmd_buffer(priv
);
1078 if (priv
->event_fifo
)
1079 kfifo_free(priv
->event_fifo
);
1080 del_timer(&priv
->command_timer
);
1081 kfree(priv
->networks
);
1082 priv
->networks
= NULL
;
1084 lbs_deb_leave(LBS_DEB_MAIN
);
1088 * @brief This function adds the card. it will probe the
1089 * card, allocate the lbs_priv and initialize the device.
1091 * @param card A pointer to card
1092 * @return A pointer to struct lbs_private structure
1094 struct lbs_private
*lbs_add_card(void *card
, struct device
*dmdev
)
1096 struct net_device
*dev
= NULL
;
1097 struct lbs_private
*priv
= NULL
;
1099 lbs_deb_enter(LBS_DEB_MAIN
);
1101 /* Allocate an Ethernet device and register it */
1102 dev
= alloc_etherdev(sizeof(struct lbs_private
));
1104 lbs_pr_err("init ethX device failed\n");
1109 if (lbs_init_adapter(priv
)) {
1110 lbs_pr_err("failed to initialize adapter structure.\n");
1111 goto err_init_adapter
;
1116 priv
->mesh_open
= 0;
1117 priv
->infra_open
= 0;
1119 /* Setup the OS Interface to our functions */
1120 dev
->open
= lbs_dev_open
;
1121 dev
->hard_start_xmit
= lbs_hard_start_xmit
;
1122 dev
->stop
= lbs_eth_stop
;
1123 dev
->set_mac_address
= lbs_set_mac_address
;
1124 dev
->tx_timeout
= lbs_tx_timeout
;
1125 dev
->do_ioctl
= lbs_do_ioctl
;
1126 dev
->get_stats
= lbs_get_stats
;
1127 dev
->watchdog_timeo
= 5 * HZ
;
1128 dev
->ethtool_ops
= &lbs_ethtool_ops
;
1130 dev
->wireless_handlers
= (struct iw_handler_def
*)&lbs_handler_def
;
1132 dev
->flags
|= IFF_BROADCAST
| IFF_MULTICAST
;
1133 dev
->set_multicast_list
= lbs_set_multicast_list
;
1135 SET_NETDEV_DEV(dev
, dmdev
);
1137 priv
->rtap_net_dev
= NULL
;
1139 lbs_deb_thread("Starting main thread...\n");
1140 init_waitqueue_head(&priv
->waitq
);
1141 priv
->main_thread
= kthread_run(lbs_thread
, dev
, "lbs_main");
1142 if (IS_ERR(priv
->main_thread
)) {
1143 lbs_deb_thread("Error creating main thread.\n");
1144 goto err_init_adapter
;
1147 priv
->work_thread
= create_singlethread_workqueue("lbs_worker");
1148 INIT_DELAYED_WORK(&priv
->assoc_work
, lbs_association_worker
);
1149 INIT_DELAYED_WORK(&priv
->scan_work
, lbs_scan_worker
);
1150 INIT_WORK(&priv
->sync_channel
, lbs_sync_channel_worker
);
1152 sprintf(priv
->mesh_ssid
, "mesh");
1153 priv
->mesh_ssid_len
= 4;
1155 priv
->wol_criteria
= 0xffffffff;
1156 priv
->wol_gpio
= 0xff;
1161 lbs_free_adapter(priv
);
1166 lbs_deb_leave_args(LBS_DEB_MAIN
, "priv %p", priv
);
1169 EXPORT_SYMBOL_GPL(lbs_add_card
);
1172 int lbs_remove_card(struct lbs_private
*priv
)
1174 struct net_device
*dev
= priv
->dev
;
1175 union iwreq_data wrqu
;
1177 lbs_deb_enter(LBS_DEB_MAIN
);
1179 lbs_remove_mesh(priv
);
1180 lbs_remove_rtap(priv
);
1184 cancel_delayed_work(&priv
->scan_work
);
1185 cancel_delayed_work(&priv
->assoc_work
);
1186 destroy_workqueue(priv
->work_thread
);
1188 if (priv
->psmode
== LBS802_11POWERMODEMAX_PSP
) {
1189 priv
->psmode
= LBS802_11POWERMODECAM
;
1190 lbs_ps_wakeup(priv
, CMD_OPTION_WAITFORRSP
);
1193 memset(wrqu
.ap_addr
.sa_data
, 0xaa, ETH_ALEN
);
1194 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1195 wireless_send_event(priv
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
1197 /* Stop the thread servicing the interrupts */
1198 priv
->surpriseremoved
= 1;
1199 kthread_stop(priv
->main_thread
);
1201 lbs_free_adapter(priv
);
1206 lbs_deb_leave(LBS_DEB_MAIN
);
1209 EXPORT_SYMBOL_GPL(lbs_remove_card
);
1212 int lbs_start_card(struct lbs_private
*priv
)
1214 struct net_device
*dev
= priv
->dev
;
1217 lbs_deb_enter(LBS_DEB_MAIN
);
1219 /* poke the firmware */
1220 ret
= lbs_setup_firmware(priv
);
1227 if (register_netdev(dev
)) {
1228 lbs_pr_err("cannot register ethX device\n");
1231 if (device_create_file(&dev
->dev
, &dev_attr_lbs_rtap
))
1232 lbs_pr_err("cannot register lbs_rtap attribute\n");
1234 lbs_update_channel(priv
);
1236 /* 5.0.16p0 is known to NOT support any mesh */
1237 if (priv
->fwrelease
> 0x05001000) {
1238 /* Enable mesh, if supported, and work out which TLV it uses.
1239 0x100 + 291 is an unofficial value used in 5.110.20.pXX
1240 0x100 + 37 is the official value used in 5.110.21.pXX
1241 but we check them in that order because 20.pXX doesn't
1242 give an error -- it just silently fails. */
1244 /* 5.110.20.pXX firmware will fail the command if the channel
1245 doesn't match the existing channel. But only if the TLV
1246 is correct. If the channel is wrong, _BOTH_ versions will
1247 give an error to 0x100+291, and allow 0x100+37 to succeed.
1248 It's just that 5.110.20.pXX will not have done anything
1251 priv
->mesh_tlv
= 0x100 + 291;
1252 if (lbs_mesh_config(priv
, 1, priv
->curbssparams
.channel
)) {
1253 priv
->mesh_tlv
= 0x100 + 37;
1254 if (lbs_mesh_config(priv
, 1, priv
->curbssparams
.channel
))
1257 if (priv
->mesh_tlv
) {
1260 if (device_create_file(&dev
->dev
, &dev_attr_lbs_mesh
))
1261 lbs_pr_err("cannot register lbs_mesh attribute\n");
1265 lbs_debugfs_init_one(priv
, dev
);
1267 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev
->name
);
1272 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1275 EXPORT_SYMBOL_GPL(lbs_start_card
);
1278 int lbs_stop_card(struct lbs_private
*priv
)
1280 struct net_device
*dev
= priv
->dev
;
1282 struct cmd_ctrl_node
*cmdnode
;
1283 unsigned long flags
;
1285 lbs_deb_enter(LBS_DEB_MAIN
);
1287 netif_stop_queue(priv
->dev
);
1288 netif_carrier_off(priv
->dev
);
1290 lbs_debugfs_remove_one(priv
);
1291 device_remove_file(&dev
->dev
, &dev_attr_lbs_rtap
);
1293 device_remove_file(&dev
->dev
, &dev_attr_lbs_mesh
);
1295 /* Flush pending command nodes */
1296 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1297 list_for_each_entry(cmdnode
, &priv
->cmdpendingq
, list
) {
1298 cmdnode
->result
= -ENOENT
;
1299 cmdnode
->cmdwaitqwoken
= 1;
1300 wake_up_interruptible(&cmdnode
->cmdwait_q
);
1302 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1304 unregister_netdev(dev
);
1306 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1309 EXPORT_SYMBOL_GPL(lbs_stop_card
);
1313 * @brief This function adds mshX interface
1315 * @param priv A pointer to the struct lbs_private structure
1316 * @return 0 if successful, -X otherwise
1318 static int lbs_add_mesh(struct lbs_private
*priv
)
1320 struct net_device
*mesh_dev
= NULL
;
1323 lbs_deb_enter(LBS_DEB_MESH
);
1325 /* Allocate a virtual mesh device */
1326 if (!(mesh_dev
= alloc_netdev(0, "msh%d", ether_setup
))) {
1327 lbs_deb_mesh("init mshX device failed\n");
1331 mesh_dev
->priv
= priv
;
1332 priv
->mesh_dev
= mesh_dev
;
1334 mesh_dev
->open
= lbs_dev_open
;
1335 mesh_dev
->hard_start_xmit
= lbs_hard_start_xmit
;
1336 mesh_dev
->stop
= lbs_mesh_stop
;
1337 mesh_dev
->do_ioctl
= lbs_do_ioctl
;
1338 mesh_dev
->get_stats
= lbs_get_stats
;
1339 mesh_dev
->set_mac_address
= lbs_set_mac_address
;
1340 mesh_dev
->ethtool_ops
= &lbs_ethtool_ops
;
1341 memcpy(mesh_dev
->dev_addr
, priv
->dev
->dev_addr
,
1342 sizeof(priv
->dev
->dev_addr
));
1344 SET_NETDEV_DEV(priv
->mesh_dev
, priv
->dev
->dev
.parent
);
1347 mesh_dev
->wireless_handlers
= (struct iw_handler_def
*)&mesh_handler_def
;
1349 /* Register virtual mesh interface */
1350 ret
= register_netdev(mesh_dev
);
1352 lbs_pr_err("cannot register mshX virtual interface\n");
1356 ret
= sysfs_create_group(&(mesh_dev
->dev
.kobj
), &lbs_mesh_attr_group
);
1358 goto err_unregister
;
1360 /* Everything successful */
1365 unregister_netdev(mesh_dev
);
1368 free_netdev(mesh_dev
);
1371 lbs_deb_leave_args(LBS_DEB_MESH
, "ret %d", ret
);
1375 static void lbs_remove_mesh(struct lbs_private
*priv
)
1377 struct net_device
*mesh_dev
;
1380 mesh_dev
= priv
->mesh_dev
;
1384 lbs_deb_enter(LBS_DEB_MESH
);
1385 netif_stop_queue(mesh_dev
);
1386 netif_carrier_off(priv
->mesh_dev
);
1387 sysfs_remove_group(&(mesh_dev
->dev
.kobj
), &lbs_mesh_attr_group
);
1388 unregister_netdev(mesh_dev
);
1389 priv
->mesh_dev
= NULL
;
1390 free_netdev(mesh_dev
);
1391 lbs_deb_leave(LBS_DEB_MESH
);
1395 * @brief This function finds the CFP in
1396 * region_cfp_table based on region and band parameter.
1398 * @param region The region code
1399 * @param band The band
1400 * @param cfp_no A pointer to CFP number
1401 * @return A pointer to CFP
1403 struct chan_freq_power
*lbs_get_region_cfp_table(u8 region
, int *cfp_no
)
1407 lbs_deb_enter(LBS_DEB_MAIN
);
1409 end
= ARRAY_SIZE(region_cfp_table
);
1411 for (i
= 0; i
< end
; i
++) {
1412 lbs_deb_main("region_cfp_table[i].region=%d\n",
1413 region_cfp_table
[i
].region
);
1414 if (region_cfp_table
[i
].region
== region
) {
1415 *cfp_no
= region_cfp_table
[i
].cfp_no_BG
;
1416 lbs_deb_leave(LBS_DEB_MAIN
);
1417 return region_cfp_table
[i
].cfp_BG
;
1421 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret NULL");
1425 int lbs_set_regiontable(struct lbs_private
*priv
, u8 region
, u8 band
)
1430 struct chan_freq_power
*cfp
;
1433 lbs_deb_enter(LBS_DEB_MAIN
);
1435 memset(priv
->region_channel
, 0, sizeof(priv
->region_channel
));
1437 cfp
= lbs_get_region_cfp_table(region
, &cfp_no
);
1439 priv
->region_channel
[i
].nrcfp
= cfp_no
;
1440 priv
->region_channel
[i
].CFP
= cfp
;
1442 lbs_deb_main("wrong region code %#x in band B/G\n",
1447 priv
->region_channel
[i
].valid
= 1;
1448 priv
->region_channel
[i
].region
= region
;
1449 priv
->region_channel
[i
].band
= band
;
1452 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1456 void lbs_queue_event(struct lbs_private
*priv
, u32 event
)
1458 unsigned long flags
;
1460 lbs_deb_enter(LBS_DEB_THREAD
);
1461 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1463 if (priv
->psstate
== PS_STATE_SLEEP
)
1464 priv
->psstate
= PS_STATE_AWAKE
;
1466 __kfifo_put(priv
->event_fifo
, (unsigned char *) &event
, sizeof(u32
));
1468 wake_up_interruptible(&priv
->waitq
);
1470 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1471 lbs_deb_leave(LBS_DEB_THREAD
);
1473 EXPORT_SYMBOL_GPL(lbs_queue_event
);
1475 void lbs_notify_command_response(struct lbs_private
*priv
, u8 resp_idx
)
1477 lbs_deb_enter(LBS_DEB_THREAD
);
1479 if (priv
->psstate
== PS_STATE_SLEEP
)
1480 priv
->psstate
= PS_STATE_AWAKE
;
1482 /* Swap buffers by flipping the response index */
1483 BUG_ON(resp_idx
> 1);
1484 priv
->resp_idx
= resp_idx
;
1486 wake_up_interruptible(&priv
->waitq
);
1488 lbs_deb_leave(LBS_DEB_THREAD
);
1490 EXPORT_SYMBOL_GPL(lbs_notify_command_response
);
1492 static int __init
lbs_init_module(void)
1494 lbs_deb_enter(LBS_DEB_MAIN
);
1495 memset(&confirm_sleep
, 0, sizeof(confirm_sleep
));
1496 confirm_sleep
.hdr
.command
= cpu_to_le16(CMD_802_11_PS_MODE
);
1497 confirm_sleep
.hdr
.size
= cpu_to_le16(sizeof(confirm_sleep
));
1498 confirm_sleep
.action
= cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED
);
1500 lbs_deb_leave(LBS_DEB_MAIN
);
1504 static void __exit
lbs_exit_module(void)
1506 lbs_deb_enter(LBS_DEB_MAIN
);
1507 lbs_debugfs_remove();
1508 lbs_deb_leave(LBS_DEB_MAIN
);
1512 * rtap interface support fuctions
1515 static int lbs_rtap_open(struct net_device
*dev
)
1517 /* Yes, _stop_ the queue. Because we don't support injection */
1518 lbs_deb_enter(LBS_DEB_MAIN
);
1519 netif_carrier_off(dev
);
1520 netif_stop_queue(dev
);
1521 lbs_deb_leave(LBS_DEB_LEAVE
);
1525 static int lbs_rtap_stop(struct net_device
*dev
)
1527 lbs_deb_enter(LBS_DEB_MAIN
);
1528 lbs_deb_leave(LBS_DEB_MAIN
);
1532 static int lbs_rtap_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1534 netif_stop_queue(dev
);
1535 return NETDEV_TX_BUSY
;
1538 static struct net_device_stats
*lbs_rtap_get_stats(struct net_device
*dev
)
1540 struct lbs_private
*priv
= dev
->priv
;
1541 lbs_deb_enter(LBS_DEB_NET
);
1542 return &priv
->stats
;
1546 static void lbs_remove_rtap(struct lbs_private
*priv
)
1548 lbs_deb_enter(LBS_DEB_MAIN
);
1549 if (priv
->rtap_net_dev
== NULL
)
1551 unregister_netdev(priv
->rtap_net_dev
);
1552 free_netdev(priv
->rtap_net_dev
);
1553 priv
->rtap_net_dev
= NULL
;
1554 lbs_deb_leave(LBS_DEB_MAIN
);
1557 static int lbs_add_rtap(struct lbs_private
*priv
)
1560 struct net_device
*rtap_dev
;
1562 lbs_deb_enter(LBS_DEB_MAIN
);
1563 if (priv
->rtap_net_dev
) {
1568 rtap_dev
= alloc_netdev(0, "rtap%d", ether_setup
);
1569 if (rtap_dev
== NULL
) {
1574 memcpy(rtap_dev
->dev_addr
, priv
->current_addr
, ETH_ALEN
);
1575 rtap_dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
1576 rtap_dev
->open
= lbs_rtap_open
;
1577 rtap_dev
->stop
= lbs_rtap_stop
;
1578 rtap_dev
->get_stats
= lbs_rtap_get_stats
;
1579 rtap_dev
->hard_start_xmit
= lbs_rtap_hard_start_xmit
;
1580 rtap_dev
->set_multicast_list
= lbs_set_multicast_list
;
1581 rtap_dev
->priv
= priv
;
1582 SET_NETDEV_DEV(rtap_dev
, priv
->dev
->dev
.parent
);
1584 ret
= register_netdev(rtap_dev
);
1586 free_netdev(rtap_dev
);
1589 priv
->rtap_net_dev
= rtap_dev
;
1592 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1596 #ifndef CONFIG_IEEE80211
1597 const char *escape_essid(const char *essid
, u8 essid_len
)
1599 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
1600 const char *s
= essid
;
1603 if (ieee80211_is_empty_essid(essid
, essid_len
)) {
1604 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
1608 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
1609 while (essid_len
--) {
1623 module_init(lbs_init_module
);
1624 module_exit(lbs_exit_module
);
1626 MODULE_DESCRIPTION("Libertas WLAN Driver Library");
1627 MODULE_AUTHOR("Marvell International Ltd.");
1628 MODULE_LICENSE("GPL");