blob: 9ccc9524153bf149a4945fd856f5380d77a4b923 [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"
24
Dan Williams125dcab2007-08-02 11:34:47 -040025#define DRIVER_RELEASE_VERSION "322.p1"
Dan Williams3ce40232007-05-10 23:03:07 -040026const char libertas_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
27#ifdef DEBUG
28 "-dbg"
29#endif
30 "";
31
Holger Schuriga46c6412007-05-25 11:32:07 -040032
33/* Module parameters */
34unsigned int libertas_debug = 0;
35module_param(libertas_debug, int, 0644);
Holger Schurig084708b2007-05-25 12:37:58 -040036EXPORT_SYMBOL_GPL(libertas_debug);
Holger Schuriga46c6412007-05-25 11:32:07 -040037
38
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020039#define WLAN_TX_PWR_DEFAULT 20 /*100mW */
40#define WLAN_TX_PWR_US_DEFAULT 20 /*100mW */
41#define WLAN_TX_PWR_JP_DEFAULT 16 /*50mW */
42#define WLAN_TX_PWR_FR_DEFAULT 20 /*100mW */
43#define WLAN_TX_PWR_EMEA_DEFAULT 20 /*100mW */
44
45/* Format { channel, frequency (MHz), maxtxpower } */
46/* band: 'B/G', region: USA FCC/Canada IC */
47static struct chan_freq_power channel_freq_power_US_BG[] = {
48 {1, 2412, WLAN_TX_PWR_US_DEFAULT},
49 {2, 2417, WLAN_TX_PWR_US_DEFAULT},
50 {3, 2422, WLAN_TX_PWR_US_DEFAULT},
51 {4, 2427, WLAN_TX_PWR_US_DEFAULT},
52 {5, 2432, WLAN_TX_PWR_US_DEFAULT},
53 {6, 2437, WLAN_TX_PWR_US_DEFAULT},
54 {7, 2442, WLAN_TX_PWR_US_DEFAULT},
55 {8, 2447, WLAN_TX_PWR_US_DEFAULT},
56 {9, 2452, WLAN_TX_PWR_US_DEFAULT},
57 {10, 2457, WLAN_TX_PWR_US_DEFAULT},
58 {11, 2462, WLAN_TX_PWR_US_DEFAULT}
59};
60
61/* band: 'B/G', region: Europe ETSI */
62static struct chan_freq_power channel_freq_power_EU_BG[] = {
63 {1, 2412, WLAN_TX_PWR_EMEA_DEFAULT},
64 {2, 2417, WLAN_TX_PWR_EMEA_DEFAULT},
65 {3, 2422, WLAN_TX_PWR_EMEA_DEFAULT},
66 {4, 2427, WLAN_TX_PWR_EMEA_DEFAULT},
67 {5, 2432, WLAN_TX_PWR_EMEA_DEFAULT},
68 {6, 2437, WLAN_TX_PWR_EMEA_DEFAULT},
69 {7, 2442, WLAN_TX_PWR_EMEA_DEFAULT},
70 {8, 2447, WLAN_TX_PWR_EMEA_DEFAULT},
71 {9, 2452, WLAN_TX_PWR_EMEA_DEFAULT},
72 {10, 2457, WLAN_TX_PWR_EMEA_DEFAULT},
73 {11, 2462, WLAN_TX_PWR_EMEA_DEFAULT},
74 {12, 2467, WLAN_TX_PWR_EMEA_DEFAULT},
75 {13, 2472, WLAN_TX_PWR_EMEA_DEFAULT}
76};
77
78/* band: 'B/G', region: Spain */
79static struct chan_freq_power channel_freq_power_SPN_BG[] = {
80 {10, 2457, WLAN_TX_PWR_DEFAULT},
81 {11, 2462, WLAN_TX_PWR_DEFAULT}
82};
83
84/* band: 'B/G', region: France */
85static struct chan_freq_power channel_freq_power_FR_BG[] = {
86 {10, 2457, WLAN_TX_PWR_FR_DEFAULT},
87 {11, 2462, WLAN_TX_PWR_FR_DEFAULT},
88 {12, 2467, WLAN_TX_PWR_FR_DEFAULT},
89 {13, 2472, WLAN_TX_PWR_FR_DEFAULT}
90};
91
92/* band: 'B/G', region: Japan */
93static struct chan_freq_power channel_freq_power_JPN_BG[] = {
94 {1, 2412, WLAN_TX_PWR_JP_DEFAULT},
95 {2, 2417, WLAN_TX_PWR_JP_DEFAULT},
96 {3, 2422, WLAN_TX_PWR_JP_DEFAULT},
97 {4, 2427, WLAN_TX_PWR_JP_DEFAULT},
98 {5, 2432, WLAN_TX_PWR_JP_DEFAULT},
99 {6, 2437, WLAN_TX_PWR_JP_DEFAULT},
100 {7, 2442, WLAN_TX_PWR_JP_DEFAULT},
101 {8, 2447, WLAN_TX_PWR_JP_DEFAULT},
102 {9, 2452, WLAN_TX_PWR_JP_DEFAULT},
103 {10, 2457, WLAN_TX_PWR_JP_DEFAULT},
104 {11, 2462, WLAN_TX_PWR_JP_DEFAULT},
105 {12, 2467, WLAN_TX_PWR_JP_DEFAULT},
106 {13, 2472, WLAN_TX_PWR_JP_DEFAULT},
107 {14, 2484, WLAN_TX_PWR_JP_DEFAULT}
108};
109
110/**
111 * the structure for channel, frequency and power
112 */
113struct region_cfp_table {
114 u8 region;
115 struct chan_freq_power *cfp_BG;
116 int cfp_no_BG;
117};
118
119/**
120 * the structure for the mapping between region and CFP
121 */
122static struct region_cfp_table region_cfp_table[] = {
123 {0x10, /*US FCC */
124 channel_freq_power_US_BG,
125 sizeof(channel_freq_power_US_BG) / sizeof(struct chan_freq_power),
126 }
127 ,
128 {0x20, /*CANADA IC */
129 channel_freq_power_US_BG,
130 sizeof(channel_freq_power_US_BG) / sizeof(struct chan_freq_power),
131 }
132 ,
133 {0x30, /*EU*/ channel_freq_power_EU_BG,
134 sizeof(channel_freq_power_EU_BG) / sizeof(struct chan_freq_power),
135 }
136 ,
137 {0x31, /*SPAIN*/ channel_freq_power_SPN_BG,
138 sizeof(channel_freq_power_SPN_BG) / sizeof(struct chan_freq_power),
139 }
140 ,
141 {0x32, /*FRANCE*/ channel_freq_power_FR_BG,
142 sizeof(channel_freq_power_FR_BG) / sizeof(struct chan_freq_power),
143 }
144 ,
145 {0x40, /*JAPAN*/ channel_freq_power_JPN_BG,
146 sizeof(channel_freq_power_JPN_BG) / sizeof(struct chan_freq_power),
147 }
148 ,
149/*Add new region here */
150};
151
152/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200153 * the table to keep region code
154 */
155u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
156 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
157
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158/**
Dan Williams8c512762007-08-02 11:40:45 -0400159 * 802.11b/g supported bitrates (in 500Kb/s units)
160 */
161u8 libertas_bg_rates[MAX_RATES] =
162 { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
1630x00, 0x00 };
164
165/**
166 * FW rate table. FW refers to rates by their index in this table, not by the
167 * rate value itself. Values of 0x00 are
168 * reserved positions.
169 */
170static u8 fw_data_rates[MAX_RATES] =
171 { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
172 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
173};
174
175/**
176 * @brief use index to get the data rate
177 *
178 * @param idx The index of data rate
179 * @return data rate or 0
180 */
181u32 libertas_fw_index_to_data_rate(u8 idx)
182{
183 if (idx >= sizeof(fw_data_rates))
184 idx = 0;
185 return fw_data_rates[idx];
186}
187
188/**
189 * @brief use rate to get the index
190 *
191 * @param rate data rate
192 * @return index or 0
193 */
194u8 libertas_data_rate_to_fw_index(u32 rate)
195{
196 u8 i;
197
198 if (!rate)
199 return 0;
200
201 for (i = 0; i < sizeof(fw_data_rates); i++) {
202 if (rate == fw_data_rates[i])
203 return i;
204 }
205 return 0;
206}
207
208/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200209 * Attributes exported through sysfs
210 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200211
212/**
Luis Carlos82fde742007-06-07 16:40:59 -0400213 * @brief Get function for sysfs attribute anycast_mask
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200214 */
Luis Carlos82fde742007-06-07 16:40:59 -0400215static ssize_t libertas_anycast_get(struct device * dev,
Dan Williamsb59bb612007-06-18 11:50:43 -0400216 struct device_attribute *attr, char * buf)
217{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200218 struct cmd_ds_mesh_access mesh_access;
219
220 memset(&mesh_access, 0, sizeof(mesh_access));
221 libertas_prepare_and_send_command(to_net_dev(dev)->priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400222 CMD_MESH_ACCESS,
223 CMD_ACT_MESH_GET_ANYCAST,
224 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200225
Luis Carlos82fde742007-06-07 16:40:59 -0400226 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200227}
228
229/**
Luis Carlos82fde742007-06-07 16:40:59 -0400230 * @brief Set function for sysfs attribute anycast_mask
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231 */
Luis Carlos82fde742007-06-07 16:40:59 -0400232static ssize_t libertas_anycast_set(struct device * dev,
Dan Williamsb59bb612007-06-18 11:50:43 -0400233 struct device_attribute *attr, const char * buf, size_t count)
234{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200235 struct cmd_ds_mesh_access mesh_access;
David Woodhouse981f1872007-05-25 23:36:54 -0400236 uint32_t datum;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200237
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200238 memset(&mesh_access, 0, sizeof(mesh_access));
Luis Carlos82fde742007-06-07 16:40:59 -0400239 sscanf(buf, "%x", &datum);
David Woodhouse981f1872007-05-25 23:36:54 -0400240 mesh_access.data[0] = cpu_to_le32(datum);
241
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200242 libertas_prepare_and_send_command((to_net_dev(dev))->priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400243 CMD_MESH_ACCESS,
244 CMD_ACT_MESH_SET_ANYCAST,
245 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246 return strlen(buf);
247}
248
249/**
Luis Carlos82fde742007-06-07 16:40:59 -0400250 * anycast_mask attribute to be exported per mshX interface
251 * through sysfs (/sys/class/net/mshX/anycast_mask)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200252 */
Luis Carlos82fde742007-06-07 16:40:59 -0400253static DEVICE_ATTR(anycast_mask, 0644, libertas_anycast_get, libertas_anycast_set);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200254
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400255static ssize_t libertas_autostart_enabled_get(struct device * dev,
256 struct device_attribute *attr, char * buf)
257{
258 struct cmd_ds_mesh_access mesh_access;
259
260 memset(&mesh_access, 0, sizeof(mesh_access));
261 libertas_prepare_and_send_command(to_net_dev(dev)->priv,
262 CMD_MESH_ACCESS,
263 CMD_ACT_MESH_GET_AUTOSTART_ENABLED,
264 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
265
266 return sprintf(buf, "%d\n", le32_to_cpu(mesh_access.data[0]));
267}
268
269static ssize_t libertas_autostart_enabled_set(struct device * dev,
270 struct device_attribute *attr, const char * buf, size_t count)
271{
272 struct cmd_ds_mesh_access mesh_access;
273 uint32_t datum;
274
275 memset(&mesh_access, 0, sizeof(mesh_access));
276 sscanf(buf, "%d", &datum);
277 mesh_access.data[0] = cpu_to_le32(datum);
278
279 libertas_prepare_and_send_command((to_net_dev(dev))->priv,
280 CMD_MESH_ACCESS,
281 CMD_ACT_MESH_SET_AUTOSTART_ENABLED,
282 CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access);
283 return strlen(buf);
284}
285
286static DEVICE_ATTR(autostart_enabled, 0644,
287 libertas_autostart_enabled_get, libertas_autostart_enabled_set);
288
289static struct attribute *libertas_mesh_sysfs_entries[] = {
290 &dev_attr_anycast_mask.attr,
291 &dev_attr_autostart_enabled.attr,
292 NULL,
293};
294
295static struct attribute_group libertas_mesh_attr_group = {
296 .attrs = libertas_mesh_sysfs_entries,
297};
298
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200299/**
300 * @brief Check if the device can be open and wait if necessary.
301 *
302 * @param dev A pointer to net_device structure
303 * @return 0
304 *
305 * For USB adapter, on some systems the device open handler will be
306 * called before FW ready. Use the following flag check and wait
307 * function to work around the issue.
308 *
309 */
Holger Schurig9012b282007-05-25 11:27:16 -0400310static int pre_open_check(struct net_device *dev)
311{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200312 wlan_private *priv = (wlan_private *) dev->priv;
313 wlan_adapter *adapter = priv->adapter;
314 int i = 0;
315
316 while (!adapter->fw_ready && i < 20) {
317 i++;
318 msleep_interruptible(100);
319 }
320 if (!adapter->fw_ready) {
Holger Schurig9012b282007-05-25 11:27:16 -0400321 lbs_pr_err("firmware not ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200322 return -1;
323 }
324
325 return 0;
326}
327
328/**
329 * @brief This function opens the device
330 *
331 * @param dev A pointer to net_device structure
332 * @return 0
333 */
Dan Williamse5241472007-08-02 11:39:19 -0400334static int libertas_dev_open(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200335{
336 wlan_private *priv = (wlan_private *) dev->priv;
337 wlan_adapter *adapter = priv->adapter;
338
Holger Schurig9012b282007-05-25 11:27:16 -0400339 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200340
341 priv->open = 1;
342
Dan Williams0aef64d2007-08-02 11:31:18 -0400343 if (adapter->connect_status == LIBERTAS_CONNECTED) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400344 netif_carrier_on(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400345 if (priv->mesh_dev)
346 netif_carrier_on(priv->mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400347 } else {
Holger Schurig634b8f42007-05-25 13:05:16 -0400348 netif_carrier_off(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400349 if (priv->mesh_dev)
350 netif_carrier_off(priv->mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400351 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200352
Holger Schurig9012b282007-05-25 11:27:16 -0400353 lbs_deb_leave(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354 return 0;
355}
356/**
357 * @brief This function opens the mshX interface
358 *
359 * @param dev A pointer to net_device structure
360 * @return 0
361 */
Dan Williamse5241472007-08-02 11:39:19 -0400362static int libertas_mesh_open(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200363{
364 wlan_private *priv = (wlan_private *) dev->priv ;
365
Holger Schurig78523da2007-05-25 11:49:19 -0400366 if (pre_open_check(dev) == -1)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200367 return -1;
368 priv->mesh_open = 1 ;
Javier Cardona51d84f52007-05-25 12:06:56 -0400369 netif_wake_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370 if (priv->infra_open == 0)
Dan Williamse5241472007-08-02 11:39:19 -0400371 return libertas_dev_open(priv->dev) ;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200372 return 0;
373}
374
375/**
376 * @brief This function opens the ethX interface
377 *
378 * @param dev A pointer to net_device structure
379 * @return 0
380 */
Dan Williamse5241472007-08-02 11:39:19 -0400381static int libertas_open(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200382{
383 wlan_private *priv = (wlan_private *) dev->priv ;
384
385 if(pre_open_check(dev) == -1)
386 return -1;
387 priv->infra_open = 1 ;
Holger Schurig634b8f42007-05-25 13:05:16 -0400388 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200389 if (priv->open == 0)
Dan Williamse5241472007-08-02 11:39:19 -0400390 return libertas_dev_open(priv->dev) ;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391 return 0;
392}
393
Dan Williamse5241472007-08-02 11:39:19 -0400394static int libertas_dev_close(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200395{
396 wlan_private *priv = dev->priv;
397
Holger Schurig9012b282007-05-25 11:27:16 -0400398 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200399
Holger Schurig634b8f42007-05-25 13:05:16 -0400400 netif_carrier_off(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200401 priv->open = 0;
402
Holger Schurig9012b282007-05-25 11:27:16 -0400403 lbs_deb_leave(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404 return 0;
405}
406
407/**
408 * @brief This function closes the mshX interface
409 *
410 * @param dev A pointer to net_device structure
411 * @return 0
412 */
Dan Williamse5241472007-08-02 11:39:19 -0400413static int libertas_mesh_close(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200414{
415 wlan_private *priv = (wlan_private *) (dev->priv);
416
417 priv->mesh_open = 0;
418 netif_stop_queue(priv->mesh_dev);
419 if (priv->infra_open == 0)
Dan Williamse5241472007-08-02 11:39:19 -0400420 return libertas_dev_close(dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200421 else
422 return 0;
423}
424
425/**
426 * @brief This function closes the ethX interface
427 *
428 * @param dev A pointer to net_device structure
429 * @return 0
430 */
Dan Williamse5241472007-08-02 11:39:19 -0400431static int libertas_close(struct net_device *dev)
Holger Schurig78523da2007-05-25 11:49:19 -0400432{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200433 wlan_private *priv = (wlan_private *) dev->priv;
434
Holger Schurig634b8f42007-05-25 13:05:16 -0400435 netif_stop_queue(dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200436 priv->infra_open = 0;
437 if (priv->mesh_open == 0)
Dan Williamse5241472007-08-02 11:39:19 -0400438 return libertas_dev_close(dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200439 else
440 return 0;
441}
442
443
Dan Williamse5241472007-08-02 11:39:19 -0400444static int libertas_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200445{
446 int ret = 0;
447 wlan_private *priv = dev->priv;
448
Holger Schurig9012b282007-05-25 11:27:16 -0400449 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200450
Holger Schurig634b8f42007-05-25 13:05:16 -0400451 if (priv->dnld_sent || priv->adapter->TxLockFlag) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200452 priv->stats.tx_dropped++;
453 goto done;
454 }
455
Holger Schurig634b8f42007-05-25 13:05:16 -0400456 netif_stop_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400457 if (priv->mesh_dev)
458 netif_stop_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200459
460 if (libertas_process_tx(priv, skb) == 0)
461 dev->trans_start = jiffies;
462done:
Holger Schurig9012b282007-05-25 11:27:16 -0400463 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464 return ret;
465}
466
467/**
Dan Williamse5241472007-08-02 11:39:19 -0400468 * @brief Mark mesh packets and handover them to libertas_hard_start_xmit
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200469 *
470 */
Dan Williamse5241472007-08-02 11:39:19 -0400471static int libertas_mesh_pre_start_xmit(struct sk_buff *skb,
472 struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200473{
474 wlan_private *priv = dev->priv;
Holger Schurig9012b282007-05-25 11:27:16 -0400475 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476
Holger Schurig9012b282007-05-25 11:27:16 -0400477 lbs_deb_enter(LBS_DEB_MESH);
478
479 SET_MESH_FRAME(skb);
480
Dan Williamse5241472007-08-02 11:39:19 -0400481 ret = libertas_hard_start_xmit(skb, priv->dev);
Holger Schurig9012b282007-05-25 11:27:16 -0400482 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
483 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200484}
485
486/**
Dan Williamse5241472007-08-02 11:39:19 -0400487 * @brief Mark non-mesh packets and handover them to libertas_hard_start_xmit
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200488 *
489 */
Dan Williamse5241472007-08-02 11:39:19 -0400490static int libertas_pre_start_xmit(struct sk_buff *skb, struct net_device *dev)
Holger Schurig9012b282007-05-25 11:27:16 -0400491{
492 int ret;
493
494 lbs_deb_enter(LBS_DEB_NET);
495
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200496 UNSET_MESH_FRAME(skb);
Holger Schurig9012b282007-05-25 11:27:16 -0400497
Dan Williamse5241472007-08-02 11:39:19 -0400498 ret = libertas_hard_start_xmit(skb, dev);
Holger Schurig9012b282007-05-25 11:27:16 -0400499 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
500 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200501}
502
Dan Williamse5241472007-08-02 11:39:19 -0400503static void libertas_tx_timeout(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200504{
505 wlan_private *priv = (wlan_private *) dev->priv;
506
Holger Schurig9012b282007-05-25 11:27:16 -0400507 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200508
Holger Schurig9012b282007-05-25 11:27:16 -0400509 lbs_pr_err("tx watch dog timeout\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200510
Holger Schurig634b8f42007-05-25 13:05:16 -0400511 priv->dnld_sent = DNLD_RES_RECEIVED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200512 dev->trans_start = jiffies;
513
514 if (priv->adapter->currenttxskb) {
515 if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
516 /* If we are here, we have not received feedback from
517 the previous packet. Assume TX_FAIL and move on. */
518 priv->adapter->eventcause = 0x01000000;
519 libertas_send_tx_feedback(priv);
520 } else
Dan Williamsfe336152007-08-02 11:32:25 -0400521 wake_up_interruptible(&priv->waitq);
Dan Williams0aef64d2007-08-02 11:31:18 -0400522 } else if (priv->adapter->connect_status == LIBERTAS_CONNECTED) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400523 netif_wake_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400524 if (priv->mesh_dev)
525 netif_wake_queue(priv->mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400526 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200527
Holger Schurig9012b282007-05-25 11:27:16 -0400528 lbs_deb_leave(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200529}
530
531/**
532 * @brief This function returns the network statistics
533 *
534 * @param dev A pointer to wlan_private structure
535 * @return A pointer to net_device_stats structure
536 */
Dan Williamse5241472007-08-02 11:39:19 -0400537static struct net_device_stats *libertas_get_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200538{
539 wlan_private *priv = (wlan_private *) dev->priv;
540
541 return &priv->stats;
542}
543
Dan Williamse5241472007-08-02 11:39:19 -0400544static int libertas_set_mac_address(struct net_device *dev, void *addr)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200545{
546 int ret = 0;
547 wlan_private *priv = (wlan_private *) dev->priv;
548 wlan_adapter *adapter = priv->adapter;
549 struct sockaddr *phwaddr = addr;
550
Holger Schurig9012b282007-05-25 11:27:16 -0400551 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200552
Luis Carlos Cobo Rus0a0d08a2007-05-25 23:05:27 -0400553 /* In case it was called from the mesh device */
554 dev = priv->dev ;
555
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200556 memset(adapter->current_addr, 0, ETH_ALEN);
557
558 /* dev->dev_addr is 8 bytes */
Holger Schurigece56192007-08-02 11:53:06 -0400559 lbs_deb_hex(LBS_DEB_NET, "dev->dev_addr", dev->dev_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200560
Holger Schurigece56192007-08-02 11:53:06 -0400561 lbs_deb_hex(LBS_DEB_NET, "addr", phwaddr->sa_data, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200562 memcpy(adapter->current_addr, phwaddr->sa_data, ETH_ALEN);
563
Dan Williams0aef64d2007-08-02 11:31:18 -0400564 ret = libertas_prepare_and_send_command(priv, CMD_802_11_MAC_ADDRESS,
565 CMD_ACT_SET,
566 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567
568 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400569 lbs_deb_net("set MAC address failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200570 ret = -1;
571 goto done;
572 }
573
Holger Schurigece56192007-08-02 11:53:06 -0400574 lbs_deb_hex(LBS_DEB_NET, "adapter->macaddr", adapter->current_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200575 memcpy(dev->dev_addr, adapter->current_addr, ETH_ALEN);
Holger Schurig78523da2007-05-25 11:49:19 -0400576 if (priv->mesh_dev)
577 memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200578
579done:
Holger Schurig9012b282007-05-25 11:27:16 -0400580 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200581 return ret;
582}
583
Dan Williamse5241472007-08-02 11:39:19 -0400584static int libertas_copy_multicast_address(wlan_adapter * adapter,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200585 struct net_device *dev)
586{
587 int i = 0;
588 struct dev_mc_list *mcptr = dev->mc_list;
589
590 for (i = 0; i < dev->mc_count; i++) {
591 memcpy(&adapter->multicastlist[i], mcptr->dmi_addr, ETH_ALEN);
592 mcptr = mcptr->next;
593 }
594
595 return i;
596
597}
598
Dan Williamse5241472007-08-02 11:39:19 -0400599static void libertas_set_multicast_list(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200600{
601 wlan_private *priv = dev->priv;
602 wlan_adapter *adapter = priv->adapter;
603 int oldpacketfilter;
604
Holger Schurig9012b282007-05-25 11:27:16 -0400605 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200606
607 oldpacketfilter = adapter->currentpacketfilter;
608
609 if (dev->flags & IFF_PROMISC) {
Holger Schurig9012b282007-05-25 11:27:16 -0400610 lbs_deb_net("enable promiscuous mode\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611 adapter->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400612 CMD_ACT_MAC_PROMISCUOUS_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200613 adapter->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400614 ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE |
615 CMD_ACT_MAC_MULTICAST_ENABLE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200616 } else {
617 /* Multicast */
618 adapter->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400619 ~CMD_ACT_MAC_PROMISCUOUS_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200620
621 if (dev->flags & IFF_ALLMULTI || dev->mc_count >
622 MRVDRV_MAX_MULTICAST_LIST_SIZE) {
Holger Schurig9012b282007-05-25 11:27:16 -0400623 lbs_deb_net( "enabling all multicast\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200624 adapter->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400625 CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200626 adapter->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400627 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200628 } else {
629 adapter->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400630 ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200631
632 if (!dev->mc_count) {
Holger Schurig9012b282007-05-25 11:27:16 -0400633 lbs_deb_net("no multicast addresses, "
634 "disabling multicast\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200635 adapter->currentpacketfilter &=
Dan Williams0aef64d2007-08-02 11:31:18 -0400636 ~CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200637 } else {
638 int i;
639
640 adapter->currentpacketfilter |=
Dan Williams0aef64d2007-08-02 11:31:18 -0400641 CMD_ACT_MAC_MULTICAST_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200642
643 adapter->nr_of_multicastmacaddr =
Dan Williamse5241472007-08-02 11:39:19 -0400644 libertas_copy_multicast_address(adapter, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200645
Holger Schurig9012b282007-05-25 11:27:16 -0400646 lbs_deb_net("multicast addresses: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200647 dev->mc_count);
648
649 for (i = 0; i < dev->mc_count; i++) {
Holger Schurig9012b282007-05-25 11:27:16 -0400650 lbs_deb_net("Multicast address %d:"
651 MAC_FMT "\n", i,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200652 adapter->multicastlist[i][0],
653 adapter->multicastlist[i][1],
654 adapter->multicastlist[i][2],
655 adapter->multicastlist[i][3],
656 adapter->multicastlist[i][4],
657 adapter->multicastlist[i][5]);
658 }
Holger Schurig9012b282007-05-25 11:27:16 -0400659 /* send multicast addresses to firmware */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200660 libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400661 CMD_MAC_MULTICAST_ADR,
662 CMD_ACT_SET, 0, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200663 NULL);
664 }
665 }
666 }
667
668 if (adapter->currentpacketfilter != oldpacketfilter) {
669 libertas_set_mac_packet_filter(priv);
670 }
671
Holger Schurig9012b282007-05-25 11:27:16 -0400672 lbs_deb_leave(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200673}
674
675/**
Holger Schurig9012b282007-05-25 11:27:16 -0400676 * @brief This function handles the major jobs in the WLAN driver.
677 * It handles all events generated by firmware, RX data received
678 * from firmware and TX data sent from kernel.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200679 *
680 * @param data A pointer to wlan_thread structure
681 * @return 0
682 */
Dan Williamsfe336152007-08-02 11:32:25 -0400683static int libertas_thread(void *data)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200684{
Dan Williamsfe336152007-08-02 11:32:25 -0400685 struct net_device *dev = data;
686 wlan_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200687 wlan_adapter *adapter = priv->adapter;
688 wait_queue_t wait;
689 u8 ireg = 0;
690
Holger Schurig9012b282007-05-25 11:27:16 -0400691 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200692
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200693 init_waitqueue_entry(&wait, current);
694
695 for (;;) {
Holger Schurig9012b282007-05-25 11:27:16 -0400696 lbs_deb_thread( "main-thread 111: intcounter=%d "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200697 "currenttxskb=%p dnld_sent=%d\n",
698 adapter->intcounter,
Holger Schurig634b8f42007-05-25 13:05:16 -0400699 adapter->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200700
Dan Williamsfe336152007-08-02 11:32:25 -0400701 add_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200702 set_current_state(TASK_INTERRUPTIBLE);
703 spin_lock_irq(&adapter->driver_lock);
704 if ((adapter->psstate == PS_STATE_SLEEP) ||
705 (!adapter->intcounter
Holger Schurig634b8f42007-05-25 13:05:16 -0400706 && (priv->dnld_sent || adapter->cur_cmd ||
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200707 list_empty(&adapter->cmdpendingq)))) {
Holger Schurig9012b282007-05-25 11:27:16 -0400708 lbs_deb_thread(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709 "main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
710 adapter->connect_status, adapter->intcounter,
711 adapter->psmode, adapter->psstate);
712 spin_unlock_irq(&adapter->driver_lock);
713 schedule();
714 } else
715 spin_unlock_irq(&adapter->driver_lock);
716
717
Holger Schurig9012b282007-05-25 11:27:16 -0400718 lbs_deb_thread(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200719 "main-thread 222 (waking up): intcounter=%d currenttxskb=%p "
720 "dnld_sent=%d\n", adapter->intcounter,
Holger Schurig634b8f42007-05-25 13:05:16 -0400721 adapter->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200722
723 set_current_state(TASK_RUNNING);
Dan Williamsfe336152007-08-02 11:32:25 -0400724 remove_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200725 try_to_freeze();
726
Holger Schurig9012b282007-05-25 11:27:16 -0400727 lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200728 "dnld_sent=%d\n",
729 adapter->intcounter,
Holger Schurig634b8f42007-05-25 13:05:16 -0400730 adapter->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200731
732 if (kthread_should_stop()
733 || adapter->surpriseremoved) {
Holger Schurig9012b282007-05-25 11:27:16 -0400734 lbs_deb_thread(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200735 "main-thread: break from main thread: surpriseremoved=0x%x\n",
736 adapter->surpriseremoved);
737 break;
738 }
739
740
741 spin_lock_irq(&adapter->driver_lock);
742 if (adapter->intcounter) {
743 u8 int_status;
744 adapter->intcounter = 0;
Holger Schurig208fdd22007-05-25 12:17:06 -0400745 int_status = priv->hw_get_int_status(priv, &ireg);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200746
747 if (int_status) {
Holger Schurig9012b282007-05-25 11:27:16 -0400748 lbs_deb_thread(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200749 "main-thread: reading HOST_INT_STATUS_REG failed\n");
750 spin_unlock_irq(&adapter->driver_lock);
751 continue;
752 }
753 adapter->hisregcpy |= ireg;
754 }
755
Holger Schurig9012b282007-05-25 11:27:16 -0400756 lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200757 "dnld_sent=%d\n",
758 adapter->intcounter,
Holger Schurig634b8f42007-05-25 13:05:16 -0400759 adapter->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200760
761 /* command response? */
Holger Schurigc95c7f92007-08-02 11:49:45 -0400762 if (adapter->hisregcpy & MRVDRV_CMD_UPLD_RDY) {
Holger Schurig9012b282007-05-25 11:27:16 -0400763 lbs_deb_thread("main-thread: cmd response ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200764
Holger Schurigc95c7f92007-08-02 11:49:45 -0400765 adapter->hisregcpy &= ~MRVDRV_CMD_UPLD_RDY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200766 spin_unlock_irq(&adapter->driver_lock);
767 libertas_process_rx_command(priv);
768 spin_lock_irq(&adapter->driver_lock);
769 }
770
771 /* Any Card Event */
Holger Schurigc95c7f92007-08-02 11:49:45 -0400772 if (adapter->hisregcpy & MRVDRV_CARDEVENT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400773 lbs_deb_thread("main-thread: Card Event Activity\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200774
Holger Schurigc95c7f92007-08-02 11:49:45 -0400775 adapter->hisregcpy &= ~MRVDRV_CARDEVENT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200776
Holger Schurig208fdd22007-05-25 12:17:06 -0400777 if (priv->hw_read_event_cause(priv)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200778 lbs_pr_alert(
Holger Schurig208fdd22007-05-25 12:17:06 -0400779 "main-thread: hw_read_event_cause failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200780 spin_unlock_irq(&adapter->driver_lock);
781 continue;
782 }
783 spin_unlock_irq(&adapter->driver_lock);
784 libertas_process_event(priv);
785 } else
786 spin_unlock_irq(&adapter->driver_lock);
787
788 /* Check if we need to confirm Sleep Request received previously */
789 if (adapter->psstate == PS_STATE_PRE_SLEEP) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400790 if (!priv->dnld_sent && !adapter->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200791 if (adapter->connect_status ==
Dan Williams0aef64d2007-08-02 11:31:18 -0400792 LIBERTAS_CONNECTED) {
Holger Schurig9012b282007-05-25 11:27:16 -0400793 lbs_deb_thread(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200794 "main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p "
795 "dnld_sent=%d cur_cmd=%p, confirm now\n",
796 adapter->intcounter,
797 adapter->currenttxskb,
Holger Schurig634b8f42007-05-25 13:05:16 -0400798 priv->dnld_sent,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200799 adapter->cur_cmd);
800
801 libertas_ps_confirm_sleep(priv,
802 (u16) adapter->psmode);
803 } else {
804 /* workaround for firmware sending
805 * deauth/linkloss event immediately
806 * after sleep request, remove this
807 * after firmware fixes it
808 */
809 adapter->psstate = PS_STATE_AWAKE;
810 lbs_pr_alert(
811 "main-thread: ignore PS_SleepConfirm in non-connected state\n");
812 }
813 }
814 }
815
816 /* The PS state is changed during processing of Sleep Request
817 * event above
818 */
819 if ((priv->adapter->psstate == PS_STATE_SLEEP) ||
820 (priv->adapter->psstate == PS_STATE_PRE_SLEEP))
821 continue;
822
823 /* Execute the next command */
Holger Schurig634b8f42007-05-25 13:05:16 -0400824 if (!priv->dnld_sent && !priv->adapter->cur_cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200825 libertas_execute_next_command(priv);
826
827 /* Wake-up command waiters which can't sleep in
828 * libertas_prepare_and_send_command
829 */
830 if (!adapter->nr_cmd_pending)
831 wake_up_all(&adapter->cmd_pending);
832
833 libertas_tx_runqueue(priv);
834 }
835
836 del_timer(&adapter->command_timer);
837 adapter->nr_cmd_pending = 0;
838 wake_up_all(&adapter->cmd_pending);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200839
Holger Schurig9012b282007-05-25 11:27:16 -0400840 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200841 return 0;
842}
843
844/**
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400845 * @brief This function downloads firmware image, gets
846 * HW spec from firmware and set basic parameters to
847 * firmware.
848 *
849 * @param priv A pointer to wlan_private structure
850 * @return 0 or -1
851 */
852static int wlan_setup_station_hw(wlan_private * priv)
853{
854 int ret = -1;
855 wlan_adapter *adapter = priv->adapter;
856
857 lbs_deb_enter(LBS_DEB_FW);
858
859 ret = priv->hw_prog_firmware(priv);
860
861 if (ret) {
862 lbs_deb_fw("bootloader in invalid state\n");
863 ret = -1;
864 goto done;
865 }
866
867 /*
868 * Read MAC address from HW
869 */
870 memset(adapter->current_addr, 0xff, ETH_ALEN);
871
872 ret = libertas_prepare_and_send_command(priv, CMD_GET_HW_SPEC,
873 0, CMD_OPTION_WAITFORRSP, 0, NULL);
874
875 if (ret) {
876 ret = -1;
877 goto done;
878 }
879
880 libertas_set_mac_packet_filter(priv);
881
882 /* Get the supported Data rates */
883 ret = libertas_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
884 CMD_ACT_GET_TX_RATE,
885 CMD_OPTION_WAITFORRSP, 0, NULL);
886
887 if (ret) {
888 ret = -1;
889 goto done;
890 }
891
892 ret = 0;
893done:
894 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
895 return ret;
896}
897
898static void command_timer_fn(unsigned long data);
899
900/**
901 * This function handles the timeout of command sending.
902 * It will re-send the same command again.
903 */
904static void command_timer_fn(unsigned long data)
905{
906 wlan_private *priv = (wlan_private *)data;
907 wlan_adapter *adapter = priv->adapter;
908 struct cmd_ctrl_node *ptempnode;
909 struct cmd_ds_command *cmd;
910 unsigned long flags;
911
912 ptempnode = adapter->cur_cmd;
913 if (ptempnode == NULL) {
914 lbs_deb_fw("ptempnode empty\n");
915 return;
916 }
917
918 cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr;
919 if (!cmd) {
920 lbs_deb_fw("cmd is NULL\n");
921 return;
922 }
923
924 lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command);
925
926 if (!adapter->fw_ready)
927 return;
928
929 spin_lock_irqsave(&adapter->driver_lock, flags);
930 adapter->cur_cmd = NULL;
931 spin_unlock_irqrestore(&adapter->driver_lock, flags);
932
933 lbs_deb_fw("re-sending same command because of timeout\n");
934 libertas_queue_cmd(adapter, ptempnode, 0);
935
936 wake_up_interruptible(&priv->waitq);
937
938 return;
939}
940
Holger Schurigac558ca2007-08-02 11:49:06 -0400941static void libertas_free_adapter(wlan_private * priv)
942{
943 wlan_adapter *adapter = priv->adapter;
944
945 if (!adapter) {
946 lbs_deb_fw("why double free adapter?\n");
947 return;
948 }
949
950 lbs_deb_fw("free command buffer\n");
951 libertas_free_cmd_buffer(priv);
952
953 lbs_deb_fw("free command_timer\n");
954 del_timer(&adapter->command_timer);
955
956 lbs_deb_fw("free scan results table\n");
957 kfree(adapter->networks);
958 adapter->networks = NULL;
959
960 /* Free the adapter object itself */
961 lbs_deb_fw("free adapter\n");
962 kfree(adapter);
963 priv->adapter = NULL;
964}
965
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400966static int wlan_allocate_adapter(wlan_private * priv)
967{
968 size_t bufsize;
969 wlan_adapter *adapter = priv->adapter;
970
971 /* Allocate buffer to store the BSSID list */
972 bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
973 adapter->networks = kzalloc(bufsize, GFP_KERNEL);
974 if (!adapter->networks) {
975 lbs_pr_err("Out of memory allocating beacons\n");
976 libertas_free_adapter(priv);
977 return -ENOMEM;
978 }
979
980 /* Allocate the command buffers */
981 libertas_allocate_cmd_buffer(priv);
982
983 memset(&adapter->libertas_ps_confirm_sleep, 0, sizeof(struct PS_CMD_ConfirmSleep));
984 adapter->libertas_ps_confirm_sleep.seqnum = cpu_to_le16(++adapter->seqnum);
985 adapter->libertas_ps_confirm_sleep.command =
986 cpu_to_le16(CMD_802_11_PS_MODE);
987 adapter->libertas_ps_confirm_sleep.size =
988 cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep));
989 adapter->libertas_ps_confirm_sleep.result = 0;
990 adapter->libertas_ps_confirm_sleep.action =
991 cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
992
993 return 0;
994}
995
996static void wlan_init_adapter(wlan_private * priv)
997{
998 wlan_adapter *adapter = priv->adapter;
999 int i;
1000
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001001 adapter->connect_status = LIBERTAS_DISCONNECTED;
1002 memset(adapter->current_addr, 0xff, ETH_ALEN);
1003
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001004 /* 802.11 specific */
1005 adapter->secinfo.wep_enabled = 0;
1006 for (i = 0; i < sizeof(adapter->wep_keys) / sizeof(adapter->wep_keys[0]);
1007 i++)
1008 memset(&adapter->wep_keys[i], 0, sizeof(struct enc_key));
1009 adapter->wep_tx_keyidx = 0;
1010 adapter->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1011 adapter->mode = IW_MODE_INFRA;
1012
1013 adapter->pending_assoc_req = NULL;
1014 adapter->in_progress_assoc_req = NULL;
1015
1016 /* Initialize scan result lists */
1017 INIT_LIST_HEAD(&adapter->network_free_list);
1018 INIT_LIST_HEAD(&adapter->network_list);
1019 for (i = 0; i < MAX_NETWORK_COUNT; i++) {
1020 list_add_tail(&adapter->networks[i].list,
1021 &adapter->network_free_list);
1022 }
1023
1024 mutex_init(&adapter->lock);
1025
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001026 memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams));
1027 adapter->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL;
1028
1029 /* PnP and power profile */
1030 adapter->surpriseremoved = 0;
1031
1032 adapter->currentpacketfilter =
1033 CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
1034
1035 adapter->radioon = RADIO_ON;
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001036
1037 adapter->auto_rate = 1;
1038 adapter->cur_rate = 0;
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001039
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001040 // set default capabilities
1041 adapter->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
1042
1043 adapter->psmode = WLAN802_11POWERMODECAM;
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001044
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001045 adapter->psstate = PS_STATE_FULL_POWER;
1046 adapter->needtowakeup = 0;
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001047
1048 adapter->intcounter = 0;
1049
1050 adapter->currenttxskb = NULL;
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001051
1052 memset(&adapter->tx_queue_ps, 0, NR_TX_QUEUE*sizeof(struct sk_buff*));
1053 adapter->tx_queue_idx = 0;
1054 spin_lock_init(&adapter->txqueue_lock);
1055
1056 return;
1057}
1058
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001059static int libertas_init_fw(wlan_private * priv)
1060{
1061 int ret = -1;
1062 wlan_adapter *adapter = priv->adapter;
1063
1064 lbs_deb_enter(LBS_DEB_FW);
1065
1066 /* Allocate adapter structure */
1067 if ((ret = wlan_allocate_adapter(priv)) != 0)
1068 goto done;
1069
1070 /* init adapter structure */
1071 wlan_init_adapter(priv);
1072
1073 /* init timer etc. */
1074 setup_timer(&adapter->command_timer, command_timer_fn,
1075 (unsigned long)priv);
1076
1077 /* download fimrware etc. */
1078 if ((ret = wlan_setup_station_hw(priv)) != 0) {
1079 del_timer_sync(&adapter->command_timer);
1080 goto done;
1081 }
1082
1083 /* init 802.11d */
1084 libertas_init_11d(priv);
1085
1086 ret = 0;
1087done:
1088 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
1089 return ret;
1090}
1091
1092/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001093 * @brief This function adds the card. it will probe the
1094 * card, allocate the wlan_priv and initialize the device.
1095 *
1096 * @param card A pointer to card
1097 * @return A pointer to wlan_private structure
1098 */
Dan Williams7732ca42007-05-25 13:13:25 -04001099wlan_private *libertas_add_card(void *card, struct device *dmdev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001100{
1101 struct net_device *dev = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001102 wlan_private *priv = NULL;
1103
Holger Schurig9012b282007-05-25 11:27:16 -04001104 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001105
1106 /* Allocate an Ethernet device and register it */
1107 if (!(dev = alloc_etherdev(sizeof(wlan_private)))) {
Holger Schurig9012b282007-05-25 11:27:16 -04001108 lbs_pr_err("init ethX device failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001109 return NULL;
1110 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001111 priv = dev->priv;
1112
1113 /* allocate buffer for wlan_adapter */
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001114 if (!(priv->adapter = kzalloc(sizeof(wlan_adapter), GFP_KERNEL))) {
Holger Schurig9012b282007-05-25 11:27:16 -04001115 lbs_pr_err("allocate buffer for wlan_adapter failed\n");
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001116 goto err_kzalloc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001117 }
1118
Holger Schurig634b8f42007-05-25 13:05:16 -04001119 priv->dev = dev;
1120 priv->card = card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001121 priv->mesh_open = 0;
1122 priv->infra_open = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001123
1124 SET_MODULE_OWNER(dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001125
1126 /* Setup the OS Interface to our functions */
Dan Williamse5241472007-08-02 11:39:19 -04001127 dev->open = libertas_open;
1128 dev->hard_start_xmit = libertas_pre_start_xmit;
1129 dev->stop = libertas_close;
1130 dev->set_mac_address = libertas_set_mac_address;
1131 dev->tx_timeout = libertas_tx_timeout;
1132 dev->get_stats = libertas_get_stats;
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001133 dev->watchdog_timeo = 5 * HZ;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001134 dev->ethtool_ops = &libertas_ethtool_ops;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001135#ifdef WIRELESS_EXT
1136 dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001137#endif
1138#define NETIF_F_DYNALLOC 16
1139 dev->features |= NETIF_F_DYNALLOC;
1140 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
Dan Williamse5241472007-08-02 11:39:19 -04001141 dev->set_multicast_list = libertas_set_multicast_list;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001142
Dan Williams7732ca42007-05-25 13:13:25 -04001143 SET_NETDEV_DEV(dev, dmdev);
1144
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001145 INIT_LIST_HEAD(&priv->adapter->cmdfreeq);
1146 INIT_LIST_HEAD(&priv->adapter->cmdpendingq);
1147
1148 spin_lock_init(&priv->adapter->driver_lock);
1149 init_waitqueue_head(&priv->adapter->cmd_pending);
1150 priv->adapter->nr_cmd_pending = 0;
Holger Schurig32a74b72007-05-25 12:04:31 -04001151 goto done;
1152
1153err_kzalloc:
1154 free_netdev(dev);
Marcelo Tosatti6a812152007-05-25 12:09:13 -04001155 priv = NULL;
Holger Schurig32a74b72007-05-25 12:04:31 -04001156done:
1157 lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv);
1158 return priv;
1159}
Holger Schurig084708b2007-05-25 12:37:58 -04001160EXPORT_SYMBOL_GPL(libertas_add_card);
Holger Schurig32a74b72007-05-25 12:04:31 -04001161
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001162int libertas_activate_card(wlan_private *priv)
Holger Schurig32a74b72007-05-25 12:04:31 -04001163{
Holger Schurig634b8f42007-05-25 13:05:16 -04001164 struct net_device *dev = priv->dev;
Holger Schurig32a74b72007-05-25 12:04:31 -04001165 int ret = -1;
1166
1167 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001168
Dan Williamsfe336152007-08-02 11:32:25 -04001169 lbs_deb_thread("Starting main thread...\n");
1170 init_waitqueue_head(&priv->waitq);
1171 priv->main_thread = kthread_run(libertas_thread, dev, "libertas_main");
1172 if (IS_ERR(priv->main_thread)) {
1173 lbs_deb_thread("Error creating main thread.\n");
1174 goto done;
1175 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001176
1177 priv->assoc_thread =
1178 create_singlethread_workqueue("libertas_assoc");
Holger Schurigeb3ce632007-05-24 23:41:15 -04001179 INIT_DELAYED_WORK(&priv->assoc_work, libertas_association_worker);
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -04001180 INIT_WORK(&priv->sync_channel, libertas_sync_channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001181
1182 /*
1183 * Register the device. Fillup the private data structure with
1184 * relevant information from the card and request for the required
1185 * IRQ.
1186 */
Holger Schurig208fdd22007-05-25 12:17:06 -04001187 if (priv->hw_register_dev(priv) < 0) {
Holger Schurig9012b282007-05-25 11:27:16 -04001188 lbs_pr_err("failed to register WLAN device\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001189 goto err_registerdev;
1190 }
1191
1192 /* init FW and HW */
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001193 if (libertas_init_fw(priv)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001194 lbs_pr_err("firmware init failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001195 goto err_registerdev;
1196 }
1197
1198 if (register_netdev(dev)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001199 lbs_pr_err("cannot register ethX device\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001200 goto err_init_fw;
1201 }
1202
Holger Schurig9012b282007-05-25 11:27:16 -04001203 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001204
1205 libertas_debugfs_init_one(priv, dev);
1206
Holger Schurig32a74b72007-05-25 12:04:31 -04001207 ret = 0;
1208 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001209
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001210err_init_fw:
Holger Schurig208fdd22007-05-25 12:17:06 -04001211 priv->hw_unregister_dev(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001212err_registerdev:
1213 destroy_workqueue(priv->assoc_thread);
1214 /* Stop the thread servicing the interrupts */
Dan Williamsfe336152007-08-02 11:32:25 -04001215 wake_up_interruptible(&priv->waitq);
1216 kthread_stop(priv->main_thread);
Holger Schurig32a74b72007-05-25 12:04:31 -04001217done:
1218 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
1219 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001220}
Holger Schurig084708b2007-05-25 12:37:58 -04001221EXPORT_SYMBOL_GPL(libertas_activate_card);
1222
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001223
Holger Schurig78523da2007-05-25 11:49:19 -04001224/**
1225 * @brief This function adds mshX interface
1226 *
1227 * @param priv A pointer to the wlan_private structure
1228 * @return 0 if successful, -X otherwise
1229 */
Dan Williams7732ca42007-05-25 13:13:25 -04001230int libertas_add_mesh(wlan_private *priv, struct device *dev)
Holger Schurig78523da2007-05-25 11:49:19 -04001231{
1232 struct net_device *mesh_dev = NULL;
1233 int ret = 0;
1234
1235 lbs_deb_enter(LBS_DEB_MESH);
1236
1237 /* Allocate a virtual mesh device */
1238 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
1239 lbs_deb_mesh("init mshX device failed\n");
1240 ret = -ENOMEM;
1241 goto done;
1242 }
1243 mesh_dev->priv = priv;
1244 priv->mesh_dev = mesh_dev;
1245
1246 SET_MODULE_OWNER(mesh_dev);
1247
Dan Williamse5241472007-08-02 11:39:19 -04001248 mesh_dev->open = libertas_mesh_open;
1249 mesh_dev->hard_start_xmit = libertas_mesh_pre_start_xmit;
1250 mesh_dev->stop = libertas_mesh_close;
1251 mesh_dev->get_stats = libertas_get_stats;
1252 mesh_dev->set_mac_address = libertas_set_mac_address;
Holger Schurig78523da2007-05-25 11:49:19 -04001253 mesh_dev->ethtool_ops = &libertas_ethtool_ops;
Holger Schurig634b8f42007-05-25 13:05:16 -04001254 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
1255 sizeof(priv->dev->dev_addr));
Holger Schurig78523da2007-05-25 11:49:19 -04001256
Dan Williams7732ca42007-05-25 13:13:25 -04001257 SET_NETDEV_DEV(priv->mesh_dev, dev);
1258
Holger Schurig78523da2007-05-25 11:49:19 -04001259#ifdef WIRELESS_EXT
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04001260 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
Holger Schurig78523da2007-05-25 11:49:19 -04001261#endif
1262#define NETIF_F_DYNALLOC 16
1263
1264 /* Register virtual mesh interface */
1265 ret = register_netdev(mesh_dev);
1266 if (ret) {
1267 lbs_pr_err("cannot register mshX virtual interface\n");
1268 goto err_free;
1269 }
1270
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -04001271 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &libertas_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001272 if (ret)
1273 goto err_unregister;
1274
1275 /* Everything successful */
1276 ret = 0;
1277 goto done;
1278
Holger Schurig78523da2007-05-25 11:49:19 -04001279err_unregister:
1280 unregister_netdev(mesh_dev);
1281
1282err_free:
1283 free_netdev(mesh_dev);
1284
1285done:
1286 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
1287 return ret;
1288}
Holger Schurig084708b2007-05-25 12:37:58 -04001289EXPORT_SYMBOL_GPL(libertas_add_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001290
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001291static void wake_pending_cmdnodes(wlan_private *priv)
1292{
1293 struct cmd_ctrl_node *cmdnode;
1294 unsigned long flags;
1295
Holger Schurig8ff12da2007-08-02 11:54:31 -04001296 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurig9012b282007-05-25 11:27:16 -04001297
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001298 spin_lock_irqsave(&priv->adapter->driver_lock, flags);
1299 list_for_each_entry(cmdnode, &priv->adapter->cmdpendingq, list) {
1300 cmdnode->cmdwaitqwoken = 1;
1301 wake_up_interruptible(&cmdnode->cmdwait_q);
1302 }
1303 spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
1304}
1305
1306
Holger Schurig084708b2007-05-25 12:37:58 -04001307int libertas_remove_card(wlan_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001308{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001309 wlan_adapter *adapter;
1310 struct net_device *dev;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001311 union iwreq_data wrqu;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001312
Holger Schurig9012b282007-05-25 11:27:16 -04001313 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001314
Holger Schurig9012b282007-05-25 11:27:16 -04001315 if (!priv)
1316 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001317
1318 adapter = priv->adapter;
1319
Holger Schurig9012b282007-05-25 11:27:16 -04001320 if (!adapter)
1321 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001322
Holger Schurig634b8f42007-05-25 13:05:16 -04001323 dev = priv->dev;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001324
Holger Schurig634b8f42007-05-25 13:05:16 -04001325 netif_stop_queue(priv->dev);
1326 netif_carrier_off(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001327
1328 wake_pending_cmdnodes(priv);
1329
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001330 unregister_netdev(dev);
1331
1332 cancel_delayed_work(&priv->assoc_work);
1333 destroy_workqueue(priv->assoc_thread);
1334
Dan Williams0aef64d2007-08-02 11:31:18 -04001335 if (adapter->psmode == WLAN802_11POWERMODEMAX_PSP) {
1336 adapter->psmode = WLAN802_11POWERMODECAM;
1337 libertas_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001338 }
1339
1340 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
1341 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -04001342 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001343
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001344 adapter->surpriseremoved = 1;
1345
1346 /* Stop the thread servicing the interrupts */
Dan Williamsfe336152007-08-02 11:32:25 -04001347 kthread_stop(priv->main_thread);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001348
1349 libertas_debugfs_remove_one(priv);
1350
Holger Schurig9012b282007-05-25 11:27:16 -04001351 lbs_deb_net("free adapter\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001352 libertas_free_adapter(priv);
1353
Holger Schurig9012b282007-05-25 11:27:16 -04001354 lbs_deb_net("unregister finish\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001355
Holger Schurig634b8f42007-05-25 13:05:16 -04001356 priv->dev = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001357 free_netdev(dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001358
Holger Schurig9012b282007-05-25 11:27:16 -04001359out:
1360 lbs_deb_leave(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001361 return 0;
1362}
Holger Schurig084708b2007-05-25 12:37:58 -04001363EXPORT_SYMBOL_GPL(libertas_remove_card);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001364
Holger Schurig084708b2007-05-25 12:37:58 -04001365
1366void libertas_remove_mesh(wlan_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001367{
1368 struct net_device *mesh_dev;
1369
1370 lbs_deb_enter(LBS_DEB_NET);
1371
1372 if (!priv)
1373 goto out;
1374
1375 mesh_dev = priv->mesh_dev;
1376
1377 netif_stop_queue(mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -04001378 netif_carrier_off(priv->mesh_dev);
Holger Schurig78523da2007-05-25 11:49:19 -04001379
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -04001380 sysfs_remove_group(&(mesh_dev->dev.kobj), &libertas_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001381 unregister_netdev(mesh_dev);
1382
1383 priv->mesh_dev = NULL ;
1384 free_netdev(mesh_dev);
1385
1386out:
1387 lbs_deb_leave(LBS_DEB_NET);
1388}
Holger Schurig084708b2007-05-25 12:37:58 -04001389EXPORT_SYMBOL_GPL(libertas_remove_mesh);
Holger Schurig78523da2007-05-25 11:49:19 -04001390
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001391/**
1392 * @brief This function finds the CFP in
1393 * region_cfp_table based on region and band parameter.
1394 *
1395 * @param region The region code
1396 * @param band The band
1397 * @param cfp_no A pointer to CFP number
1398 * @return A pointer to CFP
1399 */
1400struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band, int *cfp_no)
1401{
1402 int i, end;
1403
Holger Schurig9012b282007-05-25 11:27:16 -04001404 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001405
1406 end = sizeof(region_cfp_table)/sizeof(struct region_cfp_table);
1407
1408 for (i = 0; i < end ; i++) {
Holger Schurig9012b282007-05-25 11:27:16 -04001409 lbs_deb_main("region_cfp_table[i].region=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001410 region_cfp_table[i].region);
1411 if (region_cfp_table[i].region == region) {
1412 *cfp_no = region_cfp_table[i].cfp_no_BG;
Holger Schurig9012b282007-05-25 11:27:16 -04001413 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001414 return region_cfp_table[i].cfp_BG;
1415 }
1416 }
1417
Holger Schurig9012b282007-05-25 11:27:16 -04001418 lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001419 return NULL;
1420}
1421
1422int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band)
1423{
1424 wlan_adapter *adapter = priv->adapter;
Holger Schurig9012b282007-05-25 11:27:16 -04001425 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001426 int i = 0;
1427
1428 struct chan_freq_power *cfp;
1429 int cfp_no;
1430
Holger Schurig9012b282007-05-25 11:27:16 -04001431 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001432
1433 memset(adapter->region_channel, 0, sizeof(adapter->region_channel));
1434
1435 {
1436 cfp = libertas_get_region_cfp_table(region, band, &cfp_no);
1437 if (cfp != NULL) {
1438 adapter->region_channel[i].nrcfp = cfp_no;
1439 adapter->region_channel[i].CFP = cfp;
1440 } else {
Holger Schurig9012b282007-05-25 11:27:16 -04001441 lbs_deb_main("wrong region code %#x in band B/G\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001442 region);
Holger Schurig9012b282007-05-25 11:27:16 -04001443 ret = -1;
1444 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001445 }
1446 adapter->region_channel[i].valid = 1;
1447 adapter->region_channel[i].region = region;
1448 adapter->region_channel[i].band = band;
1449 i++;
1450 }
Holger Schurig9012b282007-05-25 11:27:16 -04001451out:
1452 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1453 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001454}
1455
1456/**
1457 * @brief This function handles the interrupt. it will change PS
1458 * state if applicable. it will wake up main_thread to handle
1459 * the interrupt event as well.
1460 *
1461 * @param dev A pointer to net_device structure
1462 * @return n/a
1463 */
1464void libertas_interrupt(struct net_device *dev)
1465{
1466 wlan_private *priv = dev->priv;
1467
Holger Schuriged37b512007-05-25 11:52:42 -04001468 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001469
Holger Schuriged37b512007-05-25 11:52:42 -04001470 lbs_deb_thread("libertas_interrupt: intcounter=%d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001471 priv->adapter->intcounter);
1472
1473 priv->adapter->intcounter++;
1474
1475 if (priv->adapter->psstate == PS_STATE_SLEEP) {
1476 priv->adapter->psstate = PS_STATE_AWAKE;
1477 netif_wake_queue(dev);
Holger Schurig3cf84092007-08-02 11:50:12 -04001478 if (priv->mesh_dev)
1479 netif_wake_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001480 }
1481
Dan Williamsfe336152007-08-02 11:32:25 -04001482 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001483
Holger Schuriged37b512007-05-25 11:52:42 -04001484 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001485}
Holger Schurig084708b2007-05-25 12:37:58 -04001486EXPORT_SYMBOL_GPL(libertas_interrupt);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001487
Dan Williamseedc2a32007-08-02 11:36:22 -04001488int libertas_reset_device(wlan_private *priv)
1489{
1490 int ret;
1491
1492 lbs_deb_enter(LBS_DEB_MAIN);
1493 ret = libertas_prepare_and_send_command(priv, CMD_802_11_RESET,
1494 CMD_ACT_HALT, 0, 0, NULL);
1495 msleep_interruptible(10);
1496
1497 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1498 return ret;
1499}
1500EXPORT_SYMBOL_GPL(libertas_reset_device);
1501
Holger Schurig084708b2007-05-25 12:37:58 -04001502static int libertas_init_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001503{
Holger Schurig9012b282007-05-25 11:27:16 -04001504 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001505 libertas_debugfs_init();
Holger Schurig084708b2007-05-25 12:37:58 -04001506 lbs_deb_leave(LBS_DEB_MAIN);
1507 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001508}
1509
Holger Schurig084708b2007-05-25 12:37:58 -04001510static void libertas_exit_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001511{
Holger Schurig9012b282007-05-25 11:27:16 -04001512 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001513
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001514 libertas_debugfs_remove();
1515
Holger Schurig9012b282007-05-25 11:27:16 -04001516 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001517}
1518
Holger Schurig084708b2007-05-25 12:37:58 -04001519module_init(libertas_init_module);
1520module_exit(libertas_exit_module);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001521
Holger Schurig084708b2007-05-25 12:37:58 -04001522MODULE_DESCRIPTION("Libertas WLAN Driver Library");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001523MODULE_AUTHOR("Marvell International Ltd.");
1524MODULE_LICENSE("GPL");