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