blob: eb61f6955e9ed5c708514a0fab3db26bb6e34252 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains the major functions in WLAN
3 * driver. It includes init, exit, open, close and main
4 * thread etc..
5 */
6
Holger Schuriga46c6412007-05-25 11:32:07 -04007#include <linux/moduleparam.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02008#include <linux/delay.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02009#include <linux/etherdevice.h>
10#include <linux/netdevice.h>
11#include <linux/if_arp.h>
Dan Williamsfe336152007-08-02 11:32:25 -040012#include <linux/kthread.h>
Holger Schurig7919b892008-04-01 14:50:43 +020013#include <linux/kfifo.h>
David Woodhouse75bf45a2008-05-20 13:32:45 +010014#include <linux/stddef.h>
Johannes Berg2c7060022008-10-30 22:09:54 +010015#include <linux/ieee80211.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020016#include <net/iw_handler.h>
Holger Schurigff9fc792009-10-06 16:31:54 +020017#include <net/cfg80211.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020018
19#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020#include "decl.h"
21#include "dev.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020022#include "wext.h"
Holger Schurigff9fc792009-10-06 16:31:54 +020023#include "cfg.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020024#include "debugfs.h"
Holger Schurig245bf202008-04-02 16:27:42 +020025#include "scan.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020026#include "assoc.h"
Dan Williams6e66f032007-12-11 12:42:16 -050027#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020028
Dan Williams7856a542007-08-03 09:43:03 -040029#define DRIVER_RELEASE_VERSION "323.p0"
Holger Schurig10078322007-11-15 18:05:47 -050030const char lbs_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
Dan Williams3ce40232007-05-10 23:03:07 -040031#ifdef DEBUG
32 "-dbg"
33#endif
34 "";
35
Holger Schuriga46c6412007-05-25 11:32:07 -040036
37/* Module parameters */
Holger Schurig10078322007-11-15 18:05:47 -050038unsigned int lbs_debug;
39EXPORT_SYMBOL_GPL(lbs_debug);
40module_param_named(libertas_debug, lbs_debug, int, 0644);
Holger Schuriga46c6412007-05-25 11:32:07 -040041
42
Holger Schurigf539f2e2008-03-26 13:22:11 +010043/* This global structure is used to send the confirm_sleep command as
44 * fast as possible down to the firmware. */
45struct cmd_confirm_sleep confirm_sleep;
46
47
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020048/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020049 * the table to keep region code
50 */
Holger Schurig10078322007-11-15 18:05:47 -050051u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020052 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
53
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020054/**
Dan Williams8c512762007-08-02 11:40:45 -040055 * FW rate table. FW refers to rates by their index in this table, not by the
56 * rate value itself. Values of 0x00 are
57 * reserved positions.
58 */
59static u8 fw_data_rates[MAX_RATES] =
60 { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
61 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
62};
63
64/**
65 * @brief use index to get the data rate
66 *
67 * @param idx The index of data rate
68 * @return data rate or 0
69 */
Holger Schurig10078322007-11-15 18:05:47 -050070u32 lbs_fw_index_to_data_rate(u8 idx)
Dan Williams8c512762007-08-02 11:40:45 -040071{
72 if (idx >= sizeof(fw_data_rates))
73 idx = 0;
74 return fw_data_rates[idx];
75}
76
77/**
78 * @brief use rate to get the index
79 *
80 * @param rate data rate
81 * @return index or 0
82 */
Holger Schurig10078322007-11-15 18:05:47 -050083u8 lbs_data_rate_to_fw_index(u32 rate)
Dan Williams8c512762007-08-02 11:40:45 -040084{
85 u8 i;
86
87 if (!rate)
88 return 0;
89
90 for (i = 0; i < sizeof(fw_data_rates); i++) {
91 if (rate == fw_data_rates[i])
92 return i;
93 }
94 return 0;
95}
96
97/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020098 * Attributes exported through sysfs
99 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200100
101/**
Luis Carlos82fde742007-06-07 16:40:59 -0400102 * @brief Get function for sysfs attribute anycast_mask
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200103 */
Holger Schurig10078322007-11-15 18:05:47 -0500104static ssize_t lbs_anycast_get(struct device *dev,
Dan Williamsb59bb612007-06-18 11:50:43 -0400105 struct device_attribute *attr, char * buf)
106{
Kiran Divekarab65f642009-02-19 19:32:39 -0500107 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200108 struct cmd_ds_mesh_access mesh_access;
David Woodhouse301eacb2007-12-11 15:23:59 -0500109 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200110
111 memset(&mesh_access, 0, sizeof(mesh_access));
David Woodhouse301eacb2007-12-11 15:23:59 -0500112
113 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
114 if (ret)
115 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200116
Luis Carlos82fde742007-06-07 16:40:59 -0400117 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200118}
119
120/**
Luis Carlos82fde742007-06-07 16:40:59 -0400121 * @brief Set function for sysfs attribute anycast_mask
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122 */
Holger Schurig10078322007-11-15 18:05:47 -0500123static ssize_t lbs_anycast_set(struct device *dev,
Dan Williamsb59bb612007-06-18 11:50:43 -0400124 struct device_attribute *attr, const char * buf, size_t count)
125{
Kiran Divekarab65f642009-02-19 19:32:39 -0500126 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127 struct cmd_ds_mesh_access mesh_access;
David Woodhouse981f1872007-05-25 23:36:54 -0400128 uint32_t datum;
David Woodhouse301eacb2007-12-11 15:23:59 -0500129 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200130
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200131 memset(&mesh_access, 0, sizeof(mesh_access));
Luis Carlos82fde742007-06-07 16:40:59 -0400132 sscanf(buf, "%x", &datum);
David Woodhouse981f1872007-05-25 23:36:54 -0400133 mesh_access.data[0] = cpu_to_le32(datum);
134
David Woodhouse301eacb2007-12-11 15:23:59 -0500135 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
136 if (ret)
137 return ret;
138
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200139 return strlen(buf);
140}
141
Anna Neal6fb53252008-12-09 13:23:45 -0800142/**
143 * @brief Get function for sysfs attribute prb_rsp_limit
144 */
145static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
146 struct device_attribute *attr, char *buf)
147{
Kiran Divekarab65f642009-02-19 19:32:39 -0500148 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Anna Neal6fb53252008-12-09 13:23:45 -0800149 struct cmd_ds_mesh_access mesh_access;
150 int ret;
151 u32 retry_limit;
152
153 memset(&mesh_access, 0, sizeof(mesh_access));
154 mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET);
155
156 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
157 &mesh_access);
158 if (ret)
159 return ret;
160
161 retry_limit = le32_to_cpu(mesh_access.data[1]);
162 return snprintf(buf, 10, "%d\n", retry_limit);
163}
164
165/**
166 * @brief Set function for sysfs attribute prb_rsp_limit
167 */
168static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
169 struct device_attribute *attr, const char *buf, size_t count)
170{
Kiran Divekarab65f642009-02-19 19:32:39 -0500171 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Anna Neal6fb53252008-12-09 13:23:45 -0800172 struct cmd_ds_mesh_access mesh_access;
173 int ret;
174 unsigned long retry_limit;
175
176 memset(&mesh_access, 0, sizeof(mesh_access));
177 mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);
178
179 if (!strict_strtoul(buf, 10, &retry_limit))
180 return -ENOTSUPP;
181 if (retry_limit > 15)
182 return -ENOTSUPP;
183
184 mesh_access.data[1] = cpu_to_le32(retry_limit);
185
186 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
187 &mesh_access);
188 if (ret)
189 return ret;
190
191 return strlen(buf);
192}
193
David Woodhouse2fd6cfe2007-12-11 17:44:10 -0500194static int lbs_add_rtap(struct lbs_private *priv);
195static void lbs_remove_rtap(struct lbs_private *priv);
David Woodhouse23a397a2007-12-11 18:56:42 -0500196static int lbs_add_mesh(struct lbs_private *priv);
197static void lbs_remove_mesh(struct lbs_private *priv);
David Woodhouse7e226272007-12-14 22:53:41 -0500198
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400199
200/**
201 * Get function for sysfs attribute rtap
202 */
Holger Schurig10078322007-11-15 18:05:47 -0500203static ssize_t lbs_rtap_get(struct device *dev,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400204 struct device_attribute *attr, char * buf)
205{
Kiran Divekarab65f642009-02-19 19:32:39 -0500206 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
David Woodhouseaa21c002007-12-08 20:04:36 +0000207 return snprintf(buf, 5, "0x%X\n", priv->monitormode);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400208}
209
210/**
211 * Set function for sysfs attribute rtap
212 */
Holger Schurig10078322007-11-15 18:05:47 -0500213static ssize_t lbs_rtap_set(struct device *dev,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400214 struct device_attribute *attr, const char * buf, size_t count)
215{
216 int monitor_mode;
Kiran Divekarab65f642009-02-19 19:32:39 -0500217 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400218
219 sscanf(buf, "%x", &monitor_mode);
Holger Schurigc2b310a2008-03-26 09:57:14 +0100220 if (monitor_mode) {
221 if (priv->monitormode == monitor_mode)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400222 return strlen(buf);
Holger Schurigc2b310a2008-03-26 09:57:14 +0100223 if (!priv->monitormode) {
David Woodhouse8552855f2007-12-10 16:38:18 -0500224 if (priv->infra_open || priv->mesh_open)
225 return -EBUSY;
David Woodhouseaa21c002007-12-08 20:04:36 +0000226 if (priv->mode == IW_MODE_INFRA)
Dan Williams191bb402008-08-21 17:46:18 -0400227 lbs_cmd_80211_deauthenticate(priv,
228 priv->curbssparams.bssid,
229 WLAN_REASON_DEAUTH_LEAVING);
David Woodhouseaa21c002007-12-08 20:04:36 +0000230 else if (priv->mode == IW_MODE_ADHOC)
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400231 lbs_adhoc_stop(priv);
Holger Schurig10078322007-11-15 18:05:47 -0500232 lbs_add_rtap(priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400233 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000234 priv->monitormode = monitor_mode;
Dan Williams3b72b012008-07-29 13:50:39 -0400235 } else {
Holger Schurigc2b310a2008-03-26 09:57:14 +0100236 if (!priv->monitormode)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400237 return strlen(buf);
Holger Schurigc2b310a2008-03-26 09:57:14 +0100238 priv->monitormode = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500239 lbs_remove_rtap(priv);
David Woodhousef86a93e2007-12-08 19:46:19 +0000240
David Woodhouseaa21c002007-12-08 20:04:36 +0000241 if (priv->currenttxskb) {
242 dev_kfree_skb_any(priv->currenttxskb);
243 priv->currenttxskb = NULL;
David Woodhousef86a93e2007-12-08 19:46:19 +0000244 }
245
246 /* Wake queues, command thread, etc. */
247 lbs_host_to_card_done(priv);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400248 }
249
Holger Schurig10078322007-11-15 18:05:47 -0500250 lbs_prepare_and_send_command(priv,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400251 CMD_802_11_MONITOR_MODE, CMD_ACT_SET,
David Woodhouseaa21c002007-12-08 20:04:36 +0000252 CMD_OPTION_WAITFORRSP, 0, &priv->monitormode);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400253 return strlen(buf);
254}
255
256/**
David Woodhouse23a397a2007-12-11 18:56:42 -0500257 * lbs_rtap attribute to be exported per ethX interface
258 * through sysfs (/sys/class/net/ethX/lbs_rtap)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400259 */
David Woodhouse23a397a2007-12-11 18:56:42 -0500260static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get, lbs_rtap_set );
261
262/**
263 * Get function for sysfs attribute mesh
264 */
265static ssize_t lbs_mesh_get(struct device *dev,
266 struct device_attribute *attr, char * buf)
267{
Kiran Divekarab65f642009-02-19 19:32:39 -0500268 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
David Woodhouse23a397a2007-12-11 18:56:42 -0500269 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
270}
271
272/**
273 * Set function for sysfs attribute mesh
274 */
275static ssize_t lbs_mesh_set(struct device *dev,
276 struct device_attribute *attr, const char * buf, size_t count)
277{
Kiran Divekarab65f642009-02-19 19:32:39 -0500278 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
David Woodhouse23a397a2007-12-11 18:56:42 -0500279 int enable;
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700280 int ret, action = CMD_ACT_MESH_CONFIG_STOP;
David Woodhouse23a397a2007-12-11 18:56:42 -0500281
282 sscanf(buf, "%x", &enable);
283 enable = !!enable;
284 if (enable == !!priv->mesh_dev)
285 return count;
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700286 if (enable)
287 action = CMD_ACT_MESH_CONFIG_START;
Holger Schurigc14951f2009-10-22 15:30:50 +0200288 ret = lbs_mesh_config(priv, action, priv->channel);
David Woodhouse23a397a2007-12-11 18:56:42 -0500289 if (ret)
290 return ret;
David Woodhouse7e226272007-12-14 22:53:41 -0500291
David Woodhouse23a397a2007-12-11 18:56:42 -0500292 if (enable)
293 lbs_add_mesh(priv);
294 else
295 lbs_remove_mesh(priv);
296
297 return count;
298}
299
300/**
301 * lbs_mesh attribute to be exported per ethX interface
302 * through sysfs (/sys/class/net/ethX/lbs_mesh)
303 */
304static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400305
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200306/**
Luis Carlos82fde742007-06-07 16:40:59 -0400307 * anycast_mask attribute to be exported per mshX interface
308 * through sysfs (/sys/class/net/mshX/anycast_mask)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200309 */
Holger Schurig10078322007-11-15 18:05:47 -0500310static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200311
Anna Neal6fb53252008-12-09 13:23:45 -0800312/**
313 * prb_rsp_limit attribute to be exported per mshX interface
314 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
315 */
316static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get,
317 lbs_prb_rsp_limit_set);
318
Holger Schurig10078322007-11-15 18:05:47 -0500319static struct attribute *lbs_mesh_sysfs_entries[] = {
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400320 &dev_attr_anycast_mask.attr,
Anna Neal6fb53252008-12-09 13:23:45 -0800321 &dev_attr_prb_rsp_limit.attr,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400322 NULL,
323};
324
Holger Schurig10078322007-11-15 18:05:47 -0500325static struct attribute_group lbs_mesh_attr_group = {
326 .attrs = lbs_mesh_sysfs_entries,
Luis Carlos Coboa9f38d02007-08-02 11:52:29 -0400327};
328
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200329/**
David Woodhouse8552855f2007-12-10 16:38:18 -0500330 * @brief This function opens the ethX or mshX interface
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200331 *
332 * @param dev A pointer to net_device structure
David Woodhouse8552855f2007-12-10 16:38:18 -0500333 * @return 0 or -EBUSY if monitor mode active
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200334 */
Holger Schurig10078322007-11-15 18:05:47 -0500335static int lbs_dev_open(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200336{
Kiran Divekarab65f642009-02-19 19:32:39 -0500337 struct lbs_private *priv = dev->ml_priv;
David Woodhouse8552855f2007-12-10 16:38:18 -0500338 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200339
Holger Schurig61d30022008-01-16 15:59:52 +0100340 lbs_deb_enter(LBS_DEB_NET);
341
David Woodhouse8552855f2007-12-10 16:38:18 -0500342 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200343
Holger Schurigc2b310a2008-03-26 09:57:14 +0100344 if (priv->monitormode) {
David Woodhouse8552855f2007-12-10 16:38:18 -0500345 ret = -EBUSY;
346 goto out;
Javier Cardona51d84f52007-05-25 12:06:56 -0400347 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200348
David Woodhouse8552855f2007-12-10 16:38:18 -0500349 if (dev == priv->mesh_dev) {
350 priv->mesh_open = 1;
351 priv->mesh_connect_status = LBS_CONNECTED;
352 netif_carrier_on(dev);
353 } else {
354 priv->infra_open = 1;
David Woodhouse7e226272007-12-14 22:53:41 -0500355
David Woodhouse8552855f2007-12-10 16:38:18 -0500356 if (priv->connect_status == LBS_CONNECTED)
357 netif_carrier_on(dev);
358 else
359 netif_carrier_off(dev);
360 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200361
David Woodhouse8552855f2007-12-10 16:38:18 -0500362 if (!priv->tx_pending_len)
363 netif_wake_queue(dev);
364 out:
Brajesh Dave01d77d82007-11-20 17:44:14 -0500365
David Woodhouse8552855f2007-12-10 16:38:18 -0500366 spin_unlock_irq(&priv->driver_lock);
Holger Schurig61d30022008-01-16 15:59:52 +0100367 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
David Woodhouse8552855f2007-12-10 16:38:18 -0500368 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369}
370
371/**
372 * @brief This function closes the mshX interface
373 *
374 * @param dev A pointer to net_device structure
375 * @return 0
376 */
David Woodhouse8552855f2007-12-10 16:38:18 -0500377static int lbs_mesh_stop(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378{
Wang Chen4ceb7b62008-09-05 11:28:47 +0800379 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200380
Holger Schurig61d30022008-01-16 15:59:52 +0100381 lbs_deb_enter(LBS_DEB_MESH);
David Woodhouse8552855f2007-12-10 16:38:18 -0500382 spin_lock_irq(&priv->driver_lock);
383
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200384 priv->mesh_open = 0;
David Woodhouse8552855f2007-12-10 16:38:18 -0500385 priv->mesh_connect_status = LBS_DISCONNECTED;
386
387 netif_stop_queue(dev);
388 netif_carrier_off(dev);
David Woodhouse7e226272007-12-14 22:53:41 -0500389
David Woodhouse8552855f2007-12-10 16:38:18 -0500390 spin_unlock_irq(&priv->driver_lock);
Holger Schurig61d30022008-01-16 15:59:52 +0100391
David Woodhouse75bf45a2008-05-20 13:32:45 +0100392 schedule_work(&priv->mcast_work);
393
Holger Schurig61d30022008-01-16 15:59:52 +0100394 lbs_deb_leave(LBS_DEB_MESH);
David Woodhouse8552855f2007-12-10 16:38:18 -0500395 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200396}
397
398/**
399 * @brief This function closes the ethX interface
400 *
401 * @param dev A pointer to net_device structure
402 * @return 0
403 */
David Woodhouse8552855f2007-12-10 16:38:18 -0500404static int lbs_eth_stop(struct net_device *dev)
Holger Schurig78523da2007-05-25 11:49:19 -0400405{
Kiran Divekarab65f642009-02-19 19:32:39 -0500406 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200407
Holger Schurig61d30022008-01-16 15:59:52 +0100408 lbs_deb_enter(LBS_DEB_NET);
409
David Woodhouse8552855f2007-12-10 16:38:18 -0500410 spin_lock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200411 priv->infra_open = 0;
David Woodhouse8552855f2007-12-10 16:38:18 -0500412 netif_stop_queue(dev);
David Woodhouse8552855f2007-12-10 16:38:18 -0500413 spin_unlock_irq(&priv->driver_lock);
Holger Schurig61d30022008-01-16 15:59:52 +0100414
David Woodhouse75bf45a2008-05-20 13:32:45 +0100415 schedule_work(&priv->mcast_work);
416
Holger Schurig61d30022008-01-16 15:59:52 +0100417 lbs_deb_leave(LBS_DEB_NET);
David Woodhouse8552855f2007-12-10 16:38:18 -0500418 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419}
420
Holger Schurig10078322007-11-15 18:05:47 -0500421static void lbs_tx_timeout(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200422{
Kiran Divekarab65f642009-02-19 19:32:39 -0500423 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200424
Holger Schurig9012b282007-05-25 11:27:16 -0400425 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200426
Holger Schurig9012b282007-05-25 11:27:16 -0400427 lbs_pr_err("tx watch dog timeout\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200428
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200429 dev->trans_start = jiffies;
430
Holger Schurig7919b892008-04-01 14:50:43 +0200431 if (priv->currenttxskb)
432 lbs_send_tx_feedback(priv, 0);
433
David Woodhousea63b22b2007-12-08 20:56:44 +0000434 /* XX: Shouldn't we also call into the hw-specific driver
435 to kick it somehow? */
436 lbs_host_to_card_done(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200437
David Woodhouse354eca92007-12-17 19:22:40 -0500438 /* More often than not, this actually happens because the
439 firmware has crapped itself -- rather than just a very
440 busy medium. So send a harmless command, and if/when
441 _that_ times out, we'll kick it in the head. */
442 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
443 0, 0, NULL);
444
Holger Schurig9012b282007-05-25 11:27:16 -0400445 lbs_deb_leave(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200446}
447
David Woodhousee775ed72007-12-06 14:36:11 +0000448void lbs_host_to_card_done(struct lbs_private *priv)
449{
David Woodhousea63b22b2007-12-08 20:56:44 +0000450 unsigned long flags;
451
Holger Schurig61d30022008-01-16 15:59:52 +0100452 lbs_deb_enter(LBS_DEB_THREAD);
453
David Woodhousea63b22b2007-12-08 20:56:44 +0000454 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhousee775ed72007-12-06 14:36:11 +0000455
456 priv->dnld_sent = DNLD_RES_RECEIVED;
457
458 /* Wake main thread if commands are pending */
Amitkumar Karwar49125452009-09-30 20:04:38 -0700459 if (!priv->cur_cmd || priv->tx_pending_len > 0) {
460 if (!priv->wakeup_dev_required)
461 wake_up_interruptible(&priv->waitq);
462 }
David Woodhousee775ed72007-12-06 14:36:11 +0000463
David Woodhousea63b22b2007-12-08 20:56:44 +0000464 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig61d30022008-01-16 15:59:52 +0100465 lbs_deb_leave(LBS_DEB_THREAD);
David Woodhousee775ed72007-12-06 14:36:11 +0000466}
467EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
468
Holger Schurig10078322007-11-15 18:05:47 -0500469static int lbs_set_mac_address(struct net_device *dev, void *addr)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470{
471 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -0500472 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200473 struct sockaddr *phwaddr = addr;
Holger Schurig2af9f032008-03-26 09:58:32 +0100474 struct cmd_ds_802_11_mac_address cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200475
Holger Schurig9012b282007-05-25 11:27:16 -0400476 lbs_deb_enter(LBS_DEB_NET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200477
Luis Carlos Cobo Rus0a0d08a2007-05-25 23:05:27 -0400478 /* In case it was called from the mesh device */
Holger Schurig2af9f032008-03-26 09:58:32 +0100479 dev = priv->dev;
Luis Carlos Cobo Rus0a0d08a2007-05-25 23:05:27 -0400480
Holger Schurig2af9f032008-03-26 09:58:32 +0100481 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
482 cmd.action = cpu_to_le16(CMD_ACT_SET);
483 memcpy(cmd.macadd, phwaddr->sa_data, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200484
Holger Schurig2af9f032008-03-26 09:58:32 +0100485 ret = lbs_cmd_with_response(priv, CMD_802_11_MAC_ADDRESS, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200486 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400487 lbs_deb_net("set MAC address failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200488 goto done;
489 }
490
Holger Schurig2af9f032008-03-26 09:58:32 +0100491 memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN);
492 memcpy(dev->dev_addr, phwaddr->sa_data, ETH_ALEN);
Holger Schurig78523da2007-05-25 11:49:19 -0400493 if (priv->mesh_dev)
Holger Schurig2af9f032008-03-26 09:58:32 +0100494 memcpy(priv->mesh_dev->dev_addr, phwaddr->sa_data, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200495
496done:
Holger Schurig9012b282007-05-25 11:27:16 -0400497 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200498 return ret;
499}
500
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200501
David Woodhouse75bf45a2008-05-20 13:32:45 +0100502static inline int mac_in_list(unsigned char *list, int list_len,
503 unsigned char *mac)
504{
505 while (list_len) {
506 if (!memcmp(list, mac, ETH_ALEN))
507 return 1;
508 list += ETH_ALEN;
509 list_len--;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200510 }
David Woodhouse75bf45a2008-05-20 13:32:45 +0100511 return 0;
512}
513
514
515static int lbs_add_mcast_addrs(struct cmd_ds_mac_multicast_adr *cmd,
516 struct net_device *dev, int nr_addrs)
517{
518 int i = nr_addrs;
519 struct dev_mc_list *mc_list;
David Woodhouse75bf45a2008-05-20 13:32:45 +0100520
521 if ((dev->flags & (IFF_UP|IFF_MULTICAST)) != (IFF_UP|IFF_MULTICAST))
522 return nr_addrs;
523
David S. Millerb9e40852008-07-15 00:15:08 -0700524 netif_addr_lock_bh(dev);
David Woodhouse75bf45a2008-05-20 13:32:45 +0100525 for (mc_list = dev->mc_list; mc_list; mc_list = mc_list->next) {
526 if (mac_in_list(cmd->maclist, nr_addrs, mc_list->dmi_addr)) {
Johannes Berge1749612008-10-27 15:59:26 -0700527 lbs_deb_net("mcast address %s:%pM skipped\n", dev->name,
528 mc_list->dmi_addr);
David Woodhouse75bf45a2008-05-20 13:32:45 +0100529 continue;
530 }
531
532 if (i == MRVDRV_MAX_MULTICAST_LIST_SIZE)
533 break;
534 memcpy(&cmd->maclist[6*i], mc_list->dmi_addr, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -0700535 lbs_deb_net("mcast address %s:%pM added to filter\n", dev->name,
536 mc_list->dmi_addr);
David Woodhouse75bf45a2008-05-20 13:32:45 +0100537 i++;
538 }
David S. Millerb9e40852008-07-15 00:15:08 -0700539 netif_addr_unlock_bh(dev);
David Woodhouse75bf45a2008-05-20 13:32:45 +0100540 if (mc_list)
541 return -EOVERFLOW;
542
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200543 return i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200544}
545
David Woodhouse75bf45a2008-05-20 13:32:45 +0100546static void lbs_set_mcast_worker(struct work_struct *work)
547{
548 struct lbs_private *priv = container_of(work, struct lbs_private, mcast_work);
549 struct cmd_ds_mac_multicast_adr mcast_cmd;
550 int dev_flags;
551 int nr_addrs;
552 int old_mac_control = priv->mac_control;
553
554 lbs_deb_enter(LBS_DEB_NET);
555
556 dev_flags = priv->dev->flags;
557 if (priv->mesh_dev)
558 dev_flags |= priv->mesh_dev->flags;
559
560 if (dev_flags & IFF_PROMISC) {
561 priv->mac_control |= CMD_ACT_MAC_PROMISCUOUS_ENABLE;
562 priv->mac_control &= ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE |
563 CMD_ACT_MAC_MULTICAST_ENABLE);
564 goto out_set_mac_control;
565 } else if (dev_flags & IFF_ALLMULTI) {
566 do_allmulti:
567 priv->mac_control |= CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
568 priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE |
569 CMD_ACT_MAC_MULTICAST_ENABLE);
570 goto out_set_mac_control;
571 }
572
573 /* Once for priv->dev, again for priv->mesh_dev if it exists */
574 nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->dev, 0);
575 if (nr_addrs >= 0 && priv->mesh_dev)
576 nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->mesh_dev, nr_addrs);
577 if (nr_addrs < 0)
578 goto do_allmulti;
579
580 if (nr_addrs) {
581 int size = offsetof(struct cmd_ds_mac_multicast_adr,
582 maclist[6*nr_addrs]);
583
584 mcast_cmd.action = cpu_to_le16(CMD_ACT_SET);
585 mcast_cmd.hdr.size = cpu_to_le16(size);
586 mcast_cmd.nr_of_adrs = cpu_to_le16(nr_addrs);
587
588 lbs_cmd_async(priv, CMD_MAC_MULTICAST_ADR, &mcast_cmd.hdr, size);
589
590 priv->mac_control |= CMD_ACT_MAC_MULTICAST_ENABLE;
591 } else
592 priv->mac_control &= ~CMD_ACT_MAC_MULTICAST_ENABLE;
593
594 priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE |
595 CMD_ACT_MAC_ALL_MULTICAST_ENABLE);
596 out_set_mac_control:
597 if (priv->mac_control != old_mac_control)
598 lbs_set_mac_control(priv);
599
600 lbs_deb_leave(LBS_DEB_NET);
601}
602
Holger Schurig10078322007-11-15 18:05:47 -0500603static void lbs_set_multicast_list(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604{
Kiran Divekarab65f642009-02-19 19:32:39 -0500605 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200606
David Woodhouse75bf45a2008-05-20 13:32:45 +0100607 schedule_work(&priv->mcast_work);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608}
609
610/**
Holger Schurig10078322007-11-15 18:05:47 -0500611 * @brief This function handles the major jobs in the LBS driver.
Holger Schurig9012b282007-05-25 11:27:16 -0400612 * It handles all events generated by firmware, RX data received
613 * from firmware and TX data sent from kernel.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200614 *
Holger Schurig10078322007-11-15 18:05:47 -0500615 * @param data A pointer to lbs_thread structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200616 * @return 0
617 */
Holger Schurig10078322007-11-15 18:05:47 -0500618static int lbs_thread(void *data)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200619{
Dan Williamsfe336152007-08-02 11:32:25 -0400620 struct net_device *dev = data;
Kiran Divekarab65f642009-02-19 19:32:39 -0500621 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200622 wait_queue_t wait;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200623
Holger Schurig9012b282007-05-25 11:27:16 -0400624 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200625
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200626 init_waitqueue_entry(&wait, current);
627
628 for (;;) {
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500629 int shouldsleep;
Holger Schurig7919b892008-04-01 14:50:43 +0200630 u8 resp_idx;
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500631
Holger Schurig7919b892008-04-01 14:50:43 +0200632 lbs_deb_thread("1: currenttxskb %p, dnld_sent %d\n",
633 priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200634
Dan Williamsfe336152007-08-02 11:32:25 -0400635 add_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200636 set_current_state(TASK_INTERRUPTIBLE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000637 spin_lock_irq(&priv->driver_lock);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000638
David Woodhoused9f88702007-12-13 21:48:00 -0500639 if (kthread_should_stop())
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500640 shouldsleep = 0; /* Bye */
David Woodhoused9f88702007-12-13 21:48:00 -0500641 else if (priv->surpriseremoved)
642 shouldsleep = 1; /* We need to wait until we're _told_ to die */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500643 else if (priv->psstate == PS_STATE_SLEEP)
644 shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */
David Woodhouse2a345092007-12-15 19:33:43 -0500645 else if (priv->cmd_timed_out)
646 shouldsleep = 0; /* Command timed out. Recover */
David Woodhouseb15152a2007-12-11 11:55:37 -0500647 else if (!priv->fw_ready)
648 shouldsleep = 1; /* Firmware not ready. We're waiting for it */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500649 else if (priv->dnld_sent)
650 shouldsleep = 1; /* Something is en route to the device already */
David Woodhouse2eb188a2007-12-09 23:54:27 -0500651 else if (priv->tx_pending_len > 0)
652 shouldsleep = 0; /* We've a packet to send */
Holger Schurigef707b82008-05-23 16:04:13 +0200653 else if (priv->resp_len[priv->resp_idx])
654 shouldsleep = 0; /* We have a command response */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500655 else if (priv->cur_cmd)
656 shouldsleep = 1; /* Can't send a command; one already running */
Amitkumar Karwar49125452009-09-30 20:04:38 -0700657 else if (!list_empty(&priv->cmdpendingq) &&
658 !(priv->wakeup_dev_required))
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500659 shouldsleep = 0; /* We have a command to send */
Holger Schurig7919b892008-04-01 14:50:43 +0200660 else if (__kfifo_len(priv->event_fifo))
661 shouldsleep = 0; /* We have an event to process */
David Woodhouseb8d40bc2007-12-09 23:44:43 -0500662 else
663 shouldsleep = 1; /* No command */
664
665 if (shouldsleep) {
Holger Schurig7919b892008-04-01 14:50:43 +0200666 lbs_deb_thread("sleeping, connect_status %d, "
Holger Schurig5f505d92008-04-30 10:50:07 +0200667 "psmode %d, psstate %d\n",
Holger Schurig7919b892008-04-01 14:50:43 +0200668 priv->connect_status,
669 priv->psmode, priv->psstate);
David Woodhouseaa21c002007-12-08 20:04:36 +0000670 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200671 schedule();
672 } else
David Woodhouseaa21c002007-12-08 20:04:36 +0000673 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200674
Holger Schurig7919b892008-04-01 14:50:43 +0200675 lbs_deb_thread("2: currenttxskb %p, dnld_send %d\n",
676 priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200677
678 set_current_state(TASK_RUNNING);
Dan Williamsfe336152007-08-02 11:32:25 -0400679 remove_wait_queue(&priv->waitq, &wait);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200680
Holger Schurig7919b892008-04-01 14:50:43 +0200681 lbs_deb_thread("3: currenttxskb %p, dnld_sent %d\n",
682 priv->currenttxskb, priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200683
David Woodhoused9f88702007-12-13 21:48:00 -0500684 if (kthread_should_stop()) {
Holger Schurig7919b892008-04-01 14:50:43 +0200685 lbs_deb_thread("break from main thread\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200686 break;
687 }
688
David Woodhoused9f88702007-12-13 21:48:00 -0500689 if (priv->surpriseremoved) {
690 lbs_deb_thread("adapter removed; waiting to die...\n");
691 continue;
692 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200693
Holger Schurig7919b892008-04-01 14:50:43 +0200694 lbs_deb_thread("4: currenttxskb %p, dnld_sent %d\n",
695 priv->currenttxskb, priv->dnld_sent);
696
Holger Schurig7919b892008-04-01 14:50:43 +0200697 /* Process any pending command response */
Holger Schuriga01f5452008-06-04 11:10:40 +0200698 spin_lock_irq(&priv->driver_lock);
Holger Schurig7919b892008-04-01 14:50:43 +0200699 resp_idx = priv->resp_idx;
700 if (priv->resp_len[resp_idx]) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000701 spin_unlock_irq(&priv->driver_lock);
Holger Schurig7919b892008-04-01 14:50:43 +0200702 lbs_process_command_response(priv,
703 priv->resp_buf[resp_idx],
704 priv->resp_len[resp_idx]);
David Woodhouseaa21c002007-12-08 20:04:36 +0000705 spin_lock_irq(&priv->driver_lock);
Holger Schurig7919b892008-04-01 14:50:43 +0200706 priv->resp_len[resp_idx] = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200707 }
Holger Schurig7919b892008-04-01 14:50:43 +0200708 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709
Amitkumar Karwar49125452009-09-30 20:04:38 -0700710 /* Process hardware events, e.g. card removed, link lost */
711 spin_lock_irq(&priv->driver_lock);
712 while (__kfifo_len(priv->event_fifo)) {
713 u32 event;
714 __kfifo_get(priv->event_fifo, (unsigned char *) &event,
715 sizeof(event));
716 spin_unlock_irq(&priv->driver_lock);
717 lbs_process_event(priv, event);
718 spin_lock_irq(&priv->driver_lock);
719 }
720 spin_unlock_irq(&priv->driver_lock);
721
722 if (priv->wakeup_dev_required) {
723 lbs_deb_thread("Waking up device...\n");
724 /* Wake up device */
725 if (priv->exit_deep_sleep(priv))
726 lbs_deb_thread("Wakeup device failed\n");
727 continue;
728 }
729
Holger Schurig7919b892008-04-01 14:50:43 +0200730 /* command timeout stuff */
David Woodhouse2a345092007-12-15 19:33:43 -0500731 if (priv->cmd_timed_out && priv->cur_cmd) {
732 struct cmd_ctrl_node *cmdnode = priv->cur_cmd;
733
Holger Schurig57962f02008-05-14 16:30:28 +0200734 if (++priv->nr_retries > 3) {
735 lbs_pr_info("Excessive timeouts submitting "
736 "command 0x%04x\n",
737 le16_to_cpu(cmdnode->cmdbuf->command));
David Woodhouse2a345092007-12-15 19:33:43 -0500738 lbs_complete_command(priv, cmdnode, -ETIMEDOUT);
739 priv->nr_retries = 0;
Holger Schurigb43441a2008-05-23 10:07:56 +0200740 if (priv->reset_card)
David Woodhouseedf5dab2008-05-20 16:43:31 +0100741 priv->reset_card(priv);
David Woodhouse2a345092007-12-15 19:33:43 -0500742 } else {
743 priv->cur_cmd = NULL;
Brian Cavagnolo02969d22008-05-13 13:54:59 +0100744 priv->dnld_sent = DNLD_RES_RECEIVED;
Holger Schurig57962f02008-05-14 16:30:28 +0200745 lbs_pr_info("requeueing command 0x%04x due "
746 "to timeout (#%d)\n",
747 le16_to_cpu(cmdnode->cmdbuf->command),
748 priv->nr_retries);
David Woodhouse2a345092007-12-15 19:33:43 -0500749
750 /* Stick it back at the _top_ of the pending queue
751 for immediate resubmission */
752 list_add(&cmdnode->list, &priv->cmdpendingq);
753 }
754 }
755 priv->cmd_timed_out = 0;
756
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200757
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200758
David Woodhouseb15152a2007-12-11 11:55:37 -0500759 if (!priv->fw_ready)
760 continue;
761
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200762 /* Check if we need to confirm Sleep Request received previously */
David Woodhouseaa21c002007-12-08 20:04:36 +0000763 if (priv->psstate == PS_STATE_PRE_SLEEP &&
764 !priv->dnld_sent && !priv->cur_cmd) {
765 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig7919b892008-04-01 14:50:43 +0200766 lbs_deb_thread("pre-sleep, currenttxskb %p, "
767 "dnld_sent %d, cur_cmd %p\n",
768 priv->currenttxskb, priv->dnld_sent,
769 priv->cur_cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200770
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100771 lbs_ps_confirm_sleep(priv);
David Woodhouse59f3e4b2007-12-08 17:42:59 +0000772 } else {
773 /* workaround for firmware sending
774 * deauth/linkloss event immediately
775 * after sleep request; remove this
776 * after firmware fixes it
777 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000778 priv->psstate = PS_STATE_AWAKE;
Holger Schurig7919b892008-04-01 14:50:43 +0200779 lbs_pr_alert("ignore PS_SleepConfirm in "
780 "non-connected state\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200781 }
782 }
783
784 /* The PS state is changed during processing of Sleep Request
785 * event above
786 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000787 if ((priv->psstate == PS_STATE_SLEEP) ||
788 (priv->psstate == PS_STATE_PRE_SLEEP))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200789 continue;
790
Amitkumar Karwar49125452009-09-30 20:04:38 -0700791 if (priv->is_deep_sleep)
792 continue;
793
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200794 /* Execute the next command */
David Woodhouseaa21c002007-12-08 20:04:36 +0000795 if (!priv->dnld_sent && !priv->cur_cmd)
Holger Schurig10078322007-11-15 18:05:47 -0500796 lbs_execute_next_command(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200797
798 /* Wake-up command waiters which can't sleep in
Holger Schurig10078322007-11-15 18:05:47 -0500799 * lbs_prepare_and_send_command
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200800 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000801 if (!list_empty(&priv->cmdpendingq))
802 wake_up_all(&priv->cmd_pending);
David Woodhouse2eb188a2007-12-09 23:54:27 -0500803
804 spin_lock_irq(&priv->driver_lock);
805 if (!priv->dnld_sent && priv->tx_pending_len > 0) {
806 int ret = priv->hw_host_to_card(priv, MVMS_DAT,
807 priv->tx_pending_buf,
808 priv->tx_pending_len);
809 if (ret) {
810 lbs_deb_tx("host_to_card failed %d\n", ret);
811 priv->dnld_sent = DNLD_RES_RECEIVED;
812 }
813 priv->tx_pending_len = 0;
814 if (!priv->currenttxskb) {
815 /* We can wake the queues immediately if we aren't
816 waiting for TX feedback */
817 if (priv->connect_status == LBS_CONNECTED)
818 netif_wake_queue(priv->dev);
819 if (priv->mesh_dev &&
820 priv->mesh_connect_status == LBS_CONNECTED)
821 netif_wake_queue(priv->mesh_dev);
822 }
823 }
824 spin_unlock_irq(&priv->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200825 }
826
David Woodhouseaa21c002007-12-08 20:04:36 +0000827 del_timer(&priv->command_timer);
Amitkumar Karwar49125452009-09-30 20:04:38 -0700828 del_timer(&priv->auto_deepsleep_timer);
David Woodhouseaa21c002007-12-08 20:04:36 +0000829 wake_up_all(&priv->cmd_pending);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200830
Holger Schurig9012b282007-05-25 11:27:16 -0400831 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200832 return 0;
833}
834
David Woodhouseab25eca2007-12-12 17:38:56 -0500835static int lbs_suspend_callback(struct lbs_private *priv, unsigned long dummy,
836 struct cmd_header *cmd)
837{
Holger Schurig61d30022008-01-16 15:59:52 +0100838 lbs_deb_enter(LBS_DEB_FW);
David Woodhouseab25eca2007-12-12 17:38:56 -0500839
840 netif_device_detach(priv->dev);
841 if (priv->mesh_dev)
842 netif_device_detach(priv->mesh_dev);
843
844 priv->fw_ready = 0;
Holger Schurig61d30022008-01-16 15:59:52 +0100845 lbs_deb_leave(LBS_DEB_FW);
David Woodhouseab25eca2007-12-12 17:38:56 -0500846 return 0;
847}
848
David Woodhouseab25eca2007-12-12 17:38:56 -0500849int lbs_suspend(struct lbs_private *priv)
850{
851 struct cmd_header cmd;
852 int ret;
853
Holger Schurig61d30022008-01-16 15:59:52 +0100854 lbs_deb_enter(LBS_DEB_FW);
855
David Woodhouse506e9022007-12-12 20:06:06 -0500856 if (priv->wol_criteria == 0xffffffff) {
857 lbs_pr_info("Suspend attempt without configuring wake params!\n");
858 return -EINVAL;
859 }
860
David Woodhouseab25eca2007-12-12 17:38:56 -0500861 memset(&cmd, 0, sizeof(cmd));
David Woodhouse7e226272007-12-14 22:53:41 -0500862
David Woodhouseab25eca2007-12-12 17:38:56 -0500863 ret = __lbs_cmd(priv, CMD_802_11_HOST_SLEEP_ACTIVATE, &cmd,
864 sizeof(cmd), lbs_suspend_callback, 0);
865 if (ret)
866 lbs_pr_info("HOST_SLEEP_ACTIVATE failed: %d\n", ret);
867
Holger Schurig61d30022008-01-16 15:59:52 +0100868 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
David Woodhouseab25eca2007-12-12 17:38:56 -0500869 return ret;
870}
871EXPORT_SYMBOL_GPL(lbs_suspend);
872
Holger Schuriga63e5cb2008-04-30 10:50:39 +0200873void lbs_resume(struct lbs_private *priv)
David Woodhouseab25eca2007-12-12 17:38:56 -0500874{
Holger Schurig61d30022008-01-16 15:59:52 +0100875 lbs_deb_enter(LBS_DEB_FW);
876
David Woodhouseab25eca2007-12-12 17:38:56 -0500877 priv->fw_ready = 1;
878
879 /* Firmware doesn't seem to give us RX packets any more
880 until we send it some command. Might as well update */
881 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
882 0, 0, NULL);
883
884 netif_device_attach(priv->dev);
885 if (priv->mesh_dev)
886 netif_device_attach(priv->mesh_dev);
887
Holger Schurig61d30022008-01-16 15:59:52 +0100888 lbs_deb_leave(LBS_DEB_FW);
David Woodhouseab25eca2007-12-12 17:38:56 -0500889}
890EXPORT_SYMBOL_GPL(lbs_resume);
891
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200892/**
Colin McCabeb4836592009-01-02 19:00:22 -0800893 * @brief This function gets the HW spec from the firmware and sets
894 * some basic parameters.
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400895 *
Holger Schurig69f90322007-11-23 15:43:44 +0100896 * @param priv A pointer to struct lbs_private structure
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400897 * @return 0 or -1
898 */
Holger Schurig69f90322007-11-23 15:43:44 +0100899static int lbs_setup_firmware(struct lbs_private *priv)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400900{
901 int ret = -1;
Dan Williams87c8c722008-08-19 15:15:35 -0400902 s16 curlevel = 0, minlevel = 0, maxlevel = 0;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400903
904 lbs_deb_enter(LBS_DEB_FW);
905
Dan Williams87c8c722008-08-19 15:15:35 -0400906 /* Read MAC address from firmware */
David Woodhouseaa21c002007-12-08 20:04:36 +0000907 memset(priv->current_addr, 0xff, ETH_ALEN);
Dan Williams6e66f032007-12-11 12:42:16 -0500908 ret = lbs_update_hw_spec(priv);
Holger Schurigef85ad52008-05-14 16:27:18 +0200909 if (ret)
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400910 goto done;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400911
Dan Williams87c8c722008-08-19 15:15:35 -0400912 /* Read power levels if available */
913 ret = lbs_get_tx_power(priv, &curlevel, &minlevel, &maxlevel);
914 if (ret == 0) {
915 priv->txpower_cur = curlevel;
916 priv->txpower_min = minlevel;
917 priv->txpower_max = maxlevel;
918 }
919
Holger Schurigd9e97782008-03-12 16:06:43 +0100920 lbs_set_mac_control(priv);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400921done:
922 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
923 return ret;
924}
925
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400926/**
927 * This function handles the timeout of command sending.
928 * It will re-send the same command again.
929 */
930static void command_timer_fn(unsigned long data)
931{
Holger Schurig69f90322007-11-23 15:43:44 +0100932 struct lbs_private *priv = (struct lbs_private *)data;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400933 unsigned long flags;
934
Holger Schurig61d30022008-01-16 15:59:52 +0100935 lbs_deb_enter(LBS_DEB_CMD);
David Woodhouseaa21c002007-12-08 20:04:36 +0000936 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400937
Holger Schurig57962f02008-05-14 16:30:28 +0200938 if (!priv->cur_cmd)
David Woodhouse2a345092007-12-15 19:33:43 -0500939 goto out;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400940
Holger Schurig57962f02008-05-14 16:30:28 +0200941 lbs_pr_info("command 0x%04x timed out\n",
942 le16_to_cpu(priv->cur_cmd->cmdbuf->command));
David Woodhouse2a345092007-12-15 19:33:43 -0500943
944 priv->cmd_timed_out = 1;
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400945 wake_up_interruptible(&priv->waitq);
Holger Schurig61d30022008-01-16 15:59:52 +0100946out:
David Woodhouse2a345092007-12-15 19:33:43 -0500947 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig61d30022008-01-16 15:59:52 +0100948 lbs_deb_leave(LBS_DEB_CMD);
Holger Schurig1df4e8f2007-08-02 11:45:12 -0400949}
950
Amitkumar Karwar49125452009-09-30 20:04:38 -0700951/**
952 * This function put the device back to deep sleep mode when timer expires
953 * and no activity (command, event, data etc.) is detected.
954 */
955static void auto_deepsleep_timer_fn(unsigned long data)
956{
957 struct lbs_private *priv = (struct lbs_private *)data;
958 int ret;
959
960 lbs_deb_enter(LBS_DEB_CMD);
961
962 if (priv->is_activity_detected) {
963 priv->is_activity_detected = 0;
964 } else {
965 if (priv->is_auto_deep_sleep_enabled &&
966 (!priv->wakeup_dev_required) &&
967 (priv->connect_status != LBS_CONNECTED)) {
968 lbs_deb_main("Entering auto deep sleep mode...\n");
969 ret = lbs_prepare_and_send_command(priv,
970 CMD_802_11_DEEP_SLEEP, 0,
971 0, 0, NULL);
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700972 if (ret)
973 lbs_pr_err("Enter Deep Sleep command failed\n");
Amitkumar Karwar49125452009-09-30 20:04:38 -0700974 }
975 }
976 mod_timer(&priv->auto_deepsleep_timer , jiffies +
977 (priv->auto_deep_sleep_timeout * HZ)/1000);
978 lbs_deb_leave(LBS_DEB_CMD);
979}
980
981int lbs_enter_auto_deep_sleep(struct lbs_private *priv)
982{
983 lbs_deb_enter(LBS_DEB_SDIO);
984
985 priv->is_auto_deep_sleep_enabled = 1;
986 if (priv->is_deep_sleep)
987 priv->wakeup_dev_required = 1;
988 mod_timer(&priv->auto_deepsleep_timer ,
989 jiffies + (priv->auto_deep_sleep_timeout * HZ)/1000);
990
991 lbs_deb_leave(LBS_DEB_SDIO);
992 return 0;
993}
994
995int lbs_exit_auto_deep_sleep(struct lbs_private *priv)
996{
997 lbs_deb_enter(LBS_DEB_SDIO);
998
999 priv->is_auto_deep_sleep_enabled = 0;
1000 priv->auto_deep_sleep_timeout = 0;
1001 del_timer(&priv->auto_deepsleep_timer);
1002
1003 lbs_deb_leave(LBS_DEB_SDIO);
1004 return 0;
1005}
1006
Holger Schurige2268682008-01-28 17:26:28 +01001007static void lbs_sync_channel_worker(struct work_struct *work)
1008{
1009 struct lbs_private *priv = container_of(work, struct lbs_private,
1010 sync_channel);
1011
1012 lbs_deb_enter(LBS_DEB_MAIN);
1013 if (lbs_update_channel(priv))
1014 lbs_pr_info("Channel synchronization failed.");
1015 lbs_deb_leave(LBS_DEB_MAIN);
1016}
1017
1018
Holger Schurig69f90322007-11-23 15:43:44 +01001019static int lbs_init_adapter(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001020{
Dan Williams954ee162007-08-20 11:43:25 -04001021 size_t bufsize;
1022 int i, ret = 0;
1023
Holger Schurig61d30022008-01-16 15:59:52 +01001024 lbs_deb_enter(LBS_DEB_MAIN);
1025
Dan Williams954ee162007-08-20 11:43:25 -04001026 /* Allocate buffer to store the BSSID list */
1027 bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
David Woodhouseaa21c002007-12-08 20:04:36 +00001028 priv->networks = kzalloc(bufsize, GFP_KERNEL);
1029 if (!priv->networks) {
Dan Williams954ee162007-08-20 11:43:25 -04001030 lbs_pr_err("Out of memory allocating beacons\n");
1031 ret = -1;
1032 goto out;
1033 }
1034
1035 /* Initialize scan result lists */
David Woodhouseaa21c002007-12-08 20:04:36 +00001036 INIT_LIST_HEAD(&priv->network_free_list);
1037 INIT_LIST_HEAD(&priv->network_list);
Dan Williams954ee162007-08-20 11:43:25 -04001038 for (i = 0; i < MAX_NETWORK_COUNT; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001039 list_add_tail(&priv->networks[i].list,
1040 &priv->network_free_list);
Dan Williams954ee162007-08-20 11:43:25 -04001041 }
1042
David Woodhouseaa21c002007-12-08 20:04:36 +00001043 memset(priv->current_addr, 0xff, ETH_ALEN);
Dan Williams954ee162007-08-20 11:43:25 -04001044
David Woodhouseaa21c002007-12-08 20:04:36 +00001045 priv->connect_status = LBS_DISCONNECTED;
1046 priv->mesh_connect_status = LBS_DISCONNECTED;
1047 priv->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1048 priv->mode = IW_MODE_INFRA;
Holger Schurigc14951f2009-10-22 15:30:50 +02001049 priv->channel = DEFAULT_AD_HOC_CHANNEL;
Holger Schurigd9e97782008-03-12 16:06:43 +01001050 priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
Dan Williamsd5db2df2008-08-21 17:51:07 -04001051 priv->radio_on = 1;
Javier Cardona85319f92008-05-24 10:59:49 +01001052 priv->enablehwauto = 1;
David Woodhouseaa21c002007-12-08 20:04:36 +00001053 priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
1054 priv->psmode = LBS802_11POWERMODECAM;
1055 priv->psstate = PS_STATE_FULL_POWER;
Amitkumar Karwar49125452009-09-30 20:04:38 -07001056 priv->is_deep_sleep = 0;
1057 priv->is_auto_deep_sleep_enabled = 0;
1058 priv->wakeup_dev_required = 0;
1059 init_waitqueue_head(&priv->ds_awake_q);
Dan Williams954ee162007-08-20 11:43:25 -04001060
David Woodhouseaa21c002007-12-08 20:04:36 +00001061 mutex_init(&priv->lock);
Dan Williams954ee162007-08-20 11:43:25 -04001062
David Woodhouseaa21c002007-12-08 20:04:36 +00001063 setup_timer(&priv->command_timer, command_timer_fn,
Holger Schurig61d30022008-01-16 15:59:52 +01001064 (unsigned long)priv);
Amitkumar Karwar49125452009-09-30 20:04:38 -07001065 setup_timer(&priv->auto_deepsleep_timer, auto_deepsleep_timer_fn,
1066 (unsigned long)priv);
Dan Williams954ee162007-08-20 11:43:25 -04001067
David Woodhouseaa21c002007-12-08 20:04:36 +00001068 INIT_LIST_HEAD(&priv->cmdfreeq);
1069 INIT_LIST_HEAD(&priv->cmdpendingq);
Dan Williams954ee162007-08-20 11:43:25 -04001070
David Woodhouseaa21c002007-12-08 20:04:36 +00001071 spin_lock_init(&priv->driver_lock);
1072 init_waitqueue_head(&priv->cmd_pending);
Dan Williams954ee162007-08-20 11:43:25 -04001073
1074 /* Allocate the command buffers */
Holger Schurig10078322007-11-15 18:05:47 -05001075 if (lbs_allocate_cmd_buffer(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001076 lbs_pr_err("Out of memory allocating command buffers\n");
Holger Schurig7919b892008-04-01 14:50:43 +02001077 ret = -ENOMEM;
1078 goto out;
1079 }
1080 priv->resp_idx = 0;
1081 priv->resp_len[0] = priv->resp_len[1] = 0;
1082
1083 /* Create the event FIFO */
1084 priv->event_fifo = kfifo_alloc(sizeof(u32) * 16, GFP_KERNEL, NULL);
1085 if (IS_ERR(priv->event_fifo)) {
1086 lbs_pr_err("Out of memory allocating event FIFO buffer\n");
1087 ret = -ENOMEM;
1088 goto out;
Dan Williams954ee162007-08-20 11:43:25 -04001089 }
1090
1091out:
Holger Schurig61d30022008-01-16 15:59:52 +01001092 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1093
Dan Williams954ee162007-08-20 11:43:25 -04001094 return ret;
1095}
1096
Holger Schurig69f90322007-11-23 15:43:44 +01001097static void lbs_free_adapter(struct lbs_private *priv)
Holger Schurigac558ca2007-08-02 11:49:06 -04001098{
Holger Schurig61d30022008-01-16 15:59:52 +01001099 lbs_deb_enter(LBS_DEB_MAIN);
1100
Holger Schurig10078322007-11-15 18:05:47 -05001101 lbs_free_cmd_buffer(priv);
Holger Schurig7919b892008-04-01 14:50:43 +02001102 if (priv->event_fifo)
1103 kfifo_free(priv->event_fifo);
David Woodhouseaa21c002007-12-08 20:04:36 +00001104 del_timer(&priv->command_timer);
Amitkumar Karwar49125452009-09-30 20:04:38 -07001105 del_timer(&priv->auto_deepsleep_timer);
David Woodhouseaa21c002007-12-08 20:04:36 +00001106 kfree(priv->networks);
1107 priv->networks = NULL;
Holger Schurig61d30022008-01-16 15:59:52 +01001108
1109 lbs_deb_leave(LBS_DEB_MAIN);
Holger Schurigac558ca2007-08-02 11:49:06 -04001110}
1111
Stephen Hemmingerf02abf12009-03-20 19:36:37 +00001112static const struct net_device_ops lbs_netdev_ops = {
1113 .ndo_open = lbs_dev_open,
1114 .ndo_stop = lbs_eth_stop,
1115 .ndo_start_xmit = lbs_hard_start_xmit,
1116 .ndo_set_mac_address = lbs_set_mac_address,
1117 .ndo_tx_timeout = lbs_tx_timeout,
1118 .ndo_set_multicast_list = lbs_set_multicast_list,
1119 .ndo_change_mtu = eth_change_mtu,
1120 .ndo_validate_addr = eth_validate_addr,
1121};
1122
Holger Schurig1df4e8f2007-08-02 11:45:12 -04001123/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001124 * @brief This function adds the card. it will probe the
Holger Schurig10078322007-11-15 18:05:47 -05001125 * card, allocate the lbs_priv and initialize the device.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001126 *
1127 * @param card A pointer to card
Holger Schurig69f90322007-11-23 15:43:44 +01001128 * @return A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001129 */
Holger Schurig69f90322007-11-23 15:43:44 +01001130struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001131{
Holger Schurigff9fc792009-10-06 16:31:54 +02001132 struct net_device *dev;
1133 struct wireless_dev *wdev;
Holger Schurig69f90322007-11-23 15:43:44 +01001134 struct lbs_private *priv = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001135
Holger Schurig61d30022008-01-16 15:59:52 +01001136 lbs_deb_enter(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001137
1138 /* Allocate an Ethernet device and register it */
Holger Schurigff9fc792009-10-06 16:31:54 +02001139 wdev = lbs_cfg_alloc(dmdev);
1140 if (IS_ERR(wdev)) {
1141 lbs_pr_err("cfg80211 init failed\n");
Dan Williams954ee162007-08-20 11:43:25 -04001142 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001143 }
Holger Schurigff9fc792009-10-06 16:31:54 +02001144 /* TODO? */
1145 wdev->iftype = NL80211_IFTYPE_STATION;
1146 priv = wdev_priv(wdev);
1147 priv->wdev = wdev;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001148
Holger Schurig10078322007-11-15 18:05:47 -05001149 if (lbs_init_adapter(priv)) {
Dan Williams954ee162007-08-20 11:43:25 -04001150 lbs_pr_err("failed to initialize adapter structure.\n");
Holger Schurigff9fc792009-10-06 16:31:54 +02001151 goto err_wdev;
Dan Williams954ee162007-08-20 11:43:25 -04001152 }
1153
Holger Schurigff9fc792009-10-06 16:31:54 +02001154 //TODO? dev = alloc_netdev_mq(0, "wlan%d", ether_setup, IWM_TX_QUEUES);
1155 dev = alloc_netdev(0, "wlan%d", ether_setup);
1156 if (!dev) {
1157 dev_err(dmdev, "no memory for network device instance\n");
1158 goto err_adapter;
1159 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001160
Holger Schurigff9fc792009-10-06 16:31:54 +02001161 dev->ieee80211_ptr = wdev;
1162 dev->ml_priv = priv;
1163 SET_NETDEV_DEV(dev, dmdev);
1164 wdev->netdev = dev;
1165 priv->dev = dev;
1166
Stephen Hemmingerf02abf12009-03-20 19:36:37 +00001167 dev->netdev_ops = &lbs_netdev_ops;
Holger Schurigfb3dddf2007-05-25 11:58:22 -04001168 dev->watchdog_timeo = 5 * HZ;
Holger Schurig10078322007-11-15 18:05:47 -05001169 dev->ethtool_ops = &lbs_ethtool_ops;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001170#ifdef WIRELESS_EXT
Stephen Hemmingerf02abf12009-03-20 19:36:37 +00001171 dev->wireless_handlers = &lbs_handler_def;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001172#endif
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001173 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001174
Holger Schurigff9fc792009-10-06 16:31:54 +02001175
1176 // TODO: kzalloc + iwm_init_default_profile(iwm, iwm->umac_profile); ??
1177
1178
1179 priv->card = card;
1180 priv->mesh_open = 0;
1181 priv->infra_open = 0;
1182
Dan Williams7732ca42007-05-25 13:13:25 -04001183
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001184 priv->rtap_net_dev = NULL;
Daniel Mackc00552c2009-08-11 16:09:34 +02001185 strcpy(dev->name, "wlan%d");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001186
Dan Williamsfe336152007-08-02 11:32:25 -04001187 lbs_deb_thread("Starting main thread...\n");
1188 init_waitqueue_head(&priv->waitq);
Holger Schurig10078322007-11-15 18:05:47 -05001189 priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
Dan Williamsfe336152007-08-02 11:32:25 -04001190 if (IS_ERR(priv->main_thread)) {
1191 lbs_deb_thread("Error creating main thread.\n");
Holger Schurigff9fc792009-10-06 16:31:54 +02001192 goto err_ndev;
Dan Williamsfe336152007-08-02 11:32:25 -04001193 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001194
Holger Schurig10078322007-11-15 18:05:47 -05001195 priv->work_thread = create_singlethread_workqueue("lbs_worker");
1196 INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker);
1197 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
David Woodhouse75bf45a2008-05-20 13:32:45 +01001198 INIT_WORK(&priv->mcast_work, lbs_set_mcast_worker);
Holger Schurige2268682008-01-28 17:26:28 +01001199 INIT_WORK(&priv->sync_channel, lbs_sync_channel_worker);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001200
David Woodhouse23a397a2007-12-11 18:56:42 -05001201 sprintf(priv->mesh_ssid, "mesh");
1202 priv->mesh_ssid_len = 4;
1203
David Woodhouse506e9022007-12-12 20:06:06 -05001204 priv->wol_criteria = 0xffffffff;
1205 priv->wol_gpio = 0xff;
1206
Dan Williams954ee162007-08-20 11:43:25 -04001207 goto done;
1208
Holger Schurigff9fc792009-10-06 16:31:54 +02001209 err_ndev:
Dan Williams954ee162007-08-20 11:43:25 -04001210 free_netdev(dev);
Holger Schurigff9fc792009-10-06 16:31:54 +02001211
1212 err_adapter:
1213 lbs_free_adapter(priv);
1214
1215 err_wdev:
1216 lbs_cfg_free(priv);
1217
Dan Williams954ee162007-08-20 11:43:25 -04001218 priv = NULL;
1219
1220done:
Holger Schurig61d30022008-01-16 15:59:52 +01001221 lbs_deb_leave_args(LBS_DEB_MAIN, "priv %p", priv);
Dan Williams954ee162007-08-20 11:43:25 -04001222 return priv;
1223}
Holger Schurig10078322007-11-15 18:05:47 -05001224EXPORT_SYMBOL_GPL(lbs_add_card);
Dan Williams954ee162007-08-20 11:43:25 -04001225
1226
Holger Schuriga63e5cb2008-04-30 10:50:39 +02001227void lbs_remove_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001228{
Dan Williams954ee162007-08-20 11:43:25 -04001229 struct net_device *dev = priv->dev;
1230 union iwreq_data wrqu;
1231
1232 lbs_deb_enter(LBS_DEB_MAIN);
1233
David Woodhouse23a397a2007-12-11 18:56:42 -05001234 lbs_remove_mesh(priv);
Holger Schurig10078322007-11-15 18:05:47 -05001235 lbs_remove_rtap(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001236
1237 dev = priv->dev;
Dan Williams954ee162007-08-20 11:43:25 -04001238
Holger Schurig652e3f22008-04-30 10:51:15 +02001239 cancel_delayed_work_sync(&priv->scan_work);
1240 cancel_delayed_work_sync(&priv->assoc_work);
David Woodhouse75bf45a2008-05-20 13:32:45 +01001241 cancel_work_sync(&priv->mcast_work);
Dan Williams71b35f32008-09-08 16:34:40 -04001242
1243 /* worker thread destruction blocks on the in-flight command which
1244 * should have been cleared already in lbs_stop_card().
1245 */
1246 lbs_deb_main("destroying worker thread\n");
Dan Williams954ee162007-08-20 11:43:25 -04001247 destroy_workqueue(priv->work_thread);
Dan Williams71b35f32008-09-08 16:34:40 -04001248 lbs_deb_main("done destroying worker thread\n");
Dan Williams954ee162007-08-20 11:43:25 -04001249
David Woodhouseaa21c002007-12-08 20:04:36 +00001250 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
1251 priv->psmode = LBS802_11POWERMODECAM;
Holger Schurig10078322007-11-15 18:05:47 -05001252 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001253 }
1254
Dan Williams954ee162007-08-20 11:43:25 -04001255 memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
1256 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1257 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
1258
Amitkumar Karwar49125452009-09-30 20:04:38 -07001259 if (priv->is_deep_sleep) {
1260 priv->is_deep_sleep = 0;
1261 wake_up_interruptible(&priv->ds_awake_q);
1262 }
1263
Dan Williams954ee162007-08-20 11:43:25 -04001264 /* Stop the thread servicing the interrupts */
David Woodhouseaa21c002007-12-08 20:04:36 +00001265 priv->surpriseremoved = 1;
Dan Williams954ee162007-08-20 11:43:25 -04001266 kthread_stop(priv->main_thread);
1267
Holger Schurig10078322007-11-15 18:05:47 -05001268 lbs_free_adapter(priv);
Holger Schurigff9fc792009-10-06 16:31:54 +02001269 lbs_cfg_free(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001270
1271 priv->dev = NULL;
1272 free_netdev(dev);
1273
1274 lbs_deb_leave(LBS_DEB_MAIN);
Dan Williams954ee162007-08-20 11:43:25 -04001275}
Holger Schurig10078322007-11-15 18:05:47 -05001276EXPORT_SYMBOL_GPL(lbs_remove_card);
Dan Williams954ee162007-08-20 11:43:25 -04001277
1278
Holger Schurig69f90322007-11-23 15:43:44 +01001279int lbs_start_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001280{
1281 struct net_device *dev = priv->dev;
1282 int ret = -1;
1283
1284 lbs_deb_enter(LBS_DEB_MAIN);
1285
1286 /* poke the firmware */
Holger Schurig10078322007-11-15 18:05:47 -05001287 ret = lbs_setup_firmware(priv);
Dan Williams954ee162007-08-20 11:43:25 -04001288 if (ret)
1289 goto done;
1290
Holger Schurigff9fc792009-10-06 16:31:54 +02001291 if (lbs_cfg_register(priv)) {
1292 lbs_pr_err("cannot register device\n");
Dan Williams954ee162007-08-20 11:43:25 -04001293 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001294 }
David Woodhouse020f3d02007-12-12 23:29:13 -05001295
David Woodhouse020f3d02007-12-12 23:29:13 -05001296 lbs_update_channel(priv);
David Woodhouse020f3d02007-12-12 23:29:13 -05001297
Bing Zhao684d6b32009-03-25 09:51:16 -07001298 /* Check mesh FW version and appropriately send the mesh start
1299 * command
1300 */
1301 if (priv->mesh_fw_ver == MESH_FW_OLD) {
Holger Schurigc9d1be362008-01-16 15:57:44 +01001302 /* Enable mesh, if supported, and work out which TLV it uses.
1303 0x100 + 291 is an unofficial value used in 5.110.20.pXX
1304 0x100 + 37 is the official value used in 5.110.21.pXX
1305 but we check them in that order because 20.pXX doesn't
1306 give an error -- it just silently fails. */
1307
1308 /* 5.110.20.pXX firmware will fail the command if the channel
1309 doesn't match the existing channel. But only if the TLV
1310 is correct. If the channel is wrong, _BOTH_ versions will
1311 give an error to 0x100+291, and allow 0x100+37 to succeed.
1312 It's just that 5.110.20.pXX will not have done anything
1313 useful */
1314
Bing Zhao684d6b32009-03-25 09:51:16 -07001315 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001316 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
Holger Schurigc14951f2009-10-22 15:30:50 +02001317 priv->channel)) {
Bing Zhao684d6b32009-03-25 09:51:16 -07001318 priv->mesh_tlv = TLV_TYPE_MESH_ID;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001319 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
Holger Schurigc14951f2009-10-22 15:30:50 +02001320 priv->channel))
Holger Schurigc9d1be362008-01-16 15:57:44 +01001321 priv->mesh_tlv = 0;
1322 }
Bing Zhao684d6b32009-03-25 09:51:16 -07001323 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
1324 /* 10.0.0.pXX new firmwares should succeed with TLV
1325 * 0x100+37; Do not invoke command with old TLV.
1326 */
1327 priv->mesh_tlv = TLV_TYPE_MESH_ID;
1328 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
Holger Schurigc14951f2009-10-22 15:30:50 +02001329 priv->channel))
Bing Zhao684d6b32009-03-25 09:51:16 -07001330 priv->mesh_tlv = 0;
1331 }
1332 if (priv->mesh_tlv) {
1333 lbs_add_mesh(priv);
Holger Schurigc9d1be362008-01-16 15:57:44 +01001334
Bing Zhao684d6b32009-03-25 09:51:16 -07001335 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
1336 lbs_pr_err("cannot register lbs_mesh attribute\n");
Dan Williams3b72b012008-07-29 13:50:39 -04001337
Bing Zhao684d6b32009-03-25 09:51:16 -07001338 /* While rtap isn't related to mesh, only mesh-enabled
1339 * firmware implements the rtap functionality via
1340 * CMD_802_11_MONITOR_MODE.
1341 */
1342 if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
1343 lbs_pr_err("cannot register lbs_rtap attribute\n");
David Woodhouse020f3d02007-12-12 23:29:13 -05001344 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001345
Holger Schurig10078322007-11-15 18:05:47 -05001346 lbs_debugfs_init_one(priv, dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001347
Dan Williams954ee162007-08-20 11:43:25 -04001348 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001349
Dan Williams954ee162007-08-20 11:43:25 -04001350 ret = 0;
1351
Holger Schurig32a74b72007-05-25 12:04:31 -04001352done:
Dan Williams954ee162007-08-20 11:43:25 -04001353 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
Holger Schurig32a74b72007-05-25 12:04:31 -04001354 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001355}
Holger Schurig10078322007-11-15 18:05:47 -05001356EXPORT_SYMBOL_GPL(lbs_start_card);
Dan Williams954ee162007-08-20 11:43:25 -04001357
1358
Holger Schuriga63e5cb2008-04-30 10:50:39 +02001359void lbs_stop_card(struct lbs_private *priv)
Dan Williams954ee162007-08-20 11:43:25 -04001360{
Julia Lawall43baa5b2009-01-09 10:23:10 +00001361 struct net_device *dev;
Dan Williams954ee162007-08-20 11:43:25 -04001362 struct cmd_ctrl_node *cmdnode;
1363 unsigned long flags;
1364
1365 lbs_deb_enter(LBS_DEB_MAIN);
1366
Holger Schurig652e3f22008-04-30 10:51:15 +02001367 if (!priv)
1368 goto out;
Julia Lawall43baa5b2009-01-09 10:23:10 +00001369 dev = priv->dev;
Holger Schurig652e3f22008-04-30 10:51:15 +02001370
Julia Lawall43baa5b2009-01-09 10:23:10 +00001371 netif_stop_queue(dev);
1372 netif_carrier_off(dev);
Dan Williams954ee162007-08-20 11:43:25 -04001373
Holger Schurig10078322007-11-15 18:05:47 -05001374 lbs_debugfs_remove_one(priv);
Javier Cardona15dbaac2008-05-17 21:01:24 -07001375 if (priv->mesh_tlv) {
David Woodhouse020f3d02007-12-12 23:29:13 -05001376 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
Dan Williams3b72b012008-07-29 13:50:39 -04001377 device_remove_file(&dev->dev, &dev_attr_lbs_rtap);
Javier Cardona15dbaac2008-05-17 21:01:24 -07001378 }
Dan Williams954ee162007-08-20 11:43:25 -04001379
Dan Williams71b35f32008-09-08 16:34:40 -04001380 /* Delete the timeout of the currently processing command */
Holger Schurig652e3f22008-04-30 10:51:15 +02001381 del_timer_sync(&priv->command_timer);
Amitkumar Karwar49125452009-09-30 20:04:38 -07001382 del_timer_sync(&priv->auto_deepsleep_timer);
Dan Williams71b35f32008-09-08 16:34:40 -04001383
1384 /* Flush pending command nodes */
David Woodhouseaa21c002007-12-08 20:04:36 +00001385 spin_lock_irqsave(&priv->driver_lock, flags);
Dan Williams71b35f32008-09-08 16:34:40 -04001386 lbs_deb_main("clearing pending commands\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001387 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
David Woodhouseae125bf2007-12-15 04:22:52 -05001388 cmdnode->result = -ENOENT;
Dan Williams954ee162007-08-20 11:43:25 -04001389 cmdnode->cmdwaitqwoken = 1;
1390 wake_up_interruptible(&cmdnode->cmdwait_q);
1391 }
Dan Williams71b35f32008-09-08 16:34:40 -04001392
1393 /* Flush the command the card is currently processing */
1394 if (priv->cur_cmd) {
1395 lbs_deb_main("clearing current command\n");
1396 priv->cur_cmd->result = -ENOENT;
1397 priv->cur_cmd->cmdwaitqwoken = 1;
1398 wake_up_interruptible(&priv->cur_cmd->cmdwait_q);
1399 }
1400 lbs_deb_main("done clearing commands\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001401 spin_unlock_irqrestore(&priv->driver_lock, flags);
Dan Williams954ee162007-08-20 11:43:25 -04001402
1403 unregister_netdev(dev);
1404
Holger Schurig652e3f22008-04-30 10:51:15 +02001405out:
Holger Schuriga63e5cb2008-04-30 10:50:39 +02001406 lbs_deb_leave(LBS_DEB_MAIN);
Dan Williams954ee162007-08-20 11:43:25 -04001407}
Holger Schurig10078322007-11-15 18:05:47 -05001408EXPORT_SYMBOL_GPL(lbs_stop_card);
Holger Schurig084708b2007-05-25 12:37:58 -04001409
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001410
Stephen Hemmingerf02abf12009-03-20 19:36:37 +00001411static const struct net_device_ops mesh_netdev_ops = {
1412 .ndo_open = lbs_dev_open,
1413 .ndo_stop = lbs_mesh_stop,
1414 .ndo_start_xmit = lbs_hard_start_xmit,
1415 .ndo_set_mac_address = lbs_set_mac_address,
1416 .ndo_set_multicast_list = lbs_set_multicast_list,
1417};
1418
Holger Schurig78523da2007-05-25 11:49:19 -04001419/**
1420 * @brief This function adds mshX interface
1421 *
Holger Schurig69f90322007-11-23 15:43:44 +01001422 * @param priv A pointer to the struct lbs_private structure
Holger Schurig78523da2007-05-25 11:49:19 -04001423 * @return 0 if successful, -X otherwise
1424 */
David Woodhouse23a397a2007-12-11 18:56:42 -05001425static int lbs_add_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001426{
1427 struct net_device *mesh_dev = NULL;
1428 int ret = 0;
1429
1430 lbs_deb_enter(LBS_DEB_MESH);
1431
1432 /* Allocate a virtual mesh device */
1433 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
1434 lbs_deb_mesh("init mshX device failed\n");
1435 ret = -ENOMEM;
1436 goto done;
1437 }
Wang Chen4ceb7b62008-09-05 11:28:47 +08001438 mesh_dev->ml_priv = priv;
Holger Schurig78523da2007-05-25 11:49:19 -04001439 priv->mesh_dev = mesh_dev;
1440
Stephen Hemmingerf02abf12009-03-20 19:36:37 +00001441 mesh_dev->netdev_ops = &mesh_netdev_ops;
Holger Schurig10078322007-11-15 18:05:47 -05001442 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
Holger Schurig634b8f42007-05-25 13:05:16 -04001443 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
1444 sizeof(priv->dev->dev_addr));
Holger Schurig78523da2007-05-25 11:49:19 -04001445
David Woodhouse23a397a2007-12-11 18:56:42 -05001446 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
Dan Williams7732ca42007-05-25 13:13:25 -04001447
Holger Schurig78523da2007-05-25 11:49:19 -04001448#ifdef WIRELESS_EXT
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04001449 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
Holger Schurig78523da2007-05-25 11:49:19 -04001450#endif
David Woodhouse75bf45a2008-05-20 13:32:45 +01001451 mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
Holger Schurig78523da2007-05-25 11:49:19 -04001452 /* Register virtual mesh interface */
1453 ret = register_netdev(mesh_dev);
1454 if (ret) {
1455 lbs_pr_err("cannot register mshX virtual interface\n");
1456 goto err_free;
1457 }
1458
Holger Schurig10078322007-11-15 18:05:47 -05001459 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Holger Schurig78523da2007-05-25 11:49:19 -04001460 if (ret)
1461 goto err_unregister;
1462
Javier Cardona15dbaac2008-05-17 21:01:24 -07001463 lbs_persist_config_init(mesh_dev);
1464
Holger Schurig78523da2007-05-25 11:49:19 -04001465 /* Everything successful */
1466 ret = 0;
1467 goto done;
1468
Holger Schurig78523da2007-05-25 11:49:19 -04001469err_unregister:
1470 unregister_netdev(mesh_dev);
1471
1472err_free:
1473 free_netdev(mesh_dev);
1474
1475done:
1476 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
1477 return ret;
1478}
Holger Schurig084708b2007-05-25 12:37:58 -04001479
David Woodhouse23a397a2007-12-11 18:56:42 -05001480static void lbs_remove_mesh(struct lbs_private *priv)
Holger Schurig78523da2007-05-25 11:49:19 -04001481{
1482 struct net_device *mesh_dev;
1483
Holger Schurig78523da2007-05-25 11:49:19 -04001484
1485 mesh_dev = priv->mesh_dev;
David Woodhouse23a397a2007-12-11 18:56:42 -05001486 if (!mesh_dev)
Holger Schurig61d30022008-01-16 15:59:52 +01001487 return;
Holger Schurig78523da2007-05-25 11:49:19 -04001488
Holger Schurig61d30022008-01-16 15:59:52 +01001489 lbs_deb_enter(LBS_DEB_MESH);
Holger Schurig78523da2007-05-25 11:49:19 -04001490 netif_stop_queue(mesh_dev);
Javier Cardona15dbaac2008-05-17 21:01:24 -07001491 netif_carrier_off(mesh_dev);
Holger Schurig10078322007-11-15 18:05:47 -05001492 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
Javier Cardona15dbaac2008-05-17 21:01:24 -07001493 lbs_persist_config_remove(mesh_dev);
Holger Schurig78523da2007-05-25 11:49:19 -04001494 unregister_netdev(mesh_dev);
David Woodhouse23a397a2007-12-11 18:56:42 -05001495 priv->mesh_dev = NULL;
Holger Schurig78523da2007-05-25 11:49:19 -04001496 free_netdev(mesh_dev);
Holger Schurig61d30022008-01-16 15:59:52 +01001497 lbs_deb_leave(LBS_DEB_MESH);
Holger Schurig78523da2007-05-25 11:49:19 -04001498}
1499
Holger Schurig7919b892008-04-01 14:50:43 +02001500void lbs_queue_event(struct lbs_private *priv, u32 event)
1501{
1502 unsigned long flags;
1503
1504 lbs_deb_enter(LBS_DEB_THREAD);
1505 spin_lock_irqsave(&priv->driver_lock, flags);
1506
1507 if (priv->psstate == PS_STATE_SLEEP)
1508 priv->psstate = PS_STATE_AWAKE;
1509
1510 __kfifo_put(priv->event_fifo, (unsigned char *) &event, sizeof(u32));
1511
1512 wake_up_interruptible(&priv->waitq);
1513
1514 spin_unlock_irqrestore(&priv->driver_lock, flags);
1515 lbs_deb_leave(LBS_DEB_THREAD);
1516}
1517EXPORT_SYMBOL_GPL(lbs_queue_event);
1518
1519void lbs_notify_command_response(struct lbs_private *priv, u8 resp_idx)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001520{
Holger Schuriged37b512007-05-25 11:52:42 -04001521 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001522
David Woodhouse4f679492007-12-10 14:58:37 -05001523 if (priv->psstate == PS_STATE_SLEEP)
David Woodhouseaa21c002007-12-08 20:04:36 +00001524 priv->psstate = PS_STATE_AWAKE;
Holger Schurig7919b892008-04-01 14:50:43 +02001525
1526 /* Swap buffers by flipping the response index */
1527 BUG_ON(resp_idx > 1);
1528 priv->resp_idx = resp_idx;
1529
Dan Williamsfe336152007-08-02 11:32:25 -04001530 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001531
Holger Schuriged37b512007-05-25 11:52:42 -04001532 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001533}
Holger Schurig7919b892008-04-01 14:50:43 +02001534EXPORT_SYMBOL_GPL(lbs_notify_command_response);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001535
Andres Salomon4fb910f2007-11-20 17:43:45 -05001536static int __init lbs_init_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001537{
Holger Schurig9012b282007-05-25 11:27:16 -04001538 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurigf539f2e2008-03-26 13:22:11 +01001539 memset(&confirm_sleep, 0, sizeof(confirm_sleep));
1540 confirm_sleep.hdr.command = cpu_to_le16(CMD_802_11_PS_MODE);
1541 confirm_sleep.hdr.size = cpu_to_le16(sizeof(confirm_sleep));
1542 confirm_sleep.action = cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
Holger Schurig10078322007-11-15 18:05:47 -05001543 lbs_debugfs_init();
Holger Schurig084708b2007-05-25 12:37:58 -04001544 lbs_deb_leave(LBS_DEB_MAIN);
1545 return 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001546}
1547
Andres Salomon4fb910f2007-11-20 17:43:45 -05001548static void __exit lbs_exit_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001549{
Holger Schurig9012b282007-05-25 11:27:16 -04001550 lbs_deb_enter(LBS_DEB_MAIN);
Holger Schurig10078322007-11-15 18:05:47 -05001551 lbs_debugfs_remove();
Holger Schurig9012b282007-05-25 11:27:16 -04001552 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001553}
1554
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001555/*
1556 * rtap interface support fuctions
1557 */
1558
Holger Schurig10078322007-11-15 18:05:47 -05001559static int lbs_rtap_open(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001560{
David Woodhouse8552855f2007-12-10 16:38:18 -05001561 /* Yes, _stop_ the queue. Because we don't support injection */
Holger Schurig61d30022008-01-16 15:59:52 +01001562 lbs_deb_enter(LBS_DEB_MAIN);
1563 netif_carrier_off(dev);
1564 netif_stop_queue(dev);
1565 lbs_deb_leave(LBS_DEB_LEAVE);
1566 return 0;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001567}
1568
Holger Schurig10078322007-11-15 18:05:47 -05001569static int lbs_rtap_stop(struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001570{
Holger Schurig61d30022008-01-16 15:59:52 +01001571 lbs_deb_enter(LBS_DEB_MAIN);
1572 lbs_deb_leave(LBS_DEB_MAIN);
1573 return 0;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001574}
1575
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +00001576static netdev_tx_t lbs_rtap_hard_start_xmit(struct sk_buff *skb,
1577 struct net_device *dev)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001578{
Holger Schurig61d30022008-01-16 15:59:52 +01001579 netif_stop_queue(dev);
1580 return NETDEV_TX_BUSY;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001581}
1582
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001583static void lbs_remove_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001584{
Holger Schurig61d30022008-01-16 15:59:52 +01001585 lbs_deb_enter(LBS_DEB_MAIN);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001586 if (priv->rtap_net_dev == NULL)
Holger Schurig5f505d92008-04-30 10:50:07 +02001587 goto out;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001588 unregister_netdev(priv->rtap_net_dev);
David Woodhoused9268fb2007-12-09 16:22:21 -05001589 free_netdev(priv->rtap_net_dev);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001590 priv->rtap_net_dev = NULL;
Holger Schurig5f505d92008-04-30 10:50:07 +02001591out:
Holger Schurig61d30022008-01-16 15:59:52 +01001592 lbs_deb_leave(LBS_DEB_MAIN);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001593}
1594
Stephen Hemmingerf02abf12009-03-20 19:36:37 +00001595static const struct net_device_ops rtap_netdev_ops = {
1596 .ndo_open = lbs_rtap_open,
1597 .ndo_stop = lbs_rtap_stop,
1598 .ndo_start_xmit = lbs_rtap_hard_start_xmit,
1599};
1600
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001601static int lbs_add_rtap(struct lbs_private *priv)
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001602{
Holger Schurig61d30022008-01-16 15:59:52 +01001603 int ret = 0;
David Woodhoused9268fb2007-12-09 16:22:21 -05001604 struct net_device *rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001605
Holger Schurig61d30022008-01-16 15:59:52 +01001606 lbs_deb_enter(LBS_DEB_MAIN);
1607 if (priv->rtap_net_dev) {
1608 ret = -EPERM;
1609 goto out;
1610 }
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001611
David Woodhoused9268fb2007-12-09 16:22:21 -05001612 rtap_dev = alloc_netdev(0, "rtap%d", ether_setup);
Holger Schurig61d30022008-01-16 15:59:52 +01001613 if (rtap_dev == NULL) {
1614 ret = -ENOMEM;
1615 goto out;
1616 }
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001617
David Woodhouse121947c2007-12-09 19:54:11 -05001618 memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN);
David Woodhoused9268fb2007-12-09 16:22:21 -05001619 rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP;
Stephen Hemmingerf02abf12009-03-20 19:36:37 +00001620 rtap_dev->netdev_ops = &rtap_netdev_ops;
Wang Chen4ceb7b62008-09-05 11:28:47 +08001621 rtap_dev->ml_priv = priv;
Masakazu Mokuno229ce3a2008-05-14 14:16:50 +09001622 SET_NETDEV_DEV(rtap_dev, priv->dev->dev.parent);
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001623
Holger Schurig61d30022008-01-16 15:59:52 +01001624 ret = register_netdev(rtap_dev);
1625 if (ret) {
David Woodhoused9268fb2007-12-09 16:22:21 -05001626 free_netdev(rtap_dev);
Holger Schurig61d30022008-01-16 15:59:52 +01001627 goto out;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001628 }
David Woodhoused9268fb2007-12-09 16:22:21 -05001629 priv->rtap_net_dev = rtap_dev;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001630
Holger Schurig61d30022008-01-16 15:59:52 +01001631out:
1632 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1633 return ret;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001634}
1635
Holger Schurig10078322007-11-15 18:05:47 -05001636module_init(lbs_init_module);
1637module_exit(lbs_exit_module);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001638
Holger Schurig084708b2007-05-25 12:37:58 -04001639MODULE_DESCRIPTION("Libertas WLAN Driver Library");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001640MODULE_AUTHOR("Marvell International Ltd.");
1641MODULE_LICENSE("GPL");