blob: ec65be0c4d930896aad9b2ba4e055afaf17d5034 [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"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020010#include "decl.h"
11#include "defs.h"
12#include "dev.h"
Holger Schurig697900a2008-04-02 16:27:10 +020013#include "assoc.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020014#include "wext.h"
Holger Schurig2d465022009-10-22 15:30:48 +020015#include "scan.h"
Dan Williams6e66f032007-12-11 12:42:16 -050016#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020017
David Woodhouse2fd6cfe2007-12-11 17:44:10 -050018static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
Holger Schurig0d61d042007-12-05 17:58:06 +010019
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020/**
Holger Schurig8db4a2b2008-03-19 10:11:00 +010021 * @brief Simple callback that copies response back into command
22 *
23 * @param priv A pointer to struct lbs_private structure
24 * @param extra A pointer to the original command structure for which
25 * 'resp' is a response
26 * @param resp A pointer to the command response
27 *
28 * @return 0 on success, error on failure
29 */
30int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
31 struct cmd_header *resp)
32{
33 struct cmd_header *buf = (void *)extra;
34 uint16_t copy_len;
35
36 copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
37 memcpy(buf, resp, copy_len);
38 return 0;
39}
40EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
41
42/**
43 * @brief Simple callback that ignores the result. Use this if
44 * you just want to send a command to the hardware, but don't
45 * care for the result.
46 *
47 * @param priv ignored
48 * @param extra ignored
49 * @param resp ignored
50 *
51 * @return 0 for success
52 */
53static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
54 struct cmd_header *resp)
55{
56 return 0;
57}
58
59
60/**
Dan Williams852e1f22007-12-10 15:24:47 -050061 * @brief Checks whether a command is allowed in Power Save mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020062 *
63 * @param command the command ID
Dan Williams852e1f22007-12-10 15:24:47 -050064 * @return 1 if allowed, 0 if not allowed
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020065 */
Dan Williams852e1f22007-12-10 15:24:47 -050066static u8 is_command_allowed_in_ps(u16 cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020067{
Dan Williams852e1f22007-12-10 15:24:47 -050068 switch (cmd) {
69 case CMD_802_11_RSSI:
70 return 1;
71 default:
72 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020073 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074 return 0;
75}
76
Dan Williams6e66f032007-12-11 12:42:16 -050077/**
Amitkumar Karwar63f275d2009-10-06 19:20:28 -070078 * @brief This function checks if the command is allowed.
79 *
80 * @param priv A pointer to lbs_private structure
81 * @return allowed or not allowed.
82 */
83
84static int lbs_is_cmd_allowed(struct lbs_private *priv)
85{
86 int ret = 1;
87
88 lbs_deb_enter(LBS_DEB_CMD);
89
90 if (!priv->is_auto_deep_sleep_enabled) {
91 if (priv->is_deep_sleep) {
92 lbs_deb_cmd("command not allowed in deep sleep\n");
93 ret = 0;
94 }
95 }
96
97 lbs_deb_leave(LBS_DEB_CMD);
98 return ret;
99}
100
101/**
Dan Williams6e66f032007-12-11 12:42:16 -0500102 * @brief Updates the hardware details like MAC address and regulatory region
103 *
104 * @param priv A pointer to struct lbs_private structure
105 *
106 * @return 0 on success, error on failure
107 */
108int lbs_update_hw_spec(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200109{
Dan Williams6e66f032007-12-11 12:42:16 -0500110 struct cmd_ds_get_hw_spec cmd;
111 int ret = -1;
112 u32 i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200113
Holger Schurig9012b282007-05-25 11:27:16 -0400114 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115
Dan Williams6e66f032007-12-11 12:42:16 -0500116 memset(&cmd, 0, sizeof(cmd));
117 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
118 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
David Woodhouse689442d2007-12-12 16:00:42 -0500119 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
Dan Williams6e66f032007-12-11 12:42:16 -0500120 if (ret)
121 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122
Dan Williams6e66f032007-12-11 12:42:16 -0500123 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500124
Holger Schurigdac10a92008-01-16 15:55:22 +0100125 /* The firmware release is in an interesting format: the patch
126 * level is in the most significant nibble ... so fix that: */
127 priv->fwrelease = le32_to_cpu(cmd.fwrelease);
128 priv->fwrelease = (priv->fwrelease << 8) |
129 (priv->fwrelease >> 24 & 0xff);
130
131 /* Some firmware capabilities:
132 * CF card firmware 5.0.16p0: cap 0x00000303
133 * USB dongle firmware 5.110.17p2: cap 0x00000303
134 */
Johannes Berge1749612008-10-27 15:59:26 -0700135 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
136 cmd.permanentaddr,
Holger Schurigdac10a92008-01-16 15:55:22 +0100137 priv->fwrelease >> 24 & 0xff,
138 priv->fwrelease >> 16 & 0xff,
139 priv->fwrelease >> 8 & 0xff,
140 priv->fwrelease & 0xff,
141 priv->fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500142 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
143 cmd.hwifversion, cmd.version);
144
Bing Zhao684d6b32009-03-25 09:51:16 -0700145 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
146 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
147 /* 5.110.22 have mesh command with 0xa3 command id */
148 /* 10.0.0.p0 FW brings in mesh config command with different id */
149 /* Check FW version MSB and initialize mesh_fw_ver */
150 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
151 priv->mesh_fw_ver = MESH_FW_OLD;
152 else if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
153 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK))
154 priv->mesh_fw_ver = MESH_FW_NEW;
155 else
156 priv->mesh_fw_ver = MESH_NONE;
157
Dan Williams6e66f032007-12-11 12:42:16 -0500158 /* Clamp region code to 8-bit since FW spec indicates that it should
159 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
160 * returns non-zero high 8 bits here.
Marek Vasut15483992009-07-16 19:19:53 +0200161 *
162 * Firmware version 4.0.102 used in CF8381 has region code shifted. We
163 * need to check for this problem and handle it properly.
Dan Williams6e66f032007-12-11 12:42:16 -0500164 */
Marek Vasut15483992009-07-16 19:19:53 +0200165 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4)
166 priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF;
167 else
168 priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
Dan Williams6e66f032007-12-11 12:42:16 -0500169
170 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
171 /* use the region code to search for the index */
172 if (priv->regioncode == lbs_region_code_to_index[i])
173 break;
174 }
175
176 /* if it's unidentified region code, use the default (USA) */
177 if (i >= MRVDRV_MAX_REGION_CODE) {
178 priv->regioncode = 0x10;
179 lbs_pr_info("unidentified region code; using the default (USA)\n");
180 }
181
182 if (priv->current_addr[0] == 0xff)
183 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
184
185 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
186 if (priv->mesh_dev)
187 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
188
189 if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
190 ret = -1;
191 goto out;
192 }
193
Dan Williams6e66f032007-12-11 12:42:16 -0500194out:
Holger Schurig9012b282007-05-25 11:27:16 -0400195 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams6e66f032007-12-11 12:42:16 -0500196 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200197}
198
Anna Neal582c1b52008-10-20 16:46:56 -0700199int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
200 struct wol_config *p_wol_config)
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500201{
202 struct cmd_ds_host_sleep cmd_config;
203 int ret;
204
David Woodhouse9fae8992007-12-15 03:46:44 -0500205 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500206 cmd_config.criteria = cpu_to_le32(criteria);
David Woodhouse506e9022007-12-12 20:06:06 -0500207 cmd_config.gpio = priv->wol_gpio;
208 cmd_config.gap = priv->wol_gap;
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500209
Anna Neal582c1b52008-10-20 16:46:56 -0700210 if (p_wol_config != NULL)
211 memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config,
212 sizeof(struct wol_config));
213 else
214 cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE;
215
David Woodhouse689442d2007-12-12 16:00:42 -0500216 ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
David Woodhouse506e9022007-12-12 20:06:06 -0500217 if (!ret) {
Anna Neal582c1b52008-10-20 16:46:56 -0700218 if (criteria) {
219 lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
220 priv->wol_criteria = criteria;
221 } else
222 memcpy((uint8_t *) p_wol_config,
223 (uint8_t *)&cmd_config.wol_conf,
224 sizeof(struct wol_config));
David Woodhouse506e9022007-12-12 20:06:06 -0500225 } else {
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500226 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500227 }
David Woodhouse506e9022007-12-12 20:06:06 -0500228
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500229 return ret;
230}
231EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
232
Holger Schurige98a88d2008-03-19 14:25:58 +0100233static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234 u16 cmd_action)
235{
236 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200237
Holger Schurig9012b282007-05-25 11:27:16 -0400238 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200239
Dan Williams0aef64d2007-08-02 11:31:18 -0400240 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouse981f1872007-05-25 23:36:54 -0400241 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
242 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200243 psm->action = cpu_to_le16(cmd_action);
244 psm->multipledtim = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400245 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400246 case CMD_SUBCMD_ENTER_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400247 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200248
Holger Schurig252cf0d2007-08-02 13:09:34 -0400249 psm->locallisteninterval = 0;
Holger Schurig97605c32007-08-02 13:09:15 -0400250 psm->nullpktinterval = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200251 psm->multipledtim =
Holger Schurig56c46562007-08-02 13:09:49 -0400252 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200253 break;
254
Dan Williams0aef64d2007-08-02 11:31:18 -0400255 case CMD_SUBCMD_EXIT_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400256 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200257 break;
258
Dan Williams0aef64d2007-08-02 11:31:18 -0400259 case CMD_SUBCMD_SLEEP_CONFIRMED:
Holger Schurig9012b282007-05-25 11:27:16 -0400260 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200261 break;
262
263 default:
264 break;
265 }
266
Holger Schurig9012b282007-05-25 11:27:16 -0400267 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200268 return 0;
269}
270
David Woodhouse3fbe1042007-12-17 23:48:31 -0500271int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
272 struct sleep_params *sp)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200273{
David Woodhouse3fbe1042007-12-17 23:48:31 -0500274 struct cmd_ds_802_11_sleep_params cmd;
275 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200276
Holger Schurig9012b282007-05-25 11:27:16 -0400277 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200278
Dan Williams0aef64d2007-08-02 11:31:18 -0400279 if (cmd_action == CMD_ACT_GET) {
David Woodhouse3fbe1042007-12-17 23:48:31 -0500280 memset(&cmd, 0, sizeof(cmd));
281 } else {
282 cmd.error = cpu_to_le16(sp->sp_error);
283 cmd.offset = cpu_to_le16(sp->sp_offset);
284 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
285 cmd.calcontrol = sp->sp_calcontrol;
286 cmd.externalsleepclk = sp->sp_extsleepclk;
287 cmd.reserved = cpu_to_le16(sp->sp_reserved);
288 }
289 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
290 cmd.action = cpu_to_le16(cmd_action);
291
292 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
293
294 if (!ret) {
295 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
296 "calcontrol 0x%x extsleepclk 0x%x\n",
297 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
298 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
299 cmd.externalsleepclk);
300
301 sp->sp_error = le16_to_cpu(cmd.error);
302 sp->sp_offset = le16_to_cpu(cmd.offset);
303 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
304 sp->sp_calcontrol = cmd.calcontrol;
305 sp->sp_extsleepclk = cmd.externalsleepclk;
306 sp->sp_reserved = le16_to_cpu(cmd.reserved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307 }
308
David Woodhouse3fbe1042007-12-17 23:48:31 -0500309 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200310 return 0;
311}
312
Amitkumar Karwar49125452009-09-30 20:04:38 -0700313static int lbs_wait_for_ds_awake(struct lbs_private *priv)
314{
315 int ret = 0;
316
317 lbs_deb_enter(LBS_DEB_CMD);
318
319 if (priv->is_deep_sleep) {
320 if (!wait_event_interruptible_timeout(priv->ds_awake_q,
321 !priv->is_deep_sleep, (10 * HZ))) {
322 lbs_pr_err("ds_awake_q: timer expired\n");
323 ret = -1;
324 }
325 }
326
327 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
328 return ret;
329}
330
331int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep)
332{
333 int ret = 0;
334
335 lbs_deb_enter(LBS_DEB_CMD);
336
337 if (deep_sleep) {
338 if (priv->is_deep_sleep != 1) {
339 lbs_deb_cmd("deep sleep: sleep\n");
340 BUG_ON(!priv->enter_deep_sleep);
341 ret = priv->enter_deep_sleep(priv);
342 if (!ret) {
343 netif_stop_queue(priv->dev);
344 netif_carrier_off(priv->dev);
345 }
346 } else {
347 lbs_pr_err("deep sleep: already enabled\n");
348 }
349 } else {
350 if (priv->is_deep_sleep) {
351 lbs_deb_cmd("deep sleep: wakeup\n");
352 BUG_ON(!priv->exit_deep_sleep);
353 ret = priv->exit_deep_sleep(priv);
354 if (!ret) {
355 ret = lbs_wait_for_ds_awake(priv);
356 if (ret)
357 lbs_pr_err("deep sleep: wakeup"
358 "failed\n");
359 }
360 }
361 }
362
363 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
364 return ret;
365}
366
David Woodhousef70dd452007-12-18 00:18:05 -0500367int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
368 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369{
David Woodhousef70dd452007-12-18 00:18:05 -0500370 struct cmd_ds_802_11_set_wep cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200372
Holger Schurig9012b282007-05-25 11:27:16 -0400373 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200374
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200375 memset(&cmd, 0, sizeof(cmd));
David Woodhousef70dd452007-12-18 00:18:05 -0500376 cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
377 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378
David Woodhousef70dd452007-12-18 00:18:05 -0500379 cmd.action = cpu_to_le16(cmd_action);
380
381 if (cmd_action == CMD_ACT_ADD) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200382 int i;
383
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200384 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500385 cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
386 CMD_WEP_KEY_INDEX_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200387
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200388 /* Copy key types and material to host command structure */
389 for (i = 0; i < 4; i++) {
David Woodhousef70dd452007-12-18 00:18:05 -0500390 struct enc_key *pkey = &assoc->wep_keys[i];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391
392 switch (pkey->len) {
393 case KEY_LEN_WEP_40:
David Woodhousef70dd452007-12-18 00:18:05 -0500394 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
395 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400396 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200397 break;
398 case KEY_LEN_WEP_104:
David Woodhousef70dd452007-12-18 00:18:05 -0500399 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
400 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400401 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200402 break;
403 case 0:
404 break;
405 default:
Holger Schurig8ff12da2007-08-02 11:54:31 -0400406 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
David Woodhousef70dd452007-12-18 00:18:05 -0500407 i, pkey->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200408 ret = -1;
409 goto done;
410 break;
411 }
412 }
David Woodhousef70dd452007-12-18 00:18:05 -0500413 } else if (cmd_action == CMD_ACT_REMOVE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200414 /* ACT_REMOVE clears _all_ WEP keys */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200415
416 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500417 cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
418 CMD_WEP_KEY_INDEX_MASK);
David Woodhouseaa21c002007-12-08 20:04:36 +0000419 lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200420 }
421
David Woodhousef70dd452007-12-18 00:18:05 -0500422 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200423done:
Holger Schurig9012b282007-05-25 11:27:16 -0400424 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200425 return ret;
426}
427
David Woodhouse4f59abf2007-12-18 00:47:17 -0500428int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
429 uint16_t *enable)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200430{
David Woodhouse4f59abf2007-12-18 00:47:17 -0500431 struct cmd_ds_802_11_enable_rsn cmd;
432 int ret;
Dan Williams90a42212007-05-25 23:01:24 -0400433
434 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200435
David Woodhouse4f59abf2007-12-18 00:47:17 -0500436 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
437 cmd.action = cpu_to_le16(cmd_action);
Dan Williams18c96c342007-06-18 12:01:12 -0400438
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200439 if (cmd_action == CMD_ACT_GET)
440 cmd.enable = 0;
441 else {
Dan Williams18c96c342007-06-18 12:01:12 -0400442 if (*enable)
David Woodhouse4f59abf2007-12-18 00:47:17 -0500443 cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
Dan Williams18c96c342007-06-18 12:01:12 -0400444 else
David Woodhouse4f59abf2007-12-18 00:47:17 -0500445 cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400446 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200447 }
448
David Woodhouse4f59abf2007-12-18 00:47:17 -0500449 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
450 if (!ret && cmd_action == CMD_ACT_GET)
451 *enable = le16_to_cpu(cmd.enable);
452
453 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
454 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200455}
456
David Woodhouse9e1228d2008-03-03 12:15:39 +0100457static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
458 struct enc_key *key)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200459{
Holger Schurig8ff12da2007-08-02 11:54:31 -0400460 lbs_deb_enter(LBS_DEB_CMD);
461
David Woodhouse9e1228d2008-03-03 12:15:39 +0100462 if (key->flags & KEY_INFO_WPA_ENABLED)
463 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
464 if (key->flags & KEY_INFO_WPA_UNICAST)
465 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
466 if (key->flags & KEY_INFO_WPA_MCAST)
467 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200468
David Woodhouse9e1228d2008-03-03 12:15:39 +0100469 keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
470 keyparam->keytypeid = cpu_to_le16(key->type);
471 keyparam->keylen = cpu_to_le16(key->len);
472 memcpy(keyparam->key, key->key, key->len);
473
474 /* Length field doesn't include the {type,length} header */
475 keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400476 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200477}
478
David Woodhouse9e1228d2008-03-03 12:15:39 +0100479int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
480 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481{
David Woodhouse9e1228d2008-03-03 12:15:39 +0100482 struct cmd_ds_802_11_key_material cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200483 int ret = 0;
484 int index = 0;
485
Holger Schurig9012b282007-05-25 11:27:16 -0400486 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200487
David Woodhouse9e1228d2008-03-03 12:15:39 +0100488 cmd.action = cpu_to_le16(cmd_action);
489 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200490
Dan Williams0aef64d2007-08-02 11:31:18 -0400491 if (cmd_action == CMD_ACT_GET) {
David Woodhouse9e1228d2008-03-03 12:15:39 +0100492 cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
493 } else {
494 memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
495
496 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
497 set_one_wpa_key(&cmd.keyParamSet[index],
498 &assoc->wpa_unicast_key);
499 index++;
500 }
501
502 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
503 set_one_wpa_key(&cmd.keyParamSet[index],
504 &assoc->wpa_mcast_key);
505 index++;
506 }
507
508 /* The common header and as many keys as we included */
509 cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
510 keyParamSet[index]));
511 }
512 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
513 /* Copy the returned key to driver private data */
514 if (!ret && cmd_action == CMD_ACT_GET) {
515 void *buf_ptr = cmd.keyParamSet;
516 void *resp_end = &(&cmd)[1];
517
518 while (buf_ptr < resp_end) {
519 struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
520 struct enc_key *key;
521 uint16_t param_set_len = le16_to_cpu(keyparam->length);
522 uint16_t key_len = le16_to_cpu(keyparam->keylen);
523 uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
524 uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
525 void *end;
526
527 end = (void *)keyparam + sizeof(keyparam->type)
528 + sizeof(keyparam->length) + param_set_len;
529
530 /* Make sure we don't access past the end of the IEs */
531 if (end > resp_end)
532 break;
533
534 if (key_flags & KEY_INFO_WPA_UNICAST)
535 key = &priv->wpa_unicast_key;
536 else if (key_flags & KEY_INFO_WPA_MCAST)
537 key = &priv->wpa_mcast_key;
538 else
539 break;
540
541 /* Copy returned key into driver */
542 memset(key, 0, sizeof(struct enc_key));
543 if (key_len > sizeof(key->key))
544 break;
545 key->type = key_type;
546 key->flags = key_flags;
547 key->len = key_len;
548 memcpy(key->key, keyparam->key, key->len);
549
550 buf_ptr = end + 1;
551 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200552 }
553
Holger Schurig9012b282007-05-25 11:27:16 -0400554 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200555 return ret;
556}
557
Dan Williams39fcf7a2008-09-10 12:49:00 -0400558/**
559 * @brief Set an SNMP MIB value
560 *
561 * @param priv A pointer to struct lbs_private structure
562 * @param oid The OID to set in the firmware
563 * @param val Value to set the OID to
564 *
565 * @return 0 on success, error on failure
566 */
567int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200568{
Dan Williams39fcf7a2008-09-10 12:49:00 -0400569 struct cmd_ds_802_11_snmp_mib cmd;
570 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200571
Holger Schurig9012b282007-05-25 11:27:16 -0400572 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200573
Dan Williams39fcf7a2008-09-10 12:49:00 -0400574 memset(&cmd, 0, sizeof (cmd));
575 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
576 cmd.action = cpu_to_le16(CMD_ACT_SET);
577 cmd.oid = cpu_to_le16((u16) oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200578
Dan Williams39fcf7a2008-09-10 12:49:00 -0400579 switch (oid) {
580 case SNMP_MIB_OID_BSS_TYPE:
581 cmd.bufsize = cpu_to_le16(sizeof(u8));
582 cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200583 break;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400584 case SNMP_MIB_OID_11D_ENABLE:
585 case SNMP_MIB_OID_FRAG_THRESHOLD:
586 case SNMP_MIB_OID_RTS_THRESHOLD:
587 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
588 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
589 cmd.bufsize = cpu_to_le16(sizeof(u16));
590 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200591 break;
592 default:
Dan Williams39fcf7a2008-09-10 12:49:00 -0400593 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
594 ret = -EINVAL;
595 goto out;
596 }
597
598 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
599 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
600
601 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
602
603out:
604 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
605 return ret;
606}
607
608/**
609 * @brief Get an SNMP MIB value
610 *
611 * @param priv A pointer to struct lbs_private structure
612 * @param oid The OID to retrieve from the firmware
613 * @param out_val Location for the returned value
614 *
615 * @return 0 on success, error on failure
616 */
617int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
618{
619 struct cmd_ds_802_11_snmp_mib cmd;
620 int ret;
621
622 lbs_deb_enter(LBS_DEB_CMD);
623
624 memset(&cmd, 0, sizeof (cmd));
625 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
626 cmd.action = cpu_to_le16(CMD_ACT_GET);
627 cmd.oid = cpu_to_le16(oid);
628
629 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
630 if (ret)
631 goto out;
632
633 switch (le16_to_cpu(cmd.bufsize)) {
634 case sizeof(u8):
635 if (oid == SNMP_MIB_OID_BSS_TYPE) {
636 if (cmd.value[0] == 2)
637 *out_val = IW_MODE_ADHOC;
638 else
639 *out_val = IW_MODE_INFRA;
640 } else
641 *out_val = cmd.value[0];
642 break;
643 case sizeof(u16):
644 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
645 break;
646 default:
647 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
648 oid, le16_to_cpu(cmd.bufsize));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200649 break;
650 }
651
Dan Williams39fcf7a2008-09-10 12:49:00 -0400652out:
653 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
654 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200655}
656
Dan Williams87c8c722008-08-19 15:15:35 -0400657/**
658 * @brief Get the min, max, and current TX power
659 *
660 * @param priv A pointer to struct lbs_private structure
661 * @param curlevel Current power level in dBm
662 * @param minlevel Minimum supported power level in dBm (optional)
663 * @param maxlevel Maximum supported power level in dBm (optional)
664 *
665 * @return 0 on success, error on failure
666 */
667int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
668 s16 *maxlevel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200669{
Dan Williams87c8c722008-08-19 15:15:35 -0400670 struct cmd_ds_802_11_rf_tx_power cmd;
671 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200672
Holger Schurig9012b282007-05-25 11:27:16 -0400673 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200674
Dan Williams87c8c722008-08-19 15:15:35 -0400675 memset(&cmd, 0, sizeof(cmd));
676 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
677 cmd.action = cpu_to_le16(CMD_ACT_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200678
Dan Williams87c8c722008-08-19 15:15:35 -0400679 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
680 if (ret == 0) {
681 *curlevel = le16_to_cpu(cmd.curlevel);
682 if (minlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100683 *minlevel = cmd.minlevel;
Dan Williams87c8c722008-08-19 15:15:35 -0400684 if (maxlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100685 *maxlevel = cmd.maxlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200686 }
Holger Schurig9012b282007-05-25 11:27:16 -0400687
688 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams87c8c722008-08-19 15:15:35 -0400689 return ret;
690}
691
692/**
693 * @brief Set the TX power
694 *
695 * @param priv A pointer to struct lbs_private structure
696 * @param dbm The desired power level in dBm
697 *
698 * @return 0 on success, error on failure
699 */
700int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
701{
702 struct cmd_ds_802_11_rf_tx_power cmd;
703 int ret;
704
705 lbs_deb_enter(LBS_DEB_CMD);
706
707 memset(&cmd, 0, sizeof(cmd));
708 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
709 cmd.action = cpu_to_le16(CMD_ACT_SET);
710 cmd.curlevel = cpu_to_le16(dbm);
711
712 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
713
714 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
715
716 lbs_deb_leave(LBS_DEB_CMD);
717 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200718}
719
Holger Schurige98a88d2008-03-19 14:25:58 +0100720static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400721 u16 cmd_action, void *pdata_buf)
722{
723 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
724
725 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
726 cmd->size =
727 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
728 S_DS_GEN);
729
730 monitor->action = cpu_to_le16(cmd_action);
731 if (cmd_action == CMD_ACT_SET) {
732 monitor->mode =
733 cpu_to_le16((u16) (*(u32 *) pdata_buf));
734 }
735
736 return 0;
737}
738
Javier Cardona85319f92008-05-24 10:59:49 +0100739static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200740{
Javier Cardona85319f92008-05-24 10:59:49 +0100741/* Bit Rate
742* 15:13 Reserved
743* 12 54 Mbps
744* 11 48 Mbps
745* 10 36 Mbps
746* 9 24 Mbps
747* 8 18 Mbps
748* 7 12 Mbps
749* 6 9 Mbps
750* 5 6 Mbps
751* 4 Reserved
752* 3 11 Mbps
753* 2 5.5 Mbps
754* 1 2 Mbps
755* 0 1 Mbps
756**/
757
758 uint16_t ratemask;
759 int i = lbs_data_rate_to_fw_index(rate);
760 if (lower_rates_ok)
761 ratemask = (0x1fef >> (12 - i));
762 else
763 ratemask = (1 << i);
764 return cpu_to_le16(ratemask);
765}
766
767int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
768 uint16_t cmd_action)
769{
770 struct cmd_ds_802_11_rate_adapt_rateset cmd;
771 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200772
Holger Schurig8ff12da2007-08-02 11:54:31 -0400773 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200774
Javier Cardona85319f92008-05-24 10:59:49 +0100775 if (!priv->cur_rate && !priv->enablehwauto)
776 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200777
Javier Cardona85319f92008-05-24 10:59:49 +0100778 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
779
780 cmd.action = cpu_to_le16(cmd_action);
781 cmd.enablehwauto = cpu_to_le16(priv->enablehwauto);
782 cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto);
783 ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd);
784 if (!ret && cmd_action == CMD_ACT_GET) {
785 priv->ratebitmap = le16_to_cpu(cmd.bitmap);
786 priv->enablehwauto = le16_to_cpu(cmd.enablehwauto);
787 }
788
789 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
790 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200791}
Javier Cardona85319f92008-05-24 10:59:49 +0100792EXPORT_SYMBOL_GPL(lbs_cmd_802_11_rate_adapt_rateset);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200793
Dan Williams8e3c91b2007-12-11 15:50:59 -0500794/**
Dan Williams8e3c91b2007-12-11 15:50:59 -0500795 * @brief Set the data rate
796 *
797 * @param priv A pointer to struct lbs_private structure
798 * @param rate The desired data rate, or 0 to clear a locked rate
799 *
800 * @return 0 on success, error on failure
801 */
802int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
803{
804 struct cmd_ds_802_11_data_rate cmd;
805 int ret = 0;
806
807 lbs_deb_enter(LBS_DEB_CMD);
808
809 memset(&cmd, 0, sizeof(cmd));
810 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
811
812 if (rate > 0) {
813 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
814 cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
815 if (cmd.rates[0] == 0) {
816 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
817 " 0x%02X\n", rate);
818 ret = 0;
819 goto out;
820 }
821 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
822 } else {
823 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400824 lbs_deb_cmd("DATA_RATE: setting auto\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200825 }
826
David Woodhouse689442d2007-12-12 16:00:42 -0500827 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
Dan Williams8e3c91b2007-12-11 15:50:59 -0500828 if (ret)
829 goto out;
830
831 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
832
833 /* FIXME: get actual rates FW can do if this command actually returns
834 * all data rates supported.
835 */
836 priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
837 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
838
839out:
840 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
841 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200842}
843
Dan Williams2dd4b262007-12-11 16:54:15 -0500844/**
845 * @brief Get the radio channel
846 *
847 * @param priv A pointer to struct lbs_private structure
848 *
849 * @return The channel on success, error on failure
850 */
Holger Schuriga3cbfb02009-10-16 17:33:56 +0200851static int lbs_get_channel(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200852{
Dan Williams2dd4b262007-12-11 16:54:15 -0500853 struct cmd_ds_802_11_rf_channel cmd;
854 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200855
Holger Schurig8ff12da2007-08-02 11:54:31 -0400856 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200857
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200858 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500859 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
860 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200861
David Woodhouse689442d2007-12-12 16:00:42 -0500862 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500863 if (ret)
864 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200865
Dan Williamscb182a62007-12-11 17:35:51 -0500866 ret = le16_to_cpu(cmd.channel);
867 lbs_deb_cmd("current radio channel is %d\n", ret);
Dan Williams2dd4b262007-12-11 16:54:15 -0500868
869out:
870 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
871 return ret;
872}
873
Holger Schurig73ab1f22008-04-02 16:52:19 +0200874int lbs_update_channel(struct lbs_private *priv)
875{
876 int ret;
877
878 /* the channel in f/w could be out of sync; get the current channel */
879 lbs_deb_enter(LBS_DEB_ASSOC);
880
881 ret = lbs_get_channel(priv);
882 if (ret > 0) {
883 priv->curbssparams.channel = ret;
884 ret = 0;
885 }
886 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
887 return ret;
888}
889
Dan Williams2dd4b262007-12-11 16:54:15 -0500890/**
891 * @brief Set the radio channel
892 *
893 * @param priv A pointer to struct lbs_private structure
894 * @param channel The desired channel, or 0 to clear a locked channel
895 *
896 * @return 0 on success, error on failure
897 */
898int lbs_set_channel(struct lbs_private *priv, u8 channel)
899{
900 struct cmd_ds_802_11_rf_channel cmd;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530901#ifdef DEBUG
Dan Williams2dd4b262007-12-11 16:54:15 -0500902 u8 old_channel = priv->curbssparams.channel;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530903#endif
Dan Williams2dd4b262007-12-11 16:54:15 -0500904 int ret = 0;
905
906 lbs_deb_enter(LBS_DEB_CMD);
907
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200908 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500909 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
910 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
911 cmd.channel = cpu_to_le16(channel);
912
David Woodhouse689442d2007-12-12 16:00:42 -0500913 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500914 if (ret)
915 goto out;
916
Dan Williamscb182a62007-12-11 17:35:51 -0500917 priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
918 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
919 priv->curbssparams.channel);
Dan Williams2dd4b262007-12-11 16:54:15 -0500920
921out:
922 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
923 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200924}
925
Holger Schurig69f90322007-11-23 15:43:44 +0100926static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200927 struct cmd_ds_command *cmd)
928{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200929
Holger Schurig8ff12da2007-08-02 11:54:31 -0400930 lbs_deb_enter(LBS_DEB_CMD);
Dan Williams0aef64d2007-08-02 11:31:18 -0400931 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
David Woodhouse981f1872007-05-25 23:36:54 -0400932 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
Holger Schuriga783f1e2007-08-02 13:08:24 -0400933 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200934
935 /* reset Beacon SNR/NF/RSSI values */
David Woodhouseaa21c002007-12-08 20:04:36 +0000936 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
937 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
938 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
939 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
940 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
941 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200942
Holger Schurig8ff12da2007-08-02 11:54:31 -0400943 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200944 return 0;
945}
946
Holger Schurige98a88d2008-03-19 14:25:58 +0100947static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200948 u8 cmd_action, void *pdata_buf)
949{
Holger Schurig10078322007-11-15 18:05:47 -0500950 struct lbs_offset_value *offval;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200951
Holger Schurig9012b282007-05-25 11:27:16 -0400952 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200953
Holger Schurig10078322007-11-15 18:05:47 -0500954 offval = (struct lbs_offset_value *)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200955
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000956 switch (le16_to_cpu(cmdptr->command)) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400957 case CMD_MAC_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200958 {
959 struct cmd_ds_mac_reg_access *macreg;
960
961 cmdptr->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400962 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
963 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200964 macreg =
965 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
966 macreg;
967
968 macreg->action = cpu_to_le16(cmd_action);
969 macreg->offset = cpu_to_le16((u16) offval->offset);
970 macreg->value = cpu_to_le32(offval->value);
971
972 break;
973 }
974
Dan Williams0aef64d2007-08-02 11:31:18 -0400975 case CMD_BBP_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200976 {
977 struct cmd_ds_bbp_reg_access *bbpreg;
978
979 cmdptr->size =
980 cpu_to_le16(sizeof
981 (struct cmd_ds_bbp_reg_access)
982 + S_DS_GEN);
983 bbpreg =
984 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
985 bbpreg;
986
987 bbpreg->action = cpu_to_le16(cmd_action);
988 bbpreg->offset = cpu_to_le16((u16) offval->offset);
989 bbpreg->value = (u8) offval->value;
990
991 break;
992 }
993
Dan Williams0aef64d2007-08-02 11:31:18 -0400994 case CMD_RF_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200995 {
996 struct cmd_ds_rf_reg_access *rfreg;
997
998 cmdptr->size =
999 cpu_to_le16(sizeof
1000 (struct cmd_ds_rf_reg_access) +
1001 S_DS_GEN);
1002 rfreg =
1003 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
1004 rfreg;
1005
1006 rfreg->action = cpu_to_le16(cmd_action);
1007 rfreg->offset = cpu_to_le16((u16) offval->offset);
1008 rfreg->value = (u8) offval->value;
1009
1010 break;
1011 }
1012
1013 default:
1014 break;
1015 }
1016
Holger Schurig9012b282007-05-25 11:27:16 -04001017 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001018 return 0;
1019}
1020
Holger Schurige98a88d2008-03-19 14:25:58 +01001021static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001022 u16 cmd_action, void *pdata_buf)
1023{
1024 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
Holger Schurig8ff12da2007-08-02 11:54:31 -04001025 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001026
Dan Williams0aef64d2007-08-02 11:31:18 -04001027 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -04001028 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001029 cmd->result = 0;
1030 bt_access->action = cpu_to_le16(cmd_action);
1031
1032 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -04001033 case CMD_ACT_BT_ACCESS_ADD:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001034 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -04001035 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001036 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001037 case CMD_ACT_BT_ACCESS_DEL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001038 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -04001039 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001040 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001041 case CMD_ACT_BT_ACCESS_LIST:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001042 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
1043 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001044 case CMD_ACT_BT_ACCESS_RESET:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001045 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001046 case CMD_ACT_BT_ACCESS_SET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -04001047 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
1048 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001049 case CMD_ACT_BT_ACCESS_GET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -04001050 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001051 default:
1052 break;
1053 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001054 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001055 return 0;
1056}
1057
Holger Schurige98a88d2008-03-19 14:25:58 +01001058static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001059 u16 cmd_action, void *pdata_buf)
1060{
1061 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
Holger Schurig8ff12da2007-08-02 11:54:31 -04001062 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001063
Dan Williams0aef64d2007-08-02 11:31:18 -04001064 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -04001065 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001066 cmd->result = 0;
1067
1068 if (pdata_buf)
1069 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
1070 else
1071 memset(fwt_access, 0, sizeof(*fwt_access));
1072
1073 fwt_access->action = cpu_to_le16(cmd_action);
1074
Holger Schurig8ff12da2007-08-02 11:54:31 -04001075 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001076 return 0;
1077}
1078
David Woodhouse301eacb2007-12-11 15:23:59 -05001079int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
1080 struct cmd_ds_mesh_access *cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001081{
David Woodhouse301eacb2007-12-11 15:23:59 -05001082 int ret;
1083
Holger Schurig8ff12da2007-08-02 11:54:31 -04001084 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001085
David Woodhouse301eacb2007-12-11 15:23:59 -05001086 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
David Woodhouse9fae8992007-12-15 03:46:44 -05001087 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
David Woodhouse301eacb2007-12-11 15:23:59 -05001088 cmd->hdr.result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001089
David Woodhouse301eacb2007-12-11 15:23:59 -05001090 cmd->action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001091
David Woodhouse689442d2007-12-12 16:00:42 -05001092 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001093
Holger Schurig8ff12da2007-08-02 11:54:31 -04001094 lbs_deb_leave(LBS_DEB_CMD);
David Woodhouse301eacb2007-12-11 15:23:59 -05001095 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001096}
1097
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001098static int __lbs_mesh_config_send(struct lbs_private *priv,
1099 struct cmd_ds_mesh_config *cmd,
1100 uint16_t action, uint16_t type)
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001101{
1102 int ret;
Bing Zhao684d6b32009-03-25 09:51:16 -07001103 u16 command = CMD_MESH_CONFIG_OLD;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001104
1105 lbs_deb_enter(LBS_DEB_CMD);
1106
Bing Zhao684d6b32009-03-25 09:51:16 -07001107 /*
1108 * Command id is 0xac for v10 FW along with mesh interface
1109 * id in bits 14-13-12.
1110 */
1111 if (priv->mesh_fw_ver == MESH_FW_NEW)
1112 command = CMD_MESH_CONFIG |
1113 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
1114
1115 cmd->hdr.command = cpu_to_le16(command);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001116 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
1117 cmd->hdr.result = 0;
1118
1119 cmd->type = cpu_to_le16(type);
1120 cmd->action = cpu_to_le16(action);
1121
Bing Zhao684d6b32009-03-25 09:51:16 -07001122 ret = lbs_cmd_with_response(priv, command, cmd);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001123
1124 lbs_deb_leave(LBS_DEB_CMD);
1125 return ret;
1126}
1127
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001128int lbs_mesh_config_send(struct lbs_private *priv,
1129 struct cmd_ds_mesh_config *cmd,
1130 uint16_t action, uint16_t type)
1131{
1132 int ret;
1133
1134 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
1135 return -EOPNOTSUPP;
1136
1137 ret = __lbs_mesh_config_send(priv, cmd, action, type);
1138 return ret;
1139}
1140
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001141/* This function is the CMD_MESH_CONFIG legacy function. It only handles the
1142 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
1143 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
1144 * lbs_mesh_config_send.
1145 */
1146int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
David Woodhouse23a397a2007-12-11 18:56:42 -05001147{
1148 struct cmd_ds_mesh_config cmd;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001149 struct mrvl_meshie *ie;
John W. Linville9387b7c2008-09-30 20:59:05 -04001150 DECLARE_SSID_BUF(ssid);
David Woodhouse23a397a2007-12-11 18:56:42 -05001151
1152 memset(&cmd, 0, sizeof(cmd));
David Woodhouse86062132007-12-13 00:32:36 -05001153 cmd.channel = cpu_to_le16(chan);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001154 ie = (struct mrvl_meshie *)cmd.data;
David Woodhouse7e226272007-12-14 22:53:41 -05001155
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001156 switch (action) {
1157 case CMD_ACT_MESH_CONFIG_START:
Johannes Berg2c7060022008-10-30 22:09:54 +01001158 ie->id = WLAN_EID_GENERIC;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001159 ie->val.oui[0] = 0x00;
1160 ie->val.oui[1] = 0x50;
1161 ie->val.oui[2] = 0x43;
1162 ie->val.type = MARVELL_MESH_IE_TYPE;
1163 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
1164 ie->val.version = MARVELL_MESH_IE_VERSION;
1165 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
1166 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
1167 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
1168 ie->val.mesh_id_len = priv->mesh_ssid_len;
1169 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
Johannes Berg2c7060022008-10-30 22:09:54 +01001170 ie->len = sizeof(struct mrvl_meshie_val) -
Holger Schurig243e84e2009-10-22 15:30:47 +02001171 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001172 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
1173 break;
1174 case CMD_ACT_MESH_CONFIG_STOP:
1175 break;
1176 default:
1177 return -1;
David Woodhouse23a397a2007-12-11 18:56:42 -05001178 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001179 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
1180 action, priv->mesh_tlv, chan,
John W. Linville9387b7c2008-09-30 20:59:05 -04001181 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001182
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001183 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
David Woodhouse23a397a2007-12-11 18:56:42 -05001184}
1185
Brajesh Dave96287ac2007-11-20 17:44:28 -05001186static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
1187 struct cmd_ds_command *cmd,
1188 u16 cmd_action)
1189{
1190 struct cmd_ds_802_11_beacon_control
1191 *bcn_ctrl = &cmd->params.bcn_ctrl;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001192
1193 lbs_deb_enter(LBS_DEB_CMD);
1194 cmd->size =
1195 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
1196 + S_DS_GEN);
1197 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
1198
1199 bcn_ctrl->action = cpu_to_le16(cmd_action);
David Woodhouseaa21c002007-12-08 20:04:36 +00001200 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
1201 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
Brajesh Dave96287ac2007-11-20 17:44:28 -05001202
1203 lbs_deb_leave(LBS_DEB_CMD);
1204 return 0;
1205}
1206
David Woodhouse681ffbb2007-12-15 20:04:54 -05001207static void lbs_queue_cmd(struct lbs_private *priv,
1208 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001209{
1210 unsigned long flags;
David Woodhouse681ffbb2007-12-15 20:04:54 -05001211 int addtail = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001212
Holger Schurig8ff12da2007-08-02 11:54:31 -04001213 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001214
David Woodhousec4ab4122007-12-15 00:41:51 -05001215 if (!cmdnode) {
1216 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001217 goto done;
1218 }
David Woodhoused9896ee2007-12-15 00:09:25 -05001219 if (!cmdnode->cmdbuf->size) {
1220 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
1221 goto done;
1222 }
David Woodhouseae125bf2007-12-15 04:22:52 -05001223 cmdnode->result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001224
1225 /* Exit_PS command needs to be queued in the header always. */
Dan Williamsddac4522007-12-11 13:49:39 -05001226 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
David Woodhouse38bfab12007-12-16 23:26:54 -05001227 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
Dan Williamsddac4522007-12-11 13:49:39 -05001228
Dan Williams0aef64d2007-08-02 11:31:18 -04001229 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001230 if (priv->psstate != PS_STATE_FULL_POWER)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001231 addtail = 0;
1232 }
1233 }
1234
David Woodhouseaa21c002007-12-08 20:04:36 +00001235 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001236
David Woodhouseac472462007-12-08 00:35:00 +00001237 if (addtail)
David Woodhouseaa21c002007-12-08 20:04:36 +00001238 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
David Woodhouseac472462007-12-08 00:35:00 +00001239 else
David Woodhouseaa21c002007-12-08 20:04:36 +00001240 list_add(&cmdnode->list, &priv->cmdpendingq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001241
David Woodhouseaa21c002007-12-08 20:04:36 +00001242 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001243
Holger Schurig8ff12da2007-08-02 11:54:31 -04001244 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
David Woodhousec4ab4122007-12-15 00:41:51 -05001245 le16_to_cpu(cmdnode->cmdbuf->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001246
1247done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001248 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001249}
1250
David Woodhouse18c52e72007-12-17 16:03:58 -05001251static void lbs_submit_command(struct lbs_private *priv,
1252 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001253{
1254 unsigned long flags;
Dan Williamsddac4522007-12-11 13:49:39 -05001255 struct cmd_header *cmd;
David Woodhouse18c52e72007-12-17 16:03:58 -05001256 uint16_t cmdsize;
1257 uint16_t command;
Holger Schurig57962f02008-05-14 16:30:28 +02001258 int timeo = 3 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -05001259 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001260
Holger Schurig8ff12da2007-08-02 11:54:31 -04001261 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001262
Dan Williamsddac4522007-12-11 13:49:39 -05001263 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001264
David Woodhouseaa21c002007-12-08 20:04:36 +00001265 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001266 priv->cur_cmd = cmdnode;
1267 priv->cur_cmd_retcode = 0;
1268 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001269
Dan Williamsddac4522007-12-11 13:49:39 -05001270 cmdsize = le16_to_cpu(cmd->size);
1271 command = le16_to_cpu(cmd->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001272
David Woodhouse18c52e72007-12-17 16:03:58 -05001273 /* These commands take longer */
Dan Williamsbe0d76e2009-05-22 20:05:25 -04001274 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
Holger Schurig57962f02008-05-14 16:30:28 +02001275 timeo = 5 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -05001276
Holger Schurige5225b32008-03-26 10:04:44 +01001277 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
1278 command, le16_to_cpu(cmd->seqnum), cmdsize);
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001279 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001280
Dan Williamsddac4522007-12-11 13:49:39 -05001281 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
David Woodhouse18c52e72007-12-17 16:03:58 -05001282
David Woodhoused9896ee2007-12-15 00:09:25 -05001283 if (ret) {
1284 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
David Woodhouse18c52e72007-12-17 16:03:58 -05001285 /* Let the timer kick in and retry, and potentially reset
1286 the whole thing if the condition persists */
Holger Schurig57962f02008-05-14 16:30:28 +02001287 timeo = HZ/4;
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001288 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001289
Amitkumar Karwar49125452009-09-30 20:04:38 -07001290 if (command == CMD_802_11_DEEP_SLEEP) {
1291 if (priv->is_auto_deep_sleep_enabled) {
1292 priv->wakeup_dev_required = 1;
1293 priv->dnld_sent = 0;
1294 }
1295 priv->is_deep_sleep = 1;
1296 lbs_complete_command(priv, cmdnode, 0);
1297 } else {
1298 /* Setup the timer after transmit command */
1299 mod_timer(&priv->command_timer, jiffies + timeo);
1300 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001301
David Woodhouse18c52e72007-12-17 16:03:58 -05001302 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001303}
1304
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001305/**
1306 * This function inserts command node to cmdfreeq
David Woodhouseaa21c002007-12-08 20:04:36 +00001307 * after cleans it. Requires priv->driver_lock held.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001308 */
David Woodhouse183aeac2007-12-15 01:52:54 -05001309static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001310 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001311{
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001312 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001313
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001314 if (!cmdnode)
1315 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001316
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001317 cmdnode->callback = NULL;
1318 cmdnode->callback_arg = 0;
1319
1320 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
1321
1322 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
1323 out:
1324 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001325}
1326
Holger Schurig69f90322007-11-23 15:43:44 +01001327static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1328 struct cmd_ctrl_node *ptempcmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001329{
1330 unsigned long flags;
1331
David Woodhouseaa21c002007-12-08 20:04:36 +00001332 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig10078322007-11-15 18:05:47 -05001333 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
David Woodhouseaa21c002007-12-08 20:04:36 +00001334 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001335}
1336
David Woodhouse183aeac2007-12-15 01:52:54 -05001337void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1338 int result)
1339{
1340 if (cmd == priv->cur_cmd)
1341 priv->cur_cmd_retcode = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001342
David Woodhouseae125bf2007-12-15 04:22:52 -05001343 cmd->result = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001344 cmd->cmdwaitqwoken = 1;
1345 wake_up_interruptible(&cmd->cmdwait_q);
1346
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001347 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
David Woodhousead12d0f2007-12-15 02:06:16 -05001348 __lbs_cleanup_and_insert_cmd(priv, cmd);
David Woodhouse183aeac2007-12-15 01:52:54 -05001349 priv->cur_cmd = NULL;
1350}
1351
Dan Williamsd5db2df2008-08-21 17:51:07 -04001352int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001353{
David Woodhousea7c45892007-12-17 22:43:48 -05001354 struct cmd_ds_802_11_radio_control cmd;
Dan Williamsd5db2df2008-08-21 17:51:07 -04001355 int ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001356
Holger Schurig9012b282007-05-25 11:27:16 -04001357 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001358
David Woodhousea7c45892007-12-17 22:43:48 -05001359 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1360 cmd.action = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001361
Dan Williamsd5db2df2008-08-21 17:51:07 -04001362 /* Only v8 and below support setting the preamble */
1363 if (priv->fwrelease < 0x09000000) {
1364 switch (preamble) {
1365 case RADIO_PREAMBLE_SHORT:
1366 if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
1367 goto out;
1368 /* Fall through */
1369 case RADIO_PREAMBLE_AUTO:
1370 case RADIO_PREAMBLE_LONG:
1371 cmd.control = cpu_to_le16(preamble);
1372 break;
1373 default:
1374 goto out;
1375 }
David Woodhousea7c45892007-12-17 22:43:48 -05001376 }
1377
Dan Williamsd5db2df2008-08-21 17:51:07 -04001378 if (radio_on)
1379 cmd.control |= cpu_to_le16(0x1);
1380 else {
1381 cmd.control &= cpu_to_le16(~0x1);
1382 priv->txpower_cur = 0;
1383 }
David Woodhousea7c45892007-12-17 22:43:48 -05001384
Dan Williamsd5db2df2008-08-21 17:51:07 -04001385 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1386 radio_on ? "ON" : "OFF", preamble);
1387
1388 priv->radio_on = radio_on;
David Woodhousea7c45892007-12-17 22:43:48 -05001389
1390 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001391
Dan Williamsd5db2df2008-08-21 17:51:07 -04001392out:
Holger Schurig9012b282007-05-25 11:27:16 -04001393 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001394 return ret;
1395}
1396
Holger Schurigc97329e2008-03-18 11:20:21 +01001397void lbs_set_mac_control(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001398{
Holger Schurig835d3ac2008-03-12 16:05:40 +01001399 struct cmd_ds_mac_control cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001400
Holger Schurig9012b282007-05-25 11:27:16 -04001401 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001402
Holger Schurig835d3ac2008-03-12 16:05:40 +01001403 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Holger Schurigd9e97782008-03-12 16:06:43 +01001404 cmd.action = cpu_to_le16(priv->mac_control);
Holger Schurig835d3ac2008-03-12 16:05:40 +01001405 cmd.reserved = 0;
1406
David Woodhouse75bf45a2008-05-20 13:32:45 +01001407 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001408
Holger Schurigc97329e2008-03-18 11:20:21 +01001409 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001410}
1411
1412/**
1413 * @brief This function prepare the command before send to firmware.
1414 *
Holger Schurig69f90322007-11-23 15:43:44 +01001415 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001416 * @param cmd_no command number
1417 * @param cmd_action command action: GET or SET
1418 * @param wait_option wait option: wait response or not
1419 * @param cmd_oid cmd oid: treated as sub command
1420 * @param pdata_buf A pointer to informaion buffer
1421 * @return 0 or -1
1422 */
Holger Schurig69f90322007-11-23 15:43:44 +01001423int lbs_prepare_and_send_command(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001424 u16 cmd_no,
1425 u16 cmd_action,
1426 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1427{
1428 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001429 struct cmd_ctrl_node *cmdnode;
1430 struct cmd_ds_command *cmdptr;
1431 unsigned long flags;
1432
Holger Schurig8ff12da2007-08-02 11:54:31 -04001433 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001434
David Woodhouseaa21c002007-12-08 20:04:36 +00001435 if (!priv) {
1436 lbs_deb_host("PREP_CMD: priv is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001437 ret = -1;
1438 goto done;
1439 }
1440
David Woodhouseaa21c002007-12-08 20:04:36 +00001441 if (priv->surpriseremoved) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001442 lbs_deb_host("PREP_CMD: card removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001443 ret = -1;
1444 goto done;
1445 }
1446
Amitkumar Karwar63f275d2009-10-06 19:20:28 -07001447 if (!lbs_is_cmd_allowed(priv)) {
1448 ret = -EBUSY;
1449 goto done;
1450 }
1451
Holger Schurig0d61d042007-12-05 17:58:06 +01001452 cmdnode = lbs_get_cmd_ctrl_node(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001453
1454 if (cmdnode == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001455 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001456
1457 /* Wake up main thread to execute next command */
Dan Williamsfe336152007-08-02 11:32:25 -04001458 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001459 ret = -1;
1460 goto done;
1461 }
1462
Holger Schurige98a88d2008-03-19 14:25:58 +01001463 cmdnode->callback = NULL;
1464 cmdnode->callback_arg = (unsigned long)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001465
Dan Williamsddac4522007-12-11 13:49:39 -05001466 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001467
Holger Schurig8ff12da2007-08-02 11:54:31 -04001468 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001469
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001470 /* Set sequence number, command and INT option */
David Woodhouseaa21c002007-12-08 20:04:36 +00001471 priv->seqnum++;
1472 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001473
David Woodhouse981f1872007-05-25 23:36:54 -04001474 cmdptr->command = cpu_to_le16(cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001475 cmdptr->result = 0;
1476
1477 switch (cmd_no) {
Dan Williams0aef64d2007-08-02 11:31:18 -04001478 case CMD_802_11_PS_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001479 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001480 break;
1481
Dan Williams0aef64d2007-08-02 11:31:18 -04001482 case CMD_MAC_REG_ACCESS:
1483 case CMD_BBP_REG_ACCESS:
1484 case CMD_RF_REG_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001485 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001486 break;
1487
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001488 case CMD_802_11_MONITOR_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001489 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001490 cmd_action, pdata_buf);
1491 break;
1492
Dan Williams0aef64d2007-08-02 11:31:18 -04001493 case CMD_802_11_RSSI:
Holger Schurig10078322007-11-15 18:05:47 -05001494 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001495 break;
1496
Dan Williams0aef64d2007-08-02 11:31:18 -04001497 case CMD_802_11_SET_AFC:
1498 case CMD_802_11_GET_AFC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001499
1500 cmdptr->command = cpu_to_le16(cmd_no);
David Woodhouse981f1872007-05-25 23:36:54 -04001501 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1502 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001503
1504 memmove(&cmdptr->params.afc,
1505 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1506
1507 ret = 0;
1508 goto done;
1509
Dan Williams0aef64d2007-08-02 11:31:18 -04001510 case CMD_802_11_TPC_CFG:
1511 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001512 cmdptr->size =
1513 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1514 S_DS_GEN);
1515
1516 memmove(&cmdptr->params.tpccfg,
1517 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1518
1519 ret = 0;
1520 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001521 case CMD_802_11_LED_GPIO_CTRL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001522 {
Dan Williams75b6a612009-05-22 20:03:09 -04001523 struct mrvl_ie_ledgpio *gpio =
1524 (struct mrvl_ie_ledgpio*)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001525 cmdptr->params.ledgpio.data;
1526
1527 memmove(&cmdptr->params.ledgpio,
1528 pdata_buf,
1529 sizeof(struct cmd_ds_802_11_led_ctrl));
1530
1531 cmdptr->command =
Dan Williams0aef64d2007-08-02 11:31:18 -04001532 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001533
1534#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1535 cmdptr->size =
Holger Schurigc2df2ef2007-12-07 15:30:44 +00001536 cpu_to_le16(le16_to_cpu(gpio->header.len)
1537 + S_DS_GEN
1538 + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1539 gpio->header.len = gpio->header.len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001540
1541 ret = 0;
1542 break;
1543 }
David Woodhouse5844d122007-12-18 02:01:37 -05001544
Dan Williams0aef64d2007-08-02 11:31:18 -04001545 case CMD_BT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001546 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001547 break;
1548
Dan Williams0aef64d2007-08-02 11:31:18 -04001549 case CMD_FWT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001550 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001551 break;
1552
Dan Williams0aef64d2007-08-02 11:31:18 -04001553 case CMD_GET_TSF:
1554 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
David Woodhouse981f1872007-05-25 23:36:54 -04001555 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1556 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001557 ret = 0;
1558 break;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001559 case CMD_802_11_BEACON_CTRL:
1560 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1561 break;
Amitkumar Karwar49125452009-09-30 20:04:38 -07001562 case CMD_802_11_DEEP_SLEEP:
1563 cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP);
1564 cmdptr->size = cpu_to_le16(S_DS_GEN);
1565 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001566 default:
David Woodhousee37fc6e2008-05-20 11:47:16 +01001567 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001568 ret = -1;
1569 break;
1570 }
1571
1572 /* return error, since the command preparation failed */
1573 if (ret != 0) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001574 lbs_deb_host("PREP_CMD: command preparation failed\n");
Holger Schurig10078322007-11-15 18:05:47 -05001575 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001576 ret = -1;
1577 goto done;
1578 }
1579
1580 cmdnode->cmdwaitqwoken = 0;
1581
David Woodhouse681ffbb2007-12-15 20:04:54 -05001582 lbs_queue_cmd(priv, cmdnode);
Dan Williamsfe336152007-08-02 11:32:25 -04001583 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001584
Dan Williams0aef64d2007-08-02 11:31:18 -04001585 if (wait_option & CMD_OPTION_WAITFORRSP) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001586 lbs_deb_host("PREP_CMD: wait for response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001587 might_sleep();
1588 wait_event_interruptible(cmdnode->cmdwait_q,
1589 cmdnode->cmdwaitqwoken);
1590 }
1591
David Woodhouseaa21c002007-12-08 20:04:36 +00001592 spin_lock_irqsave(&priv->driver_lock, flags);
1593 if (priv->cur_cmd_retcode) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001594 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001595 priv->cur_cmd_retcode);
1596 priv->cur_cmd_retcode = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001597 ret = -1;
1598 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001599 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001600
1601done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001602 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001603 return ret;
1604}
1605
1606/**
1607 * @brief This function allocates the command buffer and link
1608 * it to command free queue.
1609 *
Holger Schurig69f90322007-11-23 15:43:44 +01001610 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001611 * @return 0 or -1
1612 */
Holger Schurig69f90322007-11-23 15:43:44 +01001613int lbs_allocate_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001614{
1615 int ret = 0;
Dan Williamsddac4522007-12-11 13:49:39 -05001616 u32 bufsize;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001617 u32 i;
Dan Williamsddac4522007-12-11 13:49:39 -05001618 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001619
Holger Schurig8ff12da2007-08-02 11:54:31 -04001620 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001621
Dan Williamsddac4522007-12-11 13:49:39 -05001622 /* Allocate and initialize the command array */
1623 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1624 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001625 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001626 ret = -1;
1627 goto done;
1628 }
Dan Williamsddac4522007-12-11 13:49:39 -05001629 priv->cmd_array = cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001630
Dan Williamsddac4522007-12-11 13:49:39 -05001631 /* Allocate and initialize each command buffer in the command array */
1632 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1633 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1634 if (!cmdarray[i].cmdbuf) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001635 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001636 ret = -1;
1637 goto done;
1638 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001639 }
1640
Dan Williamsddac4522007-12-11 13:49:39 -05001641 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1642 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1643 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001644 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001645 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001646
1647done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001648 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001649 return ret;
1650}
1651
1652/**
1653 * @brief This function frees the command buffer.
1654 *
Holger Schurig69f90322007-11-23 15:43:44 +01001655 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001656 * @return 0 or -1
1657 */
Holger Schurig69f90322007-11-23 15:43:44 +01001658int lbs_free_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001659{
Dan Williamsddac4522007-12-11 13:49:39 -05001660 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001661 unsigned int i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001662
Holger Schurig8ff12da2007-08-02 11:54:31 -04001663 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001664
1665 /* need to check if cmd array is allocated or not */
David Woodhouseaa21c002007-12-08 20:04:36 +00001666 if (priv->cmd_array == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001667 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001668 goto done;
1669 }
1670
Dan Williamsddac4522007-12-11 13:49:39 -05001671 cmdarray = priv->cmd_array;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001672
1673 /* Release shared memory buffers */
Dan Williamsddac4522007-12-11 13:49:39 -05001674 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1675 if (cmdarray[i].cmdbuf) {
1676 kfree(cmdarray[i].cmdbuf);
1677 cmdarray[i].cmdbuf = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001678 }
1679 }
1680
1681 /* Release cmd_ctrl_node */
David Woodhouseaa21c002007-12-08 20:04:36 +00001682 if (priv->cmd_array) {
1683 kfree(priv->cmd_array);
1684 priv->cmd_array = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001685 }
1686
1687done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001688 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001689 return 0;
1690}
1691
1692/**
1693 * @brief This function gets a free command node if available in
1694 * command free queue.
1695 *
Holger Schurig69f90322007-11-23 15:43:44 +01001696 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001697 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1698 */
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001699static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001700{
1701 struct cmd_ctrl_node *tempnode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001702 unsigned long flags;
1703
Holger Schurig8ff12da2007-08-02 11:54:31 -04001704 lbs_deb_enter(LBS_DEB_HOST);
1705
David Woodhouseaa21c002007-12-08 20:04:36 +00001706 if (!priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001707 return NULL;
1708
David Woodhouseaa21c002007-12-08 20:04:36 +00001709 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001710
David Woodhouseaa21c002007-12-08 20:04:36 +00001711 if (!list_empty(&priv->cmdfreeq)) {
1712 tempnode = list_first_entry(&priv->cmdfreeq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001713 struct cmd_ctrl_node, list);
1714 list_del(&tempnode->list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001715 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001716 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001717 tempnode = NULL;
1718 }
1719
David Woodhouseaa21c002007-12-08 20:04:36 +00001720 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001721
Holger Schurig8ff12da2007-08-02 11:54:31 -04001722 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001723 return tempnode;
1724}
1725
1726/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001727 * @brief This function executes next command in command
Nick Andrew877d0312009-01-26 11:06:57 +01001728 * pending queue. It will put firmware back to PS mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001729 * if applicable.
1730 *
Holger Schurig69f90322007-11-23 15:43:44 +01001731 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001732 * @return 0 or -1
1733 */
Holger Schurig69f90322007-11-23 15:43:44 +01001734int lbs_execute_next_command(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001735{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001736 struct cmd_ctrl_node *cmdnode = NULL;
Dan Williamsddac4522007-12-11 13:49:39 -05001737 struct cmd_header *cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001738 unsigned long flags;
1739 int ret = 0;
1740
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001741 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1742 * only caller to us is lbs_thread() and we get even when a
1743 * data packet is received */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001744 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001745
David Woodhouseaa21c002007-12-08 20:04:36 +00001746 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001747
David Woodhouseaa21c002007-12-08 20:04:36 +00001748 if (priv->cur_cmd) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001749 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001750 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001751 ret = -1;
1752 goto done;
1753 }
1754
David Woodhouseaa21c002007-12-08 20:04:36 +00001755 if (!list_empty(&priv->cmdpendingq)) {
1756 cmdnode = list_first_entry(&priv->cmdpendingq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001757 struct cmd_ctrl_node, list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001758 }
1759
David Woodhouseaa21c002007-12-08 20:04:36 +00001760 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001761
1762 if (cmdnode) {
Dan Williamsddac4522007-12-11 13:49:39 -05001763 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001764
Dan Williamsddac4522007-12-11 13:49:39 -05001765 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001766 if ((priv->psstate == PS_STATE_SLEEP) ||
1767 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001768 lbs_deb_host(
1769 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001770 le16_to_cpu(cmd->command),
David Woodhouseaa21c002007-12-08 20:04:36 +00001771 priv->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001772 ret = -1;
1773 goto done;
1774 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001775 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
Dan Williamsddac4522007-12-11 13:49:39 -05001776 "0x%04x in psstate %d\n",
1777 le16_to_cpu(cmd->command), priv->psstate);
David Woodhouseaa21c002007-12-08 20:04:36 +00001778 } else if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001779 /*
1780 * 1. Non-PS command:
1781 * Queue it. set needtowakeup to TRUE if current state
Holger Schurig10078322007-11-15 18:05:47 -05001782 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001783 * 2. PS command but not Exit_PS:
1784 * Ignore it.
1785 * 3. PS command Exit_PS:
1786 * Set needtowakeup to TRUE if current state is SLEEP,
1787 * otherwise send this command down to firmware
1788 * immediately.
1789 */
Dan Williamsddac4522007-12-11 13:49:39 -05001790 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001791 /* Prepare to send Exit PS,
1792 * this non PS command will be sent later */
David Woodhouseaa21c002007-12-08 20:04:36 +00001793 if ((priv->psstate == PS_STATE_SLEEP)
1794 || (priv->psstate == PS_STATE_PRE_SLEEP)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001795 ) {
1796 /* w/ new scheme, it will not reach here.
1797 since it is blocked in main_thread. */
David Woodhouseaa21c002007-12-08 20:04:36 +00001798 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001799 } else
Holger Schurig10078322007-11-15 18:05:47 -05001800 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001801
1802 ret = 0;
1803 goto done;
1804 } else {
1805 /*
1806 * PS command. Ignore it if it is not Exit_PS.
1807 * otherwise send it down immediately.
1808 */
David Woodhouse38bfab12007-12-16 23:26:54 -05001809 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001810
Holger Schurig8ff12da2007-08-02 11:54:31 -04001811 lbs_deb_host(
1812 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001813 psm->action);
1814 if (psm->action !=
Dan Williams0aef64d2007-08-02 11:31:18 -04001815 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001816 lbs_deb_host(
1817 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001818 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001819 spin_lock_irqsave(&priv->driver_lock, flags);
1820 lbs_complete_command(priv, cmdnode, 0);
1821 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001822
1823 ret = 0;
1824 goto done;
1825 }
1826
David Woodhouseaa21c002007-12-08 20:04:36 +00001827 if ((priv->psstate == PS_STATE_SLEEP) ||
1828 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001829 lbs_deb_host(
1830 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001831 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001832 spin_lock_irqsave(&priv->driver_lock, flags);
1833 lbs_complete_command(priv, cmdnode, 0);
1834 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001835 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001836
1837 ret = 0;
1838 goto done;
1839 }
1840
Holger Schurig8ff12da2007-08-02 11:54:31 -04001841 lbs_deb_host(
1842 "EXEC_NEXT_CMD: sending EXIT_PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001843 }
1844 }
Li Zefanabe3ed12007-12-06 13:01:21 +01001845 list_del(&cmdnode->list);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001846 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001847 le16_to_cpu(cmd->command));
David Woodhoused9896ee2007-12-15 00:09:25 -05001848 lbs_submit_command(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001849 } else {
1850 /*
1851 * check if in power save mode, if yes, put the device back
1852 * to PS mode
1853 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001854 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1855 (priv->psstate == PS_STATE_FULL_POWER) &&
1856 ((priv->connect_status == LBS_CONNECTED) ||
1857 (priv->mesh_connect_status == LBS_CONNECTED))) {
1858 if (priv->secinfo.WPAenabled ||
1859 priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001860 /* check for valid WPA group keys */
David Woodhouseaa21c002007-12-08 20:04:36 +00001861 if (priv->wpa_mcast_key.len ||
1862 priv->wpa_unicast_key.len) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001863 lbs_deb_host(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001864 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1865 " go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001866 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001867 }
1868 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001869 lbs_deb_host(
1870 "EXEC_NEXT_CMD: cmdpendingq empty, "
1871 "go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001872 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001873 }
1874 }
1875 }
1876
1877 ret = 0;
1878done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001879 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001880 return ret;
1881}
1882
Holger Schurig69f90322007-11-23 15:43:44 +01001883void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001884{
1885 union iwreq_data iwrq;
1886 u8 buf[50];
1887
Holger Schurig8ff12da2007-08-02 11:54:31 -04001888 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001889
1890 memset(&iwrq, 0, sizeof(union iwreq_data));
1891 memset(buf, 0, sizeof(buf));
1892
1893 snprintf(buf, sizeof(buf) - 1, "%s", str);
1894
1895 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1896
1897 /* Send Event to upper layer */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001898 lbs_deb_wext("event indication string %s\n", (char *)buf);
1899 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1900 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001901
Holger Schurig634b8f42007-05-25 13:05:16 -04001902 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001903
Holger Schurig8ff12da2007-08-02 11:54:31 -04001904 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001905}
1906
Holger Schurigf539f2e2008-03-26 13:22:11 +01001907static void lbs_send_confirmsleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001908{
1909 unsigned long flags;
Holger Schurigf539f2e2008-03-26 13:22:11 +01001910 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001911
Holger Schurig8ff12da2007-08-02 11:54:31 -04001912 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurigf539f2e2008-03-26 13:22:11 +01001913 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1914 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001915
Holger Schurigf539f2e2008-03-26 13:22:11 +01001916 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1917 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001918 if (ret) {
Holger Schurigf539f2e2008-03-26 13:22:11 +01001919 lbs_pr_alert("confirm_sleep failed\n");
Holger Schurig7919b892008-04-01 14:50:43 +02001920 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001921 }
Holger Schurig7919b892008-04-01 14:50:43 +02001922
1923 spin_lock_irqsave(&priv->driver_lock, flags);
1924
Holger Schuriga01f5452008-06-04 11:10:40 +02001925 /* We don't get a response on the sleep-confirmation */
1926 priv->dnld_sent = DNLD_RES_RECEIVED;
1927
Holger Schurig7919b892008-04-01 14:50:43 +02001928 /* If nothing to do, go back to sleep (?) */
1929 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1930 priv->psstate = PS_STATE_SLEEP;
1931
1932 spin_unlock_irqrestore(&priv->driver_lock, flags);
1933
1934out:
Holger Schurigf539f2e2008-03-26 13:22:11 +01001935 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001936}
1937
Holger Schurig69f90322007-11-23 15:43:44 +01001938void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001939{
Holger Schurig8ff12da2007-08-02 11:54:31 -04001940 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001941
1942 /*
1943 * PS is currently supported only in Infrastructure mode
1944 * Remove this check if it is to be supported in IBSS mode also
1945 */
1946
Holger Schurig10078322007-11-15 18:05:47 -05001947 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001948 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001949
Holger Schurig8ff12da2007-08-02 11:54:31 -04001950 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001951}
1952
1953/**
Holger Schurig8ff12da2007-08-02 11:54:31 -04001954 * @brief This function sends Exit_PS command to firmware.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001955 *
Holger Schurig69f90322007-11-23 15:43:44 +01001956 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001957 * @param wait_option wait response or not
1958 * @return n/a
1959 */
Holger Schurig69f90322007-11-23 15:43:44 +01001960void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001961{
David Woodhouse981f1872007-05-25 23:36:54 -04001962 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001963
Holger Schurig8ff12da2007-08-02 11:54:31 -04001964 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001965
Holger Schurig10078322007-11-15 18:05:47 -05001966 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001967
Holger Schurig10078322007-11-15 18:05:47 -05001968 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001969 CMD_SUBCMD_EXIT_PS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001970 wait_option, 0, &Localpsmode);
1971
Holger Schurig8ff12da2007-08-02 11:54:31 -04001972 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001973}
1974
1975/**
1976 * @brief This function checks condition and prepares to
1977 * send sleep confirm command to firmware if ok.
1978 *
Holger Schurig69f90322007-11-23 15:43:44 +01001979 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001980 * @param psmode Power Saving mode
1981 * @return n/a
1982 */
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001983void lbs_ps_confirm_sleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001984{
1985 unsigned long flags =0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001986 int allowed = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001987
Holger Schurig8ff12da2007-08-02 11:54:31 -04001988 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001989
Holger Schuriga01f5452008-06-04 11:10:40 +02001990 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig634b8f42007-05-25 13:05:16 -04001991 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001992 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001993 lbs_deb_host("dnld_sent was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001994 }
1995
Holger Schurig7919b892008-04-01 14:50:43 +02001996 /* In-progress command? */
David Woodhouseaa21c002007-12-08 20:04:36 +00001997 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001998 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001999 lbs_deb_host("cur_cmd was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002000 }
Holger Schurig7919b892008-04-01 14:50:43 +02002001
2002 /* Pending events or command responses? */
2003 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002004 allowed = 0;
Holger Schurig7919b892008-04-01 14:50:43 +02002005 lbs_deb_host("pending events or command responses\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002006 }
David Woodhouseaa21c002007-12-08 20:04:36 +00002007 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002008
2009 if (allowed) {
Holger Schurig10078322007-11-15 18:05:47 -05002010 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
Holger Schurigf539f2e2008-03-26 13:22:11 +01002011 lbs_send_confirmsleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002012 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04002013 lbs_deb_host("sleep confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002014 }
2015
Holger Schurig8ff12da2007-08-02 11:54:31 -04002016 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002017}
Holger Schurig675787e2007-12-05 17:58:11 +01002018
2019
Anna Neal0112c9e2008-09-11 11:17:25 -07002020/**
2021 * @brief Configures the transmission power control functionality.
2022 *
2023 * @param priv A pointer to struct lbs_private structure
2024 * @param enable Transmission power control enable
2025 * @param p0 Power level when link quality is good (dBm).
2026 * @param p1 Power level when link quality is fair (dBm).
2027 * @param p2 Power level when link quality is poor (dBm).
2028 * @param usesnr Use Signal to Noise Ratio in TPC
2029 *
2030 * @return 0 on success
2031 */
2032int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
2033 int8_t p2, int usesnr)
2034{
2035 struct cmd_ds_802_11_tpc_cfg cmd;
2036 int ret;
2037
2038 memset(&cmd, 0, sizeof(cmd));
2039 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
2040 cmd.action = cpu_to_le16(CMD_ACT_SET);
2041 cmd.enable = !!enable;
Anna Neal3ed6e082008-09-26 11:34:35 -04002042 cmd.usesnr = !!usesnr;
Anna Neal0112c9e2008-09-11 11:17:25 -07002043 cmd.P0 = p0;
2044 cmd.P1 = p1;
2045 cmd.P2 = p2;
2046
2047 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
2048
2049 return ret;
2050}
2051
2052/**
2053 * @brief Configures the power adaptation settings.
2054 *
2055 * @param priv A pointer to struct lbs_private structure
2056 * @param enable Power adaptation enable
2057 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
2058 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
2059 * @param p2 Power level for 48 and 54 Mbps (dBm).
2060 *
2061 * @return 0 on Success
2062 */
2063
2064int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
2065 int8_t p1, int8_t p2)
2066{
2067 struct cmd_ds_802_11_pa_cfg cmd;
2068 int ret;
2069
2070 memset(&cmd, 0, sizeof(cmd));
2071 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
2072 cmd.action = cpu_to_le16(CMD_ACT_SET);
2073 cmd.enable = !!enable;
2074 cmd.P0 = p0;
2075 cmd.P1 = p1;
2076 cmd.P2 = p2;
2077
2078 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
2079
2080 return ret;
2081}
2082
2083
Holger Schurig6d898b12009-10-14 16:49:53 +02002084struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
Holger Schurig8db4a2b2008-03-19 10:11:00 +01002085 uint16_t command, 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)
Holger Schurig675787e2007-12-05 17:58:11 +01002088{
Holger Schurig675787e2007-12-05 17:58:11 +01002089 struct cmd_ctrl_node *cmdnode;
Holger Schurig675787e2007-12-05 17:58:11 +01002090
2091 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurig675787e2007-12-05 17:58:11 +01002092
David Woodhouseaa21c002007-12-08 20:04:36 +00002093 if (priv->surpriseremoved) {
Holger Schurig675787e2007-12-05 17:58:11 +01002094 lbs_deb_host("PREP_CMD: card removed\n");
David Woodhouse3399ea52007-12-15 03:09:33 -05002095 cmdnode = ERR_PTR(-ENOENT);
Holger Schurig675787e2007-12-05 17:58:11 +01002096 goto done;
2097 }
2098
Amitkumar Karwar63f275d2009-10-06 19:20:28 -07002099 if (!lbs_is_cmd_allowed(priv)) {
2100 cmdnode = ERR_PTR(-EBUSY);
2101 goto done;
2102 }
2103
Holger Schurig675787e2007-12-05 17:58:11 +01002104 cmdnode = lbs_get_cmd_ctrl_node(priv);
Holger Schurig675787e2007-12-05 17:58:11 +01002105 if (cmdnode == NULL) {
2106 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
2107
2108 /* Wake up main thread to execute next command */
2109 wake_up_interruptible(&priv->waitq);
David Woodhouse3399ea52007-12-15 03:09:33 -05002110 cmdnode = ERR_PTR(-ENOBUFS);
Holger Schurig675787e2007-12-05 17:58:11 +01002111 goto done;
2112 }
2113
David Woodhouse448a51a2007-12-08 00:59:54 +00002114 cmdnode->callback = callback;
David Woodhouse1309b552007-12-10 13:36:10 -05002115 cmdnode->callback_arg = callback_arg;
Holger Schurig675787e2007-12-05 17:58:11 +01002116
Dan Williams7ad994d2007-12-11 12:33:30 -05002117 /* Copy the incoming command to the buffer */
Dan Williamsddac4522007-12-11 13:49:39 -05002118 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
Dan Williams7ad994d2007-12-11 12:33:30 -05002119
Holger Schurig675787e2007-12-05 17:58:11 +01002120 /* Set sequence number, clean result, move to buffer */
David Woodhouseaa21c002007-12-08 20:04:36 +00002121 priv->seqnum++;
Dan Williamsddac4522007-12-11 13:49:39 -05002122 cmdnode->cmdbuf->command = cpu_to_le16(command);
2123 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
2124 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
2125 cmdnode->cmdbuf->result = 0;
Holger Schurig675787e2007-12-05 17:58:11 +01002126
2127 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
2128
Holger Schurig675787e2007-12-05 17:58:11 +01002129 cmdnode->cmdwaitqwoken = 0;
David Woodhouse681ffbb2007-12-15 20:04:54 -05002130 lbs_queue_cmd(priv, cmdnode);
Holger Schurig675787e2007-12-05 17:58:11 +01002131 wake_up_interruptible(&priv->waitq);
2132
David Woodhouse3399ea52007-12-15 03:09:33 -05002133 done:
2134 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
2135 return cmdnode;
2136}
2137
Holger Schurig8db4a2b2008-03-19 10:11:00 +01002138void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
2139 struct cmd_header *in_cmd, int in_cmd_size)
2140{
2141 lbs_deb_enter(LBS_DEB_CMD);
2142 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2143 lbs_cmd_async_callback, 0);
2144 lbs_deb_leave(LBS_DEB_CMD);
2145}
2146
David Woodhouse3399ea52007-12-15 03:09:33 -05002147int __lbs_cmd(struct lbs_private *priv, uint16_t command,
2148 struct cmd_header *in_cmd, int in_cmd_size,
2149 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
2150 unsigned long callback_arg)
2151{
2152 struct cmd_ctrl_node *cmdnode;
2153 unsigned long flags;
2154 int ret = 0;
2155
2156 lbs_deb_enter(LBS_DEB_HOST);
2157
2158 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2159 callback, callback_arg);
2160 if (IS_ERR(cmdnode)) {
2161 ret = PTR_ERR(cmdnode);
2162 goto done;
2163 }
2164
Holger Schurig675787e2007-12-05 17:58:11 +01002165 might_sleep();
2166 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
2167
David Woodhouseaa21c002007-12-08 20:04:36 +00002168 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseae125bf2007-12-15 04:22:52 -05002169 ret = cmdnode->result;
2170 if (ret)
2171 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
2172 command, ret);
David Woodhouse3399ea52007-12-15 03:09:33 -05002173
David Woodhousead12d0f2007-12-15 02:06:16 -05002174 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
David Woodhouseaa21c002007-12-08 20:04:36 +00002175 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig675787e2007-12-05 17:58:11 +01002176
2177done:
2178 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
2179 return ret;
2180}
Dan Williams14e865b2007-12-10 15:11:23 -05002181EXPORT_SYMBOL_GPL(__lbs_cmd);
Holger Schurig675787e2007-12-05 17:58:11 +01002182
2183