blob: fd76c46225d1198cf579c92e41c3e56e07855417 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains the major functions in WLAN
3 * driver. It includes init, exit, open, close and main
4 * thread etc..
5 */
6
Holger Schuriga46c6412007-05-25 11:32:07 -04007#include <linux/moduleparam.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02008#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>
Dan Williamsfe336152007-08-02 11:32:25 -040013#include <linux/kthread.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020014
15#include <net/iw_handler.h>
Holger Schurig9012b282007-05-25 11:27:16 -040016#include <net/ieee80211.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020017
18#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019#include "decl.h"
20#include "dev.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020021#include "wext.h"
22#include "debugfs.h"
23#include "assoc.h"
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -040024#include "join.h"
Dan Williams6e66f032007-12-11 12:42:16 -050025#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020026
Dan Williams7856a542007-08-03 09:43:03 -040027#define DRIVER_RELEASE_VERSION "323.p0"
Holger Schurig10078322007-11-15 18:05:47 -050028const char lbs_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
Dan Williams3ce40232007-05-10 23:03:07 -040029#ifdef DEBUG
30 "-dbg"
31#endif
32 "";
33
Holger Schuriga46c6412007-05-25 11:32:07 -040034
35/* Module parameters */
Holger Schurig10078322007-11-15 18:05:47 -050036unsigned int lbs_debug;
37EXPORT_SYMBOL_GPL(lbs_debug);
38module_param_named(libertas_debug, lbs_debug, int, 0644);
Holger Schuriga46c6412007-05-25 11:32:07 -040039
40
Holger Schurig10078322007-11-15 18:05:47 -050041#define LBS_TX_PWR_DEFAULT 20 /*100mW */
42#define LBS_TX_PWR_US_DEFAULT 20 /*100mW */
43#define LBS_TX_PWR_JP_DEFAULT 16 /*50mW */
44#define LBS_TX_PWR_FR_DEFAULT 20 /*100mW */
45#define LBS_TX_PWR_EMEA_DEFAULT 20 /*100mW */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020046
47/* Format { channel, frequency (MHz), maxtxpower } */
48/* band: 'B/G', region: USA FCC/Canada IC */
49static struct chan_freq_power channel_freq_power_US_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050050 {1, 2412, LBS_TX_PWR_US_DEFAULT},
51 {2, 2417, LBS_TX_PWR_US_DEFAULT},
52 {3, 2422, LBS_TX_PWR_US_DEFAULT},
53 {4, 2427, LBS_TX_PWR_US_DEFAULT},
54 {5, 2432, LBS_TX_PWR_US_DEFAULT},
55 {6, 2437, LBS_TX_PWR_US_DEFAULT},
56 {7, 2442, LBS_TX_PWR_US_DEFAULT},
57 {8, 2447, LBS_TX_PWR_US_DEFAULT},
58 {9, 2452, LBS_TX_PWR_US_DEFAULT},
59 {10, 2457, LBS_TX_PWR_US_DEFAULT},
60 {11, 2462, LBS_TX_PWR_US_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020061};
62
63/* band: 'B/G', region: Europe ETSI */
64static struct chan_freq_power channel_freq_power_EU_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050065 {1, 2412, LBS_TX_PWR_EMEA_DEFAULT},
66 {2, 2417, LBS_TX_PWR_EMEA_DEFAULT},
67 {3, 2422, LBS_TX_PWR_EMEA_DEFAULT},
68 {4, 2427, LBS_TX_PWR_EMEA_DEFAULT},
69 {5, 2432, LBS_TX_PWR_EMEA_DEFAULT},
70 {6, 2437, LBS_TX_PWR_EMEA_DEFAULT},
71 {7, 2442, LBS_TX_PWR_EMEA_DEFAULT},
72 {8, 2447, LBS_TX_PWR_EMEA_DEFAULT},
73 {9, 2452, LBS_TX_PWR_EMEA_DEFAULT},
74 {10, 2457, LBS_TX_PWR_EMEA_DEFAULT},
75 {11, 2462, LBS_TX_PWR_EMEA_DEFAULT},
76 {12, 2467, LBS_TX_PWR_EMEA_DEFAULT},
77 {13, 2472, LBS_TX_PWR_EMEA_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020078};
79
80/* band: 'B/G', region: Spain */
81static struct chan_freq_power channel_freq_power_SPN_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050082 {10, 2457, LBS_TX_PWR_DEFAULT},
83 {11, 2462, LBS_TX_PWR_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020084};
85
86/* band: 'B/G', region: France */
87static struct chan_freq_power channel_freq_power_FR_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050088 {10, 2457, LBS_TX_PWR_FR_DEFAULT},
89 {11, 2462, LBS_TX_PWR_FR_DEFAULT},
90 {12, 2467, LBS_TX_PWR_FR_DEFAULT},
91 {13, 2472, LBS_TX_PWR_FR_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020092};
93
94/* band: 'B/G', region: Japan */
95static struct chan_freq_power channel_freq_power_JPN_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050096 {1, 2412, LBS_TX_PWR_JP_DEFAULT},
97 {2, 2417, LBS_TX_PWR_JP_DEFAULT},
98 {3, 2422, LBS_TX_PWR_JP_DEFAULT},
99 {4, 2427, LBS_TX_PWR_JP_DEFAULT},
100 {5, 2432, LBS_TX_PWR_JP_DEFAULT},
101 {6, 2437, LBS_TX_PWR_JP_DEFAULT},
102 {7, 2442, LBS_TX_PWR_JP_DEFAULT},
103 {8, 2447, LBS_TX_PWR_JP_DEFAULT},
104 {9, 2452, LBS_TX_PWR_JP_DEFAULT},
105 {10, 2457, LBS_TX_PWR_JP_DEFAULT},
106 {11, 2462, LBS_TX_PWR_JP_DEFAULT},
107 {12, 2467, LBS_TX_PWR_JP_DEFAULT},
108 {13, 2472, LBS_TX_PWR_JP_DEFAULT},
109 {14, 2484, LBS_TX_PWR_JP_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200110};
111
112/**
113 * the structure for channel, frequency and power
114 */
115struct region_cfp_table {
116 u8 region;
117 struct chan_freq_power *cfp_BG;
118 int cfp_no_BG;
119};
120
121/**
122 * the structure for the mapping between region and CFP
123 */
124static struct region_cfp_table region_cfp_table[] = {
125 {0x10, /*US FCC */
126 channel_freq_power_US_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800127 ARRAY_SIZE(channel_freq_power_US_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200128 }
129 ,
130 {0x20, /*CANADA IC */
131 channel_freq_power_US_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800132 ARRAY_SIZE(channel_freq_power_US_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200133 }
134 ,
135 {0x30, /*EU*/ channel_freq_power_EU_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800136 ARRAY_SIZE(channel_freq_power_EU_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200137 }
138 ,
139 {0x31, /*SPAIN*/ channel_freq_power_SPN_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800140 ARRAY_SIZE(channel_freq_power_SPN_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200141 }
142 ,
143 {0x32, /*FRANCE*/ channel_freq_power_FR_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800144 ARRAY_SIZE(channel_freq_power_FR_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200145 }
146 ,
147 {0x40, /*JAPAN*/ channel_freq_power_JPN_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800148 ARRAY_SIZE(channel_freq_power_JPN_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149 }
150 ,
151/*Add new region here */
152};
153
154/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200155 * the table to keep region code
156 */
Holger Schurig10078322007-11-15 18:05:47 -0500157u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
159
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160/**
Dan Williams8c512762007-08-02 11:40:45 -0400161 * 802.11b/g supported bitrates (in 500Kb/s units)
162 */
Holger Schurig10078322007-11-15 18:05:47 -0500163u8 lbs_bg_rates[MAX_RATES] =
Dan Williams8c512762007-08-02 11:40:45 -0400164 { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
1650x00, 0x00 };
166
167/**
168 * FW rate table. FW refers to rates by their index in this table, not by the
169 * rate value itself. Values of 0x00 are
170 * reserved positions.
171 */
172static u8 fw_data_rates[MAX_RATES] =
173 { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
174 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
175};
176
177/**
178 * @brief use index to get the data rate
179 *
180 * @param idx The index of data rate
181 * @return data rate or 0
182 */
Holger Schurig10078322007-11-15 18:05:47 -0500183u32 lbs_fw_index_to_data_rate(u8 idx)
Dan Williams8c512762007-08-02 11:40:45 -0400184{
185 if (idx >= sizeof(fw_data_rates))
186 idx = 0;
187 return fw_data_rates[idx];
188}
189
190/**
191 * @brief use rate to get the index
192 *
193 * @param rate data rate
194 * @return index or 0
195 */
Holger Schurig10078322007-11-15 18:05:47 -0500196u8 lbs_data_rate_to_fw_index(u32 rate)
Dan Williams8c512762007-08-02 11:40:45 -0400197{
198 u8 i;
199
200 if (!rate)
201 return 0;
202
203 for (i = 0; i < sizeof(fw_data_rates); i++) {
204 if (rate == fw_data_rates[i])
205 return i;
206 }
207 return 0;
208}
209
210/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200211 * Attributes exported through sysfs
212 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200213
214/**
Luis Carlos82fde742007-06-07 16:40:59 -0400215 * @brief Get function for sysfs attribute anycast_mask
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200216 */
Holger Schurig10078322007-11-15 18:05:47 -0500217static ssize_t lbs_anycast_get(struct device *dev,
Dan Williamsb59bb612007-06-18 11:50:43 -0400218 struct device_attribute *attr, char * buf)
219{
David Woodhouse301eacb2007-12-11 15:23:59 -0500220 struct lbs_private *priv = to_net_dev(dev)->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200221 struct cmd_ds_mesh_access mesh_access;
David Woodhouse301eacb2007-12-11 15:23:59 -0500222 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200223
224 memset(&mesh_access, 0, sizeof(mesh_access));
David Woodhouse301eacb2007-12-11 15:23:59 -0500225
226 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
227 if (ret)
228 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200229
Luis Carlos82fde742007-06-07 16:40:59 -0400230 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231}
232
233/**
Luis Carlos82fde742007-06-07 16:40:59 -0400234 * @brief Set function for sysfs attribute anycast_mask
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200235 */
Holger Schurig10078322007-11-15 18:05:47 -0500236static ssize_t lbs_anycast_set(struct device *dev,
Dan Williamsb59bb612007-06-18 11:50:43 -0400237 struct device_attribute *attr, const char * buf, size_t count)
238{
David Woodhouse301eacb2007-12-11 15:23:59 -0500239 struct lbs_private *priv = to_net_dev(dev)->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200240 struct cmd_ds_mesh_access mesh_access;
David Woodhouse981f1872007-05-25 23:36:54 -0400241 uint32_t datum;
David Woodhouse301eacb2007-12-11 15:23:59 -0500242 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200243
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244 memset(&mesh_access, 0, sizeof(mesh_access));
Luis Carlos82fde742007-06-07 16:40:59 -0400245 sscanf(buf, "%x", &datum);
David Woodhouse981f1872007-05-25 23:36:54 -0400246 mesh_access.data[0] = cpu_to_le32(datum);
247
David Woodhouse301eacb2007-12-11 15:23:59 -0500248 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
249 if (ret)
250 return ret;
251
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200252 return strlen(buf);
253}
254
David Woodhouse2fd6cfe2007-12-11 17:44:10 -0500255static int lbs_add_rtap(struct lbs_private *priv);
256static void lbs_remove_rtap(struct lbs_private *priv);
David Woodhouse23a397a2007-12-11 18:56:42 -0500257static int lbs_add_mesh(struct lbs_private *priv);
258static void lbs_remove_mesh(struct lbs_private *priv);
259
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400260
261/**
262 * Get function for sysfs attribute rtap
263 */
Holger Schurig10078322007-11-15 18:05:47 -0500264static ssize_t lbs_rtap_get(struct device *dev,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400265 struct device_attribute *attr, char * buf)
266{
David Woodhousee7deced2007-12-08 18:29:16 +0000267 struct lbs_private *priv = to_net_dev(dev)->priv;
David Woodhouseaa21c002007-12-08 20:04:36 +0000268 return snprintf(buf, 5, "0x%X\n", priv->monitormode);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400269}
270
271/**
272 * Set function for sysfs attribute rtap
273 */
Holger Schurig10078322007-11-15 18:05:47 -0500274static ssize_t lbs_rtap_set(struct device *dev,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400275 struct device_attribute *attr, const char * buf, size_t count)
276{
277 int monitor_mode;
David Woodhousee7deced2007-12-08 18:29:16 +0000278 struct lbs_private *priv = to_net_dev(dev)->priv;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400279
280 sscanf(buf, "%x", &monitor_mode);
Holger Schurig10078322007-11-15 18:05:47 -0500281 if (monitor_mode != LBS_MONITOR_OFF) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000282 if(priv->monitormode == monitor_mode)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400283 return strlen(buf);
David Woodhouseaa21c002007-12-08 20:04:36 +0000284 if (priv->monitormode == LBS_MONITOR_OFF) {
David Woodhouse8552855f2007-12-10 16:38:18 -0500285 if (priv->infra_open || priv->mesh_open)
286 return -EBUSY;
David Woodhouseaa21c002007-12-08 20:04:36 +0000287 if (priv->mode == IW_MODE_INFRA)
Holger Schurig10078322007-11-15 18:05:47 -0500288 lbs_send_deauthentication(priv);
David Woodhouseaa21c002007-12-08 20:04:36 +0000289 else if (priv->mode == IW_MODE_ADHOC)
Holger Schurig10078322007-11-15 18:05:47 -0500290 lbs_stop_adhoc_network(priv);
291 lbs_add_rtap(priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400292 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000293 priv->monitormode = monitor_mode;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400294 }
295
296 else {
David Woodhouseaa21c002007-12-08 20:04:36 +0000297 if (priv->monitormode == LBS_MONITOR_OFF)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400298 return strlen(buf);
David Woodhouseaa21c002007-12-08 20:04:36 +0000299 priv->monitormode = LBS_MONITOR_OFF;
Holger Schurig10078322007-11-15 18:05:47 -0500300 lbs_remove_rtap(priv);
David Woodhousef86a93e2007-12-08 19:46:19 +0000301
David Woodhouseaa21c002007-12-08 20:04:36 +0000302 if (priv->currenttxskb) {
303 dev_kfree_skb_any(priv->currenttxskb);
304 priv->currenttxskb = NULL;
David Woodhousef86a93e2007-12-08 19:46:19 +0000305 }
306
307 /* Wake queues, command thread, etc. */
308 lbs_host_to_card_done(priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400309 }
310
Holger Schurig10078322007-11-15 18:05:47 -0500311 lbs_prepare_and_send_command(priv,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400312 CMD_802_11_MONITOR_MODE, CMD_ACT_SET,
David Woodhouseaa21c002007-12-08 20:04:36 +0000313 CMD_OPTION_WAITFORRSP, 0, &priv->monitormode);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400314 return strlen(buf);
315}
316
317/**
David Woodhouse23a397a2007-12-11 18:56:42 -0500318 * lbs_rtap attribute to be exported per ethX interface
319 * through sysfs (/sys/class/net/ethX/lbs_rtap)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400320 */
David Woodhouse23a397a2007-12-11 18:56:42 -0500321static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get, lbs_rtap_set );
322
323/**
324 * Get function for sysfs attribute mesh
325 */
326static ssize_t lbs_mesh_get(struct device *dev,
327 struct device_attribute *attr, char * buf)
328{
329 struct lbs_private *priv = to_net_dev(dev)->priv;
330 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
331}
332
333/**
334 * Set function for sysfs attribute mesh
335 */
336static ssize_t lbs_mesh_set(struct device *dev,
337 struct device_attribute *attr, const char * buf, size_t count)
338{
339 struct lbs_private *priv = to_net_dev(dev)->priv;
340 int enable;
341 int ret;
342
343 sscanf(buf, "%x", &enable);
344 enable = !!enable;
345 if (enable == !!priv->mesh_dev)
346 return count;
347
348 ret = lbs_mesh_config(priv, enable);
349 if (ret)
350 return ret;
351
352 if (enable)
353 lbs_add_mesh(priv);
354 else
355 lbs_remove_mesh(priv);
356
357 return count;
358}
359
360/**
361 * lbs_mesh attribute to be exported per ethX interface
362 * through sysfs (/sys/class/net/ethX/lbs_mesh)
363 */
364static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400365
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200366/**
Luis Carlos82fde742007-06-07 16:40:59 -0400367 * anycast_mask attribute to be exported per mshX interface
368 * through sysfs (/sys/class/net/mshX/anycast_mask)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369 */
Holger Schurig10078322007-11-15 18:05:47 -0500370static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371
Holger Schurig10078322007-11-15 18:05:47 -0500372static ssize_t lbs_autostart_enabled_get(struct device *dev,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400373 struct device_attribute *attr, char * buf)
374{
David Woodhouse301eacb2007-12-11 15:23:59 -0500375 struct lbs_private *priv = to_net_dev(dev)->priv;
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400376 struct cmd_ds_mesh_access mesh_access;
David Woodhouse301eacb2007-12-11 15:23:59 -0500377 int ret;
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400378
379 memset(&mesh_access, 0, sizeof(mesh_access));
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400380
David Woodhouse301eacb2007-12-11 15:23:59 -0500381 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_AUTOSTART_ENABLED, &mesh_access);
382 if (ret)
383 return ret;
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400384 return sprintf(buf, "%d\n", le32_to_cpu(mesh_access.data[0]));
385}
386
Holger Schurig10078322007-11-15 18:05:47 -0500387static ssize_t lbs_autostart_enabled_set(struct device *dev,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400388 struct device_attribute *attr, const char * buf, size_t count)
389{
390 struct cmd_ds_mesh_access mesh_access;
391 uint32_t datum;
Holger Schurig69f90322007-11-23 15:43:44 +0100392 struct lbs_private *priv = (to_net_dev(dev))->priv;
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400393 int ret;
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400394
395 memset(&mesh_access, 0, sizeof(mesh_access));
396 sscanf(buf, "%d", &datum);
397 mesh_access.data[0] = cpu_to_le32(datum);
398
David Woodhouse301eacb2007-12-11 15:23:59 -0500399 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_AUTOSTART_ENABLED, &mesh_access);
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400400 if (ret == 0)
401 priv->mesh_autostart_enabled = datum ? 1 : 0;
402
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400403 return strlen(buf);
404}
405
406static DEVICE_ATTR(autostart_enabled, 0644,
Holger Schurig10078322007-11-15 18:05:47 -0500407 lbs_autostart_enabled_get, lbs_autostart_enabled_set);
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400408
Holger Schurig10078322007-11-15 18:05:47 -0500409static struct attribute *lbs_mesh_sysfs_entries[] = {
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400410 &dev_attr_anycast_mask.attr,
411 &dev_attr_autostart_enabled.attr,
412 NULL,
413};
414
Holger Schurig10078322007-11-15 18:05:47 -0500415static struct attribute_group lbs_mesh_attr_group = {
416 .attrs = lbs_mesh_sysfs_entries,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400417};
418
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419/**
David Woodhouse8552855f2007-12-10 16:38:18 -0500420 * @brief This function opens the ethX or mshX interface
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200421 *
422 * @param dev A pointer to net_device structure
David Woodhouse8552855f2007-12-10 16:38:18 -0500423 * @return 0 or -EBUSY if monitor mode active
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200424 */
Holger Schurig10078322007-11-15 18:05:47 -0500425static int lbs_dev_open(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200426{
David Woodhouse8552855f2007-12-10 16:38:18 -0500427 struct lbs_private *priv = (struct lbs_private *) dev->priv ;
428 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200429
David Woodhouse8552855f2007-12-10 16:38:18 -0500430 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431
David Woodhouse8552855f2007-12-10 16:38:18 -0500432 if (priv->monitormode != LBS_MONITOR_OFF) {
433 ret = -EBUSY;
434 goto out;
Javier Cardona51d84f52007-05-25 12:06:56 -0400435 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200436
David Woodhouse8552855f2007-12-10 16:38:18 -0500437 if (dev == priv->mesh_dev) {
438 priv->mesh_open = 1;
439 priv->mesh_connect_status = LBS_CONNECTED;
440 netif_carrier_on(dev);
441 } else {
442 priv->infra_open = 1;
443
444 if (priv->connect_status == LBS_CONNECTED)
445 netif_carrier_on(dev);
446 else
447 netif_carrier_off(dev);
448 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200449
David Woodhouse8552855f2007-12-10 16:38:18 -0500450 if (!priv->tx_pending_len)
451 netif_wake_queue(dev);
452 out:
Brajesh Dave01d77d82007-11-20 17:44:14 -0500453
David Woodhouse8552855f2007-12-10 16:38:18 -0500454 spin_unlock_irq(&priv->driver_lock);
455 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200456}
457
458/**
459 * @brief This function closes the mshX interface
460 *
461 * @param dev A pointer to net_device structure
462 * @return 0
463 */
David Woodhouse8552855f2007-12-10 16:38:18 -0500464static int lbs_mesh_stop(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200465{
Holger Schurig69f90322007-11-23 15:43:44 +0100466 struct lbs_private *priv = (struct lbs_private *) (dev->priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200467
David Woodhouse8552855f2007-12-10 16:38:18 -0500468 spin_lock_irq(&priv->driver_lock);
469
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470 priv->mesh_open = 0;
David Woodhouse8552855f2007-12-10 16:38:18 -0500471 priv->mesh_connect_status = LBS_DISCONNECTED;
472
473 netif_stop_queue(dev);
474 netif_carrier_off(dev);
475
476 spin_unlock_irq(&priv->driver_lock);
477 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200478}
479
480/**
481 * @brief This function closes the ethX interface
482 *
483 * @param dev A pointer to net_device structure
484 * @return 0
485 */
David Woodhouse8552855f2007-12-10 16:38:18 -0500486static int lbs_eth_stop(struct net_device *dev)
Holger Schurig78523da2007-05-25 11:49:19 -0400487{
Holger Schurig69f90322007-11-23 15:43:44 +0100488 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489
David Woodhouse8552855f2007-12-10 16:38:18 -0500490 spin_lock_irq(&priv->driver_lock);
491
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200492 priv->infra_open = 0;
David Woodhouse8552855f2007-12-10 16:38:18 -0500493
494 netif_stop_queue(dev);
495
496 spin_unlock_irq(&priv->driver_lock);
497 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200498}
499
Holger Schurig10078322007-11-15 18:05:47 -0500500static void lbs_tx_timeout(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200501{
Holger Schurig69f90322007-11-23 15:43:44 +0100502 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200503
Holger Schurig9012b282007-05-25 11:27:16 -0400504 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200505
Holger Schurig9012b282007-05-25 11:27:16 -0400506 lbs_pr_err("tx watch dog timeout\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200508 dev->trans_start = jiffies;
509
David Woodhouseaa21c002007-12-08 20:04:36 +0000510 if (priv->currenttxskb) {
David Woodhousea63b22b2007-12-08 20:56:44 +0000511 priv->eventcause = 0x01000000;
512 lbs_send_tx_feedback(priv);
Javier Cardona51d84f52007-05-25 12:06:56 -0400513 }
David Woodhousea63b22b2007-12-08 20:56:44 +0000514 /* XX: Shouldn't we also call into the hw-specific driver
515 to kick it somehow? */
516 lbs_host_to_card_done(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200517
Holger Schurig9012b282007-05-25 11:27:16 -0400518 lbs_deb_leave(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200519}
520
David Woodhousee775ed72007-12-06 14:36:11 +0000521void lbs_host_to_card_done(struct lbs_private *priv)
522{
David Woodhousea63b22b2007-12-08 20:56:44 +0000523 unsigned long flags;
524
525 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhousee775ed72007-12-06 14:36:11 +0000526
527 priv->dnld_sent = DNLD_RES_RECEIVED;
528
529 /* Wake main thread if commands are pending */
David Woodhouseaa21c002007-12-08 20:04:36 +0000530 if (!priv->cur_cmd)
David Woodhousee775ed72007-12-06 14:36:11 +0000531 wake_up_interruptible(&priv->waitq);
532
David Woodhousef86a93e2007-12-08 19:46:19 +0000533 /* Don't wake netif queues if we're in monitor mode and
David Woodhousea63b22b2007-12-08 20:56:44 +0000534 a TX packet is already pending, or if there are commands
535 queued to be sent. */
536 if (!priv->currenttxskb && list_empty(&priv->cmdpendingq)) {
537 if (priv->dev && priv->connect_status == LBS_CONNECTED)
538 netif_wake_queue(priv->dev);
David Woodhousef86a93e2007-12-08 19:46:19 +0000539
David Woodhousea63b22b2007-12-08 20:56:44 +0000540 if (priv->mesh_dev && priv->mesh_connect_status == LBS_CONNECTED)
541 netif_wake_queue(priv->mesh_dev);
542 }
543 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhousee775ed72007-12-06 14:36:11 +0000544}
545EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
546
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200547/**
548 * @brief This function returns the network statistics
549 *
Holger Schurig69f90322007-11-23 15:43:44 +0100550 * @param dev A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200551 * @return A pointer to net_device_stats structure
552 */
Holger Schurig10078322007-11-15 18:05:47 -0500553static struct net_device_stats *lbs_get_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200554{
Holger Schurig69f90322007-11-23 15:43:44 +0100555 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200556
557 return &priv->stats;
558}
559
Holger Schurig10078322007-11-15 18:05:47 -0500560static int lbs_set_mac_address(struct net_device *dev, void *addr)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200561{
562 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100563 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200564 struct sockaddr *phwaddr = addr;
565
Holger Schurig9012b282007-05-25 11:27:16 -0400566 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567
Luis Carlos Cobo Rus0a0d08a2007-05-25 23:05:27 -0400568 /* In case it was called from the mesh device */
569 dev = priv->dev ;
570
David Woodhouseaa21c002007-12-08 20:04:36 +0000571 memset(priv->current_addr, 0, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200572
573 /* dev->dev_addr is 8 bytes */
Holger Schurigece56192007-08-02 11:53:06 -0400574 lbs_deb_hex(LBS_DEB_NET, "dev->dev_addr", dev->dev_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200575
Holger Schurigece56192007-08-02 11:53:06 -0400576 lbs_deb_hex(LBS_DEB_NET, "addr", phwaddr->sa_data, ETH_ALEN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000577 memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200578
Holger Schurig10078322007-11-15 18:05:47 -0500579 ret = lbs_prepare_and_send_command(priv, CMD_802_11_MAC_ADDRESS,
Dan Williams0aef64d2007-08-02 11:31:18 -0400580 CMD_ACT_SET,
581 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200582
583 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400584 lbs_deb_net("set MAC address failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200585 ret = -1;
586 goto done;
587 }
588
David Woodhouseaa21c002007-12-08 20:04:36 +0000589 lbs_deb_hex(LBS_DEB_NET, "priv->macaddr", priv->current_addr, ETH_ALEN);
590 memcpy(dev->dev_addr, priv->current_addr, ETH_ALEN);
Holger Schurig78523da2007-05-25 11:49:19 -0400591 if (priv->mesh_dev)
David Woodhouseaa21c002007-12-08 20:04:36 +0000592 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200593
594done:
Holger Schurig9012b282007-05-25 11:27:16 -0400595 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200596 return ret;
597}
598
David Woodhouseaa21c002007-12-08 20:04:36 +0000599static int lbs_copy_multicast_address(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200600 struct net_device *dev)
601{
602 int i = 0;
603 struct dev_mc_list *mcptr = dev->mc_list;
604
605 for (i = 0; i < dev->mc_count; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000606 memcpy(&priv->multicastlist[i], mcptr->dmi_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200607 mcptr = mcptr->next;
608 }
609
610 return i;
611
612}
613
Holger Schurig10078322007-11-15 18:05:47 -0500614static void lbs_set_multicast_list(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200615{
Holger Schurig69f90322007-11-23 15:43:44 +0100616 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200617 int oldpacketfilter;
Joe Perches0795af52007-10-03 17:59:30 -0700618 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200619
Holger Schurig9012b282007-05-25 11:27:16 -0400620 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200621
David Woodhouseaa21c002007-12-08 20:04:36 +0000622 oldpacketfilter = priv->currentpacketfilter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200623
624 if (dev->flags & IFF_PROMISC) {
Holger Schurig9012b282007-05-25 11:27:16 -0400625 lbs_deb_net("enable promiscuous mode\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000626 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400627 CMD_ACT_MAC_PROMISCUOUS_ENABLE;
David Woodhouseaa21c002007-12-08 20:04:36 +0000628 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400629 ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE |
630 CMD_ACT_MAC_MULTICAST_ENABLE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200631 } else {
632 /* Multicast */
David Woodhouseaa21c002007-12-08 20:04:36 +0000633 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400634 ~CMD_ACT_MAC_PROMISCUOUS_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200635
636 if (dev->flags & IFF_ALLMULTI || dev->mc_count >
637 MRVDRV_MAX_MULTICAST_LIST_SIZE) {
Holger Schurig9012b282007-05-25 11:27:16 -0400638 lbs_deb_net( "enabling all multicast\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000639 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400640 CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
David Woodhouseaa21c002007-12-08 20:04:36 +0000641 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400642 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200643 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +0000644 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400645 ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200646
647 if (!dev->mc_count) {
Holger Schurig9012b282007-05-25 11:27:16 -0400648 lbs_deb_net("no multicast addresses, "
649 "disabling multicast\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000650 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400651 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200652 } else {
653 int i;
654
David Woodhouseaa21c002007-12-08 20:04:36 +0000655 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400656 CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200657
David Woodhouseaa21c002007-12-08 20:04:36 +0000658 priv->nr_of_multicastmacaddr =
659 lbs_copy_multicast_address(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200660
Holger Schurig9012b282007-05-25 11:27:16 -0400661 lbs_deb_net("multicast addresses: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200662 dev->mc_count);
663
664 for (i = 0; i < dev->mc_count; i++) {
Joe Perches0795af52007-10-03 17:59:30 -0700665 lbs_deb_net("Multicast address %d:%s\n",
666 i, print_mac(mac,
David Woodhouseaa21c002007-12-08 20:04:36 +0000667 priv->multicastlist[i]));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200668 }
Holger Schurig9012b282007-05-25 11:27:16 -0400669 /* send multicast addresses to firmware */
Holger Schurig10078322007-11-15 18:05:47 -0500670 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400671 CMD_MAC_MULTICAST_ADR,
672 CMD_ACT_SET, 0, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200673 NULL);
674 }
675 }
676 }
677
David Woodhouseaa21c002007-12-08 20:04:36 +0000678 if (priv->currentpacketfilter != oldpacketfilter) {
Holger Schurig10078322007-11-15 18:05:47 -0500679 lbs_set_mac_packet_filter(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200680 }
681
Holger Schurig9012b282007-05-25 11:27:16 -0400682 lbs_deb_leave(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200683}
684
685/**
Holger Schurig10078322007-11-15 18:05:47 -0500686 * @brief This function handles the major jobs in the LBS driver.
Holger Schurig9012b282007-05-25 11:27:16 -0400687 * It handles all events generated by firmware, RX data received
688 * from firmware and TX data sent from kernel.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200689 *
Holger Schurig10078322007-11-15 18:05:47 -0500690 * @param data A pointer to lbs_thread structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200691 * @return 0
692 */
Holger Schurig10078322007-11-15 18:05:47 -0500693static int lbs_thread(void *data)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200694{
Dan Williamsfe336152007-08-02 11:32:25 -0400695 struct net_device *dev = data;
Holger Schurig69f90322007-11-23 15:43:44 +0100696 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200697 wait_queue_t wait;
698 u8 ireg = 0;
699
Holger Schurig9012b282007-05-25 11:27:16 -0400700 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200701
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200702 init_waitqueue_entry(&wait, current);
703
Dan Williamsb1b19072007-08-20 11:10:45 -0400704 set_freezable();
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000705
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200706 for (;;) {
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500707 int shouldsleep;
708
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000709 lbs_deb_thread( "main-thread 111: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000710 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200711
Dan Williamsfe336152007-08-02 11:32:25 -0400712 add_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200713 set_current_state(TASK_INTERRUPTIBLE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000714 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000715
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500716 if (priv->surpriseremoved)
717 shouldsleep = 0; /* Bye */
718 else if (priv->psstate == PS_STATE_SLEEP)
719 shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */
720 else if (priv->intcounter)
721 shouldsleep = 0; /* Interrupt pending. Deal with it now */
David Woodhouseb15152a2007-12-11 11:55:37 -0500722 else if (!priv->fw_ready)
723 shouldsleep = 1; /* Firmware not ready. We're waiting for it */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500724 else if (priv->dnld_sent)
725 shouldsleep = 1; /* Something is en route to the device already */
David Woodhouse2eb188a2007-12-09 23:54:27 -0500726 else if (priv->tx_pending_len > 0)
727 shouldsleep = 0; /* We've a packet to send */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500728 else if (priv->cur_cmd)
729 shouldsleep = 1; /* Can't send a command; one already running */
730 else if (!list_empty(&priv->cmdpendingq))
731 shouldsleep = 0; /* We have a command to send */
732 else
733 shouldsleep = 1; /* No command */
734
735 if (shouldsleep) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000736 lbs_deb_thread("main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000737 priv->connect_status, priv->intcounter,
738 priv->psmode, priv->psstate);
739 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200740 schedule();
741 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000742 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200743
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000744 lbs_deb_thread("main-thread 222 (waking up): intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000745 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200746
747 set_current_state(TASK_RUNNING);
Dan Williamsfe336152007-08-02 11:32:25 -0400748 remove_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200749 try_to_freeze();
750
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000751 lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000752 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200753
David Woodhouseaa21c002007-12-08 20:04:36 +0000754 if (kthread_should_stop() || priv->surpriseremoved) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000755 lbs_deb_thread("main-thread: break from main thread: surpriseremoved=0x%x\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000756 priv->surpriseremoved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200757 break;
758 }
759
760
David Woodhouseaa21c002007-12-08 20:04:36 +0000761 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000762
David Woodhouseaa21c002007-12-08 20:04:36 +0000763 if (priv->intcounter) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200764 u8 int_status;
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000765
David Woodhouseaa21c002007-12-08 20:04:36 +0000766 priv->intcounter = 0;
Holger Schurig208fdd22007-05-25 12:17:06 -0400767 int_status = priv->hw_get_int_status(priv, &ireg);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200768
769 if (int_status) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000770 lbs_deb_thread("main-thread: reading HOST_INT_STATUS_REG failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000771 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200772 continue;
773 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000774 priv->hisregcpy |= ireg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200775 }
776
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000777 lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000778 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200779
780 /* command response? */
David Woodhouseaa21c002007-12-08 20:04:36 +0000781 if (priv->hisregcpy & MRVDRV_CMD_UPLD_RDY) {
Holger Schurig9012b282007-05-25 11:27:16 -0400782 lbs_deb_thread("main-thread: cmd response ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200783
David Woodhouseaa21c002007-12-08 20:04:36 +0000784 priv->hisregcpy &= ~MRVDRV_CMD_UPLD_RDY;
785 spin_unlock_irq(&priv->driver_lock);
Holger Schurig10078322007-11-15 18:05:47 -0500786 lbs_process_rx_command(priv);
David Woodhouseaa21c002007-12-08 20:04:36 +0000787 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200788 }
789
790 /* Any Card Event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000791 if (priv->hisregcpy & MRVDRV_CARDEVENT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400792 lbs_deb_thread("main-thread: Card Event Activity\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200793
David Woodhouseaa21c002007-12-08 20:04:36 +0000794 priv->hisregcpy &= ~MRVDRV_CARDEVENT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200795
Holger Schurig208fdd22007-05-25 12:17:06 -0400796 if (priv->hw_read_event_cause(priv)) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000797 lbs_pr_alert("main-thread: hw_read_event_cause failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000798 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200799 continue;
800 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000801 spin_unlock_irq(&priv->driver_lock);
Holger Schurig10078322007-11-15 18:05:47 -0500802 lbs_process_event(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200803 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000804 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200805
David Woodhouseb15152a2007-12-11 11:55:37 -0500806 if (!priv->fw_ready)
807 continue;
808
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200809 /* Check if we need to confirm Sleep Request received previously */
David Woodhouseaa21c002007-12-08 20:04:36 +0000810 if (priv->psstate == PS_STATE_PRE_SLEEP &&
811 !priv->dnld_sent && !priv->cur_cmd) {
812 if (priv->connect_status == LBS_CONNECTED) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000813 lbs_deb_thread("main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p dnld_sent=%d cur_cmd=%p, confirm now\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000814 priv->intcounter, priv->currenttxskb, priv->dnld_sent, priv->cur_cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200815
David Woodhouseaa21c002007-12-08 20:04:36 +0000816 lbs_ps_confirm_sleep(priv, (u16) priv->psmode);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000817 } else {
818 /* workaround for firmware sending
819 * deauth/linkloss event immediately
820 * after sleep request; remove this
821 * after firmware fixes it
822 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000823 priv->psstate = PS_STATE_AWAKE;
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000824 lbs_pr_alert("main-thread: ignore PS_SleepConfirm in non-connected state\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200825 }
826 }
827
828 /* The PS state is changed during processing of Sleep Request
829 * event above
830 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000831 if ((priv->psstate == PS_STATE_SLEEP) ||
832 (priv->psstate == PS_STATE_PRE_SLEEP))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200833 continue;
834
835 /* Execute the next command */
David Woodhouseaa21c002007-12-08 20:04:36 +0000836 if (!priv->dnld_sent && !priv->cur_cmd)
Holger Schurig10078322007-11-15 18:05:47 -0500837 lbs_execute_next_command(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200838
839 /* Wake-up command waiters which can't sleep in
Holger Schurig10078322007-11-15 18:05:47 -0500840 * lbs_prepare_and_send_command
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200841 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000842 if (!list_empty(&priv->cmdpendingq))
843 wake_up_all(&priv->cmd_pending);
David Woodhouse2eb188a2007-12-09 23:54:27 -0500844
845 spin_lock_irq(&priv->driver_lock);
846 if (!priv->dnld_sent && priv->tx_pending_len > 0) {
847 int ret = priv->hw_host_to_card(priv, MVMS_DAT,
848 priv->tx_pending_buf,
849 priv->tx_pending_len);
850 if (ret) {
851 lbs_deb_tx("host_to_card failed %d\n", ret);
852 priv->dnld_sent = DNLD_RES_RECEIVED;
853 }
854 priv->tx_pending_len = 0;
855 if (!priv->currenttxskb) {
856 /* We can wake the queues immediately if we aren't
857 waiting for TX feedback */
858 if (priv->connect_status == LBS_CONNECTED)
859 netif_wake_queue(priv->dev);
860 if (priv->mesh_dev &&
861 priv->mesh_connect_status == LBS_CONNECTED)
862 netif_wake_queue(priv->mesh_dev);
863 }
864 }
865 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200866 }
867
David Woodhouseaa21c002007-12-08 20:04:36 +0000868 del_timer(&priv->command_timer);
869 wake_up_all(&priv->cmd_pending);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200870
Holger Schurig9012b282007-05-25 11:27:16 -0400871 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200872 return 0;
873}
874
875/**
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400876 * @brief This function downloads firmware image, gets
877 * HW spec from firmware and set basic parameters to
878 * firmware.
879 *
Holger Schurig69f90322007-11-23 15:43:44 +0100880 * @param priv A pointer to struct lbs_private structure
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400881 * @return 0 or -1
882 */
Holger Schurig69f90322007-11-23 15:43:44 +0100883static int lbs_setup_firmware(struct lbs_private *priv)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400884{
885 int ret = -1;
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400886 struct cmd_ds_mesh_access mesh_access;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400887
888 lbs_deb_enter(LBS_DEB_FW);
889
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400890 /*
891 * Read MAC address from HW
892 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000893 memset(priv->current_addr, 0xff, ETH_ALEN);
Dan Williams6e66f032007-12-11 12:42:16 -0500894 ret = lbs_update_hw_spec(priv);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400895 if (ret) {
896 ret = -1;
897 goto done;
898 }
899
Holger Schurig10078322007-11-15 18:05:47 -0500900 lbs_set_mac_packet_filter(priv);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400901
Dan Williams8e3c91b2007-12-11 15:50:59 -0500902 ret = lbs_get_data_rate(priv);
903 if (ret < 0) {
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400904 ret = -1;
905 goto done;
906 }
907
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400908 /* Disable mesh autostart */
909 if (priv->mesh_dev) {
910 memset(&mesh_access, 0, sizeof(mesh_access));
911 mesh_access.data[0] = cpu_to_le32(0);
David Woodhouse301eacb2007-12-11 15:23:59 -0500912 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_AUTOSTART_ENABLED,
913 &mesh_access);
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400914 if (ret) {
David Woodhouse23a397a2007-12-11 18:56:42 -0500915 printk("Mesh autostart set failed\n");
916 ret = 0;
917 //ret = -1;
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400918 goto done;
919 }
920 priv->mesh_autostart_enabled = 0;
921 }
922
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400923 ret = 0;
924done:
925 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
926 return ret;
927}
928
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400929/**
930 * This function handles the timeout of command sending.
931 * It will re-send the same command again.
932 */
933static void command_timer_fn(unsigned long data)
934{
Holger Schurig69f90322007-11-23 15:43:44 +0100935 struct lbs_private *priv = (struct lbs_private *)data;
Dan Williamsddac4522007-12-11 13:49:39 -0500936 struct cmd_ctrl_node *node;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400937 unsigned long flags;
938
Dan Williamsddac4522007-12-11 13:49:39 -0500939 node = priv->cur_cmd;
940 if (node == NULL) {
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400941 lbs_deb_fw("ptempnode empty\n");
942 return;
943 }
944
Dan Williamsddac4522007-12-11 13:49:39 -0500945 if (!node->cmdbuf) {
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400946 lbs_deb_fw("cmd is NULL\n");
947 return;
948 }
949
Dan Williamsddac4522007-12-11 13:49:39 -0500950 lbs_deb_fw("command_timer_fn fired, cmd %x\n", node->cmdbuf->command);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400951
David Woodhouseaa21c002007-12-08 20:04:36 +0000952 if (!priv->fw_ready)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400953 return;
954
David Woodhouseaa21c002007-12-08 20:04:36 +0000955 spin_lock_irqsave(&priv->driver_lock, flags);
956 priv->cur_cmd = NULL;
957 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400958
959 lbs_deb_fw("re-sending same command because of timeout\n");
Dan Williamsddac4522007-12-11 13:49:39 -0500960 lbs_queue_cmd(priv, node, 0);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400961
962 wake_up_interruptible(&priv->waitq);
963
964 return;
965}
966
Holger Schurig69f90322007-11-23 15:43:44 +0100967static int lbs_init_adapter(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -0400968{
Dan Williams954ee162007-08-20 11:43:25 -0400969 size_t bufsize;
970 int i, ret = 0;
971
972 /* Allocate buffer to store the BSSID list */
973 bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
David Woodhouseaa21c002007-12-08 20:04:36 +0000974 priv->networks = kzalloc(bufsize, GFP_KERNEL);
975 if (!priv->networks) {
Dan Williams954ee162007-08-20 11:43:25 -0400976 lbs_pr_err("Out of memory allocating beacons\n");
977 ret = -1;
978 goto out;
979 }
980
981 /* Initialize scan result lists */
David Woodhouseaa21c002007-12-08 20:04:36 +0000982 INIT_LIST_HEAD(&priv->network_free_list);
983 INIT_LIST_HEAD(&priv->network_list);
Dan Williams954ee162007-08-20 11:43:25 -0400984 for (i = 0; i < MAX_NETWORK_COUNT; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000985 list_add_tail(&priv->networks[i].list,
986 &priv->network_free_list);
Dan Williams954ee162007-08-20 11:43:25 -0400987 }
988
David Woodhouseaa21c002007-12-08 20:04:36 +0000989 priv->lbs_ps_confirm_sleep.seqnum = cpu_to_le16(++priv->seqnum);
990 priv->lbs_ps_confirm_sleep.command =
Dan Williams954ee162007-08-20 11:43:25 -0400991 cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000992 priv->lbs_ps_confirm_sleep.size =
Dan Williams954ee162007-08-20 11:43:25 -0400993 cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep));
David Woodhouseaa21c002007-12-08 20:04:36 +0000994 priv->lbs_ps_confirm_sleep.action =
Dan Williams954ee162007-08-20 11:43:25 -0400995 cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
996
David Woodhouseaa21c002007-12-08 20:04:36 +0000997 memset(priv->current_addr, 0xff, ETH_ALEN);
Dan Williams954ee162007-08-20 11:43:25 -0400998
David Woodhouseaa21c002007-12-08 20:04:36 +0000999 priv->connect_status = LBS_DISCONNECTED;
1000 priv->mesh_connect_status = LBS_DISCONNECTED;
1001 priv->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1002 priv->mode = IW_MODE_INFRA;
1003 priv->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL;
1004 priv->currentpacketfilter = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
1005 priv->radioon = RADIO_ON;
1006 priv->auto_rate = 1;
1007 priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
1008 priv->psmode = LBS802_11POWERMODECAM;
1009 priv->psstate = PS_STATE_FULL_POWER;
Dan Williams954ee162007-08-20 11:43:25 -04001010
David Woodhouseaa21c002007-12-08 20:04:36 +00001011 mutex_init(&priv->lock);
Dan Williams954ee162007-08-20 11:43:25 -04001012
David Woodhouseaa21c002007-12-08 20:04:36 +00001013 setup_timer(&priv->command_timer, command_timer_fn,
Dan Williams954ee162007-08-20 11:43:25 -04001014 (unsigned long)priv);
1015
David Woodhouseaa21c002007-12-08 20:04:36 +00001016 INIT_LIST_HEAD(&priv->cmdfreeq);
1017 INIT_LIST_HEAD(&priv->cmdpendingq);
Dan Williams954ee162007-08-20 11:43:25 -04001018
David Woodhouseaa21c002007-12-08 20:04:36 +00001019 spin_lock_init(&priv->driver_lock);
1020 init_waitqueue_head(&priv->cmd_pending);
Dan Williams954ee162007-08-20 11:43:25 -04001021
1022 /* Allocate the command buffers */
Holger Schurig10078322007-11-15 18:05:47 -05001023 if (lbs_allocate_cmd_buffer(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001024 lbs_pr_err("Out of memory allocating command buffers\n");
1025 ret = -1;
1026 }
1027
1028out:
1029 return ret;
1030}
1031
Holger Schurig69f90322007-11-23 15:43:44 +01001032static void lbs_free_adapter(struct lbs_private *priv)
Holger Schurigac558ca2007-08-02 11:49:06 -04001033{
Holger Schurigac558ca2007-08-02 11:49:06 -04001034 lbs_deb_fw("free command buffer\n");
Holger Schurig10078322007-11-15 18:05:47 -05001035 lbs_free_cmd_buffer(priv);
Holger Schurigac558ca2007-08-02 11:49:06 -04001036
1037 lbs_deb_fw("free command_timer\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001038 del_timer(&priv->command_timer);
Holger Schurigac558ca2007-08-02 11:49:06 -04001039
1040 lbs_deb_fw("free scan results table\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001041 kfree(priv->networks);
1042 priv->networks = NULL;
Holger Schurigac558ca2007-08-02 11:49:06 -04001043}
1044
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001045/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001046 * @brief This function adds the card. it will probe the
Holger Schurig10078322007-11-15 18:05:47 -05001047 * card, allocate the lbs_priv and initialize the device.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001048 *
1049 * @param card A pointer to card
Holger Schurig69f90322007-11-23 15:43:44 +01001050 * @return A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001051 */
Holger Schurig69f90322007-11-23 15:43:44 +01001052struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001053{
1054 struct net_device *dev = NULL;
Holger Schurig69f90322007-11-23 15:43:44 +01001055 struct lbs_private *priv = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001056
Holger Schurig9012b282007-05-25 11:27:16 -04001057 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001058
1059 /* Allocate an Ethernet device and register it */
Holger Schurig69f90322007-11-23 15:43:44 +01001060 dev = alloc_etherdev(sizeof(struct lbs_private));
1061 if (!dev) {
Holger Schurig9012b282007-05-25 11:27:16 -04001062 lbs_pr_err("init ethX device failed\n");
Dan Williams954ee162007-08-20 11:43:25 -04001063 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064 }
Dan Williams64f104e2007-08-20 11:45:16 -04001065 priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001066
Holger Schurig10078322007-11-15 18:05:47 -05001067 if (lbs_init_adapter(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001068 lbs_pr_err("failed to initialize adapter structure.\n");
1069 goto err_init_adapter;
1070 }
1071
Holger Schurig634b8f42007-05-25 13:05:16 -04001072 priv->dev = dev;
1073 priv->card = card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074 priv->mesh_open = 0;
1075 priv->infra_open = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001076
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001077 /* Setup the OS Interface to our functions */
David Woodhouse8552855f2007-12-10 16:38:18 -05001078 dev->open = lbs_dev_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001079 dev->hard_start_xmit = lbs_hard_start_xmit;
David Woodhouse8552855f2007-12-10 16:38:18 -05001080 dev->stop = lbs_eth_stop;
Holger Schurig10078322007-11-15 18:05:47 -05001081 dev->set_mac_address = lbs_set_mac_address;
1082 dev->tx_timeout = lbs_tx_timeout;
1083 dev->get_stats = lbs_get_stats;
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001084 dev->watchdog_timeo = 5 * HZ;
Holger Schurig10078322007-11-15 18:05:47 -05001085 dev->ethtool_ops = &lbs_ethtool_ops;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001086#ifdef WIRELESS_EXT
Holger Schurig10078322007-11-15 18:05:47 -05001087 dev->wireless_handlers = (struct iw_handler_def *)&lbs_handler_def;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001088#endif
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001089 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
Holger Schurig10078322007-11-15 18:05:47 -05001090 dev->set_multicast_list = lbs_set_multicast_list;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001091
Dan Williams7732ca42007-05-25 13:13:25 -04001092 SET_NETDEV_DEV(dev, dmdev);
1093
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001094 priv->rtap_net_dev = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001095
Dan Williamsfe336152007-08-02 11:32:25 -04001096 lbs_deb_thread("Starting main thread...\n");
1097 init_waitqueue_head(&priv->waitq);
Holger Schurig10078322007-11-15 18:05:47 -05001098 priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
Dan Williamsfe336152007-08-02 11:32:25 -04001099 if (IS_ERR(priv->main_thread)) {
1100 lbs_deb_thread("Error creating main thread.\n");
David Woodhousee7deced2007-12-08 18:29:16 +00001101 goto err_init_adapter;
Dan Williamsfe336152007-08-02 11:32:25 -04001102 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001103
Holger Schurig10078322007-11-15 18:05:47 -05001104 priv->work_thread = create_singlethread_workqueue("lbs_worker");
1105 INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker);
1106 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
1107 INIT_WORK(&priv->sync_channel, lbs_sync_channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001108
David Woodhouse23a397a2007-12-11 18:56:42 -05001109 sprintf(priv->mesh_ssid, "mesh");
1110 priv->mesh_ssid_len = 4;
1111
Dan Williams954ee162007-08-20 11:43:25 -04001112 goto done;
1113
Dan Williams954ee162007-08-20 11:43:25 -04001114err_init_adapter:
Holger Schurig10078322007-11-15 18:05:47 -05001115 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001116 free_netdev(dev);
1117 priv = NULL;
1118
1119done:
1120 lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv);
1121 return priv;
1122}
Holger Schurig10078322007-11-15 18:05:47 -05001123EXPORT_SYMBOL_GPL(lbs_add_card);
Dan Williams954ee162007-08-20 11:43:25 -04001124
1125
Holger Schurig69f90322007-11-23 15:43:44 +01001126int lbs_remove_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001127{
Dan Williams954ee162007-08-20 11:43:25 -04001128 struct net_device *dev = priv->dev;
1129 union iwreq_data wrqu;
1130
1131 lbs_deb_enter(LBS_DEB_MAIN);
1132
David Woodhouse23a397a2007-12-11 18:56:42 -05001133 lbs_remove_mesh(priv);
Holger Schurig10078322007-11-15 18:05:47 -05001134 lbs_remove_rtap(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001135
1136 dev = priv->dev;
Dan Williams954ee162007-08-20 11:43:25 -04001137
1138 cancel_delayed_work(&priv->scan_work);
1139 cancel_delayed_work(&priv->assoc_work);
1140 destroy_workqueue(priv->work_thread);
1141
David Woodhouseaa21c002007-12-08 20:04:36 +00001142 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
1143 priv->psmode = LBS802_11POWERMODECAM;
Holger Schurig10078322007-11-15 18:05:47 -05001144 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001145 }
1146
Dan Williams954ee162007-08-20 11:43:25 -04001147 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
1148 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1149 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
1150
1151 /* Stop the thread servicing the interrupts */
David Woodhouseaa21c002007-12-08 20:04:36 +00001152 priv->surpriseremoved = 1;
Dan Williams954ee162007-08-20 11:43:25 -04001153 kthread_stop(priv->main_thread);
1154
Holger Schurig10078322007-11-15 18:05:47 -05001155 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001156
1157 priv->dev = NULL;
1158 free_netdev(dev);
1159
1160 lbs_deb_leave(LBS_DEB_MAIN);
1161 return 0;
1162}
Holger Schurig10078322007-11-15 18:05:47 -05001163EXPORT_SYMBOL_GPL(lbs_remove_card);
Dan Williams954ee162007-08-20 11:43:25 -04001164
1165
Holger Schurig69f90322007-11-23 15:43:44 +01001166int lbs_start_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001167{
1168 struct net_device *dev = priv->dev;
1169 int ret = -1;
1170
1171 lbs_deb_enter(LBS_DEB_MAIN);
1172
1173 /* poke the firmware */
Holger Schurig10078322007-11-15 18:05:47 -05001174 ret = lbs_setup_firmware(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001175 if (ret)
1176 goto done;
1177
1178 /* init 802.11d */
Holger Schurig10078322007-11-15 18:05:47 -05001179 lbs_init_11d(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001180
1181 if (register_netdev(dev)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001182 lbs_pr_err("cannot register ethX device\n");
Dan Williams954ee162007-08-20 11:43:25 -04001183 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001184 }
David Woodhousee7deced2007-12-08 18:29:16 +00001185 if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
1186 lbs_pr_err("cannot register lbs_rtap attribute\n");
David Woodhouse23a397a2007-12-11 18:56:42 -05001187 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
1188 lbs_pr_err("cannot register lbs_mesh attribute\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001189
Holger Schurig10078322007-11-15 18:05:47 -05001190 lbs_debugfs_init_one(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001191
Dan Williams954ee162007-08-20 11:43:25 -04001192 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001193
Dan Williams954ee162007-08-20 11:43:25 -04001194 ret = 0;
1195
Holger Schurig32a74b72007-05-25 12:04:31 -04001196done:
Dan Williams954ee162007-08-20 11:43:25 -04001197 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
Holger Schurig32a74b72007-05-25 12:04:31 -04001198 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001199}
Holger Schurig10078322007-11-15 18:05:47 -05001200EXPORT_SYMBOL_GPL(lbs_start_card);
Dan Williams954ee162007-08-20 11:43:25 -04001201
1202
Holger Schurig69f90322007-11-23 15:43:44 +01001203int lbs_stop_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001204{
1205 struct net_device *dev = priv->dev;
1206 int ret = -1;
1207 struct cmd_ctrl_node *cmdnode;
1208 unsigned long flags;
1209
1210 lbs_deb_enter(LBS_DEB_MAIN);
1211
1212 netif_stop_queue(priv->dev);
1213 netif_carrier_off(priv->dev);
1214
Holger Schurig10078322007-11-15 18:05:47 -05001215 lbs_debugfs_remove_one(priv);
David Woodhouse10bca0d2007-12-11 12:54:43 -05001216 device_remove_file(&dev->dev, &dev_attr_lbs_rtap);
David Woodhouse23a397a2007-12-11 18:56:42 -05001217 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
Dan Williams954ee162007-08-20 11:43:25 -04001218
1219 /* Flush pending command nodes */
David Woodhouseaa21c002007-12-08 20:04:36 +00001220 spin_lock_irqsave(&priv->driver_lock, flags);
1221 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
Dan Williams954ee162007-08-20 11:43:25 -04001222 cmdnode->cmdwaitqwoken = 1;
1223 wake_up_interruptible(&cmdnode->cmdwait_q);
1224 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001225 spin_unlock_irqrestore(&priv->driver_lock, flags);
Dan Williams954ee162007-08-20 11:43:25 -04001226
1227 unregister_netdev(dev);
1228
1229 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1230 return ret;
1231}
Holger Schurig10078322007-11-15 18:05:47 -05001232EXPORT_SYMBOL_GPL(lbs_stop_card);
Holger Schurig084708b2007-05-25 12:37:58 -04001233
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001234
Holger Schurig78523da2007-05-25 11:49:19 -04001235/**
1236 * @brief This function adds mshX interface
1237 *
Holger Schurig69f90322007-11-23 15:43:44 +01001238 * @param priv A pointer to the struct lbs_private structure
Holger Schurig78523da2007-05-25 11:49:19 -04001239 * @return 0 if successful, -X otherwise
1240 */
David Woodhouse23a397a2007-12-11 18:56:42 -05001241static int lbs_add_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001242{
1243 struct net_device *mesh_dev = NULL;
1244 int ret = 0;
1245
1246 lbs_deb_enter(LBS_DEB_MESH);
1247
1248 /* Allocate a virtual mesh device */
1249 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
1250 lbs_deb_mesh("init mshX device failed\n");
1251 ret = -ENOMEM;
1252 goto done;
1253 }
1254 mesh_dev->priv = priv;
1255 priv->mesh_dev = mesh_dev;
1256
David Woodhouse8552855f2007-12-10 16:38:18 -05001257 mesh_dev->open = lbs_dev_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001258 mesh_dev->hard_start_xmit = lbs_hard_start_xmit;
David Woodhouse8552855f2007-12-10 16:38:18 -05001259 mesh_dev->stop = lbs_mesh_stop;
Holger Schurig10078322007-11-15 18:05:47 -05001260 mesh_dev->get_stats = lbs_get_stats;
1261 mesh_dev->set_mac_address = lbs_set_mac_address;
1262 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
Holger Schurig634b8f42007-05-25 13:05:16 -04001263 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
1264 sizeof(priv->dev->dev_addr));
Holger Schurig78523da2007-05-25 11:49:19 -04001265
David Woodhouse23a397a2007-12-11 18:56:42 -05001266 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
Dan Williams7732ca42007-05-25 13:13:25 -04001267
Holger Schurig78523da2007-05-25 11:49:19 -04001268#ifdef WIRELESS_EXT
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04001269 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
Holger Schurig78523da2007-05-25 11:49:19 -04001270#endif
Holger Schurig78523da2007-05-25 11:49:19 -04001271 /* Register virtual mesh interface */
1272 ret = register_netdev(mesh_dev);
1273 if (ret) {
1274 lbs_pr_err("cannot register mshX virtual interface\n");
1275 goto err_free;
1276 }
1277
Holger Schurig10078322007-11-15 18:05:47 -05001278 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001279 if (ret)
1280 goto err_unregister;
1281
1282 /* Everything successful */
1283 ret = 0;
1284 goto done;
1285
Holger Schurig78523da2007-05-25 11:49:19 -04001286err_unregister:
1287 unregister_netdev(mesh_dev);
1288
1289err_free:
1290 free_netdev(mesh_dev);
1291
1292done:
1293 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
1294 return ret;
1295}
Holger Schurig10078322007-11-15 18:05:47 -05001296EXPORT_SYMBOL_GPL(lbs_add_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001297
Holger Schurig084708b2007-05-25 12:37:58 -04001298
David Woodhouse23a397a2007-12-11 18:56:42 -05001299static void lbs_remove_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001300{
1301 struct net_device *mesh_dev;
1302
Dan Williams954ee162007-08-20 11:43:25 -04001303 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig78523da2007-05-25 11:49:19 -04001304
1305 if (!priv)
1306 goto out;
1307
1308 mesh_dev = priv->mesh_dev;
David Woodhouse23a397a2007-12-11 18:56:42 -05001309 if (!mesh_dev)
1310 goto out;
Holger Schurig78523da2007-05-25 11:49:19 -04001311
1312 netif_stop_queue(mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -04001313 netif_carrier_off(priv->mesh_dev);
Holger Schurig78523da2007-05-25 11:49:19 -04001314
Holger Schurig10078322007-11-15 18:05:47 -05001315 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001316 unregister_netdev(mesh_dev);
1317
David Woodhouse23a397a2007-12-11 18:56:42 -05001318 priv->mesh_dev = NULL;
Holger Schurig78523da2007-05-25 11:49:19 -04001319 free_netdev(mesh_dev);
1320
1321out:
Dan Williams954ee162007-08-20 11:43:25 -04001322 lbs_deb_leave(LBS_DEB_MAIN);
Holger Schurig78523da2007-05-25 11:49:19 -04001323}
Holger Schurig10078322007-11-15 18:05:47 -05001324EXPORT_SYMBOL_GPL(lbs_remove_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001325
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001326/**
1327 * @brief This function finds the CFP in
1328 * region_cfp_table based on region and band parameter.
1329 *
1330 * @param region The region code
1331 * @param band The band
1332 * @param cfp_no A pointer to CFP number
1333 * @return A pointer to CFP
1334 */
Holger Schurig10078322007-11-15 18:05:47 -05001335struct chan_freq_power *lbs_get_region_cfp_table(u8 region, u8 band, int *cfp_no)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001336{
1337 int i, end;
1338
Holger Schurig9012b282007-05-25 11:27:16 -04001339 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001340
Denis Chengff8ac602007-09-02 18:30:18 +08001341 end = ARRAY_SIZE(region_cfp_table);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001342
1343 for (i = 0; i < end ; i++) {
Holger Schurig9012b282007-05-25 11:27:16 -04001344 lbs_deb_main("region_cfp_table[i].region=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001345 region_cfp_table[i].region);
1346 if (region_cfp_table[i].region == region) {
1347 *cfp_no = region_cfp_table[i].cfp_no_BG;
Holger Schurig9012b282007-05-25 11:27:16 -04001348 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001349 return region_cfp_table[i].cfp_BG;
1350 }
1351 }
1352
Holger Schurig9012b282007-05-25 11:27:16 -04001353 lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001354 return NULL;
1355}
1356
Holger Schurig69f90322007-11-23 15:43:44 +01001357int lbs_set_regiontable(struct lbs_private *priv, u8 region, u8 band)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001358{
Holger Schurig9012b282007-05-25 11:27:16 -04001359 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001360 int i = 0;
1361
1362 struct chan_freq_power *cfp;
1363 int cfp_no;
1364
Holger Schurig9012b282007-05-25 11:27:16 -04001365 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001366
David Woodhouseaa21c002007-12-08 20:04:36 +00001367 memset(priv->region_channel, 0, sizeof(priv->region_channel));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001368
1369 {
Holger Schurig10078322007-11-15 18:05:47 -05001370 cfp = lbs_get_region_cfp_table(region, band, &cfp_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001371 if (cfp != NULL) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001372 priv->region_channel[i].nrcfp = cfp_no;
1373 priv->region_channel[i].CFP = cfp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001374 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001375 lbs_deb_main("wrong region code %#x in band B/G\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001376 region);
Holger Schurig9012b282007-05-25 11:27:16 -04001377 ret = -1;
1378 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001379 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001380 priv->region_channel[i].valid = 1;
1381 priv->region_channel[i].region = region;
1382 priv->region_channel[i].band = band;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001383 i++;
1384 }
Holger Schurig9012b282007-05-25 11:27:16 -04001385out:
1386 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1387 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001388}
1389
1390/**
1391 * @brief This function handles the interrupt. it will change PS
1392 * state if applicable. it will wake up main_thread to handle
1393 * the interrupt event as well.
1394 *
1395 * @param dev A pointer to net_device structure
1396 * @return n/a
1397 */
David Woodhouse4f679492007-12-10 14:58:37 -05001398void lbs_interrupt(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001399{
Holger Schuriged37b512007-05-25 11:52:42 -04001400 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001401
David Woodhouse4f679492007-12-10 14:58:37 -05001402 lbs_deb_thread("lbs_interrupt: intcounter=%d\n", priv->intcounter);
1403
1404 if (spin_trylock(&priv->driver_lock)) {
1405 spin_unlock(&priv->driver_lock);
1406 printk(KERN_CRIT "%s called without driver_lock held\n", __func__);
1407 WARN_ON(1);
1408 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001409
David Woodhouseaa21c002007-12-08 20:04:36 +00001410 priv->intcounter++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001411
David Woodhouse4f679492007-12-10 14:58:37 -05001412 if (priv->psstate == PS_STATE_SLEEP)
David Woodhouseaa21c002007-12-08 20:04:36 +00001413 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001414
Dan Williamsfe336152007-08-02 11:32:25 -04001415 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001416
Holger Schuriged37b512007-05-25 11:52:42 -04001417 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001418}
Holger Schurig10078322007-11-15 18:05:47 -05001419EXPORT_SYMBOL_GPL(lbs_interrupt);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001420
Holger Schurig69f90322007-11-23 15:43:44 +01001421int lbs_reset_device(struct lbs_private *priv)
Dan Williamseedc2a32007-08-02 11:36:22 -04001422{
1423 int ret;
1424
1425 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001426 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RESET,
Dan Williamseedc2a32007-08-02 11:36:22 -04001427 CMD_ACT_HALT, 0, 0, NULL);
1428 msleep_interruptible(10);
1429
1430 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1431 return ret;
1432}
Holger Schurig10078322007-11-15 18:05:47 -05001433EXPORT_SYMBOL_GPL(lbs_reset_device);
Dan Williamseedc2a32007-08-02 11:36:22 -04001434
Andres Salomon4fb910f2007-11-20 17:43:45 -05001435static int __init lbs_init_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001436{
Holger Schurig9012b282007-05-25 11:27:16 -04001437 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001438 lbs_debugfs_init();
Holger Schurig084708b2007-05-25 12:37:58 -04001439 lbs_deb_leave(LBS_DEB_MAIN);
1440 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001441}
1442
Andres Salomon4fb910f2007-11-20 17:43:45 -05001443static void __exit lbs_exit_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001444{
Holger Schurig9012b282007-05-25 11:27:16 -04001445 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001446
Holger Schurig10078322007-11-15 18:05:47 -05001447 lbs_debugfs_remove();
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001448
Holger Schurig9012b282007-05-25 11:27:16 -04001449 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001450}
1451
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001452/*
1453 * rtap interface support fuctions
1454 */
1455
Holger Schurig10078322007-11-15 18:05:47 -05001456static int lbs_rtap_open(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001457{
David Woodhouse8552855f2007-12-10 16:38:18 -05001458 /* Yes, _stop_ the queue. Because we don't support injection */
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001459 netif_carrier_off(dev);
1460 netif_stop_queue(dev);
1461 return 0;
1462}
1463
Holger Schurig10078322007-11-15 18:05:47 -05001464static int lbs_rtap_stop(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001465{
1466 return 0;
1467}
1468
Holger Schurig10078322007-11-15 18:05:47 -05001469static int lbs_rtap_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001470{
1471 netif_stop_queue(dev);
David Woodhouse8552855f2007-12-10 16:38:18 -05001472 return NETDEV_TX_BUSY;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001473}
1474
Holger Schurig10078322007-11-15 18:05:47 -05001475static struct net_device_stats *lbs_rtap_get_stats(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001476{
Holger Schurig69f90322007-11-23 15:43:44 +01001477 struct lbs_private *priv = dev->priv;
David Woodhoused9268fb2007-12-09 16:22:21 -05001478 return &priv->stats;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001479}
1480
1481
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001482static void lbs_remove_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001483{
1484 if (priv->rtap_net_dev == NULL)
1485 return;
1486 unregister_netdev(priv->rtap_net_dev);
David Woodhoused9268fb2007-12-09 16:22:21 -05001487 free_netdev(priv->rtap_net_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001488 priv->rtap_net_dev = NULL;
1489}
1490
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001491static int lbs_add_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001492{
1493 int rc = 0;
David Woodhoused9268fb2007-12-09 16:22:21 -05001494 struct net_device *rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001495
1496 if (priv->rtap_net_dev)
1497 return -EPERM;
1498
David Woodhoused9268fb2007-12-09 16:22:21 -05001499 rtap_dev = alloc_netdev(0, "rtap%d", ether_setup);
1500 if (rtap_dev == NULL)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001501 return -ENOMEM;
1502
David Woodhouse121947c2007-12-09 19:54:11 -05001503 memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN);
David Woodhoused9268fb2007-12-09 16:22:21 -05001504 rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP;
1505 rtap_dev->open = lbs_rtap_open;
1506 rtap_dev->stop = lbs_rtap_stop;
1507 rtap_dev->get_stats = lbs_rtap_get_stats;
1508 rtap_dev->hard_start_xmit = lbs_rtap_hard_start_xmit;
1509 rtap_dev->set_multicast_list = lbs_set_multicast_list;
1510 rtap_dev->priv = priv;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001511
David Woodhoused9268fb2007-12-09 16:22:21 -05001512 rc = register_netdev(rtap_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001513 if (rc) {
David Woodhoused9268fb2007-12-09 16:22:21 -05001514 free_netdev(rtap_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001515 return rc;
1516 }
David Woodhoused9268fb2007-12-09 16:22:21 -05001517 priv->rtap_net_dev = rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001518
1519 return 0;
1520}
1521
1522
Holger Schurig10078322007-11-15 18:05:47 -05001523module_init(lbs_init_module);
1524module_exit(lbs_exit_module);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001525
Holger Schurig084708b2007-05-25 12:37:58 -04001526MODULE_DESCRIPTION("Libertas WLAN Driver Library");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001527MODULE_AUTHOR("Marvell International Ltd.");
1528MODULE_LICENSE("GPL");