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 MT |
8 | #include <linux/delay.h> |
9 | #include <linux/freezer.h> | |
10 | #include <linux/etherdevice.h> | |
11 | #include <linux/netdevice.h> | |
12 | #include <linux/if_arp.h> | |
fe336150 | 13 | #include <linux/kthread.h> |
876c9d3a MT |
14 | |
15 | #include <net/iw_handler.h> | |
9012b28a | 16 | #include <net/ieee80211.h> |
876c9d3a MT |
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" | |
23 | #include "assoc.h" | |
965f8bbc | 24 | #include "join.h" |
876c9d3a | 25 | |
7856a541 | 26 | #define DRIVER_RELEASE_VERSION "323.p0" |
3ce40232 DW |
27 | const char libertas_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION |
28 | #ifdef DEBUG | |
29 | "-dbg" | |
30 | #endif | |
31 | ""; | |
32 | ||
a46c6410 HS |
33 | |
34 | /* Module parameters */ | |
35 | unsigned int libertas_debug = 0; | |
36 | module_param(libertas_debug, int, 0644); | |
084708b6 | 37 | EXPORT_SYMBOL_GPL(libertas_debug); |
a46c6410 HS |
38 | |
39 | ||
876c9d3a MT |
40 | #define WLAN_TX_PWR_DEFAULT 20 /*100mW */ |
41 | #define WLAN_TX_PWR_US_DEFAULT 20 /*100mW */ | |
42 | #define WLAN_TX_PWR_JP_DEFAULT 16 /*50mW */ | |
43 | #define WLAN_TX_PWR_FR_DEFAULT 20 /*100mW */ | |
44 | #define WLAN_TX_PWR_EMEA_DEFAULT 20 /*100mW */ | |
45 | ||
46 | /* Format { channel, frequency (MHz), maxtxpower } */ | |
47 | /* band: 'B/G', region: USA FCC/Canada IC */ | |
48 | static struct chan_freq_power channel_freq_power_US_BG[] = { | |
49 | {1, 2412, WLAN_TX_PWR_US_DEFAULT}, | |
50 | {2, 2417, WLAN_TX_PWR_US_DEFAULT}, | |
51 | {3, 2422, WLAN_TX_PWR_US_DEFAULT}, | |
52 | {4, 2427, WLAN_TX_PWR_US_DEFAULT}, | |
53 | {5, 2432, WLAN_TX_PWR_US_DEFAULT}, | |
54 | {6, 2437, WLAN_TX_PWR_US_DEFAULT}, | |
55 | {7, 2442, WLAN_TX_PWR_US_DEFAULT}, | |
56 | {8, 2447, WLAN_TX_PWR_US_DEFAULT}, | |
57 | {9, 2452, WLAN_TX_PWR_US_DEFAULT}, | |
58 | {10, 2457, WLAN_TX_PWR_US_DEFAULT}, | |
59 | {11, 2462, WLAN_TX_PWR_US_DEFAULT} | |
60 | }; | |
61 | ||
62 | /* band: 'B/G', region: Europe ETSI */ | |
63 | static struct chan_freq_power channel_freq_power_EU_BG[] = { | |
64 | {1, 2412, WLAN_TX_PWR_EMEA_DEFAULT}, | |
65 | {2, 2417, WLAN_TX_PWR_EMEA_DEFAULT}, | |
66 | {3, 2422, WLAN_TX_PWR_EMEA_DEFAULT}, | |
67 | {4, 2427, WLAN_TX_PWR_EMEA_DEFAULT}, | |
68 | {5, 2432, WLAN_TX_PWR_EMEA_DEFAULT}, | |
69 | {6, 2437, WLAN_TX_PWR_EMEA_DEFAULT}, | |
70 | {7, 2442, WLAN_TX_PWR_EMEA_DEFAULT}, | |
71 | {8, 2447, WLAN_TX_PWR_EMEA_DEFAULT}, | |
72 | {9, 2452, WLAN_TX_PWR_EMEA_DEFAULT}, | |
73 | {10, 2457, WLAN_TX_PWR_EMEA_DEFAULT}, | |
74 | {11, 2462, WLAN_TX_PWR_EMEA_DEFAULT}, | |
75 | {12, 2467, WLAN_TX_PWR_EMEA_DEFAULT}, | |
76 | {13, 2472, WLAN_TX_PWR_EMEA_DEFAULT} | |
77 | }; | |
78 | ||
79 | /* band: 'B/G', region: Spain */ | |
80 | static struct chan_freq_power channel_freq_power_SPN_BG[] = { | |
81 | {10, 2457, WLAN_TX_PWR_DEFAULT}, | |
82 | {11, 2462, WLAN_TX_PWR_DEFAULT} | |
83 | }; | |
84 | ||
85 | /* band: 'B/G', region: France */ | |
86 | static struct chan_freq_power channel_freq_power_FR_BG[] = { | |
87 | {10, 2457, WLAN_TX_PWR_FR_DEFAULT}, | |
88 | {11, 2462, WLAN_TX_PWR_FR_DEFAULT}, | |
89 | {12, 2467, WLAN_TX_PWR_FR_DEFAULT}, | |
90 | {13, 2472, WLAN_TX_PWR_FR_DEFAULT} | |
91 | }; | |
92 | ||
93 | /* band: 'B/G', region: Japan */ | |
94 | static struct chan_freq_power channel_freq_power_JPN_BG[] = { | |
95 | {1, 2412, WLAN_TX_PWR_JP_DEFAULT}, | |
96 | {2, 2417, WLAN_TX_PWR_JP_DEFAULT}, | |
97 | {3, 2422, WLAN_TX_PWR_JP_DEFAULT}, | |
98 | {4, 2427, WLAN_TX_PWR_JP_DEFAULT}, | |
99 | {5, 2432, WLAN_TX_PWR_JP_DEFAULT}, | |
100 | {6, 2437, WLAN_TX_PWR_JP_DEFAULT}, | |
101 | {7, 2442, WLAN_TX_PWR_JP_DEFAULT}, | |
102 | {8, 2447, WLAN_TX_PWR_JP_DEFAULT}, | |
103 | {9, 2452, WLAN_TX_PWR_JP_DEFAULT}, | |
104 | {10, 2457, WLAN_TX_PWR_JP_DEFAULT}, | |
105 | {11, 2462, WLAN_TX_PWR_JP_DEFAULT}, | |
106 | {12, 2467, WLAN_TX_PWR_JP_DEFAULT}, | |
107 | {13, 2472, WLAN_TX_PWR_JP_DEFAULT}, | |
108 | {14, 2484, WLAN_TX_PWR_JP_DEFAULT} | |
109 | }; | |
110 | ||
111 | /** | |
112 | * the structure for channel, frequency and power | |
113 | */ | |
114 | struct region_cfp_table { | |
115 | u8 region; | |
116 | struct chan_freq_power *cfp_BG; | |
117 | int cfp_no_BG; | |
118 | }; | |
119 | ||
120 | /** | |
121 | * the structure for the mapping between region and CFP | |
122 | */ | |
123 | static struct region_cfp_table region_cfp_table[] = { | |
124 | {0x10, /*US FCC */ | |
125 | channel_freq_power_US_BG, | |
ff8ac609 | 126 | ARRAY_SIZE(channel_freq_power_US_BG), |
876c9d3a MT |
127 | } |
128 | , | |
129 | {0x20, /*CANADA IC */ | |
130 | channel_freq_power_US_BG, | |
ff8ac609 | 131 | ARRAY_SIZE(channel_freq_power_US_BG), |
876c9d3a MT |
132 | } |
133 | , | |
134 | {0x30, /*EU*/ channel_freq_power_EU_BG, | |
ff8ac609 | 135 | ARRAY_SIZE(channel_freq_power_EU_BG), |
876c9d3a MT |
136 | } |
137 | , | |
138 | {0x31, /*SPAIN*/ channel_freq_power_SPN_BG, | |
ff8ac609 | 139 | ARRAY_SIZE(channel_freq_power_SPN_BG), |
876c9d3a MT |
140 | } |
141 | , | |
142 | {0x32, /*FRANCE*/ channel_freq_power_FR_BG, | |
ff8ac609 | 143 | ARRAY_SIZE(channel_freq_power_FR_BG), |
876c9d3a MT |
144 | } |
145 | , | |
146 | {0x40, /*JAPAN*/ channel_freq_power_JPN_BG, | |
ff8ac609 | 147 | ARRAY_SIZE(channel_freq_power_JPN_BG), |
876c9d3a MT |
148 | } |
149 | , | |
150 | /*Add new region here */ | |
151 | }; | |
152 | ||
876c9d3a | 153 | /** |
8c512765 | 154 | * the table to keep region code |
876c9d3a | 155 | */ |
8c512765 DW |
156 | u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE] = |
157 | { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 }; | |
876c9d3a MT |
158 | |
159 | /** | |
8c512765 | 160 | * 802.11b/g supported bitrates (in 500Kb/s units) |
876c9d3a | 161 | */ |
8c512765 DW |
162 | u8 libertas_bg_rates[MAX_RATES] = |
163 | { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c, | |
164 | 0x00, 0x00 }; | |
876c9d3a MT |
165 | |
166 | /** | |
8c512765 DW |
167 | * FW rate table. FW refers to rates by their index in this table, not by the |
168 | * rate value itself. Values of 0x00 are | |
169 | * reserved positions. | |
876c9d3a | 170 | */ |
8c512765 DW |
171 | static u8 fw_data_rates[MAX_RATES] = |
172 | { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12, | |
173 | 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00 | |
174 | }; | |
876c9d3a | 175 | |
876c9d3a | 176 | /** |
8c512765 DW |
177 | * @brief use index to get the data rate |
178 | * | |
179 | * @param idx The index of data rate | |
180 | * @return data rate or 0 | |
876c9d3a | 181 | */ |
8c512765 DW |
182 | u32 libertas_fw_index_to_data_rate(u8 idx) |
183 | { | |
184 | if (idx >= sizeof(fw_data_rates)) | |
185 | idx = 0; | |
186 | return fw_data_rates[idx]; | |
187 | } | |
188 | ||
189 | /** | |
190 | * @brief use rate to get the index | |
191 | * | |
192 | * @param rate data rate | |
193 | * @return index or 0 | |
194 | */ | |
195 | u8 libertas_data_rate_to_fw_index(u32 rate) | |
196 | { | |
197 | u8 i; | |
198 | ||
199 | if (!rate) | |
200 | return 0; | |
201 | ||
202 | for (i = 0; i < sizeof(fw_data_rates); i++) { | |
203 | if (rate == fw_data_rates[i]) | |
204 | return i; | |
205 | } | |
206 | return 0; | |
207 | } | |
876c9d3a | 208 | |
876c9d3a MT |
209 | /** |
210 | * Attributes exported through sysfs | |
211 | */ | |
876c9d3a MT |
212 | |
213 | /** | |
82fde74b | 214 | * @brief Get function for sysfs attribute anycast_mask |
876c9d3a | 215 | */ |
82fde74b | 216 | static ssize_t libertas_anycast_get(struct device * dev, |
b59bb616 DW |
217 | struct device_attribute *attr, char * buf) |
218 | { | |
876c9d3a MT |
219 | struct cmd_ds_mesh_access mesh_access; |
220 | ||
221 | memset(&mesh_access, 0, sizeof(mesh_access)); | |
222 | libertas_prepare_and_send_command(to_net_dev(dev)->priv, | |
0aef64d7 DW |
223 | CMD_MESH_ACCESS, |
224 | CMD_ACT_MESH_GET_ANYCAST, | |
225 | CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access); | |
876c9d3a | 226 | |
82fde74b | 227 | return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0])); |
876c9d3a MT |
228 | } |
229 | ||
230 | /** | |
82fde74b | 231 | * @brief Set function for sysfs attribute anycast_mask |
876c9d3a | 232 | */ |
82fde74b | 233 | static ssize_t libertas_anycast_set(struct device * dev, |
b59bb616 DW |
234 | struct device_attribute *attr, const char * buf, size_t count) |
235 | { | |
876c9d3a | 236 | struct cmd_ds_mesh_access mesh_access; |
981f187b | 237 | uint32_t datum; |
876c9d3a | 238 | |
876c9d3a | 239 | memset(&mesh_access, 0, sizeof(mesh_access)); |
82fde74b | 240 | sscanf(buf, "%x", &datum); |
981f187b DW |
241 | mesh_access.data[0] = cpu_to_le32(datum); |
242 | ||
876c9d3a | 243 | libertas_prepare_and_send_command((to_net_dev(dev))->priv, |
0aef64d7 DW |
244 | CMD_MESH_ACCESS, |
245 | CMD_ACT_MESH_SET_ANYCAST, | |
246 | CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access); | |
876c9d3a MT |
247 | return strlen(buf); |
248 | } | |
249 | ||
965f8bbc LCC |
250 | int libertas_add_rtap(wlan_private *priv); |
251 | void libertas_remove_rtap(wlan_private *priv); | |
252 | ||
253 | /** | |
254 | * Get function for sysfs attribute rtap | |
255 | */ | |
256 | static ssize_t libertas_rtap_get(struct device * dev, | |
257 | struct device_attribute *attr, char * buf) | |
258 | { | |
64f104e8 | 259 | wlan_private *priv = (wlan_private *) (to_net_dev(dev))->priv; |
965f8bbc LCC |
260 | wlan_adapter *adapter = priv->adapter; |
261 | return snprintf(buf, 5, "0x%X\n", adapter->monitormode); | |
262 | } | |
263 | ||
264 | /** | |
265 | * Set function for sysfs attribute rtap | |
266 | */ | |
267 | static ssize_t libertas_rtap_set(struct device * dev, | |
268 | struct device_attribute *attr, const char * buf, size_t count) | |
269 | { | |
270 | int monitor_mode; | |
64f104e8 | 271 | wlan_private *priv = (wlan_private *) (to_net_dev(dev))->priv; |
965f8bbc LCC |
272 | wlan_adapter *adapter = priv->adapter; |
273 | ||
274 | sscanf(buf, "%x", &monitor_mode); | |
275 | if (monitor_mode != WLAN_MONITOR_OFF) { | |
276 | if(adapter->monitormode == monitor_mode) | |
277 | return strlen(buf); | |
278 | if (adapter->monitormode == WLAN_MONITOR_OFF) { | |
279 | if (adapter->mode == IW_MODE_INFRA) | |
280 | libertas_send_deauthentication(priv); | |
281 | else if (adapter->mode == IW_MODE_ADHOC) | |
282 | libertas_stop_adhoc_network(priv); | |
283 | libertas_add_rtap(priv); | |
284 | } | |
285 | adapter->monitormode = monitor_mode; | |
286 | } | |
287 | ||
288 | else { | |
289 | if(adapter->monitormode == WLAN_MONITOR_OFF) | |
290 | return strlen(buf); | |
291 | adapter->monitormode = WLAN_MONITOR_OFF; | |
292 | libertas_remove_rtap(priv); | |
293 | netif_wake_queue(priv->dev); | |
294 | netif_wake_queue(priv->mesh_dev); | |
295 | } | |
296 | ||
297 | libertas_prepare_and_send_command(priv, | |
298 | CMD_802_11_MONITOR_MODE, CMD_ACT_SET, | |
299 | CMD_OPTION_WAITFORRSP, 0, &adapter->monitormode); | |
300 | return strlen(buf); | |
301 | } | |
302 | ||
303 | /** | |
304 | * libertas_rtap attribute to be exported per mshX interface | |
305 | * through sysfs (/sys/class/net/mshX/libertas-rtap) | |
306 | */ | |
307 | static DEVICE_ATTR(libertas_rtap, 0644, libertas_rtap_get, | |
308 | libertas_rtap_set ); | |
309 | ||
876c9d3a | 310 | /** |
82fde74b LC |
311 | * anycast_mask attribute to be exported per mshX interface |
312 | * through sysfs (/sys/class/net/mshX/anycast_mask) | |
876c9d3a | 313 | */ |
82fde74b | 314 | static DEVICE_ATTR(anycast_mask, 0644, libertas_anycast_get, libertas_anycast_set); |
876c9d3a | 315 | |
a9f38d02 LCC |
316 | static ssize_t libertas_autostart_enabled_get(struct device * dev, |
317 | struct device_attribute *attr, char * buf) | |
318 | { | |
319 | struct cmd_ds_mesh_access mesh_access; | |
320 | ||
321 | memset(&mesh_access, 0, sizeof(mesh_access)); | |
322 | libertas_prepare_and_send_command(to_net_dev(dev)->priv, | |
323 | CMD_MESH_ACCESS, | |
324 | CMD_ACT_MESH_GET_AUTOSTART_ENABLED, | |
325 | CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access); | |
326 | ||
327 | return sprintf(buf, "%d\n", le32_to_cpu(mesh_access.data[0])); | |
328 | } | |
329 | ||
330 | static ssize_t libertas_autostart_enabled_set(struct device * dev, | |
331 | struct device_attribute *attr, const char * buf, size_t count) | |
332 | { | |
333 | struct cmd_ds_mesh_access mesh_access; | |
334 | uint32_t datum; | |
d21b31fd LCC |
335 | wlan_private * priv = (to_net_dev(dev))->priv; |
336 | int ret; | |
a9f38d02 LCC |
337 | |
338 | memset(&mesh_access, 0, sizeof(mesh_access)); | |
339 | sscanf(buf, "%d", &datum); | |
340 | mesh_access.data[0] = cpu_to_le32(datum); | |
341 | ||
d21b31fd | 342 | ret = libertas_prepare_and_send_command(priv, |
a9f38d02 LCC |
343 | CMD_MESH_ACCESS, |
344 | CMD_ACT_MESH_SET_AUTOSTART_ENABLED, | |
345 | CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access); | |
d21b31fd LCC |
346 | if (ret == 0) |
347 | priv->mesh_autostart_enabled = datum ? 1 : 0; | |
348 | ||
a9f38d02 LCC |
349 | return strlen(buf); |
350 | } | |
351 | ||
352 | static DEVICE_ATTR(autostart_enabled, 0644, | |
353 | libertas_autostart_enabled_get, libertas_autostart_enabled_set); | |
354 | ||
355 | static struct attribute *libertas_mesh_sysfs_entries[] = { | |
356 | &dev_attr_anycast_mask.attr, | |
357 | &dev_attr_autostart_enabled.attr, | |
358 | NULL, | |
359 | }; | |
360 | ||
361 | static struct attribute_group libertas_mesh_attr_group = { | |
362 | .attrs = libertas_mesh_sysfs_entries, | |
363 | }; | |
364 | ||
876c9d3a MT |
365 | /** |
366 | * @brief Check if the device can be open and wait if necessary. | |
367 | * | |
368 | * @param dev A pointer to net_device structure | |
369 | * @return 0 | |
370 | * | |
371 | * For USB adapter, on some systems the device open handler will be | |
372 | * called before FW ready. Use the following flag check and wait | |
373 | * function to work around the issue. | |
374 | * | |
375 | */ | |
9012b28a HS |
376 | static int pre_open_check(struct net_device *dev) |
377 | { | |
876c9d3a MT |
378 | wlan_private *priv = (wlan_private *) dev->priv; |
379 | wlan_adapter *adapter = priv->adapter; | |
380 | int i = 0; | |
381 | ||
382 | while (!adapter->fw_ready && i < 20) { | |
383 | i++; | |
384 | msleep_interruptible(100); | |
385 | } | |
386 | if (!adapter->fw_ready) { | |
9012b28a | 387 | lbs_pr_err("firmware not ready\n"); |
876c9d3a MT |
388 | return -1; |
389 | } | |
390 | ||
391 | return 0; | |
392 | } | |
393 | ||
394 | /** | |
395 | * @brief This function opens the device | |
396 | * | |
397 | * @param dev A pointer to net_device structure | |
398 | * @return 0 | |
399 | */ | |
e5241472 | 400 | static int libertas_dev_open(struct net_device *dev) |
876c9d3a MT |
401 | { |
402 | wlan_private *priv = (wlan_private *) dev->priv; | |
403 | wlan_adapter *adapter = priv->adapter; | |
404 | ||
9012b28a | 405 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a MT |
406 | |
407 | priv->open = 1; | |
408 | ||
0aef64d7 | 409 | if (adapter->connect_status == LIBERTAS_CONNECTED) { |
634b8f49 | 410 | netif_carrier_on(priv->dev); |
3cf84091 HS |
411 | if (priv->mesh_dev) |
412 | netif_carrier_on(priv->mesh_dev); | |
51d84f50 | 413 | } else { |
634b8f49 | 414 | netif_carrier_off(priv->dev); |
3cf84091 HS |
415 | if (priv->mesh_dev) |
416 | netif_carrier_off(priv->mesh_dev); | |
51d84f50 | 417 | } |
876c9d3a | 418 | |
9012b28a | 419 | lbs_deb_leave(LBS_DEB_NET); |
876c9d3a MT |
420 | return 0; |
421 | } | |
422 | /** | |
423 | * @brief This function opens the mshX interface | |
424 | * | |
425 | * @param dev A pointer to net_device structure | |
426 | * @return 0 | |
427 | */ | |
e5241472 | 428 | static int libertas_mesh_open(struct net_device *dev) |
876c9d3a MT |
429 | { |
430 | wlan_private *priv = (wlan_private *) dev->priv ; | |
431 | ||
78523daa | 432 | if (pre_open_check(dev) == -1) |
876c9d3a MT |
433 | return -1; |
434 | priv->mesh_open = 1 ; | |
51d84f50 | 435 | netif_wake_queue(priv->mesh_dev); |
876c9d3a | 436 | if (priv->infra_open == 0) |
e5241472 | 437 | return libertas_dev_open(priv->dev) ; |
876c9d3a MT |
438 | return 0; |
439 | } | |
440 | ||
441 | /** | |
442 | * @brief This function opens the ethX interface | |
443 | * | |
444 | * @param dev A pointer to net_device structure | |
445 | * @return 0 | |
446 | */ | |
e5241472 | 447 | static int libertas_open(struct net_device *dev) |
876c9d3a MT |
448 | { |
449 | wlan_private *priv = (wlan_private *) dev->priv ; | |
450 | ||
451 | if(pre_open_check(dev) == -1) | |
452 | return -1; | |
453 | priv->infra_open = 1 ; | |
634b8f49 | 454 | netif_wake_queue(priv->dev); |
876c9d3a | 455 | if (priv->open == 0) |
e5241472 | 456 | return libertas_dev_open(priv->dev) ; |
876c9d3a MT |
457 | return 0; |
458 | } | |
459 | ||
e5241472 | 460 | static int libertas_dev_close(struct net_device *dev) |
876c9d3a MT |
461 | { |
462 | wlan_private *priv = dev->priv; | |
463 | ||
9012b28a | 464 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a | 465 | |
634b8f49 | 466 | netif_carrier_off(priv->dev); |
876c9d3a MT |
467 | priv->open = 0; |
468 | ||
9012b28a | 469 | lbs_deb_leave(LBS_DEB_NET); |
876c9d3a MT |
470 | return 0; |
471 | } | |
472 | ||
473 | /** | |
474 | * @brief This function closes the mshX interface | |
475 | * | |
476 | * @param dev A pointer to net_device structure | |
477 | * @return 0 | |
478 | */ | |
e5241472 | 479 | static int libertas_mesh_close(struct net_device *dev) |
876c9d3a MT |
480 | { |
481 | wlan_private *priv = (wlan_private *) (dev->priv); | |
482 | ||
483 | priv->mesh_open = 0; | |
484 | netif_stop_queue(priv->mesh_dev); | |
485 | if (priv->infra_open == 0) | |
e5241472 | 486 | return libertas_dev_close(dev); |
876c9d3a MT |
487 | else |
488 | return 0; | |
489 | } | |
490 | ||
491 | /** | |
492 | * @brief This function closes the ethX interface | |
493 | * | |
494 | * @param dev A pointer to net_device structure | |
495 | * @return 0 | |
496 | */ | |
e5241472 | 497 | static int libertas_close(struct net_device *dev) |
78523daa | 498 | { |
876c9d3a MT |
499 | wlan_private *priv = (wlan_private *) dev->priv; |
500 | ||
634b8f49 | 501 | netif_stop_queue(dev); |
876c9d3a MT |
502 | priv->infra_open = 0; |
503 | if (priv->mesh_open == 0) | |
e5241472 | 504 | return libertas_dev_close(dev); |
876c9d3a MT |
505 | else |
506 | return 0; | |
507 | } | |
508 | ||
509 | ||
e5241472 | 510 | static int libertas_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
876c9d3a MT |
511 | { |
512 | int ret = 0; | |
513 | wlan_private *priv = dev->priv; | |
514 | ||
9012b28a | 515 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a | 516 | |
634b8f49 | 517 | if (priv->dnld_sent || priv->adapter->TxLockFlag) { |
876c9d3a MT |
518 | priv->stats.tx_dropped++; |
519 | goto done; | |
520 | } | |
521 | ||
634b8f49 | 522 | netif_stop_queue(priv->dev); |
3cf84091 HS |
523 | if (priv->mesh_dev) |
524 | netif_stop_queue(priv->mesh_dev); | |
876c9d3a MT |
525 | |
526 | if (libertas_process_tx(priv, skb) == 0) | |
527 | dev->trans_start = jiffies; | |
528 | done: | |
9012b28a | 529 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
876c9d3a MT |
530 | return ret; |
531 | } | |
532 | ||
533 | /** | |
e5241472 | 534 | * @brief Mark mesh packets and handover them to libertas_hard_start_xmit |
876c9d3a MT |
535 | * |
536 | */ | |
e5241472 DW |
537 | static int libertas_mesh_pre_start_xmit(struct sk_buff *skb, |
538 | struct net_device *dev) | |
876c9d3a MT |
539 | { |
540 | wlan_private *priv = dev->priv; | |
9012b28a HS |
541 | int ret; |
542 | ||
543 | lbs_deb_enter(LBS_DEB_MESH); | |
965f8bbc LCC |
544 | if(priv->adapter->monitormode != WLAN_MONITOR_OFF) { |
545 | netif_stop_queue(dev); | |
546 | return -EOPNOTSUPP; | |
547 | } | |
9012b28a | 548 | |
876c9d3a | 549 | SET_MESH_FRAME(skb); |
876c9d3a | 550 | |
e5241472 | 551 | ret = libertas_hard_start_xmit(skb, priv->dev); |
9012b28a HS |
552 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); |
553 | return ret; | |
876c9d3a MT |
554 | } |
555 | ||
556 | /** | |
e5241472 | 557 | * @brief Mark non-mesh packets and handover them to libertas_hard_start_xmit |
876c9d3a MT |
558 | * |
559 | */ | |
e5241472 | 560 | static int libertas_pre_start_xmit(struct sk_buff *skb, struct net_device *dev) |
9012b28a | 561 | { |
965f8bbc | 562 | wlan_private *priv = dev->priv; |
9012b28a HS |
563 | int ret; |
564 | ||
565 | lbs_deb_enter(LBS_DEB_NET); | |
566 | ||
965f8bbc LCC |
567 | if(priv->adapter->monitormode != WLAN_MONITOR_OFF) { |
568 | netif_stop_queue(dev); | |
569 | return -EOPNOTSUPP; | |
570 | } | |
571 | ||
876c9d3a | 572 | UNSET_MESH_FRAME(skb); |
9012b28a | 573 | |
e5241472 | 574 | ret = libertas_hard_start_xmit(skb, dev); |
9012b28a HS |
575 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
576 | return ret; | |
876c9d3a MT |
577 | } |
578 | ||
e5241472 | 579 | static void libertas_tx_timeout(struct net_device *dev) |
876c9d3a MT |
580 | { |
581 | wlan_private *priv = (wlan_private *) dev->priv; | |
582 | ||
9012b28a | 583 | lbs_deb_enter(LBS_DEB_TX); |
876c9d3a | 584 | |
9012b28a | 585 | lbs_pr_err("tx watch dog timeout\n"); |
876c9d3a | 586 | |
634b8f49 | 587 | priv->dnld_sent = DNLD_RES_RECEIVED; |
876c9d3a MT |
588 | dev->trans_start = jiffies; |
589 | ||
590 | if (priv->adapter->currenttxskb) { | |
965f8bbc | 591 | if (priv->adapter->monitormode != WLAN_MONITOR_OFF) { |
876c9d3a MT |
592 | /* If we are here, we have not received feedback from |
593 | the previous packet. Assume TX_FAIL and move on. */ | |
594 | priv->adapter->eventcause = 0x01000000; | |
595 | libertas_send_tx_feedback(priv); | |
596 | } else | |
fe336150 | 597 | wake_up_interruptible(&priv->waitq); |
0aef64d7 | 598 | } else if (priv->adapter->connect_status == LIBERTAS_CONNECTED) { |
634b8f49 | 599 | netif_wake_queue(priv->dev); |
3cf84091 HS |
600 | if (priv->mesh_dev) |
601 | netif_wake_queue(priv->mesh_dev); | |
51d84f50 | 602 | } |
876c9d3a | 603 | |
9012b28a | 604 | lbs_deb_leave(LBS_DEB_TX); |
876c9d3a MT |
605 | } |
606 | ||
607 | /** | |
608 | * @brief This function returns the network statistics | |
609 | * | |
610 | * @param dev A pointer to wlan_private structure | |
611 | * @return A pointer to net_device_stats structure | |
612 | */ | |
e5241472 | 613 | static struct net_device_stats *libertas_get_stats(struct net_device *dev) |
876c9d3a MT |
614 | { |
615 | wlan_private *priv = (wlan_private *) dev->priv; | |
616 | ||
617 | return &priv->stats; | |
618 | } | |
619 | ||
e5241472 | 620 | static int libertas_set_mac_address(struct net_device *dev, void *addr) |
876c9d3a MT |
621 | { |
622 | int ret = 0; | |
623 | wlan_private *priv = (wlan_private *) dev->priv; | |
624 | wlan_adapter *adapter = priv->adapter; | |
625 | struct sockaddr *phwaddr = addr; | |
626 | ||
9012b28a | 627 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a | 628 | |
0a0d08ac LCCR |
629 | /* In case it was called from the mesh device */ |
630 | dev = priv->dev ; | |
631 | ||
876c9d3a MT |
632 | memset(adapter->current_addr, 0, ETH_ALEN); |
633 | ||
634 | /* dev->dev_addr is 8 bytes */ | |
ece56191 | 635 | lbs_deb_hex(LBS_DEB_NET, "dev->dev_addr", dev->dev_addr, ETH_ALEN); |
876c9d3a | 636 | |
ece56191 | 637 | lbs_deb_hex(LBS_DEB_NET, "addr", phwaddr->sa_data, ETH_ALEN); |
876c9d3a MT |
638 | memcpy(adapter->current_addr, phwaddr->sa_data, ETH_ALEN); |
639 | ||
0aef64d7 DW |
640 | ret = libertas_prepare_and_send_command(priv, CMD_802_11_MAC_ADDRESS, |
641 | CMD_ACT_SET, | |
642 | CMD_OPTION_WAITFORRSP, 0, NULL); | |
876c9d3a MT |
643 | |
644 | if (ret) { | |
9012b28a | 645 | lbs_deb_net("set MAC address failed\n"); |
876c9d3a MT |
646 | ret = -1; |
647 | goto done; | |
648 | } | |
649 | ||
ece56191 | 650 | lbs_deb_hex(LBS_DEB_NET, "adapter->macaddr", adapter->current_addr, ETH_ALEN); |
876c9d3a | 651 | memcpy(dev->dev_addr, adapter->current_addr, ETH_ALEN); |
78523daa HS |
652 | if (priv->mesh_dev) |
653 | memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN); | |
876c9d3a MT |
654 | |
655 | done: | |
9012b28a | 656 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
876c9d3a MT |
657 | return ret; |
658 | } | |
659 | ||
e5241472 | 660 | static int libertas_copy_multicast_address(wlan_adapter * adapter, |
876c9d3a MT |
661 | struct net_device *dev) |
662 | { | |
663 | int i = 0; | |
664 | struct dev_mc_list *mcptr = dev->mc_list; | |
665 | ||
666 | for (i = 0; i < dev->mc_count; i++) { | |
667 | memcpy(&adapter->multicastlist[i], mcptr->dmi_addr, ETH_ALEN); | |
668 | mcptr = mcptr->next; | |
669 | } | |
670 | ||
671 | return i; | |
672 | ||
673 | } | |
674 | ||
e5241472 | 675 | static void libertas_set_multicast_list(struct net_device *dev) |
876c9d3a MT |
676 | { |
677 | wlan_private *priv = dev->priv; | |
678 | wlan_adapter *adapter = priv->adapter; | |
679 | int oldpacketfilter; | |
680 | ||
9012b28a | 681 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a MT |
682 | |
683 | oldpacketfilter = adapter->currentpacketfilter; | |
684 | ||
685 | if (dev->flags & IFF_PROMISC) { | |
9012b28a | 686 | lbs_deb_net("enable promiscuous mode\n"); |
876c9d3a | 687 | adapter->currentpacketfilter |= |
0aef64d7 | 688 | CMD_ACT_MAC_PROMISCUOUS_ENABLE; |
876c9d3a | 689 | adapter->currentpacketfilter &= |
0aef64d7 DW |
690 | ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE | |
691 | CMD_ACT_MAC_MULTICAST_ENABLE); | |
876c9d3a MT |
692 | } else { |
693 | /* Multicast */ | |
694 | adapter->currentpacketfilter &= | |
0aef64d7 | 695 | ~CMD_ACT_MAC_PROMISCUOUS_ENABLE; |
876c9d3a MT |
696 | |
697 | if (dev->flags & IFF_ALLMULTI || dev->mc_count > | |
698 | MRVDRV_MAX_MULTICAST_LIST_SIZE) { | |
9012b28a | 699 | lbs_deb_net( "enabling all multicast\n"); |
876c9d3a | 700 | adapter->currentpacketfilter |= |
0aef64d7 | 701 | CMD_ACT_MAC_ALL_MULTICAST_ENABLE; |
876c9d3a | 702 | adapter->currentpacketfilter &= |
0aef64d7 | 703 | ~CMD_ACT_MAC_MULTICAST_ENABLE; |
876c9d3a MT |
704 | } else { |
705 | adapter->currentpacketfilter &= | |
0aef64d7 | 706 | ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE; |
876c9d3a MT |
707 | |
708 | if (!dev->mc_count) { | |
9012b28a HS |
709 | lbs_deb_net("no multicast addresses, " |
710 | "disabling multicast\n"); | |
876c9d3a | 711 | adapter->currentpacketfilter &= |
0aef64d7 | 712 | ~CMD_ACT_MAC_MULTICAST_ENABLE; |
876c9d3a MT |
713 | } else { |
714 | int i; | |
715 | ||
716 | adapter->currentpacketfilter |= | |
0aef64d7 | 717 | CMD_ACT_MAC_MULTICAST_ENABLE; |
876c9d3a MT |
718 | |
719 | adapter->nr_of_multicastmacaddr = | |
e5241472 | 720 | libertas_copy_multicast_address(adapter, dev); |
876c9d3a | 721 | |
9012b28a | 722 | lbs_deb_net("multicast addresses: %d\n", |
876c9d3a MT |
723 | dev->mc_count); |
724 | ||
725 | for (i = 0; i < dev->mc_count; i++) { | |
9012b28a HS |
726 | lbs_deb_net("Multicast address %d:" |
727 | MAC_FMT "\n", i, | |
876c9d3a MT |
728 | adapter->multicastlist[i][0], |
729 | adapter->multicastlist[i][1], | |
730 | adapter->multicastlist[i][2], | |
731 | adapter->multicastlist[i][3], | |
732 | adapter->multicastlist[i][4], | |
733 | adapter->multicastlist[i][5]); | |
734 | } | |
9012b28a | 735 | /* send multicast addresses to firmware */ |
876c9d3a | 736 | libertas_prepare_and_send_command(priv, |
0aef64d7 DW |
737 | CMD_MAC_MULTICAST_ADR, |
738 | CMD_ACT_SET, 0, 0, | |
876c9d3a MT |
739 | NULL); |
740 | } | |
741 | } | |
742 | } | |
743 | ||
744 | if (adapter->currentpacketfilter != oldpacketfilter) { | |
745 | libertas_set_mac_packet_filter(priv); | |
746 | } | |
747 | ||
9012b28a | 748 | lbs_deb_leave(LBS_DEB_NET); |
876c9d3a MT |
749 | } |
750 | ||
751 | /** | |
9012b28a HS |
752 | * @brief This function handles the major jobs in the WLAN driver. |
753 | * It handles all events generated by firmware, RX data received | |
754 | * from firmware and TX data sent from kernel. | |
876c9d3a MT |
755 | * |
756 | * @param data A pointer to wlan_thread structure | |
757 | * @return 0 | |
758 | */ | |
fe336150 | 759 | static int libertas_thread(void *data) |
876c9d3a | 760 | { |
fe336150 DW |
761 | struct net_device *dev = data; |
762 | wlan_private *priv = dev->priv; | |
876c9d3a MT |
763 | wlan_adapter *adapter = priv->adapter; |
764 | wait_queue_t wait; | |
765 | u8 ireg = 0; | |
766 | ||
9012b28a | 767 | lbs_deb_enter(LBS_DEB_THREAD); |
876c9d3a | 768 | |
876c9d3a MT |
769 | init_waitqueue_entry(&wait, current); |
770 | ||
b1b1907d | 771 | set_freezable(); |
876c9d3a | 772 | for (;;) { |
9012b28a | 773 | lbs_deb_thread( "main-thread 111: intcounter=%d " |
876c9d3a MT |
774 | "currenttxskb=%p dnld_sent=%d\n", |
775 | adapter->intcounter, | |
634b8f49 | 776 | adapter->currenttxskb, priv->dnld_sent); |
876c9d3a | 777 | |
fe336150 | 778 | add_wait_queue(&priv->waitq, &wait); |
876c9d3a MT |
779 | set_current_state(TASK_INTERRUPTIBLE); |
780 | spin_lock_irq(&adapter->driver_lock); | |
781 | if ((adapter->psstate == PS_STATE_SLEEP) || | |
782 | (!adapter->intcounter | |
634b8f49 | 783 | && (priv->dnld_sent || adapter->cur_cmd || |
876c9d3a | 784 | list_empty(&adapter->cmdpendingq)))) { |
9012b28a | 785 | lbs_deb_thread( |
876c9d3a MT |
786 | "main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n", |
787 | adapter->connect_status, adapter->intcounter, | |
788 | adapter->psmode, adapter->psstate); | |
789 | spin_unlock_irq(&adapter->driver_lock); | |
790 | schedule(); | |
791 | } else | |
792 | spin_unlock_irq(&adapter->driver_lock); | |
793 | ||
9012b28a | 794 | lbs_deb_thread( |
876c9d3a MT |
795 | "main-thread 222 (waking up): intcounter=%d currenttxskb=%p " |
796 | "dnld_sent=%d\n", adapter->intcounter, | |
634b8f49 | 797 | adapter->currenttxskb, priv->dnld_sent); |
876c9d3a MT |
798 | |
799 | set_current_state(TASK_RUNNING); | |
fe336150 | 800 | remove_wait_queue(&priv->waitq, &wait); |
876c9d3a MT |
801 | try_to_freeze(); |
802 | ||
9012b28a | 803 | lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p " |
876c9d3a MT |
804 | "dnld_sent=%d\n", |
805 | adapter->intcounter, | |
634b8f49 | 806 | adapter->currenttxskb, priv->dnld_sent); |
876c9d3a MT |
807 | |
808 | if (kthread_should_stop() | |
809 | || adapter->surpriseremoved) { | |
9012b28a | 810 | lbs_deb_thread( |
876c9d3a MT |
811 | "main-thread: break from main thread: surpriseremoved=0x%x\n", |
812 | adapter->surpriseremoved); | |
813 | break; | |
814 | } | |
815 | ||
816 | ||
817 | spin_lock_irq(&adapter->driver_lock); | |
818 | if (adapter->intcounter) { | |
819 | u8 int_status; | |
820 | adapter->intcounter = 0; | |
208fdd2f | 821 | int_status = priv->hw_get_int_status(priv, &ireg); |
876c9d3a MT |
822 | |
823 | if (int_status) { | |
9012b28a | 824 | lbs_deb_thread( |
876c9d3a MT |
825 | "main-thread: reading HOST_INT_STATUS_REG failed\n"); |
826 | spin_unlock_irq(&adapter->driver_lock); | |
827 | continue; | |
828 | } | |
829 | adapter->hisregcpy |= ireg; | |
830 | } | |
831 | ||
9012b28a | 832 | lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p " |
876c9d3a MT |
833 | "dnld_sent=%d\n", |
834 | adapter->intcounter, | |
634b8f49 | 835 | adapter->currenttxskb, priv->dnld_sent); |
876c9d3a MT |
836 | |
837 | /* command response? */ | |
c95c7f93 | 838 | if (adapter->hisregcpy & MRVDRV_CMD_UPLD_RDY) { |
9012b28a | 839 | lbs_deb_thread("main-thread: cmd response ready\n"); |
876c9d3a | 840 | |
c95c7f93 | 841 | adapter->hisregcpy &= ~MRVDRV_CMD_UPLD_RDY; |
876c9d3a MT |
842 | spin_unlock_irq(&adapter->driver_lock); |
843 | libertas_process_rx_command(priv); | |
844 | spin_lock_irq(&adapter->driver_lock); | |
845 | } | |
846 | ||
847 | /* Any Card Event */ | |
c95c7f93 | 848 | if (adapter->hisregcpy & MRVDRV_CARDEVENT) { |
9012b28a | 849 | lbs_deb_thread("main-thread: Card Event Activity\n"); |
876c9d3a | 850 | |
c95c7f93 | 851 | adapter->hisregcpy &= ~MRVDRV_CARDEVENT; |
876c9d3a | 852 | |
208fdd2f | 853 | if (priv->hw_read_event_cause(priv)) { |
876c9d3a | 854 | lbs_pr_alert( |
208fdd2f | 855 | "main-thread: hw_read_event_cause failed\n"); |
876c9d3a MT |
856 | spin_unlock_irq(&adapter->driver_lock); |
857 | continue; | |
858 | } | |
859 | spin_unlock_irq(&adapter->driver_lock); | |
860 | libertas_process_event(priv); | |
861 | } else | |
862 | spin_unlock_irq(&adapter->driver_lock); | |
863 | ||
864 | /* Check if we need to confirm Sleep Request received previously */ | |
865 | if (adapter->psstate == PS_STATE_PRE_SLEEP) { | |
634b8f49 | 866 | if (!priv->dnld_sent && !adapter->cur_cmd) { |
876c9d3a | 867 | if (adapter->connect_status == |
0aef64d7 | 868 | LIBERTAS_CONNECTED) { |
9012b28a | 869 | lbs_deb_thread( |
876c9d3a MT |
870 | "main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p " |
871 | "dnld_sent=%d cur_cmd=%p, confirm now\n", | |
872 | adapter->intcounter, | |
873 | adapter->currenttxskb, | |
634b8f49 | 874 | priv->dnld_sent, |
876c9d3a MT |
875 | adapter->cur_cmd); |
876 | ||
877 | libertas_ps_confirm_sleep(priv, | |
878 | (u16) adapter->psmode); | |
879 | } else { | |
880 | /* workaround for firmware sending | |
881 | * deauth/linkloss event immediately | |
882 | * after sleep request, remove this | |
883 | * after firmware fixes it | |
884 | */ | |
885 | adapter->psstate = PS_STATE_AWAKE; | |
886 | lbs_pr_alert( | |
887 | "main-thread: ignore PS_SleepConfirm in non-connected state\n"); | |
888 | } | |
889 | } | |
890 | } | |
891 | ||
892 | /* The PS state is changed during processing of Sleep Request | |
893 | * event above | |
894 | */ | |
895 | if ((priv->adapter->psstate == PS_STATE_SLEEP) || | |
896 | (priv->adapter->psstate == PS_STATE_PRE_SLEEP)) | |
897 | continue; | |
898 | ||
899 | /* Execute the next command */ | |
634b8f49 | 900 | if (!priv->dnld_sent && !priv->adapter->cur_cmd) |
876c9d3a MT |
901 | libertas_execute_next_command(priv); |
902 | ||
903 | /* Wake-up command waiters which can't sleep in | |
904 | * libertas_prepare_and_send_command | |
905 | */ | |
906 | if (!adapter->nr_cmd_pending) | |
907 | wake_up_all(&adapter->cmd_pending); | |
908 | ||
909 | libertas_tx_runqueue(priv); | |
910 | } | |
911 | ||
912 | del_timer(&adapter->command_timer); | |
913 | adapter->nr_cmd_pending = 0; | |
914 | wake_up_all(&adapter->cmd_pending); | |
876c9d3a | 915 | |
9012b28a | 916 | lbs_deb_leave(LBS_DEB_THREAD); |
876c9d3a MT |
917 | return 0; |
918 | } | |
919 | ||
1df4e8fe HS |
920 | /** |
921 | * @brief This function downloads firmware image, gets | |
922 | * HW spec from firmware and set basic parameters to | |
923 | * firmware. | |
924 | * | |
925 | * @param priv A pointer to wlan_private structure | |
926 | * @return 0 or -1 | |
927 | */ | |
954ee164 | 928 | static int wlan_setup_firmware(wlan_private * priv) |
1df4e8fe HS |
929 | { |
930 | int ret = -1; | |
931 | wlan_adapter *adapter = priv->adapter; | |
d21b31fd | 932 | struct cmd_ds_mesh_access mesh_access; |
1df4e8fe HS |
933 | |
934 | lbs_deb_enter(LBS_DEB_FW); | |
935 | ||
1df4e8fe HS |
936 | /* |
937 | * Read MAC address from HW | |
938 | */ | |
939 | memset(adapter->current_addr, 0xff, ETH_ALEN); | |
940 | ||
941 | ret = libertas_prepare_and_send_command(priv, CMD_GET_HW_SPEC, | |
942 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); | |
943 | ||
944 | if (ret) { | |
945 | ret = -1; | |
946 | goto done; | |
947 | } | |
948 | ||
949 | libertas_set_mac_packet_filter(priv); | |
950 | ||
951 | /* Get the supported Data rates */ | |
952 | ret = libertas_prepare_and_send_command(priv, CMD_802_11_DATA_RATE, | |
953 | CMD_ACT_GET_TX_RATE, | |
954 | CMD_OPTION_WAITFORRSP, 0, NULL); | |
955 | ||
956 | if (ret) { | |
957 | ret = -1; | |
958 | goto done; | |
959 | } | |
960 | ||
d21b31fd LCC |
961 | /* Disable mesh autostart */ |
962 | if (priv->mesh_dev) { | |
963 | memset(&mesh_access, 0, sizeof(mesh_access)); | |
964 | mesh_access.data[0] = cpu_to_le32(0); | |
965 | ret = libertas_prepare_and_send_command(priv, | |
966 | CMD_MESH_ACCESS, | |
967 | CMD_ACT_MESH_SET_AUTOSTART_ENABLED, | |
968 | CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access); | |
969 | if (ret) { | |
970 | ret = -1; | |
971 | goto done; | |
972 | } | |
973 | priv->mesh_autostart_enabled = 0; | |
974 | } | |
975 | ||
63f0023b LCC |
976 | /* Set the boot2 version in firmware */ |
977 | ret = libertas_prepare_and_send_command(priv, CMD_SET_BOOT2_VER, | |
978 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); | |
979 | ||
1df4e8fe HS |
980 | ret = 0; |
981 | done: | |
982 | lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret); | |
983 | return ret; | |
984 | } | |
985 | ||
1df4e8fe HS |
986 | /** |
987 | * This function handles the timeout of command sending. | |
988 | * It will re-send the same command again. | |
989 | */ | |
990 | static void command_timer_fn(unsigned long data) | |
991 | { | |
992 | wlan_private *priv = (wlan_private *)data; | |
993 | wlan_adapter *adapter = priv->adapter; | |
994 | struct cmd_ctrl_node *ptempnode; | |
995 | struct cmd_ds_command *cmd; | |
996 | unsigned long flags; | |
997 | ||
998 | ptempnode = adapter->cur_cmd; | |
999 | if (ptempnode == NULL) { | |
1000 | lbs_deb_fw("ptempnode empty\n"); | |
1001 | return; | |
1002 | } | |
1003 | ||
1004 | cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr; | |
1005 | if (!cmd) { | |
1006 | lbs_deb_fw("cmd is NULL\n"); | |
1007 | return; | |
1008 | } | |
1009 | ||
1010 | lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command); | |
1011 | ||
1012 | if (!adapter->fw_ready) | |
1013 | return; | |
1014 | ||
1015 | spin_lock_irqsave(&adapter->driver_lock, flags); | |
1016 | adapter->cur_cmd = NULL; | |
1017 | spin_unlock_irqrestore(&adapter->driver_lock, flags); | |
1018 | ||
1019 | lbs_deb_fw("re-sending same command because of timeout\n"); | |
1020 | libertas_queue_cmd(adapter, ptempnode, 0); | |
1021 | ||
1022 | wake_up_interruptible(&priv->waitq); | |
1023 | ||
1024 | return; | |
1025 | } | |
1026 | ||
954ee164 | 1027 | static int libertas_init_adapter(wlan_private * priv) |
ac558ca2 HS |
1028 | { |
1029 | wlan_adapter *adapter = priv->adapter; | |
1df4e8fe | 1030 | size_t bufsize; |
954ee164 | 1031 | int i, ret = 0; |
1df4e8fe HS |
1032 | |
1033 | /* Allocate buffer to store the BSSID list */ | |
1034 | bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor); | |
1035 | adapter->networks = kzalloc(bufsize, GFP_KERNEL); | |
1036 | if (!adapter->networks) { | |
1037 | lbs_pr_err("Out of memory allocating beacons\n"); | |
954ee164 DW |
1038 | ret = -1; |
1039 | goto out; | |
1df4e8fe HS |
1040 | } |
1041 | ||
954ee164 DW |
1042 | /* Initialize scan result lists */ |
1043 | INIT_LIST_HEAD(&adapter->network_free_list); | |
1044 | INIT_LIST_HEAD(&adapter->network_list); | |
1045 | for (i = 0; i < MAX_NETWORK_COUNT; i++) { | |
1046 | list_add_tail(&adapter->networks[i].list, | |
1047 | &adapter->network_free_list); | |
1048 | } | |
1df4e8fe | 1049 | |
1df4e8fe HS |
1050 | adapter->libertas_ps_confirm_sleep.seqnum = cpu_to_le16(++adapter->seqnum); |
1051 | adapter->libertas_ps_confirm_sleep.command = | |
1052 | cpu_to_le16(CMD_802_11_PS_MODE); | |
1053 | adapter->libertas_ps_confirm_sleep.size = | |
1054 | cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep)); | |
1df4e8fe HS |
1055 | adapter->libertas_ps_confirm_sleep.action = |
1056 | cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED); | |
1057 | ||
1df4e8fe HS |
1058 | memset(adapter->current_addr, 0xff, ETH_ALEN); |
1059 | ||
954ee164 | 1060 | adapter->connect_status = LIBERTAS_DISCONNECTED; |
1df4e8fe HS |
1061 | adapter->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
1062 | adapter->mode = IW_MODE_INFRA; | |
1df4e8fe | 1063 | adapter->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL; |
954ee164 | 1064 | adapter->currentpacketfilter = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON; |
1df4e8fe | 1065 | adapter->radioon = RADIO_ON; |
1df4e8fe | 1066 | adapter->auto_rate = 1; |
1df4e8fe | 1067 | adapter->capability = WLAN_CAPABILITY_SHORT_PREAMBLE; |
1df4e8fe | 1068 | adapter->psmode = WLAN802_11POWERMODECAM; |
1df4e8fe | 1069 | adapter->psstate = PS_STATE_FULL_POWER; |
1df4e8fe | 1070 | |
954ee164 | 1071 | mutex_init(&adapter->lock); |
1df4e8fe HS |
1072 | |
1073 | memset(&adapter->tx_queue_ps, 0, NR_TX_QUEUE*sizeof(struct sk_buff*)); | |
1074 | adapter->tx_queue_idx = 0; | |
1075 | spin_lock_init(&adapter->txqueue_lock); | |
1076 | ||
954ee164 DW |
1077 | setup_timer(&adapter->command_timer, command_timer_fn, |
1078 | (unsigned long)priv); | |
1df4e8fe | 1079 | |
954ee164 DW |
1080 | INIT_LIST_HEAD(&adapter->cmdfreeq); |
1081 | INIT_LIST_HEAD(&adapter->cmdpendingq); | |
1df4e8fe | 1082 | |
954ee164 DW |
1083 | spin_lock_init(&adapter->driver_lock); |
1084 | init_waitqueue_head(&adapter->cmd_pending); | |
1085 | adapter->nr_cmd_pending = 0; | |
1df4e8fe | 1086 | |
954ee164 DW |
1087 | /* Allocate the command buffers */ |
1088 | if (libertas_allocate_cmd_buffer(priv)) { | |
1089 | lbs_pr_err("Out of memory allocating command buffers\n"); | |
1090 | ret = -1; | |
1091 | } | |
1df4e8fe | 1092 | |
954ee164 DW |
1093 | out: |
1094 | return ret; | |
1095 | } | |
1df4e8fe | 1096 | |
954ee164 DW |
1097 | static void libertas_free_adapter(wlan_private * priv) |
1098 | { | |
1099 | wlan_adapter *adapter = priv->adapter; | |
1df4e8fe | 1100 | |
954ee164 DW |
1101 | if (!adapter) { |
1102 | lbs_deb_fw("why double free adapter?\n"); | |
1103 | return; | |
1df4e8fe HS |
1104 | } |
1105 | ||
954ee164 DW |
1106 | lbs_deb_fw("free command buffer\n"); |
1107 | libertas_free_cmd_buffer(priv); | |
1df4e8fe | 1108 | |
954ee164 DW |
1109 | lbs_deb_fw("free command_timer\n"); |
1110 | del_timer(&adapter->command_timer); | |
1111 | ||
1112 | lbs_deb_fw("free scan results table\n"); | |
1113 | kfree(adapter->networks); | |
1114 | adapter->networks = NULL; | |
1115 | ||
1116 | /* Free the adapter object itself */ | |
1117 | lbs_deb_fw("free adapter\n"); | |
1118 | kfree(adapter); | |
1119 | priv->adapter = NULL; | |
1df4e8fe HS |
1120 | } |
1121 | ||
876c9d3a MT |
1122 | /** |
1123 | * @brief This function adds the card. it will probe the | |
1124 | * card, allocate the wlan_priv and initialize the device. | |
1125 | * | |
1126 | * @param card A pointer to card | |
1127 | * @return A pointer to wlan_private structure | |
1128 | */ | |
7732ca45 | 1129 | wlan_private *libertas_add_card(void *card, struct device *dmdev) |
876c9d3a MT |
1130 | { |
1131 | struct net_device *dev = NULL; | |
876c9d3a MT |
1132 | wlan_private *priv = NULL; |
1133 | ||
9012b28a | 1134 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a MT |
1135 | |
1136 | /* Allocate an Ethernet device and register it */ | |
1137 | if (!(dev = alloc_etherdev(sizeof(wlan_private)))) { | |
9012b28a | 1138 | lbs_pr_err("init ethX device failed\n"); |
954ee164 | 1139 | goto done; |
876c9d3a | 1140 | } |
64f104e8 | 1141 | priv = dev->priv; |
876c9d3a MT |
1142 | |
1143 | /* allocate buffer for wlan_adapter */ | |
fb3dddf2 | 1144 | if (!(priv->adapter = kzalloc(sizeof(wlan_adapter), GFP_KERNEL))) { |
9012b28a | 1145 | lbs_pr_err("allocate buffer for wlan_adapter failed\n"); |
fb3dddf2 | 1146 | goto err_kzalloc; |
876c9d3a MT |
1147 | } |
1148 | ||
954ee164 DW |
1149 | if (libertas_init_adapter(priv)) { |
1150 | lbs_pr_err("failed to initialize adapter structure.\n"); | |
1151 | goto err_init_adapter; | |
1152 | } | |
1153 | ||
634b8f49 HS |
1154 | priv->dev = dev; |
1155 | priv->card = card; | |
876c9d3a MT |
1156 | priv->mesh_open = 0; |
1157 | priv->infra_open = 0; | |
954ee164 | 1158 | priv->hotplug_device = dmdev; |
876c9d3a | 1159 | |
876c9d3a | 1160 | /* Setup the OS Interface to our functions */ |
e5241472 DW |
1161 | dev->open = libertas_open; |
1162 | dev->hard_start_xmit = libertas_pre_start_xmit; | |
1163 | dev->stop = libertas_close; | |
1164 | dev->set_mac_address = libertas_set_mac_address; | |
1165 | dev->tx_timeout = libertas_tx_timeout; | |
1166 | dev->get_stats = libertas_get_stats; | |
fb3dddf2 | 1167 | dev->watchdog_timeo = 5 * HZ; |
876c9d3a | 1168 | dev->ethtool_ops = &libertas_ethtool_ops; |
876c9d3a MT |
1169 | #ifdef WIRELESS_EXT |
1170 | dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def; | |
876c9d3a MT |
1171 | #endif |
1172 | #define NETIF_F_DYNALLOC 16 | |
1173 | dev->features |= NETIF_F_DYNALLOC; | |
1174 | dev->flags |= IFF_BROADCAST | IFF_MULTICAST; | |
e5241472 | 1175 | dev->set_multicast_list = libertas_set_multicast_list; |
876c9d3a | 1176 | |
7732ca45 DW |
1177 | SET_NETDEV_DEV(dev, dmdev); |
1178 | ||
965f8bbc LCC |
1179 | priv->rtap_net_dev = NULL; |
1180 | if (device_create_file(dmdev, &dev_attr_libertas_rtap)) | |
954ee164 DW |
1181 | goto err_init_adapter; |
1182 | ||
1183 | lbs_deb_thread("Starting main thread...\n"); | |
1184 | init_waitqueue_head(&priv->waitq); | |
1185 | priv->main_thread = kthread_run(libertas_thread, dev, "libertas_main"); | |
1186 | if (IS_ERR(priv->main_thread)) { | |
1187 | lbs_deb_thread("Error creating main thread.\n"); | |
1188 | goto err_kthread_run; | |
1189 | } | |
1190 | ||
1191 | priv->work_thread = create_singlethread_workqueue("libertas_worker"); | |
1192 | INIT_DELAYED_WORK(&priv->assoc_work, libertas_association_worker); | |
1193 | INIT_DELAYED_WORK(&priv->scan_work, libertas_scan_worker); | |
1194 | INIT_WORK(&priv->sync_channel, libertas_sync_channel); | |
1195 | ||
32a74b7c HS |
1196 | goto done; |
1197 | ||
954ee164 DW |
1198 | err_kthread_run: |
1199 | device_remove_file(dmdev, &dev_attr_libertas_rtap); | |
1200 | ||
1201 | err_init_adapter: | |
1202 | libertas_free_adapter(priv); | |
1203 | ||
32a74b7c HS |
1204 | err_kzalloc: |
1205 | free_netdev(dev); | |
6a812157 | 1206 | priv = NULL; |
954ee164 | 1207 | |
32a74b7c HS |
1208 | done: |
1209 | lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv); | |
1210 | return priv; | |
1211 | } | |
084708b6 | 1212 | EXPORT_SYMBOL_GPL(libertas_add_card); |
32a74b7c | 1213 | |
954ee164 DW |
1214 | |
1215 | int libertas_remove_card(wlan_private *priv) | |
32a74b7c | 1216 | { |
954ee164 | 1217 | wlan_adapter *adapter = priv->adapter; |
634b8f49 | 1218 | struct net_device *dev = priv->dev; |
954ee164 | 1219 | union iwreq_data wrqu; |
32a74b7c HS |
1220 | |
1221 | lbs_deb_enter(LBS_DEB_MAIN); | |
876c9d3a | 1222 | |
954ee164 | 1223 | libertas_remove_rtap(priv); |
876c9d3a | 1224 | |
954ee164 DW |
1225 | dev = priv->dev; |
1226 | device_remove_file(priv->hotplug_device, &dev_attr_libertas_rtap); | |
2afc0c5d | 1227 | |
954ee164 DW |
1228 | cancel_delayed_work(&priv->scan_work); |
1229 | cancel_delayed_work(&priv->assoc_work); | |
1230 | destroy_workqueue(priv->work_thread); | |
876c9d3a | 1231 | |
954ee164 DW |
1232 | if (adapter->psmode == WLAN802_11POWERMODEMAX_PSP) { |
1233 | adapter->psmode = WLAN802_11POWERMODECAM; | |
1234 | libertas_ps_wakeup(priv, CMD_OPTION_WAITFORRSP); | |
876c9d3a MT |
1235 | } |
1236 | ||
954ee164 DW |
1237 | memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN); |
1238 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
1239 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); | |
1240 | ||
1241 | /* Stop the thread servicing the interrupts */ | |
1242 | adapter->surpriseremoved = 1; | |
1243 | kthread_stop(priv->main_thread); | |
1244 | ||
1245 | libertas_free_adapter(priv); | |
1246 | ||
1247 | priv->dev = NULL; | |
1248 | free_netdev(dev); | |
1249 | ||
1250 | lbs_deb_leave(LBS_DEB_MAIN); | |
1251 | return 0; | |
1252 | } | |
1253 | EXPORT_SYMBOL_GPL(libertas_remove_card); | |
1254 | ||
1255 | ||
1256 | int libertas_start_card(wlan_private *priv) | |
1257 | { | |
1258 | struct net_device *dev = priv->dev; | |
1259 | int ret = -1; | |
1260 | ||
1261 | lbs_deb_enter(LBS_DEB_MAIN); | |
1262 | ||
1263 | /* poke the firmware */ | |
1264 | ret = wlan_setup_firmware(priv); | |
1265 | if (ret) | |
1266 | goto done; | |
1267 | ||
1268 | /* init 802.11d */ | |
1269 | libertas_init_11d(priv); | |
876c9d3a MT |
1270 | |
1271 | if (register_netdev(dev)) { | |
9012b28a | 1272 | lbs_pr_err("cannot register ethX device\n"); |
954ee164 | 1273 | goto done; |
876c9d3a MT |
1274 | } |
1275 | ||
876c9d3a MT |
1276 | libertas_debugfs_init_one(priv, dev); |
1277 | ||
954ee164 DW |
1278 | lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name); |
1279 | ||
32a74b7c | 1280 | ret = 0; |
876c9d3a | 1281 | |
32a74b7c | 1282 | done: |
954ee164 DW |
1283 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); |
1284 | return ret; | |
1285 | } | |
1286 | EXPORT_SYMBOL_GPL(libertas_start_card); | |
1287 | ||
1288 | ||
1289 | int libertas_stop_card(wlan_private *priv) | |
1290 | { | |
1291 | struct net_device *dev = priv->dev; | |
1292 | int ret = -1; | |
1293 | struct cmd_ctrl_node *cmdnode; | |
1294 | unsigned long flags; | |
1295 | ||
1296 | lbs_deb_enter(LBS_DEB_MAIN); | |
1297 | ||
1298 | netif_stop_queue(priv->dev); | |
1299 | netif_carrier_off(priv->dev); | |
1300 | ||
1301 | libertas_debugfs_remove_one(priv); | |
1302 | ||
1303 | /* Flush pending command nodes */ | |
1304 | spin_lock_irqsave(&priv->adapter->driver_lock, flags); | |
1305 | list_for_each_entry(cmdnode, &priv->adapter->cmdpendingq, list) { | |
1306 | cmdnode->cmdwaitqwoken = 1; | |
1307 | wake_up_interruptible(&cmdnode->cmdwait_q); | |
1308 | } | |
1309 | spin_unlock_irqrestore(&priv->adapter->driver_lock, flags); | |
1310 | ||
1311 | unregister_netdev(dev); | |
1312 | ||
1313 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); | |
32a74b7c | 1314 | return ret; |
876c9d3a | 1315 | } |
954ee164 | 1316 | EXPORT_SYMBOL_GPL(libertas_stop_card); |
084708b6 | 1317 | |
876c9d3a | 1318 | |
78523daa HS |
1319 | /** |
1320 | * @brief This function adds mshX interface | |
1321 | * | |
1322 | * @param priv A pointer to the wlan_private structure | |
1323 | * @return 0 if successful, -X otherwise | |
1324 | */ | |
7732ca45 | 1325 | int libertas_add_mesh(wlan_private *priv, struct device *dev) |
78523daa HS |
1326 | { |
1327 | struct net_device *mesh_dev = NULL; | |
1328 | int ret = 0; | |
1329 | ||
1330 | lbs_deb_enter(LBS_DEB_MESH); | |
1331 | ||
1332 | /* Allocate a virtual mesh device */ | |
1333 | if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) { | |
1334 | lbs_deb_mesh("init mshX device failed\n"); | |
1335 | ret = -ENOMEM; | |
1336 | goto done; | |
1337 | } | |
1338 | mesh_dev->priv = priv; | |
1339 | priv->mesh_dev = mesh_dev; | |
1340 | ||
e5241472 DW |
1341 | mesh_dev->open = libertas_mesh_open; |
1342 | mesh_dev->hard_start_xmit = libertas_mesh_pre_start_xmit; | |
1343 | mesh_dev->stop = libertas_mesh_close; | |
1344 | mesh_dev->get_stats = libertas_get_stats; | |
1345 | mesh_dev->set_mac_address = libertas_set_mac_address; | |
78523daa | 1346 | mesh_dev->ethtool_ops = &libertas_ethtool_ops; |
634b8f49 HS |
1347 | memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, |
1348 | sizeof(priv->dev->dev_addr)); | |
78523daa | 1349 | |
7732ca45 DW |
1350 | SET_NETDEV_DEV(priv->mesh_dev, dev); |
1351 | ||
78523daa | 1352 | #ifdef WIRELESS_EXT |
f5e05b69 | 1353 | mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def; |
78523daa HS |
1354 | #endif |
1355 | #define NETIF_F_DYNALLOC 16 | |
1356 | ||
1357 | /* Register virtual mesh interface */ | |
1358 | ret = register_netdev(mesh_dev); | |
1359 | if (ret) { | |
1360 | lbs_pr_err("cannot register mshX virtual interface\n"); | |
1361 | goto err_free; | |
1362 | } | |
1363 | ||
a9f38d02 | 1364 | ret = sysfs_create_group(&(mesh_dev->dev.kobj), &libertas_mesh_attr_group); |
78523daa HS |
1365 | if (ret) |
1366 | goto err_unregister; | |
1367 | ||
1368 | /* Everything successful */ | |
1369 | ret = 0; | |
1370 | goto done; | |
1371 | ||
78523daa HS |
1372 | err_unregister: |
1373 | unregister_netdev(mesh_dev); | |
1374 | ||
1375 | err_free: | |
1376 | free_netdev(mesh_dev); | |
1377 | ||
1378 | done: | |
1379 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); | |
1380 | return ret; | |
1381 | } | |
084708b6 | 1382 | EXPORT_SYMBOL_GPL(libertas_add_mesh); |
78523daa | 1383 | |
084708b6 HS |
1384 | |
1385 | void libertas_remove_mesh(wlan_private *priv) | |
78523daa HS |
1386 | { |
1387 | struct net_device *mesh_dev; | |
1388 | ||
954ee164 | 1389 | lbs_deb_enter(LBS_DEB_MAIN); |
78523daa HS |
1390 | |
1391 | if (!priv) | |
1392 | goto out; | |
1393 | ||
1394 | mesh_dev = priv->mesh_dev; | |
1395 | ||
1396 | netif_stop_queue(mesh_dev); | |
51d84f50 | 1397 | netif_carrier_off(priv->mesh_dev); |
78523daa | 1398 | |
a9f38d02 | 1399 | sysfs_remove_group(&(mesh_dev->dev.kobj), &libertas_mesh_attr_group); |
78523daa HS |
1400 | unregister_netdev(mesh_dev); |
1401 | ||
1402 | priv->mesh_dev = NULL ; | |
1403 | free_netdev(mesh_dev); | |
1404 | ||
1405 | out: | |
954ee164 | 1406 | lbs_deb_leave(LBS_DEB_MAIN); |
78523daa | 1407 | } |
084708b6 | 1408 | EXPORT_SYMBOL_GPL(libertas_remove_mesh); |
78523daa | 1409 | |
876c9d3a MT |
1410 | /** |
1411 | * @brief This function finds the CFP in | |
1412 | * region_cfp_table based on region and band parameter. | |
1413 | * | |
1414 | * @param region The region code | |
1415 | * @param band The band | |
1416 | * @param cfp_no A pointer to CFP number | |
1417 | * @return A pointer to CFP | |
1418 | */ | |
1419 | struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band, int *cfp_no) | |
1420 | { | |
1421 | int i, end; | |
1422 | ||
9012b28a | 1423 | lbs_deb_enter(LBS_DEB_MAIN); |
876c9d3a | 1424 | |
ff8ac609 | 1425 | end = ARRAY_SIZE(region_cfp_table); |
876c9d3a MT |
1426 | |
1427 | for (i = 0; i < end ; i++) { | |
9012b28a | 1428 | lbs_deb_main("region_cfp_table[i].region=%d\n", |
876c9d3a MT |
1429 | region_cfp_table[i].region); |
1430 | if (region_cfp_table[i].region == region) { | |
1431 | *cfp_no = region_cfp_table[i].cfp_no_BG; | |
9012b28a | 1432 | lbs_deb_leave(LBS_DEB_MAIN); |
876c9d3a MT |
1433 | return region_cfp_table[i].cfp_BG; |
1434 | } | |
1435 | } | |
1436 | ||
9012b28a | 1437 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL"); |
876c9d3a MT |
1438 | return NULL; |
1439 | } | |
1440 | ||
1441 | int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band) | |
1442 | { | |
1443 | wlan_adapter *adapter = priv->adapter; | |
9012b28a | 1444 | int ret = 0; |
876c9d3a MT |
1445 | int i = 0; |
1446 | ||
1447 | struct chan_freq_power *cfp; | |
1448 | int cfp_no; | |
1449 | ||
9012b28a | 1450 | lbs_deb_enter(LBS_DEB_MAIN); |
876c9d3a MT |
1451 | |
1452 | memset(adapter->region_channel, 0, sizeof(adapter->region_channel)); | |
1453 | ||
1454 | { | |
1455 | cfp = libertas_get_region_cfp_table(region, band, &cfp_no); | |
1456 | if (cfp != NULL) { | |
1457 | adapter->region_channel[i].nrcfp = cfp_no; | |
1458 | adapter->region_channel[i].CFP = cfp; | |
1459 | } else { | |
9012b28a | 1460 | lbs_deb_main("wrong region code %#x in band B/G\n", |
876c9d3a | 1461 | region); |
9012b28a HS |
1462 | ret = -1; |
1463 | goto out; | |
876c9d3a MT |
1464 | } |
1465 | adapter->region_channel[i].valid = 1; | |
1466 | adapter->region_channel[i].region = region; | |
1467 | adapter->region_channel[i].band = band; | |
1468 | i++; | |
1469 | } | |
9012b28a HS |
1470 | out: |
1471 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); | |
1472 | return ret; | |
876c9d3a MT |
1473 | } |
1474 | ||
1475 | /** | |
1476 | * @brief This function handles the interrupt. it will change PS | |
1477 | * state if applicable. it will wake up main_thread to handle | |
1478 | * the interrupt event as well. | |
1479 | * | |
1480 | * @param dev A pointer to net_device structure | |
1481 | * @return n/a | |
1482 | */ | |
1483 | void libertas_interrupt(struct net_device *dev) | |
1484 | { | |
1485 | wlan_private *priv = dev->priv; | |
1486 | ||
ed37b516 | 1487 | lbs_deb_enter(LBS_DEB_THREAD); |
876c9d3a | 1488 | |
ed37b516 | 1489 | lbs_deb_thread("libertas_interrupt: intcounter=%d\n", |
876c9d3a MT |
1490 | priv->adapter->intcounter); |
1491 | ||
1492 | priv->adapter->intcounter++; | |
1493 | ||
1494 | if (priv->adapter->psstate == PS_STATE_SLEEP) { | |
1495 | priv->adapter->psstate = PS_STATE_AWAKE; | |
1496 | netif_wake_queue(dev); | |
3cf84091 HS |
1497 | if (priv->mesh_dev) |
1498 | netif_wake_queue(priv->mesh_dev); | |
876c9d3a MT |
1499 | } |
1500 | ||
fe336150 | 1501 | wake_up_interruptible(&priv->waitq); |
876c9d3a | 1502 | |
ed37b516 | 1503 | lbs_deb_leave(LBS_DEB_THREAD); |
876c9d3a | 1504 | } |
084708b6 | 1505 | EXPORT_SYMBOL_GPL(libertas_interrupt); |
876c9d3a | 1506 | |
eedc2a31 DW |
1507 | int libertas_reset_device(wlan_private *priv) |
1508 | { | |
1509 | int ret; | |
1510 | ||
1511 | lbs_deb_enter(LBS_DEB_MAIN); | |
1512 | ret = libertas_prepare_and_send_command(priv, CMD_802_11_RESET, | |
1513 | CMD_ACT_HALT, 0, 0, NULL); | |
1514 | msleep_interruptible(10); | |
1515 | ||
1516 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); | |
1517 | return ret; | |
1518 | } | |
1519 | EXPORT_SYMBOL_GPL(libertas_reset_device); | |
1520 | ||
084708b6 | 1521 | static int libertas_init_module(void) |
876c9d3a | 1522 | { |
9012b28a | 1523 | lbs_deb_enter(LBS_DEB_MAIN); |
876c9d3a | 1524 | libertas_debugfs_init(); |
084708b6 HS |
1525 | lbs_deb_leave(LBS_DEB_MAIN); |
1526 | return 0; | |
876c9d3a MT |
1527 | } |
1528 | ||
084708b6 | 1529 | static void libertas_exit_module(void) |
876c9d3a | 1530 | { |
9012b28a | 1531 | lbs_deb_enter(LBS_DEB_MAIN); |
876c9d3a | 1532 | |
876c9d3a MT |
1533 | libertas_debugfs_remove(); |
1534 | ||
9012b28a | 1535 | lbs_deb_leave(LBS_DEB_MAIN); |
876c9d3a MT |
1536 | } |
1537 | ||
965f8bbc LCC |
1538 | /* |
1539 | * rtap interface support fuctions | |
1540 | */ | |
1541 | ||
1542 | static int libertas_rtap_open(struct net_device *dev) | |
1543 | { | |
1544 | netif_carrier_off(dev); | |
1545 | netif_stop_queue(dev); | |
1546 | return 0; | |
1547 | } | |
1548 | ||
1549 | static int libertas_rtap_stop(struct net_device *dev) | |
1550 | { | |
1551 | return 0; | |
1552 | } | |
1553 | ||
1554 | static int libertas_rtap_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) | |
1555 | { | |
1556 | netif_stop_queue(dev); | |
1557 | return -EOPNOTSUPP; | |
1558 | } | |
1559 | ||
1560 | static struct net_device_stats *libertas_rtap_get_stats(struct net_device *dev) | |
1561 | { | |
1562 | wlan_private *priv = dev->priv; | |
1563 | return &priv->ieee->stats; | |
1564 | } | |
1565 | ||
1566 | ||
1567 | void libertas_remove_rtap(wlan_private *priv) | |
1568 | { | |
1569 | if (priv->rtap_net_dev == NULL) | |
1570 | return; | |
1571 | unregister_netdev(priv->rtap_net_dev); | |
1572 | free_ieee80211(priv->rtap_net_dev); | |
1573 | priv->rtap_net_dev = NULL; | |
1574 | } | |
1575 | ||
1576 | int libertas_add_rtap(wlan_private *priv) | |
1577 | { | |
1578 | int rc = 0; | |
1579 | ||
1580 | if (priv->rtap_net_dev) | |
1581 | return -EPERM; | |
1582 | ||
1583 | priv->rtap_net_dev = alloc_ieee80211(0); | |
1584 | if (priv->rtap_net_dev == NULL) | |
1585 | return -ENOMEM; | |
1586 | ||
1587 | ||
1588 | priv->ieee = netdev_priv(priv->rtap_net_dev); | |
1589 | ||
1590 | strcpy(priv->rtap_net_dev->name, "rtap%d"); | |
1591 | ||
1592 | priv->rtap_net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | |
1593 | priv->rtap_net_dev->open = libertas_rtap_open; | |
1594 | priv->rtap_net_dev->stop = libertas_rtap_stop; | |
1595 | priv->rtap_net_dev->get_stats = libertas_rtap_get_stats; | |
1596 | priv->rtap_net_dev->hard_start_xmit = libertas_rtap_hard_start_xmit; | |
1597 | priv->rtap_net_dev->set_multicast_list = libertas_set_multicast_list; | |
1598 | priv->rtap_net_dev->priv = priv; | |
1599 | ||
1600 | priv->ieee->iw_mode = IW_MODE_MONITOR; | |
1601 | ||
1602 | rc = register_netdev(priv->rtap_net_dev); | |
1603 | if (rc) { | |
1604 | free_ieee80211(priv->rtap_net_dev); | |
1605 | priv->rtap_net_dev = NULL; | |
1606 | return rc; | |
1607 | } | |
1608 | ||
1609 | return 0; | |
1610 | } | |
1611 | ||
1612 | ||
084708b6 HS |
1613 | module_init(libertas_init_module); |
1614 | module_exit(libertas_exit_module); | |
876c9d3a | 1615 | |
084708b6 | 1616 | MODULE_DESCRIPTION("Libertas WLAN Driver Library"); |
876c9d3a MT |
1617 | MODULE_AUTHOR("Marvell International Ltd."); |
1618 | MODULE_LICENSE("GPL"); |