blob: 9a231099212f8a9e734de31a2dea8b8c96e47094 [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 */
David Woodhouseb15152a2007-12-11 11:55:37 -0500674 else if (!priv->fw_ready)
675 shouldsleep = 1; /* Firmware not ready. We're waiting for it */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500676 else if (priv->dnld_sent)
677 shouldsleep = 1; /* Something is en route to the device already */
David Woodhouse2eb188a2007-12-09 23:54:27 -0500678 else if (priv->tx_pending_len > 0)
679 shouldsleep = 0; /* We've a packet to send */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500680 else if (priv->cur_cmd)
681 shouldsleep = 1; /* Can't send a command; one already running */
682 else if (!list_empty(&priv->cmdpendingq))
683 shouldsleep = 0; /* We have a command to send */
684 else
685 shouldsleep = 1; /* No command */
686
687 if (shouldsleep) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000688 lbs_deb_thread("main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000689 priv->connect_status, priv->intcounter,
690 priv->psmode, priv->psstate);
691 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200692 schedule();
693 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000694 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200695
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000696 lbs_deb_thread("main-thread 222 (waking up): intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000697 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200698
699 set_current_state(TASK_RUNNING);
Dan Williamsfe336152007-08-02 11:32:25 -0400700 remove_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200701 try_to_freeze();
702
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000703 lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000704 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200705
David Woodhouseaa21c002007-12-08 20:04:36 +0000706 if (kthread_should_stop() || priv->surpriseremoved) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000707 lbs_deb_thread("main-thread: break from main thread: surpriseremoved=0x%x\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000708 priv->surpriseremoved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709 break;
710 }
711
712
David Woodhouseaa21c002007-12-08 20:04:36 +0000713 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000714
David Woodhouseaa21c002007-12-08 20:04:36 +0000715 if (priv->intcounter) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200716 u8 int_status;
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000717
David Woodhouseaa21c002007-12-08 20:04:36 +0000718 priv->intcounter = 0;
Holger Schurig208fdd22007-05-25 12:17:06 -0400719 int_status = priv->hw_get_int_status(priv, &ireg);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200720
721 if (int_status) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000722 lbs_deb_thread("main-thread: reading HOST_INT_STATUS_REG failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000723 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200724 continue;
725 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000726 priv->hisregcpy |= ireg;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200727 }
728
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000729 lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000730 priv->intcounter, priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200731
732 /* command response? */
David Woodhouseaa21c002007-12-08 20:04:36 +0000733 if (priv->hisregcpy & MRVDRV_CMD_UPLD_RDY) {
Holger Schurig9012b282007-05-25 11:27:16 -0400734 lbs_deb_thread("main-thread: cmd response ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200735
David Woodhouseaa21c002007-12-08 20:04:36 +0000736 priv->hisregcpy &= ~MRVDRV_CMD_UPLD_RDY;
737 spin_unlock_irq(&priv->driver_lock);
Holger Schurig10078322007-11-15 18:05:47 -0500738 lbs_process_rx_command(priv);
David Woodhouseaa21c002007-12-08 20:04:36 +0000739 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200740 }
741
742 /* Any Card Event */
David Woodhouseaa21c002007-12-08 20:04:36 +0000743 if (priv->hisregcpy & MRVDRV_CARDEVENT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400744 lbs_deb_thread("main-thread: Card Event Activity\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200745
David Woodhouseaa21c002007-12-08 20:04:36 +0000746 priv->hisregcpy &= ~MRVDRV_CARDEVENT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200747
Holger Schurig208fdd22007-05-25 12:17:06 -0400748 if (priv->hw_read_event_cause(priv)) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000749 lbs_pr_alert("main-thread: hw_read_event_cause failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000750 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200751 continue;
752 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000753 spin_unlock_irq(&priv->driver_lock);
Holger Schurig10078322007-11-15 18:05:47 -0500754 lbs_process_event(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200755 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000756 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200757
David Woodhouseb15152a2007-12-11 11:55:37 -0500758 if (!priv->fw_ready)
759 continue;
760
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200761 /* Check if we need to confirm Sleep Request received previously */
David Woodhouseaa21c002007-12-08 20:04:36 +0000762 if (priv->psstate == PS_STATE_PRE_SLEEP &&
763 !priv->dnld_sent && !priv->cur_cmd) {
764 if (priv->connect_status == LBS_CONNECTED) {
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000765 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 +0000766 priv->intcounter, priv->currenttxskb, priv->dnld_sent, priv->cur_cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200767
David Woodhouseaa21c002007-12-08 20:04:36 +0000768 lbs_ps_confirm_sleep(priv, (u16) priv->psmode);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000769 } else {
770 /* workaround for firmware sending
771 * deauth/linkloss event immediately
772 * after sleep request; remove this
773 * after firmware fixes it
774 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000775 priv->psstate = PS_STATE_AWAKE;
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000776 lbs_pr_alert("main-thread: ignore PS_SleepConfirm in non-connected state\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200777 }
778 }
779
780 /* The PS state is changed during processing of Sleep Request
781 * event above
782 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000783 if ((priv->psstate == PS_STATE_SLEEP) ||
784 (priv->psstate == PS_STATE_PRE_SLEEP))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200785 continue;
786
787 /* Execute the next command */
David Woodhouseaa21c002007-12-08 20:04:36 +0000788 if (!priv->dnld_sent && !priv->cur_cmd)
Holger Schurig10078322007-11-15 18:05:47 -0500789 lbs_execute_next_command(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200790
791 /* Wake-up command waiters which can't sleep in
Holger Schurig10078322007-11-15 18:05:47 -0500792 * lbs_prepare_and_send_command
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200793 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000794 if (!list_empty(&priv->cmdpendingq))
795 wake_up_all(&priv->cmd_pending);
David Woodhouse2eb188a2007-12-09 23:54:27 -0500796
797 spin_lock_irq(&priv->driver_lock);
798 if (!priv->dnld_sent && priv->tx_pending_len > 0) {
799 int ret = priv->hw_host_to_card(priv, MVMS_DAT,
800 priv->tx_pending_buf,
801 priv->tx_pending_len);
802 if (ret) {
803 lbs_deb_tx("host_to_card failed %d\n", ret);
804 priv->dnld_sent = DNLD_RES_RECEIVED;
805 }
806 priv->tx_pending_len = 0;
807 if (!priv->currenttxskb) {
808 /* We can wake the queues immediately if we aren't
809 waiting for TX feedback */
810 if (priv->connect_status == LBS_CONNECTED)
811 netif_wake_queue(priv->dev);
812 if (priv->mesh_dev &&
813 priv->mesh_connect_status == LBS_CONNECTED)
814 netif_wake_queue(priv->mesh_dev);
815 }
816 }
817 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200818 }
819
David Woodhouseaa21c002007-12-08 20:04:36 +0000820 del_timer(&priv->command_timer);
821 wake_up_all(&priv->cmd_pending);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200822
Holger Schurig9012b282007-05-25 11:27:16 -0400823 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200824 return 0;
825}
826
827/**
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400828 * @brief This function downloads firmware image, gets
829 * HW spec from firmware and set basic parameters to
830 * firmware.
831 *
Holger Schurig69f90322007-11-23 15:43:44 +0100832 * @param priv A pointer to struct lbs_private structure
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400833 * @return 0 or -1
834 */
Holger Schurig69f90322007-11-23 15:43:44 +0100835static int lbs_setup_firmware(struct lbs_private *priv)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400836{
837 int ret = -1;
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400838 struct cmd_ds_mesh_access mesh_access;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400839
840 lbs_deb_enter(LBS_DEB_FW);
841
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400842 /*
843 * Read MAC address from HW
844 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000845 memset(priv->current_addr, 0xff, ETH_ALEN);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400846
Holger Schurig10078322007-11-15 18:05:47 -0500847 ret = lbs_prepare_and_send_command(priv, CMD_GET_HW_SPEC,
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400848 0, CMD_OPTION_WAITFORRSP, 0, NULL);
849
850 if (ret) {
851 ret = -1;
852 goto done;
853 }
854
Holger Schurig10078322007-11-15 18:05:47 -0500855 lbs_set_mac_packet_filter(priv);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400856
857 /* Get the supported Data rates */
Holger Schurig10078322007-11-15 18:05:47 -0500858 ret = lbs_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400859 CMD_ACT_GET_TX_RATE,
860 CMD_OPTION_WAITFORRSP, 0, NULL);
861
862 if (ret) {
863 ret = -1;
864 goto done;
865 }
866
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400867 /* Disable mesh autostart */
868 if (priv->mesh_dev) {
869 memset(&mesh_access, 0, sizeof(mesh_access));
870 mesh_access.data[0] = cpu_to_le32(0);
Holger Schurig10078322007-11-15 18:05:47 -0500871 ret = lbs_prepare_and_send_command(priv,
Luis Carlos Cobod21b31f2007-08-02 13:16:02 -0400872 CMD_MESH_ACCESS,
873 CMD_ACT_MESH_SET_AUTOSTART_ENABLED,
874 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
875 if (ret) {
876 ret = -1;
877 goto done;
878 }
879 priv->mesh_autostart_enabled = 0;
880 }
881
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400882 ret = 0;
883done:
884 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
885 return ret;
886}
887
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400888/**
889 * This function handles the timeout of command sending.
890 * It will re-send the same command again.
891 */
892static void command_timer_fn(unsigned long data)
893{
Holger Schurig69f90322007-11-23 15:43:44 +0100894 struct lbs_private *priv = (struct lbs_private *)data;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400895 struct cmd_ctrl_node *ptempnode;
896 struct cmd_ds_command *cmd;
897 unsigned long flags;
898
David Woodhouseaa21c002007-12-08 20:04:36 +0000899 ptempnode = priv->cur_cmd;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400900 if (ptempnode == NULL) {
901 lbs_deb_fw("ptempnode empty\n");
902 return;
903 }
904
905 cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr;
906 if (!cmd) {
907 lbs_deb_fw("cmd is NULL\n");
908 return;
909 }
910
911 lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command);
912
David Woodhouseaa21c002007-12-08 20:04:36 +0000913 if (!priv->fw_ready)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400914 return;
915
David Woodhouseaa21c002007-12-08 20:04:36 +0000916 spin_lock_irqsave(&priv->driver_lock, flags);
917 priv->cur_cmd = NULL;
918 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400919
920 lbs_deb_fw("re-sending same command because of timeout\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000921 lbs_queue_cmd(priv, ptempnode, 0);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400922
923 wake_up_interruptible(&priv->waitq);
924
925 return;
926}
927
Holger Schurig69f90322007-11-23 15:43:44 +0100928static int lbs_init_adapter(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -0400929{
Dan Williams954ee162007-08-20 11:43:25 -0400930 size_t bufsize;
931 int i, ret = 0;
932
933 /* Allocate buffer to store the BSSID list */
934 bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
David Woodhouseaa21c002007-12-08 20:04:36 +0000935 priv->networks = kzalloc(bufsize, GFP_KERNEL);
936 if (!priv->networks) {
Dan Williams954ee162007-08-20 11:43:25 -0400937 lbs_pr_err("Out of memory allocating beacons\n");
938 ret = -1;
939 goto out;
940 }
941
942 /* Initialize scan result lists */
David Woodhouseaa21c002007-12-08 20:04:36 +0000943 INIT_LIST_HEAD(&priv->network_free_list);
944 INIT_LIST_HEAD(&priv->network_list);
Dan Williams954ee162007-08-20 11:43:25 -0400945 for (i = 0; i < MAX_NETWORK_COUNT; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000946 list_add_tail(&priv->networks[i].list,
947 &priv->network_free_list);
Dan Williams954ee162007-08-20 11:43:25 -0400948 }
949
David Woodhouseaa21c002007-12-08 20:04:36 +0000950 priv->lbs_ps_confirm_sleep.seqnum = cpu_to_le16(++priv->seqnum);
951 priv->lbs_ps_confirm_sleep.command =
Dan Williams954ee162007-08-20 11:43:25 -0400952 cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000953 priv->lbs_ps_confirm_sleep.size =
Dan Williams954ee162007-08-20 11:43:25 -0400954 cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep));
David Woodhouseaa21c002007-12-08 20:04:36 +0000955 priv->lbs_ps_confirm_sleep.action =
Dan Williams954ee162007-08-20 11:43:25 -0400956 cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
957
David Woodhouseaa21c002007-12-08 20:04:36 +0000958 memset(priv->current_addr, 0xff, ETH_ALEN);
Dan Williams954ee162007-08-20 11:43:25 -0400959
David Woodhouseaa21c002007-12-08 20:04:36 +0000960 priv->connect_status = LBS_DISCONNECTED;
961 priv->mesh_connect_status = LBS_DISCONNECTED;
962 priv->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
963 priv->mode = IW_MODE_INFRA;
964 priv->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL;
965 priv->currentpacketfilter = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
966 priv->radioon = RADIO_ON;
967 priv->auto_rate = 1;
968 priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
969 priv->psmode = LBS802_11POWERMODECAM;
970 priv->psstate = PS_STATE_FULL_POWER;
Dan Williams954ee162007-08-20 11:43:25 -0400971
David Woodhouseaa21c002007-12-08 20:04:36 +0000972 mutex_init(&priv->lock);
Dan Williams954ee162007-08-20 11:43:25 -0400973
David Woodhouseaa21c002007-12-08 20:04:36 +0000974 setup_timer(&priv->command_timer, command_timer_fn,
Dan Williams954ee162007-08-20 11:43:25 -0400975 (unsigned long)priv);
976
David Woodhouseaa21c002007-12-08 20:04:36 +0000977 INIT_LIST_HEAD(&priv->cmdfreeq);
978 INIT_LIST_HEAD(&priv->cmdpendingq);
Dan Williams954ee162007-08-20 11:43:25 -0400979
David Woodhouseaa21c002007-12-08 20:04:36 +0000980 spin_lock_init(&priv->driver_lock);
981 init_waitqueue_head(&priv->cmd_pending);
Dan Williams954ee162007-08-20 11:43:25 -0400982
983 /* Allocate the command buffers */
Holger Schurig10078322007-11-15 18:05:47 -0500984 if (lbs_allocate_cmd_buffer(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -0400985 lbs_pr_err("Out of memory allocating command buffers\n");
986 ret = -1;
987 }
988
989out:
990 return ret;
991}
992
Holger Schurig69f90322007-11-23 15:43:44 +0100993static void lbs_free_adapter(struct lbs_private *priv)
Holger Schurigac558ca2007-08-02 11:49:06 -0400994{
Holger Schurigac558ca2007-08-02 11:49:06 -0400995 lbs_deb_fw("free command buffer\n");
Holger Schurig10078322007-11-15 18:05:47 -0500996 lbs_free_cmd_buffer(priv);
Holger Schurigac558ca2007-08-02 11:49:06 -0400997
998 lbs_deb_fw("free command_timer\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000999 del_timer(&priv->command_timer);
Holger Schurigac558ca2007-08-02 11:49:06 -04001000
1001 lbs_deb_fw("free scan results table\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001002 kfree(priv->networks);
1003 priv->networks = NULL;
Holger Schurigac558ca2007-08-02 11:49:06 -04001004}
1005
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001006/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001007 * @brief This function adds the card. it will probe the
Holger Schurig10078322007-11-15 18:05:47 -05001008 * card, allocate the lbs_priv and initialize the device.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001009 *
1010 * @param card A pointer to card
Holger Schurig69f90322007-11-23 15:43:44 +01001011 * @return A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001012 */
Holger Schurig69f90322007-11-23 15:43:44 +01001013struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001014{
1015 struct net_device *dev = NULL;
Holger Schurig69f90322007-11-23 15:43:44 +01001016 struct lbs_private *priv = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001017
Holger Schurig9012b282007-05-25 11:27:16 -04001018 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001019
1020 /* Allocate an Ethernet device and register it */
Holger Schurig69f90322007-11-23 15:43:44 +01001021 dev = alloc_etherdev(sizeof(struct lbs_private));
1022 if (!dev) {
Holger Schurig9012b282007-05-25 11:27:16 -04001023 lbs_pr_err("init ethX device failed\n");
Dan Williams954ee162007-08-20 11:43:25 -04001024 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001025 }
Dan Williams64f104e2007-08-20 11:45:16 -04001026 priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001027
Holger Schurig10078322007-11-15 18:05:47 -05001028 if (lbs_init_adapter(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001029 lbs_pr_err("failed to initialize adapter structure.\n");
1030 goto err_init_adapter;
1031 }
1032
Holger Schurig634b8f42007-05-25 13:05:16 -04001033 priv->dev = dev;
1034 priv->card = card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001035 priv->mesh_open = 0;
1036 priv->infra_open = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001037
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001038 /* Setup the OS Interface to our functions */
David Woodhouse8552855f2007-12-10 16:38:18 -05001039 dev->open = lbs_dev_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001040 dev->hard_start_xmit = lbs_hard_start_xmit;
David Woodhouse8552855f2007-12-10 16:38:18 -05001041 dev->stop = lbs_eth_stop;
Holger Schurig10078322007-11-15 18:05:47 -05001042 dev->set_mac_address = lbs_set_mac_address;
1043 dev->tx_timeout = lbs_tx_timeout;
1044 dev->get_stats = lbs_get_stats;
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001045 dev->watchdog_timeo = 5 * HZ;
Holger Schurig10078322007-11-15 18:05:47 -05001046 dev->ethtool_ops = &lbs_ethtool_ops;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001047#ifdef WIRELESS_EXT
Holger Schurig10078322007-11-15 18:05:47 -05001048 dev->wireless_handlers = (struct iw_handler_def *)&lbs_handler_def;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001049#endif
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001050 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
Holger Schurig10078322007-11-15 18:05:47 -05001051 dev->set_multicast_list = lbs_set_multicast_list;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001052
Dan Williams7732ca42007-05-25 13:13:25 -04001053 SET_NETDEV_DEV(dev, dmdev);
1054
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001055 priv->rtap_net_dev = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001056
Dan Williamsfe336152007-08-02 11:32:25 -04001057 lbs_deb_thread("Starting main thread...\n");
1058 init_waitqueue_head(&priv->waitq);
Holger Schurig10078322007-11-15 18:05:47 -05001059 priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
Dan Williamsfe336152007-08-02 11:32:25 -04001060 if (IS_ERR(priv->main_thread)) {
1061 lbs_deb_thread("Error creating main thread.\n");
David Woodhousee7deced2007-12-08 18:29:16 +00001062 goto err_init_adapter;
Dan Williamsfe336152007-08-02 11:32:25 -04001063 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064
Holger Schurig10078322007-11-15 18:05:47 -05001065 priv->work_thread = create_singlethread_workqueue("lbs_worker");
1066 INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker);
1067 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
1068 INIT_WORK(&priv->sync_channel, lbs_sync_channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001069
Dan Williams954ee162007-08-20 11:43:25 -04001070 goto done;
1071
Dan Williams954ee162007-08-20 11:43:25 -04001072err_init_adapter:
Holger Schurig10078322007-11-15 18:05:47 -05001073 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001074 free_netdev(dev);
1075 priv = NULL;
1076
1077done:
1078 lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv);
1079 return priv;
1080}
Holger Schurig10078322007-11-15 18:05:47 -05001081EXPORT_SYMBOL_GPL(lbs_add_card);
Dan Williams954ee162007-08-20 11:43:25 -04001082
1083
Holger Schurig69f90322007-11-23 15:43:44 +01001084int lbs_remove_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001085{
Dan Williams954ee162007-08-20 11:43:25 -04001086 struct net_device *dev = priv->dev;
1087 union iwreq_data wrqu;
1088
1089 lbs_deb_enter(LBS_DEB_MAIN);
1090
Holger Schurig10078322007-11-15 18:05:47 -05001091 lbs_remove_rtap(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001092
1093 dev = priv->dev;
David Woodhousee7deced2007-12-08 18:29:16 +00001094 device_remove_file(&dev->dev, &dev_attr_lbs_rtap);
Dan Williams954ee162007-08-20 11:43:25 -04001095
1096 cancel_delayed_work(&priv->scan_work);
1097 cancel_delayed_work(&priv->assoc_work);
1098 destroy_workqueue(priv->work_thread);
1099
David Woodhouseaa21c002007-12-08 20:04:36 +00001100 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
1101 priv->psmode = LBS802_11POWERMODECAM;
Holger Schurig10078322007-11-15 18:05:47 -05001102 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001103 }
1104
Dan Williams954ee162007-08-20 11:43:25 -04001105 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
1106 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1107 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
1108
1109 /* Stop the thread servicing the interrupts */
David Woodhouseaa21c002007-12-08 20:04:36 +00001110 priv->surpriseremoved = 1;
Dan Williams954ee162007-08-20 11:43:25 -04001111 kthread_stop(priv->main_thread);
1112
Holger Schurig10078322007-11-15 18:05:47 -05001113 lbs_free_adapter(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001114
1115 priv->dev = NULL;
1116 free_netdev(dev);
1117
1118 lbs_deb_leave(LBS_DEB_MAIN);
1119 return 0;
1120}
Holger Schurig10078322007-11-15 18:05:47 -05001121EXPORT_SYMBOL_GPL(lbs_remove_card);
Dan Williams954ee162007-08-20 11:43:25 -04001122
1123
Holger Schurig69f90322007-11-23 15:43:44 +01001124int lbs_start_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001125{
1126 struct net_device *dev = priv->dev;
1127 int ret = -1;
1128
1129 lbs_deb_enter(LBS_DEB_MAIN);
1130
1131 /* poke the firmware */
Holger Schurig10078322007-11-15 18:05:47 -05001132 ret = lbs_setup_firmware(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001133 if (ret)
1134 goto done;
1135
1136 /* init 802.11d */
Holger Schurig10078322007-11-15 18:05:47 -05001137 lbs_init_11d(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001138
1139 if (register_netdev(dev)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001140 lbs_pr_err("cannot register ethX device\n");
Dan Williams954ee162007-08-20 11:43:25 -04001141 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001142 }
David Woodhousee7deced2007-12-08 18:29:16 +00001143 if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
1144 lbs_pr_err("cannot register lbs_rtap attribute\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001145
Holger Schurig10078322007-11-15 18:05:47 -05001146 lbs_debugfs_init_one(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001147
Dan Williams954ee162007-08-20 11:43:25 -04001148 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001149
Dan Williams954ee162007-08-20 11:43:25 -04001150 ret = 0;
1151
Holger Schurig32a74b72007-05-25 12:04:31 -04001152done:
Dan Williams954ee162007-08-20 11:43:25 -04001153 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
Holger Schurig32a74b72007-05-25 12:04:31 -04001154 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001155}
Holger Schurig10078322007-11-15 18:05:47 -05001156EXPORT_SYMBOL_GPL(lbs_start_card);
Dan Williams954ee162007-08-20 11:43:25 -04001157
1158
Holger Schurig69f90322007-11-23 15:43:44 +01001159int lbs_stop_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001160{
1161 struct net_device *dev = priv->dev;
1162 int ret = -1;
1163 struct cmd_ctrl_node *cmdnode;
1164 unsigned long flags;
1165
1166 lbs_deb_enter(LBS_DEB_MAIN);
1167
1168 netif_stop_queue(priv->dev);
1169 netif_carrier_off(priv->dev);
1170
Holger Schurig10078322007-11-15 18:05:47 -05001171 lbs_debugfs_remove_one(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001172
1173 /* Flush pending command nodes */
David Woodhouseaa21c002007-12-08 20:04:36 +00001174 spin_lock_irqsave(&priv->driver_lock, flags);
1175 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
Dan Williams954ee162007-08-20 11:43:25 -04001176 cmdnode->cmdwaitqwoken = 1;
1177 wake_up_interruptible(&cmdnode->cmdwait_q);
1178 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001179 spin_unlock_irqrestore(&priv->driver_lock, flags);
Dan Williams954ee162007-08-20 11:43:25 -04001180
1181 unregister_netdev(dev);
1182
1183 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1184 return ret;
1185}
Holger Schurig10078322007-11-15 18:05:47 -05001186EXPORT_SYMBOL_GPL(lbs_stop_card);
Holger Schurig084708b2007-05-25 12:37:58 -04001187
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001188
Holger Schurig78523da2007-05-25 11:49:19 -04001189/**
1190 * @brief This function adds mshX interface
1191 *
Holger Schurig69f90322007-11-23 15:43:44 +01001192 * @param priv A pointer to the struct lbs_private structure
Holger Schurig78523da2007-05-25 11:49:19 -04001193 * @return 0 if successful, -X otherwise
1194 */
Holger Schurig69f90322007-11-23 15:43:44 +01001195int lbs_add_mesh(struct lbs_private *priv, struct device *dev)
Holger Schurig78523da2007-05-25 11:49:19 -04001196{
1197 struct net_device *mesh_dev = NULL;
1198 int ret = 0;
1199
1200 lbs_deb_enter(LBS_DEB_MESH);
1201
1202 /* Allocate a virtual mesh device */
1203 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
1204 lbs_deb_mesh("init mshX device failed\n");
1205 ret = -ENOMEM;
1206 goto done;
1207 }
1208 mesh_dev->priv = priv;
1209 priv->mesh_dev = mesh_dev;
1210
David Woodhouse8552855f2007-12-10 16:38:18 -05001211 mesh_dev->open = lbs_dev_open;
David Woodhouse198cefb2007-12-09 15:04:19 -05001212 mesh_dev->hard_start_xmit = lbs_hard_start_xmit;
David Woodhouse8552855f2007-12-10 16:38:18 -05001213 mesh_dev->stop = lbs_mesh_stop;
Holger Schurig10078322007-11-15 18:05:47 -05001214 mesh_dev->get_stats = lbs_get_stats;
1215 mesh_dev->set_mac_address = lbs_set_mac_address;
1216 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
Holger Schurig634b8f42007-05-25 13:05:16 -04001217 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
1218 sizeof(priv->dev->dev_addr));
Holger Schurig78523da2007-05-25 11:49:19 -04001219
Dan Williams7732ca42007-05-25 13:13:25 -04001220 SET_NETDEV_DEV(priv->mesh_dev, dev);
1221
Holger Schurig78523da2007-05-25 11:49:19 -04001222#ifdef WIRELESS_EXT
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04001223 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
Holger Schurig78523da2007-05-25 11:49:19 -04001224#endif
Holger Schurig78523da2007-05-25 11:49:19 -04001225 /* Register virtual mesh interface */
1226 ret = register_netdev(mesh_dev);
1227 if (ret) {
1228 lbs_pr_err("cannot register mshX virtual interface\n");
1229 goto err_free;
1230 }
1231
Holger Schurig10078322007-11-15 18:05:47 -05001232 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001233 if (ret)
1234 goto err_unregister;
1235
1236 /* Everything successful */
1237 ret = 0;
1238 goto done;
1239
Holger Schurig78523da2007-05-25 11:49:19 -04001240err_unregister:
1241 unregister_netdev(mesh_dev);
1242
1243err_free:
1244 free_netdev(mesh_dev);
1245
1246done:
1247 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
1248 return ret;
1249}
Holger Schurig10078322007-11-15 18:05:47 -05001250EXPORT_SYMBOL_GPL(lbs_add_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001251
Holger Schurig084708b2007-05-25 12:37:58 -04001252
Holger Schurig69f90322007-11-23 15:43:44 +01001253void lbs_remove_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001254{
1255 struct net_device *mesh_dev;
1256
Dan Williams954ee162007-08-20 11:43:25 -04001257 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig78523da2007-05-25 11:49:19 -04001258
1259 if (!priv)
1260 goto out;
1261
1262 mesh_dev = priv->mesh_dev;
1263
1264 netif_stop_queue(mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -04001265 netif_carrier_off(priv->mesh_dev);
Holger Schurig78523da2007-05-25 11:49:19 -04001266
Holger Schurig10078322007-11-15 18:05:47 -05001267 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001268 unregister_netdev(mesh_dev);
1269
1270 priv->mesh_dev = NULL ;
1271 free_netdev(mesh_dev);
1272
1273out:
Dan Williams954ee162007-08-20 11:43:25 -04001274 lbs_deb_leave(LBS_DEB_MAIN);
Holger Schurig78523da2007-05-25 11:49:19 -04001275}
Holger Schurig10078322007-11-15 18:05:47 -05001276EXPORT_SYMBOL_GPL(lbs_remove_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001277
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001278/**
1279 * @brief This function finds the CFP in
1280 * region_cfp_table based on region and band parameter.
1281 *
1282 * @param region The region code
1283 * @param band The band
1284 * @param cfp_no A pointer to CFP number
1285 * @return A pointer to CFP
1286 */
Holger Schurig10078322007-11-15 18:05:47 -05001287struct chan_freq_power *lbs_get_region_cfp_table(u8 region, u8 band, int *cfp_no)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001288{
1289 int i, end;
1290
Holger Schurig9012b282007-05-25 11:27:16 -04001291 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001292
Denis Chengff8ac602007-09-02 18:30:18 +08001293 end = ARRAY_SIZE(region_cfp_table);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001294
1295 for (i = 0; i < end ; i++) {
Holger Schurig9012b282007-05-25 11:27:16 -04001296 lbs_deb_main("region_cfp_table[i].region=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001297 region_cfp_table[i].region);
1298 if (region_cfp_table[i].region == region) {
1299 *cfp_no = region_cfp_table[i].cfp_no_BG;
Holger Schurig9012b282007-05-25 11:27:16 -04001300 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001301 return region_cfp_table[i].cfp_BG;
1302 }
1303 }
1304
Holger Schurig9012b282007-05-25 11:27:16 -04001305 lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001306 return NULL;
1307}
1308
Holger Schurig69f90322007-11-23 15:43:44 +01001309int lbs_set_regiontable(struct lbs_private *priv, u8 region, u8 band)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001310{
Holger Schurig9012b282007-05-25 11:27:16 -04001311 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001312 int i = 0;
1313
1314 struct chan_freq_power *cfp;
1315 int cfp_no;
1316
Holger Schurig9012b282007-05-25 11:27:16 -04001317 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001318
David Woodhouseaa21c002007-12-08 20:04:36 +00001319 memset(priv->region_channel, 0, sizeof(priv->region_channel));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001320
1321 {
Holger Schurig10078322007-11-15 18:05:47 -05001322 cfp = lbs_get_region_cfp_table(region, band, &cfp_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001323 if (cfp != NULL) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001324 priv->region_channel[i].nrcfp = cfp_no;
1325 priv->region_channel[i].CFP = cfp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001326 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001327 lbs_deb_main("wrong region code %#x in band B/G\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001328 region);
Holger Schurig9012b282007-05-25 11:27:16 -04001329 ret = -1;
1330 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001331 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001332 priv->region_channel[i].valid = 1;
1333 priv->region_channel[i].region = region;
1334 priv->region_channel[i].band = band;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001335 i++;
1336 }
Holger Schurig9012b282007-05-25 11:27:16 -04001337out:
1338 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1339 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001340}
1341
1342/**
1343 * @brief This function handles the interrupt. it will change PS
1344 * state if applicable. it will wake up main_thread to handle
1345 * the interrupt event as well.
1346 *
1347 * @param dev A pointer to net_device structure
1348 * @return n/a
1349 */
David Woodhouse4f679492007-12-10 14:58:37 -05001350void lbs_interrupt(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001351{
Holger Schuriged37b512007-05-25 11:52:42 -04001352 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001353
David Woodhouse4f679492007-12-10 14:58:37 -05001354 lbs_deb_thread("lbs_interrupt: intcounter=%d\n", priv->intcounter);
1355
1356 if (spin_trylock(&priv->driver_lock)) {
1357 spin_unlock(&priv->driver_lock);
1358 printk(KERN_CRIT "%s called without driver_lock held\n", __func__);
1359 WARN_ON(1);
1360 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001361
David Woodhouseaa21c002007-12-08 20:04:36 +00001362 priv->intcounter++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001363
David Woodhouse4f679492007-12-10 14:58:37 -05001364 if (priv->psstate == PS_STATE_SLEEP)
David Woodhouseaa21c002007-12-08 20:04:36 +00001365 priv->psstate = PS_STATE_AWAKE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001366
Dan Williamsfe336152007-08-02 11:32:25 -04001367 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001368
Holger Schuriged37b512007-05-25 11:52:42 -04001369 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001370}
Holger Schurig10078322007-11-15 18:05:47 -05001371EXPORT_SYMBOL_GPL(lbs_interrupt);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001372
Holger Schurig69f90322007-11-23 15:43:44 +01001373int lbs_reset_device(struct lbs_private *priv)
Dan Williamseedc2a32007-08-02 11:36:22 -04001374{
1375 int ret;
1376
1377 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001378 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RESET,
Dan Williamseedc2a32007-08-02 11:36:22 -04001379 CMD_ACT_HALT, 0, 0, NULL);
1380 msleep_interruptible(10);
1381
1382 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1383 return ret;
1384}
Holger Schurig10078322007-11-15 18:05:47 -05001385EXPORT_SYMBOL_GPL(lbs_reset_device);
Dan Williamseedc2a32007-08-02 11:36:22 -04001386
Andres Salomon4fb910f2007-11-20 17:43:45 -05001387static int __init lbs_init_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001388{
Holger Schurig9012b282007-05-25 11:27:16 -04001389 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001390 lbs_debugfs_init();
Holger Schurig084708b2007-05-25 12:37:58 -04001391 lbs_deb_leave(LBS_DEB_MAIN);
1392 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001393}
1394
Andres Salomon4fb910f2007-11-20 17:43:45 -05001395static void __exit lbs_exit_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001396{
Holger Schurig9012b282007-05-25 11:27:16 -04001397 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001398
Holger Schurig10078322007-11-15 18:05:47 -05001399 lbs_debugfs_remove();
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001400
Holger Schurig9012b282007-05-25 11:27:16 -04001401 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001402}
1403
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001404/*
1405 * rtap interface support fuctions
1406 */
1407
Holger Schurig10078322007-11-15 18:05:47 -05001408static int lbs_rtap_open(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001409{
David Woodhouse8552855f2007-12-10 16:38:18 -05001410 /* Yes, _stop_ the queue. Because we don't support injection */
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001411 netif_carrier_off(dev);
1412 netif_stop_queue(dev);
1413 return 0;
1414}
1415
Holger Schurig10078322007-11-15 18:05:47 -05001416static int lbs_rtap_stop(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001417{
1418 return 0;
1419}
1420
Holger Schurig10078322007-11-15 18:05:47 -05001421static int lbs_rtap_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001422{
1423 netif_stop_queue(dev);
David Woodhouse8552855f2007-12-10 16:38:18 -05001424 return NETDEV_TX_BUSY;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001425}
1426
Holger Schurig10078322007-11-15 18:05:47 -05001427static struct net_device_stats *lbs_rtap_get_stats(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001428{
Holger Schurig69f90322007-11-23 15:43:44 +01001429 struct lbs_private *priv = dev->priv;
David Woodhoused9268fb2007-12-09 16:22:21 -05001430 return &priv->stats;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001431}
1432
1433
Holger Schurig69f90322007-11-23 15:43:44 +01001434void lbs_remove_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001435{
1436 if (priv->rtap_net_dev == NULL)
1437 return;
1438 unregister_netdev(priv->rtap_net_dev);
David Woodhoused9268fb2007-12-09 16:22:21 -05001439 free_netdev(priv->rtap_net_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001440 priv->rtap_net_dev = NULL;
1441}
1442
Holger Schurig69f90322007-11-23 15:43:44 +01001443int lbs_add_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001444{
1445 int rc = 0;
David Woodhoused9268fb2007-12-09 16:22:21 -05001446 struct net_device *rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001447
1448 if (priv->rtap_net_dev)
1449 return -EPERM;
1450
David Woodhoused9268fb2007-12-09 16:22:21 -05001451 rtap_dev = alloc_netdev(0, "rtap%d", ether_setup);
1452 if (rtap_dev == NULL)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001453 return -ENOMEM;
1454
David Woodhouse121947c2007-12-09 19:54:11 -05001455 memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN);
David Woodhoused9268fb2007-12-09 16:22:21 -05001456 rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP;
1457 rtap_dev->open = lbs_rtap_open;
1458 rtap_dev->stop = lbs_rtap_stop;
1459 rtap_dev->get_stats = lbs_rtap_get_stats;
1460 rtap_dev->hard_start_xmit = lbs_rtap_hard_start_xmit;
1461 rtap_dev->set_multicast_list = lbs_set_multicast_list;
1462 rtap_dev->priv = priv;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001463
David Woodhoused9268fb2007-12-09 16:22:21 -05001464 rc = register_netdev(rtap_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001465 if (rc) {
David Woodhoused9268fb2007-12-09 16:22:21 -05001466 free_netdev(rtap_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001467 return rc;
1468 }
David Woodhoused9268fb2007-12-09 16:22:21 -05001469 priv->rtap_net_dev = rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001470
1471 return 0;
1472}
1473
1474
Holger Schurig10078322007-11-15 18:05:47 -05001475module_init(lbs_init_module);
1476module_exit(lbs_exit_module);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001477
Holger Schurig084708b2007-05-25 12:37:58 -04001478MODULE_DESCRIPTION("Libertas WLAN Driver Library");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001479MODULE_AUTHOR("Marvell International Ltd.");
1480MODULE_LICENSE("GPL");