blob: 88664024bf8057a02b48b2dc409c801baf987225 [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) {
David Woodhouse8552855f2007-12-10 16:38:18 -0500277 if (priv->infra_open || priv->mesh_open)
278 return -EBUSY;
David Woodhouseaa21c002007-12-08 20:04:36 +0000279 if (priv->mode == IW_MODE_INFRA)
Holger Schurig10078322007-11-15 18:05:47 -0500280 lbs_send_deauthentication(priv);
David Woodhouseaa21c002007-12-08 20:04:36 +0000281 else if (priv->mode == IW_MODE_ADHOC)
Holger Schurig10078322007-11-15 18:05:47 -0500282 lbs_stop_adhoc_network(priv);
283 lbs_add_rtap(priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400284 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000285 priv->monitormode = monitor_mode;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400286 }
287
288 else {
David Woodhouseaa21c002007-12-08 20:04:36 +0000289 if (priv->monitormode == LBS_MONITOR_OFF)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400290 return strlen(buf);
David Woodhouseaa21c002007-12-08 20:04:36 +0000291 priv->monitormode = LBS_MONITOR_OFF;
Holger Schurig10078322007-11-15 18:05:47 -0500292 lbs_remove_rtap(priv);
David Woodhousef86a93e2007-12-08 19:46:19 +0000293
David Woodhouseaa21c002007-12-08 20:04:36 +0000294 if (priv->currenttxskb) {
295 dev_kfree_skb_any(priv->currenttxskb);
296 priv->currenttxskb = NULL;
David Woodhousef86a93e2007-12-08 19:46:19 +0000297 }
298
299 /* Wake queues, command thread, etc. */
300 lbs_host_to_card_done(priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400301 }
302
Holger Schurig10078322007-11-15 18:05:47 -0500303 lbs_prepare_and_send_command(priv,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400304 CMD_802_11_MONITOR_MODE, CMD_ACT_SET,
David Woodhouseaa21c002007-12-08 20:04:36 +0000305 CMD_OPTION_WAITFORRSP, 0, &priv->monitormode);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400306 return strlen(buf);
307}
308
309/**
Holger Schurig10078322007-11-15 18:05:47 -0500310 * lbs_rtap attribute to be exported per mshX interface
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400311 * through sysfs (/sys/class/net/mshX/libertas-rtap)
312 */
Holger Schurig10078322007-11-15 18:05:47 -0500313static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get,
314 lbs_rtap_set );
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400315
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200316/**
Luis Carlos82fde742007-06-07 16:40:59 -0400317 * anycast_mask attribute to be exported per mshX interface
318 * through sysfs (/sys/class/net/mshX/anycast_mask)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200319 */
Holger Schurig10078322007-11-15 18:05:47 -0500320static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200321
Holger Schurig10078322007-11-15 18:05:47 -0500322static ssize_t lbs_autostart_enabled_get(struct device *dev,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400323 struct device_attribute *attr, char * buf)
324{
325 struct cmd_ds_mesh_access mesh_access;
326
327 memset(&mesh_access, 0, sizeof(mesh_access));
Holger Schurig10078322007-11-15 18:05:47 -0500328 lbs_prepare_and_send_command(to_net_dev(dev)->priv,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400329 CMD_MESH_ACCESS,
330 CMD_ACT_MESH_GET_AUTOSTART_ENABLED,
331 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
332
333 return sprintf(buf, "%d\n", le32_to_cpu(mesh_access.data[0]));
334}
335
Holger Schurig10078322007-11-15 18:05:47 -0500336static ssize_t lbs_autostart_enabled_set(struct device *dev,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400337 struct device_attribute *attr, const char * buf, size_t count)
338{
339 struct cmd_ds_mesh_access mesh_access;
340 uint32_t datum;
Holger Schurig69f90322007-11-23 15:43:44 +0100341 struct lbs_private *priv = (to_net_dev(dev))->priv;
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400342 int ret;
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400343
344 memset(&mesh_access, 0, sizeof(mesh_access));
345 sscanf(buf, "%d", &datum);
346 mesh_access.data[0] = cpu_to_le32(datum);
347
Holger Schurig10078322007-11-15 18:05:47 -0500348 ret = lbs_prepare_and_send_command(priv,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400349 CMD_MESH_ACCESS,
350 CMD_ACT_MESH_SET_AUTOSTART_ENABLED,
351 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400352 if (ret == 0)
353 priv->mesh_autostart_enabled = datum ? 1 : 0;
354
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400355 return strlen(buf);
356}
357
358static DEVICE_ATTR(autostart_enabled, 0644,
Holger Schurig10078322007-11-15 18:05:47 -0500359 lbs_autostart_enabled_get, lbs_autostart_enabled_set);
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400360
Holger Schurig10078322007-11-15 18:05:47 -0500361static struct attribute *lbs_mesh_sysfs_entries[] = {
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400362 &dev_attr_anycast_mask.attr,
363 &dev_attr_autostart_enabled.attr,
364 NULL,
365};
366
Holger Schurig10078322007-11-15 18:05:47 -0500367static struct attribute_group lbs_mesh_attr_group = {
368 .attrs = lbs_mesh_sysfs_entries,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400369};
370
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371/**
David Woodhouse8552855f2007-12-10 16:38:18 -0500372 * @brief This function opens the ethX or mshX interface
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200373 *
374 * @param dev A pointer to net_device structure
David Woodhouse8552855f2007-12-10 16:38:18 -0500375 * @return 0 or -EBUSY if monitor mode active
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200376 */
Holger Schurig10078322007-11-15 18:05:47 -0500377static int lbs_dev_open(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378{
David Woodhouse8552855f2007-12-10 16:38:18 -0500379 struct lbs_private *priv = (struct lbs_private *) dev->priv ;
380 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200381
David Woodhouse8552855f2007-12-10 16:38:18 -0500382 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200383
David Woodhouse8552855f2007-12-10 16:38:18 -0500384 if (priv->monitormode != LBS_MONITOR_OFF) {
385 ret = -EBUSY;
386 goto out;
Javier Cardona51d84f52007-05-25 12:06:56 -0400387 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200388
David Woodhouse8552855f2007-12-10 16:38:18 -0500389 if (dev == priv->mesh_dev) {
390 priv->mesh_open = 1;
391 priv->mesh_connect_status = LBS_CONNECTED;
392 netif_carrier_on(dev);
393 } else {
394 priv->infra_open = 1;
395
396 if (priv->connect_status == LBS_CONNECTED)
397 netif_carrier_on(dev);
398 else
399 netif_carrier_off(dev);
400 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200401
David Woodhouse8552855f2007-12-10 16:38:18 -0500402 if (!priv->tx_pending_len)
403 netif_wake_queue(dev);
404 out:
Brajesh Dave01d77d82007-11-20 17:44:14 -0500405
David Woodhouse8552855f2007-12-10 16:38:18 -0500406 spin_unlock_irq(&priv->driver_lock);
407 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200408}
409
410/**
411 * @brief This function closes the mshX interface
412 *
413 * @param dev A pointer to net_device structure
414 * @return 0
415 */
David Woodhouse8552855f2007-12-10 16:38:18 -0500416static int lbs_mesh_stop(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417{
Holger Schurig69f90322007-11-23 15:43:44 +0100418 struct lbs_private *priv = (struct lbs_private *) (dev->priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419
David Woodhouse8552855f2007-12-10 16:38:18 -0500420 spin_lock_irq(&priv->driver_lock);
421
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200422 priv->mesh_open = 0;
David Woodhouse8552855f2007-12-10 16:38:18 -0500423 priv->mesh_connect_status = LBS_DISCONNECTED;
424
425 netif_stop_queue(dev);
426 netif_carrier_off(dev);
427
428 spin_unlock_irq(&priv->driver_lock);
429 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200430}
431
432/**
433 * @brief This function closes the ethX interface
434 *
435 * @param dev A pointer to net_device structure
436 * @return 0
437 */
David Woodhouse8552855f2007-12-10 16:38:18 -0500438static int lbs_eth_stop(struct net_device *dev)
Holger Schurig78523da2007-05-25 11:49:19 -0400439{
Holger Schurig69f90322007-11-23 15:43:44 +0100440 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200441
David Woodhouse8552855f2007-12-10 16:38:18 -0500442 spin_lock_irq(&priv->driver_lock);
443
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200444 priv->infra_open = 0;
David Woodhouse8552855f2007-12-10 16:38:18 -0500445
446 netif_stop_queue(dev);
447
448 spin_unlock_irq(&priv->driver_lock);
449 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200450}
451
Holger Schurig10078322007-11-15 18:05:47 -0500452static void lbs_tx_timeout(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200453{
Holger Schurig69f90322007-11-23 15:43:44 +0100454 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200455
Holger Schurig9012b282007-05-25 11:27:16 -0400456 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200457
Holger Schurig9012b282007-05-25 11:27:16 -0400458 lbs_pr_err("tx watch dog timeout\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200459
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200460 dev->trans_start = jiffies;
461
David Woodhouseaa21c002007-12-08 20:04:36 +0000462 if (priv->currenttxskb) {
David Woodhousea63b22b2007-12-08 20:56:44 +0000463 priv->eventcause = 0x01000000;
464 lbs_send_tx_feedback(priv);
Javier Cardona51d84f52007-05-25 12:06:56 -0400465 }
David Woodhousea63b22b2007-12-08 20:56:44 +0000466 /* XX: Shouldn't we also call into the hw-specific driver
467 to kick it somehow? */
468 lbs_host_to_card_done(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200469
Holger Schurig9012b282007-05-25 11:27:16 -0400470 lbs_deb_leave(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200471}
472
David Woodhousee775ed72007-12-06 14:36:11 +0000473void lbs_host_to_card_done(struct lbs_private *priv)
474{
David Woodhousea63b22b2007-12-08 20:56:44 +0000475 unsigned long flags;
476
477 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhousee775ed72007-12-06 14:36:11 +0000478
479 priv->dnld_sent = DNLD_RES_RECEIVED;
480
481 /* Wake main thread if commands are pending */
David Woodhouseaa21c002007-12-08 20:04:36 +0000482 if (!priv->cur_cmd)
David Woodhousee775ed72007-12-06 14:36:11 +0000483 wake_up_interruptible(&priv->waitq);
484
David Woodhousef86a93e2007-12-08 19:46:19 +0000485 /* Don't wake netif queues if we're in monitor mode and
David Woodhousea63b22b2007-12-08 20:56:44 +0000486 a TX packet is already pending, or if there are commands
487 queued to be sent. */
488 if (!priv->currenttxskb && list_empty(&priv->cmdpendingq)) {
489 if (priv->dev && priv->connect_status == LBS_CONNECTED)
490 netif_wake_queue(priv->dev);
David Woodhousef86a93e2007-12-08 19:46:19 +0000491
David Woodhousea63b22b2007-12-08 20:56:44 +0000492 if (priv->mesh_dev && priv->mesh_connect_status == LBS_CONNECTED)
493 netif_wake_queue(priv->mesh_dev);
494 }
495 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhousee775ed72007-12-06 14:36:11 +0000496}
497EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
498
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200499/**
500 * @brief This function returns the network statistics
501 *
Holger Schurig69f90322007-11-23 15:43:44 +0100502 * @param dev A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200503 * @return A pointer to net_device_stats structure
504 */
Holger Schurig10078322007-11-15 18:05:47 -0500505static struct net_device_stats *lbs_get_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200506{
Holger Schurig69f90322007-11-23 15:43:44 +0100507 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200508
509 return &priv->stats;
510}
511
Holger Schurig10078322007-11-15 18:05:47 -0500512static int lbs_set_mac_address(struct net_device *dev, void *addr)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200513{
514 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100515 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200516 struct sockaddr *phwaddr = addr;
517
Holger Schurig9012b282007-05-25 11:27:16 -0400518 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200519
Luis Carlos Cobo Rus0a0d08a2007-05-25 23:05:27 -0400520 /* In case it was called from the mesh device */
521 dev = priv->dev ;
522
David Woodhouseaa21c002007-12-08 20:04:36 +0000523 memset(priv->current_addr, 0, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200524
525 /* dev->dev_addr is 8 bytes */
Holger Schurigece56192007-08-02 11:53:06 -0400526 lbs_deb_hex(LBS_DEB_NET, "dev->dev_addr", dev->dev_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200527
Holger Schurigece56192007-08-02 11:53:06 -0400528 lbs_deb_hex(LBS_DEB_NET, "addr", phwaddr->sa_data, ETH_ALEN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000529 memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200530
Holger Schurig10078322007-11-15 18:05:47 -0500531 ret = lbs_prepare_and_send_command(priv, CMD_802_11_MAC_ADDRESS,
Dan Williams0aef64d2007-08-02 11:31:18 -0400532 CMD_ACT_SET,
533 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200534
535 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400536 lbs_deb_net("set MAC address failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200537 ret = -1;
538 goto done;
539 }
540
David Woodhouseaa21c002007-12-08 20:04:36 +0000541 lbs_deb_hex(LBS_DEB_NET, "priv->macaddr", priv->current_addr, ETH_ALEN);
542 memcpy(dev->dev_addr, priv->current_addr, ETH_ALEN);
Holger Schurig78523da2007-05-25 11:49:19 -0400543 if (priv->mesh_dev)
David Woodhouseaa21c002007-12-08 20:04:36 +0000544 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200545
546done:
Holger Schurig9012b282007-05-25 11:27:16 -0400547 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200548 return ret;
549}
550
David Woodhouseaa21c002007-12-08 20:04:36 +0000551static int lbs_copy_multicast_address(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200552 struct net_device *dev)
553{
554 int i = 0;
555 struct dev_mc_list *mcptr = dev->mc_list;
556
557 for (i = 0; i < dev->mc_count; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000558 memcpy(&priv->multicastlist[i], mcptr->dmi_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200559 mcptr = mcptr->next;
560 }
561
562 return i;
563
564}
565
Holger Schurig10078322007-11-15 18:05:47 -0500566static void lbs_set_multicast_list(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567{
Holger Schurig69f90322007-11-23 15:43:44 +0100568 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200569 int oldpacketfilter;
Joe Perches0795af52007-10-03 17:59:30 -0700570 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200571
Holger Schurig9012b282007-05-25 11:27:16 -0400572 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200573
David Woodhouseaa21c002007-12-08 20:04:36 +0000574 oldpacketfilter = priv->currentpacketfilter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200575
576 if (dev->flags & IFF_PROMISC) {
Holger Schurig9012b282007-05-25 11:27:16 -0400577 lbs_deb_net("enable promiscuous mode\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000578 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400579 CMD_ACT_MAC_PROMISCUOUS_ENABLE;
David Woodhouseaa21c002007-12-08 20:04:36 +0000580 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400581 ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE |
582 CMD_ACT_MAC_MULTICAST_ENABLE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200583 } else {
584 /* Multicast */
David Woodhouseaa21c002007-12-08 20:04:36 +0000585 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400586 ~CMD_ACT_MAC_PROMISCUOUS_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200587
588 if (dev->flags & IFF_ALLMULTI || dev->mc_count >
589 MRVDRV_MAX_MULTICAST_LIST_SIZE) {
Holger Schurig9012b282007-05-25 11:27:16 -0400590 lbs_deb_net( "enabling all multicast\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000591 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400592 CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
David Woodhouseaa21c002007-12-08 20:04:36 +0000593 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400594 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200595 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +0000596 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400597 ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200598
599 if (!dev->mc_count) {
Holger Schurig9012b282007-05-25 11:27:16 -0400600 lbs_deb_net("no multicast addresses, "
601 "disabling multicast\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000602 priv->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400603 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604 } else {
605 int i;
606
David Woodhouseaa21c002007-12-08 20:04:36 +0000607 priv->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400608 CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609
David Woodhouseaa21c002007-12-08 20:04:36 +0000610 priv->nr_of_multicastmacaddr =
611 lbs_copy_multicast_address(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200612
Holger Schurig9012b282007-05-25 11:27:16 -0400613 lbs_deb_net("multicast addresses: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200614 dev->mc_count);
615
616 for (i = 0; i < dev->mc_count; i++) {
Joe Perches0795af52007-10-03 17:59:30 -0700617 lbs_deb_net("Multicast address %d:%s\n",
618 i, print_mac(mac,
David Woodhouseaa21c002007-12-08 20:04:36 +0000619 priv->multicastlist[i]));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200620 }
Holger Schurig9012b282007-05-25 11:27:16 -0400621 /* send multicast addresses to firmware */
Holger Schurig10078322007-11-15 18:05:47 -0500622 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400623 CMD_MAC_MULTICAST_ADR,
624 CMD_ACT_SET, 0, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200625 NULL);
626 }
627 }
628 }
629
David Woodhouseaa21c002007-12-08 20:04:36 +0000630 if (priv->currentpacketfilter != oldpacketfilter) {
Holger Schurig10078322007-11-15 18:05:47 -0500631 lbs_set_mac_packet_filter(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200632 }
633
Holger Schurig9012b282007-05-25 11:27:16 -0400634 lbs_deb_leave(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200635}
636
637/**
Holger Schurig10078322007-11-15 18:05:47 -0500638 * @brief This function handles the major jobs in the LBS driver.
Holger Schurig9012b282007-05-25 11:27:16 -0400639 * It handles all events generated by firmware, RX data received
640 * from firmware and TX data sent from kernel.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641 *
Holger Schurig10078322007-11-15 18:05:47 -0500642 * @param data A pointer to lbs_thread structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200643 * @return 0
644 */
Holger Schurig10078322007-11-15 18:05:47 -0500645static int lbs_thread(void *data)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200646{
Dan Williamsfe336152007-08-02 11:32:25 -0400647 struct net_device *dev = data;
Holger Schurig69f90322007-11-23 15:43:44 +0100648 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200649 wait_queue_t wait;
650 u8 ireg = 0;
651
Holger Schurig9012b282007-05-25 11:27:16 -0400652 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200653
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200654 init_waitqueue_entry(&wait, current);
655
Dan Williamsb1b19072007-08-20 11:10:45 -0400656 set_freezable();
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000657
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200658 for (;;) {
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500659 int shouldsleep;
660
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000661 lbs_deb_thread( "main-thread 111: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000662 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200663
Dan Williamsfe336152007-08-02 11:32:25 -0400664 add_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200665 set_current_state(TASK_INTERRUPTIBLE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000666 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000667
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500668 if (priv->surpriseremoved)
669 shouldsleep = 0; /* Bye */
670 else if (priv->psstate == PS_STATE_SLEEP)
671 shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */
672 else if (priv->intcounter)
673 shouldsleep = 0; /* Interrupt pending. Deal with it now */
674 else if (priv->dnld_sent)
675 shouldsleep = 1; /* Something is en route to the device already */
David Woodhouse2eb188a2007-12-09 23:54:27 -0500676 else if (priv->tx_pending_len > 0)
677 shouldsleep = 0; /* We've a packet to send */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500678 else if (priv->cur_cmd)
679 shouldsleep = 1; /* Can't send a command; one already running */
680 else if (!list_empty(&priv->cmdpendingq))
681 shouldsleep = 0; /* We have a command to send */
682 else
683 shouldsleep = 1; /* No command */
684
685 if (shouldsleep) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000686 lbs_deb_thread("main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000687 priv->connect_status, priv->intcounter,
688 priv->psmode, priv->psstate);
689 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200690 schedule();
691 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000692 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200693
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000694 lbs_deb_thread("main-thread 222 (waking up): intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000695 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200696
697 set_current_state(TASK_RUNNING);
Dan Williamsfe336152007-08-02 11:32:25 -0400698 remove_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200699 try_to_freeze();
700
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000701 lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000702 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200703
David Woodhouseaa21c002007-12-08 20:04:36 +0000704 if (kthread_should_stop() || priv->surpriseremoved) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000705 lbs_deb_thread("main-thread: break from main thread: surpriseremoved=0x%x\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000706 priv->surpriseremoved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200707 break;
708 }
709
710
David Woodhouseaa21c002007-12-08 20:04:36 +0000711 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000712
David Woodhouseaa21c002007-12-08 20:04:36 +0000713 if (priv->intcounter) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200714 u8 int_status;
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000715
David Woodhouseaa21c002007-12-08 20:04:36 +0000716 priv->intcounter = 0;
Holger Schurig208fdd22007-05-25 12:17:06 -0400717 int_status = priv->hw_get_int_status(priv, &ireg);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200718
719 if (int_status) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000720 lbs_deb_thread("main-thread: reading HOST_INT_STATUS_REG failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000721 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200722 continue;
723 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000724 priv->hisregcpy |= ireg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200725 }
726
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000727 lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000728 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200729
730 /* command response? */
David Woodhouseaa21c002007-12-08 20:04:36 +0000731 if (priv->hisregcpy & MRVDRV_CMD_UPLD_RDY) {
Holger Schurig9012b282007-05-25 11:27:16 -0400732 lbs_deb_thread("main-thread: cmd response ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200733
David Woodhouseaa21c002007-12-08 20:04:36 +0000734 priv->hisregcpy &= ~MRVDRV_CMD_UPLD_RDY;
735 spin_unlock_irq(&priv->driver_lock);
Holger Schurig10078322007-11-15 18:05:47 -0500736 lbs_process_rx_command(priv);
David Woodhouseaa21c002007-12-08 20:04:36 +0000737 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200738 }
739
740 /* Any Card Event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000741 if (priv->hisregcpy & MRVDRV_CARDEVENT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400742 lbs_deb_thread("main-thread: Card Event Activity\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200743
David Woodhouseaa21c002007-12-08 20:04:36 +0000744 priv->hisregcpy &= ~MRVDRV_CARDEVENT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200745
Holger Schurig208fdd22007-05-25 12:17:06 -0400746 if (priv->hw_read_event_cause(priv)) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000747 lbs_pr_alert("main-thread: hw_read_event_cause failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000748 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200749 continue;
750 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000751 spin_unlock_irq(&priv->driver_lock);
Holger Schurig10078322007-11-15 18:05:47 -0500752 lbs_process_event(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200753 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000754 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200755
756 /* Check if we need to confirm Sleep Request received previously */
David Woodhouseaa21c002007-12-08 20:04:36 +0000757 if (priv->psstate == PS_STATE_PRE_SLEEP &&
758 !priv->dnld_sent && !priv->cur_cmd) {
759 if (priv->connect_status == LBS_CONNECTED) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000760 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 +0000761 priv->intcounter, priv->currenttxskb, priv->dnld_sent, priv->cur_cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200762
David Woodhouseaa21c002007-12-08 20:04:36 +0000763 lbs_ps_confirm_sleep(priv, (u16) priv->psmode);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000764 } else {
765 /* workaround for firmware sending
766 * deauth/linkloss event immediately
767 * after sleep request; remove this
768 * after firmware fixes it
769 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000770 priv->psstate = PS_STATE_AWAKE;
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000771 lbs_pr_alert("main-thread: ignore PS_SleepConfirm in non-connected state\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200772 }
773 }
774
775 /* The PS state is changed during processing of Sleep Request
776 * event above
777 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000778 if ((priv->psstate == PS_STATE_SLEEP) ||
779 (priv->psstate == PS_STATE_PRE_SLEEP))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200780 continue;
781
782 /* Execute the next command */
David Woodhouseaa21c002007-12-08 20:04:36 +0000783 if (!priv->dnld_sent && !priv->cur_cmd)
Holger Schurig10078322007-11-15 18:05:47 -0500784 lbs_execute_next_command(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200785
786 /* Wake-up command waiters which can't sleep in
Holger Schurig10078322007-11-15 18:05:47 -0500787 * lbs_prepare_and_send_command
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200788 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000789 if (!list_empty(&priv->cmdpendingq))
790 wake_up_all(&priv->cmd_pending);
David Woodhouse2eb188a2007-12-09 23:54:27 -0500791
792 spin_lock_irq(&priv->driver_lock);
793 if (!priv->dnld_sent && priv->tx_pending_len > 0) {
794 int ret = priv->hw_host_to_card(priv, MVMS_DAT,
795 priv->tx_pending_buf,
796 priv->tx_pending_len);
797 if (ret) {
798 lbs_deb_tx("host_to_card failed %d\n", ret);
799 priv->dnld_sent = DNLD_RES_RECEIVED;
800 }
801 priv->tx_pending_len = 0;
802 if (!priv->currenttxskb) {
803 /* We can wake the queues immediately if we aren't
804 waiting for TX feedback */
805 if (priv->connect_status == LBS_CONNECTED)
806 netif_wake_queue(priv->dev);
807 if (priv->mesh_dev &&
808 priv->mesh_connect_status == LBS_CONNECTED)
809 netif_wake_queue(priv->mesh_dev);
810 }
811 }
812 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200813 }
814
David Woodhouseaa21c002007-12-08 20:04:36 +0000815 del_timer(&priv->command_timer);
816 wake_up_all(&priv->cmd_pending);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200817
Holger Schurig9012b282007-05-25 11:27:16 -0400818 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200819 return 0;
820}
821
822/**
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400823 * @brief This function downloads firmware image, gets
824 * HW spec from firmware and set basic parameters to
825 * firmware.
826 *
Holger Schurig69f90322007-11-23 15:43:44 +0100827 * @param priv A pointer to struct lbs_private structure
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400828 * @return 0 or -1
829 */
Holger Schurig69f90322007-11-23 15:43:44 +0100830static int lbs_setup_firmware(struct lbs_private *priv)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400831{
832 int ret = -1;
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400833 struct cmd_ds_mesh_access mesh_access;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400834
835 lbs_deb_enter(LBS_DEB_FW);
836
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400837 /*
838 * Read MAC address from HW
839 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000840 memset(priv->current_addr, 0xff, ETH_ALEN);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400841
Holger Schurig10078322007-11-15 18:05:47 -0500842 ret = lbs_prepare_and_send_command(priv, CMD_GET_HW_SPEC,
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400843 0, CMD_OPTION_WAITFORRSP, 0, NULL);
844
845 if (ret) {
846 ret = -1;
847 goto done;
848 }
849
Holger Schurig10078322007-11-15 18:05:47 -0500850 lbs_set_mac_packet_filter(priv);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400851
852 /* Get the supported Data rates */
Holger Schurig10078322007-11-15 18:05:47 -0500853 ret = lbs_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400854 CMD_ACT_GET_TX_RATE,
855 CMD_OPTION_WAITFORRSP, 0, NULL);
856
857 if (ret) {
858 ret = -1;
859 goto done;
860 }
861
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400862 /* Disable mesh autostart */
863 if (priv->mesh_dev) {
864 memset(&mesh_access, 0, sizeof(mesh_access));
865 mesh_access.data[0] = cpu_to_le32(0);
Holger Schurig10078322007-11-15 18:05:47 -0500866 ret = lbs_prepare_and_send_command(priv,
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400867 CMD_MESH_ACCESS,
868 CMD_ACT_MESH_SET_AUTOSTART_ENABLED,
869 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
870 if (ret) {
871 ret = -1;
872 goto done;
873 }
874 priv->mesh_autostart_enabled = 0;
875 }
876
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400877 ret = 0;
878done:
879 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
880 return ret;
881}
882
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400883/**
884 * This function handles the timeout of command sending.
885 * It will re-send the same command again.
886 */
887static void command_timer_fn(unsigned long data)
888{
Holger Schurig69f90322007-11-23 15:43:44 +0100889 struct lbs_private *priv = (struct lbs_private *)data;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400890 struct cmd_ctrl_node *ptempnode;
891 struct cmd_ds_command *cmd;
892 unsigned long flags;
893
David Woodhouseaa21c002007-12-08 20:04:36 +0000894 ptempnode = priv->cur_cmd;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400895 if (ptempnode == NULL) {
896 lbs_deb_fw("ptempnode empty\n");
897 return;
898 }
899
900 cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr;
901 if (!cmd) {
902 lbs_deb_fw("cmd is NULL\n");
903 return;
904 }
905
906 lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command);
907
David Woodhouseaa21c002007-12-08 20:04:36 +0000908 if (!priv->fw_ready)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400909 return;
910
David Woodhouseaa21c002007-12-08 20:04:36 +0000911 spin_lock_irqsave(&priv->driver_lock, flags);
912 priv->cur_cmd = NULL;
913 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400914
915 lbs_deb_fw("re-sending same command because of timeout\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000916 lbs_queue_cmd(priv, ptempnode, 0);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400917
918 wake_up_interruptible(&priv->waitq);
919
920 return;
921}
922
Holger Schurig69f90322007-11-23 15:43:44 +0100923static int lbs_init_adapter(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -0400924{
Dan Williams954ee162007-08-20 11:43:25 -0400925 size_t bufsize;
926 int i, ret = 0;
927
928 /* Allocate buffer to store the BSSID list */
929 bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
David Woodhouseaa21c002007-12-08 20:04:36 +0000930 priv->networks = kzalloc(bufsize, GFP_KERNEL);
931 if (!priv->networks) {
Dan Williams954ee162007-08-20 11:43:25 -0400932 lbs_pr_err("Out of memory allocating beacons\n");
933 ret = -1;
934 goto out;
935 }
936
937 /* Initialize scan result lists */
David Woodhouseaa21c002007-12-08 20:04:36 +0000938 INIT_LIST_HEAD(&priv->network_free_list);
939 INIT_LIST_HEAD(&priv->network_list);
Dan Williams954ee162007-08-20 11:43:25 -0400940 for (i = 0; i < MAX_NETWORK_COUNT; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000941 list_add_tail(&priv->networks[i].list,
942 &priv->network_free_list);
Dan Williams954ee162007-08-20 11:43:25 -0400943 }
944
David Woodhouseaa21c002007-12-08 20:04:36 +0000945 priv->lbs_ps_confirm_sleep.seqnum = cpu_to_le16(++priv->seqnum);
946 priv->lbs_ps_confirm_sleep.command =
Dan Williams954ee162007-08-20 11:43:25 -0400947 cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000948 priv->lbs_ps_confirm_sleep.size =
Dan Williams954ee162007-08-20 11:43:25 -0400949 cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep));
David Woodhouseaa21c002007-12-08 20:04:36 +0000950 priv->lbs_ps_confirm_sleep.action =
Dan Williams954ee162007-08-20 11:43:25 -0400951 cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
952
David Woodhouseaa21c002007-12-08 20:04:36 +0000953 memset(priv->current_addr, 0xff, ETH_ALEN);
Dan Williams954ee162007-08-20 11:43:25 -0400954
David Woodhouseaa21c002007-12-08 20:04:36 +0000955 priv->connect_status = LBS_DISCONNECTED;
956 priv->mesh_connect_status = LBS_DISCONNECTED;
957 priv->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
958 priv->mode = IW_MODE_INFRA;
959 priv->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL;
960 priv->currentpacketfilter = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
961 priv->radioon = RADIO_ON;
962 priv->auto_rate = 1;
963 priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
964 priv->psmode = LBS802_11POWERMODECAM;
965 priv->psstate = PS_STATE_FULL_POWER;
Dan Williams954ee162007-08-20 11:43:25 -0400966
David Woodhouseaa21c002007-12-08 20:04:36 +0000967 mutex_init(&priv->lock);
Dan Williams954ee162007-08-20 11:43:25 -0400968
David Woodhouseaa21c002007-12-08 20:04:36 +0000969 setup_timer(&priv->command_timer, command_timer_fn,
Dan Williams954ee162007-08-20 11:43:25 -0400970 (unsigned long)priv);
971
David Woodhouseaa21c002007-12-08 20:04:36 +0000972 INIT_LIST_HEAD(&priv->cmdfreeq);
973 INIT_LIST_HEAD(&priv->cmdpendingq);
Dan Williams954ee162007-08-20 11:43:25 -0400974
David Woodhouseaa21c002007-12-08 20:04:36 +0000975 spin_lock_init(&priv->driver_lock);
976 init_waitqueue_head(&priv->cmd_pending);
Dan Williams954ee162007-08-20 11:43:25 -0400977
978 /* Allocate the command buffers */
Holger Schurig10078322007-11-15 18:05:47 -0500979 if (lbs_allocate_cmd_buffer(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -0400980 lbs_pr_err("Out of memory allocating command buffers\n");
981 ret = -1;
982 }
983
984out:
985 return ret;
986}
987
Holger Schurig69f90322007-11-23 15:43:44 +0100988static void lbs_free_adapter(struct lbs_private *priv)
Holger Schurigac558ca2007-08-02 11:49:06 -0400989{
Holger Schurigac558ca2007-08-02 11:49:06 -0400990 lbs_deb_fw("free command buffer\n");
Holger Schurig10078322007-11-15 18:05:47 -0500991 lbs_free_cmd_buffer(priv);
Holger Schurigac558ca2007-08-02 11:49:06 -0400992
993 lbs_deb_fw("free command_timer\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000994 del_timer(&priv->command_timer);
Holger Schurigac558ca2007-08-02 11:49:06 -0400995
996 lbs_deb_fw("free scan results table\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000997 kfree(priv->networks);
998 priv->networks = NULL;
Holger Schurigac558ca2007-08-02 11:49:06 -0400999}
1000
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001001/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001002 * @brief This function adds the card. it will probe the
Holger Schurig10078322007-11-15 18:05:47 -05001003 * card, allocate the lbs_priv and initialize the device.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001004 *
1005 * @param card A pointer to card
Holger Schurig69f90322007-11-23 15:43:44 +01001006 * @return A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001007 */
Holger Schurig69f90322007-11-23 15:43:44 +01001008struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001009{
1010 struct net_device *dev = NULL;
Holger Schurig69f90322007-11-23 15:43:44 +01001011 struct lbs_private *priv = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001012
Holger Schurig9012b282007-05-25 11:27:16 -04001013 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001014
1015 /* Allocate an Ethernet device and register it */
Holger Schurig69f90322007-11-23 15:43:44 +01001016 dev = alloc_etherdev(sizeof(struct lbs_private));
1017 if (!dev) {
Holger Schurig9012b282007-05-25 11:27:16 -04001018 lbs_pr_err("init ethX device failed\n");
Dan Williams954ee162007-08-20 11:43:25 -04001019 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001020 }
Dan Williams64f104e2007-08-20 11:45:16 -04001021 priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001022
Holger Schurig10078322007-11-15 18:05:47 -05001023 if (lbs_init_adapter(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001024 lbs_pr_err("failed to initialize adapter structure.\n");
1025 goto err_init_adapter;
1026 }
1027
Holger Schurig634b8f42007-05-25 13:05:16 -04001028 priv->dev = dev;
1029 priv->card = card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001030 priv->mesh_open = 0;
1031 priv->infra_open = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001032
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001033 /* Setup the OS Interface to our functions */
David Woodhouse8552855f2007-12-10 16:38:18 -05001034 dev->open = lbs_dev_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001035 dev->hard_start_xmit = lbs_hard_start_xmit;
David Woodhouse8552855f2007-12-10 16:38:18 -05001036 dev->stop = lbs_eth_stop;
Holger Schurig10078322007-11-15 18:05:47 -05001037 dev->set_mac_address = lbs_set_mac_address;
1038 dev->tx_timeout = lbs_tx_timeout;
1039 dev->get_stats = lbs_get_stats;
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001040 dev->watchdog_timeo = 5 * HZ;
Holger Schurig10078322007-11-15 18:05:47 -05001041 dev->ethtool_ops = &lbs_ethtool_ops;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001042#ifdef WIRELESS_EXT
Holger Schurig10078322007-11-15 18:05:47 -05001043 dev->wireless_handlers = (struct iw_handler_def *)&lbs_handler_def;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001044#endif
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001045 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
Holger Schurig10078322007-11-15 18:05:47 -05001046 dev->set_multicast_list = lbs_set_multicast_list;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001047
Dan Williams7732ca42007-05-25 13:13:25 -04001048 SET_NETDEV_DEV(dev, dmdev);
1049
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001050 priv->rtap_net_dev = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001051
Dan Williamsfe336152007-08-02 11:32:25 -04001052 lbs_deb_thread("Starting main thread...\n");
1053 init_waitqueue_head(&priv->waitq);
Holger Schurig10078322007-11-15 18:05:47 -05001054 priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
Dan Williamsfe336152007-08-02 11:32:25 -04001055 if (IS_ERR(priv->main_thread)) {
1056 lbs_deb_thread("Error creating main thread.\n");
David Woodhousee7deced2007-12-08 18:29:16 +00001057 goto err_init_adapter;
Dan Williamsfe336152007-08-02 11:32:25 -04001058 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001059
Holger Schurig10078322007-11-15 18:05:47 -05001060 priv->work_thread = create_singlethread_workqueue("lbs_worker");
1061 INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker);
1062 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
1063 INIT_WORK(&priv->sync_channel, lbs_sync_channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064
Dan Williams954ee162007-08-20 11:43:25 -04001065 goto done;
1066
Dan Williams954ee162007-08-20 11:43:25 -04001067err_init_adapter:
Holger Schurig10078322007-11-15 18:05:47 -05001068 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001069 free_netdev(dev);
1070 priv = NULL;
1071
1072done:
1073 lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv);
1074 return priv;
1075}
Holger Schurig10078322007-11-15 18:05:47 -05001076EXPORT_SYMBOL_GPL(lbs_add_card);
Dan Williams954ee162007-08-20 11:43:25 -04001077
1078
Holger Schurig69f90322007-11-23 15:43:44 +01001079int lbs_remove_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001080{
Dan Williams954ee162007-08-20 11:43:25 -04001081 struct net_device *dev = priv->dev;
1082 union iwreq_data wrqu;
1083
1084 lbs_deb_enter(LBS_DEB_MAIN);
1085
Holger Schurig10078322007-11-15 18:05:47 -05001086 lbs_remove_rtap(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001087
1088 dev = priv->dev;
David Woodhousee7deced2007-12-08 18:29:16 +00001089 device_remove_file(&dev->dev, &dev_attr_lbs_rtap);
Dan Williams954ee162007-08-20 11:43:25 -04001090
1091 cancel_delayed_work(&priv->scan_work);
1092 cancel_delayed_work(&priv->assoc_work);
1093 destroy_workqueue(priv->work_thread);
1094
David Woodhouseaa21c002007-12-08 20:04:36 +00001095 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
1096 priv->psmode = LBS802_11POWERMODECAM;
Holger Schurig10078322007-11-15 18:05:47 -05001097 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001098 }
1099
Dan Williams954ee162007-08-20 11:43:25 -04001100 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
1101 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1102 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
1103
1104 /* Stop the thread servicing the interrupts */
David Woodhouseaa21c002007-12-08 20:04:36 +00001105 priv->surpriseremoved = 1;
Dan Williams954ee162007-08-20 11:43:25 -04001106 kthread_stop(priv->main_thread);
1107
Holger Schurig10078322007-11-15 18:05:47 -05001108 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001109
1110 priv->dev = NULL;
1111 free_netdev(dev);
1112
1113 lbs_deb_leave(LBS_DEB_MAIN);
1114 return 0;
1115}
Holger Schurig10078322007-11-15 18:05:47 -05001116EXPORT_SYMBOL_GPL(lbs_remove_card);
Dan Williams954ee162007-08-20 11:43:25 -04001117
1118
Holger Schurig69f90322007-11-23 15:43:44 +01001119int lbs_start_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001120{
1121 struct net_device *dev = priv->dev;
1122 int ret = -1;
1123
1124 lbs_deb_enter(LBS_DEB_MAIN);
1125
1126 /* poke the firmware */
Holger Schurig10078322007-11-15 18:05:47 -05001127 ret = lbs_setup_firmware(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001128 if (ret)
1129 goto done;
1130
1131 /* init 802.11d */
Holger Schurig10078322007-11-15 18:05:47 -05001132 lbs_init_11d(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001133
1134 if (register_netdev(dev)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001135 lbs_pr_err("cannot register ethX device\n");
Dan Williams954ee162007-08-20 11:43:25 -04001136 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001137 }
David Woodhousee7deced2007-12-08 18:29:16 +00001138 if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
1139 lbs_pr_err("cannot register lbs_rtap attribute\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001140
Holger Schurig10078322007-11-15 18:05:47 -05001141 lbs_debugfs_init_one(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001142
Dan Williams954ee162007-08-20 11:43:25 -04001143 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001144
Dan Williams954ee162007-08-20 11:43:25 -04001145 ret = 0;
1146
Holger Schurig32a74b72007-05-25 12:04:31 -04001147done:
Dan Williams954ee162007-08-20 11:43:25 -04001148 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
Holger Schurig32a74b72007-05-25 12:04:31 -04001149 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001150}
Holger Schurig10078322007-11-15 18:05:47 -05001151EXPORT_SYMBOL_GPL(lbs_start_card);
Dan Williams954ee162007-08-20 11:43:25 -04001152
1153
Holger Schurig69f90322007-11-23 15:43:44 +01001154int lbs_stop_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001155{
1156 struct net_device *dev = priv->dev;
1157 int ret = -1;
1158 struct cmd_ctrl_node *cmdnode;
1159 unsigned long flags;
1160
1161 lbs_deb_enter(LBS_DEB_MAIN);
1162
1163 netif_stop_queue(priv->dev);
1164 netif_carrier_off(priv->dev);
1165
Holger Schurig10078322007-11-15 18:05:47 -05001166 lbs_debugfs_remove_one(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001167
1168 /* Flush pending command nodes */
David Woodhouseaa21c002007-12-08 20:04:36 +00001169 spin_lock_irqsave(&priv->driver_lock, flags);
1170 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
Dan Williams954ee162007-08-20 11:43:25 -04001171 cmdnode->cmdwaitqwoken = 1;
1172 wake_up_interruptible(&cmdnode->cmdwait_q);
1173 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001174 spin_unlock_irqrestore(&priv->driver_lock, flags);
Dan Williams954ee162007-08-20 11:43:25 -04001175
1176 unregister_netdev(dev);
1177
1178 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1179 return ret;
1180}
Holger Schurig10078322007-11-15 18:05:47 -05001181EXPORT_SYMBOL_GPL(lbs_stop_card);
Holger Schurig084708b2007-05-25 12:37:58 -04001182
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001183
Holger Schurig78523da2007-05-25 11:49:19 -04001184/**
1185 * @brief This function adds mshX interface
1186 *
Holger Schurig69f90322007-11-23 15:43:44 +01001187 * @param priv A pointer to the struct lbs_private structure
Holger Schurig78523da2007-05-25 11:49:19 -04001188 * @return 0 if successful, -X otherwise
1189 */
Holger Schurig69f90322007-11-23 15:43:44 +01001190int lbs_add_mesh(struct lbs_private *priv, struct device *dev)
Holger Schurig78523da2007-05-25 11:49:19 -04001191{
1192 struct net_device *mesh_dev = NULL;
1193 int ret = 0;
1194
1195 lbs_deb_enter(LBS_DEB_MESH);
1196
1197 /* Allocate a virtual mesh device */
1198 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
1199 lbs_deb_mesh("init mshX device failed\n");
1200 ret = -ENOMEM;
1201 goto done;
1202 }
1203 mesh_dev->priv = priv;
1204 priv->mesh_dev = mesh_dev;
1205
David Woodhouse8552855f2007-12-10 16:38:18 -05001206 mesh_dev->open = lbs_dev_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001207 mesh_dev->hard_start_xmit = lbs_hard_start_xmit;
David Woodhouse8552855f2007-12-10 16:38:18 -05001208 mesh_dev->stop = lbs_mesh_stop;
Holger Schurig10078322007-11-15 18:05:47 -05001209 mesh_dev->get_stats = lbs_get_stats;
1210 mesh_dev->set_mac_address = lbs_set_mac_address;
1211 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
Holger Schurig634b8f42007-05-25 13:05:16 -04001212 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
1213 sizeof(priv->dev->dev_addr));
Holger Schurig78523da2007-05-25 11:49:19 -04001214
Dan Williams7732ca42007-05-25 13:13:25 -04001215 SET_NETDEV_DEV(priv->mesh_dev, dev);
1216
Holger Schurig78523da2007-05-25 11:49:19 -04001217#ifdef WIRELESS_EXT
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04001218 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
Holger Schurig78523da2007-05-25 11:49:19 -04001219#endif
Holger Schurig78523da2007-05-25 11:49:19 -04001220 /* Register virtual mesh interface */
1221 ret = register_netdev(mesh_dev);
1222 if (ret) {
1223 lbs_pr_err("cannot register mshX virtual interface\n");
1224 goto err_free;
1225 }
1226
Holger Schurig10078322007-11-15 18:05:47 -05001227 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001228 if (ret)
1229 goto err_unregister;
1230
1231 /* Everything successful */
1232 ret = 0;
1233 goto done;
1234
Holger Schurig78523da2007-05-25 11:49:19 -04001235err_unregister:
1236 unregister_netdev(mesh_dev);
1237
1238err_free:
1239 free_netdev(mesh_dev);
1240
1241done:
1242 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
1243 return ret;
1244}
Holger Schurig10078322007-11-15 18:05:47 -05001245EXPORT_SYMBOL_GPL(lbs_add_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001246
Holger Schurig084708b2007-05-25 12:37:58 -04001247
Holger Schurig69f90322007-11-23 15:43:44 +01001248void lbs_remove_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001249{
1250 struct net_device *mesh_dev;
1251
Dan Williams954ee162007-08-20 11:43:25 -04001252 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig78523da2007-05-25 11:49:19 -04001253
1254 if (!priv)
1255 goto out;
1256
1257 mesh_dev = priv->mesh_dev;
1258
1259 netif_stop_queue(mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -04001260 netif_carrier_off(priv->mesh_dev);
Holger Schurig78523da2007-05-25 11:49:19 -04001261
Holger Schurig10078322007-11-15 18:05:47 -05001262 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001263 unregister_netdev(mesh_dev);
1264
1265 priv->mesh_dev = NULL ;
1266 free_netdev(mesh_dev);
1267
1268out:
Dan Williams954ee162007-08-20 11:43:25 -04001269 lbs_deb_leave(LBS_DEB_MAIN);
Holger Schurig78523da2007-05-25 11:49:19 -04001270}
Holger Schurig10078322007-11-15 18:05:47 -05001271EXPORT_SYMBOL_GPL(lbs_remove_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001272
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001273/**
1274 * @brief This function finds the CFP in
1275 * region_cfp_table based on region and band parameter.
1276 *
1277 * @param region The region code
1278 * @param band The band
1279 * @param cfp_no A pointer to CFP number
1280 * @return A pointer to CFP
1281 */
Holger Schurig10078322007-11-15 18:05:47 -05001282struct chan_freq_power *lbs_get_region_cfp_table(u8 region, u8 band, int *cfp_no)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001283{
1284 int i, end;
1285
Holger Schurig9012b282007-05-25 11:27:16 -04001286 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001287
Denis Chengff8ac602007-09-02 18:30:18 +08001288 end = ARRAY_SIZE(region_cfp_table);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001289
1290 for (i = 0; i < end ; i++) {
Holger Schurig9012b282007-05-25 11:27:16 -04001291 lbs_deb_main("region_cfp_table[i].region=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001292 region_cfp_table[i].region);
1293 if (region_cfp_table[i].region == region) {
1294 *cfp_no = region_cfp_table[i].cfp_no_BG;
Holger Schurig9012b282007-05-25 11:27:16 -04001295 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001296 return region_cfp_table[i].cfp_BG;
1297 }
1298 }
1299
Holger Schurig9012b282007-05-25 11:27:16 -04001300 lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001301 return NULL;
1302}
1303
Holger Schurig69f90322007-11-23 15:43:44 +01001304int lbs_set_regiontable(struct lbs_private *priv, u8 region, u8 band)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001305{
Holger Schurig9012b282007-05-25 11:27:16 -04001306 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001307 int i = 0;
1308
1309 struct chan_freq_power *cfp;
1310 int cfp_no;
1311
Holger Schurig9012b282007-05-25 11:27:16 -04001312 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001313
David Woodhouseaa21c002007-12-08 20:04:36 +00001314 memset(priv->region_channel, 0, sizeof(priv->region_channel));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001315
1316 {
Holger Schurig10078322007-11-15 18:05:47 -05001317 cfp = lbs_get_region_cfp_table(region, band, &cfp_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001318 if (cfp != NULL) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001319 priv->region_channel[i].nrcfp = cfp_no;
1320 priv->region_channel[i].CFP = cfp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001321 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001322 lbs_deb_main("wrong region code %#x in band B/G\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001323 region);
Holger Schurig9012b282007-05-25 11:27:16 -04001324 ret = -1;
1325 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001326 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001327 priv->region_channel[i].valid = 1;
1328 priv->region_channel[i].region = region;
1329 priv->region_channel[i].band = band;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001330 i++;
1331 }
Holger Schurig9012b282007-05-25 11:27:16 -04001332out:
1333 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1334 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001335}
1336
1337/**
1338 * @brief This function handles the interrupt. it will change PS
1339 * state if applicable. it will wake up main_thread to handle
1340 * the interrupt event as well.
1341 *
1342 * @param dev A pointer to net_device structure
1343 * @return n/a
1344 */
David Woodhouse4f679492007-12-10 14:58:37 -05001345void lbs_interrupt(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001346{
Holger Schuriged37b512007-05-25 11:52:42 -04001347 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001348
David Woodhouse4f679492007-12-10 14:58:37 -05001349 lbs_deb_thread("lbs_interrupt: intcounter=%d\n", priv->intcounter);
1350
1351 if (spin_trylock(&priv->driver_lock)) {
1352 spin_unlock(&priv->driver_lock);
1353 printk(KERN_CRIT "%s called without driver_lock held\n", __func__);
1354 WARN_ON(1);
1355 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001356
David Woodhouseaa21c002007-12-08 20:04:36 +00001357 priv->intcounter++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001358
David Woodhouse4f679492007-12-10 14:58:37 -05001359 if (priv->psstate == PS_STATE_SLEEP)
David Woodhouseaa21c002007-12-08 20:04:36 +00001360 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001361
Dan Williamsfe336152007-08-02 11:32:25 -04001362 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001363
Holger Schuriged37b512007-05-25 11:52:42 -04001364 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001365}
Holger Schurig10078322007-11-15 18:05:47 -05001366EXPORT_SYMBOL_GPL(lbs_interrupt);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001367
Holger Schurig69f90322007-11-23 15:43:44 +01001368int lbs_reset_device(struct lbs_private *priv)
Dan Williamseedc2a32007-08-02 11:36:22 -04001369{
1370 int ret;
1371
1372 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001373 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RESET,
Dan Williamseedc2a32007-08-02 11:36:22 -04001374 CMD_ACT_HALT, 0, 0, NULL);
1375 msleep_interruptible(10);
1376
1377 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1378 return ret;
1379}
Holger Schurig10078322007-11-15 18:05:47 -05001380EXPORT_SYMBOL_GPL(lbs_reset_device);
Dan Williamseedc2a32007-08-02 11:36:22 -04001381
Andres Salomon4fb910f2007-11-20 17:43:45 -05001382static int __init lbs_init_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001383{
Holger Schurig9012b282007-05-25 11:27:16 -04001384 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001385 lbs_debugfs_init();
Holger Schurig084708b2007-05-25 12:37:58 -04001386 lbs_deb_leave(LBS_DEB_MAIN);
1387 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001388}
1389
Andres Salomon4fb910f2007-11-20 17:43:45 -05001390static void __exit lbs_exit_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001391{
Holger Schurig9012b282007-05-25 11:27:16 -04001392 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001393
Holger Schurig10078322007-11-15 18:05:47 -05001394 lbs_debugfs_remove();
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001395
Holger Schurig9012b282007-05-25 11:27:16 -04001396 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001397}
1398
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001399/*
1400 * rtap interface support fuctions
1401 */
1402
Holger Schurig10078322007-11-15 18:05:47 -05001403static int lbs_rtap_open(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001404{
David Woodhouse8552855f2007-12-10 16:38:18 -05001405 /* Yes, _stop_ the queue. Because we don't support injection */
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001406 netif_carrier_off(dev);
1407 netif_stop_queue(dev);
1408 return 0;
1409}
1410
Holger Schurig10078322007-11-15 18:05:47 -05001411static int lbs_rtap_stop(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001412{
1413 return 0;
1414}
1415
Holger Schurig10078322007-11-15 18:05:47 -05001416static int lbs_rtap_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001417{
1418 netif_stop_queue(dev);
David Woodhouse8552855f2007-12-10 16:38:18 -05001419 return NETDEV_TX_BUSY;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001420}
1421
Holger Schurig10078322007-11-15 18:05:47 -05001422static struct net_device_stats *lbs_rtap_get_stats(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001423{
Holger Schurig69f90322007-11-23 15:43:44 +01001424 struct lbs_private *priv = dev->priv;
David Woodhoused9268fb2007-12-09 16:22:21 -05001425 return &priv->stats;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001426}
1427
1428
Holger Schurig69f90322007-11-23 15:43:44 +01001429void lbs_remove_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001430{
1431 if (priv->rtap_net_dev == NULL)
1432 return;
1433 unregister_netdev(priv->rtap_net_dev);
David Woodhoused9268fb2007-12-09 16:22:21 -05001434 free_netdev(priv->rtap_net_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001435 priv->rtap_net_dev = NULL;
1436}
1437
Holger Schurig69f90322007-11-23 15:43:44 +01001438int lbs_add_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001439{
1440 int rc = 0;
David Woodhoused9268fb2007-12-09 16:22:21 -05001441 struct net_device *rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001442
1443 if (priv->rtap_net_dev)
1444 return -EPERM;
1445
David Woodhoused9268fb2007-12-09 16:22:21 -05001446 rtap_dev = alloc_netdev(0, "rtap%d", ether_setup);
1447 if (rtap_dev == NULL)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001448 return -ENOMEM;
1449
David Woodhouse121947c2007-12-09 19:54:11 -05001450 memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN);
David Woodhoused9268fb2007-12-09 16:22:21 -05001451 rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP;
1452 rtap_dev->open = lbs_rtap_open;
1453 rtap_dev->stop = lbs_rtap_stop;
1454 rtap_dev->get_stats = lbs_rtap_get_stats;
1455 rtap_dev->hard_start_xmit = lbs_rtap_hard_start_xmit;
1456 rtap_dev->set_multicast_list = lbs_set_multicast_list;
1457 rtap_dev->priv = priv;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001458
David Woodhoused9268fb2007-12-09 16:22:21 -05001459 rc = register_netdev(rtap_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001460 if (rc) {
David Woodhoused9268fb2007-12-09 16:22:21 -05001461 free_netdev(rtap_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001462 return rc;
1463 }
David Woodhoused9268fb2007-12-09 16:22:21 -05001464 priv->rtap_net_dev = rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001465
1466 return 0;
1467}
1468
1469
Holger Schurig10078322007-11-15 18:05:47 -05001470module_init(lbs_init_module);
1471module_exit(lbs_exit_module);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001472
Holger Schurig084708b2007-05-25 12:37:58 -04001473MODULE_DESCRIPTION("Libertas WLAN Driver Library");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001474MODULE_AUTHOR("Marvell International Ltd.");
1475MODULE_LICENSE("GPL");