blob: 74353e1d72ff29b17cf99b0c63f097e6d760d750 [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 Cobo965f8bb2007-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 Cobo965f8bb2007-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 Cobo965f8bb2007-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 Cobo965f8bb2007-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 Cobo965f8bb2007-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 Cobo965f8bb2007-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 Cobo965f8bb2007-08-02 13:16:55 -0400282 return strlen(buf);
David Woodhouseaa21c002007-12-08 20:04:36 +0000283 if (priv->monitormode == LBS_MONITOR_OFF) {
David Woodhouse85528552007-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 Cobo965f8bb2007-08-02 13:16:55 -0400291 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000292 priv->monitormode = monitor_mode;
Luis Carlos Cobo965f8bb2007-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 Cobo965f8bb2007-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 Cobo965f8bb2007-08-02 13:16:55 -0400308 }
309
Holger Schurig10078322007-11-15 18:05:47 -0500310 lbs_prepare_and_send_command(priv,
Luis Carlos Cobo965f8bb2007-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 Cobo965f8bb2007-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 Cobo965f8bb2007-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 Cobo965f8bb2007-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 Woodhouse85528552007-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 Woodhouse85528552007-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 Woodhouse85528552007-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 Woodhouse85528552007-12-10 16:38:18 -0500391 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392
David Woodhouse85528552007-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 Woodhouse85528552007-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 Woodhouse85528552007-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 Woodhouse85528552007-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 Woodhouse85528552007-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 Woodhouse85528552007-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 Woodhouse85528552007-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 Woodhouse85528552007-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 Woodhouse85528552007-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 Woodhouse85528552007-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 Woodhouse85528552007-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 Woodhouse85528552007-12-10 16:38:18 -0500454
455 netif_stop_queue(dev);
David Woodhouse7e226272007-12-14 22:53:41 -0500456
David Woodhouse85528552007-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
David Woodhouse354eca92007-12-17 19:22:40 -0500479 /* More often than not, this actually happens because the
480 firmware has crapped itself -- rather than just a very
481 busy medium. So send a harmless command, and if/when
482 _that_ times out, we'll kick it in the head. */
483 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
484 0, 0, NULL);
485
Holger Schurig9012b282007-05-25 11:27:16 -0400486 lbs_deb_leave(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200487}
488
David Woodhousee775ed72007-12-06 14:36:11 +0000489void lbs_host_to_card_done(struct lbs_private *priv)
490{
David Woodhousea63b22b2007-12-08 20:56:44 +0000491 unsigned long flags;
492
493 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhousee775ed72007-12-06 14:36:11 +0000494
495 priv->dnld_sent = DNLD_RES_RECEIVED;
496
497 /* Wake main thread if commands are pending */
David Woodhousea27b9f92007-12-12 00:41:51 -0500498 if (!priv->cur_cmd || priv->tx_pending_len > 0)
David Woodhousee775ed72007-12-06 14:36:11 +0000499 wake_up_interruptible(&priv->waitq);
500
David Woodhousea63b22b2007-12-08 20:56:44 +0000501 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhousee775ed72007-12-06 14:36:11 +0000502}
503EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
504
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200505/**
506 * @brief This function returns the network statistics
507 *
Holger Schurig69f90322007-11-23 15:43:44 +0100508 * @param dev A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200509 * @return A pointer to net_device_stats structure
510 */
Holger Schurig10078322007-11-15 18:05:47 -0500511static struct net_device_stats *lbs_get_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200512{
Holger Schurig69f90322007-11-23 15:43:44 +0100513 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200514
515 return &priv->stats;
516}
517
Holger Schurig10078322007-11-15 18:05:47 -0500518static int lbs_set_mac_address(struct net_device *dev, void *addr)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200519{
520 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100521 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200522 struct sockaddr *phwaddr = addr;
523
Holger Schurig9012b282007-05-25 11:27:16 -0400524 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200525
Luis Carlos Cobo Rus0a0d08a2007-05-25 23:05:27 -0400526 /* In case it was called from the mesh device */
527 dev = priv->dev ;
528
David Woodhouseaa21c002007-12-08 20:04:36 +0000529 memset(priv->current_addr, 0, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200530
531 /* dev->dev_addr is 8 bytes */
Holger Schurigece56192007-08-02 11:53:06 -0400532 lbs_deb_hex(LBS_DEB_NET, "dev->dev_addr", dev->dev_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200533
Holger Schurigece56192007-08-02 11:53:06 -0400534 lbs_deb_hex(LBS_DEB_NET, "addr", phwaddr->sa_data, ETH_ALEN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000535 memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200536
Holger Schurig10078322007-11-15 18:05:47 -0500537 ret = lbs_prepare_and_send_command(priv, CMD_802_11_MAC_ADDRESS,
Dan Williams0aef64d2007-08-02 11:31:18 -0400538 CMD_ACT_SET,
539 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200540
541 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400542 lbs_deb_net("set MAC address failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200543 ret = -1;
544 goto done;
545 }
546
David Woodhouseaa21c002007-12-08 20:04:36 +0000547 lbs_deb_hex(LBS_DEB_NET, "priv->macaddr", priv->current_addr, ETH_ALEN);
548 memcpy(dev->dev_addr, priv->current_addr, ETH_ALEN);
Holger Schurig78523da2007-05-25 11:49:19 -0400549 if (priv->mesh_dev)
David Woodhouseaa21c002007-12-08 20:04:36 +0000550 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200551
552done:
Holger Schurig9012b282007-05-25 11:27:16 -0400553 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200554 return ret;
555}
556
David Woodhouseaa21c002007-12-08 20:04:36 +0000557static int lbs_copy_multicast_address(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200558 struct net_device *dev)
559{
560 int i = 0;
561 struct dev_mc_list *mcptr = dev->mc_list;
562
563 for (i = 0; i < dev->mc_count; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000564 memcpy(&priv->multicastlist[i], mcptr->dmi_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200565 mcptr = mcptr->next;
566 }
567
568 return i;
569
570}
571
Holger Schurig10078322007-11-15 18:05:47 -0500572static void lbs_set_multicast_list(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200573{
Holger Schurig69f90322007-11-23 15:43:44 +0100574 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200575 int oldpacketfilter;
Joe Perches0795af52007-10-03 17:59:30 -0700576 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200577
Holger Schurig9012b282007-05-25 11:27:16 -0400578 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200579
David Woodhouseaa21c002007-12-08 20:04:36 +0000580 oldpacketfilter = priv->currentpacketfilter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200581
582 if (dev->flags & IFF_PROMISC) {
Holger Schurig9012b282007-05-25 11:27:16 -0400583 lbs_deb_net("enable promiscuous mode\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000584 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400585 CMD_ACT_MAC_PROMISCUOUS_ENABLE;
David Woodhouseaa21c002007-12-08 20:04:36 +0000586 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400587 ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE |
588 CMD_ACT_MAC_MULTICAST_ENABLE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200589 } else {
590 /* Multicast */
David Woodhouseaa21c002007-12-08 20:04:36 +0000591 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400592 ~CMD_ACT_MAC_PROMISCUOUS_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200593
594 if (dev->flags & IFF_ALLMULTI || dev->mc_count >
595 MRVDRV_MAX_MULTICAST_LIST_SIZE) {
Holger Schurig9012b282007-05-25 11:27:16 -0400596 lbs_deb_net( "enabling all multicast\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000597 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400598 CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
David Woodhouseaa21c002007-12-08 20:04:36 +0000599 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400600 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200601 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +0000602 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400603 ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604
605 if (!dev->mc_count) {
Holger Schurig9012b282007-05-25 11:27:16 -0400606 lbs_deb_net("no multicast addresses, "
607 "disabling multicast\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000608 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400609 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610 } else {
611 int i;
612
David Woodhouseaa21c002007-12-08 20:04:36 +0000613 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400614 CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200615
David Woodhouseaa21c002007-12-08 20:04:36 +0000616 priv->nr_of_multicastmacaddr =
617 lbs_copy_multicast_address(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200618
Holger Schurig9012b282007-05-25 11:27:16 -0400619 lbs_deb_net("multicast addresses: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200620 dev->mc_count);
621
622 for (i = 0; i < dev->mc_count; i++) {
Joe Perches0795af52007-10-03 17:59:30 -0700623 lbs_deb_net("Multicast address %d:%s\n",
624 i, print_mac(mac,
David Woodhouseaa21c002007-12-08 20:04:36 +0000625 priv->multicastlist[i]));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200626 }
Holger Schurig9012b282007-05-25 11:27:16 -0400627 /* send multicast addresses to firmware */
Holger Schurig10078322007-11-15 18:05:47 -0500628 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400629 CMD_MAC_MULTICAST_ADR,
630 CMD_ACT_SET, 0, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200631 NULL);
632 }
633 }
634 }
635
David Woodhouseaa21c002007-12-08 20:04:36 +0000636 if (priv->currentpacketfilter != oldpacketfilter) {
Holger Schurig10078322007-11-15 18:05:47 -0500637 lbs_set_mac_packet_filter(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200638 }
639
Holger Schurig9012b282007-05-25 11:27:16 -0400640 lbs_deb_leave(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641}
642
643/**
Holger Schurig10078322007-11-15 18:05:47 -0500644 * @brief This function handles the major jobs in the LBS driver.
Holger Schurig9012b282007-05-25 11:27:16 -0400645 * It handles all events generated by firmware, RX data received
646 * from firmware and TX data sent from kernel.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200647 *
Holger Schurig10078322007-11-15 18:05:47 -0500648 * @param data A pointer to lbs_thread structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200649 * @return 0
650 */
Holger Schurig10078322007-11-15 18:05:47 -0500651static int lbs_thread(void *data)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200652{
Dan Williamsfe336152007-08-02 11:32:25 -0400653 struct net_device *dev = data;
Holger Schurig69f90322007-11-23 15:43:44 +0100654 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200655 wait_queue_t wait;
656 u8 ireg = 0;
657
Holger Schurig9012b282007-05-25 11:27:16 -0400658 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200659
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200660 init_waitqueue_entry(&wait, current);
661
662 for (;;) {
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500663 int shouldsleep;
664
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000665 lbs_deb_thread( "main-thread 111: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000666 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200667
Dan Williamsfe336152007-08-02 11:32:25 -0400668 add_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200669 set_current_state(TASK_INTERRUPTIBLE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000670 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000671
David Woodhoused9f88702007-12-13 21:48:00 -0500672 if (kthread_should_stop())
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500673 shouldsleep = 0; /* Bye */
David Woodhoused9f88702007-12-13 21:48:00 -0500674 else if (priv->surpriseremoved)
675 shouldsleep = 1; /* We need to wait until we're _told_ to die */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500676 else if (priv->psstate == PS_STATE_SLEEP)
677 shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */
678 else if (priv->intcounter)
679 shouldsleep = 0; /* Interrupt pending. Deal with it now */
David Woodhouse2a345092007-12-15 19:33:43 -0500680 else if (priv->cmd_timed_out)
681 shouldsleep = 0; /* Command timed out. Recover */
David Woodhouseb15152a2007-12-11 11:55:37 -0500682 else if (!priv->fw_ready)
683 shouldsleep = 1; /* Firmware not ready. We're waiting for it */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500684 else if (priv->dnld_sent)
685 shouldsleep = 1; /* Something is en route to the device already */
David Woodhouse2eb188a2007-12-09 23:54:27 -0500686 else if (priv->tx_pending_len > 0)
687 shouldsleep = 0; /* We've a packet to send */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500688 else if (priv->cur_cmd)
689 shouldsleep = 1; /* Can't send a command; one already running */
690 else if (!list_empty(&priv->cmdpendingq))
691 shouldsleep = 0; /* We have a command to send */
692 else
693 shouldsleep = 1; /* No command */
694
695 if (shouldsleep) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000696 lbs_deb_thread("main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000697 priv->connect_status, priv->intcounter,
698 priv->psmode, priv->psstate);
699 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200700 schedule();
701 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000702 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200703
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000704 lbs_deb_thread("main-thread 222 (waking up): intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000705 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200706
707 set_current_state(TASK_RUNNING);
Dan Williamsfe336152007-08-02 11:32:25 -0400708 remove_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000710 lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000711 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200712
David Woodhoused9f88702007-12-13 21:48:00 -0500713 if (kthread_should_stop()) {
714 lbs_deb_thread("main-thread: break from main thread\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200715 break;
716 }
717
David Woodhoused9f88702007-12-13 21:48:00 -0500718 if (priv->surpriseremoved) {
719 lbs_deb_thread("adapter removed; waiting to die...\n");
720 continue;
721 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200722
David Woodhouseaa21c002007-12-08 20:04:36 +0000723 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000724
David Woodhouseaa21c002007-12-08 20:04:36 +0000725 if (priv->intcounter) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200726 u8 int_status;
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000727
David Woodhouseaa21c002007-12-08 20:04:36 +0000728 priv->intcounter = 0;
Holger Schurig208fdd22007-05-25 12:17:06 -0400729 int_status = priv->hw_get_int_status(priv, &ireg);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200730
731 if (int_status) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000732 lbs_deb_thread("main-thread: reading HOST_INT_STATUS_REG failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000733 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200734 continue;
735 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000736 priv->hisregcpy |= ireg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200737 }
738
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000739 lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000740 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741
742 /* command response? */
David Woodhouseaa21c002007-12-08 20:04:36 +0000743 if (priv->hisregcpy & MRVDRV_CMD_UPLD_RDY) {
Holger Schurig9012b282007-05-25 11:27:16 -0400744 lbs_deb_thread("main-thread: cmd response ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200745
David Woodhouseaa21c002007-12-08 20:04:36 +0000746 priv->hisregcpy &= ~MRVDRV_CMD_UPLD_RDY;
747 spin_unlock_irq(&priv->driver_lock);
Holger Schurig10078322007-11-15 18:05:47 -0500748 lbs_process_rx_command(priv);
David Woodhouseaa21c002007-12-08 20:04:36 +0000749 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200750 }
751
David Woodhouse2a345092007-12-15 19:33:43 -0500752 if (priv->cmd_timed_out && priv->cur_cmd) {
753 struct cmd_ctrl_node *cmdnode = priv->cur_cmd;
754
755 if (++priv->nr_retries > 10) {
756 lbs_pr_info("Excessive timeouts submitting command %x\n",
757 le16_to_cpu(cmdnode->cmdbuf->command));
758 lbs_complete_command(priv, cmdnode, -ETIMEDOUT);
759 priv->nr_retries = 0;
760 } else {
761 priv->cur_cmd = NULL;
762 lbs_pr_info("requeueing command %x due to timeout (#%d)\n",
763 le16_to_cpu(cmdnode->cmdbuf->command), priv->nr_retries);
764
765 /* Stick it back at the _top_ of the pending queue
766 for immediate resubmission */
767 list_add(&cmdnode->list, &priv->cmdpendingq);
768 }
769 }
770 priv->cmd_timed_out = 0;
771
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200772 /* Any Card Event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000773 if (priv->hisregcpy & MRVDRV_CARDEVENT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400774 lbs_deb_thread("main-thread: Card Event Activity\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200775
David Woodhouseaa21c002007-12-08 20:04:36 +0000776 priv->hisregcpy &= ~MRVDRV_CARDEVENT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200777
Holger Schurig208fdd22007-05-25 12:17:06 -0400778 if (priv->hw_read_event_cause(priv)) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000779 lbs_pr_alert("main-thread: hw_read_event_cause failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000780 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200781 continue;
782 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000783 spin_unlock_irq(&priv->driver_lock);
Holger Schurig10078322007-11-15 18:05:47 -0500784 lbs_process_event(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200785 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000786 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200787
David Woodhouseb15152a2007-12-11 11:55:37 -0500788 if (!priv->fw_ready)
789 continue;
790
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200791 /* Check if we need to confirm Sleep Request received previously */
David Woodhouseaa21c002007-12-08 20:04:36 +0000792 if (priv->psstate == PS_STATE_PRE_SLEEP &&
793 !priv->dnld_sent && !priv->cur_cmd) {
794 if (priv->connect_status == LBS_CONNECTED) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000795 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 +0000796 priv->intcounter, priv->currenttxskb, priv->dnld_sent, priv->cur_cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200797
David Woodhouseaa21c002007-12-08 20:04:36 +0000798 lbs_ps_confirm_sleep(priv, (u16) priv->psmode);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000799 } else {
800 /* workaround for firmware sending
801 * deauth/linkloss event immediately
802 * after sleep request; remove this
803 * after firmware fixes it
804 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000805 priv->psstate = PS_STATE_AWAKE;
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000806 lbs_pr_alert("main-thread: ignore PS_SleepConfirm in non-connected state\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200807 }
808 }
809
810 /* The PS state is changed during processing of Sleep Request
811 * event above
812 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000813 if ((priv->psstate == PS_STATE_SLEEP) ||
814 (priv->psstate == PS_STATE_PRE_SLEEP))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200815 continue;
816
817 /* Execute the next command */
David Woodhouseaa21c002007-12-08 20:04:36 +0000818 if (!priv->dnld_sent && !priv->cur_cmd)
Holger Schurig10078322007-11-15 18:05:47 -0500819 lbs_execute_next_command(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820
821 /* Wake-up command waiters which can't sleep in
Holger Schurig10078322007-11-15 18:05:47 -0500822 * lbs_prepare_and_send_command
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200823 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000824 if (!list_empty(&priv->cmdpendingq))
825 wake_up_all(&priv->cmd_pending);
David Woodhouse2eb188a2007-12-09 23:54:27 -0500826
827 spin_lock_irq(&priv->driver_lock);
828 if (!priv->dnld_sent && priv->tx_pending_len > 0) {
829 int ret = priv->hw_host_to_card(priv, MVMS_DAT,
830 priv->tx_pending_buf,
831 priv->tx_pending_len);
832 if (ret) {
833 lbs_deb_tx("host_to_card failed %d\n", ret);
834 priv->dnld_sent = DNLD_RES_RECEIVED;
835 }
836 priv->tx_pending_len = 0;
837 if (!priv->currenttxskb) {
838 /* We can wake the queues immediately if we aren't
839 waiting for TX feedback */
840 if (priv->connect_status == LBS_CONNECTED)
841 netif_wake_queue(priv->dev);
842 if (priv->mesh_dev &&
843 priv->mesh_connect_status == LBS_CONNECTED)
844 netif_wake_queue(priv->mesh_dev);
845 }
846 }
847 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200848 }
849
David Woodhouseaa21c002007-12-08 20:04:36 +0000850 del_timer(&priv->command_timer);
851 wake_up_all(&priv->cmd_pending);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200852
Holger Schurig9012b282007-05-25 11:27:16 -0400853 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200854 return 0;
855}
856
David Woodhouseab25eca2007-12-12 17:38:56 -0500857static int lbs_suspend_callback(struct lbs_private *priv, unsigned long dummy,
858 struct cmd_header *cmd)
859{
860 lbs_deb_fw("HOST_SLEEP_ACTIVATE succeeded\n");
861
862 netif_device_detach(priv->dev);
863 if (priv->mesh_dev)
864 netif_device_detach(priv->mesh_dev);
865
866 priv->fw_ready = 0;
867 return 0;
868}
869
870
871int lbs_suspend(struct lbs_private *priv)
872{
873 struct cmd_header cmd;
874 int ret;
875
David Woodhouse506e9022007-12-12 20:06:06 -0500876 if (priv->wol_criteria == 0xffffffff) {
877 lbs_pr_info("Suspend attempt without configuring wake params!\n");
878 return -EINVAL;
879 }
880
David Woodhouseab25eca2007-12-12 17:38:56 -0500881 memset(&cmd, 0, sizeof(cmd));
David Woodhouse7e226272007-12-14 22:53:41 -0500882
David Woodhouseab25eca2007-12-12 17:38:56 -0500883 ret = __lbs_cmd(priv, CMD_802_11_HOST_SLEEP_ACTIVATE, &cmd,
884 sizeof(cmd), lbs_suspend_callback, 0);
885 if (ret)
886 lbs_pr_info("HOST_SLEEP_ACTIVATE failed: %d\n", ret);
887
888 return ret;
889}
890EXPORT_SYMBOL_GPL(lbs_suspend);
891
892int lbs_resume(struct lbs_private *priv)
893{
894 priv->fw_ready = 1;
895
896 /* Firmware doesn't seem to give us RX packets any more
897 until we send it some command. Might as well update */
898 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
899 0, 0, NULL);
900
901 netif_device_attach(priv->dev);
902 if (priv->mesh_dev)
903 netif_device_attach(priv->mesh_dev);
904
905 return 0;
906}
907EXPORT_SYMBOL_GPL(lbs_resume);
908
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200909/**
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400910 * @brief This function downloads firmware image, gets
911 * HW spec from firmware and set basic parameters to
912 * firmware.
913 *
Holger Schurig69f90322007-11-23 15:43:44 +0100914 * @param priv A pointer to struct lbs_private structure
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400915 * @return 0 or -1
916 */
Holger Schurig69f90322007-11-23 15:43:44 +0100917static int lbs_setup_firmware(struct lbs_private *priv)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400918{
919 int ret = -1;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400920
921 lbs_deb_enter(LBS_DEB_FW);
922
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400923 /*
924 * Read MAC address from HW
925 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000926 memset(priv->current_addr, 0xff, ETH_ALEN);
Dan Williams6e66f032007-12-11 12:42:16 -0500927 ret = lbs_update_hw_spec(priv);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400928 if (ret) {
929 ret = -1;
930 goto done;
931 }
932
Holger Schurig10078322007-11-15 18:05:47 -0500933 lbs_set_mac_packet_filter(priv);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400934
Dan Williams8e3c91b2007-12-11 15:50:59 -0500935 ret = lbs_get_data_rate(priv);
936 if (ret < 0) {
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400937 ret = -1;
938 goto done;
939 }
940
941 ret = 0;
942done:
943 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
944 return ret;
945}
946
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400947/**
948 * This function handles the timeout of command sending.
949 * It will re-send the same command again.
950 */
951static void command_timer_fn(unsigned long data)
952{
Holger Schurig69f90322007-11-23 15:43:44 +0100953 struct lbs_private *priv = (struct lbs_private *)data;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400954 unsigned long flags;
955
David Woodhouseaa21c002007-12-08 20:04:36 +0000956 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400957
David Woodhouse2a345092007-12-15 19:33:43 -0500958 if (!priv->cur_cmd) {
959 lbs_pr_info("Command timer expired; no pending command\n");
960 goto out;
961 }
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400962
David Woodhouse2a345092007-12-15 19:33:43 -0500963 lbs_pr_info("Command %x timed out\n", le16_to_cpu(priv->cur_cmd->cmdbuf->command));
964
965 priv->cmd_timed_out = 1;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400966 wake_up_interruptible(&priv->waitq);
David Woodhouse2a345092007-12-15 19:33:43 -0500967 out:
968 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400969}
970
Holger Schurig69f90322007-11-23 15:43:44 +0100971static int lbs_init_adapter(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -0400972{
Dan Williams954ee162007-08-20 11:43:25 -0400973 size_t bufsize;
974 int i, ret = 0;
975
976 /* Allocate buffer to store the BSSID list */
977 bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
David Woodhouseaa21c002007-12-08 20:04:36 +0000978 priv->networks = kzalloc(bufsize, GFP_KERNEL);
979 if (!priv->networks) {
Dan Williams954ee162007-08-20 11:43:25 -0400980 lbs_pr_err("Out of memory allocating beacons\n");
981 ret = -1;
982 goto out;
983 }
984
985 /* Initialize scan result lists */
David Woodhouseaa21c002007-12-08 20:04:36 +0000986 INIT_LIST_HEAD(&priv->network_free_list);
987 INIT_LIST_HEAD(&priv->network_list);
Dan Williams954ee162007-08-20 11:43:25 -0400988 for (i = 0; i < MAX_NETWORK_COUNT; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000989 list_add_tail(&priv->networks[i].list,
990 &priv->network_free_list);
Dan Williams954ee162007-08-20 11:43:25 -0400991 }
992
David Woodhouseaa21c002007-12-08 20:04:36 +0000993 priv->lbs_ps_confirm_sleep.seqnum = cpu_to_le16(++priv->seqnum);
994 priv->lbs_ps_confirm_sleep.command =
Dan Williams954ee162007-08-20 11:43:25 -0400995 cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000996 priv->lbs_ps_confirm_sleep.size =
Dan Williams954ee162007-08-20 11:43:25 -0400997 cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep));
David Woodhouseaa21c002007-12-08 20:04:36 +0000998 priv->lbs_ps_confirm_sleep.action =
Dan Williams954ee162007-08-20 11:43:25 -0400999 cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
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;
1008 priv->currentpacketfilter = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
1009 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,
Dan Williams954ee162007-08-20 11:43:25 -04001018 (unsigned long)priv);
1019
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");
1029 ret = -1;
1030 }
1031
1032out:
1033 return ret;
1034}
1035
Holger Schurig69f90322007-11-23 15:43:44 +01001036static void lbs_free_adapter(struct lbs_private *priv)
Holger Schurigac558ca2007-08-02 11:49:06 -04001037{
Holger Schurigac558ca2007-08-02 11:49:06 -04001038 lbs_deb_fw("free command buffer\n");
Holger Schurig10078322007-11-15 18:05:47 -05001039 lbs_free_cmd_buffer(priv);
Holger Schurigac558ca2007-08-02 11:49:06 -04001040
1041 lbs_deb_fw("free command_timer\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001042 del_timer(&priv->command_timer);
Holger Schurigac558ca2007-08-02 11:49:06 -04001043
1044 lbs_deb_fw("free scan results table\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001045 kfree(priv->networks);
1046 priv->networks = NULL;
Holger Schurigac558ca2007-08-02 11:49:06 -04001047}
1048
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001049/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001050 * @brief This function adds the card. it will probe the
Holger Schurig10078322007-11-15 18:05:47 -05001051 * card, allocate the lbs_priv and initialize the device.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001052 *
1053 * @param card A pointer to card
Holger Schurig69f90322007-11-23 15:43:44 +01001054 * @return A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001055 */
Holger Schurig69f90322007-11-23 15:43:44 +01001056struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001057{
1058 struct net_device *dev = NULL;
Holger Schurig69f90322007-11-23 15:43:44 +01001059 struct lbs_private *priv = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001060
Holger Schurig9012b282007-05-25 11:27:16 -04001061 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001062
1063 /* Allocate an Ethernet device and register it */
Holger Schurig69f90322007-11-23 15:43:44 +01001064 dev = alloc_etherdev(sizeof(struct lbs_private));
1065 if (!dev) {
Holger Schurig9012b282007-05-25 11:27:16 -04001066 lbs_pr_err("init ethX device failed\n");
Dan Williams954ee162007-08-20 11:43:25 -04001067 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001068 }
Dan Williams64f104e2007-08-20 11:45:16 -04001069 priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001070
Holger Schurig10078322007-11-15 18:05:47 -05001071 if (lbs_init_adapter(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001072 lbs_pr_err("failed to initialize adapter structure.\n");
1073 goto err_init_adapter;
1074 }
1075
Holger Schurig634b8f42007-05-25 13:05:16 -04001076 priv->dev = dev;
1077 priv->card = card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001078 priv->mesh_open = 0;
1079 priv->infra_open = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001080
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001081 /* Setup the OS Interface to our functions */
David Woodhouse85528552007-12-10 16:38:18 -05001082 dev->open = lbs_dev_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001083 dev->hard_start_xmit = lbs_hard_start_xmit;
David Woodhouse85528552007-12-10 16:38:18 -05001084 dev->stop = lbs_eth_stop;
Holger Schurig10078322007-11-15 18:05:47 -05001085 dev->set_mac_address = lbs_set_mac_address;
1086 dev->tx_timeout = lbs_tx_timeout;
1087 dev->get_stats = lbs_get_stats;
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001088 dev->watchdog_timeo = 5 * HZ;
Holger Schurig10078322007-11-15 18:05:47 -05001089 dev->ethtool_ops = &lbs_ethtool_ops;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001090#ifdef WIRELESS_EXT
Holger Schurig10078322007-11-15 18:05:47 -05001091 dev->wireless_handlers = (struct iw_handler_def *)&lbs_handler_def;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001092#endif
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001093 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
Holger Schurig10078322007-11-15 18:05:47 -05001094 dev->set_multicast_list = lbs_set_multicast_list;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001095
Dan Williams7732ca42007-05-25 13:13:25 -04001096 SET_NETDEV_DEV(dev, dmdev);
1097
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001098 priv->rtap_net_dev = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001099
Dan Williamsfe336152007-08-02 11:32:25 -04001100 lbs_deb_thread("Starting main thread...\n");
1101 init_waitqueue_head(&priv->waitq);
Holger Schurig10078322007-11-15 18:05:47 -05001102 priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
Dan Williamsfe336152007-08-02 11:32:25 -04001103 if (IS_ERR(priv->main_thread)) {
1104 lbs_deb_thread("Error creating main thread.\n");
David Woodhousee7deced2007-12-08 18:29:16 +00001105 goto err_init_adapter;
Dan Williamsfe336152007-08-02 11:32:25 -04001106 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001107
Holger Schurig10078322007-11-15 18:05:47 -05001108 priv->work_thread = create_singlethread_workqueue("lbs_worker");
1109 INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker);
1110 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
1111 INIT_WORK(&priv->sync_channel, lbs_sync_channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001112
David Woodhouse23a397a2007-12-11 18:56:42 -05001113 sprintf(priv->mesh_ssid, "mesh");
1114 priv->mesh_ssid_len = 4;
1115
David Woodhouse506e9022007-12-12 20:06:06 -05001116 priv->wol_criteria = 0xffffffff;
1117 priv->wol_gpio = 0xff;
1118
Dan Williams954ee162007-08-20 11:43:25 -04001119 goto done;
1120
Dan Williams954ee162007-08-20 11:43:25 -04001121err_init_adapter:
Holger Schurig10078322007-11-15 18:05:47 -05001122 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001123 free_netdev(dev);
1124 priv = NULL;
1125
1126done:
1127 lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv);
1128 return priv;
1129}
Holger Schurig10078322007-11-15 18:05:47 -05001130EXPORT_SYMBOL_GPL(lbs_add_card);
Dan Williams954ee162007-08-20 11:43:25 -04001131
1132
Holger Schurig69f90322007-11-23 15:43:44 +01001133int lbs_remove_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001134{
Dan Williams954ee162007-08-20 11:43:25 -04001135 struct net_device *dev = priv->dev;
1136 union iwreq_data wrqu;
1137
1138 lbs_deb_enter(LBS_DEB_MAIN);
1139
David Woodhouse23a397a2007-12-11 18:56:42 -05001140 lbs_remove_mesh(priv);
Holger Schurig10078322007-11-15 18:05:47 -05001141 lbs_remove_rtap(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001142
1143 dev = priv->dev;
Dan Williams954ee162007-08-20 11:43:25 -04001144
1145 cancel_delayed_work(&priv->scan_work);
1146 cancel_delayed_work(&priv->assoc_work);
1147 destroy_workqueue(priv->work_thread);
1148
David Woodhouseaa21c002007-12-08 20:04:36 +00001149 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
1150 priv->psmode = LBS802_11POWERMODECAM;
Holger Schurig10078322007-11-15 18:05:47 -05001151 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001152 }
1153
Dan Williams954ee162007-08-20 11:43:25 -04001154 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
1155 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1156 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
1157
1158 /* Stop the thread servicing the interrupts */
David Woodhouseaa21c002007-12-08 20:04:36 +00001159 priv->surpriseremoved = 1;
Dan Williams954ee162007-08-20 11:43:25 -04001160 kthread_stop(priv->main_thread);
1161
Holger Schurig10078322007-11-15 18:05:47 -05001162 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001163
1164 priv->dev = NULL;
1165 free_netdev(dev);
1166
1167 lbs_deb_leave(LBS_DEB_MAIN);
1168 return 0;
1169}
Holger Schurig10078322007-11-15 18:05:47 -05001170EXPORT_SYMBOL_GPL(lbs_remove_card);
Dan Williams954ee162007-08-20 11:43:25 -04001171
1172
Holger Schurig69f90322007-11-23 15:43:44 +01001173int lbs_start_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001174{
1175 struct net_device *dev = priv->dev;
1176 int ret = -1;
1177
1178 lbs_deb_enter(LBS_DEB_MAIN);
1179
1180 /* poke the firmware */
Holger Schurig10078322007-11-15 18:05:47 -05001181 ret = lbs_setup_firmware(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001182 if (ret)
1183 goto done;
1184
1185 /* init 802.11d */
Holger Schurig10078322007-11-15 18:05:47 -05001186 lbs_init_11d(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001187
1188 if (register_netdev(dev)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001189 lbs_pr_err("cannot register ethX device\n");
Dan Williams954ee162007-08-20 11:43:25 -04001190 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001191 }
David Woodhousee7deced2007-12-08 18:29:16 +00001192 if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
1193 lbs_pr_err("cannot register lbs_rtap attribute\n");
David Woodhouse020f3d02007-12-12 23:29:13 -05001194
1195 /* Enable mesh, if supported, and work out which TLV it uses.
1196 0x100 + 291 is an unofficial value used in 5.110.20.pXX
1197 0x100 + 37 is the official value used in 5.110.21.pXX
David Woodhouse7e226272007-12-14 22:53:41 -05001198 but we check them in that order because 20.pXX doesn't
David Woodhouse020f3d02007-12-12 23:29:13 -05001199 give an error -- it just silently fails. */
1200
1201 /* 5.110.20.pXX firmware will fail the command if the channel
1202 doesn't match the existing channel. But only if the TLV
1203 is correct. If the channel is wrong, _BOTH_ versions will
1204 give an error to 0x100+291, and allow 0x100+37 to succeed.
1205 It's just that 5.110.20.pXX will not have done anything
1206 useful */
1207
1208 lbs_update_channel(priv);
1209 priv->mesh_tlv = 0x100 + 291;
David Woodhouse86062132007-12-13 00:32:36 -05001210 if (lbs_mesh_config(priv, 1, priv->curbssparams.channel)) {
David Woodhouse020f3d02007-12-12 23:29:13 -05001211 priv->mesh_tlv = 0x100 + 37;
David Woodhouse86062132007-12-13 00:32:36 -05001212 if (lbs_mesh_config(priv, 1, priv->curbssparams.channel))
David Woodhouse020f3d02007-12-12 23:29:13 -05001213 priv->mesh_tlv = 0;
1214 }
1215 if (priv->mesh_tlv) {
1216 lbs_add_mesh(priv);
1217
1218 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
1219 lbs_pr_err("cannot register lbs_mesh attribute\n");
1220 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001221
Holger Schurig10078322007-11-15 18:05:47 -05001222 lbs_debugfs_init_one(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001223
Dan Williams954ee162007-08-20 11:43:25 -04001224 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001225
Dan Williams954ee162007-08-20 11:43:25 -04001226 ret = 0;
1227
Holger Schurig32a74b72007-05-25 12:04:31 -04001228done:
Dan Williams954ee162007-08-20 11:43:25 -04001229 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
Holger Schurig32a74b72007-05-25 12:04:31 -04001230 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001231}
Holger Schurig10078322007-11-15 18:05:47 -05001232EXPORT_SYMBOL_GPL(lbs_start_card);
Dan Williams954ee162007-08-20 11:43:25 -04001233
1234
Holger Schurig69f90322007-11-23 15:43:44 +01001235int lbs_stop_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001236{
1237 struct net_device *dev = priv->dev;
1238 int ret = -1;
1239 struct cmd_ctrl_node *cmdnode;
1240 unsigned long flags;
1241
1242 lbs_deb_enter(LBS_DEB_MAIN);
1243
1244 netif_stop_queue(priv->dev);
1245 netif_carrier_off(priv->dev);
1246
Holger Schurig10078322007-11-15 18:05:47 -05001247 lbs_debugfs_remove_one(priv);
David Woodhouse10bca0d2007-12-11 12:54:43 -05001248 device_remove_file(&dev->dev, &dev_attr_lbs_rtap);
David Woodhouse020f3d02007-12-12 23:29:13 -05001249 if (priv->mesh_tlv)
1250 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
Dan Williams954ee162007-08-20 11:43:25 -04001251
1252 /* Flush pending command nodes */
David Woodhouseaa21c002007-12-08 20:04:36 +00001253 spin_lock_irqsave(&priv->driver_lock, flags);
1254 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
David Woodhouseae125bf2007-12-15 04:22:52 -05001255 cmdnode->result = -ENOENT;
Dan Williams954ee162007-08-20 11:43:25 -04001256 cmdnode->cmdwaitqwoken = 1;
1257 wake_up_interruptible(&cmdnode->cmdwait_q);
1258 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001259 spin_unlock_irqrestore(&priv->driver_lock, flags);
Dan Williams954ee162007-08-20 11:43:25 -04001260
1261 unregister_netdev(dev);
1262
1263 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1264 return ret;
1265}
Holger Schurig10078322007-11-15 18:05:47 -05001266EXPORT_SYMBOL_GPL(lbs_stop_card);
Holger Schurig084708b2007-05-25 12:37:58 -04001267
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001268
Holger Schurig78523da2007-05-25 11:49:19 -04001269/**
1270 * @brief This function adds mshX interface
1271 *
Holger Schurig69f90322007-11-23 15:43:44 +01001272 * @param priv A pointer to the struct lbs_private structure
Holger Schurig78523da2007-05-25 11:49:19 -04001273 * @return 0 if successful, -X otherwise
1274 */
David Woodhouse23a397a2007-12-11 18:56:42 -05001275static int lbs_add_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001276{
1277 struct net_device *mesh_dev = NULL;
1278 int ret = 0;
1279
1280 lbs_deb_enter(LBS_DEB_MESH);
1281
1282 /* Allocate a virtual mesh device */
1283 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
1284 lbs_deb_mesh("init mshX device failed\n");
1285 ret = -ENOMEM;
1286 goto done;
1287 }
1288 mesh_dev->priv = priv;
1289 priv->mesh_dev = mesh_dev;
1290
David Woodhouse85528552007-12-10 16:38:18 -05001291 mesh_dev->open = lbs_dev_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001292 mesh_dev->hard_start_xmit = lbs_hard_start_xmit;
David Woodhouse85528552007-12-10 16:38:18 -05001293 mesh_dev->stop = lbs_mesh_stop;
Holger Schurig10078322007-11-15 18:05:47 -05001294 mesh_dev->get_stats = lbs_get_stats;
1295 mesh_dev->set_mac_address = lbs_set_mac_address;
1296 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
Holger Schurig634b8f42007-05-25 13:05:16 -04001297 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
1298 sizeof(priv->dev->dev_addr));
Holger Schurig78523da2007-05-25 11:49:19 -04001299
David Woodhouse23a397a2007-12-11 18:56:42 -05001300 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
Dan Williams7732ca42007-05-25 13:13:25 -04001301
Holger Schurig78523da2007-05-25 11:49:19 -04001302#ifdef WIRELESS_EXT
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04001303 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
Holger Schurig78523da2007-05-25 11:49:19 -04001304#endif
Holger Schurig78523da2007-05-25 11:49:19 -04001305 /* Register virtual mesh interface */
1306 ret = register_netdev(mesh_dev);
1307 if (ret) {
1308 lbs_pr_err("cannot register mshX virtual interface\n");
1309 goto err_free;
1310 }
1311
Holger Schurig10078322007-11-15 18:05:47 -05001312 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001313 if (ret)
1314 goto err_unregister;
1315
1316 /* Everything successful */
1317 ret = 0;
1318 goto done;
1319
Holger Schurig78523da2007-05-25 11:49:19 -04001320err_unregister:
1321 unregister_netdev(mesh_dev);
1322
1323err_free:
1324 free_netdev(mesh_dev);
1325
1326done:
1327 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
1328 return ret;
1329}
Holger Schurig10078322007-11-15 18:05:47 -05001330EXPORT_SYMBOL_GPL(lbs_add_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001331
Holger Schurig084708b2007-05-25 12:37:58 -04001332
David Woodhouse23a397a2007-12-11 18:56:42 -05001333static void lbs_remove_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001334{
1335 struct net_device *mesh_dev;
1336
Dan Williams954ee162007-08-20 11:43:25 -04001337 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig78523da2007-05-25 11:49:19 -04001338
1339 if (!priv)
1340 goto out;
1341
1342 mesh_dev = priv->mesh_dev;
David Woodhouse23a397a2007-12-11 18:56:42 -05001343 if (!mesh_dev)
1344 goto out;
Holger Schurig78523da2007-05-25 11:49:19 -04001345
1346 netif_stop_queue(mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -04001347 netif_carrier_off(priv->mesh_dev);
Holger Schurig78523da2007-05-25 11:49:19 -04001348
Holger Schurig10078322007-11-15 18:05:47 -05001349 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001350 unregister_netdev(mesh_dev);
1351
David Woodhouse23a397a2007-12-11 18:56:42 -05001352 priv->mesh_dev = NULL;
Holger Schurig78523da2007-05-25 11:49:19 -04001353 free_netdev(mesh_dev);
1354
1355out:
Dan Williams954ee162007-08-20 11:43:25 -04001356 lbs_deb_leave(LBS_DEB_MAIN);
Holger Schurig78523da2007-05-25 11:49:19 -04001357}
Holger Schurig10078322007-11-15 18:05:47 -05001358EXPORT_SYMBOL_GPL(lbs_remove_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001359
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001360/**
1361 * @brief This function finds the CFP in
1362 * region_cfp_table based on region and band parameter.
1363 *
1364 * @param region The region code
1365 * @param band The band
1366 * @param cfp_no A pointer to CFP number
1367 * @return A pointer to CFP
1368 */
Holger Schurig10078322007-11-15 18:05:47 -05001369struct chan_freq_power *lbs_get_region_cfp_table(u8 region, u8 band, int *cfp_no)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001370{
1371 int i, end;
1372
Holger Schurig9012b282007-05-25 11:27:16 -04001373 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001374
Denis Chengff8ac602007-09-02 18:30:18 +08001375 end = ARRAY_SIZE(region_cfp_table);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001376
1377 for (i = 0; i < end ; i++) {
Holger Schurig9012b282007-05-25 11:27:16 -04001378 lbs_deb_main("region_cfp_table[i].region=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001379 region_cfp_table[i].region);
1380 if (region_cfp_table[i].region == region) {
1381 *cfp_no = region_cfp_table[i].cfp_no_BG;
Holger Schurig9012b282007-05-25 11:27:16 -04001382 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001383 return region_cfp_table[i].cfp_BG;
1384 }
1385 }
1386
Holger Schurig9012b282007-05-25 11:27:16 -04001387 lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001388 return NULL;
1389}
1390
Holger Schurig69f90322007-11-23 15:43:44 +01001391int lbs_set_regiontable(struct lbs_private *priv, u8 region, u8 band)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001392{
Holger Schurig9012b282007-05-25 11:27:16 -04001393 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001394 int i = 0;
1395
1396 struct chan_freq_power *cfp;
1397 int cfp_no;
1398
Holger Schurig9012b282007-05-25 11:27:16 -04001399 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001400
David Woodhouseaa21c002007-12-08 20:04:36 +00001401 memset(priv->region_channel, 0, sizeof(priv->region_channel));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001402
1403 {
Holger Schurig10078322007-11-15 18:05:47 -05001404 cfp = lbs_get_region_cfp_table(region, band, &cfp_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001405 if (cfp != NULL) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001406 priv->region_channel[i].nrcfp = cfp_no;
1407 priv->region_channel[i].CFP = cfp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001408 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001409 lbs_deb_main("wrong region code %#x in band B/G\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001410 region);
Holger Schurig9012b282007-05-25 11:27:16 -04001411 ret = -1;
1412 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001413 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001414 priv->region_channel[i].valid = 1;
1415 priv->region_channel[i].region = region;
1416 priv->region_channel[i].band = band;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001417 i++;
1418 }
Holger Schurig9012b282007-05-25 11:27:16 -04001419out:
1420 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1421 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001422}
1423
1424/**
1425 * @brief This function handles the interrupt. it will change PS
1426 * state if applicable. it will wake up main_thread to handle
1427 * the interrupt event as well.
1428 *
1429 * @param dev A pointer to net_device structure
1430 * @return n/a
1431 */
David Woodhouse4f679492007-12-10 14:58:37 -05001432void lbs_interrupt(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001433{
Holger Schuriged37b512007-05-25 11:52:42 -04001434 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001435
David Woodhouse4f679492007-12-10 14:58:37 -05001436 lbs_deb_thread("lbs_interrupt: intcounter=%d\n", priv->intcounter);
1437
David Woodhousef5a3ea62007-12-13 01:53:57 -05001438 if (!spin_is_locked(&priv->driver_lock)) {
David Woodhouse4f679492007-12-10 14:58:37 -05001439 printk(KERN_CRIT "%s called without driver_lock held\n", __func__);
1440 WARN_ON(1);
1441 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001442
David Woodhouseaa21c002007-12-08 20:04:36 +00001443 priv->intcounter++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001444
David Woodhouse4f679492007-12-10 14:58:37 -05001445 if (priv->psstate == PS_STATE_SLEEP)
David Woodhouseaa21c002007-12-08 20:04:36 +00001446 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001447
Dan Williamsfe336152007-08-02 11:32:25 -04001448 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001449
Holger Schuriged37b512007-05-25 11:52:42 -04001450 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001451}
Holger Schurig10078322007-11-15 18:05:47 -05001452EXPORT_SYMBOL_GPL(lbs_interrupt);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001453
Holger Schurig69f90322007-11-23 15:43:44 +01001454int lbs_reset_device(struct lbs_private *priv)
Dan Williamseedc2a32007-08-02 11:36:22 -04001455{
1456 int ret;
1457
1458 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001459 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RESET,
Dan Williamseedc2a32007-08-02 11:36:22 -04001460 CMD_ACT_HALT, 0, 0, NULL);
1461 msleep_interruptible(10);
1462
1463 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1464 return ret;
1465}
Holger Schurig10078322007-11-15 18:05:47 -05001466EXPORT_SYMBOL_GPL(lbs_reset_device);
Dan Williamseedc2a32007-08-02 11:36:22 -04001467
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 Schurig10078322007-11-15 18:05:47 -05001471 lbs_debugfs_init();
Holger Schurig084708b2007-05-25 12:37:58 -04001472 lbs_deb_leave(LBS_DEB_MAIN);
1473 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001474}
1475
Andres Salomon4fb910f2007-11-20 17:43:45 -05001476static void __exit lbs_exit_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001477{
Holger Schurig9012b282007-05-25 11:27:16 -04001478 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001479
Holger Schurig10078322007-11-15 18:05:47 -05001480 lbs_debugfs_remove();
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001481
Holger Schurig9012b282007-05-25 11:27:16 -04001482 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001483}
1484
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001485/*
1486 * rtap interface support fuctions
1487 */
1488
Holger Schurig10078322007-11-15 18:05:47 -05001489static int lbs_rtap_open(struct net_device *dev)
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001490{
David Woodhouse85528552007-12-10 16:38:18 -05001491 /* Yes, _stop_ the queue. Because we don't support injection */
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001492 netif_carrier_off(dev);
1493 netif_stop_queue(dev);
1494 return 0;
1495}
1496
Holger Schurig10078322007-11-15 18:05:47 -05001497static int lbs_rtap_stop(struct net_device *dev)
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001498{
1499 return 0;
1500}
1501
Holger Schurig10078322007-11-15 18:05:47 -05001502static int lbs_rtap_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001503{
1504 netif_stop_queue(dev);
David Woodhouse85528552007-12-10 16:38:18 -05001505 return NETDEV_TX_BUSY;
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001506}
1507
Holger Schurig10078322007-11-15 18:05:47 -05001508static struct net_device_stats *lbs_rtap_get_stats(struct net_device *dev)
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001509{
Holger Schurig69f90322007-11-23 15:43:44 +01001510 struct lbs_private *priv = dev->priv;
David Woodhoused9268fb2007-12-09 16:22:21 -05001511 return &priv->stats;
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001512}
1513
1514
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001515static void lbs_remove_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001516{
1517 if (priv->rtap_net_dev == NULL)
1518 return;
1519 unregister_netdev(priv->rtap_net_dev);
David Woodhoused9268fb2007-12-09 16:22:21 -05001520 free_netdev(priv->rtap_net_dev);
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001521 priv->rtap_net_dev = NULL;
1522}
1523
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001524static int lbs_add_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001525{
1526 int rc = 0;
David Woodhoused9268fb2007-12-09 16:22:21 -05001527 struct net_device *rtap_dev;
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001528
1529 if (priv->rtap_net_dev)
1530 return -EPERM;
1531
David Woodhoused9268fb2007-12-09 16:22:21 -05001532 rtap_dev = alloc_netdev(0, "rtap%d", ether_setup);
1533 if (rtap_dev == NULL)
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001534 return -ENOMEM;
1535
David Woodhouse121947c2007-12-09 19:54:11 -05001536 memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN);
David Woodhoused9268fb2007-12-09 16:22:21 -05001537 rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP;
1538 rtap_dev->open = lbs_rtap_open;
1539 rtap_dev->stop = lbs_rtap_stop;
1540 rtap_dev->get_stats = lbs_rtap_get_stats;
1541 rtap_dev->hard_start_xmit = lbs_rtap_hard_start_xmit;
1542 rtap_dev->set_multicast_list = lbs_set_multicast_list;
1543 rtap_dev->priv = priv;
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001544
David Woodhoused9268fb2007-12-09 16:22:21 -05001545 rc = register_netdev(rtap_dev);
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001546 if (rc) {
David Woodhoused9268fb2007-12-09 16:22:21 -05001547 free_netdev(rtap_dev);
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001548 return rc;
1549 }
David Woodhoused9268fb2007-12-09 16:22:21 -05001550 priv->rtap_net_dev = rtap_dev;
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001551
1552 return 0;
1553}
1554
1555
Holger Schurig10078322007-11-15 18:05:47 -05001556module_init(lbs_init_module);
1557module_exit(lbs_exit_module);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001558
Holger Schurig084708b2007-05-25 12:37:58 -04001559MODULE_DESCRIPTION("Libertas WLAN Driver Library");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001560MODULE_AUTHOR("Marvell International Ltd.");
1561MODULE_LICENSE("GPL");