blob: 5326483b50d28e3f17812d161c0a8d4396191c40 [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) +
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200242 sizeof(struct cmd_header));
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
Dan Williams39fcf7a2008-09-10 12:49:00 -0400367/**
368 * @brief Set an SNMP MIB value
369 *
370 * @param priv A pointer to struct lbs_private structure
371 * @param oid The OID to set in the firmware
372 * @param val Value to set the OID to
373 *
374 * @return 0 on success, error on failure
375 */
376int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200377{
Dan Williams39fcf7a2008-09-10 12:49:00 -0400378 struct cmd_ds_802_11_snmp_mib cmd;
379 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200380
Holger Schurig9012b282007-05-25 11:27:16 -0400381 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200382
Dan Williams39fcf7a2008-09-10 12:49:00 -0400383 memset(&cmd, 0, sizeof (cmd));
384 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
385 cmd.action = cpu_to_le16(CMD_ACT_SET);
386 cmd.oid = cpu_to_le16((u16) oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200387
Dan Williams39fcf7a2008-09-10 12:49:00 -0400388 switch (oid) {
389 case SNMP_MIB_OID_BSS_TYPE:
390 cmd.bufsize = cpu_to_le16(sizeof(u8));
391 cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392 break;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400393 case SNMP_MIB_OID_11D_ENABLE:
394 case SNMP_MIB_OID_FRAG_THRESHOLD:
395 case SNMP_MIB_OID_RTS_THRESHOLD:
396 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
397 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
398 cmd.bufsize = cpu_to_le16(sizeof(u16));
399 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400 break;
401 default:
Dan Williams39fcf7a2008-09-10 12:49:00 -0400402 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
403 ret = -EINVAL;
404 goto out;
405 }
406
407 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
408 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
409
410 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
411
412out:
413 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
414 return ret;
415}
416
417/**
418 * @brief Get an SNMP MIB value
419 *
420 * @param priv A pointer to struct lbs_private structure
421 * @param oid The OID to retrieve from the firmware
422 * @param out_val Location for the returned value
423 *
424 * @return 0 on success, error on failure
425 */
426int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
427{
428 struct cmd_ds_802_11_snmp_mib cmd;
429 int ret;
430
431 lbs_deb_enter(LBS_DEB_CMD);
432
433 memset(&cmd, 0, sizeof (cmd));
434 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
435 cmd.action = cpu_to_le16(CMD_ACT_GET);
436 cmd.oid = cpu_to_le16(oid);
437
438 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
439 if (ret)
440 goto out;
441
442 switch (le16_to_cpu(cmd.bufsize)) {
443 case sizeof(u8):
444 if (oid == SNMP_MIB_OID_BSS_TYPE) {
445 if (cmd.value[0] == 2)
446 *out_val = IW_MODE_ADHOC;
447 else
448 *out_val = IW_MODE_INFRA;
449 } else
450 *out_val = cmd.value[0];
451 break;
452 case sizeof(u16):
453 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
454 break;
455 default:
456 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
457 oid, le16_to_cpu(cmd.bufsize));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200458 break;
459 }
460
Dan Williams39fcf7a2008-09-10 12:49:00 -0400461out:
462 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
463 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464}
465
Dan Williams87c8c722008-08-19 15:15:35 -0400466/**
467 * @brief Get the min, max, and current TX power
468 *
469 * @param priv A pointer to struct lbs_private structure
470 * @param curlevel Current power level in dBm
471 * @param minlevel Minimum supported power level in dBm (optional)
472 * @param maxlevel Maximum supported power level in dBm (optional)
473 *
474 * @return 0 on success, error on failure
475 */
476int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
477 s16 *maxlevel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200478{
Dan Williams87c8c722008-08-19 15:15:35 -0400479 struct cmd_ds_802_11_rf_tx_power cmd;
480 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481
Holger Schurig9012b282007-05-25 11:27:16 -0400482 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200483
Dan Williams87c8c722008-08-19 15:15:35 -0400484 memset(&cmd, 0, sizeof(cmd));
485 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
486 cmd.action = cpu_to_le16(CMD_ACT_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200487
Dan Williams87c8c722008-08-19 15:15:35 -0400488 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
489 if (ret == 0) {
490 *curlevel = le16_to_cpu(cmd.curlevel);
491 if (minlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100492 *minlevel = cmd.minlevel;
Dan Williams87c8c722008-08-19 15:15:35 -0400493 if (maxlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100494 *maxlevel = cmd.maxlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200495 }
Holger Schurig9012b282007-05-25 11:27:16 -0400496
497 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams87c8c722008-08-19 15:15:35 -0400498 return ret;
499}
500
501/**
502 * @brief Set the TX power
503 *
504 * @param priv A pointer to struct lbs_private structure
505 * @param dbm The desired power level in dBm
506 *
507 * @return 0 on success, error on failure
508 */
509int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
510{
511 struct cmd_ds_802_11_rf_tx_power cmd;
512 int ret;
513
514 lbs_deb_enter(LBS_DEB_CMD);
515
516 memset(&cmd, 0, sizeof(cmd));
517 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
518 cmd.action = cpu_to_le16(CMD_ACT_SET);
519 cmd.curlevel = cpu_to_le16(dbm);
520
521 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
522
523 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
524
525 lbs_deb_leave(LBS_DEB_CMD);
526 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200527}
528
Holger Schurige98a88d2008-03-19 14:25:58 +0100529static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400530 u16 cmd_action, void *pdata_buf)
531{
532 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
533
534 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
535 cmd->size =
536 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200537 sizeof(struct cmd_header));
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400538
539 monitor->action = cpu_to_le16(cmd_action);
540 if (cmd_action == CMD_ACT_SET) {
541 monitor->mode =
542 cpu_to_le16((u16) (*(u32 *) pdata_buf));
543 }
544
545 return 0;
546}
547
Dan Williams2dd4b262007-12-11 16:54:15 -0500548/**
549 * @brief Get the radio channel
550 *
551 * @param priv A pointer to struct lbs_private structure
552 *
553 * @return The channel on success, error on failure
554 */
Holger Schuriga3cbfb02009-10-16 17:33:56 +0200555static int lbs_get_channel(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200556{
Dan Williams2dd4b262007-12-11 16:54:15 -0500557 struct cmd_ds_802_11_rf_channel cmd;
558 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200559
Holger Schurig8ff12da2007-08-02 11:54:31 -0400560 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200561
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200562 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500563 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
564 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200565
David Woodhouse689442d2007-12-12 16:00:42 -0500566 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500567 if (ret)
568 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200569
Dan Williamscb182a62007-12-11 17:35:51 -0500570 ret = le16_to_cpu(cmd.channel);
571 lbs_deb_cmd("current radio channel is %d\n", ret);
Dan Williams2dd4b262007-12-11 16:54:15 -0500572
573out:
574 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
575 return ret;
576}
577
Holger Schurig73ab1f22008-04-02 16:52:19 +0200578int lbs_update_channel(struct lbs_private *priv)
579{
580 int ret;
581
582 /* the channel in f/w could be out of sync; get the current channel */
583 lbs_deb_enter(LBS_DEB_ASSOC);
584
585 ret = lbs_get_channel(priv);
586 if (ret > 0) {
Holger Schurigc14951f2009-10-22 15:30:50 +0200587 priv->channel = ret;
Holger Schurig73ab1f22008-04-02 16:52:19 +0200588 ret = 0;
589 }
590 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
591 return ret;
592}
593
Dan Williams2dd4b262007-12-11 16:54:15 -0500594/**
595 * @brief Set the radio channel
596 *
597 * @param priv A pointer to struct lbs_private structure
598 * @param channel The desired channel, or 0 to clear a locked channel
599 *
600 * @return 0 on success, error on failure
601 */
602int lbs_set_channel(struct lbs_private *priv, u8 channel)
603{
604 struct cmd_ds_802_11_rf_channel cmd;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530605#ifdef DEBUG
Holger Schurigc14951f2009-10-22 15:30:50 +0200606 u8 old_channel = priv->channel;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530607#endif
Dan Williams2dd4b262007-12-11 16:54:15 -0500608 int ret = 0;
609
610 lbs_deb_enter(LBS_DEB_CMD);
611
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200612 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500613 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
614 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
615 cmd.channel = cpu_to_le16(channel);
616
David Woodhouse689442d2007-12-12 16:00:42 -0500617 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500618 if (ret)
619 goto out;
620
Holger Schurigc14951f2009-10-22 15:30:50 +0200621 priv->channel = (uint8_t) le16_to_cpu(cmd.channel);
Dan Williamscb182a62007-12-11 17:35:51 -0500622 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
Holger Schurigc14951f2009-10-22 15:30:50 +0200623 priv->channel);
Dan Williams2dd4b262007-12-11 16:54:15 -0500624
625out:
626 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
627 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200628}
629
Holger Schurige98a88d2008-03-19 14:25:58 +0100630static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200631 u8 cmd_action, void *pdata_buf)
632{
Holger Schurig10078322007-11-15 18:05:47 -0500633 struct lbs_offset_value *offval;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200634
Holger Schurig9012b282007-05-25 11:27:16 -0400635 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200636
Holger Schurig10078322007-11-15 18:05:47 -0500637 offval = (struct lbs_offset_value *)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200638
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000639 switch (le16_to_cpu(cmdptr->command)) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400640 case CMD_MAC_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641 {
642 struct cmd_ds_mac_reg_access *macreg;
643
644 cmdptr->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400645 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200646 + sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200647 macreg =
648 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
649 macreg;
650
651 macreg->action = cpu_to_le16(cmd_action);
652 macreg->offset = cpu_to_le16((u16) offval->offset);
653 macreg->value = cpu_to_le32(offval->value);
654
655 break;
656 }
657
Dan Williams0aef64d2007-08-02 11:31:18 -0400658 case CMD_BBP_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200659 {
660 struct cmd_ds_bbp_reg_access *bbpreg;
661
662 cmdptr->size =
663 cpu_to_le16(sizeof
664 (struct cmd_ds_bbp_reg_access)
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200665 + sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200666 bbpreg =
667 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
668 bbpreg;
669
670 bbpreg->action = cpu_to_le16(cmd_action);
671 bbpreg->offset = cpu_to_le16((u16) offval->offset);
672 bbpreg->value = (u8) offval->value;
673
674 break;
675 }
676
Dan Williams0aef64d2007-08-02 11:31:18 -0400677 case CMD_RF_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200678 {
679 struct cmd_ds_rf_reg_access *rfreg;
680
681 cmdptr->size =
682 cpu_to_le16(sizeof
683 (struct cmd_ds_rf_reg_access) +
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200684 sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200685 rfreg =
686 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
687 rfreg;
688
689 rfreg->action = cpu_to_le16(cmd_action);
690 rfreg->offset = cpu_to_le16((u16) offval->offset);
691 rfreg->value = (u8) offval->value;
692
693 break;
694 }
695
696 default:
697 break;
698 }
699
Holger Schurig9012b282007-05-25 11:27:16 -0400700 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200701 return 0;
702}
703
Holger Schurige98a88d2008-03-19 14:25:58 +0100704static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200705 u16 cmd_action, void *pdata_buf)
706{
707 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400708 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709
Dan Williams0aef64d2007-08-02 11:31:18 -0400710 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200711 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) +
712 sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200713 cmd->result = 0;
714 bt_access->action = cpu_to_le16(cmd_action);
715
716 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400717 case CMD_ACT_BT_ACCESS_ADD:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200718 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400719 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200720 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400721 case CMD_ACT_BT_ACCESS_DEL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200722 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400723 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200724 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400725 case CMD_ACT_BT_ACCESS_LIST:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200726 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
727 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400728 case CMD_ACT_BT_ACCESS_RESET:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200729 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400730 case CMD_ACT_BT_ACCESS_SET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -0400731 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
732 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400733 case CMD_ACT_BT_ACCESS_GET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -0400734 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200735 default:
736 break;
737 }
Holger Schurig8ff12da2007-08-02 11:54:31 -0400738 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200739 return 0;
740}
741
Holger Schurige98a88d2008-03-19 14:25:58 +0100742static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200743 u16 cmd_action, void *pdata_buf)
744{
745 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400746 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200747
Dan Williams0aef64d2007-08-02 11:31:18 -0400748 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
Holger Schurig8ec97cc2009-10-22 15:30:55 +0200749 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) +
750 sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200751 cmd->result = 0;
752
753 if (pdata_buf)
754 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
755 else
756 memset(fwt_access, 0, sizeof(*fwt_access));
757
758 fwt_access->action = cpu_to_le16(cmd_action);
759
Holger Schurig8ff12da2007-08-02 11:54:31 -0400760 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200761 return 0;
762}
763
David Woodhouse301eacb2007-12-11 15:23:59 -0500764int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
765 struct cmd_ds_mesh_access *cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200766{
David Woodhouse301eacb2007-12-11 15:23:59 -0500767 int ret;
768
Holger Schurig8ff12da2007-08-02 11:54:31 -0400769 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200770
David Woodhouse301eacb2007-12-11 15:23:59 -0500771 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
David Woodhouse9fae8992007-12-15 03:46:44 -0500772 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
David Woodhouse301eacb2007-12-11 15:23:59 -0500773 cmd->hdr.result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200774
David Woodhouse301eacb2007-12-11 15:23:59 -0500775 cmd->action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200776
David Woodhouse689442d2007-12-12 16:00:42 -0500777 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200778
Holger Schurig8ff12da2007-08-02 11:54:31 -0400779 lbs_deb_leave(LBS_DEB_CMD);
David Woodhouse301eacb2007-12-11 15:23:59 -0500780 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200781}
782
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -0700783static int __lbs_mesh_config_send(struct lbs_private *priv,
784 struct cmd_ds_mesh_config *cmd,
785 uint16_t action, uint16_t type)
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700786{
787 int ret;
Bing Zhao684d6b32009-03-25 09:51:16 -0700788 u16 command = CMD_MESH_CONFIG_OLD;
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700789
790 lbs_deb_enter(LBS_DEB_CMD);
791
Bing Zhao684d6b32009-03-25 09:51:16 -0700792 /*
793 * Command id is 0xac for v10 FW along with mesh interface
794 * id in bits 14-13-12.
795 */
796 if (priv->mesh_fw_ver == MESH_FW_NEW)
797 command = CMD_MESH_CONFIG |
798 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
799
800 cmd->hdr.command = cpu_to_le16(command);
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700801 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
802 cmd->hdr.result = 0;
803
804 cmd->type = cpu_to_le16(type);
805 cmd->action = cpu_to_le16(action);
806
Bing Zhao684d6b32009-03-25 09:51:16 -0700807 ret = lbs_cmd_with_response(priv, command, cmd);
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700808
809 lbs_deb_leave(LBS_DEB_CMD);
810 return ret;
811}
812
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -0700813int lbs_mesh_config_send(struct lbs_private *priv,
814 struct cmd_ds_mesh_config *cmd,
815 uint16_t action, uint16_t type)
816{
817 int ret;
818
819 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
820 return -EOPNOTSUPP;
821
822 ret = __lbs_mesh_config_send(priv, cmd, action, type);
823 return ret;
824}
825
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700826/* This function is the CMD_MESH_CONFIG legacy function. It only handles the
827 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
828 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
829 * lbs_mesh_config_send.
830 */
831int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
David Woodhouse23a397a2007-12-11 18:56:42 -0500832{
833 struct cmd_ds_mesh_config cmd;
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700834 struct mrvl_meshie *ie;
John W. Linville9387b7c2008-09-30 20:59:05 -0400835 DECLARE_SSID_BUF(ssid);
David Woodhouse23a397a2007-12-11 18:56:42 -0500836
837 memset(&cmd, 0, sizeof(cmd));
David Woodhouse86062132007-12-13 00:32:36 -0500838 cmd.channel = cpu_to_le16(chan);
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700839 ie = (struct mrvl_meshie *)cmd.data;
David Woodhouse7e226272007-12-14 22:53:41 -0500840
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700841 switch (action) {
842 case CMD_ACT_MESH_CONFIG_START:
Johannes Berg2c7060022008-10-30 22:09:54 +0100843 ie->id = WLAN_EID_GENERIC;
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700844 ie->val.oui[0] = 0x00;
845 ie->val.oui[1] = 0x50;
846 ie->val.oui[2] = 0x43;
847 ie->val.type = MARVELL_MESH_IE_TYPE;
848 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
849 ie->val.version = MARVELL_MESH_IE_VERSION;
850 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
851 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
852 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
853 ie->val.mesh_id_len = priv->mesh_ssid_len;
854 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
Johannes Berg2c7060022008-10-30 22:09:54 +0100855 ie->len = sizeof(struct mrvl_meshie_val) -
Holger Schurig243e84e2009-10-22 15:30:47 +0200856 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700857 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
858 break;
859 case CMD_ACT_MESH_CONFIG_STOP:
860 break;
861 default:
862 return -1;
David Woodhouse23a397a2007-12-11 18:56:42 -0500863 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700864 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
865 action, priv->mesh_tlv, chan,
John W. Linville9387b7c2008-09-30 20:59:05 -0400866 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700867
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -0700868 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
David Woodhouse23a397a2007-12-11 18:56:42 -0500869}
870
David Woodhouse681ffbb2007-12-15 20:04:54 -0500871static void lbs_queue_cmd(struct lbs_private *priv,
872 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200873{
874 unsigned long flags;
David Woodhouse681ffbb2007-12-15 20:04:54 -0500875 int addtail = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200876
Holger Schurig8ff12da2007-08-02 11:54:31 -0400877 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200878
David Woodhousec4ab4122007-12-15 00:41:51 -0500879 if (!cmdnode) {
880 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200881 goto done;
882 }
David Woodhoused9896ee2007-12-15 00:09:25 -0500883 if (!cmdnode->cmdbuf->size) {
884 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
885 goto done;
886 }
David Woodhouseae125bf2007-12-15 04:22:52 -0500887 cmdnode->result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200888
889 /* Exit_PS command needs to be queued in the header always. */
Dan Williamsddac4522007-12-11 13:49:39 -0500890 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
David Woodhouse38bfab12007-12-16 23:26:54 -0500891 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
Dan Williamsddac4522007-12-11 13:49:39 -0500892
Dan Williams0aef64d2007-08-02 11:31:18 -0400893 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000894 if (priv->psstate != PS_STATE_FULL_POWER)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200895 addtail = 0;
896 }
897 }
898
David Woodhouseaa21c002007-12-08 20:04:36 +0000899 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200900
David Woodhouseac472462007-12-08 00:35:00 +0000901 if (addtail)
David Woodhouseaa21c002007-12-08 20:04:36 +0000902 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
David Woodhouseac472462007-12-08 00:35:00 +0000903 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000904 list_add(&cmdnode->list, &priv->cmdpendingq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200905
David Woodhouseaa21c002007-12-08 20:04:36 +0000906 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200907
Holger Schurig8ff12da2007-08-02 11:54:31 -0400908 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
David Woodhousec4ab4122007-12-15 00:41:51 -0500909 le16_to_cpu(cmdnode->cmdbuf->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200910
911done:
Holger Schurig8ff12da2007-08-02 11:54:31 -0400912 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200913}
914
David Woodhouse18c52e72007-12-17 16:03:58 -0500915static void lbs_submit_command(struct lbs_private *priv,
916 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200917{
918 unsigned long flags;
Dan Williamsddac4522007-12-11 13:49:39 -0500919 struct cmd_header *cmd;
David Woodhouse18c52e72007-12-17 16:03:58 -0500920 uint16_t cmdsize;
921 uint16_t command;
Holger Schurig57962f02008-05-14 16:30:28 +0200922 int timeo = 3 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -0500923 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200924
Holger Schurig8ff12da2007-08-02 11:54:31 -0400925 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200926
Dan Williamsddac4522007-12-11 13:49:39 -0500927 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200928
David Woodhouseaa21c002007-12-08 20:04:36 +0000929 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +0000930 priv->cur_cmd = cmdnode;
931 priv->cur_cmd_retcode = 0;
932 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200933
Dan Williamsddac4522007-12-11 13:49:39 -0500934 cmdsize = le16_to_cpu(cmd->size);
935 command = le16_to_cpu(cmd->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200936
David Woodhouse18c52e72007-12-17 16:03:58 -0500937 /* These commands take longer */
Dan Williamsbe0d76e2009-05-22 20:05:25 -0400938 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
Holger Schurig57962f02008-05-14 16:30:28 +0200939 timeo = 5 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -0500940
Holger Schurige5225b32008-03-26 10:04:44 +0100941 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
942 command, le16_to_cpu(cmd->seqnum), cmdsize);
Holger Schurig1afc09ab2008-01-29 09:14:40 +0100943 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400944
Dan Williamsddac4522007-12-11 13:49:39 -0500945 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
David Woodhouse18c52e72007-12-17 16:03:58 -0500946
David Woodhoused9896ee2007-12-15 00:09:25 -0500947 if (ret) {
948 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
David Woodhouse18c52e72007-12-17 16:03:58 -0500949 /* Let the timer kick in and retry, and potentially reset
950 the whole thing if the condition persists */
Holger Schurig57962f02008-05-14 16:30:28 +0200951 timeo = HZ/4;
Holger Schurig1afc09ab2008-01-29 09:14:40 +0100952 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200953
Amitkumar Karwar49125452009-09-30 20:04:38 -0700954 if (command == CMD_802_11_DEEP_SLEEP) {
955 if (priv->is_auto_deep_sleep_enabled) {
956 priv->wakeup_dev_required = 1;
957 priv->dnld_sent = 0;
958 }
959 priv->is_deep_sleep = 1;
960 lbs_complete_command(priv, cmdnode, 0);
961 } else {
962 /* Setup the timer after transmit command */
963 mod_timer(&priv->command_timer, jiffies + timeo);
964 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200965
David Woodhouse18c52e72007-12-17 16:03:58 -0500966 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200967}
968
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200969/**
970 * This function inserts command node to cmdfreeq
David Woodhouseaa21c002007-12-08 20:04:36 +0000971 * after cleans it. Requires priv->driver_lock held.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200972 */
David Woodhouse183aeac2007-12-15 01:52:54 -0500973static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
David Woodhouse5ba2f8a2007-12-15 02:02:56 -0500974 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200975{
David Woodhouse5ba2f8a2007-12-15 02:02:56 -0500976 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200977
David Woodhouse5ba2f8a2007-12-15 02:02:56 -0500978 if (!cmdnode)
979 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200980
David Woodhouse5ba2f8a2007-12-15 02:02:56 -0500981 cmdnode->callback = NULL;
982 cmdnode->callback_arg = 0;
983
984 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
985
986 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
987 out:
988 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200989}
990
Holger Schurig69f90322007-11-23 15:43:44 +0100991static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
992 struct cmd_ctrl_node *ptempcmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200993{
994 unsigned long flags;
995
David Woodhouseaa21c002007-12-08 20:04:36 +0000996 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig10078322007-11-15 18:05:47 -0500997 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
David Woodhouseaa21c002007-12-08 20:04:36 +0000998 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200999}
1000
David Woodhouse183aeac2007-12-15 01:52:54 -05001001void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1002 int result)
1003{
1004 if (cmd == priv->cur_cmd)
1005 priv->cur_cmd_retcode = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001006
David Woodhouseae125bf2007-12-15 04:22:52 -05001007 cmd->result = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001008 cmd->cmdwaitqwoken = 1;
1009 wake_up_interruptible(&cmd->cmdwait_q);
1010
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001011 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
David Woodhousead12d0f2007-12-15 02:06:16 -05001012 __lbs_cleanup_and_insert_cmd(priv, cmd);
David Woodhouse183aeac2007-12-15 01:52:54 -05001013 priv->cur_cmd = NULL;
1014}
1015
Dan Williamsd5db2df2008-08-21 17:51:07 -04001016int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001017{
David Woodhousea7c45892007-12-17 22:43:48 -05001018 struct cmd_ds_802_11_radio_control cmd;
Dan Williamsd5db2df2008-08-21 17:51:07 -04001019 int ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001020
Holger Schurig9012b282007-05-25 11:27:16 -04001021 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001022
David Woodhousea7c45892007-12-17 22:43:48 -05001023 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1024 cmd.action = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001025
Dan Williamsd5db2df2008-08-21 17:51:07 -04001026 /* Only v8 and below support setting the preamble */
1027 if (priv->fwrelease < 0x09000000) {
1028 switch (preamble) {
1029 case RADIO_PREAMBLE_SHORT:
1030 if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
1031 goto out;
1032 /* Fall through */
1033 case RADIO_PREAMBLE_AUTO:
1034 case RADIO_PREAMBLE_LONG:
1035 cmd.control = cpu_to_le16(preamble);
1036 break;
1037 default:
1038 goto out;
1039 }
David Woodhousea7c45892007-12-17 22:43:48 -05001040 }
1041
Dan Williamsd5db2df2008-08-21 17:51:07 -04001042 if (radio_on)
1043 cmd.control |= cpu_to_le16(0x1);
1044 else {
1045 cmd.control &= cpu_to_le16(~0x1);
1046 priv->txpower_cur = 0;
1047 }
David Woodhousea7c45892007-12-17 22:43:48 -05001048
Dan Williamsd5db2df2008-08-21 17:51:07 -04001049 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1050 radio_on ? "ON" : "OFF", preamble);
1051
1052 priv->radio_on = radio_on;
David Woodhousea7c45892007-12-17 22:43:48 -05001053
1054 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001055
Dan Williamsd5db2df2008-08-21 17:51:07 -04001056out:
Holger Schurig9012b282007-05-25 11:27:16 -04001057 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001058 return ret;
1059}
1060
Holger Schurigc97329e2008-03-18 11:20:21 +01001061void lbs_set_mac_control(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001062{
Holger Schurig835d3ac2008-03-12 16:05:40 +01001063 struct cmd_ds_mac_control cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064
Holger Schurig9012b282007-05-25 11:27:16 -04001065 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001066
Holger Schurig835d3ac2008-03-12 16:05:40 +01001067 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Holger Schurigd9e97782008-03-12 16:06:43 +01001068 cmd.action = cpu_to_le16(priv->mac_control);
Holger Schurig835d3ac2008-03-12 16:05:40 +01001069 cmd.reserved = 0;
1070
David Woodhouse75bf45a2008-05-20 13:32:45 +01001071 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001072
Holger Schurigc97329e2008-03-18 11:20:21 +01001073 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074}
1075
1076/**
1077 * @brief This function prepare the command before send to firmware.
1078 *
Holger Schurig69f90322007-11-23 15:43:44 +01001079 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001080 * @param cmd_no command number
1081 * @param cmd_action command action: GET or SET
1082 * @param wait_option wait option: wait response or not
1083 * @param cmd_oid cmd oid: treated as sub command
1084 * @param pdata_buf A pointer to informaion buffer
1085 * @return 0 or -1
1086 */
Holger Schurig69f90322007-11-23 15:43:44 +01001087int lbs_prepare_and_send_command(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001088 u16 cmd_no,
1089 u16 cmd_action,
1090 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1091{
1092 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001093 struct cmd_ctrl_node *cmdnode;
1094 struct cmd_ds_command *cmdptr;
1095 unsigned long flags;
1096
Holger Schurig8ff12da2007-08-02 11:54:31 -04001097 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001098
David Woodhouseaa21c002007-12-08 20:04:36 +00001099 if (!priv) {
1100 lbs_deb_host("PREP_CMD: priv is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001101 ret = -1;
1102 goto done;
1103 }
1104
David Woodhouseaa21c002007-12-08 20:04:36 +00001105 if (priv->surpriseremoved) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001106 lbs_deb_host("PREP_CMD: card removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001107 ret = -1;
1108 goto done;
1109 }
1110
Amitkumar Karwar63f275d2009-10-06 19:20:28 -07001111 if (!lbs_is_cmd_allowed(priv)) {
1112 ret = -EBUSY;
1113 goto done;
1114 }
1115
Holger Schurig0d61d042007-12-05 17:58:06 +01001116 cmdnode = lbs_get_cmd_ctrl_node(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001117
1118 if (cmdnode == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001119 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001120
1121 /* Wake up main thread to execute next command */
Dan Williamsfe336152007-08-02 11:32:25 -04001122 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001123 ret = -1;
1124 goto done;
1125 }
1126
Holger Schurige98a88d2008-03-19 14:25:58 +01001127 cmdnode->callback = NULL;
1128 cmdnode->callback_arg = (unsigned long)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001129
Dan Williamsddac4522007-12-11 13:49:39 -05001130 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001131
Holger Schurig8ff12da2007-08-02 11:54:31 -04001132 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001133
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001134 /* Set sequence number, command and INT option */
David Woodhouseaa21c002007-12-08 20:04:36 +00001135 priv->seqnum++;
1136 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001137
David Woodhouse981f1872007-05-25 23:36:54 -04001138 cmdptr->command = cpu_to_le16(cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001139 cmdptr->result = 0;
1140
1141 switch (cmd_no) {
Dan Williams0aef64d2007-08-02 11:31:18 -04001142 case CMD_802_11_PS_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001143 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001144 break;
1145
Dan Williams0aef64d2007-08-02 11:31:18 -04001146 case CMD_MAC_REG_ACCESS:
1147 case CMD_BBP_REG_ACCESS:
1148 case CMD_RF_REG_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001149 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001150 break;
1151
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001152 case CMD_802_11_MONITOR_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001153 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001154 cmd_action, pdata_buf);
1155 break;
1156
Dan Williams0aef64d2007-08-02 11:31:18 -04001157 case CMD_802_11_RSSI:
Holger Schurig10078322007-11-15 18:05:47 -05001158 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001159 break;
1160
Dan Williams0aef64d2007-08-02 11:31:18 -04001161 case CMD_802_11_SET_AFC:
1162 case CMD_802_11_GET_AFC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001163
1164 cmdptr->command = cpu_to_le16(cmd_no);
David Woodhouse981f1872007-05-25 23:36:54 -04001165 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
Holger Schurig8ec97cc2009-10-22 15:30:55 +02001166 sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001167
1168 memmove(&cmdptr->params.afc,
1169 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1170
1171 ret = 0;
1172 goto done;
1173
Dan Williams0aef64d2007-08-02 11:31:18 -04001174 case CMD_802_11_TPC_CFG:
1175 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001176 cmdptr->size =
1177 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
Holger Schurig8ec97cc2009-10-22 15:30:55 +02001178 sizeof(struct cmd_header));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001179
1180 memmove(&cmdptr->params.tpccfg,
1181 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1182
1183 ret = 0;
1184 break;
David Woodhouse5844d122007-12-18 02:01:37 -05001185
Dan Williams0aef64d2007-08-02 11:31:18 -04001186 case CMD_BT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001187 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001188 break;
1189
Dan Williams0aef64d2007-08-02 11:31:18 -04001190 case CMD_FWT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001191 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001192 break;
1193
Brajesh Dave96287ac2007-11-20 17:44:28 -05001194 case CMD_802_11_BEACON_CTRL:
1195 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1196 break;
Amitkumar Karwar49125452009-09-30 20:04:38 -07001197 case CMD_802_11_DEEP_SLEEP:
1198 cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP);
Holger Schurig8ec97cc2009-10-22 15:30:55 +02001199 cmdptr->size = cpu_to_le16(sizeof(struct cmd_header));
Amitkumar Karwar49125452009-09-30 20:04:38 -07001200 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001201 default:
David Woodhousee37fc6e2008-05-20 11:47:16 +01001202 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001203 ret = -1;
1204 break;
1205 }
1206
1207 /* return error, since the command preparation failed */
1208 if (ret != 0) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001209 lbs_deb_host("PREP_CMD: command preparation failed\n");
Holger Schurig10078322007-11-15 18:05:47 -05001210 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001211 ret = -1;
1212 goto done;
1213 }
1214
1215 cmdnode->cmdwaitqwoken = 0;
1216
David Woodhouse681ffbb2007-12-15 20:04:54 -05001217 lbs_queue_cmd(priv, cmdnode);
Dan Williamsfe336152007-08-02 11:32:25 -04001218 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001219
Dan Williams0aef64d2007-08-02 11:31:18 -04001220 if (wait_option & CMD_OPTION_WAITFORRSP) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001221 lbs_deb_host("PREP_CMD: wait for response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001222 might_sleep();
1223 wait_event_interruptible(cmdnode->cmdwait_q,
1224 cmdnode->cmdwaitqwoken);
1225 }
1226
David Woodhouseaa21c002007-12-08 20:04:36 +00001227 spin_lock_irqsave(&priv->driver_lock, flags);
1228 if (priv->cur_cmd_retcode) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001229 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001230 priv->cur_cmd_retcode);
1231 priv->cur_cmd_retcode = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001232 ret = -1;
1233 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001234 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001235
1236done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001237 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001238 return ret;
1239}
1240
1241/**
1242 * @brief This function allocates the command buffer and link
1243 * it to command free queue.
1244 *
Holger Schurig69f90322007-11-23 15:43:44 +01001245 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001246 * @return 0 or -1
1247 */
Holger Schurig69f90322007-11-23 15:43:44 +01001248int lbs_allocate_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001249{
1250 int ret = 0;
Dan Williamsddac4522007-12-11 13:49:39 -05001251 u32 bufsize;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001252 u32 i;
Dan Williamsddac4522007-12-11 13:49:39 -05001253 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001254
Holger Schurig8ff12da2007-08-02 11:54:31 -04001255 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001256
Dan Williamsddac4522007-12-11 13:49:39 -05001257 /* Allocate and initialize the command array */
1258 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1259 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001260 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001261 ret = -1;
1262 goto done;
1263 }
Dan Williamsddac4522007-12-11 13:49:39 -05001264 priv->cmd_array = cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001265
Dan Williamsddac4522007-12-11 13:49:39 -05001266 /* Allocate and initialize each command buffer in the command array */
1267 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1268 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1269 if (!cmdarray[i].cmdbuf) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001270 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001271 ret = -1;
1272 goto done;
1273 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001274 }
1275
Dan Williamsddac4522007-12-11 13:49:39 -05001276 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1277 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1278 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001279 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001280 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001281
1282done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001283 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001284 return ret;
1285}
1286
1287/**
1288 * @brief This function frees the command buffer.
1289 *
Holger Schurig69f90322007-11-23 15:43:44 +01001290 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001291 * @return 0 or -1
1292 */
Holger Schurig69f90322007-11-23 15:43:44 +01001293int lbs_free_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001294{
Dan Williamsddac4522007-12-11 13:49:39 -05001295 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001296 unsigned int i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001297
Holger Schurig8ff12da2007-08-02 11:54:31 -04001298 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001299
1300 /* need to check if cmd array is allocated or not */
David Woodhouseaa21c002007-12-08 20:04:36 +00001301 if (priv->cmd_array == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001302 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001303 goto done;
1304 }
1305
Dan Williamsddac4522007-12-11 13:49:39 -05001306 cmdarray = priv->cmd_array;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001307
1308 /* Release shared memory buffers */
Dan Williamsddac4522007-12-11 13:49:39 -05001309 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1310 if (cmdarray[i].cmdbuf) {
1311 kfree(cmdarray[i].cmdbuf);
1312 cmdarray[i].cmdbuf = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001313 }
1314 }
1315
1316 /* Release cmd_ctrl_node */
David Woodhouseaa21c002007-12-08 20:04:36 +00001317 if (priv->cmd_array) {
1318 kfree(priv->cmd_array);
1319 priv->cmd_array = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001320 }
1321
1322done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001323 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001324 return 0;
1325}
1326
1327/**
1328 * @brief This function gets a free command node if available in
1329 * command free queue.
1330 *
Holger Schurig69f90322007-11-23 15:43:44 +01001331 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001332 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1333 */
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001334static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001335{
1336 struct cmd_ctrl_node *tempnode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001337 unsigned long flags;
1338
Holger Schurig8ff12da2007-08-02 11:54:31 -04001339 lbs_deb_enter(LBS_DEB_HOST);
1340
David Woodhouseaa21c002007-12-08 20:04:36 +00001341 if (!priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001342 return NULL;
1343
David Woodhouseaa21c002007-12-08 20:04:36 +00001344 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001345
David Woodhouseaa21c002007-12-08 20:04:36 +00001346 if (!list_empty(&priv->cmdfreeq)) {
1347 tempnode = list_first_entry(&priv->cmdfreeq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001348 struct cmd_ctrl_node, list);
1349 list_del(&tempnode->list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001350 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001351 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001352 tempnode = NULL;
1353 }
1354
David Woodhouseaa21c002007-12-08 20:04:36 +00001355 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001356
Holger Schurig8ff12da2007-08-02 11:54:31 -04001357 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001358 return tempnode;
1359}
1360
1361/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001362 * @brief This function executes next command in command
Nick Andrew877d0312009-01-26 11:06:57 +01001363 * pending queue. It will put firmware back to PS mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001364 * if applicable.
1365 *
Holger Schurig69f90322007-11-23 15:43:44 +01001366 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001367 * @return 0 or -1
1368 */
Holger Schurig69f90322007-11-23 15:43:44 +01001369int lbs_execute_next_command(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001370{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001371 struct cmd_ctrl_node *cmdnode = NULL;
Dan Williamsddac4522007-12-11 13:49:39 -05001372 struct cmd_header *cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001373 unsigned long flags;
1374 int ret = 0;
1375
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001376 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1377 * only caller to us is lbs_thread() and we get even when a
1378 * data packet is received */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001379 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001380
David Woodhouseaa21c002007-12-08 20:04:36 +00001381 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001382
David Woodhouseaa21c002007-12-08 20:04:36 +00001383 if (priv->cur_cmd) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001384 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001385 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001386 ret = -1;
1387 goto done;
1388 }
1389
David Woodhouseaa21c002007-12-08 20:04:36 +00001390 if (!list_empty(&priv->cmdpendingq)) {
1391 cmdnode = list_first_entry(&priv->cmdpendingq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001392 struct cmd_ctrl_node, list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001393 }
1394
David Woodhouseaa21c002007-12-08 20:04:36 +00001395 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001396
1397 if (cmdnode) {
Dan Williamsddac4522007-12-11 13:49:39 -05001398 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001399
Dan Williamsddac4522007-12-11 13:49:39 -05001400 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001401 if ((priv->psstate == PS_STATE_SLEEP) ||
1402 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001403 lbs_deb_host(
1404 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001405 le16_to_cpu(cmd->command),
David Woodhouseaa21c002007-12-08 20:04:36 +00001406 priv->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001407 ret = -1;
1408 goto done;
1409 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001410 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
Dan Williamsddac4522007-12-11 13:49:39 -05001411 "0x%04x in psstate %d\n",
1412 le16_to_cpu(cmd->command), priv->psstate);
David Woodhouseaa21c002007-12-08 20:04:36 +00001413 } else if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001414 /*
1415 * 1. Non-PS command:
1416 * Queue it. set needtowakeup to TRUE if current state
Holger Schurig10078322007-11-15 18:05:47 -05001417 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001418 * 2. PS command but not Exit_PS:
1419 * Ignore it.
1420 * 3. PS command Exit_PS:
1421 * Set needtowakeup to TRUE if current state is SLEEP,
1422 * otherwise send this command down to firmware
1423 * immediately.
1424 */
Dan Williamsddac4522007-12-11 13:49:39 -05001425 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001426 /* Prepare to send Exit PS,
1427 * this non PS command will be sent later */
David Woodhouseaa21c002007-12-08 20:04:36 +00001428 if ((priv->psstate == PS_STATE_SLEEP)
1429 || (priv->psstate == PS_STATE_PRE_SLEEP)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001430 ) {
1431 /* w/ new scheme, it will not reach here.
1432 since it is blocked in main_thread. */
David Woodhouseaa21c002007-12-08 20:04:36 +00001433 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001434 } else
Holger Schurig10078322007-11-15 18:05:47 -05001435 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001436
1437 ret = 0;
1438 goto done;
1439 } else {
1440 /*
1441 * PS command. Ignore it if it is not Exit_PS.
1442 * otherwise send it down immediately.
1443 */
David Woodhouse38bfab12007-12-16 23:26:54 -05001444 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001445
Holger Schurig8ff12da2007-08-02 11:54:31 -04001446 lbs_deb_host(
1447 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001448 psm->action);
1449 if (psm->action !=
Dan Williams0aef64d2007-08-02 11:31:18 -04001450 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001451 lbs_deb_host(
1452 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001453 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001454 spin_lock_irqsave(&priv->driver_lock, flags);
1455 lbs_complete_command(priv, cmdnode, 0);
1456 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001457
1458 ret = 0;
1459 goto done;
1460 }
1461
David Woodhouseaa21c002007-12-08 20:04:36 +00001462 if ((priv->psstate == PS_STATE_SLEEP) ||
1463 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001464 lbs_deb_host(
1465 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001466 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001467 spin_lock_irqsave(&priv->driver_lock, flags);
1468 lbs_complete_command(priv, cmdnode, 0);
1469 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001470 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001471
1472 ret = 0;
1473 goto done;
1474 }
1475
Holger Schurig8ff12da2007-08-02 11:54:31 -04001476 lbs_deb_host(
1477 "EXEC_NEXT_CMD: sending EXIT_PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001478 }
1479 }
Li Zefanabe3ed12007-12-06 13:01:21 +01001480 list_del(&cmdnode->list);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001481 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001482 le16_to_cpu(cmd->command));
David Woodhoused9896ee2007-12-15 00:09:25 -05001483 lbs_submit_command(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001484 } else {
1485 /*
1486 * check if in power save mode, if yes, put the device back
1487 * to PS mode
1488 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001489 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1490 (priv->psstate == PS_STATE_FULL_POWER) &&
1491 ((priv->connect_status == LBS_CONNECTED) ||
1492 (priv->mesh_connect_status == LBS_CONNECTED))) {
1493 if (priv->secinfo.WPAenabled ||
1494 priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001495 /* check for valid WPA group keys */
David Woodhouseaa21c002007-12-08 20:04:36 +00001496 if (priv->wpa_mcast_key.len ||
1497 priv->wpa_unicast_key.len) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001498 lbs_deb_host(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001499 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1500 " go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001501 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001502 }
1503 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001504 lbs_deb_host(
1505 "EXEC_NEXT_CMD: cmdpendingq empty, "
1506 "go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001507 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001508 }
1509 }
1510 }
1511
1512 ret = 0;
1513done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001514 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001515 return ret;
1516}
1517
Holger Schurigf539f2e2008-03-26 13:22:11 +01001518static void lbs_send_confirmsleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001519{
1520 unsigned long flags;
Holger Schurigf539f2e2008-03-26 13:22:11 +01001521 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001522
Holger Schurig8ff12da2007-08-02 11:54:31 -04001523 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurigf539f2e2008-03-26 13:22:11 +01001524 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1525 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001526
Holger Schurigf539f2e2008-03-26 13:22:11 +01001527 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1528 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001529 if (ret) {
Holger Schurigf539f2e2008-03-26 13:22:11 +01001530 lbs_pr_alert("confirm_sleep failed\n");
Holger Schurig7919b892008-04-01 14:50:43 +02001531 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001532 }
Holger Schurig7919b892008-04-01 14:50:43 +02001533
1534 spin_lock_irqsave(&priv->driver_lock, flags);
1535
Holger Schuriga01f5452008-06-04 11:10:40 +02001536 /* We don't get a response on the sleep-confirmation */
1537 priv->dnld_sent = DNLD_RES_RECEIVED;
1538
Holger Schurig7919b892008-04-01 14:50:43 +02001539 /* If nothing to do, go back to sleep (?) */
1540 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1541 priv->psstate = PS_STATE_SLEEP;
1542
1543 spin_unlock_irqrestore(&priv->driver_lock, flags);
1544
1545out:
Holger Schurigf539f2e2008-03-26 13:22:11 +01001546 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001547}
1548
Holger Schurig69f90322007-11-23 15:43:44 +01001549void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001550{
Holger Schurig8ff12da2007-08-02 11:54:31 -04001551 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001552
1553 /*
1554 * PS is currently supported only in Infrastructure mode
1555 * Remove this check if it is to be supported in IBSS mode also
1556 */
1557
Holger Schurig10078322007-11-15 18:05:47 -05001558 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001559 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001560
Holger Schurig8ff12da2007-08-02 11:54:31 -04001561 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001562}
1563
1564/**
Holger Schurig8ff12da2007-08-02 11:54:31 -04001565 * @brief This function sends Exit_PS command to firmware.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001566 *
Holger Schurig69f90322007-11-23 15:43:44 +01001567 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001568 * @param wait_option wait response or not
1569 * @return n/a
1570 */
Holger Schurig69f90322007-11-23 15:43:44 +01001571void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001572{
David Woodhouse981f1872007-05-25 23:36:54 -04001573 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001574
Holger Schurig8ff12da2007-08-02 11:54:31 -04001575 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001576
Holger Schurig10078322007-11-15 18:05:47 -05001577 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001578
Holger Schurig10078322007-11-15 18:05:47 -05001579 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001580 CMD_SUBCMD_EXIT_PS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001581 wait_option, 0, &Localpsmode);
1582
Holger Schurig8ff12da2007-08-02 11:54:31 -04001583 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001584}
1585
1586/**
1587 * @brief This function checks condition and prepares to
1588 * send sleep confirm command to firmware if ok.
1589 *
Holger Schurig69f90322007-11-23 15:43:44 +01001590 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001591 * @param psmode Power Saving mode
1592 * @return n/a
1593 */
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001594void lbs_ps_confirm_sleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001595{
1596 unsigned long flags =0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001597 int allowed = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001598
Holger Schurig8ff12da2007-08-02 11:54:31 -04001599 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001600
Holger Schuriga01f5452008-06-04 11:10:40 +02001601 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig634b8f42007-05-25 13:05:16 -04001602 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001603 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001604 lbs_deb_host("dnld_sent was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001605 }
1606
Holger Schurig7919b892008-04-01 14:50:43 +02001607 /* In-progress command? */
David Woodhouseaa21c002007-12-08 20:04:36 +00001608 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001609 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001610 lbs_deb_host("cur_cmd was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001611 }
Holger Schurig7919b892008-04-01 14:50:43 +02001612
1613 /* Pending events or command responses? */
1614 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001615 allowed = 0;
Holger Schurig7919b892008-04-01 14:50:43 +02001616 lbs_deb_host("pending events or command responses\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001617 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001618 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001619
1620 if (allowed) {
Holger Schurig10078322007-11-15 18:05:47 -05001621 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
Holger Schurigf539f2e2008-03-26 13:22:11 +01001622 lbs_send_confirmsleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001623 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001624 lbs_deb_host("sleep confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001625 }
1626
Holger Schurig8ff12da2007-08-02 11:54:31 -04001627 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001628}
Holger Schurig675787e2007-12-05 17:58:11 +01001629
1630
Anna Neal0112c9e2008-09-11 11:17:25 -07001631/**
1632 * @brief Configures the transmission power control functionality.
1633 *
1634 * @param priv A pointer to struct lbs_private structure
1635 * @param enable Transmission power control enable
1636 * @param p0 Power level when link quality is good (dBm).
1637 * @param p1 Power level when link quality is fair (dBm).
1638 * @param p2 Power level when link quality is poor (dBm).
1639 * @param usesnr Use Signal to Noise Ratio in TPC
1640 *
1641 * @return 0 on success
1642 */
1643int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1644 int8_t p2, int usesnr)
1645{
1646 struct cmd_ds_802_11_tpc_cfg cmd;
1647 int ret;
1648
1649 memset(&cmd, 0, sizeof(cmd));
1650 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1651 cmd.action = cpu_to_le16(CMD_ACT_SET);
1652 cmd.enable = !!enable;
Anna Neal3ed6e082008-09-26 11:34:35 -04001653 cmd.usesnr = !!usesnr;
Anna Neal0112c9e2008-09-11 11:17:25 -07001654 cmd.P0 = p0;
1655 cmd.P1 = p1;
1656 cmd.P2 = p2;
1657
1658 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
1659
1660 return ret;
1661}
1662
1663/**
1664 * @brief Configures the power adaptation settings.
1665 *
1666 * @param priv A pointer to struct lbs_private structure
1667 * @param enable Power adaptation enable
1668 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
1669 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
1670 * @param p2 Power level for 48 and 54 Mbps (dBm).
1671 *
1672 * @return 0 on Success
1673 */
1674
1675int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
1676 int8_t p1, int8_t p2)
1677{
1678 struct cmd_ds_802_11_pa_cfg cmd;
1679 int ret;
1680
1681 memset(&cmd, 0, sizeof(cmd));
1682 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1683 cmd.action = cpu_to_le16(CMD_ACT_SET);
1684 cmd.enable = !!enable;
1685 cmd.P0 = p0;
1686 cmd.P1 = p1;
1687 cmd.P2 = p2;
1688
1689 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
1690
1691 return ret;
1692}
1693
1694
Holger Schurig6d898b12009-10-14 16:49:53 +02001695struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001696 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
1697 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1698 unsigned long callback_arg)
Holger Schurig675787e2007-12-05 17:58:11 +01001699{
Holger Schurig675787e2007-12-05 17:58:11 +01001700 struct cmd_ctrl_node *cmdnode;
Holger Schurig675787e2007-12-05 17:58:11 +01001701
1702 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurig675787e2007-12-05 17:58:11 +01001703
David Woodhouseaa21c002007-12-08 20:04:36 +00001704 if (priv->surpriseremoved) {
Holger Schurig675787e2007-12-05 17:58:11 +01001705 lbs_deb_host("PREP_CMD: card removed\n");
David Woodhouse3399ea52007-12-15 03:09:33 -05001706 cmdnode = ERR_PTR(-ENOENT);
Holger Schurig675787e2007-12-05 17:58:11 +01001707 goto done;
1708 }
1709
Amitkumar Karwar63f275d2009-10-06 19:20:28 -07001710 if (!lbs_is_cmd_allowed(priv)) {
1711 cmdnode = ERR_PTR(-EBUSY);
1712 goto done;
1713 }
1714
Holger Schurig675787e2007-12-05 17:58:11 +01001715 cmdnode = lbs_get_cmd_ctrl_node(priv);
Holger Schurig675787e2007-12-05 17:58:11 +01001716 if (cmdnode == NULL) {
1717 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1718
1719 /* Wake up main thread to execute next command */
1720 wake_up_interruptible(&priv->waitq);
David Woodhouse3399ea52007-12-15 03:09:33 -05001721 cmdnode = ERR_PTR(-ENOBUFS);
Holger Schurig675787e2007-12-05 17:58:11 +01001722 goto done;
1723 }
1724
David Woodhouse448a51a2007-12-08 00:59:54 +00001725 cmdnode->callback = callback;
David Woodhouse1309b552007-12-10 13:36:10 -05001726 cmdnode->callback_arg = callback_arg;
Holger Schurig675787e2007-12-05 17:58:11 +01001727
Dan Williams7ad994d2007-12-11 12:33:30 -05001728 /* Copy the incoming command to the buffer */
Dan Williamsddac4522007-12-11 13:49:39 -05001729 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
Dan Williams7ad994d2007-12-11 12:33:30 -05001730
Holger Schurig675787e2007-12-05 17:58:11 +01001731 /* Set sequence number, clean result, move to buffer */
David Woodhouseaa21c002007-12-08 20:04:36 +00001732 priv->seqnum++;
Dan Williamsddac4522007-12-11 13:49:39 -05001733 cmdnode->cmdbuf->command = cpu_to_le16(command);
1734 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
1735 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
1736 cmdnode->cmdbuf->result = 0;
Holger Schurig675787e2007-12-05 17:58:11 +01001737
1738 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
1739
Holger Schurig675787e2007-12-05 17:58:11 +01001740 cmdnode->cmdwaitqwoken = 0;
David Woodhouse681ffbb2007-12-15 20:04:54 -05001741 lbs_queue_cmd(priv, cmdnode);
Holger Schurig675787e2007-12-05 17:58:11 +01001742 wake_up_interruptible(&priv->waitq);
1743
David Woodhouse3399ea52007-12-15 03:09:33 -05001744 done:
1745 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
1746 return cmdnode;
1747}
1748
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001749void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
1750 struct cmd_header *in_cmd, int in_cmd_size)
1751{
1752 lbs_deb_enter(LBS_DEB_CMD);
1753 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1754 lbs_cmd_async_callback, 0);
1755 lbs_deb_leave(LBS_DEB_CMD);
1756}
1757
David Woodhouse3399ea52007-12-15 03:09:33 -05001758int __lbs_cmd(struct lbs_private *priv, uint16_t command,
1759 struct cmd_header *in_cmd, int in_cmd_size,
1760 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1761 unsigned long callback_arg)
1762{
1763 struct cmd_ctrl_node *cmdnode;
1764 unsigned long flags;
1765 int ret = 0;
1766
1767 lbs_deb_enter(LBS_DEB_HOST);
1768
1769 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1770 callback, callback_arg);
1771 if (IS_ERR(cmdnode)) {
1772 ret = PTR_ERR(cmdnode);
1773 goto done;
1774 }
1775
Holger Schurig675787e2007-12-05 17:58:11 +01001776 might_sleep();
1777 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
1778
David Woodhouseaa21c002007-12-08 20:04:36 +00001779 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseae125bf2007-12-15 04:22:52 -05001780 ret = cmdnode->result;
1781 if (ret)
1782 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
1783 command, ret);
David Woodhouse3399ea52007-12-15 03:09:33 -05001784
David Woodhousead12d0f2007-12-15 02:06:16 -05001785 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
David Woodhouseaa21c002007-12-08 20:04:36 +00001786 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig675787e2007-12-05 17:58:11 +01001787
1788done:
1789 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1790 return ret;
1791}
Dan Williams14e865b2007-12-10 15:11:23 -05001792EXPORT_SYMBOL_GPL(__lbs_cmd);