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