blob: 3a3e8947e84a2f348119d6e2fd0f9611daac0cb7 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready.
4 */
5
6#include <net/iw_handler.h>
John W. Linville7e272fc2008-09-24 18:13:14 -04007#include <net/lib80211.h>
Holger Schurig7919b892008-04-01 14:50:43 +02008#include <linux/kfifo.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02009#include "host.h"
10#include "hostcmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020011#include "decl.h"
12#include "defs.h"
13#include "dev.h"
Holger Schurig697900a2008-04-02 16:27:10 +020014#include "assoc.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020015#include "wext.h"
Dan Williams6e66f032007-12-11 12:42:16 -050016#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020017
David Woodhouse2fd6cfe2007-12-11 17:44:10 -050018static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
Holger Schurig0d61d042007-12-05 17:58:06 +010019
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020/**
Holger Schurig8db4a2b2008-03-19 10:11:00 +010021 * @brief Simple callback that copies response back into command
22 *
23 * @param priv A pointer to struct lbs_private structure
24 * @param extra A pointer to the original command structure for which
25 * 'resp' is a response
26 * @param resp A pointer to the command response
27 *
28 * @return 0 on success, error on failure
29 */
30int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
31 struct cmd_header *resp)
32{
33 struct cmd_header *buf = (void *)extra;
34 uint16_t copy_len;
35
36 copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
37 memcpy(buf, resp, copy_len);
38 return 0;
39}
40EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
41
42/**
43 * @brief Simple callback that ignores the result. Use this if
44 * you just want to send a command to the hardware, but don't
45 * care for the result.
46 *
47 * @param priv ignored
48 * @param extra ignored
49 * @param resp ignored
50 *
51 * @return 0 for success
52 */
53static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
54 struct cmd_header *resp)
55{
56 return 0;
57}
58
59
60/**
Dan Williams852e1f22007-12-10 15:24:47 -050061 * @brief Checks whether a command is allowed in Power Save mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020062 *
63 * @param command the command ID
Dan Williams852e1f22007-12-10 15:24:47 -050064 * @return 1 if allowed, 0 if not allowed
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020065 */
Dan Williams852e1f22007-12-10 15:24:47 -050066static u8 is_command_allowed_in_ps(u16 cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020067{
Dan Williams852e1f22007-12-10 15:24:47 -050068 switch (cmd) {
69 case CMD_802_11_RSSI:
70 return 1;
71 default:
72 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020073 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074 return 0;
75}
76
Dan Williams6e66f032007-12-11 12:42:16 -050077/**
78 * @brief Updates the hardware details like MAC address and regulatory region
79 *
80 * @param priv A pointer to struct lbs_private structure
81 *
82 * @return 0 on success, error on failure
83 */
84int lbs_update_hw_spec(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020085{
Dan Williams6e66f032007-12-11 12:42:16 -050086 struct cmd_ds_get_hw_spec cmd;
87 int ret = -1;
88 u32 i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020089
Holger Schurig9012b282007-05-25 11:27:16 -040090 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020091
Dan Williams6e66f032007-12-11 12:42:16 -050092 memset(&cmd, 0, sizeof(cmd));
93 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
94 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
David Woodhouse689442d2007-12-12 16:00:42 -050095 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
Dan Williams6e66f032007-12-11 12:42:16 -050096 if (ret)
97 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020098
Dan Williams6e66f032007-12-11 12:42:16 -050099 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500100
Holger Schurigdac10a92008-01-16 15:55:22 +0100101 /* The firmware release is in an interesting format: the patch
102 * level is in the most significant nibble ... so fix that: */
103 priv->fwrelease = le32_to_cpu(cmd.fwrelease);
104 priv->fwrelease = (priv->fwrelease << 8) |
105 (priv->fwrelease >> 24 & 0xff);
106
107 /* Some firmware capabilities:
108 * CF card firmware 5.0.16p0: cap 0x00000303
109 * USB dongle firmware 5.110.17p2: cap 0x00000303
110 */
Johannes Berge1749612008-10-27 15:59:26 -0700111 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
112 cmd.permanentaddr,
Holger Schurigdac10a92008-01-16 15:55:22 +0100113 priv->fwrelease >> 24 & 0xff,
114 priv->fwrelease >> 16 & 0xff,
115 priv->fwrelease >> 8 & 0xff,
116 priv->fwrelease & 0xff,
117 priv->fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500118 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
119 cmd.hwifversion, cmd.version);
120
Bing Zhao684d6b32009-03-25 09:51:16 -0700121 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
122 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
123 /* 5.110.22 have mesh command with 0xa3 command id */
124 /* 10.0.0.p0 FW brings in mesh config command with different id */
125 /* Check FW version MSB and initialize mesh_fw_ver */
126 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
127 priv->mesh_fw_ver = MESH_FW_OLD;
128 else if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
129 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK))
130 priv->mesh_fw_ver = MESH_FW_NEW;
131 else
132 priv->mesh_fw_ver = MESH_NONE;
133
Dan Williams6e66f032007-12-11 12:42:16 -0500134 /* Clamp region code to 8-bit since FW spec indicates that it should
135 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
136 * returns non-zero high 8 bits here.
Marek Vasut15483992009-07-16 19:19:53 +0200137 *
138 * Firmware version 4.0.102 used in CF8381 has region code shifted. We
139 * need to check for this problem and handle it properly.
Dan Williams6e66f032007-12-11 12:42:16 -0500140 */
Marek Vasut15483992009-07-16 19:19:53 +0200141 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4)
142 priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF;
143 else
144 priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
Dan Williams6e66f032007-12-11 12:42:16 -0500145
146 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
147 /* use the region code to search for the index */
148 if (priv->regioncode == lbs_region_code_to_index[i])
149 break;
150 }
151
152 /* if it's unidentified region code, use the default (USA) */
153 if (i >= MRVDRV_MAX_REGION_CODE) {
154 priv->regioncode = 0x10;
155 lbs_pr_info("unidentified region code; using the default (USA)\n");
156 }
157
158 if (priv->current_addr[0] == 0xff)
159 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
160
161 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
162 if (priv->mesh_dev)
163 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
164
165 if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
166 ret = -1;
167 goto out;
168 }
169
170 if (lbs_set_universaltable(priv, 0)) {
171 ret = -1;
172 goto out;
173 }
174
175out:
Holger Schurig9012b282007-05-25 11:27:16 -0400176 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams6e66f032007-12-11 12:42:16 -0500177 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200178}
179
Anna Neal582c1b52008-10-20 16:46:56 -0700180int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
181 struct wol_config *p_wol_config)
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500182{
183 struct cmd_ds_host_sleep cmd_config;
184 int ret;
185
David Woodhouse9fae8992007-12-15 03:46:44 -0500186 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500187 cmd_config.criteria = cpu_to_le32(criteria);
David Woodhouse506e9022007-12-12 20:06:06 -0500188 cmd_config.gpio = priv->wol_gpio;
189 cmd_config.gap = priv->wol_gap;
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500190
Anna Neal582c1b52008-10-20 16:46:56 -0700191 if (p_wol_config != NULL)
192 memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config,
193 sizeof(struct wol_config));
194 else
195 cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE;
196
David Woodhouse689442d2007-12-12 16:00:42 -0500197 ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
David Woodhouse506e9022007-12-12 20:06:06 -0500198 if (!ret) {
Anna Neal582c1b52008-10-20 16:46:56 -0700199 if (criteria) {
200 lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
201 priv->wol_criteria = criteria;
202 } else
203 memcpy((uint8_t *) p_wol_config,
204 (uint8_t *)&cmd_config.wol_conf,
205 sizeof(struct wol_config));
David Woodhouse506e9022007-12-12 20:06:06 -0500206 } else {
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500207 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500208 }
David Woodhouse506e9022007-12-12 20:06:06 -0500209
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500210 return ret;
211}
212EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
213
Holger Schurige98a88d2008-03-19 14:25:58 +0100214static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200215 u16 cmd_action)
216{
217 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200218
Holger Schurig9012b282007-05-25 11:27:16 -0400219 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200220
Dan Williams0aef64d2007-08-02 11:31:18 -0400221 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouse981f1872007-05-25 23:36:54 -0400222 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
223 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200224 psm->action = cpu_to_le16(cmd_action);
225 psm->multipledtim = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400226 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400227 case CMD_SUBCMD_ENTER_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400228 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200229
Holger Schurig252cf0d12007-08-02 13:09:34 -0400230 psm->locallisteninterval = 0;
Holger Schurig97605c32007-08-02 13:09:15 -0400231 psm->nullpktinterval = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200232 psm->multipledtim =
Holger Schurig56c46562007-08-02 13:09:49 -0400233 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234 break;
235
Dan Williams0aef64d2007-08-02 11:31:18 -0400236 case CMD_SUBCMD_EXIT_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400237 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200238 break;
239
Dan Williams0aef64d2007-08-02 11:31:18 -0400240 case CMD_SUBCMD_SLEEP_CONFIRMED:
Holger Schurig9012b282007-05-25 11:27:16 -0400241 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200242 break;
243
244 default:
245 break;
246 }
247
Holger Schurig9012b282007-05-25 11:27:16 -0400248 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200249 return 0;
250}
251
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500252int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
253 uint16_t cmd_action, uint16_t *timeout)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200254{
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500255 struct cmd_ds_802_11_inactivity_timeout cmd;
256 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200257
Holger Schurig8ff12da2007-08-02 11:54:31 -0400258 lbs_deb_enter(LBS_DEB_CMD);
259
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500260 cmd.hdr.command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
261 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200262
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500263 cmd.action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200264
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500265 if (cmd_action == CMD_ACT_SET)
266 cmd.timeout = cpu_to_le16(*timeout);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200267 else
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500268 cmd.timeout = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200269
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500270 ret = lbs_cmd_with_response(priv, CMD_802_11_INACTIVITY_TIMEOUT, &cmd);
271
272 if (!ret)
273 *timeout = le16_to_cpu(cmd.timeout);
274
275 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200276 return 0;
277}
278
David Woodhouse3fbe1042007-12-17 23:48:31 -0500279int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
280 struct sleep_params *sp)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200281{
David Woodhouse3fbe1042007-12-17 23:48:31 -0500282 struct cmd_ds_802_11_sleep_params cmd;
283 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200284
Holger Schurig9012b282007-05-25 11:27:16 -0400285 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200286
Dan Williams0aef64d2007-08-02 11:31:18 -0400287 if (cmd_action == CMD_ACT_GET) {
David Woodhouse3fbe1042007-12-17 23:48:31 -0500288 memset(&cmd, 0, sizeof(cmd));
289 } else {
290 cmd.error = cpu_to_le16(sp->sp_error);
291 cmd.offset = cpu_to_le16(sp->sp_offset);
292 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
293 cmd.calcontrol = sp->sp_calcontrol;
294 cmd.externalsleepclk = sp->sp_extsleepclk;
295 cmd.reserved = cpu_to_le16(sp->sp_reserved);
296 }
297 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
298 cmd.action = cpu_to_le16(cmd_action);
299
300 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
301
302 if (!ret) {
303 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
304 "calcontrol 0x%x extsleepclk 0x%x\n",
305 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
306 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
307 cmd.externalsleepclk);
308
309 sp->sp_error = le16_to_cpu(cmd.error);
310 sp->sp_offset = le16_to_cpu(cmd.offset);
311 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
312 sp->sp_calcontrol = cmd.calcontrol;
313 sp->sp_extsleepclk = cmd.externalsleepclk;
314 sp->sp_reserved = le16_to_cpu(cmd.reserved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200315 }
316
David Woodhouse3fbe1042007-12-17 23:48:31 -0500317 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200318 return 0;
319}
320
Amitkumar Karwar49125452009-09-30 20:04:38 -0700321static int lbs_wait_for_ds_awake(struct lbs_private *priv)
322{
323 int ret = 0;
324
325 lbs_deb_enter(LBS_DEB_CMD);
326
327 if (priv->is_deep_sleep) {
328 if (!wait_event_interruptible_timeout(priv->ds_awake_q,
329 !priv->is_deep_sleep, (10 * HZ))) {
330 lbs_pr_err("ds_awake_q: timer expired\n");
331 ret = -1;
332 }
333 }
334
335 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
336 return ret;
337}
338
339int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep)
340{
341 int ret = 0;
342
343 lbs_deb_enter(LBS_DEB_CMD);
344
345 if (deep_sleep) {
346 if (priv->is_deep_sleep != 1) {
347 lbs_deb_cmd("deep sleep: sleep\n");
348 BUG_ON(!priv->enter_deep_sleep);
349 ret = priv->enter_deep_sleep(priv);
350 if (!ret) {
351 netif_stop_queue(priv->dev);
352 netif_carrier_off(priv->dev);
353 }
354 } else {
355 lbs_pr_err("deep sleep: already enabled\n");
356 }
357 } else {
358 if (priv->is_deep_sleep) {
359 lbs_deb_cmd("deep sleep: wakeup\n");
360 BUG_ON(!priv->exit_deep_sleep);
361 ret = priv->exit_deep_sleep(priv);
362 if (!ret) {
363 ret = lbs_wait_for_ds_awake(priv);
364 if (ret)
365 lbs_pr_err("deep sleep: wakeup"
366 "failed\n");
367 }
368 }
369 }
370
371 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
372 return ret;
373}
374
David Woodhousef70dd452007-12-18 00:18:05 -0500375int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
376 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200377{
David Woodhousef70dd452007-12-18 00:18:05 -0500378 struct cmd_ds_802_11_set_wep cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200379 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200380
Holger Schurig9012b282007-05-25 11:27:16 -0400381 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200382
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200383 memset(&cmd, 0, sizeof(cmd));
David Woodhousef70dd452007-12-18 00:18:05 -0500384 cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
385 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386
David Woodhousef70dd452007-12-18 00:18:05 -0500387 cmd.action = cpu_to_le16(cmd_action);
388
389 if (cmd_action == CMD_ACT_ADD) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200390 int i;
391
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500393 cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
394 CMD_WEP_KEY_INDEX_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200395
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200396 /* Copy key types and material to host command structure */
397 for (i = 0; i < 4; i++) {
David Woodhousef70dd452007-12-18 00:18:05 -0500398 struct enc_key *pkey = &assoc->wep_keys[i];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200399
400 switch (pkey->len) {
401 case KEY_LEN_WEP_40:
David Woodhousef70dd452007-12-18 00:18:05 -0500402 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
403 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400404 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200405 break;
406 case KEY_LEN_WEP_104:
David Woodhousef70dd452007-12-18 00:18:05 -0500407 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
408 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400409 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200410 break;
411 case 0:
412 break;
413 default:
Holger Schurig8ff12da2007-08-02 11:54:31 -0400414 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
David Woodhousef70dd452007-12-18 00:18:05 -0500415 i, pkey->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200416 ret = -1;
417 goto done;
418 break;
419 }
420 }
David Woodhousef70dd452007-12-18 00:18:05 -0500421 } else if (cmd_action == CMD_ACT_REMOVE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200422 /* ACT_REMOVE clears _all_ WEP keys */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200423
424 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500425 cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
426 CMD_WEP_KEY_INDEX_MASK);
David Woodhouseaa21c002007-12-08 20:04:36 +0000427 lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200428 }
429
David Woodhousef70dd452007-12-18 00:18:05 -0500430 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431done:
Holger Schurig9012b282007-05-25 11:27:16 -0400432 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200433 return ret;
434}
435
David Woodhouse4f59abf2007-12-18 00:47:17 -0500436int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
437 uint16_t *enable)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200438{
David Woodhouse4f59abf2007-12-18 00:47:17 -0500439 struct cmd_ds_802_11_enable_rsn cmd;
440 int ret;
Dan Williams90a42212007-05-25 23:01:24 -0400441
442 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200443
David Woodhouse4f59abf2007-12-18 00:47:17 -0500444 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
445 cmd.action = cpu_to_le16(cmd_action);
Dan Williams18c96c342007-06-18 12:01:12 -0400446
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200447 if (cmd_action == CMD_ACT_GET)
448 cmd.enable = 0;
449 else {
Dan Williams18c96c342007-06-18 12:01:12 -0400450 if (*enable)
David Woodhouse4f59abf2007-12-18 00:47:17 -0500451 cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
Dan Williams18c96c342007-06-18 12:01:12 -0400452 else
David Woodhouse4f59abf2007-12-18 00:47:17 -0500453 cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400454 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200455 }
456
David Woodhouse4f59abf2007-12-18 00:47:17 -0500457 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
458 if (!ret && cmd_action == CMD_ACT_GET)
459 *enable = le16_to_cpu(cmd.enable);
460
461 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
462 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200463}
464
David Woodhouse9e1228d2008-03-03 12:15:39 +0100465static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
466 struct enc_key *key)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200467{
Holger Schurig8ff12da2007-08-02 11:54:31 -0400468 lbs_deb_enter(LBS_DEB_CMD);
469
David Woodhouse9e1228d2008-03-03 12:15:39 +0100470 if (key->flags & KEY_INFO_WPA_ENABLED)
471 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
472 if (key->flags & KEY_INFO_WPA_UNICAST)
473 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
474 if (key->flags & KEY_INFO_WPA_MCAST)
475 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476
David Woodhouse9e1228d2008-03-03 12:15:39 +0100477 keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
478 keyparam->keytypeid = cpu_to_le16(key->type);
479 keyparam->keylen = cpu_to_le16(key->len);
480 memcpy(keyparam->key, key->key, key->len);
481
482 /* Length field doesn't include the {type,length} header */
483 keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400484 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200485}
486
David Woodhouse9e1228d2008-03-03 12:15:39 +0100487int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
488 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489{
David Woodhouse9e1228d2008-03-03 12:15:39 +0100490 struct cmd_ds_802_11_key_material cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200491 int ret = 0;
492 int index = 0;
493
Holger Schurig9012b282007-05-25 11:27:16 -0400494 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200495
David Woodhouse9e1228d2008-03-03 12:15:39 +0100496 cmd.action = cpu_to_le16(cmd_action);
497 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200498
Dan Williams0aef64d2007-08-02 11:31:18 -0400499 if (cmd_action == CMD_ACT_GET) {
David Woodhouse9e1228d2008-03-03 12:15:39 +0100500 cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
501 } else {
502 memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
503
504 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
505 set_one_wpa_key(&cmd.keyParamSet[index],
506 &assoc->wpa_unicast_key);
507 index++;
508 }
509
510 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
511 set_one_wpa_key(&cmd.keyParamSet[index],
512 &assoc->wpa_mcast_key);
513 index++;
514 }
515
516 /* The common header and as many keys as we included */
517 cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
518 keyParamSet[index]));
519 }
520 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
521 /* Copy the returned key to driver private data */
522 if (!ret && cmd_action == CMD_ACT_GET) {
523 void *buf_ptr = cmd.keyParamSet;
524 void *resp_end = &(&cmd)[1];
525
526 while (buf_ptr < resp_end) {
527 struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
528 struct enc_key *key;
529 uint16_t param_set_len = le16_to_cpu(keyparam->length);
530 uint16_t key_len = le16_to_cpu(keyparam->keylen);
531 uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
532 uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
533 void *end;
534
535 end = (void *)keyparam + sizeof(keyparam->type)
536 + sizeof(keyparam->length) + param_set_len;
537
538 /* Make sure we don't access past the end of the IEs */
539 if (end > resp_end)
540 break;
541
542 if (key_flags & KEY_INFO_WPA_UNICAST)
543 key = &priv->wpa_unicast_key;
544 else if (key_flags & KEY_INFO_WPA_MCAST)
545 key = &priv->wpa_mcast_key;
546 else
547 break;
548
549 /* Copy returned key into driver */
550 memset(key, 0, sizeof(struct enc_key));
551 if (key_len > sizeof(key->key))
552 break;
553 key->type = key_type;
554 key->flags = key_flags;
555 key->len = key_len;
556 memcpy(key->key, keyparam->key, key->len);
557
558 buf_ptr = end + 1;
559 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200560 }
561
Holger Schurig9012b282007-05-25 11:27:16 -0400562 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200563 return ret;
564}
565
Dan Williams39fcf7a2008-09-10 12:49:00 -0400566/**
567 * @brief Set an SNMP MIB value
568 *
569 * @param priv A pointer to struct lbs_private structure
570 * @param oid The OID to set in the firmware
571 * @param val Value to set the OID to
572 *
573 * @return 0 on success, error on failure
574 */
575int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200576{
Dan Williams39fcf7a2008-09-10 12:49:00 -0400577 struct cmd_ds_802_11_snmp_mib cmd;
578 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200579
Holger Schurig9012b282007-05-25 11:27:16 -0400580 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200581
Dan Williams39fcf7a2008-09-10 12:49:00 -0400582 memset(&cmd, 0, sizeof (cmd));
583 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
584 cmd.action = cpu_to_le16(CMD_ACT_SET);
585 cmd.oid = cpu_to_le16((u16) oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200586
Dan Williams39fcf7a2008-09-10 12:49:00 -0400587 switch (oid) {
588 case SNMP_MIB_OID_BSS_TYPE:
589 cmd.bufsize = cpu_to_le16(sizeof(u8));
590 cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200591 break;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400592 case SNMP_MIB_OID_11D_ENABLE:
593 case SNMP_MIB_OID_FRAG_THRESHOLD:
594 case SNMP_MIB_OID_RTS_THRESHOLD:
595 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
596 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
597 cmd.bufsize = cpu_to_le16(sizeof(u16));
598 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200599 break;
600 default:
Dan Williams39fcf7a2008-09-10 12:49:00 -0400601 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
602 ret = -EINVAL;
603 goto out;
604 }
605
606 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
607 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
608
609 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
610
611out:
612 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
613 return ret;
614}
615
616/**
617 * @brief Get an SNMP MIB value
618 *
619 * @param priv A pointer to struct lbs_private structure
620 * @param oid The OID to retrieve from the firmware
621 * @param out_val Location for the returned value
622 *
623 * @return 0 on success, error on failure
624 */
625int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
626{
627 struct cmd_ds_802_11_snmp_mib cmd;
628 int ret;
629
630 lbs_deb_enter(LBS_DEB_CMD);
631
632 memset(&cmd, 0, sizeof (cmd));
633 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
634 cmd.action = cpu_to_le16(CMD_ACT_GET);
635 cmd.oid = cpu_to_le16(oid);
636
637 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
638 if (ret)
639 goto out;
640
641 switch (le16_to_cpu(cmd.bufsize)) {
642 case sizeof(u8):
643 if (oid == SNMP_MIB_OID_BSS_TYPE) {
644 if (cmd.value[0] == 2)
645 *out_val = IW_MODE_ADHOC;
646 else
647 *out_val = IW_MODE_INFRA;
648 } else
649 *out_val = cmd.value[0];
650 break;
651 case sizeof(u16):
652 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
653 break;
654 default:
655 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
656 oid, le16_to_cpu(cmd.bufsize));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200657 break;
658 }
659
Dan Williams39fcf7a2008-09-10 12:49:00 -0400660out:
661 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
662 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200663}
664
Dan Williams87c8c722008-08-19 15:15:35 -0400665/**
666 * @brief Get the min, max, and current TX power
667 *
668 * @param priv A pointer to struct lbs_private structure
669 * @param curlevel Current power level in dBm
670 * @param minlevel Minimum supported power level in dBm (optional)
671 * @param maxlevel Maximum supported power level in dBm (optional)
672 *
673 * @return 0 on success, error on failure
674 */
675int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
676 s16 *maxlevel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200677{
Dan Williams87c8c722008-08-19 15:15:35 -0400678 struct cmd_ds_802_11_rf_tx_power cmd;
679 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200680
Holger Schurig9012b282007-05-25 11:27:16 -0400681 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200682
Dan Williams87c8c722008-08-19 15:15:35 -0400683 memset(&cmd, 0, sizeof(cmd));
684 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
685 cmd.action = cpu_to_le16(CMD_ACT_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200686
Dan Williams87c8c722008-08-19 15:15:35 -0400687 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
688 if (ret == 0) {
689 *curlevel = le16_to_cpu(cmd.curlevel);
690 if (minlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100691 *minlevel = cmd.minlevel;
Dan Williams87c8c722008-08-19 15:15:35 -0400692 if (maxlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100693 *maxlevel = cmd.maxlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200694 }
Holger Schurig9012b282007-05-25 11:27:16 -0400695
696 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams87c8c722008-08-19 15:15:35 -0400697 return ret;
698}
699
700/**
701 * @brief Set the TX power
702 *
703 * @param priv A pointer to struct lbs_private structure
704 * @param dbm The desired power level in dBm
705 *
706 * @return 0 on success, error on failure
707 */
708int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
709{
710 struct cmd_ds_802_11_rf_tx_power cmd;
711 int ret;
712
713 lbs_deb_enter(LBS_DEB_CMD);
714
715 memset(&cmd, 0, sizeof(cmd));
716 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
717 cmd.action = cpu_to_le16(CMD_ACT_SET);
718 cmd.curlevel = cpu_to_le16(dbm);
719
720 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
721
722 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
723
724 lbs_deb_leave(LBS_DEB_CMD);
725 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200726}
727
Holger Schurige98a88d2008-03-19 14:25:58 +0100728static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -0400729 u16 cmd_action, void *pdata_buf)
730{
731 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
732
733 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
734 cmd->size =
735 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
736 S_DS_GEN);
737
738 monitor->action = cpu_to_le16(cmd_action);
739 if (cmd_action == CMD_ACT_SET) {
740 monitor->mode =
741 cpu_to_le16((u16) (*(u32 *) pdata_buf));
742 }
743
744 return 0;
745}
746
Javier Cardona85319f92008-05-24 10:59:49 +0100747static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200748{
Javier Cardona85319f92008-05-24 10:59:49 +0100749/* Bit Rate
750* 15:13 Reserved
751* 12 54 Mbps
752* 11 48 Mbps
753* 10 36 Mbps
754* 9 24 Mbps
755* 8 18 Mbps
756* 7 12 Mbps
757* 6 9 Mbps
758* 5 6 Mbps
759* 4 Reserved
760* 3 11 Mbps
761* 2 5.5 Mbps
762* 1 2 Mbps
763* 0 1 Mbps
764**/
765
766 uint16_t ratemask;
767 int i = lbs_data_rate_to_fw_index(rate);
768 if (lower_rates_ok)
769 ratemask = (0x1fef >> (12 - i));
770 else
771 ratemask = (1 << i);
772 return cpu_to_le16(ratemask);
773}
774
775int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
776 uint16_t cmd_action)
777{
778 struct cmd_ds_802_11_rate_adapt_rateset cmd;
779 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200780
Holger Schurig8ff12da2007-08-02 11:54:31 -0400781 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200782
Javier Cardona85319f92008-05-24 10:59:49 +0100783 if (!priv->cur_rate && !priv->enablehwauto)
784 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200785
Javier Cardona85319f92008-05-24 10:59:49 +0100786 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
787
788 cmd.action = cpu_to_le16(cmd_action);
789 cmd.enablehwauto = cpu_to_le16(priv->enablehwauto);
790 cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto);
791 ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd);
792 if (!ret && cmd_action == CMD_ACT_GET) {
793 priv->ratebitmap = le16_to_cpu(cmd.bitmap);
794 priv->enablehwauto = le16_to_cpu(cmd.enablehwauto);
795 }
796
797 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
798 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200799}
Javier Cardona85319f92008-05-24 10:59:49 +0100800EXPORT_SYMBOL_GPL(lbs_cmd_802_11_rate_adapt_rateset);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200801
Dan Williams8e3c91b2007-12-11 15:50:59 -0500802/**
Dan Williams8e3c91b2007-12-11 15:50:59 -0500803 * @brief Set the data rate
804 *
805 * @param priv A pointer to struct lbs_private structure
806 * @param rate The desired data rate, or 0 to clear a locked rate
807 *
808 * @return 0 on success, error on failure
809 */
810int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
811{
812 struct cmd_ds_802_11_data_rate cmd;
813 int ret = 0;
814
815 lbs_deb_enter(LBS_DEB_CMD);
816
817 memset(&cmd, 0, sizeof(cmd));
818 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
819
820 if (rate > 0) {
821 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
822 cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
823 if (cmd.rates[0] == 0) {
824 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
825 " 0x%02X\n", rate);
826 ret = 0;
827 goto out;
828 }
829 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
830 } else {
831 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400832 lbs_deb_cmd("DATA_RATE: setting auto\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200833 }
834
David Woodhouse689442d2007-12-12 16:00:42 -0500835 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
Dan Williams8e3c91b2007-12-11 15:50:59 -0500836 if (ret)
837 goto out;
838
839 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
840
841 /* FIXME: get actual rates FW can do if this command actually returns
842 * all data rates supported.
843 */
844 priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
845 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
846
847out:
848 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
849 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200850}
851
Dan Williams2dd4b262007-12-11 16:54:15 -0500852/**
853 * @brief Get the radio channel
854 *
855 * @param priv A pointer to struct lbs_private structure
856 *
857 * @return The channel on success, error on failure
858 */
859int lbs_get_channel(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200860{
Dan Williams2dd4b262007-12-11 16:54:15 -0500861 struct cmd_ds_802_11_rf_channel cmd;
862 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200863
Holger Schurig8ff12da2007-08-02 11:54:31 -0400864 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200865
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200866 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500867 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
868 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200869
David Woodhouse689442d2007-12-12 16:00:42 -0500870 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500871 if (ret)
872 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200873
Dan Williamscb182a62007-12-11 17:35:51 -0500874 ret = le16_to_cpu(cmd.channel);
875 lbs_deb_cmd("current radio channel is %d\n", ret);
Dan Williams2dd4b262007-12-11 16:54:15 -0500876
877out:
878 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
879 return ret;
880}
881
Holger Schurig73ab1f22008-04-02 16:52:19 +0200882int lbs_update_channel(struct lbs_private *priv)
883{
884 int ret;
885
886 /* the channel in f/w could be out of sync; get the current channel */
887 lbs_deb_enter(LBS_DEB_ASSOC);
888
889 ret = lbs_get_channel(priv);
890 if (ret > 0) {
891 priv->curbssparams.channel = ret;
892 ret = 0;
893 }
894 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
895 return ret;
896}
897
Dan Williams2dd4b262007-12-11 16:54:15 -0500898/**
899 * @brief Set the radio channel
900 *
901 * @param priv A pointer to struct lbs_private structure
902 * @param channel The desired channel, or 0 to clear a locked channel
903 *
904 * @return 0 on success, error on failure
905 */
906int lbs_set_channel(struct lbs_private *priv, u8 channel)
907{
908 struct cmd_ds_802_11_rf_channel cmd;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530909#ifdef DEBUG
Dan Williams2dd4b262007-12-11 16:54:15 -0500910 u8 old_channel = priv->curbssparams.channel;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530911#endif
Dan Williams2dd4b262007-12-11 16:54:15 -0500912 int ret = 0;
913
914 lbs_deb_enter(LBS_DEB_CMD);
915
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200916 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500917 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
918 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
919 cmd.channel = cpu_to_le16(channel);
920
David Woodhouse689442d2007-12-12 16:00:42 -0500921 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500922 if (ret)
923 goto out;
924
Dan Williamscb182a62007-12-11 17:35:51 -0500925 priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
926 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
927 priv->curbssparams.channel);
Dan Williams2dd4b262007-12-11 16:54:15 -0500928
929out:
930 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
931 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200932}
933
Holger Schurig69f90322007-11-23 15:43:44 +0100934static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200935 struct cmd_ds_command *cmd)
936{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200937
Holger Schurig8ff12da2007-08-02 11:54:31 -0400938 lbs_deb_enter(LBS_DEB_CMD);
Dan Williams0aef64d2007-08-02 11:31:18 -0400939 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
David Woodhouse981f1872007-05-25 23:36:54 -0400940 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
Holger Schuriga783f1e2007-08-02 13:08:24 -0400941 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200942
943 /* reset Beacon SNR/NF/RSSI values */
David Woodhouseaa21c002007-12-08 20:04:36 +0000944 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
945 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
946 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
947 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
948 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
949 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200950
Holger Schurig8ff12da2007-08-02 11:54:31 -0400951 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200952 return 0;
953}
954
Holger Schurige98a88d2008-03-19 14:25:58 +0100955static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200956 u8 cmd_action, void *pdata_buf)
957{
Holger Schurig10078322007-11-15 18:05:47 -0500958 struct lbs_offset_value *offval;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200959
Holger Schurig9012b282007-05-25 11:27:16 -0400960 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200961
Holger Schurig10078322007-11-15 18:05:47 -0500962 offval = (struct lbs_offset_value *)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200963
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000964 switch (le16_to_cpu(cmdptr->command)) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400965 case CMD_MAC_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200966 {
967 struct cmd_ds_mac_reg_access *macreg;
968
969 cmdptr->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400970 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
971 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200972 macreg =
973 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
974 macreg;
975
976 macreg->action = cpu_to_le16(cmd_action);
977 macreg->offset = cpu_to_le16((u16) offval->offset);
978 macreg->value = cpu_to_le32(offval->value);
979
980 break;
981 }
982
Dan Williams0aef64d2007-08-02 11:31:18 -0400983 case CMD_BBP_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200984 {
985 struct cmd_ds_bbp_reg_access *bbpreg;
986
987 cmdptr->size =
988 cpu_to_le16(sizeof
989 (struct cmd_ds_bbp_reg_access)
990 + S_DS_GEN);
991 bbpreg =
992 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
993 bbpreg;
994
995 bbpreg->action = cpu_to_le16(cmd_action);
996 bbpreg->offset = cpu_to_le16((u16) offval->offset);
997 bbpreg->value = (u8) offval->value;
998
999 break;
1000 }
1001
Dan Williams0aef64d2007-08-02 11:31:18 -04001002 case CMD_RF_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001003 {
1004 struct cmd_ds_rf_reg_access *rfreg;
1005
1006 cmdptr->size =
1007 cpu_to_le16(sizeof
1008 (struct cmd_ds_rf_reg_access) +
1009 S_DS_GEN);
1010 rfreg =
1011 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
1012 rfreg;
1013
1014 rfreg->action = cpu_to_le16(cmd_action);
1015 rfreg->offset = cpu_to_le16((u16) offval->offset);
1016 rfreg->value = (u8) offval->value;
1017
1018 break;
1019 }
1020
1021 default:
1022 break;
1023 }
1024
Holger Schurig9012b282007-05-25 11:27:16 -04001025 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001026 return 0;
1027}
1028
Holger Schurige98a88d2008-03-19 14:25:58 +01001029static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001030 u16 cmd_action, void *pdata_buf)
1031{
1032 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
Holger Schurig8ff12da2007-08-02 11:54:31 -04001033 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001034
Dan Williams0aef64d2007-08-02 11:31:18 -04001035 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -04001036 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001037 cmd->result = 0;
1038 bt_access->action = cpu_to_le16(cmd_action);
1039
1040 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -04001041 case CMD_ACT_BT_ACCESS_ADD:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001042 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -04001043 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001044 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001045 case CMD_ACT_BT_ACCESS_DEL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001046 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -04001047 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001048 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001049 case CMD_ACT_BT_ACCESS_LIST:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001050 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
1051 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001052 case CMD_ACT_BT_ACCESS_RESET:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001053 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001054 case CMD_ACT_BT_ACCESS_SET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -04001055 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
1056 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001057 case CMD_ACT_BT_ACCESS_GET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -04001058 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001059 default:
1060 break;
1061 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001062 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001063 return 0;
1064}
1065
Holger Schurige98a88d2008-03-19 14:25:58 +01001066static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001067 u16 cmd_action, void *pdata_buf)
1068{
1069 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
Holger Schurig8ff12da2007-08-02 11:54:31 -04001070 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001071
Dan Williams0aef64d2007-08-02 11:31:18 -04001072 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -04001073 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074 cmd->result = 0;
1075
1076 if (pdata_buf)
1077 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
1078 else
1079 memset(fwt_access, 0, sizeof(*fwt_access));
1080
1081 fwt_access->action = cpu_to_le16(cmd_action);
1082
Holger Schurig8ff12da2007-08-02 11:54:31 -04001083 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001084 return 0;
1085}
1086
David Woodhouse301eacb2007-12-11 15:23:59 -05001087int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
1088 struct cmd_ds_mesh_access *cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001089{
David Woodhouse301eacb2007-12-11 15:23:59 -05001090 int ret;
1091
Holger Schurig8ff12da2007-08-02 11:54:31 -04001092 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001093
David Woodhouse301eacb2007-12-11 15:23:59 -05001094 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
David Woodhouse9fae8992007-12-15 03:46:44 -05001095 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
David Woodhouse301eacb2007-12-11 15:23:59 -05001096 cmd->hdr.result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001097
David Woodhouse301eacb2007-12-11 15:23:59 -05001098 cmd->action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001099
David Woodhouse689442d2007-12-12 16:00:42 -05001100 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001101
Holger Schurig8ff12da2007-08-02 11:54:31 -04001102 lbs_deb_leave(LBS_DEB_CMD);
David Woodhouse301eacb2007-12-11 15:23:59 -05001103 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001104}
1105
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001106static int __lbs_mesh_config_send(struct lbs_private *priv,
1107 struct cmd_ds_mesh_config *cmd,
1108 uint16_t action, uint16_t type)
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001109{
1110 int ret;
Bing Zhao684d6b32009-03-25 09:51:16 -07001111 u16 command = CMD_MESH_CONFIG_OLD;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001112
1113 lbs_deb_enter(LBS_DEB_CMD);
1114
Bing Zhao684d6b32009-03-25 09:51:16 -07001115 /*
1116 * Command id is 0xac for v10 FW along with mesh interface
1117 * id in bits 14-13-12.
1118 */
1119 if (priv->mesh_fw_ver == MESH_FW_NEW)
1120 command = CMD_MESH_CONFIG |
1121 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
1122
1123 cmd->hdr.command = cpu_to_le16(command);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001124 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
1125 cmd->hdr.result = 0;
1126
1127 cmd->type = cpu_to_le16(type);
1128 cmd->action = cpu_to_le16(action);
1129
Bing Zhao684d6b32009-03-25 09:51:16 -07001130 ret = lbs_cmd_with_response(priv, command, cmd);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001131
1132 lbs_deb_leave(LBS_DEB_CMD);
1133 return ret;
1134}
1135
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001136int lbs_mesh_config_send(struct lbs_private *priv,
1137 struct cmd_ds_mesh_config *cmd,
1138 uint16_t action, uint16_t type)
1139{
1140 int ret;
1141
1142 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
1143 return -EOPNOTSUPP;
1144
1145 ret = __lbs_mesh_config_send(priv, cmd, action, type);
1146 return ret;
1147}
1148
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001149/* This function is the CMD_MESH_CONFIG legacy function. It only handles the
1150 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
1151 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
1152 * lbs_mesh_config_send.
1153 */
1154int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
David Woodhouse23a397a2007-12-11 18:56:42 -05001155{
1156 struct cmd_ds_mesh_config cmd;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001157 struct mrvl_meshie *ie;
John W. Linville9387b7c2008-09-30 20:59:05 -04001158 DECLARE_SSID_BUF(ssid);
David Woodhouse23a397a2007-12-11 18:56:42 -05001159
1160 memset(&cmd, 0, sizeof(cmd));
David Woodhouse86062132007-12-13 00:32:36 -05001161 cmd.channel = cpu_to_le16(chan);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001162 ie = (struct mrvl_meshie *)cmd.data;
David Woodhouse7e226272007-12-14 22:53:41 -05001163
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001164 switch (action) {
1165 case CMD_ACT_MESH_CONFIG_START:
Johannes Berg2c7060022008-10-30 22:09:54 +01001166 ie->id = WLAN_EID_GENERIC;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001167 ie->val.oui[0] = 0x00;
1168 ie->val.oui[1] = 0x50;
1169 ie->val.oui[2] = 0x43;
1170 ie->val.type = MARVELL_MESH_IE_TYPE;
1171 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
1172 ie->val.version = MARVELL_MESH_IE_VERSION;
1173 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
1174 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
1175 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
1176 ie->val.mesh_id_len = priv->mesh_ssid_len;
1177 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
Johannes Berg2c7060022008-10-30 22:09:54 +01001178 ie->len = sizeof(struct mrvl_meshie_val) -
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001179 IW_ESSID_MAX_SIZE + priv->mesh_ssid_len;
1180 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
1181 break;
1182 case CMD_ACT_MESH_CONFIG_STOP:
1183 break;
1184 default:
1185 return -1;
David Woodhouse23a397a2007-12-11 18:56:42 -05001186 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001187 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
1188 action, priv->mesh_tlv, chan,
John W. Linville9387b7c2008-09-30 20:59:05 -04001189 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001190
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001191 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
David Woodhouse23a397a2007-12-11 18:56:42 -05001192}
1193
Brajesh Dave96287ac2007-11-20 17:44:28 -05001194static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
1195 struct cmd_ds_command *cmd,
1196 u16 cmd_action)
1197{
1198 struct cmd_ds_802_11_beacon_control
1199 *bcn_ctrl = &cmd->params.bcn_ctrl;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001200
1201 lbs_deb_enter(LBS_DEB_CMD);
1202 cmd->size =
1203 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
1204 + S_DS_GEN);
1205 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
1206
1207 bcn_ctrl->action = cpu_to_le16(cmd_action);
David Woodhouseaa21c002007-12-08 20:04:36 +00001208 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
1209 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
Brajesh Dave96287ac2007-11-20 17:44:28 -05001210
1211 lbs_deb_leave(LBS_DEB_CMD);
1212 return 0;
1213}
1214
David Woodhouse681ffbb2007-12-15 20:04:54 -05001215static void lbs_queue_cmd(struct lbs_private *priv,
1216 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001217{
1218 unsigned long flags;
David Woodhouse681ffbb2007-12-15 20:04:54 -05001219 int addtail = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001220
Holger Schurig8ff12da2007-08-02 11:54:31 -04001221 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001222
David Woodhousec4ab4122007-12-15 00:41:51 -05001223 if (!cmdnode) {
1224 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001225 goto done;
1226 }
David Woodhoused9896ee2007-12-15 00:09:25 -05001227 if (!cmdnode->cmdbuf->size) {
1228 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
1229 goto done;
1230 }
David Woodhouseae125bf2007-12-15 04:22:52 -05001231 cmdnode->result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001232
1233 /* Exit_PS command needs to be queued in the header always. */
Dan Williamsddac4522007-12-11 13:49:39 -05001234 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
David Woodhouse38bfab12007-12-16 23:26:54 -05001235 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
Dan Williamsddac4522007-12-11 13:49:39 -05001236
Dan Williams0aef64d2007-08-02 11:31:18 -04001237 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001238 if (priv->psstate != PS_STATE_FULL_POWER)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001239 addtail = 0;
1240 }
1241 }
1242
David Woodhouseaa21c002007-12-08 20:04:36 +00001243 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001244
David Woodhouseac472462007-12-08 00:35:00 +00001245 if (addtail)
David Woodhouseaa21c002007-12-08 20:04:36 +00001246 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
David Woodhouseac472462007-12-08 00:35:00 +00001247 else
David Woodhouseaa21c002007-12-08 20:04:36 +00001248 list_add(&cmdnode->list, &priv->cmdpendingq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001249
David Woodhouseaa21c002007-12-08 20:04:36 +00001250 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001251
Holger Schurig8ff12da2007-08-02 11:54:31 -04001252 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
David Woodhousec4ab4122007-12-15 00:41:51 -05001253 le16_to_cpu(cmdnode->cmdbuf->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001254
1255done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001256 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001257}
1258
David Woodhouse18c52e72007-12-17 16:03:58 -05001259static void lbs_submit_command(struct lbs_private *priv,
1260 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001261{
1262 unsigned long flags;
Dan Williamsddac4522007-12-11 13:49:39 -05001263 struct cmd_header *cmd;
David Woodhouse18c52e72007-12-17 16:03:58 -05001264 uint16_t cmdsize;
1265 uint16_t command;
Holger Schurig57962f02008-05-14 16:30:28 +02001266 int timeo = 3 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -05001267 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001268
Holger Schurig8ff12da2007-08-02 11:54:31 -04001269 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001270
Dan Williamsddac4522007-12-11 13:49:39 -05001271 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001272
David Woodhouseaa21c002007-12-08 20:04:36 +00001273 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001274 priv->cur_cmd = cmdnode;
1275 priv->cur_cmd_retcode = 0;
1276 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001277
Dan Williamsddac4522007-12-11 13:49:39 -05001278 cmdsize = le16_to_cpu(cmd->size);
1279 command = le16_to_cpu(cmd->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001280
David Woodhouse18c52e72007-12-17 16:03:58 -05001281 /* These commands take longer */
Dan Williamsbe0d76e2009-05-22 20:05:25 -04001282 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
Holger Schurig57962f02008-05-14 16:30:28 +02001283 timeo = 5 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -05001284
Holger Schurige5225b32008-03-26 10:04:44 +01001285 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
1286 command, le16_to_cpu(cmd->seqnum), cmdsize);
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001287 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001288
Dan Williamsddac4522007-12-11 13:49:39 -05001289 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
David Woodhouse18c52e72007-12-17 16:03:58 -05001290
David Woodhoused9896ee2007-12-15 00:09:25 -05001291 if (ret) {
1292 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
David Woodhouse18c52e72007-12-17 16:03:58 -05001293 /* Let the timer kick in and retry, and potentially reset
1294 the whole thing if the condition persists */
Holger Schurig57962f02008-05-14 16:30:28 +02001295 timeo = HZ/4;
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001296 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001297
Amitkumar Karwar49125452009-09-30 20:04:38 -07001298 if (command == CMD_802_11_DEEP_SLEEP) {
1299 if (priv->is_auto_deep_sleep_enabled) {
1300 priv->wakeup_dev_required = 1;
1301 priv->dnld_sent = 0;
1302 }
1303 priv->is_deep_sleep = 1;
1304 lbs_complete_command(priv, cmdnode, 0);
1305 } else {
1306 /* Setup the timer after transmit command */
1307 mod_timer(&priv->command_timer, jiffies + timeo);
1308 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001309
David Woodhouse18c52e72007-12-17 16:03:58 -05001310 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001311}
1312
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001313/**
1314 * This function inserts command node to cmdfreeq
David Woodhouseaa21c002007-12-08 20:04:36 +00001315 * after cleans it. Requires priv->driver_lock held.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001316 */
David Woodhouse183aeac2007-12-15 01:52:54 -05001317static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001318 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001319{
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001320 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001321
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001322 if (!cmdnode)
1323 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001324
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001325 cmdnode->callback = NULL;
1326 cmdnode->callback_arg = 0;
1327
1328 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
1329
1330 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
1331 out:
1332 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001333}
1334
Holger Schurig69f90322007-11-23 15:43:44 +01001335static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1336 struct cmd_ctrl_node *ptempcmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001337{
1338 unsigned long flags;
1339
David Woodhouseaa21c002007-12-08 20:04:36 +00001340 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig10078322007-11-15 18:05:47 -05001341 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
David Woodhouseaa21c002007-12-08 20:04:36 +00001342 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001343}
1344
David Woodhouse183aeac2007-12-15 01:52:54 -05001345void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1346 int result)
1347{
1348 if (cmd == priv->cur_cmd)
1349 priv->cur_cmd_retcode = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001350
David Woodhouseae125bf2007-12-15 04:22:52 -05001351 cmd->result = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001352 cmd->cmdwaitqwoken = 1;
1353 wake_up_interruptible(&cmd->cmdwait_q);
1354
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001355 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
David Woodhousead12d0f2007-12-15 02:06:16 -05001356 __lbs_cleanup_and_insert_cmd(priv, cmd);
David Woodhouse183aeac2007-12-15 01:52:54 -05001357 priv->cur_cmd = NULL;
1358}
1359
Dan Williamsd5db2df2008-08-21 17:51:07 -04001360int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001361{
David Woodhousea7c45892007-12-17 22:43:48 -05001362 struct cmd_ds_802_11_radio_control cmd;
Dan Williamsd5db2df2008-08-21 17:51:07 -04001363 int ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001364
Holger Schurig9012b282007-05-25 11:27:16 -04001365 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001366
David Woodhousea7c45892007-12-17 22:43:48 -05001367 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1368 cmd.action = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001369
Dan Williamsd5db2df2008-08-21 17:51:07 -04001370 /* Only v8 and below support setting the preamble */
1371 if (priv->fwrelease < 0x09000000) {
1372 switch (preamble) {
1373 case RADIO_PREAMBLE_SHORT:
1374 if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
1375 goto out;
1376 /* Fall through */
1377 case RADIO_PREAMBLE_AUTO:
1378 case RADIO_PREAMBLE_LONG:
1379 cmd.control = cpu_to_le16(preamble);
1380 break;
1381 default:
1382 goto out;
1383 }
David Woodhousea7c45892007-12-17 22:43:48 -05001384 }
1385
Dan Williamsd5db2df2008-08-21 17:51:07 -04001386 if (radio_on)
1387 cmd.control |= cpu_to_le16(0x1);
1388 else {
1389 cmd.control &= cpu_to_le16(~0x1);
1390 priv->txpower_cur = 0;
1391 }
David Woodhousea7c45892007-12-17 22:43:48 -05001392
Dan Williamsd5db2df2008-08-21 17:51:07 -04001393 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1394 radio_on ? "ON" : "OFF", preamble);
1395
1396 priv->radio_on = radio_on;
David Woodhousea7c45892007-12-17 22:43:48 -05001397
1398 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001399
Dan Williamsd5db2df2008-08-21 17:51:07 -04001400out:
Holger Schurig9012b282007-05-25 11:27:16 -04001401 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001402 return ret;
1403}
1404
Holger Schurigc97329e2008-03-18 11:20:21 +01001405void lbs_set_mac_control(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001406{
Holger Schurig835d3ac2008-03-12 16:05:40 +01001407 struct cmd_ds_mac_control cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001408
Holger Schurig9012b282007-05-25 11:27:16 -04001409 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001410
Holger Schurig835d3ac2008-03-12 16:05:40 +01001411 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Holger Schurigd9e97782008-03-12 16:06:43 +01001412 cmd.action = cpu_to_le16(priv->mac_control);
Holger Schurig835d3ac2008-03-12 16:05:40 +01001413 cmd.reserved = 0;
1414
David Woodhouse75bf45a2008-05-20 13:32:45 +01001415 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001416
Holger Schurigc97329e2008-03-18 11:20:21 +01001417 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001418}
1419
1420/**
1421 * @brief This function prepare the command before send to firmware.
1422 *
Holger Schurig69f90322007-11-23 15:43:44 +01001423 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001424 * @param cmd_no command number
1425 * @param cmd_action command action: GET or SET
1426 * @param wait_option wait option: wait response or not
1427 * @param cmd_oid cmd oid: treated as sub command
1428 * @param pdata_buf A pointer to informaion buffer
1429 * @return 0 or -1
1430 */
Holger Schurig69f90322007-11-23 15:43:44 +01001431int lbs_prepare_and_send_command(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001432 u16 cmd_no,
1433 u16 cmd_action,
1434 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1435{
1436 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001437 struct cmd_ctrl_node *cmdnode;
1438 struct cmd_ds_command *cmdptr;
1439 unsigned long flags;
1440
Holger Schurig8ff12da2007-08-02 11:54:31 -04001441 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001442
David Woodhouseaa21c002007-12-08 20:04:36 +00001443 if (!priv) {
1444 lbs_deb_host("PREP_CMD: priv is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001445 ret = -1;
1446 goto done;
1447 }
1448
David Woodhouseaa21c002007-12-08 20:04:36 +00001449 if (priv->surpriseremoved) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001450 lbs_deb_host("PREP_CMD: card removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001451 ret = -1;
1452 goto done;
1453 }
1454
Holger Schurig0d61d042007-12-05 17:58:06 +01001455 cmdnode = lbs_get_cmd_ctrl_node(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001456
1457 if (cmdnode == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001458 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001459
1460 /* Wake up main thread to execute next command */
Dan Williamsfe336152007-08-02 11:32:25 -04001461 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001462 ret = -1;
1463 goto done;
1464 }
1465
Holger Schurige98a88d2008-03-19 14:25:58 +01001466 cmdnode->callback = NULL;
1467 cmdnode->callback_arg = (unsigned long)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001468
Dan Williamsddac4522007-12-11 13:49:39 -05001469 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001470
Holger Schurig8ff12da2007-08-02 11:54:31 -04001471 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001472
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001473 /* Set sequence number, command and INT option */
David Woodhouseaa21c002007-12-08 20:04:36 +00001474 priv->seqnum++;
1475 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001476
David Woodhouse981f1872007-05-25 23:36:54 -04001477 cmdptr->command = cpu_to_le16(cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001478 cmdptr->result = 0;
1479
1480 switch (cmd_no) {
Dan Williams0aef64d2007-08-02 11:31:18 -04001481 case CMD_802_11_PS_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001482 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001483 break;
1484
Dan Williams0aef64d2007-08-02 11:31:18 -04001485 case CMD_MAC_REG_ACCESS:
1486 case CMD_BBP_REG_ACCESS:
1487 case CMD_RF_REG_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001488 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001489 break;
1490
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001491 case CMD_802_11_MONITOR_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001492 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001493 cmd_action, pdata_buf);
1494 break;
1495
Dan Williams0aef64d2007-08-02 11:31:18 -04001496 case CMD_802_11_RSSI:
Holger Schurig10078322007-11-15 18:05:47 -05001497 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001498 break;
1499
Dan Williams0aef64d2007-08-02 11:31:18 -04001500 case CMD_802_11_SET_AFC:
1501 case CMD_802_11_GET_AFC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001502
1503 cmdptr->command = cpu_to_le16(cmd_no);
David Woodhouse981f1872007-05-25 23:36:54 -04001504 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1505 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001506
1507 memmove(&cmdptr->params.afc,
1508 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1509
1510 ret = 0;
1511 goto done;
1512
Dan Williams0aef64d2007-08-02 11:31:18 -04001513 case CMD_802_11D_DOMAIN_INFO:
Holger Schurig10078322007-11-15 18:05:47 -05001514 ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001515 cmd_no, cmd_action);
1516 break;
1517
Dan Williams0aef64d2007-08-02 11:31:18 -04001518 case CMD_802_11_TPC_CFG:
1519 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001520 cmdptr->size =
1521 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1522 S_DS_GEN);
1523
1524 memmove(&cmdptr->params.tpccfg,
1525 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1526
1527 ret = 0;
1528 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001529 case CMD_802_11_LED_GPIO_CTRL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001530 {
Dan Williams75b6a612009-05-22 20:03:09 -04001531 struct mrvl_ie_ledgpio *gpio =
1532 (struct mrvl_ie_ledgpio*)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001533 cmdptr->params.ledgpio.data;
1534
1535 memmove(&cmdptr->params.ledgpio,
1536 pdata_buf,
1537 sizeof(struct cmd_ds_802_11_led_ctrl));
1538
1539 cmdptr->command =
Dan Williams0aef64d2007-08-02 11:31:18 -04001540 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001541
1542#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1543 cmdptr->size =
Holger Schurigc2df2ef2007-12-07 15:30:44 +00001544 cpu_to_le16(le16_to_cpu(gpio->header.len)
1545 + S_DS_GEN
1546 + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1547 gpio->header.len = gpio->header.len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001548
1549 ret = 0;
1550 break;
1551 }
David Woodhouse5844d122007-12-18 02:01:37 -05001552
Dan Williams0aef64d2007-08-02 11:31:18 -04001553 case CMD_BT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001554 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001555 break;
1556
Dan Williams0aef64d2007-08-02 11:31:18 -04001557 case CMD_FWT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001558 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001559 break;
1560
Dan Williams0aef64d2007-08-02 11:31:18 -04001561 case CMD_GET_TSF:
1562 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
David Woodhouse981f1872007-05-25 23:36:54 -04001563 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1564 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001565 ret = 0;
1566 break;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001567 case CMD_802_11_BEACON_CTRL:
1568 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1569 break;
Amitkumar Karwar49125452009-09-30 20:04:38 -07001570 case CMD_802_11_DEEP_SLEEP:
1571 cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP);
1572 cmdptr->size = cpu_to_le16(S_DS_GEN);
1573 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001574 default:
David Woodhousee37fc6e2008-05-20 11:47:16 +01001575 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001576 ret = -1;
1577 break;
1578 }
1579
1580 /* return error, since the command preparation failed */
1581 if (ret != 0) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001582 lbs_deb_host("PREP_CMD: command preparation failed\n");
Holger Schurig10078322007-11-15 18:05:47 -05001583 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001584 ret = -1;
1585 goto done;
1586 }
1587
1588 cmdnode->cmdwaitqwoken = 0;
1589
David Woodhouse681ffbb2007-12-15 20:04:54 -05001590 lbs_queue_cmd(priv, cmdnode);
Dan Williamsfe336152007-08-02 11:32:25 -04001591 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001592
Dan Williams0aef64d2007-08-02 11:31:18 -04001593 if (wait_option & CMD_OPTION_WAITFORRSP) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001594 lbs_deb_host("PREP_CMD: wait for response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001595 might_sleep();
1596 wait_event_interruptible(cmdnode->cmdwait_q,
1597 cmdnode->cmdwaitqwoken);
1598 }
1599
David Woodhouseaa21c002007-12-08 20:04:36 +00001600 spin_lock_irqsave(&priv->driver_lock, flags);
1601 if (priv->cur_cmd_retcode) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001602 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001603 priv->cur_cmd_retcode);
1604 priv->cur_cmd_retcode = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001605 ret = -1;
1606 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001607 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001608
1609done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001610 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001611 return ret;
1612}
1613
1614/**
1615 * @brief This function allocates the command buffer and link
1616 * it to command free queue.
1617 *
Holger Schurig69f90322007-11-23 15:43:44 +01001618 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001619 * @return 0 or -1
1620 */
Holger Schurig69f90322007-11-23 15:43:44 +01001621int lbs_allocate_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001622{
1623 int ret = 0;
Dan Williamsddac4522007-12-11 13:49:39 -05001624 u32 bufsize;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001625 u32 i;
Dan Williamsddac4522007-12-11 13:49:39 -05001626 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001627
Holger Schurig8ff12da2007-08-02 11:54:31 -04001628 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001629
Dan Williamsddac4522007-12-11 13:49:39 -05001630 /* Allocate and initialize the command array */
1631 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1632 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001633 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001634 ret = -1;
1635 goto done;
1636 }
Dan Williamsddac4522007-12-11 13:49:39 -05001637 priv->cmd_array = cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001638
Dan Williamsddac4522007-12-11 13:49:39 -05001639 /* Allocate and initialize each command buffer in the command array */
1640 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1641 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1642 if (!cmdarray[i].cmdbuf) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001643 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001644 ret = -1;
1645 goto done;
1646 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001647 }
1648
Dan Williamsddac4522007-12-11 13:49:39 -05001649 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1650 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1651 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001652 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001653 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001654
1655done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001656 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001657 return ret;
1658}
1659
1660/**
1661 * @brief This function frees the command buffer.
1662 *
Holger Schurig69f90322007-11-23 15:43:44 +01001663 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001664 * @return 0 or -1
1665 */
Holger Schurig69f90322007-11-23 15:43:44 +01001666int lbs_free_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001667{
Dan Williamsddac4522007-12-11 13:49:39 -05001668 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001669 unsigned int i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001670
Holger Schurig8ff12da2007-08-02 11:54:31 -04001671 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001672
1673 /* need to check if cmd array is allocated or not */
David Woodhouseaa21c002007-12-08 20:04:36 +00001674 if (priv->cmd_array == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001675 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001676 goto done;
1677 }
1678
Dan Williamsddac4522007-12-11 13:49:39 -05001679 cmdarray = priv->cmd_array;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001680
1681 /* Release shared memory buffers */
Dan Williamsddac4522007-12-11 13:49:39 -05001682 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1683 if (cmdarray[i].cmdbuf) {
1684 kfree(cmdarray[i].cmdbuf);
1685 cmdarray[i].cmdbuf = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001686 }
1687 }
1688
1689 /* Release cmd_ctrl_node */
David Woodhouseaa21c002007-12-08 20:04:36 +00001690 if (priv->cmd_array) {
1691 kfree(priv->cmd_array);
1692 priv->cmd_array = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001693 }
1694
1695done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001696 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001697 return 0;
1698}
1699
1700/**
1701 * @brief This function gets a free command node if available in
1702 * command free queue.
1703 *
Holger Schurig69f90322007-11-23 15:43:44 +01001704 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001705 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1706 */
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001707static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001708{
1709 struct cmd_ctrl_node *tempnode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001710 unsigned long flags;
1711
Holger Schurig8ff12da2007-08-02 11:54:31 -04001712 lbs_deb_enter(LBS_DEB_HOST);
1713
David Woodhouseaa21c002007-12-08 20:04:36 +00001714 if (!priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001715 return NULL;
1716
David Woodhouseaa21c002007-12-08 20:04:36 +00001717 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001718
David Woodhouseaa21c002007-12-08 20:04:36 +00001719 if (!list_empty(&priv->cmdfreeq)) {
1720 tempnode = list_first_entry(&priv->cmdfreeq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001721 struct cmd_ctrl_node, list);
1722 list_del(&tempnode->list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001723 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001724 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001725 tempnode = NULL;
1726 }
1727
David Woodhouseaa21c002007-12-08 20:04:36 +00001728 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001729
Holger Schurig8ff12da2007-08-02 11:54:31 -04001730 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001731 return tempnode;
1732}
1733
1734/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001735 * @brief This function executes next command in command
Nick Andrew877d0312009-01-26 11:06:57 +01001736 * pending queue. It will put firmware back to PS mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001737 * if applicable.
1738 *
Holger Schurig69f90322007-11-23 15:43:44 +01001739 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001740 * @return 0 or -1
1741 */
Holger Schurig69f90322007-11-23 15:43:44 +01001742int lbs_execute_next_command(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001743{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001744 struct cmd_ctrl_node *cmdnode = NULL;
Dan Williamsddac4522007-12-11 13:49:39 -05001745 struct cmd_header *cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001746 unsigned long flags;
1747 int ret = 0;
1748
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001749 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1750 * only caller to us is lbs_thread() and we get even when a
1751 * data packet is received */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001752 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001753
David Woodhouseaa21c002007-12-08 20:04:36 +00001754 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001755
David Woodhouseaa21c002007-12-08 20:04:36 +00001756 if (priv->cur_cmd) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001757 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001758 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001759 ret = -1;
1760 goto done;
1761 }
1762
David Woodhouseaa21c002007-12-08 20:04:36 +00001763 if (!list_empty(&priv->cmdpendingq)) {
1764 cmdnode = list_first_entry(&priv->cmdpendingq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001765 struct cmd_ctrl_node, list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001766 }
1767
David Woodhouseaa21c002007-12-08 20:04:36 +00001768 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001769
1770 if (cmdnode) {
Dan Williamsddac4522007-12-11 13:49:39 -05001771 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001772
Dan Williamsddac4522007-12-11 13:49:39 -05001773 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001774 if ((priv->psstate == PS_STATE_SLEEP) ||
1775 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001776 lbs_deb_host(
1777 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001778 le16_to_cpu(cmd->command),
David Woodhouseaa21c002007-12-08 20:04:36 +00001779 priv->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001780 ret = -1;
1781 goto done;
1782 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001783 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
Dan Williamsddac4522007-12-11 13:49:39 -05001784 "0x%04x in psstate %d\n",
1785 le16_to_cpu(cmd->command), priv->psstate);
David Woodhouseaa21c002007-12-08 20:04:36 +00001786 } else if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001787 /*
1788 * 1. Non-PS command:
1789 * Queue it. set needtowakeup to TRUE if current state
Holger Schurig10078322007-11-15 18:05:47 -05001790 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001791 * 2. PS command but not Exit_PS:
1792 * Ignore it.
1793 * 3. PS command Exit_PS:
1794 * Set needtowakeup to TRUE if current state is SLEEP,
1795 * otherwise send this command down to firmware
1796 * immediately.
1797 */
Dan Williamsddac4522007-12-11 13:49:39 -05001798 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001799 /* Prepare to send Exit PS,
1800 * this non PS command will be sent later */
David Woodhouseaa21c002007-12-08 20:04:36 +00001801 if ((priv->psstate == PS_STATE_SLEEP)
1802 || (priv->psstate == PS_STATE_PRE_SLEEP)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001803 ) {
1804 /* w/ new scheme, it will not reach here.
1805 since it is blocked in main_thread. */
David Woodhouseaa21c002007-12-08 20:04:36 +00001806 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001807 } else
Holger Schurig10078322007-11-15 18:05:47 -05001808 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001809
1810 ret = 0;
1811 goto done;
1812 } else {
1813 /*
1814 * PS command. Ignore it if it is not Exit_PS.
1815 * otherwise send it down immediately.
1816 */
David Woodhouse38bfab12007-12-16 23:26:54 -05001817 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001818
Holger Schurig8ff12da2007-08-02 11:54:31 -04001819 lbs_deb_host(
1820 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001821 psm->action);
1822 if (psm->action !=
Dan Williams0aef64d2007-08-02 11:31:18 -04001823 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001824 lbs_deb_host(
1825 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001826 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001827 spin_lock_irqsave(&priv->driver_lock, flags);
1828 lbs_complete_command(priv, cmdnode, 0);
1829 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001830
1831 ret = 0;
1832 goto done;
1833 }
1834
David Woodhouseaa21c002007-12-08 20:04:36 +00001835 if ((priv->psstate == PS_STATE_SLEEP) ||
1836 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001837 lbs_deb_host(
1838 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001839 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001840 spin_lock_irqsave(&priv->driver_lock, flags);
1841 lbs_complete_command(priv, cmdnode, 0);
1842 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001843 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001844
1845 ret = 0;
1846 goto done;
1847 }
1848
Holger Schurig8ff12da2007-08-02 11:54:31 -04001849 lbs_deb_host(
1850 "EXEC_NEXT_CMD: sending EXIT_PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001851 }
1852 }
Li Zefanabe3ed12007-12-06 13:01:21 +01001853 list_del(&cmdnode->list);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001854 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001855 le16_to_cpu(cmd->command));
David Woodhoused9896ee2007-12-15 00:09:25 -05001856 lbs_submit_command(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001857 } else {
1858 /*
1859 * check if in power save mode, if yes, put the device back
1860 * to PS mode
1861 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001862 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1863 (priv->psstate == PS_STATE_FULL_POWER) &&
1864 ((priv->connect_status == LBS_CONNECTED) ||
1865 (priv->mesh_connect_status == LBS_CONNECTED))) {
1866 if (priv->secinfo.WPAenabled ||
1867 priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001868 /* check for valid WPA group keys */
David Woodhouseaa21c002007-12-08 20:04:36 +00001869 if (priv->wpa_mcast_key.len ||
1870 priv->wpa_unicast_key.len) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001871 lbs_deb_host(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001872 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1873 " go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001874 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001875 }
1876 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001877 lbs_deb_host(
1878 "EXEC_NEXT_CMD: cmdpendingq empty, "
1879 "go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001880 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001881 }
1882 }
1883 }
1884
1885 ret = 0;
1886done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001887 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001888 return ret;
1889}
1890
Holger Schurig69f90322007-11-23 15:43:44 +01001891void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001892{
1893 union iwreq_data iwrq;
1894 u8 buf[50];
1895
Holger Schurig8ff12da2007-08-02 11:54:31 -04001896 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001897
1898 memset(&iwrq, 0, sizeof(union iwreq_data));
1899 memset(buf, 0, sizeof(buf));
1900
1901 snprintf(buf, sizeof(buf) - 1, "%s", str);
1902
1903 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1904
1905 /* Send Event to upper layer */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001906 lbs_deb_wext("event indication string %s\n", (char *)buf);
1907 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1908 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001909
Holger Schurig634b8f42007-05-25 13:05:16 -04001910 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001911
Holger Schurig8ff12da2007-08-02 11:54:31 -04001912 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001913}
1914
Holger Schurigf539f2e2008-03-26 13:22:11 +01001915static void lbs_send_confirmsleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001916{
1917 unsigned long flags;
Holger Schurigf539f2e2008-03-26 13:22:11 +01001918 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001919
Holger Schurig8ff12da2007-08-02 11:54:31 -04001920 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurigf539f2e2008-03-26 13:22:11 +01001921 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1922 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001923
Holger Schurigf539f2e2008-03-26 13:22:11 +01001924 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1925 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001926 if (ret) {
Holger Schurigf539f2e2008-03-26 13:22:11 +01001927 lbs_pr_alert("confirm_sleep failed\n");
Holger Schurig7919b892008-04-01 14:50:43 +02001928 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001929 }
Holger Schurig7919b892008-04-01 14:50:43 +02001930
1931 spin_lock_irqsave(&priv->driver_lock, flags);
1932
Holger Schuriga01f5452008-06-04 11:10:40 +02001933 /* We don't get a response on the sleep-confirmation */
1934 priv->dnld_sent = DNLD_RES_RECEIVED;
1935
Holger Schurig7919b892008-04-01 14:50:43 +02001936 /* If nothing to do, go back to sleep (?) */
1937 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1938 priv->psstate = PS_STATE_SLEEP;
1939
1940 spin_unlock_irqrestore(&priv->driver_lock, flags);
1941
1942out:
Holger Schurigf539f2e2008-03-26 13:22:11 +01001943 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001944}
1945
Holger Schurig69f90322007-11-23 15:43:44 +01001946void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001947{
Holger Schurig8ff12da2007-08-02 11:54:31 -04001948 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001949
1950 /*
1951 * PS is currently supported only in Infrastructure mode
1952 * Remove this check if it is to be supported in IBSS mode also
1953 */
1954
Holger Schurig10078322007-11-15 18:05:47 -05001955 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001956 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001957
Holger Schurig8ff12da2007-08-02 11:54:31 -04001958 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001959}
1960
1961/**
Holger Schurig8ff12da2007-08-02 11:54:31 -04001962 * @brief This function sends Exit_PS command to firmware.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001963 *
Holger Schurig69f90322007-11-23 15:43:44 +01001964 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001965 * @param wait_option wait response or not
1966 * @return n/a
1967 */
Holger Schurig69f90322007-11-23 15:43:44 +01001968void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001969{
David Woodhouse981f1872007-05-25 23:36:54 -04001970 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001971
Holger Schurig8ff12da2007-08-02 11:54:31 -04001972 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001973
Holger Schurig10078322007-11-15 18:05:47 -05001974 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001975
Holger Schurig10078322007-11-15 18:05:47 -05001976 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001977 CMD_SUBCMD_EXIT_PS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001978 wait_option, 0, &Localpsmode);
1979
Holger Schurig8ff12da2007-08-02 11:54:31 -04001980 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001981}
1982
1983/**
1984 * @brief This function checks condition and prepares to
1985 * send sleep confirm command to firmware if ok.
1986 *
Holger Schurig69f90322007-11-23 15:43:44 +01001987 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001988 * @param psmode Power Saving mode
1989 * @return n/a
1990 */
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001991void lbs_ps_confirm_sleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001992{
1993 unsigned long flags =0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001994 int allowed = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001995
Holger Schurig8ff12da2007-08-02 11:54:31 -04001996 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001997
Holger Schuriga01f5452008-06-04 11:10:40 +02001998 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig634b8f42007-05-25 13:05:16 -04001999 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002000 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05002001 lbs_deb_host("dnld_sent was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002002 }
2003
Holger Schurig7919b892008-04-01 14:50:43 +02002004 /* In-progress command? */
David Woodhouseaa21c002007-12-08 20:04:36 +00002005 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002006 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05002007 lbs_deb_host("cur_cmd was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002008 }
Holger Schurig7919b892008-04-01 14:50:43 +02002009
2010 /* Pending events or command responses? */
2011 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002012 allowed = 0;
Holger Schurig7919b892008-04-01 14:50:43 +02002013 lbs_deb_host("pending events or command responses\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002014 }
David Woodhouseaa21c002007-12-08 20:04:36 +00002015 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002016
2017 if (allowed) {
Holger Schurig10078322007-11-15 18:05:47 -05002018 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
Holger Schurigf539f2e2008-03-26 13:22:11 +01002019 lbs_send_confirmsleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002020 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04002021 lbs_deb_host("sleep confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002022 }
2023
Holger Schurig8ff12da2007-08-02 11:54:31 -04002024 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002025}
Holger Schurig675787e2007-12-05 17:58:11 +01002026
2027
Anna Neal0112c9e2008-09-11 11:17:25 -07002028/**
2029 * @brief Configures the transmission power control functionality.
2030 *
2031 * @param priv A pointer to struct lbs_private structure
2032 * @param enable Transmission power control enable
2033 * @param p0 Power level when link quality is good (dBm).
2034 * @param p1 Power level when link quality is fair (dBm).
2035 * @param p2 Power level when link quality is poor (dBm).
2036 * @param usesnr Use Signal to Noise Ratio in TPC
2037 *
2038 * @return 0 on success
2039 */
2040int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
2041 int8_t p2, int usesnr)
2042{
2043 struct cmd_ds_802_11_tpc_cfg cmd;
2044 int ret;
2045
2046 memset(&cmd, 0, sizeof(cmd));
2047 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
2048 cmd.action = cpu_to_le16(CMD_ACT_SET);
2049 cmd.enable = !!enable;
Anna Neal3ed6e082008-09-26 11:34:35 -04002050 cmd.usesnr = !!usesnr;
Anna Neal0112c9e2008-09-11 11:17:25 -07002051 cmd.P0 = p0;
2052 cmd.P1 = p1;
2053 cmd.P2 = p2;
2054
2055 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
2056
2057 return ret;
2058}
2059
2060/**
2061 * @brief Configures the power adaptation settings.
2062 *
2063 * @param priv A pointer to struct lbs_private structure
2064 * @param enable Power adaptation enable
2065 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
2066 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
2067 * @param p2 Power level for 48 and 54 Mbps (dBm).
2068 *
2069 * @return 0 on Success
2070 */
2071
2072int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
2073 int8_t p1, int8_t p2)
2074{
2075 struct cmd_ds_802_11_pa_cfg cmd;
2076 int ret;
2077
2078 memset(&cmd, 0, sizeof(cmd));
2079 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
2080 cmd.action = cpu_to_le16(CMD_ACT_SET);
2081 cmd.enable = !!enable;
2082 cmd.P0 = p0;
2083 cmd.P1 = p1;
2084 cmd.P2 = p2;
2085
2086 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
2087
2088 return ret;
2089}
2090
2091
Holger Schurig8db4a2b2008-03-19 10:11:00 +01002092static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
2093 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
2094 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
2095 unsigned long callback_arg)
Holger Schurig675787e2007-12-05 17:58:11 +01002096{
Holger Schurig675787e2007-12-05 17:58:11 +01002097 struct cmd_ctrl_node *cmdnode;
Holger Schurig675787e2007-12-05 17:58:11 +01002098
2099 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurig675787e2007-12-05 17:58:11 +01002100
David Woodhouseaa21c002007-12-08 20:04:36 +00002101 if (priv->surpriseremoved) {
Holger Schurig675787e2007-12-05 17:58:11 +01002102 lbs_deb_host("PREP_CMD: card removed\n");
David Woodhouse3399ea52007-12-15 03:09:33 -05002103 cmdnode = ERR_PTR(-ENOENT);
Holger Schurig675787e2007-12-05 17:58:11 +01002104 goto done;
2105 }
2106
2107 cmdnode = lbs_get_cmd_ctrl_node(priv);
Holger Schurig675787e2007-12-05 17:58:11 +01002108 if (cmdnode == NULL) {
2109 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
2110
2111 /* Wake up main thread to execute next command */
2112 wake_up_interruptible(&priv->waitq);
David Woodhouse3399ea52007-12-15 03:09:33 -05002113 cmdnode = ERR_PTR(-ENOBUFS);
Holger Schurig675787e2007-12-05 17:58:11 +01002114 goto done;
2115 }
2116
David Woodhouse448a51a2007-12-08 00:59:54 +00002117 cmdnode->callback = callback;
David Woodhouse1309b552007-12-10 13:36:10 -05002118 cmdnode->callback_arg = callback_arg;
Holger Schurig675787e2007-12-05 17:58:11 +01002119
Dan Williams7ad994d2007-12-11 12:33:30 -05002120 /* Copy the incoming command to the buffer */
Dan Williamsddac4522007-12-11 13:49:39 -05002121 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
Dan Williams7ad994d2007-12-11 12:33:30 -05002122
Holger Schurig675787e2007-12-05 17:58:11 +01002123 /* Set sequence number, clean result, move to buffer */
David Woodhouseaa21c002007-12-08 20:04:36 +00002124 priv->seqnum++;
Dan Williamsddac4522007-12-11 13:49:39 -05002125 cmdnode->cmdbuf->command = cpu_to_le16(command);
2126 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
2127 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
2128 cmdnode->cmdbuf->result = 0;
Holger Schurig675787e2007-12-05 17:58:11 +01002129
2130 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
2131
Holger Schurig675787e2007-12-05 17:58:11 +01002132 cmdnode->cmdwaitqwoken = 0;
David Woodhouse681ffbb2007-12-15 20:04:54 -05002133 lbs_queue_cmd(priv, cmdnode);
Holger Schurig675787e2007-12-05 17:58:11 +01002134 wake_up_interruptible(&priv->waitq);
2135
David Woodhouse3399ea52007-12-15 03:09:33 -05002136 done:
2137 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
2138 return cmdnode;
2139}
2140
Holger Schurig8db4a2b2008-03-19 10:11:00 +01002141void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
2142 struct cmd_header *in_cmd, int in_cmd_size)
2143{
2144 lbs_deb_enter(LBS_DEB_CMD);
2145 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2146 lbs_cmd_async_callback, 0);
2147 lbs_deb_leave(LBS_DEB_CMD);
2148}
2149
David Woodhouse3399ea52007-12-15 03:09:33 -05002150int __lbs_cmd(struct lbs_private *priv, uint16_t command,
2151 struct cmd_header *in_cmd, int in_cmd_size,
2152 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
2153 unsigned long callback_arg)
2154{
2155 struct cmd_ctrl_node *cmdnode;
2156 unsigned long flags;
2157 int ret = 0;
2158
2159 lbs_deb_enter(LBS_DEB_HOST);
2160
2161 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2162 callback, callback_arg);
2163 if (IS_ERR(cmdnode)) {
2164 ret = PTR_ERR(cmdnode);
2165 goto done;
2166 }
2167
Holger Schurig675787e2007-12-05 17:58:11 +01002168 might_sleep();
2169 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
2170
David Woodhouseaa21c002007-12-08 20:04:36 +00002171 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseae125bf2007-12-15 04:22:52 -05002172 ret = cmdnode->result;
2173 if (ret)
2174 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
2175 command, ret);
David Woodhouse3399ea52007-12-15 03:09:33 -05002176
David Woodhousead12d0f2007-12-15 02:06:16 -05002177 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
David Woodhouseaa21c002007-12-08 20:04:36 +00002178 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig675787e2007-12-05 17:58:11 +01002179
2180done:
2181 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
2182 return ret;
2183}
Dan Williams14e865b2007-12-10 15:11:23 -05002184EXPORT_SYMBOL_GPL(__lbs_cmd);
Holger Schurig675787e2007-12-05 17:58:11 +01002185
2186