blob: e333f14dce235041536f5d6c90dda1cffb9fc321 [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>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02009#include <linux/etherdevice.h>
10#include <linux/netdevice.h>
11#include <linux/if_arp.h>
Dan Williamsfe336152007-08-02 11:32:25 -040012#include <linux/kthread.h>
Holger Schurig7919b892008-04-01 14:50:43 +020013#include <linux/kfifo.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"
Holger Schurig245bf202008-04-02 16:27:42 +020023#include "scan.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020024#include "assoc.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 Schurigf539f2e2008-03-26 13:22:11 +010041/* This global structure is used to send the confirm_sleep command as
42 * fast as possible down to the firmware. */
43struct cmd_confirm_sleep confirm_sleep;
44
45
Holger Schurig10078322007-11-15 18:05:47 -050046#define LBS_TX_PWR_DEFAULT 20 /*100mW */
47#define LBS_TX_PWR_US_DEFAULT 20 /*100mW */
48#define LBS_TX_PWR_JP_DEFAULT 16 /*50mW */
49#define LBS_TX_PWR_FR_DEFAULT 20 /*100mW */
50#define LBS_TX_PWR_EMEA_DEFAULT 20 /*100mW */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020051
52/* Format { channel, frequency (MHz), maxtxpower } */
53/* band: 'B/G', region: USA FCC/Canada IC */
54static struct chan_freq_power channel_freq_power_US_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050055 {1, 2412, LBS_TX_PWR_US_DEFAULT},
56 {2, 2417, LBS_TX_PWR_US_DEFAULT},
57 {3, 2422, LBS_TX_PWR_US_DEFAULT},
58 {4, 2427, LBS_TX_PWR_US_DEFAULT},
59 {5, 2432, LBS_TX_PWR_US_DEFAULT},
60 {6, 2437, LBS_TX_PWR_US_DEFAULT},
61 {7, 2442, LBS_TX_PWR_US_DEFAULT},
62 {8, 2447, LBS_TX_PWR_US_DEFAULT},
63 {9, 2452, LBS_TX_PWR_US_DEFAULT},
64 {10, 2457, LBS_TX_PWR_US_DEFAULT},
65 {11, 2462, LBS_TX_PWR_US_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020066};
67
68/* band: 'B/G', region: Europe ETSI */
69static struct chan_freq_power channel_freq_power_EU_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050070 {1, 2412, LBS_TX_PWR_EMEA_DEFAULT},
71 {2, 2417, LBS_TX_PWR_EMEA_DEFAULT},
72 {3, 2422, LBS_TX_PWR_EMEA_DEFAULT},
73 {4, 2427, LBS_TX_PWR_EMEA_DEFAULT},
74 {5, 2432, LBS_TX_PWR_EMEA_DEFAULT},
75 {6, 2437, LBS_TX_PWR_EMEA_DEFAULT},
76 {7, 2442, LBS_TX_PWR_EMEA_DEFAULT},
77 {8, 2447, LBS_TX_PWR_EMEA_DEFAULT},
78 {9, 2452, LBS_TX_PWR_EMEA_DEFAULT},
79 {10, 2457, LBS_TX_PWR_EMEA_DEFAULT},
80 {11, 2462, LBS_TX_PWR_EMEA_DEFAULT},
81 {12, 2467, LBS_TX_PWR_EMEA_DEFAULT},
82 {13, 2472, LBS_TX_PWR_EMEA_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020083};
84
85/* band: 'B/G', region: Spain */
86static struct chan_freq_power channel_freq_power_SPN_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050087 {10, 2457, LBS_TX_PWR_DEFAULT},
88 {11, 2462, LBS_TX_PWR_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020089};
90
91/* band: 'B/G', region: France */
92static struct chan_freq_power channel_freq_power_FR_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050093 {10, 2457, LBS_TX_PWR_FR_DEFAULT},
94 {11, 2462, LBS_TX_PWR_FR_DEFAULT},
95 {12, 2467, LBS_TX_PWR_FR_DEFAULT},
96 {13, 2472, LBS_TX_PWR_FR_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020097};
98
99/* band: 'B/G', region: Japan */
100static struct chan_freq_power channel_freq_power_JPN_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -0500101 {1, 2412, LBS_TX_PWR_JP_DEFAULT},
102 {2, 2417, LBS_TX_PWR_JP_DEFAULT},
103 {3, 2422, LBS_TX_PWR_JP_DEFAULT},
104 {4, 2427, LBS_TX_PWR_JP_DEFAULT},
105 {5, 2432, LBS_TX_PWR_JP_DEFAULT},
106 {6, 2437, LBS_TX_PWR_JP_DEFAULT},
107 {7, 2442, LBS_TX_PWR_JP_DEFAULT},
108 {8, 2447, LBS_TX_PWR_JP_DEFAULT},
109 {9, 2452, LBS_TX_PWR_JP_DEFAULT},
110 {10, 2457, LBS_TX_PWR_JP_DEFAULT},
111 {11, 2462, LBS_TX_PWR_JP_DEFAULT},
112 {12, 2467, LBS_TX_PWR_JP_DEFAULT},
113 {13, 2472, LBS_TX_PWR_JP_DEFAULT},
114 {14, 2484, LBS_TX_PWR_JP_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115};
116
117/**
118 * the structure for channel, frequency and power
119 */
120struct region_cfp_table {
121 u8 region;
122 struct chan_freq_power *cfp_BG;
123 int cfp_no_BG;
124};
125
126/**
127 * the structure for the mapping between region and CFP
128 */
129static struct region_cfp_table region_cfp_table[] = {
130 {0x10, /*US FCC */
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 {0x20, /*CANADA IC */
136 channel_freq_power_US_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800137 ARRAY_SIZE(channel_freq_power_US_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200138 }
139 ,
140 {0x30, /*EU*/ channel_freq_power_EU_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800141 ARRAY_SIZE(channel_freq_power_EU_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200142 }
143 ,
144 {0x31, /*SPAIN*/ channel_freq_power_SPN_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800145 ARRAY_SIZE(channel_freq_power_SPN_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200146 }
147 ,
148 {0x32, /*FRANCE*/ channel_freq_power_FR_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800149 ARRAY_SIZE(channel_freq_power_FR_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200150 }
151 ,
152 {0x40, /*JAPAN*/ channel_freq_power_JPN_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800153 ARRAY_SIZE(channel_freq_power_JPN_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200154 }
155 ,
156/*Add new region here */
157};
158
159/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160 * the table to keep region code
161 */
Holger Schurig10078322007-11-15 18:05:47 -0500162u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200163 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
164
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165/**
Dan Williams8c512762007-08-02 11:40:45 -0400166 * 802.11b/g supported bitrates (in 500Kb/s units)
167 */
Holger Schurig10078322007-11-15 18:05:47 -0500168u8 lbs_bg_rates[MAX_RATES] =
Dan Williams8c512762007-08-02 11:40:45 -0400169 { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
1700x00, 0x00 };
171
172/**
173 * FW rate table. FW refers to rates by their index in this table, not by the
174 * rate value itself. Values of 0x00 are
175 * reserved positions.
176 */
177static u8 fw_data_rates[MAX_RATES] =
178 { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
179 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
180};
181
182/**
183 * @brief use index to get the data rate
184 *
185 * @param idx The index of data rate
186 * @return data rate or 0
187 */
Holger Schurig10078322007-11-15 18:05:47 -0500188u32 lbs_fw_index_to_data_rate(u8 idx)
Dan Williams8c512762007-08-02 11:40:45 -0400189{
190 if (idx >= sizeof(fw_data_rates))
191 idx = 0;
192 return fw_data_rates[idx];
193}
194
195/**
196 * @brief use rate to get the index
197 *
198 * @param rate data rate
199 * @return index or 0
200 */
Holger Schurig10078322007-11-15 18:05:47 -0500201u8 lbs_data_rate_to_fw_index(u32 rate)
Dan Williams8c512762007-08-02 11:40:45 -0400202{
203 u8 i;
204
205 if (!rate)
206 return 0;
207
208 for (i = 0; i < sizeof(fw_data_rates); i++) {
209 if (rate == fw_data_rates[i])
210 return i;
211 }
212 return 0;
213}
214
215/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200216 * Attributes exported through sysfs
217 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200218
219/**
Luis Carlos82fde742007-06-07 16:40:59 -0400220 * @brief Get function for sysfs attribute anycast_mask
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200221 */
Holger Schurig10078322007-11-15 18:05:47 -0500222static ssize_t lbs_anycast_get(struct device *dev,
Dan Williamsb59bb612007-06-18 11:50:43 -0400223 struct device_attribute *attr, char * buf)
224{
David Woodhouse301eacb2007-12-11 15:23:59 -0500225 struct lbs_private *priv = to_net_dev(dev)->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200226 struct cmd_ds_mesh_access mesh_access;
David Woodhouse301eacb2007-12-11 15:23:59 -0500227 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200228
229 memset(&mesh_access, 0, sizeof(mesh_access));
David Woodhouse301eacb2007-12-11 15:23:59 -0500230
231 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
232 if (ret)
233 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234
Luis Carlos82fde742007-06-07 16:40:59 -0400235 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200236}
237
238/**
Luis Carlos82fde742007-06-07 16:40:59 -0400239 * @brief Set function for sysfs attribute anycast_mask
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200240 */
Holger Schurig10078322007-11-15 18:05:47 -0500241static ssize_t lbs_anycast_set(struct device *dev,
Dan Williamsb59bb612007-06-18 11:50:43 -0400242 struct device_attribute *attr, const char * buf, size_t count)
243{
David Woodhouse301eacb2007-12-11 15:23:59 -0500244 struct lbs_private *priv = to_net_dev(dev)->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200245 struct cmd_ds_mesh_access mesh_access;
David Woodhouse981f1872007-05-25 23:36:54 -0400246 uint32_t datum;
David Woodhouse301eacb2007-12-11 15:23:59 -0500247 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200248
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200249 memset(&mesh_access, 0, sizeof(mesh_access));
Luis Carlos82fde742007-06-07 16:40:59 -0400250 sscanf(buf, "%x", &datum);
David Woodhouse981f1872007-05-25 23:36:54 -0400251 mesh_access.data[0] = cpu_to_le32(datum);
252
David Woodhouse301eacb2007-12-11 15:23:59 -0500253 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
254 if (ret)
255 return ret;
256
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200257 return strlen(buf);
258}
259
David Woodhouse2fd6cfe2007-12-11 17:44:10 -0500260static int lbs_add_rtap(struct lbs_private *priv);
261static void lbs_remove_rtap(struct lbs_private *priv);
David Woodhouse23a397a2007-12-11 18:56:42 -0500262static int lbs_add_mesh(struct lbs_private *priv);
263static void lbs_remove_mesh(struct lbs_private *priv);
David Woodhouse7e226272007-12-14 22:53:41 -0500264
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400265
266/**
267 * Get function for sysfs attribute rtap
268 */
Holger Schurig10078322007-11-15 18:05:47 -0500269static ssize_t lbs_rtap_get(struct device *dev,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400270 struct device_attribute *attr, char * buf)
271{
David Woodhousee7deced2007-12-08 18:29:16 +0000272 struct lbs_private *priv = to_net_dev(dev)->priv;
David Woodhouseaa21c002007-12-08 20:04:36 +0000273 return snprintf(buf, 5, "0x%X\n", priv->monitormode);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400274}
275
276/**
277 * Set function for sysfs attribute rtap
278 */
Holger Schurig10078322007-11-15 18:05:47 -0500279static ssize_t lbs_rtap_set(struct device *dev,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400280 struct device_attribute *attr, const char * buf, size_t count)
281{
282 int monitor_mode;
David Woodhousee7deced2007-12-08 18:29:16 +0000283 struct lbs_private *priv = to_net_dev(dev)->priv;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400284
285 sscanf(buf, "%x", &monitor_mode);
Holger Schurigc2b310a2008-03-26 09:57:14 +0100286 if (monitor_mode) {
287 if (priv->monitormode == monitor_mode)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400288 return strlen(buf);
Holger Schurigc2b310a2008-03-26 09:57:14 +0100289 if (!priv->monitormode) {
David Woodhouse8552855f2007-12-10 16:38:18 -0500290 if (priv->infra_open || priv->mesh_open)
291 return -EBUSY;
David Woodhouseaa21c002007-12-08 20:04:36 +0000292 if (priv->mode == IW_MODE_INFRA)
Holger Schurig10078322007-11-15 18:05:47 -0500293 lbs_send_deauthentication(priv);
David Woodhouseaa21c002007-12-08 20:04:36 +0000294 else if (priv->mode == IW_MODE_ADHOC)
Holger Schurig10078322007-11-15 18:05:47 -0500295 lbs_stop_adhoc_network(priv);
296 lbs_add_rtap(priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400297 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000298 priv->monitormode = monitor_mode;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400299 }
300
301 else {
Holger Schurigc2b310a2008-03-26 09:57:14 +0100302 if (!priv->monitormode)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400303 return strlen(buf);
Holger Schurigc2b310a2008-03-26 09:57:14 +0100304 priv->monitormode = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500305 lbs_remove_rtap(priv);
David Woodhousef86a93e2007-12-08 19:46:19 +0000306
David Woodhouseaa21c002007-12-08 20:04:36 +0000307 if (priv->currenttxskb) {
308 dev_kfree_skb_any(priv->currenttxskb);
309 priv->currenttxskb = NULL;
David Woodhousef86a93e2007-12-08 19:46:19 +0000310 }
311
312 /* Wake queues, command thread, etc. */
313 lbs_host_to_card_done(priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400314 }
315
Holger Schurig10078322007-11-15 18:05:47 -0500316 lbs_prepare_and_send_command(priv,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400317 CMD_802_11_MONITOR_MODE, CMD_ACT_SET,
David Woodhouseaa21c002007-12-08 20:04:36 +0000318 CMD_OPTION_WAITFORRSP, 0, &priv->monitormode);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400319 return strlen(buf);
320}
321
322/**
David Woodhouse23a397a2007-12-11 18:56:42 -0500323 * lbs_rtap attribute to be exported per ethX interface
324 * through sysfs (/sys/class/net/ethX/lbs_rtap)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400325 */
David Woodhouse23a397a2007-12-11 18:56:42 -0500326static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get, lbs_rtap_set );
327
328/**
329 * Get function for sysfs attribute mesh
330 */
331static ssize_t lbs_mesh_get(struct device *dev,
332 struct device_attribute *attr, char * buf)
333{
334 struct lbs_private *priv = to_net_dev(dev)->priv;
335 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
336}
337
338/**
339 * Set function for sysfs attribute mesh
340 */
341static ssize_t lbs_mesh_set(struct device *dev,
342 struct device_attribute *attr, const char * buf, size_t count)
343{
344 struct lbs_private *priv = to_net_dev(dev)->priv;
345 int enable;
346 int ret;
347
348 sscanf(buf, "%x", &enable);
349 enable = !!enable;
350 if (enable == !!priv->mesh_dev)
351 return count;
352
David Woodhouse86062132007-12-13 00:32:36 -0500353 ret = lbs_mesh_config(priv, enable, priv->curbssparams.channel);
David Woodhouse23a397a2007-12-11 18:56:42 -0500354 if (ret)
355 return ret;
David Woodhouse7e226272007-12-14 22:53:41 -0500356
David Woodhouse23a397a2007-12-11 18:56:42 -0500357 if (enable)
358 lbs_add_mesh(priv);
359 else
360 lbs_remove_mesh(priv);
361
362 return count;
363}
364
365/**
366 * lbs_mesh attribute to be exported per ethX interface
367 * through sysfs (/sys/class/net/ethX/lbs_mesh)
368 */
369static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400370
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371/**
Luis Carlos82fde742007-06-07 16:40:59 -0400372 * anycast_mask attribute to be exported per mshX interface
373 * through sysfs (/sys/class/net/mshX/anycast_mask)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200374 */
Holger Schurig10078322007-11-15 18:05:47 -0500375static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200376
Holger Schurig10078322007-11-15 18:05:47 -0500377static struct attribute *lbs_mesh_sysfs_entries[] = {
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400378 &dev_attr_anycast_mask.attr,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400379 NULL,
380};
381
Holger Schurig10078322007-11-15 18:05:47 -0500382static struct attribute_group lbs_mesh_attr_group = {
383 .attrs = lbs_mesh_sysfs_entries,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400384};
385
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386/**
David Woodhouse8552855f2007-12-10 16:38:18 -0500387 * @brief This function opens the ethX or mshX interface
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200388 *
389 * @param dev A pointer to net_device structure
David Woodhouse8552855f2007-12-10 16:38:18 -0500390 * @return 0 or -EBUSY if monitor mode active
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391 */
Holger Schurig10078322007-11-15 18:05:47 -0500392static int lbs_dev_open(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200393{
David Woodhouse8552855f2007-12-10 16:38:18 -0500394 struct lbs_private *priv = (struct lbs_private *) dev->priv ;
395 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200396
Holger Schurig61d30022008-01-16 15:59:52 +0100397 lbs_deb_enter(LBS_DEB_NET);
398
David Woodhouse8552855f2007-12-10 16:38:18 -0500399 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400
Holger Schurigc2b310a2008-03-26 09:57:14 +0100401 if (priv->monitormode) {
David Woodhouse8552855f2007-12-10 16:38:18 -0500402 ret = -EBUSY;
403 goto out;
Javier Cardona51d84f52007-05-25 12:06:56 -0400404 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200405
David Woodhouse8552855f2007-12-10 16:38:18 -0500406 if (dev == priv->mesh_dev) {
407 priv->mesh_open = 1;
408 priv->mesh_connect_status = LBS_CONNECTED;
409 netif_carrier_on(dev);
410 } else {
411 priv->infra_open = 1;
David Woodhouse7e226272007-12-14 22:53:41 -0500412
David Woodhouse8552855f2007-12-10 16:38:18 -0500413 if (priv->connect_status == LBS_CONNECTED)
414 netif_carrier_on(dev);
415 else
416 netif_carrier_off(dev);
417 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200418
David Woodhouse8552855f2007-12-10 16:38:18 -0500419 if (!priv->tx_pending_len)
420 netif_wake_queue(dev);
421 out:
Brajesh Dave01d77d82007-11-20 17:44:14 -0500422
David Woodhouse8552855f2007-12-10 16:38:18 -0500423 spin_unlock_irq(&priv->driver_lock);
Holger Schurig61d30022008-01-16 15:59:52 +0100424 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
David Woodhouse8552855f2007-12-10 16:38:18 -0500425 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200426}
427
428/**
429 * @brief This function closes the mshX interface
430 *
431 * @param dev A pointer to net_device structure
432 * @return 0
433 */
David Woodhouse8552855f2007-12-10 16:38:18 -0500434static int lbs_mesh_stop(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200435{
Holger Schurig69f90322007-11-23 15:43:44 +0100436 struct lbs_private *priv = (struct lbs_private *) (dev->priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200437
Holger Schurig61d30022008-01-16 15:59:52 +0100438 lbs_deb_enter(LBS_DEB_MESH);
David Woodhouse8552855f2007-12-10 16:38:18 -0500439 spin_lock_irq(&priv->driver_lock);
440
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200441 priv->mesh_open = 0;
David Woodhouse8552855f2007-12-10 16:38:18 -0500442 priv->mesh_connect_status = LBS_DISCONNECTED;
443
444 netif_stop_queue(dev);
445 netif_carrier_off(dev);
David Woodhouse7e226272007-12-14 22:53:41 -0500446
David Woodhouse8552855f2007-12-10 16:38:18 -0500447 spin_unlock_irq(&priv->driver_lock);
Holger Schurig61d30022008-01-16 15:59:52 +0100448
449 lbs_deb_leave(LBS_DEB_MESH);
David Woodhouse8552855f2007-12-10 16:38:18 -0500450 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200451}
452
453/**
454 * @brief This function closes the ethX interface
455 *
456 * @param dev A pointer to net_device structure
457 * @return 0
458 */
David Woodhouse8552855f2007-12-10 16:38:18 -0500459static int lbs_eth_stop(struct net_device *dev)
Holger Schurig78523da2007-05-25 11:49:19 -0400460{
Holger Schurig69f90322007-11-23 15:43:44 +0100461 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200462
Holger Schurig61d30022008-01-16 15:59:52 +0100463 lbs_deb_enter(LBS_DEB_NET);
464
David Woodhouse8552855f2007-12-10 16:38:18 -0500465 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200466 priv->infra_open = 0;
David Woodhouse8552855f2007-12-10 16:38:18 -0500467 netif_stop_queue(dev);
David Woodhouse8552855f2007-12-10 16:38:18 -0500468 spin_unlock_irq(&priv->driver_lock);
Holger Schurig61d30022008-01-16 15:59:52 +0100469
470 lbs_deb_leave(LBS_DEB_NET);
David Woodhouse8552855f2007-12-10 16:38:18 -0500471 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200472}
473
Holger Schurig10078322007-11-15 18:05:47 -0500474static void lbs_tx_timeout(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200475{
Holger Schurig69f90322007-11-23 15:43:44 +0100476 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200477
Holger Schurig9012b282007-05-25 11:27:16 -0400478 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200479
Holger Schurig9012b282007-05-25 11:27:16 -0400480 lbs_pr_err("tx watch dog timeout\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200482 dev->trans_start = jiffies;
483
Holger Schurig7919b892008-04-01 14:50:43 +0200484 if (priv->currenttxskb)
485 lbs_send_tx_feedback(priv, 0);
486
David Woodhousea63b22b2007-12-08 20:56:44 +0000487 /* XX: Shouldn't we also call into the hw-specific driver
488 to kick it somehow? */
489 lbs_host_to_card_done(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200490
David Woodhouse354eca92007-12-17 19:22:40 -0500491 /* More often than not, this actually happens because the
492 firmware has crapped itself -- rather than just a very
493 busy medium. So send a harmless command, and if/when
494 _that_ times out, we'll kick it in the head. */
495 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
496 0, 0, NULL);
497
Holger Schurig9012b282007-05-25 11:27:16 -0400498 lbs_deb_leave(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200499}
500
David Woodhousee775ed72007-12-06 14:36:11 +0000501void lbs_host_to_card_done(struct lbs_private *priv)
502{
David Woodhousea63b22b2007-12-08 20:56:44 +0000503 unsigned long flags;
504
Holger Schurig61d30022008-01-16 15:59:52 +0100505 lbs_deb_enter(LBS_DEB_THREAD);
506
David Woodhousea63b22b2007-12-08 20:56:44 +0000507 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhousee775ed72007-12-06 14:36:11 +0000508
509 priv->dnld_sent = DNLD_RES_RECEIVED;
510
511 /* Wake main thread if commands are pending */
David Woodhousea27b9f92007-12-12 00:41:51 -0500512 if (!priv->cur_cmd || priv->tx_pending_len > 0)
David Woodhousee775ed72007-12-06 14:36:11 +0000513 wake_up_interruptible(&priv->waitq);
514
David Woodhousea63b22b2007-12-08 20:56:44 +0000515 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig61d30022008-01-16 15:59:52 +0100516 lbs_deb_leave(LBS_DEB_THREAD);
David Woodhousee775ed72007-12-06 14:36:11 +0000517}
518EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
519
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200520/**
521 * @brief This function returns the network statistics
522 *
Holger Schurig69f90322007-11-23 15:43:44 +0100523 * @param dev A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200524 * @return A pointer to net_device_stats structure
525 */
Holger Schurig10078322007-11-15 18:05:47 -0500526static struct net_device_stats *lbs_get_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200527{
Holger Schurig69f90322007-11-23 15:43:44 +0100528 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200529
Holger Schurig61d30022008-01-16 15:59:52 +0100530 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200531 return &priv->stats;
532}
533
Holger Schurig10078322007-11-15 18:05:47 -0500534static int lbs_set_mac_address(struct net_device *dev, void *addr)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200535{
536 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100537 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200538 struct sockaddr *phwaddr = addr;
Holger Schurig2af9f032008-03-26 09:58:32 +0100539 struct cmd_ds_802_11_mac_address cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200540
Holger Schurig9012b282007-05-25 11:27:16 -0400541 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200542
Luis Carlos Cobo Rus0a0d08a2007-05-25 23:05:27 -0400543 /* In case it was called from the mesh device */
Holger Schurig2af9f032008-03-26 09:58:32 +0100544 dev = priv->dev;
Luis Carlos Cobo Rus0a0d08a2007-05-25 23:05:27 -0400545
Holger Schurig2af9f032008-03-26 09:58:32 +0100546 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
547 cmd.action = cpu_to_le16(CMD_ACT_SET);
548 memcpy(cmd.macadd, phwaddr->sa_data, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200549
Holger Schurig2af9f032008-03-26 09:58:32 +0100550 ret = lbs_cmd_with_response(priv, CMD_802_11_MAC_ADDRESS, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200551 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400552 lbs_deb_net("set MAC address failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553 goto done;
554 }
555
Holger Schurig2af9f032008-03-26 09:58:32 +0100556 memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN);
557 memcpy(dev->dev_addr, phwaddr->sa_data, ETH_ALEN);
Holger Schurig78523da2007-05-25 11:49:19 -0400558 if (priv->mesh_dev)
Holger Schurig2af9f032008-03-26 09:58:32 +0100559 memcpy(priv->mesh_dev->dev_addr, phwaddr->sa_data, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200560
561done:
Holger Schurig9012b282007-05-25 11:27:16 -0400562 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200563 return ret;
564}
565
David Woodhouseaa21c002007-12-08 20:04:36 +0000566static int lbs_copy_multicast_address(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567 struct net_device *dev)
568{
569 int i = 0;
570 struct dev_mc_list *mcptr = dev->mc_list;
571
572 for (i = 0; i < dev->mc_count; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000573 memcpy(&priv->multicastlist[i], mcptr->dmi_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200574 mcptr = mcptr->next;
575 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200576 return i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200577}
578
Holger Schurig10078322007-11-15 18:05:47 -0500579static void lbs_set_multicast_list(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200580{
Holger Schurig69f90322007-11-23 15:43:44 +0100581 struct lbs_private *priv = dev->priv;
Holger Schurigd9e97782008-03-12 16:06:43 +0100582 int old_mac_control;
Joe Perches0795af52007-10-03 17:59:30 -0700583 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200584
Holger Schurig9012b282007-05-25 11:27:16 -0400585 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200586
Holger Schurigd9e97782008-03-12 16:06:43 +0100587 old_mac_control = priv->mac_control;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200588
589 if (dev->flags & IFF_PROMISC) {
Holger Schurig9012b282007-05-25 11:27:16 -0400590 lbs_deb_net("enable promiscuous mode\n");
Holger Schurigd9e97782008-03-12 16:06:43 +0100591 priv->mac_control |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400592 CMD_ACT_MAC_PROMISCUOUS_ENABLE;
Holger Schurigd9e97782008-03-12 16:06:43 +0100593 priv->mac_control &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400594 ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE |
595 CMD_ACT_MAC_MULTICAST_ENABLE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200596 } else {
597 /* Multicast */
Holger Schurigd9e97782008-03-12 16:06:43 +0100598 priv->mac_control &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400599 ~CMD_ACT_MAC_PROMISCUOUS_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200600
601 if (dev->flags & IFF_ALLMULTI || dev->mc_count >
602 MRVDRV_MAX_MULTICAST_LIST_SIZE) {
Holger Schurig9012b282007-05-25 11:27:16 -0400603 lbs_deb_net( "enabling all multicast\n");
Holger Schurigd9e97782008-03-12 16:06:43 +0100604 priv->mac_control |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400605 CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
Holger Schurigd9e97782008-03-12 16:06:43 +0100606 priv->mac_control &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400607 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608 } else {
Holger Schurigd9e97782008-03-12 16:06:43 +0100609 priv->mac_control &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400610 ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611
612 if (!dev->mc_count) {
Holger Schurig9012b282007-05-25 11:27:16 -0400613 lbs_deb_net("no multicast addresses, "
614 "disabling multicast\n");
Holger Schurigd9e97782008-03-12 16:06:43 +0100615 priv->mac_control &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400616 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200617 } else {
618 int i;
619
Holger Schurigd9e97782008-03-12 16:06:43 +0100620 priv->mac_control |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400621 CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200622
David Woodhouseaa21c002007-12-08 20:04:36 +0000623 priv->nr_of_multicastmacaddr =
624 lbs_copy_multicast_address(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200625
Holger Schurig9012b282007-05-25 11:27:16 -0400626 lbs_deb_net("multicast addresses: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200627 dev->mc_count);
628
629 for (i = 0; i < dev->mc_count; i++) {
Holger Schurig61d30022008-01-16 15:59:52 +0100630 lbs_deb_net("Multicast address %d: %s\n",
Joe Perches0795af52007-10-03 17:59:30 -0700631 i, print_mac(mac,
David Woodhouseaa21c002007-12-08 20:04:36 +0000632 priv->multicastlist[i]));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200633 }
Holger Schurig9012b282007-05-25 11:27:16 -0400634 /* send multicast addresses to firmware */
Holger Schurig10078322007-11-15 18:05:47 -0500635 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400636 CMD_MAC_MULTICAST_ADR,
637 CMD_ACT_SET, 0, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200638 NULL);
639 }
640 }
641 }
642
Holger Schurigd9e97782008-03-12 16:06:43 +0100643 if (priv->mac_control != old_mac_control)
644 lbs_set_mac_control(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200645
Holger Schurig9012b282007-05-25 11:27:16 -0400646 lbs_deb_leave(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200647}
648
649/**
Holger Schurig10078322007-11-15 18:05:47 -0500650 * @brief This function handles the major jobs in the LBS driver.
Holger Schurig9012b282007-05-25 11:27:16 -0400651 * It handles all events generated by firmware, RX data received
652 * from firmware and TX data sent from kernel.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200653 *
Holger Schurig10078322007-11-15 18:05:47 -0500654 * @param data A pointer to lbs_thread structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200655 * @return 0
656 */
Holger Schurig10078322007-11-15 18:05:47 -0500657static int lbs_thread(void *data)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200658{
Dan Williamsfe336152007-08-02 11:32:25 -0400659 struct net_device *dev = data;
Holger Schurig69f90322007-11-23 15:43:44 +0100660 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200661 wait_queue_t wait;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200662
Holger Schurig9012b282007-05-25 11:27:16 -0400663 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200664
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200665 init_waitqueue_entry(&wait, current);
666
667 for (;;) {
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500668 int shouldsleep;
Holger Schurig7919b892008-04-01 14:50:43 +0200669 u8 resp_idx;
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500670
Holger Schurig7919b892008-04-01 14:50:43 +0200671 lbs_deb_thread("1: currenttxskb %p, dnld_sent %d\n",
672 priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200673
Dan Williamsfe336152007-08-02 11:32:25 -0400674 add_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200675 set_current_state(TASK_INTERRUPTIBLE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000676 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000677
David Woodhoused9f88702007-12-13 21:48:00 -0500678 if (kthread_should_stop())
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500679 shouldsleep = 0; /* Bye */
David Woodhoused9f88702007-12-13 21:48:00 -0500680 else if (priv->surpriseremoved)
681 shouldsleep = 1; /* We need to wait until we're _told_ to die */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500682 else if (priv->psstate == PS_STATE_SLEEP)
683 shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */
David Woodhouse2a345092007-12-15 19:33:43 -0500684 else if (priv->cmd_timed_out)
685 shouldsleep = 0; /* Command timed out. Recover */
David Woodhouseb15152a2007-12-11 11:55:37 -0500686 else if (!priv->fw_ready)
687 shouldsleep = 1; /* Firmware not ready. We're waiting for it */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500688 else if (priv->dnld_sent)
689 shouldsleep = 1; /* Something is en route to the device already */
David Woodhouse2eb188a2007-12-09 23:54:27 -0500690 else if (priv->tx_pending_len > 0)
691 shouldsleep = 0; /* We've a packet to send */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500692 else if (priv->cur_cmd)
693 shouldsleep = 1; /* Can't send a command; one already running */
694 else if (!list_empty(&priv->cmdpendingq))
695 shouldsleep = 0; /* We have a command to send */
Holger Schurig7919b892008-04-01 14:50:43 +0200696 else if (__kfifo_len(priv->event_fifo))
697 shouldsleep = 0; /* We have an event to process */
698 else if (priv->resp_len[priv->resp_idx])
699 shouldsleep = 0; /* We have a command response */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500700 else
701 shouldsleep = 1; /* No command */
702
703 if (shouldsleep) {
Holger Schurig7919b892008-04-01 14:50:43 +0200704 lbs_deb_thread("sleeping, connect_status %d, "
Holger Schurig5f505d92008-04-30 10:50:07 +0200705 "psmode %d, psstate %d\n",
Holger Schurig7919b892008-04-01 14:50:43 +0200706 priv->connect_status,
707 priv->psmode, priv->psstate);
David Woodhouseaa21c002007-12-08 20:04:36 +0000708 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709 schedule();
710 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000711 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200712
Holger Schurig7919b892008-04-01 14:50:43 +0200713 lbs_deb_thread("2: currenttxskb %p, dnld_send %d\n",
714 priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200715
716 set_current_state(TASK_RUNNING);
Dan Williamsfe336152007-08-02 11:32:25 -0400717 remove_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200718
Holger Schurig7919b892008-04-01 14:50:43 +0200719 lbs_deb_thread("3: currenttxskb %p, dnld_sent %d\n",
720 priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200721
David Woodhoused9f88702007-12-13 21:48:00 -0500722 if (kthread_should_stop()) {
Holger Schurig7919b892008-04-01 14:50:43 +0200723 lbs_deb_thread("break from main thread\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200724 break;
725 }
726
David Woodhoused9f88702007-12-13 21:48:00 -0500727 if (priv->surpriseremoved) {
728 lbs_deb_thread("adapter removed; waiting to die...\n");
729 continue;
730 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200731
Holger Schurig7919b892008-04-01 14:50:43 +0200732 lbs_deb_thread("4: currenttxskb %p, dnld_sent %d\n",
733 priv->currenttxskb, priv->dnld_sent);
734
David Woodhouseaa21c002007-12-08 20:04:36 +0000735 spin_lock_irq(&priv->driver_lock);
Holger Schurig7919b892008-04-01 14:50:43 +0200736 /* Process any pending command response */
737 resp_idx = priv->resp_idx;
738 if (priv->resp_len[resp_idx]) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000739 spin_unlock_irq(&priv->driver_lock);
Holger Schurig7919b892008-04-01 14:50:43 +0200740 lbs_process_command_response(priv,
741 priv->resp_buf[resp_idx],
742 priv->resp_len[resp_idx]);
David Woodhouseaa21c002007-12-08 20:04:36 +0000743 spin_lock_irq(&priv->driver_lock);
Holger Schurig7919b892008-04-01 14:50:43 +0200744 priv->resp_len[resp_idx] = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200745 }
Holger Schurig7919b892008-04-01 14:50:43 +0200746 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200747
Holger Schurig7919b892008-04-01 14:50:43 +0200748 /* command timeout stuff */
David Woodhouse2a345092007-12-15 19:33:43 -0500749 if (priv->cmd_timed_out && priv->cur_cmd) {
750 struct cmd_ctrl_node *cmdnode = priv->cur_cmd;
751
752 if (++priv->nr_retries > 10) {
753 lbs_pr_info("Excessive timeouts submitting command %x\n",
754 le16_to_cpu(cmdnode->cmdbuf->command));
755 lbs_complete_command(priv, cmdnode, -ETIMEDOUT);
756 priv->nr_retries = 0;
757 } else {
758 priv->cur_cmd = NULL;
759 lbs_pr_info("requeueing command %x due to timeout (#%d)\n",
760 le16_to_cpu(cmdnode->cmdbuf->command), priv->nr_retries);
761
762 /* Stick it back at the _top_ of the pending queue
763 for immediate resubmission */
764 list_add(&cmdnode->list, &priv->cmdpendingq);
765 }
766 }
767 priv->cmd_timed_out = 0;
768
Holger Schurig7919b892008-04-01 14:50:43 +0200769 /* Process hardware events, e.g. card removed, link lost */
770 spin_lock_irq(&priv->driver_lock);
771 while (__kfifo_len(priv->event_fifo)) {
772 u32 event;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200773
Holger Schurig7919b892008-04-01 14:50:43 +0200774 __kfifo_get(priv->event_fifo, (unsigned char *) &event,
775 sizeof(event));
David Woodhouseaa21c002007-12-08 20:04:36 +0000776 spin_unlock_irq(&priv->driver_lock);
Holger Schurig7919b892008-04-01 14:50:43 +0200777 lbs_process_event(priv, event);
778 spin_lock_irq(&priv->driver_lock);
779 }
780 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200781
David Woodhouseb15152a2007-12-11 11:55:37 -0500782 if (!priv->fw_ready)
783 continue;
784
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200785 /* Check if we need to confirm Sleep Request received previously */
David Woodhouseaa21c002007-12-08 20:04:36 +0000786 if (priv->psstate == PS_STATE_PRE_SLEEP &&
787 !priv->dnld_sent && !priv->cur_cmd) {
788 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig7919b892008-04-01 14:50:43 +0200789 lbs_deb_thread("pre-sleep, currenttxskb %p, "
790 "dnld_sent %d, cur_cmd %p\n",
791 priv->currenttxskb, priv->dnld_sent,
792 priv->cur_cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200793
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100794 lbs_ps_confirm_sleep(priv);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000795 } else {
796 /* workaround for firmware sending
797 * deauth/linkloss event immediately
798 * after sleep request; remove this
799 * after firmware fixes it
800 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000801 priv->psstate = PS_STATE_AWAKE;
Holger Schurig7919b892008-04-01 14:50:43 +0200802 lbs_pr_alert("ignore PS_SleepConfirm in "
803 "non-connected state\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200804 }
805 }
806
807 /* The PS state is changed during processing of Sleep Request
808 * event above
809 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000810 if ((priv->psstate == PS_STATE_SLEEP) ||
811 (priv->psstate == PS_STATE_PRE_SLEEP))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200812 continue;
813
814 /* Execute the next command */
David Woodhouseaa21c002007-12-08 20:04:36 +0000815 if (!priv->dnld_sent && !priv->cur_cmd)
Holger Schurig10078322007-11-15 18:05:47 -0500816 lbs_execute_next_command(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200817
818 /* Wake-up command waiters which can't sleep in
Holger Schurig10078322007-11-15 18:05:47 -0500819 * lbs_prepare_and_send_command
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000821 if (!list_empty(&priv->cmdpendingq))
822 wake_up_all(&priv->cmd_pending);
David Woodhouse2eb188a2007-12-09 23:54:27 -0500823
824 spin_lock_irq(&priv->driver_lock);
825 if (!priv->dnld_sent && priv->tx_pending_len > 0) {
826 int ret = priv->hw_host_to_card(priv, MVMS_DAT,
827 priv->tx_pending_buf,
828 priv->tx_pending_len);
829 if (ret) {
830 lbs_deb_tx("host_to_card failed %d\n", ret);
831 priv->dnld_sent = DNLD_RES_RECEIVED;
832 }
833 priv->tx_pending_len = 0;
834 if (!priv->currenttxskb) {
835 /* We can wake the queues immediately if we aren't
836 waiting for TX feedback */
837 if (priv->connect_status == LBS_CONNECTED)
838 netif_wake_queue(priv->dev);
839 if (priv->mesh_dev &&
840 priv->mesh_connect_status == LBS_CONNECTED)
841 netif_wake_queue(priv->mesh_dev);
842 }
843 }
844 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200845 }
846
David Woodhouseaa21c002007-12-08 20:04:36 +0000847 del_timer(&priv->command_timer);
848 wake_up_all(&priv->cmd_pending);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200849
Holger Schurig9012b282007-05-25 11:27:16 -0400850 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200851 return 0;
852}
853
David Woodhouseab25eca2007-12-12 17:38:56 -0500854static int lbs_suspend_callback(struct lbs_private *priv, unsigned long dummy,
855 struct cmd_header *cmd)
856{
Holger Schurig61d30022008-01-16 15:59:52 +0100857 lbs_deb_enter(LBS_DEB_FW);
David Woodhouseab25eca2007-12-12 17:38:56 -0500858
859 netif_device_detach(priv->dev);
860 if (priv->mesh_dev)
861 netif_device_detach(priv->mesh_dev);
862
863 priv->fw_ready = 0;
Holger Schurig61d30022008-01-16 15:59:52 +0100864 lbs_deb_leave(LBS_DEB_FW);
David Woodhouseab25eca2007-12-12 17:38:56 -0500865 return 0;
866}
867
David Woodhouseab25eca2007-12-12 17:38:56 -0500868int lbs_suspend(struct lbs_private *priv)
869{
870 struct cmd_header cmd;
871 int ret;
872
Holger Schurig61d30022008-01-16 15:59:52 +0100873 lbs_deb_enter(LBS_DEB_FW);
874
David Woodhouse506e9022007-12-12 20:06:06 -0500875 if (priv->wol_criteria == 0xffffffff) {
876 lbs_pr_info("Suspend attempt without configuring wake params!\n");
877 return -EINVAL;
878 }
879
David Woodhouseab25eca2007-12-12 17:38:56 -0500880 memset(&cmd, 0, sizeof(cmd));
David Woodhouse7e226272007-12-14 22:53:41 -0500881
David Woodhouseab25eca2007-12-12 17:38:56 -0500882 ret = __lbs_cmd(priv, CMD_802_11_HOST_SLEEP_ACTIVATE, &cmd,
883 sizeof(cmd), lbs_suspend_callback, 0);
884 if (ret)
885 lbs_pr_info("HOST_SLEEP_ACTIVATE failed: %d\n", ret);
886
Holger Schurig61d30022008-01-16 15:59:52 +0100887 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
David Woodhouseab25eca2007-12-12 17:38:56 -0500888 return ret;
889}
890EXPORT_SYMBOL_GPL(lbs_suspend);
891
Holger Schuriga63e5cb2008-04-30 10:50:39 +0200892void lbs_resume(struct lbs_private *priv)
David Woodhouseab25eca2007-12-12 17:38:56 -0500893{
Holger Schurig61d30022008-01-16 15:59:52 +0100894 lbs_deb_enter(LBS_DEB_FW);
895
David Woodhouseab25eca2007-12-12 17:38:56 -0500896 priv->fw_ready = 1;
897
898 /* Firmware doesn't seem to give us RX packets any more
899 until we send it some command. Might as well update */
900 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
901 0, 0, NULL);
902
903 netif_device_attach(priv->dev);
904 if (priv->mesh_dev)
905 netif_device_attach(priv->mesh_dev);
906
Holger Schurig61d30022008-01-16 15:59:52 +0100907 lbs_deb_leave(LBS_DEB_FW);
David Woodhouseab25eca2007-12-12 17:38:56 -0500908}
909EXPORT_SYMBOL_GPL(lbs_resume);
910
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200911/**
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400912 * @brief This function downloads firmware image, gets
913 * HW spec from firmware and set basic parameters to
914 * firmware.
915 *
Holger Schurig69f90322007-11-23 15:43:44 +0100916 * @param priv A pointer to struct lbs_private structure
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400917 * @return 0 or -1
918 */
Holger Schurig69f90322007-11-23 15:43:44 +0100919static int lbs_setup_firmware(struct lbs_private *priv)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400920{
921 int ret = -1;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400922
923 lbs_deb_enter(LBS_DEB_FW);
924
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400925 /*
926 * Read MAC address from HW
927 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000928 memset(priv->current_addr, 0xff, ETH_ALEN);
Dan Williams6e66f032007-12-11 12:42:16 -0500929 ret = lbs_update_hw_spec(priv);
Holger Schurigef85ad52008-05-14 16:27:18 +0200930 if (ret)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400931 goto done;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400932
Holger Schurigd9e97782008-03-12 16:06:43 +0100933 lbs_set_mac_control(priv);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400934done:
935 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
936 return ret;
937}
938
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400939/**
940 * This function handles the timeout of command sending.
941 * It will re-send the same command again.
942 */
943static void command_timer_fn(unsigned long data)
944{
Holger Schurig69f90322007-11-23 15:43:44 +0100945 struct lbs_private *priv = (struct lbs_private *)data;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400946 unsigned long flags;
947
Holger Schurig61d30022008-01-16 15:59:52 +0100948 lbs_deb_enter(LBS_DEB_CMD);
David Woodhouseaa21c002007-12-08 20:04:36 +0000949 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400950
David Woodhouse2a345092007-12-15 19:33:43 -0500951 if (!priv->cur_cmd) {
952 lbs_pr_info("Command timer expired; no pending command\n");
953 goto out;
954 }
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400955
David Woodhouse2a345092007-12-15 19:33:43 -0500956 lbs_pr_info("Command %x timed out\n", le16_to_cpu(priv->cur_cmd->cmdbuf->command));
957
958 priv->cmd_timed_out = 1;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400959 wake_up_interruptible(&priv->waitq);
Holger Schurig61d30022008-01-16 15:59:52 +0100960out:
David Woodhouse2a345092007-12-15 19:33:43 -0500961 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig61d30022008-01-16 15:59:52 +0100962 lbs_deb_leave(LBS_DEB_CMD);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400963}
964
Holger Schurige2268682008-01-28 17:26:28 +0100965static void lbs_sync_channel_worker(struct work_struct *work)
966{
967 struct lbs_private *priv = container_of(work, struct lbs_private,
968 sync_channel);
969
970 lbs_deb_enter(LBS_DEB_MAIN);
971 if (lbs_update_channel(priv))
972 lbs_pr_info("Channel synchronization failed.");
973 lbs_deb_leave(LBS_DEB_MAIN);
974}
975
976
Holger Schurig69f90322007-11-23 15:43:44 +0100977static int lbs_init_adapter(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -0400978{
Dan Williams954ee162007-08-20 11:43:25 -0400979 size_t bufsize;
980 int i, ret = 0;
981
Holger Schurig61d30022008-01-16 15:59:52 +0100982 lbs_deb_enter(LBS_DEB_MAIN);
983
Dan Williams954ee162007-08-20 11:43:25 -0400984 /* Allocate buffer to store the BSSID list */
985 bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
David Woodhouseaa21c002007-12-08 20:04:36 +0000986 priv->networks = kzalloc(bufsize, GFP_KERNEL);
987 if (!priv->networks) {
Dan Williams954ee162007-08-20 11:43:25 -0400988 lbs_pr_err("Out of memory allocating beacons\n");
989 ret = -1;
990 goto out;
991 }
992
993 /* Initialize scan result lists */
David Woodhouseaa21c002007-12-08 20:04:36 +0000994 INIT_LIST_HEAD(&priv->network_free_list);
995 INIT_LIST_HEAD(&priv->network_list);
Dan Williams954ee162007-08-20 11:43:25 -0400996 for (i = 0; i < MAX_NETWORK_COUNT; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000997 list_add_tail(&priv->networks[i].list,
998 &priv->network_free_list);
Dan Williams954ee162007-08-20 11:43:25 -0400999 }
1000
David Woodhouseaa21c002007-12-08 20:04:36 +00001001 memset(priv->current_addr, 0xff, ETH_ALEN);
Dan Williams954ee162007-08-20 11:43:25 -04001002
David Woodhouseaa21c002007-12-08 20:04:36 +00001003 priv->connect_status = LBS_DISCONNECTED;
1004 priv->mesh_connect_status = LBS_DISCONNECTED;
1005 priv->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1006 priv->mode = IW_MODE_INFRA;
1007 priv->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL;
Holger Schurigd9e97782008-03-12 16:06:43 +01001008 priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
David Woodhouseaa21c002007-12-08 20:04:36 +00001009 priv->radioon = RADIO_ON;
1010 priv->auto_rate = 1;
1011 priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
1012 priv->psmode = LBS802_11POWERMODECAM;
1013 priv->psstate = PS_STATE_FULL_POWER;
Dan Williams954ee162007-08-20 11:43:25 -04001014
David Woodhouseaa21c002007-12-08 20:04:36 +00001015 mutex_init(&priv->lock);
Dan Williams954ee162007-08-20 11:43:25 -04001016
David Woodhouseaa21c002007-12-08 20:04:36 +00001017 setup_timer(&priv->command_timer, command_timer_fn,
Holger Schurig61d30022008-01-16 15:59:52 +01001018 (unsigned long)priv);
Dan Williams954ee162007-08-20 11:43:25 -04001019
David Woodhouseaa21c002007-12-08 20:04:36 +00001020 INIT_LIST_HEAD(&priv->cmdfreeq);
1021 INIT_LIST_HEAD(&priv->cmdpendingq);
Dan Williams954ee162007-08-20 11:43:25 -04001022
David Woodhouseaa21c002007-12-08 20:04:36 +00001023 spin_lock_init(&priv->driver_lock);
1024 init_waitqueue_head(&priv->cmd_pending);
Dan Williams954ee162007-08-20 11:43:25 -04001025
1026 /* Allocate the command buffers */
Holger Schurig10078322007-11-15 18:05:47 -05001027 if (lbs_allocate_cmd_buffer(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001028 lbs_pr_err("Out of memory allocating command buffers\n");
Holger Schurig7919b892008-04-01 14:50:43 +02001029 ret = -ENOMEM;
1030 goto out;
1031 }
1032 priv->resp_idx = 0;
1033 priv->resp_len[0] = priv->resp_len[1] = 0;
1034
1035 /* Create the event FIFO */
1036 priv->event_fifo = kfifo_alloc(sizeof(u32) * 16, GFP_KERNEL, NULL);
1037 if (IS_ERR(priv->event_fifo)) {
1038 lbs_pr_err("Out of memory allocating event FIFO buffer\n");
1039 ret = -ENOMEM;
1040 goto out;
Dan Williams954ee162007-08-20 11:43:25 -04001041 }
1042
1043out:
Holger Schurig61d30022008-01-16 15:59:52 +01001044 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1045
Dan Williams954ee162007-08-20 11:43:25 -04001046 return ret;
1047}
1048
Holger Schurig69f90322007-11-23 15:43:44 +01001049static void lbs_free_adapter(struct lbs_private *priv)
Holger Schurigac558ca2007-08-02 11:49:06 -04001050{
Holger Schurig61d30022008-01-16 15:59:52 +01001051 lbs_deb_enter(LBS_DEB_MAIN);
1052
Holger Schurig10078322007-11-15 18:05:47 -05001053 lbs_free_cmd_buffer(priv);
Holger Schurig7919b892008-04-01 14:50:43 +02001054 if (priv->event_fifo)
1055 kfifo_free(priv->event_fifo);
David Woodhouseaa21c002007-12-08 20:04:36 +00001056 del_timer(&priv->command_timer);
David Woodhouseaa21c002007-12-08 20:04:36 +00001057 kfree(priv->networks);
1058 priv->networks = NULL;
Holger Schurig61d30022008-01-16 15:59:52 +01001059
1060 lbs_deb_leave(LBS_DEB_MAIN);
Holger Schurigac558ca2007-08-02 11:49:06 -04001061}
1062
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001063/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064 * @brief This function adds the card. it will probe the
Holger Schurig10078322007-11-15 18:05:47 -05001065 * card, allocate the lbs_priv and initialize the device.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001066 *
1067 * @param card A pointer to card
Holger Schurig69f90322007-11-23 15:43:44 +01001068 * @return A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001069 */
Holger Schurig69f90322007-11-23 15:43:44 +01001070struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001071{
1072 struct net_device *dev = NULL;
Holger Schurig69f90322007-11-23 15:43:44 +01001073 struct lbs_private *priv = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074
Holger Schurig61d30022008-01-16 15:59:52 +01001075 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001076
1077 /* Allocate an Ethernet device and register it */
Holger Schurig69f90322007-11-23 15:43:44 +01001078 dev = alloc_etherdev(sizeof(struct lbs_private));
1079 if (!dev) {
Holger Schurig9012b282007-05-25 11:27:16 -04001080 lbs_pr_err("init ethX device failed\n");
Dan Williams954ee162007-08-20 11:43:25 -04001081 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001082 }
Dan Williams64f104e2007-08-20 11:45:16 -04001083 priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001084
Holger Schurig10078322007-11-15 18:05:47 -05001085 if (lbs_init_adapter(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001086 lbs_pr_err("failed to initialize adapter structure.\n");
1087 goto err_init_adapter;
1088 }
1089
Holger Schurig634b8f42007-05-25 13:05:16 -04001090 priv->dev = dev;
1091 priv->card = card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001092 priv->mesh_open = 0;
1093 priv->infra_open = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001094
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001095 /* Setup the OS Interface to our functions */
David Woodhouse8552855f2007-12-10 16:38:18 -05001096 dev->open = lbs_dev_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001097 dev->hard_start_xmit = lbs_hard_start_xmit;
David Woodhouse8552855f2007-12-10 16:38:18 -05001098 dev->stop = lbs_eth_stop;
Holger Schurig10078322007-11-15 18:05:47 -05001099 dev->set_mac_address = lbs_set_mac_address;
1100 dev->tx_timeout = lbs_tx_timeout;
1101 dev->get_stats = lbs_get_stats;
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001102 dev->watchdog_timeo = 5 * HZ;
Holger Schurig10078322007-11-15 18:05:47 -05001103 dev->ethtool_ops = &lbs_ethtool_ops;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001104#ifdef WIRELESS_EXT
Holger Schurig10078322007-11-15 18:05:47 -05001105 dev->wireless_handlers = (struct iw_handler_def *)&lbs_handler_def;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001106#endif
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001107 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
Holger Schurig10078322007-11-15 18:05:47 -05001108 dev->set_multicast_list = lbs_set_multicast_list;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001109
Dan Williams7732ca42007-05-25 13:13:25 -04001110 SET_NETDEV_DEV(dev, dmdev);
1111
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001112 priv->rtap_net_dev = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001113
Dan Williamsfe336152007-08-02 11:32:25 -04001114 lbs_deb_thread("Starting main thread...\n");
1115 init_waitqueue_head(&priv->waitq);
Holger Schurig10078322007-11-15 18:05:47 -05001116 priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
Dan Williamsfe336152007-08-02 11:32:25 -04001117 if (IS_ERR(priv->main_thread)) {
1118 lbs_deb_thread("Error creating main thread.\n");
David Woodhousee7deced2007-12-08 18:29:16 +00001119 goto err_init_adapter;
Dan Williamsfe336152007-08-02 11:32:25 -04001120 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001121
Holger Schurig10078322007-11-15 18:05:47 -05001122 priv->work_thread = create_singlethread_workqueue("lbs_worker");
1123 INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker);
1124 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
Holger Schurige2268682008-01-28 17:26:28 +01001125 INIT_WORK(&priv->sync_channel, lbs_sync_channel_worker);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001126
David Woodhouse23a397a2007-12-11 18:56:42 -05001127 sprintf(priv->mesh_ssid, "mesh");
1128 priv->mesh_ssid_len = 4;
1129
David Woodhouse506e9022007-12-12 20:06:06 -05001130 priv->wol_criteria = 0xffffffff;
1131 priv->wol_gpio = 0xff;
1132
Dan Williams954ee162007-08-20 11:43:25 -04001133 goto done;
1134
Dan Williams954ee162007-08-20 11:43:25 -04001135err_init_adapter:
Holger Schurig10078322007-11-15 18:05:47 -05001136 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001137 free_netdev(dev);
1138 priv = NULL;
1139
1140done:
Holger Schurig61d30022008-01-16 15:59:52 +01001141 lbs_deb_leave_args(LBS_DEB_MAIN, "priv %p", priv);
Dan Williams954ee162007-08-20 11:43:25 -04001142 return priv;
1143}
Holger Schurig10078322007-11-15 18:05:47 -05001144EXPORT_SYMBOL_GPL(lbs_add_card);
Dan Williams954ee162007-08-20 11:43:25 -04001145
1146
Holger Schuriga63e5cb2008-04-30 10:50:39 +02001147void lbs_remove_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001148{
Dan Williams954ee162007-08-20 11:43:25 -04001149 struct net_device *dev = priv->dev;
1150 union iwreq_data wrqu;
1151
1152 lbs_deb_enter(LBS_DEB_MAIN);
1153
David Woodhouse23a397a2007-12-11 18:56:42 -05001154 lbs_remove_mesh(priv);
Holger Schurig10078322007-11-15 18:05:47 -05001155 lbs_remove_rtap(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001156
1157 dev = priv->dev;
Dan Williams954ee162007-08-20 11:43:25 -04001158
Holger Schurig652e3f22008-04-30 10:51:15 +02001159 cancel_delayed_work_sync(&priv->scan_work);
1160 cancel_delayed_work_sync(&priv->assoc_work);
Dan Williams954ee162007-08-20 11:43:25 -04001161 destroy_workqueue(priv->work_thread);
1162
David Woodhouseaa21c002007-12-08 20:04:36 +00001163 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
1164 priv->psmode = LBS802_11POWERMODECAM;
Holger Schurig10078322007-11-15 18:05:47 -05001165 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001166 }
1167
Dan Williams954ee162007-08-20 11:43:25 -04001168 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
1169 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1170 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
1171
1172 /* Stop the thread servicing the interrupts */
David Woodhouseaa21c002007-12-08 20:04:36 +00001173 priv->surpriseremoved = 1;
Dan Williams954ee162007-08-20 11:43:25 -04001174 kthread_stop(priv->main_thread);
1175
Holger Schurig10078322007-11-15 18:05:47 -05001176 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001177
1178 priv->dev = NULL;
1179 free_netdev(dev);
1180
1181 lbs_deb_leave(LBS_DEB_MAIN);
Dan Williams954ee162007-08-20 11:43:25 -04001182}
Holger Schurig10078322007-11-15 18:05:47 -05001183EXPORT_SYMBOL_GPL(lbs_remove_card);
Dan Williams954ee162007-08-20 11:43:25 -04001184
1185
Holger Schurig69f90322007-11-23 15:43:44 +01001186int lbs_start_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001187{
1188 struct net_device *dev = priv->dev;
1189 int ret = -1;
1190
1191 lbs_deb_enter(LBS_DEB_MAIN);
1192
1193 /* poke the firmware */
Holger Schurig10078322007-11-15 18:05:47 -05001194 ret = lbs_setup_firmware(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001195 if (ret)
1196 goto done;
1197
1198 /* init 802.11d */
Holger Schurig10078322007-11-15 18:05:47 -05001199 lbs_init_11d(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001200
1201 if (register_netdev(dev)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001202 lbs_pr_err("cannot register ethX device\n");
Dan Williams954ee162007-08-20 11:43:25 -04001203 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001204 }
David Woodhousee7deced2007-12-08 18:29:16 +00001205 if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
1206 lbs_pr_err("cannot register lbs_rtap attribute\n");
David Woodhouse020f3d02007-12-12 23:29:13 -05001207
David Woodhouse020f3d02007-12-12 23:29:13 -05001208 lbs_update_channel(priv);
David Woodhouse020f3d02007-12-12 23:29:13 -05001209
Holger Schurigc9d1be362008-01-16 15:57:44 +01001210 /* 5.0.16p0 is known to NOT support any mesh */
1211 if (priv->fwrelease > 0x05001000) {
1212 /* Enable mesh, if supported, and work out which TLV it uses.
1213 0x100 + 291 is an unofficial value used in 5.110.20.pXX
1214 0x100 + 37 is the official value used in 5.110.21.pXX
1215 but we check them in that order because 20.pXX doesn't
1216 give an error -- it just silently fails. */
1217
1218 /* 5.110.20.pXX firmware will fail the command if the channel
1219 doesn't match the existing channel. But only if the TLV
1220 is correct. If the channel is wrong, _BOTH_ versions will
1221 give an error to 0x100+291, and allow 0x100+37 to succeed.
1222 It's just that 5.110.20.pXX will not have done anything
1223 useful */
1224
1225 priv->mesh_tlv = 0x100 + 291;
1226 if (lbs_mesh_config(priv, 1, priv->curbssparams.channel)) {
1227 priv->mesh_tlv = 0x100 + 37;
1228 if (lbs_mesh_config(priv, 1, priv->curbssparams.channel))
1229 priv->mesh_tlv = 0;
1230 }
1231 if (priv->mesh_tlv) {
1232 lbs_add_mesh(priv);
1233
1234 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
1235 lbs_pr_err("cannot register lbs_mesh attribute\n");
1236 }
David Woodhouse020f3d02007-12-12 23:29:13 -05001237 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001238
Holger Schurig10078322007-11-15 18:05:47 -05001239 lbs_debugfs_init_one(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001240
Dan Williams954ee162007-08-20 11:43:25 -04001241 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001242
Dan Williams954ee162007-08-20 11:43:25 -04001243 ret = 0;
1244
Holger Schurig32a74b72007-05-25 12:04:31 -04001245done:
Dan Williams954ee162007-08-20 11:43:25 -04001246 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
Holger Schurig32a74b72007-05-25 12:04:31 -04001247 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001248}
Holger Schurig10078322007-11-15 18:05:47 -05001249EXPORT_SYMBOL_GPL(lbs_start_card);
Dan Williams954ee162007-08-20 11:43:25 -04001250
1251
Holger Schuriga63e5cb2008-04-30 10:50:39 +02001252void lbs_stop_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001253{
1254 struct net_device *dev = priv->dev;
Dan Williams954ee162007-08-20 11:43:25 -04001255 struct cmd_ctrl_node *cmdnode;
1256 unsigned long flags;
1257
1258 lbs_deb_enter(LBS_DEB_MAIN);
1259
Holger Schurig652e3f22008-04-30 10:51:15 +02001260 if (!priv)
1261 goto out;
1262
Dan Williams954ee162007-08-20 11:43:25 -04001263 netif_stop_queue(priv->dev);
1264 netif_carrier_off(priv->dev);
1265
Holger Schurig10078322007-11-15 18:05:47 -05001266 lbs_debugfs_remove_one(priv);
David Woodhouse10bca0d2007-12-11 12:54:43 -05001267 device_remove_file(&dev->dev, &dev_attr_lbs_rtap);
David Woodhouse020f3d02007-12-12 23:29:13 -05001268 if (priv->mesh_tlv)
1269 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
Dan Williams954ee162007-08-20 11:43:25 -04001270
1271 /* Flush pending command nodes */
Holger Schurig652e3f22008-04-30 10:51:15 +02001272 del_timer_sync(&priv->command_timer);
David Woodhouseaa21c002007-12-08 20:04:36 +00001273 spin_lock_irqsave(&priv->driver_lock, flags);
1274 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
David Woodhouseae125bf2007-12-15 04:22:52 -05001275 cmdnode->result = -ENOENT;
Dan Williams954ee162007-08-20 11:43:25 -04001276 cmdnode->cmdwaitqwoken = 1;
1277 wake_up_interruptible(&cmdnode->cmdwait_q);
1278 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001279 spin_unlock_irqrestore(&priv->driver_lock, flags);
Dan Williams954ee162007-08-20 11:43:25 -04001280
1281 unregister_netdev(dev);
1282
Holger Schurig652e3f22008-04-30 10:51:15 +02001283out:
Holger Schuriga63e5cb2008-04-30 10:50:39 +02001284 lbs_deb_leave(LBS_DEB_MAIN);
Dan Williams954ee162007-08-20 11:43:25 -04001285}
Holger Schurig10078322007-11-15 18:05:47 -05001286EXPORT_SYMBOL_GPL(lbs_stop_card);
Holger Schurig084708b2007-05-25 12:37:58 -04001287
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001288
Holger Schurig78523da2007-05-25 11:49:19 -04001289/**
1290 * @brief This function adds mshX interface
1291 *
Holger Schurig69f90322007-11-23 15:43:44 +01001292 * @param priv A pointer to the struct lbs_private structure
Holger Schurig78523da2007-05-25 11:49:19 -04001293 * @return 0 if successful, -X otherwise
1294 */
David Woodhouse23a397a2007-12-11 18:56:42 -05001295static int lbs_add_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001296{
1297 struct net_device *mesh_dev = NULL;
1298 int ret = 0;
1299
1300 lbs_deb_enter(LBS_DEB_MESH);
1301
1302 /* Allocate a virtual mesh device */
1303 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
1304 lbs_deb_mesh("init mshX device failed\n");
1305 ret = -ENOMEM;
1306 goto done;
1307 }
1308 mesh_dev->priv = priv;
1309 priv->mesh_dev = mesh_dev;
1310
David Woodhouse8552855f2007-12-10 16:38:18 -05001311 mesh_dev->open = lbs_dev_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001312 mesh_dev->hard_start_xmit = lbs_hard_start_xmit;
David Woodhouse8552855f2007-12-10 16:38:18 -05001313 mesh_dev->stop = lbs_mesh_stop;
Holger Schurig10078322007-11-15 18:05:47 -05001314 mesh_dev->get_stats = lbs_get_stats;
1315 mesh_dev->set_mac_address = lbs_set_mac_address;
1316 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
Holger Schurig634b8f42007-05-25 13:05:16 -04001317 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
1318 sizeof(priv->dev->dev_addr));
Holger Schurig78523da2007-05-25 11:49:19 -04001319
David Woodhouse23a397a2007-12-11 18:56:42 -05001320 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
Dan Williams7732ca42007-05-25 13:13:25 -04001321
Holger Schurig78523da2007-05-25 11:49:19 -04001322#ifdef WIRELESS_EXT
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04001323 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
Holger Schurig78523da2007-05-25 11:49:19 -04001324#endif
Holger Schurig78523da2007-05-25 11:49:19 -04001325 /* Register virtual mesh interface */
1326 ret = register_netdev(mesh_dev);
1327 if (ret) {
1328 lbs_pr_err("cannot register mshX virtual interface\n");
1329 goto err_free;
1330 }
1331
Holger Schurig10078322007-11-15 18:05:47 -05001332 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001333 if (ret)
1334 goto err_unregister;
1335
1336 /* Everything successful */
1337 ret = 0;
1338 goto done;
1339
Holger Schurig78523da2007-05-25 11:49:19 -04001340err_unregister:
1341 unregister_netdev(mesh_dev);
1342
1343err_free:
1344 free_netdev(mesh_dev);
1345
1346done:
1347 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
1348 return ret;
1349}
Holger Schurig084708b2007-05-25 12:37:58 -04001350
David Woodhouse23a397a2007-12-11 18:56:42 -05001351static void lbs_remove_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001352{
1353 struct net_device *mesh_dev;
1354
Holger Schurig78523da2007-05-25 11:49:19 -04001355
1356 mesh_dev = priv->mesh_dev;
David Woodhouse23a397a2007-12-11 18:56:42 -05001357 if (!mesh_dev)
Holger Schurig61d30022008-01-16 15:59:52 +01001358 return;
Holger Schurig78523da2007-05-25 11:49:19 -04001359
Holger Schurig61d30022008-01-16 15:59:52 +01001360 lbs_deb_enter(LBS_DEB_MESH);
Holger Schurig78523da2007-05-25 11:49:19 -04001361 netif_stop_queue(mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -04001362 netif_carrier_off(priv->mesh_dev);
Holger Schurig10078322007-11-15 18:05:47 -05001363 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001364 unregister_netdev(mesh_dev);
David Woodhouse23a397a2007-12-11 18:56:42 -05001365 priv->mesh_dev = NULL;
Holger Schurig78523da2007-05-25 11:49:19 -04001366 free_netdev(mesh_dev);
Holger Schurig61d30022008-01-16 15:59:52 +01001367 lbs_deb_leave(LBS_DEB_MESH);
Holger Schurig78523da2007-05-25 11:49:19 -04001368}
1369
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001370/**
1371 * @brief This function finds the CFP in
1372 * region_cfp_table based on region and band parameter.
1373 *
1374 * @param region The region code
1375 * @param band The band
1376 * @param cfp_no A pointer to CFP number
1377 * @return A pointer to CFP
1378 */
Holger Schurige98a88d2008-03-19 14:25:58 +01001379struct chan_freq_power *lbs_get_region_cfp_table(u8 region, int *cfp_no)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001380{
1381 int i, end;
1382
Holger Schurig9012b282007-05-25 11:27:16 -04001383 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001384
Denis Chengff8ac602007-09-02 18:30:18 +08001385 end = ARRAY_SIZE(region_cfp_table);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001386
1387 for (i = 0; i < end ; i++) {
Holger Schurig9012b282007-05-25 11:27:16 -04001388 lbs_deb_main("region_cfp_table[i].region=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001389 region_cfp_table[i].region);
1390 if (region_cfp_table[i].region == region) {
1391 *cfp_no = region_cfp_table[i].cfp_no_BG;
Holger Schurig9012b282007-05-25 11:27:16 -04001392 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001393 return region_cfp_table[i].cfp_BG;
1394 }
1395 }
1396
Holger Schurig9012b282007-05-25 11:27:16 -04001397 lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001398 return NULL;
1399}
1400
Holger Schurig69f90322007-11-23 15:43:44 +01001401int lbs_set_regiontable(struct lbs_private *priv, u8 region, u8 band)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001402{
Holger Schurig9012b282007-05-25 11:27:16 -04001403 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001404 int i = 0;
1405
1406 struct chan_freq_power *cfp;
1407 int cfp_no;
1408
Holger Schurig9012b282007-05-25 11:27:16 -04001409 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001410
David Woodhouseaa21c002007-12-08 20:04:36 +00001411 memset(priv->region_channel, 0, sizeof(priv->region_channel));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001412
Holger Schurige98a88d2008-03-19 14:25:58 +01001413 cfp = lbs_get_region_cfp_table(region, &cfp_no);
Holger Schurig61d30022008-01-16 15:59:52 +01001414 if (cfp != NULL) {
1415 priv->region_channel[i].nrcfp = cfp_no;
1416 priv->region_channel[i].CFP = cfp;
1417 } else {
1418 lbs_deb_main("wrong region code %#x in band B/G\n",
1419 region);
1420 ret = -1;
1421 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001422 }
Holger Schurig61d30022008-01-16 15:59:52 +01001423 priv->region_channel[i].valid = 1;
1424 priv->region_channel[i].region = region;
1425 priv->region_channel[i].band = band;
1426 i++;
Holger Schurig9012b282007-05-25 11:27:16 -04001427out:
1428 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1429 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001430}
1431
Holger Schurig7919b892008-04-01 14:50:43 +02001432void lbs_queue_event(struct lbs_private *priv, u32 event)
1433{
1434 unsigned long flags;
1435
1436 lbs_deb_enter(LBS_DEB_THREAD);
1437 spin_lock_irqsave(&priv->driver_lock, flags);
1438
1439 if (priv->psstate == PS_STATE_SLEEP)
1440 priv->psstate = PS_STATE_AWAKE;
1441
1442 __kfifo_put(priv->event_fifo, (unsigned char *) &event, sizeof(u32));
1443
1444 wake_up_interruptible(&priv->waitq);
1445
1446 spin_unlock_irqrestore(&priv->driver_lock, flags);
1447 lbs_deb_leave(LBS_DEB_THREAD);
1448}
1449EXPORT_SYMBOL_GPL(lbs_queue_event);
1450
1451void lbs_notify_command_response(struct lbs_private *priv, u8 resp_idx)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001452{
Holger Schuriged37b512007-05-25 11:52:42 -04001453 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001454
David Woodhouse4f679492007-12-10 14:58:37 -05001455 if (priv->psstate == PS_STATE_SLEEP)
David Woodhouseaa21c002007-12-08 20:04:36 +00001456 priv->psstate = PS_STATE_AWAKE;
Holger Schurig7919b892008-04-01 14:50:43 +02001457
1458 /* Swap buffers by flipping the response index */
1459 BUG_ON(resp_idx > 1);
1460 priv->resp_idx = resp_idx;
1461
Dan Williamsfe336152007-08-02 11:32:25 -04001462 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001463
Holger Schuriged37b512007-05-25 11:52:42 -04001464 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001465}
Holger Schurig7919b892008-04-01 14:50:43 +02001466EXPORT_SYMBOL_GPL(lbs_notify_command_response);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001467
Andres Salomon4fb910f2007-11-20 17:43:45 -05001468static int __init lbs_init_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001469{
Holger Schurig9012b282007-05-25 11:27:16 -04001470 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurigf539f2e2008-03-26 13:22:11 +01001471 memset(&confirm_sleep, 0, sizeof(confirm_sleep));
1472 confirm_sleep.hdr.command = cpu_to_le16(CMD_802_11_PS_MODE);
1473 confirm_sleep.hdr.size = cpu_to_le16(sizeof(confirm_sleep));
1474 confirm_sleep.action = cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
Holger Schurig10078322007-11-15 18:05:47 -05001475 lbs_debugfs_init();
Holger Schurig084708b2007-05-25 12:37:58 -04001476 lbs_deb_leave(LBS_DEB_MAIN);
1477 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001478}
1479
Andres Salomon4fb910f2007-11-20 17:43:45 -05001480static void __exit lbs_exit_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001481{
Holger Schurig9012b282007-05-25 11:27:16 -04001482 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001483 lbs_debugfs_remove();
Holger Schurig9012b282007-05-25 11:27:16 -04001484 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001485}
1486
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001487/*
1488 * rtap interface support fuctions
1489 */
1490
Holger Schurig10078322007-11-15 18:05:47 -05001491static int lbs_rtap_open(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001492{
David Woodhouse8552855f2007-12-10 16:38:18 -05001493 /* Yes, _stop_ the queue. Because we don't support injection */
Holger Schurig61d30022008-01-16 15:59:52 +01001494 lbs_deb_enter(LBS_DEB_MAIN);
1495 netif_carrier_off(dev);
1496 netif_stop_queue(dev);
1497 lbs_deb_leave(LBS_DEB_LEAVE);
1498 return 0;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001499}
1500
Holger Schurig10078322007-11-15 18:05:47 -05001501static int lbs_rtap_stop(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001502{
Holger Schurig61d30022008-01-16 15:59:52 +01001503 lbs_deb_enter(LBS_DEB_MAIN);
1504 lbs_deb_leave(LBS_DEB_MAIN);
1505 return 0;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001506}
1507
Holger Schurig10078322007-11-15 18:05:47 -05001508static int lbs_rtap_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001509{
Holger Schurig61d30022008-01-16 15:59:52 +01001510 netif_stop_queue(dev);
1511 return NETDEV_TX_BUSY;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001512}
1513
Holger Schurig10078322007-11-15 18:05:47 -05001514static struct net_device_stats *lbs_rtap_get_stats(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001515{
Holger Schurig69f90322007-11-23 15:43:44 +01001516 struct lbs_private *priv = dev->priv;
Holger Schurig61d30022008-01-16 15:59:52 +01001517 lbs_deb_enter(LBS_DEB_NET);
David Woodhoused9268fb2007-12-09 16:22:21 -05001518 return &priv->stats;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001519}
1520
1521
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001522static void lbs_remove_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001523{
Holger Schurig61d30022008-01-16 15:59:52 +01001524 lbs_deb_enter(LBS_DEB_MAIN);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001525 if (priv->rtap_net_dev == NULL)
Holger Schurig5f505d92008-04-30 10:50:07 +02001526 goto out;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001527 unregister_netdev(priv->rtap_net_dev);
David Woodhoused9268fb2007-12-09 16:22:21 -05001528 free_netdev(priv->rtap_net_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001529 priv->rtap_net_dev = NULL;
Holger Schurig5f505d92008-04-30 10:50:07 +02001530out:
Holger Schurig61d30022008-01-16 15:59:52 +01001531 lbs_deb_leave(LBS_DEB_MAIN);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001532}
1533
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001534static int lbs_add_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001535{
Holger Schurig61d30022008-01-16 15:59:52 +01001536 int ret = 0;
David Woodhoused9268fb2007-12-09 16:22:21 -05001537 struct net_device *rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001538
Holger Schurig61d30022008-01-16 15:59:52 +01001539 lbs_deb_enter(LBS_DEB_MAIN);
1540 if (priv->rtap_net_dev) {
1541 ret = -EPERM;
1542 goto out;
1543 }
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001544
David Woodhoused9268fb2007-12-09 16:22:21 -05001545 rtap_dev = alloc_netdev(0, "rtap%d", ether_setup);
Holger Schurig61d30022008-01-16 15:59:52 +01001546 if (rtap_dev == NULL) {
1547 ret = -ENOMEM;
1548 goto out;
1549 }
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001550
David Woodhouse121947c2007-12-09 19:54:11 -05001551 memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN);
David Woodhoused9268fb2007-12-09 16:22:21 -05001552 rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP;
1553 rtap_dev->open = lbs_rtap_open;
1554 rtap_dev->stop = lbs_rtap_stop;
1555 rtap_dev->get_stats = lbs_rtap_get_stats;
1556 rtap_dev->hard_start_xmit = lbs_rtap_hard_start_xmit;
1557 rtap_dev->set_multicast_list = lbs_set_multicast_list;
1558 rtap_dev->priv = priv;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001559
Holger Schurig61d30022008-01-16 15:59:52 +01001560 ret = register_netdev(rtap_dev);
1561 if (ret) {
David Woodhoused9268fb2007-12-09 16:22:21 -05001562 free_netdev(rtap_dev);
Holger Schurig61d30022008-01-16 15:59:52 +01001563 goto out;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001564 }
David Woodhoused9268fb2007-12-09 16:22:21 -05001565 priv->rtap_net_dev = rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001566
Holger Schurig61d30022008-01-16 15:59:52 +01001567out:
1568 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1569 return ret;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001570}
1571
Holger Schurig04850a42008-03-26 17:56:26 +01001572#ifndef CONFIG_IEEE80211
1573const char *escape_essid(const char *essid, u8 essid_len)
1574{
1575 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
1576 const char *s = essid;
1577 char *d = escaped;
1578
1579 if (ieee80211_is_empty_essid(essid, essid_len)) {
1580 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
1581 return escaped;
1582 }
1583
1584 essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
1585 while (essid_len--) {
1586 if (*s == '\0') {
1587 *d++ = '\\';
1588 *d++ = '0';
1589 s++;
1590 } else {
1591 *d++ = *s++;
1592 }
1593 }
1594 *d = '\0';
1595 return escaped;
1596}
1597#endif
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001598
Holger Schurig10078322007-11-15 18:05:47 -05001599module_init(lbs_init_module);
1600module_exit(lbs_exit_module);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001601
Holger Schurig084708b2007-05-25 12:37:58 -04001602MODULE_DESCRIPTION("Libertas WLAN Driver Library");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001603MODULE_AUTHOR("Marvell International Ltd.");
1604MODULE_LICENSE("GPL");