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