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" |
10078321 | 27 | const char lbs_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION |
3ce40232 DW |
28 | #ifdef DEBUG |
29 | "-dbg" | |
30 | #endif | |
31 | ""; | |
32 | ||
a46c6410 HS |
33 | |
34 | /* Module parameters */ | |
10078321 HS |
35 | unsigned int lbs_debug; |
36 | EXPORT_SYMBOL_GPL(lbs_debug); | |
37 | module_param_named(libertas_debug, lbs_debug, int, 0644); | |
a46c6410 HS |
38 | |
39 | ||
10078321 HS |
40 | #define LBS_TX_PWR_DEFAULT 20 /*100mW */ |
41 | #define LBS_TX_PWR_US_DEFAULT 20 /*100mW */ | |
42 | #define LBS_TX_PWR_JP_DEFAULT 16 /*50mW */ | |
43 | #define LBS_TX_PWR_FR_DEFAULT 20 /*100mW */ | |
44 | #define LBS_TX_PWR_EMEA_DEFAULT 20 /*100mW */ | |
876c9d3a MT |
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[] = { | |
10078321 HS |
49 | {1, 2412, LBS_TX_PWR_US_DEFAULT}, |
50 | {2, 2417, LBS_TX_PWR_US_DEFAULT}, | |
51 | {3, 2422, LBS_TX_PWR_US_DEFAULT}, | |
52 | {4, 2427, LBS_TX_PWR_US_DEFAULT}, | |
53 | {5, 2432, LBS_TX_PWR_US_DEFAULT}, | |
54 | {6, 2437, LBS_TX_PWR_US_DEFAULT}, | |
55 | {7, 2442, LBS_TX_PWR_US_DEFAULT}, | |
56 | {8, 2447, LBS_TX_PWR_US_DEFAULT}, | |
57 | {9, 2452, LBS_TX_PWR_US_DEFAULT}, | |
58 | {10, 2457, LBS_TX_PWR_US_DEFAULT}, | |
59 | {11, 2462, LBS_TX_PWR_US_DEFAULT} | |
876c9d3a MT |
60 | }; |
61 | ||
62 | /* band: 'B/G', region: Europe ETSI */ | |
63 | static struct chan_freq_power channel_freq_power_EU_BG[] = { | |
10078321 HS |
64 | {1, 2412, LBS_TX_PWR_EMEA_DEFAULT}, |
65 | {2, 2417, LBS_TX_PWR_EMEA_DEFAULT}, | |
66 | {3, 2422, LBS_TX_PWR_EMEA_DEFAULT}, | |
67 | {4, 2427, LBS_TX_PWR_EMEA_DEFAULT}, | |
68 | {5, 2432, LBS_TX_PWR_EMEA_DEFAULT}, | |
69 | {6, 2437, LBS_TX_PWR_EMEA_DEFAULT}, | |
70 | {7, 2442, LBS_TX_PWR_EMEA_DEFAULT}, | |
71 | {8, 2447, LBS_TX_PWR_EMEA_DEFAULT}, | |
72 | {9, 2452, LBS_TX_PWR_EMEA_DEFAULT}, | |
73 | {10, 2457, LBS_TX_PWR_EMEA_DEFAULT}, | |
74 | {11, 2462, LBS_TX_PWR_EMEA_DEFAULT}, | |
75 | {12, 2467, LBS_TX_PWR_EMEA_DEFAULT}, | |
76 | {13, 2472, LBS_TX_PWR_EMEA_DEFAULT} | |
876c9d3a MT |
77 | }; |
78 | ||
79 | /* band: 'B/G', region: Spain */ | |
80 | static struct chan_freq_power channel_freq_power_SPN_BG[] = { | |
10078321 HS |
81 | {10, 2457, LBS_TX_PWR_DEFAULT}, |
82 | {11, 2462, LBS_TX_PWR_DEFAULT} | |
876c9d3a MT |
83 | }; |
84 | ||
85 | /* band: 'B/G', region: France */ | |
86 | static struct chan_freq_power channel_freq_power_FR_BG[] = { | |
10078321 HS |
87 | {10, 2457, LBS_TX_PWR_FR_DEFAULT}, |
88 | {11, 2462, LBS_TX_PWR_FR_DEFAULT}, | |
89 | {12, 2467, LBS_TX_PWR_FR_DEFAULT}, | |
90 | {13, 2472, LBS_TX_PWR_FR_DEFAULT} | |
876c9d3a MT |
91 | }; |
92 | ||
93 | /* band: 'B/G', region: Japan */ | |
94 | static struct chan_freq_power channel_freq_power_JPN_BG[] = { | |
10078321 HS |
95 | {1, 2412, LBS_TX_PWR_JP_DEFAULT}, |
96 | {2, 2417, LBS_TX_PWR_JP_DEFAULT}, | |
97 | {3, 2422, LBS_TX_PWR_JP_DEFAULT}, | |
98 | {4, 2427, LBS_TX_PWR_JP_DEFAULT}, | |
99 | {5, 2432, LBS_TX_PWR_JP_DEFAULT}, | |
100 | {6, 2437, LBS_TX_PWR_JP_DEFAULT}, | |
101 | {7, 2442, LBS_TX_PWR_JP_DEFAULT}, | |
102 | {8, 2447, LBS_TX_PWR_JP_DEFAULT}, | |
103 | {9, 2452, LBS_TX_PWR_JP_DEFAULT}, | |
104 | {10, 2457, LBS_TX_PWR_JP_DEFAULT}, | |
105 | {11, 2462, LBS_TX_PWR_JP_DEFAULT}, | |
106 | {12, 2467, LBS_TX_PWR_JP_DEFAULT}, | |
107 | {13, 2472, LBS_TX_PWR_JP_DEFAULT}, | |
108 | {14, 2484, LBS_TX_PWR_JP_DEFAULT} | |
876c9d3a MT |
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 | */ |
10078321 | 156 | u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] = |
8c512765 | 157 | { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 }; |
876c9d3a MT |
158 | |
159 | /** | |
8c512765 | 160 | * 802.11b/g supported bitrates (in 500Kb/s units) |
876c9d3a | 161 | */ |
10078321 | 162 | u8 lbs_bg_rates[MAX_RATES] = |
8c512765 DW |
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 | */ |
10078321 | 182 | u32 lbs_fw_index_to_data_rate(u8 idx) |
8c512765 DW |
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 | */ | |
10078321 | 195 | u8 lbs_data_rate_to_fw_index(u32 rate) |
8c512765 DW |
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 | */ |
10078321 | 216 | static ssize_t lbs_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)); | |
10078321 | 222 | lbs_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 | */ |
10078321 | 233 | static ssize_t lbs_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 | ||
10078321 | 243 | lbs_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 | ||
69f9032d HS |
250 | int lbs_add_rtap(struct lbs_private *priv); |
251 | void lbs_remove_rtap(struct lbs_private *priv); | |
965f8bbc LCC |
252 | |
253 | /** | |
254 | * Get function for sysfs attribute rtap | |
255 | */ | |
10078321 | 256 | static ssize_t lbs_rtap_get(struct device *dev, |
965f8bbc LCC |
257 | struct device_attribute *attr, char * buf) |
258 | { | |
e7deced0 | 259 | struct lbs_private *priv = to_net_dev(dev)->priv; |
aa21c004 | 260 | return snprintf(buf, 5, "0x%X\n", priv->monitormode); |
965f8bbc LCC |
261 | } |
262 | ||
263 | /** | |
264 | * Set function for sysfs attribute rtap | |
265 | */ | |
10078321 | 266 | static ssize_t lbs_rtap_set(struct device *dev, |
965f8bbc LCC |
267 | struct device_attribute *attr, const char * buf, size_t count) |
268 | { | |
269 | int monitor_mode; | |
e7deced0 | 270 | struct lbs_private *priv = to_net_dev(dev)->priv; |
965f8bbc LCC |
271 | |
272 | sscanf(buf, "%x", &monitor_mode); | |
10078321 | 273 | if (monitor_mode != LBS_MONITOR_OFF) { |
aa21c004 | 274 | if(priv->monitormode == monitor_mode) |
965f8bbc | 275 | return strlen(buf); |
aa21c004 DW |
276 | if (priv->monitormode == LBS_MONITOR_OFF) { |
277 | if (priv->mode == IW_MODE_INFRA) | |
10078321 | 278 | lbs_send_deauthentication(priv); |
aa21c004 | 279 | else if (priv->mode == IW_MODE_ADHOC) |
10078321 HS |
280 | lbs_stop_adhoc_network(priv); |
281 | lbs_add_rtap(priv); | |
965f8bbc | 282 | } |
aa21c004 | 283 | priv->monitormode = monitor_mode; |
965f8bbc LCC |
284 | } |
285 | ||
286 | else { | |
aa21c004 | 287 | if (priv->monitormode == LBS_MONITOR_OFF) |
965f8bbc | 288 | return strlen(buf); |
aa21c004 | 289 | priv->monitormode = LBS_MONITOR_OFF; |
10078321 | 290 | lbs_remove_rtap(priv); |
f86a93e1 | 291 | |
aa21c004 DW |
292 | if (priv->currenttxskb) { |
293 | dev_kfree_skb_any(priv->currenttxskb); | |
294 | priv->currenttxskb = NULL; | |
f86a93e1 DW |
295 | } |
296 | ||
297 | /* Wake queues, command thread, etc. */ | |
298 | lbs_host_to_card_done(priv); | |
965f8bbc LCC |
299 | } |
300 | ||
10078321 | 301 | lbs_prepare_and_send_command(priv, |
965f8bbc | 302 | CMD_802_11_MONITOR_MODE, CMD_ACT_SET, |
aa21c004 | 303 | CMD_OPTION_WAITFORRSP, 0, &priv->monitormode); |
965f8bbc LCC |
304 | return strlen(buf); |
305 | } | |
306 | ||
307 | /** | |
10078321 | 308 | * lbs_rtap attribute to be exported per mshX interface |
965f8bbc LCC |
309 | * through sysfs (/sys/class/net/mshX/libertas-rtap) |
310 | */ | |
10078321 HS |
311 | static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get, |
312 | lbs_rtap_set ); | |
965f8bbc | 313 | |
876c9d3a | 314 | /** |
82fde74b LC |
315 | * anycast_mask attribute to be exported per mshX interface |
316 | * through sysfs (/sys/class/net/mshX/anycast_mask) | |
876c9d3a | 317 | */ |
10078321 | 318 | static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set); |
876c9d3a | 319 | |
10078321 | 320 | static ssize_t lbs_autostart_enabled_get(struct device *dev, |
a9f38d02 LCC |
321 | struct device_attribute *attr, char * buf) |
322 | { | |
323 | struct cmd_ds_mesh_access mesh_access; | |
324 | ||
325 | memset(&mesh_access, 0, sizeof(mesh_access)); | |
10078321 | 326 | lbs_prepare_and_send_command(to_net_dev(dev)->priv, |
a9f38d02 LCC |
327 | CMD_MESH_ACCESS, |
328 | CMD_ACT_MESH_GET_AUTOSTART_ENABLED, | |
329 | CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access); | |
330 | ||
331 | return sprintf(buf, "%d\n", le32_to_cpu(mesh_access.data[0])); | |
332 | } | |
333 | ||
10078321 | 334 | static ssize_t lbs_autostart_enabled_set(struct device *dev, |
a9f38d02 LCC |
335 | struct device_attribute *attr, const char * buf, size_t count) |
336 | { | |
337 | struct cmd_ds_mesh_access mesh_access; | |
338 | uint32_t datum; | |
69f9032d | 339 | struct lbs_private *priv = (to_net_dev(dev))->priv; |
d21b31fd | 340 | int ret; |
a9f38d02 LCC |
341 | |
342 | memset(&mesh_access, 0, sizeof(mesh_access)); | |
343 | sscanf(buf, "%d", &datum); | |
344 | mesh_access.data[0] = cpu_to_le32(datum); | |
345 | ||
10078321 | 346 | ret = lbs_prepare_and_send_command(priv, |
a9f38d02 LCC |
347 | CMD_MESH_ACCESS, |
348 | CMD_ACT_MESH_SET_AUTOSTART_ENABLED, | |
349 | CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access); | |
d21b31fd LCC |
350 | if (ret == 0) |
351 | priv->mesh_autostart_enabled = datum ? 1 : 0; | |
352 | ||
a9f38d02 LCC |
353 | return strlen(buf); |
354 | } | |
355 | ||
356 | static DEVICE_ATTR(autostart_enabled, 0644, | |
10078321 | 357 | lbs_autostart_enabled_get, lbs_autostart_enabled_set); |
a9f38d02 | 358 | |
10078321 | 359 | static struct attribute *lbs_mesh_sysfs_entries[] = { |
a9f38d02 LCC |
360 | &dev_attr_anycast_mask.attr, |
361 | &dev_attr_autostart_enabled.attr, | |
362 | NULL, | |
363 | }; | |
364 | ||
10078321 HS |
365 | static struct attribute_group lbs_mesh_attr_group = { |
366 | .attrs = lbs_mesh_sysfs_entries, | |
a9f38d02 LCC |
367 | }; |
368 | ||
876c9d3a MT |
369 | /** |
370 | * @brief Check if the device can be open and wait if necessary. | |
371 | * | |
372 | * @param dev A pointer to net_device structure | |
373 | * @return 0 | |
374 | * | |
375 | * For USB adapter, on some systems the device open handler will be | |
376 | * called before FW ready. Use the following flag check and wait | |
377 | * function to work around the issue. | |
378 | * | |
379 | */ | |
9012b28a HS |
380 | static int pre_open_check(struct net_device *dev) |
381 | { | |
69f9032d | 382 | struct lbs_private *priv = (struct lbs_private *) dev->priv; |
876c9d3a MT |
383 | int i = 0; |
384 | ||
aa21c004 | 385 | while (!priv->fw_ready && i < 20) { |
876c9d3a MT |
386 | i++; |
387 | msleep_interruptible(100); | |
388 | } | |
aa21c004 | 389 | if (!priv->fw_ready) { |
9012b28a | 390 | lbs_pr_err("firmware not ready\n"); |
876c9d3a MT |
391 | return -1; |
392 | } | |
393 | ||
394 | return 0; | |
395 | } | |
396 | ||
397 | /** | |
398 | * @brief This function opens the device | |
399 | * | |
400 | * @param dev A pointer to net_device structure | |
401 | * @return 0 | |
402 | */ | |
10078321 | 403 | static int lbs_dev_open(struct net_device *dev) |
876c9d3a | 404 | { |
69f9032d | 405 | struct lbs_private *priv = (struct lbs_private *) dev->priv; |
876c9d3a | 406 | |
9012b28a | 407 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a MT |
408 | |
409 | priv->open = 1; | |
410 | ||
aa21c004 | 411 | if (priv->connect_status == LBS_CONNECTED) |
634b8f49 | 412 | netif_carrier_on(priv->dev); |
01d77d8d | 413 | else |
634b8f49 | 414 | netif_carrier_off(priv->dev); |
01d77d8d BD |
415 | |
416 | if (priv->mesh_dev) { | |
aa21c004 | 417 | if (priv->mesh_connect_status == LBS_CONNECTED) |
01d77d8d BD |
418 | netif_carrier_on(priv->mesh_dev); |
419 | else | |
3cf84091 | 420 | netif_carrier_off(priv->mesh_dev); |
51d84f50 | 421 | } |
876c9d3a | 422 | |
9012b28a | 423 | lbs_deb_leave(LBS_DEB_NET); |
876c9d3a MT |
424 | return 0; |
425 | } | |
426 | /** | |
427 | * @brief This function opens the mshX interface | |
428 | * | |
429 | * @param dev A pointer to net_device structure | |
430 | * @return 0 | |
431 | */ | |
10078321 | 432 | static int lbs_mesh_open(struct net_device *dev) |
876c9d3a | 433 | { |
69f9032d | 434 | struct lbs_private *priv = (struct lbs_private *) dev->priv ; |
876c9d3a | 435 | |
78523daa | 436 | if (pre_open_check(dev) == -1) |
876c9d3a MT |
437 | return -1; |
438 | priv->mesh_open = 1 ; | |
51d84f50 | 439 | netif_wake_queue(priv->mesh_dev); |
01d77d8d | 440 | |
aa21c004 | 441 | priv->mesh_connect_status = LBS_CONNECTED; |
01d77d8d BD |
442 | |
443 | netif_carrier_on(priv->mesh_dev); | |
444 | netif_wake_queue(priv->mesh_dev); | |
876c9d3a | 445 | if (priv->infra_open == 0) |
10078321 | 446 | return lbs_dev_open(priv->dev) ; |
876c9d3a MT |
447 | return 0; |
448 | } | |
449 | ||
450 | /** | |
451 | * @brief This function opens the ethX interface | |
452 | * | |
453 | * @param dev A pointer to net_device structure | |
454 | * @return 0 | |
455 | */ | |
10078321 | 456 | static int lbs_open(struct net_device *dev) |
876c9d3a | 457 | { |
69f9032d | 458 | struct lbs_private *priv = (struct lbs_private *) dev->priv ; |
876c9d3a MT |
459 | |
460 | if(pre_open_check(dev) == -1) | |
461 | return -1; | |
462 | priv->infra_open = 1 ; | |
634b8f49 | 463 | netif_wake_queue(priv->dev); |
876c9d3a | 464 | if (priv->open == 0) |
10078321 | 465 | return lbs_dev_open(priv->dev) ; |
876c9d3a MT |
466 | return 0; |
467 | } | |
468 | ||
10078321 | 469 | static int lbs_dev_close(struct net_device *dev) |
876c9d3a | 470 | { |
69f9032d | 471 | struct lbs_private *priv = dev->priv; |
876c9d3a | 472 | |
9012b28a | 473 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a | 474 | |
634b8f49 | 475 | netif_carrier_off(priv->dev); |
876c9d3a MT |
476 | priv->open = 0; |
477 | ||
9012b28a | 478 | lbs_deb_leave(LBS_DEB_NET); |
876c9d3a MT |
479 | return 0; |
480 | } | |
481 | ||
482 | /** | |
483 | * @brief This function closes the mshX interface | |
484 | * | |
485 | * @param dev A pointer to net_device structure | |
486 | * @return 0 | |
487 | */ | |
10078321 | 488 | static int lbs_mesh_close(struct net_device *dev) |
876c9d3a | 489 | { |
69f9032d | 490 | struct lbs_private *priv = (struct lbs_private *) (dev->priv); |
876c9d3a MT |
491 | |
492 | priv->mesh_open = 0; | |
493 | netif_stop_queue(priv->mesh_dev); | |
494 | if (priv->infra_open == 0) | |
10078321 | 495 | return lbs_dev_close(dev); |
876c9d3a MT |
496 | else |
497 | return 0; | |
498 | } | |
499 | ||
500 | /** | |
501 | * @brief This function closes the ethX interface | |
502 | * | |
503 | * @param dev A pointer to net_device structure | |
504 | * @return 0 | |
505 | */ | |
10078321 | 506 | static int lbs_close(struct net_device *dev) |
78523daa | 507 | { |
69f9032d | 508 | struct lbs_private *priv = (struct lbs_private *) dev->priv; |
876c9d3a | 509 | |
634b8f49 | 510 | netif_stop_queue(dev); |
876c9d3a MT |
511 | priv->infra_open = 0; |
512 | if (priv->mesh_open == 0) | |
10078321 | 513 | return lbs_dev_close(dev); |
876c9d3a MT |
514 | else |
515 | return 0; | |
516 | } | |
517 | ||
10078321 | 518 | static void lbs_tx_timeout(struct net_device *dev) |
876c9d3a | 519 | { |
69f9032d | 520 | struct lbs_private *priv = (struct lbs_private *) dev->priv; |
876c9d3a | 521 | |
9012b28a | 522 | lbs_deb_enter(LBS_DEB_TX); |
876c9d3a | 523 | |
9012b28a | 524 | lbs_pr_err("tx watch dog timeout\n"); |
876c9d3a | 525 | |
876c9d3a MT |
526 | dev->trans_start = jiffies; |
527 | ||
aa21c004 | 528 | if (priv->currenttxskb) { |
a63b22bb DW |
529 | priv->eventcause = 0x01000000; |
530 | lbs_send_tx_feedback(priv); | |
51d84f50 | 531 | } |
a63b22bb DW |
532 | /* XX: Shouldn't we also call into the hw-specific driver |
533 | to kick it somehow? */ | |
534 | lbs_host_to_card_done(priv); | |
876c9d3a | 535 | |
9012b28a | 536 | lbs_deb_leave(LBS_DEB_TX); |
876c9d3a MT |
537 | } |
538 | ||
e775ed7c DW |
539 | void lbs_host_to_card_done(struct lbs_private *priv) |
540 | { | |
a63b22bb DW |
541 | unsigned long flags; |
542 | ||
543 | spin_lock_irqsave(&priv->driver_lock, flags); | |
e775ed7c DW |
544 | |
545 | priv->dnld_sent = DNLD_RES_RECEIVED; | |
546 | ||
547 | /* Wake main thread if commands are pending */ | |
aa21c004 | 548 | if (!priv->cur_cmd) |
e775ed7c DW |
549 | wake_up_interruptible(&priv->waitq); |
550 | ||
f86a93e1 | 551 | /* Don't wake netif queues if we're in monitor mode and |
a63b22bb DW |
552 | a TX packet is already pending, or if there are commands |
553 | queued to be sent. */ | |
554 | if (!priv->currenttxskb && list_empty(&priv->cmdpendingq)) { | |
555 | if (priv->dev && priv->connect_status == LBS_CONNECTED) | |
556 | netif_wake_queue(priv->dev); | |
e775ed7c | 557 | |
a63b22bb DW |
558 | if (priv->mesh_dev && priv->mesh_connect_status == LBS_CONNECTED) |
559 | netif_wake_queue(priv->mesh_dev); | |
560 | } | |
561 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
e775ed7c DW |
562 | } |
563 | EXPORT_SYMBOL_GPL(lbs_host_to_card_done); | |
564 | ||
876c9d3a MT |
565 | /** |
566 | * @brief This function returns the network statistics | |
567 | * | |
69f9032d | 568 | * @param dev A pointer to struct lbs_private structure |
876c9d3a MT |
569 | * @return A pointer to net_device_stats structure |
570 | */ | |
10078321 | 571 | static struct net_device_stats *lbs_get_stats(struct net_device *dev) |
876c9d3a | 572 | { |
69f9032d | 573 | struct lbs_private *priv = (struct lbs_private *) dev->priv; |
876c9d3a MT |
574 | |
575 | return &priv->stats; | |
576 | } | |
577 | ||
10078321 | 578 | static int lbs_set_mac_address(struct net_device *dev, void *addr) |
876c9d3a MT |
579 | { |
580 | int ret = 0; | |
69f9032d | 581 | struct lbs_private *priv = (struct lbs_private *) dev->priv; |
876c9d3a MT |
582 | struct sockaddr *phwaddr = addr; |
583 | ||
9012b28a | 584 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a | 585 | |
0a0d08ac LCCR |
586 | /* In case it was called from the mesh device */ |
587 | dev = priv->dev ; | |
588 | ||
aa21c004 | 589 | memset(priv->current_addr, 0, ETH_ALEN); |
876c9d3a MT |
590 | |
591 | /* dev->dev_addr is 8 bytes */ | |
ece56191 | 592 | lbs_deb_hex(LBS_DEB_NET, "dev->dev_addr", dev->dev_addr, ETH_ALEN); |
876c9d3a | 593 | |
ece56191 | 594 | lbs_deb_hex(LBS_DEB_NET, "addr", phwaddr->sa_data, ETH_ALEN); |
aa21c004 | 595 | memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN); |
876c9d3a | 596 | |
10078321 | 597 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_MAC_ADDRESS, |
0aef64d7 DW |
598 | CMD_ACT_SET, |
599 | CMD_OPTION_WAITFORRSP, 0, NULL); | |
876c9d3a MT |
600 | |
601 | if (ret) { | |
9012b28a | 602 | lbs_deb_net("set MAC address failed\n"); |
876c9d3a MT |
603 | ret = -1; |
604 | goto done; | |
605 | } | |
606 | ||
aa21c004 DW |
607 | lbs_deb_hex(LBS_DEB_NET, "priv->macaddr", priv->current_addr, ETH_ALEN); |
608 | memcpy(dev->dev_addr, priv->current_addr, ETH_ALEN); | |
78523daa | 609 | if (priv->mesh_dev) |
aa21c004 | 610 | memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN); |
876c9d3a MT |
611 | |
612 | done: | |
9012b28a | 613 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
876c9d3a MT |
614 | return ret; |
615 | } | |
616 | ||
aa21c004 | 617 | static int lbs_copy_multicast_address(struct lbs_private *priv, |
876c9d3a MT |
618 | struct net_device *dev) |
619 | { | |
620 | int i = 0; | |
621 | struct dev_mc_list *mcptr = dev->mc_list; | |
622 | ||
623 | for (i = 0; i < dev->mc_count; i++) { | |
aa21c004 | 624 | memcpy(&priv->multicastlist[i], mcptr->dmi_addr, ETH_ALEN); |
876c9d3a MT |
625 | mcptr = mcptr->next; |
626 | } | |
627 | ||
628 | return i; | |
629 | ||
630 | } | |
631 | ||
10078321 | 632 | static void lbs_set_multicast_list(struct net_device *dev) |
876c9d3a | 633 | { |
69f9032d | 634 | struct lbs_private *priv = dev->priv; |
876c9d3a | 635 | int oldpacketfilter; |
0795af57 | 636 | DECLARE_MAC_BUF(mac); |
876c9d3a | 637 | |
9012b28a | 638 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a | 639 | |
aa21c004 | 640 | oldpacketfilter = priv->currentpacketfilter; |
876c9d3a MT |
641 | |
642 | if (dev->flags & IFF_PROMISC) { | |
9012b28a | 643 | lbs_deb_net("enable promiscuous mode\n"); |
aa21c004 | 644 | priv->currentpacketfilter |= |
0aef64d7 | 645 | CMD_ACT_MAC_PROMISCUOUS_ENABLE; |
aa21c004 | 646 | priv->currentpacketfilter &= |
0aef64d7 DW |
647 | ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE | |
648 | CMD_ACT_MAC_MULTICAST_ENABLE); | |
876c9d3a MT |
649 | } else { |
650 | /* Multicast */ | |
aa21c004 | 651 | priv->currentpacketfilter &= |
0aef64d7 | 652 | ~CMD_ACT_MAC_PROMISCUOUS_ENABLE; |
876c9d3a MT |
653 | |
654 | if (dev->flags & IFF_ALLMULTI || dev->mc_count > | |
655 | MRVDRV_MAX_MULTICAST_LIST_SIZE) { | |
9012b28a | 656 | lbs_deb_net( "enabling all multicast\n"); |
aa21c004 | 657 | priv->currentpacketfilter |= |
0aef64d7 | 658 | CMD_ACT_MAC_ALL_MULTICAST_ENABLE; |
aa21c004 | 659 | priv->currentpacketfilter &= |
0aef64d7 | 660 | ~CMD_ACT_MAC_MULTICAST_ENABLE; |
876c9d3a | 661 | } else { |
aa21c004 | 662 | priv->currentpacketfilter &= |
0aef64d7 | 663 | ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE; |
876c9d3a MT |
664 | |
665 | if (!dev->mc_count) { | |
9012b28a HS |
666 | lbs_deb_net("no multicast addresses, " |
667 | "disabling multicast\n"); | |
aa21c004 | 668 | priv->currentpacketfilter &= |
0aef64d7 | 669 | ~CMD_ACT_MAC_MULTICAST_ENABLE; |
876c9d3a MT |
670 | } else { |
671 | int i; | |
672 | ||
aa21c004 | 673 | priv->currentpacketfilter |= |
0aef64d7 | 674 | CMD_ACT_MAC_MULTICAST_ENABLE; |
876c9d3a | 675 | |
aa21c004 DW |
676 | priv->nr_of_multicastmacaddr = |
677 | lbs_copy_multicast_address(priv, dev); | |
876c9d3a | 678 | |
9012b28a | 679 | lbs_deb_net("multicast addresses: %d\n", |
876c9d3a MT |
680 | dev->mc_count); |
681 | ||
682 | for (i = 0; i < dev->mc_count; i++) { | |
0795af57 JP |
683 | lbs_deb_net("Multicast address %d:%s\n", |
684 | i, print_mac(mac, | |
aa21c004 | 685 | priv->multicastlist[i])); |
876c9d3a | 686 | } |
9012b28a | 687 | /* send multicast addresses to firmware */ |
10078321 | 688 | lbs_prepare_and_send_command(priv, |
0aef64d7 DW |
689 | CMD_MAC_MULTICAST_ADR, |
690 | CMD_ACT_SET, 0, 0, | |
876c9d3a MT |
691 | NULL); |
692 | } | |
693 | } | |
694 | } | |
695 | ||
aa21c004 | 696 | if (priv->currentpacketfilter != oldpacketfilter) { |
10078321 | 697 | lbs_set_mac_packet_filter(priv); |
876c9d3a MT |
698 | } |
699 | ||
9012b28a | 700 | lbs_deb_leave(LBS_DEB_NET); |
876c9d3a MT |
701 | } |
702 | ||
703 | /** | |
10078321 | 704 | * @brief This function handles the major jobs in the LBS driver. |
9012b28a HS |
705 | * It handles all events generated by firmware, RX data received |
706 | * from firmware and TX data sent from kernel. | |
876c9d3a | 707 | * |
10078321 | 708 | * @param data A pointer to lbs_thread structure |
876c9d3a MT |
709 | * @return 0 |
710 | */ | |
10078321 | 711 | static int lbs_thread(void *data) |
876c9d3a | 712 | { |
fe336150 | 713 | struct net_device *dev = data; |
69f9032d | 714 | struct lbs_private *priv = dev->priv; |
876c9d3a MT |
715 | wait_queue_t wait; |
716 | u8 ireg = 0; | |
717 | ||
9012b28a | 718 | lbs_deb_enter(LBS_DEB_THREAD); |
876c9d3a | 719 | |
876c9d3a MT |
720 | init_waitqueue_entry(&wait, current); |
721 | ||
b1b1907d | 722 | set_freezable(); |
59f3e4bf | 723 | |
876c9d3a | 724 | for (;;) { |
b8d40bc9 DW |
725 | int shouldsleep; |
726 | ||
59f3e4bf | 727 | lbs_deb_thread( "main-thread 111: intcounter=%d currenttxskb=%p dnld_sent=%d\n", |
aa21c004 | 728 | priv->intcounter, priv->currenttxskb, priv->dnld_sent); |
876c9d3a | 729 | |
fe336150 | 730 | add_wait_queue(&priv->waitq, &wait); |
876c9d3a | 731 | set_current_state(TASK_INTERRUPTIBLE); |
aa21c004 | 732 | spin_lock_irq(&priv->driver_lock); |
59f3e4bf | 733 | |
b8d40bc9 DW |
734 | if (priv->surpriseremoved) |
735 | shouldsleep = 0; /* Bye */ | |
736 | else if (priv->psstate == PS_STATE_SLEEP) | |
737 | shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */ | |
738 | else if (priv->intcounter) | |
739 | shouldsleep = 0; /* Interrupt pending. Deal with it now */ | |
740 | else if (priv->dnld_sent) | |
741 | shouldsleep = 1; /* Something is en route to the device already */ | |
742 | else if (priv->cur_cmd) | |
743 | shouldsleep = 1; /* Can't send a command; one already running */ | |
744 | else if (!list_empty(&priv->cmdpendingq)) | |
745 | shouldsleep = 0; /* We have a command to send */ | |
746 | else | |
747 | shouldsleep = 1; /* No command */ | |
748 | ||
749 | if (shouldsleep) { | |
59f3e4bf | 750 | lbs_deb_thread("main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n", |
aa21c004 DW |
751 | priv->connect_status, priv->intcounter, |
752 | priv->psmode, priv->psstate); | |
753 | spin_unlock_irq(&priv->driver_lock); | |
876c9d3a MT |
754 | schedule(); |
755 | } else | |
aa21c004 | 756 | spin_unlock_irq(&priv->driver_lock); |
876c9d3a | 757 | |
59f3e4bf | 758 | lbs_deb_thread("main-thread 222 (waking up): intcounter=%d currenttxskb=%p dnld_sent=%d\n", |
aa21c004 | 759 | priv->intcounter, priv->currenttxskb, priv->dnld_sent); |
876c9d3a MT |
760 | |
761 | set_current_state(TASK_RUNNING); | |
fe336150 | 762 | remove_wait_queue(&priv->waitq, &wait); |
876c9d3a MT |
763 | try_to_freeze(); |
764 | ||
59f3e4bf | 765 | lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p dnld_sent=%d\n", |
aa21c004 | 766 | priv->intcounter, priv->currenttxskb, priv->dnld_sent); |
876c9d3a | 767 | |
aa21c004 | 768 | if (kthread_should_stop() || priv->surpriseremoved) { |
59f3e4bf | 769 | lbs_deb_thread("main-thread: break from main thread: surpriseremoved=0x%x\n", |
aa21c004 | 770 | priv->surpriseremoved); |
876c9d3a MT |
771 | break; |
772 | } | |
773 | ||
774 | ||
aa21c004 | 775 | spin_lock_irq(&priv->driver_lock); |
59f3e4bf | 776 | |
aa21c004 | 777 | if (priv->intcounter) { |
876c9d3a | 778 | u8 int_status; |
59f3e4bf | 779 | |
aa21c004 | 780 | priv->intcounter = 0; |
208fdd2f | 781 | int_status = priv->hw_get_int_status(priv, &ireg); |
876c9d3a MT |
782 | |
783 | if (int_status) { | |
59f3e4bf | 784 | lbs_deb_thread("main-thread: reading HOST_INT_STATUS_REG failed\n"); |
aa21c004 | 785 | spin_unlock_irq(&priv->driver_lock); |
876c9d3a MT |
786 | continue; |
787 | } | |
aa21c004 | 788 | priv->hisregcpy |= ireg; |
876c9d3a MT |
789 | } |
790 | ||
59f3e4bf | 791 | lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p dnld_sent=%d\n", |
aa21c004 | 792 | priv->intcounter, priv->currenttxskb, priv->dnld_sent); |
876c9d3a MT |
793 | |
794 | /* command response? */ | |
aa21c004 | 795 | if (priv->hisregcpy & MRVDRV_CMD_UPLD_RDY) { |
9012b28a | 796 | lbs_deb_thread("main-thread: cmd response ready\n"); |
876c9d3a | 797 | |
aa21c004 DW |
798 | priv->hisregcpy &= ~MRVDRV_CMD_UPLD_RDY; |
799 | spin_unlock_irq(&priv->driver_lock); | |
10078321 | 800 | lbs_process_rx_command(priv); |
aa21c004 | 801 | spin_lock_irq(&priv->driver_lock); |
876c9d3a MT |
802 | } |
803 | ||
804 | /* Any Card Event */ | |
aa21c004 | 805 | if (priv->hisregcpy & MRVDRV_CARDEVENT) { |
9012b28a | 806 | lbs_deb_thread("main-thread: Card Event Activity\n"); |
876c9d3a | 807 | |
aa21c004 | 808 | priv->hisregcpy &= ~MRVDRV_CARDEVENT; |
876c9d3a | 809 | |
208fdd2f | 810 | if (priv->hw_read_event_cause(priv)) { |
59f3e4bf | 811 | lbs_pr_alert("main-thread: hw_read_event_cause failed\n"); |
aa21c004 | 812 | spin_unlock_irq(&priv->driver_lock); |
876c9d3a MT |
813 | continue; |
814 | } | |
aa21c004 | 815 | spin_unlock_irq(&priv->driver_lock); |
10078321 | 816 | lbs_process_event(priv); |
876c9d3a | 817 | } else |
aa21c004 | 818 | spin_unlock_irq(&priv->driver_lock); |
876c9d3a MT |
819 | |
820 | /* Check if we need to confirm Sleep Request received previously */ | |
aa21c004 DW |
821 | if (priv->psstate == PS_STATE_PRE_SLEEP && |
822 | !priv->dnld_sent && !priv->cur_cmd) { | |
823 | if (priv->connect_status == LBS_CONNECTED) { | |
59f3e4bf | 824 | lbs_deb_thread("main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p dnld_sent=%d cur_cmd=%p, confirm now\n", |
aa21c004 | 825 | priv->intcounter, priv->currenttxskb, priv->dnld_sent, priv->cur_cmd); |
59f3e4bf | 826 | |
aa21c004 | 827 | lbs_ps_confirm_sleep(priv, (u16) priv->psmode); |
59f3e4bf DW |
828 | } else { |
829 | /* workaround for firmware sending | |
830 | * deauth/linkloss event immediately | |
831 | * after sleep request; remove this | |
832 | * after firmware fixes it | |
833 | */ | |
aa21c004 | 834 | priv->psstate = PS_STATE_AWAKE; |
59f3e4bf | 835 | lbs_pr_alert("main-thread: ignore PS_SleepConfirm in non-connected state\n"); |
876c9d3a MT |
836 | } |
837 | } | |
838 | ||
839 | /* The PS state is changed during processing of Sleep Request | |
840 | * event above | |
841 | */ | |
aa21c004 DW |
842 | if ((priv->psstate == PS_STATE_SLEEP) || |
843 | (priv->psstate == PS_STATE_PRE_SLEEP)) | |
876c9d3a MT |
844 | continue; |
845 | ||
846 | /* Execute the next command */ | |
aa21c004 | 847 | if (!priv->dnld_sent && !priv->cur_cmd) |
10078321 | 848 | lbs_execute_next_command(priv); |
876c9d3a MT |
849 | |
850 | /* Wake-up command waiters which can't sleep in | |
10078321 | 851 | * lbs_prepare_and_send_command |
876c9d3a | 852 | */ |
aa21c004 DW |
853 | if (!list_empty(&priv->cmdpendingq)) |
854 | wake_up_all(&priv->cmd_pending); | |
876c9d3a MT |
855 | } |
856 | ||
aa21c004 DW |
857 | del_timer(&priv->command_timer); |
858 | wake_up_all(&priv->cmd_pending); | |
876c9d3a | 859 | |
9012b28a | 860 | lbs_deb_leave(LBS_DEB_THREAD); |
876c9d3a MT |
861 | return 0; |
862 | } | |
863 | ||
1df4e8fe HS |
864 | /** |
865 | * @brief This function downloads firmware image, gets | |
866 | * HW spec from firmware and set basic parameters to | |
867 | * firmware. | |
868 | * | |
69f9032d | 869 | * @param priv A pointer to struct lbs_private structure |
1df4e8fe HS |
870 | * @return 0 or -1 |
871 | */ | |
69f9032d | 872 | static int lbs_setup_firmware(struct lbs_private *priv) |
1df4e8fe HS |
873 | { |
874 | int ret = -1; | |
d21b31fd | 875 | struct cmd_ds_mesh_access mesh_access; |
1df4e8fe HS |
876 | |
877 | lbs_deb_enter(LBS_DEB_FW); | |
878 | ||
1df4e8fe HS |
879 | /* |
880 | * Read MAC address from HW | |
881 | */ | |
aa21c004 | 882 | memset(priv->current_addr, 0xff, ETH_ALEN); |
1df4e8fe | 883 | |
10078321 | 884 | ret = lbs_prepare_and_send_command(priv, CMD_GET_HW_SPEC, |
1df4e8fe HS |
885 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); |
886 | ||
887 | if (ret) { | |
888 | ret = -1; | |
889 | goto done; | |
890 | } | |
891 | ||
10078321 | 892 | lbs_set_mac_packet_filter(priv); |
1df4e8fe HS |
893 | |
894 | /* Get the supported Data rates */ | |
10078321 | 895 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_DATA_RATE, |
1df4e8fe HS |
896 | CMD_ACT_GET_TX_RATE, |
897 | CMD_OPTION_WAITFORRSP, 0, NULL); | |
898 | ||
899 | if (ret) { | |
900 | ret = -1; | |
901 | goto done; | |
902 | } | |
903 | ||
d21b31fd LCC |
904 | /* Disable mesh autostart */ |
905 | if (priv->mesh_dev) { | |
906 | memset(&mesh_access, 0, sizeof(mesh_access)); | |
907 | mesh_access.data[0] = cpu_to_le32(0); | |
10078321 | 908 | ret = lbs_prepare_and_send_command(priv, |
d21b31fd LCC |
909 | CMD_MESH_ACCESS, |
910 | CMD_ACT_MESH_SET_AUTOSTART_ENABLED, | |
911 | CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access); | |
912 | if (ret) { | |
913 | ret = -1; | |
914 | goto done; | |
915 | } | |
916 | priv->mesh_autostart_enabled = 0; | |
917 | } | |
918 | ||
1df4e8fe HS |
919 | ret = 0; |
920 | done: | |
921 | lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret); | |
922 | return ret; | |
923 | } | |
924 | ||
1df4e8fe HS |
925 | /** |
926 | * This function handles the timeout of command sending. | |
927 | * It will re-send the same command again. | |
928 | */ | |
929 | static void command_timer_fn(unsigned long data) | |
930 | { | |
69f9032d | 931 | struct lbs_private *priv = (struct lbs_private *)data; |
1df4e8fe HS |
932 | struct cmd_ctrl_node *ptempnode; |
933 | struct cmd_ds_command *cmd; | |
934 | unsigned long flags; | |
935 | ||
aa21c004 | 936 | ptempnode = priv->cur_cmd; |
1df4e8fe HS |
937 | if (ptempnode == NULL) { |
938 | lbs_deb_fw("ptempnode empty\n"); | |
939 | return; | |
940 | } | |
941 | ||
942 | cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr; | |
943 | if (!cmd) { | |
944 | lbs_deb_fw("cmd is NULL\n"); | |
945 | return; | |
946 | } | |
947 | ||
948 | lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command); | |
949 | ||
aa21c004 | 950 | if (!priv->fw_ready) |
1df4e8fe HS |
951 | return; |
952 | ||
aa21c004 DW |
953 | spin_lock_irqsave(&priv->driver_lock, flags); |
954 | priv->cur_cmd = NULL; | |
955 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
1df4e8fe HS |
956 | |
957 | lbs_deb_fw("re-sending same command because of timeout\n"); | |
aa21c004 | 958 | lbs_queue_cmd(priv, ptempnode, 0); |
1df4e8fe HS |
959 | |
960 | wake_up_interruptible(&priv->waitq); | |
961 | ||
962 | return; | |
963 | } | |
964 | ||
69f9032d | 965 | static int lbs_init_adapter(struct lbs_private *priv) |
ac558ca2 | 966 | { |
1df4e8fe | 967 | size_t bufsize; |
954ee164 | 968 | int i, ret = 0; |
1df4e8fe HS |
969 | |
970 | /* Allocate buffer to store the BSSID list */ | |
971 | bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor); | |
aa21c004 DW |
972 | priv->networks = kzalloc(bufsize, GFP_KERNEL); |
973 | if (!priv->networks) { | |
1df4e8fe | 974 | lbs_pr_err("Out of memory allocating beacons\n"); |
954ee164 DW |
975 | ret = -1; |
976 | goto out; | |
1df4e8fe HS |
977 | } |
978 | ||
954ee164 | 979 | /* Initialize scan result lists */ |
aa21c004 DW |
980 | INIT_LIST_HEAD(&priv->network_free_list); |
981 | INIT_LIST_HEAD(&priv->network_list); | |
954ee164 | 982 | for (i = 0; i < MAX_NETWORK_COUNT; i++) { |
aa21c004 DW |
983 | list_add_tail(&priv->networks[i].list, |
984 | &priv->network_free_list); | |
954ee164 | 985 | } |
1df4e8fe | 986 | |
aa21c004 DW |
987 | priv->lbs_ps_confirm_sleep.seqnum = cpu_to_le16(++priv->seqnum); |
988 | priv->lbs_ps_confirm_sleep.command = | |
1df4e8fe | 989 | cpu_to_le16(CMD_802_11_PS_MODE); |
aa21c004 | 990 | priv->lbs_ps_confirm_sleep.size = |
1df4e8fe | 991 | cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep)); |
aa21c004 | 992 | priv->lbs_ps_confirm_sleep.action = |
1df4e8fe HS |
993 | cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED); |
994 | ||
aa21c004 | 995 | memset(priv->current_addr, 0xff, ETH_ALEN); |
1df4e8fe | 996 | |
aa21c004 DW |
997 | priv->connect_status = LBS_DISCONNECTED; |
998 | priv->mesh_connect_status = LBS_DISCONNECTED; | |
999 | priv->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; | |
1000 | priv->mode = IW_MODE_INFRA; | |
1001 | priv->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL; | |
1002 | priv->currentpacketfilter = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON; | |
1003 | priv->radioon = RADIO_ON; | |
1004 | priv->auto_rate = 1; | |
1005 | priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE; | |
1006 | priv->psmode = LBS802_11POWERMODECAM; | |
1007 | priv->psstate = PS_STATE_FULL_POWER; | |
1df4e8fe | 1008 | |
aa21c004 | 1009 | mutex_init(&priv->lock); |
1df4e8fe | 1010 | |
aa21c004 | 1011 | setup_timer(&priv->command_timer, command_timer_fn, |
954ee164 | 1012 | (unsigned long)priv); |
1df4e8fe | 1013 | |
aa21c004 DW |
1014 | INIT_LIST_HEAD(&priv->cmdfreeq); |
1015 | INIT_LIST_HEAD(&priv->cmdpendingq); | |
1df4e8fe | 1016 | |
aa21c004 DW |
1017 | spin_lock_init(&priv->driver_lock); |
1018 | init_waitqueue_head(&priv->cmd_pending); | |
1df4e8fe | 1019 | |
954ee164 | 1020 | /* Allocate the command buffers */ |
10078321 | 1021 | if (lbs_allocate_cmd_buffer(priv)) { |
954ee164 DW |
1022 | lbs_pr_err("Out of memory allocating command buffers\n"); |
1023 | ret = -1; | |
1024 | } | |
1df4e8fe | 1025 | |
954ee164 DW |
1026 | out: |
1027 | return ret; | |
1028 | } | |
1df4e8fe | 1029 | |
69f9032d | 1030 | static void lbs_free_adapter(struct lbs_private *priv) |
954ee164 | 1031 | { |
954ee164 | 1032 | lbs_deb_fw("free command buffer\n"); |
10078321 | 1033 | lbs_free_cmd_buffer(priv); |
1df4e8fe | 1034 | |
954ee164 | 1035 | lbs_deb_fw("free command_timer\n"); |
aa21c004 | 1036 | del_timer(&priv->command_timer); |
954ee164 DW |
1037 | |
1038 | lbs_deb_fw("free scan results table\n"); | |
aa21c004 DW |
1039 | kfree(priv->networks); |
1040 | priv->networks = NULL; | |
1df4e8fe HS |
1041 | } |
1042 | ||
876c9d3a MT |
1043 | /** |
1044 | * @brief This function adds the card. it will probe the | |
10078321 | 1045 | * card, allocate the lbs_priv and initialize the device. |
876c9d3a MT |
1046 | * |
1047 | * @param card A pointer to card | |
69f9032d | 1048 | * @return A pointer to struct lbs_private structure |
876c9d3a | 1049 | */ |
69f9032d | 1050 | struct lbs_private *lbs_add_card(void *card, struct device *dmdev) |
876c9d3a MT |
1051 | { |
1052 | struct net_device *dev = NULL; | |
69f9032d | 1053 | struct lbs_private *priv = NULL; |
876c9d3a | 1054 | |
9012b28a | 1055 | lbs_deb_enter(LBS_DEB_NET); |
876c9d3a MT |
1056 | |
1057 | /* Allocate an Ethernet device and register it */ | |
69f9032d HS |
1058 | dev = alloc_etherdev(sizeof(struct lbs_private)); |
1059 | if (!dev) { | |
9012b28a | 1060 | lbs_pr_err("init ethX device failed\n"); |
954ee164 | 1061 | goto done; |
876c9d3a | 1062 | } |
64f104e8 | 1063 | priv = dev->priv; |
876c9d3a | 1064 | |
10078321 | 1065 | if (lbs_init_adapter(priv)) { |
954ee164 DW |
1066 | lbs_pr_err("failed to initialize adapter structure.\n"); |
1067 | goto err_init_adapter; | |
1068 | } | |
1069 | ||
634b8f49 HS |
1070 | priv->dev = dev; |
1071 | priv->card = card; | |
876c9d3a MT |
1072 | priv->mesh_open = 0; |
1073 | priv->infra_open = 0; | |
876c9d3a | 1074 | |
876c9d3a | 1075 | /* Setup the OS Interface to our functions */ |
10078321 | 1076 | dev->open = lbs_open; |
198cefb9 | 1077 | dev->hard_start_xmit = lbs_hard_start_xmit; |
10078321 HS |
1078 | dev->stop = lbs_close; |
1079 | dev->set_mac_address = lbs_set_mac_address; | |
1080 | dev->tx_timeout = lbs_tx_timeout; | |
1081 | dev->get_stats = lbs_get_stats; | |
fb3dddf2 | 1082 | dev->watchdog_timeo = 5 * HZ; |
10078321 | 1083 | dev->ethtool_ops = &lbs_ethtool_ops; |
876c9d3a | 1084 | #ifdef WIRELESS_EXT |
10078321 | 1085 | dev->wireless_handlers = (struct iw_handler_def *)&lbs_handler_def; |
876c9d3a | 1086 | #endif |
876c9d3a | 1087 | dev->flags |= IFF_BROADCAST | IFF_MULTICAST; |
10078321 | 1088 | dev->set_multicast_list = lbs_set_multicast_list; |
876c9d3a | 1089 | |
7732ca45 DW |
1090 | SET_NETDEV_DEV(dev, dmdev); |
1091 | ||
965f8bbc | 1092 | priv->rtap_net_dev = NULL; |
954ee164 DW |
1093 | |
1094 | lbs_deb_thread("Starting main thread...\n"); | |
1095 | init_waitqueue_head(&priv->waitq); | |
10078321 | 1096 | priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main"); |
954ee164 DW |
1097 | if (IS_ERR(priv->main_thread)) { |
1098 | lbs_deb_thread("Error creating main thread.\n"); | |
e7deced0 | 1099 | goto err_init_adapter; |
954ee164 DW |
1100 | } |
1101 | ||
10078321 HS |
1102 | priv->work_thread = create_singlethread_workqueue("lbs_worker"); |
1103 | INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker); | |
1104 | INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker); | |
1105 | INIT_WORK(&priv->sync_channel, lbs_sync_channel); | |
954ee164 | 1106 | |
32a74b7c HS |
1107 | goto done; |
1108 | ||
954ee164 | 1109 | err_init_adapter: |
10078321 | 1110 | lbs_free_adapter(priv); |
32a74b7c | 1111 | free_netdev(dev); |
6a812157 | 1112 | priv = NULL; |
954ee164 | 1113 | |
32a74b7c HS |
1114 | done: |
1115 | lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv); | |
1116 | return priv; | |
1117 | } | |
10078321 | 1118 | EXPORT_SYMBOL_GPL(lbs_add_card); |
32a74b7c | 1119 | |
954ee164 | 1120 | |
69f9032d | 1121 | int lbs_remove_card(struct lbs_private *priv) |
32a74b7c | 1122 | { |
634b8f49 | 1123 | struct net_device *dev = priv->dev; |
954ee164 | 1124 | union iwreq_data wrqu; |
32a74b7c HS |
1125 | |
1126 | lbs_deb_enter(LBS_DEB_MAIN); | |
876c9d3a | 1127 | |
10078321 | 1128 | lbs_remove_rtap(priv); |
876c9d3a | 1129 | |
954ee164 | 1130 | dev = priv->dev; |
e7deced0 | 1131 | device_remove_file(&dev->dev, &dev_attr_lbs_rtap); |
2afc0c5d | 1132 | |
954ee164 DW |
1133 | cancel_delayed_work(&priv->scan_work); |
1134 | cancel_delayed_work(&priv->assoc_work); | |
1135 | destroy_workqueue(priv->work_thread); | |
876c9d3a | 1136 | |
aa21c004 DW |
1137 | if (priv->psmode == LBS802_11POWERMODEMAX_PSP) { |
1138 | priv->psmode = LBS802_11POWERMODECAM; | |
10078321 | 1139 | lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP); |
876c9d3a MT |
1140 | } |
1141 | ||
954ee164 DW |
1142 | memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN); |
1143 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
1144 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); | |
1145 | ||
1146 | /* Stop the thread servicing the interrupts */ | |
aa21c004 | 1147 | priv->surpriseremoved = 1; |
954ee164 DW |
1148 | kthread_stop(priv->main_thread); |
1149 | ||
10078321 | 1150 | lbs_free_adapter(priv); |
954ee164 DW |
1151 | |
1152 | priv->dev = NULL; | |
1153 | free_netdev(dev); | |
1154 | ||
1155 | lbs_deb_leave(LBS_DEB_MAIN); | |
1156 | return 0; | |
1157 | } | |
10078321 | 1158 | EXPORT_SYMBOL_GPL(lbs_remove_card); |
954ee164 DW |
1159 | |
1160 | ||
69f9032d | 1161 | int lbs_start_card(struct lbs_private *priv) |
954ee164 DW |
1162 | { |
1163 | struct net_device *dev = priv->dev; | |
1164 | int ret = -1; | |
1165 | ||
1166 | lbs_deb_enter(LBS_DEB_MAIN); | |
1167 | ||
1168 | /* poke the firmware */ | |
10078321 | 1169 | ret = lbs_setup_firmware(priv); |
954ee164 DW |
1170 | if (ret) |
1171 | goto done; | |
1172 | ||
1173 | /* init 802.11d */ | |
10078321 | 1174 | lbs_init_11d(priv); |
876c9d3a MT |
1175 | |
1176 | if (register_netdev(dev)) { | |
9012b28a | 1177 | lbs_pr_err("cannot register ethX device\n"); |
954ee164 | 1178 | goto done; |
876c9d3a | 1179 | } |
e7deced0 DW |
1180 | if (device_create_file(&dev->dev, &dev_attr_lbs_rtap)) |
1181 | lbs_pr_err("cannot register lbs_rtap attribute\n"); | |
876c9d3a | 1182 | |
10078321 | 1183 | lbs_debugfs_init_one(priv, dev); |
876c9d3a | 1184 | |
954ee164 DW |
1185 | lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name); |
1186 | ||
32a74b7c | 1187 | ret = 0; |
876c9d3a | 1188 | |
32a74b7c | 1189 | done: |
954ee164 DW |
1190 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); |
1191 | return ret; | |
1192 | } | |
10078321 | 1193 | EXPORT_SYMBOL_GPL(lbs_start_card); |
954ee164 DW |
1194 | |
1195 | ||
69f9032d | 1196 | int lbs_stop_card(struct lbs_private *priv) |
954ee164 DW |
1197 | { |
1198 | struct net_device *dev = priv->dev; | |
1199 | int ret = -1; | |
1200 | struct cmd_ctrl_node *cmdnode; | |
1201 | unsigned long flags; | |
1202 | ||
1203 | lbs_deb_enter(LBS_DEB_MAIN); | |
1204 | ||
1205 | netif_stop_queue(priv->dev); | |
1206 | netif_carrier_off(priv->dev); | |
1207 | ||
10078321 | 1208 | lbs_debugfs_remove_one(priv); |
954ee164 DW |
1209 | |
1210 | /* Flush pending command nodes */ | |
aa21c004 DW |
1211 | spin_lock_irqsave(&priv->driver_lock, flags); |
1212 | list_for_each_entry(cmdnode, &priv->cmdpendingq, list) { | |
954ee164 DW |
1213 | cmdnode->cmdwaitqwoken = 1; |
1214 | wake_up_interruptible(&cmdnode->cmdwait_q); | |
1215 | } | |
aa21c004 | 1216 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
954ee164 DW |
1217 | |
1218 | unregister_netdev(dev); | |
1219 | ||
1220 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); | |
32a74b7c | 1221 | return ret; |
876c9d3a | 1222 | } |
10078321 | 1223 | EXPORT_SYMBOL_GPL(lbs_stop_card); |
084708b6 | 1224 | |
876c9d3a | 1225 | |
78523daa HS |
1226 | /** |
1227 | * @brief This function adds mshX interface | |
1228 | * | |
69f9032d | 1229 | * @param priv A pointer to the struct lbs_private structure |
78523daa HS |
1230 | * @return 0 if successful, -X otherwise |
1231 | */ | |
69f9032d | 1232 | int lbs_add_mesh(struct lbs_private *priv, struct device *dev) |
78523daa HS |
1233 | { |
1234 | struct net_device *mesh_dev = NULL; | |
1235 | int ret = 0; | |
1236 | ||
1237 | lbs_deb_enter(LBS_DEB_MESH); | |
1238 | ||
1239 | /* Allocate a virtual mesh device */ | |
1240 | if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) { | |
1241 | lbs_deb_mesh("init mshX device failed\n"); | |
1242 | ret = -ENOMEM; | |
1243 | goto done; | |
1244 | } | |
1245 | mesh_dev->priv = priv; | |
1246 | priv->mesh_dev = mesh_dev; | |
1247 | ||
10078321 | 1248 | mesh_dev->open = lbs_mesh_open; |
198cefb9 | 1249 | mesh_dev->hard_start_xmit = lbs_hard_start_xmit; |
10078321 HS |
1250 | mesh_dev->stop = lbs_mesh_close; |
1251 | mesh_dev->get_stats = lbs_get_stats; | |
1252 | mesh_dev->set_mac_address = lbs_set_mac_address; | |
1253 | mesh_dev->ethtool_ops = &lbs_ethtool_ops; | |
634b8f49 HS |
1254 | memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, |
1255 | sizeof(priv->dev->dev_addr)); | |
78523daa | 1256 | |
7732ca45 DW |
1257 | SET_NETDEV_DEV(priv->mesh_dev, dev); |
1258 | ||
78523daa | 1259 | #ifdef WIRELESS_EXT |
f5e05b69 | 1260 | mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def; |
78523daa | 1261 | #endif |
78523daa HS |
1262 | /* Register virtual mesh interface */ |
1263 | ret = register_netdev(mesh_dev); | |
1264 | if (ret) { | |
1265 | lbs_pr_err("cannot register mshX virtual interface\n"); | |
1266 | goto err_free; | |
1267 | } | |
1268 | ||
10078321 | 1269 | ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group); |
78523daa HS |
1270 | if (ret) |
1271 | goto err_unregister; | |
1272 | ||
1273 | /* Everything successful */ | |
1274 | ret = 0; | |
1275 | goto done; | |
1276 | ||
78523daa HS |
1277 | err_unregister: |
1278 | unregister_netdev(mesh_dev); | |
1279 | ||
1280 | err_free: | |
1281 | free_netdev(mesh_dev); | |
1282 | ||
1283 | done: | |
1284 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); | |
1285 | return ret; | |
1286 | } | |
10078321 | 1287 | EXPORT_SYMBOL_GPL(lbs_add_mesh); |
78523daa | 1288 | |
084708b6 | 1289 | |
69f9032d | 1290 | void lbs_remove_mesh(struct lbs_private *priv) |
78523daa HS |
1291 | { |
1292 | struct net_device *mesh_dev; | |
1293 | ||
954ee164 | 1294 | lbs_deb_enter(LBS_DEB_MAIN); |
78523daa HS |
1295 | |
1296 | if (!priv) | |
1297 | goto out; | |
1298 | ||
1299 | mesh_dev = priv->mesh_dev; | |
1300 | ||
1301 | netif_stop_queue(mesh_dev); | |
51d84f50 | 1302 | netif_carrier_off(priv->mesh_dev); |
78523daa | 1303 | |
10078321 | 1304 | sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group); |
78523daa HS |
1305 | unregister_netdev(mesh_dev); |
1306 | ||
1307 | priv->mesh_dev = NULL ; | |
1308 | free_netdev(mesh_dev); | |
1309 | ||
1310 | out: | |
954ee164 | 1311 | lbs_deb_leave(LBS_DEB_MAIN); |
78523daa | 1312 | } |
10078321 | 1313 | EXPORT_SYMBOL_GPL(lbs_remove_mesh); |
78523daa | 1314 | |
876c9d3a MT |
1315 | /** |
1316 | * @brief This function finds the CFP in | |
1317 | * region_cfp_table based on region and band parameter. | |
1318 | * | |
1319 | * @param region The region code | |
1320 | * @param band The band | |
1321 | * @param cfp_no A pointer to CFP number | |
1322 | * @return A pointer to CFP | |
1323 | */ | |
10078321 | 1324 | struct chan_freq_power *lbs_get_region_cfp_table(u8 region, u8 band, int *cfp_no) |
876c9d3a MT |
1325 | { |
1326 | int i, end; | |
1327 | ||
9012b28a | 1328 | lbs_deb_enter(LBS_DEB_MAIN); |
876c9d3a | 1329 | |
ff8ac609 | 1330 | end = ARRAY_SIZE(region_cfp_table); |
876c9d3a MT |
1331 | |
1332 | for (i = 0; i < end ; i++) { | |
9012b28a | 1333 | lbs_deb_main("region_cfp_table[i].region=%d\n", |
876c9d3a MT |
1334 | region_cfp_table[i].region); |
1335 | if (region_cfp_table[i].region == region) { | |
1336 | *cfp_no = region_cfp_table[i].cfp_no_BG; | |
9012b28a | 1337 | lbs_deb_leave(LBS_DEB_MAIN); |
876c9d3a MT |
1338 | return region_cfp_table[i].cfp_BG; |
1339 | } | |
1340 | } | |
1341 | ||
9012b28a | 1342 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL"); |
876c9d3a MT |
1343 | return NULL; |
1344 | } | |
1345 | ||
69f9032d | 1346 | int lbs_set_regiontable(struct lbs_private *priv, u8 region, u8 band) |
876c9d3a | 1347 | { |
9012b28a | 1348 | int ret = 0; |
876c9d3a MT |
1349 | int i = 0; |
1350 | ||
1351 | struct chan_freq_power *cfp; | |
1352 | int cfp_no; | |
1353 | ||
9012b28a | 1354 | lbs_deb_enter(LBS_DEB_MAIN); |
876c9d3a | 1355 | |
aa21c004 | 1356 | memset(priv->region_channel, 0, sizeof(priv->region_channel)); |
876c9d3a MT |
1357 | |
1358 | { | |
10078321 | 1359 | cfp = lbs_get_region_cfp_table(region, band, &cfp_no); |
876c9d3a | 1360 | if (cfp != NULL) { |
aa21c004 DW |
1361 | priv->region_channel[i].nrcfp = cfp_no; |
1362 | priv->region_channel[i].CFP = cfp; | |
876c9d3a | 1363 | } else { |
9012b28a | 1364 | lbs_deb_main("wrong region code %#x in band B/G\n", |
876c9d3a | 1365 | region); |
9012b28a HS |
1366 | ret = -1; |
1367 | goto out; | |
876c9d3a | 1368 | } |
aa21c004 DW |
1369 | priv->region_channel[i].valid = 1; |
1370 | priv->region_channel[i].region = region; | |
1371 | priv->region_channel[i].band = band; | |
876c9d3a MT |
1372 | i++; |
1373 | } | |
9012b28a HS |
1374 | out: |
1375 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); | |
1376 | return ret; | |
876c9d3a MT |
1377 | } |
1378 | ||
1379 | /** | |
1380 | * @brief This function handles the interrupt. it will change PS | |
1381 | * state if applicable. it will wake up main_thread to handle | |
1382 | * the interrupt event as well. | |
1383 | * | |
1384 | * @param dev A pointer to net_device structure | |
1385 | * @return n/a | |
1386 | */ | |
10078321 | 1387 | void lbs_interrupt(struct net_device *dev) |
876c9d3a | 1388 | { |
69f9032d | 1389 | struct lbs_private *priv = dev->priv; |
876c9d3a | 1390 | |
ed37b516 | 1391 | lbs_deb_enter(LBS_DEB_THREAD); |
876c9d3a | 1392 | |
10078321 | 1393 | lbs_deb_thread("lbs_interrupt: intcounter=%d\n", |
aa21c004 | 1394 | priv->intcounter); |
876c9d3a | 1395 | |
aa21c004 | 1396 | priv->intcounter++; |
876c9d3a | 1397 | |
aa21c004 DW |
1398 | if (priv->psstate == PS_STATE_SLEEP) { |
1399 | priv->psstate = PS_STATE_AWAKE; | |
876c9d3a | 1400 | netif_wake_queue(dev); |
3cf84091 HS |
1401 | if (priv->mesh_dev) |
1402 | netif_wake_queue(priv->mesh_dev); | |
876c9d3a MT |
1403 | } |
1404 | ||
fe336150 | 1405 | wake_up_interruptible(&priv->waitq); |
876c9d3a | 1406 | |
ed37b516 | 1407 | lbs_deb_leave(LBS_DEB_THREAD); |
876c9d3a | 1408 | } |
10078321 | 1409 | EXPORT_SYMBOL_GPL(lbs_interrupt); |
876c9d3a | 1410 | |
69f9032d | 1411 | int lbs_reset_device(struct lbs_private *priv) |
eedc2a31 DW |
1412 | { |
1413 | int ret; | |
1414 | ||
1415 | lbs_deb_enter(LBS_DEB_MAIN); | |
10078321 | 1416 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_RESET, |
eedc2a31 DW |
1417 | CMD_ACT_HALT, 0, 0, NULL); |
1418 | msleep_interruptible(10); | |
1419 | ||
1420 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); | |
1421 | return ret; | |
1422 | } | |
10078321 | 1423 | EXPORT_SYMBOL_GPL(lbs_reset_device); |
eedc2a31 | 1424 | |
4fb910fd | 1425 | static int __init lbs_init_module(void) |
876c9d3a | 1426 | { |
9012b28a | 1427 | lbs_deb_enter(LBS_DEB_MAIN); |
10078321 | 1428 | lbs_debugfs_init(); |
084708b6 HS |
1429 | lbs_deb_leave(LBS_DEB_MAIN); |
1430 | return 0; | |
876c9d3a MT |
1431 | } |
1432 | ||
4fb910fd | 1433 | static void __exit lbs_exit_module(void) |
876c9d3a | 1434 | { |
9012b28a | 1435 | lbs_deb_enter(LBS_DEB_MAIN); |
876c9d3a | 1436 | |
10078321 | 1437 | lbs_debugfs_remove(); |
876c9d3a | 1438 | |
9012b28a | 1439 | lbs_deb_leave(LBS_DEB_MAIN); |
876c9d3a MT |
1440 | } |
1441 | ||
965f8bbc LCC |
1442 | /* |
1443 | * rtap interface support fuctions | |
1444 | */ | |
1445 | ||
10078321 | 1446 | static int lbs_rtap_open(struct net_device *dev) |
965f8bbc LCC |
1447 | { |
1448 | netif_carrier_off(dev); | |
1449 | netif_stop_queue(dev); | |
1450 | return 0; | |
1451 | } | |
1452 | ||
10078321 | 1453 | static int lbs_rtap_stop(struct net_device *dev) |
965f8bbc LCC |
1454 | { |
1455 | return 0; | |
1456 | } | |
1457 | ||
10078321 | 1458 | static int lbs_rtap_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
965f8bbc LCC |
1459 | { |
1460 | netif_stop_queue(dev); | |
1461 | return -EOPNOTSUPP; | |
1462 | } | |
1463 | ||
10078321 | 1464 | static struct net_device_stats *lbs_rtap_get_stats(struct net_device *dev) |
965f8bbc | 1465 | { |
69f9032d | 1466 | struct lbs_private *priv = dev->priv; |
d9268fb9 | 1467 | return &priv->stats; |
965f8bbc LCC |
1468 | } |
1469 | ||
1470 | ||
69f9032d | 1471 | void lbs_remove_rtap(struct lbs_private *priv) |
965f8bbc LCC |
1472 | { |
1473 | if (priv->rtap_net_dev == NULL) | |
1474 | return; | |
1475 | unregister_netdev(priv->rtap_net_dev); | |
d9268fb9 | 1476 | free_netdev(priv->rtap_net_dev); |
965f8bbc LCC |
1477 | priv->rtap_net_dev = NULL; |
1478 | } | |
1479 | ||
69f9032d | 1480 | int lbs_add_rtap(struct lbs_private *priv) |
965f8bbc LCC |
1481 | { |
1482 | int rc = 0; | |
d9268fb9 | 1483 | struct net_device *rtap_dev; |
965f8bbc LCC |
1484 | |
1485 | if (priv->rtap_net_dev) | |
1486 | return -EPERM; | |
1487 | ||
d9268fb9 DW |
1488 | rtap_dev = alloc_netdev(0, "rtap%d", ether_setup); |
1489 | if (rtap_dev == NULL) | |
965f8bbc LCC |
1490 | return -ENOMEM; |
1491 | ||
121947c6 | 1492 | memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN); |
d9268fb9 DW |
1493 | rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
1494 | rtap_dev->open = lbs_rtap_open; | |
1495 | rtap_dev->stop = lbs_rtap_stop; | |
1496 | rtap_dev->get_stats = lbs_rtap_get_stats; | |
1497 | rtap_dev->hard_start_xmit = lbs_rtap_hard_start_xmit; | |
1498 | rtap_dev->set_multicast_list = lbs_set_multicast_list; | |
1499 | rtap_dev->priv = priv; | |
965f8bbc | 1500 | |
d9268fb9 | 1501 | rc = register_netdev(rtap_dev); |
965f8bbc | 1502 | if (rc) { |
d9268fb9 | 1503 | free_netdev(rtap_dev); |
965f8bbc LCC |
1504 | return rc; |
1505 | } | |
d9268fb9 | 1506 | priv->rtap_net_dev = rtap_dev; |
965f8bbc LCC |
1507 | |
1508 | return 0; | |
1509 | } | |
1510 | ||
1511 | ||
10078321 HS |
1512 | module_init(lbs_init_module); |
1513 | module_exit(lbs_exit_module); | |
876c9d3a | 1514 | |
084708b6 | 1515 | MODULE_DESCRIPTION("Libertas WLAN Driver Library"); |
876c9d3a MT |
1516 | MODULE_AUTHOR("Marvell International Ltd."); |
1517 | MODULE_LICENSE("GPL"); |