]>
Commit | Line | Data |
---|---|---|
876c9d3a MT |
1 | /** |
2 | * This file contains the major functions in WLAN | |
3 | * driver. It includes init, exit, open, close and main | |
4 | * thread etc.. | |
5 | */ | |
6 | ||
a46c6410 | 7 | #include <linux/moduleparam.h> |
876c9d3a | 8 | #include <linux/delay.h> |
876c9d3a MT |
9 | #include <linux/etherdevice.h> |
10 | #include <linux/netdevice.h> | |
11 | #include <linux/if_arp.h> | |
fe336150 | 12 | #include <linux/kthread.h> |
7919b89c | 13 | #include <linux/kfifo.h> |
75bf45a7 | 14 | #include <linux/stddef.h> |
2c706002 | 15 | #include <linux/ieee80211.h> |
876c9d3a | 16 | #include <net/iw_handler.h> |
ff9fc791 | 17 | #include <net/cfg80211.h> |
876c9d3a MT |
18 | |
19 | #include "host.h" | |
876c9d3a MT |
20 | #include "decl.h" |
21 | #include "dev.h" | |
876c9d3a | 22 | #include "wext.h" |
ff9fc791 | 23 | #include "cfg.h" |
876c9d3a | 24 | #include "debugfs.h" |
245bf20f | 25 | #include "scan.h" |
876c9d3a | 26 | #include "assoc.h" |
6e66f03f | 27 | #include "cmd.h" |
876c9d3a | 28 | |
7856a541 | 29 | #define DRIVER_RELEASE_VERSION "323.p0" |
10078321 | 30 | const char lbs_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION |
3ce40232 DW |
31 | #ifdef DEBUG |
32 | "-dbg" | |
33 | #endif | |
34 | ""; | |
35 | ||
a46c6410 HS |
36 | |
37 | /* Module parameters */ | |
10078321 HS |
38 | unsigned int lbs_debug; |
39 | EXPORT_SYMBOL_GPL(lbs_debug); | |
40 | module_param_named(libertas_debug, lbs_debug, int, 0644); | |
a46c6410 HS |
41 | |
42 | ||
f539f2ef HS |
43 | /* This global structure is used to send the confirm_sleep command as |
44 | * fast as possible down to the firmware. */ | |
45 | struct cmd_confirm_sleep confirm_sleep; | |
46 | ||
47 | ||
876c9d3a | 48 | /** |
8c512765 | 49 | * the table to keep region code |
876c9d3a | 50 | */ |
10078321 | 51 | u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] = |
8c512765 | 52 | { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 }; |
876c9d3a | 53 | |
876c9d3a | 54 | /** |
8c512765 DW |
55 | * FW rate table. FW refers to rates by their index in this table, not by the |
56 | * rate value itself. Values of 0x00 are | |
57 | * reserved positions. | |
876c9d3a | 58 | */ |
8c512765 DW |
59 | static u8 fw_data_rates[MAX_RATES] = |
60 | { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12, | |
61 | 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00 | |
62 | }; | |
876c9d3a | 63 | |
876c9d3a | 64 | /** |
8c512765 DW |
65 | * @brief use index to get the data rate |
66 | * | |
67 | * @param idx The index of data rate | |
68 | * @return data rate or 0 | |
876c9d3a | 69 | */ |
10078321 | 70 | u32 lbs_fw_index_to_data_rate(u8 idx) |
8c512765 DW |
71 | { |
72 | if (idx >= sizeof(fw_data_rates)) | |
73 | idx = 0; | |
74 | return fw_data_rates[idx]; | |
75 | } | |
76 | ||
77 | /** | |
78 | * @brief use rate to get the index | |
79 | * | |
80 | * @param rate data rate | |
81 | * @return index or 0 | |
82 | */ | |
10078321 | 83 | u8 lbs_data_rate_to_fw_index(u32 rate) |
8c512765 DW |
84 | { |
85 | u8 i; | |
86 | ||
87 | if (!rate) | |
88 | return 0; | |
89 | ||
90 | for (i = 0; i < sizeof(fw_data_rates); i++) { | |
91 | if (rate == fw_data_rates[i]) | |
92 | return i; | |
93 | } | |
94 | return 0; | |
95 | } | |
876c9d3a | 96 | |
876c9d3a MT |
97 | /** |
98 | * Attributes exported through sysfs | |
99 | */ | |
876c9d3a MT |
100 | |
101 | /** | |
82fde74b | 102 | * @brief Get function for sysfs attribute anycast_mask |
876c9d3a | 103 | */ |
10078321 | 104 | static ssize_t lbs_anycast_get(struct device *dev, |
b59bb616 DW |
105 | struct device_attribute *attr, char * buf) |
106 | { | |
ab65f649 | 107 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
876c9d3a | 108 | struct cmd_ds_mesh_access mesh_access; |
301eacbf | 109 | int ret; |
876c9d3a MT |
110 | |
111 | memset(&mesh_access, 0, sizeof(mesh_access)); | |
301eacbf DW |
112 | |
113 | ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access); | |
114 | if (ret) | |
115 | return ret; | |
876c9d3a | 116 | |
82fde74b | 117 | return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0])); |
876c9d3a MT |
118 | } |
119 | ||
120 | /** | |
82fde74b | 121 | * @brief Set function for sysfs attribute anycast_mask |
876c9d3a | 122 | */ |
10078321 | 123 | static ssize_t lbs_anycast_set(struct device *dev, |
b59bb616 DW |
124 | struct device_attribute *attr, const char * buf, size_t count) |
125 | { | |
ab65f649 | 126 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
876c9d3a | 127 | struct cmd_ds_mesh_access mesh_access; |
981f187b | 128 | uint32_t datum; |
301eacbf | 129 | int ret; |
876c9d3a | 130 | |
876c9d3a | 131 | memset(&mesh_access, 0, sizeof(mesh_access)); |
82fde74b | 132 | sscanf(buf, "%x", &datum); |
981f187b DW |
133 | mesh_access.data[0] = cpu_to_le32(datum); |
134 | ||
301eacbf DW |
135 | ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access); |
136 | if (ret) | |
137 | return ret; | |
138 | ||
876c9d3a MT |
139 | return strlen(buf); |
140 | } | |
141 | ||
6fb53252 AN |
142 | /** |
143 | * @brief Get function for sysfs attribute prb_rsp_limit | |
144 | */ | |
145 | static ssize_t lbs_prb_rsp_limit_get(struct device *dev, | |
146 | struct device_attribute *attr, char *buf) | |
147 | { | |
ab65f649 | 148 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
6fb53252 AN |
149 | struct cmd_ds_mesh_access mesh_access; |
150 | int ret; | |
151 | u32 retry_limit; | |
152 | ||
153 | memset(&mesh_access, 0, sizeof(mesh_access)); | |
154 | mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET); | |
155 | ||
156 | ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT, | |
157 | &mesh_access); | |
158 | if (ret) | |
159 | return ret; | |
160 | ||
161 | retry_limit = le32_to_cpu(mesh_access.data[1]); | |
162 | return snprintf(buf, 10, "%d\n", retry_limit); | |
163 | } | |
164 | ||
165 | /** | |
166 | * @brief Set function for sysfs attribute prb_rsp_limit | |
167 | */ | |
168 | static ssize_t lbs_prb_rsp_limit_set(struct device *dev, | |
169 | struct device_attribute *attr, const char *buf, size_t count) | |
170 | { | |
ab65f649 | 171 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
6fb53252 AN |
172 | struct cmd_ds_mesh_access mesh_access; |
173 | int ret; | |
174 | unsigned long retry_limit; | |
175 | ||
176 | memset(&mesh_access, 0, sizeof(mesh_access)); | |
177 | mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET); | |
178 | ||
179 | if (!strict_strtoul(buf, 10, &retry_limit)) | |
180 | return -ENOTSUPP; | |
181 | if (retry_limit > 15) | |
182 | return -ENOTSUPP; | |
183 | ||
184 | mesh_access.data[1] = cpu_to_le32(retry_limit); | |
185 | ||
186 | ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT, | |
187 | &mesh_access); | |
188 | if (ret) | |
189 | return ret; | |
190 | ||
191 | return strlen(buf); | |
192 | } | |
193 | ||
2fd6cfe3 DW |
194 | static int lbs_add_rtap(struct lbs_private *priv); |
195 | static void lbs_remove_rtap(struct lbs_private *priv); | |
23a397ac DW |
196 | static int lbs_add_mesh(struct lbs_private *priv); |
197 | static void lbs_remove_mesh(struct lbs_private *priv); | |
7e226272 | 198 | |
965f8bbc LCC |
199 | |
200 | /** | |
201 | * Get function for sysfs attribute rtap | |
202 | */ | |
10078321 | 203 | static ssize_t lbs_rtap_get(struct device *dev, |
965f8bbc LCC |
204 | struct device_attribute *attr, char * buf) |
205 | { | |
ab65f649 | 206 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
aa21c004 | 207 | return snprintf(buf, 5, "0x%X\n", priv->monitormode); |
965f8bbc LCC |
208 | } |
209 | ||
210 | /** | |
211 | * Set function for sysfs attribute rtap | |
212 | */ | |
10078321 | 213 | static ssize_t lbs_rtap_set(struct device *dev, |
965f8bbc LCC |
214 | struct device_attribute *attr, const char * buf, size_t count) |
215 | { | |
216 | int monitor_mode; | |
ab65f649 | 217 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
965f8bbc LCC |
218 | |
219 | sscanf(buf, "%x", &monitor_mode); | |
c2b310a7 HS |
220 | if (monitor_mode) { |
221 | if (priv->monitormode == monitor_mode) | |
965f8bbc | 222 | return strlen(buf); |
c2b310a7 | 223 | if (!priv->monitormode) { |
8552855f DW |
224 | if (priv->infra_open || priv->mesh_open) |
225 | return -EBUSY; | |
aa21c004 | 226 | if (priv->mode == IW_MODE_INFRA) |
191bb40e DW |
227 | lbs_cmd_80211_deauthenticate(priv, |
228 | priv->curbssparams.bssid, | |
229 | WLAN_REASON_DEAUTH_LEAVING); | |
aa21c004 | 230 | else if (priv->mode == IW_MODE_ADHOC) |
f5fe1fda | 231 | lbs_adhoc_stop(priv); |
10078321 | 232 | lbs_add_rtap(priv); |
965f8bbc | 233 | } |
aa21c004 | 234 | priv->monitormode = monitor_mode; |
3b72b01d | 235 | } else { |
c2b310a7 | 236 | if (!priv->monitormode) |
965f8bbc | 237 | return strlen(buf); |
c2b310a7 | 238 | priv->monitormode = 0; |
10078321 | 239 | lbs_remove_rtap(priv); |
f86a93e1 | 240 | |
aa21c004 DW |
241 | if (priv->currenttxskb) { |
242 | dev_kfree_skb_any(priv->currenttxskb); | |
243 | priv->currenttxskb = NULL; | |
f86a93e1 DW |
244 | } |
245 | ||
246 | /* Wake queues, command thread, etc. */ | |
247 | lbs_host_to_card_done(priv); | |
965f8bbc LCC |
248 | } |
249 | ||
10078321 | 250 | lbs_prepare_and_send_command(priv, |
965f8bbc | 251 | CMD_802_11_MONITOR_MODE, CMD_ACT_SET, |
aa21c004 | 252 | CMD_OPTION_WAITFORRSP, 0, &priv->monitormode); |
965f8bbc LCC |
253 | return strlen(buf); |
254 | } | |
255 | ||
256 | /** | |
23a397ac DW |
257 | * lbs_rtap attribute to be exported per ethX interface |
258 | * through sysfs (/sys/class/net/ethX/lbs_rtap) | |
965f8bbc | 259 | */ |
23a397ac DW |
260 | static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get, lbs_rtap_set ); |
261 | ||
262 | /** | |
263 | * Get function for sysfs attribute mesh | |
264 | */ | |
265 | static ssize_t lbs_mesh_get(struct device *dev, | |
266 | struct device_attribute *attr, char * buf) | |
267 | { | |
ab65f649 | 268 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
23a397ac DW |
269 | return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev); |
270 | } | |
271 | ||
272 | /** | |
273 | * Set function for sysfs attribute mesh | |
274 | */ | |
275 | static ssize_t lbs_mesh_set(struct device *dev, | |
276 | struct device_attribute *attr, const char * buf, size_t count) | |
277 | { | |
ab65f649 | 278 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
23a397ac | 279 | int enable; |
edaea5ce | 280 | int ret, action = CMD_ACT_MESH_CONFIG_STOP; |
23a397ac DW |
281 | |
282 | sscanf(buf, "%x", &enable); | |
283 | enable = !!enable; | |
284 | if (enable == !!priv->mesh_dev) | |
285 | return count; | |
edaea5ce JC |
286 | if (enable) |
287 | action = CMD_ACT_MESH_CONFIG_START; | |
288 | ret = lbs_mesh_config(priv, action, priv->curbssparams.channel); | |
23a397ac DW |
289 | if (ret) |
290 | return ret; | |
7e226272 | 291 | |
23a397ac DW |
292 | if (enable) |
293 | lbs_add_mesh(priv); | |
294 | else | |
295 | lbs_remove_mesh(priv); | |
296 | ||
297 | return count; | |
298 | } | |
299 | ||
300 | /** | |
301 | * lbs_mesh attribute to be exported per ethX interface | |
302 | * through sysfs (/sys/class/net/ethX/lbs_mesh) | |
303 | */ | |
304 | static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set); | |
965f8bbc | 305 | |
876c9d3a | 306 | /** |
82fde74b LC |
307 | * anycast_mask attribute to be exported per mshX interface |
308 | * through sysfs (/sys/class/net/mshX/anycast_mask) | |
876c9d3a | 309 | */ |
10078321 | 310 | static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set); |
876c9d3a | 311 | |
6fb53252 AN |
312 | /** |
313 | * prb_rsp_limit attribute to be exported per mshX interface | |
314 | * through sysfs (/sys/class/net/mshX/prb_rsp_limit) | |
315 | */ | |
316 | static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get, | |
317 | lbs_prb_rsp_limit_set); | |
318 | ||
10078321 | 319 | static struct attribute *lbs_mesh_sysfs_entries[] = { |
a9f38d02 | 320 | &dev_attr_anycast_mask.attr, |
6fb53252 | 321 | &dev_attr_prb_rsp_limit.attr, |
a9f38d02 LCC |
322 | NULL, |
323 | }; | |
324 | ||
10078321 HS |
325 | static struct attribute_group lbs_mesh_attr_group = { |
326 | .attrs = lbs_mesh_sysfs_entries, | |
a9f38d02 LCC |
327 | }; |
328 | ||
876c9d3a | 329 | /** |
8552855f | 330 | * @brief This function opens the ethX or mshX interface |
876c9d3a MT |
331 | * |
332 | * @param dev A pointer to net_device structure | |
8552855f | 333 | * @return 0 or -EBUSY if monitor mode active |
876c9d3a | 334 | */ |
10078321 | 335 | static int lbs_dev_open(struct net_device *dev) |
876c9d3a | 336 | { |
ab65f649 | 337 | struct lbs_private *priv = dev->ml_priv; |
8552855f | 338 | int ret = 0; |
876c9d3a | 339 | |
61d30020 HS |
340 | lbs_deb_enter(LBS_DEB_NET); |
341 | ||
8552855f | 342 | spin_lock_irq(&priv->driver_lock); |
876c9d3a | 343 | |
c2b310a7 | 344 | if (priv->monitormode) { |
8552855f DW |
345 | ret = -EBUSY; |
346 | goto out; | |
347 | } | |
01d77d8d | 348 | |
8552855f DW |
349 | if (dev == priv->mesh_dev) { |
350 | priv->mesh_open = 1; | |
351 | priv->mesh_connect_status = LBS_CONNECTED; | |
352 | netif_carrier_on(dev); | |
353 | } else { | |
354 | priv->infra_open = 1; | |
7e226272 | 355 | |
8552855f DW |
356 | if (priv->connect_status == LBS_CONNECTED) |
357 | netif_carrier_on(dev); | |
01d77d8d | 358 | else |
8552855f | 359 | netif_carrier_off(dev); |
51d84f50 | 360 | } |
876c9d3a | 361 | |
8552855f DW |
362 | if (!priv->tx_pending_len) |
363 | netif_wake_queue(dev); | |
364 | out: | |
876c9d3a | 365 | |
8552855f | 366 | spin_unlock_irq(&priv->driver_lock); |
61d30020 | 367 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
8552855f | 368 | return ret; |
876c9d3a MT |
369 | } |
370 | ||
371 | /** | |
372 | * @brief This function closes the mshX interface | |
373 | * | |
374 | * @param dev A pointer to net_device structure | |
375 | * @return 0 | |
376 | */ | |
8552855f | 377 | static int lbs_mesh_stop(struct net_device *dev) |
876c9d3a | 378 | { |
4ceb7b6a | 379 | struct lbs_private *priv = dev->ml_priv; |
876c9d3a | 380 | |
61d30020 | 381 | lbs_deb_enter(LBS_DEB_MESH); |
8552855f DW |
382 | spin_lock_irq(&priv->driver_lock); |
383 | ||
876c9d3a | 384 | priv->mesh_open = 0; |
8552855f DW |
385 | priv->mesh_connect_status = LBS_DISCONNECTED; |
386 | ||
387 | netif_stop_queue(dev); | |
388 | netif_carrier_off(dev); | |
7e226272 | 389 | |
8552855f | 390 | spin_unlock_irq(&priv->driver_lock); |
61d30020 | 391 | |
75bf45a7 DW |
392 | schedule_work(&priv->mcast_work); |
393 | ||
61d30020 | 394 | lbs_deb_leave(LBS_DEB_MESH); |
8552855f | 395 | return 0; |
876c9d3a MT |
396 | } |
397 | ||
398 | /** | |
399 | * @brief This function closes the ethX interface | |
400 | * | |
401 | * @param dev A pointer to net_device structure | |
402 | * @return 0 | |
403 | */ | |
8552855f | 404 | static int lbs_eth_stop(struct net_device *dev) |
78523daa | 405 | { |
ab65f649 | 406 | struct lbs_private *priv = dev->ml_priv; |
876c9d3a | 407 | |
61d30020 | 408 | lbs_deb_enter(LBS_DEB_NET); |
8552855f | 409 | |
61d30020 | 410 | spin_lock_irq(&priv->driver_lock); |
876c9d3a | 411 | priv->infra_open = 0; |
8552855f | 412 | netif_stop_queue(dev); |
8552855f | 413 | spin_unlock_irq(&priv->driver_lock); |
61d30020 | 414 | |
75bf45a7 DW |
415 | schedule_work(&priv->mcast_work); |
416 | ||
61d30020 | 417 | lbs_deb_leave(LBS_DEB_NET); |
8552855f | 418 | return 0; |
876c9d3a MT |
419 | } |
420 | ||
10078321 | 421 | static void lbs_tx_timeout(struct net_device *dev) |
876c9d3a | 422 | { |
ab65f649 | 423 | struct lbs_private *priv = dev->ml_priv; |
876c9d3a | 424 | |
9012b28a | 425 | lbs_deb_enter(LBS_DEB_TX); |
876c9d3a | 426 | |
9012b28a | 427 | lbs_pr_err("tx watch dog timeout\n"); |
876c9d3a | 428 | |
876c9d3a MT |
429 | dev->trans_start = jiffies; |
430 | ||
7919b89c HS |
431 | if (priv->currenttxskb) |
432 | lbs_send_tx_feedback(priv, 0); | |
433 | ||
a63b22bb DW |
434 | /* XX: Shouldn't we also call into the hw-specific driver |
435 | to kick it somehow? */ | |
436 | lbs_host_to_card_done(priv); | |
876c9d3a | 437 | |
354eca98 DW |
438 | /* More often than not, this actually happens because the |
439 | firmware has crapped itself -- rather than just a very | |
440 | busy medium. So send a harmless command, and if/when | |
441 | _that_ times out, we'll kick it in the head. */ | |
442 | lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0, | |
443 | 0, 0, NULL); | |
444 | ||
9012b28a | 445 | lbs_deb_leave(LBS_DEB_TX); |
876c9d3a MT |
446 | } |
447 | ||
e775ed7c DW |
448 | void lbs_host_to_card_done(struct lbs_private *priv) |
449 | { | |
a63b22bb DW |
450 | unsigned long flags; |
451 | ||
61d30020 HS |
452 | lbs_deb_enter(LBS_DEB_THREAD); |
453 | ||
a63b22bb | 454 | spin_lock_irqsave(&priv->driver_lock, flags); |
e775ed7c DW |
455 | |
456 | priv->dnld_sent = DNLD_RES_RECEIVED; | |
457 | ||
458 | /* Wake main thread if commands are pending */ | |
49125454 AK |
459 | if (!priv->cur_cmd || priv->tx_pending_len > 0) { |
460 | if (!priv->wakeup_dev_required) | |
461 | wake_up_interruptible(&priv->waitq); | |
462 | } | |
e775ed7c | 463 | |
a63b22bb | 464 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
61d30020 | 465 | lbs_deb_leave(LBS_DEB_THREAD); |
e775ed7c DW |
466 | } |
467 | EXPORT_SYMBOL_GPL(lbs_host_to_card_done); | |
468 | ||
10078321 | 469 | static int lbs_set_mac_address(struct net_device *dev, void *addr) |
876c9d3a MT |
470 | { |
471 | int ret = 0; | |
ab65f649 | 472 | struct lbs_private *priv = dev->ml_priv; |
876c9d3a | 473 | struct sockaddr *phwaddr = addr; |
2af9f039 | 474 | struct cmd_ds_802_11_mac_address cmd; |
876c9d3a | 475 | |
9012b28a | 476 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a | 477 | |
0a0d08ac | 478 | /* In case it was called from the mesh device */ |
2af9f039 | 479 | dev = priv->dev; |
0a0d08ac | 480 | |
2af9f039 HS |
481 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
482 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
483 | memcpy(cmd.macadd, phwaddr->sa_data, ETH_ALEN); | |
876c9d3a | 484 | |
2af9f039 | 485 | ret = lbs_cmd_with_response(priv, CMD_802_11_MAC_ADDRESS, &cmd); |
876c9d3a | 486 | if (ret) { |
9012b28a | 487 | lbs_deb_net("set MAC address failed\n"); |
876c9d3a MT |
488 | goto done; |
489 | } | |
490 | ||
2af9f039 HS |
491 | memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN); |
492 | memcpy(dev->dev_addr, phwaddr->sa_data, ETH_ALEN); | |
78523daa | 493 | if (priv->mesh_dev) |
2af9f039 | 494 | memcpy(priv->mesh_dev->dev_addr, phwaddr->sa_data, ETH_ALEN); |
876c9d3a MT |
495 | |
496 | done: | |
9012b28a | 497 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
876c9d3a MT |
498 | return ret; |
499 | } | |
500 | ||
75bf45a7 DW |
501 | |
502 | static inline int mac_in_list(unsigned char *list, int list_len, | |
503 | unsigned char *mac) | |
876c9d3a | 504 | { |
75bf45a7 DW |
505 | while (list_len) { |
506 | if (!memcmp(list, mac, ETH_ALEN)) | |
507 | return 1; | |
508 | list += ETH_ALEN; | |
509 | list_len--; | |
510 | } | |
511 | return 0; | |
512 | } | |
513 | ||
876c9d3a | 514 | |
75bf45a7 DW |
515 | static int lbs_add_mcast_addrs(struct cmd_ds_mac_multicast_adr *cmd, |
516 | struct net_device *dev, int nr_addrs) | |
517 | { | |
518 | int i = nr_addrs; | |
519 | struct dev_mc_list *mc_list; | |
75bf45a7 DW |
520 | |
521 | if ((dev->flags & (IFF_UP|IFF_MULTICAST)) != (IFF_UP|IFF_MULTICAST)) | |
522 | return nr_addrs; | |
523 | ||
b9e40857 | 524 | netif_addr_lock_bh(dev); |
75bf45a7 DW |
525 | for (mc_list = dev->mc_list; mc_list; mc_list = mc_list->next) { |
526 | if (mac_in_list(cmd->maclist, nr_addrs, mc_list->dmi_addr)) { | |
e174961c JB |
527 | lbs_deb_net("mcast address %s:%pM skipped\n", dev->name, |
528 | mc_list->dmi_addr); | |
75bf45a7 DW |
529 | continue; |
530 | } | |
876c9d3a | 531 | |
75bf45a7 DW |
532 | if (i == MRVDRV_MAX_MULTICAST_LIST_SIZE) |
533 | break; | |
534 | memcpy(&cmd->maclist[6*i], mc_list->dmi_addr, ETH_ALEN); | |
e174961c JB |
535 | lbs_deb_net("mcast address %s:%pM added to filter\n", dev->name, |
536 | mc_list->dmi_addr); | |
75bf45a7 | 537 | i++; |
876c9d3a | 538 | } |
b9e40857 | 539 | netif_addr_unlock_bh(dev); |
75bf45a7 DW |
540 | if (mc_list) |
541 | return -EOVERFLOW; | |
542 | ||
876c9d3a | 543 | return i; |
876c9d3a MT |
544 | } |
545 | ||
75bf45a7 | 546 | static void lbs_set_mcast_worker(struct work_struct *work) |
876c9d3a | 547 | { |
75bf45a7 DW |
548 | struct lbs_private *priv = container_of(work, struct lbs_private, mcast_work); |
549 | struct cmd_ds_mac_multicast_adr mcast_cmd; | |
550 | int dev_flags; | |
551 | int nr_addrs; | |
552 | int old_mac_control = priv->mac_control; | |
876c9d3a | 553 | |
9012b28a | 554 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a | 555 | |
75bf45a7 DW |
556 | dev_flags = priv->dev->flags; |
557 | if (priv->mesh_dev) | |
558 | dev_flags |= priv->mesh_dev->flags; | |
559 | ||
560 | if (dev_flags & IFF_PROMISC) { | |
561 | priv->mac_control |= CMD_ACT_MAC_PROMISCUOUS_ENABLE; | |
562 | priv->mac_control &= ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE | | |
563 | CMD_ACT_MAC_MULTICAST_ENABLE); | |
564 | goto out_set_mac_control; | |
565 | } else if (dev_flags & IFF_ALLMULTI) { | |
566 | do_allmulti: | |
567 | priv->mac_control |= CMD_ACT_MAC_ALL_MULTICAST_ENABLE; | |
568 | priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE | | |
569 | CMD_ACT_MAC_MULTICAST_ENABLE); | |
570 | goto out_set_mac_control; | |
876c9d3a MT |
571 | } |
572 | ||
75bf45a7 DW |
573 | /* Once for priv->dev, again for priv->mesh_dev if it exists */ |
574 | nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->dev, 0); | |
575 | if (nr_addrs >= 0 && priv->mesh_dev) | |
576 | nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->mesh_dev, nr_addrs); | |
577 | if (nr_addrs < 0) | |
578 | goto do_allmulti; | |
579 | ||
580 | if (nr_addrs) { | |
581 | int size = offsetof(struct cmd_ds_mac_multicast_adr, | |
582 | maclist[6*nr_addrs]); | |
583 | ||
584 | mcast_cmd.action = cpu_to_le16(CMD_ACT_SET); | |
585 | mcast_cmd.hdr.size = cpu_to_le16(size); | |
586 | mcast_cmd.nr_of_adrs = cpu_to_le16(nr_addrs); | |
587 | ||
588 | lbs_cmd_async(priv, CMD_MAC_MULTICAST_ADR, &mcast_cmd.hdr, size); | |
589 | ||
590 | priv->mac_control |= CMD_ACT_MAC_MULTICAST_ENABLE; | |
591 | } else | |
592 | priv->mac_control &= ~CMD_ACT_MAC_MULTICAST_ENABLE; | |
593 | ||
594 | priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE | | |
595 | CMD_ACT_MAC_ALL_MULTICAST_ENABLE); | |
596 | out_set_mac_control: | |
d9e9778c HS |
597 | if (priv->mac_control != old_mac_control) |
598 | lbs_set_mac_control(priv); | |
876c9d3a | 599 | |
9012b28a | 600 | lbs_deb_leave(LBS_DEB_NET); |
876c9d3a MT |
601 | } |
602 | ||
75bf45a7 DW |
603 | static void lbs_set_multicast_list(struct net_device *dev) |
604 | { | |
ab65f649 | 605 | struct lbs_private *priv = dev->ml_priv; |
75bf45a7 DW |
606 | |
607 | schedule_work(&priv->mcast_work); | |
608 | } | |
609 | ||
876c9d3a | 610 | /** |
10078321 | 611 | * @brief This function handles the major jobs in the LBS driver. |
9012b28a HS |
612 | * It handles all events generated by firmware, RX data received |
613 | * from firmware and TX data sent from kernel. | |
876c9d3a | 614 | * |
10078321 | 615 | * @param data A pointer to lbs_thread structure |
876c9d3a MT |
616 | * @return 0 |
617 | */ | |
10078321 | 618 | static int lbs_thread(void *data) |
876c9d3a | 619 | { |
fe336150 | 620 | struct net_device *dev = data; |
ab65f649 | 621 | struct lbs_private *priv = dev->ml_priv; |
876c9d3a | 622 | wait_queue_t wait; |
876c9d3a | 623 | |
9012b28a | 624 | lbs_deb_enter(LBS_DEB_THREAD); |
876c9d3a | 625 | |
876c9d3a MT |
626 | init_waitqueue_entry(&wait, current); |
627 | ||
628 | for (;;) { | |
b8d40bc9 | 629 | int shouldsleep; |
7919b89c | 630 | u8 resp_idx; |
b8d40bc9 | 631 | |
7919b89c HS |
632 | lbs_deb_thread("1: currenttxskb %p, dnld_sent %d\n", |
633 | priv->currenttxskb, priv->dnld_sent); | |
876c9d3a | 634 | |
fe336150 | 635 | add_wait_queue(&priv->waitq, &wait); |
876c9d3a | 636 | set_current_state(TASK_INTERRUPTIBLE); |
aa21c004 | 637 | spin_lock_irq(&priv->driver_lock); |
59f3e4bf | 638 | |
d9f88705 | 639 | if (kthread_should_stop()) |
b8d40bc9 | 640 | shouldsleep = 0; /* Bye */ |
d9f88705 DW |
641 | else if (priv->surpriseremoved) |
642 | shouldsleep = 1; /* We need to wait until we're _told_ to die */ | |
b8d40bc9 DW |
643 | else if (priv->psstate == PS_STATE_SLEEP) |
644 | shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */ | |
2a345099 DW |
645 | else if (priv->cmd_timed_out) |
646 | shouldsleep = 0; /* Command timed out. Recover */ | |
b15152a4 DW |
647 | else if (!priv->fw_ready) |
648 | shouldsleep = 1; /* Firmware not ready. We're waiting for it */ | |
b8d40bc9 DW |
649 | else if (priv->dnld_sent) |
650 | shouldsleep = 1; /* Something is en route to the device already */ | |
2eb188a1 DW |
651 | else if (priv->tx_pending_len > 0) |
652 | shouldsleep = 0; /* We've a packet to send */ | |
ef707b83 HS |
653 | else if (priv->resp_len[priv->resp_idx]) |
654 | shouldsleep = 0; /* We have a command response */ | |
b8d40bc9 DW |
655 | else if (priv->cur_cmd) |
656 | shouldsleep = 1; /* Can't send a command; one already running */ | |
49125454 AK |
657 | else if (!list_empty(&priv->cmdpendingq) && |
658 | !(priv->wakeup_dev_required)) | |
b8d40bc9 | 659 | shouldsleep = 0; /* We have a command to send */ |
7919b89c HS |
660 | else if (__kfifo_len(priv->event_fifo)) |
661 | shouldsleep = 0; /* We have an event to process */ | |
b8d40bc9 DW |
662 | else |
663 | shouldsleep = 1; /* No command */ | |
664 | ||
665 | if (shouldsleep) { | |
7919b89c | 666 | lbs_deb_thread("sleeping, connect_status %d, " |
5f505d90 | 667 | "psmode %d, psstate %d\n", |
7919b89c HS |
668 | priv->connect_status, |
669 | priv->psmode, priv->psstate); | |
aa21c004 | 670 | spin_unlock_irq(&priv->driver_lock); |
876c9d3a MT |
671 | schedule(); |
672 | } else | |
aa21c004 | 673 | spin_unlock_irq(&priv->driver_lock); |
876c9d3a | 674 | |
7919b89c HS |
675 | lbs_deb_thread("2: currenttxskb %p, dnld_send %d\n", |
676 | priv->currenttxskb, priv->dnld_sent); | |
876c9d3a MT |
677 | |
678 | set_current_state(TASK_RUNNING); | |
fe336150 | 679 | remove_wait_queue(&priv->waitq, &wait); |
876c9d3a | 680 | |
7919b89c HS |
681 | lbs_deb_thread("3: currenttxskb %p, dnld_sent %d\n", |
682 | priv->currenttxskb, priv->dnld_sent); | |
876c9d3a | 683 | |
d9f88705 | 684 | if (kthread_should_stop()) { |
7919b89c | 685 | lbs_deb_thread("break from main thread\n"); |
876c9d3a MT |
686 | break; |
687 | } | |
688 | ||
d9f88705 DW |
689 | if (priv->surpriseremoved) { |
690 | lbs_deb_thread("adapter removed; waiting to die...\n"); | |
691 | continue; | |
692 | } | |
876c9d3a | 693 | |
7919b89c HS |
694 | lbs_deb_thread("4: currenttxskb %p, dnld_sent %d\n", |
695 | priv->currenttxskb, priv->dnld_sent); | |
59f3e4bf | 696 | |
7919b89c | 697 | /* Process any pending command response */ |
a01f5450 | 698 | spin_lock_irq(&priv->driver_lock); |
7919b89c HS |
699 | resp_idx = priv->resp_idx; |
700 | if (priv->resp_len[resp_idx]) { | |
aa21c004 | 701 | spin_unlock_irq(&priv->driver_lock); |
7919b89c HS |
702 | lbs_process_command_response(priv, |
703 | priv->resp_buf[resp_idx], | |
704 | priv->resp_len[resp_idx]); | |
aa21c004 | 705 | spin_lock_irq(&priv->driver_lock); |
7919b89c | 706 | priv->resp_len[resp_idx] = 0; |
876c9d3a | 707 | } |
7919b89c | 708 | spin_unlock_irq(&priv->driver_lock); |
876c9d3a | 709 | |
49125454 AK |
710 | /* Process hardware events, e.g. card removed, link lost */ |
711 | spin_lock_irq(&priv->driver_lock); | |
712 | while (__kfifo_len(priv->event_fifo)) { | |
713 | u32 event; | |
714 | __kfifo_get(priv->event_fifo, (unsigned char *) &event, | |
715 | sizeof(event)); | |
716 | spin_unlock_irq(&priv->driver_lock); | |
717 | lbs_process_event(priv, event); | |
718 | spin_lock_irq(&priv->driver_lock); | |
719 | } | |
720 | spin_unlock_irq(&priv->driver_lock); | |
721 | ||
722 | if (priv->wakeup_dev_required) { | |
723 | lbs_deb_thread("Waking up device...\n"); | |
724 | /* Wake up device */ | |
725 | if (priv->exit_deep_sleep(priv)) | |
726 | lbs_deb_thread("Wakeup device failed\n"); | |
727 | continue; | |
728 | } | |
729 | ||
7919b89c | 730 | /* command timeout stuff */ |
2a345099 DW |
731 | if (priv->cmd_timed_out && priv->cur_cmd) { |
732 | struct cmd_ctrl_node *cmdnode = priv->cur_cmd; | |
733 | ||
57962f0b HS |
734 | if (++priv->nr_retries > 3) { |
735 | lbs_pr_info("Excessive timeouts submitting " | |
736 | "command 0x%04x\n", | |
737 | le16_to_cpu(cmdnode->cmdbuf->command)); | |
2a345099 DW |
738 | lbs_complete_command(priv, cmdnode, -ETIMEDOUT); |
739 | priv->nr_retries = 0; | |
b43441a4 | 740 | if (priv->reset_card) |
edf5dabf | 741 | priv->reset_card(priv); |
2a345099 DW |
742 | } else { |
743 | priv->cur_cmd = NULL; | |
02969d29 | 744 | priv->dnld_sent = DNLD_RES_RECEIVED; |
57962f0b HS |
745 | lbs_pr_info("requeueing command 0x%04x due " |
746 | "to timeout (#%d)\n", | |
747 | le16_to_cpu(cmdnode->cmdbuf->command), | |
748 | priv->nr_retries); | |
2a345099 DW |
749 | |
750 | /* Stick it back at the _top_ of the pending queue | |
751 | for immediate resubmission */ | |
752 | list_add(&cmdnode->list, &priv->cmdpendingq); | |
753 | } | |
754 | } | |
755 | priv->cmd_timed_out = 0; | |
756 | ||
876c9d3a | 757 | |
876c9d3a | 758 | |
b15152a4 DW |
759 | if (!priv->fw_ready) |
760 | continue; | |
761 | ||
876c9d3a | 762 | /* Check if we need to confirm Sleep Request received previously */ |
aa21c004 DW |
763 | if (priv->psstate == PS_STATE_PRE_SLEEP && |
764 | !priv->dnld_sent && !priv->cur_cmd) { | |
765 | if (priv->connect_status == LBS_CONNECTED) { | |
7919b89c HS |
766 | lbs_deb_thread("pre-sleep, currenttxskb %p, " |
767 | "dnld_sent %d, cur_cmd %p\n", | |
768 | priv->currenttxskb, priv->dnld_sent, | |
769 | priv->cur_cmd); | |
59f3e4bf | 770 | |
d4ff0ef6 | 771 | lbs_ps_confirm_sleep(priv); |
59f3e4bf DW |
772 | } else { |
773 | /* workaround for firmware sending | |
774 | * deauth/linkloss event immediately | |
775 | * after sleep request; remove this | |
776 | * after firmware fixes it | |
777 | */ | |
aa21c004 | 778 | priv->psstate = PS_STATE_AWAKE; |
7919b89c HS |
779 | lbs_pr_alert("ignore PS_SleepConfirm in " |
780 | "non-connected state\n"); | |
876c9d3a MT |
781 | } |
782 | } | |
783 | ||
784 | /* The PS state is changed during processing of Sleep Request | |
785 | * event above | |
786 | */ | |
aa21c004 DW |
787 | if ((priv->psstate == PS_STATE_SLEEP) || |
788 | (priv->psstate == PS_STATE_PRE_SLEEP)) | |
876c9d3a MT |
789 | continue; |
790 | ||
49125454 AK |
791 | if (priv->is_deep_sleep) |
792 | continue; | |
793 | ||
876c9d3a | 794 | /* Execute the next command */ |
aa21c004 | 795 | if (!priv->dnld_sent && !priv->cur_cmd) |
10078321 | 796 | lbs_execute_next_command(priv); |
876c9d3a MT |
797 | |
798 | /* Wake-up command waiters which can't sleep in | |
10078321 | 799 | * lbs_prepare_and_send_command |
876c9d3a | 800 | */ |
aa21c004 DW |
801 | if (!list_empty(&priv->cmdpendingq)) |
802 | wake_up_all(&priv->cmd_pending); | |
2eb188a1 DW |
803 | |
804 | spin_lock_irq(&priv->driver_lock); | |
805 | if (!priv->dnld_sent && priv->tx_pending_len > 0) { | |
806 | int ret = priv->hw_host_to_card(priv, MVMS_DAT, | |
807 | priv->tx_pending_buf, | |
808 | priv->tx_pending_len); | |
809 | if (ret) { | |
810 | lbs_deb_tx("host_to_card failed %d\n", ret); | |
811 | priv->dnld_sent = DNLD_RES_RECEIVED; | |
812 | } | |
813 | priv->tx_pending_len = 0; | |
814 | if (!priv->currenttxskb) { | |
815 | /* We can wake the queues immediately if we aren't | |
816 | waiting for TX feedback */ | |
817 | if (priv->connect_status == LBS_CONNECTED) | |
818 | netif_wake_queue(priv->dev); | |
819 | if (priv->mesh_dev && | |
820 | priv->mesh_connect_status == LBS_CONNECTED) | |
821 | netif_wake_queue(priv->mesh_dev); | |
822 | } | |
823 | } | |
824 | spin_unlock_irq(&priv->driver_lock); | |
876c9d3a MT |
825 | } |
826 | ||
aa21c004 | 827 | del_timer(&priv->command_timer); |
49125454 | 828 | del_timer(&priv->auto_deepsleep_timer); |
aa21c004 | 829 | wake_up_all(&priv->cmd_pending); |
876c9d3a | 830 | |
9012b28a | 831 | lbs_deb_leave(LBS_DEB_THREAD); |
876c9d3a MT |
832 | return 0; |
833 | } | |
834 | ||
ab25ecae DW |
835 | static int lbs_suspend_callback(struct lbs_private *priv, unsigned long dummy, |
836 | struct cmd_header *cmd) | |
837 | { | |
61d30020 | 838 | lbs_deb_enter(LBS_DEB_FW); |
ab25ecae DW |
839 | |
840 | netif_device_detach(priv->dev); | |
841 | if (priv->mesh_dev) | |
842 | netif_device_detach(priv->mesh_dev); | |
843 | ||
844 | priv->fw_ready = 0; | |
61d30020 | 845 | lbs_deb_leave(LBS_DEB_FW); |
ab25ecae DW |
846 | return 0; |
847 | } | |
848 | ||
ab25ecae DW |
849 | int lbs_suspend(struct lbs_private *priv) |
850 | { | |
851 | struct cmd_header cmd; | |
852 | int ret; | |
853 | ||
61d30020 HS |
854 | lbs_deb_enter(LBS_DEB_FW); |
855 | ||
506e9025 DW |
856 | if (priv->wol_criteria == 0xffffffff) { |
857 | lbs_pr_info("Suspend attempt without configuring wake params!\n"); | |
858 | return -EINVAL; | |
859 | } | |
860 | ||
ab25ecae | 861 | memset(&cmd, 0, sizeof(cmd)); |
7e226272 | 862 | |
ab25ecae DW |
863 | ret = __lbs_cmd(priv, CMD_802_11_HOST_SLEEP_ACTIVATE, &cmd, |
864 | sizeof(cmd), lbs_suspend_callback, 0); | |
865 | if (ret) | |
866 | lbs_pr_info("HOST_SLEEP_ACTIVATE failed: %d\n", ret); | |
867 | ||
61d30020 | 868 | lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret); |
ab25ecae DW |
869 | return ret; |
870 | } | |
871 | EXPORT_SYMBOL_GPL(lbs_suspend); | |
872 | ||
a63e5cb2 | 873 | void lbs_resume(struct lbs_private *priv) |
ab25ecae | 874 | { |
61d30020 HS |
875 | lbs_deb_enter(LBS_DEB_FW); |
876 | ||
ab25ecae DW |
877 | priv->fw_ready = 1; |
878 | ||
879 | /* Firmware doesn't seem to give us RX packets any more | |
880 | until we send it some command. Might as well update */ | |
881 | lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0, | |
882 | 0, 0, NULL); | |
883 | ||
884 | netif_device_attach(priv->dev); | |
885 | if (priv->mesh_dev) | |
886 | netif_device_attach(priv->mesh_dev); | |
887 | ||
61d30020 | 888 | lbs_deb_leave(LBS_DEB_FW); |
ab25ecae DW |
889 | } |
890 | EXPORT_SYMBOL_GPL(lbs_resume); | |
891 | ||
1df4e8fe | 892 | /** |
b4836599 CM |
893 | * @brief This function gets the HW spec from the firmware and sets |
894 | * some basic parameters. | |
1df4e8fe | 895 | * |
69f9032d | 896 | * @param priv A pointer to struct lbs_private structure |
1df4e8fe HS |
897 | * @return 0 or -1 |
898 | */ | |
69f9032d | 899 | static int lbs_setup_firmware(struct lbs_private *priv) |
1df4e8fe HS |
900 | { |
901 | int ret = -1; | |
87c8c72d | 902 | s16 curlevel = 0, minlevel = 0, maxlevel = 0; |
1df4e8fe HS |
903 | |
904 | lbs_deb_enter(LBS_DEB_FW); | |
905 | ||
87c8c72d | 906 | /* Read MAC address from firmware */ |
aa21c004 | 907 | memset(priv->current_addr, 0xff, ETH_ALEN); |
6e66f03f | 908 | ret = lbs_update_hw_spec(priv); |
ef85ad54 | 909 | if (ret) |
1df4e8fe | 910 | goto done; |
1df4e8fe | 911 | |
87c8c72d DW |
912 | /* Read power levels if available */ |
913 | ret = lbs_get_tx_power(priv, &curlevel, &minlevel, &maxlevel); | |
914 | if (ret == 0) { | |
915 | priv->txpower_cur = curlevel; | |
916 | priv->txpower_min = minlevel; | |
917 | priv->txpower_max = maxlevel; | |
918 | } | |
919 | ||
d9e9778c | 920 | lbs_set_mac_control(priv); |
1df4e8fe HS |
921 | done: |
922 | lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret); | |
923 | return ret; | |
924 | } | |
925 | ||
1df4e8fe HS |
926 | /** |
927 | * This function handles the timeout of command sending. | |
928 | * It will re-send the same command again. | |
929 | */ | |
930 | static void command_timer_fn(unsigned long data) | |
931 | { | |
69f9032d | 932 | struct lbs_private *priv = (struct lbs_private *)data; |
1df4e8fe HS |
933 | unsigned long flags; |
934 | ||
61d30020 | 935 | lbs_deb_enter(LBS_DEB_CMD); |
2a345099 | 936 | spin_lock_irqsave(&priv->driver_lock, flags); |
1df4e8fe | 937 | |
57962f0b | 938 | if (!priv->cur_cmd) |
2a345099 | 939 | goto out; |
1df4e8fe | 940 | |
57962f0b HS |
941 | lbs_pr_info("command 0x%04x timed out\n", |
942 | le16_to_cpu(priv->cur_cmd->cmdbuf->command)); | |
1df4e8fe | 943 | |
2a345099 | 944 | priv->cmd_timed_out = 1; |
1df4e8fe | 945 | wake_up_interruptible(&priv->waitq); |
61d30020 | 946 | out: |
2a345099 | 947 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
61d30020 | 948 | lbs_deb_leave(LBS_DEB_CMD); |
1df4e8fe HS |
949 | } |
950 | ||
49125454 AK |
951 | /** |
952 | * This function put the device back to deep sleep mode when timer expires | |
953 | * and no activity (command, event, data etc.) is detected. | |
954 | */ | |
955 | static void auto_deepsleep_timer_fn(unsigned long data) | |
956 | { | |
957 | struct lbs_private *priv = (struct lbs_private *)data; | |
958 | int ret; | |
959 | ||
960 | lbs_deb_enter(LBS_DEB_CMD); | |
961 | ||
962 | if (priv->is_activity_detected) { | |
963 | priv->is_activity_detected = 0; | |
964 | } else { | |
965 | if (priv->is_auto_deep_sleep_enabled && | |
966 | (!priv->wakeup_dev_required) && | |
967 | (priv->connect_status != LBS_CONNECTED)) { | |
968 | lbs_deb_main("Entering auto deep sleep mode...\n"); | |
969 | ret = lbs_prepare_and_send_command(priv, | |
970 | CMD_802_11_DEEP_SLEEP, 0, | |
971 | 0, 0, NULL); | |
c0bbd576 AK |
972 | if (ret) |
973 | lbs_pr_err("Enter Deep Sleep command failed\n"); | |
49125454 AK |
974 | } |
975 | } | |
976 | mod_timer(&priv->auto_deepsleep_timer , jiffies + | |
977 | (priv->auto_deep_sleep_timeout * HZ)/1000); | |
978 | lbs_deb_leave(LBS_DEB_CMD); | |
979 | } | |
980 | ||
981 | int lbs_enter_auto_deep_sleep(struct lbs_private *priv) | |
982 | { | |
983 | lbs_deb_enter(LBS_DEB_SDIO); | |
984 | ||
985 | priv->is_auto_deep_sleep_enabled = 1; | |
986 | if (priv->is_deep_sleep) | |
987 | priv->wakeup_dev_required = 1; | |
988 | mod_timer(&priv->auto_deepsleep_timer , | |
989 | jiffies + (priv->auto_deep_sleep_timeout * HZ)/1000); | |
990 | ||
991 | lbs_deb_leave(LBS_DEB_SDIO); | |
992 | return 0; | |
993 | } | |
994 | ||
995 | int lbs_exit_auto_deep_sleep(struct lbs_private *priv) | |
996 | { | |
997 | lbs_deb_enter(LBS_DEB_SDIO); | |
998 | ||
999 | priv->is_auto_deep_sleep_enabled = 0; | |
1000 | priv->auto_deep_sleep_timeout = 0; | |
1001 | del_timer(&priv->auto_deepsleep_timer); | |
1002 | ||
1003 | lbs_deb_leave(LBS_DEB_SDIO); | |
1004 | return 0; | |
1005 | } | |
1006 | ||
e226868e HS |
1007 | static void lbs_sync_channel_worker(struct work_struct *work) |
1008 | { | |
1009 | struct lbs_private *priv = container_of(work, struct lbs_private, | |
1010 | sync_channel); | |
1011 | ||
1012 | lbs_deb_enter(LBS_DEB_MAIN); | |
1013 | if (lbs_update_channel(priv)) | |
1014 | lbs_pr_info("Channel synchronization failed."); | |
1015 | lbs_deb_leave(LBS_DEB_MAIN); | |
1016 | } | |
1017 | ||
1018 | ||
69f9032d | 1019 | static int lbs_init_adapter(struct lbs_private *priv) |
ac558ca2 | 1020 | { |
1df4e8fe | 1021 | size_t bufsize; |
954ee164 | 1022 | int i, ret = 0; |
1df4e8fe | 1023 | |
61d30020 HS |
1024 | lbs_deb_enter(LBS_DEB_MAIN); |
1025 | ||
1df4e8fe HS |
1026 | /* Allocate buffer to store the BSSID list */ |
1027 | bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor); | |
aa21c004 DW |
1028 | priv->networks = kzalloc(bufsize, GFP_KERNEL); |
1029 | if (!priv->networks) { | |
1df4e8fe | 1030 | lbs_pr_err("Out of memory allocating beacons\n"); |
954ee164 DW |
1031 | ret = -1; |
1032 | goto out; | |
1df4e8fe HS |
1033 | } |
1034 | ||
954ee164 | 1035 | /* Initialize scan result lists */ |
aa21c004 DW |
1036 | INIT_LIST_HEAD(&priv->network_free_list); |
1037 | INIT_LIST_HEAD(&priv->network_list); | |
954ee164 | 1038 | for (i = 0; i < MAX_NETWORK_COUNT; i++) { |
aa21c004 DW |
1039 | list_add_tail(&priv->networks[i].list, |
1040 | &priv->network_free_list); | |
954ee164 | 1041 | } |
1df4e8fe | 1042 | |
aa21c004 | 1043 | memset(priv->current_addr, 0xff, ETH_ALEN); |
1df4e8fe | 1044 | |
aa21c004 DW |
1045 | priv->connect_status = LBS_DISCONNECTED; |
1046 | priv->mesh_connect_status = LBS_DISCONNECTED; | |
1047 | priv->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; | |
1048 | priv->mode = IW_MODE_INFRA; | |
1049 | priv->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL; | |
d9e9778c | 1050 | priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON; |
d5db2dfa | 1051 | priv->radio_on = 1; |
85319f93 | 1052 | priv->enablehwauto = 1; |
aa21c004 DW |
1053 | priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE; |
1054 | priv->psmode = LBS802_11POWERMODECAM; | |
1055 | priv->psstate = PS_STATE_FULL_POWER; | |
49125454 AK |
1056 | priv->is_deep_sleep = 0; |
1057 | priv->is_auto_deep_sleep_enabled = 0; | |
1058 | priv->wakeup_dev_required = 0; | |
1059 | init_waitqueue_head(&priv->ds_awake_q); | |
1df4e8fe | 1060 | |
aa21c004 | 1061 | mutex_init(&priv->lock); |
1df4e8fe | 1062 | |
aa21c004 | 1063 | setup_timer(&priv->command_timer, command_timer_fn, |
61d30020 | 1064 | (unsigned long)priv); |
49125454 AK |
1065 | setup_timer(&priv->auto_deepsleep_timer, auto_deepsleep_timer_fn, |
1066 | (unsigned long)priv); | |
1df4e8fe | 1067 | |
aa21c004 DW |
1068 | INIT_LIST_HEAD(&priv->cmdfreeq); |
1069 | INIT_LIST_HEAD(&priv->cmdpendingq); | |
1df4e8fe | 1070 | |
aa21c004 DW |
1071 | spin_lock_init(&priv->driver_lock); |
1072 | init_waitqueue_head(&priv->cmd_pending); | |
1df4e8fe | 1073 | |
954ee164 | 1074 | /* Allocate the command buffers */ |
10078321 | 1075 | if (lbs_allocate_cmd_buffer(priv)) { |
954ee164 | 1076 | lbs_pr_err("Out of memory allocating command buffers\n"); |
7919b89c HS |
1077 | ret = -ENOMEM; |
1078 | goto out; | |
1079 | } | |
1080 | priv->resp_idx = 0; | |
1081 | priv->resp_len[0] = priv->resp_len[1] = 0; | |
1082 | ||
1083 | /* Create the event FIFO */ | |
1084 | priv->event_fifo = kfifo_alloc(sizeof(u32) * 16, GFP_KERNEL, NULL); | |
1085 | if (IS_ERR(priv->event_fifo)) { | |
1086 | lbs_pr_err("Out of memory allocating event FIFO buffer\n"); | |
1087 | ret = -ENOMEM; | |
1088 | goto out; | |
954ee164 | 1089 | } |
1df4e8fe | 1090 | |
954ee164 | 1091 | out: |
61d30020 HS |
1092 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); |
1093 | ||
954ee164 DW |
1094 | return ret; |
1095 | } | |
1df4e8fe | 1096 | |
69f9032d | 1097 | static void lbs_free_adapter(struct lbs_private *priv) |
954ee164 | 1098 | { |
61d30020 | 1099 | lbs_deb_enter(LBS_DEB_MAIN); |
1df4e8fe | 1100 | |
61d30020 | 1101 | lbs_free_cmd_buffer(priv); |
7919b89c HS |
1102 | if (priv->event_fifo) |
1103 | kfifo_free(priv->event_fifo); | |
aa21c004 | 1104 | del_timer(&priv->command_timer); |
49125454 | 1105 | del_timer(&priv->auto_deepsleep_timer); |
aa21c004 DW |
1106 | kfree(priv->networks); |
1107 | priv->networks = NULL; | |
61d30020 HS |
1108 | |
1109 | lbs_deb_leave(LBS_DEB_MAIN); | |
1df4e8fe HS |
1110 | } |
1111 | ||
f02abf10 SH |
1112 | static const struct net_device_ops lbs_netdev_ops = { |
1113 | .ndo_open = lbs_dev_open, | |
1114 | .ndo_stop = lbs_eth_stop, | |
1115 | .ndo_start_xmit = lbs_hard_start_xmit, | |
1116 | .ndo_set_mac_address = lbs_set_mac_address, | |
1117 | .ndo_tx_timeout = lbs_tx_timeout, | |
1118 | .ndo_set_multicast_list = lbs_set_multicast_list, | |
1119 | .ndo_change_mtu = eth_change_mtu, | |
1120 | .ndo_validate_addr = eth_validate_addr, | |
1121 | }; | |
1122 | ||
876c9d3a MT |
1123 | /** |
1124 | * @brief This function adds the card. it will probe the | |
10078321 | 1125 | * card, allocate the lbs_priv and initialize the device. |
876c9d3a MT |
1126 | * |
1127 | * @param card A pointer to card | |
69f9032d | 1128 | * @return A pointer to struct lbs_private structure |
876c9d3a | 1129 | */ |
69f9032d | 1130 | struct lbs_private *lbs_add_card(void *card, struct device *dmdev) |
876c9d3a | 1131 | { |
ff9fc791 HS |
1132 | struct net_device *dev; |
1133 | struct wireless_dev *wdev; | |
69f9032d | 1134 | struct lbs_private *priv = NULL; |
876c9d3a | 1135 | |
61d30020 | 1136 | lbs_deb_enter(LBS_DEB_MAIN); |
876c9d3a MT |
1137 | |
1138 | /* Allocate an Ethernet device and register it */ | |
ff9fc791 HS |
1139 | wdev = lbs_cfg_alloc(dmdev); |
1140 | if (IS_ERR(wdev)) { | |
1141 | lbs_pr_err("cfg80211 init failed\n"); | |
954ee164 | 1142 | goto done; |
876c9d3a | 1143 | } |
ff9fc791 HS |
1144 | /* TODO? */ |
1145 | wdev->iftype = NL80211_IFTYPE_STATION; | |
1146 | priv = wdev_priv(wdev); | |
1147 | priv->wdev = wdev; | |
876c9d3a | 1148 | |
10078321 | 1149 | if (lbs_init_adapter(priv)) { |
954ee164 | 1150 | lbs_pr_err("failed to initialize adapter structure.\n"); |
ff9fc791 HS |
1151 | goto err_wdev; |
1152 | } | |
1153 | ||
1154 | //TODO? dev = alloc_netdev_mq(0, "wlan%d", ether_setup, IWM_TX_QUEUES); | |
1155 | dev = alloc_netdev(0, "wlan%d", ether_setup); | |
1156 | if (!dev) { | |
1157 | dev_err(dmdev, "no memory for network device instance\n"); | |
1158 | goto err_adapter; | |
954ee164 DW |
1159 | } |
1160 | ||
ff9fc791 HS |
1161 | dev->ieee80211_ptr = wdev; |
1162 | dev->ml_priv = priv; | |
1163 | SET_NETDEV_DEV(dev, dmdev); | |
1164 | wdev->netdev = dev; | |
634b8f49 | 1165 | priv->dev = dev; |
876c9d3a | 1166 | |
f02abf10 | 1167 | dev->netdev_ops = &lbs_netdev_ops; |
fb3dddf2 | 1168 | dev->watchdog_timeo = 5 * HZ; |
10078321 | 1169 | dev->ethtool_ops = &lbs_ethtool_ops; |
876c9d3a | 1170 | #ifdef WIRELESS_EXT |
f02abf10 | 1171 | dev->wireless_handlers = &lbs_handler_def; |
876c9d3a | 1172 | #endif |
876c9d3a | 1173 | dev->flags |= IFF_BROADCAST | IFF_MULTICAST; |
876c9d3a | 1174 | |
ff9fc791 HS |
1175 | |
1176 | // TODO: kzalloc + iwm_init_default_profile(iwm, iwm->umac_profile); ?? | |
1177 | ||
1178 | ||
1179 | priv->card = card; | |
1180 | priv->mesh_open = 0; | |
1181 | priv->infra_open = 0; | |
1182 | ||
7732ca45 | 1183 | |
965f8bbc | 1184 | priv->rtap_net_dev = NULL; |
c00552c6 | 1185 | strcpy(dev->name, "wlan%d"); |
954ee164 DW |
1186 | |
1187 | lbs_deb_thread("Starting main thread...\n"); | |
1188 | init_waitqueue_head(&priv->waitq); | |
10078321 | 1189 | priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main"); |
954ee164 DW |
1190 | if (IS_ERR(priv->main_thread)) { |
1191 | lbs_deb_thread("Error creating main thread.\n"); | |
ff9fc791 | 1192 | goto err_ndev; |
954ee164 DW |
1193 | } |
1194 | ||
10078321 HS |
1195 | priv->work_thread = create_singlethread_workqueue("lbs_worker"); |
1196 | INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker); | |
1197 | INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker); | |
75bf45a7 | 1198 | INIT_WORK(&priv->mcast_work, lbs_set_mcast_worker); |
e226868e | 1199 | INIT_WORK(&priv->sync_channel, lbs_sync_channel_worker); |
954ee164 | 1200 | |
23a397ac DW |
1201 | sprintf(priv->mesh_ssid, "mesh"); |
1202 | priv->mesh_ssid_len = 4; | |
1203 | ||
506e9025 DW |
1204 | priv->wol_criteria = 0xffffffff; |
1205 | priv->wol_gpio = 0xff; | |
1206 | ||
32a74b7c HS |
1207 | goto done; |
1208 | ||
ff9fc791 | 1209 | err_ndev: |
32a74b7c | 1210 | free_netdev(dev); |
ff9fc791 HS |
1211 | |
1212 | err_adapter: | |
1213 | lbs_free_adapter(priv); | |
1214 | ||
1215 | err_wdev: | |
1216 | lbs_cfg_free(priv); | |
1217 | ||
6a812157 | 1218 | priv = NULL; |
954ee164 | 1219 | |
32a74b7c | 1220 | done: |
61d30020 | 1221 | lbs_deb_leave_args(LBS_DEB_MAIN, "priv %p", priv); |
32a74b7c HS |
1222 | return priv; |
1223 | } | |
10078321 | 1224 | EXPORT_SYMBOL_GPL(lbs_add_card); |
32a74b7c | 1225 | |
954ee164 | 1226 | |
a63e5cb2 | 1227 | void lbs_remove_card(struct lbs_private *priv) |
32a74b7c | 1228 | { |
634b8f49 | 1229 | struct net_device *dev = priv->dev; |
954ee164 | 1230 | union iwreq_data wrqu; |
32a74b7c HS |
1231 | |
1232 | lbs_deb_enter(LBS_DEB_MAIN); | |
876c9d3a | 1233 | |
23a397ac | 1234 | lbs_remove_mesh(priv); |
10078321 | 1235 | lbs_remove_rtap(priv); |
876c9d3a | 1236 | |
954ee164 | 1237 | dev = priv->dev; |
2afc0c5d | 1238 | |
652e3f20 HS |
1239 | cancel_delayed_work_sync(&priv->scan_work); |
1240 | cancel_delayed_work_sync(&priv->assoc_work); | |
75bf45a7 | 1241 | cancel_work_sync(&priv->mcast_work); |
71b35f3a DW |
1242 | |
1243 | /* worker thread destruction blocks on the in-flight command which | |
1244 | * should have been cleared already in lbs_stop_card(). | |
1245 | */ | |
1246 | lbs_deb_main("destroying worker thread\n"); | |
954ee164 | 1247 | destroy_workqueue(priv->work_thread); |
71b35f3a | 1248 | lbs_deb_main("done destroying worker thread\n"); |
876c9d3a | 1249 | |
aa21c004 DW |
1250 | if (priv->psmode == LBS802_11POWERMODEMAX_PSP) { |
1251 | priv->psmode = LBS802_11POWERMODECAM; | |
10078321 | 1252 | lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP); |
876c9d3a MT |
1253 | } |
1254 | ||
954ee164 DW |
1255 | memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN); |
1256 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
1257 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); | |
1258 | ||
49125454 AK |
1259 | if (priv->is_deep_sleep) { |
1260 | priv->is_deep_sleep = 0; | |
1261 | wake_up_interruptible(&priv->ds_awake_q); | |
1262 | } | |
1263 | ||
954ee164 | 1264 | /* Stop the thread servicing the interrupts */ |
aa21c004 | 1265 | priv->surpriseremoved = 1; |
954ee164 DW |
1266 | kthread_stop(priv->main_thread); |
1267 | ||
10078321 | 1268 | lbs_free_adapter(priv); |
ff9fc791 | 1269 | lbs_cfg_free(priv); |
954ee164 DW |
1270 | |
1271 | priv->dev = NULL; | |
1272 | free_netdev(dev); | |
1273 | ||
1274 | lbs_deb_leave(LBS_DEB_MAIN); | |
954ee164 | 1275 | } |
10078321 | 1276 | EXPORT_SYMBOL_GPL(lbs_remove_card); |
954ee164 DW |
1277 | |
1278 | ||
69f9032d | 1279 | int lbs_start_card(struct lbs_private *priv) |
954ee164 DW |
1280 | { |
1281 | struct net_device *dev = priv->dev; | |
1282 | int ret = -1; | |
1283 | ||
1284 | lbs_deb_enter(LBS_DEB_MAIN); | |
1285 | ||
1286 | /* poke the firmware */ | |
10078321 | 1287 | ret = lbs_setup_firmware(priv); |
954ee164 DW |
1288 | if (ret) |
1289 | goto done; | |
1290 | ||
ff9fc791 HS |
1291 | if (lbs_cfg_register(priv)) { |
1292 | lbs_pr_err("cannot register device\n"); | |
954ee164 | 1293 | goto done; |
876c9d3a | 1294 | } |
020f3d00 | 1295 | |
020f3d00 | 1296 | lbs_update_channel(priv); |
020f3d00 | 1297 | |
684d6b36 BZ |
1298 | /* Check mesh FW version and appropriately send the mesh start |
1299 | * command | |
1300 | */ | |
1301 | if (priv->mesh_fw_ver == MESH_FW_OLD) { | |
c9d1be36 HS |
1302 | /* Enable mesh, if supported, and work out which TLV it uses. |
1303 | 0x100 + 291 is an unofficial value used in 5.110.20.pXX | |
1304 | 0x100 + 37 is the official value used in 5.110.21.pXX | |
1305 | but we check them in that order because 20.pXX doesn't | |
1306 | give an error -- it just silently fails. */ | |
1307 | ||
1308 | /* 5.110.20.pXX firmware will fail the command if the channel | |
1309 | doesn't match the existing channel. But only if the TLV | |
1310 | is correct. If the channel is wrong, _BOTH_ versions will | |
1311 | give an error to 0x100+291, and allow 0x100+37 to succeed. | |
1312 | It's just that 5.110.20.pXX will not have done anything | |
1313 | useful */ | |
1314 | ||
684d6b36 | 1315 | priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID; |
edaea5ce JC |
1316 | if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, |
1317 | priv->curbssparams.channel)) { | |
684d6b36 | 1318 | priv->mesh_tlv = TLV_TYPE_MESH_ID; |
edaea5ce JC |
1319 | if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, |
1320 | priv->curbssparams.channel)) | |
c9d1be36 HS |
1321 | priv->mesh_tlv = 0; |
1322 | } | |
684d6b36 BZ |
1323 | } else if (priv->mesh_fw_ver == MESH_FW_NEW) { |
1324 | /* 10.0.0.pXX new firmwares should succeed with TLV | |
1325 | * 0x100+37; Do not invoke command with old TLV. | |
1326 | */ | |
1327 | priv->mesh_tlv = TLV_TYPE_MESH_ID; | |
1328 | if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, | |
1329 | priv->curbssparams.channel)) | |
1330 | priv->mesh_tlv = 0; | |
1331 | } | |
1332 | if (priv->mesh_tlv) { | |
1333 | lbs_add_mesh(priv); | |
1334 | ||
1335 | if (device_create_file(&dev->dev, &dev_attr_lbs_mesh)) | |
1336 | lbs_pr_err("cannot register lbs_mesh attribute\n"); | |
1337 | ||
1338 | /* While rtap isn't related to mesh, only mesh-enabled | |
1339 | * firmware implements the rtap functionality via | |
1340 | * CMD_802_11_MONITOR_MODE. | |
1341 | */ | |
1342 | if (device_create_file(&dev->dev, &dev_attr_lbs_rtap)) | |
1343 | lbs_pr_err("cannot register lbs_rtap attribute\n"); | |
020f3d00 | 1344 | } |
876c9d3a | 1345 | |
10078321 | 1346 | lbs_debugfs_init_one(priv, dev); |
876c9d3a | 1347 | |
954ee164 DW |
1348 | lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name); |
1349 | ||
32a74b7c | 1350 | ret = 0; |
876c9d3a | 1351 | |
32a74b7c | 1352 | done: |
954ee164 DW |
1353 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); |
1354 | return ret; | |
1355 | } | |
10078321 | 1356 | EXPORT_SYMBOL_GPL(lbs_start_card); |
954ee164 DW |
1357 | |
1358 | ||
a63e5cb2 | 1359 | void lbs_stop_card(struct lbs_private *priv) |
954ee164 | 1360 | { |
43baa5bb | 1361 | struct net_device *dev; |
954ee164 DW |
1362 | struct cmd_ctrl_node *cmdnode; |
1363 | unsigned long flags; | |
1364 | ||
1365 | lbs_deb_enter(LBS_DEB_MAIN); | |
1366 | ||
652e3f20 HS |
1367 | if (!priv) |
1368 | goto out; | |
43baa5bb | 1369 | dev = priv->dev; |
652e3f20 | 1370 | |
43baa5bb JL |
1371 | netif_stop_queue(dev); |
1372 | netif_carrier_off(dev); | |
954ee164 | 1373 | |
10078321 | 1374 | lbs_debugfs_remove_one(priv); |
15dbaac0 | 1375 | if (priv->mesh_tlv) { |
020f3d00 | 1376 | device_remove_file(&dev->dev, &dev_attr_lbs_mesh); |
3b72b01d | 1377 | device_remove_file(&dev->dev, &dev_attr_lbs_rtap); |
15dbaac0 | 1378 | } |
954ee164 | 1379 | |
71b35f3a | 1380 | /* Delete the timeout of the currently processing command */ |
652e3f20 | 1381 | del_timer_sync(&priv->command_timer); |
49125454 | 1382 | del_timer_sync(&priv->auto_deepsleep_timer); |
71b35f3a DW |
1383 | |
1384 | /* Flush pending command nodes */ | |
aa21c004 | 1385 | spin_lock_irqsave(&priv->driver_lock, flags); |
71b35f3a | 1386 | lbs_deb_main("clearing pending commands\n"); |
aa21c004 | 1387 | list_for_each_entry(cmdnode, &priv->cmdpendingq, list) { |
ae125bf8 | 1388 | cmdnode->result = -ENOENT; |
954ee164 DW |
1389 | cmdnode->cmdwaitqwoken = 1; |
1390 | wake_up_interruptible(&cmdnode->cmdwait_q); | |
1391 | } | |
71b35f3a DW |
1392 | |
1393 | /* Flush the command the card is currently processing */ | |
1394 | if (priv->cur_cmd) { | |
1395 | lbs_deb_main("clearing current command\n"); | |
1396 | priv->cur_cmd->result = -ENOENT; | |
1397 | priv->cur_cmd->cmdwaitqwoken = 1; | |
1398 | wake_up_interruptible(&priv->cur_cmd->cmdwait_q); | |
1399 | } | |
1400 | lbs_deb_main("done clearing commands\n"); | |
aa21c004 | 1401 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
954ee164 DW |
1402 | |
1403 | unregister_netdev(dev); | |
1404 | ||
652e3f20 | 1405 | out: |
a63e5cb2 | 1406 | lbs_deb_leave(LBS_DEB_MAIN); |
876c9d3a | 1407 | } |
10078321 | 1408 | EXPORT_SYMBOL_GPL(lbs_stop_card); |
084708b6 | 1409 | |
876c9d3a | 1410 | |
f02abf10 SH |
1411 | static const struct net_device_ops mesh_netdev_ops = { |
1412 | .ndo_open = lbs_dev_open, | |
1413 | .ndo_stop = lbs_mesh_stop, | |
1414 | .ndo_start_xmit = lbs_hard_start_xmit, | |
1415 | .ndo_set_mac_address = lbs_set_mac_address, | |
1416 | .ndo_set_multicast_list = lbs_set_multicast_list, | |
1417 | }; | |
1418 | ||
78523daa HS |
1419 | /** |
1420 | * @brief This function adds mshX interface | |
1421 | * | |
69f9032d | 1422 | * @param priv A pointer to the struct lbs_private structure |
78523daa HS |
1423 | * @return 0 if successful, -X otherwise |
1424 | */ | |
23a397ac | 1425 | static int lbs_add_mesh(struct lbs_private *priv) |
78523daa HS |
1426 | { |
1427 | struct net_device *mesh_dev = NULL; | |
1428 | int ret = 0; | |
1429 | ||
1430 | lbs_deb_enter(LBS_DEB_MESH); | |
1431 | ||
1432 | /* Allocate a virtual mesh device */ | |
1433 | if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) { | |
1434 | lbs_deb_mesh("init mshX device failed\n"); | |
1435 | ret = -ENOMEM; | |
1436 | goto done; | |
1437 | } | |
4ceb7b6a | 1438 | mesh_dev->ml_priv = priv; |
78523daa HS |
1439 | priv->mesh_dev = mesh_dev; |
1440 | ||
f02abf10 | 1441 | mesh_dev->netdev_ops = &mesh_netdev_ops; |
10078321 | 1442 | mesh_dev->ethtool_ops = &lbs_ethtool_ops; |
634b8f49 HS |
1443 | memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, |
1444 | sizeof(priv->dev->dev_addr)); | |
78523daa | 1445 | |
23a397ac | 1446 | SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent); |
7732ca45 | 1447 | |
78523daa | 1448 | #ifdef WIRELESS_EXT |
f5e05b69 | 1449 | mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def; |
78523daa | 1450 | #endif |
75bf45a7 | 1451 | mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST; |
78523daa HS |
1452 | /* Register virtual mesh interface */ |
1453 | ret = register_netdev(mesh_dev); | |
1454 | if (ret) { | |
1455 | lbs_pr_err("cannot register mshX virtual interface\n"); | |
1456 | goto err_free; | |
1457 | } | |
1458 | ||
10078321 | 1459 | ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group); |
78523daa HS |
1460 | if (ret) |
1461 | goto err_unregister; | |
1462 | ||
15dbaac0 JC |
1463 | lbs_persist_config_init(mesh_dev); |
1464 | ||
78523daa HS |
1465 | /* Everything successful */ |
1466 | ret = 0; | |
1467 | goto done; | |
1468 | ||
78523daa HS |
1469 | err_unregister: |
1470 | unregister_netdev(mesh_dev); | |
1471 | ||
1472 | err_free: | |
1473 | free_netdev(mesh_dev); | |
1474 | ||
1475 | done: | |
1476 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); | |
1477 | return ret; | |
1478 | } | |
084708b6 | 1479 | |
23a397ac | 1480 | static void lbs_remove_mesh(struct lbs_private *priv) |
78523daa HS |
1481 | { |
1482 | struct net_device *mesh_dev; | |
1483 | ||
78523daa HS |
1484 | |
1485 | mesh_dev = priv->mesh_dev; | |
23a397ac | 1486 | if (!mesh_dev) |
61d30020 | 1487 | return; |
78523daa | 1488 | |
61d30020 | 1489 | lbs_deb_enter(LBS_DEB_MESH); |
78523daa | 1490 | netif_stop_queue(mesh_dev); |
15dbaac0 | 1491 | netif_carrier_off(mesh_dev); |
10078321 | 1492 | sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group); |
15dbaac0 | 1493 | lbs_persist_config_remove(mesh_dev); |
78523daa | 1494 | unregister_netdev(mesh_dev); |
23a397ac | 1495 | priv->mesh_dev = NULL; |
78523daa | 1496 | free_netdev(mesh_dev); |
61d30020 | 1497 | lbs_deb_leave(LBS_DEB_MESH); |
78523daa HS |
1498 | } |
1499 | ||
7919b89c HS |
1500 | void lbs_queue_event(struct lbs_private *priv, u32 event) |
1501 | { | |
1502 | unsigned long flags; | |
1503 | ||
1504 | lbs_deb_enter(LBS_DEB_THREAD); | |
1505 | spin_lock_irqsave(&priv->driver_lock, flags); | |
1506 | ||
1507 | if (priv->psstate == PS_STATE_SLEEP) | |
1508 | priv->psstate = PS_STATE_AWAKE; | |
1509 | ||
1510 | __kfifo_put(priv->event_fifo, (unsigned char *) &event, sizeof(u32)); | |
1511 | ||
1512 | wake_up_interruptible(&priv->waitq); | |
1513 | ||
1514 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
1515 | lbs_deb_leave(LBS_DEB_THREAD); | |
1516 | } | |
1517 | EXPORT_SYMBOL_GPL(lbs_queue_event); | |
1518 | ||
1519 | void lbs_notify_command_response(struct lbs_private *priv, u8 resp_idx) | |
876c9d3a | 1520 | { |
ed37b516 | 1521 | lbs_deb_enter(LBS_DEB_THREAD); |
876c9d3a | 1522 | |
4f679496 | 1523 | if (priv->psstate == PS_STATE_SLEEP) |
aa21c004 | 1524 | priv->psstate = PS_STATE_AWAKE; |
7919b89c HS |
1525 | |
1526 | /* Swap buffers by flipping the response index */ | |
1527 | BUG_ON(resp_idx > 1); | |
1528 | priv->resp_idx = resp_idx; | |
1529 | ||
fe336150 | 1530 | wake_up_interruptible(&priv->waitq); |
876c9d3a | 1531 | |
ed37b516 | 1532 | lbs_deb_leave(LBS_DEB_THREAD); |
876c9d3a | 1533 | } |
7919b89c | 1534 | EXPORT_SYMBOL_GPL(lbs_notify_command_response); |
876c9d3a | 1535 | |
4fb910fd | 1536 | static int __init lbs_init_module(void) |
876c9d3a | 1537 | { |
9012b28a | 1538 | lbs_deb_enter(LBS_DEB_MAIN); |
f539f2ef HS |
1539 | memset(&confirm_sleep, 0, sizeof(confirm_sleep)); |
1540 | confirm_sleep.hdr.command = cpu_to_le16(CMD_802_11_PS_MODE); | |
1541 | confirm_sleep.hdr.size = cpu_to_le16(sizeof(confirm_sleep)); | |
1542 | confirm_sleep.action = cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED); | |
10078321 | 1543 | lbs_debugfs_init(); |
084708b6 HS |
1544 | lbs_deb_leave(LBS_DEB_MAIN); |
1545 | return 0; | |
876c9d3a MT |
1546 | } |
1547 | ||
4fb910fd | 1548 | static void __exit lbs_exit_module(void) |
876c9d3a | 1549 | { |
9012b28a | 1550 | lbs_deb_enter(LBS_DEB_MAIN); |
10078321 | 1551 | lbs_debugfs_remove(); |
9012b28a | 1552 | lbs_deb_leave(LBS_DEB_MAIN); |
876c9d3a MT |
1553 | } |
1554 | ||
965f8bbc LCC |
1555 | /* |
1556 | * rtap interface support fuctions | |
1557 | */ | |
1558 | ||
10078321 | 1559 | static int lbs_rtap_open(struct net_device *dev) |
965f8bbc | 1560 | { |
8552855f | 1561 | /* Yes, _stop_ the queue. Because we don't support injection */ |
61d30020 HS |
1562 | lbs_deb_enter(LBS_DEB_MAIN); |
1563 | netif_carrier_off(dev); | |
1564 | netif_stop_queue(dev); | |
1565 | lbs_deb_leave(LBS_DEB_LEAVE); | |
1566 | return 0; | |
965f8bbc LCC |
1567 | } |
1568 | ||
10078321 | 1569 | static int lbs_rtap_stop(struct net_device *dev) |
965f8bbc | 1570 | { |
61d30020 HS |
1571 | lbs_deb_enter(LBS_DEB_MAIN); |
1572 | lbs_deb_leave(LBS_DEB_MAIN); | |
1573 | return 0; | |
965f8bbc LCC |
1574 | } |
1575 | ||
d0cf9c0d SH |
1576 | static netdev_tx_t lbs_rtap_hard_start_xmit(struct sk_buff *skb, |
1577 | struct net_device *dev) | |
965f8bbc | 1578 | { |
61d30020 HS |
1579 | netif_stop_queue(dev); |
1580 | return NETDEV_TX_BUSY; | |
965f8bbc LCC |
1581 | } |
1582 | ||
2fd6cfe3 | 1583 | static void lbs_remove_rtap(struct lbs_private *priv) |
965f8bbc | 1584 | { |
61d30020 | 1585 | lbs_deb_enter(LBS_DEB_MAIN); |
965f8bbc | 1586 | if (priv->rtap_net_dev == NULL) |
5f505d90 | 1587 | goto out; |
965f8bbc | 1588 | unregister_netdev(priv->rtap_net_dev); |
d9268fb9 | 1589 | free_netdev(priv->rtap_net_dev); |
965f8bbc | 1590 | priv->rtap_net_dev = NULL; |
5f505d90 | 1591 | out: |
61d30020 | 1592 | lbs_deb_leave(LBS_DEB_MAIN); |
965f8bbc LCC |
1593 | } |
1594 | ||
f02abf10 SH |
1595 | static const struct net_device_ops rtap_netdev_ops = { |
1596 | .ndo_open = lbs_rtap_open, | |
1597 | .ndo_stop = lbs_rtap_stop, | |
1598 | .ndo_start_xmit = lbs_rtap_hard_start_xmit, | |
1599 | }; | |
1600 | ||
2fd6cfe3 | 1601 | static int lbs_add_rtap(struct lbs_private *priv) |
965f8bbc | 1602 | { |
61d30020 | 1603 | int ret = 0; |
d9268fb9 | 1604 | struct net_device *rtap_dev; |
965f8bbc | 1605 | |
61d30020 HS |
1606 | lbs_deb_enter(LBS_DEB_MAIN); |
1607 | if (priv->rtap_net_dev) { | |
1608 | ret = -EPERM; | |
1609 | goto out; | |
1610 | } | |
965f8bbc | 1611 | |
d9268fb9 | 1612 | rtap_dev = alloc_netdev(0, "rtap%d", ether_setup); |
61d30020 HS |
1613 | if (rtap_dev == NULL) { |
1614 | ret = -ENOMEM; | |
1615 | goto out; | |
1616 | } | |
965f8bbc | 1617 | |
121947c6 | 1618 | memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN); |
d9268fb9 | 1619 | rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
f02abf10 | 1620 | rtap_dev->netdev_ops = &rtap_netdev_ops; |
4ceb7b6a | 1621 | rtap_dev->ml_priv = priv; |
229ce3ab | 1622 | SET_NETDEV_DEV(rtap_dev, priv->dev->dev.parent); |
965f8bbc | 1623 | |
61d30020 HS |
1624 | ret = register_netdev(rtap_dev); |
1625 | if (ret) { | |
d9268fb9 | 1626 | free_netdev(rtap_dev); |
61d30020 | 1627 | goto out; |
965f8bbc | 1628 | } |
d9268fb9 | 1629 | priv->rtap_net_dev = rtap_dev; |
965f8bbc | 1630 | |
61d30020 HS |
1631 | out: |
1632 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); | |
1633 | return ret; | |
965f8bbc LCC |
1634 | } |
1635 | ||
10078321 HS |
1636 | module_init(lbs_init_module); |
1637 | module_exit(lbs_exit_module); | |
876c9d3a | 1638 | |
084708b6 | 1639 | MODULE_DESCRIPTION("Libertas WLAN Driver Library"); |
876c9d3a MT |
1640 | MODULE_AUTHOR("Marvell International Ltd."); |
1641 | MODULE_LICENSE("GPL"); |