blob: 685098148e10e137a2cf14d47d491fc7a4973975 [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
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020021/**
Holger Schurig8db4a2b2008-03-19 10:11:00 +010022 * @brief Simple callback that copies response back into command
23 *
24 * @param priv A pointer to struct lbs_private structure
25 * @param extra A pointer to the original command structure for which
26 * 'resp' is a response
27 * @param resp A pointer to the command response
28 *
29 * @return 0 on success, error on failure
30 */
31int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
32 struct cmd_header *resp)
33{
34 struct cmd_header *buf = (void *)extra;
35 uint16_t copy_len;
36
37 copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
38 memcpy(buf, resp, copy_len);
39 return 0;
40}
41EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
42
43/**
44 * @brief Simple callback that ignores the result. Use this if
45 * you just want to send a command to the hardware, but don't
46 * care for the result.
47 *
48 * @param priv ignored
49 * @param extra ignored
50 * @param resp ignored
51 *
52 * @return 0 for success
53 */
54static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
55 struct cmd_header *resp)
56{
57 return 0;
58}
59
60
61/**
Dan Williams852e1f22007-12-10 15:24:47 -050062 * @brief Checks whether a command is allowed in Power Save mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020063 *
64 * @param command the command ID
Dan Williams852e1f22007-12-10 15:24:47 -050065 * @return 1 if allowed, 0 if not allowed
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020066 */
Dan Williams852e1f22007-12-10 15:24:47 -050067static u8 is_command_allowed_in_ps(u16 cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020068{
Dan Williams852e1f22007-12-10 15:24:47 -050069 switch (cmd) {
70 case CMD_802_11_RSSI:
71 return 1;
72 default:
73 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075 return 0;
76}
77
Dan Williams6e66f032007-12-11 12:42:16 -050078/**
79 * @brief Updates the hardware details like MAC address and regulatory region
80 *
81 * @param priv A pointer to struct lbs_private structure
82 *
83 * @return 0 on success, error on failure
84 */
85int lbs_update_hw_spec(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020086{
Dan Williams6e66f032007-12-11 12:42:16 -050087 struct cmd_ds_get_hw_spec cmd;
88 int ret = -1;
89 u32 i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020090
Holger Schurig9012b282007-05-25 11:27:16 -040091 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020092
Dan Williams6e66f032007-12-11 12:42:16 -050093 memset(&cmd, 0, sizeof(cmd));
94 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
95 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
David Woodhouse689442d2007-12-12 16:00:42 -050096 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
Dan Williams6e66f032007-12-11 12:42:16 -050097 if (ret)
98 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020099
Dan Williams6e66f032007-12-11 12:42:16 -0500100 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500101
Holger Schurigdac10a92008-01-16 15:55:22 +0100102 /* The firmware release is in an interesting format: the patch
103 * level is in the most significant nibble ... so fix that: */
104 priv->fwrelease = le32_to_cpu(cmd.fwrelease);
105 priv->fwrelease = (priv->fwrelease << 8) |
106 (priv->fwrelease >> 24 & 0xff);
107
108 /* Some firmware capabilities:
109 * CF card firmware 5.0.16p0: cap 0x00000303
110 * USB dongle firmware 5.110.17p2: cap 0x00000303
111 */
Johannes Berge1749612008-10-27 15:59:26 -0700112 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
113 cmd.permanentaddr,
Holger Schurigdac10a92008-01-16 15:55:22 +0100114 priv->fwrelease >> 24 & 0xff,
115 priv->fwrelease >> 16 & 0xff,
116 priv->fwrelease >> 8 & 0xff,
117 priv->fwrelease & 0xff,
118 priv->fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500119 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
120 cmd.hwifversion, cmd.version);
121
Bing Zhao684d6b32009-03-25 09:51:16 -0700122 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
123 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
124 /* 5.110.22 have mesh command with 0xa3 command id */
125 /* 10.0.0.p0 FW brings in mesh config command with different id */
126 /* Check FW version MSB and initialize mesh_fw_ver */
127 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
128 priv->mesh_fw_ver = MESH_FW_OLD;
129 else if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
130 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK))
131 priv->mesh_fw_ver = MESH_FW_NEW;
132 else
133 priv->mesh_fw_ver = MESH_NONE;
134
Dan Williams6e66f032007-12-11 12:42:16 -0500135 /* Clamp region code to 8-bit since FW spec indicates that it should
136 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
137 * returns non-zero high 8 bits here.
Marek Vasut15483992009-07-16 19:19:53 +0200138 *
139 * Firmware version 4.0.102 used in CF8381 has region code shifted. We
140 * need to check for this problem and handle it properly.
Dan Williams6e66f032007-12-11 12:42:16 -0500141 */
Marek Vasut15483992009-07-16 19:19:53 +0200142 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4)
143 priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF;
144 else
145 priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
Dan Williams6e66f032007-12-11 12:42:16 -0500146
147 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
148 /* use the region code to search for the index */
149 if (priv->regioncode == lbs_region_code_to_index[i])
150 break;
151 }
152
153 /* if it's unidentified region code, use the default (USA) */
154 if (i >= MRVDRV_MAX_REGION_CODE) {
155 priv->regioncode = 0x10;
156 lbs_pr_info("unidentified region code; using the default (USA)\n");
157 }
158
159 if (priv->current_addr[0] == 0xff)
160 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
161
162 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
163 if (priv->mesh_dev)
164 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
165
166 if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
167 ret = -1;
168 goto out;
169 }
170
171 if (lbs_set_universaltable(priv, 0)) {
172 ret = -1;
173 goto out;
174 }
175
176out:
Holger Schurig9012b282007-05-25 11:27:16 -0400177 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams6e66f032007-12-11 12:42:16 -0500178 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200179}
180
Anna Neal582c1b52008-10-20 16:46:56 -0700181int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
182 struct wol_config *p_wol_config)
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500183{
184 struct cmd_ds_host_sleep cmd_config;
185 int ret;
186
David Woodhouse9fae8992007-12-15 03:46:44 -0500187 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500188 cmd_config.criteria = cpu_to_le32(criteria);
David Woodhouse506e9022007-12-12 20:06:06 -0500189 cmd_config.gpio = priv->wol_gpio;
190 cmd_config.gap = priv->wol_gap;
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500191
Anna Neal582c1b52008-10-20 16:46:56 -0700192 if (p_wol_config != NULL)
193 memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config,
194 sizeof(struct wol_config));
195 else
196 cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE;
197
David Woodhouse689442d2007-12-12 16:00:42 -0500198 ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
David Woodhouse506e9022007-12-12 20:06:06 -0500199 if (!ret) {
Anna Neal582c1b52008-10-20 16:46:56 -0700200 if (criteria) {
201 lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
202 priv->wol_criteria = criteria;
203 } else
204 memcpy((uint8_t *) p_wol_config,
205 (uint8_t *)&cmd_config.wol_conf,
206 sizeof(struct wol_config));
David Woodhouse506e9022007-12-12 20:06:06 -0500207 } else {
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500208 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500209 }
David Woodhouse506e9022007-12-12 20:06:06 -0500210
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500211 return ret;
212}
213EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
214
Holger Schurige98a88d2008-03-19 14:25:58 +0100215static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200216 u16 cmd_action)
217{
218 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200219
Holger Schurig9012b282007-05-25 11:27:16 -0400220 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200221
Dan Williams0aef64d2007-08-02 11:31:18 -0400222 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouse981f1872007-05-25 23:36:54 -0400223 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
224 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200225 psm->action = cpu_to_le16(cmd_action);
226 psm->multipledtim = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400227 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400228 case CMD_SUBCMD_ENTER_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400229 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200230
Holger Schurig252cf0d2007-08-02 13:09:34 -0400231 psm->locallisteninterval = 0;
Holger Schurig97605c32007-08-02 13:09:15 -0400232 psm->nullpktinterval = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200233 psm->multipledtim =
Holger Schurig56c46562007-08-02 13:09:49 -0400234 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200235 break;
236
Dan Williams0aef64d2007-08-02 11:31:18 -0400237 case CMD_SUBCMD_EXIT_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400238 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200239 break;
240
Dan Williams0aef64d2007-08-02 11:31:18 -0400241 case CMD_SUBCMD_SLEEP_CONFIRMED:
Holger Schurig9012b282007-05-25 11:27:16 -0400242 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200243 break;
244
245 default:
246 break;
247 }
248
Holger Schurig9012b282007-05-25 11:27:16 -0400249 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200250 return 0;
251}
252
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500253int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
254 uint16_t cmd_action, uint16_t *timeout)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200255{
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500256 struct cmd_ds_802_11_inactivity_timeout cmd;
257 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200258
Holger Schurig8ff12da2007-08-02 11:54:31 -0400259 lbs_deb_enter(LBS_DEB_CMD);
260
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500261 cmd.hdr.command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
262 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200263
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500264 cmd.action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500266 if (cmd_action == CMD_ACT_SET)
267 cmd.timeout = cpu_to_le16(*timeout);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200268 else
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500269 cmd.timeout = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200270
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500271 ret = lbs_cmd_with_response(priv, CMD_802_11_INACTIVITY_TIMEOUT, &cmd);
272
273 if (!ret)
274 *timeout = le16_to_cpu(cmd.timeout);
275
276 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200277 return 0;
278}
279
David Woodhouse3fbe1042007-12-17 23:48:31 -0500280int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
281 struct sleep_params *sp)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200282{
David Woodhouse3fbe1042007-12-17 23:48:31 -0500283 struct cmd_ds_802_11_sleep_params cmd;
284 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200285
Holger Schurig9012b282007-05-25 11:27:16 -0400286 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200287
Dan Williams0aef64d2007-08-02 11:31:18 -0400288 if (cmd_action == CMD_ACT_GET) {
David Woodhouse3fbe1042007-12-17 23:48:31 -0500289 memset(&cmd, 0, sizeof(cmd));
290 } else {
291 cmd.error = cpu_to_le16(sp->sp_error);
292 cmd.offset = cpu_to_le16(sp->sp_offset);
293 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
294 cmd.calcontrol = sp->sp_calcontrol;
295 cmd.externalsleepclk = sp->sp_extsleepclk;
296 cmd.reserved = cpu_to_le16(sp->sp_reserved);
297 }
298 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
299 cmd.action = cpu_to_le16(cmd_action);
300
301 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
302
303 if (!ret) {
304 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
305 "calcontrol 0x%x extsleepclk 0x%x\n",
306 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
307 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
308 cmd.externalsleepclk);
309
310 sp->sp_error = le16_to_cpu(cmd.error);
311 sp->sp_offset = le16_to_cpu(cmd.offset);
312 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
313 sp->sp_calcontrol = cmd.calcontrol;
314 sp->sp_extsleepclk = cmd.externalsleepclk;
315 sp->sp_reserved = le16_to_cpu(cmd.reserved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200316 }
317
David Woodhouse3fbe1042007-12-17 23:48:31 -0500318 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200319 return 0;
320}
321
David Woodhousef70dd452007-12-18 00:18:05 -0500322int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
323 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200324{
David Woodhousef70dd452007-12-18 00:18:05 -0500325 struct cmd_ds_802_11_set_wep cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200326 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200327
Holger Schurig9012b282007-05-25 11:27:16 -0400328 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200329
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200330 memset(&cmd, 0, sizeof(cmd));
David Woodhousef70dd452007-12-18 00:18:05 -0500331 cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
332 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200333
David Woodhousef70dd452007-12-18 00:18:05 -0500334 cmd.action = cpu_to_le16(cmd_action);
335
336 if (cmd_action == CMD_ACT_ADD) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200337 int i;
338
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200339 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500340 cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
341 CMD_WEP_KEY_INDEX_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200342
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200343 /* Copy key types and material to host command structure */
344 for (i = 0; i < 4; i++) {
David Woodhousef70dd452007-12-18 00:18:05 -0500345 struct enc_key *pkey = &assoc->wep_keys[i];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200346
347 switch (pkey->len) {
348 case KEY_LEN_WEP_40:
David Woodhousef70dd452007-12-18 00:18:05 -0500349 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
350 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400351 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200352 break;
353 case KEY_LEN_WEP_104:
David Woodhousef70dd452007-12-18 00:18:05 -0500354 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
355 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400356 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200357 break;
358 case 0:
359 break;
360 default:
Holger Schurig8ff12da2007-08-02 11:54:31 -0400361 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
David Woodhousef70dd452007-12-18 00:18:05 -0500362 i, pkey->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200363 ret = -1;
364 goto done;
365 break;
366 }
367 }
David Woodhousef70dd452007-12-18 00:18:05 -0500368 } else if (cmd_action == CMD_ACT_REMOVE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369 /* ACT_REMOVE clears _all_ WEP keys */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370
371 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500372 cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
373 CMD_WEP_KEY_INDEX_MASK);
David Woodhouseaa21c002007-12-08 20:04:36 +0000374 lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200375 }
376
David Woodhousef70dd452007-12-18 00:18:05 -0500377 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378done:
Holger Schurig9012b282007-05-25 11:27:16 -0400379 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200380 return ret;
381}
382
David Woodhouse4f59abf2007-12-18 00:47:17 -0500383int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
384 uint16_t *enable)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200385{
David Woodhouse4f59abf2007-12-18 00:47:17 -0500386 struct cmd_ds_802_11_enable_rsn cmd;
387 int ret;
Dan Williams90a42212007-05-25 23:01:24 -0400388
389 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200390
David Woodhouse4f59abf2007-12-18 00:47:17 -0500391 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
392 cmd.action = cpu_to_le16(cmd_action);
Dan Williams18c96c342007-06-18 12:01:12 -0400393
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200394 if (cmd_action == CMD_ACT_GET)
395 cmd.enable = 0;
396 else {
Dan Williams18c96c342007-06-18 12:01:12 -0400397 if (*enable)
David Woodhouse4f59abf2007-12-18 00:47:17 -0500398 cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
Dan Williams18c96c342007-06-18 12:01:12 -0400399 else
David Woodhouse4f59abf2007-12-18 00:47:17 -0500400 cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400401 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200402 }
403
David Woodhouse4f59abf2007-12-18 00:47:17 -0500404 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
405 if (!ret && cmd_action == CMD_ACT_GET)
406 *enable = le16_to_cpu(cmd.enable);
407
408 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
409 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200410}
411
David Woodhouse9e1228d2008-03-03 12:15:39 +0100412static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
413 struct enc_key *key)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200414{
Holger Schurig8ff12da2007-08-02 11:54:31 -0400415 lbs_deb_enter(LBS_DEB_CMD);
416
David Woodhouse9e1228d2008-03-03 12:15:39 +0100417 if (key->flags & KEY_INFO_WPA_ENABLED)
418 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
419 if (key->flags & KEY_INFO_WPA_UNICAST)
420 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
421 if (key->flags & KEY_INFO_WPA_MCAST)
422 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200423
David Woodhouse9e1228d2008-03-03 12:15:39 +0100424 keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
425 keyparam->keytypeid = cpu_to_le16(key->type);
426 keyparam->keylen = cpu_to_le16(key->len);
427 memcpy(keyparam->key, key->key, key->len);
428
429 /* Length field doesn't include the {type,length} header */
430 keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400431 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200432}
433
David Woodhouse9e1228d2008-03-03 12:15:39 +0100434int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
435 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200436{
David Woodhouse9e1228d2008-03-03 12:15:39 +0100437 struct cmd_ds_802_11_key_material cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200438 int ret = 0;
439 int index = 0;
440
Holger Schurig9012b282007-05-25 11:27:16 -0400441 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200442
David Woodhouse9e1228d2008-03-03 12:15:39 +0100443 cmd.action = cpu_to_le16(cmd_action);
444 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200445
Dan Williams0aef64d2007-08-02 11:31:18 -0400446 if (cmd_action == CMD_ACT_GET) {
David Woodhouse9e1228d2008-03-03 12:15:39 +0100447 cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
448 } else {
449 memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
450
451 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
452 set_one_wpa_key(&cmd.keyParamSet[index],
453 &assoc->wpa_unicast_key);
454 index++;
455 }
456
457 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
458 set_one_wpa_key(&cmd.keyParamSet[index],
459 &assoc->wpa_mcast_key);
460 index++;
461 }
462
463 /* The common header and as many keys as we included */
464 cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
465 keyParamSet[index]));
466 }
467 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
468 /* Copy the returned key to driver private data */
469 if (!ret && cmd_action == CMD_ACT_GET) {
470 void *buf_ptr = cmd.keyParamSet;
471 void *resp_end = &(&cmd)[1];
472
473 while (buf_ptr < resp_end) {
474 struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
475 struct enc_key *key;
476 uint16_t param_set_len = le16_to_cpu(keyparam->length);
477 uint16_t key_len = le16_to_cpu(keyparam->keylen);
478 uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
479 uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
480 void *end;
481
482 end = (void *)keyparam + sizeof(keyparam->type)
483 + sizeof(keyparam->length) + param_set_len;
484
485 /* Make sure we don't access past the end of the IEs */
486 if (end > resp_end)
487 break;
488
489 if (key_flags & KEY_INFO_WPA_UNICAST)
490 key = &priv->wpa_unicast_key;
491 else if (key_flags & KEY_INFO_WPA_MCAST)
492 key = &priv->wpa_mcast_key;
493 else
494 break;
495
496 /* Copy returned key into driver */
497 memset(key, 0, sizeof(struct enc_key));
498 if (key_len > sizeof(key->key))
499 break;
500 key->type = key_type;
501 key->flags = key_flags;
502 key->len = key_len;
503 memcpy(key->key, keyparam->key, key->len);
504
505 buf_ptr = end + 1;
506 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507 }
508
Holger Schurig9012b282007-05-25 11:27:16 -0400509 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200510 return ret;
511}
512
Dan Williams39fcf7a2008-09-10 12:49:00 -0400513/**
514 * @brief Set an SNMP MIB value
515 *
516 * @param priv A pointer to struct lbs_private structure
517 * @param oid The OID to set in the firmware
518 * @param val Value to set the OID to
519 *
520 * @return 0 on success, error on failure
521 */
522int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200523{
Dan Williams39fcf7a2008-09-10 12:49:00 -0400524 struct cmd_ds_802_11_snmp_mib cmd;
525 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200526
Holger Schurig9012b282007-05-25 11:27:16 -0400527 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200528
Dan Williams39fcf7a2008-09-10 12:49:00 -0400529 memset(&cmd, 0, sizeof (cmd));
530 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
531 cmd.action = cpu_to_le16(CMD_ACT_SET);
532 cmd.oid = cpu_to_le16((u16) oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200533
Dan Williams39fcf7a2008-09-10 12:49:00 -0400534 switch (oid) {
535 case SNMP_MIB_OID_BSS_TYPE:
536 cmd.bufsize = cpu_to_le16(sizeof(u8));
537 cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200538 break;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400539 case SNMP_MIB_OID_11D_ENABLE:
540 case SNMP_MIB_OID_FRAG_THRESHOLD:
541 case SNMP_MIB_OID_RTS_THRESHOLD:
542 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
543 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
544 cmd.bufsize = cpu_to_le16(sizeof(u16));
545 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200546 break;
547 default:
Dan Williams39fcf7a2008-09-10 12:49:00 -0400548 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
549 ret = -EINVAL;
550 goto out;
551 }
552
553 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
554 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
555
556 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
557
558out:
559 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
560 return ret;
561}
562
563/**
564 * @brief Get an SNMP MIB value
565 *
566 * @param priv A pointer to struct lbs_private structure
567 * @param oid The OID to retrieve from the firmware
568 * @param out_val Location for the returned value
569 *
570 * @return 0 on success, error on failure
571 */
572int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
573{
574 struct cmd_ds_802_11_snmp_mib cmd;
575 int ret;
576
577 lbs_deb_enter(LBS_DEB_CMD);
578
579 memset(&cmd, 0, sizeof (cmd));
580 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
581 cmd.action = cpu_to_le16(CMD_ACT_GET);
582 cmd.oid = cpu_to_le16(oid);
583
584 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
585 if (ret)
586 goto out;
587
588 switch (le16_to_cpu(cmd.bufsize)) {
589 case sizeof(u8):
590 if (oid == SNMP_MIB_OID_BSS_TYPE) {
591 if (cmd.value[0] == 2)
592 *out_val = IW_MODE_ADHOC;
593 else
594 *out_val = IW_MODE_INFRA;
595 } else
596 *out_val = cmd.value[0];
597 break;
598 case sizeof(u16):
599 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
600 break;
601 default:
602 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
603 oid, le16_to_cpu(cmd.bufsize));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604 break;
605 }
606
Dan Williams39fcf7a2008-09-10 12:49:00 -0400607out:
608 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
609 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610}
611
Dan Williams87c8c722008-08-19 15:15:35 -0400612/**
613 * @brief Get the min, max, and current TX power
614 *
615 * @param priv A pointer to struct lbs_private structure
616 * @param curlevel Current power level in dBm
617 * @param minlevel Minimum supported power level in dBm (optional)
618 * @param maxlevel Maximum supported power level in dBm (optional)
619 *
620 * @return 0 on success, error on failure
621 */
622int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
623 s16 *maxlevel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200624{
Dan Williams87c8c722008-08-19 15:15:35 -0400625 struct cmd_ds_802_11_rf_tx_power cmd;
626 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200627
Holger Schurig9012b282007-05-25 11:27:16 -0400628 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200629
Dan Williams87c8c722008-08-19 15:15:35 -0400630 memset(&cmd, 0, sizeof(cmd));
631 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
632 cmd.action = cpu_to_le16(CMD_ACT_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200633
Dan Williams87c8c722008-08-19 15:15:35 -0400634 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
635 if (ret == 0) {
636 *curlevel = le16_to_cpu(cmd.curlevel);
637 if (minlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100638 *minlevel = cmd.minlevel;
Dan Williams87c8c722008-08-19 15:15:35 -0400639 if (maxlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100640 *maxlevel = cmd.maxlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641 }
Holger Schurig9012b282007-05-25 11:27:16 -0400642
643 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams87c8c722008-08-19 15:15:35 -0400644 return ret;
645}
646
647/**
648 * @brief Set the TX power
649 *
650 * @param priv A pointer to struct lbs_private structure
651 * @param dbm The desired power level in dBm
652 *
653 * @return 0 on success, error on failure
654 */
655int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
656{
657 struct cmd_ds_802_11_rf_tx_power cmd;
658 int ret;
659
660 lbs_deb_enter(LBS_DEB_CMD);
661
662 memset(&cmd, 0, sizeof(cmd));
663 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
664 cmd.action = cpu_to_le16(CMD_ACT_SET);
665 cmd.curlevel = cpu_to_le16(dbm);
666
667 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
668
669 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
670
671 lbs_deb_leave(LBS_DEB_CMD);
672 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200673}
674
Holger Schurige98a88d2008-03-19 14:25:58 +0100675static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -0400676 u16 cmd_action, void *pdata_buf)
677{
678 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
679
680 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
681 cmd->size =
682 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
683 S_DS_GEN);
684
685 monitor->action = cpu_to_le16(cmd_action);
686 if (cmd_action == CMD_ACT_SET) {
687 monitor->mode =
688 cpu_to_le16((u16) (*(u32 *) pdata_buf));
689 }
690
691 return 0;
692}
693
Javier Cardona85319f92008-05-24 10:59:49 +0100694static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200695{
Javier Cardona85319f92008-05-24 10:59:49 +0100696/* Bit Rate
697* 15:13 Reserved
698* 12 54 Mbps
699* 11 48 Mbps
700* 10 36 Mbps
701* 9 24 Mbps
702* 8 18 Mbps
703* 7 12 Mbps
704* 6 9 Mbps
705* 5 6 Mbps
706* 4 Reserved
707* 3 11 Mbps
708* 2 5.5 Mbps
709* 1 2 Mbps
710* 0 1 Mbps
711**/
712
713 uint16_t ratemask;
714 int i = lbs_data_rate_to_fw_index(rate);
715 if (lower_rates_ok)
716 ratemask = (0x1fef >> (12 - i));
717 else
718 ratemask = (1 << i);
719 return cpu_to_le16(ratemask);
720}
721
722int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
723 uint16_t cmd_action)
724{
725 struct cmd_ds_802_11_rate_adapt_rateset cmd;
726 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200727
Holger Schurig8ff12da2007-08-02 11:54:31 -0400728 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200729
Javier Cardona85319f92008-05-24 10:59:49 +0100730 if (!priv->cur_rate && !priv->enablehwauto)
731 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200732
Javier Cardona85319f92008-05-24 10:59:49 +0100733 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
734
735 cmd.action = cpu_to_le16(cmd_action);
736 cmd.enablehwauto = cpu_to_le16(priv->enablehwauto);
737 cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto);
738 ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd);
739 if (!ret && cmd_action == CMD_ACT_GET) {
740 priv->ratebitmap = le16_to_cpu(cmd.bitmap);
741 priv->enablehwauto = le16_to_cpu(cmd.enablehwauto);
742 }
743
744 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
745 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200746}
Javier Cardona85319f92008-05-24 10:59:49 +0100747EXPORT_SYMBOL_GPL(lbs_cmd_802_11_rate_adapt_rateset);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200748
Dan Williams8e3c91b2007-12-11 15:50:59 -0500749/**
Dan Williams8e3c91b2007-12-11 15:50:59 -0500750 * @brief Set the data rate
751 *
752 * @param priv A pointer to struct lbs_private structure
753 * @param rate The desired data rate, or 0 to clear a locked rate
754 *
755 * @return 0 on success, error on failure
756 */
757int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
758{
759 struct cmd_ds_802_11_data_rate cmd;
760 int ret = 0;
761
762 lbs_deb_enter(LBS_DEB_CMD);
763
764 memset(&cmd, 0, sizeof(cmd));
765 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
766
767 if (rate > 0) {
768 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
769 cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
770 if (cmd.rates[0] == 0) {
771 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
772 " 0x%02X\n", rate);
773 ret = 0;
774 goto out;
775 }
776 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
777 } else {
778 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400779 lbs_deb_cmd("DATA_RATE: setting auto\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200780 }
781
David Woodhouse689442d2007-12-12 16:00:42 -0500782 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
Dan Williams8e3c91b2007-12-11 15:50:59 -0500783 if (ret)
784 goto out;
785
786 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
787
788 /* FIXME: get actual rates FW can do if this command actually returns
789 * all data rates supported.
790 */
791 priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
792 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
793
794out:
795 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
796 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200797}
798
Dan Williams2dd4b262007-12-11 16:54:15 -0500799/**
800 * @brief Get the radio channel
801 *
802 * @param priv A pointer to struct lbs_private structure
803 *
804 * @return The channel on success, error on failure
805 */
806int lbs_get_channel(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200807{
Dan Williams2dd4b262007-12-11 16:54:15 -0500808 struct cmd_ds_802_11_rf_channel cmd;
809 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200810
Holger Schurig8ff12da2007-08-02 11:54:31 -0400811 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200812
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200813 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500814 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
815 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200816
David Woodhouse689442d2007-12-12 16:00:42 -0500817 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500818 if (ret)
819 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820
Dan Williamscb182a62007-12-11 17:35:51 -0500821 ret = le16_to_cpu(cmd.channel);
822 lbs_deb_cmd("current radio channel is %d\n", ret);
Dan Williams2dd4b262007-12-11 16:54:15 -0500823
824out:
825 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
826 return ret;
827}
828
Holger Schurig73ab1f22008-04-02 16:52:19 +0200829int lbs_update_channel(struct lbs_private *priv)
830{
831 int ret;
832
833 /* the channel in f/w could be out of sync; get the current channel */
834 lbs_deb_enter(LBS_DEB_ASSOC);
835
836 ret = lbs_get_channel(priv);
837 if (ret > 0) {
838 priv->curbssparams.channel = ret;
839 ret = 0;
840 }
841 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
842 return ret;
843}
844
Dan Williams2dd4b262007-12-11 16:54:15 -0500845/**
846 * @brief Set the radio channel
847 *
848 * @param priv A pointer to struct lbs_private structure
849 * @param channel The desired channel, or 0 to clear a locked channel
850 *
851 * @return 0 on success, error on failure
852 */
853int lbs_set_channel(struct lbs_private *priv, u8 channel)
854{
855 struct cmd_ds_802_11_rf_channel cmd;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530856#ifdef DEBUG
Dan Williams2dd4b262007-12-11 16:54:15 -0500857 u8 old_channel = priv->curbssparams.channel;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530858#endif
Dan Williams2dd4b262007-12-11 16:54:15 -0500859 int ret = 0;
860
861 lbs_deb_enter(LBS_DEB_CMD);
862
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200863 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500864 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
865 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
866 cmd.channel = cpu_to_le16(channel);
867
David Woodhouse689442d2007-12-12 16:00:42 -0500868 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500869 if (ret)
870 goto out;
871
Dan Williamscb182a62007-12-11 17:35:51 -0500872 priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
873 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
874 priv->curbssparams.channel);
Dan Williams2dd4b262007-12-11 16:54:15 -0500875
876out:
877 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
878 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200879}
880
Holger Schurig69f90322007-11-23 15:43:44 +0100881static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200882 struct cmd_ds_command *cmd)
883{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200884
Holger Schurig8ff12da2007-08-02 11:54:31 -0400885 lbs_deb_enter(LBS_DEB_CMD);
Dan Williams0aef64d2007-08-02 11:31:18 -0400886 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
David Woodhouse981f1872007-05-25 23:36:54 -0400887 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
Holger Schuriga783f1e2007-08-02 13:08:24 -0400888 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200889
890 /* reset Beacon SNR/NF/RSSI values */
David Woodhouseaa21c002007-12-08 20:04:36 +0000891 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
892 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
893 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
894 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
895 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
896 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200897
Holger Schurig8ff12da2007-08-02 11:54:31 -0400898 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200899 return 0;
900}
901
Holger Schurige98a88d2008-03-19 14:25:58 +0100902static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200903 u8 cmd_action, void *pdata_buf)
904{
Holger Schurig10078322007-11-15 18:05:47 -0500905 struct lbs_offset_value *offval;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200906
Holger Schurig9012b282007-05-25 11:27:16 -0400907 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200908
Holger Schurig10078322007-11-15 18:05:47 -0500909 offval = (struct lbs_offset_value *)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200910
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000911 switch (le16_to_cpu(cmdptr->command)) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400912 case CMD_MAC_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200913 {
914 struct cmd_ds_mac_reg_access *macreg;
915
916 cmdptr->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400917 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
918 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200919 macreg =
920 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
921 macreg;
922
923 macreg->action = cpu_to_le16(cmd_action);
924 macreg->offset = cpu_to_le16((u16) offval->offset);
925 macreg->value = cpu_to_le32(offval->value);
926
927 break;
928 }
929
Dan Williams0aef64d2007-08-02 11:31:18 -0400930 case CMD_BBP_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200931 {
932 struct cmd_ds_bbp_reg_access *bbpreg;
933
934 cmdptr->size =
935 cpu_to_le16(sizeof
936 (struct cmd_ds_bbp_reg_access)
937 + S_DS_GEN);
938 bbpreg =
939 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
940 bbpreg;
941
942 bbpreg->action = cpu_to_le16(cmd_action);
943 bbpreg->offset = cpu_to_le16((u16) offval->offset);
944 bbpreg->value = (u8) offval->value;
945
946 break;
947 }
948
Dan Williams0aef64d2007-08-02 11:31:18 -0400949 case CMD_RF_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200950 {
951 struct cmd_ds_rf_reg_access *rfreg;
952
953 cmdptr->size =
954 cpu_to_le16(sizeof
955 (struct cmd_ds_rf_reg_access) +
956 S_DS_GEN);
957 rfreg =
958 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
959 rfreg;
960
961 rfreg->action = cpu_to_le16(cmd_action);
962 rfreg->offset = cpu_to_le16((u16) offval->offset);
963 rfreg->value = (u8) offval->value;
964
965 break;
966 }
967
968 default:
969 break;
970 }
971
Holger Schurig9012b282007-05-25 11:27:16 -0400972 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200973 return 0;
974}
975
Holger Schurige98a88d2008-03-19 14:25:58 +0100976static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200977 u16 cmd_action, void *pdata_buf)
978{
979 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400980 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200981
Dan Williams0aef64d2007-08-02 11:31:18 -0400982 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -0400983 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200984 cmd->result = 0;
985 bt_access->action = cpu_to_le16(cmd_action);
986
987 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400988 case CMD_ACT_BT_ACCESS_ADD:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200989 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400990 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200991 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400992 case CMD_ACT_BT_ACCESS_DEL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200993 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400994 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200995 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400996 case CMD_ACT_BT_ACCESS_LIST:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200997 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
998 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400999 case CMD_ACT_BT_ACCESS_RESET:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001000 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001001 case CMD_ACT_BT_ACCESS_SET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -04001002 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
1003 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001004 case CMD_ACT_BT_ACCESS_GET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -04001005 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001006 default:
1007 break;
1008 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001009 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001010 return 0;
1011}
1012
Holger Schurige98a88d2008-03-19 14:25:58 +01001013static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001014 u16 cmd_action, void *pdata_buf)
1015{
1016 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
Holger Schurig8ff12da2007-08-02 11:54:31 -04001017 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001018
Dan Williams0aef64d2007-08-02 11:31:18 -04001019 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -04001020 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001021 cmd->result = 0;
1022
1023 if (pdata_buf)
1024 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
1025 else
1026 memset(fwt_access, 0, sizeof(*fwt_access));
1027
1028 fwt_access->action = cpu_to_le16(cmd_action);
1029
Holger Schurig8ff12da2007-08-02 11:54:31 -04001030 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001031 return 0;
1032}
1033
David Woodhouse301eacb2007-12-11 15:23:59 -05001034int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
1035 struct cmd_ds_mesh_access *cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001036{
David Woodhouse301eacb2007-12-11 15:23:59 -05001037 int ret;
1038
Holger Schurig8ff12da2007-08-02 11:54:31 -04001039 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001040
David Woodhouse301eacb2007-12-11 15:23:59 -05001041 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
David Woodhouse9fae8992007-12-15 03:46:44 -05001042 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
David Woodhouse301eacb2007-12-11 15:23:59 -05001043 cmd->hdr.result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001044
David Woodhouse301eacb2007-12-11 15:23:59 -05001045 cmd->action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001046
David Woodhouse689442d2007-12-12 16:00:42 -05001047 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001048
Holger Schurig8ff12da2007-08-02 11:54:31 -04001049 lbs_deb_leave(LBS_DEB_CMD);
David Woodhouse301eacb2007-12-11 15:23:59 -05001050 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001051}
1052
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001053static int __lbs_mesh_config_send(struct lbs_private *priv,
1054 struct cmd_ds_mesh_config *cmd,
1055 uint16_t action, uint16_t type)
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001056{
1057 int ret;
Bing Zhao684d6b32009-03-25 09:51:16 -07001058 u16 command = CMD_MESH_CONFIG_OLD;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001059
1060 lbs_deb_enter(LBS_DEB_CMD);
1061
Bing Zhao684d6b32009-03-25 09:51:16 -07001062 /*
1063 * Command id is 0xac for v10 FW along with mesh interface
1064 * id in bits 14-13-12.
1065 */
1066 if (priv->mesh_fw_ver == MESH_FW_NEW)
1067 command = CMD_MESH_CONFIG |
1068 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
1069
1070 cmd->hdr.command = cpu_to_le16(command);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001071 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
1072 cmd->hdr.result = 0;
1073
1074 cmd->type = cpu_to_le16(type);
1075 cmd->action = cpu_to_le16(action);
1076
Bing Zhao684d6b32009-03-25 09:51:16 -07001077 ret = lbs_cmd_with_response(priv, command, cmd);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001078
1079 lbs_deb_leave(LBS_DEB_CMD);
1080 return ret;
1081}
1082
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001083int lbs_mesh_config_send(struct lbs_private *priv,
1084 struct cmd_ds_mesh_config *cmd,
1085 uint16_t action, uint16_t type)
1086{
1087 int ret;
1088
1089 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
1090 return -EOPNOTSUPP;
1091
1092 ret = __lbs_mesh_config_send(priv, cmd, action, type);
1093 return ret;
1094}
1095
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001096/* This function is the CMD_MESH_CONFIG legacy function. It only handles the
1097 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
1098 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
1099 * lbs_mesh_config_send.
1100 */
1101int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
David Woodhouse23a397a2007-12-11 18:56:42 -05001102{
1103 struct cmd_ds_mesh_config cmd;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001104 struct mrvl_meshie *ie;
John W. Linville9387b7c2008-09-30 20:59:05 -04001105 DECLARE_SSID_BUF(ssid);
David Woodhouse23a397a2007-12-11 18:56:42 -05001106
1107 memset(&cmd, 0, sizeof(cmd));
David Woodhouse86062132007-12-13 00:32:36 -05001108 cmd.channel = cpu_to_le16(chan);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001109 ie = (struct mrvl_meshie *)cmd.data;
David Woodhouse7e226272007-12-14 22:53:41 -05001110
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001111 switch (action) {
1112 case CMD_ACT_MESH_CONFIG_START:
Johannes Berg2c7060022008-10-30 22:09:54 +01001113 ie->id = WLAN_EID_GENERIC;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001114 ie->val.oui[0] = 0x00;
1115 ie->val.oui[1] = 0x50;
1116 ie->val.oui[2] = 0x43;
1117 ie->val.type = MARVELL_MESH_IE_TYPE;
1118 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
1119 ie->val.version = MARVELL_MESH_IE_VERSION;
1120 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
1121 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
1122 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
1123 ie->val.mesh_id_len = priv->mesh_ssid_len;
1124 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
Johannes Berg2c7060022008-10-30 22:09:54 +01001125 ie->len = sizeof(struct mrvl_meshie_val) -
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001126 IW_ESSID_MAX_SIZE + priv->mesh_ssid_len;
1127 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
1128 break;
1129 case CMD_ACT_MESH_CONFIG_STOP:
1130 break;
1131 default:
1132 return -1;
David Woodhouse23a397a2007-12-11 18:56:42 -05001133 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001134 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
1135 action, priv->mesh_tlv, chan,
John W. Linville9387b7c2008-09-30 20:59:05 -04001136 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001137
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001138 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
David Woodhouse23a397a2007-12-11 18:56:42 -05001139}
1140
Brajesh Dave96287ac2007-11-20 17:44:28 -05001141static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
1142 struct cmd_ds_command *cmd,
1143 u16 cmd_action)
1144{
1145 struct cmd_ds_802_11_beacon_control
1146 *bcn_ctrl = &cmd->params.bcn_ctrl;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001147
1148 lbs_deb_enter(LBS_DEB_CMD);
1149 cmd->size =
1150 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
1151 + S_DS_GEN);
1152 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
1153
1154 bcn_ctrl->action = cpu_to_le16(cmd_action);
David Woodhouseaa21c002007-12-08 20:04:36 +00001155 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
1156 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
Brajesh Dave96287ac2007-11-20 17:44:28 -05001157
1158 lbs_deb_leave(LBS_DEB_CMD);
1159 return 0;
1160}
1161
David Woodhouse681ffbb2007-12-15 20:04:54 -05001162static void lbs_queue_cmd(struct lbs_private *priv,
1163 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001164{
1165 unsigned long flags;
David Woodhouse681ffbb2007-12-15 20:04:54 -05001166 int addtail = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001167
Holger Schurig8ff12da2007-08-02 11:54:31 -04001168 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001169
David Woodhousec4ab4122007-12-15 00:41:51 -05001170 if (!cmdnode) {
1171 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001172 goto done;
1173 }
David Woodhoused9896ee2007-12-15 00:09:25 -05001174 if (!cmdnode->cmdbuf->size) {
1175 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
1176 goto done;
1177 }
David Woodhouseae125bf2007-12-15 04:22:52 -05001178 cmdnode->result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001179
1180 /* Exit_PS command needs to be queued in the header always. */
Dan Williamsddac4522007-12-11 13:49:39 -05001181 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
David Woodhouse38bfab12007-12-16 23:26:54 -05001182 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
Dan Williamsddac4522007-12-11 13:49:39 -05001183
Dan Williams0aef64d2007-08-02 11:31:18 -04001184 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001185 if (priv->psstate != PS_STATE_FULL_POWER)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001186 addtail = 0;
1187 }
1188 }
1189
David Woodhouseaa21c002007-12-08 20:04:36 +00001190 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001191
David Woodhouseac472462007-12-08 00:35:00 +00001192 if (addtail)
David Woodhouseaa21c002007-12-08 20:04:36 +00001193 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
David Woodhouseac472462007-12-08 00:35:00 +00001194 else
David Woodhouseaa21c002007-12-08 20:04:36 +00001195 list_add(&cmdnode->list, &priv->cmdpendingq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001196
David Woodhouseaa21c002007-12-08 20:04:36 +00001197 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001198
Holger Schurig8ff12da2007-08-02 11:54:31 -04001199 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
David Woodhousec4ab4122007-12-15 00:41:51 -05001200 le16_to_cpu(cmdnode->cmdbuf->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001201
1202done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001203 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001204}
1205
David Woodhouse18c52e72007-12-17 16:03:58 -05001206static void lbs_submit_command(struct lbs_private *priv,
1207 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001208{
1209 unsigned long flags;
Dan Williamsddac4522007-12-11 13:49:39 -05001210 struct cmd_header *cmd;
David Woodhouse18c52e72007-12-17 16:03:58 -05001211 uint16_t cmdsize;
1212 uint16_t command;
Holger Schurig57962f02008-05-14 16:30:28 +02001213 int timeo = 3 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -05001214 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001215
Holger Schurig8ff12da2007-08-02 11:54:31 -04001216 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001217
Dan Williamsddac4522007-12-11 13:49:39 -05001218 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001219
David Woodhouseaa21c002007-12-08 20:04:36 +00001220 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001221 priv->cur_cmd = cmdnode;
1222 priv->cur_cmd_retcode = 0;
1223 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001224
Dan Williamsddac4522007-12-11 13:49:39 -05001225 cmdsize = le16_to_cpu(cmd->size);
1226 command = le16_to_cpu(cmd->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001227
David Woodhouse18c52e72007-12-17 16:03:58 -05001228 /* These commands take longer */
Dan Williamsbe0d76e2009-05-22 20:05:25 -04001229 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
Holger Schurig57962f02008-05-14 16:30:28 +02001230 timeo = 5 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -05001231
Holger Schurige5225b32008-03-26 10:04:44 +01001232 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
1233 command, le16_to_cpu(cmd->seqnum), cmdsize);
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001234 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001235
Dan Williamsddac4522007-12-11 13:49:39 -05001236 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
David Woodhouse18c52e72007-12-17 16:03:58 -05001237
David Woodhoused9896ee2007-12-15 00:09:25 -05001238 if (ret) {
1239 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
David Woodhouse18c52e72007-12-17 16:03:58 -05001240 /* Let the timer kick in and retry, and potentially reset
1241 the whole thing if the condition persists */
Holger Schurig57962f02008-05-14 16:30:28 +02001242 timeo = HZ/4;
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001243 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001244
1245 /* Setup the timer after transmit command */
David Woodhouse18c52e72007-12-17 16:03:58 -05001246 mod_timer(&priv->command_timer, jiffies + timeo);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001247
David Woodhouse18c52e72007-12-17 16:03:58 -05001248 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001249}
1250
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001251/**
1252 * This function inserts command node to cmdfreeq
David Woodhouseaa21c002007-12-08 20:04:36 +00001253 * after cleans it. Requires priv->driver_lock held.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001254 */
David Woodhouse183aeac2007-12-15 01:52:54 -05001255static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001256 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001257{
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001258 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001259
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001260 if (!cmdnode)
1261 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001262
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001263 cmdnode->callback = NULL;
1264 cmdnode->callback_arg = 0;
1265
1266 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
1267
1268 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
1269 out:
1270 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001271}
1272
Holger Schurig69f90322007-11-23 15:43:44 +01001273static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1274 struct cmd_ctrl_node *ptempcmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001275{
1276 unsigned long flags;
1277
David Woodhouseaa21c002007-12-08 20:04:36 +00001278 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig10078322007-11-15 18:05:47 -05001279 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
David Woodhouseaa21c002007-12-08 20:04:36 +00001280 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001281}
1282
David Woodhouse183aeac2007-12-15 01:52:54 -05001283void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1284 int result)
1285{
1286 if (cmd == priv->cur_cmd)
1287 priv->cur_cmd_retcode = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001288
David Woodhouseae125bf2007-12-15 04:22:52 -05001289 cmd->result = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001290 cmd->cmdwaitqwoken = 1;
1291 wake_up_interruptible(&cmd->cmdwait_q);
1292
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001293 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
David Woodhousead12d0f2007-12-15 02:06:16 -05001294 __lbs_cleanup_and_insert_cmd(priv, cmd);
David Woodhouse183aeac2007-12-15 01:52:54 -05001295 priv->cur_cmd = NULL;
1296}
1297
Dan Williamsd5db2df2008-08-21 17:51:07 -04001298int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001299{
David Woodhousea7c45892007-12-17 22:43:48 -05001300 struct cmd_ds_802_11_radio_control cmd;
Dan Williamsd5db2df2008-08-21 17:51:07 -04001301 int ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001302
Holger Schurig9012b282007-05-25 11:27:16 -04001303 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001304
David Woodhousea7c45892007-12-17 22:43:48 -05001305 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1306 cmd.action = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001307
Dan Williamsd5db2df2008-08-21 17:51:07 -04001308 /* Only v8 and below support setting the preamble */
1309 if (priv->fwrelease < 0x09000000) {
1310 switch (preamble) {
1311 case RADIO_PREAMBLE_SHORT:
1312 if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
1313 goto out;
1314 /* Fall through */
1315 case RADIO_PREAMBLE_AUTO:
1316 case RADIO_PREAMBLE_LONG:
1317 cmd.control = cpu_to_le16(preamble);
1318 break;
1319 default:
1320 goto out;
1321 }
David Woodhousea7c45892007-12-17 22:43:48 -05001322 }
1323
Dan Williamsd5db2df2008-08-21 17:51:07 -04001324 if (radio_on)
1325 cmd.control |= cpu_to_le16(0x1);
1326 else {
1327 cmd.control &= cpu_to_le16(~0x1);
1328 priv->txpower_cur = 0;
1329 }
David Woodhousea7c45892007-12-17 22:43:48 -05001330
Dan Williamsd5db2df2008-08-21 17:51:07 -04001331 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1332 radio_on ? "ON" : "OFF", preamble);
1333
1334 priv->radio_on = radio_on;
David Woodhousea7c45892007-12-17 22:43:48 -05001335
1336 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001337
Dan Williamsd5db2df2008-08-21 17:51:07 -04001338out:
Holger Schurig9012b282007-05-25 11:27:16 -04001339 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001340 return ret;
1341}
1342
Holger Schurigc97329e2008-03-18 11:20:21 +01001343void lbs_set_mac_control(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001344{
Holger Schurig835d3ac2008-03-12 16:05:40 +01001345 struct cmd_ds_mac_control cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001346
Holger Schurig9012b282007-05-25 11:27:16 -04001347 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001348
Holger Schurig835d3ac2008-03-12 16:05:40 +01001349 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Holger Schurigd9e97782008-03-12 16:06:43 +01001350 cmd.action = cpu_to_le16(priv->mac_control);
Holger Schurig835d3ac2008-03-12 16:05:40 +01001351 cmd.reserved = 0;
1352
David Woodhouse75bf45a2008-05-20 13:32:45 +01001353 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001354
Holger Schurigc97329e2008-03-18 11:20:21 +01001355 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001356}
1357
1358/**
1359 * @brief This function prepare the command before send to firmware.
1360 *
Holger Schurig69f90322007-11-23 15:43:44 +01001361 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001362 * @param cmd_no command number
1363 * @param cmd_action command action: GET or SET
1364 * @param wait_option wait option: wait response or not
1365 * @param cmd_oid cmd oid: treated as sub command
1366 * @param pdata_buf A pointer to informaion buffer
1367 * @return 0 or -1
1368 */
Holger Schurig69f90322007-11-23 15:43:44 +01001369int lbs_prepare_and_send_command(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001370 u16 cmd_no,
1371 u16 cmd_action,
1372 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1373{
1374 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001375 struct cmd_ctrl_node *cmdnode;
1376 struct cmd_ds_command *cmdptr;
1377 unsigned long flags;
1378
Holger Schurig8ff12da2007-08-02 11:54:31 -04001379 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001380
David Woodhouseaa21c002007-12-08 20:04:36 +00001381 if (!priv) {
1382 lbs_deb_host("PREP_CMD: priv is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001383 ret = -1;
1384 goto done;
1385 }
1386
David Woodhouseaa21c002007-12-08 20:04:36 +00001387 if (priv->surpriseremoved) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001388 lbs_deb_host("PREP_CMD: card removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001389 ret = -1;
1390 goto done;
1391 }
1392
Holger Schurig0d61d042007-12-05 17:58:06 +01001393 cmdnode = lbs_get_cmd_ctrl_node(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001394
1395 if (cmdnode == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001396 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001397
1398 /* Wake up main thread to execute next command */
Dan Williamsfe336152007-08-02 11:32:25 -04001399 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001400 ret = -1;
1401 goto done;
1402 }
1403
Holger Schurige98a88d2008-03-19 14:25:58 +01001404 cmdnode->callback = NULL;
1405 cmdnode->callback_arg = (unsigned long)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001406
Dan Williamsddac4522007-12-11 13:49:39 -05001407 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001408
Holger Schurig8ff12da2007-08-02 11:54:31 -04001409 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001410
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001411 /* Set sequence number, command and INT option */
David Woodhouseaa21c002007-12-08 20:04:36 +00001412 priv->seqnum++;
1413 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001414
David Woodhouse981f1872007-05-25 23:36:54 -04001415 cmdptr->command = cpu_to_le16(cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001416 cmdptr->result = 0;
1417
1418 switch (cmd_no) {
Dan Williams0aef64d2007-08-02 11:31:18 -04001419 case CMD_802_11_PS_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001420 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001421 break;
1422
Dan Williams0aef64d2007-08-02 11:31:18 -04001423 case CMD_MAC_REG_ACCESS:
1424 case CMD_BBP_REG_ACCESS:
1425 case CMD_RF_REG_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001426 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001427 break;
1428
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001429 case CMD_802_11_MONITOR_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001430 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001431 cmd_action, pdata_buf);
1432 break;
1433
Dan Williams0aef64d2007-08-02 11:31:18 -04001434 case CMD_802_11_RSSI:
Holger Schurig10078322007-11-15 18:05:47 -05001435 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001436 break;
1437
Dan Williams0aef64d2007-08-02 11:31:18 -04001438 case CMD_802_11_SET_AFC:
1439 case CMD_802_11_GET_AFC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001440
1441 cmdptr->command = cpu_to_le16(cmd_no);
David Woodhouse981f1872007-05-25 23:36:54 -04001442 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1443 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001444
1445 memmove(&cmdptr->params.afc,
1446 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1447
1448 ret = 0;
1449 goto done;
1450
Dan Williams0aef64d2007-08-02 11:31:18 -04001451 case CMD_802_11D_DOMAIN_INFO:
Holger Schurig10078322007-11-15 18:05:47 -05001452 ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001453 cmd_no, cmd_action);
1454 break;
1455
Dan Williams0aef64d2007-08-02 11:31:18 -04001456 case CMD_802_11_TPC_CFG:
1457 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001458 cmdptr->size =
1459 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1460 S_DS_GEN);
1461
1462 memmove(&cmdptr->params.tpccfg,
1463 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1464
1465 ret = 0;
1466 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001467 case CMD_802_11_LED_GPIO_CTRL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001468 {
Dan Williams75b6a612009-05-22 20:03:09 -04001469 struct mrvl_ie_ledgpio *gpio =
1470 (struct mrvl_ie_ledgpio*)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001471 cmdptr->params.ledgpio.data;
1472
1473 memmove(&cmdptr->params.ledgpio,
1474 pdata_buf,
1475 sizeof(struct cmd_ds_802_11_led_ctrl));
1476
1477 cmdptr->command =
Dan Williams0aef64d2007-08-02 11:31:18 -04001478 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001479
1480#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1481 cmdptr->size =
Holger Schurigc2df2ef2007-12-07 15:30:44 +00001482 cpu_to_le16(le16_to_cpu(gpio->header.len)
1483 + S_DS_GEN
1484 + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1485 gpio->header.len = gpio->header.len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001486
1487 ret = 0;
1488 break;
1489 }
David Woodhouse5844d122007-12-18 02:01:37 -05001490
Dan Williams0aef64d2007-08-02 11:31:18 -04001491 case CMD_BT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001492 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001493 break;
1494
Dan Williams0aef64d2007-08-02 11:31:18 -04001495 case CMD_FWT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001496 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001497 break;
1498
Dan Williams0aef64d2007-08-02 11:31:18 -04001499 case CMD_GET_TSF:
1500 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
David Woodhouse981f1872007-05-25 23:36:54 -04001501 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1502 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001503 ret = 0;
1504 break;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001505 case CMD_802_11_BEACON_CTRL:
1506 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1507 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001508 default:
David Woodhousee37fc6e2008-05-20 11:47:16 +01001509 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001510 ret = -1;
1511 break;
1512 }
1513
1514 /* return error, since the command preparation failed */
1515 if (ret != 0) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001516 lbs_deb_host("PREP_CMD: command preparation failed\n");
Holger Schurig10078322007-11-15 18:05:47 -05001517 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001518 ret = -1;
1519 goto done;
1520 }
1521
1522 cmdnode->cmdwaitqwoken = 0;
1523
David Woodhouse681ffbb2007-12-15 20:04:54 -05001524 lbs_queue_cmd(priv, cmdnode);
Dan Williamsfe336152007-08-02 11:32:25 -04001525 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001526
Dan Williams0aef64d2007-08-02 11:31:18 -04001527 if (wait_option & CMD_OPTION_WAITFORRSP) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001528 lbs_deb_host("PREP_CMD: wait for response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001529 might_sleep();
1530 wait_event_interruptible(cmdnode->cmdwait_q,
1531 cmdnode->cmdwaitqwoken);
1532 }
1533
David Woodhouseaa21c002007-12-08 20:04:36 +00001534 spin_lock_irqsave(&priv->driver_lock, flags);
1535 if (priv->cur_cmd_retcode) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001536 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001537 priv->cur_cmd_retcode);
1538 priv->cur_cmd_retcode = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001539 ret = -1;
1540 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001541 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001542
1543done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001544 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001545 return ret;
1546}
1547
1548/**
1549 * @brief This function allocates the command buffer and link
1550 * it to command free queue.
1551 *
Holger Schurig69f90322007-11-23 15:43:44 +01001552 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001553 * @return 0 or -1
1554 */
Holger Schurig69f90322007-11-23 15:43:44 +01001555int lbs_allocate_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001556{
1557 int ret = 0;
Dan Williamsddac4522007-12-11 13:49:39 -05001558 u32 bufsize;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001559 u32 i;
Dan Williamsddac4522007-12-11 13:49:39 -05001560 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001561
Holger Schurig8ff12da2007-08-02 11:54:31 -04001562 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001563
Dan Williamsddac4522007-12-11 13:49:39 -05001564 /* Allocate and initialize the command array */
1565 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1566 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001567 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001568 ret = -1;
1569 goto done;
1570 }
Dan Williamsddac4522007-12-11 13:49:39 -05001571 priv->cmd_array = cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001572
Dan Williamsddac4522007-12-11 13:49:39 -05001573 /* Allocate and initialize each command buffer in the command array */
1574 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1575 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1576 if (!cmdarray[i].cmdbuf) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001577 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001578 ret = -1;
1579 goto done;
1580 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001581 }
1582
Dan Williamsddac4522007-12-11 13:49:39 -05001583 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1584 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1585 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001586 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001587 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001588
1589done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001590 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001591 return ret;
1592}
1593
1594/**
1595 * @brief This function frees the command buffer.
1596 *
Holger Schurig69f90322007-11-23 15:43:44 +01001597 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001598 * @return 0 or -1
1599 */
Holger Schurig69f90322007-11-23 15:43:44 +01001600int lbs_free_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001601{
Dan Williamsddac4522007-12-11 13:49:39 -05001602 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001603 unsigned int i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001604
Holger Schurig8ff12da2007-08-02 11:54:31 -04001605 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001606
1607 /* need to check if cmd array is allocated or not */
David Woodhouseaa21c002007-12-08 20:04:36 +00001608 if (priv->cmd_array == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001609 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001610 goto done;
1611 }
1612
Dan Williamsddac4522007-12-11 13:49:39 -05001613 cmdarray = priv->cmd_array;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001614
1615 /* Release shared memory buffers */
Dan Williamsddac4522007-12-11 13:49:39 -05001616 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1617 if (cmdarray[i].cmdbuf) {
1618 kfree(cmdarray[i].cmdbuf);
1619 cmdarray[i].cmdbuf = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001620 }
1621 }
1622
1623 /* Release cmd_ctrl_node */
David Woodhouseaa21c002007-12-08 20:04:36 +00001624 if (priv->cmd_array) {
1625 kfree(priv->cmd_array);
1626 priv->cmd_array = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001627 }
1628
1629done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001630 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001631 return 0;
1632}
1633
1634/**
1635 * @brief This function gets a free command node if available in
1636 * command free queue.
1637 *
Holger Schurig69f90322007-11-23 15:43:44 +01001638 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001639 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1640 */
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001641static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001642{
1643 struct cmd_ctrl_node *tempnode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001644 unsigned long flags;
1645
Holger Schurig8ff12da2007-08-02 11:54:31 -04001646 lbs_deb_enter(LBS_DEB_HOST);
1647
David Woodhouseaa21c002007-12-08 20:04:36 +00001648 if (!priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001649 return NULL;
1650
David Woodhouseaa21c002007-12-08 20:04:36 +00001651 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001652
David Woodhouseaa21c002007-12-08 20:04:36 +00001653 if (!list_empty(&priv->cmdfreeq)) {
1654 tempnode = list_first_entry(&priv->cmdfreeq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001655 struct cmd_ctrl_node, list);
1656 list_del(&tempnode->list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001657 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001658 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001659 tempnode = NULL;
1660 }
1661
David Woodhouseaa21c002007-12-08 20:04:36 +00001662 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001663
Holger Schurig8ff12da2007-08-02 11:54:31 -04001664 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001665 return tempnode;
1666}
1667
1668/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001669 * @brief This function executes next command in command
Nick Andrew877d0312009-01-26 11:06:57 +01001670 * pending queue. It will put firmware back to PS mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001671 * if applicable.
1672 *
Holger Schurig69f90322007-11-23 15:43:44 +01001673 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001674 * @return 0 or -1
1675 */
Holger Schurig69f90322007-11-23 15:43:44 +01001676int lbs_execute_next_command(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001677{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001678 struct cmd_ctrl_node *cmdnode = NULL;
Dan Williamsddac4522007-12-11 13:49:39 -05001679 struct cmd_header *cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001680 unsigned long flags;
1681 int ret = 0;
1682
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001683 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1684 * only caller to us is lbs_thread() and we get even when a
1685 * data packet is received */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001686 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001687
David Woodhouseaa21c002007-12-08 20:04:36 +00001688 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001689
David Woodhouseaa21c002007-12-08 20:04:36 +00001690 if (priv->cur_cmd) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001691 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001692 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001693 ret = -1;
1694 goto done;
1695 }
1696
David Woodhouseaa21c002007-12-08 20:04:36 +00001697 if (!list_empty(&priv->cmdpendingq)) {
1698 cmdnode = list_first_entry(&priv->cmdpendingq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001699 struct cmd_ctrl_node, list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001700 }
1701
David Woodhouseaa21c002007-12-08 20:04:36 +00001702 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001703
1704 if (cmdnode) {
Dan Williamsddac4522007-12-11 13:49:39 -05001705 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001706
Dan Williamsddac4522007-12-11 13:49:39 -05001707 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001708 if ((priv->psstate == PS_STATE_SLEEP) ||
1709 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001710 lbs_deb_host(
1711 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001712 le16_to_cpu(cmd->command),
David Woodhouseaa21c002007-12-08 20:04:36 +00001713 priv->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001714 ret = -1;
1715 goto done;
1716 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001717 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
Dan Williamsddac4522007-12-11 13:49:39 -05001718 "0x%04x in psstate %d\n",
1719 le16_to_cpu(cmd->command), priv->psstate);
David Woodhouseaa21c002007-12-08 20:04:36 +00001720 } else if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001721 /*
1722 * 1. Non-PS command:
1723 * Queue it. set needtowakeup to TRUE if current state
Holger Schurig10078322007-11-15 18:05:47 -05001724 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001725 * 2. PS command but not Exit_PS:
1726 * Ignore it.
1727 * 3. PS command Exit_PS:
1728 * Set needtowakeup to TRUE if current state is SLEEP,
1729 * otherwise send this command down to firmware
1730 * immediately.
1731 */
Dan Williamsddac4522007-12-11 13:49:39 -05001732 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001733 /* Prepare to send Exit PS,
1734 * this non PS command will be sent later */
David Woodhouseaa21c002007-12-08 20:04:36 +00001735 if ((priv->psstate == PS_STATE_SLEEP)
1736 || (priv->psstate == PS_STATE_PRE_SLEEP)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001737 ) {
1738 /* w/ new scheme, it will not reach here.
1739 since it is blocked in main_thread. */
David Woodhouseaa21c002007-12-08 20:04:36 +00001740 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001741 } else
Holger Schurig10078322007-11-15 18:05:47 -05001742 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001743
1744 ret = 0;
1745 goto done;
1746 } else {
1747 /*
1748 * PS command. Ignore it if it is not Exit_PS.
1749 * otherwise send it down immediately.
1750 */
David Woodhouse38bfab12007-12-16 23:26:54 -05001751 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001752
Holger Schurig8ff12da2007-08-02 11:54:31 -04001753 lbs_deb_host(
1754 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001755 psm->action);
1756 if (psm->action !=
Dan Williams0aef64d2007-08-02 11:31:18 -04001757 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001758 lbs_deb_host(
1759 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001760 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001761 spin_lock_irqsave(&priv->driver_lock, flags);
1762 lbs_complete_command(priv, cmdnode, 0);
1763 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001764
1765 ret = 0;
1766 goto done;
1767 }
1768
David Woodhouseaa21c002007-12-08 20:04:36 +00001769 if ((priv->psstate == PS_STATE_SLEEP) ||
1770 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001771 lbs_deb_host(
1772 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001773 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001774 spin_lock_irqsave(&priv->driver_lock, flags);
1775 lbs_complete_command(priv, cmdnode, 0);
1776 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001777 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001778
1779 ret = 0;
1780 goto done;
1781 }
1782
Holger Schurig8ff12da2007-08-02 11:54:31 -04001783 lbs_deb_host(
1784 "EXEC_NEXT_CMD: sending EXIT_PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001785 }
1786 }
Li Zefanabe3ed12007-12-06 13:01:21 +01001787 list_del(&cmdnode->list);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001788 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001789 le16_to_cpu(cmd->command));
David Woodhoused9896ee2007-12-15 00:09:25 -05001790 lbs_submit_command(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001791 } else {
1792 /*
1793 * check if in power save mode, if yes, put the device back
1794 * to PS mode
1795 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001796 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1797 (priv->psstate == PS_STATE_FULL_POWER) &&
1798 ((priv->connect_status == LBS_CONNECTED) ||
1799 (priv->mesh_connect_status == LBS_CONNECTED))) {
1800 if (priv->secinfo.WPAenabled ||
1801 priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001802 /* check for valid WPA group keys */
David Woodhouseaa21c002007-12-08 20:04:36 +00001803 if (priv->wpa_mcast_key.len ||
1804 priv->wpa_unicast_key.len) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001805 lbs_deb_host(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001806 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1807 " go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001808 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001809 }
1810 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001811 lbs_deb_host(
1812 "EXEC_NEXT_CMD: cmdpendingq empty, "
1813 "go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001814 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001815 }
1816 }
1817 }
1818
1819 ret = 0;
1820done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001821 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001822 return ret;
1823}
1824
Holger Schurig69f90322007-11-23 15:43:44 +01001825void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001826{
1827 union iwreq_data iwrq;
1828 u8 buf[50];
1829
Holger Schurig8ff12da2007-08-02 11:54:31 -04001830 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001831
1832 memset(&iwrq, 0, sizeof(union iwreq_data));
1833 memset(buf, 0, sizeof(buf));
1834
1835 snprintf(buf, sizeof(buf) - 1, "%s", str);
1836
1837 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1838
1839 /* Send Event to upper layer */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001840 lbs_deb_wext("event indication string %s\n", (char *)buf);
1841 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1842 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001843
Holger Schurig634b8f42007-05-25 13:05:16 -04001844 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001845
Holger Schurig8ff12da2007-08-02 11:54:31 -04001846 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001847}
1848
Holger Schurigf539f2e2008-03-26 13:22:11 +01001849static void lbs_send_confirmsleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001850{
1851 unsigned long flags;
Holger Schurigf539f2e2008-03-26 13:22:11 +01001852 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001853
Holger Schurig8ff12da2007-08-02 11:54:31 -04001854 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurigf539f2e2008-03-26 13:22:11 +01001855 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1856 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001857
Holger Schurigf539f2e2008-03-26 13:22:11 +01001858 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1859 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001860 if (ret) {
Holger Schurigf539f2e2008-03-26 13:22:11 +01001861 lbs_pr_alert("confirm_sleep failed\n");
Holger Schurig7919b892008-04-01 14:50:43 +02001862 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001863 }
Holger Schurig7919b892008-04-01 14:50:43 +02001864
1865 spin_lock_irqsave(&priv->driver_lock, flags);
1866
Holger Schuriga01f5452008-06-04 11:10:40 +02001867 /* We don't get a response on the sleep-confirmation */
1868 priv->dnld_sent = DNLD_RES_RECEIVED;
1869
Holger Schurig7919b892008-04-01 14:50:43 +02001870 /* If nothing to do, go back to sleep (?) */
1871 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1872 priv->psstate = PS_STATE_SLEEP;
1873
1874 spin_unlock_irqrestore(&priv->driver_lock, flags);
1875
1876out:
Holger Schurigf539f2e2008-03-26 13:22:11 +01001877 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001878}
1879
Holger Schurig69f90322007-11-23 15:43:44 +01001880void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001881{
Holger Schurig8ff12da2007-08-02 11:54:31 -04001882 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001883
1884 /*
1885 * PS is currently supported only in Infrastructure mode
1886 * Remove this check if it is to be supported in IBSS mode also
1887 */
1888
Holger Schurig10078322007-11-15 18:05:47 -05001889 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001890 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001891
Holger Schurig8ff12da2007-08-02 11:54:31 -04001892 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001893}
1894
1895/**
Holger Schurig8ff12da2007-08-02 11:54:31 -04001896 * @brief This function sends Exit_PS command to firmware.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001897 *
Holger Schurig69f90322007-11-23 15:43:44 +01001898 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001899 * @param wait_option wait response or not
1900 * @return n/a
1901 */
Holger Schurig69f90322007-11-23 15:43:44 +01001902void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001903{
David Woodhouse981f1872007-05-25 23:36:54 -04001904 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001905
Holger Schurig8ff12da2007-08-02 11:54:31 -04001906 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001907
Holger Schurig10078322007-11-15 18:05:47 -05001908 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001909
Holger Schurig10078322007-11-15 18:05:47 -05001910 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001911 CMD_SUBCMD_EXIT_PS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001912 wait_option, 0, &Localpsmode);
1913
Holger Schurig8ff12da2007-08-02 11:54:31 -04001914 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001915}
1916
1917/**
1918 * @brief This function checks condition and prepares to
1919 * send sleep confirm command to firmware if ok.
1920 *
Holger Schurig69f90322007-11-23 15:43:44 +01001921 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001922 * @param psmode Power Saving mode
1923 * @return n/a
1924 */
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001925void lbs_ps_confirm_sleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001926{
1927 unsigned long flags =0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001928 int allowed = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001929
Holger Schurig8ff12da2007-08-02 11:54:31 -04001930 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001931
Holger Schuriga01f5452008-06-04 11:10:40 +02001932 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig634b8f42007-05-25 13:05:16 -04001933 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001934 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001935 lbs_deb_host("dnld_sent was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001936 }
1937
Holger Schurig7919b892008-04-01 14:50:43 +02001938 /* In-progress command? */
David Woodhouseaa21c002007-12-08 20:04:36 +00001939 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001940 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001941 lbs_deb_host("cur_cmd was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001942 }
Holger Schurig7919b892008-04-01 14:50:43 +02001943
1944 /* Pending events or command responses? */
1945 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001946 allowed = 0;
Holger Schurig7919b892008-04-01 14:50:43 +02001947 lbs_deb_host("pending events or command responses\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001948 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001949 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001950
1951 if (allowed) {
Holger Schurig10078322007-11-15 18:05:47 -05001952 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
Holger Schurigf539f2e2008-03-26 13:22:11 +01001953 lbs_send_confirmsleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001954 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001955 lbs_deb_host("sleep confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001956 }
1957
Holger Schurig8ff12da2007-08-02 11:54:31 -04001958 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001959}
Holger Schurig675787e2007-12-05 17:58:11 +01001960
1961
Anna Neal0112c9e2008-09-11 11:17:25 -07001962/**
1963 * @brief Configures the transmission power control functionality.
1964 *
1965 * @param priv A pointer to struct lbs_private structure
1966 * @param enable Transmission power control enable
1967 * @param p0 Power level when link quality is good (dBm).
1968 * @param p1 Power level when link quality is fair (dBm).
1969 * @param p2 Power level when link quality is poor (dBm).
1970 * @param usesnr Use Signal to Noise Ratio in TPC
1971 *
1972 * @return 0 on success
1973 */
1974int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1975 int8_t p2, int usesnr)
1976{
1977 struct cmd_ds_802_11_tpc_cfg cmd;
1978 int ret;
1979
1980 memset(&cmd, 0, sizeof(cmd));
1981 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1982 cmd.action = cpu_to_le16(CMD_ACT_SET);
1983 cmd.enable = !!enable;
Anna Neal3ed6e082008-09-26 11:34:35 -04001984 cmd.usesnr = !!usesnr;
Anna Neal0112c9e2008-09-11 11:17:25 -07001985 cmd.P0 = p0;
1986 cmd.P1 = p1;
1987 cmd.P2 = p2;
1988
1989 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
1990
1991 return ret;
1992}
1993
1994/**
1995 * @brief Configures the power adaptation settings.
1996 *
1997 * @param priv A pointer to struct lbs_private structure
1998 * @param enable Power adaptation enable
1999 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
2000 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
2001 * @param p2 Power level for 48 and 54 Mbps (dBm).
2002 *
2003 * @return 0 on Success
2004 */
2005
2006int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
2007 int8_t p1, int8_t p2)
2008{
2009 struct cmd_ds_802_11_pa_cfg cmd;
2010 int ret;
2011
2012 memset(&cmd, 0, sizeof(cmd));
2013 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
2014 cmd.action = cpu_to_le16(CMD_ACT_SET);
2015 cmd.enable = !!enable;
2016 cmd.P0 = p0;
2017 cmd.P1 = p1;
2018 cmd.P2 = p2;
2019
2020 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
2021
2022 return ret;
2023}
2024
2025
Holger Schurig8db4a2b2008-03-19 10:11:00 +01002026static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
2027 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
2028 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
2029 unsigned long callback_arg)
Holger Schurig675787e2007-12-05 17:58:11 +01002030{
Holger Schurig675787e2007-12-05 17:58:11 +01002031 struct cmd_ctrl_node *cmdnode;
Holger Schurig675787e2007-12-05 17:58:11 +01002032
2033 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurig675787e2007-12-05 17:58:11 +01002034
David Woodhouseaa21c002007-12-08 20:04:36 +00002035 if (priv->surpriseremoved) {
Holger Schurig675787e2007-12-05 17:58:11 +01002036 lbs_deb_host("PREP_CMD: card removed\n");
David Woodhouse3399ea52007-12-15 03:09:33 -05002037 cmdnode = ERR_PTR(-ENOENT);
Holger Schurig675787e2007-12-05 17:58:11 +01002038 goto done;
2039 }
2040
2041 cmdnode = lbs_get_cmd_ctrl_node(priv);
Holger Schurig675787e2007-12-05 17:58:11 +01002042 if (cmdnode == NULL) {
2043 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
2044
2045 /* Wake up main thread to execute next command */
2046 wake_up_interruptible(&priv->waitq);
David Woodhouse3399ea52007-12-15 03:09:33 -05002047 cmdnode = ERR_PTR(-ENOBUFS);
Holger Schurig675787e2007-12-05 17:58:11 +01002048 goto done;
2049 }
2050
David Woodhouse448a51a2007-12-08 00:59:54 +00002051 cmdnode->callback = callback;
David Woodhouse1309b552007-12-10 13:36:10 -05002052 cmdnode->callback_arg = callback_arg;
Holger Schurig675787e2007-12-05 17:58:11 +01002053
Dan Williams7ad994d2007-12-11 12:33:30 -05002054 /* Copy the incoming command to the buffer */
Dan Williamsddac4522007-12-11 13:49:39 -05002055 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
Dan Williams7ad994d2007-12-11 12:33:30 -05002056
Holger Schurig675787e2007-12-05 17:58:11 +01002057 /* Set sequence number, clean result, move to buffer */
David Woodhouseaa21c002007-12-08 20:04:36 +00002058 priv->seqnum++;
Dan Williamsddac4522007-12-11 13:49:39 -05002059 cmdnode->cmdbuf->command = cpu_to_le16(command);
2060 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
2061 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
2062 cmdnode->cmdbuf->result = 0;
Holger Schurig675787e2007-12-05 17:58:11 +01002063
2064 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
2065
Holger Schurig675787e2007-12-05 17:58:11 +01002066 cmdnode->cmdwaitqwoken = 0;
David Woodhouse681ffbb2007-12-15 20:04:54 -05002067 lbs_queue_cmd(priv, cmdnode);
Holger Schurig675787e2007-12-05 17:58:11 +01002068 wake_up_interruptible(&priv->waitq);
2069
David Woodhouse3399ea52007-12-15 03:09:33 -05002070 done:
2071 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
2072 return cmdnode;
2073}
2074
Holger Schurig8db4a2b2008-03-19 10:11:00 +01002075void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
2076 struct cmd_header *in_cmd, int in_cmd_size)
2077{
2078 lbs_deb_enter(LBS_DEB_CMD);
2079 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2080 lbs_cmd_async_callback, 0);
2081 lbs_deb_leave(LBS_DEB_CMD);
2082}
2083
David Woodhouse3399ea52007-12-15 03:09:33 -05002084int __lbs_cmd(struct lbs_private *priv, uint16_t command,
2085 struct cmd_header *in_cmd, int in_cmd_size,
2086 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
2087 unsigned long callback_arg)
2088{
2089 struct cmd_ctrl_node *cmdnode;
2090 unsigned long flags;
2091 int ret = 0;
2092
2093 lbs_deb_enter(LBS_DEB_HOST);
2094
2095 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2096 callback, callback_arg);
2097 if (IS_ERR(cmdnode)) {
2098 ret = PTR_ERR(cmdnode);
2099 goto done;
2100 }
2101
Holger Schurig675787e2007-12-05 17:58:11 +01002102 might_sleep();
2103 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
2104
David Woodhouseaa21c002007-12-08 20:04:36 +00002105 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseae125bf2007-12-15 04:22:52 -05002106 ret = cmdnode->result;
2107 if (ret)
2108 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
2109 command, ret);
David Woodhouse3399ea52007-12-15 03:09:33 -05002110
David Woodhousead12d0f2007-12-15 02:06:16 -05002111 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
David Woodhouseaa21c002007-12-08 20:04:36 +00002112 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig675787e2007-12-05 17:58:11 +01002113
2114done:
2115 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
2116 return ret;
2117}
Dan Williams14e865b2007-12-10 15:11:23 -05002118EXPORT_SYMBOL_GPL(__lbs_cmd);
Holger Schurig675787e2007-12-05 17:58:11 +01002119
2120