drivers/net: Add export.h to files using EXPORT_SYMBOL/THIS_MODULE
[deliverable/linux.git] / drivers / net / wireless / libertas / main.c
CommitLineData
8973a6e7
RD
1/*
2 * This file contains the major functions in WLAN
3 * driver. It includes init, exit, open, close and main
4 * thread etc..
5 */
876c9d3a 6
0e4e06ae
JP
7#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8
a46c6410 9#include <linux/moduleparam.h>
876c9d3a 10#include <linux/delay.h>
876c9d3a 11#include <linux/etherdevice.h>
a6b7a407 12#include <linux/hardirq.h>
876c9d3a
MT
13#include <linux/netdevice.h>
14#include <linux/if_arp.h>
fe336150 15#include <linux/kthread.h>
7919b89c 16#include <linux/kfifo.h>
5a0e3ad6 17#include <linux/slab.h>
ff9fc791 18#include <net/cfg80211.h>
876c9d3a
MT
19
20#include "host.h"
876c9d3a
MT
21#include "decl.h"
22#include "dev.h"
ff9fc791 23#include "cfg.h"
876c9d3a 24#include "debugfs.h"
6e66f03f 25#include "cmd.h"
49fee692 26#include "mesh.h"
876c9d3a 27
7856a541 28#define DRIVER_RELEASE_VERSION "323.p0"
10078321 29const char lbs_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
3ce40232
DW
30#ifdef DEBUG
31 "-dbg"
32#endif
33 "";
34
a46c6410
HS
35
36/* Module parameters */
10078321
HS
37unsigned int lbs_debug;
38EXPORT_SYMBOL_GPL(lbs_debug);
39module_param_named(libertas_debug, lbs_debug, int, 0644);
a46c6410 40
6bdbdbf4
SS
41unsigned int lbs_disablemesh;
42EXPORT_SYMBOL_GPL(lbs_disablemesh);
43module_param_named(libertas_disablemesh, lbs_disablemesh, int, 0644);
44
a46c6410 45
8973a6e7
RD
46/*
47 * This global structure is used to send the confirm_sleep command as
48 * fast as possible down to the firmware.
49 */
f539f2ef
HS
50struct cmd_confirm_sleep confirm_sleep;
51
52
8973a6e7 53/*
8c512765 54 * the table to keep region code
876c9d3a 55 */
10078321 56u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
8c512765 57 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
876c9d3a 58
8973a6e7 59/*
8c512765
DW
60 * FW rate table. FW refers to rates by their index in this table, not by the
61 * rate value itself. Values of 0x00 are
62 * reserved positions.
876c9d3a 63 */
8c512765
DW
64static u8 fw_data_rates[MAX_RATES] =
65 { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
66 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
67};
876c9d3a 68
876c9d3a 69/**
8973a6e7 70 * lbs_fw_index_to_data_rate - use index to get the data rate
8c512765 71 *
8973a6e7
RD
72 * @idx: The index of data rate
73 * returns: data rate or 0
876c9d3a 74 */
10078321 75u32 lbs_fw_index_to_data_rate(u8 idx)
8c512765
DW
76{
77 if (idx >= sizeof(fw_data_rates))
78 idx = 0;
79 return fw_data_rates[idx];
80}
81
82/**
8973a6e7 83 * lbs_data_rate_to_fw_index - use rate to get the index
8c512765 84 *
8973a6e7
RD
85 * @rate: data rate
86 * returns: index or 0
8c512765 87 */
10078321 88u8 lbs_data_rate_to_fw_index(u32 rate)
8c512765
DW
89{
90 u8 i;
91
92 if (!rate)
93 return 0;
94
95 for (i = 0; i < sizeof(fw_data_rates); i++) {
96 if (rate == fw_data_rates[i])
97 return i;
98 }
99 return 0;
100}
876c9d3a 101
5c1381ac
DD
102int lbs_set_iface_type(struct lbs_private *priv, enum nl80211_iftype type)
103{
104 int ret = 0;
105
106 switch (type) {
107 case NL80211_IFTYPE_MONITOR:
108 ret = lbs_set_monitor_mode(priv, 1);
109 break;
110 case NL80211_IFTYPE_STATION:
111 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
112 ret = lbs_set_monitor_mode(priv, 0);
113 if (!ret)
114 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 1);
115 break;
116 case NL80211_IFTYPE_ADHOC:
117 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
118 ret = lbs_set_monitor_mode(priv, 0);
119 if (!ret)
120 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 2);
121 break;
122 default:
123 ret = -ENOTSUPP;
124 }
125 return ret;
126}
127
d2e7b342
DD
128int lbs_start_iface(struct lbs_private *priv)
129{
130 struct cmd_ds_802_11_mac_address cmd;
131 int ret;
132
133 if (priv->power_restore) {
134 ret = priv->power_restore(priv);
135 if (ret)
136 return ret;
137 }
138
139 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
140 cmd.action = cpu_to_le16(CMD_ACT_SET);
141 memcpy(cmd.macadd, priv->current_addr, ETH_ALEN);
142
143 ret = lbs_cmd_with_response(priv, CMD_802_11_MAC_ADDRESS, &cmd);
144 if (ret) {
145 lbs_deb_net("set MAC address failed\n");
146 goto err;
147 }
148
5c1381ac
DD
149 ret = lbs_set_iface_type(priv, priv->wdev->iftype);
150 if (ret) {
151 lbs_deb_net("set iface type failed\n");
152 goto err;
153 }
154
d2e7b342
DD
155 lbs_update_channel(priv);
156
157 priv->iface_running = true;
158 return 0;
159
160err:
161 if (priv->power_save)
162 priv->power_save(priv);
163 return ret;
164}
6fb53252 165
23a397ac 166/**
8973a6e7 167 * lbs_dev_open - open the ethX interface
876c9d3a 168 *
8973a6e7
RD
169 * @dev: A pointer to &net_device structure
170 * returns: 0 or -EBUSY if monitor mode active
876c9d3a 171 */
10078321 172static int lbs_dev_open(struct net_device *dev)
876c9d3a 173{
ab65f649 174 struct lbs_private *priv = dev->ml_priv;
8552855f 175 int ret = 0;
876c9d3a 176
61d30020 177 lbs_deb_enter(LBS_DEB_NET);
d2e7b342
DD
178 if (!priv->iface_running) {
179 ret = lbs_start_iface(priv);
180 if (ret)
181 goto out;
182 }
61d30020 183
8552855f 184 spin_lock_irq(&priv->driver_lock);
876c9d3a 185
d2e7b342 186 netif_carrier_off(dev);
876c9d3a 187
8552855f
DW
188 if (!priv->tx_pending_len)
189 netif_wake_queue(dev);
876c9d3a 190
8552855f 191 spin_unlock_irq(&priv->driver_lock);
d2e7b342
DD
192
193out:
61d30020 194 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
8552855f 195 return ret;
876c9d3a
MT
196}
197
d2e7b342
DD
198static bool lbs_command_queue_empty(struct lbs_private *priv)
199{
200 unsigned long flags;
201 bool ret;
202 spin_lock_irqsave(&priv->driver_lock, flags);
203 ret = priv->cur_cmd == NULL && list_empty(&priv->cmdpendingq);
204 spin_unlock_irqrestore(&priv->driver_lock, flags);
205 return ret;
206}
207
208int lbs_stop_iface(struct lbs_private *priv)
209{
210 unsigned long flags;
211 int ret = 0;
212
213 lbs_deb_enter(LBS_DEB_MAIN);
214
215 spin_lock_irqsave(&priv->driver_lock, flags);
216 priv->iface_running = false;
217 kfree_skb(priv->currenttxskb);
218 priv->currenttxskb = NULL;
219 priv->tx_pending_len = 0;
220 spin_unlock_irqrestore(&priv->driver_lock, flags);
221
222 cancel_work_sync(&priv->mcast_work);
8f641d93 223 del_timer_sync(&priv->tx_lockup_timer);
d2e7b342
DD
224
225 /* Disable command processing, and wait for all commands to complete */
226 lbs_deb_main("waiting for commands to complete\n");
227 wait_event(priv->waitq, lbs_command_queue_empty(priv));
228 lbs_deb_main("all commands completed\n");
229
230 if (priv->power_save)
231 ret = priv->power_save(priv);
232
233 lbs_deb_leave(LBS_DEB_MAIN);
234 return ret;
235}
236
876c9d3a 237/**
8973a6e7 238 * lbs_eth_stop - close the ethX interface
876c9d3a 239 *
8973a6e7
RD
240 * @dev: A pointer to &net_device structure
241 * returns: 0
876c9d3a 242 */
8552855f 243static int lbs_eth_stop(struct net_device *dev)
78523daa 244{
ab65f649 245 struct lbs_private *priv = dev->ml_priv;
876c9d3a 246
61d30020 247 lbs_deb_enter(LBS_DEB_NET);
8552855f 248
d2e7b342
DD
249 if (priv->connect_status == LBS_CONNECTED)
250 lbs_disconnect(priv, WLAN_REASON_DEAUTH_LEAVING);
251
61d30020 252 spin_lock_irq(&priv->driver_lock);
8552855f 253 netif_stop_queue(dev);
8552855f 254 spin_unlock_irq(&priv->driver_lock);
61d30020 255
d2e7b342 256 lbs_update_mcast(priv);
2e30168b
DD
257 cancel_delayed_work_sync(&priv->scan_work);
258 if (priv->scan_req) {
259 cfg80211_scan_done(priv->scan_req, false);
260 priv->scan_req = NULL;
261 }
75bf45a7 262
d2e7b342
DD
263 netif_carrier_off(priv->dev);
264
265 if (!lbs_iface_active(priv))
266 lbs_stop_iface(priv);
267
61d30020 268 lbs_deb_leave(LBS_DEB_NET);
8552855f 269 return 0;
876c9d3a
MT
270}
271
e775ed7c
DW
272void lbs_host_to_card_done(struct lbs_private *priv)
273{
a63b22bb
DW
274 unsigned long flags;
275
61d30020
HS
276 lbs_deb_enter(LBS_DEB_THREAD);
277
a63b22bb 278 spin_lock_irqsave(&priv->driver_lock, flags);
8f641d93 279 del_timer(&priv->tx_lockup_timer);
e775ed7c
DW
280
281 priv->dnld_sent = DNLD_RES_RECEIVED;
282
283 /* Wake main thread if commands are pending */
49125454
AK
284 if (!priv->cur_cmd || priv->tx_pending_len > 0) {
285 if (!priv->wakeup_dev_required)
d2e7b342 286 wake_up(&priv->waitq);
49125454 287 }
e775ed7c 288
a63b22bb 289 spin_unlock_irqrestore(&priv->driver_lock, flags);
61d30020 290 lbs_deb_leave(LBS_DEB_THREAD);
e775ed7c
DW
291}
292EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
293
e0e42da3 294int lbs_set_mac_address(struct net_device *dev, void *addr)
876c9d3a
MT
295{
296 int ret = 0;
ab65f649 297 struct lbs_private *priv = dev->ml_priv;
876c9d3a
MT
298 struct sockaddr *phwaddr = addr;
299
9012b28a 300 lbs_deb_enter(LBS_DEB_NET);
876c9d3a 301
d2e7b342
DD
302 /*
303 * Can only set MAC address when all interfaces are down, to be written
304 * to the hardware when one of them is brought up.
305 */
306 if (lbs_iface_active(priv))
307 return -EBUSY;
308
0a0d08ac 309 /* In case it was called from the mesh device */
2af9f039 310 dev = priv->dev;
0a0d08ac 311
2af9f039
HS
312 memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN);
313 memcpy(dev->dev_addr, phwaddr->sa_data, ETH_ALEN);
78523daa 314 if (priv->mesh_dev)
2af9f039 315 memcpy(priv->mesh_dev->dev_addr, phwaddr->sa_data, ETH_ALEN);
876c9d3a 316
9012b28a 317 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
876c9d3a
MT
318 return ret;
319}
320
75bf45a7
DW
321
322static inline int mac_in_list(unsigned char *list, int list_len,
323 unsigned char *mac)
876c9d3a 324{
75bf45a7
DW
325 while (list_len) {
326 if (!memcmp(list, mac, ETH_ALEN))
327 return 1;
328 list += ETH_ALEN;
329 list_len--;
330 }
331 return 0;
332}
333
876c9d3a 334
75bf45a7
DW
335static int lbs_add_mcast_addrs(struct cmd_ds_mac_multicast_adr *cmd,
336 struct net_device *dev, int nr_addrs)
337{
338 int i = nr_addrs;
22bedad3 339 struct netdev_hw_addr *ha;
655ffee2 340 int cnt;
75bf45a7
DW
341
342 if ((dev->flags & (IFF_UP|IFF_MULTICAST)) != (IFF_UP|IFF_MULTICAST))
343 return nr_addrs;
344
b9e40857 345 netif_addr_lock_bh(dev);
655ffee2 346 cnt = netdev_mc_count(dev);
22bedad3
JP
347 netdev_for_each_mc_addr(ha, dev) {
348 if (mac_in_list(cmd->maclist, nr_addrs, ha->addr)) {
e174961c 349 lbs_deb_net("mcast address %s:%pM skipped\n", dev->name,
22bedad3 350 ha->addr);
655ffee2 351 cnt--;
75bf45a7
DW
352 continue;
353 }
876c9d3a 354
75bf45a7
DW
355 if (i == MRVDRV_MAX_MULTICAST_LIST_SIZE)
356 break;
22bedad3 357 memcpy(&cmd->maclist[6*i], ha->addr, ETH_ALEN);
e174961c 358 lbs_deb_net("mcast address %s:%pM added to filter\n", dev->name,
22bedad3 359 ha->addr);
75bf45a7 360 i++;
655ffee2 361 cnt--;
876c9d3a 362 }
b9e40857 363 netif_addr_unlock_bh(dev);
655ffee2 364 if (cnt)
75bf45a7
DW
365 return -EOVERFLOW;
366
876c9d3a 367 return i;
876c9d3a
MT
368}
369
d2e7b342 370void lbs_update_mcast(struct lbs_private *priv)
876c9d3a 371{
75bf45a7 372 struct cmd_ds_mac_multicast_adr mcast_cmd;
d2e7b342 373 int dev_flags = 0;
75bf45a7
DW
374 int nr_addrs;
375 int old_mac_control = priv->mac_control;
876c9d3a 376
9012b28a 377 lbs_deb_enter(LBS_DEB_NET);
876c9d3a 378
d2e7b342
DD
379 if (netif_running(priv->dev))
380 dev_flags |= priv->dev->flags;
381 if (priv->mesh_dev && netif_running(priv->mesh_dev))
75bf45a7
DW
382 dev_flags |= priv->mesh_dev->flags;
383
384 if (dev_flags & IFF_PROMISC) {
385 priv->mac_control |= CMD_ACT_MAC_PROMISCUOUS_ENABLE;
386 priv->mac_control &= ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE |
387 CMD_ACT_MAC_MULTICAST_ENABLE);
388 goto out_set_mac_control;
389 } else if (dev_flags & IFF_ALLMULTI) {
390 do_allmulti:
391 priv->mac_control |= CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
392 priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE |
393 CMD_ACT_MAC_MULTICAST_ENABLE);
394 goto out_set_mac_control;
876c9d3a
MT
395 }
396
75bf45a7
DW
397 /* Once for priv->dev, again for priv->mesh_dev if it exists */
398 nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->dev, 0);
399 if (nr_addrs >= 0 && priv->mesh_dev)
400 nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->mesh_dev, nr_addrs);
401 if (nr_addrs < 0)
402 goto do_allmulti;
403
404 if (nr_addrs) {
405 int size = offsetof(struct cmd_ds_mac_multicast_adr,
406 maclist[6*nr_addrs]);
407
408 mcast_cmd.action = cpu_to_le16(CMD_ACT_SET);
409 mcast_cmd.hdr.size = cpu_to_le16(size);
410 mcast_cmd.nr_of_adrs = cpu_to_le16(nr_addrs);
411
412 lbs_cmd_async(priv, CMD_MAC_MULTICAST_ADR, &mcast_cmd.hdr, size);
413
414 priv->mac_control |= CMD_ACT_MAC_MULTICAST_ENABLE;
415 } else
416 priv->mac_control &= ~CMD_ACT_MAC_MULTICAST_ENABLE;
417
418 priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE |
419 CMD_ACT_MAC_ALL_MULTICAST_ENABLE);
420 out_set_mac_control:
d9e9778c
HS
421 if (priv->mac_control != old_mac_control)
422 lbs_set_mac_control(priv);
876c9d3a 423
9012b28a 424 lbs_deb_leave(LBS_DEB_NET);
876c9d3a
MT
425}
426
d2e7b342
DD
427static void lbs_set_mcast_worker(struct work_struct *work)
428{
429 struct lbs_private *priv = container_of(work, struct lbs_private, mcast_work);
430 lbs_update_mcast(priv);
431}
432
e0e42da3 433void lbs_set_multicast_list(struct net_device *dev)
75bf45a7 434{
ab65f649 435 struct lbs_private *priv = dev->ml_priv;
75bf45a7
DW
436
437 schedule_work(&priv->mcast_work);
438}
439
876c9d3a 440/**
8973a6e7 441 * lbs_thread - handles the major jobs in the LBS driver.
9012b28a
HS
442 * It handles all events generated by firmware, RX data received
443 * from firmware and TX data sent from kernel.
876c9d3a 444 *
8973a6e7
RD
445 * @data: A pointer to &lbs_thread structure
446 * returns: 0
876c9d3a 447 */
10078321 448static int lbs_thread(void *data)
876c9d3a 449{
fe336150 450 struct net_device *dev = data;
ab65f649 451 struct lbs_private *priv = dev->ml_priv;
876c9d3a 452 wait_queue_t wait;
876c9d3a 453
9012b28a 454 lbs_deb_enter(LBS_DEB_THREAD);
876c9d3a 455
876c9d3a
MT
456 init_waitqueue_entry(&wait, current);
457
458 for (;;) {
b8d40bc9 459 int shouldsleep;
7919b89c 460 u8 resp_idx;
b8d40bc9 461
7919b89c
HS
462 lbs_deb_thread("1: currenttxskb %p, dnld_sent %d\n",
463 priv->currenttxskb, priv->dnld_sent);
876c9d3a 464
fe336150 465 add_wait_queue(&priv->waitq, &wait);
876c9d3a 466 set_current_state(TASK_INTERRUPTIBLE);
aa21c004 467 spin_lock_irq(&priv->driver_lock);
59f3e4bf 468
d9f88705 469 if (kthread_should_stop())
b8d40bc9 470 shouldsleep = 0; /* Bye */
d9f88705
DW
471 else if (priv->surpriseremoved)
472 shouldsleep = 1; /* We need to wait until we're _told_ to die */
b8d40bc9
DW
473 else if (priv->psstate == PS_STATE_SLEEP)
474 shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */
2a345099
DW
475 else if (priv->cmd_timed_out)
476 shouldsleep = 0; /* Command timed out. Recover */
b15152a4
DW
477 else if (!priv->fw_ready)
478 shouldsleep = 1; /* Firmware not ready. We're waiting for it */
b8d40bc9
DW
479 else if (priv->dnld_sent)
480 shouldsleep = 1; /* Something is en route to the device already */
2eb188a1
DW
481 else if (priv->tx_pending_len > 0)
482 shouldsleep = 0; /* We've a packet to send */
ef707b83
HS
483 else if (priv->resp_len[priv->resp_idx])
484 shouldsleep = 0; /* We have a command response */
b8d40bc9
DW
485 else if (priv->cur_cmd)
486 shouldsleep = 1; /* Can't send a command; one already running */
49125454
AK
487 else if (!list_empty(&priv->cmdpendingq) &&
488 !(priv->wakeup_dev_required))
b8d40bc9 489 shouldsleep = 0; /* We have a command to send */
e64c026d 490 else if (kfifo_len(&priv->event_fifo))
7919b89c 491 shouldsleep = 0; /* We have an event to process */
b8d40bc9
DW
492 else
493 shouldsleep = 1; /* No command */
494
495 if (shouldsleep) {
7919b89c 496 lbs_deb_thread("sleeping, connect_status %d, "
5f505d90 497 "psmode %d, psstate %d\n",
7919b89c
HS
498 priv->connect_status,
499 priv->psmode, priv->psstate);
aa21c004 500 spin_unlock_irq(&priv->driver_lock);
876c9d3a
MT
501 schedule();
502 } else
aa21c004 503 spin_unlock_irq(&priv->driver_lock);
876c9d3a 504
7919b89c
HS
505 lbs_deb_thread("2: currenttxskb %p, dnld_send %d\n",
506 priv->currenttxskb, priv->dnld_sent);
876c9d3a
MT
507
508 set_current_state(TASK_RUNNING);
fe336150 509 remove_wait_queue(&priv->waitq, &wait);
876c9d3a 510
7919b89c
HS
511 lbs_deb_thread("3: currenttxskb %p, dnld_sent %d\n",
512 priv->currenttxskb, priv->dnld_sent);
876c9d3a 513
d9f88705 514 if (kthread_should_stop()) {
7919b89c 515 lbs_deb_thread("break from main thread\n");
876c9d3a
MT
516 break;
517 }
518
d9f88705
DW
519 if (priv->surpriseremoved) {
520 lbs_deb_thread("adapter removed; waiting to die...\n");
521 continue;
522 }
876c9d3a 523
7919b89c
HS
524 lbs_deb_thread("4: currenttxskb %p, dnld_sent %d\n",
525 priv->currenttxskb, priv->dnld_sent);
59f3e4bf 526
7919b89c 527 /* Process any pending command response */
a01f5450 528 spin_lock_irq(&priv->driver_lock);
7919b89c
HS
529 resp_idx = priv->resp_idx;
530 if (priv->resp_len[resp_idx]) {
aa21c004 531 spin_unlock_irq(&priv->driver_lock);
7919b89c
HS
532 lbs_process_command_response(priv,
533 priv->resp_buf[resp_idx],
534 priv->resp_len[resp_idx]);
aa21c004 535 spin_lock_irq(&priv->driver_lock);
7919b89c 536 priv->resp_len[resp_idx] = 0;
876c9d3a 537 }
7919b89c 538 spin_unlock_irq(&priv->driver_lock);
876c9d3a 539
49125454
AK
540 /* Process hardware events, e.g. card removed, link lost */
541 spin_lock_irq(&priv->driver_lock);
e64c026d 542 while (kfifo_len(&priv->event_fifo)) {
49125454 543 u32 event;
7acd72eb 544
9842c38e
SS
545 if (kfifo_out(&priv->event_fifo,
546 (unsigned char *) &event, sizeof(event)) !=
547 sizeof(event))
548 break;
49125454
AK
549 spin_unlock_irq(&priv->driver_lock);
550 lbs_process_event(priv, event);
551 spin_lock_irq(&priv->driver_lock);
552 }
553 spin_unlock_irq(&priv->driver_lock);
554
555 if (priv->wakeup_dev_required) {
556 lbs_deb_thread("Waking up device...\n");
557 /* Wake up device */
558 if (priv->exit_deep_sleep(priv))
559 lbs_deb_thread("Wakeup device failed\n");
560 continue;
561 }
562
7919b89c 563 /* command timeout stuff */
2a345099
DW
564 if (priv->cmd_timed_out && priv->cur_cmd) {
565 struct cmd_ctrl_node *cmdnode = priv->cur_cmd;
566
f3a57fd1
JP
567 netdev_info(dev, "Timeout submitting command 0x%04x\n",
568 le16_to_cpu(cmdnode->cmdbuf->command));
40e6fa82
HS
569 lbs_complete_command(priv, cmdnode, -ETIMEDOUT);
570 if (priv->reset_card)
571 priv->reset_card(priv);
2a345099
DW
572 }
573 priv->cmd_timed_out = 0;
574
b15152a4
DW
575 if (!priv->fw_ready)
576 continue;
577
876c9d3a 578 /* Check if we need to confirm Sleep Request received previously */
aa21c004
DW
579 if (priv->psstate == PS_STATE_PRE_SLEEP &&
580 !priv->dnld_sent && !priv->cur_cmd) {
581 if (priv->connect_status == LBS_CONNECTED) {
7919b89c
HS
582 lbs_deb_thread("pre-sleep, currenttxskb %p, "
583 "dnld_sent %d, cur_cmd %p\n",
584 priv->currenttxskb, priv->dnld_sent,
585 priv->cur_cmd);
59f3e4bf 586
d4ff0ef6 587 lbs_ps_confirm_sleep(priv);
59f3e4bf
DW
588 } else {
589 /* workaround for firmware sending
590 * deauth/linkloss event immediately
591 * after sleep request; remove this
592 * after firmware fixes it
593 */
aa21c004 594 priv->psstate = PS_STATE_AWAKE;
f3a57fd1
JP
595 netdev_alert(dev,
596 "ignore PS_SleepConfirm in non-connected state\n");
876c9d3a
MT
597 }
598 }
599
600 /* The PS state is changed during processing of Sleep Request
601 * event above
602 */
aa21c004
DW
603 if ((priv->psstate == PS_STATE_SLEEP) ||
604 (priv->psstate == PS_STATE_PRE_SLEEP))
876c9d3a
MT
605 continue;
606
49125454
AK
607 if (priv->is_deep_sleep)
608 continue;
609
876c9d3a 610 /* Execute the next command */
aa21c004 611 if (!priv->dnld_sent && !priv->cur_cmd)
10078321 612 lbs_execute_next_command(priv);
876c9d3a 613
2eb188a1
DW
614 spin_lock_irq(&priv->driver_lock);
615 if (!priv->dnld_sent && priv->tx_pending_len > 0) {
616 int ret = priv->hw_host_to_card(priv, MVMS_DAT,
617 priv->tx_pending_buf,
618 priv->tx_pending_len);
619 if (ret) {
620 lbs_deb_tx("host_to_card failed %d\n", ret);
621 priv->dnld_sent = DNLD_RES_RECEIVED;
8f641d93
DD
622 } else {
623 mod_timer(&priv->tx_lockup_timer,
624 jiffies + (HZ * 5));
2eb188a1
DW
625 }
626 priv->tx_pending_len = 0;
627 if (!priv->currenttxskb) {
628 /* We can wake the queues immediately if we aren't
629 waiting for TX feedback */
630 if (priv->connect_status == LBS_CONNECTED)
631 netif_wake_queue(priv->dev);
632 if (priv->mesh_dev &&
d9319986 633 netif_running(priv->mesh_dev))
2eb188a1
DW
634 netif_wake_queue(priv->mesh_dev);
635 }
636 }
637 spin_unlock_irq(&priv->driver_lock);
876c9d3a
MT
638 }
639
aa21c004 640 del_timer(&priv->command_timer);
8f641d93 641 del_timer(&priv->tx_lockup_timer);
49125454 642 del_timer(&priv->auto_deepsleep_timer);
876c9d3a 643
9012b28a 644 lbs_deb_leave(LBS_DEB_THREAD);
876c9d3a
MT
645 return 0;
646}
647
75abde4d 648/**
8973a6e7
RD
649 * lbs_setup_firmware - gets the HW spec from the firmware and sets
650 * some basic parameters
75abde4d 651 *
8973a6e7
RD
652 * @priv: A pointer to &struct lbs_private structure
653 * returns: 0 or -1
75abde4d
VK
654 */
655static int lbs_setup_firmware(struct lbs_private *priv)
656{
657 int ret = -1;
658 s16 curlevel = 0, minlevel = 0, maxlevel = 0;
659
660 lbs_deb_enter(LBS_DEB_FW);
661
662 /* Read MAC address from firmware */
663 memset(priv->current_addr, 0xff, ETH_ALEN);
664 ret = lbs_update_hw_spec(priv);
665 if (ret)
666 goto done;
667
668 /* Read power levels if available */
669 ret = lbs_get_tx_power(priv, &curlevel, &minlevel, &maxlevel);
670 if (ret == 0) {
671 priv->txpower_cur = curlevel;
672 priv->txpower_min = minlevel;
673 priv->txpower_max = maxlevel;
674 }
675
676 /* Send cmd to FW to enable 11D function */
677 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_11D_ENABLE, 1);
678
679 lbs_set_mac_control(priv);
680done:
681 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
682 return ret;
683}
684
ab25ecae
DW
685int lbs_suspend(struct lbs_private *priv)
686{
ab25ecae
DW
687 int ret;
688
61d30020
HS
689 lbs_deb_enter(LBS_DEB_FW);
690
66fceb69
AK
691 if (priv->is_deep_sleep) {
692 ret = lbs_set_deep_sleep(priv, 0);
693 if (ret) {
f3a57fd1
JP
694 netdev_err(priv->dev,
695 "deep sleep cancellation failed: %d\n", ret);
66fceb69
AK
696 return ret;
697 }
698 priv->deep_sleep_required = 1;
506e9025
DW
699 }
700
1311843c 701 ret = lbs_set_host_sleep(priv, 1);
7e226272 702
66fceb69
AK
703 netif_device_detach(priv->dev);
704 if (priv->mesh_dev)
705 netif_device_detach(priv->mesh_dev);
ab25ecae 706
61d30020 707 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
ab25ecae
DW
708 return ret;
709}
710EXPORT_SYMBOL_GPL(lbs_suspend);
711
66fceb69 712int lbs_resume(struct lbs_private *priv)
ab25ecae 713{
66fceb69 714 int ret;
61d30020 715
66fceb69 716 lbs_deb_enter(LBS_DEB_FW);
ab25ecae 717
1311843c 718 ret = lbs_set_host_sleep(priv, 0);
ab25ecae
DW
719
720 netif_device_attach(priv->dev);
721 if (priv->mesh_dev)
722 netif_device_attach(priv->mesh_dev);
723
66fceb69
AK
724 if (priv->deep_sleep_required) {
725 priv->deep_sleep_required = 0;
726 ret = lbs_set_deep_sleep(priv, 1);
727 if (ret)
f3a57fd1
JP
728 netdev_err(priv->dev,
729 "deep sleep activation failed: %d\n", ret);
66fceb69
AK
730 }
731
75abde4d
VK
732 if (priv->setup_fw_on_resume)
733 ret = lbs_setup_firmware(priv);
87c8c72d 734
1df4e8fe
HS
735 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
736 return ret;
737}
75abde4d 738EXPORT_SYMBOL_GPL(lbs_resume);
1df4e8fe 739
1df4e8fe 740/**
8973a6e7
RD
741 * lbs_cmd_timeout_handler - handles the timeout of command sending.
742 * It will re-send the same command again.
743 *
744 * @data: &struct lbs_private pointer
1df4e8fe 745 */
40e6fa82 746static void lbs_cmd_timeout_handler(unsigned long data)
1df4e8fe 747{
69f9032d 748 struct lbs_private *priv = (struct lbs_private *)data;
1df4e8fe
HS
749 unsigned long flags;
750
61d30020 751 lbs_deb_enter(LBS_DEB_CMD);
2a345099 752 spin_lock_irqsave(&priv->driver_lock, flags);
1df4e8fe 753
57962f0b 754 if (!priv->cur_cmd)
2a345099 755 goto out;
1df4e8fe 756
f3a57fd1
JP
757 netdev_info(priv->dev, "command 0x%04x timed out\n",
758 le16_to_cpu(priv->cur_cmd->cmdbuf->command));
1df4e8fe 759
2a345099 760 priv->cmd_timed_out = 1;
df90d843
DD
761
762 /*
763 * If the device didn't even acknowledge the command, reset the state
764 * so that we don't block all future commands due to this one timeout.
765 */
766 if (priv->dnld_sent == DNLD_CMD_SENT)
767 priv->dnld_sent = DNLD_RES_RECEIVED;
768
d2e7b342 769 wake_up(&priv->waitq);
61d30020 770out:
2a345099 771 spin_unlock_irqrestore(&priv->driver_lock, flags);
61d30020 772 lbs_deb_leave(LBS_DEB_CMD);
1df4e8fe
HS
773}
774
8f641d93
DD
775/**
776 * lbs_tx_lockup_handler - handles the timeout of the passing of TX frames
777 * to the hardware. This is known to frequently happen with SD8686 when
778 * waking up after a Wake-on-WLAN-triggered resume.
779 *
780 * @data: &struct lbs_private pointer
781 */
782static void lbs_tx_lockup_handler(unsigned long data)
783{
784 struct lbs_private *priv = (struct lbs_private *)data;
785 unsigned long flags;
786
787 lbs_deb_enter(LBS_DEB_TX);
788 spin_lock_irqsave(&priv->driver_lock, flags);
789
790 netdev_info(priv->dev, "TX lockup detected\n");
791 if (priv->reset_card)
792 priv->reset_card(priv);
793
794 priv->dnld_sent = DNLD_RES_RECEIVED;
795 wake_up_interruptible(&priv->waitq);
796
797 spin_unlock_irqrestore(&priv->driver_lock, flags);
798 lbs_deb_leave(LBS_DEB_TX);
799}
800
49125454 801/**
8973a6e7
RD
802 * auto_deepsleep_timer_fn - put the device back to deep sleep mode when
803 * timer expires and no activity (command, event, data etc.) is detected.
804 * @data: &struct lbs_private pointer
805 * returns: N/A
49125454
AK
806 */
807static void auto_deepsleep_timer_fn(unsigned long data)
808{
809 struct lbs_private *priv = (struct lbs_private *)data;
49125454
AK
810
811 lbs_deb_enter(LBS_DEB_CMD);
812
813 if (priv->is_activity_detected) {
814 priv->is_activity_detected = 0;
815 } else {
816 if (priv->is_auto_deep_sleep_enabled &&
53800f5d
DW
817 (!priv->wakeup_dev_required) &&
818 (priv->connect_status != LBS_CONNECTED)) {
819 struct cmd_header cmd;
820
49125454 821 lbs_deb_main("Entering auto deep sleep mode...\n");
53800f5d
DW
822 memset(&cmd, 0, sizeof(cmd));
823 cmd.size = cpu_to_le16(sizeof(cmd));
824 lbs_cmd_async(priv, CMD_802_11_DEEP_SLEEP, &cmd,
825 sizeof(cmd));
49125454
AK
826 }
827 }
828 mod_timer(&priv->auto_deepsleep_timer , jiffies +
829 (priv->auto_deep_sleep_timeout * HZ)/1000);
830 lbs_deb_leave(LBS_DEB_CMD);
831}
832
833int lbs_enter_auto_deep_sleep(struct lbs_private *priv)
834{
835 lbs_deb_enter(LBS_DEB_SDIO);
836
837 priv->is_auto_deep_sleep_enabled = 1;
838 if (priv->is_deep_sleep)
839 priv->wakeup_dev_required = 1;
840 mod_timer(&priv->auto_deepsleep_timer ,
841 jiffies + (priv->auto_deep_sleep_timeout * HZ)/1000);
842
843 lbs_deb_leave(LBS_DEB_SDIO);
844 return 0;
845}
846
847int lbs_exit_auto_deep_sleep(struct lbs_private *priv)
848{
849 lbs_deb_enter(LBS_DEB_SDIO);
850
851 priv->is_auto_deep_sleep_enabled = 0;
852 priv->auto_deep_sleep_timeout = 0;
853 del_timer(&priv->auto_deepsleep_timer);
854
855 lbs_deb_leave(LBS_DEB_SDIO);
856 return 0;
857}
858
69f9032d 859static int lbs_init_adapter(struct lbs_private *priv)
ac558ca2 860{
e86dc1ca 861 int ret;
1df4e8fe 862
61d30020
HS
863 lbs_deb_enter(LBS_DEB_MAIN);
864
aa21c004 865 memset(priv->current_addr, 0xff, ETH_ALEN);
1df4e8fe 866
aa21c004 867 priv->connect_status = LBS_DISCONNECTED;
c14951fe 868 priv->channel = DEFAULT_AD_HOC_CHANNEL;
d9e9778c 869 priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
d5db2dfa 870 priv->radio_on = 1;
aa21c004
DW
871 priv->psmode = LBS802_11POWERMODECAM;
872 priv->psstate = PS_STATE_FULL_POWER;
49125454
AK
873 priv->is_deep_sleep = 0;
874 priv->is_auto_deep_sleep_enabled = 0;
66fceb69 875 priv->deep_sleep_required = 0;
49125454
AK
876 priv->wakeup_dev_required = 0;
877 init_waitqueue_head(&priv->ds_awake_q);
cc026819 878 init_waitqueue_head(&priv->scan_q);
921ca03c 879 priv->authtype_auto = 1;
66fceb69
AK
880 priv->is_host_sleep_configured = 0;
881 priv->is_host_sleep_activated = 0;
882 init_waitqueue_head(&priv->host_sleep_q);
aa21c004 883 mutex_init(&priv->lock);
1df4e8fe 884
40e6fa82 885 setup_timer(&priv->command_timer, lbs_cmd_timeout_handler,
61d30020 886 (unsigned long)priv);
8f641d93
DD
887 setup_timer(&priv->tx_lockup_timer, lbs_tx_lockup_handler,
888 (unsigned long)priv);
49125454
AK
889 setup_timer(&priv->auto_deepsleep_timer, auto_deepsleep_timer_fn,
890 (unsigned long)priv);
1df4e8fe 891
aa21c004
DW
892 INIT_LIST_HEAD(&priv->cmdfreeq);
893 INIT_LIST_HEAD(&priv->cmdpendingq);
1df4e8fe 894
aa21c004 895 spin_lock_init(&priv->driver_lock);
1df4e8fe 896
954ee164 897 /* Allocate the command buffers */
10078321 898 if (lbs_allocate_cmd_buffer(priv)) {
0e4e06ae 899 pr_err("Out of memory allocating command buffers\n");
7919b89c
HS
900 ret = -ENOMEM;
901 goto out;
902 }
903 priv->resp_idx = 0;
904 priv->resp_len[0] = priv->resp_len[1] = 0;
905
906 /* Create the event FIFO */
c1e13f25 907 ret = kfifo_alloc(&priv->event_fifo, sizeof(u32) * 16, GFP_KERNEL);
45465487 908 if (ret) {
0e4e06ae 909 pr_err("Out of memory allocating event FIFO buffer\n");
7919b89c 910 goto out;
954ee164 911 }
1df4e8fe 912
954ee164 913out:
61d30020
HS
914 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
915
954ee164
DW
916 return ret;
917}
1df4e8fe 918
69f9032d 919static void lbs_free_adapter(struct lbs_private *priv)
954ee164 920{
61d30020 921 lbs_deb_enter(LBS_DEB_MAIN);
1df4e8fe 922
61d30020 923 lbs_free_cmd_buffer(priv);
45465487 924 kfifo_free(&priv->event_fifo);
aa21c004 925 del_timer(&priv->command_timer);
8f641d93 926 del_timer(&priv->tx_lockup_timer);
49125454 927 del_timer(&priv->auto_deepsleep_timer);
61d30020
HS
928
929 lbs_deb_leave(LBS_DEB_MAIN);
1df4e8fe
HS
930}
931
f02abf10
SH
932static const struct net_device_ops lbs_netdev_ops = {
933 .ndo_open = lbs_dev_open,
934 .ndo_stop = lbs_eth_stop,
935 .ndo_start_xmit = lbs_hard_start_xmit,
936 .ndo_set_mac_address = lbs_set_mac_address,
afc4b13d 937 .ndo_set_rx_mode = lbs_set_multicast_list,
f02abf10
SH
938 .ndo_change_mtu = eth_change_mtu,
939 .ndo_validate_addr = eth_validate_addr,
940};
941
876c9d3a 942/**
8973a6e7 943 * lbs_add_card - adds the card. It will probe the
10078321 944 * card, allocate the lbs_priv and initialize the device.
876c9d3a 945 *
8973a6e7
RD
946 * @card: A pointer to card
947 * @dmdev: A pointer to &struct device
948 * returns: A pointer to &struct lbs_private structure
876c9d3a 949 */
69f9032d 950struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
876c9d3a 951{
ff9fc791
HS
952 struct net_device *dev;
953 struct wireless_dev *wdev;
69f9032d 954 struct lbs_private *priv = NULL;
876c9d3a 955
61d30020 956 lbs_deb_enter(LBS_DEB_MAIN);
876c9d3a
MT
957
958 /* Allocate an Ethernet device and register it */
ff9fc791
HS
959 wdev = lbs_cfg_alloc(dmdev);
960 if (IS_ERR(wdev)) {
0e4e06ae 961 pr_err("cfg80211 init failed\n");
954ee164 962 goto done;
876c9d3a 963 }
e86dc1ca 964
ff9fc791
HS
965 wdev->iftype = NL80211_IFTYPE_STATION;
966 priv = wdev_priv(wdev);
967 priv->wdev = wdev;
876c9d3a 968
10078321 969 if (lbs_init_adapter(priv)) {
0e4e06ae 970 pr_err("failed to initialize adapter structure\n");
ff9fc791
HS
971 goto err_wdev;
972 }
973
ff9fc791
HS
974 dev = alloc_netdev(0, "wlan%d", ether_setup);
975 if (!dev) {
976 dev_err(dmdev, "no memory for network device instance\n");
977 goto err_adapter;
954ee164
DW
978 }
979
ff9fc791
HS
980 dev->ieee80211_ptr = wdev;
981 dev->ml_priv = priv;
982 SET_NETDEV_DEV(dev, dmdev);
983 wdev->netdev = dev;
634b8f49 984 priv->dev = dev;
876c9d3a 985
f02abf10 986 dev->netdev_ops = &lbs_netdev_ops;
fb3dddf2 987 dev->watchdog_timeo = 5 * HZ;
10078321 988 dev->ethtool_ops = &lbs_ethtool_ops;
876c9d3a 989 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
876c9d3a 990
ff9fc791 991 priv->card = card;
7732ca45 992
c00552c6 993 strcpy(dev->name, "wlan%d");
954ee164
DW
994
995 lbs_deb_thread("Starting main thread...\n");
996 init_waitqueue_head(&priv->waitq);
10078321 997 priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
954ee164
DW
998 if (IS_ERR(priv->main_thread)) {
999 lbs_deb_thread("Error creating main thread.\n");
ff9fc791 1000 goto err_ndev;
954ee164
DW
1001 }
1002
10078321 1003 priv->work_thread = create_singlethread_workqueue("lbs_worker");
75bf45a7 1004 INIT_WORK(&priv->mcast_work, lbs_set_mcast_worker);
23a397ac 1005
ae63a33e 1006 priv->wol_criteria = EHS_REMOVE_WAKEUP;
506e9025 1007 priv->wol_gpio = 0xff;
66fceb69 1008 priv->wol_gap = 20;
ae63a33e 1009 priv->ehs_remove_supported = true;
506e9025 1010
32a74b7c
HS
1011 goto done;
1012
ff9fc791 1013 err_ndev:
32a74b7c 1014 free_netdev(dev);
ff9fc791
HS
1015
1016 err_adapter:
1017 lbs_free_adapter(priv);
1018
1019 err_wdev:
1020 lbs_cfg_free(priv);
1021
6a812157 1022 priv = NULL;
954ee164 1023
32a74b7c 1024done:
61d30020 1025 lbs_deb_leave_args(LBS_DEB_MAIN, "priv %p", priv);
32a74b7c
HS
1026 return priv;
1027}
10078321 1028EXPORT_SYMBOL_GPL(lbs_add_card);
32a74b7c 1029
954ee164 1030
a63e5cb2 1031void lbs_remove_card(struct lbs_private *priv)
32a74b7c 1032{
634b8f49 1033 struct net_device *dev = priv->dev;
32a74b7c
HS
1034
1035 lbs_deb_enter(LBS_DEB_MAIN);
876c9d3a 1036
23a397ac 1037 lbs_remove_mesh(priv);
e86dc1ca 1038 lbs_scan_deinit(priv);
876c9d3a 1039
71b35f3a
DW
1040 /* worker thread destruction blocks on the in-flight command which
1041 * should have been cleared already in lbs_stop_card().
1042 */
1043 lbs_deb_main("destroying worker thread\n");
954ee164 1044 destroy_workqueue(priv->work_thread);
71b35f3a 1045 lbs_deb_main("done destroying worker thread\n");
876c9d3a 1046
aa21c004
DW
1047 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
1048 priv->psmode = LBS802_11POWERMODECAM;
0bb64087 1049 lbs_set_ps_mode(priv, PS_MODE_ACTION_EXIT_PS, true);
876c9d3a
MT
1050 }
1051
49125454
AK
1052 if (priv->is_deep_sleep) {
1053 priv->is_deep_sleep = 0;
1054 wake_up_interruptible(&priv->ds_awake_q);
1055 }
1056
66fceb69
AK
1057 priv->is_host_sleep_configured = 0;
1058 priv->is_host_sleep_activated = 0;
1059 wake_up_interruptible(&priv->host_sleep_q);
1060
954ee164 1061 /* Stop the thread servicing the interrupts */
aa21c004 1062 priv->surpriseremoved = 1;
954ee164
DW
1063 kthread_stop(priv->main_thread);
1064
10078321 1065 lbs_free_adapter(priv);
ff9fc791 1066 lbs_cfg_free(priv);
954ee164
DW
1067 free_netdev(dev);
1068
1069 lbs_deb_leave(LBS_DEB_MAIN);
954ee164 1070}
10078321 1071EXPORT_SYMBOL_GPL(lbs_remove_card);
954ee164
DW
1072
1073
e86dc1ca 1074int lbs_rtap_supported(struct lbs_private *priv)
cd74468b
HS
1075{
1076 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
1077 return 1;
1078
1079 /* newer firmware use a capability mask */
1080 return ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
1081 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK));
1082}
1083
1084
69f9032d 1085int lbs_start_card(struct lbs_private *priv)
954ee164
DW
1086{
1087 struct net_device *dev = priv->dev;
1088 int ret = -1;
1089
1090 lbs_deb_enter(LBS_DEB_MAIN);
1091
1092 /* poke the firmware */
10078321 1093 ret = lbs_setup_firmware(priv);
954ee164
DW
1094 if (ret)
1095 goto done;
1096
49fee692
DD
1097 if (!lbs_disablemesh)
1098 lbs_init_mesh(priv);
1099 else
1100 pr_info("%s: mesh disabled\n", dev->name);
1101
ff9fc791 1102 if (lbs_cfg_register(priv)) {
0e4e06ae 1103 pr_err("cannot register device\n");
954ee164 1104 goto done;
876c9d3a 1105 }
020f3d00 1106
49fee692
DD
1107 if (lbs_mesh_activated(priv))
1108 lbs_start_mesh(priv);
cd74468b 1109
10078321 1110 lbs_debugfs_init_one(priv, dev);
876c9d3a 1111
f3a57fd1 1112 netdev_info(dev, "Marvell WLAN 802.11 adapter\n");
954ee164 1113
32a74b7c 1114 ret = 0;
876c9d3a 1115
32a74b7c 1116done:
954ee164
DW
1117 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1118 return ret;
1119}
10078321 1120EXPORT_SYMBOL_GPL(lbs_start_card);
954ee164
DW
1121
1122
a63e5cb2 1123void lbs_stop_card(struct lbs_private *priv)
954ee164 1124{
43baa5bb 1125 struct net_device *dev;
954ee164
DW
1126
1127 lbs_deb_enter(LBS_DEB_MAIN);
1128
652e3f20
HS
1129 if (!priv)
1130 goto out;
43baa5bb 1131 dev = priv->dev;
652e3f20 1132
43baa5bb
JL
1133 netif_stop_queue(dev);
1134 netif_carrier_off(dev);
954ee164 1135
10078321 1136 lbs_debugfs_remove_one(priv);
cd74468b 1137 lbs_deinit_mesh(priv);
954ee164
DW
1138 unregister_netdev(dev);
1139
652e3f20 1140out:
a63e5cb2 1141 lbs_deb_leave(LBS_DEB_MAIN);
876c9d3a 1142}
10078321 1143EXPORT_SYMBOL_GPL(lbs_stop_card);
084708b6 1144
876c9d3a 1145
7919b89c
HS
1146void lbs_queue_event(struct lbs_private *priv, u32 event)
1147{
1148 unsigned long flags;
1149
1150 lbs_deb_enter(LBS_DEB_THREAD);
1151 spin_lock_irqsave(&priv->driver_lock, flags);
1152
1153 if (priv->psstate == PS_STATE_SLEEP)
1154 priv->psstate = PS_STATE_AWAKE;
1155
7acd72eb 1156 kfifo_in(&priv->event_fifo, (unsigned char *) &event, sizeof(u32));
7919b89c 1157
d2e7b342 1158 wake_up(&priv->waitq);
7919b89c
HS
1159
1160 spin_unlock_irqrestore(&priv->driver_lock, flags);
1161 lbs_deb_leave(LBS_DEB_THREAD);
1162}
1163EXPORT_SYMBOL_GPL(lbs_queue_event);
1164
1165void lbs_notify_command_response(struct lbs_private *priv, u8 resp_idx)
876c9d3a 1166{
ed37b516 1167 lbs_deb_enter(LBS_DEB_THREAD);
876c9d3a 1168
4f679496 1169 if (priv->psstate == PS_STATE_SLEEP)
aa21c004 1170 priv->psstate = PS_STATE_AWAKE;
7919b89c
HS
1171
1172 /* Swap buffers by flipping the response index */
1173 BUG_ON(resp_idx > 1);
1174 priv->resp_idx = resp_idx;
1175
d2e7b342 1176 wake_up(&priv->waitq);
876c9d3a 1177
ed37b516 1178 lbs_deb_leave(LBS_DEB_THREAD);
876c9d3a 1179}
7919b89c 1180EXPORT_SYMBOL_GPL(lbs_notify_command_response);
876c9d3a 1181
72f7a667 1182/**
8973a6e7 1183 * lbs_get_firmware - Retrieves two-stage firmware
72f7a667 1184 *
8973a6e7
RD
1185 * @dev: A pointer to &device structure
1186 * @user_helper: User-defined helper firmware file
1187 * @user_mainfw: User-defined main firmware file
1188 * @card_model: Bus-specific card model ID used to filter firmware table
1189 * elements
1190 * @fw_table: Table of firmware file names and device model numbers
1191 * terminated by an entry with a NULL helper name
1192 * @helper: On success, the helper firmware; caller must free
1193 * @mainfw: On success, the main firmware; caller must free
72f7a667 1194 *
8973a6e7 1195 * returns: 0 on success, non-zero on failure
72f7a667
DW
1196 */
1197int lbs_get_firmware(struct device *dev, const char *user_helper,
1198 const char *user_mainfw, u32 card_model,
1199 const struct lbs_fw_table *fw_table,
1200 const struct firmware **helper,
1201 const struct firmware **mainfw)
1202{
1203 const struct lbs_fw_table *iter;
1204 int ret;
1205
1206 BUG_ON(helper == NULL);
1207 BUG_ON(mainfw == NULL);
1208
1209 /* Try user-specified firmware first */
1210 if (user_helper) {
1211 ret = request_firmware(helper, user_helper, dev);
1212 if (ret) {
f3a57fd1
JP
1213 dev_err(dev, "couldn't find helper firmware %s\n",
1214 user_helper);
72f7a667
DW
1215 goto fail;
1216 }
1217 }
1218 if (user_mainfw) {
1219 ret = request_firmware(mainfw, user_mainfw, dev);
1220 if (ret) {
f3a57fd1
JP
1221 dev_err(dev, "couldn't find main firmware %s\n",
1222 user_mainfw);
72f7a667
DW
1223 goto fail;
1224 }
1225 }
1226
1227 if (*helper && *mainfw)
1228 return 0;
1229
1230 /* Otherwise search for firmware to use. If neither the helper or
1231 * the main firmware were specified by the user, then we need to
1232 * make sure that found helper & main are from the same entry in
1233 * fw_table.
1234 */
1235 iter = fw_table;
1236 while (iter && iter->helper) {
1237 if (iter->model != card_model)
1238 goto next;
1239
1240 if (*helper == NULL) {
1241 ret = request_firmware(helper, iter->helper, dev);
1242 if (ret)
1243 goto next;
1244
1245 /* If the device has one-stage firmware (ie cf8305) and
1246 * we've got it then we don't need to bother with the
1247 * main firmware.
1248 */
1249 if (iter->fwname == NULL)
1250 return 0;
1251 }
1252
1253 if (*mainfw == NULL) {
1254 ret = request_firmware(mainfw, iter->fwname, dev);
1255 if (ret && !user_helper) {
1256 /* Clear the helper if it wasn't user-specified
1257 * and the main firmware load failed, to ensure
1258 * we don't have mismatched firmware pairs.
1259 */
1260 release_firmware(*helper);
1261 *helper = NULL;
1262 }
1263 }
1264
1265 if (*helper && *mainfw)
1266 return 0;
1267
1268 next:
1269 iter++;
1270 }
1271
1272 fail:
1273 /* Failed */
1274 if (*helper) {
1275 release_firmware(*helper);
1276 *helper = NULL;
1277 }
1278 if (*mainfw) {
1279 release_firmware(*mainfw);
1280 *mainfw = NULL;
1281 }
1282
1283 return -ENOENT;
1284}
1285EXPORT_SYMBOL_GPL(lbs_get_firmware);
1286
4fb910fd 1287static int __init lbs_init_module(void)
876c9d3a 1288{
9012b28a 1289 lbs_deb_enter(LBS_DEB_MAIN);
f539f2ef
HS
1290 memset(&confirm_sleep, 0, sizeof(confirm_sleep));
1291 confirm_sleep.hdr.command = cpu_to_le16(CMD_802_11_PS_MODE);
1292 confirm_sleep.hdr.size = cpu_to_le16(sizeof(confirm_sleep));
0bb64087 1293 confirm_sleep.action = cpu_to_le16(PS_MODE_ACTION_SLEEP_CONFIRMED);
10078321 1294 lbs_debugfs_init();
084708b6
HS
1295 lbs_deb_leave(LBS_DEB_MAIN);
1296 return 0;
876c9d3a
MT
1297}
1298
4fb910fd 1299static void __exit lbs_exit_module(void)
876c9d3a 1300{
9012b28a 1301 lbs_deb_enter(LBS_DEB_MAIN);
10078321 1302 lbs_debugfs_remove();
9012b28a 1303 lbs_deb_leave(LBS_DEB_MAIN);
876c9d3a
MT
1304}
1305
10078321
HS
1306module_init(lbs_init_module);
1307module_exit(lbs_exit_module);
876c9d3a 1308
084708b6 1309MODULE_DESCRIPTION("Libertas WLAN Driver Library");
876c9d3a
MT
1310MODULE_AUTHOR("Marvell International Ltd.");
1311MODULE_LICENSE("GPL");
This page took 0.874972 seconds and 5 git commands to generate.