blob: 0dc7de6a067b23e748703aa2ee408d78ac3761f4 [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>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020013
14#include <net/iw_handler.h>
Holger Schurig9012b282007-05-25 11:27:16 -040015#include <net/ieee80211.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020016
17#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020018#include "decl.h"
19#include "dev.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020#include "wext.h"
21#include "debugfs.h"
22#include "assoc.h"
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -040023#include "join.h"
Dan Williams6e66f032007-12-11 12:42:16 -050024#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020025
Dan Williams7856a542007-08-03 09:43:03 -040026#define DRIVER_RELEASE_VERSION "323.p0"
Holger Schurig10078322007-11-15 18:05:47 -050027const char lbs_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
Dan Williams3ce40232007-05-10 23:03:07 -040028#ifdef DEBUG
29 "-dbg"
30#endif
31 "";
32
Holger Schuriga46c6412007-05-25 11:32:07 -040033
34/* Module parameters */
Holger Schurig10078322007-11-15 18:05:47 -050035unsigned int lbs_debug;
36EXPORT_SYMBOL_GPL(lbs_debug);
37module_param_named(libertas_debug, lbs_debug, int, 0644);
Holger Schuriga46c6412007-05-25 11:32:07 -040038
39
Holger Schurig10078322007-11-15 18:05:47 -050040#define LBS_TX_PWR_DEFAULT 20 /*100mW */
41#define LBS_TX_PWR_US_DEFAULT 20 /*100mW */
42#define LBS_TX_PWR_JP_DEFAULT 16 /*50mW */
43#define LBS_TX_PWR_FR_DEFAULT 20 /*100mW */
44#define LBS_TX_PWR_EMEA_DEFAULT 20 /*100mW */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020045
46/* Format { channel, frequency (MHz), maxtxpower } */
47/* band: 'B/G', region: USA FCC/Canada IC */
48static struct chan_freq_power channel_freq_power_US_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050049 {1, 2412, LBS_TX_PWR_US_DEFAULT},
50 {2, 2417, LBS_TX_PWR_US_DEFAULT},
51 {3, 2422, LBS_TX_PWR_US_DEFAULT},
52 {4, 2427, LBS_TX_PWR_US_DEFAULT},
53 {5, 2432, LBS_TX_PWR_US_DEFAULT},
54 {6, 2437, LBS_TX_PWR_US_DEFAULT},
55 {7, 2442, LBS_TX_PWR_US_DEFAULT},
56 {8, 2447, LBS_TX_PWR_US_DEFAULT},
57 {9, 2452, LBS_TX_PWR_US_DEFAULT},
58 {10, 2457, LBS_TX_PWR_US_DEFAULT},
59 {11, 2462, LBS_TX_PWR_US_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020060};
61
62/* band: 'B/G', region: Europe ETSI */
63static struct chan_freq_power channel_freq_power_EU_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050064 {1, 2412, LBS_TX_PWR_EMEA_DEFAULT},
65 {2, 2417, LBS_TX_PWR_EMEA_DEFAULT},
66 {3, 2422, LBS_TX_PWR_EMEA_DEFAULT},
67 {4, 2427, LBS_TX_PWR_EMEA_DEFAULT},
68 {5, 2432, LBS_TX_PWR_EMEA_DEFAULT},
69 {6, 2437, LBS_TX_PWR_EMEA_DEFAULT},
70 {7, 2442, LBS_TX_PWR_EMEA_DEFAULT},
71 {8, 2447, LBS_TX_PWR_EMEA_DEFAULT},
72 {9, 2452, LBS_TX_PWR_EMEA_DEFAULT},
73 {10, 2457, LBS_TX_PWR_EMEA_DEFAULT},
74 {11, 2462, LBS_TX_PWR_EMEA_DEFAULT},
75 {12, 2467, LBS_TX_PWR_EMEA_DEFAULT},
76 {13, 2472, LBS_TX_PWR_EMEA_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020077};
78
79/* band: 'B/G', region: Spain */
80static struct chan_freq_power channel_freq_power_SPN_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050081 {10, 2457, LBS_TX_PWR_DEFAULT},
82 {11, 2462, LBS_TX_PWR_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020083};
84
85/* band: 'B/G', region: France */
86static struct chan_freq_power channel_freq_power_FR_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050087 {10, 2457, LBS_TX_PWR_FR_DEFAULT},
88 {11, 2462, LBS_TX_PWR_FR_DEFAULT},
89 {12, 2467, LBS_TX_PWR_FR_DEFAULT},
90 {13, 2472, LBS_TX_PWR_FR_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020091};
92
93/* band: 'B/G', region: Japan */
94static struct chan_freq_power channel_freq_power_JPN_BG[] = {
Holger Schurig10078322007-11-15 18:05:47 -050095 {1, 2412, LBS_TX_PWR_JP_DEFAULT},
96 {2, 2417, LBS_TX_PWR_JP_DEFAULT},
97 {3, 2422, LBS_TX_PWR_JP_DEFAULT},
98 {4, 2427, LBS_TX_PWR_JP_DEFAULT},
99 {5, 2432, LBS_TX_PWR_JP_DEFAULT},
100 {6, 2437, LBS_TX_PWR_JP_DEFAULT},
101 {7, 2442, LBS_TX_PWR_JP_DEFAULT},
102 {8, 2447, LBS_TX_PWR_JP_DEFAULT},
103 {9, 2452, LBS_TX_PWR_JP_DEFAULT},
104 {10, 2457, LBS_TX_PWR_JP_DEFAULT},
105 {11, 2462, LBS_TX_PWR_JP_DEFAULT},
106 {12, 2467, LBS_TX_PWR_JP_DEFAULT},
107 {13, 2472, LBS_TX_PWR_JP_DEFAULT},
108 {14, 2484, LBS_TX_PWR_JP_DEFAULT}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200109};
110
111/**
112 * the structure for channel, frequency and power
113 */
114struct region_cfp_table {
115 u8 region;
116 struct chan_freq_power *cfp_BG;
117 int cfp_no_BG;
118};
119
120/**
121 * the structure for the mapping between region and CFP
122 */
123static struct region_cfp_table region_cfp_table[] = {
124 {0x10, /*US FCC */
125 channel_freq_power_US_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800126 ARRAY_SIZE(channel_freq_power_US_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127 }
128 ,
129 {0x20, /*CANADA IC */
130 channel_freq_power_US_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800131 ARRAY_SIZE(channel_freq_power_US_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200132 }
133 ,
134 {0x30, /*EU*/ channel_freq_power_EU_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800135 ARRAY_SIZE(channel_freq_power_EU_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200136 }
137 ,
138 {0x31, /*SPAIN*/ channel_freq_power_SPN_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800139 ARRAY_SIZE(channel_freq_power_SPN_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200140 }
141 ,
142 {0x32, /*FRANCE*/ channel_freq_power_FR_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800143 ARRAY_SIZE(channel_freq_power_FR_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200144 }
145 ,
146 {0x40, /*JAPAN*/ channel_freq_power_JPN_BG,
Denis Chengff8ac602007-09-02 18:30:18 +0800147 ARRAY_SIZE(channel_freq_power_JPN_BG),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200148 }
149 ,
150/*Add new region here */
151};
152
153/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200154 * the table to keep region code
155 */
Holger Schurig10078322007-11-15 18:05:47 -0500156u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200157 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
158
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159/**
Dan Williams8c512762007-08-02 11:40:45 -0400160 * 802.11b/g supported bitrates (in 500Kb/s units)
161 */
Holger Schurig10078322007-11-15 18:05:47 -0500162u8 lbs_bg_rates[MAX_RATES] =
Dan Williams8c512762007-08-02 11:40:45 -0400163 { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
1640x00, 0x00 };
165
166/**
167 * FW rate table. FW refers to rates by their index in this table, not by the
168 * rate value itself. Values of 0x00 are
169 * reserved positions.
170 */
171static u8 fw_data_rates[MAX_RATES] =
172 { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
173 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
174};
175
176/**
177 * @brief use index to get the data rate
178 *
179 * @param idx The index of data rate
180 * @return data rate or 0
181 */
Holger Schurig10078322007-11-15 18:05:47 -0500182u32 lbs_fw_index_to_data_rate(u8 idx)
Dan Williams8c512762007-08-02 11:40:45 -0400183{
184 if (idx >= sizeof(fw_data_rates))
185 idx = 0;
186 return fw_data_rates[idx];
187}
188
189/**
190 * @brief use rate to get the index
191 *
192 * @param rate data rate
193 * @return index or 0
194 */
Holger Schurig10078322007-11-15 18:05:47 -0500195u8 lbs_data_rate_to_fw_index(u32 rate)
Dan Williams8c512762007-08-02 11:40:45 -0400196{
197 u8 i;
198
199 if (!rate)
200 return 0;
201
202 for (i = 0; i < sizeof(fw_data_rates); i++) {
203 if (rate == fw_data_rates[i])
204 return i;
205 }
206 return 0;
207}
208
209/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200210 * Attributes exported through sysfs
211 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200212
213/**
Luis Carlos82fde742007-06-07 16:40:59 -0400214 * @brief Get function for sysfs attribute anycast_mask
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200215 */
Holger Schurig10078322007-11-15 18:05:47 -0500216static ssize_t lbs_anycast_get(struct device *dev,
Dan Williamsb59bb612007-06-18 11:50:43 -0400217 struct device_attribute *attr, char * buf)
218{
David Woodhouse301eacb2007-12-11 15:23:59 -0500219 struct lbs_private *priv = to_net_dev(dev)->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200220 struct cmd_ds_mesh_access mesh_access;
David Woodhouse301eacb2007-12-11 15:23:59 -0500221 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200222
223 memset(&mesh_access, 0, sizeof(mesh_access));
David Woodhouse301eacb2007-12-11 15:23:59 -0500224
225 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
226 if (ret)
227 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200228
Luis Carlos82fde742007-06-07 16:40:59 -0400229 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200230}
231
232/**
Luis Carlos82fde742007-06-07 16:40:59 -0400233 * @brief Set function for sysfs attribute anycast_mask
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234 */
Holger Schurig10078322007-11-15 18:05:47 -0500235static ssize_t lbs_anycast_set(struct device *dev,
Dan Williamsb59bb612007-06-18 11:50:43 -0400236 struct device_attribute *attr, const char * buf, size_t count)
237{
David Woodhouse301eacb2007-12-11 15:23:59 -0500238 struct lbs_private *priv = to_net_dev(dev)->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200239 struct cmd_ds_mesh_access mesh_access;
David Woodhouse981f1872007-05-25 23:36:54 -0400240 uint32_t datum;
David Woodhouse301eacb2007-12-11 15:23:59 -0500241 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200242
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200243 memset(&mesh_access, 0, sizeof(mesh_access));
Luis Carlos82fde742007-06-07 16:40:59 -0400244 sscanf(buf, "%x", &datum);
David Woodhouse981f1872007-05-25 23:36:54 -0400245 mesh_access.data[0] = cpu_to_le32(datum);
246
David Woodhouse301eacb2007-12-11 15:23:59 -0500247 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
248 if (ret)
249 return ret;
250
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200251 return strlen(buf);
252}
253
David Woodhouse2fd6cfe2007-12-11 17:44:10 -0500254static int lbs_add_rtap(struct lbs_private *priv);
255static void lbs_remove_rtap(struct lbs_private *priv);
David Woodhouse23a397a2007-12-11 18:56:42 -0500256static int lbs_add_mesh(struct lbs_private *priv);
257static void lbs_remove_mesh(struct lbs_private *priv);
David Woodhouse7e226272007-12-14 22:53:41 -0500258
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400259
260/**
261 * Get function for sysfs attribute rtap
262 */
Holger Schurig10078322007-11-15 18:05:47 -0500263static ssize_t lbs_rtap_get(struct device *dev,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400264 struct device_attribute *attr, char * buf)
265{
David Woodhousee7deced2007-12-08 18:29:16 +0000266 struct lbs_private *priv = to_net_dev(dev)->priv;
David Woodhouseaa21c002007-12-08 20:04:36 +0000267 return snprintf(buf, 5, "0x%X\n", priv->monitormode);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400268}
269
270/**
271 * Set function for sysfs attribute rtap
272 */
Holger Schurig10078322007-11-15 18:05:47 -0500273static ssize_t lbs_rtap_set(struct device *dev,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400274 struct device_attribute *attr, const char * buf, size_t count)
275{
276 int monitor_mode;
David Woodhousee7deced2007-12-08 18:29:16 +0000277 struct lbs_private *priv = to_net_dev(dev)->priv;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400278
279 sscanf(buf, "%x", &monitor_mode);
Holger Schurig10078322007-11-15 18:05:47 -0500280 if (monitor_mode != LBS_MONITOR_OFF) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000281 if(priv->monitormode == monitor_mode)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400282 return strlen(buf);
David Woodhouseaa21c002007-12-08 20:04:36 +0000283 if (priv->monitormode == LBS_MONITOR_OFF) {
David Woodhouse8552855f2007-12-10 16:38:18 -0500284 if (priv->infra_open || priv->mesh_open)
285 return -EBUSY;
David Woodhouseaa21c002007-12-08 20:04:36 +0000286 if (priv->mode == IW_MODE_INFRA)
Holger Schurig10078322007-11-15 18:05:47 -0500287 lbs_send_deauthentication(priv);
David Woodhouseaa21c002007-12-08 20:04:36 +0000288 else if (priv->mode == IW_MODE_ADHOC)
Holger Schurig10078322007-11-15 18:05:47 -0500289 lbs_stop_adhoc_network(priv);
290 lbs_add_rtap(priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400291 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000292 priv->monitormode = monitor_mode;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400293 }
294
295 else {
David Woodhouseaa21c002007-12-08 20:04:36 +0000296 if (priv->monitormode == LBS_MONITOR_OFF)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400297 return strlen(buf);
David Woodhouseaa21c002007-12-08 20:04:36 +0000298 priv->monitormode = LBS_MONITOR_OFF;
Holger Schurig10078322007-11-15 18:05:47 -0500299 lbs_remove_rtap(priv);
David Woodhousef86a93e2007-12-08 19:46:19 +0000300
David Woodhouseaa21c002007-12-08 20:04:36 +0000301 if (priv->currenttxskb) {
302 dev_kfree_skb_any(priv->currenttxskb);
303 priv->currenttxskb = NULL;
David Woodhousef86a93e2007-12-08 19:46:19 +0000304 }
305
306 /* Wake queues, command thread, etc. */
307 lbs_host_to_card_done(priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400308 }
309
Holger Schurig10078322007-11-15 18:05:47 -0500310 lbs_prepare_and_send_command(priv,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400311 CMD_802_11_MONITOR_MODE, CMD_ACT_SET,
David Woodhouseaa21c002007-12-08 20:04:36 +0000312 CMD_OPTION_WAITFORRSP, 0, &priv->monitormode);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400313 return strlen(buf);
314}
315
316/**
David Woodhouse23a397a2007-12-11 18:56:42 -0500317 * lbs_rtap attribute to be exported per ethX interface
318 * through sysfs (/sys/class/net/ethX/lbs_rtap)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400319 */
David Woodhouse23a397a2007-12-11 18:56:42 -0500320static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get, lbs_rtap_set );
321
322/**
323 * Get function for sysfs attribute mesh
324 */
325static ssize_t lbs_mesh_get(struct device *dev,
326 struct device_attribute *attr, char * buf)
327{
328 struct lbs_private *priv = to_net_dev(dev)->priv;
329 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
330}
331
332/**
333 * Set function for sysfs attribute mesh
334 */
335static ssize_t lbs_mesh_set(struct device *dev,
336 struct device_attribute *attr, const char * buf, size_t count)
337{
338 struct lbs_private *priv = to_net_dev(dev)->priv;
339 int enable;
340 int ret;
341
342 sscanf(buf, "%x", &enable);
343 enable = !!enable;
344 if (enable == !!priv->mesh_dev)
345 return count;
346
David Woodhouse86062132007-12-13 00:32:36 -0500347 ret = lbs_mesh_config(priv, enable, priv->curbssparams.channel);
David Woodhouse23a397a2007-12-11 18:56:42 -0500348 if (ret)
349 return ret;
David Woodhouse7e226272007-12-14 22:53:41 -0500350
David Woodhouse23a397a2007-12-11 18:56:42 -0500351 if (enable)
352 lbs_add_mesh(priv);
353 else
354 lbs_remove_mesh(priv);
355
356 return count;
357}
358
359/**
360 * lbs_mesh attribute to be exported per ethX interface
361 * through sysfs (/sys/class/net/ethX/lbs_mesh)
362 */
363static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400364
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200365/**
Luis Carlos82fde742007-06-07 16:40:59 -0400366 * anycast_mask attribute to be exported per mshX interface
367 * through sysfs (/sys/class/net/mshX/anycast_mask)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200368 */
Holger Schurig10078322007-11-15 18:05:47 -0500369static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370
Holger Schurig10078322007-11-15 18:05:47 -0500371static struct attribute *lbs_mesh_sysfs_entries[] = {
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400372 &dev_attr_anycast_mask.attr,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400373 NULL,
374};
375
Holger Schurig10078322007-11-15 18:05:47 -0500376static struct attribute_group lbs_mesh_attr_group = {
377 .attrs = lbs_mesh_sysfs_entries,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400378};
379
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200380/**
David Woodhouse8552855f2007-12-10 16:38:18 -0500381 * @brief This function opens the ethX or mshX interface
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200382 *
383 * @param dev A pointer to net_device structure
David Woodhouse8552855f2007-12-10 16:38:18 -0500384 * @return 0 or -EBUSY if monitor mode active
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200385 */
Holger Schurig10078322007-11-15 18:05:47 -0500386static int lbs_dev_open(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200387{
David Woodhouse8552855f2007-12-10 16:38:18 -0500388 struct lbs_private *priv = (struct lbs_private *) dev->priv ;
389 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200390
David Woodhouse8552855f2007-12-10 16:38:18 -0500391 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392
David Woodhouse8552855f2007-12-10 16:38:18 -0500393 if (priv->monitormode != LBS_MONITOR_OFF) {
394 ret = -EBUSY;
395 goto out;
Javier Cardona51d84f52007-05-25 12:06:56 -0400396 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200397
David Woodhouse8552855f2007-12-10 16:38:18 -0500398 if (dev == priv->mesh_dev) {
399 priv->mesh_open = 1;
400 priv->mesh_connect_status = LBS_CONNECTED;
401 netif_carrier_on(dev);
402 } else {
403 priv->infra_open = 1;
David Woodhouse7e226272007-12-14 22:53:41 -0500404
David Woodhouse8552855f2007-12-10 16:38:18 -0500405 if (priv->connect_status == LBS_CONNECTED)
406 netif_carrier_on(dev);
407 else
408 netif_carrier_off(dev);
409 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200410
David Woodhouse8552855f2007-12-10 16:38:18 -0500411 if (!priv->tx_pending_len)
412 netif_wake_queue(dev);
413 out:
Brajesh Dave01d77d82007-11-20 17:44:14 -0500414
David Woodhouse8552855f2007-12-10 16:38:18 -0500415 spin_unlock_irq(&priv->driver_lock);
416 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417}
418
419/**
420 * @brief This function closes the mshX interface
421 *
422 * @param dev A pointer to net_device structure
423 * @return 0
424 */
David Woodhouse8552855f2007-12-10 16:38:18 -0500425static int lbs_mesh_stop(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200426{
Holger Schurig69f90322007-11-23 15:43:44 +0100427 struct lbs_private *priv = (struct lbs_private *) (dev->priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200428
David Woodhouse8552855f2007-12-10 16:38:18 -0500429 spin_lock_irq(&priv->driver_lock);
430
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431 priv->mesh_open = 0;
David Woodhouse8552855f2007-12-10 16:38:18 -0500432 priv->mesh_connect_status = LBS_DISCONNECTED;
433
434 netif_stop_queue(dev);
435 netif_carrier_off(dev);
David Woodhouse7e226272007-12-14 22:53:41 -0500436
David Woodhouse8552855f2007-12-10 16:38:18 -0500437 spin_unlock_irq(&priv->driver_lock);
438 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200439}
440
441/**
442 * @brief This function closes the ethX interface
443 *
444 * @param dev A pointer to net_device structure
445 * @return 0
446 */
David Woodhouse8552855f2007-12-10 16:38:18 -0500447static int lbs_eth_stop(struct net_device *dev)
Holger Schurig78523da2007-05-25 11:49:19 -0400448{
Holger Schurig69f90322007-11-23 15:43:44 +0100449 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200450
David Woodhouse8552855f2007-12-10 16:38:18 -0500451 spin_lock_irq(&priv->driver_lock);
452
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200453 priv->infra_open = 0;
David Woodhouse8552855f2007-12-10 16:38:18 -0500454
455 netif_stop_queue(dev);
David Woodhouse7e226272007-12-14 22:53:41 -0500456
David Woodhouse8552855f2007-12-10 16:38:18 -0500457 spin_unlock_irq(&priv->driver_lock);
458 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200459}
460
Holger Schurig10078322007-11-15 18:05:47 -0500461static void lbs_tx_timeout(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200462{
Holger Schurig69f90322007-11-23 15:43:44 +0100463 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464
Holger Schurig9012b282007-05-25 11:27:16 -0400465 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200466
Holger Schurig9012b282007-05-25 11:27:16 -0400467 lbs_pr_err("tx watch dog timeout\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200468
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200469 dev->trans_start = jiffies;
470
David Woodhouseaa21c002007-12-08 20:04:36 +0000471 if (priv->currenttxskb) {
David Woodhousea63b22b2007-12-08 20:56:44 +0000472 priv->eventcause = 0x01000000;
473 lbs_send_tx_feedback(priv);
Javier Cardona51d84f52007-05-25 12:06:56 -0400474 }
David Woodhousea63b22b2007-12-08 20:56:44 +0000475 /* XX: Shouldn't we also call into the hw-specific driver
476 to kick it somehow? */
477 lbs_host_to_card_done(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200478
Holger Schurig9012b282007-05-25 11:27:16 -0400479 lbs_deb_leave(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200480}
481
David Woodhousee775ed72007-12-06 14:36:11 +0000482void lbs_host_to_card_done(struct lbs_private *priv)
483{
David Woodhousea63b22b2007-12-08 20:56:44 +0000484 unsigned long flags;
485
486 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhousee775ed72007-12-06 14:36:11 +0000487
488 priv->dnld_sent = DNLD_RES_RECEIVED;
489
490 /* Wake main thread if commands are pending */
David Woodhousea27b9f92007-12-12 00:41:51 -0500491 if (!priv->cur_cmd || priv->tx_pending_len > 0)
David Woodhousee775ed72007-12-06 14:36:11 +0000492 wake_up_interruptible(&priv->waitq);
493
David Woodhousea63b22b2007-12-08 20:56:44 +0000494 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhousee775ed72007-12-06 14:36:11 +0000495}
496EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
497
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200498/**
499 * @brief This function returns the network statistics
500 *
Holger Schurig69f90322007-11-23 15:43:44 +0100501 * @param dev A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200502 * @return A pointer to net_device_stats structure
503 */
Holger Schurig10078322007-11-15 18:05:47 -0500504static struct net_device_stats *lbs_get_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200505{
Holger Schurig69f90322007-11-23 15:43:44 +0100506 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507
508 return &priv->stats;
509}
510
Holger Schurig10078322007-11-15 18:05:47 -0500511static int lbs_set_mac_address(struct net_device *dev, void *addr)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200512{
513 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100514 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200515 struct sockaddr *phwaddr = addr;
516
Holger Schurig9012b282007-05-25 11:27:16 -0400517 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200518
Luis Carlos Cobo Rus0a0d08a2007-05-25 23:05:27 -0400519 /* In case it was called from the mesh device */
520 dev = priv->dev ;
521
David Woodhouseaa21c002007-12-08 20:04:36 +0000522 memset(priv->current_addr, 0, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200523
524 /* dev->dev_addr is 8 bytes */
Holger Schurigece56192007-08-02 11:53:06 -0400525 lbs_deb_hex(LBS_DEB_NET, "dev->dev_addr", dev->dev_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200526
Holger Schurigece56192007-08-02 11:53:06 -0400527 lbs_deb_hex(LBS_DEB_NET, "addr", phwaddr->sa_data, ETH_ALEN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000528 memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200529
Holger Schurig10078322007-11-15 18:05:47 -0500530 ret = lbs_prepare_and_send_command(priv, CMD_802_11_MAC_ADDRESS,
Dan Williams0aef64d2007-08-02 11:31:18 -0400531 CMD_ACT_SET,
532 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200533
534 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400535 lbs_deb_net("set MAC address failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200536 ret = -1;
537 goto done;
538 }
539
David Woodhouseaa21c002007-12-08 20:04:36 +0000540 lbs_deb_hex(LBS_DEB_NET, "priv->macaddr", priv->current_addr, ETH_ALEN);
541 memcpy(dev->dev_addr, priv->current_addr, ETH_ALEN);
Holger Schurig78523da2007-05-25 11:49:19 -0400542 if (priv->mesh_dev)
David Woodhouseaa21c002007-12-08 20:04:36 +0000543 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200544
545done:
Holger Schurig9012b282007-05-25 11:27:16 -0400546 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200547 return ret;
548}
549
David Woodhouseaa21c002007-12-08 20:04:36 +0000550static int lbs_copy_multicast_address(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200551 struct net_device *dev)
552{
553 int i = 0;
554 struct dev_mc_list *mcptr = dev->mc_list;
555
556 for (i = 0; i < dev->mc_count; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000557 memcpy(&priv->multicastlist[i], mcptr->dmi_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200558 mcptr = mcptr->next;
559 }
560
561 return i;
562
563}
564
Holger Schurig10078322007-11-15 18:05:47 -0500565static void lbs_set_multicast_list(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200566{
Holger Schurig69f90322007-11-23 15:43:44 +0100567 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200568 int oldpacketfilter;
Joe Perches0795af52007-10-03 17:59:30 -0700569 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200570
Holger Schurig9012b282007-05-25 11:27:16 -0400571 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200572
David Woodhouseaa21c002007-12-08 20:04:36 +0000573 oldpacketfilter = priv->currentpacketfilter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200574
575 if (dev->flags & IFF_PROMISC) {
Holger Schurig9012b282007-05-25 11:27:16 -0400576 lbs_deb_net("enable promiscuous mode\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000577 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400578 CMD_ACT_MAC_PROMISCUOUS_ENABLE;
David Woodhouseaa21c002007-12-08 20:04:36 +0000579 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400580 ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE |
581 CMD_ACT_MAC_MULTICAST_ENABLE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200582 } else {
583 /* Multicast */
David Woodhouseaa21c002007-12-08 20:04:36 +0000584 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400585 ~CMD_ACT_MAC_PROMISCUOUS_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200586
587 if (dev->flags & IFF_ALLMULTI || dev->mc_count >
588 MRVDRV_MAX_MULTICAST_LIST_SIZE) {
Holger Schurig9012b282007-05-25 11:27:16 -0400589 lbs_deb_net( "enabling all multicast\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000590 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400591 CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
David Woodhouseaa21c002007-12-08 20:04:36 +0000592 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400593 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200594 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +0000595 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400596 ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200597
598 if (!dev->mc_count) {
Holger Schurig9012b282007-05-25 11:27:16 -0400599 lbs_deb_net("no multicast addresses, "
600 "disabling multicast\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000601 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400602 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200603 } else {
604 int i;
605
David Woodhouseaa21c002007-12-08 20:04:36 +0000606 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400607 CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608
David Woodhouseaa21c002007-12-08 20:04:36 +0000609 priv->nr_of_multicastmacaddr =
610 lbs_copy_multicast_address(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611
Holger Schurig9012b282007-05-25 11:27:16 -0400612 lbs_deb_net("multicast addresses: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200613 dev->mc_count);
614
615 for (i = 0; i < dev->mc_count; i++) {
Joe Perches0795af52007-10-03 17:59:30 -0700616 lbs_deb_net("Multicast address %d:%s\n",
617 i, print_mac(mac,
David Woodhouseaa21c002007-12-08 20:04:36 +0000618 priv->multicastlist[i]));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200619 }
Holger Schurig9012b282007-05-25 11:27:16 -0400620 /* send multicast addresses to firmware */
Holger Schurig10078322007-11-15 18:05:47 -0500621 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400622 CMD_MAC_MULTICAST_ADR,
623 CMD_ACT_SET, 0, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200624 NULL);
625 }
626 }
627 }
628
David Woodhouseaa21c002007-12-08 20:04:36 +0000629 if (priv->currentpacketfilter != oldpacketfilter) {
Holger Schurig10078322007-11-15 18:05:47 -0500630 lbs_set_mac_packet_filter(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200631 }
632
Holger Schurig9012b282007-05-25 11:27:16 -0400633 lbs_deb_leave(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200634}
635
636/**
Holger Schurig10078322007-11-15 18:05:47 -0500637 * @brief This function handles the major jobs in the LBS driver.
Holger Schurig9012b282007-05-25 11:27:16 -0400638 * It handles all events generated by firmware, RX data received
639 * from firmware and TX data sent from kernel.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200640 *
Holger Schurig10078322007-11-15 18:05:47 -0500641 * @param data A pointer to lbs_thread structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200642 * @return 0
643 */
Holger Schurig10078322007-11-15 18:05:47 -0500644static int lbs_thread(void *data)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200645{
Dan Williamsfe336152007-08-02 11:32:25 -0400646 struct net_device *dev = data;
Holger Schurig69f90322007-11-23 15:43:44 +0100647 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200648 wait_queue_t wait;
649 u8 ireg = 0;
650
Holger Schurig9012b282007-05-25 11:27:16 -0400651 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200652
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200653 init_waitqueue_entry(&wait, current);
654
655 for (;;) {
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500656 int shouldsleep;
657
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000658 lbs_deb_thread( "main-thread 111: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000659 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200660
Dan Williamsfe336152007-08-02 11:32:25 -0400661 add_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200662 set_current_state(TASK_INTERRUPTIBLE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000663 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000664
David Woodhoused9f88702007-12-13 21:48:00 -0500665 if (kthread_should_stop())
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500666 shouldsleep = 0; /* Bye */
David Woodhoused9f88702007-12-13 21:48:00 -0500667 else if (priv->surpriseremoved)
668 shouldsleep = 1; /* We need to wait until we're _told_ to die */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500669 else if (priv->psstate == PS_STATE_SLEEP)
670 shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */
671 else if (priv->intcounter)
672 shouldsleep = 0; /* Interrupt pending. Deal with it now */
David Woodhouseb15152a2007-12-11 11:55:37 -0500673 else if (!priv->fw_ready)
674 shouldsleep = 1; /* Firmware not ready. We're waiting for it */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500675 else if (priv->dnld_sent)
676 shouldsleep = 1; /* Something is en route to the device already */
David Woodhouse2eb188a2007-12-09 23:54:27 -0500677 else if (priv->tx_pending_len > 0)
678 shouldsleep = 0; /* We've a packet to send */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500679 else if (priv->cur_cmd)
680 shouldsleep = 1; /* Can't send a command; one already running */
681 else if (!list_empty(&priv->cmdpendingq))
682 shouldsleep = 0; /* We have a command to send */
683 else
684 shouldsleep = 1; /* No command */
685
686 if (shouldsleep) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000687 lbs_deb_thread("main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000688 priv->connect_status, priv->intcounter,
689 priv->psmode, priv->psstate);
690 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200691 schedule();
692 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000693 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200694
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000695 lbs_deb_thread("main-thread 222 (waking up): intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000696 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200697
698 set_current_state(TASK_RUNNING);
Dan Williamsfe336152007-08-02 11:32:25 -0400699 remove_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200700
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000701 lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000702 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200703
David Woodhoused9f88702007-12-13 21:48:00 -0500704 if (kthread_should_stop()) {
705 lbs_deb_thread("main-thread: break from main thread\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200706 break;
707 }
708
David Woodhoused9f88702007-12-13 21:48:00 -0500709 if (priv->surpriseremoved) {
710 lbs_deb_thread("adapter removed; waiting to die...\n");
711 continue;
712 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200713
David Woodhouseaa21c002007-12-08 20:04:36 +0000714 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000715
David Woodhouseaa21c002007-12-08 20:04:36 +0000716 if (priv->intcounter) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200717 u8 int_status;
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000718
David Woodhouseaa21c002007-12-08 20:04:36 +0000719 priv->intcounter = 0;
Holger Schurig208fdd22007-05-25 12:17:06 -0400720 int_status = priv->hw_get_int_status(priv, &ireg);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200721
722 if (int_status) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000723 lbs_deb_thread("main-thread: reading HOST_INT_STATUS_REG failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000724 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200725 continue;
726 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000727 priv->hisregcpy |= ireg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200728 }
729
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000730 lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000731 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200732
733 /* command response? */
David Woodhouseaa21c002007-12-08 20:04:36 +0000734 if (priv->hisregcpy & MRVDRV_CMD_UPLD_RDY) {
Holger Schurig9012b282007-05-25 11:27:16 -0400735 lbs_deb_thread("main-thread: cmd response ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200736
David Woodhouseaa21c002007-12-08 20:04:36 +0000737 priv->hisregcpy &= ~MRVDRV_CMD_UPLD_RDY;
738 spin_unlock_irq(&priv->driver_lock);
Holger Schurig10078322007-11-15 18:05:47 -0500739 lbs_process_rx_command(priv);
David Woodhouseaa21c002007-12-08 20:04:36 +0000740 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741 }
742
743 /* Any Card Event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000744 if (priv->hisregcpy & MRVDRV_CARDEVENT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400745 lbs_deb_thread("main-thread: Card Event Activity\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200746
David Woodhouseaa21c002007-12-08 20:04:36 +0000747 priv->hisregcpy &= ~MRVDRV_CARDEVENT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200748
Holger Schurig208fdd22007-05-25 12:17:06 -0400749 if (priv->hw_read_event_cause(priv)) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000750 lbs_pr_alert("main-thread: hw_read_event_cause failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000751 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200752 continue;
753 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000754 spin_unlock_irq(&priv->driver_lock);
Holger Schurig10078322007-11-15 18:05:47 -0500755 lbs_process_event(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200756 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000757 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200758
David Woodhouseb15152a2007-12-11 11:55:37 -0500759 if (!priv->fw_ready)
760 continue;
761
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200762 /* Check if we need to confirm Sleep Request received previously */
David Woodhouseaa21c002007-12-08 20:04:36 +0000763 if (priv->psstate == PS_STATE_PRE_SLEEP &&
764 !priv->dnld_sent && !priv->cur_cmd) {
765 if (priv->connect_status == LBS_CONNECTED) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000766 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 +0000767 priv->intcounter, priv->currenttxskb, priv->dnld_sent, priv->cur_cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200768
David Woodhouseaa21c002007-12-08 20:04:36 +0000769 lbs_ps_confirm_sleep(priv, (u16) priv->psmode);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000770 } else {
771 /* workaround for firmware sending
772 * deauth/linkloss event immediately
773 * after sleep request; remove this
774 * after firmware fixes it
775 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000776 priv->psstate = PS_STATE_AWAKE;
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000777 lbs_pr_alert("main-thread: ignore PS_SleepConfirm in non-connected state\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200778 }
779 }
780
781 /* The PS state is changed during processing of Sleep Request
782 * event above
783 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000784 if ((priv->psstate == PS_STATE_SLEEP) ||
785 (priv->psstate == PS_STATE_PRE_SLEEP))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200786 continue;
787
788 /* Execute the next command */
David Woodhouseaa21c002007-12-08 20:04:36 +0000789 if (!priv->dnld_sent && !priv->cur_cmd)
Holger Schurig10078322007-11-15 18:05:47 -0500790 lbs_execute_next_command(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200791
792 /* Wake-up command waiters which can't sleep in
Holger Schurig10078322007-11-15 18:05:47 -0500793 * lbs_prepare_and_send_command
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200794 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000795 if (!list_empty(&priv->cmdpendingq))
796 wake_up_all(&priv->cmd_pending);
David Woodhouse2eb188a2007-12-09 23:54:27 -0500797
798 spin_lock_irq(&priv->driver_lock);
799 if (!priv->dnld_sent && priv->tx_pending_len > 0) {
800 int ret = priv->hw_host_to_card(priv, MVMS_DAT,
801 priv->tx_pending_buf,
802 priv->tx_pending_len);
803 if (ret) {
804 lbs_deb_tx("host_to_card failed %d\n", ret);
805 priv->dnld_sent = DNLD_RES_RECEIVED;
806 }
807 priv->tx_pending_len = 0;
808 if (!priv->currenttxskb) {
809 /* We can wake the queues immediately if we aren't
810 waiting for TX feedback */
811 if (priv->connect_status == LBS_CONNECTED)
812 netif_wake_queue(priv->dev);
813 if (priv->mesh_dev &&
814 priv->mesh_connect_status == LBS_CONNECTED)
815 netif_wake_queue(priv->mesh_dev);
816 }
817 }
818 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200819 }
820
David Woodhouseaa21c002007-12-08 20:04:36 +0000821 del_timer(&priv->command_timer);
822 wake_up_all(&priv->cmd_pending);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200823
Holger Schurig9012b282007-05-25 11:27:16 -0400824 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200825 return 0;
826}
827
David Woodhouseab25eca2007-12-12 17:38:56 -0500828static int lbs_suspend_callback(struct lbs_private *priv, unsigned long dummy,
829 struct cmd_header *cmd)
830{
831 lbs_deb_fw("HOST_SLEEP_ACTIVATE succeeded\n");
832
833 netif_device_detach(priv->dev);
834 if (priv->mesh_dev)
835 netif_device_detach(priv->mesh_dev);
836
837 priv->fw_ready = 0;
838 return 0;
839}
840
841
842int lbs_suspend(struct lbs_private *priv)
843{
844 struct cmd_header cmd;
845 int ret;
846
David Woodhouse506e9022007-12-12 20:06:06 -0500847 if (priv->wol_criteria == 0xffffffff) {
848 lbs_pr_info("Suspend attempt without configuring wake params!\n");
849 return -EINVAL;
850 }
851
David Woodhouseab25eca2007-12-12 17:38:56 -0500852 memset(&cmd, 0, sizeof(cmd));
David Woodhouse7e226272007-12-14 22:53:41 -0500853
David Woodhouseab25eca2007-12-12 17:38:56 -0500854 ret = __lbs_cmd(priv, CMD_802_11_HOST_SLEEP_ACTIVATE, &cmd,
855 sizeof(cmd), lbs_suspend_callback, 0);
856 if (ret)
857 lbs_pr_info("HOST_SLEEP_ACTIVATE failed: %d\n", ret);
858
859 return ret;
860}
861EXPORT_SYMBOL_GPL(lbs_suspend);
862
863int lbs_resume(struct lbs_private *priv)
864{
865 priv->fw_ready = 1;
866
867 /* Firmware doesn't seem to give us RX packets any more
868 until we send it some command. Might as well update */
869 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
870 0, 0, NULL);
871
872 netif_device_attach(priv->dev);
873 if (priv->mesh_dev)
874 netif_device_attach(priv->mesh_dev);
875
876 return 0;
877}
878EXPORT_SYMBOL_GPL(lbs_resume);
879
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200880/**
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400881 * @brief This function downloads firmware image, gets
882 * HW spec from firmware and set basic parameters to
883 * firmware.
884 *
Holger Schurig69f90322007-11-23 15:43:44 +0100885 * @param priv A pointer to struct lbs_private structure
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400886 * @return 0 or -1
887 */
Holger Schurig69f90322007-11-23 15:43:44 +0100888static int lbs_setup_firmware(struct lbs_private *priv)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400889{
890 int ret = -1;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400891
892 lbs_deb_enter(LBS_DEB_FW);
893
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400894 /*
895 * Read MAC address from HW
896 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000897 memset(priv->current_addr, 0xff, ETH_ALEN);
Dan Williams6e66f032007-12-11 12:42:16 -0500898 ret = lbs_update_hw_spec(priv);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400899 if (ret) {
900 ret = -1;
901 goto done;
902 }
903
Holger Schurig10078322007-11-15 18:05:47 -0500904 lbs_set_mac_packet_filter(priv);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400905
Dan Williams8e3c91b2007-12-11 15:50:59 -0500906 ret = lbs_get_data_rate(priv);
907 if (ret < 0) {
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400908 ret = -1;
909 goto done;
910 }
911
912 ret = 0;
913done:
914 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
915 return ret;
916}
917
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400918/**
919 * This function handles the timeout of command sending.
920 * It will re-send the same command again.
921 */
922static void command_timer_fn(unsigned long data)
923{
Holger Schurig69f90322007-11-23 15:43:44 +0100924 struct lbs_private *priv = (struct lbs_private *)data;
Dan Williamsddac4522007-12-11 13:49:39 -0500925 struct cmd_ctrl_node *node;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400926 unsigned long flags;
927
Dan Williamsddac4522007-12-11 13:49:39 -0500928 node = priv->cur_cmd;
929 if (node == NULL) {
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400930 lbs_deb_fw("ptempnode empty\n");
931 return;
932 }
933
Dan Williamsddac4522007-12-11 13:49:39 -0500934 if (!node->cmdbuf) {
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400935 lbs_deb_fw("cmd is NULL\n");
936 return;
937 }
938
David Woodhousee1258172007-12-11 23:42:49 -0500939 lbs_pr_info("command %x timed out\n", le16_to_cpu(node->cmdbuf->command));
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400940
David Woodhouseaa21c002007-12-08 20:04:36 +0000941 if (!priv->fw_ready)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400942 return;
943
David Woodhouseaa21c002007-12-08 20:04:36 +0000944 spin_lock_irqsave(&priv->driver_lock, flags);
945 priv->cur_cmd = NULL;
946 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400947
948 lbs_deb_fw("re-sending same command because of timeout\n");
Dan Williamsddac4522007-12-11 13:49:39 -0500949 lbs_queue_cmd(priv, node, 0);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400950
951 wake_up_interruptible(&priv->waitq);
952
953 return;
954}
955
Holger Schurig69f90322007-11-23 15:43:44 +0100956static int lbs_init_adapter(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -0400957{
Dan Williams954ee162007-08-20 11:43:25 -0400958 size_t bufsize;
959 int i, ret = 0;
960
961 /* Allocate buffer to store the BSSID list */
962 bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
David Woodhouseaa21c002007-12-08 20:04:36 +0000963 priv->networks = kzalloc(bufsize, GFP_KERNEL);
964 if (!priv->networks) {
Dan Williams954ee162007-08-20 11:43:25 -0400965 lbs_pr_err("Out of memory allocating beacons\n");
966 ret = -1;
967 goto out;
968 }
969
970 /* Initialize scan result lists */
David Woodhouseaa21c002007-12-08 20:04:36 +0000971 INIT_LIST_HEAD(&priv->network_free_list);
972 INIT_LIST_HEAD(&priv->network_list);
Dan Williams954ee162007-08-20 11:43:25 -0400973 for (i = 0; i < MAX_NETWORK_COUNT; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000974 list_add_tail(&priv->networks[i].list,
975 &priv->network_free_list);
Dan Williams954ee162007-08-20 11:43:25 -0400976 }
977
David Woodhouseaa21c002007-12-08 20:04:36 +0000978 priv->lbs_ps_confirm_sleep.seqnum = cpu_to_le16(++priv->seqnum);
979 priv->lbs_ps_confirm_sleep.command =
Dan Williams954ee162007-08-20 11:43:25 -0400980 cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000981 priv->lbs_ps_confirm_sleep.size =
Dan Williams954ee162007-08-20 11:43:25 -0400982 cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep));
David Woodhouseaa21c002007-12-08 20:04:36 +0000983 priv->lbs_ps_confirm_sleep.action =
Dan Williams954ee162007-08-20 11:43:25 -0400984 cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
985
David Woodhouseaa21c002007-12-08 20:04:36 +0000986 memset(priv->current_addr, 0xff, ETH_ALEN);
Dan Williams954ee162007-08-20 11:43:25 -0400987
David Woodhouseaa21c002007-12-08 20:04:36 +0000988 priv->connect_status = LBS_DISCONNECTED;
989 priv->mesh_connect_status = LBS_DISCONNECTED;
990 priv->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
991 priv->mode = IW_MODE_INFRA;
992 priv->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL;
993 priv->currentpacketfilter = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
994 priv->radioon = RADIO_ON;
995 priv->auto_rate = 1;
996 priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
997 priv->psmode = LBS802_11POWERMODECAM;
998 priv->psstate = PS_STATE_FULL_POWER;
Dan Williams954ee162007-08-20 11:43:25 -0400999
David Woodhouseaa21c002007-12-08 20:04:36 +00001000 mutex_init(&priv->lock);
Dan Williams954ee162007-08-20 11:43:25 -04001001
David Woodhouseaa21c002007-12-08 20:04:36 +00001002 setup_timer(&priv->command_timer, command_timer_fn,
Dan Williams954ee162007-08-20 11:43:25 -04001003 (unsigned long)priv);
1004
David Woodhouseaa21c002007-12-08 20:04:36 +00001005 INIT_LIST_HEAD(&priv->cmdfreeq);
1006 INIT_LIST_HEAD(&priv->cmdpendingq);
Dan Williams954ee162007-08-20 11:43:25 -04001007
David Woodhouseaa21c002007-12-08 20:04:36 +00001008 spin_lock_init(&priv->driver_lock);
1009 init_waitqueue_head(&priv->cmd_pending);
Dan Williams954ee162007-08-20 11:43:25 -04001010
1011 /* Allocate the command buffers */
Holger Schurig10078322007-11-15 18:05:47 -05001012 if (lbs_allocate_cmd_buffer(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001013 lbs_pr_err("Out of memory allocating command buffers\n");
1014 ret = -1;
1015 }
1016
1017out:
1018 return ret;
1019}
1020
Holger Schurig69f90322007-11-23 15:43:44 +01001021static void lbs_free_adapter(struct lbs_private *priv)
Holger Schurigac558ca2007-08-02 11:49:06 -04001022{
Holger Schurigac558ca2007-08-02 11:49:06 -04001023 lbs_deb_fw("free command buffer\n");
Holger Schurig10078322007-11-15 18:05:47 -05001024 lbs_free_cmd_buffer(priv);
Holger Schurigac558ca2007-08-02 11:49:06 -04001025
1026 lbs_deb_fw("free command_timer\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001027 del_timer(&priv->command_timer);
Holger Schurigac558ca2007-08-02 11:49:06 -04001028
1029 lbs_deb_fw("free scan results table\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001030 kfree(priv->networks);
1031 priv->networks = NULL;
Holger Schurigac558ca2007-08-02 11:49:06 -04001032}
1033
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001034/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001035 * @brief This function adds the card. it will probe the
Holger Schurig10078322007-11-15 18:05:47 -05001036 * card, allocate the lbs_priv and initialize the device.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001037 *
1038 * @param card A pointer to card
Holger Schurig69f90322007-11-23 15:43:44 +01001039 * @return A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001040 */
Holger Schurig69f90322007-11-23 15:43:44 +01001041struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001042{
1043 struct net_device *dev = NULL;
Holger Schurig69f90322007-11-23 15:43:44 +01001044 struct lbs_private *priv = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001045
Holger Schurig9012b282007-05-25 11:27:16 -04001046 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001047
1048 /* Allocate an Ethernet device and register it */
Holger Schurig69f90322007-11-23 15:43:44 +01001049 dev = alloc_etherdev(sizeof(struct lbs_private));
1050 if (!dev) {
Holger Schurig9012b282007-05-25 11:27:16 -04001051 lbs_pr_err("init ethX device failed\n");
Dan Williams954ee162007-08-20 11:43:25 -04001052 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001053 }
Dan Williams64f104e2007-08-20 11:45:16 -04001054 priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001055
Holger Schurig10078322007-11-15 18:05:47 -05001056 if (lbs_init_adapter(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001057 lbs_pr_err("failed to initialize adapter structure.\n");
1058 goto err_init_adapter;
1059 }
1060
Holger Schurig634b8f42007-05-25 13:05:16 -04001061 priv->dev = dev;
1062 priv->card = card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001063 priv->mesh_open = 0;
1064 priv->infra_open = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001065
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001066 /* Setup the OS Interface to our functions */
David Woodhouse8552855f2007-12-10 16:38:18 -05001067 dev->open = lbs_dev_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001068 dev->hard_start_xmit = lbs_hard_start_xmit;
David Woodhouse8552855f2007-12-10 16:38:18 -05001069 dev->stop = lbs_eth_stop;
Holger Schurig10078322007-11-15 18:05:47 -05001070 dev->set_mac_address = lbs_set_mac_address;
1071 dev->tx_timeout = lbs_tx_timeout;
1072 dev->get_stats = lbs_get_stats;
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001073 dev->watchdog_timeo = 5 * HZ;
Holger Schurig10078322007-11-15 18:05:47 -05001074 dev->ethtool_ops = &lbs_ethtool_ops;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001075#ifdef WIRELESS_EXT
Holger Schurig10078322007-11-15 18:05:47 -05001076 dev->wireless_handlers = (struct iw_handler_def *)&lbs_handler_def;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001077#endif
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001078 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
Holger Schurig10078322007-11-15 18:05:47 -05001079 dev->set_multicast_list = lbs_set_multicast_list;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001080
Dan Williams7732ca42007-05-25 13:13:25 -04001081 SET_NETDEV_DEV(dev, dmdev);
1082
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001083 priv->rtap_net_dev = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001084
Dan Williamsfe336152007-08-02 11:32:25 -04001085 lbs_deb_thread("Starting main thread...\n");
1086 init_waitqueue_head(&priv->waitq);
Holger Schurig10078322007-11-15 18:05:47 -05001087 priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
Dan Williamsfe336152007-08-02 11:32:25 -04001088 if (IS_ERR(priv->main_thread)) {
1089 lbs_deb_thread("Error creating main thread.\n");
David Woodhousee7deced2007-12-08 18:29:16 +00001090 goto err_init_adapter;
Dan Williamsfe336152007-08-02 11:32:25 -04001091 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001092
Holger Schurig10078322007-11-15 18:05:47 -05001093 priv->work_thread = create_singlethread_workqueue("lbs_worker");
1094 INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker);
1095 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
1096 INIT_WORK(&priv->sync_channel, lbs_sync_channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001097
David Woodhouse23a397a2007-12-11 18:56:42 -05001098 sprintf(priv->mesh_ssid, "mesh");
1099 priv->mesh_ssid_len = 4;
1100
David Woodhouse506e9022007-12-12 20:06:06 -05001101 priv->wol_criteria = 0xffffffff;
1102 priv->wol_gpio = 0xff;
1103
Dan Williams954ee162007-08-20 11:43:25 -04001104 goto done;
1105
Dan Williams954ee162007-08-20 11:43:25 -04001106err_init_adapter:
Holger Schurig10078322007-11-15 18:05:47 -05001107 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001108 free_netdev(dev);
1109 priv = NULL;
1110
1111done:
1112 lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv);
1113 return priv;
1114}
Holger Schurig10078322007-11-15 18:05:47 -05001115EXPORT_SYMBOL_GPL(lbs_add_card);
Dan Williams954ee162007-08-20 11:43:25 -04001116
1117
Holger Schurig69f90322007-11-23 15:43:44 +01001118int lbs_remove_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001119{
Dan Williams954ee162007-08-20 11:43:25 -04001120 struct net_device *dev = priv->dev;
1121 union iwreq_data wrqu;
1122
1123 lbs_deb_enter(LBS_DEB_MAIN);
1124
David Woodhouse23a397a2007-12-11 18:56:42 -05001125 lbs_remove_mesh(priv);
Holger Schurig10078322007-11-15 18:05:47 -05001126 lbs_remove_rtap(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001127
1128 dev = priv->dev;
Dan Williams954ee162007-08-20 11:43:25 -04001129
1130 cancel_delayed_work(&priv->scan_work);
1131 cancel_delayed_work(&priv->assoc_work);
1132 destroy_workqueue(priv->work_thread);
1133
David Woodhouseaa21c002007-12-08 20:04:36 +00001134 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
1135 priv->psmode = LBS802_11POWERMODECAM;
Holger Schurig10078322007-11-15 18:05:47 -05001136 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001137 }
1138
Dan Williams954ee162007-08-20 11:43:25 -04001139 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
1140 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1141 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
1142
1143 /* Stop the thread servicing the interrupts */
David Woodhouseaa21c002007-12-08 20:04:36 +00001144 priv->surpriseremoved = 1;
Dan Williams954ee162007-08-20 11:43:25 -04001145 kthread_stop(priv->main_thread);
1146
Holger Schurig10078322007-11-15 18:05:47 -05001147 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001148
1149 priv->dev = NULL;
1150 free_netdev(dev);
1151
1152 lbs_deb_leave(LBS_DEB_MAIN);
1153 return 0;
1154}
Holger Schurig10078322007-11-15 18:05:47 -05001155EXPORT_SYMBOL_GPL(lbs_remove_card);
Dan Williams954ee162007-08-20 11:43:25 -04001156
1157
Holger Schurig69f90322007-11-23 15:43:44 +01001158int lbs_start_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001159{
1160 struct net_device *dev = priv->dev;
1161 int ret = -1;
1162
1163 lbs_deb_enter(LBS_DEB_MAIN);
1164
1165 /* poke the firmware */
Holger Schurig10078322007-11-15 18:05:47 -05001166 ret = lbs_setup_firmware(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001167 if (ret)
1168 goto done;
1169
1170 /* init 802.11d */
Holger Schurig10078322007-11-15 18:05:47 -05001171 lbs_init_11d(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001172
1173 if (register_netdev(dev)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001174 lbs_pr_err("cannot register ethX device\n");
Dan Williams954ee162007-08-20 11:43:25 -04001175 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001176 }
David Woodhousee7deced2007-12-08 18:29:16 +00001177 if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
1178 lbs_pr_err("cannot register lbs_rtap attribute\n");
David Woodhouse020f3d02007-12-12 23:29:13 -05001179
1180 /* Enable mesh, if supported, and work out which TLV it uses.
1181 0x100 + 291 is an unofficial value used in 5.110.20.pXX
1182 0x100 + 37 is the official value used in 5.110.21.pXX
David Woodhouse7e226272007-12-14 22:53:41 -05001183 but we check them in that order because 20.pXX doesn't
David Woodhouse020f3d02007-12-12 23:29:13 -05001184 give an error -- it just silently fails. */
1185
1186 /* 5.110.20.pXX firmware will fail the command if the channel
1187 doesn't match the existing channel. But only if the TLV
1188 is correct. If the channel is wrong, _BOTH_ versions will
1189 give an error to 0x100+291, and allow 0x100+37 to succeed.
1190 It's just that 5.110.20.pXX will not have done anything
1191 useful */
1192
1193 lbs_update_channel(priv);
1194 priv->mesh_tlv = 0x100 + 291;
David Woodhouse86062132007-12-13 00:32:36 -05001195 if (lbs_mesh_config(priv, 1, priv->curbssparams.channel)) {
David Woodhouse020f3d02007-12-12 23:29:13 -05001196 priv->mesh_tlv = 0x100 + 37;
David Woodhouse86062132007-12-13 00:32:36 -05001197 if (lbs_mesh_config(priv, 1, priv->curbssparams.channel))
David Woodhouse020f3d02007-12-12 23:29:13 -05001198 priv->mesh_tlv = 0;
1199 }
1200 if (priv->mesh_tlv) {
1201 lbs_add_mesh(priv);
1202
1203 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
1204 lbs_pr_err("cannot register lbs_mesh attribute\n");
1205 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001206
Holger Schurig10078322007-11-15 18:05:47 -05001207 lbs_debugfs_init_one(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001208
Dan Williams954ee162007-08-20 11:43:25 -04001209 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001210
Dan Williams954ee162007-08-20 11:43:25 -04001211 ret = 0;
1212
Holger Schurig32a74b72007-05-25 12:04:31 -04001213done:
Dan Williams954ee162007-08-20 11:43:25 -04001214 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
Holger Schurig32a74b72007-05-25 12:04:31 -04001215 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001216}
Holger Schurig10078322007-11-15 18:05:47 -05001217EXPORT_SYMBOL_GPL(lbs_start_card);
Dan Williams954ee162007-08-20 11:43:25 -04001218
1219
Holger Schurig69f90322007-11-23 15:43:44 +01001220int lbs_stop_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001221{
1222 struct net_device *dev = priv->dev;
1223 int ret = -1;
1224 struct cmd_ctrl_node *cmdnode;
1225 unsigned long flags;
1226
1227 lbs_deb_enter(LBS_DEB_MAIN);
1228
1229 netif_stop_queue(priv->dev);
1230 netif_carrier_off(priv->dev);
1231
Holger Schurig10078322007-11-15 18:05:47 -05001232 lbs_debugfs_remove_one(priv);
David Woodhouse10bca0d2007-12-11 12:54:43 -05001233 device_remove_file(&dev->dev, &dev_attr_lbs_rtap);
David Woodhouse020f3d02007-12-12 23:29:13 -05001234 if (priv->mesh_tlv)
1235 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
Dan Williams954ee162007-08-20 11:43:25 -04001236
1237 /* Flush pending command nodes */
David Woodhouseaa21c002007-12-08 20:04:36 +00001238 spin_lock_irqsave(&priv->driver_lock, flags);
1239 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
Dan Williams954ee162007-08-20 11:43:25 -04001240 cmdnode->cmdwaitqwoken = 1;
1241 wake_up_interruptible(&cmdnode->cmdwait_q);
1242 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001243 spin_unlock_irqrestore(&priv->driver_lock, flags);
Dan Williams954ee162007-08-20 11:43:25 -04001244
1245 unregister_netdev(dev);
1246
1247 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1248 return ret;
1249}
Holger Schurig10078322007-11-15 18:05:47 -05001250EXPORT_SYMBOL_GPL(lbs_stop_card);
Holger Schurig084708b2007-05-25 12:37:58 -04001251
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001252
Holger Schurig78523da2007-05-25 11:49:19 -04001253/**
1254 * @brief This function adds mshX interface
1255 *
Holger Schurig69f90322007-11-23 15:43:44 +01001256 * @param priv A pointer to the struct lbs_private structure
Holger Schurig78523da2007-05-25 11:49:19 -04001257 * @return 0 if successful, -X otherwise
1258 */
David Woodhouse23a397a2007-12-11 18:56:42 -05001259static int lbs_add_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001260{
1261 struct net_device *mesh_dev = NULL;
1262 int ret = 0;
1263
1264 lbs_deb_enter(LBS_DEB_MESH);
1265
1266 /* Allocate a virtual mesh device */
1267 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
1268 lbs_deb_mesh("init mshX device failed\n");
1269 ret = -ENOMEM;
1270 goto done;
1271 }
1272 mesh_dev->priv = priv;
1273 priv->mesh_dev = mesh_dev;
1274
David Woodhouse8552855f2007-12-10 16:38:18 -05001275 mesh_dev->open = lbs_dev_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001276 mesh_dev->hard_start_xmit = lbs_hard_start_xmit;
David Woodhouse8552855f2007-12-10 16:38:18 -05001277 mesh_dev->stop = lbs_mesh_stop;
Holger Schurig10078322007-11-15 18:05:47 -05001278 mesh_dev->get_stats = lbs_get_stats;
1279 mesh_dev->set_mac_address = lbs_set_mac_address;
1280 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
Holger Schurig634b8f42007-05-25 13:05:16 -04001281 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
1282 sizeof(priv->dev->dev_addr));
Holger Schurig78523da2007-05-25 11:49:19 -04001283
David Woodhouse23a397a2007-12-11 18:56:42 -05001284 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
Dan Williams7732ca42007-05-25 13:13:25 -04001285
Holger Schurig78523da2007-05-25 11:49:19 -04001286#ifdef WIRELESS_EXT
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04001287 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
Holger Schurig78523da2007-05-25 11:49:19 -04001288#endif
Holger Schurig78523da2007-05-25 11:49:19 -04001289 /* Register virtual mesh interface */
1290 ret = register_netdev(mesh_dev);
1291 if (ret) {
1292 lbs_pr_err("cannot register mshX virtual interface\n");
1293 goto err_free;
1294 }
1295
Holger Schurig10078322007-11-15 18:05:47 -05001296 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001297 if (ret)
1298 goto err_unregister;
1299
1300 /* Everything successful */
1301 ret = 0;
1302 goto done;
1303
Holger Schurig78523da2007-05-25 11:49:19 -04001304err_unregister:
1305 unregister_netdev(mesh_dev);
1306
1307err_free:
1308 free_netdev(mesh_dev);
1309
1310done:
1311 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
1312 return ret;
1313}
Holger Schurig10078322007-11-15 18:05:47 -05001314EXPORT_SYMBOL_GPL(lbs_add_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001315
Holger Schurig084708b2007-05-25 12:37:58 -04001316
David Woodhouse23a397a2007-12-11 18:56:42 -05001317static void lbs_remove_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001318{
1319 struct net_device *mesh_dev;
1320
Dan Williams954ee162007-08-20 11:43:25 -04001321 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig78523da2007-05-25 11:49:19 -04001322
1323 if (!priv)
1324 goto out;
1325
1326 mesh_dev = priv->mesh_dev;
David Woodhouse23a397a2007-12-11 18:56:42 -05001327 if (!mesh_dev)
1328 goto out;
Holger Schurig78523da2007-05-25 11:49:19 -04001329
1330 netif_stop_queue(mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -04001331 netif_carrier_off(priv->mesh_dev);
Holger Schurig78523da2007-05-25 11:49:19 -04001332
Holger Schurig10078322007-11-15 18:05:47 -05001333 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001334 unregister_netdev(mesh_dev);
1335
David Woodhouse23a397a2007-12-11 18:56:42 -05001336 priv->mesh_dev = NULL;
Holger Schurig78523da2007-05-25 11:49:19 -04001337 free_netdev(mesh_dev);
1338
1339out:
Dan Williams954ee162007-08-20 11:43:25 -04001340 lbs_deb_leave(LBS_DEB_MAIN);
Holger Schurig78523da2007-05-25 11:49:19 -04001341}
Holger Schurig10078322007-11-15 18:05:47 -05001342EXPORT_SYMBOL_GPL(lbs_remove_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001343
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001344/**
1345 * @brief This function finds the CFP in
1346 * region_cfp_table based on region and band parameter.
1347 *
1348 * @param region The region code
1349 * @param band The band
1350 * @param cfp_no A pointer to CFP number
1351 * @return A pointer to CFP
1352 */
Holger Schurig10078322007-11-15 18:05:47 -05001353struct chan_freq_power *lbs_get_region_cfp_table(u8 region, u8 band, int *cfp_no)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001354{
1355 int i, end;
1356
Holger Schurig9012b282007-05-25 11:27:16 -04001357 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001358
Denis Chengff8ac602007-09-02 18:30:18 +08001359 end = ARRAY_SIZE(region_cfp_table);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001360
1361 for (i = 0; i < end ; i++) {
Holger Schurig9012b282007-05-25 11:27:16 -04001362 lbs_deb_main("region_cfp_table[i].region=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001363 region_cfp_table[i].region);
1364 if (region_cfp_table[i].region == region) {
1365 *cfp_no = region_cfp_table[i].cfp_no_BG;
Holger Schurig9012b282007-05-25 11:27:16 -04001366 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001367 return region_cfp_table[i].cfp_BG;
1368 }
1369 }
1370
Holger Schurig9012b282007-05-25 11:27:16 -04001371 lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001372 return NULL;
1373}
1374
Holger Schurig69f90322007-11-23 15:43:44 +01001375int lbs_set_regiontable(struct lbs_private *priv, u8 region, u8 band)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001376{
Holger Schurig9012b282007-05-25 11:27:16 -04001377 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001378 int i = 0;
1379
1380 struct chan_freq_power *cfp;
1381 int cfp_no;
1382
Holger Schurig9012b282007-05-25 11:27:16 -04001383 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001384
David Woodhouseaa21c002007-12-08 20:04:36 +00001385 memset(priv->region_channel, 0, sizeof(priv->region_channel));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001386
1387 {
Holger Schurig10078322007-11-15 18:05:47 -05001388 cfp = lbs_get_region_cfp_table(region, band, &cfp_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001389 if (cfp != NULL) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001390 priv->region_channel[i].nrcfp = cfp_no;
1391 priv->region_channel[i].CFP = cfp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001392 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001393 lbs_deb_main("wrong region code %#x in band B/G\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001394 region);
Holger Schurig9012b282007-05-25 11:27:16 -04001395 ret = -1;
1396 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001397 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001398 priv->region_channel[i].valid = 1;
1399 priv->region_channel[i].region = region;
1400 priv->region_channel[i].band = band;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001401 i++;
1402 }
Holger Schurig9012b282007-05-25 11:27:16 -04001403out:
1404 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1405 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001406}
1407
1408/**
1409 * @brief This function handles the interrupt. it will change PS
1410 * state if applicable. it will wake up main_thread to handle
1411 * the interrupt event as well.
1412 *
1413 * @param dev A pointer to net_device structure
1414 * @return n/a
1415 */
David Woodhouse4f679492007-12-10 14:58:37 -05001416void lbs_interrupt(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001417{
Holger Schuriged37b512007-05-25 11:52:42 -04001418 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001419
David Woodhouse4f679492007-12-10 14:58:37 -05001420 lbs_deb_thread("lbs_interrupt: intcounter=%d\n", priv->intcounter);
1421
David Woodhousef5a3ea62007-12-13 01:53:57 -05001422 if (!spin_is_locked(&priv->driver_lock)) {
David Woodhouse4f679492007-12-10 14:58:37 -05001423 printk(KERN_CRIT "%s called without driver_lock held\n", __func__);
1424 WARN_ON(1);
1425 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001426
David Woodhouseaa21c002007-12-08 20:04:36 +00001427 priv->intcounter++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001428
David Woodhouse4f679492007-12-10 14:58:37 -05001429 if (priv->psstate == PS_STATE_SLEEP)
David Woodhouseaa21c002007-12-08 20:04:36 +00001430 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001431
Dan Williamsfe336152007-08-02 11:32:25 -04001432 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001433
Holger Schuriged37b512007-05-25 11:52:42 -04001434 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001435}
Holger Schurig10078322007-11-15 18:05:47 -05001436EXPORT_SYMBOL_GPL(lbs_interrupt);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001437
Holger Schurig69f90322007-11-23 15:43:44 +01001438int lbs_reset_device(struct lbs_private *priv)
Dan Williamseedc2a32007-08-02 11:36:22 -04001439{
1440 int ret;
1441
1442 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001443 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RESET,
Dan Williamseedc2a32007-08-02 11:36:22 -04001444 CMD_ACT_HALT, 0, 0, NULL);
1445 msleep_interruptible(10);
1446
1447 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1448 return ret;
1449}
Holger Schurig10078322007-11-15 18:05:47 -05001450EXPORT_SYMBOL_GPL(lbs_reset_device);
Dan Williamseedc2a32007-08-02 11:36:22 -04001451
Andres Salomon4fb910f2007-11-20 17:43:45 -05001452static int __init lbs_init_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001453{
Holger Schurig9012b282007-05-25 11:27:16 -04001454 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001455 lbs_debugfs_init();
Holger Schurig084708b2007-05-25 12:37:58 -04001456 lbs_deb_leave(LBS_DEB_MAIN);
1457 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001458}
1459
Andres Salomon4fb910f2007-11-20 17:43:45 -05001460static void __exit lbs_exit_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001461{
Holger Schurig9012b282007-05-25 11:27:16 -04001462 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001463
Holger Schurig10078322007-11-15 18:05:47 -05001464 lbs_debugfs_remove();
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001465
Holger Schurig9012b282007-05-25 11:27:16 -04001466 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001467}
1468
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001469/*
1470 * rtap interface support fuctions
1471 */
1472
Holger Schurig10078322007-11-15 18:05:47 -05001473static int lbs_rtap_open(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001474{
David Woodhouse8552855f2007-12-10 16:38:18 -05001475 /* Yes, _stop_ the queue. Because we don't support injection */
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001476 netif_carrier_off(dev);
1477 netif_stop_queue(dev);
1478 return 0;
1479}
1480
Holger Schurig10078322007-11-15 18:05:47 -05001481static int lbs_rtap_stop(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001482{
1483 return 0;
1484}
1485
Holger Schurig10078322007-11-15 18:05:47 -05001486static int lbs_rtap_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001487{
1488 netif_stop_queue(dev);
David Woodhouse8552855f2007-12-10 16:38:18 -05001489 return NETDEV_TX_BUSY;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001490}
1491
Holger Schurig10078322007-11-15 18:05:47 -05001492static struct net_device_stats *lbs_rtap_get_stats(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001493{
Holger Schurig69f90322007-11-23 15:43:44 +01001494 struct lbs_private *priv = dev->priv;
David Woodhoused9268fb2007-12-09 16:22:21 -05001495 return &priv->stats;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001496}
1497
1498
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001499static void lbs_remove_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001500{
1501 if (priv->rtap_net_dev == NULL)
1502 return;
1503 unregister_netdev(priv->rtap_net_dev);
David Woodhoused9268fb2007-12-09 16:22:21 -05001504 free_netdev(priv->rtap_net_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001505 priv->rtap_net_dev = NULL;
1506}
1507
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001508static int lbs_add_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001509{
1510 int rc = 0;
David Woodhoused9268fb2007-12-09 16:22:21 -05001511 struct net_device *rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001512
1513 if (priv->rtap_net_dev)
1514 return -EPERM;
1515
David Woodhoused9268fb2007-12-09 16:22:21 -05001516 rtap_dev = alloc_netdev(0, "rtap%d", ether_setup);
1517 if (rtap_dev == NULL)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001518 return -ENOMEM;
1519
David Woodhouse121947c2007-12-09 19:54:11 -05001520 memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN);
David Woodhoused9268fb2007-12-09 16:22:21 -05001521 rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP;
1522 rtap_dev->open = lbs_rtap_open;
1523 rtap_dev->stop = lbs_rtap_stop;
1524 rtap_dev->get_stats = lbs_rtap_get_stats;
1525 rtap_dev->hard_start_xmit = lbs_rtap_hard_start_xmit;
1526 rtap_dev->set_multicast_list = lbs_set_multicast_list;
1527 rtap_dev->priv = priv;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001528
David Woodhoused9268fb2007-12-09 16:22:21 -05001529 rc = register_netdev(rtap_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001530 if (rc) {
David Woodhoused9268fb2007-12-09 16:22:21 -05001531 free_netdev(rtap_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001532 return rc;
1533 }
David Woodhoused9268fb2007-12-09 16:22:21 -05001534 priv->rtap_net_dev = rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001535
1536 return 0;
1537}
1538
1539
Holger Schurig10078322007-11-15 18:05:47 -05001540module_init(lbs_init_module);
1541module_exit(lbs_exit_module);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001542
Holger Schurig084708b2007-05-25 12:37:58 -04001543MODULE_DESCRIPTION("Libertas WLAN Driver Library");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001544MODULE_AUTHOR("Marvell International Ltd.");
1545MODULE_LICENSE("GPL");