blob: e9c6b4ffd8e13cbd0c22ac45656f7bce7dc3ed5c [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains the major functions in WLAN
3 * driver. It includes init, exit, open, close and main
4 * thread etc..
5 */
6
Holger Schuriga46c6412007-05-25 11:32:07 -04007#include <linux/moduleparam.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02008#include <linux/delay.h>
9#include <linux/freezer.h>
10#include <linux/etherdevice.h>
11#include <linux/netdevice.h>
12#include <linux/if_arp.h>
Dan Williamsfe336152007-08-02 11:32:25 -040013#include <linux/kthread.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020014
15#include <net/iw_handler.h>
Holger Schurig9012b282007-05-25 11:27:16 -040016#include <net/ieee80211.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020017
18#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019#include "decl.h"
20#include "dev.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020021#include "wext.h"
22#include "debugfs.h"
23#include "assoc.h"
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -040024#include "join.h"
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{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200219 struct cmd_ds_mesh_access mesh_access;
220
221 memset(&mesh_access, 0, sizeof(mesh_access));
Holger Schurig10078322007-11-15 18:05:47 -0500222 lbs_prepare_and_send_command(to_net_dev(dev)->priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400223 CMD_MESH_ACCESS,
224 CMD_ACT_MESH_GET_ANYCAST,
225 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200226
Luis Carlos82fde742007-06-07 16:40:59 -0400227 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200228}
229
230/**
Luis Carlos82fde742007-06-07 16:40:59 -0400231 * @brief Set function for sysfs attribute anycast_mask
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200232 */
Holger Schurig10078322007-11-15 18:05:47 -0500233static ssize_t lbs_anycast_set(struct device *dev,
Dan Williamsb59bb612007-06-18 11:50:43 -0400234 struct device_attribute *attr, const char * buf, size_t count)
235{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200236 struct cmd_ds_mesh_access mesh_access;
David Woodhouse981f1872007-05-25 23:36:54 -0400237 uint32_t datum;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200238
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200239 memset(&mesh_access, 0, sizeof(mesh_access));
Luis Carlos82fde742007-06-07 16:40:59 -0400240 sscanf(buf, "%x", &datum);
David Woodhouse981f1872007-05-25 23:36:54 -0400241 mesh_access.data[0] = cpu_to_le32(datum);
242
Holger Schurig10078322007-11-15 18:05:47 -0500243 lbs_prepare_and_send_command((to_net_dev(dev))->priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400244 CMD_MESH_ACCESS,
245 CMD_ACT_MESH_SET_ANYCAST,
246 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200247 return strlen(buf);
248}
249
Holger Schurig69f90322007-11-23 15:43:44 +0100250int lbs_add_rtap(struct lbs_private *priv);
251void lbs_remove_rtap(struct lbs_private *priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400252
253/**
254 * Get function for sysfs attribute rtap
255 */
Holger Schurig10078322007-11-15 18:05:47 -0500256static ssize_t lbs_rtap_get(struct device *dev,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400257 struct device_attribute *attr, char * buf)
258{
David Woodhousee7deced2007-12-08 18:29:16 +0000259 struct lbs_private *priv = to_net_dev(dev)->priv;
David Woodhouseaa21c002007-12-08 20:04:36 +0000260 return snprintf(buf, 5, "0x%X\n", priv->monitormode);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400261}
262
263/**
264 * Set function for sysfs attribute rtap
265 */
Holger Schurig10078322007-11-15 18:05:47 -0500266static ssize_t lbs_rtap_set(struct device *dev,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400267 struct device_attribute *attr, const char * buf, size_t count)
268{
269 int monitor_mode;
David Woodhousee7deced2007-12-08 18:29:16 +0000270 struct lbs_private *priv = to_net_dev(dev)->priv;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400271
272 sscanf(buf, "%x", &monitor_mode);
Holger Schurig10078322007-11-15 18:05:47 -0500273 if (monitor_mode != LBS_MONITOR_OFF) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000274 if(priv->monitormode == monitor_mode)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400275 return strlen(buf);
David Woodhouseaa21c002007-12-08 20:04:36 +0000276 if (priv->monitormode == LBS_MONITOR_OFF) {
277 if (priv->mode == IW_MODE_INFRA)
Holger Schurig10078322007-11-15 18:05:47 -0500278 lbs_send_deauthentication(priv);
David Woodhouseaa21c002007-12-08 20:04:36 +0000279 else if (priv->mode == IW_MODE_ADHOC)
Holger Schurig10078322007-11-15 18:05:47 -0500280 lbs_stop_adhoc_network(priv);
281 lbs_add_rtap(priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400282 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000283 priv->monitormode = monitor_mode;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400284 }
285
286 else {
David Woodhouseaa21c002007-12-08 20:04:36 +0000287 if (priv->monitormode == LBS_MONITOR_OFF)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400288 return strlen(buf);
David Woodhouseaa21c002007-12-08 20:04:36 +0000289 priv->monitormode = LBS_MONITOR_OFF;
Holger Schurig10078322007-11-15 18:05:47 -0500290 lbs_remove_rtap(priv);
David Woodhousef86a93e2007-12-08 19:46:19 +0000291
David Woodhouseaa21c002007-12-08 20:04:36 +0000292 if (priv->currenttxskb) {
293 dev_kfree_skb_any(priv->currenttxskb);
294 priv->currenttxskb = NULL;
David Woodhousef86a93e2007-12-08 19:46:19 +0000295 }
296
297 /* Wake queues, command thread, etc. */
298 lbs_host_to_card_done(priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400299 }
300
Holger Schurig10078322007-11-15 18:05:47 -0500301 lbs_prepare_and_send_command(priv,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400302 CMD_802_11_MONITOR_MODE, CMD_ACT_SET,
David Woodhouseaa21c002007-12-08 20:04:36 +0000303 CMD_OPTION_WAITFORRSP, 0, &priv->monitormode);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400304 return strlen(buf);
305}
306
307/**
Holger Schurig10078322007-11-15 18:05:47 -0500308 * lbs_rtap attribute to be exported per mshX interface
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400309 * through sysfs (/sys/class/net/mshX/libertas-rtap)
310 */
Holger Schurig10078322007-11-15 18:05:47 -0500311static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get,
312 lbs_rtap_set );
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400313
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200314/**
Luis Carlos82fde742007-06-07 16:40:59 -0400315 * anycast_mask attribute to be exported per mshX interface
316 * through sysfs (/sys/class/net/mshX/anycast_mask)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200317 */
Holger Schurig10078322007-11-15 18:05:47 -0500318static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200319
Holger Schurig10078322007-11-15 18:05:47 -0500320static ssize_t lbs_autostart_enabled_get(struct device *dev,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400321 struct device_attribute *attr, char * buf)
322{
323 struct cmd_ds_mesh_access mesh_access;
324
325 memset(&mesh_access, 0, sizeof(mesh_access));
Holger Schurig10078322007-11-15 18:05:47 -0500326 lbs_prepare_and_send_command(to_net_dev(dev)->priv,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400327 CMD_MESH_ACCESS,
328 CMD_ACT_MESH_GET_AUTOSTART_ENABLED,
329 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
330
331 return sprintf(buf, "%d\n", le32_to_cpu(mesh_access.data[0]));
332}
333
Holger Schurig10078322007-11-15 18:05:47 -0500334static ssize_t lbs_autostart_enabled_set(struct device *dev,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400335 struct device_attribute *attr, const char * buf, size_t count)
336{
337 struct cmd_ds_mesh_access mesh_access;
338 uint32_t datum;
Holger Schurig69f90322007-11-23 15:43:44 +0100339 struct lbs_private *priv = (to_net_dev(dev))->priv;
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400340 int ret;
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400341
342 memset(&mesh_access, 0, sizeof(mesh_access));
343 sscanf(buf, "%d", &datum);
344 mesh_access.data[0] = cpu_to_le32(datum);
345
Holger Schurig10078322007-11-15 18:05:47 -0500346 ret = lbs_prepare_and_send_command(priv,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400347 CMD_MESH_ACCESS,
348 CMD_ACT_MESH_SET_AUTOSTART_ENABLED,
349 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400350 if (ret == 0)
351 priv->mesh_autostart_enabled = datum ? 1 : 0;
352
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400353 return strlen(buf);
354}
355
356static DEVICE_ATTR(autostart_enabled, 0644,
Holger Schurig10078322007-11-15 18:05:47 -0500357 lbs_autostart_enabled_get, lbs_autostart_enabled_set);
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400358
Holger Schurig10078322007-11-15 18:05:47 -0500359static struct attribute *lbs_mesh_sysfs_entries[] = {
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400360 &dev_attr_anycast_mask.attr,
361 &dev_attr_autostart_enabled.attr,
362 NULL,
363};
364
Holger Schurig10078322007-11-15 18:05:47 -0500365static struct attribute_group lbs_mesh_attr_group = {
366 .attrs = lbs_mesh_sysfs_entries,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400367};
368
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369/**
370 * @brief Check if the device can be open and wait if necessary.
371 *
372 * @param dev A pointer to net_device structure
373 * @return 0
374 *
375 * For USB adapter, on some systems the device open handler will be
376 * called before FW ready. Use the following flag check and wait
377 * function to work around the issue.
378 *
379 */
Holger Schurig9012b282007-05-25 11:27:16 -0400380static int pre_open_check(struct net_device *dev)
381{
Holger Schurig69f90322007-11-23 15:43:44 +0100382 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200383 int i = 0;
384
David Woodhouseaa21c002007-12-08 20:04:36 +0000385 while (!priv->fw_ready && i < 20) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386 i++;
387 msleep_interruptible(100);
388 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000389 if (!priv->fw_ready) {
Holger Schurig9012b282007-05-25 11:27:16 -0400390 lbs_pr_err("firmware not ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391 return -1;
392 }
393
394 return 0;
395}
396
397/**
398 * @brief This function opens the device
399 *
400 * @param dev A pointer to net_device structure
401 * @return 0
402 */
Holger Schurig10078322007-11-15 18:05:47 -0500403static int lbs_dev_open(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404{
Holger Schurig69f90322007-11-23 15:43:44 +0100405 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200406
Holger Schurig9012b282007-05-25 11:27:16 -0400407 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200408
409 priv->open = 1;
410
David Woodhouseaa21c002007-12-08 20:04:36 +0000411 if (priv->connect_status == LBS_CONNECTED)
Holger Schurig634b8f42007-05-25 13:05:16 -0400412 netif_carrier_on(priv->dev);
Brajesh Dave01d77d82007-11-20 17:44:14 -0500413 else
Holger Schurig634b8f42007-05-25 13:05:16 -0400414 netif_carrier_off(priv->dev);
Brajesh Dave01d77d82007-11-20 17:44:14 -0500415
416 if (priv->mesh_dev) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000417 if (priv->mesh_connect_status == LBS_CONNECTED)
Brajesh Dave01d77d82007-11-20 17:44:14 -0500418 netif_carrier_on(priv->mesh_dev);
419 else
Holger Schurig3cf84092007-08-02 11:50:12 -0400420 netif_carrier_off(priv->mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400421 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200422
Holger Schurig9012b282007-05-25 11:27:16 -0400423 lbs_deb_leave(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200424 return 0;
425}
426/**
427 * @brief This function opens the mshX interface
428 *
429 * @param dev A pointer to net_device structure
430 * @return 0
431 */
Holger Schurig10078322007-11-15 18:05:47 -0500432static int lbs_mesh_open(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200433{
Holger Schurig69f90322007-11-23 15:43:44 +0100434 struct lbs_private *priv = (struct lbs_private *) dev->priv ;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200435
Holger Schurig78523da2007-05-25 11:49:19 -0400436 if (pre_open_check(dev) == -1)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200437 return -1;
438 priv->mesh_open = 1 ;
Javier Cardona51d84f52007-05-25 12:06:56 -0400439 netif_wake_queue(priv->mesh_dev);
Brajesh Dave01d77d82007-11-20 17:44:14 -0500440
David Woodhouseaa21c002007-12-08 20:04:36 +0000441 priv->mesh_connect_status = LBS_CONNECTED;
Brajesh Dave01d77d82007-11-20 17:44:14 -0500442
443 netif_carrier_on(priv->mesh_dev);
444 netif_wake_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200445 if (priv->infra_open == 0)
Holger Schurig10078322007-11-15 18:05:47 -0500446 return lbs_dev_open(priv->dev) ;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200447 return 0;
448}
449
450/**
451 * @brief This function opens the ethX interface
452 *
453 * @param dev A pointer to net_device structure
454 * @return 0
455 */
Holger Schurig10078322007-11-15 18:05:47 -0500456static int lbs_open(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200457{
Holger Schurig69f90322007-11-23 15:43:44 +0100458 struct lbs_private *priv = (struct lbs_private *) dev->priv ;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200459
460 if(pre_open_check(dev) == -1)
461 return -1;
462 priv->infra_open = 1 ;
Holger Schurig634b8f42007-05-25 13:05:16 -0400463 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464 if (priv->open == 0)
Holger Schurig10078322007-11-15 18:05:47 -0500465 return lbs_dev_open(priv->dev) ;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200466 return 0;
467}
468
Holger Schurig10078322007-11-15 18:05:47 -0500469static int lbs_dev_close(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470{
Holger Schurig69f90322007-11-23 15:43:44 +0100471 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200472
Holger Schurig9012b282007-05-25 11:27:16 -0400473 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200474
Holger Schurig634b8f42007-05-25 13:05:16 -0400475 netif_carrier_off(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 priv->open = 0;
477
Holger Schurig9012b282007-05-25 11:27:16 -0400478 lbs_deb_leave(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200479 return 0;
480}
481
482/**
483 * @brief This function closes the mshX interface
484 *
485 * @param dev A pointer to net_device structure
486 * @return 0
487 */
Holger Schurig10078322007-11-15 18:05:47 -0500488static int lbs_mesh_close(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489{
Holger Schurig69f90322007-11-23 15:43:44 +0100490 struct lbs_private *priv = (struct lbs_private *) (dev->priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200491
492 priv->mesh_open = 0;
493 netif_stop_queue(priv->mesh_dev);
494 if (priv->infra_open == 0)
Holger Schurig10078322007-11-15 18:05:47 -0500495 return lbs_dev_close(dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200496 else
497 return 0;
498}
499
500/**
501 * @brief This function closes the ethX interface
502 *
503 * @param dev A pointer to net_device structure
504 * @return 0
505 */
Holger Schurig10078322007-11-15 18:05:47 -0500506static int lbs_close(struct net_device *dev)
Holger Schurig78523da2007-05-25 11:49:19 -0400507{
Holger Schurig69f90322007-11-23 15:43:44 +0100508 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200509
Holger Schurig634b8f42007-05-25 13:05:16 -0400510 netif_stop_queue(dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200511 priv->infra_open = 0;
512 if (priv->mesh_open == 0)
Holger Schurig10078322007-11-15 18:05:47 -0500513 return lbs_dev_close(dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200514 else
515 return 0;
516}
517
Holger Schurig10078322007-11-15 18:05:47 -0500518static void lbs_tx_timeout(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200519{
Holger Schurig69f90322007-11-23 15:43:44 +0100520 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200521
Holger Schurig9012b282007-05-25 11:27:16 -0400522 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200523
Holger Schurig9012b282007-05-25 11:27:16 -0400524 lbs_pr_err("tx watch dog timeout\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200525
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200526 dev->trans_start = jiffies;
527
David Woodhouseaa21c002007-12-08 20:04:36 +0000528 if (priv->currenttxskb) {
David Woodhousea63b22b2007-12-08 20:56:44 +0000529 priv->eventcause = 0x01000000;
530 lbs_send_tx_feedback(priv);
Javier Cardona51d84f52007-05-25 12:06:56 -0400531 }
David Woodhousea63b22b2007-12-08 20:56:44 +0000532 /* XX: Shouldn't we also call into the hw-specific driver
533 to kick it somehow? */
534 lbs_host_to_card_done(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200535
Holger Schurig9012b282007-05-25 11:27:16 -0400536 lbs_deb_leave(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200537}
538
David Woodhousee775ed72007-12-06 14:36:11 +0000539void lbs_host_to_card_done(struct lbs_private *priv)
540{
David Woodhousea63b22b2007-12-08 20:56:44 +0000541 unsigned long flags;
542
543 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhousee775ed72007-12-06 14:36:11 +0000544
545 priv->dnld_sent = DNLD_RES_RECEIVED;
546
547 /* Wake main thread if commands are pending */
David Woodhouseaa21c002007-12-08 20:04:36 +0000548 if (!priv->cur_cmd)
David Woodhousee775ed72007-12-06 14:36:11 +0000549 wake_up_interruptible(&priv->waitq);
550
David Woodhousef86a93e2007-12-08 19:46:19 +0000551 /* Don't wake netif queues if we're in monitor mode and
David Woodhousea63b22b2007-12-08 20:56:44 +0000552 a TX packet is already pending, or if there are commands
553 queued to be sent. */
554 if (!priv->currenttxskb && list_empty(&priv->cmdpendingq)) {
555 if (priv->dev && priv->connect_status == LBS_CONNECTED)
556 netif_wake_queue(priv->dev);
David Woodhousef86a93e2007-12-08 19:46:19 +0000557
David Woodhousea63b22b2007-12-08 20:56:44 +0000558 if (priv->mesh_dev && priv->mesh_connect_status == LBS_CONNECTED)
559 netif_wake_queue(priv->mesh_dev);
560 }
561 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhousee775ed72007-12-06 14:36:11 +0000562}
563EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
564
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200565/**
566 * @brief This function returns the network statistics
567 *
Holger Schurig69f90322007-11-23 15:43:44 +0100568 * @param dev A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200569 * @return A pointer to net_device_stats structure
570 */
Holger Schurig10078322007-11-15 18:05:47 -0500571static struct net_device_stats *lbs_get_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200572{
Holger Schurig69f90322007-11-23 15:43:44 +0100573 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200574
575 return &priv->stats;
576}
577
Holger Schurig10078322007-11-15 18:05:47 -0500578static int lbs_set_mac_address(struct net_device *dev, void *addr)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200579{
580 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100581 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200582 struct sockaddr *phwaddr = addr;
583
Holger Schurig9012b282007-05-25 11:27:16 -0400584 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200585
Luis Carlos Cobo Rus0a0d08a2007-05-25 23:05:27 -0400586 /* In case it was called from the mesh device */
587 dev = priv->dev ;
588
David Woodhouseaa21c002007-12-08 20:04:36 +0000589 memset(priv->current_addr, 0, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200590
591 /* dev->dev_addr is 8 bytes */
Holger Schurigece56192007-08-02 11:53:06 -0400592 lbs_deb_hex(LBS_DEB_NET, "dev->dev_addr", dev->dev_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200593
Holger Schurigece56192007-08-02 11:53:06 -0400594 lbs_deb_hex(LBS_DEB_NET, "addr", phwaddr->sa_data, ETH_ALEN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000595 memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200596
Holger Schurig10078322007-11-15 18:05:47 -0500597 ret = lbs_prepare_and_send_command(priv, CMD_802_11_MAC_ADDRESS,
Dan Williams0aef64d2007-08-02 11:31:18 -0400598 CMD_ACT_SET,
599 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200600
601 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400602 lbs_deb_net("set MAC address failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200603 ret = -1;
604 goto done;
605 }
606
David Woodhouseaa21c002007-12-08 20:04:36 +0000607 lbs_deb_hex(LBS_DEB_NET, "priv->macaddr", priv->current_addr, ETH_ALEN);
608 memcpy(dev->dev_addr, priv->current_addr, ETH_ALEN);
Holger Schurig78523da2007-05-25 11:49:19 -0400609 if (priv->mesh_dev)
David Woodhouseaa21c002007-12-08 20:04:36 +0000610 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611
612done:
Holger Schurig9012b282007-05-25 11:27:16 -0400613 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200614 return ret;
615}
616
David Woodhouseaa21c002007-12-08 20:04:36 +0000617static int lbs_copy_multicast_address(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200618 struct net_device *dev)
619{
620 int i = 0;
621 struct dev_mc_list *mcptr = dev->mc_list;
622
623 for (i = 0; i < dev->mc_count; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000624 memcpy(&priv->multicastlist[i], mcptr->dmi_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200625 mcptr = mcptr->next;
626 }
627
628 return i;
629
630}
631
Holger Schurig10078322007-11-15 18:05:47 -0500632static void lbs_set_multicast_list(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200633{
Holger Schurig69f90322007-11-23 15:43:44 +0100634 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200635 int oldpacketfilter;
Joe Perches0795af52007-10-03 17:59:30 -0700636 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200637
Holger Schurig9012b282007-05-25 11:27:16 -0400638 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200639
David Woodhouseaa21c002007-12-08 20:04:36 +0000640 oldpacketfilter = priv->currentpacketfilter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641
642 if (dev->flags & IFF_PROMISC) {
Holger Schurig9012b282007-05-25 11:27:16 -0400643 lbs_deb_net("enable promiscuous mode\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000644 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400645 CMD_ACT_MAC_PROMISCUOUS_ENABLE;
David Woodhouseaa21c002007-12-08 20:04:36 +0000646 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400647 ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE |
648 CMD_ACT_MAC_MULTICAST_ENABLE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200649 } else {
650 /* Multicast */
David Woodhouseaa21c002007-12-08 20:04:36 +0000651 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400652 ~CMD_ACT_MAC_PROMISCUOUS_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200653
654 if (dev->flags & IFF_ALLMULTI || dev->mc_count >
655 MRVDRV_MAX_MULTICAST_LIST_SIZE) {
Holger Schurig9012b282007-05-25 11:27:16 -0400656 lbs_deb_net( "enabling all multicast\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000657 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400658 CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
David Woodhouseaa21c002007-12-08 20:04:36 +0000659 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400660 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200661 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +0000662 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400663 ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200664
665 if (!dev->mc_count) {
Holger Schurig9012b282007-05-25 11:27:16 -0400666 lbs_deb_net("no multicast addresses, "
667 "disabling multicast\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000668 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400669 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200670 } else {
671 int i;
672
David Woodhouseaa21c002007-12-08 20:04:36 +0000673 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400674 CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200675
David Woodhouseaa21c002007-12-08 20:04:36 +0000676 priv->nr_of_multicastmacaddr =
677 lbs_copy_multicast_address(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200678
Holger Schurig9012b282007-05-25 11:27:16 -0400679 lbs_deb_net("multicast addresses: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200680 dev->mc_count);
681
682 for (i = 0; i < dev->mc_count; i++) {
Joe Perches0795af52007-10-03 17:59:30 -0700683 lbs_deb_net("Multicast address %d:%s\n",
684 i, print_mac(mac,
David Woodhouseaa21c002007-12-08 20:04:36 +0000685 priv->multicastlist[i]));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200686 }
Holger Schurig9012b282007-05-25 11:27:16 -0400687 /* send multicast addresses to firmware */
Holger Schurig10078322007-11-15 18:05:47 -0500688 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400689 CMD_MAC_MULTICAST_ADR,
690 CMD_ACT_SET, 0, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200691 NULL);
692 }
693 }
694 }
695
David Woodhouseaa21c002007-12-08 20:04:36 +0000696 if (priv->currentpacketfilter != oldpacketfilter) {
Holger Schurig10078322007-11-15 18:05:47 -0500697 lbs_set_mac_packet_filter(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200698 }
699
Holger Schurig9012b282007-05-25 11:27:16 -0400700 lbs_deb_leave(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200701}
702
703/**
Holger Schurig10078322007-11-15 18:05:47 -0500704 * @brief This function handles the major jobs in the LBS driver.
Holger Schurig9012b282007-05-25 11:27:16 -0400705 * It handles all events generated by firmware, RX data received
706 * from firmware and TX data sent from kernel.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200707 *
Holger Schurig10078322007-11-15 18:05:47 -0500708 * @param data A pointer to lbs_thread structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709 * @return 0
710 */
Holger Schurig10078322007-11-15 18:05:47 -0500711static int lbs_thread(void *data)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200712{
Dan Williamsfe336152007-08-02 11:32:25 -0400713 struct net_device *dev = data;
Holger Schurig69f90322007-11-23 15:43:44 +0100714 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200715 wait_queue_t wait;
716 u8 ireg = 0;
717
Holger Schurig9012b282007-05-25 11:27:16 -0400718 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200719
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200720 init_waitqueue_entry(&wait, current);
721
Dan Williamsb1b19072007-08-20 11:10:45 -0400722 set_freezable();
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000723
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200724 for (;;) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000725 lbs_deb_thread( "main-thread 111: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000726 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200727
Dan Williamsfe336152007-08-02 11:32:25 -0400728 add_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200729 set_current_state(TASK_INTERRUPTIBLE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000730 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000731
David Woodhouseaa21c002007-12-08 20:04:36 +0000732 if ((priv->psstate == PS_STATE_SLEEP) ||
733 (!priv->intcounter && (priv->dnld_sent || priv->cur_cmd || list_empty(&priv->cmdpendingq)))) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000734 lbs_deb_thread("main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000735 priv->connect_status, priv->intcounter,
736 priv->psmode, priv->psstate);
737 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200738 schedule();
739 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000740 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000742 lbs_deb_thread("main-thread 222 (waking up): intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000743 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200744
745 set_current_state(TASK_RUNNING);
Dan Williamsfe336152007-08-02 11:32:25 -0400746 remove_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200747 try_to_freeze();
748
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000749 lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000750 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200751
David Woodhouseaa21c002007-12-08 20:04:36 +0000752 if (kthread_should_stop() || priv->surpriseremoved) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000753 lbs_deb_thread("main-thread: break from main thread: surpriseremoved=0x%x\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000754 priv->surpriseremoved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200755 break;
756 }
757
758
David Woodhouseaa21c002007-12-08 20:04:36 +0000759 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000760
David Woodhouseaa21c002007-12-08 20:04:36 +0000761 if (priv->intcounter) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200762 u8 int_status;
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000763
David Woodhouseaa21c002007-12-08 20:04:36 +0000764 priv->intcounter = 0;
Holger Schurig208fdd22007-05-25 12:17:06 -0400765 int_status = priv->hw_get_int_status(priv, &ireg);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200766
767 if (int_status) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000768 lbs_deb_thread("main-thread: reading HOST_INT_STATUS_REG failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000769 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200770 continue;
771 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000772 priv->hisregcpy |= ireg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200773 }
774
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000775 lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000776 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200777
778 /* command response? */
David Woodhouseaa21c002007-12-08 20:04:36 +0000779 if (priv->hisregcpy & MRVDRV_CMD_UPLD_RDY) {
Holger Schurig9012b282007-05-25 11:27:16 -0400780 lbs_deb_thread("main-thread: cmd response ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200781
David Woodhouseaa21c002007-12-08 20:04:36 +0000782 priv->hisregcpy &= ~MRVDRV_CMD_UPLD_RDY;
783 spin_unlock_irq(&priv->driver_lock);
Holger Schurig10078322007-11-15 18:05:47 -0500784 lbs_process_rx_command(priv);
David Woodhouseaa21c002007-12-08 20:04:36 +0000785 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200786 }
787
788 /* Any Card Event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000789 if (priv->hisregcpy & MRVDRV_CARDEVENT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400790 lbs_deb_thread("main-thread: Card Event Activity\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200791
David Woodhouseaa21c002007-12-08 20:04:36 +0000792 priv->hisregcpy &= ~MRVDRV_CARDEVENT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200793
Holger Schurig208fdd22007-05-25 12:17:06 -0400794 if (priv->hw_read_event_cause(priv)) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000795 lbs_pr_alert("main-thread: hw_read_event_cause failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000796 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200797 continue;
798 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000799 spin_unlock_irq(&priv->driver_lock);
Holger Schurig10078322007-11-15 18:05:47 -0500800 lbs_process_event(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200801 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000802 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200803
804 /* Check if we need to confirm Sleep Request received previously */
David Woodhouseaa21c002007-12-08 20:04:36 +0000805 if (priv->psstate == PS_STATE_PRE_SLEEP &&
806 !priv->dnld_sent && !priv->cur_cmd) {
807 if (priv->connect_status == LBS_CONNECTED) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000808 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 +0000809 priv->intcounter, priv->currenttxskb, priv->dnld_sent, priv->cur_cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200810
David Woodhouseaa21c002007-12-08 20:04:36 +0000811 lbs_ps_confirm_sleep(priv, (u16) priv->psmode);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000812 } else {
813 /* workaround for firmware sending
814 * deauth/linkloss event immediately
815 * after sleep request; remove this
816 * after firmware fixes it
817 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000818 priv->psstate = PS_STATE_AWAKE;
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000819 lbs_pr_alert("main-thread: ignore PS_SleepConfirm in non-connected state\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820 }
821 }
822
823 /* The PS state is changed during processing of Sleep Request
824 * event above
825 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000826 if ((priv->psstate == PS_STATE_SLEEP) ||
827 (priv->psstate == PS_STATE_PRE_SLEEP))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200828 continue;
829
830 /* Execute the next command */
David Woodhouseaa21c002007-12-08 20:04:36 +0000831 if (!priv->dnld_sent && !priv->cur_cmd)
Holger Schurig10078322007-11-15 18:05:47 -0500832 lbs_execute_next_command(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200833
834 /* Wake-up command waiters which can't sleep in
Holger Schurig10078322007-11-15 18:05:47 -0500835 * lbs_prepare_and_send_command
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200836 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000837 if (!list_empty(&priv->cmdpendingq))
838 wake_up_all(&priv->cmd_pending);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200839 }
840
David Woodhouseaa21c002007-12-08 20:04:36 +0000841 del_timer(&priv->command_timer);
842 wake_up_all(&priv->cmd_pending);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200843
Holger Schurig9012b282007-05-25 11:27:16 -0400844 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200845 return 0;
846}
847
848/**
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400849 * @brief This function downloads firmware image, gets
850 * HW spec from firmware and set basic parameters to
851 * firmware.
852 *
Holger Schurig69f90322007-11-23 15:43:44 +0100853 * @param priv A pointer to struct lbs_private structure
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400854 * @return 0 or -1
855 */
Holger Schurig69f90322007-11-23 15:43:44 +0100856static int lbs_setup_firmware(struct lbs_private *priv)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400857{
858 int ret = -1;
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400859 struct cmd_ds_mesh_access mesh_access;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400860
861 lbs_deb_enter(LBS_DEB_FW);
862
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400863 /*
864 * Read MAC address from HW
865 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000866 memset(priv->current_addr, 0xff, ETH_ALEN);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400867
Holger Schurig10078322007-11-15 18:05:47 -0500868 ret = lbs_prepare_and_send_command(priv, CMD_GET_HW_SPEC,
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400869 0, CMD_OPTION_WAITFORRSP, 0, NULL);
870
871 if (ret) {
872 ret = -1;
873 goto done;
874 }
875
Holger Schurig10078322007-11-15 18:05:47 -0500876 lbs_set_mac_packet_filter(priv);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400877
878 /* Get the supported Data rates */
Holger Schurig10078322007-11-15 18:05:47 -0500879 ret = lbs_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400880 CMD_ACT_GET_TX_RATE,
881 CMD_OPTION_WAITFORRSP, 0, NULL);
882
883 if (ret) {
884 ret = -1;
885 goto done;
886 }
887
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400888 /* Disable mesh autostart */
889 if (priv->mesh_dev) {
890 memset(&mesh_access, 0, sizeof(mesh_access));
891 mesh_access.data[0] = cpu_to_le32(0);
Holger Schurig10078322007-11-15 18:05:47 -0500892 ret = lbs_prepare_and_send_command(priv,
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400893 CMD_MESH_ACCESS,
894 CMD_ACT_MESH_SET_AUTOSTART_ENABLED,
895 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
896 if (ret) {
897 ret = -1;
898 goto done;
899 }
900 priv->mesh_autostart_enabled = 0;
901 }
902
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400903 ret = 0;
904done:
905 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
906 return ret;
907}
908
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400909/**
910 * This function handles the timeout of command sending.
911 * It will re-send the same command again.
912 */
913static void command_timer_fn(unsigned long data)
914{
Holger Schurig69f90322007-11-23 15:43:44 +0100915 struct lbs_private *priv = (struct lbs_private *)data;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400916 struct cmd_ctrl_node *ptempnode;
917 struct cmd_ds_command *cmd;
918 unsigned long flags;
919
David Woodhouseaa21c002007-12-08 20:04:36 +0000920 ptempnode = priv->cur_cmd;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400921 if (ptempnode == NULL) {
922 lbs_deb_fw("ptempnode empty\n");
923 return;
924 }
925
926 cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr;
927 if (!cmd) {
928 lbs_deb_fw("cmd is NULL\n");
929 return;
930 }
931
932 lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command);
933
David Woodhouseaa21c002007-12-08 20:04:36 +0000934 if (!priv->fw_ready)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400935 return;
936
David Woodhouseaa21c002007-12-08 20:04:36 +0000937 spin_lock_irqsave(&priv->driver_lock, flags);
938 priv->cur_cmd = NULL;
939 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400940
941 lbs_deb_fw("re-sending same command because of timeout\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000942 lbs_queue_cmd(priv, ptempnode, 0);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400943
944 wake_up_interruptible(&priv->waitq);
945
946 return;
947}
948
Holger Schurig69f90322007-11-23 15:43:44 +0100949static int lbs_init_adapter(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -0400950{
Dan Williams954ee162007-08-20 11:43:25 -0400951 size_t bufsize;
952 int i, ret = 0;
953
954 /* Allocate buffer to store the BSSID list */
955 bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
David Woodhouseaa21c002007-12-08 20:04:36 +0000956 priv->networks = kzalloc(bufsize, GFP_KERNEL);
957 if (!priv->networks) {
Dan Williams954ee162007-08-20 11:43:25 -0400958 lbs_pr_err("Out of memory allocating beacons\n");
959 ret = -1;
960 goto out;
961 }
962
963 /* Initialize scan result lists */
David Woodhouseaa21c002007-12-08 20:04:36 +0000964 INIT_LIST_HEAD(&priv->network_free_list);
965 INIT_LIST_HEAD(&priv->network_list);
Dan Williams954ee162007-08-20 11:43:25 -0400966 for (i = 0; i < MAX_NETWORK_COUNT; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000967 list_add_tail(&priv->networks[i].list,
968 &priv->network_free_list);
Dan Williams954ee162007-08-20 11:43:25 -0400969 }
970
David Woodhouseaa21c002007-12-08 20:04:36 +0000971 priv->lbs_ps_confirm_sleep.seqnum = cpu_to_le16(++priv->seqnum);
972 priv->lbs_ps_confirm_sleep.command =
Dan Williams954ee162007-08-20 11:43:25 -0400973 cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000974 priv->lbs_ps_confirm_sleep.size =
Dan Williams954ee162007-08-20 11:43:25 -0400975 cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep));
David Woodhouseaa21c002007-12-08 20:04:36 +0000976 priv->lbs_ps_confirm_sleep.action =
Dan Williams954ee162007-08-20 11:43:25 -0400977 cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
978
David Woodhouseaa21c002007-12-08 20:04:36 +0000979 memset(priv->current_addr, 0xff, ETH_ALEN);
Dan Williams954ee162007-08-20 11:43:25 -0400980
David Woodhouseaa21c002007-12-08 20:04:36 +0000981 priv->connect_status = LBS_DISCONNECTED;
982 priv->mesh_connect_status = LBS_DISCONNECTED;
983 priv->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
984 priv->mode = IW_MODE_INFRA;
985 priv->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL;
986 priv->currentpacketfilter = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
987 priv->radioon = RADIO_ON;
988 priv->auto_rate = 1;
989 priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
990 priv->psmode = LBS802_11POWERMODECAM;
991 priv->psstate = PS_STATE_FULL_POWER;
Dan Williams954ee162007-08-20 11:43:25 -0400992
David Woodhouseaa21c002007-12-08 20:04:36 +0000993 mutex_init(&priv->lock);
Dan Williams954ee162007-08-20 11:43:25 -0400994
David Woodhouseaa21c002007-12-08 20:04:36 +0000995 setup_timer(&priv->command_timer, command_timer_fn,
Dan Williams954ee162007-08-20 11:43:25 -0400996 (unsigned long)priv);
997
David Woodhouseaa21c002007-12-08 20:04:36 +0000998 INIT_LIST_HEAD(&priv->cmdfreeq);
999 INIT_LIST_HEAD(&priv->cmdpendingq);
Dan Williams954ee162007-08-20 11:43:25 -04001000
David Woodhouseaa21c002007-12-08 20:04:36 +00001001 spin_lock_init(&priv->driver_lock);
1002 init_waitqueue_head(&priv->cmd_pending);
Dan Williams954ee162007-08-20 11:43:25 -04001003
1004 /* Allocate the command buffers */
Holger Schurig10078322007-11-15 18:05:47 -05001005 if (lbs_allocate_cmd_buffer(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001006 lbs_pr_err("Out of memory allocating command buffers\n");
1007 ret = -1;
1008 }
1009
1010out:
1011 return ret;
1012}
1013
Holger Schurig69f90322007-11-23 15:43:44 +01001014static void lbs_free_adapter(struct lbs_private *priv)
Holger Schurigac558ca2007-08-02 11:49:06 -04001015{
Holger Schurigac558ca2007-08-02 11:49:06 -04001016 lbs_deb_fw("free command buffer\n");
Holger Schurig10078322007-11-15 18:05:47 -05001017 lbs_free_cmd_buffer(priv);
Holger Schurigac558ca2007-08-02 11:49:06 -04001018
1019 lbs_deb_fw("free command_timer\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001020 del_timer(&priv->command_timer);
Holger Schurigac558ca2007-08-02 11:49:06 -04001021
1022 lbs_deb_fw("free scan results table\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001023 kfree(priv->networks);
1024 priv->networks = NULL;
Holger Schurigac558ca2007-08-02 11:49:06 -04001025}
1026
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001027/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001028 * @brief This function adds the card. it will probe the
Holger Schurig10078322007-11-15 18:05:47 -05001029 * card, allocate the lbs_priv and initialize the device.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001030 *
1031 * @param card A pointer to card
Holger Schurig69f90322007-11-23 15:43:44 +01001032 * @return A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001033 */
Holger Schurig69f90322007-11-23 15:43:44 +01001034struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001035{
1036 struct net_device *dev = NULL;
Holger Schurig69f90322007-11-23 15:43:44 +01001037 struct lbs_private *priv = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001038
Holger Schurig9012b282007-05-25 11:27:16 -04001039 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001040
1041 /* Allocate an Ethernet device and register it */
Holger Schurig69f90322007-11-23 15:43:44 +01001042 dev = alloc_etherdev(sizeof(struct lbs_private));
1043 if (!dev) {
Holger Schurig9012b282007-05-25 11:27:16 -04001044 lbs_pr_err("init ethX device failed\n");
Dan Williams954ee162007-08-20 11:43:25 -04001045 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001046 }
Dan Williams64f104e2007-08-20 11:45:16 -04001047 priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001048
Holger Schurig10078322007-11-15 18:05:47 -05001049 if (lbs_init_adapter(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001050 lbs_pr_err("failed to initialize adapter structure.\n");
1051 goto err_init_adapter;
1052 }
1053
Holger Schurig634b8f42007-05-25 13:05:16 -04001054 priv->dev = dev;
1055 priv->card = card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001056 priv->mesh_open = 0;
1057 priv->infra_open = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001058
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001059 /* Setup the OS Interface to our functions */
Holger Schurig10078322007-11-15 18:05:47 -05001060 dev->open = lbs_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001061 dev->hard_start_xmit = lbs_hard_start_xmit;
Holger Schurig10078322007-11-15 18:05:47 -05001062 dev->stop = lbs_close;
1063 dev->set_mac_address = lbs_set_mac_address;
1064 dev->tx_timeout = lbs_tx_timeout;
1065 dev->get_stats = lbs_get_stats;
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001066 dev->watchdog_timeo = 5 * HZ;
Holger Schurig10078322007-11-15 18:05:47 -05001067 dev->ethtool_ops = &lbs_ethtool_ops;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001068#ifdef WIRELESS_EXT
Holger Schurig10078322007-11-15 18:05:47 -05001069 dev->wireless_handlers = (struct iw_handler_def *)&lbs_handler_def;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001070#endif
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001071 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
Holger Schurig10078322007-11-15 18:05:47 -05001072 dev->set_multicast_list = lbs_set_multicast_list;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001073
Dan Williams7732ca42007-05-25 13:13:25 -04001074 SET_NETDEV_DEV(dev, dmdev);
1075
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001076 priv->rtap_net_dev = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001077
Dan Williamsfe336152007-08-02 11:32:25 -04001078 lbs_deb_thread("Starting main thread...\n");
1079 init_waitqueue_head(&priv->waitq);
Holger Schurig10078322007-11-15 18:05:47 -05001080 priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
Dan Williamsfe336152007-08-02 11:32:25 -04001081 if (IS_ERR(priv->main_thread)) {
1082 lbs_deb_thread("Error creating main thread.\n");
David Woodhousee7deced2007-12-08 18:29:16 +00001083 goto err_init_adapter;
Dan Williamsfe336152007-08-02 11:32:25 -04001084 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001085
Holger Schurig10078322007-11-15 18:05:47 -05001086 priv->work_thread = create_singlethread_workqueue("lbs_worker");
1087 INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker);
1088 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
1089 INIT_WORK(&priv->sync_channel, lbs_sync_channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001090
Dan Williams954ee162007-08-20 11:43:25 -04001091 goto done;
1092
Dan Williams954ee162007-08-20 11:43:25 -04001093err_init_adapter:
Holger Schurig10078322007-11-15 18:05:47 -05001094 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001095 free_netdev(dev);
1096 priv = NULL;
1097
1098done:
1099 lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv);
1100 return priv;
1101}
Holger Schurig10078322007-11-15 18:05:47 -05001102EXPORT_SYMBOL_GPL(lbs_add_card);
Dan Williams954ee162007-08-20 11:43:25 -04001103
1104
Holger Schurig69f90322007-11-23 15:43:44 +01001105int lbs_remove_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001106{
Dan Williams954ee162007-08-20 11:43:25 -04001107 struct net_device *dev = priv->dev;
1108 union iwreq_data wrqu;
1109
1110 lbs_deb_enter(LBS_DEB_MAIN);
1111
Holger Schurig10078322007-11-15 18:05:47 -05001112 lbs_remove_rtap(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001113
1114 dev = priv->dev;
David Woodhousee7deced2007-12-08 18:29:16 +00001115 device_remove_file(&dev->dev, &dev_attr_lbs_rtap);
Dan Williams954ee162007-08-20 11:43:25 -04001116
1117 cancel_delayed_work(&priv->scan_work);
1118 cancel_delayed_work(&priv->assoc_work);
1119 destroy_workqueue(priv->work_thread);
1120
David Woodhouseaa21c002007-12-08 20:04:36 +00001121 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
1122 priv->psmode = LBS802_11POWERMODECAM;
Holger Schurig10078322007-11-15 18:05:47 -05001123 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001124 }
1125
Dan Williams954ee162007-08-20 11:43:25 -04001126 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
1127 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1128 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
1129
1130 /* Stop the thread servicing the interrupts */
David Woodhouseaa21c002007-12-08 20:04:36 +00001131 priv->surpriseremoved = 1;
Dan Williams954ee162007-08-20 11:43:25 -04001132 kthread_stop(priv->main_thread);
1133
Holger Schurig10078322007-11-15 18:05:47 -05001134 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001135
1136 priv->dev = NULL;
1137 free_netdev(dev);
1138
1139 lbs_deb_leave(LBS_DEB_MAIN);
1140 return 0;
1141}
Holger Schurig10078322007-11-15 18:05:47 -05001142EXPORT_SYMBOL_GPL(lbs_remove_card);
Dan Williams954ee162007-08-20 11:43:25 -04001143
1144
Holger Schurig69f90322007-11-23 15:43:44 +01001145int lbs_start_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001146{
1147 struct net_device *dev = priv->dev;
1148 int ret = -1;
1149
1150 lbs_deb_enter(LBS_DEB_MAIN);
1151
1152 /* poke the firmware */
Holger Schurig10078322007-11-15 18:05:47 -05001153 ret = lbs_setup_firmware(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001154 if (ret)
1155 goto done;
1156
1157 /* init 802.11d */
Holger Schurig10078322007-11-15 18:05:47 -05001158 lbs_init_11d(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001159
1160 if (register_netdev(dev)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001161 lbs_pr_err("cannot register ethX device\n");
Dan Williams954ee162007-08-20 11:43:25 -04001162 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001163 }
David Woodhousee7deced2007-12-08 18:29:16 +00001164 if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
1165 lbs_pr_err("cannot register lbs_rtap attribute\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001166
Holger Schurig10078322007-11-15 18:05:47 -05001167 lbs_debugfs_init_one(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001168
Dan Williams954ee162007-08-20 11:43:25 -04001169 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001170
Dan Williams954ee162007-08-20 11:43:25 -04001171 ret = 0;
1172
Holger Schurig32a74b72007-05-25 12:04:31 -04001173done:
Dan Williams954ee162007-08-20 11:43:25 -04001174 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
Holger Schurig32a74b72007-05-25 12:04:31 -04001175 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001176}
Holger Schurig10078322007-11-15 18:05:47 -05001177EXPORT_SYMBOL_GPL(lbs_start_card);
Dan Williams954ee162007-08-20 11:43:25 -04001178
1179
Holger Schurig69f90322007-11-23 15:43:44 +01001180int lbs_stop_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001181{
1182 struct net_device *dev = priv->dev;
1183 int ret = -1;
1184 struct cmd_ctrl_node *cmdnode;
1185 unsigned long flags;
1186
1187 lbs_deb_enter(LBS_DEB_MAIN);
1188
1189 netif_stop_queue(priv->dev);
1190 netif_carrier_off(priv->dev);
1191
Holger Schurig10078322007-11-15 18:05:47 -05001192 lbs_debugfs_remove_one(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001193
1194 /* Flush pending command nodes */
David Woodhouseaa21c002007-12-08 20:04:36 +00001195 spin_lock_irqsave(&priv->driver_lock, flags);
1196 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
Dan Williams954ee162007-08-20 11:43:25 -04001197 cmdnode->cmdwaitqwoken = 1;
1198 wake_up_interruptible(&cmdnode->cmdwait_q);
1199 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001200 spin_unlock_irqrestore(&priv->driver_lock, flags);
Dan Williams954ee162007-08-20 11:43:25 -04001201
1202 unregister_netdev(dev);
1203
1204 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1205 return ret;
1206}
Holger Schurig10078322007-11-15 18:05:47 -05001207EXPORT_SYMBOL_GPL(lbs_stop_card);
Holger Schurig084708b2007-05-25 12:37:58 -04001208
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001209
Holger Schurig78523da2007-05-25 11:49:19 -04001210/**
1211 * @brief This function adds mshX interface
1212 *
Holger Schurig69f90322007-11-23 15:43:44 +01001213 * @param priv A pointer to the struct lbs_private structure
Holger Schurig78523da2007-05-25 11:49:19 -04001214 * @return 0 if successful, -X otherwise
1215 */
Holger Schurig69f90322007-11-23 15:43:44 +01001216int lbs_add_mesh(struct lbs_private *priv, struct device *dev)
Holger Schurig78523da2007-05-25 11:49:19 -04001217{
1218 struct net_device *mesh_dev = NULL;
1219 int ret = 0;
1220
1221 lbs_deb_enter(LBS_DEB_MESH);
1222
1223 /* Allocate a virtual mesh device */
1224 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
1225 lbs_deb_mesh("init mshX device failed\n");
1226 ret = -ENOMEM;
1227 goto done;
1228 }
1229 mesh_dev->priv = priv;
1230 priv->mesh_dev = mesh_dev;
1231
Holger Schurig10078322007-11-15 18:05:47 -05001232 mesh_dev->open = lbs_mesh_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001233 mesh_dev->hard_start_xmit = lbs_hard_start_xmit;
Holger Schurig10078322007-11-15 18:05:47 -05001234 mesh_dev->stop = lbs_mesh_close;
1235 mesh_dev->get_stats = lbs_get_stats;
1236 mesh_dev->set_mac_address = lbs_set_mac_address;
1237 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
Holger Schurig634b8f42007-05-25 13:05:16 -04001238 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
1239 sizeof(priv->dev->dev_addr));
Holger Schurig78523da2007-05-25 11:49:19 -04001240
Dan Williams7732ca42007-05-25 13:13:25 -04001241 SET_NETDEV_DEV(priv->mesh_dev, dev);
1242
Holger Schurig78523da2007-05-25 11:49:19 -04001243#ifdef WIRELESS_EXT
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04001244 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
Holger Schurig78523da2007-05-25 11:49:19 -04001245#endif
Holger Schurig78523da2007-05-25 11:49:19 -04001246 /* Register virtual mesh interface */
1247 ret = register_netdev(mesh_dev);
1248 if (ret) {
1249 lbs_pr_err("cannot register mshX virtual interface\n");
1250 goto err_free;
1251 }
1252
Holger Schurig10078322007-11-15 18:05:47 -05001253 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001254 if (ret)
1255 goto err_unregister;
1256
1257 /* Everything successful */
1258 ret = 0;
1259 goto done;
1260
Holger Schurig78523da2007-05-25 11:49:19 -04001261err_unregister:
1262 unregister_netdev(mesh_dev);
1263
1264err_free:
1265 free_netdev(mesh_dev);
1266
1267done:
1268 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
1269 return ret;
1270}
Holger Schurig10078322007-11-15 18:05:47 -05001271EXPORT_SYMBOL_GPL(lbs_add_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001272
Holger Schurig084708b2007-05-25 12:37:58 -04001273
Holger Schurig69f90322007-11-23 15:43:44 +01001274void lbs_remove_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001275{
1276 struct net_device *mesh_dev;
1277
Dan Williams954ee162007-08-20 11:43:25 -04001278 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig78523da2007-05-25 11:49:19 -04001279
1280 if (!priv)
1281 goto out;
1282
1283 mesh_dev = priv->mesh_dev;
1284
1285 netif_stop_queue(mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -04001286 netif_carrier_off(priv->mesh_dev);
Holger Schurig78523da2007-05-25 11:49:19 -04001287
Holger Schurig10078322007-11-15 18:05:47 -05001288 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001289 unregister_netdev(mesh_dev);
1290
1291 priv->mesh_dev = NULL ;
1292 free_netdev(mesh_dev);
1293
1294out:
Dan Williams954ee162007-08-20 11:43:25 -04001295 lbs_deb_leave(LBS_DEB_MAIN);
Holger Schurig78523da2007-05-25 11:49:19 -04001296}
Holger Schurig10078322007-11-15 18:05:47 -05001297EXPORT_SYMBOL_GPL(lbs_remove_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001298
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001299/**
1300 * @brief This function finds the CFP in
1301 * region_cfp_table based on region and band parameter.
1302 *
1303 * @param region The region code
1304 * @param band The band
1305 * @param cfp_no A pointer to CFP number
1306 * @return A pointer to CFP
1307 */
Holger Schurig10078322007-11-15 18:05:47 -05001308struct chan_freq_power *lbs_get_region_cfp_table(u8 region, u8 band, int *cfp_no)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001309{
1310 int i, end;
1311
Holger Schurig9012b282007-05-25 11:27:16 -04001312 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001313
Denis Chengff8ac602007-09-02 18:30:18 +08001314 end = ARRAY_SIZE(region_cfp_table);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001315
1316 for (i = 0; i < end ; i++) {
Holger Schurig9012b282007-05-25 11:27:16 -04001317 lbs_deb_main("region_cfp_table[i].region=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001318 region_cfp_table[i].region);
1319 if (region_cfp_table[i].region == region) {
1320 *cfp_no = region_cfp_table[i].cfp_no_BG;
Holger Schurig9012b282007-05-25 11:27:16 -04001321 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001322 return region_cfp_table[i].cfp_BG;
1323 }
1324 }
1325
Holger Schurig9012b282007-05-25 11:27:16 -04001326 lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001327 return NULL;
1328}
1329
Holger Schurig69f90322007-11-23 15:43:44 +01001330int lbs_set_regiontable(struct lbs_private *priv, u8 region, u8 band)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001331{
Holger Schurig9012b282007-05-25 11:27:16 -04001332 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001333 int i = 0;
1334
1335 struct chan_freq_power *cfp;
1336 int cfp_no;
1337
Holger Schurig9012b282007-05-25 11:27:16 -04001338 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001339
David Woodhouseaa21c002007-12-08 20:04:36 +00001340 memset(priv->region_channel, 0, sizeof(priv->region_channel));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001341
1342 {
Holger Schurig10078322007-11-15 18:05:47 -05001343 cfp = lbs_get_region_cfp_table(region, band, &cfp_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001344 if (cfp != NULL) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001345 priv->region_channel[i].nrcfp = cfp_no;
1346 priv->region_channel[i].CFP = cfp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001347 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001348 lbs_deb_main("wrong region code %#x in band B/G\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001349 region);
Holger Schurig9012b282007-05-25 11:27:16 -04001350 ret = -1;
1351 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001352 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001353 priv->region_channel[i].valid = 1;
1354 priv->region_channel[i].region = region;
1355 priv->region_channel[i].band = band;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001356 i++;
1357 }
Holger Schurig9012b282007-05-25 11:27:16 -04001358out:
1359 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1360 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001361}
1362
1363/**
1364 * @brief This function handles the interrupt. it will change PS
1365 * state if applicable. it will wake up main_thread to handle
1366 * the interrupt event as well.
1367 *
1368 * @param dev A pointer to net_device structure
1369 * @return n/a
1370 */
Holger Schurig10078322007-11-15 18:05:47 -05001371void lbs_interrupt(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001372{
Holger Schurig69f90322007-11-23 15:43:44 +01001373 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001374
Holger Schuriged37b512007-05-25 11:52:42 -04001375 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001376
Holger Schurig10078322007-11-15 18:05:47 -05001377 lbs_deb_thread("lbs_interrupt: intcounter=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001378 priv->intcounter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001379
David Woodhouseaa21c002007-12-08 20:04:36 +00001380 priv->intcounter++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001381
David Woodhouseaa21c002007-12-08 20:04:36 +00001382 if (priv->psstate == PS_STATE_SLEEP) {
1383 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001384 netif_wake_queue(dev);
Holger Schurig3cf84092007-08-02 11:50:12 -04001385 if (priv->mesh_dev)
1386 netif_wake_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001387 }
1388
Dan Williamsfe336152007-08-02 11:32:25 -04001389 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001390
Holger Schuriged37b512007-05-25 11:52:42 -04001391 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001392}
Holger Schurig10078322007-11-15 18:05:47 -05001393EXPORT_SYMBOL_GPL(lbs_interrupt);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001394
Holger Schurig69f90322007-11-23 15:43:44 +01001395int lbs_reset_device(struct lbs_private *priv)
Dan Williamseedc2a32007-08-02 11:36:22 -04001396{
1397 int ret;
1398
1399 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001400 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RESET,
Dan Williamseedc2a32007-08-02 11:36:22 -04001401 CMD_ACT_HALT, 0, 0, NULL);
1402 msleep_interruptible(10);
1403
1404 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1405 return ret;
1406}
Holger Schurig10078322007-11-15 18:05:47 -05001407EXPORT_SYMBOL_GPL(lbs_reset_device);
Dan Williamseedc2a32007-08-02 11:36:22 -04001408
Andres Salomon4fb910f2007-11-20 17:43:45 -05001409static int __init lbs_init_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001410{
Holger Schurig9012b282007-05-25 11:27:16 -04001411 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001412 lbs_debugfs_init();
Holger Schurig084708b2007-05-25 12:37:58 -04001413 lbs_deb_leave(LBS_DEB_MAIN);
1414 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001415}
1416
Andres Salomon4fb910f2007-11-20 17:43:45 -05001417static void __exit lbs_exit_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001418{
Holger Schurig9012b282007-05-25 11:27:16 -04001419 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001420
Holger Schurig10078322007-11-15 18:05:47 -05001421 lbs_debugfs_remove();
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001422
Holger Schurig9012b282007-05-25 11:27:16 -04001423 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001424}
1425
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001426/*
1427 * rtap interface support fuctions
1428 */
1429
Holger Schurig10078322007-11-15 18:05:47 -05001430static int lbs_rtap_open(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001431{
1432 netif_carrier_off(dev);
1433 netif_stop_queue(dev);
1434 return 0;
1435}
1436
Holger Schurig10078322007-11-15 18:05:47 -05001437static int lbs_rtap_stop(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001438{
1439 return 0;
1440}
1441
Holger Schurig10078322007-11-15 18:05:47 -05001442static int lbs_rtap_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001443{
1444 netif_stop_queue(dev);
1445 return -EOPNOTSUPP;
1446}
1447
Holger Schurig10078322007-11-15 18:05:47 -05001448static struct net_device_stats *lbs_rtap_get_stats(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001449{
Holger Schurig69f90322007-11-23 15:43:44 +01001450 struct lbs_private *priv = dev->priv;
David Woodhoused9268fb2007-12-09 16:22:21 -05001451 return &priv->stats;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001452}
1453
1454
Holger Schurig69f90322007-11-23 15:43:44 +01001455void lbs_remove_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001456{
1457 if (priv->rtap_net_dev == NULL)
1458 return;
1459 unregister_netdev(priv->rtap_net_dev);
David Woodhoused9268fb2007-12-09 16:22:21 -05001460 free_netdev(priv->rtap_net_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001461 priv->rtap_net_dev = NULL;
1462}
1463
Holger Schurig69f90322007-11-23 15:43:44 +01001464int lbs_add_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001465{
1466 int rc = 0;
David Woodhoused9268fb2007-12-09 16:22:21 -05001467 struct net_device *rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001468
1469 if (priv->rtap_net_dev)
1470 return -EPERM;
1471
David Woodhoused9268fb2007-12-09 16:22:21 -05001472 rtap_dev = alloc_netdev(0, "rtap%d", ether_setup);
1473 if (rtap_dev == NULL)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001474 return -ENOMEM;
1475
David Woodhouse121947c2007-12-09 19:54:11 -05001476 memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN);
David Woodhoused9268fb2007-12-09 16:22:21 -05001477 rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP;
1478 rtap_dev->open = lbs_rtap_open;
1479 rtap_dev->stop = lbs_rtap_stop;
1480 rtap_dev->get_stats = lbs_rtap_get_stats;
1481 rtap_dev->hard_start_xmit = lbs_rtap_hard_start_xmit;
1482 rtap_dev->set_multicast_list = lbs_set_multicast_list;
1483 rtap_dev->priv = priv;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001484
David Woodhoused9268fb2007-12-09 16:22:21 -05001485 rc = register_netdev(rtap_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001486 if (rc) {
David Woodhoused9268fb2007-12-09 16:22:21 -05001487 free_netdev(rtap_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001488 return rc;
1489 }
David Woodhoused9268fb2007-12-09 16:22:21 -05001490 priv->rtap_net_dev = rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001491
1492 return 0;
1493}
1494
1495
Holger Schurig10078322007-11-15 18:05:47 -05001496module_init(lbs_init_module);
1497module_exit(lbs_exit_module);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001498
Holger Schurig084708b2007-05-25 12:37:58 -04001499MODULE_DESCRIPTION("Libertas WLAN Driver Library");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001500MODULE_AUTHOR("Marvell International Ltd.");
1501MODULE_LICENSE("GPL");